src/hbcore/inputfw/hbinputmodecache.cpp
changeset 5 627c4a0fd0e7
parent 3 11d3954df52a
child 6 c3690ec91ef8
equal deleted inserted replaced
3:11d3954df52a 5:627c4a0fd0e7
    73     HbInputMethod *methodInstance(const QString &pluginFileName, const QString &key) const;
    73     HbInputMethod *methodInstance(const QString &pluginFileName, const QString &key) const;
    74     HbInputModeProperties propertiesFromString(const QString &entry) const;
    74     HbInputModeProperties propertiesFromString(const QString &entry) const;
    75     HbInputModeProperties propertiesFromState(const HbInputState &state) const;
    75     HbInputModeProperties propertiesFromState(const HbInputState &state) const;
    76     HbInputMethod *cachedMethod(HbInputMethodListItem &item);
    76     HbInputMethod *cachedMethod(HbInputMethodListItem &item);
    77     void updateMonitoredPaths();
    77     void updateMonitoredPaths();
       
    78     bool isMappedLanguage(const HbInputLanguage &language) const;
    78 
    79 
    79 public:
    80 public:
    80     QFileSystemWatcher *mWatcher;
    81     QFileSystemWatcher *mWatcher;
    81     QList<HbInputMethodListItem> mMethods;
    82     QList<HbInputMethodListItem> mMethods;
    82     bool mShuttingDown;
    83     bool mShuttingDown;
   169         if (mMethods[i].toBeRemoved) {
   170         if (mMethods[i].toBeRemoved) {
   170             if (mMethods[i].cached && mMethods[i].cached->isActiveMethod()) {
   171             if (mMethods[i].cached && mMethods[i].cached->isActiveMethod()) {
   171                 // If the item to be removed happens to be the active one,
   172                 // If the item to be removed happens to be the active one,
   172                 // try to deal with the situation.
   173                 // try to deal with the situation.
   173                 mMethods[i].cached->forceUnfocus();
   174                 mMethods[i].cached->forceUnfocus();
   174                 if (mMethods[i].descriptor.pluginNameAndPath() == HbInputSettingProxy::instance()->activeCustomInputMethod().pluginNameAndPath()) {
   175                 // The active custom method is being removed.
   175                     // The active custom method is being removed.
   176                 // Clear out related setting proxy values.
   176                     // Clear out related setting proxy values.
   177                 if (mMethods[i].descriptor.pluginNameAndPath() == HbInputSettingProxy::instance()->preferredInputMethod(Qt::Horizontal).pluginNameAndPath()) {
   177                     HbInputSettingProxy::instance()->setActiveCustomInputMethod(HbInputMethodDescriptor());
   178                     HbInputSettingProxy::instance()->setPreferredInputMethod(Qt::Horizontal, HbInputMethodDescriptor());
       
   179                 }
       
   180                 if (mMethods[i].descriptor.pluginNameAndPath() == HbInputSettingProxy::instance()->preferredInputMethod(Qt::Vertical).pluginNameAndPath()) {
       
   181                     HbInputSettingProxy::instance()->setPreferredInputMethod(Qt::Vertical, HbInputMethodDescriptor());
   178                 }
   182                 }
   179 
   183 
   180                 // Replace it with null input context.
   184                 // Replace it with null input context.
   181                 HbInputMethod *master = HbInputMethodNull::Instance();
   185                 HbInputMethod *master = HbInputMethodNull::Instance();
   182                 master->d_ptr->mIsActive = true;
   186                 master->d_ptr->mIsActive = true;
   183                 QInputContext* proxy = master->d_ptr->newProxy();
   187                 QInputContext* proxy = master->d_ptr->proxy();
   184                 qApp->setInputContext(proxy);
   188                 if (proxy != qApp->inputContext())
       
   189                     qApp->setInputContext(proxy);
   185             }
   190             }
   186             delete mMethods[i].cached;
   191             delete mMethods[i].cached;
   187             mMethods.removeAt(i);
   192             mMethods.removeAt(i);
   188             i--;
   193             i--;
   189         }
   194         }
   243         } else {
   248         } else {
   244             mWatcher->addPath(path);
   249             mWatcher->addPath(path);
   245         }
   250         }
   246     }
   251     }
   247 }
   252 }
       
   253 
       
   254 bool HbInputModeCachePrivate::isMappedLanguage(const HbInputLanguage &language) const
       
   255 {
       
   256     if (language.defined()) {
       
   257         QList<HbInputLanguage> languages = HbKeymapFactory::instance()->availableLanguages();
       
   258         foreach (const HbInputLanguage mappedLanguage, languages) {
       
   259             if (mappedLanguage == language) {
       
   260                 return true;
       
   261             }
       
   262         }
       
   263     }
       
   264 
       
   265     return false;
       
   266 }
       
   267 
   248 /// @endcond
   268 /// @endcond
   249 
   269 
   250 /*!
   270 /*!
   251 \internal
   271 \internal
   252 Returns the singleton instance.
   272 Returns the singleton instance.
   468     }
   488     }
   469 
   489 
   470     return result;
   490     return result;
   471 }
   491 }
   472 
   492 
       
   493 /*!
       
   494 \internal
       
   495 Returns true if given input method is able to handle given input state.
       
   496 */
       
   497 bool HbInputModeCache::acceptsState(const HbInputMethod *inputMethod, const HbInputState &state) const
       
   498 {
       
   499     Q_D(const HbInputModeCache);
       
   500 
       
   501     foreach (const HbInputMethodListItem item, d->mMethods) {
       
   502         if (item.cached == inputMethod) {           
       
   503             foreach (const QString language, item.languages) {
       
   504                 HbInputModeProperties mode = d->propertiesFromString(language);
       
   505                 // Check if keyboard type matches.
       
   506                 if (mode.keyboard() == state.keyboard()) {
       
   507                     // Check if input mode matches or it is a custom input method but
       
   508                     // state's mode is not numeric.
       
   509                     if (mode.inputMode() == state.inputMode() ||
       
   510                         ((mode.inputMode() == HbInputModeCustom) &&
       
   511                          (state.inputMode() != HbInputModeNumeric))) {
       
   512                         // Check if language matches or input method supports
       
   513                         // all mapped languages and state's language is among them.
       
   514                         if (mode.language() == state.language() ||
       
   515                             (mode.language().undefined() && d->isMappedLanguage(state.language()))) {
       
   516                             return true;
       
   517                         }
       
   518                     }
       
   519                 }
       
   520             }
       
   521         }
       
   522     }
       
   523 
       
   524     return false;
       
   525 }
       
   526 
       
   527 /*!
       
   528 \internal
       
   529 Returns input method descriptor for given input method. Returns empty descriptor if the framework
       
   530 doesn't recognize given input method.
       
   531 */
       
   532 HbInputMethodDescriptor HbInputModeCache::descriptor(const HbInputMethod *inputMethod) const
       
   533 {
       
   534     Q_D(const HbInputModeCache);
       
   535 
       
   536     foreach (HbInputMethodListItem item, d->mMethods) {
       
   537         if (item.cached == inputMethod) {
       
   538             return item.descriptor;
       
   539         }
       
   540     }
       
   541 
       
   542     return HbInputMethodDescriptor();
       
   543 }
       
   544 
       
   545 
   473 // End of file
   546 // End of file
       
   547