telephonyutils/etel3rdpartyapi/ExampleApps/AutoDTMFDialler/CMainMenu.cpp
changeset 0 3553901f7fa8
child 24 6638e7f4bd8f
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     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 #include "CMainMenu.h"
       
    17 
       
    18 /**
       
    19 Factory constructor.
       
    20 
       
    21 @param  aConsole Console to which output is printed.
       
    22 @return          Instance of CMainMenu class.
       
    23 */
       
    24 CMainMenu* CMainMenu::NewLC(CConsoleBase& aConsole)
       
    25 	{
       
    26 	CMainMenu* self = new(ELeave) CMainMenu(aConsole);
       
    27 	CleanupStack::PushL(self);
       
    28 	self->ConstructL();
       
    29 	return self;
       
    30 	}
       
    31 
       
    32 /**
       
    33 Constructor called by CMainMenu::NewLC(). Sets iSingleString to ETrue 
       
    34 by default.
       
    35 
       
    36 @param Console to which output is printed
       
    37 */
       
    38 CMainMenu::CMainMenu(CConsoleBase& aConsole)
       
    39 	: CBaseMenuAsync(aConsole)
       
    40 	, iCurrentTone(_L(""))
       
    41 	, iCurrentToneLog(_L(""))
       
    42 	, iTheNumber(KTheNumber)
       
    43 	{
       
    44 	iSingleString = ETrue;
       
    45 	}
       
    46 
       
    47 /**
       
    48 Second phase constructor.
       
    49 */
       
    50 void CMainMenu::ConstructL()
       
    51 	{
       
    52 	CBaseMenuAsync::ConstructL();
       
    53 	iPhoneId = CPhoneId::NewL(this);
       
    54 
       
    55 	iFlightModeInfo = CFlightModeInfo::NewL(this);
       
    56 	iNetworkRegInfo = CNetworkRegInfo::NewL(this);
       
    57 
       
    58 	iDialCall = CDialCall::NewL(this);
       
    59 	iSendDTMF = CSendDTMF::NewL(this);
       
    60 	iHangup = CHangup::NewL(this);
       
    61 	iLineStatus = CLineStatus::NewL(this);
       
    62 	}
       
    63 
       
    64 /**
       
    65 Destructor.  Deletes the owned objects.
       
    66 */
       
    67 CMainMenu::~CMainMenu()
       
    68 	{
       
    69 	delete iTelephony;
       
    70 	delete iPhoneId;
       
    71 
       
    72 	delete iFlightModeInfo;
       
    73 	delete iNetworkRegInfo;
       
    74 
       
    75 	delete iDialCall;
       
    76 	delete iHangup;
       
    77 	delete iSendDTMF;
       
    78 	delete iCallStatus;
       
    79 	delete iLineStatus;
       
    80 	}
       
    81 
       
    82 /**
       
    83 Provides functionality for member objects to notify the Menu object
       
    84 (their owner) that they have completed their request.
       
    85 
       
    86 @param aDerivedType Type of class derived from CISVAPIBase
       
    87 */
       
    88 void CMainMenu::ExecComplete(TTelISVExampleType aDerivedType)
       
    89 	{
       
    90 	if	(iState==ESetNotifier || aDerivedType == KDialCall)
       
    91 		{
       
    92 		switch(aDerivedType)
       
    93 			{
       
    94 		case KSendDTMF:
       
    95 			iLastOperation = iSendDTMF;
       
    96 			break;
       
    97 		case KFlightModeInfo:
       
    98 			iLastOperation = iFlightModeInfo;
       
    99 			break;
       
   100 		case KNetworkRegInfo:
       
   101 			iLastOperation = iNetworkRegInfo;
       
   102 			break;
       
   103 		case KDialCall:
       
   104 			iLastOperation = iDialCall;
       
   105 			break;
       
   106 		case KHangup:
       
   107 			iLastOperation = iHangup;
       
   108 			break;
       
   109 		case KCallStatus:
       
   110 			iLastOperation = iCallStatus;
       
   111 			break;
       
   112 			}
       
   113 		TRAPD(errNotify, iLastOperation->RequestNotificationL());
       
   114 		if (errNotify != KErrNone)
       
   115 			{
       
   116 			iConsole->Printf(_L("Notification Request for TTelISVExampleType"));
       
   117 			iConsole->Printf(_L("%d left with error code "), aDerivedType);
       
   118 			iConsole->Printf(_L("%d\n"), errNotify);
       
   119 			return;
       
   120 			}
       
   121 			
       
   122 		// Check the type of iLastOperation to see
       
   123 		// what it has been cast to.
       
   124 		switch(iLastOperation->GetExampleType())
       
   125 			{
       
   126 		case KFlightModeInfo:
       
   127 			iState = EGetNetworkRegStatus;
       
   128 			iLastOperation = iNetworkRegInfo;
       
   129 			SetActive();
       
   130 			CompleteOwnRequest(KErrNone);
       
   131 			break;
       
   132 		case KDialCall:
       
   133 			iCallId = reinterpret_cast<CDialCall*>
       
   134 			          (iDialCall)->iCallId;
       
   135 			TRAPD(err, 	iCallStatus = CCallStatus::NewL(this, iCallId));
       
   136 			if (err != KErrNone)
       
   137 				{
       
   138 				iConsole->Printf(_L("CallStatus construction left "));
       
   139 				iConsole->Printf(_L("with error code %d\n"), err);
       
   140 				return;
       
   141 				}
       
   142 			iState = EGetCallStatus;
       
   143 			iLastOperation = iCallStatus;
       
   144 			SetActive();
       
   145 			CompleteOwnRequest(KErrNone);
       
   146 			break;
       
   147 		case KCallStatus:
       
   148 			iConsole->ClearScreen();
       
   149 			iConsole->Printf(KMenuMsg);
       
   150 			iConsole->Printf(KDTMFQuestion);
       
   151 			iConsole->Printf(KiSingleString);
       
   152 			iConsole->Printf(KAsChar);
       
   153 			GetInput();
       
   154 			break;
       
   155 		case KSendDTMF:
       
   156 			iConsole->ClearScreen();
       
   157 			iConsole->Printf(KMenuMsg);
       
   158 			iConsole->Printf(KHangupMsg);
       
   159 			GetInput();
       
   160 			break;
       
   161 		default:
       
   162 
       
   163 			break;
       
   164 			}
       
   165 		}
       
   166 	else if(aDerivedType == KPhoneId)
       
   167 		{
       
   168 		iLastOperation = iFlightModeInfo;
       
   169 		SetActive();
       
   170 		CompleteOwnRequest(KErrNone);
       
   171 		}
       
   172 	}
       
   173 
       
   174 /**
       
   175 Provides functionality for member objects to notify the Menu object
       
   176 (their owner) that they have been notified of a change.
       
   177 
       
   178 @param aDerivedType Type of class derived from CISVAPIBase
       
   179 */
       
   180 void CMainMenu::ExecNotify(TTelISVExampleType aDerivedType)
       
   181 	{
       
   182 	switch(aDerivedType)
       
   183 		{
       
   184 	case KNetworkRegInfo:
       
   185 		TRAPD(err, iNetworkRegInfo->RequestNotificationL());
       
   186 		if (err != KErrNone)
       
   187 			{
       
   188 			iConsole->Printf(_L("Request left with error code "));
       
   189 			iConsole->Printf(_L("%d\n"),err);
       
   190 			return;
       
   191 			}
       
   192 		iState = EGetLineStatus;
       
   193 		iLastOperation = iLineStatus;
       
   194 		SetActive();
       
   195 		CompleteOwnRequest(KErrNone);
       
   196 		break;
       
   197 	case KLineStatus:
       
   198 		// Waiting for dial request
       
   199 		TRAP(err, iLineStatus->RequestNotificationL());
       
   200 		if (err != KErrNone)
       
   201 			{
       
   202 			iConsole->Printf(_L("Request left with error code "));
       
   203 			iConsole->Printf(_L("%d\n"),err);
       
   204 			return;
       
   205 			}
       
   206 		iConsole->ClearScreen();
       
   207 		iConsole->Printf(KMenuMsg);
       
   208 		iConsole->Printf(KDialMsg);
       
   209 		GetInput();
       
   210 		break;
       
   211 	case KCallStatus:
       
   212 		delete iCallStatus;
       
   213 		iCallStatus = NULL;
       
   214 		iState = EGetLineStatus;
       
   215 		iLastOperation = iLineStatus;
       
   216 		SetActive();
       
   217 		CompleteOwnRequest(KErrNone);
       
   218 		break;
       
   219 	case KSendDTMF:
       
   220 		iConsole->ClearScreen();
       
   221 		iConsole->Printf(KMenuMsg);
       
   222 		iConsole->Printf(KAsChar);
       
   223 		GetInput();
       
   224 		break;
       
   225 	default:
       
   226 		break;
       
   227 		}
       
   228 	}
       
   229 
       
   230 /**
       
   231 Handles user's key presses.
       
   232 */
       
   233 void CMainMenu::RunL()
       
   234 	{
       
   235 	switch(iState)
       
   236 		{
       
   237 	case EStart:
       
   238 		iState = EGetFlightModeInfo;
       
   239 		iLastOperation = iPhoneId;
       
   240 		TRAPD(errPhone, iLastOperation->StartRequestL());
       
   241 		if (errPhone != KErrNone)
       
   242 			{
       
   243 			iConsole->Printf(_L("Request left with error code "));
       
   244 			iConsole->Printf(_L("%d\n"), errPhone);
       
   245 			return;
       
   246 			}
       
   247 		break;
       
   248 	case EEnd:
       
   249 		CActiveScheduler::Stop();
       
   250 		break;
       
   251 	case EGetLineStatus:
       
   252 	case EGetCallStatus:
       
   253 	case EGetFlightModeInfo:
       
   254 	case EGetNetworkRegStatus:
       
   255 		iState = ESetNotifier;
       
   256 		TRAPD(err, iLastOperation->StartRequestL());
       
   257 		if (err != KErrNone)
       
   258 			{
       
   259 			iConsole->Printf(_L("Request left with error code "));
       
   260 			iConsole->Printf(_L("%d\n"), err);
       
   261 			return;
       
   262 			}
       
   263 		break;
       
   264 	case EHangup:
       
   265 		iState = ESetNotifier;
       
   266 		TRAPD(errArg, iLastOperation->StartRequestL(iCallId));
       
   267 		if (errArg != KErrNone)
       
   268 			{
       
   269 			iConsole->Printf(_L("Request left with error code "));
       
   270 			iConsole->Printf(_L("%d\n"), errArg);
       
   271 			return;
       
   272 			}
       
   273 		break;
       
   274 	case EDialCall:
       
   275 		iState = ESetNotifier;
       
   276 		TRAPD(errArg3, iLastOperation->StartRequestL(KTheNumber));
       
   277 		if (errArg3 != KErrNone)
       
   278 			{
       
   279 			iConsole->Printf(_L("Request left with error code "));
       
   280 			iConsole->Printf(_L("%d\n"), errArg3);
       
   281 			return;
       
   282 			}
       
   283 		break;
       
   284 	case ESendDTMF:
       
   285 		iState = ESetNotifier;
       
   286 		if (iSingleString)
       
   287 			{
       
   288 			TRAPD(errArg2, iLastOperation->StartRequestL(iTheNumber))
       
   289 			if (errArg2 != KErrNone)
       
   290 				{
       
   291 				iConsole->Printf(_L("Request left with error code "));
       
   292 				iConsole->Printf(_L("%d\n"), errArg2);
       
   293 				return;
       
   294 				}
       
   295 			}
       
   296 		else
       
   297 			{
       
   298 			TRAPD(errArg2, iLastOperation->StartRequestL(iCurrentTone))
       
   299 			if (errArg2 != KErrNone)
       
   300 				{
       
   301 				iConsole->Printf(_L("Request left with error code "));
       
   302 				iConsole->Printf(_L("%d\n"), errArg2);
       
   303 				return;
       
   304 				}
       
   305 			}
       
   306 		break;
       
   307 	case EWaitingForKeyPress:
       
   308 		{
       
   309 		TInt c = iConsole->KeyCode();
       
   310 		switch(c)
       
   311 			{
       
   312 		case 'E':
       
   313 		case 'e':
       
   314 		case EKeyEscape:
       
   315 		// Cancel notifications
       
   316 			iNetworkRegInfo->Cancel();
       
   317 			iFlightModeInfo->Cancel();
       
   318 			if (iCallStatus != NULL)
       
   319 				{
       
   320 				iCallStatus->Cancel();
       
   321 				}
       
   322 			if (iLineStatus->IsActive())
       
   323 				{
       
   324 				iLineStatus->Cancel();
       
   325 				}
       
   326 			CActiveScheduler::Stop();
       
   327 			break;
       
   328 		case 'D':
       
   329 		case 'd':
       
   330 			if (iCallStatus == NULL)
       
   331 				{
       
   332 				iState = EDialCall;
       
   333 				iLastOperation = iDialCall;
       
   334 				SetActive();
       
   335 				CompleteOwnRequest(KErrNone);
       
   336 				break;
       
   337 				}
       
   338 			else
       
   339 				{
       
   340 				// Print correct menu
       
   341 				GetInput();
       
   342 				break;
       
   343 				}
       
   344 		case 'H':
       
   345 		case 'h':
       
   346 			if (iCallStatus != NULL)
       
   347 				{
       
   348 				iSingleString = ETrue;
       
   349 				iState = EHangup;
       
   350 				iLastOperation = iHangup;
       
   351 				SetActive();
       
   352 				CompleteOwnRequest(KErrNone);
       
   353 				break;
       
   354 				}
       
   355 			else
       
   356 				{
       
   357 				// Print correct menu
       
   358 				GetInput();
       
   359 				break;
       
   360 				}
       
   361 		case 'S':
       
   362 		case 's':
       
   363 			if (iCallStatus != NULL && iSingleString)
       
   364 				{
       
   365 				iConsole->Printf(_L("Be Right Back\n"));
       
   366 				iSingleString = ETrue;
       
   367 				iCurrentToneLog.Append(iTheNumber);
       
   368 				iCurrentToneLog.Append('#');
       
   369 				iState = ESendDTMF;
       
   370 				iLastOperation = iSendDTMF;
       
   371 				SetActive();
       
   372 				CompleteOwnRequest(KErrNone);
       
   373 				break;
       
   374 				}
       
   375 			else
       
   376 				{
       
   377 				// Print correct menu
       
   378 				GetInput();
       
   379 				break;
       
   380 				}
       
   381 		// Send number
       
   382 		case '0':
       
   383 		case '1':
       
   384 		case '2':
       
   385 		case '3':
       
   386 		case '4':
       
   387 		case '5':
       
   388 		case '6':
       
   389 		case '7':
       
   390 		case '8':
       
   391 		case '9':
       
   392 		case '*':
       
   393 			if (iCallStatus != NULL)
       
   394 				{
       
   395 				iSingleString = EFalse;
       
   396 				iCurrentTone.Delete(0,1);
       
   397 				iCurrentTone.Append(c);
       
   398 				iCurrentToneLog.Append(iCurrentTone);
       
   399 				iState = ESendDTMF;
       
   400 				iLastOperation = iSendDTMF;
       
   401 				SetActive();
       
   402 				CompleteOwnRequest(KErrNone);
       
   403 				break;
       
   404 				}
       
   405 			else
       
   406 				{
       
   407 				// Print correct menu
       
   408 				GetInput();
       
   409 				break;
       
   410 				}
       
   411 
       
   412 		case '#':
       
   413 			if (iCallStatus != NULL && !iSingleString)
       
   414 				{
       
   415 				iConsole->Printf(_L("You sent "));
       
   416 				iConsole->Printf(iCurrentToneLog);
       
   417 				iConsole->Printf(KNewLine);
       
   418 				iCurrentToneLog.Delete(0, iCurrentToneLog.Length());
       
   419 				iConsole->Printf(KMenuMsg);
       
   420 				iConsole->Printf(KHangupMsg);
       
   421 				// Key presses finished!
       
   422 				// Call is active, DTMF has been indicated to be
       
   423 				// finished as # character has been received.
       
   424 				}
       
   425 			else
       
   426 				{
       
   427 				// Print correct menu
       
   428 				GetInput();
       
   429 				break;
       
   430 				}
       
   431 		default:
       
   432 			GetInput();
       
   433 			}
       
   434 		}
       
   435 		break;
       
   436 	default:
       
   437 		break;
       
   438 		}
       
   439 	}
       
   440 	
       
   441 /**
       
   442 Cancels outstanding asynchonous request.
       
   443 */
       
   444 void CMainMenu::DoCancel()
       
   445 	{
       
   446 	if(iState == EStart)
       
   447 		{
       
   448 		CompleteOwnRequest(KErrCancel);
       
   449 		}
       
   450 	else
       
   451 		{
       
   452 		iConsole->ReadCancel();
       
   453 		}
       
   454 	}