[plasmalnf] Migrate more settings to Config

This commit is contained in:
Adriaan de Groot 2020-11-11 14:41:45 +01:00
parent b4aca7e188
commit 0af12546ef
4 changed files with 69 additions and 47 deletions

View File

@ -9,6 +9,7 @@
#include "Config.h" #include "Config.h"
#include "utils/CalamaresUtilsSystem.h"
#include "utils/Logger.h" #include "utils/Logger.h"
#include "utils/Variant.h" #include "utils/Variant.h"
@ -26,4 +27,45 @@ Config::setConfigurationMap( const QVariantMap& configurationMap )
{ {
cWarning() << "no lnftool given for plasmalnf module."; cWarning() << "no lnftool given for plasmalnf module.";
} }
m_liveUser = CalamaresUtils::getString( configurationMap, "liveuser" );
}
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 );
} }

View File

@ -16,16 +16,40 @@ class Config : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY( QString theme READ theme WRITE setTheme NOTIFY themeChanged )
public: public:
Config( QObject* parent = nullptr ); Config( QObject* parent = nullptr );
virtual ~Config() override = default; virtual ~Config() override = default;
void setConfigurationMap( const QVariantMap& ); void setConfigurationMap( const QVariantMap& );
/** @brief Full path to the lookandfeeltool (if it exists)
*
* This can be configured, or defaults to `lookandfeeltool` to find
* it in $PATH.
*/
QString lnfToolPath() const { return m_lnfPath; } QString lnfToolPath() const { return m_lnfPath; }
/** @brief For OEM mode, the name of the (current) live user
*
*/
QString liveUser() const { return m_liveUser; }
/** @brief The id (in reverse-DNS notation) of the current theme.
*/
QString theme() const { return m_themeId; }
public slots:
void setTheme( const QString& id );
signals:
void themeChanged( const QString& id );
private: private:
QString m_lnfPath; // Path to the lnf tool QString m_lnfPath; // Path to the lnf tool
QString m_liveUser; // Name of the live user (for OEM mode)
QString m_themeId; // Id of selected theme
}; };
#endif #endif

View File

@ -43,7 +43,7 @@ PlasmaLnfViewStep::PlasmaLnfViewStep( QObject* parent )
, m_config( new Config( this ) ) , m_config( new Config( this ) )
, m_widget( new PlasmaLnfPage ) , m_widget( new PlasmaLnfPage )
{ {
connect( m_widget, &PlasmaLnfPage::plasmaThemeSelected, this, &PlasmaLnfViewStep::themeSelected ); connect( m_widget, &PlasmaLnfPage::plasmaThemeSelected, m_config, &Config::setTheme );
emit nextStatusChanged( false ); emit nextStatusChanged( false );
} }
@ -111,11 +111,11 @@ PlasmaLnfViewStep::jobs() const
Calamares::JobList l; Calamares::JobList l;
cDebug() << "Creating Plasma LNF jobs .."; cDebug() << "Creating Plasma LNF jobs ..";
if ( !m_themeId.isEmpty() ) if ( !m_config->theme().isEmpty() )
{ {
if ( !m_config->lnfToolPath().isEmpty() ) if ( !m_config->lnfToolPath().isEmpty() )
{ {
l.append( Calamares::job_ptr( new PlasmaLnfJob( m_config->lnfToolPath(), m_themeId ) ) ); l.append( Calamares::job_ptr( new PlasmaLnfJob( m_config->lnfToolPath(), m_config->theme() ) ) );
} }
else else
{ {
@ -133,8 +133,6 @@ PlasmaLnfViewStep::setConfigurationMap( const QVariantMap& configurationMap )
m_widget->setLnfPath( m_config->lnfToolPath() ); m_widget->setLnfPath( m_config->lnfToolPath() );
m_liveUser = CalamaresUtils::getString( configurationMap, "liveuser" );
QString preselect = CalamaresUtils::getString( configurationMap, "preselect" ); QString preselect = CalamaresUtils::getString( configurationMap, "preselect" );
if ( preselect == QStringLiteral( "*" ) ) if ( preselect == QStringLiteral( "*" ) )
{ {
@ -176,40 +174,3 @@ PlasmaLnfViewStep::setConfigurationMap( const QVariantMap& configurationMap )
m_widget->setEnabledThemesAll(); // All of them m_widget->setEnabledThemesAll(); // All of them
} }
} }
void
PlasmaLnfViewStep::themeSelected( const QString& id )
{
m_themeId = id;
if ( m_config->lnfToolPath().isEmpty() )
{
cWarning() << "no lnftool given for plasmalnf module.";
return;
}
QProcess lnftool;
if ( !m_liveUser.isEmpty() )
lnftool.start( "sudo", { "-E", "-H", "-u", m_liveUser, m_config->lnfToolPath(), "--resetLayout", "--apply", id } );
else
lnftool.start( m_config->lnfToolPath(), { "--resetLayout", "--apply", id } );
if ( !lnftool.waitForStarted( 1000 ) )
{
cWarning() << "could not start look-and-feel" << m_config->lnfToolPath();
return;
}
if ( !lnftool.waitForFinished() )
{
cWarning() << m_config->lnfToolPath() << "timed out.";
return;
}
if ( ( lnftool.exitCode() == 0 ) && ( lnftool.exitStatus() == QProcess::NormalExit ) )
{
cDebug() << "Plasma look-and-feel applied" << id;
}
else
{
cWarning() << "could not apply look-and-feel" << id;
}
}

View File

@ -41,14 +41,9 @@ public:
void setConfigurationMap( const QVariantMap& configurationMap ) override; void setConfigurationMap( const QVariantMap& configurationMap ) override;
public slots:
void themeSelected( const QString& id );
private: private:
Config* m_config; Config* m_config;
PlasmaLnfPage* m_widget; PlasmaLnfPage* m_widget;
QString m_themeId; // Id of selected theme
QString m_liveUser; // Name of the live user (for OEM mode)
}; };
CALAMARES_PLUGIN_FACTORY_DECLARATION( PlasmaLnfViewStepFactory ) CALAMARES_PLUGIN_FACTORY_DECLARATION( PlasmaLnfViewStepFactory )