contentstorage/casrv/caappscanner/src/casrvappscanner.cpp
changeset 94 dbb8300717f7
parent 93 82b66994846c
child 96 5d243a69bdda
--- a/contentstorage/casrv/caappscanner/src/casrvappscanner.cpp	Fri Apr 30 15:22:08 2010 +0300
+++ b/contentstorage/casrv/caappscanner/src/casrvappscanner.cpp	Fri May 14 17:24:44 2010 +0300
@@ -20,6 +20,7 @@
 #include <swi/sisregistrysession.h>
 #include <swi/sisregistryentry.h>
 #include <swi/sisregistrypackage.h>
+#include <usif/scr/screntries.h>
 #include <WidgetRegistryClient.h>
 
 #include "cadef.h"
@@ -33,7 +34,9 @@
 #include "caarraycleanup.inl"
 #include "castorageproxy.h"
 
+#include "caarraycleanup.inl"
 
+using namespace Usif;
 
 // ==================== LOCAL FUNCTIONS ====================
 
@@ -66,7 +69,7 @@
 // ==================== MEMBER FUNCTIONS ====================
 
 // ---------------------------------------------------------
-// CCaSrvAppScanner::NewL
+//
 // ---------------------------------------------------------
 //
 CCaSrvAppScanner* CCaSrvAppScanner::NewL( CCaStorageProxy& aCaStorageProxy,
@@ -81,12 +84,13 @@
     }
 
 // ---------------------------------------------------------
-// CCaSrvAppScanner::~CCaSrvAppScanner
+//
 // ---------------------------------------------------------
 //
 CCaSrvAppScanner::~CCaSrvAppScanner()
     {
     Cancel();
+    iSoftwareRegistry.Close();
     iApaLsSession.Close();
     iInstalledPackages.Close();
     delete iInstallNotifier;
@@ -96,7 +100,7 @@
     }
 
 // ---------------------------------------------------------
-// CCaSrvAppScanner::CCaSrvAppScanner
+//
 // ---------------------------------------------------------
 //
 CCaSrvAppScanner::CCaSrvAppScanner( CCaStorageProxy& aCaStorageProxy,
@@ -108,7 +112,7 @@
     }
 
 // ---------------------------------------------------------
-// CCaSrvAppScanner::ConstructL
+//
 // ---------------------------------------------------------
 //
 void CCaSrvAppScanner::ConstructL()
@@ -117,7 +121,7 @@
     TFileName path;
     User::LeaveIfError( iFs.PrivatePath( path ) );
     TUint attribute;
-    if( iFs.Att( path, attribute) == KErrNotFound )
+    if( iFs.Att( path, attribute ) == KErrNotFound )
         {
         TInt mdRes = iFs.MkDirAll( path );
         if ( mdRes != KErrNone )
@@ -125,10 +129,8 @@
             User::Leave( mdRes );
             }
         }
-    iMmcHistory = new (ELeave) CCaSrvMmcHistory();
+    iMmcHistory = CCaSrvMmcHistory::NewL();
     iMmcHistory->LoadL( iFs, KCaMmcHistoryFname() );
-    // The notifier has its own session to apparc, instead of taking
-    // it as argument... :(
     iNotifier = CApaAppListNotifier::NewL(
             this, CActive::EPriorityStandard );
     iInstallNotifier = CCaInstallNotifier::NewL(
@@ -136,6 +138,7 @@
 
     User::LeaveIfError( iApaLsSession.Connect() );
     User::LeaveIfError( iApaLsSession.GetAllApps() ); // This is async.
+    User::LeaveIfError( iSoftwareRegistry.Connect() );
     iApaLsSession.RegisterListPopulationCompleteObserver( iStatus );
     iCollectionDownloadId = 0;
     iAllCollectionId = 0;
@@ -143,12 +146,12 @@
     }
 
 // ---------------------------------------------------------
-// CCaSrvAppScanner::RunL
+//
 // ---------------------------------------------------------
 //
 void CCaSrvAppScanner::RunL()
     {
-    User::LeaveIfError( iStatus.Int() ); // Handle errors in RunL.
+    User::LeaveIfError( iStatus.Int() );
     // AppArc app scan complete, we have the app list.
     UpdateApplicationEntriesL();
     InstallationNotifyL();
@@ -156,7 +159,7 @@
     }
 
 // ---------------------------------------------------------
-// CCaSrvAppScanner::DoCancel
+//
 // ---------------------------------------------------------
 //
 void CCaSrvAppScanner::DoCancel()
@@ -165,43 +168,42 @@
     }
 
 // ---------------------------------------------------------
-// CCaSrvAppScanner::RunError
+//
 // ---------------------------------------------------------
 //
 TInt CCaSrvAppScanner::RunError( TInt /*aError*/)
     {
     // Ignore the error (what else could we do?).
-    // When next AppArc update occurs, we will run again.
+    // When next update occurs, we will run again.
     return KErrNone;
     }
 
 // ---------------------------------------------------------
