|
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 |
|
19 /** |
|
20 Factory constructor. |
|
21 |
|
22 @param aConsole Console to which output is printed |
|
23 @return Instance of CMainMenu class |
|
24 */ |
|
25 CMainMenu* CMainMenu::NewLC(CConsoleBase& aConsole) |
|
26 { |
|
27 CMainMenu* self = new(ELeave) CMainMenu(aConsole); |
|
28 CleanupStack::PushL(self); |
|
29 self->ConstructL(); |
|
30 return self; |
|
31 } |
|
32 |
|
33 /** |
|
34 Constructor, called by the CMainMenu::NewLC() factory constructor. |
|
35 |
|
36 @param aConsole Console to which output is printed. |
|
37 */ |
|
38 CMainMenu::CMainMenu(CConsoleBase& aConsole) |
|
39 : CBaseMenuAsync(aConsole) |
|
40 { |
|
41 // Empty method |
|
42 } |
|
43 |
|
44 /** |
|
45 Second phase constructor. |
|
46 */ |
|
47 void CMainMenu::ConstructL() |
|
48 { |
|
49 CBaseMenuAsync::ConstructL(); |
|
50 iPhoneId = CPhoneId::NewL(this); |
|
51 |
|
52 iBatteryInfo = CBatteryInfo::NewL(this); |
|
53 iSignalInfo = CSignalInfo::NewL(this); |
|
54 |
|
55 iFlightModeInfo = CFlightModeInfo::NewL(this); |
|
56 iGetIndicator = CGetIndicator::NewL(this); |
|
57 } |
|
58 |
|
59 /** |
|
60 Destructor. |
|
61 Deletes owned objects. |
|
62 */ |
|
63 CMainMenu::~CMainMenu() |
|
64 { |
|
65 delete iTelephony; |
|
66 delete iPhoneId; |
|
67 |
|
68 delete iBatteryInfo; |
|
69 delete iSignalInfo; |
|
70 |
|
71 delete iFlightModeInfo; |
|
72 delete iGetIndicator; |
|
73 } |
|
74 |
|
75 /** |
|
76 Provides functionality for member objects to notify the Menu object (their |
|
77 owner) that they have completed their request. |
|
78 |
|
79 @param aDerivedType Type of class derived from CISVAPIBase |
|
80 */ |
|
81 void CMainMenu::ExecComplete(TTelISVExampleType aDerivedType) |
|
82 { |
|
83 if(iState==ESetNotifier || aDerivedType == KFlightModeInfo) |
|
84 { |
|
85 switch(aDerivedType) |
|
86 { |
|
87 case KBatteryInfo: |
|
88 iLastOperation = iBatteryInfo; |
|
89 break; |
|
90 case KSignalInfo: |
|
91 iLastOperation = iSignalInfo; |
|
92 break; |
|
93 case KFlightModeInfo: |
|
94 iLastOperation = iFlightModeInfo; |
|
95 break; |
|
96 case KGetIndicator: |
|
97 iLastOperation = iGetIndicator; |
|
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 KBatteryInfo: |
|
113 iState = EGetFlightModeInfo; |
|
114 iLastOperation = iFlightModeInfo; |
|
115 SetActive(); |
|
116 CompleteOwnRequest(KErrNone); |
|
117 break; |
|
118 case KSignalInfo: |
|
119 iConsole->Printf(KMenuMsg); |
|
120 GetInput(); |
|
121 break; |
|
122 case KFlightModeInfo: |
|
123 Cancel(); |
|
124 iState = EGetSignalInfo; |
|
125 iLastOperation = iSignalInfo; |
|
126 SetActive(); |
|
127 CompleteOwnRequest(KErrNone); |
|
128 break; |
|
129 case KGetIndicator: |
|
130 iState = EGetBatteryInfo; |
|
131 iLastOperation = iBatteryInfo; |
|
132 SetActive(); |
|
133 CompleteOwnRequest(KErrNone); |
|
134 break; |
|
135 default: |
|
136 |
|
137 break; |
|
138 } |
|
139 } |
|
140 else if(aDerivedType == KPhoneId) |
|
141 { |
|
142 iLastOperation = iGetIndicator; |
|
143 SetActive(); |
|
144 CompleteOwnRequest(KErrNone); |
|
145 } |
|
146 } |
|
147 |
|
148 /** |
|
149 Provides functionality for member objects to notify the Menu object (their |
|
150 owner) that they have been notified of a change. |
|
151 |
|
152 @param aDerivedType Type of class derived from CISVAPIBase |
|
153 */ |
|
154 void CMainMenu::ExecNotify(TTelISVExampleType aDerivedType) |
|
155 { |
|
156 switch(aDerivedType) |
|
157 { |
|
158 case KFlightModeInfo: |
|
159 if (IsActive()) |
|
160 { |
|
161 Cancel(); |
|
162 } |
|
163 if (iSignalInfo->IsActive()) |
|
164 { |
|
165 iSignalInfo->Cancel(); |
|
166 } |
|
167 iConsole->Printf(KMenuMsg); |
|
168 GetInput(); |
|
169 break; |
|
170 } |
|
171 } |
|
172 |
|
173 /** |
|
174 Handles key presses and CMainMenu states. |
|
175 */ |
|
176 void CMainMenu::RunL() |
|
177 { |
|
178 switch(iState) |
|
179 { |
|
180 case EStart: |
|
181 iState = EGetIndicator; |
|
182 iLastOperation = iPhoneId; |
|
183 TRAPD(errPhone, iLastOperation->StartRequestL()); |
|
184 if (errPhone != KErrNone) |
|
185 { |
|
186 iConsole->Printf(_L("Request left with error code ")); |
|
187 iConsole->Printf(_L("%d\n"), errPhone); |
|
188 return; |
|
189 }; |
|
190 break; |
|
191 case EEnd: |
|
192 CActiveScheduler::Stop(); |
|
193 break; |
|
194 case EGetIndicator: |
|
195 case EGetBatteryInfo: |
|
196 case EGetSignalInfo: |
|
197 case EGetFlightModeInfo: |
|
198 iState = ESetNotifier; |
|
199 TRAPD(err, iLastOperation->StartRequestL()); |
|
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 break; |
|
207 case EWaitingForKeyPress: |
|
208 { |
|
209 TInt c = iConsole->KeyCode(); |
|
210 switch(c) |
|
211 { |
|
212 case 'E': |
|
213 case 'e': |
|
214 case EKeyEscape: |
|
215 iGetIndicator->Cancel(); |
|
216 iBatteryInfo->Cancel(); |
|
217 iSignalInfo->Cancel(); |
|
218 iFlightModeInfo->Cancel(); |
|
219 |
|
220 CActiveScheduler::Stop(); |
|
221 break; |
|
222 default: |
|
223 GetInput(); |
|
224 } |
|
225 } |
|
226 break; |
|
227 default: |
|
228 break; |
|
229 } |
|
230 } |
|
231 |
|
232 /** |
|
233 Cancels outstanding asynchronous request. |
|
234 */ |
|
235 void CMainMenu::DoCancel() |
|
236 { |
|
237 if(iState == EStart) |
|
238 { |
|
239 CompleteOwnRequest(KErrCancel); |
|
240 } |
|
241 else |
|
242 { |
|
243 iConsole->ReadCancel(); |
|
244 } |
|
245 } |
|
246 |