Keyboard: guess at layout based on locale
Split locale into <language>_<country> and go looking for keyboard layouts that match. Do that in reverse, so look for country first. - known weakness is el_CY (should get layout gr) because CY and el don't name any keyboard layout. - known weakness are Hausa, Igbo .. which are ha_NG and ig_NG. They select keyboard layout ng, which is labeled "English (Nigeria)"; they ought to select ng(hausa) and ng(igbo), which are the right variant keyboard layouts to use. - similar selecting a locale in Canada (en_CA, fr_CA, iu_CA ...) will select keyboard layout ca, which is for French-speaking Canada. Locale en_CA should select keyboard en -- e.g. en(us). But iu_CA (Inuktituk) needs layout ca(ike).
This commit is contained in:
parent
8d9f75ffba
commit
88715b9a0f
@ -1,6 +1,7 @@
|
||||
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||
*
|
||||
* Copyright 2014-2016, Teo Mrnjavac <teo@kde.org>
|
||||
* Copyright 2017, Adriaan de Groot <groot@kde.org>
|
||||
*
|
||||
* Portions from the Manjaro Installation Framework
|
||||
* by Roland Singer <roland@manjaro.org>
|
||||
@ -221,10 +222,58 @@ KeyboardPage::createJobs( const QString& xOrgConfFileName,
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
KeyboardPage::guessLayout( const QStringList& langParts )
|
||||
{
|
||||
const KeyboardLayoutModel* klm = dynamic_cast< KeyboardLayoutModel* >( ui->listLayout->model() );
|
||||
bool foundCountryPart = false;
|
||||
for ( auto countryPart = langParts.rbegin(); !foundCountryPart && countryPart != langParts.rend(); ++countryPart)
|
||||
{
|
||||
cDebug() << " .. looking for locale part" << *countryPart;
|
||||
for ( int i = 0; i < klm->rowCount(); ++i )
|
||||
{
|
||||
QModelIndex idx = klm->index( i );
|
||||
if ( idx.isValid() &&
|
||||
( idx.data( KeyboardLayoutModel::KeyboardLayoutKeyRole ).toString().compare( *countryPart, Qt::CaseInsensitive ) == 0 ) )
|
||||
{
|
||||
cDebug() << " .. matched" << idx.data( KeyboardLayoutModel::KeyboardLayoutKeyRole ).toString();
|
||||
ui->listLayout->setCurrentIndex( idx );
|
||||
foundCountryPart = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
KeyboardPage::onActivate()
|
||||
{
|
||||
ui->listLayout->setFocus();
|
||||
|
||||
// Try to preselect a layout, depending on language and locale
|
||||
Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage();
|
||||
QString lang = gs->value( "localeConf" ).toMap().value( "LANG" ).toString();
|
||||
|
||||
cDebug() << "Got locale language" << lang;
|
||||
if ( !lang.isEmpty() )
|
||||
{
|
||||
// Chop off .codeset and @modifier
|
||||
int index = lang.indexOf('.');
|
||||
if ( index >= 0 )
|
||||
lang.truncate( index );
|
||||
index = lang.indexOf('@');
|
||||
if ( index >= 0 )
|
||||
lang.truncate( index );
|
||||
|
||||
lang.replace( '-', '_' ); // Normalize separators
|
||||
const auto langParts = lang.split( '_' , QString::SkipEmptyParts );
|
||||
|
||||
QString country = QLocale::countryToString( QLocale( lang ).country() );
|
||||
cDebug() << " .. extracted country" << country << "::" << langParts;
|
||||
|
||||
guessLayout( langParts );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||
*
|
||||
* Copyright 2014-2016, Teo Mrnjavac <teo@kde.org>
|
||||
* Copyright 2017, Adriaan de Groot <groot@kde.org>
|
||||
*
|
||||
* Portions from the Manjaro Installation Framework
|
||||
* by Roland Singer <roland@manjaro.org>
|
||||
@ -70,6 +71,8 @@ private:
|
||||
KeyboardGlobal::KeyboardInfo info;
|
||||
};
|
||||
|
||||
/// Guess a layout based on the split-apart locale
|
||||
void guessLayout( const QStringList& langParts );
|
||||
void updateVariants( const QPersistentModelIndex& currentItem,
|
||||
QString currentVariant = QString() );
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user