diff --git a/src/modules/keyboard/Config.cpp b/src/modules/keyboard/Config.cpp index 489f4a1ac..b137927b4 100644 --- a/src/modules/keyboard/Config.cpp +++ b/src/modules/keyboard/Config.cpp @@ -366,22 +366,22 @@ Config::createJobs() return list; } -void -Config::guessLayout( const QStringList& langParts ) +static void +guessLayout( const QStringList& langParts, KeyboardLayoutModel* layouts, KeyboardVariantsModel* variants ) { bool foundCountryPart = false; for ( auto countryPart = langParts.rbegin(); !foundCountryPart && countryPart != langParts.rend(); ++countryPart ) { cDebug() << Logger::SubEntry << "looking for locale part" << *countryPart; - for ( int i = 0; i < m_keyboardLayoutsModel->rowCount(); ++i ) + for ( int i = 0; i < layouts->rowCount(); ++i ) { - QModelIndex idx = m_keyboardLayoutsModel->index( i ); + QModelIndex idx = layouts->index( i ); QString name = idx.isValid() ? idx.data( KeyboardLayoutModel::KeyboardLayoutKeyRole ).toString() : QString(); if ( idx.isValid() && ( name.compare( *countryPart, Qt::CaseInsensitive ) == 0 ) ) { cDebug() << Logger::SubEntry << "matched" << name; - m_keyboardLayoutsModel->setCurrentIndex( i ); + layouts->setCurrentIndex( i ); foundCountryPart = true; break; } @@ -392,14 +392,13 @@ Config::guessLayout( const QStringList& langParts ) if ( countryPart != langParts.rend() ) { cDebug() << "Next level:" << *countryPart; - for ( int variantnumber = 0; variantnumber < m_keyboardVariantsModel->rowCount(); ++variantnumber ) + for ( int variantnumber = 0; variantnumber < variants->rowCount(); ++variantnumber ) { - if ( m_keyboardVariantsModel->key( variantnumber ).compare( *countryPart, Qt::CaseInsensitive ) - == 0 ) + if ( variants->key( variantnumber ).compare( *countryPart, Qt::CaseInsensitive ) == 0 ) { - m_keyboardVariantsModel->setCurrentIndex( variantnumber ); + variants->setCurrentIndex( variantnumber ); cDebug() << Logger::SubEntry << "matched variant" << *countryPart << ' ' - << m_keyboardVariantsModel->key( variantnumber ); + << variants->key( variantnumber ); } } } @@ -408,7 +407,7 @@ Config::guessLayout( const QStringList& langParts ) } void -Config::onActivate() +Config::guessLocaleKeyboardLayout() { /* Guessing a keyboard layout based on the locale means * mapping between language identifiers in _ @@ -495,7 +494,7 @@ Config::onActivate() QString country = QLocale::countryToString( QLocale( lang ).country() ); cDebug() << Logger::SubEntry << "extracted country" << country << "::" << langParts; - guessLayout( langParts ); + guessLayout( langParts, m_keyboardLayoutsModel, m_keyboardVariantsModel ); } } diff --git a/src/modules/keyboard/Config.h b/src/modules/keyboard/Config.h index 4919a154c..d4090bafc 100644 --- a/src/modules/keyboard/Config.h +++ b/src/modules/keyboard/Config.h @@ -32,16 +32,17 @@ class Config : public QObject public: Config( QObject* parent = nullptr ); + /// @brief Based on current xkb settings, pick a layout void detectCurrentKeyboardLayout(); + /// @brief Based on current locale, pick a layout + void guessLocaleKeyboardLayout(); Calamares::JobList createJobs(); QString prettyStatus() const; - void onActivate(); + /// @brief When leaving the page, write to GS void finalize(); - void setConfigurationMap( const QVariantMap& configurationMap ); - static AdditionalLayoutInfo getAdditionalLayoutInfo( const QString& layout ); /* A model is a physical configuration of a keyboard, e.g. 105-key PC @@ -69,11 +70,12 @@ public: */ void retranslate(); + void setConfigurationMap( const QVariantMap& configurationMap ); + signals: void prettyStatusChanged(); private: - void guessLayout( const QStringList& langParts ); void updateVariants( const QPersistentModelIndex& currentItem, QString currentVariant = QString() ); /* These two methods are used in tandem to apply changes to the diff --git a/src/modules/keyboard/KeyboardViewStep.cpp b/src/modules/keyboard/KeyboardViewStep.cpp index d1eb3eb68..029e1ae85 100644 --- a/src/modules/keyboard/KeyboardViewStep.cpp +++ b/src/modules/keyboard/KeyboardViewStep.cpp @@ -95,7 +95,7 @@ KeyboardViewStep::jobs() const void KeyboardViewStep::onActivate() { - m_config->onActivate(); + m_config->guessLocaleKeyboardLayout(); } diff --git a/src/modules/keyboardq/KeyboardQmlViewStep.cpp b/src/modules/keyboardq/KeyboardQmlViewStep.cpp index e8ae630e7..231d2a090 100644 --- a/src/modules/keyboardq/KeyboardQmlViewStep.cpp +++ b/src/modules/keyboardq/KeyboardQmlViewStep.cpp @@ -71,7 +71,7 @@ KeyboardQmlViewStep::jobs() const void KeyboardQmlViewStep::onActivate() { - m_config->onActivate(); + m_config->guessLocaleKeyboardLayout(); } void