1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-06 14:16:32 +02:00

New spotify config

This commit is contained in:
Leo Franchi
2012-07-02 12:07:33 -04:00
parent b4fa46c3c7
commit 427a26e034
5 changed files with 92 additions and 15 deletions

View File

@@ -543,6 +543,13 @@ SpotifyAccount::resolverMessage( const QString &msgType, const QVariantMap &msg
creds[ "highQuality" ] = msg.value( "highQuality" ); creds[ "highQuality" ] = msg.value( "highQuality" );
setCredentials( creds ); setCredentials( creds );
const bool loggedIn = msg.value( "loggedIn", false ).toBool();
if ( loggedIn )
{
configurationWidget();
m_configWidget.data()->loginResponse( true, QString(), creds[ "username" ].toString() );
}
qDebug() << "Set creds:" << creds.value( "username" ) << creds.value( "password" ) << msg.value( "username" ) << msg.value( "password" ); qDebug() << "Set creds:" << creds.value( "username" ) << creds.value( "password" ) << msg.value( "username" ) << msg.value( "password" );
QVariantHash config = configuration(); QVariantHash config = configuration();
@@ -710,7 +717,7 @@ SpotifyAccount::resolverMessage( const QString &msgType, const QVariantMap &msg
if ( m_configWidget.data() ) if ( m_configWidget.data() )
{ {
const QString message = msg.value( "message" ).toString(); const QString message = msg.value( "message" ).toString();
m_configWidget.data()->loginResponse( success, message ); m_configWidget.data()->loginResponse( success, message, creds[ "username" ].toString() );
} }
} }
else if ( msgType == "playlistDeleted" ) else if ( msgType == "playlistDeleted" )
@@ -769,6 +776,7 @@ SpotifyAccount::configurationWidget()
{ {
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 ) ) ); connect( m_configWidget.data(), SIGNAL( login( QString,QString ) ), this, SLOT( login( QString,QString ) ) );
connect( m_configWidget.data(), SIGNAL( logout() ), this, SLOT( logout() ) );
m_configWidget.data()->setPlaylists( m_allSpotifyPlaylists ); m_configWidget.data()->setPlaylists( m_allSpotifyPlaylists );
} }
@@ -851,7 +859,6 @@ SpotifyAccount::saveConfig()
void void
SpotifyAccount::login( const QString& username, const QString& password ) SpotifyAccount::login( const QString& username, const QString& password )
{ {
// Send the result to the resolver
QVariantMap msg; QVariantMap msg;
msg[ "_msgtype" ] = "login"; msg[ "_msgtype" ] = "login";
msg[ "username" ] = username; msg[ "username" ] = username;
@@ -863,6 +870,15 @@ SpotifyAccount::login( const QString& username, const QString& password )
} }
void
SpotifyAccount::logout()
{
QVariantMap msg;
msg[ "_msgtype" ] = "logout";
m_spotifyResolver.data()->sendMessage( msg );
}
void void
SpotifyAccount::startPlaylistSync( SpotifyPlaylistInfo* playlist ) SpotifyAccount::startPlaylistSync( SpotifyPlaylistInfo* playlist )
{ {

View File

@@ -122,6 +122,8 @@ 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 ); void login( const QString& username, const QString& password );
void logout();
// 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 );

View File

@@ -25,6 +25,7 @@
#include <QListWidget> #include <QListWidget>
#include <QListWidgetItem> #include <QListWidgetItem>
#include <QShowEvent> #include <QShowEvent>
#include <QLabel>
using namespace Tomahawk; using namespace Tomahawk;
using namespace Accounts; using namespace Accounts;
@@ -32,9 +33,11 @@ using namespace Accounts;
SpotifyAccountConfig::SpotifyAccountConfig( SpotifyAccount *account ) SpotifyAccountConfig::SpotifyAccountConfig( SpotifyAccount *account )
: QWidget( 0 ) : QWidget( 0 )
, m_ui( new Ui::SpotifyConfig ) , m_ui( new Ui::SpotifyConfig )
, m_loggedInUser( 0 )
, m_account( account ) , m_account( account )
, m_playlistsLoading( 0 ) , m_playlistsLoading( 0 )
, m_loggedInManually( false ) , m_loggedInManually( false )
, m_isLoggedIn( false )
{ {
m_ui->setupUi( this ); m_ui->setupUi( this );
@@ -132,28 +135,42 @@ SpotifyAccountConfig::setPlaylists( const QList<SpotifyPlaylistInfo *>& playlist
void void
SpotifyAccountConfig::doLogin() SpotifyAccountConfig::doLogin()
{ {
m_ui->loginButton->setText( tr( "Logging in..." ) ); if ( !m_isLoggedIn )
m_ui->loginButton->setEnabled( false ); {
m_ui->loginButton->setText( tr( "Logging in..." ) );
m_ui->loginButton->setEnabled( false );
m_playlistsLoading->fadeIn(); m_playlistsLoading->fadeIn();
m_loggedInManually = true; m_loggedInManually = true;
emit login( username(), password() ); emit login( username(), password() );
}
else
{
// Log out
m_isLoggedIn = false;
m_loggedInManually = false;
m_verifiedUsername.clear();
emit logout();
showLoggedOut();
}
} }
void void
SpotifyAccountConfig::loginResponse( bool success, const QString& msg ) SpotifyAccountConfig::loginResponse( bool success, const QString& msg, const QString& username )
{ {
if ( success ) if ( success )
{ {
m_ui->loginButton->setText( tr( "Logged in!" ) ); m_verifiedUsername = username;
m_ui->loginButton->setEnabled( false ); m_isLoggedIn = true;
showLoggedIn();
} }
else else
{ {
setPlaylists( QList< SpotifyPlaylistInfo* >() ); setPlaylists( QList< SpotifyPlaylistInfo* >() );
m_playlistsLoading->fadeOut(); m_playlistsLoading->fadeOut();
m_ui->loginButton->setText( tr( "Failed: %1" ).arg( msg ) ); m_ui->loginButton->setText( tr( "Failed: %1" ).arg( msg ) );
m_ui->loginButton->setEnabled( true ); m_ui->loginButton->setEnabled( true );
} }
@@ -161,6 +178,42 @@ SpotifyAccountConfig::loginResponse( bool success, const QString& msg )
} }
void
SpotifyAccountConfig::showLoggedIn()
{
m_ui->passwordEdit->hide();
m_ui->passwordLabel->hide();
m_ui->usernameEdit->hide();
m_ui->usernameLabel->hide();
if ( !m_loggedInUser )
{
m_loggedInUser = new QLabel( this );
m_ui->verticalLayout->insertWidget( 1, m_loggedInUser, 0, Qt::AlignCenter );
}
m_loggedInUser->setText( tr( "Logged in as %1" ).arg( m_verifiedUsername ) );
m_ui->loginButton->setText( tr( "Log Out" ) );
m_ui->loginButton->setEnabled( true );
}
void
SpotifyAccountConfig::showLoggedOut()
{
m_ui->passwordEdit->show();
m_ui->passwordLabel->show();
m_ui->usernameEdit->show();
m_ui->usernameLabel->show();
m_loggedInUser->hide();
m_ui->loginButton->setText( tr( "Log In" ) );
m_ui->loginButton->setEnabled( true );
}
void void
SpotifyAccountConfig::resetLoginButton() SpotifyAccountConfig::resetLoginButton()
{ {

View File

@@ -23,6 +23,7 @@
#include <QVariantMap> #include <QVariantMap>
#include <QTimer> #include <QTimer>
class QLabel;
class AnimatedSpinner; class AnimatedSpinner;
class QShowEvent; class QShowEvent;
@@ -55,14 +56,13 @@ public:
void loadFromConfig(); void loadFromConfig();
void saveSettings(); void saveSettings();
void loginResponse( bool success, const QString& msg ); void loginResponse( bool success, const QString& msg, const QString& username );
bool loggedInManually() const { return m_loggedInManually; } bool loggedInManually() const { return m_loggedInManually; }
signals: signals:
void login( const QString& username, const QString& pw ); void login( const QString& username, const QString& pw );
void logout();
public slots:
// void verifyResult( const QString& msgType, const QVariantMap& msg );
protected: protected:
void showEvent( QShowEvent* event ); void showEvent( QShowEvent* event );
@@ -72,10 +72,15 @@ private slots:
void resetLoginButton(); void resetLoginButton();
private: private:
void showLoggedIn();
void showLoggedOut();
Ui::SpotifyConfig* m_ui; Ui::SpotifyConfig* m_ui;
QLabel* m_loggedInUser;
QString m_verifiedUsername;
SpotifyAccount* m_account; SpotifyAccount* m_account;
AnimatedSpinner* m_playlistsLoading; AnimatedSpinner* m_playlistsLoading;
bool m_loggedInManually; bool m_loggedInManually, m_isLoggedIn;
}; };
} }

View File

@@ -387,6 +387,7 @@ ScriptResolver::doSetup( const QVariantMap& m )
m_ready = true; m_ready = true;
m_configSent = false; m_configSent = false;
m_num_restarts = 0;
if ( !m_stopped ) if ( !m_stopped )
Tomahawk::Pipeline::instance()->addResolver( this ); Tomahawk::Pipeline::instance()->addResolver( this );