From c7feb0f6f0d8fc6da8727ddf28fed1461a3c5196 Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Sun, 15 Apr 2012 22:50:09 -0400 Subject: [PATCH] Only show Sync actions if user is logged in, and re-add if spotify user switches --- src/accounts/spotify/SpotifyAccount.cpp | 39 +++++++++++++++++++------ src/accounts/spotify/SpotifyAccount.h | 3 ++ 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/accounts/spotify/SpotifyAccount.cpp b/src/accounts/spotify/SpotifyAccount.cpp index 552c85fd6..008139b14 100644 --- a/src/accounts/spotify/SpotifyAccount.cpp +++ b/src/accounts/spotify/SpotifyAccount.cpp @@ -113,12 +113,6 @@ SpotifyAccount::init() msg[ "_msgtype" ] = "getCredentials"; m_spotifyResolver.data()->sendMessage( msg ); } - - QAction* action = new QAction( 0 ); - action->setIcon( QIcon( RESPATH "images/spotify-logo.png" ) ); - connect( action, SIGNAL( triggered( bool ) ), this, SLOT( syncActionTriggered( bool ) ) ); - ActionCollection::instance()->addAction( ActionCollection::LocalPlaylists, action, this ); - m_customActions.append( action ); } @@ -376,10 +370,14 @@ SpotifyAccount::resolverMessage( const QString &msgType, const QVariantMap &msg setCredentials( creds ); sync(); + const bool success = msg.value( "success" ).toBool(); + + if ( success ) + createActions(); + configurationWidget(); // ensure it's created so we can set the login button if ( m_configWidget.data() ) { - const bool success = msg.value( "success" ).toBool(); const QString message = msg.value( "message" ).toString(); m_configWidget.data()->loginResponse( success, message ); } @@ -417,8 +415,7 @@ SpotifyAccount::clearUser( bool permanentlyDelete ) m_qidToSlotMap.clear(); m_waitingForCreateReply.clear(); - foreach( QAction* action, m_customActions ) - ActionCollection::instance()->removeAction( action ); + removeActions(); } @@ -731,3 +728,27 @@ SpotifyAccount::setSyncForPlaylist( const QString& spotifyPlaylistId, bool sync m_configWidget.data()->setPlaylists( m_allSpotifyPlaylists ); } + +void +SpotifyAccount::createActions() +{ + if ( !m_customActions.isEmpty() ) + return; + + QAction* action = new QAction( 0 ); + action->setIcon( QIcon( RESPATH "images/spotify-logo.png" ) ); + connect( action, SIGNAL( triggered( bool ) ), this, SLOT( syncActionTriggered( bool ) ) ); + ActionCollection::instance()->addAction( ActionCollection::LocalPlaylists, action, this ); + m_customActions.append( action ); +} + + +void +SpotifyAccount::removeActions() +{ + foreach( QAction* action, m_customActions ) + ActionCollection::instance()->removeAction( action ); + + m_customActions.clear(); +} + diff --git a/src/accounts/spotify/SpotifyAccount.h b/src/accounts/spotify/SpotifyAccount.h index c6cf1a73c..db035fe0a 100644 --- a/src/accounts/spotify/SpotifyAccount.h +++ b/src/accounts/spotify/SpotifyAccount.h @@ -119,6 +119,9 @@ private: void setSyncForPlaylist( const QString& spotifyPlaylistId, bool sync ); + void createActions(); + void removeActions(); + QWeakPointer m_configWidget; QWeakPointer m_aboutWidget; QWeakPointer m_spotifyResolver;