idlefw/plugins/mcsplugin/publisher/src/mcsplugindata.cpp
branchRCL_3
changeset 19 edd621764147
parent 16 b276298d5729
child 23 ace62b58f4b2
--- a/idlefw/plugins/mcsplugin/publisher/src/mcsplugindata.cpp	Tue Apr 27 16:57:49 2010 +0300
+++ b/idlefw/plugins/mcsplugin/publisher/src/mcsplugindata.cpp	Tue May 11 16:30:05 2010 +0300
@@ -75,6 +75,7 @@
 // ---------------------------------------------------------------------------
 //
 CMCSData::CMCSData()
+    :iDirty( ETrue )
     {
     }
 
@@ -229,43 +230,67 @@
     RPointerArray<CItemMap> settings;
     CleanupResetAndDestroyPushL( settings );
 
-    iPluginSettings->GetSettingsL( iInstanceUid, settings );
-    TInt count = settings.Count();
+    User::LeaveIfError( iPluginSettings->GetSettingsL( iInstanceUid, settings ) );
+    if ( settings.Count() <= 0 )
+        {
+        User::Leave( KErrNotFound );
+        }
+
     TBool wasEmpty = !iData.Count();
     
-    for ( TInt i = 0; i < count; i++ )
+    for ( TInt i = 0; i < settings.Count(); i++ )
        {
         CItemMap* itemMap = settings[ i ];
+        
+        // get properties
         RPointerArray<HSPluginSettingsIf::CPropertyMap>& properties
             = itemMap->Properties();
+        
         CMCSData* data = GetMenuDataL( properties );
-
+        CleanupStack::PushL( data );
         if ( wasEmpty )
             {
             // list of shortcut slot was empty
-            // we append the shortcut data slots one-by-one to the list
+            // we append the shortcut data slots one-by-one to the list            
             data->SetDirty( ETrue );
             iData.AppendL( data );
+            CleanupStack::Pop( data );
             }
         else 
             {
             // check for updates in existing shortcut data slot
             // if menuitem id has changed, replace the item and 
             // set as dirty
-            TInt id = -1;
-            id = iData[ i ]->MenuItem().Id();
+            TInt id( iData[ i ]->MenuItem().Id() );
             
-            if ( data->MenuItem().Id() != id )
+            // id of all bookmarks is zero so name has to be check
+            // in case of bookmark has changed
+            if ( id >= 0 && ( data->MenuItem().Id() != id ||
+                    ( id == 0 && data->Name().CompareF(
+                            iData[ i ]->Name() ) != 0 ) ) )
                 {
                 data->SetDirty( ETrue );
                 CMCSData* oldData = iData[i];
                 iData.Remove( i );
                 delete oldData;
+                
                 iData.InsertL( data, i );
+                CleanupStack::Pop( data );
+                }
+            else
+                {
+                CleanupStack::PopAndDestroy( data );
                 }
             }
         }
-
+    
+    // Leave if there isn't any data filled into array as there isn't
+    // anything shortcut to publish on homescreen.
+    if ( iData.Count() <= 0 ) 
+        {
+        User::Leave( KErrNotFound );
+        }
+    
     // Cleanup.
     CleanupStack::PopAndDestroy(); // settings
     }
@@ -308,12 +333,18 @@
 // Gets the menu item from engine using the setting properties as filter
 // ---------------------------------------------------------------------------
 //
-CMCSData* CMCSPluginData::GetMenuDataL( RPointerArray<HSPluginSettingsIf::CPropertyMap>& aProperties )
+CMCSData* CMCSPluginData::GetMenuDataL( 
+        RPointerArray<HSPluginSettingsIf::CPropertyMap>& aProperties )
     {
+    if ( aProperties.Count() <= 0 )
+		{
+		User::Leave( KErrArgument );
+		}
+
     TPtrC8 type;
-    TPtrC8 uid;
-    TPtrC8 view;
-    TPtrC8 param;
+	TPtrC8 uid;
+	TPtrC8 view;
+	TPtrC8 param;
     
     // first we need to check the item type
     for ( TInt i = 0; i < aProperties.Count(); i++ )
@@ -495,8 +526,11 @@
     if ( aIndex >= 0 && aIndex < settingItems.Count() )
         {
         CItemMap* itemMap = settingItems[ aIndex ];
-        RPointerArray<HSPluginSettingsIf::CPropertyMap> properties;
-        properties = itemMap->Properties();
+        
+        // get properties
+        RPointerArray<HSPluginSettingsIf::CPropertyMap>& properties
+            = itemMap->Properties();
+
         for ( TInt i = 0; i < properties.Count(); i++ )
             {
             if ( properties[ i ]->Name() == KProperNameType )