mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 14:16:32 +02:00
add resolved tracks as we get them when previewing, and stop previewing if we're running
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
*
|
*
|
||||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||||
*
|
*
|
||||||
* Tomahawk is free software: you can redistribute it and/or modify
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
@@ -33,7 +33,7 @@ DynamicModel::DynamicModel( QObject* parent )
|
|||||||
, m_currentAttempts( 0 )
|
, m_currentAttempts( 0 )
|
||||||
, m_lastResolvedRow( 0 )
|
, m_lastResolvedRow( 0 )
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DynamicModel::~DynamicModel()
|
DynamicModel::~DynamicModel()
|
||||||
@@ -41,7 +41,7 @@ DynamicModel::~DynamicModel()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DynamicModel::loadPlaylist( const Tomahawk::dynplaylist_ptr& playlist, bool loadEntries )
|
DynamicModel::loadPlaylist( const Tomahawk::dynplaylist_ptr& playlist, bool loadEntries )
|
||||||
{
|
{
|
||||||
Q_UNUSED( loadEntries );
|
Q_UNUSED( loadEntries );
|
||||||
@@ -50,55 +50,55 @@ DynamicModel::loadPlaylist( const Tomahawk::dynplaylist_ptr& playlist, bool load
|
|||||||
disconnect( m_playlist->generator().data(), SIGNAL( nextTrackGenerated( Tomahawk::query_ptr ) ), this, SLOT( newTrackGenerated( Tomahawk::query_ptr ) ) );
|
disconnect( m_playlist->generator().data(), SIGNAL( nextTrackGenerated( Tomahawk::query_ptr ) ), this, SLOT( newTrackGenerated( Tomahawk::query_ptr ) ) );
|
||||||
}
|
}
|
||||||
m_playlist = playlist;
|
m_playlist = playlist;
|
||||||
|
|
||||||
if( m_playlist->mode() == OnDemand )
|
if( m_playlist->mode() == OnDemand )
|
||||||
setFilterUnresolvable( true );
|
setFilterUnresolvable( true );
|
||||||
|
|
||||||
connect( m_playlist->generator().data(), SIGNAL( nextTrackGenerated( Tomahawk::query_ptr ) ), this, SLOT( newTrackGenerated( Tomahawk::query_ptr ) ) );
|
connect( m_playlist->generator().data(), SIGNAL( nextTrackGenerated( Tomahawk::query_ptr ) ), this, SLOT( newTrackGenerated( Tomahawk::query_ptr ) ) );
|
||||||
PlaylistModel::loadPlaylist( m_playlist, m_playlist->mode() == Static );
|
PlaylistModel::loadPlaylist( m_playlist, m_playlist->mode() == Static );
|
||||||
|
|
||||||
if( m_playlist->mode() == OnDemand )
|
if( m_playlist->mode() == OnDemand )
|
||||||
emit trackCountChanged( rowCount( QModelIndex() ) );
|
emit trackCountChanged( rowCount( QModelIndex() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
QString
|
QString
|
||||||
DynamicModel::description() const
|
DynamicModel::description() const
|
||||||
{
|
{
|
||||||
return m_playlist->generator()->sentenceSummary();
|
return m_playlist->generator()->sentenceSummary();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
DynamicModel::startOnDemand()
|
DynamicModel::startOnDemand()
|
||||||
{
|
{
|
||||||
connect( AudioEngine::instance(), SIGNAL( loading( Tomahawk::result_ptr ) ), this, SLOT( newTrackLoading() ) );
|
connect( AudioEngine::instance(), SIGNAL( loading( Tomahawk::result_ptr ) ), this, SLOT( newTrackLoading() ) );
|
||||||
|
|
||||||
m_playlist->generator()->startOnDemand();
|
m_playlist->generator()->startOnDemand();
|
||||||
|
|
||||||
m_onDemandRunning = true;
|
m_onDemandRunning = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DynamicModel::newTrackGenerated( const Tomahawk::query_ptr& query )
|
DynamicModel::newTrackGenerated( const Tomahawk::query_ptr& query )
|
||||||
{
|
{
|
||||||
if( m_onDemandRunning ) {
|
if( m_onDemandRunning ) {
|
||||||
connect( query.data(), SIGNAL( resolvingFinished( bool ) ), this, SLOT( trackResolveFinished( bool ) ) );
|
connect( query.data(), SIGNAL( resolvingFinished( bool ) ), this, SLOT( trackResolveFinished( bool ) ) );
|
||||||
|
|
||||||
append( query );
|
append( query );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DynamicModel::stopOnDemand( bool stopPlaying )
|
DynamicModel::stopOnDemand( bool stopPlaying )
|
||||||
{
|
{
|
||||||
m_onDemandRunning = false;
|
m_onDemandRunning = false;
|
||||||
if( stopPlaying )
|
if( stopPlaying )
|
||||||
AudioEngine::instance()->stop();
|
AudioEngine::instance()->stop();
|
||||||
|
|
||||||
disconnect( AudioEngine::instance(), SIGNAL( loading( Tomahawk::result_ptr ) ), this, SLOT( newTrackLoading() ) );
|
disconnect( AudioEngine::instance(), SIGNAL( loading( Tomahawk::result_ptr ) ), this, SLOT( newTrackLoading() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DynamicModel::changeStation()
|
DynamicModel::changeStation()
|
||||||
{
|
{
|
||||||
if( m_onDemandRunning )
|
if( m_onDemandRunning )
|
||||||
@@ -107,7 +107,7 @@ DynamicModel::changeStation()
|
|||||||
m_playlist->generator()->startOnDemand();
|
m_playlist->generator()->startOnDemand();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DynamicModel::trackResolveFinished( bool success )
|
DynamicModel::trackResolveFinished( bool success )
|
||||||
{
|
{
|
||||||
Q_UNUSED( success );
|
Q_UNUSED( success );
|
||||||
@@ -117,7 +117,7 @@ DynamicModel::trackResolveFinished( bool success )
|
|||||||
if( !q->playable() ) {
|
if( !q->playable() ) {
|
||||||
qDebug() << "Got not resolved track:" << q->track() << q->artist() << m_lastResolvedRow << m_currentAttempts;
|
qDebug() << "Got not resolved track:" << q->track() << q->artist() << m_lastResolvedRow << m_currentAttempts;
|
||||||
m_currentAttempts++;
|
m_currentAttempts++;
|
||||||
|
|
||||||
int curAttempts = m_startingAfterFailed ? m_currentAttempts - 20 : m_currentAttempts; // if we just failed, m_currentAttempts includes those failures
|
int curAttempts = m_startingAfterFailed ? m_currentAttempts - 20 : m_currentAttempts; // if we just failed, m_currentAttempts includes those failures
|
||||||
if( curAttempts < 20 ) {
|
if( curAttempts < 20 ) {
|
||||||
qDebug() << "FETCHING MORE!";
|
qDebug() << "FETCHING MORE!";
|
||||||
@@ -129,20 +129,20 @@ DynamicModel::trackResolveFinished( bool success )
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
qDebug() << "Got successful resolved track:" << q->track() << q->artist() << m_lastResolvedRow << m_currentAttempts;
|
qDebug() << "Got successful resolved track:" << q->track() << q->artist() << m_lastResolvedRow << m_currentAttempts;
|
||||||
|
|
||||||
if( m_currentAttempts > 0 ) {
|
if( m_currentAttempts > 0 ) {
|
||||||
qDebug() << "EMITTING AN ASK FOR COLLAPSE:" << m_lastResolvedRow << m_currentAttempts;
|
qDebug() << "EMITTING AN ASK FOR COLLAPSE:" << m_lastResolvedRow << m_currentAttempts;
|
||||||
emit collapseFromTo( m_lastResolvedRow, m_currentAttempts );
|
emit collapseFromTo( m_lastResolvedRow, m_currentAttempts );
|
||||||
}
|
}
|
||||||
m_currentAttempts = 0;
|
m_currentAttempts = 0;
|
||||||
m_searchingForNext = false;
|
m_searchingForNext = false;
|
||||||
|
|
||||||
emit checkForOverflow();
|
emit checkForOverflow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
DynamicModel::newTrackLoading()
|
DynamicModel::newTrackLoading()
|
||||||
{
|
{
|
||||||
qDebug() << "Got NEW TRACK LOADING signal";
|
qDebug() << "Got NEW TRACK LOADING signal";
|
||||||
@@ -155,10 +155,10 @@ DynamicModel::newTrackLoading()
|
|||||||
m_searchingForNext = true;
|
m_searchingForNext = true;
|
||||||
qDebug() << "IDLE fetching new track!";
|
qDebug() << "IDLE fetching new track!";
|
||||||
m_playlist->generator()->fetchNext();
|
m_playlist->generator()->fetchNext();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DynamicModel::tracksGenerated( const QList< query_ptr > entries, int limitResolvedTo )
|
DynamicModel::tracksGenerated( const QList< query_ptr > entries, int limitResolvedTo )
|
||||||
{
|
{
|
||||||
if( m_filterUnresolvable && m_playlist->mode() == OnDemand ) { // wait till we get them resolved (for previewing stations)
|
if( m_filterUnresolvable && m_playlist->mode() == OnDemand ) { // wait till we get them resolved (for previewing stations)
|
||||||
@@ -166,31 +166,39 @@ DynamicModel::tracksGenerated( const QList< query_ptr > entries, int limitResolv
|
|||||||
filterUnresolved( entries );
|
filterUnresolved( entries );
|
||||||
} else {
|
} else {
|
||||||
addToPlaylist( entries, m_playlist->mode() == OnDemand ); // if ondemand, we're previewing, so clear old
|
addToPlaylist( entries, m_playlist->mode() == OnDemand ); // if ondemand, we're previewing, so clear old
|
||||||
|
|
||||||
if( m_playlist->mode() == OnDemand ) {
|
if( m_playlist->mode() == OnDemand ) {
|
||||||
m_lastResolvedRow = rowCount( QModelIndex() );
|
m_lastResolvedRow = rowCount( QModelIndex() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DynamicModel::filterUnresolved( const QList< query_ptr >& entries )
|
DynamicModel::filterUnresolved( const QList< query_ptr >& entries )
|
||||||
{
|
{
|
||||||
m_toResolveList = entries;
|
m_toResolveList = entries;
|
||||||
|
|
||||||
foreach( const query_ptr& q, entries ) {
|
foreach( const query_ptr& q, entries ) {
|
||||||
connect( q.data(), SIGNAL( resolvingFinished( bool ) ), this, SLOT( filteringTrackResolved( bool ) ) );
|
connect( q.data(), SIGNAL( resolvingFinished( bool ) ), this, SLOT( filteringTrackResolved( bool ) ) );
|
||||||
}
|
}
|
||||||
Pipeline::instance()->resolve( entries, true );
|
Pipeline::instance()->resolve( entries, true );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DynamicModel::filteringTrackResolved( bool successful )
|
DynamicModel::filteringTrackResolved( bool successful )
|
||||||
{
|
{
|
||||||
// arg, we don't have the query_ptr, just the Query
|
// arg, we don't have the query_ptr, just the Query
|
||||||
Query* q = qobject_cast< Query* >( sender() );
|
Query* q = qobject_cast< Query* >( sender() );
|
||||||
Q_ASSERT( q );
|
Q_ASSERT( q );
|
||||||
|
|
||||||
|
// if meantime the user began the station, abort
|
||||||
|
if( m_onDemandRunning ) {
|
||||||
|
m_toResolveList.clear();
|
||||||
|
m_resolvedList.clear();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
query_ptr realptr;
|
query_ptr realptr;
|
||||||
foreach( const query_ptr& qptr, m_toResolveList ) {
|
foreach( const query_ptr& qptr, m_toResolveList ) {
|
||||||
if( qptr.data() == q ) {
|
if( qptr.data() == q ) {
|
||||||
@@ -200,53 +208,54 @@ DynamicModel::filteringTrackResolved( bool successful )
|
|||||||
}
|
}
|
||||||
if( realptr.isNull() ) // we already finished
|
if( realptr.isNull() ) // we already finished
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_toResolveList.removeAll( realptr );
|
m_toResolveList.removeAll( realptr );
|
||||||
|
|
||||||
if( successful )
|
if( successful ) {
|
||||||
m_resolvedList << realptr;
|
m_resolvedList << realptr;
|
||||||
|
|
||||||
if( m_toResolveList.isEmpty() || m_resolvedList.size() == m_limitResolvedTo ) { // done, add to playlist
|
// append and update internal lastResolvedRow
|
||||||
if( m_limitResolvedTo < m_resolvedList.count() ) // limit to how many we were asked for
|
addToPlaylist( QList< query_ptr >() << realptr, false );
|
||||||
m_resolvedList = m_resolvedList.mid( 0, m_limitResolvedTo );
|
|
||||||
|
|
||||||
addToPlaylist( m_resolvedList, true );
|
|
||||||
m_toResolveList.clear();
|
|
||||||
m_resolvedList.clear();
|
|
||||||
|
|
||||||
if( m_playlist->mode() == OnDemand ) {
|
if( m_playlist->mode() == OnDemand ) {
|
||||||
m_lastResolvedRow = rowCount( QModelIndex() );
|
m_lastResolvedRow = rowCount( QModelIndex() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( m_toResolveList.isEmpty() || m_resolvedList.size() == m_limitResolvedTo ) { // done
|
||||||
|
m_toResolveList.clear();
|
||||||
|
m_resolvedList.clear();
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( m_toResolveList.isEmpty() && rowCount( QModelIndex() ) == 0 ) // we failed
|
if( m_toResolveList.isEmpty() && rowCount( QModelIndex() ) == 0 ) // we failed
|
||||||
emit trackGenerationFailure( tr( "Could not find a playable track.\n\nPlease change the filters or try again." ) );
|
emit trackGenerationFailure( tr( "Could not find a playable track.\n\nPlease change the filters or try again." ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
DynamicModel::addToPlaylist( const QList< query_ptr >& entries, bool clearFirst )
|
DynamicModel::addToPlaylist( const QList< query_ptr >& entries, bool clearFirst )
|
||||||
{
|
{
|
||||||
if( clearFirst )
|
if( clearFirst )
|
||||||
clear();
|
clear();
|
||||||
|
|
||||||
if( m_playlist->author()->isLocal() && m_playlist->mode() == Static ) {
|
if( m_playlist->author()->isLocal() && m_playlist->mode() == Static ) {
|
||||||
m_playlist->addEntries( entries, m_playlist->currentrevision() );
|
m_playlist->addEntries( entries, m_playlist->currentrevision() );
|
||||||
} else { // read-only, so add tracks only in the GUI, not to the playlist itself
|
} else { // read-only, so add tracks only in the GUI, not to the playlist itself
|
||||||
foreach( const query_ptr& query, entries ) {
|
foreach( const query_ptr& query, entries ) {
|
||||||
append( query );
|
append( query );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
emit tracksAdded();
|
emit tracksAdded();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
DynamicModel::removeIndex(const QModelIndex& idx, bool moreToCome)
|
DynamicModel::removeIndex(const QModelIndex& idx, bool moreToCome)
|
||||||
{
|
{
|
||||||
if ( m_playlist->mode() == Static && isReadOnly() )
|
if ( m_playlist->mode() == Static && isReadOnly() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if( m_playlist->mode() == OnDemand ) {
|
if( m_playlist->mode() == OnDemand ) {
|
||||||
if( !moreToCome && idx == index( rowCount( QModelIndex() ) - 1, 0, QModelIndex() ) ) { // if the user is manually removing the last one, re-add as we're a station
|
if( !moreToCome && idx == index( rowCount( QModelIndex() ) - 1, 0, QModelIndex() ) ) { // if the user is manually removing the last one, re-add as we're a station
|
||||||
newTrackLoading();
|
newTrackLoading();
|
||||||
@@ -255,7 +264,7 @@ DynamicModel::removeIndex(const QModelIndex& idx, bool moreToCome)
|
|||||||
} else
|
} else
|
||||||
PlaylistModel::removeIndex( idx, moreToCome );
|
PlaylistModel::removeIndex( idx, moreToCome );
|
||||||
// don't call onPlaylistChanged.
|
// don't call onPlaylistChanged.
|
||||||
|
|
||||||
if( !moreToCome )
|
if( !moreToCome )
|
||||||
m_lastResolvedRow = rowCount( QModelIndex() );
|
m_lastResolvedRow = rowCount( QModelIndex() );
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user