storage:expose applet plugins information

pull/19/head
Michail Vourlakos 5 years ago
parent a36b49de77
commit dd46c79475

@ -62,5 +62,10 @@ Applet &Applet::operator=(Applet &&rhs)
return (*this);
}
bool Applet::isValid() const
{
return !id.isEmpty() && !name.isEmpty();
}
}
}

@ -46,9 +46,11 @@ public:
//! Operators
Applet &operator=(const Applet &rhs);
Applet &operator=(Applet &&rhs);
bool isValid() const;
};
typedef GenericTable<Applet> AppletTable;
typedef GenericTable<Applet> AppletsTable;
}
}

@ -35,7 +35,10 @@
// KDE
#include <KConfigGroup>
#include <KPluginMetaData>
#include <KSharedConfig>
#include <KPackage/Package>
#include <KPackage/PackageLoader>
// Plasma
#include <Plasma>
@ -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<int> 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<int> 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<int, QList<int>> &subContainments, QList<int> &assignedSubContainments, QList<int> &orphanSubContainments)
{

@ -20,6 +20,9 @@
#ifndef LAYOUTSSTORAGE_H
#define LAYOUTSSTORAGE_H
// local
#include "../data/appletdata.h"
// Qt
#include <QTemporaryDir>
@ -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<subcontainment ids>], list<subcontainment ids>, list[subcontainment ids]
void subContainmentsInfo(const QString &file, QHash<int, QList<int>> &subContainments, QList<int> &assignedSubContainments, QList<int> &orphanSubContainments);

Loading…
Cancel
Save