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 |
|
73 TInt leaveCode( 0 ); |
|
74 TInt retry( 0 ); |
|
75 RTimer timer; |
|
76 TRequestStatus timerReady; |
|
77 timer.CreateLocal(); |
|
78 // Phone Engine is tried to start for KPeRetryCount times |
|
79 do |
|
80 { |
|
81 // Handle the message and trap leaves from message handling functions |
|
82 TRAP( leaveCode, iPhoneEngine = iStateMachine->CreatePhoneEngineL( |
|
83 *this ) ); |
|
84 |
|
85 if ( leaveCode ) |
|
86 { |
|
87 // This thread is suspended for KPeRetryDelay |
|
88 timer.After( timerReady, KPeRetryDelay ); |
|
89 User::WaitForRequest( timerReady ); |
|
90 retry++; |
|
91 } |
|
92 }while ( leaveCode && retry < KPeRetryCount ); |
|
93 timer.Close(); |
|
94 |
|
95 if ( leaveCode ) |
|
96 { |
|
97 // If Phone Engine didn't start |
|
98 User::Leave( leaveCode ); |
|
99 } |
|
100 |
|
101 // Get the engine info |
|
102 iEngineInfo = iPhoneEngine->EngineInfo(); |
|
103 |
|
104 // Store the phone engine information in the logger |
|
105 CPhoneLogger* phoneLogger = static_cast<CPhoneLogger*> |
|
106 ( CCoeEnv::Static( KUidPhoneUILoggerSingleton ) ); |
|
107 phoneLogger->SetPhoneEngine( iPhoneEngine ); |
|
108 |
|
109 // Store the phone engine information in the state machine |
|
110 iStateMachine->SetPhoneEngine( iPhoneEngine ); |
|
111 |
|
112 // Set Number Entry observer |
|
113 TPhoneCmdParamNumberEntryObserver cmdParamNumberEntryObserver; |
|
114 cmdParamNumberEntryObserver.SetObserver( TCallBack( HandlePhoneNumberEditorCallBack, this ) ); |
|
115 aViewCommandHandle->ExecuteCommand( EPhoneViewSetNumberEntryObserver, |
|
116 &cmdParamNumberEntryObserver); |
|
117 |
|
118 // Go to the startup state |
|
119 iStateMachine->ChangeState( EPhoneStateStartup ); |
|
120 |
|
121 CPhoneMediatorFactory::Instance()->CommandListener( this, iStateMachine, |
|
122 iStateMachine->PhoneEngineInfo() ); |
|
123 } |
|
124 |
|
125 // ----------------------------------------------------------------------------- |
|
126 // CPhoneUIController::NewL |
|
127 // Two-phased constructor. |
|
128 // ----------------------------------------------------------------------------- |
|
129 // |
|
130 EXPORT_C CPhoneUIController* CPhoneUIController::NewL( |
|
131 MPhoneViewCommandHandle* aViewCommandHandle ) |
|
132 { |
|
133 __ASSERT_DEBUG( aViewCommandHandle, |
|
134 Panic( EPhoneCtrlParameterNotInitialized ) ); |
|
135 |
|
136 CPhoneUIController* self = new( ELeave ) CPhoneUIController; |
|
137 |
|
138 CleanupStack::PushL( self ); |
|
139 self->ConstructL( aViewCommandHandle ); |
|
140 CleanupStack::Pop( self ); |
|
141 |
|
142 return self; |
|
143 } |
|
144 |
|
145 // ----------------------------------------------------------- |
|
146 // Destructor |
|
147 // |
|
148 // ----------------------------------------------------------- |
|
149 |
|
150 EXPORT_C CPhoneUIController::~CPhoneUIController() |
|
151 { |
|
152 __LOGMETHODSTARTEND(EPhoneControl, "CPhoneUIController::~CPhoneUIController()"); |
|
153 delete iRemoteControlHandler; |
|
154 delete iSystemEventHandler; |
|
155 delete iEngineHandler; |
|
156 delete iKeyEventForwarder; |
|
157 delete iStateHandle; |
|
158 } |
|
159 |
|
160 // --------------------------------------------------------- |
|
161 // CPhoneUIController::HandleMessage( TInt aMessage, TInt aCallId ) |
|
162 // --------------------------------------------------------- |
|
163 // |
|
164 EXPORT_C void CPhoneUIController::HandleMessage( |
|
165 const TInt aMessage, |
|
166 const TInt aCallId ) |
|
167 { |
|
168 __PHONELOGENGINEMSG( aMessage, aCallId ); |
|
169 TRAPD( err, iEngineHandler->DoHandleMessageL( aMessage, aCallId ) ); |
|
170 |
|
171 if ( err != KErrNone ) |
|
172 { |
|
173 __PHONELOG2( |
|
174 EOnlyFatal, |
|
175 EPhoneControl, |
|
176 "PHONEUI_ERROR: CPhoneUIController::HandleMessage - Message received in unexpected state (aMessage=%d, err=%d)", |
|
177 aMessage, |
|
178 err); |
|
179 } |
|
180 |
|
181 __PHONELOGENGINEMSGEND( aMessage ); |
|
182 } |
|
183 |
|
184 // --------------------------------------------------------- |
|
185 // CPhoneUIController::HandleError( const TPEErrorInfo& aErrorInfo ) |
|
186 // --------------------------------------------------------- |
|
187 // |
|
188 EXPORT_C void CPhoneUIController::HandleError( |
|
189 const TPEErrorInfo& aErrorInfo ) |
|
190 { |
|
191 TInt err( KErrNone ); |
|
192 |
|
193 TRAP( err, iStateMachine->State()->HandleErrorL( aErrorInfo ) ); |
|
194 |
|
195 if( err != KErrNone ) |
|
196 { |
|
197 __PHONELOG1( |
|
198 EOnlyFatal, |
|
199 EPhoneControl, |
|
200 "PHONEUI_ERROR: CPhoneUIController::HandleError - leave (err=%d)", |
|
201 err); |
|
202 __ASSERT_DEBUG( EFalse, Panic( EPhoneCtrlUnknownPanic ) ); |
|
203 } |
|
204 } |
|
205 |
|
206 // --------------------------------------------------------- |
|
207 // CPhoneUIController::HandleKeyEventL |
|
208 // --------------------------------------------------------- |
|
209 // |
|
210 EXPORT_C TKeyResponse CPhoneUIController::HandleKeyEventL( |
|
211 const TKeyEvent& aKeyEvent, |
|
212 TEventCode aEventCode ) |
|
213 { |
|
214 if ( aEventCode == EEventKey ) |
|
215 { |
|
216 iStateMachine->State()->HandleKeyMessageL( |
|
217 MPhoneKeyEvents::EPhoneKeyShortPress, |
|
218 TKeyCode( aKeyEvent.iCode ) ); |
|
219 |
|
220 iStateMachine->State()->HandleDtmfKeyToneL( aKeyEvent, aEventCode ); |
|
221 } |
|
222 else if ( aEventCode == EEventLongPress ) |
|
223 { |
|
224 iStateMachine->State()->HandleKeyMessageL( |
|
225 MPhoneKeyEvents::EPhoneKeyLongPress, |
|
226 TKeyCode( aKeyEvent.iCode ) ); |
|
227 } |
|
228 else |
|
229 { |
|
230 iStateMachine->State()->HandleDtmfKeyToneL( aKeyEvent, aEventCode ); |
|
231 } |
|
232 |
|
233 |
|
234 |
|
235 return EKeyWasNotConsumed; |
|
236 } |
|
237 |
|
238 // --------------------------------------------------------- |
|
239 // CPhoneUIController::DynInitMenuPaneL |
|
240 // --------------------------------------------------------- |
|
241 // |
|
242 EXPORT_C void CPhoneUIController::DynInitMenuPaneL( |
|
243 TInt aResourceId, |
|
244 CEikMenuPane* aMenuPane ) |
|
245 { |
|
246 __ASSERT_DEBUG( iSystemEventHandler, Panic( EPhoneCtrlInvariant ) ); |
|
247 iSystemEventHandler->DynInitMenuPaneL( aResourceId, aMenuPane ); |
|
248 } |
|
249 |
|
250 // --------------------------------------------------------- |
|
251 // CPhoneUIController::DynInitMenuBarL |
|
252 // --------------------------------------------------------- |
|
253 // |
|
254 EXPORT_C void CPhoneUIController::DynInitMenuBarL( |
|
255 TInt aResourceId, |
|
256 CEikMenuBar* aMenuBar ) |
|
257 { |
|
258 __ASSERT_DEBUG( iSystemEventHandler, Panic( EPhoneCtrlInvariant ) ); |
|
259 iSystemEventHandler->DynInitMenuBarL( aResourceId, aMenuBar ); |
|
260 } |
|
261 |
|
262 // --------------------------------------------------------- |
|
263 // CPhoneUIController::HandleSystemEventL |
|
264 // --------------------------------------------------------- |
|
265 // |
|
266 EXPORT_C void CPhoneUIController::HandleSystemEventL( const TWsEvent& aEvent ) |
|
267 { |
|
268 __ASSERT_DEBUG( iSystemEventHandler, Panic( EPhoneCtrlInvariant ) ); |
|
269 iSystemEventHandler->HandleSystemEventL( aEvent ); |
|
270 } |
|
271 |
|
272 // --------------------------------------------------------- |
|
273 // CPhoneUIController::HandleForegroundEventL |
|
274 // --------------------------------------------------------- |
|
275 // |
|
276 EXPORT_C void CPhoneUIController::HandleForegroundEventL( TBool aForeground ) |
|
277 { |
|
278 __ASSERT_DEBUG( iSystemEventHandler, Panic( EPhoneCtrlInvariant ) ); |
|
279 iSystemEventHandler->HandleForegroundEventL( aForeground ); |
|
280 } |
|
281 |
|
282 // --------------------------------------------------------- |
|
283 // CPhoneUIController::HandlePhoneForegroundEventL |
|
284 // --------------------------------------------------------- |
|
285 // |
|
286 EXPORT_C void CPhoneUIController::HandlePhoneForegroundEventL() |
|
287 { |
|
288 __ASSERT_DEBUG( iSystemEventHandler, Panic( EPhoneCtrlInvariant ) ); |
|
289 iSystemEventHandler->HandlePhoneForegroundEventL(); |
|
290 } |
|
291 |
|
292 // --------------------------------------------------------- |
|
293 // CPhoneUIController::HandlePhoneFocusLostEventL |
|
294 // --------------------------------------------------------- |
|
295 // |
|
296 EXPORT_C void CPhoneUIController::HandlePhoneFocusLostEventL() |
|
297 { |
|
298 __ASSERT_DEBUG( iSystemEventHandler, Panic( EPhoneCtrlInvariant ) ); |
|
299 iSystemEventHandler->HandlePhoneFocusLostEventL(); |
|
300 } |
|
301 |
|
302 // --------------------------------------------------------- |
|
303 // CPhoneUIController::HandleIdleForegroundEventL |
|
304 // --------------------------------------------------------- |
|
305 // |
|
306 EXPORT_C void CPhoneUIController::HandleIdleForegroundEventL() |
|
307 { |
|
308 __ASSERT_DEBUG( iSystemEventHandler, Panic( EPhoneCtrlInvariant ) ); |
|
309 iSystemEventHandler->HandleIdleForegroundEventL(); |
|
310 } |
|
311 |
|
312 // --------------------------------------------------------- |
|
313 // CPhoneUIController::HandleEnvironmentChangeL |
|
314 // --------------------------------------------------------- |
|
315 // |
|
316 EXPORT_C void CPhoneUIController::HandleEnvironmentChangeL( |
|
317 const TInt aChanges ) |
|
318 { |
|
319 __ASSERT_DEBUG( iSystemEventHandler, Panic( EPhoneCtrlInvariant ) ); |
|
320 iSystemEventHandler->HandleEnvironmentChangeL( aChanges ); |
|
321 } |
|
322 |
|
323 // --------------------------------------------------------- |
|
324 // CPhoneUIController::HandlePhoneStartupL |
|
325 // --------------------------------------------------------- |
|
326 // |
|
327 EXPORT_C void CPhoneUIController::HandlePhoneStartupL() |
|
328 { |
|
329 __ASSERT_DEBUG( iSystemEventHandler, Panic( EPhoneCtrlInvariant ) ); |
|
330 iSystemEventHandler->HandlePhoneStartupL(); |
|
331 } |
|
332 |
|
333 // --------------------------------------------------------- |
|
334 // CPhoneUIController::HandleCommandL |
|
335 // --------------------------------------------------------- |
|
336 // |
|
337 EXPORT_C TBool CPhoneUIController::HandleCommandL( TInt aCommand ) |
|
338 { |
|
339 __ASSERT_DEBUG( iStateMachine->State(), Panic( EPhoneCtrlInvariant ) ); |
|
340 |
|
341 // Send key up message to engine so that we wouldn't accidentally play |
|
342 // any DTMF tone. |
|
343 iStateMachine->SendPhoneEngineMessage( MPEPhoneModel::EPEMessageEndDTMF ); |
|
344 |
|
345 return iStateMachine->State()->HandleCommandL( aCommand ); |
|
346 } |
|
347 |
|
348 // --------------------------------------------------------- |
|
349 // CPhoneUIController::ProcessCommandL |
|
350 // --------------------------------------------------------- |
|
351 // |
|
352 EXPORT_C TBool CPhoneUIController::ProcessCommandL( TInt aCommand ) |
|
353 { |
|
354 __ASSERT_DEBUG( iStateMachine->State(), Panic( EPhoneCtrlInvariant ) ); |
|
355 return iStateMachine->State()->ProcessCommandL( aCommand ); |
|
356 } |
|
357 |
|
358 |
|
359 // --------------------------------------------------------- |
|
360 // CPhoneUIController::HandleKeyLockEnabled |
|
361 // --------------------------------------------------------- |
|
362 // |
|
363 EXPORT_C void CPhoneUIController::HandleKeyLockEnabled( TBool aKeylockEnabled ) |
|
364 { |
|
365 iSystemEventHandler->HandleKeyLockEnabled( aKeylockEnabled ); |
|
366 } |
|
367 |
|
368 // --------------------------------------------------------- |
|
369 // CPhoneUIController::CreateProtocolDllL |
|
370 // --------------------------------------------------------- |
|
371 // |
|
372 void CPhoneUIController::CreateProtocolDllL( |
|
373 MPhoneViewCommandHandle* aViewCommandHandle ) |
|
374 { |
|
375 TBool voipSupported( EFalse ); |
|
376 |
|
377 if( FeatureManager::FeatureSupported( KFeatureIdCommonVoip ) ) |
|
378 { |
|
379 TInt dynamicVoIP( KDynamicVoIPOff ); |
|
380 CPhoneCenRepProxy::Instance()->GetInt( |
|
381 KCRUidTelephonySettings, KDynamicVoIP, dynamicVoIP ); |
|
382 |
|
383 if( dynamicVoIP == KDynamicVoIPOn ) |
|
384 { |
|
385 voipSupported = ETrue; |
|
386 } |
|
387 } |
|
388 |
|
389 if( voipSupported ) |
|
390 { |
|
391 iStateHandle = CPhoneStateHandle::CreateL( |
|
392 aViewCommandHandle, |
|
393 KVoIPExtension, |
|
394 KUidAppVoIPExtensionStates ); |
|
395 } |
|
396 else |
|
397 { |
|
398 iStateHandle = CPhoneStateHandle::CreateL( |
|
399 aViewCommandHandle, |
|
400 KGSMProtocol, |
|
401 KUidAppGSMStates ); |
|
402 } |
|
403 } |
|
404 |
|
405 // --------------------------------------------------------- |
|
406 // CPhoneUIController::HandlePhoneNumberEditorCallBack |
|
407 // --------------------------------------------------------- |
|
408 // |
|
409 TInt CPhoneUIController::HandlePhoneNumberEditorCallBack( TAny* aAny ) |
|
410 { |
|
411 CPhoneUIController* aPhoneUiController = |
|
412 static_cast< CPhoneUIController* >( aAny ); |
|
413 |
|
414 aPhoneUiController->DoHandlePhoneNumberEditorCallBack(); |
|
415 |
|
416 return 0; |
|
417 } |
|
418 |
|
419 // --------------------------------------------------------- |
|
420 // CPhoneUIController::DoHandlePhoneNumberEditorCallBack |
|
421 // --------------------------------------------------------- |
|
422 // |
|
423 void CPhoneUIController::DoHandlePhoneNumberEditorCallBack() |
|
424 { |
|
425 iStateMachine->State()->HandleNumberEntryEdited(); |
|
426 } |
|
427 |
|
428 // End of File |
|