webengine/widgetregistry/Server/src/WidgetEntry.cpp
branchRCL_3
changeset 35 1f3c3f2f5b0a
parent 26 cb62a4f66ebe
child 46 30342f40acbf
--- a/webengine/widgetregistry/Server/src/WidgetEntry.cpp	Fri Mar 12 15:48:51 2010 +0200
+++ b/webengine/widgetregistry/Server/src/WidgetEntry.cpp	Mon Mar 15 12:44:50 2010 +0200
@@ -17,6 +17,7 @@
 */
 
 #include "WidgetEntry.h"
+#include "UidAllocator.h"
 #include <widgetregistryconstants.h>
 #include <s32file.h>
 #include <f32file.h>
@@ -54,8 +55,6 @@
 _LIT( KXmlDataTypeString, "string" );
 _LIT( KXmlDataTypeUid, "uid" );
 
-static const TInt KWidgetPropertyListVersion32 = 1;
-static const TInt KWidgetPropertyListVersion71 = 3;
 // MODULE DATA STRUCTURES
 
 // LOCAL FUNCTION PROTOTYPES
@@ -93,7 +92,8 @@
 CWidgetEntry* CWidgetEntry::NewL( RPointerArray<CWidgetPropertyValue>** aProps )
 {
     CWidgetEntry* tmp = NewL();
-    for ( TInt i = 0; i < (*aProps)->Count(); i++ )
+    TInt i = 0;
+    for ( ; i < (*aProps)->Count(); i++ )
     {
         CWidgetPropertyValue* value = CWidgetPropertyValue::NewL();
         tmp->iPropertyValues.AppendL( value );
@@ -102,6 +102,14 @@
         (**aProps)[i]->iType = EWidgetPropTypeUnknown;
         delete (**aProps)[i];
     }
+
+    // Pad out with unknown properties to reach the correct number
+    for ( ; i < EWidgetPropertyIdCount ; i++ )
+    {
+        CWidgetPropertyValue* value = CWidgetPropertyValue::NewL();
+        tmp->iPropertyValues.AppendL( value );
+    }
+    
     (*aProps)->Close();
     delete *aProps;
     *aProps = NULL;
@@ -170,12 +178,42 @@
     //WIDGETPROPERTYLISTVERSION is 1 in case of Tiger engine and 3 in case of Leopard engine. Therefore, modifying the check such that 
     //when the Version id is 1 or 3, we do not treat the file as corrupt.
     if ( ( EWidgetPropTypeUnknown == (*this)[EWidgetPropertyListVersion].iType )
-         || ( (KWidgetPropertyListVersion32 != (*this)[EWidgetPropertyListVersion] ) && (KWidgetPropertyListVersion71 != (*this)[EWidgetPropertyListVersion] )) )
+         || ( (KWidgetPropertyListVersion32 != (*this)[EWidgetPropertyListVersion] ) && 
+              (KWidgetPropertyListVersion71 != (*this)[EWidgetPropertyListVersion] ) &&
+              (KWidgetPropertyListVersion71CWRT != (*this)[EWidgetPropertyListVersion] ) ))
         {
         User::Leave( KErrCorrupt );
         }
