|
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_datapopupcontainer.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 |
|
30 const TInt KLeftMargin = 2; |
|
31 const TInt KPopupWidth = 94; |
|
32 const TInt KCPUExtraLength = 8; |
|
33 const TInt KPopupExtraSpaceBig = 15; |
|
34 const TInt KPopupExtraSpace = 3; |
|
35 |
|
36 |
|
37 // ===================================== MEMBER FUNCTIONS ===================================== |
|
38 |
|
39 void CPerfMonDataPopupContainer::ConstructL(const TRect& /*aRect*/) |
|
40 { |
|
41 iModel = static_cast<CPerfMonDocument*>(reinterpret_cast<CEikAppUi*>(iEikonEnv->AppUi())->Document())->Model(); |
|
42 iFont = LatinPlain12(); |
|
43 iFontSize = iFont->FontMaxHeight(); |
|
44 |
|
45 // set windowgroup so that it always on top and does not receive focus |
|
46 iWindowGroup = RWindowGroup(iCoeEnv->WsSession()); |
|
47 User::LeaveIfError(iWindowGroup.Construct((TUint32)&iWindowGroup)); |
|
48 iWindowGroup.SetOrdinalPosition(0, ECoeWinPriorityAlwaysAtFront); |
|
49 iWindowGroup.EnableReceiptOfFocus(EFalse); |
|
50 |
|
51 CreateWindowL(&iWindowGroup); |
|
52 //SetRect(aRect); |
|
53 SetPositionAndSize(); |
|
54 SetBlank(); |
|
55 |
|
56 ActivateL(); |
|
57 } |
|
58 |
|
59 // -------------------------------------------------------------------------------------------- |
|
60 |
|
61 CPerfMonDataPopupContainer::~CPerfMonDataPopupContainer() |
|
62 { |
|
63 iWindowGroup.Close(); |
|
64 } |
|
65 |
|
66 // -------------------------------------------------------------------------------------------- |
|
67 |
|
68 void CPerfMonDataPopupContainer::Draw(const TRect& aRect) const |
|
69 { |
|
70 CWindowGc& gc = SystemGc(); |
|
71 gc.SetBrushColor(KRgbWhite); |
|
72 gc.Clear(aRect); |
|
73 |
|
74 // check if sample array has been constructed |
|
75 if (iModel->SampleEntryArray()) |
|
76 { |
|
77 // init font |
|
78 gc.SetPenColor(KRgbBlack); |
|
79 gc.UseFont( iFont ); |
|
80 |
|
81 // draw a rect around the popup |
|
82 gc.DrawRect(aRect); |
|
83 |
|
84 TInt posCounter(1); |
|
85 |
|
86 // draw CPU % if enabled |
|
87 if (iModel->Settings().iDataPopupSources.iSrcEnabled[ESourceCPU]) |
|
88 { |
|
89 TBuf<64> cpuText; |
|
90 cpuText.Copy(_L("CPU: ")); |
|
91 |
|
92 // loop all CPUs |
|
93 for (TInt i=iModel->CPU0PositionInSamples(); i<iModel->CPU0PositionInSamples()+iModel->AmountOfCPUs(); i++) |
|
94 { |
|
95 // check samples available |
|
96 if (iModel->SampleEntryArray()->At(i).iSampleDataArray->Count() > 0) |
|
97 { |
|
98 TSampleData& currentSample = iModel->SampleEntryArray()->At(i).iSampleDataArray->At(0); |
|
99 |
|
100 // append % value |
|
101 cpuText.AppendNum( currentSample.iSize > 0 ? TInt( (1 - ((TReal)(currentSample.iFree) / (TReal)currentSample.iSize)) * 100) : 0 ); |
|
102 cpuText.Append(_L("% ")); |
|
103 } |
|
104 } |
|
105 |
|
106 gc.DrawText(cpuText, TPoint(KLeftMargin, iFontSize*posCounter)); |
|
107 posCounter++; |
|
108 } |
|
109 |
|
110 // draw RAM and Drive values |
|
111 for (TInt i=iModel->RAMPositionInSamples(); i<iModel->PowerPositionInSamples(); i++) |
|
112 { |
|
113 // check if this setting has been enabled and it has some data |
|
114 if (iModel->Settings().iDataPopupSources.iSrcEnabled[ESourceRAM + i - iModel->RAMPositionInSamples()] && iModel->SampleEntryArray()->At(i).iSampleDataArray->Count() > 0) |
|
115 { |
|
116 TSampleData& currentSample = iModel->SampleEntryArray()->At(i).iSampleDataArray->At(0); |
|
117 |
|
118 TBuf<32> freeBuf; |
|
119 freeBuf.AppendNum(currentSample.iFree, TRealFormat(KDefaultRealWidth, 0)); |
|
120 |
|
121 TBuf<32> buf; |
|
122 buf.Format(KFreeFormat, &iModel->SampleEntryArray()->At(i).iDescription, &freeBuf, &iModel->SampleEntryArray()->At(i).iUnitTypeShort); |
|
123 gc.DrawText(buf, TPoint(KLeftMargin, iFontSize*posCounter)); |
|
124 |
|
125 posCounter++; |
|
126 } |
|
127 } |
|
128 |
|
129 // draw power value |
|
130 // check if this setting has been enabled and it has some data |
|
131 if (iModel->Settings().iDataPopupSources.iSrcEnabled[ESourcePwr] && iModel->SampleEntryArray()->At(iModel->PowerPositionInSamples()).iSampleDataArray->Count() > 0) |
|
132 { |
|
133 TSampleData& currentSample = iModel->SampleEntryArray()->At(iModel->PowerPositionInSamples()).iSampleDataArray->At(0); |
|
134 |
|
135 TBuf<32> powerText; |
|
136 powerText.Copy(_L("Power ")); |
|
137 |
|
138 powerText.AppendNum(currentSample.iSize - currentSample.iFree, TRealFormat(KDefaultRealWidth, 0)); |
|
139 powerText.AppendFormat(_L("%S"), &iModel->SampleEntryArray()->At(iModel->PowerPositionInSamples()).iUnitTypeShort); |
|
140 |
|
141 gc.DrawText(powerText, TPoint(KLeftMargin,iFontSize*posCounter)); |
|
142 |
|
143 posCounter++; |
|
144 } |
|
145 |
|
146 gc.DiscardFont(); |
|
147 } |
|
148 } |
|
149 |
|
150 // -------------------------------------------------------------------------------------------- |
|
151 |
|
152 void CPerfMonDataPopupContainer::SizeChanged() |
|
153 { |
|
154 DrawNow(); |
|
155 } |
|
156 |
|
157 // -------------------------------------------------------------------------------------------- |
|
158 |
|
159 void CPerfMonDataPopupContainer::SetPositionAndSize() |
|
160 { |
|
161 CWsScreenDevice* screenDevice = iEikonEnv->ScreenDevice(); |
|
162 |
|
163 const TInt popupWidth = iModel->AmountOfCPUs() * KCPUExtraLength + KPopupWidth; |
|
164 |
|
165 // top right |
|
166 if (iModel->Settings().iDataPopupLocation == EDataPopupLocationTopRight) |
|
167 { |
|
168 // screen orientation is landscape with softkeys on right |
|
169 if (AknLayoutUtils::CbaLocation()==AknLayoutUtils::EAknCbaLocationRight) |
|
170 { |
|
171 SetRect( |
|
172 TRect( |
|
173 screenDevice->SizeInPixels().iWidth-popupWidth-KPopupExtraSpaceBig, |
|
174 0, |
|
175 screenDevice->SizeInPixels().iWidth-KPopupExtraSpaceBig, |
|
176 iModel->Settings().iDataPopupSources.EnabledSourcesCount()*iFontSize + KPopupExtraSpace |
|
177 )); |
|
178 } |
|
179 |
|
180 // any other orientation |
|
181 else |
|
182 { |
|
183 SetRect( |
|
184 TRect( |
|
185 screenDevice->SizeInPixels().iWidth-popupWidth, |
|
186 0, |
|
187 screenDevice->SizeInPixels().iWidth, |
|
188 iModel->Settings().iDataPopupSources.EnabledSourcesCount()*iFontSize + KPopupExtraSpace |
|
189 )); |
|
190 } |
|
191 } |
|
192 |
|
193 // bottom middle |
|
194 else if (iModel->Settings().iDataPopupLocation == EDataPopupLocationBottomMiddle) |
|
195 { |
|
196 SetRect( |
|
197 TRect( |
|
198 screenDevice->SizeInPixels().iWidth/2-popupWidth/2, |
|
199 screenDevice->SizeInPixels().iHeight - iModel->Settings().iDataPopupSources.EnabledSourcesCount()*iFontSize - KPopupExtraSpace, |
|
200 screenDevice->SizeInPixels().iWidth/2+popupWidth/2, |
|
201 screenDevice->SizeInPixels().iHeight |
|
202 )); |
|
203 } |
|
204 } |
|
205 |
|
206 // -------------------------------------------------------------------------------------------- |
|
207 |
|
208 void CPerfMonDataPopupContainer::UpdateVisibility(TBool aForeground) |
|
209 { |
|
210 // application has been brought to foregound |
|
211 if (aForeground) |
|
212 { |
|
213 if (iModel->Settings().iDataPopupVisibility==EDataPopupVisbilityAlwaysOn) |
|
214 { |
|
215 MakeVisible(ETrue); |
|
216 } |
|
217 else |
|
218 { |
|
219 MakeVisible(EFalse); |
|
220 } |
|
221 } |
|
222 |
|
223 // application has been sent to background |
|
224 else |
|
225 { |
|
226 if (iModel->Settings().iDataPopupVisibility==EDataPopupVisbilityAlwaysOn |
|
227 || iModel->Settings().iDataPopupVisibility==EDataPopupVisbilityBackgroundOnly) |
|
228 { |
|
229 MakeVisible(ETrue); |
|
230 } |
|
231 else |
|
232 { |
|
233 MakeVisible(EFalse); |
|
234 } |
|
235 } |
|
236 } |
|
237 |
|
238 // -------------------------------------------------------------------------------------------- |
|
239 |
|
240 void CPerfMonDataPopupContainer::DrawUpdate() |
|
241 { |
|
242 DrawDeferred(); |
|
243 } |
|
244 |
|
245 // -------------------------------------------------------------------------------------------- |
|
246 |
|
247 // End of File |