perfapps/perfmon/ui/avkon/src/perfmon_valuescontainer.cpp
changeset 51 b048e15729d6
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 // INCLUDE FILES
       
    20 #include "perfmon_valuescontainer.h"
       
    21 #include "perfmon.hrh"
       
    22 #include "perfmon_document.h"
       
    23 #include "perfmon_appui.h"
       
    24 #include "perfmon_model.h"
       
    25 
       
    26 #include <AknUtils.h>
       
    27 
       
    28 _LIT(KFreeFormat,"%S free %S%S"); 
       
    29 _LIT(KSizeFormat,"%S size %S%S"); 
       
    30 
       
    31 const TInt KLeftMargin = 2;
       
    32 
       
    33 
       
    34 // ===================================== MEMBER FUNCTIONS =====================================
       
    35 
       
    36 void CPerfMonValuesContainer::ConstructL(const TRect& aRect)
       
    37     {
       
    38     iModel = static_cast<CPerfMonDocument*>(reinterpret_cast<CEikAppUi*>(iEikonEnv->AppUi())->Document())->Model();
       
    39     iFont = AknLayoutUtils::FontFromId(EAknLogicalFontSecondaryFont);
       
    40  
       
    41     CreateWindowL();
       
    42     SetRect(aRect);
       
    43     SetBlank();
       
    44 
       
    45     ActivateL();
       
    46     }
       
    47 
       
    48 // --------------------------------------------------------------------------------------------
       
    49 
       
    50 CPerfMonValuesContainer::~CPerfMonValuesContainer()
       
    51     {
       
    52     }
       
    53     
       
    54 // --------------------------------------------------------------------------------------------
       
    55 
       
    56 void CPerfMonValuesContainer::Draw(const TRect& aRect) const
       
    57     {
       
    58     CWindowGc& gc = SystemGc();
       
    59     gc.SetBrushColor(KRgbWhite);
       
    60     gc.Clear(aRect);
       
    61     
       
    62     // check if sample array has been constructed
       
    63     if (iModel->SampleEntryArray())
       
    64         {
       
    65         // init font
       
    66         gc.SetPenColor(KRgbBlack);
       
    67         gc.UseFont( iFont );
       
    68         TUint separator = iFont->HeightInPixels()-2;
       
    69 
       
    70         // draw CPU %
       
    71         TBuf<64> cpuText;
       
    72         cpuText.Copy(_L("CPU: "));
       
    73 
       
    74         for (TInt i=iModel->CPU0PositionInSamples(); i<iModel->CPU0PositionInSamples()+iModel->AmountOfCPUs(); i++)
       
    75             {
       
    76             // check if data available
       
    77             if (iModel->SampleEntryArray()->At(i).iSampleDataArray->Count() > 0)
       
    78                 {
       
    79                 TSampleData& currentSample = iModel->SampleEntryArray()->At(i).iSampleDataArray->At(0);
       
    80                 
       
    81                 cpuText.AppendNum( currentSample.iSize > 0 ? TInt( (1 - ((TReal)(currentSample.iFree) / (TReal)currentSample.iSize)) * 100) : 0 );
       
    82                 cpuText.Append(_L("% "));
       
    83                 }
       
    84 
       
    85             }
       
    86         gc.DrawText(cpuText, TPoint(KLeftMargin,separator));
       
    87         
       
    88         TInt c(2);  // line counter
       
    89 
       
    90         // draw RAM and Drive values
       
    91         for (TInt i=iModel->RAMPositionInSamples(); i<iModel->PowerPositionInSamples(); i++)
       
    92             {
       
    93             // check if data available
       
    94             if (iModel->SampleEntryArray()->At(i).iSampleDataArray->Count() > 0)
       
    95                 {
       
    96                 TSampleData& currentSample = iModel->SampleEntryArray()->At(i).iSampleDataArray->At(0);
       
    97 
       
    98                 if (currentSample.iSize > 0) // draw only when size is known, this should ignore absent drives
       
    99                     {
       
   100                     TBuf<32> amountBuf;
       
   101                     amountBuf.AppendNum(currentSample.iFree, TRealFormat(KDefaultRealWidth, 0));
       
   102         
       
   103                     TBuf<32> buf;
       
   104                     buf.Format(KFreeFormat, &iModel->SampleEntryArray()->At(i).iDescription, &amountBuf, &iModel->SampleEntryArray()->At(i).iUnitTypeShort);
       
   105                     gc.DrawText(buf, TPoint(KLeftMargin,separator*c));
       
   106                     c++;
       
   107                     
       
   108                     amountBuf.Copy(KNullDesC);
       
   109                     amountBuf.AppendNum(currentSample.iSize, TRealFormat(KDefaultRealWidth, 0));
       
   110         
       
   111                     buf.Format(KSizeFormat, &iModel->SampleEntryArray()->At(i).iDescription, &amountBuf, &iModel->SampleEntryArray()->At(i).iUnitTypeShort);
       
   112                     gc.DrawText(buf, TPoint(KLeftMargin,separator*c));
       
   113                     c++;
       
   114                     }
       
   115                 }
       
   116             }
       
   117             
       
   118         // draw power value
       
   119         if (iModel->SampleEntryArray()->At(iModel->PowerPositionInSamples()).iSampleDataArray->Count() > 0)
       
   120             {
       
   121             TSampleData& currentSample = iModel->SampleEntryArray()->At(iModel->PowerPositionInSamples()).iSampleDataArray->At(0);
       
   122 
       
   123             if (currentSample.iSize > 0)
       
   124                 {
       
   125                 TBuf<32> powerText;
       
   126                 powerText.Copy(_L("Power "));
       
   127 
       
   128                 powerText.AppendNum(currentSample.iSize - currentSample.iFree, TRealFormat(KDefaultRealWidth, 0));
       
   129                 powerText.AppendFormat(_L("%S"), &iModel->SampleEntryArray()->At(iModel->PowerPositionInSamples()).iUnitTypeShort);
       
   130 
       
   131                 gc.DrawText(powerText, TPoint(KLeftMargin,separator*c));
       
   132                 }
       
   133             }
       
   134             
       
   135         gc.DiscardFont();        
       
   136         }
       
   137     }
       
   138 
       
   139 // --------------------------------------------------------------------------------------------
       
   140 
       
   141 TKeyResponse CPerfMonValuesContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
       
   142     {
       
   143     return CCoeControl::OfferKeyEventL(aKeyEvent, aType);
       
   144     }
       
   145         
       
   146 // --------------------------------------------------------------------------------------------
       
   147 
       
   148 void CPerfMonValuesContainer::HandleResourceChange(TInt aType)
       
   149     {
       
   150     if (aType == KEikDynamicLayoutVariantSwitch)
       
   151         {
       
   152         TRect mainPaneRect;
       
   153         AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, mainPaneRect);
       
   154         SetRect(mainPaneRect);
       
   155         }
       
   156     else
       
   157         CCoeControl::HandleResourceChange(aType);    
       
   158     }
       
   159 
       
   160 // --------------------------------------------------------------------------------------------
       
   161 
       
   162 void CPerfMonValuesContainer::DrawUpdate()
       
   163     {
       
   164     DrawDeferred(); 
       
   165     }
       
   166     
       
   167 // --------------------------------------------------------------------------------------------
       
   168        
       
   169 // End of File