From af3261b16f7a551d59b00036fef60a44e3a1b7c4 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 8 Sep 2020 17:04:36 +0200 Subject: [PATCH] [keyboard] Refactor findLegacyKeymap into something testable --- src/modules/keyboard/SetKeyboardLayoutJob.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/modules/keyboard/SetKeyboardLayoutJob.cpp b/src/modules/keyboard/SetKeyboardLayoutJob.cpp index d0ad8fcbf..a36604926 100644 --- a/src/modules/keyboard/SetKeyboardLayoutJob.cpp +++ b/src/modules/keyboard/SetKeyboardLayoutJob.cpp @@ -79,8 +79,8 @@ SetKeyboardLayoutJob::findConvertedKeymap( const QString& convertedKeymapPath ) } -QString -SetKeyboardLayoutJob::findLegacyKeymap() const +STATICTEST QString +findLegacyKeymap( const QString& layout, const QString& model, const QString& variant ) { cDebug() << "Looking for legacy keymap in QRC"; @@ -109,20 +109,20 @@ SetKeyboardLayoutJob::findLegacyKeymap() const // Determine how well matching this entry is // We assume here that we have one X11 layout. If the UI changes to // allow more than one layout, this should change too. - if ( m_layout == mapping[ 1 ] ) + if ( layout == mapping[ 1 ] ) // If we got an exact match, this is best { matching = 10; } // Look for an entry whose first layout matches ours - else if ( mapping[ 1 ].startsWith( m_layout + ',' ) ) + else if ( mapping[ 1 ].startsWith( layout + ',' ) ) { matching = 5; } if ( matching > 0 ) { - if ( m_model.isEmpty() || m_model == mapping[ 2 ] ) + if ( model.isEmpty() || model == mapping[ 2 ] ) { matching++; } @@ -137,7 +137,7 @@ SetKeyboardLayoutJob::findLegacyKeymap() const mappingVariant.remove( 1, 0 ); } - if ( m_variant == mappingVariant ) + if ( variant == mappingVariant ) { matching++; } @@ -162,6 +162,12 @@ SetKeyboardLayoutJob::findLegacyKeymap() const return name; } +QString +SetKeyboardLayoutJob::findLegacyKeymap() const +{ + return ::findLegacyKeymap( m_layout, m_model, m_variant ); +} + bool SetKeyboardLayoutJob::writeVConsoleData( const QString& vconsoleConfPath, const QString& convertedKeymapPath ) const