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