From 1f49f764a6328d557d623bc80ea4311e3eb3bd52 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sun, 3 Dec 2017 10:09:00 -0500 Subject: [PATCH 01/27] [libcalamares] Allow retrieving chroot mode from system (as well as settings) --- src/libcalamares/utils/CalamaresUtilsSystem.cpp | 7 ++++++- src/libcalamares/utils/CalamaresUtilsSystem.h | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/libcalamares/utils/CalamaresUtilsSystem.cpp b/src/libcalamares/utils/CalamaresUtilsSystem.cpp index 656a57c10..1f910230d 100644 --- a/src/libcalamares/utils/CalamaresUtilsSystem.cpp +++ b/src/libcalamares/utils/CalamaresUtilsSystem.cpp @@ -256,5 +256,10 @@ System::getTotalMemoryB() #endif } - +bool +System::doChroot() const +{ + return m_doChroot; } + +} // namespace diff --git a/src/libcalamares/utils/CalamaresUtilsSystem.h b/src/libcalamares/utils/CalamaresUtilsSystem.h index 1ccdfb516..8eeff4ef9 100644 --- a/src/libcalamares/utils/CalamaresUtilsSystem.h +++ b/src/libcalamares/utils/CalamaresUtilsSystem.h @@ -114,6 +114,8 @@ public: */ DLLEXPORT QPair getTotalMemoryB(); + DLLEXPORT bool doChroot() const; + private: static System* s_instance; From cddc4699aa6b53e3a161d2aeb762a4d2ad660942 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sun, 3 Dec 2017 12:47:41 -0500 Subject: [PATCH 02/27] [plasmalnf] Import Plasma Look-and-Feel module independently --- src/modules/plasmalnf/CMakeLists.txt | 21 +++ src/modules/plasmalnf/PlasmaLnfInfo.cpp | 140 ++++++++++++++++++++ src/modules/plasmalnf/PlasmaLnfInfo.h | 39 ++++++ src/modules/plasmalnf/PlasmaLnfJob.cpp | 93 +++++++++++++ src/modules/plasmalnf/PlasmaLnfJob.h | 46 +++++++ src/modules/plasmalnf/PlasmaLnfPage.cpp | 70 ++++++++++ src/modules/plasmalnf/PlasmaLnfPage.h | 46 +++++++ src/modules/plasmalnf/PlasmaLnfViewStep.cpp | 138 +++++++++++++++++++ src/modules/plasmalnf/PlasmaLnfViewStep.h | 70 ++++++++++ src/modules/plasmalnf/page_plasmalnf.qrc | 1 + src/modules/plasmalnf/page_plasmalnf.ui | 53 ++++++++ src/modules/plasmalnf/plasmalnf.conf | 4 + 12 files changed, 721 insertions(+) create mode 100644 src/modules/plasmalnf/CMakeLists.txt create mode 100644 src/modules/plasmalnf/PlasmaLnfInfo.cpp create mode 100644 src/modules/plasmalnf/PlasmaLnfInfo.h create mode 100644 src/modules/plasmalnf/PlasmaLnfJob.cpp create mode 100644 src/modules/plasmalnf/PlasmaLnfJob.h create mode 100644 src/modules/plasmalnf/PlasmaLnfPage.cpp create mode 100644 src/modules/plasmalnf/PlasmaLnfPage.h create mode 100644 src/modules/plasmalnf/PlasmaLnfViewStep.cpp create mode 100644 src/modules/plasmalnf/PlasmaLnfViewStep.h create mode 100644 src/modules/plasmalnf/page_plasmalnf.qrc create mode 100644 src/modules/plasmalnf/page_plasmalnf.ui create mode 100644 src/modules/plasmalnf/plasmalnf.conf diff --git a/src/modules/plasmalnf/CMakeLists.txt b/src/modules/plasmalnf/CMakeLists.txt new file mode 100644 index 000000000..9b3ccf716 --- /dev/null +++ b/src/modules/plasmalnf/CMakeLists.txt @@ -0,0 +1,21 @@ +find_package(ECM ${ECM_VERSION} REQUIRED NO_MODULE) + +find_package( KF5 5.29 REQUIRED CoreAddons Plasma Service Package ) + +calamares_add_plugin( plasmalnf + TYPE viewmodule + EXPORT_MACRO PLUGINDLLEXPORT_PRO + SOURCES + PlasmaLnfViewStep.cpp + PlasmaLnfPage.cpp + PlasmaLnfJob.cpp + PlasmaLnfInfo.cpp + UI + page_plasmalnf.ui + LINK_PRIVATE_LIBRARIES + calamaresui + KF5::Package + 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..6e9249825 --- /dev/null +++ b/src/modules/plasmalnf/PlasmaLnfInfo.cpp @@ -0,0 +1,140 @@ +/* === 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 +{ + +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() +{ + 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 new file mode 100644 index 000000000..27adc224c --- /dev/null +++ b/src/modules/plasmalnf/PlasmaLnfInfo.h @@ -0,0 +1,39 @@ +/* === 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& ); + + /* 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/PlasmaLnfJob.cpp b/src/modules/plasmalnf/PlasmaLnfJob.cpp new file mode 100644 index 000000000..e6a4fbe10 --- /dev/null +++ b/src/modules/plasmalnf/PlasmaLnfJob.cpp @@ -0,0 +1,93 @@ +/* === 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 "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 "utils/CalamaresUtilsSystem.h" +#include "utils/Logger.h" + +PlasmaLnfJob::PlasmaLnfJob( const QString& lnfPath, const QString& id ) + : m_lnfPath( lnfPath ) + , m_id(id) +{ +} + + +PlasmaLnfJob::~PlasmaLnfJob() +{ +} + + +QString +PlasmaLnfJob::prettyName() const +{ + return tr( "Plasma Look-and-Feel Job" ); +} + +QString +PlasmaLnfJob::prettyDescription() const +{ + return prettyName(); +} + +QString PlasmaLnfJob::prettyStatusMessage() const +{ + return prettyName(); +} + + +Calamares::JobResult +PlasmaLnfJob::exec() +{ + cDebug() << "Plasma Look-and-Feel Job"; + + 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; + + int r = system->targetEnvCall( command ); + 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" ) ); + + return Calamares::JobResult::ok(); +} + diff --git a/src/modules/plasmalnf/PlasmaLnfJob.h b/src/modules/plasmalnf/PlasmaLnfJob.h new file mode 100644 index 000000000..c7a7726ed --- /dev/null +++ b/src/modules/plasmalnf/PlasmaLnfJob.h @@ -0,0 +1,46 @@ +/* === 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 PLASMALNFJOB_H +#define PLASMALNFJOB_H + +#include +#include + +#include + +class PlasmaLnfJob : public Calamares::Job +{ + Q_OBJECT + +public: + explicit PlasmaLnfJob( const QString& lnfPath, const QString& id ); + virtual ~PlasmaLnfJob() override; + + QString prettyName() const override; + QString prettyDescription() const override; + QString prettyStatusMessage() const override; + + Calamares::JobResult exec() override; + +private: + QString m_lnfPath; + QString m_id; +}; + +#endif // PLASMALNFJOB_H diff --git a/src/modules/plasmalnf/PlasmaLnfPage.cpp b/src/modules/plasmalnf/PlasmaLnfPage.cpp new file mode 100644 index 000000000..632b9f13a --- /dev/null +++ b/src/modules/plasmalnf/PlasmaLnfPage.cpp @@ -0,0 +1,70 @@ +/* === 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 "PlasmaLnfPage.h" +#include "PlasmaLnfInfo.h" + +#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 + +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." ) ); + ) + + Calamares::themes_by_package(); + ui->lnfCombo->addItems( Calamares::plasma_themes() ); + + QObject::connect(ui->lnfCombo, &QComboBox::activated, this, &PlasmaLnfPage::activated); +} + +void +PlasmaLnfPage::activated(const QString& name) +{ + cDebug() << "Changed to" << name; + + QProcess lnftool; + lnftool.start( Calamares::lnftool(), {"--resetLayout", "--apply", name} ); + + if ( lnftool.waitForStarted(1000) && lnftool.waitForFinished( 1000 ) && (lnftool.exitCode() == 0) && (lnftool.exitStatus() == QProcess::NormalExit ) ) + ; // OK + else + cDebug() << "WARNING: could not apply look-and-feel" << name; + + + emit plasmaThemeSelected( name ); +} diff --git a/src/modules/plasmalnf/PlasmaLnfPage.h b/src/modules/plasmalnf/PlasmaLnfPage.h new file mode 100644 index 000000000..ceed37044 --- /dev/null +++ b/src/modules/plasmalnf/PlasmaLnfPage.h @@ -0,0 +1,46 @@ +/* === 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 PLASMALNFPAGE_H +#define PLASMALNFPAGE_H + +#include +#include + +namespace Ui +{ +class PlasmaLnfPage; +} + +class PlasmaLnfPage : public QWidget +{ + Q_OBJECT +public: + explicit PlasmaLnfPage( QWidget* parent = nullptr ); + +public slots: + void activated(const QString& name); + +signals: + void plasmaThemeSelected( const QString &id ); + +private: + Ui::PlasmaLnfPage* ui; +}; + +#endif //PLASMALNFPAGE_H diff --git a/src/modules/plasmalnf/PlasmaLnfViewStep.cpp b/src/modules/plasmalnf/PlasmaLnfViewStep.cpp new file mode 100644 index 000000000..73f89091b --- /dev/null +++ b/src/modules/plasmalnf/PlasmaLnfViewStep.cpp @@ -0,0 +1,138 @@ +/* === 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 "JobQueue.h" +#include "GlobalStorage.h" +#include "utils/Logger.h" +#include "utils/CalamaresUtils.h" +#include "utils/CalamaresUtilsSystem.h" + +#include "PlasmaLnfInfo.h" +#include "PlasmaLnfJob.h" +#include "PlasmaLnfPage.h" +#include "PlasmaLnfViewStep.h" + +#include +#include + +CALAMARES_PLUGIN_FACTORY_DEFINITION( PlasmaLnfViewStepFactory, registerPlugin(); ) + +PlasmaLnfViewStep::PlasmaLnfViewStep( QObject* parent ) + : Calamares::ViewStep( parent ) + , m_widget( new PlasmaLnfPage ) +{ + connect( m_widget, &PlasmaLnfPage::plasmaThemeSelected, this, &PlasmaLnfViewStep::themeSelected ); + emit nextStatusChanged( false ); +} + + +PlasmaLnfViewStep::~PlasmaLnfViewStep() +{ + if ( m_widget && m_widget->parent() == nullptr ) + m_widget->deleteLater(); +} + + +QString +PlasmaLnfViewStep::prettyName() const +{ + return tr( "Look-and-Feel" ); +} + + +QWidget* +PlasmaLnfViewStep::widget() +{ + return m_widget; +} + + +void +PlasmaLnfViewStep::next() +{ + emit done(); +} + + +void +PlasmaLnfViewStep::back() +{} + + +bool +PlasmaLnfViewStep::isNextEnabled() const +{ + return true; +} + + +bool +PlasmaLnfViewStep::isBackEnabled() const +{ + return true; +} + + +bool +PlasmaLnfViewStep::isAtBeginning() const +{ + return true; +} + + +bool +PlasmaLnfViewStep::isAtEnd() const +{ + return true; +} + + +void PlasmaLnfViewStep::onLeave() +{ +} + + +Calamares::JobList +PlasmaLnfViewStep::jobs() const +{ + Calamares::JobList l; + + 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; +} + + +void +PlasmaLnfViewStep::setConfigurationMap( const QVariantMap& configurationMap ) +{ + m_lnfPath = CalamaresUtils::getString( configurationMap, "lnftool" ); + Calamares::set_lnftool( m_lnfPath ); + + if (m_lnfPath.isEmpty()) + cDebug() << "WARNING: no lnftool given for plasmalnf module."; +} + +void +PlasmaLnfViewStep::themeSelected( const QString& id ) +{ + m_themeId = id; +} diff --git a/src/modules/plasmalnf/PlasmaLnfViewStep.h b/src/modules/plasmalnf/PlasmaLnfViewStep.h new file mode 100644 index 000000000..c2bcce2c0 --- /dev/null +++ b/src/modules/plasmalnf/PlasmaLnfViewStep.h @@ -0,0 +1,70 @@ +/* === 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 PLASMALNFVIEWSTEP_H +#define PLASMALNFVIEWSTEP_H + +#include +#include +#include + +#include +#include +#include + +class PlasmaLnfPage; + +class PLUGINDLLEXPORT PlasmaLnfViewStep : public Calamares::ViewStep +{ + Q_OBJECT + +public: + explicit PlasmaLnfViewStep( QObject* parent = nullptr ); + virtual ~PlasmaLnfViewStep() override; + + QString prettyName() const override; + + QWidget* widget() override; + + void next() override; + void back() override; + + bool isNextEnabled() const override; + bool isBackEnabled() const override; + + bool isAtBeginning() const override; + bool isAtEnd() const override; + + void onLeave() override; + + Calamares::JobList jobs() const override; + + void setConfigurationMap( const QVariantMap& configurationMap ) override; + +public slots: + void themeSelected( const QString &id ); + +private: + PlasmaLnfPage* m_widget; + QString m_lnfPath; + QString m_themeId; +}; + +CALAMARES_PLUGIN_FACTORY_DECLARATION( PlasmaLnfViewStepFactory ) + +#endif // PLASMALNFVIEWSTEP_H diff --git a/src/modules/plasmalnf/page_plasmalnf.qrc b/src/modules/plasmalnf/page_plasmalnf.qrc new file mode 100644 index 000000000..7646d2b36 --- /dev/null +++ b/src/modules/plasmalnf/page_plasmalnf.qrc @@ -0,0 +1 @@ + diff --git a/src/modules/plasmalnf/page_plasmalnf.ui b/src/modules/plasmalnf/page_plasmalnf.ui new file mode 100644 index 000000000..340527ad0 --- /dev/null +++ b/src/modules/plasmalnf/page_plasmalnf.ui @@ -0,0 +1,53 @@ + + + PlasmaLnfPage + + + + 0 + 0 + 799 + 400 + + + + Form + + + + + + margin-bottom: 1ex; +margin-left: 2em; + + + Placeholder + + + true + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + diff --git a/src/modules/plasmalnf/plasmalnf.conf b/src/modules/plasmalnf/plasmalnf.conf new file mode 100644 index 000000000..d9817ecbc --- /dev/null +++ b/src/modules/plasmalnf/plasmalnf.conf @@ -0,0 +1,4 @@ +--- +# Full path to the Plasma look-and-feel tool (CLI program +# for querying and applying Plasma themes). +lnftool: "/usr/bin/lookandfeeltool" From 3a94f02547b2b39884680ac7e185ddab489a03f7 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 31 Oct 2017 08:25:57 -0400 Subject: [PATCH 03/27] CMake: look for ECM at top-level, add to search path if found. --- CMakeLists.txt | 10 ++++++++++ src/modules/interactiveterminal/CMakeLists.txt | 3 +-- src/modules/partition/CMakeLists.txt | 3 +-- src/modules/users/CMakeLists.txt | 3 +-- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dce53b416..ad579be2c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -114,6 +114,16 @@ find_package( Qt5 ${QT_VERSION} CONFIG REQUIRED Core Gui Widgets LinguistTools S find_package( YAMLCPP 0.5.1 REQUIRED ) find_package( PolkitQt5-1 REQUIRED ) +# Find ECM once, and add it to the module search path; Calamares +# modules that need ECM can do +# find_package(ECM ${ECM_VERSION} REQUIRED NO_MODULE), +# no need to mess with the module path after. +set( ECM_VERSION 5.10.0 ) +find_package(ECM ${ECM_VERSION} NO_MODULE) +if( ECM_FOUND ) + set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${CMAKE_MODULE_PATH}) +endif() + option( INSTALL_CONFIG "Install configuration files" ON ) option( WITH_PYTHON "Enable Python modules API (requires Boost.Python)." ON ) option( WITH_PYTHONQT "Enable next generation Python modules API (experimental, requires PythonQt)." OFF ) diff --git a/src/modules/interactiveterminal/CMakeLists.txt b/src/modules/interactiveterminal/CMakeLists.txt index 7b35fae0d..71f6bae14 100644 --- a/src/modules/interactiveterminal/CMakeLists.txt +++ b/src/modules/interactiveterminal/CMakeLists.txt @@ -1,5 +1,4 @@ -find_package(ECM 5.10.0 REQUIRED NO_MODULE) -set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${CMAKE_MODULE_PATH}) +find_package(ECM ${ECM_VERSION} REQUIRED NO_MODULE) include(KDEInstallDirs) include(GenerateExportHeader) diff --git a/src/modules/partition/CMakeLists.txt b/src/modules/partition/CMakeLists.txt index ee96c4275..c58eb1d69 100644 --- a/src/modules/partition/CMakeLists.txt +++ b/src/modules/partition/CMakeLists.txt @@ -1,5 +1,4 @@ -find_package(ECM 5.10.0 REQUIRED NO_MODULE) -set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${CMAKE_MODULE_PATH}) +find_package(ECM ${ECM_VERSION} REQUIRED NO_MODULE) include(KDEInstallDirs) include(GenerateExportHeader) diff --git a/src/modules/users/CMakeLists.txt b/src/modules/users/CMakeLists.txt index 074118d54..ebff9df8c 100644 --- a/src/modules/users/CMakeLists.txt +++ b/src/modules/users/CMakeLists.txt @@ -1,6 +1,5 @@ -find_package(ECM 5.10.0 NO_MODULE) +find_package(ECM ${ECM_VERSION} NO_MODULE) if( ECM_FOUND ) - set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${CMAKE_MODULE_PATH}) include( ECMAddTests ) endif() From ac92d4911d4f52add6ccd40710653ccecf5116f2 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sun, 3 Dec 2017 12:58:54 -0500 Subject: [PATCH 04/27] Compatibility: revert conveniences from master --- src/modules/plasmalnf/PlasmaLnfViewStep.cpp | 9 ++++++--- src/modules/plasmalnf/PlasmaLnfViewStep.h | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/modules/plasmalnf/PlasmaLnfViewStep.cpp b/src/modules/plasmalnf/PlasmaLnfViewStep.cpp index 73f89091b..1beb71d2e 100644 --- a/src/modules/plasmalnf/PlasmaLnfViewStep.cpp +++ b/src/modules/plasmalnf/PlasmaLnfViewStep.cpp @@ -107,10 +107,10 @@ void PlasmaLnfViewStep::onLeave() } -Calamares::JobList +QList PlasmaLnfViewStep::jobs() const { - Calamares::JobList l; + QList l; cDebug() << "Creating Plasma LNF jobs .."; if ( !m_themeId.isEmpty() && !m_lnfPath.isEmpty() ) @@ -124,7 +124,10 @@ PlasmaLnfViewStep::jobs() const void PlasmaLnfViewStep::setConfigurationMap( const QVariantMap& configurationMap ) { - m_lnfPath = CalamaresUtils::getString( configurationMap, "lnftool" ); + QString lnfPath; + if ( configurationMap.contains( "lnftool" ) && configurationMap.value( "lnftool" ).type() == QVariant::String ) + lnfPath = configurationMap.value( "lnftool" ).toString(); + m_lnfPath = lnfPath; Calamares::set_lnftool( m_lnfPath ); if (m_lnfPath.isEmpty()) diff --git a/src/modules/plasmalnf/PlasmaLnfViewStep.h b/src/modules/plasmalnf/PlasmaLnfViewStep.h index c2bcce2c0..4d2598ccc 100644 --- a/src/modules/plasmalnf/PlasmaLnfViewStep.h +++ b/src/modules/plasmalnf/PlasmaLnfViewStep.h @@ -52,7 +52,7 @@ public: void onLeave() override; - Calamares::JobList jobs() const override; + QList jobs() const override; void setConfigurationMap( const QVariantMap& configurationMap ) override; From 4e2e55a93503faefc304ab2676db341f132e3766 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sun, 3 Dec 2017 15:24:39 -0500 Subject: [PATCH 05/27] [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 06/27] [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 07/27] [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 08/27] [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 09/27] [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 10/27] [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 11/27] [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 12/27] [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; } From 98b9f67e3944452b38baf4577dddcc87c011845a Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 4 Dec 2017 11:51:16 -0500 Subject: [PATCH 13/27] [plasmalnf] Complain more loudly (and more often) when badly configured --- src/modules/plasmalnf/PlasmaLnfViewStep.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/modules/plasmalnf/PlasmaLnfViewStep.cpp b/src/modules/plasmalnf/PlasmaLnfViewStep.cpp index fd6eab78d..452be8680 100644 --- a/src/modules/plasmalnf/PlasmaLnfViewStep.cpp +++ b/src/modules/plasmalnf/PlasmaLnfViewStep.cpp @@ -136,6 +136,11 @@ void PlasmaLnfViewStep::themeSelected( const QString& id ) { m_themeId = id; + if ( m_lnfPath.isEmpty() ) + { + cDebug() << "WARNING: no lnftool given for plasmalnf module."; + return; + } QProcess lnftool; if ( !m_liveUser.isEmpty() ) From ad69eda337ece7aeb871b6a8d22a20ea09db578c Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 4 Dec 2017 11:54:33 -0500 Subject: [PATCH 14/27] [plasmalnf] Complain again if poorly configured --- src/modules/plasmalnf/PlasmaLnfViewStep.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/modules/plasmalnf/PlasmaLnfViewStep.cpp b/src/modules/plasmalnf/PlasmaLnfViewStep.cpp index 452be8680..f4e01b711 100644 --- a/src/modules/plasmalnf/PlasmaLnfViewStep.cpp +++ b/src/modules/plasmalnf/PlasmaLnfViewStep.cpp @@ -108,8 +108,13 @@ PlasmaLnfViewStep::jobs() const QList l; cDebug() << "Creating Plasma LNF jobs .."; - if ( !m_themeId.isEmpty() && !m_lnfPath.isEmpty() ) - l.append( Calamares::job_ptr( new PlasmaLnfJob( m_lnfPath, m_themeId ) ) ); + if ( !m_themeId.isEmpty() ) + { + if ( !m_lnfPath.isEmpty() ) + l.append( Calamares::job_ptr( new PlasmaLnfJob( m_lnfPath, m_themeId ) ) ); + else + cDebug() << "WARNING: no lnftool given for plasmalnf module."; + } return l; } From 6bd8c67ca9fc7337d87a0e80221571d397bd28e1 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 4 Dec 2017 12:27:30 -0500 Subject: [PATCH 15/27] [plasmalnf] Allow filtering the selectable lnf themes - empty list allows all of them - always suppress hidden, invalid themes, and those named --- src/modules/plasmalnf/PlasmaLnfPage.cpp | 29 +++++++++++++++------ src/modules/plasmalnf/PlasmaLnfPage.h | 5 ++++ src/modules/plasmalnf/PlasmaLnfViewStep.cpp | 9 +++++++ src/modules/plasmalnf/plasmalnf.conf | 16 ++++++++++-- 4 files changed, 49 insertions(+), 10 deletions(-) diff --git a/src/modules/plasmalnf/PlasmaLnfPage.cpp b/src/modules/plasmalnf/PlasmaLnfPage.cpp index 01759ba32..21e097a0e 100644 --- a/src/modules/plasmalnf/PlasmaLnfPage.cpp +++ b/src/modules/plasmalnf/PlasmaLnfPage.cpp @@ -34,11 +34,11 @@ static PlasmaLnfList plasma_themes() for ( const KPluginMetaData& data : pkgs ) { - 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(); + if ( data.isValid() && !data.isHidden() && !data.name().isEmpty() ) + { + packages << PlasmaLnfDescriptor{ data.pluginId(), data.name() }; + cDebug() << "LNF Package" << data.pluginId(); + } } return packages; @@ -55,9 +55,7 @@ PlasmaLnfPage::PlasmaLnfPage( QWidget* parent ) 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 ); + winnowThemes(); } ) @@ -83,3 +81,18 @@ PlasmaLnfPage::setLnfPath( const QString& path ) { m_lnfPath = path; } + +void +PlasmaLnfPage::setEnabledThemes(const QStringList& themes) +{ + m_enabledThemes = themes; + winnowThemes(); +} + +void PlasmaLnfPage::winnowThemes() +{ + ui->lnfCombo->clear(); + for ( const auto& p : m_availableLnf ) + if ( m_enabledThemes.isEmpty() || m_enabledThemes.contains( p.id ) ) + ui->lnfCombo->addItem( p.name ); +} diff --git a/src/modules/plasmalnf/PlasmaLnfPage.h b/src/modules/plasmalnf/PlasmaLnfPage.h index 31731eb0d..89867cabf 100644 --- a/src/modules/plasmalnf/PlasmaLnfPage.h +++ b/src/modules/plasmalnf/PlasmaLnfPage.h @@ -21,6 +21,7 @@ #include #include +#include #include namespace Ui @@ -43,6 +44,7 @@ public: explicit PlasmaLnfPage( QWidget* parent = nullptr ); void setLnfPath( const QString& path ); + void setEnabledThemes( const QStringList& themes ); public slots: void activated( int index ); @@ -51,8 +53,11 @@ signals: void plasmaThemeSelected( const QString& id ); private: + void winnowThemes(); + Ui::PlasmaLnfPage* ui; QString m_lnfPath; + QStringList m_enabledThemes; PlasmaLnfList m_availableLnf; }; diff --git a/src/modules/plasmalnf/PlasmaLnfViewStep.cpp b/src/modules/plasmalnf/PlasmaLnfViewStep.cpp index f4e01b711..550e42a17 100644 --- a/src/modules/plasmalnf/PlasmaLnfViewStep.cpp +++ b/src/modules/plasmalnf/PlasmaLnfViewStep.cpp @@ -135,6 +135,15 @@ PlasmaLnfViewStep::setConfigurationMap( const QVariantMap& configurationMap ) if ( configurationMap.contains( "liveuser" ) && configurationMap.value( "liveuser" ).type() == QVariant::String ) liveUser = configurationMap.value( "liveuser" ).toString(); m_liveUser = liveUser; + + if ( configurationMap.contains( "themes" ) && + configurationMap.value( "themes" ).type() == QVariant::List ) + { + QStringList enabledThemes( configurationMap.value( "themes" ).toStringList() ); + if ( enabledThemes.length() == 1 ) + cDebug() << "WARNING: only one theme enabled in plasmalnf"; + m_widget->setEnabledThemes( enabledThemes ); + } } void diff --git a/src/modules/plasmalnf/plasmalnf.conf b/src/modules/plasmalnf/plasmalnf.conf index 059ed9e36..a35b50da6 100644 --- a/src/modules/plasmalnf/plasmalnf.conf +++ b/src/modules/plasmalnf/plasmalnf.conf @@ -1,10 +1,22 @@ --- # Full path to the Plasma look-and-feel tool (CLI program -# for querying and applying Plasma themes). +# for querying and applying Plasma themes). If this is not +# set, no LNF setting will happen. 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" +# +# liveuser: "live" + +# You can limit the list of Plasma look-and-feel themes by listing ids +# here. If this key is not present, or the list is empty, all of the +# installed themes are listed. If only one theme is listed, why are +# you using this module at all? +# +themes: + - org.kde.breeze.desktop + # - org.kde.breezedark.desktop + From 748ccf94e98d27642c2e72e14546d39ef5167469 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 12 Dec 2017 05:42:35 -0500 Subject: [PATCH 16/27] [plasmalnf] Enrich config file - Extend the config file format to allow theme, image pairs as well as just naming the themes. - Reduce verbosity when querying Plasma themes. --- src/modules/plasmalnf/PlasmaLnfPage.cpp | 33 +++++---- src/modules/plasmalnf/PlasmaLnfPage.h | 15 ++--- src/modules/plasmalnf/PlasmaLnfViewStep.cpp | 17 ++++- src/modules/plasmalnf/ThemeInfo.h | 75 +++++++++++++++++++++ src/modules/plasmalnf/plasmalnf.conf | 12 ++-- 5 files changed, 122 insertions(+), 30 deletions(-) create mode 100644 src/modules/plasmalnf/ThemeInfo.h diff --git a/src/modules/plasmalnf/PlasmaLnfPage.cpp b/src/modules/plasmalnf/PlasmaLnfPage.cpp index 21e097a0e..7b68a612f 100644 --- a/src/modules/plasmalnf/PlasmaLnfPage.cpp +++ b/src/modules/plasmalnf/PlasmaLnfPage.cpp @@ -26,9 +26,9 @@ #include #include -static PlasmaLnfList plasma_themes() +static ThemeInfoList plasma_themes() { - PlasmaLnfList packages; + ThemeInfoList packages; QList pkgs = KPackage::PackageLoader::self()->listPackages( "Plasma/LookAndFeel" ); @@ -36,8 +36,7 @@ static PlasmaLnfList plasma_themes() { if ( data.isValid() && !data.isHidden() && !data.name().isEmpty() ) { - packages << PlasmaLnfDescriptor{ data.pluginId(), data.name() }; - cDebug() << "LNF Package" << data.pluginId(); + packages << ThemeInfo{ data.pluginId(), data.name() }; } } @@ -54,7 +53,6 @@ PlasmaLnfPage::PlasmaLnfPage( QWidget* parent ) { ui->retranslateUi( this ); ui->generalExplanation->setText( tr( "Please choose a look-and-feel for the KDE Plasma Desktop, below." ) ); - m_availableLnf = plasma_themes(); winnowThemes(); } ) @@ -65,13 +63,13 @@ PlasmaLnfPage::PlasmaLnfPage( QWidget* parent ) void PlasmaLnfPage::activated( int index ) { - if ( ( index < 0 ) || ( index > m_availableLnf.length() ) ) + if ( ( index < 0 ) || ( index > m_enabledThemes.length() ) ) { cDebug() << "Plasma LNF index" << index << "out of range."; return; } - const PlasmaLnfDescriptor& lnf = m_availableLnf.at( index ); + const ThemeInfo& lnf = m_enabledThemes.at( index ); cDebug() << "Changed to" << index << lnf.id << lnf.name; emit plasmaThemeSelected( lnf.id ); } @@ -83,16 +81,27 @@ PlasmaLnfPage::setLnfPath( const QString& path ) } void -PlasmaLnfPage::setEnabledThemes(const QStringList& themes) +PlasmaLnfPage::setEnabledThemes(const ThemeInfoList& themes) { - m_enabledThemes = themes; + if ( themes.isEmpty() ) + m_enabledThemes = plasma_themes(); + else + m_enabledThemes = themes; winnowThemes(); } void PlasmaLnfPage::winnowThemes() { + auto plasmaThemes = plasma_themes(); ui->lnfCombo->clear(); - for ( const auto& p : m_availableLnf ) - if ( m_enabledThemes.isEmpty() || m_enabledThemes.contains( p.id ) ) - ui->lnfCombo->addItem( p.name ); + for ( auto& enabled_theme : m_enabledThemes ) + { + ThemeInfo* t = plasmaThemes.findById( enabled_theme.id ); + if ( t != nullptr ) + { + enabled_theme.name = t->name; + ui->lnfCombo->addItem( enabled_theme.name ); + cDebug() << "Enabled" << enabled_theme.id << "as" << enabled_theme.name; + } + } } diff --git a/src/modules/plasmalnf/PlasmaLnfPage.h b/src/modules/plasmalnf/PlasmaLnfPage.h index 89867cabf..279f83d27 100644 --- a/src/modules/plasmalnf/PlasmaLnfPage.h +++ b/src/modules/plasmalnf/PlasmaLnfPage.h @@ -24,19 +24,13 @@ #include #include +#include "ThemeInfo.h" + namespace Ui { class PlasmaLnfPage; } -struct PlasmaLnfDescriptor -{ - QString id; - QString name; -} ; - -using PlasmaLnfList = QList; - class PlasmaLnfPage : public QWidget { Q_OBJECT @@ -44,7 +38,7 @@ public: explicit PlasmaLnfPage( QWidget* parent = nullptr ); void setLnfPath( const QString& path ); - void setEnabledThemes( const QStringList& themes ); + void setEnabledThemes( const ThemeInfoList& themes ); public slots: void activated( int index ); @@ -57,8 +51,7 @@ private: Ui::PlasmaLnfPage* ui; QString m_lnfPath; - QStringList m_enabledThemes; - PlasmaLnfList m_availableLnf; + ThemeInfoList m_enabledThemes; }; #endif //PLASMALNFPAGE_H diff --git a/src/modules/plasmalnf/PlasmaLnfViewStep.cpp b/src/modules/plasmalnf/PlasmaLnfViewStep.cpp index 550e42a17..ad4e531b5 100644 --- a/src/modules/plasmalnf/PlasmaLnfViewStep.cpp +++ b/src/modules/plasmalnf/PlasmaLnfViewStep.cpp @@ -19,6 +19,7 @@ #include "PlasmaLnfJob.h" #include "PlasmaLnfPage.h" +#include "ThemeInfo.h" #include "utils/Logger.h" @@ -139,10 +140,20 @@ PlasmaLnfViewStep::setConfigurationMap( const QVariantMap& configurationMap ) if ( configurationMap.contains( "themes" ) && configurationMap.value( "themes" ).type() == QVariant::List ) { - QStringList enabledThemes( configurationMap.value( "themes" ).toStringList() ); - if ( enabledThemes.length() == 1 ) + ThemeInfoList allThemes; + auto themeList = configurationMap.value( "themes" ).toList(); + for ( const auto& i : themeList ) + if ( i.type() == QVariant::Map ) + { + auto iv = i.toMap(); + allThemes.append( ThemeInfo( iv.value( "theme" ).toString(), QString(), iv.value( "image" ).toString() ) ); + } + else if ( i.type() == QVariant::String ) + allThemes.append( ThemeInfo( i.toString(), QString() ) ); + + if ( allThemes.length() == 1 ) cDebug() << "WARNING: only one theme enabled in plasmalnf"; - m_widget->setEnabledThemes( enabledThemes ); + m_widget->setEnabledThemes( allThemes ); } } diff --git a/src/modules/plasmalnf/ThemeInfo.h b/src/modules/plasmalnf/ThemeInfo.h new file mode 100644 index 000000000..048c9c8f2 --- /dev/null +++ b/src/modules/plasmalnf/ThemeInfo.h @@ -0,0 +1,75 @@ +/* === 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 PLASMALNF_THEMEINFO_H +#define PLASMALNF_THEMEINFO_H + +#include +#include + +class QDebug; + + +struct ThemeInfo +{ + QString id; + QString name; + QString imagePath; + + ThemeInfo() + {} + + ThemeInfo( const QString& _id, const QString& _name, const QString& image = QString() ) + : id( _id ) + , name( _name ) + , imagePath( image ) + {} + + bool isValid() const { return !id.isEmpty(); } +} ; + +class ThemeInfoList : public QList< ThemeInfo > +{ +public: + ThemeInfo* findById( const QString& id ) + { + for ( ThemeInfo& i : *this ) + { + if ( i.id == id ) + return &i; + } + return nullptr; + } + + const ThemeInfo* findById( const QString& id ) const + { + for ( const ThemeInfo& i : *this ) + { + if ( i.id == id ) + return &i; + } + return nullptr; + } + + bool contains( const QString& id ) const + { + return findById( id ) != nullptr; + } +} ; + +#endif diff --git a/src/modules/plasmalnf/plasmalnf.conf b/src/modules/plasmalnf/plasmalnf.conf index a35b50da6..dc2d57dfd 100644 --- a/src/modules/plasmalnf/plasmalnf.conf +++ b/src/modules/plasmalnf/plasmalnf.conf @@ -14,9 +14,13 @@ lnftool: "/usr/bin/lookandfeeltool" # You can limit the list of Plasma look-and-feel themes by listing ids # here. If this key is not present, or the list is empty, all of the # installed themes are listed. If only one theme is listed, why are -# you using this module at all? +# you using this module at all? Themes may be listed by id, +# (e.g. fluffy-bunny, below) or as a theme and an image (e.g. breeze) +# which will be used to show a screenshot. # themes: - - org.kde.breeze.desktop - # - org.kde.breezedark.desktop - + - theme: org.kde.breeze.desktop + image: "breeze.png" + - theme: org.kde.breezedark.desktop + image: "breeze-dark.png" + - org.kde.fluffy-bunny.desktop From 11fc3e0507f03f2f23f54e26e0eb9fdce0b238e6 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 12 Dec 2017 11:35:35 -0500 Subject: [PATCH 17/27] [plasmalnf] minor documentation - Code documentation - Add another broken example theme, as test for winnowing --- src/modules/plasmalnf/ThemeInfo.h | 13 ++++++++++--- src/modules/plasmalnf/plasmalnf.conf | 1 + 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/modules/plasmalnf/ThemeInfo.h b/src/modules/plasmalnf/ThemeInfo.h index 048c9c8f2..863043969 100644 --- a/src/modules/plasmalnf/ThemeInfo.h +++ b/src/modules/plasmalnf/ThemeInfo.h @@ -22,9 +22,13 @@ #include #include -class QDebug; - - +/** @brief describes a single plasma LnF theme. + * + * A theme description has an id, which is really the name of the desktop + * file (e.g. org.kde.breeze.desktop), a name which is human-readable and + * translated, and an optional image Page, which points to a local screenshot + * of that theme. + */ struct ThemeInfo { QString id; @@ -46,6 +50,7 @@ struct ThemeInfo class ThemeInfoList : public QList< ThemeInfo > { public: + /** @brief Looks for a given @p id in the list of themes, returns nullptr if not found. */ ThemeInfo* findById( const QString& id ) { for ( ThemeInfo& i : *this ) @@ -56,6 +61,7 @@ public: return nullptr; } + /** @brief Looks for a given @p id in the list of themes, returns nullptr if not found. */ const ThemeInfo* findById( const QString& id ) const { for ( const ThemeInfo& i : *this ) @@ -66,6 +72,7 @@ public: return nullptr; } + /** @brief Checks if a given @p id is in the list of themes. */ bool contains( const QString& id ) const { return findById( id ) != nullptr; diff --git a/src/modules/plasmalnf/plasmalnf.conf b/src/modules/plasmalnf/plasmalnf.conf index dc2d57dfd..4aeca2471 100644 --- a/src/modules/plasmalnf/plasmalnf.conf +++ b/src/modules/plasmalnf/plasmalnf.conf @@ -19,6 +19,7 @@ lnftool: "/usr/bin/lookandfeeltool" # which will be used to show a screenshot. # themes: + - org.kde.fuzzy-pig.desktop - theme: org.kde.breeze.desktop image: "breeze.png" - theme: org.kde.breezedark.desktop From 755c0cba184a317b074a679158c311845d73ee44 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 12 Dec 2017 11:40:10 -0500 Subject: [PATCH 18/27] [plasmalnf] Prep-work for UI changes --- src/modules/plasmalnf/PlasmaLnfPage.cpp | 49 ++++++++++++++++++++++--- src/modules/plasmalnf/PlasmaLnfPage.h | 5 +++ 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/src/modules/plasmalnf/PlasmaLnfPage.cpp b/src/modules/plasmalnf/PlasmaLnfPage.cpp index 7b68a612f..60ba79d68 100644 --- a/src/modules/plasmalnf/PlasmaLnfPage.cpp +++ b/src/modules/plasmalnf/PlasmaLnfPage.cpp @@ -53,7 +53,8 @@ PlasmaLnfPage::PlasmaLnfPage( QWidget* parent ) { ui->retranslateUi( this ); ui->generalExplanation->setText( tr( "Please choose a look-and-feel for the KDE Plasma Desktop, below." ) ); - winnowThemes(); + updateThemeNames(); + fillUi(); } ) @@ -87,21 +88,59 @@ PlasmaLnfPage::setEnabledThemes(const ThemeInfoList& themes) m_enabledThemes = plasma_themes(); else m_enabledThemes = themes; + + updateThemeNames(); winnowThemes(); + fillUi(); } -void PlasmaLnfPage::winnowThemes() +void PlasmaLnfPage::updateThemeNames() { auto plasmaThemes = plasma_themes(); - ui->lnfCombo->clear(); for ( auto& enabled_theme : m_enabledThemes ) { ThemeInfo* t = plasmaThemes.findById( enabled_theme.id ); if ( t != nullptr ) { enabled_theme.name = t->name; - ui->lnfCombo->addItem( enabled_theme.name ); - cDebug() << "Enabled" << enabled_theme.id << "as" << enabled_theme.name; } } } + +void PlasmaLnfPage::winnowThemes() +{ + auto plasmaThemes = plasma_themes(); + bool winnowed = true; + int winnow_index = 0; + while ( winnowed ) + { + winnowed = false; + winnow_index = 0; + + for ( auto& enabled_theme : m_enabledThemes ) + { + ThemeInfo* t = plasmaThemes.findById( enabled_theme.id ); + if ( t == nullptr ) + { + cDebug() << "Removing" << enabled_theme.id; + winnowed = true; + break; + } + ++winnow_index; + } + + if ( winnowed ) + { + m_enabledThemes.removeAt( winnow_index ); + } + } +} + +void PlasmaLnfPage::fillUi() +{ + ui->lnfCombo->clear(); + for ( auto& theme : m_enabledThemes ) + { + ui->lnfCombo->addItem( theme.name ); + } +} diff --git a/src/modules/plasmalnf/PlasmaLnfPage.h b/src/modules/plasmalnf/PlasmaLnfPage.h index 279f83d27..6e9f36242 100644 --- a/src/modules/plasmalnf/PlasmaLnfPage.h +++ b/src/modules/plasmalnf/PlasmaLnfPage.h @@ -47,7 +47,12 @@ signals: void plasmaThemeSelected( const QString& id ); private: + /** @brief Intersect the list of enabled themes with the installed ones. */ void winnowThemes(); + /** @brief Get the translated names for all enabled themes. */ + void updateThemeNames(); + /** @brief show enabled themes in the UI. */ + void fillUi(); Ui::PlasmaLnfPage* ui; QString m_lnfPath; From 8b3f71af40b784ee903e9118cc73437a47303d88 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 13 Dec 2017 10:28:31 -0500 Subject: [PATCH 19/27] [plasmalnf] Widget for showing theme info - Radio button + group for button action - Use a (still very primitive) widget for displaying theme information --- src/modules/plasmalnf/CMakeLists.txt | 1 + src/modules/plasmalnf/PlasmaLnfPage.cpp | 36 ++++++++--------- src/modules/plasmalnf/PlasmaLnfPage.h | 8 ++-- src/modules/plasmalnf/ThemeWidget.cpp | 52 +++++++++++++++++++++++++ src/modules/plasmalnf/ThemeWidget.h | 48 +++++++++++++++++++++++ src/modules/plasmalnf/page_plasmalnf.ui | 5 +-- 6 files changed, 125 insertions(+), 25 deletions(-) create mode 100644 src/modules/plasmalnf/ThemeWidget.cpp create mode 100644 src/modules/plasmalnf/ThemeWidget.h diff --git a/src/modules/plasmalnf/CMakeLists.txt b/src/modules/plasmalnf/CMakeLists.txt index 61b44862f..f752755a5 100644 --- a/src/modules/plasmalnf/CMakeLists.txt +++ b/src/modules/plasmalnf/CMakeLists.txt @@ -9,6 +9,7 @@ calamares_add_plugin( plasmalnf PlasmaLnfViewStep.cpp PlasmaLnfPage.cpp PlasmaLnfJob.cpp + ThemeWidget.cpp UI page_plasmalnf.ui LINK_PRIVATE_LIBRARIES diff --git a/src/modules/plasmalnf/PlasmaLnfPage.cpp b/src/modules/plasmalnf/PlasmaLnfPage.cpp index 60ba79d68..e93002855 100644 --- a/src/modules/plasmalnf/PlasmaLnfPage.cpp +++ b/src/modules/plasmalnf/PlasmaLnfPage.cpp @@ -19,6 +19,7 @@ #include "PlasmaLnfPage.h" #include "ui_page_plasmalnf.h" +#include "ThemeWidget.h" #include "utils/Logger.h" #include "utils/Retranslator.h" @@ -47,6 +48,7 @@ static ThemeInfoList plasma_themes() PlasmaLnfPage::PlasmaLnfPage( QWidget* parent ) : QWidget( parent ) , ui( new Ui::PlasmaLnfPage ) + , m_buttonGroup( nullptr ) { ui->setupUi( this ); CALAMARES_RETRANSLATE( @@ -57,22 +59,6 @@ PlasmaLnfPage::PlasmaLnfPage( QWidget* parent ) fillUi(); } ) - - QObject::connect( ui->lnfCombo, &QComboBox::activated, this, &PlasmaLnfPage::activated ); -} - -void -PlasmaLnfPage::activated( int index ) -{ - if ( ( index < 0 ) || ( index > m_enabledThemes.length() ) ) - { - cDebug() << "Plasma LNF index" << index << "out of range."; - return; - } - - const ThemeInfo& lnf = m_enabledThemes.at( index ); - cDebug() << "Changed to" << index << lnf.id << lnf.name; - emit plasmaThemeSelected( lnf.id ); } void @@ -138,9 +124,23 @@ void PlasmaLnfPage::winnowThemes() void PlasmaLnfPage::fillUi() { - ui->lnfCombo->clear(); + if ( m_enabledThemes.isEmpty() ) + { + return; + } + + if ( m_buttonGroup ) + delete m_buttonGroup; + m_buttonGroup = new QButtonGroup( this ); + m_buttonGroup->setExclusive( true ); + + int c = 1; // After the general explanation for ( auto& theme : m_enabledThemes ) { - ui->lnfCombo->addItem( theme.name ); + ThemeWidget* w = new ThemeWidget( theme ); + m_buttonGroup->addButton( w->button() ); + ui->verticalLayout->insertWidget( c, w ); + connect( w, &ThemeWidget::themeSelected, this, &PlasmaLnfPage::plasmaThemeSelected); + ++c; } } diff --git a/src/modules/plasmalnf/PlasmaLnfPage.h b/src/modules/plasmalnf/PlasmaLnfPage.h index 6e9f36242..59fffc93a 100644 --- a/src/modules/plasmalnf/PlasmaLnfPage.h +++ b/src/modules/plasmalnf/PlasmaLnfPage.h @@ -19,12 +19,14 @@ #ifndef PLASMALNFPAGE_H #define PLASMALNFPAGE_H +#include #include #include #include #include #include "ThemeInfo.h" +#include "ThemeWidget.h" namespace Ui { @@ -40,9 +42,6 @@ public: void setLnfPath( const QString& path ); void setEnabledThemes( const ThemeInfoList& themes ); -public slots: - void activated( int index ); - signals: void plasmaThemeSelected( const QString& id ); @@ -57,6 +56,9 @@ private: Ui::PlasmaLnfPage* ui; QString m_lnfPath; ThemeInfoList m_enabledThemes; + + QButtonGroup *m_buttonGroup; + QList< ThemeWidget* > m_widgets; }; #endif //PLASMALNFPAGE_H diff --git a/src/modules/plasmalnf/ThemeWidget.cpp b/src/modules/plasmalnf/ThemeWidget.cpp new file mode 100644 index 000000000..2261c2c4f --- /dev/null +++ b/src/modules/plasmalnf/ThemeWidget.cpp @@ -0,0 +1,52 @@ +/* === 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 "ThemeWidget.h" + +#include "ThemeInfo.h" + +#include +#include +#include + +ThemeWidget::ThemeWidget(const ThemeInfo& info, QWidget* parent) + : QWidget( parent ) + , m_check( new QRadioButton( info.name.isEmpty() ? info.id : info.name, parent ) ) + , m_id( info.id ) +{ + QHBoxLayout* layout = new QHBoxLayout( this ); + this->setLayout( layout ); + + layout->addWidget( m_check ); + layout->addWidget( new QLabel( "Image", this ) ); + + connect( m_check, &QRadioButton::clicked, this, &ThemeWidget::clicked ); +} + +void +ThemeWidget::clicked( bool checked ) +{ + if ( checked ) + emit themeSelected( m_id ); +} + +QAbstractButton* +ThemeWidget::button() const +{ + return m_check; +} diff --git a/src/modules/plasmalnf/ThemeWidget.h b/src/modules/plasmalnf/ThemeWidget.h new file mode 100644 index 000000000..837d362f4 --- /dev/null +++ b/src/modules/plasmalnf/ThemeWidget.h @@ -0,0 +1,48 @@ +/* === 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 PLASMALNF_THEMEWIDGET_H +#define PLASMALNF_THEMEWIDGET_H + +#include + +class QAbstractButton; +class QRadioButton; +class ThemeInfo; + +class ThemeWidget : public QWidget +{ + Q_OBJECT +public: + explicit ThemeWidget( const ThemeInfo& info, QWidget* parent = nullptr ); + + QAbstractButton* button() const; + +signals: + void themeSelected( const QString& id ); + +public slots: + void clicked( bool ); + +private: + QString m_id; + QRadioButton* m_check; +} ; + +#endif + diff --git a/src/modules/plasmalnf/page_plasmalnf.ui b/src/modules/plasmalnf/page_plasmalnf.ui index 340527ad0..dfb906c22 100644 --- a/src/modules/plasmalnf/page_plasmalnf.ui +++ b/src/modules/plasmalnf/page_plasmalnf.ui @@ -13,7 +13,7 @@ Form - + @@ -28,9 +28,6 @@ margin-left: 2em; - - - From 244919d6feb8344c76364a7e0ad31089d8a7ded1 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 14 Dec 2017 17:01:59 -0500 Subject: [PATCH 20/27] [plasmalnf] Add description to theme widget --- src/modules/plasmalnf/PlasmaLnfPage.cpp | 11 +++++++++-- src/modules/plasmalnf/PlasmaLnfViewStep.cpp | 7 +++++-- src/modules/plasmalnf/ThemeInfo.h | 14 ++++++++++++-- src/modules/plasmalnf/ThemeWidget.cpp | 1 + src/modules/plasmalnf/ThemeWidget.h | 3 ++- 5 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/modules/plasmalnf/PlasmaLnfPage.cpp b/src/modules/plasmalnf/PlasmaLnfPage.cpp index e93002855..501827003 100644 --- a/src/modules/plasmalnf/PlasmaLnfPage.cpp +++ b/src/modules/plasmalnf/PlasmaLnfPage.cpp @@ -19,7 +19,6 @@ #include "PlasmaLnfPage.h" #include "ui_page_plasmalnf.h" -#include "ThemeWidget.h" #include "utils/Logger.h" #include "utils/Retranslator.h" @@ -27,6 +26,13 @@ #include #include +ThemeInfo::ThemeInfo( const KPluginMetaData& data ) + : id( data.pluginId() ) + , name( data.name() ) + , description( data.description() ) +{ +} + static ThemeInfoList plasma_themes() { ThemeInfoList packages; @@ -37,7 +43,7 @@ static ThemeInfoList plasma_themes() { if ( data.isValid() && !data.isHidden() && !data.name().isEmpty() ) { - packages << ThemeInfo{ data.pluginId(), data.name() }; + packages << ThemeInfo{ data }; } } @@ -89,6 +95,7 @@ void PlasmaLnfPage::updateThemeNames() if ( t != nullptr ) { enabled_theme.name = t->name; + enabled_theme.description = t->description; } } } diff --git a/src/modules/plasmalnf/PlasmaLnfViewStep.cpp b/src/modules/plasmalnf/PlasmaLnfViewStep.cpp index ad4e531b5..4dcfd2f47 100644 --- a/src/modules/plasmalnf/PlasmaLnfViewStep.cpp +++ b/src/modules/plasmalnf/PlasmaLnfViewStep.cpp @@ -142,14 +142,17 @@ PlasmaLnfViewStep::setConfigurationMap( const QVariantMap& configurationMap ) { ThemeInfoList allThemes; auto themeList = configurationMap.value( "themes" ).toList(); + // Create the ThemInfo objects for the listed themes; information + // about the themes from Plasma (e.g. human-readable name and description) + // are filled in by update_names() in PlasmaLnfPage. for ( const auto& i : themeList ) if ( i.type() == QVariant::Map ) { auto iv = i.toMap(); - allThemes.append( ThemeInfo( iv.value( "theme" ).toString(), QString(), iv.value( "image" ).toString() ) ); + allThemes.append( ThemeInfo( iv.value( "theme" ).toString(), iv.value( "image" ).toString() ) ); } else if ( i.type() == QVariant::String ) - allThemes.append( ThemeInfo( i.toString(), QString() ) ); + allThemes.append( ThemeInfo( i.toString() ) ); if ( allThemes.length() == 1 ) cDebug() << "WARNING: only one theme enabled in plasmalnf"; diff --git a/src/modules/plasmalnf/ThemeInfo.h b/src/modules/plasmalnf/ThemeInfo.h index 863043969..f11083485 100644 --- a/src/modules/plasmalnf/ThemeInfo.h +++ b/src/modules/plasmalnf/ThemeInfo.h @@ -22,6 +22,8 @@ #include #include +class KPluginMetaData; + /** @brief describes a single plasma LnF theme. * * A theme description has an id, which is really the name of the desktop @@ -33,17 +35,25 @@ struct ThemeInfo { QString id; QString name; + QString description; QString imagePath; ThemeInfo() {} - ThemeInfo( const QString& _id, const QString& _name, const QString& image = QString() ) + explicit ThemeInfo( const QString& _id ) + : id( _id ) + { + } + + explicit ThemeInfo( const QString& _id, const QString& image ) : id( _id ) - , name( _name ) , imagePath( image ) {} + // Defined in PlasmaLnfPage.cpp + explicit ThemeInfo( const KPluginMetaData& ); + bool isValid() const { return !id.isEmpty(); } } ; diff --git a/src/modules/plasmalnf/ThemeWidget.cpp b/src/modules/plasmalnf/ThemeWidget.cpp index 2261c2c4f..b2f8143bc 100644 --- a/src/modules/plasmalnf/ThemeWidget.cpp +++ b/src/modules/plasmalnf/ThemeWidget.cpp @@ -34,6 +34,7 @@ ThemeWidget::ThemeWidget(const ThemeInfo& info, QWidget* parent) layout->addWidget( m_check ); layout->addWidget( new QLabel( "Image", this ) ); + layout->addWidget( new QLabel( info.description, this ) ); connect( m_check, &QRadioButton::clicked, this, &ThemeWidget::clicked ); } diff --git a/src/modules/plasmalnf/ThemeWidget.h b/src/modules/plasmalnf/ThemeWidget.h index 837d362f4..42f064039 100644 --- a/src/modules/plasmalnf/ThemeWidget.h +++ b/src/modules/plasmalnf/ThemeWidget.h @@ -23,7 +23,8 @@ class QAbstractButton; class QRadioButton; -class ThemeInfo; + +struct ThemeInfo; class ThemeWidget : public QWidget { From 2db485bb332ea9d7a724aa82f13322e6f0532a29 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 14 Dec 2017 17:04:16 -0500 Subject: [PATCH 21/27] [plasmalnf] Improve layout of theme widget --- src/modules/plasmalnf/ThemeWidget.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/modules/plasmalnf/ThemeWidget.cpp b/src/modules/plasmalnf/ThemeWidget.cpp index b2f8143bc..2c9251e5f 100644 --- a/src/modules/plasmalnf/ThemeWidget.cpp +++ b/src/modules/plasmalnf/ThemeWidget.cpp @@ -32,9 +32,9 @@ ThemeWidget::ThemeWidget(const ThemeInfo& info, QWidget* parent) QHBoxLayout* layout = new QHBoxLayout( this ); this->setLayout( layout ); - layout->addWidget( m_check ); - layout->addWidget( new QLabel( "Image", this ) ); - layout->addWidget( new QLabel( info.description, this ) ); + layout->addWidget( m_check, 1 ); + layout->addWidget( new QLabel( "Image", this ), 1 ); + layout->addWidget( new QLabel( info.description, this ), 3 ); connect( m_check, &QRadioButton::clicked, this, &ThemeWidget::clicked ); } From 3f258d4bd9c8c3f890d4b4e60cd89edd787475d0 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 18 Dec 2017 07:07:47 -0500 Subject: [PATCH 22/27] [plasmalnf] Fallback for image-not-found - calculate a hash of the filename, and use that - makes it possible to distinguish different screenshots even when the image file is missing / badly configured - most colors will be dreadful --- src/modules/plasmalnf/ThemeWidget.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/modules/plasmalnf/ThemeWidget.cpp b/src/modules/plasmalnf/ThemeWidget.cpp index 2c9251e5f..c7256cce3 100644 --- a/src/modules/plasmalnf/ThemeWidget.cpp +++ b/src/modules/plasmalnf/ThemeWidget.cpp @@ -20,6 +20,8 @@ #include "ThemeInfo.h" +#include "utils/Logger.h" + #include #include #include @@ -33,7 +35,25 @@ ThemeWidget::ThemeWidget(const ThemeInfo& info, QWidget* parent) this->setLayout( layout ); layout->addWidget( m_check, 1 ); - layout->addWidget( new QLabel( "Image", this ), 1 ); + + constexpr QSize image_size{240, 160}; + + QPixmap image( info.imagePath ); + if ( image.isNull() ) + { + // Not found or not specified, so convert the name into some (horrible, likely) + // color instead. + image = QPixmap( image_size ); + uint hash_color = qHash( info.imagePath ); + cDebug() << "Theme image" << info.imagePath << "not found, hash" << hash_color; + image.fill( QColor( QRgb( hash_color ) ) ); + } + else + image.scaled( image_size ); + + QLabel* image_label = new QLabel( this ); + image_label->setPixmap( image ); + layout->addWidget( image_label, 1 ); layout->addWidget( new QLabel( info.description, this ), 3 ); connect( m_check, &QRadioButton::clicked, this, &ThemeWidget::clicked ); From cf39dddbf30306954604519dd36e2a659b035315 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 18 Dec 2017 07:20:32 -0500 Subject: [PATCH 23/27] [plasmalnf] Prevent duplicate widgets - Only create widgets for themes once - Update visible texts as needed --- src/modules/plasmalnf/PlasmaLnfPage.cpp | 26 +++++++++++++++++-------- src/modules/plasmalnf/ThemeInfo.h | 5 +++++ src/modules/plasmalnf/ThemeWidget.cpp | 11 +++++++++-- src/modules/plasmalnf/ThemeWidget.h | 4 ++++ 4 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/modules/plasmalnf/PlasmaLnfPage.cpp b/src/modules/plasmalnf/PlasmaLnfPage.cpp index 501827003..916e6db64 100644 --- a/src/modules/plasmalnf/PlasmaLnfPage.cpp +++ b/src/modules/plasmalnf/PlasmaLnfPage.cpp @@ -30,6 +30,7 @@ ThemeInfo::ThemeInfo( const KPluginMetaData& data ) : id( data.pluginId() ) , name( data.name() ) , description( data.description() ) + , widget( nullptr ) { } @@ -136,18 +137,27 @@ void PlasmaLnfPage::fillUi() return; } - if ( m_buttonGroup ) - delete m_buttonGroup; - m_buttonGroup = new QButtonGroup( this ); - m_buttonGroup->setExclusive( true ); + if ( !m_buttonGroup ) + { + m_buttonGroup = new QButtonGroup( this ); + m_buttonGroup->setExclusive( true ); + } int c = 1; // After the general explanation for ( auto& theme : m_enabledThemes ) { - ThemeWidget* w = new ThemeWidget( theme ); - m_buttonGroup->addButton( w->button() ); - ui->verticalLayout->insertWidget( c, w ); - connect( w, &ThemeWidget::themeSelected, this, &PlasmaLnfPage::plasmaThemeSelected); + if ( !theme.widget ) + { + ThemeWidget* w = new ThemeWidget( theme ); + m_buttonGroup->addButton( w->button() ); + ui->verticalLayout->insertWidget( c, w ); + connect( w, &ThemeWidget::themeSelected, this, &PlasmaLnfPage::plasmaThemeSelected); + theme.widget = w; + } + else + { + theme.widget->updateThemeName( theme ); + } ++c; } } diff --git a/src/modules/plasmalnf/ThemeInfo.h b/src/modules/plasmalnf/ThemeInfo.h index f11083485..b186b9be1 100644 --- a/src/modules/plasmalnf/ThemeInfo.h +++ b/src/modules/plasmalnf/ThemeInfo.h @@ -23,6 +23,7 @@ #include class KPluginMetaData; +class ThemeWidget; /** @brief describes a single plasma LnF theme. * @@ -37,18 +38,22 @@ struct ThemeInfo QString name; QString description; QString imagePath; + ThemeWidget* widget; ThemeInfo() + : widget( nullptr ) {} explicit ThemeInfo( const QString& _id ) : id( _id ) + , widget( nullptr ) { } explicit ThemeInfo( const QString& _id, const QString& image ) : id( _id ) , imagePath( image ) + , widget( nullptr ) {} // Defined in PlasmaLnfPage.cpp diff --git a/src/modules/plasmalnf/ThemeWidget.cpp b/src/modules/plasmalnf/ThemeWidget.cpp index c7256cce3..fac3980c5 100644 --- a/src/modules/plasmalnf/ThemeWidget.cpp +++ b/src/modules/plasmalnf/ThemeWidget.cpp @@ -29,6 +29,7 @@ ThemeWidget::ThemeWidget(const ThemeInfo& info, QWidget* parent) : QWidget( parent ) , m_check( new QRadioButton( info.name.isEmpty() ? info.id : info.name, parent ) ) + , m_description( new QLabel( info.description, parent ) ) , m_id( info.id ) { QHBoxLayout* layout = new QHBoxLayout( this ); @@ -44,7 +45,7 @@ ThemeWidget::ThemeWidget(const ThemeInfo& info, QWidget* parent) // Not found or not specified, so convert the name into some (horrible, likely) // color instead. image = QPixmap( image_size ); - uint hash_color = qHash( info.imagePath ); + uint hash_color = qHash( info.imagePath.isEmpty() ? info.id : info.imagePath ); cDebug() << "Theme image" << info.imagePath << "not found, hash" << hash_color; image.fill( QColor( QRgb( hash_color ) ) ); } @@ -54,7 +55,7 @@ ThemeWidget::ThemeWidget(const ThemeInfo& info, QWidget* parent) QLabel* image_label = new QLabel( this ); image_label->setPixmap( image ); layout->addWidget( image_label, 1 ); - layout->addWidget( new QLabel( info.description, this ), 3 ); + layout->addWidget( m_description, 3 ); connect( m_check, &QRadioButton::clicked, this, &ThemeWidget::clicked ); } @@ -71,3 +72,9 @@ ThemeWidget::button() const { return m_check; } + +void ThemeWidget::updateThemeName(const ThemeInfo& info) +{ + m_check->setText( info.name ); + m_description->setText( info.description ); +} diff --git a/src/modules/plasmalnf/ThemeWidget.h b/src/modules/plasmalnf/ThemeWidget.h index 42f064039..a6716ce72 100644 --- a/src/modules/plasmalnf/ThemeWidget.h +++ b/src/modules/plasmalnf/ThemeWidget.h @@ -22,6 +22,7 @@ #include class QAbstractButton; +class QLabel; class QRadioButton; struct ThemeInfo; @@ -34,6 +35,8 @@ public: QAbstractButton* button() const; + void updateThemeName( const ThemeInfo& info ); + signals: void themeSelected( const QString& id ); @@ -43,6 +46,7 @@ public slots: private: QString m_id; QRadioButton* m_check; + QLabel* m_description; } ; #endif From e73d54767d497ec201797e23632ff58401b02641 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 18 Dec 2017 07:57:19 -0500 Subject: [PATCH 24/27] [plasmalnf] Expand explanation, drop CSS --- src/modules/plasmalnf/PlasmaLnfPage.cpp | 2 +- src/modules/plasmalnf/page_plasmalnf.ui | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/modules/plasmalnf/PlasmaLnfPage.cpp b/src/modules/plasmalnf/PlasmaLnfPage.cpp index 916e6db64..0c3d94079 100644 --- a/src/modules/plasmalnf/PlasmaLnfPage.cpp +++ b/src/modules/plasmalnf/PlasmaLnfPage.cpp @@ -61,7 +61,7 @@ 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." ) ); + ui->generalExplanation->setText( tr( "Please choose a look-and-feel for the KDE Plasma Desktop. You can also skip this step and configure the look-and-feel once the system is installed." ) ); updateThemeNames(); fillUi(); } diff --git a/src/modules/plasmalnf/page_plasmalnf.ui b/src/modules/plasmalnf/page_plasmalnf.ui index dfb906c22..6da6647fd 100644 --- a/src/modules/plasmalnf/page_plasmalnf.ui +++ b/src/modules/plasmalnf/page_plasmalnf.ui @@ -16,10 +16,6 @@ - - margin-bottom: 1ex; -margin-left: 2em; - Placeholder From 10e71bab30ec2236de9b089947af2a7fcf3095e6 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 19 Dec 2017 12:21:05 +0100 Subject: [PATCH 25/27] [plasmalnf] Add Breeze 'view-preview' icon for missing screenshots --- src/modules/plasmalnf/page_plasmalnf.qrc | 6 +++++- src/modules/plasmalnf/view-preview.png | Bin 0 -> 560 bytes src/modules/plasmalnf/view-preview.svg | 13 +++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/modules/plasmalnf/view-preview.png create mode 100644 src/modules/plasmalnf/view-preview.svg diff --git a/src/modules/plasmalnf/page_plasmalnf.qrc b/src/modules/plasmalnf/page_plasmalnf.qrc index 7646d2b36..c63ecc03b 100644 --- a/src/modules/plasmalnf/page_plasmalnf.qrc +++ b/src/modules/plasmalnf/page_plasmalnf.qrc @@ -1 +1,5 @@ - + + + view-preview.png + + diff --git a/src/modules/plasmalnf/view-preview.png b/src/modules/plasmalnf/view-preview.png new file mode 100644 index 0000000000000000000000000000000000000000..8e5f07ba9018e2708d9825b2446ea3ae5cc98d91 GIT binary patch literal 560 zcmeAS@N?(olHy`uVBq!ia0vp^6+j%o!3HER&ED7vq&N#aB8wRq_>O=u<5X=vX$A(y zN1iT@Ar*7p-tt|w*g>N8;bmXvV@=ituaqXSN*pXyTX(QAx`X+k>=iyHwUjw;9H&2I znl#atWBbmRe@gO-w@y0s+owgSi=TgfsF)Yf3N&y)q3(v>18bMSEBu!K(>7P$eE#Kh z8RPxby>a|T?`!PjQ|@j2vn7_H?WqrY{k77$J%(Ag!zPKeExcqh_5JT@+S2ojW$%>E z-J}yNz_MzUS7@jv2UBX~vURU>rkh(mXEHmc(U+|1sdWDHlgfFMR03s=8y&l$mtS&@ z_0G1nX`62z{ZV4|_w%Vb^>eH}#phUM+7_1WzI*gX-TrWiHZiSDr+3Dd%vyG8lh37> zTXp6hTKhUGH8N_=8NTOC-)iGiBTq>z-nCA3?yg-rr)SUiJpMRv^2wAlMju53MZW%D zojI#+W5gHV%Q1WHzZkx_Fekcs|DxPzQP+hko*^Pfqu*_cKcp;MV + + + + + From f2aeecf546ce1d338e679eaf772d432e393a8f01 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 19 Dec 2017 12:28:42 +0100 Subject: [PATCH 26/27] [plasmalnf] Improve screenshot view - make screenies smaller - use view-preview to indicate no-screenshot-specified --- src/modules/plasmalnf/CMakeLists.txt | 2 ++ src/modules/plasmalnf/ThemeWidget.cpp | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/modules/plasmalnf/CMakeLists.txt b/src/modules/plasmalnf/CMakeLists.txt index f752755a5..8148a80e9 100644 --- a/src/modules/plasmalnf/CMakeLists.txt +++ b/src/modules/plasmalnf/CMakeLists.txt @@ -10,6 +10,8 @@ calamares_add_plugin( plasmalnf PlasmaLnfPage.cpp PlasmaLnfJob.cpp ThemeWidget.cpp + RESOURCES + page_plasmalnf.qrc UI page_plasmalnf.ui LINK_PRIVATE_LIBRARIES diff --git a/src/modules/plasmalnf/ThemeWidget.cpp b/src/modules/plasmalnf/ThemeWidget.cpp index fac3980c5..28e01c2ff 100644 --- a/src/modules/plasmalnf/ThemeWidget.cpp +++ b/src/modules/plasmalnf/ThemeWidget.cpp @@ -37,10 +37,15 @@ ThemeWidget::ThemeWidget(const ThemeInfo& info, QWidget* parent) layout->addWidget( m_check, 1 ); - constexpr QSize image_size{240, 160}; + constexpr QSize image_size{120, 80}; QPixmap image( info.imagePath ); - if ( image.isNull() ) + if ( info.imagePath.isEmpty() ) + { + // Image can't possibly be valid + image = QPixmap( ":/view-preview.png" ); + } + else if ( image.isNull() ) { // Not found or not specified, so convert the name into some (horrible, likely) // color instead. From d5b46dfb8650e019b81f953c0e5ebb9271a2d87d Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 19 Dec 2017 12:51:56 +0100 Subject: [PATCH 27/27] [plasmalnf] Improve theme-listing handling - if key is missing or badly typed, enable all (explicitly) - document settings and code --- src/modules/plasmalnf/PlasmaLnfPage.cpp | 12 ++++++++---- src/modules/plasmalnf/PlasmaLnfPage.h | 9 +++++++++ src/modules/plasmalnf/PlasmaLnfViewStep.cpp | 2 ++ src/modules/plasmalnf/plasmalnf.conf | 12 +++++++----- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/modules/plasmalnf/PlasmaLnfPage.cpp b/src/modules/plasmalnf/PlasmaLnfPage.cpp index 0c3d94079..2b171cc40 100644 --- a/src/modules/plasmalnf/PlasmaLnfPage.cpp +++ b/src/modules/plasmalnf/PlasmaLnfPage.cpp @@ -77,16 +77,20 @@ PlasmaLnfPage::setLnfPath( const QString& path ) void PlasmaLnfPage::setEnabledThemes(const ThemeInfoList& themes) { - if ( themes.isEmpty() ) - m_enabledThemes = plasma_themes(); - else - m_enabledThemes = themes; + m_enabledThemes = themes; updateThemeNames(); winnowThemes(); fillUi(); } +void +PlasmaLnfPage::setEnabledThemesAll() +{ + setEnabledThemes( plasma_themes() ); +} + + void PlasmaLnfPage::updateThemeNames() { auto plasmaThemes = plasma_themes(); diff --git a/src/modules/plasmalnf/PlasmaLnfPage.h b/src/modules/plasmalnf/PlasmaLnfPage.h index 59fffc93a..e489e99a7 100644 --- a/src/modules/plasmalnf/PlasmaLnfPage.h +++ b/src/modules/plasmalnf/PlasmaLnfPage.h @@ -33,6 +33,12 @@ namespace Ui class PlasmaLnfPage; } +/** @brief Page for selecting a Plasma Look-and-Feel theme. + * + * You must call setEnabledThemes -- either overload -- once + * to get the selection widgets. Note that calling that with + * an empty list will result in zero (0) selectable themes. + */ class PlasmaLnfPage : public QWidget { Q_OBJECT @@ -40,7 +46,10 @@ public: explicit PlasmaLnfPage( QWidget* parent = nullptr ); void setLnfPath( const QString& path ); + /** @brief enable only the listed themes. */ void setEnabledThemes( const ThemeInfoList& themes ); + /** @brief enable all installed plasma themes. */ + void setEnabledThemesAll(); signals: void plasmaThemeSelected( const QString& id ); diff --git a/src/modules/plasmalnf/PlasmaLnfViewStep.cpp b/src/modules/plasmalnf/PlasmaLnfViewStep.cpp index 4dcfd2f47..db8529d56 100644 --- a/src/modules/plasmalnf/PlasmaLnfViewStep.cpp +++ b/src/modules/plasmalnf/PlasmaLnfViewStep.cpp @@ -158,6 +158,8 @@ PlasmaLnfViewStep::setConfigurationMap( const QVariantMap& configurationMap ) cDebug() << "WARNING: only one theme enabled in plasmalnf"; m_widget->setEnabledThemes( allThemes ); } + else + m_widget->setEnabledThemesAll(); // All of them } void diff --git a/src/modules/plasmalnf/plasmalnf.conf b/src/modules/plasmalnf/plasmalnf.conf index 4aeca2471..aa9865117 100644 --- a/src/modules/plasmalnf/plasmalnf.conf +++ b/src/modules/plasmalnf/plasmalnf.conf @@ -12,12 +12,14 @@ lnftool: "/usr/bin/lookandfeeltool" # liveuser: "live" # You can limit the list of Plasma look-and-feel themes by listing ids -# here. If this key is not present, or the list is empty, all of the -# installed themes are listed. If only one theme is listed, why are -# you using this module at all? Themes may be listed by id, -# (e.g. fluffy-bunny, below) or as a theme and an image (e.g. breeze) -# which will be used to show a screenshot. +# here. If this key is not present, all of the installed themes are listed. +# If the key is present, only installed themes that are *also* included +# in the list are shown (could be none!). # +# Themes may be listed by id, (e.g. fluffy-bunny, below) or as a theme +# and an image (e.g. breeze) which will be used to show a screenshot. +# Themes with no image get a "missing screenshot" image; if the +# image file is not found, they get a color swatch based on the image name. themes: - org.kde.fuzzy-pig.desktop - theme: org.kde.breeze.desktop