1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-04-21 16:31:58 +02:00

change credentials to QVariantMap instead of QVariantHash

This commit is contained in:
Stefan Derkits 2014-04-27 20:20:10 +02:00
parent afccb15e18
commit ee85c082e3
13 changed files with 35 additions and 41 deletions

View File

@ -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() )
{

View File

@ -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();

View File

@ -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();

View File

@ -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();
}

View File

@ -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" );

View File

@ -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; }

View File

@ -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() );
}

View File

@ -22,7 +22,7 @@
#include "DllMacro.h"
#include <QObject>
#include <QVariantHash>
#include <QVariantMap>
#include <QMutex>
#include <QStringList>
@ -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:

View File

@ -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() );
}
}

View File

@ -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();

View File

@ -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 );
}

View File

@ -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() )

View File

@ -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();
}