From 11652c585669d3d25615f1fbd3edaf7d6e17142c Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 29 Mar 2018 04:45:34 -0400 Subject: [PATCH] [plasmalnf] Add pre-selected theme - For OEM modes where there is already a theme, add a preselect: key to pick a specific theme and have that one come up as already- selected in the list. - Don't re-run the lnftool if an already-selected theme is clicked again. Use toggled() instead of clicked(). --- src/modules/plasmalnf/PlasmaLnfPage.cpp | 15 +++++++++++++++ src/modules/plasmalnf/PlasmaLnfPage.h | 3 +++ src/modules/plasmalnf/PlasmaLnfViewStep.cpp | 6 ++++++ src/modules/plasmalnf/PlasmaLnfViewStep.h | 6 +++--- src/modules/plasmalnf/ThemeWidget.cpp | 2 +- src/modules/plasmalnf/plasmalnf.conf | 12 ++++++++++++ 6 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/modules/plasmalnf/PlasmaLnfPage.cpp b/src/modules/plasmalnf/PlasmaLnfPage.cpp index 8462261c9..2638ca9b1 100644 --- a/src/modules/plasmalnf/PlasmaLnfPage.cpp +++ b/src/modules/plasmalnf/PlasmaLnfPage.cpp @@ -23,6 +23,8 @@ #include "utils/Logger.h" #include "utils/Retranslator.h" +#include + #include #include @@ -94,6 +96,14 @@ PlasmaLnfPage::setEnabledThemesAll() setEnabledThemes( plasma_themes() ); } +void +PlasmaLnfPage::setPreselect( const QString& id ) +{ + m_preselect = id; + if ( !m_enabledThemes.isEmpty() ) + fillUi(); +} + void PlasmaLnfPage::updateThemeNames() { @@ -166,6 +176,11 @@ void PlasmaLnfPage::fillUi() { theme.widget->updateThemeName( theme ); } + if ( theme.id == m_preselect ) + { + const QSignalBlocker b( theme.widget->button() ); + theme.widget->button()->setChecked( true ); + } ++c; } } diff --git a/src/modules/plasmalnf/PlasmaLnfPage.h b/src/modules/plasmalnf/PlasmaLnfPage.h index e489e99a7..104fca83d 100644 --- a/src/modules/plasmalnf/PlasmaLnfPage.h +++ b/src/modules/plasmalnf/PlasmaLnfPage.h @@ -50,6 +50,8 @@ public: void setEnabledThemes( const ThemeInfoList& themes ); /** @brief enable all installed plasma themes. */ void setEnabledThemesAll(); + /** @brief set which theme is to be preselected. */ + void setPreselect( const QString& id ); signals: void plasmaThemeSelected( const QString& id ); @@ -64,6 +66,7 @@ private: Ui::PlasmaLnfPage* ui; QString m_lnfPath; + QString m_preselect; ThemeInfoList m_enabledThemes; QButtonGroup *m_buttonGroup; diff --git a/src/modules/plasmalnf/PlasmaLnfViewStep.cpp b/src/modules/plasmalnf/PlasmaLnfViewStep.cpp index db8529d56..a14b8e338 100644 --- a/src/modules/plasmalnf/PlasmaLnfViewStep.cpp +++ b/src/modules/plasmalnf/PlasmaLnfViewStep.cpp @@ -137,6 +137,12 @@ PlasmaLnfViewStep::setConfigurationMap( const QVariantMap& configurationMap ) liveUser = configurationMap.value( "liveuser" ).toString(); m_liveUser = liveUser; + QString preselect; + if ( configurationMap.contains( "preselect" ) && configurationMap.value( "preselect" ).type() == QVariant::String ) + preselect = configurationMap.value( "preselect" ).toString(); + if ( !preselect.isEmpty() ) + m_widget->setPreselect( preselect ); + if ( configurationMap.contains( "themes" ) && configurationMap.value( "themes" ).type() == QVariant::List ) { diff --git a/src/modules/plasmalnf/PlasmaLnfViewStep.h b/src/modules/plasmalnf/PlasmaLnfViewStep.h index 7fcfc50cc..1fa4139e1 100644 --- a/src/modules/plasmalnf/PlasmaLnfViewStep.h +++ b/src/modules/plasmalnf/PlasmaLnfViewStep.h @@ -61,9 +61,9 @@ public slots: private: PlasmaLnfPage* m_widget; - QString m_lnfPath; - QString m_themeId; - QString m_liveUser; + QString m_lnfPath; // Path to the lnf tool + QString m_themeId; // Id of selected theme + QString m_liveUser; // Name of the live user (for OEM mode) }; CALAMARES_PLUGIN_FACTORY_DECLARATION( PlasmaLnfViewStepFactory ) diff --git a/src/modules/plasmalnf/ThemeWidget.cpp b/src/modules/plasmalnf/ThemeWidget.cpp index 28e01c2ff..68a8c5f83 100644 --- a/src/modules/plasmalnf/ThemeWidget.cpp +++ b/src/modules/plasmalnf/ThemeWidget.cpp @@ -62,7 +62,7 @@ ThemeWidget::ThemeWidget(const ThemeInfo& info, QWidget* parent) layout->addWidget( image_label, 1 ); layout->addWidget( m_description, 3 ); - connect( m_check, &QRadioButton::clicked, this, &ThemeWidget::clicked ); + connect( m_check, &QRadioButton::toggled, this, &ThemeWidget::clicked ); } void diff --git a/src/modules/plasmalnf/plasmalnf.conf b/src/modules/plasmalnf/plasmalnf.conf index aa9865117..49a91b3b5 100644 --- a/src/modules/plasmalnf/plasmalnf.conf +++ b/src/modules/plasmalnf/plasmalnf.conf @@ -27,3 +27,15 @@ themes: - theme: org.kde.breezedark.desktop image: "breeze-dark.png" - org.kde.fluffy-bunny.desktop + +# You can pre-select one of the themes; it is not applied +# immediately, but its radio-button is switched on to indicate +# that that is the theme (that is most likely) currently in use. +# Do this only on Live images where you are reasonably sure +# that the user is not going to change the theme out from under +# themselves before running the installer. +# +# If this key is present, its value should be the id of the theme +# which should be pre-selected. If absent, empty, or the pre-selected +# theme is not found on the live system, no theme will be pre-selected. +preselect: org.kde.breeze.desktop