1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-13 20:39:57 +01:00

Keep config UI in sync with resolver

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

View File

@ -82,6 +82,7 @@ SpotifyAccountFactory::icon() const
SpotifyAccount::SpotifyAccount( const QString& accountId )
: CustomAtticaAccount( accountId )
, m_preventEnabling( false )
, m_loggedIn( false )
{
init();
}
@ -203,15 +204,10 @@ SpotifyAccount::hookupResolver()
connect( m_spotifyResolver.data(), SIGNAL( changed() ), this, SLOT( resolverChanged() ) );
connect( m_spotifyResolver.data(), SIGNAL( customMessage( QString,QVariantMap ) ), this, SLOT( resolverMessage( QString, QVariantMap ) ) );
const bool hasMigrated = configuration().value( "hasMigrated" ).toBool();
if ( !hasMigrated )
{
qDebug() << "Getting credentials from spotify resolver to migrate to in-app config";
QVariantMap msg;
msg[ "_msgtype" ] = "getCredentials";
m_spotifyResolver.data()->sendMessage( msg );
}
// Always get logged in status
QVariantMap msg;
msg[ "_msgtype" ] = "getCredentials";
m_spotifyResolver.data()->sendMessage( msg );
}
@ -407,8 +403,7 @@ SpotifyAccount::setManualResolverPath( const QString &resolverPath )
bool
SpotifyAccount::loggedIn() const
{
// TODO pending newconfigui branch
return enabled() && !m_spotifyResolver.isNull() && m_spotifyResolver.data()->running();
return m_loggedIn;
}
@ -543,11 +538,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 )
m_loggedIn = msg.value( "loggedIn", false ).toBool();
if ( m_loggedIn )
{
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" );
@ -710,6 +707,8 @@ SpotifyAccount::resolverMessage( const QString &msgType, const QVariantMap &msg
const bool success = msg.value( "success" ).toBool();
m_loggedIn = success;
if ( success )
createActions();
@ -730,6 +729,23 @@ SpotifyAccount::resolverMessage( const QString &msgType, const QVariantMap &msg
SpotifyPlaylistUpdater* updater = m_updaters.take( plid );
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;
}
}
@ -769,9 +785,6 @@ SpotifyAccount::icon() const
QWidget*
SpotifyAccount::configurationWidget()
{
if ( m_spotifyResolver.isNull() || !m_spotifyResolver.data()->running() )
return 0;
if ( m_configWidget.isNull() )
{
m_configWidget = QWeakPointer< SpotifyAccountConfig >( new SpotifyAccountConfig( this ) );
@ -780,6 +793,9 @@ SpotifyAccount::configurationWidget()
m_configWidget.data()->setPlaylists( m_allSpotifyPlaylists );
}
if ( m_spotifyResolver.isNull() || !m_spotifyResolver.data()->running() )
return 0;
return static_cast< QWidget* >( m_configWidget.data() );
}

View File

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

View File

@ -64,10 +64,21 @@ SpotifyAccountConfig::showEvent( QShowEvent *event )
void
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->streamingCheckbox->setChecked( m_account->credentials().value( "highQuality" ).toBool() );
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
@ -149,7 +160,7 @@ SpotifyAccountConfig::doLogin()
{
// Log out
m_isLoggedIn = false;
m_loggedInManually = false;
m_loggedInManually = true;
m_verifiedUsername.clear();
m_ui->playlistList->clear();
emit logout();
@ -163,6 +174,7 @@ SpotifyAccountConfig::loginResponse( bool success, const QString& msg, const QSt
{
if ( success )
{
qDebug() << Q_FUNC_INFO << "Login response with username:" << username;
m_verifiedUsername = username;
m_isLoggedIn = true;
showLoggedIn();
@ -193,6 +205,8 @@ SpotifyAccountConfig::showLoggedIn()
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_ui->loginButton->setText( tr( "Log Out" ) );
@ -208,7 +222,8 @@ SpotifyAccountConfig::showLoggedOut()
m_ui->usernameEdit->show();
m_ui->usernameLabel->show();
m_loggedInUser->hide();
if ( m_loggedInUser )
m_loggedInUser->hide();
m_ui->loginButton->setText( tr( "Log In" ) );
m_ui->loginButton->setEnabled( true );

View File

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

View File

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