|
1 /* |
|
2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Implementation of CPhoneUIController class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <featmgr.h> // for FeatureManager |
|
21 #include <settingsinternalcrkeys.h> |
|
22 |
|
23 #include "cphoneuicontroller.h" |
|
24 #include "pevirtualengine.h" |
|
25 #include "cphonestatehandle.h" |
|
26 #include "cphoneenginehandler.h" |
|
27 #include "cphonesystemeventhandler.h" |
|
28 #include "cphoneremotecontrolhandler.h" |
|
29 #include "mphoneviewcommandhandle.h" |
|
30 #include "phonestatedefinitions.h" |
|
31 #include "phonelogger.h" |
|
32 #include "phoneconstants.h" |
|
33 #include "phoneui.pan" |
|
34 #include "cphonekeyeventforwarder.h" |
|
35 #include "cphonecenrepproxy.h" |
|
36 #include "cphonemediatorfactory.h" |
|
37 #include "tphonecmdparamnumberentryobserver.h" |
|
38 |
|
39 // ================= MEMBER FUNCTIONS ======================= |
|
40 |
|
41 // ----------------------------------------------------------- |
|
42 // CPhoneUIController::CPhoneUIController |
|
43 // C++ default constructor can NOT contain any code, that |
|
44 // might leave. |
|
45 // ----------------------------------------------------------- |
|
46 // |
|
47 CPhoneUIController::CPhoneUIController() |
|
48 { |
|
49 } |
|
50 |
|
51 // ----------------------------------------------------------- |
|
52 // CPhoneUIController::ConstructL() |
|
53 // (other items were commented in a header). |
|
54 // ----------------------------------------------------------- |
|
55 // |
|
56 void CPhoneUIController::ConstructL( |
|
57 MPhoneViewCommandHandle* aViewCommandHandle ) |
|
58 { |
|
59 __LOGMETHODSTARTEND(EPhoneControl, "CPhoneUIController::ConstructL()"); |
|
60 // Creates correct protocol DLL |
|
61 CreateProtocolDllL( aViewCommandHandle ); |
|
62 |
|
63 // Reference the phone state machine |
|
64 iStateMachine = CPhoneStateHandle::Instance()->StateMachine(); |
|
65 |
|
66 // Create the phone engine handler |
|
67 iEngineHandler = CPhoneEngineHandler::NewL( iStateMachine ); |
|
68 // Create the system event handler |
|
69 iSystemEventHandler = CPhoneSystemEventHandler::NewL( iStateMachine ); |
|
70 // Create the remote control handler |
|
71 iRemoteControlHandler = CPhoneRemoteControlHandler::NewL( iStateMachine ); |
|
72 // Create the key event forwarder |
|
73 iKeyEventForwarder = CPhoneKeyEventForwarder::NewL( |
|
74 CEikonEnv::Static()->EikAppUi()->ClientRect(), iStateMachine, aViewCommandHandle ); |
|
75 |
|
76 TInt leaveCode( 0 ); |
|
77 TInt retry( 0 ); |
|
78 RTimer timer; |
|
79 TRequestStatus timerReady; |
|
80 timer.CreateLocal(); |
|
81 // Phone Engine is tried to start for KPeRetryCount times |
|
82 do |
|
83 { |
|
84 // Handle the message and trap leaves from message handling functions |
|
85 TRAP( leaveCode, iPhoneEngine = iStateMachine->CreatePhoneEngineL( |
|
86 *this ) ); |
|
87 |
|
88 if ( leaveCode ) |
|
89 { |
|
90 // This thread is suspended for KPeRetryDelay |
|
91 timer.After( timerReady, KPeRetryDelay ); |
|
92 User::WaitForRequest( timerReady ); |
|
93 retry++; |
|
94 } |
|
95 }while ( leaveCode && retry < KPeRetryCount ); |
|
96 timer.Close(); |
|
97 |
|
98 if ( leaveCode ) |
|
99 { |
|
100 // If Phone Engine didn't start |
|
101 User::Leave( leaveCode ); |
|
102 } |
|
103 |
|
104 // Get the engine info |
|
105 iEngineInfo = iPhoneEngine->EngineInfo(); |
|
106 |
|
107 // Store the phone engine information in the logger |
|
108 CPhoneLogger* phoneLogger = static_cast<CPhoneLogger*> |
|
109 ( CCoeEnv::Static( KUidPhoneUILoggerSingleton ) ); |
|
110 phoneLogger->SetPhoneEngine( iPhoneEngine ); |
|
111 |
|
112 // Store the phone engine information in the state machine |
|
113 iStateMachine->SetPhoneEngine( iPhoneEngine ); |
|
114 |
|
115 // Set Number Entry observer |
|
116 TPhoneCmdParamNumberEntryObserver cmdParamNumberEntryObserver; |
|
117 cmdParamNumberEntryObserver.SetObserver( TCallBack( HandlePhoneNumberEditorCallBack, this ) ); |
|
118 aViewCommandHandle->ExecuteCommand( EPhoneViewSetNumberEntryObserver, |
|
119 &cmdParamNumberEntryObserver); |
|
120 |
|
121 // Go to the startup state |
|
122 iStateMachine->ChangeState( EPhoneStateStartup ); |
|
123 |
|
124 CPhoneMediatorFactory::Instance()->CommandListener( this, iStateMachine, |
|
125 iStateMachine->PhoneEngineInfo() ); |
|
126 } |
|
127 |
|
128 // ----------------------------------------------------------------------------- |
|
129 // CPhoneUIController::NewL |
|
130 // Two-phased constructor. |
|
131 // ----------------------------------------------------------------------------- |
|
132 // |
|
133 EXPORT_C CPhoneUIController* CPhoneUIController::NewL( |
|
134 MPhoneViewCommandHandle* aViewCommandHandle ) |
|
135 { |
|
136 __ASSERT_DEBUG( aViewCommandHandle, |
|
137 Panic( EPhoneCtrlParameterNotInitialized ) ); |
|
138 |
|
139 CPhoneUIController* self = new( ELeave ) CPhoneUIController; |
|
140 |
|
141 CleanupStack::PushL( self ); |
|
142 self->ConstructL( aViewCommandHandle ); |
|
143 CleanupStack::Pop( self ); |
|
144 |
|
145 return self; |
|
146 } |
|
147 |
|
148 // ----------------------------------------------------------- |
|
149 // Destructor |
|
150 // |
|
151 // ----------------------------------------------------------- |
|
152 |
|
153 EXPORT_C CPhoneUIController::~CPhoneUIController() |
|
154 { |
|
155 __LOGMETHODSTARTEND(EPhoneControl, "CPhoneUIController::~CPhoneUIController()"); |
|
156 delete iRemoteControlHandler; |
|
157 delete iSystemEventHandler; |
|
158 delete iEngineHandler; |
|
159 delete iKeyEventForwarder; |
|
160 // delete iStateHandle; <-- CCoeStatic objects are destroyed outside application |
|
161 } |
|
162 |
|
163 // --------------------------------------------------------- |
|
164 // CPhoneUIController::HandleMessage( TInt aMessage, TInt aCallId ) |
|
165 // --------------------------------------------------------- |
|
166 // |
|
167 EXPORT_C void CPhoneUIController::HandleMessage( |
|
168 const TInt aMessage, |
|
169 const TInt aCallId ) |
|
170 { |
|
171 __PHONELOGENGINEMSG( aMessage, aCallId ); |
|
172 TRAPD( err, iEngineHandler->DoHandleMessageL( aMessage, aCallId ) ); |
|
173 |
|
174 if ( err != KErrNone ) |
|
175 { |
|
176 __PHONELOG2( |
|
177 EOnlyFatal, |
|
178 EPhoneControl, |
|
179 "PHONEUI_ERROR: CPhoneUIController::HandleMessage - Message received in unexpected state (aMessage=%d, err=%d)", |
|
180 aMessage, |
|
181 err); |
|
182 } |
|
183 |
|
184 __PHONELOGENGINEMSGEND( aMessage ); |
|
185 } |
|
186 |
|
187 // --------------------------------------------------------- |
|
188 // CPhoneUIController::HandleError( const TPEErrorInfo& aErrorInfo ) |
|
189 // --------------------------------------------------------- |
|
190 // |
|
191 EXPORT_C void CPhoneUIController::HandleError( |
|
192 const TPEErrorInfo& aErrorInfo ) |
|
193 { |
|
194 TInt err( KErrNone ); |
|
195 |
|
196 TRAP( err, iStateMachine->State()->HandleErrorL( aErrorInfo ) ); |
|
197 |
|
198 if( err != KErrNone ) |
|
199 { |
|
200 __PHONELOG1( |
|
201 EOnlyFatal, |
|
202 EPhoneControl, |
|
203 "PHONEUI_ERROR: CPhoneUIController::HandleError - leave (err=%d)", |
|
204 err); |
|
205 __ASSERT_DEBUG( EFalse, Panic( EPhoneCtrlUnknownPanic ) ); |
|
206 } |
|
207 } |
|
208 |
|
209 // --------------------------------------------------------- |
|
210 // CPhoneUIController::HandleKeyEventL |
|
211 // --------------------------------------------------------- |
|
212 // |
|
213 EXPORT_C TKeyResponse CPhoneUIController::HandleKeyEventL( |
|
214 const TKeyEvent& aKeyEvent, |
|
215 TEventCode aEventCode ) |
|
216 { |
|
217 __ASSERT_DEBUG( iKeyEventForwarder, Panic( EPhoneCtrlInvariant ) ); |
|
218 return iKeyEventForwarder->OfferKeyEventAfterControlStackL( |
|
219 aKeyEvent, |
|
220 aEventCode ); |
|
221 } |
|
222 |
|
223 // --------------------------------------------------------- |
|
224 // CPhoneUIController::DynInitMenuPaneL |
|
225 // --------------------------------------------------------- |
|
226 // |
|
227 EXPORT_C void CPhoneUIController::DynInitMenuPaneL( |
|
228 TInt aResourceId, |
|
229 CEikMenuPane* aMenuPane ) |
|
230 { |
|
231 __ASSERT_DEBUG( iSystemEventHandler, Panic( EPhoneCtrlInvariant ) ); |
|
232 iSystemEventHandler->DynInitMenuPaneL( aResourceId, aMenuPane ); |
|
233 } |
|
234 |
|
235 // --------------------------------------------------------- |
|
236 // CPhoneUIController::DynInitMenuBarL |
|
237 // --------------------------------------------------------- |
|
238 // |
|
239 EXPORT_C void CPhoneUIController::DynInitMenuBarL( |
|
240 TInt aResourceId, |
|
241 CEikMenuBar* aMenuBar ) |
|
242 { |
|
243 __ASSERT_DEBUG( iSystemEventHandler, Panic( EPhoneCtrlInvariant ) ); |
|
244 iSystemEventHandler->DynInitMenuBarL( aResourceId, aMenuBar ); |
|
245 } |
|
246 |
|
247 // --------------------------------------------------------- |
|
248 // CPhoneUIController::HandleSystemEventL |
|
249 // --------------------------------------------------------- |
|
250 // |
|
251 EXPORT_C void CPhoneUIController::HandleSystemEventL( const TWsEvent& aEvent ) |
|
252 { |
|
253 __ASSERT_DEBUG( iSystemEventHandler, Panic( EPhoneCtrlInvariant ) ); |
|
254 iSystemEventHandler->HandleSystemEventL( aEvent ); |
|
255 } |
|
256 |
|
257 // --------------------------------------------------------- |
|
258 // CPhoneUIController::HandleForegroundEventL |
|
259 // --------------------------------------------------------- |
|
260 // |
|
261 EXPORT_C void CPhoneUIController::HandleForegroundEventL( TBool aForeground ) |
|
262 { |
|
263 __ASSERT_DEBUG( iSystemEventHandler, Panic( EPhoneCtrlInvariant ) ); |
|
264 iSystemEventHandler->HandleForegroundEventL( aForeground ); |
|
265 } |
|
266 |
|
267 // --------------------------------------------------------- |
|
268 // CPhoneUIController::HandlePhoneForegroundEventL |
|
269 // --------------------------------------------------------- |
|
270 // |
|
271 EXPORT_C void CPhoneUIController::HandlePhoneForegroundEventL() |
|
272 { |
|
273 __ASSERT_DEBUG( iSystemEventHandler, Panic( EPhoneCtrlInvariant ) ); |
|
274 iSystemEventHandler->HandlePhoneForegroundEventL(); |
|
275 } |
|
276 |
|
277 // --------------------------------------------------------- |
|
278 // CPhoneUIController::HandlePhoneFocusLostEventL |
|
279 // --------------------------------------------------------- |
|
280 // |
|
281 EXPORT_C void CPhoneUIController::HandlePhoneFocusLostEventL() |
|
282 { |
|
283 __ASSERT_DEBUG( iSystemEventHandler, Panic( EPhoneCtrlInvariant ) ); |
|
284 iSystemEventHandler->HandlePhoneFocusLostEventL(); |
|
285 } |
|
286 |
|
287 // --------------------------------------------------------- |
|
288 // CPhoneUIController::HandleIdleForegroundEventL |
|
289 // --------------------------------------------------------- |
|
290 // |
|
291 EXPORT_C void CPhoneUIController::HandleIdleForegroundEventL() |
|
292 { |
|
293 __ASSERT_DEBUG( iSystemEventHandler, Panic( EPhoneCtrlInvariant ) ); |
|
294 iSystemEventHandler->HandleIdleForegroundEventL(); |
|
295 } |
|
296 |
|
297 // --------------------------------------------------------- |
|
298 // CPhoneUIController::HandleEnvironmentChangeL |
|
299 // --------------------------------------------------------- |
|
300 // |
|
301 EXPORT_C void CPhoneUIController::HandleEnvironmentChangeL( |
|
302 const TInt aChanges ) |
|
303 { |
|
304 __ASSERT_DEBUG( iSystemEventHandler, Panic( EPhoneCtrlInvariant ) ); |
|
305 iSystemEventHandler->HandleEnvironmentChangeL( aChanges ); |
|
306 } |
|
307 |
|
308 // --------------------------------------------------------- |
|
309 // CPhoneUIController::HandlePhoneStartupL |
|
310 // --------------------------------------------------------- |
|
311 // |
|
312 EXPORT_C void CPhoneUIController::HandlePhoneStartupL() |
|
313 { |
|
314 __ASSERT_DEBUG( iSystemEventHandler, Panic( EPhoneCtrlInvariant ) ); |
|
315 iSystemEventHandler->HandlePhoneStartupL(); |
|
316 } |
|
317 |
|
318 // --------------------------------------------------------- |
|
319 // CPhoneUIController::HandleCommandL |
|
320 // --------------------------------------------------------- |
|
321 // |
|
322 EXPORT_C TBool CPhoneUIController::HandleCommandL( TInt aCommand ) |
|
323 { |
|
324 __ASSERT_DEBUG( iStateMachine->State(), Panic( EPhoneCtrlInvariant ) ); |
|
325 |
|
326 // Send key up message to engine so that we wouldn't accidentally play |
|
327 // any DTMF tone. |
|
328 iStateMachine->SendPhoneEngineMessage( MPEPhoneModel::EPEMessageEndDTMF ); |
|
329 |
|
330 return iStateMachine->State()->HandleCommandL( aCommand ); |
|
331 } |
|
332 |
|
333 // --------------------------------------------------------- |
|
334 // CPhoneUIController::ProcessCommandL |
|
335 // --------------------------------------------------------- |
|
336 // |
|
337 EXPORT_C TBool CPhoneUIController::ProcessCommandL( TInt aCommand ) |
|
338 { |
|
339 __ASSERT_DEBUG( iStateMachine->State(), Panic( EPhoneCtrlInvariant ) ); |
|
340 return iStateMachine->State()->ProcessCommandL( aCommand ); |
|
341 } |
|
342 |
|
343 |
|
344 // --------------------------------------------------------- |
|
345 // CPhoneUIController::HandleKeyLockEnabled |
|
346 // --------------------------------------------------------- |
|
347 // |
|
348 EXPORT_C void CPhoneUIController::HandleKeyLockEnabled( TBool aKeylockEnabled ) |
|
349 { |
|
350 iSystemEventHandler->HandleKeyLockEnabled( aKeylockEnabled ); |
|
351 } |
|
352 |
|
353 // --------------------------------------------------------- |
|
354 // CPhoneUIController::CreateProtocolDllL |
|
355 // --------------------------------------------------------- |
|
356 // |
|
357 void CPhoneUIController::CreateProtocolDllL( |
|
358 MPhoneViewCommandHandle* aViewCommandHandle ) |
|
359 { |
|
360 TBool voipSupported( EFalse ); |
|
361 |
|
362 if( FeatureManager::FeatureSupported( KFeatureIdCommonVoip ) ) |
|
363 { |
|
364 TInt dynamicVoIP( KDynamicVoIPOff ); |
|
365 CPhoneCenRepProxy::Instance()->GetInt( |
|
366 KCRUidTelephonySettings, KDynamicVoIP, dynamicVoIP ); |
|
367 |
|
368 if( dynamicVoIP == KDynamicVoIPOn ) |
|
369 { |
|
370 voipSupported = ETrue; |
|
371 } |
|
372 } |
|
373 |
|
374 if( voipSupported ) |
|
375 { |
|
376 iStateHandle = CPhoneStateHandle::CreateL( |
|
377 aViewCommandHandle, |
|
378 KVoIPExtension, |
|
379 KUidAppVoIPExtensionStates ); |
|
380 } |
|
381 else |
|
382 { |
|
383 iStateHandle = CPhoneStateHandle::CreateL( |
|
384 aViewCommandHandle, |
|
385 KGSMProtocol, |
|
386 KUidAppGSMStates ); |
|
387 } |
|
388 } |
|
389 |
|
390 // --------------------------------------------------------- |
|
391 // CPhoneUIController::HandlePhoneNumberEditorCallBack |
|
392 // --------------------------------------------------------- |
|
393 // |
|
394 TInt CPhoneUIController::HandlePhoneNumberEditorCallBack( TAny* aAny ) |
|
395 { |
|
396 CPhoneUIController* aPhoneUiController = |
|
397 static_cast< CPhoneUIController* >( aAny ); |
|
398 |
|
399 aPhoneUiController->DoHandlePhoneNumberEditorCallBack(); |
|
400 |
|
401 return 0; |
|
402 } |
|
403 |
|
404 // --------------------------------------------------------- |
|
405 // CPhoneUIController::DoHandlePhoneNumberEditorCallBack |
|
406 // --------------------------------------------------------- |
|
407 // |
|
408 void CPhoneUIController::DoHandlePhoneNumberEditorCallBack() |
|
409 { |
|
410 iStateMachine->State()->HandleNumberEntryEdited(); |
|
411 } |
|
412 |
|
413 // End of File |