From 755c0cba184a317b074a679158c311845d73ee44 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 12 Dec 2017 11:40:10 -0500 Subject: [PATCH] [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;