00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include "CMainMenu.h"
00033 #include <simtsy.h>
00034
00041 CMainMenu* CMainMenu::NewLC(CConsoleBase& aConsole)
00042 {
00043 CMainMenu* self = new(ELeave) CMainMenu(aConsole);
00044 CleanupStack::PushL(self);
00045 self->ConstructL();
00046 return self;
00047 }
00048
00054 CMainMenu::CMainMenu(CConsoleBase& aConsole)
00055 : CBaseMenuAsync(aConsole)
00056 {
00057 iCount = 0;
00058 iMessages = 0;
00059 iRecievedCalls = 0;
00060 iCallWaitingOn = EFalse;
00061 }
00062
00066 void CMainMenu::ConstructL()
00067 {
00068 CBaseMenuAsync::ConstructL();
00069 iPhoneId = CPhoneId::NewL(this);
00070
00071
00072 iCallForwarding = CCallForwardingStatus::NewL(this);
00073 iCallBarring = CCallBarringStatus::NewL(this);
00074 iFlightModeInfo = CFlightModeInfo::NewL(this);
00075 iIdentityService = CIdentityServiceStatus::NewL(this);
00076 iCallWaiting = CCallWaitingStatus::NewL(this);
00077
00078 iLineStatus = CLineStatus::NewL(this);
00079 iAnswerIncomingCall = CAnswerIncomingCall::NewL(this);
00080 iCallInfo = CCallInfo::NewL(this);
00081 iDummyAnswer = CDummyAnswer::NewL(this);
00082 iHangup = CHangup::NewL(this);
00083
00084 iCallStatus = NULL;
00085
00086 }
00087
00092 CMainMenu::~CMainMenu()
00093 {
00094 delete iTelephony;
00095 delete iPhoneId;
00096
00097 delete iFlightModeInfo;
00098 delete iCallForwarding;
00099 delete iCallBarring;
00100 delete iIdentityService;
00101 delete iCallWaiting;
00102
00103 delete iAnswerIncomingCall;
00104 delete iHangup;
00105 delete iCallStatus;
00106 delete iCallInfo;
00107 delete iDummyAnswer;
00108 delete iLineStatus;
00109 }
00110
00117 void CMainMenu::ExecComplete(TTelISVExampleType aDerivedType)
00118 {
00119 if (iState==ESetNotifier)
00120 {
00121 switch(aDerivedType)
00122 {
00123 case KLineStatus:
00124 iLastOperation = iLineStatus;
00125 break;
00126 case KCallInfo:
00127 iLastOperation = iCallInfo;
00128 break;
00129 case KCallStatus:
00130 iLastOperation = iCallStatus;
00131 break;
00132 case KAnswerIncomingCall:
00133 iLastOperation = iAnswerIncomingCall;
00134 break;
00135 case KHangup:
00136 iLastOperation = iHangup;
00137 break;
00138 case KCallForwardingStatus:
00139 iLastOperation = iCallForwarding;
00140 break;
00141 case KCallBarringStatus:
00142 iLastOperation = iCallBarring;
00143 break;
00144 case KFlightModeInfo:
00145 iLastOperation = iFlightModeInfo;
00146 break;
00147 case KIdentityServiceStatus:
00148 iLastOperation = iIdentityService;
00149 break;
00150 case KCallWaitingStatus:
00151 iLastOperation = iCallWaiting;
00152 break;
00153 case KNotType:
00154 case KPhoneId:
00155 case KSubscriberId:
00156 case KBatteryInfo:
00157 case KSignalInfo:
00158 case KGetIndicator:
00159 case KLockInfo:
00160 case KNetworkInfo:
00161 case KNetworkName:
00162 case KOperatorName:
00163 case KNetworkRegInfo:
00164 case KDialCall:
00165 case KDynamicCaps:
00166 case KHold:
00167 case KResume:
00168 case KSwap:
00169 case KSendDTMF:
00170 default:
00171 break;
00172 }
00173
00174
00175 TRAPD(errNotify, iLastOperation->RequestNotificationL());
00176 if (errNotify != KErrNone)
00177 {
00178 iConsole->Printf(_L("Notification Request for TTelISVExampleType"));
00179 iConsole->Printf(_L("%d left with error code "), aDerivedType);
00180 iConsole->Printf(_L("%d\n"), errNotify);
00181 return;
00182 };
00183
00184
00185 switch(iLastOperation->GetExampleType())
00186 {
00187 case KLineStatus:
00188 iConsole->ClearScreen();
00189 iConsole->Printf(KMenuMsg);
00190 CallsCount();
00191 iConsole->Printf(KAnyMsg);
00192 GetInput();
00193 break;
00194 case KAnswerIncomingCall:
00195 iCallId = reinterpret_cast<CAnswerIncomingCall*>
00196 (iAnswerIncomingCall)->iCallId;
00197 TRAPD(err, iCallStatus = CCallStatus::NewL(this, iCallId));
00198 if (err != KErrNone)
00199 {
00200 iConsole->Printf(_L("CallStatus construction left "));
00201 iConsole->Printf(_L("with error code %d\n"), err);
00202 return;
00203 }
00204 iState = EGetCallStatus;
00205 iLastOperation = iCallStatus;
00206 SetActive();
00207 CompleteOwnRequest(KErrNone);
00208 break;
00209 case KCallInfo:
00210 iState = EAnswerIncomingCall;
00211 iLastOperation = iAnswerIncomingCall;
00212 SetActive();
00213 CompleteOwnRequest(KErrNone);
00214 break;
00215 case KCallStatus:
00216 iState = EDummyAnswer;
00217 SetActive();
00218 CompleteOwnRequest(KErrNone);
00219 break;
00220 case KFlightModeInfo:
00221 if (IsActive())
00222 {
00223 Cancel();
00224 }
00225 iState = ECallBarring;
00226 iLastOperation = iCallBarring;
00227 SetActive();
00228 CompleteOwnRequest(KErrNone);
00229 break;
00230 case KCallBarringStatus:
00231 iState = ECallForwarding;
00232 iLastOperation = iCallForwarding;
00233 SetActive();
00234 CompleteOwnRequest(KErrNone);
00235 break;
00236 case KCallForwardingStatus:
00237 iState = EIdentityService;
00238 iLastOperation = iIdentityService;
00239 SetActive();
00240 CompleteOwnRequest(KErrNone);
00241 break;
00242 case KIdentityServiceStatus:
00243 iState = ECallWaiting;
00244 iLastOperation = iCallWaiting;
00245 SetActive();
00246 CompleteOwnRequest(KErrNone);
00247 break;
00248 case KCallWaitingStatus:
00249 iCallWaitingOn = EFalse;
00250 iState = EGetLineStatus;
00251 iLastOperation = iLineStatus;
00252 SetActive();
00253 CompleteOwnRequest(KErrNone);
00254 break;
00255 default:
00256
00257 break;
00258 }
00259 }
00260 else if(aDerivedType == KPhoneId)
00261 {
00262 iLastOperation = iFlightModeInfo;
00263 SetActive();
00264 CompleteOwnRequest(KErrNone);
00265 }
00266 else if (aDerivedType == KNotType)
00267 {
00268 iConsole->ClearScreen();
00269 iConsole->Printf(KMenuMsg);
00270 CallsCount();
00271 iConsole->Printf(KHangupMsg);
00272 GetInput();
00273 }
00274 }
00275
00282 void CMainMenu::ExecNotify(TTelISVExampleType aDerivedType)
00283 {
00284 switch(aDerivedType)
00285 {
00286 case KAnswerIncomingCall:
00287 iCallId = reinterpret_cast<CAnswerIncomingCall*>
00288 (iAnswerIncomingCall)->iCallId;
00289 TRAPD(err, iCallStatus = CCallStatus::NewL(this, iCallId));
00290 if (err != KErrNone)
00291 {
00292 iConsole->Printf(_L("CallStatus construction left "));
00293 iConsole->Printf(_L("with error code %d\n"), err);
00294 return;
00295 }
00296 iState = EGetCallStatus;
00297 iLastOperation = iCallStatus;
00298 SetActive();
00299 CompleteOwnRequest(KErrNone);
00300 break;
00301 case KCallWaitingStatus:
00302 iCallWaitingOn = ETrue;
00303 iState = EGetLineStatus;
00304 iLastOperation = iLineStatus;
00305 SetActive();
00306 CompleteOwnRequest(KErrNone);
00307 break;
00308 case KLineStatus:
00309 if (iCallStatus != NULL)
00310 {
00311 iConsole->Printf(_L("Call Waiting!\n"));
00312 iRecievedCalls++;
00313 iConsole->ClearScreen();
00314 iConsole->Printf(KMenuMsg);
00315 CallsCount();
00316 iConsole->Printf(KHangupMsg);
00317 GetInput();
00318 }
00319 else
00320 {
00321
00322 TRAPD(err, iLineStatus->RequestNotificationL());
00323 if (err != KErrNone)
00324 {
00325 iConsole->Printf(_L("Request left with error code "));
00326 iConsole->Printf(_L("%d\n"),err);
00327 return;
00328 }
00329 iRecievedCalls++;
00330 iState = EGetCallInfo;
00331 iLastOperation = iCallInfo;
00332 SetActive();
00333 CompleteOwnRequest(KErrNone);
00334 }
00335 break;
00336 case KCallStatus:
00337 if (iFlightModeInfo->IsActive())
00338 {
00339 iFlightModeInfo->Cancel();
00340 }
00341 delete iCallStatus;
00342 iCallStatus = NULL;
00343 iLineStatus->Cancel();
00344 iState = EStart;
00345 SetActive();
00346 CompleteOwnRequest(KErrNone);
00347 break;
00348 case KCallForwardingStatus:
00349 iState = ECallForwarding;
00350 iLastOperation = iCallForwarding;
00351 SetActive();
00352 CompleteOwnRequest(KErrNone);
00353 break;
00354 case KNotType:
00355 case KPhoneId:
00356 case KSubscriberId:
00357 case KBatteryInfo:
00358 case KSignalInfo:
00359 case KGetIndicator:
00360 case KLockInfo:
00361 case KNetworkInfo:
00362 case KNetworkName:
00363 case KOperatorName:
00364 case KCallInfo:
00365 case KFlightModeInfo:
00366 case KNetworkRegInfo:
00367 case KDialCall:
00368 case KDynamicCaps:
00369 case KHold:
00370 case KResume:
00371 case KSwap:
00372 case KSendDTMF:
00373 case KHangup:
00374 case KCallBarringStatus:
00375 case KIdentityServiceStatus:
00376 default:
00377 break;
00378 }
00379 }
00380
00384 void CMainMenu::RunL()
00385 {
00386 switch(iState)
00387 {
00388 case EStart:
00389 iState = EGetFlightModeInfo;
00390 if (iCount)
00391 {
00392 iCount = 0;
00393 iLastOperation = iFlightModeInfo;
00394 SetActive();
00395 CompleteOwnRequest(KErrNone);
00396 }
00397 else
00398 {
00399 iLastOperation = iPhoneId;
00400 TRAPD(errPhone, iLastOperation->StartRequestL());
00401 if (errPhone != KErrNone)
00402 {
00403 iConsole->Printf(_L("Request left with error code "));
00404 iConsole->Printf(_L("%d\n"), errPhone);
00405 return;
00406 };
00407 }
00408 break;
00409 case EEnd:
00410 iFlightModeInfo->Cancel();
00411 CActiveScheduler::Stop();
00412 break;
00413 case ECallWaiting:
00414 case EGetFlightModeInfo:
00415 case ECallForwarding:
00416 case ECallBarring:
00417 case EIdentityService:
00418 case EGetLineStatus:
00419 case EGetCallInfo:
00420 case EGetCallStatus:
00421 case EAnswerIncomingCall:
00422 iState = ESetNotifier;
00423 TRAPD(errAnswer, iLastOperation->StartRequestL());
00424 if (errAnswer != KErrNone)
00425 {
00426 iConsole->Printf(_L("Request left with error code "));
00427 iConsole->Printf(_L("%d\n"), errAnswer);
00428 return;
00429 };
00430 break;
00431 case EHangup:
00432 iDummyAnswer->Cancel();
00433 TRAPD(errArg, iLastOperation->StartRequestL(iCallId));
00434 if (errArg != KErrNone)
00435 {
00436 iConsole->Printf(_L("Request left with error code "));
00437 iConsole->Printf(_L("%d\n"), errArg);
00438 return;
00439 }
00440 break;
00441 case EDummyAnswer:
00442 iMessages++;
00443 iState = EHangup;
00444 TRAPD(errDummy, iDummyAnswer->StartCount(1000000));
00445 if (errDummy != KErrNone)
00446 {
00447 iConsole->Printf(_L("Request left with error code "));
00448 iConsole->Printf(_L("%d\n"), errDummy);
00449 return;
00450 };
00451 break;
00452 case EWaitingForKeyPress:
00453 {
00454 TInt c = iConsole->KeyCode();
00455 switch(c)
00456 {
00457 case 'E':
00458 case 'e':
00459 case EKeyEscape:
00460
00461 if (iAnswerIncomingCall->IsActive())
00462 {
00463 iAnswerIncomingCall->Cancel();
00464 }
00465 if (iHangup->IsActive())
00466 {
00467 iHangup->Cancel();
00468 }
00469 if (iCallStatus != NULL && iCallStatus->IsActive())
00470 {
00471 iCallStatus->Cancel();
00472 }
00473 iFlightModeInfo->Cancel();
00474 iLineStatus->Cancel();
00475 CActiveScheduler::Stop();
00476 break;
00477 case 'h':
00478 case 'H':
00479 if (iDummyAnswer->IsActive())
00480 {
00481 iState = EHangup;
00482 iLastOperation = iHangup;
00483 SetActive();
00484 CompleteOwnRequest(KErrNone);
00485 break;
00486 }
00487 else
00488 {
00489 GetInput();
00490 break;
00491 }
00492 case 'i':
00493 case 'I':
00494 {
00495 CTelephony::TPhoneLine line = CTelephony::EVoiceLine;
00496 CTelephony::TCallStatusV1 iLineStatusV1;
00497 CTelephony::TCallStatusV1Pckg iLineStatusV1Pckg(iLineStatusV1);
00498 iTelephony->GetLineStatus(line, iLineStatusV1Pckg);
00499 CTelephony::TCallStatus voiceLineStatus = iLineStatusV1.iStatus;
00500 if (iCount >= 1
00501 && iCallWaitingOn
00502 && voiceLineStatus != CTelephony::EStatusRinging)
00503 {
00504 iCount++;
00505 TInt ret = RProperty::Set(KUidPSSimTsyCategory,
00506 KPSSimTsyIncomingVoiceCall,
00507 0);
00508 if(ret!=KErrNone)
00509 {
00510 iConsole->Printf(_L("Set failed : %d\n"),ret);
00511 }
00512 break;
00513 }
00514 else
00515 {
00516 GetInput();
00517 break;
00518 }
00519 }
00520 default:
00521
00522 if (iCount == 0)
00523 {
00524
00525 iCount = 1;
00526 TInt ret = RProperty::Set(KUidPSSimTsyCategory,
00527 KPSSimTsyIncomingVoiceCall,
00528 0);
00529 if(ret!=KErrNone)
00530 {
00531 iConsole->Printf(_L("Set failed : %d\n"),ret);
00532 }
00533
00534 }
00535 else
00536 {
00537 GetInput();
00538 }
00539 break;
00540 }
00541 }
00542 break;
00543 default:
00544 break;
00545 }
00546 }
00547
00552 void CMainMenu::CallsCount()
00553 {
00554 iConsole->Printf(_L("You have %d Messages\n"), iMessages);
00555 TInt difference = iRecievedCalls - iMessages;
00556 if (difference > 0)
00557 {
00558 iConsole->Printf(_L("%d people called and left no message\n"),
00559 difference);
00560 }
00561 }
00562
00566 void CMainMenu::DoCancel()
00567 {
00568 if(iState == EStart)
00569 {
00570 CompleteOwnRequest(KErrCancel);
00571 }
00572 else
00573 {
00574 iConsole->ReadCancel();
00575 }
00576 }