1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-24 22:46:03 +02:00

Additional work on password storage via qtkeychain

This commit is contained in:
Stefan Derkits
2012-05-14 01:15:53 +02:00
parent fc5bdae520
commit 7fbcf653d3
3 changed files with 36 additions and 17 deletions

View File

@@ -452,7 +452,7 @@ TARGET_LINK_LIBRARIES( tomahawklib
${OS_SPECIFIC_LINK_LIBRARIES} ${OS_SPECIFIC_LINK_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT} ${CMAKE_THREAD_LIBS_INIT}
${LINK_LIBRARIES} ${LINK_LIBRARIES}
-L/home/t95012/kde/lib/ -L/home/t95012/kde/lib/i386-linux-gnu/
qtkeychain qtkeychain
) )

View File

@@ -116,20 +116,31 @@ Account::onError( int errorCode, const QString& error )
void void
Account::keychainJobFinished(QKeychain::Job* j ) Account::keychainJobFinished(QKeychain::Job* j )
{ {
QKeychain::ReadPasswordJob* readJob = qobject_cast< QKeychain::ReadPasswordJob* >( j ); if ( j->error() != QKeychain::NoError )
if ( readJob != 0 )
{ {
QVariantHash var; QKeychain::ReadPasswordJob* readJob = qobject_cast< QKeychain::ReadPasswordJob* >( j );
tLog() << Q_FUNC_INFO << "readJob finished"; if ( readJob != 0 )
tLog() << Q_FUNC_INFO << readJob->key(); {
deserializeCredentials( var, readJob->binaryData() ); tLog() << Q_FUNC_INFO << "readJob finished without errors";
tLog() << Q_FUNC_INFO << var; deserializeCredentials( m_credentials, readJob->binaryData() );
tLog() << Q_FUNC_INFO << readJob->key();
tLog() << Q_FUNC_INFO << m_credentials;
}
else
{
QKeychain::WritePasswordJob* writeJob = qobject_cast< QKeychain::WritePasswordJob* >( j );
if ( writeJob != 0 )
tLog() << Q_FUNC_INFO << "writeJob finished";
else
{
QKeychain::DeletePasswordJob* deleteJob = qobject_cast< QKeychain::DeletePasswordJob* >( j );
tLog() << Q_FUNC_INFO << "deleteJob finished";
}
}
} }
else else
{ tLog() << Q_FUNC_INFO << "Job finished with error: " << j->errorString();
QKeychain::WritePasswordJob* writeJob = qobject_cast< QKeychain::WritePasswordJob* >( j ); j->deleteLater();
tLog() << Q_FUNC_INFO << "writeJob finished";
}
} }
@@ -163,19 +174,20 @@ Account::syncConfig()
s->beginGroup( "accounts/" + m_accountId ); s->beginGroup( "accounts/" + m_accountId );
s->setValue( "accountfriendlyname", m_accountFriendlyName ); s->setValue( "accountfriendlyname", m_accountFriendlyName );
s->setValue( "enabled", m_enabled ); s->setValue( "enabled", m_enabled );
s->setValue( "credentials", m_credentials ); //s->setValue( "credentials", m_credentials );
s->setValue( "configuration", m_configuration ); s->setValue( "configuration", m_configuration );
s->setValue( "acl", m_acl ); s->setValue( "acl", m_acl );
s->setValue( "types", m_types ); s->setValue( "types", m_types );
s->endGroup(); s->endGroup();
s->sync();
QKeychain::WritePasswordJob* j = new QKeychain::WritePasswordJob( QLatin1String( "tomahawkaccounts" ), this ); QKeychain::WritePasswordJob* j = new QKeychain::WritePasswordJob( QLatin1String( "tomahawkaccounts" ), this );
j->setKey( m_accountId ); j->setKey( m_accountId );
j->setAutoDelete( false );
QByteArray bData; QByteArray bData;
serializeCredentials( m_credentials, bData ); serializeCredentials( m_credentials, bData );
j->setBinaryData( bData ); j->setBinaryData( bData );
connect( j, SIGNAL( finished( QKeychain::Job* ) ), this, SLOT( keychainJobFinished( QKeychain::Job* ) ) ); connect( j, SIGNAL( finished( QKeychain::Job* ) ), this, SLOT( keychainJobFinished( QKeychain::Job* ) ) );
j->start(); j->start();
s->sync();
} }
@@ -187,15 +199,16 @@ Account::loadFromConfig( const QString& accountId )
s->beginGroup( "accounts/" + m_accountId ); s->beginGroup( "accounts/" + m_accountId );
m_accountFriendlyName = s->value( "accountfriendlyname", QString() ).toString(); m_accountFriendlyName = s->value( "accountfriendlyname", QString() ).toString();
m_enabled = s->value( "enabled", false ).toBool(); m_enabled = s->value( "enabled", false ).toBool();
m_credentials = s->value( "credentials", QVariantHash() ).toHash(); //m_credentials = s->value( "credentials", QVariantHash() ).toHash();
m_configuration = s->value( "configuration", QVariantHash() ).toHash(); m_configuration = s->value( "configuration", QVariantHash() ).toHash();
m_acl = s->value( "acl", QVariantMap() ).toMap(); m_acl = s->value( "acl", QVariantMap() ).toMap();
m_types = s->value( "types", QStringList() ).toStringList(); m_types = s->value( "types", QStringList() ).toStringList();
s->endGroup();
QKeychain::ReadPasswordJob* j = new QKeychain::ReadPasswordJob( QLatin1String( "tomahawkaccounts" ), this ); QKeychain::ReadPasswordJob* j = new QKeychain::ReadPasswordJob( QLatin1String( "tomahawkaccounts" ), this );
j->setKey( m_accountId ); j->setKey( m_accountId );
j->setAutoDelete( false );
connect( j, SIGNAL( finished( QKeychain::Job* ) ), this, SLOT( keychainJobFinished( QKeychain::Job* ) ) ); connect( j, SIGNAL( finished( QKeychain::Job* ) ), this, SLOT( keychainJobFinished( QKeychain::Job* ) ) );
j->start(); j->start();
s->endGroup();
} }
@@ -206,12 +219,17 @@ Account::removeFromConfig()
s->beginGroup( "accounts/" + m_accountId ); s->beginGroup( "accounts/" + m_accountId );
s->remove( "accountfriendlyname" ); s->remove( "accountfriendlyname" );
s->remove( "enabled" ); s->remove( "enabled" );
s->remove( "credentials" ); //s->remove( "credentials" );
s->remove( "configuration" ); s->remove( "configuration" );
s->remove( "acl" ); s->remove( "acl" );
s->remove( "types" ); s->remove( "types" );
s->endGroup(); s->endGroup();
s->remove( "accounts/" + m_accountId ); s->remove( "accounts/" + m_accountId );
QKeychain::DeletePasswordJob* j = new QKeychain::DeletePasswordJob( QLatin1String( "tomahawkaccounts" ), this );
j->setKey( m_accountId );
j->setAutoDelete( false );
connect( j, SIGNAL( finished( QKeychain::Job* ) ), this, SLOT( keychainJobFinished( QKeychain::Job* ) ) );
j->start();
} }

View File

@@ -33,6 +33,7 @@ SipPlugin::SipPlugin( Tomahawk::Accounts::Account *account, QObject* parent )
{ {
connect( this, SIGNAL( peerOnline( QString ) ), this, SLOT( onPeerOnline( QString ) ) ); connect( this, SIGNAL( peerOnline( QString ) ), this, SLOT( onPeerOnline( QString ) ) );
connect( this, SIGNAL( peerOffline( QString ) ), this, SLOT( onPeerOffline( QString ) ) ); connect( this, SIGNAL( peerOffline( QString ) ), this, SLOT( onPeerOffline( QString ) ) );
connect( m_account, SIGNAL( credentialsChanged( ) ), this, SLOT( configurationChanged( ) ) );
} }