1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-26 07:14:47 +02:00

preperations & first steps towards implementations of password storage via QtKeychain (using async branch)

This commit is contained in:
Stefan Derkits
2012-05-07 00:16:44 +02:00
parent 43a55d932e
commit fc5bdae520
3 changed files with 58 additions and 0 deletions

View File

@@ -452,6 +452,8 @@ TARGET_LINK_LIBRARIES( tomahawklib
${OS_SPECIFIC_LINK_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
${LINK_LIBRARIES}
-L/home/t95012/kde/lib/
qtkeychain
)
INSTALL( TARGETS tomahawklib

View File

@@ -113,6 +113,42 @@ Account::onError( int errorCode, const QString& error )
}
void
Account::keychainJobFinished(QKeychain::Job* j )
{
QKeychain::ReadPasswordJob* readJob = qobject_cast< QKeychain::ReadPasswordJob* >( j );
if ( readJob != 0 )
{
QVariantHash var;
tLog() << Q_FUNC_INFO << "readJob finished";
tLog() << Q_FUNC_INFO << readJob->key();
deserializeCredentials( var, readJob->binaryData() );
tLog() << Q_FUNC_INFO << var;
}
else
{
QKeychain::WritePasswordJob* writeJob = qobject_cast< QKeychain::WritePasswordJob* >( j );
tLog() << Q_FUNC_INFO << "writeJob finished";
}
}
void
Account::serializeCredentials(const QVariantHash& credentials, QByteArray& data)
{
QDataStream ds(&data, QIODevice::WriteOnly);
ds << credentials;
}
void
Account::deserializeCredentials(QVariantHash& credentials, const QByteArray& data)
{
QDataStream ds2(data);
ds2 >> credentials;
}
void
Account::onConnectionStateChanged( Account::ConnectionState )
{
@@ -132,6 +168,13 @@ Account::syncConfig()
s->setValue( "acl", m_acl );
s->setValue( "types", m_types );
s->endGroup();
QKeychain::WritePasswordJob* j = new QKeychain::WritePasswordJob( QLatin1String( "tomahawkaccounts" ), this );
j->setKey( m_accountId );
QByteArray bData;
serializeCredentials( m_credentials, bData );
j->setBinaryData( bData );
connect( j, SIGNAL( finished( QKeychain::Job* ) ), this, SLOT( keychainJobFinished( QKeychain::Job* ) ) );
j->start();
s->sync();
}
@@ -148,6 +191,10 @@ Account::loadFromConfig( const QString& accountId )
m_configuration = s->value( "configuration", QVariantHash() ).toHash();
m_acl = s->value( "acl", QVariantMap() ).toMap();
m_types = s->value( "types", QStringList() ).toStringList();
QKeychain::ReadPasswordJob* j = new QKeychain::ReadPasswordJob( QLatin1String( "tomahawkaccounts" ), this );
j->setKey( m_accountId );
connect( j, SIGNAL( finished( QKeychain::Job* ) ), this, SLOT( keychainJobFinished( QKeychain::Job* ) ) );
j->start();
s->endGroup();
}

View File

@@ -27,6 +27,8 @@
#include <QtCore/QString>
#include <QtCore/QUuid>
#include <qtkeychain/keychain.h>
#include "Typedefs.h"
#include "DllMacro.h"
#include "TomahawkSettings.h"
@@ -132,6 +134,8 @@ signals:
void configurationChanged();
void credentialsChanged();
protected:
virtual void loadFromConfig( const QString &accountId );
virtual void syncConfig();
@@ -140,7 +144,12 @@ private slots:
void onConnectionStateChanged( Tomahawk::Accounts::Account::ConnectionState );
void onError( int, const QString& );
void keychainJobFinished( QKeychain::Job* );
private:
void serializeCredentials( const QVariantHash& credentials, QByteArray& data );
void deserializeCredentials( QVariantHash& credentials, const QByteArray& data );
QString m_accountServiceName;
QString m_accountFriendlyName;
QString m_cachedError;