From 8febff60309591e93a7ed8eadd6a31104a9c6e5b Mon Sep 17 00:00:00 2001 From: Stefan Derkits Date: Mon, 14 May 2012 19:55:58 +0200 Subject: [PATCH] start migration code, load credentials on show (instead on object creation) in XmppConfigWidget --- src/accounts/xmpp/XmppConfigWidget.cpp | 29 +++++++++++++++++++------- src/accounts/xmpp/XmppConfigWidget.h | 5 +++++ src/libtomahawk/TomahawkSettings.cpp | 12 +++++++++++ src/libtomahawk/accounts/Account.cpp | 6 ++++-- src/libtomahawk/accounts/Account.h | 7 +++++-- 5 files changed, 48 insertions(+), 11 deletions(-) diff --git a/src/accounts/xmpp/XmppConfigWidget.cpp b/src/accounts/xmpp/XmppConfigWidget.cpp index e5fb56002..7ad37e4b4 100644 --- a/src/accounts/xmpp/XmppConfigWidget.cpp +++ b/src/accounts/xmpp/XmppConfigWidget.cpp @@ -38,14 +38,9 @@ XmppConfigWidget::XmppConfigWidget( XmppAccount* account, QWidget *parent ) : m_account( account ) { m_ui->setupUi( this ); - - m_ui->xmppUsername->setText( account->credentials().contains( "username" ) ? account->credentials()[ "username" ].toString() : QString() ); - m_ui->xmppPassword->setText( account->credentials().contains( "password" ) ? account->credentials()[ "password" ].toString() : QString() ); - m_ui->xmppServer->setText( account->configuration().contains( "server" ) ? account->configuration()[ "server" ].toString() : QString() ); - m_ui->xmppPort->setValue( account->configuration().contains( "port" ) ? account->configuration()[ "port" ].toInt() : 5222 ); - m_ui->xmppPublishTracksCheckbox->setChecked( account->configuration().contains( "publishtracks" ) ? account->configuration()[ "publishtracks" ].toBool() : true); - m_ui->xmppEnforceSecureCheckbox->setChecked( account->configuration().contains( "enforcesecure" ) ? account->configuration()[ "enforcesecure" ].toBool() : false); m_ui->jidExistsLabel->hide(); + + loadFromConfig(); connect( m_ui->xmppUsername, SIGNAL( textChanged( QString ) ), SLOT( onCheckJidExists( QString ) ) ); } @@ -78,6 +73,26 @@ XmppConfigWidget::saveConfig() } +void +XmppConfigWidget::showEvent(QShowEvent* event) +{ + loadFromConfig(); +} + + +void +XmppConfigWidget::loadFromConfig() +{ + m_ui->xmppUsername->setText( m_account->credentials().contains( "username" ) ? m_account->credentials()[ "username" ].toString() : QString() ); + m_ui->xmppPassword->setText( m_account->credentials().contains( "password" ) ? m_account->credentials()[ "password" ].toString() : QString() ); + m_ui->xmppServer->setText( m_account->configuration().contains( "server" ) ? m_account->configuration()[ "server" ].toString() : QString() ); + m_ui->xmppPort->setValue( m_account->configuration().contains( "port" ) ? m_account->configuration()[ "port" ].toInt() : 5222 ); + m_ui->xmppPublishTracksCheckbox->setChecked( m_account->configuration().contains( "publishtracks" ) ? m_account->configuration()[ "publishtracks" ].toBool() : true); + m_ui->xmppEnforceSecureCheckbox->setChecked( m_account->configuration().contains( "enforcesecure" ) ? m_account->configuration()[ "enforcesecure" ].toBool() : false); +} + + + void XmppConfigWidget::onCheckJidExists( QString jid ) { diff --git a/src/accounts/xmpp/XmppConfigWidget.h b/src/accounts/xmpp/XmppConfigWidget.h index 25521b786..f1046635d 100644 --- a/src/accounts/xmpp/XmppConfigWidget.h +++ b/src/accounts/xmpp/XmppConfigWidget.h @@ -48,10 +48,15 @@ public: virtual ~XmppConfigWidget(); void saveConfig(); + + void loadFromConfig(); signals: void dataError( bool exists ); +protected: + void showEvent( QShowEvent* event ); + private slots: void onCheckJidExists( QString jid ); diff --git a/src/libtomahawk/TomahawkSettings.cpp b/src/libtomahawk/TomahawkSettings.cpp index 3f68f5f99..c83faccb7 100644 --- a/src/libtomahawk/TomahawkSettings.cpp +++ b/src/libtomahawk/TomahawkSettings.cpp @@ -22,6 +22,8 @@ #include +#include + #include "sip/SipHandler.h" #include "PlaylistInterface.h" @@ -516,6 +518,16 @@ TomahawkSettings::doUpgrade( int oldVersion, int newVersion ) remove( "playlistupdaters" ); } + else if ( oldVersion == 10 ) + { + const QStringList accounts = childGroups(); + //Move storage of Credentials from QSettings to QtKeychain + foreach ( const QString& account, accounts ) + { + //TODO: migration code to be written + + } + } } diff --git a/src/libtomahawk/accounts/Account.cpp b/src/libtomahawk/accounts/Account.cpp index 48de36282..6eb2c1754 100644 --- a/src/libtomahawk/accounts/Account.cpp +++ b/src/libtomahawk/accounts/Account.cpp @@ -19,6 +19,8 @@ #include "Account.h" +#include + namespace Tomahawk { @@ -216,7 +218,7 @@ Account::loadFromConfig( const QString& accountId ) m_acl = s->value( "acl", QVariantMap() ).toMap(); 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( "tomahawk" ), this ); j->setKey( m_accountId ); j->setAutoDelete( false ); connect( j, SIGNAL( finished( QKeychain::Job* ) ), this, SLOT( keychainJobFinished( QKeychain::Job* ) ) ); @@ -237,7 +239,7 @@ Account::removeFromConfig() s->remove( "types" ); s->endGroup(); s->remove( "accounts/" + m_accountId ); - QKeychain::DeletePasswordJob* j = new QKeychain::DeletePasswordJob( QLatin1String( "tomahawkaccounts" ), this ); + QKeychain::DeletePasswordJob* j = new QKeychain::DeletePasswordJob( QLatin1String( "tomahawk" ), this ); j->setKey( m_accountId ); j->setAutoDelete( false ); connect( j, SIGNAL( finished( QKeychain::Job* ) ), this, SLOT( keychainJobFinished( QKeychain::Job* ) ) ); diff --git a/src/libtomahawk/accounts/Account.h b/src/libtomahawk/accounts/Account.h index d94d30d33..096357d70 100644 --- a/src/libtomahawk/accounts/Account.h +++ b/src/libtomahawk/accounts/Account.h @@ -27,8 +27,6 @@ #include #include -#include - #include "Typedefs.h" #include "DllMacro.h" #include "TomahawkSettings.h" @@ -37,6 +35,11 @@ class SipPlugin; +namespace QKeychain +{ + class Job; +} + namespace Tomahawk {