-// CCaSrvAppScanner::UpdateApplicationItemL
+//
 // ---------------------------------------------------------
 //
 void CCaSrvAppScanner::UpdateApplicationEntryL(
         RPointerArray<CCaInnerEntry>& aCaEntries,
-        const TCaAppAtributes& aApaItem, TUint aMmcId )
+        TUint aAppUid, TUint aMmcId )
     {
-    TInt appuid = aApaItem.GetUid();
     RPointerArray<CCaInnerEntry> resultArray;
     CleanupResetAndDestroyPushL( resultArray );
-    GetCaAppEntriesL( appuid, resultArray );
+    GetCaAppEntriesL( aAppUid, resultArray );
 
     // This app is not in the storage, add it now.
     // We don't add hidden items, there are too many of them!
     // do not display Menu app
     if( !resultArray.Count() )
         {
-        AddAppEntryL( appuid, aMmcId );
+        AddAppEntryL( aAppUid, aMmcId );
         }//if
 
     // "removable", "missing" and "visible"  flags update
     for( TInt j = 0; j < resultArray.Count(); j++ )
         {
-        //we need to handle first run of appscanner,
-        //there might be some incorrect data in content xml file
-        //if this will have impact on performance we may run this methods only at start up
+        //We need to handle first run of appscanner,
+        //there might be some incorrect data. If this will have impact
+        //on performance we may run this methods only at start up.
 
         UpdateAppEntryL( resultArray[j], aMmcId );
         TInt index = aCaEntries.Find( resultArray[j],
@@ -216,7 +218,7 @@
     }
 
 // ---------------------------------------------------------
-// CCaSrvAppScanner::UpdateAppEntryL
+//
 // ---------------------------------------------------------
 //
 void CCaSrvAppScanner::UpdateAppEntryL( CCaInnerEntry* aEntry, TUint aMmcId )
@@ -225,9 +227,9 @@
     TBool missingVisibleFlagChanged =
         HandleMissingVisibleFlagsUpdate( aEntry );
     toUpdate = missingVisibleFlagChanged || toUpdate;
-    toUpdate = HandleLockDeleteFlagUpdateL( aEntry ) || toUpdate;
+    toUpdate = HandleRemovableVisibleFlagsUpdateL( aEntry ) || toUpdate;
     toUpdate = SetApaAppInfoL( aEntry ) || toUpdate;
-    
+
     if( iInstalledPackages.Find( aEntry->GetUid() ) != KErrNotFound )
         {
         AddEntryToDownloadedCollectionL( aEntry->GetId() );
@@ -246,6 +248,142 @@
         RemoveFromInstalledPackages( aEntry->GetUid() );
         }
     }
+
+// ---------------------------------------------------------
+//
+// ---------------------------------------------------------
+//
+TBool CCaSrvAppScanner::HandleMmcAttrUpdateL(
+        CCaInnerEntry* aItem, TUint aMmcId )
+    {
+    TBool toUpdate( ETrue );
+    if( IsInMmcL( TUid::Uid( aItem->GetUid() ) ) )
+        {
+        //app is instaled on mmc - KCaAttrMmcId attribute update
+        RBuf uidString;
+        uidString.CleanupClosePushL();
+        uidString.CreateL(KUidChars);
+        uidString.Format( KHexFormat, aMmcId );
+        aItem->AddAttributeL( KCaAttrMmcId, uidString );
+        CleanupStack::PopAndDestroy( &uidString );
+        }
+    else if ( IsInMassStorageL( TUid::Uid( aItem->GetUid() ) ) )
+        {
+        //its app installed on mass storage, we need to leave it
+        //in case of connecting usb in mass storage mode
+        aItem->AddAttributeL( KCaAttrMmcId, KCaMassStorage );
+        }
+    else
+        {
+        RBuf attrVal;
+        attrVal.CleanupClosePushL();
+        attrVal.CreateL( KCaMaxAttrValueLen );
+        if( aItem->FindAttribute( KCaAttrMmcId, attrVal ) )
+            {
+            aItem->RemoveAttributeL( KCaAttrMmcId );
+            }
+        else
+            {
+            toUpdate = EFalse;
+            }
+        CleanupStack::PopAndDestroy( &attrVal );
+        //its installed on c: drive - remove attribute
+        }
+    return toUpdate;
+    }
+
+// ---------------------------------------------------------
+//
+// ---------------------------------------------------------
+//
+void CCaSrvAppScanner::InstallationNotifyL()
+    {
+    for( TInt i = iInstalledPackages.Count() - 1; i >= 0; i-- )
+        {
+        NotifyL( iInstalledPackages[i] );
+        iInstalledPackages.Remove( i );
+        }
+    }
+
+// ---------------------------------------------------------
+//
+// ---------------------------------------------------------
+//
+void CCaSrvAppScanner::UpdateApplicationEntriesL()
+    {
+    TUint currentMmcId = UpdateMmcHistoryL();
+    // get all Content arsenal enties with type application
+    RPointerArray<CCaInnerEntry> resultArray;
+    CleanupResetAndDestroyPushL( resultArray );
+    GetCaAppEntriesL( resultArray );
+    HandleHsAppEntryL( resultArray );
+    RemoveSatAppL( resultArray );
+
+    RArray<TUint> appUids;
+    CleanupClosePushL( appUids );
+    GetApaItemsL( appUids );
+    RemoveApp( appUids, KSatUid.iUid );
+    RemoveApp( appUids, KHsAppUid.iUid );
+
+    //for every item in apaAndCrItems array
+    for( TInt i = 0; i < appUids.Count(); i++ )
+        {
+        // if there was leave for any item we ignore it
+        // and proceed to the next one
+        TRAP_IGNORE(UpdateApplicationEntryL(
+                resultArray, appUids[i], currentMmcId));
+        }
+    // Here the big list with items that refer to missing apps.
+    HandleMissingItemsL( resultArray );
+    CleanupStack::PopAndDestroy( &appUids );
+    CleanupStack::PopAndDestroy( &resultArray );
+    }
+
+// ---------------------------------------------------------
+//
+// ---------------------------------------------------------
+//
+TBool CCaSrvAppScanner::HandleRemovableVisibleFlagsUpdateL(
+        CCaInnerEntry* aItem )
+    {
+    TBool toChange( EFalse );
+    if( ( aItem->GetFlags() & EVisible ) && IsInRomL( aItem->GetUid() ) )
+        {
+        if( ( aItem->GetFlags() & ERemovable ) != 0 )
+            {
+            aItem->SetFlags( aItem->GetFlags() & ~ERemovable );
+            toChange = ETrue;
+            }
+        }
+    else
+        {
+        if( ( aItem->GetFlags() & ERemovable ) == 0 )
+            {
+            aItem->SetFlags( aItem->GetFlags() | ERemovable );
+            toChange = ETrue;
+            }
+        }
+    return toChange;
+    }
+
+// ---------------------------------------------------------
+//
+// ---------------------------------------------------------
+//
+TBool CCaSrvAppScanner::HandleMissingVisibleFlagsUpdate(
+        CCaInnerEntry* aItem )
+    {
+    TBool ret( EFalse );
+    if( aItem->GetFlags() & EMissing ||
+        !( aItem->GetFlags() & EVisible ) )
+        {
+        //application found so we unset "missing" and set "visible" flags
+        aItem->SetFlags( aItem->GetFlags() & ~EMissing | EVisible );
+        ret = ETrue;
+        }
+    return ret;
+    }
+
 // ---------------------------------------------------------
 //
 // ---------------------------------------------------------
@@ -277,144 +415,12 @@
     }
 
 // ---------------------------------------------------------