-    // Read only until the ENokiaWidget for the 3.2 widgets 
-    TInt propertyIdCount =  (*this)[EWidgetPropertyListVersion] == KWidgetPropertyListVersion32 ? ENokiaWidget+1 : EWidgetPropertyIdCount; 
+        
+    // Provide appropriate values for EProcessUid and EMimeType
+    (*this)[EProcessUid] = KUidWidgetUi.iUid;
+    
+    HBufC* heapBuf = HBufC::NewLC(KWidgetMime().Length());
+    TPtr ptr(heapBuf->Des());   
+    ptr.Copy(KWidgetMime);  // 8-bit to 16-bit copy
+    (*this)[EMimeType] = *heapBuf;
+    CleanupStack::PopAndDestroy();
+    
+    // Read only until the ENokiaWidget for the 3.2 widgets, EPreInstalled for 7.1 widgets
+    TInt propertyIdCount = 0;
+    switch ((*this)[EWidgetPropertyListVersion]) {
+    case KWidgetPropertyListVersion32:
+        propertyIdCount = ENokiaWidget+1;
+        // since we've filled in the EProcessUid and EMimeType we're
+        // now at KWidgetPropertyListVersion71CWRT
+        (*this)[EWidgetPropertyListVersion] = KWidgetPropertyListVersion71CWRT;
+        break;
+    case KWidgetPropertyListVersion71:
+        propertyIdCount = EPreInstalled+1;
+        // since we've filled in the EProcessUid and EMimeType we're
+        // now at KWidgetPropertyListVersion71CWRT
+        (*this)[EWidgetPropertyListVersion] = KWidgetPropertyListVersion71CWRT;
+        break;
+    case KWidgetPropertyListVersion71CWRT:
+        propertyIdCount = EWidgetPropertyIdCount;
+        break;
+    }        
+
     // fill property values array
     for ( TInt i = 1; i < propertyIdCount; ++i )
         {
@@ -218,6 +256,8 @@
                 iPropertyValues.AppendL( val );
                 CleanupStack::Pop(); // val
                 }
+            // Internalization of the Xml is complete, cleanup the properties appropriately
+            PropertyCleanupL();
             return;
             }
         TPtrC8 propTag( n->name );
@@ -584,7 +624,17 @@
         User::LeaveIfError( wsSession.Connect() );
         CleanupClosePushL( wsSession );
         TApaTaskList taskList( wsSession );
-        TApaTask task = taskList.FindApp( KUidWidgetUi );
+
+        TUid uid;
+
+        if ( EWidgetPropTypeUnknown == (*this)[EProcessUid].iType ) {
+            uid = KUidWidgetUi;
+        } else {
+            uid = TUid::Uid( (*this)[EProcessUid] );
+        }
+
+        TApaTask task = taskList.FindApp( uid );
+
         if ( EFalse == task.Exists() )
             {
             // widget UI crashed, reset active
@@ -618,5 +668,49 @@
         }
         
     }
+    
+// ============================================================================
+// CWidgetEntry::PropertyCleanupL()
+// Make adjustments to bring the property values up to the current
+// property list version
+//
+// @since 
+// ============================================================================
+//
+void CWidgetEntry::PropertyCleanupL()
+{
+    TInt currentVersion = (*this)[EWidgetPropertyListVersion];
+
+    while (currentVersion < WIDGETPROPERTYLISTVERSION) {
+        switch (currentVersion) {
+        case KWidgetPropertyListVersion32:
+            // Go from PropertyListVersion32 to PropertyListVersion71
+            // Adds EMiniViewEnable, EBlanketPermGranted, EPreInstalled
+            // (all are optional, just update the version number now
+            //  and they will be undefined when serialized/deserialized)
+            currentVersion = KWidgetPropertyListVersion71;
+            break;
+        case KWidgetPropertyListVersion71:
+            // Go from PropertlyListVersion71 to PropertyListVersion71CWRT
+            // 1) add ProcessUid for WRT (wgz) widgets
+            (*this)[EProcessUid] = KUidWidgetUi.iUid;
+
+             // 2) add MIMEType
+            HBufC* heapBuf = HBufC::NewLC(KWidgetMime().Length());
+            TPtr ptr(heapBuf->Des());
+            ptr.Copy(KWidgetMime);  // 8-bit to 16-bit copy
+            (*this)[EMimeType] = *heapBuf;
+            CleanupStack::PopAndDestroy();
+
+            currentVersion = KWidgetPropertyListVersion71CWRT;
+            break;
+        default:
+            // Trouble
+            return;
+        }
+
+        (*this)[EWidgetPropertyListVersion] = currentVersion;
+    }
+}
 
 //  End of File