diff --git a/src/libtomahawk/accounts/spotify/SpotifyAccount.cpp b/src/libtomahawk/accounts/spotify/SpotifyAccount.cpp index f7b11d8c5..4c955efb7 100644 --- a/src/libtomahawk/accounts/spotify/SpotifyAccount.cpp +++ b/src/libtomahawk/accounts/spotify/SpotifyAccount.cpp @@ -902,6 +902,19 @@ SpotifyAccount::resolverMessage( const QString &msgType, const QVariantMap &msg updater->spotifyTracksMoved( tracksList, newStartPos, newRev, oldRev ); } + else if ( msgType == "starredChanged" ) + { + if( loveSync() ) + { + const QVariantList tracksList = msg.value( "tracks" ).toList(); + const bool love = msg.value( "starred" ).toBool(); + QList qs = SpotifyPlaylistUpdater::variantToQueries( tracksList ); + foreach( const query_ptr& query, qs ) + { + query->setLoved( love ); + } + } + } else if ( msgType == "playlistMetadataChanged" ) { const QString plid = msg.value( "id" ).toString(); @@ -1114,6 +1127,7 @@ SpotifyAccount::saveConfig() QVariantHash config = configuration(); config[ "deleteOnUnsync" ] = m_configWidget.data()->deleteOnUnsync(); + config[ "loveSync" ] = m_configWidget.data()->loveSync(); setConfiguration( config ); m_configWidget.data()->saveSettings(); @@ -1123,7 +1137,15 @@ SpotifyAccount::saveConfig() if ( pl->changed ) { pl->changed = false; - if ( pl->sync ) + if( !pl->sync && pl->loveSync ) + { + QVariantMap msg; + msg[ "_msgtype" ] = "setSync"; + msg[ "playlistid" ] = pl->plid; + msg[ "sync" ] = pl->loveSync; + sendMessage( msg ); + } + else if ( pl->sync ) { // Fetch full playlist contents, then begin the sync startPlaylistSync( pl ); @@ -1355,6 +1377,14 @@ SpotifyAccount::deleteOnUnsync() const return configuration().value( "deleteOnUnsync", false ).toBool(); } + +bool +SpotifyAccount::loveSync() const +{ + return configuration().value( "loveSync", false ).toBool(); +} + + void SpotifyAccount::stopPlaylistSync( SpotifyPlaylistInfo* playlist, bool forceDontDelete ) { diff --git a/src/libtomahawk/accounts/spotify/SpotifyAccount.h b/src/libtomahawk/accounts/spotify/SpotifyAccount.h index afc4ee3cc..e3bf35965 100644 --- a/src/libtomahawk/accounts/spotify/SpotifyAccount.h +++ b/src/libtomahawk/accounts/spotify/SpotifyAccount.h @@ -51,13 +51,13 @@ class SpotifyAccountConfig; // metadata for a playlist struct SpotifyPlaylistInfo { QString name, plid, revid; - bool sync, subscribed, changed, isOwner; + bool sync, subscribed, changed, isOwner, loveSync; - SpotifyPlaylistInfo( const QString& nname, const QString& pid, const QString& rrevid, bool ssync, bool ssubscribed, bool isowner = false ) - : name( nname ), plid( pid ), revid( rrevid ), sync( ssync ), subscribed( ssubscribed ), changed( false ), isOwner( isowner ) {} + SpotifyPlaylistInfo( const QString& nname, const QString& pid, const QString& rrevid, bool ssync, bool ssubscribed, bool isowner = false, bool lovesync = false ) + : name( nname ), plid( pid ), revid( rrevid ), sync( ssync ), subscribed( ssubscribed ), changed( false ), isOwner( isowner ), loveSync( lovesync ) {} - SpotifyPlaylistInfo() : sync( false ), changed( false ) {} + SpotifyPlaylistInfo() : sync( false ), changed( false ), loveSync( false ) {} }; @@ -109,7 +109,7 @@ public: void unregisterUpdater( const QString& plid ); bool deleteOnUnsync() const; - + bool loveSync() const; void setManualResolverPath( const QString& resolverPath ); bool loggedIn() const; diff --git a/src/libtomahawk/accounts/spotify/SpotifyAccountConfig.cpp b/src/libtomahawk/accounts/spotify/SpotifyAccountConfig.cpp index 09ce54add..5ff1ea278 100644 --- a/src/libtomahawk/accounts/spotify/SpotifyAccountConfig.cpp +++ b/src/libtomahawk/accounts/spotify/SpotifyAccountConfig.cpp @@ -77,6 +77,7 @@ SpotifyAccountConfig::loadFromConfig() m_ui->passwordEdit->setText( m_account->credentials().value( "password" ).toString() ); m_ui->streamingCheckbox->setChecked( m_account->credentials().value( "highQuality" ).toBool() ); m_ui->deleteOnUnsync->setChecked( m_account->deleteOnUnsync() ); + m_ui->loveSync->setChecked( m_account->loveSync() ); if ( m_account->loggedIn() ) { @@ -103,6 +104,11 @@ SpotifyAccountConfig::saveSettings() pl->changed = true; pl->sync = toSync; } + if ( pl->name == "Starred Tracks" && pl->loveSync != loveSync() ) + { + pl->loveSync = loveSync(); + pl->changed = true; + } } } @@ -133,6 +139,13 @@ SpotifyAccountConfig::deleteOnUnsync() const } +bool +SpotifyAccountConfig::loveSync() const +{ + return m_ui->loveSync->isChecked(); +} + + void SpotifyAccountConfig::setPlaylists( const QList& playlists ) { diff --git a/src/libtomahawk/accounts/spotify/SpotifyAccountConfig.h b/src/libtomahawk/accounts/spotify/SpotifyAccountConfig.h index 1080d2a70..c3eeb2267 100644 --- a/src/libtomahawk/accounts/spotify/SpotifyAccountConfig.h +++ b/src/libtomahawk/accounts/spotify/SpotifyAccountConfig.h @@ -50,6 +50,7 @@ public: QString password() const; bool highQuality() const; bool deleteOnUnsync() const; + bool loveSync() const; void setPlaylists( const QList< SpotifyPlaylistInfo* >& playlists ); diff --git a/src/libtomahawk/accounts/spotify/SpotifyAccountConfig.ui b/src/libtomahawk/accounts/spotify/SpotifyAccountConfig.ui index 129d8a129..8eb3e55f5 100644 --- a/src/libtomahawk/accounts/spotify/SpotifyAccountConfig.ui +++ b/src/libtomahawk/accounts/spotify/SpotifyAccountConfig.ui @@ -145,6 +145,19 @@ + + + + Qt::LeftToRight + + + Sync Starred tracks to Loved tracks + + + false + + +