loadgen/src/loadgen_settingsviewdlg.cpp
branchRCL_3
changeset 22 fad26422216a
equal deleted inserted replaced
21:b3cee849fa46 22:fad26422216a
       
     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 // INCLUDE FILES
       
    20 #include "loadgen_settingsviewdlg.h"
       
    21 #include "loadgen_model.h"
       
    22 #include "loadgen.hrh"
       
    23 #include "loadgen_std.h"
       
    24 #include <loadgen.rsg>
       
    25 
       
    26 #include <aknsettingitemlist.h>
       
    27 #include <CAknMemorySelectionSettingItem.h> 
       
    28 #include <aknlists.h>
       
    29 #include <akntitle.h>
       
    30 #include <aknnavi.h>
       
    31 #include <aknnavide.h>
       
    32 #include <StringLoader.h>
       
    33 #include <aknnotewrappers.h> 
       
    34 
       
    35 // ===================================== MEMBER FUNCTIONS =====================================
       
    36 
       
    37 CLoadGenSettingsViewDlg* CLoadGenSettingsViewDlg::NewL(TLoadGenSettings& aSettings)
       
    38     {
       
    39     CLoadGenSettingsViewDlg* self = new(ELeave) CLoadGenSettingsViewDlg(aSettings);
       
    40     CleanupStack::PushL(self);
       
    41     self->ConstructL();
       
    42     CleanupStack::Pop(self);
       
    43     return self;    
       
    44     }
       
    45 
       
    46 // --------------------------------------------------------------------------------------------
       
    47 
       
    48 CLoadGenSettingsViewDlg::~CLoadGenSettingsViewDlg()
       
    49     {
       
    50     // restore default navi pane
       
    51     if (iNaviContainer)
       
    52         iNaviContainer->Pop();
       
    53     
       
    54     if (iSettingItemArray)
       
    55         {
       
    56         iSettingItemArray->ResetAndDestroy();
       
    57         delete iSettingItemArray; 
       
    58         }
       
    59     
       
    60     delete iDecoratedTabGroup;   
       
    61     }
       
    62 
       
    63 // --------------------------------------------------------------------------------------------
       
    64 
       
    65 CLoadGenSettingsViewDlg::CLoadGenSettingsViewDlg(TLoadGenSettings& aSettings) : iSettings(aSettings)
       
    66     {
       
    67     }
       
    68 
       
    69 // --------------------------------------------------------------------------------------------
       
    70 
       
    71 void CLoadGenSettingsViewDlg::ConstructL()
       
    72     {
       
    73     // construct a menu bar
       
    74     CAknDialog::ConstructL(R_LOADGEN_SETTINGS_MENUBAR);
       
    75    
       
    76     CEikStatusPane* sp = iEikonEnv->AppUiFactory()->StatusPane();
       
    77     
       
    78     // set empty navi pane label
       
    79     iNaviContainer = static_cast<CAknNavigationControlContainer*>(sp->ControlL(TUid::Uid(EEikStatusPaneUidNavi)));
       
    80     //iNaviContainer->PushDefaultL();
       
    81     
       
    82     // set title text
       
    83     CAknTitlePane* tp = static_cast<CAknTitlePane*>( sp->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) );
       
    84     tp->SetTextL( _L("Settings") );
       
    85     
       
    86     // create a tab group
       
    87     iDecoratedTabGroup = iNaviContainer->CreateTabGroupL(this);
       
    88     iTabGroup = static_cast<CAknTabGroup*>(iDecoratedTabGroup->DecoratedControl());
       
    89     iTabGroup->SetTabFixedWidthL(KTabWidthWithTwoLongTabs); 
       
    90     
       
    91     // add tabs
       
    92     //iTabGroup->AddTabL(ETabGeneral, _L("General"));
       
    93     //iTabGroup->AddTabL(ETabScreenShot, _L("Screen shot"));
       
    94     //iTabGroup->SetActiveTabByIndex(ETabGeneral);
       
    95     
       
    96     iNaviContainer->PushL( *iDecoratedTabGroup );
       
    97     }
       
    98 
       
    99 // --------------------------------------------------------------------------------------------
       
   100 
       
   101 void CLoadGenSettingsViewDlg::HandleListBoxEventL(CEikListBox* /*aListBox*/, TListBoxEvent aEventType)
       
   102     {
       
   103     switch (aEventType)
       
   104         {
       
   105         case EEventEnterKeyPressed:
       
   106         case EEventItemDoubleClicked:
       
   107             ShowSettingPageL(EFalse);
       
   108             break;
       
   109         default:
       
   110             break;
       
   111         }
       
   112     }
       
   113 
       
   114 // --------------------------------------------------------------------------------------------
       
   115 
       
   116 void CLoadGenSettingsViewDlg::TabChangedL(TInt /*aIndex*/)
       
   117     {
       
   118     iListBox->SetCurrentItemIndex(0);
       
   119 
       
   120     SetVisibilitiesOfSettingItemsL();   
       
   121     }
       
   122 
       
   123 // --------------------------------------------------------------------------------------------
       
   124 
       
   125 void CLoadGenSettingsViewDlg::ProcessCommandL(TInt aCommandId)
       
   126     {
       
   127     CAknDialog::ProcessCommandL(aCommandId);
       
   128 
       
   129     switch (aCommandId)
       
   130         {
       
   131         case ELoadGenCmdSettingsChange:
       
   132             ShowSettingPageL(ETrue);
       
   133             break;
       
   134         case ELoadGenCmdSettingsExit:
       
   135             TryExitL(EAknCmdExit);
       
   136             break;
       
   137         default:
       
   138             break;
       
   139         }
       
   140     }
       
   141 
       
   142 // --------------------------------------------------------------------------------------------
       
   143 
       
   144 TKeyResponse CLoadGenSettingsViewDlg::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
       
   145     {
       
   146     if (iTabGroup == NULL)
       
   147         {
       
   148         return EKeyWasNotConsumed;
       
   149         }
       
   150 
       
   151     TInt active = iTabGroup->ActiveTabIndex();
       
   152     TInt count = iTabGroup->TabCount();
       
   153 
       
   154     switch ( aKeyEvent.iCode )
       
   155         {
       
   156         case EKeyLeftArrow:
       
   157             if (active > 0)
       
   158                 {
       
   159                 active--;
       
   160                 iTabGroup->SetActiveTabByIndex(active);
       
   161                 TabChangedL(active); 
       
   162                 }
       
   163             break;
       
   164         
       
   165         case EKeyRightArrow:
       
   166             if((active + 1) < count)
       
   167                 {
       
   168                 active++;
       
   169                 iTabGroup->SetActiveTabByIndex(active);
       
   170                 TabChangedL(active); 
       
   171                 }
       
   172             break;
       
   173         }
       
   174 
       
   175     return CAknDialog::OfferKeyEventL(aKeyEvent, aType);
       
   176     }    
       
   177 
       
   178 // --------------------------------------------------------------------------------------------
       
   179 
       
   180 void CLoadGenSettingsViewDlg::PreLayoutDynInitL()
       
   181     {
       
   182     iListBox = static_cast<CAknSettingStyleListBox*>( Control(ELoadGenSettingItemList) );
       
   183     iListBox->SetMopParent(this);
       
   184     iListBox->CreateScrollBarFrameL(ETrue);
       
   185     iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
       
   186     iListBox->SetListBoxObserver(this);
       
   187 
       
   188     iSettingItemArray = new(ELeave) CAknSettingItemArray(16, EFalse, 0);
       
   189 
       
   190     CTextListBoxModel* model = iListBox->Model();
       
   191     model->SetItemTextArray(iSettingItemArray);
       
   192     model->SetOwnershipType(ELbmDoesNotOwnItemArray);
       
   193 
       
   194     UpdateListBoxL();    
       
   195     }
       
   196 
       
   197 // --------------------------------------------------------------------------------------------
       
   198 
       
   199 TBool CLoadGenSettingsViewDlg::OkToExitL(TInt aButtonId)
       
   200     {
       
   201     return CAknDialog::OkToExitL(aButtonId);
       
   202     }
       
   203 
       
   204 // --------------------------------------------------------------------------------------------
       
   205 
       
   206 void CLoadGenSettingsViewDlg::ShowSettingPageL(TInt aCalledFromMenu)
       
   207     {
       
   208     TInt listIndex = iListBox->CurrentItemIndex();
       
   209     TInt realIndex = iSettingItemArray->ItemIndexFromVisibleIndex(listIndex);
       
   210     CAknSettingItem* item = iSettingItemArray->At(realIndex);
       
   211     item->EditItemL(aCalledFromMenu);
       
   212     item->StoreL();
       
   213     SetVisibilitiesOfSettingItemsL();
       
   214     DrawNow();
       
   215     }
       
   216 
       
   217 // --------------------------------------------------------------------------------------------
       
   218 
       
   219 void CLoadGenSettingsViewDlg::SetVisibilitiesOfSettingItemsL()
       
   220     {
       
   221     if (iSettingItemArray->Count() > 0)
       
   222         {
       
   223 /*
       
   224         switch (iTabGroup->ActiveTabIndex())
       
   225             {
       
   226 
       
   227             case ETabGeneral:
       
   228                 {
       
   229                 ((*iSettingItemArray)[ESettingListDisplayModeSelection])->SetHidden(EFalse);
       
   230                 ((*iSettingItemArray)[ESettingListFileViewModeSelection])->SetHidden(EFalse);
       
   231                 break;
       
   232                 }
       
   233             
       
   234             case ETabScreenShot:
       
   235                 {
       
   236                 ((*iSettingItemArray)[ESettingListDisplayModeSelection])->SetHidden(ETrue);
       
   237                 ((*iSettingItemArray)[ESettingListFileViewModeSelection])->SetHidden(ETrue);
       
   238                 break;            
       
   239                 }
       
   240 
       
   241             default:
       
   242                 User::Panic(_L("TabIOOB"), 50);
       
   243                 break;
       
   244             }
       
   245 */
       
   246         iSettingItemArray->RecalculateVisibleIndicesL();
       
   247         iListBox->HandleItemAdditionL();
       
   248         iListBox->UpdateScrollBarsL();
       
   249         }
       
   250     }   
       
   251 
       
   252 // --------------------------------------------------------------------------------------------
       
   253 
       
   254 void CLoadGenSettingsViewDlg::UpdateListBoxL()
       
   255     {
       
   256     iSettingItemArray->ResetAndDestroy();
       
   257 
       
   258 /* 
       
   259     // create items
       
   260     TInt ordinal(0);
       
   261 
       
   262     AddSettingItemL(ESettingListDisplayModeSelection,
       
   263                     R_DISPLAYMODESELECTION_SETTING_TITLE,
       
   264                     R_DISPLAYMODESELECTION_SETTING_PAGE,
       
   265                     R_DISPLAYMODESELECTION_SETTING_TEXTS,
       
   266                     ordinal++);
       
   267                     
       
   268     AddSettingItemL(ESettingListFileViewModeSelection,
       
   269                     R_FILEVIEWMODESELECTION_SETTING_TITLE,
       
   270                     R_FILEVIEWMODESELECTION_SETTING_PAGE,
       
   271                     R_FILEVIEWMODESELECTION_SETTING_TEXTS,
       
   272                     ordinal++); 
       
   273 */                                                              
       
   274     SetVisibilitiesOfSettingItemsL(); 
       
   275     }
       
   276 
       
   277 // --------------------------------------------------------------------------------------------
       
   278 
       
   279 void CLoadGenSettingsViewDlg::AddSettingItemL(TInt aId,
       
   280                                                  TInt aTitleResource,
       
   281                                                  TInt aSettingPageResource,
       
   282                                                  TInt aAssociatedResource,
       
   283                                                  TInt aOrdinal)
       
   284     {
       
   285     // create a setting item
       
   286     CAknSettingItem* settingItem = NULL;
       
   287     
       
   288     switch (aId)
       
   289         {
       
   290 /*
       
   291         case ESettingListDisplayModeSelection:
       
   292             settingItem = new(ELeave) CAknEnumeratedTextPopupSettingItem(aId, iSettings.iDisplayMode);
       
   293             break;
       
   294             
       
   295         case ESettingListFileViewModeSelection:
       
   296             settingItem = new(ELeave) CAknEnumeratedTextPopupSettingItem(aId, iSettings.iFileViewMode);
       
   297             break;
       
   298 
       
   299         default:
       
   300             User::Panic(_L("NotSetItem"), 50);
       
   301             break;
       
   302 */
       
   303         }
       
   304         
       
   305     CleanupStack::PushL(settingItem);
       
   306 
       
   307     // get title text
       
   308     HBufC* itemTitle = StringLoader::LoadLC(aTitleResource);
       
   309 
       
   310     // construct the setting item
       
   311     settingItem->ConstructL(EFalse, aOrdinal, *itemTitle, NULL, aSettingPageResource,
       
   312                             EAknCtPopupSettingList, NULL, aAssociatedResource);
       
   313 
       
   314     // append the setting item to settingitem array
       
   315     iSettingItemArray->InsertL(aOrdinal, settingItem);
       
   316 
       
   317     CleanupStack::PopAndDestroy(); //itemTitle
       
   318     CleanupStack::Pop(); //settingItem
       
   319     }
       
   320 
       
   321 // --------------------------------------------------------------------------------------------
       
   322     
       
   323 // End of File