textinput/GSLangPlugin/src/DualLanguageDialog.cpp
branchRCL_3
changeset 21 ecbabf52600f
equal deleted inserted replaced
20:ebd48d2de13c 21:ecbabf52600f
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0""
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 /*
       
    18  * ============================================================================
       
    19  *  Name     : CGSPredictiveSettingList from AknFepPredictiveSettingList 
       
    20  * ============================================================================
       
    21  */
       
    22 #include <CentralRepository.h>
       
    23 #include <AknQueryDialog.h>
       
    24 #include <AknFepInternalCRKeys.h>
       
    25 #include <PtiDefs.h>
       
    26 #include <e32property.h>
       
    27 #include <AvkonInternalCRKeys.h>
       
    28 #include <AknFepGlobalEnums.h>
       
    29 #include "DualLanguageDialog.h"
       
    30 #include <aknnotewrappers.h>
       
    31 #include <aknfep.rsg>
       
    32 #include "GSLangModel.h"
       
    33 #include "DualLanguageData.h"
       
    34 #include <GSCommon.hrh>
       
    35 
       
    36 CGSDualLanguageDialog *CGSDualLanguageDialog::NewL(TInt aMenuResId, CGSLangModel* aModel)
       
    37     {
       
    38     CGSDualLanguageDialog* self = CGSDualLanguageDialog::NewLC(aMenuResId, aModel);      
       
    39     CleanupStack::Pop(self);
       
    40     return self;
       
    41     }
       
    42 
       
    43 CGSDualLanguageDialog *CGSDualLanguageDialog::NewLC(TInt aMenuResId, CGSLangModel* aModel)
       
    44     {
       
    45     CGSDualLanguageDialog* self = new (ELeave) CGSDualLanguageDialog(aModel);
       
    46     CleanupStack::PushL(self);
       
    47     self->ConstructL(aMenuResId);
       
    48     return self;
       
    49     }
       
    50 
       
    51 CGSDualLanguageDialog::CGSDualLanguageDialog(CGSLangModel* aModel)
       
    52     : iModel(aModel)
       
    53     {
       
    54     }
       
    55     
       
    56 CGSDualLanguageDialog::~CGSDualLanguageDialog()
       
    57     {
       
    58     delete iLangData;
       
    59     delete iLanguages;
       
    60     delete iSecondaryLanguages;
       
    61     }
       
    62 
       
    63 SEikControlInfo CGSDualLanguageDialog::CreateCustomControlL(TInt /*aControlType*/)
       
    64 {
       
    65     // construct the data object the settings list will use
       
    66     ReadSettingsDataL();
       
    67         
       
    68     iSettingsList = CGSDualLanguageList::NewL(iLangData, this);
       
    69     
       
    70     SEikControlInfo controlInfo;
       
    71     controlInfo.iFlags = EEikControlHasEars;
       
    72     controlInfo.iTrailerTextId = 0;
       
    73     controlInfo.iControl = iSettingsList;
       
    74     STATIC_CAST(CGSDualLanguageList*, controlInfo.iControl)->SetContainerWindowL(*this);
       
    75     
       
    76     return controlInfo;
       
    77 }
       
    78 
       
    79 CGSDualLanguageDialog::TFormControlTypes CGSDualLanguageDialog::ConvertCustomControlTypeToBaseControlType(TInt /*aControlType*/) const
       
    80 {
       
    81     return EPopfieldDerived;
       
    82 }
       
    83 
       
    84 TBool CGSDualLanguageDialog::OkToExitL(TInt aButtonId)
       
    85 {
       
    86     TBool retValue = EFalse;
       
    87     switch(aButtonId)
       
    88     {
       
    89     case EAknSoftkeyBack:        
       
    90         retValue = ETrue;
       
    91         break;
       
    92     
       
    93     case EAknSoftkeyOptions:
       
    94         DisplayMenuL();
       
    95         break;
       
    96     
       
    97         
       
    98     case EAknSoftkeyChange:
       
    99         EditItemL(EFalse);
       
   100         break;
       
   101     
       
   102     }
       
   103     return retValue;
       
   104 }
       
   105 
       
   106 void CGSDualLanguageDialog::ProcessCommandL(TInt aCommandId)
       
   107     {
       
   108 	// This is TSW eror fixing.
       
   109 	// This function is called by dialog framework, whenever menu item is 
       
   110 	// selected. we should have to hide existing display menu first to maitain the
       
   111 	// control stack .
       
   112 	// If user try to stop displaying menu after creating any control
       
   113 	// In that situation whenever application goes to background framework remove the
       
   114 	// control from the stack when try to remove the menubar from control stack.
       
   115 	 CAknDialog::ProcessCommandL(aCommandId);
       
   116 	
       
   117     switch(aCommandId) 
       
   118         {
       
   119         case EGSCmdAppChange:
       
   120             EditItemL(ETrue);
       
   121             break;
       
   122         case EGSCmdAppHelp:
       
   123             break;
       
   124         case EAknCmdExit:
       
   125 			// Pass the EAknCmdExit command to Avkon 
       
   126 			// Framework 
       
   127 			iAvkonAppUi->ProcessCommandL(aCommandId);
       
   128             break;
       
   129         }
       
   130 
       
   131     }
       
   132 
       
   133 void CGSDualLanguageDialog::ReadSettingsDataL()
       
   134     {
       
   135     if(iLangData == NULL)
       
   136         {
       
   137         iLangData = CGSDualLanguageData::NewL();
       
   138         }
       
   139     
       
   140     // If the setting page has a list create array which contains all
       
   141     // the items of the list in the setting page:
       
   142 
       
   143     //some dummy size of 10
       
   144     iLanguages = new( ELeave )CArrayFixFlat<TInt>(10);
       
   145 
       
   146     iSecondaryLanguages = new( ELeave )CArrayFixFlat<TInt>(10);
       
   147 
       
   148     //some dummy size of 10
       
   149     CDesCArrayFlat* items = new( ELeave )CDesCArrayFlat(10);
       
   150     CleanupStack::PushL( items );
       
   151 
       
   152     CDesCArrayFlat* secondaryItems = new( ELeave )CDesCArrayFlat(10);
       
   153     CleanupStack::PushL( secondaryItems );
       
   154     
       
   155     iModel->GetLanguagesFromPtiL( NULL, iLanguages, items );
       
   156     iModel->GetSecondaryInputLanguagesL(iSecondaryLanguages, secondaryItems,
       
   157             iCoeEnv);
       
   158     
       
   159     TInt i;
       
   160     TInt currentItem = 0;
       
   161     TInt currentItemSecondary = 0;
       
   162 
       
   163     //fetch the current value from model:
       
   164     // current item is the decimal value of T9 language code from shared data
       
   165     TInt currentInputLanguage =
       
   166     iModel->LanguageL( CGSLangModel::EGSInputLanguage );
       
   167 
       
   168     TInt currentInputLanguageSecondary =
       
   169     iModel->LanguageL( CGSLangModel::EGSInputLanguageSecondary );
       
   170     
       
   171     // total sum of available T9 dictionaries
       
   172     TInt count = iLanguages->Count();
       
   173 
       
   174     // compare sharedata languageCode with PtiLanguageCode array
       
   175     // Ptilanguage <-> listindex converter
       
   176 
       
   177     for ( i=0;i<count;i++ )
       
   178         {
       
   179         if ((*iLanguages)[i] == currentInputLanguage)
       
   180             {
       
   181             currentItem = i;
       
   182             break;
       
   183             }
       
   184         }
       
   185     
       
   186     count = iSecondaryLanguages->Count();
       
   187 
       
   188     // compare sharedata languageCode with PtiLanguageCode array
       
   189     // Ptilanguage <-> listindex converter
       
   190 
       
   191     for ( i=0;i<count;i++ )
       
   192         {
       
   193         if ((*iSecondaryLanguages)[i] == currentInputLanguageSecondary)
       
   194             {
       
   195             currentItemSecondary = i;
       
   196             break;
       
   197             }
       
   198         }
       
   199 
       
   200     iLangData->LoadL(items, secondaryItems, currentItem, currentItemSecondary);
       
   201     
       
   202     CleanupStack::Pop(secondaryItems);
       
   203     CleanupStack::Pop(items);
       
   204     }
       
   205 
       
   206 void CGSDualLanguageDialog::SaveSettingsDataL() const
       
   207     {
       
   208     TInt index = iSettingsList->SettingItemArray()->ItemIndexFromVisibleIndex(iSettingsList->ListBox()->CurrentItemIndex());
       
   209     TInt curLang = (*iLanguages)[iLangData->CurrentValue()]; 
       
   210     
       
   211     if(0 == index)
       
   212         {
       
   213         TInt previous = iModel->LanguageL( CGSLangModel::EGSInputLanguage );
       
   214         iModel->SetLanguageL( CGSLangModel::EGSInputLanguage, curLang );     
       
   215                
       
   216         if ((curLang == ELangPrcChinese || curLang == ELangHongKongChinese
       
   217             || curLang == ELangTaiwanChinese) && previous != curLang)
       
   218             {
       
   219             if (curLang == ELangPrcChinese )
       
   220                 {
       
   221                 iModel->SetDefaultInputMethodL( EPinyin );
       
   222                 }
       
   223             else if ( curLang == ELangHongKongChinese )
       
   224                 {
       
   225                 iModel->SetDefaultInputMethodL( EStroke );
       
   226                 }
       
   227             else if ( curLang == ELangTaiwanChinese )
       
   228                 {
       
   229                 iModel->SetDefaultInputMethodL( EZhuyin );
       
   230                 }            
       
   231             }
       
   232         }
       
   233     else
       
   234         {        
       
   235         if(curLang == ELangTaiwanChinese ||
       
   236            curLang == ELangHongKongChinese ||
       
   237            curLang == ELangPrcChinese ||
       
   238            curLang == ELangJapanese ||
       
   239            curLang == ELangKorean )
       
   240             {
       
   241             iModel->SetLanguageL( CGSLangModel::EGSInputLanguageSecondary, 0);
       
   242             }
       
   243         else
       
   244             {
       
   245             iModel->SetLanguageL( CGSLangModel::EGSInputLanguageSecondary,
       
   246                     (*iSecondaryLanguages)[iLangData->CurrentSecondaryValue()]);
       
   247             }
       
   248         }
       
   249     }
       
   250 
       
   251 void CGSDualLanguageDialog::EditItemL(TBool aCalledFromMenu)
       
   252     {
       
   253     iSettingsList->EditCurrentItemL(aCalledFromMenu);
       
   254     
       
   255     // Secondary language item shouldnt be displayed for Chinsese/Japanese/Korean languages
       
   256     TInt curLang = (*iLanguages)[iLangData->CurrentValue()]; 
       
   257    
       
   258     if(curLang == ELangTaiwanChinese ||
       
   259        curLang == ELangHongKongChinese ||
       
   260        curLang == ELangPrcChinese ||
       
   261        curLang == ELangJapanese ||
       
   262        curLang == ELangKorean )
       
   263         {
       
   264         iSettingsList->HideSecondaryInputL(ETrue);
       
   265         }
       
   266     else
       
   267         {
       
   268         iSettingsList->HideSecondaryInputL(EFalse);
       
   269         }
       
   270     
       
   271     iSettingsList->StoreSettingsL();
       
   272     SaveSettingsDataL();
       
   273     }