|
1 /* |
|
2 * Copyright (c) 2010 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: Mylocation engine source implementation for location picker |
|
15 * and maptile service. |
|
16 * |
|
17 */ |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <f32file.h> |
|
21 #include <calchangecallback.h> |
|
22 #include <cntitem.h> |
|
23 #include <CNTFLDST.H> |
|
24 #include <EPos_CPosLmDatabaseManager.h> |
|
25 #include <lbsposition.h> |
|
26 #include <bautils.h> |
|
27 #include <f32file.h> |
|
28 #include "mylocationsengine.h" |
|
29 #include "mylocationsdefines.h" |
|
30 #include "geocodeupdate.h" //header for CGeocodeUpdate class |
|
31 //handle for CMyLocationsHistoryDbObserver class |
|
32 #include "mylocationlogger.h" |
|
33 #if ( defined __WINSCW__ ) || ( defined __WINS__ ) |
|
34 _LIT ( KImageStorageDrive, "C:\\Maptile\\"); |
|
35 #endif |
|
36 _LIT(KFolderName,":\\MapTile\\"); |
|
37 const TInt KImagePathSize=36; |
|
38 const TInt KBufSize=256; |
|
39 const TInt KDefaultFilePathSize = 20; |
|
40 |
|
41 // separator |
|
42 _LIT( KSeparator, ","); |
|
43 _LIT(KContactPrefered, "Contact Prefered"); |
|
44 _LIT(KContactHome, "Contact Home"); |
|
45 _LIT(KContactWork, "Contact Work"); |
|
46 _LIT(KPNGType, ".png"); |
|
47 _LIT(KSingleSpace, " "); |
|
48 |
|
49 // ============================ MEMBER FUNCTIONS =============================== |
|
50 |
|
51 CMyLocationsEngine* CMyLocationsEngine::NewL() |
|
52 { |
|
53 CMyLocationsEngine* self = new (ELeave) CMyLocationsEngine(); |
|
54 CleanupStack::PushL(self); |
|
55 self->ConstructL(); |
|
56 CleanupStack::Pop(self); |
|
57 return self; |
|
58 } |
|
59 |
|
60 // ----------------------------------------------------------------------------- |
|
61 // CMyLocationsEngine::ConstructL() |
|
62 // Symbian 2nd phase constructor can leave. |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 void CMyLocationsEngine::ConstructL() |
|
66 { |
|
67 __TRACE_CALLSTACK; |
|
68 CActiveScheduler::Add(this); |
|
69 |
|
70 |
|
71 |
|
72 //Connection to Landmark DB |
|
73 iLandmarkDb = CPosLandmarkDatabase::OpenL(); |
|
74 ExecuteAndDeleteLD(iLandmarkDb->InitializeL()); |
|
75 |
|
76 MYLOCLOGSTRING("Connection to Landmark DB."); |
|
77 // create CMyLocationsDatabaseManager instance |
|
78 iMyLocationsDatabaseManager = new (ELeave) CMyLocationsDatabaseManager; |
|
79 iMyLocationsDatabaseManager->ConstructL(); |
|
80 |
|
81 MYLOCLOGSTRING("create CMyLocationsDatabaseManager instance"); |
|
82 |
|
83 TRAPD( error , iMapTileInterface = CMapTileInterface::NewL()); |
|
84 if( error == KErrNone ) |
|
85 { |
|
86 iMaptileGeocoderPluginAvailable = ETrue; |
|
87 } |
|
88 |
|
89 MYLOCLOGSTRING("iMapTileInterface = CMapTileInterface::NewL()"); |
|
90 //Maptile Db instance |
|
91 iMaptileDatabase = CLookupMapTileDatabase::NewL(KMapTileLookupDatabaseName); |
|
92 |
|
93 MYLOCLOGSTRING("Maptile Db instance created "); |
|
94 |
|
95 iAddressCompare = CAddressComparision::NewL(); |
|
96 |
|
97 MYLOCLOGSTRING(" start contact db observation "); |
|
98 StartContactsChangeNotifierL(); |
|
99 MYLOCLOGSTRING(" start landmark db observation "); |
|
100 StartLandmarksChangeNotifier(); |
|
101 |
|
102 //set the folder path to store maptile |
|
103 imageFilePath.Zero(); |
|
104 SetFolderPathL(); |
|
105 |
|
106 TInt status; |
|
107 iCalSession = CCalSession::NewL(); |
|
108 NotifyChangeL(status); |
|
109 |
|
110 } |
|
111 // ----------------------------------------------------------------------------- |
|
112 // CMyLocationsEngine::SetFolderPath() |
|
113 // set folder path structure |
|
114 // ----------------------------------------------------------------------------- |
|
115 // |
|
116 void CMyLocationsEngine::SetFolderPathL() |
|
117 { |
|
118 __TRACE_CALLSTACK; |
|
119 RFs session; |
|
120 User::LeaveIfError(session.Connect()); |
|
121 if ( imageFilePath.Length() > 0 && BaflUtils::FolderExists(session, imageFilePath)) |
|
122 { |
|
123 session.Close(); |
|
124 MYLOCLOGSTRING("Image folder path exists"); |
|
125 return; |
|
126 } |
|
127 const TUint EMediaMemoryCard = 0x000014; |
|
128 imageFilePath.Zero(); |
|
129 #if ( defined __WINSCW__ ) || ( defined __WINS__ ) |
|
130 imageFilePath.Copy(KImageStorageDrive); |
|
131 MYLOCLOGSTRING("using in debug mode"); |
|
132 #else |
|
133 TVolumeInfo vol; |
|
134 TInt driveNumber = EDriveE; |
|
135 TChar driveLetter; |
|
136 TDriveInfo driveInfo; |
|
137 TInt error( KErrNone ); |
|
138 error=session.Volume(vol, driveNumber); |
|
139 MYLOCLOGSTRING1("E drive volume info status -%d",error); |
|
140 if (error == KErrNone) |
|
141 { |
|
142 error = session.Drive(driveInfo, driveNumber); |
|
143 MYLOCLOGSTRING1("E driveinfo status -%d",error); |
|
144 switch(driveInfo.iType) |
|
145 { |
|
146 case EMediaFlash: |
|
147 case EMediaHardDisk: |
|
148 case EMediaNANDFlash: |
|
149 case EMediaMemoryCard: |
|
150 case EMediaCdRom: |
|
151 { |
|
152 MYLOCLOGSTRING(" E drive match case"); |
|
153 session.DriveToChar( driveNumber , driveLetter ); |
|
154 imageFilePath.Append(driveLetter); |
|
155 imageFilePath.Append(KFolderName); |
|
156 break; |
|
157 } |
|
158 default: |
|
159 break; |
|
160 |
|
161 }; |
|
162 } |
|
163 |
|
164 if (!imageFilePath.Length() > 0) |
|
165 { |
|
166 driveNumber = EDriveF; |
|
167 error = session.Volume(vol, driveNumber); |
|
168 MYLOCLOGSTRING1("F drive volume info status -%d",error); |
|
169 |
|
170 if (error == KErrNone) |
|
171 { |
|
172 error = session.Drive(driveInfo, driveNumber); |
|
173 MYLOCLOGSTRING1("F drive info status-%d", error); |
|
174 |
|
175 switch (driveInfo.iMediaAtt) |
|
176 { |
|
177 /** Solid-state media. */ |
|
178 case EMediaFlash: |
|
179 case EMediaHardDisk: |
|
180 case EMediaNANDFlash: |
|
181 case EMediaMemoryCard: |
|
182 { |
|
183 MYLOCLOGSTRING("F drive exist as this type"); |
|
184 session.DriveToChar(driveNumber, driveLetter); |
|
185 imageFilePath.Append(driveLetter); |
|
186 imageFilePath.Append(KFolderName); |
|
187 break; |
|
188 } |
|
189 |
|
190 default: |
|
191 break; |
|
192 |
|
193 }; |
|
194 } |
|
195 } |
|
196 #endif |
|
197 if (imageFilePath.Length()>0 && !BaflUtils::FolderExists(session, imageFilePath)) |
|
198 { |
|
199 session.MkDirAll(imageFilePath); |
|
200 MYLOCLOGSTRING("folder path does not exist , created "); |
|
201 } |
|
202 session.Close(); |
|
203 } |
|
204 // ----------------------------------------------------------------------------- |
|
205 // CMyLocationsEngine::CMyLocationsEngine() |
|
206 // C++ default constructor can NOT contain any code, that might leave. |
|
207 // ----------------------------------------------------------------------------- |
|
208 // |
|
209 CMyLocationsEngine::CMyLocationsEngine() : |
|
210 CActive(EPriorityStandard), iCalSession(NULL), iCalView(NULL), iContactsDb( |
|
211 NULL), iContactChangeNotifier(NULL), iLandmarkDb(NULL), |
|
212 iMapTileInterface(NULL), iMyLocationsDatabaseManager(NULL), |
|
213 iMaptileDatabase(NULL), iAddressCompare(NULL), |
|
214 iMaptileGeocoderPluginAvailable(EFalse),iCalenderNotification(NULL) |
|
215 { |
|
216 |
|
217 } |
|
218 |
|
219 // ----------------------------------------------------------------------------- |
|
220 // CMyLocationsEngine::~CMyLocationsEngine() |
|
221 // Destructor. |
|
222 // ----------------------------------------------------------------------------- |
|
223 // |
|
224 CMyLocationsEngine::~CMyLocationsEngine() |
|
225 { |
|
226 __TRACE_CALLSTACK;// delete the member variables. |
|
227 |
|
228 delete iContactChangeNotifier; |
|
229 |
|
230 delete iMyLocationsDatabaseManager; |
|
231 |
|
232 delete iLandmarkDb; |
|
233 |
|
234 delete iContactsDb; |
|
235 |
|
236 delete iCalView; |
|
237 |
|
238 delete iCalSession; |
|
239 |
|
240 delete iMapTileInterface; |
|
241 |
|
242 delete iMaptileDatabase; |
|
243 |
|
244 delete iAddressCompare; |
|
245 |
|
246 delete iCalenderNotification; |
|
247 |
|
248 } |
|
249 |
|
250 // ----------------------------------------------------------------------------- |
|
251 // CMyLocationsEngine::NotifyChangeL() |
|
252 // Starts calender db create notification to get callbacks. |
|
253 // ----------------------------------------------------------------------------- |
|
254 // |
|
255 void CMyLocationsEngine::NotifyChangeL(TInt &aStatus) |
|
256 { |
|
257 __TRACE_CALLSTACK; |
|
258 |
|
259 TBufC<KDefaultFilePathSize> defaultFile = iCalSession->DefaultFileNameL(); |
|
260 TChar drive = defaultFile[0]; |
|
261 |
|
262 TRAP(aStatus, iCalSession->OpenL( defaultFile )); |
|
263 MYLOCLOGSTRING1("iCalSession->OpenL() status-%d",aStatus); |
|
264 if ( KErrNone == aStatus ) |
|
265 { |
|
266 // create a calendar entry view with the opened session |
|
267 iCalView = CCalEntryView::NewL(*iCalSession); |
|
268 StartCalenderChangeNotifierL(); |
|
269 } |
|
270 else |
|
271 { |
|
272 if( !iCalenderNotification ) |
|
273 { |
|
274 iCalenderNotification = CCalenderNotification::NewL( this ); |
|
275 } |
|
276 |
|
277 |
|
278 iCalenderNotification->CheckCalenderDbFileStructure( drive ); |
|
279 } |
|
280 } |
|
281 // ----------------------------------------------------------------------------- |
|
282 // CMyLocationsEngine::StartCalenderChangeNotifierL() |
|
283 // Starts calender change notification method to get callbacks when entries are |
|
284 // added/modified/deleted in contacts |
|
285 // ----------------------------------------------------------------------------- |
|
286 // |
|
287 void CMyLocationsEngine::StartCalenderChangeNotifierL() |
|
288 { |
|
289 __TRACE_CALLSTACK;// Get the current time and set Calendar filter to consider entries whose start time |
|
290 // fall under the timeframe one year past and one year ahead of the current time. |
|
291 if (iCalSession) |
|
292 { |
|
293 MYLOCLOGSTRING("iCalSession is not null"); |
|
294 TTime currentTime; |
|
295 currentTime.HomeTime(); |
|
296 |
|
297 TTime startTime = currentTime - TTimeIntervalYears(1); |
|
298 TTime endTime = currentTime + TTimeIntervalYears(1); |
|
299 |
|
300 TCalTime calStartTime; |
|
301 calStartTime.SetTimeLocalL(startTime); |
|
302 |
|
303 MYLOCLOGSTRING("SetTimeLocalL(startTime)"); |
|
304 |
|
305 TCalTime calEndTime; |
|
306 calEndTime.SetTimeLocalL(endTime); |
|
307 |
|
308 MYLOCLOGSTRING("SetTimeLocalL(endTime)"); |
|
309 |
|
310 // set the filter for modification tracking |
|
311 CCalChangeNotificationFilter *filter = |
|
312 CCalChangeNotificationFilter::NewL( |
|
313 MCalChangeCallBack2::EChangeEntryAll, ETrue, |
|
314 CalCommon::TCalTimeRange(calStartTime, calEndTime)); |
|
315 MYLOCLOGSTRING(" CCalChangeNotificationFilter::NewL()"); |
|
316 // 'this' object implements MCalChangeCallBack |
|
317 iCalSession->StartChangeNotification(*this, *filter); |
|
318 } |
|
319 } |
|
320 |
|
321 // ----------------------------------------------------------------------------- |
|
322 // CMyLocationsEngine::StartContactsChangeNotifierL() |
|
323 // Starts contacts change notification method to get callbacks when entries are |
|
324 // added/modified/deleted in contacts |
|
325 // ----------------------------------------------------------------------------- |
|
326 // |
|
327 void CMyLocationsEngine::StartContactsChangeNotifierL() |
|
328 { |
|
329 __TRACE_CALLSTACK; |
|
330 |
|
331 GeocodeUpdate::CreateContactdb(); |
|
332 iContactsDb = CContactDatabase::OpenL(); |
|
333 // Create CContactChangeNotifier object with 'this' object. |
|
334 iContactChangeNotifier = CContactChangeNotifier::NewL(*iContactsDb,this); |
|
335 } |
|
336 |
|
337 // ----------------------------------------------------------------------------- |
|
338 // CMyLocationsEngine::StartLandmarksChangeNotifier() |
|
339 // Starts landmarks change notification method to get callbacks when entries are added/modified/deleted in landmarks |
|
340 // ----------------------------------------------------------------------------- |
|
341 // |
|
342 void CMyLocationsEngine::StartLandmarksChangeNotifier() |
|
343 { |
|
344 __TRACE_CALLSTACK;// Resume event listening |
|
345 iLandmarkDb->NotifyDatabaseEvent(iLmEvent, iStatus); |
|
346 SetActive(); |
|
347 } |
|
348 |
|
349 |
|
350 // ----------------------------------------------------------------------------- |
|
351 // CMyLocationsEngine::CalChangeNotification() |
|
352 // Callback when there is a change in the calendar database. |
|
353 // ----------------------------------------------------------------------------- |
|
354 // |
|
355 |
|
356 void CMyLocationsEngine::CalChangeNotification( |
|
357 RArray<TCalChangeEntry>& aChangeItems) |
|
358 { |
|
359 __TRACE_CALLSTACK; |
|
360 |
|
361 if(iCalenderNotification) |
|
362 { |
|
363 delete iCalenderNotification; |
|
364 iCalenderNotification = NULL; |
|
365 } |
|
366 |
|
367 // get entries associated with this UID |
|
368 for (int i = 0; i < aChangeItems.Count(); i++) |
|
369 { |
|
370 |
|
371 TCalChangeEntry calChangeEntry = aChangeItems[i]; |
|
372 iEventType = calChangeEntry.iChangeType; |
|
373 switch (calChangeEntry.iChangeType) |
|
374 { |
|
375 case EChangeAdd: |
|
376 { |
|
377 |
|
378 TRAP_IGNORE(CalenderEntryAddedL(calChangeEntry)); |
|
379 break; |
|
380 } |
|
381 |
|
382 case EChangeModify: |
|
383 { |
|
384 |
|
385 TLookupItem lookupItem; |
|
386 lookupItem.iSource = ESourceCalendar; |
|
387 lookupItem.iUid = calChangeEntry.iEntryId; |
|
388 //TODO: comapare address and then delete |
|
389 TRAP_IGNORE( iMaptileDatabase->DeleteEntryL(lookupItem) ); |
|
390 TRAP_IGNORE( CalenderEntryAddedL(calChangeEntry) ); |
|
391 break; |
|
392 } |
|
393 case EChangeDelete: |
|
394 { |
|
395 TLookupItem lookupItem; |
|
396 lookupItem.iSource = ESourceCalendar; |
|
397 lookupItem.iUid = calChangeEntry.iEntryId; |
|
398 TRAP_IGNORE( iMaptileDatabase->DeleteEntryL(lookupItem)); |
|
399 break; |
|
400 } |
|
401 }; |
|
402 |
|
403 } |
|
404 } |
|
405 |
|
406 void CMyLocationsEngine::CalenderEntryAddedL(TCalChangeEntry aCalChangeEntry) |
|
407 { |
|
408 __TRACE_CALLSTACK; |
|
409 CCalEntry* calEntry = NULL; |
|
410 calEntry = iCalView->FetchL(aCalChangeEntry.iEntryId); |
|
411 TPtrC address(calEntry->LocationL()); |
|
412 if(address.Length()>0) |
|
413 { |
|
414 RequestMapTileImageL(address,ESourceCalendar, aCalChangeEntry.iEntryId); |
|
415 } |
|
416 delete calEntry; |
|
417 } |
|
418 |
|
419 // ----------------------------------------------------------------------------- |
|
420 // CMyLocationsEngine::HandleDatabaseEventL() |
|
421 // Callback that provides information about the contact database change event. |
|
422 // ----------------------------------------------------------------------------- |
|
423 // |
|
424 void CMyLocationsEngine::HandleDatabaseEventL(TContactDbObserverEvent aEvent) |
|
425 { |
|
426 __TRACE_CALLSTACK; |
|
427 |
|
428 HandlelandmarkDatabaseL(aEvent); |
|
429 |
|
430 //Forward the event for maptile fetching only if maptile plugin available |
|
431 if( iMaptileGeocoderPluginAvailable ) |
|
432 { |
|
433 TriggerMaptileRequestL(aEvent); |
|
434 } |
|
435 |
|
436 } |
|
437 |
|
438 // ----------------------------------------------------------------------------- |
|
439 // CMyLocationsEngine::HandlelandmarkDatabaseL() |
|
440 // Process the contact database event and updates the landmark database |
|
441 // ----------------------------------------------------------------------------- |
|
442 // |
|
443 void CMyLocationsEngine::HandlelandmarkDatabaseL( |
|
444 TContactDbObserverEvent& aEvent) |
|
445 { |
|
446 __TRACE_CALLSTACK;// If contact is modified or added, update the mylocations db |
|
447 if (aEvent.iType == EContactDbObserverEventContactChanged || aEvent.iType |
|
448 == EContactDbObserverEventContactAdded) |
|
449 { |
|
450 //Get the contact item |
|
451 CContactItem* contactItem = |
|
452 iContactsDb->ReadContactL(aEvent.iContactId); |
|
453 |
|
454 if (contactItem) |
|
455 { |
|
456 CleanupStack::PushL(contactItem); |
|
457 |
|
458 // Get the default/prefered address details |
|
459 CPosLandmark *preferedAddressLm = GetContactLocationDetailsLC( |
|
460 contactItem, EAddressPref); |
|
461 |
|
462 // Get the work address details |
|
463 CPosLandmark *workAddressLm = GetContactLocationDetailsLC( |
|
464 contactItem, EAddressWork); |
|
465 |
|
466 // Get the home address details |
|
467 CPosLandmark *homeAddressLm = GetContactLocationDetailsLC( |
|
468 contactItem, EAddressHome); |
|
469 |
|
470 // if the contact item has no validated address (preferef, home or work) |
|
471 if (!preferedAddressLm && !workAddressLm && !homeAddressLm) |
|
472 { |
|
473 if (aEvent.iType == EContactDbObserverEventContactChanged) |
|
474 { |
|
475 // If the contact is a modified one and it might already exist in |
|
476 // mylocations db, so delete it |
|
477 iMyLocationsDatabaseManager->UpdateDatabaseL(NULL, |
|
478 aEvent.iContactId, ESourceContactsPref, |
|
479 EEntryDeleted); |
|
480 iMyLocationsDatabaseManager->UpdateDatabaseL(NULL, |
|
481 aEvent.iContactId, ESourceContactsWork, |
|
482 EEntryDeleted); |
|
483 iMyLocationsDatabaseManager->UpdateDatabaseL(NULL, |
|
484 aEvent.iContactId, ESourceContactsHome, |
|
485 EEntryDeleted); |
|
486 } |
|
487 } |
|
488 else |
|
489 { |
|
490 // There is atleast one valid address present. |
|
491 |
|
492 // Get the TEntryChangeType for contacts. |
|
493 TEntryChangeType changeType = MapChangeType( |
|
494 ESourceContactsPref, aEvent.iType); |
|
495 |
|
496 // if home address available, update Mylocations. |
|
497 if (homeAddressLm) |
|
498 { |
|
499 iMyLocationsDatabaseManager->UpdateDatabaseL(homeAddressLm, |
|
500 aEvent.iContactId, ESourceContactsHome, changeType); |
|
501 CleanupStack::PopAndDestroy(homeAddressLm); |
|
502 } |
|
503 |
|
504 // if work address available, update Mylocations. |
|
505 if (workAddressLm) |
|
506 { |
|
507 iMyLocationsDatabaseManager->UpdateDatabaseL(workAddressLm, |
|
508 aEvent.iContactId, ESourceContactsWork, changeType); |
|
509 CleanupStack::PopAndDestroy(workAddressLm); |
|
510 } |
|
511 |
|
512 // if prefered address available, update Mylocations. |
|
513 if (preferedAddressLm) |
|
514 { |
|
515 iMyLocationsDatabaseManager->UpdateDatabaseL( |
|
516 preferedAddressLm, aEvent.iContactId, |
|
517 ESourceContactsPref, changeType); |
|
518 CleanupStack::PopAndDestroy(preferedAddressLm); |
|
519 } |
|
520 |
|
521 } |
|
522 |
|
523 // Pop and destroy the contactItem |
|
524 CleanupStack::PopAndDestroy(contactItem); |
|
525 } |
|
526 } |
|
527 else if (aEvent.iType == EContactDbObserverEventContactDeleted) |
|
528 { |
|
529 // the contact is deleted, so delete the corresponding entries from database. |
|
530 |
|
531 // delete prefered address in database |
|
532 iMyLocationsDatabaseManager->UpdateDatabaseL(NULL, aEvent.iContactId, |
|
533 ESourceContactsPref, EEntryDeleted); |
|
534 |
|
535 // delete work address in database |
|
536 iMyLocationsDatabaseManager->UpdateDatabaseL(NULL, aEvent.iContactId, |
|
537 ESourceContactsWork, EEntryDeleted); |
|
538 |
|
539 // delete home address in database |
|
540 iMyLocationsDatabaseManager->UpdateDatabaseL(NULL, aEvent.iContactId, |
|
541 ESourceContactsHome, EEntryDeleted); |
|
542 } |
|
543 } |
|
544 |
|
545 // ----------------------------------------------------------------------------- |
|
546 // CMyLocationsEngine::TriggerMaptileRequestL() |
|
547 // Callback that provides information about the contact database change event. |
|
548 // ----------------------------------------------------------------------------- |
|
549 // |
|
550 |
|
551 void CMyLocationsEngine::TriggerMaptileRequestL(TContactDbObserverEvent& aEvent) |
|
552 { |
|
553 __TRACE_CALLSTACK; |
|
554 TLookupItem lookupItem; |
|
555 lookupItem.iUid = aEvent.iContactId; |
|
556 // If contact is deleted delete from mylocations db |
|
557 /* if (aEvent.iType == EContactDbObserverEventContactDeleted) |
|
558 { |
|
559 MYLOCLOGSTRING("EContactDbObserverEventContactDeleted" ); |
|
560 // delete prefered address in database |
|
561 lookupItem.iSource = ESourceContactsPref; |
|
562 FindEntryAndDeleteL(lookupItem); |
|
563 |
|
564 lookupItem.iSource = ESourceContactsWork; |
|
565 FindEntryAndDeleteL(lookupItem); |
|
566 |
|
567 lookupItem.iSource = ESourceContactsHome; |
|
568 FindEntryAndDeleteL(lookupItem); |
|
569 }*/ |
|
570 |
|
571 //Get the contact item |
|
572 iEventType = aEvent.iType; |
|
573 CContactItem* contactItem = iContactsDb->ReadContactL(aEvent.iContactId); |
|
574 CleanupStack::PushL(contactItem); |
|
575 |
|
576 CPosLandmark *preferedAddressLm = NULL; |
|
577 CPosLandmark *workAddressLm = NULL; |
|
578 CPosLandmark *homeAddressLm = NULL; |
|
579 |
|
580 // If contact is modified or added, update the mylocations db |
|
581 /* if (contactItem) |
|
582 { |
|
583 CleanupStack::PushL(contactItem); |
|
584 */ |
|
585 // Get the home address details |
|
586 homeAddressLm = GetContactAddressDetailsLC(contactItem, EAddressHome); |
|
587 |
|
588 // Get the work address details |
|
589 workAddressLm = GetContactAddressDetailsLC(contactItem, EAddressWork); |
|
590 |
|
591 // Get the default/prefered address details |
|
592 preferedAddressLm = GetContactAddressDetailsLC(contactItem, EAddressPref); |
|
593 |
|
594 // iContactUid = aEvent.iContactId; |
|
595 switch (aEvent.iType) |
|
596 { |
|
597 case EContactDbObserverEventContactChanged: |
|
598 { |
|
599 MYLOCLOGSTRING("EContactDbObserverEventContactChanged" );MYLOCLOGSTRING1("iMapTileRequestQueue.Count()-%d",iMapTileRequestQueue.Count() ); |
|
600 |
|
601 if (iMapTileRequestQueue.Count() > 0) |
|
602 { |
|
603 if (iMapTileRequestQueue[0]->iUId == aEvent.iContactId) |
|
604 { |
|
605 if (preferedAddressLm) |
|
606 { |
|
607 CleanupStack::PopAndDestroy(preferedAddressLm); |
|
608 } |
|
609 if (workAddressLm) |
|
610 { |
|
611 CleanupStack::PopAndDestroy(workAddressLm); |
|
612 } |
|
613 if (homeAddressLm) |
|
614 { |
|
615 CleanupStack::PopAndDestroy(homeAddressLm); |
|
616 } |
|
617 |
|
618 CleanupStack::PopAndDestroy(contactItem); |
|
619 MYLOCLOGSTRING("retrun from geolocation callback" ); |
|
620 return; |
|
621 } |
|
622 } |
|
623 /* |
|
624 // if the contact item has no validated address (preferef, home or work) |
|
625 if (!preferedAddressLm && !workAddressLm && !homeAddressLm) |
|
626 { |
|
627 MYLOCLOGSTRING("Contact changed no address" ); |
|
628 //Delete the entries from maptile lookup table |
|
629 lookupItem.iSource = ESourceContactsPref; |
|
630 iMaptileDatabase->DeleteEntryL(lookupItem); |
|
631 |
|
632 lookupItem.iSource = ESourceContactsWork; |
|
633 iMaptileDatabase->DeleteEntryL(lookupItem); |
|
634 |
|
635 lookupItem.iSource = ESourceContactsHome; |
|
636 iMaptileDatabase->DeleteEntryL(lookupItem); |
|
637 |
|
638 }*/ |
|
639 /* else |
|
640 {*/ |
|
641 MYLOCLOGSTRING("Contact address changed" ); |
|
642 |
|
643 // if default address available, update Mylocations. |
|
644 lookupItem.iSource = ESourceContactsPref; |
|
645 if (preferedAddressLm) |
|
646 { |
|
647 MYLOCLOGSTRING("preferedAddressLm address changed" ); |
|
648 |
|
649 if (iAddressCompare->IsAddressChangedL(*preferedAddressLm, |
|
650 aEvent.iContactId, ESourceContactsPref)) |
|
651 |
|
652 { |
|
653 //remove entry from database |
|
654 iMaptileDatabase->DeleteEntryL(lookupItem); |
|
655 RequestMapTileImageL(*preferedAddressLm, ESourceContactsPref, |
|
656 aEvent.iContactId); |
|
657 } |
|
658 |
|
659 CleanupStack::PopAndDestroy(preferedAddressLm); |
|
660 |
|
661 } |
|
662 else |
|
663 { |
|
664 iMaptileDatabase->DeleteEntryL(lookupItem); |
|
665 } |
|
666 |
|
667 // if work address available, update Mylocations. |
|
668 lookupItem.iSource = ESourceContactsWork; |
|
669 if (workAddressLm) |
|
670 { |
|
671 MYLOCLOGSTRING("workAddressLm address changed" ); |
|
672 if (iAddressCompare->IsAddressChangedL(*workAddressLm, |
|
673 aEvent.iContactId, ESourceContactsWork)) |
|
674 //remove entry from database |
|
675 { |
|
676 iMaptileDatabase->DeleteEntryL(lookupItem); |
|
677 RequestMapTileImageL(*workAddressLm, ESourceContactsWork, |
|
678 aEvent.iContactId); |
|
679 } |
|
680 |
|
681 CleanupStack::PopAndDestroy(workAddressLm); |
|
682 |
|
683 } |
|
684 else |
|
685 { |
|
686 iMaptileDatabase->DeleteEntryL(lookupItem); |
|
687 } |
|
688 |
|
689 // if home address available, update Mylocations. |
|
690 lookupItem.iSource = ESourceContactsHome; |
|
691 if (homeAddressLm) |
|
692 { |
|
693 MYLOCLOGSTRING("homeAddressLm address changed" ); |
|
694 |
|
695 if (iAddressCompare->IsAddressChangedL(*homeAddressLm, |
|
696 aEvent.iContactId, ESourceContactsHome)) |
|
697 |
|
698 { |
|
699 //remove entry from databse |
|
700 iMaptileDatabase->DeleteEntryL(lookupItem); |
|
701 RequestMapTileImageL(*homeAddressLm, ESourceContactsHome, |
|
702 aEvent.iContactId); |
|
703 } |
|
704 CleanupStack::PopAndDestroy(homeAddressLm); |
|
705 } |
|
706 else |
|
707 { |
|
708 iMaptileDatabase->DeleteEntryL(lookupItem); |
|
709 } |
|
710 // } |
|
711 break; |
|
712 } |
|
713 case EContactDbObserverEventContactDeleted: |
|
714 { |
|
715 |
|
716 lookupItem.iSource = ESourceContactsPref; |
|
717 iMaptileDatabase->DeleteEntryL(lookupItem); |
|
718 |
|
719 lookupItem.iSource = ESourceContactsWork; |
|
720 iMaptileDatabase->DeleteEntryL(lookupItem); |
|
721 |
|
722 lookupItem.iSource = ESourceContactsHome; |
|
723 iMaptileDatabase->DeleteEntryL(lookupItem); |
|
724 |
|
725 MYLOCLOGSTRING("EContactDbObserverEventContactDeleted "); |
|
726 /* // the contact is deleted, so delete the corresponding entries from database. |
|
727 TLookupItem lookupItem; |
|
728 lookupItem.iUid = aEvent.iContactId; |
|
729 iMaptileDatabase->DeleteEntryL(lookupItem);*/ |
|
730 break; |
|
731 } |
|
732 case EContactDbObserverEventContactAdded: |
|
733 { |
|
734 MYLOCLOGSTRING("EContactDbObserverEventContactAdded" ); |
|
735 if (preferedAddressLm) |
|
736 { |
|
737 RequestMapTileImageL(*preferedAddressLm, ESourceContactsPref, |
|
738 aEvent.iContactId); |
|
739 CleanupStack::PopAndDestroy(preferedAddressLm); |
|
740 } |
|
741 if (workAddressLm) |
|
742 { |
|
743 RequestMapTileImageL(*workAddressLm, ESourceContactsWork, |
|
744 aEvent.iContactId); |
|
745 CleanupStack::PopAndDestroy(workAddressLm); |
|
746 } |
|
747 if (homeAddressLm) |
|
748 { |
|
749 RequestMapTileImageL(*homeAddressLm, ESourceContactsHome, |
|
750 aEvent.iContactId); |
|
751 CleanupStack::PopAndDestroy(homeAddressLm); |
|
752 } |
|
753 break; |
|
754 } |
|
755 |
|
756 }; |
|
757 CleanupStack::PopAndDestroy(contactItem); |
|
758 //} |
|
759 |
|
760 } |
|
761 |
|
762 void CMyLocationsEngine::RequestMapTileImageL(const TDesC& aAddressDetails, |
|
763 const TUidSourceType aAddressType, const TInt32 aUId) |
|
764 { |
|
765 __TRACE_CALLSTACK; |
|
766 SetFolderPathL(); |
|
767 TBuf<KImagePathSize> mImagePath; |
|
768 |
|
769 //mImagePath.Append(KImageStorageDrive); |
|
770 mImagePath.Copy(imageFilePath); |
|
771 mImagePath.AppendNum(aUId); |
|
772 mImagePath.AppendNum(aAddressType); |
|
773 mImagePath.Append(KPNGType); |
|
774 |
|
775 CMapTileRequest* mapTileRequest = new (ELeave) CMapTileRequest; |
|
776 |
|
777 mapTileRequest->iAddressDetails = aAddressDetails.AllocL(); |
|
778 mapTileRequest->iUId = aUId; |
|
779 mapTileRequest->iAddressType = aAddressType; |
|
780 mapTileRequest->iEventType = iEventType; |
|
781 mapTileRequest->iImagePath.Zero(); |
|
782 mapTileRequest->iImagePath.Copy(mImagePath); |
|
783 if (iMapTileRequestQueue.Count() <= 0) |
|
784 { |
|
785 if ( KErrNone == RequestExecute(mapTileRequest) ) |
|
786 { |
|
787 iMapTileRequestQueue.Append(mapTileRequest); |
|
788 } |
|
789 else |
|
790 { |
|
791 delete mapTileRequest; |
|
792 } |
|
793 } |
|
794 else |
|
795 { |
|
796 MYLOCLOGSTRING("Added one more request to request queue" ); |
|
797 iMapTileRequestQueue.Append(mapTileRequest); |
|
798 } |
|
799 } |
|
800 // ----------------------------------------------------------------------------- |
|
801 // CMyLocationsEngine::RequestMapTileImageL() |
|
802 // Request to get maptiel |
|
803 // ----------------------------------------------------------------------------- |
|
804 // |
|
805 void CMyLocationsEngine::RequestMapTileImageL(CPosLandmark& aLandmark, |
|
806 const TUidSourceType aAddressType, const TInt32 aUId) |
|
807 { |
|
808 __TRACE_CALLSTACK; |
|
809 |
|
810 MYLOCLOGSTRING("check folder path existance!"); |
|
811 SetFolderPathL(); |
|
812 TBuf<KImagePathSize> mImagePath; |
|
813 |
|
814 //mImagePath.Append(KImageStorageDrive); |
|
815 mImagePath.Copy(imageFilePath); |
|
816 mImagePath.AppendNum(aUId); |
|
817 mImagePath.AppendNum(aAddressType); |
|
818 mImagePath.Append(KPNGType); |
|
819 |
|
820 CMapTileRequest* mapTileRequest = new (ELeave) CMapTileRequest; |
|
821 |
|
822 mapTileRequest->iLandmarkInfo = CPosLandmark::NewL(aLandmark); |
|
823 mapTileRequest->iUId = aUId; |
|
824 mapTileRequest->iAddressType = aAddressType; |
|
825 mapTileRequest->iEventType = iEventType; |
|
826 mapTileRequest->iImagePath.Zero(); |
|
827 mapTileRequest->iImagePath.Copy(mImagePath); |
|
828 MYLOCLOGSTRING1("RequestMapTileImageL() Queue count -%d",iMapTileRequestQueue.Count()); |
|
829 |
|
830 if (iMapTileRequestQueue.Count() <= 0) |
|
831 { |
|
832 // iMapTileRequestQueue.Append(mapTileRequest); |
|
833 if( KErrNone == RequestExecute(mapTileRequest) ) |
|
834 { |
|
835 iMapTileRequestQueue.Append(mapTileRequest); |
|
836 } |
|
837 else |
|
838 { |
|
839 delete mapTileRequest; |
|
840 } |
|
841 } |
|
842 else |
|
843 { |
|
844 MYLOCLOGSTRING("Added one more request to request queue" ); |
|
845 iMapTileRequestQueue.Append(mapTileRequest); |
|
846 } |
|
847 |
|
848 |
|
849 } |
|
850 TInt CMyLocationsEngine::RequestExecute( CMapTileRequest* aMapTileRequest) |
|
851 { |
|
852 __TRACE_CALLSTACK; |
|
853 TInt errorCode; |
|
854 switch (aMapTileRequest->iAddressType) |
|
855 { |
|
856 case ESourceCalendar: |
|
857 { |
|
858 TRAP(errorCode,iMapTileInterface->GetMapTileImageL(aMapTileRequest->iAddressDetails->Des(), |
|
859 aMapTileRequest->iImagePath, this )); |
|
860 break; |
|
861 } |
|
862 case ESourceContactsPref: |
|
863 case ESourceContactsWork: |
|
864 case ESourceContactsHome: |
|
865 { |
|
866 TRAP(errorCode, iMapTileInterface->GetMapTileImageL(aMapTileRequest->iLandmarkInfo, |
|
867 aMapTileRequest->iImagePath, this)); |
|
868 break; |
|
869 } |
|
870 }; |
|
871 |
|
872 return errorCode; |
|
873 } |
|
874 |
|
875 // ----------------------------------------------------------------------------- |
|
876 // CMyLocationsEngine::GetLocationDetailsLC() |
|
877 // get locatin details |
|
878 // ----------------------------------------------------------------------------- |
|
879 // |
|
880 CPosLandmark* CMyLocationsEngine::GetContactAddressDetailsLC( |
|
881 const CContactItem *aContactItem, TContactAddressType aAddressType) |
|
882 { |
|
883 __TRACE_CALLSTACK; |
|
884 CPosLandmark *landmark = NULL; |
|
885 |
|
886 // Set the street |
|
887 TInt adrId = FindContactsField(aContactItem, aAddressType, |
|
888 KUidContactFieldVCardMapADR); |
|
889 |
|
890 if (adrId != KErrNotFound) |
|
891 { |
|
892 TPtrC tempText = |
|
893 aContactItem->CardFields()[adrId].TextStorage()->Text(); |
|
894 if (tempText.Length() > 0) |
|
895 { |
|
896 if (!landmark) |
|
897 { |
|
898 landmark = CPosLandmark::NewL(); |
|
899 CleanupStack::PushL(landmark); |
|
900 } |
|
901 |
|
902 landmark->SetPositionFieldL(EPositionFieldStreet, tempText); |
|
903 } |
|
904 } |
|
905 |
|
906 // Set the City |
|
907 adrId = FindContactsField(aContactItem, aAddressType, |
|
908 KUidContactFieldVCardMapLOCALITY); |
|
909 if (adrId != KErrNotFound) |
|
910 { |
|
911 TPtrC tempText = |
|
912 aContactItem->CardFields()[adrId].TextStorage()->Text(); |
|
913 if (tempText.Length() > 0) |
|
914 { |
|
915 if (!landmark) |
|
916 { |
|
917 landmark = CPosLandmark::NewL(); |
|
918 CleanupStack::PushL(landmark); |
|
919 } |
|
920 landmark->SetPositionFieldL(EPositionFieldCity, tempText); |
|
921 } |
|
922 } |
|
923 |
|
924 // Set the state/region |
|
925 adrId = FindContactsField(aContactItem, aAddressType, |
|
926 KUidContactFieldVCardMapREGION); |
|
927 if (adrId != KErrNotFound) |
|
928 { |
|
929 TPtrC tempText = |
|
930 aContactItem->CardFields()[adrId].TextStorage()->Text(); |
|
931 if (tempText.Length() > 0) |
|
932 { |
|
933 if (!landmark) |
|
934 { |
|
935 landmark = CPosLandmark::NewL(); |
|
936 CleanupStack::PushL(landmark); |
|
937 } |
|
938 landmark->SetPositionFieldL(EPositionFieldState, tempText); |
|
939 } |
|
940 } |
|
941 |
|
942 // Set the Postal code |
|
943 adrId = FindContactsField(aContactItem, aAddressType, |
|
944 KUidContactFieldVCardMapPOSTCODE); |
|
945 if (adrId != KErrNotFound) |
|
946 { |
|
947 TPtrC tempText = |
|
948 aContactItem->CardFields()[adrId].TextStorage()->Text(); |
|
949 if (tempText.Length() > 0) |
|
950 { |
|
951 if (!landmark) |
|
952 { |
|
953 landmark = CPosLandmark::NewL(); |
|
954 CleanupStack::PushL(landmark); |
|
955 } |
|
956 landmark->SetPositionFieldL(EPositionFieldPostalCode, tempText); |
|
957 } |
|
958 } |
|
959 |
|
960 // Set the country |
|
961 adrId = FindContactsField(aContactItem, aAddressType, |
|
962 KUidContactFieldVCardMapCOUNTRY); |
|
963 if (adrId != KErrNotFound) |
|
964 { |
|
965 TPtrC tempText = |
|
966 aContactItem->CardFields()[adrId].TextStorage()->Text(); |
|
967 if (tempText.Length() > 0) |
|
968 { |
|
969 if (!landmark) |
|
970 { |
|
971 landmark = CPosLandmark::NewL(); |
|
972 CleanupStack::PushL(landmark); |
|
973 } |
|
974 landmark->SetPositionFieldL(EPositionFieldCountry, tempText); |
|
975 } |
|
976 } |
|
977 |
|
978 return landmark; |
|
979 |
|
980 } |
|
981 |
|
982 // ----------------------------------------------------------------------------- |
|
983 // CMyLocationsEngine::GetContactLocationDetailsLC() |
|
984 // Finds the contact's location details |
|
985 // ----------------------------------------------------------------------------- |
|
986 // |
|
987 CPosLandmark* CMyLocationsEngine::GetContactLocationDetailsLC( |
|
988 const CContactItem *aContactItem, TContactAddressType aAddressType) |
|
989 { |
|
990 __TRACE_CALLSTACK;//return value |
|
991 CPosLandmark *landmark = NULL; |
|
992 // Get the geo field |
|
993 TInt addrInd = FindContactsField(aContactItem, aAddressType, |
|
994 KUidContactFieldVCardMapGEO); |
|
995 if (addrInd != KErrNotFound) |
|
996 { |
|
997 // Geo field present. |
|
998 |
|
999 TPtrC addrText = |
|
1000 aContactItem->CardFields()[addrInd].TextStorage()->Text(); |
|
1001 if (addrText.Length() > 0) |
|
1002 { |
|
1003 //Parse the addresstext to get the latitude and longitude |
|
1004 TInt separator = addrText.Find(KSeparator); |
|
1005 if (separator != KErrNotFound) |
|
1006 { |
|
1007 TReal64 latitude = 0; |
|
1008 TReal64 longitude = 0; |
|
1009 TLex lexLatitude(addrText.Left(addrText.Length() - separator)); |
|
1010 TLex lexLongitude(addrText.Right(addrText.Length() - separator |
|
1011 - 1)); |
|
1012 if (lexLatitude.Val(latitude) == KErrNone && lexLongitude.Val( |
|
1013 longitude) == KErrNone) |
|
1014 { |
|
1015 TLocality loc(TCoordinate(latitude, longitude), 0); |
|
1016 |
|
1017 landmark = CPosLandmark::NewL(); |
|
1018 CleanupStack::PushL(landmark); |
|
1019 |
|
1020 // Fill the location details into the landmark object |
|
1021 landmark->SetPositionL(loc); |
|
1022 |
|
1023 // Set the landmark name as contact name |
|
1024 TBuf<KBufSize> sName1; |
|
1025 TBool nameEmpty = ETrue; |
|
1026 //get the second name and |
|
1027 TInt sNameInd = aContactItem->CardFields().Find( |
|
1028 KUidContactFieldGivenName); |
|
1029 if (sNameInd != KErrNotFound) |
|
1030 { |
|
1031 TPtrC sName = |
|
1032 aContactItem->CardFields()[sNameInd].TextStorage()->Text(); |
|
1033 sName1.Copy(sName); |
|
1034 nameEmpty = EFalse; |
|
1035 } |
|
1036 |
|
1037 sNameInd = aContactItem->CardFields().Find( |
|
1038 KUidContactFieldFamilyName); |
|
1039 if (sNameInd != KErrNotFound) |
|
1040 { |
|
1041 if (!nameEmpty) |
|
1042 { |
|
1043 sName1.Append(KSingleSpace); |
|
1044 } |
|
1045 TPtrC |
|
1046 sName = |
|
1047 aContactItem->CardFields()[sNameInd].TextStorage()->Text(); |
|
1048 sName1.Append(sName); |
|
1049 } |
|
1050 |
|
1051 TRAP_IGNORE( landmark->SetLandmarkNameL( sName1 ) ); |
|
1052 |
|
1053 if (aAddressType == EAddressPref) // default/prefered address |
|
1054 { |
|
1055 TRAP_IGNORE( landmark->SetLandmarkDescriptionL(KContactPrefered) ); |
|
1056 } |
|
1057 else if (aAddressType == EAddressWork) // work address |
|
1058 { |
|
1059 TRAP_IGNORE( landmark->SetLandmarkDescriptionL(KContactWork) ); |
|
1060 } |
|
1061 else // home address |
|
1062 { |
|
1063 TRAP_IGNORE( landmark->SetLandmarkDescriptionL(KContactHome) ); |
|
1064 } |
|
1065 |
|
1066 // Set the street |
|
1067 TInt adrId = FindContactsField(aContactItem, aAddressType, |
|
1068 KUidContactFieldVCardMapADR); |
|
1069 if (adrId != KErrNotFound) |
|
1070 { |
|
1071 TPtrC |
|
1072 tempText = |
|
1073 aContactItem->CardFields()[adrId].TextStorage()->Text(); |
|
1074 if (tempText.Length() > 0) |
|
1075 { |
|
1076 landmark->SetPositionFieldL(EPositionFieldStreet, |
|
1077 tempText); |
|
1078 } |
|
1079 } |
|
1080 |
|
1081 // Set the City |
|
1082 adrId = FindContactsField(aContactItem, aAddressType, |
|
1083 KUidContactFieldVCardMapLOCALITY); |
|
1084 if (adrId != KErrNotFound) |
|
1085 { |
|
1086 TPtrC |
|
1087 tempText = |
|
1088 aContactItem->CardFields()[adrId].TextStorage()->Text(); |
|
1089 if (tempText.Length() > 0) |
|
1090 { |
|
1091 landmark->SetPositionFieldL(EPositionFieldCity, |
|
1092 tempText); |
|
1093 } |
|
1094 } |
|
1095 |
|
1096 // Set the state/region |
|
1097 adrId = FindContactsField(aContactItem, aAddressType, |
|
1098 KUidContactFieldVCardMapREGION); |
|
1099 if (adrId != KErrNotFound) |
|
1100 { |
|
1101 TPtrC |
|
1102 tempText = |
|
1103 aContactItem->CardFields()[adrId].TextStorage()->Text(); |
|
1104 if (tempText.Length() > 0) |
|
1105 { |
|
1106 landmark->SetPositionFieldL(EPositionFieldState, |
|
1107 tempText); |
|
1108 } |
|
1109 } |
|
1110 |
|
1111 // Set the Postal code |
|
1112 adrId = FindContactsField(aContactItem, aAddressType, |
|
1113 KUidContactFieldVCardMapPOSTCODE); |
|
1114 if (adrId != KErrNotFound) |
|
1115 { |
|
1116 TPtrC |
|
1117 tempText = |
|
1118 aContactItem->CardFields()[adrId].TextStorage()->Text(); |
|
1119 if (tempText.Length() > 0) |
|
1120 { |
|
1121 landmark->SetPositionFieldL( |
|
1122 EPositionFieldPostalCode, tempText); |
|
1123 } |
|
1124 } |
|
1125 |
|
1126 // Set the country |
|
1127 adrId = FindContactsField(aContactItem, aAddressType, |
|
1128 KUidContactFieldVCardMapCOUNTRY); |
|
1129 if (adrId != KErrNotFound) |
|
1130 { |
|
1131 TPtrC |
|
1132 tempText = |
|
1133 aContactItem->CardFields()[adrId].TextStorage()->Text(); |
|
1134 if (tempText.Length() > 0) |
|
1135 { |
|
1136 landmark->SetPositionFieldL(EPositionFieldCountry, |
|
1137 tempText); |
|
1138 } |
|
1139 } |
|
1140 } |
|
1141 } |
|
1142 } |
|
1143 } |
|
1144 |
|
1145 return landmark; |
|
1146 } |
|
1147 |
|
1148 // ----------------------------------------------------------------------------- |
|
1149 // CMyLocationsEngine::FindContactsField() |
|
1150 // Finds the contact's field type id |
|
1151 // ----------------------------------------------------------------------------- |
|
1152 // |
|
1153 |
|
1154 TInt CMyLocationsEngine::FindContactsField(const CContactItem *aContactItem, |
|
1155 TContactAddressType aAddressType, TUid aField) |
|
1156 { |
|
1157 __TRACE_CALLSTACK; |
|
1158 if (aAddressType == EAddressPref) // default/prefered address |
|
1159 { |
|
1160 return aContactItem->CardFields().Find(aField); |
|
1161 } |
|
1162 else if (aAddressType == EAddressWork) // work address |
|
1163 { |
|
1164 return aContactItem->CardFields().Find(KUidContactFieldVCardMapWORK, |
|
1165 aField); |
|
1166 } |
|
1167 else // home address |
|
1168 { |
|
1169 return aContactItem->CardFields().Find(KUidContactFieldVCardMapHOME, |
|
1170 aField); |
|
1171 } |
|
1172 } |
|
1173 |
|
1174 // ----------------------------------------------------------------------------- |
|
1175 // CMyLocationsEngine::MapsChangeType() |
|
1176 // Maps the source's change type to Mylocations entry change type |
|
1177 // ----------------------------------------------------------------------------- |
|
1178 // |
|
1179 TEntryChangeType CMyLocationsEngine::MapChangeType(TUidSourceType aSrcType, |
|
1180 TUint32 aChangeType) |
|
1181 { |
|
1182 __TRACE_CALLSTACK;// return value |
|
1183 TEntryChangeType retVal = EEntryUnknown; |
|
1184 |
|
1185 switch (aSrcType) |
|
1186 { |
|
1187 // if source type is contacts |
|
1188 case ESourceContactsPref: |
|
1189 case ESourceContactsWork: |
|
1190 case ESourceContactsHome: |
|
1191 { |
|
1192 switch (aChangeType) |
|
1193 { |
|
1194 case EContactDbObserverEventContactAdded: |
|
1195 retVal = EEntryAdded; |
|
1196 break; |
|
1197 case EContactDbObserverEventContactDeleted: |
|
1198 retVal = EEntryDeleted; |
|
1199 break; |
|
1200 case EContactDbObserverEventContactChanged: |
|
1201 retVal = EEntryModified; |
|
1202 break; |
|
1203 } |
|
1204 break; |
|
1205 } |
|
1206 |
|
1207 // if source type is landmarks or maps history |
|
1208 case ESourceLandmarks: |
|
1209 { |
|
1210 switch (aChangeType) |
|
1211 { |
|
1212 case EPosLmEventLandmarkCreated: |
|
1213 retVal = EEntryAdded; |
|
1214 break; |
|
1215 case EPosLmEventLandmarkDeleted: |
|
1216 retVal = EEntryDeleted; |
|
1217 break; |
|
1218 case EPosLmEventLandmarkUpdated: |
|
1219 retVal = EEntryModified; |
|
1220 break; |
|
1221 } |
|
1222 break; |
|
1223 } |
|
1224 case ESourceLandmarksCategory: |
|
1225 { |
|
1226 switch (aChangeType) |
|
1227 { |
|
1228 case EPosLmEventCategoryCreated: |
|
1229 retVal = EEntryAdded; |
|
1230 break; |
|
1231 } |
|
1232 } |
|
1233 break; |
|
1234 } |
|
1235 return retVal; |
|
1236 } |
|
1237 |
|
1238 // ----------------------------------------------------------------------------- |
|
1239 // CMyLocationsEngine::MyLocationsDbManager() |
|
1240 // Gets handle to mylocations database manager. |
|
1241 // ----------------------------------------------------------------------------- |
|
1242 // |
|
1243 CMyLocationsDatabaseManager& CMyLocationsEngine::MyLocationsDbManager() |
|
1244 { |
|
1245 __TRACE_CALLSTACK; |
|
1246 return *iMyLocationsDatabaseManager; |
|
1247 } |
|
1248 // ----------------------------------------------------------------------------- |
|
1249 // CMyLocationsEngine::RunL() |
|
1250 // Handles active object's request completion event. |
|
1251 // ----------------------------------------------------------------------------- |
|
1252 // |
|
1253 void CMyLocationsEngine::RunL() |
|
1254 { |
|
1255 __TRACE_CALLSTACK; |
|
1256 switch (iLmEvent.iEventType) |
|
1257 { |
|
1258 case EPosLmEventLandmarkCreated: |
|
1259 case EPosLmEventLandmarkUpdated: |
|
1260 { |
|
1261 TBuf<KMaxAddressLength> lmAddress; |
|
1262 CPosLandmark* readLandmark = iLandmarkDb->ReadLandmarkLC( |
|
1263 iLmEvent.iLandmarkItemId); |
|
1264 |
|
1265 if (readLandmark) |
|
1266 { |
|
1267 iMyLocationsDatabaseManager->GetLandmarkFullAddress(lmAddress, |
|
1268 readLandmark); |
|
1269 |
|
1270 CPosLandmark* landmark = CPosLandmark::NewL(); |
|
1271 CleanupStack::PushL(landmark); |
|
1272 |
|
1273 TRAP_IGNORE( landmark->SetLandmarkNameL( lmAddress )); |
|
1274 |
|
1275 TPtrC iconFileName; |
|
1276 TInt iconIndex; |
|
1277 TInt iconMaskIndex; |
|
1278 TInt err = readLandmark->GetIcon(iconFileName, iconIndex, |
|
1279 iconMaskIndex); |
|
1280 |
|
1281 if (err == KErrNone) |
|
1282 { |
|
1283 TRAP_IGNORE( landmark->SetIconL( |
|
1284 iconFileName, iconIndex, iconMaskIndex ) ); |
|
1285 } |
|
1286 |
|
1287 // update the entry in mylocations database. |
|
1288 iMyLocationsDatabaseManager->UpdateDatabaseL(landmark, |
|
1289 iLmEvent.iLandmarkItemId, ESourceLandmarks, MapChangeType( |
|
1290 ESourceLandmarks, iLmEvent.iEventType)); |
|
1291 |
|
1292 CleanupStack::PopAndDestroy(landmark); |
|
1293 CleanupStack::PopAndDestroy(readLandmark); |
|
1294 } |
|
1295 } |
|
1296 break; |
|
1297 case EPosLmEventLandmarkDeleted: |
|
1298 { |
|
1299 // delete the corresponding entries in mylocations database. |
|
1300 iMyLocationsDatabaseManager->UpdateDatabaseL(NULL, |
|
1301 iLmEvent.iLandmarkItemId, ESourceLandmarks, EEntryDeleted); |
|
1302 } |
|
1303 break; |
|
1304 |
|
1305 case EPosLmEventCategoryCreated: |
|
1306 { |
|
1307 // delete the corresponding entries in mylocations database. |
|
1308 iMyLocationsDatabaseManager->UpdateDatabaseL(NULL, |
|
1309 iLmEvent.iLandmarkItemId, ESourceLandmarksCategory, |
|
1310 MapChangeType(ESourceLandmarksCategory, iLmEvent.iEventType)); |
|
1311 } |
|
1312 break; |
|
1313 |
|
1314 |
|
1315 } |
|
1316 |
|
1317 // start the change notifier again; |
|
1318 StartLandmarksChangeNotifier(); |
|
1319 |
|
1320 } |
|
1321 |
|
1322 // ----------------------------------------------------------------------------- |
|
1323 // CMyLocationsEngine::DoCancel() |
|
1324 // Implements cancellation of an outstanding request. |
|
1325 // ----------------------------------------------------------------------------- |
|
1326 // |
|
1327 void CMyLocationsEngine::DoCancel() |
|
1328 { |
|
1329 __TRACE_CALLSTACK; |
|
1330 iLandmarkDb->CancelNotifyDatabaseEvent(); |
|
1331 } |
|
1332 |
|
1333 // ----------------------------------------------------------------------------- |
|
1334 // CMyLocationsEngine::RunError() |
|
1335 // Implements cancellation of an outstanding request. |
|
1336 // ----------------------------------------------------------------------------- |
|
1337 // |
|
1338 TInt CMyLocationsEngine::RunError(TInt /*aError*/) |
|
1339 { |
|
1340 __TRACE_CALLSTACK; |
|
1341 return KErrNone; |
|
1342 } |
|
1343 |
|
1344 // ----------------------------------------------------------------------------- |
|
1345 // CMyLocationsEngine::MapTilefetchingCompleted() |
|
1346 // Handles the maptile fetching completion event and updates the maptile lookup db. |
|
1347 // ----------------------------------------------------------------------------- |
|
1348 // |
|
1349 void CMyLocationsEngine::MapTilefetchingCompleted(TInt aErrCode, |
|
1350 const TDesC& aMapTilePath) |
|
1351 { |
|
1352 __TRACE_CALLSTACK; |
|
1353 MYLOCLOGSTRING1("MapTilefetchingCompleted aErrCode - %d ",aErrCode); |
|
1354 MYLOCLOGSTRING1("iMapTileRequestQueue.Count - %d",iMapTileRequestQueue.Count()); |
|
1355 |
|
1356 if (iMapTileRequestQueue.Count() > 0) |
|
1357 { |
|
1358 |
|
1359 MYLOCLOGSTRING1("No.of RequestQueue - %d",iMapTileRequestQueue.Count()); |
|
1360 |
|
1361 if (aErrCode == KErrNone ) |
|
1362 { |
|
1363 TLookupItem lookupItem; |
|
1364 lookupItem.iSource = iMapTileRequestQueue[0]->iAddressType; |
|
1365 lookupItem.iUid = iMapTileRequestQueue[0]->iUId; |
|
1366 lookupItem.iFilePath.Copy(aMapTilePath); |
|
1367 TRAP_IGNORE( HandleMaptileDatabaseL(iMapTileRequestQueue[0]->iEventType,lookupItem ) ); |
|
1368 } |
|
1369 |
|
1370 delete iMapTileRequestQueue[0]; |
|
1371 iMapTileRequestQueue.Remove(0); |
|
1372 iMapTileRequestQueue.Compress(); |
|
1373 } |
|
1374 |
|
1375 |
|
1376 //Process the next request |
|
1377 if (iMapTileRequestQueue.Count() > 0) |
|
1378 { |
|
1379 MYLOCLOGSTRING1("MapTile fetch completed request-%d",iMapTileRequestQueue.Count()); |
|
1380 for (TInt cnt = 0; cnt < iMapTileRequestQueue.Count(); cnt++) |
|
1381 { |
|
1382 if ( KErrNone == RequestExecute(iMapTileRequestQueue[0]) ) |
|
1383 { |
|
1384 break; |
|
1385 } |
|
1386 else |
|
1387 { |
|
1388 delete iMapTileRequestQueue[0]; |
|
1389 iMapTileRequestQueue.Remove(0); |
|
1390 iMapTileRequestQueue.Compress(); |
|
1391 } |
|
1392 } |
|
1393 } |
|
1394 else |
|
1395 { |
|
1396 MYLOCLOGSTRING("MapTile fetch completed no request in queue"); |
|
1397 iMapTileRequestQueue.Reset(); |
|
1398 } |
|
1399 |
|
1400 } |
|
1401 // ----------------------------------------------------------------------------- |
|
1402 // CMyLocationsEngine::HandleMaptileDatabaseL() |
|
1403 // Handle maptile database(find/create/update/delete). |
|
1404 // ----------------------------------------------------------------------------- |
|
1405 // |
|
1406 void CMyLocationsEngine::HandleMaptileDatabaseL( |
|
1407 TInt aEventType, TLookupItem& aLookupItem) |
|
1408 { |
|
1409 __TRACE_CALLSTACK; |
|
1410 if (aEventType == EContactDbObserverEventContactChanged || aEventType |
|
1411 == EChangeModify) |
|
1412 { |
|
1413 if (iMaptileDatabase->FindEntryL(aLookupItem)) |
|
1414 { |
|
1415 iMaptileDatabase->UpdateEntryL(aLookupItem); |
|
1416 } |
|
1417 else |
|
1418 { |
|
1419 iMaptileDatabase->CreateEntryL(aLookupItem); |
|
1420 } |
|
1421 } |
|
1422 else if (aEventType == EContactDbObserverEventContactAdded || aEventType |
|
1423 == EChangeAdd) |
|
1424 { |
|
1425 iMaptileDatabase->CreateEntryL(aLookupItem); |
|
1426 |
|
1427 } |
|
1428 } |
|
1429 |
|
1430 // ----------------------------------------------------------------------------- |
|
1431 // CMyLocationsEngine::RestGeoCodeCompleted() |
|
1432 // observed when rest geo codeing completed. |
|
1433 // started lat and lon field updation into contact db. |
|
1434 // ----------------------------------------------------------------------------- |
|
1435 // |
|
1436 void CMyLocationsEngine::RestGeoCodeCompleted(TReal aLatitude, TReal aLongitude) |
|
1437 { |
|
1438 __TRACE_CALLSTACK; |
|
1439 |
|
1440 MYLOCLOGSTRING1("No. of iMapTileRequestQueue - %d",iMapTileRequestQueue.Count()); |
|
1441 if (iMapTileRequestQueue.Count() > 0) |
|
1442 { |
|
1443 switch (iMapTileRequestQueue[0]->iAddressType) |
|
1444 { |
|
1445 /*//TODO: |
|
1446 case ESourceCalendar: |
|
1447 { |
|
1448 break; |
|
1449 }*/ |
|
1450 case ESourceContactsPref: |
|
1451 case ESourceContactsWork: |
|
1452 case ESourceContactsHome: |
|
1453 { |
|
1454 GeocodeUpdate::UpDate(iMapTileRequestQueue[0]->iUId, |
|
1455 iMapTileRequestQueue[0]->iAddressType, aLatitude, |
|
1456 aLongitude); |
|
1457 MYLOCLOGSTRING("Geo code updated into contact db"); |
|
1458 break; |
|
1459 } |
|
1460 }; |
|
1461 |
|
1462 |
|
1463 } |
|
1464 |
|
1465 } |
|
1466 |
|
1467 //End of file |