|
1 /* |
|
2 * Copyright (c) 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 * Initial Contributors: |
|
9 * Nokia Corporation - initial contribution. |
|
10 * |
|
11 * Contributors: |
|
12 * |
|
13 * Description: Data class to hold view data info |
|
14 * |
|
15 */ |
|
16 |
|
17 // System includes |
|
18 #include <babitflags.h> |
|
19 |
|
20 // User includes |
|
21 #include <aifwdefs.h> |
|
22 #include <aifwpublisherinfo.h> |
|
23 #include "xnappuiadapter.h" |
|
24 #include "xncomposer.h" |
|
25 #include "xnodtparser.h" |
|
26 #include "xnviewmanager.h" |
|
27 #include "xnviewdata.h" |
|
28 #include "xnpublisherdata.h" |
|
29 #include "xncontroladapter.h" |
|
30 #include "xndomnode.h" |
|
31 #include "xnnode.h" |
|
32 #include "xnoomsyshandler.h" |
|
33 #include "ainativeuiplugins.h" |
|
34 #include "xnpanic.h" |
|
35 |
|
36 |
|
37 #include "debug.h" |
|
38 |
|
39 // Constants |
|
40 _LIT8( KNs, "namespace" ); |
|
41 |
|
42 // ============================ LOCAL FUNCTIONS ================================ |
|
43 |
|
44 // ============================ MEMBER FUNCTIONS =============================== |
|
45 // ----------------------------------------------------------------------------- |
|
46 // CXnViewData::NewL() |
|
47 // Two-phased constructor. |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 CXnViewData* CXnViewData::NewL( CXnPluginData& aParent ) |
|
51 { |
|
52 CXnViewData* self = CXnViewData::NewLC( aParent ); |
|
53 CleanupStack::Pop( self ); |
|
54 return self; |
|
55 } |
|
56 |
|
57 // ----------------------------------------------------------------------------- |
|
58 // CXnViewData::NewLC() |
|
59 // Two-phased constructor. |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 CXnViewData* CXnViewData::NewLC( CXnPluginData& aParent ) |
|
63 { |
|
64 CXnViewData* self = new ( ELeave ) CXnViewData( aParent ); |
|
65 CleanupStack::PushL( self ); |
|
66 self->ConstructL(); |
|
67 return self; |
|
68 } |
|
69 |
|
70 // ----------------------------------------------------------------------------- |
|
71 // CXnViewData::CXnViewData() |
|
72 // C++ default constructor |
|
73 // ----------------------------------------------------------------------------- |
|
74 // |
|
75 CXnViewData::CXnViewData( CXnPluginData& aParent ) |
|
76 : CXnPluginData( aParent ) |
|
77 { |
|
78 // By default view data is removable |
|
79 iFlags.Set( EIsRemovable ); |
|
80 } |
|
81 |
|
82 // ----------------------------------------------------------------------------- |
|
83 // CXnViewData::~CXnViewData() |
|
84 // C++ default destructor. |
|
85 // ----------------------------------------------------------------------------- |
|
86 // |
|
87 CXnViewData::~CXnViewData() |
|
88 { |
|
89 Destroy(); |
|
90 } |
|
91 |
|
92 // ----------------------------------------------------------------------------- |
|
93 // CXnViewData::ConstructL() |
|
94 // 2nd phase constructor |
|
95 // ----------------------------------------------------------------------------- |
|
96 // |
|
97 void CXnViewData::ConstructL() |
|
98 { |
|
99 CXnPluginData::ConstructL(); |
|
100 } |
|
101 |
|
102 // ----------------------------------------------------------------------------- |
|
103 // CXnViewData::SetActive() |
|
104 // |
|
105 // ----------------------------------------------------------------------------- |
|
106 // |
|
107 TInt CXnViewData::SetActive( TBool aActive ) |
|
108 { |
|
109 TBool active( Active() ); |
|
110 |
|
111 TInt err( KErrNone ); |
|
112 |
|
113 if ( !Occupied() ) |
|
114 { |
|
115 err = KErrGeneral; |
|
116 } |
|
117 else if ( active == aActive ) |
|
118 { |
|
119 err = KErrNone; |
|
120 } |
|
121 else |
|
122 { |
|
123 if ( aActive ) |
|
124 { |
|
125 if ( iFlags.IsSet( EIsInitial ) ) |
|
126 { |
|
127 // Load device status plugin here because it is always needed |
|
128 THsPublisherInfo devstat( KDeviceStatusPluginUid, |
|
129 KDeviceStatusPluginName, KNs ); |
|
130 |
|
131 TAiFwPublisherInfo publisher( devstat, |
|
132 TAiFwCallback(), EAiFwSystemStartup ); |
|
133 |
|
134 CXnAppUiAdapter* appui = |
|
135 static_cast< CXnAppUiAdapter* >( iAvkonAppUi ); |
|
136 |
|
137 appui->LoadPublisher( publisher ); |
|
138 } |
|
139 |
|
140 iFlags.Set( EIsActive ); |
|
141 iFlags.Clear( EIsInitial ); |
|
142 |
|
143 LoadPublishers( EAiFwPageStartup ); |
|
144 |
|
145 err = iLoadError; |
|
146 |
|
147 iLoadError = KErrNone; |
|
148 } |
|
149 else |
|
150 { |
|
151 DestroyPublishers( EAiFwPageShutdown ); |
|
152 |
|
153 iFlags.Clear( EIsActive ); |
|
154 } |
|
155 } |
|
156 |
|
157 return err; |
|
158 } |
|
159 |
|
160 // ----------------------------------------------------------------------------- |
|
161 // CXnViewData::Load() |
|
162 |
|
163 // ----------------------------------------------------------------------------- |
|
164 // |
|
165 TInt CXnViewData::Load() |
|
166 { |
|
167 TInt err( KErrNone ); |
|
168 |
|
169 if ( Occupied() ) |
|
170 { |
|
171 err = KErrInUse; |
|
172 } |
|
173 else if ( !CXnOomSysHandler::HeapAvailable( VIEW_MIN_MEM ) ) |
|
174 { |
|
175 err = KErrNoMemory; |
|
176 } |
|
177 else |
|
178 { |
|
179 TRAP( err, err = iManager.Composer().ComposeViewL( *this ) ); |
|
180 |
|
181 if ( err == KErrNone ) |
|
182 { |
|
183 TRAP( err, iManager.Parser().LoadViewL( *this ) ); |
|
184 } |
|
185 |
|
186 if ( err == KErrNone ) |
|
187 { |
|
188 // Load view's initial widgets |
|
189 for ( TInt i = 0; i < iPluginsData.Count(); i++ ) |
|
190 { |
|
191 if ( iPluginsData[i]->PluginId() != KNullDesC8 ) |
|
192 { |
|
193 TInt err2( iPluginsData[i]->Load() ); |
|
194 |
|
195 if ( err2 == KXnErrWidgetPluginFailure ) |
|
196 { |
|
197 err = err2; |
|
198 } |
|
199 else if ( err2 == KErrNoMemory ) |
|
200 { |
|
201 err = err2; |
|
202 break; |
|
203 } |
|
204 } |
|
205 } |
|
206 |
|
207 // Succesfully enough composed, publishers |
|
208 // will be loaded when view is activated |
|
209 } |
|
210 } |
|
211 |
|
212 iLoadError = err; |
|
213 |
|
214 return iLoadError; |
|
215 } |
|
216 |
|
217 // ----------------------------------------------------------------------------- |
|
218 // CXnViewData::Destroy() |
|
219 |
|
220 // ----------------------------------------------------------------------------- |
|
221 // |
|
222 void CXnViewData::Destroy() |
|
223 { |
|
224 if ( Occupied() ) |
|
225 { |
|
226 // View is deleted, pretend plugin is removed from UI |
|
227 DestroyPublishers( EAiFwPluginShutdown ); |
|
228 |
|
229 iManager.Parser().DestroyView( *this ); |
|
230 } |
|
231 |
|
232 delete iBgImage; |
|
233 iBgImage = NULL; |
|
234 |
|
235 delete iBgImagePath; |
|
236 iBgImagePath = NULL; |
|
237 |
|
238 iLoadError = KErrNone; |
|
239 |
|
240 Flush(); |
|
241 } |
|
242 |
|
243 // ----------------------------------------------------------------------------- |
|
244 // CXnViewData::Plugin() |
|
245 // Finds plugin or view data based on node |
|
246 // ----------------------------------------------------------------------------- |
|
247 // |
|
248 CXnPluginData* CXnViewData::Plugin( CXnNode* aNode ) |
|
249 { |
|
250 if ( !aNode ) |
|
251 { |
|
252 return NULL; |
|
253 } |
|
254 |
|
255 CXnDomNode* view( Node() ); |
|
256 |
|
257 if ( aNode->ViewNodeImpl() ) |
|
258 { |
|
259 // Reached view, return self |
|
260 if ( view && view->LayoutNode() == aNode ) |
|
261 { |
|
262 return this; |
|
263 } |
|
264 } |
|
265 |
|
266 for ( TInt i = 0; i < iPluginsData.Count(); i++ ) |
|
267 { |
|
268 CXnDomNode* plugin( iPluginsData[i]->Owner() ); |
|
269 |
|
270 if ( plugin && plugin->LayoutNode() == aNode ) |
|
271 { |
|
272 return iPluginsData[i]; |
|
273 } |
|
274 } |
|
275 |
|
276 // Not found, try parent |
|
277 CXnNode* parent( aNode->Parent() ); |
|
278 |
|
279 return Plugin( parent ); |
|
280 } |
|
281 |
|
282 // ----------------------------------------------------------------------------- |
|
283 // CXnViewData::Plugin() |
|
284 // Finds plugin or view data based on namespace |
|
285 // ----------------------------------------------------------------------------- |
|
286 // |
|
287 CXnPluginData* CXnViewData::Plugin( const TDesC8& aNamespace ) |
|
288 { |
|
289 if ( aNamespace == KNullDesC8 ) |
|
290 { |
|
291 // No namespace, return self for global access |
|
292 return this; |
|
293 } |
|
294 |
|
295 CXnDomNode* view( Node() ); |
|
296 |
|
297 if ( view && view->LayoutNode()->Namespace() == aNamespace ) |
|
298 { |
|
299 return this; |
|
300 } |
|
301 |
|
302 for ( TInt i = 0; i < iPluginsData.Count(); i++ ) |
|
303 { |
|
304 CXnDomNode* widget( iPluginsData[i]->Node() ); |
|
305 |
|
306 if ( widget && widget->LayoutNode()->Namespace() == aNamespace ) |
|
307 { |
|
308 return iPluginsData[i]; |
|
309 } |
|
310 } |
|
311 |
|
312 return NULL; |
|
313 } |
|
314 |
|
315 // ----------------------------------------------------------------------------- |
|
316 // CXnViewData::ViewNode() |
|
317 // Returns this view data's view node |
|
318 // ----------------------------------------------------------------------------- |
|
319 // |
|
320 CXnNode* CXnViewData::ViewNode() const |
|
321 { |
|
322 return iNode->LayoutNode(); |
|
323 } |
|
324 |
|
325 // ----------------------------------------------------------------------------- |
|
326 // CXnViewData::SetWallpaperImage |
|
327 // Store background image. Ownership is transferred. |
|
328 // ----------------------------------------------------------------------------- |
|
329 // |
|
330 void CXnViewData::SetWallpaperImage( CFbsBitmap* aBitmap ) |
|
331 { |
|
332 delete iBgImage; |
|
333 iBgImage = aBitmap; |
|
334 } |
|
335 |
|
336 // ----------------------------------------------------------------------------- |
|
337 // CXnViewData::WallpaperImage |
|
338 // Get wallpaper image. |
|
339 // ----------------------------------------------------------------------------- |
|
340 // |
|
341 CFbsBitmap* CXnViewData::WallpaperImage() const |
|
342 { |
|
343 return iBgImage; |
|
344 } |
|
345 |
|
346 // ----------------------------------------------------------------------------- |
|
347 // CXnViewData::SetWallpaperImagePathL |
|
348 // |
|
349 // ----------------------------------------------------------------------------- |
|
350 // |
|
351 void CXnViewData::SetWallpaperImagePathL( const TDesC& aFileName ) |
|
352 { |
|
353 if( !iBgImagePath || iBgImagePath->Des() != aFileName ) |
|
354 { |
|
355 delete iBgImagePath; |
|
356 iBgImagePath = NULL; |
|
357 iBgImagePath = aFileName.AllocL(); |
|
358 } |
|
359 } |
|
360 |
|
361 // ----------------------------------------------------------------------------- |
|
362 // CXnViewData::WallpaperImagePath |
|
363 // |
|
364 // ----------------------------------------------------------------------------- |
|
365 // |
|
366 const TDesC& CXnViewData::WallpaperImagePath() const |
|
367 { |
|
368 if( iBgImagePath ) |
|
369 { |
|
370 return *iBgImagePath; |
|
371 } |
|
372 return KNullDesC; |
|
373 } |
|
374 |
|
375 // ----------------------------------------------------------------------------- |
|
376 // CXnViewData::ResourcesL() |
|
377 // Gets this view data's resources |
|
378 // ----------------------------------------------------------------------------- |
|
379 // |
|
380 void CXnViewData::ResourcesL( CArrayPtrSeg< CXnResource >& aList ) const |
|
381 { |
|
382 // Get my resources |
|
383 CXnPluginData::ResourcesL( aList ); |
|
384 |
|
385 for ( TInt i = 0; i < iPluginsData.Count(); i++ ) |
|
386 { |
|
387 // And resources which my plugin holds |
|
388 iPluginsData[i]->ResourcesL( aList ); |
|
389 } |
|
390 } |
|
391 |
|
392 // ----------------------------------------------------------------------------- |
|
393 // CXnViewData::ControlsL() |
|
394 // Gets this view data's controls |
|
395 // ----------------------------------------------------------------------------- |
|
396 // |
|
397 void CXnViewData::ControlsL( RPointerArray< CXnControlAdapter >& aList ) const |
|
398 { |
|
399 // Get my controls |
|
400 CXnPluginData::ControlsL( aList ); |
|
401 |
|
402 for ( TInt i = 0; i < iPluginsData.Count(); i++ ) |
|
403 { |
|
404 // And controls which my plugin holds |
|
405 iPluginsData[i]->ControlsL( aList ); |
|
406 } |
|
407 } |
|
408 |
|
409 // ----------------------------------------------------------------------------- |
|
410 // CXnViewData::PluginNodesL() |
|
411 // Gets this view data's appearance nodes |
|
412 // ----------------------------------------------------------------------------- |
|
413 // |
|
414 void CXnViewData::AppearanceNodesL( RPointerArray< CXnNode >& aList ) const |
|
415 { |
|
416 // Get my appearance nodes |
|
417 CXnPluginData::AppearanceNodesL( aList ); |
|
418 |
|
419 for ( TInt i = 0; i < iPluginsData.Count(); i++ ) |
|
420 { |
|
421 // And appearance nodes which my plugin holds |
|
422 iPluginsData[i]->AppearanceNodesL( aList ); |
|
423 } |
|
424 } |
|
425 |
|
426 // ----------------------------------------------------------------------------- |
|
427 // CXnViewData::PopupNodesL() |
|
428 // Gets this view data's popup nodes |
|
429 // ----------------------------------------------------------------------------- |
|
430 // |
|
431 void CXnViewData::PopupNodesL( RPointerArray< CXnNode >& aList ) const |
|
432 { |
|
433 // Get my Popup nodes |
|
434 CXnPluginData::PopupNodesL( aList ); |
|
435 |
|
436 for ( TInt i = 0; i < iPluginsData.Count(); i++ ) |
|
437 { |
|
438 // And Popup nodes which my plugin holds |
|
439 iPluginsData[i]->PopupNodesL( aList ); |
|
440 } |
|
441 } |
|
442 |
|
443 // ----------------------------------------------------------------------------- |
|
444 // CXnViewData::InitialFocusNodesL() |
|
445 // Gets this view data's initial focus nodes |
|
446 // ----------------------------------------------------------------------------- |
|
447 // |
|
448 void CXnViewData::InitialFocusNodesL( RPointerArray< CXnNode >& aList ) const |
|
449 { |
|
450 // Offer widgets initial focus nodes by default first |
|
451 for ( TInt i = 0; i < iPluginsData.Count(); i++ ) |
|
452 { |
|
453 // And appearance nodes which my plugin holds |
|
454 iPluginsData[i]->InitialFocusNodesL( aList ); |
|
455 } |
|
456 |
|
457 // Get my initial focus nodes |
|
458 CXnPluginData::InitialFocusNodesL( aList ); |
|
459 } |
|
460 |
|
461 // ----------------------------------------------------------------------------- |
|
462 // CXnViewData::ContentSourceNodesL() |
|
463 // Gets this view data's content source nodes |
|
464 // ----------------------------------------------------------------------------- |
|
465 // |
|
466 void CXnViewData::ContentSourceNodesL( RPointerArray< CXnNode >& aList ) const |
|
467 { |
|
468 // Get my data publisher nodes |
|
469 CXnPluginData::ContentSourceNodesL( aList ); |
|
470 |
|
471 for ( TInt i = 0; i < iPluginsData.Count(); i++ ) |
|
472 { |
|
473 // And publisher nodes which my plugin holds |
|
474 iPluginsData[i]->ContentSourceNodesL( aList ); |
|
475 } |
|
476 } |
|
477 |
|
478 // ----------------------------------------------------------------------------- |
|
479 // CXnViewData::PluginNodesL() |
|
480 // Gets this view data's plugin nodes |
|
481 // ----------------------------------------------------------------------------- |
|
482 // |
|
483 void CXnViewData::PluginNodesL( RPointerArray< CXnNode >& aList ) const |
|
484 { |
|
485 for ( TInt i = 0; i < iPluginsData.Count(); i++ ) |
|
486 { |
|
487 // And controls which my plugin holds |
|
488 aList.AppendL( iPluginsData[i]->Owner()->LayoutNode() ); |
|
489 } |
|
490 } |
|
491 |
|
492 // ----------------------------------------------------------------------------- |
|
493 // CXnViewData::LoadPublishers |
|
494 // Loads data plugins associated to the plugin |
|
495 // ----------------------------------------------------------------------------- |
|
496 // |
|
497 void CXnViewData::LoadPublishers( TInt aReason ) |
|
498 { |
|
499 __PRINTS( "*** CXnViewData::LoadPublishers" ); |
|
500 |
|
501 if( !Active() || !Occupied() ) |
|
502 { |
|
503 __PRINTS( "*** CXnViewData::LoadPublishers - done, !Active() || !Occupied()" ); |
|
504 |
|
505 return; |
|
506 } |
|
507 |
|
508 for ( TInt i = 0; i < iPluginsData.Count(); i++ ) |
|
509 { |
|
510 CXnPluginData* plugin( iPluginsData[i] ); |
|
511 |
|
512 if ( plugin->Occupied() ) |
|
513 { |
|
514 plugin->LoadPublishers( aReason ); |
|
515 } |
|
516 } |
|
517 |
|
518 CXnPluginData::LoadPublishers( aReason ); |
|
519 |
|
520 __PRINTS( "*** CXnViewData::LoadPublishers - done" ); |
|
521 } |
|
522 |
|
523 // ----------------------------------------------------------------------------- |
|
524 // CXnViewData::NotifyPublisherReadyL |
|
525 // Notifies a publisher is ready |
|
526 // ----------------------------------------------------------------------------- |
|
527 // |
|
528 void CXnViewData::NotifyPublisherReadyL() |
|
529 { |
|
530 if ( !Active() ) |
|
531 { |
|
532 return; |
|
533 } |
|
534 |
|
535 TBool allready( ETrue ); |
|
536 |
|
537 RPointerArray< CXnPublisherData > list; |
|
538 CleanupClosePushL( list ); |
|
539 |
|
540 for ( TInt i = 0; i < iPluginsData.Count(); i++ ) |
|
541 { |
|
542 CXnPluginData* plugin( iPluginsData[i] ); |
|
543 |
|
544 if ( plugin->Occupied() ) |
|
545 { |
|
546 plugin->PublishersL( list ); |
|
547 } |
|
548 } |
|
549 |
|
550 CXnPluginData::PublishersL( list ); |
|
551 |
|
552 for ( TInt i = 0; i < list.Count(); i++ ) |
|
553 { |
|
554 CXnPublisherData* publisher( list[i] ); |
|
555 |
|
556 if ( publisher->IsLoading() ) |
|
557 { |
|
558 allready = EFalse; |
|
559 break; |
|
560 } |
|
561 } |
|
562 |
|
563 if ( allready && Active() ) |
|
564 { |
|
565 TInt result( KErrNone ); |
|
566 |
|
567 for ( TInt i = 0; i < list.Count(); i++ ) |
|
568 { |
|
569 CXnPublisherData* publisher( list[i] ); |
|
570 |
|
571 if ( publisher->IsFailed() ) |
|
572 { |
|
573 CXnPluginData* plugin( publisher->Owner() ); |
|
574 |
|
575 if ( plugin != this && plugin->Removable() ) |
|
576 { |
|
577 iManager.UnloadWidgetFromPluginL( *plugin, ETrue ); |
|
578 |
|
579 result = KXnErrWidgetPluginFailure; |
|
580 } |
|
581 } |
|
582 } |
|
583 |
|
584 TRAP_IGNORE( iManager.PublishersReadyL( *this, result ) ); |
|
585 } |
|
586 |
|
587 CleanupStack::PopAndDestroy( &list ); |
|
588 } |
|
589 |
|
590 // ----------------------------------------------------------------------------- |
|
591 // CXnViewData::DestroyPublishers |
|
592 // Destroys data plugins associated to the plugin |
|
593 // ----------------------------------------------------------------------------- |
|
594 // |
|
595 void CXnViewData::DestroyPublishers( TInt aReason ) |
|
596 { |
|
597 __PRINTS( "*** CXnViewData::DestroyPublishers" ); |
|
598 |
|
599 if ( !Occupied() ) |
|
600 { |
|
601 __PRINTS( "*** CXnViewData::DestroyPublishers - done, !Occupied()" ); |
|
602 |
|
603 return; |
|
604 } |
|
605 |
|
606 for ( TInt i = 0; i < iPluginsData.Count(); i++ ) |
|
607 { |
|
608 CXnPluginData* plugin( iPluginsData[i] ); |
|
609 |
|
610 if ( plugin->Occupied() ) |
|
611 { |
|
612 plugin->DestroyPublishers( aReason ); |
|
613 } |
|
614 } |
|
615 |
|
616 CXnPluginData::DestroyPublishers( aReason ); |
|
617 |
|
618 __PRINTS( "*** CXnViewData::DestroyPublishers - done" ); |
|
619 } |
|
620 |
|
621 // End of file |