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

Keep config UI in sync with resolver

This commit is contained in:
Leo Franchi
2012-07-05 23:33:28 -04:00
parent aa0f99bcce
commit 64d9a0f5d2
5 changed files with 52 additions and 37 deletions

View File

@@ -82,6 +82,7 @@ SpotifyAccountFactory::icon() const
SpotifyAccount::SpotifyAccount( const QString& accountId ) SpotifyAccount::SpotifyAccount( const QString& accountId )
: CustomAtticaAccount( accountId ) : CustomAtticaAccount( accountId )
, m_preventEnabling( false ) , m_preventEnabling( false )
, m_loggedIn( false )
{ {
init(); init();
} }
@@ -203,15 +204,10 @@ SpotifyAccount::hookupResolver()
connect( m_spotifyResolver.data(), SIGNAL( changed() ), this, SLOT( resolverChanged() ) ); connect( m_spotifyResolver.data(), SIGNAL( changed() ), this, SLOT( resolverChanged() ) );
connect( m_spotifyResolver.data(), SIGNAL( customMessage( QString,QVariantMap ) ), this, SLOT( resolverMessage( QString, QVariantMap ) ) ); connect( m_spotifyResolver.data(), SIGNAL( customMessage( QString,QVariantMap ) ), this, SLOT( resolverMessage( QString, QVariantMap ) ) );
const bool hasMigrated = configuration().value( "hasMigrated" ).toBool(); // Always get logged in status
if ( !hasMigrated ) QVariantMap msg;
{ msg[ "_msgtype" ] = "getCredentials";
qDebug() << "Getting credentials from spotify resolver to migrate to in-app config"; m_spotifyResolver.data()->sendMessage( msg );
QVariantMap msg;
msg[ "_msgtype" ] = "getCredentials";
m_spotifyResolver.data()->sendMessage( msg );
}
} }
@@ -407,8 +403,7 @@ SpotifyAccount::setManualResolverPath( const QString &resolverPath )
bool bool
SpotifyAccount::loggedIn() const SpotifyAccount::loggedIn() const
{ {
// TODO pending newconfigui branch return m_loggedIn;
return enabled() && !m_spotifyResolver.isNull() && m_spotifyResolver.data()->running();
} }
@@ -543,11 +538,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(); m_loggedIn = msg.value( "loggedIn", false ).toBool();
if ( loggedIn ) if ( m_loggedIn )
{ {
configurationWidget(); configurationWidget();
m_configWidget.data()->loginResponse( true, QString(), creds[ "username" ].toString() );
if ( !m_configWidget.isNull() )
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" );
@@ -714,6 +711,8 @@ SpotifyAccount::resolverMessage( const QString &msgType, const QVariantMap &msg
const bool success = msg.value( "success" ).toBool(); const bool success = msg.value( "success" ).toBool();
m_loggedIn = success;
if ( success ) if ( success )
createActions(); createActions();
@@ -734,6 +733,23 @@ SpotifyAccount::resolverMessage( const QString &msgType, const QVariantMap &msg
SpotifyPlaylistUpdater* updater = m_updaters.take( plid ); SpotifyPlaylistUpdater* updater = m_updaters.take( plid );
updater->remove( false ); updater->remove( false );
} }
else if ( msgType == "status" )
{
const bool loggedIn = msg.value( "loggedIn" ).toBool();
const QString username = msg.value( "username" ).toString();
qDebug() << "Got status message with login info:" << loggedIn << username;
if ( !loggedIn || username.isEmpty() || credentials().value( "username").toString() != username )
m_loggedIn = false;
QVariantMap msg;
msg[ "_msgtype" ] = "status";
msg[ "_status" ] = 1;
sendMessage( msg );
return;
}
} }
@@ -773,9 +789,6 @@ SpotifyAccount::icon() const
QWidget* QWidget*
SpotifyAccount::configurationWidget() SpotifyAccount::configurationWidget()
{ {
if ( m_spotifyResolver.isNull() || !m_spotifyResolver.data()->running() )
return 0;
if ( m_configWidget.isNull() ) if ( m_configWidget.isNull() )
{ {
m_configWidget = QWeakPointer< SpotifyAccountConfig >( new SpotifyAccountConfig( this ) ); m_configWidget = QWeakPointer< SpotifyAccountConfig >( new SpotifyAccountConfig( this ) );
@@ -784,6 +797,9 @@ SpotifyAccount::configurationWidget()
m_configWidget.data()->setPlaylists( m_allSpotifyPlaylists ); m_configWidget.data()->setPlaylists( m_allSpotifyPlaylists );
} }
if ( m_spotifyResolver.isNull() || !m_spotifyResolver.data()->running() )
return 0;
return static_cast< QWidget* >( m_configWidget.data() ); return static_cast< QWidget* >( m_configWidget.data() );
} }

View File

