[keyboard] match keyboard layouts with selected sys-lang
This commit is contained in:
parent
4b4bd83a39
commit
243d7c5e29
@ -61,15 +61,13 @@ void
|
||||
KeyboardLayoutModel::init()
|
||||
{
|
||||
KeyboardGlobal::LayoutsMap layouts =
|
||||
KeyboardGlobal::getKeyboardLayouts();
|
||||
KeyboardGlobal::getKeyboardLayouts();
|
||||
for ( KeyboardGlobal::LayoutsMap::const_iterator it = layouts.constBegin();
|
||||
it != layouts.constEnd(); ++it )
|
||||
{
|
||||
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 )
|
||||
const QPair< QString, KeyboardGlobal::KeyboardInfo >& b )
|
||||
{
|
||||
return a.second.description < b.second.description;
|
||||
} );
|
||||
|
@ -58,7 +58,7 @@ findLayout( const KeyboardLayoutModel* klm, const QString& currentLayout )
|
||||
{
|
||||
QModelIndex idx = klm->index( i );
|
||||
if ( idx.isValid() &&
|
||||
idx.data( KeyboardLayoutModel::KeyboardLayoutKeyRole ).toString() == currentLayout )
|
||||
idx.data( KeyboardLayoutModel::KeyboardLayoutKeyRole ).toString() == currentLayout )
|
||||
currentLayoutItem = idx;
|
||||
}
|
||||
|
||||
@ -86,7 +86,7 @@ KeyboardPage::KeyboardPage( QWidget* parent )
|
||||
[this]
|
||||
{
|
||||
ui->comboBoxModel->setCurrentIndex( m_defaultIndex );
|
||||
});
|
||||
} );
|
||||
|
||||
connect( ui->comboBoxModel,
|
||||
static_cast< void ( QComboBox::* )( const QString& ) >( &QComboBox::currentIndexChanged ),
|
||||
@ -97,7 +97,7 @@ KeyboardPage::KeyboardPage( QWidget* parent )
|
||||
// Set Xorg keyboard model
|
||||
QProcess::execute( QLatin1Literal( "setxkbmap" ),
|
||||
QStringList() << "-model" << model );
|
||||
});
|
||||
} );
|
||||
|
||||
CALAMARES_RETRANSLATE( ui->retranslateUi( this ); )
|
||||
}
|
||||
@ -121,7 +121,7 @@ KeyboardPage::init()
|
||||
if ( process.waitForFinished() )
|
||||
{
|
||||
const QStringList list = QString( process.readAll() )
|
||||
.split( "\n", QString::SkipEmptyParts );
|
||||
.split( "\n", QString::SkipEmptyParts );
|
||||
|
||||
for ( QString line : list )
|
||||
{
|
||||
@ -130,8 +130,8 @@ KeyboardPage::init()
|
||||
continue;
|
||||
|
||||
line = line.remove( "}" )
|
||||
.remove( "{" )
|
||||
.remove( ";" );
|
||||
.remove( "{" )
|
||||
.remove( ";" );
|
||||
line = line.mid( line.indexOf( "\"" ) + 1 );
|
||||
|
||||
QStringList split = line.split( "+", QString::SkipEmptyParts );
|
||||
@ -143,7 +143,7 @@ KeyboardPage::init()
|
||||
{
|
||||
int parenthesisIndex = currentLayout.indexOf( "(" );
|
||||
currentVariant = currentLayout.mid( parenthesisIndex + 1 )
|
||||
.trimmed();
|
||||
.trimmed();
|
||||
currentVariant.chop( 1 );
|
||||
currentLayout = currentLayout
|
||||
.mid( 0, parenthesisIndex )
|
||||
@ -189,8 +189,8 @@ KeyboardPage::init()
|
||||
|
||||
QPersistentModelIndex currentLayoutItem = findLayout( klm, currentLayout );
|
||||
if ( !currentLayoutItem.isValid() && (
|
||||
( currentLayout == "latin" )
|
||||
|| ( currentLayout == "pc" ) ) )
|
||||
( currentLayout == "latin" )
|
||||
|| ( currentLayout == "pc" ) ) )
|
||||
{
|
||||
currentLayout = "us";
|
||||
currentLayoutItem = findLayout( klm, currentLayout );
|
||||
@ -237,11 +237,11 @@ KeyboardPage::createJobs( const QString& xOrgConfFileName,
|
||||
"pc105" );
|
||||
|
||||
Calamares::Job* j = new SetKeyboardLayoutJob( selectedModel,
|
||||
m_selectedLayout,
|
||||
m_selectedVariant,
|
||||
xOrgConfFileName,
|
||||
convertedKeymapPath,
|
||||
writeEtcDefaultKeyboard );
|
||||
m_selectedLayout,
|
||||
m_selectedVariant,
|
||||
xOrgConfFileName,
|
||||
convertedKeymapPath,
|
||||
writeEtcDefaultKeyboard );
|
||||
list.append( Calamares::job_ptr( j ) );
|
||||
|
||||
return list;
|
||||
@ -253,21 +253,38 @@ 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)
|
||||
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 ) )
|
||||
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
|
||||
@ -285,15 +308,24 @@ KeyboardPage::onActivate()
|
||||
if ( !lang.isEmpty() )
|
||||
{
|
||||
// Chop off .codeset and @modifier
|
||||
int index = lang.indexOf('.');
|
||||
int index = lang.indexOf( '.' );
|
||||
if ( index >= 0 )
|
||||
lang.truncate( index );
|
||||
index = lang.indexOf('@');
|
||||
index = lang.indexOf( '@' );
|
||||
if ( index >= 0 )
|
||||
lang.truncate( index );
|
||||
|
||||
lang.replace( '-', '_' ); // Normalize separators
|
||||
const auto langParts = lang.split( '_' , QString::SkipEmptyParts );
|
||||
}
|
||||
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() );
|
||||
cDebug() << " .. extracted country" << country << "::" << langParts;
|
||||
@ -325,8 +357,8 @@ KeyboardPage::updateVariants( const QPersistentModelIndex& currentItem,
|
||||
ui->listVariant->blockSignals( true );
|
||||
|
||||
QMap< QString, QString > variants =
|
||||
currentItem.data( KeyboardLayoutModel::KeyboardVariantsRole )
|
||||
.value< QMap< QString, QString > >();
|
||||
currentItem.data( KeyboardLayoutModel::KeyboardVariantsRole )
|
||||
.value< QMap< QString, QString > >();
|
||||
QMapIterator< QString, QString > li( variants );
|
||||
LayoutItem* defaultItem = nullptr;
|
||||
|
||||
@ -334,17 +366,17 @@ KeyboardPage::updateVariants( const QPersistentModelIndex& currentItem,
|
||||
|
||||
while ( li.hasNext() )
|
||||
{
|
||||
li.next();
|
||||
li.next();
|
||||
|
||||
LayoutItem* item = new LayoutItem();
|
||||
item->setText( li.key() );
|
||||
item->data = li.value();
|
||||
ui->listVariant->addItem( item );
|
||||
LayoutItem* item = new LayoutItem();
|
||||
item->setText( li.key() );
|
||||
item->data = li.value();
|
||||
ui->listVariant->addItem( item );
|
||||
|
||||
// currentVariant defaults to QString(). It is only non-empty during the
|
||||
// initial setup.
|
||||
if ( li.value() == currentVariant )
|
||||
defaultItem = item;
|
||||
// currentVariant defaults to QString(). It is only non-empty during the
|
||||
// initial setup.
|
||||
if ( li.value() == currentVariant )
|
||||
defaultItem = item;
|
||||
}
|
||||
|
||||
// Unblock signals
|
||||
@ -352,13 +384,13 @@ KeyboardPage::updateVariants( const QPersistentModelIndex& currentItem,
|
||||
|
||||
// Set to default value
|
||||
if ( defaultItem )
|
||||
ui->listVariant->setCurrentItem( defaultItem );
|
||||
ui->listVariant->setCurrentItem( defaultItem );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
KeyboardPage::onListLayoutCurrentItemChanged( const QModelIndex& current,
|
||||
const QModelIndex& previous )
|
||||
const QModelIndex& previous )
|
||||
{
|
||||
Q_UNUSED( previous );
|
||||
if ( !current.isValid() )
|
||||
@ -370,7 +402,7 @@ KeyboardPage::onListLayoutCurrentItemChanged( const QModelIndex& current,
|
||||
/* Returns stringlist with suitable setxkbmap command-line arguments
|
||||
* to set the given @p layout and @p variant.
|
||||
*/
|
||||
static inline QStringList xkbmap_args( QStringList&& r, const QString& layout, const QString& variant)
|
||||
static inline QStringList xkbmap_args( QStringList&& r, const QString& layout, const QString& variant )
|
||||
{
|
||||
r << "-layout" << layout;
|
||||
if ( !variant.isEmpty() )
|
||||
|
@ -135,36 +135,28 @@ void
|
||||
KeyboardViewStep::setConfigurationMap( const QVariantMap& configurationMap )
|
||||
{
|
||||
if ( configurationMap.contains( "xOrgConfFileName" ) &&
|
||||
configurationMap.value( "xOrgConfFileName" ).type() == QVariant::String &&
|
||||
!configurationMap.value( "xOrgConfFileName" ).toString().isEmpty() )
|
||||
configurationMap.value( "xOrgConfFileName" ).type() == QVariant::String &&
|
||||
!configurationMap.value( "xOrgConfFileName" ).toString().isEmpty() )
|
||||
{
|
||||
m_xOrgConfFileName = configurationMap.value( "xOrgConfFileName" )
|
||||
.toString();
|
||||
.toString();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_xOrgConfFileName = "00-keyboard.conf";
|
||||
}
|
||||
|
||||
if ( configurationMap.contains( "convertedKeymapPath" ) &&
|
||||
configurationMap.value( "convertedKeymapPath" ).type() == QVariant::String &&
|
||||
!configurationMap.value( "convertedKeymapPath" ).toString().isEmpty() )
|
||||
configurationMap.value( "convertedKeymapPath" ).type() == QVariant::String &&
|
||||
!configurationMap.value( "convertedKeymapPath" ).toString().isEmpty() )
|
||||
{
|
||||
m_convertedKeymapPath = configurationMap.value( "convertedKeymapPath" )
|
||||
.toString();
|
||||
.toString();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_convertedKeymapPath = QString();
|
||||
}
|
||||
|
||||
if ( configurationMap.contains( "writeEtcDefaultKeyboard" ) &&
|
||||
configurationMap.value( "writeEtcDefaultKeyboard" ).type() == QVariant::Bool )
|
||||
{
|
||||
configurationMap.value( "writeEtcDefaultKeyboard" ).type() == QVariant::Bool )
|
||||
m_writeEtcDefaultKeyboard = configurationMap.value( "writeEtcDefaultKeyboard" ).toBool();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_writeEtcDefaultKeyboard = true;
|
||||
}
|
||||
}
|
||||
|
@ -37,11 +37,11 @@
|
||||
|
||||
|
||||
SetKeyboardLayoutJob::SetKeyboardLayoutJob( const QString& model,
|
||||
const QString& layout,
|
||||
const QString& variant,
|
||||
const QString& xOrgConfFileName,
|
||||
const QString& convertedKeymapPath,
|
||||
bool writeEtcDefaultKeyboard)
|
||||
const QString& layout,
|
||||
const QString& variant,
|
||||
const QString& xOrgConfFileName,
|
||||
const QString& convertedKeymapPath,
|
||||
bool writeEtcDefaultKeyboard )
|
||||
: Calamares::Job()
|
||||
, m_model( model )
|
||||
, m_layout( layout )
|
||||
@ -57,8 +57,8 @@ QString
|
||||
SetKeyboardLayoutJob::prettyName() const
|
||||
{
|
||||
return tr( "Set keyboard model to %1, layout to %2-%3" ).arg( m_model )
|
||||
.arg( m_layout )
|
||||
.arg( m_variant );
|
||||
.arg( m_layout )
|
||||
.arg( m_variant );
|
||||
}
|
||||
|
||||
|
||||
@ -74,7 +74,7 @@ SetKeyboardLayoutJob::findConvertedKeymap( const QString& convertedKeymapPath )
|
||||
QString name = m_variant.isEmpty() ? m_layout : ( m_layout + '-' + m_variant );
|
||||
|
||||
if ( convertedKeymapDir.exists( name + ".map" )
|
||||
|| convertedKeymapDir.exists( name + ".map.gz" ) )
|
||||
|| convertedKeymapDir.exists( name + ".map.gz" ) )
|
||||
{
|
||||
cDebug() << "Found converted keymap" << name;
|
||||
|
||||
@ -154,7 +154,7 @@ SetKeyboardLayoutJob::findLegacyKeymap() const
|
||||
|
||||
bool
|
||||
SetKeyboardLayoutJob::writeVConsoleData( const QString& vconsoleConfPath,
|
||||
const QString& convertedKeymapPath ) const
|
||||
const QString& convertedKeymapPath ) const
|
||||
{
|
||||
QString keymap = findConvertedKeymap( convertedKeymapPath );
|
||||
if ( keymap.isEmpty() )
|
||||
@ -215,10 +215,10 @@ SetKeyboardLayoutJob::writeX11Data( const QString& keyboardConfPath ) const
|
||||
QTextStream stream( &file );
|
||||
|
||||
stream << "# Read and parsed by systemd-localed. It's probably wise not to edit this file\n"
|
||||
"# manually too freely.\n"
|
||||
"Section \"InputClass\"\n"
|
||||
" Identifier \"system-keyboard\"\n"
|
||||
" MatchIsKeyboard \"on\"\n";
|
||||
"# manually too freely.\n"
|
||||
"Section \"InputClass\"\n"
|
||||
" Identifier \"system-keyboard\"\n"
|
||||
" MatchIsKeyboard \"on\"\n";
|
||||
|
||||
if ( !m_layout.isEmpty() )
|
||||
stream << " Option \"XkbLayout\" \"" << m_layout << "\"\n";
|
||||
@ -235,8 +235,8 @@ SetKeyboardLayoutJob::writeX11Data( const QString& keyboardConfPath ) const
|
||||
file.close();
|
||||
|
||||
cDebug() << "Written XkbLayout" << m_layout <<
|
||||
"; XkbModel" << m_model <<
|
||||
"; XkbVariant" << m_variant << "to X.org file" << keyboardConfPath;
|
||||
"; XkbModel" << m_model <<
|
||||
"; XkbVariant" << m_variant << "to X.org file" << keyboardConfPath;
|
||||
|
||||
return ( stream.status() == QTextStream::Ok );
|
||||
}
|
||||
@ -250,7 +250,7 @@ SetKeyboardLayoutJob::writeDefaultKeyboardData( const QString& defaultKeyboardPa
|
||||
QTextStream stream( &file );
|
||||
|
||||
stream << "# KEYBOARD CONFIGURATION FILE\n\n"
|
||||
"# Consult the keyboard(5) manual page.\n\n";
|
||||
"# Consult the keyboard(5) manual page.\n\n";
|
||||
|
||||
stream << "XKBMODEL=\"" << m_model << "\"\n";
|
||||
stream << "XKBLAYOUT=\"" << m_layout << "\"\n";
|
||||
@ -262,9 +262,9 @@ SetKeyboardLayoutJob::writeDefaultKeyboardData( const QString& defaultKeyboardPa
|
||||
file.close();
|
||||
|
||||
cDebug() << "Written XKBMODEL" << m_model <<
|
||||
"; XKBLAYOUT" << m_layout <<
|
||||
"; XKBVARIANT" << m_variant <<
|
||||
"to /etc/default/keyboard file" << defaultKeyboardPath;
|
||||
"; XKBLAYOUT" << m_layout <<
|
||||
"; XKBVARIANT" << m_variant <<
|
||||
"to /etc/default/keyboard file" << defaultKeyboardPath;
|
||||
|
||||
return ( stream.status() == QTextStream::Ok );
|
||||
}
|
||||
@ -297,15 +297,13 @@ SetKeyboardLayoutJob::exec()
|
||||
{
|
||||
xorgConfDPath = destDir.absoluteFilePath( "etc/X11/xorg.conf.d" );
|
||||
keyboardConfPath = QDir( xorgConfDPath )
|
||||
.absoluteFilePath( m_xOrgConfFileName );
|
||||
.absoluteFilePath( m_xOrgConfFileName );
|
||||
}
|
||||
destDir.mkpath( xorgConfDPath );
|
||||
|
||||
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