src/hbinput/inputwidgets/hbinputsettingwidget.cpp
changeset 34 ed14f46c0e55
parent 7 923ff622b8b9
equal deleted inserted replaced
31:7516d6d86cf5 34:ed14f46c0e55
    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>
       
    45 
       
    46 /*!
       
    47 @stable
       
    48 @hbinput
       
    49 \class HbInputSettingWidget
       
    50 \brief Displays settings for Hb inputs.
       
    51 
       
    52 This is a input settings widget to be embedded in e.g. control panel view or input settings popup.
       
    53 */
    41 
    54 
    42 const QString statusOff = QObject::tr("Off");
    55 const QString statusOff = QObject::tr("Off");
    43 const QString statusOn = QObject::tr("On");
    56 const QString statusOn = QObject::tr("On");
    44 const QString bestPrediction = QObject::tr("Best prediction");
    57 const QString bestPrediction = QObject::tr("Best prediction");
    45 const QString exactTyping = QObject::tr("Exact typing");
    58 const QString exactTyping = QObject::tr("Exact typing");
    51 const QString KZhuyinName("Zhuyin");
    64 const QString KZhuyinName("Zhuyin");
    52 const QString KCangjieNormalName("CangjieNormal");
    65 const QString KCangjieNormalName("CangjieNormal");
    53 const QString KCangjieEasyName("CangjieEasy");
    66 const QString KCangjieEasyName("CangjieEasy");
    54 const QString KCangjieAdvancedName("CangjieAdvanced");
    67 const QString KCangjieAdvancedName("CangjieAdvanced");
    55 const QString KHwrName("Handwriting");
    68 const QString KHwrName("Handwriting");
    56 const QString KHwrVerySlowName("VerySlow");
    69 const QString KHwrVerySlowName("Very Slow");
    57 const QString KHwrSlowName("Slow");
    70 const QString KHwrSlowName("Slow");
    58 const QString KHwrNormalName("Normal");
    71 const QString KHwrNormalName("Normal");
    59 const QString KHwrFastName("Fast");
    72 const QString KHwrFastName("Fast");
    60 const QString KHwrVeryFastName("VeryFast");
    73 const QString KHwrVeryFastName("Very Fast");
       
    74 
       
    75 // strings used for default language
       
    76 const QString KDefaultChineseName("Chinese");
       
    77 const QString KDefaultEnglishName("English");
       
    78 
       
    79 // hwr speed index are exactly saming as enum HbHwrWritingSpeed
       
    80 const int KHwrSpeedCount = 5;
    61 
    81 
    62 // strings used for represent cangjie
    82 // strings used for represent cangjie
    63 const QString KCangjieGeneralName("Cangjie");
    83 const QString KCangjieGeneralName("Cangjie");
    64 const QString KEasy("Easy");
    84 const QString KEasy("Easy");
    65 const QString KNormal("Normal");
    85 const QString KNormal("Normal");
    73 const int KCangjieNormalMode = 3;
    93 const int KCangjieNormalMode = 3;
    74 const int KCangjieEasyMode = 4;
    94 const int KCangjieEasyMode = 4;
    75 const int KCangjieAdvancedMode = 5;
    95 const int KCangjieAdvancedMode = 5;
    76 const int KHwrMode = 6;
    96 const int KHwrMode = 6;
    77 
    97 
    78 // define chinese input plugin name
    98 class HbCnInputModeMap
    79 #ifdef Q_OS_WIN
    99 {
    80 const QString KCnHwrPluginName("HbChineseHwrd.dll");
   100 public:
    81 #else
   101     int mMode;
    82 #ifdef Q_OS_SYMBIAN
   102     QString mModeName;
    83 const QString KCnHwrPluginName("HbChineseHwr.qtplugin");
   103 };
    84 #else
   104 
    85 const QString KCnHwrPluginName("HbChineseHwr.dll");
   105 const HbCnInputModeMap modesMap[] = {
    86 #endif
   106     {KPinyinMode, KPinyinName},
    87 #endif
   107     {KStrokeMode, KStrokeName},
    88 
   108     {KZhuyinMode, KZhuyinName},
    89 #ifdef Q_OS_WIN
   109     {KCangjieNormalMode, KCangjieNormalName},
    90 const QString KCnVItutPluginName("HbChineseVItutd.dll");
   110     {KCangjieEasyMode, KCangjieEasyName},
    91 #else
   111     {KCangjieAdvancedMode, KCangjieAdvancedName},
    92 #ifdef Q_OS_SYMBIAN
   112     {KHwrMode, KHwrName}
    93 const QString KCnVItutPluginName("HbChineseVItut.qtplugin");
   113 };
    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 
   114 
   109 class HbInputSettingWidgetPrivate
   115 class HbInputSettingWidgetPrivate
   110 {
   116 {
   111     Q_DECLARE_PUBLIC(HbInputSettingWidget)
   117     Q_DECLARE_PUBLIC(HbInputSettingWidget)
   112 
   118 
   118     void fillLanguageList(QStringList &list, QList<HbInputLanguage> &languageList, const QString &replace = QString(" "));
   124     void fillLanguageList(QStringList &list, QList<HbInputLanguage> &languageList, const QString &replace = QString(" "));
   119     int languageToIndex(const HbInputLanguage &language, const QList<HbInputLanguage> &languageList);
   125     int languageToIndex(const HbInputLanguage &language, const QList<HbInputLanguage> &languageList);
   120     HbInputLanguage indexToLanguage(int index, const QList<HbInputLanguage> &languageList);
   126     HbInputLanguage indexToLanguage(int index, const QList<HbInputLanguage> &languageList);
   121     void createSecondaryLanguageList();
   127     void createSecondaryLanguageList();
   122     void updateContentWidgetData();
   128     void updateContentWidgetData();
       
   129     // following API used by chinese
   123     int inputModeToIndex(const int &inputMode, const QList<int> &inputModeList);
   130     int inputModeToIndex(const int &inputMode, const QList<int> &inputModeList);
   124     int indexToInputmode(int index, const QList<int> &inputModeList);
   131     int indexToInputmode(int index, const QList<int> &inputModeList);
   125     void createChineseSettingGroup(HbDataFormModel *model);
   132     void createChineseSettingGroup(HbDataFormModel *model);
   126 
   133     void createValidModesList(QStringList &imModeNames, QList<int> &imModeList);
   127     QInputContextPlugin *pluginInstance(const QString &pluginFileName) const;
   134     QString inputModeName(int mode) const;
   128     HbInputMethodDescriptor findInputMethodDescriptor(const QString &inputMethodString);
   135     int inputModeByGivenName(const QString& imName) const;
   129     void setInputMethodVar(Qt::Orientation orientation, QString &inputMethodString, QByteArray &num);
   136     int defaultModeByGivenLang(const HbInputLanguage &lang) const;
   130     QByteArray createHwrSpeedData(QByteArray preferredCustomData, int index);
   137 
   131 public:
   138 public:  
   132     HbDataForm *mForm;
   139     HbDataForm *mForm;
   133     HbDataFormModelItem *mPrimaryLanguageItem;
   140     HbDataFormModelItem *mPrimaryLanguageItem;
   134     HbDataFormModelItem *mSecondaryLanguageItem;
   141     HbDataFormModelItem *mSecondaryLanguageItem;
   135     HbDataFormModelItem *mKeypressTimeoutItem;
   142     HbDataFormModelItem *mKeypressTimeoutItem;
   136     HbDataFormModelItem *mCharacterPreviewItem;
   143     HbDataFormModelItem *mCharacterPreviewItem;
   162     HbDataFormModelItem *mCangjieItem;
   169     HbDataFormModelItem *mCangjieItem;
   163     int mCnPortraitInputMode;
   170     int mCnPortraitInputMode;
   164     int mCnLandscapeInputMode;
   171     int mCnLandscapeInputMode;
   165     int mCnCangjieInputMode;
   172     int mCnCangjieInputMode;
   166 
   173 
   167     int mHwrSpeed;
   174     HbHwrWritingSpeed  mHwrSpeed;
   168     QList<int> mCnPortraitInputModeList;
   175     QList<int> mCnPortraitInputModeList;
   169     QList<int> mCnLandscapeInputModeList;
   176     QList<int> mCnLandscapeInputModeList;
   170     QList<int> mCangjieInputModeList;
   177     QList<int> mCangjieInputModeList;
   171     QStringList mCnPortraitInputModeNames;
   178     QStringList mCnPortraitInputModeNames;
   172     QStringList mCnLandscapeInputModeNames;
   179     QStringList mCnLandscapeInputModeNames;
   173     QStringList mCnCangjieInputModeNames;
   180     QStringList mCnCangjieInputModeNames;
   174     QStringList mHwrSpeedNames;
   181     QStringList mHwrSpeedNames;
       
   182     QStringList mCnDefaultLanguageNames;
       
   183     HbDataFormModelItem *mCnDefaultLanguageItem;
   175 };
   184 };
   176 
   185 
   177 /*!
   186 /*!
   178 Constructs setting widget
   187 Constructs setting widget
   179 */
   188 */
   188       mCorrectionLevelItem(0),
   197       mCorrectionLevelItem(0),
   189       mPrimaryCandidateItem(0),
   198       mPrimaryCandidateItem(0),
   190       q_ptr(0),
   199       q_ptr(0),
   191       mModel(0),
   200       mModel(0),
   192       mLanguageGroup(0),
   201       mLanguageGroup(0),
   193       mChineseInputGroup(0),
   202       mChineseInputGroup(0),      
   194       mPortraitInputMethodItem(0),
   203       mPortraitInputMethodItem(0),
   195       mLandscapeInputMethodItem(0),
   204       mLandscapeInputMethodItem(0),
   196       mHwrSpeedItem(0),
   205       mHwrSpeedItem(0),
   197       mCangjieItem(0)
   206       mCangjieItem(0),      
       
   207       mCnCangjieInputMode(KCangjieNormalMode),
       
   208       mCnDefaultLanguageItem(0)
       
   209 
   198 {
   210 {
   199 }
   211 }
   200 
   212 
   201 /*!
   213 /*!
   202 Initializes setting widget
   214 Initializes setting widget
   222         createSettingItems();
   234         createSettingItems();
   223     } else {
   235     } else {
   224         // simply update the settings dependant content widget data of all the items
   236         // simply update the settings dependant content widget data of all the items
   225         updateContentWidgetData();
   237         updateContentWidgetData();
   226         //make sure that the items are not expanded
   238         //make sure that the items are not expanded
   227         QModelIndex index = mModel->indexFromItem(mSecondaryLanguageItem->parent());
   239         QModelIndex index = mModel->indexFromItem(mSecondaryLanguageItem ? mSecondaryLanguageItem->parent(): mPrimaryLanguageItem->parent());
   228         mForm->setExpanded(index, false);
   240         mForm->setExpanded(index, false);
   229         index = mModel->indexFromItem(mKeypressTimeoutItem->parent());
   241         index = mModel->indexFromItem(mKeypressTimeoutItem->parent());
   230         mForm->setExpanded(index, false);
   242         mForm->setExpanded(index, false);
   231         index = mModel->indexFromItem(mPredictionItem->parent());
   243         index = mModel->indexFromItem(mPredictionItem->parent());
   232         mForm->setExpanded(index, false);        
   244         mForm->setExpanded(index, false);        
   233     }
   245     }
   234 }
   246 }
   235 
   247 
       
   248 void HbInputSettingWidgetPrivate::createValidModesList(QStringList &imModeNames, QList<int> &imModeList)
       
   249 {    
       
   250     Qt::Orientation orientation = Qt::Horizontal;
       
   251     if (mForm) {
       
   252        orientation = mForm->mainWindow()->orientation();
       
   253     }
       
   254 
       
   255     QList<HbInputMethodDescriptor> methodList = HbInputMethod::listCustomInputMethods(orientation,
       
   256         HbInputSettingProxy::instance()->globalInputLanguage());
       
   257     methodList.insert(0, HbInputMethod::defaultInputMethod(orientation));
       
   258 
       
   259     foreach(const HbInputMethodDescriptor &des, methodList) {
       
   260         QStringList displayNames = des.displayNames();
       
   261         if (!displayNames.isEmpty()) {
       
   262             imModeNames += displayNames;
       
   263         } else {
       
   264             QString displayName = des.displayName();
       
   265             imModeNames.append(displayName);
       
   266         }
       
   267     }
       
   268 
       
   269     imModeNames.removeDuplicates();
       
   270     // filter out the input mode that not valid to current screen orientation
       
   271     if (imModeNames.contains(KCangjieGeneralName)) {
       
   272         imModeNames.removeOne(KCangjieGeneralName);
       
   273     }
       
   274 
       
   275     for (int i = 0; i < imModeNames.count(); ++i) {
       
   276         imModeList.append(inputModeByGivenName(imModeNames.at(i)));
       
   277     }
       
   278 }
       
   279 
       
   280 QString HbInputSettingWidgetPrivate::inputModeName(int mode) const
       
   281 {
       
   282     int cnImCnts = sizeof(modesMap) / sizeof(modesMap[0]);
       
   283     if (mode >= 0 && mode < cnImCnts) {
       
   284         return modesMap[mode].mModeName;
       
   285     }
       
   286 
       
   287     return QString();
       
   288 }
       
   289 
       
   290 int HbInputSettingWidgetPrivate::inputModeByGivenName(const QString& imName) const
       
   291 {
       
   292     int cnMode = KChineseInputModeNone;
       
   293 
       
   294     if (imName == KCangjieGeneralName) {
       
   295         HbCangjieDetailMode cjDetail = HbInputSettingProxy::instance()->detailedCangjieMode();
       
   296         switch (cjDetail) {
       
   297         case HbCangjieEasy: {
       
   298             cnMode = KCangjieEasyMode;
       
   299         }
       
   300             break;
       
   301         case HbCangjieAdvanced: {
       
   302             cnMode = KCangjieAdvancedMode;
       
   303         }
       
   304             break;
       
   305         case HbCangjieNormal: 
       
   306         default: {
       
   307             cnMode = KCangjieNormalMode;
       
   308         }
       
   309             break;
       
   310         }
       
   311     } else {
       
   312         int cnImCnts = sizeof(modesMap) / sizeof(modesMap[0]);
       
   313         for (int i = 0; i < cnImCnts; ++i) {
       
   314             if (modesMap[i].mModeName == imName) {
       
   315                 cnMode = modesMap[i].mMode;
       
   316             }
       
   317         }
       
   318     }
       
   319 
       
   320     if (KChineseInputModeNone == cnMode) {
       
   321         HbInputLanguage lang = HbInputSettingProxy::instance()->globalInputLanguage();
       
   322         cnMode = defaultModeByGivenLang(lang);
       
   323     }
       
   324     
       
   325     return cnMode;
       
   326 }
       
   327 
       
   328 int HbInputSettingWidgetPrivate::defaultModeByGivenLang(const HbInputLanguage &lang) const
       
   329 {
       
   330     int imMode = KChineseInputModeNone;
       
   331     if (lang.variant() == QLocale::China) {
       
   332         imMode = KPinyinMode;
       
   333     } else if (lang.variant() == QLocale::HongKong) {
       
   334         imMode = KStrokeMode;
       
   335     } else if (lang.variant() == QLocale::Taiwan) {
       
   336         imMode = KZhuyinMode;
       
   337     }
       
   338 
       
   339     return imMode;
       
   340 }
       
   341 
   236 void HbInputSettingWidgetPrivate::createChineseSettingGroup(HbDataFormModel *model)
   342 void HbInputSettingWidgetPrivate::createChineseSettingGroup(HbDataFormModel *model)
   237 {
   343 {
   238     Q_Q(HbInputSettingWidget);
   344     Q_Q(HbInputSettingWidget);
   239     int imMode = KChineseInputModeNone;
       
   240     QByteArray ba = HbInputSettingProxy::instance()->preferredInputMethodCustomData(Qt::Vertical);
   345     QByteArray ba = HbInputSettingProxy::instance()->preferredInputMethodCustomData(Qt::Vertical);
   241     QString portraitCustomData(ba);
   346     QString imName(ba);
   242     QString imName = portraitCustomData.split(" ").at(0);
       
   243     HbInputLanguage lang = HbInputSettingProxy::instance()->globalInputLanguage();
   347     HbInputLanguage lang = HbInputSettingProxy::instance()->globalInputLanguage();
   244 
   348     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 
   349 
   265     ba = HbInputSettingProxy::instance()->preferredInputMethodCustomData(Qt::Horizontal);
   350     ba = HbInputSettingProxy::instance()->preferredInputMethodCustomData(Qt::Horizontal);
   266     QString landscapeCustomData(ba);
   351     imName = QString(ba);
   267     imName = landscapeCustomData.split(" ").at(0);
   352     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 
   353 
   319     mHwrSpeedNames.clear();
   354     mHwrSpeedNames.clear();
   320     mCnPortraitInputModeList.clear();
   355     mCnPortraitInputModeList.clear();
   321     mCnLandscapeInputModeList.clear();
   356     mCnLandscapeInputModeList.clear();
   322     mCnPortraitInputModeNames.clear();
   357     mCnPortraitInputModeNames.clear();
   323     mCnLandscapeInputModeNames.clear();
   358     mCnLandscapeInputModeNames.clear();
   324     mCnCangjieInputModeNames.clear();
   359     mCnCangjieInputModeNames.clear();
   325 
   360     mCnDefaultLanguageNames.clear();
   326     mHwrSpeedNames << "Very slow" << "Slow" << "Normal" << "Fast" << "Very Fast";
   361 
   327     if (mPrimaryInputLanguage == HbInputLanguage(QLocale::Chinese, QLocale::China)) {
   362     createValidModesList(mCnPortraitInputModeNames, mCnPortraitInputModeList);
   328         mCnPortraitInputModeList << KPinyinMode << KStrokeMode << KHwrMode;
   363     mCnLandscapeInputModeNames = mCnPortraitInputModeNames;
   329         mCnLandscapeInputModeList << KPinyinMode << KStrokeMode << KHwrMode;
   364     mCnLandscapeInputModeList = mCnPortraitInputModeList;
   330         mCnPortraitInputModeNames << KPinyinName << KStrokeName << KHwrName;
   365 
   331         mCnLandscapeInputModeNames << KPinyinName << KStrokeName << KHwrName;
   366     // append cangjie to landscape related list if need
   332     } else if (mPrimaryInputLanguage == HbInputLanguage(QLocale::Chinese, QLocale::HongKong)) {
   367     if (mPrimaryInputLanguage == HbInputLanguage(QLocale::Chinese, QLocale::HongKong) && 
   333         mCnPortraitInputModeList << KStrokeMode << KHwrMode;
   368         !mCnLandscapeInputModeNames.contains(KCangjieGeneralName)) {
   334         mCnLandscapeInputModeList << KStrokeMode << KCangjieNormalMode << KHwrMode;
   369 
       
   370         int index = HbInputSettingProxy::instance()->detailedCangjieMode();
       
   371         switch(index) {
       
   372         case 0:
       
   373             mCnCangjieInputMode = KCangjieEasyMode;
       
   374             break;
       
   375         case 1: 
       
   376             mCnCangjieInputMode = KCangjieNormalMode;
       
   377             break;
       
   378         case 2:
       
   379             mCnCangjieInputMode = KCangjieAdvancedMode;
       
   380             break;
       
   381         default:
       
   382             break;
       
   383         }
       
   384 
       
   385         QStringList tmpInputmodeNames;
       
   386         QList<int> tmpInputmode;
       
   387         tmpInputmodeNames << mCnLandscapeInputModeNames.at(0) << KCangjieGeneralName << mCnLandscapeInputModeNames.at(1);
       
   388         tmpInputmode << mCnLandscapeInputModeList.at(0) << mCnCangjieInputMode << mCnLandscapeInputModeList.at(1);
       
   389         mCnLandscapeInputModeList.clear();
       
   390         mCnLandscapeInputModeNames.clear();
       
   391         mCnLandscapeInputModeList = tmpInputmode;
       
   392         mCnLandscapeInputModeNames = tmpInputmodeNames;
   335         mCangjieInputModeList << KCangjieEasyMode << KCangjieNormalMode << KCangjieAdvancedMode;
   393         mCangjieInputModeList << KCangjieEasyMode << KCangjieNormalMode << KCangjieAdvancedMode;
   336         mCnPortraitInputModeNames << KStrokeName << KHwrName;
       
   337         mCnLandscapeInputModeNames << KStrokeName << KCangjieGeneralName << KHwrName;
       
   338         mCnCangjieInputModeNames << KEasy << KNormal << KAdvanced;
   394         mCnCangjieInputModeNames << KEasy << KNormal << KAdvanced;
   339     } else if (mPrimaryInputLanguage == HbInputLanguage(QLocale::Chinese, QLocale::Taiwan)) {
   395     }
   340         mCnPortraitInputModeList << KZhuyinMode << KHwrMode;
   396 
   341         mCnLandscapeInputModeList << KZhuyinMode << KHwrMode;
   397     mHwrSpeed = HbInputSettingProxy::instance()->hwrWritingSpeed();
   342         mCnPortraitInputModeNames << KZhuyinName << KHwrName;
   398     mHwrSpeedNames << KHwrVerySlowName << KHwrSlowName << KHwrNormalName << KHwrFastName << KHwrVeryFastName;
   343         mCnLandscapeInputModeNames << KZhuyinName << KHwrName;
   399     mCnDefaultLanguageNames << KDefaultChineseName << KDefaultEnglishName;
   344     }
       
   345 
   400 
   346     if (!mChineseInputGroup) {
   401     if (!mChineseInputGroup) {
   347         mChineseInputGroup = model->appendDataFormGroup(QObject::tr("Chinese Input"));
   402         mChineseInputGroup = model->appendDataFormGroup(QObject::tr("Chinese Input"));
   348         mPortraitInputMethodItem = new HbDataFormModelItem(HbDataFormModelItem::ComboBoxItem, QObject::tr("Portrait mode input method"));
   403         mPortraitInputMethodItem = new HbDataFormModelItem(HbDataFormModelItem::ComboBoxItem, QObject::tr("Portrait mode input method"));
   349         mChineseInputGroup->appendChild(mPortraitInputMethodItem);
   404         mChineseInputGroup->appendChild(mPortraitInputMethodItem);
   366         mForm->addConnection(mLandscapeInputMethodItem, SIGNAL(currentIndexChanged(int)), q, SLOT(setLandscapeInputMethod(int)));
   421         mForm->addConnection(mLandscapeInputMethodItem, SIGNAL(currentIndexChanged(int)), q, SLOT(setLandscapeInputMethod(int)));
   367 
   422 
   368         mHwrSpeedItem = new HbDataFormModelItem(HbDataFormModelItem::ComboBoxItem, QObject::tr("Handwriting speed"));
   423         mHwrSpeedItem = new HbDataFormModelItem(HbDataFormModelItem::ComboBoxItem, QObject::tr("Handwriting speed"));
   369         mChineseInputGroup->appendChild(mHwrSpeedItem);
   424         mChineseInputGroup->appendChild(mHwrSpeedItem);
   370         mHwrSpeedItem->setContentWidgetData(QString("items"), mHwrSpeedNames);
   425         mHwrSpeedItem->setContentWidgetData(QString("items"), mHwrSpeedNames);
   371         int hwr = mHwrSpeed;
   426         mHwrSpeedItem->setContentWidgetData(QString("currentIndex"), mHwrSpeed);
   372         mHwrSpeedItem->setContentWidgetData(QString("currentIndex"), hwr);
       
   373         mHwrSpeedItem->setContentWidgetData(QString("objectName"), QString("handwriting_speed"));
   427         mHwrSpeedItem->setContentWidgetData(QString("objectName"), QString("handwriting_speed"));
   374         mForm->addConnection(mHwrSpeedItem, SIGNAL(currentIndexChanged(int)), q, SLOT(setHwrSpeed(int)));
   428         mForm->addConnection(mHwrSpeedItem, SIGNAL(currentIndexChanged(int)), q, SLOT(setHwrSpeed(int)));
   375     }
   429 
   376 
   430         mCnDefaultLanguageItem = new HbDataFormModelItem(HbDataFormModelItem::ComboBoxItem, QObject::tr("Default language for keyboard input"));
       
   431         mChineseInputGroup->appendChild(mCnDefaultLanguageItem);
       
   432         int defaultLanguageIndex = HbInputSettingProxy::instance()->useWesternDefaultKeypadForChinese() ? 1 : 0;
       
   433         mCnDefaultLanguageItem->setContentWidgetData(QString("items"), mCnDefaultLanguageNames);
       
   434         mCnDefaultLanguageItem->setContentWidgetData(QString("currentIndex"), defaultLanguageIndex);
       
   435         mCnDefaultLanguageItem->setContentWidgetData(QString("objectName"), QString("default_language_for_keyboard_input"));
       
   436         mForm->addConnection(mCnDefaultLanguageItem, SIGNAL(currentIndexChanged(int)), q, SLOT(setDefaultLanguageForKeyboardInput(int)));
       
   437     }
       
   438 
       
   439     int cangjieIdx = HbInputSettingProxy::instance()->detailedCangjieMode();
   377     if (mPrimaryInputLanguage == HbInputLanguage(QLocale::Chinese, QLocale::HongKong)) {
   440     if (mPrimaryInputLanguage == HbInputLanguage(QLocale::Chinese, QLocale::HongKong)) {
   378         mCangjieItem = new HbDataFormModelItem(HbDataFormModelItem::ComboBoxItem, QObject::tr("Cangjie mode"));
   441         mCangjieItem = new HbDataFormModelItem(HbDataFormModelItem::ComboBoxItem, QObject::tr("Cangjie mode"));
   379         mChineseInputGroup->appendChild(mCangjieItem);
   442         mChineseInputGroup->appendChild(mCangjieItem);
   380         mCangjieItem->setContentWidgetData(QString("items"), mCnCangjieInputModeNames);
   443         mCangjieItem->setContentWidgetData(QString("items"), mCnCangjieInputModeNames);
   381         int cangjieIdx = inputModeToIndex(mCnCangjieInputMode, mCangjieInputModeList);
       
   382         QVariant varCang;
   444         QVariant varCang;
   383         varCang.setValue(cangjieIdx);
   445         varCang.setValue(cangjieIdx);
   384         mCangjieItem->setContentWidgetData(QString("currentIndex"), varCang);
   446         mCangjieItem->setContentWidgetData(QString("currentIndex"), varCang);
   385         mCangjieItem->setContentWidgetData(QString("objectName"), QString("cangjie_mode"));
   447         mCangjieItem->setContentWidgetData(QString("objectName"), QString("cangjie_mode"));
   386         mForm->addConnection(mCangjieItem, SIGNAL(currentIndexChanged(int)), q, SLOT(setCangjieMode(int)));
   448         mForm->addConnection(mCangjieItem, SIGNAL(currentIndexChanged(int)), q, SLOT(setCangjieMode(int)));
   387     }
   449     }
   388 }
   450 }
   389 
   451 
   390 void HbInputSettingWidgetPrivate::updateContentWidgetData()
   452 void HbInputSettingWidgetPrivate::updateContentWidgetData() 
   391 {
   453 {
   392     // current primary language
   454     // current primary language
   393     mPrimaryLanguageItem->setContentWidgetData(QString("currentIndex"), languageToIndex(mPrimaryInputLanguage, mPrimaryLanguages));
   455     mPrimaryLanguageItem->setContentWidgetData(QString("currentIndex"), languageToIndex(mPrimaryInputLanguage, mPrimaryLanguages));
   394 
   456 
   395     mSecondaryLanguageItem->setContentWidgetData(QString("currentIndex"), languageToIndex(mSecondaryInputLanguage, mSecondaryLanguages));
   457     if (mSecondaryLanguageItem) {
       
   458         mSecondaryLanguageItem->setContentWidgetData(QString("currentIndex"), languageToIndex(mSecondaryInputLanguage, mSecondaryLanguages));
       
   459     }
   396     // key press timeout
   460     // key press timeout
   397     mKeypressTimeoutItem->setContentWidgetData(QString("sliderPosition"), mKeypressTimeout);
   461     mKeypressTimeoutItem->setContentWidgetData(QString("sliderPosition"), mKeypressTimeout);
   398     if (mCharacterPreviewEnabled) {
   462     if (mCharacterPreviewEnabled) {
   399         mCharacterPreviewItem->setContentWidgetData(QString("text"), statusOn);
   463         mCharacterPreviewItem->setContentWidgetData(QString("text"), statusOn);
   400         mCharacterPreviewItem->setContentWidgetData(QString("additionalText"), statusOff);
   464         mCharacterPreviewItem->setContentWidgetData(QString("additionalText"), statusOff);
   417         mPrimaryCandidateItem->setContentWidgetData(QString("additionalText"), exactTyping);
   481         mPrimaryCandidateItem->setContentWidgetData(QString("additionalText"), exactTyping);
   418     } else {
   482     } else {
   419         mPrimaryCandidateItem->setContentWidgetData(QString("text"), exactTyping);
   483         mPrimaryCandidateItem->setContentWidgetData(QString("text"), exactTyping);
   420         mPrimaryCandidateItem->setContentWidgetData(QString("additionalText"), bestPrediction);
   484         mPrimaryCandidateItem->setContentWidgetData(QString("additionalText"), bestPrediction);
   421     }
   485     }
       
   486 
       
   487     if(mChineseInputGroup && mCnDefaultLanguageItem) {
       
   488         int defaultLanguageIndex = HbInputSettingProxy::instance()->useWesternDefaultKeypadForChinese() ? 1 : 0;
       
   489         mCnDefaultLanguageItem->setContentWidgetData(QString("currentIndex"), defaultLanguageIndex);
       
   490     }
   422 }
   491 }
   423 
   492 
   424 /*!
   493 /*!
   425 Creates setting items to this widget
   494 Creates setting items to this widget
   426 */
   495 */
   427 void HbInputSettingWidgetPrivate::createSettingItems()
   496 void HbInputSettingWidgetPrivate::createSettingItems()
   428 {
   497 {   
   429     Q_Q(HbInputSettingWidget);
   498     Q_Q(HbInputSettingWidget);
   430 
   499 
   431     mModel = new HbDataFormModel();
   500     mModel = new HbDataFormModel();
   432 
   501 
   433     HbInputCheckBoxList *customPrototype = new HbInputCheckBoxList(mForm);
   502     HbInputCheckBoxList *customPrototype = new HbInputCheckBoxList(mForm);
   526 
   595 
   527     if (mPrimaryInputLanguage.language() == QLocale::Chinese) {
   596     if (mPrimaryInputLanguage.language() == QLocale::Chinese) {
   528         createChineseSettingGroup(mModel);
   597         createChineseSettingGroup(mModel);
   529     }
   598     }
   530     mForm->setModel(mModel);
   599     mForm->setModel(mModel);
       
   600 
       
   601     // expand language selection
       
   602     QModelIndex index = mModel->indexFromItem(mLanguageGroup);
       
   603     mForm->setExpanded(index, true);
       
   604 
   531     QObject::connect(mModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)), q, SLOT(dataChange(QModelIndex, QModelIndex)));
   605     QObject::connect(mModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)), q, SLOT(dataChange(QModelIndex, QModelIndex)));
   532 }
   606 }
   533 
   607 
   534 /*!
   608 /*!
   535 Fills given list with language names in the language list
   609 Fills given list with language names in the language list
   610     if (index >= 0 && index < inputModeList.count()) {
   684     if (index >= 0 && index < inputModeList.count()) {
   611         return inputModeList.at(index);
   685         return inputModeList.at(index);
   612     } else {
   686     } else {
   613         return KChineseInputModeNone;
   687         return KChineseInputModeNone;
   614     }
   688     }
   615 }
       
   616 
       
   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 }
   689 }
   756 
   690 
   757 /// @endcond
   691 /// @endcond
   758 
   692 
   759 /*!
   693 /*!
   943 
   877 
   944     HbInputSettingProxy *settings = HbInputSettingProxy::instance();
   878     HbInputSettingProxy *settings = HbInputSettingProxy::instance();
   945     HbPredictionFactory *predFactory = HbPredictionFactory::instance();
   879     HbPredictionFactory *predFactory = HbPredictionFactory::instance();
   946     bool oldPLangSupportsPrediction = (predFactory->predictionEngineForLanguage(d->mPrimaryInputLanguage) != NULL);
   880     bool oldPLangSupportsPrediction = (predFactory->predictionEngineForLanguage(d->mPrimaryInputLanguage) != NULL);
   947     d->mPrimaryInputLanguage = d->indexToLanguage(index, d->mPrimaryLanguages);
   881     d->mPrimaryInputLanguage = d->indexToLanguage(index, d->mPrimaryLanguages);
       
   882     if (d->mPrimaryInputLanguage.language() == QLocale::Chinese) {
       
   883         HbInputSettingProxy::instance()->setPreferredInputMethod(Qt::Horizontal, HbInputMethodDescriptor());
       
   884         HbInputSettingProxy::instance()->setPreferredInputMethod(Qt::Vertical, HbInputMethodDescriptor());        
       
   885     }
   948     HbInputSettingProxy::instance()->setGlobalInputLanguage(d->mPrimaryInputLanguage);
   886     HbInputSettingProxy::instance()->setGlobalInputLanguage(d->mPrimaryInputLanguage);
   949     bool langSupportsPrediction = (predFactory->predictionEngineForLanguage(d->mPrimaryInputLanguage) != NULL);
   887     bool langSupportsPrediction = (predFactory->predictionEngineForLanguage(d->mPrimaryInputLanguage) != NULL);
   950     if (oldPLangSupportsPrediction != langSupportsPrediction) {
   888     if (oldPLangSupportsPrediction != langSupportsPrediction) {
   951         if (settings->predictiveInputStatus(HbKeyboardSetting12key) != langSupportsPrediction) {
   889         if (settings->predictiveInputStatus(HbKeyboardSetting12key) != langSupportsPrediction) {
   952             settings->setPredictiveInputStatus(HbKeyboardSetting12key, langSupportsPrediction);
   890             settings->setPredictiveInputStatus(HbKeyboardSetting12key, langSupportsPrediction);
   978 
   916 
   979         HbDataFormModel *model = qobject_cast<HbDataFormModel *>(d->mForm->model());
   917         HbDataFormModel *model = qobject_cast<HbDataFormModel *>(d->mForm->model());
   980         if (d->mChineseInputGroup) {
   918         if (d->mChineseInputGroup) {
   981             model->removeItem(d->mChineseInputGroup);
   919             model->removeItem(d->mChineseInputGroup);
   982             d->mChineseInputGroup = NULL;
   920             d->mChineseInputGroup = NULL;
       
   921             HbInputSettingProxy::instance()->setPreferredInputMethod(Qt::Horizontal, HbInputMethodDescriptor());
       
   922             HbInputSettingProxy::instance()->setPreferredInputMethod(Qt::Vertical, HbInputMethodDescriptor());
   983         }
   923         }
   984     } else {
   924     } else {
   985         HbDataFormModel *model = qobject_cast<HbDataFormModel *>(d->mForm->model());
   925         HbDataFormModel *model = qobject_cast<HbDataFormModel *>(d->mForm->model());
   986         if (d->mChineseInputGroup) {
   926         if (d->mChineseInputGroup) {
   987             model->removeItem(d->mChineseInputGroup);
   927             model->removeItem(d->mChineseInputGroup);
   991         if (d->mSecondaryLanguageItem) {
   931         if (d->mSecondaryLanguageItem) {
   992             model->removeItem(d->mSecondaryLanguageItem);
   932             model->removeItem(d->mSecondaryLanguageItem);
   993             d->mSecondaryLanguageItem = NULL;
   933             d->mSecondaryLanguageItem = NULL;
   994         }
   934         }
   995 
   935 
   996         resetChineseInputMode();
   936         resetChineseInputMode(d->mPrimaryInputLanguage);
   997         d->createChineseSettingGroup(model);
   937         d->createChineseSettingGroup(model);
   998         d->mForm->setModel(model);
   938         d->mForm->setModel(model);
   999     }
   939     }
  1000 }
   940 }
  1001 
   941 
  1095 */
  1035 */
  1096 void HbInputSettingWidget::setPortraitInputMethod(int index)
  1036 void HbInputSettingWidget::setPortraitInputMethod(int index)
  1097 {
  1037 {
  1098     Q_D(HbInputSettingWidget);
  1038     Q_D(HbInputSettingWidget);
  1099     d->mCnPortraitInputMode = d->indexToInputmode(index, d->mCnPortraitInputModeList);
  1039     d->mCnPortraitInputMode = d->indexToInputmode(index, d->mCnPortraitInputModeList);
  1100     QString inputMethodString;
       
  1101     QByteArray customData;
  1040     QByteArray customData;
  1102     d->setInputMethodVar(Qt::Vertical, inputMethodString, customData);
  1041     HbInputMethodDescriptor descriptor;
  1103 
  1042 
  1104     const HbInputMethodDescriptor descriptor = d->findInputMethodDescriptor(inputMethodString);
  1043     if (d->mCnPortraitInputMode != KHwrMode) {
  1105     HbInputSettingProxy::instance()->setPreferredInputMethod(Qt::Vertical, (const HbInputMethodDescriptor &)descriptor, customData);
  1044         QString imName = d->inputModeName(d->mCnPortraitInputMode);
       
  1045         customData.append(imName.toLatin1().data());
       
  1046         customData.append((char)0);
       
  1047         descriptor = HbInputMethod::defaultInputMethod(Qt::Vertical);
       
  1048     } else {
       
  1049         customData.append(KHwrName.toLatin1().data());
       
  1050         customData.append((char)0);
       
  1051         QList<HbInputMethodDescriptor> methodList = HbInputMethod::listCustomInputMethods(Qt::Vertical, HbInputSettingProxy::instance()->globalInputLanguage());
       
  1052         foreach(const HbInputMethodDescriptor &des, methodList) {
       
  1053             if (des.displayName() == "Chinese Hand Writing Recognition") {
       
  1054                 descriptor = des;
       
  1055                 break;
       
  1056             }
       
  1057         }
       
  1058     }
       
  1059 
       
  1060     Qt::Orientation orientation = Qt::Vertical;
       
  1061     if (d->mForm) {
       
  1062         orientation = d->mForm->mainWindow()->orientation();
       
  1063     }
       
  1064 
       
  1065     HbInputSettingProxy::instance()->setPreferredInputMethod(Qt::Vertical, descriptor, customData);
       
  1066     if (orientation == Qt::Vertical) {
       
  1067         HbInputMethod::activeInputMethod()->activateInputMethod(descriptor);
       
  1068     }
  1106 }
  1069 }
  1107 
  1070 
  1108 /*!
  1071 /*!
  1109 Saves the landscape input method
  1072 Saves the landscape input method
  1110 */
  1073 */
  1111 void HbInputSettingWidget::setLandscapeInputMethod(int index)
  1074 void HbInputSettingWidget::setLandscapeInputMethod(int index)
  1112 {
  1075 {
  1113     Q_D(HbInputSettingWidget);
  1076     Q_D(HbInputSettingWidget);
  1114     d->mCnLandscapeInputMode = d->indexToInputmode(index, d->mCnLandscapeInputModeList);
  1077     d->mCnLandscapeInputMode = d->indexToInputmode(index, d->mCnLandscapeInputModeList);
  1115     QString inputMethodString;
       
  1116     QByteArray customData;
  1078     QByteArray customData;
  1117     d->setInputMethodVar(Qt::Horizontal, inputMethodString, customData);
  1079     HbInputMethodDescriptor descriptor;
  1118 
  1080 
  1119     const HbInputMethodDescriptor descriptor = d->findInputMethodDescriptor(inputMethodString);
  1081     if (d->mCnLandscapeInputMode != KHwrMode) {
       
  1082         QString imName;
       
  1083         if (d->mCnLandscapeInputMode == KCangjieNormalMode || 
       
  1084             d->mCnLandscapeInputMode == KCangjieEasyMode  || 
       
  1085             d->mCnLandscapeInputMode == KCangjieAdvancedMode) {
       
  1086             imName = KCangjieGeneralName;
       
  1087         } else {
       
  1088             imName = d->inputModeName(d->mCnLandscapeInputMode);
       
  1089         }
       
  1090 
       
  1091         customData.append(imName.toLatin1().data());
       
  1092         customData.append((char)0);
       
  1093         descriptor = HbInputMethod::defaultInputMethod(Qt::Horizontal);
       
  1094     } else {
       
  1095         customData.append(KHwrName.toLatin1().data());
       
  1096         customData.append((char)0);
       
  1097         QList<HbInputMethodDescriptor> methodList = HbInputMethod::listCustomInputMethods(Qt::Horizontal, HbInputSettingProxy::instance()->globalInputLanguage());
       
  1098         foreach(const HbInputMethodDescriptor &des, methodList) {
       
  1099             if (des.displayName() == "Chinese Hand Writing Recognition") {
       
  1100                 descriptor = des;
       
  1101                 break;
       
  1102             }
       
  1103         }
       
  1104     }
       
  1105 
       
  1106     Qt::Orientation orientation = Qt::Horizontal;
       
  1107     if (d->mForm) {
       
  1108         orientation = d->mForm->mainWindow()->orientation();
       
  1109     }
       
  1110 
  1120     HbInputSettingProxy::instance()->setPreferredInputMethod(Qt::Horizontal, descriptor, customData);
  1111     HbInputSettingProxy::instance()->setPreferredInputMethod(Qt::Horizontal, descriptor, customData);
       
  1112     if (orientation == Qt::Horizontal) {
       
  1113         HbInputMethod::activeInputMethod()->activateInputMethod(descriptor);
       
  1114     }
  1121 }
  1115 }
  1122 
  1116 
  1123 /*!
  1117 /*!
  1124 Saves the cangjie input mode
  1118 Saves the cangjie input mode
  1125 */
  1119 */
  1127 {
  1121 {
  1128     Q_D(HbInputSettingWidget);
  1122     Q_D(HbInputSettingWidget);
  1129     d->mCnCangjieInputMode = d->indexToInputmode(index, d->mCangjieInputModeList);
  1123     d->mCnCangjieInputMode = d->indexToInputmode(index, d->mCangjieInputModeList);
  1130     d->mCnLandscapeInputMode = d->mCnCangjieInputMode;
  1124     d->mCnLandscapeInputMode = d->mCnCangjieInputMode;
  1131 
  1125 
  1132     QString inputMethodString;
  1126     QString imName = KCangjieGeneralName;
  1133     QByteArray customData;
  1127     QByteArray customData;
  1134     d->setInputMethodVar(Qt::Horizontal, inputMethodString, customData);
  1128     customData.append(imName.toLatin1().data());
  1135 
  1129     customData.append((char)0);
  1136     const HbInputMethodDescriptor descriptor = d->findInputMethodDescriptor(inputMethodString);
  1130 
       
  1131     HbInputMethodDescriptor descriptor;
       
  1132     descriptor = HbInputMethod::defaultInputMethod(Qt::Horizontal);
       
  1133      
  1137     HbInputSettingProxy::instance()->setPreferredInputMethod(Qt::Horizontal, descriptor, customData);
  1134     HbInputSettingProxy::instance()->setPreferredInputMethod(Qt::Horizontal, descriptor, customData);
  1138 }
  1135     HbInputSettingProxy::instance()->setDetailedCangjieMode(HbCangjieDetailMode(index));
  1139 
  1136 }
  1140 
  1137 
  1141 /*!
  1138 /*!
  1142 Saves the handwriting speed
  1139 Saves the handwriting speed
  1143 */
  1140 */
  1144 void HbInputSettingWidget::setHwrSpeed(int index)
  1141 void HbInputSettingWidget::setHwrSpeed(int index)
  1145 {
  1142 {
  1146     Q_D(HbInputSettingWidget);
  1143     // hwr speed index in setting widget are exactly same as enum HbHwrWritingSpeed of setting proxy
  1147     Qt::Orientation currentOrientation = HbInputSettingProxy::instance()->screenOrientation();
  1144     if (index >= 0 && index < KHwrSpeedCount) {
  1148     QByteArray portraitCustomData = HbInputSettingProxy::instance()->preferredInputMethodCustomData(Qt::Vertical);
  1145         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     }
  1146     }
  1163 }
  1147 }
  1164 
  1148 
  1165 /*!
  1149 /*!
  1166 Saves the portrait input method
  1150 Saves the portrait input method
  1167 */
  1151 */
  1168 void HbInputSettingWidget::resetChineseInputMode()
  1152 void HbInputSettingWidget::resetChineseInputMode(HbInputLanguage lang)
  1169 {
  1153 {
  1170     Q_D(HbInputSettingWidget);
  1154     Q_D(HbInputSettingWidget);
  1171     HbInputLanguage lang = HbInputSettingProxy::instance()->globalInputLanguage();
  1155     d->mCnPortraitInputMode = d->defaultModeByGivenLang(lang);
  1172 
  1156     d->mCnLandscapeInputMode = d->defaultModeByGivenLang(lang);
  1173     if (lang.variant() == QLocale::China) {
  1157     HbInputSettingProxy::instance()->setDetailedCangjieMode(HbCangjieNormal);
  1174         d->mCnPortraitInputMode = KPinyinMode;
  1158 
  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;
  1159     QByteArray portraitCustomData;
  1187     QByteArray landscapeCustomData;
  1160     QByteArray landscapeCustomData;
  1188     d->setInputMethodVar(Qt::Vertical, portraitInputMethodString, portraitCustomData);
  1161     QString imName = d->inputModeName(d->mCnPortraitInputMode);
  1189     d->setInputMethodVar(Qt::Horizontal, landscapeInputMethodString, landscapeCustomData);
  1162     portraitCustomData.append(imName.toLatin1().data());
  1190 
  1163     portraitCustomData.append((char)0);
  1191     const HbInputMethodDescriptor portraitDescriptor = d->findInputMethodDescriptor(portraitInputMethodString);
  1164     HbInputMethodDescriptor portraitDescriptor = HbInputMethod::defaultInputMethod(Qt::Vertical);
  1192     const HbInputMethodDescriptor landscapeDescriptor = d->findInputMethodDescriptor(landscapeInputMethodString);
  1165 
       
  1166     if (d->mCnLandscapeInputMode == KCangjieNormalMode || 
       
  1167         d->mCnLandscapeInputMode == KCangjieEasyMode || 
       
  1168         d->mCnLandscapeInputMode == KCangjieAdvancedMode) {
       
  1169         imName = KCangjieGeneralName;
       
  1170     } else {
       
  1171         imName = d->inputModeName(d->mCnLandscapeInputMode);
       
  1172     }
       
  1173 
       
  1174     landscapeCustomData.append(imName.toLatin1().data());
       
  1175     landscapeCustomData.append((char)0);
       
  1176     HbInputMethodDescriptor landscapeDescriptor = HbInputMethod::defaultInputMethod(Qt::Horizontal);
       
  1177 
  1193     HbInputSettingProxy::instance()->setPreferredInputMethod(Qt::Vertical, (const HbInputMethodDescriptor &)portraitDescriptor, portraitCustomData);
  1178     HbInputSettingProxy::instance()->setPreferredInputMethod(Qt::Vertical, (const HbInputMethodDescriptor &)portraitDescriptor, portraitCustomData);
  1194     HbInputSettingProxy::instance()->setPreferredInputMethod(Qt::Horizontal, (const HbInputMethodDescriptor &)landscapeDescriptor, landscapeCustomData);
  1179     HbInputSettingProxy::instance()->setPreferredInputMethod(Qt::Horizontal, (const HbInputMethodDescriptor &)landscapeDescriptor, landscapeCustomData);
       
  1180 
       
  1181     return;
  1195 }
  1182 }
  1196 
  1183 
  1197 /*
  1184 /*
  1198     This slot is called when ever data in the form model is changed
  1185     This slot is called when ever data in the form model is changed
  1199 */
  1186 */
  1224     disconnect(settings, SIGNAL(autocompletionStateChanged(HbKeyboardSettingFlags, bool)), this, SLOT(updateAutocompletionState(HbKeyboardSettingFlags, bool)));
  1211     disconnect(settings, SIGNAL(autocompletionStateChanged(HbKeyboardSettingFlags, bool)), this, SLOT(updateAutocompletionState(HbKeyboardSettingFlags, bool)));
  1225     disconnect(settings, SIGNAL(typingCorrectionLevelChanged(HbTypingCorrectionLevel)), this, SLOT(updateTypingCorrectionLevel(HbTypingCorrectionLevel)));
  1212     disconnect(settings, SIGNAL(typingCorrectionLevelChanged(HbTypingCorrectionLevel)), this, SLOT(updateTypingCorrectionLevel(HbTypingCorrectionLevel)));
  1226     disconnect(settings, SIGNAL(primaryCandidateModeChanged(HbPrimaryCandidateMode)), this, SLOT(updatePrimaryCandidateMode(HbPrimaryCandidateMode)));
  1213     disconnect(settings, SIGNAL(primaryCandidateModeChanged(HbPrimaryCandidateMode)), this, SLOT(updatePrimaryCandidateMode(HbPrimaryCandidateMode)));
  1227 }
  1214 }
  1228 
  1215 
       
  1216 /*!
       
  1217 Set default language for keyboard input
       
  1218 */
       
  1219 void HbInputSettingWidget::setDefaultLanguageForKeyboardInput(int index)
       
  1220 {
       
  1221     if(index == 1) {
       
  1222         HbInputSettingProxy::instance()->setWesternDefaultKeypadForChinese(true);
       
  1223     } else {
       
  1224         HbInputSettingProxy::instance()->setWesternDefaultKeypadForChinese(false);
       
  1225     }
       
  1226 }
       
  1227 
  1229 // End of file
  1228 // End of file