-// CCaSrvAppScanner::HandleMmcAttrUpdateL
-// ---------------------------------------------------------
 //
-TBool CCaSrvAppScanner::HandleMmcAttrUpdateL(
-        CCaInnerEntry* aItem, TUint aMmcId )
-    {
-    TBool toUpdate( ETrue );
-    if( IsInMmcL( TUid::Uid( aItem->GetUid() ) ) )
-        {
-        //app is instaled on mmc - KCaAttrMmcId attribute update
-        TBuf<KUidChars> uidString;
-        uidString.Format( KHexFormat, aMmcId );
-        aItem->AddAttributeL( KCaAttrMmcId, uidString );
-        }
-    else if ( IsInMassStorageL( TUid::Uid( aItem->GetUid() ) ) )
-        {
-        //its app installed on mass storage, we need to leave it
-        //in case of connecting usb in mass storage mode
-        aItem->AddAttributeL( KCaAttrMmcId, KCaMassStorage );
-        }
-    else
-        {
-        RBuf attrVal;
-        attrVal.CleanupClosePushL();
-        attrVal.CreateL( KCaMaxAttrValueLen );
-        if( aItem->FindAttribute( KCaAttrMmcId, attrVal ) )
-            {
-            aItem->RemoveAttributeL( KCaAttrMmcId );
-            }
-        else
-            {
-            toUpdate = EFalse;
-            }
-        CleanupStack::PopAndDestroy( &attrVal );
-        //its installed on c: drive - remove attribute
-        }
-    return toUpdate;
-    }
-
-// ---------------------------------------------------------
-// CCaSrvAppScanner::UpdateApplicationItemsL
-// ---------------------------------------------------------
-//
-void CCaSrvAppScanner::InstallationNotifyL()
-    {
-    for( TInt i = iInstalledPackages.Count() - 1; i >= 0; i-- )
-        {
-        NotifyL( iInstalledPackages[i] );
-        iInstalledPackages.Remove( i );
-        }
-    }
-
-// ---------------------------------------------------------
-// CCaSrvAppScanner::UpdateApplicationItemsL
 // ---------------------------------------------------------
 //
