2020-11-11 13:08:42 +01:00
|
|
|
/* === This file is part of Calamares - <https://calamares.io> ===
|
|
|
|
*
|
|
|
|
* SPDX-FileCopyrightText: 2020 Adriaan de Groot <groot@kde.org>
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
*
|
|
|
|
* Calamares is Free Software: see the License-Identifier above.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "Config.h"
|
|
|
|
|
2020-11-11 14:45:31 +01:00
|
|
|
#include "PlasmaLnfJob.h"
|
|
|
|
|
2020-11-11 14:41:45 +01:00
|
|
|
#include "utils/CalamaresUtilsSystem.h"
|
2020-11-11 13:21:16 +01:00
|
|
|
#include "utils/Logger.h"
|
|
|
|
#include "utils/Variant.h"
|
|
|
|
|
2020-11-12 15:36:29 +01:00
|
|
|
#ifdef WITH_KCONFIG
|
|
|
|
#include <KConfigGroup>
|
|
|
|
#include <KSharedConfig>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <KPackage/Package>
|
|
|
|
#include <KPackage/PackageLoader>
|
|
|
|
|
|
|
|
#include <QAbstractListModel>
|
|
|
|
#include <QList>
|
|
|
|
|
|
|
|
class ThemesModel : public QAbstractListModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
LabelRole = Qt::DisplayRole,
|
|
|
|
KeyRole = Qt::UserRole
|
|
|
|
};
|
|
|
|
|
|
|
|
explicit ThemesModel( QObject* parent );
|
|
|
|
|
|
|
|
int rowCount( const QModelIndex& = QModelIndex() ) const override;
|
|
|
|
QVariant data( const QModelIndex& index, int role ) const override;
|
|
|
|
|
|
|
|
QHash< int, QByteArray > roleNames() const override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
QList< KPluginMetaData > m_themes;
|
|
|
|
};
|
|
|
|
|
|
|
|
ThemesModel::ThemesModel( QObject* parent )
|
|
|
|
: QAbstractListModel( parent )
|
|
|
|
, m_themes( KPackage::PackageLoader::self()->listPackages( "Plasma/LookAndFeel" ) )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ThemesModel::rowCount( const QModelIndex& ) const
|
|
|
|
{
|
|
|
|
return m_themes.count();
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant
|
|
|
|
ThemesModel::data( const QModelIndex& index, int role ) const
|
|
|
|
{
|
|
|
|
if ( !index.isValid() )
|
|
|
|
{
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
if ( index.row() < 0 || index.row() >= m_themes.count() )
|
|
|
|
{
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto& item = m_themes.at( index.row() );
|
|
|
|
switch ( role )
|
|
|
|
{
|
|
|
|
case LabelRole:
|
|
|
|
return item.name();
|
|
|
|
case KeyRole:
|
|
|
|
return item.pluginId();
|
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
__builtin_unreachable();
|
|
|
|
}
|
|
|
|
|
|
|
|
QHash< int, QByteArray >
|
|
|
|
ThemesModel::roleNames() const
|
|
|
|
{
|
|
|
|
return { { LabelRole, "label" }, { KeyRole, "key" } };
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-11 13:08:42 +01:00
|
|
|
Config::Config( QObject* parent )
|
|
|
|
: QObject( parent )
|
2020-11-12 15:36:29 +01:00
|
|
|
, m_themeModel( new ThemesModel( this ) )
|
2020-11-11 13:08:42 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-11-11 13:21:16 +01:00
|
|
|
Config::setConfigurationMap( const QVariantMap& configurationMap )
|
2020-11-11 13:08:42 +01:00
|
|
|
{
|
2020-11-11 13:21:16 +01:00
|
|
|
m_lnfPath = CalamaresUtils::getString( configurationMap, "lnftool" );
|
|
|
|
|
|
|
|
if ( m_lnfPath.isEmpty() )
|
|
|
|
{
|
|
|
|
cWarning() << "no lnftool given for plasmalnf module.";
|
|
|
|
}
|
2020-11-11 14:41:45 +01:00
|
|
|
|
|
|
|
m_liveUser = CalamaresUtils::getString( configurationMap, "liveuser" );
|
2020-11-12 15:36:29 +01:00
|
|
|
|
|
|
|
QString preselect = CalamaresUtils::getString( configurationMap, "preselect" );
|
|
|
|
if ( preselect == QStringLiteral( "*" ) )
|
|
|
|
{
|
|
|
|
preselect = currentPlasmaTheme();
|
|
|
|
}
|
|
|
|
m_preselectThemeId = preselect;
|
2020-11-11 14:41:45 +01:00
|
|
|
}
|
|
|
|
|
2020-11-11 14:45:31 +01:00
|
|
|
Calamares::JobList
|
|
|
|
Config::createJobs() const
|
|
|
|
{
|
|
|
|
Calamares::JobList l;
|
|
|
|
|
|
|
|
cDebug() << "Creating Plasma LNF jobs ..";
|
|
|
|
if ( !theme().isEmpty() )
|
|
|
|
{
|
|
|
|
if ( !lnfToolPath().isEmpty() )
|
|
|
|
{
|
|
|
|
l.append( Calamares::job_ptr( new PlasmaLnfJob( lnfToolPath(), theme() ) ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cWarning() << "no lnftool given for plasmalnf module.";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-11 14:41:45 +01:00
|
|
|
void
|
|
|
|
Config::setTheme( const QString& id )
|
|
|
|
{
|
|
|
|
if ( m_themeId == id )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_themeId = id;
|
|
|
|
if ( lnfToolPath().isEmpty() )
|
|
|
|
{
|
|
|
|
cWarning() << "no lnftool given for plasmalnf module.";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QStringList command;
|
|
|
|
if ( !m_liveUser.isEmpty() )
|
|
|
|
{
|
|
|
|
command << "sudo"
|
|
|
|
<< "-E"
|
|
|
|
<< "-H"
|
|
|
|
<< "-u" << m_liveUser;
|
|
|
|
}
|
|
|
|
command << lnfToolPath() << "--resetLayout"
|
|
|
|
<< "--apply" << id;
|
|
|
|
auto r = CalamaresUtils::System::instance()->runCommand( command, std::chrono::seconds( 10 ) );
|
|
|
|
|
|
|
|
if ( r.getExitCode() )
|
|
|
|
{
|
|
|
|
cWarning() << r.explainProcess( command, std::chrono::seconds( 10 ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cDebug() << "Plasma look-and-feel applied" << id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
emit themeChanged( id );
|
2020-11-11 13:08:42 +01:00
|
|
|
}
|
2020-11-12 15:36:29 +01:00
|
|
|
|
|
|
|
#include "utils/moc-warnings.h"
|
|
|
|
|
|
|
|
#include "Config.moc"
|