From a95702d49791522eb5e9d590ee42901f91cf3ebc Mon Sep 17 00:00:00 2001 From: Rodney Dawes Date: Thu, 3 Feb 2022 16:33:41 -0500 Subject: [PATCH 1/4] Cycle through enabled languages, rather than swapping between last two Fixes #47 --- qml/keys/LanguageKey.qml | 4 ++-- src/plugin/inputmethod.cpp | 12 ++++++++++++ src/plugin/inputmethod.h | 1 + 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/qml/keys/LanguageKey.qml b/qml/keys/LanguageKey.qml index 50b06710..02930c8d 100644 --- a/qml/keys/LanguageKey.qml +++ b/qml/keys/LanguageKey.qml @@ -52,8 +52,8 @@ ActionKey { return; } - if (maliit_input_method.previousLanguage && maliit_input_method.previousLanguage != maliit_input_method.activeLanguage) { - maliit_input_method.activeLanguage = maliit_input_method.previousLanguage + if (altLangs) { + Keyboard.selectNextLanguage(); } else { keypad.state = "EMOJI" } diff --git a/src/plugin/inputmethod.cpp b/src/plugin/inputmethod.cpp index 27011a97..54170e0c 100644 --- a/src/plugin/inputmethod.cpp +++ b/src/plugin/inputmethod.cpp @@ -596,6 +596,18 @@ const QString InputMethod::audioFeedbackSound() const return d->m_settings.keyPressAudioFeedbackSound(); } +//! \brief InputMethod::selectNextLanguage +//! Sets the active language to the next language in the enaabled languages list +void InputMethod::selectNextLanguage() +{ + auto const& langs = enabledLanguages(); + if (activeLanguage() == langs.back()) { + setActiveLanguage(langs.front()); + } else { + setActiveLanguage(langs[langs.indexOf(activeLanguage()) + 1]); + } +} + //! \brief InputMethod::setActiveLanguage //! Sets the currently active/used language //! \param newLanguage id of the new language. For example "en" or "es" diff --git a/src/plugin/inputmethod.h b/src/plugin/inputmethod.h index f9b49a76..e279b4e5 100644 --- a/src/plugin/inputmethod.h +++ b/src/plugin/inputmethod.h @@ -114,6 +114,7 @@ class InputMethod const QStringList &enabledLanguages() const; const QString &activeLanguage() const; + Q_INVOKABLE void selectNextLanguage(); Q_SLOT void setActiveLanguage(const QString& newLanguage); const QString &previousLanguage() const; From 7e872054bbb109059461da11ae9f28191c6793cc Mon Sep 17 00:00:00 2001 From: Rodney Dawes Date: Thu, 3 Feb 2022 16:47:59 -0500 Subject: [PATCH 2/4] Remove the previous-language setting and all references thereto As we cycle through all enabled languages now, the previos language setting is no longer useful,so remove it. This also nullifies the switchBack property of the Keyboard component, so remove that and its references as well. --- .../org.maliit.keyboard.maliit.gschema.xml | 5 ---- qml/Keyboard.qml | 6 ---- qml/KeyboardContainer.qml | 1 - qml/keys/LanguageKey.qml | 1 - src/plugin/inputmethod.cpp | 30 ------------------- src/plugin/inputmethod.h | 5 ---- src/plugin/inputmethod_p.h | 11 ------- src/plugin/keyboardsettings.cpp | 27 ----------------- src/plugin/keyboardsettings.h | 3 -- 9 files changed, 89 deletions(-) diff --git a/data/schemas/org.maliit.keyboard.maliit.gschema.xml b/data/schemas/org.maliit.keyboard.maliit.gschema.xml index 4f3990c0..f999b362 100644 --- a/data/schemas/org.maliit.keyboard.maliit.gschema.xml +++ b/data/schemas/org.maliit.keyboard.maliit.gschema.xml @@ -6,11 +6,6 @@ Currently active language, selected by user in the keyboard language menu 'en' - - Previous language - Language which was in use immediately prior to the current active language - '' - Enabled languages User-defined list of activatable languages. diff --git a/qml/Keyboard.qml b/qml/Keyboard.qml index 3456767f..6bf96e4b 100644 --- a/qml/Keyboard.qml +++ b/qml/Keyboard.qml @@ -253,12 +253,6 @@ Item { maliit_input_method.close(); canvas.hidingComplete = true; reportKeyboardVisibleRect(); - // Switch back to the previous layout if we're in - // in a layout like emoji that requests switchBack - if (keypad.switchBack && maliit_input_method.previousLanguage) { - keypad.switchBack = false; - maliit_input_method.activeLanguage = maliit_input_method.previousLanguage; - } // Exit cursor swipe mode when the keyboard hides fullScreenItem.exitSwipeMode(); diff --git a/qml/KeyboardContainer.qml b/qml/KeyboardContainer.qml index 1e5a99de..78489ac4 100644 --- a/qml/KeyboardContainer.qml +++ b/qml/KeyboardContainer.qml @@ -31,7 +31,6 @@ Item { property string activeKeypadState: "NORMAL" property alias popoverEnabled: extendedKeysSelector.enabled - property bool switchBack: false // Switch back to the previous layout when changing fields property bool hideKeyLabels: false // Hide key labels when in cursor movement mode property Item lastKeyPressed // Used for determining double click validity in PressArea diff --git a/qml/keys/LanguageKey.qml b/qml/keys/LanguageKey.qml index 02930c8d..88fac78d 100644 --- a/qml/keys/LanguageKey.qml +++ b/qml/keys/LanguageKey.qml @@ -47,7 +47,6 @@ ActionKey { } onReleased: { - panel.switchBack = false; if (held) { return; } diff --git a/src/plugin/inputmethod.cpp b/src/plugin/inputmethod.cpp index 54170e0c..b80009b9 100644 --- a/src/plugin/inputmethod.cpp +++ b/src/plugin/inputmethod.cpp @@ -119,7 +119,6 @@ InputMethod::InputMethod(MAbstractInputMethodHost *host) d->registerAutoCapsSetting(); d->registerWordEngineSetting(); d->registerActiveLanguage(); - d->registerPreviousLanguage(); d->registerEnabledLanguages(); d->registerDoubleSpaceFullStop(); d->registerStayHidden(); @@ -341,9 +340,6 @@ void InputMethod::onEnabledLanguageSettingsChanged() { Q_D(InputMethod); d->enabledLanguages = d->m_settings.enabledLanguages(); - if (!d->enabledLanguages.contains(d->previousLanguage)) { - setPreviousLanguage(QString()); - } Q_EMIT enabledLanguagesChanged(d->enabledLanguages); } @@ -543,14 +539,6 @@ const QString &InputMethod::activeLanguage() const return d->activeLanguage; } -//! \brief InputMethod::previousLanguage returns the language that was used -//! immediately prior to the current activeLanguage -const QString &InputMethod::previousLanguage() const -{ - Q_D(const InputMethod); - return d->previousLanguage; -} - //! \brief InputMethod::useAudioFeedback is true, when keys should play a audio //! feedback when pressed //! \return @@ -631,7 +619,6 @@ void InputMethod::setActiveLanguage(const QString &newLanguage) d->editor.commitPreedit(); - setPreviousLanguage(d->activeLanguage); d->activeLanguage = newLanguage; d->host->setLanguage(newLanguage); d->m_settings.setActiveLanguage(newLanguage); @@ -640,23 +627,6 @@ void InputMethod::setActiveLanguage(const QString &newLanguage) Q_EMIT activeLanguageChanged(d->activeLanguage); } -//! \brief InputMethod::setPreviousLanguage -//! Set the language used immediately prior to the current active language. -//! \param prevLanguage id the previous language used. e.g. "en" or "emoji" -void InputMethod::setPreviousLanguage(const QString &prevLanguage) -{ - Q_D(InputMethod); - - if (d->previousLanguage == prevLanguage) - return; - - d->previousLanguage = prevLanguage; - d->m_settings.setPreviousLanguage(prevLanguage); - - Q_EMIT previousLanguageChanged(d->previousLanguage); -} - - void InputMethod::onWordEnginePluginChanged() { reset(); diff --git a/src/plugin/inputmethod.h b/src/plugin/inputmethod.h index e279b4e5..154d2aa5 100644 --- a/src/plugin/inputmethod.h +++ b/src/plugin/inputmethod.h @@ -51,7 +51,6 @@ class InputMethod Q_PROPERTY(TextContentType contentType READ contentType WRITE setContentType NOTIFY contentTypeChanged) Q_PROPERTY(QStringList enabledLanguages READ enabledLanguages NOTIFY enabledLanguagesChanged) Q_PROPERTY(QString activeLanguage READ activeLanguage WRITE setActiveLanguage NOTIFY activeLanguageChanged) - Q_PROPERTY(QString previousLanguage READ previousLanguage WRITE setPreviousLanguage NOTIFY previousLanguageChanged) Q_PROPERTY(QObject* actionKeyOverride READ actionKeyOverride NOTIFY actionKeyOverrideChanged) Q_PROPERTY(bool useHapticFeedback READ useHapticFeedback NOTIFY useHapticFeedbackChanged) Q_PROPERTY(bool enableMagnifier READ enableMagnifier NOTIFY enableMagnifierChanged) @@ -117,9 +116,6 @@ class InputMethod Q_INVOKABLE void selectNextLanguage(); Q_SLOT void setActiveLanguage(const QString& newLanguage); - const QString &previousLanguage() const; - Q_SLOT void setPreviousLanguage(const QString& prevLanguage); - Q_SLOT void onVisibleRectChanged(); bool useAudioFeedback() const; @@ -163,7 +159,6 @@ class InputMethod void deactivateAutocaps(); void enabledLanguagesChanged(QStringList languages); void activeLanguageChanged(QString language); - void previousLanguageChanged(QString language); void useAudioFeedbackChanged(); void audioFeedbackSoundChanged(QString sound); void useHapticFeedbackChanged(); diff --git a/src/plugin/inputmethod_p.h b/src/plugin/inputmethod_p.h index e47a1564..bee9e979 100644 --- a/src/plugin/inputmethod_p.h +++ b/src/plugin/inputmethod_p.h @@ -82,7 +82,6 @@ class InputMethodPrivate bool wordEngineEnabled; InputMethod::TextContentType contentType; QString activeLanguage; - QString previousLanguage; QStringList enabledLanguages; Qt::ScreenOrientation appsCurrentOrientation; QString keyboardState; @@ -120,7 +119,6 @@ class InputMethodPrivate , wordEngineEnabled(false) , contentType(InputMethod::FreeTextContentType) , activeLanguage(QStringLiteral("en")) - , previousLanguage() , enabledLanguages(activeLanguage) , appsCurrentOrientation(qGuiApp->primaryScreen()->orientation()) , keyboardState(QStringLiteral("CHARACTERS")) @@ -305,15 +303,6 @@ class InputMethodPrivate q->setActiveLanguage(activeLanguage); } - void registerPreviousLanguage() - { - QObject::connect(&m_settings, &MaliitKeyboard::KeyboardSettings::previousLanguageChanged, - q, &InputMethod::setPreviousLanguage); - - previousLanguage = m_settings.previousLanguage(); - q->setPreviousLanguage(previousLanguage); - } - void registerEnabledLanguages() { QObject::connect(&m_settings, &MaliitKeyboard::KeyboardSettings::enabledLanguagesChanged, diff --git a/src/plugin/keyboardsettings.cpp b/src/plugin/keyboardsettings.cpp index 940bfd12..879f82f5 100644 --- a/src/plugin/keyboardsettings.cpp +++ b/src/plugin/keyboardsettings.cpp @@ -35,7 +35,6 @@ using namespace MaliitKeyboard; const QLatin1String ACTIVE_LANGUAGE_KEY = QLatin1String("activeLanguage"); -const QLatin1String PREVIOUS_LANGUAGE_KEY = QLatin1String("previousLanguage"); const QLatin1String ENABLED_LANGUAGES_KEY = QLatin1String("enabledLanguages"); const QLatin1String AUTO_CAPITALIZATION_KEY = QLatin1String("autoCapitalization"); const QLatin1String AUTO_COMPLETION_KEY = QLatin1String("autoCompletion"); @@ -81,13 +80,6 @@ KeyboardSettings::KeyboardSettings(QObject *parent) : if (activeLanguage() == emoji) { setActiveLanguage(enabled[0]); } - if (previousLanguage() == emoji) { - if (enabled.length() > 1) { - setPreviousLanguage(enabled.back()); - } else { - setPreviousLanguage(QLatin1String("")); - } - } } /*! @@ -105,22 +97,6 @@ void KeyboardSettings::setActiveLanguage(const QString& id) m_settings->set(ACTIVE_LANGUAGE_KEY, QVariant(id)); } -/*! - * \brief KeyboardSettings::previousLanguage returns the language that was - * active immediately before the current one. - * \return previously language - */ - -QString KeyboardSettings::previousLanguage() const -{ - return m_settings->get(PREVIOUS_LANGUAGE_KEY).toString(); -} - -void KeyboardSettings::setPreviousLanguage(const QString& id) -{ - m_settings->set(PREVIOUS_LANGUAGE_KEY, QVariant(id)); -} - /*! * \brief KeyboardSettings::enabledLanguages returns a list of languages that are * active @@ -271,9 +247,6 @@ void KeyboardSettings::settingUpdated(const QString &key) if (key == ACTIVE_LANGUAGE_KEY) { Q_EMIT activeLanguageChanged(activeLanguage()); return; - } else if (key == PREVIOUS_LANGUAGE_KEY) { - Q_EMIT previousLanguageChanged(previousLanguage()); - return; } else if (key == ENABLED_LANGUAGES_KEY) { Q_EMIT enabledLanguagesChanged(enabledLanguages()); return; diff --git a/src/plugin/keyboardsettings.h b/src/plugin/keyboardsettings.h index 9f2dca7d..b5361fcf 100644 --- a/src/plugin/keyboardsettings.h +++ b/src/plugin/keyboardsettings.h @@ -45,8 +45,6 @@ class KeyboardSettings : public QObject QString activeLanguage() const; void setActiveLanguage(const QString& id); - QString previousLanguage() const; - void setPreviousLanguage(const QString& id); QStringList enabledLanguages() const; bool autoCapitalization() const; bool autoCompletion() const; @@ -66,7 +64,6 @@ class KeyboardSettings : public QObject Q_SIGNALS: void activeLanguageChanged(QString); - void previousLanguageChanged(QString); void enabledLanguagesChanged(QStringList); void autoCapitalizationChanged(bool); void autoCompletionChanged(bool); From bdcf4a5d92b4e38203e83b802cce80eeab95d714 Mon Sep 17 00:00:00 2001 From: Rodney Dawes Date: Thu, 3 Feb 2022 17:04:03 -0500 Subject: [PATCH 3/4] inputmethod: Switch active language to first in list if current was disabled When the currently active language is removed from the enabled languages list, switch to the first language in the enabled languages list. Fixes #90 --- src/plugin/inputmethod.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/plugin/inputmethod.cpp b/src/plugin/inputmethod.cpp index b80009b9..7ea89073 100644 --- a/src/plugin/inputmethod.cpp +++ b/src/plugin/inputmethod.cpp @@ -340,6 +340,11 @@ void InputMethod::onEnabledLanguageSettingsChanged() { Q_D(InputMethod); d->enabledLanguages = d->m_settings.enabledLanguages(); + // Switch to first language in enabled languages if the currently active + // language is no longer enabled + if (!d->enabledLanguages.contains(d->activeLanguage)) { + setActiveLanguage(d->enabledLanguages.front()); + } Q_EMIT enabledLanguagesChanged(d->enabledLanguages); } From ff81ea7449bc91e7e276bef10f3fe4ed3a7baac2 Mon Sep 17 00:00:00 2001 From: Rodney Dawes Date: Thu, 3 Feb 2022 17:48:47 -0500 Subject: [PATCH 4/4] plugin: Handle invalid values being set for active and enabled languages When a language is not found in the known paths, reset the value, and remove it if also set in enabled languages. --- src/plugin/inputmethod.cpp | 21 +++++++++++++++++++-- src/plugin/keyboardsettings.cpp | 24 ++++++++++++++++++++---- src/plugin/keyboardsettings.h | 3 +++ 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/plugin/inputmethod.cpp b/src/plugin/inputmethod.cpp index 7ea89073..02390d63 100644 --- a/src/plugin/inputmethod.cpp +++ b/src/plugin/inputmethod.cpp @@ -340,6 +340,10 @@ void InputMethod::onEnabledLanguageSettingsChanged() { Q_D(InputMethod); d->enabledLanguages = d->m_settings.enabledLanguages(); + // Reset the value if it gets unset + if (d->enabledLanguages.length() == 0) { + d->m_settings.resetEnabledLanguages(); + } // Switch to first language in enabled languages if the currently active // language is no longer enabled if (!d->enabledLanguages.contains(d->activeLanguage)) { @@ -604,20 +608,33 @@ void InputMethod::selectNextLanguage() //! \brief InputMethod::setActiveLanguage //! Sets the currently active/used language //! \param newLanguage id of the new language. For example "en" or "es" -//! FIXME check if the language is supported - if not use "en" as fallback void InputMethod::setActiveLanguage(const QString &newLanguage) { Q_D(InputMethod); qDebug() << "in inputMethod.cpp setActiveLanguage() activeLanguage is:" << newLanguage; + QString newPluginPath; foreach(QString pluginPath, d->languagesPaths) { QDir testDir(pluginPath + QDir::separator() + newLanguage); if (testDir.exists()) { - d->currentPluginPath = testDir.absolutePath(); + newPluginPath = testDir.absolutePath(); break; } } + // The language plpugin was not found, so reset the active language + if (newPluginPath.isEmpty()) { + d->m_settings.resetActiveLanguage(); + // If the plugin was not found, and was in enabledLanguages list, + // also remove it from there + auto enabled = enabledLanguages(); + if (enabled.contains(newLanguage)) { + enabled.removeAll(newLanguage); + d->m_settings.setEnabledLanguages(enabled); + } + return; + } + d->currentPluginPath = newPluginPath; if (d->activeLanguage == newLanguage) return; diff --git a/src/plugin/keyboardsettings.cpp b/src/plugin/keyboardsettings.cpp index 879f82f5..f64af95f 100644 --- a/src/plugin/keyboardsettings.cpp +++ b/src/plugin/keyboardsettings.cpp @@ -72,10 +72,7 @@ KeyboardSettings::KeyboardSettings(QObject *parent) : auto enabled = enabledLanguages(); if (enabled.contains(emoji)) { enabled.removeAll(emoji); - if (enabled.isEmpty()) { - enabled << QLatin1String("en"); - } - m_settings->set(ENABLED_LANGUAGES_KEY, enabled); + setEnabledLanguages(enabled); } if (activeLanguage() == emoji) { setActiveLanguage(enabled[0]); @@ -97,6 +94,11 @@ void KeyboardSettings::setActiveLanguage(const QString& id) m_settings->set(ACTIVE_LANGUAGE_KEY, QVariant(id)); } +void KeyboardSettings::resetActiveLanguage() +{ + m_settings->reset(ACTIVE_LANGUAGE_KEY); +} + /*! * \brief KeyboardSettings::enabledLanguages returns a list of languages that are * active @@ -107,6 +109,20 @@ QStringList KeyboardSettings::enabledLanguages() const return m_settings->get(ENABLED_LANGUAGES_KEY).toStringList(); } +void KeyboardSettings::setEnabledLanguages(const QStringList& ids) +{ + if (ids.isEmpty()) { + resetEnabledLanguages(); + return; + } + m_settings->set(ENABLED_LANGUAGES_KEY, ids); +} + +void KeyboardSettings::resetEnabledLanguages() +{ + m_settings->reset(ENABLED_LANGUAGES_KEY); +} + /*! * \brief KeyboardSettings::autoCapitalization returns true id the first letter * of each sentence should be capitalized diff --git a/src/plugin/keyboardsettings.h b/src/plugin/keyboardsettings.h index b5361fcf..7e285134 100644 --- a/src/plugin/keyboardsettings.h +++ b/src/plugin/keyboardsettings.h @@ -45,7 +45,10 @@ class KeyboardSettings : public QObject QString activeLanguage() const; void setActiveLanguage(const QString& id); + void resetActiveLanguage(); QStringList enabledLanguages() const; + void setEnabledLanguages(const QStringList& ids); + void resetEnabledLanguages(); bool autoCapitalization() const; bool autoCompletion() const; bool predictiveText() const;