piprofilerui/ui/avkon/src/profiler_gui_settingsviewdlg.cpp
changeset 51 b048e15729d6
parent 44 5db69f4c3d06
child 52 36d60d12b4af
equal deleted inserted replaced
44:5db69f4c3d06 51:b048e15729d6
     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 // INCLUDE FILES
       
    21 #include "profiler_gui_settingsviewdlg.h"
       
    22 #include "profiler_gui_model.h"
       
    23 #include "profiler_gui.hrh"
       
    24 #include "profiler_gui_std.h"
       
    25 #include <piprofilerui.rsg>
       
    26 
       
    27 #include <aknsettingitemlist.h>
       
    28 #include <CAknMemorySelectionSettingItem.h> 
       
    29 #include <aknlists.h>
       
    30 #include <akntitle.h>
       
    31 #include <aknnavi.h>
       
    32 #include <aknnavide.h>
       
    33 #include <StringLoader.h>
       
    34 #include <aknnotewrappers.h> 
       
    35 
       
    36 // LITERALS
       
    37 _LIT8(KDebugOutput, "debug_output");
       
    38 _LIT8(KFileSystem, "file_system");
       
    39 _LIT(KEmptySettingItem, "");
       
    40 
       
    41 // ===================================== MEMBER FUNCTIONS =====================================
       
    42 
       
    43 CProfilerGuiSettingsViewDlg* CProfilerGuiSettingsViewDlg::NewL(TGeneralAttributes& aSettings)
       
    44     {
       
    45     CProfilerGuiSettingsViewDlg* self = new(ELeave) CProfilerGuiSettingsViewDlg(aSettings);
       
    46     CleanupStack::PushL(self);
       
    47     self->ConstructL();
       
    48     CleanupStack::Pop(self);
       
    49     return self;    
       
    50     }
       
    51 
       
    52 // --------------------------------------------------------------------------------------------
       
    53 
       
    54 CProfilerGuiSettingsViewDlg::~CProfilerGuiSettingsViewDlg()
       
    55     {
       
    56     // restore default navi pane
       
    57     if(iNaviContainer)
       
    58         iNaviContainer->Pop();
       
    59     
       
    60     if (iSettingItemArray)
       
    61         {
       
    62         iSettingItemArray->ResetAndDestroy();
       
    63         delete iSettingItemArray; 
       
    64         }
       
    65     
       
    66     }
       
    67 
       
    68 // --------------------------------------------------------------------------------------------
       
    69 
       
    70 CProfilerGuiSettingsViewDlg::CProfilerGuiSettingsViewDlg(TGeneralAttributes& aSettings) : iSettings(aSettings)
       
    71     {
       
    72     }
       
    73 
       
    74 // --------------------------------------------------------------------------------------------
       
    75 
       
    76 void CProfilerGuiSettingsViewDlg::ConstructL()
       
    77     {
       
    78     // construct a menu bar
       
    79     CAknDialog::ConstructL(R_PROFILER_GUI_SETTINGS_MENUBAR);
       
    80    
       
    81     CEikStatusPane* sp = iEikonEnv->AppUiFactory()->StatusPane();
       
    82     
       
    83     // set empty navi pane label
       
    84     iNaviContainer = static_cast<CAknNavigationControlContainer*>(sp->ControlL(TUid::Uid(EEikStatusPaneUidNavi)));
       
    85     iNaviContainer->PushDefaultL();
       
    86     
       
    87     // set title text
       
    88     CAknTitlePane* tp = static_cast<CAknTitlePane*>( sp->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) );
       
    89     tp->SetTextL( _L("Settings") );
       
    90 
       
    91     }
       
    92 
       
    93 // --------------------------------------------------------------------------------------------
       
    94 
       
    95 void CProfilerGuiSettingsViewDlg::HandleListBoxEventL(CEikListBox* /*aListBox*/, TListBoxEvent aEventType)
       
    96     {
       
    97     switch (aEventType)
       
    98         {
       
    99         case EEventEnterKeyPressed:
       
   100         case EEventItemDoubleClicked:
       
   101             ShowSettingPageL(EFalse);
       
   102             break;
       
   103         default:
       
   104             break;
       
   105         }
       
   106     }
       
   107 
       
   108 // --------------------------------------------------------------------------------------------
       
   109 
       
   110 void CProfilerGuiSettingsViewDlg::TabChangedL(TInt /*aIndex*/)
       
   111     {
       
   112     iListBox->SetCurrentItemIndex(0);
       
   113 
       
   114     SetVisibilitiesOfSettingItemsL();   
       
   115     }
       
   116 
       
   117 // --------------------------------------------------------------------------------------------
       
   118 
       
   119 void CProfilerGuiSettingsViewDlg::ProcessCommandL(TInt aCommandId)
       
   120     {
       
   121     CAknDialog::ProcessCommandL(aCommandId);
       
   122 
       
   123     switch (aCommandId)
       
   124         {
       
   125         case EProfilerGuiCmdSettingsChange:
       
   126             ShowSettingPageL(ETrue);
       
   127             break;
       
   128         case EProfilerGuiCmdSettingsExit:
       
   129             TryExitL(EAknCmdExit);
       
   130             break;
       
   131         default:
       
   132             break;
       
   133         }
       
   134     }
       
   135 
       
   136 // --------------------------------------------------------------------------------------------
       
   137 
       
   138 TKeyResponse CProfilerGuiSettingsViewDlg::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
       
   139     {
       
   140     /*
       
   141     if (iTabGroup == NULL)
       
   142         {
       
   143         return EKeyWasNotConsumed;
       
   144         }
       
   145         */
       
   146 /*
       
   147     TInt active = iTabGroup->ActiveTabIndex();
       
   148     TInt count = iTabGroup->TabCount();
       
   149 
       
   150     switch ( aKeyEvent.iCode )
       
   151         {
       
   152         case EKeyLeftArrow:
       
   153             if (active > 0)
       
   154                 {
       
   155                 active--;
       
   156                 iTabGroup->SetActiveTabByIndex(active);
       
   157                 TabChangedL(active); 
       
   158                 }
       
   159             break;
       
   160         
       
   161         case EKeyRightArrow:
       
   162             if((active + 1) < count)
       
   163                 {
       
   164                 active++;
       
   165                 iTabGroup->SetActiveTabByIndex(active);
       
   166                 TabChangedL(active); 
       
   167                 }
       
   168             break;
       
   169         }
       
   170 */
       
   171     return CAknDialog::OfferKeyEventL(aKeyEvent, aType);
       
   172     }    
       
   173 
       
   174 // --------------------------------------------------------------------------------------------
       
   175 
       
   176 void CProfilerGuiSettingsViewDlg::PreLayoutDynInitL()
       
   177     {
       
   178     iListBox = static_cast<CAknSettingStyleListBox*>( Control(EProfilerGuiSettingItemList) );
       
   179     iListBox->SetMopParent(this);
       
   180     iListBox->CreateScrollBarFrameL(ETrue);
       
   181     iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
       
   182     iListBox->SetListBoxObserver(this);
       
   183 
       
   184     iSettingItemArray = new(ELeave) CAknSettingItemArray(16, EFalse, 0);
       
   185 
       
   186     CTextListBoxModel* model = iListBox->Model();
       
   187     model->SetItemTextArray(iSettingItemArray);
       
   188     model->SetOwnershipType(ELbmDoesNotOwnItemArray);
       
   189 
       
   190     UpdateListBoxL();    
       
   191     }
       
   192 
       
   193 // --------------------------------------------------------------------------------------------
       
   194 
       
   195 TBool CProfilerGuiSettingsViewDlg::OkToExitL(TInt aButtonId)
       
   196     {
       
   197     // save settings to iSettings before exiting
       
   198     
       
   199     // check if trace output target changed
       
   200     if(iTraceOutput == EOutputToDebugPort)
       
   201         {
       
   202         iSettings.iTraceOutput.Copy(KDebugOutput);
       
   203         }
       
   204     else
       
   205         {
       
   206         iSettings.iTraceOutput.Copy(KFileSystem);
       
   207         }
       
   208     
       
   209     // save trace file prefix
       
   210     if(iFilePrefix.CompareF(KNullDesC) != 0)
       
   211         {
       
   212         CnvUtfConverter::ConvertFromUnicodeToUtf8(iSettings.iTraceFilePrefix, iFilePrefix);
       
   213         }
       
   214     
       
   215     // save the drive 
       
   216     if(iSaveDrive.CompareF(KNullDesC) != 0)
       
   217         {
       
   218         CnvUtfConverter::ConvertFromUnicodeToUtf8(iSettings.iSaveFileDrive, iSaveDrive);
       
   219         }
       
   220     
       
   221     return CAknDialog::OkToExitL(aButtonId);
       
   222     }
       
   223 
       
   224 
       
   225 
       
   226 // --------------------------------------------------------------------------------------------
       
   227 
       
   228 void CProfilerGuiSettingsViewDlg::ShowSettingPageL(TInt aCalledFromMenu)
       
   229     {
       
   230     TInt listIndex = iListBox->CurrentItemIndex();
       
   231     TInt realIndex = iSettingItemArray->ItemIndexFromVisibleIndex(listIndex);
       
   232     CAknSettingItem* item = iSettingItemArray->At(realIndex);
       
   233     item->EditItemL(aCalledFromMenu);
       
   234     item->StoreL();
       
   235     SetVisibilitiesOfSettingItemsL();
       
   236     DrawNow();
       
   237     }
       
   238 
       
   239 // --------------------------------------------------------------------------------------------
       
   240 
       
   241 void CProfilerGuiSettingsViewDlg::SetVisibilitiesOfSettingItemsL()
       
   242     {
       
   243 
       
   244     // check if setting item array contains more than 0 items
       
   245     if (iSettingItemArray->Count() > 0)
       
   246         {
       
   247 //        ((*iSettingItemArray)[ESettingListItemPluginNameMode])->SetHidden(ETrue);
       
   248         ((*iSettingItemArray)[ESettingListItemPluginTraceOutput])->SetHidden(EFalse);
       
   249         if(iTraceOutput == EOutputToDebugPort)
       
   250         	{
       
   251         	((*iSettingItemArray)[ESettingListItemPluginSaveFileDrive])->SetHidden(ETrue);
       
   252         	((*iSettingItemArray)[ESettingListItemPluginTraceFilePrefix])->SetHidden(ETrue);
       
   253         	}
       
   254         else 
       
   255         	{
       
   256         	((*iSettingItemArray)[ESettingListItemPluginSaveFileDrive])->SetHidden(EFalse);
       
   257         	((*iSettingItemArray)[ESettingListItemPluginTraceFilePrefix])->SetHidden(EFalse);
       
   258         	}
       
   259 //        ((*iSettingItemArray)[ESettingListItemPluginTraceMode])->SetHidden(ETrue);
       
   260 
       
   261         iSettingItemArray->RecalculateVisibleIndicesL();
       
   262         iListBox->HandleItemAdditionL();
       
   263         iListBox->UpdateScrollBarsL();
       
   264         }
       
   265     }   
       
   266 
       
   267 // --------------------------------------------------------------------------------------------
       
   268 
       
   269 void CProfilerGuiSettingsViewDlg::UpdateListBoxL()
       
   270     {
       
   271     iSettingItemArray->ResetAndDestroy();
       
   272 
       
   273     // create items
       
   274     TInt ordinal(0);
       
   275     
       
   276 //    AddSettingItemL(ESettingListItemPluginNameMode,
       
   277 //                    R_PLUGIN_NAME_MODE_SETTING_TITLE,
       
   278 //                    R_PLUGIN_NAME_MODE_SETTING_PAGE,
       
   279 //                    R_PLUGIN_NAME_MODE_SETTING_TEXTS,
       
   280 //                    ordinal++);    
       
   281 
       
   282     AddSettingItemL(ESettingListItemPluginTraceOutput,
       
   283                     R_TRACE_OUTPUT_SETTING_TITLE,
       
   284                     R_TRACE_OUTPUT_SETTING_PAGE,
       
   285                     R_TRACE_OUTPUT_SETTING_TEXTS,
       
   286                     ordinal++);
       
   287     
       
   288     AddSettingItemL(ESettingListItemPluginSaveFileDrive,
       
   289                     R_SAVE_FILE_DRIVE_SETTING_TITLE,
       
   290                     R_SAVE_FILE_DRIVE_SETTING_PAGE,
       
   291                     NULL, //R_SAVE_FILE_DRIVE_SETTING_TEXTS,
       
   292                     ordinal++);
       
   293 
       
   294     AddSettingItemL(ESettingListItemPluginTraceFilePrefix,
       
   295                     R_SAVE_FILE_PREFIX_SETTING_TITLE,
       
   296                     R_SAVE_FILE_PREFIX_SETTING_PAGE,
       
   297                     NULL,
       
   298                     ordinal++);
       
   299     
       
   300     AddSettingItemL(ESettingListItemPluginSamplingTime,
       
   301                     R_TIMED_SAMPLING_PERIOD_SETTING_TITLE,
       
   302                     R_TIMED_SAMPLING_PERIOD_SETTING_PAGE,
       
   303                     NULL,
       
   304                     ordinal++);
       
   305     
       
   306     
       
   307 
       
   308 //    AddSettingItemL(ESettingListItemPluginTraceMode,
       
   309 //                    R_TRACE_MODE_SETTING_TITLE,
       
   310 //                    R_TRACE_MODE_SETTING_PAGE,
       
   311 //                    R_TRACE_MODE_SETTING_TEXTS,
       
   312 //                    ordinal++);
       
   313 
       
   314     SetVisibilitiesOfSettingItemsL(); 
       
   315     }
       
   316 
       
   317 // --------------------------------------------------------------------------------------------
       
   318 
       
   319 void CProfilerGuiSettingsViewDlg::AddSettingItemL(TInt aId,
       
   320                                                  TInt aTitleResource,
       
   321                                                  TInt aSettingPageResource,
       
   322                                                  TInt aAssociatedResource,
       
   323                                                  TInt aOrdinal)
       
   324     {
       
   325     // create a setting item
       
   326     CAknSettingItem* settingItem = NULL;
       
   327     
       
   328     switch (aId)
       
   329         {
       
   330 
       
   331         case ESettingListItemPluginSaveFileDrive:
       
   332             {
       
   333             CnvUtfConverter::ConvertToUnicodeFromUtf8(iSaveDrive, iSettings.iSaveFileDrive);
       
   334             settingItem = new(ELeave) CAknTextSettingItem(aId, iSaveDrive);
       
   335             settingItem->SetEmptyItemTextL(KEmptySettingItem); 
       
   336             break;
       
   337             }
       
   338         case ESettingListItemPluginTraceOutput:
       
   339             if(iSettings.iTraceOutput.MatchF(KDebugOutput) != KErrNotFound)
       
   340                 {
       
   341                 iTraceOutput = EOutputToDebugPort;
       
   342                 }
       
   343             else
       
   344                 {
       
   345                 iTraceOutput = EOutputToFileSystem;
       
   346                 }
       
   347             settingItem = new(ELeave) CAknEnumeratedTextPopupSettingItem(aId, iTraceOutput); 
       
   348 
       
   349             break;
       
   350 
       
   351         case ESettingListItemPluginTraceFilePrefix:
       
   352             {
       
   353             CnvUtfConverter::ConvertToUnicodeFromUtf8(iFilePrefix, iSettings.iTraceFilePrefix);
       
   354             settingItem = new(ELeave) CAknTextSettingItem(aId, iFilePrefix);
       
   355             settingItem->SetEmptyItemTextL(KEmptySettingItem); 
       
   356             break;
       
   357             }
       
   358         case ESettingListItemPluginSamplingTime:
       
   359             {
       
   360             settingItem = new(ELeave) CAknIntegerEdwinSettingItem(aId, iSettings.iTimedSamplingPeriod);
       
   361             break;
       
   362             }
       
   363         default:
       
   364             User::Panic(_L("NotSetItem"), 50);
       
   365             break;
       
   366 
       
   367         }
       
   368         
       
   369     CleanupStack::PushL(settingItem);
       
   370 
       
   371     // get title text
       
   372     HBufC* itemTitle = StringLoader::LoadLC(aTitleResource);
       
   373 
       
   374     // construct the setting item
       
   375     settingItem->ConstructL(EFalse, aOrdinal, *itemTitle, NULL, aSettingPageResource,
       
   376                             EAknCtPopupSettingList, NULL, aAssociatedResource);
       
   377     
       
   378     // append the setting item to settingitem array
       
   379     iSettingItemArray->InsertL(aOrdinal, settingItem);
       
   380 
       
   381     CleanupStack::PopAndDestroy(); //itemTitle
       
   382     CleanupStack::Pop(); //settingItem
       
   383     }
       
   384 
       
   385 // End of File
       
   386