mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-05-04 23:28:58 +02:00
Asyncify ConfigStorage loading, and allow multiple ConfigStorages.
This commit is contained in:
parent
08158ca405
commit
ebd7091fda
@ -38,6 +38,7 @@
|
||||
#include <QtCore/QDir>
|
||||
#include <QtCore/QPluginLoader>
|
||||
#include <QtCore/QCoreApplication>
|
||||
#include <QSet>
|
||||
#include <QTimer>
|
||||
|
||||
|
||||
@ -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 >();
|
||||
}
|
||||
|
||||
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "TomahawkSettings.h"
|
||||
#include "Account.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
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
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user