fep/aknfep/UiPlugins/AknFepUiInterface/AvkonImpl/src/AknFepPredictiveSettingList.cpp
changeset 40 2cb9bae34d17
parent 31 f1bdd6b078d1
child 49 37f5d84451bd
equal deleted inserted replaced
31:f1bdd6b078d1 40:2cb9bae34d17
     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 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 
       
    26 
       
    27 /*
       
    28  * ============================================================================
       
    29  *  Name     : CAknFepPredictiveSettingList from AknFepPredictiveSettingList 
       
    30  * ============================================================================
       
    31  */
       
    32 
       
    33 #include <barsread.h>
       
    34 #include <AvkonInternalCRKeys.h>
       
    35 #include <e32property.h>
       
    36 #include <PtiDefs.h>
       
    37 #include <aknfep.rsg>
       
    38 #include <AknFepGlobalEnums.h>
       
    39 #include <featmgr.h> 
       
    40 
       
    41 #include "AknFepPredictiveSettingList.h"
       
    42 #include "AknFepPredictiveSettingData.h"
       
    43 #include "AknFepPredictiveSettingDialog.h"
       
    44 
       
    45 CAknFepMultiSelectionSettingItem::CAknFepMultiSelectionSettingItem ( 
       
    46         TInt aResourceId, CAknFepPredictiveSettingData &aData, CCoeEnv* aCoeEnv )
       
    47     : CAknBigSettingItemBase(aResourceId), iData(aData), iCoeEnv(aCoeEnv)
       
    48     {
       
    49     iItutIndex = -1;
       
    50     iQwertyIndex = -1;
       
    51     iHalfQwertyIndex = -1;    
       
    52     }
       
    53 
       
    54 CAknFepMultiSelectionSettingItem::~CAknFepMultiSelectionSettingItem()
       
    55     {
       
    56     if (iSelection)
       
    57         {
       
    58         iSelection->ResetAndDestroy();
       
    59         }
       
    60     delete iSelection;
       
    61     }
       
    62         
       
    63 void CAknFepMultiSelectionSettingItem::EditItemL( TBool /*aCalledFromMenu*/ )
       
    64     {
       
    65     if(!iSelection)
       
    66         {
       
    67         iSelection = CreateSelectionItemListL();
       
    68         }
       
    69     CAknCheckBoxSettingPage* settingPage = 
       
    70         new( ELeave) CAknCheckBoxSettingPage( R_AUTOWORDCOMPLMULTI_PAGE, iSelection);
       
    71 
       
    72     SetSettingPage(settingPage);
       
    73     
       
    74     if( settingPage->ExecuteLD(CAknSettingPage::EUpdateWhenAccepted))
       
    75         {
       
    76         StoreL();
       
    77         }
       
    78     else
       
    79         {
       
    80         TInt physicalKeyboards = iData.PhysicalKeyboards();
       
    81         
       
    82         if( iItutIndex > -1 )
       
    83             {
       
    84             TBool selected = iData.AWCBitmask() & EKeyboardStyle12Key ? ETrue : EFalse;
       
    85             iSelection->At(iItutIndex)->SetSelectionStatus( selected );
       
    86             }
       
    87         
       
    88         if( iQwertyIndex > -1  )
       
    89             {
       
    90             TBool selected = iData.AWCBitmask() & EKeyboardStyleQwerty ? ETrue : EFalse;
       
    91             iSelection->At(iQwertyIndex)->SetSelectionStatus( selected );
       
    92             }
       
    93         
       
    94         if( iHalfQwertyIndex > -1 )
       
    95             {
       
    96             TBool selected = iData.AWCBitmask() & EKeyboardStyleHalfQwerty ? ETrue : EFalse;
       
    97             iSelection->At(iHalfQwertyIndex)->SetSelectionStatus( selected );
       
    98             }
       
    99         }
       
   100     SetSettingPage(0);
       
   101     }
       
   102 
       
   103 void CAknFepMultiSelectionSettingItem::StoreL()
       
   104     {
       
   105     if(iSelection)
       
   106         {
       
   107         if ( iItutIndex > -1 )
       
   108             {
       
   109             if(iSelection->At(iItutIndex)->SelectionStatus())
       
   110                 {
       
   111                 iData.AWCBitmask() |= EKeyboardStyle12Key;
       
   112                 }
       
   113             else
       
   114                 {
       
   115                 iData.AWCBitmask() &= ~EKeyboardStyle12Key;
       
   116                 }
       
   117             }
       
   118         
       
   119         if( iHalfQwertyIndex > -1 )
       
   120             {                   
       
   121             if(iSelection->At(iHalfQwertyIndex)->SelectionStatus())
       
   122                 {
       
   123                 iData.AWCBitmask() |= EKeyboardStyleHalfQwerty;
       
   124                 }
       
   125             else
       
   126                 {
       
   127                 iData.AWCBitmask() &= ~EKeyboardStyleHalfQwerty;
       
   128                 }
       
   129             }
       
   130         if ( iQwertyIndex > -1 )
       
   131             {
       
   132             if(iSelection->At(iQwertyIndex)->SelectionStatus())
       
   133                 {
       
   134                 iData.AWCBitmask() |= EKeyboardStyleQwerty;
       
   135                 }
       
   136             else
       
   137                 {
       
   138                 iData.AWCBitmask() &= ~EKeyboardStyleQwerty;
       
   139                 }
       
   140             }
       
   141         }
       
   142     }
       
   143 
       
   144 void CAknFepMultiSelectionSettingItem::LoadL()
       
   145     {
       
   146     if(iSelection)
       
   147         {
       
   148         iSelection->ResetAndDestroy();
       
   149         delete iSelection;   
       
   150         iSelection = NULL;
       
   151         }
       
   152     iSelection = CreateSelectionItemListL();
       
   153     }
       
   154 
       
   155 CSelectionItemList* CAknFepMultiSelectionSettingItem::CreateSelectionItemListL()
       
   156     {
       
   157     iItutIndex = -1;
       
   158     iQwertyIndex = -1;
       
   159     iHalfQwertyIndex = -1;
       
   160     
       
   161     CSelectionItemList* selection = new (ELeave) CSelectionItemList(2);
       
   162     CleanupStack::PushL( selection );
       
   163     
       
   164     TInt physicalKeyboards = iData.PhysicalKeyboards();
       
   165     TInt count = 0;
       
   166     
       
   167     TInt qwertyMask = EPhysicalKeyboardQwerty4x12 | EPhysicalKeyboardQwerty4x10 | 
       
   168                       EPhysicalKeyboardQwerty3x11 | EPhysicalKeyboardCustomQwerty;
       
   169     
       
   170     TBool supportVFSQ = FeatureManager::FeatureSupported( KFeatureIdVirtualFullscrQwertyInput );
       
   171     
       
   172     if ( physicalKeyboards & EPhysicalKeyboard12key ) //itut
       
   173         {
       
   174         TBool active = iData.AWCBitmask() & EKeyboardStyle12Key ? ETrue : EFalse; 
       
   175         HBufC* text = iCoeEnv->AllocReadResourceLC( R_AKNFEP_PRED_SETTING_ITUT );
       
   176         iItutIndex = count++;
       
   177         
       
   178         CSelectableItem* item = new (ELeave) CSelectableItem( *text, active );
       
   179         CleanupStack::PushL( item );
       
   180         item->ConstructL();
       
   181         selection->AppendL( item );
       
   182         CleanupStack::Pop( item );
       
   183         CleanupStack::PopAndDestroy( text );        
       
   184         }
       
   185     
       
   186     if ( ( physicalKeyboards & qwertyMask ) || supportVFSQ ) //4x12,4x10,3x11,custom, FSQ
       
   187         {
       
   188         TBool active = iData.AWCBitmask() & EKeyboardStyleQwerty ? ETrue : EFalse;
       
   189         HBufC* text = iCoeEnv->AllocReadResourceLC( R_AKNFEP_PRED_SETTING_QWERTY );
       
   190         iQwertyIndex = count++;
       
   191 
       
   192         CSelectableItem* item = new (ELeave) CSelectableItem( *text, active );
       
   193         CleanupStack::PushL( item );
       
   194         item->ConstructL();
       
   195         selection->AppendL( item );
       
   196         CleanupStack::Pop( item );
       
   197         CleanupStack::PopAndDestroy( text );          
       
   198         }
       
   199   
       
   200     if ( physicalKeyboards & EPhysicalKeyboardHalfQwerty ) //half qwerty
       
   201         {
       
   202         TBool active = iData.AWCBitmask() & EKeyboardStyleHalfQwerty ? ETrue : EFalse; 
       
   203         HBufC* text = iCoeEnv->AllocReadResourceLC( R_AKNFEP_PRED_SETTING_HALF_QWERTY );
       
   204         iHalfQwertyIndex = count++;
       
   205         
       
   206         CSelectableItem* item = new (ELeave) CSelectableItem( *text, active );
       
   207         CleanupStack::PushL( item );
       
   208         item->ConstructL();
       
   209         selection->AppendL( item );
       
   210         CleanupStack::Pop( item );
       
   211         CleanupStack::PopAndDestroy( text );        
       
   212         }
       
   213     
       
   214     CleanupStack::Pop( selection );
       
   215     
       
   216     return selection;
       
   217     }
       
   218 
       
   219 CAknFepPredictiveSettingList *CAknFepPredictiveSettingList::NewL(CAknFepPredictiveSettingData &aData, CAknFepPredictiveSettingDialog &aDialog)
       
   220 	{
       
   221 	CAknFepPredictiveSettingList* self = CAknFepPredictiveSettingList::NewLC(aData, aDialog);		
       
   222 	CleanupStack::Pop(self);
       
   223 	return self;
       
   224 	}
       
   225 
       
   226 CAknFepPredictiveSettingList *CAknFepPredictiveSettingList::NewLC(CAknFepPredictiveSettingData &aData, CAknFepPredictiveSettingDialog &aDialog)
       
   227 	{
       
   228 	CAknFepPredictiveSettingList* self = new (ELeave) CAknFepPredictiveSettingList(aData, aDialog);
       
   229 	CleanupStack::PushL(self);
       
   230 	return self;
       
   231 	}
       
   232 
       
   233 CAknFepPredictiveSettingList::CAknFepPredictiveSettingList(CAknFepPredictiveSettingData &aData, CAknFepPredictiveSettingDialog &aDialog) : 
       
   234 	CAknSettingItemList(),
       
   235 	iSettingsData(aData),
       
   236 	iSettingsDialog(aDialog)	
       
   237 	{
       
   238 	}
       
   239 
       
   240 CAknFepPredictiveSettingList::~CAknFepPredictiveSettingList()
       
   241 	{
       
   242 	// no specific destruction code required - no owned data
       
   243 	}
       
   244 
       
   245 
       
   246 void CAknFepPredictiveSettingList::SizeChanged()
       
   247     {
       
   248 	// if size changes, make sure component takes whole available space
       
   249 	CEikFormattedCellListBox *listbox = ListBox();
       
   250 
       
   251     if (listbox) 
       
   252         {
       
   253         listbox->SetRect(Rect());
       
   254         }
       
   255     }
       
   256 
       
   257 void CAknFepPredictiveSettingList::HandleListBoxEventL(CEikListBox* aListBox, TListBoxEvent aEventType)
       
   258 	{
       
   259 	TBool isSingleClick = iAvkonAppUi->IsSingleClickCompatible();
       
   260 	if( aEventType == EEventEnterKeyPressed || aEventType == EEventItemDoubleClicked 
       
   261 	      || ( isSingleClick && ( aEventType == EEventItemSingleClicked )))
       
   262 		{
       
   263 		iSettingsDialog.EditItemL(EFalse);//EditCurrentItemL(EFalse);
       
   264 		}
       
   265 	else
       
   266 	    {
       
   267 	    CAknSettingItemList::HandleListBoxEventL( aListBox,aEventType );
       
   268 	    }
       
   269 	}
       
   270 
       
   271 void CAknFepPredictiveSettingList::EditCurrentItemL(TBool aCalledFromMenu)
       
   272 	{
       
   273 	// invoke EditItemL on the current item
       
   274 	TInt index = SettingItemArray()->ItemIndexFromVisibleIndex(ListBox()->CurrentItemIndex());
       
   275 	
       
   276 	EditItemL(index, aCalledFromMenu);	// invoked from menu,or not
       
   277 			  
       
   278 	StoreSettingsL();
       
   279 	}
       
   280 
       
   281 CAknSettingItem * CAknFepPredictiveSettingList::CreateSettingItemL (TInt aIdentifier) 
       
   282 	{
       
   283 	// method is used to create specific setting item as required at run-time.
       
   284 	// aIdentifier is used to determine what kind of setting item should be 
       
   285 	// created
       
   286 	CAknSettingItem* settingItem = NULL;
       
   287 	TInt keyboardLayout = 0;
       
   288 	RProperty::Get(KCRUidAvkon, KAknKeyBoardLayout, keyboardLayout);
       
   289     switch (aIdentifier)
       
   290         {
       
   291         case EAknFepCmdPredAutoComplSetting:
       
   292             settingItem = new (ELeave) CAknBinaryPopupSettingItem (
       
   293                         aIdentifier, iSettingsData.AutoWordCompl());
       
   294             if(DeviceHasMultipleKeyboards())
       
   295                 {
       
   296                 settingItem->SetHidden(ETrue);
       
   297                 }
       
   298             break;
       
   299         case EAknFepCmdPredAutoComplMultiSetting:
       
   300             settingItem = new (ELeave) CAknFepMultiSelectionSettingItem (
       
   301                     aIdentifier, iSettingsData, iCoeEnv ); 
       
   302             if(!DeviceHasMultipleKeyboards())
       
   303                 {
       
   304                 settingItem->SetHidden(ETrue);
       
   305                 }
       
   306             break;
       
   307         case EAknFepCmdPredNumberCandidateSetting:
       
   308             settingItem = new (ELeave) CAknBinaryPopupSettingItem (
       
   309                                             aIdentifier, 
       
   310                                             iSettingsData.NumberCandidates());
       
   311             if(keyboardLayout == EPtiKeyboard12Key || keyboardLayout == EPtiKeyboardHalfQwerty)
       
   312                 settingItem->SetHidden(ETrue);
       
   313             break;
       
   314         case EAknFepCmdPredTypingCorrectionSetting:
       
   315             settingItem = new (ELeave) CAknEnumeratedTextPopupSettingItem (
       
   316                                             aIdentifier, 
       
   317                                             iSettingsData.TypingCorrection());
       
   318             // Disabled for ITU-T
       
   319             if(keyboardLayout == EPtiKeyboard12Key || keyboardLayout == EPtiKeyboardHalfQwerty)
       
   320                 settingItem->SetHidden(ETrue);
       
   321             break;
       
   322         case EAknFepCmdPredPrimaryCandidateSetting:
       
   323             settingItem = new (ELeave) CAknBinaryPopupSettingItem (
       
   324                                             aIdentifier, 
       
   325                                             iSettingsData.PrimaryCandidate());
       
   326             // Disabled for Half Qwerty and ITU-T
       
   327             if(keyboardLayout == EPtiKeyboardHalfQwerty ||
       
   328                     keyboardLayout == EPtiKeyboard12Key)
       
   329                 settingItem->SetHidden(ETrue);
       
   330             break;
       
   331         default:
       
   332             break;
       
   333         }
       
   334 
       
   335     return settingItem;
       
   336 	}
       
   337 
       
   338 TBool CAknFepPredictiveSettingList::DeviceHasMultipleKeyboards() 
       
   339     {
       
   340     TInt physicalKeyboards = iSettingsData.PhysicalKeyboards();
       
   341     TBool firstFound = EFalse;
       
   342     for(TUint i = 0x01; i <= 0xF0; i = i << 1)
       
   343         {
       
   344         if(physicalKeyboards & i)
       
   345             {
       
   346             if (firstFound)
       
   347                 {
       
   348                 return ETrue;
       
   349                 }
       
   350             else
       
   351                 {
       
   352                 firstFound = ETrue;
       
   353                 }
       
   354             }
       
   355         }
       
   356     return EFalse;
       
   357     }
       
   358 
       
   359 void CAknFepPredictiveSettingList::HandleResourceChange(TInt aType)
       
   360     {
       
   361     CAknSettingItemList::HandleResourceChange(aType);
       
   362     // Check for keyboard layout change
       
   363     // If layout is changed, close settings with information note
       
   364     if(aType==KEikDynamicLayoutVariantSwitch)
       
   365         {
       
   366         TInt keyboardLayout = 0;
       
   367         RProperty::Get(KCRUidAvkon, KAknKeyBoardLayout, keyboardLayout);
       
   368         if(keyboardLayout == EPtiKeyboard12Key)
       
   369             {
       
   370 #ifndef __ITI_VIRTUAL_TOUCH_FIRST_GENERATION_SUPPORT__
       
   371 			// Adding this under the flag would avoid flickering as settings page will be
       
   372 			// dismissed if __ITI_VIRTUAL_TOUCH_FIRST_GENERATION_SUPPORT__ is defined
       
   373             // Number candidate
       
   374             SettingItemArray()->At(2)->SetHidden(ETrue);
       
   375             // Typing correction
       
   376             SettingItemArray()->At(3)->SetHidden(ETrue);
       
   377             // Primary Candidate
       
   378             SettingItemArray()->At(4)->SetHidden(ETrue);
       
   379 #endif            
       
   380             }
       
   381         else if (keyboardLayout == EPtiKeyboardHalfQwerty)
       
   382             {
       
   383             // Number candidate
       
   384             SettingItemArray()->At(2)->SetHidden(ETrue);
       
   385             // Typing correction
       
   386             SettingItemArray()->At(3)->SetHidden(ETrue);
       
   387             // Primary Candidate
       
   388             SettingItemArray()->At(4)->SetHidden(ETrue);
       
   389             }
       
   390         else
       
   391             {
       
   392             // Number candidate
       
   393             SettingItemArray()->At(2)->SetHidden(EFalse);
       
   394             // Typing correction
       
   395             SettingItemArray()->At(3)->SetHidden(EFalse);
       
   396             // Primary Candidate
       
   397             SettingItemArray()->At(4)->SetHidden(EFalse);            
       
   398             }
       
   399             
       
   400         TRAP_IGNORE(
       
   401         { 								 
       
   402         HandleChangeInItemArrayOrVisibilityL();	
       
   403         });
       
   404         
       
   405         }
       
   406     }
       
   407