From ee85c082e3afa8fef6679188f81ae7d8bcfb9bde Mon Sep 17 00:00:00 2001 From: Stefan Derkits Date: Sun, 27 Apr 2014 20:20:10 +0200 Subject: [PATCH 1/2] change credentials to QVariantMap instead of QVariantHash --- .../hatchet/account/HatchetAccount.cpp | 4 ++-- .../hatchet/account/HatchetAccountConfig.cpp | 2 +- src/accounts/xmpp/XmppConfigWidget.cpp | 2 +- src/accounts/xmpp/sip/XmppSip.cpp | 6 ++--- src/libtomahawk/TomahawkSettings.cpp | 8 +++---- src/libtomahawk/accounts/Account.h | 6 ++--- .../accounts/CredentialsManager.cpp | 22 +++++++------------ src/libtomahawk/accounts/CredentialsManager.h | 4 ++-- .../accounts/LocalConfigStorage.cpp | 6 ++--- .../telepathy/TelepathyConfigStorage.cpp | 2 +- .../accounts/lastfm/LastFmAccount.cpp | 6 ++--- .../accounts/spotify/SpotifyAccount.cpp | 6 ++--- src/libtomahawk/utils/SpotifyParser.cpp | 2 +- 13 files changed, 35 insertions(+), 41 deletions(-) diff --git a/src/accounts/hatchet/account/HatchetAccount.cpp b/src/accounts/hatchet/account/HatchetAccount.cpp index 2d2198d0b..1372ba3b0 100644 --- a/src/accounts/hatchet/account/HatchetAccount.cpp +++ b/src/accounts/hatchet/account/HatchetAccount.cpp @@ -406,7 +406,7 @@ HatchetAccount::onPasswordLoginFinished( QNetworkReply* reply, const QString& us return; } - QVariantHash creds = credentials(); + QVariantMap creds = credentials(); creds[ "username" ] = username; creds[ "refresh_token" ] = refreshTokenBytes; creds[ "refresh_token_expiration" ] = refreshTokenExpiration == 0 ? 0 : QDateTime::currentDateTime().toTime_t() + refreshTokenExpiration; @@ -462,7 +462,7 @@ HatchetAccount::onFetchAccessTokenFinished( QNetworkReply* reply, const QString& return; } - QVariantHash creds = credentials(); + QVariantMap creds = credentials(); if ( !originalType.isEmpty() ) { diff --git a/src/accounts/hatchet/account/HatchetAccountConfig.cpp b/src/accounts/hatchet/account/HatchetAccountConfig.cpp index 6d35320ee..f0b626762 100644 --- a/src/accounts/hatchet/account/HatchetAccountConfig.cpp +++ b/src/accounts/hatchet/account/HatchetAccountConfig.cpp @@ -92,7 +92,7 @@ HatchetAccountConfig::login() m_ui->passwordEdit->clear(); m_ui->otpEdit->clear(); - QVariantHash creds = m_account->credentials(); + QVariantMap creds = m_account->credentials(); creds.clear(); m_account->setCredentials( creds ); m_account->sync(); diff --git a/src/accounts/xmpp/XmppConfigWidget.cpp b/src/accounts/xmpp/XmppConfigWidget.cpp index 021e6289b..69a84e4a2 100644 --- a/src/accounts/xmpp/XmppConfigWidget.cpp +++ b/src/accounts/xmpp/XmppConfigWidget.cpp @@ -96,7 +96,7 @@ XmppConfigWidget::~XmppConfigWidget() void XmppConfigWidget::saveConfig() { - QVariantHash credentials = m_account->credentials(); + QVariantMap credentials = m_account->credentials(); credentials[ "username" ] = m_ui->xmppUsername->text().trimmed(); credentials[ "password" ] = m_ui->xmppPassword->text().trimmed(); diff --git a/src/accounts/xmpp/sip/XmppSip.cpp b/src/accounts/xmpp/sip/XmppSip.cpp index 8f86bc025..49ebb551b 100644 --- a/src/accounts/xmpp/sip/XmppSip.cpp +++ b/src/accounts/xmpp/sip/XmppSip.cpp @@ -599,7 +599,7 @@ XmppSipPlugin::configurationChanged() if ( !m_currentUsername.contains( '@' ) ) { m_currentUsername += defaultSuffix(); - QVariantHash credentials = m_account->credentials(); + QVariantMap credentials = m_account->credentials(); credentials[ "username" ] = m_currentUsername; m_account->setCredentials( credentials ); m_account->sync(); @@ -1103,7 +1103,7 @@ XmppSipPlugin::readXmlConsoleEnabled() QString XmppSipPlugin::readUsername() { - QVariantHash credentials = m_account->credentials(); + QVariantMap credentials = m_account->credentials(); return credentials.contains( "username" ) ? credentials[ "username" ].toString() : QString(); } @@ -1111,7 +1111,7 @@ XmppSipPlugin::readUsername() QString XmppSipPlugin::readPassword() { - QVariantHash credentials = m_account->credentials(); + QVariantMap credentials = m_account->credentials(); return credentials.contains( "password" ) ? credentials[ "password" ].toString() : QString(); } diff --git a/src/libtomahawk/TomahawkSettings.cpp b/src/libtomahawk/TomahawkSettings.cpp index e4b653c77..a91406373 100644 --- a/src/libtomahawk/TomahawkSettings.cpp +++ b/src/libtomahawk/TomahawkSettings.cpp @@ -337,7 +337,7 @@ TomahawkSettings::doUpgrade( int oldVersion, int newVersion ) if ( pluginName == "sipjabber" || pluginName == "sipgoogle" ) { - QVariantHash credentials; + QVariantMap credentials; credentials[ "username" ] = value( sipPlugin + "/username" ); credentials[ "password" ] = value( sipPlugin + "/password" ); @@ -358,7 +358,7 @@ TomahawkSettings::doUpgrade( int oldVersion, int newVersion ) value( sipPlugin + "/screenname" ).toString().isEmpty() ) continue; - QVariantHash credentials; + QVariantMap credentials; credentials[ "oauthtoken" ] = value( sipPlugin + "/oauthtoken" ); credentials[ "oauthtokensecret" ] = value( sipPlugin + "/oauthtokensecret" ); credentials[ "username" ] = value( sipPlugin + "/screenname" ); @@ -448,7 +448,7 @@ TomahawkSettings::doUpgrade( int oldVersion, int newVersion ) setValue( "enabled", hasLastFmEnabled ); setValue( "autoconnect", true ); setValue( "types", QStringList() << "ResolverType" << "StatusPushType" ); - QVariantHash credentials; + QVariantMap credentials; credentials[ "username" ] = lfmUsername; credentials[ "password" ] = lfmPassword; credentials[ "session" ] = value( "lastfm/session" ).toString(); @@ -631,7 +631,7 @@ TomahawkSettings::doUpgrade( int oldVersion, int newVersion ) { tDebug() << "beginGroup" << QString( "accounts/%1" ).arg( account ); beginGroup( QString( "accounts/%1" ).arg( account ) ); - const QVariantHash creds = value( "credentials" ).toHash(); + const QVariantMap creds = value( "credentials" ).toMap(); tDebug() << creds[ "username" ] << ( creds[ "password" ].isNull() ? ", no password" : ", has password" ); diff --git a/src/libtomahawk/accounts/Account.h b/src/libtomahawk/accounts/Account.h index 1d73644ab..b51e0fc78 100644 --- a/src/libtomahawk/accounts/Account.h +++ b/src/libtomahawk/accounts/Account.h @@ -76,7 +76,7 @@ public: QVariantHash configuration; QVariantMap acl; QStringList types; - QVariantHash credentials; + QVariantMap credentials; }; enum AuthErrorCode { AuthError, ConnectionError }; @@ -107,7 +107,7 @@ public: virtual void saveConfig() {} // called when the widget has been edited. save values from config widget, call sync() to write to disk account generic settings - QVariantHash credentials() const { QMutexLocker locker( &m_mutex ); return m_cfg.credentials; } + QVariantMap credentials() const { QMutexLocker locker( &m_mutex ); return m_cfg.credentials; } QVariantMap acl() const { QMutexLocker locker( &m_mutex ); return m_cfg.acl; } @@ -129,7 +129,7 @@ public: void setAccountFriendlyName( const QString &friendlyName ) { QMutexLocker locker( &m_mutex ); m_cfg.accountFriendlyName = friendlyName; } void setEnabled( bool enabled ) { QMutexLocker locker( &m_mutex ); m_cfg.enabled = enabled; } void setAccountId( const QString &accountId ) { QMutexLocker locker( &m_mutex ); m_accountId = accountId; } - void setCredentials( const QVariantHash &credentialHash ) { QMutexLocker locker( &m_mutex ); m_cfg.credentials = credentialHash; } + void setCredentials( const QVariantMap &credentialHash ) { QMutexLocker locker( &m_mutex ); m_cfg.credentials = credentialHash; } void setConfiguration( const QVariantHash &configuration ) { QMutexLocker locker( &m_mutex ); m_cfg.configuration = configuration; } void setAcl( const QVariantMap &acl ) { QMutexLocker locker( &m_mutex ); m_cfg.acl = acl; } diff --git a/src/libtomahawk/accounts/CredentialsManager.cpp b/src/libtomahawk/accounts/CredentialsManager.cpp index af6f02878..b4cbb9bad 100644 --- a/src/libtomahawk/accounts/CredentialsManager.cpp +++ b/src/libtomahawk/accounts/CredentialsManager.cpp @@ -95,7 +95,7 @@ CredentialsManager::loadCredentials( const QString &service ) { tDebug() << "beginGroup" << QString( "accounts/%1" ).arg( key ); TomahawkSettings::instance()->beginGroup( QString( "accounts/%1" ).arg( key ) ); - const QVariantHash creds = TomahawkSettings::instance()->value( "credentials" ).toHash(); + const QVariantMap creds = TomahawkSettings::instance()->value( "credentials" ).toMap(); tDebug() << creds[ "username" ] << ( creds[ "password" ].isNull() ? ", no password" : ", has password" ); @@ -176,7 +176,7 @@ CredentialsManager::setCredentials( const CredentialsStorageKey& csKey, const QV QKeychain::Job* j; if ( value.isNull() || - ( value.type() == QVariant::Hash && value.toHash().isEmpty() ) || + ( value.type() == QVariant::Map && value.toMap().isEmpty() ) || ( value.type() == QVariant::String && value.toString().isEmpty() ) ) { if ( !m_credentials.contains( csKey ) ) //if we don't have any credentials for this key, we bail @@ -209,16 +209,16 @@ CredentialsManager::setCredentials( const CredentialsStorageKey& csKey, const QV QKeychain::WritePasswordJob* wj = new QKeychain::WritePasswordJob( csKey.service(), this ); wj->setKey( csKey.key() ); - Q_ASSERT( value.type() == QVariant::String || value.type() == QVariant::Hash ); + Q_ASSERT( value.type() == QVariant::String || value.type() == QVariant::Map ); if ( tryToWriteAsString && value.type() == QVariant::String ) { wj->setTextData( value.toString() ); } - else if ( value.type() == QVariant::Hash ) + else if ( value.type() == QVariant::Map ) { bool ok; - QByteArray data = TomahawkUtils::toJson( value.toHash(), &ok ); + QByteArray data = TomahawkUtils::toJson( value.toMap(), &ok ); if ( ok ) { @@ -250,7 +250,7 @@ CredentialsManager::setCredentials( const CredentialsStorageKey& csKey, const QV void -CredentialsManager::setCredentials( const QString& serviceName, const QString& key, const QVariantHash& value ) +CredentialsManager::setCredentials( const QString& serviceName, const QString& key, const QVariantMap& value ) { setCredentials( CredentialsStorageKey( serviceName, key ), QVariant( value ) ); } @@ -281,15 +281,9 @@ CredentialsManager::keychainJobFinished( QKeychain::Job* j ) creds = TomahawkUtils::parseJson( readJob->textData().toLatin1(), &ok ); QVariantMap map = creds.toMap(); - QVariantHash hash; - for ( QVariantMap::const_iterator it = map.constBegin(); - it != map.constEnd(); ++it ) - { - hash.insert( it.key(), it.value() ); - } - creds = QVariant( hash ); + creds = QVariant( map ); - if ( !ok || creds.toHash().isEmpty() ) + if ( !ok || creds.toMap().isEmpty() ) { creds = QVariant( readJob->textData() ); } diff --git a/src/libtomahawk/accounts/CredentialsManager.h b/src/libtomahawk/accounts/CredentialsManager.h index 86fb2f2c9..d0abb3c8d 100644 --- a/src/libtomahawk/accounts/CredentialsManager.h +++ b/src/libtomahawk/accounts/CredentialsManager.h @@ -22,7 +22,7 @@ #include "DllMacro.h" #include -#include +#include #include #include @@ -69,7 +69,7 @@ public: QStringList services() const; QVariant credentials( const QString& serviceName, const QString& key ) const; //returns QString or QVH - void setCredentials( const QString& serviceName, const QString& key, const QVariantHash& value ); + void setCredentials( const QString& serviceName, const QString& key, const QVariantMap& value ); void setCredentials( const QString& serviceName, const QString& key, const QString& value ); signals: diff --git a/src/libtomahawk/accounts/LocalConfigStorage.cpp b/src/libtomahawk/accounts/LocalConfigStorage.cpp index ccea8375b..6eb76f36b 100644 --- a/src/libtomahawk/accounts/LocalConfigStorage.cpp +++ b/src/libtomahawk/accounts/LocalConfigStorage.cpp @@ -142,8 +142,8 @@ LocalConfigStorage::load( const QString& accountId, Account::Configuration& cfg CredentialsManager* c = AccountManager::instance()->credentialsManager(); QVariant credentials = c->credentials( s_credentialsServiceName, accountId ); - if ( credentials.type() == QVariant::Hash ) - cfg.credentials = credentials.toHash(); + if ( credentials.type() == QVariant::Map ) + cfg.credentials = credentials.toMap(); } @@ -161,7 +161,7 @@ LocalConfigStorage::remove( const QString& accountId ) s->remove( "accounts/" + accountId ); CredentialsManager* c = AccountManager::instance()->credentialsManager(); - c->setCredentials( s_credentialsServiceName, accountId, QVariantHash() ); + c->setCredentials( s_credentialsServiceName, accountId, QVariantMap() ); } } diff --git a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp index 4f2b629fe..a324703c0 100644 --- a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp +++ b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp @@ -319,7 +319,7 @@ Tomahawk::Accounts::TelepathyConfigStorage::load( const QString& accountId, Acco cfg.configuration[ "publishtracks" ] = true; Tomahawk::Accounts::CredentialsManager* c = Tomahawk::Accounts::AccountManager::instance()->credentialsManager(); - cfg.credentials = QVariantHash(); + cfg.credentials = QVariantMap(); if ( !account->parameters()[ "account" ].isNull() ) cfg.credentials[ "username" ] = account->parameters()[ "account" ].toString(); diff --git a/src/libtomahawk/accounts/lastfm/LastFmAccount.cpp b/src/libtomahawk/accounts/lastfm/LastFmAccount.cpp index a966bdd6f..5deff8d58 100644 --- a/src/libtomahawk/accounts/lastfm/LastFmAccount.cpp +++ b/src/libtomahawk/accounts/lastfm/LastFmAccount.cpp @@ -204,7 +204,7 @@ LastFmAccount::password() const void LastFmAccount::setPassword( const QString& password ) { - QVariantHash creds = credentials(); + QVariantMap creds = credentials(); creds[ "password" ] = password; setCredentials( creds ); } @@ -219,7 +219,7 @@ LastFmAccount::sessionKey() const void LastFmAccount::setSessionKey( const QString& sessionkey ) { - QVariantHash creds = credentials(); + QVariantMap creds = credentials(); creds[ "sessionkey" ] = sessionkey; setCredentials( creds ); } @@ -235,7 +235,7 @@ LastFmAccount::username() const void LastFmAccount::setUsername( const QString& username ) { - QVariantHash creds = credentials(); + QVariantMap creds = credentials(); creds[ "username" ] = username; setCredentials( creds ); } diff --git a/src/libtomahawk/accounts/spotify/SpotifyAccount.cpp b/src/libtomahawk/accounts/spotify/SpotifyAccount.cpp index f5889e99d..babf61f93 100644 --- a/src/libtomahawk/accounts/spotify/SpotifyAccount.cpp +++ b/src/libtomahawk/accounts/spotify/SpotifyAccount.cpp @@ -807,7 +807,7 @@ SpotifyAccount::resolverMessage( const QString &msgType, const QVariantMap &msg { if ( msgType == "credentials" ) { - QVariantHash creds = credentials(); + QVariantMap creds = credentials(); creds[ "username" ] = msg.value( "username" ); creds[ "password" ] = msg.value( "password" ); @@ -1043,7 +1043,7 @@ SpotifyAccount::resolverMessage( const QString &msgType, const QVariantMap &msg } else if ( msgType == "loginResponse" ) { - QVariantHash creds = credentials(); + QVariantMap creds = credentials(); creds[ "username" ] = msg.value( "username" ).toString(); creds[ "password" ] = msg.value( "password" ).toString(); creds[ "highQuality" ] = msg.value( "highQuality" ).toString(); @@ -1181,7 +1181,7 @@ SpotifyAccount::saveConfig() if ( m_configWidget.isNull() ) return; - QVariantHash creds = credentials(); + QVariantMap creds = credentials(); if ( creds.value( "username" ).toString() != m_configWidget.data()->username() || creds.value( "password" ).toString() != m_configWidget.data()->password() || creds.value( "highQuality" ).toBool() != m_configWidget.data()->highQuality() ) diff --git a/src/libtomahawk/utils/SpotifyParser.cpp b/src/libtomahawk/utils/SpotifyParser.cpp index 95fec4f0f..80a2dcbd3 100644 --- a/src/libtomahawk/utils/SpotifyParser.cpp +++ b/src/libtomahawk/utils/SpotifyParser.cpp @@ -406,7 +406,7 @@ SpotifyParser::checkBrowseFinished() if ( spotifyAccountLoggedIn ) { - QVariantHash creds = Accounts::SpotifyAccount::instance()->credentials(); + QVariantMap creds = Accounts::SpotifyAccount::instance()->credentials(); spotifyUsername = creds.value( "username" ).toString(); } From 38edecbc0a27eb6b317c3ce5873093550030fe2f Mon Sep 17 00:00:00 2001 From: Stefan Derkits Date: Sun, 27 Apr 2014 22:15:12 +0200 Subject: [PATCH 2/2] old setting based credentials werent maps, they were hashes. convert them to maps and save them --- src/libtomahawk/TomahawkSettings.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/libtomahawk/TomahawkSettings.cpp b/src/libtomahawk/TomahawkSettings.cpp index a91406373..706707347 100644 --- a/src/libtomahawk/TomahawkSettings.cpp +++ b/src/libtomahawk/TomahawkSettings.cpp @@ -337,7 +337,7 @@ TomahawkSettings::doUpgrade( int oldVersion, int newVersion ) if ( pluginName == "sipjabber" || pluginName == "sipgoogle" ) { - QVariantMap credentials; + QVariantHash credentials; credentials[ "username" ] = value( sipPlugin + "/username" ); credentials[ "password" ] = value( sipPlugin + "/password" ); @@ -631,10 +631,16 @@ TomahawkSettings::doUpgrade( int oldVersion, int newVersion ) { tDebug() << "beginGroup" << QString( "accounts/%1" ).arg( account ); beginGroup( QString( "accounts/%1" ).arg( account ) ); - const QVariantMap creds = value( "credentials" ).toMap(); - tDebug() << creds[ "username" ] - << ( creds[ "password" ].isNull() ? ", no password" : ", has password" ); + const QVariantHash hash = value( "credentials" ).toHash(); + tDebug() << hash[ "username" ] + << ( hash[ "password" ].isNull() ? ", no password" : ", has password" ); + QVariantMap creds; + for ( QVariantHash::const_iterator it = hash.constBegin(); it != hash.constEnd(); ++it ) + { + creds.insert( it.key(), it.value() ); + + } if ( !creds.isEmpty() ) { QKeychain::WritePasswordJob* j = new QKeychain::WritePasswordJob( QLatin1String( "Tomahawk" ), this );