From d61a99629f7d19a247ed4d4330b7bcced2ae6964 Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Sat, 14 Apr 2012 22:09:22 -0400 Subject: [PATCH] Rework spotify UI a bit for greater clarity --- src/accounts/spotify/SpotifyAccount.cpp | 62 +++++++++++++---- src/accounts/spotify/SpotifyAccount.h | 2 + src/accounts/spotify/SpotifyAccountConfig.cpp | 66 ++++++++++++++----- src/accounts/spotify/SpotifyAccountConfig.h | 14 ++-- src/accounts/spotify/SpotifyAccountConfig.ui | 14 ++-- 5 files changed, 118 insertions(+), 40 deletions(-) diff --git a/src/accounts/spotify/SpotifyAccount.cpp b/src/accounts/spotify/SpotifyAccount.cpp index fe8d13d86..de915bc3f 100644 --- a/src/accounts/spotify/SpotifyAccount.cpp +++ b/src/accounts/spotify/SpotifyAccount.cpp @@ -90,8 +90,7 @@ SpotifyAccount::SpotifyAccount( const QString& accountId, const QString& path ) SpotifyAccount::~SpotifyAccount() { - foreach( QAction* action, m_customActions ) - ActionCollection::instance()->removeAction( action ); + clearUser(); } @@ -363,10 +362,41 @@ SpotifyAccount::resolverMessage( const QString &msgType, const QVariantMap &msg //const QString newuser = msg.value( "newUser" ).toString(); if( rmsg.isEmpty() ) return; - /// @todo: actually remove sync states for old user.... - JobStatusView::instance()->model()->addJob( new ErrorStatusMessage( QString( "Spotify: %1" ).arg( rmsg ) ) ); + clearUser(); + + if ( m_configWidget.data() ) + m_configWidget.data()->setPlaylists( QList< SpotifyPlaylistInfo* >() ); + + qDebug() << "User changed message from spotify:" << rmsg; } + else if ( msgType == "loginResponse" ) + { + if ( m_configWidget.data() ) + { + const bool success = msg.value( "success" ).toBool(); + const QString message = msg.value( "message" ).toString(); + m_configWidget.data()->loginResponse( success, message ); + } + } +} + + +void +SpotifyAccount::clearUser() +{ + foreach( SpotifyPlaylistUpdater* updater, m_updaters.values() ) + updater->deleteLater(); + m_updaters.clear(); + + qDeleteAll( m_allSpotifyPlaylists ); + m_allSpotifyPlaylists.clear(); + + m_qidToSlotMap.clear(); + m_waitingForCreateReply.clear(); + + foreach( QAction* action, m_customActions ) + ActionCollection::instance()->removeAction( action ); } @@ -386,6 +416,7 @@ SpotifyAccount::configurationWidget() if ( m_configWidget.isNull() ) { m_configWidget = QWeakPointer< SpotifyAccountConfig >( new SpotifyAccountConfig( this ) ); + connect( m_configWidget.data(), SIGNAL( login( QString,QString ) ), this, SLOT( login( QString,QString ) ) ); m_configWidget.data()->setPlaylists( m_allSpotifyPlaylists ); } @@ -410,14 +441,6 @@ SpotifyAccount::saveConfig() creds[ "highQuality" ] = m_configWidget.data()->highQuality(); setCredentials( creds ); - // Send the result to the resolver - QVariantMap msg; - msg[ "_msgtype" ] = "saveSettings"; - msg[ "username" ] = m_configWidget.data()->username(); - msg[ "password" ] = m_configWidget.data()->password(); - msg[ "highQuality" ] = m_configWidget.data()->highQuality(); - - m_spotifyResolver.data()->sendMessage( msg ); } QVariantHash config = configuration(); @@ -444,6 +467,21 @@ SpotifyAccount::saveConfig() } +void +SpotifyAccount::login( const QString& username, const QString& password ) +{ + // Send the result to the resolver + QVariantMap msg; + msg[ "_msgtype" ] = "login"; + msg[ "username" ] = username; + msg[ "password" ] = password; + + msg[ "highQuality" ] = m_configWidget.data()->highQuality(); + + m_spotifyResolver.data()->sendMessage( msg ); +} + + void SpotifyAccount::startPlaylistSync( SpotifyPlaylistInfo* playlist ) { diff --git a/src/accounts/spotify/SpotifyAccount.h b/src/accounts/spotify/SpotifyAccount.h index d60f26086..f2057a2d9 100644 --- a/src/accounts/spotify/SpotifyAccount.h +++ b/src/accounts/spotify/SpotifyAccount.h @@ -101,6 +101,7 @@ public slots: private slots: void resolverMessage( const QString& msgType, const QVariantMap& msg ); + void login( const QString& username, const QString& password ); // SpotifyResolver message handlers, all take msgtype, msg as argument // void ( const QString& msgType, const QVariantMap& msg ); void startPlaylistSyncWithPlaylist( const QString& msgType, const QVariantMap& msg ); @@ -109,6 +110,7 @@ private slots: private: void init(); void loadPlaylists(); + void clearUser(); void startPlaylistSync( SpotifyPlaylistInfo* playlist ); void stopPlaylistSync( SpotifyPlaylistInfo* playlist, bool forceDontDelete = false ); diff --git a/src/accounts/spotify/SpotifyAccountConfig.cpp b/src/accounts/spotify/SpotifyAccountConfig.cpp index 4d5a158df..b67b9b184 100644 --- a/src/accounts/spotify/SpotifyAccountConfig.cpp +++ b/src/accounts/spotify/SpotifyAccountConfig.cpp @@ -19,6 +19,7 @@ #include "SpotifyAccountConfig.h" #include "SpotifyAccount.h" +#include #include "ui_SpotifyAccountConfig.h" #include @@ -32,18 +33,17 @@ SpotifyAccountConfig::SpotifyAccountConfig( SpotifyAccount *account ) : QWidget( 0 ) , m_ui( new Ui::SpotifyConfig ) , m_account( account ) + , m_playlistsLoading( 0 ) { m_ui->setupUi( this ); - connect( m_ui->verifyCreds, SIGNAL( clicked( bool ) ), this, SLOT( verifyLogin() ) ); + connect( m_ui->loginButton, SIGNAL( clicked( bool ) ), this, SLOT( doLogin() ) ); - m_resetTimer.setSingleShot( true ); - m_resetTimer.setInterval( 10000 ); - - connect( &m_resetTimer, SIGNAL( timeout() ), this, SLOT( resetVerifyButton() ) ); - connect( m_ui->usernameEdit, SIGNAL( textChanged( QString ) ), this, SLOT( clearVerifyButton() ) ); - connect( m_ui->passwordEdit, SIGNAL( textChanged( QString ) ), this, SLOT( clearVerifyButton() ) ); + connect( m_ui->usernameEdit, SIGNAL( textChanged( QString ) ), this, SLOT( resetLoginButton() ) ); + connect( m_ui->passwordEdit, SIGNAL( textChanged( QString ) ), this, SLOT( resetLoginButton() ) ); loadFromConfig(); + + m_playlistsLoading = new LoadingSpinner( m_ui->playlistList ); } @@ -110,6 +110,10 @@ SpotifyAccountConfig::deleteOnUnsync() const void SpotifyAccountConfig::setPlaylists( const QList& playlists ) { + // User always has at least 1 playlist (starred tracks) + if ( !playlists.isEmpty() ) + m_playlistsLoading->fadeOut(); + m_ui->playlistList->clear(); foreach ( SpotifyPlaylistInfo* pl, playlists ) { @@ -122,8 +126,16 @@ SpotifyAccountConfig::setPlaylists( const QList& playlist void -SpotifyAccountConfig::verifyLogin() +SpotifyAccountConfig::doLogin() { + m_ui->loginButton->setText( tr( "Logging in..." ) ); + m_ui->loginButton->setEnabled( false ); + + m_playlistsLoading->fadeIn(); + + emit login( username(), password() ); + + /* QVariantMap msg; msg[ "_msgtype" ] = "checkLogin"; msg[ "username" ] = username(); @@ -134,10 +146,30 @@ SpotifyAccountConfig::verifyLogin() m_ui->verifyCreds->setText( tr( "Verifying..." ) ); m_ui->verifyCreds->setEnabled( false ); - m_resetTimer.start(); + m_resetTimer.start();*/ } +void +SpotifyAccountConfig::loginResponse( bool success, const QString& msg ) +{ + m_playlistsLoading->fadeOut(); + + if ( success ) + { + m_ui->loginButton->setText( tr( "Logged in!" ) ); + m_ui->loginButton->setEnabled( false ); + } + else + { + m_ui->loginButton->setText( tr( "Failed: %1" ).arg( msg ) ); + m_ui->loginButton->setEnabled( true ); + } + +} + + +/* void SpotifyAccountConfig::resetVerifyButton() { @@ -145,17 +177,19 @@ SpotifyAccountConfig::resetVerifyButton() m_ui->verifyCreds->setEnabled( true ); m_ui->verifyCreds->setToolTip( tr( "No response from Spotify, bad credentials likely." ) ); } - +*/ void -SpotifyAccountConfig::clearVerifyButton() +SpotifyAccountConfig::resetLoginButton() { - m_ui->verifyCreds->setText( tr( "Verify" ) ); - m_ui->verifyCreds->setEnabled( true ); - m_ui->verifyCreds->setToolTip( QString() ); + if ( !m_ui->loginButton->isEnabled() ) + { + m_ui->loginButton->setText( tr( "Log In" ) ); + m_ui->loginButton->setEnabled( true ); + } } - +/* void SpotifyAccountConfig::verifyResult( const QString& msgType, const QVariantMap& msg ) { @@ -172,4 +206,4 @@ SpotifyAccountConfig::verifyResult( const QString& msgType, const QVariantMap& m m_ui->verifyCreds->setEnabled( true ); m_ui->verifyCreds->setToolTip( message ); } -} +}*/ diff --git a/src/accounts/spotify/SpotifyAccountConfig.h b/src/accounts/spotify/SpotifyAccountConfig.h index 889a3a7ca..9aa5fe1d0 100644 --- a/src/accounts/spotify/SpotifyAccountConfig.h +++ b/src/accounts/spotify/SpotifyAccountConfig.h @@ -23,6 +23,7 @@ #include #include +class LoadingSpinner; class QShowEvent; namespace Ui @@ -54,21 +55,24 @@ public: void loadFromConfig(); void saveSettings(); + void loginResponse( bool success, const QString& msg ); +signals: + void login( const QString& username, const QString& pw ); + public slots: - void verifyResult( const QString& msgType, const QVariantMap& msg ); +// void verifyResult( const QString& msgType, const QVariantMap& msg ); protected: void showEvent( QShowEvent* event ); private slots: - void verifyLogin(); - void resetVerifyButton(); - void clearVerifyButton(); + void doLogin(); + void resetLoginButton(); private: Ui::SpotifyConfig* m_ui; SpotifyAccount* m_account; - QTimer m_resetTimer; + LoadingSpinner* m_playlistsLoading; }; } diff --git a/src/accounts/spotify/SpotifyAccountConfig.ui b/src/accounts/spotify/SpotifyAccountConfig.ui index 24dbbaa3b..3e603368f 100644 --- a/src/accounts/spotify/SpotifyAccountConfig.ui +++ b/src/accounts/spotify/SpotifyAccountConfig.ui @@ -109,15 +109,15 @@ - - - - Verify - - - + + + + Log In + + +