From bfa1100523b60b793acfa7a0828c8ef5a917a2e8 Mon Sep 17 00:00:00 2001 From: Nicolas Fella Date: Mon, 29 Mar 2021 20:38:56 +0200 Subject: [PATCH] [pluginloader] Add methods to list containments using KPluginMetaData To replace the KPluginInfo-based variants --- autotests/pluginloadertest.cpp | 4 ++++ src/plasma/pluginloader.cpp | 22 ++++++++++++++++++++++ src/plasma/pluginloader.h | 18 ++++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/autotests/pluginloadertest.cpp b/autotests/pluginloadertest.cpp index 449dbba37..e30c88e02 100644 --- a/autotests/pluginloadertest.cpp +++ b/autotests/pluginloadertest.cpp @@ -55,6 +55,10 @@ void PluginTest::listContainmentsOfType() const KPluginInfo::List plugins = Plasma::PluginLoader::listContainmentsOfType(QStringLiteral("Desktop")); qDebug() << "Desktop Containments: " << plugins.count(); QVERIFY(plugins.count() > 0 || m_buildonly); + + const QList pluginsMetaData = Plasma::PluginLoader::listContainmentsMetaDataOfType(QStringLiteral("Desktop")); + qDebug() << "Desktop Containments MetaData: " << pluginsMetaData.count(); + QVERIFY(pluginsMetaData.count() > 0 || m_buildonly); } static const auto source = QStringLiteral("Europe/Sofia"); diff --git a/src/plasma/pluginloader.cpp b/src/plasma/pluginloader.cpp index 8ed73375b..0ad7c7d86 100644 --- a/src/plasma/pluginloader.cpp +++ b/src/plasma/pluginloader.cpp @@ -663,6 +663,28 @@ KPluginInfo::List PluginLoader::listContainments(const QString &category, const return listContainmentsOfType(QString(), category, parentApp); } +QList PluginLoader::listContainmentsMetaData(std::function filter) +{ + auto ownFilter = [filter](const KPluginMetaData &md) -> bool { + if (!md.serviceTypes().contains(QLatin1String("Plasma/Containment"))) { + return false; + } + + return filter(md); + }; + + return KPackage::PackageLoader::self()->findPackages(QStringLiteral("Plasma/Applet"), QString(), ownFilter); +} + +QList PluginLoader::listContainmentsMetaDataOfType(const QString &type) +{ + auto filter = [type](const KPluginMetaData &md) -> bool { + return md.value(QStringLiteral("X-Plasma-ContainmentType")) == type; + }; + + return listContainmentsMetaData(filter); +} + KPluginInfo::List PluginLoader::listContainmentsOfType(const QString &type, const QString &category, const QString &parentApp) { KConfigGroup group(KSharedConfig::openConfig(), "General"); diff --git a/src/plasma/pluginloader.h b/src/plasma/pluginloader.h index 4050f8874..6d7bff6a0 100644 --- a/src/plasma/pluginloader.h +++ b/src/plasma/pluginloader.h @@ -280,6 +280,24 @@ public: **/ static KPluginInfo::List listContainments(const QString &category = QString(), const QString &parentApp = QString()); + /** + * Returns a list of all known containments. + * + * @param filter An optional predicate that can be used for filtering. + * + * @return list of containments + */ + static QList listContainmentsMetaData(std::function filter = {}); + + /** + * Returns a list of containments of the specified type. + * + * @param type The target containment type + * + * @return list of containments + */ + static QList listContainmentsMetaDataOfType(const QString &type); + /** * Returns a list of all known containments that match the parameters. *