menucontentsrv/srvsrc/menusrvfoldercrnotifier.cpp
changeset 0 79c6a41cd166
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 "menusrvfoldercrnotifier.h"
       
    18 //#include "menusrvappscanner.h"
       
    19 #include "menusrvengutils.h"
       
    20 
       
    21 #include "menusrvmmchistory.h"
       
    22 #include "menueng.h"
       
    23 #include "menuengobject.h"
       
    24 #include "mcsmenuitem.h"
       
    25 #include "pathinfo.h"
       
    26 #include "menulogger.h"
       
    27 #include "centralrepository.h"
       
    28 
       
    29 
       
    30 
       
    31 // ==================== MEMBER FUNCTIONS ====================
       
    32 
       
    33 // ---------------------------------------------------------
       
    34 // CMenuSrvFolderCrNotifier::NewL
       
    35 // ---------------------------------------------------------
       
    36 //
       
    37 CMenuSrvFolderCrNotifier* CMenuSrvFolderCrNotifier::NewL( CMenuEng& aEng )
       
    38     {
       
    39     CMenuSrvFolderCrNotifier* scanner = new (ELeave) CMenuSrvFolderCrNotifier( aEng );
       
    40     CleanupStack::PushL( scanner );
       
    41     scanner->ConstructL();
       
    42     CleanupStack::Pop( scanner );
       
    43     return scanner;
       
    44     }
       
    45 
       
    46 // ---------------------------------------------------------
       
    47 // CMenuSrvFolderCrNotifier::CMenuSrvFolderCrNotifier
       
    48 // ---------------------------------------------------------
       
    49 //
       
    50 CMenuSrvFolderCrNotifier::~CMenuSrvFolderCrNotifier()
       
    51     {
       
    52     iHiddenCRFolders.Close();
       
    53     iNewHiddenCRFolders.Close();
       
    54     
       
    55     Cancel();
       
    56     iEng.DequeueOperation( *this );
       
    57     iFs.Close();
       
    58 
       
    59     if( iCenRepNotifyHandlerCPHiddenFolders )
       
    60         {
       
    61         iCenRepNotifyHandlerCPHiddenFolders->StopListening();
       
    62         }
       
    63     delete iCenRepNotifyHandlerCPHiddenFolders;
       
    64   	delete iCenRepSession;
       
    65   	delete iFreeSpaceObserver;
       
    66 
       
    67     }
       
    68 
       
    69 // ---------------------------------------------------------
       
    70 // CMenuSrvAppScanner::CMenuSrvAppScanner
       
    71 // ---------------------------------------------------------
       
    72 //
       
    73 CMenuSrvFolderCrNotifier::CMenuSrvFolderCrNotifier( CMenuEng& aEng )
       
    74 : CActive( CActive::EPriorityStandard ), iEng( aEng )
       
    75     {
       
    76     CActiveScheduler::Add( this );
       
    77     iOpStatus = EFalse;
       
    78     }
       
    79 
       
    80 // ---------------------------------------------------------
       
    81 // CMenuSrvFolderCrNotifier::ConstructL
       
    82 // ---------------------------------------------------------
       
    83 //
       
    84 void CMenuSrvFolderCrNotifier::ConstructL()
       
    85     {
       
    86     User::LeaveIfError( iFs.Connect() );
       
    87     TFileName path;
       
    88     User::LeaveIfError( iFs.PrivatePath( path ) );
       
    89     TUint attribute;
       
    90     if( iFs.Att( path, attribute) == KErrNotFound )
       
    91     	{
       
    92 		TInt mdRes = iFs.MkDirAll( path );
       
    93 		if ( mdRes != KErrNone )
       
    94 			{
       
    95 			User::Leave( mdRes );
       
    96 			}
       
    97     	}
       
    98     
       
    99     iFreeSpaceObserver = CMcsFreeSpaceObserver::NewL( *this );
       
   100    	iCenRepSession = CRepository::NewL( KCRUidMenu );
       
   101 
       
   102 	iCenRepNotifyHandlerCPHiddenFolders = CCenRepNotifyHandler::NewL(
       
   103 	    *this, *iCenRepSession, 
       
   104 		CCenRepNotifyHandler::EStringKey, KMenuHideCPFolder );
       
   105 
       
   106 	iCenRepNotifyHandlerCPHiddenFolders->StartListeningL();
       
   107 	iHiddenCRFolders.CreateL( KCenRepBufferSize );
       
   108 	iNewHiddenCRFolders.CreateL( KCenRepBufferSize );
       
   109 	HandleNotifyString( KMenuHideCPFolder, KNullDesC() );
       
   110     }
       
   111 
       
   112 // ---------------------------------------------------------
       
   113 // CMenuSrvFolderCrNotifier::RunL
       
   114 // ---------------------------------------------------------
       
   115 //
       
   116 void CMenuSrvFolderCrNotifier::RunL()
       
   117     {
       
   118     User::LeaveIfError( iStatus.Int() ); // Handle errors in RunL.
       
   119     // Now queue this operation to be executed by the Engine.
       
   120     iEng.QueueOperationL( *this );
       
   121     }
       
   122 
       
   123 // ---------------------------------------------------------
       
   124 // CMenuSrvFolderCrNotifier::DoCancel
       
   125 // ---------------------------------------------------------
       
   126 //
       
   127 void CMenuSrvFolderCrNotifier::DoCancel()
       
   128     {
       
   129     }
       
   130 
       
   131 // ---------------------------------------------------------
       
   132 // CMenuSrvFolderCrNotifier::RunError
       
   133 // ---------------------------------------------------------
       
   134 //
       
   135 TInt CMenuSrvFolderCrNotifier::RunError( TInt /*aError*/ )
       
   136     {
       
   137     // Ignore the error 
       
   138     return KErrNone;
       
   139     }
       
   140 
       
   141 // ---------------------------------------------------------
       
   142 // CMenuSrvFolderScanner::HandleFreeSpaceEventL
       
   143 // ---------------------------------------------------------
       
   144 //
       
   145 void CMenuSrvFolderCrNotifier::HandleFreeSpaceEventL()
       
   146     {
       
   147     if ( !IsActive() && !iOpStatus )
       
   148         {
       
   149         iOpStatus = ETrue;
       
   150         TRequestStatus* ownStatus = &iStatus;
       
   151         *ownStatus = KRequestPending;
       
   152         SetActive();
       
   153         User::RequestComplete( ownStatus, KErrNone );
       
   154         }
       
   155     }
       
   156 
       
   157 // ---------------------------------------------------------
       
   158 // CMenuSrvFolderCrNotifier::RunMenuEngOperationL
       
   159 // ---------------------------------------------------------
       
   160 //
       
   161 void CMenuSrvFolderCrNotifier::RunMenuEngOperationL()
       
   162     {
       
   163     HandleNewCrHiddenFoldersL( iNewHiddenCRFolders );
       
   164     }
       
   165 
       
   166 // ---------------------------------------------------------
       
   167 // CMenuSrvFolderCrNotifier::CompletedMenuEngOperation
       
   168 // ---------------------------------------------------------
       
   169 //
       
   170 void CMenuSrvFolderCrNotifier::CompletedMenuEngOperation( TInt /*aErr*/ )
       
   171     {
       
   172     // If there was error, ignore it (what else could we do?).
       
   173     // When next AppArc update occurs, we will run again.
       
   174     }
       
   175 
       
   176 // -----------------------------------------------------------------------------
       
   177 // CMenuSrvFolderCrNotifier::HandleNotifyString
       
   178 // -----------------------------------------------------------------------------
       
   179 //
       
   180 void CMenuSrvFolderCrNotifier::HandleNotifyString( TUint32 aKey, 
       
   181         const TDesC16& aNewValue )
       
   182     {
       
   183     if (( aKey == KMenuHideCPFolder ))
       
   184         {
       
   185         iOpStatus = ETrue;
       
   186         TRequestStatus* ownStatus = &iStatus;
       
   187         *ownStatus = KRequestPending;
       
   188         SetActive();
       
   189         User::RequestComplete( ownStatus, KErrNone );
       
   190 
       
   191         iHiddenCRFolders = iNewHiddenCRFolders;
       
   192         iNewHiddenCRFolders = aNewValue;
       
   193         }
       
   194     }  
       
   195 
       
   196 
       
   197 // ---------------------------------------------------------
       
   198 // CMenuSrvFolderCrNotifier::ParseHiddenFoldersL
       
   199 // ---------------------------------------------------------
       
   200 //
       
   201 void CMenuSrvFolderCrNotifier::ParseHiddenFoldersL( 
       
   202             const TDesC& aHiddenFolders, RArray<TPtrC>& aHiddenFoldersArray )
       
   203     {
       
   204     TLex input( aHiddenFolders );
       
   205     TLexMark startMark;
       
   206     input.Mark( startMark ); 
       
   207     TBool notEmpty = false;
       
   208     while ( !input.Eos() )
       
   209         {
       
   210         if( input.Peek() == ',')
       
   211             {
       
   212             User::LeaveIfError( aHiddenFoldersArray.
       
   213                             Append( input.MarkedToken( startMark )  ) );            
       
   214             input.Inc();
       
   215             input.Mark( startMark );
       
   216             }
       
   217         input.Inc();     
       
   218         notEmpty = true;       
       
   219         }
       
   220 	if ( notEmpty )
       
   221 		{
       
   222 		User::LeaveIfError( aHiddenFoldersArray.
       
   223 						Append( input.MarkedToken( startMark )  ) );            
       
   224 		}
       
   225    }
       
   226 // ---------------------------------------------------------
       
   227 // CMenuSrvFolderCrNotifier::NotifyEngineL
       
   228 // ---------------------------------------------------------
       
   229 //
       
   230 void CMenuSrvFolderCrNotifier::NotifyEngineL( const TDesC& aFolder )
       
   231     {
       
   232 	//find id by group name
       
   233 	TInt root;
       
   234 	iEng.RootFolderL( root );
       
   235 	TMenuSrvTypeAttrFilter appFilter;
       
   236 	appFilter.SetType( KMenuTypeFolder() );
       
   237 	appFilter.SetAttr( KMenuAttrAppGroupName(), aFolder );
       
   238 	
       
   239 	RArray<TMenuItem> items; // All folders items.
       
   240 	CleanupClosePushL( items );
       
   241 	iEng.GetItemsL( items, root, &appFilter, ETrue );
       
   242 	for ( TInt j = 0; j < items.Count(); j++ )
       
   243 		{
       
   244 		//we append notification for parrent
       
   245 		iEng.ModifiableObjectL( items[j].Id(), RMenuNotifier::EItemsAddedRemoved );
       
   246 		}
       
   247 	
       
   248 	CleanupStack::PopAndDestroy( &items );
       
   249     }
       
   250 
       
   251 // ---------------------------------------------------------
       
   252 // CMenuSrvFolderCrNotifier::NotifyEngineL
       
   253 // ---------------------------------------------------------
       
   254 //
       
   255 void CMenuSrvFolderCrNotifier::HandleNewCrHiddenFoldersL( const TDesC& aNewHiddenFolders )
       
   256     {
       
   257 	RArray<TPtrC> hiddenFoldersArray;
       
   258     CleanupClosePushL( hiddenFoldersArray );
       
   259 	ParseHiddenFoldersL( iHiddenCRFolders, hiddenFoldersArray );
       
   260 	
       
   261 	RArray<TPtrC> newHiddenFoldersArray;
       
   262     CleanupClosePushL( newHiddenFoldersArray );
       
   263     ParseHiddenFoldersL( aNewHiddenFolders, newHiddenFoldersArray );
       
   264 
       
   265     //send notify for new values,
       
   266     NotifyEngineL( hiddenFoldersArray, newHiddenFoldersArray );
       
   267     //send notify for removed values,
       
   268     NotifyEngineL( newHiddenFoldersArray, hiddenFoldersArray );
       
   269     
       
   270     CleanupStack::PopAndDestroy( &newHiddenFoldersArray );
       
   271     CleanupStack::PopAndDestroy( &hiddenFoldersArray );
       
   272     }
       
   273 
       
   274 // ---------------------------------------------------------
       
   275 // CMenuSrvFolderCrNotifier::NotifyEngineL
       
   276 // ---------------------------------------------------------
       
   277 //
       
   278 void CMenuSrvFolderCrNotifier::NotifyEngineL( 
       
   279 		const RArray<TPtrC>& aLeftArray, 
       
   280 		const RArray<TPtrC>& aRightArray )
       
   281     {
       
   282   	for ( TInt i = 0; i < aRightArray.Count(); i++ )
       
   283  		{
       
   284         TInt id = aLeftArray.Find( aRightArray[i] );
       
   285         if ( id == KErrNotFound )
       
   286             {
       
   287             NotifyEngineL( aRightArray[i] );
       
   288             }
       
   289  		}
       
   290     }
       
   291 
       
   292 //  End of File  
       
   293