56 bool operator==(const HbInputMethodListItem &item) const { |
56 bool operator==(const HbInputMethodListItem &item) const { |
57 return (descriptor.pluginNameAndPath() == item.descriptor.pluginNameAndPath() && |
57 return (descriptor.pluginNameAndPath() == item.descriptor.pluginNameAndPath() && |
58 descriptor.key() == item.descriptor.key()); |
58 descriptor.key() == item.descriptor.key()); |
59 } |
59 } |
60 |
60 |
|
61 void setValues(QInputContextPlugin *plugin, const QString &key); |
|
62 |
61 public: |
63 public: |
62 HbInputMethodDescriptor descriptor; |
64 HbInputMethodDescriptor descriptor; |
63 QStringList languages; |
65 QStringList languages; |
64 HbInputMethod *cached; |
66 HbInputMethod *cached; |
65 bool toBeRemoved; |
67 bool toBeRemoved; |
|
68 HbInputLanguage cachedLanguage; |
66 }; |
69 }; |
|
70 |
|
71 void HbInputMethodListItem::setValues(QInputContextPlugin *plugin, const QString &key) |
|
72 { |
|
73 if (plugin) { |
|
74 descriptor.setKey(key); |
|
75 descriptor.setDisplayName(plugin->displayName(key)); |
|
76 |
|
77 HbInputContextPlugin *extension = qobject_cast<HbInputContextPlugin *>(plugin); |
|
78 if (extension) { |
|
79 descriptor.setDisplayNames(extension->displayNames(key)); |
|
80 descriptor.setIcon(extension->icon(key)); |
|
81 descriptor.setIcons(extension->icons(key)); |
|
82 } |
|
83 } |
|
84 } |
67 |
85 |
68 class HbInputModeCachePrivate |
86 class HbInputModeCachePrivate |
69 { |
87 { |
70 public: |
88 public: |
71 HbInputModeCachePrivate() : mWatcher(new QFileSystemWatcher()), mShuttingDown(false) {} |
89 HbInputModeCachePrivate() : mWatcher(new QFileSystemWatcher()), mShuttingDown(false) {} |
76 HbInputModeProperties propertiesFromString(const QString &entry) const; |
94 HbInputModeProperties propertiesFromString(const QString &entry) const; |
77 HbInputModeProperties propertiesFromState(const HbInputState &state) const; |
95 HbInputModeProperties propertiesFromState(const HbInputState &state) const; |
78 HbInputMethod *cachedMethod(HbInputMethodListItem &item); |
96 HbInputMethod *cachedMethod(HbInputMethodListItem &item); |
79 void updateMonitoredPaths(); |
97 void updateMonitoredPaths(); |
80 bool isMappedLanguage(const HbInputLanguage &language) const; |
98 bool isMappedLanguage(const HbInputLanguage &language) const; |
|
99 void refreshIfNeeded(HbInputMethodListItem &item, const HbInputLanguage &language); |
81 |
100 |
82 public: |
101 public: |
83 QFileSystemWatcher *mWatcher; |
102 QFileSystemWatcher *mWatcher; |
84 QList<HbInputMethodListItem> mMethods; |
103 QList<HbInputMethodListItem> mMethods; |
85 bool mShuttingDown; |
104 bool mShuttingDown; |
128 // tag them not refreshed. |
147 // tag them not refreshed. |
129 for (int k = 0; k < mMethods.count(); k++) { |
148 for (int k = 0; k < mMethods.count(); k++) { |
130 mMethods[k].toBeRemoved = true; |
149 mMethods[k].toBeRemoved = true; |
131 } |
150 } |
132 |
151 |
|
152 HbInputLanguage activeLanguage = HbInputSettingProxy::instance()->globalInputLanguage(); |
|
153 |
133 // Query plugin paths and scan the folders. |
154 // Query plugin paths and scan the folders. |
134 QStringList folders = HbInputSettingProxy::instance()->inputMethodPluginPaths(); |
155 QStringList folders = HbInputSettingProxy::instance()->inputMethodPluginPaths(); |
135 foreach(const QString &folder, folders) { |
156 foreach(const QString &folder, folders) { |
136 QDir dir(folder); |
157 QDir dir(folder); |
137 for (unsigned int i = 0; i < dir.count(); i++) { |
158 for (unsigned int i = 0; i < dir.count(); i++) { |
147 |
168 |
148 // For each found plugin, check if there is already a list item for it. |
169 // For each found plugin, check if there is already a list item for it. |
149 // If not, then add one. |
170 // If not, then add one. |
150 QStringList contextKeys = inputContextPlugin->keys(); |
171 QStringList contextKeys = inputContextPlugin->keys(); |
151 foreach(const QString &key, contextKeys) { |
172 foreach(const QString &key, contextKeys) { |
152 listItem.descriptor.setKey(key); |
173 listItem.setValues(inputContextPlugin, key); |
153 listItem.descriptor.setDisplayName(inputContextPlugin->displayName(key)); |
|
154 |
|
155 HbInputContextPlugin *extension = qobject_cast<HbInputContextPlugin *>(inputContextPlugin); |
|
156 if (extension) { |
|
157 listItem.descriptor.setDisplayNames(extension->displayNames(key)); |
|
158 listItem.descriptor.setIcon(extension->icon(key)); |
|
159 listItem.descriptor.setIcons(extension->icons(key)); |
|
160 } |
|
161 |
174 |
162 int index = mMethods.indexOf(listItem); |
175 int index = mMethods.indexOf(listItem); |
163 if (index >= 0) { |
176 if (index >= 0) { |
164 // The method is already in the list, the situation hasn't changed. |
177 // The method is already in the list, the situation hasn't changed. |
165 // just tag it not to be removed. |
178 // just tag it not to be removed. |
166 mMethods[index].toBeRemoved = false; |
179 mMethods[index].toBeRemoved = false; |
167 } else { |
180 } else { |
168 listItem.languages = inputContextPlugin->languages(key); |
181 listItem.languages = inputContextPlugin->languages(key); |
|
182 listItem.cachedLanguage = activeLanguage; |
169 mMethods.append(listItem); |
183 mMethods.append(listItem); |
170 } |
184 } |
171 } |
185 } |
172 } |
186 } |
173 } |
187 } |
261 } |
275 } |
262 } |
276 } |
263 |
277 |
264 bool HbInputModeCachePrivate::isMappedLanguage(const HbInputLanguage &language) const |
278 bool HbInputModeCachePrivate::isMappedLanguage(const HbInputLanguage &language) const |
265 { |
279 { |
266 if (language.defined()) { |
280 return (HbKeymapFactory::instance()->keymap(language) != 0); |
267 QList<HbInputLanguage> languages = HbKeymapFactory::instance()->availableLanguages(); |
281 } |
268 foreach(const HbInputLanguage &mappedLanguage, languages) { |
282 |
269 if (mappedLanguage == language) { |
283 void HbInputModeCachePrivate::refreshIfNeeded(HbInputMethodListItem &item, const HbInputLanguage &language) |
270 return true; |
284 { |
271 } |
285 if (item.cachedLanguage != language) { |
272 } |
286 QInputContextPlugin *plugin = pluginInstance(item.descriptor.pluginNameAndPath()); |
273 } |
287 item.setValues(plugin, item.descriptor.key()); |
274 |
288 item.cachedLanguage = language; |
275 return false; |
289 } |
276 } |
290 } |
277 |
291 |
278 /// @endcond |
292 /// @endcond |
279 |
293 |
280 /*! |
294 /*! |
401 { |
415 { |
402 Q_D(HbInputModeCache); |
416 Q_D(HbInputModeCache); |
403 |
417 |
404 QList<HbInputMethodDescriptor> result; |
418 QList<HbInputMethodDescriptor> result; |
405 |
419 |
406 foreach (const HbInputMethodListItem &item, d->mMethods) { |
420 for (int ii = 0; ii < d->mMethods.count(); ii++) { |
407 foreach (const QString &lang, item.languages) { |
421 foreach (const QString &lang, d->mMethods[ii].languages) { |
408 HbInputModeProperties properties = d->propertiesFromString(lang); |
422 HbInputModeProperties properties = d->propertiesFromString(lang); |
409 |
423 |
410 // Find custom methods that supports given language or any language and |
424 // Find custom methods that supports given language or any language and |
411 // supports given orientation |
425 // supports given orientation |
412 if (properties.inputMode() == HbInputModeCustom && |
426 if (properties.inputMode() == HbInputModeCustom && |
413 (properties.language() == language || properties.language() == HbInputLanguage()) && |
427 (properties.language() == language || properties.language() == HbInputLanguage()) && |
414 ((orientation == Qt::Vertical && properties.keyboard() == HbKeyboardTouchPortrait) || |
428 ((orientation == Qt::Vertical && properties.keyboard() == HbKeyboardTouchPortrait) || |
415 (orientation == Qt::Horizontal && properties.keyboard() == HbKeyboardTouchLandscape))) { |
429 (orientation == Qt::Horizontal && properties.keyboard() == HbKeyboardTouchLandscape))) { |
416 result.append(item.descriptor); |
430 |
|
431 d->refreshIfNeeded(d->mMethods[ii], language); |
|
432 result.append(d->mMethods[ii].descriptor); |
417 break; |
433 break; |
418 } |
434 } |
419 } |
435 } |
420 } |
436 } |
421 |
437 |
428 */ |
444 */ |
429 HbInputMethodDescriptor HbInputModeCache::defaultInputMethod(Qt::Orientation orientation) |
445 HbInputMethodDescriptor HbInputModeCache::defaultInputMethod(Qt::Orientation orientation) |
430 { |
446 { |
431 Q_D(HbInputModeCache); |
447 Q_D(HbInputModeCache); |
432 |
448 |
433 HbInputMethodDescriptor result; |
449 HbInputLanguage currentLanguage = HbInputSettingProxy::instance()->globalInputLanguage(); |
434 foreach (const HbInputMethodListItem &item, d->mMethods) { |
450 bool mapped = d->isMappedLanguage(currentLanguage); |
435 foreach (const QString &language, item.languages) { |
451 |
|
452 for (int ii = 0; ii < d->mMethods.count(); ii++) { |
|
453 foreach (const QString &language, d->mMethods[ii].languages) { |
436 HbInputModeProperties properties = d->propertiesFromString(language); |
454 HbInputModeProperties properties = d->propertiesFromString(language); |
|
455 |
|
456 if (properties.language().undefined()) { |
|
457 // The input method reports language range but current language is not mapped |
|
458 // language. Skip this one. |
|
459 if (!mapped) { |
|
460 continue; |
|
461 } |
|
462 } else { |
|
463 // The input method reports support for specific language but it is not an exact |
|
464 // match to current language. Skip this one |
|
465 if (properties.language() != currentLanguage) { |
|
466 // It is not direct match either. |
|
467 continue; |
|
468 } |
|
469 } |
437 |
470 |
438 // Find default method that supports given orientation |
471 // Find default method that supports given orientation |
439 if (properties.inputMode() == HbInputModeDefault && |
472 if (properties.inputMode() == HbInputModeDefault && |
440 ((orientation == Qt::Vertical && properties.keyboard() == HbKeyboardTouchPortrait) || |
473 ((orientation == Qt::Vertical && properties.keyboard() == HbKeyboardTouchPortrait) || |
441 (orientation == Qt::Horizontal && properties.keyboard() == HbKeyboardTouchLandscape))) { |
474 (orientation == Qt::Horizontal && properties.keyboard() == HbKeyboardTouchLandscape))) { |
442 result = item.descriptor; |
475 d->refreshIfNeeded(d->mMethods[ii], currentLanguage); |
443 break; |
476 return d->mMethods[ii].descriptor; |
444 } |
477 } |
445 } |
478 } |
446 } |
479 } |
447 |
480 |
448 return result; |
481 return HbInputMethodDescriptor(); |
449 } |
482 } |
450 |
483 |
451 /*! |
484 /*! |
452 \internal |
485 \internal |
453 Find correct handler for given input state. |
486 Find correct handler for given input state. |