[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:
parent
f38b518e86
commit
12b23db286
@ -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 <lang>_<country>
|
||||
@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -95,7 +95,7 @@ KeyboardViewStep::jobs() const
|
||||
void
|
||||
KeyboardViewStep::onActivate()
|
||||
{
|
||||
m_config->onActivate();
|
||||
m_config->guessLocaleKeyboardLayout();
|
||||
}
|
||||
|
||||
|
||||
|
@ -71,7 +71,7 @@ KeyboardQmlViewStep::jobs() const
|
||||
void
|
||||
KeyboardQmlViewStep::onActivate()
|
||||
{
|
||||
m_config->onActivate();
|
||||
m_config->guessLocaleKeyboardLayout();
|
||||
}
|
||||
|
||||
void
|
||||
|
Loading…
Reference in New Issue
Block a user