From 8c65ee54814e8c8e79f84087e1823d61e3d7bf93 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sun, 3 Dec 2017 08:48:41 -0500 Subject: [PATCH] [plasmalnf] Get available LNF - Implement various ways of getting the LNF; the process-based one uses a recent CLI-tool from the Plasma developers. - Fill the UI with (meaningless) LNF package IDs. --- src/modules/plasmalnf/CMakeLists.txt | 3 + src/modules/plasmalnf/PlasmaLnfInfo.cpp | 99 +++++++++++++++++++++++++ src/modules/plasmalnf/PlasmaLnfInfo.h | 33 +++++++++ src/modules/plasmalnf/PlasmaLnfPage.cpp | 4 + src/modules/plasmalnf/page_plasmalnf.ui | 5 +- 5 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 src/modules/plasmalnf/PlasmaLnfInfo.cpp create mode 100644 src/modules/plasmalnf/PlasmaLnfInfo.h diff --git a/src/modules/plasmalnf/CMakeLists.txt b/src/modules/plasmalnf/CMakeLists.txt index e3dee1c61..727c9e7df 100644 --- a/src/modules/plasmalnf/CMakeLists.txt +++ b/src/modules/plasmalnf/CMakeLists.txt @@ -8,9 +8,12 @@ calamares_add_plugin( plasmalnf SOURCES PlasmaLnfViewStep.cpp PlasmaLnfPage.cpp + PlasmaLnfInfo.cpp UI page_plasmalnf.ui LINK_PRIVATE_LIBRARIES calamaresui + KF5::Plasma + KF5::Service SHARED_LIB ) diff --git a/src/modules/plasmalnf/PlasmaLnfInfo.cpp b/src/modules/plasmalnf/PlasmaLnfInfo.cpp new file mode 100644 index 000000000..420c57919 --- /dev/null +++ b/src/modules/plasmalnf/PlasmaLnfInfo.cpp @@ -0,0 +1,99 @@ +/* === This file is part of Calamares - === + * + * Copyright 2017, Adriaan de Groot + * + * Calamares is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#include "PlasmaLnfInfo.h" + +#include +#include +#include +#include +#include + +#include +#include +#include // Future + +#include // TODO: port to KPluginLoader + +#include "utils/Logger.h" + + +namespace Calamares +{ + +QStringList themes_by_service() +{ + KService::List services; + KServiceTypeTrader* trader = KServiceTypeTrader::self(); + + cDebug() << "Plasma themes by service:"; + QStringList packages; + services = trader->query("Plasma/Theme"); + int c = 0; + for ( const auto s : services ) + { + cDebug() << " .. Plasma theme" << s->name(); + packages << s->name(); + c++; + } + + return packages; +} + +QStringList themes_by_kcm() +{ + QString component; + QList packages; + QStringList paths; + QStringList packageNames; + 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); + } + + cDebug() << "Plasma themes by kcm:"; + 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; + packageNames << pkg.metadata().pluginName(); + cDebug() << " .. Plasma theme" << pkg.metadata().pluginName(); + } + } + + return packageNames; +} + +QStringList themes_by_lnftool() +{ + QStringList packages; + + QProcess lnftool; + lnftool.start( "lookandfeeltool", {"--list"} ); + if ( lnftool.waitForStarted(1000) && lnftool.waitForFinished( 1000 ) && (lnftool.exitCode() == 0) && (lnftool.exitStatus() == QProcess::NormalExit ) ) + { + packages = QString::fromLocal8Bit( lnftool.readAllStandardOutput() ).trimmed().split('\n'); + } + return packages; +} + +} // namespace Calamares diff --git a/src/modules/plasmalnf/PlasmaLnfInfo.h b/src/modules/plasmalnf/PlasmaLnfInfo.h new file mode 100644 index 000000000..1ee2cd2ac --- /dev/null +++ b/src/modules/plasmalnf/PlasmaLnfInfo.h @@ -0,0 +1,33 @@ +/* === This file is part of Calamares - === + * + * Copyright 2017, Adriaan de Groot + * + * Calamares is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#ifndef PLASMALNFINFO_H +#define PLASMALNFINFO_H + +#include + +namespace Calamares +{ + +QStringList themes_by_service(); +QStringList themes_by_kcm(); +QStringList themes_by_lnftool(); + +} + +#endif // PLASMALNFINFO_H diff --git a/src/modules/plasmalnf/PlasmaLnfPage.cpp b/src/modules/plasmalnf/PlasmaLnfPage.cpp index d83a845bc..eee9534c4 100644 --- a/src/modules/plasmalnf/PlasmaLnfPage.cpp +++ b/src/modules/plasmalnf/PlasmaLnfPage.cpp @@ -17,6 +17,7 @@ */ #include "PlasmaLnfPage.h" +#include "PlasmaLnfInfo.h" #include "ui_page_plasmalnf.h" @@ -43,5 +44,8 @@ PlasmaLnfPage::PlasmaLnfPage(QWidget *parent) ui->retranslateUi( this ); ui->generalExplanation->setText( tr( "Please choose a look-and-feel for the KDE Plasma Desktop, below." ) ); ) + + Calamares::themes_by_service(); + ui->lnfCombo->addItems( Calamares::themes_by_lnftool() ); } diff --git a/src/modules/plasmalnf/page_plasmalnf.ui b/src/modules/plasmalnf/page_plasmalnf.ui index dfb906c22..340527ad0 100644 --- a/src/modules/plasmalnf/page_plasmalnf.ui +++ b/src/modules/plasmalnf/page_plasmalnf.ui @@ -13,7 +13,7 @@ Form - + @@ -28,6 +28,9 @@ margin-left: 2em; + + +