1 /* |
|
2 * Copyright (c) 2007-2008 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: items order manager class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "hnitemsorder.h" |
|
20 |
|
21 // ============================ MEMBER FUNCTIONS ============================= |
|
22 |
|
23 |
|
24 // --------------------------------------------------------------------------- |
|
25 // |
|
26 // --------------------------------------------------------------------------- |
|
27 // |
|
28 EXPORT_C CHnItemsOrder* CHnItemsOrder::NewL() |
|
29 { |
|
30 CHnItemsOrder* self = NewLC(); |
|
31 self->ConstructL(); |
|
32 CleanupStack::Pop( self ); |
|
33 return self; |
|
34 } |
|
35 |
|
36 // --------------------------------------------------------------------------- |
|
37 // |
|
38 // --------------------------------------------------------------------------- |
|
39 // |
|
40 EXPORT_C void CHnItemsOrder::MarkSuiteUninitialized() |
|
41 { |
|
42 for (TInt i(0); i < iItemsEvaluated.Count(); i++) |
|
43 { |
|
44 iItemsEvaluated[i] = EFalse; |
|
45 } |
|
46 |
|
47 iSuiteEvaluated = EFalse; |
|
48 } |
|
49 // --------------------------------------------------------------------------- |
|
50 // |
|
51 // --------------------------------------------------------------------------- |
|
52 // |
|
53 EXPORT_C CHnItemsOrder* CHnItemsOrder::NewLC() |
|
54 { |
|
55 CHnItemsOrder* self = new( ELeave ) CHnItemsOrder(); |
|
56 CleanupStack::PushL( self ); |
|
57 return self; |
|
58 } |
|
59 |
|
60 // --------------------------------------------------------------------------- |
|
61 // |
|
62 // --------------------------------------------------------------------------- |
|
63 // |
|
64 CHnItemsOrder::~CHnItemsOrder() |
|
65 { |
|
66 iItemsOrderCounts.Reset(); |
|
67 iComplexItemsOrder.Reset(); |
|
68 iItemsEvaluated.Reset(); |
|
69 } |
|
70 |
|
71 // --------------------------------------------------------------------------- |
|
72 // |
|
73 // --------------------------------------------------------------------------- |
|
74 // |
|
75 EXPORT_C void CHnItemsOrder::SetSuiteId( TInt aId ) |
|
76 { |
|
77 iSuiteId = aId; |
|
78 } |
|
79 |
|
80 // --------------------------------------------------------------------------- |
|
81 // |
|
82 // --------------------------------------------------------------------------- |
|
83 // |
|
84 EXPORT_C TInt CHnItemsOrder::GetSuiteId() const |
|
85 { |
|
86 return iSuiteId; |
|
87 } |
|
88 |
|
89 // --------------------------------------------------------------------------- |
|
90 // |
|
91 // --------------------------------------------------------------------------- |
|
92 // |
|
93 EXPORT_C void CHnItemsOrder::RemoveItemId( TInt aId ) |
|
94 { |
|
95 TInt position = iComplexItemsOrder.Find( aId ); |
|
96 if (position != KErrNotFound) |
|
97 { |
|
98 TInt modelNumber = CountModelNumberFor( position ); |
|
99 --iItemsOrderCounts[ modelNumber ] ; |
|
100 iComplexItemsOrder.Remove( position ); |
|
101 } |
|
102 } |
|
103 |
|
104 // --------------------------------------------------------------------------- |
|
105 // |
|
106 // --------------------------------------------------------------------------- |
|
107 // |
|
108 EXPORT_C void CHnItemsOrder::InsertItemIdToL( TInt aDataModelItem, |
|
109 TInt aIndex, TInt aId ) |
|
110 { |
|
111 TInt position = CountStartIndexFor( aDataModelItem ) + aIndex; |
|
112 if (position < iComplexItemsOrder.Count() ) |
|
113 { |
|
114 iComplexItemsOrder.InsertL( aId, position ); |
|
115 } |
|
116 else |
|
117 { |
|
118 iComplexItemsOrder.AppendL( aId ); |
|
119 } |
|
120 |
|
121 TInt modelsCount = iItemsOrderCounts.Count(); |
|
122 if (modelsCount <= aDataModelItem) |
|
123 { |
|
124 for (TInt i(modelsCount); i <= aDataModelItem; i++) |
|
125 { |
|
126 iItemsOrderCounts.AppendL( 0 ); |
|
127 } |
|
128 } |
|
129 ++iItemsOrderCounts[ aDataModelItem ] ; |
|
130 } |
|
131 |
|
132 // --------------------------------------------------------------------------- |
|
133 // |
|
134 // --------------------------------------------------------------------------- |
|
135 // |
|
136 EXPORT_C TInt CHnItemsOrder::GetItemIdAt( TInt aDataModelItem, TInt aIndex ) |
|
137 { |
|
138 TInt globalItemPosition = CountStartIndexFor( aDataModelItem ) + aIndex; |
|
139 return (iComplexItemsOrder.Count() > globalItemPosition) |
|
140 ? iComplexItemsOrder[globalItemPosition] : KErrNotFound; |
|
141 } |
|
142 |
|
143 // --------------------------------------------------------------------------- |
|
144 // |
|
145 // --------------------------------------------------------------------------- |
|
146 // |
|
147 EXPORT_C TInt CHnItemsOrder::GetItemIdAt( TInt aPosition ) |
|
148 { |
|
149 return (iComplexItemsOrder.Count() > aPosition) |
|
150 ? iComplexItemsOrder[aPosition] : KErrNotFound; |
|
151 } |
|
152 |
|
153 // --------------------------------------------------------------------------- |
|
154 // |
|
155 // --------------------------------------------------------------------------- |
|
156 // |
|
157 EXPORT_C void CHnItemsOrder::GetIdsForL( TInt aDataModelItem, |
|
158 RArray< TInt >& aIds ) |
|
159 { |
|
160 if ( CountStartIndexFor( aDataModelItem ) == KErrNotFound |
|
161 || iItemsOrderCounts.Count() <= aDataModelItem ) |
|
162 { |
|
163 return; |
|
164 } |
|
165 |
|
166 TInt startIndex = CountStartIndexFor( aDataModelItem ); |
|
167 |
|
168 for ( TInt i = 0; |
|
169 i < iItemsOrderCounts[ aDataModelItem ]; i++ ) |
|
170 { |
|
171 aIds.AppendL( iComplexItemsOrder[ startIndex + i ] ); |
|
172 } |
|
173 } |
|
174 |
|
175 // --------------------------------------------------------------------------- |
|
176 // |
|
177 // --------------------------------------------------------------------------- |
|
178 // |
|
179 EXPORT_C void CHnItemsOrder::SetItemIdAtL( TInt aPosition, TInt aId ) |
|
180 { |
|
181 if ( aPosition >= iComplexItemsOrder.Count() ) |
|
182 { |
|
183 iComplexItemsOrder.AppendL( aId ); |
|
184 } |
|
185 else |
|
186 { |
|
187 iComplexItemsOrder[ aPosition ] = aId; |
|
188 } |
|
189 } |
|
190 |
|
191 // --------------------------------------------------------------------------- |
|
192 // |
|
193 // --------------------------------------------------------------------------- |
|
194 // |
|
195 EXPORT_C void CHnItemsOrder::DefineModelItemCountL( TInt aItemCounts ) |
|
196 { |
|
197 // Don't update this information on a initialized suitemodel. |
|
198 if (iItemsEvaluated.Count() == 0 && !iSuiteEvaluated) |
|
199 { |
|
200 iSuiteEvaluated = EFalse; |
|
201 for (TInt i(0); i < aItemCounts; i++) |
|
202 { |
|
203 iItemsOrderCounts.AppendL( 0 ); |
|
204 iItemsEvaluated.AppendL(EFalse); |
|
205 } |
|
206 } |
|
207 } |
|
208 |
|
209 // --------------------------------------------------------------------------- |
|
210 // |
|
211 // --------------------------------------------------------------------------- |
|
212 // |
|
213 EXPORT_C void CHnItemsOrder::SuiteEvaluated() |
|
214 { |
|
215 iSuiteEvaluated = ETrue; |
|
216 } |
|
217 |
|
218 // --------------------------------------------------------------------------- |
|
219 // |
|
220 // --------------------------------------------------------------------------- |
|
221 // |
|
222 EXPORT_C void CHnItemsOrder::ItemEvaluated( TInt aIndex ) |
|
223 { |
|
224 iItemsEvaluated[aIndex] = ETrue; |
|
225 } |
|
226 |
|
227 // --------------------------------------------------------------------------- |
|
228 // |
|
229 // --------------------------------------------------------------------------- |
|
230 // |
|
231 EXPORT_C TBool CHnItemsOrder::IsSuiteReadyToShow() |
|
232 { |
|
233 TBool ready = ETrue; |
|
234 for (TInt i(0); ready && i < iItemsEvaluated.Count(); i++) |
|
235 { |
|
236 ready = iItemsEvaluated[i]; |
|
237 } |
|
238 |
|
239 return ready && iSuiteEvaluated; |
|
240 } |
|
241 // --------------------------------------------------------------------------- |
|
242 // |
|
243 // --------------------------------------------------------------------------- |
|
244 // |
|
245 EXPORT_C TInt CHnItemsOrder::GetModelItemCount( ) |
|
246 { |
|
247 return iItemsOrderCounts.Count(); |
|
248 } |
|
249 |
|
250 // --------------------------------------------------------------------------- |
|
251 // |
|
252 // --------------------------------------------------------------------------- |
|
253 // |
|
254 EXPORT_C TInt CHnItemsOrder::operator[]( TInt aPosition ) |
|
255 { |
|
256 return GetItemIdAt( aPosition ); |
|
257 } |
|
258 |
|
259 // --------------------------------------------------------------------------- |
|
260 // |
|
261 // --------------------------------------------------------------------------- |
|
262 // |
|
263 EXPORT_C TInt CHnItemsOrder::GetItemPosition( TInt aId ) |
|
264 { |
|
265 return iComplexItemsOrder.Find( aId ); |
|
266 } |
|
267 |
|
268 // --------------------------------------------------------------------------- |
|
269 // |
|
270 // --------------------------------------------------------------------------- |
|
271 // |
|
272 TInt CHnItemsOrder::CountStartIndexFor( TInt aDataModelItem ) |
|
273 { |
|
274 TInt startIndex( 0 ); |
|
275 for( TInt i = 0; i < aDataModelItem && i < iItemsOrderCounts.Count(); i++ ) |
|
276 { |
|
277 startIndex += iItemsOrderCounts[ i ]; |
|
278 } |
|
279 return startIndex; |
|
280 } |
|
281 |
|
282 // --------------------------------------------------------------------------- |
|
283 // |
|
284 // --------------------------------------------------------------------------- |
|
285 // |
|
286 TInt CHnItemsOrder::CountModelNumberFor( TInt aIndex ) |
|
287 { |
|
288 TInt modelNumber( 0 ); |
|
289 TInt countLow( 0 ); |
|
290 TInt countHigh( 0 ); |
|
291 for( ; modelNumber < iItemsOrderCounts.Count(); modelNumber++ ) |
|
292 { |
|
293 countHigh += iItemsOrderCounts[ modelNumber ]; |
|
294 if ( aIndex >= countLow && aIndex < countHigh ) |
|
295 { |
|
296 break; |
|
297 } |
|
298 countLow = countHigh; |
|
299 } |
|
300 return modelNumber; |
|
301 } |
|
302 |
|
303 // --------------------------------------------------------------------------- |
|
304 // |
|
305 // --------------------------------------------------------------------------- |
|
306 // |
|
307 EXPORT_C TInt CHnItemsOrder::Count() |
|
308 { |
|
309 return iComplexItemsOrder.Count(); |
|
310 } |
|
311 |
|
312 // --------------------------------------------------------------------------- |
|
313 // |
|
314 // --------------------------------------------------------------------------- |
|
315 // |
|
316 CHnItemsOrder::CHnItemsOrder() : iSuiteId( KErrNotFound ) |
|
317 { |
|
318 |
|
319 } |
|
320 |
|
321 // --------------------------------------------------------------------------- |
|
322 // |
|
323 // --------------------------------------------------------------------------- |
|
324 // |
|
325 void CHnItemsOrder::ConstructL() |
|
326 { |
|
327 |
|
328 } |
|
329 |
|