menucontentsrv/srvsrc/mcssuitehandler.cpp
branchRCL_3
changeset 23 ace62b58f4b2
parent 22 1b207dd38b72
child 25 9e077f9a342c
equal deleted inserted replaced
22:1b207dd38b72 23:ace62b58f4b2
     1 /*
       
     2 * Copyright (c) 2008 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 
       
    18 // INCLUDE FILES
       
    19 #include <badesca.h>
       
    20 #include <sacls.h>
       
    21 
       
    22 #include "mcssuitehandler.h"
       
    23 #include "menueng.h"
       
    24 #include "mcsinstallnotifier.h"
       
    25 #include "mcssuiteparser.h"
       
    26 #include "mcssuiteobject.h"
       
    27 #include "menusrvengutils.h"
       
    28 #include "mcsmenuitem.h"
       
    29 
       
    30 // ================= LOCAL FUNCTIONS =======================
       
    31 
       
    32 /**
       
    33 * Cleanup support method. Call ResetAndDestroy() on the array.
       
    34 * @param RMenuItemArray* as TAny*
       
    35 */
       
    36 LOCAL_C void ResetAndDestroy( TAny* aArray )
       
    37     {
       
    38     ((RPointerArray<CSuiteObject>*)aArray)->ResetAndDestroy();
       
    39     }
       
    40 
       
    41 // ---------------------------------------------------------
       
    42 // CleanupResetAndDestroyPushL
       
    43 // ---------------------------------------------------------
       
    44 //
       
    45 LOCAL_C void CleanupResetAndDestroyPushL( RPointerArray<CSuiteObject>& aArray )
       
    46     {
       
    47     CleanupStack::PushL( TCleanupItem( ResetAndDestroy, &aArray ) );
       
    48     }
       
    49 
       
    50 // ================= MEMBER FUNCTIONS =======================
       
    51 
       
    52 // ---------------------------------------------------------
       
    53 // CMcsSuiteHandler::NewL
       
    54 // ---------------------------------------------------------
       
    55 //
       
    56 CMcsSuiteHandler* CMcsSuiteHandler::NewL( CMenuEng& aEng, const TDesC& aDirName )
       
    57 	{
       
    58 	CMcsSuiteHandler* self = new( ELeave ) CMcsSuiteHandler( aEng );
       
    59 	CleanupStack::PushL( self );
       
    60 	self->ConstructL(aDirName);
       
    61 	CleanupStack::Pop( self );
       
    62 	return self;
       
    63 	}
       
    64 
       
    65 
       
    66 // ---------------------------------------------------------
       
    67 // CMcsSuiteHandler::~CMcsSuiteHandler
       
    68 // ---------------------------------------------------------
       
    69 //
       
    70 CMcsSuiteHandler::~CMcsSuiteHandler()
       
    71 	{
       
    72 	iSuites.ResetAndDestroy();
       
    73 	delete iMmcObserver;
       
    74 	delete iFreeSpaceObserver;
       
    75 	delete iInstallNotifier;
       
    76 	iTimestamps.Close();
       
    77 	iNewTimestamps.Close();
       
    78 	iEng.DequeueOperation( *this );
       
    79 	delete iInstalledFileList;
       
    80 	delete iFileNewList;
       
    81 	iDirPath.Close();
       
    82 	iFs.Close();
       
    83 	}
       
    84 
       
    85 
       
    86 // ---------------------------------------------------------
       
    87 // CMcsSuiteHandler::HaveSuite
       
    88 // ---------------------------------------------------------
       
    89 //
       
    90 TBool CMcsSuiteHandler::HaveSuite(const TDesC& aSuiteName)
       
    91 	{
       
    92 	return iSuites.Exist(aSuiteName);
       
    93 	}
       
    94 
       
    95 void CMcsSuiteHandler::GetAttribute( const TDesC& aSuiteName, const TDesC& aAttrName, 
       
    96 	TBool& aAttrExists, TDes& aAttrVal )
       
    97 	{
       
    98 	TInt suitePos = iSuites.FindLastSuite(aSuiteName);
       
    99 	if (suitePos != KErrNotFound)
       
   100 		{
       
   101 		iSuites[suitePos]->GetAttribute(aAttrName, aAttrExists, aAttrVal);
       
   102 		}
       
   103 	}
       
   104 
       
   105 // ---------------------------------------------------------
       
   106 // CMcsSuiteHandler::CMcsSuiteHandler
       
   107 // ---------------------------------------------------------
       
   108 //
       
   109 CMcsSuiteHandler::CMcsSuiteHandler( CMenuEng& aEng ) :
       
   110 	iEng(aEng)
       
   111 	{
       
   112 	}
       
   113 
       
   114 // ---------------------------------------------------------
       
   115 // CMcsSuiteHandler::ConstructL
       
   116 // ---------------------------------------------------------
       
   117 //
       
   118 void CMcsSuiteHandler::ConstructL(const TDesC& aDirName)
       
   119 	{
       
   120 	User::LeaveIfError( iFs.Connect( ) );
       
   121 	iDirPath.CreateL( KMaxPath );
       
   122 	User::LeaveIfError( iFs.PrivatePath( iDirPath ) );
       
   123 	iDirPath.Append(KImportDir);
       
   124 	iDirPath.Append(KBackSlash);
       
   125 	iDirPath.Append(aDirName);
       
   126 	iDirPath.Append(KBackSlash);
       
   127 	iFileNewList = new (ELeave) CDesCArrayFlat(KDefaultGranularity);
       
   128 	iInstalledFileList = new (ELeave) CDesCArrayFlat(KDefaultGranularity);
       
   129 	iInstallNotifier = CMcsInstallNotifier::NewL(*this, KSAUidSoftwareInstallKeyValue);
       
   130 	iMmcObserver = CMcsMmcObserver::NewL( *this );
       
   131 	iFreeSpaceObserver = CMcsFreeSpaceObserver::NewL( *this );
       
   132 	// Import suites form suite dir
       
   133 	CheckSuiteDirL();
       
   134 	iEvent = EInstOpRestore;
       
   135 	iEng.QueueOperationL( *this );
       
   136 	}
       
   137     
       
   138 
       
   139 // ---------------------------------------------------------
       
   140 // CMcsSuiteHandler::HandleInstallNotifyL
       
   141 // ---------------------------------------------------------
       
   142 //
       
   143 void CMcsSuiteHandler::HandleInstallNotifyL(TInt aEvent)
       
   144 	{
       
   145 	// Look for new files
       
   146     CheckSuiteDirL();
       
   147     iEvent = aEvent;
       
   148     iEng.QueueOperationL( *this );
       
   149     }
       
   150 
       
   151 // ---------------------------------------------------------
       
   152 // CMcsSuiteHandler::HandleMmcEventL
       
   153 // ---------------------------------------------------------
       
   154 //
       
   155 void CMcsSuiteHandler::HandleMmcEventL(TInt aEvent)
       
   156     {
       
   157     CheckSuiteDirL();
       
   158     if (aEvent == EMmcInsert)
       
   159         {
       
   160         iEvent = EInstOpInstall;
       
   161         }
       
   162     else if (aEvent == EMmcRemove)
       
   163         {
       
   164         iEvent = EInstOpUninstall;
       
   165         }
       
   166     iEng.QueueOperationL( *this );
       
   167     }
       
   168 
       
   169 // ---------------------------------------------------------
       
   170 // CMcsSuiteHandler::HandleFreeSpaceEventL
       
   171 // ---------------------------------------------------------
       
   172 //
       
   173 void CMcsSuiteHandler::HandleFreeSpaceEventL()
       
   174     {
       
   175     CheckSuiteDirL();
       
   176     iEvent = EInstOpUninstall;
       
   177     iEng.QueueOperationL( *this );
       
   178     }
       
   179 
       
   180 // ---------------------------------------------------------
       
   181 // CMcsSuiteHandler::CheckSuiteDirL
       
   182 // ---------------------------------------------------------
       
   183 //
       
   184 void CMcsSuiteHandler::CheckSuiteDirL()
       
   185 	{
       
   186 	// Get file list
       
   187 	iFileNewList->Reset();
       
   188 	iNewTimestamps.Reset();
       
   189 
       
   190 	TDriveList driveList;
       
   191 	TChar driveLetter;
       
   192 	User::LeaveIfError(iFs.DriveList(driveList));
       
   193 	for (TInt driveNumber = EDriveA; driveNumber <= EDriveZ; driveNumber++)
       
   194 		{
       
   195 		if (driveList[driveNumber])
       
   196 			{
       
   197 			User::LeaveIfError(iFs.DriveToChar(driveNumber, driveLetter));
       
   198 			RBuf filePath;
       
   199 			filePath.CreateL(KMaxPath);
       
   200 			CleanupClosePushL(filePath);
       
   201 			filePath.Append(driveLetter);
       
   202 			filePath.Append(KColen);
       
   203 			filePath.Append(iDirPath);
       
   204 			CDir* fileList;
       
   205 			
       
   206 			iFs.GetDir(filePath, KEntryAttMaskSupported,
       
   207 					ESortByName, fileList);
       
   208 			
       
   209 			CleanupStack::PopAndDestroy(&filePath);
       
   210 			if (fileList)
       
   211 				{
       
   212 				CleanupStack::PushL(fileList);
       
   213 				for (TInt i = 0; i < fileList->Count(); i++)
       
   214 					{
       
   215 					// Not dir, xml file
       
   216 					if (!(*fileList)[i].IsDir() && ValidExtansion(
       
   217 							(*fileList)[i].iName))
       
   218 						{
       
   219 						// Don't add same file names more then once
       
   220 						// Or else it will case trouble during update
       
   221 						TInt dummy;
       
   222 						if ( iFileNewList->Find((*fileList)[i].iName, dummy) )
       
   223 							{
       
   224 							iFileNewList->AppendL((*fileList)[i].iName);
       
   225 							iNewTimestamps.AppendL((*fileList)[i].iModified);
       
   226 							}
       
   227 						}
       
   228 					}
       
   229 				CleanupStack::PopAndDestroy(fileList);
       
   230 				}
       
   231 			}
       
   232 		}
       
   233 	}
       
   234 
       
   235 // ---------------------------------------------------------
       
   236 // CMcsSuiteHandler::AddNewL
       
   237 // ---------------------------------------------------------
       
   238 //
       
   239 void CMcsSuiteHandler::AddNew()
       
   240 	{
       
   241 	for ( TInt i = 0; i < iFileNewList->Count(); i++ )
       
   242 		{
       
   243 		TPtrC fileNewName = (*iFileNewList)[i];
       
   244 		TTime fileTimestamp = iNewTimestamps[i];
       
   245 		
       
   246 		if ( !FileInstalled(fileNewName) )
       
   247 			{
       
   248 			// Not yet installed, install it
       
   249 			TRAP_IGNORE( InstallFileL(fileNewName, fileTimestamp) );
       
   250 			}
       
   251 		else if (FileNeedUpdate(fileNewName, fileTimestamp) )
       
   252 			{
       
   253 			//Installed, but needs update
       
   254 			TRAP_IGNORE( UpdateFileL( fileNewName, fileTimestamp) );
       
   255 			}
       
   256 		}
       
   257 	}
       
   258 
       
   259 // ---------------------------------------------------------
       
   260 // CMcsSuiteHandler::RemoveOldL
       
   261 // ---------------------------------------------------------
       
   262 //
       
   263 void CMcsSuiteHandler::RemoveOld()
       
   264 	{
       
   265 	for ( TInt i = 0; i < iInstalledFileList->Count(); i++ )
       
   266 		{
       
   267 		TPtrC fileNewName = (*iInstalledFileList)[i]; 
       
   268 
       
   269 		// File was removed, unistall it
       
   270 		if ( FileUninstalled(fileNewName) )
       
   271 			{
       
   272 			TRAP_IGNORE( UninstallFileL(fileNewName) );
       
   273 			}
       
   274 		}
       
   275 	iInstalledFileList->Compress();
       
   276 	}
       
   277 
       
   278 // ---------------------------------------------------------
       
   279 // CMcsSuiteHandler::ScanSuitesL
       
   280 // ---------------------------------------------------------
       
   281 //
       
   282 void CMcsSuiteHandler::ScanSuitesL()
       
   283 	{
       
   284 	RArray<TMenuItem> suiteItems; 
       
   285 	CleanupClosePushL( suiteItems );
       
   286 	GetMenuSuitesL( suiteItems, KMenuAttSuiteAdded(), KMenuTrue() );
       
   287 	
       
   288 	for ( TInt i = 0; i < suiteItems.Count(); i++ )
       
   289 		{
       
   290 		TBool dummy(EFalse);
       
   291 		TPtrC suiteName(KNullDesC);
       
   292 		iEng.ObjectL( suiteItems[i].Id() ).
       
   293 			FindAttribute( KMenuAttSuiteName, suiteName, dummy );
       
   294 
       
   295 		if ( !HaveSuite( suiteName ) )
       
   296 			{
       
   297 			iEng.RemoveL( suiteItems[i].Id() );
       
   298 			}
       
   299 		}
       
   300 	CleanupStack::PopAndDestroy(&suiteItems);
       
   301 	}
       
   302 
       
   303 // ---------------------------------------------------------
       
   304 // CMcsSuiteHandler::FileExistL
       
   305 // ---------------------------------------------------------
       
   306 //
       
   307 TBool CMcsSuiteHandler::FileInstalled(const TDesC& aFileName)
       
   308 	{
       
   309 	TInt posInArray;
       
   310 	// uses Folded Comparing
       
   311 	if (iInstalledFileList->Find(aFileName, posInArray) == KErrNone)
       
   312 		{
       
   313 		return ETrue;
       
   314 		}
       
   315 	return EFalse;
       
   316 	}
       
   317 
       
   318 // ---------------------------------------------------------
       
   319 // CMcsSuiteHandler::FileUninstalled
       
   320 // ---------------------------------------------------------
       
   321 //
       
   322 TBool CMcsSuiteHandler::FileUninstalled(const TDesC& aFileName)
       
   323 	{
       
   324 	for (TInt j = 0 ; j < iFileNewList->Count(); j++)
       
   325 		{
       
   326 		if ( !(*iFileNewList)[j].Compare( aFileName ) )
       
   327 			{
       
   328 			// Wasn't removed but maybe needs to be updated (rom case)
       
   329 			return FileNeedUpdate(aFileName, iNewTimestamps[j]);
       
   330 			}
       
   331 		}
       
   332 	return ETrue;
       
   333 	}
       
   334 
       
   335 // ---------------------------------------------------------
       
   336 // CMcsSuiteHandler::FileNeedUpdate
       
   337 // ---------------------------------------------------------
       
   338 //
       
   339 TBool CMcsSuiteHandler::FileNeedUpdate(const TDesC& aFileName, const TTime& aTimestamp)
       
   340 	{
       
   341 	TInt posInArray;
       
   342 	// uses Folded Comparing
       
   343 	if (iInstalledFileList->Find(aFileName, posInArray) == KErrNone)
       
   344 		{
       
   345 		// If timestamps mach then it's the same file
       
   346 		return (iTimestamps[posInArray] != aTimestamp);
       
   347 		}
       
   348 	return EFalse;
       
   349 	}
       
   350 
       
   351 // ---------------------------------------------------------
       
   352 // CMcsSuiteHandler::ValidExtansion
       
   353 // ---------------------------------------------------------
       
   354 //
       
   355 TBool CMcsSuiteHandler::ValidExtansion(const TDesC& aFileName)
       
   356 	{
       
   357 	TPtrC fileExt = 
       
   358 		aFileName.Mid( aFileName.LocateReverse( KDot ) + 1 );
       
   359 
       
   360 	return ( fileExt.CompareF(KXmlExt) == 0 );
       
   361 	}
       
   362 
       
   363 
       
   364 // ---------------------------------------------------------
       
   365 // CMcsSuiteHandler::InstallFile
       
   366 // ---------------------------------------------------------
       
   367 //
       
   368 void CMcsSuiteHandler::InstallFileL(const TDesC& aFileName, const TTime& aTimestam)
       
   369 	{	
       
   370 	RPointerArray<CSuiteObject> suiteArray;
       
   371 	CleanupResetAndDestroyPushL(suiteArray);
       
   372 	
       
   373 	// Get suite from suite file
       
   374 	GetSuitesL(aFileName, suiteArray);
       
   375 	
       
   376 	//Add filename to installed suites files array
       
   377 	//If Leave occured during GetSuitesL filename wont be added 
       
   378 	iInstalledFileList->AppendL(aFileName);
       
   379 	iTimestamps.AppendL(aTimestam);
       
   380 	
       
   381 	// Take the ownership of suite items
       
   382 	for (TInt i = 0; i < suiteArray.Count(); i++ )
       
   383 		{
       
   384 		User::LeaveIfError( iSuites.Append( suiteArray[i] ) );
       
   385         TRAPD( err, AddSuiteL( suiteArray[i]->SuiteName() ) );
       
   386 		if( err!=KErrNone )
       
   387 		    {
       
   388 		    if( i==0 )
       
   389                 {
       
   390                 iInstalledFileList->Delete( iInstalledFileList->Count()-1 );
       
   391                 iTimestamps.Remove( iTimestamps.Count()-1 );
       
   392                 }
       
   393             iSuites.Remove( iSuites.Count()-1 );
       
   394             User::Leave( err );
       
   395 		    }
       
   396 		suiteArray[i] = NULL;
       
   397 		}
       
   398 	CleanupStack::Pop(&suiteArray);
       
   399 	suiteArray.Close();
       
   400 	}
       
   401 
       
   402 // ---------------------------------------------------------
       
   403 // CMcsSuiteHandler::UninstallFile
       
   404 // ---------------------------------------------------------
       
   405 //
       
   406 void CMcsSuiteHandler::UninstallFileL(const TDesC& aFileName)
       
   407 	{
       
   408 	TInt pos(KErrNotFound);
       
   409 	if ( !iInstalledFileList->Find(aFileName, pos))
       
   410 		{
       
   411 		
       
   412 		// Need to know what suites are beeing removed
       
   413 		CDesCArrayFlat* removedSuites = 
       
   414 			new (ELeave) CDesCArrayFlat(KDefaultGranularity);
       
   415 		CleanupStack::PushL(removedSuites);
       
   416 		for (TInt i = 0; i < iSuites.Count(); i++)
       
   417 			{
       
   418 			if ( aFileName.Compare( iSuites[i]->FileName() ) == KErrNone )
       
   419 			    {
       
   420 				removedSuites->AppendL( iSuites[i]->SuiteName() );
       
   421 				}
       
   422 			}
       
   423 		
       
   424 		// We know what suites are beeing removed, we can remove those safly
       
   425 		iSuites.RemoveByFileName(aFileName);
       
   426 		
       
   427 		// Remove uninstalled file from our list
       
   428 		iInstalledFileList->Delete(pos);
       
   429 		iTimestamps.Remove(pos);
       
   430 		
       
   431 		// And reopen removed suites defined in other files
       
   432 		for (TInt i = 0; i < removedSuites->Count(); i++)
       
   433 			{
       
   434 			TInt suitePos = iSuites.FindLastSuite( (*removedSuites)[i] );
       
   435 			if (suitePos != KErrNotFound)
       
   436 				{
       
   437 				ReopenSuiteL(suitePos);
       
   438 				}
       
   439 			else
       
   440 			    {
       
   441 			    RemoveSuiteFromXmlL( (*removedSuites)[i] );
       
   442 			    }
       
   443 			}
       
   444 
       
   445 		CleanupStack::PopAndDestroy(removedSuites);
       
   446 		}
       
   447 	}
       
   448 
       
   449 // ---------------------------------------------------------
       
   450 // CMcsSuiteHandler::UpdateFileL
       
   451 // ---------------------------------------------------------
       
   452 //
       
   453 void CMcsSuiteHandler::UpdateFileL(const TDesC& aFileName, const TTime& aTimestam)
       
   454 	{
       
   455 	TInt pos;
       
   456 	if (iInstalledFileList->Find(aFileName, pos) == KErrNone)
       
   457 		{
       
   458 		// Get rid of out of date suites
       
   459 		iSuites.RemoveByFileName(aFileName);
       
   460 		iInstalledFileList->Delete(pos);
       
   461 		//iInstalledFileList->Compress();
       
   462 		iTimestamps.Remove(pos);
       
   463 		
       
   464 		// Instal suites form file name 
       
   465 		InstallFileL(aFileName, aTimestam);
       
   466 		}
       
   467 	}
       
   468 
       
   469 // ---------------------------------------------------------
       
   470 // CMcsSuiteHandler::GetSuites
       
   471 // ---------------------------------------------------------
       
   472 //
       
   473 void CMcsSuiteHandler::GetSuitesL(const TDesC& aFileName, 
       
   474 		RPointerArray<CSuiteObject>& aSuiteArray)
       
   475 	{
       
   476 	TDriveList driveList;
       
   477     TChar driveLetter;
       
   478     User::LeaveIfError( iFs.DriveList( driveList ) );
       
   479     for ( TInt driveNumber = EDriveZ; driveNumber >= EDriveA; driveNumber-- )
       
   480         {
       
   481         if ( driveList[driveNumber] )
       
   482             {
       
   483             User::LeaveIfError( iFs.DriveToChar( driveNumber, driveLetter ) );
       
   484             RBuf file;
       
   485             file.CleanupClosePushL();
       
   486             file.CreateL( KMaxPath );
       
   487             file.Append( driveLetter );
       
   488             file.Append( KColen );
       
   489             file.Append( iDirPath );
       
   490             file.Append( aFileName );
       
   491             CSuiteParser* suiteParser = CSuiteParser::NewL(file);
       
   492             CleanupStack::PushL(suiteParser);
       
   493             TRAP_IGNORE( suiteParser->GetSuitsArrayL( aSuiteArray ) );
       
   494             CleanupStack::PopAndDestroy(suiteParser);
       
   495             CleanupStack::PopAndDestroy( &file );
       
   496             }
       
   497         }
       
   498 	}
       
   499 
       
   500 // ---------------------------------------------------------
       
   501 // CMcsSuiteHandler::ReopenSuite
       
   502 // ---------------------------------------------------------
       
   503 //
       
   504 void CMcsSuiteHandler::ReopenSuiteL(TInt aSuiteArrayPos)
       
   505 	{
       
   506 	RPointerArray<CSuiteObject> suiteArray;
       
   507 	CleanupResetAndDestroyPushL(suiteArray);
       
   508 	
       
   509 	TPtrC suiteName = iSuites[aSuiteArrayPos]->SuiteName();
       
   510 	TPtrC fileName = iSuites[aSuiteArrayPos]->FileName();
       
   511 	
       
   512 	// Get suite from suite file
       
   513 	GetSuitesL(fileName, suiteArray);
       
   514 	
       
   515 	// Find our suite in suites from specified file
       
   516 	CSuiteObject* neededSuite = NULL;
       
   517 	for (TInt j = 0; j < suiteArray.Count(); j++)
       
   518 		{
       
   519 		if (suiteArray[j]->SuiteName().Compare(suiteName) == KErrNone)
       
   520 			{
       
   521 			// Take ownership of Suite Object
       
   522 			neededSuite = suiteArray[j];
       
   523 			suiteArray.Remove(j);
       
   524 			break;
       
   525 			}
       
   526 		}
       
   527 	
       
   528 	if ( neededSuite )
       
   529 		{
       
   530 		// Replace Suite Object in suiteArray
       
   531 		delete iSuites[aSuiteArrayPos];
       
   532 		iSuites[aSuiteArrayPos] = neededSuite;
       
   533 		}
       
   534 	else
       
   535 		{
       
   536 		// Must be some error, delete that suite
       
   537 		delete iSuites[aSuiteArrayPos];
       
   538 		iSuites.Remove( aSuiteArrayPos );
       
   539 		}
       
   540 	
       
   541 	CleanupStack::PopAndDestroy(&suiteArray);
       
   542 	}
       
   543 
       
   544 // ---------------------------------------------------------
       
   545 // CMcsSuiteHandler::GetMenuSuitesL
       
   546 // ---------------------------------------------------------
       
   547 //
       
   548 void CMcsSuiteHandler::GetMenuSuitesL( 
       
   549 		RArray<TMenuItem>& aItemArray, 
       
   550 		const TDesC& aAttrName, 
       
   551 		const TDesC& aAttrValue )
       
   552     {
       
   553     TInt root( 0 );
       
   554     iEng.RootFolderL( root );
       
   555     TMenuSrvTypeAttrFilter suiteFilter;
       
   556     suiteFilter.SetType( KMenuTypeSuite() );   
       
   557     suiteFilter.SetAttr( aAttrName, aAttrValue );
       
   558     iEng.GetItemsL( aItemArray, root, &suiteFilter, ETrue );
       
   559     }
       
   560 
       
   561 // ---------------------------------------------------------
       
   562 // CMcsSuiteHandler::AddSuiteL
       
   563 // ---------------------------------------------------------
       
   564 //
       
   565 void CMcsSuiteHandler::AddSuiteL( const TPtrC& aSuiteName )
       
   566     {
       
   567     RArray<TMenuItem> mcsItems; 
       
   568     CleanupClosePushL( mcsItems );
       
   569     GetMenuSuitesL( mcsItems, KMenuAttSuiteName(), aSuiteName );
       
   570     
       
   571     if( mcsItems.Count() == KErrNone )
       
   572         {
       
   573         AddSuiteToXmlL( aSuiteName );
       
   574         }
       
   575     else
       
   576         {
       
   577         UpdateItemsL( mcsItems );
       
   578         }
       
   579     CleanupStack::PopAndDestroy(&mcsItems);
       
   580     }
       
   581 
       
   582 
       
   583 // ---------------------------------------------------------
       
   584 // CMcsSuiteHandler::AddSuiteL
       
   585 // ---------------------------------------------------------
       
   586 //
       
   587 void CMcsSuiteHandler::RemoveSuiteFromXmlL( const TPtrC& aSuiteName )
       
   588     {
       
   589     RArray<TMenuItem> mcsItems; 
       
   590     CleanupClosePushL( mcsItems );
       
   591     GetMenuSuitesL( mcsItems, KMenuAttSuiteName(), aSuiteName );
       
   592 
       
   593     for( TInt i( 0 ); i < mcsItems.Count(); i++ )
       
   594         {
       
   595         UpdateSuiteInXmlL( mcsItems, i );
       
   596         }
       
   597     
       
   598     CleanupStack::PopAndDestroy(&mcsItems);
       
   599     }
       
   600 
       
   601 // ---------------------------------------------------------
       
   602 // CMcsSuiteHandler::UpdateSuiteInXmlL
       
   603 // ---------------------------------------------------------
       
   604 //
       
   605 void CMcsSuiteHandler::UpdateSuiteInXmlL( 
       
   606 		RArray<TMenuItem> & aMcsItems, TInt aIndex )
       
   607 	{
       
   608 	TBool dummy(EFalse);
       
   609 	TPtrC val(KNullDesC);
       
   610 	if( iEng.ObjectL(aMcsItems[aIndex].Id()).
       
   611 			FindAttribute( KMenuAttSuiteAdded, val, dummy ) )
       
   612 		{
       
   613 		if ( val.Compare(KMenuTrue) == KErrNone )
       
   614 			{
       
   615 			iEng.RemoveL(aMcsItems[aIndex].Id());
       
   616 			}
       
   617 		else if ( val.Compare(KMenuFalse) == KErrNone )
       
   618 			{
       
   619 			iEng.ModifiableObjectL(aMcsItems[aIndex].Id()).
       
   620 				RemoveAttribute( KMenuAttSuiteAdded );
       
   621 			}
       
   622 		}
       
   623 	}
       
   624 
       
   625 // ---------------------------------------------------------
       
   626 // CMcsSuiteHandler::RunMenuEngOperationL
       
   627 // ---------------------------------------------------------
       
   628 //
       
   629 void CMcsSuiteHandler::RunMenuEngOperationL()
       
   630     {
       
   631     if ( iEvent & EInstOpInstall )
       
   632         {
       
   633         // Add new suites
       
   634         AddNew();
       
   635         }
       
   636     else if ( ( iEvent & EInstOpUninstall ) )
       
   637         {
       
   638         // Remove old suites, andd new if needed (stub sis case)
       
   639         RemoveOld();
       
   640         AddNew();
       
   641         }
       
   642     else if( ( iEvent & EInstOpRestore ) )
       
   643     	{
       
   644         AddNew();
       
   645         ScanSuitesL();
       
   646     	}
       
   647     }
       
   648 
       
   649 // ---------------------------------------------------------
       
   650 // CMcsSuiteHandler::CompletedMenuEngOperation
       
   651 // ---------------------------------------------------------
       
   652 //
       
   653 void CMcsSuiteHandler::CompletedMenuEngOperation( TInt /*aErr*/ )
       
   654     {
       
   655     
       
   656     }
       
   657 // ---------------------------------------------------------
       
   658 // CMcsSuiteHandler::AddSuiteToXmlL
       
   659 // ---------------------------------------------------------
       
   660 //
       
   661 void CMcsSuiteHandler::AddSuiteToXmlL( const TPtrC& aSuiteName )
       
   662     {
       
   663     TInt root( 0 );
       
   664     iEng.RootFolderL( root );
       
   665     
       
   666     CMenuEngObject* obj = iEng.NewObjectL( KMenuTypeSuite );
       
   667     CleanupStack::PushL( obj );
       
   668     obj->SetAttributeL( KMenuAttSuiteName, aSuiteName, EFalse );
       
   669     obj->SetAttributeL( KMenuAttSuiteAdded, KMenuTrue, EFalse );
       
   670     iEng.AddL( *obj, root, 0 );
       
   671     CleanupStack::Pop( obj );
       
   672     }
       
   673 
       
   674 // ---------------------------------------------------------
       
   675 // CMcsSuiteHandler::UpdateItemsL
       
   676 // ---------------------------------------------------------
       
   677 //
       
   678 void CMcsSuiteHandler::UpdateItemsL( 
       
   679     const RArray<TMenuItem>& aItemArray )
       
   680     {
       
   681     for( TInt i( 0 ); i < aItemArray.Count(); ++i )
       
   682         {
       
   683         TPtrC val(KNullDesC);
       
   684         TBool dummy( EFalse );
       
   685         iEng.ObjectL( aItemArray[i].Id() ).
       
   686             FindAttribute( KMenuAttSuiteAdded, val, dummy );
       
   687         if( val.Compare( KMenuTrue ) != KErrNone )
       
   688             {
       
   689             iEng.ModifiableObjectL( aItemArray[i].Id() ).
       
   690                         SetAttributeL( KMenuAttSuiteAdded, KMenuFalse, EFalse);
       
   691             }
       
   692         else
       
   693         	{
       
   694         	iEng.ModifiableObjectL( aItemArray[i].Id() ).
       
   695         	            SetAttributeL( KMenuAttSuiteAdded, KMenuTrue, EFalse);
       
   696         	}
       
   697         }
       
   698     }
       
   699