Akonadi

agentconfigurationmanager.cpp
1 /*
2  Copyright (c) 2018 Daniel Vrátil <[email protected]>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 */
19 
20 #include "agentconfigurationmanager_p.h"
21 #include "akonadicore_debug.h"
22 #include "servermanager.h"
23 
24 #include <QDBusConnectionInterface>
25 #include <QCoreApplication>
26 #include <QPluginLoader>
27 #include <QDir>
28 
29 #include <QDBusConnection>
30 
31 namespace Akonadi {
32 class Q_DECL_HIDDEN AgentConfigurationManager::Private {
33 public:
34  QString serviceName(const QString &instance) const
35  {
36  QString service = QStringLiteral("org.freedesktop.Akonadi.AgentConfig.%1").arg(instance);
37  if (ServerManager::self()->hasInstanceIdentifier()) {
38  service += QLatin1Char('.') + ServerManager::self()->instanceIdentifier();
39  }
40  return service;
41  }
42 };
43 }
44 
45 using namespace Akonadi;
46 
47 AgentConfigurationManager *AgentConfigurationManager::sInstance = nullptr;
48 
49 AgentConfigurationManager::AgentConfigurationManager(QObject *parent)
50  : QObject(parent)
51 {
52 }
53 
54 AgentConfigurationManager *AgentConfigurationManager::self()
55 {
56  if (sInstance == nullptr) {
57  sInstance = new AgentConfigurationManager();
58  }
59  return sInstance;
60 }
61 
62 AgentConfigurationManager::~AgentConfigurationManager()
63 {
64 }
65 
66 bool AgentConfigurationManager::registerInstanceConfiguration(const QString &instance)
67 {
68  const auto serviceName = d->serviceName(instance);
70  if (conn.interface()->isServiceRegistered(serviceName)) {
71  qCDebug(AKONADICORE_LOG) << "Service " << serviceName << " is already registered";
72  return false;
73  }
74 
75  return conn.registerService(serviceName);
76 }
77 
78 void AgentConfigurationManager::unregisterInstanceConfiguration(const QString &instance)
79 {
80  const auto serviceName = d->serviceName(instance);
82 }
83 
84 bool AgentConfigurationManager::isInstanceRegistered(const QString &instance) const
85 {
86  const auto serviceName = d->serviceName(instance);
88 }
89 
90 QString AgentConfigurationManager::findConfigPlugin(const QString &type) const
91 {
92  const auto libPaths = QCoreApplication::libraryPaths();
93  for (const auto &libPath : libPaths) {
94  const QString pluginPath = QStringLiteral("%1/akonadi/config/").arg(libPath);
95  const auto libs = QDir(pluginPath).entryInfoList(QDir::Files | QDir::NoDotAndDotDot);
96  for (const auto &lib : libs) {
97  QPluginLoader loader(lib.absoluteFilePath());
98  const auto metaData = loader.metaData().toVariantMap();
99  if (metaData.value(QStringLiteral("IID")).toString() != QLatin1String("org.freedesktop.Akonadi.AgentConfig")) {
100  continue;
101  }
102  const auto md = metaData.value(QStringLiteral("MetaData")).toMap();
103  if (md.value(QStringLiteral("X-Akonadi-PluginType")).toString() != QLatin1String("AgentConfig")) {
104  continue;
105  }
106  if (!type.startsWith(md.value(QStringLiteral("X-Akonadi-AgentConfig-Type")).toString())) {
107  continue;
108  }
109  return loader.fileName();
110  }
111  }
112 
113  return {};
114 }
static QString instanceIdentifier()
Returns the identifier of the Akonadi instance we are connected to.
QDBusConnectionInterface * interface() const const
QVariantMap toVariantMap() const const
static ServerManager * self()
Returns the singleton instance of this class, for connecting to its signals.
QDBusConnection sessionBus()
QJsonObject metaData() const const
QDBusReply< bool > isServiceRegistered(const QString &serviceName) const const
QFileInfoList entryInfoList(QDir::Filters filters, QDir::SortFlags sort) const const
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const const
bool unregisterService(const QString &serviceName)
QStringList libraryPaths()
Helper integration between Akonadi and Qt.
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
bool registerService(const QString &serviceName)
const T value(const Key &key, const T &defaultValue) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon May 25 2020 22:46:07 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.