[keyboard] Move configuration to the Config object

- information from the configuration file -> Config object
- job creation -> Config object

Ignore keyboardq for now.
This commit is contained in:
Adriaan de Groot 2020-10-12 16:30:06 +02:00
parent 0f6602cad7
commit c7c7e6a6c1
6 changed files with 60 additions and 51 deletions

View File

@ -7,6 +7,7 @@ calamares_add_plugin( keyboard
TYPE viewmodule TYPE viewmodule
EXPORT_MACRO PLUGINDLLEXPORT_PRO EXPORT_MACRO PLUGINDLLEXPORT_PRO
SOURCES SOURCES
Config.cpp
KeyboardViewStep.cpp KeyboardViewStep.cpp
KeyboardPage.cpp KeyboardPage.cpp
KeyboardLayoutModel.cpp KeyboardLayoutModel.cpp

View File

@ -18,6 +18,7 @@
#include "utils/Logger.h" #include "utils/Logger.h"
#include "utils/Retranslator.h" #include "utils/Retranslator.h"
#include "utils/String.h" #include "utils/String.h"
#include "utils/Variant.h"
#include <QApplication> #include <QApplication>
#include <QProcess> #include <QProcess>
@ -214,16 +215,16 @@ Config::prettyStatus() const
} }
Calamares::JobList Calamares::JobList
Config::createJobs( const QString& xOrgConfFileName, const QString& convertedKeymapPath, bool writeEtcDefaultKeyboard ) Config::createJobs()
{ {
QList< Calamares::job_ptr > list; QList< Calamares::job_ptr > list;
Calamares::Job* j = new SetKeyboardLayoutJob( m_selectedModel, Calamares::Job* j = new SetKeyboardLayoutJob( m_selectedModel,
m_selectedLayout, m_selectedLayout,
m_selectedVariant, m_selectedVariant,
xOrgConfFileName, m_xOrgConfFileName,
convertedKeymapPath, m_convertedKeymapPath,
writeEtcDefaultKeyboard ); m_writeEtcDefaultKeyboard );
list.append( Calamares::job_ptr( j ) ); list.append( Calamares::job_ptr( j ) );
return list; return list;
@ -393,3 +394,41 @@ Config::updateVariants( const QPersistentModelIndex& currentItem, QString curren
} }
} }
} }
void
Config::setConfigurationMap( const QVariantMap& configurationMap )
{
using namespace CalamaresUtils;
if ( configurationMap.contains( "xOrgConfFileName" )
&& configurationMap.value( "xOrgConfFileName" ).type() == QVariant::String
&& !getString( configurationMap, "xOrgConfFileName" ).isEmpty() )
{
m_xOrgConfFileName = getString( configurationMap, "xOrgConfFileName" );
}
else
{
m_xOrgConfFileName = "00-keyboard.conf";
}
if ( configurationMap.contains( "convertedKeymapPath" )
&& configurationMap.value( "convertedKeymapPath" ).type() == QVariant::String
&& !getString( configurationMap, "convertedKeymapPath" ).isEmpty() )
{
m_convertedKeymapPath = getString( configurationMap, "convertedKeymapPath" );
}
else
{
m_convertedKeymapPath = QString();
}
if ( configurationMap.contains( "writeEtcDefaultKeyboard" )
&& configurationMap.value( "writeEtcDefaultKeyboard" ).type() == QVariant::Bool )
{
m_writeEtcDefaultKeyboard = getBool( configurationMap, "writeEtcDefaultKeyboard", true );
}
else
{
m_writeEtcDefaultKeyboard = true;
}
}

View File

@ -33,13 +33,14 @@ public:
void init(); void init();
Calamares::JobList Calamares::JobList createJobs();
createJobs( const QString& xOrgConfFileName, const QString& convertedKeymapPath, bool writeEtcDefaultKeyboard );
QString prettyStatus() const; QString prettyStatus() const;
void onActivate(); void onActivate();
void finalize(); void finalize();
void setConfigurationMap( const QVariantMap& configurationMap );
private: private:
void guessLayout( const QStringList& langParts ); void guessLayout( const QStringList& langParts );
void updateVariants( const QPersistentModelIndex& currentItem, QString currentVariant = QString() ); void updateVariants( const QPersistentModelIndex& currentItem, QString currentVariant = QString() );
@ -53,6 +54,12 @@ private:
QString m_selectedVariant; QString m_selectedVariant;
QTimer m_setxkbmapTimer; QTimer m_setxkbmapTimer;
// From configuration
QString m_xOrgConfFileName;
QString m_convertedKeymapPath;
bool m_writeEtcDefaultKeyboard = true;
protected: protected:
KeyboardModelsModel* keyboardModels() const; KeyboardModelsModel* keyboardModels() const;
KeyboardLayoutModel* keyboardLayouts() const; KeyboardLayoutModel* keyboardLayouts() const;

View File

