src/hbinput/inputwidgets/hbinputsettingwidget.cpp
changeset 23 e6ad4ef83b23
parent 7 923ff622b8b9
child 30 80e4d18b72f5
equal deleted inserted replaced
21:4633027730f5 23:e6ad4ef83b23
    32 #include <QInputContextPlugin>
    32 #include <QInputContextPlugin>
    33 #include <QLibrary>
    33 #include <QLibrary>
    34 #include <QPluginLoader>
    34 #include <QPluginLoader>
    35 #include <QDir>
    35 #include <QDir>
    36 #include <QtAlgorithms>
    36 #include <QtAlgorithms>
       
    37 #include <hbinputcontextplugin.h>
       
    38 #include <hbinputmodeproperties.h>
    37 
    39 
    38 #include "hbinputcheckboxlist_p.h"
    40 #include "hbinputcheckboxlist_p.h"
    39 #include "hbinputsettingproxy_p.h"
    41 #include "hbinputsettingproxy_p.h"
    40 #include <hbinputmethoddescriptor.h>
    42 #include <hbinputmethoddescriptor.h>
       
    43 #include <hbinputmethod.h>
       
    44 #include <hbmainwindow.h>
    41 
    45 
    42 const QString statusOff = QObject::tr("Off");
    46 const QString statusOff = QObject::tr("Off");
    43 const QString statusOn = QObject::tr("On");
    47 const QString statusOn = QObject::tr("On");
    44 const QString bestPrediction = QObject::tr("Best prediction");
    48 const QString bestPrediction = QObject::tr("Best prediction");
    45 const QString exactTyping = QObject::tr("Exact typing");
    49 const QString exactTyping = QObject::tr("Exact typing");
    51 const QString KZhuyinName("Zhuyin");
    55 const QString KZhuyinName("Zhuyin");
    52 const QString KCangjieNormalName("CangjieNormal");
    56 const QString KCangjieNormalName("CangjieNormal");
    53 const QString KCangjieEasyName("CangjieEasy");
    57 const QString KCangjieEasyName("CangjieEasy");
    54 const QString KCangjieAdvancedName("CangjieAdvanced");
    58 const QString KCangjieAdvancedName("CangjieAdvanced");
    55 const QString KHwrName("Handwriting");
    59 const QString KHwrName("Handwriting");
    56 const QString KHwrVerySlowName("VerySlow");
    60 const QString KHwrVerySlowName("Very Slow");
    57 const QString KHwrSlowName("Slow");
    61 const QString KHwrSlowName("Slow");
    58 const QString KHwrNormalName("Normal");
    62 const QString KHwrNormalName("Normal");
    59 const QString KHwrFastName("Fast");
    63 const QString KHwrFastName("Fast");
    60 const QString KHwrVeryFastName("VeryFast");
    64 const QString KHwrVeryFastName("Very Fast");
       
    65 
       
    66 // strings used for default language
       
    67 const QString KDefaultChineseName("Chinese");
       
    68 const QString KDefaultEnglishName("English");
       
    69 
       
    70 // hwr speed index are exactly saming as enum HbHwrWritingSpeed
       
    71 const int KHwrSpeedCount = 5;
    61 
    72 
    62 // strings used for represent cangjie
    73 // strings used for represent cangjie
    63 const QString KCangjieGeneralName("Cangjie");
    74 const QString KCangjieGeneralName("Cangjie");
    64 const QString KEasy("Easy");
    75 const QString KEasy("Easy");
    65 const QString KNormal("Normal");
    76 const QString KNormal("Normal");
    73 const int KCangjieNormalMode = 3;
    84 const int KCangjieNormalMode = 3;
    74 const int KCangjieEasyMode = 4;
    85 const int KCangjieEasyMode = 4;
    75 const int KCangjieAdvancedMode = 5;
    86 const int KCangjieAdvancedMode = 5;
    76 const int KHwrMode = 6;
    87 const int KHwrMode = 6;
    77 
    88 
    78 // define chinese input plugin name
    89 class HbCnInputModeMap
    79 #ifdef Q_OS_WIN
    90 {
    80 const QString KCnHwrPluginName("HbChineseHwrd.dll");
    91 public:
    81 #else
    92     int mMode;
    82 #ifdef Q_OS_SYMBIAN
    93     QString mModeName;
    83 const QString KCnHwrPluginName("HbChineseHwr.qtplugin");
    94 };
    84 #else
    95 
    85 const QString KCnHwrPluginName("HbChineseHwr.dll");
    96 const HbCnInputModeMap modesMap[] = {
    86 #endif
    97     {KPinyinMode, KPinyinName},
    87 #endif
    98     {KStrokeMode, KStrokeName},
    88 
    99     {KZhuyinMode, KZhuyinName},
    89 #ifdef Q_OS_WIN
   100     {KCangjieNormalMode, KCangjieNormalName},
    90 const QString KCnVItutPluginName("HbChineseVItutd.dll");
   101     {KCangjieEasyMode, KCangjieEasyName},
    91 #else
   102     {KCangjieAdvancedMode, KCangjieAdvancedName},
    92 #ifdef Q_OS_SYMBIAN
   103     {KHwrMode, KHwrName}
    93 const QString KCnVItutPluginName("HbChineseVItut.qtplugin");
   104 };
    94 #else
       
    95 const QString KCnVItutPluginName("HbChineseVItut.dll");
       
    96 #endif
       
    97 #endif
       
    98 
       
    99 #ifdef Q_OS_WIN
       
   100 const QString KCnVkbPluginName("HbChineseVkbd.dll");
       
   101 #else
       
   102 #ifdef Q_OS_SYMBIAN
       
   103 const QString KCnVkbPluginName("HbChineseVkb.qtplugin");
       
   104 #else
       
   105 const QString KCnVkbPluginName("HbChineseVkb.dll");
       
   106 #endif
       
   107 #endif
       
   108 
   105 
   109 class HbInputSettingWidgetPrivate
   106 class HbInputSettingWidgetPrivate
   110 {
   107 {
   111     Q_DECLARE_PUBLIC(HbInputSettingWidget)
   108     Q_DECLARE_PUBLIC(HbInputSettingWidget)
   112 
   109 
   118     void fillLanguageList(QStringList &list, QList<HbInputLanguage> &languageList, const QString &replace = QString(" "));
   115     void fillLanguageList(QStringList &list, QList<HbInputLanguage> &languageList, const QString &replace = QString(" "));
   119     int languageToIndex(const HbInputLanguage &language, const QList<HbInputLanguage> &languageList);
   116     int languageToIndex(const HbInputLanguage &language, const QList<HbInputLanguage> &languageList);
   120     HbInputLanguage indexToLanguage(int index, const QList<HbInputLanguage> &languageList);
   117     HbInputLanguage indexToLanguage(int index, const QList<HbInputLanguage> &languageList);
   121     void createSecondaryLanguageList();
   118     void createSecondaryLanguageList();
   122     void updateContentWidgetData();
   119     void updateContentWidgetData();
       
   120     // following API used by chinese
   123     int inputModeToIndex(const int &inputMode, const QList<int> &inputModeList);
   121     int inputModeToIndex(const int &inputMode, const QList<int> &inputModeList);
   124     int indexToInputmode(int index, const QList<int> &inputModeList);
   122     int indexToInputmode(int index, const QList<int> &inputModeList);
   125     void createChineseSettingGroup(HbDataFormModel *model);
   123     void createChineseSettingGroup(HbDataFormModel *model);
   126 
   124     void createValidModesList(QStringList &imModeNames, QList<int> &imModeList);
   127     QInputContextPlugin *pluginInstance(const QString &pluginFileName) const;
   125     QString inputModeName(int mode) const;
   128     HbInputMethodDescriptor findInputMethodDescriptor(const QString &inputMethodString);
   126     int inputModeByGivenName(const QString& imName) const;
   129     void setInputMethodVar(Qt::Orientation orientation, QString &inputMethodString, QByteArray &num);
   127     int defaultModeByGivenLang(const HbInputLanguage &lang) const;
   130     QByteArray createHwrSpeedData(QByteArray preferredCustomData, int index);
   128 
   131 public:
   129 public:  
   132     HbDataForm *mForm;
   130     HbDataForm *mForm;
   133     HbDataFormModelItem *mPrimaryLanguageItem;
   131     HbDataFormModelItem *mPrimaryLanguageItem;
   134     HbDataFormModelItem *mSecondaryLanguageItem;
   132     HbDataFormModelItem *mSecondaryLanguageItem;
   135     HbDataFormModelItem *mKeypressTimeoutItem;
   133     HbDataFormModelItem *mKeypressTimeoutItem;
   136     HbDataFormModelItem *mCharacterPreviewItem;
   134     HbDataFormModelItem *mCharacterPreviewItem;
   162     HbDataFormModelItem *mCangjieItem;
   160     HbDataFormModelItem *mCangjieItem;
   163     int mCnPortraitInputMode;
   161     int mCnPortraitInputMode;
   164     int mCnLandscapeInputMode;
   162     int mCnLandscapeInputMode;
   165     int mCnCangjieInputMode;
   163     int mCnCangjieInputMode;
   166 
   164 
   167     int mHwrSpeed;
   165     HbHwrWritingSpeed  mHwrSpeed;
   168     QList<int> mCnPortraitInputModeList;
   166     QList<int> mCnPortraitInputModeList;
   169     QList<int> mCnLandscapeInputModeList;
   167     QList<int> mCnLandscapeInputModeList;
   170     QList<int> mCangjieInputModeList;
   168     QList<int> mCangjieInputModeList;
   171     QStringList mCnPortraitInputModeNames;
   169     QStringList mCnPortraitInputModeNames;
   172     QStringList mCnLandscapeInputModeNames;
   170     QStringList mCnLandscapeInputModeNames;
   173     QStringList mCnCangjieInputModeNames;
   171     QStringList mCnCangjieInputModeNames;
   174     QStringList mHwrSpeedNames;
   172     QStringList mHwrSpeedNames;
       
   173     QStringList mCnDefaultLanguageNames;
       
   174     HbDataFormModelItem *mCnDefaultLanguageItem;
   175 };
   175 };
   176 
   176 
   177 /*!
   177 /*!
   178 Constructs setting widget
   178 Constructs setting widget
   179 */
   179 */
   188       mCorrectionLevelItem(0),
   188       mCorrectionLevelItem(0),
   189       mPrimaryCandidateItem(0),
   189       mPrimaryCandidateItem(0),
   190       q_ptr(0),
   190       q_ptr(0),
   191       mModel(0),
   191       mModel(0),
   192       mLanguageGroup(0),
   192       mLanguageGroup(0),
   193       mChineseInputGroup(0),
   193       mChineseInputGroup(0),      
   194       mPortraitInputMethodItem(0),
   194       mPortraitInputMethodItem(0),
   195       mLandscapeInputMethodItem(0),
   195       mLandscapeInputMethodItem(0),
   196       mHwrSpeedItem(0),
   196       mHwrSpeedItem(0),
   197       mCangjieItem(0)
   197       mCangjieItem(0),      
       
   198       mCnCangjieInputMode(KCangjieNormalMode),
       
   199       mCnDefaultLanguageItem(0)
       
   200 
   198 {
   201 {
   199 }
   202 }
   200 
   203 
   201 /*!
   204 /*!
   202 Initializes setting widget
   205 Initializes setting widget
   222         createSettingItems();
   225         createSettingItems();
   223     } else {
   226     } else {
   224         // simply update the settings dependant content widget data of all the items
   227         // simply update the settings dependant content widget data of all the items
   225         updateContentWidgetData();
   228         updateContentWidgetData();
   226         //make sure that the items are not expanded
   229         //make sure that the items are not expanded
   227         QModelIndex index = mModel->indexFromItem(mSecondaryLanguageItem->parent());
   230         QModelIndex index = mModel->indexFromItem(mSecondaryLanguageItem ? mSecondaryLanguageItem->parent(): mPrimaryLanguageItem->parent());
   228         mForm->setExpanded(index, false);
   231         mForm->setExpanded(index, false);
   229         index = mModel->indexFromItem(mKeypressTimeoutItem->parent());
   232         index = mModel->indexFromItem(mKeypressTimeoutItem->parent());
   230         mForm->setExpanded(index, false);
   233         mForm->setExpanded(index, false);
   231         index = mModel->indexFromItem(mPredictionItem->parent());
   234         index = mModel->indexFromItem(mPredictionItem->parent());
   232         mForm->setExpanded(index, false);        
   235         mForm->setExpanded(index, false);        
   233     }
   236     }
   234 }
   237 }
   235 
   238 
       
   239 void HbInputSettingWidgetPrivate::createValidModesList(QStringList &imModeNames, QList<int> &imModeList)
       
   240 {    
       
   241     Qt::Orientation orientation = Qt::Horizontal;
       
   242     if (mForm) {
       
   243        orientation = mForm->mainWindow()->orientation();
       
   244     }
       
   245 
       
   246     QList<HbInputMethodDescriptor> methodList = HbInputMethod::listCustomInputMethods(orientation,
       
   247         HbInputSettingProxy::instance()->globalInputLanguage());
       
   248     methodList.insert(0, HbInputMethod::defaultInputMethod(orientation));
       
   249 
       
   250     foreach(const HbInputMethodDescriptor &des, methodList) {
       
   251         QStringList displayNames = des.displayNames();
       
   252         if (!displayNames.isEmpty()) {
       
   253             imModeNames += displayNames;
       
   254         } else {
       
   255             QString displayName = des.displayName();
       
   256             imModeNames.append(displayName);
       
   257         }
       
   258     }
       
   259 
       
   260     imModeNames.removeDuplicates();
       
   261     // filter out the input mode that not valid to current screen orientation
       
   262     if (imModeNames.contains(KCangjieGeneralName)) {
       
   263         imModeNames.removeOne(KCangjieGeneralName);
       
   264     }
       
   265 
       
   266     for (int i = 0; i < imModeNames.count(); ++i) {
       
   267         imModeList.append(inputModeByGivenName(imModeNames.at(i)));
       
   268     }
       
   269 }
       
   270 
       
   271 QString HbInputSettingWidgetPrivate::inputModeName(int mode) const
       
   272 {
       
   273     int cnImCnts = sizeof(modesMap) / sizeof(modesMap[0]);
       
   274     if (mode >= 0 && mode < cnImCnts) {
       
   275         return modesMap[mode].mModeName;
       
   276     }
       
   277 
       
   278     return QString();
       
   279 }
       
   280 
       
   281 int HbInputSettingWidgetPrivate::inputModeByGivenName(const QString& imName) const
       
   282 {
       
   283     int cnMode = KChineseInputModeNone;
       
   284 
       
   285     if (imName == KCangjieGeneralName) {
       
   286         HbCangjieDetailMode cjDetail = HbInputSettingProxy::instance()->detailedCangjieMode();
       
   287         switch (cjDetail) {
       
   288         case HbCangjieEasy: {
       
   289             cnMode = KCangjieEasyMode;
       
   290         }
       
   291             break;
       
   292         case HbCangjieAdvanced: {
       
   293             cnMode = KCangjieAdvancedMode;
       
   294         }
       
   295             break;
       
   296         case HbCangjieNormal: 
       
   297         default: {
       
   298             cnMode = KCangjieNormalMode;
       
   299         }
       
   300             break;
       
   301         }
       
   302     } else {
       
   303         int cnImCnts = sizeof(modesMap) / sizeof(modesMap[0]);
       
   304         for (int i = 0; i < cnImCnts; ++i) {
       
   305             if (modesMap[i].mModeName == imName) {
       
   306                 cnMode = modesMap[i].mMode;
       
   307             }
       
   308         }
       
   309     }
       
   310 
       
   311     if (KChineseInputModeNone == cnMode) {
       
   312         HbInputLanguage lang = HbInputSettingProxy::instance()->globalInputLanguage();
       
   313         cnMode = defaultModeByGivenLang(lang);
       
   314     }
       
   315     
       
   316     return cnMode;
       
   317 }
       
   318 
       
   319 int HbInputSettingWidgetPrivate::defaultModeByGivenLang(const HbInputLanguage &lang) const
       
   320 {
       
   321     int imMode = KChineseInputModeNone;
       
   322     if (lang.variant() == QLocale::China) {
       
   323         imMode = KPinyinMode;
       
   324     } else if (lang.variant() == QLocale::HongKong) {
       
   325         imMode = KStrokeMode;
       
   326     } else if (lang.variant() == QLocale::Taiwan) {
       
   327         imMode = KZhuyinMode;
       
   328     }
       
   329 
       
   330     return imMode;
       
   331 }
       
   332 
   236 void HbInputSettingWidgetPrivate::createChineseSettingGroup(HbDataFormModel *model)
   333 void HbInputSettingWidgetPrivate::createChineseSettingGroup(HbDataFormModel *model)
   237 {
   334 {
   238     Q_Q(HbInputSettingWidget);
   335     Q_Q(HbInputSettingWidget);
   239     int imMode = KChineseInputModeNone;
       
   240     QByteArray ba = HbInputSettingProxy::instance()->preferredInputMethodCustomData(Qt::Vertical);
   336     QByteArray ba = HbInputSettingProxy::instance()->preferredInputMethodCustomData(Qt::Vertical);
   241     QString portraitCustomData(ba);
   337     QString imName(ba);
   242     QString imName = portraitCustomData.split(" ").at(0);
       
   243     HbInputLanguage lang = HbInputSettingProxy::instance()->globalInputLanguage();
   338     HbInputLanguage lang = HbInputSettingProxy::instance()->globalInputLanguage();
   244 
   339     mCnPortraitInputMode = inputModeByGivenName(imName);
   245     if (imName == KPinyinName) {
       
   246         imMode = KPinyinMode;
       
   247     } else if (imName == KStrokeName) {
       
   248         imMode = KStrokeMode;
       
   249     } else if (imName == KZhuyinName) {
       
   250         imMode = KZhuyinMode;
       
   251     } else if (imName == KHwrName) {
       
   252         imMode = KHwrMode;
       
   253     } else {
       
   254         if (lang.variant() == QLocale::China) {
       
   255             imMode = KPinyinMode;
       
   256         } else if (lang.variant() == QLocale::HongKong) {
       
   257             imMode = KStrokeMode;
       
   258         } else if (lang.variant() == QLocale::Taiwan) {
       
   259             imMode = KZhuyinMode;
       
   260         }
       
   261     }
       
   262 
       
   263     mCnPortraitInputMode = imMode;
       
   264 
   340 
   265     ba = HbInputSettingProxy::instance()->preferredInputMethodCustomData(Qt::Horizontal);
   341     ba = HbInputSettingProxy::instance()->preferredInputMethodCustomData(Qt::Horizontal);
   266     QString landscapeCustomData(ba);
   342     imName = QString(ba);
   267     imName = landscapeCustomData.split(" ").at(0);
   343     mCnLandscapeInputMode = inputModeByGivenName(imName);
   268 
       
   269     mCnCangjieInputMode = KCangjieNormalMode;
       
   270     if (imName == KPinyinName) {
       
   271         mCnLandscapeInputMode = KPinyinMode;
       
   272     } else if (imName == KStrokeName) {
       
   273         mCnLandscapeInputMode = KStrokeMode;
       
   274     } else if (imName == KZhuyinName) {
       
   275         mCnLandscapeInputMode = KZhuyinMode;
       
   276     } else if (imName == KCangjieNormalName) {
       
   277         mCnLandscapeInputMode = KCangjieNormalMode;
       
   278         mCnCangjieInputMode = KCangjieNormalMode;
       
   279     } else if (imName == KCangjieEasyName) {
       
   280         mCnLandscapeInputMode = KCangjieNormalMode;
       
   281         mCnCangjieInputMode = KCangjieEasyMode;
       
   282     } else if (imName == KCangjieAdvancedName) {
       
   283         mCnLandscapeInputMode = KCangjieNormalMode;
       
   284         mCnCangjieInputMode = KCangjieAdvancedMode;
       
   285     } else if (imName == KHwrName) {
       
   286         mCnLandscapeInputMode = KHwrMode;
       
   287     } else {
       
   288         if (lang.variant() == QLocale::China) {
       
   289             mCnLandscapeInputMode = KPinyinMode;
       
   290         } else if (lang.variant() == QLocale::HongKong) {
       
   291             mCnLandscapeInputMode = KStrokeMode;
       
   292         } else if (lang.variant() == QLocale::Taiwan) {
       
   293             mCnLandscapeInputMode = KZhuyinMode;
       
   294         }
       
   295     }
       
   296 
       
   297     Qt::Orientation orientation = HbInputSettingProxy::instance()->screenOrientation();
       
   298     ba = HbInputSettingProxy::instance()->preferredInputMethodCustomData(orientation);
       
   299     QString customData(ba);
       
   300     if (customData.split(" ").count() > 1) {
       
   301         imName = customData.split(" ").at(1);
       
   302         if (imName == KHwrVerySlowName) {
       
   303             mHwrSpeed = 0;
       
   304         } else if (imName == KHwrSlowName) {
       
   305             mHwrSpeed = 1;
       
   306         } else if (imName == KHwrNormalName) {
       
   307             mHwrSpeed = 2;
       
   308         } else if (imName == KHwrFastName) {
       
   309             mHwrSpeed = 3;
       
   310         } else if (imName == KHwrVeryFastName) {
       
   311             mHwrSpeed = 4;
       
   312         } else {
       
   313             mHwrSpeed = 2;
       
   314         }
       
   315     } else {
       
   316         mHwrSpeed = 2;
       
   317     }
       
   318 
   344 
   319     mHwrSpeedNames.clear();
   345     mHwrSpeedNames.clear();
   320     mCnPortraitInputModeList.clear();
   346     mCnPortraitInputModeList.clear();
   321     mCnLandscapeInputModeList.clear();
   347     mCnLandscapeInputModeList.clear();
   322     mCnPortraitInputModeNames.clear();
   348     mCnPortraitInputModeNames.clear();
   323     mCnLandscapeInputModeNames.clear();
   349     mCnLandscapeInputModeNames.clear();
   324     mCnCangjieInputModeNames.clear();
   350     mCnCangjieInputModeNames.clear();
   325 
   351     mCnDefaultLanguageNames.clear();
   326     mHwrSpeedNames << "Very slow" << "Slow" << "Normal" << "Fast" << "Very Fast";
   352 
   327     if (mPrimaryInputLanguage == HbInputLanguage(QLocale::Chinese, QLocale::China)) {
   353     createValidModesList(mCnPortraitInputModeNames, mCnPortraitInputModeList);
   328         mCnPortraitInputModeList << KPinyinMode << KStrokeMode << KHwrMode;
   354     mCnLandscapeInputModeNames = mCnPortraitInputModeNames;
   329         mCnLandscapeInputModeList << KPinyinMode << KStrokeMode << KHwrMode;
   355     mCnLandscapeInputModeList = mCnPortraitInputModeList;
   330         mCnPortraitInputModeNames << KPinyinName << KStrokeName << KHwrName;
   356 
   331         mCnLandscapeInputModeNames << KPinyinName << KStrokeName << KHwrName;
   357     // append cangjie to landscape related list if need
   332     } else if (mPrimaryInputLanguage == HbInputLanguage(QLocale::Chinese, QLocale::HongKong)) {
   358     if (mPrimaryInputLanguage == HbInputLanguage(QLocale::Chinese, QLocale::HongKong) && 
   333         mCnPortraitInputModeList << KStrokeMode << KHwrMode;
   359         !mCnLandscapeInputModeNames.contains(KCangjieGeneralName)) {
   334         mCnLandscapeInputModeList << KStrokeMode << KCangjieNormalMode << KHwrMode;
   360 
       
   361         int index = HbInputSettingProxy::instance()->detailedCangjieMode();
       
   362         switch(index) {
       
   363         case 0:
       
   364             mCnCangjieInputMode = KCangjieEasyMode;
       
   365             break;
       
   366         case 1: 
       
   367             mCnCangjieInputMode = KCangjieNormalMode;
       
   368             break;
       
   369         case 2:
       
   370             mCnCangjieInputMode = KCangjieAdvancedMode;
       
   371             break;
       
   372         default:
       
   373             break;
       
   374         }
       
   375 
       
   376         QStringList tmpInputmodeNames;
       
   377         QList<int> tmpInputmode;
       
   378         tmpInputmodeNames << mCnLandscapeInputModeNames.at(0) << KCangjieGeneralName << mCnLandscapeInputModeNames.at(1);
       
   379         tmpInputmode << mCnLandscapeInputModeList.at(0) << mCnCangjieInputMode << mCnLandscapeInputModeList.at(1);
       
   380         mCnLandscapeInputModeList.clear();
       
   381         mCnLandscapeInputModeNames.clear();
       
   382         mCnLandscapeInputModeList = tmpInputmode;
       
   383         mCnLandscapeInputModeNames = tmpInputmodeNames;
   335         mCangjieInputModeList << KCangjieEasyMode << KCangjieNormalMode << KCangjieAdvancedMode;
   384         mCangjieInputModeList << KCangjieEasyMode << KCangjieNormalMode << KCangjieAdvancedMode;
   336         mCnPortraitInputModeNames << KStrokeName << KHwrName;
       
   337         mCnLandscapeInputModeNames << KStrokeName << KCangjieGeneralName << KHwrName;
       
   338         mCnCangjieInputModeNames << KEasy << KNormal << KAdvanced;
   385         mCnCangjieInputModeNames << KEasy << KNormal << KAdvanced;
   339     } else if (mPrimaryInputLanguage == HbInputLanguage(QLocale::Chinese, QLocale::Taiwan)) {
   386     }
   340         mCnPortraitInputModeList << KZhuyinMode << KHwrMode;
   387 
   341         mCnLandscapeInputModeList << KZhuyinMode << KHwrMode;
   388     mHwrSpeed = HbInputSettingProxy::instance()->hwrWritingSpeed();
   342         mCnPortraitInputModeNames << KZhuyinName << KHwrName;
   389     mHwrSpeedNames << KHwrVerySlowName << KHwrSlowName << KHwrNormalName << KHwrFastName << KHwrVeryFastName;
   343         mCnLandscapeInputModeNames << KZhuyinName << KHwrName;
   390     mCnDefaultLanguageNames << KDefaultChineseName << KDefaultEnglishName;
   344     }
       
   345 
   391 
   346     if (!mChineseInputGroup) {
   392     if (!mChineseInputGroup) {
   347         mChineseInputGroup = model->appendDataFormGroup(QObject::tr("Chinese Input"));
   393         mChineseInputGroup = model->appendDataFormGroup(QObject::tr("Chinese Input"));
   348         mPortraitInputMethodItem = new HbDataFormModelItem(HbDataFormModelItem::ComboBoxItem, QObject::tr("Portrait mode input method"));
   394         mPortraitInputMethodItem = new HbDataFormModelItem(HbDataFormModelItem::ComboBoxItem, QObject::tr("Portrait mode input method"));
   349         mChineseInputGroup->appendChild(mPortraitInputMethodItem);
   395         mChineseInputGroup->appendChild(mPortraitInputMethodItem);
   366         mForm->addConnection(mLandscapeInputMethodItem, SIGNAL(currentIndexChanged(int)), q, SLOT(setLandscapeInputMethod(int)));
   412         mForm->addConnection(mLandscapeInputMethodItem, SIGNAL(currentIndexChanged(int)), q, SLOT(setLandscapeInputMethod(int)));
   367 
   413 
   368         mHwrSpeedItem = new HbDataFormModelItem(HbDataFormModelItem::ComboBoxItem, QObject::tr("Handwriting speed"));
   414         mHwrSpeedItem = new HbDataFormModelItem(HbDataFormModelItem::ComboBoxItem, QObject::tr("Handwriting speed"));
   369         mChineseInputGroup->appendChild(mHwrSpeedItem);
   415         mChineseInputGroup->appendChild(mHwrSpeedItem);
   370         mHwrSpeedItem->setContentWidgetData(QString("items"), mHwrSpeedNames);
   416         mHwrSpeedItem->setContentWidgetData(QString("items"), mHwrSpeedNames);
   371         int hwr = mHwrSpeed;
   417         mHwrSpeedItem->setContentWidgetData(QString("currentIndex"), mHwrSpeed);
   372         mHwrSpeedItem->setContentWidgetData(QString("currentIndex"), hwr);
       
   373         mHwrSpeedItem->setContentWidgetData(QString("objectName"), QString("handwriting_speed"));
   418         mHwrSpeedItem->setContentWidgetData(QString("objectName"), QString("handwriting_speed"));
   374         mForm->addConnection(mHwrSpeedItem, SIGNAL(currentIndexChanged(int)), q, SLOT(setHwrSpeed(int)));
   419         mForm->addConnection(mHwrSpeedItem, SIGNAL(currentIndexChanged(int)), q, SLOT(setHwrSpeed(int)));
   375     }
   420 
   376 
   421         mCnDefaultLanguageItem = new HbDataFormModelItem(HbDataFormModelItem::ComboBoxItem, QObject::tr("Default language for keyboard input"));
       
   422         mChineseInputGroup->appendChild(mCnDefaultLanguageItem);
       
   423         int defaultLanguageIndex = HbInputSettingProxy::instance()->useWesternDefaultKeypadForChinese()?1:0;
       
   424         mCnDefaultLanguageItem->setContentWidgetData(QString("items"), mCnDefaultLanguageNames);
       
   425         mCnDefaultLanguageItem->setContentWidgetData(QString("currentIndex"), defaultLanguageIndex);
       
   426         mCnDefaultLanguageItem->setContentWidgetData(QString("objectName"), QString("default_language_for_keyboard_input"));
       
   427         mForm->addConnection(mCnDefaultLanguageItem, SIGNAL(currentIndexChanged(int)), q, SLOT(setDefaultLanguageForKeyboardInput(int)));
       
   428     }
       
   429 
       
   430     int cangjieIdx = HbInputSettingProxy::instance()->detailedCangjieMode();
   377     if (mPrimaryInputLanguage == HbInputLanguage(QLocale::Chinese, QLocale::HongKong)) {
   431     if (mPrimaryInputLanguage == HbInputLanguage(QLocale::Chinese, QLocale::HongKong)) {
   378         mCangjieItem = new HbDataFormModelItem(HbDataFormModelItem::ComboBoxItem, QObject::tr("Cangjie mode"));
   432         mCangjieItem = new HbDataFormModelItem(HbDataFormModelItem::ComboBoxItem, QObject::tr("Cangjie mode"));
   379         mChineseInputGroup->appendChild(mCangjieItem);
   433         mChineseInputGroup->appendChild(mCangjieItem);
   380         mCangjieItem->setContentWidgetData(QString("items"), mCnCangjieInputModeNames);
   434         mCangjieItem->setContentWidgetData(QString("items"), mCnCangjieInputModeNames);
   381         int cangjieIdx = inputModeToIndex(mCnCangjieInputMode, mCangjieInputModeList);
       
   382         QVariant varCang;
   435         QVariant varCang;
   383         varCang.setValue(cangjieIdx);
   436         varCang.setValue(cangjieIdx);
   384         mCangjieItem->setContentWidgetData(QString("currentIndex"), varCang);
   437         mCangjieItem->setContentWidgetData(QString("currentIndex"), varCang);
   385         mCangjieItem->setContentWidgetData(QString("objectName"), QString("cangjie_mode"));
   438         mCangjieItem->setContentWidgetData(QString("objectName"), QString("cangjie_mode"));
   386         mForm->addConnection(mCangjieItem, SIGNAL(currentIndexChanged(int)), q, SLOT(setCangjieMode(int)));
   439         mForm->addConnection(mCangjieItem, SIGNAL(currentIndexChanged(int)), q, SLOT(setCangjieMode(int)));
   387     }
   440     }
   388 }
   441 }
   389 
   442 
   390 void HbInputSettingWidgetPrivate::updateContentWidgetData()
   443 void HbInputSettingWidgetPrivate::updateContentWidgetData() 
   391 {
   444 {
   392     // current primary language
   445     // current primary language
   393     mPrimaryLanguageItem->setContentWidgetData(QString("currentIndex"), languageToIndex(mPrimaryInputLanguage, mPrimaryLanguages));
   446     mPrimaryLanguageItem->setContentWidgetData(QString("currentIndex"), languageToIndex(mPrimaryInputLanguage, mPrimaryLanguages));
   394 
   447 
   395     mSecondaryLanguageItem->setContentWidgetData(QString("currentIndex"), languageToIndex(mSecondaryInputLanguage, mSecondaryLanguages));
   448     if (mSecondaryLanguageItem) {
       
   449         mSecondaryLanguageItem->setContentWidgetData(QString("currentIndex"), languageToIndex(mSecondaryInputLanguage, mSecondaryLanguages));
       
   450     }
   396     // key press timeout
   451     // key press timeout
   397     mKeypressTimeoutItem->setContentWidgetData(QString("sliderPosition"), mKeypressTimeout);
   452     mKeypressTimeoutItem->setContentWidgetData(QString("sliderPosition"), mKeypressTimeout);
   398     if (mCharacterPreviewEnabled) {
   453     if (mCharacterPreviewEnabled) {
   399         mCharacterPreviewItem->setContentWidgetData(QString("text"), statusOn);
   454         mCharacterPreviewItem->setContentWidgetData(QString("text"), statusOn);
   400         mCharacterPreviewItem->setContentWidgetData(QString("additionalText"), statusOff);
   455         mCharacterPreviewItem->setContentWidgetData(QString("additionalText"), statusOff);
   417         mPrimaryCandidateItem->setContentWidgetData(QString("additionalText"), exactTyping);
   472         mPrimaryCandidateItem->setContentWidgetData(QString("additionalText"), exactTyping);
   418     } else {
   473     } else {
   419         mPrimaryCandidateItem->setContentWidgetData(QString("text"), exactTyping);
   474         mPrimaryCandidateItem->setContentWidgetData(QString("text"), exactTyping);
   420         mPrimaryCandidateItem->setContentWidgetData(QString("additionalText"), bestPrediction);
   475         mPrimaryCandidateItem->setContentWidgetData(QString("additionalText"), bestPrediction);
   421     }
   476     }
       
   477 
       
   478     if(mChineseInputGroup && mCnDefaultLanguageItem) {
       
   479         int defaultLanguageIndex = HbInputSettingProxy::instance()->useWesternDefaultKeypadForChinese()?1:0;
       
   480         mCnDefaultLanguageItem->setContentWidgetData(QString("currentIndex"), defaultLanguageIndex);
       
   481     }
   422 }
   482 }
   423 
   483 
   424 /*!
   484 /*!
   425 Creates setting items to this widget
   485 Creates setting items to this widget
   426 */
   486 */
   427 void HbInputSettingWidgetPrivate::createSettingItems()
   487 void HbInputSettingWidgetPrivate::createSettingItems()
   428 {
   488 {   
   429     Q_Q(HbInputSettingWidget);
   489     Q_Q(HbInputSettingWidget);
   430 
   490 
   431     mModel = new HbDataFormModel();
   491     mModel = new HbDataFormModel();
   432 
   492 
   433     HbInputCheckBoxList *customPrototype = new HbInputCheckBoxList(mForm);
   493     HbInputCheckBoxList *customPrototype = new HbInputCheckBoxList(mForm);
   612     } else {
   672     } else {
   613         return KChineseInputModeNone;
   673         return KChineseInputModeNone;
   614     }
   674     }
   615 }
   675 }
   616 
   676 
   617 QInputContextPlugin *HbInputSettingWidgetPrivate::pluginInstance(const QString &pluginFileName) const
       
   618 {
       
   619     if (QLibrary::isLibrary(pluginFileName)) {
       
   620         QPluginLoader loader(pluginFileName);
       
   621         QObject *plugin = loader.instance();
       
   622         if (plugin) {
       
   623             return qobject_cast<QInputContextPlugin *>(plugin);
       
   624         }
       
   625     }
       
   626 
       
   627     return 0;
       
   628 }
       
   629 
       
   630 HbInputMethodDescriptor HbInputSettingWidgetPrivate::findInputMethodDescriptor(const QString &inputMethodString)
       
   631 {
       
   632     HbInputMethodDescriptor descriptor;
       
   633     // Query plugin paths and scan the folders.
       
   634     QStringList folders = HbInputSettingProxy::instance()->inputMethodPluginPaths();
       
   635     foreach(const QString &folder, folders) {
       
   636         QDir dir(folder);
       
   637         for (unsigned int i = 0; i < dir.count(); i++) {
       
   638             QString path = QString(dir.absolutePath());
       
   639             if (path.right(1) != "\\" && path.right(1) != "/") {
       
   640                 path += QDir::separator();
       
   641             }
       
   642             path += inputMethodString;
       
   643             QInputContextPlugin *inputContextPlugin = pluginInstance(path);
       
   644             if (inputContextPlugin) {
       
   645                 descriptor.setPluginNameAndPath(dir.absolutePath() + QDir::separator() + inputMethodString);
       
   646 
       
   647                 // For each found plugin, check if there is already a list item for it.
       
   648                 // If not, then add one.
       
   649                 QStringList contextKeys = inputContextPlugin->keys();
       
   650                 foreach(QString key, contextKeys) {
       
   651                     descriptor.setKey(key);
       
   652                     descriptor.setDisplayName(inputContextPlugin->displayName(key));
       
   653                 }
       
   654                 break;
       
   655             }
       
   656         }
       
   657     }
       
   658     return descriptor;
       
   659 }
       
   660 
       
   661 void HbInputSettingWidgetPrivate::setInputMethodVar(Qt::Orientation orientation, QString &inputMethodString, QByteArray &customData)
       
   662 {
       
   663     int inputMode = KChineseInputModeNone;
       
   664     if (orientation == Qt::Vertical) {
       
   665         inputMode = mCnPortraitInputMode;
       
   666     } else if (orientation == Qt::Horizontal) {
       
   667         inputMode = mCnLandscapeInputMode;
       
   668     } else {
       
   669         return;
       
   670     }
       
   671 
       
   672     switch (inputMode) {
       
   673     case KPinyinMode: {
       
   674         orientation == Qt::Vertical ? inputMethodString = KCnVItutPluginName : inputMethodString = KCnVkbPluginName;
       
   675         customData.append(KPinyinName.toLatin1().data());
       
   676     }
       
   677     break;
       
   678     case KStrokeMode: {
       
   679         orientation == Qt::Vertical ? inputMethodString = KCnVItutPluginName : inputMethodString = KCnVkbPluginName;
       
   680         customData.append(KStrokeName.toLatin1().data());
       
   681     }
       
   682     break;
       
   683     case KZhuyinMode: {
       
   684         orientation == Qt::Vertical ? inputMethodString = KCnVItutPluginName : inputMethodString = KCnVkbPluginName;
       
   685         customData.append(KZhuyinName.toLatin1().data());
       
   686     }
       
   687     break;
       
   688     case KHwrMode: {
       
   689         inputMethodString = KCnHwrPluginName;
       
   690         customData.append(KHwrName.toLatin1().data());
       
   691     }
       
   692     break;
       
   693     case KCangjieNormalMode: {
       
   694         inputMethodString = KCnVkbPluginName;
       
   695         customData.append(KCangjieNormalName.toLatin1().data());
       
   696     }
       
   697     break;
       
   698     case KCangjieEasyMode: {
       
   699         inputMethodString = KCnVkbPluginName;
       
   700         customData.append(KCangjieEasyName.toLatin1().data());
       
   701     }
       
   702     break;
       
   703     case KCangjieAdvancedMode: {
       
   704         inputMethodString = KCnVkbPluginName;
       
   705         customData.append(KCangjieAdvancedName.toLatin1().data());
       
   706     }
       
   707     break;
       
   708     default:
       
   709         break;
       
   710     }
       
   711 
       
   712     QByteArray preferredCustomData = HbInputSettingProxy::instance()->preferredInputMethodCustomData(orientation);
       
   713     QString imName(preferredCustomData);
       
   714     QStringList temp = imName.split(" ");
       
   715     if (temp.count() > 1) {
       
   716         customData.append(" ");
       
   717         customData.append(temp.at(1).toLatin1().data());	
       
   718     } else {
       
   719         customData.append(" ");
       
   720         customData.append(KHwrNormalName.toLatin1().data());
       
   721     }
       
   722     customData.append((char)0);
       
   723     return;
       
   724 }
       
   725 
       
   726 QByteArray HbInputSettingWidgetPrivate::createHwrSpeedData(QByteArray preferredCustomData, int index)
       
   727 {
       
   728     QString imName(preferredCustomData);
       
   729     QStringList temp = imName.split(" ");
       
   730 
       
   731     QByteArray customData;
       
   732     customData.append(temp.at(0).toLatin1().data());
       
   733     customData.append(" ");
       
   734     switch (index) {
       
   735     case 0:
       
   736         customData.append(KHwrVerySlowName.toLatin1().data());
       
   737         break;
       
   738     case 1:
       
   739         customData.append(KHwrSlowName.toLatin1().data());
       
   740         break;
       
   741     case 2:
       
   742         customData.append(KHwrNormalName.toLatin1().data());
       
   743         break;
       
   744     case 3:
       
   745         customData.append(KHwrFastName.toLatin1().data());
       
   746         break;
       
   747     case 4:
       
   748         customData.append(KHwrVeryFastName.toLatin1().data());
       
   749         break;
       
   750     default:
       
   751         break;
       
   752     }
       
   753     customData.append((char)0);
       
   754     return customData;
       
   755 }
       
   756 
       
   757 /// @endcond
       
   758 
       
   759 /*!
   677 /*!
   760 Constructs input setting widget
   678 Constructs input setting widget
   761 */
   679 */
   762 HbInputSettingWidget::HbInputSettingWidget(HbDataForm *dataForm, QGraphicsWidget *parent)
   680 HbInputSettingWidget::HbInputSettingWidget(HbDataForm *dataForm, QGraphicsWidget *parent)
   763     : QObject(parent), d_ptr(new HbInputSettingWidgetPrivate(dataForm))
   681     : QObject(parent), d_ptr(new HbInputSettingWidgetPrivate(dataForm))
   943 
   861 
   944     HbInputSettingProxy *settings = HbInputSettingProxy::instance();
   862     HbInputSettingProxy *settings = HbInputSettingProxy::instance();
   945     HbPredictionFactory *predFactory = HbPredictionFactory::instance();
   863     HbPredictionFactory *predFactory = HbPredictionFactory::instance();
   946     bool oldPLangSupportsPrediction = (predFactory->predictionEngineForLanguage(d->mPrimaryInputLanguage) != NULL);
   864     bool oldPLangSupportsPrediction = (predFactory->predictionEngineForLanguage(d->mPrimaryInputLanguage) != NULL);
   947     d->mPrimaryInputLanguage = d->indexToLanguage(index, d->mPrimaryLanguages);
   865     d->mPrimaryInputLanguage = d->indexToLanguage(index, d->mPrimaryLanguages);
       
   866     if (d->mPrimaryInputLanguage.language() == QLocale::Chinese) {
       
   867         HbInputSettingProxy::instance()->setPreferredInputMethod(Qt::Horizontal, HbInputMethodDescriptor());
       
   868         HbInputSettingProxy::instance()->setPreferredInputMethod(Qt::Vertical, HbInputMethodDescriptor());        
       
   869     }
   948     HbInputSettingProxy::instance()->setGlobalInputLanguage(d->mPrimaryInputLanguage);
   870     HbInputSettingProxy::instance()->setGlobalInputLanguage(d->mPrimaryInputLanguage);
   949     bool langSupportsPrediction = (predFactory->predictionEngineForLanguage(d->mPrimaryInputLanguage) != NULL);
   871     bool langSupportsPrediction = (predFactory->predictionEngineForLanguage(d->mPrimaryInputLanguage) != NULL);
   950     if (oldPLangSupportsPrediction != langSupportsPrediction) {
   872     if (oldPLangSupportsPrediction != langSupportsPrediction) {
   951         if (settings->predictiveInputStatus(HbKeyboardSetting12key) != langSupportsPrediction) {
   873         if (settings->predictiveInputStatus(HbKeyboardSetting12key) != langSupportsPrediction) {
   952             settings->setPredictiveInputStatus(HbKeyboardSetting12key, langSupportsPrediction);
   874             settings->setPredictiveInputStatus(HbKeyboardSetting12key, langSupportsPrediction);
   978 
   900 
   979         HbDataFormModel *model = qobject_cast<HbDataFormModel *>(d->mForm->model());
   901         HbDataFormModel *model = qobject_cast<HbDataFormModel *>(d->mForm->model());
   980         if (d->mChineseInputGroup) {
   902         if (d->mChineseInputGroup) {
   981             model->removeItem(d->mChineseInputGroup);
   903             model->removeItem(d->mChineseInputGroup);
   982             d->mChineseInputGroup = NULL;
   904             d->mChineseInputGroup = NULL;
       
   905             HbInputSettingProxy::instance()->setPreferredInputMethod(Qt::Horizontal, HbInputMethodDescriptor());
       
   906             HbInputSettingProxy::instance()->setPreferredInputMethod(Qt::Vertical, HbInputMethodDescriptor());
   983         }
   907         }
   984     } else {
   908     } else {
   985         HbDataFormModel *model = qobject_cast<HbDataFormModel *>(d->mForm->model());
   909         HbDataFormModel *model = qobject_cast<HbDataFormModel *>(d->mForm->model());
   986         if (d->mChineseInputGroup) {
   910         if (d->mChineseInputGroup) {
   987             model->removeItem(d->mChineseInputGroup);
   911             model->removeItem(d->mChineseInputGroup);
   991         if (d->mSecondaryLanguageItem) {
   915         if (d->mSecondaryLanguageItem) {
   992             model->removeItem(d->mSecondaryLanguageItem);
   916             model->removeItem(d->mSecondaryLanguageItem);
   993             d->mSecondaryLanguageItem = NULL;
   917             d->mSecondaryLanguageItem = NULL;
   994         }
   918         }
   995 
   919 
   996         resetChineseInputMode();
   920         resetChineseInputMode(d->mPrimaryInputLanguage);
   997         d->createChineseSettingGroup(model);
   921         d->createChineseSettingGroup(model);
   998         d->mForm->setModel(model);
   922         d->mForm->setModel(model);
   999     }
   923     }
  1000 }
   924 }
  1001 
   925 
  1095 */
  1019 */
  1096 void HbInputSettingWidget::setPortraitInputMethod(int index)
  1020 void HbInputSettingWidget::setPortraitInputMethod(int index)
  1097 {
  1021 {
  1098     Q_D(HbInputSettingWidget);
  1022     Q_D(HbInputSettingWidget);
  1099     d->mCnPortraitInputMode = d->indexToInputmode(index, d->mCnPortraitInputModeList);
  1023     d->mCnPortraitInputMode = d->indexToInputmode(index, d->mCnPortraitInputModeList);
  1100     QString inputMethodString;
       
  1101     QByteArray customData;
  1024     QByteArray customData;
  1102     d->setInputMethodVar(Qt::Vertical, inputMethodString, customData);
  1025     HbInputMethodDescriptor descriptor;
  1103 
  1026 
  1104     const HbInputMethodDescriptor descriptor = d->findInputMethodDescriptor(inputMethodString);
  1027     if (d->mCnPortraitInputMode != KHwrMode) {
  1105     HbInputSettingProxy::instance()->setPreferredInputMethod(Qt::Vertical, (const HbInputMethodDescriptor &)descriptor, customData);
  1028         QString imName = d->inputModeName(d->mCnPortraitInputMode);
       
  1029         customData.append(imName.toLatin1().data());
       
  1030         customData.append((char)0);
       
  1031         descriptor = HbInputMethod::defaultInputMethod(Qt::Vertical);
       
  1032     } else {
       
  1033         customData.append(KHwrName.toLatin1().data());
       
  1034         customData.append((char)0);
       
  1035         QList<HbInputMethodDescriptor> methodList = HbInputMethod::listCustomInputMethods(Qt::Vertical, HbInputSettingProxy::instance()->globalInputLanguage());
       
  1036         foreach(const HbInputMethodDescriptor &des, methodList) {
       
  1037             if (des.displayName() == "Chinese Hand Writing Recognition") {
       
  1038                 descriptor = des;
       
  1039                 break;
       
  1040             }
       
  1041         }
       
  1042     }
       
  1043 
       
  1044     Qt::Orientation orientation = Qt::Vertical;
       
  1045     if (d->mForm) {
       
  1046         orientation = d->mForm->mainWindow()->orientation();
       
  1047     }
       
  1048 
       
  1049     HbInputSettingProxy::instance()->setPreferredInputMethod(Qt::Vertical, descriptor, customData);
       
  1050     if (orientation == Qt::Vertical) {
       
  1051         HbInputMethod::activeInputMethod()->activateInputMethod(descriptor);
       
  1052     }
  1106 }
  1053 }
  1107 
  1054 
  1108 /*!
  1055 /*!
  1109 Saves the landscape input method
  1056 Saves the landscape input method
  1110 */
  1057 */
  1111 void HbInputSettingWidget::setLandscapeInputMethod(int index)
  1058 void HbInputSettingWidget::setLandscapeInputMethod(int index)
  1112 {
  1059 {
  1113     Q_D(HbInputSettingWidget);
  1060     Q_D(HbInputSettingWidget);
  1114     d->mCnLandscapeInputMode = d->indexToInputmode(index, d->mCnLandscapeInputModeList);
  1061     d->mCnLandscapeInputMode = d->indexToInputmode(index, d->mCnLandscapeInputModeList);
  1115     QString inputMethodString;
       
  1116     QByteArray customData;
  1062     QByteArray customData;
  1117     d->setInputMethodVar(Qt::Horizontal, inputMethodString, customData);
  1063     HbInputMethodDescriptor descriptor;
  1118 
  1064 
  1119     const HbInputMethodDescriptor descriptor = d->findInputMethodDescriptor(inputMethodString);
  1065     if (d->mCnLandscapeInputMode != KHwrMode) {
       
  1066         QString imName;
       
  1067         if (d->mCnLandscapeInputMode == KCangjieNormalMode || 
       
  1068             d->mCnLandscapeInputMode == KCangjieEasyMode  || 
       
  1069             d->mCnLandscapeInputMode == KCangjieAdvancedMode) {
       
  1070             imName = KCangjieGeneralName;
       
  1071         } else {
       
  1072             imName = d->inputModeName(d->mCnLandscapeInputMode);
       
  1073         }
       
  1074 
       
  1075         customData.append(imName.toLatin1().data());
       
  1076         customData.append((char)0);
       
  1077         descriptor = HbInputMethod::defaultInputMethod(Qt::Horizontal);
       
  1078     } else {
       
  1079         customData.append(KHwrName.toLatin1().data());
       
  1080         customData.append((char)0);
       
  1081         QList<HbInputMethodDescriptor> methodList = HbInputMethod::listCustomInputMethods(Qt::Horizontal, HbInputSettingProxy::instance()->globalInputLanguage());
       
  1082         foreach(const HbInputMethodDescriptor &des, methodList) {
       
  1083             if (des.displayName() == "Chinese Hand Writing Recognition") {
       
  1084                 descriptor = des;
       
  1085                 break;
       
  1086             }
       
  1087         }
       
  1088     }
       
  1089 
       
  1090     Qt::Orientation orientation = Qt::Horizontal;
       
  1091     if (d->mForm) {
       
  1092         orientation = d->mForm->mainWindow()->orientation();
       
  1093     }
       
  1094 
  1120     HbInputSettingProxy::instance()->setPreferredInputMethod(Qt::Horizontal, descriptor, customData);
  1095     HbInputSettingProxy::instance()->setPreferredInputMethod(Qt::Horizontal, descriptor, customData);
       
  1096     if (orientation == Qt::Horizontal) {
       
  1097         HbInputMethod::activeInputMethod()->activateInputMethod(descriptor);
       
  1098     }
  1121 }
  1099 }
  1122 
  1100 
  1123 /*!
  1101 /*!
  1124 Saves the cangjie input mode
  1102 Saves the cangjie input mode
  1125 */
  1103 */
  1127 {
  1105 {
  1128     Q_D(HbInputSettingWidget);
  1106     Q_D(HbInputSettingWidget);
  1129     d->mCnCangjieInputMode = d->indexToInputmode(index, d->mCangjieInputModeList);
  1107     d->mCnCangjieInputMode = d->indexToInputmode(index, d->mCangjieInputModeList);
  1130     d->mCnLandscapeInputMode = d->mCnCangjieInputMode;
  1108     d->mCnLandscapeInputMode = d->mCnCangjieInputMode;
  1131 
  1109 
  1132     QString inputMethodString;
  1110     QString imName = KCangjieGeneralName;
  1133     QByteArray customData;
  1111     QByteArray customData;
  1134     d->setInputMethodVar(Qt::Horizontal, inputMethodString, customData);
  1112     customData.append(imName.toLatin1().data());
  1135 
  1113     customData.append((char)0);
  1136     const HbInputMethodDescriptor descriptor = d->findInputMethodDescriptor(inputMethodString);
  1114 
       
  1115     HbInputMethodDescriptor descriptor;
       
  1116     descriptor = HbInputMethod::defaultInputMethod(Qt::Horizontal);
       
  1117      
  1137     HbInputSettingProxy::instance()->setPreferredInputMethod(Qt::Horizontal, descriptor, customData);
  1118     HbInputSettingProxy::instance()->setPreferredInputMethod(Qt::Horizontal, descriptor, customData);
  1138 }
  1119     HbInputSettingProxy::instance()->setDetailedCangjieMode(HbCangjieDetailMode(index));
  1139 
  1120 }
  1140 
  1121 
  1141 /*!
  1122 /*!
  1142 Saves the handwriting speed
  1123 Saves the handwriting speed
  1143 */
  1124 */
  1144 void HbInputSettingWidget::setHwrSpeed(int index)
  1125 void HbInputSettingWidget::setHwrSpeed(int index)
  1145 {
  1126 {
  1146     Q_D(HbInputSettingWidget);
  1127     // hwr speed index in setting widget are exactly same as enum HbHwrWritingSpeed of setting proxy
  1147     Qt::Orientation currentOrientation = HbInputSettingProxy::instance()->screenOrientation();
  1128     if (index >= 0 && index < KHwrSpeedCount) {
  1148     QByteArray portraitCustomData = HbInputSettingProxy::instance()->preferredInputMethodCustomData(Qt::Vertical);
  1129         HbInputSettingProxy::instance()->setHwrWritingSpeed(HbHwrWritingSpeed(index));
  1149     QByteArray landscapeCustomData = HbInputSettingProxy::instance()->preferredInputMethodCustomData(Qt::Horizontal);
       
  1150     HbInputMethodDescriptor portraitDes = HbInputSettingProxy::instance()->preferredInputMethod(Qt::Vertical);
       
  1151     HbInputMethodDescriptor landscapeDes = HbInputSettingProxy::instance()->preferredInputMethod(Qt::Horizontal);
       
  1152     QByteArray portraitHwrspeed = d->createHwrSpeedData(portraitCustomData, index);
       
  1153     QByteArray landscapeHwrspeed = d->createHwrSpeedData(landscapeCustomData, index);
       
  1154 
       
  1155     if (currentOrientation == Qt::Vertical) {
       
  1156         HbInputSettingProxy::instance()->setPreferredInputMethod(Qt::Horizontal, landscapeDes, landscapeHwrspeed);
       
  1157         HbInputSettingProxy::instance()->setPreferredInputMethod(Qt::Vertical, portraitDes, portraitHwrspeed);
       
  1158 
       
  1159     } if (currentOrientation == Qt::Horizontal) {
       
  1160         HbInputSettingProxy::instance()->setPreferredInputMethod(Qt::Vertical, portraitDes, portraitHwrspeed);
       
  1161         HbInputSettingProxy::instance()->setPreferredInputMethod(Qt::Horizontal, landscapeDes, landscapeHwrspeed);
       
  1162     }
  1130     }
  1163 }
  1131 }
  1164 
  1132 
  1165 /*!
  1133 /*!
  1166 Saves the portrait input method
  1134 Saves the portrait input method
  1167 */
  1135 */
  1168 void HbInputSettingWidget::resetChineseInputMode()
  1136 void HbInputSettingWidget::resetChineseInputMode(HbInputLanguage lang)
  1169 {
  1137 {
  1170     Q_D(HbInputSettingWidget);
  1138     Q_D(HbInputSettingWidget);
  1171     HbInputLanguage lang = HbInputSettingProxy::instance()->globalInputLanguage();
  1139     d->mCnPortraitInputMode = d->defaultModeByGivenLang(lang);
  1172 
  1140     d->mCnLandscapeInputMode = d->defaultModeByGivenLang(lang);
  1173     if (lang.variant() == QLocale::China) {
  1141     HbInputSettingProxy::instance()->setDetailedCangjieMode(HbCangjieNormal);
  1174         d->mCnPortraitInputMode = KPinyinMode;
  1142 
  1175         d->mCnLandscapeInputMode = KPinyinMode;
       
  1176     } else if (lang.variant() == QLocale::HongKong) {
       
  1177         d->mCnPortraitInputMode = KStrokeMode;
       
  1178         d->mCnLandscapeInputMode = KStrokeMode;
       
  1179     } else if (lang.variant() == QLocale::Taiwan) {
       
  1180         d->mCnPortraitInputMode = KZhuyinMode;
       
  1181         d->mCnLandscapeInputMode = KZhuyinMode;
       
  1182     }
       
  1183 
       
  1184     QString portraitInputMethodString;
       
  1185     QString landscapeInputMethodString;
       
  1186     QByteArray portraitCustomData;
  1143     QByteArray portraitCustomData;
  1187     QByteArray landscapeCustomData;
  1144     QByteArray landscapeCustomData;
  1188     d->setInputMethodVar(Qt::Vertical, portraitInputMethodString, portraitCustomData);
  1145     QString imName = d->inputModeName(d->mCnPortraitInputMode);
  1189     d->setInputMethodVar(Qt::Horizontal, landscapeInputMethodString, landscapeCustomData);
  1146     portraitCustomData.append(imName.toLatin1().data());
  1190 
  1147     portraitCustomData.append((char)0);
  1191     const HbInputMethodDescriptor portraitDescriptor = d->findInputMethodDescriptor(portraitInputMethodString);
  1148     HbInputMethodDescriptor portraitDescriptor = HbInputMethod::defaultInputMethod(Qt::Vertical);
  1192     const HbInputMethodDescriptor landscapeDescriptor = d->findInputMethodDescriptor(landscapeInputMethodString);
  1149 
       
  1150     if (d->mCnLandscapeInputMode == KCangjieNormalMode || 
       
  1151         d->mCnLandscapeInputMode == KCangjieEasyMode || 
       
  1152         d->mCnLandscapeInputMode == KCangjieAdvancedMode) {
       
  1153         imName = KCangjieGeneralName;
       
  1154     } else {
       
  1155         imName = d->inputModeName(d->mCnLandscapeInputMode);
       
  1156     }
       
  1157 
       
  1158     landscapeCustomData.append(imName.toLatin1().data());
       
  1159     landscapeCustomData.append((char)0);
       
  1160     HbInputMethodDescriptor landscapeDescriptor = HbInputMethod::defaultInputMethod(Qt::Horizontal);
       
  1161 
  1193     HbInputSettingProxy::instance()->setPreferredInputMethod(Qt::Vertical, (const HbInputMethodDescriptor &)portraitDescriptor, portraitCustomData);
  1162     HbInputSettingProxy::instance()->setPreferredInputMethod(Qt::Vertical, (const HbInputMethodDescriptor &)portraitDescriptor, portraitCustomData);
  1194     HbInputSettingProxy::instance()->setPreferredInputMethod(Qt::Horizontal, (const HbInputMethodDescriptor &)landscapeDescriptor, landscapeCustomData);
  1163     HbInputSettingProxy::instance()->setPreferredInputMethod(Qt::Horizontal, (const HbInputMethodDescriptor &)landscapeDescriptor, landscapeCustomData);
       
  1164 
       
  1165     return;
  1195 }
  1166 }
  1196 
  1167 
  1197 /*
  1168 /*
  1198     This slot is called when ever data in the form model is changed
  1169     This slot is called when ever data in the form model is changed
  1199 */
  1170 */
  1224     disconnect(settings, SIGNAL(autocompletionStateChanged(HbKeyboardSettingFlags, bool)), this, SLOT(updateAutocompletionState(HbKeyboardSettingFlags, bool)));
  1195     disconnect(settings, SIGNAL(autocompletionStateChanged(HbKeyboardSettingFlags, bool)), this, SLOT(updateAutocompletionState(HbKeyboardSettingFlags, bool)));
  1225     disconnect(settings, SIGNAL(typingCorrectionLevelChanged(HbTypingCorrectionLevel)), this, SLOT(updateTypingCorrectionLevel(HbTypingCorrectionLevel)));
  1196     disconnect(settings, SIGNAL(typingCorrectionLevelChanged(HbTypingCorrectionLevel)), this, SLOT(updateTypingCorrectionLevel(HbTypingCorrectionLevel)));
  1226     disconnect(settings, SIGNAL(primaryCandidateModeChanged(HbPrimaryCandidateMode)), this, SLOT(updatePrimaryCandidateMode(HbPrimaryCandidateMode)));
  1197     disconnect(settings, SIGNAL(primaryCandidateModeChanged(HbPrimaryCandidateMode)), this, SLOT(updatePrimaryCandidateMode(HbPrimaryCandidateMode)));
  1227 }
  1198 }
  1228 
  1199 
       
  1200 /*!
       
  1201 Set default language for keyboard input
       
  1202 */
       
  1203 void HbInputSettingWidget::setDefaultLanguageForKeyboardInput(int index)
       
  1204 {
       
  1205     if(index == 1) {
       
  1206         HbInputSettingProxy::instance()->setWesternDefaultKeypadForChinese(true);
       
  1207     } else {
       
  1208         HbInputSettingProxy::instance()->setWesternDefaultKeypadForChinese(false);
       
  1209     }
       
  1210 }
       
  1211 
  1229 // End of file
  1212 // End of file