-void CCaSrvAppScanner::UpdateApplicationEntriesL()
-    {
-    TUint currentMmcId = UpdateMmcHistoryL();
-    // get all Content arsenal enties with type application
-    RPointerArray<CCaInnerEntry> resultArray;
-    CleanupResetAndDestroyPushL( resultArray );
-    GetCaAppEntriesL( resultArray );
-    HandleHsAppEntryL( resultArray );
-    RemoveSatAppL( resultArray );
-
-    RArray<TCaAppAtributes> apaItems;
-    CleanupClosePushL( apaItems );
-    GetApaItemsL( apaItems );
-    RemoveApp( apaItems, KSatUid.iUid );
-    RemoveApp( apaItems, KHsAppUid.iUid );
-
-    //for every item in apaAndCrItems array
-    for( TInt i = 0; i < apaItems.Count(); i++ )
-        {
-            // if there was leave for any item we ignore it
-            // and proceed to the next one
-            TRAP_IGNORE(UpdateApplicationEntryL(
-                            resultArray, apaItems[i], currentMmcId));
-        }
-    // Here the big list cwith items that refer to missing apps.
-    HandleMissingItemsL( resultArray );
-    CleanupStack::PopAndDestroy( &apaItems );
-    CleanupStack::PopAndDestroy( &resultArray );
-    }
-
-// ---------------------------------------------------------
-// CCaSrvAppScanner::HandleLockDeleteFlagUpdateL
-// ---------------------------------------------------------
-//
-TBool CCaSrvAppScanner::HandleLockDeleteFlagUpdateL( CCaInnerEntry* aItem )
+void CCaSrvAppScanner::RemoveApp( RArray<TUint>& aArray, TInt32 aUid )
     {
-    TBool toChange( EFalse );
-    TBool isVisible = ( ( aItem->GetFlags() & EVisible ) != 0 );
-    if( isVisible && IsInRomL( aItem->GetUid() ) )
-        {
-        if( ( aItem->GetFlags() & ERemovable ) != 0 )
-            {
-            aItem->SetFlags( aItem->GetFlags() & ~ERemovable );
-            toChange = ETrue;
-            }
-        }
-    else
-        {
-        if( ( aItem->GetFlags() & ERemovable ) == 0 )
-            {
-            aItem->SetFlags( aItem->GetFlags() | ERemovable );
-            toChange = ETrue;
-            }
-        }
-    return toChange;
-    }
-
-// ---------------------------------------------------------
-// CCaSrvAppScanner::HandleMissingFlagUpdateL
-// ---------------------------------------------------------
-//
-TBool CCaSrvAppScanner::HandleMissingVisibleFlagsUpdate( CCaInnerEntry* aItem )
-    {
-    TBool ret( EFalse );
-    if( aItem->GetFlags() & EMissing ||
-        !( aItem->GetFlags() & EVisible ) )
-        {
-        //application found so we unset "missing" and set "visible" flags
-        aItem->SetFlags( aItem->GetFlags() & ~EMissing | EVisible );
-        ret = ETrue;
-        }
-    return ret;
-    }
-
-// ---------------------------------------------------------
-// CCaSrvAppScanner::RemoveApp
-// ---------------------------------------------------------
-//
-void CCaSrvAppScanner::RemoveApp( RArray<TCaAppAtributes>& aArray, TInt32 aUid )
-    {
-    TCaAppAtributes app( aUid );
-    TInt id = aArray.Find( app, TCaAppAtributes::MatchItems );
+    TInt id = aArray.Find( aUid );
     if( id != KErrNotFound )
         {
         aArray.Remove( id );
@@ -422,7 +428,7 @@
     }
 
 // ---------------------------------------------------------
-// CCaSrvAppScanner::RemoveSatApp
+//
 // ---------------------------------------------------------
 //
 void CCaSrvAppScanner::RemoveSatAppL( RPointerArray<CCaInnerEntry>& aArray )
@@ -440,10 +446,11 @@
     }
 
 // ---------------------------------------------------------
-// CCaSrvAppScanner::HandleHsAppEntryL
+//
 // ---------------------------------------------------------
 //
-void CCaSrvAppScanner::HandleHsAppEntryL( RPointerArray<CCaInnerEntry>& aArray )
+void CCaSrvAppScanner::HandleHsAppEntryL(
+        RPointerArray<CCaInnerEntry>& aArray )
     {
     CCaInnerEntry* appEntry = CCaInnerEntry::NewLC();
     appEntry->SetUid( KHsAppUid.iUid );
@@ -476,12 +483,12 @@
 
 
 // ---------------------------------------------------------
-// CCaSrvAppScanner::GetApaItemsL
+//
 // ---------------------------------------------------------
 //
-void CCaSrvAppScanner::GetApaItemsL( RArray<TCaAppAtributes>& aArray )
+void CCaSrvAppScanner::GetApaItemsL( RArray<TUint>& aArray )
     {
-    TApaAppInfo* appInfo = new(ELeave) TApaAppInfo();
+    TApaAppInfo* appInfo = new ( ELeave ) TApaAppInfo();
     CleanupStack::PushL(appInfo);
     TApaAppCapabilityBuf appCap;
 
@@ -495,22 +502,22 @@
         // "Hidden" status according to AppArc.
         if( !appCap().iAppIsHidden )
             {
-            TCaAppAtributes appAtributes( appInfo->iUid.iUid );
-            aArray.AppendL( appAtributes );
+            aArray.AppendL( appInfo->iUid.iUid );
             }
         }
     CleanupStack::PopAndDestroy(appInfo);
     }
 
 // ---------------------------------------------------------
-// CCaSrvAppScanner::GetMcsItemsL
+//
 // ---------------------------------------------------------
 //
 void CCaSrvAppScanner::GetCaAppEntriesL(
         RPointerArray<CCaInnerEntry>& aArray )
     {
     CCaInnerQuery* allAppQuery = CCaInnerQuery::NewLC();
-    CDesC16ArrayFlat* appType = new ( ELeave ) CDesC16ArrayFlat( 1 );
+    CDesC16ArrayFlat* appType =
+            new ( ELeave ) CDesC16ArrayFlat( KGranularityOne );
     CleanupStack::PushL( appType );
     appType->AppendL( KCaTypeApp );
     allAppQuery->SetEntryTypeNames( appType );
@@ -520,7 +527,7 @@
     }
 
 // ---------------------------------------------------------
-// CCaSrvAppScanner::GetMcsItemsL
+//
 // ---------------------------------------------------------
 //
 TInt CCaSrvAppScanner::GetCollectionDownloadIdL()
@@ -530,7 +537,8 @@
         RPointerArray<CCaInnerEntry> resultArray;
         CleanupResetAndDestroyPushL( resultArray );
         CCaInnerQuery* allAppQuery = CCaInnerQuery::NewLC();
-        CDesC16ArrayFlat* appType = new ( ELeave ) CDesC16ArrayFlat( 1 );
+        CDesC16ArrayFlat* appType =
+                new ( ELeave ) CDesC16ArrayFlat( KGranularityOne );
         CleanupStack::PushL( appType );
         appType->AppendL( KCaTypeCollectionDownload );
         allAppQuery->SetEntryTypeNames( appType );
