120 if (iLandmarksLookupDb) |
101 if (iLandmarksLookupDb) |
121 { |
102 { |
122 iLandmarksLookupDb->Close(); |
103 iLandmarksLookupDb->Close(); |
123 delete iLandmarksLookupDb; |
104 delete iLandmarksLookupDb; |
124 } |
105 } |
125 if (iMylocationsLookupDb) |
106 if (iLocationAppLookupDb) |
126 { |
107 { |
127 iMylocationsLookupDb->Close(); |
108 iLocationAppLookupDb->close(); |
128 delete iMylocationsLookupDb; |
109 delete iLocationAppLookupDb; |
129 } |
110 } |
130 |
111 |
131 delete iLandmarksCatManager; |
112 delete iLandmarksCatManager; |
132 |
113 |
133 delete iLandmarkDb; |
114 delete iLandmarkDb; |
134 |
115 |
135 delete iMyLocationsCatManager; |
|
136 |
|
137 delete iMyLocationsLandmarksDb; |
|
138 |
|
139 // close the file session |
116 // close the file session |
140 iFsSession.Close(); |
117 iFsSession.Close(); |
141 |
118 |
142 } |
119 } |
143 |
120 |
144 // ----------------------------------------------------------------------------- |
121 // ----------------------------------------------------------------------------- |
145 // CMyLocationsDatabaseManager::AddMylocationsCategoryL() |
122 // CMyLocationsDatabaseManager::AddMylocationsCategoryL() |
146 // Adds the category to the mylocations and landmarks database.. |
123 // Adds the category to the mylocations and landmarks database.. |
147 // ----------------------------------------------------------------------------- |
124 // ----------------------------------------------------------------------------- |
148 // |
125 // |
149 void CMyLocationsDatabaseManager::AddMylocationsCategoryL( const TUint32 aCategoryType ) |
126 TUint32 CMyLocationsDatabaseManager::AddMylocationsCategoryL( const TDesC& aCategoryName ) |
150 { |
127 { |
151 __TRACE_CALLSTACK;//Open the resource file |
128 __TRACE_CALLSTACK;//Open the resource file |
152 RResourceFile resourceFile; |
129 |
153 resourceFile.OpenL( iFsSession, KMyLocationsResourceFile ); |
130 TPosLmItemId catId = 0; |
154 CleanupClosePushL( resourceFile ); |
131 |
155 |
132 //create category |
156 // Get the category name |
133 CPosLandmarkCategory *category = CPosLandmarkCategory::NewL(); |
157 HBufC8* dataBuffer = NULL; |
134 CleanupStack::PushL(category); |
158 if (aCategoryType == ESourceLandmarksContactsCat) |
135 category->SetCategoryNameL( aCategoryName ); |
159 { |
136 |
160 dataBuffer = resourceFile.AllocReadLC(R_LOCINT_LIST_CATEGORY_CONTACTS); |
137 // Add category to landmarks database |
161 } |
138 TRAPD ( error, ( catId = iLandmarksCatManager->AddCategoryL( *category ) ) ); |
162 |
139 if (error == KErrNone || error == KErrAlreadyExists) |
163 TResourceReader resReader; |
140 { |
164 resReader.SetBuffer(dataBuffer); |
141 catId = iLandmarksCatManager->GetCategoryL( aCategoryName ); |
165 TPtrC resData = resReader.ReadTPtrC(); |
142 } |
166 |
143 |
167 TLookupItem lookupItem; |
144 CleanupStack::PopAndDestroy(category); |
168 lookupItem.iLmId = 0; |
145 |
169 lookupItem.iSource = aCategoryType; |
146 return catId; |
170 lookupItem.iUid = 0; |
|
171 |
|
172 RArray<TLookupItem> itemArray; |
|
173 CleanupClosePushL(itemArray); |
|
174 iMylocationsLookupDb->FindEntriesBySourceTypeL(lookupItem.iSource, |
|
175 itemArray); |
|
176 |
|
177 // Get the category from mylocations lookup table |
|
178 if (itemArray.Count() == 0) |
|
179 { |
|
180 // category not found, so create one. |
|
181 CPosLandmarkCategory *category = CPosLandmarkCategory::NewL(); |
|
182 CleanupStack::PushL(category); |
|
183 category->SetCategoryNameL(resData); |
|
184 |
|
185 if ( aCategoryType == ESourceLandmarksContactsCat) |
|
186 { |
|
187 TPosLmItemId landmarksCatId = 0; |
|
188 // Add category to landmarks database |
|
189 TRAPD ( error, ( landmarksCatId = iLandmarksCatManager->AddCategoryL( *category ) ) ); |
|
190 if (error == KErrNone || error == KErrAlreadyExists) |
|
191 { |
|
192 landmarksCatId = iLandmarksCatManager->GetCategoryL(resData); |
|
193 } |
|
194 lookupItem.iUid = landmarksCatId; |
|
195 } |
|
196 |
|
197 // Add the catefory to mylocations database |
|
198 TPosLmItemId myLocationsCatId = 0; |
|
199 // Add category to mylocations database |
|
200 TRAPD ( error, ( myLocationsCatId = iMyLocationsCatManager->AddCategoryL( *category ) ) ); |
|
201 if (error == KErrNone || error == KErrAlreadyExists) |
|
202 { |
|
203 myLocationsCatId = iMyLocationsCatManager->GetCategoryL(resData); |
|
204 } |
|
205 // create this entry in mylocations lookup table |
|
206 lookupItem.iSource = aCategoryType; |
|
207 lookupItem.iLmId = myLocationsCatId; |
|
208 iMylocationsLookupDb->CreateEntryL(lookupItem); |
|
209 |
|
210 CleanupStack::PopAndDestroy(category); |
|
211 } |
|
212 else |
|
213 { |
|
214 // category found in lookup table, |
|
215 // update the corresponding category in Mylocations and landmarks database with |
|
216 // current localized string |
|
217 |
|
218 |
|
219 lookupItem.iLmId = itemArray[0].iLmId; |
|
220 lookupItem.iUid = itemArray[0].iUid; |
|
221 if ( aCategoryType == ESourceLandmarksContactsCat) |
|
222 { |
|
223 CPosLandmarkCategory *category = |
|
224 iLandmarksCatManager->ReadCategoryLC(lookupItem.iUid); |
|
225 category->SetCategoryNameL(resData); |
|
226 TRAP_IGNORE ( ( iLandmarksCatManager->UpdateCategoryL( *category ) ) ); |
|
227 CleanupStack::PopAndDestroy(category); |
|
228 } |
|
229 // update category in mylocations db |
|
230 CPosLandmarkCategory *category2 = |
|
231 iMyLocationsCatManager->ReadCategoryLC(lookupItem.iLmId); |
|
232 category2->SetCategoryNameL(resData); |
|
233 TRAP_IGNORE ( ( iMyLocationsCatManager->UpdateCategoryL( *category2 ) ) ); |
|
234 CleanupStack::PopAndDestroy(category2); |
|
235 } |
|
236 |
|
237 CleanupStack::PopAndDestroy(&itemArray); |
|
238 |
|
239 if ( dataBuffer ) |
|
240 { |
|
241 CleanupStack::PopAndDestroy(dataBuffer); |
|
242 } |
|
243 |
|
244 if (aCategoryType == ESourceLandmarksContactsCat) |
|
245 iLmContactsCatId = lookupItem.iUid; |
|
246 |
|
247 // Close the resource file |
|
248 CleanupStack::PopAndDestroy( &resourceFile ); |
|
249 |
|
250 } |
147 } |
251 |
148 |
252 // ----------------------------------------------------------------------------- |
149 // ----------------------------------------------------------------------------- |
253 // CMyLocationsDatabaseManager::UpdateDatabaseL() |
150 // CMyLocationsDatabaseManager::UpdateDatabaseL() |
254 // Updates the location into the landmark database and lookup table. Based on |
151 // Updates the location into the landmark database and lookup table. Based on |
427 // |
281 // |
428 void CMyLocationsDatabaseManager::HandleEntryAdditionL(CPosLandmark* aLandmark, |
282 void CMyLocationsDatabaseManager::HandleEntryAdditionL(CPosLandmark* aLandmark, |
429 const TUint32 aUid, const TUint32 aSourceType) |
283 const TUint32 aUid, const TUint32 aSourceType) |
430 { |
284 { |
431 __TRACE_CALLSTACK; |
285 __TRACE_CALLSTACK; |
|
286 // Create a lookup item |
|
287 QLookupItem lookupItem; |
|
288 lookupItem.mSourceUid = aUid; |
|
289 lookupItem.mSourceType = aSourceType; |
|
290 lookupItem.mDestId = 0; |
|
291 lookupItem.mIconType = QLookupItem::EIconTypeDefault; |
|
292 lookupItem.mIsDuplicate = 0; |
|
293 lookupItem.mIconPath = ""; |
|
294 lookupItem.mMapTilePath = ""; |
|
295 |
|
296 //fill address into lookup item. |
|
297 FillLookupItemAddressDetails( aLandmark, lookupItem ); |
|
298 |
432 if ( aSourceType == ESourceLandmarks ) |
299 if ( aSourceType == ESourceLandmarks ) |
433 { |
300 { |
434 AddToMylocationsDbL(aLandmark, aUid, aSourceType); |
301 // Logic: check if the entry is already present in lookupdb. |
435 return; |
302 // If present, it means the landmark corresponds to a contact/calendar. So ignore it. |
436 } |
303 // If not present, it means the landmark is created directly into the landmarks db. So add |
437 if ( aSourceType == ESourceLandmarksCategory ) |
304 // it in lookupdb as well. |
438 { |
305 |
439 CreateCategoryL(aUid); |
306 // check if the entry is already present in lookup db. |
440 return; |
307 QList<QLookupItem> itemArray; |
441 } |
308 iLocationAppLookupDb->findEntriesByLandmarkId( aUid, itemArray ); |
442 // Create a lookup item |
309 if( itemArray.count() ) |
443 TLookupItem lookupItem; |
310 { |
444 lookupItem.iUid = aUid; |
311 return; |
445 lookupItem.iSource = aSourceType; |
312 } |
446 |
313 else |
|
314 { |
|
315 lookupItem.mDestId = aUid; |
|
316 iLocationAppLookupDb->createEntry( lookupItem ); |
|
317 return; |
|
318 } |
|
319 } |
|
320 |
|
321 TPosLmItemId catId; |
|
322 if( aSourceType == ESourceCalendar ) |
|
323 { |
|
324 // category id to calendar |
|
325 catId = iLmCalendarCatId; |
|
326 } |
|
327 else |
|
328 { |
|
329 // remove landmark name, which is basically contact's name. |
|
330 aLandmark->SetLandmarkNameL( KNullDesC ); |
|
331 // category id to contacts |
|
332 catId = iLmContactsCatId; |
|
333 } |
447 // check if this landmark is already present in database |
334 // check if this landmark is already present in database |
448 TPosLmItemId dupLmId = CheckIfDuplicateExistsL(aLandmark); |
335 TPosLmItemId dupLmId = CheckIfDuplicateExistsL( aLandmark ); |
449 if (dupLmId) |
336 if ( dupLmId ) |
450 { |
337 { |
451 // landmark already present in db. get the details |
338 // landmark already present in db. get the details |
452 CPosLandmark* dupLandmark = iLandmarkDb->ReadLandmarkLC(dupLmId); |
339 CPosLandmark* dupLandmark = iLandmarkDb->ReadLandmarkLC(dupLmId); |
453 if (dupLandmark) |
340 if( dupLandmark ) |
454 { |
341 { |
455 if (aSourceType == ESourceContactsPref || aSourceType |
342 // add category. |
456 == ESourceContactsWork || aSourceType |
343 dupLandmark->AddCategoryL( catId ); |
457 == ESourceContactsHome) |
|
458 { |
|
459 dupLandmark->AddCategoryL(iLmContactsCatId); |
|
460 } |
|
461 // update the landmark object in the db |
344 // update the landmark object in the db |
462 iLandmarkDb->UpdateLandmarkL(*dupLandmark); |
345 iLandmarkDb->UpdateLandmarkL( *dupLandmark ); |
463 CleanupStack::PopAndDestroy(dupLandmark); |
346 CleanupStack::PopAndDestroy( dupLandmark ); |
464 } |
347 } |
465 |
348 |
466 // point the lookup item's landmark uid to the existing landmark. |
349 // point the lookup item's landmark uid to the existing landmark. |
467 lookupItem.iLmId = dupLmId; |
350 lookupItem.mDestId = dupLmId; |
|
351 if( aSourceType == ESourceCalendar ) |
|
352 { |
|
353 // set duplicate flag to true. only if it is calendar entry. |
|
354 // for contacts duplicate doesnot hold good as the location name is the contact name. |
|
355 |
|
356 // set duplicate only if there are calendar entries already pointing to this landmark. |
|
357 if( IsDuplicateEntry( dupLmId ) ) |
|
358 { |
|
359 lookupItem.mIsDuplicate = 1; |
|
360 } |
|
361 } |
468 } |
362 } |
469 else // it is a new entry, so add into the database |
363 else // it is a new entry, so add into the database |
470 { |
364 { |
471 if (aSourceType == ESourceContactsPref || aSourceType |
365 // add category. |
472 == ESourceContactsWork || aSourceType == ESourceContactsHome) |
366 aLandmark->AddCategoryL( catId ); |
473 { |
|
474 aLandmark->AddCategoryL(iLmContactsCatId); |
|
475 } |
|
476 // add the landmark into the db. |
367 // add the landmark into the db. |
477 // point the lookup item's landmark uid to the newly created landmark in the db. |
368 // point the lookup item's landmark uid to the newly created landmark in the db. |
478 lookupItem.iLmId = iLandmarkDb->AddLandmarkL(*aLandmark); |
369 lookupItem.mDestId = iLandmarkDb->AddLandmarkL( *aLandmark ); |
479 } |
370 } |
480 |
371 |
481 // create the entry in the lookup table. |
372 // create the entry in the lookup table. |
482 iLandmarksLookupDb->CreateEntryL(lookupItem); |
373 iLocationAppLookupDb->createEntry( lookupItem ); |
483 |
|
484 } |
374 } |
485 |
375 |
486 // ----------------------------------------------------------------------------- |
376 // ----------------------------------------------------------------------------- |
487 // CMyLocationsDatabaseManager::HandleEntryModificationL() |
377 // CMyLocationsDatabaseManager::HandleEntryModificationL() |
488 // Handles the entry modification in the lookup table and landmarks db. |
378 // Handles the entry modification in the lookup table and landmarks db. |
489 // ----------------------------------------------------------------------------- |
379 // ----------------------------------------------------------------------------- |
490 // |
380 // |
491 void CMyLocationsDatabaseManager::HandleEntryModificationL( |
381 void CMyLocationsDatabaseManager::HandleEntryModificationL( |
492 CPosLandmark* aLandmark, const TUint32 aUid, const TUint32 aSourceType) |
382 CPosLandmark* aLandmark, const TUint32 aUid, const TUint32 aSourceType ) |
493 { |
383 { |
494 __TRACE_CALLSTACK; |
384 __TRACE_CALLSTACK; |
495 if ( aSourceType == ESourceLandmarks ) |
385 if ( aSourceType == ESourceLandmarks ) |
496 { |
386 { |
497 ModifyMylocationsDbL( aLandmark, aUid, aSourceType ); |
387 HandleLandmarkModificationL( aLandmark, aUid ); |
498 return; |
388 return; |
499 } |
389 } |
500 |
390 |
501 TLookupItem lookupItem; |
391 QLookupItem lookupItem; |
502 lookupItem.iUid = aUid; |
392 lookupItem.mSourceUid = aUid; |
503 lookupItem.iSource = aSourceType; |
393 lookupItem.mSourceType = aSourceType; |
504 |
394 lookupItem.mIconType = QLookupItem::EIconTypeDefault; |
505 |
395 |
506 if (aSourceType == ESourceContactsPref || aSourceType |
396 // Behavior: If an entry is modified, |
507 == ESourceContactsWork || aSourceType == ESourceContactsHome) |
397 // If this entry is not present in lookup table. add the entry and update the landmarks db. |
508 { |
398 // If this entry is already present in lookup table, check if the location info is modified or not. |
509 // Behavior: If a contact is modified, |
399 // If the location info is modified, delete the landmark from db and add the new landmark |
510 // If this entry is not present in lookup table. add the entry and update the landmarks db. |
400 // into the db. |
511 // If this entry is already present in lookup table, check if the location info is modified or not. |
401 // Before deletion make sure that the landmark is not being refered by other lookup entries. |
512 // If the location info is modified, delete the landmark from db and add the new landmark |
402 |
513 // into the db. |
403 // find the entry in the lookup table. |
514 // Before deletion make sure that the landmark is not being refered by other lookup entries. |
404 if ( iLocationAppLookupDb->findEntryBySourceIdAndType( lookupItem ) ) |
515 |
405 { |
516 // find the entry in the lookup table. |
406 //fill address into lookup item. |
517 if (iLandmarksLookupDb->FindEntryL(lookupItem)) |
407 FillLookupItemAddressDetails( aLandmark, lookupItem ); |
518 { |
408 |
519 // check if the location info is modified by comparing the new landmark with the existing landmark |
409 QString locationName = lookupItem.mName; |
520 CPosLandmark* existingLandmark = NULL; |
410 |
521 TRAPD( error, ( existingLandmark = |
411 TPosLmItemId catId; |
522 CheckAndReadLandmarkL( iLandmarkDb, lookupItem.iLmId ) ) ); |
412 |
523 CleanupStack::PushL(existingLandmark); |
413 if( aSourceType == ESourceCalendar ) |
524 if (error == KErrNotFound) |
414 { |
525 { |
415 catId = iLmCalendarCatId; |
526 // Landmarks item deleted. So delete corresponding lookup entries. |
416 } |
527 RArray<TLookupItem> itemArray; |
417 else |
528 CleanupClosePushL(itemArray); |
418 { |
529 iLandmarksLookupDb->FindEntriesByLandmarkIdL(lookupItem.iLmId, |
419 // remove landmark name, which is basically contact's name. |
530 itemArray); |
420 aLandmark->SetLandmarkNameL( KNullDesC ); |
531 for (TInt i = 0; i < itemArray.Count(); i++) |
421 |
|
422 // category id to contacts |
|
423 catId = iLmContactsCatId; |
|
424 } |
|
425 |
|
426 |
|
427 // check if the location info is modified by comparing the new landmark with the existing landmark |
|
428 CPosLandmark* existingLandmark = NULL; |
|
429 TRAPD( error, ( existingLandmark = |
|
430 CheckAndReadLandmarkL( iLandmarkDb, lookupItem.mDestId ) ) ); |
|
431 CleanupStack::PushL( existingLandmark ); |
|
432 if ( error == KErrNotFound ) |
|
433 { |
|
434 // Landmarks item deleted. So delete corresponding lookup entries. |
|
435 QList<QLookupItem> itemArray; |
|
436 iLocationAppLookupDb->findEntriesByLandmarkId( lookupItem.mDestId, itemArray ); |
|
437 for ( int i = 0; i < itemArray.count(); i++) |
|
438 { |
|
439 iLocationAppLookupDb->deleteEntryBySourceIdAndType( itemArray[i] ); |
|
440 } |
|
441 |
|
442 // Add the entry into the lookup table and update landmarks db. |
|
443 HandleEntryAdditionL( aLandmark, aUid, aSourceType ); |
|
444 |
|
445 CleanupStack::PopAndDestroy( existingLandmark ); |
|
446 return; |
|
447 } |
|
448 |
|
449 if ( !CompareLandmarks( existingLandmark, aLandmark ) ) |
|
450 { |
|
451 // landmarks are not same, means location information is modified. |
|
452 |
|
453 // Check if the new landmark is already in db. |
|
454 TPosLmItemId dupLmId = CheckIfDuplicateExistsL( aLandmark ); |
|
455 if ( dupLmId ) |
|
456 { |
|
457 // landmark already present in db. get the details |
|
458 CPosLandmark* dupLandmark = iLandmarkDb->ReadLandmarkLC( dupLmId ); |
|
459 if ( dupLandmark ) |
532 { |
460 { |
533 iLandmarksLookupDb->DeleteEntryL(itemArray[i]); |
461 // add category. |
|
462 dupLandmark->AddCategoryL( catId ); |
|
463 |
|
464 // update the landmark object in the db |
|
465 iLandmarkDb->UpdateLandmarkL( *dupLandmark ); |
534 } |
466 } |
535 CleanupStack::PopAndDestroy(&itemArray); |
467 CleanupStack::PopAndDestroy( dupLandmark ); |
536 |
468 |
537 // Add the entry into the lookup table and update landmarks db. |
469 // update the lookup item to refer to the newly created landmark. |
538 HandleEntryAdditionL(aLandmark, aUid, aSourceType); |
470 lookupItem.mDestId = dupLmId; |
|
471 if( aSourceType == ESourceCalendar ) |
|
472 { |
|
473 // for contacts duplicate doesnot hold good as the location name is the contact name. |
|
474 if( !lookupItem.mIsDuplicate ) |
|
475 { |
|
476 // if current lookup item duplicate property is 0, then remove next corresponding |
|
477 // calendar lookup entry duplicate property. |
|
478 // this is required because the current entry will be pointing to a new landmark. |
|
479 UnsetDuplicateNextCalEntry( existingLandmark->LandmarkId() ); |
|
480 } |
|
481 |
|
482 // set duplicate only if there are calendar entries already pointing to this landmark. |
|
483 if( IsDuplicateEntry( dupLmId ) ) |
|
484 { |
|
485 lookupItem.mIsDuplicate = 1; |
|
486 } |
|
487 |
|
488 } |
539 |
489 |
540 CleanupStack::PopAndDestroy(existingLandmark); |
490 iLocationAppLookupDb->updateEntryBySourceIdAndType( lookupItem ); |
541 return; |
491 } |
542 } |
492 else |
543 |
493 { |
544 if (!CompareLandmarks(existingLandmark, aLandmark)) |
494 // landmark not already present in db. |
545 { |
495 // Create a new entry in the db |
546 // landmarks are not same, means location information is modified. |
496 aLandmark->AddCategoryL( catId ); |
547 |
497 lookupItem.mDestId = iLandmarkDb->AddLandmarkL( *aLandmark ); |
548 // Check if the new landmark is already in db. |
498 if( aSourceType == ESourceCalendar ) |
549 TPosLmItemId dupLmId = CheckIfDuplicateExistsL(aLandmark); |
|
550 if (dupLmId) |
|
551 { |
499 { |
552 // landmark already present in db. get the details |
500 // for contacts duplicate doesnot hold good as the location name is the contact name. |
553 CPosLandmark* dupLandmark = iLandmarkDb->ReadLandmarkLC( |
501 if( !lookupItem.mIsDuplicate ) |
554 dupLmId); |
|
555 if (dupLandmark) |
|
556 { |
502 { |
557 // add category. |
503 // if current lookup item duplicate property is 0, then remove next corresponding |
558 dupLandmark->AddCategoryL(iLmContactsCatId); |
504 // calendar lookup entry duplicate property. |
559 |
505 // this is required because the current entry will be pointing to a new landmark. |
560 // update the landmark object in the db |
506 UnsetDuplicateNextCalEntry( existingLandmark->LandmarkId() ); |
561 iLandmarkDb->UpdateLandmarkL(*dupLandmark); |
507 } |
|
508 } |
|
509 |
|
510 lookupItem.mIsDuplicate = 0; |
|
511 // update the lookup table |
|
512 iLocationAppLookupDb->updateEntryBySourceIdAndType( lookupItem ); |
|
513 } |
|
514 } |
|
515 else |
|
516 { |
|
517 // landmarks are same, means location not modified. So return. |
|
518 if( aSourceType == ESourceContactsPref |
|
519 || aSourceType == ESourceContactsWork |
|
520 || aSourceType == ESourceContactsHome |
|
521 ) |
|
522 { |
|
523 // in case of contacts, there is a chance that contact name is modified. |
|
524 // so update the lookup database entry with that name. |
|
525 lookupItem.mName = locationName; |
|
526 iLocationAppLookupDb->updateEntryBySourceIdAndType( lookupItem ); |
|
527 } |
|
528 |
|
529 CleanupStack::PopAndDestroy( existingLandmark ); |
|
530 return; |
|
531 } |
|
532 |
|
533 // delete the existing landmark only if it not being refered by other lookup entries. |
|
534 |
|
535 // Check if any other entries are refering this landmark. |
|
536 QList<QLookupItem> itemArray; |
|
537 iLocationAppLookupDb->findEntriesByLandmarkId( |
|
538 existingLandmark->LandmarkId(), itemArray ); |
|
539 |
|
540 if ( itemArray.count() ) |
|
541 { |
|
542 // There are other lookup entries refering this landmark. So do not delete the landmark |
|
543 |
|
544 // If none of these lookup item's source type is current source type, disassociate 'catId' category |
|
545 // from this landmark. |
|
546 TInt i = 0; |
|
547 while ( i < itemArray.count() ) |
|
548 { |
|
549 if( aSourceType == ESourceCalendar ) |
|
550 { |
|
551 if ( itemArray[i].mSourceType == aSourceType ) |
|
552 { |
|
553 // a lookup item exists which is from calendar, so 'catId' is still valid. |
|
554 break; |
562 } |
555 } |
563 CleanupStack::PopAndDestroy(dupLandmark); |
556 } |
564 |
557 else |
565 // update the lookup item to refer to the newly created landmark. |
558 { |
566 lookupItem.iLmId = dupLmId; |
559 // a lookup item exists which is from contacts, so 'catId' is still valid. |
567 iLandmarksLookupDb->UpdateEntryL(lookupItem); |
560 break; |
|
561 } |
|
562 i++; |
|
563 } |
|
564 if ( i == itemArray.count() ) |
|
565 { |
|
566 // no lookup items from current source type exists refering this landmark. |
|
567 // so disassociate 'catId' from this landmark |
|
568 |
|
569 existingLandmark->RemoveCategory( catId ); |
|
570 iLandmarkDb->UpdateLandmarkL( *existingLandmark ); |
|
571 } |
|
572 } |
|
573 else |
|
574 { |
|
575 // no other lookup entry is refering this landmark. |
|
576 // delete the landmark. |
|
577 iLandmarkDb->RemoveLandmarkL( existingLandmark->LandmarkId() ); |
|
578 } |
|
579 CleanupStack::PopAndDestroy( existingLandmark ); |
|
580 |
|
581 } |
|
582 else // entry not present in lookup table |
|
583 { |
|
584 // Add the entry into the lookup table and update landmarks db. |
|
585 HandleEntryAdditionL( aLandmark, aUid, aSourceType ); |
|
586 } |
|
587 } |
|
588 |
|
589 // ----------------------------------------------------------------------------- |
|
590 // CMyLocationsDatabaseManager::HandleEntryDeletionL() |
|
591 // Handles the entry deletion in lookup table and landmarks db. |
|
592 // ----------------------------------------------------------------------------- |
|
593 // |
|
594 void CMyLocationsDatabaseManager::HandleEntryDeletionL(const TUint32 aUid, |
|
595 const TUint32 aSourceType) |
|
596 { |
|
597 __TRACE_CALLSTACK; |
|
598 QLookupItem lookupItem; |
|
599 lookupItem.mSourceUid = aUid; |
|
600 lookupItem.mSourceType = aSourceType; |
|
601 |
|
602 // Behavior: if an entry is deleted, delete the corresponding entries from |
|
603 // both lookup table and iLandmarkDb. |
|
604 // Before deleting the entry from iLandmarkDb, make sure that this entry is not being refered by |
|
605 // other entries of the lookup table. If it is being refered by other entries in lookup table, then |
|
606 // do not delete the landmark. |
|
607 |
|
608 if ( !iLocationAppLookupDb->findEntryBySourceIdAndType( lookupItem ) ) |
|
609 { |
|
610 if( aSourceType == ESourceLandmarks ) |
|
611 { |
|
612 lookupItem.mDestId = aUid; |
|
613 } |
|
614 else |
|
615 { |
|
616 return; |
|
617 } |
|
618 } |
|
619 |
|
620 // Find the corresponding landmark uid |
|
621 |
|
622 |
|
623 // delete the lookup entry. |
|
624 iLocationAppLookupDb->deleteEntryBySourceIdAndType( lookupItem ); |
|
625 |
|
626 // Check if any other entries are refering this landmark. |
|
627 QList<QLookupItem> itemArray; |
|
628 iLocationAppLookupDb->findEntriesByLandmarkId( lookupItem.mDestId, itemArray ); |
|
629 |
|
630 if ( itemArray.count() ) |
|
631 { |
|
632 |
|
633 if( aSourceType == ESourceLandmarks ) |
|
634 { |
|
635 CPosLandmark* lm = NULL; |
|
636 |
|
637 for( int i = 0; i < itemArray.count(); i++ ) |
|
638 { |
|
639 if( itemArray[i].mSourceType == ESourceCalendar ) |
|
640 { |
|
641 // add landmark entry since a calendar item is present with this location. |
|
642 if( !lm ) |
|
643 { |
|
644 lm = CreateLandmarkItemLC( itemArray[i] ); |
|
645 } |
|
646 lm->AddCategoryL( iLmCalendarCatId ); |
568 } |
647 } |
569 else |
648 else |
570 { |
649 { |
571 // landmark not already present in db. |
650 // add landmark entry since a contact item is present with this location. |
572 // Create a new entry in the db |
651 if( !lm ) |
573 aLandmark->AddCategoryL(iLmContactsCatId); |
652 { |
574 lookupItem.iLmId = iLandmarkDb->AddLandmarkL(*aLandmark); |
653 QString tempStr = itemArray[i].mName; |
575 // update the lookup table |
654 itemArray[i].mName = ""; |
576 iLandmarksLookupDb->UpdateEntryL(lookupItem); |
655 lm = CreateLandmarkItemLC( itemArray[i] ); |
|
656 itemArray[i].mName = tempStr; |
|
657 } |
|
658 lm->AddCategoryL( iLmCalendarCatId ); |
|
659 } |
|
660 } |
|
661 |
|
662 lookupItem.mDestId = iLandmarkDb->AddLandmarkL( *lm ); |
|
663 CleanupStack::PopAndDestroy( lm ); |
|
664 |
|
665 bool dupUnset = false; |
|
666 for( int i=0; i<itemArray.count(); i++ ) |
|
667 { |
|
668 itemArray[i].mDestId = lookupItem.mDestId; |
|
669 if( itemArray[i].mSourceType == ESourceCalendar && dupUnset == false ) |
|
670 { |
|
671 dupUnset = true; |
|
672 itemArray[i].mIsDuplicate = 0; |
577 } |
673 } |
|
674 iLocationAppLookupDb->updateEntryById( itemArray[i] ); |
|
675 } |
|
676 |
|
677 return; |
|
678 } |
|
679 |
|
680 // There are other lookup entries refering this landmark. So do not delete the landmark |
|
681 |
|
682 // If none of these lookup item's source type is current source type, disassociate current source category |
|
683 // from this landmark. |
|
684 TInt i = 0; |
|
685 while ( i < itemArray.count() ) |
|
686 { |
|
687 if( aSourceType == ESourceCalendar ) |
|
688 { |
|
689 if( itemArray[i].mSourceType == aSourceType ) |
|
690 { |
|
691 if( lookupItem.mIsDuplicate == 0 ) |
|
692 { |
|
693 itemArray[i].mIsDuplicate = 0; |
|
694 iLocationAppLookupDb->updateEntryById( itemArray[i] ); |
|
695 } |
|
696 // a lookup item exists which is from calendar, so 'iLmCalendarCatId' is still valid. |
|
697 break; |
|
698 } |
|
699 |
|
700 } |
|
701 else if ( itemArray[i].mSourceType == ESourceContactsPref |
|
702 || itemArray[i].mSourceType == ESourceContactsWork |
|
703 || itemArray[i].mSourceType == ESourceContactsHome) |
|
704 { |
|
705 // a lookup item exists which is from contacts, so 'iLmContactsCatId' is still valid. |
|
706 break; |
|
707 } |
|
708 i++; |
|
709 } |
|
710 if ( i == itemArray.count() ) |
|
711 { |
|
712 // no lookup items from current source type exists refering this landmark. |
|
713 // so disassociate current source category from this landmark |
|
714 |
|
715 CPosLandmark* landmark = iLandmarkDb->ReadLandmarkLC( lookupItem.mDestId ); |
|
716 if( aSourceType == ESourceCalendar ) |
|
717 { |
|
718 landmark->RemoveCategory( iLmCalendarCatId ); |
578 } |
719 } |
579 else |
720 else |
580 { |
721 { |
581 // landmarks are same, means location not modified. So return. |
722 landmark->RemoveCategory( iLmContactsCatId ); |
582 CleanupStack::PopAndDestroy(existingLandmark); |
723 } |
583 return; |
724 |
584 } |
725 iLandmarkDb->UpdateLandmarkL( *landmark ); |
585 |
726 CleanupStack::PopAndDestroy( landmark ); |
586 // delete the existing landmark only if it not being refered by other lookup entries. |
727 } |
587 |
728 } |
588 // Check if any other entries are refering this landmark. |
729 else |
589 RArray<TLookupItem> itemArray; |
730 { |
590 CleanupClosePushL(itemArray); |
731 // no other lookup entry is refering this landmark. |
591 iLandmarksLookupDb->FindEntriesByLandmarkIdL( |
732 // delete the landmark. |
592 existingLandmark->LandmarkId(), itemArray); |
733 if ( aSourceType != ESourceLandmarks ) |
593 |
734 { |
594 if (itemArray.Count()) |
735 iLandmarkDb->RemoveLandmarkL( lookupItem.mDestId ); |
595 { |
736 } |
596 // There are other lookup entries refering this landmark. So do not delete the landmark |
737 } |
597 |
738 } |
598 // If none of these lookup item's source type is contacts, disassociate 'iLmContactsCatId' category |
739 |
599 // from this landmark. |
740 // ----------------------------------------------------------------------------- |
600 TInt i = 0; |
741 // CMyLocationsDatabaseManager::HandleLandmarkModificationL() |
601 while (i < itemArray.Count()) |
742 // ----------------------------------------------------------------------------- |
|
743 // |
|
744 void CMyLocationsDatabaseManager::HandleLandmarkModificationL( |
|
745 CPosLandmark* aLandmark, const TUint32 aUid ) |
|
746 { |
|
747 // logic: if a landmark is modified, |
|
748 // first update the corresponding landmark lookup entry if present, else create a new entry. |
|
749 // Check for any contact/calendar entries refering this landmark entry, |
|
750 // if exists, create a new landmark entry with that location details and update all those |
|
751 // lookup entry's destid with the newly created landmark id. |
|
752 |
|
753 QLookupItem lookupItem; |
|
754 lookupItem.mSourceUid = aUid; |
|
755 lookupItem.mSourceType = ESourceLandmarks; |
|
756 lookupItem.mIconType = QLookupItem::EIconTypeDefault; |
|
757 |
|
758 bool found = iLocationAppLookupDb->findEntryBySourceIdAndType( lookupItem ); |
|
759 //fill address into lookup item. |
|
760 FillLookupItemAddressDetails( aLandmark, lookupItem ); |
|
761 lookupItem.mDestId = aUid; |
|
762 lookupItem.mIsDuplicate = 0; |
|
763 lookupItem.mIconType = QLookupItem::EIconTypeDefault; |
|
764 lookupItem.mIconPath = ""; |
|
765 lookupItem.mMapTilePath = ""; |
|
766 |
|
767 // update entry in lookup table. |
|
768 if ( found ) |
|
769 { |
|
770 iLocationAppLookupDb->updateEntryById( lookupItem ); |
|
771 } |
|
772 else |
|
773 { |
|
774 iLocationAppLookupDb->createEntry( lookupItem ); |
|
775 } |
|
776 |
|
777 QList<QLookupItem> itemArray; |
|
778 iLocationAppLookupDb->findEntriesByLandmarkId( lookupItem.mDestId, itemArray ); |
|
779 |
|
780 if( itemArray.count() == 1 ) |
|
781 { |
|
782 //only one entry ie the entry corresponding to landmark db is present. |
|
783 return; |
|
784 } |
|
785 |
|
786 CPosLandmark* lm = NULL; |
|
787 |
|
788 for( int i = 0; i < itemArray.count(); i++ ) |
|
789 { |
|
790 if( itemArray[i].mSourceType != ESourceLandmarks ) |
|
791 { |
|
792 if( itemArray[i].mSourceType == ESourceCalendar ) |
|
793 { |
|
794 // add landmark entry since a calendar item is present with this location. |
|
795 if( !lm ) |
|
796 { |
|
797 lm = CreateLandmarkItemLC( itemArray[i] ); |
|
798 } |
|
799 lm->AddCategoryL( iLmCalendarCatId ); |
|
800 } |
|
801 else |
|
802 { |
|
803 // add landmark entry since a calendar item is present with this location. |
|
804 if( !lm ) |
|
805 { |
|
806 QString tempStr = itemArray[i].mName; |
|
807 itemArray[i].mName = ""; |
|
808 lm = CreateLandmarkItemLC( itemArray[i] ); |
|
809 itemArray[i].mName = tempStr; |
|
810 } |
|
811 lm->AddCategoryL( iLmCalendarCatId ); |
|
812 } |
|
813 } |
|
814 } |
|
815 |
|
816 // add the entry to landmarks db |
|
817 quint32 newDestId = iLandmarkDb->AddLandmarkL( *lm ); |
|
818 CleanupStack::PopAndDestroy( lm ); |
|
819 |
|
820 bool calDuplicateUnset = false; |
|
821 // update all the lookup entries with new landmark id |
|
822 for( int i = 0; i < itemArray.count(); i++ ) |
|
823 { |
|
824 if( itemArray[i].mSourceType != ESourceLandmarks ) |
|
825 { |
|
826 itemArray[i].mDestId = newDestId; |
|
827 |
|
828 if( itemArray[i].mSourceType == ESourceCalendar ) |
|
829 { |
|
830 if( !calDuplicateUnset ) |
602 { |
831 { |
603 if (itemArray[i].iSource == ESourceContactsPref |
832 itemArray[i].mIsDuplicate = 0; |
604 || itemArray[i].iSource == ESourceContactsWork |
833 calDuplicateUnset = true; |
605 || itemArray[i].iSource == ESourceContactsHome |
|
606 ) |
|
607 { |
|
608 // a lookup item exists which is from contacts, so 'iLmContactsCatId' is still valid. |
|
609 break; |
|
610 } |
|
611 i++; |
|
612 } |
834 } |
613 if (i == itemArray.Count()) |
835 else |
614 { |
836 { |
615 // no lookup items from contacts exists refering this landmark. |
837 itemArray[i].mIsDuplicate = 1; |
616 // so disassociate 'iLmContactsCatId' from this landmark |
|
617 |
|
618 existingLandmark->RemoveCategory(iLmContactsCatId); |
|
619 iLandmarkDb->UpdateLandmarkL(*existingLandmark); |
|
620 } |
838 } |
621 } |
839 } |
622 else |
840 iLocationAppLookupDb->updateEntryById( itemArray[i] ); |
623 { |
841 } |
624 // no other lookup entry is refering this landmark. |
842 } |
625 |
843 } |
626 // check if any other categories is associated with this landmark. |
|
627 // Assume this landmark is associated with a history entry or a user created landmark entry. |
|
628 // there is a chance that this landmark is still valid. |
|
629 // Do not delete the landmark in this case. |
|
630 RArray<TPosLmItemId> categoryIdArray; |
|
631 CleanupClosePushL(categoryIdArray); |
|
632 existingLandmark->GetCategoriesL(categoryIdArray); |
|
633 if (categoryIdArray.Count() == 1) |
|
634 { |
|
635 // only one category i.e, 'iLmContactsCatId' is associated. |
|
636 // delete the landmark. |
|
637 iLandmarkDb->RemoveLandmarkL(existingLandmark->LandmarkId()); |
|
638 } |
|
639 CleanupStack::PopAndDestroy(&categoryIdArray); |
|
640 } |
|
641 CleanupStack::PopAndDestroy(&itemArray); |
|
642 CleanupStack::PopAndDestroy(existingLandmark); |
|
643 |
|
644 } |
|
645 else // entry not present in lookup table |
|
646 { |
|
647 // Add the entry into the lookup table and update landmarks db. |
|
648 HandleEntryAdditionL(aLandmark, aUid, aSourceType); |
|
649 } |
|
650 } |
|
651 } |
|
652 |
|
653 // ----------------------------------------------------------------------------- |
|
654 // CMyLocationsDatabaseManager::HandleEntryDeletionL() |
|
655 // Handles the entry deletion in lookup table and landmarks db. |
|
656 // ----------------------------------------------------------------------------- |
|
657 // |
|
658 void CMyLocationsDatabaseManager::HandleEntryDeletionL(const TUint32 aUid, |
|
659 const TUint32 aSourceType) |
|
660 { |
|
661 __TRACE_CALLSTACK; |
|
662 TLookupItem lookupItem; |
|
663 lookupItem.iUid = aUid; |
|
664 lookupItem.iSource = aSourceType; |
|
665 |
|
666 if (aSourceType == ESourceContactsPref || aSourceType |
|
667 == ESourceContactsWork || aSourceType == ESourceContactsHome) |
|
668 { |
|
669 // Behavior: In the context of contacts, if a contact is deleted, the user is not interested in |
|
670 // that contact's data, hence its address as well. So, delete the corresponding entries from |
|
671 // both lookup table and iLandmarkDb. |
|
672 // Before deleting the entry from iLandmarkDb, make sure that this entry is not being refered by |
|
673 // other entries of the lookup table. If it is being refered by other entries in lookup table, then |
|
674 // do not delete the landmark. |
|
675 |
|
676 // Find the corresponding landmark uid |
|
677 if (iLandmarksLookupDb->FindEntryL(lookupItem)) |
|
678 { |
|
679 // delete the lookup entry. |
|
680 iLandmarksLookupDb->DeleteEntryL(lookupItem); |
|
681 |
|
682 // Check if any other entries are refering this landmark. |
|
683 RArray<TLookupItem> itemArray; |
|
684 CleanupClosePushL(itemArray); |
|
685 iLandmarksLookupDb->FindEntriesByLandmarkIdL(lookupItem.iLmId, |
|
686 itemArray); |
|
687 |
|
688 if (itemArray.Count()) |
|
689 { |
|
690 // There are other lookup entries refering this landmark. So do not delete the landmark |
|
691 |
|
692 // If none of these lookup item's source type is contacts, disassociate 'iLmContactsCatId' category |
|
693 // from this landmark. |
|
694 TInt i = 0; |
|
695 while (i < itemArray.Count()) |
|
696 { |
|
697 if (itemArray[i].iSource == ESourceContactsPref |
|
698 || itemArray[i].iSource == ESourceContactsWork |
|
699 || itemArray[i].iSource == ESourceContactsHome) |
|
700 { |
|
701 // a lookup item exists which is from contacts/calendar, so 'iLmContactsCatId' is still valid. |
|
702 break; |
|
703 } |
|
704 i++; |
|
705 } |
|
706 if ( i == itemArray.Count() ) |
|
707 { |
|
708 // no lookup items from contacts exists refering this landmark. |
|
709 // so disassociate 'iLmContactsCatId' from this landmark |
|
710 |
|
711 CPosLandmark* landmark = iLandmarkDb->ReadLandmarkLC( |
|
712 lookupItem.iLmId); |
|
713 landmark->RemoveCategory(iLmContactsCatId); |
|
714 iLandmarkDb->UpdateLandmarkL(*landmark); |
|
715 CleanupStack::PopAndDestroy(landmark); |
|
716 } |
|
717 } |
|
718 else |
|
719 { |
|
720 // no other lookup entry is refering this landmark. |
|
721 |
|
722 // check if any other categories is associated with this landmark. |
|
723 // Assume this landmark is associated with a history entry or a user created landmark entry. |
|
724 // there is a chance that this landmark is still valid. |
|
725 // Do not delete the landmark in this case. |
|
726 CPosLandmark* landmark = iLandmarkDb->ReadLandmarkLC( |
|
727 lookupItem.iLmId); |
|
728 RArray<TPosLmItemId> categoryIdArray; |
|
729 CleanupClosePushL(categoryIdArray); |
|
730 landmark->GetCategoriesL(categoryIdArray); |
|
731 if (categoryIdArray.Count() == 1) |
|
732 { |
|
733 // only one category i.e, 'iLmCalendarCatId' is associated. |
|
734 // delete the landmark. |
|
735 iLandmarkDb->RemoveLandmarkL(lookupItem.iLmId); |
|
736 } |
|
737 |
|
738 CleanupStack::PopAndDestroy(&categoryIdArray); |
|
739 CleanupStack::PopAndDestroy(landmark); |
|
740 } |
|
741 CleanupStack::PopAndDestroy(&itemArray); |
|
742 } |
|
743 } |
|
744 |
|
745 else if (aSourceType == ESourceLandmarks) |
|
746 { |
|
747 // Landmarks item deleted. So delete corresponding lookup entries. |
|
748 RArray<TLookupItem> itemArray; |
|
749 CleanupClosePushL(itemArray); |
|
750 iLandmarksLookupDb->FindEntriesByLandmarkIdL(aUid, itemArray); |
|
751 for (TInt i = 0; i < itemArray.Count(); i++) |
|
752 { |
|
753 iLandmarksLookupDb->DeleteEntryL(itemArray[i]); |
|
754 } |
|
755 |
|
756 CleanupStack::PopAndDestroy(&itemArray); |
|
757 |
|
758 DeleteFromMylocationsDbL(aUid, aSourceType); |
|
759 } |
|
760 } |
|
761 |
|
762 |
|
763 // ----------------------------------------------------------------------------- |
844 // ----------------------------------------------------------------------------- |
764 // CMyLocationsDatabaseManager::GetLandmarkFullAddress() |
845 // CMyLocationsDatabaseManager::GetLandmarkFullAddress() |
765 // Gets the comma separated full address of the given landmark. |
846 // Gets the comma separated full address of the given landmark. |
766 // ----------------------------------------------------------------------------- |
847 // ----------------------------------------------------------------------------- |
767 // |
848 // |
868 __TRACE_CALLSTACK; |
922 __TRACE_CALLSTACK; |
869 CPosLandmark* lm = aDb->ReadLandmarkLC(aLmId); |
923 CPosLandmark* lm = aDb->ReadLandmarkLC(aLmId); |
870 CleanupStack::Pop(lm); |
924 CleanupStack::Pop(lm); |
871 return lm; |
925 return lm; |
872 } |
926 } |
873 // ----------------------------------------------------------------------------- |
927 |
874 // CMyLocationsDatabaseManager::AddToMylocationsDbL() |
928 // ----------------------------------------------------------------------------- |
875 // Adds the entry into the mylocations database and updates the lookup table. |
929 // CMyLocationsDatabaseManager::FillLookupItemAddressDetails() |
876 // ----------------------------------------------------------------------------- |
|
877 // |
|
878 void CMyLocationsDatabaseManager::AddToMylocationsDbL(CPosLandmark* aLandmark, |
|
879 const TUint32 aUid, const TUint32 aSourceType) |
|
880 { |
|
881 __TRACE_CALLSTACK; |
|
882 if (aSourceType == ESourceLandmarks) |
|
883 { |
|
884 CPosLandmark* landmark = iLandmarkDb->ReadLandmarkLC(aUid); |
|
885 RArray<TPosLmItemId> catArray; |
|
886 CleanupClosePushL( catArray ); |
|
887 landmark->GetCategoriesL(catArray); |
|
888 |
|
889 |
|
890 // add the categories in the mylocations database for this landmark |
|
891 for (TInt i = 0; i < catArray.Count(); i++) |
|
892 { |
|
893 TLookupItem lItem; |
|
894 lItem.iUid = catArray[i]; |
|
895 lItem.iSource = ESourceLandmarksUserCat; |
|
896 lItem.iLmId = 0; |
|
897 if (!iMylocationsLookupDb->FindEntryL(lItem)) |
|
898 { |
|
899 lItem.iSource = ESourceLandmarksContactsCat; |
|
900 if (!iMylocationsLookupDb->FindEntryL(lItem)) |
|
901 { |
|
902 // means this is global category, so just add it |
|
903 lItem.iLmId = lItem.iUid; |
|
904 } |
|
905 } |
|
906 TRAP_IGNORE( aLandmark->AddCategoryL( lItem.iLmId ) ); |
|
907 } |
|
908 |
|
909 CleanupStack::PopAndDestroy( &catArray ); |
|
910 TLookupItem lookupItem; |
|
911 lookupItem.iUid = aUid; |
|
912 lookupItem.iSource = aSourceType; |
|
913 TRAP_IGNORE( lookupItem.iLmId = iMyLocationsLandmarksDb->AddLandmarkL( *aLandmark ) ); |
|
914 CleanupStack::PopAndDestroy(landmark); |
|
915 iMylocationsLookupDb->CreateEntryL(lookupItem); |
|
916 } |
|
917 } |
|
918 |
|
919 // ----------------------------------------------------------------------------- |
|
920 // CMyLocationsDatabaseManager::ModifyMylocationsDbL() |
|
921 // Adds the entry into the mylocations database and updates the lookup table. |
|
922 // ----------------------------------------------------------------------------- |
|
923 // |
|
924 void CMyLocationsDatabaseManager::ModifyMylocationsDbL(CPosLandmark* aLandmark, |
|
925 const TUint32 aUid, const TUint32 aSourceType) |
|
926 { |
|
927 __TRACE_CALLSTACK; |
|
928 TLookupItem lookupItem; |
|
929 lookupItem.iUid = aUid; |
|
930 lookupItem.iSource = aSourceType; |
|
931 iMylocationsLookupDb->FindEntryL(lookupItem); |
|
932 iMylocationsLookupDb->DeleteEntryL(lookupItem); |
|
933 iMyLocationsLandmarksDb->RemoveLandmarkL(lookupItem.iLmId); |
|
934 AddToMylocationsDbL(aLandmark, lookupItem.iUid, lookupItem.iSource); |
|
935 } |
|
936 |
|
937 // ----------------------------------------------------------------------------- |
|
938 // CMyLocationsDatabaseManager::DeleteFromMylocationsDbL() |
|
939 // Deletes the entry from the mylocations database and updates the lookup table. |
|
940 // ----------------------------------------------------------------------------- |
|
941 // |
|
942 void CMyLocationsDatabaseManager::DeleteFromMylocationsDbL(const TUint32 aUid, |
|
943 const TUint32 aSourceType) |
|
944 { |
|
945 __TRACE_CALLSTACK; |
|
946 TLookupItem lookupItem; |
|
947 lookupItem.iUid = aUid; |
|
948 lookupItem.iSource = aSourceType; |
|
949 iMylocationsLookupDb->FindEntryL(lookupItem); |
|
950 |
|
951 iMyLocationsLandmarksDb->RemoveLandmarkL(lookupItem.iLmId); |
|
952 iMylocationsLookupDb->DeleteEntryL(lookupItem); |
|
953 } |
|
954 // ----------------------------------------------------------------------------- |
|
955 // CMyLocationsDatabaseManager::CreateCategoryL() |
|
956 // Creates a new category in Mylocations Db and adds a corresponding entry in |
930 // Creates a new category in Mylocations Db and adds a corresponding entry in |
957 // mylocations lookup table. |
931 // mylocations lookup table. |
958 // ----------------------------------------------------------------------------- |
932 // ----------------------------------------------------------------------------- |
959 // |
933 // |
960 void CMyLocationsDatabaseManager::CreateCategoryL(const TUint32 aUid) |
934 void CMyLocationsDatabaseManager::FillLookupItemAddressDetails( CPosLandmark* aLandmark, QLookupItem& aLookupItem ) |
961 { |
935 { |
962 __TRACE_CALLSTACK;// Read the category. |
936 __TRACE_CALLSTACK;// Read the category. |
963 CPosLandmarkCategory *category = iLandmarksCatManager->ReadCategoryLC(aUid); |
937 |
964 |
938 // fill geo-coordinates |
965 TLookupItem lookupItem; |
939 TLocality position; |
966 lookupItem.iUid = aUid; |
940 aLandmark->GetPosition( position ); |
967 lookupItem.iSource = ESourceLandmarksUserCat; |
941 aLookupItem.mLatitude = position.Latitude(); |
968 // Add category to landmarks database |
942 aLookupItem.mLongitude = position.Longitude(); |
969 TRAPD ( err, (lookupItem.iLmId = iMyLocationsCatManager->AddCategoryL( *category ) ) ); |
943 |
970 |
944 TPtrC tempStr; |
971 if (err == KErrNone) |
945 TInt retStatus; |
972 { |
946 |
973 iMylocationsLookupDb->CreateEntryL(lookupItem); |
947 // Copy landmark name in address 1 |
974 } |
948 retStatus = aLandmark->GetLandmarkName( tempStr ); |
975 CleanupStack::PopAndDestroy(category); |
949 aLookupItem.mName = ""; |
976 |
950 if( retStatus == KErrNone && tempStr.Length() > 0 ) |
977 } |
951 { |
978 |
952 aLookupItem.mName = QString( (QChar*)tempStr.Ptr(), tempStr.Length() ); |
|
953 } |
|
954 |
|
955 // get street |
|
956 aLookupItem.mStreet = ""; |
|
957 retStatus = aLandmark->GetPositionField( EPositionFieldStreet, tempStr ); |
|
958 if( retStatus == KErrNone && tempStr.Length() ) |
|
959 { |
|
960 aLookupItem.mStreet = QString( (QChar*)tempStr.Ptr(), tempStr.Length()); |
|
961 } |
|
962 |
|
963 // get postal code |
|
964 aLookupItem.mPostalCode = ""; |
|
965 retStatus = aLandmark->GetPositionField( EPositionFieldPostalCode, tempStr ); |
|
966 if( retStatus == KErrNone && tempStr.Length() ) |
|
967 { |
|
968 aLookupItem.mPostalCode = QString( (QChar*)tempStr.Ptr(), tempStr.Length()); |
|
969 } |
|
970 |
|
971 // get city |
|
972 aLookupItem.mCity = ""; |
|
973 retStatus = aLandmark->GetPositionField( EPositionFieldCity, tempStr ); |
|
974 if( retStatus == KErrNone && tempStr.Length() ) |
|
975 { |
|
976 aLookupItem.mCity = QString( (QChar*)tempStr.Ptr(), tempStr.Length()); |
|
977 } |
|
978 |
|
979 // get State |
|
980 aLookupItem.mState = ""; |
|
981 retStatus = aLandmark->GetPositionField( EPositionFieldState, tempStr ); |
|
982 if( retStatus == KErrNone && tempStr.Length() ) |
|
983 { |
|
984 aLookupItem.mState = QString( (QChar*)tempStr.Ptr(), tempStr.Length()); |
|
985 } |
|
986 |
|
987 // get country |
|
988 aLookupItem.mCountry = ""; |
|
989 retStatus = aLandmark->GetPositionField( EPositionFieldCountry, tempStr ); |
|
990 if( retStatus == KErrNone && tempStr.Length() ) |
|
991 { |
|
992 aLookupItem.mCountry = QString( (QChar*)tempStr.Ptr(), tempStr.Length()); |
|
993 } |
|
994 } |
|
995 |
|
996 // ----------------------------------------------------------------------------- |
|
997 // CMyLocationsDatabaseManager::UnsetDuplicateNextCalEntry() |
|
998 // ----------------------------------------------------------------------------- |
|
999 // |
|
1000 void CMyLocationsDatabaseManager::UnsetDuplicateNextCalEntry( quint32 aLandmarkId ) |
|
1001 { |
|
1002 // get next duplicate item |
|
1003 QList<QLookupItem> itemArray; |
|
1004 iLocationAppLookupDb->findEntriesByLandmarkId( aLandmarkId, itemArray ); |
|
1005 for ( int i = 0; i < itemArray.count(); i++) |
|
1006 { |
|
1007 if( itemArray[i].mSourceType == ESourceCalendar ) |
|
1008 { |
|
1009 itemArray[i].mIsDuplicate = 0; |
|
1010 iLocationAppLookupDb->updateEntryById( itemArray[i] ); |
|
1011 break; |
|
1012 } |
|
1013 } |
|
1014 |
|
1015 } |
|
1016 // ----------------------------------------------------------------------------- |
|
1017 // CMyLocationsDatabaseManager::IsDuplicateEntry() |
|
1018 // ----------------------------------------------------------------------------- |
|
1019 // |
|
1020 bool CMyLocationsDatabaseManager::IsDuplicateEntry( quint32 aLandmarkId ) |
|
1021 { |
|
1022 // get next duplicate item |
|
1023 QList<QLookupItem> itemArray; |
|
1024 iLocationAppLookupDb->findEntriesByLandmarkId( aLandmarkId, itemArray ); |
|
1025 for ( int i = 0; i < itemArray.count(); i++) |
|
1026 { |
|
1027 if( itemArray[i].mSourceType == ESourceCalendar || |
|
1028 itemArray[i].mSourceType == ESourceLandmarks ) |
|
1029 { |
|
1030 return true; |
|
1031 } |
|
1032 } |
|
1033 |
|
1034 return false; |
|
1035 } |
|
1036 |
|
1037 // ----------------------------------------------------------------------------- |
|
1038 // CMyLocationsDatabaseManager::CreateLandmarkItemLC() |
|
1039 // ----------------------------------------------------------------------------- |
|
1040 // |
|
1041 CPosLandmark* CMyLocationsDatabaseManager::CreateLandmarkItemLC( const QLookupItem &aLookupItem ) |
|
1042 { |
|
1043 __TRACE_CALLSTACK;//return value |
|
1044 CPosLandmark *landmark = NULL; |
|
1045 TLocality loc( TCoordinate( aLookupItem.mLatitude, aLookupItem.mLongitude ), 0 ); |
|
1046 |
|
1047 landmark = CPosLandmark::NewL(); |
|
1048 CleanupStack::PushL( landmark ); |
|
1049 |
|
1050 // Fill the location details into the landmark object |
|
1051 landmark->SetPositionL( loc ); |
|
1052 |
|
1053 // Set the landmark name as contact name |
|
1054 TBuf<KBufSize> text( aLookupItem.mName.utf16() ); |
|
1055 TRAP_IGNORE( landmark->SetLandmarkNameL( text ) ); |
|
1056 |
|
1057 text.Copy( aLookupItem.mStreet.utf16() ); |
|
1058 landmark->SetPositionFieldL( EPositionFieldStreet, text ); |
|
1059 |
|
1060 // Set the City |
|
1061 text.Copy( aLookupItem.mCity.utf16() ); |
|
1062 landmark->SetPositionFieldL( EPositionFieldCity, text ); |
|
1063 |
|
1064 // Set the state/region |
|
1065 text.Copy( aLookupItem.mState.utf16() ); |
|
1066 landmark->SetPositionFieldL( EPositionFieldState, text ); |
|
1067 |
|
1068 // Set the Postal code |
|
1069 text.Copy( aLookupItem.mPostalCode.utf16() ); |
|
1070 landmark->SetPositionFieldL( EPositionFieldPostalCode, text ); |
|
1071 |
|
1072 // Set the country |
|
1073 text.Copy( aLookupItem.mCountry.utf16() ); |
|
1074 landmark->SetPositionFieldL( EPositionFieldCountry, text ); |
|
1075 |
|
1076 return landmark; |
|
1077 } |
|
1078 |
|
1079 // ----------------------------------------------------------------------------- |
|
1080 // CMyLocationsDatabaseManager::UpdateMapTilePath() |
|
1081 // ----------------------------------------------------------------------------- |
|
1082 // |
|
1083 void CMyLocationsDatabaseManager::UpdateMapTilePath( TUint32 aSourceId, TUint32 aSourceType, |
|
1084 TFileName aFilePath ) |
|
1085 { |
|
1086 QString filePath = QString( (QChar*)aFilePath.Ptr(), aFilePath.Length() ); |
|
1087 iLocationAppLookupDb->updateMaptileBySourceIdAndType( aSourceId, aSourceType, filePath ); |
|
1088 } |
979 |
1089 |
980 // End of file |
1090 // End of file |