From eb92755b0a418cfaa3b8386145a419efe95d7c55 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 4 Dec 2017 06:40:13 -0500 Subject: [PATCH] [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; }