@@ -547,7 +555,7 @@
     }
 
 // ---------------------------------------------------------
-// CCaSrvAppScanner::GetAllCollectionIdL
+//
 // ---------------------------------------------------------
 //
 TInt CCaSrvAppScanner::GetAllCollectionIdL()
@@ -556,7 +564,7 @@
         {
         CCaInnerQuery *getAllCollectionIdQuery = CCaInnerQuery::NewLC();
         CDesC16ArrayFlat *typenameArray = new(ELeave) CDesC16ArrayFlat(
-                KDefaultGranularity );
+                KGranularityOne );
         CleanupStack::PushL( typenameArray );
         typenameArray->AppendL( KCaTypeMenuCollections );
         getAllCollectionIdQuery->SetEntryTypeNames( typenameArray );
@@ -577,7 +585,7 @@
     }
 
 // ---------------------------------------------------------
-// CCaSrvAppScanner::GetMcsItemsL
+//
 // ---------------------------------------------------------
 //
 void CCaSrvAppScanner::GetCaAppEntriesL( TInt aUid,
@@ -590,7 +598,7 @@
     }
 
 // ---------------------------------------------------------
-// CCaSrvAppScanner::HandleAppListEvent
+//
 // ---------------------------------------------------------
 //
 void CCaSrvAppScanner::HandleAppListEvent( TInt /*aEvent*/)
@@ -604,7 +612,7 @@
     }
 
 // ---------------------------------------------------------
-// CCaSrvAppScanner::HandleInstallNotifyL
+//
 // ---------------------------------------------------------
 //
 void CCaSrvAppScanner::HandleInstallNotifyL( TInt aUid )
@@ -614,8 +622,8 @@
     CleanupClosePushL( uids );
 
     Swi::RSisRegistrySession iSisRegSession;
+    CleanupClosePushL( iSisRegSession );
     User::LeaveIfError( iSisRegSession.Connect() );
-    CleanupClosePushL( iSisRegSession );
 
     // Open sis package entry related to aUid
     Swi::RSisRegistryEntry packageEntry;
@@ -626,7 +634,7 @@
 
         // Get packageEntry's embedded sis'
         RPointerArray<Swi::CSisRegistryPackage> embedded;
-        CleanupClosePushL( embedded );
+        CleanupResetAndDestroyPushL( embedded );
         packageEntry.EmbeddedPackagesL( embedded );
         if( embedded.Count() )
             {
@@ -642,7 +650,6 @@
             // of changes in apps included in packageEntry
             NotifyL( packageEntry );
             }
-        embedded.ResetAndDestroy();
         CleanupStack::PopAndDestroy( &embedded );
         CleanupStack::PopAndDestroy( &packageEntry );
         }
@@ -651,7 +658,7 @@
     }
 
 // ---------------------------------------------------------
-// CCaSrvAppScanner::NotifyL
+//
 // ---------------------------------------------------------
 //
 void CCaSrvAppScanner::NotifyL( Swi::RSisRegistryEntry & aPackageEntry )
@@ -672,7 +679,7 @@
     }
 
 // ---------------------------------------------------------
-// CCaSrvAppScanner::NotifyL
+//
 // ---------------------------------------------------------
 //
 void CCaSrvAppScanner::NotifyL( TInt aAppUid )
@@ -682,20 +689,22 @@
     CleanupResetAndDestroyPushL( resultArray );
     GetCaAppEntriesL( aAppUid, resultArray );
     if( resultArray.Count() && ( resultArray[0]->GetFlags() & EVisible ) )
-        {//TODO: this only for icons. This functionality should be change 
+        {//TODO: this only for icons. This functionality should be change
         iCaStorageProxy.AddL( resultArray[0] );
         }
     CleanupStack::PopAndDestroy( &resultArray );
     }
 
 // ---------------------------------------------------------
-// CCaSrvAppScanner::AddEntryToDownloadedCollectionL
+//
 // ---------------------------------------------------------
 //
 void CCaSrvAppScanner::AddEntryToDownloadedCollectionL( TInt aEntryId )
     {
-    TCaOperationParams params = { TCaOperationParams::EPrepend, GetCollectionDownloadIdL(), 0 // not used
-            };
+    TCaOperationParams params;
+    params.iOperationType = TCaOperationParams::EPrepend;
+    params.iGroupId = GetCollectionDownloadIdL();
+    params.iBeforeEntryId = 0; // Not used.
 
     RArray<TInt> entryIds;
     CleanupClosePushL( entryIds );
@@ -706,7 +715,7 @@
     }
 
 // ---------------------------------------------------------
-// CCaSrvAppScanner::AddEntryToPredefinedCollectionL
+//
 // ---------------------------------------------------------
 //
 void CCaSrvAppScanner::AddEntryToPredefinedCollectionL(
@@ -731,10 +740,10 @@
 
         RArray<TInt> entryIds;
         CleanupClosePushL( entryIds );
-        TInt entryId = aEntry->GetId();
-        entryIds.AppendL( entryId );
+        entryIds.AppendL( aEntry->GetId() );
         TCaOperationParams organizeParams;
         organizeParams.iBeforeEntryId = 0;
+        organizeParams.iOperationType = TCaOperationParams::EAppend;
 
         if( resultArrayItems.Count() )
             {
@@ -755,14 +764,12 @@
 
             if( aUpdate )
                 {
-                organizeParams.iOperationType = TCaOperationParams::EAppend;
                 iCaStorageProxy.OrganizeL( entryIds, organizeParams );
                 }
             }
 
         if( !aUpdate )
             {
-            organizeParams.iOperationType = TCaOperationParams::EAppend;
             iCaStorageProxy.OrganizeL( entryIds, organizeParams );
             }
 
@@ -773,7 +780,7 @@
     }
 
 // ---------------------------------------------------------
