From e905a4b6172e8b19b4971e0a843974dab75c30ab Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Mon, 22 Apr 2013 09:25:28 +0200 Subject: [PATCH] * Use new DbCmd interfaces. --- src/libtomahawk/PlaylistInterface.cpp | 9 ++-- .../accounts/lastfm/LastFmConfig.cpp | 33 +++++++------- .../accounts/lastfm/LastFmConfig.h | 4 +- src/libtomahawk/playlist/PlayableItem.cpp | 44 ++++++++++++------- src/libtomahawk/playlist/PlayableItem.h | 6 +++ src/sourcetree/items/SourceItem.cpp | 5 +-- 6 files changed, 59 insertions(+), 42 deletions(-) diff --git a/src/libtomahawk/PlaylistInterface.cpp b/src/libtomahawk/PlaylistInterface.cpp index d9709d7b6..7b04bf2ec 100644 --- a/src/libtomahawk/PlaylistInterface.cpp +++ b/src/libtomahawk/PlaylistInterface.cpp @@ -181,10 +181,7 @@ PlaylistInterface::filterTracks( const QList& queries ) if ( picked ) { - query_ptr q = Query::get( q1->artist(), q1->track(), q1->album(), uuid(), false ); - q->setAlbumPos( q1->results().first()->albumpos() ); - q->setDiscNumber( q1->discnumber() ); - result << q; + result << q1; } } @@ -222,7 +219,7 @@ PlaylistInterface::onItemsChanged() Tomahawk::result_ptr nextResult = siblingResult( 1, m_currentIndex ); { - bool avail = prevResult && prevResult->toQuery()->playable(); + bool avail = prevResult && prevResult->playable(); if ( avail != m_prevAvail ) { m_prevAvail = avail; @@ -231,7 +228,7 @@ PlaylistInterface::onItemsChanged() } { - bool avail = nextResult && nextResult->toQuery()->playable(); + bool avail = nextResult && nextResult->playable(); if ( avail != m_nextAvail ) { m_nextAvail = avail; diff --git a/src/libtomahawk/accounts/lastfm/LastFmConfig.cpp b/src/libtomahawk/accounts/lastfm/LastFmConfig.cpp index ecda751b0..195eb72b7 100644 --- a/src/libtomahawk/accounts/lastfm/LastFmConfig.cpp +++ b/src/libtomahawk/accounts/lastfm/LastFmConfig.cpp @@ -152,13 +152,13 @@ LastFmConfig::onHistoryLoaded() foreach ( lastfm::XmlQuery e, lfm.children( "track" ) ) { // tDebug() << "Found:" << e.children( "artist" ).first()["name"].text() << e["name"].text() << e["date"].attribute( "uts" ).toUInt(); - Tomahawk::query_ptr query = Tomahawk::Query::get( e.children( "artist" ).first()["name"].text(), e["name"].text(), QString(), QString(), false ); - if ( query.isNull() ) + Tomahawk::track_ptr track = Tomahawk::Track::get( e.children( "artist" ).first()["name"].text(), e["name"].text(), QString() ); + if ( !track ) continue; m_lastTimeStamp = e["date"].attribute( "uts" ).toUInt(); - DatabaseCommand_LogPlayback* cmd = new DatabaseCommand_LogPlayback( query, DatabaseCommand_LogPlayback::Finished, m_lastTimeStamp ); + DatabaseCommand_LogPlayback* cmd = new DatabaseCommand_LogPlayback( track, DatabaseCommand_LogPlayback::Finished, 0, m_lastTimeStamp ); Database::instance()->enqueue( QSharedPointer(cmd) ); } @@ -296,12 +296,12 @@ LastFmConfig::onLovedFinished( QNetworkReply* reply ) m_ui->progressBar->setValue( thisPage ); foreach ( lastfm::XmlQuery e, loved.children( "track" ) ) { - tDebug() << "Found:" << e.children( "artist" ).first()["name"].text() << e["name"].text() << e["date"].attribute( "uts" ).toUInt(); - Tomahawk::query_ptr query = Tomahawk::Query::get( e.children( "artist" ).first()["name"].text(), e["name"].text(), QString(), QString(), false ); - if ( query.isNull() ) + tDebug() << "Found:" << e.children( "artist" ).first()["name"].text() << e["name"].text() << e["date"].attribute( "uts" ).toUInt(); + Tomahawk::track_ptr track = Tomahawk::Track::get( e.children( "artist" ).first()["name"].text(), e["name"].text(), QString() ); + if ( track.isNull() ) continue; - m_lastfmLoved.insert( query ); + m_lastfmLoved.insert( track ); } if ( thisPage == m_totalLovedPages ) @@ -335,7 +335,8 @@ LastFmConfig::onLovedFinished( QNetworkReply* reply ) } -bool trackEquality( const Tomahawk::query_ptr& first, const Tomahawk::query_ptr& second ) +bool +trackEquality( const Tomahawk::track_ptr& first, const Tomahawk::track_ptr& second ) { qDebug() << "Comparing:" << first->track() << second->track(); qDebug() << "==========" << first->artist() << second->artist(); @@ -357,15 +358,15 @@ LastFmConfig::localLovedLoaded( DatabaseCommand_LoadSocialActions::TrackActions void LastFmConfig::syncLoved() { - QSet< Tomahawk::query_ptr > localToLove, lastFmToLove, lastFmToUnlove; + QSet< Tomahawk::track_ptr > localToLove, lastFmToLove, lastFmToUnlove; - const QSet< Tomahawk::query_ptr > myLoved = m_localLoved.keys().toSet(); + const QSet< Tomahawk::track_ptr > myLoved = m_localLoved.keys().toSet(); m_ui->progressBar->setValue( m_ui->progressBar->value() + 1 ); - foreach ( const Tomahawk::query_ptr& lastfmLoved, m_lastfmLoved ) + foreach ( const Tomahawk::track_ptr& lastfmLoved, m_lastfmLoved ) { - QSet< Tomahawk::query_ptr >::const_iterator iter = std::find_if( myLoved.begin(), myLoved.end(), boost::bind( &trackEquality, _1, boost::ref( lastfmLoved ) ) ); + QSet< Tomahawk::track_ptr >::const_iterator iter = std::find_if( myLoved.begin(), myLoved.end(), boost::bind( &trackEquality, _1, boost::ref( lastfmLoved ) ) ); if ( iter == myLoved.constEnd() ) { // qDebug() << "Found last.fm loved track that we didn't have loved locally:" << lastfmLoved->track() << lastfmLoved->artist(); @@ -373,10 +374,10 @@ LastFmConfig::syncLoved() } } - foreach ( const Tomahawk::query_ptr& localLoved, myLoved ) + foreach ( const Tomahawk::track_ptr& localLoved, myLoved ) { qDebug() << "CHECKING FOR LOCAL LOVED ON LAST.FM TOO:" << m_localLoved[ localLoved ].value.toString() << localLoved->track() << localLoved->artist(); - QSet< Tomahawk::query_ptr >::const_iterator iter = std::find_if( m_lastfmLoved.begin(), m_lastfmLoved.end(), boost::bind( &trackEquality, _1, boost::ref( localLoved ) ) ); + QSet< Tomahawk::track_ptr >::const_iterator iter = std::find_if( m_lastfmLoved.begin(), m_lastfmLoved.end(), boost::bind( &trackEquality, _1, boost::ref( localLoved ) ) ); qDebug() << "Result:" << (iter == m_lastfmLoved.constEnd()); // If we unloved it locally, but it's still loved on last.fm, unlove it @@ -391,7 +392,7 @@ LastFmConfig::syncLoved() } } - foreach ( const Tomahawk::query_ptr& track, localToLove ) + foreach ( const Tomahawk::track_ptr& track, localToLove ) { // Don't use the infosystem as we don't want to tweet a few hundred times :) DatabaseCommand_SocialAction* cmd = new DatabaseCommand_SocialAction( track, QString( "Love" ), QString( "true" ) ); @@ -400,7 +401,7 @@ LastFmConfig::syncLoved() lastFmToLove.unite( lastFmToUnlove ); - foreach ( const Tomahawk::query_ptr& track, lastFmToLove ) + foreach ( const Tomahawk::track_ptr& track, lastFmToLove ) { lastfm::MutableTrack lfmTrack; lfmTrack.stamp(); diff --git a/src/libtomahawk/accounts/lastfm/LastFmConfig.h b/src/libtomahawk/accounts/lastfm/LastFmConfig.h index 83964b460..190efcd3f 100644 --- a/src/libtomahawk/accounts/lastfm/LastFmConfig.h +++ b/src/libtomahawk/accounts/lastfm/LastFmConfig.h @@ -19,7 +19,7 @@ #ifndef LASTFMCONFIG_H #define LASTFMCONFIG_H -#include "Query.h" +#include "Track.h" #include "accounts/AccountConfigWidget.h" #include "database/DatabaseCommand_LoadSocialActions.h" @@ -74,7 +74,7 @@ private: int m_totalLovedPages; bool m_doneFetchingLoved, m_doneFetchingLocal; - QSet< Tomahawk::query_ptr > m_lastfmLoved; + QSet< Tomahawk::track_ptr > m_lastfmLoved; DatabaseCommand_LoadSocialActions::TrackActions m_localLoved; }; diff --git a/src/libtomahawk/playlist/PlayableItem.cpp b/src/libtomahawk/playlist/PlayableItem.cpp index 42e8a210a..78f222395 100644 --- a/src/libtomahawk/playlist/PlayableItem.cpp +++ b/src/libtomahawk/playlist/PlayableItem.cpp @@ -86,11 +86,11 @@ PlayableItem::PlayableItem( const Tomahawk::query_ptr& query, PlayableItem* pare { init( parent, row ); - connect( query.data(), SIGNAL( socialActionsLoaded() ), - SIGNAL( dataChanged() ) ); + connect( query->track().data(), SIGNAL( socialActionsLoaded() ), + SIGNAL( dataChanged() ) ); - connect( query.data(), SIGNAL( updated() ), - SIGNAL( dataChanged() ) ); + connect( query->track().data(), SIGNAL( updated() ), + SIGNAL( dataChanged() ) ); connect( query.data(), SIGNAL( resultsChanged() ), SLOT( onResultsChanged() ) ); @@ -104,11 +104,11 @@ PlayableItem::PlayableItem( const Tomahawk::plentry_ptr& entry, PlayableItem* pa m_query = entry->query(); init( parent, row ); - connect( m_query.data(), SIGNAL( socialActionsLoaded() ), - SIGNAL( dataChanged() ) ); + connect( m_query->track().data(), SIGNAL( socialActionsLoaded() ), + SIGNAL( dataChanged() ) ); - connect( m_query.data(), SIGNAL( updated() ), - SIGNAL( dataChanged() ) ); + connect( m_query->track().data(), SIGNAL( updated() ), + SIGNAL( dataChanged() ) ); connect( m_query.data(), SIGNAL( resultsChanged() ), SLOT( onResultsChanged() ) ); @@ -167,11 +167,11 @@ PlayableItem::name() const } else if ( !m_result.isNull() ) { - return m_result->track(); + return m_result->track()->track(); } else if ( !m_query.isNull() ) { - return m_query->track(); + return m_query->track()->track(); } Q_ASSERT( false ); @@ -184,11 +184,11 @@ PlayableItem::artistName() const { if ( !m_result.isNull() ) { - return m_result->artist()->name(); + return m_result->track()->artist(); } else if ( !m_query.isNull() ) { - return m_query->artist(); + return m_query->track()->artist(); } return QString(); @@ -198,13 +198,13 @@ PlayableItem::artistName() const QString PlayableItem::albumName() const { - if ( !m_result.isNull() && !m_result->album().isNull() ) + if ( !m_result.isNull() ) { - return m_result->album()->name(); + return m_result->track()->album(); } else if ( !m_query.isNull() ) { - return m_query->album(); + return m_query->track()->album(); } return QString(); @@ -222,3 +222,17 @@ PlayableItem::result() const return m_result; } + + +Tomahawk::PlaybackLog +PlayableItem::playbackLog() const +{ + return m_playbackLog; +} + + +void +PlayableItem::setPlaybackLog( const Tomahawk::PlaybackLog& log ) +{ + m_playbackLog = log; +} diff --git a/src/libtomahawk/playlist/PlayableItem.h b/src/libtomahawk/playlist/PlayableItem.h index 025f7a2e9..5f1e7913f 100644 --- a/src/libtomahawk/playlist/PlayableItem.h +++ b/src/libtomahawk/playlist/PlayableItem.h @@ -24,6 +24,7 @@ #include #include +#include "Track.h" #include "Typedefs.h" #include "DllMacro.h" @@ -47,6 +48,9 @@ public: const Tomahawk::plentry_ptr& entry() const { return m_entry; } const Tomahawk::result_ptr& result() const; + Tomahawk::PlaybackLog playbackLog() const; + void setPlaybackLog( const Tomahawk::PlaybackLog& log ); + PlayableItem* parent() const { return m_parent; } bool isPlaying() const { return m_isPlaying; } @@ -81,6 +85,8 @@ private: PlayableItem* m_parent; bool m_fetchingMore; bool m_isPlaying; + + Tomahawk::PlaybackLog m_playbackLog; }; #endif // PLAYABLEITEM_H diff --git a/src/sourcetree/items/SourceItem.cpp b/src/sourcetree/items/SourceItem.cpp index 14482a296..eb3c4c328 100644 --- a/src/sourcetree/items/SourceItem.cpp +++ b/src/sourcetree/items/SourceItem.cpp @@ -570,7 +570,7 @@ SourceItem::collectionClicked( const Tomahawk::collection_ptr& collection ) ViewPage* SourceItem::getCollectionPage( const Tomahawk::collection_ptr& collection ) const -{ +{ return m_collectionPages[ collection ]; } @@ -685,8 +685,7 @@ SourceItem::onTracksDropped( const QList< query_ptr >& queries ) { foreach ( const query_ptr& query, queries ) { - DatabaseCommand_ShareTrack* cmd = - new DatabaseCommand_ShareTrack( query, m_source->nodeId() ); + DatabaseCommand_ShareTrack* cmd = new DatabaseCommand_ShareTrack( query->track(), m_source->nodeId() ); Database::instance()->enqueue( QSharedPointer< DatabaseCommand >( cmd ) ); }