src/hbcore/inputfw/hbinputmodecache.cpp
changeset 5 627c4a0fd0e7
parent 3 11d3954df52a
child 6 c3690ec91ef8
--- a/src/hbcore/inputfw/hbinputmodecache.cpp	Thu May 27 13:10:59 2010 +0300
+++ b/src/hbcore/inputfw/hbinputmodecache.cpp	Fri Jun 11 13:58:22 2010 +0300
@@ -75,6 +75,7 @@
     HbInputModeProperties propertiesFromState(const HbInputState &state) const;
     HbInputMethod *cachedMethod(HbInputMethodListItem &item);
     void updateMonitoredPaths();
+    bool isMappedLanguage(const HbInputLanguage &language) const;
 
 public:
     QFileSystemWatcher *mWatcher;
@@ -171,17 +172,21 @@
                 // If the item to be removed happens to be the active one,
                 // try to deal with the situation.
                 mMethods[i].cached->forceUnfocus();
-                if (mMethods[i].descriptor.pluginNameAndPath() == HbInputSettingProxy::instance()->activeCustomInputMethod().pluginNameAndPath()) {
-                    // The active custom method is being removed.
-                    // Clear out related setting proxy values.
-                    HbInputSettingProxy::instance()->setActiveCustomInputMethod(HbInputMethodDescriptor());
+                // The active custom method is being removed.
+                // Clear out related setting proxy values.
+                if (mMethods[i].descriptor.pluginNameAndPath() == HbInputSettingProxy::instance()->preferredInputMethod(Qt::Horizontal).pluginNameAndPath()) {
+                    HbInputSettingProxy::instance()->setPreferredInputMethod(Qt::Horizontal, HbInputMethodDescriptor());
+                }
+                if (mMethods[i].descriptor.pluginNameAndPath() == HbInputSettingProxy::instance()->preferredInputMethod(Qt::Vertical).pluginNameAndPath()) {
+                    HbInputSettingProxy::instance()->setPreferredInputMethod(Qt::Vertical, HbInputMethodDescriptor());
                 }
 
                 // Replace it with null input context.
                 HbInputMethod *master = HbInputMethodNull::Instance();
                 master->d_ptr->mIsActive = true;
-                QInputContext* proxy = master->d_ptr->newProxy();
-                qApp->setInputContext(proxy);
+                QInputContext* proxy = master->d_ptr->proxy();
+                if (proxy != qApp->inputContext())
+                    qApp->setInputContext(proxy);
             }
             delete mMethods[i].cached;
             mMethods.removeAt(i);
@@ -245,6 +250,21 @@
         }
     }
 }
+
+bool HbInputModeCachePrivate::isMappedLanguage(const HbInputLanguage &language) const
+{
+    if (language.defined()) {
+        QList<HbInputLanguage> languages = HbKeymapFactory::instance()->availableLanguages();
+        foreach (const HbInputLanguage mappedLanguage, languages) {
+            if (mappedLanguage == language) {
+                return true;
+            }
+        }
+    }
+
+    return false;
+}
+
 /// @endcond
 
 /*!
@@ -470,4 +490,58 @@
     return result;
 }
 
+/*!
+\internal
+Returns true if given input method is able to handle given input state.
+*/
+bool HbInputModeCache::acceptsState(const HbInputMethod *inputMethod, const HbInputState &state) const
+{
+    Q_D(const HbInputModeCache);
+
+    foreach (const HbInputMethodListItem item, d->mMethods) {
+        if (item.cached == inputMethod) {           
+            foreach (const QString language, item.languages) {
+                HbInputModeProperties mode = d->propertiesFromString(language);
+                // Check if keyboard type matches.
+                if (mode.keyboard() == state.keyboard()) {
+                    // Check if input mode matches or it is a custom input method but
+                    // state's mode is not numeric.
+                    if (mode.inputMode() == state.inputMode() ||
+                        ((mode.inputMode() == HbInputModeCustom) &&
+                         (state.inputMode() != HbInputModeNumeric))) {
+                        // Check if language matches or input method supports
+                        // all mapped languages and state's language is among them.
+                        if (mode.language() == state.language() ||
+                            (mode.language().undefined() && d->isMappedLanguage(state.language()))) {
+                            return true;
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    return false;
+}
+
+/*!
+\internal
+Returns input method descriptor for given input method. Returns empty descriptor if the framework
+doesn't recognize given input method.
+*/
+HbInputMethodDescriptor HbInputModeCache::descriptor(const HbInputMethod *inputMethod) const
+{
+    Q_D(const HbInputModeCache);
+
+    foreach (HbInputMethodListItem item, d->mMethods) {
+        if (item.cached == inputMethod) {
+            return item.descriptor;
+        }
+    }
+
+    return HbInputMethodDescriptor();
+}
+
+
 // End of file
+