1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-22 13:43:11 +02:00

Rework spotify UI a bit for greater clarity

This commit is contained in:
Leo Franchi
2012-04-14 22:09:22 -04:00
parent 4d02b9945d
commit d61a99629f
5 changed files with 118 additions and 40 deletions

View File

@@ -90,8 +90,7 @@ SpotifyAccount::SpotifyAccount( const QString& accountId, const QString& path )
SpotifyAccount::~SpotifyAccount() SpotifyAccount::~SpotifyAccount()
{ {
foreach( QAction* action, m_customActions ) clearUser();
ActionCollection::instance()->removeAction( action );
} }
@@ -363,10 +362,41 @@ SpotifyAccount::resolverMessage( const QString &msgType, const QVariantMap &msg
//const QString newuser = msg.value( "newUser" ).toString(); //const QString newuser = msg.value( "newUser" ).toString();
if( rmsg.isEmpty() ) if( rmsg.isEmpty() )
return; 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() ) if ( m_configWidget.isNull() )
{ {
m_configWidget = QWeakPointer< SpotifyAccountConfig >( new SpotifyAccountConfig( this ) ); 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 ); m_configWidget.data()->setPlaylists( m_allSpotifyPlaylists );
} }
@@ -410,14 +441,6 @@ SpotifyAccount::saveConfig()
creds[ "highQuality" ] = m_configWidget.data()->highQuality(); creds[ "highQuality" ] = m_configWidget.data()->highQuality();
setCredentials( creds ); 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(); 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 void
SpotifyAccount::startPlaylistSync( SpotifyPlaylistInfo* playlist ) SpotifyAccount::startPlaylistSync( SpotifyPlaylistInfo* playlist )
{ {

View File

@@ -101,6 +101,7 @@ public slots:
private slots: private slots:
void resolverMessage( const QString& msgType, const QVariantMap& msg ); 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 // SpotifyResolver message handlers, all take msgtype, msg as argument
// void <here>( const QString& msgType, const QVariantMap& msg ); // void <here>( const QString& msgType, const QVariantMap& msg );
void startPlaylistSyncWithPlaylist( const QString& msgType, const QVariantMap& msg ); void startPlaylistSyncWithPlaylist( const QString& msgType, const QVariantMap& msg );
@@ -109,6 +110,7 @@ private slots:
private: private:
void init(); void init();
void loadPlaylists(); void loadPlaylists();
void clearUser();
void startPlaylistSync( SpotifyPlaylistInfo* playlist ); void startPlaylistSync( SpotifyPlaylistInfo* playlist );
void stopPlaylistSync( SpotifyPlaylistInfo* playlist, bool forceDontDelete = false ); void stopPlaylistSync( SpotifyPlaylistInfo* playlist, bool forceDontDelete = false );

View File

@@ -19,6 +19,7 @@
#include "SpotifyAccountConfig.h" #include "SpotifyAccountConfig.h"
#include "SpotifyAccount.h" #include "SpotifyAccount.h"
#include <playlist/dynamic/widgets/LoadingSpinner.h>
#include "ui_SpotifyAccountConfig.h" #include "ui_SpotifyAccountConfig.h"
#include <QListWidget> #include <QListWidget>
@@ -32,18 +33,17 @@ SpotifyAccountConfig::SpotifyAccountConfig( SpotifyAccount *account )
: QWidget( 0 ) : QWidget( 0 )
, m_ui( new Ui::SpotifyConfig ) , m_ui( new Ui::SpotifyConfig )
, m_account( account ) , m_account( account )
, m_playlistsLoading( 0 )
{ {
m_ui->setupUi( this ); 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 ); connect( m_ui->usernameEdit, SIGNAL( textChanged( QString ) ), this, SLOT( resetLoginButton() ) );
m_resetTimer.setInterval( 10000 ); connect( m_ui->passwordEdit, SIGNAL( textChanged( QString ) ), this, SLOT( resetLoginButton() ) );
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() ) );
loadFromConfig(); loadFromConfig();
m_playlistsLoading = new LoadingSpinner( m_ui->playlistList );
} }
@@ -110,6 +110,10 @@ SpotifyAccountConfig::deleteOnUnsync() const
void void
SpotifyAccountConfig::setPlaylists( const QList<SpotifyPlaylistInfo *>& playlists ) SpotifyAccountConfig::setPlaylists( const QList<SpotifyPlaylistInfo *>& playlists )
{ {
// User always has at least 1 playlist (starred tracks)
if ( !playlists.isEmpty() )
m_playlistsLoading->fadeOut();
m_ui->playlistList->clear(); m_ui->playlistList->clear();
foreach ( SpotifyPlaylistInfo* pl, playlists ) foreach ( SpotifyPlaylistInfo* pl, playlists )
{ {
@@ -122,8 +126,16 @@ SpotifyAccountConfig::setPlaylists( const QList<SpotifyPlaylistInfo *>& playlist
void 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; QVariantMap msg;
msg[ "_msgtype" ] = "checkLogin"; msg[ "_msgtype" ] = "checkLogin";
msg[ "username" ] = username(); msg[ "username" ] = username();
@@ -134,10 +146,30 @@ SpotifyAccountConfig::verifyLogin()
m_ui->verifyCreds->setText( tr( "Verifying..." ) ); m_ui->verifyCreds->setText( tr( "Verifying..." ) );
m_ui->verifyCreds->setEnabled( false ); 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 void
SpotifyAccountConfig::resetVerifyButton() SpotifyAccountConfig::resetVerifyButton()
{ {
@@ -145,17 +177,19 @@ SpotifyAccountConfig::resetVerifyButton()
m_ui->verifyCreds->setEnabled( true ); m_ui->verifyCreds->setEnabled( true );
m_ui->verifyCreds->setToolTip( tr( "No response from Spotify, bad credentials likely." ) ); m_ui->verifyCreds->setToolTip( tr( "No response from Spotify, bad credentials likely." ) );
} }
*/
void void
SpotifyAccountConfig::clearVerifyButton() SpotifyAccountConfig::resetLoginButton()
{ {
m_ui->verifyCreds->setText( tr( "Verify" ) ); if ( !m_ui->loginButton->isEnabled() )
m_ui->verifyCreds->setEnabled( true ); {
m_ui->verifyCreds->setToolTip( QString() ); m_ui->loginButton->setText( tr( "Log In" ) );
m_ui->loginButton->setEnabled( true );
}
} }
/*
void void
SpotifyAccountConfig::verifyResult( const QString& msgType, const QVariantMap& msg ) 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->setEnabled( true );
m_ui->verifyCreds->setToolTip( message ); m_ui->verifyCreds->setToolTip( message );
} }
} }*/

View File

@@ -23,6 +23,7 @@
#include <QVariantMap> #include <QVariantMap>
#include <QTimer> #include <QTimer>
class LoadingSpinner;
class QShowEvent; class QShowEvent;
namespace Ui namespace Ui
@@ -54,21 +55,24 @@ public:
void loadFromConfig(); void loadFromConfig();
void saveSettings(); void saveSettings();
void loginResponse( bool success, const QString& msg );
signals:
void login( const QString& username, const QString& pw );
public slots: public slots:
void verifyResult( const QString& msgType, const QVariantMap& msg ); // void verifyResult( const QString& msgType, const QVariantMap& msg );
protected: protected:
void showEvent( QShowEvent* event ); void showEvent( QShowEvent* event );
private slots: private slots:
void verifyLogin(); void doLogin();
void resetVerifyButton(); void resetLoginButton();
void clearVerifyButton();
private: private:
Ui::SpotifyConfig* m_ui; Ui::SpotifyConfig* m_ui;
SpotifyAccount* m_account; SpotifyAccount* m_account;
QTimer m_resetTimer; LoadingSpinner* m_playlistsLoading;
}; };
} }

View File

@@ -109,15 +109,15 @@
</item> </item>
</layout> </layout>
</item> </item>
</layout>
</item>
<item> <item>
<widget class="QPushButton" name="verifyCreds"> <widget class="QPushButton" name="loginButton">
<property name="text"> <property name="text">
<string>Verify</string> <string>Log In</string>
</property> </property>
</widget> </widget>
</item> </item>
</layout>
</item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_3"> <layout class="QHBoxLayout" name="horizontalLayout_3">
<item> <item>