stifui/stifui/src/StatisticsView.cpp
branchRCL_3
changeset 9 404ad6c9bc20
parent 8 87e9ebfbe96a
child 11 454d022d514b
equal deleted inserted replaced
8:87e9ebfbe96a 9:404ad6c9bc20
     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: This file contains CStatisticsView class 
       
    15 * definition.
       
    16 *
       
    17 */
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include  <eikmenub.h>
       
    21 #include  <aknViewAppUi.h>
       
    22 #include  <aknlistquerydialog.h> 
       
    23 #include  <barsread.h>	//TResourceReader
       
    24 #include  <Stifui.rsg>
       
    25 #include  "AppUIAppUi.h"
       
    26 #include  "Stifui.hrh" 
       
    27 #include  "StatisticsView.h"
       
    28 #include  "StatisticsContainer.h"
       
    29 
       
    30 // ================= MEMBER FUNCTIONS =======================
       
    31 // ----------------------------------------------------------------------------
       
    32 // CStatisticsView::ConstructL
       
    33 // 
       
    34 // Symbian OS two-phased constructor.
       
    35 // ----------------------------------------------------------------------------
       
    36 //
       
    37 void CStatisticsView::ConstructL()
       
    38     {
       
    39     CView::ConstructL();
       
    40     BaseConstructL( R_APPUI_STATISTICSVIEW );
       
    41     iCurrentTestCase = 0;
       
    42     }
       
    43 
       
    44 // ----------------------------------------------------------------------------
       
    45 // CStatisticsView::~CStatisticsView
       
    46 // 
       
    47 // Destructor.
       
    48 // ----------------------------------------------------------------------------
       
    49 //
       
    50 CStatisticsView::~CStatisticsView()
       
    51     {
       
    52     if ( iContainer )
       
    53         {
       
    54         AppUi()->RemoveFromViewStack( *this, iContainer );
       
    55         delete iContainer;
       
    56         }
       
    57     delete iNaviDecorator;
       
    58     iNaviDecorator = NULL;
       
    59     }
       
    60 
       
    61 // ----------------------------------------------------------------------------
       
    62 // CStatisticsView::Id
       
    63 // 
       
    64 // Returns view´s id.
       
    65 // ----------------------------------------------------------------------------
       
    66 //
       
    67 TUid CStatisticsView::Id() const
       
    68     {
       
    69     return TUid::Uid(EStatisticsViewId);
       
    70     }
       
    71 
       
    72 // ----------------------------------------------------------------------------
       
    73 // CStatisticsView::HandleCommandL
       
    74 // 
       
    75 // Handles a command.
       
    76 // ----------------------------------------------------------------------------
       
    77 //
       
    78 void CStatisticsView::HandleCommandL(TInt aCommand)
       
    79     {   
       
    80     if ( aCommand >= ECmdFilterByModule && aCommand < ECmdFilterByTestCaseFile ) // 0x1000 - 0x1FFF
       
    81         {
       
    82         TInt moduleNumber = aCommand - ECmdFilterByModule;
       
    83 
       
    84         RRefArray<TDesC> moduleName;
       
    85         TInt ret = ((CAppUIAppUi*)AppUi())->UIStoreHandler()->Modules( moduleName );
       
    86         if( KErrNone != ret )
       
    87             {
       
    88             moduleName.Reset();
       
    89             moduleName.Close();
       
    90             User::Leave( ret );
       
    91             }
       
    92         //iFilterModule = testModules[moduleNumber];
       
    93 
       
    94         iContainer->FilterCasesByModuleL( moduleName[moduleNumber] );
       
    95 
       
    96         moduleName.Reset();
       
    97         moduleName.Close();
       
    98 
       
    99         return;
       
   100         }
       
   101 
       
   102     if ( aCommand >= ECmdFilterByTestCaseFile && aCommand < ECmdNOFiltering )
       
   103         {
       
   104         TInt testCaseFileNumber = aCommand - ECmdFilterByTestCaseFile;
       
   105         RRefArray<TDesC> testCaseFileName;
       
   106         TInt ret = ((CAppUIAppUi*)AppUi())->UIStoreHandler()->TestCaseFiles( testCaseFileName );
       
   107         if( KErrNone != ret )
       
   108             {
       
   109             testCaseFileName.Reset();
       
   110             testCaseFileName.Close();
       
   111             User::Leave( ret );
       
   112             }
       
   113 
       
   114         iContainer->FilterCasesByTCFileNameL( testCaseFileName[testCaseFileNumber] );
       
   115 
       
   116         testCaseFileName.Reset();
       
   117         testCaseFileName.Close();
       
   118 
       
   119         return;
       
   120         }
       
   121 
       
   122     if ( aCommand == ECmdNOFiltering )
       
   123         {
       
   124         iContainer->NoFilteringL();
       
   125         return;
       
   126         }
       
   127 
       
   128     switch ( aCommand )
       
   129         {
       
   130         case ECmdStartCases:
       
   131             {
       
   132             iCurrentTestCase = iContainer->CurrentItemIndex();
       
   133             StartTestCasesL();
       
   134             break;
       
   135             }
       
   136         case EAknSoftkeyBack:
       
   137             {
       
   138             AppUi()->HandleCommandL( EAppUIGoBack );
       
   139             break;
       
   140             }
       
   141         default:
       
   142             {
       
   143             AppUi()->HandleCommandL( aCommand );
       
   144             break;
       
   145             }
       
   146         }
       
   147 
       
   148     }
       
   149 
       
   150 // ----------------------------------------------------------------------------
       
   151 // CStatisticsView::HandleClientRectChange
       
   152 // 
       
   153 // Handles client rect changes.
       
   154 // ----------------------------------------------------------------------------
       
   155 //
       
   156 void CStatisticsView::HandleClientRectChange()
       
   157     {
       
   158     if ( iContainer )
       
   159         {
       
   160         iContainer->SetRect( ClientRect() );
       
   161         }
       
   162     }
       
   163 
       
   164 // ----------------------------------------------------------------------------
       
   165 // CStatisticsView::DoActivateL
       
   166 // 
       
   167 // Initializes view when activated.
       
   168 // ----------------------------------------------------------------------------
       
   169 //
       
   170 void CStatisticsView::DoActivateL(
       
   171    const TVwsViewId& /*aPrevViewId*/,TUid /*aCustomMessageId*/,
       
   172    const TDesC8& /*aCustomMessage*/)
       
   173     {
       
   174     if (!iContainer)
       
   175         {
       
   176            ((CAppUIAppUi*)AppUi())->iLogger->Log(_L("StatisticsView: DoActivateL"));
       
   177         //message = _L("eng.open ret:");
       
   178         //message.AppendNum( ret , EDecimal );
       
   179         //AppUi()->iLogger->Log( message );
       
   180         iContainer = new (ELeave) CStatisticsContainer;
       
   181         iContainer->SetMopParent(this);
       
   182         iContainer->ConstructL( ClientRect(), this );
       
   183            ((CAppUIAppUi*)AppUi())->iLogger->Log(_L("StatisticsView: container constructed"));
       
   184         AppUi()->AddToStackL( *this, iContainer );
       
   185         }
       
   186     iContainer->SetCurrentItemIndex(iCurrentTestCase);
       
   187 	
       
   188 	CEikStatusPane* sp=iEikonEnv->AppUiFactory()->StatusPane();
       
   189 	CAknNavigationControlContainer* np= (CAknNavigationControlContainer *)sp->ControlL(TUid::Uid(EEikStatusPaneUidNavi));
       
   190 	
       
   191 	TResourceReader reader;
       
   192 	iCoeEnv->CreateResourceReaderLC(reader,R_NAVITITLE_STARTED_STATS);
       
   193 	iNaviDecorator = np->CreateNavigationLabelL( reader );
       
   194 	CleanupStack::PopAndDestroy(); // resource reader
       
   195 	np->PushL(*iNaviDecorator);
       
   196     }
       
   197 
       
   198 // ----------------------------------------------------------------------------
       
   199 // CStatisticsView::DoDeactivate
       
   200 // 
       
   201 // Deactivates view.
       
   202 // ----------------------------------------------------------------------------
       
   203 //
       
   204 void CStatisticsView::DoDeactivate()
       
   205     {
       
   206     if ( iContainer )
       
   207         {
       
   208         iContainer->SaveActiveLine();
       
   209         AppUi()->RemoveFromViewStack( *this, iContainer );
       
   210         delete iContainer;
       
   211         iContainer = NULL;
       
   212         }
       
   213     delete iNaviDecorator;
       
   214     iNaviDecorator = NULL;
       
   215     }
       
   216 
       
   217 // ----------------------------------------------------------------------------
       
   218 // CStatisticsView::DynInitMenuPaneL
       
   219 // 
       
   220 // Initializes menu pane.
       
   221 // ----------------------------------------------------------------------------
       
   222 //
       
   223 void CStatisticsView::DynInitMenuPaneL(
       
   224     TInt aResourceId, CEikMenuPane* aMenuPane)
       
   225     {
       
   226 
       
   227     // Test modules are added to filter by test module submenu if the submenu is opened
       
   228     if (R_APPUI_FILTERBYMODULES_MENU == aResourceId)
       
   229         {
       
   230         RRefArray<TDesC> modules;
       
   231         TInt ret = ((CAppUIAppUi*)AppUi())->UIStoreHandler()->Modules( modules );
       
   232         if( KErrNone != ret )
       
   233             {
       
   234             modules.Reset();
       
   235             modules.Close();
       
   236             User::Leave( ret );
       
   237             }
       
   238 
       
   239         TInt moduleCount = modules.Count();
       
   240         
       
   241         TInt i;
       
   242         CEikMenuPaneItem::SData item;
       
   243 
       
   244         item.iCommandId = ECmdFilterByModule;
       
   245         item.iFlags = 0;
       
   246         item.iCascadeId = 0;
       
   247 
       
   248         for (i = 0; i < moduleCount; i++)
       
   249             {
       
   250             item.iText = modules[i];
       
   251             aMenuPane->AddMenuItemL(item);
       
   252             item.iCommandId++; // command IDs 0x1000 - 0x1FFF are reserved for modules in hrh file
       
   253             }
       
   254         
       
   255         modules.Reset();
       
   256         modules.Close();
       
   257         }
       
   258 
       
   259     // Test case files are added to filter by test case file submenu if the submenu is opened
       
   260     if (R_APPUI_FILTER_BY_TESTCASEFILE_MENU == aResourceId)
       
   261         {
       
   262         RRefArray<TDesC> testCaseFiles;
       
   263         TInt ret = ((CAppUIAppUi*)AppUi())->UIStoreHandler()->TestCaseFiles( testCaseFiles );
       
   264         if( KErrNone != ret )
       
   265             {
       
   266             testCaseFiles.Reset();
       
   267             testCaseFiles.Close();
       
   268             User::Leave( ret );
       
   269             }
       
   270 
       
   271         TInt testCaseFileCount = testCaseFiles.Count();
       
   272 
       
   273         TInt i;
       
   274         CEikMenuPaneItem::SData item;
       
   275 
       
   276         item.iCommandId = ECmdFilterByTestCaseFile;
       
   277         item.iFlags = 0;
       
   278         item.iCascadeId = 0;
       
   279 
       
   280         for (i = 0; i < testCaseFileCount; i++)
       
   281             {
       
   282             item.iText = testCaseFiles[i];
       
   283             aMenuPane->AddMenuItemL(item);
       
   284             item.iCommandId++; // command IDs 0x2000 - 0x2FFF are reserved for test case files in hrh file
       
   285             }
       
   286 
       
   287         testCaseFiles.Reset();
       
   288         testCaseFiles.Close();
       
   289         }
       
   290 
       
   291     }
       
   292 
       
   293 // ----------------------------------------------------------------------------
       
   294 // CStatisticsView::HandleListBoxEventL
       
   295 // 
       
   296 // Handles a list box event.
       
   297 // ----------------------------------------------------------------------------
       
   298 //
       
   299 void CStatisticsView::HandleListBoxEventL(CEikListBox* /*aListBox*/, TListBoxEvent aEventType)
       
   300 	{
       
   301 	if ( ( aEventType == EEventEnterKeyPressed ) || ( aEventType == EEventItemDoubleClicked ) )
       
   302 		{
       
   303         //iCurrentTestCase = aListBox->CurrentItemIndex();
       
   304         //iCurrentTestCase = iContainer->CurrentItemIndex();
       
   305         //StartTestCases();
       
   306         }
       
   307     }
       
   308 
       
   309 // ----------------------------------------------------------------------------
       
   310 // CStatisticsView::StartTestCases
       
   311 // 
       
   312 // Starts test case(s) which is selected in containers list box.
       
   313 // First shows a list query if user wants just start test case or
       
   314 // if he wants to start test case and view test case output.
       
   315 // ----------------------------------------------------------------------------
       
   316 //
       
   317 void CStatisticsView::StartTestCasesL()
       
   318     {
       
   319     TInt selectedItem(0);
       
   320     CAknListQueryDialog* startDialog = new (ELeave) CAknListQueryDialog(&selectedItem);
       
   321     if ( startDialog->ExecuteLD(R_START_TESTCASE_LIST_QUERY) )
       
   322         {
       
   323         RRefArray<CTestInfo> testInfo;
       
   324         TInt ret = ((CAppUIAppUi*)AppUi())->UIStoreHandler()->TestCases( testInfo );
       
   325         if( KErrNone != ret )
       
   326             {
       
   327             testInfo.Reset();
       
   328             testInfo.Close();
       
   329             User::Leave( ret );
       
   330             }
       
   331         TInt testCaseNumber = testInfo[0].TestCaseNum();
       
   332         TInt testCaseIndex( 0 );
       
   333 
       
   334         //CUIEngineContainer* container = NULL;
       
   335         ret = ((CAppUIAppUi*)AppUi())->UIStoreHandler()->StartTestCase( testInfo[testCaseNumber], testCaseIndex );
       
   336         if( KErrNone != ret )
       
   337             {
       
   338             User::Leave( ret );
       
   339             }
       
   340         testInfo.Reset();
       
   341         testInfo.Close();
       
   342 
       
   343         // Increment the counter value
       
   344         ((CAppUIAppUi*)AppUi())->iUIStoreHandler->iExecutedTestCaseCount++;
       
   345 
       
   346         }
       
   347 
       
   348     }
       
   349 
       
   350 // End of File