00001 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). 00002 // All rights reserved. 00003 // This component and the accompanying materials are made available 00004 // under the terms of "Eclipse Public License v1.0" 00005 // which accompanies this distribution, and is available 00006 // at the URL "http://www.eclipse.org/legal/epl-v10.html". 00007 // 00008 // Initial Contributors: 00009 // Nokia Corporation - initial contribution. 00010 // 00011 // Contributors: 00012 // 00013 // Description: 00014 // 00015 00016 #include "CMainMenu.h" 00017 00024 CMainMenu* CMainMenu::NewLC(CConsoleBase& aConsole) 00025 { 00026 CMainMenu* self = new(ELeave) CMainMenu(aConsole); 00027 CleanupStack::PushL(self); 00028 self->ConstructL(); 00029 return self; 00030 } 00031 00038 CMainMenu::CMainMenu(CConsoleBase& aConsole) 00039 : CBaseMenuAsync(aConsole) 00040 , iCurrentTone(_L("")) 00041 , iCurrentToneLog(_L("")) 00042 , iTheNumber(KTheNumber) 00043 { 00044 iSingleString = ETrue; 00045 } 00046 00050 void CMainMenu::ConstructL() 00051 { 00052 CBaseMenuAsync::ConstructL(); 00053 iPhoneId = CPhoneId::NewL(this); 00054 00055 iFlightModeInfo = CFlightModeInfo::NewL(this); 00056 iNetworkRegInfo = CNetworkRegInfo::NewL(this); 00057 00058 iDialCall = CDialCall::NewL(this); 00059 iSendDTMF = CSendDTMF::NewL(this); 00060 iHangup = CHangup::NewL(this); 00061 iLineStatus = CLineStatus::NewL(this); 00062 } 00063 00067 CMainMenu::~CMainMenu() 00068 { 00069 delete iTelephony; 00070 delete iPhoneId; 00071 00072 delete iFlightModeInfo; 00073 delete iNetworkRegInfo; 00074 00075 delete iDialCall; 00076 delete iHangup; 00077 delete iSendDTMF; 00078 delete iCallStatus; 00079 delete iLineStatus; 00080 } 00081 00088 void CMainMenu::ExecComplete(TTelISVExampleType aDerivedType) 00089 { 00090 if (iState==ESetNotifier || aDerivedType == KDialCall) 00091 { 00092 switch(aDerivedType) 00093 { 00094 case KSendDTMF: 00095 iLastOperation = iSendDTMF; 00096 break; 00097 case KFlightModeInfo: 00098 iLastOperation = iFlightModeInfo; 00099 break; 00100 case KNetworkRegInfo: 00101 iLastOperation = iNetworkRegInfo; 00102 break; 00103 case KDialCall: 00104 iLastOperation = iDialCall; 00105 break; 00106 case KHangup: 00107 iLastOperation = iHangup; 00108 break; 00109 case KCallStatus: 00110 iLastOperation = iCallStatus; 00111 break; 00112 default: 00113 break; 00114 } 00115 TRAPD(errNotify, iLastOperation->RequestNotificationL()); 00116 if (errNotify != KErrNone) 00117 { 00118 iConsole->Printf(_L("Notification Request for TTelISVExampleType")); 00119 iConsole->Printf(_L("%d left with error code "), aDerivedType); 00120 iConsole->Printf(_L("%d\n"), errNotify); 00121 return; 00122 } 00123 00124 // Check the type of iLastOperation to see 00125 // what it has been cast to. 00126 switch(iLastOperation->GetExampleType()) 00127 { 00128 case KFlightModeInfo: 00129 iState = EGetNetworkRegStatus; 00130 iLastOperation = iNetworkRegInfo; 00131 SetActive(); 00132 CompleteOwnRequest(KErrNone); 00133 break; 00134 case KDialCall: 00135 iCallId = reinterpret_cast<CDialCall*> 00136 (iDialCall)->iCallId; 00137 TRAPD(err, iCallStatus = CCallStatus::NewL(this, iCallId)); 00138 if (err != KErrNone) 00139 { 00140 iConsole->Printf(_L("CallStatus construction left ")); 00141 iConsole->Printf(_L("with error code %d\n"), err); 00142 return; 00143 } 00144 iState = EGetCallStatus; 00145 iLastOperation = iCallStatus; 00146 SetActive(); 00147 CompleteOwnRequest(KErrNone); 00148 break; 00149 case KCallStatus: 00150 iConsole->ClearScreen(); 00151 iConsole->Printf(KMenuMsg); 00152 iConsole->Printf(KDTMFQuestion); 00153 iConsole->Printf(KiSingleString); 00154 iConsole->Printf(KAsChar); 00155 GetInput(); 00156 break; 00157 case KSendDTMF: 00158 iConsole->ClearScreen(); 00159 iConsole->Printf(KMenuMsg); 00160 iConsole->Printf(KHangupMsg); 00161 GetInput(); 00162 break; 00163 default: 00164 00165 break; 00166 } 00167 } 00168 else if(aDerivedType == KPhoneId) 00169 { 00170 iLastOperation = iFlightModeInfo; 00171 SetActive(); 00172 CompleteOwnRequest(KErrNone); 00173 } 00174 } 00175 00182 void CMainMenu::ExecNotify(TTelISVExampleType aDerivedType) 00183 { 00184 switch(aDerivedType) 00185 { 00186 case KNetworkRegInfo: 00187 TRAPD(err, iNetworkRegInfo->RequestNotificationL()); 00188 if (err != KErrNone) 00189 { 00190 iConsole->Printf(_L("Request left with error code ")); 00191 iConsole->Printf(_L("%d\n"),err); 00192 return; 00193 } 00194 iState = EGetLineStatus; 00195 iLastOperation = iLineStatus; 00196 SetActive(); 00197 CompleteOwnRequest(KErrNone); 00198 break; 00199 case KLineStatus: 00200 // Waiting for dial request 00201 TRAP(err, iLineStatus->RequestNotificationL()); 00202 if (err != KErrNone) 00203 { 00204 iConsole->Printf(_L("Request left with error code ")); 00205 iConsole->Printf(_L("%d\n"),err); 00206 return; 00207 } 00208 iConsole->ClearScreen(); 00209 iConsole->Printf(KMenuMsg); 00210 iConsole->Printf(KDialMsg); 00211 GetInput(); 00212 break; 00213 case KCallStatus: 00214 delete iCallStatus; 00215 iCallStatus = NULL; 00216 iState = EGetLineStatus; 00217 iLastOperation = iLineStatus; 00218 SetActive(); 00219 CompleteOwnRequest(KErrNone); 00220 break; 00221 case KSendDTMF: 00222 iConsole->ClearScreen(); 00223 iConsole->Printf(KMenuMsg); 00224 iConsole->Printf(KAsChar); 00225 GetInput(); 00226 break; 00227 default: 00228 break; 00229 } 00230 } 00231 00235 void CMainMenu::RunL() 00236 { 00237 switch(iState) 00238 { 00239 case EStart: 00240 iState = EGetFlightModeInfo; 00241 iLastOperation = iPhoneId; 00242 TRAPD(errPhone, iLastOperation->StartRequestL()); 00243 if (errPhone != KErrNone) 00244 { 00245 iConsole->Printf(_L("Request left with error code ")); 00246 iConsole->Printf(_L("%d\n"), errPhone); 00247 return; 00248 } 00249 break; 00250 case EEnd: 00251 CActiveScheduler::Stop(); 00252 break; 00253 case EGetLineStatus: 00254 case EGetCallStatus: 00255 case EGetFlightModeInfo: 00256 case EGetNetworkRegStatus: 00257 iState = ESetNotifier; 00258 TRAPD(err, iLastOperation->StartRequestL()); 00259 if (err != KErrNone) 00260 { 00261 iConsole->Printf(_L("Request left with error code ")); 00262 iConsole->Printf(_L("%d\n"), err); 00263 return; 00264 } 00265 break; 00266 case EHangup: 00267 iState = ESetNotifier; 00268 TRAPD(errArg, iLastOperation->StartRequestL(iCallId)); 00269 if (errArg != KErrNone) 00270 { 00271 iConsole->Printf(_L("Request left with error code ")); 00272 iConsole->Printf(_L("%d\n"), errArg); 00273 return; 00274 } 00275 break; 00276 case EDialCall: 00277 iState = ESetNotifier; 00278 TRAPD(errArg3, iLastOperation->StartRequestL(KTheNumber)); 00279 if (errArg3 != KErrNone) 00280 { 00281 iConsole->Printf(_L("Request left with error code ")); 00282 iConsole->Printf(_L("%d\n"), errArg3); 00283 return; 00284 } 00285 break; 00286 case ESendDTMF: 00287 iState = ESetNotifier; 00288 if (iSingleString) 00289 { 00290 TRAPD(errArg2, iLastOperation->StartRequestL(iTheNumber)) 00291 if (errArg2 != KErrNone) 00292 { 00293 iConsole->Printf(_L("Request left with error code ")); 00294 iConsole->Printf(_L("%d\n"), errArg2); 00295 return; 00296 } 00297 } 00298 else 00299 { 00300 TRAPD(errArg2, iLastOperation->StartRequestL(iCurrentTone)) 00301 if (errArg2 != KErrNone) 00302 { 00303 iConsole->Printf(_L("Request left with error code ")); 00304 iConsole->Printf(_L("%d\n"), errArg2); 00305 return; 00306 } 00307 } 00308 break; 00309 case EWaitingForKeyPress: 00310 { 00311 TInt c = iConsole->KeyCode(); 00312 switch(c) 00313 { 00314 case 'E': 00315 case 'e': 00316 case EKeyEscape: 00317 // Cancel notifications 00318 iNetworkRegInfo->Cancel(); 00319 iFlightModeInfo->Cancel(); 00320 if (iCallStatus != NULL) 00321 { 00322 iCallStatus->Cancel(); 00323 } 00324 if (iLineStatus->IsActive()) 00325 { 00326 iLineStatus->Cancel(); 00327 } 00328 CActiveScheduler::Stop(); 00329 break; 00330 case 'D': 00331 case 'd': 00332 if (iCallStatus == NULL) 00333 { 00334 iState = EDialCall; 00335 iLastOperation = iDialCall; 00336 SetActive(); 00337 CompleteOwnRequest(KErrNone); 00338 break; 00339 } 00340 else 00341 { 00342 // Print correct menu 00343 GetInput(); 00344 break; 00345 } 00346 case 'H': 00347 case 'h': 00348 if (iCallStatus != NULL) 00349 { 00350 iSingleString = ETrue; 00351 iState = EHangup; 00352 iLastOperation = iHangup; 00353 SetActive(); 00354 CompleteOwnRequest(KErrNone); 00355 break; 00356 } 00357 else 00358 { 00359 // Print correct menu 00360 GetInput(); 00361 break; 00362 } 00363 case 'S': 00364 case 's': 00365 if (iCallStatus != NULL && iSingleString) 00366 { 00367 iConsole->Printf(_L("Be Right Back\n")); 00368 iSingleString = ETrue; 00369 iCurrentToneLog.Append(iTheNumber); 00370 iCurrentToneLog.Append('#'); 00371 iState = ESendDTMF; 00372 iLastOperation = iSendDTMF; 00373 SetActive(); 00374 CompleteOwnRequest(KErrNone); 00375 break; 00376 } 00377 else 00378 { 00379 // Print correct menu 00380 GetInput(); 00381 break; 00382 } 00383 // Send number 00384 case '0': 00385 case '1': 00386 case '2': 00387 case '3': 00388 case '4': 00389 case '5': 00390 case '6': 00391 case '7': 00392 case '8': 00393 case '9': 00394 case '*': 00395 if (iCallStatus != NULL) 00396 { 00397 iSingleString = EFalse; 00398 iCurrentTone.Delete(0,1); 00399 iCurrentTone.Append(c); 00400 iCurrentToneLog.Append(iCurrentTone); 00401 iState = ESendDTMF; 00402 iLastOperation = iSendDTMF; 00403 SetActive(); 00404 CompleteOwnRequest(KErrNone); 00405 break; 00406 } 00407 else 00408 { 00409 // Print correct menu 00410 GetInput(); 00411 break; 00412 } 00413 00414 case '#': 00415 if (iCallStatus != NULL && !iSingleString) 00416 { 00417 iConsole->Printf(_L("You sent ")); 00418 iConsole->Printf(iCurrentToneLog); 00419 iConsole->Printf(KNewLine); 00420 iCurrentToneLog.Delete(0, iCurrentToneLog.Length()); 00421 iConsole->Printf(KMenuMsg); 00422 iConsole->Printf(KHangupMsg); 00423 // Key presses finished! 00424 // Call is active, DTMF has been indicated to be 00425 // finished as # character has been received. 00426 } 00427 else 00428 { 00429 // Print correct menu 00430 GetInput(); 00431 break; 00432 } 00433 default: 00434 GetInput(); 00435 } 00436 } 00437 break; 00438 default: 00439 break; 00440 } 00441 } 00442 00446 void CMainMenu::DoCancel() 00447 { 00448 if(iState == EStart) 00449 { 00450 CompleteOwnRequest(KErrCancel); 00451 } 00452 else 00453 { 00454 iConsole->ReadCancel(); 00455 } 00456 }
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights
reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License
v1.0.