Akonadi

agentconfigurationmanager.cpp
1 /*
2  SPDX-FileCopyrightText: 2018 Daniel Vr├ítil <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "agentconfigurationmanager_p.h"
8 #include "akonadicore_debug.h"
9 #include "servermanager.h"
10 
11 #include <QCoreApplication>
12 #include <QDBusConnectionInterface>
13 #include <QDir>
14 #include <QPluginLoader>
15 
16 #include <QDBusConnection>
17 
18 namespace Akonadi
19 {
20 class AgentConfigurationManagerPrivate
21 {
22 public:
23  QString serviceName(const QString &instance) const
24  {
25  QString service = QStringLiteral("org.freedesktop.Akonadi.AgentConfig.%1").arg(instance);
26  if (ServerManager::self()->hasInstanceIdentifier()) {
27  service += QLatin1Char('.') + ServerManager::self()->instanceIdentifier();
28  }
29  return service;
30  }
31 };
32 } // namespace Akonadi
33 
34 using namespace Akonadi;
35 
36 AgentConfigurationManager *AgentConfigurationManager::sInstance = nullptr;
37 
38 AgentConfigurationManager::AgentConfigurationManager(QObject *parent)
39  : QObject(parent)
40 {
41 }
42 
43 AgentConfigurationManager *AgentConfigurationManager::self()
44 {
45  if (sInstance == nullptr) {
46  sInstance = new AgentConfigurationManager();
47  }
48  return sInstance;
49 }
50 
51 AgentConfigurationManager::~AgentConfigurationManager()
52 {
53 }
54 
55 bool AgentConfigurationManager::registerInstanceConfiguration(const QString &instance)
56 {
57  const auto serviceName = d->serviceName(instance);
59  if (conn.interface()->isServiceRegistered(serviceName)) {
60  qCDebug(AKONADICORE_LOG) << "Service " << serviceName << " is already registered";
61  return false;
62  }
63 
64  return conn.registerService(serviceName);
65 }
66 
67 void AgentConfigurationManager::unregisterInstanceConfiguration(const QString &instance)
68 {
69  const auto serviceName = d->serviceName(instance);
71 }
72 
73 bool AgentConfigurationManager::isInstanceRegistered(const QString &instance) const
74 {
75  const auto serviceName = d->serviceName(instance);
77 }
78 
79 QString AgentConfigurationManager::findConfigPlugin(const QString &type) const
80 {
81  const auto libPaths = QCoreApplication::libraryPaths();
82  const QString prefixPluginPath = QStringLiteral("pim" QT_STRINGIFY(QT_VERSION_MAJOR)) + QStringLiteral("/akonadi/config");
83  for (const auto &libPath : libPaths) {
84  const QString pluginPath = QStringLiteral("%1/%2/").arg(libPath, prefixPluginPath);
85  const auto libs = QDir(pluginPath).entryInfoList(QDir::Files | QDir::NoDotAndDotDot);
86  for (const auto &lib : libs) {
87  QPluginLoader loader(lib.absoluteFilePath());
88  const auto metaData = loader.metaData().toVariantMap();
89  if (metaData.value(QStringLiteral("IID")).toString() != QLatin1String("org.freedesktop.Akonadi.AgentConfig")) {
90  continue;
91  }
92  const auto md = metaData.value(QStringLiteral("MetaData")).toMap();
93  if (md.value(QStringLiteral("X-Akonadi-PluginType")).toString() != QLatin1String("AgentConfig")) {
94  continue;
95  }
96  if (!type.startsWith(md.value(QStringLiteral("X-Akonadi-AgentConfig-Type")).toString())) {
97  continue;
98  }
99  return loader.fileName();
100  }
101  }
102 
103  return {};
104 }
static ServerManager * self()
Returns the singleton instance of this class, for connecting to its signals.
QDBusReply< bool > isServiceRegistered(const QString &serviceName) const const
QStringList libraryPaths()
QDBusConnection sessionBus()
bool registerService(const QString &serviceName)
QFileInfoList entryInfoList(QDir::Filters filters, QDir::SortFlags sort) const const
bool unregisterService(const QString &serviceName)
char * toString(const T &value)
QDBusConnectionInterface * interface() const const
static QString instanceIdentifier()
Returns the identifier of the Akonadi instance we are connected to.
VehicleSection::Type type(QStringView coachNumber, QStringView coachClassification)
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Jun 30 2022 03:51:45 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.