sysanadatacapture/piprofiler/piprofilerui/gui/src/profiler_gui_mainview.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.hrh"
       
    22 #include "profiler_gui_mainview.h"
       
    23 #include "profiler_gui_maincontainer.h"
       
    24 #include "profiler_gui_document.h" 
       
    25 #include "profiler_gui_model.h"
       
    26 #include <piprofilerui.rsg>
       
    27 
       
    28 #include <aknwaitdialog.h>
       
    29 #include <aknglobalnote.h>
       
    30 #include <eikenv.h>
       
    31 #include <aknviewappui.h> 
       
    32 #include <akncontext.h>
       
    33 #include <stringloader.h>
       
    34 #include <aknnavi.h>
       
    35 #include <akntitle.h>
       
    36 #include <barsread.h>
       
    37 #include <aknnavide.h>
       
    38 #include <aknmessagequerydialog.h> 
       
    39 
       
    40 // ================= MEMBER FUNCTIONS =======================
       
    41 
       
    42 // ---------------------------------------------------------
       
    43 // CProfilerGuiMainView::ConstructL(const TRect& aRect)
       
    44 // EPOC two-phased constructor
       
    45 // ---------------------------------------------------------
       
    46 //
       
    47 void CProfilerGuiMainView::ConstructL()
       
    48     {
       
    49     BaseConstructL( R_PROFILER_GUI_VIEW_MAIN );
       
    50     
       
    51     iModel = static_cast<CProfilerGuiDocument*>(reinterpret_cast<CEikAppUi*>(iEikonEnv->AppUi())->Document())->Model();
       
    52     iNaviDecorator = NULL;
       
    53     iModel->SetMainView(this);
       
    54     }
       
    55 
       
    56 // ---------------------------------------------------------
       
    57 // CProfilerGuiMainView::~CProfilerGuiMainView()
       
    58 // ---------------------------------------------------------
       
    59 //
       
    60 CProfilerGuiMainView::~CProfilerGuiMainView()
       
    61     {
       
    62 
       
    63     if(iNaviDecorator)
       
    64     	{
       
    65     	delete iNaviDecorator;
       
    66     	iNaviDecorator = NULL;
       
    67     	}
       
    68     
       
    69     if (iContainer)
       
    70         {
       
    71         AppUi()->RemoveFromViewStack( *this, iContainer );
       
    72         delete iContainer;
       
    73         iContainer = NULL;
       
    74         }
       
    75     
       
    76     }
       
    77 
       
    78 // ---------------------------------------------------------
       
    79 // TUid CProfilerGuiMainView::Id()
       
    80 // ---------------------------------------------------------
       
    81 //
       
    82 TUid CProfilerGuiMainView::Id() const
       
    83     {
       
    84     return KMainViewUID;
       
    85     }
       
    86 
       
    87 // ---------------------------------------------------------
       
    88 // TUid CProfilerGuiMainView::DynInitMenuPaneL(TInt aResourceId, CEikMenuPane* aMenuPane)
       
    89 // ---------------------------------------------------------
       
    90 //
       
    91 void CProfilerGuiMainView::DynInitMenuPaneL(TInt aResourceId, CEikMenuPane* aMenuPane)
       
    92     {
       
    93     AppUi()->DynInitMenuPaneL(aResourceId, aMenuPane);
       
    94     }
       
    95 
       
    96   
       
    97 // ---------------------------------------------------------
       
    98 // CProfilerGuiMainView::HandleCommandL(TInt aCommand)
       
    99 // ---------------------------------------------------------
       
   100 //
       
   101 void CProfilerGuiMainView::HandleCommandL(TInt aCommand)
       
   102     {   
       
   103     switch ( aCommand )
       
   104         {
       
   105         // commands from sampler control sub menu 
       
   106         case EProfilerGuiCmdSamplerEnable:
       
   107             {
       
   108             iModel->DisableOrEnableSelectedOrHighlightedItemsL();
       
   109             break;
       
   110             }
       
   111         case EProfilerGuiCmdSamplerDisable:
       
   112             {
       
   113             iModel->DisableOrEnableSelectedOrHighlightedItemsL();
       
   114             break;
       
   115             }
       
   116         case EProfilerGuiCmdSamplerSettings:
       
   117             {
       
   118             // check if sampler settings dialog returned exit command
       
   119             iModel->EditSelectedSamplerL(iContainer->CurrentListBoxItemIndex());
       
   120             break;
       
   121             }
       
   122         case EProfilerGuiCmdSamplerInfo:
       
   123             {
       
   124             iModel->SelectedSamplerInfoL(iContainer->CurrentListBoxItemIndex());
       
   125             break;
       
   126             }
       
   127             
       
   128         case EProfilerGuiCmdStartAll:
       
   129             {
       
   130             // still using the old way of starting all the samplers simultaneously
       
   131             if( iModel->iState != MProfilerStatusObserver::ERunning )
       
   132             	{
       
   133             	// set state as "initializing" for a moment before profiling has started, 
       
   134             	// NOTE: engine changes to "Running" state
       
   135             	iModel->iState = MProfilerStatusObserver::EInitializing;
       
   136                 // start the actual sampling process on Profiler Engine 
       
   137                 iModel->StartAllSamplerItemsL();
       
   138             	}
       
   139 
       
   140 			// prevent the control of sampler specific settings during the trace 
       
   141             iContainer->SetDimmed(ETrue);
       
   142             break;
       
   143             }          
       
   144         case EProfilerGuiCmdStopAll:
       
   145             {
       
   146 			// check if still profiling
       
   147 			if( iModel->iState != MProfilerStatusObserver::EIdle )
       
   148 				{
       
   149 				// set to stopping mode
       
   150 				iModel->iState = MProfilerStatusObserver::EStopping;
       
   151                 // stop actual sampling process on Profiler Engine
       
   152 				iModel->StopAllSamplerItemsL();
       
   153 				}
       
   154             
       
   155 			// return the control to sampler specific settings when tracing stopped
       
   156 			iContainer->SetDimmed(EFalse);
       
   157 
       
   158             break;
       
   159             }
       
   160             
       
   161         default:
       
   162             {
       
   163             AppUi()->HandleCommandL(aCommand);
       
   164             break;
       
   165             }
       
   166         }
       
   167     }
       
   168 
       
   169 // ---------------------------------------------------------
       
   170 // CProfilerGuiMainView::HandleClientRectChange()
       
   171 // ---------------------------------------------------------
       
   172 //
       
   173 void CProfilerGuiMainView::HandleClientRectChange()
       
   174     {
       
   175     if ( iContainer )
       
   176         {
       
   177         iContainer->SetRect( ClientRect() );
       
   178         }
       
   179     }
       
   180 
       
   181 // ---------------------------------------------------------
       
   182 // CProfilerGuiMainView::DoActivateL(...)
       
   183 // ---------------------------------------------------------
       
   184 //
       
   185 void CProfilerGuiMainView::DoActivateL(
       
   186    const TVwsViewId& /*aPrevViewId*/,TUid /*aCustomMessageId*/,
       
   187    const TDesC8& /*aCustomMessage*/)
       
   188     {
       
   189     // show wait dialog
       
   190     CAknGlobalNote* waitDialog = CAknGlobalNote::NewLC();
       
   191     waitDialog->SetSoftkeys(R_AVKON_SOFTKEYS_EMPTY);
       
   192     TInt dialogId = waitDialog->ShowNoteL(EAknGlobalWaitNote, _L("Initializing samplers"));
       
   193 
       
   194     // setup the profiler engine status pane
       
   195     SetupStatusPaneL();
       
   196     
       
   197     // check if container creation succesfull
       
   198     if (!iContainer)
       
   199         {
       
   200         iContainer = new (ELeave) CProfilerGuiMainContainer;
       
   201         iModel->SetMainContainer(iContainer);
       
   202         iContainer->SetMopParent(this);
       
   203         iContainer->ConstructL( ClientRect() );
       
   204         iModel->NotifyContainerReadyL();
       
   205         AppUi()->AddToStackL( *this, iContainer );
       
   206         } 
       
   207     
       
   208 	// remove the wait dialog
       
   209 	waitDialog->CancelNoteL(dialogId);
       
   210 	CleanupStack::PopAndDestroy(); //waitDialog;
       
   211    }
       
   212 
       
   213 // ---------------------------------------------------------
       
   214 // CProfilerGuiMainView::DoDeactivate()
       
   215 // ---------------------------------------------------------
       
   216 //
       
   217 void CProfilerGuiMainView::DoDeactivate()
       
   218     {
       
   219     TRAP_IGNORE(CleanupStatusPaneL());
       
   220     
       
   221     if (iContainer)
       
   222         {
       
   223         AppUi()->RemoveFromViewStack( *this, iContainer );
       
   224         delete iContainer;
       
   225         iContainer = NULL;
       
   226         }
       
   227     }
       
   228 
       
   229 void CProfilerGuiMainView::HandleStatusPaneSizeChange()
       
   230 	{
       
   231 	CAknView::HandleStatusPaneSizeChange();
       
   232 	
       
   233 	TInt result;
       
   234 	TRAP(result, SetupStatusPaneL());
       
   235 	}
       
   236 
       
   237 
       
   238 void CProfilerGuiMainView::SetupStatusPaneL()
       
   239 	{
       
   240 	TUid naviPaneUid = TUid::Uid(EEikStatusPaneUidNavi);
       
   241 	CEikStatusPaneBase::TPaneCapabilities subPaneNavi = StatusPane()->PaneCapabilities(naviPaneUid);
       
   242 	if(subPaneNavi.IsPresent() && subPaneNavi.IsAppOwned())
       
   243 		{
       
   244 		CAknNavigationControlContainer* naviPane = static_cast<CAknNavigationControlContainer*> (StatusPane()->ControlL(naviPaneUid));
       
   245 		if(iNaviDecorator)
       
   246 			{
       
   247 			delete iNaviDecorator;
       
   248 			iNaviDecorator = NULL;
       
   249 			}
       
   250 		
       
   251 		// get the initial status label
       
   252 		HBufC* labelText = GetLabelTextLC(iModel->iState);
       
   253 		iNaviDecorator = naviPane->CreateNavigationLabelL(*labelText);
       
   254 		CleanupStack::PopAndDestroy(labelText);
       
   255 		
       
   256 		naviPane->PushL(*iNaviDecorator);
       
   257 		}
       
   258 	}
       
   259 
       
   260 void CProfilerGuiMainView::CleanupStatusPaneL()
       
   261 	{
       
   262 	// destructor for navi pane, called by destructor
       
   263 	TUid naviPaneUid = TUid::Uid(EEikStatusPaneUidNavi);
       
   264 	CEikStatusPaneBase::TPaneCapabilities subPaneNavi = StatusPane()->PaneCapabilities(naviPaneUid);
       
   265 	if(subPaneNavi.IsPresent() && subPaneNavi.IsAppOwned())
       
   266 		{
       
   267 		CAknNavigationControlContainer* naviPane = static_cast<CAknNavigationControlContainer*> (StatusPane()->ControlL(naviPaneUid));
       
   268 		if(iNaviDecorator)
       
   269 			{
       
   270 			naviPane->Pop(iNaviDecorator);
       
   271 			delete iNaviDecorator;
       
   272 			iNaviDecorator = NULL;
       
   273 			}
       
   274 		}
       
   275 	}
       
   276 
       
   277 HBufC* CProfilerGuiMainView::GetLabelTextLC(TInt aStatus)
       
   278 	{
       
   279 	// get the predefined status text
       
   280 	HBufC* labelText = NULL;
       
   281 	switch(aStatus)
       
   282 		{
       
   283 		case MProfilerStatusObserver::EIdle:
       
   284 			labelText = StringLoader::LoadLC(R_PROFILER_GUI_NAVI_TEXT_IDLE);
       
   285 			break;
       
   286 		case MProfilerStatusObserver::EInitializing:
       
   287 			labelText = StringLoader::LoadLC(R_PROFILER_GUI_NAVI_TEXT_INITIALIZING);
       
   288 			break;
       
   289 		case MProfilerStatusObserver::ERunning:
       
   290 			labelText = StringLoader::LoadLC(R_PROFILER_GUI_NAVI_TEXT_RUNNING);
       
   291 			break;
       
   292 		case MProfilerStatusObserver::EStopping:
       
   293 			labelText = StringLoader::LoadLC(R_PROFILER_GUI_NAVI_TEXT_STOPPING);
       
   294 			break;
       
   295 	     case MProfilerStatusObserver::ERestarting:
       
   296             labelText = StringLoader::LoadLC(R_PROFILER_GUI_NAVI_TEXT_RUNNING);
       
   297             break;
       
   298 	     default:
       
   299 	        labelText = StringLoader::LoadLC(R_PROFILER_GUI_NAVI_TEXT_IDLE); 
       
   300 	        break;
       
   301 		}
       
   302 	return labelText;
       
   303 	}
       
   304 
       
   305 void CProfilerGuiMainView::UpdateStatusPaneL( TInt aStatus )
       
   306 	{
       
   307 	TUid naviPaneUid = TUid::Uid(EEikStatusPaneUidNavi);
       
   308 	CEikStatusPaneBase::TPaneCapabilities subPaneNavi = StatusPane()->PaneCapabilities(naviPaneUid);
       
   309 	// check if navi pane is correctly initialized
       
   310 	if(subPaneNavi.IsPresent() && subPaneNavi.IsAppOwned())
       
   311 		{
       
   312 		CAknNavigationControlContainer* naviPane = static_cast<CAknNavigationControlContainer*> (StatusPane()->ControlL(naviPaneUid));
       
   313 		if(iNaviDecorator)
       
   314 			{
       
   315 			delete iNaviDecorator;
       
   316 			iNaviDecorator = NULL;
       
   317 			}
       
   318 		HBufC* labelText;
       
   319 
       
   320 		// get the right status label text 
       
   321 		labelText = GetLabelTextLC(aStatus);
       
   322 		iNaviDecorator = naviPane->CreateNavigationLabelL(*labelText);
       
   323 		CleanupStack::PopAndDestroy(labelText);
       
   324 		
       
   325 		naviPane->PushL(*iNaviDecorator);
       
   326 		}
       
   327 	}
       
   328 
       
   329 
       
   330 // End of File