From 41e8fdd362a7fe888afac203d4b1204e991d86b8 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 31 Oct 2017 09:49:16 -0400 Subject: [PATCH] [plasmalnf] Search for LNF themes like the KCM does --- src/modules/plasmalnf/CMakeLists.txt | 4 +- src/modules/plasmalnf/PlasmaLnfJob.cpp | 52 +++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/src/modules/plasmalnf/CMakeLists.txt b/src/modules/plasmalnf/CMakeLists.txt index 3a6c0324f..b78aac6b8 100644 --- a/src/modules/plasmalnf/CMakeLists.txt +++ b/src/modules/plasmalnf/CMakeLists.txt @@ -1,6 +1,6 @@ find_package(ECM ${ECM_VERSION} REQUIRED NO_MODULE) -find_package( KF5 REQUIRED CoreAddons Service ) +find_package( KF5 5.29 REQUIRED CoreAddons Plasma Service ) calamares_add_plugin( plasmalnf TYPE job @@ -9,5 +9,7 @@ calamares_add_plugin( plasmalnf PlasmaLnfJob.cpp LINK_PRIVATE_LIBRARIES calamares + KF5::Plasma + KF5::Service SHARED_LIB ) diff --git a/src/modules/plasmalnf/PlasmaLnfJob.cpp b/src/modules/plasmalnf/PlasmaLnfJob.cpp index 15b4e39ce..0aa7314cf 100644 --- a/src/modules/plasmalnf/PlasmaLnfJob.cpp +++ b/src/modules/plasmalnf/PlasmaLnfJob.cpp @@ -18,10 +18,18 @@ #include "PlasmaLnfJob.h" -#include #include +#include +#include +#include #include +#include +#include +#include // Future + +#include // TODO: port to KPluginLoader + #include "CalamaresVersion.h" #include "JobQueue.h" #include "GlobalStorage.h" @@ -45,12 +53,54 @@ PlasmaLnfJob::prettyName() const return tr( "Plasma Look-and-Feel Job" ); } +static void _themes_by_service() +{ + KService::List services; + KServiceTypeTrader* trader = KServiceTypeTrader::self(); + + services = trader->query("Plasma/Theme"); + int c = 0; + for ( const auto s : services ) + { + cDebug() << "Plasma theme '" << s->name() << '\''; + c++; + } + cDebug() << "Plasma themes by service found" << c; +} + +static void _themes_by_kcm() +{ + QString component; + QList packages; + QStringList paths; + const QStringList dataPaths = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation); + + for (const QString &path : dataPaths) { + QDir dir(path + "/plasma/look-and-feel"); + paths << dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot); + } + + for (const QString &path : paths) { + Plasma::Package pkg = Plasma::PluginLoader::self()->loadPackage(QStringLiteral("Plasma/LookAndFeel")); + pkg.setPath(path); + pkg.setFallbackPackage(Plasma::Package()); + if (component.isEmpty() || !pkg.filePath(component.toUtf8()).isEmpty()) { + packages << pkg; + cDebug() << "Plasma theme '" << pkg.metadata().pluginName() << '\''; + } + } + cDebug() << "Plasma themes by kcm found" << packages.length(); +} + Calamares::JobResult PlasmaLnfJob::exec() { cDebug() << "Plasma Look-and-Feel Job"; + _themes_by_service(); + _themes_by_kcm(); + return Calamares::JobResult::ok(); }