telephonyutils/etel3rdpartyapi/ExampleApps/SuppleServices/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 factory constructor CMainMenu::NewLC()
       
    34 
       
    35 @param aConsole Console to which output is printed
       
    36 */
       
    37 CMainMenu::CMainMenu(CConsoleBase& aConsole)
       
    38 	: CBaseMenuAsync(aConsole)
       
    39 	{
       
    40 	// Empty method
       
    41 	}
       
    42 
       
    43 /**
       
    44 Second phase constructor.
       
    45 */
       
    46 void CMainMenu::ConstructL()
       
    47 	{
       
    48 	CBaseMenuAsync::ConstructL();
       
    49 	iPhoneId = CPhoneId::NewL(this);
       
    50 	iCallForwarding = CCallForwardingStatus::NewL(this);
       
    51 	iCallWaiting = CCallWaitingStatus::NewL(this);
       
    52 	iCallBarring = CCallBarringStatus::NewL(this);
       
    53 	iFlightModeInfo = CFlightModeInfo::NewL(this);
       
    54 	iIdentityService = CIdentityServiceStatus::NewL(this);
       
    55 	}
       
    56 
       
    57 /**
       
    58 Destructor.
       
    59 Deletes owned objects.
       
    60 */
       
    61 CMainMenu::~CMainMenu()
       
    62 	{
       
    63 	delete iTelephony;
       
    64 	delete iPhoneId;
       
    65 	delete iFlightModeInfo;
       
    66 	delete iCallForwarding;
       
    67 	delete iCallWaiting;
       
    68 	delete iCallBarring;
       
    69 	delete iIdentityService;
       
    70 	}
       
    71 
       
    72 /**
       
    73 Provides functionality for member objects to notify the Menu object (their
       
    74 owner) that they have completed their request.
       
    75 
       
    76 @param aDerivedType Type of class derived from CISVAPIBase
       
    77 */
       
    78 void CMainMenu::ExecComplete(TTelISVExampleType aDerivedType)
       
    79 	{
       
    80    if	(iState==ESetNotifier || aDerivedType == KFlightModeInfo)
       
    81 		{
       
    82 		switch(aDerivedType)
       
    83 			{
       
    84 		case KCallForwardingStatus:
       
    85 			iLastOperation = iCallForwarding;
       
    86 			break;
       
    87 		case KCallBarringStatus:
       
    88 			iLastOperation = iCallBarring;
       
    89 			break;
       
    90 		case KCallWaitingStatus:
       
    91 			iLastOperation = iCallWaiting;
       
    92 			break;
       
    93 		case KFlightModeInfo:
       
    94 			iLastOperation = iFlightModeInfo;
       
    95 			break;
       
    96 		case KIdentityServiceStatus:
       
    97 			iLastOperation = iIdentityService;
       
    98 			break;
       
    99 			}
       
   100 		TRAPD(errNotify, iLastOperation->RequestNotificationL());
       
   101 		if (errNotify != KErrNone)
       
   102 			{
       
   103 			iConsole->Printf(_L("Notification Request for TTelISVExampleType"));
       
   104 			iConsole->Printf(_L("%d left with error code "), aDerivedType);
       
   105 			iConsole->Printf(_L("%d\n"), errNotify);
       
   106 			return;
       
   107 			};
       
   108 			
       
   109 		// Check the type of iLastOperation to see what it has been cast to.
       
   110 		switch(iLastOperation->GetExampleType())
       
   111 			{
       
   112 		case KCallBarringStatus:
       
   113 			iState = ECallWaiting;
       
   114 			iLastOperation = iCallWaiting;
       
   115 			SetActive();
       
   116 			CompleteOwnRequest(KErrNone);
       
   117 			break;
       
   118 		case KCallWaitingStatus:
       
   119 			iState = ECallForwarding;
       
   120 			iLastOperation = iCallForwarding;
       
   121 			SetActive();
       
   122 			CompleteOwnRequest(KErrNone);
       
   123 			break;
       
   124 		case KCallForwardingStatus:
       
   125 			iState = EIdentityService;
       
   126 			iLastOperation = iIdentityService;
       
   127 			SetActive();
       
   128 			CompleteOwnRequest(KErrNone);
       
   129 			break;
       
   130 		case KIdentityServiceStatus:
       
   131 			iConsole->Printf(KMenuMsg);
       
   132 			GetInput();
       
   133 			break;
       
   134 		default:
       
   135 
       
   136 			break;
       
   137 			}
       
   138 		}
       
   139 	else if(aDerivedType == KPhoneId)
       
   140 		{
       
   141 		iLastOperation = iFlightModeInfo;
       
   142 		SetActive();
       
   143 		CompleteOwnRequest(KErrNone);
       
   144 		}
       
   145 	}
       
   146 
       
   147 /**
       
   148 Provides functionality for member objects to notify the Menu object (their 
       
   149 owner) that they have been notified of a change.
       
   150 
       
   151 @param aDerivedType Type of class derived from CISVAPIBase.
       
   152 */
       
   153 void CMainMenu::ExecNotify(TTelISVExampleType aDerivedType)
       
   154 	{
       
   155 	switch(aDerivedType)
       
   156 		{
       
   157 	case KFlightModeInfo:
       
   158 		if (IsActive())
       
   159 			{
       
   160 			Cancel();
       
   161 			}
       
   162 		iState = ECallBarring;
       
   163 		iLastOperation = iCallBarring;
       
   164 		SetActive();
       
   165 		CompleteOwnRequest(KErrNone);
       
   166 		break;
       
   167 	case KCallForwardingStatus:
       
   168 		iState = ECallForwarding;
       
   169 		iLastOperation = iCallForwarding;
       
   170 		SetActive();
       
   171 		CompleteOwnRequest(KErrNone);
       
   172 		break;
       
   173 		}
       
   174 	}
       
   175 
       
   176 /**
       
   177 Handles key presses and CMainMenu states.
       
   178 */
       
   179 void CMainMenu::RunL()
       
   180 	{
       
   181 	switch(iState)
       
   182 		{
       
   183 	case EStart:
       
   184 		iState = EGetFlightModeInfo;
       
   185 		iLastOperation = iPhoneId;
       
   186 		TRAPD(errPhone, iLastOperation->StartRequestL());
       
   187 		if (errPhone)
       
   188 			{
       
   189 			iConsole->Printf(_L("Request left with error code "));
       
   190 			iConsole->Printf(_L("%d\n"), errPhone);
       
   191 			return;
       
   192 			};
       
   193 		break;
       
   194 	case EEnd:
       
   195 		CActiveScheduler::Stop();
       
   196 		break;
       
   197 	case EGetFlightModeInfo:
       
   198 	case ECallWaiting:
       
   199 	case ECallForwarding:
       
   200 	case ECallBarring:
       
   201 	case EIdentityService:
       
   202 		iState = ESetNotifier;
       
   203 		TRAPD(err, iLastOperation->StartRequestL());
       
   204 		if (err != KErrNone)
       
   205 			{
       
   206 			iConsole->Printf(_L("Request left with error code "));
       
   207 			iConsole->Printf(_L("%d\n"), err);
       
   208 			return;
       
   209 			}
       
   210 		break;
       
   211 	case EWaitingForKeyPress:
       
   212 		{
       
   213 		TInt c = iConsole->KeyCode();
       
   214 		switch(c)
       
   215 			{
       
   216 		case 'E':
       
   217 		case 'e':
       
   218 		case EKeyEscape:
       
   219 		// cancel notifications
       
   220 			iFlightModeInfo->Cancel();
       
   221 			CActiveScheduler::Stop();
       
   222 			break;
       
   223 		default:
       
   224 			GetInput();
       
   225 			}
       
   226 		}
       
   227 		break;
       
   228 	default:
       
   229 		break;
       
   230 		}
       
   231 	}
       
   232 
       
   233 /**
       
   234 Cancels outstanding asynchronous request.
       
   235 */
       
   236 void CMainMenu::DoCancel()
       
   237 	{
       
   238 	if(iState == EStart)
       
   239 		{
       
   240 		CompleteOwnRequest(KErrCancel);
       
   241 		}
       
   242 	else
       
   243 		{
       
   244 		iConsole->ReadCancel();
       
   245 		}
       
   246 	}
       
   247