diff --git a/src/libtomahawk/accounts/spotify/SpotifyAccount.cpp b/src/libtomahawk/accounts/spotify/SpotifyAccount.cpp index 9818e398d..5cf9ee94e 100644 --- a/src/libtomahawk/accounts/spotify/SpotifyAccount.cpp +++ b/src/libtomahawk/accounts/spotify/SpotifyAccount.cpp @@ -414,6 +414,18 @@ SpotifyAccount::setManualResolverPath( const QString &resolverPath ) } } +void +SpotifyAccount::starTrack(const QString &artist, const QString &title, const bool starred) +{ + qDebug() << Q_FUNC_INFO << artist << title << starred; + QVariantMap msg; + msg[ "_msgtype" ] = "setStarred"; + msg[ "starred" ] = starred; + msg[ "artist" ] = artist; + msg[ "title" ] = title; + sendMessage( msg ); +} + bool SpotifyAccount::loggedIn() const diff --git a/src/libtomahawk/accounts/spotify/SpotifyAccount.h b/src/libtomahawk/accounts/spotify/SpotifyAccount.h index e3bf35965..4e252f3c7 100644 --- a/src/libtomahawk/accounts/spotify/SpotifyAccount.h +++ b/src/libtomahawk/accounts/spotify/SpotifyAccount.h @@ -110,6 +110,7 @@ public: bool deleteOnUnsync() const; bool loveSync() const; + void starTrack(const QString& artist, const QString&title, const bool starred); void setManualResolverPath( const QString& resolverPath ); bool loggedIn() const; @@ -139,13 +140,11 @@ private slots: void playlistCopyCreated( const QString& msgType, const QVariantMap& msg, const QVariant& extraData ); void delayedInit(); void hookupAfterDeletion( bool autoEnable ); - private: void init(); bool checkForResolver(); void hookupResolver(); void killExistingResolvers(); - void loadPlaylists(); void clearUser( bool permanentlyDelete = false ); diff --git a/src/libtomahawk/accounts/spotify/SpotifyInfoPlugin.cpp b/src/libtomahawk/accounts/spotify/SpotifyInfoPlugin.cpp index 87697c02f..60872a9cc 100644 --- a/src/libtomahawk/accounts/spotify/SpotifyInfoPlugin.cpp +++ b/src/libtomahawk/accounts/spotify/SpotifyInfoPlugin.cpp @@ -20,6 +20,7 @@ #include "SpotifyAccount.h" #include "utils/Closure.h" +#include "utils/Logger.h" using namespace Tomahawk; using namespace Tomahawk::InfoSystem; @@ -30,7 +31,10 @@ SpotifyInfoPlugin::SpotifyInfoPlugin( Accounts::SpotifyAccount* account ) , m_account( QWeakPointer< Accounts::SpotifyAccount >( account ) ) { if ( !m_account.isNull() ) + { m_supportedGetTypes << InfoAlbumSongs; + m_supportedPushTypes << InfoLove << InfoUnLove; + } } @@ -39,6 +43,53 @@ SpotifyInfoPlugin::~SpotifyInfoPlugin() } +void +SpotifyInfoPlugin::pushInfo( Tomahawk::InfoSystem::InfoPushData pushData ) +{ + if ( m_account.isNull() || !m_account.data()->loggedIn() ) + return; + + switch ( pushData.type ) + { + case InfoLove: + case InfoUnLove: + sendLoveSong(pushData.type, pushData.infoPair.second); + break; + + default: + return; + } +} + +void +SpotifyInfoPlugin::sendLoveSong( const InfoType type, QVariant input ) +{ + + if ( m_account.isNull() || !m_account.data()->loggedIn() ) + return; + + if( !m_account.data()->loveSync() ) + return; + + if ( !input.toMap().contains( "trackinfo" ) || !input.toMap()[ "trackinfo" ].canConvert< Tomahawk::InfoSystem::InfoStringHash >() ) + { + tLog( LOGVERBOSE ) << "SpotifyInfoPlugin::sendLoveSong cannot convert input!"; + return; + } + + InfoStringHash hash = input.toMap()[ "trackinfo" ].value< Tomahawk::InfoSystem::InfoStringHash >(); + if ( !hash.contains( "title" ) || !hash.contains( "artist" ) || !hash.contains( "album" ) ) + return; + + if ( type == Tomahawk::InfoSystem::InfoLove ) + { + m_account.data()->starTrack( hash["artist"], hash["title"], true ); + } + else if ( type == Tomahawk::InfoSystem::InfoUnLove ) + { + m_account.data()->starTrack( hash["artist"], hash["title"], false ); + } +} void SpotifyInfoPlugin::getInfo( InfoRequestData requestData ) @@ -97,7 +148,7 @@ SpotifyInfoPlugin::notInCacheSlot( InfoStringHash criteria, InfoRequestData requ else { // Running resolver, so do the lookup through that - qDebug() << Q_FUNC_INFO << "Doing album lookup through spotify:" << album << artist; + tLog( LOGVERBOSE ) << Q_FUNC_INFO << "Doing album lookup through spotify:" << album << artist; QVariantMap message; message[ "_msgtype" ] = "albumListing"; message[ "artist" ] = artist; @@ -138,7 +189,7 @@ SpotifyInfoPlugin::albumListingResult( const QString& msgType, const QVariantMap trackNameList << trackData[ "track" ].toString(); } - qDebug() << Q_FUNC_INFO << "Successfully got album listing from spotify resolver"; + tLog( LOGVERBOSE ) << Q_FUNC_INFO << "Successfully got album listing from spotify resolver"; trackListResult( trackNameList, requestData ); } @@ -171,12 +222,12 @@ SpotifyInfoPlugin::albumIdLookupFinished( QNetworkReply* reply, const InfoReques const QString id = album.value( "href" ).toString(); if ( id.isEmpty() || !id.contains( "spotify:album" ) ) { - qDebug() << "Empty or malformed spotify album ID from json:" << id << response; + tLog( LOGVERBOSE ) << "Empty or malformed spotify album ID from json:" << id << response; dataError( requestData ); return; } - qDebug() << "Doing spotify album lookup via webservice with ID:" << id; + tLog( LOGVERBOSE ) << "Doing spotify album lookup via webservice with ID:" << id; QUrl lookupUrl( QString( "http://spotikea.tomahawk-player.org/browse/%1" ).arg( id ) ); @@ -186,7 +237,7 @@ SpotifyInfoPlugin::albumIdLookupFinished( QNetworkReply* reply, const InfoReques } else { - qDebug() << "Network Error retrieving ID from spotify metadata service:" << reply->error() << reply->errorString() << reply->url(); + tLog( LOGVERBOSE ) << "Network Error retrieving ID from spotify metadata service:" << reply->error() << reply->errorString() << reply->url(); } } @@ -226,7 +277,7 @@ SpotifyInfoPlugin::albumContentsLookupFinished( QNetworkReply* reply, const Info trackNameList << trackMap.value( "title" ).toString(); } - qDebug() << Q_FUNC_INFO << "Successfully got album listing from spotikea service!"; + tLog( LOGVERBOSE ) << Q_FUNC_INFO << "Successfully got album listing from spotikea service!"; if ( trackNameList.isEmpty() ) dataError( requestData ); @@ -235,7 +286,7 @@ SpotifyInfoPlugin::albumContentsLookupFinished( QNetworkReply* reply, const Info } else { - qDebug() << "Network Error retrieving ID from spotify metadata service:" << reply->error() << reply->errorString() << reply->url(); + tLog( LOGVERBOSE ) << "Network Error retrieving ID from spotify metadata service:" << reply->error() << reply->errorString() << reply->url(); } } diff --git a/src/libtomahawk/accounts/spotify/SpotifyInfoPlugin.h b/src/libtomahawk/accounts/spotify/SpotifyInfoPlugin.h index 97c0b96ad..26757cac2 100644 --- a/src/libtomahawk/accounts/spotify/SpotifyInfoPlugin.h +++ b/src/libtomahawk/accounts/spotify/SpotifyInfoPlugin.h @@ -52,7 +52,7 @@ protected slots: virtual void init() {} virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData ); virtual void notInCacheSlot( Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData ); - virtual void pushInfo( Tomahawk::InfoSystem::InfoPushData ) {} + virtual void pushInfo( Tomahawk::InfoSystem::InfoPushData ); private slots: void albumIdLookupFinished( QNetworkReply* reply, const Tomahawk::InfoSystem::InfoRequestData& requestData ); @@ -61,7 +61,7 @@ private slots: private: void dataError( InfoRequestData ); void trackListResult( const QStringList& trackNameList, const Tomahawk::InfoSystem::InfoRequestData& requestData ); - + void sendLoveSong( const InfoType type, QVariant input ); QWeakPointer< Tomahawk::Accounts::SpotifyAccount > m_account; };