From 5a64fc1361de8e492b2e2a1fe27d3f20981f06ce Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Thu, 19 May 2011 03:12:46 +0200 Subject: [PATCH] * Protect DynamicPlaylists, too. * Only load the five most recent playlists & 25 tracks in the WelcomeWidget. --- .../databasecommand_setplaylistrevision.cpp | 1 - src/libtomahawk/playlist.cpp | 3 +- src/libtomahawk/playlist.h | 1 + .../playlist/dynamic/DynamicPlaylist.cpp | 39 +++++++++++-------- src/libtomahawk/playlist/playlistmodel.cpp | 6 ++- src/libtomahawk/tomahawksettings.cpp | 9 ++++- src/libtomahawk/tomahawksettings.h | 2 +- .../widgets/welcomeplaylistmodel.cpp | 3 +- .../widgets/welcomeplaylistmodel.h | 4 ++ src/libtomahawk/widgets/welcomewidget.cpp | 11 +++--- 10 files changed, 50 insertions(+), 29 deletions(-) diff --git a/src/libtomahawk/database/databasecommand_setplaylistrevision.cpp b/src/libtomahawk/database/databasecommand_setplaylistrevision.cpp index 0343c781a..fb01e40be 100644 --- a/src/libtomahawk/database/databasecommand_setplaylistrevision.cpp +++ b/src/libtomahawk/database/databasecommand_setplaylistrevision.cpp @@ -40,7 +40,6 @@ DatabaseCommand_SetPlaylistRevision::DatabaseCommand_SetPlaylistRevision( , m_entries( entries ) { Q_ASSERT( !newrev.isEmpty() ); - Q_ASSERT( !oldrev.isEmpty() ); m_localOnly = ( newrev == oldrev ); setPlaylistguid( playlistguid ); diff --git a/src/libtomahawk/playlist.cpp b/src/libtomahawk/playlist.cpp index b72699d36..dcfd29737 100644 --- a/src/libtomahawk/playlist.cpp +++ b/src/libtomahawk/playlist.cpp @@ -175,7 +175,7 @@ Playlist::create( const source_ptr& author, // reportCreated for us automatically, which should cause new playlists to be added to the GUI. DatabaseCommand_CreatePlaylist* cmd = new DatabaseCommand_CreatePlaylist( author, playlist ); - connect( cmd, SIGNAL(finished()), playlist.data(), SIGNAL(created()) ); + connect( cmd, SIGNAL( finished() ), playlist.data(), SIGNAL( created() ) ); Database::instance()->enqueue( QSharedPointer(cmd) ); playlist->reportCreated( playlist ); return playlist; @@ -244,6 +244,7 @@ Playlist::loadRevision( const QString& rev ) { qDebug() << Q_FUNC_INFO << currentrevision() << rev << m_title; + setBusy( true ); DatabaseCommand_LoadPlaylistEntries* cmd = new DatabaseCommand_LoadPlaylistEntries( rev.isEmpty() ? currentrevision() : rev ); diff --git a/src/libtomahawk/playlist.h b/src/libtomahawk/playlist.h index e29a6651b..47a744843 100644 --- a/src/libtomahawk/playlist.h +++ b/src/libtomahawk/playlist.h @@ -114,6 +114,7 @@ Q_PROPERTY( bool shared READ shared WRITE setShared ) friend class ::DatabaseCommand_LoadAllPlaylists; friend class ::DatabaseCommand_SetPlaylistRevision; friend class ::DatabaseCommand_CreatePlaylist; +friend class DynamicPlaylist; public: ~Playlist(); diff --git a/src/libtomahawk/playlist/dynamic/DynamicPlaylist.cpp b/src/libtomahawk/playlist/dynamic/DynamicPlaylist.cpp index 5b6481a6f..a078a656b 100644 --- a/src/libtomahawk/playlist/dynamic/DynamicPlaylist.cpp +++ b/src/libtomahawk/playlist/dynamic/DynamicPlaylist.cpp @@ -153,6 +153,9 @@ DynamicPlaylist::createNewRevision( const QString& newrev, const QList< dyncontrol_ptr>& controls, const QList< plentry_ptr >& entries ) { + Q_ASSERT( !busy() ); + setBusy( true ); + // get the newly added tracks QList< plentry_ptr > added = newEntries( entries ); @@ -162,21 +165,21 @@ DynamicPlaylist::createNewRevision( const QString& newrev, // no conflict resolution or partial updating for controls. all or nothing baby - // source making the change (local user in this case) - source_ptr author = SourceList::instance()->getLocal(); - // command writes new rev to DB and calls setRevision, which emits our signal - DatabaseCommand_SetDynamicPlaylistRevision* cmd = - new DatabaseCommand_SetDynamicPlaylistRevision( author, - guid(), - newrev, - oldrev, - orderedguids, - added, - entries, - type, - Static, - controls ); - Database::instance()->enqueue( QSharedPointer( cmd ) ); + // source making the change (local user in this case) + source_ptr author = SourceList::instance()->getLocal(); + // command writes new rev to DB and calls setRevision, which emits our signal + DatabaseCommand_SetDynamicPlaylistRevision* cmd = + new DatabaseCommand_SetDynamicPlaylistRevision( author, + guid(), + newrev, + oldrev, + orderedguids, + added, + entries, + type, + Static, + controls ); + Database::instance()->enqueue( QSharedPointer( cmd ) ); } // create a new revision that will be an ondemand playlist, as it has no entries @@ -205,6 +208,7 @@ DynamicPlaylist::loadRevision( const QString& rev ) { qDebug() << Q_FUNC_INFO << "Loading with:" << ( rev.isEmpty() ? currentrevision() : rev ); + setBusy( true ); DatabaseCommand_LoadDynamicPlaylist* cmd = new DatabaseCommand_LoadDynamicPlaylist( rev.isEmpty() ? currentrevision() : rev ); if( m_generator->mode() == OnDemand ) { @@ -335,10 +339,11 @@ void DynamicPlaylist::setRevision( const QString& rev, dpr.type = type; dpr.mode = Static; - if( applied ) { + if( applied ) setCurrentrevision( rev ); - } + // qDebug() << "EMITTING REVISION LOADED 1!"; + setBusy( false ); emit dynamicRevisionLoaded( dpr ); } diff --git a/src/libtomahawk/playlist/playlistmodel.cpp b/src/libtomahawk/playlist/playlistmodel.cpp index cf3ae35b4..262d126d9 100644 --- a/src/libtomahawk/playlist/playlistmodel.cpp +++ b/src/libtomahawk/playlist/playlistmodel.cpp @@ -221,7 +221,11 @@ void PlaylistModel::trackResolved( bool ) { Tomahawk::Query* q = qobject_cast< Query* >( sender() ); - Q_ASSERT( q ); + if ( !q ) + { + // Track has been removed from the playlist by now + return; + } m_waitingForResolved.removeAll( q ); disconnect( q, SIGNAL( resolvingFinished( bool ) ), this, SLOT( trackResolved( bool ) ) ); diff --git a/src/libtomahawk/tomahawksettings.cpp b/src/libtomahawk/tomahawksettings.cpp index 0d13763a5..6ec09a432 100644 --- a/src/libtomahawk/tomahawksettings.cpp +++ b/src/libtomahawk/tomahawksettings.cpp @@ -385,9 +385,14 @@ TomahawkSettings::recentlyPlayedPlaylists() const } QStringList -TomahawkSettings::recentlyPlayedPlaylistGuids() const +TomahawkSettings::recentlyPlayedPlaylistGuids( unsigned int amount ) const { - return value( "playlists/recentlyPlayed" ).toStringList(); + QStringList p = value( "playlists/recentlyPlayed" ).toStringList(); + + while ( amount && p.count() > (int)amount ) + p.removeAt( p.count() - 1 ); + + return p; } diff --git a/src/libtomahawk/tomahawksettings.h b/src/libtomahawk/tomahawksettings.h index 64365199d..b61660b23 100644 --- a/src/libtomahawk/tomahawksettings.h +++ b/src/libtomahawk/tomahawksettings.h @@ -66,7 +66,7 @@ public: void setPlaylistColumnSizes( const QString& playlistid, const QByteArray& state ); QList recentlyPlayedPlaylists() const; - QStringList recentlyPlayedPlaylistGuids() const; + QStringList recentlyPlayedPlaylistGuids( unsigned int amount = 0 ) const; void appendRecentlyPlayedPlaylist( const Tomahawk::playlist_ptr& playlist ); /// SIP plugins diff --git a/src/libtomahawk/widgets/welcomeplaylistmodel.cpp b/src/libtomahawk/widgets/welcomeplaylistmodel.cpp index e5421e83f..f6f5fb838 100644 --- a/src/libtomahawk/widgets/welcomeplaylistmodel.cpp +++ b/src/libtomahawk/widgets/welcomeplaylistmodel.cpp @@ -28,6 +28,7 @@ using namespace Tomahawk; WelcomePlaylistModel::WelcomePlaylistModel( QObject* parent ) : QAbstractListModel( parent ) , m_waitingForSome( true ) + , m_maxPlaylists( 0 ) { loadFromSettings(); @@ -49,7 +50,7 @@ WelcomePlaylistModel::loadFromSettings() m_recplaylists.clear(); m_waitingForSome = false; - QStringList playlist_guids = TomahawkSettings::instance()->recentlyPlayedPlaylistGuids(); + QStringList playlist_guids = TomahawkSettings::instance()->recentlyPlayedPlaylistGuids( m_maxPlaylists ); for( int i = playlist_guids.size() - 1; i >= 0; i-- ) { diff --git a/src/libtomahawk/widgets/welcomeplaylistmodel.h b/src/libtomahawk/widgets/welcomeplaylistmodel.h index 4c8b13b59..531cf2894 100644 --- a/src/libtomahawk/widgets/welcomeplaylistmodel.h +++ b/src/libtomahawk/widgets/welcomeplaylistmodel.h @@ -34,6 +34,9 @@ public: { ArtistRole = Qt::UserRole, TrackCountRole, PlaylistRole }; explicit WelcomePlaylistModel( QObject* parent = 0 ); + + void setMaxPlaylists( unsigned int max ) { m_maxPlaylists = max; } + virtual QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const; virtual int rowCount( const QModelIndex& parent = QModelIndex() ) const; @@ -53,6 +56,7 @@ private: QHash< QString, Tomahawk::playlist_ptr > m_cached; mutable QHash< Tomahawk::playlist_ptr, QString > m_artists; + unsigned int m_maxPlaylists; bool m_waitingForSome; }; diff --git a/src/libtomahawk/widgets/welcomewidget.cpp b/src/libtomahawk/widgets/welcomewidget.cpp index e2b8012eb..5ba725e8f 100644 --- a/src/libtomahawk/widgets/welcomewidget.cpp +++ b/src/libtomahawk/widgets/welcomewidget.cpp @@ -33,8 +33,8 @@ #include #include "welcomeplaylistmodel.h" -#define HISTORY_TRACK_ITEMS 50 -#define HISTORY_PLAYLIST_ITEMS 10 +#define HISTORY_TRACK_ITEMS 25 +#define HISTORY_PLAYLIST_ITEMS 5 #define HISTORY_RESOLVING_TIMEOUT 2500 @@ -44,14 +44,15 @@ WelcomeWidget::WelcomeWidget( QWidget* parent ) { ui->setupUi( this ); + WelcomePlaylistModel* model = new WelcomePlaylistModel( this ); + model->setMaxPlaylists( HISTORY_PLAYLIST_ITEMS ); + ui->playlistWidget->setItemDelegate( new PlaylistDelegate() ); - WelcomePlaylistModel* model = new WelcomePlaylistModel( this ); ui->playlistWidget->setModel( model ); ui->playlistWidget->overlay()->resize( 380, 86 ); ui->tracksView->overlay()->setEnabled( false ); - connect( model,SIGNAL( emptinessChanged( bool) ), this, SLOT( updatePlaylists() ) ); - + connect( model, SIGNAL( emptinessChanged( bool) ), this, SLOT( updatePlaylists() ) ); m_tracksModel = new PlaylistModel( ui->tracksView ); ui->tracksView->setPlaylistModel( m_tracksModel );