Akonadi

agentconfigurationmanager.cpp
1/*
2 SPDX-FileCopyrightText: 2018 Daniel Vrátil <dvratil@kde.org>
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
18namespace Akonadi
19{
20class AgentConfigurationManagerPrivate
21{
22public:
23 QString serviceName(const QString &instance) const
24 {
25 QString service = QStringLiteral("org.freedesktop.Akonadi.AgentConfig.%1").arg(instance);
26 if (ServerManager::self()->hasInstanceIdentifier()) {
28 }
29 return service;
30 }
31};
32} // namespace Akonadi
33
34using namespace Akonadi;
35
36AgentConfigurationManager *AgentConfigurationManager::sInstance = nullptr;
37
38AgentConfigurationManager::AgentConfigurationManager(QObject *parent)
39 : QObject(parent)
40{
41}
42
43AgentConfigurationManager *AgentConfigurationManager::self()
44{
45 if (sInstance == nullptr) {
46 sInstance = new AgentConfigurationManager();
47 }
48 return sInstance;
49}
50
51AgentConfigurationManager::~AgentConfigurationManager()
52{
53}
54
55bool 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
67void AgentConfigurationManager::unregisterInstanceConfiguration(const QString &instance)
68{
69 const auto serviceName = d->serviceName(instance);
71}
72
73bool AgentConfigurationManager::isInstanceRegistered(const QString &instance) const
74{
75 const auto serviceName = d->serviceName(instance);
77}
78
79QString AgentConfigurationManager::findConfigPlugin(const QString &type) const
80{
81 const auto libPaths = QCoreApplication::libraryPaths();
82 const QString prefixPluginPath = QStringLiteral("pim6/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() != QLatin1StringView("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() != QLatin1StringView("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}
105
106#include "moc_agentconfigurationmanager_p.cpp"
static ServerManager * self()
Returns the singleton instance of this class, for connecting to its signals.
static QString instanceIdentifier()
Returns the identifier of the Akonadi instance we are connected to.
Helper integration between Akonadi and Qt.
char * toString(const EngineQuery &query)
VehicleSection::Type type(QStringView coachNumber, QStringView coachClassification)
QStringList libraryPaths()
QDBusConnectionInterface * interface() const const
bool registerService(const QString &serviceName)
QDBusConnection sessionBus()
bool unregisterService(const QString &serviceName)
QDBusReply< bool > isServiceRegistered(const QString &serviceName) const const
QFileInfoList entryInfoList(Filters filters, SortFlags sort) const const
QString arg(Args &&... args) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:01:42 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.