sysanadatacapture/piprofiler/piprofilerui/gui/src/profiler_gui_settingsviewdlg.cpp
changeset 1 3ff3fecb12fe
equal deleted inserted replaced
0:f0f2b8682603 1:3ff3fecb12fe
       
     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(ESettingListItemPluginTraceMode,
       
   301 //                    R_TRACE_MODE_SETTING_TITLE,
       
   302 //                    R_TRACE_MODE_SETTING_PAGE,
       
   303 //                    R_TRACE_MODE_SETTING_TEXTS,
       
   304 //                    ordinal++);
       
   305 
       
   306     SetVisibilitiesOfSettingItemsL(); 
       
   307     }
       
   308 
       
   309 // --------------------------------------------------------------------------------------------
       
   310 
       
   311 void CProfilerGuiSettingsViewDlg::AddSettingItemL(TInt aId,
       
   312                                                  TInt aTitleResource,
       
   313                                                  TInt aSettingPageResource,
       
   314                                                  TInt aAssociatedResource,
       
   315                                                  TInt aOrdinal)
       
   316     {
       
   317     // create a setting item
       
   318     CAknSettingItem* settingItem = NULL;
       
   319     
       
   320     switch (aId)
       
   321         {
       
   322 
       
   323         case ESettingListItemPluginSaveFileDrive:
       
   324             {
       
   325             CnvUtfConverter::ConvertToUnicodeFromUtf8(iSaveDrive, iSettings.iSaveFileDrive);
       
   326             settingItem = new(ELeave) CAknTextSettingItem(aId, iSaveDrive);
       
   327             settingItem->SetEmptyItemTextL(KEmptySettingItem); 
       
   328             break;
       
   329             }
       
   330         case ESettingListItemPluginTraceOutput:
       
   331             if(iSettings.iTraceOutput.MatchF(KDebugOutput) != KErrNotFound)
       
   332                 {
       
   333                 iTraceOutput = EOutputToDebugPort;
       
   334                 }
       
   335             else
       
   336                 {
       
   337                 iTraceOutput = EOutputToFileSystem;
       
   338                 }
       
   339             settingItem = new(ELeave) CAknEnumeratedTextPopupSettingItem(aId, iTraceOutput); 
       
   340 
       
   341             break;
       
   342 
       
   343         case ESettingListItemPluginTraceFilePrefix:
       
   344             {
       
   345             CnvUtfConverter::ConvertToUnicodeFromUtf8(iFilePrefix, iSettings.iTraceFilePrefix);
       
   346             settingItem = new(ELeave) CAknTextSettingItem(aId, iFilePrefix);
       
   347             settingItem->SetEmptyItemTextL(KEmptySettingItem); 
       
   348             break;
       
   349             }
       
   350         default:
       
   351             User::Panic(_L("NotSetItem"), 50);
       
   352             break;
       
   353 
       
   354         }
       
   355         
       
   356     CleanupStack::PushL(settingItem);
       
   357 
       
   358     // get title text
       
   359     HBufC* itemTitle = StringLoader::LoadLC(aTitleResource);
       
   360 
       
   361     // construct the setting item
       
   362     settingItem->ConstructL(EFalse, aOrdinal, *itemTitle, NULL, aSettingPageResource,
       
   363                             EAknCtPopupSettingList, NULL, aAssociatedResource);
       
   364     
       
   365     // append the setting item to settingitem array
       
   366     iSettingItemArray->InsertL(aOrdinal, settingItem);
       
   367 
       
   368     CleanupStack::PopAndDestroy(); //itemTitle
       
   369     CleanupStack::Pop(); //settingItem
       
   370     }
       
   371 
       
   372 // End of File
       
   373