1 /* |
|
2 * Copyright (c) 2002-2009 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: Category List info provider for listbox model |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 |
|
23 #include <eikenv.h> |
|
24 #include <StringLoader.h> |
|
25 #include <EPos_CPosLandmarkDatabase.h> |
|
26 #include <EPos_CPosLandmarkCategory.h> |
|
27 #include <EPos_CPosLmCategoryManager.h> |
|
28 #include <EPos_CPosLmItemIterator.h> |
|
29 #include <EPos_TPosLmSortPref.h> |
|
30 #include <EPos_CPosLmSearchCriteria.h> |
|
31 #include <EPos_CPosLandmarkSearch.h> |
|
32 #include <EPos_CPosLmCategoryCriteria.h> |
|
33 #include <lmkui.rsg> |
|
34 #include "LmkConsts.h" |
|
35 #include "CLmkAOOperation.h" |
|
36 #include "CLmkCategoryUiItem.h" |
|
37 #include "MLmkSelectorIconMgr.h" |
|
38 #include "CLmkCategoryListProvider.h" |
|
39 #include <lmkerrors.h> |
|
40 |
|
41 #if defined(_DEBUG) |
|
42 // CONSTANTS |
|
43 /// Unnamed namespace for local definitions |
|
44 namespace { |
|
45 |
|
46 _LIT( KPanicMsg, "CLmkCategoryListProvider" ); |
|
47 |
|
48 void Panic( TPanicCode aReason ) |
|
49 { |
|
50 User::Panic( KPanicMsg, aReason ); |
|
51 } |
|
52 } // namespace |
|
53 #endif |
|
54 // ============================ MEMBER FUNCTIONS =============================== |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // CLmkCategoryListProvider::CLmkCategoryListProvider |
|
58 // C++ constructor can NOT contain any code, that |
|
59 // might leave. |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 CLmkCategoryListProvider::CLmkCategoryListProvider( |
|
63 CPosLandmarkDatabase& aDb, |
|
64 TLmkProviderType aShowType ) |
|
65 : CLmkLmItemListProvider( aDb ), |
|
66 iShowType( aShowType ), |
|
67 iAreUncategorisedItems( EFalse ) |
|
68 { |
|
69 } |
|
70 |
|
71 // ----------------------------------------------------------------------------- |
|
72 // CLmkCategoryListProvider::ConstructL |
|
73 // Symbian 2nd phase constructor can leave. |
|
74 // ----------------------------------------------------------------------------- |
|
75 // |
|
76 void CLmkCategoryListProvider::ConstructL() |
|
77 { |
|
78 // base class 2nd phase constructor |
|
79 CLmkLmItemListProvider::BaseConstructL(); |
|
80 iCategoryMgr = CPosLmCategoryManager::NewL( iDb ); |
|
81 iSearch = CPosLandmarkSearch::NewL( iDb ); |
|
82 } |
|
83 |
|
84 // ----------------------------------------------------------------------------- |
|
85 // CLmkCategoryListProvider::NewL |
|
86 // Two-phased constructor. |
|
87 // ----------------------------------------------------------------------------- |
|
88 // |
|
89 CLmkCategoryListProvider* CLmkCategoryListProvider::NewL( |
|
90 CPosLandmarkDatabase& aDb, |
|
91 TLmkProviderType aShowType ) |
|
92 { |
|
93 CLmkCategoryListProvider* self = |
|
94 new ( ELeave ) CLmkCategoryListProvider( aDb, aShowType ); |
|
95 |
|
96 CleanupStack::PushL( self ); |
|
97 self->ConstructL(); |
|
98 CleanupStack::Pop(); |
|
99 |
|
100 return self; |
|
101 } |
|
102 |
|
103 // ----------------------------------------------------------------------------- |
|
104 // CLmkCategoryListProvider::~CLmkCategoryListProvider |
|
105 // ----------------------------------------------------------------------------- |
|
106 // |
|
107 CLmkCategoryListProvider::~CLmkCategoryListProvider() |
|
108 { |
|
109 delete iCategoryMgr; |
|
110 delete iSearch; |
|
111 if( iSearchAO ) |
|
112 { |
|
113 delete iSearchAO; |
|
114 } |
|
115 delete iCriteria; |
|
116 iUsageArray.Close(); |
|
117 } |
|
118 |
|
119 // ----------------------------------------------------------------------------- |
|
120 // CLmkCategoryListProvider::ItemAtL |
|
121 // ----------------------------------------------------------------------------- |
|
122 // |
|
123 CLmkUiItemBase* CLmkCategoryListProvider::ItemAtL( TInt aIndex ) |
|
124 { |
|
125 __ASSERT_DEBUG( iIconMgr, Panic( KLmkPanicNullMember ) ); |
|
126 CLmkCategoryUiItem* uiItem = NULL; |
|
127 |
|
128 if (iIdArray[aIndex] != KPosLmNullItemId) |
|
129 { |
|
130 CPosLandmarkCategory* category = |
|
131 iCategoryMgr->ReadCategoryLC( iIdArray[aIndex] ); |
|
132 |
|
133 TPtrC mbmFile; |
|
134 TInt iconFileIndex = -1; |
|
135 TInt iconListIndex = -1; |
|
136 |
|
137 TInt iconMaskIndex = -1; |
|
138 TInt result = category->GetIcon( mbmFile, iconFileIndex ,iconMaskIndex); |
|
139 if ( result == KErrNone ) |
|
140 { |
|
141 TRAPD(err, iconListIndex = |
|
142 iIconMgr->GetIconL( mbmFile, iconFileIndex ) ); |
|
143 if ( err == KErrNotFound ) // icon file not found -> fallback to default |
|
144 { |
|
145 iconListIndex = iIconMgr->GetDefaultIconL( |
|
146 MLmkSelectorIconMgr::ECategoryDefaultIcon ); |
|
147 } |
|
148 } |
|
149 else |
|
150 { |
|
151 iconListIndex = iIconMgr->GetDefaultIconL( |
|
152 MLmkSelectorIconMgr::ECategoryDefaultIcon ); |
|
153 } |
|
154 |
|
155 switch( iShowType ) |
|
156 { |
|
157 //these are same |
|
158 case ELmkNotShowEmptyCategories: |
|
159 case ELmkShowEmptyCategories: |
|
160 { |
|
161 uiItem = |
|
162 CLmkCategoryUiItem::NewL( category, iconListIndex ); |
|
163 break; |
|
164 } |
|
165 case ELmkShowExtendedCategories: |
|
166 { |
|
167 uiItem = |
|
168 CLmkCategoryUiItem::NewL( category, iconListIndex ); |
|
169 uiItem->SetExtensionInt( IsUsedL( *category) ); |
|
170 break; |
|
171 } |
|
172 default: |
|
173 { |
|
174 break; |
|
175 } |
|
176 } |
|
177 } |
|
178 else // if category id is 'uncategorised' |
|
179 { |
|
180 CPosLandmarkCategory* category = CPosLandmarkCategory::NewL(); |
|
181 CleanupStack::PushL( category); |
|
182 |
|
183 // Set category name |
|
184 CEikonEnv* env = CEikonEnv::Static(); |
|
185 HBufC* catNameText = NULL; |
|
186 catNameText = StringLoader::LoadLC( R_LMK_LM_LIST_UNCATEGORISED, env ); |
|
187 TPtrC categoryName; |
|
188 categoryName.Set(*catNameText); |
|
189 category->SetCategoryNameL(categoryName); |
|
190 CleanupStack::PopAndDestroy( catNameText ); |
|
191 TInt iconListIndex = -1; |
|
192 iconListIndex |
|
193 = iIconMgr->GetDefaultIconL( |
|
194 MLmkSelectorIconMgr::ECategoryDefaultIcon ); |
|
195 uiItem = CLmkCategoryUiItem::NewL( category, iconListIndex ); |
|
196 } |
|
197 CleanupStack::Pop(); // category, ownership transferred |
|
198 return uiItem; |
|
199 } |
|
200 |
|
201 // --------------------------------------------------------- |
|
202 // CLmkCategoryListProvider::ReadItemsToArrayL |
|
203 // --------------------------------------------------------- |
|
204 // |
|
205 void CLmkCategoryListProvider::ReadItemsToArrayL() |
|
206 { |
|
207 // Update the IdArray to have 'uncategorised' category Id |
|
208 CPosLmItemIterator* lmIterator = iSearch->MatchIteratorL(); |
|
209 CleanupStack::PushL( lmIterator ); |
|
210 TInt lmCount = lmIterator->NumOfItemsL(); |
|
211 CleanupStack::PopAndDestroy( lmIterator ); |
|
212 if ( lmCount > 0 ) |
|
213 { |
|
214 // There is atleast 'one' landmark which is 'uncategorised' |
|
215 // can only be called if there are some items |
|
216 // Append 'uncategorised' category ID to the idArray |
|
217 iIdArray.Append(KPosLmNullItemId); |
|
218 iAreUncategorisedItems = ETrue; |
|
219 if(iCount == -1 ) |
|
220 { |
|
221 NotifyObservers( ELmkEventItemAdditionComplete ); |
|
222 } |
|
223 else |
|
224 { |
|
225 NotifyObservers( ELmkEventListReady ); |
|
226 } |
|
227 iSearchAO->StopOperation(); |
|
228 iCount = 1; |
|
229 } |
|
230 } |
|
231 |
|
232 // --------------------------------------------------------- |
|
233 // CLmkCategoryListProvider::HandleOperationL |
|
234 // --------------------------------------------------------- |
|
235 // |
|
236 void CLmkCategoryListProvider::HandleOperationL( |
|
237 TOperationTypes aType, |
|
238 TReal32 aProgress, |
|
239 TInt aStatus ) |
|
240 { |
|
241 if ( aType == MLmkAOOperationObserver::ESearch ) |
|
242 { |
|
243 if( iCount < 1 ) |
|
244 { |
|
245 ReadItemsToArrayL(); |
|
246 } |
|
247 if ( aStatus == KErrNone ) |
|
248 { |
|
249 if(iCount == 0) |
|
250 { |
|
251 NotifyObservers( ELmkEventListReady ); |
|
252 } |
|
253 delete iSearchAO; |
|
254 iSearchAO = NULL; |
|
255 iCount = 0; |
|
256 } |
|
257 } |
|
258 else |
|
259 { // This is not this classes' operation |
|
260 CLmkLmItemListProvider::HandleOperationL( aType, aProgress, aStatus); |
|
261 } |
|
262 } |
|
263 |
|
264 // ----------------------------------------------------------------------------- |
|
265 // CLmkCategoryListProvider::PrepareListL |
|
266 // ----------------------------------------------------------------------------- |
|
267 // |
|
268 void CLmkCategoryListProvider::PrepareListL() |
|
269 { |
|
270 if ( iListAllItemsInDb ) |
|
271 { |
|
272 CPosLmItemIterator* iterator = NULL; |
|
273 |
|
274 switch( iShowType ) |
|
275 { |
|
276 case ELmkNotShowEmptyCategories: |
|
277 { |
|
278 iCount = 0; |
|
279 iIdArray.Reset(); |
|
280 |
|
281 // Query for 'referenced categories' from Category manager here |
|
282 CPosLmItemIterator* categoryIterator = iCategoryMgr->ReferencedCategoryIteratorL( |
|
283 CPosLmCategoryManager::ECategorySortOrderNameAscending ); |
|
284 CleanupStack::PushL( categoryIterator ); |
|
285 TUint categoryCount = categoryIterator->NumOfItemsL(); |
|
286 |
|
287 if ( categoryCount > 0 ) |
|
288 { // can only be called if there are some items |
|
289 categoryIterator->GetItemIdsL( iIdArray, 0, categoryCount ); |
|
290 if( iAreUncategorisedItems ) |
|
291 { |
|
292 iIdArray.Append(KPosLmNullItemId); |
|
293 } |
|
294 NotifyObservers( ELmkEventListReady ); |
|
295 iCount = -1; |
|
296 } |
|
297 CleanupStack::PopAndDestroy( categoryIterator ); |
|
298 |
|
299 if( iAreUncategorisedItems ) |
|
300 { |
|
301 if( iIdArray.Count() == 0) |
|
302 { |
|
303 iIdArray.Append(KPosLmNullItemId); |
|
304 } |
|
305 NotifyObservers( ELmkEventListReady ); |
|
306 return; |
|
307 } |
|
308 |
|
309 // Set criteria parameters here -- for uncategorised landmarks |
|
310 if (iCriteria) |
|
311 { |
|
312 delete iCriteria; |
|
313 iCriteria = NULL; |
|
314 } |
|
315 iCriteria = CPosLmCategoryCriteria::NewLC(); |
|
316 CleanupStack::Pop( iCriteria ); |
|
317 iCriteria->SetCategoryItemId(KPosLmNullItemId); |
|
318 |
|
319 TPosLmSortPref sortOrder( CPosLandmark::ELandmarkName, |
|
320 TPosLmSortPref::EAscending ); |
|
321 |
|
322 |
|
323 CPosLmOperation* operation = |
|
324 iSearch->StartLandmarkSearchL( *iCriteria , sortOrder ); |
|
325 CleanupStack::PushL( operation ); |
|
326 delete iSearchAO; // cancel possibly pending operation |
|
327 iSearchAO = NULL; |
|
328 iSearchAO = CLmkAOOperation::NewL( operation, |
|
329 *this, |
|
330 MLmkAOOperationObserver::ESearch, |
|
331 iOperationNotInUse ); |
|
332 |
|
333 CleanupStack::Pop( operation ); // ownership transferred |
|
334 iSearchAO->StartOperation(); |
|
335 return; |
|
336 } |
|
337 case ELmkShowEmptyCategories: |
|
338 { |
|
339 iterator = iCategoryMgr->CategoryIteratorL( |
|
340 CPosLmCategoryManager::ECategorySortOrderNameAscending ); |
|
341 CleanupStack::PushL( iterator ); |
|
342 break; |
|
343 } |
|
344 case ELmkShowExtendedCategories: |
|
345 { |
|
346 iterator = iCategoryMgr->CategoryIteratorL( |
|
347 CPosLmCategoryManager::ECategorySortOrderNameAscending ); |
|
348 CleanupStack::PushL( iterator ); |
|
349 PrepareCategoryUsageListL(); |
|
350 break; |
|
351 } |
|
352 default: |
|
353 { |
|
354 break; |
|
355 } |
|
356 } |
|
357 |
|
358 if( iterator ) |
|
359 { |
|
360 TUint count = iterator->NumOfItemsL(); |
|
361 iIdArray.Reset(); |
|
362 if ( count > 0 ) |
|
363 { // can only be called if there are some items |
|
364 iterator->GetItemIdsL( iIdArray, 0, count ); |
|
365 } |
|
366 CleanupStack::PopAndDestroy( iterator ); |
|
367 } |
|
368 } |
|
369 |
|
370 NotifyObservers( ELmkEventListReady ); |
|
371 } |
|
372 |
|
373 // ----------------------------------------------------------------------------- |
|
374 // CLmkCategoryListProvider::PrepareListL |
|
375 // ----------------------------------------------------------------------------- |
|
376 // |
|
377 TBool CLmkCategoryListProvider::PrepareListL(const TDesC& /*aSearchPattern*/, |
|
378 TBool /*aSearchOnlyInPreviousMatches*/) |
|
379 { |
|
380 // not preparing the new list based on search criteria, |
|
381 // as using the avkon's search api |
|
382 return EFalse; |
|
383 } |
|
384 |
|
385 // --------------------------------------------------------- |
|
386 // CLmkCategoryListProvider::RemoveLandmarksL |
|
387 // --------------------------------------------------------- |
|
388 // |
|
389 void CLmkCategoryListProvider::RemoveLandmarksL(const RArray<TPosLmItemId>& /*aSelectedItems*/ ) |
|
390 { |
|
391 // no implementation required |
|
392 } |
|
393 |
|
394 // ----------------------------------------------------------------------------- |
|
395 // CLmkCategoryListProvider::HandleDatabaseEvent |
|
396 // ----------------------------------------------------------------------------- |
|
397 // |
|
398 void CLmkCategoryListProvider::HandleDatabaseEvent( TPosLmEvent& aEvent ) |
|
399 { |
|
400 TBool needRefresh = EFalse; |
|
401 |
|
402 switch ( aEvent.iEventType ) |
|
403 { |
|
404 case EPosLmEventLandmarkUnknownChanges: |
|
405 case EPosLmEventLandmarkDeleted: |
|
406 case EPosLmEventLandmarkUpdated: |
|
407 case EPosLmEventUnknownChanges: |
|
408 { |
|
409 iAreUncategorisedItems = EFalse; |
|
410 needRefresh = ETrue; |
|
411 break; |
|
412 } |
|
413 case EPosLmEventLandmarkCreated: |
|
414 case EPosLmEventCategoryUnknownChanges: |
|
415 case EPosLmEventCategoryCreated: |
|
416 case EPosLmEventCategoryDeleted: |
|
417 case EPosLmEventCategoryUpdated: |
|
418 { |
|
419 needRefresh = ETrue; |
|
420 break; |
|
421 } |
|
422 default: |
|
423 { |
|
424 // Not interesting event for this provider |
|
425 break; |
|
426 } |
|
427 } |
|
428 |
|
429 if( needRefresh ) |
|
430 { |
|
431 TRAPD( err, PrepareListL() ); |
|
432 if ( err ) |
|
433 { |
|
434 HandleError( err ); |
|
435 } |
|
436 } |
|
437 |
|
438 // Remember to call base class observer method too |
|
439 CLmkLmItemListProvider::HandleDatabaseEvent( aEvent ); |
|
440 } |
|
441 |
|
442 // ----------------------------------------------------------------------------- |
|
443 // CLmkCategoryListProvider::PrepareCategoryUsageListL |
|
444 // ----------------------------------------------------------------------------- |
|
445 // |
|
446 void CLmkCategoryListProvider::PrepareCategoryUsageListL() |
|
447 { |
|
448 iUsageArray.Reset(); |
|
449 iUsageIndex = 0; |
|
450 CPosLmItemIterator* iterator = iCategoryMgr->ReferencedCategoryIteratorL( |
|
451 CPosLmCategoryManager::ECategorySortOrderNameAscending ); |
|
452 |
|
453 CleanupStack::PushL( iterator ); |
|
454 TUint count = iterator->NumOfItemsL(); |
|
455 if ( count > 0 ) |
|
456 { // can only be called if there are some items |
|
457 iterator->GetItemIdsL( iUsageArray, 0, count ); |
|
458 } |
|
459 CleanupStack::PopAndDestroy( iterator ); |
|
460 } |
|
461 |
|
462 // ----------------------------------------------------------------------------- |
|
463 // CLmkCategoryListProvider::IsUsedL |
|
464 // ----------------------------------------------------------------------------- |
|
465 // |
|
466 TBool CLmkCategoryListProvider::IsUsedL( CPosLandmarkCategory& aCategory ) |
|
467 { |
|
468 TBool result( EFalse ); |
|
469 |
|
470 TInt count( iUsageArray.Count() ); |
|
471 CPosLandmarkCategory* usageCat = NULL; |
|
472 |
|
473 for ( TInt i=0; i<count; i++ ) |
|
474 { |
|
475 usageCat = iCategoryMgr->ReadCategoryLC( iUsageArray[i] ); |
|
476 |
|
477 if ( aCategory.CategoryId() == usageCat->CategoryId() ) |
|
478 { |
|
479 result = ETrue; |
|
480 CleanupStack::PopAndDestroy(); |
|
481 break; |
|
482 } |
|
483 CleanupStack::PopAndDestroy(); |
|
484 } |
|
485 return result; |
|
486 } |
|
487 |
|
488 |
|
489 |
|
490 // End of File |
|