• Skip to content
  • Skip to link menu
  • KDE API Reference
  • KDE Home
  • Contact Us
 

Nepomuk-Core

  • KTp
message-filter-config-manager.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Lasath Fernando <kde@lasath.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 "message-filter-config-manager.h"
20 #include "version.h"
21 
22 #include <QMutex>
23 #include <QSet>
24 
25 #include <KGlobal>
26 #include <KDebug>
27 #include <KServiceTypeTrader>
28 
29 typedef QSet<KPluginInfo> PluginSet;
30 
31 using namespace KTp;
32 
33 class MessageFilterConfigManager::Private
34 {
35  public:
36  Private(MessageFilterConfigManager *parent):
37  q(parent)
38  { }
39 
40  PluginSet all;
41  PluginSet enabled;
42 
43  KService::List offers() const;
44  void generateCache();
45 
46  private:
47  MessageFilterConfigManager *q;
48 };
49 
50 KService::List MessageFilterConfigManager::Private::offers() const
51 {
52  return KServiceTypeTrader::self()->query(QLatin1String("KTpTextUi/MessageFilter"),
53  QLatin1String("[X-KTp-PluginInfo-Version] == " KTP_MESSAGE_FILTER_FRAMEWORK_VERSION));
54 }
55 
56 
57 void MessageFilterConfigManager::Private::generateCache()
58 {
59  KPluginInfo::List pluginInfos = KPluginInfo::fromServices(offers(), q->configGroup());
60  for (KPluginInfo::List::Iterator i = pluginInfos.begin(); i != pluginInfos.end(); i++) {
61  KPluginInfo &plugin = *i;
62 
63  all.insert(plugin);
64 
65  plugin.load();
66  if (plugin.isPluginEnabled()) {
67  enabled.insert(plugin);
68  }
69  }
70 }
71 
72 MessageFilterConfigManager *MessageFilterConfigManager::self()
73 {
74  static MessageFilterConfigManager *mfcm_instance;
75  static QMutex mutex;
76  mutex.lock();
77  if (!mfcm_instance) {
78  mfcm_instance = new MessageFilterConfigManager;
79  }
80  mutex.unlock();
81 
82  return mfcm_instance;
83 }
84 
85 MessageFilterConfigManager::MessageFilterConfigManager() :
86  d(new Private(this))
87 {
88  d->generateCache();
89 }
90 
91 MessageFilterConfigManager::~MessageFilterConfigManager()
92 {
93  delete d;
94 }
95 
96 KPluginInfo::List MessageFilterConfigManager::allPlugins() const
97 {
98  return d->all.toList();
99 }
100 
101 KPluginInfo::List MessageFilterConfigManager::enabledPlugins() const
102 {
103  return d->enabled.toList();
104 }
105 
106 KConfigGroup MessageFilterConfigManager::configGroup() const
107 {
108  return sharedConfig()->group("Plugins");
109 }
110 
111 KSharedConfig::Ptr MessageFilterConfigManager::sharedConfig() const
112 {
113  return KSharedConfig::openConfig(QLatin1String("ktelepathyrc"));
114 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Fri Mar 22 2013 10:58:52 by doxygen 1.8.1.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

ktp-common-internals API Reference

Skip menu "ktp-common-internals API Reference"
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