From 5c60f5d3cc1dd73637e5ed3fae71b52a6facaf63 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Tue, 16 Apr 2013 02:43:54 +0200 Subject: [PATCH] * Fixed TWK-1215: Dupe tracks used to caused playback to loop. --- src/libtomahawk/PlaylistInterface.cpp | 43 ++++++++++++++++++++++++-- src/libtomahawk/PlaylistInterface.h | 4 ++- src/libtomahawk/audio/AudioEngine.cpp | 6 ++-- src/libtomahawk/playlist/TrackView.cpp | 5 +-- 4 files changed, 49 insertions(+), 9 deletions(-) diff --git a/src/libtomahawk/PlaylistInterface.cpp b/src/libtomahawk/PlaylistInterface.cpp index 1dd1e73ef..d9709d7b6 100644 --- a/src/libtomahawk/PlaylistInterface.cpp +++ b/src/libtomahawk/PlaylistInterface.cpp @@ -58,8 +58,8 @@ PlaylistInterface::nextResult() const } -Tomahawk::result_ptr -PlaylistInterface::siblingResult( int itemsAway, qint64 rootIndex ) const +qint64 +PlaylistInterface::siblingResultIndex( int itemsAway, qint64 rootIndex ) const { qint64 idx = siblingIndex( itemsAway, rootIndex ); QList< qint64 > safetyCheck; @@ -73,12 +73,49 @@ PlaylistInterface::siblingResult( int itemsAway, qint64 rootIndex ) const if ( query && query->playable() ) { - return query->results().first(); + return idx; } idx = siblingIndex( itemsAway < 0 ? -1 : 1, idx ); } + return -1; +} + + +Tomahawk::result_ptr +PlaylistInterface::siblingResult( int itemsAway, qint64 rootIndex ) const +{ + qint64 idx = siblingResultIndex( itemsAway, rootIndex ); + if ( idx >= 0 ) + { + Tomahawk::query_ptr query = queryAt( idx ); + + if ( query && query->playable() ) + { + return query->results().first(); + } + } + + return Tomahawk::result_ptr(); +} + + +Tomahawk::result_ptr +PlaylistInterface::setSiblingResult( int itemsAway, qint64 rootIndex ) +{ + qint64 idx = siblingResultIndex( itemsAway, rootIndex ); + if ( idx >= 0 ) + { + Tomahawk::query_ptr query = queryAt( idx ); + + if ( query && query->playable() ) + { + setCurrentIndex( idx ); + return query->results().first(); + } + } + return Tomahawk::result_ptr(); } diff --git a/src/libtomahawk/PlaylistInterface.h b/src/libtomahawk/PlaylistInterface.h index 4cccd3224..bbd4f94d7 100644 --- a/src/libtomahawk/PlaylistInterface.h +++ b/src/libtomahawk/PlaylistInterface.h @@ -53,8 +53,10 @@ public: virtual Tomahawk::result_ptr previousResult() const; virtual qint64 siblingIndex( int itemsAway, qint64 rootIndex = -1 ) const = 0; + 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; diff --git a/src/libtomahawk/audio/AudioEngine.cpp b/src/libtomahawk/audio/AudioEngine.cpp index 5be27baa2..fd6a0b447 100644 --- a/src/libtomahawk/audio/AudioEngine.cpp +++ b/src/libtomahawk/audio/AudioEngine.cpp @@ -558,7 +558,7 @@ AudioEngine::loadPreviousTrack() Tomahawk::result_ptr result; if ( m_playlist.data()->previousResult() ) { - result = m_playlist.data()->previousResult(); + result = m_playlist.data()->setSiblingResult( -1 ); m_currentTrackPlaylist = m_playlist; } @@ -599,7 +599,7 @@ AudioEngine::loadNextTrack() if ( m_playlist.data()->nextResult() ) { - result = m_playlist.data()->nextResult(); + result = m_playlist.data()->setSiblingResult( 1 ); m_currentTrackPlaylist = m_playlist; } } @@ -1004,7 +1004,7 @@ AudioEngine::setCurrentTrack( const Tomahawk::result_ptr& result ) if ( result ) { - if ( m_playlist ) + if ( m_playlist && m_playlist->currentItem() != result ) { m_playlist->setCurrentIndex( m_playlist->indexOfResult( result ) ); } diff --git a/src/libtomahawk/playlist/TrackView.cpp b/src/libtomahawk/playlist/TrackView.cpp index 05613d7c3..d0431ef97 100644 --- a/src/libtomahawk/playlist/TrackView.cpp +++ b/src/libtomahawk/playlist/TrackView.cpp @@ -154,14 +154,14 @@ TrackView::setProxyModel( PlayableProxyModel* model ) disconnect( m_proxyModel, SIGNAL( rowsInserted( QModelIndex, int, int ) ), this, SLOT( verifySize() ) ); disconnect( m_proxyModel, SIGNAL( rowsRemoved( QModelIndex, int, int ) ), this, SLOT( verifySize() ) ); } - + m_proxyModel = model; connect( m_proxyModel, SIGNAL( filterChanged( QString ) ), SLOT( onFilterChanged( QString ) ) ); connect( m_proxyModel, SIGNAL( rowsInserted( QModelIndex, int, int ) ), SLOT( onViewChanged() ) ); connect( m_proxyModel, SIGNAL( rowsInserted( QModelIndex, int, int ) ), SLOT( verifySize() ) ); connect( m_proxyModel, SIGNAL( rowsRemoved( QModelIndex, int, int ) ), SLOT( verifySize() ) ); - + m_delegate = new PlaylistItemDelegate( this, m_proxyModel ); setItemDelegate( m_delegate ); @@ -360,6 +360,7 @@ TrackView::tryToPlayItem( const QModelIndex& index ) PlayableItem* item = m_model->itemFromIndex( m_proxyModel->mapToSource( index ) ); if ( item && !item->query().isNull() ) { + m_model->setCurrentIndex( m_proxyModel->mapToSource( index ) ); AudioEngine::instance()->playItem( playlistInterface(), item->query() ); return true;