|
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 |
|
28 // ======== MEMBER FUNCTIONS ======== |
|
29 |
|
30 // --------------------------------------------------------------------------- |
|
31 // |
|
32 // --------------------------------------------------------------------------- |
|
33 // |
|
34 void CHnXmlModelProvider::ConstructL() |
|
35 { |
|
36 iDomImpl.OpenL(); |
|
37 User::LeaveIfError(iDomParser.Open(iDomImpl)); |
|
38 User::LeaveIfError(iFs.Connect()); |
|
39 iFileMan = CFileMan::NewL(iFs); |
|
40 |
|
41 iPath.CreateL(KMaxPath); |
|
42 User::LeaveIfError(iFs.PrivatePath(iPath)); |
|
43 iPath.Insert(0, KDrive); |
|
44 iPath.Append(KEntriesSuffix); |
|
45 iCache = CHnXmlModelCache::NewL(); |
|
46 |
|
47 CActiveScheduler::Add( this); |
|
48 } |
|
49 |
|
50 // --------------------------------------------------------------------------- |
|
51 // |
|
52 // --------------------------------------------------------------------------- |
|
53 // |
|
54 void CHnXmlModelProvider::DoCancel() |
|
55 { |
|
56 |
|
57 } |
|
58 |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 // --------------------------------------------------------------------------- |
|
62 // |
|
63 void CHnXmlModelProvider::SynchronizationFinishedL() |
|
64 { |
|
65 ResetCache(); |
|
66 THnMdCommonPointers &cmnPtr = *THnMdCommonPointers::Static(); |
|
67 CHnMdModel* model = cmnPtr.iModel; |
|
68 if ( iSuiteFilesUpdated ) |
|
69 { |
|
70 model->ReloadStackSuitesL( cmnPtr.iContainer ); |
|
71 } |
|
72 } |
|
73 // --------------------------------------------------------------------------- |
|
74 // |
|
75 // --------------------------------------------------------------------------- |
|
76 // |
|
77 void CHnXmlModelProvider::RunL() |
|
78 { |
|
79 if ( !iSuiteSetIterator ) |
|
80 { |
|
81 CheckDrivesL(); |
|
82 iSuiteSetIterator = new ( ELeave ) THashSetIter<HBufC*>( iInstSuites ); |
|
83 iSuiteSetIterator->Reset(); |
|
84 iStatus = KRequestPending; |
|
85 SetActive(); |
|
86 TRequestStatus* status = &iStatus; |
|
87 User::RequestComplete( status, KErrNone ); |
|
88 } |
|
89 else if ( iSuiteSetIterator->Next() ) |
|
90 { |
|
91 TBool filesUpdated = CHnXmlSuiteFilesReg::SynchronizeL( |
|
92 iFs, **(iSuiteSetIterator->Current()) ); |
|
93 iSuiteFilesUpdated = ( iSuiteFilesUpdated || filesUpdated ); |
|
94 iStatus = KRequestPending; |
|
95 SetActive(); |
|
96 TRequestStatus* status = &iStatus; |
|
97 User::RequestComplete( status, KErrNone ); |
|
98 } |
|
99 else |
|
100 { |
|
101 delete iSuiteSetIterator; |
|
102 iSuiteSetIterator = NULL; |
|
103 SynchronizationFinishedL(); |
|
104 } |
|
105 } |
|
106 |
|
107 // --------------------------------------------------------------------------- |
|
108 // |
|
109 // --------------------------------------------------------------------------- |
|
110 // |
|
111 EXPORT_C CHnXmlModelProvider* CHnXmlModelProvider::NewL() |
|
112 { |
|
113 CHnXmlModelProvider* self = CHnXmlModelProvider::NewLC(); |
|
114 CleanupStack::Pop(self); |
|
115 return self; |
|
116 } |
|
117 |
|
118 // --------------------------------------------------------------------------- |
|
119 // |
|
120 // --------------------------------------------------------------------------- |
|
121 // |
|
122 EXPORT_C CHnXmlModelProvider* CHnXmlModelProvider::NewLC() |
|
123 { |
|
124 CHnXmlModelProvider* self = new (ELeave) CHnXmlModelProvider; |
|
125 CleanupStack::PushL(self); |
|
126 self->ConstructL(); |
|
127 return self; |
|
128 } |
|
129 |
|
130 // --------------------------------------------------------------------------- |
|
131 // |
|
132 // --------------------------------------------------------------------------- |
|
133 // |
|
134 CHnXmlModelProvider::CHnXmlModelProvider() : |
|
135 CActive( EPriorityLow ), |
|
136 iInstSuites(&HBuf16Hash, &HBuf16Ident), |
|
137 iEventMap(&HBuf16Hash, &HBuf16Ident), |
|
138 iSuiteSetIterator( NULL ) |
|
139 { |
|
140 |
|
141 } |
|
142 |
|
143 // --------------------------------------------------------------------------- |
|
144 // |
|
145 // --------------------------------------------------------------------------- |
|
146 // |
|
147 EXPORT_C CHnXmlModelProvider::~CHnXmlModelProvider() |
|
148 { |
|
149 Cancel(); |
|
150 |
|
151 delete iSuiteSetIterator; |
|
152 delete iCache; |
|
153 iDomParser.Close(); |
|
154 iDomImpl.Close(); |
|
155 delete iFileMan; |
|
156 iFs.Close(); |
|
157 iPath.Close(); |
|
158 |
|
159 // clean up eventmap |
|
160 THashMapIter<HBufC*, TInt> iter(iEventMap); |
|
161 while (HBufC* const * ptr = iter.NextKey()) |
|
162 { |
|
163 delete *ptr; |
|
164 } |
|
165 iEventMap.Close(); |
|
166 |
|
167 THashSetIter<HBufC*> iterSuites(iInstSuites); |
|
168 while ( iterSuites.Next()) |
|
169 { |
|
170 delete *iterSuites.Current(); |
|
171 } |
|
172 iInstSuites.Close(); |
|
173 |
|
174 } |
|
175 |
|
176 #ifdef _DEBUG |
|
177 // --------------------------------------------------------------------------- |
|
178 // |
|
179 // --------------------------------------------------------------------------- |
|
180 // |
|
181 void CHnXmlModelProvider::LogEventMapping( |
|
182 const RHashMap<HBufC*, TInt>& aEventMap) |
|
183 { |
|
184 DEBUG(("\t_MM_: CHnXmlModelProvider::LogEventMapping IN")); |
|
185 RFs fs; |
|
186 if ( !fs.Connect() ) |
|
187 { |
|
188 RFile logFile; |
|
189 if ( !logFile.Replace( fs, KEventMapLogFile, EFileWrite ) ) |
|
190 { |
|
191 // first line |
|
192 TBuf8<256> buf1; |
|
193 buf1.Append( _L8("EventName") ); |
|
194 buf1.Append( _L8("\t") ); |
|
195 buf1.Append( _L8("EventId") ); |
|
196 buf1.Append( _L8("\n") ); |
|
197 logFile.Write( 0, buf1 ); |
|
198 THashMapIter<HBufC*, TInt> iter( aEventMap ); |
|
199 while ( HBufC* const * ptr = iter.NextKey() ) |
|
200 { |
|
201 TInt *v = iter.CurrentValue(); |
|
202 TBuf8<256> buf2; |
|
203 buf2.Append( (*ptr)->Des() ); |
|
204 buf2.Append( _L8("\t") ); |
|
205 buf2.AppendNum( *v ); |
|
206 buf2.Append( _L8("\n") ); |
|
207 TInt size ( 0 ); |
|
208 logFile.Size( size ); |
|
209 logFile.Write( size, buf2 ); |
|
210 } |
|
211 logFile.Close(); |
|
212 } |
|
213 fs.Close(); |
|
214 } |
|
215 DEBUG(("\t_MM_: CHnXmlModelProvider::LogEventMapping OUT")); |
|
216 } |
|
217 |
|
218 // --------------------------------------------------------------------------- |
|
219 // |
|
220 // --------------------------------------------------------------------------- |
|
221 // |
|
222 void CHnXmlModelProvider::LogSuiteModel( const TDesC& aName, |
|
223 RXmlEngDocument& aDoc ) |
|
224 { |
|
225 DEBUG(("\t_MM_: CHnXmlModelProvider::LogSuiteModel IN")); |
|
226 TBuf8<256> buf1; |
|
227 TFileName logFileName; |
|
228 logFileName.Copy( KSuiteLoadingLogFile ); |
|
229 logFileName.Append( Kbackslash ); |
|
230 logFileName.Append( aName ); |
|
231 logFileName.Append( KXmlExt ); |
|
232 TRAP_IGNORE( aDoc.SaveL( logFileName, aDoc.DocumentElement() ) ); |
|
233 DEBUG(("\t_MM_: CHnXmlModelProvider::LogSuiteModel OUT")); |
|
234 } |
|
235 #endif |
|
236 |
|
237 // --------------------------------------------------------------------------- |
|
238 // |
|
239 // --------------------------------------------------------------------------- |
|
240 // |
|
241 RXmlEngDocument CHnXmlModelProvider::ParseFileL( const TDesC& aPath ) |
|
242 { |
|
243 RBuf8 doc( ReadFileLC( aPath ) ); |
|
244 CleanupClosePushL(doc); |
|
245 |
|
246 RXmlEngDocument xmlDoc; |
|
247 CleanupClosePushL( xmlDoc ); |
|
248 xmlDoc = ParseDocL(doc); |
|
249 CleanupStack::Pop( &xmlDoc ); |
|
250 |
|
251 // clean up |
|
252 CleanupStack::PopAndDestroy( &doc ); |
|
253 |
|
254 return xmlDoc; |
|
255 } |
|
256 |
|
257 // --------------------------------------------------------------------------- |
|
258 // |
|
259 // --------------------------------------------------------------------------- |
|
260 // |
|
261 RXmlEngDocument CHnXmlModelProvider::ParseDocL( const TDesC8& aDoc ) |
|
262 { |
|
263 RXmlEngDocument doc; |
|
264 CleanupClosePushL( doc ); |
|
265 doc = iDomParser.ParseL( aDoc ); |
|
266 CleanupStack::Pop( &doc ); |
|
267 return doc; |
|
268 } |
|
269 |
|
270 // --------------------------------------------------------------------------- |
|
271 // |
|
272 // --------------------------------------------------------------------------- |
|
273 // |
|
274 HBufC8* CHnXmlModelProvider::ReadFileLC(const TDesC& aPath) |
|
275 { |
|
276 RFile file; |
|
277 User::LeaveIfError( file.Open(iFs, aPath, EFileRead) ); |
|
278 CleanupClosePushL( file ); |
|
279 |
|
280 TInt fileSize(0); |
|
281 User::LeaveIfError( file.Size( fileSize ) ); |
|
282 HBufC8* buf = HBufC8::NewLC( fileSize ); |
|
283 TPtr8 bufPtr( buf->Des() ); |
|
284 User::LeaveIfError( file.Read( bufPtr ) ); |
|
285 |
|
286 // clean up |
|
287 CleanupStack::Pop(buf); |
|
288 CleanupStack::PopAndDestroy(&file); |
|
289 |
|
290 return buf; |
|
291 } |
|
292 |
|
293 // --------------------------------------------------------------------------- |
|
294 // |
|
295 // --------------------------------------------------------------------------- |
|
296 // |
|
297 void CHnXmlModelProvider::ChangeEventsToIdsInChildrenL( |
|
298 TXmlEngElement & aElement) |
|
299 { |
|
300 RXmlEngNodeList<TXmlEngElement> children; |
|
301 CleanupClosePushL(children); |
|
302 aElement.GetChildElements(children); |
|
303 TInt amount = children.Count(); |
|
304 for (TInt i(0); i < amount; i++) |
|
305 { |
|
306 TXmlEngElement child = children.Next(); |
|
307 TPtrC8 childName = child.Name(); |
|
308 |
|
309 if (!childName.Compare(KEventName8) || !childName.Compare( |
|
310 KMenuItemName8) ||!childName.Compare( KMenuItemSpecificName8 ) |
|
311 || !child.Name().Compare(KMenuToolbar8)) |
|
312 { |
|
313 ChangeEventNamesToIdsL(child); |
|
314 } |
|
315 else if (!childName.Compare(KEditModeItem8)) |
|
316 { |
|
317 ChangeEventsToIdsInChildrenL(child); |
|
318 } |
|
319 } |
|
320 |
|
321 CleanupStack::PopAndDestroy(&children); |
|
322 } |
|
323 |
|
324 // --------------------------------------------------------------------------- |
|
325 // |
|
326 // --------------------------------------------------------------------------- |
|
327 // |
|
328 TInt CHnXmlModelProvider::CollectSuiteL(const TDesC& aSuiteName, |
|
329 RXmlEngDocument& aXmlDoc) |
|
330 { |
|
331 TInt err(KErrNotFound); |
|
332 TBuf<KMaxPath> filePath; |
|
333 TBuf<KMaxPath> KsuitePath; |
|
334 KsuitePath.Zero(); |
|
335 KsuitePath.Copy(iPath); |
|
336 KsuitePath.Append(aSuiteName); |
|
337 KsuitePath.Append(Kbackslash); |
|
338 |
|
339 filePath.Zero(); |
|
340 filePath.Copy(KsuitePath); |
|
341 filePath.Append(KSuiteDefFileName); |
|
342 |
|
343 RXmlEngDocument suiteDoc; |
|
344 CleanupClosePushL(suiteDoc); |
|
345 |
|
346 suiteDoc = ParseFileL(filePath); |
|
347 |
|
348 // one suite per file |
|
349 RXmlEngNodeList<TXmlEngElement> elements; |
|
350 suiteDoc.DocumentElement().GetChildElements( elements ); |
|
351 TXmlEngElement suiteElement; |
|
352 while ( elements.HasNext() ) |
|
353 { |
|
354 suiteElement = elements.Next(); |
|
355 TPtrC8 t = suiteElement.Name(); |
|
356 if ( !suiteElement.Name().Compare( KSuiteElementName8 ) ) |
|
357 { |
|
358 ChangeEventsToIdsInChildrenL( suiteElement.AsElement() ); |
|
359 break; |
|
360 } |
|
361 } |
|
362 |
|
363 aXmlDoc.OpenL( iDomImpl, suiteDoc.DocumentElement() ); |
|
364 err = KErrNone; |
|
365 |
|
366 CleanupStack::PopAndDestroy( &suiteDoc ); |
|
367 return err; |
|
368 } |
|
369 |
|
370 // --------------------------------------------------------------------------- |
|
371 // |
|
372 // --------------------------------------------------------------------------- |
|
373 // |
|
374 TBool CHnXmlModelProvider::SuiteExistsL( const TDesC& aSuite ) |
|
375 { |
|
376 TBuf<KMaxPath> filePath; |
|
377 TBuf<KMaxPath> KsuitePath; |
|
378 KsuitePath.Zero(); |
|
379 KsuitePath.Copy( iPath ); |
|
380 KsuitePath.Append( aSuite ); |
|
381 KsuitePath.Append( Kbackslash ); |
|
382 |
|
383 filePath.Zero(); |
|
384 filePath.Copy( KsuitePath ); |
|
385 filePath.Append( KSuiteDefFileName ); |
|
386 |
|
387 return BaflUtils::FileExists( iFs, filePath ); |
|
388 } |
|
389 |
|
390 |
|
391 // --------------------------------------------------------------------------- |
|
392 // |
|
393 // --------------------------------------------------------------------------- |
|
394 // |
|
395 void CHnXmlModelProvider::CollectItemsL( const TDesC& aSuiteName, |
|
396 RXmlEngDocument& aXmlDoc ) |
|
397 { |
|
398 TBuf<KMaxPath> filePath; |
|
399 TBuf<KMaxPath> KsuitePath; |
|
400 KsuitePath.Zero(); |
|
401 KsuitePath.Copy( iPath ); |
|
402 KsuitePath.Append( aSuiteName ); |
|
403 KsuitePath.Append( Kbackslash ); |
|
404 CDir* fileList; |
|
405 iFs.GetDir( KsuitePath, KEntryAttMaskSupported, ESortByName, fileList); |
|
406 CleanupStack::PushL(fileList); |
|
407 |
|
408 //for each file with entries definitions |
|
409 for( TInt i(0); i<fileList->Count(); i++ ) |
|
410 { |
|
411 TPtrC fileName = (*fileList)[i].iName; |
|
412 |
|
413 if(!fileName.Compare(KSuiteDefFileName)) |
|
414 continue; |
|
415 |
|
416 filePath.Zero(); |
|
417 filePath.Copy(KsuitePath); |
|
418 filePath.Append(fileName); |
|
419 |
|
420 RXmlEngDocument itemDoc; |
|
421 CleanupClosePushL( itemDoc ); |
|
422 |
|
423 TInt err( KErrNone ); |
|
424 TRAP( err , itemDoc = ParseFileL(filePath) ); |
|
425 if( !err ) |
|
426 { |
|
427 RXmlEngNodeList< TXmlEngElement > children; |
|
428 CleanupClosePushL(children); |
|
429 itemDoc.DocumentElement().GetChildElements(children); |
|
430 |
|
431 TPtrC8 itemGenre = |
|
432 itemDoc.DocumentElement().AttributeNodeL(KGenreName8).Value(); |
|
433 |
|
434 TInt amount = children.Count(); |
|
435 for( TInt i(0); i<amount; i++ ) |
|
436 { |
|
437 TXmlEngElement child = children.Next(); |
|
438 TPtrC8 tempChildName = child.Name(); |
|
439 // append localizations to root |
|
440 if (!child.Name().Compare(KLocalizationName8)) |
|
441 { |
|
442 aXmlDoc.DocumentElement().AsElement().AppendChildL(child); |
|
443 child.ReconcileNamespacesL(); |
|
444 } |
|
445 // append itmes to proper suite |
|
446 else if (!child.Name().Compare(KItemName8) ) |
|
447 { |
|
448 // go througs item's children to change event names to ids |
|
449 ChangeEventsToIdsInChildrenL(child); |
|
450 |
|
451 // edit_mode item |
|
452 RXmlEngNodeList< TXmlEngElement > editModeItems; |
|
453 CleanupClosePushL( editModeItems ); |
|
454 child.GetChildElements( editModeItems ); |
|
455 TInt count = editModeItems.Count(); |
|
456 for ( TInt ic( 0 ); ic < count; ic++ ) |
|
457 { |
|
458 TXmlEngElement editModeItem = editModeItems.Next(); |
|
459 if ( !editModeItem.Name().Compare( KEditModeItem8 )) |
|
460 { |
|
461 editModeItem.AddNewAttributeL(KSuiteElementName8, |
|
462 itemGenre); |
|
463 } |
|
464 } |
|
465 CleanupStack::PopAndDestroy(&editModeItems); |
|
466 // edit_mode items - end |
|
467 |
|
468 RXmlEngNodeList<TXmlEngElement> suites; |
|
469 CleanupClosePushL(suites); |
|
470 aXmlDoc.DocumentElement().GetChildElements(suites); |
|
471 TInt amountSuites = suites.Count(); |
|
472 for (TInt i(0); i < amountSuites; i++) |
|
473 { |
|
474 TXmlEngElement childSuite = suites.Next(); |
|
475 TPtrC8 tempName = child.Name(); |
|
476 //find suite |
|
477 if (!childSuite.Name().Compare(KTitleName8)) |
|
478 { |
|
479 TPtrC8 suiteGenre = childSuite.AttributeNodeL( |
|
480 KGenreName8).Value(); |
|
481 |
|
482 //find proper suite to append item |
|
483 if (!suiteGenre.Compare(itemGenre)) |
|
484 { |
|
485 child.AddNewAttributeL(KSuiteElementName8, |
|
486 itemGenre); |
|
487 childSuite.AppendChildL(child); |
|
488 } |
|
489 } |
|
490 } |
|
491 aXmlDoc.DocumentElement().ReconcileNamespacesL(); |
|
492 CleanupStack::PopAndDestroy( &suites ); |
|
493 } |
|
494 } |
|
495 CleanupStack::PopAndDestroy( &children ); |
|
496 } |
|
497 CleanupStack::PopAndDestroy( &itemDoc ); |
|
498 } |
|
499 |
|
500 CleanupStack::PopAndDestroy(fileList); |
|
501 } |
|
502 |
|
503 |
|
504 // --------------------------------------------------------------------------- |
|
505 // |
|
506 // --------------------------------------------------------------------------- |
|
507 // |
|
508 TInt CHnXmlModelProvider::GetNewEventId( HBufC* aEventName ) |
|
509 { |
|
510 TInt res( KErrGeneral ); |
|
511 |
|
512 if ( !aEventName->Compare( KKeyEmpty ) ) |
|
513 { |
|
514 res = KKeyIdEmpty; |
|
515 } |
|
516 else if ( !aEventName->Compare( KKeySelect ) ) |
|
517 { |
|
518 res = KKeyIdSelect; |
|
519 } |
|
520 else if ( !aEventName->Compare( KKeySelect2 ) ) |
|
521 { |
|
522 res = KKeyIdSelect2; |
|
523 } |
|
524 else if ( !aEventName->Compare( KKeySelect3 ) ) |
|
525 { |
|
526 res = KKeyIdSelect3; |
|
527 } |
|
528 else if ( !aEventName->Compare( KKeyCall ) ) |
|
529 { |
|
530 res = KKeyIdCall; |
|
531 } |
|
532 else if ( !aEventName->Compare( KKeyClear ) ) |
|
533 { |
|
534 res = KKeyIdClear; |
|
535 } |
|
536 else if ( !aEventName->Compare( KKeyMove ) ) |
|
537 { |
|
538 res = KKeyIdMove; |
|
539 } |
|
540 else if ( !aEventName->Compare( KKeyMoveInto ) ) |
|
541 { |
|
542 res = KKeyIdMoveInto; |
|
543 } |
|
544 else if ( !aEventName->Compare( KOnSuiteLoad ) ) |
|
545 { |
|
546 res = KIdSuiteLoad; |
|
547 } |
|
548 else if ( !aEventName->Compare( KOnSuiteUnLoad ) ) |
|
549 { |
|
550 res = KIdSuiteUnLoad; |
|
551 } |
|
552 else if ( !aEventName->Compare( KOnFocusGain ) ) |
|
553 { |
|
554 res = KIdFocusGain; |
|
555 } |
|
556 else if ( !aEventName->Compare( KOnFocusLost ) ) |
|
557 { |
|
558 res = KIdFocusLost; |
|
559 } |
|
560 else |
|
561 { |
|
562 THashMapIter<HBufC*, TInt> iter( iEventMap ); |
|
563 res = KCustomKeyOffset; |
|
564 |
|
565 while ( TInt const * v = iter.NextValue() ) |
|
566 { |
|
567 if ( v != NULL && *v >= KCustomKeyOffset ) |
|
568 { |
|
569 res++; |
|
570 } |
|
571 } |
|
572 } |
|
573 |
|
574 return res; |
|
575 } |
|
576 |
|
577 // --------------------------------------------------------------------------- |
|
578 // |
|
579 // --------------------------------------------------------------------------- |
|
580 // |
|
581 void CHnXmlModelProvider::ChangeEventNamesToIdsL( TXmlEngElement& aElement ) |
|
582 { |
|
583 if ( aElement.HasChildNodes() && ( !aElement.Name().Compare( KMenuItemName8 ) |
|
584 || !aElement.Name().Compare( KMenuToolbar8 ) ) ) |
|
585 { |
|
586 |
|
587 RXmlEngNodeList< TXmlEngElement > children; |
|
588 CleanupClosePushL(children); |
|
589 aElement.GetChildElements(children); |
|
590 TInt count( children.Count() ); |
|
591 for( TInt i( 0 ); i < count; i++ ) |
|
592 { |
|
593 TXmlEngElement element = children.Next(); |
|
594 if ( !element.Name().Compare( KMenuItemName8 ) || |
|
595 !element.Name().Compare( KMenuItemSpecificName8 ) || |
|
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 |