1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-07-31 03:10:12 +02:00

PlaylistInterface emits a signal when the first playable track has been resolved.

This commit is contained in:
Christian Muehlhaeuser
2014-11-12 09:24:12 +01:00
parent 15356eba47
commit cf7ce9aa0e
6 changed files with 65 additions and 40 deletions

View File

@@ -141,7 +141,7 @@ AlbumPlaylistInterface::tracks() const
const_cast< int& >( m_lastQueryTimestamp ) = QDateTime::currentMSecsSinceEpoch(); const_cast< int& >( m_lastQueryTimestamp ) = QDateTime::currentMSecsSinceEpoch();
} }
else if ( m_mode == DatabaseMode && !m_databaseLoaded && !m_finished ) else if ( m_mode == DatabaseMode && !m_databaseLoaded && !isFinished() )
{ {
if ( m_collection.isNull() ) //we do a dbcmd directly, for the SuperCollection I guess? if ( m_collection.isNull() ) //we do a dbcmd directly, for the SuperCollection I guess?
{ {
@@ -205,7 +205,6 @@ AlbumPlaylistInterface::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData re
Pipeline::instance()->resolve( ql ); Pipeline::instance()->resolve( ql );
m_queries << ql; m_queries << ql;
checkQueries();
} }
break; break;
@@ -238,7 +237,7 @@ AlbumPlaylistInterface::infoSystemFinished( const QString& infoId )
this, SLOT( infoSystemFinished( QString ) ) ); this, SLOT( infoSystemFinished( QString ) ) );
// Add !m_finished check to not endlessly reload on an empty album. // Add !m_finished check to not endlessly reload on an empty album.
if ( m_queries.isEmpty() && m_mode == Mixed && !m_finished ) if ( m_queries.isEmpty() && m_mode == Mixed && !isFinished() )
{ {
if ( m_collection.isNull() ) //we do a dbcmd directly, for the SuperCollection I guess? if ( m_collection.isNull() ) //we do a dbcmd directly, for the SuperCollection I guess?
{ {
@@ -262,7 +261,7 @@ AlbumPlaylistInterface::infoSystemFinished( const QString& infoId )
} }
else else
{ {
m_finished = true; finishLoading();
emit tracksLoaded( m_mode, m_collection ); emit tracksLoaded( m_mode, m_collection );
} }
} }
@@ -279,9 +278,7 @@ AlbumPlaylistInterface::onTracksLoaded( const QList< query_ptr >& tracks )
else else
m_queries << tracks; m_queries << tracks;
checkQueries(); finishLoading();
m_finished = true;
emit tracksLoaded( m_mode, m_collection ); emit tracksLoaded( m_mode, m_collection );
} }
@@ -339,13 +336,3 @@ AlbumPlaylistInterface::resultAt( qint64 index ) const
return Tomahawk::result_ptr(); return Tomahawk::result_ptr();
} }
void
AlbumPlaylistInterface::checkQueries()
{
foreach ( const Tomahawk::query_ptr& query, m_queries )
{
connect( query.data(), SIGNAL( playableStateChanged( bool ) ), SLOT( onItemsChanged() ), Qt::UniqueConnection );
}
}

View File

@@ -70,8 +70,6 @@ private slots:
void infoSystemFinished( const QString& infoId ); void infoSystemFinished( const QString& infoId );
private: private:
void checkQueries();
QList< Tomahawk::query_ptr > m_queries; QList< Tomahawk::query_ptr > m_queries;
mutable result_ptr m_currentItem; mutable result_ptr m_currentItem;

View File

@@ -162,7 +162,6 @@ ArtistPlaylistInterface::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData r
} }
m_queries << ql; m_queries << ql;
checkQueries();
} }
break; break;
@@ -207,7 +206,7 @@ ArtistPlaylistInterface::infoSystemFinished( const QString &infoId )
} }
else else
{ {
m_finished = true; finishLoading();
emit tracksLoaded( m_mode, m_collection ); emit tracksLoaded( m_mode, m_collection );
} }
} }
@@ -224,9 +223,7 @@ ArtistPlaylistInterface::onTracksLoaded( const QList< query_ptr >& tracks )
else else
m_queries << tracks; m_queries << tracks;
checkQueries(); finishLoading();
m_finished = true;
emit tracksLoaded( m_mode, m_collection ); emit tracksLoaded( m_mode, m_collection );
} }
@@ -284,13 +281,3 @@ ArtistPlaylistInterface::resultAt( qint64 index ) const
return Tomahawk::result_ptr(); return Tomahawk::result_ptr();
} }
void
ArtistPlaylistInterface::checkQueries()
{
foreach ( const Tomahawk::query_ptr& query, m_queries )
{
connect( query.data(), SIGNAL( playableStateChanged( bool ) ), SLOT( onItemsChanged() ), Qt::UniqueConnection );
}
}

View File

@@ -69,8 +69,6 @@ private slots:
private: private:
Q_DISABLE_COPY( ArtistPlaylistInterface ) Q_DISABLE_COPY( ArtistPlaylistInterface )
void checkQueries();
QList< Tomahawk::query_ptr > m_queries; QList< Tomahawk::query_ptr > m_queries;
mutable result_ptr m_currentItem; mutable result_ptr m_currentItem;

