mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-01 20:00:13 +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 "PlaylistInterface.h"
|
||||||
#include "Source.h"
|
#include "Source.h"
|
||||||
|
|
||||||
|
#include <qjson/serializer.h>
|
||||||
|
|
||||||
#include <qtkeychain/keychain.h>
|
#include <qtkeychain/keychain.h>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
|
||||||
@@ -634,11 +636,20 @@ TomahawkSettings::doUpgrade( int oldVersion, int newVersion )
|
|||||||
#if defined( Q_OS_UNIX ) && !defined( Q_OS_MAC )
|
#if defined( Q_OS_UNIX ) && !defined( Q_OS_MAC )
|
||||||
j->setInsecureFallback( true );
|
j->setInsecureFallback( true );
|
||||||
#endif
|
#endif
|
||||||
QByteArray data;
|
QJson::Serializer serializer;
|
||||||
QDataStream ds( &data, QIODevice::WriteOnly );
|
bool ok;
|
||||||
ds << creds;
|
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();
|
j->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -22,6 +22,9 @@
|
|||||||
|
|
||||||
#include <qtkeychain/keychain.h>
|
#include <qtkeychain/keychain.h>
|
||||||
|
|
||||||
|
#include <qjson/serializer.h>
|
||||||
|
#include <qjson/parser.h>
|
||||||
|
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
||||||
|
|
||||||
@@ -176,13 +179,20 @@ CredentialsManager::setCredentials( const CredentialsStorageKey& csKey, const QV
|
|||||||
}
|
}
|
||||||
else if ( value.type() == QVariant::Hash )
|
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 );
|
tDebug() << "About to write credentials for key" << csKey.key();
|
||||||
ds << value.toHash();
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tDebug() << "Cannot serialize credentials for writing:" << serializer.errorMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
wj->setBinaryData( data );
|
wj->setTextData( data );
|
||||||
}
|
}
|
||||||
|
|
||||||
j = wj;
|
j = wj;
|
||||||
@@ -224,17 +234,24 @@ CredentialsManager::keychainJobFinished( QKeychain::Job* j )
|
|||||||
<< readJob->key() << "finished without errors";
|
<< readJob->key() << "finished without errors";
|
||||||
|
|
||||||
QVariant creds;
|
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() );
|
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 );
|
m_credentials.insert( CredentialsStorageKey( readJob->service(), readJob->key() ), creds );
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user