@ -9,20 +9,19 @@
#include "KeyboardViewStep.h" #include "KeyboardViewStep.h"
#include "Config.h"
#include "KeyboardPage.h" #include "KeyboardPage.h"
#include "GlobalStorage.h" #include "GlobalStorage.h"
#include "JobQueue.h" #include "JobQueue.h"
#include "utils/Variant.h"
CALAMARES_PLUGIN_FACTORY_DEFINITION( KeyboardViewStepFactory, registerPlugin< KeyboardViewStep >(); ) CALAMARES_PLUGIN_FACTORY_DEFINITION( KeyboardViewStepFactory, registerPlugin< KeyboardViewStep >(); )
KeyboardViewStep::KeyboardViewStep( QObject* parent ) KeyboardViewStep::KeyboardViewStep( QObject* parent )
: Calamares::ViewStep( parent ) : Calamares::ViewStep( parent )
, m_config( new Config(this) )
, m_widget( new KeyboardPage() ) , m_widget( new KeyboardPage() )
, m_nextEnabled( false ) , m_nextEnabled( false )
, m_writeEtcDefaultKeyboard( true )
{ {
m_widget->init(); m_widget->init();
m_nextEnabled = true; m_nextEnabled = true;
@ -91,7 +90,7 @@ KeyboardViewStep::isAtEnd() const
QList< Calamares::job_ptr > QList< Calamares::job_ptr >
KeyboardViewStep::jobs() const KeyboardViewStep::jobs() const
{ {
return m_jobs; return m_config->createJobs();
} }
@ -106,7 +105,6 @@ void
KeyboardViewStep::onLeave() KeyboardViewStep::onLeave()
{ {
m_widget->finalize(); m_widget->finalize();
m_jobs = m_widget->createJobs( m_xOrgConfFileName, m_convertedKeymapPath, m_writeEtcDefaultKeyboard );
m_prettyStatus = m_widget->prettyStatus(); m_prettyStatus = m_widget->prettyStatus();
} }
@ -114,37 +112,5 @@ KeyboardViewStep::onLeave()
void void
KeyboardViewStep::setConfigurationMap( const QVariantMap& configurationMap ) KeyboardViewStep::setConfigurationMap( const QVariantMap& configurationMap )
{ {
using namespace CalamaresUtils; m_config->setConfigurationMap(configurationMap);
if ( configurationMap.contains( "xOrgConfFileName" )
&& configurationMap.value( "xOrgConfFileName" ).type() == QVariant::String
&& !getString( configurationMap, "xOrgConfFileName" ).isEmpty() )
{
m_xOrgConfFileName = getString( configurationMap, "xOrgConfFileName" );
}
else
{
m_xOrgConfFileName = "00-keyboard.conf";
}
if ( configurationMap.contains( "convertedKeymapPath" )
&& configurationMap.value( "convertedKeymapPath" ).type() == QVariant::String
&& !getString( configurationMap, "convertedKeymapPath" ).isEmpty() )
{
m_convertedKeymapPath = getString( configurationMap, "convertedKeymapPath" );
}
else
{
m_convertedKeymapPath = QString();
}
if ( configurationMap.contains( "writeEtcDefaultKeyboard" )
&& configurationMap.value( "writeEtcDefaultKeyboard" ).type() == QVariant::Bool )
{
m_writeEtcDefaultKeyboard = getBool( configurationMap, "writeEtcDefaultKeyboard", true );
}
else
{
m_writeEtcDefaultKeyboard = true;
}
} }

View File

@ -17,6 +17,7 @@
#include <QObject> #include <QObject>
class Config;
class KeyboardPage; class KeyboardPage;
class PLUGINDLLEXPORT KeyboardViewStep : public Calamares::ViewStep class PLUGINDLLEXPORT KeyboardViewStep : public Calamares::ViewStep
@ -46,15 +47,10 @@ public:
void setConfigurationMap( const QVariantMap& configurationMap ) override; void setConfigurationMap( const QVariantMap& configurationMap ) override;
private: private:
Config* m_config;
KeyboardPage* m_widget; KeyboardPage* m_widget;
bool m_nextEnabled; bool m_nextEnabled;
QString m_prettyStatus; QString m_prettyStatus;
QString m_xOrgConfFileName;
QString m_convertedKeymapPath;
bool m_writeEtcDefaultKeyboard;
Calamares::JobList m_jobs;
}; };
CALAMARES_PLUGIN_FACTORY_DECLARATION( KeyboardViewStepFactory ) CALAMARES_PLUGIN_FACTORY_DECLARATION( KeyboardViewStepFactory )

View File

@ -79,7 +79,7 @@ void
KeyboardQmlViewStep::onLeave() KeyboardQmlViewStep::onLeave()
{ {
m_config->finalize(); m_config->finalize();
m_jobs = m_config->createJobs( m_xOrgConfFileName, m_convertedKeymapPath, m_writeEtcDefaultKeyboard ); // m_jobs = m_config->createJobs( m_xOrgConfFileName, m_convertedKeymapPath, m_writeEtcDefaultKeyboard );
m_prettyStatus = m_config->prettyStatus(); m_prettyStatus = m_config->prettyStatus();
} }