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