|
1 /* |
|
2 * Copyright (c) 2005-2008 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: UI controller manager class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "aiuicontrollermanager.h" |
|
20 #include "aiuicontroller.h" |
|
21 #include "aicontentpublisher.h" |
|
22 #include "aicontentobserver.h" |
|
23 #include "activeidle2domaincrkeys.h" |
|
24 #include "aifwpanic.h" |
|
25 #include <ecom/ecom.h> |
|
26 #include <ecom/implementationinformation.h> |
|
27 #include <centralrepository.h> |
|
28 |
|
29 #include <aisystemuids.hrh> |
|
30 |
|
31 #include "debug.h" |
|
32 |
|
33 // ======== MEMBER FUNCTIONS ======== |
|
34 |
|
35 // ---------------------------------------------------------------------------- |
|
36 // CAiUiControllerManager::CAiUiControllerManager() |
|
37 // ---------------------------------------------------------------------------- |
|
38 // |
|
39 CAiUiControllerManager::CAiUiControllerManager() |
|
40 { |
|
41 } |
|
42 |
|
43 // ---------------------------------------------------------------------------- |
|
44 // CAiUiControllerManager::LoadMainControllerL() |
|
45 // ---------------------------------------------------------------------------- |
|
46 // |
|
47 void CAiUiControllerManager::LoadMainControllerL( |
|
48 CRepository& aCenRepConfig ) |
|
49 { |
|
50 TInt value( 0 ); |
|
51 |
|
52 // Main UI Controller must be configured correctly |
|
53 User::LeaveIfError( aCenRepConfig.Get( KAiMainUIController, value ) ); |
|
54 |
|
55 CAiUiController* controller = CAiUiController::NewL( TUid::Uid( value ) ); |
|
56 |
|
57 iCreatedUICList.Append( value ); |
|
58 CleanupStack::PushL( controller ); |
|
59 |
|
60 iMainUiController = controller->MainInterface(); |
|
61 |
|
62 // Main UI controller must be configured correctly |
|
63 if( !iMainUiController ) |
|
64 { |
|
65 __PRINT( __DBG_FORMAT("Main UI controller interface not found from controller 0x%x"), value ); |
|
66 User::Leave( KErrNotFound ); |
|
67 } |
|
68 |
|
69 iUiControllerArray.AppendL( controller ); |
|
70 CleanupStack::Pop( controller ); |
|
71 |
|
72 // Register this as a UI framework observer of the main UI controller |
|
73 iMainUiController->SetUiFrameworkObserver( *this ); |
|
74 } |
|
75 |
|
76 // ---------------------------------------------------------------------------- |
|
77 // CAiUiControllerManager::LoadSecondaryControllersL() |
|
78 // ---------------------------------------------------------------------------- |
|
79 // |
|
80 void CAiUiControllerManager::LoadSecondaryControllersL( |
|
81 CRepository& aCenRepConfig ) |
|
82 { |
|
83 TInt value( 0 ); |
|
84 |
|
85 // Instantiate rest of the UI controllers. |
|
86 for( TInt key = KAiFirstUIController; |
|
87 key <= KAiLastUIController && aCenRepConfig.Get( key, value ) == KErrNone; |
|
88 ++key ) |
|
89 { |
|
90 // skip empty entries |
|
91 if( value == 0 ) |
|
92 { |
|
93 continue; |
|
94 } |
|
95 |
|
96 if( iCreatedUICList.Find( value ) != KErrNotFound ) |
|
97 { |
|
98 continue; |
|
99 } |
|
100 |
|
101 iCreatedUICList.Append( value ); |
|
102 |
|
103 CAiUiController* controller = |
|
104 CAiUiController::NewL( TUid::Uid( value ) ); |
|
105 |
|
106 CleanupStack::PushL( controller ); |
|
107 |
|
108 iUiControllerArray.AppendL( controller ); |
|
109 CleanupStack::Pop( controller ); |
|
110 |
|
111 // Get the secondary interface |
|
112 MAiSecondaryUiController* secController( |
|
113 controller->SecondaryInterface() ); |
|
114 |
|
115 if( secController ) |
|
116 { |
|
117 MAiUiFrameworkObserver* uiFwObserver( |
|
118 secController->UiFrameworkObserver() ); |
|
119 |
|
120 if( uiFwObserver ) |
|
121 { |
|
122 // Add secondary controller as UI framework event observer. |
|
123 User::LeaveIfError( |
|
124 iUiFrameworkObservers.InsertInAddressOrder( uiFwObserver ) ); |
|
125 } |
|
126 } |
|
127 } |
|
128 } |
|
129 |
|
130 // ---------------------------------------------------------------------------- |
|
131 // CAiUiControllerManager::ConstructL() |
|
132 // ---------------------------------------------------------------------------- |
|
133 // |
|
134 void CAiUiControllerManager::ConstructL() |
|
135 { |
|
136 __HEAP("FW: Init - Create UI Ctrls"); |
|
137 __TIME_MARK(t); |
|
138 |
|
139 CRepository* cenRep( NULL ); |
|
140 |
|
141 #if 0 |
|
142 // For AI3_test |
|
143 RProcess proc; |
|
144 // 0x102750F0 in AI3, 0x2001CB4F in AI3_Test |
|
145 TSecureId secId( proc.SecureId() ); |
|
146 |
|
147 if( secId == 0x2001CB4F ) |
|
148 { |
|
149 cenRep = CRepository::NewL( TUid::Uid( 0x2001952B ) ); |
|
150 } |
|
151 else |
|
152 { |
|
153 cenRep = CRepository::NewL( TUid::Uid( KCRUidActiveIdleLV ) ); |
|
154 } |
|
155 #else |
|
156 cenRep = CRepository::NewLC( TUid::Uid( KCRUidActiveIdleLV ) ); |
|
157 #endif |
|
158 |
|
159 LoadMainControllerL( *cenRep ); |
|
160 |
|
161 // Failing on secondary is not fatal. Ignore leaves. |
|
162 TRAP_IGNORE( LoadSecondaryControllersL( *cenRep ) ); |
|
163 |
|
164 CleanupStack::PopAndDestroy( cenRep ); |
|
165 |
|
166 __TIME_ENDMARK("FW: Create UI Ctrls", t); |
|
167 __HEAP("FW: Done - Create UI Ctrls"); |
|
168 } |
|
169 |
|
170 // ---------------------------------------------------------------------------- |
|
171 // CAiUiControllerManager::NewL() |
|
172 // ---------------------------------------------------------------------------- |
|
173 // |
|
174 CAiUiControllerManager* CAiUiControllerManager::NewL() |
|
175 { |
|
176 CAiUiControllerManager* self = new (ELeave) CAiUiControllerManager; |
|
177 |
|
178 CleanupStack::PushL( self ); |
|
179 self->ConstructL(); |
|
180 CleanupStack::Pop( self ); // self |
|
181 |
|
182 return self; |
|
183 } |
|
184 |
|
185 // ---------------------------------------------------------------------------- |
|
186 // CAiUiControllerManager::~CAiUiControllerManager() |
|
187 // ---------------------------------------------------------------------------- |
|
188 // |
|
189 CAiUiControllerManager::~CAiUiControllerManager() |
|
190 { |
|
191 iUiControllerArray.ResetAndDestroy(); |
|
192 |
|
193 iUiFrameworkObservers.Reset(); |
|
194 |
|
195 iCreatedUICList.Reset(); |
|
196 } |
|
197 |
|
198 // ---------------------------------------------------------------------------- |
|
199 // CAiUiControllerManager::UiControllers() |
|
200 // ---------------------------------------------------------------------------- |
|
201 // |
|
202 RPointerArray< CAiUiController >& CAiUiControllerManager::UiControllers() const |
|
203 { |
|
204 return iUiControllerArray; |
|
205 } |
|
206 |
|
207 // ---------------------------------------------------------------------------- |
|
208 // CAiUiControllerManager::IsMainUiController() |
|
209 // ---------------------------------------------------------------------------- |
|
210 // |
|
211 TBool CAiUiControllerManager::IsMainUiController( |
|
212 CAiUiController& aUiController ) const |
|
213 { |
|
214 return ( aUiController.MainInterface() == iMainUiController ); |
|
215 } |
|
216 |
|
217 // ---------------------------------------------------------------------------- |
|
218 // CAiUiControllerManager::SetEventHandler() |
|
219 // ---------------------------------------------------------------------------- |
|
220 // |
|
221 void CAiUiControllerManager::SetEventHandler( |
|
222 MAiFwEventHandler& aEventHandler ) |
|
223 { |
|
224 for ( TInt i = 0; i < iUiControllerArray.Count(); i++ ) |
|
225 { |
|
226 iUiControllerArray[i]->SetEventHandler( aEventHandler ); |
|
227 } |
|
228 } |
|
229 |
|
230 // ---------------------------------------------------------------------------- |
|
231 // CAiUiControllerManager::RunApplicationL() |
|
232 // ---------------------------------------------------------------------------- |
|
233 // |
|
234 void CAiUiControllerManager::RunApplicationL() |
|
235 { |
|
236 iMainUiController->RunApplicationL(); |
|
237 } |
|
238 |
|
239 // ---------------------------------------------------------------------------- |
|
240 // CAiUiControllerManager::ActivateUI() |
|
241 // ---------------------------------------------------------------------------- |
|
242 // |
|
243 void CAiUiControllerManager::ActivateUI() |
|
244 { |
|
245 for( TInt i = 0; i < iUiControllerArray.Count(); i++ ) |
|
246 { |
|
247 iUiControllerArray[i]->ActivateUI(); |
|
248 } |
|
249 } |
|
250 |
|
251 // ---------------------------------------------------------------------------- |
|
252 // CAiUiControllerManager::LoadUIDefinition() |
|
253 // ---------------------------------------------------------------------------- |
|
254 // |
|
255 void CAiUiControllerManager::LoadUIDefinition() |
|
256 { |
|
257 for( TInt i = 0; i < iUiControllerArray.Count(); i++ ) |
|
258 { |
|
259 CAiUiController* uiCtl( iUiControllerArray[i] ); |
|
260 |
|
261 MAiSecondaryUiController* secIntr( uiCtl->SecondaryInterface() ); |
|
262 |
|
263 if( secIntr ) |
|
264 { |
|
265 secIntr->SetCoeEnv( CoeEnv() ); |
|
266 } |
|
267 |
|
268 TRAPD( err, uiCtl->LoadUIDefinitionL() ); |
|
269 |
|
270 if( err != KErrNone ) |
|
271 { |
|
272 if( IsMainUiController( *uiCtl ) ) |
|
273 { |
|
274 // Main ui controller failing is fatal |
|
275 _LIT(KAIFWStartupFailed, "FW startup failed."); |
|
276 |
|
277 User::Panic( KAIFWStartupFailed, 0 ); |
|
278 } |
|
279 else |
|
280 { |
|
281 // Secondary UI controller failed, delete it |
|
282 delete uiCtl; |
|
283 uiCtl = NULL; |
|
284 |
|
285 iUiControllerArray.Remove( i ); |
|
286 } |
|
287 } |
|
288 } |
|
289 } |
|
290 |
|
291 // ---------------------------------------------------------------------------- |
|
292 // CAiUiControllerManager::CoeEnv() |
|
293 // ---------------------------------------------------------------------------- |
|
294 // |
|
295 CCoeEnv& CAiUiControllerManager::CoeEnv() const |
|
296 { |
|
297 return iMainUiController->CoeEnv(); |
|
298 } |
|
299 |
|
300 // ---------------------------------------------------------------------------- |
|
301 // CAiUiControllerManager::MainUiController() |
|
302 // ---------------------------------------------------------------------------- |
|
303 // |
|
304 MAiMainUiController& CAiUiControllerManager::MainUiController() const |
|
305 { |
|
306 return *iMainUiController; |
|
307 } |
|
308 |
|
309 // ---------------------------------------------------------------------------- |
|
310 // CAiUiControllerManager::DestroySecondaryUiControllers() |
|
311 // ---------------------------------------------------------------------------- |
|
312 // |
|
313 void CAiUiControllerManager::DestroySecondaryUiControllers() |
|
314 { |
|
315 for( TInt i = iUiControllerArray.Count() - 1; i >= 0; --i ) |
|
316 { |
|
317 CAiUiController* uiController = iUiControllerArray[i]; |
|
318 |
|
319 if( !IsMainUiController( *uiController ) ) |
|
320 { |
|
321 delete uiController; |
|
322 uiController = NULL; |
|
323 |
|
324 iUiControllerArray.Remove(i); |
|
325 } |
|
326 } |
|
327 } |
|
328 |
|
329 // ---------------------------------------------------------------------------- |
|
330 // CAiUiControllerManager::ExitMainController() |
|
331 // ---------------------------------------------------------------------------- |
|
332 // |
|
333 void CAiUiControllerManager::ExitMainController() |
|
334 { |
|
335 iMainUiController->Exit(); |
|
336 } |
|
337 |
|
338 // ---------------------------------------------------------------------------- |
|
339 // CAiUiControllerManager::AddObserverL() |
|
340 // ---------------------------------------------------------------------------- |
|
341 // |
|
342 void CAiUiControllerManager::AddObserverL( |
|
343 MAiUiFrameworkObserver& aUiFwObserver ) |
|
344 { |
|
345 User::LeaveIfError( |
|
346 iUiFrameworkObservers.InsertInAddressOrder( &aUiFwObserver ) ); |
|
347 } |
|
348 |
|
349 // ---------------------------------------------------------------------------- |
|
350 // CAiUiControllerManager::RemoveObserver() |
|
351 // ---------------------------------------------------------------------------- |
|
352 // |
|
353 void CAiUiControllerManager::RemoveObserver( |
|
354 MAiUiFrameworkObserver& aUiFwObserver ) |
|
355 { |
|
356 TInt index( iUiFrameworkObservers.FindInAddressOrder( &aUiFwObserver ) ); |
|
357 |
|
358 if( index != KErrNotFound ) |
|
359 { |
|
360 iUiFrameworkObservers.Remove( index ); |
|
361 } |
|
362 } |
|
363 |
|
364 // ---------------------------------------------------------------------------- |
|
365 // CAiUiControllerManager::RemovePluginFromUI() |
|
366 // ---------------------------------------------------------------------------- |
|
367 // |
|
368 void CAiUiControllerManager::RemovePluginFromUI( CAiContentPublisher& aPlugin ) |
|
369 { |
|
370 // Get MAiPropertyExtension from plugin |
|
371 MAiPropertyExtension* plugin = |
|
372 static_cast< MAiPropertyExtension* >( |
|
373 aPlugin.Extension( KExtensionUidProperty ) ); |
|
374 |
|
375 // Inform all UI controller that this plugin need to be removed from UI. |
|
376 if( plugin ) |
|
377 { |
|
378 for ( TInt i = 0; i < iUiControllerArray.Count(); i++ ) |
|
379 { |
|
380 iUiControllerArray[i]->RemovePluginFromUI( *plugin ); |
|
381 } |
|
382 } |
|
383 } |
|
384 |
|
385 // ---------------------------------------------------------------------------- |
|
386 // CAiUiControllerManager::HandleResourceChange() |
|
387 // ---------------------------------------------------------------------------- |
|
388 // |
|
389 void CAiUiControllerManager::HandleResourceChange( TInt aType ) |
|
390 { |
|
391 for( TInt i = 0; i < iUiFrameworkObservers.Count(); i++ ) |
|
392 { |
|
393 iUiFrameworkObservers[i]->HandleResourceChange( aType ); |
|
394 } |
|
395 } |
|
396 |
|
397 // ---------------------------------------------------------------------------- |
|
398 // CAiUiControllerManager::HandleForegroundEvent() |
|
399 // ---------------------------------------------------------------------------- |
|
400 // |
|
401 void CAiUiControllerManager::HandleForegroundEvent( TBool aForeground ) |
|
402 { |
|
403 for( TInt i = 0; i < iUiFrameworkObservers.Count(); i++ ) |
|
404 { |
|
405 iUiFrameworkObservers[i]->HandleForegroundEvent( aForeground ); |
|
406 } |
|
407 } |
|
408 |
|
409 // End of file |