mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-17 11:30:49 +02:00
Load TelepathyConfigStorage plugin.
This commit is contained in:
@@ -34,10 +34,10 @@
|
|||||||
#include "TomahawkSettings.h"
|
#include "TomahawkSettings.h"
|
||||||
#include "LocalConfigStorage.h"
|
#include "LocalConfigStorage.h"
|
||||||
|
|
||||||
#include <QtCore/QLibrary>
|
#include <QLibrary>
|
||||||
#include <QtCore/QDir>
|
#include <QDir>
|
||||||
#include <QtCore/QPluginLoader>
|
#include <QPluginLoader>
|
||||||
#include <QtCore/QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
@@ -101,10 +101,9 @@ AccountManager::init()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QStringList
|
QList< QDir >
|
||||||
AccountManager::findPluginFactories()
|
AccountManager::findPluginDirs() const
|
||||||
{
|
{
|
||||||
QStringList paths;
|
|
||||||
QList< QDir > pluginDirs;
|
QList< QDir > pluginDirs;
|
||||||
|
|
||||||
QDir appDir( qApp->applicationDirPath() );
|
QDir appDir( qApp->applicationDirPath() );
|
||||||
@@ -125,10 +124,21 @@ AccountManager::findPluginFactories()
|
|||||||
lib64Dir.cd( "lib64" );
|
lib64Dir.cd( "lib64" );
|
||||||
|
|
||||||
pluginDirs << appDir << libDir << lib64Dir << QDir( qApp->applicationDirPath() );
|
pluginDirs << appDir << libDir << lib64Dir << QDir( qApp->applicationDirPath() );
|
||||||
foreach ( const QDir& pluginDir, pluginDirs )
|
return pluginDirs;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QStringList
|
||||||
|
AccountManager::findPluginFactories()
|
||||||
|
{
|
||||||
|
QStringList paths;
|
||||||
|
|
||||||
|
foreach ( const QDir& pluginDir, findPluginDirs() )
|
||||||
{
|
{
|
||||||
tDebug() << Q_FUNC_INFO << "Checking directory for plugins:" << pluginDir;
|
tDebug() << Q_FUNC_INFO << "Checking directory for account plugins:" << pluginDir;
|
||||||
foreach ( QString fileName, pluginDir.entryList( QStringList() << "*tomahawk_account_*.so" << "*tomahawk_account_*.dylib" << "*tomahawk_account_*.dll", QDir::Files ) )
|
foreach ( QString fileName, pluginDir.entryList( QStringList() << "*tomahawk_account_*.so"
|
||||||
|
<< "*tomahawk_account_*.dylib"
|
||||||
|
<< "*tomahawk_account_*.dll", QDir::Files ) )
|
||||||
{
|
{
|
||||||
if ( fileName.startsWith( "libtomahawk_account" ) )
|
if ( fileName.startsWith( "libtomahawk_account" ) )
|
||||||
{
|
{
|
||||||
@@ -143,6 +153,33 @@ AccountManager::findPluginFactories()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QStringList
|
||||||
|
AccountManager::findConfigStoragePlugins()
|
||||||
|
{
|
||||||
|
QStringList paths;
|
||||||
|
|
||||||
|
foreach( const QDir& pluginDir, findPluginDirs() )
|
||||||
|
{
|
||||||
|
tDebug() << Q_FUNC_INFO << "Checking directory for ConfigStorage plugins:" << pluginDir;
|
||||||
|
foreach ( QString fileName, pluginDir.entryList( QStringList() << "*tomahawk_configstorage_*.so"
|
||||||
|
<< "*tomahawk_configstorage_*.dylib"
|
||||||
|
<< "*tomahawk_configstorage_*.dll", QDir::Files ) )
|
||||||
|
{
|
||||||
|
if ( fileName.startsWith( "libtomahawk_configstorage" ) )
|
||||||
|
{
|
||||||
|
const QString path = pluginDir.absoluteFilePath( fileName );
|
||||||
|
if ( !paths.contains( path ) )
|
||||||
|
paths << path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tDebug() << Q_FUNC_INFO << "ConfigStorage plugin file paths:" << paths;
|
||||||
|
|
||||||
|
return paths;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
AccountManager::loadPluginFactories( const QStringList& paths )
|
AccountManager::loadPluginFactories( const QStringList& paths )
|
||||||
{
|
{
|
||||||
@@ -288,31 +325,50 @@ AccountManager::loadFromConfig()
|
|||||||
{
|
{
|
||||||
m_creds = new CredentialsManager( this );
|
m_creds = new CredentialsManager( this );
|
||||||
|
|
||||||
QSharedPointer< ConfigStorage > configStorage;
|
ConfigStorage* localCS = new LocalConfigStorage( this );
|
||||||
configStorage = QSharedPointer< ConfigStorage >( new LocalConfigStorage( this ) );
|
m_configStorageById.insert( localCS->id(), localCS );
|
||||||
m_configStorageById.insert( configStorage->id(), configStorage );
|
|
||||||
|
|
||||||
|
QStringList configStoragePlugins = findConfigStoragePlugins();
|
||||||
|
foreach( const QString& pluginPath, configStoragePlugins )
|
||||||
|
{
|
||||||
|
QPluginLoader loader;
|
||||||
|
if ( !QLibrary::isLibrary( pluginPath ) )
|
||||||
|
continue;
|
||||||
|
|
||||||
foreach ( const QSharedPointer< ConfigStorage >& cs, m_configStorageById )
|
loader.setFileName( pluginPath );
|
||||||
|
if ( !loader.load() )
|
||||||
|
{
|
||||||
|
tDebug() << "Error loading ConfigStorage plugin" << loader.errorString() << loader.staticInstances().count();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ConfigStorage* cs = qobject_cast< ConfigStorage* >( loader.instance() );
|
||||||
|
if ( !cs )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
m_configStorageById.insert( cs->id(), cs );
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ( ConfigStorage* cs, m_configStorageById )
|
||||||
{
|
{
|
||||||
m_configStorageLoading.insert( cs->id() );
|
m_configStorageLoading.insert( cs->id() );
|
||||||
NewClosure( cs.data(), SIGNAL( ready() ),
|
NewClosure( cs, SIGNAL( ready() ),
|
||||||
this, SLOT( finishLoadingFromConfig( QSharedPointer< ConfigStorage > ) ), cs );
|
this, SLOT( finishLoadingFromConfig( QString ) ), cs->id() );
|
||||||
cs->init();
|
cs->init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
AccountManager::finishLoadingFromConfig( const QSharedPointer< ConfigStorage >& cs )
|
AccountManager::finishLoadingFromConfig( const QString& csid )
|
||||||
{
|
{
|
||||||
if ( m_configStorageLoading.contains( cs->id() ) )
|
if ( m_configStorageLoading.contains( csid ) )
|
||||||
m_configStorageLoading.remove( cs->id() );
|
m_configStorageLoading.remove( csid );
|
||||||
|
|
||||||
if ( !m_configStorageLoading.isEmpty() )
|
if ( !m_configStorageLoading.isEmpty() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
foreach ( const QSharedPointer< ConfigStorage >& cs, m_configStorageById )
|
foreach ( const ConfigStorage* cs, m_configStorageById )
|
||||||
{
|
{
|
||||||
QStringList accountIds = cs->accountIds();
|
QStringList accountIds = cs->accountIds();
|
||||||
|
|
||||||
@@ -466,15 +522,15 @@ AccountManager::zeroconfAccount() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QSharedPointer< ConfigStorage >
|
ConfigStorage*
|
||||||
AccountManager::configStorageForAccount( const QString& accountId )
|
AccountManager::configStorageForAccount( const QString& accountId )
|
||||||
{
|
{
|
||||||
foreach ( const QSharedPointer< ConfigStorage >& cs, m_configStorageById )
|
foreach ( ConfigStorage* cs, m_configStorageById )
|
||||||
{
|
{
|
||||||
if ( cs->accountIds().contains( accountId ) )
|
if ( cs->accountIds().contains( accountId ) )
|
||||||
return cs;
|
return cs;
|
||||||
}
|
}
|
||||||
return QSharedPointer< ConfigStorage >();
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -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; }
|
||||||
QSharedPointer< ConfigStorage > configStorageForAccount( const QString& accountId );
|
ConfigStorage* configStorageForAccount( const QString& accountId );
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void connectAll();
|
void connectAll();
|
||||||
@@ -120,16 +120,20 @@ 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( const QSharedPointer< ConfigStorage >& cs );
|
void finishLoadingFromConfig( const QString& cs );
|
||||||
|
|
||||||
void onSettingsChanged();
|
void onSettingsChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QList< QDir > findPluginDirs() const;
|
||||||
|
|
||||||
QStringList findPluginFactories();
|
QStringList findPluginFactories();
|
||||||
void loadPluginFactories( const QStringList &paths );
|
void loadPluginFactories( const QStringList &paths );
|
||||||
void loadPluginFactory( const QString &path );
|
void loadPluginFactory( const QString &path );
|
||||||
QString factoryFromId( const QString& accountId ) const;
|
QString factoryFromId( const QString& accountId ) const;
|
||||||
|
|
||||||
|
QStringList findConfigStoragePlugins();
|
||||||
|
|
||||||
Account* loadPlugin( const QString& accountId );
|
Account* loadPlugin( const QString& accountId );
|
||||||
void hookupAccount( Account* ) const;
|
void hookupAccount( Account* ) const;
|
||||||
|
|
||||||
@@ -146,7 +150,7 @@ private:
|
|||||||
QHash< QString, AccountFactory* > m_accountFactories;
|
QHash< QString, AccountFactory* > m_accountFactories;
|
||||||
QList< AccountFactory* > m_factoriesForFilesytem;
|
QList< AccountFactory* > m_factoriesForFilesytem;
|
||||||
|
|
||||||
QMap< QString, QSharedPointer< ConfigStorage > > m_configStorageById;
|
QHash< QString, ConfigStorage* > m_configStorageById;
|
||||||
QSet< QString > m_configStorageLoading;
|
QSet< QString > m_configStorageLoading;
|
||||||
|
|
||||||
static AccountManager* s_instance;
|
static AccountManager* s_instance;
|
||||||
|
@@ -55,6 +55,6 @@ signals:
|
|||||||
} //namespace Accounts
|
} //namespace Accounts
|
||||||
} //namespace Tomahawk
|
} //namespace Tomahawk
|
||||||
|
|
||||||
Q_DECLARE_METATYPE( QSharedPointer< Tomahawk::Accounts::ConfigStorage > )
|
Q_DECLARE_INTERFACE( Tomahawk::Accounts::ConfigStorage, "tomahawk.ConfigStorage/1.0" )
|
||||||
|
|
||||||
#endif // CONFIGSTORAGE_H
|
#endif // CONFIGSTORAGE_H
|
||||||
|
@@ -23,6 +23,8 @@
|
|||||||
#include "accounts/CredentialsManager.h"
|
#include "accounts/CredentialsManager.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
|
|
||||||
namespace Tomahawk
|
namespace Tomahawk
|
||||||
{
|
{
|
||||||
@@ -46,7 +48,7 @@ TelepathyConfigStorage::init()
|
|||||||
// 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();
|
QTimer::singleShot( 0, this, SIGNAL( ready() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -118,3 +120,5 @@ TelepathyConfigStorage::remove( const QString& accountId )
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Q_EXPORT_PLUGIN2( Tomahawk::Accounts::ConfigStorage, Tomahawk::Accounts::TelepathyConfigStorage )
|
||||||
|
@@ -31,6 +31,7 @@ namespace Accounts
|
|||||||
class CONFIGSTORAGEDLLEXPORT TelepathyConfigStorage : public ConfigStorage
|
class CONFIGSTORAGEDLLEXPORT TelepathyConfigStorage : public ConfigStorage
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
Q_INTERFACES( Tomahawk::Accounts::ConfigStorage )
|
||||||
public:
|
public:
|
||||||
explicit TelepathyConfigStorage( QObject* parent = 0 );
|
explicit TelepathyConfigStorage( QObject* parent = 0 );
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user