[keyboard] Only guess layouts until the user picks one
- when activating the page, the "guess" functions do their work and afterwards the config is left in a "guessable" state, but if the user makes a specific choice, then the config leaves the "guessable" state and the user's explicit choice is preserved. FIXES #1744
This commit is contained in:
parent
a65723d4da
commit
2b485a5e59
@ -16,6 +16,7 @@
|
|||||||
#include "GlobalStorage.h"
|
#include "GlobalStorage.h"
|
||||||
#include "JobQueue.h"
|
#include "JobQueue.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
#include "utils/RAII.h"
|
||||||
#include "utils/Retranslator.h"
|
#include "utils/Retranslator.h"
|
||||||
#include "utils/String.h"
|
#include "utils/String.h"
|
||||||
#include "utils/Variant.h"
|
#include "utils/Variant.h"
|
||||||
@ -170,6 +171,12 @@ Config::Config( QObject* parent )
|
|||||||
|
|
||||||
connect( m_keyboardVariantsModel, &KeyboardVariantsModel::currentIndexChanged, this, &Config::xkbChanged );
|
connect( m_keyboardVariantsModel, &KeyboardVariantsModel::currentIndexChanged, this, &Config::xkbChanged );
|
||||||
|
|
||||||
|
// If the user picks something explicitly -- not a consequence of
|
||||||
|
// a guess -- then move to UserSelected state and stay there.
|
||||||
|
connect( m_keyboardModelsModel, &KeyboardModelsModel::currentIndexChanged, this, &Config::selectionChange );
|
||||||
|
connect( m_keyboardLayoutsModel, &KeyboardLayoutModel::currentIndexChanged, this, &Config::selectionChange );
|
||||||
|
connect( m_keyboardVariantsModel, &KeyboardVariantsModel::currentIndexChanged, this, &Config::selectionChange );
|
||||||
|
|
||||||
m_selectedModel = m_keyboardModelsModel->key( m_keyboardModelsModel->currentIndex() );
|
m_selectedModel = m_keyboardModelsModel->key( m_keyboardModelsModel->currentIndex() );
|
||||||
m_selectedLayout = m_keyboardLayoutsModel->item( m_keyboardLayoutsModel->currentIndex() ).first;
|
m_selectedLayout = m_keyboardLayoutsModel->item( m_keyboardLayoutsModel->currentIndex() ).first;
|
||||||
m_selectedVariant = m_keyboardVariantsModel->key( m_keyboardVariantsModel->currentIndex() );
|
m_selectedVariant = m_keyboardVariantsModel->key( m_keyboardVariantsModel->currentIndex() );
|
||||||
@ -264,6 +271,13 @@ findLayout( const KeyboardLayoutModel* klm, const QString& currentLayout )
|
|||||||
void
|
void
|
||||||
Config::detectCurrentKeyboardLayout()
|
Config::detectCurrentKeyboardLayout()
|
||||||
{
|
{
|
||||||
|
if ( m_state != State::Initial )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
cPointerSetter returnToIntial( &m_state, State::Initial );
|
||||||
|
m_state = State::Guessing;
|
||||||
|
|
||||||
//### Detect current keyboard layout and variant
|
//### Detect current keyboard layout and variant
|
||||||
QString currentLayout;
|
QString currentLayout;
|
||||||
QString currentVariant;
|
QString currentVariant;
|
||||||
@ -409,6 +423,13 @@ guessLayout( const QStringList& langParts, KeyboardLayoutModel* layouts, Keyboar
|
|||||||
void
|
void
|
||||||
Config::guessLocaleKeyboardLayout()
|
Config::guessLocaleKeyboardLayout()
|
||||||
{
|
{
|
||||||
|
if ( m_state != State::Initial )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
cPointerSetter returnToIntial( &m_state, State::Initial );
|
||||||
|
m_state = State::Guessing;
|
||||||
|
|
||||||
/* Guessing a keyboard layout based on the locale means
|
/* Guessing a keyboard layout based on the locale means
|
||||||
* mapping between language identifiers in <lang>_<country>
|
* mapping between language identifiers in <lang>_<country>
|
||||||
* format to keyboard mappings, which are <country>_<layout>
|
* format to keyboard mappings, which are <country>_<layout>
|
||||||
@ -556,3 +577,12 @@ Config::retranslate()
|
|||||||
{
|
{
|
||||||
retranslateKeyboardModels();
|
retranslateKeyboardModels();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Config::selectionChange()
|
||||||
|
{
|
||||||
|
if ( m_state == State::Initial )
|
||||||
|
{
|
||||||
|
m_state = State::UserSelected;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -107,6 +107,24 @@ private:
|
|||||||
QString m_xOrgConfFileName;
|
QString m_xOrgConfFileName;
|
||||||
QString m_convertedKeymapPath;
|
QString m_convertedKeymapPath;
|
||||||
bool m_writeEtcDefaultKeyboard = true;
|
bool m_writeEtcDefaultKeyboard = true;
|
||||||
|
|
||||||
|
// The state determines whether we guess settings or preserve them:
|
||||||
|
// - Initial -> Guessing
|
||||||
|
// - Initial -> UserSelected
|
||||||
|
// - Guessing -> Initial
|
||||||
|
enum class State
|
||||||
|
{
|
||||||
|
Initial, // after configuration, nothing special going on
|
||||||
|
Guessing, // on activation
|
||||||
|
UserSelected // explicit choice is made, preserve that
|
||||||
|
};
|
||||||
|
State m_state = State::Initial;
|
||||||
|
|
||||||
|
/** @brief Handles state change when selections in model, variant, layout
|
||||||
|
*
|
||||||
|
* This handles the Initial -> UserSelected transition in particular.
|
||||||
|
*/
|
||||||
|
void selectionChange();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user