keyboard: Coding style fixes.

main
Kevin Kofler 10 years ago
parent 4f9f7d7858
commit bfdcf0dbc0

@ -59,7 +59,8 @@ protected slots:
QListWidgetItem* previous ); QListWidgetItem* previous );
private: private:
class LayoutItem : public QListWidgetItem { class LayoutItem : public QListWidgetItem
{
public: public:
QString data; QString data;
KeyboardGlobal::KeyboardInfo info; KeyboardGlobal::KeyboardInfo info;

@ -56,17 +56,19 @@ SetKeyboardLayoutJob::prettyName() const
QString QString
SetKeyboardLayoutJob::findConvertedKeymap( const QString& convertedKeymapPath ) const { SetKeyboardLayoutJob::findConvertedKeymap( const QString& convertedKeymapPath ) const
{
// No search path supplied, assume the distribution does not provide // No search path supplied, assume the distribution does not provide
// converted keymaps // converted keymaps
if ( convertedKeymapPath.isEmpty() ) if ( convertedKeymapPath.isEmpty() )
return QString(); return QString();
QDir convertedKeymapDir( convertedKeymapPath ); QDir convertedKeymapDir( 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;
return name; return name;
@ -77,14 +79,16 @@ SetKeyboardLayoutJob::findConvertedKeymap( const QString& convertedKeymapPath )
QString QString
SetKeyboardLayoutJob::findLegacyKeymap() const { SetKeyboardLayoutJob::findLegacyKeymap() const
{
int bestMatching = 0; int bestMatching = 0;
QString name; QString name;
QFile file( ":/kbd-model-map" ); QFile file( ":/kbd-model-map" );
file.open( QIODevice::ReadOnly | QIODevice::Text ); file.open( QIODevice::ReadOnly | QIODevice::Text );
QTextStream stream( &file ); QTextStream stream( &file );
while ( !stream.atEnd() ) { while ( !stream.atEnd() )
{
QString line = stream.readLine().trimmed(); QString line = stream.readLine().trimmed();
if ( line.isEmpty() || line.startsWith( '#' ) ) if ( line.isEmpty() || line.startsWith( '#' ) )
continue; continue;
@ -105,7 +109,8 @@ SetKeyboardLayoutJob::findLegacyKeymap() const {
else if ( mapping[1].startsWith( m_layout + ',' ) ) else if ( mapping[1].startsWith( m_layout + ',' ) )
matching = 5; matching = 5;
if (matching > 0) { if ( matching > 0 )
{
if ( m_model.isEmpty() || m_model == mapping[2] ) if ( m_model.isEmpty() || m_model == mapping[2] )
matching++; matching++;
@ -123,11 +128,13 @@ SetKeyboardLayoutJob::findLegacyKeymap() const {
} }
// The best matching entry so far, then let's save that // The best matching entry so far, then let's save that
if ( matching >= qMax( bestMatching, 1 ) ) { if ( matching >= qMax( bestMatching, 1 ) )
{
cDebug() << "Found legacy keymap" << mapping[0] cDebug() << "Found legacy keymap" << mapping[0]
<< "with score" << matching; << "with score" << matching;
if ( matching > bestMatching ) { if ( matching > bestMatching )
{
bestMatching = matching; bestMatching = matching;
name = mapping[0]; name = mapping[0];
} }
@ -140,11 +147,13 @@ 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() )
keymap = findLegacyKeymap(); keymap = findLegacyKeymap();
if ( keymap.isEmpty() ) { if ( keymap.isEmpty() )
{
cDebug() << "Trying to use X11 layout" << m_layout cDebug() << "Trying to use X11 layout" << m_layout
<< "as the virtual console layout"; << "as the virtual console layout";
keymap = m_layout; keymap = m_layout;
@ -154,7 +163,8 @@ SetKeyboardLayoutJob::writeVConsoleData( const QString& vconsoleConfPath,
// Read in the existing vconsole.conf, if it exists // Read in the existing vconsole.conf, if it exists
QFile file( vconsoleConfPath ); QFile file( vconsoleConfPath );
if ( file.exists() ) { if ( file.exists() )
{
file.open( QIODevice::ReadOnly | QIODevice::Text ); file.open( QIODevice::ReadOnly | QIODevice::Text );
QTextStream stream( &file ); QTextStream stream( &file );
while ( !stream.atEnd() ) while ( !stream.atEnd() )
@ -168,25 +178,29 @@ SetKeyboardLayoutJob::writeVConsoleData( const QString& vconsoleConfPath,
file.open( QIODevice::WriteOnly | QIODevice::Text ); file.open( QIODevice::WriteOnly | QIODevice::Text );
QTextStream stream( &file ); QTextStream stream( &file );
bool found = false; bool found = false;
foreach ( const QString& existingLine, existingLines ) { foreach ( const QString& existingLine, existingLines )
if ( existingLine.trimmed().startsWith( "KEYMAP=" ) ) { {
if ( existingLine.trimmed().startsWith( "KEYMAP=" ) )
{
stream << "KEYMAP=" << keymap << '\n'; stream << "KEYMAP=" << keymap << '\n';
found = true; found = true;
} else }
else
stream << existingLine << '\n'; stream << existingLine << '\n';
} }
// Add a KEYMAP= line if there wasn't any // Add a KEYMAP= line if there wasn't any
if (!found) if ( !found )
stream << "KEYMAP=" << keymap << '\n'; stream << "KEYMAP=" << keymap << '\n';
stream.flush(); stream.flush();
file.close(); file.close();
return (stream.status() == QTextStream::Ok); return ( stream.status() == QTextStream::Ok );
} }
bool bool
SetKeyboardLayoutJob::writeX11Data( const QString& keyboardConfPath ) const { SetKeyboardLayoutJob::writeX11Data( const QString& keyboardConfPath ) const
{
QFile file( keyboardConfPath ); QFile file( keyboardConfPath );
file.open( QIODevice::WriteOnly | QIODevice::Text ); file.open( QIODevice::WriteOnly | QIODevice::Text );
QTextStream stream( &file ); QTextStream stream( &file );
@ -211,7 +225,7 @@ SetKeyboardLayoutJob::writeX11Data( const QString& keyboardConfPath ) const {
file.close(); file.close();
return (stream.status() == QTextStream::Ok); return ( stream.status() == QTextStream::Ok );
} }
@ -237,7 +251,8 @@ SetKeyboardLayoutJob::exec()
QString convertedKeymapPath; QString convertedKeymapPath;
QString convertedKeymapPathSetting QString convertedKeymapPathSetting
= gs->value( "keyboardConvertedKeymapPath" ).toString(); = gs->value( "keyboardConvertedKeymapPath" ).toString();
if ( !convertedKeymapPathSetting.isEmpty() ) { if ( !convertedKeymapPathSetting.isEmpty() )
{
while ( convertedKeymapPathSetting.startsWith( '/' ) ) while ( convertedKeymapPathSetting.startsWith( '/' ) )
convertedKeymapPathSetting.remove( 0, 1 ); convertedKeymapPathSetting.remove( 0, 1 );
convertedKeymapPath = destDir.absoluteFilePath( convertedKeymapPathSetting ); convertedKeymapPath = destDir.absoluteFilePath( convertedKeymapPathSetting );

Loading…
Cancel
Save