|
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 <mmf/common/mmfcontrollerpluginresolver.h> |
|
19 #include <AvkonInternalCRKeys.h> |
|
20 |
|
21 #include "hnmdmodel.h" |
|
22 #include "hnmdsuite.h" |
|
23 #include "hnrepositoryobserver.h" |
|
24 #include "hnfilter.h" |
|
25 #include "hnglobals.h" |
|
26 #include "hneventhandler.h" |
|
27 #include "hnmdlocalization.h" |
|
28 #include "hnxmlmodelprovider.h" |
|
29 #include "hnsuitemodelcontainer.h" |
|
30 #include "hnitemsorder.h" |
|
31 #include "hninterface.h" |
|
32 #include "menudebug.h" |
|
33 #include "hnconvutils.h" |
|
34 #include "hnbitmapidcache.h" |
|
35 |
|
36 // ======== MEMBER FUNCTIONS ======== |
|
37 |
|
38 // --------------------------------------------------------------------------- |
|
39 // |
|
40 // --------------------------------------------------------------------------- |
|
41 // |
|
42 void CHnMdModel::ConstructL( MHnMdModelEventObserver *aModelObserver, |
|
43 CHnSuiteModelContainer * aSuiteModelContainer ) |
|
44 { |
|
45 MMPERF(("CHnMetaDataModel::ConstructL - START")); |
|
46 MMPERF(("CHnMetaDataModel::ConstructL - query handler ready")); |
|
47 iLocalization = CHnMdLocalization::NewL(); |
|
48 MMPERF(("CHnMetaDataModel::ConstructL - localization ready")); |
|
49 iXmlModelProvider = CHnXmlModelProvider::NewL(); |
|
50 MMPERF(("CHnMetaDataModel::ConstructL - bitmap and mask ids cache ready")); |
|
51 iBitmapIdCache = CHnBitmapIdCache::NewL(); |
|
52 MMPERF(("CHnMetaDataModel::ConstructL - model privider ready")); |
|
53 iXmlModelProvider->ReloadModelL(); |
|
54 MMPERF(("CHnMetaDataModel::ConstructL - model reloaded")); |
|
55 |
|
56 iCmnPtrs.iLocalization = iLocalization; |
|
57 iCmnPtrs.iIdGenerator = &iIdGenerator; |
|
58 iCmnPtrs.iModel = this; |
|
59 iCmnPtrs.iXmlModelProvider = iXmlModelProvider; |
|
60 iCmnPtrs.iContainer = aSuiteModelContainer; |
|
61 iCmnPtrs.iModelEventObserver = aModelObserver; |
|
62 iCmnPtrs.iBitmapIdCache = iBitmapIdCache; |
|
63 |
|
64 THnMdCommonPointers::SetStatic(&iCmnPtrs); |
|
65 |
|
66 iMode = EMdModeNormal; |
|
67 iRepositoryWidgetTypeObserver = CHnRepositoryWidgetTypeObserver::NewL( &iCmnPtrs, KMatrixRepositoryUid ); |
|
68 iRepositoryShowFolderObserver = CHnRepositoryShowFolderObserver::NewL( &iCmnPtrs, KCRUidMenu, KMenuShowFolder ); |
|
69 iRepositoryZoomObserver = CHnRepositoryZoomObserver::NewL( &iCmnPtrs, KCRUidAvkon, KAknGlobalUiZoom ); |
|
70 MMPERF(("CHnMetaDataModel::ConstructL - rep. observer ready")); |
|
71 } |
|
72 |
|
73 // --------------------------------------------------------------------------- |
|
74 // |
|
75 // --------------------------------------------------------------------------- |
|
76 // |
|
77 EXPORT_C CHnMdModel* CHnMdModel::NewL( |
|
78 MHnMdModelEventObserver* aModelObserver, |
|
79 CHnSuiteModelContainer * aSuiteModelContainer ) |
|
80 { |
|
81 CHnMdModel* self = CHnMdModel::NewLC( aModelObserver, |
|
82 aSuiteModelContainer ); |
|
83 CleanupStack::Pop( self ); |
|
84 return self; |
|
85 } |
|
86 |
|
87 // --------------------------------------------------------------------------- |
|
88 // |
|
89 // --------------------------------------------------------------------------- |
|
90 // |
|
91 EXPORT_C CHnMdModel* CHnMdModel::NewLC( |
|
92 MHnMdModelEventObserver* aModelObserver, |
|
93 CHnSuiteModelContainer * aSuiteModelContainer ) |
|
94 { |
|
95 CHnMdModel* self = new( ELeave ) CHnMdModel(); |
|
96 CleanupStack::PushL( self ); |
|
97 self->ConstructL( aModelObserver, aSuiteModelContainer ); |
|
98 return self; |
|
99 } |
|
100 |
|
101 // --------------------------------------------------------------------------- |
|
102 // |
|
103 // --------------------------------------------------------------------------- |
|
104 // |
|
105 CHnMdModel::CHnMdModel() |
|
106 { |
|
107 } |
|
108 |
|
109 // --------------------------------------------------------------------------- |
|
110 // |
|
111 // --------------------------------------------------------------------------- |
|
112 // |
|
113 CHnMdModel::~CHnMdModel() |
|
114 { |
|
115 delete iRepositoryWidgetTypeObserver; |
|
116 delete iRepositoryShowFolderObserver; |
|
117 delete iRepositoryZoomObserver; |
|
118 iLoadedSuites.ResetAndDestroy(); |
|
119 delete iXmlModelProvider; |
|
120 delete iLocalization; |
|
121 delete iBitmapIdCache; |
|
122 } |
|
123 |
|
124 // --------------------------------------------------------------------------- |
|
125 // |
|
126 // --------------------------------------------------------------------------- |
|
127 // |
|
128 EXPORT_C TInt CHnMdModel::HandleBackEventL( |
|
129 CHnSuiteModelContainer* aMulContainer, |
|
130 const TDesC& aSuiteName, |
|
131 TInt aIterations ) |
|
132 { |
|
133 TInt ret( KErrNotFound ); |
|
134 #ifdef _DEBUG |
|
135 // check if genres match |
|
136 CHnMdSuite* lastMdModel = GetLastSuite(); |
|
137 ASSERT( !lastMdModel->SuiteName().Compare( aSuiteName ) ); |
|
138 #endif |
|
139 |
|
140 TInt countDown( aIterations ); |
|
141 CHnSuiteModel* current = NULL; |
|
142 while( ( current = aMulContainer->GetParentSuiteModel() ) != NULL && |
|
143 countDown > 0 ) |
|
144 { |
|
145 current = aMulContainer->GetLastSuiteModel(); |
|
146 // pop the suite model |
|
147 aMulContainer->PopSuiteModelL( current->SuiteName() ); |
|
148 |
|
149 // remove the suite that we are leaving |
|
150 DeleteLastSuite(); |
|
151 countDown--; |
|
152 } |
|
153 |
|
154 current = aMulContainer->GetLastSuiteModel(); |
|
155 current->GetItemsOrder()->MarkSuiteUninitialized(); |
|
156 CHnFilter* filter = CHnFilter::NewLC(); |
|
157 filter->SetSuiteNameL( current->SuiteName() ); |
|
158 filter->SetSuiteId( current->CustomId() ); |
|
159 GetLastSuite()->MarkEvaluationL( *filter, *current); |
|
160 CleanupStack::PopAndDestroy( filter ); |
|
161 //Evaluate suite at the top (if needed) |
|
162 EvaluateTopSuiteL(); |
|
163 return ret; |
|
164 } |
|
165 |
|
166 // --------------------------------------------------------------------------- |
|
167 // |
|
168 // --------------------------------------------------------------------------- |
|
169 // |
|
170 EXPORT_C void CHnMdModel::HandleSisInstallationEventL( |
|
171 CHnSuiteModelContainer* /*aModelContainer*/ ) |
|
172 { |
|
173 iXmlModelProvider->ReloadModelL(); |
|
174 } |
|
175 |
|
176 // --------------------------------------------------------------------------- |
|
177 // |
|
178 // --------------------------------------------------------------------------- |
|
179 // |
|
180 void CHnMdModel::ReloadStackSuitesL( CHnSuiteModelContainer* aModelContainer ) |
|
181 { |
|
182 RPointerArray< CLiwGenericParamList > paramsArray; |
|
183 CleanupResetAndDestroyPushL( paramsArray ); |
|
184 |
|
185 TBool rootDisplayed( iLoadedSuites.Count() == 1 ); |
|
186 while( iLoadedSuites.Count() > 0 ) |
|
187 { |
|
188 // break loop to leave root suite on the stack |
|
189 if( ( iLoadedSuites.Count() == 1 && paramsArray.Count() > 0 ) |
|
190 || rootDisplayed ) |
|
191 { |
|
192 break; |
|
193 } |
|
194 |
|
195 CHnMdSuite* suite = GetLastSuite(); |
|
196 if( iXmlModelProvider->SuiteExistsL( suite->SuiteName() ) ) |
|
197 { |
|
198 CLiwGenericParamList* suiteParams = CLiwGenericParamList::NewL(); |
|
199 CleanupStack::PushL( suiteParams ); |
|
200 suiteParams->AppendL( suite->GetSuiteParameters() ); |
|
201 paramsArray.Append( suiteParams ); |
|
202 CleanupStack::Pop( suiteParams ); |
|
203 } |
|
204 aModelContainer->PopSuiteModelL( suite->SuiteName() ); |
|
205 DeleteLastSuite(); |
|
206 } |
|
207 |
|
208 TInt err( KErrNone ); |
|
209 CHnFilter* filter = CHnFilter::NewLC(); |
|
210 filter->SetEvaluateSuiteL( ETrue ); |
|
211 |
|
212 SetModeL( iMode ); |
|
213 |
|
214 for( TInt i( paramsArray.Count() - 1 ); i >= 0 && !err; i-- ) |
|
215 { |
|
216 CLiwGenericParamList* suiteParams = CLiwGenericParamList::NewL(); |
|
217 CleanupStack::PushL(suiteParams); |
|
218 suiteParams->AppendL( *(paramsArray[ i ])); |
|
219 TInt pos( 0 ); |
|
220 const TLiwGenericParam* param = suiteParams->FindFirst( pos, KSuiteName8 ); |
|
221 if ( param && pos >= 0) |
|
222 { |
|
223 TPtrC suiteName; |
|
224 param->Value().Get( suiteName ); |
|
225 err = LoadSuiteL( suiteName, suiteParams ); |
|
226 } |
|
227 CleanupStack::PopAndDestroy( suiteParams ); |
|
228 |
|
229 GetLastSuite()->SetModeL( iMode ); |
|
230 GetLastSuite()->MarkEvaluationL( |
|
231 *filter, *iCmnPtrs.iContainer->GetLastSuiteModel() ); |
|
232 GetLastSuite()->EvaluateL( *iCmnPtrs.iContainer->GetLastSuiteModel() ); |
|
233 } |
|
234 |
|
235 CleanupStack::PopAndDestroy( filter ); |
|
236 CleanupStack::PopAndDestroy( ¶msArray ); |
|
237 } |
|
238 |
|
239 // --------------------------------------------------------------------------- |
|
240 // |
|
241 // --------------------------------------------------------------------------- |
|
242 // |
|
243 EXPORT_C void CHnMdModel::DeleteLastSuite() |
|
244 { |
|
245 CHnMdSuite* tmpPtr = GetLastSuite(); |
|
246 iLoadedSuites.Remove( iLoadedSuites.Count() - 1 ); |
|
247 delete tmpPtr; |
|
248 } |
|
249 // --------------------------------------------------------------------------- |
|
250 // |
|
251 // --------------------------------------------------------------------------- |
|
252 // |
|
253 EXPORT_C void CHnMdModel::ReleaseLocalization() |
|
254 { |
|
255 iLocalization->ReleaseResourceFiles(); |
|
256 iXmlModelProvider->ResetCache(); |
|
257 } |
|
258 // --------------------------------------------------------------------------- |
|
259 // |
|
260 // --------------------------------------------------------------------------- |
|
261 // |
|
262 EXPORT_C void CHnMdModel::ReloadLocalizationL() |
|
263 { |
|
264 iLocalization->ReloadResourceFilesL(); |
|
265 } |
|
266 |
|
267 // --------------------------------------------------------------------------- |
|
268 // |
|
269 // --------------------------------------------------------------------------- |
|
270 // |
|
271 EXPORT_C void CHnMdModel::EvaluateL() |
|
272 { |
|
273 CHnFilter* empty = CHnFilter::NewLC(); |
|
274 EvaluateL( *empty ); |
|
275 CleanupStack::PopAndDestroy( empty ); |
|
276 } |
|
277 |
|
278 // --------------------------------------------------------------------------- |
|
279 // |
|
280 // --------------------------------------------------------------------------- |
|
281 // |
|
282 EXPORT_C void CHnMdModel::SetModeL( TMdMode aMode ) |
|
283 { |
|
284 iMode = aMode; |
|
285 for ( TInt i( 0 ); i < iLoadedSuites.Count(); i++ ) |
|
286 { |
|
287 CHnMdSuite* suite = iLoadedSuites[i]; |
|
288 ASSERT( suite != NULL ); |
|
289 suite->SetModeL( aMode ); |
|
290 } |
|
291 } |
|
292 |
|
293 // --------------------------------------------------------------------------- |
|
294 // |
|
295 // --------------------------------------------------------------------------- |
|
296 // |
|
297 EXPORT_C CHnMdSuite* CHnMdModel::GetLastSuite() |
|
298 { |
|
299 return (iLoadedSuites.Count()>0) |
|
300 ? iLoadedSuites[ iLoadedSuites.Count()-1 ] |
|
301 : NULL; |
|
302 } |
|
303 |
|
304 // --------------------------------------------------------------------------- |
|
305 // |
|
306 // --------------------------------------------------------------------------- |
|
307 // |
|
308 EXPORT_C void CHnMdModel::IgnoreEvaluations( TBool aIgnore ) |
|
309 { |
|
310 iIgnoreEvaluations = aIgnore; |
|
311 } |
|
312 |
|
313 // --------------------------------------------------------------------------- |
|
314 // |
|
315 // --------------------------------------------------------------------------- |
|
316 // |
|
317 EXPORT_C void CHnMdModel::QueueForeground( |
|
318 TForegroundGainTriggeringEvent aWhen ) |
|
319 { |
|
320 switch ( aWhen ) |
|
321 { |
|
322 case EWhenAnySuiteIsEvaluated: |
|
323 iForegroundQueued = ETrue; |
|
324 iForegroundTriggeringSuite = NULL; |
|
325 break; |
|
326 case EWhenCurrentTopSuiteIsEvaluated: |
|
327 iForegroundQueued = ETrue; |
|
328 iForegroundTriggeringSuite = iCmnPtrs.iContainer->GetLastSuiteModel(); |
|
329 break; |
|
330 case ENever: |
|
331 iForegroundQueued = EFalse; |
|
332 iForegroundTriggeringSuite = NULL; |
|
333 break; |
|
334 default: |
|
335 ASSERT( 0 ); |
|
336 } |
|
337 } |
|
338 |
|
339 // --------------------------------------------------------------------------- |
|
340 // |
|
341 // --------------------------------------------------------------------------- |
|
342 // |
|
343 EXPORT_C TBool CHnMdModel::IsForegroundQueued() const |
|
344 { |
|
345 return iForegroundQueued; |
|
346 } |
|
347 |
|
348 // --------------------------------------------------------------------------- |
|
349 // |
|
350 // --------------------------------------------------------------------------- |
|
351 // |
|
352 void CHnMdModel::SuiteModelReadyToShowL( CHnSuiteModel* aJustEvaluatedSuite ) |
|
353 { |
|
354 if ( !aJustEvaluatedSuite ) |
|
355 { |
|
356 User::Leave( KErrArgument ); |
|
357 } |
|
358 |
|
359 if ( IsForegroundQueued() && ( !iForegroundTriggeringSuite || |
|
360 iForegroundTriggeringSuite == aJustEvaluatedSuite ) ) |
|
361 { |
|
362 CLiwGenericParamList* pl = CLiwGenericParamList::NewL(); |
|
363 CleanupStack::PushL( pl ); |
|
364 iCmnPtrs.iModelEventObserver->HandleModelEventL( KAppGainForeground, *pl ); |
|
365 CleanupStack::PopAndDestroy( pl ); |
|
366 QueueForeground( ENever ); |
|
367 } |
|
368 } |
|
369 |
|
370 // --------------------------------------------------------------------------- |
|
371 // |
|
372 // --------------------------------------------------------------------------- |
|
373 // |
|
374 CHnMdSuite* CHnMdModel::GetSuite( TInt aPosition ) |
|
375 { |
|
376 return ( (aPosition >= 0) && (aPosition < iLoadedSuites.Count()) ) |
|
377 ? iLoadedSuites[ aPosition ] |
|
378 : NULL; |
|
379 } |
|
380 // --------------------------------------------------------------------------- |
|
381 // |
|
382 // --------------------------------------------------------------------------- |
|
383 // |
|
384 EXPORT_C CLiwGenericParamList& CHnMdModel::GetSuiteParameters( TInt aPosition ) |
|
385 { |
|
386 return GetSuite( aPosition )->GetSuiteParameters(); |
|
387 } |
|
388 // --------------------------------------------------------------------------- |
|
389 // |
|
390 // --------------------------------------------------------------------------- |
|
391 // |
|
392 EXPORT_C void CHnMdModel::EvaluateL( CHnFilter& aFilter ) |
|
393 { |
|
394 for ( TInt i = iLoadedSuites.Count() - 1; i >= 0; i-- ) |
|
395 { |
|
396 iLoadedSuites[i]->MarkEvaluationL( aFilter, *iCmnPtrs.iContainer->GetSuiteModel(i) ); |
|
397 if( i == iLoadedSuites.Count() - 1 && !iIgnoreEvaluations ) |
|
398 { |
|
399 iLoadedSuites[i]->EvaluateL( *iCmnPtrs.iContainer->GetSuiteModel(i) ); |
|
400 } |
|
401 } |
|
402 } |
|
403 |
|
404 // --------------------------------------------------------------------------- |
|
405 // |
|
406 // --------------------------------------------------------------------------- |
|
407 // |
|
408 EXPORT_C TInt CHnMdModel::LoadSuiteL( const TDesC& aGenre, |
|
409 CLiwGenericParamList* aSuiteParams ) |
|
410 { |
|
411 TInt err( KErrNone ); |
|
412 |
|
413 RXmlEngDocument xmlDoc; |
|
414 // Xml model provider takes ownership of xmlDoc. |
|
415 TRAP( err, iXmlModelProvider->GetModelL( aGenre, xmlDoc ) ); |
|
416 |
|
417 TXmlEngElement element; |
|
418 if ( !err ) |
|
419 { |
|
420 element = xmlDoc.DocumentElement().AsElement(); |
|
421 if ( element.Name() != KContentElementName8 ) |
|
422 { |
|
423 err = KErrCorrupt; |
|
424 } |
|
425 } |
|
426 |
|
427 if ( !err ) |
|
428 { |
|
429 CHnMdSuite* newSuite = CHnMdSuite::NewLC( element, &iCmnPtrs ); |
|
430 |
|
431 if (aSuiteParams) |
|
432 { |
|
433 newSuite->SetSuiteParametersL( *aSuiteParams ); |
|
434 } |
|
435 |
|
436 TInt pos( 0 ); |
|
437 newSuite->GetSuiteParameters().FindFirst( pos, KSuiteName8); |
|
438 if ( pos == KErrNotFound ) |
|
439 { |
|
440 newSuite->GetSuiteParameters().AppendL( |
|
441 TLiwGenericParam(KSuiteName8, TLiwVariant( aGenre ) ) ); |
|
442 } |
|
443 |
|
444 iCmnPtrs.iContainer->PushNewSuiteModelL( newSuite->SuiteName() ); |
|
445 iCmnPtrs.iContainer->GetLastSuiteModel()->GetItemsOrder()-> |
|
446 SetSuiteId( iCmnPtrs.iIdGenerator->GetNextId() ); |
|
447 |
|
448 CleanupStack::Pop( newSuite ); |
|
449 iLoadedSuites.AppendL( newSuite ); |
|
450 } |
|
451 else |
|
452 { |
|
453 MMPERF(("CHnMdModel::LoadSuiteL - Error TRAPPED!")); |
|
454 } |
|
455 |
|
456 return err; |
|
457 } |
|
458 |
|
459 // --------------------------------------------------------------------------- |
|
460 // |
|
461 // --------------------------------------------------------------------------- |
|
462 // |
|
463 EXPORT_C TBool CHnMdModel::SuiteModelExistsL( const TDesC8& aSuiteModel ) |
|
464 { |
|
465 TBool res( EFalse ); |
|
466 HBufC* suiteName = HnConvUtils::Str8ToStrLC( aSuiteModel ); |
|
467 res = iXmlModelProvider->SuiteExistsL( *suiteName ) || |
|
468 aSuiteModel.Compare( KRoot8 ) == KErrNone ; |
|
469 CleanupStack::PopAndDestroy( suiteName ); |
|
470 return res; |
|
471 } |
|
472 |
|
473 // --------------------------------------------------------------------------- |
|
474 // |
|
475 // --------------------------------------------------------------------------- |
|
476 // |
|
477 EXPORT_C void CHnMdModel::GetCurrentUriL( TDes& aUri ) |
|
478 { |
|
479 iXmlModelProvider->ReloadModelL(); |
|
480 |
|
481 aUri.Append( KPrefMm ); |
|
482 for( TInt i(0); i < iLoadedSuites.Count(); i++ ) |
|
483 { |
|
484 aUri.Append( iLoadedSuites[ i ]->SuiteName() ); |
|
485 aUri.Append( KSlash ); |
|
486 } |
|
487 } |
|
488 |
|
489 // --------------------------------------------------------------------------- |
|
490 // |
|
491 // --------------------------------------------------------------------------- |
|
492 // |
|
493 void CHnMdModel::EvaluateTopSuiteL() |
|
494 { |
|
495 if ( !iIgnoreEvaluations ) |
|
496 { |
|
497 TInt topItem = iLoadedSuites.Count() - 1; |
|
498 iLoadedSuites[topItem]->EvaluateL( *iCmnPtrs.iContainer->GetSuiteModel(topItem) ); |
|
499 } |
|
500 } |
|
501 |
|
502 // --------------------------------------------------------------------------- |
|
503 // |
|
504 // --------------------------------------------------------------------------- |
|
505 // |
|
506 TInt CHnMdModel::LoadedSuitesCount() |
|
507 { |
|
508 return iLoadedSuites.Count(); |
|
509 } |
|
510 |
|
511 |