|
1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 |
|
17 #include "CMainMenu.h" |
|
18 #include <simtsy.h> |
|
19 |
|
20 /** |
|
21 Factory constructor. |
|
22 |
|
23 @param aConsole Console to which output is printed |
|
24 @return Instance of CMainMenu class |
|
25 */ |
|
26 CMainMenu* CMainMenu::NewLC(CConsoleBase& aConsole) |
|
27 { |
|
28 CMainMenu* self = new(ELeave) CMainMenu(aConsole); |
|
29 CleanupStack::PushL(self); |
|
30 self->ConstructL(); |
|
31 return self; |
|
32 } |
|
33 |
|
34 /** |
|
35 Constructor called by CMainMenu::NewLC(). |
|
36 |
|
37 @param Console to which output is printed |
|
38 */ |
|
39 CMainMenu::CMainMenu(CConsoleBase& aConsole) |
|
40 : CBaseMenuAsync(aConsole) |
|
41 { |
|
42 iCount = 0; |
|
43 iMessages = 0; |
|
44 iRecievedCalls = 0; |
|
45 iCallWaitingOn = EFalse; |
|
46 } |
|
47 |
|
48 /** |
|
49 Second phase constructor. |
|
50 */ |
|
51 void CMainMenu::ConstructL() |
|
52 { |
|
53 CBaseMenuAsync::ConstructL(); |
|
54 iPhoneId = CPhoneId::NewL(this); |
|
55 |
|
56 // Create active objects using their factory constructors. |
|
57 iCallForwarding = CCallForwardingStatus::NewL(this); |
|
58 iCallBarring = CCallBarringStatus::NewL(this); |
|
59 iFlightModeInfo = CFlightModeInfo::NewL(this); |
|
60 iIdentityService = CIdentityServiceStatus::NewL(this); |
|
61 iCallWaiting = CCallWaitingStatus::NewL(this); |
|
62 |
|
63 iLineStatus = CLineStatus::NewL(this); |
|
64 iAnswerIncomingCall = CAnswerIncomingCall::NewL(this); |
|
65 iCallInfo = CCallInfo::NewL(this); |
|
66 iDummyAnswer = CDummyAnswer::NewL(this); |
|
67 iHangup = CHangup::NewL(this); |
|
68 |
|
69 iCallStatus = NULL; |
|
70 |
|
71 } |
|
72 |
|
73 /** |
|
74 Destructor. |
|
75 Deletes owned objects. |
|
76 */ |
|
77 CMainMenu::~CMainMenu() |
|
78 { |
|
79 delete iTelephony; |
|
80 delete iPhoneId; |
|
81 |
|
82 delete iFlightModeInfo; |
|
83 delete iCallForwarding; |
|
84 delete iCallBarring; |
|
85 delete iIdentityService; |
|
86 delete iCallWaiting; |
|
87 |
|
88 delete iAnswerIncomingCall; |
|
89 delete iHangup; |
|
90 delete iCallStatus; |
|
91 delete iCallInfo; |
|
92 delete iDummyAnswer; |
|
93 delete iLineStatus; |
|
94 } |
|
95 |
|
96 /** |
|
97 Provides functionality for member objects to notify the Menu object (their |
|
98 owner) that they have completed their request. |
|
99 |
|
100 @param aDerivedType Type of class derived from CISVAPIBase |
|
101 */ |
|
102 void CMainMenu::ExecComplete(TTelISVExampleType aDerivedType) |
|
103 { |
|
104 if (iState==ESetNotifier) |
|
105 { |
|
106 switch(aDerivedType) |
|
107 { |
|
108 case KLineStatus: |
|
109 iLastOperation = iLineStatus; |
|
110 break; |
|
111 case KCallInfo: |
|
112 iLastOperation = iCallInfo; |
|
113 break; |
|
114 case KCallStatus: |
|
115 iLastOperation = iCallStatus; |
|
116 break; |
|
117 case KAnswerIncomingCall: |
|
118 iLastOperation = iAnswerIncomingCall; |
|
119 break; |
|
120 case KHangup: |
|
121 iLastOperation = iHangup; |
|
122 break; |
|
123 case KCallForwardingStatus: |
|
124 iLastOperation = iCallForwarding; |
|
125 break; |
|
126 case KCallBarringStatus: |
|
127 iLastOperation = iCallBarring; |
|
128 break; |
|
129 case KFlightModeInfo: |
|
130 iLastOperation = iFlightModeInfo; |
|
131 break; |
|
132 case KIdentityServiceStatus: |
|
133 iLastOperation = iIdentityService; |
|
134 break; |
|
135 case KCallWaitingStatus: |
|
136 iLastOperation = iCallWaiting; |
|
137 break; |
|
138 } |
|
139 |
|
140 // Request to be told about particular events occurring. |
|
141 TRAPD(errNotify, iLastOperation->RequestNotificationL()); |
|
142 if (errNotify != KErrNone) |
|
143 { |
|
144 iConsole->Printf(_L("Notification Request for TTelISVExampleType")); |
|
145 iConsole->Printf(_L("%d left with error code "), aDerivedType); |
|
146 iConsole->Printf(_L("%d\n"), errNotify); |
|
147 return; |
|
148 }; |
|
149 |
|
150 // Check the type of iLastOperation to see what it has been cast to. |
|
151 switch(iLastOperation->GetExampleType()) |
|
152 { |
|
153 case KLineStatus: |
|
154 iConsole->ClearScreen(); |
|
155 iConsole->Printf(KMenuMsg); |
|
156 CallsCount(); |
|
157 iConsole->Printf(KAnyMsg); |
|
158 GetInput(); |
|
159 break; |
|
160 case KAnswerIncomingCall: |
|
161 iCallId = reinterpret_cast<CAnswerIncomingCall*> |
|
162 (iAnswerIncomingCall)->iCallId; |
|
163 TRAPD(err, iCallStatus = CCallStatus::NewL(this, iCallId)); |
|
164 if (err != KErrNone) |
|
165 { |
|
166 iConsole->Printf(_L("CallStatus construction left ")); |
|
167 iConsole->Printf(_L("with error code %d\n"), err); |
|
168 return; |
|
169 } |
|
170 iState = EGetCallStatus; |
|
171 iLastOperation = iCallStatus; |
|
172 SetActive(); |
|
173 CompleteOwnRequest(KErrNone); |
|
174 break; |
|
175 case KCallInfo: |
|
176 iState = EAnswerIncomingCall; |
|
177 iLastOperation = iAnswerIncomingCall; |
|
178 SetActive(); |
|
179 CompleteOwnRequest(KErrNone); |
|
180 break; |
|
181 case KCallStatus: |
|
182 iState = EDummyAnswer; |
|
183 SetActive(); |
|
184 CompleteOwnRequest(KErrNone); |
|
185 break; |
|
186 case KFlightModeInfo: |
|
187 if (IsActive()) |
|
188 { |
|
189 Cancel(); |
|
190 } |
|
191 iState = ECallBarring; |
|
192 iLastOperation = iCallBarring; |
|
193 SetActive(); |
|
194 CompleteOwnRequest(KErrNone); |
|
195 break; |
|
196 case KCallBarringStatus: |
|
197 iState = ECallForwarding; |
|
198 iLastOperation = iCallForwarding; |
|
199 SetActive(); |
|
200 CompleteOwnRequest(KErrNone); |
|
201 break; |
|
202 case KCallForwardingStatus: |
|
203 iState = EIdentityService; |
|
204 iLastOperation = iIdentityService; |
|
205 SetActive(); |
|
206 CompleteOwnRequest(KErrNone); |
|
207 break; |
|
208 case KIdentityServiceStatus: |
|
209 iState = ECallWaiting; |
|
210 iLastOperation = iCallWaiting; |
|
211 SetActive(); |
|
212 CompleteOwnRequest(KErrNone); |
|
213 break; |
|
214 case KCallWaitingStatus: |
|
215 iCallWaitingOn = EFalse; |
|
216 iState = EGetLineStatus; |
|
217 iLastOperation = iLineStatus; |
|
218 SetActive(); |
|
219 CompleteOwnRequest(KErrNone); |
|
220 break; |
|
221 default: |
|
222 |
|
223 break; |
|
224 } |
|
225 } |
|
226 else if(aDerivedType == KPhoneId) |
|
227 { |
|
228 iLastOperation = iFlightModeInfo; |
|
229 SetActive(); |
|
230 CompleteOwnRequest(KErrNone); |
|
231 } |
|
232 else if (aDerivedType == KNotType) |
|
233 { |
|
234 iConsole->ClearScreen(); |
|
235 iConsole->Printf(KMenuMsg); |
|
236 CallsCount(); |
|
237 iConsole->Printf(KHangupMsg); |
|
238 GetInput(); |
|
239 } |
|
240 } |
|
241 |
|
242 /** |
|
243 Provides functionality for member objects to notify the Menu object (their |
|
244 owner) that they have been notified of a change. |
|
245 |
|
246 @param aDerivedType Type of class derived from CISVAPIBase |
|
247 */ |
|
248 void CMainMenu::ExecNotify(TTelISVExampleType aDerivedType) |
|
249 { |
|
250 switch(aDerivedType) |
|
251 { |
|
252 case KAnswerIncomingCall: |
|
253 iCallId = reinterpret_cast<CAnswerIncomingCall*> |
|
254 (iAnswerIncomingCall)->iCallId; |
|
255 TRAPD(err, iCallStatus = CCallStatus::NewL(this, iCallId)); |
|
256 if (err != KErrNone) |
|
257 { |
|
258 iConsole->Printf(_L("CallStatus construction left ")); |
|
259 iConsole->Printf(_L("with error code %d\n"), err); |
|
260 return; |
|
261 } |
|
262 iState = EGetCallStatus; |
|
263 iLastOperation = iCallStatus; |
|
264 SetActive(); |
|
265 CompleteOwnRequest(KErrNone); |
|
266 break; |
|
267 case KCallWaitingStatus: |
|
268 iCallWaitingOn = ETrue; |
|
269 iState = EGetLineStatus; |
|
270 iLastOperation = iLineStatus; |
|
271 SetActive(); |
|
272 CompleteOwnRequest(KErrNone); |
|
273 break; |
|
274 case KLineStatus: |
|
275 if (iCallStatus != NULL) |
|
276 { |
|
277 iConsole->Printf(_L("Call Waiting!\n")); |
|
278 iRecievedCalls++; |
|
279 iConsole->ClearScreen(); |
|
280 iConsole->Printf(KMenuMsg); |
|
281 CallsCount(); |
|
282 iConsole->Printf(KHangupMsg); |
|
283 GetInput(); |
|
284 } |
|
285 else |
|
286 { |
|
287 // Request to be told about particular events occuring |
|
288 TRAPD(err, iLineStatus->RequestNotificationL()); |
|
289 if (err != KErrNone) |
|
290 { |
|
291 iConsole->Printf(_L("Request left with error code ")); |
|
292 iConsole->Printf(_L("%d\n"),err); |
|
293 return; |
|
294 } |
|
295 iRecievedCalls++; |
|
296 iState = EGetCallInfo; |
|
297 iLastOperation = iCallInfo; |
|
298 SetActive(); |
|
299 CompleteOwnRequest(KErrNone); |
|
300 } |
|
301 break; |
|
302 case KCallStatus: |
|
303 if (iFlightModeInfo->IsActive()) |
|
304 { |
|
305 iFlightModeInfo->Cancel(); |
|
306 } |
|
307 delete iCallStatus; |
|
308 iCallStatus = NULL; |
|
309 iLineStatus->Cancel(); |
|
310 iState = EStart; |
|
311 SetActive(); |
|
312 CompleteOwnRequest(KErrNone); |
|
313 break; |
|
314 case KCallForwardingStatus: |
|
315 iState = ECallForwarding; |
|
316 iLastOperation = iCallForwarding; |
|
317 SetActive(); |
|
318 CompleteOwnRequest(KErrNone); |
|
319 break; |
|
320 } |
|
321 } |
|
322 |
|
323 /** |
|
324 Responds appropriately depending on what key the user has pressed. |
|
325 */ |
|
326 void CMainMenu::RunL() |
|
327 { |
|
328 switch(iState) |
|
329 { |
|
330 case EStart: |
|
331 iState = EGetFlightModeInfo; |
|
332 if (iCount) |
|
333 { |
|
334 iCount = 0; |
|
335 iLastOperation = iFlightModeInfo; |
|
336 SetActive(); |
|
337 CompleteOwnRequest(KErrNone); |
|
338 } |
|
339 else |
|
340 { |
|
341 iLastOperation = iPhoneId; |
|
342 TRAPD(errPhone, iLastOperation->StartRequestL()); |
|
343 if (errPhone != KErrNone) |
|
344 { |
|
345 iConsole->Printf(_L("Request left with error code ")); |
|
346 iConsole->Printf(_L("%d\n"), errPhone); |
|
347 return; |
|
348 }; |
|
349 } |
|
350 break; |
|
351 case EEnd: |
|
352 iFlightModeInfo->Cancel(); |
|
353 CActiveScheduler::Stop(); |
|
354 break; |
|
355 case ECallWaiting: |
|
356 case EGetFlightModeInfo: |
|
357 case ECallForwarding: |
|
358 case ECallBarring: |
|
359 case EIdentityService: |
|
360 case EGetLineStatus: |
|
361 case EGetCallInfo: |
|
362 case EGetCallStatus: |
|
363 case EAnswerIncomingCall: |
|
364 iState = ESetNotifier; |
|
365 TRAPD(errAnswer, iLastOperation->StartRequestL()); |
|
366 if (errAnswer != KErrNone) |
|
367 { |
|
368 iConsole->Printf(_L("Request left with error code ")); |
|
369 iConsole->Printf(_L("%d\n"), errAnswer); |
|
370 return; |
|
371 }; |
|
372 break; |
|
373 case EHangup: |
|
374 iDummyAnswer->Cancel(); |
|
375 TRAPD(errArg, iLastOperation->StartRequestL(iCallId)); |
|
376 if (errArg != KErrNone) |
|
377 { |
|
378 iConsole->Printf(_L("Request left with error code ")); |
|
379 iConsole->Printf(_L("%d\n"), errArg); |
|
380 return; |
|
381 } |
|
382 break; |
|
383 case EDummyAnswer: |
|
384 iMessages++; |
|
385 iState = EHangup; |
|
386 TRAPD(errDummy, iDummyAnswer->StartCount(1000000)); |
|
387 if (errDummy != KErrNone) |
|
388 { |
|
389 iConsole->Printf(_L("Request left with error code ")); |
|
390 iConsole->Printf(_L("%d\n"), errDummy); |
|
391 return; |
|
392 }; |
|
393 break; |
|
394 case EWaitingForKeyPress: |
|
395 { |
|
396 TInt c = iConsole->KeyCode(); |
|
397 switch(c) |
|
398 { |
|
399 case 'E': |
|
400 case 'e': |
|
401 case EKeyEscape: |
|
402 // Cancel notifications |
|
403 if (iAnswerIncomingCall->IsActive()) |
|
404 { |
|
405 iAnswerIncomingCall->Cancel(); |
|
406 } |
|
407 if (iHangup->IsActive()) |
|
408 { |
|
409 iHangup->Cancel(); |
|
410 } |
|
411 if (iCallStatus != NULL && iCallStatus->IsActive()) |
|
412 { |
|
413 iCallStatus->Cancel(); |
|
414 } |
|
415 iFlightModeInfo->Cancel(); |
|
416 iLineStatus->Cancel(); |
|
417 CActiveScheduler::Stop(); |
|
418 break; |
|
419 case 'h': |
|
420 case 'H': |
|
421 if (iDummyAnswer->IsActive()) |
|
422 { |
|
423 iState = EHangup; |
|
424 iLastOperation = iHangup; |
|
425 SetActive(); |
|
426 CompleteOwnRequest(KErrNone); |
|
427 break; |
|
428 } |
|
429 else |
|
430 { |
|
431 GetInput(); |
|
432 break; |
|
433 } |
|
434 case 'i': |
|
435 case 'I': |
|
436 { |
|
437 CTelephony::TPhoneLine line = CTelephony::EVoiceLine; |
|
438 CTelephony::TCallStatusV1 iLineStatusV1; |
|
439 CTelephony::TCallStatusV1Pckg iLineStatusV1Pckg(iLineStatusV1); |
|
440 iTelephony->GetLineStatus(line, iLineStatusV1Pckg); |
|
441 CTelephony::TCallStatus voiceLineStatus = iLineStatusV1.iStatus; |
|
442 if (iCount >= 1 |
|
443 && iCallWaitingOn |
|
444 && voiceLineStatus != CTelephony::EStatusRinging) |
|
445 { |
|
446 iCount++; |
|
447 TInt ret = RProperty::Set(KUidPSSimTsyCategory, |
|
448 KPSSimTsyIncomingVoiceCall, |
|
449 0); |
|
450 break; |
|
451 } |
|
452 else |
|
453 { |
|
454 GetInput(); |
|
455 break; |
|
456 } |
|
457 } |
|
458 default: |
|
459 // Pressed a non suggested key to simulate an incoming call |
|
460 if (iCount == 0) |
|
461 { |
|
462 // For SIM TSY to simulate an incoming call |
|
463 iCount = 1; |
|
464 TInt ret = RProperty::Set(KUidPSSimTsyCategory, |
|
465 KPSSimTsyIncomingVoiceCall, |
|
466 0); |
|
467 } |
|
468 else |
|
469 { |
|
470 GetInput(); |
|
471 } |
|
472 break; |
|
473 } |
|
474 } |
|
475 break; |
|
476 default: |
|
477 break; |
|
478 } // switch(iState) |
|
479 } |
|
480 |
|
481 /** |
|
482 Calculates the number of people who did not leave a message and displays result |
|
483 to the console. Result = Number of received calls - Number of messages received |
|
484 */ |
|
485 void CMainMenu::CallsCount() |
|
486 { |
|
487 iConsole->Printf(_L("You have %d Messages\n"), iMessages); |
|
488 TInt difference = iRecievedCalls - iMessages; |
|
489 if (difference > 0) |
|
490 { |
|
491 iConsole->Printf(_L("%d people called and left no message\n"), |
|
492 difference); |
|
493 } |
|
494 } |
|
495 |
|
496 /** |
|
497 Cancels outstanding asynchronous request. |
|
498 */ |
|
499 void CMainMenu::DoCancel() |
|
500 { |
|
501 if(iState == EStart) |
|
502 { |
|
503 CompleteOwnRequest(KErrCancel); |
|
504 } |
|
505 else |
|
506 { |
|
507 iConsole->ReadCancel(); |
|
508 } |
|
509 } |