refactor after review - use QStringList

This commit is contained in:
Ivan Borzenkov 2023-07-08 19:19:07 +03:00
parent 2d0940e555
commit 8ca841d08e
2 changed files with 22 additions and 56 deletions

View File

@ -175,6 +175,13 @@ SetKeyboardLayoutJob::findLegacyKeymap() const
return ::findLegacyKeymap( m_layout, m_model, m_variant );
}
QStringList
SetKeyboardLayoutJob::removeEmpty(QStringList& list) const
{
list.removeAll(QString());
return list;
}
bool
SetKeyboardLayoutJob::writeVConsoleData( const QString& vconsoleConfPath, const QString& convertedKeymapPath ) const
@ -266,32 +273,12 @@ SetKeyboardLayoutJob::writeX11Data( const QString& keyboardConfPath ) const
" MatchIsKeyboard \"on\"\n";
if ( m_additionalLayoutInfo.additionalLayout.isEmpty() )
QStringList layouts({m_additionalLayoutInfo.additionalLayout, m_layout});
QStringList variants({m_additionalLayoutInfo.additionalVariant, m_variant});
stream << " Option \"XkbLayout\" \"" << removeEmpty(layouts).join(",") << "\"\n";
stream << " Option \"XkbVariant\" \"" << removeEmpty(variants).join(",") << "\"\n";
if ( !m_additionalLayoutInfo.additionalLayout.isEmpty() )
{
if ( !m_layout.isEmpty() )
{
stream << " Option \"XkbLayout\" \"" << m_layout << "\"\n";
}
if ( !m_variant.isEmpty() )
{
stream << " Option \"XkbVariant\" \"" << m_variant << "\"\n";
}
}
else
{
if ( !m_layout.isEmpty() )
{
stream << " Option \"XkbLayout\" \"" << m_additionalLayoutInfo.additionalLayout << "," << m_layout
<< "\"\n";
}
if ( !m_variant.isEmpty() )
{
stream << " Option \"XkbVariant\" \"" << m_additionalLayoutInfo.additionalVariant << "," << m_variant
<< "\"\n";
}
stream << " Option \"XkbOptions\" \"" << m_additionalLayoutInfo.groupSwitcher << "\"\n";
}
@ -300,8 +287,8 @@ SetKeyboardLayoutJob::writeX11Data( const QString& keyboardConfPath ) const
file.close();
cDebug() << Logger::SubEntry << "Written XkbLayout" << m_layout << "; XkbModel" << m_model << "; XkbVariant"
<< m_variant << "to X.org file" << keyboardConfPath << stream.status();
cDebug() << Logger::SubEntry << "Written XkbLayout" << layouts.join(",") << "; XkbModel" << m_model << "; XkbVariant"
<< variants.join(",") << "to X.org file" << keyboardConfPath << stream.status();
return ( stream.status() == QTextStream::Ok );
}
@ -320,38 +307,16 @@ SetKeyboardLayoutJob::writeDefaultKeyboardData( const QString& defaultKeyboardPa
}
QTextStream stream( &file );
QStringList layouts({m_additionalLayoutInfo.additionalLayout, m_layout});
QStringList variants({m_additionalLayoutInfo.additionalVariant, m_variant});
stream << "# KEYBOARD CONFIGURATION FILE\n\n"
"# Consult the keyboard(5) manual page.\n\n";
stream << "XKBMODEL=\"" << m_model << "\"\n";
if ( m_additionalLayoutInfo.additionalLayout.isEmpty() )
stream << "XKBLAYOUT=\"" << removeEmpty(layouts).join(",") << "\"\n";
stream << "XKBVARIANT=\"" << removeEmpty(variants).join(",") << "\"\n";
if ( !m_additionalLayoutInfo.additionalLayout.isEmpty() )
{
if ( !m_layout.isEmpty() )
{
stream << "XKBLAYOUT=\"" << m_layout << "\"\n";
}
if ( !m_variant.isEmpty() )
{
stream << "XKBVARIANT=\"" << m_variant << "\"\n";
}
stream << "XKBOPTIONS=\"\"\n\n";
}
else
{
if ( !m_layout.isEmpty() )
{
stream << "XKBLAYOUT=\"" << m_additionalLayoutInfo.additionalLayout << "," << m_layout
<< "\"\n";
}
if ( !m_variant.isEmpty() )
{
stream << "XKBVARIANT=\"" << m_additionalLayoutInfo.additionalVariant << "," << m_variant
<< "\"\n";
}
stream << "XKBOPTIONS=\"" << m_additionalLayoutInfo.groupSwitcher << "\"\n";
}
stream << "BACKSPACE=\"guess\"\n";
@ -359,8 +324,8 @@ SetKeyboardLayoutJob::writeDefaultKeyboardData( const QString& defaultKeyboardPa
file.close();
cDebug() << Logger::SubEntry << "Written XKBMODEL" << m_model << "; XKBLAYOUT" << m_layout << "; XKBVARIANT"
<< m_variant << "to /etc/default/keyboard file" << defaultKeyboardPath << stream.status();
cDebug() << Logger::SubEntry << "Written XKBMODEL" << m_model << "; XKBLAYOUT" << layouts.join(",") << "; XKBVARIANT"
<< variants.join(",") << "to /etc/default/keyboard file" << defaultKeyboardPath << stream.status();
return ( stream.status() == QTextStream::Ok );
}

View File

@ -36,6 +36,7 @@ private:
bool writeVConsoleData( const QString& vconsoleConfPath, const QString& convertedKeymapPath ) const;
bool writeX11Data( const QString& keyboardConfPath ) const;
bool writeDefaultKeyboardData( const QString& defaultKeyboardPath ) const;
QStringList removeEmpty(QStringList& list) const;
QString m_model;
QString m_layout;