menufw/menufwui/mmwidgets/src/mmcacheforitem.cpp
changeset 0 f72a12da539e
child 4 4d54b72983ae
equal deleted inserted replaced
-1:000000000000 0:f72a12da539e
       
     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:
       
    15 * Version     : 2 << Don't touch! Updated by Synergy at check-out.
       
    16 *
       
    17 */
       
    18 
       
    19 #include "mmcacheforitem.h"
       
    20 #include "mmitemsdatacache.h"
       
    21 #include "hniconholder.h"
       
    22 
       
    23 const TInt KIconHolderListGranularity = 2;
       
    24 
       
    25 // -----------------------------------------------------------------------------
       
    26 //
       
    27 // -----------------------------------------------------------------------------
       
    28 //
       
    29 CMmCacheForItem* CMmCacheForItem::NewLC( CMmItemsDataCache& aParent )
       
    30     {
       
    31     CMmCacheForItem* self = new (ELeave) CMmCacheForItem( aParent );
       
    32     CleanupStack::PushL( self );
       
    33     self->ConstructL();
       
    34     return self;
       
    35     }
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 //
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 CMmCacheForItem* CMmCacheForItem::NewL( CMmItemsDataCache& aParent )
       
    42     {
       
    43     CMmCacheForItem* self = NewLC( aParent );
       
    44     CleanupStack::Pop( self );
       
    45     return self;
       
    46     }
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 CMmCacheForItem::~CMmCacheForItem()
       
    53     {
       
    54     ClearIconArray();
       
    55     iIconHolderList.Close();
       
    56     iItemText.Close();
       
    57     }
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 const TDesC8& CMmCacheForItem::GetTemplate() const
       
    64     {
       
    65     __ASSERT_DEBUG( iIsValid, User::Invariant() );
       
    66     return iParent.GetTemplateNameByIdentifier( iTemplateIdentifier );
       
    67     }
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 void CMmCacheForItem::SetTemplateL( const TDesC8& aItemTemplate )
       
    74     {
       
    75     iTemplateIdentifier = iParent.GetTemplateIdentifierL( aItemTemplate );
       
    76     }
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 CArrayPtr<CGulIcon>* CMmCacheForItem::GetIconListL()
       
    83     {
       
    84     __ASSERT_DEBUG( iIsValid, User::Invariant() );
       
    85 
       
    86     const TInt iconCount = iIconHolderList.Count();
       
    87     CArrayPtr<CGulIcon>* iconList = new (ELeave) CArrayPtrFlat<CGulIcon>(
       
    88              Max( iconCount, 1 ) );
       
    89     CleanupStack::PushL( iconList );
       
    90     
       
    91     for ( TInt i = 0; i < iconCount; ++i )
       
    92         {
       
    93         iconList->AppendL( iIconHolderList[i]->GetGulIcon() );
       
    94         }
       
    95     
       
    96     CleanupStack::Pop( iconList );
       
    97     return iconList;
       
    98     }
       
    99 
       
   100 // -----------------------------------------------------------------------------
       
   101 //
       
   102 // -----------------------------------------------------------------------------
       
   103 //
       
   104 TInt CMmCacheForItem::AppendIconL( CHnIconHolder* aIconHolder )
       
   105     {
       
   106     ASSERT( aIconHolder );
       
   107     iIconHolderList.AppendL( aIconHolder );
       
   108     TInt itemIndex =  iIconHolderList.Count() - 1;
       
   109     TInt err = aIconHolder->Open();
       
   110     if ( err != KErrNone )
       
   111         {
       
   112         iIconHolderList.Remove( itemIndex );
       
   113         User::Leave( err );
       
   114         }
       
   115     return itemIndex;
       
   116     }
       
   117 
       
   118 // -----------------------------------------------------------------------------
       
   119 //
       
   120 // -----------------------------------------------------------------------------
       
   121 //
       
   122 void CMmCacheForItem::ClearIconArray()
       
   123     {
       
   124     const TInt count = iIconHolderList.Count();
       
   125     for (TInt i = 0; i < count; ++i )
       
   126         {
       
   127         iIconHolderList[i]->Close();
       
   128         }
       
   129     if ( count )
       
   130         {
       
   131         iIconHolderList.Reset();
       
   132         }
       
   133     }
       
   134 
       
   135 // -----------------------------------------------------------------------------
       
   136 //
       
   137 // -----------------------------------------------------------------------------
       
   138 //
       
   139 void CMmCacheForItem::InvalidateIfCacheMayNotBeUsed( TBool aIsItemCurrent,
       
   140             TMmSubcellsSetupCode aSubcellsSetupCode )
       
   141     {
       
   142     if ( iSubcellsSetupCode != aSubcellsSetupCode ||
       
   143             (!!iIsCurrent) != (!!aIsItemCurrent) )
       
   144         {
       
   145         iIsValid = EFalse;
       
   146         }
       
   147     }
       
   148 
       
   149 // -----------------------------------------------------------------------------
       
   150 //
       
   151 // -----------------------------------------------------------------------------
       
   152 //
       
   153 CMmCacheForItem::CMmCacheForItem( CMmItemsDataCache& aParent )
       
   154     : iIconHolderList( KIconHolderListGranularity ), iParent( aParent )
       
   155     {
       
   156     }
       
   157 
       
   158 // -----------------------------------------------------------------------------
       
   159 //
       
   160 // -----------------------------------------------------------------------------
       
   161 //
       
   162 void CMmCacheForItem::ConstructL()
       
   163     {    
       
   164     }