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