|
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_samplersettingsviewdlg.h" |
|
22 #include "profiler_gui_model.h" |
|
23 #include "profiler_gui.hrh" |
|
24 #include "profiler_gui_std.h" |
|
25 #include <piprofilerui.rsg> |
|
26 |
|
27 #include <aknsettingitemlist.h> |
|
28 #include <caknmemoryselectionsettingitem.h> |
|
29 #include <aknlists.h> |
|
30 #include <akntitle.h> |
|
31 #include <aknnavi.h> |
|
32 #include <aknnavide.h> |
|
33 #include <stringloader.h> |
|
34 #include <aknnotewrappers.h> |
|
35 |
|
36 // LITERALS |
|
37 _LIT8(KCPUSamplerName, "gpp"); |
|
38 _LIT(KEmptySettingItem, ""); |
|
39 |
|
40 // ===================================== MEMBER FUNCTIONS ===================================== |
|
41 |
|
42 CProfilerSamplerSettingsViewDlg* CProfilerSamplerSettingsViewDlg::NewL(TSamplerAttributes& aSettings) |
|
43 { |
|
44 CProfilerSamplerSettingsViewDlg* self = new(ELeave) CProfilerSamplerSettingsViewDlg(aSettings); |
|
45 CleanupStack::PushL(self); |
|
46 self->ConstructL(); |
|
47 CleanupStack::Pop(self); |
|
48 return self; |
|
49 } |
|
50 |
|
51 // -------------------------------------------------------------------------------------------- |
|
52 |
|
53 CProfilerSamplerSettingsViewDlg::~CProfilerSamplerSettingsViewDlg() |
|
54 { |
|
55 // restore default navi pane |
|
56 if(iNaviContainer) |
|
57 iNaviContainer->Pop(); |
|
58 |
|
59 if (iSettingItemArray) |
|
60 { |
|
61 iSettingItemArray->ResetAndDestroy(); |
|
62 delete iSettingItemArray; |
|
63 } |
|
64 |
|
65 } |
|
66 |
|
67 // -------------------------------------------------------------------------------------------- |
|
68 |
|
69 CProfilerSamplerSettingsViewDlg::CProfilerSamplerSettingsViewDlg(TSamplerAttributes& aSettings) |
|
70 : iSettings(aSettings) |
|
71 { |
|
72 } |
|
73 |
|
74 // -------------------------------------------------------------------------------------------- |
|
75 |
|
76 void CProfilerSamplerSettingsViewDlg::ConstructL() |
|
77 { |
|
78 // construct a menu bar |
|
79 CAknDialog::ConstructL(R_PROFILER_SAMPLER_SETTINGS_MENUBAR); |
|
80 |
|
81 CEikStatusPane* sp = iEikonEnv->AppUiFactory()->StatusPane(); |
|
82 |
|
83 // set empty navi pane label |
|
84 iNaviContainer = static_cast<CAknNavigationControlContainer*>(sp->ControlL(TUid::Uid(EEikStatusPaneUidNavi))); |
|
85 iNaviContainer->PushDefaultL(); |
|
86 |
|
87 // set title text |
|
88 CAknTitlePane* tp = static_cast<CAknTitlePane*>( sp->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) ); |
|
89 tp->SetTextL( _L("Sampler Settings") ); |
|
90 |
|
91 iItemCount = iSettings.iItemCount; |
|
92 |
|
93 } |
|
94 |
|
95 // -------------------------------------------------------------------------------------------- |
|
96 |
|
97 void CProfilerSamplerSettingsViewDlg::HandleListBoxEventL(CEikListBox* /*aListBox*/, TListBoxEvent aEventType) |
|
98 { |
|
99 switch (aEventType) |
|
100 { |
|
101 case EEventEnterKeyPressed: |
|
102 case EEventItemDoubleClicked: |
|
103 ShowSettingPageL(EFalse); |
|
104 break; |
|
105 default: |
|
106 break; |
|
107 } |
|
108 } |
|
109 |
|
110 // -------------------------------------------------------------------------------------------- |
|
111 |
|
112 void CProfilerSamplerSettingsViewDlg::TabChangedL(TInt /*aIndex*/) |
|
113 { |
|
114 iListBox->SetCurrentItemIndex(0); |
|
115 |
|
116 SetVisibilitiesOfSettingItemsL(); |
|
117 } |
|
118 |
|
119 // -------------------------------------------------------------------------------------------- |
|
120 |
|
121 void CProfilerSamplerSettingsViewDlg::ProcessCommandL(TInt aCommandId) |
|
122 { |
|
123 CAknDialog::ProcessCommandL(aCommandId); |
|
124 |
|
125 switch (aCommandId) |
|
126 { |
|
127 case EProfilerGuiCmdSettingsChange: |
|
128 ShowSettingPageL(ETrue); |
|
129 break; |
|
130 case EProfilerGuiCmdSettingsExit: |
|
131 TryExitL(EAknCmdExit); |
|
132 break; |
|
133 default: |
|
134 break; |
|
135 } |
|
136 } |
|
137 |
|
138 // -------------------------------------------------------------------------------------------- |
|
139 |
|
140 TKeyResponse CProfilerSamplerSettingsViewDlg::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType) |
|
141 { |
|
142 |
|
143 return CAknDialog::OfferKeyEventL(aKeyEvent, aType); |
|
144 } |
|
145 |
|
146 // -------------------------------------------------------------------------------------------- |
|
147 |
|
148 void CProfilerSamplerSettingsViewDlg::PreLayoutDynInitL() |
|
149 { |
|
150 iListBox = static_cast<CAknSettingStyleListBox*>( Control(EProfilerSamplerSettingItemList) ); |
|
151 iListBox->SetMopParent(this); |
|
152 iListBox->CreateScrollBarFrameL(ETrue); |
|
153 iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto); |
|
154 iListBox->SetListBoxObserver(this); |
|
155 |
|
156 iSettingItemArray = new(ELeave) CAknSettingItemArray(16, EFalse, 0); |
|
157 |
|
158 CTextListBoxModel* model = iListBox->Model(); |
|
159 model->SetItemTextArray(iSettingItemArray); |
|
160 model->SetOwnershipType(ELbmDoesNotOwnItemArray); |
|
161 |
|
162 UpdateListBoxL(); |
|
163 } |
|
164 |
|
165 // -------------------------------------------------------------------------------------------- |
|
166 |
|
167 TBool CProfilerSamplerSettingsViewDlg::OkToExitL(TInt aButtonId) |
|
168 { |
|
169 // save all settings when exiting, only numeric values are needed to saved since copied from TBuf |
|
170 for(TInt i(1);i<iItemCount+1;i++) |
|
171 { |
|
172 if(iSettingItemArray->At(i)->IsHidden() == EFalse) |
|
173 { |
|
174 switch(i) |
|
175 { |
|
176 case 1: |
|
177 { |
|
178 // check if settings value type integer |
|
179 if(iSettings.iSettingItem1.iType == TSettingItem::ESettingItemTypeInt) |
|
180 { |
|
181 iSettings.iSettingItem1.iValue.Num(iItemBuf[i]); |
|
182 } |
|
183 break; |
|
184 } |
|
185 case 2: |
|
186 { |
|
187 // check if settings value type integer |
|
188 if(iSettings.iSettingItem2.iType == TSettingItem::ESettingItemTypeInt) |
|
189 { |
|
190 iSettings.iSettingItem2.iValue.Num(iItemBuf[i]); |
|
191 } |
|
192 break; |
|
193 } |
|
194 case 3: |
|
195 { |
|
196 // check if settings value type integer |
|
197 if(iSettings.iSettingItem3.iType == TSettingItem::ESettingItemTypeInt) |
|
198 { |
|
199 iSettings.iSettingItem3.iValue.Num(iItemBuf[i]); |
|
200 } |
|
201 break; |
|
202 } |
|
203 case 4: |
|
204 { |
|
205 // check if settings value type integer |
|
206 if(iSettings.iSettingItem4.iType == TSettingItem::ESettingItemTypeInt) |
|
207 { |
|
208 iSettings.iSettingItem4.iValue.Num(iItemBuf[i]); |
|
209 } |
|
210 |
|
211 break; |
|
212 } |
|
213 case 5: |
|
214 { |
|
215 // check if settings value type integer |
|
216 if(iSettings.iSettingItem5.iType == TSettingItem::ESettingItemTypeInt) |
|
217 { |
|
218 iSettings.iSettingItem5.iValue.Num(iItemBuf[i]); |
|
219 } |
|
220 |
|
221 break; |
|
222 } |
|
223 case 6: |
|
224 { |
|
225 // check if settings value type integer |
|
226 if(iSettings.iSettingItem6.iType == TSettingItem::ESettingItemTypeInt) |
|
227 { |
|
228 iSettings.iSettingItem6.iValue.Num(iItemBuf[i]); |
|
229 } |
|
230 |
|
231 break; |
|
232 } |
|
233 } |
|
234 } |
|
235 } |
|
236 return CAknDialog::OkToExitL(aButtonId); |
|
237 } |
|
238 |
|
239 // -------------------------------------------------------------------------------------------- |
|
240 |
|
241 void CProfilerSamplerSettingsViewDlg::ShowSettingPageL(TInt aCalledFromMenu) |
|
242 { |
|
243 TInt listIndex = iListBox->CurrentItemIndex(); |
|
244 TInt realIndex = iSettingItemArray->ItemIndexFromVisibleIndex(listIndex); |
|
245 CAknSettingItem* item = iSettingItemArray->At(realIndex); |
|
246 item->EditItemL(aCalledFromMenu); |
|
247 item->StoreL(); |
|
248 SetVisibilitiesOfSettingItemsL(); |
|
249 DrawNow(); |
|
250 } |
|
251 |
|
252 // -------------------------------------------------------------------------------------------- |
|
253 |
|
254 void CProfilerSamplerSettingsViewDlg::SetVisibilitiesOfSettingItemsL() |
|
255 { |
|
256 if (iSettingItemArray->Count() > 0) |
|
257 { |
|
258 if(iSettings.iSampleRate > 0) |
|
259 { |
|
260 ((*iSettingItemArray)[EProfilerGuiGenericSamplerQuerySampleRate])->SetHidden(EFalse); |
|
261 } |
|
262 else |
|
263 { |
|
264 ((*iSettingItemArray)[EProfilerGuiGenericSamplerQuerySampleRate])->SetHidden(ETrue); |
|
265 } |
|
266 if(iItemCount>0) |
|
267 ((*iSettingItemArray)[EProfilerGuiGenericSamplerQueryItem1])->SetHidden(EFalse); |
|
268 if(iItemCount>1) |
|
269 ((*iSettingItemArray)[EProfilerGuiGenericSamplerQueryItem2])->SetHidden(EFalse); |
|
270 if(iItemCount>2) |
|
271 ((*iSettingItemArray)[EProfilerGuiGenericSamplerQueryItem3])->SetHidden(EFalse); |
|
272 if(iItemCount>3) |
|
273 ((*iSettingItemArray)[EProfilerGuiGenericSamplerQueryItem4])->SetHidden(EFalse); |
|
274 if(iItemCount>4) |
|
275 ((*iSettingItemArray)[EProfilerGuiGenericSamplerQueryItem5])->SetHidden(EFalse); |
|
276 if(iItemCount>5) |
|
277 ((*iSettingItemArray)[EProfilerGuiGenericSamplerQueryItem6])->SetHidden(EFalse); |
|
278 |
|
279 iSettingItemArray->RecalculateVisibleIndicesL(); |
|
280 iListBox->HandleItemAdditionL(); |
|
281 iListBox->UpdateScrollBarsL(); |
|
282 } |
|
283 } |
|
284 |
|
285 // -------------------------------------------------------------------------------------------- |
|
286 |
|
287 void CProfilerSamplerSettingsViewDlg::UpdateListBoxL() |
|
288 { |
|
289 iSettingItemArray->ResetAndDestroy(); |
|
290 |
|
291 // create items |
|
292 TInt ordinal(0); |
|
293 |
|
294 AddSettingItemL(EProfilerGuiGenericSamplerQuerySampleRate, |
|
295 R_SAMPLE_RATE_SETTING_TITLE, |
|
296 R_SAMPLER_RATE_SETTING_PAGE, |
|
297 NULL, |
|
298 ordinal++); |
|
299 |
|
300 if(iItemCount>0) |
|
301 AddSettingItemL(EProfilerGuiGenericSamplerQueryItem1, |
|
302 R_ITEM1_SETTING_TITLE, |
|
303 NULL, |
|
304 NULL, |
|
305 ordinal++); |
|
306 if(iItemCount>1) |
|
307 AddSettingItemL(EProfilerGuiGenericSamplerQueryItem2, |
|
308 R_ITEM2_SETTING_TITLE, |
|
309 NULL, |
|
310 NULL, |
|
311 ordinal++); |
|
312 if(iItemCount>2) |
|
313 AddSettingItemL(EProfilerGuiGenericSamplerQueryItem3, |
|
314 R_ITEM3_SETTING_TITLE, |
|
315 NULL, |
|
316 NULL, |
|
317 ordinal++); |
|
318 if(iItemCount>3) |
|
319 AddSettingItemL(EProfilerGuiGenericSamplerQueryItem4, |
|
320 R_ITEM4_SETTING_TITLE, |
|
321 NULL, |
|
322 NULL, |
|
323 ordinal++); |
|
324 if(iItemCount>4) |
|
325 AddSettingItemL(EProfilerGuiGenericSamplerQueryItem5, |
|
326 R_ITEM5_SETTING_TITLE, |
|
327 NULL, |
|
328 NULL, |
|
329 ordinal++); |
|
330 if(iItemCount>5) |
|
331 AddSettingItemL(EProfilerGuiGenericSamplerQueryItem6, |
|
332 R_ITEM6_SETTING_TITLE, |
|
333 NULL, |
|
334 NULL, |
|
335 ordinal++); |
|
336 |
|
337 SetVisibilitiesOfSettingItemsL(); |
|
338 } |
|
339 |
|
340 // -------------------------------------------------------------------------------------------- |
|
341 |
|
342 CAknSettingItem* CProfilerSamplerSettingsViewDlg::GetSettingItemL(TSettingItem& aItem, TInt aIndex, TInt& aSettingPageResource) |
|
343 { |
|
344 CAknSettingItem* settingItem = NULL; |
|
345 |
|
346 // set default setting page dialog style resource |
|
347 aSettingPageResource = R_GENERIC_TEXT_SETTING_PAGE; |
|
348 |
|
349 // check if setting item type integer |
|
350 if(aItem.iType == TSettingItem::ESettingItemTypeInt) |
|
351 { |
|
352 TLex* lex = new TLex(aItem.iValue); |
|
353 // check if value valid |
|
354 if(lex->Val(iItemBuf[aIndex]) != KErrNone) |
|
355 { |
|
356 // if value not valid set to 0 |
|
357 iItemBuf[aIndex] = 0; |
|
358 } |
|
359 settingItem = new(ELeave) CAknIntegerEdwinSettingItem(aIndex, iItemBuf[aIndex]); |
|
360 aSettingPageResource = R_NUMERIC_SETTING_PAGE; |
|
361 delete lex; |
|
362 return settingItem; |
|
363 } |
|
364 else // else manipulate as a text setting |
|
365 { |
|
366 settingItem = new(ELeave) CAknTextSettingItem(aIndex, aItem.iValue); |
|
367 settingItem->SetEmptyItemTextL(KEmptySettingItem); |
|
368 return settingItem; |
|
369 } |
|
370 } |
|
371 |
|
372 // -------------------------------------------------------------------------------------------- |
|
373 |
|
374 void CProfilerSamplerSettingsViewDlg::AddSettingItemL(TInt aId, |
|
375 TInt aTitleResource, |
|
376 TInt aSettingPageResource, |
|
377 TInt aAssociatedResource, |
|
378 TInt aOrdinal) |
|
379 { |
|
380 // create a setting item |
|
381 CAknSettingItem* settingItem = NULL; |
|
382 |
|
383 TBuf<KMaxSettingUITextLength> ptr; |
|
384 switch(aId) |
|
385 { |
|
386 case EProfilerGuiGenericSamplerQuerySampleRate: |
|
387 { |
|
388 settingItem = new (ELeave) CAknIntegerEdwinSettingItem(aId, iSettings.iSampleRate); |
|
389 break; |
|
390 } |
|
391 case EProfilerGuiGenericSamplerQueryItem1: |
|
392 { |
|
393 ptr.Copy(iSettings.iSettingItem1.iUIText); |
|
394 settingItem = GetSettingItemL(iSettings.iSettingItem1, aId, aSettingPageResource); |
|
395 break; |
|
396 } |
|
397 case EProfilerGuiGenericSamplerQueryItem2: |
|
398 { |
|
399 ptr.Copy(iSettings.iSettingItem2.iUIText); |
|
400 settingItem = GetSettingItemL(iSettings.iSettingItem2, aId, aSettingPageResource); |
|
401 break; |
|
402 } |
|
403 case EProfilerGuiGenericSamplerQueryItem3: |
|
404 { |
|
405 ptr.Copy(iSettings.iSettingItem3.iUIText); |
|
406 settingItem = GetSettingItemL(iSettings.iSettingItem3, aId, aSettingPageResource); |
|
407 break; |
|
408 } |
|
409 case EProfilerGuiGenericSamplerQueryItem4: |
|
410 { |
|
411 ptr.Copy(iSettings.iSettingItem4.iUIText); |
|
412 settingItem = GetSettingItemL(iSettings.iSettingItem4, aId, aSettingPageResource); |
|
413 break; |
|
414 } |
|
415 case EProfilerGuiGenericSamplerQueryItem5: |
|
416 { |
|
417 ptr.Copy(iSettings.iSettingItem5.iUIText); |
|
418 settingItem = GetSettingItemL(iSettings.iSettingItem5, aId, aSettingPageResource); |
|
419 break; |
|
420 } |
|
421 case EProfilerGuiGenericSamplerQueryItem6: |
|
422 { |
|
423 ptr.Copy(iSettings.iSettingItem6.iUIText); |
|
424 settingItem = GetSettingItemL(iSettings.iSettingItem6, aId, aSettingPageResource); |
|
425 break; |
|
426 } |
|
427 } |
|
428 |
|
429 CleanupStack::PushL(settingItem); |
|
430 |
|
431 // get title text |
|
432 HBufC* itemTitle; |
|
433 |
|
434 if( ptr.Compare(KNullDesC) == 0 ) |
|
435 { |
|
436 itemTitle = StringLoader::LoadLC(aTitleResource); |
|
437 |
|
438 // special case: check if CPU sampler |
|
439 if(iSettings.iShortName.CompareF(KCPUSamplerName) == 0) |
|
440 { |
|
441 // change setting page using different value range, since > 10000 ms rates are too big |
|
442 aSettingPageResource = R_CPU_SAMPLER_RATE_SETTING_PAGE; |
|
443 } |
|
444 |
|
445 // construct the setting item |
|
446 settingItem->ConstructL(EFalse, aOrdinal, *itemTitle, NULL, aSettingPageResource, |
|
447 EAknCtPopupSettingList, NULL, aAssociatedResource); |
|
448 // append the setting item to settingitem array |
|
449 iSettingItemArray->InsertL(aOrdinal, settingItem); |
|
450 |
|
451 CleanupStack::PopAndDestroy(); //itemTitle |
|
452 } |
|
453 else |
|
454 { |
|
455 // construct the setting item |
|
456 settingItem->ConstructL(EFalse, aOrdinal, ptr, NULL, aSettingPageResource, |
|
457 EAknCtPopupSettingList, NULL, aAssociatedResource); |
|
458 |
|
459 // append the setting item to settingitem array |
|
460 iSettingItemArray->InsertL(aOrdinal, settingItem); |
|
461 } |
|
462 |
|
463 CleanupStack::Pop(); //settingItem |
|
464 } |
|
465 |
|
466 // -------------------------------------------------------------------------------------------- |
|
467 // End of File |
|
468 |