diff --git a/src/libtomahawk/TomahawkSettings.cpp b/src/libtomahawk/TomahawkSettings.cpp index 62260e7ad..ade1208d3 100644 --- a/src/libtomahawk/TomahawkSettings.cpp +++ b/src/libtomahawk/TomahawkSettings.cpp @@ -32,6 +32,8 @@ #include "PlaylistInterface.h" #include "Source.h" +#include + #include #include @@ -634,11 +636,20 @@ TomahawkSettings::doUpgrade( int oldVersion, int newVersion ) #if defined( Q_OS_UNIX ) && !defined( Q_OS_MAC ) j->setInsecureFallback( true ); #endif - QByteArray data; - QDataStream ds( &data, QIODevice::WriteOnly ); - ds << creds; + QJson::Serializer serializer; + bool ok; + QByteArray data = serializer.serialize( creds, &ok ); - j->setBinaryData( data ); + if ( ok ) + { + tDebug() << "Performing upgrade for account" << account; + } + else + { + tDebug() << "Upgrade error:" << serializer.errorMessage(); + } + + j->setTextData( data ); j->start(); } diff --git a/src/libtomahawk/accounts/CredentialsManager.cpp b/src/libtomahawk/accounts/CredentialsManager.cpp index e6eff40bb..9537bddf7 100644 --- a/src/libtomahawk/accounts/CredentialsManager.cpp +++ b/src/libtomahawk/accounts/CredentialsManager.cpp @@ -22,6 +22,9 @@ #include +#include +#include + #include @@ -176,13 +179,20 @@ CredentialsManager::setCredentials( const CredentialsStorageKey& csKey, const QV } else if ( value.type() == QVariant::Hash ) { - QByteArray data; + QJson::Serializer serializer; + bool ok; + QByteArray data = serializer.serialize( value.toHash(), &ok ); + + if ( ok ) { - QDataStream ds( &data, QIODevice::WriteOnly ); - ds << value.toHash(); + tDebug() << "About to write credentials for key" << csKey.key(); + } + else + { + tDebug() << "Cannot serialize credentials for writing:" << serializer.errorMessage(); } - wj->setBinaryData( data ); + wj->setTextData( data ); } j = wj; @@ -224,17 +234,24 @@ CredentialsManager::keychainJobFinished( QKeychain::Job* j ) << readJob->key() << "finished without errors"; QVariant creds; - if ( !readJob->textData().isEmpty() ) + QJson::Parser parser; + bool ok; + + creds = parser.parse( 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 ); + + if ( !ok || creds.toHash().isEmpty() ) { creds = QVariant( readJob->textData() ); } - else //must be a QVH - { - QDataStream dataStream( readJob->binaryData() ); - QVariantHash hash; - dataStream >> hash; - creds = QVariant( hash ); - } m_credentials.insert( CredentialsStorageKey( readJob->service(), readJob->key() ), creds ); }