|
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: Base class landmarks list provider for listbox model |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // SYSTEM INCLUDES |
|
20 #include <EPos_CPosLandmarkDatabase.h> |
|
21 #include <EPos_CPosLmOperation.h> |
|
22 #include <EPos_CPosLmCategoryManager.h> |
|
23 #include <AknWaitDialog.h> |
|
24 |
|
25 // USER INCLUDES |
|
26 #include "CLmkLmItemListProvider.h" |
|
27 #include "MLmkListProviderObserver.h" |
|
28 #include "CLmkDbUtils.h" |
|
29 #include "CLmkDbInitializer.h" |
|
30 #include "CLmkEventListenerSingleton.h" |
|
31 #include "CLmkAOOperation.h" |
|
32 #include "LmkConsts.h" |
|
33 #include <lmkerrors.h> |
|
34 |
|
35 // CONSTANTS |
|
36 /// Unnamed namespace for local definitions |
|
37 namespace { |
|
38 |
|
39 _LIT( KPanicMsg, "CLmkLmItemListProvider" ); |
|
40 |
|
41 void Panic( TPanicCode aReason ) |
|
42 { |
|
43 User::Panic( KPanicMsg, aReason ); |
|
44 } |
|
45 } // namespace |
|
46 |
|
47 // ============================ MEMBER FUNCTIONS =============================== |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 // CLmkLmItemListProvider::CLmkLmItemListProvider |
|
51 // C++ constructor can NOT contain any code, that |
|
52 // might leave. |
|
53 // ----------------------------------------------------------------------------- |
|
54 // |
|
55 CLmkLmItemListProvider::CLmkLmItemListProvider( |
|
56 CPosLandmarkDatabase& aDb ) |
|
57 : iDb( aDb ), |
|
58 iListAllItemsInDb( ETrue ), |
|
59 iIdArray( KLmItemArrayGranularity ), |
|
60 iSelectedItemsCount( 0 ), iCount( 0 ), |
|
61 iRequestFromFindBox(EFalse), |
|
62 iOperationNotInUse( ETrue ), |
|
63 iOperationCmd( ELmkCmdStopOperation ), //temp default value |
|
64 iSelectedForDelete(KLmItemArrayGranularity), |
|
65 iItemsToDelete( 0 ), |
|
66 iItemsDeleted( 0 ), |
|
67 iIsRemoveLandmarks( EFalse ), |
|
68 iCategoryId(KPosLmNullItemId) |
|
69 { |
|
70 } |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // CLmkLmItemListProvider::ConstructL |
|
74 // Symbian 2nd phase constructor can leave. |
|
75 // ----------------------------------------------------------------------------- |
|
76 // |
|
77 void CLmkLmItemListProvider::BaseConstructL() |
|
78 { |
|
79 // Create db utils, request callback only when operations completed: |
|
80 iDbUtils = CLmkDbUtils::NewL( iDb, *this, EFalse ); |
|
81 //Create landmark array, which will hold all those landmarks, which belong |
|
82 //to one category and needs icon change. |
|
83 iIconChangeLmkArray = new(ELeave) RPointerArray<CPosLandmark>; |
|
84 // base class 2nd phase constructor |
|
85 CLmkListProviderBase::BaseConstructL(); |
|
86 } |
|
87 |
|
88 // ----------------------------------------------------------------------------- |
|
89 // CLmkLmItemListProvider::~CLmkLmItemListProvider |
|
90 // ----------------------------------------------------------------------------- |
|
91 // |
|
92 CLmkLmItemListProvider::~CLmkLmItemListProvider() |
|
93 { |
|
94 if ( iWaitNote ) |
|
95 { |
|
96 TRAPD( err, iWaitNote->ProcessFinishedL() ); |
|
97 if (err != KErrNone) |
|
98 { |
|
99 delete iWaitNote; |
|
100 iWaitNote = NULL; |
|
101 } |
|
102 } |
|
103 // Stop db event observing: |
|
104 CLmkEventListenerSingleton::RemoveObserver( *this ); |
|
105 if (iIconChangeLmkArray) |
|
106 { |
|
107 iIconChangeLmkArray->ResetAndDestroy(); |
|
108 delete iIconChangeLmkArray; |
|
109 } |
|
110 delete iInitializer; |
|
111 delete iDbUtils; |
|
112 |
|
113 iSelectedForDelete.Close(); |
|
114 iIdArray.Close(); |
|
115 } |
|
116 |
|
117 // ----------------------------------------------------------------------------- |
|
118 // CLmkLmItemListProvider::SelectedIndexesL |
|
119 // ----------------------------------------------------------------------------- |
|
120 // |
|
121 EXPORT_C CArrayFix<TInt>* CLmkLmItemListProvider::SelectedIndexesL( |
|
122 const RArray<TPosLmItemId>& aSelectedItems ) const |
|
123 { |
|
124 CArrayFix<TInt>* array = NULL; |
|
125 TInt count = aSelectedItems.Count(); |
|
126 if ( count < KLmkMultiSelectionGranularity ) |
|
127 { // decent minimum granularity because of possible user selections |
|
128 array = |
|
129 new ( ELeave ) CArrayFixFlat<TInt>( KLmkMultiSelectionGranularity ); |
|
130 } |
|
131 else |
|
132 { |
|
133 array = new ( ELeave ) CArrayFixFlat<TInt>( aSelectedItems.Count() ); |
|
134 } |
|
135 CleanupStack::PushL( array ); |
|
136 |
|
137 GetSelectedIndexesL( *array, aSelectedItems ); |
|
138 |
|
139 CleanupStack::Pop( array ); |
|
140 return array; |
|
141 } |
|
142 |
|
143 // ----------------------------------------------------------------------------- |
|
144 // CLmkLmItemListProvider::GetSelectedIndexesL |
|
145 // ----------------------------------------------------------------------------- |
|
146 // |
|
147 EXPORT_C void CLmkLmItemListProvider::GetSelectedIndexesL( |
|
148 CArrayFix<TInt>& aSelectedIndexes, |
|
149 const RArray<TPosLmItemId>& aSelectedItems ) const |
|
150 { |
|
151 aSelectedIndexes.Reset(); |
|
152 TInt count = aSelectedItems.Count(); |
|
153 for ( TInt i( 0 ); i < count; ++i ) |
|
154 { |
|
155 TInt index = iIdArray.Find( aSelectedItems[i] ); |
|
156 if ( index >= 0 ) |
|
157 { // item found --> append it's index |
|
158 aSelectedIndexes.AppendL( index ); |
|
159 } |
|
160 } |
|
161 } |
|
162 |
|
163 // ----------------------------------------------------------------------------- |
|
164 // CLmkLmItemListProvider::GetSelectedItemIdsL |
|
165 // ----------------------------------------------------------------------------- |
|
166 // |
|
167 EXPORT_C void CLmkLmItemListProvider::GetSelectedItemIdsL( |
|
168 RArray<TPosLmItemId>& aSelectedItems, |
|
169 const CArrayFix<TInt>& aSelectedIndexes ) const |
|
170 { |
|
171 aSelectedItems.Reset(); |
|
172 TInt itemCount = iIdArray.Count(); |
|
173 TInt selectionCount = aSelectedIndexes.Count(); |
|
174 |
|
175 for ( TInt i( 0 ); i < selectionCount; ++i ) |
|
176 { |
|
177 TInt index = aSelectedIndexes[i]; |
|
178 __ASSERT_ALWAYS( index >= 0 && index < itemCount, |
|
179 Panic( KLmkPanicInvalidIndex ) ); |
|
180 |
|
181 User::LeaveIfError( aSelectedItems.Append( iIdArray[index] ) ); |
|
182 } |
|
183 } |
|
184 |
|
185 // ----------------------------------------------------------------------------- |
|
186 // CLmkLmItemListProvider::GetAllItemIdsL |
|
187 // ----------------------------------------------------------------------------- |
|
188 // |
|
189 EXPORT_C void CLmkLmItemListProvider::GetAllItemIdsL( |
|
190 RArray<TPosLmItemId>& aSelectedItems ) const |
|
191 { |
|
192 aSelectedItems.Reset(); |
|
193 TInt itemCount = iIdArray.Count(); |
|
194 |
|
195 for ( TInt i( 0 ); i < itemCount; ++i ) |
|
196 { |
|
197 User::LeaveIfError( aSelectedItems.Append( iIdArray[i] ) ); |
|
198 } |
|
199 } |
|
200 |
|
201 // ----------------------------------------------------------------------------- |
|
202 // CLmkLmItemListProvider::SelectedIndex |
|
203 // ----------------------------------------------------------------------------- |
|
204 // |
|
205 EXPORT_C TInt CLmkLmItemListProvider::SelectedIndex( |
|
206 TPosLmItemId aSelectedItem ) const |
|
207 { |
|
208 return iIdArray.Find( aSelectedItem ); |
|
209 } |
|
210 |
|
211 // ----------------------------------------------------------------------------- |
|
212 // CLmkLmItemListProvider::GetSelectedItemId |
|
213 // ----------------------------------------------------------------------------- |
|
214 // |
|
215 EXPORT_C void CLmkLmItemListProvider::GetSelectedItemId( |
|
216 TPosLmItemId& aSelected, |
|
217 TInt aIndex ) const |
|
218 { |
|
219 __ASSERT_ALWAYS( aIndex >= 0 && aIndex < iIdArray.Count(), |
|
220 Panic( KLmkPanicInvalidIndex ) ); |
|
221 |
|
222 aSelected = iIdArray[aIndex]; |
|
223 } |
|
224 |
|
225 // ----------------------------------------------------------------------------- |
|
226 // CLmkLmItemListProvider::SetSelectedItemsCount |
|
227 // ----------------------------------------------------------------------------- |
|
228 // |
|
229 EXPORT_C void CLmkLmItemListProvider::SetSelectedItemsCount( TInt aSelectedItemsCount ) |
|
230 { |
|
231 iSelectedItemsCount = aSelectedItemsCount; |
|
232 } |
|
233 |
|
234 // ----------------------------------------------------------------------------- |
|
235 // CLmkLmItemListProvider::RemoveItem |
|
236 // ----------------------------------------------------------------------------- |
|
237 // |
|
238 EXPORT_C void CLmkLmItemListProvider::RemoveItem( TPosLmItemId aItemId ) |
|
239 { |
|
240 TInt index = iIdArray.Find(aItemId); |
|
241 if( index != KErrNotFound && index < iIdArray.Count()) |
|
242 { |
|
243 iIdArray.Remove(index); |
|
244 NotifyObservers( ELmkEventListReady ); |
|
245 } |
|
246 } |
|
247 |
|
248 // ----------------------------------------------------------------------------- |
|
249 // CLmkLmItemListProvider::RemoveItemsL |
|
250 // ----------------------------------------------------------------------------- |
|
251 // |
|
252 EXPORT_C void CLmkLmItemListProvider::RemoveItemsL( |
|
253 const RArray<TPosLmItemId>& aSelectedItems, |
|
254 MLmkAOOperationObserver::TOperationTypes aType, |
|
255 TPosLmItemId aCategoryId ) |
|
256 { |
|
257 iCategoryId = aCategoryId; |
|
258 iType = aType; |
|
259 RemoveLandmarksL(aSelectedItems); |
|
260 } |
|
261 |
|
262 // ----------------------------------------------------------------------------- |
|
263 // CLmkLmItemListProvider::SetOperationCmd |
|
264 // ----------------------------------------------------------------------------- |
|
265 // |
|
266 EXPORT_C void CLmkLmItemListProvider::SetOperationCmd( TLmkAppCmdId aOperationCmd ) |
|
267 { |
|
268 iOperationCmd = aOperationCmd; |
|
269 } |
|
270 |
|
271 // ----------------------------------------------------------------------------- |
|
272 // CLmkLmItemListProvider::InitializeL |
|
273 // ----------------------------------------------------------------------------- |
|
274 // |
|
275 void CLmkLmItemListProvider::InitializeL() |
|
276 { |
|
277 __ASSERT_DEBUG( !iInitializer, Panic( KLmkPanicIllegalMethodCall ) ); |
|
278 // We don't want intermediate callbacks -> 3rd parameter EFalse |
|
279 iInitializer = CLmkDbInitializer::NewL( iDb, *this, EFalse ); |
|
280 iInitializer->StartInitAndCompactL(); |
|
281 } |
|
282 |
|
283 // ----------------------------------------------------------------------------- |
|
284 // CLmkLmItemListProvider::StartSearchingLandmarksL() |
|
285 // ----------------------------------------------------------------------------- |
|
286 // |
|
287 TBool CLmkLmItemListProvider::StartSearchingLandmarksL( |
|
288 const TDesC& aSearchPattern, |
|
289 TBool aSearchOnlyInPreviousMatches) |
|
290 { |
|
291 iRequestFromFindBox = ETrue; |
|
292 return PrepareListL(aSearchPattern, aSearchOnlyInPreviousMatches); |
|
293 } |
|
294 |
|
295 // ----------------------------------------------------------------------------- |
|
296 // CLmkLmItemListProvider::ItemCount |
|
297 // ----------------------------------------------------------------------------- |
|
298 // |
|
299 TInt CLmkLmItemListProvider::ItemCount() const |
|
300 { |
|
301 return iIdArray.Count(); |
|
302 } |
|
303 |
|
304 // ----------------------------------------------------------------------------- |
|
305 // CLmkLmItemListProvider::HandleOperationL |
|
306 // ----------------------------------------------------------------------------- |
|
307 // |
|
308 void CLmkLmItemListProvider::HandleOperationL( |
|
309 TOperationTypes /*aType*/, |
|
310 TReal32 /*aProgress*/, |
|
311 TInt aStatus ) |
|
312 { |
|
313 __ASSERT_DEBUG( aStatus != KPosLmOperationNotComplete, |
|
314 Panic( KLmkPanicIntermediateCallback ) ); |
|
315 |
|
316 // init and compact completed, delete unnecessary helper object: |
|
317 delete iInitializer; |
|
318 iInitializer = NULL; |
|
319 |
|
320 TInt err( aStatus ); |
|
321 |
|
322 if ( aStatus == KErrNone ) |
|
323 { |
|
324 TRAP( err, HandleDatabaseInitializedL() ); |
|
325 } |
|
326 |
|
327 if ( err != KErrNone ) |
|
328 { // Error already in aStatus or within this method |
|
329 HandleError( err ); |
|
330 } |
|
331 } |
|
332 |
|
333 // ----------------------------------------------------------------------------- |
|
334 // CLmkLmItemListProvider::HandleDatabaseInitializedL |
|
335 // ----------------------------------------------------------------------------- |
|
336 // |
|
337 void CLmkLmItemListProvider::HandleDatabaseInitializedL() |
|
338 { |
|
339 // Start db event observing: |
|
340 CLmkEventListenerSingleton::AddObserverL( *this, iDb ); |
|
341 |
|
342 iRequestFromFindBox = EFalse; |
|
343 |
|
344 // Call provider-specific templated method for preparing list: |
|
345 PrepareListL(); |
|
346 } |
|
347 |
|
348 // ----------------------------------------------------------------------------- |
|
349 // CLmkLmItemListProvider::HandleError |
|
350 // ----------------------------------------------------------------------------- |
|
351 // |
|
352 void CLmkLmItemListProvider::HandleError( TInt aError ) |
|
353 { |
|
354 if ( aError != KErrNone ) |
|
355 { |
|
356 NotifyError( aError ); |
|
357 } |
|
358 } |
|
359 |
|
360 // ----------------------------------------------------------------------------- |
|
361 // CLmkLmItemListProvider::HandleDatabaseEvent |
|
362 // ----------------------------------------------------------------------------- |
|
363 // |
|
364 void CLmkLmItemListProvider::HandleDatabaseEvent( TPosLmEvent& aEvent ) |
|
365 { |
|
366 switch ( aEvent.iEventType ) |
|
367 { |
|
368 case EPosLmEventNewDefaultDatabaseLocation: |
|
369 case EPosLmEventMediaRemoved: |
|
370 { |
|
371 //TODO: |
|
372 break; |
|
373 } |
|
374 default: |
|
375 { |
|
376 //TODO: |
|
377 // not interesting event for this class |
|
378 break; |
|
379 } |
|
380 } |
|
381 } |
|
382 |
|
383 // ----------------------------------------------------------------------------- |
|
384 // CLmkLmItemListProvider::GetLandmarkLC |
|
385 // ----------------------------------------------------------------------------- |
|
386 // |
|
387 CPosLandmark* CLmkLmItemListProvider::GetLandmarkLC(TInt aIndex) |
|
388 { |
|
389 RArray<TPosLmItemId> itemArray; |
|
390 CPosLandmark* landmark = iDb.ReadPartialLandmarkLC( iIdArray[aIndex] ); |
|
391 //check whether landmark is associated with more than one cat. |
|
392 landmark->GetCategoriesL(itemArray); |
|
393 if (itemArray.Count() == 1) |
|
394 { |
|
395 //if associated with one cat, check if the icon is not set by the |
|
396 //user explicitly |
|
397 TPtrC iconPath; |
|
398 TInt iconId; |
|
399 TInt iconMaskIndex; |
|
400 if (landmark->GetIcon(iconPath,iconId, iconMaskIndex)) |
|
401 { |
|
402 //lmk has one cat & icon is not set by the user: |
|
403 CPosLmCategoryManager* categoryMgr = CPosLmCategoryManager::NewL(iDb); |
|
404 CleanupStack::PushL( categoryMgr ); |
|
405 CPosLandmarkCategory* category = categoryMgr->ReadCategoryLC( itemArray[0] ); |
|
406 //get the cat icon and set it as landmark icon only for display |
|
407 if (category->GetIcon(iconPath,iconId, iconMaskIndex) == KErrNone ) |
|
408 { |
|
409 landmark->SetIconL(iconPath,iconId,iconMaskIndex); |
|
410 } |
|
411 CleanupStack::PopAndDestroy();//category |
|
412 CleanupStack::PopAndDestroy();//categoryMgr |
|
413 } |
|
414 } |
|
415 itemArray.Close(); |
|
416 return landmark; |
|
417 } |
|
418 // End of File |