mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-04-22 08:52:12 +02:00
New spotify config
This commit is contained in:
parent
b4fa46c3c7
commit
427a26e034
src/libtomahawk
accounts/spotify
resolvers
@ -543,6 +543,13 @@ SpotifyAccount::resolverMessage( const QString &msgType, const QVariantMap &msg
|
||||
creds[ "highQuality" ] = msg.value( "highQuality" );
|
||||
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" );
|
||||
|
||||
QVariantHash config = configuration();
|
||||
@ -710,7 +717,7 @@ SpotifyAccount::resolverMessage( const QString &msgType, const QVariantMap &msg
|
||||
if ( m_configWidget.data() )
|
||||
{
|
||||
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" )
|
||||
@ -769,6 +776,7 @@ SpotifyAccount::configurationWidget()
|
||||
{
|
||||
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( logout() ), this, SLOT( logout() ) );
|
||||
m_configWidget.data()->setPlaylists( m_allSpotifyPlaylists );
|
||||
}
|
||||
|
||||
@ -851,7 +859,6 @@ 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;
|
||||
@ -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
|
||||
SpotifyAccount::startPlaylistSync( SpotifyPlaylistInfo* playlist )
|
||||
{
|
||||
|
@ -122,6 +122,8 @@ private slots:
|
||||
void resolverMessage( const QString& msgType, const QVariantMap& msg );
|
||||
|
||||
void login( const QString& username, const QString& password );
|
||||
void logout();
|
||||
|
||||
// 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 );
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include <QListWidget>
|
||||
#include <QListWidgetItem>
|
||||
#include <QShowEvent>
|
||||
#include <QLabel>
|
||||
|
||||
using namespace Tomahawk;
|
||||
using namespace Accounts;
|
||||
@ -32,9 +33,11 @@ using namespace Accounts;
|
||||
SpotifyAccountConfig::SpotifyAccountConfig( SpotifyAccount *account )
|
||||
: QWidget( 0 )
|
||||
, m_ui( new Ui::SpotifyConfig )
|
||||
, m_loggedInUser( 0 )
|
||||
, m_account( account )
|
||||
, m_playlistsLoading( 0 )
|
||||
, m_loggedInManually( false )
|
||||
, m_isLoggedIn( false )
|
||||
{
|
||||
m_ui->setupUi( this );
|
||||
|
||||
@ -132,28 +135,42 @@ SpotifyAccountConfig::setPlaylists( const QList<SpotifyPlaylistInfo *>& playlist
|
||||
void
|
||||
SpotifyAccountConfig::doLogin()
|
||||
{
|
||||
m_ui->loginButton->setText( tr( "Logging in..." ) );
|
||||
m_ui->loginButton->setEnabled( false );
|
||||
if ( !m_isLoggedIn )
|
||||
{
|
||||
m_ui->loginButton->setText( tr( "Logging in..." ) );
|
||||
m_ui->loginButton->setEnabled( false );
|
||||
|
||||
m_playlistsLoading->fadeIn();
|
||||
m_loggedInManually = true;
|
||||
m_playlistsLoading->fadeIn();
|
||||
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
|
||||
SpotifyAccountConfig::loginResponse( bool success, const QString& msg )
|
||||
SpotifyAccountConfig::loginResponse( bool success, const QString& msg, const QString& username )
|
||||
{
|
||||
if ( success )
|
||||
{
|
||||
m_ui->loginButton->setText( tr( "Logged in!" ) );
|
||||
m_ui->loginButton->setEnabled( false );
|
||||
m_verifiedUsername = username;
|
||||
m_isLoggedIn = true;
|
||||
showLoggedIn();
|
||||
}
|
||||
else
|
||||
{
|
||||
setPlaylists( QList< SpotifyPlaylistInfo* >() );
|
||||
m_playlistsLoading->fadeOut();
|
||||
|
||||
m_ui->loginButton->setText( tr( "Failed: %1" ).arg( msg ) );
|
||||
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
|
||||
SpotifyAccountConfig::resetLoginButton()
|
||||
{
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include <QVariantMap>
|
||||
#include <QTimer>
|
||||
|
||||
class QLabel;
|
||||
class AnimatedSpinner;
|
||||
class QShowEvent;
|
||||
|
||||
@ -55,14 +56,13 @@ public:
|
||||
void loadFromConfig();
|
||||
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; }
|
||||
|
||||
signals:
|
||||
void login( const QString& username, const QString& pw );
|
||||
|
||||
public slots:
|
||||
// void verifyResult( const QString& msgType, const QVariantMap& msg );
|
||||
void logout();
|
||||
|
||||
protected:
|
||||
void showEvent( QShowEvent* event );
|
||||
@ -72,10 +72,15 @@ private slots:
|
||||
void resetLoginButton();
|
||||
|
||||
private:
|
||||
void showLoggedIn();
|
||||
void showLoggedOut();
|
||||
|
||||
Ui::SpotifyConfig* m_ui;
|
||||
QLabel* m_loggedInUser;
|
||||
QString m_verifiedUsername;
|
||||
SpotifyAccount* m_account;
|
||||
AnimatedSpinner* m_playlistsLoading;
|
||||
bool m_loggedInManually;
|
||||
bool m_loggedInManually, m_isLoggedIn;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -387,6 +387,7 @@ ScriptResolver::doSetup( const QVariantMap& m )
|
||||
|
||||
m_ready = true;
|
||||
m_configSent = false;
|
||||
m_num_restarts = 0;
|
||||
|
||||
if ( !m_stopped )
|
||||
Tomahawk::Pipeline::instance()->addResolver( this );
|
||||
|
Loading…
x
Reference in New Issue
Block a user