From 63f9168b4af7b3e639e3be8c4c48120935daa173 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Sun, 2 Jun 2013 17:41:08 +0200 Subject: [PATCH] Added ConfigStorage and LocalConfigStorage, preparation for Telepathy. --- src/accounts/xmpp/XmppAccount.h | 2 +- src/libtomahawk/CMakeLists.txt | 1 + src/libtomahawk/accounts/Account.cpp | 63 +++------- src/libtomahawk/accounts/Account.h | 47 +++++--- src/libtomahawk/accounts/AccountManager.cpp | 55 ++++++--- src/libtomahawk/accounts/AccountManager.h | 7 +- src/libtomahawk/accounts/ConfigStorage.h | 54 +++++++++ .../accounts/CredentialsManager.cpp | 22 +++- src/libtomahawk/accounts/CredentialsManager.h | 11 +- .../accounts/LocalConfigStorage.cpp | 108 ++++++++++++++++++ src/libtomahawk/accounts/LocalConfigStorage.h | 55 +++++++++ 11 files changed, 327 insertions(+), 98 deletions(-) create mode 100644 src/libtomahawk/accounts/ConfigStorage.h create mode 100644 src/libtomahawk/accounts/LocalConfigStorage.cpp create mode 100644 src/libtomahawk/accounts/LocalConfigStorage.h diff --git a/src/accounts/xmpp/XmppAccount.h b/src/accounts/xmpp/XmppAccount.h index 077cdbaf3..b0593b3c2 100644 --- a/src/accounts/xmpp/XmppAccount.h +++ b/src/accounts/xmpp/XmppAccount.h @@ -52,7 +52,7 @@ public: QString description() const { return tr( "Log on to your Jabber/XMPP account to connect to your friends" ); } QString factoryId() const { return "xmppaccount"; } QPixmap icon() const { return QPixmap( ":/xmpp-account/xmpp-icon.png" ); } - AccountTypes types() const { return AccountTypes( SipType | StatusPushType ); }; + AccountTypes types() const { return AccountTypes( SipType | StatusPushType ); } Account* createAccount( const QString& pluginId = QString() ); }; diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index 2c8b25ab8..277e92a9d 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -219,6 +219,7 @@ list(APPEND libSources accounts/AccountFactoryWrapper.cpp accounts/AccountFactoryWrapperDelegate.cpp accounts/AccountConfigWidget.cpp + accounts/LocalConfigStorage.cpp accounts/spotify/SpotifyAccount.cpp accounts/spotify/SpotifyAccountConfig.cpp diff --git a/src/libtomahawk/accounts/Account.cpp b/src/libtomahawk/accounts/Account.cpp index 8cfdd659e..0cda69122 100644 --- a/src/libtomahawk/accounts/Account.cpp +++ b/src/libtomahawk/accounts/Account.cpp @@ -2,6 +2,7 @@ * * Copyright 2011, Christian Muehlhaeuser * Copyright 2011, Leo Franchi + * Copyright 2013, Teo Mrnjavac * * Tomahawk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,9 +20,9 @@ #include "Account.h" -#include "TomahawkSettings.h" #include "AccountManager.h" #include "CredentialsManager.h" +#include "ConfigStorage.h" namespace Tomahawk { @@ -51,10 +52,11 @@ accountTypeToString( AccountType type ) Account::Account( const QString& accountId ) : QObject() - , m_enabled( false ) , m_accountId( accountId ) { - connect( this, SIGNAL( error( int, QString ) ), this, SLOT( onError( int,QString ) ) ); + m_cfg.enabled = false; + + connect( this, SIGNAL( error( int, QString ) ), this, SLOT( onError( int, QString ) ) ); connect( this, SIGNAL( connectionStateChanged( Tomahawk::Accounts::Account::ConnectionState ) ) , this, SLOT( onConnectionStateChanged( Tomahawk::Accounts::Account::ConnectionState ) ) ); loadFromConfig( accountId ); @@ -132,18 +134,7 @@ Account::onConnectionStateChanged( Account::ConnectionState ) void Account::syncConfig() { - TomahawkSettings* s = TomahawkSettings::instance(); - s->beginGroup( "accounts/" + m_accountId ); - s->setValue( "accountfriendlyname", m_accountFriendlyName ); - s->setValue( "enabled", m_enabled ); - s->setValue( "configuration", m_configuration ); - s->setValue( "acl", m_acl ); - s->setValue( "types", m_types ); - s->endGroup(); - s->sync(); - - CredentialsManager* c = AccountManager::instance()->credentialsManager(); - c->setCredentials( "Tomahawk", m_accountId, m_credentials ); + AccountManager::instance()->configStorageForAccount( m_accountId )->save( m_accountId, m_cfg ); } @@ -151,35 +142,15 @@ void Account::loadFromConfig( const QString& accountId ) { m_accountId = accountId; - TomahawkSettings* s = TomahawkSettings::instance(); - s->beginGroup( "accounts/" + m_accountId ); - m_accountFriendlyName = s->value( "accountfriendlyname", QString() ).toString(); - m_enabled = s->value( "enabled", false ).toBool(); - m_configuration = s->value( "configuration", QVariantHash() ).toHash(); - m_acl = s->value( "acl", QVariantMap() ).toMap(); - m_types = s->value( "types", QStringList() ).toStringList(); - s->endGroup(); - CredentialsManager* c = AccountManager::instance()->credentialsManager(); - m_credentials = c->credentials( "Tomahawk", m_accountId ); + AccountManager::instance()->configStorageForAccount( m_accountId )->load( m_accountId, m_cfg ); } void Account::removeFromConfig() { - TomahawkSettings* s = TomahawkSettings::instance(); - s->beginGroup( "accounts/" + m_accountId ); - s->remove( "accountfriendlyname" ); - s->remove( "enabled" ); - s->remove( "configuration" ); - s->remove( "acl" ); - s->remove( "types" ); - s->endGroup(); - s->remove( "accounts/" + m_accountId ); - - CredentialsManager* c = AccountManager::instance()->credentialsManager(); - c->setCredentials( "Tomahawk", m_accountId, QVariantHash() ); + AccountManager::instance()->configStorageForAccount( m_accountId )->remove( m_accountId ); } @@ -187,15 +158,15 @@ void Account::setTypes( AccountTypes types ) { QMutexLocker locker( &m_mutex ); - m_types = QStringList(); + m_cfg.types = QStringList(); if ( types & InfoType ) - m_types << "InfoType"; + m_cfg.types << "InfoType"; if ( types & SipType ) - m_types << "SipType"; + m_cfg.types << "SipType"; if ( types & ResolverType ) - m_types << "ResolverType"; + m_cfg.types << "ResolverType"; if ( types & StatusPushType ) - m_types << "StatusPushType"; + m_cfg.types << "StatusPushType"; syncConfig(); } @@ -205,13 +176,13 @@ Account::types() const { QMutexLocker locker( &m_mutex ); AccountTypes types; - if ( m_types.contains( "InfoType" ) ) + if ( m_cfg.types.contains( "InfoType" ) ) types |= InfoType; - if ( m_types.contains( "SipType" ) ) + if ( m_cfg.types.contains( "SipType" ) ) types |= SipType; - if ( m_types.contains( "ResolverType" ) ) + if ( m_cfg.types.contains( "ResolverType" ) ) types |= ResolverType; - if ( m_types.contains( "StatusPushType" ) ) + if ( m_cfg.types.contains( "StatusPushType" ) ) types |= StatusPushType; return types; diff --git a/src/libtomahawk/accounts/Account.h b/src/libtomahawk/accounts/Account.h index d7b54d0a5..436335af7 100644 --- a/src/libtomahawk/accounts/Account.h +++ b/src/libtomahawk/accounts/Account.h @@ -2,6 +2,7 @@ * * Copyright 2011, Christian Muehlhaeuser * Copyright 2011, Leo Franchi + * Copyright 2013, Teo Mrnjavac * * Tomahawk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -41,6 +42,8 @@ namespace Tomahawk namespace Accounts { +class ConfigStorage; + enum AccountType { NoType = 0x00, @@ -66,18 +69,28 @@ class DLLEXPORT Account : public QObject Q_OBJECT public: + struct Configuration + { + QString accountFriendlyName; + bool enabled; + QVariantHash configuration; + QVariantMap acl; + QStringList types; + QVariantHash credentials; + }; + enum AuthErrorCode { AuthError, ConnectionError }; enum ConnectionState { Disconnected, Connecting, Connected, Disconnecting }; - explicit Account( const QString &accountId ); + explicit Account(const QString &accountId); virtual ~Account(); QString accountServiceName() const { QMutexLocker locker( &m_mutex ); return m_accountServiceName; } // e.g. "Twitter", "Last.fm" - QString accountFriendlyName() const { QMutexLocker locker( &m_mutex ); return m_accountFriendlyName; } // e.g. screen name on the service, JID, etc. - bool enabled() const { QMutexLocker locker( &m_mutex ); return m_enabled; } + QString accountFriendlyName() const { QMutexLocker locker( &m_mutex ); return m_cfg.accountFriendlyName; } // e.g. screen name on the service, JID, etc. + bool enabled() const { QMutexLocker locker( &m_mutex ); return m_cfg.enabled; } QString accountId() const { QMutexLocker locker( &m_mutex ); return m_accountId; } - QVariantHash configuration() const { QMutexLocker locker( &m_mutex ); return m_configuration; } + QVariantHash configuration() const { QMutexLocker locker( &m_mutex ); return m_cfg.configuration; } /** * Configuration widgets can have a "dataError( bool )" signal to enable/disable the OK button in their wrapper dialogs. @@ -94,9 +107,9 @@ public: virtual void saveConfig() {} // called when the widget has been edited. save values from config widget, call sync() to write to disk account generic settings - QVariantHash credentials() const { QMutexLocker locker( &m_mutex ); return m_credentials; } + QVariantHash credentials() const { QMutexLocker locker( &m_mutex ); return m_cfg.credentials; } - QVariantMap acl() const { QMutexLocker locker( &m_mutex ); return m_acl; } + QVariantMap acl() const { QMutexLocker locker( &m_mutex ); return m_cfg.acl; } virtual ConnectionState connectionState() const = 0; virtual bool isAuthenticated() const = 0; @@ -113,15 +126,16 @@ public: AccountTypes types() const; void setAccountServiceName( const QString &serviceName ) { QMutexLocker locker( &m_mutex ); m_accountServiceName = serviceName; } - void setAccountFriendlyName( const QString &friendlyName ) { QMutexLocker locker( &m_mutex ); m_accountFriendlyName = friendlyName; } - void setEnabled( bool enabled ) { QMutexLocker locker( &m_mutex ); m_enabled = enabled; } + void setAccountFriendlyName( const QString &friendlyName ) { QMutexLocker locker( &m_mutex ); m_cfg.accountFriendlyName = friendlyName; } + void setEnabled( bool enabled ) { QMutexLocker locker( &m_mutex ); m_cfg.enabled = enabled; } void setAccountId( const QString &accountId ) { QMutexLocker locker( &m_mutex ); m_accountId = accountId; } - void setCredentials( const QVariantHash &credentialHash ) { QMutexLocker locker( &m_mutex ); m_credentials = credentialHash; } - void setConfiguration( const QVariantHash &configuration ) { QMutexLocker locker( &m_mutex ); m_configuration = configuration; } - void setAcl( const QVariantMap &acl ) { QMutexLocker locker( &m_mutex ); m_acl = acl; } + void setCredentials( const QVariantHash &credentialHash ) { QMutexLocker locker( &m_mutex ); m_cfg.credentials = credentialHash; } + void setConfiguration( const QVariantHash &configuration ) { QMutexLocker locker( &m_mutex ); m_cfg.configuration = configuration; } + void setAcl( const QVariantMap &acl ) { QMutexLocker locker( &m_mutex ); m_cfg.acl = acl; } + void setTypes( AccountTypes types ); - void sync() { QMutexLocker locker( &m_mutex ); syncConfig(); }; + void sync() { QMutexLocker locker( &m_mutex ); syncConfig(); } /** * Removes all the settings held in the config file for this account instance @@ -150,15 +164,12 @@ private slots: private: QString m_accountServiceName; - QString m_accountFriendlyName; QString m_cachedError; - bool m_enabled; QString m_accountId; - QVariantHash m_credentials; - QVariantHash m_configuration; - QVariantMap m_acl; - QStringList m_types; + mutable QMutex m_mutex; + + Account::Configuration m_cfg; }; class DLLEXPORT AccountFactory : public QObject diff --git a/src/libtomahawk/accounts/AccountManager.cpp b/src/libtomahawk/accounts/AccountManager.cpp index 71ff0b0a9..88ec4c4e7 100644 --- a/src/libtomahawk/accounts/AccountManager.cpp +++ b/src/libtomahawk/accounts/AccountManager.cpp @@ -32,6 +32,7 @@ #include "ResolverAccount.h" #include "SourceList.h" #include "TomahawkSettings.h" +#include "LocalConfigStorage.h" #include #include @@ -284,38 +285,42 @@ AccountManager::toggleAccountsConnected() void AccountManager::loadFromConfig() { - QStringList accountIds = TomahawkSettings::instance()->accounts(); + m_creds = new CredentialsManager( this ); + ConfigStorage* configStorage = new LocalConfigStorage( this ); //registers with CredentialsManager in the ctor + m_configStorageById.insert( configStorage->id(), configStorage ); + + QStringList accountIds; + foreach ( ConfigStorage* cs, m_configStorageById ) + accountIds << cs->accountIds(); qDebug() << "LOADING ALL CREDENTIALS" << accountIds; - m_creds = new CredentialsManager( this ); NewClosure( m_creds, SIGNAL( ready() ), - this, SLOT( finishLoadingFromConfig( QStringList ) ), accountIds ); - - CredentialsManager::Service tomahawkSvc; - tomahawkSvc.name = "Tomahawk"; //the string where we store in QtKeychain - tomahawkSvc.keys = accountIds; - QList< CredentialsManager::Service > svcs; - svcs << tomahawkSvc; - m_creds->loadCredentials( svcs ); + this, SLOT( finishLoadingFromConfig() ) ); + m_creds->loadCredentials(); } void -AccountManager::finishLoadingFromConfig( const QStringList& accountIds ) +AccountManager::finishLoadingFromConfig() { - qDebug() << "LOADING ALL ACCOUNTS" << accountIds; - - foreach ( const QString& accountId, accountIds ) + foreach ( ConfigStorage* cs, m_configStorageById ) { - QString pluginFactory = factoryFromId( accountId ); - if ( m_accountFactories.contains( pluginFactory ) ) + QStringList accountIds = cs->accountIds(); + + qDebug() << "LOADING ALL ACCOUNTS FOR STORAGE" << cs->metaObject()->className() + << ":" << accountIds; + + foreach ( const QString& accountId, accountIds ) { - Account* account = loadPlugin( accountId ); - addAccount( account ); + QString pluginFactory = factoryFromId( accountId ); + if ( m_accountFactories.contains( pluginFactory ) ) + { + Account* account = loadPlugin( accountId ); + addAccount( account ); + } } } - m_readyForSip = true; emit readyForSip(); //we have to yield to TomahawkApp because we don't know if Servent is ready } @@ -453,6 +458,18 @@ AccountManager::zeroconfAccount() const } +ConfigStorage* +AccountManager::configStorageForAccount( const QString& accountId ) +{ + foreach ( ConfigStorage* cs, m_configStorageById ) + { + if ( cs->accountIds().contains( accountId ) ) + return cs; + } + return 0; +} + + void AccountManager::hookupAccount( Account* account ) const { diff --git a/src/libtomahawk/accounts/AccountManager.h b/src/libtomahawk/accounts/AccountManager.h index 3e74802cc..0e9f5efd1 100644 --- a/src/libtomahawk/accounts/AccountManager.h +++ b/src/libtomahawk/accounts/AccountManager.h @@ -95,6 +95,7 @@ public: bool isReady() const { return m_completelyReady; } CredentialsManager* credentialsManager() const { return m_creds; } + ConfigStorage* configStorageForAccount( const QString& accountId ); public slots: void connectAll(); @@ -119,7 +120,7 @@ private slots: void init(); void onStateChanged( Tomahawk::Accounts::Account::ConnectionState state ); void onError( int code, const QString& msg ); - void finishLoadingFromConfig( const QStringList& accountIds ); + void finishLoadingFromConfig(); void onSettingsChanged(); @@ -129,7 +130,7 @@ private: void loadPluginFactory( const QString &path ); QString factoryFromId( const QString& accountId ) const; - Account* loadPlugin( const QString &accountId ); + Account* loadPlugin( const QString& accountId ); void hookupAccount( Account* ) const; CredentialsManager* m_creds; @@ -145,6 +146,8 @@ private: QHash< QString, AccountFactory* > m_accountFactories; QList< AccountFactory* > m_factoriesForFilesytem; + QMap< QString, ConfigStorage* > m_configStorageById; + static AccountManager* s_instance; }; diff --git a/src/libtomahawk/accounts/ConfigStorage.h b/src/libtomahawk/accounts/ConfigStorage.h new file mode 100644 index 000000000..ad95fe5a7 --- /dev/null +++ b/src/libtomahawk/accounts/ConfigStorage.h @@ -0,0 +1,54 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Teo Mrnjavac + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#ifndef CONFIGSTORAGE_H +#define CONFIGSTORAGE_H + +#include "TomahawkSettings.h" +#include "Account.h" + + +namespace Tomahawk +{ + +namespace Accounts +{ + +class ConfigStorage : public QObject +{ +public: + explicit ConfigStorage( QObject* parent ) + : QObject( parent ) + {} + + virtual ~ConfigStorage() {} + + virtual QString id() const = 0; + + virtual QStringList accountIds() const = 0; + + virtual void save( const QString& accountId, const Account::Configuration& cfg ) = 0; + virtual void load( const QString& accountId, Account::Configuration& cfg ) = 0; + virtual void remove( const QString& accountId ) = 0; + +}; + +} //namespace Accounts +} //namespace Tomahawk + +#endif // CONFIGSTORAGE_H diff --git a/src/libtomahawk/accounts/CredentialsManager.cpp b/src/libtomahawk/accounts/CredentialsManager.cpp index b0c62d1c7..3f0be86d1 100644 --- a/src/libtomahawk/accounts/CredentialsManager.cpp +++ b/src/libtomahawk/accounts/CredentialsManager.cpp @@ -66,14 +66,26 @@ CredentialsManager::CredentialsManager( QObject* parent ) void -CredentialsManager::loadCredentials( QList< Service > keysByService ) +CredentialsManager::addService( const QString& service , const QStringList& accountIds ) { - foreach ( const Service svc, keysByService ) + if ( m_services.contains( service ) ) + m_services.remove( service ); + m_services.insert( service, accountIds ); +} + + +void +CredentialsManager::loadCredentials() +{ + for ( QHash< QString, QStringList >::const_iterator it = m_services.constBegin(); + it != m_services.constEnd(); ++it ) { - tDebug() << Q_FUNC_INFO << "keys for service" << svc.name << ":" << svc.keys; - foreach ( QString key, svc.keys ) + const QString& svcName = it.key(); + const QStringList& accountIds = it.value(); + tDebug() << Q_FUNC_INFO << "keys for service" << svcName << ":" << accountIds; + foreach ( QString key, accountIds ) { - QKeychain::ReadPasswordJob* j = new QKeychain::ReadPasswordJob( svc.name, this ); + QKeychain::ReadPasswordJob* j = new QKeychain::ReadPasswordJob( svcName, this ); j->setKey( key ); j->setAutoDelete( false ); #if defined( Q_OS_UNIX ) && !defined( Q_OS_MAC ) diff --git a/src/libtomahawk/accounts/CredentialsManager.h b/src/libtomahawk/accounts/CredentialsManager.h index f450aaeff..aa000709e 100644 --- a/src/libtomahawk/accounts/CredentialsManager.h +++ b/src/libtomahawk/accounts/CredentialsManager.h @@ -64,15 +64,11 @@ class CredentialsManager : public QObject { Q_OBJECT public: - struct Service - { - QString name; - QStringList keys; - }; - explicit CredentialsManager( QObject* parent = 0 ); - void loadCredentials( QList< Service > keysByService ); + void addService( const QString& service, const QStringList& accountIds ); + + void loadCredentials(); QList< CredentialsStorageKey > keys() const; @@ -88,6 +84,7 @@ private slots: void keychainJobFinished( QKeychain::Job* ); private: + QHash< QString, QStringList > m_services; QHash< CredentialsStorageKey, QVariantHash > m_credentials; QList< QKeychain::ReadPasswordJob* > m_readJobs; QMutex m_mutex; diff --git a/src/libtomahawk/accounts/LocalConfigStorage.cpp b/src/libtomahawk/accounts/LocalConfigStorage.cpp new file mode 100644 index 000000000..b1581b978 --- /dev/null +++ b/src/libtomahawk/accounts/LocalConfigStorage.cpp @@ -0,0 +1,108 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Teo Mrnjavac + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#include "LocalConfigStorage.h" + +#include "Account.h" +#include "AccountManager.h" +#include "CredentialsManager.h" + +namespace Tomahawk +{ + +namespace Accounts +{ + + +LocalConfigStorage::LocalConfigStorage( QObject* parent ) + : ConfigStorage( parent ) + , m_credentialsServiceName( "Tomahawk" ) +{ + m_accountIds = TomahawkSettings::instance()->accounts(); + + // tell CredentialsManager which account ids it will be writing credentials for and in which svc + // so it can preload them when we call CM::loadCredentials() + AccountManager::instance()->credentialsManager()->addService( m_credentialsServiceName, + m_accountIds ); +} + + +QStringList +LocalConfigStorage::accountIds() const +{ + return m_accountIds; +} + + +void +LocalConfigStorage::save( const QString& accountId, const Account::Configuration& cfg ) +{ + TomahawkSettings* s = TomahawkSettings::instance(); + s->beginGroup( "accounts/" + accountId ); + s->setValue( "accountfriendlyname", cfg.accountFriendlyName ); + s->setValue( "enabled", cfg.enabled ); + s->setValue( "configuration", cfg.configuration ); + s->setValue( "acl", cfg.acl ); + s->setValue( "types", cfg.types ); + s->endGroup(); + s->sync(); + + CredentialsManager* c = AccountManager::instance()->credentialsManager(); + c->setCredentials( m_credentialsServiceName, accountId, cfg.credentials ); + + if ( !m_accountIds.contains( accountId ) ) + m_accountIds.append( accountId ); +} + + +void +LocalConfigStorage::load( const QString& accountId, Account::Configuration& cfg ) +{ + TomahawkSettings* s = TomahawkSettings::instance(); + s->beginGroup( "accounts/" + accountId ); + cfg.accountFriendlyName = s->value( "accountfriendlyname", QString() ).toString(); + cfg.enabled = s->value( "enabled", false ).toBool(); + cfg.configuration = s->value( "configuration", QVariantHash() ).toHash(); + cfg.acl = s->value( "acl", QVariantMap() ).toMap(); + cfg.types = s->value( "types", QStringList() ).toStringList(); + s->endGroup(); + + CredentialsManager* c = AccountManager::instance()->credentialsManager(); + cfg.credentials = c->credentials( m_credentialsServiceName, accountId ); +} + + +void +LocalConfigStorage::remove( const QString& accountId ) +{ + TomahawkSettings* s = TomahawkSettings::instance(); + s->beginGroup( "accounts/" + accountId ); + s->remove( "accountfriendlyname" ); + s->remove( "enabled" ); + s->remove( "configuration" ); + s->remove( "acl" ); + s->remove( "types" ); + s->endGroup(); + s->remove( "accounts/" + accountId ); + + CredentialsManager* c = AccountManager::instance()->credentialsManager(); + c->setCredentials( m_credentialsServiceName, accountId, QVariantHash() ); +} + +} +} diff --git a/src/libtomahawk/accounts/LocalConfigStorage.h b/src/libtomahawk/accounts/LocalConfigStorage.h new file mode 100644 index 000000000..31f04d0b0 --- /dev/null +++ b/src/libtomahawk/accounts/LocalConfigStorage.h @@ -0,0 +1,55 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Teo Mrnjavac + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#ifndef LOCALCONFIGSTORAGE_H +#define LOCALCONFIGSTORAGE_H + +#include "ConfigStorage.h" + +namespace Tomahawk +{ + +namespace Accounts +{ + +class LocalConfigStorage : public ConfigStorage +{ + Q_OBJECT +public: + explicit LocalConfigStorage( QObject* parent = 0 ); + + QString id() const { return "localconfigstorage"; } + + QStringList accountIds() const; + + virtual void save( const QString& accountId, const Account::Configuration& cfg ); + virtual void load( const QString& accountId, Account::Configuration& cfg ); + virtual void remove( const QString& accountId ); + +private: + const QString m_credentialsServiceName; + QStringList m_accountIds; + + static LocalConfigStorage* s_instance; +}; + +} //namespace Accounts + +} //namespace Tomahawk + +#endif // LOCALCONFIGSTORAGE_H