mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-04-22 00:42:04 +02:00
PlaylistInterface emits a signal when the first playable track has been resolved.
This commit is contained in:
parent
15356eba47
commit
cf7ce9aa0e
@ -141,7 +141,7 @@ AlbumPlaylistInterface::tracks() const
|
||||
|
||||
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?
|
||||
{
|
||||
@ -205,7 +205,6 @@ AlbumPlaylistInterface::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData re
|
||||
Pipeline::instance()->resolve( ql );
|
||||
|
||||
m_queries << ql;
|
||||
checkQueries();
|
||||
}
|
||||
|
||||
break;
|
||||
@ -238,7 +237,7 @@ AlbumPlaylistInterface::infoSystemFinished( const QString& infoId )
|
||||
this, SLOT( infoSystemFinished( QString ) ) );
|
||||
|
||||
// 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?
|
||||
{
|
||||
@ -262,7 +261,7 @@ AlbumPlaylistInterface::infoSystemFinished( const QString& infoId )
|
||||
}
|
||||
else
|
||||
{
|
||||
m_finished = true;
|
||||
finishLoading();
|
||||
emit tracksLoaded( m_mode, m_collection );
|
||||
}
|
||||
}
|
||||
@ -279,9 +278,7 @@ AlbumPlaylistInterface::onTracksLoaded( const QList< query_ptr >& tracks )
|
||||
else
|
||||
m_queries << tracks;
|
||||
|
||||
checkQueries();
|
||||
|
||||
m_finished = true;
|
||||
finishLoading();
|
||||
emit tracksLoaded( m_mode, m_collection );
|
||||
}
|
||||
|
||||
@ -339,13 +336,3 @@ AlbumPlaylistInterface::resultAt( qint64 index ) const
|
||||
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
@ -70,8 +70,6 @@ private slots:
|
||||
void infoSystemFinished( const QString& infoId );
|
||||
|
||||
private:
|
||||
void checkQueries();
|
||||
|
||||
QList< Tomahawk::query_ptr > m_queries;
|
||||
mutable result_ptr m_currentItem;
|
||||
|
||||
|
@ -162,7 +162,6 @@ ArtistPlaylistInterface::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData r
|
||||
}
|
||||
|
||||
m_queries << ql;
|
||||
checkQueries();
|
||||
}
|
||||
|
||||
break;
|
||||
@ -207,7 +206,7 @@ ArtistPlaylistInterface::infoSystemFinished( const QString &infoId )
|
||||
}
|
||||
else
|
||||
{
|
||||
m_finished = true;
|
||||
finishLoading();
|
||||
emit tracksLoaded( m_mode, m_collection );
|
||||
}
|
||||
}
|
||||
@ -224,9 +223,7 @@ ArtistPlaylistInterface::onTracksLoaded( const QList< query_ptr >& tracks )
|
||||
else
|
||||
m_queries << tracks;
|
||||
|
||||
checkQueries();
|
||||
|
||||
m_finished = true;
|
||||
finishLoading();
|
||||
emit tracksLoaded( m_mode, m_collection );
|
||||
}
|
||||
|
||||
@ -284,13 +281,3 @@ ArtistPlaylistInterface::resultAt( qint64 index ) const
|
||||
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
@ -69,8 +69,6 @@ private slots:
|
||||
private:
|
||||
Q_DISABLE_COPY( ArtistPlaylistInterface )
|
||||
|
||||
void checkQueries();
|
||||
|
||||
QList< Tomahawk::query_ptr > m_queries;
|
||||
mutable result_ptr m_currentItem;
|
||||
|
||||
|
@ -30,10 +30,11 @@ using namespace Tomahawk;
|
||||
PlaylistInterface::PlaylistInterface()
|
||||
: QObject()
|
||||
, m_latchMode( PlaylistModes::StayOnSong )
|
||||
, m_finished( false )
|
||||
, m_prevAvail( false )
|
||||
, m_nextAvail( false )
|
||||
, m_currentIndex( -1 )
|
||||
, m_finished( false )
|
||||
, m_foundFirstTrack( false )
|
||||
{
|
||||
m_id = uuid();
|
||||
}
|
||||
@ -246,3 +247,51 @@ PlaylistInterface::setCurrentIndex( qint64 index )
|
||||
emit currentIndexChanged();
|
||||
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() ) );
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,8 @@ public:
|
||||
const QString id() const { return m_id; }
|
||||
|
||||
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;
|
||||
|
||||
@ -56,7 +57,7 @@ public:
|
||||
virtual qint64 siblingResultIndex( 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 resultAt( qint64 index ) const = 0;
|
||||
virtual Tomahawk::query_ptr queryAt( qint64 index ) const = 0;
|
||||
virtual qint64 indexOfResult( const Tomahawk::result_ptr& result ) const = 0;
|
||||
@ -102,15 +103,18 @@ signals:
|
||||
void nextTrackAvailable( bool available );
|
||||
|
||||
void currentIndexChanged();
|
||||
void finishedLoading();
|
||||
void foundFirstPlayableTrack();
|
||||
|
||||
protected slots:
|
||||
virtual void onItemsChanged();
|
||||
void finishLoading();
|
||||
void onQueryResolved();
|
||||
|
||||
protected:
|
||||
virtual QList<Tomahawk::query_ptr> filterTracks( const QList<Tomahawk::query_ptr>& queries );
|
||||
|
||||
PlaylistModes::LatchMode m_latchMode;
|
||||
bool m_finished;
|
||||
mutable bool m_prevAvail;
|
||||
mutable bool m_nextAvail;
|
||||
mutable qint64 m_currentIndex;
|
||||
@ -121,6 +125,8 @@ private:
|
||||
private:
|
||||
QString m_id;
|
||||
QString m_filter;
|
||||
bool m_finished;
|
||||
bool m_foundFirstTrack;
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user