2017-12-20 14:39:09 +01:00
|
|
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
2017-12-03 13:08:54 +01:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
2017-12-04 12:44:37 +01:00
|
|
|
#include "PlasmaLnfViewStep.h"
|
2017-12-03 13:08:54 +01:00
|
|
|
|
|
|
|
#include "PlasmaLnfJob.h"
|
|
|
|
#include "PlasmaLnfPage.h"
|
2017-12-12 11:42:35 +01:00
|
|
|
#include "ThemeInfo.h"
|
2017-12-03 13:08:54 +01:00
|
|
|
|
2017-12-04 17:38:58 +01:00
|
|
|
#include "utils/CalamaresUtils.h"
|
2017-12-04 12:44:37 +01:00
|
|
|
#include "utils/Logger.h"
|
|
|
|
|
2017-12-04 12:40:13 +01:00
|
|
|
#include <QProcess>
|
2017-12-03 13:08:54 +01:00
|
|
|
#include <QVariantMap>
|
|
|
|
|
2018-03-29 14:49:22 +02:00
|
|
|
#ifdef WITH_KCONFIG
|
|
|
|
#include <KConfigGroup>
|
|
|
|
#include <KSharedConfig>
|
|
|
|
#endif
|
|
|
|
|
2017-12-03 13:08:54 +01:00
|
|
|
CALAMARES_PLUGIN_FACTORY_DEFINITION( PlasmaLnfViewStepFactory, registerPlugin<PlasmaLnfViewStep>(); )
|
|
|
|
|
2018-03-29 14:49:22 +02:00
|
|
|
static QString
|
|
|
|
currentPlasmaTheme()
|
|
|
|
{
|
|
|
|
#ifdef WITH_KCONFIG
|
|
|
|
KConfigGroup cg( KSharedConfig::openConfig( QStringLiteral( "kdeglobals" ) ), "KDE" );
|
|
|
|
return cg.readEntry( "LookAndFeelPackage", QString() );
|
|
|
|
#else
|
|
|
|
cWarning() << "No KConfig support, cannot determine Plasma theme.";
|
|
|
|
return QString();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-12-03 13:08:54 +01:00
|
|
|
PlasmaLnfViewStep::PlasmaLnfViewStep( QObject* parent )
|
|
|
|
: Calamares::ViewStep( parent )
|
|
|
|
, m_widget( new PlasmaLnfPage )
|
|
|
|
{
|
2017-12-03 15:26:59 +01:00
|
|
|
connect( m_widget, &PlasmaLnfPage::plasmaThemeSelected, this, &PlasmaLnfViewStep::themeSelected );
|
2017-12-03 13:08:54 +01:00
|
|
|
emit nextStatusChanged( false );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PlasmaLnfViewStep::~PlasmaLnfViewStep()
|
|
|
|
{
|
|
|
|
if ( m_widget && m_widget->parent() == nullptr )
|
|
|
|
m_widget->deleteLater();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString
|
|
|
|
PlasmaLnfViewStep::prettyName() const
|
|
|
|
{
|
|
|
|
return tr( "Look-and-Feel" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QWidget*
|
|
|
|
PlasmaLnfViewStep::widget()
|
|
|
|
{
|
|
|
|
return m_widget;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
PlasmaLnfViewStep::next()
|
|
|
|
{
|
|
|
|
emit done();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
PlasmaLnfViewStep::back()
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
PlasmaLnfViewStep::isNextEnabled() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
PlasmaLnfViewStep::isBackEnabled() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
PlasmaLnfViewStep::isAtBeginning() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
PlasmaLnfViewStep::isAtEnd() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PlasmaLnfViewStep::onLeave()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Calamares::JobList
|
|
|
|
PlasmaLnfViewStep::jobs() const
|
|
|
|
{
|
|
|
|
Calamares::JobList l;
|
|
|
|
|
|
|
|
cDebug() << "Creating Plasma LNF jobs ..";
|
2017-12-04 17:54:33 +01:00
|
|
|
if ( !m_themeId.isEmpty() )
|
|
|
|
{
|
|
|
|
if ( !m_lnfPath.isEmpty() )
|
|
|
|
l.append( Calamares::job_ptr( new PlasmaLnfJob( m_lnfPath, m_themeId ) ) );
|
|
|
|
else
|
2018-02-13 11:07:12 +01:00
|
|
|
cWarning() << "no lnftool given for plasmalnf module.";
|
2017-12-04 17:54:33 +01:00
|
|
|
}
|
2017-12-03 13:08:54 +01:00
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
PlasmaLnfViewStep::setConfigurationMap( const QVariantMap& configurationMap )
|
|
|
|
{
|
2017-12-03 15:44:29 +01:00
|
|
|
m_lnfPath = CalamaresUtils::getString( configurationMap, "lnftool" );
|
2017-12-03 21:41:52 +01:00
|
|
|
m_widget->setLnfPath( m_lnfPath );
|
2017-12-03 15:44:29 +01:00
|
|
|
|
2017-12-04 12:44:37 +01:00
|
|
|
if ( m_lnfPath.isEmpty() )
|
2018-02-13 11:07:12 +01:00
|
|
|
cWarning() << "no lnftool given for plasmalnf module.";
|
2017-12-04 15:37:34 +01:00
|
|
|
|
2017-12-04 17:38:58 +01:00
|
|
|
m_liveUser = CalamaresUtils::getString( configurationMap, "liveuser" );
|
2017-12-04 18:27:30 +01:00
|
|
|
|
2018-03-29 23:35:36 +02:00
|
|
|
QString preselect = CalamaresUtils::getString( configurationMap, "preselect" );
|
2018-03-29 14:49:22 +02:00
|
|
|
if ( preselect == QStringLiteral( "*" ) )
|
|
|
|
preselect = currentPlasmaTheme();
|
2018-03-29 10:45:34 +02:00
|
|
|
if ( !preselect.isEmpty() )
|
|
|
|
m_widget->setPreselect( preselect );
|
|
|
|
|
2018-03-29 23:35:36 +02:00
|
|
|
bool showAll = CalamaresUtils::getBool( configurationMap, "showAll", false );
|
2018-03-29 15:57:19 +02:00
|
|
|
|
2017-12-04 18:27:30 +01:00
|
|
|
if ( configurationMap.contains( "themes" ) &&
|
|
|
|
configurationMap.value( "themes" ).type() == QVariant::List )
|
|
|
|
{
|
2018-03-29 16:09:45 +02:00
|
|
|
ThemeInfoList listedThemes;
|
2017-12-12 11:42:35 +01:00
|
|
|
auto themeList = configurationMap.value( "themes" ).toList();
|
2017-12-14 23:01:59 +01:00
|
|
|
// 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.
|
2017-12-12 11:42:35 +01:00
|
|
|
for ( const auto& i : themeList )
|
|
|
|
if ( i.type() == QVariant::Map )
|
|
|
|
{
|
|
|
|
auto iv = i.toMap();
|
2018-03-29 16:09:45 +02:00
|
|
|
listedThemes.append( ThemeInfo( iv.value( "theme" ).toString(), iv.value( "image" ).toString() ) );
|
2017-12-12 11:42:35 +01:00
|
|
|
}
|
|
|
|
else if ( i.type() == QVariant::String )
|
2018-03-29 16:09:45 +02:00
|
|
|
listedThemes.append( ThemeInfo( i.toString() ) );
|
2017-12-12 11:42:35 +01:00
|
|
|
|
2018-03-29 16:09:45 +02:00
|
|
|
if ( listedThemes.length() == 1 )
|
2018-02-13 11:07:12 +01:00
|
|
|
cWarning() << "only one theme enabled in plasmalnf";
|
2018-03-29 16:09:45 +02:00
|
|
|
m_widget->setEnabledThemes( listedThemes, showAll );
|
2017-12-04 18:27:30 +01:00
|
|
|
}
|
2017-12-19 12:51:56 +01:00
|
|
|
else
|
|
|
|
m_widget->setEnabledThemesAll(); // All of them
|
2017-12-03 13:08:54 +01:00
|
|
|
}
|
2017-12-03 15:26:59 +01:00
|
|
|
|
|
|
|
void
|
|
|
|
PlasmaLnfViewStep::themeSelected( const QString& id )
|
|
|
|
{
|
|
|
|
m_themeId = id;
|
2017-12-04 17:51:16 +01:00
|
|
|
if ( m_lnfPath.isEmpty() )
|
|
|
|
{
|
2018-02-13 11:07:12 +01:00
|
|
|
cWarning() << "no lnftool given for plasmalnf module.";
|
2017-12-04 17:51:16 +01:00
|
|
|
return;
|
|
|
|
}
|
2017-12-04 12:40:13 +01:00
|
|
|
|
|
|
|
QProcess lnftool;
|
2017-12-04 15:37:34 +01:00
|
|
|
if ( !m_liveUser.isEmpty() )
|
|
|
|
lnftool.start( "sudo", {"-E", "-H", "-u", m_liveUser, m_lnfPath, "--resetLayout", "--apply", id} );
|
|
|
|
else
|
|
|
|
lnftool.start( m_lnfPath, {"--resetLayout", "--apply", id} );
|
2017-12-04 12:40:13 +01:00
|
|
|
|
|
|
|
if ( !lnftool.waitForStarted( 1000 ) )
|
|
|
|
{
|
2018-02-13 11:07:12 +01:00
|
|
|
cWarning() << "could not start look-and-feel" << m_lnfPath;
|
2017-12-04 12:40:13 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ( !lnftool.waitForFinished() )
|
|
|
|
{
|
2018-02-13 11:07:12 +01:00
|
|
|
cWarning() << m_lnfPath << "timed out.";
|
2017-12-04 12:40:13 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-04 12:44:37 +01:00
|
|
|
if ( ( lnftool.exitCode() == 0 ) && ( lnftool.exitStatus() == QProcess::NormalExit ) )
|
2017-12-04 12:40:13 +01:00
|
|
|
cDebug() << "Plasma look-and-feel applied" << id;
|
|
|
|
else
|
2018-02-13 11:07:12 +01:00
|
|
|
cWarning() << "could not apply look-and-feel" << id;
|
2017-12-03 15:26:59 +01:00
|
|
|
}
|