webengine/widgetregistry/Server/src/WidgetRegistry.cpp
changeset 36 0ed94ceaa377
parent 27 60c5402cb945
child 37 cb62a4f66ebe
--- a/webengine/widgetregistry/Server/src/WidgetRegistry.cpp	Tue Nov 24 09:02:20 2009 +0200
+++ b/webengine/widgetregistry/Server/src/WidgetRegistry.cpp	Thu Dec 17 09:20:16 2009 +0200
@@ -29,6 +29,7 @@
 #include <libc/stdlib.h>
 #include <libxml2_parser.h>
 #include <libxml2_tree.h>
+#include "WidgetMMCHandler.h"
 #include <xmlengxestd.h>
 #include "UidAllocator.h"
 #if defined( BRDO_WRT_SECURITY_MGR_FF )
@@ -183,13 +184,14 @@
 CWidgetRegistry::~CWidgetRegistry()
     {
     iEntries.ResetAndDestroy();
+    iOldEntries.ResetAndDestroy();
     iUsedUids.Close();
     // iFs not owned
     iAppArch.Close();
     delete iInstaller;
     iLangDirList.ResetAndDestroy();
+    delete iMMCHandler;
     delete iXmlProcessor;
-	delete iApaAppListNotifier;
     iFs.Close();
     LOG_DESTRUCT;
     }
@@ -250,7 +252,8 @@
     LOG1( "ConstructL internalize done, registry count %d",
               iEntries.Count() );
     LOG_CLOSE;
-    iApaAppListNotifier = CApaAppListNotifier::NewL(this,CActive::EPriorityStandard);
+    iMMCHandler = CWidgetMMCHandler::NewL( *this, iFs );
+    iMMCHandler->Start();
     }
 
 // ============================================================================
@@ -384,6 +387,29 @@
     }
 
 // ============================================================================
+// CWidgetRegistry::GetWidgetOldEntry()
+// Get the widget entry from iOldEntrys array
+//
+// @since 3.1
+// ============================================================================
+//
+TInt CWidgetRegistry::GetWidgetOldEntry(
+    const TUid& aUid,
+    CWidgetEntry*& aEntry) const
+    {
+    for(TInt i = 0;i < iOldEntries.Count();i++)
+        {
+        CWidgetEntry* entry = iOldEntries[i];
+        if ( TUid::Uid( (*entry)[EUid] ) == aUid )
+            {
+            aEntry = entry;
+            return i;
+            }
+        }
+    return -1;
+    }
+
+// ============================================================================
 // CWidgetRegistry::GetWidgetEntry()
 // Get the widget entry
 //
@@ -527,9 +553,15 @@
     // internal dirty flag, will be copied to arg dirty flag at
     // end if no leave occurs
     TBool dirtyFlag = EFalse;
-
-    // empty the registry
-    iEntries.ResetAndDestroy();
+    
+    // Copy the entries so we are able to use them later
+    // iOldEntries owns the data and is responcible to ResetAndDestroy()
+    for ( TInt i = 0; i < iEntries.Count(); i++ )
+        {
+        iOldEntries.Append( iEntries[i] );
+        }
+    // Only reset here as the iOldEntries owns the data
+    iEntries.Reset();
     iUsedUids.Reset();
 
     CleanupClosePushL( appArchList );
@@ -682,6 +714,8 @@
     CleanupStack::PopAndDestroy( 2, &appArchList );//appArchListFlags, appArchList
 
     aDirtyFlag = dirtyFlag;
+    // Reset and Destroy entries in iOldEntries array
+    iOldEntries.ResetAndDestroy();
     LOG1( "Internalize done, dirty flag %d", (TInt)dirtyFlag );
     LOG_CLOSE;
     }
@@ -712,15 +746,15 @@
     readStream.Attach( file );
 
     TInt error = KErrNone;
-    TInt entryCount = 0;
+    TInt entryCount = 0,errorCount =0;
     TRAP( error, entryCount = readStream.ReadInt32L() );
     // TODO should limit entryCount to something like 1024
     // for each entry in the registry file
     for ( TInt i = 0 ; i < entryCount; i++ )
         {
         CWidgetEntry* entry = CWidgetEntry::NewL();
-        CleanupStack::PushL( entry );
-
+        // push as delete entry so if we leave it will be handled
+        CleanupDeletePushL( entry );
         // extract one entry
         TRAP( error,
               entry->InternalizeBinaryL( readStream ) );
@@ -764,6 +798,12 @@
                               uidInt, uidInt );
                     }
                 }
+            else
+                {
+                // Pop and delete the un-needed entry so it is not left behind.
+                errorCount++; 
+                CleanupStack::PopAndDestroy( entry );                
+                }
             }
         else
             {
@@ -773,6 +813,10 @@
         } // for
 
     CleanupStack::PopAndDestroy( 2, &file ); // readStream, file
+    if ( errorCount != 0 )
+        {
+        User::Leave(KErrGeneral);
+        }
     }
 
 // ============================================================================
@@ -867,7 +911,16 @@
                                                   aDirtyFlag );
                         }
                     if ( NULL != entry )
-                        {
+                        { 
+                        CWidgetEntry* entry1 = NULL;
+                        TInt uid = (*entry)[EUid];
+                        TInt pos  = GetWidgetOldEntry( TUid::Uid( uid ), entry1 );
+                        if ( pos != -1 )
+                            {
+                            entry->SetActive((iOldEntries[pos]->ActiveL()));
+                            entry->SetFullView((iOldEntries[pos]->GetFullViewState()));
+                            entry->SetMiniView((iOldEntries[pos]->GetMiniViewState()));
+                            }
                         TRAP( error, InsertL( entry ) );
                         if ( KErrNone != error )
                             {
@@ -2244,24 +2297,4 @@
         }
     LOG( "AppArchListConsistency done" );
     }
-
-void CWidgetRegistry::HandleAppListEvent(TInt aEvent)
-    {
-    TBool dirtyFlag = EFalse;
-    TInt parseError = KErrNone;
-    // Assume usual case and things are consistent
-    // and the registry entry file can be parsed and used.
-    TRAPD( error, InternalizeL( EFalse,
-                                EFalse,
-                                dirtyFlag,
-                                parseError ) );
-    if ( KErrNone == error )
-        {
-        // internalize consistency enforcement may have altered registry
-        if ( dirtyFlag )
-            {
-            TRAP_IGNORE( ExternalizeL(); );
-            }
-        }
-    }
 // End of File