webengine/widgetregistry/Server/src/WidgetEntry.cpp
branchRCL_3
changeset 48 79859ed3eea9
parent 46 30342f40acbf
child 49 919f36ff910f
equal deleted inserted replaced
47:e1bea15f9a39 48:79859ed3eea9
    15 *
    15 *
    16 *
    16 *
    17 */
    17 */
    18 
    18 
    19 #include "WidgetEntry.h"
    19 #include "WidgetEntry.h"
    20 #include "UidAllocator.h"
    20 #include "WidgetRegistryConstants.h"
    21 #include <widgetregistryconstants.h>
       
    22 #include <s32file.h>
    21 #include <s32file.h>
    23 #include <f32file.h>
    22 #include <f32file.h>
    24 #include <APGTASK.H>
    23 #include <apgtask.h>
    25 //#include <widgetappdefs.rh>
    24 //#include <widgetappdefs.rh>
    26 
    25 
    27 // EXTERNAL DATA STRUCTURES
    26 // EXTERNAL DATA STRUCTURES
    28 
    27 
    29 // EXTERNAL FUNCTION PROTOTYPES
    28 // EXTERNAL FUNCTION PROTOTYPES
    53 _LIT( KXmlDataTypeBool, "bool" );
    52 _LIT( KXmlDataTypeBool, "bool" );
    54 _LIT( KXmlDataTypeInt, "int" );
    53 _LIT( KXmlDataTypeInt, "int" );
    55 _LIT( KXmlDataTypeString, "string" );
    54 _LIT( KXmlDataTypeString, "string" );
    56 _LIT( KXmlDataTypeUid, "uid" );
    55 _LIT( KXmlDataTypeUid, "uid" );
    57 
    56 
       
    57 static const TInt KWidgetPropertyListVersion32 = 1;
       
    58 static const TInt KWidgetPropertyListVersion71 = 3;
    58 // MODULE DATA STRUCTURES
    59 // MODULE DATA STRUCTURES
    59 
    60 
    60 // LOCAL FUNCTION PROTOTYPES
    61 // LOCAL FUNCTION PROTOTYPES
    61 
    62 
    62 // FORWARD DECLARATIONS
    63 // FORWARD DECLARATIONS
    90 // ============================================================================
    91 // ============================================================================
    91 //    
    92 //    
    92 CWidgetEntry* CWidgetEntry::NewL( RPointerArray<CWidgetPropertyValue>** aProps )
    93 CWidgetEntry* CWidgetEntry::NewL( RPointerArray<CWidgetPropertyValue>** aProps )
    93 {
    94 {
    94     CWidgetEntry* tmp = NewL();
    95     CWidgetEntry* tmp = NewL();
    95     TInt i = 0;
    96     for ( TInt i = 0; i < (*aProps)->Count(); i++ )
    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     
       
   113     (*aProps)->Close();
   105     (*aProps)->Close();
   114     delete *aProps;
   106     delete *aProps;
   115     *aProps = NULL;
   107     *aProps = NULL;
   116     return tmp;
   108     return tmp;
   117 }
   109 }
   123 // @since 3.1
   115 // @since 3.1
   124 // ============================================================================
   116 // ============================================================================
   125 //
   117 //
   126 CWidgetEntry::CWidgetEntry()
   118 CWidgetEntry::CWidgetEntry()
   127     : iPropertyValues( EWidgetPropertyIdCount ),
   119     : iPropertyValues( EWidgetPropertyIdCount ),
   128       iMiniView ( EFalse),
   120       iBlanketPermGranted ( EFalse),
   129       iFullView ( EFalse),
   121       iFullView ( EFalse),
   130       iBlanketPermGranted ( EFalse)
   122       iMiniView ( EFalse)
   131     {
   123     {
   132     }
   124     }
   133 
   125 
   134 // ============================================================================
   126 // ============================================================================
   135 // CWidgetEntry::~CWidgetEntry()
   127 // CWidgetEntry::~CWidgetEntry()
   176     // For now, leave if version doesn't match compiled-in version,
   168     // For now, leave if version doesn't match compiled-in version,
   177     // FUTURE do something smarter
   169     // FUTURE do something smarter
   178     //WIDGETPROPERTYLISTVERSION is 1 in case of Tiger engine and 3 in case of Leopard engine. Therefore, modifying the check such that 
   170     //WIDGETPROPERTYLISTVERSION is 1 in case of Tiger engine and 3 in case of Leopard engine. Therefore, modifying the check such that 
   179     //when the Version id is 1 or 3, we do not treat the file as corrupt.
   171     //when the Version id is 1 or 3, we do not treat the file as corrupt.
   180     if ( ( EWidgetPropTypeUnknown == (*this)[EWidgetPropertyListVersion].iType )
   172     if ( ( EWidgetPropTypeUnknown == (*this)[EWidgetPropertyListVersion].iType )
   181          || ( (KWidgetPropertyListVersion32 != (*this)[EWidgetPropertyListVersion] ) && 
   173          || ( (KWidgetPropertyListVersion32 != (*this)[EWidgetPropertyListVersion] ) && (KWidgetPropertyListVersion71 != (*this)[EWidgetPropertyListVersion] )) )
   182               (KWidgetPropertyListVersion71 != (*this)[EWidgetPropertyListVersion] ) &&
       
   183               (KWidgetPropertyListVersion71CWRT != (*this)[EWidgetPropertyListVersion] ) ))
       
   184         {
   174         {
   185         User::Leave( KErrCorrupt );
   175         User::Leave( KErrCorrupt );
   186         }
   176         }
   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     }        
       
   216 
   177 
   217     // fill property values array
   178     // fill property values array
   218     for ( TInt i = 1; i < propertyIdCount; ++i )
   179     for ( TInt i = 1; i < EWidgetPropertyIdCount; ++i )
   219         {
   180         {
   220         (*this)[i].DeserializeL( aReadStream );
   181         (*this)[i].DeserializeL( aReadStream );
   221         }
   182         }
   222     }
   183     }
   223 
   184 
   254                 CWidgetPropertyValue* val = CWidgetPropertyValue::NewL();
   215                 CWidgetPropertyValue* val = CWidgetPropertyValue::NewL();
   255                 CleanupStack::PushL(val);
   216                 CleanupStack::PushL(val);
   256                 iPropertyValues.AppendL( val );
   217                 iPropertyValues.AppendL( val );
   257                 CleanupStack::Pop(); // val
   218                 CleanupStack::Pop(); // val
   258                 }
   219                 }
   259             // Internalization of the Xml is complete, cleanup the properties appropriately
       
   260             PropertyCleanupL();
       
   261             return;
   220             return;
   262             }
   221             }
   263         TPtrC8 propTag( n->name );
   222         TPtrC8 propTag( n->name );
   264         if ( 0 != propTag.Compare( KXmlPropTag() ) )
   223         if ( 0 != propTag.Compare( KXmlPropTag() ) )
   265             {
   224             {
   434 
   393 
   435 void CWidgetEntry::ExternalizeXmlL( RWriteStream& aWriteStream,
   394 void CWidgetEntry::ExternalizeXmlL( RWriteStream& aWriteStream,
   436                                     CWidgetRegistryXml* aXmlProcessor,
   395                                     CWidgetRegistryXml* aXmlProcessor,
   437                                     RFs& aFileSession )
   396                                     RFs& aFileSession )
   438     {
   397     {
       
   398     xmlDocPtr doc = NULL; // not really used
   439     TInt i = 0;
   399     TInt i = 0;
   440     // For each property, write an XML entry
   400     // For each property, write an XML entry
   441     for ( ; i < EWidgetPropertyIdCount; ++i )
   401     for ( ; i < EWidgetPropertyIdCount; ++i )
   442         {
   402         {
   443         // skip props without values
   403         // skip props without values
   621         // in the registry are running under WidgetUI
   581         // in the registry are running under WidgetUI
   622         RWsSession wsSession;
   582         RWsSession wsSession;
   623         User::LeaveIfError( wsSession.Connect() );
   583         User::LeaveIfError( wsSession.Connect() );
   624         CleanupClosePushL( wsSession );
   584         CleanupClosePushL( wsSession );
   625         TApaTaskList taskList( wsSession );
   585         TApaTaskList taskList( wsSession );
   626 
   586         TApaTask task = taskList.FindApp( KUidWidgetUi );
   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 
       
   637         if ( EFalse == task.Exists() )
   587         if ( EFalse == task.Exists() )
   638             {
   588             {
   639             // widget UI crashed, reset active
   589             // widget UI crashed, reset active
   640             iActive = 0;
   590             iActive = 0;
   641             }
   591             }
   665         {
   615         {
   666         return SAPIACCESSDENIED;
   616         return SAPIACCESSDENIED;
   667         }
   617         }
   668         
   618         
   669     }
   619     }
   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 }
       
   716 
   620 
   717 //  End of File
   621 //  End of File