From 4e2e55a93503faefc304ab2676db341f132e3766 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sun, 3 Dec 2017 15:24:39 -0500 Subject: [PATCH 1/8] [plasmalnf] Needs to run as target user in all cases --- src/modules/plasmalnf/PlasmaLnfJob.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/modules/plasmalnf/PlasmaLnfJob.cpp b/src/modules/plasmalnf/PlasmaLnfJob.cpp index e6a4fbe10..a06716a89 100644 --- a/src/modules/plasmalnf/PlasmaLnfJob.cpp +++ b/src/modules/plasmalnf/PlasmaLnfJob.cpp @@ -75,12 +75,9 @@ PlasmaLnfJob::exec() auto system = CalamaresUtils::System::instance(); Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage(); - QStringList command; - - if ( !system->doChroot() ) - command << "sudo" << "-E" << "-H" << "-u" << gs->value("username").toString(); - - command << m_lnfPath << "-platform" << "minimal" << "--resetLayout" << "--apply" << m_id; + QStringList command( { + "sudo", "-E", "-H", "-u", gs->value("username").toString(), + m_lnfPath, "-platform", "minimal", "--resetLayout", "--apply", m_id } ); int r = system->targetEnvCall( command ); if (r) From fe8ff3ab05d8fd9ae3c85a931d7313514f9d55c7 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sun, 3 Dec 2017 15:34:06 -0500 Subject: [PATCH 2/8] [plasmalnf] Simplify code, remove redundant implementations --- src/modules/plasmalnf/CMakeLists.txt | 3 +- src/modules/plasmalnf/PlasmaLnfInfo.cpp | 82 ------------------------- src/modules/plasmalnf/PlasmaLnfInfo.h | 8 --- src/modules/plasmalnf/PlasmaLnfPage.cpp | 20 +++++- 4 files changed, 19 insertions(+), 94 deletions(-) diff --git a/src/modules/plasmalnf/CMakeLists.txt b/src/modules/plasmalnf/CMakeLists.txt index 9b3ccf716..1bbc555c8 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 5.29 REQUIRED CoreAddons Plasma Service Package ) +find_package( KF5 5.29 REQUIRED CoreAddons Plasma Package ) calamares_add_plugin( plasmalnf TYPE viewmodule @@ -16,6 +16,5 @@ calamares_add_plugin( plasmalnf calamaresui KF5::Package KF5::Plasma - KF5::Service SHARED_LIB ) diff --git a/src/modules/plasmalnf/PlasmaLnfInfo.cpp b/src/modules/plasmalnf/PlasmaLnfInfo.cpp index 6e9249825..1112ee18a 100644 --- a/src/modules/plasmalnf/PlasmaLnfInfo.cpp +++ b/src/modules/plasmalnf/PlasmaLnfInfo.cpp @@ -38,88 +38,6 @@ namespace Calamares { -QStringList themes_by_package() -{ - QStringList packages; - - QList pkgs = KPackage::PackageLoader::self()->listPackages("Plasma/LookAndFeel"); - - for (const KPluginMetaData &data : pkgs) { - packages << data.pluginId(); - } - - return packages; -} - - -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( Calamares::lnftool(), {"--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; -} - -QStringList plasma_themes() -{ - QStringList l( themes_by_package() ); - if (l.isEmpty()) - return themes_by_lnftool(); - return l; -} - static QString *p_lnfPath = nullptr; QString lnftool() diff --git a/src/modules/plasmalnf/PlasmaLnfInfo.h b/src/modules/plasmalnf/PlasmaLnfInfo.h index 27adc224c..f1ed43b72 100644 --- a/src/modules/plasmalnf/PlasmaLnfInfo.h +++ b/src/modules/plasmalnf/PlasmaLnfInfo.h @@ -26,14 +26,6 @@ namespace Calamares { QString lnftool(); void set_lnftool( const QString& ); - - /* Internal */ -QStringList themes_by_package(); -QStringList themes_by_service(); -QStringList themes_by_kcm(); -QStringList themes_by_lnftool(); - -QStringList plasma_themes(); } #endif // PLASMALNFINFO_H diff --git a/src/modules/plasmalnf/PlasmaLnfPage.cpp b/src/modules/plasmalnf/PlasmaLnfPage.cpp index 632b9f13a..5a94ac789 100644 --- a/src/modules/plasmalnf/PlasmaLnfPage.cpp +++ b/src/modules/plasmalnf/PlasmaLnfPage.cpp @@ -29,11 +29,28 @@ #include "utils/Retranslator.h" #include "ViewManager.h" +#include +#include + #include #include #include #include +static QStringList plasma_themes() +{ + QStringList packages; + + QList pkgs = KPackage::PackageLoader::self()->listPackages("Plasma/LookAndFeel"); + + for (const KPluginMetaData &data : pkgs) { + packages << data.pluginId(); + } + + return packages; +} + + PlasmaLnfPage::PlasmaLnfPage(QWidget *parent) : QWidget( parent ) , ui( new Ui::PlasmaLnfPage ) @@ -46,8 +63,7 @@ PlasmaLnfPage::PlasmaLnfPage(QWidget *parent) ui->generalExplanation->setText( tr( "Please choose a look-and-feel for the KDE Plasma Desktop, below." ) ); ) - Calamares::themes_by_package(); - ui->lnfCombo->addItems( Calamares::plasma_themes() ); + ui->lnfCombo->addItems( plasma_themes() ); QObject::connect(ui->lnfCombo, &QComboBox::activated, this, &PlasmaLnfPage::activated); } From 1de2e94fd098e12908411eb19af611e65b199e46 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sun, 3 Dec 2017 15:41:52 -0500 Subject: [PATCH 3/8] [plasmalnf] Simplify code, reduce copies of lnftool setting --- src/modules/plasmalnf/CMakeLists.txt | 1 - src/modules/plasmalnf/PlasmaLnfInfo.cpp | 58 --------------------- src/modules/plasmalnf/PlasmaLnfInfo.h | 31 ----------- src/modules/plasmalnf/PlasmaLnfPage.cpp | 9 +++- src/modules/plasmalnf/PlasmaLnfPage.h | 3 ++ src/modules/plasmalnf/PlasmaLnfViewStep.cpp | 3 +- 6 files changed, 11 insertions(+), 94 deletions(-) delete mode 100644 src/modules/plasmalnf/PlasmaLnfInfo.cpp delete mode 100644 src/modules/plasmalnf/PlasmaLnfInfo.h diff --git a/src/modules/plasmalnf/CMakeLists.txt b/src/modules/plasmalnf/CMakeLists.txt index 1bbc555c8..61b44862f 100644 --- a/src/modules/plasmalnf/CMakeLists.txt +++ b/src/modules/plasmalnf/CMakeLists.txt @@ -9,7 +9,6 @@ calamares_add_plugin( plasmalnf PlasmaLnfViewStep.cpp PlasmaLnfPage.cpp PlasmaLnfJob.cpp - PlasmaLnfInfo.cpp UI page_plasmalnf.ui LINK_PRIVATE_LIBRARIES diff --git a/src/modules/plasmalnf/PlasmaLnfInfo.cpp b/src/modules/plasmalnf/PlasmaLnfInfo.cpp deleted file mode 100644 index 1112ee18a..000000000 --- a/src/modules/plasmalnf/PlasmaLnfInfo.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* === 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 -#include - -#include "utils/Logger.h" - - -namespace Calamares -{ - -static QString *p_lnfPath = nullptr; - -QString lnftool() -{ - if ( !p_lnfPath ) - p_lnfPath = new QString("/usr/bin/lookandfeeltool"); - - return *p_lnfPath; -} - -void set_lnftool( const QString& lnfPath ) -{ - if (p_lnfPath) - delete p_lnfPath; - p_lnfPath = new QString( lnfPath ); -} - -} // namespace Calamares diff --git a/src/modules/plasmalnf/PlasmaLnfInfo.h b/src/modules/plasmalnf/PlasmaLnfInfo.h deleted file mode 100644 index f1ed43b72..000000000 --- a/src/modules/plasmalnf/PlasmaLnfInfo.h +++ /dev/null @@ -1,31 +0,0 @@ -/* === 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 -#include - -namespace Calamares -{ -QString lnftool(); -void set_lnftool( const QString& ); -} - -#endif // PLASMALNFINFO_H diff --git a/src/modules/plasmalnf/PlasmaLnfPage.cpp b/src/modules/plasmalnf/PlasmaLnfPage.cpp index 5a94ac789..65675949f 100644 --- a/src/modules/plasmalnf/PlasmaLnfPage.cpp +++ b/src/modules/plasmalnf/PlasmaLnfPage.cpp @@ -17,7 +17,6 @@ */ #include "PlasmaLnfPage.h" -#include "PlasmaLnfInfo.h" #include "ui_page_plasmalnf.h" @@ -74,7 +73,7 @@ PlasmaLnfPage::activated(const QString& name) cDebug() << "Changed to" << name; QProcess lnftool; - lnftool.start( Calamares::lnftool(), {"--resetLayout", "--apply", name} ); + lnftool.start( m_lnfPath, {"--resetLayout", "--apply", name} ); if ( lnftool.waitForStarted(1000) && lnftool.waitForFinished( 1000 ) && (lnftool.exitCode() == 0) && (lnftool.exitStatus() == QProcess::NormalExit ) ) ; // OK @@ -84,3 +83,9 @@ PlasmaLnfPage::activated(const QString& name) emit plasmaThemeSelected( name ); } + +void +PlasmaLnfPage::setLnfPath(const QString& path) +{ + m_lnfPath = path; +} diff --git a/src/modules/plasmalnf/PlasmaLnfPage.h b/src/modules/plasmalnf/PlasmaLnfPage.h index ceed37044..d146cbb95 100644 --- a/src/modules/plasmalnf/PlasmaLnfPage.h +++ b/src/modules/plasmalnf/PlasmaLnfPage.h @@ -33,6 +33,8 @@ class PlasmaLnfPage : public QWidget public: explicit PlasmaLnfPage( QWidget* parent = nullptr ); + void setLnfPath( const QString& path ); + public slots: void activated(const QString& name); @@ -41,6 +43,7 @@ signals: private: Ui::PlasmaLnfPage* ui; + QString m_lnfPath; }; #endif //PLASMALNFPAGE_H diff --git a/src/modules/plasmalnf/PlasmaLnfViewStep.cpp b/src/modules/plasmalnf/PlasmaLnfViewStep.cpp index 1beb71d2e..f754c82fe 100644 --- a/src/modules/plasmalnf/PlasmaLnfViewStep.cpp +++ b/src/modules/plasmalnf/PlasmaLnfViewStep.cpp @@ -22,7 +22,6 @@ #include "utils/CalamaresUtils.h" #include "utils/CalamaresUtilsSystem.h" -#include "PlasmaLnfInfo.h" #include "PlasmaLnfJob.h" #include "PlasmaLnfPage.h" #include "PlasmaLnfViewStep.h" @@ -128,7 +127,7 @@ PlasmaLnfViewStep::setConfigurationMap( const QVariantMap& configurationMap ) if ( configurationMap.contains( "lnftool" ) && configurationMap.value( "lnftool" ).type() == QVariant::String ) lnfPath = configurationMap.value( "lnftool" ).toString(); m_lnfPath = lnfPath; - Calamares::set_lnftool( m_lnfPath ); + m_widget->setLnfPath( m_lnfPath ); if (m_lnfPath.isEmpty()) cDebug() << "WARNING: no lnftool given for plasmalnf module."; From 71966b533052344bd61d6f3513cb4f07c0952199 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sun, 3 Dec 2017 16:09:34 -0500 Subject: [PATCH 4/8] [plasmalnf] Wait longer for the tool to finish --- src/modules/plasmalnf/PlasmaLnfPage.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/modules/plasmalnf/PlasmaLnfPage.cpp b/src/modules/plasmalnf/PlasmaLnfPage.cpp index 65675949f..14d8e9e36 100644 --- a/src/modules/plasmalnf/PlasmaLnfPage.cpp +++ b/src/modules/plasmalnf/PlasmaLnfPage.cpp @@ -75,13 +75,21 @@ PlasmaLnfPage::activated(const QString& name) QProcess lnftool; lnftool.start( m_lnfPath, {"--resetLayout", "--apply", name} ); - if ( lnftool.waitForStarted(1000) && lnftool.waitForFinished( 1000 ) && (lnftool.exitCode() == 0) && (lnftool.exitStatus() == QProcess::NormalExit ) ) - ; // OK + if ( !lnftool.waitForStarted( 1000 ) ) + { + cDebug() << "WARNING: could not start look-and-feel" << m_lnfPath; + return; + } + if ( !lnftool.waitForFinished() ) + { + cDebug() << "WARNING:" << m_lnfPath << "timed out."; + return; + } + + if ( (lnftool.exitCode() == 0) && (lnftool.exitStatus() == QProcess::NormalExit ) ) + emit plasmaThemeSelected( name ); else cDebug() << "WARNING: could not apply look-and-feel" << name; - - - emit plasmaThemeSelected( name ); } void From eb92755b0a418cfaa3b8386145a419efe95d7c55 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 4 Dec 2017 06:40:13 -0500 Subject: [PATCH 5/8] [plasmalnf] Enable translations - Move tool-running to the view-step - Enable translations by showing name instead of theme-id - More verbose logging --- src/modules/plasmalnf/PlasmaLnfPage.cpp | 41 +++++++++------------ src/modules/plasmalnf/PlasmaLnfPage.h | 13 ++++++- src/modules/plasmalnf/PlasmaLnfViewStep.cpp | 20 ++++++++++ 3 files changed, 49 insertions(+), 25 deletions(-) diff --git a/src/modules/plasmalnf/PlasmaLnfPage.cpp b/src/modules/plasmalnf/PlasmaLnfPage.cpp index 14d8e9e36..1ea20a75e 100644 --- a/src/modules/plasmalnf/PlasmaLnfPage.cpp +++ b/src/modules/plasmalnf/PlasmaLnfPage.cpp @@ -34,16 +34,19 @@ #include #include #include -#include -static QStringList plasma_themes() +static PlasmaLnfList plasma_themes() { - QStringList packages; + PlasmaLnfList packages; QList pkgs = KPackage::PackageLoader::self()->listPackages("Plasma/LookAndFeel"); for (const KPluginMetaData &data : pkgs) { - packages << data.pluginId(); + packages << PlasmaLnfDescriptor{ data.pluginId(), data.name() }; + cDebug() << "LNF Package" << data.pluginId(); + cDebug() << " .." << data.name(); + cDebug() << " .." << data.description(); + cDebug() << " .." << 'V' << data.isValid() << 'H' << data.isHidden() << 'D' << data.isEnabledByDefault(); } return packages; @@ -60,36 +63,28 @@ PlasmaLnfPage::PlasmaLnfPage(QWidget *parent) CALAMARES_RETRANSLATE( ui->retranslateUi( this ); ui->generalExplanation->setText( tr( "Please choose a look-and-feel for the KDE Plasma Desktop, below." ) ); + m_availableLnf = plasma_themes(); + ui->lnfCombo->clear(); + for ( const auto& p : m_availableLnf ) + ui->lnfCombo->addItem( p.name ); ) - ui->lnfCombo->addItems( plasma_themes() ); - QObject::connect(ui->lnfCombo, &QComboBox::activated, this, &PlasmaLnfPage::activated); + QObject::connect(ui->lnfCombo, &QComboBox::activated, this, &PlasmaLnfPage::activated); } void -PlasmaLnfPage::activated(const QString& name) +PlasmaLnfPage::activated( int index ) { - cDebug() << "Changed to" << name; - - QProcess lnftool; - lnftool.start( m_lnfPath, {"--resetLayout", "--apply", name} ); - - if ( !lnftool.waitForStarted( 1000 ) ) + if ( (index < 0) || (index > m_availableLnf.length()) ) { - cDebug() << "WARNING: could not start look-and-feel" << m_lnfPath; - return; - } - if ( !lnftool.waitForFinished() ) - { - cDebug() << "WARNING:" << m_lnfPath << "timed out."; + cDebug() << "Plasma LNF index" << index << "out of range."; return; } - if ( (lnftool.exitCode() == 0) && (lnftool.exitStatus() == QProcess::NormalExit ) ) - emit plasmaThemeSelected( name ); - else - cDebug() << "WARNING: could not apply look-and-feel" << name; + const PlasmaLnfDescriptor& lnf = m_availableLnf.at( index ); + cDebug() << "Changed to" << index << lnf.id << lnf.name; + emit plasmaThemeSelected( lnf.id ); } void diff --git a/src/modules/plasmalnf/PlasmaLnfPage.h b/src/modules/plasmalnf/PlasmaLnfPage.h index d146cbb95..e115fb649 100644 --- a/src/modules/plasmalnf/PlasmaLnfPage.h +++ b/src/modules/plasmalnf/PlasmaLnfPage.h @@ -27,6 +27,14 @@ namespace Ui class PlasmaLnfPage; } +struct PlasmaLnfDescriptor +{ + QString id; + QString name; +} ; + +using PlasmaLnfList = QList; + class PlasmaLnfPage : public QWidget { Q_OBJECT @@ -36,14 +44,15 @@ public: void setLnfPath( const QString& path ); public slots: - void activated(const QString& name); + void activated( int index ); signals: - void plasmaThemeSelected( const QString &id ); + void plasmaThemeSelected( const QString& id ); private: Ui::PlasmaLnfPage* ui; QString m_lnfPath; + PlasmaLnfList m_availableLnf; }; #endif //PLASMALNFPAGE_H diff --git a/src/modules/plasmalnf/PlasmaLnfViewStep.cpp b/src/modules/plasmalnf/PlasmaLnfViewStep.cpp index f754c82fe..b9337e263 100644 --- a/src/modules/plasmalnf/PlasmaLnfViewStep.cpp +++ b/src/modules/plasmalnf/PlasmaLnfViewStep.cpp @@ -27,6 +27,7 @@ #include "PlasmaLnfViewStep.h" #include +#include #include CALAMARES_PLUGIN_FACTORY_DEFINITION( PlasmaLnfViewStepFactory, registerPlugin(); ) @@ -137,4 +138,23 @@ void PlasmaLnfViewStep::themeSelected( const QString& id ) { m_themeId = id; + + QProcess lnftool; + lnftool.start( m_lnfPath, {"--resetLayout", "--apply", id} ); + + if ( !lnftool.waitForStarted( 1000 ) ) + { + cDebug() << "WARNING: could not start look-and-feel" << m_lnfPath; + return; + } + if ( !lnftool.waitForFinished() ) + { + cDebug() << "WARNING:" << m_lnfPath << "timed out."; + return; + } + + if ( (lnftool.exitCode() == 0) && (lnftool.exitStatus() == QProcess::NormalExit ) ) + cDebug() << "Plasma look-and-feel applied" << id; + else + cDebug() << "WARNING: could not apply look-and-feel" << id; } From b10b19e9ee5a704fac051f0186f6b1bdd86d0fcc Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 4 Dec 2017 06:44:37 -0500 Subject: [PATCH 6/8] [plasmalnf] C++ style and reduce includes --- src/modules/plasmalnf/PlasmaLnfJob.cpp | 32 +++++++-------------- src/modules/plasmalnf/PlasmaLnfPage.cpp | 27 ++++++----------- src/modules/plasmalnf/PlasmaLnfPage.h | 3 +- src/modules/plasmalnf/PlasmaLnfViewStep.cpp | 17 ++++------- src/modules/plasmalnf/PlasmaLnfViewStep.h | 2 +- 5 files changed, 27 insertions(+), 54 deletions(-) diff --git a/src/modules/plasmalnf/PlasmaLnfJob.cpp b/src/modules/plasmalnf/PlasmaLnfJob.cpp index a06716a89..82d55f609 100644 --- a/src/modules/plasmalnf/PlasmaLnfJob.cpp +++ b/src/modules/plasmalnf/PlasmaLnfJob.cpp @@ -18,28 +18,14 @@ #include "PlasmaLnfJob.h" -#include -#include -#include -#include -#include - -#include -#include -#include // Future - -#include // TODO: port to KPluginLoader - -#include "CalamaresVersion.h" -#include "JobQueue.h" #include "GlobalStorage.h" - +#include "JobQueue.h" #include "utils/CalamaresUtilsSystem.h" #include "utils/Logger.h" PlasmaLnfJob::PlasmaLnfJob( const QString& lnfPath, const QString& id ) : m_lnfPath( lnfPath ) - , m_id(id) + , m_id( id ) { } @@ -75,15 +61,17 @@ PlasmaLnfJob::exec() auto system = CalamaresUtils::System::instance(); Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage(); - QStringList command( { - "sudo", "-E", "-H", "-u", gs->value("username").toString(), - m_lnfPath, "-platform", "minimal", "--resetLayout", "--apply", m_id } ); + QStringList command( + { + "sudo", "-E", "-H", "-u", gs->value( "username" ).toString(), + m_lnfPath, "-platform", "minimal", "--resetLayout", "--apply", m_id + } ); int r = system->targetEnvCall( command ); - if (r) + if ( r ) return Calamares::JobResult::error( - tr( "Could not select KDE Plasma Look-and-Feel package" ), - tr( "Could not select KDE Plasma Look-and-Feel package" ) ); + tr( "Could not select KDE Plasma Look-and-Feel package" ), + tr( "Could not select KDE Plasma Look-and-Feel package" ) ); return Calamares::JobResult::ok(); } diff --git a/src/modules/plasmalnf/PlasmaLnfPage.cpp b/src/modules/plasmalnf/PlasmaLnfPage.cpp index 1ea20a75e..01759ba32 100644 --- a/src/modules/plasmalnf/PlasmaLnfPage.cpp +++ b/src/modules/plasmalnf/PlasmaLnfPage.cpp @@ -20,28 +20,20 @@ #include "ui_page_plasmalnf.h" -#include "Branding.h" -#include "JobQueue.h" -#include "GlobalStorage.h" #include "utils/Logger.h" -#include "utils/CalamaresUtilsGui.h" #include "utils/Retranslator.h" -#include "ViewManager.h" #include #include -#include -#include -#include - static PlasmaLnfList plasma_themes() { PlasmaLnfList packages; - QList pkgs = KPackage::PackageLoader::self()->listPackages("Plasma/LookAndFeel"); + QList pkgs = KPackage::PackageLoader::self()->listPackages( "Plasma/LookAndFeel" ); - for (const KPluginMetaData &data : pkgs) { + for ( const KPluginMetaData& data : pkgs ) + { packages << PlasmaLnfDescriptor{ data.pluginId(), data.name() }; cDebug() << "LNF Package" << data.pluginId(); cDebug() << " .." << data.name(); @@ -53,30 +45,29 @@ static PlasmaLnfList plasma_themes() } -PlasmaLnfPage::PlasmaLnfPage(QWidget *parent) +PlasmaLnfPage::PlasmaLnfPage( QWidget* parent ) : QWidget( parent ) , ui( new Ui::PlasmaLnfPage ) { - using StringEntry = Calamares::Branding::StringEntry; - ui->setupUi( this ); CALAMARES_RETRANSLATE( + { ui->retranslateUi( this ); ui->generalExplanation->setText( tr( "Please choose a look-and-feel for the KDE Plasma Desktop, below." ) ); m_availableLnf = plasma_themes(); ui->lnfCombo->clear(); for ( const auto& p : m_availableLnf ) ui->lnfCombo->addItem( p.name ); + } ) - - QObject::connect(ui->lnfCombo, &QComboBox::activated, this, &PlasmaLnfPage::activated); + QObject::connect( ui->lnfCombo, &QComboBox::activated, this, &PlasmaLnfPage::activated ); } void PlasmaLnfPage::activated( int index ) { - if ( (index < 0) || (index > m_availableLnf.length()) ) + if ( ( index < 0 ) || ( index > m_availableLnf.length() ) ) { cDebug() << "Plasma LNF index" << index << "out of range."; return; @@ -88,7 +79,7 @@ PlasmaLnfPage::activated( int index ) } void -PlasmaLnfPage::setLnfPath(const QString& path) +PlasmaLnfPage::setLnfPath( const QString& path ) { m_lnfPath = path; } diff --git a/src/modules/plasmalnf/PlasmaLnfPage.h b/src/modules/plasmalnf/PlasmaLnfPage.h index e115fb649..31731eb0d 100644 --- a/src/modules/plasmalnf/PlasmaLnfPage.h +++ b/src/modules/plasmalnf/PlasmaLnfPage.h @@ -19,8 +19,9 @@ #ifndef PLASMALNFPAGE_H #define PLASMALNFPAGE_H +#include +#include #include -#include namespace Ui { diff --git a/src/modules/plasmalnf/PlasmaLnfViewStep.cpp b/src/modules/plasmalnf/PlasmaLnfViewStep.cpp index b9337e263..1ac3226b1 100644 --- a/src/modules/plasmalnf/PlasmaLnfViewStep.cpp +++ b/src/modules/plasmalnf/PlasmaLnfViewStep.cpp @@ -15,18 +15,13 @@ * You should have received a copy of the GNU General Public License * along with Calamares. If not, see . */ - -#include "JobQueue.h" -#include "GlobalStorage.h" -#include "utils/Logger.h" -#include "utils/CalamaresUtils.h" -#include "utils/CalamaresUtilsSystem.h" +#include "PlasmaLnfViewStep.h" #include "PlasmaLnfJob.h" #include "PlasmaLnfPage.h" -#include "PlasmaLnfViewStep.h" -#include +#include "utils/Logger.h" + #include #include @@ -114,9 +109,7 @@ PlasmaLnfViewStep::jobs() const cDebug() << "Creating Plasma LNF jobs .."; if ( !m_themeId.isEmpty() && !m_lnfPath.isEmpty() ) - { l.append( Calamares::job_ptr( new PlasmaLnfJob( m_lnfPath, m_themeId ) ) ); - } return l; } @@ -130,7 +123,7 @@ PlasmaLnfViewStep::setConfigurationMap( const QVariantMap& configurationMap ) m_lnfPath = lnfPath; m_widget->setLnfPath( m_lnfPath ); - if (m_lnfPath.isEmpty()) + if ( m_lnfPath.isEmpty() ) cDebug() << "WARNING: no lnftool given for plasmalnf module."; } @@ -153,7 +146,7 @@ PlasmaLnfViewStep::themeSelected( const QString& id ) return; } - if ( (lnftool.exitCode() == 0) && (lnftool.exitStatus() == QProcess::NormalExit ) ) + if ( ( lnftool.exitCode() == 0 ) && ( lnftool.exitStatus() == QProcess::NormalExit ) ) cDebug() << "Plasma look-and-feel applied" << id; else cDebug() << "WARNING: could not apply look-and-feel" << id; diff --git a/src/modules/plasmalnf/PlasmaLnfViewStep.h b/src/modules/plasmalnf/PlasmaLnfViewStep.h index 4d2598ccc..e65b59b93 100644 --- a/src/modules/plasmalnf/PlasmaLnfViewStep.h +++ b/src/modules/plasmalnf/PlasmaLnfViewStep.h @@ -57,7 +57,7 @@ public: void setConfigurationMap( const QVariantMap& configurationMap ) override; public slots: - void themeSelected( const QString &id ); + void themeSelected( const QString& id ); private: PlasmaLnfPage* m_widget; From e628ddfdbfbf83b9052b099cfd00abac3ba0143a Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 4 Dec 2017 09:37:34 -0500 Subject: [PATCH 7/8] [plasmalnf] Try to get back to the live user before changing themes --- src/modules/plasmalnf/PlasmaLnfViewStep.cpp | 10 +++++++++- src/modules/plasmalnf/PlasmaLnfViewStep.h | 1 + src/modules/plasmalnf/plasmalnf.conf | 6 ++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/modules/plasmalnf/PlasmaLnfViewStep.cpp b/src/modules/plasmalnf/PlasmaLnfViewStep.cpp index 1ac3226b1..fd6eab78d 100644 --- a/src/modules/plasmalnf/PlasmaLnfViewStep.cpp +++ b/src/modules/plasmalnf/PlasmaLnfViewStep.cpp @@ -125,6 +125,11 @@ PlasmaLnfViewStep::setConfigurationMap( const QVariantMap& configurationMap ) if ( m_lnfPath.isEmpty() ) cDebug() << "WARNING: no lnftool given for plasmalnf module."; + + QString liveUser; + if ( configurationMap.contains( "liveuser" ) && configurationMap.value( "liveuser" ).type() == QVariant::String ) + liveUser = configurationMap.value( "liveuser" ).toString(); + m_liveUser = liveUser; } void @@ -133,7 +138,10 @@ PlasmaLnfViewStep::themeSelected( const QString& id ) m_themeId = id; QProcess lnftool; - lnftool.start( m_lnfPath, {"--resetLayout", "--apply", id} ); + if ( !m_liveUser.isEmpty() ) + lnftool.start( "sudo", {"-E", "-H", "-u", m_liveUser, m_lnfPath, "--resetLayout", "--apply", id} ); + else + lnftool.start( m_lnfPath, {"--resetLayout", "--apply", id} ); if ( !lnftool.waitForStarted( 1000 ) ) { diff --git a/src/modules/plasmalnf/PlasmaLnfViewStep.h b/src/modules/plasmalnf/PlasmaLnfViewStep.h index e65b59b93..7fcfc50cc 100644 --- a/src/modules/plasmalnf/PlasmaLnfViewStep.h +++ b/src/modules/plasmalnf/PlasmaLnfViewStep.h @@ -63,6 +63,7 @@ private: PlasmaLnfPage* m_widget; QString m_lnfPath; QString m_themeId; + QString m_liveUser; }; CALAMARES_PLUGIN_FACTORY_DECLARATION( PlasmaLnfViewStepFactory ) diff --git a/src/modules/plasmalnf/plasmalnf.conf b/src/modules/plasmalnf/plasmalnf.conf index d9817ecbc..059ed9e36 100644 --- a/src/modules/plasmalnf/plasmalnf.conf +++ b/src/modules/plasmalnf/plasmalnf.conf @@ -2,3 +2,9 @@ # Full path to the Plasma look-and-feel tool (CLI program # for querying and applying Plasma themes). lnftool: "/usr/bin/lookandfeeltool" + +# For systems where the user Calamares runs as (usually root, +# via either sudo or pkexec) has a clean environment, set this +# to the originating username; the lnftool will be run through +# "sudo -H -u " instead of directly. +liveuser: "live" From 02dfe51d55dc1443d43019b133665d40fde979b6 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 4 Dec 2017 10:47:26 -0500 Subject: [PATCH 8/8] [welcome] Improve error reporting from requirements checker --- .../welcome/checker/RequirementsChecker.cpp | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/modules/welcome/checker/RequirementsChecker.cpp b/src/modules/welcome/checker/RequirementsChecker.cpp index 3d4e394c4..e56e88a4c 100644 --- a/src/modules/welcome/checker/RequirementsChecker.cpp +++ b/src/modules/welcome/checker/RequirementsChecker.cpp @@ -213,12 +213,16 @@ RequirementsChecker::setConfigurationMap( const QVariantMap& configurationMap ) bool ok = false; m_requiredStorageGB = configurationMap.value( "requiredStorage" ).toDouble( &ok ); if ( !ok ) + { + cDebug() << "WARNING: RequirementsChecker entry 'requiredStorage' is invalid."; m_requiredStorageGB = 3.; + } Calamares::JobQueue::instance()->globalStorage()->insert( "requiredStorageGB", m_requiredStorageGB ); } else { + cDebug() << "WARNING: RequirementsChecker entry 'requiredStorage' is missing."; m_requiredStorageGB = 3.; incompleteConfiguration = true; } @@ -231,12 +235,14 @@ RequirementsChecker::setConfigurationMap( const QVariantMap& configurationMap ) m_requiredRamGB = configurationMap.value( "requiredRam" ).toDouble( &ok ); if ( !ok ) { + cDebug() << "WARNING: RequirementsChecker entry 'requiredRam' is invalid."; m_requiredRamGB = 1.; incompleteConfiguration = true; } } else { + cDebug() << "WARNING: RequirementsChecker entry 'requiredRam' is missing."; m_requiredRamGB = 1.; incompleteConfiguration = true; } @@ -248,7 +254,7 @@ RequirementsChecker::setConfigurationMap( const QVariantMap& configurationMap ) if ( m_checkHasInternetUrl.isEmpty() || !QUrl( m_checkHasInternetUrl ).isValid() ) { - cDebug() << "Invalid internetCheckUrl in welcome.conf" << m_checkHasInternetUrl + cDebug() << "WARNING: RequirementsChecker entry 'internetCheckUrl' is invalid in welcome.conf" << m_checkHasInternetUrl << "reverting to default (http://example.com)."; m_checkHasInternetUrl = "http://example.com"; incompleteConfiguration = true; @@ -256,8 +262,9 @@ RequirementsChecker::setConfigurationMap( const QVariantMap& configurationMap ) } else { - cDebug() << "internetCheckUrl is undefined in welcome.conf, " + cDebug() << "WARNING: RequirementsChecker entry 'internetCheckUrl' is undefined in welcome.conf," "reverting to default (http://example.com)."; + m_checkHasInternetUrl = "http://example.com"; incompleteConfiguration = true; } @@ -269,7 +276,10 @@ RequirementsChecker::setConfigurationMap( const QVariantMap& configurationMap ) m_entriesToCheck.append( configurationMap.value( "check" ).toStringList() ); } else + { + cDebug() << "WARNING: RequirementsChecker entry 'check' is incomplete."; incompleteConfiguration = true; + } if ( configurationMap.contains( "required" ) && configurationMap.value( "required" ).type() == QVariant::List ) @@ -278,18 +288,13 @@ RequirementsChecker::setConfigurationMap( const QVariantMap& configurationMap ) m_entriesToRequire.append( configurationMap.value( "required" ).toStringList() ); } else + { + cDebug() << "WARNING: RequirementsChecker entry 'required' is incomplete."; incompleteConfiguration = true; + } if ( incompleteConfiguration ) - { - cDebug() << "WARNING: The RequirementsChecker configuration map provided by " - "the welcome module configuration file is incomplete or " - "incorrect.\n" - "Startup will continue for debugging purposes, but one or " - "more checks might not function correctly.\n" - "RequirementsChecker configuration map:\n" - << configurationMap; - } + cDebug() << "WARNING: RequirementsChecker configuration map:\n" << configurationMap; }