KCalendarCore

calendarpluginloader.cpp
1/*
2 SPDX-FileCopyrightText: 2022 Volker Krause <vkrause@kde.org>
3 SPDX-License-Identifier: LGPL-2.0-or-later
4*/
5
6#include "calendarpluginloader.h"
7
8#include <QCoreApplication>
9#include <QDirIterator>
10#include <QPluginLoader>
11
12using namespace KCalendarCore;
13
14struct PluginLoader {
15 PluginLoader();
16 std::unique_ptr<KCalendarCore::CalendarPlugin> plugin;
17};
18
19PluginLoader::PluginLoader()
20{
21 // static plugins
22 const auto staticPluginData = QPluginLoader::staticPlugins();
23 for (const auto &data : staticPluginData) {
24 if (data.metaData().value(QLatin1String("IID")).toString() == QLatin1String("org.kde.kcalendarcore.CalendarPlugin")) {
25 plugin.reset(qobject_cast<KCalendarCore::CalendarPlugin *>(data.instance()));
26 }
27 if (plugin) {
28 return;
29 }
30 }
31
32 // dynamic plugins
34 searchPaths += QCoreApplication::libraryPaths();
35
36 for (const auto &searchPath : std::as_const(searchPaths)) {
37 const QString pluginPath = searchPath + QLatin1String("/kf6/org.kde.kcalendarcore.calendars");
38 for (QDirIterator it(pluginPath, QDir::Files); it.hasNext() && !plugin;) {
39 it.next();
40 QPluginLoader loader(it.fileInfo().absoluteFilePath());
41 if (loader.load()) {
42 plugin.reset(qobject_cast<KCalendarCore::CalendarPlugin *>(loader.instance()));
43 } else {
44 qDebug() << loader.errorString();
45 }
46 }
47 }
48}
49
50Q_GLOBAL_STATIC(PluginLoader, s_pluginLoader)
51
52bool CalendarPluginLoader::hasPlugin()
53{
54 return (bool)s_pluginLoader->plugin;
55}
56
57KCalendarCore::CalendarPlugin *CalendarPluginLoader::plugin()
58{
59 return s_pluginLoader->plugin.get();
60}
61
62#include "moc_calendarpluginloader.cpp"
A plugin that provides calendar data.
char * toString(const EngineQuery &query)
Namespace for all KCalendarCore types.
Definition alarm.h:37
QString applicationDirPath()
QStringList libraryPaths()
bool hasNext() const const
QList< QStaticPlugin > staticPlugins()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:08:40 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.