[keyboard] Move remaining variables to Config

- Config already *has* everythind, but drop the useless copies
  and duplicated code from the Page
- Plug the models model into the Page
- While here, document the model / layout / variant distinctions

The code doesn't fill the UI properly, and the drop-down
for the models combobox is not right, but at least the data
is shared.
This commit is contained in:
Adriaan de Groot 2020-10-28 01:10:05 +01:00
parent fe5757c7d1
commit d464e98e89
4 changed files with 34 additions and 58 deletions

View File

@ -44,6 +44,23 @@ public:
static AdditionalLayoutInfo getAdditionalLayoutInfo( const QString& layout );
/* A model is a physical configuration of a keyboard, e.g. 105-key PC
* or TKL 88-key physical size.
*/
KeyboardModelsModel* keyboardModels() const;
/* A layout describes the basic keycaps / language assigned to the
* keys of the physical keyboard, e.g. English (US) or Russian.
*/
KeyboardLayoutModel* keyboardLayouts() const;
/* A variant describes a variant of the basic keycaps; this can
* concern options (dead keys), or different placements of the keycaps
* (dvorak).
*/
KeyboardVariantsModel* keyboardVariants() const;
signals:
void prettyStatusChanged();
private:
void guessLayout( const QStringList& langParts );
void updateVariants( const QPersistentModelIndex& currentItem, QString currentVariant = QString() );
@ -65,16 +82,6 @@ private:
QString m_xOrgConfFileName;
QString m_convertedKeymapPath;
bool m_writeEtcDefaultKeyboard = true;
protected:
KeyboardModelsModel* keyboardModels() const;
KeyboardLayoutModel* keyboardLayouts() const;
KeyboardVariantsModel* keyboardVariants() const;
signals:
void prettyStatusChanged();
};

View File

@ -15,6 +15,7 @@
#include "KeyboardPage.h"
#include "Config.h"
#include "KeyboardLayoutModel.h"
#include "SetKeyboardLayoutJob.h"
#include "keyboardwidget/keyboardpreview.h"
@ -40,30 +41,32 @@ public:
LayoutItem::~LayoutItem() {}
KeyboardPage::KeyboardPage( QWidget* parent )
KeyboardPage::KeyboardPage( Config* config, QWidget* parent )
: QWidget( parent )
, ui( new Ui::Page_Keyboard )
, m_keyboardPreview( new KeyBoardPreview( this ) )
, m_defaultIndex( 0 )
{
ui->setupUi( this );
// Keyboard Preview
ui->KBPreviewLayout->addWidget( m_keyboardPreview );
m_setxkbmapTimer.setSingleShot( true );
ui->comboBoxModel->setModel( config->keyboardModels() );
// Connect signals and slots
connect( ui->listVariant, &QListWidget::currentItemChanged, this, &KeyboardPage::onListVariantCurrentItemChanged );
connect(
ui->buttonRestore, &QPushButton::clicked, [this] { ui->comboBoxModel->setCurrentIndex( m_defaultIndex ); } );
ui->buttonRestore, &QPushButton::clicked, [this] {
cDebug() << "Restore clicked";
// ui->comboBoxModel->setCurrentIndex( m_defaultIndex );
} );
connect( ui->comboBoxModel, &QComboBox::currentTextChanged, [this]( const QString& text ) {
QString model = m_models.value( text, "pc105" );
cDebug() << "ComboBox changed to" << text;
// QString model = m_models.value( text, "pc105" );
// Set Xorg keyboard model
QProcess::execute( "setxkbmap", QStringList { "-model", model } );
// QProcess::execute( "setxkbmap", QStringList { "-model", model } );
} );
CALAMARES_RETRANSLATE( ui->retranslateUi( this ); )
@ -128,25 +131,13 @@ KeyboardPage::onListLayoutCurrentItemChanged( const QModelIndex& current, const
updateVariants( QPersistentModelIndex( current ) );
}
/* Returns stringlist with suitable setxkbmap command-line arguments
* to set the given @p layout and @p variant.
*/
static inline QStringList
xkbmap_args( const QString& layout, const QString& variant )
{
QStringList r { "-layout", layout };
if ( !variant.isEmpty() )
{
r << "-variant" << variant;
}
return r;
}
void
KeyboardPage::onListVariantCurrentItemChanged( QListWidgetItem* current, QListWidgetItem* previous )
{
Q_UNUSED( previous )
cDebug() << "item" << Logger::Pointer( current );
QPersistentModelIndex layoutIndex = ui->listLayout->currentIndex();
LayoutItem* variantItem = dynamic_cast< LayoutItem* >( current );
@ -158,25 +149,8 @@ KeyboardPage::onListVariantCurrentItemChanged( QListWidgetItem* current, QListWi
QString layout = layoutIndex.data( KeyboardLayoutModel::KeyboardLayoutKeyRole ).toString();
QString variant = variantItem->data;
cDebug() << Logger::SubEntry << layout << variant;
m_keyboardPreview->setLayout( layout );
m_keyboardPreview->setVariant( variant );
//emit checkReady();
// Set Xorg keyboard layout
if ( m_setxkbmapTimer.isActive() )
{
m_setxkbmapTimer.stop();
m_setxkbmapTimer.disconnect( this );
}
connect( &m_setxkbmapTimer, &QTimer::timeout, this, [=] {
QProcess::execute( "setxkbmap", xkbmap_args( layout, variant ) );
cDebug() << "xkbmap selection changed to: " << layout << '-' << variant;
m_setxkbmapTimer.disconnect( this );
} );
m_setxkbmapTimer.start( QApplication::keyboardInputInterval() );
m_selectedLayout = layout;
m_selectedVariant = variant;
}

View File

@ -27,13 +27,14 @@ namespace Ui
class Page_Keyboard;
}
class Config;
class KeyBoardPreview;
class KeyboardPage : public QWidget
{
Q_OBJECT
public:
explicit KeyboardPage( QWidget* parent = nullptr );
explicit KeyboardPage( Config* config, QWidget* parent = nullptr );
~KeyboardPage() override;
protected slots:
@ -45,12 +46,6 @@ private:
Ui::Page_Keyboard* ui;
KeyBoardPreview* m_keyboardPreview;
int m_defaultIndex;
QMap< QString, QString > m_models;
QString m_selectedLayout;
QString m_selectedVariant;
QTimer m_setxkbmapTimer;
};
#endif // KEYBOARDPAGE_H

View File

@ -20,7 +20,7 @@ CALAMARES_PLUGIN_FACTORY_DEFINITION( KeyboardViewStepFactory, registerPlugin< Ke
KeyboardViewStep::KeyboardViewStep( QObject* parent )
: Calamares::ViewStep( parent )
, m_config( new Config(this) )
, m_widget( new KeyboardPage() )
, m_widget( new KeyboardPage( m_config ) )
{
m_config->detectCurrentKeyboardLayout();
emit nextStatusChanged( true );