diff --git a/src/libtomahawk/playlist/PlayableModel.cpp b/src/libtomahawk/playlist/PlayableModel.cpp index f1bbfc88a..0f8f8c28a 100644 --- a/src/libtomahawk/playlist/PlayableModel.cpp +++ b/src/libtomahawk/playlist/PlayableModel.cpp @@ -173,36 +173,36 @@ PlayableModel::queryData( const query_ptr& query, int column, int role ) const switch ( column ) { case Artist: - return query->artist(); + return query->track()->artist(); break; case Name: case Track: - return query->track(); + return query->track()->track(); break; case Album: - return query->album(); + return query->track()->album(); break; case Composer: - return query->composer(); + return query->track()->composer(); break; case Duration: - return TomahawkUtils::timeToString( query->duration() ); + return TomahawkUtils::timeToString( query->track()->duration() ); break; case AlbumPos: { QString tPos; - if ( query->albumpos() != 0 ) + if ( query->track()->albumpos() != 0 ) { - tPos = QString::number( query->albumpos() ); - if ( query->discnumber() == 0 ) + tPos = QString::number( query->track()->albumpos() ); + if ( query->track()->discnumber() == 0 ) return tPos; else - return QString( "%1.%2" ).arg( QString::number( query->discnumber() ) ) + return QString( "%1.%2" ).arg( QString::number( query->track()->discnumber() ) ) .arg( tPos ); } } @@ -252,7 +252,7 @@ PlayableModel::queryData( const query_ptr& query, int column, int role ) const return tr( "Bad match" ); if ( score > 0.0 ) return tr( "Very bad match" ); - + return tr( "Not available" ); break; } @@ -306,7 +306,7 @@ PlayableModel::data( const QModelIndex& index, int role ) const { if ( !entry->query().isNull() ) { - return queryData( entry->query()->displayQuery(), index.column(), role ); + return queryData( entry->query(), index.column(), role ); } else if ( !entry->artist().isNull() ) { @@ -571,7 +571,7 @@ PlayableModel::queries() const template void -PlayableModel::insertInternal( const QList< T >& items, int row ) +PlayableModel::insertInternal( const QList< T >& items, int row, const QList< Tomahawk::PlaybackLog >& logs ) { if ( !items.count() ) { @@ -594,6 +594,10 @@ PlayableModel::insertInternal( const QList< T >& items, int row ) { plitem = new PlayableItem( item, m_rootItem, row + i ); plitem->index = createIndex( row + i, 0, plitem ); + + if ( logs.count() > i ) + plitem->setPlaybackLog( logs.at( i ) ); + i++; /* if ( item->id() == currentItemUuid() ) @@ -635,7 +639,7 @@ PlayableModel::removeIndex( const QModelIndex& index, bool moreToCome ) { if ( index == m_currentIndex ) setCurrentIndex( QModelIndex() ); - + emit beginRemoveRows( index.parent(), index.row(), index.row() ); delete item; emit endRemoveRows(); @@ -823,6 +827,19 @@ PlayableModel::appendQueries( const QList< Tomahawk::query_ptr >& queries ) } +void +PlayableModel::appendTracks( const QList< Tomahawk::track_ptr >& tracks, const QList< Tomahawk::PlaybackLog >& logs ) +{ + QList< Tomahawk::query_ptr > queries; + foreach ( const track_ptr& track, tracks ) + { + queries << track->toQuery(); + } + + insertQueries( queries, rowCount( QModelIndex() ), logs ); +} + + void PlayableModel::insertArtist( const Tomahawk::artist_ptr& artist, int row ) { @@ -868,9 +885,9 @@ PlayableModel::insertAlbums( const QList< Tomahawk::album_ptr >& albums, int row void -PlayableModel::insertQueries( const QList< Tomahawk::query_ptr >& queries, int row ) +PlayableModel::insertQueries( const QList< Tomahawk::query_ptr >& queries, int row, const QList< Tomahawk::PlaybackLog >& logs ) { - insertInternal( queries, row ); + insertInternal( queries, row, logs ); } @@ -924,17 +941,17 @@ void PlayableModel::onQueryResolved( bool hasResults ) { Q_UNUSED( hasResults ); - + Tomahawk::Query* q = qobject_cast< Query* >( sender() ); if ( !q ) { // Track has been removed from the playlist by now return; } - + Tomahawk::query_ptr query = q->weakRef().toStrongRef(); PlayableItem* item = itemFromQuery( query ); - + if ( item ) { emit indexResolved( item->index ); diff --git a/src/libtomahawk/playlist/PlayableModel.h b/src/libtomahawk/playlist/PlayableModel.h index 8b0b69647..496dc0d9a 100644 --- a/src/libtomahawk/playlist/PlayableModel.h +++ b/src/libtomahawk/playlist/PlayableModel.h @@ -131,6 +131,7 @@ public slots: virtual void clear(); + virtual void appendTracks( const QList< Tomahawk::track_ptr >& tracks, const QList< Tomahawk::PlaybackLog >& logs = QList< Tomahawk::PlaybackLog >() ); virtual void appendQueries( const QList< Tomahawk::query_ptr >& queries ); virtual void appendArtists( const QList< Tomahawk::artist_ptr >& artists ); virtual void appendAlbums( const QList< Tomahawk::album_ptr >& albums ); @@ -138,7 +139,7 @@ public slots: virtual void appendArtist( const Tomahawk::artist_ptr& artist ); virtual void appendAlbum( const Tomahawk::album_ptr& album ); - virtual void insertQueries( const QList< Tomahawk::query_ptr >& queries, int row = 0 ); + virtual void insertQueries( const QList< Tomahawk::query_ptr >& queries, int row = 0, const QList< Tomahawk::PlaybackLog >& logs = QList< Tomahawk::PlaybackLog >() ); virtual void insertArtists( const QList< Tomahawk::artist_ptr >& artists, int row = 0 ); virtual void insertAlbums( const QList< Tomahawk::album_ptr >& albums, int row = 0 ); virtual void insertQuery( const Tomahawk::query_ptr& query, int row = 0 ); @@ -162,13 +163,13 @@ private slots: void onQueryBecamePlayable( bool playable ); void onQueryResolved( bool hasResults ); - + void onPlaybackStarted( const Tomahawk::result_ptr& result ); void onPlaybackStopped(); private: template - void insertInternal( const QList< T >& items, int row ); + void insertInternal( const QList< T >& items, int row, const QList< Tomahawk::PlaybackLog >& logs = QList< Tomahawk::PlaybackLog >() ); Qt::Alignment columnAlignment( int column ) const; diff --git a/src/libtomahawk/playlist/PlaylistModel.cpp b/src/libtomahawk/playlist/PlaylistModel.cpp index cccf817e5..1939529e1 100644 --- a/src/libtomahawk/playlist/PlaylistModel.cpp +++ b/src/libtomahawk/playlist/PlaylistModel.cpp @@ -214,7 +214,7 @@ PlaylistModel::insertArtists( const QList< Tomahawk::artist_ptr >& artists, int void -PlaylistModel::insertQueries( const QList< Tomahawk::query_ptr >& queries, int row ) +PlaylistModel::insertQueries( const QList< Tomahawk::query_ptr >& queries, int row, const QList< Tomahawk::PlaybackLog >& logs ) { QList< Tomahawk::plentry_ptr > entries; foreach ( const query_ptr& query, queries ) @@ -224,7 +224,7 @@ PlaylistModel::insertQueries( const QList< Tomahawk::query_ptr >& queries, int r plentry_ptr entry = plentry_ptr( new PlaylistEntry() ); - entry->setDuration( query->displayQuery()->duration() ); + entry->setDuration( query->track()->duration() ); entry->setLastmodified( 0 ); QString annotation = ""; if ( !query->property( "annotation" ).toString().isEmpty() ) @@ -237,12 +237,12 @@ PlaylistModel::insertQueries( const QList< Tomahawk::query_ptr >& queries, int r entries << entry; } - insertEntries( entries, row ); + insertEntries( entries, row, logs ); } void -PlaylistModel::insertEntries( const QList< Tomahawk::plentry_ptr >& entries, int row ) +PlaylistModel::insertEntries( const QList< Tomahawk::plentry_ptr >& entries, int row, const QList< Tomahawk::PlaybackLog >& logs ) { if ( !entries.count() ) { @@ -271,6 +271,10 @@ PlaylistModel::insertEntries( const QList< Tomahawk::plentry_ptr >& entries, int { plitem = new PlayableItem( entry, rootItem(), row + i ); plitem->index = createIndex( row + i, 0, plitem ); + + if ( logs.count() > i ) + plitem->setPlaybackLog( logs.at( i ) ); + i++; if ( entry->query()->id() == currentItemUuid() ) @@ -434,7 +438,12 @@ void PlaylistModel::endPlaylistChanges() { if ( m_playlist.isNull() || !m_playlist->author()->isLocal() ) + { + m_savedInsertPos = -1; + m_savedInsertTracks.clear(); + m_savedRemoveTracks.clear(); return; + } if ( m_changesOngoing ) { diff --git a/src/libtomahawk/playlist/PlaylistModel.h b/src/libtomahawk/playlist/PlaylistModel.h index 69ca826dc..ce8875ba9 100644 --- a/src/libtomahawk/playlist/PlaylistModel.h +++ b/src/libtomahawk/playlist/PlaylistModel.h @@ -67,8 +67,8 @@ public slots: 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 insertQueries( const QList< Tomahawk::query_ptr >& queries, int row = 0, const QList< Tomahawk::PlaybackLog >& logs = QList< Tomahawk::PlaybackLog >() ); + virtual void insertEntries( const QList< Tomahawk::plentry_ptr >& entries, int row = 0, const QList< Tomahawk::PlaybackLog >& logs = QList< Tomahawk::PlaybackLog >() ); virtual void removeIndex( const QModelIndex& index, bool moreToCome = false ); diff --git a/src/libtomahawk/playlist/RecentlyPlayedModel.cpp b/src/libtomahawk/playlist/RecentlyPlayedModel.cpp index 4eb83533a..4d0646a4f 100644 --- a/src/libtomahawk/playlist/RecentlyPlayedModel.cpp +++ b/src/libtomahawk/playlist/RecentlyPlayedModel.cpp @@ -58,8 +58,8 @@ RecentlyPlayedModel::loadHistory() DatabaseCommand_PlaybackHistory* cmd = new DatabaseCommand_PlaybackHistory( m_source ); cmd->setLimit( m_limit ); - connect( cmd, SIGNAL( tracks( QList ) ), - SLOT( appendQueries( QList ) ), Qt::QueuedConnection ); + connect( cmd, SIGNAL( tracks( QList, QList ) ), + SLOT( appendTracks( QList, QList ) ), Qt::QueuedConnection ); Database::instance()->enqueue( QSharedPointer( cmd ) ); } @@ -101,25 +101,24 @@ RecentlyPlayedModel::setSource( const Tomahawk::source_ptr& source ) void RecentlyPlayedModel::onSourceAdded( const Tomahawk::source_ptr& source ) { - connect( source.data(), SIGNAL( playbackFinished( Tomahawk::query_ptr ) ), SLOT( onPlaybackFinished( Tomahawk::query_ptr ) ), Qt::UniqueConnection ); + connect( source.data(), SIGNAL( playbackFinished( Tomahawk::track_ptr, unsigned int, unsigned int ) ), SLOT( onPlaybackFinished( Tomahawk::track_ptr, unsigned int, unsigned int ) ), Qt::UniqueConnection ); } void -RecentlyPlayedModel::onPlaybackFinished( const Tomahawk::query_ptr& query ) +RecentlyPlayedModel::onPlaybackFinished( const Tomahawk::track_ptr& track, unsigned int playtime, unsigned int secsPlayed ) { int count = trackCount(); - unsigned int playtime = query->playedBy().second; if ( count ) { PlayableItem* oldestItem = itemFromIndex( index( count - 1, 0, QModelIndex() ) ); - if ( oldestItem->query()->playedBy().second >= playtime ) + if ( oldestItem->playbackLog().timestamp >= playtime ) return; PlayableItem* youngestItem = itemFromIndex( index( 0, 0, QModelIndex() ) ); - if ( youngestItem->query()->playedBy().second <= playtime ) - insertQuery( query, 0 ); + if ( youngestItem->playbackLog().timestamp <= playtime ) + insertQuery( track->toQuery(), 0 ); else { for ( int i = 0; i < count - 1; i++ ) @@ -127,16 +126,16 @@ RecentlyPlayedModel::onPlaybackFinished( const Tomahawk::query_ptr& query ) PlayableItem* item1 = itemFromIndex( index( i, 0, QModelIndex() ) ); PlayableItem* item2 = itemFromIndex( index( i + 1, 0, QModelIndex() ) ); - if ( item1->query()->playedBy().second >= playtime && item2->query()->playedBy().second <= playtime ) + if ( item1->playbackLog().timestamp >= playtime && item2->playbackLog().timestamp <= playtime ) { - insertQuery( query, i + 1 ); + insertQuery( track->toQuery(), i + 1 ); break; } } } } else - insertQuery( query, 0 ); + insertQuery( track->toQuery(), 0 ); if ( trackCount() > (int)m_limit ) remove( m_limit ); diff --git a/src/libtomahawk/playlist/RecentlyPlayedModel.h b/src/libtomahawk/playlist/RecentlyPlayedModel.h index 8ec9328e0..1bd725c00 100644 --- a/src/libtomahawk/playlist/RecentlyPlayedModel.h +++ b/src/libtomahawk/playlist/RecentlyPlayedModel.h @@ -47,7 +47,7 @@ private slots: void onSourcesReady(); void onSourceAdded( const Tomahawk::source_ptr& source ); - void onPlaybackFinished( const Tomahawk::query_ptr& query ); + void onPlaybackFinished( const Tomahawk::track_ptr& track, unsigned int playtime, unsigned int secsPlayed ); void loadHistory(); private: