From 461854d158170ef280d017b281a228fa54d5c480 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Fri, 17 Jun 2011 13:33:38 -0400 Subject: [PATCH] Don't endlessely loop on a track when following if the person you're following stops playing. Also don't crash if they go away or time out. --- src/libtomahawk/sourceplaylistinterface.cpp | 16 +++++++++++----- src/libtomahawk/sourceplaylistinterface.h | 3 ++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/libtomahawk/sourceplaylistinterface.cpp b/src/libtomahawk/sourceplaylistinterface.cpp index 550222463..27c30cf39 100644 --- a/src/libtomahawk/sourceplaylistinterface.cpp +++ b/src/libtomahawk/sourceplaylistinterface.cpp @@ -28,6 +28,7 @@ using namespace Tomahawk; SourcePlaylistInterface::SourcePlaylistInterface( Tomahawk::source_ptr& source ) : PlaylistInterface( this ) , m_source( source ) + , m_gotNextSong( false ) { connect( source.data(), SIGNAL( playbackStarted( const Tomahawk::query_ptr& ) ), SLOT( onSourcePlaybackStarted( const Tomahawk::query_ptr& ) ) ); } @@ -38,12 +39,14 @@ SourcePlaylistInterface::siblingItem( int itemsAway ) { Q_UNUSED( itemsAway ); qDebug() << Q_FUNC_INFO; - if ( m_source->currentTrack()->results().empty() ) + if ( !m_gotNextSong || m_source.isNull() || m_source->currentTrack().isNull() || m_source->currentTrack()->results().isEmpty() ) { - qDebug() << Q_FUNC_INFO << " Results were empty for current track"; + qDebug() << Q_FUNC_INFO << " Results were empty for current track or source no longer valid"; return Tomahawk::result_ptr(); } + m_gotNextSong = false; + return m_source->currentTrack()->results().first(); } @@ -52,12 +55,14 @@ Tomahawk::result_ptr SourcePlaylistInterface::nextItem() { qDebug() << Q_FUNC_INFO; - if ( m_source->currentTrack()->results().empty() ) + if ( !m_gotNextSong || m_source.isNull() || m_source->currentTrack().isNull() || m_source->currentTrack()->results().isEmpty() ) { - qDebug() << Q_FUNC_INFO << " Results were empty for current track"; + qDebug() << Q_FUNC_INFO << " Results were empty for current track or source no longer valid"; return Tomahawk::result_ptr(); } + m_gotNextSong = false; + return m_source->currentTrack()->results().first(); } @@ -70,12 +75,13 @@ SourcePlaylistInterface::tracks() void -SourcePlaylistInterface::onSourcePlaybackStarted( const Tomahawk::query_ptr& query ) const +SourcePlaylistInterface::onSourcePlaybackStarted( const Tomahawk::query_ptr& query ) { qDebug() << Q_FUNC_INFO; connect( query.data(), SIGNAL( resultsAdded( const QList& ) ), SLOT( resolveResultsAdded( const QList& ) ) ); connect( query.data(), SIGNAL( resolvingFinished( bool ) ), SLOT( resolvingFinished( bool ) ) ); Pipeline::instance()->resolve( query, true ); + m_gotNextSong = true; } diff --git a/src/libtomahawk/sourceplaylistinterface.h b/src/libtomahawk/sourceplaylistinterface.h index 56d2768d0..3a32a285b 100644 --- a/src/libtomahawk/sourceplaylistinterface.h +++ b/src/libtomahawk/sourceplaylistinterface.h @@ -63,12 +63,13 @@ signals: void sourceTrackCountChanged( unsigned int tracks ); private slots: - void onSourcePlaybackStarted( const Tomahawk::query_ptr& query ) const; + void onSourcePlaybackStarted( const Tomahawk::query_ptr& query ); void resolveResultsAdded( const QList& results ) const; void resolvingFinished( bool hasResults ) const; private: Tomahawk::source_ptr m_source; + bool m_gotNextSong; }; }; // ns