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 50b06710..88fac78d 100644 --- a/qml/keys/LanguageKey.qml +++ b/qml/keys/LanguageKey.qml @@ -47,13 +47,12 @@ ActionKey { } onReleased: { - panel.switchBack = false; if (held) { 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..02390d63 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,8 +340,14 @@ void InputMethod::onEnabledLanguageSettingsChanged() { Q_D(InputMethod); d->enabledLanguages = d->m_settings.enabledLanguages(); - if (!d->enabledLanguages.contains(d->previousLanguage)) { - setPreviousLanguage(QString()); + // 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)) { + setActiveLanguage(d->enabledLanguages.front()); } Q_EMIT enabledLanguagesChanged(d->enabledLanguages); } @@ -543,14 +548,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 @@ -596,30 +593,54 @@ 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" -//! 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; d->editor.commitPreedit(); - setPreviousLanguage(d->activeLanguage); d->activeLanguage = newLanguage; d->host->setLanguage(newLanguage); d->m_settings.setActiveLanguage(newLanguage); @@ -628,23 +649,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 f9b49a76..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) @@ -114,11 +113,9 @@ 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; - Q_SLOT void setPreviousLanguage(const QString& prevLanguage); - Q_SLOT void onVisibleRectChanged(); bool useAudioFeedback() const; @@ -162,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..f64af95f 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"); @@ -73,21 +72,11 @@ 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]); } - if (previousLanguage() == emoji) { - if (enabled.length() > 1) { - setPreviousLanguage(enabled.back()); - } else { - setPreviousLanguage(QLatin1String("")); - } - } } /*! @@ -105,20 +94,9 @@ 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) +void KeyboardSettings::resetActiveLanguage() { - m_settings->set(PREVIOUS_LANGUAGE_KEY, QVariant(id)); + m_settings->reset(ACTIVE_LANGUAGE_KEY); } /*! @@ -131,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 @@ -271,9 +263,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..7e285134 100644 --- a/src/plugin/keyboardsettings.h +++ b/src/plugin/keyboardsettings.h @@ -45,9 +45,10 @@ class KeyboardSettings : public QObject QString activeLanguage() const; void setActiveLanguage(const QString& id); - QString previousLanguage() const; - void setPreviousLanguage(const QString& id); + void resetActiveLanguage(); QStringList enabledLanguages() const; + void setEnabledLanguages(const QStringList& ids); + void resetEnabledLanguages(); bool autoCapitalization() const; bool autoCompletion() const; bool predictiveText() const; @@ -66,7 +67,6 @@ class KeyboardSettings : public QObject Q_SIGNALS: void activeLanguageChanged(QString); - void previousLanguageChanged(QString); void enabledLanguagesChanged(QStringList); void autoCapitalizationChanged(bool); void autoCompletionChanged(bool);