Code-style: format the keyboard module

This commit is contained in:
Adriaan de Groot 2017-09-26 11:22:51 +02:00
parent ea07d9e1d8
commit 9b9801d48d
4 changed files with 63 additions and 75 deletions

View File

@ -61,15 +61,13 @@ void
KeyboardLayoutModel::init() KeyboardLayoutModel::init()
{ {
KeyboardGlobal::LayoutsMap layouts = KeyboardGlobal::LayoutsMap layouts =
KeyboardGlobal::getKeyboardLayouts(); KeyboardGlobal::getKeyboardLayouts();
for ( KeyboardGlobal::LayoutsMap::const_iterator it = layouts.constBegin(); for ( KeyboardGlobal::LayoutsMap::const_iterator it = layouts.constBegin();
it != layouts.constEnd(); ++it ) it != layouts.constEnd(); ++it )
{
m_layouts.append( qMakePair( it.key(), it.value() ) ); m_layouts.append( qMakePair( it.key(), it.value() ) );
}
std::stable_sort( m_layouts.begin(), m_layouts.end(), []( const QPair< QString, KeyboardGlobal::KeyboardInfo >& a, 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; return a.second.description < b.second.description;
} ); } );

View File

@ -58,7 +58,7 @@ findLayout( const KeyboardLayoutModel* klm, const QString& currentLayout )
{ {
QModelIndex idx = klm->index( i ); QModelIndex idx = klm->index( i );
if ( idx.isValid() && if ( idx.isValid() &&
idx.data( KeyboardLayoutModel::KeyboardLayoutKeyRole ).toString() == currentLayout ) idx.data( KeyboardLayoutModel::KeyboardLayoutKeyRole ).toString() == currentLayout )
currentLayoutItem = idx; currentLayoutItem = idx;
} }
@ -86,7 +86,7 @@ KeyboardPage::KeyboardPage( QWidget* parent )
[this] [this]
{ {
ui->comboBoxModel->setCurrentIndex( m_defaultIndex ); ui->comboBoxModel->setCurrentIndex( m_defaultIndex );
}); } );
connect( ui->comboBoxModel, connect( ui->comboBoxModel,
static_cast< void ( QComboBox::* )( const QString& ) >( &QComboBox::currentIndexChanged ), static_cast< void ( QComboBox::* )( const QString& ) >( &QComboBox::currentIndexChanged ),
@ -97,7 +97,7 @@ KeyboardPage::KeyboardPage( QWidget* parent )
// Set Xorg keyboard model // Set Xorg keyboard model
QProcess::execute( QLatin1Literal( "setxkbmap" ), QProcess::execute( QLatin1Literal( "setxkbmap" ),
QStringList() << "-model" << model ); QStringList() << "-model" << model );
}); } );
CALAMARES_RETRANSLATE( ui->retranslateUi( this ); ) CALAMARES_RETRANSLATE( ui->retranslateUi( this ); )
} }
@ -121,7 +121,7 @@ KeyboardPage::init()
if ( process.waitForFinished() ) if ( process.waitForFinished() )
{ {
const QStringList list = QString( process.readAll() ) const QStringList list = QString( process.readAll() )
.split( "\n", QString::SkipEmptyParts ); .split( "\n", QString::SkipEmptyParts );
for ( QString line : list ) for ( QString line : list )
{ {
@ -130,8 +130,8 @@ KeyboardPage::init()
continue; continue;
line = line.remove( "}" ) line = line.remove( "}" )
.remove( "{" ) .remove( "{" )
.remove( ";" ); .remove( ";" );
line = line.mid( line.indexOf( "\"" ) + 1 ); line = line.mid( line.indexOf( "\"" ) + 1 );
QStringList split = line.split( "+", QString::SkipEmptyParts ); QStringList split = line.split( "+", QString::SkipEmptyParts );
@ -143,7 +143,7 @@ KeyboardPage::init()
{ {
int parenthesisIndex = currentLayout.indexOf( "(" ); int parenthesisIndex = currentLayout.indexOf( "(" );
currentVariant = currentLayout.mid( parenthesisIndex + 1 ) currentVariant = currentLayout.mid( parenthesisIndex + 1 )
.trimmed(); .trimmed();
currentVariant.chop( 1 ); currentVariant.chop( 1 );
currentLayout = currentLayout currentLayout = currentLayout
.mid( 0, parenthesisIndex ) .mid( 0, parenthesisIndex )
@ -189,8 +189,8 @@ KeyboardPage::init()
QPersistentModelIndex currentLayoutItem = findLayout( klm, currentLayout ); QPersistentModelIndex currentLayoutItem = findLayout( klm, currentLayout );
if ( !currentLayoutItem.isValid() && ( if ( !currentLayoutItem.isValid() && (
( currentLayout == "latin" ) ( currentLayout == "latin" )
|| ( currentLayout == "pc" ) ) ) || ( currentLayout == "pc" ) ) )
{ {
currentLayout = "us"; currentLayout = "us";
currentLayoutItem = findLayout( klm, currentLayout ); currentLayoutItem = findLayout( klm, currentLayout );
@ -237,11 +237,11 @@ KeyboardPage::createJobs( const QString& xOrgConfFileName,
"pc105" ); "pc105" );
Calamares::Job* j = new SetKeyboardLayoutJob( selectedModel, Calamares::Job* j = new SetKeyboardLayoutJob( selectedModel,
m_selectedLayout, m_selectedLayout,
m_selectedVariant, m_selectedVariant,
xOrgConfFileName, xOrgConfFileName,
convertedKeymapPath, convertedKeymapPath,
writeEtcDefaultKeyboard ); writeEtcDefaultKeyboard );
list.append( Calamares::job_ptr( j ) ); list.append( Calamares::job_ptr( j ) );
return list; return list;
@ -253,14 +253,14 @@ KeyboardPage::guessLayout( const QStringList& langParts )
{ {
const KeyboardLayoutModel* klm = dynamic_cast< KeyboardLayoutModel* >( ui->listLayout->model() ); const KeyboardLayoutModel* klm = dynamic_cast< KeyboardLayoutModel* >( ui->listLayout->model() );
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() << " .. looking for locale part" << *countryPart; cDebug() << " .. looking for locale part" << *countryPart;
for ( int i = 0; i < klm->rowCount(); ++i ) for ( int i = 0; i < klm->rowCount(); ++i )
{ {
QModelIndex idx = klm->index( i ); QModelIndex idx = klm->index( i );
if ( idx.isValid() && if ( idx.isValid() &&
( idx.data( KeyboardLayoutModel::KeyboardLayoutKeyRole ).toString().compare( *countryPart, Qt::CaseInsensitive ) == 0 ) ) ( idx.data( KeyboardLayoutModel::KeyboardLayoutKeyRole ).toString().compare( *countryPart, Qt::CaseInsensitive ) == 0 ) )
{ {
cDebug() << " .. matched" << idx.data( KeyboardLayoutModel::KeyboardLayoutKeyRole ).toString(); cDebug() << " .. matched" << idx.data( KeyboardLayoutModel::KeyboardLayoutKeyRole ).toString();
ui->listLayout->setCurrentIndex( idx ); ui->listLayout->setCurrentIndex( idx );
@ -285,15 +285,15 @@ KeyboardPage::onActivate()
if ( !lang.isEmpty() ) if ( !lang.isEmpty() )
{ {
// Chop off .codeset and @modifier // Chop off .codeset and @modifier
int index = lang.indexOf('.'); int index = lang.indexOf( '.' );
if ( index >= 0 ) if ( index >= 0 )
lang.truncate( index ); lang.truncate( index );
index = lang.indexOf('@'); index = lang.indexOf( '@' );
if ( index >= 0 ) if ( index >= 0 )
lang.truncate( index ); lang.truncate( index );
lang.replace( '-', '_' ); // Normalize separators lang.replace( '-', '_' ); // Normalize separators
const auto langParts = lang.split( '_' , QString::SkipEmptyParts ); const auto langParts = lang.split( '_', QString::SkipEmptyParts );
QString country = QLocale::countryToString( QLocale( lang ).country() ); QString country = QLocale::countryToString( QLocale( lang ).country() );
cDebug() << " .. extracted country" << country << "::" << langParts; cDebug() << " .. extracted country" << country << "::" << langParts;
@ -325,8 +325,8 @@ KeyboardPage::updateVariants( const QPersistentModelIndex& currentItem,
ui->listVariant->blockSignals( true ); ui->listVariant->blockSignals( true );
QMap< QString, QString > variants = QMap< QString, QString > variants =
currentItem.data( KeyboardLayoutModel::KeyboardVariantsRole ) currentItem.data( KeyboardLayoutModel::KeyboardVariantsRole )
.value< QMap< QString, QString > >(); .value< QMap< QString, QString > >();
QMapIterator< QString, QString > li( variants ); QMapIterator< QString, QString > li( variants );
LayoutItem* defaultItem = nullptr; LayoutItem* defaultItem = nullptr;
@ -334,17 +334,17 @@ KeyboardPage::updateVariants( const QPersistentModelIndex& currentItem,
while ( li.hasNext() ) while ( li.hasNext() )
{ {
li.next(); li.next();
LayoutItem* item = new LayoutItem(); LayoutItem* item = new LayoutItem();
item->setText( li.key() ); item->setText( li.key() );
item->data = li.value(); item->data = li.value();
ui->listVariant->addItem( item ); ui->listVariant->addItem( item );
// currentVariant defaults to QString(). It is only non-empty during the // currentVariant defaults to QString(). It is only non-empty during the
// initial setup. // initial setup.
if ( li.value() == currentVariant ) if ( li.value() == currentVariant )
defaultItem = item; defaultItem = item;
} }
// Unblock signals // Unblock signals
@ -352,13 +352,13 @@ KeyboardPage::updateVariants( const QPersistentModelIndex& currentItem,
// Set to default value // Set to default value
if ( defaultItem ) if ( defaultItem )
ui->listVariant->setCurrentItem( defaultItem ); ui->listVariant->setCurrentItem( defaultItem );
} }
void void
KeyboardPage::onListLayoutCurrentItemChanged( const QModelIndex& current, KeyboardPage::onListLayoutCurrentItemChanged( const QModelIndex& current,
const QModelIndex& previous ) const QModelIndex& previous )
{ {
Q_UNUSED( previous ); Q_UNUSED( previous );
if ( !current.isValid() ) if ( !current.isValid() )
@ -370,7 +370,7 @@ KeyboardPage::onListLayoutCurrentItemChanged( const QModelIndex& current,
/* Returns stringlist with suitable setxkbmap command-line arguments /* Returns stringlist with suitable setxkbmap command-line arguments
* to set the given @p layout and @p variant. * 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; r << "-layout" << layout;
if ( !variant.isEmpty() ) if ( !variant.isEmpty() )

View File

@ -135,36 +135,28 @@ void
KeyboardViewStep::setConfigurationMap( const QVariantMap& configurationMap ) KeyboardViewStep::setConfigurationMap( const QVariantMap& configurationMap )
{ {
if ( configurationMap.contains( "xOrgConfFileName" ) && if ( configurationMap.contains( "xOrgConfFileName" ) &&
configurationMap.value( "xOrgConfFileName" ).type() == QVariant::String && configurationMap.value( "xOrgConfFileName" ).type() == QVariant::String &&
!configurationMap.value( "xOrgConfFileName" ).toString().isEmpty() ) !configurationMap.value( "xOrgConfFileName" ).toString().isEmpty() )
{ {
m_xOrgConfFileName = configurationMap.value( "xOrgConfFileName" ) m_xOrgConfFileName = configurationMap.value( "xOrgConfFileName" )
.toString(); .toString();
} }
else else
{
m_xOrgConfFileName = "00-keyboard.conf"; m_xOrgConfFileName = "00-keyboard.conf";
}
if ( configurationMap.contains( "convertedKeymapPath" ) && if ( configurationMap.contains( "convertedKeymapPath" ) &&
configurationMap.value( "convertedKeymapPath" ).type() == QVariant::String && configurationMap.value( "convertedKeymapPath" ).type() == QVariant::String &&
!configurationMap.value( "convertedKeymapPath" ).toString().isEmpty() ) !configurationMap.value( "convertedKeymapPath" ).toString().isEmpty() )
{ {
m_convertedKeymapPath = configurationMap.value( "convertedKeymapPath" ) m_convertedKeymapPath = configurationMap.value( "convertedKeymapPath" )
.toString(); .toString();
} }
else else
{
m_convertedKeymapPath = QString(); m_convertedKeymapPath = QString();
}
if ( configurationMap.contains( "writeEtcDefaultKeyboard" ) && if ( configurationMap.contains( "writeEtcDefaultKeyboard" ) &&
configurationMap.value( "writeEtcDefaultKeyboard" ).type() == QVariant::Bool ) configurationMap.value( "writeEtcDefaultKeyboard" ).type() == QVariant::Bool )
{
m_writeEtcDefaultKeyboard = configurationMap.value( "writeEtcDefaultKeyboard" ).toBool(); m_writeEtcDefaultKeyboard = configurationMap.value( "writeEtcDefaultKeyboard" ).toBool();
}
else else
{
m_writeEtcDefaultKeyboard = true; m_writeEtcDefaultKeyboard = true;
}
} }

View File

@ -37,11 +37,11 @@
SetKeyboardLayoutJob::SetKeyboardLayoutJob( const QString& model, SetKeyboardLayoutJob::SetKeyboardLayoutJob( const QString& model,
const QString& layout, const QString& layout,
const QString& variant, const QString& variant,
const QString& xOrgConfFileName, const QString& xOrgConfFileName,
const QString& convertedKeymapPath, const QString& convertedKeymapPath,
bool writeEtcDefaultKeyboard) bool writeEtcDefaultKeyboard )
: Calamares::Job() : Calamares::Job()
, m_model( model ) , m_model( model )
, m_layout( layout ) , m_layout( layout )
@ -57,8 +57,8 @@ QString
SetKeyboardLayoutJob::prettyName() const SetKeyboardLayoutJob::prettyName() const
{ {
return tr( "Set keyboard model to %1, layout to %2-%3" ).arg( m_model ) return tr( "Set keyboard model to %1, layout to %2-%3" ).arg( m_model )
.arg( m_layout ) .arg( m_layout )
.arg( m_variant ); .arg( m_variant );
} }
@ -74,7 +74,7 @@ SetKeyboardLayoutJob::findConvertedKeymap( const QString& convertedKeymapPath )
QString name = m_variant.isEmpty() ? m_layout : ( m_layout + '-' + m_variant ); QString name = m_variant.isEmpty() ? m_layout : ( m_layout + '-' + m_variant );
if ( convertedKeymapDir.exists( name + ".map" ) if ( convertedKeymapDir.exists( name + ".map" )
|| convertedKeymapDir.exists( name + ".map.gz" ) ) || convertedKeymapDir.exists( name + ".map.gz" ) )
{ {
cDebug() << "Found converted keymap" << name; cDebug() << "Found converted keymap" << name;
@ -154,7 +154,7 @@ SetKeyboardLayoutJob::findLegacyKeymap() const
bool bool
SetKeyboardLayoutJob::writeVConsoleData( const QString& vconsoleConfPath, SetKeyboardLayoutJob::writeVConsoleData( const QString& vconsoleConfPath,
const QString& convertedKeymapPath ) const const QString& convertedKeymapPath ) const
{ {
QString keymap = findConvertedKeymap( convertedKeymapPath ); QString keymap = findConvertedKeymap( convertedKeymapPath );
if ( keymap.isEmpty() ) if ( keymap.isEmpty() )
@ -215,10 +215,10 @@ SetKeyboardLayoutJob::writeX11Data( const QString& keyboardConfPath ) const
QTextStream stream( &file ); QTextStream stream( &file );
stream << "# Read and parsed by systemd-localed. It's probably wise not to edit this file\n" stream << "# Read and parsed by systemd-localed. It's probably wise not to edit this file\n"
"# manually too freely.\n" "# manually too freely.\n"
"Section \"InputClass\"\n" "Section \"InputClass\"\n"
" Identifier \"system-keyboard\"\n" " Identifier \"system-keyboard\"\n"
" MatchIsKeyboard \"on\"\n"; " MatchIsKeyboard \"on\"\n";
if ( !m_layout.isEmpty() ) if ( !m_layout.isEmpty() )
stream << " Option \"XkbLayout\" \"" << m_layout << "\"\n"; stream << " Option \"XkbLayout\" \"" << m_layout << "\"\n";
@ -235,8 +235,8 @@ SetKeyboardLayoutJob::writeX11Data( const QString& keyboardConfPath ) const
file.close(); file.close();
cDebug() << "Written XkbLayout" << m_layout << cDebug() << "Written XkbLayout" << m_layout <<
"; XkbModel" << m_model << "; XkbModel" << m_model <<
"; XkbVariant" << m_variant << "to X.org file" << keyboardConfPath; "; XkbVariant" << m_variant << "to X.org file" << keyboardConfPath;
return ( stream.status() == QTextStream::Ok ); return ( stream.status() == QTextStream::Ok );
} }
@ -250,7 +250,7 @@ SetKeyboardLayoutJob::writeDefaultKeyboardData( const QString& defaultKeyboardPa
QTextStream stream( &file ); QTextStream stream( &file );
stream << "# KEYBOARD CONFIGURATION FILE\n\n" 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 << "XKBMODEL=\"" << m_model << "\"\n";
stream << "XKBLAYOUT=\"" << m_layout << "\"\n"; stream << "XKBLAYOUT=\"" << m_layout << "\"\n";
@ -262,9 +262,9 @@ SetKeyboardLayoutJob::writeDefaultKeyboardData( const QString& defaultKeyboardPa
file.close(); file.close();
cDebug() << "Written XKBMODEL" << m_model << cDebug() << "Written XKBMODEL" << m_model <<
"; XKBLAYOUT" << m_layout << "; XKBLAYOUT" << m_layout <<
"; XKBVARIANT" << m_variant << "; XKBVARIANT" << m_variant <<
"to /etc/default/keyboard file" << defaultKeyboardPath; "to /etc/default/keyboard file" << defaultKeyboardPath;
return ( stream.status() == QTextStream::Ok ); return ( stream.status() == QTextStream::Ok );
} }
@ -297,15 +297,13 @@ SetKeyboardLayoutJob::exec()
{ {
xorgConfDPath = destDir.absoluteFilePath( "etc/X11/xorg.conf.d" ); xorgConfDPath = destDir.absoluteFilePath( "etc/X11/xorg.conf.d" );
keyboardConfPath = QDir( xorgConfDPath ) keyboardConfPath = QDir( xorgConfDPath )
.absoluteFilePath( m_xOrgConfFileName ); .absoluteFilePath( m_xOrgConfFileName );
} }
destDir.mkpath( xorgConfDPath ); destDir.mkpath( xorgConfDPath );
QString defaultKeyboardPath; QString defaultKeyboardPath;
if ( QDir( destDir.absoluteFilePath( "etc/default" ) ).exists() ) if ( QDir( destDir.absoluteFilePath( "etc/default" ) ).exists() )
{
defaultKeyboardPath = destDir.absoluteFilePath( "etc/default/keyboard" ); defaultKeyboardPath = destDir.absoluteFilePath( "etc/default/keyboard" );
}
// Get the path to the destination's path to the converted key mappings // Get the path to the destination's path to the converted key mappings
QString convertedKeymapPath = m_convertedKeymapPath; QString convertedKeymapPath = m_convertedKeymapPath;