1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-09 07:36:48 +02:00

Only show Sync actions if user is logged in, and re-add if spotify user switches

This commit is contained in:
Leo Franchi
2012-04-15 22:50:09 -04:00
parent 46cb1f01fb
commit c7feb0f6f0
2 changed files with 33 additions and 9 deletions

View File

@@ -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();
}

View File

@@ -119,6 +119,9 @@ private:
void setSyncForPlaylist( const QString& spotifyPlaylistId, bool sync );
void createActions();
void removeActions();
QWeakPointer<SpotifyAccountConfig> m_configWidget;
QWeakPointer<QWidget> m_aboutWidget;
QWeakPointer<ScriptResolver> m_spotifyResolver;