diff --git a/src/libtomahawk/TomahawkSettings.cpp b/src/libtomahawk/TomahawkSettings.cpp index 1e5b79b09..5895acb38 100644 --- a/src/libtomahawk/TomahawkSettings.cpp +++ b/src/libtomahawk/TomahawkSettings.cpp @@ -20,8 +20,6 @@ #include "TomahawkSettings.h" -#include - #include "Source.h" #include "PlaylistInterface.h" @@ -33,6 +31,9 @@ #include "playlist/PlaylistUpdaterInterface.h" #include "infosystem/InfoSystemCache.h" +#include +#include + using namespace Tomahawk; TomahawkSettings* TomahawkSettings::s_instance = 0; @@ -612,6 +613,39 @@ TomahawkSettings::doUpgrade( int oldVersion, int newVersion ) const bool removed = dataFile.remove(); tDebug() << "Tried to remove echonest_stylesandmoods.dat, succeeded?" << removed; } + else if ( oldVersion == 14 ) + { + const QStringList accounts = value( "accounts/allaccounts" ).toStringList(); + tDebug() << "About to move these accounts to QtKeychain:" << accounts; + //Move storage of Credentials from QSettings to QtKeychain + foreach ( const QString& account, accounts ) + { + tDebug() << "beginGroup" << QString( "accounts/%1" ).arg( account ); + beginGroup( QString( "accounts/%1" ).arg( account ) ); + const QVariantHash creds = value( "credentials" ).toHash(); + + tDebug() << "creds:" << creds; + if ( !creds.isEmpty() ) + { + QKeychain::WritePasswordJob* j = new QKeychain::WritePasswordJob( QLatin1String( "tomahawkaccounts" ), this ); + j->setKey( account ); + j->setAutoDelete( false ); + + QByteArray data; + QDataStream ds( &data, QIODevice::WriteOnly ); + ds << creds; + + j->setBinaryData( data ); + j->start(); + + qDebug() << "Migrating account credentials for account:" << account; + } + + remove( "credentials" ); + + endGroup(); + } + } }