diff --git a/src/libtomahawk/accounts/AccountManager.cpp b/src/libtomahawk/accounts/AccountManager.cpp index ec8776a13..3b9dcd33e 100644 --- a/src/libtomahawk/accounts/AccountManager.cpp +++ b/src/libtomahawk/accounts/AccountManager.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include @@ -287,19 +288,31 @@ AccountManager::loadFromConfig() { m_creds = new CredentialsManager( this ); - ConfigStorage* configStorage = new LocalConfigStorage( this ); //registers with CredentialsManager in the ctor + QSharedPointer< ConfigStorage > configStorage; + configStorage = QSharedPointer< ConfigStorage >( new LocalConfigStorage( this ) ); m_configStorageById.insert( configStorage->id(), configStorage ); - //TODO: when we get more than one CS, hook them all up to continue with account loading - NewClosure( configStorage, SIGNAL( ready() ), - this, SLOT( finishLoadingFromConfig() ) ); + + foreach ( const QSharedPointer< ConfigStorage >& cs, m_configStorageById ) + { + m_configStorageLoading.insert( cs->id() ); + NewClosure( cs.data(), SIGNAL( ready() ), + this, SLOT( finishLoadingFromConfig( QSharedPointer< ConfigStorage > ) ), cs ); + cs->init(); + } } void -AccountManager::finishLoadingFromConfig() +AccountManager::finishLoadingFromConfig( const QSharedPointer< ConfigStorage >& cs ) { - foreach ( ConfigStorage* cs, m_configStorageById ) + if ( m_configStorageLoading.contains( cs->id() ) ) + m_configStorageLoading.remove( cs->id() ); + + if ( !m_configStorageLoading.isEmpty() ) + return; + + foreach ( const QSharedPointer< ConfigStorage >& cs, m_configStorageById ) { QStringList accountIds = cs->accountIds(); @@ -453,15 +466,15 @@ AccountManager::zeroconfAccount() const } -ConfigStorage* +QSharedPointer< ConfigStorage > AccountManager::configStorageForAccount( const QString& accountId ) { - foreach ( ConfigStorage* cs, m_configStorageById ) + foreach ( const QSharedPointer< ConfigStorage >& cs, m_configStorageById ) { if ( cs->accountIds().contains( accountId ) ) return cs; } - return 0; + return QSharedPointer< ConfigStorage >(); } diff --git a/src/libtomahawk/accounts/AccountManager.h b/src/libtomahawk/accounts/AccountManager.h index 0e9f5efd1..bc56f9d44 100644 --- a/src/libtomahawk/accounts/AccountManager.h +++ b/src/libtomahawk/accounts/AccountManager.h @@ -95,7 +95,7 @@ public: bool isReady() const { return m_completelyReady; } CredentialsManager* credentialsManager() const { return m_creds; } - ConfigStorage* configStorageForAccount( const QString& accountId ); + QSharedPointer< ConfigStorage > configStorageForAccount( const QString& accountId ); public slots: void connectAll(); @@ -120,7 +120,7 @@ private slots: void init(); void onStateChanged( Tomahawk::Accounts::Account::ConnectionState state ); void onError( int code, const QString& msg ); - void finishLoadingFromConfig(); + void finishLoadingFromConfig( const QSharedPointer< ConfigStorage >& cs ); void onSettingsChanged(); @@ -146,7 +146,8 @@ private: QHash< QString, AccountFactory* > m_accountFactories; QList< AccountFactory* > m_factoriesForFilesytem; - QMap< QString, ConfigStorage* > m_configStorageById; + QMap< QString, QSharedPointer< ConfigStorage > > m_configStorageById; + QSet< QString > m_configStorageLoading; static AccountManager* s_instance; }; diff --git a/src/libtomahawk/accounts/ConfigStorage.h b/src/libtomahawk/accounts/ConfigStorage.h index 69a531186..cbf784918 100644 --- a/src/libtomahawk/accounts/ConfigStorage.h +++ b/src/libtomahawk/accounts/ConfigStorage.h @@ -22,6 +22,7 @@ #include "TomahawkSettings.h" #include "Account.h" +#include namespace Tomahawk { @@ -37,6 +38,8 @@ public: virtual ~ConfigStorage(); + virtual void init() = 0; + virtual QString id() const = 0; virtual QStringList accountIds() const = 0; @@ -52,4 +55,6 @@ signals: } //namespace Accounts } //namespace Tomahawk +Q_DECLARE_METATYPE( QSharedPointer< Tomahawk::Accounts::ConfigStorage > ) + #endif // CONFIGSTORAGE_H diff --git a/src/libtomahawk/accounts/LocalConfigStorage.cpp b/src/libtomahawk/accounts/LocalConfigStorage.cpp index 878e722cd..254ac1c79 100644 --- a/src/libtomahawk/accounts/LocalConfigStorage.cpp +++ b/src/libtomahawk/accounts/LocalConfigStorage.cpp @@ -35,7 +35,12 @@ LocalConfigStorage::LocalConfigStorage( QObject* parent ) , m_credentialsServiceName( "Tomahawk" ) { m_accountIds = TomahawkSettings::instance()->accounts(); +} + +void +LocalConfigStorage::init() +{ // tell CredentialsManager which account ids it will be writing credentials for and in which svc CredentialsManager* cm = AccountManager::instance()->credentialsManager(); diff --git a/src/libtomahawk/accounts/LocalConfigStorage.h b/src/libtomahawk/accounts/LocalConfigStorage.h index 3540bebd9..4303c463f 100644 --- a/src/libtomahawk/accounts/LocalConfigStorage.h +++ b/src/libtomahawk/accounts/LocalConfigStorage.h @@ -33,6 +33,8 @@ class LocalConfigStorage : public ConfigStorage public: explicit LocalConfigStorage( QObject* parent = 0 ); + virtual void init(); + QString id() const { return "localconfigstorage"; } QStringList accountIds() const; diff --git a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp index ecae779bf..e6420230f 100644 --- a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp +++ b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp @@ -36,11 +36,17 @@ TelepathyConfigStorage::TelepathyConfigStorage( QObject* parent ) , m_credentialsServiceName( "telepathy-kde" ) { tDebug() << Q_FUNC_INFO; +} + +void +TelepathyConfigStorage::init() +{ // 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 ); + emit ready(); } diff --git a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.h b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.h index c85df045c..df83532b0 100644 --- a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.h +++ b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.h @@ -34,6 +34,8 @@ class CONFIGSTORAGEDLLEXPORT TelepathyConfigStorage : public ConfigStorage public: explicit TelepathyConfigStorage( QObject* parent = 0 ); + void init(); + QString id() const { return "telepathyconfigstorage"; } QStringList accountIds() const;