mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-21 13:21:52 +02:00
Rework spotify UI a bit for greater clarity
This commit is contained in:
@@ -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 )
|
||||
{
|
||||
|
@@ -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 <here>( 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 );
|
||||
|
@@ -19,6 +19,7 @@
|
||||
#include "SpotifyAccountConfig.h"
|
||||
|
||||
#include "SpotifyAccount.h"
|
||||
#include <playlist/dynamic/widgets/LoadingSpinner.h>
|
||||
#include "ui_SpotifyAccountConfig.h"
|
||||
|
||||
#include <QListWidget>
|
||||
@@ -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<SpotifyPlaylistInfo *>& 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<SpotifyPlaylistInfo *>& 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 );
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
@@ -23,6 +23,7 @@
|
||||
#include <QVariantMap>
|
||||
#include <QTimer>
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
}
|
||||
|
@@ -109,15 +109,15 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="verifyCreds">
|
||||
<property name="text">
|
||||
<string>Verify</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="loginButton">
|
||||
<property name="text">
|
||||
<string>Log In</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
|
Reference in New Issue
Block a user