mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-07-31 19:30:21 +02:00
Asyncify ConfigStorage loading, and allow multiple ConfigStorages.
This commit is contained in:
@@ -38,6 +38,7 @@
|
|||||||
#include <QtCore/QDir>
|
#include <QtCore/QDir>
|
||||||
#include <QtCore/QPluginLoader>
|
#include <QtCore/QPluginLoader>
|
||||||
#include <QtCore/QCoreApplication>
|
#include <QtCore/QCoreApplication>
|
||||||
|
#include <QSet>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
|
|
||||||
@@ -287,19 +288,31 @@ AccountManager::loadFromConfig()
|
|||||||
{
|
{
|
||||||
m_creds = new CredentialsManager( this );
|
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 );
|
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() ),
|
foreach ( const QSharedPointer< ConfigStorage >& cs, m_configStorageById )
|
||||||
this, SLOT( finishLoadingFromConfig() ) );
|
{
|
||||||
|
m_configStorageLoading.insert( cs->id() );
|
||||||
|
NewClosure( cs.data(), SIGNAL( ready() ),
|
||||||
|
this, SLOT( finishLoadingFromConfig( QSharedPointer< ConfigStorage > ) ), cs );
|
||||||
|
cs->init();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
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();
|
QStringList accountIds = cs->accountIds();
|
||||||
|
|
||||||
@@ -453,15 +466,15 @@ AccountManager::zeroconfAccount() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ConfigStorage*
|
QSharedPointer< ConfigStorage >
|
||||||
AccountManager::configStorageForAccount( const QString& accountId )
|
AccountManager::configStorageForAccount( const QString& accountId )
|
||||||
{
|
{
|
||||||
foreach ( ConfigStorage* cs, m_configStorageById )
|
foreach ( const QSharedPointer< ConfigStorage >& cs, m_configStorageById )
|
||||||
{
|
{
|
||||||
if ( cs->accountIds().contains( accountId ) )
|
if ( cs->accountIds().contains( accountId ) )
|
||||||
return cs;
|
return cs;
|
||||||
}
|
}
|
||||||
return 0;
|
return QSharedPointer< ConfigStorage >();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -95,7 +95,7 @@ public:
|
|||||||
bool isReady() const { return m_completelyReady; }
|
bool isReady() const { return m_completelyReady; }
|
||||||
|
|
||||||
CredentialsManager* credentialsManager() const { return m_creds; }
|
CredentialsManager* credentialsManager() const { return m_creds; }
|
||||||
ConfigStorage* configStorageForAccount( const QString& accountId );
|
QSharedPointer< ConfigStorage > configStorageForAccount( const QString& accountId );
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void connectAll();
|
void connectAll();
|
||||||
@@ -120,7 +120,7 @@ private slots:
|
|||||||
void init();
|
void init();
|
||||||
void onStateChanged( Tomahawk::Accounts::Account::ConnectionState state );
|
void onStateChanged( Tomahawk::Accounts::Account::ConnectionState state );
|
||||||
void onError( int code, const QString& msg );
|
void onError( int code, const QString& msg );
|
||||||
void finishLoadingFromConfig();
|
void finishLoadingFromConfig( const QSharedPointer< ConfigStorage >& cs );
|
||||||
|
|
||||||
void onSettingsChanged();
|
void onSettingsChanged();
|
||||||
|
|
||||||
@@ -146,7 +146,8 @@ private:
|
|||||||
QHash< QString, AccountFactory* > m_accountFactories;
|
QHash< QString, AccountFactory* > m_accountFactories;
|
||||||
QList< AccountFactory* > m_factoriesForFilesytem;
|
QList< AccountFactory* > m_factoriesForFilesytem;
|
||||||
|
|
||||||
QMap< QString, ConfigStorage* > m_configStorageById;
|
QMap< QString, QSharedPointer< ConfigStorage > > m_configStorageById;
|
||||||
|
QSet< QString > m_configStorageLoading;
|
||||||
|
|
||||||
static AccountManager* s_instance;
|
static AccountManager* s_instance;
|
||||||
};
|
};
|
||||||
|
@@ -22,6 +22,7 @@
|
|||||||
#include "TomahawkSettings.h"
|
#include "TomahawkSettings.h"
|
||||||
#include "Account.h"
|
#include "Account.h"
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
namespace Tomahawk
|
namespace Tomahawk
|
||||||
{
|
{
|
||||||
@@ -37,6 +38,8 @@ public:
|
|||||||
|
|
||||||
virtual ~ConfigStorage();
|
virtual ~ConfigStorage();
|
||||||
|
|
||||||
|
virtual void init() = 0;
|
||||||
|
|
||||||
virtual QString id() const = 0;
|
virtual QString id() const = 0;
|
||||||
|
|
||||||
virtual QStringList accountIds() const = 0;
|
virtual QStringList accountIds() const = 0;
|
||||||
@@ -52,4 +55,6 @@ signals:
|
|||||||
} //namespace Accounts
|
} //namespace Accounts
|
||||||
} //namespace Tomahawk
|
} //namespace Tomahawk
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE( QSharedPointer< Tomahawk::Accounts::ConfigStorage > )
|
||||||
|
|
||||||
#endif // CONFIGSTORAGE_H
|
#endif // CONFIGSTORAGE_H
|
||||||
|
@@ -35,7 +35,12 @@ LocalConfigStorage::LocalConfigStorage( QObject* parent )
|
|||||||
, m_credentialsServiceName( "Tomahawk" )
|
, m_credentialsServiceName( "Tomahawk" )
|
||||||
{
|
{
|
||||||
m_accountIds = TomahawkSettings::instance()->accounts();
|
m_accountIds = TomahawkSettings::instance()->accounts();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
LocalConfigStorage::init()
|
||||||
|
{
|
||||||
// tell CredentialsManager which account ids it will be writing credentials for and in which svc
|
// tell CredentialsManager which account ids it will be writing credentials for and in which svc
|
||||||
|
|
||||||
CredentialsManager* cm = AccountManager::instance()->credentialsManager();
|
CredentialsManager* cm = AccountManager::instance()->credentialsManager();
|
||||||
|
@@ -33,6 +33,8 @@ class LocalConfigStorage : public ConfigStorage
|
|||||||
public:
|
public:
|
||||||
explicit LocalConfigStorage( QObject* parent = 0 );
|
explicit LocalConfigStorage( QObject* parent = 0 );
|
||||||
|
|
||||||
|
virtual void init();
|
||||||
|
|
||||||
QString id() const { return "localconfigstorage"; }
|
QString id() const { return "localconfigstorage"; }
|
||||||
|
|
||||||
QStringList accountIds() const;
|
QStringList accountIds() const;
|
||||||
|
@@ -36,11 +36,17 @@ TelepathyConfigStorage::TelepathyConfigStorage( QObject* parent )
|
|||||||
, m_credentialsServiceName( "telepathy-kde" )
|
, m_credentialsServiceName( "telepathy-kde" )
|
||||||
{
|
{
|
||||||
tDebug() << Q_FUNC_INFO;
|
tDebug() << Q_FUNC_INFO;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TelepathyConfigStorage::init()
|
||||||
|
{
|
||||||
// tell CredentialsManager which account ids it will be writing credentials for and in which svc
|
// 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()
|
// so it can preload them when we call CM::loadCredentials()
|
||||||
AccountManager::instance()->credentialsManager()->addService( m_credentialsServiceName,
|
AccountManager::instance()->credentialsManager()->addService( m_credentialsServiceName,
|
||||||
m_accountIds );
|
m_accountIds );
|
||||||
|
emit ready();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -34,6 +34,8 @@ class CONFIGSTORAGEDLLEXPORT TelepathyConfigStorage : public ConfigStorage
|
|||||||
public:
|
public:
|
||||||
explicit TelepathyConfigStorage( QObject* parent = 0 );
|
explicit TelepathyConfigStorage( QObject* parent = 0 );
|
||||||
|
|
||||||
|
void init();
|
||||||
|
|
||||||
QString id() const { return "telepathyconfigstorage"; }
|
QString id() const { return "telepathyconfigstorage"; }
|
||||||
|
|
||||||
QStringList accountIds() const;
|
QStringList accountIds() const;
|
||||||
|
Reference in New Issue
Block a user