2017-12-03 18:47:41 +01:00
|
|
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
|
|
|
*
|
|
|
|
* Copyright 2017, Adriaan de Groot <groot@kde.org>
|
|
|
|
*
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "PlasmaLnfPage.h"
|
|
|
|
|
|
|
|
#include "ui_page_plasmalnf.h"
|
|
|
|
|
|
|
|
#include "utils/Logger.h"
|
|
|
|
#include "utils/Retranslator.h"
|
|
|
|
|
2018-03-29 10:45:34 +02:00
|
|
|
#include <QAbstractButton>
|
|
|
|
|
2017-12-03 21:34:06 +01:00
|
|
|
#include <KPackage/Package>
|
|
|
|
#include <KPackage/PackageLoader>
|
|
|
|
|
2017-12-14 23:01:59 +01:00
|
|
|
ThemeInfo::ThemeInfo( const KPluginMetaData& data )
|
|
|
|
: id( data.pluginId() )
|
|
|
|
, name( data.name() )
|
|
|
|
, description( data.description() )
|
2017-12-18 13:20:32 +01:00
|
|
|
, widget( nullptr )
|
2017-12-14 23:01:59 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-12-12 11:42:35 +01:00
|
|
|
static ThemeInfoList plasma_themes()
|
2017-12-03 21:34:06 +01:00
|
|
|
{
|
2017-12-12 11:42:35 +01:00
|
|
|
ThemeInfoList packages;
|
2017-12-03 21:34:06 +01:00
|
|
|
|
2017-12-04 12:44:37 +01:00
|
|
|
QList<KPluginMetaData> pkgs = KPackage::PackageLoader::self()->listPackages( "Plasma/LookAndFeel" );
|
2017-12-03 21:34:06 +01:00
|
|
|
|
2017-12-04 12:44:37 +01:00
|
|
|
for ( const KPluginMetaData& data : pkgs )
|
|
|
|
{
|
2017-12-04 18:27:30 +01:00
|
|
|
if ( data.isValid() && !data.isHidden() && !data.name().isEmpty() )
|
|
|
|
{
|
2017-12-14 23:01:59 +01:00
|
|
|
packages << ThemeInfo{ data };
|
2017-12-04 18:27:30 +01:00
|
|
|
}
|
2017-12-03 21:34:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return packages;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-04 12:44:37 +01:00
|
|
|
PlasmaLnfPage::PlasmaLnfPage( QWidget* parent )
|
2017-12-03 18:47:41 +01:00
|
|
|
: QWidget( parent )
|
|
|
|
, ui( new Ui::PlasmaLnfPage )
|
2017-12-13 16:28:31 +01:00
|
|
|
, m_buttonGroup( nullptr )
|
2017-12-03 18:47:41 +01:00
|
|
|
{
|
|
|
|
ui->setupUi( this );
|
|
|
|
CALAMARES_RETRANSLATE(
|
2017-12-04 12:44:37 +01:00
|
|
|
{
|
2017-12-03 18:47:41 +01:00
|
|
|
ui->retranslateUi( this );
|
2018-03-29 10:33:55 +02:00
|
|
|
ui->generalExplanation->setText( tr(
|
|
|
|
"Please choose a look-and-feel for the KDE Plasma Desktop. "
|
|
|
|
"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.") );
|
2017-12-12 17:40:10 +01:00
|
|
|
updateThemeNames();
|
|
|
|
fillUi();
|
2017-12-04 12:44:37 +01:00
|
|
|
}
|
2017-12-03 18:47:41 +01:00
|
|
|
)
|
|
|
|
}
|
2017-12-03 21:41:52 +01:00
|
|
|
|
|
|
|
void
|
2017-12-04 12:44:37 +01:00
|
|
|
PlasmaLnfPage::setLnfPath( const QString& path )
|
2017-12-03 21:41:52 +01:00
|
|
|
{
|
|
|
|
m_lnfPath = path;
|
|
|
|
}
|
2017-12-04 18:27:30 +01:00
|
|
|
|
|
|
|
void
|
2017-12-12 11:42:35 +01:00
|
|
|
PlasmaLnfPage::setEnabledThemes(const ThemeInfoList& themes)
|
2017-12-04 18:27:30 +01:00
|
|
|
{
|
2017-12-19 12:51:56 +01:00
|
|
|
m_enabledThemes = themes;
|
2017-12-12 17:40:10 +01:00
|
|
|
|
|
|
|
updateThemeNames();
|
2017-12-04 18:27:30 +01:00
|
|
|
winnowThemes();
|
2017-12-12 17:40:10 +01:00
|
|
|
fillUi();
|
2017-12-04 18:27:30 +01:00
|
|
|
}
|
|
|
|
|
2017-12-19 12:51:56 +01:00
|
|
|
void
|
|
|
|
PlasmaLnfPage::setEnabledThemesAll()
|
|
|
|
{
|
|
|
|
setEnabledThemes( plasma_themes() );
|
|
|
|
}
|
|
|
|
|
2018-03-29 10:45:34 +02:00
|
|
|
void
|
|
|
|
PlasmaLnfPage::setPreselect( const QString& id )
|
|
|
|
{
|
|
|
|
m_preselect = id;
|
|
|
|
if ( !m_enabledThemes.isEmpty() )
|
|
|
|
fillUi();
|
|
|
|
}
|
|
|
|
|
2017-12-19 12:51:56 +01:00
|
|
|
|
2017-12-12 17:40:10 +01:00
|
|
|
void PlasmaLnfPage::updateThemeNames()
|
2017-12-04 18:27:30 +01:00
|
|
|
{
|
2017-12-12 11:42:35 +01:00
|
|
|
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;
|
2017-12-14 23:01:59 +01:00
|
|
|
enabled_theme.description = t->description;
|
2017-12-12 11:42:35 +01:00
|
|
|
}
|
|
|
|
}
|
2017-12-04 18:27:30 +01:00
|
|
|
}
|
2017-12-12 17:40:10 +01:00
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2017-12-13 16:28:31 +01:00
|
|
|
if ( m_enabledThemes.isEmpty() )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-18 13:20:32 +01:00
|
|
|
if ( !m_buttonGroup )
|
|
|
|
{
|
|
|
|
m_buttonGroup = new QButtonGroup( this );
|
|
|
|
m_buttonGroup->setExclusive( true );
|
|
|
|
}
|
2017-12-13 16:28:31 +01:00
|
|
|
|
|
|
|
int c = 1; // After the general explanation
|
2017-12-12 17:40:10 +01:00
|
|
|
for ( auto& theme : m_enabledThemes )
|
|
|
|
{
|
2017-12-18 13:20:32 +01:00
|
|
|
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 );
|
|
|
|
}
|
2018-03-29 10:45:34 +02:00
|
|
|
if ( theme.id == m_preselect )
|
|
|
|
{
|
|
|
|
const QSignalBlocker b( theme.widget->button() );
|
|
|
|
theme.widget->button()->setChecked( true );
|
|
|
|
}
|
2017-12-13 16:28:31 +01:00
|
|
|
++c;
|
2017-12-12 17:40:10 +01:00
|
|
|
}
|
|
|
|
}
|