|
1 /* |
|
2 * Copyright (c) 2007 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: suite presentation model |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32cmn.h> |
|
20 #include "hnsuitemodel.h" |
|
21 #include "hnsuitemodelcontainer.h" |
|
22 #include "hnitemmodel.h" |
|
23 #include "hnmenuitemmodel.h" |
|
24 #include "hnactionmodel.h" |
|
25 #include "hntoolbarmodel.h" |
|
26 #include "menudebug.h" |
|
27 #include "hnglobals.h" |
|
28 #include "hnsuiteobserver.h" |
|
29 #include "hnattributebase.h" |
|
30 #include "hnattributetext.h" |
|
31 #include "hnitemsorder.h" |
|
32 #include "hneventhandler.h" |
|
33 #include "hnitemfocushandler.h" |
|
34 |
|
35 // ============================ MEMBER FUNCTIONS ============================= |
|
36 |
|
37 |
|
38 // --------------------------------------------------------------------------- |
|
39 // |
|
40 // --------------------------------------------------------------------------- |
|
41 // |
|
42 EXPORT_C CHnSuiteModel* CHnSuiteModel::NewL( CHnEventHandler& aEventHandler, |
|
43 const TDesC& aGenreName ) |
|
44 { |
|
45 CHnSuiteModel* self = new (ELeave) CHnSuiteModel( aEventHandler ); |
|
46 CleanupStack::PushL( self ); |
|
47 self->ConstructL( aGenreName ); |
|
48 CleanupStack::Pop( self ); |
|
49 return self; |
|
50 } |
|
51 |
|
52 // --------------------------------------------------------------------------- |
|
53 // |
|
54 // --------------------------------------------------------------------------- |
|
55 // |
|
56 void CHnSuiteModel::ConstructL( const TDesC& aSuiteName ) |
|
57 { |
|
58 ASSERT( aSuiteName.Length() ); |
|
59 iSuiteName = aSuiteName.AllocL(); |
|
60 iTemplate.CreateL( KNullDesC8() ); |
|
61 iItemsOrder = CHnItemsOrder::NewL(); |
|
62 iExitMode = EExitModeNormal; |
|
63 } |
|
64 |
|
65 // --------------------------------------------------------------------------- |
|
66 // |
|
67 // --------------------------------------------------------------------------- |
|
68 // |
|
69 EXPORT_C CHnSuiteModel::~CHnSuiteModel() |
|
70 { |
|
71 for (TInt i(0) ; i < iSuiteObservers.Count(); i++) |
|
72 { |
|
73 TRAP_IGNORE( iSuiteObservers[i]->HandleSuiteEventL( ESuiteModelDestroyed, this ) ); |
|
74 } |
|
75 |
|
76 if ( iIsVisible && iIsActive ) |
|
77 { |
|
78 TRAP_IGNORE( HandleItemFocusL( iSuiteHighlight.iItemId, EFalse ) ); |
|
79 } |
|
80 delete iItemFocusHandler; |
|
81 TRAP_IGNORE( OfferHnEventL( KIdSuiteUnLoad, |
|
82 GetItemsOrder()->GetSuiteId(), NULL ) ); |
|
83 |
|
84 DEBUG16(("\t_Mm_:KIdSuiteUnLoad - %S",iSuiteName)); |
|
85 |
|
86 iSuiteObservers.Close(); |
|
87 iObserverPriorities.Close(); |
|
88 DEBUG16(("\t_MM_: CHnSuiteModel destructor: %S",iSuiteName)); |
|
89 iTemplate.Close(); |
|
90 delete iTitle; |
|
91 delete iEmptyText; |
|
92 delete iSuiteName; |
|
93 |
|
94 THashMapIter< TInt ,CHnItemModel* > modelIter( iItemsModels ); |
|
95 while( modelIter.NextKey() ) |
|
96 { |
|
97 const TInt* key = modelIter.CurrentKey(); |
|
98 iItemsOrder->RemoveItemId( *key ); |
|
99 CHnItemModel** model = modelIter.CurrentValue(); |
|
100 delete *model; |
|
101 modelIter.RemoveCurrent(); |
|
102 } |
|
103 iItemsModels.Close(); |
|
104 |
|
105 THashMapIter< TInt, CArrayPtr<CHnActionModel>* > actionIter( iActions ); |
|
106 while( actionIter.NextKey() ) |
|
107 { |
|
108 CArrayPtr<CHnActionModel>** actions = actionIter.CurrentValue(); |
|
109 (*actions)->ResetAndDestroy(); |
|
110 delete *actions; |
|
111 actionIter.RemoveCurrent(); |
|
112 } |
|
113 iActions.Close(); |
|
114 delete iItemsOrder; |
|
115 DEBUG16(("\t_MM_: CHnSuiteModel destructor OUT")); |
|
116 } |
|
117 |
|
118 // --------------------------------------------------------------------------- |
|
119 // |
|
120 // --------------------------------------------------------------------------- |
|
121 // |
|
122 CHnSuiteModel::CHnSuiteModel( CHnEventHandler& aEventHandler ) : |
|
123 iItemsModels( &DefaultHash::Integer, &DefaultIdentity::Integer ), |
|
124 iActions( &DefaultHash::Integer, &DefaultIdentity::Integer ), |
|
125 iEmptyItemId( KErrNotFound ), |
|
126 iFocusQueue( KErrNotFound ), |
|
127 iCustomId( KErrNotFound ), |
|
128 iEventHandler( aEventHandler ) |
|
129 { |
|
130 iSuiteHighlight.iWidgetIndex = KErrNotFound; |
|
131 iSuiteHighlight.iItemId = KErrNotFound; |
|
132 iSuiteHighlight.iCustomId = KErrNotFound; |
|
133 } |
|
134 |
|
135 // --------------------------------------------------------------------------- |
|
136 // |
|
137 // --------------------------------------------------------------------------- |
|
138 // |
|
139 TInt CHnSuiteModel::OfferHnEventL( |
|
140 const TInt aEventId, const TInt aRecipientId, |
|
141 CLiwGenericParamList* aEventParameters ) |
|
142 { |
|
143 TInt err( KErrNotFound ); |
|
144 |
|
145 CArrayPtr<CHnActionModel>* actions = GetActions( aEventId ); |
|
146 |
|
147 if ( aRecipientId != KErrNotFound ) |
|
148 { |
|
149 CHnItemModel** itemModel = iItemsModels.Find( aRecipientId ); |
|
150 if ( itemModel && *itemModel ) |
|
151 { |
|
152 err = (*itemModel)->OfferHnEventL( iEventHandler, aEventId, |
|
153 aEventParameters); |
|
154 } |
|
155 } |
|
156 |
|
157 if ( err != KErrNone && actions) |
|
158 { |
|
159 for( TInt i = 0; i < actions->Count(); i++ ) |
|
160 { |
|
161 ASSERT( actions->At( i ) ); |
|
162 err = actions->At( i )->ExecuteL( iEventHandler, aEventParameters ); |
|
163 if ( err != KErrNone ) |
|
164 { |
|
165 break; |
|
166 } |
|
167 } |
|
168 } |
|
169 return err; |
|
170 } |
|
171 |
|
172 // --------------------------------------------------------------------------- |
|
173 // |
|
174 // --------------------------------------------------------------------------- |
|
175 // |
|
176 EXPORT_C TBool CHnSuiteModel::ItemEvaluationFinishedL( TInt aModelItemNumber ) |
|
177 { |
|
178 TBool observersNotified( EFalse ); |
|
179 TBool alreadyNotified = iItemsOrder->IsSuiteReadyToShow(); |
|
180 iItemsOrder->ItemEvaluated( aModelItemNumber ); |
|
181 if ( iItemsOrder->IsSuiteReadyToShow() && !alreadyNotified ) |
|
182 { |
|
183 TRAP_IGNORE( OfferHnEventL( KIdSuiteLoad, |
|
184 GetItemsOrder()->GetSuiteId(), NULL ) ); |
|
185 DEBUG16(("\t_Mm_:KIdSuiteLoad - %S",iSuiteName)); |
|
186 NotifyObserversL( ESuiteModelInitialized ); |
|
187 observersNotified = ETrue; |
|
188 } |
|
189 return observersNotified; |
|
190 } |
|
191 |
|
192 // --------------------------------------------------------------------------- |
|
193 // |
|
194 // --------------------------------------------------------------------------- |
|
195 // |
|
196 EXPORT_C TBool CHnSuiteModel::SuiteEvaluationFinishedL( ) |
|
197 { |
|
198 TBool observersNotified( EFalse ); |
|
199 TBool alreadyNotified = iItemsOrder->IsSuiteReadyToShow(); |
|
200 iItemsOrder->SuiteEvaluated(); |
|
201 if ( iItemsOrder->IsSuiteReadyToShow() && !alreadyNotified ) |
|
202 { |
|
203 TRAP_IGNORE( OfferHnEventL( KIdSuiteLoad, |
|
204 GetItemsOrder()->GetSuiteId(), NULL ) ); |
|
205 DEBUG16(("\t_Mm_:KIdSuiteLoad - %S",iSuiteName)); |
|
206 NotifyObserversL( ESuiteModelInitialized ); |
|
207 observersNotified = ETrue; |
|
208 } |
|
209 return observersNotified; |
|
210 } |
|
211 |
|
212 // --------------------------------------------------------------------------- |
|
213 // |
|
214 // --------------------------------------------------------------------------- |
|
215 // |
|
216 EXPORT_C TInt CHnSuiteModel::GetItemModelsCount() |
|
217 { |
|
218 return iItemsModels.Count(); |
|
219 } |
|
220 |
|
221 // --------------------------------------------------------------------------- |
|
222 // |
|
223 // --------------------------------------------------------------------------- |
|
224 // |
|
225 EXPORT_C const TDesC& CHnSuiteModel::SuiteName() const |
|
226 { |
|
227 return *iSuiteName; |
|
228 } |
|
229 |
|
230 // --------------------------------------------------------------------------- |
|
231 // |
|
232 // --------------------------------------------------------------------------- |
|
233 // |
|
234 EXPORT_C const TDesC& CHnSuiteModel::Title() const |
|
235 { |
|
236 if ( iTitle ) |
|
237 { |
|
238 return *iTitle; |
|
239 } |
|
240 else |
|
241 { |
|
242 return KNullDesC(); |
|
243 } |
|
244 } |
|
245 |
|
246 // --------------------------------------------------------------------------- |
|
247 // |
|
248 // --------------------------------------------------------------------------- |
|
249 // |
|
250 EXPORT_C void CHnSuiteModel::SetTitleL( const TDesC& aName ) |
|
251 { |
|
252 delete iTitle; |
|
253 iTitle = NULL; |
|
254 iTitle = aName.AllocL(); |
|
255 } |
|
256 |
|
257 // --------------------------------------------------------------------------- |
|
258 // |
|
259 // --------------------------------------------------------------------------- |
|
260 // |
|
261 EXPORT_C const TDesC& CHnSuiteModel::EmptyText() const |
|
262 { |
|
263 if ( iEmptyText ) |
|
264 { |
|
265 return *iEmptyText; |
|
266 } |
|
267 else |
|
268 { |
|
269 return KNullDesC(); |
|
270 } |
|
271 } |
|
272 |
|
273 // --------------------------------------------------------------------------- |
|
274 // |
|
275 // --------------------------------------------------------------------------- |
|
276 // |
|
277 EXPORT_C void CHnSuiteModel::SetEmptyTextL( const TDesC& aName ) |
|
278 { |
|
279 delete iEmptyText; |
|
280 iEmptyText = NULL; |
|
281 iEmptyText = aName.AllocL(); |
|
282 } |
|
283 |
|
284 // --------------------------------------------------------------------------- |
|
285 // |
|
286 // --------------------------------------------------------------------------- |
|
287 // |
|
288 EXPORT_C TInt CHnSuiteModel::WidgetType() const |
|
289 { |
|
290 //Following check is necessary because suite can be |
|
291 //during evalutation -> UI Widgets can try to get and process templates |
|
292 //what causes problems. Only when suite is fully evaluated and |
|
293 //ready to be shown it returns widget type. |
|
294 THnSuiteWidgetType ret( EUnspecified ); |
|
295 if ( iItemsOrder->IsSuiteReadyToShow() ) |
|
296 { |
|
297 ret = iWidgetType; |
|
298 } |
|
299 return ret; |
|
300 } |
|
301 |
|
302 // --------------------------------------------------------------------------- |
|
303 // |
|
304 // --------------------------------------------------------------------------- |
|
305 // |
|
306 EXPORT_C void CHnSuiteModel::SetWidgetType( THnSuiteWidgetType aWidgetType ) |
|
307 { |
|
308 iWidgetType = aWidgetType; |
|
309 } |
|
310 |
|
311 // --------------------------------------------------------------------------- |
|
312 // |
|
313 // --------------------------------------------------------------------------- |
|
314 // |
|
315 EXPORT_C MHnMenuItemModelIterator* CHnSuiteModel::GetMenuStructureL( |
|
316 TInt aItemId ) |
|
317 { |
|
318 if (aItemId == KErrNotFound) |
|
319 { |
|
320 // this could be used in future for empty item |
|
321 return NULL; |
|
322 } |
|
323 return iItemsModels.FindL( aItemId )->GetMenuStructure(); |
|
324 } |
|
325 |
|
326 // --------------------------------------------------------------------------- |
|
327 // |
|
328 // --------------------------------------------------------------------------- |
|
329 // |
|
330 EXPORT_C void CHnSuiteModel::AddItemL( TInt aId, CHnItemModel* aItemModel, |
|
331 TInt aItemModelNumber, TInt aItemModelPosition ) |
|
332 { |
|
333 DEBUG16(("_MM_: CHnSuiteModel::AddItemL IN")); |
|
334 ASSERT( aItemModel ); |
|
335 |
|
336 TInt highlightedItem( iSuiteHighlight.iCustomId ); |
|
337 iItemsModels.InsertL( aId, aItemModel ); |
|
338 |
|
339 // "empty" item should not be added to ordering table |
|
340 if ( !aItemModel->GetTemplate().Compare( KTemplateEmpty8 ) ) |
|
341 { |
|
342 // store id of empty item |
|
343 iEmptyItemId = aId; |
|
344 } |
|
345 else |
|
346 { |
|
347 iItemsOrder->InsertItemIdToL( aItemModelNumber, aItemModelPosition, aId ); |
|
348 DEBUG16(("_MM_: Adding at index: model no. %D item no. %D, id: %D", aItemModelNumber, aItemModelPosition, aId)); |
|
349 |
|
350 // focus queue |
|
351 if ( ( iFocusQueue >= 0 ) && ( iFocusQueue == aItemModel->CustomId() ) ) |
|
352 { |
|
353 SetSuiteHighlightL( iItemsOrder->Count() - 1 ); |
|
354 iFocusQueue = KErrGeneral ; |
|
355 } |
|
356 else if( aItemModel->CustomId() != KErrNotFound ) |
|
357 { |
|
358 SetSuiteHighlightByCustomIdL( highlightedItem ); |
|
359 } |
|
360 } |
|
361 |
|
362 DEBUG16(("_MM_: CHnSuiteModel::AddItemL OUT")); |
|
363 } |
|
364 |
|
365 // --------------------------------------------------------------------------- |
|
366 // |
|
367 // --------------------------------------------------------------------------- |
|
368 // |
|
369 EXPORT_C const TDesC8& CHnSuiteModel::GetTemplate() const |
|
370 { |
|
371 //Following check is necessary because suite can be |
|
372 //during evalutation -> UI Widgets can try to get and process templates |
|
373 //what causes problems. Only when suite is fully evaluated and |
|
374 //ready to be shown it returns templates. |
|
375 if ( iItemsOrder->IsSuiteReadyToShow() ) |
|
376 { |
|
377 return iTemplate; |
|
378 } |
|
379 return KNullDesC8; |
|
380 } |
|
381 |
|
382 // --------------------------------------------------------------------------- |
|
383 // |
|
384 // --------------------------------------------------------------------------- |
|
385 // |
|
386 EXPORT_C void CHnSuiteModel::SetTemplateL( const TDesC8& aValue ) |
|
387 { |
|
388 if( aValue.Compare( iTemplate ) ) |
|
389 { |
|
390 iTemplate.Close(); |
|
391 iTemplate.CreateL( aValue.Length() + 1); |
|
392 iTemplate.Copy( aValue ); |
|
393 const char* templateChar = reinterpret_cast<const char* >( |
|
394 iTemplate.PtrZ() ); |
|
395 } |
|
396 } |
|
397 |
|
398 // --------------------------------------------------------------------------- |
|
399 // |
|
400 // --------------------------------------------------------------------------- |
|
401 // |
|
402 EXPORT_C void CHnSuiteModel::NotifyObserversL( THnCustomSuiteEvent aEventType ) |
|
403 { |
|
404 RPointerArray<MHnSuiteObserver> observerFreezedArray; |
|
405 CleanupClosePushL( observerFreezedArray ); |
|
406 |
|
407 for (TInt i(0); i < iSuiteObservers.Count(); i++) |
|
408 { |
|
409 observerFreezedArray.AppendL( iSuiteObservers[i] ); |
|
410 } |
|
411 |
|
412 for (TInt i(0); i < observerFreezedArray.Count(); i++) |
|
413 { |
|
414 observerFreezedArray[i]->HandleSuiteEventL( aEventType, this ); |
|
415 } |
|
416 |
|
417 CleanupStack::PopAndDestroy( &observerFreezedArray ); |
|
418 } |
|
419 // --------------------------------------------------------------------------- |
|
420 // |
|
421 // --------------------------------------------------------------------------- |
|
422 // |
|
423 EXPORT_C void CHnSuiteModel::RefreshMulModelL( TInt aPreviousItemCount ) |
|
424 { |
|
425 if (iItemsOrder->IsSuiteReadyToShow()) |
|
426 { |
|
427 TInt modelcount = iItemsOrder->Count(); |
|
428 if ( aPreviousItemCount < modelcount ) |
|
429 { |
|
430 NotifyObserversL(ESuiteItemsAdded); |
|
431 } |
|
432 else if ( aPreviousItemCount > modelcount ) |
|
433 { |
|
434 NotifyObserversL(ESuiteItemsRemoved); |
|
435 } |
|
436 else |
|
437 { |
|
438 NotifyObserversL(ESuiteItemsUpdated); |
|
439 } |
|
440 } |
|
441 } |
|
442 |
|
443 // --------------------------------------------------------------------------- |
|
444 // |
|
445 // --------------------------------------------------------------------------- |
|
446 // |
|
447 EXPORT_C void CHnSuiteModel::UpdateItemTemplateL( TInt aId ) |
|
448 { |
|
449 TInt position = iItemsOrder->GetItemPosition( aId ); |
|
450 if( position != KErrNotFound ) |
|
451 { |
|
452 CHnItemModel** model = iItemsModels.Find( aId ); |
|
453 if (model && !(*model)->GetTemplate().Compare( KNullDesC8() ) ) |
|
454 { |
|
455 (*model)->SetTemplateL( GetTemplate() ); |
|
456 } |
|
457 } |
|
458 } |
|
459 |
|
460 // --------------------------------------------------------------------------- |
|
461 // |
|
462 // --------------------------------------------------------------------------- |
|
463 // |
|
464 EXPORT_C void CHnSuiteModel::RegisterSuiteObserverL( MHnSuiteObserver* aObserver, |
|
465 TThreadPriority aPriority ) |
|
466 { |
|
467 TInt i(0); |
|
468 TInt posFound = iSuiteObservers.Find( aObserver ); |
|
469 if ( posFound != KErrNotFound ) |
|
470 { |
|
471 iObserverPriorities.Remove( posFound ); |
|
472 iSuiteObservers.Remove( posFound ); |
|
473 } |
|
474 |
|
475 for (; i < iObserverPriorities.Count(); i++) |
|
476 { |
|
477 if (aPriority > iObserverPriorities[i]) |
|
478 { |
|
479 break; |
|
480 } |
|
481 } |
|
482 |
|
483 iObserverPriorities.InsertL( aPriority , i ); |
|
484 iSuiteObservers.InsertL( aObserver, i ); |
|
485 |
|
486 if ( iItemsOrder->IsSuiteReadyToShow() && posFound == KErrNotFound ) |
|
487 { |
|
488 aObserver->HandleSuiteEventL( ESuiteModelInitialized, this ); |
|
489 } |
|
490 |
|
491 } |
|
492 |
|
493 // --------------------------------------------------------------------------- |
|
494 // |
|
495 // --------------------------------------------------------------------------- |
|
496 // |
|
497 EXPORT_C void CHnSuiteModel::UnregisterSuiteObserver( MHnSuiteObserver* aObserver) |
|
498 { |
|
499 TInt index = iSuiteObservers.Find( aObserver ); |
|
500 if (index != KErrNotFound) |
|
501 { |
|
502 iSuiteObservers.Remove( index ); |
|
503 iObserverPriorities.Remove( index ); |
|
504 } |
|
505 } |
|
506 |
|
507 // --------------------------------------------------------------------------- |
|
508 // |
|
509 // --------------------------------------------------------------------------- |
|
510 // |
|
511 EXPORT_C void CHnSuiteModel::RemoveItemL( TInt aId ) |
|
512 { |
|
513 TInt highlightedItem( KErrNotFound ); |
|
514 CHnItemModel* modelToRemove = GetItemModel( aId ); |
|
515 if( modelToRemove ) |
|
516 { |
|
517 if( modelToRemove->CustomId() != KErrNotFound ) |
|
518 { |
|
519 if (modelToRemove->CustomId() != iSuiteHighlight.iCustomId ) |
|
520 { |
|
521 highlightedItem = iSuiteHighlight.iCustomId; |
|
522 } |
|
523 else |
|
524 { |
|
525 // set the highlight to the item before the removed item. |
|
526 TInt newWidgetIndex = iItemsOrder->Count() - 2; |
|
527 if( newWidgetIndex < 0 ) |
|
528 { |
|
529 newWidgetIndex = 0; |
|
530 } |
|
531 SetSuiteHighlightL( newWidgetIndex ); |
|
532 } |
|
533 } |
|
534 delete modelToRemove; |
|
535 iItemsModels.Remove( aId ); |
|
536 } |
|
537 iItemsOrder->RemoveItemId( aId ); |
|
538 SetSuiteHighlightByCustomIdL( highlightedItem ); |
|
539 } |
|
540 |
|
541 // --------------------------------------------------------------------------- |
|
542 // |
|
543 // --------------------------------------------------------------------------- |
|
544 // |
|
545 EXPORT_C void CHnSuiteModel::RemoveAllItems() |
|
546 { |
|
547 THashMapIter< TInt ,CHnItemModel* > iterator( iItemsModels ); |
|
548 while( iterator.NextKey() ) |
|
549 { |
|
550 CHnItemModel** model = iterator.CurrentValue(); |
|
551 delete *model; |
|
552 iterator.RemoveCurrent(); |
|
553 } |
|
554 } |
|
555 |
|
556 // --------------------------------------------------------------------------- |
|
557 // |
|
558 // --------------------------------------------------------------------------- |
|
559 // |
|
560 EXPORT_C RHashMap< TInt, CArrayPtr<CHnActionModel>* >& |
|
561 CHnSuiteModel::GetActions() |
|
562 { |
|
563 return iActions; |
|
564 } |
|
565 |
|
566 // --------------------------------------------------------------------------- |
|
567 // |
|
568 // --------------------------------------------------------------------------- |
|
569 // |
|
570 EXPORT_C CArrayPtr<CHnActionModel>* CHnSuiteModel::GetActions( TInt aId ) |
|
571 { |
|
572 CArrayPtr<CHnActionModel>** ret = iActions.Find( aId ); |
|
573 if( ret ) |
|
574 { |
|
575 return *ret; |
|
576 } |
|
577 return NULL; |
|
578 } |
|
579 |
|
580 // --------------------------------------------------------------------------- |
|
581 // |
|
582 // --------------------------------------------------------------------------- |
|
583 // |
|
584 EXPORT_C CHnItemModel* CHnSuiteModel::GetItemModel( TInt aId ) |
|
585 { |
|
586 TRAP_IGNORE( UpdateItemTemplateL( aId ) ); |
|
587 |
|
588 CHnItemModel** model = iItemsModels.Find( aId ); |
|
589 return ( model ) ? *model : NULL; |
|
590 } |
|
591 |
|
592 // --------------------------------------------------------------------------- |
|
593 // |
|
594 // --------------------------------------------------------------------------- |
|
595 // |
|
596 EXPORT_C TBool CHnSuiteModel::HasToolbar() const |
|
597 { |
|
598 TBool hasToolbar = EFalse; |
|
599 THashMapIter< TInt ,CHnItemModel* > modelIter( iItemsModels ); |
|
600 while( modelIter.NextKey() ) |
|
601 { |
|
602 CHnItemModel** model = modelIter.CurrentValue(); |
|
603 const CHnToolbarModel * toolbarModel = ( *model )->GetToolbarModel(); |
|
604 hasToolbar = (toolbarModel) ? toolbarModel->HasButtons() : EFalse; |
|
605 if( hasToolbar ) |
|
606 { |
|
607 break; |
|
608 } |
|
609 } |
|
610 return hasToolbar; |
|
611 } |
|
612 |
|
613 // --------------------------------------------------------------------------- |
|
614 // |
|
615 // --------------------------------------------------------------------------- |
|
616 // |
|
617 EXPORT_C TInt CHnSuiteModel::IdByIndex( TInt aIndex ) |
|
618 { |
|
619 TInt result(KErrNotFound); |
|
620 |
|
621 if (aIndex < 0) |
|
622 { |
|
623 result = iEmptyItemId; |
|
624 } |
|
625 else |
|
626 { |
|
627 result = iItemsOrder->GetItemIdAt( aIndex ); |
|
628 } |
|
629 |
|
630 return result; |
|
631 } |
|
632 |
|
633 // --------------------------------------------------------------------------- |
|
634 // |
|
635 // --------------------------------------------------------------------------- |
|
636 // |
|
637 EXPORT_C TBool CHnSuiteModel::IsItemMoveLocked( TInt aIndex ) |
|
638 { |
|
639 TInt ret( EFalse ); |
|
640 |
|
641 if (aIndex >= 0) |
|
642 { |
|
643 CHnItemModel** itemModel = iItemsModels.Find( |
|
644 iItemsOrder->GetItemIdAt( aIndex ) ); |
|
645 |
|
646 if ( !itemModel || (*itemModel)->IsMoveLocked() ) |
|
647 { |
|
648 ret = ETrue; |
|
649 } |
|
650 } |
|
651 |
|
652 return ret; |
|
653 } |
|
654 |
|
655 // --------------------------------------------------------------------------- |
|
656 // |
|
657 // --------------------------------------------------------------------------- |
|
658 // |
|
659 EXPORT_C TMcsItemType CHnSuiteModel::GetItemType( TInt aIndex ) |
|
660 { |
|
661 TMcsItemType type = EItemTypeUnknown; |
|
662 |
|
663 CHnItemModel** itemModel = iItemsModels.Find( |
|
664 iItemsOrder->GetItemIdAt( aIndex ) ); |
|
665 |
|
666 if ( itemModel ) |
|
667 { |
|
668 type = (*itemModel)->GetItemType(); |
|
669 } |
|
670 |
|
671 return type; |
|
672 } |
|
673 |
|
674 // --------------------------------------------------------------------------- |
|
675 // |
|
676 // --------------------------------------------------------------------------- |
|
677 // |
|
678 EXPORT_C TInt CHnSuiteModel::GetSuiteHighlight() |
|
679 { |
|
680 return iSuiteHighlight.iWidgetIndex; |
|
681 } |
|
682 |
|
683 // --------------------------------------------------------------------------- |
|
684 // |
|
685 // --------------------------------------------------------------------------- |
|
686 // |
|
687 EXPORT_C void CHnSuiteModel::SetSuiteHighlightL( TInt aHighLight ) |
|
688 { |
|
689 DEBUG(("_MM_:CHnSuiteModel::SetSuiteHighlight - IN")); |
|
690 DEBUG(("\t_MM_:aHighLight: %d",aHighLight)); |
|
691 |
|
692 TInt newItemId( IdByIndex( aHighLight ) ); |
|
693 CHnItemModel* itemModel( GetItemModel( newItemId ) ); |
|
694 TInt64 newCustomId( KErrNotFound ); |
|
695 if ( itemModel ) |
|
696 { |
|
697 newCustomId = itemModel->CustomId(); |
|
698 } |
|
699 |
|
700 if ( ( newCustomId != iSuiteHighlight.iCustomId || |
|
701 newItemId != iSuiteHighlight.iItemId ) && ( iIsActive && iIsVisible ) ) |
|
702 { |
|
703 HandleItemFocusL( iSuiteHighlight.iItemId, EFalse ); |
|
704 HandleItemFocusL( newItemId, ETrue ); |
|
705 } |
|
706 |
|
707 iSuiteHighlight.iCustomId = newCustomId; |
|
708 iSuiteHighlight.iItemId = newItemId; |
|
709 iSuiteHighlight.iWidgetIndex = aHighLight; |
|
710 |
|
711 DEBUG(("_MM_:CHnSuiteModel::SetSuiteHighlight - OUT")); |
|
712 } |
|
713 |
|
714 // --------------------------------------------------------------------------- |
|
715 // |
|
716 // --------------------------------------------------------------------------- |
|
717 // |
|
718 void CHnSuiteModel::SetSuiteHighlightByCustomIdL( TInt64 aCustomId ) |
|
719 { |
|
720 DEBUG(("_MM_:CHnSuiteModel::SetSuiteHighlightByCustomIdL - IN")); |
|
721 DEBUG(("\t_MM_:aHighLight: %d",aCustomId)); |
|
722 |
|
723 if( aCustomId != KErrNotFound ) |
|
724 { |
|
725 THashMapIter< TInt ,CHnItemModel* > modelIter( iItemsModels ); |
|
726 while( modelIter.NextKey() ) |
|
727 { |
|
728 const TInt* id = modelIter.CurrentKey(); |
|
729 CHnItemModel** model = modelIter.CurrentValue(); |
|
730 if( (*model)->CustomId() == aCustomId ) |
|
731 { |
|
732 if( *id != KErrNotFound ) |
|
733 { |
|
734 TInt itemIndex( iItemsOrder->GetItemPosition( *id ) ); |
|
735 if( itemIndex != KErrNotFound ) |
|
736 { |
|
737 SetSuiteHighlightL( itemIndex ); |
|
738 } |
|
739 } |
|
740 break; |
|
741 } |
|
742 } |
|
743 } |
|
744 |
|
745 DEBUG(("_MM_:CHnSuiteModel::SetSuiteHighlightByCustomIdL - OUT")); |
|
746 } |
|
747 |
|
748 // --------------------------------------------------------------------------- |
|
749 // |
|
750 // --------------------------------------------------------------------------- |
|
751 // |
|
752 EXPORT_C TBool CHnSuiteModel::IsItemBetweenMoveLocked( TInt aIndexStart, TInt aIndexEnd ) |
|
753 { |
|
754 if ( aIndexEnd < KErrNone || aIndexStart < KErrNone ) |
|
755 { |
|
756 return ETrue; |
|
757 } |
|
758 if ( aIndexEnd >= iItemsOrder->Count() ) |
|
759 { |
|
760 aIndexEnd = iItemsOrder->Count() - 1; |
|
761 } |
|
762 |
|
763 TInt start( ( aIndexStart > aIndexEnd ) ? aIndexEnd : aIndexStart ); |
|
764 TInt end( ( aIndexStart > aIndexEnd ) ? aIndexStart : aIndexEnd ); |
|
765 |
|
766 TInt ret( EFalse ); |
|
767 |
|
768 for ( TInt index = start; index <= end; index++ ) |
|
769 { |
|
770 CHnItemModel** itemModel = iItemsModels.Find( |
|
771 iItemsOrder->GetItemIdAt( index ) ); |
|
772 if ( !itemModel || (*itemModel)->IsMoveLocked() ) |
|
773 { |
|
774 ret = ETrue; |
|
775 break; |
|
776 } |
|
777 } |
|
778 return ret; |
|
779 } |
|
780 |
|
781 // --------------------------------------------------------------------------- |
|
782 // |
|
783 // --------------------------------------------------------------------------- |
|
784 // |
|
785 EXPORT_C TInt CHnSuiteModel::ReorderItemsL( TInt aFromIndex, TInt aToIndex ) |
|
786 { |
|
787 DEBUG( ("_MM_: CHnSuiteModel::ReorderItems - IN" ) ); |
|
788 |
|
789 TInt operation ( (aFromIndex < aToIndex) ? 1 : -1 ); |
|
790 TInt realFromId = iItemsOrder->GetItemIdAt(aFromIndex); |
|
791 for ( int i = aFromIndex ; (operation == 1 && i < aToIndex) |
|
792 || (operation == -1 && i > aToIndex) ; i = i + operation ) |
|
793 { |
|
794 if ( (i+operation < 0) || (i+operation >= GetItemModelsCount()) ) |
|
795 break; |
|
796 |
|
797 iItemsOrder->SetItemIdAtL(i, iItemsOrder->GetItemIdAt(i+operation)); |
|
798 } |
|
799 |
|
800 iItemsOrder->SetItemIdAtL(aToIndex, realFromId); |
|
801 |
|
802 // recalculate current active item |
|
803 SetSuiteHighlightL( GetSuiteHighlight() ); |
|
804 |
|
805 DEBUG( ("_MM_: CHnSuiteModel::ReorderItems - OUT" ) ); |
|
806 return KErrNone; |
|
807 } |
|
808 |
|
809 // --------------------------------------------------------------------------- |
|
810 // |
|
811 // --------------------------------------------------------------------------- |
|
812 // |
|
813 EXPORT_C CHnItemsOrder* CHnSuiteModel::GetItemsOrder() |
|
814 { |
|
815 return iItemsOrder; |
|
816 } |
|
817 |
|
818 // --------------------------------------------------------------------------- |
|
819 // |
|
820 // --------------------------------------------------------------------------- |
|
821 // |
|
822 EXPORT_C void CHnSuiteModel::QueueFocus( TInt aCustomId ) |
|
823 { |
|
824 iFocusQueue = aCustomId; |
|
825 } |
|
826 |
|
827 // --------------------------------------------------------------------------- |
|
828 // |
|
829 // --------------------------------------------------------------------------- |
|
830 // |
|
831 EXPORT_C void CHnSuiteModel::SetCustomId( TInt64 aCustomId ) |
|
832 { |
|
833 iCustomId = aCustomId; |
|
834 } |
|
835 |
|
836 // --------------------------------------------------------------------------- |
|
837 // |
|
838 // --------------------------------------------------------------------------- |
|
839 // |
|
840 EXPORT_C TInt64 CHnSuiteModel::CustomId() |
|
841 { |
|
842 return iCustomId; |
|
843 } |
|
844 |
|
845 // --------------------------------------------------------------------------- |
|
846 // |
|
847 // --------------------------------------------------------------------------- |
|
848 // |
|
849 EXPORT_C void CHnSuiteModel::SetActiveL( TBool aActive ) |
|
850 { |
|
851 DEBUG16(("_MM_:CHnSuiteModel::SetActiveL %S - IN",iSuiteName)); |
|
852 DEBUG(("\t_MM_:aActive: %d",aActive)); |
|
853 DEBUG(("\t_MM_:iIsActive: %d",iIsActive)); |
|
854 |
|
855 if ( aActive != iIsActive ) |
|
856 { |
|
857 iIsActive = aActive; |
|
858 if ( iIsVisible ) |
|
859 { |
|
860 HandleItemFocusL( iSuiteHighlight.iItemId, aActive ); |
|
861 } |
|
862 } |
|
863 |
|
864 DEBUG(("_MM_:CHnSuiteModel::SetActiveL - OUT")); |
|
865 } |
|
866 |
|
867 // --------------------------------------------------------------------------- |
|
868 // |
|
869 // --------------------------------------------------------------------------- |
|
870 // |
|
871 EXPORT_C TBool CHnSuiteModel::IsActive() |
|
872 { |
|
873 return iIsActive; |
|
874 } |
|
875 |
|
876 // --------------------------------------------------------------------------- |
|
877 // |
|
878 // --------------------------------------------------------------------------- |
|
879 // |
|
880 EXPORT_C void CHnSuiteModel::SetVisibleL( TBool aVisible ) |
|
881 { |
|
882 DEBUG16(("_MM_:CHnSuiteModel::SetVisible %S - IN",iSuiteName)); |
|
883 DEBUG(("\t_MM_:aVisible: %d",aVisible)); |
|
884 DEBUG(("\t_MM_:iIsVisible: %d",iIsVisible)); |
|
885 |
|
886 if ( aVisible != iIsVisible ) |
|
887 { |
|
888 iIsVisible = aVisible; |
|
889 if ( iIsActive ) |
|
890 { |
|
891 HandleItemFocusL( iSuiteHighlight.iItemId, aVisible ); |
|
892 } |
|
893 } |
|
894 |
|
895 DEBUG(("_MM_:CHnSuiteModel::SetVisible - OUT")); |
|
896 } |
|
897 |
|
898 // --------------------------------------------------------------------------- |
|
899 // |
|
900 // --------------------------------------------------------------------------- |
|
901 // |
|
902 void CHnSuiteModel::HandleItemFocusL( TInt aItemId, TBool aFocused ) |
|
903 { |
|
904 DEBUG16(("_MM_:CHnSuiteModel::HandleItemFocusL %S - IN",iSuiteName)); |
|
905 DEBUG(("\t_MM_:aItemIndex: %d",aItemId)); |
|
906 DEBUG(("\t_MM_:aFocused: %d",aFocused)); |
|
907 |
|
908 if ( aItemId >= 0 ) |
|
909 { |
|
910 if ( !iItemFocusHandler ) |
|
911 { |
|
912 iItemFocusHandler = CHnItemFocusHandler::NewL( this ); |
|
913 } |
|
914 TInt eventId = aFocused ? KIdFocusGain : KIdFocusLost; |
|
915 iItemFocusHandler->SetFocusL( eventId, aItemId ); |
|
916 // TRAP_IGNORE( OfferHnEventL( eventId, aItemId, NULL ) ); |
|
917 } |
|
918 |
|
919 DEBUG(("_MM_:CHnSuiteModel::HandleItemFocusL - OUT")); |
|
920 } |
|
921 |
|
922 // --------------------------------------------------------------------------- |
|
923 // |
|
924 // --------------------------------------------------------------------------- |
|
925 // |
|
926 EXPORT_C CHnItemModel* CHnSuiteModel::GetMatchingItemModelL( TInt64 aCustomId, |
|
927 TInt& aIndex ) |
|
928 { |
|
929 CHnItemModel* itemModel( NULL ); |
|
930 |
|
931 // check suiteCustomId |
|
932 if ( aCustomId >= 0 ) |
|
933 { |
|
934 for ( TInt i( 0 ); i < GetItemModelsCount(); i++ ) |
|
935 { |
|
936 TInt itemModelId = IdByIndex( i ); |
|
937 CHnItemModel* tmpItemModel = GetItemModel( itemModelId ); |
|
938 |
|
939 if ( tmpItemModel && |
|
940 tmpItemModel->CustomId() == aCustomId ) |
|
941 { |
|
942 aIndex = i; |
|
943 itemModel = tmpItemModel; |
|
944 break; |
|
945 } |
|
946 } |
|
947 } |
|
948 |
|
949 return itemModel; |
|
950 } |
|
951 |
|
952 // --------------------------------------------------------------------------- |
|
953 // |
|
954 // --------------------------------------------------------------------------- |
|
955 // |
|
956 EXPORT_C void CHnSuiteModel::SetExitMode( TExitMode aExitMode ) |
|
957 { |
|
958 iExitMode = aExitMode; |
|
959 } |
|
960 |
|
961 // --------------------------------------------------------------------------- |
|
962 // |
|
963 // --------------------------------------------------------------------------- |
|
964 // |
|
965 void CHnSuiteModel::RemoveLiwObjects() |
|
966 { |
|
967 for ( TInt i = 0; i < GetItemModelsCount(); ++i ) |
|
968 { |
|
969 CHnItemModel* itemModel = GetItemModel( IdByIndex( i ) ); |
|
970 if ( itemModel ) |
|
971 { |
|
972 itemModel->RemoveLiwObjects(); |
|
973 } |
|
974 } |
|
975 } |
|
976 |
|
977 // --------------------------------------------------------------------------- |
|
978 // |
|
979 // --------------------------------------------------------------------------- |
|
980 // |
|
981 EXPORT_C TExitMode CHnSuiteModel::ExitMode() |
|
982 { |
|
983 return iExitMode; |
|
984 } |
|
985 |
|
986 |
|
987 // End of file |