34
|
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 "mmitemsdatacache.h"
|
|
20 |
#include "mmcacheforitem.h"
|
|
21 |
|
|
22 |
const TInt KItemCacheArrGranularity = 20;
|
|
23 |
|
|
24 |
// -----------------------------------------------------------------------------
|
|
25 |
//
|
|
26 |
// -----------------------------------------------------------------------------
|
|
27 |
//
|
|
28 |
CMmItemsDataCache* CMmItemsDataCache::NewLC()
|
|
29 |
{
|
|
30 |
CMmItemsDataCache* self = new (ELeave) CMmItemsDataCache();
|
|
31 |
CleanupStack::PushL( self );
|
|
32 |
self->ConstructL();
|
|
33 |
return self;
|
|
34 |
}
|
|
35 |
|
|
36 |
// -----------------------------------------------------------------------------
|
|
37 |
//
|
|
38 |
// -----------------------------------------------------------------------------
|
|
39 |
//
|
|
40 |
CMmItemsDataCache* CMmItemsDataCache::NewL()
|
|
41 |
{
|
|
42 |
CMmItemsDataCache* self = NewLC();
|
|
43 |
CleanupStack::Pop( self );
|
|
44 |
return self;
|
|
45 |
}
|
|
46 |
|
|
47 |
// -----------------------------------------------------------------------------
|
|
48 |
//
|
|
49 |
// -----------------------------------------------------------------------------
|
|
50 |
//
|
|
51 |
CMmCacheForItem* CMmItemsDataCache::GetItemCacheL( TInt aItemIndex )
|
|
52 |
{
|
|
53 |
ASSERT( aItemIndex >= 0 );
|
|
54 |
while ( iItemCacheArr.Count() <= aItemIndex )
|
|
55 |
{
|
|
56 |
CMmCacheForItem* cacheForItem = CMmCacheForItem::NewLC( *this );
|
|
57 |
iItemCacheArr.AppendL( cacheForItem );
|
|
58 |
CleanupStack::Pop( cacheForItem );
|
|
59 |
}
|
|
60 |
return iItemCacheArr[aItemIndex];
|
|
61 |
}
|
|
62 |
|
|
63 |
// -----------------------------------------------------------------------------
|
|
64 |
//
|
|
65 |
// -----------------------------------------------------------------------------
|
|
66 |
//
|
|
67 |
TInt CMmItemsDataCache::GetTemplateIdentifierL( const TDesC8& aTemplateName )
|
|
68 |
{
|
|
69 |
TInt identifier = KErrNotFound;
|
|
70 |
|
|
71 |
// this looks very primitive, but RPointerArray::FindL just compares pointers
|
|
72 |
// so I guess there is no other way
|
|
73 |
TInt templateCount = iTemplateNames.Count();
|
|
74 |
for ( TInt i = 0; i < templateCount; ++i )
|
|
75 |
{
|
|
76 |
if ( iTemplateNames[i]->Compare( aTemplateName ) == 0 )
|
|
77 |
{
|
|
78 |
identifier = i;
|
|
79 |
break;
|
|
80 |
}
|
|
81 |
}
|
|
82 |
|
|
83 |
if ( identifier == KErrNotFound )
|
|
84 |
{
|
|
85 |
HBufC8* templateNameCopy = HBufC8::NewLC( aTemplateName.Length() );
|
|
86 |
templateNameCopy->Des().Copy( aTemplateName );
|
|
87 |
iTemplateNames.AppendL( templateNameCopy );
|
|
88 |
CleanupStack::Pop( templateNameCopy );
|
|
89 |
identifier = iTemplateNames.Count() - 1;
|
|
90 |
}
|
|
91 |
return identifier;
|
|
92 |
}
|
|
93 |
|
|
94 |
// -----------------------------------------------------------------------------
|
|
95 |
//
|
|
96 |
// -----------------------------------------------------------------------------
|
|
97 |
//
|
|
98 |
const TDesC8& CMmItemsDataCache::GetTemplateNameByIdentifier(
|
|
99 |
TInt aTemplateIdentifier ) const
|
|
100 |
{
|
|
101 |
return *( iTemplateNames[aTemplateIdentifier] );
|
|
102 |
}
|
|
103 |
|
|
104 |
// -----------------------------------------------------------------------------
|
|
105 |
//
|
|
106 |
// -----------------------------------------------------------------------------
|
|
107 |
//
|
|
108 |
void CMmItemsDataCache::Invalidate()
|
|
109 |
{
|
|
110 |
const TInt count = iItemCacheArr.Count();
|
|
111 |
for ( TInt i = 0; i < count; ++i )
|
|
112 |
{
|
|
113 |
iItemCacheArr[i]->MarkAsInvalid();
|
|
114 |
}
|
|
115 |
}
|
|
116 |
|
|
117 |
// -----------------------------------------------------------------------------
|
|
118 |
//
|
|
119 |
// -----------------------------------------------------------------------------
|
|
120 |
//
|
|
121 |
void CMmItemsDataCache::Trim( TInt aItemCount )
|
|
122 |
{
|
|
123 |
__ASSERT_ALWAYS( aItemCount >= 0, User::Invariant() );
|
|
124 |
for ( TInt i = iItemCacheArr.Count() - 1; i >= aItemCount; --i )
|
|
125 |
{
|
|
126 |
CMmCacheForItem* cache = iItemCacheArr[i];
|
|
127 |
iItemCacheArr.Remove( i );
|
|
128 |
delete cache;
|
|
129 |
}
|
|
130 |
}
|
|
131 |
|
|
132 |
// -----------------------------------------------------------------------------
|
|
133 |
//
|
|
134 |
// -----------------------------------------------------------------------------
|
|
135 |
//
|
|
136 |
CMmItemsDataCache::~CMmItemsDataCache()
|
|
137 |
{
|
|
138 |
iItemCacheArr.ResetAndDestroy();
|
|
139 |
iItemCacheArr.Close();
|
|
140 |
iTemplateNames.ResetAndDestroy();
|
|
141 |
iTemplateNames.Close();
|
|
142 |
}
|
|
143 |
|
|
144 |
// -----------------------------------------------------------------------------
|
|
145 |
//
|
|
146 |
// -----------------------------------------------------------------------------
|
|
147 |
//
|
|
148 |
CMmItemsDataCache::CMmItemsDataCache()
|
|
149 |
: iItemCacheArr( KItemCacheArrGranularity )
|
|
150 |
{
|
|
151 |
}
|
|
152 |
|
|
153 |
// -----------------------------------------------------------------------------
|
|
154 |
//
|
|
155 |
// -----------------------------------------------------------------------------
|
|
156 |
//
|
|
157 |
void CMmItemsDataCache::ConstructL()
|
|
158 |
{
|
|
159 |
}
|