From d907a9fbc883936927551e4017618ec91ffe0418 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Fri, 29 Jun 2012 03:13:31 +0200 Subject: [PATCH] * Adjust inheriting models to new PlayableModel API. --- src/libtomahawk/playlist/PlaylistModel.cpp | 97 ++++++++----------- src/libtomahawk/playlist/PlaylistModel.h | 13 +-- .../playlist/RecentlyAddedModel.cpp | 2 +- .../playlist/RecentlyPlayedModel.cpp | 8 +- .../playlist/dynamic/DynamicModel.cpp | 10 +- 5 files changed, 57 insertions(+), 73 deletions(-) diff --git a/src/libtomahawk/playlist/PlaylistModel.cpp b/src/libtomahawk/playlist/PlaylistModel.cpp index 6f40cc161..b324b2f42 100644 --- a/src/libtomahawk/playlist/PlaylistModel.cpp +++ b/src/libtomahawk/playlist/PlaylistModel.cpp @@ -93,10 +93,10 @@ PlaylistModel::loadPlaylist( const Tomahawk::playlist_ptr& playlist, bool loadEn } QList entries = playlist->entries(); - foreach( const plentry_ptr& p, entries ) - qDebug() << p->guid() << p->query()->track() << p->query()->artist(); +/* foreach ( const plentry_ptr& p, entries ) + qDebug() << p->guid() << p->query()->track() << p->query()->artist();*/ - append( entries ); + appendEntries( entries ); m_isLoading = false; } @@ -112,78 +112,67 @@ PlaylistModel::clear() void -PlaylistModel::append( const QList< plentry_ptr >& entries ) +PlaylistModel::appendEntries( const QList< plentry_ptr >& entries ) { - insert( entries, rowCount( QModelIndex() ) ); + insertEntries( entries, rowCount( QModelIndex() ) ); } void -PlaylistModel::append( const QList< query_ptr >& queries ) +PlaylistModel::insertAlbums( const QList< Tomahawk::album_ptr >& albums, int row ) { - insert( queries, rowCount( QModelIndex() ) ); -} + // FIXME: This currently appends, not inserts! - -void -PlaylistModel::append( const Tomahawk::query_ptr& query ) -{ - insert( query, rowCount( QModelIndex() ) ); -} - - -void -PlaylistModel::append( const Tomahawk::album_ptr& album ) -{ - if ( album.isNull() ) - return; - - connect( album.data(), SIGNAL( tracksAdded( QList, Tomahawk::ModelMode, Tomahawk::collection_ptr ) ), - SLOT( append( QList ) ) ); - - if ( rowCount( QModelIndex() ) == 0 ) + foreach ( const album_ptr& album, albums ) { - setTitle( album->name() ); - setDescription( tr( "All tracks by %1 on album %2" ).arg( album->artist()->name() ).arg( album->name() ) ); - m_isTemporary = true; + if ( album.isNull() ) + return; + + connect( album.data(), SIGNAL( tracksAdded( QList, Tomahawk::ModelMode, Tomahawk::collection_ptr ) ), + SLOT( appendQueries( QList ) ) ); + + appendQueries( album->playlistInterface( Mixed )->tracks() ); } - append( album->playlistInterface( Mixed )->tracks() ); -} - - -void -PlaylistModel::append( const Tomahawk::artist_ptr& artist ) -{ - if ( artist.isNull() ) - return; - - connect( artist.data(), SIGNAL( tracksAdded( QList, Tomahawk::ModelMode, Tomahawk::collection_ptr ) ), - SLOT( append( QList ) ) ); - - if ( rowCount( QModelIndex() ) == 0 ) + if ( rowCount( QModelIndex() ) == 0 && albums.count() == 1 ) { - setTitle( artist->name() ); - setDescription( tr( "All tracks by %1" ).arg( artist->name() ) ); + setTitle( albums.first()->name() ); + setDescription( tr( "All tracks by %1 on album %2" ).arg( albums.first()->artist()->name() ).arg( albums.first()->name() ) ); m_isTemporary = true; } - - append( artist->playlistInterface( Mixed )->tracks() ); } void -PlaylistModel::insert( const Tomahawk::query_ptr& query, int row ) +PlaylistModel::insertArtists( const QList< Tomahawk::artist_ptr >& artists, int row ) { - PlayableModel::insert( query, row ); + // FIXME: This currently appends, not inserts! + + foreach ( const artist_ptr& artist, artists ) + { + if ( artist.isNull() ) + return; + + connect( artist.data(), SIGNAL( tracksAdded( QList, Tomahawk::ModelMode, Tomahawk::collection_ptr ) ), + SLOT( appendQueries( QList ) ) ); + + appendQueries( artist->playlistInterface( Mixed )->tracks() ); + } + + if ( rowCount( QModelIndex() ) == 0 && artists.count() == 1 ) + { + setTitle( artists.first()->name() ); + setDescription( tr( "All tracks by %1" ).arg( artists.first()->name() ) ); + m_isTemporary = true; + } } void -PlaylistModel::insert( const QList< Tomahawk::query_ptr >& queries, int row ) +PlaylistModel::insertQueries( const QList< Tomahawk::query_ptr >& queries, int row ) { QList< Tomahawk::plentry_ptr > entries; - foreach( const query_ptr& query, queries ) + foreach ( const query_ptr& query, queries ) { plentry_ptr entry = plentry_ptr( new PlaylistEntry() ); @@ -200,12 +189,12 @@ PlaylistModel::insert( const QList< Tomahawk::query_ptr >& queries, int row ) entries << entry; } - insert( entries, row ); + insertEntries( entries, row ); } void -PlaylistModel::insert( const QList< Tomahawk::plentry_ptr >& entries, int row ) +PlaylistModel::insertEntries( const QList< Tomahawk::plentry_ptr >& entries, int row ) { if ( !entries.count() ) { @@ -368,7 +357,7 @@ PlaylistModel::parsedDroppedTracks( QList< query_ptr > tracks ) if ( update ) beginPlaylistChanges(); - insert( tracks, beginRow ); + insertQueries( tracks, beginRow ); if ( update && m_dropStorage.action & Qt::CopyAction ) endPlaylistChanges(); diff --git a/src/libtomahawk/playlist/PlaylistModel.h b/src/libtomahawk/playlist/PlaylistModel.h index 9d2d4dcdb..88ac0ec90 100644 --- a/src/libtomahawk/playlist/PlaylistModel.h +++ b/src/libtomahawk/playlist/PlaylistModel.h @@ -58,15 +58,12 @@ public: public slots: virtual void clear(); - virtual void append( const Tomahawk::query_ptr& query ); - virtual void append( const Tomahawk::album_ptr& album ); - virtual void append( const Tomahawk::artist_ptr& artist ); - virtual void append( const QList< Tomahawk::query_ptr >& queries ); - virtual void append( const QList< Tomahawk::plentry_ptr >& entries ); + virtual void appendEntries( const QList< Tomahawk::plentry_ptr >& entries ); - virtual void insert( const Tomahawk::query_ptr& query, int row = 0 ); - virtual void insert( const QList< Tomahawk::query_ptr >& queries, int row = 0 ); - virtual void insert( const QList< Tomahawk::plentry_ptr >& entries, int row = 0 ); + virtual void insertAlbums( const QList< Tomahawk::album_ptr >& album, int row = 0 ); + virtual void insertArtists( const QList< Tomahawk::artist_ptr >& artist, int row = 0 ); + virtual void insertQueries( const QList< Tomahawk::query_ptr >& queries, int row = 0 ); + virtual void insertEntries( const QList< Tomahawk::plentry_ptr >& entries, int row = 0 ); virtual void removeIndex( const QModelIndex& index, bool moreToCome = false ); diff --git a/src/libtomahawk/playlist/RecentlyAddedModel.cpp b/src/libtomahawk/playlist/RecentlyAddedModel.cpp index 8a0004f53..344232b36 100644 --- a/src/libtomahawk/playlist/RecentlyAddedModel.cpp +++ b/src/libtomahawk/playlist/RecentlyAddedModel.cpp @@ -60,7 +60,7 @@ RecentlyAddedModel::loadHistory() cmd->setSortDescending( true ); connect( cmd, SIGNAL( tracks( QList, QVariant ) ), - SLOT( append( QList ) ), Qt::QueuedConnection ); + SLOT( appendQueries( QList ) ), Qt::QueuedConnection ); Database::instance()->enqueue( QSharedPointer( cmd ) ); } diff --git a/src/libtomahawk/playlist/RecentlyPlayedModel.cpp b/src/libtomahawk/playlist/RecentlyPlayedModel.cpp index ec9b66a80..4eb83533a 100644 --- a/src/libtomahawk/playlist/RecentlyPlayedModel.cpp +++ b/src/libtomahawk/playlist/RecentlyPlayedModel.cpp @@ -59,7 +59,7 @@ RecentlyPlayedModel::loadHistory() cmd->setLimit( m_limit ); connect( cmd, SIGNAL( tracks( QList ) ), - SLOT( append( QList ) ), Qt::QueuedConnection ); + SLOT( appendQueries( QList ) ), Qt::QueuedConnection ); Database::instance()->enqueue( QSharedPointer( cmd ) ); } @@ -119,7 +119,7 @@ RecentlyPlayedModel::onPlaybackFinished( const Tomahawk::query_ptr& query ) PlayableItem* youngestItem = itemFromIndex( index( 0, 0, QModelIndex() ) ); if ( youngestItem->query()->playedBy().second <= playtime ) - insert( query, 0 ); + insertQuery( query, 0 ); else { for ( int i = 0; i < count - 1; i++ ) @@ -129,14 +129,14 @@ RecentlyPlayedModel::onPlaybackFinished( const Tomahawk::query_ptr& query ) if ( item1->query()->playedBy().second >= playtime && item2->query()->playedBy().second <= playtime ) { - insert( query, i + 1 ); + insertQuery( query, i + 1 ); break; } } } } else - insert( query, 0 ); + insertQuery( query, 0 ); if ( trackCount() > (int)m_limit ) remove( m_limit ); diff --git a/src/libtomahawk/playlist/dynamic/DynamicModel.cpp b/src/libtomahawk/playlist/dynamic/DynamicModel.cpp index 7c0fd171b..ad5ea0652 100644 --- a/src/libtomahawk/playlist/dynamic/DynamicModel.cpp +++ b/src/libtomahawk/playlist/dynamic/DynamicModel.cpp @@ -121,7 +121,7 @@ DynamicModel::newTrackGenerated( const Tomahawk::query_ptr& query ) connect( query.data(), SIGNAL( resolvingFinished( bool ) ), this, SLOT( trackResolveFinished( bool ) ) ); m_waitingFor << query.data(); - append( query ); + appendQuery( query ); } } @@ -316,11 +316,9 @@ DynamicModel::addToPlaylist( const QList< query_ptr >& entries, bool clearFirst m_playlist->addEntries( entries, m_playlist->currentrevision() ); } else - { // read-only, so add tracks only in the GUI, not to the playlist itself - foreach ( const query_ptr& query, entries ) - { - append( query ); - } + { + // read-only, so add tracks only in the GUI, not to the playlist itself + appendQueries( entries ); } emit tracksAdded();