-// CCaSrvAppScanner::CreatePredefinedCollectionL
+//
 // ---------------------------------------------------------
 //
 TInt CCaSrvAppScanner::CreatePredefinedCollectionL( const TDesC& aGroupName )
@@ -783,9 +790,7 @@
     innerEntry->SetEntryTypeNameL( KCaTypeCollection );
     innerEntry->SetRole( CCaInnerQuery::Group );
     innerEntry->AddAttributeL( KCaAppGroupName, aGroupName );
-    innerEntry->SetFlags( EVisible );
-    innerEntry->SetFlags( innerEntry->GetFlags() | ERemovable );
-    _LIT( KCollectionIconFileName, "qtg_large_applications_user");
+    innerEntry->SetFlags( EVisible | ERemovable );
     innerEntry->SetIconDataL( KCollectionIconFileName,
             KNullDesC, KNullDesC );
     iCaStorageProxy.AddL( innerEntry );
@@ -797,7 +802,7 @@
     }
 
 // ---------------------------------------------------------
-// CCaSrvAppScanner::AddCollectionToAllCollectionL
+//
 // ---------------------------------------------------------
 //
 void CCaSrvAppScanner::AddCollectionToAllCollectionL( TInt aCollectionId )
@@ -817,13 +822,15 @@
 
 
 // ---------------------------------------------------------
-// CCaSrvAppScanner::RemoveToDownloadedCollectionL
+//
 // ---------------------------------------------------------
 //
 void CCaSrvAppScanner::RemoveEntryFromDownloadedL( TInt aEntryId )
     {
-    TCaOperationParams params = { TCaOperationParams::ERemove, GetCollectionDownloadIdL(), 0 // not used
-            };
+    TCaOperationParams params;
+    params.iOperationType = TCaOperationParams::ERemove;
+    params.iGroupId = GetCollectionDownloadIdL();
+    params.iBeforeEntryId = 0; // Not Used
 
     RArray<TInt> entryIds;
     CleanupClosePushL( entryIds );
@@ -834,7 +841,7 @@
     }
 
 // ---------------------------------------------------------
-// CCaSrvAppScanner::ScheduleScan
+//
 // ---------------------------------------------------------
 //
 void CCaSrvAppScanner::ScheduleScan()
@@ -849,7 +856,7 @@
     }
 
 // ---------------------------------------------------------
-// CCaSrvAppScanner::AddAppItemL
+//
 // ---------------------------------------------------------
 //
 void CCaSrvAppScanner::AddAppEntryL( TUint aUid, TUint aCurrentMmcId )
@@ -863,7 +870,7 @@
     appEntry->SetRole( EItemEntryRole );
 
     SetApaAppInfoL( appEntry );
-    HandleLockDeleteFlagUpdateL( appEntry );
+    HandleRemovableVisibleFlagsUpdateL( appEntry );
     HandleMmcAttrUpdateL( appEntry, aCurrentMmcId );
 
     iCaStorageProxy.AddL( appEntry );
@@ -873,14 +880,14 @@
     if( iInstalledPackages.Find( aUid ) != KErrNotFound )
         {
         AddEntryToDownloadedCollectionL( appEntry->GetId() );
+        RemoveFromInstalledPackages( aUid );
         }
-    RemoveFromInstalledPackages( aUid );
 
     CleanupStack::PopAndDestroy( appEntry );
     }
 
 // ---------------------------------------------------------
-// CCaSrvAppScanner::RemoveFromInstalledPackages
+//
 // ---------------------------------------------------------
 //
 void CCaSrvAppScanner::RemoveFromInstalledPackages( TUint aUid )
@@ -893,58 +900,77 @@
     }
 
 // ---------------------------------------------------------------------------