@@ -165,7 +165,7 @@ private:
QHash< QString, playlist_ptr > m_waitingForCreateReply; QHash< QString, playlist_ptr > m_waitingForCreateReply;
bool m_preventEnabling; bool m_preventEnabling, m_loggedIn;
SmartPointerList< QAction > m_customActions; SmartPointerList< QAction > m_customActions;
friend class ::SpotifyPlaylistUpdater; friend class ::SpotifyPlaylistUpdater;

View File

@@ -66,10 +66,21 @@ SpotifyAccountConfig::showEvent( QShowEvent *event )
void void
SpotifyAccountConfig::loadFromConfig() SpotifyAccountConfig::loadFromConfig()
{ {
m_ui->usernameEdit->setText( m_account->credentials().value( "username" ).toString() ); const QString username = m_account->credentials().value( "username" ).toString();
m_ui->usernameEdit->setText( username );
m_ui->passwordEdit->setText( m_account->credentials().value( "password" ).toString() ); m_ui->passwordEdit->setText( m_account->credentials().value( "password" ).toString() );
m_ui->streamingCheckbox->setChecked( m_account->credentials().value( "highQuality" ).toBool() ); m_ui->streamingCheckbox->setChecked( m_account->credentials().value( "highQuality" ).toBool() );
m_ui->deleteOnUnsync->setChecked( m_account->deleteOnUnsync() ); m_ui->deleteOnUnsync->setChecked( m_account->deleteOnUnsync() );
if ( m_account->loggedIn() )
{
qDebug() << "Loading spotify config widget with logged in username:" << username;
if ( !username.isEmpty() )
m_verifiedUsername = username;
showLoggedIn();
}
else
showLoggedOut();
} }
void void
@@ -151,7 +162,7 @@ SpotifyAccountConfig::doLogin()
{ {
// Log out // Log out
m_isLoggedIn = false; m_isLoggedIn = false;
m_loggedInManually = false; m_loggedInManually = true;
m_verifiedUsername.clear(); m_verifiedUsername.clear();
m_ui->playlistList->clear(); m_ui->playlistList->clear();
emit logout(); emit logout();
@@ -165,6 +176,7 @@ SpotifyAccountConfig::loginResponse( bool success, const QString& msg, const QSt
{ {
if ( success ) if ( success )
{ {
qDebug() << Q_FUNC_INFO << "Login response with username:" << username;
m_verifiedUsername = username; m_verifiedUsername = username;
m_isLoggedIn = true; m_isLoggedIn = true;
showLoggedIn(); showLoggedIn();
@@ -195,6 +207,8 @@ SpotifyAccountConfig::showLoggedIn()
m_ui->verticalLayout->insertWidget( 1, m_loggedInUser, 0, Qt::AlignCenter ); m_ui->verticalLayout->insertWidget( 1, m_loggedInUser, 0, Qt::AlignCenter );
} }
qDebug() << "Showing logged in withuserame:" << m_verifiedUsername;
m_loggedInUser->show();
m_loggedInUser->setText( tr( "Logged in as %1" ).arg( m_verifiedUsername ) ); m_loggedInUser->setText( tr( "Logged in as %1" ).arg( m_verifiedUsername ) );
m_ui->loginButton->setText( tr( "Log Out" ) ); m_ui->loginButton->setText( tr( "Log Out" ) );
@@ -210,7 +224,8 @@ SpotifyAccountConfig::showLoggedOut()
m_ui->usernameEdit->show(); m_ui->usernameEdit->show();
m_ui->usernameLabel->show(); m_ui->usernameLabel->show();
m_loggedInUser->hide(); if ( m_loggedInUser )
m_loggedInUser->hide();
m_ui->loginButton->setText( tr( "Log In" ) ); m_ui->loginButton->setText( tr( "Log In" ) );
m_ui->loginButton->setEnabled( true ); m_ui->loginButton->setEnabled( true );

View File

@@ -255,11 +255,6 @@ ScriptResolver::handleMsg( const QByteArray& msg )
setupConfWidget( m ); setupConfWidget( m );
return; return;
} }
else if ( msgtype == "status" )
{
sendStatus();
return;
}
else if ( msgtype == "results" ) else if ( msgtype == "results" )
{ {
const QString qid = m.value( "qid" ).toString(); const QString qid = m.value( "qid" ).toString();
@@ -367,16 +362,6 @@ ScriptResolver::resolve( const Tomahawk::query_ptr& query )
} }
void
ScriptResolver::sendStatus()
{
QVariantMap msg;
msg[ "_msgtype" ] = "status";
msg[ "_status" ] = 1;
sendMessage( msg );
}
void void
ScriptResolver::doSetup( const QVariantMap& m ) ScriptResolver::doSetup( const QVariantMap& m )
{ {

View File

@@ -77,7 +77,6 @@ private:
void sendMsg( const QByteArray& msg ); void sendMsg( const QByteArray& msg );
void doSetup( const QVariantMap& m ); void doSetup( const QVariantMap& m );
void setupConfWidget( const QVariantMap& m ); void setupConfWidget( const QVariantMap& m );
void sendStatus();
void startProcess(); void startProcess();