diff --git a/src/libtomahawk/accounts/spotify/SpotifyAccount.cpp b/src/libtomahawk/accounts/spotify/SpotifyAccount.cpp index f06a35fde..f330678ea 100644 --- a/src/libtomahawk/accounts/spotify/SpotifyAccount.cpp +++ b/src/libtomahawk/accounts/spotify/SpotifyAccount.cpp @@ -547,47 +547,12 @@ SpotifyAccount::subscribeActionTriggered( bool ) } } + Q_ASSERT( updater ); if ( !updater ) - { - tLog() << "No SpotifyPlaylistUpdater in payload slot of triggered action! Uh oh!!"; return; - } - SpotifyPlaylistInfo* info = m_allSpotifyPlaylists.value( updater->spotifyId(), 0 ); - - // When we unsubscribe, all playlists is resent - // and we will could loose the SpotifyPlaylistInfo, but all we really need is the id - if ( updater->spotifyId().isEmpty() ) - { - tLog() << "No spotify id in updater, WTF?"; - return; - } - - if ( !info ) - { - info = new SpotifyPlaylistInfo( playlist->title(), - updater->spotifyId(), - updater->spotifyId(), - false, - false - ); - - registerPlaylistInfo( info ); - } - - info->subscribed = !updater->subscribed(); - - QVariantMap msg; - msg[ "_msgtype" ] = "setSubscription"; - msg[ "subscribe" ] = info->subscribed; - msg[ "playlistid" ] = info->plid; - - sendMessage( msg, this ); - - updater->setSync( !updater->sync() ); - updater->setSubscribed( !updater->subscribed() ); - info->sync = !updater->sync(); - info->subscribed = !updater->subscribed(); + // Toggle subscription status + setSubscribedForPlaylist( playlist, !updater->subscribed() ); } @@ -661,6 +626,63 @@ SpotifyAccount::syncActionTriggered( bool ) } +void +SpotifyAccount::setSubscribedForPlaylist( const playlist_ptr& playlist, bool subscribed ) +{ + SpotifyPlaylistUpdater* updater = 0; + QList updaters = playlist->updaters(); + foreach ( PlaylistUpdaterInterface* u, updaters ) + { + if ( SpotifyPlaylistUpdater* spotifyUpdater = qobject_cast< SpotifyPlaylistUpdater* >( u ) ) + { + updater = spotifyUpdater; + break; + } + } + + if ( !updater ) + { + tLog() << "No SpotifyPlaylistUpdater in payload slot of triggered action! Uh oh!!"; + return; + } + + SpotifyPlaylistInfo* info = m_allSpotifyPlaylists.value( updater->spotifyId(), 0 ); + + // When we unsubscribe, all playlists is resent + // and we will could loose the SpotifyPlaylistInfo, but all we really need is the id + if ( updater->spotifyId().isEmpty() ) + { + tLog() << "No spotify id in updater, WTF?"; + return; + } + + if ( !info ) + { + info = new SpotifyPlaylistInfo( playlist->title(), + updater->spotifyId(), + updater->spotifyId(), + false, + false + ); + + registerPlaylistInfo( info ); + } + + info->subscribed = subscribed; + info->sync = subscribed; + + QVariantMap msg; + msg[ "_msgtype" ] = "setSubscription"; + msg[ "subscribe" ] = info->subscribed; + msg[ "playlistid" ] = info->plid; + + sendMessage( msg, this ); + + updater->setSync( subscribed ); + updater->setSubscribed( subscribed ); +} + + playlist_ptr SpotifyAccount::playlistFromAction( QAction* action ) const { diff --git a/src/libtomahawk/accounts/spotify/SpotifyAccount.h b/src/libtomahawk/accounts/spotify/SpotifyAccount.h index 39e5d1c0c..c31bcff2d 100644 --- a/src/libtomahawk/accounts/spotify/SpotifyAccount.h +++ b/src/libtomahawk/accounts/spotify/SpotifyAccount.h @@ -36,6 +36,8 @@ class ScriptResolver; namespace Tomahawk { +class SpotifyParser; + namespace InfoSystem { class SpotifyInfoPlugin; @@ -150,6 +152,7 @@ private: void fetchFullPlaylist( SpotifyPlaylistInfo* playlist ); void setSyncForPlaylist( const QString& spotifyPlaylistId, bool sync ); + void setSubscribedForPlaylist( const playlist_ptr& pl, bool subscribed ); void createActions(); void removeActions(); @@ -175,6 +178,7 @@ private: SmartPointerList< QAction > m_customActions; friend class ::SpotifyPlaylistUpdater; + friend class Tomahawk::SpotifyParser; }; } diff --git a/src/libtomahawk/utils/SpotifyParser.cpp b/src/libtomahawk/utils/SpotifyParser.cpp index 02f024a44..877c811e9 100644 --- a/src/libtomahawk/utils/SpotifyParser.cpp +++ b/src/libtomahawk/utils/SpotifyParser.cpp @@ -370,12 +370,13 @@ SpotifyParser::checkBrowseFinished() if ( !m_browseUri.contains( creds.value( "username" ).toString() ) ) updater->setCanSubscribe( true ); - updater->setSubscribed( true ); - updater->setSync( true ); - // Just register the infos Accounts::SpotifyAccount::instance()->registerPlaylistInfo( m_title, m_browseUri, m_browseUri, false, false ); Accounts::SpotifyAccount::instance()->registerUpdaterForPlaylist( m_browseUri, updater ); + + + Accounts::SpotifyAccount::instance()->setSubscribedForPlaylist( m_playlist, true ); + } return; }