-// CCaSrvAppScanner::IsMidletL
-// Checks if given app is midlet by reading the apptype uid (2nd uid)
+//
 // ---------------------------------------------------------------------------
 //
 TBool CCaSrvAppScanner::SetApaAppInfoL( CCaInnerEntry* aEntry )
     {
     TBool changed( EFalse );
-    TApaAppInfo info;
-    if( KErrNone == iSrvEngUtils.GetAppInfo( *aEntry, info ) )
+    TApaAppInfo* info = new ( ELeave ) TApaAppInfo();
+    CleanupStack::PushL(info);
+    if( KErrNone == iSrvEngUtils.GetAppInfo( *aEntry, *info ) )
         {
         RBuf attrVal;
         attrVal.CleanupClosePushL();
         attrVal.CreateL( KCaMaxAttrValueLen );
         aEntry->FindAttribute( KCaAttrLongName, attrVal );
-        if( attrVal.Compare( info.iCaption ) != KErrNone
-                || aEntry->GetText().Compare( info.iCaption )
+        if( attrVal.Compare( info->iCaption ) != KErrNone
+                || aEntry->GetText().Compare( info->iCaption )
                         != KErrNone )
             {
-            aEntry->SetTextL( info.iCaption );
-            aEntry->AddAttributeL( KCaAttrLongName, info.iCaption );
+            aEntry->SetTextL( info->iCaption );
+            aEntry->AddAttributeL( KCaAttrLongName, info->iCaption );
             changed = ETrue;
             }
+        
+        
+        if ( UpdateComponentIdL( *info, *aEntry ) )
+            {
+            changed = ETrue;
+            }
+        
         CleanupStack::PopAndDestroy( &attrVal );
-        // check if its java app and add attr for entrys
+        
+        // check if its java app and add attr for entries
         TUid appTypeUid;
-        if( KErrNone == iApaLsSession.GetAppType( appTypeUid, info.iUid ) )
+        if( KErrNone == iApaLsSession.GetAppType( appTypeUid, info->iUid ) )
             {
             if( appTypeUid == KMidletApplicationTypeUid )
                 {
-                aEntry->AddAttributeL( KCaAttrAppType, KCaAttrAppTypeValueJava );
-                aEntry->AddAttributeL( KCaAttrAppSettingsPlugin, KCaAttrJavaAppSettingsPluginValue );
+                aEntry->AddAttributeL(
+                        KCaAttrAppType,
+                        KCaAttrAppTypeValueJava );
+                aEntry->AddAttributeL(
+                        KCaAttrAppSettingsPlugin,
+                        KCaAttrJavaAppSettingsPluginValue );
                 }
             else if (appTypeUid == KCWRTApplicationTypeUid)
                 {
-                aEntry->AddAttributeL( KCaAttrAppType, KCaAttrAppTypeValueCWRT );
-                aEntry->AddAttributeL( KCaAttrAppWidgetUri, KCaAttrAppWidgetUriCWRTValue );
+                aEntry->AddAttributeL(
+                        KCaAttrAppType,
+                        KCaAttrAppTypeValueCWRT );
+                aEntry->AddAttributeL(
+                        KCaAttrAppWidgetUri,
+                        KCaAttrAppWidgetUriCWRTValue );
                 // web id should be taken from SCR when supported
                 RWidgetRegistryClientSession wrtSession;
                 CleanupClosePushL(wrtSession);
                 User::LeaveIfError( wrtSession.Connect());
                 TFileName bundleId;
-                wrtSession.GetWidgetBundleId(info.iUid, bundleId);
-                aEntry->AddAttributeL( KCaAttrAppWidgetParamWebAppId, bundleId );
+                wrtSession.GetWidgetBundleId(info->iUid, bundleId);
+                aEntry->AddAttributeL(
+                        KCaAttrAppWidgetParamWebAppId,
+                        bundleId );
                 CleanupStack::PopAndDestroy(&wrtSession);
                 }
             }
         }
+    CleanupStack::PopAndDestroy( info );
     return changed;
     }
 
 // ---------------------------------------------------------
-// CCaSrvAppScanner::HandleMissingItemsL
+//
 // ---------------------------------------------------------
 //
 void CCaSrvAppScanner::HandleMissingItemsL(
@@ -952,7 +978,6 @@
     {
     for( TInt i = 0; i < aCaEntries.Count(); i++ )
         {
-        const TInt id = aCaEntries[i]->GetId();
         RBuf attrVal;
         attrVal.CleanupClosePushL();
         attrVal.CreateL( KCaMaxAttrValueLen );
@@ -985,7 +1010,7 @@
     }
 
 // ---------------------------------------------------------
-// CCaSrvAppScanner::RemoveAppL
+//
 // ---------------------------------------------------------
 //
 void CCaSrvAppScanner::RemoveAppL( CCaInnerEntry* aAppEntry )
@@ -1018,13 +1043,17 @@
     {
     if( aEntry->GetFlags() & EVisible )
         {
-        aEntry->SetFlags( aEntry->GetFlags() & ~EVisible & ~EMissing & ~EUsed );
+        aEntry->SetFlags(
+                aEntry->GetFlags() &
+                ~EVisible &
+                ~EMissing &
+                ~EUsed );
         iCaStorageProxy.AddL( aEntry, EFalse, EItemDisappeared );
         }
     }
 
 // ---------------------------------------------------------
-// CCaSrvAppScanner::UpdateMmcHistoryL
+//
 // ---------------------------------------------------------
 //
 TUint CCaSrvAppScanner::UpdateMmcHistoryL()
@@ -1039,7 +1068,7 @@
     }
 
 // ---------------------------------------------------------
-// CCaSrvAppScanner::CurrentMmcId
+//
 // ---------------------------------------------------------
 //
 TUint CCaSrvAppScanner::CurrentMmcId() const
@@ -1047,8 +1076,7 @@
     // Get mmc id. Errors are ignored.
     TUint mmcId = 0;
     TInt mmcDrive;
-    TInt err;
-    err = DriveInfo::GetDefaultDrive(
+    TInt err = DriveInfo::GetDefaultDrive(
             DriveInfo::EDefaultRemovableMassStorage, mmcDrive );
     if( !err )
         {
@@ -1063,16 +1091,17 @@
     }
 
 // ---------------------------------------------------------
-// CCaSrvAppScanner::IsFileInDrive
+//
 // ---------------------------------------------------------
 //
 TBool CCaSrvAppScanner::IsFileInDrive(
-        const TDesC& aFileName,
-        const DriveInfo::TDefaultDrives& aDefaultDrive ) const
+    const TDesC& aFileName,
+    const DriveInfo::TDefaultDrives& aDefaultDrive ) const
+    {
+    TBool retVal( EFalse );
+    if ( aFileName.Length()>0 )
         {
-        if ( aFileName.Length() )
-            {
-            TInt mmcDrive;
+        TInt mmcDrive;
         TInt err = DriveInfo::GetDefaultDrive( aDefaultDrive, mmcDrive );
         if( !err )
             {
@@ -1080,15 +1109,15 @@
             err = RFs::CharToDrive( aFileName[0], fileDrive );
             if( !err && fileDrive == mmcDrive )
                 {
-                return ETrue;
+                retVal = ETrue;
                 }
             }
         }
-    return EFalse;
+    return retVal;
     }
 
 // ---------------------------------------------------------
-// CCaSrvAppScanner::IsAppInDriveL
+//
 // ---------------------------------------------------------
 //
 TBool CCaSrvAppScanner::IsAppInDriveL(
@@ -1096,7 +1125,7 @@
         const DriveInfo::TDefaultDrives& aDefaultDrive ) const
     {
     TBool ret( EFalse );
-    TApaAppInfo* appInfo = new( ELeave ) TApaAppInfo();
+    TApaAppInfo* appInfo = new ( ELeave ) TApaAppInfo();
     TInt err = iApaLsSession.GetAppInfo( *appInfo, aUid );
     if( !err && IsFileInDrive( appInfo->iFullName, aDefaultDrive ) )
         {
@@ -1107,7 +1136,7 @@
     }
 
 // ---------------------------------------------------------
-// CCaSrvAppScanner::IsInMmcL
+//
 // ---------------------------------------------------------
 //
 TBool CCaSrvAppScanner::IsInMmcL( const TUid aUid ) const
@@ -1116,7 +1145,7 @@
     }
 
 // ---------------------------------------------------------
-// CCaSrvAppScanner::IsInMassStorageL
+//
 // ---------------------------------------------------------
 //
 TBool CCaSrvAppScanner::IsInMassStorageL( const TUid aUid ) const
@@ -1125,7 +1154,7 @@
     }
 
 // ---------------------------------------------------------
-// CCaSrvAppScanner::IsInRomL
+//
 // ---------------------------------------------------------
 //
 TBool CCaSrvAppScanner::IsInRomL( TInt aUid )
@@ -1134,7 +1163,7 @@
     }
 
 // ---------------------------------------------------------
-// CCaSrvAppScanner::IsDriveInUse
+//
 // ---------------------------------------------------------
 //
 TBool CCaSrvAppScanner::IsDriveInUse(
@@ -1157,6 +1186,10 @@
     return inUse;
     }
 
+// ---------------------------------------------------------
+//
+// ---------------------------------------------------------
+//
 void CCaSrvAppScanner::MakeNotEmptyCollectionsVisibleL()
     {
     RPointerArray<CCaInnerEntry> resultArray;
@@ -1182,6 +1215,10 @@
     CleanupStack::PopAndDestroy( &resultArray );
    }
 
+// ---------------------------------------------------------
+//
+// ---------------------------------------------------------
+//
 void CCaSrvAppScanner::MakeCollectionVisibleIfHasVisibleEntryL(
         CCaInnerEntry* aEntry )
     {
@@ -1205,34 +1242,60 @@
     CleanupStack::PopAndDestroy( &resultEntriesArray );
     }
 
-
-// ==================== MEMBER FUNCTIONS ====================
-
-// ---------------------------------------------------------
-// TAppAtributes::TAppAtributes
-// ---------------------------------------------------------
-//
-TCaAppAtributes::TCaAppAtributes( TUint aUid )
-    {
-    iUid = aUid;
-    }
-
-// ---------------------------------------------------------
-// TAppAtributes::GetUid
 // ---------------------------------------------------------
 //
-TUint TCaAppAtributes::GetUid() const
+// ---------------------------------------------------------//
+TBool CCaSrvAppScanner::UpdateComponentIdL( TApaAppInfo& appInfo, 
+    CCaInnerEntry& aEntry ) const
     {
-    return iUid;
-    }
+    TBool updated( EFalse );
+    
+    CComponentFilter* const fileNameFilter = CComponentFilter::NewLC();
+
+    fileNameFilter->SetFileL( appInfo.iFullName );
 
-// ---------------------------------------------------------
-// TAppAtributes::MatchItems
-// ---------------------------------------------------------
-//
-TBool TCaAppAtributes::MatchItems( const TCaAppAtributes& item1,
-        const TCaAppAtributes& item2 )
+    RArray<TComponentId> componentIds;
+    CleanupClosePushL( componentIds );
+    iSoftwareRegistry.GetComponentIdsL( componentIds, fileNameFilter );
+    
+    if ( componentIds.Count() == 0 )
     {
-    return item1.GetUid() == item2.GetUid();
+        CComponentFilter* const uidFilter = CComponentFilter::NewLC();
+        uidFilter->AddPropertyL(_L("Uid"), aEntry.GetUid());
+        iSoftwareRegistry.GetComponentIdsL( componentIds, uidFilter );
+        CleanupStack::PopAndDestroy( uidFilter );
     }
+    
+    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 );
+            
+            updated = ETrue;
+            }
+        
+        CleanupStack::PopAndDestroy( &oldComponentId );
+        CleanupStack::PopAndDestroy( &newComponentId );
+        }
 
+    CleanupStack::PopAndDestroy( &componentIds );
+    CleanupStack::PopAndDestroy( fileNameFilter );
+    
+    return updated;
+    }