15 * |
15 * |
16 * |
16 * |
17 */ |
17 */ |
18 |
18 |
19 #include "WidgetEntry.h" |
19 #include "WidgetEntry.h" |
20 #include "WidgetRegistryConstants.h" |
20 #include "UidAllocator.h" |
|
21 #include <widgetregistryconstants.h> |
21 #include <s32file.h> |
22 #include <s32file.h> |
22 #include <f32file.h> |
23 #include <f32file.h> |
23 #include <apgtask.h> |
24 #include <APGTASK.H> |
24 //#include <widgetappdefs.rh> |
25 //#include <widgetappdefs.rh> |
25 |
26 |
26 // EXTERNAL DATA STRUCTURES |
27 // EXTERNAL DATA STRUCTURES |
27 |
28 |
28 // EXTERNAL FUNCTION PROTOTYPES |
29 // EXTERNAL FUNCTION PROTOTYPES |
52 _LIT( KXmlDataTypeBool, "bool" ); |
53 _LIT( KXmlDataTypeBool, "bool" ); |
53 _LIT( KXmlDataTypeInt, "int" ); |
54 _LIT( KXmlDataTypeInt, "int" ); |
54 _LIT( KXmlDataTypeString, "string" ); |
55 _LIT( KXmlDataTypeString, "string" ); |
55 _LIT( KXmlDataTypeUid, "uid" ); |
56 _LIT( KXmlDataTypeUid, "uid" ); |
56 |
57 |
57 static const TInt KWidgetPropertyListVersion32 = 1; |
|
58 static const TInt KWidgetPropertyListVersion71 = 3; |
|
59 // MODULE DATA STRUCTURES |
58 // MODULE DATA STRUCTURES |
60 |
59 |
61 // LOCAL FUNCTION PROTOTYPES |
60 // LOCAL FUNCTION PROTOTYPES |
62 |
61 |
63 // FORWARD DECLARATIONS |
62 // FORWARD DECLARATIONS |
91 // ============================================================================ |
90 // ============================================================================ |
92 // |
91 // |
93 CWidgetEntry* CWidgetEntry::NewL( RPointerArray<CWidgetPropertyValue>** aProps ) |
92 CWidgetEntry* CWidgetEntry::NewL( RPointerArray<CWidgetPropertyValue>** aProps ) |
94 { |
93 { |
95 CWidgetEntry* tmp = NewL(); |
94 CWidgetEntry* tmp = NewL(); |
96 for ( TInt i = 0; i < (*aProps)->Count(); i++ ) |
95 TInt i = 0; |
|
96 for ( ; i < (*aProps)->Count(); i++ ) |
97 { |
97 { |
98 CWidgetPropertyValue* value = CWidgetPropertyValue::NewL(); |
98 CWidgetPropertyValue* value = CWidgetPropertyValue::NewL(); |
99 tmp->iPropertyValues.AppendL( value ); |
99 tmp->iPropertyValues.AppendL( value ); |
100 (*tmp)[i].iType = (**aProps)[i]->iType; |
100 (*tmp)[i].iType = (**aProps)[i]->iType; |
101 (*tmp)[i].iValue = (**aProps)[i]->iValue; // shallow copy of strings |
101 (*tmp)[i].iValue = (**aProps)[i]->iValue; // shallow copy of strings |
102 (**aProps)[i]->iType = EWidgetPropTypeUnknown; |
102 (**aProps)[i]->iType = EWidgetPropTypeUnknown; |
103 delete (**aProps)[i]; |
103 delete (**aProps)[i]; |
104 } |
104 } |
|
105 |
|
106 // Pad out with unknown properties to reach the correct number |
|
107 for ( ; i < EWidgetPropertyIdCount ; i++ ) |
|
108 { |
|
109 CWidgetPropertyValue* value = CWidgetPropertyValue::NewL(); |
|
110 tmp->iPropertyValues.AppendL( value ); |
|
111 } |
|
112 |
105 (*aProps)->Close(); |
113 (*aProps)->Close(); |
106 delete *aProps; |
114 delete *aProps; |
107 *aProps = NULL; |
115 *aProps = NULL; |
108 return tmp; |
116 return tmp; |
109 } |
117 } |
115 // @since 3.1 |
123 // @since 3.1 |
116 // ============================================================================ |
124 // ============================================================================ |
117 // |
125 // |
118 CWidgetEntry::CWidgetEntry() |
126 CWidgetEntry::CWidgetEntry() |
119 : iPropertyValues( EWidgetPropertyIdCount ), |
127 : iPropertyValues( EWidgetPropertyIdCount ), |
120 iBlanketPermGranted ( EFalse), |
128 iMiniView ( EFalse), |
121 iFullView ( EFalse), |
129 iFullView ( EFalse), |
122 iMiniView ( EFalse) |
130 iBlanketPermGranted ( EFalse) |
123 { |
131 { |
124 } |
132 } |
125 |
133 |
126 // ============================================================================ |
134 // ============================================================================ |
127 // CWidgetEntry::~CWidgetEntry() |
135 // CWidgetEntry::~CWidgetEntry() |
168 // For now, leave if version doesn't match compiled-in version, |
176 // For now, leave if version doesn't match compiled-in version, |
169 // FUTURE do something smarter |
177 // FUTURE do something smarter |
170 //WIDGETPROPERTYLISTVERSION is 1 in case of Tiger engine and 3 in case of Leopard engine. Therefore, modifying the check such that |
178 //WIDGETPROPERTYLISTVERSION is 1 in case of Tiger engine and 3 in case of Leopard engine. Therefore, modifying the check such that |
171 //when the Version id is 1 or 3, we do not treat the file as corrupt. |
179 //when the Version id is 1 or 3, we do not treat the file as corrupt. |
172 if ( ( EWidgetPropTypeUnknown == (*this)[EWidgetPropertyListVersion].iType ) |
180 if ( ( EWidgetPropTypeUnknown == (*this)[EWidgetPropertyListVersion].iType ) |
173 || ( (KWidgetPropertyListVersion32 != (*this)[EWidgetPropertyListVersion] ) && (KWidgetPropertyListVersion71 != (*this)[EWidgetPropertyListVersion] )) ) |
181 || ( (KWidgetPropertyListVersion32 != (*this)[EWidgetPropertyListVersion] ) && |
|
182 (KWidgetPropertyListVersion71 != (*this)[EWidgetPropertyListVersion] ) && |
|
183 (KWidgetPropertyListVersion71CWRT != (*this)[EWidgetPropertyListVersion] ) )) |
174 { |
184 { |
175 User::Leave( KErrCorrupt ); |
185 User::Leave( KErrCorrupt ); |
176 } |
186 } |
|
187 |
|
188 // Provide appropriate values for EProcessUid and EMimeType |
|
189 (*this)[EProcessUid] = KUidWidgetUi.iUid; |
|
190 |
|
191 HBufC* heapBuf = HBufC::NewLC(KWidgetMime().Length()); |
|
192 TPtr ptr(heapBuf->Des()); |
|
193 ptr.Copy(KWidgetMime); // 8-bit to 16-bit copy |
|
194 (*this)[EMimeType] = *heapBuf; |
|
195 CleanupStack::PopAndDestroy(); |
|
196 |
|
197 // Read only until the ENokiaWidget for the 3.2 widgets, EPreInstalled for 7.1 widgets |
|
198 TInt propertyIdCount = 0; |
|
199 switch ((*this)[EWidgetPropertyListVersion]) { |
|
200 case KWidgetPropertyListVersion32: |
|
201 propertyIdCount = ENokiaWidget+1; |
|
202 // since we've filled in the EProcessUid and EMimeType we're |
|
203 // now at KWidgetPropertyListVersion71CWRT |
|
204 (*this)[EWidgetPropertyListVersion] = KWidgetPropertyListVersion71CWRT; |
|
205 break; |
|
206 case KWidgetPropertyListVersion71: |
|
207 propertyIdCount = EPreInstalled+1; |
|
208 // since we've filled in the EProcessUid and EMimeType we're |
|
209 // now at KWidgetPropertyListVersion71CWRT |
|
210 (*this)[EWidgetPropertyListVersion] = KWidgetPropertyListVersion71CWRT; |
|
211 break; |
|
212 case KWidgetPropertyListVersion71CWRT: |
|
213 propertyIdCount = EWidgetPropertyIdCount; |
|
214 break; |
|
215 } |
177 |
216 |
178 // fill property values array |
217 // fill property values array |
179 for ( TInt i = 1; i < EWidgetPropertyIdCount; ++i ) |
218 for ( TInt i = 1; i < propertyIdCount; ++i ) |
180 { |
219 { |
181 (*this)[i].DeserializeL( aReadStream ); |
220 (*this)[i].DeserializeL( aReadStream ); |
182 } |
221 } |
183 } |
222 } |
184 |
223 |
215 CWidgetPropertyValue* val = CWidgetPropertyValue::NewL(); |
254 CWidgetPropertyValue* val = CWidgetPropertyValue::NewL(); |
216 CleanupStack::PushL(val); |
255 CleanupStack::PushL(val); |
217 iPropertyValues.AppendL( val ); |
256 iPropertyValues.AppendL( val ); |
218 CleanupStack::Pop(); // val |
257 CleanupStack::Pop(); // val |
219 } |
258 } |
|
259 // Internalization of the Xml is complete, cleanup the properties appropriately |
|
260 PropertyCleanupL(); |
220 return; |
261 return; |
221 } |
262 } |
222 TPtrC8 propTag( n->name ); |
263 TPtrC8 propTag( n->name ); |
223 if ( 0 != propTag.Compare( KXmlPropTag() ) ) |
264 if ( 0 != propTag.Compare( KXmlPropTag() ) ) |
224 { |
265 { |
393 |
434 |
394 void CWidgetEntry::ExternalizeXmlL( RWriteStream& aWriteStream, |
435 void CWidgetEntry::ExternalizeXmlL( RWriteStream& aWriteStream, |
395 CWidgetRegistryXml* aXmlProcessor, |
436 CWidgetRegistryXml* aXmlProcessor, |
396 RFs& aFileSession ) |
437 RFs& aFileSession ) |
397 { |
438 { |
398 xmlDocPtr doc = NULL; // not really used |
|
399 TInt i = 0; |
439 TInt i = 0; |
400 // For each property, write an XML entry |
440 // For each property, write an XML entry |
401 for ( ; i < EWidgetPropertyIdCount; ++i ) |
441 for ( ; i < EWidgetPropertyIdCount; ++i ) |
402 { |
442 { |
403 // skip props without values |
443 // skip props without values |
581 // in the registry are running under WidgetUI |
621 // in the registry are running under WidgetUI |
582 RWsSession wsSession; |
622 RWsSession wsSession; |
583 User::LeaveIfError( wsSession.Connect() ); |
623 User::LeaveIfError( wsSession.Connect() ); |
584 CleanupClosePushL( wsSession ); |
624 CleanupClosePushL( wsSession ); |
585 TApaTaskList taskList( wsSession ); |
625 TApaTaskList taskList( wsSession ); |
586 TApaTask task = taskList.FindApp( KUidWidgetUi ); |
626 |
|
627 TUid uid; |
|
628 |
|
629 if ( EWidgetPropTypeUnknown == (*this)[EProcessUid].iType ) { |
|
630 uid = KUidWidgetUi; |
|
631 } else { |
|
632 uid = TUid::Uid( (*this)[EProcessUid] ); |
|
633 } |
|
634 |
|
635 TApaTask task = taskList.FindApp( uid ); |
|
636 |
587 if ( EFalse == task.Exists() ) |
637 if ( EFalse == task.Exists() ) |
588 { |
638 { |
589 // widget UI crashed, reset active |
639 // widget UI crashed, reset active |
590 iActive = 0; |
640 iActive = 0; |
591 } |
641 } |
615 { |
665 { |
616 return SAPIACCESSDENIED; |
666 return SAPIACCESSDENIED; |
617 } |
667 } |
618 |
668 |
619 } |
669 } |
|
670 |
|
671 // ============================================================================ |
|
672 // CWidgetEntry::PropertyCleanupL() |
|
673 // Make adjustments to bring the property values up to the current |
|
674 // property list version |
|
675 // |
|
676 // @since |
|
677 // ============================================================================ |
|
678 // |
|
679 void CWidgetEntry::PropertyCleanupL() |
|
680 { |
|
681 TInt currentVersion = (*this)[EWidgetPropertyListVersion]; |
|
682 |
|
683 while (currentVersion < WIDGETPROPERTYLISTVERSION) { |
|
684 switch (currentVersion) { |
|
685 case KWidgetPropertyListVersion32: |
|
686 // Go from PropertyListVersion32 to PropertyListVersion71 |
|
687 // Adds EMiniViewEnable, EBlanketPermGranted, EPreInstalled |
|
688 // (all are optional, just update the version number now |
|
689 // and they will be undefined when serialized/deserialized) |
|
690 currentVersion = KWidgetPropertyListVersion71; |
|
691 break; |
|
692 case KWidgetPropertyListVersion71: |
|
693 // Go from PropertlyListVersion71 to PropertyListVersion71CWRT |
|
694 // 1) add ProcessUid for WRT (wgz) widgets |
|
695 { |
|
696 (*this)[EProcessUid] = KUidWidgetUi.iUid; |
|
697 |
|
698 // 2) add MIMEType |
|
699 HBufC* heapBuf = HBufC::NewLC(KWidgetMime().Length()); |
|
700 TPtr ptr(heapBuf->Des()); |
|
701 ptr.Copy(KWidgetMime); // 8-bit to 16-bit copy |
|
702 (*this)[EMimeType] = *heapBuf; |
|
703 CleanupStack::PopAndDestroy(); |
|
704 |
|
705 currentVersion = KWidgetPropertyListVersion71CWRT; |
|
706 } |
|
707 break; |
|
708 default: |
|
709 // Trouble |
|
710 return; |
|
711 } |
|
712 |
|
713 (*this)[EWidgetPropertyListVersion] = currentVersion; |
|
714 } |
|
715 } |
620 |
716 |
621 // End of File |
717 // End of File |