19 #include "personpluginmanager_p.h"
20 #include "backends/basepersonsdatasource.h"
23 #include <KServiceTypeTrader>
24 #include <KPluginInfo>
31 class PersonPluginManagerPrivate
34 PersonPluginManagerPrivate();
35 ~PersonPluginManagerPrivate();
36 QHash<QString , BasePersonsDataSource *> dataSourcePlugins;
38 void loadDataSourcePlugins();
39 bool m_loadedDataSourcePlugins;
44 Q_GLOBAL_STATIC(PersonPluginManagerPrivate, s_instance);
46 PersonPluginManagerPrivate::PersonPluginManagerPrivate():
47 m_loadedDataSourcePlugins(false)
51 PersonPluginManagerPrivate::~PersonPluginManagerPrivate()
53 qDeleteAll(dataSourcePlugins);
56 void PersonPluginManagerPrivate::loadDataSourcePlugins()
58 KService::List pluginList = KServiceTypeTrader::self()->query(QLatin1String(
"KPeople/DataSource"));
59 Q_FOREACH (
const KService::Ptr &service, pluginList) {
60 BasePersonsDataSource *dataSource = service->createInstance<BasePersonsDataSource>(0);
62 dataSourcePlugins[dataSource->sourcePluginId()] = dataSource;
64 qWarning() <<
"Failed to create data source " << service->name() << service->path();
67 m_loadedDataSourcePlugins =
true;
70 void PersonPluginManager::setDataSourcePlugins(
const QHash<QString, BasePersonsDataSource * > &dataSources)
72 s_instance->m_mutex.lock();
73 qDeleteAll(s_instance->dataSourcePlugins);
74 s_instance->dataSourcePlugins = dataSources;
75 s_instance->m_loadedDataSourcePlugins =
true;
76 s_instance->m_mutex.unlock();
79 QList<BasePersonsDataSource *> PersonPluginManager::dataSourcePlugins()
81 s_instance->m_mutex.lock();
82 if (!s_instance->m_loadedDataSourcePlugins) {
83 s_instance->loadDataSourcePlugins();
85 s_instance->m_mutex.unlock();
86 return s_instance->dataSourcePlugins.values();
89 BasePersonsDataSource *PersonPluginManager::dataSource(
const QString &sourceId)
91 s_instance->m_mutex.lock();
92 if (!s_instance->m_loadedDataSourcePlugins) {
93 s_instance->loadDataSourcePlugins();
95 s_instance->m_mutex.unlock();
97 return s_instance->dataSourcePlugins.value(sourceId);
The KPeople namespace contains all the classes for Libkpeople.