|
1 /* |
|
2 * Copyright (c) 2010 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 "loadgen_cpuload.h" |
|
21 #include "loadgen_memoryeat.h" |
|
22 #include "loadgen_phonecall.h" |
|
23 #include "loadgen_netconn.h" |
|
24 #include "loadgen_keypress.h" |
|
25 #include "loadgen_pointerevent.h" |
|
26 #include "loadgen_messages.h" |
|
27 #include "loadgen_applications.h" |
|
28 #include "loadgen_photocapture.h" |
|
29 #include "loadgen_bluetooth.h" |
|
30 #include "loadgen_utils.h" |
|
31 |
|
32 #include "loadgen_traces.h" |
|
33 #include "loadgen_editors.h" |
|
34 #include "loadgen_loadattributes.h" |
|
35 #include "loadgen_model.h" |
|
36 #include "loadgen_app.h" |
|
37 #include "loadgen_settingsviewdlg.h" |
|
38 #include "loadgen_maincontainer.h" |
|
39 #include "loadgen.hrh" |
|
40 #include <loadgen.rsg> |
|
41 |
|
42 #include <coeutils.h> |
|
43 #include <bautils.h> |
|
44 #include <eikenv.h> |
|
45 #include <AknQueryDialog.h> |
|
46 #include <e32math.h> |
|
47 #include <u32hal.h> |
|
48 #include <hal.h> |
|
49 #include <hal_data.h> |
|
50 |
|
51 #include <ecam.h> |
|
52 #include <aknnotewrappers.h> |
|
53 #include <featdiscovery.h> |
|
54 |
|
55 inline TInt64 INIT_SEED() |
|
56 { |
|
57 TTime now; |
|
58 now.HomeTime(); |
|
59 return now.Int64(); |
|
60 } |
|
61 |
|
62 TInt64 CLoadGenModel::iRandomNumberSeed = INIT_SEED(); |
|
63 |
|
64 // ===================================== MEMBER FUNCTIONS ===================================== |
|
65 |
|
66 CLoadGenModel* CLoadGenModel::NewL() |
|
67 { |
|
68 CLoadGenModel* self = new(ELeave) CLoadGenModel; |
|
69 CleanupStack::PushL(self); |
|
70 self->ConstructL(); |
|
71 CleanupStack::Pop(); |
|
72 return self; |
|
73 } |
|
74 |
|
75 // -------------------------------------------------------------------------------------------- |
|
76 |
|
77 CLoadGenModel::CLoadGenModel() : CActive(EPriorityStandard) |
|
78 { |
|
79 } |
|
80 |
|
81 // -------------------------------------------------------------------------------------------- |
|
82 |
|
83 void CLoadGenModel::ConstructL() |
|
84 { |
|
85 iDrawState = EDrawStateInvalid; |
|
86 iReferenceNumber = 0; |
|
87 |
|
88 iEnv = CEikonEnv::Static(); |
|
89 User::LeaveIfError(iLs.Connect()); |
|
90 |
|
91 iLoadItemList = new(ELeave) CLoadItemList(64); |
|
92 |
|
93 User::LeaveIfError(iTimer.CreateLocal()); |
|
94 CActiveScheduler::Add(this); |
|
95 } |
|
96 |
|
97 // -------------------------------------------------------------------------------------------- |
|
98 |
|
99 void CLoadGenModel::ActivateModelL() |
|
100 { |
|
101 // load settings |
|
102 //TRAP_IGNORE(LoadSettingsL()); |
|
103 |
|
104 // set defaults to attributes |
|
105 iCpuLoadAttributes.iId = 0; |
|
106 iCpuLoadAttributes.iPriority = EThreadPriorityTypeNormal; |
|
107 iCpuLoadAttributes.iMode = ECpuLoadModeYielding; |
|
108 iCpuLoadAttributes.iType = ECpuLoadTypePeriodic; |
|
109 iCpuLoadAttributes.iLength = 4000; |
|
110 iCpuLoadAttributes.iIdle = 2000; |
|
111 iCpuLoadAttributes.iRandomVariance = 0; |
|
112 iCpuLoadAttributes.iCpu = KCPUSelection_FreeScheduling; // set CPU as "undefined" (can be >= 0 only in SMP environments) |
|
113 iCpuLoadAttributes.iCpuCount = UserSvr::HalFunction(EHalGroupKernel, KHalFunction_EKernelHalNumLogicalCpus, 0, 0); |
|
114 if( iCpuLoadAttributes.iCpuCount < 1 || iCpuLoadAttributes.iCpuCount > KMaxCPUs ) |
|
115 { |
|
116 // HAL may not support this function, so let's use CPU count 1: |
|
117 iCpuLoadAttributes.iCpuCount = 1; |
|
118 } |
|
119 iMemoryEatAttributes.iId = 0; |
|
120 iMemoryEatAttributes.iPriority = EThreadPriorityTypeNormal; |
|
121 iMemoryEatAttributes.iSource = 0; |
|
122 iMemoryEatAttributes.iType = EMemoryEatTypeMemoryToBeLeft; |
|
123 iMemoryEatAttributes.iBuffer = 16*1024; |
|
124 iMemoryEatAttributes.iIdle = 0; |
|
125 iMemoryEatAttributes.iAmount = 0; |
|
126 iMemoryEatAttributes.iRandomMin = 1000000; |
|
127 iMemoryEatAttributes.iRandomMax = 1500000; |
|
128 iMemoryEatAttributes.iAmountDes.Copy(KNullDesC); |
|
129 iMemoryEatAttributes.iRandomMinDes.Copy(KNullDesC); |
|
130 iMemoryEatAttributes.iRandomMaxDes.Copy(KNullDesC); |
|
131 iMemoryEatAttributes.iRandomVariance = 0; |
|
132 |
|
133 iPhoneCallAttributes.iId = 0; |
|
134 iPhoneCallAttributes.iPriority = EThreadPriorityTypeNormal; |
|
135 iPhoneCallAttributes.iDestination.Copy(_L("+358")); |
|
136 iPhoneCallAttributes.iLength = 60000; |
|
137 iPhoneCallAttributes.iIdle = 10000; |
|
138 iPhoneCallAttributes.iRandomVariance = 0; |
|
139 |
|
140 iNetConnAttributes.iId = 0; |
|
141 iNetConnAttributes.iPriority = EThreadPriorityTypeNormal; |
|
142 iNetConnAttributes.iDestination.Copy(_L("http://www.nokia.com")); |
|
143 iNetConnAttributes.iIdle = 10000; |
|
144 iNetConnAttributes.iRandomVariance = 0; |
|
145 |
|
146 iKeyPressAttributes.iId = 0; |
|
147 iKeyPressAttributes.iPriority = EThreadPriorityTypeNormal; |
|
148 iKeyPressAttributes.iHeartBeat = 100; |
|
149 iKeyPressAttributes.iRandomVariance = 0; |
|
150 |
|
151 iPointerEventAttributes.iId = 0; |
|
152 iPointerEventAttributes.iPriority = EThreadPriorityTypeNormal; |
|
153 iPointerEventAttributes.iHeartBeat = 1000; |
|
154 iPointerEventAttributes.iRandomVariance = 0; |
|
155 |
|
156 iMessageAttributes.iId = 0; |
|
157 iMessageAttributes.iPriority = EThreadPriorityTypeNormal; |
|
158 iMessageAttributes.iMessageType = EMessageTypeSMS; |
|
159 iMessageAttributes.iDestination.Copy(_L("+358")); |
|
160 iMessageAttributes.iAmount = 5; |
|
161 iMessageAttributes.iLength = 160; |
|
162 iMessageAttributes.iIdle = 15000; |
|
163 iMessageAttributes.iRandomVariance = 0; |
|
164 |
|
165 iApplicationsAttributes.iId = 0; |
|
166 iApplicationsAttributes.iLaunchingInterval = 2000; |
|
167 iApplicationsAttributes.iPriority = EThreadPriorityTypeNormal; |
|
168 iApplicationsAttributes.iKeyPressType = EApplicationsKeyPressTypeNone; |
|
169 iApplicationsAttributes.iMaxOpen = 20; |
|
170 iApplicationsAttributes.iHeartBeat = 50; |
|
171 iApplicationsAttributes.iRandomVariance = 0; |
|
172 |
|
173 iPhotoCaptureAttributes.iId = 0; |
|
174 iPhotoCaptureAttributes.iPriority = EThreadPriorityTypeNormal; |
|
175 iPhotoCaptureAttributes.iIdle = 10000; |
|
176 iPhotoCaptureAttributes.iRandomVariance = 0; |
|
177 iPhotoCaptureAttributes.iCameraCount = CCamera::CamerasAvailable(); |
|
178 if(iPhotoCaptureAttributes.iCameraCount > 0) |
|
179 { |
|
180 iPhotoCaptureAttributes.iCamera = 0; // Main camera |
|
181 } |
|
182 else |
|
183 { |
|
184 iPhotoCaptureAttributes.iCamera = -1; |
|
185 } |
|
186 |
|
187 iBluetoothAttributes.iId = 0; |
|
188 iBluetoothAttributes.iPriority = EThreadPriorityTypeNormal; |
|
189 iBluetoothAttributes.iIdle = 10000; |
|
190 iBluetoothAttributes.iRandomVariance = 0; |
|
191 iBluetoothAttributes.iBluetoothSupported = CFeatureDiscovery::IsFeatureSupportedL(KFeatureIdBt); |
|
192 } |
|
193 |
|
194 // -------------------------------------------------------------------------------------------- |
|
195 |
|
196 void CLoadGenModel::DeActivateModelL() |
|
197 { |
|
198 Cancel(); |
|
199 |
|
200 // for a faster exit, send the application to background |
|
201 TApaTask selfTask(iEnv->WsSession()); |
|
202 selfTask.SetWgId(iEnv->RootWin().Identifier()); |
|
203 selfTask.SendToBackground(); |
|
204 } |
|
205 |
|
206 // -------------------------------------------------------------------------------------------- |
|
207 |
|
208 CLoadGenModel::~CLoadGenModel() |
|
209 { |
|
210 if (iLoadItemList) |
|
211 { |
|
212 DeleteAllLoadItems(); |
|
213 delete iLoadItemList; |
|
214 } |
|
215 if ( iApplicationsAttributes.iAppsArray ) |
|
216 { |
|
217 delete iApplicationsAttributes.iAppsArray; |
|
218 } |
|
219 iTimer.Close(); |
|
220 iLs.Close(); |
|
221 } |
|
222 |
|
223 // -------------------------------------------------------------------------------------------- |
|
224 |
|
225 void CLoadGenModel::DoCancel() |
|
226 { |
|
227 iTimer.Cancel(); |
|
228 } |
|
229 |
|
230 // -------------------------------------------------------------------------------------------- |
|
231 |
|
232 void CLoadGenModel::RunL() |
|
233 { |
|
234 // continue |
|
235 //iTimer.After(iStatus, 400000); |
|
236 //SetActive(); |
|
237 } |
|
238 |
|
239 // -------------------------------------------------------------------------------------------- |
|
240 |
|
241 void CLoadGenModel::SetMainContainer(CLoadGenMainContainer* aContainer) |
|
242 { |
|
243 iMainContainer = aContainer; |
|
244 iDrawState = EDrawStateMain; |
|
245 } |
|
246 |
|
247 // -------------------------------------------------------------------------------------------- |
|
248 |
|
249 void CLoadGenModel::StartNewLoadL(TInt aCommand) |
|
250 { |
|
251 // show new load query |
|
252 CLoadGenLoadTypeEditorBase* dlg = NULL; |
|
253 |
|
254 switch ( aCommand ) |
|
255 { |
|
256 case ELoadGenCmdNewLoadCPULoad: |
|
257 { |
|
258 dlg = CLoadGenCPULoadEditor::NewL(iCpuLoadAttributes); |
|
259 break; |
|
260 } |
|
261 case ELoadGenCmdNewLoadEatMemory: |
|
262 { |
|
263 dlg = CLoadGenMemoryEatEditor::NewL(iMemoryEatAttributes); |
|
264 break; |
|
265 } |
|
266 case ELoadGenCmdNewLoadPhoneCall: |
|
267 { |
|
268 dlg = CLoadGenPhoneCallEditor::NewL(iPhoneCallAttributes); |
|
269 break; |
|
270 } |
|
271 case ELoadGenCmdNewLoadNetConn: |
|
272 { |
|
273 dlg = CLoadGenNetConnEditor::NewL(iNetConnAttributes); |
|
274 break; |
|
275 } |
|
276 case ELoadGenCmdNewLoadKeyPress: |
|
277 { |
|
278 dlg = CLoadGenKeyPressEditor::NewL(iKeyPressAttributes); |
|
279 break; |
|
280 } |
|
281 case ELoadGenCmdNewLoadMessages: |
|
282 { |
|
283 dlg = CLoadGenMessagesEditor::NewL( iMessageAttributes ); |
|
284 break; |
|
285 } |
|
286 case ELoadGenCmdNewLoadApplications: |
|
287 { |
|
288 dlg = CLoadGenApplicationsEditor::NewL( iApplicationsAttributes ); |
|
289 break; |
|
290 } |
|
291 case ELoadGenCmdNewLoadPhotoCaptures: |
|
292 { |
|
293 if( iPhotoCaptureAttributes.iCameraCount > 0 ) |
|
294 { |
|
295 dlg = CLoadGenPhotoCaptureEditor::NewL( iPhotoCaptureAttributes ); |
|
296 } |
|
297 else |
|
298 { |
|
299 _LIT(message, "Cameras not available"); |
|
300 CAknErrorNote* errorNote = new(ELeave) CAknErrorNote; |
|
301 errorNote->ExecuteLD(message); |
|
302 return; |
|
303 } |
|
304 break; |
|
305 } |
|
306 case ELoadGenCmdNewLoadBluetooth: |
|
307 { |
|
308 if( iBluetoothAttributes.iBluetoothSupported ) |
|
309 { |
|
310 dlg = CLoadGenBluetoothEditor::NewL(iBluetoothAttributes); |
|
311 } |
|
312 else |
|
313 { |
|
314 _LIT(message, "Bluetooth device not available"); |
|
315 CAknErrorNote* errorNote = new(ELeave) CAknErrorNote; |
|
316 errorNote->ExecuteLD(message); |
|
317 return; |
|
318 } |
|
319 break; |
|
320 } |
|
321 case ELoadGenCmdNewLoadPointerEvent: |
|
322 { |
|
323 dlg = CLoadGenPointerEventEditor::NewL(iPointerEventAttributes); |
|
324 break; |
|
325 } |
|
326 |
|
327 default: |
|
328 { |
|
329 User::Panic(_L("Wrong new load"), 111); |
|
330 break; |
|
331 } |
|
332 } |
|
333 |
|
334 TBool dlgResult = dlg->RunQueryLD(); |
|
335 |
|
336 // set back title |
|
337 if (iMainContainer) |
|
338 iMainContainer->SetDefaultTitlePaneTextL(); |
|
339 |
|
340 // start creating new load if dialog accepted |
|
341 if (dlgResult) |
|
342 { |
|
343 DoStartNewLoadL(aCommand); |
|
344 } |
|
345 |
|
346 } |
|
347 |
|
348 // -------------------------------------------------------------------------------------------- |
|
349 |
|
350 void CLoadGenModel::EditLoadL(CLoadBase* aItem) |
|
351 { |
|
352 // suspend current |
|
353 aItem->Suspend(); |
|
354 |
|
355 // show new load query |
|
356 CLoadGenLoadTypeEditorBase* dlg = NULL; |
|
357 |
|
358 switch ( aItem->Type() ) |
|
359 { |
|
360 case ELoadGenCmdNewLoadCPULoad: |
|
361 { |
|
362 dlg = CLoadGenCPULoadEditor::NewL(static_cast<CCPULoad*>(aItem)->Attributes(), ETrue); |
|
363 break; |
|
364 } |
|
365 case ELoadGenCmdNewLoadEatMemory: |
|
366 { |
|
367 dlg = CLoadGenMemoryEatEditor::NewL(static_cast<CMemoryEat*>(aItem)->Attributes(), ETrue); |
|
368 break; |
|
369 } |
|
370 case ELoadGenCmdNewLoadPhoneCall: |
|
371 { |
|
372 dlg = CLoadGenPhoneCallEditor::NewL(static_cast<CPhoneCall*>(aItem)->Attributes(), ETrue); |
|
373 break; |
|
374 } |
|
375 case ELoadGenCmdNewLoadNetConn: |
|
376 { |
|
377 dlg = CLoadGenNetConnEditor::NewL(static_cast<CNetConn*>(aItem)->Attributes(), ETrue); |
|
378 break; |
|
379 } |
|
380 case ELoadGenCmdNewLoadKeyPress: |
|
381 { |
|
382 dlg = CLoadGenKeyPressEditor::NewL(static_cast<CKeyPress*>(aItem)->Attributes(), ETrue); |
|
383 break; |
|
384 } |
|
385 case ELoadGenCmdNewLoadMessages: |
|
386 { |
|
387 dlg = CLoadGenMessagesEditor::NewL(static_cast<CMessages*>(aItem)->Attributes(), ETrue); |
|
388 break; |
|
389 } |
|
390 case ELoadGenCmdNewLoadApplications: |
|
391 { |
|
392 dlg = CLoadGenApplicationsEditor::NewL( static_cast<CAppLauncher*>(aItem)->Attributes(), ETrue ); |
|
393 break; |
|
394 } |
|
395 case ELoadGenCmdNewLoadPhotoCaptures: |
|
396 { |
|
397 dlg = CLoadGenPhotoCaptureEditor::NewL( static_cast<CPhotoCapture*>(aItem)->Attributes(), ETrue ); |
|
398 break; |
|
399 } |
|
400 case ELoadGenCmdNewLoadBluetooth: |
|
401 { |
|
402 dlg = CLoadGenBluetoothEditor::NewL( static_cast<CBluetooth*>(aItem)->Attributes(), ETrue ); |
|
403 break; |
|
404 } |
|
405 case ELoadGenCmdNewLoadPointerEvent: |
|
406 { |
|
407 dlg = CLoadGenPointerEventEditor::NewL(static_cast<CPointerEvent*>(aItem)->Attributes(), ETrue); |
|
408 break; |
|
409 } |
|
410 default: |
|
411 { |
|
412 User::Panic(_L("Wrong edit load"), 114); |
|
413 break; |
|
414 } |
|
415 } |
|
416 |
|
417 TBool dlgResult = dlg->RunQueryLD(); |
|
418 |
|
419 // set back title |
|
420 if (iMainContainer) |
|
421 iMainContainer->SetDefaultTitlePaneTextL(); |
|
422 |
|
423 // change priority of the load item |
|
424 aItem->SetPriority(); |
|
425 |
|
426 // resume execution the item |
|
427 aItem->Resume(); |
|
428 |
|
429 if (dlgResult) |
|
430 RefreshViewL(EFalse); |
|
431 } |
|
432 |
|
433 // -------------------------------------------------------------------------------------------- |
|
434 |
|
435 void CLoadGenModel::DoStartNewLoadL(TInt aCommand) |
|
436 { |
|
437 CLoadBase* item = NULL; |
|
438 |
|
439 switch ( aCommand ) |
|
440 { |
|
441 case ELoadGenCmdNewLoadCPULoad: |
|
442 { |
|
443 if( iCpuLoadAttributes.iCpu == KCPUSelection_AllCPUs ) |
|
444 { |
|
445 // Call this function recursively for all CPUs: |
|
446 for( TUint i = 0; i < iCpuLoadAttributes.iCpuCount; ++i ) |
|
447 { |
|
448 iCpuLoadAttributes.iCpu = i; |
|
449 DoStartNewLoadL(aCommand); |
|
450 } |
|
451 // And finally set user selection back to "All CPUs" |
|
452 iCpuLoadAttributes.iCpu = KCPUSelection_AllCPUs; |
|
453 return; |
|
454 } |
|
455 else |
|
456 { |
|
457 item = CCPULoad::NewL(iCpuLoadAttributes, iReferenceNumber); |
|
458 } |
|
459 break; |
|
460 } |
|
461 case ELoadGenCmdNewLoadEatMemory: |
|
462 { |
|
463 item = CMemoryEat::NewL(iMemoryEatAttributes, iReferenceNumber); |
|
464 break; |
|
465 } |
|
466 case ELoadGenCmdNewLoadPhoneCall: |
|
467 { |
|
468 item = CPhoneCall::NewL(iPhoneCallAttributes, iReferenceNumber); |
|
469 break; |
|
470 } |
|
471 case ELoadGenCmdNewLoadNetConn: |
|
472 { |
|
473 item = CNetConn::NewL(iNetConnAttributes, iReferenceNumber); |
|
474 break; |
|
475 } |
|
476 case ELoadGenCmdNewLoadKeyPress: |
|
477 { |
|
478 item = CKeyPress::NewL(iKeyPressAttributes, iReferenceNumber); |
|
479 break; |
|
480 } |
|
481 case ELoadGenCmdNewLoadMessages: |
|
482 { |
|
483 item = CMessages::NewL( iMessageAttributes, iReferenceNumber ); |
|
484 break; |
|
485 } |
|
486 case ELoadGenCmdNewLoadApplications: |
|
487 { |
|
488 iApplicationsAttributes.iAppsArray = ListOfAllAppsL(); |
|
489 item = CAppLauncher::NewL( iApplicationsAttributes, iReferenceNumber ); |
|
490 break; |
|
491 } |
|
492 case ELoadGenCmdNewLoadPhotoCaptures: |
|
493 { |
|
494 item = CPhotoCapture::NewL( iPhotoCaptureAttributes, iReferenceNumber); |
|
495 break; |
|
496 } |
|
497 case ELoadGenCmdNewLoadBluetooth: |
|
498 { |
|
499 item = CBluetooth::NewL( iBluetoothAttributes, iReferenceNumber); |
|
500 break; |
|
501 } |
|
502 case ELoadGenCmdNewLoadPointerEvent: |
|
503 { |
|
504 item = CPointerEvent::NewL(iPointerEventAttributes, iReferenceNumber); |
|
505 break; |
|
506 } |
|
507 |
|
508 default: |
|
509 { |
|
510 User::Panic(_L("Wrong new load"), 112); |
|
511 break; |
|
512 } |
|
513 } |
|
514 |
|
515 iReferenceNumber++; |
|
516 |
|
517 // add item to the array |
|
518 AppendToLoadItemListL(item); |
|
519 |
|
520 // update the listbox |
|
521 RefreshViewL(EFalse); |
|
522 |
|
523 // set item index to the end |
|
524 iMainContainer->ListBox()->SetCurrentItemIndexAndDraw( iMainContainer->ListBox()->Model()->NumberOfItems()-1 ); |
|
525 |
|
526 // start the load |
|
527 item->Resume(); |
|
528 |
|
529 // refresh again |
|
530 RefreshViewL(EFalse); |
|
531 } |
|
532 |
|
533 // -------------------------------------------------------------------------------------------- |
|
534 |
|
535 |
|
536 void CLoadGenModel::StopAllLoadItemsL() |
|
537 { |
|
538 DeleteAllLoadItems(); |
|
539 |
|
540 RefreshViewL(); |
|
541 } |
|
542 |
|
543 // -------------------------------------------------------------------------------------------- |
|
544 |
|
545 void CLoadGenModel::SuspendAllLoadItemsL() |
|
546 { |
|
547 for (TInt i=0; i<LoadItemCount(); i++) |
|
548 { |
|
549 if ( iLoadItemList->At(i) ) |
|
550 { |
|
551 iLoadItemList->At(i)->Suspend(); |
|
552 } |
|
553 } |
|
554 |
|
555 RefreshViewL(); |
|
556 } |
|
557 // -------------------------------------------------------------------------------------------- |
|
558 |
|
559 void CLoadGenModel::ResumeAllLoadItemsL() |
|
560 { |
|
561 for (TInt i=0; i<LoadItemCount(); i++) |
|
562 { |
|
563 if ( iLoadItemList->At(i) ) |
|
564 { |
|
565 iLoadItemList->At(i)->Resume(); |
|
566 } |
|
567 } |
|
568 |
|
569 RefreshViewL(); |
|
570 } |
|
571 |
|
572 // -------------------------------------------------------------------------------------------- |
|
573 |
|
574 void CLoadGenModel::RefreshViewL(TBool aClearSelection) |
|
575 { |
|
576 if (iMainContainer && iDrawState == EDrawStateMain && iMainContainer->ListBox()) |
|
577 { |
|
578 // clear selections if any |
|
579 iMainContainer->ListBox()->ClearSelection(); |
|
580 |
|
581 // set item index to 0 |
|
582 if (aClearSelection) |
|
583 iMainContainer->ListBox()->SetCurrentItemIndex(0); |
|
584 |
|
585 // set text items |
|
586 iMainContainer->SetListBoxTextArrayL(GenerateListBoxItemTextArrayL()); |
|
587 } |
|
588 } |
|
589 |
|
590 // -------------------------------------------------------------------------------------------- |
|
591 |
|
592 void CLoadGenModel::AppendToLoadItemListL(CLoadBase* aItem) |
|
593 { |
|
594 if (iLoadItemList) |
|
595 iLoadItemList->AppendL( aItem ); |
|
596 else |
|
597 User::Leave(KErrNotReady); |
|
598 } |
|
599 |
|
600 // -------------------------------------------------------------------------------------------- |
|
601 |
|
602 void CLoadGenModel::DeleteFromLoadItemListL(TInt aIndex) |
|
603 { |
|
604 if (iLoadItemList) |
|
605 { |
|
606 if (iLoadItemList->Count() > aIndex && aIndex >= 0) |
|
607 { |
|
608 // first call delete on the item |
|
609 if (iLoadItemList->At(aIndex)) |
|
610 { |
|
611 delete iLoadItemList->At(aIndex); |
|
612 iLoadItemList->At(aIndex) = NULL; |
|
613 } |
|
614 |
|
615 // and them remove the array entry |
|
616 iLoadItemList->Delete(aIndex); |
|
617 iLoadItemList->Compress(); |
|
618 } |
|
619 else |
|
620 User::Leave(KErrNotFound); |
|
621 } |
|
622 else |
|
623 User::Leave(KErrNotReady); |
|
624 } |
|
625 |
|
626 // -------------------------------------------------------------------------------------------- |
|
627 |
|
628 void CLoadGenModel::SuspendOrResumeFromLoadItemListL(TInt aIndex) |
|
629 { |
|
630 if (iLoadItemList) |
|
631 { |
|
632 if (iLoadItemList->Count() > aIndex && aIndex >= 0) |
|
633 { |
|
634 if (iLoadItemList->At(aIndex)) |
|
635 { |
|
636 if (iLoadItemList->At(aIndex)->State() == CLoadBase::ELoadStateRunning) |
|
637 { |
|
638 iLoadItemList->At(aIndex)->Suspend(); |
|
639 } |
|
640 else if (iLoadItemList->At(aIndex)->State() == CLoadBase::ELoadStateSuspended) |
|
641 { |
|
642 iLoadItemList->At(aIndex)->Resume(); |
|
643 } |
|
644 } |
|
645 } |
|
646 else |
|
647 User::Leave(KErrNotFound); |
|
648 } |
|
649 else |
|
650 User::Leave(KErrNotReady); |
|
651 } |
|
652 |
|
653 // -------------------------------------------------------------------------------------------- |
|
654 |
|
655 TInt CLoadGenModel::LoadItemCount() const |
|
656 { |
|
657 TInt count(0); |
|
658 |
|
659 if (iLoadItemList) |
|
660 count = iLoadItemList->Count(); |
|
661 |
|
662 return count; |
|
663 } |
|
664 |
|
665 // -------------------------------------------------------------------------------------------- |
|
666 |
|
667 void CLoadGenModel::DeleteAllLoadItems() |
|
668 { |
|
669 // call delete for each entry and free memory allocated for the array |
|
670 for (TInt i=0; i<LoadItemCount(); i++) |
|
671 { |
|
672 if ( iLoadItemList->At(i) ) |
|
673 { |
|
674 delete iLoadItemList->At(i); |
|
675 iLoadItemList->At(i) = NULL; |
|
676 } |
|
677 } |
|
678 |
|
679 iLoadItemList->Reset(); |
|
680 } |
|
681 |
|
682 // -------------------------------------------------------------------------------------------- |
|
683 |
|
684 CDesCArray* CLoadGenModel::GenerateListBoxItemTextArrayL() |
|
685 { |
|
686 CDesCArray* textArray = new(ELeave) CDesCArrayFlat(64); |
|
687 CleanupStack::PushL(textArray); |
|
688 |
|
689 _LIT(KEntryTemplateRedIcon, "1\t%S\t\t"); |
|
690 _LIT(KEntryTemplateGreenIcon, "2\t%S\t\t"); |
|
691 |
|
692 for (TInt i=0; i<LoadItemCount(); i++) |
|
693 { |
|
694 // add description from each entry |
|
695 TBuf<256> textEntry; |
|
696 TBuf<256> description = iLoadItemList->At(i)->Description(); |
|
697 |
|
698 if (iLoadItemList->At(i)->State() == CLoadBase::ELoadStateRunning) |
|
699 textEntry.Format(KEntryTemplateGreenIcon, &description); |
|
700 else |
|
701 textEntry.Format(KEntryTemplateRedIcon, &description); |
|
702 |
|
703 textArray->AppendL(textEntry); |
|
704 } |
|
705 |
|
706 CleanupStack::Pop(); //textArray |
|
707 return textArray; |
|
708 } |
|
709 |
|
710 // -------------------------------------------------------------------------------------------- |
|
711 |
|
712 void CLoadGenModel::ShowItemActionMenuL() |
|
713 { |
|
714 TInt currentItemIndex = iMainContainer->CurrentListBoxItemIndex(); |
|
715 |
|
716 if (LoadItemCount() > currentItemIndex && currentItemIndex >= 0) |
|
717 { |
|
718 // show a query dialog |
|
719 TInt queryIndex(0); |
|
720 CAknListQueryDialog* listQueryDlg = new(ELeave) CAknListQueryDialog(&queryIndex); |
|
721 |
|
722 if (listQueryDlg->ExecuteLD(R_ITEM_ACTION_QUERY)) |
|
723 { |
|
724 // stop |
|
725 if (queryIndex == EItemActionMenuTypeStop) |
|
726 { |
|
727 StopSelectedOrHighlightedItemsL(); |
|
728 } |
|
729 |
|
730 // suspend or resume |
|
731 else if (queryIndex == EItemActionMenuTypeSuspendResume) |
|
732 { |
|
733 SuspendOrResumeSelectedOrHighlightedItemsL(); |
|
734 } |
|
735 |
|
736 // edit |
|
737 else if (queryIndex == EItemActionMenuTypeEdit) |
|
738 { |
|
739 EditLoadL(iLoadItemList->At(currentItemIndex)); |
|
740 } |
|
741 } |
|
742 } |
|
743 } |
|
744 |
|
745 // -------------------------------------------------------------------------------------------- |
|
746 |
|
747 void CLoadGenModel::StopSelectedOrHighlightedItemsL() |
|
748 { |
|
749 const CArrayFix<TInt>* selectionIndexes = iMainContainer->ListBoxSelectionIndexes(); |
|
750 |
|
751 TInt err(KErrNone); |
|
752 |
|
753 // by default use selected items |
|
754 if (selectionIndexes && selectionIndexes->Count() > 0) |
|
755 { |
|
756 CAknQueryDialog* query = CAknQueryDialog::NewL(); |
|
757 _LIT(KQueryMessage, "Stop %d selections?"); |
|
758 TFileName queryMsg; |
|
759 queryMsg.Format(KQueryMessage, selectionIndexes->Count()); |
|
760 |
|
761 |
|
762 if (query->ExecuteLD(R_GENERAL_CONFIRMATION_QUERY, queryMsg)) |
|
763 { |
|
764 TInt deleteIndexCounter(0); |
|
765 TInt ref(0); |
|
766 TKeyArrayFix key(0, ECmpTUint16); |
|
767 TInt index(0); |
|
768 |
|
769 TInt loadCount = LoadItemCount(); |
|
770 |
|
771 for (TInt i=0; i<loadCount; i++) |
|
772 { |
|
773 ref = i; |
|
774 |
|
775 if (selectionIndexes->Find(ref, key, index) == 0) |
|
776 { |
|
777 TRAP(err, DeleteFromLoadItemListL(i-deleteIndexCounter)); |
|
778 deleteIndexCounter++; // amount of indexes decreases after each delete |
|
779 } |
|
780 } |
|
781 |
|
782 RefreshViewL(); |
|
783 User::LeaveIfError(err); |
|
784 } |
|
785 } |
|
786 |
|
787 // or if none selected, use the current item index |
|
788 else |
|
789 { |
|
790 TInt currentItemIndex = iMainContainer->CurrentListBoxItemIndex(); |
|
791 |
|
792 if (LoadItemCount() > currentItemIndex && currentItemIndex >= 0) |
|
793 { |
|
794 CAknQueryDialog* query = CAknQueryDialog::NewL(); |
|
795 _LIT(KQueryMessage, "Stop hightlighted item?"); |
|
796 |
|
797 if (query->ExecuteLD(R_GENERAL_CONFIRMATION_QUERY, KQueryMessage)) |
|
798 { |
|
799 TRAP(err, DeleteFromLoadItemListL(currentItemIndex)); |
|
800 |
|
801 RefreshViewL(); |
|
802 User::LeaveIfError(err); |
|
803 } |
|
804 } |
|
805 } |
|
806 } |
|
807 |
|
808 // -------------------------------------------------------------------------------------------- |
|
809 |
|
810 void CLoadGenModel::SuspendOrResumeSelectedOrHighlightedItemsL() |
|
811 { |
|
812 const CArrayFix<TInt>* selectionIndexes = iMainContainer->ListBoxSelectionIndexes(); |
|
813 |
|
814 // by default use selected items |
|
815 if (selectionIndexes && selectionIndexes->Count() > 0) |
|
816 { |
|
817 TInt ref(0); |
|
818 TKeyArrayFix key(0, ECmpTUint16); |
|
819 TInt index(0); |
|
820 |
|
821 for (TInt i=0; i<LoadItemCount(); i++) |
|
822 { |
|
823 ref = i; |
|
824 |
|
825 if (selectionIndexes->Find(ref, key, index) == 0) |
|
826 { |
|
827 SuspendOrResumeFromLoadItemListL(i); |
|
828 } |
|
829 } |
|
830 |
|
831 RefreshViewL(EFalse); |
|
832 } |
|
833 |
|
834 // or if none selected, use the current item index |
|
835 else |
|
836 { |
|
837 TInt currentItemIndex = iMainContainer->CurrentListBoxItemIndex(); |
|
838 |
|
839 if (LoadItemCount() > currentItemIndex && currentItemIndex >= 0) |
|
840 { |
|
841 SuspendOrResumeFromLoadItemListL(currentItemIndex); |
|
842 |
|
843 RefreshViewL(EFalse); |
|
844 } |
|
845 } |
|
846 } |
|
847 // -------------------------------------------------------------------------------------------- |
|
848 |
|
849 void CLoadGenModel::LoadSettingsL() |
|
850 { |
|
851 } |
|
852 |
|
853 // -------------------------------------------------------------------------------------------- |
|
854 |
|
855 void CLoadGenModel::SaveSettingsL() |
|
856 { |
|
857 } |
|
858 |
|
859 // -------------------------------------------------------------------------------------------- |
|
860 |
|
861 TInt CLoadGenModel::LaunchSettingsDialogL() |
|
862 { |
|
863 return 0; |
|
864 } |
|
865 |
|
866 // -------------------------------------------------------------------------------------------- |
|
867 |
|
868 CDesCArray* CLoadGenModel::ListOfAllAppsL() |
|
869 { |
|
870 const TInt KMaxAppsArraySize=250; |
|
871 RApaLsSession ls; |
|
872 CleanupClosePushL(ls); |
|
873 |
|
874 User::LeaveIfError( ls.Connect() ); |
|
875 CDesCArray* allAppsArray = new(ELeave) CDesCArrayFlat( KMaxAppsArraySize ); |
|
876 CleanupStack::PushL( allAppsArray ); |
|
877 // reset the apps list |
|
878 allAppsArray->Reset(); |
|
879 |
|
880 // search all apps |
|
881 TApaAppInfo appInfo; |
|
882 User::LeaveIfError(ls.GetAllApps()); |
|
883 |
|
884 |
|
885 while ( ls.GetNextApp( appInfo ) == KErrNone ) |
|
886 { |
|
887 allAppsArray->AppendL( appInfo.iFullName ); |
|
888 } |
|
889 CleanupStack::Pop( allAppsArray ); |
|
890 CleanupStack::PopAndDestroy( &ls ); |
|
891 |
|
892 |
|
893 // remove loadgen.* from the list |
|
894 for ( TInt i = 0; i < allAppsArray->MdcaCount(); i++ ) |
|
895 { |
|
896 if ( allAppsArray->MdcaPoint(i).FindF( _L("\\loadgen.") ) != KErrNotFound ) |
|
897 { |
|
898 allAppsArray->Delete(i); |
|
899 allAppsArray->Compress(); |
|
900 break; |
|
901 } |
|
902 } |
|
903 |
|
904 // sort the elements |
|
905 allAppsArray->Sort(); |
|
906 |
|
907 return allAppsArray; // ownership transferred |
|
908 } |
|
909 |
|
910 // End of File |