|
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 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Data class to hold widget info |
|
15 * |
|
16 */ |
|
17 |
|
18 // System includes |
|
19 #include <utf.h> |
|
20 |
|
21 // User includes |
|
22 #include <aifwdefs.h> |
|
23 #include "xnappuiadapter.h" |
|
24 #include "xncomposer.h" |
|
25 #include "xnodtparser.h" |
|
26 #include "xnresource.h" |
|
27 #include "xnodt.h" |
|
28 #include "xnnode.h" |
|
29 #include "xnplugindata.h" |
|
30 #include "xnviewdata.h" |
|
31 #include "xnpublisherdata.h" |
|
32 #include "xnviewmanager.h" |
|
33 #include "xnoomsyshandler.h" |
|
34 #include "xnpanic.h" |
|
35 |
|
36 #include "debug.h" |
|
37 |
|
38 // Constants |
|
39 _LIT8( KLockingStatusLocked, "locked" ); |
|
40 |
|
41 // ============================ LOCAL FUNCTIONS ================================ |
|
42 |
|
43 // ============================ MEMBER FUNCTIONS =============================== |
|
44 // ----------------------------------------------------------------------------- |
|
45 // CXnPluginData::NewL() |
|
46 // Two-phased constructor. |
|
47 // ----------------------------------------------------------------------------- |
|
48 // |
|
49 CXnPluginData* CXnPluginData::NewL( CXnPluginData& aParent ) |
|
50 { |
|
51 CXnPluginData* self = CXnPluginData::NewLC( aParent ); |
|
52 CleanupStack::Pop( self ); |
|
53 return self; |
|
54 } |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // CXnPluginData::NewLC() |
|
58 // Two-phased constructor. |
|
59 // ----------------------------------------------------------------------------- |
|
60 // |
|
61 CXnPluginData* CXnPluginData::NewLC( CXnPluginData& aParent ) |
|
62 { |
|
63 CXnPluginData* self = new ( ELeave ) CXnPluginData( aParent ); |
|
64 CleanupStack::PushL( self ); |
|
65 self->ConstructL(); |
|
66 return self; |
|
67 } |
|
68 |
|
69 // ----------------------------------------------------------------------------- |
|
70 // CXnPluginData::CXnPluginData() |
|
71 // C++ constructor |
|
72 // ----------------------------------------------------------------------------- |
|
73 // |
|
74 CXnPluginData::CXnPluginData( CXnPluginData& aParent ) |
|
75 : iParent( &aParent ), iManager( iParent->ViewManager() ) |
|
76 { |
|
77 // Plugin data is removable by default |
|
78 iFlags.Set( EIsRemovable ); |
|
79 } |
|
80 |
|
81 // ----------------------------------------------------------------------------- |
|
82 // CXnPluginData::CXnPluginData() |
|
83 // C++ constructor |
|
84 // ----------------------------------------------------------------------------- |
|
85 // |
|
86 CXnPluginData::CXnPluginData( CXnViewManager& aManager ) |
|
87 : iParent( NULL ), iManager( aManager ) |
|
88 { |
|
89 // This constructor overload is used by CXnRootData |
|
90 } |
|
91 |
|
92 // ----------------------------------------------------------------------------- |
|
93 // CXnPluginData::~CXnPluginData() |
|
94 // C++ default destructor. |
|
95 // ----------------------------------------------------------------------------- |
|
96 // |
|
97 CXnPluginData::~CXnPluginData() |
|
98 { |
|
99 Flush(); |
|
100 } |
|
101 |
|
102 // ----------------------------------------------------------------------------- |
|
103 // CXnPluginData::ConstructL() |
|
104 // 2nd phase constructor |
|
105 // ----------------------------------------------------------------------------- |
|
106 // |
|
107 void CXnPluginData::ConstructL() |
|
108 { |
|
109 } |
|
110 |
|
111 // ----------------------------------------------------------------------------- |
|
112 // CXnPluginData::Load() |
|
113 // |
|
114 // ----------------------------------------------------------------------------- |
|
115 // |
|
116 TInt CXnPluginData::Load() |
|
117 { |
|
118 if ( Occupied() ) |
|
119 { |
|
120 return KErrInUse; |
|
121 } |
|
122 |
|
123 if ( !CXnOomSysHandler::HeapAvailable( WIDGET_MIN_MEM ) ) |
|
124 { |
|
125 return KErrNoMemory; |
|
126 } |
|
127 |
|
128 iFlags.Clear( EIsEmpty ); |
|
129 |
|
130 TInt err( KErrNone ); |
|
131 |
|
132 TRAP( err, err = iManager.Composer().ComposeWidgetL( *this ) ); |
|
133 |
|
134 if ( err == KErrNone ) |
|
135 { |
|
136 TRAP( err, iManager.Parser().LoadWidgetL( *this ) ); |
|
137 } |
|
138 |
|
139 if ( err == KErrNone ) |
|
140 { |
|
141 // Succesfully composed, try schedule publishers' loading |
|
142 LoadPublishers( EAiFwPluginStartup ); |
|
143 } |
|
144 else if ( err == KXnErrWidgetPluginFailure ) |
|
145 { |
|
146 // Widget's configuration is broken, remove it |
|
147 TRAP_IGNORE( iManager.UnloadWidgetFromPluginL( *this, ETrue ) ); |
|
148 } |
|
149 |
|
150 return err; |
|
151 } |
|
152 |
|
153 // ----------------------------------------------------------------------------- |
|
154 // CXnPluginData::Destroy() |
|
155 // |
|
156 // ----------------------------------------------------------------------------- |
|
157 // |
|
158 void CXnPluginData::Destroy() |
|
159 { |
|
160 if ( Occupied() ) |
|
161 { |
|
162 DestroyPublishers( EAiFwPluginShutdown ); |
|
163 |
|
164 TRAP_IGNORE( iManager.Parser().DestroyWidgetL( *this ) ); |
|
165 } |
|
166 |
|
167 Flush(); |
|
168 } |
|
169 |
|
170 // ----------------------------------------------------------------------------- |
|
171 // CXnPluginData::LoadPublishers() |
|
172 // |
|
173 // ----------------------------------------------------------------------------- |
|
174 // |
|
175 void CXnPluginData::LoadPublishers( TInt aReason ) |
|
176 { |
|
177 __PRINTS( "*** CXnPluginData::LoadPublishers" ); |
|
178 |
|
179 if ( !Active() || !Occupied() ) |
|
180 { |
|
181 __PRINTS( "*** CXnPluginData::LoadPublishers - done, !Active() || !Occupied()" ); |
|
182 |
|
183 return; |
|
184 } |
|
185 |
|
186 TInt count( iPublishers.Count() ); |
|
187 |
|
188 if ( count == 0 ) |
|
189 { |
|
190 TRAP_IGNORE( NotifyPublisherReadyL() ); |
|
191 } |
|
192 else |
|
193 { |
|
194 for ( TInt i = 0; i < count; i++ ) |
|
195 { |
|
196 iPublishers[i]->Load( aReason ); |
|
197 } |
|
198 } |
|
199 |
|
200 __PRINTS( "*** CXnPluginData::LoadPublishers - done" ); |
|
201 } |
|
202 |
|
203 // ----------------------------------------------------------------------------- |
|
204 // CXnPluginData::NotifyPublisherReadyL() |
|
205 // |
|
206 // ----------------------------------------------------------------------------- |
|
207 // |
|
208 void CXnPluginData::NotifyPublisherReadyL() |
|
209 { |
|
210 if ( iParent ) |
|
211 { |
|
212 // Forward to parent |
|
213 iParent->NotifyPublisherReadyL(); |
|
214 } |
|
215 } |
|
216 |
|
217 // ----------------------------------------------------------------------------- |
|
218 // CXnPluginData::DestroyPublishers |
|
219 // |
|
220 // ----------------------------------------------------------------------------- |
|
221 // |
|
222 void CXnPluginData::DestroyPublishers( TInt aReason ) |
|
223 { |
|
224 __PRINTS( "*** CXnPluginData::DestroyPublishers" ); |
|
225 |
|
226 if ( !Occupied() ) |
|
227 { |
|
228 __PRINTS( "*** CXnPluginData::DestroyPublishers - done, !Occupied()" ); |
|
229 |
|
230 return; |
|
231 } |
|
232 |
|
233 for ( TInt i = 0; i < iPublishers.Count(); i++ ) |
|
234 { |
|
235 iPublishers[i]->Destroy( aReason ); |
|
236 } |
|
237 |
|
238 __PRINTS( "*** CXnPluginData::DestroyPublishers - done" ); |
|
239 } |
|
240 |
|
241 // ----------------------------------------------------------------------------- |
|
242 // CXnPluginData::SetConfigurationIdL() |
|
243 // |
|
244 // ----------------------------------------------------------------------------- |
|
245 // |
|
246 void CXnPluginData::SetConfigurationIdL( const TDesC8& aConfigurationId ) |
|
247 { |
|
248 delete iConfigurationId; |
|
249 iConfigurationId = NULL; |
|
250 |
|
251 iConfigurationId = aConfigurationId.AllocL(); |
|
252 } |
|
253 |
|
254 // ----------------------------------------------------------------------------- |
|
255 // CXnPluginData::SetPluginIdL() |
|
256 // |
|
257 // ----------------------------------------------------------------------------- |
|
258 // |
|
259 void CXnPluginData::SetPluginIdL( const TDesC8& aPluginId ) |
|
260 { |
|
261 delete iPluginId; |
|
262 iPluginId = NULL; |
|
263 |
|
264 iPluginId = aPluginId.AllocL(); |
|
265 } |
|
266 |
|
267 // ----------------------------------------------------------------------------- |
|
268 // CXnPluginData::SetPluginUidL() |
|
269 // |
|
270 // ----------------------------------------------------------------------------- |
|
271 // |
|
272 void CXnPluginData::SetPluginUidL( const TDesC8& aPluginUid ) |
|
273 { |
|
274 delete iPluginUid; |
|
275 iPluginUid = NULL; |
|
276 |
|
277 iPluginUid = aPluginUid.AllocL(); |
|
278 } |
|
279 |
|
280 // ----------------------------------------------------------------------------- |
|
281 // CXnPluginData::SetPluginNameL() |
|
282 // |
|
283 // ----------------------------------------------------------------------------- |
|
284 // |
|
285 void CXnPluginData::SetPluginNameL( const TDesC8& aPluginName ) |
|
286 { |
|
287 delete iPluginName; |
|
288 iPluginName = NULL; |
|
289 |
|
290 iPluginName = aPluginName.AllocL(); |
|
291 } |
|
292 |
|
293 // ----------------------------------------------------------------------------- |
|
294 // CXnPluginData::SetPublisherName () |
|
295 // Set the publisher name |
|
296 // ----------------------------------------------------------------------------- |
|
297 // |
|
298 void CXnPluginData::SetPublisherNameL( const TDesC8& aPublisherName ) |
|
299 { |
|
300 delete iPublisherName; |
|
301 iPublisherName = NULL; |
|
302 |
|
303 iPublisherName = |
|
304 CnvUtfConverter::ConvertToUnicodeFromUtf8L( aPublisherName ); |
|
305 } |
|
306 |
|
307 // ----------------------------------------------------------------------------- |
|
308 // CXnPluginData::SetPublisherName() |
|
309 // Set the publisher name |
|
310 // ----------------------------------------------------------------------------- |
|
311 // |
|
312 void CXnPluginData::SetPublisherNameL( const TDesC& aPublisherName ) |
|
313 { |
|
314 delete iPublisherName; |
|
315 iPublisherName = NULL; |
|
316 |
|
317 iPublisherName = aPublisherName.AllocL(); |
|
318 } |
|
319 |
|
320 // ----------------------------------------------------------------------------- |
|
321 // CXnPluginData::SetPluginTypeL() |
|
322 // |
|
323 // ----------------------------------------------------------------------------- |
|
324 // |
|
325 void CXnPluginData::SetPluginTypeL( const TDesC8& aPluginType ) |
|
326 { |
|
327 delete iPluginType; |
|
328 iPluginType = NULL; |
|
329 |
|
330 iPluginType = aPluginType.AllocL(); |
|
331 } |
|
332 |
|
333 // ----------------------------------------------------------------------------- |
|
334 // CXnPluginData::SetResources() |
|
335 // |
|
336 // ----------------------------------------------------------------------------- |
|
337 // |
|
338 void CXnPluginData::SetResources( CArrayPtrSeg< CXnResource >* aResources ) |
|
339 { |
|
340 if ( iResources ) |
|
341 { |
|
342 iResources->ResetAndDestroy(); |
|
343 |
|
344 delete iResources; |
|
345 iResources = NULL; |
|
346 } |
|
347 |
|
348 iResources = aResources; |
|
349 } |
|
350 |
|
351 // ----------------------------------------------------------------------------- |
|
352 // CXnPluginData::ResourcesL() |
|
353 // |
|
354 // ----------------------------------------------------------------------------- |
|
355 // |
|
356 void CXnPluginData::ResourcesL( CArrayPtrSeg< CXnResource >& aList ) const |
|
357 { |
|
358 for ( TInt i = 0; iResources && i < iResources->Count(); i++ ) |
|
359 { |
|
360 aList.AppendL( iResources->At(i) ); |
|
361 } |
|
362 } |
|
363 |
|
364 // ----------------------------------------------------------------------------- |
|
365 // CXnPluginData::SetControlL() |
|
366 // |
|
367 // ----------------------------------------------------------------------------- |
|
368 // |
|
369 void CXnPluginData::SetControlL( CXnNode* aNode ) |
|
370 { |
|
371 CXnControlAdapter* control( aNode->Control() ); |
|
372 |
|
373 if ( control ) |
|
374 { |
|
375 User::LeaveIfError( iControls.InsertInAddressOrder( control ) ); |
|
376 } |
|
377 } |
|
378 |
|
379 // ----------------------------------------------------------------------------- |
|
380 // CXnPluginData::ControlsL() |
|
381 // |
|
382 // ----------------------------------------------------------------------------- |
|
383 // |
|
384 void CXnPluginData::ControlsL( RPointerArray< CXnControlAdapter >& aList ) const |
|
385 { |
|
386 for ( TInt i = 0; i < iControls.Count(); i++ ) |
|
387 { |
|
388 aList.AppendL( iControls[i] ); |
|
389 } |
|
390 } |
|
391 |
|
392 // ----------------------------------------------------------------------------- |
|
393 // CXnPluginData::SetContentSourceNodeL() |
|
394 // |
|
395 // ----------------------------------------------------------------------------- |
|
396 // |
|
397 void CXnPluginData::SetContentSourceNodeL( CXnNode* aNode ) |
|
398 { |
|
399 if ( !aNode ) |
|
400 { |
|
401 return; |
|
402 } |
|
403 |
|
404 for ( TInt i = 0; i < iPublishers.Count(); i++ ) |
|
405 { |
|
406 if ( *iPublishers[i] == *aNode ) |
|
407 { |
|
408 // Duplicate entries not allowed |
|
409 return; |
|
410 } |
|
411 } |
|
412 |
|
413 CXnPublisherData* publisher = |
|
414 CXnPublisherData::NewLC( *this, *aNode ); |
|
415 |
|
416 iPublishers.AppendL( publisher ); |
|
417 CleanupStack::Pop( publisher ); |
|
418 } |
|
419 |
|
420 // ----------------------------------------------------------------------------- |
|
421 // CXnPluginData::ContentSourceNodesL() |
|
422 // |
|
423 // ----------------------------------------------------------------------------- |
|
424 // |
|
425 void CXnPluginData::ContentSourceNodesL( RPointerArray< CXnNode >& aList ) const |
|
426 { |
|
427 for ( TInt i = 0; i < iPublishers.Count(); i++ ) |
|
428 { |
|
429 aList.AppendL( iPublishers[i]->ContentSource() ); |
|
430 } |
|
431 } |
|
432 |
|
433 // ----------------------------------------------------------------------------- |
|
434 // CXnPluginData::Publishers() |
|
435 // |
|
436 // ----------------------------------------------------------------------------- |
|
437 // |
|
438 void CXnPluginData::PublishersL( RPointerArray< CXnPublisherData >& aList ) const |
|
439 { |
|
440 for ( TInt i = 0; i < iPublishers.Count(); i++ ) |
|
441 { |
|
442 aList.AppendL( iPublishers[i] ); |
|
443 } |
|
444 } |
|
445 |
|
446 // ----------------------------------------------------------------------------- |
|
447 // CXnPluginData::SetAppearanceNodeL() |
|
448 // |
|
449 // ----------------------------------------------------------------------------- |
|
450 // |
|
451 void CXnPluginData::SetAppearanceNodeL( CXnNode* aNode ) |
|
452 { |
|
453 User::LeaveIfError( iAppearanceNodes.InsertInAddressOrder( aNode ) ); |
|
454 } |
|
455 |
|
456 // ----------------------------------------------------------------------------- |
|
457 // CXnPluginData::AppearanceNodesL() |
|
458 // |
|
459 // ----------------------------------------------------------------------------- |
|
460 // |
|
461 void CXnPluginData::AppearanceNodesL( RPointerArray< CXnNode >& aList ) const |
|
462 { |
|
463 for ( TInt i = 0; i < iAppearanceNodes.Count(); i++ ) |
|
464 { |
|
465 aList.AppendL( iAppearanceNodes[i] ); |
|
466 } |
|
467 } |
|
468 |
|
469 // ----------------------------------------------------------------------------- |
|
470 // CXnPluginData::SetInitialFocusNodeL() |
|
471 // |
|
472 // ----------------------------------------------------------------------------- |
|
473 // |
|
474 void CXnPluginData::SetInitialFocusNodeL( CXnNode* aNode ) |
|
475 { |
|
476 User::LeaveIfError( iInitialFocusNodes.InsertInAddressOrder( aNode ) ); |
|
477 } |
|
478 |
|
479 // ----------------------------------------------------------------------------- |
|
480 // CXnPluginData::InitialFocusNodesL() |
|
481 // |
|
482 // ----------------------------------------------------------------------------- |
|
483 // |
|
484 void CXnPluginData::InitialFocusNodesL( RPointerArray< CXnNode >& aList ) const |
|
485 { |
|
486 for ( TInt i = 0; i < iInitialFocusNodes.Count(); i++ ) |
|
487 { |
|
488 aList.AppendL( iInitialFocusNodes[i] ); |
|
489 } |
|
490 } |
|
491 |
|
492 // ----------------------------------------------------------------------------- |
|
493 // CXnPluginData::Flush() |
|
494 // Flushes this plugins data |
|
495 // ----------------------------------------------------------------------------- |
|
496 // |
|
497 void CXnPluginData::Flush() |
|
498 { |
|
499 // Don't touch to iOwner, because this plugin might be reused later |
|
500 |
|
501 iFlags.ClearAll(); |
|
502 |
|
503 // This is default |
|
504 iFlags.Set( EIsRemovable ); |
|
505 |
|
506 iNode = NULL; |
|
507 |
|
508 delete iConfigurationId; |
|
509 iConfigurationId = NULL; |
|
510 |
|
511 delete iPluginId; |
|
512 iPluginId = NULL; |
|
513 |
|
514 delete iPluginUid; |
|
515 iPluginUid = NULL; |
|
516 |
|
517 delete iPluginName; |
|
518 iPluginName = NULL; |
|
519 |
|
520 delete iPluginType; |
|
521 iPluginType = NULL; |
|
522 |
|
523 delete iPublisherName; |
|
524 iPublisherName = NULL; |
|
525 |
|
526 if ( iResources ) |
|
527 { |
|
528 iResources->ResetAndDestroy(); |
|
529 delete iResources; |
|
530 iResources = NULL; |
|
531 } |
|
532 |
|
533 iPublishers.ResetAndDestroy(); |
|
534 iControls.Reset(); |
|
535 iAppearanceNodes.Reset(); |
|
536 iInitialFocusNodes.Reset(); |
|
537 iPopupNodes.Reset(); |
|
538 iPluginsData.ResetAndDestroy(); |
|
539 |
|
540 User::Heap().Compress(); |
|
541 } |
|
542 |
|
543 // ----------------------------------------------------------------------------- |
|
544 // CXnPluginData::Empty() |
|
545 // |
|
546 // ----------------------------------------------------------------------------- |
|
547 // |
|
548 TBool CXnPluginData::Empty() const |
|
549 { |
|
550 return ( iFlags.IsSet( EIsEmpty ) ? ETrue : EFalse ); |
|
551 } |
|
552 |
|
553 // ----------------------------------------------------------------------------- |
|
554 // CXnPluginData::SetEmpty() |
|
555 // |
|
556 // ----------------------------------------------------------------------------- |
|
557 // |
|
558 void CXnPluginData::SetEmptyL( const TDesC8& aPluginId ) |
|
559 { |
|
560 if ( Occupied() ) |
|
561 { |
|
562 User::Leave( KErrInUse ); |
|
563 } |
|
564 |
|
565 HBufC8* id( aPluginId.AllocL() ); |
|
566 |
|
567 Flush(); |
|
568 |
|
569 // Takes ownership |
|
570 iPluginId = id; |
|
571 |
|
572 iFlags.Set( EIsEmpty ); |
|
573 } |
|
574 |
|
575 // ----------------------------------------------------------------------------- |
|
576 // CXnPluginData::SetIsDisplayingPopup() |
|
577 // |
|
578 // ----------------------------------------------------------------------------- |
|
579 // |
|
580 void CXnPluginData::SetIsDisplayingPopup ( TBool aVisible, CXnNode* aNode ) |
|
581 { |
|
582 if ( aVisible ) |
|
583 { |
|
584 iPopupNodes.InsertInAddressOrder( aNode ); |
|
585 } |
|
586 else |
|
587 { |
|
588 TInt index( iPopupNodes.Find( aNode ) ); |
|
589 |
|
590 if ( index != KErrNotFound ) |
|
591 { |
|
592 iPopupNodes.Remove( index ); |
|
593 } |
|
594 } |
|
595 } |
|
596 |
|
597 //------------------------------------------------------------------------------ |
|
598 // CXnPluginData::IsDisplayingPopup() |
|
599 // |
|
600 //------------------------------------------------------------------------------ |
|
601 // |
|
602 TBool CXnPluginData::IsDisplayingPopup() const |
|
603 { |
|
604 return ( iPopupNodes.Count() > 0 ); |
|
605 } |
|
606 |
|
607 // ----------------------------------------------------------------------------- |
|
608 // CXnPluginData::PopupNodesL() |
|
609 // |
|
610 // ----------------------------------------------------------------------------- |
|
611 // |
|
612 void CXnPluginData::PopupNodesL( RPointerArray< CXnNode >& aList ) const |
|
613 { |
|
614 for ( TInt i = 0; i < iPopupNodes.Count(); i++ ) |
|
615 { |
|
616 aList.AppendL( iPopupNodes[i] ); |
|
617 } |
|
618 } |
|
619 |
|
620 // ----------------------------------------------------------------------------- |
|
621 // CXnViewData::SetLockingStatus |
|
622 // |
|
623 // ----------------------------------------------------------------------------- |
|
624 // |
|
625 void CXnPluginData::SetLockingStatus( const TDesC8& aStatus ) |
|
626 { |
|
627 if ( aStatus.CompareF( KLockingStatusLocked ) == 0 ) |
|
628 { |
|
629 iFlags.Clear( EIsRemovable ); |
|
630 } |
|
631 else |
|
632 { |
|
633 iFlags.Set( EIsRemovable ); |
|
634 } |
|
635 } |
|
636 |
|
637 // End of file |