From aaa56b69033e1111464cef1b89f373751c4916d6 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 16 Nov 2020 23:36:32 +0100 Subject: [PATCH] [plasmalnf] Rip out most of the widget - put a filter model in place, so only the themes with "show" set are displayed - rip out the messing about with widgets, soon to introduce a model- based UI --- src/modules/plasmalnf/Config.cpp | 9 +- src/modules/plasmalnf/Config.h | 3 +- src/modules/plasmalnf/PlasmaLnfPage.cpp | 149 +------------------- src/modules/plasmalnf/PlasmaLnfPage.h | 30 +--- src/modules/plasmalnf/PlasmaLnfViewStep.cpp | 36 +---- src/modules/plasmalnf/ThemeInfo.cpp | 2 + src/modules/plasmalnf/ThemeInfo.h | 3 +- 7 files changed, 23 insertions(+), 209 deletions(-) diff --git a/src/modules/plasmalnf/Config.cpp b/src/modules/plasmalnf/Config.cpp index 9e5183383..f5fa59b89 100644 --- a/src/modules/plasmalnf/Config.cpp +++ b/src/modules/plasmalnf/Config.cpp @@ -21,6 +21,8 @@ #include #endif +#include + static QString currentPlasmaTheme() { @@ -33,11 +35,16 @@ currentPlasmaTheme() #endif } - Config::Config( QObject* parent ) : QObject( parent ) , m_themeModel( new ThemesModel( this ) ) { + auto* filter = new QSortFilterProxyModel( m_themeModel ); + filter->setFilterRole( ThemesModel::ShownRole ); + filter->setFilterFixedString( QStringLiteral( "true" ) ); + filter->setSourceModel( m_themeModel ); + + m_filteredModel = filter; } void diff --git a/src/modules/plasmalnf/Config.h b/src/modules/plasmalnf/Config.h index 725563c34..aafdf6418 100644 --- a/src/modules/plasmalnf/Config.h +++ b/src/modules/plasmalnf/Config.h @@ -55,7 +55,7 @@ public: /** @brief The (list) model of available themes. */ - QAbstractItemModel* themeModel() const { return m_themeModel; } + QAbstractItemModel* themeModel() const { return m_filteredModel; } public slots: void setTheme( const QString& id ); @@ -70,6 +70,7 @@ private: QString m_preselectThemeId; QString m_themeId; // Id of selected theme + QAbstractItemModel* m_filteredModel = nullptr; ThemesModel* m_themeModel = nullptr; }; diff --git a/src/modules/plasmalnf/PlasmaLnfPage.cpp b/src/modules/plasmalnf/PlasmaLnfPage.cpp index 22e240266..095bd3ec9 100644 --- a/src/modules/plasmalnf/PlasmaLnfPage.cpp +++ b/src/modules/plasmalnf/PlasmaLnfPage.cpp @@ -10,6 +10,7 @@ #include "PlasmaLnfPage.h" +#include "Config.h" #include "ui_page_plasmalnf.h" #include "Settings.h" @@ -21,30 +22,10 @@ #include #include -static ThemeInfoList -plasma_themes() -{ - ThemeInfoList packages; - - QList< KPluginMetaData > pkgs = KPackage::PackageLoader::self()->listPackages( "Plasma/LookAndFeel" ); - - for ( const KPluginMetaData& data : pkgs ) - { - if ( data.isValid() && !data.isHidden() && !data.name().isEmpty() ) - { - packages << ThemeInfo { data }; - } - } - - return packages; -} - - -PlasmaLnfPage::PlasmaLnfPage( QWidget* parent ) +PlasmaLnfPage::PlasmaLnfPage( Config* config, QWidget* parent ) : QWidget( parent ) , ui( new Ui::PlasmaLnfPage ) - , m_showAll( false ) - , m_buttonGroup( nullptr ) + , m_config( config ) { ui->setupUi( this ); CALAMARES_RETRANSLATE( { @@ -59,128 +40,6 @@ PlasmaLnfPage::PlasmaLnfPage( QWidget* parent ) "You can also skip this step and configure the look-and-feel " "once the system is installed. Clicking on a look-and-feel " "selection will give you a live preview of that look-and-feel." ) ); - updateThemeNames(); - fillUi(); } ) -} - -void -PlasmaLnfPage::setEnabledThemes( const ThemeInfoList& themes, bool showAll ) -{ - m_enabledThemes = themes; - - if ( showAll ) - { - auto plasmaThemes = plasma_themes(); - for ( auto& installed_theme : plasmaThemes ) - if ( !m_enabledThemes.findById( installed_theme.id ) ) - { - m_enabledThemes.append( installed_theme ); - } - } - - updateThemeNames(); - winnowThemes(); - fillUi(); -} - -void -PlasmaLnfPage::setEnabledThemesAll() -{ - // Don't need to set showAll=true, because we're already passing in - // the complete list of installed themes. - setEnabledThemes( plasma_themes(), false ); -} - -void -PlasmaLnfPage::setPreselect( const QString& id ) -{ - m_preselect = id; - if ( !m_enabledThemes.isEmpty() ) - { - fillUi(); - } -} - -void -PlasmaLnfPage::updateThemeNames() -{ - auto plasmaThemes = plasma_themes(); - for ( auto& enabled_theme : m_enabledThemes ) - { - ThemeInfo* t = plasmaThemes.findById( enabled_theme.id ); - if ( t != nullptr ) - { - enabled_theme.name = t->name; - enabled_theme.description = t->description; - } - } -} - -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() -{ - if ( m_enabledThemes.isEmpty() ) - { - return; - } - - if ( !m_buttonGroup ) - { - m_buttonGroup = new QButtonGroup( this ); - m_buttonGroup->setExclusive( true ); - } - - int c = 1; // After the general explanation - for ( auto& theme : m_enabledThemes ) - { - 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 ); - } - if ( theme.id == m_preselect ) - { - const QSignalBlocker b( theme.widget->button() ); - theme.widget->button()->setChecked( true ); - } - ++c; - } + connect( this, &PlasmaLnfPage::plasmaThemeSelected, config, &Config::setTheme ); } diff --git a/src/modules/plasmalnf/PlasmaLnfPage.h b/src/modules/plasmalnf/PlasmaLnfPage.h index acdf7c587..9afda305c 100644 --- a/src/modules/plasmalnf/PlasmaLnfPage.h +++ b/src/modules/plasmalnf/PlasmaLnfPage.h @@ -24,6 +24,8 @@ namespace Ui class PlasmaLnfPage; } +class Config; + /** @brief Page for selecting a Plasma Look-and-Feel theme. * * You must call setEnabledThemes -- either overload -- once @@ -34,38 +36,14 @@ class PlasmaLnfPage : public QWidget { Q_OBJECT public: - explicit PlasmaLnfPage( QWidget* parent = nullptr ); - - /** @brief enable only the listed themes. - * - * Shows the listed @p themes with full information (e.g. screenshot). - * If @p showAll is true, then also show all installed themes - * not explicitly listed (without a screenshot). - */ - void setEnabledThemes( const ThemeInfoList& themes, bool showAll ); - /** @brief enable all installed plasma themes. */ - void setEnabledThemesAll(); - /** @brief set which theme is to be preselected. */ - void setPreselect( const QString& id ); + explicit PlasmaLnfPage( Config* config, QWidget* parent = nullptr ); 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_preselect; - bool m_showAll; // If true, don't winnow according to enabledThemes - ThemeInfoList m_enabledThemes; - - QButtonGroup* m_buttonGroup; - QList< ThemeWidget* > m_widgets; + Config* m_config; }; #endif //PLASMALNFPAGE_H diff --git a/src/modules/plasmalnf/PlasmaLnfViewStep.cpp b/src/modules/plasmalnf/PlasmaLnfViewStep.cpp index 445e5dddb..fd38bfab3 100644 --- a/src/modules/plasmalnf/PlasmaLnfViewStep.cpp +++ b/src/modules/plasmalnf/PlasmaLnfViewStep.cpp @@ -22,9 +22,8 @@ CALAMARES_PLUGIN_FACTORY_DEFINITION( PlasmaLnfViewStepFactory, registerPlugin< P PlasmaLnfViewStep::PlasmaLnfViewStep( QObject* parent ) : Calamares::ViewStep( parent ) , m_config( new Config( this ) ) - , m_widget( new PlasmaLnfPage ) + , m_widget( new PlasmaLnfPage( m_config ) ) { - connect( m_widget, &PlasmaLnfPage::plasmaThemeSelected, m_config, &Config::setTheme ); emit nextStatusChanged( false ); } @@ -97,37 +96,4 @@ void PlasmaLnfViewStep::setConfigurationMap( const QVariantMap& configurationMap ) { m_config->setConfigurationMap( configurationMap ); - - m_widget->setPreselect( m_config->preselectedTheme() ); - - bool showAll = CalamaresUtils::getBool( configurationMap, "showAll", false ); - - if ( configurationMap.contains( "themes" ) && configurationMap.value( "themes" ).type() == QVariant::List ) - { - ThemeInfoList listedThemes; - 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(); - listedThemes.append( ThemeInfo( iv.value( "theme" ).toString(), iv.value( "image" ).toString() ) ); - } - else if ( i.type() == QVariant::String ) - { - listedThemes.append( ThemeInfo( i.toString() ) ); - } - - if ( listedThemes.length() == 1 ) - { - cWarning() << "only one theme enabled in plasmalnf"; - } - m_widget->setEnabledThemes( listedThemes, showAll ); - } - else - { - m_widget->setEnabledThemesAll(); // All of them - } } diff --git a/src/modules/plasmalnf/ThemeInfo.cpp b/src/modules/plasmalnf/ThemeInfo.cpp index 51b19c8fa..c9ab3e36a 100644 --- a/src/modules/plasmalnf/ThemeInfo.cpp +++ b/src/modules/plasmalnf/ThemeInfo.cpp @@ -48,6 +48,8 @@ ThemesModel::data( const QModelIndex& index, int role ) const return item.name; case KeyRole: return item.id; + case ShownRole: + return item.show; default: return QVariant(); } diff --git a/src/modules/plasmalnf/ThemeInfo.h b/src/modules/plasmalnf/ThemeInfo.h index 978aee70e..cba9b87d6 100644 --- a/src/modules/plasmalnf/ThemeInfo.h +++ b/src/modules/plasmalnf/ThemeInfo.h @@ -97,7 +97,8 @@ public: enum { LabelRole = Qt::DisplayRole, - KeyRole = Qt::UserRole + KeyRole = Qt::UserRole, + ShownRole }; explicit ThemesModel( QObject* parent );