From 23fb6aec5676cba1a58e64f7cb9e12b72802aef7 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Wed, 28 Nov 2012 12:48:58 +0100 Subject: [PATCH 1/4] * Added a safety check in PlaylistInterface to prevent infinite looping. --- src/libtomahawk/PlaylistInterface.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/libtomahawk/PlaylistInterface.cpp b/src/libtomahawk/PlaylistInterface.cpp index 928c19174..80d851805 100644 --- a/src/libtomahawk/PlaylistInterface.cpp +++ b/src/libtomahawk/PlaylistInterface.cpp @@ -58,9 +58,13 @@ Tomahawk::result_ptr PlaylistInterface::siblingResult( int itemsAway ) const { qint64 idx = siblingIndex( itemsAway ); + qint64 safetyCheck = 0; - while ( idx >= 0 ) + // If safetyCheck equals idx, this means the interface keeps returning the same item and we won't discover anything new - abort + // This can happen in repeat / random mode e.g. + while ( idx >= 0 && safetyCheck != idx ) { + safetyCheck = idx; Tomahawk::query_ptr query = queryAt( idx ); if ( query->numResults() ) { From 5b213f1ac4ce0c3ebaa0125a661720a0cfbde91f Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Wed, 28 Nov 2012 12:54:48 +0100 Subject: [PATCH 2/4] * Be more consistent when enabling the prev/next buttons. --- .../playlist/PlayableProxyModelPlaylistInterface.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/libtomahawk/playlist/PlayableProxyModelPlaylistInterface.cpp b/src/libtomahawk/playlist/PlayableProxyModelPlaylistInterface.cpp index 850bf0b20..5bb3c3dbd 100644 --- a/src/libtomahawk/playlist/PlayableProxyModelPlaylistInterface.cpp +++ b/src/libtomahawk/playlist/PlayableProxyModelPlaylistInterface.cpp @@ -191,6 +191,9 @@ PlayableProxyModelPlaylistInterface::siblingIndex( int itemsAway, qint64 rootInd } else { + if ( !proxyModel->currentIndex().isValid() ) + return -1; + // random mode is enabled if ( m_shuffleCache.isValid() ) { @@ -207,7 +210,7 @@ PlayableProxyModelPlaylistInterface::siblingIndex( int itemsAway, qint64 rootInd item = proxyModel->itemFromIndex( proxyModel->mapToSource( idx ) ); } while ( safetyCounter < proxyModel->rowCount() && - ( !item || !item->query()->playable() || m_shuffleHistory.contains( item->query() ) ) ); + ( !item || !item->query()->playable() || m_shuffleHistory.contains( item->query() ) ) ); if ( item && item->query()->playable() ) { @@ -252,6 +255,9 @@ PlayableProxyModelPlaylistInterface::siblingIndex( int itemsAway, qint64 rootInd if ( !idx.isValid() && m_repeatMode == PlaylistModes::RepeatAll ) { + if ( !proxyModel->currentIndex().isValid() ) + return -1; + // repeat all tracks if ( itemsAway > 0 ) { From a0b5006a731f74c268980464588365bf4060f6bd Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Wed, 28 Nov 2012 12:55:49 +0100 Subject: [PATCH 3/4] * Remove mode handling from ViewManager. --- src/libtomahawk/ViewManager.cpp | 51 --------------------------------- src/libtomahawk/ViewManager.h | 2 -- 2 files changed, 53 deletions(-) diff --git a/src/libtomahawk/ViewManager.cpp b/src/libtomahawk/ViewManager.cpp index ae44c171b..c11074012 100644 --- a/src/libtomahawk/ViewManager.cpp +++ b/src/libtomahawk/ViewManager.cpp @@ -121,7 +121,6 @@ ViewManager::ViewManager( QObject* parent ) ViewManager::~ViewManager() { - saveCurrentPlaylistSettings(); delete m_whatsHotWidget; delete m_newReleasesWidget; delete m_welcomeWidget; @@ -525,8 +524,6 @@ ViewManager::setPage( ViewPage* page, bool trackHistory ) if ( page == m_currentPage ) return; - // save the old playlist shuffle state in config before we change playlists - saveCurrentPlaylistSettings(); unlinkPlaylist(); if ( m_stack->indexOf( page->widget() ) < 0 ) @@ -606,29 +603,6 @@ ViewManager::unlinkPlaylist() } -void -ViewManager::saveCurrentPlaylistSettings() -{ - TomahawkSettings* s = TomahawkSettings::instance(); - Tomahawk::playlist_ptr pl = playlistForInterface( currentPlaylistInterface() ); - - if ( !pl.isNull() ) - { - s->setShuffleState( pl->guid(), currentPlaylistInterface()->shuffled() ); - s->setRepeatMode( pl->guid(), currentPlaylistInterface()->repeatMode() ); - } - else - { - Tomahawk::dynplaylist_ptr dynPl = dynamicPlaylistForInterface( currentPlaylistInterface() ); - if ( !dynPl.isNull() ) - { - s->setShuffleState( dynPl->guid(), currentPlaylistInterface()->shuffled() ); - s->setRepeatMode( dynPl->guid(), currentPlaylistInterface()->repeatMode() ); - } - } -} - - void ViewManager::updateView() { @@ -672,31 +646,6 @@ ViewManager::updateView() } m_infobar->setLongDescription( currentPage()->longDescription() ); m_infobar->setPixmap( currentPage()->pixmap() ); - - // turn on shuffle/repeat mode for the new playlist view if specified in config - loadCurrentPlaylistSettings(); -} - - -void -ViewManager::loadCurrentPlaylistSettings() -{ - TomahawkSettings* s = TomahawkSettings::instance(); - Tomahawk::playlist_ptr pl = playlistForInterface( currentPlaylistInterface() ); - - if ( !pl.isNull() ) - { - currentPlaylistInterface()->setShuffled( s->shuffleState( pl->guid() )); - currentPlaylistInterface()->setRepeatMode( s->repeatMode( pl->guid() )); - } - else - { - Tomahawk::dynplaylist_ptr dynPl = dynamicPlaylistForInterface( currentPlaylistInterface() ); - if ( !dynPl.isNull() ) - { - currentPlaylistInterface()->setShuffled( s->shuffleState( dynPl->guid() )); - } - } } diff --git a/src/libtomahawk/ViewManager.h b/src/libtomahawk/ViewManager.h index 238897f02..5b7d86e25 100644 --- a/src/libtomahawk/ViewManager.h +++ b/src/libtomahawk/ViewManager.h @@ -175,8 +175,6 @@ private: void setPage( Tomahawk::ViewPage* page, bool trackHistory = true ); void updateView(); void unlinkPlaylist(); - void saveCurrentPlaylistSettings(); - void loadCurrentPlaylistSettings(); Tomahawk::playlist_ptr playlistForInterface( Tomahawk::playlistinterface_ptr plInterface ) const; Tomahawk::dynplaylist_ptr dynamicPlaylistForInterface( Tomahawk::playlistinterface_ptr plInterface ) const; From a0e3d58561aa0ed3cc0c64f34903bd050e87a9a2 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Wed, 28 Nov 2012 12:56:20 +0100 Subject: [PATCH 4/4] * Store PlaylistInterface modes for all TrackViews. --- src/libtomahawk/playlist/TrackView.cpp | 53 ++++++++++++++++++++------ src/libtomahawk/playlist/TrackView.h | 4 +- 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/src/libtomahawk/playlist/TrackView.cpp b/src/libtomahawk/playlist/TrackView.cpp index 5a66e2ba7..fcd77f183 100644 --- a/src/libtomahawk/playlist/TrackView.cpp +++ b/src/libtomahawk/playlist/TrackView.cpp @@ -28,17 +28,18 @@ #include "PlayableModel.h" #include "PlayableProxyModel.h" #include "PlayableItem.h" -#include "audio/AudioEngine.h" -#include "context/ContextWidget.h" -#include "widgets/OverlayWidget.h" -#include "utils/TomahawkUtilsGui.h" -#include "utils/Logger.h" -#include "utils/Closure.h" #include "DropJob.h" #include "Artist.h" #include "Album.h" #include "Source.h" +#include "TomahawkSettings.h" +#include "audio/AudioEngine.h" +#include "context/ContextWidget.h" +#include "widgets/OverlayWidget.h" +#include "utils/TomahawkUtilsGui.h" +#include "utils/Closure.h" #include "utils/AnimatedSpinner.h" +#include "utils/Logger.h" #define SCROLL_TIMEOUT 280 @@ -95,19 +96,47 @@ TrackView::TrackView( QWidget* parent ) TrackView::~TrackView() { - tDebug() << Q_FUNC_INFO; + tDebug() << Q_FUNC_INFO << ( m_guid.isEmpty() ? QString( "with empty guid" ) : QString( "with guid %1" ).arg( m_guid ) ); + + if ( !m_guid.isEmpty() && proxyModel()->playlistInterface() ) + { + tDebug() << Q_FUNC_INFO << "Storing shuffle & random mode settings for guid" << m_guid; + + TomahawkSettings* s = TomahawkSettings::instance(); + s->setShuffleState( m_guid, proxyModel()->playlistInterface()->shuffled() ); + s->setRepeatMode( m_guid, proxyModel()->playlistInterface()->repeatMode() ); + } +} + + +QString +TrackView::guid() const +{ + if ( m_guid.isEmpty() ) + return QString(); + + return QString( "%1/%2" ).arg( m_guid ).arg( m_proxyModel->columnCount() ); } void -TrackView::setGuid( const QString& guid ) +TrackView::setGuid( const QString& newguid ) { - if ( !guid.isEmpty() ) + if ( !newguid.isEmpty() ) { - tDebug() << Q_FUNC_INFO << "Setting guid on header" << guid << "for a view with" << m_proxyModel->columnCount() << "columns"; + tDebug() << Q_FUNC_INFO << "Setting guid on header" << newguid << "for a view with" << m_proxyModel->columnCount() << "columns"; - m_guid = QString( "%1/%2" ).arg( guid ).arg( m_proxyModel->columnCount() ); - m_header->setGuid( m_guid ); + m_guid = newguid; + m_header->setGuid( guid() ); + + if ( !m_guid.isEmpty() && proxyModel()->playlistInterface() ) + { + tDebug() << Q_FUNC_INFO << "Restoring shuffle & random mode settings for guid" << m_guid; + + TomahawkSettings* s = TomahawkSettings::instance(); + proxyModel()->playlistInterface()->setShuffled( s->shuffleState( m_guid ) ); + proxyModel()->playlistInterface()->setRepeatMode( s->repeatMode( m_guid ) ); + } } } diff --git a/src/libtomahawk/playlist/TrackView.h b/src/libtomahawk/playlist/TrackView.h index 28ccacf8b..b840c3576 100644 --- a/src/libtomahawk/playlist/TrackView.h +++ b/src/libtomahawk/playlist/TrackView.h @@ -45,8 +45,8 @@ public: explicit TrackView( QWidget* parent = 0 ); ~TrackView(); - virtual QString guid() const { return m_guid; } - virtual void setGuid( const QString& guid ); + virtual QString guid() const; + virtual void setGuid( const QString& newguid ); virtual void setPlayableModel( PlayableModel* model ); virtual void setModel( QAbstractItemModel* model );