[keyboard] match keyboard layouts with selected sys-lang
This commit is contained in:
parent
4b4bd83a39
commit
243d7c5e29
@ -64,9 +64,7 @@ KeyboardLayoutModel::init()
|
||||
KeyboardGlobal::getKeyboardLayouts();
|
||||
for ( KeyboardGlobal::LayoutsMap::const_iterator it = layouts.constBegin();
|
||||
it != layouts.constEnd(); ++it )
|
||||
{
|
||||
m_layouts.append( qMakePair( it.key(), it.value() ) );
|
||||
}
|
||||
|
||||
std::stable_sort( m_layouts.begin(), m_layouts.end(), []( const QPair< QString, KeyboardGlobal::KeyboardInfo >& a,
|
||||
const QPair< QString, KeyboardGlobal::KeyboardInfo >& b )
|
||||
|
@ -259,15 +259,32 @@ KeyboardPage::guessLayout( const QStringList& langParts )
|
||||
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 ) )
|
||||
QString name = idx.isValid() ? idx.data( KeyboardLayoutModel::KeyboardLayoutKeyRole ).toString() : QString();
|
||||
if ( idx.isValid() && ( name.compare( *countryPart, Qt::CaseInsensitive ) == 0 ) )
|
||||
{
|
||||
cDebug() << " .. matched" << idx.data( KeyboardLayoutModel::KeyboardLayoutKeyRole ).toString();
|
||||
cDebug() << " .. matched" << name;
|
||||
ui->listLayout->setCurrentIndex( idx );
|
||||
foundCountryPart = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( foundCountryPart )
|
||||
{
|
||||
++countryPart;
|
||||
if ( countryPart != langParts.rend() )
|
||||
{
|
||||
cDebug() << "Next level:" << *countryPart;
|
||||
for (int variantnumber = 0; variantnumber < ui->listVariant->count(); ++variantnumber)
|
||||
{
|
||||
LayoutItem *variantdata = dynamic_cast< LayoutItem* >( ui->listVariant->item( variantnumber ) );
|
||||
if ( variantdata && (variantdata->data.compare( *countryPart, Qt::CaseInsensitive ) == 0) )
|
||||
{
|
||||
ui->listVariant->setCurrentItem( variantdata );
|
||||
cDebug() << " .. matched variant" << variantdata->data << ' ' << variantdata->text();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -275,6 +292,12 @@ KeyboardPage::guessLayout( const QStringList& langParts )
|
||||
void
|
||||
KeyboardPage::onActivate()
|
||||
{
|
||||
static auto specialCaseMap = QMap<std::string, std::string>( {
|
||||
{ "ar_EG", "ara" },
|
||||
{ "ca_ES", "cat_ES" },
|
||||
{ "as_ES", "ast_ES" },
|
||||
} );
|
||||
|
||||
ui->listLayout->setFocus();
|
||||
|
||||
// Try to preselect a layout, depending on language and locale
|
||||
@ -293,6 +316,15 @@ KeyboardPage::onActivate()
|
||||
lang.truncate( index );
|
||||
|
||||
lang.replace( '-', '_' ); // Normalize separators
|
||||
}
|
||||
if ( !lang.isEmpty() && specialCaseMap.contains( lang.toStdString() ) )
|
||||
{
|
||||
QLatin1String newLang( specialCaseMap.value( lang.toStdString() ).c_str() );
|
||||
cDebug() << " .. special case language" << lang << '>' << newLang;
|
||||
lang = newLang;
|
||||
}
|
||||
if ( !lang.isEmpty() )
|
||||
{
|
||||
const auto langParts = lang.split( '_', QString::SkipEmptyParts );
|
||||
|
||||
QString country = QLocale::countryToString( QLocale( lang ).country() );
|
||||
|
@ -142,9 +142,7 @@ KeyboardViewStep::setConfigurationMap( const QVariantMap& configurationMap )
|
||||
.toString();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_xOrgConfFileName = "00-keyboard.conf";
|
||||
}
|
||||
|
||||
if ( configurationMap.contains( "convertedKeymapPath" ) &&
|
||||
configurationMap.value( "convertedKeymapPath" ).type() == QVariant::String &&
|
||||
@ -154,17 +152,11 @@ KeyboardViewStep::setConfigurationMap( const QVariantMap& configurationMap )
|
||||
.toString();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_convertedKeymapPath = QString();
|
||||
}
|
||||
|
||||
if ( configurationMap.contains( "writeEtcDefaultKeyboard" ) &&
|
||||
configurationMap.value( "writeEtcDefaultKeyboard" ).type() == QVariant::Bool )
|
||||
{
|
||||
m_writeEtcDefaultKeyboard = configurationMap.value( "writeEtcDefaultKeyboard" ).toBool();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_writeEtcDefaultKeyboard = true;
|
||||
}
|
||||
}
|
||||
|
@ -303,9 +303,7 @@ SetKeyboardLayoutJob::exec()
|
||||
|
||||
QString defaultKeyboardPath;
|
||||
if ( QDir( destDir.absoluteFilePath( "etc/default" ) ).exists() )
|
||||
{
|
||||
defaultKeyboardPath = destDir.absoluteFilePath( "etc/default/keyboard" );
|
||||
}
|
||||
|
||||
// Get the path to the destination's path to the converted key mappings
|
||||
QString convertedKeymapPath = m_convertedKeymapPath;
|
||||
|
Loading…
Reference in New Issue
Block a user