From 5b0ed433f5303c3782d2a5719408253aa84cfe41 Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Mon, 2 May 2011 23:05:59 -0400 Subject: [PATCH] fix recent playlists --- src/libtomahawk/widgets/welcomeplaylistmodel.cpp | 12 ++++++++++-- src/libtomahawk/widgets/welcomeplaylistmodel.h | 2 ++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/libtomahawk/widgets/welcomeplaylistmodel.cpp b/src/libtomahawk/widgets/welcomeplaylistmodel.cpp index ba48f1289..d15760601 100644 --- a/src/libtomahawk/widgets/welcomeplaylistmodel.cpp +++ b/src/libtomahawk/widgets/welcomeplaylistmodel.cpp @@ -27,10 +27,11 @@ using namespace Tomahawk; WelcomePlaylistModel::WelcomePlaylistModel( QObject* parent ) : QAbstractListModel( parent ) + , m_waitingForSome( true ) { loadFromSettings(); - connect( SourceList::instance(), SIGNAL( sourceAdded( Tomahawk::source_ptr ) ), SLOT( loadFromSettings() ), Qt::QueuedConnection ); + connect( SourceList::instance(), SIGNAL( sourceAdded( Tomahawk::source_ptr ) ), this, SLOT( onSourceAdded( Tomahawk::source_ptr ) ), Qt::QueuedConnection ); connect( TomahawkSettings::instance(), SIGNAL( recentlyPlayedPlaylistAdded( Tomahawk::playlist_ptr ) ), this, SLOT( plAdded( Tomahawk::playlist_ptr ) ) ); connect( AudioEngine::instance(),SIGNAL( playlistChanged( PlaylistInterface* ) ), this, SLOT( playlistChanged( PlaylistInterface* ) ), Qt::QueuedConnection ); @@ -40,8 +41,12 @@ WelcomePlaylistModel::WelcomePlaylistModel( QObject* parent ) void WelcomePlaylistModel::loadFromSettings() { + if( !m_waitingForSome ) + return; + beginResetModel(); m_recplaylists.clear(); + m_waitingForSome = false; QStringList playlist_guids = TomahawkSettings::instance()->recentlyPlayedPlaylistGuids(); @@ -58,7 +63,8 @@ WelcomePlaylistModel::loadFromSettings() if( !m_cached.contains( playlist_guids[i] ) ) m_cached[playlist_guids[i]] = pl; - } + } else + m_waitingForSome = true; } endResetModel(); @@ -66,6 +72,7 @@ WelcomePlaylistModel::loadFromSettings() } + QVariant WelcomePlaylistModel::data( const QModelIndex& index, int role ) const { @@ -107,6 +114,7 @@ WelcomePlaylistModel::data( const QModelIndex& index, int role ) const void WelcomePlaylistModel::onSourceAdded( const Tomahawk::source_ptr& source ) { + connect( source->collection().data(), SIGNAL( playlistsAdded( QList ) ), SLOT( loadFromSettings() ) ); connect( source->collection().data(), SIGNAL( playlistsDeleted( QList ) ), SLOT( onPlaylistsRemoved( QList ) ) ); } diff --git a/src/libtomahawk/widgets/welcomeplaylistmodel.h b/src/libtomahawk/widgets/welcomeplaylistmodel.h index 0127ce3cd..4c8b13b59 100644 --- a/src/libtomahawk/widgets/welcomeplaylistmodel.h +++ b/src/libtomahawk/widgets/welcomeplaylistmodel.h @@ -52,6 +52,8 @@ private: QList< Tomahawk::playlist_ptr > m_recplaylists; QHash< QString, Tomahawk::playlist_ptr > m_cached; mutable QHash< Tomahawk::playlist_ptr, QString > m_artists; + + bool m_waitingForSome; }; #endif // WELCOMEPLAYLISTMODEL_H