src/hbcore/inputfw/hbinputmodecache.cpp
changeset 21 4633027730f5
parent 7 923ff622b8b9
child 23 e6ad4ef83b23
--- a/src/hbcore/inputfw/hbinputmodecache.cpp	Tue Jul 06 14:36:53 2010 +0300
+++ b/src/hbcore/inputfw/hbinputmodecache.cpp	Wed Aug 18 10:05:37 2010 +0300
@@ -58,13 +58,31 @@
                 descriptor.key() == item.descriptor.key());
     }
 
+    void setValues(QInputContextPlugin *plugin, const QString &key);
+
 public:
     HbInputMethodDescriptor descriptor;
     QStringList languages;
     HbInputMethod *cached;
     bool toBeRemoved;
+    HbInputLanguage cachedLanguage;
 };
 
+void HbInputMethodListItem::setValues(QInputContextPlugin *plugin, const QString &key)
+{
+    if (plugin) {
+        descriptor.setKey(key);
+        descriptor.setDisplayName(plugin->displayName(key));
+
+        HbInputContextPlugin *extension = qobject_cast<HbInputContextPlugin *>(plugin);
+        if (extension) {
+            descriptor.setDisplayNames(extension->displayNames(key));
+            descriptor.setIcon(extension->icon(key));
+            descriptor.setIcons(extension->icons(key));
+        }
+    }
+}
+
 class HbInputModeCachePrivate
 {
 public:
@@ -78,6 +96,7 @@
     HbInputMethod *cachedMethod(HbInputMethodListItem &item);
     void updateMonitoredPaths();
     bool isMappedLanguage(const HbInputLanguage &language) const;
+    void refreshIfNeeded(HbInputMethodListItem &item, const HbInputLanguage &language);
 
 public:
     QFileSystemWatcher *mWatcher;
@@ -130,6 +149,8 @@
         mMethods[k].toBeRemoved = true;
     }
 
+    HbInputLanguage activeLanguage = HbInputSettingProxy::instance()->globalInputLanguage();
+
     // Query plugin paths and scan the folders.
     QStringList folders = HbInputSettingProxy::instance()->inputMethodPluginPaths();
     foreach(const QString &folder, folders) {
@@ -149,15 +170,7 @@
                 // If not, then add one.
                 QStringList contextKeys = inputContextPlugin->keys();
                 foreach(const QString &key, contextKeys) {
-                    listItem.descriptor.setKey(key);
-                    listItem.descriptor.setDisplayName(inputContextPlugin->displayName(key));
-
-                    HbInputContextPlugin *extension = qobject_cast<HbInputContextPlugin *>(inputContextPlugin);
-                    if (extension) {
-                        listItem.descriptor.setDisplayNames(extension->displayNames(key));
-                        listItem.descriptor.setIcon(extension->icon(key));
-                        listItem.descriptor.setIcons(extension->icons(key));
-                    }
+                    listItem.setValues(inputContextPlugin, key);
 
                     int index = mMethods.indexOf(listItem);
                     if (index >= 0) {
@@ -166,6 +179,7 @@
                         mMethods[index].toBeRemoved = false;
                     } else {
                         listItem.languages = inputContextPlugin->languages(key);
+                        listItem.cachedLanguage = activeLanguage;
                         mMethods.append(listItem);
                     }
                 }
@@ -263,16 +277,16 @@
 
 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 (HbKeymapFactory::instance()->keymap(language) != 0);
+}
+
+void HbInputModeCachePrivate::refreshIfNeeded(HbInputMethodListItem &item, const HbInputLanguage &language)
+{
+    if (item.cachedLanguage != language) {
+        QInputContextPlugin *plugin = pluginInstance(item.descriptor.pluginNameAndPath());
+        item.setValues(plugin, item.descriptor.key());
+        item.cachedLanguage = language;
     }
-
-    return false;
 }
 
 /// @endcond
@@ -403,8 +417,8 @@
 
     QList<HbInputMethodDescriptor> result;
 
-    foreach (const HbInputMethodListItem &item, d->mMethods) {
-        foreach (const QString &lang, item.languages) {
+    for (int ii = 0; ii < d->mMethods.count(); ii++) {
+        foreach (const QString &lang, d->mMethods[ii].languages) {
             HbInputModeProperties properties = d->propertiesFromString(lang);
             
             // Find custom methods that supports given language or any language and
@@ -413,7 +427,9 @@
                 (properties.language() == language || properties.language() == HbInputLanguage()) &&
                 ((orientation == Qt::Vertical && properties.keyboard() == HbKeyboardTouchPortrait) ||
                 (orientation == Qt::Horizontal && properties.keyboard() == HbKeyboardTouchLandscape))) {
-                result.append(item.descriptor);
+
+                d->refreshIfNeeded(d->mMethods[ii], language);
+                result.append(d->mMethods[ii].descriptor);
                 break;
             }
         }
@@ -430,22 +446,39 @@
 {
     Q_D(HbInputModeCache);
 
-    HbInputMethodDescriptor result;
-    foreach (const HbInputMethodListItem &item, d->mMethods) {
-        foreach (const QString &language, item.languages) {
+    HbInputLanguage currentLanguage = HbInputSettingProxy::instance()->globalInputLanguage();
+    bool mapped = d->isMappedLanguage(currentLanguage);
+
+    for (int ii = 0; ii < d->mMethods.count(); ii++) {
+        foreach (const QString &language, d->mMethods[ii].languages) {
             HbInputModeProperties properties = d->propertiesFromString(language);
 
+            if (properties.language().undefined()) {
+                // The input method reports language range but current language is not mapped
+                // language. Skip this one. 
+                if (!mapped) {
+                    continue; 
+                }
+            } else {
+                // The input method reports support for specific language but it is not an exact
+                // match to current language. Skip this one 
+                if (properties.language() != currentLanguage) {
+                    // It is not direct match either.
+                    continue;
+                }
+            }
+
             // Find default method that supports given orientation
             if (properties.inputMode() == HbInputModeDefault &&
                 ((orientation == Qt::Vertical && properties.keyboard() == HbKeyboardTouchPortrait) ||
                 (orientation == Qt::Horizontal && properties.keyboard() == HbKeyboardTouchLandscape))) {
-                result = item.descriptor;
-                break;
+                d->refreshIfNeeded(d->mMethods[ii], currentLanguage);
+                return d->mMethods[ii].descriptor;
             }
         }
     }
 
-    return result;
+    return HbInputMethodDescriptor();
 }
 
 /*!