contentstorage/casrv/cawidgetscanner/src/cawidgetstoragehandler.cpp
changeset 80 397d00875918
parent 73 4bc7b118b3df
child 83 156f692b1687
--- a/contentstorage/casrv/cawidgetscanner/src/cawidgetstoragehandler.cpp	Fri May 14 16:10:06 2010 +0300
+++ b/contentstorage/casrv/cawidgetscanner/src/cawidgetstoragehandler.cpp	Thu May 27 13:11:12 2010 +0300
@@ -17,6 +17,7 @@
 // INCLUDE FILES
 
 #include <badesca.h>
+#include <usif/scr/screntries.h>
 #include "widgetscannerutils.h"
 #include "cawidgetstoragehandler.h"
 #include "cadef.h"
@@ -25,6 +26,8 @@
 #include "castorageproxy.h"
 #include "caarraycleanup.inl"
 
+using namespace Usif;
+
 // ============================ MEMBER FUNCTIONS ===============================
 
 // -----------------------------------------------------------------------------
@@ -47,6 +50,7 @@
 //
 void CCaWidgetStorageHandler::ConstructL()
     {
+    User::LeaveIfError( iSoftwareRegistry.Connect() );
     }
 
 // -----------------------------------------------------------------------------
@@ -83,6 +87,7 @@
 //
 CCaWidgetStorageHandler::~CCaWidgetStorageHandler()
     {
+    iSoftwareRegistry.Close();
     iWidgets.ResetAndDestroy();
     iUpdatedIndexes.Close();
     }
@@ -105,6 +110,7 @@
 void CCaWidgetStorageHandler::AddL( const CCaWidgetDescription* aWidget )
     {
     CCaInnerEntry* entry = aWidget->GetEntryLC();
+    UpdateComponentIdL( aWidget->GetManifestFilePathName(), *entry );
     iStorage->AddL( entry );
     if( entry->GetFlags() & ERemovable )
         {
@@ -121,6 +127,7 @@
         TUint aEntryId )
     {
     CCaInnerEntry* entry = aWidget->GetEntryLC();
+    UpdateComponentIdL( aWidget->GetManifestFilePathName(), *entry );
     entry->SetId( aEntryId );
     if( !aWidget->IsMissing() && aWidget->IsUsed() )
         {
@@ -331,4 +338,52 @@
     return massStorageNotInUse;
     }
 
+// ----------------------------------------------------------------------------
+//
+// ----------------------------------------------------------------------------
+//
+
+void CCaWidgetStorageHandler::UpdateComponentIdL( 
+    const TDesC& aManifestFilePathName, 
+    CCaInnerEntry& aEntry ) const
+    {
+    RArray<TComponentId> componentIds;
+    CleanupClosePushL( componentIds );
+    
+    CComponentFilter* const fileNameFilter = CComponentFilter::NewLC();
+    fileNameFilter->SetFileL( aManifestFilePathName );
+    iSoftwareRegistry.GetComponentIdsL( componentIds, fileNameFilter );
+
+    CleanupStack::PopAndDestroy( fileNameFilter );
+    
+    if ( componentIds.Count() == 1 )
+        {
+        RBuf newComponentId;
+        newComponentId.CleanupClosePushL();
+        newComponentId.CreateL( sizeof(TComponentId) + 1 );
+        newComponentId.AppendNum( componentIds[0] );
+        
+        RBuf oldComponentId;
+        oldComponentId.CleanupClosePushL();
+        oldComponentId.CreateL( KCaMaxAttrValueLen );
+        
+        const TBool componentIdAttributeFound = 
+            aEntry.FindAttribute( KCaComponentId, oldComponentId );
+              
+        if ( !componentIdAttributeFound 
+            || oldComponentId.Compare( newComponentId ) != 0 )
+            {
+            // 'add' or 'update' the component id attribute value
+            aEntry.AddAttributeL( KCaComponentId, 
+                newComponentId );
+            }
+        
+        CleanupStack::PopAndDestroy( &oldComponentId );
+        CleanupStack::PopAndDestroy( &newComponentId );
+        }
+
+    CleanupStack::PopAndDestroy( &componentIds );
+    }
+
+
 //  End of File