View File

@@ -30,10 +30,11 @@ using namespace Tomahawk;
PlaylistInterface::PlaylistInterface() PlaylistInterface::PlaylistInterface()
: QObject() : QObject()
, m_latchMode( PlaylistModes::StayOnSong ) , m_latchMode( PlaylistModes::StayOnSong )
, m_finished( false )
, m_prevAvail( false ) , m_prevAvail( false )
, m_nextAvail( false ) , m_nextAvail( false )
, m_currentIndex( -1 ) , m_currentIndex( -1 )
, m_finished( false )
, m_foundFirstTrack( false )
{ {
m_id = uuid(); m_id = uuid();
} }
@@ -246,3 +247,51 @@ PlaylistInterface::setCurrentIndex( qint64 index )
emit currentIndexChanged(); emit currentIndexChanged();
onItemsChanged(); onItemsChanged();
} }
void
PlaylistInterface::finishLoading()
{
foreach ( const Tomahawk::query_ptr& query, tracks() )
{
connect( query.data(), SIGNAL( playableStateChanged( bool ) ), SLOT( onItemsChanged() ), Qt::UniqueConnection );
connect( query.data(), SIGNAL( resolvingFinished( bool ) ), SLOT( onQueryResolved() ), Qt::UniqueConnection );
}
m_finished = true;
emit finishedLoading();
}
void
PlaylistInterface::onQueryResolved()
{
if ( m_foundFirstTrack )
return;
// We're looking for the first playable track, but want to make sure the
// second track doesn't start playing before the first really finished resolving
foreach ( const Tomahawk::query_ptr& query, tracks() )
{
if ( !query->resolvingFinished() )
{
// Wait for this track to be resolved
return;
}
if ( query->playable() )
{
// We have a playable track, all previous tracks are resolved but not playable
break;
}
}
// We have either found the first playable track or none of the tracks are playable
m_foundFirstTrack = true;
emit foundFirstPlayableTrack();
foreach ( const Tomahawk::query_ptr& query, tracks() )
{
disconnect( query.data(), SIGNAL( resolvingFinished( bool ) ), this, SLOT( onQueryResolved() ) );
}
}

View File

@@ -40,7 +40,8 @@ public:
const QString id() const { return m_id; } const QString id() const { return m_id; }
virtual QList< Tomahawk::query_ptr > tracks() const = 0; virtual QList< Tomahawk::query_ptr > tracks() const = 0;
virtual bool isFinished() const { return m_finished; } bool isFinished() const { return m_finished; }
bool hasFirstPlayableTrack() const { return m_foundFirstTrack; }
virtual int trackCount() const = 0; virtual int trackCount() const = 0;
@@ -56,7 +57,7 @@ public:
virtual qint64 siblingResultIndex( int itemsAway, qint64 rootIndex = -1 ) const; virtual qint64 siblingResultIndex( int itemsAway, qint64 rootIndex = -1 ) const;
virtual Tomahawk::result_ptr siblingResult( int itemsAway, qint64 rootIndex = -1 ) const; virtual Tomahawk::result_ptr siblingResult( int itemsAway, qint64 rootIndex = -1 ) const;
virtual Tomahawk::result_ptr setSiblingResult( int itemsAway, qint64 rootIndex = -1 ); virtual Tomahawk::result_ptr setSiblingResult( int itemsAway, qint64 rootIndex = -1 );
virtual Tomahawk::result_ptr resultAt( qint64 index ) const = 0; virtual Tomahawk::result_ptr resultAt( qint64 index ) const = 0;
virtual Tomahawk::query_ptr queryAt( qint64 index ) const = 0; virtual Tomahawk::query_ptr queryAt( qint64 index ) const = 0;
virtual qint64 indexOfResult( const Tomahawk::result_ptr& result ) const = 0; virtual qint64 indexOfResult( const Tomahawk::result_ptr& result ) const = 0;
@@ -102,15 +103,18 @@ signals:
void nextTrackAvailable( bool available ); void nextTrackAvailable( bool available );
void currentIndexChanged(); void currentIndexChanged();
void finishedLoading();
void foundFirstPlayableTrack();
protected slots: protected slots:
virtual void onItemsChanged(); virtual void onItemsChanged();
void finishLoading();
void onQueryResolved();
protected: protected:
virtual QList<Tomahawk::query_ptr> filterTracks( const QList<Tomahawk::query_ptr>& queries ); virtual QList<Tomahawk::query_ptr> filterTracks( const QList<Tomahawk::query_ptr>& queries );
PlaylistModes::LatchMode m_latchMode; PlaylistModes::LatchMode m_latchMode;
bool m_finished;
mutable bool m_prevAvail; mutable bool m_prevAvail;
mutable bool m_nextAvail; mutable bool m_nextAvail;
mutable qint64 m_currentIndex; mutable qint64 m_currentIndex;
@@ -121,6 +125,8 @@ private:
private: private:
QString m_id; QString m_id;
QString m_filter; QString m_filter;
bool m_finished;
bool m_foundFirstTrack;
}; };
} }