• Skip to content
  • Skip to link menu
KDE API Documentation - personpluginmanager.cpp Source File (KPeople)
  • KDE Home
  • Contact Us
 

KPeople

  • frameworks
  • kpeople
  • src
personpluginmanager.cpp
1 /*
2  Copyright (C) 2013 David Edmundson <davidedmundson@kde.org>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License as published by the Free Software Foundation; either
7  version 2.1 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public
15  License along with this library; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #include "personpluginmanager_p.h"
20 #include "backends/basepersonsdatasource.h"
21 
22 #include <KService>
23 #include <KServiceTypeTrader>
24 #include <KPluginInfo>
25 
26 #include <QMutex>
27 #include <QDebug>
28 
29 using namespace KPeople;
30 
31 class PersonPluginManagerPrivate
32 {
33 public:
34  PersonPluginManagerPrivate();
35  ~PersonPluginManagerPrivate();
36  QHash<QString /* SourceName*/, BasePersonsDataSource *> dataSourcePlugins;
37 
38  void loadDataSourcePlugins();
39  bool m_loadedDataSourcePlugins;
40  QMutex m_mutex;
41 
42 };
43 
44 Q_GLOBAL_STATIC(PersonPluginManagerPrivate, s_instance);
45 
46 PersonPluginManagerPrivate::PersonPluginManagerPrivate():
47  m_loadedDataSourcePlugins(false)
48 {
49 }
50 
51 PersonPluginManagerPrivate::~PersonPluginManagerPrivate()
52 {
53  qDeleteAll(dataSourcePlugins);
54 }
55 
56 void PersonPluginManagerPrivate::loadDataSourcePlugins()
57 {
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);
61  if (dataSource) {
62  dataSourcePlugins[dataSource->sourcePluginId()] = dataSource;
63  } else {
64  qWarning() << "Failed to create data source " << service->name() << service->path();
65  }
66  }
67  m_loadedDataSourcePlugins = true;
68 }
69 
70 void PersonPluginManager::setDataSourcePlugins(const QHash<QString, BasePersonsDataSource * > &dataSources)
71 {
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();
77 }
78 
79 QList<BasePersonsDataSource *> PersonPluginManager::dataSourcePlugins()
80 {
81  s_instance->m_mutex.lock();
82  if (!s_instance->m_loadedDataSourcePlugins) {
83  s_instance->loadDataSourcePlugins();
84  }
85  s_instance->m_mutex.unlock();
86  return s_instance->dataSourcePlugins.values();
87 }
88 
89 BasePersonsDataSource *PersonPluginManager::dataSource(const QString &sourceId)
90 {
91  s_instance->m_mutex.lock();
92  if (!s_instance->m_loadedDataSourcePlugins) {
93  s_instance->loadDataSourcePlugins();
94  }
95  s_instance->m_mutex.unlock();
96 
97  return s_instance->dataSourcePlugins.value(sourceId);
98 }
KPeople
The KPeople namespace contains all the classes for Libkpeople.
This file is part of the KDE documentation.
Documentation copyright © 1996-2015 The KDE developers.
Generated on Fri Feb 13 2015 15:16:39 by doxygen 1.8.9.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KPeople

Skip menu "KPeople"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • File List

Class Picker

Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal