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

Merge pull request #230 from tomahawk-player/qvariantmap_for_qt5

change credentials to QVariantMap instead of QVariantHash
This commit is contained in:
Uwe L. Korn
2014-04-29 06:31:58 +02:00
13 changed files with 42 additions and 42 deletions

View File

@@ -406,7 +406,7 @@ HatchetAccount::onPasswordLoginFinished( QNetworkReply* reply, const QString& us
return; return;
} }
QVariantHash creds = credentials(); QVariantMap creds = credentials();
creds[ "username" ] = username; creds[ "username" ] = username;
creds[ "refresh_token" ] = refreshTokenBytes; creds[ "refresh_token" ] = refreshTokenBytes;
creds[ "refresh_token_expiration" ] = refreshTokenExpiration == 0 ? 0 : QDateTime::currentDateTime().toTime_t() + refreshTokenExpiration; creds[ "refresh_token_expiration" ] = refreshTokenExpiration == 0 ? 0 : QDateTime::currentDateTime().toTime_t() + refreshTokenExpiration;
@@ -462,7 +462,7 @@ HatchetAccount::onFetchAccessTokenFinished( QNetworkReply* reply, const QString&
return; return;
} }
QVariantHash creds = credentials(); QVariantMap creds = credentials();
if ( !originalType.isEmpty() ) if ( !originalType.isEmpty() )
{ {

View File

@@ -92,7 +92,7 @@ HatchetAccountConfig::login()
m_ui->passwordEdit->clear(); m_ui->passwordEdit->clear();
m_ui->otpEdit->clear(); m_ui->otpEdit->clear();
QVariantHash creds = m_account->credentials(); QVariantMap creds = m_account->credentials();
creds.clear(); creds.clear();
m_account->setCredentials( creds ); m_account->setCredentials( creds );
m_account->sync(); m_account->sync();

View File

@@ -96,7 +96,7 @@ XmppConfigWidget::~XmppConfigWidget()
void void
XmppConfigWidget::saveConfig() XmppConfigWidget::saveConfig()
{ {
QVariantHash credentials = m_account->credentials(); QVariantMap credentials = m_account->credentials();
credentials[ "username" ] = m_ui->xmppUsername->text().trimmed(); credentials[ "username" ] = m_ui->xmppUsername->text().trimmed();
credentials[ "password" ] = m_ui->xmppPassword->text().trimmed(); credentials[ "password" ] = m_ui->xmppPassword->text().trimmed();

View File

@@ -599,7 +599,7 @@ XmppSipPlugin::configurationChanged()
if ( !m_currentUsername.contains( '@' ) ) if ( !m_currentUsername.contains( '@' ) )
{ {
m_currentUsername += defaultSuffix(); m_currentUsername += defaultSuffix();
QVariantHash credentials = m_account->credentials(); QVariantMap credentials = m_account->credentials();
credentials[ "username" ] = m_currentUsername; credentials[ "username" ] = m_currentUsername;
m_account->setCredentials( credentials ); m_account->setCredentials( credentials );
m_account->sync(); m_account->sync();
@@ -1103,7 +1103,7 @@ XmppSipPlugin::readXmlConsoleEnabled()
QString QString
XmppSipPlugin::readUsername() XmppSipPlugin::readUsername()
{ {
QVariantHash credentials = m_account->credentials(); QVariantMap credentials = m_account->credentials();
return credentials.contains( "username" ) ? credentials[ "username" ].toString() : QString(); return credentials.contains( "username" ) ? credentials[ "username" ].toString() : QString();
} }
@@ -1111,7 +1111,7 @@ XmppSipPlugin::readUsername()
QString QString
XmppSipPlugin::readPassword() XmppSipPlugin::readPassword()
{ {
QVariantHash credentials = m_account->credentials(); QVariantMap credentials = m_account->credentials();
return credentials.contains( "password" ) ? credentials[ "password" ].toString() : QString(); return credentials.contains( "password" ) ? credentials[ "password" ].toString() : QString();
} }

View File

@@ -358,7 +358,7 @@ TomahawkSettings::doUpgrade( int oldVersion, int newVersion )
value( sipPlugin + "/screenname" ).toString().isEmpty() ) value( sipPlugin + "/screenname" ).toString().isEmpty() )
continue; continue;
QVariantHash credentials; QVariantMap credentials;
credentials[ "oauthtoken" ] = value( sipPlugin + "/oauthtoken" ); credentials[ "oauthtoken" ] = value( sipPlugin + "/oauthtoken" );
credentials[ "oauthtokensecret" ] = value( sipPlugin + "/oauthtokensecret" ); credentials[ "oauthtokensecret" ] = value( sipPlugin + "/oauthtokensecret" );
credentials[ "username" ] = value( sipPlugin + "/screenname" ); credentials[ "username" ] = value( sipPlugin + "/screenname" );
@@ -448,7 +448,7 @@ TomahawkSettings::doUpgrade( int oldVersion, int newVersion )
setValue( "enabled", hasLastFmEnabled ); setValue( "enabled", hasLastFmEnabled );
setValue( "autoconnect", true ); setValue( "autoconnect", true );
setValue( "types", QStringList() << "ResolverType" << "StatusPushType" ); setValue( "types", QStringList() << "ResolverType" << "StatusPushType" );
QVariantHash credentials; QVariantMap credentials;
credentials[ "username" ] = lfmUsername; credentials[ "username" ] = lfmUsername;
credentials[ "password" ] = lfmPassword; credentials[ "password" ] = lfmPassword;
credentials[ "session" ] = value( "lastfm/session" ).toString(); credentials[ "session" ] = value( "lastfm/session" ).toString();
@@ -631,10 +631,16 @@ TomahawkSettings::doUpgrade( int oldVersion, int newVersion )
{ {
tDebug() << "beginGroup" << QString( "accounts/%1" ).arg( account ); tDebug() << "beginGroup" << QString( "accounts/%1" ).arg( account );
beginGroup( QString( "accounts/%1" ).arg( account ) ); beginGroup( QString( "accounts/%1" ).arg( account ) );
const QVariantHash creds = value( "credentials" ).toHash(); const QVariantHash hash = value( "credentials" ).toHash();
tDebug() << creds[ "username" ] tDebug() << hash[ "username" ]
<< ( creds[ "password" ].isNull() ? ", no password" : ", has password" ); << ( 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() ) if ( !creds.isEmpty() )
{ {
QKeychain::WritePasswordJob* j = new QKeychain::WritePasswordJob( QLatin1String( "Tomahawk" ), this ); QKeychain::WritePasswordJob* j = new QKeychain::WritePasswordJob( QLatin1String( "Tomahawk" ), this );

View File

@@ -76,7 +76,7 @@ public:
QVariantHash configuration; QVariantHash configuration;
QVariantMap acl; QVariantMap acl;
QStringList types; QStringList types;
QVariantHash credentials; QVariantMap credentials;
}; };
enum AuthErrorCode { AuthError, ConnectionError }; 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 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; } 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 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 setEnabled( bool enabled ) { QMutexLocker locker( &m_mutex ); m_cfg.enabled = enabled; }
void setAccountId( const QString &accountId ) { QMutexLocker locker( &m_mutex ); m_accountId = accountId; } 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 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; } void setAcl( const QVariantMap &acl ) { QMutexLocker locker( &m_mutex ); m_cfg.acl = acl; }

View File

@@ -95,7 +95,7 @@ CredentialsManager::loadCredentials( const QString &service )
{ {
tDebug() << "beginGroup" << QString( "accounts/%1" ).arg( key ); tDebug() << "beginGroup" << QString( "accounts/%1" ).arg( key );
TomahawkSettings::instance()->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" ] tDebug() << creds[ "username" ]
<< ( creds[ "password" ].isNull() ? ", no password" : ", has password" ); << ( creds[ "password" ].isNull() ? ", no password" : ", has password" );
@@ -176,7 +176,7 @@ CredentialsManager::setCredentials( const CredentialsStorageKey& csKey, const QV
QKeychain::Job* j; QKeychain::Job* j;
if ( value.isNull() || if ( value.isNull() ||
( value.type() == QVariant::Hash && value.toHash().isEmpty() ) || ( value.type() == QVariant::Map && value.toMap().isEmpty() ) ||
( value.type() == QVariant::String && value.toString().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 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 ); QKeychain::WritePasswordJob* wj = new QKeychain::WritePasswordJob( csKey.service(), this );
wj->setKey( csKey.key() ); 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 ) if ( tryToWriteAsString && value.type() == QVariant::String )
{ {
wj->setTextData( value.toString() ); wj->setTextData( value.toString() );
} }
else if ( value.type() == QVariant::Hash ) else if ( value.type() == QVariant::Map )
{ {
bool ok; bool ok;
QByteArray data = TomahawkUtils::toJson( value.toHash(), &ok ); QByteArray data = TomahawkUtils::toJson( value.toMap(), &ok );
if ( ok ) if ( ok )
{ {
@@ -250,7 +250,7 @@ CredentialsManager::setCredentials( const CredentialsStorageKey& csKey, const QV
void 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 ) ); setCredentials( CredentialsStorageKey( serviceName, key ), QVariant( value ) );
} }
@@ -281,15 +281,9 @@ CredentialsManager::keychainJobFinished( QKeychain::Job* j )
creds = TomahawkUtils::parseJson( readJob->textData().toLatin1(), &ok ); creds = TomahawkUtils::parseJson( readJob->textData().toLatin1(), &ok );
QVariantMap map = creds.toMap(); QVariantMap map = creds.toMap();
QVariantHash hash; creds = QVariant( map );
for ( QVariantMap::const_iterator it = map.constBegin();
it != map.constEnd(); ++it )
{
hash.insert( it.key(), it.value() );
}
creds = QVariant( hash );
if ( !ok || creds.toHash().isEmpty() ) if ( !ok || creds.toMap().isEmpty() )
{ {
creds = QVariant( readJob->textData() ); creds = QVariant( readJob->textData() );
} }

View File

@@ -22,7 +22,7 @@
#include "DllMacro.h" #include "DllMacro.h"
#include <QObject> #include <QObject>
#include <QVariantHash> #include <QVariantMap>
#include <QMutex> #include <QMutex>
#include <QStringList> #include <QStringList>
@@ -69,7 +69,7 @@ public:
QStringList services() const; QStringList services() const;
QVariant credentials( const QString& serviceName, const QString& key ) const; //returns QString or QVH 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 ); void setCredentials( const QString& serviceName, const QString& key, const QString& value );
signals: signals:

View File

@@ -142,8 +142,8 @@ LocalConfigStorage::load( const QString& accountId, Account::Configuration& cfg
CredentialsManager* c = AccountManager::instance()->credentialsManager(); CredentialsManager* c = AccountManager::instance()->credentialsManager();
QVariant credentials = c->credentials( s_credentialsServiceName, accountId ); QVariant credentials = c->credentials( s_credentialsServiceName, accountId );
if ( credentials.type() == QVariant::Hash ) if ( credentials.type() == QVariant::Map )
cfg.credentials = credentials.toHash(); cfg.credentials = credentials.toMap();
} }
@@ -161,7 +161,7 @@ LocalConfigStorage::remove( const QString& accountId )
s->remove( "accounts/" + accountId ); s->remove( "accounts/" + accountId );
CredentialsManager* c = AccountManager::instance()->credentialsManager(); CredentialsManager* c = AccountManager::instance()->credentialsManager();
c->setCredentials( s_credentialsServiceName, accountId, QVariantHash() ); c->setCredentials( s_credentialsServiceName, accountId, QVariantMap() );
} }
} }

View File

@@ -319,7 +319,7 @@ Tomahawk::Accounts::TelepathyConfigStorage::load( const QString& accountId, Acco
cfg.configuration[ "publishtracks" ] = true; cfg.configuration[ "publishtracks" ] = true;
Tomahawk::Accounts::CredentialsManager* c = Tomahawk::Accounts::AccountManager::instance()->credentialsManager(); Tomahawk::Accounts::CredentialsManager* c = Tomahawk::Accounts::AccountManager::instance()->credentialsManager();
cfg.credentials = QVariantHash(); cfg.credentials = QVariantMap();
if ( !account->parameters()[ "account" ].isNull() ) if ( !account->parameters()[ "account" ].isNull() )
cfg.credentials[ "username" ] = account->parameters()[ "account" ].toString(); cfg.credentials[ "username" ] = account->parameters()[ "account" ].toString();

View File

@@ -204,7 +204,7 @@ LastFmAccount::password() const
void void
LastFmAccount::setPassword( const QString& password ) LastFmAccount::setPassword( const QString& password )
{ {
QVariantHash creds = credentials(); QVariantMap creds = credentials();
creds[ "password" ] = password; creds[ "password" ] = password;
setCredentials( creds ); setCredentials( creds );
} }
@@ -219,7 +219,7 @@ LastFmAccount::sessionKey() const
void void
LastFmAccount::setSessionKey( const QString& sessionkey ) LastFmAccount::setSessionKey( const QString& sessionkey )
{ {
QVariantHash creds = credentials(); QVariantMap creds = credentials();
creds[ "sessionkey" ] = sessionkey; creds[ "sessionkey" ] = sessionkey;
setCredentials( creds ); setCredentials( creds );
} }
@@ -235,7 +235,7 @@ LastFmAccount::username() const
void void
LastFmAccount::setUsername( const QString& username ) LastFmAccount::setUsername( const QString& username )
{ {
QVariantHash creds = credentials(); QVariantMap creds = credentials();
creds[ "username" ] = username; creds[ "username" ] = username;
setCredentials( creds ); setCredentials( creds );
} }

View File

@@ -807,7 +807,7 @@ SpotifyAccount::resolverMessage( const QString &msgType, const QVariantMap &msg
{ {
if ( msgType == "credentials" ) if ( msgType == "credentials" )
{ {
QVariantHash creds = credentials(); QVariantMap creds = credentials();
creds[ "username" ] = msg.value( "username" ); creds[ "username" ] = msg.value( "username" );
creds[ "password" ] = msg.value( "password" ); creds[ "password" ] = msg.value( "password" );
@@ -1043,7 +1043,7 @@ SpotifyAccount::resolverMessage( const QString &msgType, const QVariantMap &msg
} }
else if ( msgType == "loginResponse" ) else if ( msgType == "loginResponse" )
{ {
QVariantHash creds = credentials(); QVariantMap creds = credentials();
creds[ "username" ] = msg.value( "username" ).toString(); creds[ "username" ] = msg.value( "username" ).toString();
creds[ "password" ] = msg.value( "password" ).toString(); creds[ "password" ] = msg.value( "password" ).toString();
creds[ "highQuality" ] = msg.value( "highQuality" ).toString(); creds[ "highQuality" ] = msg.value( "highQuality" ).toString();
@@ -1181,7 +1181,7 @@ SpotifyAccount::saveConfig()
if ( m_configWidget.isNull() ) if ( m_configWidget.isNull() )
return; return;
QVariantHash creds = credentials(); QVariantMap creds = credentials();
if ( creds.value( "username" ).toString() != m_configWidget.data()->username() || if ( creds.value( "username" ).toString() != m_configWidget.data()->username() ||
creds.value( "password" ).toString() != m_configWidget.data()->password() || creds.value( "password" ).toString() != m_configWidget.data()->password() ||
creds.value( "highQuality" ).toBool() != m_configWidget.data()->highQuality() ) creds.value( "highQuality" ).toBool() != m_configWidget.data()->highQuality() )

View File

@@ -406,7 +406,7 @@ SpotifyParser::checkBrowseFinished()
if ( spotifyAccountLoggedIn ) if ( spotifyAccountLoggedIn )
{ {
QVariantHash creds = Accounts::SpotifyAccount::instance()->credentials(); QVariantMap creds = Accounts::SpotifyAccount::instance()->credentials();
spotifyUsername = creds.value( "username" ).toString(); spotifyUsername = creds.value( "username" ).toString();
} }