menucontentsrv/srvsrc/menusrvappscanner.cpp
changeset 0 79c6a41cd166
child 1 844b978f8d5e
equal deleted inserted replaced
-1:000000000000 0:79c6a41cd166
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 #include <mcsmenuutils.h>
       
    18 #include <e32property.h>
       
    19 #include <WidgetRegistryClient.h>
       
    20 #include "menusrvappscanner.h"
       
    21 #include "menusrvmmchistory.h"
       
    22 #include "menueng.h"
       
    23 #include "menuengobject.h"
       
    24 #include "pathinfo.h"
       
    25 #include "menulogger.h"
       
    26 #include "centralrepository.h"
       
    27 #include "mcssathandler.h"
       
    28 #include "menusrvengutils.h"
       
    29 #include "bautils.h"
       
    30 
       
    31 _LIT( KMenuOne, "1" );
       
    32 _LIT( KMenuAttrMmcId, "mmc_id" );
       
    33 _LIT( KMenuMassStorage, "mass_storage" );
       
    34 _LIT( KMenuMmcHistoryFname, "mmchistory" );
       
    35 _LIT( KZDrive, "Z" );
       
    36 
       
    37 // ==================== LOCAL FUNCTIONS ====================
       
    38 
       
    39 /**
       
    40 * Identity function to search in an array of TMenuItems.
       
    41 * Identity is the ID.
       
    42 * @param aLeft Search term.
       
    43 * @param aRight Array item.
       
    44 * @return ETrue if ID-s match.
       
    45 */
       
    46 LOCAL_C TBool IdMatch( const TMenuItem& aLeft, const TMenuItem& aRight )
       
    47     {
       
    48     return aLeft.Id() == aRight.Id();
       
    49     }
       
    50 
       
    51 // ==================== MEMBER FUNCTIONS ====================
       
    52 
       
    53 // ---------------------------------------------------------
       
    54 // CMenuSrvAppScanner::NewL
       
    55 // ---------------------------------------------------------
       
    56 //
       
    57 CMenuSrvAppScanner* CMenuSrvAppScanner::NewL( CMenuEng& aEng )
       
    58     {
       
    59     CMenuSrvAppScanner* scanner = new (ELeave) CMenuSrvAppScanner( aEng );
       
    60     CleanupStack::PushL( scanner );
       
    61     scanner->ConstructL();
       
    62     CleanupStack::Pop( scanner );
       
    63     return scanner;
       
    64     }
       
    65 
       
    66 // ---------------------------------------------------------
       
    67 // CMenuSrvAppScanner::~CMenuSrvAppScanner
       
    68 // ---------------------------------------------------------
       
    69 //
       
    70 CMenuSrvAppScanner::~CMenuSrvAppScanner()
       
    71     {
       
    72     Cancel();
       
    73     iApaLsSession.Close();
       
    74     delete iMcsSatNotifier;
       
    75     delete iNotifier;
       
    76     iEng.DequeueOperation( *this );
       
    77     delete iMmcHistory;
       
    78     iFs.Close();
       
    79 	iWidgetSession.Close();
       
    80 
       
    81     if( iCenRepNotifyHandlerHiddenApps )
       
    82         {
       
    83         iCenRepNotifyHandlerHiddenApps->StopListening();
       
    84         }
       
    85     delete iCenRepNotifyHandlerHiddenApps;
       
    86 
       
    87     if( iCenRepNotifyHandlerCPHiddenApps )
       
    88         {
       
    89         iCenRepNotifyHandlerCPHiddenApps->StopListening();
       
    90         }
       
    91     delete iCenRepNotifyHandlerCPHiddenApps;
       
    92 
       
    93     if( iCenRepNotifyHandlerCPHiddenFolders )
       
    94         {
       
    95         iCenRepNotifyHandlerCPHiddenFolders->StopListening();
       
    96         }
       
    97     delete iCenRepNotifyHandlerCPHiddenFolders;
       
    98   	delete iCenRepSession;
       
    99   	delete iFreeSpaceObserver;
       
   100 
       
   101     }
       
   102 
       
   103 // ---------------------------------------------------------
       
   104 // CMenuSrvAppScanner::CMenuSrvAppScanner
       
   105 // ---------------------------------------------------------
       
   106 //
       
   107 CMenuSrvAppScanner::CMenuSrvAppScanner( CMenuEng& aEng )
       
   108 : CActive( CActive::EPriorityStandard ), iEng( aEng )
       
   109     {
       
   110     CActiveScheduler::Add( this );
       
   111     }
       
   112 
       
   113 // ---------------------------------------------------------
       
   114 // CMenuSrvAppScanner::ConstructL
       
   115 // ---------------------------------------------------------
       
   116 //
       
   117 void CMenuSrvAppScanner::ConstructL()
       
   118     {
       
   119     iOpStatus = EFalse;
       
   120     User::LeaveIfError( iFs.Connect() );
       
   121     TFileName path;
       
   122     User::LeaveIfError( iFs.PrivatePath( path ) );
       
   123     TUint attribute;
       
   124     if( iFs.Att( path, attribute) == KErrNotFound )
       
   125     	{
       
   126         TInt mdRes = iFs.MkDirAll( path );
       
   127         if ( mdRes != KErrNone )
       
   128         	{
       
   129         	User::Leave( mdRes );
       
   130         	}
       
   131     	}
       
   132 
       
   133     iMmcHistory = new (ELeave) CMenuSrvMmcHistory();
       
   134     iMmcHistory->LoadL( iFs, KMenuMmcHistoryFname() );
       
   135     // The notifier has its own session to apparc, instead of taking
       
   136     // it as argument... :(
       
   137     iNotifier = CApaAppListNotifier::NewL( this, CActive::EPriorityStandard );
       
   138     User::LeaveIfError( iApaLsSession.Connect() );
       
   139     User::LeaveIfError( iApaLsSession.GetAllApps() ); // This is async.
       
   140 	User::LeaveIfError( iWidgetSession.Connect() );
       
   141 
       
   142    	iCenRepSession = CRepository::NewL( KCRUidMenu );
       
   143 
       
   144 	iCenRepNotifyHandlerHiddenApps = CCenRepNotifyHandler::NewL(
       
   145 	    *this, *iCenRepSession,
       
   146 		CCenRepNotifyHandler::EStringKey, KMenuHideApplication );
       
   147 	iCenRepNotifyHandlerCPHiddenApps = CCenRepNotifyHandler::NewL(
       
   148 	    *this, *iCenRepSession,
       
   149 		CCenRepNotifyHandler::EStringKey, KMenuHideCPApplication );
       
   150 
       
   151 	iCenRepNotifyHandlerCPHiddenFolders = CCenRepNotifyHandler::NewL(
       
   152 	    *this, *iCenRepSession,
       
   153 		CCenRepNotifyHandler::EStringKey, KMenuHideCPFolder );
       
   154 
       
   155 	iCenRepNotifyHandlerHiddenApps->StartListeningL();
       
   156 	iCenRepNotifyHandlerCPHiddenApps->StartListeningL();
       
   157 	iCenRepNotifyHandlerCPHiddenFolders->StartListeningL();
       
   158 
       
   159 	iMcsSatNotifier = CMcsSatNotifier::NewL(
       
   160 	                this, KCRUidMenu, KMenuShowSatUI );
       
   161 
       
   162 	iFreeSpaceObserver = CMcsFreeSpaceObserver::NewL( *this );
       
   163 
       
   164     iApaLsSession.RegisterListPopulationCompleteObserver( iStatus );
       
   165     SetActive();
       
   166     iOpStatus = ETrue;
       
   167     }
       
   168 
       
   169 // ---------------------------------------------------------
       
   170 // CMenuSrvAppScanner::RunL
       
   171 // ---------------------------------------------------------
       
   172 //
       
   173 void CMenuSrvAppScanner::RunL()
       
   174     {
       
   175     User::LeaveIfError( iStatus.Int() ); // Handle errors in RunL.
       
   176     // AppArc app scan complete, we have the app list.
       
   177     // Now queue this operation to be executed by the Engine.
       
   178     iEng.QueueOperationL( *this );
       
   179     }
       
   180 
       
   181 // ---------------------------------------------------------
       
   182 // CMenuSrvAppScanner::DoCancel
       
   183 // ---------------------------------------------------------
       
   184 //
       
   185 void CMenuSrvAppScanner::DoCancel()
       
   186     {
       
   187     iApaLsSession.CancelListPopulationCompleteObserver();
       
   188     }
       
   189 
       
   190 // ---------------------------------------------------------
       
   191 // CMenuSrvAppScanner::RunError
       
   192 // ---------------------------------------------------------
       
   193 //
       
   194 TInt CMenuSrvAppScanner::RunError( TInt /*aError*/ )
       
   195     {
       
   196     // Ignore the error (what else could we do?).
       
   197     // When next AppArc update occurs, we will run again.
       
   198     return KErrNone;
       
   199     }
       
   200 
       
   201 // ---------------------------------------------------------
       
   202 // CMenuSrvAppScanner::UpdateApplicationWithHideIfInstalledItemsL
       
   203 // ---------------------------------------------------------
       
   204 //
       
   205 void CMenuSrvAppScanner::UpdateApplicationWithHideIfInstalledItemsL()
       
   206     {
       
   207     TInt root;
       
   208     iEng.RootFolderL( root );
       
   209 
       
   210     TMenuSrvAttrExistsFilter appFilter;
       
   211     appFilter.SetAttr( KMenuAttrHideIfInstalledUid() );
       
   212 
       
   213     RArray<TMenuItem> items;
       
   214     CleanupClosePushL( items );
       
   215     iEng.GetItemsL( items, root, &appFilter, ETrue );
       
   216 
       
   217     for (TInt i=0; i < items.Count(); i++)
       
   218         {
       
   219         TBool wasHidden;
       
   220         TPtrC uidTmp;
       
   221 
       
   222         GetHiddenFlagAndUidL( items[i].Id(), wasHidden, uidTmp );
       
   223 
       
   224         HideItemIfPresentL( root, items[i].Id(), uidTmp, wasHidden );
       
   225         }
       
   226     CleanupStack::PopAndDestroy( &items );
       
   227     }
       
   228 
       
   229 // ---------------------------------------------------------
       
   230 // CMenuSrvAppScanner::GetHiddenFlagAndUidL
       
   231 // ---------------------------------------------------------
       
   232 //
       
   233 void CMenuSrvAppScanner::GetHiddenFlagAndUidL( TInt aId, TBool& aHidden, TPtrC& aUidStr )
       
   234     {
       
   235     const CMenuEngObject& object = iEng.ObjectL( aId );
       
   236     aHidden = (0 != (object.Flags() & TMenuItem::EHidden));
       
   237 
       
   238     TBool tmp;
       
   239     object.FindAttribute( KMenuAttrHideIfInstalledUid(), aUidStr, tmp);
       
   240     }
       
   241 
       
   242 // ---------------------------------------------------------
       
   243 // CMenuSrvAppScanner::HideAppIfExists
       
   244 // ---------------------------------------------------------
       
   245 //
       
   246 void CMenuSrvAppScanner::HideItemIfPresentL( TInt aFolder, TInt aId, const TDesC& aUid, TBool aWasHidden )
       
   247     {
       
   248     TBool hideItem = EFalse;
       
   249     TMenuSrvAttrFilter uidAppFilter;
       
   250     uidAppFilter.SetAttr( KMenuAttrUid(), aUid );
       
   251 
       
   252     RArray<TMenuItem> appItems;
       
   253     CleanupClosePushL( appItems );
       
   254     iEng.GetItemsL( appItems, aFolder, &uidAppFilter, ETrue );
       
   255 
       
   256     for (TInt i=0; i < appItems.Count(); i++)
       
   257         {
       
   258         if(appItems[i].Type() != KMenuTypeLink())
       
   259         	{
       
   260             const TMenuItem& item = appItems[i];
       
   261 
       
   262             TBool itemHidden = (0 != (item.Flags() & TMenuItem::EHidden));
       
   263             TBool itemMissing = (0 != (item.Flags() & TMenuItem::EMissing));
       
   264             if ( !itemHidden && !itemMissing )
       
   265                 {
       
   266                 hideItem = ETrue;
       
   267                 }
       
   268         	}
       
   269         }
       
   270 
       
   271     SetHiddenFlagL( aId, aWasHidden, hideItem );
       
   272 
       
   273     CleanupStack::PopAndDestroy( &appItems );
       
   274     }
       
   275 
       
   276 // ---------------------------------------------------------
       
   277 // CMenuSrvAppScanner::SetHiddenFlagL
       
   278 // ---------------------------------------------------------
       
   279 //
       
   280 void CMenuSrvAppScanner::SetHiddenFlagL( TInt aId, TBool aWasHidden, TBool aHide )
       
   281     {
       
   282     if ( aWasHidden ^ aHide )
       
   283         {
       
   284         iEng.ModifiableObjectL( aId, RMenuNotifier::EItemsAddedRemoved ).
       
   285             SetFlags( TMenuItem::EHidden, aHide );
       
   286         }
       
   287     }
       
   288 
       
   289 // ---------------------------------------------------------
       
   290 // CMenuSrvAppScanner::ValidateLinkUidL
       
   291 // ---------------------------------------------------------
       
   292 //
       
   293 void CMenuSrvAppScanner::ValidateLinkUidL( TInt aFolder, TInt aId, const TDesC& aUidStr )
       
   294     {
       
   295     TMenuSrvAttrFilter uidAppFilter;
       
   296     uidAppFilter.SetAttr( KMenuAttrUid(), aUidStr );
       
   297 
       
   298     RArray<TMenuItem> appItems;
       
   299     CleanupClosePushL( appItems );
       
   300     iEng.GetItemsL( appItems, aFolder, &uidAppFilter, ETrue );
       
   301 
       
   302     TBool showItem = EFalse;
       
   303     TBool exists = EFalse;
       
   304     TBool itemMissing = EFalse;
       
   305     for (TInt i=0; i < appItems.Count(); i++)
       
   306         {
       
   307         if(appItems[i].Id() != aId)
       
   308         	{
       
   309             exists = ETrue;
       
   310             const TMenuItem& item = appItems[i];
       
   311 
       
   312             TBool itemHidden = (0 != (item.Flags() & TMenuItem::EHidden));
       
   313             itemMissing = (0 != (item.Flags() & TMenuItem::EMissing));
       
   314             if ( !itemHidden && !itemMissing )
       
   315                 {
       
   316                 showItem = ETrue;
       
   317                 }
       
   318         	}
       
   319         }
       
   320 
       
   321     UpdateLinkL( aId, exists, showItem, itemMissing );
       
   322 
       
   323     CleanupStack::PopAndDestroy( &appItems );
       
   324     }
       
   325 
       
   326 // ---------------------------------------------------------
       
   327 // CMenuSrvAppScanner::UpdateLinkL
       
   328 // ---------------------------------------------------------
       
   329 //
       
   330 void CMenuSrvAppScanner::UpdateLinkL(
       
   331     TInt aId,
       
   332     TBool aExists,
       
   333     TBool aShowItem,
       
   334     TBool aMissingItem )
       
   335     {
       
   336     if (!aExists)
       
   337         {
       
   338         iEng.ModifiableObjectL( aId ).SetFlags( TMenuItem::ELockDelete, EFalse );
       
   339         iEng.RemoveL( aId );
       
   340         }
       
   341     else if ( !aMissingItem )
       
   342         {
       
   343         const CMenuEngObject& object = iEng.ObjectL( aId );
       
   344         TBool itemHidden = (0 != (object.Flags() & TMenuItem::EHidden));
       
   345         TBool itemMissing = (0 != (object.Flags() & TMenuItem::EMissing));
       
   346         if ( itemHidden == aShowItem )
       
   347             {
       
   348             iEng.ModifiableObjectL( aId, RMenuNotifier::EItemsAddedRemoved  ).
       
   349             SetFlags( TMenuItem::EHidden, !aShowItem );
       
   350             }
       
   351         if ( itemMissing != aMissingItem )
       
   352             {
       
   353             iEng.ModifiableObjectL( aId, RMenuNotifier::EItemsAddedRemoved  ).
       
   354             SetFlags( TMenuItem::EMissing, aMissingItem );
       
   355             }
       
   356         }
       
   357     else
       
   358         {
       
   359         const CMenuEngObject& object = iEng.ObjectL( aId );
       
   360         TBool itemMissing = (0 != (object.Flags() & TMenuItem::EMissing));
       
   361         if ( itemMissing != aMissingItem )
       
   362             {
       
   363             iEng.ModifiableObjectL( aId, RMenuNotifier::EItemsAddedRemoved  ).
       
   364             SetFlags( TMenuItem::EMissing, aMissingItem );
       
   365             }
       
   366         }
       
   367     }
       
   368 
       
   369 // ---------------------------------------------------------
       
   370 // CMenuSrvAppScanner::ValidateLinkRefIdL
       
   371 // ---------------------------------------------------------
       
   372 //
       
   373 void CMenuSrvAppScanner::ValidateLinkRefIdL( TInt aId, const TDesC& refIdStr )
       
   374     {
       
   375     TUint refItemId;
       
   376     MenuUtils::GetTUint( refIdStr, refItemId );
       
   377 
       
   378     TMenuItem refItem;
       
   379 
       
   380     TBool showItem = EFalse;
       
   381     TBool exists = EFalse;
       
   382 
       
   383     TRAPD( err, iEng.GetItemL( refItemId, refItem ) );
       
   384 
       
   385     if (err == KErrNone)
       
   386         {
       
   387         exists = ETrue;
       
   388         }
       
   389 
       
   390     TBool itemHidden = (0 != (refItem.Flags() & TMenuItem::EHidden));
       
   391     TBool itemMissing = (0 != (refItem.Flags() & TMenuItem::EMissing));
       
   392     if ( !itemHidden  && !itemMissing )
       
   393         {
       
   394         showItem = ETrue;
       
   395         }
       
   396 
       
   397     UpdateLinkL( aId, exists, showItem, itemMissing );
       
   398     }
       
   399 
       
   400 // ---------------------------------------------------------
       
   401 // CMenuSrvAppScanner::ValidateLinkL
       
   402 // ---------------------------------------------------------
       
   403 //
       
   404 void CMenuSrvAppScanner::ValidateLinkL( TInt aFolder, TInt aId )
       
   405     {
       
   406     const CMenuEngObject& object = iEng.ObjectL( aId );
       
   407 
       
   408     TBool tmp;
       
   409     TPtrC refIdStr;
       
   410     TPtrC uidStr;
       
   411     if ( object.FindAttribute( KMenuAttrRefId(), refIdStr, tmp) )
       
   412         {
       
   413         ValidateLinkRefIdL( aId, refIdStr );
       
   414         }
       
   415     else if ( object.FindAttribute( KMenuAttrUid(), uidStr, tmp) )
       
   416         {
       
   417         ValidateLinkUidL( aFolder, aId, uidStr );
       
   418         }
       
   419     else
       
   420         {
       
   421         UpdateLinkL( aId, EFalse, EFalse, EFalse );
       
   422         }
       
   423     }
       
   424 
       
   425 // ---------------------------------------------------------
       
   426 // CMenuSrvAppScanner::UpdateLinkItemsL
       
   427 // ---------------------------------------------------------
       
   428 //
       
   429 void CMenuSrvAppScanner::UpdateLinkItemsL()
       
   430     {
       
   431     TInt root;
       
   432     iEng.RootFolderL( root );
       
   433 
       
   434     TMenuSrvTypeFilter linkFilter;
       
   435     linkFilter.SetType( KMenuTypeLink() );
       
   436 
       
   437     RArray<TMenuItem> items;
       
   438     CleanupClosePushL( items );
       
   439     iEng.GetItemsL( items, root, &linkFilter, ETrue );
       
   440 
       
   441     for (TInt i=0; i < items.Count(); i++)
       
   442         {
       
   443         ValidateLinkL( root, items[i].Id() );
       
   444         }
       
   445     CleanupStack::PopAndDestroy( &items );
       
   446     }
       
   447 
       
   448 // ---------------------------------------------------------
       
   449 // CMenuSrvAppScanner::HandleFreeSpaceEventL
       
   450 // ---------------------------------------------------------
       
   451 //
       
   452 void CMenuSrvAppScanner::HandleFreeSpaceEventL()
       
   453     {
       
   454     if ( !IsActive() && !iOpStatus )
       
   455         {
       
   456         iOpStatus = ETrue;
       
   457         TRequestStatus* ownStatus = &iStatus;
       
   458         *ownStatus = KRequestPending;
       
   459         SetActive();
       
   460         User::RequestComplete( ownStatus, KErrNone );
       
   461         }
       
   462     }
       
   463 // ---------------------------------------------------------
       
   464 // CMenuSrvAppScanner::RunMenuEngOperationL
       
   465 // ---------------------------------------------------------
       
   466 //
       
   467 void CMenuSrvAppScanner::RunMenuEngOperationL()
       
   468     {
       
   469     UpdateApplicationItemsL();
       
   470     UpdateApplicationWithHideIfInstalledItemsL();
       
   471     UpdateLinkItemsL();
       
   472     iOpStatus = EFalse;
       
   473     }
       
   474 
       
   475 
       
   476 // ---------------------------------------------------------
       
   477 // CMenuSrvAppScanner::UpdateApplicationItemL
       
   478 // ---------------------------------------------------------
       
   479 //
       
   480 void CMenuSrvAppScanner::UpdateApplicationItemL(
       
   481 		RArray<TMenuItem>& aMcsItems, const TAppAtributes& aApaItem,
       
   482 		TUint aMmcId, TBool isLegacy)
       
   483     {
       
   484     RArray<TMenuItem> mcsUidItems;
       
   485     CleanupClosePushL( mcsUidItems );
       
   486     TInt appuid = aApaItem.GetUid();
       
   487     GetMcsAppItemsL( isLegacy, appuid, mcsUidItems );
       
   488     TBool isApaItemHidden( aApaItem.IsHidden() );
       
   489 
       
   490     // This app is not in the menu, add it now.
       
   491     // We don't add hidden items, there are too many of them!
       
   492     // do not display Menu app
       
   493     if ( !mcsUidItems.Count()
       
   494     		&& !isApaItemHidden
       
   495     		&& appuid !=  KMmUid3.iUid  )
       
   496         {
       
   497         if( appuid == KSatUid.iUid )
       
   498             {
       
   499             if( CMcsSatHandler::CheckVisibility() )
       
   500              	{
       
   501               	AddAppItemL( appuid, aMmcId );
       
   502                	}
       
   503             }
       
   504         else
       
   505           	{
       
   506           	AddAppItemL( appuid, aMmcId );
       
   507             GetMcsAppItemsL( isLegacy, appuid, mcsUidItems );
       
   508            	}
       
   509         }//if
       
   510 
       
   511     // if there are any items with legacy UID format
       
   512     // update them to new uid format
       
   513     else if ( mcsUidItems.Count() && isLegacy )
       
   514         {
       
   515         //for every item with matching UID
       
   516         for (TInt j=0; j < mcsUidItems.Count(); j++)
       
   517      		{
       
   518        		CMenuEngObject& object =
       
   519       		                iEng.ModifiableObjectL( mcsUidItems[j].Id() );
       
   520             TBuf<KUidChars> uidString;
       
   521             MenuSrvUtil::UidToStringL( appuid, uidString, EFalse, EHex );
       
   522        	    object.SetAttributeL( KMenuAttrUid(), uidString, EFalse );
       
   523        		}//for
       
   524         }//else if
       
   525     // "hidden", "missing" and "lock_delete"  flags update
       
   526     for ( TInt j = 0; j < mcsUidItems.Count(); j++ )
       
   527         {
       
   528         const TMenuItem& item = mcsUidItems[j];
       
   529 
       
   530         //we need to handle first run of appscanner,
       
   531         //there might be some incorrect data in content xml file
       
   532         //if this will have impact on performance we may run this methods only at start up
       
   533        	HandleMmcAttrUpdateL( item, appuid, aMmcId );
       
   534 		HandleNativeAttrUpdateL( item, appuid );
       
   535 
       
   536         // "hidden" flag handling.
       
   537         HandleHiddenFlagUpdateL( item, appuid, isApaItemHidden );
       
   538 
       
   539         // "missing" flag handling
       
   540         HandleMissingFlagUpdateL( item );
       
   541 
       
   542         //"lock_delete" flag handling
       
   543         HandleLockDeleteFlagUpdateL(item, appuid);
       
   544         // if item was just added to MCS  it is not present in aMcsItems
       
   545         // so we cannot remove it
       
   546         TInt index = aMcsItems.Find( item, TIdentityRelation<TMenuItem>( IdMatch ) );
       
   547         if ( index != KErrNotFound )
       
   548         	{
       
   549         	aMcsItems.Remove( index );
       
   550         	}
       
   551         }//for
       
   552     CleanupStack::PopAndDestroy( &mcsUidItems );
       
   553     }
       
   554 
       
   555 // ---------------------------------------------------------
       
   556 // CMenuSrvAppScanner::HandleHiddenFlagUpdateL
       
   557 // ---------------------------------------------------------
       
   558 //
       
   559 void CMenuSrvAppScanner::HandleHiddenFlagUpdateL( const TMenuItem & aItem,
       
   560 		TInt & aAppUid, TBool aApaItemHidden )
       
   561 	{
       
   562 	TBool itemHidden = (0 != (aItem.Flags() & TMenuItem::EHidden));
       
   563 	if (aAppUid == KSatUid.iUid)
       
   564 		{
       
   565 		if (itemHidden == CMcsSatHandler::CheckVisibility())
       
   566 			{
       
   567 			iEng.ModifiableObjectL(aItem.Id(), RMenuNotifier::EItemsAddedRemoved).
       
   568 				SetFlags( TMenuItem::EHidden, !CMcsSatHandler::CheckVisibility());
       
   569 			}
       
   570 		}
       
   571 	else if (itemHidden != aApaItemHidden)
       
   572 		{
       
   573 		iEng.ModifiableObjectL(aItem.Id(), RMenuNotifier::EItemsAddedRemoved).
       
   574 			SetFlags( TMenuItem::EHidden, aApaItemHidden );
       
   575 		}
       
   576 	}
       
   577 
       
   578 // ---------------------------------------------------------
       
   579 // CMenuSrvAppScanner::HandleNativeAttrUpdateL
       
   580 // ---------------------------------------------------------
       
   581 //
       
   582 void CMenuSrvAppScanner::HandleNativeAttrUpdateL(
       
   583 		const TMenuItem& aItem, TInt aUid )
       
   584 	{
       
   585     //we need this to delete uninstalled java app item
       
   586 	if( ( IsMidlet( TUid::Uid( aUid ) )
       
   587 	        || iWidgetSession.IsWidget( TUid::Uid( aUid ) ) )
       
   588     		&& iEng.ObjectL( aItem.Id() ).GetNative() )
       
   589     	{
       
   590     	iEng.ModifiableObjectL( aItem.Id(),
       
   591     			RMenuNotifier::EItemsNone ).SetNative( EFalse );
       
   592     	}
       
   593 	}
       
   594 
       
   595 
       
   596 // ---------------------------------------------------------
       
   597 // CMenuSrvAppScanner::HandleMmcAttrUpdateL
       
   598 // ---------------------------------------------------------
       
   599 //
       
   600 void CMenuSrvAppScanner::HandleMmcAttrUpdateL(
       
   601 		const TMenuItem& aItem, TInt aUid, TUint aMmcId )
       
   602 	{
       
   603     if ( IsMmcApp( TUid::Uid( aUid ) ) )
       
   604     	{
       
   605     	//app is instaled on mmc - KMenuAttrMmcId attribute update
       
   606     	TBuf<KUidChars> uidString;
       
   607         uidString.Format( KHexFormat, aMmcId );
       
   608         iEng.ModifiableObjectL( aItem.Id(), RMenuNotifier::EItemsAddedRemoved ).
       
   609 			SetAttributeL( KMenuAttrMmcId, uidString, EFalse );
       
   610     	}
       
   611     else if ( IsMassStorageApp( TUid::Uid( aUid ) )
       
   612     		&& IsMidlet( TUid::Uid( aUid ) ) )
       
   613     	{
       
   614     	//its java app installed on mass storage, we need to leave it in xml
       
   615     	//in case of connecting usb in mass storage mode
       
   616         iEng.ModifiableObjectL( aItem.Id(), RMenuNotifier::EItemsAddedRemoved ).
       
   617 			SetAttributeL( KMenuAttrMmcId, KMenuMassStorage, EFalse );
       
   618     	}
       
   619     else
       
   620     	{
       
   621     	//its installed on c: drive - remove attribute
       
   622 		iEng.ModifiableObjectL( aItem.Id(), RMenuNotifier::EItemsAddedRemoved ).
       
   623 			RemoveAttribute( KMenuAttrMmcId );
       
   624     	}
       
   625 	}
       
   626 // ---------------------------------------------------------
       
   627 // CMenuSrvAppScanner::UpdateApplicationItemsL
       
   628 // ---------------------------------------------------------
       
   629 //
       
   630 void CMenuSrvAppScanner::UpdateApplicationItemsL()
       
   631     {
       
   632     TUint currentMmcId = UpdateMmcHistoryL();
       
   633     // get all MCS items
       
   634     RArray<TMenuItem> mcsItems;
       
   635     CleanupClosePushL( mcsItems );
       
   636     GetMcsAppItemsL( mcsItems );
       
   637     RArray<TAppAtributes> apaAndCrItems;
       
   638     CleanupClosePushL( apaAndCrItems );
       
   639     GetApaItemsL( apaAndCrItems );
       
   640     GetCrItemsL( apaAndCrItems );
       
   641     TBool isLegacy = iEng.GetOnceLegacyFormat();
       
   642 
       
   643 
       
   644     //for every item in apaAndCrItems array
       
   645     for ( TInt i = ( apaAndCrItems.Count() - 1 ); i >= 0 ; i-- )
       
   646         {
       
   647         // if there was leave for any item we ignore it
       
   648         // and proceed to the next one
       
   649         TRAP_IGNORE(UpdateApplicationItemL(
       
   650         		mcsItems, apaAndCrItems[i], currentMmcId, isLegacy));
       
   651         }
       
   652     // Here the big list contains menu items that refer to missing apps.
       
   653     HandleMissingItemsL( mcsItems );
       
   654     CleanupStack::PopAndDestroy( &apaAndCrItems );
       
   655     CleanupStack::PopAndDestroy( &mcsItems );
       
   656     }
       
   657 
       
   658 // ---------------------------------------------------------
       
   659 // CMenuSrvAppScanner::HandleLockDeleteFlagUpdateL
       
   660 // ---------------------------------------------------------
       
   661 //
       
   662 void CMenuSrvAppScanner::HandleLockDeleteFlagUpdateL(
       
   663 		const TMenuItem& aItem, TInt aUid )
       
   664 	{
       
   665 	TBool isHidden = ( ( iEng.ObjectL( aItem.Id() )
       
   666 							.Flags() & TMenuItem::EHidden ) != 0 );
       
   667 	if ( !isHidden && IsInRomL( aUid ) )
       
   668 		{
       
   669 		if ( ( aItem.Flags() & TMenuItem::ELockDelete ) == 0 )
       
   670 			{
       
   671 			iEng.ModifiableObjectL(aItem.Id())
       
   672 					.SetFlags( TMenuItem::ELockDelete, ETrue );
       
   673 			}
       
   674 		}
       
   675 	else
       
   676 		{
       
   677 		if ( ( aItem.Flags() & TMenuItem::ELockDelete ) != 0 )
       
   678 			{
       
   679 			iEng.ModifiableObjectL(aItem.Id())
       
   680 					.SetFlags( TMenuItem::ELockDelete, EFalse );
       
   681 			}
       
   682 		}
       
   683 	}
       
   684 
       
   685 // ---------------------------------------------------------
       
   686 // CMenuSrvAppScanner::HandleMissingFlagUpdateL
       
   687 // ---------------------------------------------------------
       
   688 //
       
   689 void CMenuSrvAppScanner::HandleMissingFlagUpdateL( const TMenuItem& aItem )
       
   690 	{
       
   691 	if ( aItem.Flags() & TMenuItem::EMissing )
       
   692         {
       
   693         CLOG_WRITE_FORMAT8( "Unsetting flag EMissing on %d", item.Id() );
       
   694         //application found so we unset "missing" flag
       
   695         iEng.ModifiableObjectL( aItem.Id(), RMenuNotifier::EItemsAddedRemoved ).
       
   696             SetFlags( TMenuItem::EMissing, EFalse );
       
   697         }
       
   698 	}
       
   699 
       
   700 // ---------------------------------------------------------
       
   701 // CMenuSrvAppScanner::IsInRomL
       
   702 // ---------------------------------------------------------
       
   703 //
       
   704 TBool CMenuSrvAppScanner::IsInRomL( TInt aUid )
       
   705     {
       
   706     TBool inROM = EFalse;
       
   707     TApaAppInfo appInfo;
       
   708     if( iApaLsSession.GetAppInfo( appInfo, TUid::Uid( aUid ) ) == KErrNone )
       
   709         {
       
   710         RBuf path;
       
   711         CleanupClosePushL( path );
       
   712         path.CreateL( appInfo.iFullName );
       
   713         path.Replace( 0, 1, KZDrive );
       
   714         if( BaflUtils::FileExists( iFs, path ) )
       
   715             {
       
   716             inROM = ETrue;
       
   717             }
       
   718         CleanupStack::PopAndDestroy( &path );
       
   719         }
       
   720     return inROM;
       
   721     }
       
   722 
       
   723 // ---------------------------------------------------------
       
   724 // CMenuSrvAppScanner::GetCrItemsL
       
   725 // ---------------------------------------------------------
       
   726 //
       
   727 void CMenuSrvAppScanner::GetCrItemsL( RArray<TAppAtributes>& aArray )
       
   728     {
       
   729  	TBuf<KCenRepBufferSize> buf;
       
   730 	iCenRepSession->Get( KMenuHideCPApplication, buf );
       
   731 	ParseUidsL( buf, aArray );// parses UIDs from buf and appends them to array
       
   732 	iCenRepSession->Get( KMenuHideApplication, buf );
       
   733 	ParseUidsL( buf, aArray );// parses UIDs from buf and appends them to array
       
   734     }
       
   735 
       
   736 // ---------------------------------------------------------
       
   737 // CMenuSrvAppScanner::ParseUidsL
       
   738 // ---------------------------------------------------------
       
   739 //
       
   740 void CMenuSrvAppScanner::ParseUidsL( const TDesC& aHiddenApplications,
       
   741                                         RArray<TAppAtributes>& aArray )
       
   742     {
       
   743     TLex input( aHiddenApplications );
       
   744     TLexMark startMark;
       
   745     input.Mark( startMark );
       
   746     TBool notEmpty = EFalse;
       
   747     while ( !input.Eos() )
       
   748         {
       
   749         if( input.Peek() == ',')
       
   750             {
       
   751             SetHidden(input.MarkedToken( startMark ), aArray);
       
   752             input.Inc();
       
   753             input.Mark( startMark );
       
   754             }
       
   755         input.Inc();
       
   756         notEmpty = ETrue;
       
   757         }
       
   758         if ( notEmpty )
       
   759             {
       
   760             SetHidden(input.MarkedToken( startMark ), aArray);
       
   761             }
       
   762 
       
   763 
       
   764     }
       
   765 
       
   766 // ---------------------------------------------------------
       
   767 // CMenuSrvAppScanner::SetHidden
       
   768 // ---------------------------------------------------------
       
   769 //
       
   770 void CMenuSrvAppScanner::SetHidden( const TDesC& aHiddenAppUid,
       
   771                                             RArray<TAppAtributes>& aArray )
       
   772     {
       
   773     TLex appUidDescriptor(aHiddenAppUid);
       
   774     TUint hiddenAppUid( 0 );
       
   775     appUidDescriptor.Val( hiddenAppUid, EHex );
       
   776     if ( hiddenAppUid )
       
   777        {
       
   778        //all applications in descriptor are hidden
       
   779        TAppAtributes appAtributes( hiddenAppUid,  ETrue );
       
   780        TInt id = aArray.Find(appAtributes, TAppAtributes::MatchItems );
       
   781        if ( id != KErrNotFound )
       
   782            {
       
   783            aArray[id].SetHidden( ETrue );
       
   784            }
       
   785        }
       
   786     }
       
   787 
       
   788 // ---------------------------------------------------------
       
   789 // CMenuSrvAppScanner::GetApaItemsL
       
   790 // ---------------------------------------------------------
       
   791 //
       
   792 void CMenuSrvAppScanner::GetApaItemsL( RArray<TAppAtributes>& aArray )
       
   793     {
       
   794     TApaAppInfo appInfo;
       
   795     TApaAppCapabilityBuf appCap;
       
   796     TInt screenNumber;
       
   797 
       
   798     User::LeaveIfError( iApaLsSession.GetAllApps() );
       
   799     // for every application get uid, hidden and missing attribute
       
   800     // and add to aArray.
       
   801     while ( KErrNone == iApaLsSession.GetNextApp( appInfo ) )
       
   802         {
       
   803         User::LeaveIfError( iApaLsSession.GetAppCapability
       
   804             ( appCap, appInfo.iUid ) );
       
   805         User::LeaveIfError( iApaLsSession.GetDefaultScreenNumber
       
   806             ( screenNumber, appInfo.iUid ) );
       
   807         // "Hidden" status according to AppArc.
       
   808         TBool appHidden = appCap().iAppIsHidden || screenNumber != 0;
       
   809 
       
   810         TAppAtributes appAtributes( appInfo.iUid.iUid,  appHidden );
       
   811         aArray.AppendL( appAtributes );
       
   812         }
       
   813     }
       
   814 
       
   815 // ---------------------------------------------------------
       
   816 // CMenuSrvAppScanner::GetMcsItemsL
       
   817 // ---------------------------------------------------------
       
   818 //
       
   819 void CMenuSrvAppScanner::GetMcsAppItemsL( RArray<TMenuItem>& aArray )
       
   820     {
       
   821     TInt root;
       
   822     iEng.RootFolderL( root );
       
   823     TMenuSrvTypeFilter appFilter;
       
   824     appFilter.SetType( KMenuTypeApp() );
       
   825     iEng.GetItemsL( aArray, root, &appFilter, ETrue );
       
   826     }
       
   827 
       
   828 // ---------------------------------------------------------
       
   829 // CMenuSrvAppScanner::GetMcsItemsL
       
   830 // ---------------------------------------------------------
       
   831 //
       
   832 void CMenuSrvAppScanner::GetMcsAppItemsL( TBool aLegacy,
       
   833                        const TUint aUid, RArray<TMenuItem>& aArray )
       
   834     {
       
   835     TInt root;
       
   836     iEng.RootFolderL( root );
       
   837     TMenuSrvTypeAttrFilter appFilter;
       
   838     appFilter.SetType( KMenuTypeApp() );
       
   839     TBuf<KUidChars> uidString;
       
   840     MenuSrvUtil::UidToStringL( aUid, uidString, aLegacy, EHex );
       
   841     appFilter.SetAttr( KMenuAttrUid(), uidString );
       
   842     iEng.GetItemsL( aArray, root, &appFilter, ETrue );
       
   843     //if not found in mcs try with UID in decimal format
       
   844     if (!aArray.Count())
       
   845         {
       
   846         MenuSrvUtil::UidToStringL( aUid, uidString, aLegacy, EDecimal );
       
   847         appFilter.SetAttr( KMenuAttrUid(), uidString );
       
   848         iEng.GetItemsL( aArray, root, &appFilter, ETrue );
       
   849         }
       
   850     }
       
   851 
       
   852 
       
   853 // ---------------------------------------------------------
       
   854 // CMenuSrvAppScanner::CompletedMenuEngOperation
       
   855 // ---------------------------------------------------------
       
   856 //
       
   857 void CMenuSrvAppScanner::CompletedMenuEngOperation( TInt /*aErr*/ )
       
   858     {
       
   859     iOpStatus = EFalse;
       
   860     }
       
   861 
       
   862 // ---------------------------------------------------------
       
   863 // CMenuSrvAppScanner::HandleAppListEvent
       
   864 // ---------------------------------------------------------
       
   865 //
       
   866 void CMenuSrvAppScanner::HandleAppListEvent( TInt /*aEvent*/ )
       
   867     {
       
   868     // We only have one event, EAppListChanged.
       
   869     // Call back RunL async, to requeue and initiate rescan.
       
   870     if ( !IsActive()  && !iOpStatus)
       
   871         {
       
   872         iOpStatus = ETrue;
       
   873         TRequestStatus* ownStatus = &iStatus;
       
   874         *ownStatus = KRequestPending;
       
   875         SetActive();
       
   876         User::RequestComplete( ownStatus, KErrNone );
       
   877         }
       
   878     }
       
   879 
       
   880 // -----------------------------------------------------------------------------
       
   881 // CMenuSrvAppScanner::HandleNotifyString
       
   882 // -----------------------------------------------------------------------------
       
   883 //
       
   884 void CMenuSrvAppScanner::HandleNotifyString( TUint32 aKey,
       
   885         const TDesC16& /*aNewValue*/ )
       
   886     {
       
   887     if((aKey ==KMenuHideApplication )||(aKey == KMenuHideCPApplication))
       
   888         {
       
   889         if ( !IsActive() && !iOpStatus )
       
   890             {
       
   891             iOpStatus = ETrue;
       
   892            TRequestStatus* ownStatus = &iStatus;
       
   893             *ownStatus = KRequestPending;
       
   894             SetActive();
       
   895             User::RequestComplete( ownStatus, KErrNone );
       
   896             }
       
   897         }
       
   898     }
       
   899 
       
   900 // -----------------------------------------------------------------------------
       
   901 // CMenuSrvAppScanner::SATChangeL
       
   902 // -----------------------------------------------------------------------------
       
   903 //
       
   904 void CMenuSrvAppScanner::SATChangeL()
       
   905     {
       
   906     ScheduleScan();
       
   907     }
       
   908 
       
   909 // ---------------------------------------------------------
       
   910 // CMenuSrvAppScanner::ScheduleScan
       
   911 // ---------------------------------------------------------
       
   912 //
       
   913 void CMenuSrvAppScanner::ScheduleScan()
       
   914 	{
       
   915 	if ( !IsActive() && !iOpStatus )
       
   916 		{
       
   917 		iOpStatus = ETrue;
       
   918 		TRequestStatus* ownStatus = &iStatus;
       
   919 		*ownStatus = KRequestPending;
       
   920 		SetActive();
       
   921 		User::RequestComplete( ownStatus, KErrNone );
       
   922 		}
       
   923 	}
       
   924 
       
   925 // ---------------------------------------------------------
       
   926 // CMenuSrvAppScanner::CreateInstallFolderL
       
   927 // ---------------------------------------------------------
       
   928 //
       
   929 TInt CMenuSrvAppScanner::CreateInstallFolderL( TUint aUid )
       
   930 	{
       
   931     // Find a folder for this app.
       
   932     TInt folder(0);
       
   933 
       
   934     TApaAppCapabilityBuf capability;
       
   935     User::LeaveIfError(iApaLsSession.GetAppCapability( capability, TUid::Uid( aUid )));
       
   936 
       
   937     if ( capability().iGroupName.Length() )
       
   938         {
       
   939         // appgroup_name is defined for this app. Find or create folder.
       
   940         AppGroupFolderL( capability().iGroupName, folder );
       
   941         }
       
   942     else
       
   943         {
       
   944         // No appgroup_name, use default folder, if any.
       
   945         DefaultFolderL( folder );
       
   946         }
       
   947     if ( !folder )
       
   948         {
       
   949         // Last resort: it goes to the root.
       
   950         iEng.RootFolderL( folder );
       
   951         }
       
   952     return folder;
       
   953 	}
       
   954 
       
   955 // ---------------------------------------------------------
       
   956 // CMenuSrvAppScanner::AddAppItemL
       
   957 // ---------------------------------------------------------
       
   958 //
       
   959 void CMenuSrvAppScanner::AddAppItemL(
       
   960         TUint aUid,
       
   961         TUint aCurrentMmcId )
       
   962     {
       
   963     TInt folder = CreateInstallFolderL( aUid );
       
   964     // Now add the app item.
       
   965     CMenuEngObject* object = iEng.NewObjectL( KMenuTypeApp() );
       
   966     CleanupStack::PushL( object );
       
   967     TBuf<KUidChars> uidString;
       
   968     _LIT(KHexFormat, "0x%X");
       
   969     uidString.Format( KHexFormat, aUid );
       
   970 
       
   971     object->SetAttributeL( KMenuAttrUid(), uidString, EFalse );
       
   972     if ( aCurrentMmcId && IsMmcApp( TUid::Uid( aUid ) ) )
       
   973         {
       
   974         // This app is on the MMC, set the "mmc_id" attribute.
       
   975         uidString.Format( KHexFormat, aCurrentMmcId );
       
   976         object->SetAttributeL( KMenuAttrMmcId, uidString, EFalse );
       
   977         }
       
   978     if( IsMidlet( TUid::Uid( aUid ) ) 
       
   979 	    || iWidgetSession.IsWidget( TUid::Uid( aUid ) ) )
       
   980     	{
       
   981     	//we need this to delete uninstalled java or wrt widget app item
       
   982     	object->SetNative( EFalse );
       
   983     	if ( !IsMmcApp( TUid::Uid( aUid ) )
       
   984     			&& IsMassStorageApp( TUid::Uid( aUid ) ) )
       
   985     		{
       
   986     		object->SetAttributeL( KMenuAttrMmcId, KMenuMassStorage, EFalse );
       
   987     		}
       
   988     	}
       
   989     EnsureFolderWritableL( folder );
       
   990     iEng.AddL( *object, folder, 0 );
       
   991     CleanupStack::Pop( object );
       
   992     }
       
   993 
       
   994 // ---------------------------------------------------------------------------
       
   995 // CMenuSrvAppScanner::IsMidletL
       
   996 // Checks if given app is midlet by reading the apptype uid (2nd uid)
       
   997 // ---------------------------------------------------------------------------
       
   998 //
       
   999 TBool CMenuSrvAppScanner::IsMidlet( const TUid aAppUid )
       
  1000 	{
       
  1001     const TUid KMidletType = { 0x10210E26 };
       
  1002     TUid typeuid = KNullUid;
       
  1003 
       
  1004     if ( KErrNone == iApaLsSession.GetAppType( typeuid, aAppUid  ) )
       
  1005         {
       
  1006         if ( typeuid == KMidletType )
       
  1007             {
       
  1008             return ETrue;
       
  1009             }
       
  1010         }
       
  1011     return EFalse;
       
  1012 	}
       
  1013 
       
  1014 
       
  1015 // ---------------------------------------------------------
       
  1016 // CMenuSrvAppScanner::AppGroupFolderL
       
  1017 // ---------------------------------------------------------
       
  1018 //
       
  1019 void CMenuSrvAppScanner::AppGroupFolderL( const TDesC& aAppGroupName, TInt& aFolderId )
       
  1020     {
       
  1021     __ASSERT_DEBUG( aAppGroupName.Length(), User::Invariant() );
       
  1022 
       
  1023     TInt folder = 0;
       
  1024     TInt defaultFolderId( 0 );
       
  1025     iEng.RootFolderL( defaultFolderId );
       
  1026     const CMenuEngObject& rootObject = iEng.ObjectL( defaultFolderId );
       
  1027     TPtrC groupName;
       
  1028     TBool localized;
       
  1029 
       
  1030     if ( rootObject.FindAttribute( KMenuAttrAppGroupName, groupName, localized ) &&
       
  1031     	groupName.Compare( aAppGroupName )==0 )
       
  1032         {
       
  1033         folder = defaultFolderId;
       
  1034         }
       
  1035     else
       
  1036     	{
       
  1037         TMenuSrvTypeAttrFilter filter;
       
  1038         filter.SetType( KMenuTypeFolder() );
       
  1039         filter.SetAttr( KMenuAttrAppGroupName(), aAppGroupName );
       
  1040         RArray<TMenuItem> items;
       
  1041         CleanupClosePushL( items );
       
  1042 
       
  1043         iEng.GetItemsL( items, defaultFolderId, &filter, ETrue );
       
  1044         if ( items.Count() )
       
  1045             {
       
  1046             folder = items[0].Id();
       
  1047             }
       
  1048         CleanupStack::PopAndDestroy( &items );
       
  1049     	}
       
  1050     if ( !folder )
       
  1051         {
       
  1052         // No such folder, create it now.
       
  1053         CMenuEngObject* object = iEng.NewObjectL( KMenuTypeFolder() );
       
  1054         CleanupStack::PushL( object );
       
  1055         object->SetAttributeL
       
  1056             ( KMenuAttrAppGroupName(), aAppGroupName, EFalse );
       
  1057         EnsureFolderWritableL( defaultFolderId );
       
  1058         iEng.AddL( *object, defaultFolderId, 0 );
       
  1059 
       
  1060         CleanupStack::Pop( object );
       
  1061         folder = object->Id();
       
  1062         }
       
  1063     __ASSERT_DEBUG( folder, User::Invariant() );
       
  1064     aFolderId = folder;
       
  1065     }
       
  1066 
       
  1067 // ---------------------------------------------------------
       
  1068 // CMenuSrvAppScanner::DefaultFolderL
       
  1069 // ---------------------------------------------------------
       
  1070 //
       
  1071 void CMenuSrvAppScanner::DefaultFolderL( TInt& aFolderId )
       
  1072     {
       
  1073     TInt folder = 0;
       
  1074     TMenuSrvTypeAttrFilter filter;
       
  1075     filter.SetType( KMenuTypeFolder() );
       
  1076     filter.SetAttr( KMenuAttrDefault(), KMenuOne() );
       
  1077     RArray<TMenuItem> items;
       
  1078     CleanupClosePushL( items );
       
  1079     TInt rootId;
       
  1080     iEng.RootFolderL( rootId );
       
  1081     iEng.GetItemsL( items, rootId, &filter, ETrue );
       
  1082     if ( items.Count() )
       
  1083         {
       
  1084         folder = items[0].Id();
       
  1085         }
       
  1086     CleanupStack::PopAndDestroy( &items );
       
  1087     aFolderId = folder;
       
  1088     }
       
  1089 
       
  1090 // ---------------------------------------------------------
       
  1091 // CMenuSrvAppScanner::EnsureFolderWritableL
       
  1092 // ---------------------------------------------------------
       
  1093 //
       
  1094 void CMenuSrvAppScanner::EnsureFolderWritableL( TInt aFolder )
       
  1095     {
       
  1096     // This folder should not be read-only! Remove the protection.
       
  1097     // Otherwise we can't add the items to it.
       
  1098     if ( iEng.ObjectL( aFolder ).Flags() & TMenuItem::ELockMoveInto )
       
  1099         {
       
  1100         iEng.ModifiableObjectL( aFolder ).
       
  1101             SetFlags( TMenuItem::ELockMoveInto, EFalse );
       
  1102         }
       
  1103     }
       
  1104 
       
  1105 // ---------------------------------------------------------
       
  1106 // CMenuSrvAppScanner::HandleMissingItemsL
       
  1107 // ---------------------------------------------------------
       
  1108 //
       
  1109 void CMenuSrvAppScanner::HandleMissingItemsL
       
  1110 ( const RArray<TMenuItem>& aItems )
       
  1111     {
       
  1112     for ( TInt i = 0; i < aItems.Count(); i++ )
       
  1113         {
       
  1114         const TInt id = aItems[i].Id();
       
  1115         TUint mmcId = 0;
       
  1116         TPtrC val;
       
  1117         TBool dummy;
       
  1118         if( iEng.ObjectL( id ).FindAttribute( KMenuAttrMmcId(), val, dummy ) )
       
  1119             {
       
  1120             MenuUtils::GetTUint( val, mmcId );
       
  1121 			if ( mmcId && KErrNotFound != iMmcHistory->Find( mmcId ) )
       
  1122 				{
       
  1123 				// This item is on an MMC which is currently in the MMC history.
       
  1124 				// Set it "missing" but keep it.
       
  1125 				SetObjectFlagsL( ETrue, aItems[i], TMenuItem::EMissing,
       
  1126 						RMenuNotifier::EItemsAddedRemoved );
       
  1127 				}
       
  1128 			else if ( val == KMenuMassStorage()
       
  1129 						&& IsDriveInUse( DriveInfo::EDefaultMassStorage ) )
       
  1130 				{
       
  1131 				SetObjectFlagsL( ETrue, aItems[i], TMenuItem::EMissing,
       
  1132 						RMenuNotifier::EItemsAddedRemoved );
       
  1133 				}
       
  1134 			else
       
  1135 				{
       
  1136 				iEng.RemoveL( id );
       
  1137 				}
       
  1138             }
       
  1139         else
       
  1140             {
       
  1141             // This item is not on MMC or its MMC has been purged from the MMC
       
  1142             // history. Hide the item.
       
  1143             SetObjectFlagsL( EFalse, aItems[i], TMenuItem::ELockDelete );
       
  1144 
       
  1145 			if( iEng.ObjectL( id ).GetNative() )
       
  1146             	{
       
  1147             	SetObjectFlagsL( ETrue, aItems[i], TMenuItem::EHidden,
       
  1148 						RMenuNotifier::EItemsAddedRemoved );
       
  1149             	}
       
  1150             else
       
  1151             	{
       
  1152                	iEng.RemoveL( id );
       
  1153             	}
       
  1154             }
       
  1155         }
       
  1156     }
       
  1157 
       
  1158 // ---------------------------------------------------------
       
  1159 // CMenuSrvAppScanner::SetObjectFlagsL
       
  1160 // ---------------------------------------------------------
       
  1161 //
       
  1162 void CMenuSrvAppScanner::SetObjectFlagsL( TBool aFlagValue, const TMenuItem& aItem,
       
  1163 		const TMenuItem::TFlags& aFlag, const RMenuNotifier::TEvent& aEvent  )
       
  1164 	{
       
  1165 	TBool itemFlagPresent = (0 != (aItem.Flags() & aFlag));
       
  1166 	if( aFlagValue != itemFlagPresent )
       
  1167 		{
       
  1168 		iEng.ModifiableObjectL( aItem.Id(), aEvent ).
       
  1169 			 SetFlags( aFlag, aFlagValue );
       
  1170 		}
       
  1171 	}
       
  1172 
       
  1173 // ---------------------------------------------------------
       
  1174 // CMenuSrvAppScanner::UpdateMmcHistoryL
       
  1175 // ---------------------------------------------------------
       
  1176 //
       
  1177 TUint CMenuSrvAppScanner::UpdateMmcHistoryL()
       
  1178     {
       
  1179     TUint mmcId = CurrentMmcId();
       
  1180     if( mmcId )
       
  1181     	{
       
  1182     	iMmcHistory->InsertL( mmcId );
       
  1183     	iMmcHistory->SaveL( iFs, KMenuMmcHistoryFname() );
       
  1184     	}
       
  1185     return mmcId;
       
  1186     }
       
  1187 
       
  1188 // ---------------------------------------------------------
       
  1189 // CMenuSrvAppScanner::CurrentMmcId
       
  1190 // ---------------------------------------------------------
       
  1191 //
       
  1192 TUint CMenuSrvAppScanner::CurrentMmcId() const
       
  1193     {
       
  1194     // Get mmc id. Errors are ignored.
       
  1195     TUint mmcId = 0;
       
  1196     TInt mmcDrive;
       
  1197     TInt err;
       
  1198     err = DriveInfo::GetDefaultDrive(
       
  1199     	    DriveInfo::EDefaultRemovableMassStorage, mmcDrive );
       
  1200     if ( !err )
       
  1201         {
       
  1202         TVolumeInfo volumeInfo;
       
  1203         err = iFs.Volume( volumeInfo, mmcDrive );
       
  1204         if( !err )
       
  1205             {
       
  1206             mmcId = volumeInfo.iUniqueID;
       
  1207             }
       
  1208         }
       
  1209     return mmcId;
       
  1210     }
       
  1211 
       
  1212 // ---------------------------------------------------------
       
  1213 // CMenuSrvAppScanner::IsFileInDrive
       
  1214 // ---------------------------------------------------------
       
  1215 //
       
  1216 TBool CMenuSrvAppScanner::IsFileInDrive(
       
  1217 			const TDesC& aFileName,
       
  1218 			const DriveInfo::TDefaultDrives& aDefaultDrive ) const
       
  1219     {
       
  1220     if ( aFileName.Length() )
       
  1221         {
       
  1222         TInt mmcDrive;
       
  1223         TInt err = DriveInfo::GetDefaultDrive(
       
  1224 						aDefaultDrive, mmcDrive );
       
  1225         if ( !err )
       
  1226             {
       
  1227             TInt fileDrive;
       
  1228             err = RFs::CharToDrive( aFileName[0], fileDrive );
       
  1229             if ( !err && fileDrive == mmcDrive )
       
  1230                 {
       
  1231                 return ETrue;
       
  1232                 }
       
  1233             }
       
  1234         }
       
  1235     return EFalse;
       
  1236     }
       
  1237 
       
  1238 
       
  1239 // ---------------------------------------------------------
       
  1240 // CMenuSrvAppScanner::IsAppInDrive
       
  1241 // ---------------------------------------------------------
       
  1242 //
       
  1243 TBool CMenuSrvAppScanner::IsAppInDrive(
       
  1244 		const TUid aUid,
       
  1245 		const DriveInfo::TDefaultDrives& aDefaultDrive ) const
       
  1246     {
       
  1247     TBool ret( EFalse );
       
  1248     TApaAppInfo info;
       
  1249     TInt err = iApaLsSession.GetAppInfo( info, aUid );
       
  1250     if ( !err && IsFileInDrive( info.iFullName, aDefaultDrive ) )
       
  1251     	{
       
  1252     	ret = ETrue;
       
  1253     	}
       
  1254     return ret;
       
  1255     }
       
  1256 
       
  1257 // ---------------------------------------------------------
       
  1258 // CMenuSrvAppScanner::IsMmcApp
       
  1259 // ---------------------------------------------------------
       
  1260 //
       
  1261 TBool CMenuSrvAppScanner::IsMmcApp( const TUid aUid ) const
       
  1262     {
       
  1263     return IsAppInDrive( aUid, DriveInfo::EDefaultRemovableMassStorage );
       
  1264     }
       
  1265 
       
  1266 // ---------------------------------------------------------
       
  1267 // CMenuSrvAppScanner::IsMassStorageApp
       
  1268 // ---------------------------------------------------------
       
  1269 //
       
  1270 TBool CMenuSrvAppScanner::IsMassStorageApp( const TUid aUid ) const
       
  1271     {
       
  1272     return IsAppInDrive( aUid, DriveInfo::EDefaultMassStorage );
       
  1273     }
       
  1274 
       
  1275 // ---------------------------------------------------------
       
  1276 // CMenuSrvAppScanner::IsDriveInUse
       
  1277 // ---------------------------------------------------------
       
  1278 //
       
  1279 TBool CMenuSrvAppScanner::IsDriveInUse(
       
  1280 		const DriveInfo::TDefaultDrives& aDefaultDrive )
       
  1281     {
       
  1282     TBool inUse( EFalse );
       
  1283     TInt drive;
       
  1284 
       
  1285     TInt err = DriveInfo::GetDefaultDrive( aDefaultDrive, drive );
       
  1286     if( err == KErrNone )
       
  1287 		{
       
  1288 		TUint status;
       
  1289 		err =  DriveInfo::GetDriveStatus(  iFs, drive, status );
       
  1290 		if( err == KErrNone
       
  1291 				&& ( status & DriveInfo::EDriveInUse ) )
       
  1292 			{
       
  1293 			inUse = ETrue;
       
  1294 			}
       
  1295 		}
       
  1296 
       
  1297 	return inUse;
       
  1298     }
       
  1299 
       
  1300 // ==================== MEMBER FUNCTIONS ====================
       
  1301 
       
  1302 // ---------------------------------------------------------
       
  1303 // TAppAtributes::TAppAtributes
       
  1304 // ---------------------------------------------------------
       
  1305 //
       
  1306 TAppAtributes::TAppAtributes ( TUint aUid, TBool aHidden/*, TBool aMissing*/)
       
  1307     {
       
  1308     iUid = aUid;
       
  1309     iHidden = aHidden;
       
  1310     /*iMissing = aMissing;*/
       
  1311     }
       
  1312 
       
  1313 // ---------------------------------------------------------
       
  1314 // TAppAtributes::GetUid
       
  1315 // ---------------------------------------------------------
       
  1316 //
       
  1317 TUint TAppAtributes::GetUid() const
       
  1318     {
       
  1319     return iUid;
       
  1320     }
       
  1321 
       
  1322 // ---------------------------------------------------------
       
  1323 // TAppAtributes::IsHidden
       
  1324 // ---------------------------------------------------------
       
  1325 //
       
  1326 TBool TAppAtributes::IsHidden() const
       
  1327     {
       
  1328     return iHidden;
       
  1329     }
       
  1330 // ---------------------------------------------------------
       
  1331 // TAppAtributes::SetHidden
       
  1332 // ---------------------------------------------------------
       
  1333 //
       
  1334 void TAppAtributes::SetHidden( TBool aHidden )
       
  1335     {
       
  1336     iHidden = aHidden;
       
  1337     }
       
  1338 
       
  1339 // ---------------------------------------------------------
       
  1340 // TAppAtributes::MatchItems
       
  1341 // ---------------------------------------------------------
       
  1342 //
       
  1343 TBool TAppAtributes::MatchItems(const TAppAtributes& item1,
       
  1344                                         const TAppAtributes& item2)
       
  1345     {
       
  1346     TBool result( EFalse );
       
  1347     TUint uid1(item1.GetUid());
       
  1348     TUint uid2(item2.GetUid());
       
  1349     if ( uid1 == uid2 )
       
  1350         {
       
  1351         result = ETrue;
       
  1352         }
       
  1353     return result;
       
  1354     }
       
  1355 
       
  1356 
       
  1357 
       
  1358 //  End of File