|
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: This file mainly is responsible for handling the database event |
|
15 * w.r.t landmarks & preparing landmark lists accordingly. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 // SYSTEM INCLUDE |
|
26 #include <EPos_CPosLmPartialReadParameters.h> |
|
27 #include <EPos_CPosLandmark.h> |
|
28 #include <EPos_TPosLmSortPref.h> |
|
29 #include <EPos_CPosLandmarkDatabase.h> |
|
30 #include <EPos_CPosLmItemIterator.h> |
|
31 #include <EPos_CPosLandmarkSearch.h> |
|
32 #include <EPos_CPosLmTextCriteria.h> |
|
33 #include <EPos_CPosLmCompositeCriteria.h> |
|
34 #include <e32math.h> |
|
35 #include <AknWaitDialog.h> |
|
36 #include <lmkui.rsg> |
|
37 |
|
38 // USER INCLUDES |
|
39 #include "CLmkLandmarkListProvider.h" |
|
40 #include "CLmkLandmarkUiItem.h" |
|
41 #include "CLmkAOOperation.h" |
|
42 #include "MLmkSelectorIconMgr.h" |
|
43 #include <lmkerrors.h> |
|
44 |
|
45 // CONSTANTS |
|
46 _LIT(KDefaultTextCriteria,"*"); |
|
47 _LIT(KSpaceTextCriteria,"* "); |
|
48 |
|
49 |
|
50 #if defined(_DEBUG) |
|
51 // CONSTANTS |
|
52 /// Unnamed namespace for local definitions |
|
53 namespace { |
|
54 |
|
55 _LIT( KPanicMsg, "CLmkLandmarkListProvider" ); |
|
56 |
|
57 void Panic( TPanicCode aReason ) |
|
58 { |
|
59 User::Panic( KPanicMsg, aReason ); |
|
60 } |
|
61 } // namespace |
|
62 #endif |
|
63 // ============================ MEMBER FUNCTIONS =============================== |
|
64 |
|
65 // ----------------------------------------------------------------------------- |
|
66 // CLmkLandmarkListProvider::CLmkLandmarkListProvider |
|
67 // C++ constructor can NOT contain any code, that |
|
68 // might leave. |
|
69 // ----------------------------------------------------------------------------- |
|
70 // |
|
71 CLmkLandmarkListProvider::CLmkLandmarkListProvider( |
|
72 CPosLandmarkDatabase& aDb ) |
|
73 : CLmkLmItemListProvider( aDb ) |
|
74 { |
|
75 } |
|
76 |
|
77 // ----------------------------------------------------------------------------- |
|
78 // CLmkLandmarkListProvider::ConstructL |
|
79 // Symbian 2nd phase constructor can leave. |
|
80 // ----------------------------------------------------------------------------- |
|
81 // |
|
82 void CLmkLandmarkListProvider::ConstructL() |
|
83 { |
|
84 // base class 2nd phase constructor |
|
85 CLmkLmItemListProvider::BaseConstructL(); |
|
86 |
|
87 iReadParams = CPosLmPartialReadParameters::NewLC(); |
|
88 CleanupStack::Pop(); // iReadParams |
|
89 iReadParams->SetRequestedAttributes( CPosLandmark::ELandmarkName | |
|
90 CPosLandmark::EIcon | CPosLandmark::ECategoryInfo ); |
|
91 iSearch = CPosLandmarkSearch::NewL( iDb ); |
|
92 } |
|
93 |
|
94 // ----------------------------------------------------------------------------- |
|
95 // CLmkLandmarkListProvider::NewL |
|
96 // Two-phased constructor. |
|
97 // ----------------------------------------------------------------------------- |
|
98 // |
|
99 CLmkLandmarkListProvider* CLmkLandmarkListProvider::NewL( |
|
100 CPosLandmarkDatabase& aDb ) |
|
101 { |
|
102 CLmkLandmarkListProvider* self = |
|
103 new ( ELeave ) CLmkLandmarkListProvider( aDb ); |
|
104 |
|
105 CleanupStack::PushL( self ); |
|
106 self->ConstructL(); |
|
107 CleanupStack::Pop(); |
|
108 |
|
109 return self; |
|
110 } |
|
111 |
|
112 // ----------------------------------------------------------------------------- |
|
113 // CLmkLandmarkListProvider::~CLmkLandmarkListProvider |
|
114 // ----------------------------------------------------------------------------- |
|
115 // |
|
116 CLmkLandmarkListProvider::~CLmkLandmarkListProvider() |
|
117 { |
|
118 delete iReadParams; |
|
119 if (iSearchAO) |
|
120 { |
|
121 iSearchAO->StopOperation(); |
|
122 } |
|
123 delete iSearchAO; |
|
124 delete iSearch; |
|
125 } |
|
126 |
|
127 // ----------------------------------------------------------------------------- |
|
128 // CLmkLandmarkListProvider::ItemAtL |
|
129 // ----------------------------------------------------------------------------- |
|
130 // |
|
131 CLmkUiItemBase* CLmkLandmarkListProvider::ItemAtL( TInt aIndex ) |
|
132 { |
|
133 __ASSERT_DEBUG( iIconMgr, Panic( KLmkPanicNullMember ) ); |
|
134 //landmark with updated icon, if associated with one cat. |
|
135 CPosLandmark* landmark = GetLandmarkLC(aIndex); |
|
136 TPtrC mbmFile; |
|
137 TInt iconFileIndex = -1; |
|
138 TInt iconListIndex = -1; |
|
139 TInt iconMaskIndex = -1; |
|
140 |
|
141 TInt result = landmark->GetIcon( mbmFile, iconFileIndex, iconMaskIndex ); |
|
142 if ( result == KErrNone ) |
|
143 { |
|
144 TRAPD(err, iconListIndex = |
|
145 iIconMgr->GetIconL( mbmFile, iconFileIndex ) ); |
|
146 if ( err == KErrNotFound ) // icon file not found -> fallback to default |
|
147 { |
|
148 iconListIndex = iIconMgr->GetDefaultIconL( |
|
149 MLmkSelectorIconMgr::ELandmarkDefaultIcon ); |
|
150 } |
|
151 } |
|
152 else |
|
153 { |
|
154 iconListIndex = iIconMgr->GetDefaultIconL( |
|
155 MLmkSelectorIconMgr::ELandmarkDefaultIcon ); |
|
156 } |
|
157 |
|
158 CLmkLandmarkUiItem* uiItem = |
|
159 CLmkLandmarkUiItem::NewL( landmark, iconListIndex ); |
|
160 CleanupStack::Pop(); // landmark, ownership transferred |
|
161 return uiItem; |
|
162 } |
|
163 |
|
164 // ----------------------------------------------------------------------------- |
|
165 // CLmkLandmarkListProvider::PrepareListL |
|
166 // ----------------------------------------------------------------------------- |
|
167 // |
|
168 void CLmkLandmarkListProvider::PrepareListL() |
|
169 { |
|
170 if ( iListAllItemsInDb ) |
|
171 { |
|
172 iCount = 0; |
|
173 iDb.SetPartialReadParametersL( *iReadParams ); |
|
174 CPosLmTextCriteria* criteria = CPosLmTextCriteria::NewLC(); |
|
175 criteria->SetTextL(KDefaultTextCriteria); |
|
176 TPosLmSortPref sortOrder( CPosLandmark::ELandmarkName, |
|
177 TPosLmSortPref::EAscending ); |
|
178 |
|
179 CPosLmOperation* searchOperation = iSearch->StartLandmarkSearchL( *criteria , sortOrder ); |
|
180 CleanupStack::PopAndDestroy( criteria ); //criteria |
|
181 CleanupStack::PushL( searchOperation ); |
|
182 if (iSearchAO) |
|
183 { |
|
184 iSearchAO->StopOperation(); |
|
185 delete iSearchAO; // cancel possibly pending operation |
|
186 iSearchAO = NULL; |
|
187 } |
|
188 |
|
189 iSearchAO = CLmkAOOperation::NewL( searchOperation, |
|
190 *this, |
|
191 MLmkAOOperationObserver::ESearch, |
|
192 iOperationNotInUse ); |
|
193 |
|
194 iOperationNotInUse = ETrue; |
|
195 CleanupStack::Pop( searchOperation ); // ownership transferred |
|
196 if( iSearchAO ) |
|
197 iSearchAO->StartOperation(); |
|
198 } |
|
199 } |
|
200 |
|
201 // ----------------------------------------------------------------------------- |
|
202 // CLmkLandmarkListProvider::PrepareListL |
|
203 // ----------------------------------------------------------------------------- |
|
204 // |
|
205 TBool CLmkLandmarkListProvider::PrepareListL(const TDesC& aSearchPattern, |
|
206 TBool aSearchOnlyInPreviousMatches) |
|
207 { |
|
208 iCount = 0; |
|
209 iRequestFromFindBox = ETrue; |
|
210 iOperationNotInUse = ETrue; |
|
211 |
|
212 if( aSearchPattern.Compare( KDefaultTextCriteria ) == 0 |
|
213 || aSearchPattern.Length() <= 0 ) |
|
214 { |
|
215 PrepareListL(); |
|
216 iRequestFromFindBox = EFalse; |
|
217 return ETrue; |
|
218 } |
|
219 |
|
220 // We need to cancel if we are searching/reading landmarks. |
|
221 if (iSearchAO) |
|
222 { |
|
223 iSearchAO->StopOperation(); |
|
224 delete iSearchAO; // cancel possibly pending operation |
|
225 iSearchAO = NULL; |
|
226 } |
|
227 |
|
228 // Create the composite criterion |
|
229 CPosLmCompositeCriteria* compCrit = CPosLmCompositeCriteria::NewLC( |
|
230 CPosLmCompositeCriteria::ECompositionOR ); |
|
231 |
|
232 // Create the text search criterion and add it to composite |
|
233 CPosLmTextCriteria* textCrit = CPosLmTextCriteria::NewLC(); |
|
234 |
|
235 const TInt KExtraChars = 3; // 2 chars wildcards |
|
236 HBufC* filterBuf = HBufC::NewLC(aSearchPattern.Length() + KExtraChars); |
|
237 TPtr filter = filterBuf->Des(); |
|
238 filter.Copy(KSpaceTextCriteria); |
|
239 filter.Append(aSearchPattern); |
|
240 |
|
241 textCrit->SetTextL( filter ); |
|
242 textCrit->SetAttributesToSearch(CPosLandmark::ELandmarkName); |
|
243 |
|
244 User::LeaveIfError( compCrit->AddArgument( textCrit ) ); |
|
245 // Ownership of the text criterion has been passed to the composite |
|
246 CleanupStack::PopAndDestroy( filterBuf ); |
|
247 CleanupStack::Pop( textCrit ); |
|
248 |
|
249 // Create the text search criterion and add it to composite |
|
250 CPosLmTextCriteria* textCrit2 = CPosLmTextCriteria::NewLC(); |
|
251 textCrit2->SetTextL( aSearchPattern ); |
|
252 textCrit2->SetAttributesToSearch(CPosLandmark::ELandmarkName); |
|
253 |
|
254 User::LeaveIfError( compCrit->AddArgument( textCrit2 ) ); |
|
255 // Ownership of the text criterion has been passed to the composite |
|
256 CleanupStack::Pop( textCrit2 ); |
|
257 |
|
258 iDb.SetPartialReadParametersL( *iReadParams ); |
|
259 |
|
260 TPosLmSortPref sortOrder( CPosLandmark::ELandmarkName, |
|
261 TPosLmSortPref::EAscending ); |
|
262 // Start the search |
|
263 // Create search operation |
|
264 CPosLmOperation* operation = iSearch->StartLandmarkSearchL( |
|
265 *compCrit, sortOrder, aSearchOnlyInPreviousMatches ); |
|
266 |
|
267 CleanupStack::PopAndDestroy( compCrit ); |
|
268 CleanupStack::PushL( operation ); |
|
269 |
|
270 iSearchAO = CLmkAOOperation::NewL( operation, |
|
271 *this, |
|
272 MLmkAOOperationObserver::ESearch, |
|
273 ETrue ); |
|
274 CleanupStack::Pop( operation ); // ownership transferred |
|
275 |
|
276 if( iSearchAO ) |
|
277 iSearchAO->StartOperation(); |
|
278 return ETrue; |
|
279 } |
|
280 |
|
281 // ----------------------------------------------------------------------------- |
|
282 // CLmkLandmarkListProvider::HandleDatabaseEvent |
|
283 // ----------------------------------------------------------------------------- |
|
284 // |
|
285 void CLmkLandmarkListProvider::HandleDatabaseEvent( TPosLmEvent& aEvent ) |
|
286 { |
|
287 // TODO: we need a helper method like ValidatedIdArrayL() to check id |
|
288 // array given by the client (that means: iListAllItemsInDb == EFalse) |
|
289 // in case when database items are modified. Some items might have been |
|
290 // deleted for instance. Possibly CLmkLmItemListProvider functionality? |
|
291 |
|
292 TBool needRefresh = ETrue; |
|
293 |
|
294 // check any items are selected to do operations like iconchanges or add to category. |
|
295 if( iSelectedItemsCount > 0 ) |
|
296 { |
|
297 iCount++; |
|
298 if( iSelectedItemsCount == iCount ) |
|
299 { |
|
300 iSelectedItemsCount = 0; |
|
301 iCount = 0; |
|
302 } |
|
303 needRefresh = EFalse; |
|
304 } |
|
305 switch ( aEvent.iEventType ) |
|
306 { |
|
307 case EPosLmEventLandmarkUpdated: // lm icon changes, lm renaming |
|
308 case EPosLmEventLandmarkUnknownChanges: // lm multiple deletion, lm add to category |
|
309 case EPosLmEventUnknownChanges: |
|
310 case EPosLmEventLandmarkCreated: |
|
311 { |
|
312 if( needRefresh ) |
|
313 { |
|
314 if( iSearchAO ) |
|
315 { |
|
316 iSearchAO->StopOperation(); |
|
317 delete iSearchAO; |
|
318 iSearchAO = NULL; |
|
319 } |
|
320 iOperationNotInUse = EFalse; |
|
321 TInt err = KErrNone; |
|
322 do |
|
323 { |
|
324 TRAP( err, PrepareListL() ); |
|
325 }while(err == KErrLocked); |
|
326 if ( err ) |
|
327 { |
|
328 HandleError( err ); |
|
329 } |
|
330 } |
|
331 else |
|
332 { |
|
333 NotifyObservers( ELmkEventListReady ); |
|
334 } |
|
335 break; |
|
336 } |
|
337 case EPosLmEventLandmarkDeleted: |
|
338 { |
|
339 TInt index = iIdArray.Find( aEvent.iLandmarkItemId ); |
|
340 if( index != KErrNotFound && index < iIdArray.Count()) |
|
341 { |
|
342 iIdArray.Remove(index); |
|
343 NotifyObservers( ELmkEventListReady ); |
|
344 } |
|
345 break; |
|
346 } |
|
347 default: |
|
348 { // Not interesting event for this provider |
|
349 break; |
|
350 } |
|
351 } |
|
352 // Remember to call base class observer method too |
|
353 CLmkLmItemListProvider::HandleDatabaseEvent( aEvent ); |
|
354 } |
|
355 |
|
356 // --------------------------------------------------------- |
|
357 // CLmkLandmarkListProvider::HandleOperationL |
|
358 // --------------------------------------------------------- |
|
359 // |
|
360 void CLmkLandmarkListProvider::HandleOperationL( |
|
361 TOperationTypes aType, |
|
362 TReal32 aProgress, |
|
363 TInt aStatus ) |
|
364 { |
|
365 if ( aType == MLmkAOOperationObserver::EDeleteLandmarks ) |
|
366 { |
|
367 return; |
|
368 } |
|
369 if ( aType == MLmkAOOperationObserver::ESearch ) |
|
370 { |
|
371 ReadItemsToArrayL(); |
|
372 if ( aStatus == KErrNone ) |
|
373 { |
|
374 if( iSearchAO ) |
|
375 { |
|
376 iSearchAO->StopOperation(); |
|
377 delete iSearchAO; |
|
378 iSearchAO = NULL; |
|
379 } |
|
380 if (iOperationNotInUse == EFalse ) |
|
381 { |
|
382 NotifyObservers( ELmkEventItemAdditionComplete ); |
|
383 } |
|
384 else |
|
385 { |
|
386 if (iRequestFromFindBox) |
|
387 { |
|
388 NotifyObservers( ELmkEventFindListReady ); |
|
389 } |
|
390 else |
|
391 { |
|
392 NotifyObservers( ELmkEventListReady ); |
|
393 } |
|
394 } |
|
395 iOperationNotInUse = ETrue; |
|
396 |
|
397 iCount = 0; |
|
398 if(iItemsDeleted < iItemsToDelete) |
|
399 { |
|
400 PrepareForDeleteL(); |
|
401 } |
|
402 else |
|
403 { |
|
404 if(iWaitNote) |
|
405 { |
|
406 iWaitNote->ProcessFinishedL(); |
|
407 iWaitNote = NULL; |
|
408 } |
|
409 } |
|
410 return; |
|
411 } // end of if ( aStatus == KErrNone ) |
|
412 |
|
413 else if ( iCount == ELmkStepOne || iCount == ELmkStepTwo ) |
|
414 { |
|
415 if (iRequestFromFindBox) |
|
416 { |
|
417 NotifyObservers( ELmkEventFindListReady ); |
|
418 } |
|
419 else |
|
420 { |
|
421 NotifyObservers( ELmkEventListReady ); |
|
422 } |
|
423 iOperationNotInUse = EFalse; |
|
424 } |
|
425 } |
|
426 else |
|
427 { // This is not this classes' operation |
|
428 CLmkLmItemListProvider::HandleOperationL( aType, aProgress, aStatus); |
|
429 } |
|
430 } |
|
431 |
|
432 // --------------------------------------------------------- |
|
433 // CLmkLandmarkListProvider::ReadItemsToArrayL |
|
434 // --------------------------------------------------------- |
|
435 // |
|
436 void CLmkLandmarkListProvider::ReadItemsToArrayL() |
|
437 { |
|
438 iIdArray.Reset(); |
|
439 CPosLmItemIterator* iterator = iSearch->MatchIteratorL(); |
|
440 CleanupStack::PushL( iterator ); |
|
441 iCount = iterator->NumOfItemsL(); |
|
442 if ( iCount > 0 ) |
|
443 { // can only be called if there are some items |
|
444 iterator->GetItemIdsL( iIdArray, 0, iCount ); // array is first reseted |
|
445 } |
|
446 CleanupStack::PopAndDestroy( iterator ); |
|
447 } |
|
448 |
|
449 // --------------------------------------------------------- |
|
450 // CLmkLandmarkListProvider::RemoveLandmarksL |
|
451 // --------------------------------------------------------- |
|
452 // |
|
453 void CLmkLandmarkListProvider::RemoveLandmarksL(const RArray<TPosLmItemId>& aSelectedItems ) |
|
454 { |
|
455 iItemsToDelete = aSelectedItems.Count(); |
|
456 iSelectedForDelete.Reset(); |
|
457 for(TInt i=0;i<iItemsToDelete;i++) |
|
458 iSelectedForDelete.Append(aSelectedItems[i]); |
|
459 iItemsDeleted = 0; |
|
460 iIsRemoveLandmarks = ETrue; |
|
461 |
|
462 if(iWaitNote) |
|
463 { |
|
464 delete iWaitNote; |
|
465 iWaitNote = NULL; |
|
466 } |
|
467 PrepareForDeleteL(); |
|
468 } |
|
469 |
|
470 // --------------------------------------------------------- |
|
471 // CLmkLandmarkListProvider::PrepareForDelete |
|
472 // --------------------------------------------------------- |
|
473 // |
|
474 void CLmkLandmarkListProvider::PrepareForDeleteL() |
|
475 { |
|
476 RArray<TPosLmItemId> bufItems; |
|
477 TInt count = iItemsDeleted; |
|
478 if(iItemsToDelete > (iItemsDeleted + 10)) |
|
479 { |
|
480 iItemsDeleted = iItemsDeleted + 10; |
|
481 } |
|
482 else |
|
483 { |
|
484 iItemsDeleted = iItemsDeleted + (iItemsToDelete - iItemsDeleted); |
|
485 } |
|
486 |
|
487 for(TInt i=count;i<iItemsDeleted;i++) |
|
488 { |
|
489 bufItems.Append(iSelectedForDelete[i]); |
|
490 } |
|
491 |
|
492 CPosLmOperation* operation = |
|
493 iDb.RemoveLandmarksL( bufItems ); |
|
494 |
|
495 CleanupStack::PushL( operation ); |
|
496 iSearchAO = CLmkAOOperation::NewL( operation, |
|
497 *this, |
|
498 MLmkAOOperationObserver::EDeleteLandmarks, |
|
499 EFalse ); |
|
500 CleanupStack::Pop( operation ); // ownership transferred |
|
501 |
|
502 if( iSearchAO ) |
|
503 { |
|
504 iSearchAO->StartOperation(); |
|
505 if(!iWaitNote) |
|
506 { |
|
507 iWaitNote = new (ELeave) CAknWaitDialog(NULL, ETrue); |
|
508 if(!iWaitNote->ExecuteLD(R_LMK_PROCESSING_WAIT_NOTE)) |
|
509 { |
|
510 iSearchAO->StopOperation(); |
|
511 delete iSearchAO; |
|
512 iSearchAO = NULL; |
|
513 iWaitNote = NULL; |
|
514 } |
|
515 } |
|
516 } |
|
517 bufItems.Close(); |
|
518 } |
|
519 |
|
520 // End of File |