From 9b9801d48d838478c82acb59e807dd1b99ca2228 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 26 Sep 2017 11:22:51 +0200 Subject: [PATCH] Code-style: format the keyboard module --- src/modules/keyboard/KeyboardLayoutModel.cpp | 8 +-- src/modules/keyboard/KeyboardPage.cpp | 66 +++++++++---------- src/modules/keyboard/KeyboardViewStep.cpp | 22 ++----- src/modules/keyboard/SetKeyboardLayoutJob.cpp | 42 ++++++------ 4 files changed, 63 insertions(+), 75 deletions(-) diff --git a/src/modules/keyboard/KeyboardLayoutModel.cpp b/src/modules/keyboard/KeyboardLayoutModel.cpp index 63989819c..e03c2a36c 100644 --- a/src/modules/keyboard/KeyboardLayoutModel.cpp +++ b/src/modules/keyboard/KeyboardLayoutModel.cpp @@ -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; } ); diff --git a/src/modules/keyboard/KeyboardPage.cpp b/src/modules/keyboard/KeyboardPage.cpp index 3287dc711..d7b14b338 100644 --- a/src/modules/keyboard/KeyboardPage.cpp +++ b/src/modules/keyboard/KeyboardPage.cpp @@ -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,14 +253,14 @@ 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 ) ) + ( idx.data( KeyboardLayoutModel::KeyboardLayoutKeyRole ).toString().compare( *countryPart, Qt::CaseInsensitive ) == 0 ) ) { cDebug() << " .. matched" << idx.data( KeyboardLayoutModel::KeyboardLayoutKeyRole ).toString(); ui->listLayout->setCurrentIndex( idx ); @@ -285,15 +285,15 @@ 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 ); + const auto langParts = lang.split( '_', QString::SkipEmptyParts ); QString country = QLocale::countryToString( QLocale( lang ).country() ); cDebug() << " .. extracted country" << country << "::" << langParts; @@ -325,8 +325,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 +334,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 +352,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 +370,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() ) diff --git a/src/modules/keyboard/KeyboardViewStep.cpp b/src/modules/keyboard/KeyboardViewStep.cpp index 0dd326a8d..e04e94ce1 100644 --- a/src/modules/keyboard/KeyboardViewStep.cpp +++ b/src/modules/keyboard/KeyboardViewStep.cpp @@ -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; - } } diff --git a/src/modules/keyboard/SetKeyboardLayoutJob.cpp b/src/modules/keyboard/SetKeyboardLayoutJob.cpp index 430a227eb..1b94502ea 100644 --- a/src/modules/keyboard/SetKeyboardLayoutJob.cpp +++ b/src/modules/keyboard/SetKeyboardLayoutJob.cpp @@ -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;