menufw/hierarchynavigator/hnmetadatamodel/src/hnxmlmodelprovider.cpp
branchv5backport
changeset 14 1abc632eb502
parent 13 6205fd287e8a
child 20 636d517f67e6
equal deleted inserted replaced
13:6205fd287e8a 14:1abc632eb502
     1 /*
       
     2 * Copyright (c) 2007-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 <sysutil.h> 
       
    19 #include "hnxmlmodelprovider.h"
       
    20 #include "hnxmlmodelcache.h"	
       
    21 #include "hnxmlsuitefilesreg.h"
       
    22 #include "hnglobals.h"
       
    23 #include "hnconvutils.h"
       
    24 #include "menudebug.h"
       
    25 #include "hnhelper.inl"
       
    26 #include "hnmdmodel.h"
       
    27 #include "hnmdmenuitem.h"
       
    28 
       
    29 // ======== MEMBER FUNCTIONS ========
       
    30 
       
    31 // ---------------------------------------------------------------------------
       
    32 // 
       
    33 // ---------------------------------------------------------------------------
       
    34 //
       
    35 void CHnXmlModelProvider::ConstructL()
       
    36 	{
       
    37 	iDomImpl.OpenL();
       
    38 	User::LeaveIfError(iDomParser.Open(iDomImpl));
       
    39 	User::LeaveIfError(iFs.Connect());
       
    40 	iFileMan = CFileMan::NewL(iFs);
       
    41 
       
    42 	iPath.CreateL(KMaxPath);
       
    43 	User::LeaveIfError(iFs.PrivatePath(iPath));
       
    44 	iPath.Insert(0, KDrive);
       
    45 	iPath.Append(KEntriesSuffix);
       
    46 	iCache = CHnXmlModelCache::NewL();
       
    47 	
       
    48 	CActiveScheduler::Add( this);
       
    49 	}
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 // 
       
    53 // ---------------------------------------------------------------------------
       
    54 //
       
    55 void CHnXmlModelProvider::DoCancel()
       
    56 	{
       
    57 	
       
    58 	}
       
    59 
       
    60 // ---------------------------------------------------------------------------
       
    61 // 
       
    62 // ---------------------------------------------------------------------------
       
    63 //
       
    64 void CHnXmlModelProvider::SynchronizationFinishedL()
       
    65 	{
       
    66 	ResetCache();
       
    67 	THnMdCommonPointers &cmnPtr = *THnMdCommonPointers::Static();
       
    68 	CHnMdModel* model = cmnPtr.iModel;
       
    69 	if ( iSuiteFilesUpdated )
       
    70 	    {
       
    71 	    model->ReloadStackSuitesL( cmnPtr.iContainer );
       
    72 	    }
       
    73 	}
       
    74 // ---------------------------------------------------------------------------
       
    75 // 
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 void CHnXmlModelProvider::RunL()
       
    79 	{
       
    80 	if ( !iSuiteSetIterator )
       
    81 		{
       
    82 		CheckDrivesL();
       
    83 	    iSuiteSetIterator = new ( ELeave ) THashSetIter<HBufC*>( iInstSuites );
       
    84 	    iSuiteSetIterator->Reset();
       
    85 	    iStatus = KRequestPending;
       
    86 	    SetActive();
       
    87 	    TRequestStatus* status = &iStatus;
       
    88 	    User::RequestComplete( status, KErrNone );
       
    89 		}
       
    90 	else if ( iSuiteSetIterator->Next() )
       
    91 		{
       
    92 		TBool filesUpdated = CHnXmlSuiteFilesReg::SynchronizeL(
       
    93                 iFs, **(iSuiteSetIterator->Current()) );
       
    94         iSuiteFilesUpdated = ( iSuiteFilesUpdated || filesUpdated ); 
       
    95 	    iStatus = KRequestPending;
       
    96 	    SetActive();
       
    97 	    TRequestStatus* status = &iStatus;
       
    98 	    User::RequestComplete( status, KErrNone );
       
    99 		}
       
   100 	else
       
   101 		{
       
   102 		delete iSuiteSetIterator;
       
   103 		iSuiteSetIterator = NULL;
       
   104 		SynchronizationFinishedL();
       
   105 		}
       
   106 	}
       
   107 	
       
   108 // ---------------------------------------------------------------------------
       
   109 // 
       
   110 // ---------------------------------------------------------------------------
       
   111 //
       
   112 EXPORT_C CHnXmlModelProvider* CHnXmlModelProvider::NewL()
       
   113 	{
       
   114 	CHnXmlModelProvider* self = CHnXmlModelProvider::NewLC();
       
   115 	CleanupStack::Pop(self);
       
   116 	return self;
       
   117 	}
       
   118 
       
   119 // ---------------------------------------------------------------------------
       
   120 // 
       
   121 // ---------------------------------------------------------------------------
       
   122 //
       
   123 EXPORT_C CHnXmlModelProvider* CHnXmlModelProvider::NewLC()
       
   124 	{
       
   125 	CHnXmlModelProvider* self = new (ELeave) CHnXmlModelProvider;
       
   126 	CleanupStack::PushL(self);
       
   127 	self->ConstructL();
       
   128 	return self;
       
   129 	}
       
   130 
       
   131 // ---------------------------------------------------------------------------
       
   132 // 
       
   133 // ---------------------------------------------------------------------------
       
   134 //
       
   135 CHnXmlModelProvider::CHnXmlModelProvider() :
       
   136 	CActive( EPriorityLow ),	
       
   137 	iInstSuites(&HBuf16Hash, &HBuf16Ident),
       
   138 	iEventMap(&HBuf16Hash, &HBuf16Ident), 
       
   139 	iSuiteSetIterator( NULL )
       
   140 	{
       
   141 	 
       
   142 	}
       
   143 
       
   144 // ---------------------------------------------------------------------------
       
   145 // 
       
   146 // ---------------------------------------------------------------------------
       
   147 //
       
   148 EXPORT_C CHnXmlModelProvider::~CHnXmlModelProvider()
       
   149 	{
       
   150 	Cancel(); 
       
   151 	
       
   152 	delete iSuiteSetIterator;
       
   153 	delete iCache;
       
   154 	iDomParser.Close();
       
   155 	iDomImpl.Close();
       
   156 	delete iFileMan;
       
   157 	iFs.Close();
       
   158 	iPath.Close();
       
   159 
       
   160 	// clean up eventmap
       
   161 	THashMapIter<HBufC*, TInt> iter(iEventMap);
       
   162 	while (HBufC* const * ptr = iter.NextKey())
       
   163 		{
       
   164 		delete *ptr;
       
   165 		}
       
   166 	iEventMap.Close();
       
   167 
       
   168 	THashSetIter<HBufC*> iterSuites(iInstSuites);
       
   169 	while ( iterSuites.Next())
       
   170 		{
       
   171 		delete *iterSuites.Current();
       
   172 		}
       
   173 	iInstSuites.Close();
       
   174 
       
   175 	}
       
   176 
       
   177 #ifdef _DEBUG
       
   178 // ---------------------------------------------------------------------------
       
   179 // 
       
   180 // ---------------------------------------------------------------------------
       
   181 //
       
   182 void CHnXmlModelProvider::LogEventMapping(
       
   183 		const RHashMap<HBufC*, TInt>& aEventMap)
       
   184 	{
       
   185     DEBUG(("\t_MM_: CHnXmlModelProvider::LogEventMapping IN"));
       
   186     RFs fs;
       
   187     if ( !fs.Connect() )
       
   188         {
       
   189         RFile logFile;
       
   190         if ( !logFile.Replace( fs, KEventMapLogFile, EFileWrite ) )
       
   191             {
       
   192             // first line
       
   193             TBuf8<256> buf1;
       
   194             buf1.Append( _L8("EventName") );
       
   195             buf1.Append( _L8("\t") );
       
   196             buf1.Append( _L8("EventId") );
       
   197             buf1.Append( _L8("\n") );
       
   198             logFile.Write( 0, buf1 );                    
       
   199             THashMapIter<HBufC*, TInt> iter( aEventMap );
       
   200             while ( HBufC* const * ptr = iter.NextKey() )
       
   201                 {
       
   202                 TInt *v = iter.CurrentValue();
       
   203                 TBuf8<256> buf2;
       
   204                 buf2.Append( (*ptr)->Des() );
       
   205                 buf2.Append( _L8("\t") );
       
   206                 buf2.AppendNum( *v );
       
   207                 buf2.Append( _L8("\n") );
       
   208                 TInt size ( 0 );
       
   209                 logFile.Size( size );
       
   210                 logFile.Write( size, buf2 );
       
   211                 }
       
   212             logFile.Close();
       
   213             }
       
   214         fs.Close();
       
   215         }
       
   216     DEBUG(("\t_MM_: CHnXmlModelProvider::LogEventMapping OUT"));
       
   217     }
       
   218 
       
   219 // ---------------------------------------------------------------------------
       
   220 // 
       
   221 // ---------------------------------------------------------------------------
       
   222 // 
       
   223 void CHnXmlModelProvider::LogSuiteModel( const TDesC& aName, 
       
   224                                                     RXmlEngDocument& aDoc )
       
   225     {
       
   226     DEBUG(("\t_MM_: CHnXmlModelProvider::LogSuiteModel IN"));
       
   227     TBuf8<256> buf1;
       
   228     TFileName logFileName;
       
   229     logFileName.Copy( KSuiteLoadingLogFile );
       
   230     logFileName.Append( Kbackslash );
       
   231     logFileName.Append( aName );
       
   232     logFileName.Append( KXmlExt );
       
   233     TRAP_IGNORE( aDoc.SaveL( logFileName, aDoc.DocumentElement() ) );
       
   234     DEBUG(("\t_MM_: CHnXmlModelProvider::LogSuiteModel OUT"));
       
   235     }
       
   236 #endif
       
   237 
       
   238 // ---------------------------------------------------------------------------
       
   239 // 
       
   240 // ---------------------------------------------------------------------------
       
   241 //
       
   242 RXmlEngDocument CHnXmlModelProvider::ParseFileL( const TDesC& aPath )
       
   243     {
       
   244     RBuf8 doc( ReadFileLC( aPath ) );
       
   245     CleanupClosePushL(doc);
       
   246     
       
   247     RXmlEngDocument xmlDoc;
       
   248     CleanupClosePushL( xmlDoc );
       
   249     xmlDoc = ParseDocL(doc);
       
   250     CleanupStack::Pop( &xmlDoc );
       
   251     
       
   252     // clean up
       
   253     CleanupStack::PopAndDestroy( &doc );
       
   254     
       
   255     return xmlDoc;
       
   256     }
       
   257 
       
   258 // ---------------------------------------------------------------------------
       
   259 // 
       
   260 // ---------------------------------------------------------------------------
       
   261 //
       
   262 RXmlEngDocument CHnXmlModelProvider::ParseDocL( const TDesC8& aDoc )
       
   263     {
       
   264     RXmlEngDocument doc;
       
   265     CleanupClosePushL( doc );
       
   266     doc = iDomParser.ParseL( aDoc );
       
   267     CleanupStack::Pop( &doc );
       
   268     return doc;
       
   269     }
       
   270 
       
   271 // ---------------------------------------------------------------------------
       
   272 // 
       
   273 // ---------------------------------------------------------------------------
       
   274 //
       
   275 HBufC8* CHnXmlModelProvider::ReadFileLC(const TDesC& aPath)
       
   276     {
       
   277     RFile file;
       
   278     User::LeaveIfError( file.Open(iFs, aPath, EFileRead) );
       
   279     CleanupClosePushL( file );
       
   280     
       
   281     TInt fileSize(0);
       
   282     User::LeaveIfError( file.Size( fileSize ) );
       
   283     HBufC8* buf = HBufC8::NewLC( fileSize );
       
   284     TPtr8 bufPtr( buf->Des() );
       
   285     User::LeaveIfError( file.Read( bufPtr ) );
       
   286 
       
   287     // clean up
       
   288     CleanupStack::Pop(buf);
       
   289     CleanupStack::PopAndDestroy(&file);    
       
   290 
       
   291     return buf;
       
   292     }
       
   293 
       
   294 // ---------------------------------------------------------------------------
       
   295 // 
       
   296 // ---------------------------------------------------------------------------
       
   297 //
       
   298 void CHnXmlModelProvider::ChangeEventsToIdsInChildrenL(
       
   299 		TXmlEngElement & aElement)
       
   300 	{
       
   301 	RXmlEngNodeList<TXmlEngElement> children;
       
   302 	CleanupClosePushL(children);
       
   303 	aElement.GetChildElements(children);
       
   304 	TInt amount = children.Count();
       
   305 	for (TInt i(0); i < amount; i++)
       
   306 		{
       
   307 		TXmlEngElement child = children.Next();
       
   308 		TPtrC8 childName = child.Name();
       
   309 
       
   310 		if (!childName.Compare(KEventName8) 
       
   311 				|| CHnMdMenuItem::IsMenuItemElementName( childName )
       
   312 				|| !child.Name().Compare(KMenuToolbar8))
       
   313 			{
       
   314 			ChangeEventNamesToIdsL(child);
       
   315 			}
       
   316 		else if (!childName.Compare(KEditModeItem8))
       
   317 			{
       
   318 			ChangeEventsToIdsInChildrenL(child);
       
   319 			}
       
   320 		}
       
   321 
       
   322 	CleanupStack::PopAndDestroy(&children);
       
   323 	}
       
   324 
       
   325 // ---------------------------------------------------------------------------
       
   326 // 
       
   327 // ---------------------------------------------------------------------------
       
   328 //
       
   329 TInt CHnXmlModelProvider::CollectSuiteL(const TDesC& aSuiteName,
       
   330 		RXmlEngDocument& aXmlDoc)
       
   331 	{
       
   332 	TInt err(KErrNotFound);
       
   333 	TBuf<KMaxPath> filePath;
       
   334 	TBuf<KMaxPath> KsuitePath;
       
   335 	KsuitePath.Zero();
       
   336 	KsuitePath.Copy(iPath);
       
   337 	KsuitePath.Append(aSuiteName);
       
   338 	KsuitePath.Append(Kbackslash);
       
   339 
       
   340 	filePath.Zero();
       
   341 	filePath.Copy(KsuitePath);
       
   342 	filePath.Append(KSuiteDefFileName);
       
   343 
       
   344 	RXmlEngDocument suiteDoc;
       
   345 	CleanupClosePushL(suiteDoc);
       
   346 	
       
   347 	suiteDoc = ParseFileL(filePath);
       
   348     
       
   349     // one suite per file
       
   350     RXmlEngNodeList<TXmlEngElement> elements;
       
   351     suiteDoc.DocumentElement().GetChildElements( elements );
       
   352     TXmlEngElement suiteElement;
       
   353     while ( elements.HasNext() )
       
   354         {
       
   355         suiteElement = elements.Next();
       
   356         TPtrC8 t = suiteElement.Name();
       
   357         if ( !suiteElement.Name().Compare( KSuiteElementName8 ) )
       
   358             {
       
   359             ChangeEventsToIdsInChildrenL( suiteElement.AsElement() );    
       
   360             break;
       
   361             }
       
   362         }
       
   363     
       
   364     aXmlDoc.OpenL( iDomImpl, suiteDoc.DocumentElement() );            
       
   365     err = KErrNone;
       
   366     
       
   367     CleanupStack::PopAndDestroy( &suiteDoc );
       
   368     return err;             
       
   369     }
       
   370 
       
   371 // ---------------------------------------------------------------------------
       
   372 // 
       
   373 // ---------------------------------------------------------------------------
       
   374 //
       
   375 TBool CHnXmlModelProvider::SuiteExistsL( const TDesC& aSuite )
       
   376     {
       
   377     TBuf<KMaxPath> filePath;
       
   378     TBuf<KMaxPath> KsuitePath;
       
   379     KsuitePath.Zero();
       
   380     KsuitePath.Copy( iPath );
       
   381     KsuitePath.Append( aSuite );
       
   382     KsuitePath.Append( Kbackslash );
       
   383 
       
   384     filePath.Zero();
       
   385     filePath.Copy( KsuitePath );
       
   386     filePath.Append( KSuiteDefFileName );
       
   387     
       
   388     return BaflUtils::FileExists( iFs, filePath );
       
   389     }
       
   390 
       
   391 
       
   392 // ---------------------------------------------------------------------------
       
   393 // 
       
   394 // ---------------------------------------------------------------------------
       
   395 //
       
   396 void CHnXmlModelProvider::CollectItemsL( const TDesC& aSuiteName,
       
   397         RXmlEngDocument& aXmlDoc )
       
   398     {
       
   399     TBuf<KMaxPath> filePath;
       
   400     TBuf<KMaxPath> KsuitePath;
       
   401     KsuitePath.Zero();
       
   402     KsuitePath.Copy( iPath );
       
   403     KsuitePath.Append( aSuiteName ); 
       
   404     KsuitePath.Append( Kbackslash ); 
       
   405     CDir* fileList;                  
       
   406     iFs.GetDir( KsuitePath, KEntryAttMaskSupported, ESortByName, fileList);
       
   407     CleanupStack::PushL(fileList);
       
   408 
       
   409     //for each file with entries definitions         
       
   410     for( TInt i(0); i<fileList->Count(); i++ )  
       
   411         {            
       
   412         TPtrC fileName = (*fileList)[i].iName;   
       
   413         
       
   414         if(!fileName.Compare(KSuiteDefFileName))
       
   415             continue;
       
   416         
       
   417         filePath.Zero();
       
   418         filePath.Copy(KsuitePath);
       
   419         filePath.Append(fileName);  
       
   420             
       
   421         RXmlEngDocument itemDoc;
       
   422         CleanupClosePushL( itemDoc );
       
   423         
       
   424         TInt err( KErrNone );
       
   425         TRAP( err , itemDoc = ParseFileL(filePath) );
       
   426         if( !err )
       
   427             {
       
   428             RXmlEngNodeList< TXmlEngElement > children;
       
   429             CleanupClosePushL(children);
       
   430             itemDoc.DocumentElement().GetChildElements(children);
       
   431             
       
   432             TPtrC8 itemGenre =
       
   433                 itemDoc.DocumentElement().AttributeNodeL(KGenreName8).Value();
       
   434                 
       
   435             TInt amount = children.Count();
       
   436             for( TInt i(0); i<amount; i++ )
       
   437                 {
       
   438                 TXmlEngElement child = children.Next();
       
   439                 TPtrC8 tempChildName = child.Name();
       
   440                 // append localizations to root
       
   441                 if (!child.Name().Compare(KLocalizationName8)) 
       
   442                     {                
       
   443                     aXmlDoc.DocumentElement().AsElement().AppendChildL(child);
       
   444                     child.ReconcileNamespacesL();
       
   445                     } 
       
   446                 // append itmes to proper suite 
       
   447                 else if (!child.Name().Compare(KItemName8) )
       
   448                     {                                    
       
   449                     // go througs item's children to change event names to ids
       
   450                     ChangeEventsToIdsInChildrenL(child);
       
   451                     
       
   452                     // edit_mode item
       
   453                     RXmlEngNodeList< TXmlEngElement > editModeItems;
       
   454                     CleanupClosePushL( editModeItems );
       
   455                     child.GetChildElements( editModeItems );
       
   456                     TInt count = editModeItems.Count();
       
   457                     for ( TInt ic( 0 ); ic < count; ic++ )
       
   458                         {
       
   459                         TXmlEngElement editModeItem = editModeItems.Next();
       
   460                         if ( !editModeItem.Name().Compare( KEditModeItem8 ))
       
   461                             {
       
   462 							editModeItem.AddNewAttributeL(KSuiteElementName8,
       
   463 									itemGenre);
       
   464 							}
       
   465 						}
       
   466 					CleanupStack::PopAndDestroy(&editModeItems);
       
   467 					// edit_mode items - end
       
   468 
       
   469 					RXmlEngNodeList<TXmlEngElement> suites;
       
   470 					CleanupClosePushL(suites);
       
   471 					aXmlDoc.DocumentElement().GetChildElements(suites);
       
   472 					TInt amountSuites = suites.Count();
       
   473 					for (TInt i(0); i < amountSuites; i++)
       
   474 						{
       
   475 						TXmlEngElement childSuite = suites.Next();
       
   476 						TPtrC8 tempName = child.Name();
       
   477 						//find suite
       
   478 						if (!childSuite.Name().Compare(KTitleName8))
       
   479 							{
       
   480 							TPtrC8 suiteGenre = childSuite.AttributeNodeL(
       
   481 									KGenreName8).Value();
       
   482 
       
   483 							//find proper suite to append item
       
   484 							if (!suiteGenre.Compare(itemGenre))
       
   485 								{
       
   486 								child.AddNewAttributeL(KSuiteElementName8,
       
   487 										itemGenre);
       
   488 								childSuite.AppendChildL(child);
       
   489                                 }                        
       
   490                             }
       
   491                         }
       
   492 					aXmlDoc.DocumentElement().ReconcileNamespacesL();
       
   493                     CleanupStack::PopAndDestroy( &suites );                    
       
   494                     }                                
       
   495                 }                   
       
   496             CleanupStack::PopAndDestroy( &children );
       
   497             }
       
   498         CleanupStack::PopAndDestroy( &itemDoc );
       
   499         } 
       
   500     
       
   501     CleanupStack::PopAndDestroy(fileList);
       
   502     }        
       
   503 
       
   504 
       
   505 // ---------------------------------------------------------------------------
       
   506 // 
       
   507 // ---------------------------------------------------------------------------
       
   508 //
       
   509 TInt CHnXmlModelProvider::GetNewEventId( HBufC* aEventName )
       
   510     {
       
   511     TInt res( KErrGeneral );
       
   512 
       
   513     if ( !aEventName->Compare( KKeyEmpty ) )
       
   514         {
       
   515         res = KKeyIdEmpty;
       
   516         }
       
   517     else if ( !aEventName->Compare( KKeySelect ) )
       
   518         {
       
   519         res = KKeyIdSelect;
       
   520         }
       
   521     else if ( !aEventName->Compare( KKeySelect2 ) )
       
   522         {
       
   523         res = KKeyIdSelect2;
       
   524         }
       
   525     else if ( !aEventName->Compare( KKeySelect3 ) )
       
   526         {
       
   527         res = KKeyIdSelect3;
       
   528         }
       
   529     else if ( !aEventName->Compare( KKeyCall ) )
       
   530         {
       
   531         res = KKeyIdCall;
       
   532         }
       
   533     else if ( !aEventName->Compare( KKeyClear ) )
       
   534         {
       
   535         res = KKeyIdClear;
       
   536         }
       
   537     else if ( !aEventName->Compare( KKeyMove ) )
       
   538         {
       
   539         res = KKeyIdMove;
       
   540         }
       
   541     else if ( !aEventName->Compare( KKeyMoveInto ) )
       
   542         {
       
   543         res = KKeyIdMoveInto;
       
   544         }
       
   545     else if ( !aEventName->Compare( KOnSuiteLoad ) )
       
   546         {
       
   547         res = KIdSuiteLoad;
       
   548         }
       
   549     else if ( !aEventName->Compare( KOnSuiteUnLoad ) )
       
   550         {
       
   551         res = KIdSuiteUnLoad;
       
   552         }
       
   553     else if ( !aEventName->Compare( KOnFocusGain ) )
       
   554         {
       
   555         res = KIdFocusGain;
       
   556         }
       
   557     else if ( !aEventName->Compare( KOnFocusLost ) )
       
   558         {
       
   559         res = KIdFocusLost;
       
   560         }
       
   561     else
       
   562         {
       
   563         THashMapIter<HBufC*, TInt> iter( iEventMap );
       
   564         res = KCustomKeyOffset;
       
   565         
       
   566         while ( TInt const * v = iter.NextValue() )
       
   567             {
       
   568             if ( v != NULL && *v >= KCustomKeyOffset )
       
   569                 {
       
   570                 res++;
       
   571                 }
       
   572             }
       
   573         }
       
   574     
       
   575     return res;    
       
   576     }
       
   577 
       
   578 // ---------------------------------------------------------------------------
       
   579 // 
       
   580 // ---------------------------------------------------------------------------
       
   581 //
       
   582 void CHnXmlModelProvider::ChangeEventNamesToIdsL( TXmlEngElement& aElement )
       
   583     {
       
   584     if ( aElement.HasChildNodes() && ( !aElement.Name().Compare( KMenuItemName8 )  
       
   585             || !aElement.Name().Compare( KMenuToolbar8 ) ) )
       
   586         {
       
   587         
       
   588         RXmlEngNodeList< TXmlEngElement > children;
       
   589         CleanupClosePushL(children);
       
   590         aElement.GetChildElements(children);
       
   591         TInt count( children.Count() );
       
   592         for( TInt i( 0 ); i < count; i++ )
       
   593             {
       
   594             TXmlEngElement element = children.Next();
       
   595             if ( CHnMdMenuItem::IsMenuItemElementName( element.Name() ) ||
       
   596                     !element.Name().Compare( KMenuButton8 ) )
       
   597                 {
       
   598                 ChangeEventNamesToIdsL( element );
       
   599                 }
       
   600             }
       
   601         CleanupStack::PopAndDestroy( &children );
       
   602         }
       
   603     else if( aElement.AttributeValueL( KEventAttrName8 ).Length() )
       
   604         {
       
   605         TBool bufferEmpty ( ETrue );
       
   606         TBuf8<KMaxPath> newEventIds;
       
   607              
       
   608         // loop through all event names
       
   609 
       
   610         // parsing events        
       
   611         HBufC* events = HnConvUtils::Str8ToStrLC(
       
   612             aElement.AttributeValueL( KEventName8 ) );
       
   613         
       
   614         TLex lex( events->Ptr() );
       
   615         TChar ch;
       
   616         
       
   617         TInt length( events->Length() );
       
   618         TInt cnt = 0;
       
   619         while( ch = lex.Get() != 0 )
       
   620             {
       
   621             cnt++;
       
   622             while ( ( ch = lex.Peek() ) != '|' && cnt < length)
       
   623                 {
       
   624                 lex.Inc();
       
   625                 cnt++;
       
   626                 }
       
   627 
       
   628             // iEventMap takes ownership of "en"
       
   629             HBufC* en = HBufC::NewL( lex.MarkedToken().Length() );
       
   630             en->Des().Copy( lex.MarkedToken() );
       
   631 
       
   632             TInt* resFind = iEventMap.Find( en );
       
   633             TInt res = -1;
       
   634             if ( resFind == NULL )
       
   635                 {
       
   636                 TInt newId( GetNewEventId( en ) );
       
   637                 iEventMap.Insert( en, newId );                
       
   638                 res = newId;
       
   639                 }
       
   640             else
       
   641                 {
       
   642                 res = *resFind;
       
   643                 delete en;
       
   644                 }
       
   645             
       
   646             if ( bufferEmpty ) 
       
   647                 {
       
   648                 newEventIds.AppendNum( res );
       
   649                 bufferEmpty = EFalse;
       
   650                 }
       
   651 			else
       
   652 				{
       
   653 				newEventIds.Append(KPipe);
       
   654 				newEventIds.AppendNum(res);
       
   655 				}
       
   656 
       
   657             lex.Inc();
       
   658             cnt++;
       
   659             lex.Mark();
       
   660             if (cnt >= length)
       
   661                 break;
       
   662             }
       
   663 
       
   664         TXmlEngAttr att = aElement.AttributeNodeL( KEventName8 );
       
   665         att.SetValueL( newEventIds );
       
   666         aElement.SetAttributeNodeL( att );
       
   667 
       
   668         CleanupStack::PopAndDestroy( events );
       
   669         }
       
   670     }
       
   671     
       
   672 // ---------------------------------------------------------------------------
       
   673 // 
       
   674 // ---------------------------------------------------------------------------
       
   675 //
       
   676 TBool CHnXmlModelProvider::SynchronizeSuitesL()
       
   677     {
       
   678     MMPERF(("CHnXmlModelProvider::SynchronizeSuitesL - START"));
       
   679     iSuiteFilesUpdated = EFalse;
       
   680     TBool refresh( EFalse );   
       
   681 
       
   682     if (IsActive())
       
   683     	{
       
   684     	Cancel();
       
   685     	}
       
   686     
       
   687     delete iSuiteSetIterator;
       
   688     iSuiteSetIterator = NULL;
       
   689     
       
   690     iStatus = KRequestPending;
       
   691     SetActive();
       
   692     TRequestStatus* status = &iStatus;
       
   693     User::RequestComplete( status, KErrNone );
       
   694    
       
   695     MMPERF(("CHnXmlModelProvider::SynchronizeSuitesL - DONE"));
       
   696     return refresh;
       
   697     }
       
   698  
       
   699 // ---------------------------------------------------------------------------
       
   700 // 
       
   701 // ---------------------------------------------------------------------------
       
   702 // 
       
   703 void CHnXmlModelProvider::ResetCache()
       
   704     {
       
   705     iCache->Reset();
       
   706     }
       
   707 
       
   708 // ---------------------------------------------------------------------------
       
   709 // 
       
   710 // ---------------------------------------------------------------------------
       
   711 //   
       
   712 void CHnXmlModelProvider::SetupSuitePathL()
       
   713 	{
       
   714 	iPath.Close();
       
   715 	iPath.CreateL(KMaxPath);
       
   716 	User::LeaveIfError(iFs.PrivatePath(iPath));
       
   717 	TChar drive;
       
   718 	TBuf<1> driveLetter;
       
   719 	
       
   720 	iFs.DriveToChar( EDriveC, drive );
       
   721 	iPath.Insert(0, KColon );
       
   722 	driveLetter.Append( drive );
       
   723 	iPath.Insert(0, driveLetter );
       
   724 	iPath.Append(KEntriesSuffix);
       
   725 	}
       
   726 
       
   727 // ---------------------------------------------------------------------------
       
   728 // 
       
   729 // ---------------------------------------------------------------------------
       
   730 //   
       
   731 void CHnXmlModelProvider::SetupFailSafeSuitePathL()
       
   732 	{
       
   733 	iPath.Close();
       
   734 	iPath.CreateL(KMaxPath);
       
   735 	User::LeaveIfError(iFs.PrivatePath(iPath));
       
   736 	TChar drive;
       
   737 	TBuf<1> driveLetter;
       
   738 	
       
   739 	iFs.DriveToChar( EDriveZ, drive );
       
   740 	iPath.Insert(0, KColon );
       
   741 	driveLetter.Append( drive );
       
   742 	iPath.Insert(0, driveLetter );
       
   743 	iPath.Append(KSuitesDir);
       
   744 	}
       
   745 
       
   746 
       
   747 // ---------------------------------------------------------------------------
       
   748 // 
       
   749 // ---------------------------------------------------------------------------
       
   750 // 
       
   751 EXPORT_C void CHnXmlModelProvider::ReloadModelL()
       
   752 	{
       
   753 	SynchronizeSuitesL();
       
   754 	}
       
   755 
       
   756 // ---------------------------------------------------------------------------
       
   757 // 
       
   758 // ---------------------------------------------------------------------------
       
   759 // 
       
   760 void CHnXmlModelProvider::CreateModelL(const TDesC& aSuiteName,
       
   761         RXmlEngDocument& aXmlDoc )
       
   762     {
       
   763     MMPERF( ( "CHnXmlModelProvider::CreateModelL IN") );
       
   764     MMPERF( ( "    Suite name: %S", &aSuiteName ) );
       
   765     
       
   766     TBool suiteCollected = EFalse;
       
   767 	
       
   768     SetupSuitePathL();	
       
   769     TRAPD( failSafeErr, suiteCollected = CollectSuiteL( aSuiteName, aXmlDoc ));
       
   770     if (failSafeErr)
       
   771     	{
       
   772     	SetupFailSafeSuitePathL();
       
   773     	suiteCollected = CollectSuiteL( aSuiteName, aXmlDoc );
       
   774     	}
       
   775     
       
   776     if ( !suiteCollected )
       
   777         {
       
   778         MMPERF(("CHnXmlModelProvider::CreateModelL - suite collected"));
       
   779         CollectItemsL( aSuiteName, aXmlDoc );
       
   780         MMPERF(("CHnXmlModelProvider::CreateModelL - items collected"));
       
   781         }
       
   782     MMPERF( ( "CHnXmlModelProvider::CreateModelL OUT") );
       
   783     }
       
   784 
       
   785 
       
   786 // ---------------------------------------------------------------------------
       
   787 // 
       
   788 // ---------------------------------------------------------------------------
       
   789 // 
       
   790 EXPORT_C TInt CHnXmlModelProvider::GetModelL(
       
   791     const TDesC& aSuiteName, RXmlEngDocument& aXmlDoc )
       
   792     {
       
   793     if ( !iCache->IsCachedL( aSuiteName ) )
       
   794         {
       
   795         RXmlEngDocument newXmlDoc;
       
   796         CleanupClosePushL( newXmlDoc );
       
   797         
       
   798         CreateModelL( aSuiteName, newXmlDoc );
       
   799         
       
   800         #ifdef _DEBUG
       
   801             DEBUG(("_MM_:CHnXmlModelProvider::GetModelL _DEBUG IN"));
       
   802             LogEventMapping( iEventMap );
       
   803             LogSuiteModel( aSuiteName, newXmlDoc );
       
   804             DEBUG(("_MM_:CHnXmlModelProvider::GetModelL _DEBUG OUT"));
       
   805         #endif
       
   806 
       
   807         // cache takes ownership of the suite name and the document  
       
   808         iCache->AddL( aSuiteName, newXmlDoc );
       
   809         
       
   810         CleanupStack::Pop( &newXmlDoc );
       
   811         }
       
   812     
       
   813     iCache->GetL( aSuiteName, aXmlDoc );
       
   814     
       
   815     return KErrNone;
       
   816     }   
       
   817    
       
   818 
       
   819 // ---------------------------------------------------------------------------
       
   820 // 
       
   821 // ---------------------------------------------------------------------------
       
   822 //
       
   823 void CHnXmlModelProvider::SearchPathForSuitesL( const TDesC& aPath )
       
   824 	{
       
   825 	CDir* fileList = NULL;            
       
   826 	iFs.GetDir( aPath, KEntryAttMaskSupported, ESortByName, fileList );  
       
   827 	if ( fileList )                        
       
   828 		{                
       
   829 		CleanupStack::PushL( fileList );      
       
   830 		for( TInt i( 0 ); i < fileList->Count(); i++ ) 
       
   831 			{  
       
   832 			if ( (*fileList)[ i ].IsDir() )
       
   833 				{
       
   834 				HBufC* suiteName = (*fileList)[i].iName.AllocLC();
       
   835 				if ( !iInstSuites.Find(suiteName) )
       
   836 					{
       
   837 					iInstSuites.InsertL( suiteName );
       
   838 					CleanupStack::Pop(suiteName);
       
   839 					}
       
   840 				else
       
   841 					{
       
   842 					CleanupStack::PopAndDestroy(suiteName);
       
   843 					}
       
   844 				}
       
   845 			}
       
   846 			CleanupStack::PopAndDestroy( fileList );
       
   847 		}
       
   848     }
       
   849 // ---------------------------------------------------------------------------
       
   850 // 
       
   851 // ---------------------------------------------------------------------------
       
   852 //
       
   853 void CHnXmlModelProvider::CheckDrivesL()
       
   854     { 
       
   855     TDriveList driveList;
       
   856     User::LeaveIfError( iFs.DriveList( driveList ) );
       
   857     
       
   858     TFixedArray< TInt, KMaxDrives > driveSearchOrder( KDriveSearchOrder, KMaxDrives );
       
   859     for(TInt iterator(0); iterator < driveSearchOrder.Count(); iterator++ )
       
   860      	{        
       
   861         if ( driveList[ driveSearchOrder[ iterator ] ] )
       
   862             {
       
   863             TBuf<KMaxPath> filePath;
       
   864 
       
   865             TChar driveLetter;
       
   866             User::LeaveIfError( iFs.DriveToChar( driveSearchOrder[ iterator ], driveLetter ) );  
       
   867             
       
   868             TBuf< KSingleChar > driveLetterConst;
       
   869             driveLetterConst.Append( driveLetter );
       
   870             User::LeaveIfError( iFs.PrivatePath( filePath ) );
       
   871             filePath.Insert( 0, driveLetterConst );
       
   872             filePath.Insert( 1, KColon );
       
   873             filePath.Append( KSuitesDir );
       
   874                          
       
   875             SearchPathForSuitesL( filePath );           
       
   876             }
       
   877     	}
       
   878     
       
   879     SearchPathForSuitesL( iPath );
       
   880     }
       
   881