|
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 Default constructor called by CMainMenu::NewLC(). |
|
35 |
|
36 @param 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 iNetworkInfo = CCurrentNetworkInfo::NewL(this); |
|
52 iFlightModeInfo = CFlightModeInfo::NewL(this); |
|
53 } |
|
54 |
|
55 /** |
|
56 Destructor. |
|
57 Deletes owned objects. |
|
58 */ |
|
59 CMainMenu::~CMainMenu() |
|
60 { |
|
61 delete iTelephony; |
|
62 delete iPhoneId; |
|
63 delete iFlightModeInfo; |
|
64 delete iNetworkInfo; |
|
65 } |
|
66 |
|
67 /** |
|
68 Provides functionality for member objects to notify the Menu object (their |
|
69 owner) that they have completed their request. |
|
70 |
|
71 @param aDerivedType Type of class derived from CISVAPIBase |
|
72 */ |
|
73 void CMainMenu::ExecComplete(TTelISVExampleType aDerivedType) |
|
74 { |
|
75 if (iState==ESetNotifier || aDerivedType == KFlightModeInfo) |
|
76 { |
|
77 switch(aDerivedType) |
|
78 { |
|
79 case KNetworkInfo: |
|
80 iLastOperation = iNetworkInfo; |
|
81 break; |
|
82 case KFlightModeInfo: |
|
83 iLastOperation = iFlightModeInfo; |
|
84 break; |
|
85 } |
|
86 TRAPD(errNotify, iLastOperation->RequestNotificationL()); |
|
87 if (errNotify != KErrNone) |
|
88 { |
|
89 iConsole->Printf(_L("Notification Request for TTelISVExampleType")); |
|
90 iConsole->Printf(_L("%d left with error code "), aDerivedType); |
|
91 iConsole->Printf(_L("%d\n"), errNotify); |
|
92 return; |
|
93 }; |
|
94 // Check the type of iLastOperation to see |
|
95 // what it has been cast to. |
|
96 switch(iLastOperation->GetExampleType()) |
|
97 { |
|
98 case KFlightModeInfo: |
|
99 if (IsActive()) |
|
100 { |
|
101 Cancel(); |
|
102 } |
|
103 iState = EGetNetworkInfo; |
|
104 iLastOperation = iNetworkInfo; |
|
105 SetActive(); |
|
106 CompleteOwnRequest(KErrNone); |
|
107 break; |
|
108 case KNetworkInfo: |
|
109 iConsole->Printf(KMenuMsg); |
|
110 GetInput(); |
|
111 break; |
|
112 default: |
|
113 |
|
114 break; |
|
115 } |
|
116 } |
|
117 else if(aDerivedType == KPhoneId) |
|
118 { |
|
119 iLastOperation = iFlightModeInfo; |
|
120 SetActive(); |
|
121 CompleteOwnRequest(KErrNone); |
|
122 } |
|
123 } |
|
124 |
|
125 /** |
|
126 Provides functionality for member objects to notify the Menu object (their |
|
127 owner) that they have been notified of a change. |
|
128 |
|
129 @param aDerivedType Type of class derived from CISVAPIBase |
|
130 */ |
|
131 void CMainMenu::ExecNotify(TTelISVExampleType aDerivedType) |
|
132 { |
|
133 switch(aDerivedType) |
|
134 { |
|
135 case KFlightModeInfo: |
|
136 // Request to be told about particular events occurring |
|
137 TRAPD(err, iFlightModeInfo->RequestNotificationL()); |
|
138 if (err != KErrNone) |
|
139 { |
|
140 iConsole->Printf(_L("%d\n"),err); |
|
141 return; |
|
142 } |
|
143 iNetworkInfo->Cancel(); |
|
144 break; |
|
145 } |
|
146 } |
|
147 |
|
148 /** |
|
149 Moves the active object into the next state depending on what its current state |
|
150 is. |
|
151 */ |
|
152 void CMainMenu::RunL() |
|
153 { |
|
154 switch(iState) |
|
155 { |
|
156 case EStart: |
|
157 iState = EGetFlightModeInfo; |
|
158 iLastOperation = iPhoneId; |
|
159 TRAPD(errPhone, iLastOperation->StartRequestL()); |
|
160 if (errPhone) |
|
161 { |
|
162 iConsole->Printf(_L("Request left with error code ")); |
|
163 iConsole->Printf(_L("%d\n"), errPhone); |
|
164 return; |
|
165 }; |
|
166 break; |
|
167 case EEnd: |
|
168 CActiveScheduler::Stop(); |
|
169 break; |
|
170 case EGetFlightModeInfo: |
|
171 case EGetNetworkInfo: |
|
172 iState = ESetNotifier; |
|
173 TRAPD(err, iLastOperation->StartRequestL()); |
|
174 if (err) |
|
175 { |
|
176 iConsole->Printf(_L("Request left with error code ")); |
|
177 iConsole->Printf(_L("%d\n"), err); |
|
178 return; |
|
179 } |
|
180 break; |
|
181 case EWaitingForKeyPress: |
|
182 { |
|
183 TInt c = iConsole->KeyCode(); |
|
184 // Handle key presses |
|
185 switch(c) |
|
186 { |
|
187 case 'E': |
|
188 case 'e': |
|
189 case EKeyEscape: |
|
190 // Cancel notifications |
|
191 iNetworkInfo->Cancel(); |
|
192 iFlightModeInfo->Cancel(); |
|
193 CActiveScheduler::Stop(); |
|
194 break; |
|
195 default: |
|
196 GetInput(); |
|
197 } |
|
198 } |
|
199 break; |
|
200 default: |
|
201 break; |
|
202 } |
|
203 } |
|
204 |
|
205 /** |
|
206 Cancels outstanding asynchronous request. |
|
207 */ |
|
208 void CMainMenu::DoCancel() |
|
209 { |
|
210 if(iState == EStart) |
|
211 { |
|
212 CompleteOwnRequest(KErrCancel); |
|
213 } |
|
214 else |
|
215 { |
|
216 iConsole->ReadCancel(); |
|
217 } |
|
218 } |