mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-07-31 03:10:12 +02:00
JSON-serialize creds.
If you are running master you will have to re-enter your passwords, sorry :C
This commit is contained in:
@@ -32,6 +32,8 @@
|
||||
#include "PlaylistInterface.h"
|
||||
#include "Source.h"
|
||||
|
||||
#include <qjson/serializer.h>
|
||||
|
||||
#include <qtkeychain/keychain.h>
|
||||
#include <QDir>
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
@@ -22,6 +22,9 @@
|
||||
|
||||
#include <qtkeychain/keychain.h>
|
||||
|
||||
#include <qjson/serializer.h>
|
||||
#include <qjson/parser.h>
|
||||
|
||||
#include <QStringList>
|
||||
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
|
Reference in New Issue
Block a user