Plasma5Support

pluginloader.cpp
1/*
2 SPDX-FileCopyrightText: 2010 Ryan Rix <ry@n.rix.si>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "pluginloader.h"
8
9#include <QPluginLoader>
10#include <QPointer>
11#include <QStandardPaths>
12
13#include <KRuntimePlatform>
14#include <QDebug>
15#include <QRegularExpression>
16
17#include "dataengine.h"
18#include "private/service_p.h" // for NullService
19#include "private/storage_p.h"
20
21namespace Plasma5Support
22{
23PluginLoader::~PluginLoader() = default;
24
26{
27 const static QString s_servicesPluginDir = QStringLiteral("plasma5support/services");
28 Service *service = nullptr;
29
30 // TODO: scripting API support
31 if (name.isEmpty()) {
32 return new NullService(QString(), parent);
33 } else if (name == QLatin1String("org.kde.servicestorage")) {
34 return new Storage(parent);
35 }
36
37 // Look for C++ plugins first
38 KPluginMetaData plugin = KPluginMetaData::findPluginById(s_servicesPluginDir, name);
39 if (plugin.isValid()) {
40 service = KPluginFactory::instantiatePlugin<Plasma5Support::Service>(plugin, parent).plugin;
41 }
42
43 if (service) {
44 if (service->name().isEmpty()) {
45 service->setName(name);
46 }
47 return service;
48 } else {
49 return new NullService(name, parent);
50 }
51}
52
54{
55 const static QString s_dataEnginePluginDir = QStringLiteral("plasma5support/dataengine");
56 if (parentApp.isEmpty()) {
57 return KPluginMetaData::findPlugins(s_dataEnginePluginDir);
58 } else {
59 return KPluginMetaData::findPlugins(s_dataEnginePluginDir, [&parentApp](const KPluginMetaData &md) -> bool {
60 return md.value(QStringLiteral("X-KDE-ParentApp")) == parentApp;
61 });
62 }
63}
64
65} // Plasma Namespace
bool value(QStringView key, bool defaultValue) const
static QList< KPluginMetaData > findPlugins(const QString &directory, std::function< bool(const KPluginMetaData &)> filter={}, KPluginMetaDataOptions options={})
bool isValid() const
static KPluginMetaData findPluginById(const QString &directory, const QString &pluginId, KPluginMetaDataOptions options={})
static QList< KPluginMetaData > listDataEngineMetaData(const QString &parentApp=QString())
Returns a list of all known dataengines.
static Service * loadService(const QString &name, QObject *parent=nullptr)
Load a Service plugin.
This class provides a generic API for write access to settings or services.
Definition service.h:78
void setName(const QString &name)
Sets the name of the Service; useful for Services not loaded from plugins, which use the plugin name ...
Definition service.cpp:114
Namespace for everything in libplasma.
Definition datamodel.cpp:15
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:59:38 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.