From dd46c79475960a0f0288558840b0e167b8ff0e14 Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Thu, 20 Aug 2020 17:28:29 +0300 Subject: [PATCH] storage:expose applet plugins information --- app/data/appletdata.cpp | 5 ++ app/data/appletdata.h | 4 +- app/layouts/storage.cpp | 149 ++++++++++++++++++++++++++++++++++++++++ app/layouts/storage.h | 9 +++ 4 files changed, 166 insertions(+), 1 deletion(-) diff --git a/app/data/appletdata.cpp b/app/data/appletdata.cpp index 4d8f4958d..e51fbf731 100644 --- a/app/data/appletdata.cpp +++ b/app/data/appletdata.cpp @@ -62,5 +62,10 @@ Applet &Applet::operator=(Applet &&rhs) return (*this); } +bool Applet::isValid() const +{ + return !id.isEmpty() && !name.isEmpty(); +} + } } diff --git a/app/data/appletdata.h b/app/data/appletdata.h index 5798088cf..290d3f433 100644 --- a/app/data/appletdata.h +++ b/app/data/appletdata.h @@ -46,9 +46,11 @@ public: //! Operators Applet &operator=(const Applet &rhs); Applet &operator=(Applet &&rhs); + + bool isValid() const; }; -typedef GenericTable AppletTable; +typedef GenericTable AppletsTable; } } diff --git a/app/layouts/storage.cpp b/app/layouts/storage.cpp index dc5ca4470..5aa565a49 100644 --- a/app/layouts/storage.cpp +++ b/app/layouts/storage.cpp @@ -35,7 +35,10 @@ // KDE #include +#include #include +#include +#include // Plasma #include @@ -800,6 +803,152 @@ bool Storage::isBroken(const Layout::GenericLayout *layout, QStringList &errors) return false; } +//! AppletsData Information +Data::Applet Storage::metadata(const QString &pluginId) +{ + Data::Applet data; + data.id = pluginId; + + KPackage::Package pkg = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/Applet")); + pkg.setDefaultPackageRoot(QStringLiteral("plasma/plasmoids")); + pkg.setPath(pluginId); + + if (pkg.isValid()) { + data.name = pkg.metadata().name(); + data.description = pkg.metadata().description(); + data.icon = pkg.metadata().iconName(); + } + + return data; +} + +Data::AppletsTable Storage::plugins(const Layout::GenericLayout *layout, const int containmentid) +{ + Data::AppletsTable knownapplets; + Data::AppletsTable unknownapplets; + + if (!layout) { + return knownapplets; + } + + //! empty means all containments are valid + QList validcontainmentids; + + if (isValid(containmentid)) { + validcontainmentids << containmentid; + + //! searching for specific containment and subcontainments and ignore all other containments + for(auto containment : *layout->containments()) { + if (containment->id() != containmentid) { + //! ignore irrelevant containments + continue; + } + + for (auto applet : containment->applets()) { + if (isSubContainment(layout, applet)) { + validcontainmentids << subContainmentId(applet->config()); + } + } + } + } + + //! cycle through valid contaiments in order to retrieve their metadata + for(auto containment : *layout->containments()) { + if (validcontainmentids.count()>0 && !validcontainmentids.contains(containment->id())) { + //! searching only for valid containments + continue; + } + + for (auto applet : containment->applets()) { + if (!isSubContainment(layout, applet)) { + QString pluginId = applet->pluginMetaData().pluginId(); + if (!knownapplets.containsId(pluginId) && !unknownapplets.containsId(pluginId)) { + Data::Applet appletdata = metadata(pluginId); + + if (appletdata.isValid()) { + knownapplets.insertBasedOnName(appletdata); + } else { + unknownapplets.insertBasedOnId(appletdata); + } + } + } + } + } + + knownapplets << unknownapplets; + + return knownapplets; +} + +Data::AppletsTable Storage::plugins(const QString &layoutfile, const int containmentid) +{ + Data::AppletsTable knownapplets; + Data::AppletsTable unknownapplets; + + if (layoutfile.isEmpty()) { + return knownapplets; + } + + KSharedConfigPtr lFile = KSharedConfig::openConfig(layoutfile); + KConfigGroup containmentGroups = KConfigGroup(lFile, "Containments"); + + //! empty means all containments are valid + QList validcontainmentids; + + if (isValid(containmentid)) { + validcontainmentids << containmentid; + + //! searching for specific containment and subcontainments and ignore all other containments + for (const auto &cId : containmentGroups.groupList()) { + if (cId.toInt() != containmentid) { + //! ignore irrelevant containments + continue; + } + + auto appletGroups = containmentGroups.group(cId).group("Applets"); + + for (const auto &appletId : appletGroups.groupList()) { + KConfigGroup appletCfg = appletGroups.group(appletId); + if (isSubContainment(appletCfg)) { + validcontainmentids << subContainmentId(appletCfg); + } + } + } + } + + //! cycle through valid contaiments in order to retrieve their metadata + for (const auto &cId : containmentGroups.groupList()) { + if (validcontainmentids.count()>0 && !validcontainmentids.contains(cId.toInt())) { + //! searching only for valid containments + continue; + } + + auto appletGroups = containmentGroups.group(cId).group("Applets"); + + for (const auto &appletId : appletGroups.groupList()) { + KConfigGroup appletCfg = appletGroups.group(appletId); + if (!isSubContainment(appletCfg)) { + QString pluginId = appletCfg.readEntry("plugin", ""); + + if (!knownapplets.containsId(pluginId) && !unknownapplets.containsId(pluginId)) { + Data::Applet appletdata = metadata(pluginId); + + if (appletdata.isValid()) { + knownapplets.insertBasedOnName(appletdata); + } else { + unknownapplets.insertBasedOnId(appletdata); + } + } + } + } + } + + knownapplets << unknownapplets; + + return knownapplets; +} + + //! Data For Reports void Storage::subContainmentsInfo(const QString &file, QHash> &subContainments, QList &assignedSubContainments, QList &orphanSubContainments) { diff --git a/app/layouts/storage.h b/app/layouts/storage.h index 744d8fee8..14e52c71f 100644 --- a/app/layouts/storage.h +++ b/app/layouts/storage.h @@ -20,6 +20,9 @@ #ifndef LAYOUTSSTORAGE_H #define LAYOUTSSTORAGE_H +// local +#include "../data/appletdata.h" + // Qt #include @@ -87,6 +90,12 @@ public: static bool appletGroupIsValid(const KConfigGroup &appletGroup); static bool isValid(const int &id); + + //! AppletsData Information + Data::Applet metadata(const QString &pluginId); + Data::AppletsTable plugins(const Layout::GenericLayout *layout, const int containmentid = IDNULL); + Data::AppletsTable plugins(const QString &layoutfile, const int containmentid = IDNULL); + //! Functions used from Layout Reports //! [containment id, list], list, list[subcontainment ids] void subContainmentsInfo(const QString &file, QHash> &subContainments, QList &assignedSubContainments, QList &orphanSubContainments);