From 50a03b39a39159db615870ca20bf5fc8c2685e9a Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Tue, 21 Jul 2020 16:06:13 +0200 Subject: [PATCH] filter on formfactors if set if KDeclarative::runtimePlatform() is set, then filter applets that have formfactors set and don't match, in order to not show on the phone applets that are desktop only in desktop case, list all applets, for maximum retrocompatibility, to be reconsidered for kf6 --- src/plasma/pluginloader.cpp | 40 +++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/src/plasma/pluginloader.cpp b/src/plasma/pluginloader.cpp index 59de58d43..c0097e3a7 100644 --- a/src/plasma/pluginloader.cpp +++ b/src/plasma/pluginloader.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include "config-plasma.h" @@ -468,22 +469,57 @@ Package PluginLoader::loadPackage(const QString &packageFormat, const QString &s QList PluginLoader::listAppletMetaData(const QString &category, const QString &parentApp) { + auto platforms = KDeclarative::KDeclarative::runtimePlatform(); + // For now desktop always lists everything + if (platforms.contains(QStringLiteral("desktop"))) { + platforms.clear(); + } + //FIXME: this assumes we are always use packages.. no pure c++ std::function filter; if (category.isEmpty()) { //use all but the excluded categories KConfigGroup group(KSharedConfig::openConfig(), "General"); QStringList excluded = group.readEntry("ExcludeCategories", QStringList()); - filter = [excluded, parentApp](const KPluginMetaData &md) -> bool + filter = [excluded, parentApp, platforms](const KPluginMetaData &md) -> bool { + if (!platforms.isEmpty() && !md.formFactors().isEmpty()) { + bool found = false; + for (const auto &plat : platforms) { + if (md.formFactors().contains(plat)) { + found = true; + break; + } + } + + if (!found) { + return false; + } + } + const QString pa = md.value(QStringLiteral("X-KDE-ParentApp")); return (parentApp.isEmpty() || pa == parentApp) && !excluded.contains(md.category()); }; } else { //specific category (this could be an excluded one - is that bad?) - filter = [category, parentApp](const KPluginMetaData &md) -> bool + filter = [category, parentApp, platforms](const KPluginMetaData &md) -> bool { + if (!platforms.isEmpty() && !md.formFactors().isEmpty()) { + bool found = false; + for (const auto &plat : platforms) { + if (md.formFactors().contains(plat)) { + found = true; + break; + } + } + + if (!found) { + return false; + } + } + const QString pa = md.value(QStringLiteral("X-KDE-ParentApp")); + if (category == QLatin1String("Miscellaneous")) { return (parentApp.isEmpty() || pa == parentApp) && (md.category() == category || md.category().isEmpty()); } else {