[keyboard] Re-phrase API

- expose only intended API, guessLayout() becomes internal and static
- rename onActivate() since it was *called* for activation, but does
  something totally different.
This commit is contained in:
Adriaan de Groot 2021-07-30 22:17:26 +02:00
parent f38b518e86
commit 12b23db286
4 changed files with 19 additions and 18 deletions

View file

@ -366,22 +366,22 @@ Config::createJobs()
return list; return list;
} }
void static void
Config::guessLayout( const QStringList& langParts ) guessLayout( const QStringList& langParts, KeyboardLayoutModel* layouts, KeyboardVariantsModel* variants )
{ {
bool foundCountryPart = false; bool foundCountryPart = false;
for ( auto countryPart = langParts.rbegin(); !foundCountryPart && countryPart != langParts.rend(); ++countryPart ) for ( auto countryPart = langParts.rbegin(); !foundCountryPart && countryPart != langParts.rend(); ++countryPart )
{ {
cDebug() << Logger::SubEntry << "looking for locale part" << *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 QString name
= idx.isValid() ? idx.data( KeyboardLayoutModel::KeyboardLayoutKeyRole ).toString() : QString(); = idx.isValid() ? idx.data( KeyboardLayoutModel::KeyboardLayoutKeyRole ).toString() : QString();
if ( idx.isValid() && ( name.compare( *countryPart, Qt::CaseInsensitive ) == 0 ) ) if ( idx.isValid() && ( name.compare( *countryPart, Qt::CaseInsensitive ) == 0 ) )
{ {
cDebug() << Logger::SubEntry << "matched" << name; cDebug() << Logger::SubEntry << "matched" << name;
m_keyboardLayoutsModel->setCurrentIndex( i ); layouts->setCurrentIndex( i );
foundCountryPart = true; foundCountryPart = true;
break; break;
} }
@ -392,14 +392,13 @@ Config::guessLayout( const QStringList& langParts )
if ( countryPart != langParts.rend() ) if ( countryPart != langParts.rend() )
{ {
cDebug() << "Next level:" << *countryPart; 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 ) if ( variants->key( variantnumber ).compare( *countryPart, Qt::CaseInsensitive ) == 0 )
== 0 )
{ {
m_keyboardVariantsModel->setCurrentIndex( variantnumber ); variants->setCurrentIndex( variantnumber );
cDebug() << Logger::SubEntry << "matched variant" << *countryPart << ' ' cDebug() << Logger::SubEntry << "matched variant" << *countryPart << ' '
<< m_keyboardVariantsModel->key( variantnumber ); << variants->key( variantnumber );
} }
} }
} }
@ -408,7 +407,7 @@ Config::guessLayout( const QStringList& langParts )
} }
void void
Config::onActivate() Config::guessLocaleKeyboardLayout()
{ {
/* Guessing a keyboard layout based on the locale means /* Guessing a keyboard layout based on the locale means
* mapping between language identifiers in <lang>_<country> * mapping between language identifiers in <lang>_<country>
@ -495,7 +494,7 @@ Config::onActivate()
QString country = QLocale::countryToString( QLocale( lang ).country() ); QString country = QLocale::countryToString( QLocale( lang ).country() );
cDebug() << Logger::SubEntry << "extracted country" << country << "::" << langParts; cDebug() << Logger::SubEntry << "extracted country" << country << "::" << langParts;
guessLayout( langParts ); guessLayout( langParts, m_keyboardLayoutsModel, m_keyboardVariantsModel );
} }
} }

View file

@ -32,16 +32,17 @@ class Config : public QObject
public: public:
Config( QObject* parent = nullptr ); Config( QObject* parent = nullptr );
/// @brief Based on current xkb settings, pick a layout
void detectCurrentKeyboardLayout(); void detectCurrentKeyboardLayout();
/// @brief Based on current locale, pick a layout
void guessLocaleKeyboardLayout();
Calamares::JobList createJobs(); Calamares::JobList createJobs();
QString prettyStatus() const; QString prettyStatus() const;
void onActivate(); /// @brief When leaving the page, write to GS
void finalize(); void finalize();
void setConfigurationMap( const QVariantMap& configurationMap );
static AdditionalLayoutInfo getAdditionalLayoutInfo( const QString& layout ); static AdditionalLayoutInfo getAdditionalLayoutInfo( const QString& layout );
/* A model is a physical configuration of a keyboard, e.g. 105-key PC /* A model is a physical configuration of a keyboard, e.g. 105-key PC
@ -69,11 +70,12 @@ public:
*/ */
void retranslate(); void retranslate();
void setConfigurationMap( const QVariantMap& configurationMap );
signals: signals:
void prettyStatusChanged(); void prettyStatusChanged();
private: private:
void guessLayout( const QStringList& langParts );
void updateVariants( const QPersistentModelIndex& currentItem, QString currentVariant = QString() ); void updateVariants( const QPersistentModelIndex& currentItem, QString currentVariant = QString() );
/* These two methods are used in tandem to apply changes to the /* These two methods are used in tandem to apply changes to the

View file

@ -95,7 +95,7 @@ KeyboardViewStep::jobs() const
void void
KeyboardViewStep::onActivate() KeyboardViewStep::onActivate()
{ {
m_config->onActivate(); m_config->guessLocaleKeyboardLayout();
} }

View file

@ -71,7 +71,7 @@ KeyboardQmlViewStep::jobs() const
void void
KeyboardQmlViewStep::onActivate() KeyboardQmlViewStep::onActivate()
{ {
m_config->onActivate(); m_config->guessLocaleKeyboardLayout();
} }
void void