perfmon/ui/avkon/src/perfmon_appui.cpp
branchRCL_3
changeset 22 fad26422216a
parent 21 b3cee849fa46
child 23 f8280f3bfeb7
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 "perfmon_appui.h"
       
    21 #include "perfmon_valuesview.h"
       
    22 #include "perfmon_graphsview.h"
       
    23 #include "perfmon_datapopupcontainer.h"
       
    24 #include "perfmon.hrh"
       
    25 #include "perfmon_model.h"
       
    26 #include "perfmon_document.h"
       
    27 #include <perfmon.rsg>
       
    28 
       
    29 #include <avkon.hrh>
       
    30 #include <AknQueryDialog.h>
       
    31 #include <aknmessagequerydialog.h> 
       
    32 
       
    33 
       
    34 // ================= MEMBER FUNCTIONS =======================
       
    35 
       
    36 // --------------------------------------------------------------------------------------------
       
    37 
       
    38 void CPerfMonAppUi::ConstructL()
       
    39     {
       
    40     // disable window server priority control for this application
       
    41     iEikonEnv->WsSession().ComputeMode( RWsSession::EPriorityControlDisabled );
       
    42 
       
    43     // set as system application to prevent getting shut down events 
       
    44     iEikonEnv->SetSystem(ETrue);
       
    45     
       
    46     BaseConstructL(EAknEnableSkin);
       
    47 
       
    48     iModel = static_cast<CPerfMonDocument*>(reinterpret_cast<CEikAppUi*>(iEikonEnv->AppUi())->Document())->Model();
       
    49 
       
    50     // Show tabs for main views from resources
       
    51     CEikStatusPane* sp = StatusPane();
       
    52 
       
    53     // Fetch pointer to the default navi pane control
       
    54     iNaviPane = (CAknNavigationControlContainer*)sp->ControlL( 
       
    55         TUid::Uid(EEikStatusPaneUidNavi));
       
    56 
       
    57     // Tabgroup has been read from resource and it were pushed to the navi pane. 
       
    58     // Get pointer to the navigation decorator with the ResourceDecorator() function. 
       
    59     // Application owns the decorator and it has responsibility to delete the object.
       
    60     iDecoratedTabGroup = iNaviPane->ResourceDecorator();
       
    61     if (iDecoratedTabGroup)
       
    62         {
       
    63         iTabGroup = (CAknTabGroup*) iDecoratedTabGroup->DecoratedControl();
       
    64         }
       
    65         
       
    66     CPerfMonValuesView* valuesView = new(ELeave) CPerfMonValuesView;
       
    67     CleanupStack::PushL(valuesView);
       
    68     valuesView->ConstructL();
       
    69     AddViewL(valuesView);           // transfer ownership to CAknViewAppUi
       
    70     CleanupStack::Pop();            // valuesView
       
    71 
       
    72     CPerfMonGraphsView* graphsView = new(ELeave) CPerfMonGraphsView;
       
    73     CleanupStack::PushL(graphsView);
       
    74     graphsView->ConstructL();
       
    75     AddViewL(graphsView);           // transfer ownership to CAknViewAppUi
       
    76     CleanupStack::Pop();            // graphsView
       
    77     
       
    78     // set the default view
       
    79     SetDefaultViewL(*valuesView);
       
    80 
       
    81     // notify the model that everything has been constructed
       
    82     iModel->ActivateModelL();
       
    83     }
       
    84 
       
    85 // --------------------------------------------------------------------------------------------
       
    86 
       
    87 CPerfMonAppUi::~CPerfMonAppUi()
       
    88     {
       
    89     // notify the model that the application is closing
       
    90     if (iModel)    
       
    91         TRAP_IGNORE(iModel->DeActivateModelL());
       
    92     
       
    93     delete iDecoratedTabGroup;
       
    94     }
       
    95 
       
    96 // --------------------------------------------------------------------------------------------
       
    97 
       
    98 void CPerfMonAppUi::DynInitMenuPaneL(TInt aResourceId, CEikMenuPane* aMenuPane)
       
    99     {
       
   100     if (aResourceId == R_PERFMON_APP_MENU)
       
   101         {
       
   102         aMenuPane->SetItemDimmed(EPerfMonCmdEnableLogging, iModel->Settings().iLoggingEnabled);
       
   103         aMenuPane->SetItemDimmed(EPerfMonCmdDisableLogging, !iModel->Settings().iLoggingEnabled);
       
   104         }
       
   105     }
       
   106 
       
   107 // --------------------------------------------------------------------------------------------
       
   108 
       
   109 TKeyResponse CPerfMonAppUi::HandleKeyEventL(const TKeyEvent& aKeyEvent, TEventCode /*aType*/)
       
   110     {
       
   111     if ( iTabGroup == NULL )
       
   112         {
       
   113         return EKeyWasNotConsumed;
       
   114         }
       
   115 
       
   116     TInt active = iTabGroup->ActiveTabIndex();
       
   117     TInt count = iTabGroup->TabCount();
       
   118 
       
   119     switch ( aKeyEvent.iCode )
       
   120         {
       
   121         case EKeyLeftArrow:
       
   122             if (active > 0)
       
   123                 {
       
   124                 active--;
       
   125                 iTabGroup->SetActiveTabByIndex( active );
       
   126                 ActivateLocalViewL(TUid::Uid(iTabGroup->TabIdFromIndex(active)));
       
   127                 }
       
   128             break;
       
   129         case EKeyRightArrow:
       
   130             if((active + 1) < count)
       
   131                 {
       
   132                 active++;
       
   133                 iTabGroup->SetActiveTabByIndex( active );
       
   134                 ActivateLocalViewL(TUid::Uid(iTabGroup->TabIdFromIndex(active)));
       
   135                 }
       
   136             break;
       
   137         default:
       
   138             return EKeyWasNotConsumed;
       
   139         }
       
   140 
       
   141     return EKeyWasConsumed;
       
   142     }
       
   143 
       
   144 
       
   145 // --------------------------------------------------------------------------------------------
       
   146 
       
   147 void CPerfMonAppUi::HandleCommandL(TInt aCommand)
       
   148     {
       
   149     switch ( aCommand )
       
   150         {
       
   151         case EPerfMonCmdEnableLogging:
       
   152             {
       
   153             iModel->EnableLogging(ETrue);
       
   154             break;
       
   155             }
       
   156 
       
   157         case EPerfMonCmdDisableLogging:
       
   158             {
       
   159             iModel->EnableLogging(EFalse);
       
   160             break;
       
   161             }
       
   162                         
       
   163         case EPerfMonCmdSettings:
       
   164             {
       
   165             if (iModel->LaunchSettingsDialogL() == EAknCmdExit)
       
   166                 Exit();
       
   167             break;
       
   168             }
       
   169 
       
   170         case EPerfMonCmdAbout:
       
   171             {
       
   172 	        CAknMessageQueryDialog* dialog = new(ELeave) CAknMessageQueryDialog;
       
   173             dialog->ExecuteLD(R_PERFMON_ABOUT_DIALOG);
       
   174             }
       
   175             break;
       
   176             
       
   177         // a normal way to close an application
       
   178         case EAknCmdExit:
       
   179         case EEikCmdExit:
       
   180         case EAknSoftkeyExit: 
       
   181 			{
       
   182             Exit();
       
   183 			}
       
   184             break;
       
   185 
       
   186         default:
       
   187             break;      
       
   188         }
       
   189     }
       
   190 
       
   191 // --------------------------------------------------------------------------------------------
       
   192 
       
   193 void CPerfMonAppUi::HandleForegroundEventL(TBool aForeground)
       
   194     {
       
   195     // handle visibility of the data popup container
       
   196     if (iModel && iModel->DataPopupContainer())
       
   197         {
       
   198         iModel->DataPopupContainer()->UpdateVisibility(aForeground);
       
   199         }
       
   200     
       
   201     // call the base class
       
   202     CAknAppUi::HandleForegroundEventL(aForeground); 
       
   203     }
       
   204 
       
   205 // --------------------------------------------------------------------------------------------
       
   206 
       
   207 void CPerfMonAppUi::HandleResourceChangeL(TInt aType)
       
   208     {
       
   209     CAknAppUi::HandleResourceChangeL(aType);
       
   210 
       
   211     // update size of the data popup container (implemented here because data popup container
       
   212     // does not get HandleResourceChangeL events)
       
   213     if (aType == KEikDynamicLayoutVariantSwitch)
       
   214         {
       
   215         if (iModel)
       
   216             {
       
   217             if (iModel->DataPopupContainer())
       
   218                 {
       
   219                 iModel->DataPopupContainer()->SetPositionAndSize();
       
   220                 }
       
   221             
       
   222             }
       
   223         }
       
   224     }
       
   225 
       
   226 // --------------------------------------------------------------------------------------------
       
   227 
       
   228 // End of File