18 |
18 |
19 // INCLUDE FILES |
19 // INCLUDE FILES |
20 #include <QFile> |
20 #include <QFile> |
21 #include <f32file.h> |
21 #include <f32file.h> |
22 #include <calchangecallback.h> |
22 #include <calchangecallback.h> |
|
23 #include <caliterator.h> |
23 #include <cntitem.h> |
24 #include <cntitem.h> |
24 #include <cntfldst.h> |
25 #include <cntfldst.h> |
25 #include <EPos_CPosLmDatabaseManager.h> |
26 #include <EPos_CPosLmDatabaseManager.h> |
26 #include <lbsposition.h> |
27 #include <lbsposition.h> |
27 #include <bautils.h> |
28 #include <bautils.h> |
28 #include <f32file.h> |
29 #include <f32file.h> |
29 #include <locationservicedefines.h> |
30 #include <locationservicedefines.h> |
30 #include <e32property.h> |
31 #include <e32property.h> |
|
32 #include <centralrepository.h> |
31 #include "contactsubscriber.h" |
33 #include "contactsubscriber.h" |
32 #include "calendarsubscriber.h" |
34 #include "calendarsubscriber.h" |
33 #include "mylocationsengine.h" |
35 #include "mylocationsengine.h" |
|
36 #include "mylocationsdefines.h" |
34 #include "geocodeupdate.h" //header for GeocodeUpdate class |
37 #include "geocodeupdate.h" //header for GeocodeUpdate class |
35 //handle for CMyLocationsHistoryDbObserver class |
38 //handle for CMyLocationsHistoryDbObserver class |
36 #include "mylocationlogger.h" |
39 #include "mylocationlogger.h" |
37 #if ( defined __WINSCW__ ) || ( defined __WINS__ ) |
40 #if ( defined __WINSCW__ ) || ( defined __WINS__ ) |
38 _LIT ( KImageStorageDrive, "C:\\MapTile\\"); |
41 _LIT ( KImageStorageDrive, "C:\\MapTile\\"); |
44 enum TMaptileStatusKeys {EMaptileStatusInteger=0x1}; |
47 enum TMaptileStatusKeys {EMaptileStatusInteger=0x1}; |
45 |
48 |
46 //Protocol : [appid-addresstype-maptilestatus] |
49 //Protocol : [appid-addresstype-maptilestatus] |
47 _LIT8( KMaptileStatusFormat, "%d-%d-%d" ); |
50 _LIT8( KMaptileStatusFormat, "%d-%d-%d" ); |
48 const TInt KProtocolBufferSize = 16; |
51 const TInt KProtocolBufferSize = 16; |
49 |
52 static const TInt startDateArray[2] = { 1900, 1}; |
|
53 static const TInt endDateArray[2] = { 2100, 1}; |
|
54 // Maptile interface uid |
|
55 const TUid KUidMapTileInterface = { 0x2002E6E8 }; |
|
56 |
|
57 // Central Repository Key IDs |
|
58 const TInt KMaptileDbSyncState = 0x2; |
50 const QString KSpace(" "); |
59 const QString KSpace(" "); |
51 |
60 |
52 // ============================ MEMBER FUNCTIONS =============================== |
61 // ============================ MEMBER FUNCTIONS =============================== |
53 |
62 |
54 CMyLocationsEngine* CMyLocationsEngine::NewL() |
63 CMyLocationsEngine* CMyLocationsEngine::NewL() |
432 // ----------------------------------------------------------------------------- |
451 // ----------------------------------------------------------------------------- |
433 // |
452 // |
434 void CMyLocationsEngine::SubscribeFromCalendarL(TInt aId) |
453 void CMyLocationsEngine::SubscribeFromCalendarL(TInt aId) |
435 { |
454 { |
436 __TRACE_CALLSTACK; |
455 __TRACE_CALLSTACK; |
|
456 if( !iMaptileGeocoderPluginAvailable ) |
|
457 { |
|
458 return; |
|
459 } |
437 iLastCalendarId = aId; |
460 iLastCalendarId = aId; |
|
461 TInt repValue=0; |
|
462 MaptileDbSyncStatusL(EMapTileDbStatusGet , repValue); |
|
463 if ( repValue == 1 ) |
|
464 { |
|
465 return; |
|
466 } |
438 for ( int index =0;iMapTileRequestQueue.Count()>index ;index++) |
467 for ( int index =0;iMapTileRequestQueue.Count()>index ;index++) |
439 { |
468 { |
440 if( iLastCalendarId == iMapTileRequestQueue[index]->iUId ) |
469 if( iLastCalendarId == iMapTileRequestQueue[index]->iUId ) |
441 { |
470 { |
442 return; |
471 return; |
443 } |
472 } |
444 } |
473 } |
445 |
474 TCalChangeEntry calChangeEntry ; |
446 CCalEntry* calEntry = NULL; |
475 calChangeEntry.iEntryId=aId; |
447 calEntry = iCalView->FetchL(aId); |
476 calChangeEntry.iChangeType=MCalChangeCallBack2::EChangeModify; |
448 CleanupStack::PushL(calEntry); |
477 CalenderEntryModifyL(calChangeEntry); |
449 TPtrC address(calEntry->LocationL()); |
|
450 if( address.Length()>0 ) |
|
451 { |
|
452 TLookupItem lookupItem; |
|
453 lookupItem.iUid = aId; |
|
454 lookupItem.iSource = ESourceCalendar; |
|
455 lookupItem.iFilePath.Zero(); |
|
456 lookupItem.iFetchingStatus = EMapTileFetchingInProgress; |
|
457 iMaptileDatabase->UpdateEntryL( lookupItem ); |
|
458 RequestMapTileImageL( address, ESourceCalendar, aId , EChangeModify ); |
|
459 } |
|
460 CleanupStack::PopAndDestroy(calEntry); |
|
461 } |
478 } |
462 // ----------------------------------------------------------------------------- |
479 // ----------------------------------------------------------------------------- |
463 // CMyLocationsEngine::StartCalenderChangeNotifierL() |
480 // CMyLocationsEngine::StartCalenderChangeNotifierL() |
464 // Starts calender change notification method to get callbacks when entries are |
481 // Starts calender change notification method to get callbacks when entries are |
465 // added/modified/deleted in contacts |
482 // added/modified/deleted in contacts |
469 { |
486 { |
470 __TRACE_CALLSTACK;// Get the current time and set Calendar filter to consider entries whose start time |
487 __TRACE_CALLSTACK;// Get the current time and set Calendar filter to consider entries whose start time |
471 // fall under the timeframe one year past and one year ahead of the current time. |
488 // fall under the timeframe one year past and one year ahead of the current time. |
472 if (iCalSession) |
489 if (iCalSession) |
473 { |
490 { |
474 MYLOCLOGSTRING("iCalSession is not null"); |
491 // Subscribe for notification on changes in the opened session (file). |
475 TTime currentTime; |
492 TCalTime startDate; |
476 currentTime.HomeTime(); |
493 TCalTime endDate; |
477 |
494 TDateTime startTime = TDateTime( |
478 TTime startTime = currentTime - TTimeIntervalYears(1); |
495 startDateArray[0], static_cast<TMonth>(startDateArray[1]), |
479 TTime endTime = currentTime + TTimeIntervalYears(1); |
496 0, 0, 0, 0, 0); |
480 |
497 TDateTime endTime = TDateTime( |
481 TCalTime calStartTime; |
498 endDateArray[0], static_cast<TMonth>(endDateArray[1]), |
482 calStartTime.SetTimeLocalL(startTime); |
499 0, 0, 0, 0, 0); |
483 |
500 |
484 MYLOCLOGSTRING("SetTimeLocalL(startTime)"); |
501 startDate.SetTimeUtcL(startTime); |
485 |
502 endDate.SetTimeUtcL(endTime); |
486 TCalTime calEndTime; |
503 CalCommon::TCalTimeRange searchTimeRange(startDate, endDate); |
487 calEndTime.SetTimeLocalL(endTime); |
|
488 |
504 |
489 MYLOCLOGSTRING("SetTimeLocalL(endTime)"); |
505 CCalChangeNotificationFilter* filter = NULL; |
490 |
506 filter = CCalChangeNotificationFilter::NewL( |
491 // set the filter for modification tracking |
507 MCalChangeCallBack2::EChangeEntryAll, true, searchTimeRange); |
492 CCalChangeNotificationFilter *filter = |
508 |
493 CCalChangeNotificationFilter::NewL( |
|
494 MCalChangeCallBack2::EChangeEntryAll, ETrue, |
|
495 CalCommon::TCalTimeRange(calStartTime, calEndTime)); |
|
496 MYLOCLOGSTRING(" CCalChangeNotificationFilter::NewL()"); |
|
497 // 'this' object implements MCalChangeCallBack |
|
498 iCalSession->StartChangeNotification(*this, *filter); |
509 iCalSession->StartChangeNotification(*this, *filter); |
|
510 |
|
511 // Cleanup. |
|
512 delete filter; |
499 } |
513 } |
500 } |
514 } |
501 |
515 |
502 // ----------------------------------------------------------------------------- |
516 // ----------------------------------------------------------------------------- |
503 // CMyLocationsEngine::StartContactsChangeNotifierL() |
517 // CMyLocationsEngine::StartContactsChangeNotifierL() |
541 if(iCalenderNotification) |
555 if(iCalenderNotification) |
542 { |
556 { |
543 delete iCalenderNotification; |
557 delete iCalenderNotification; |
544 iCalenderNotification = NULL; |
558 iCalenderNotification = NULL; |
545 } |
559 } |
546 |
560 if( !iMaptileGeocoderPluginAvailable ) |
|
561 { |
|
562 return; |
|
563 } |
547 // get entries associated with this UID |
564 // get entries associated with this UID |
548 for (int i = 0; i < aChangeItems.Count(); i++) |
565 for (int i = 0; i < aChangeItems.Count(); i++) |
549 { |
566 { |
550 |
567 |
551 // Check if this is some undefined change in calendar db. |
568 // Check if this is some undefined change in calendar db. |
552 if( aChangeItems[0].iChangeType == EChangeUndefined && aChangeItems[0].iEntryType == EChangeEntryAll ) |
569 if( aChangeItems[0].iChangeType == EChangeUndefined && aChangeItems[0].iEntryType == EChangeEntryAll ) |
553 { |
570 { |
|
571 MYLOCLOGSTRING("Refresh the calendar for EChangeUndefined "); |
554 // Refresh the calendar related entries in the location and maptiledb. |
572 // Refresh the calendar related entries in the location and maptiledb. |
555 RefreshCalendarEntryListL(); |
573 RefreshCalendarEntryListL(); |
556 break; |
574 break; |
557 } |
575 } |
558 TCalChangeEntry calChangeEntry = aChangeItems[i]; |
576 TCalChangeEntry calChangeEntry = aChangeItems[i]; |
559 iEventType = calChangeEntry.iChangeType; |
577 iEventType = calChangeEntry.iChangeType; |
560 switch (calChangeEntry.iChangeType) |
578 switch (calChangeEntry.iChangeType) |
597 // CMyLocationsEngine::RefreshCalendarEntryListL() |
617 // CMyLocationsEngine::RefreshCalendarEntryListL() |
598 // ----------------------------------------------------------------------------- |
618 // ----------------------------------------------------------------------------- |
599 // |
619 // |
600 void CMyLocationsEngine::RefreshCalendarEntryListL() |
620 void CMyLocationsEngine::RefreshCalendarEntryListL() |
601 { |
621 { |
|
622 __TRACE_CALLSTACK; |
|
623 TInt repValue=1; |
|
624 MaptileDbSyncStatusL(EMapTileDbStatusSet , repValue); |
|
625 // Deletes all the invalid calendar entries from location and maptile lookup db. |
|
626 DeleteInvalidCalendarEntriesL(); |
|
627 |
|
628 CCalIter* calIter = CCalIter::NewL(*iCalSession); |
|
629 CleanupStack::PushL( calIter ); |
|
630 TPtrC8 iterUid = calIter->FirstL(); |
|
631 while ( iterUid != KNullDesC8 ) |
|
632 { |
|
633 |
|
634 MYLOCLOGSTRING("while ( iterUid != KNullDesC8 )"); |
|
635 RPointerArray<CCalEntry> entryArray; |
|
636 iCalView->FetchL( iterUid, entryArray ); |
|
637 MYLOCLOGSTRING1("iCalView->FetchL :entryArray.Count()->%d",entryArray.Count()); |
|
638 // get entries associated with this UID |
|
639 for( int i =0; i<entryArray.Count() ; i++ ) |
|
640 { |
|
641 TCalChangeEntry calChangeEntry; |
|
642 calChangeEntry.iEntryId = entryArray[i]->LocalUidL() ; |
|
643 MaptileLookupItem lookupItem; |
|
644 lookupItem.iUid = entryArray[i]->LocalUidL() ; |
|
645 lookupItem.iSource = ESourceCalendar; |
|
646 if( iMaptileDatabase->findEntry(lookupItem ) ) |
|
647 { |
|
648 calChangeEntry.iChangeType = EChangeModify; |
|
649 TRAP_IGNORE( CalenderEntryModifyL(calChangeEntry) ) ; |
|
650 } |
|
651 else |
|
652 { |
|
653 calChangeEntry.iChangeType = EChangeAdd; |
|
654 TRAP_IGNORE(CalenderEntryAddedL(calChangeEntry)); |
|
655 } |
|
656 } |
|
657 iterUid.Set(calIter->NextL()); |
|
658 entryArray.ResetAndDestroy(); |
|
659 } |
|
660 CleanupStack::PopAndDestroy( calIter ); |
|
661 repValue=0; |
|
662 MaptileDbSyncStatusL(EMapTileDbStatusSet , repValue); |
|
663 } |
|
664 |
|
665 // ----------------------------------------------------------------------------- |
|
666 // CMyLocationsEngine::DeleteInvalidCalendarEntriesL() |
|
667 // ----------------------------------------------------------------------------- |
|
668 // |
|
669 void CMyLocationsEngine::DeleteInvalidCalendarEntriesL() |
|
670 { |
|
671 __TRACE_CALLSTACK; |
602 //Get all the calendar ids and check its validity. |
672 //Get all the calendar ids and check its validity. |
603 //Delete if they are no more valid. |
673 //Delete if they are no more valid. |
604 RArray<TUint32> ids; |
674 QList<quint32> ids; |
605 iMaptileDatabase->GetAllCalendarIdsL( ids ); |
675 iMaptileDatabase->getAllCalendarIds( ids ); |
606 for( TInt i = 0; i < ids.Count(); i++ ) |
676 for( TInt i = 0; i < ids.count(); i++ ) |
607 { |
677 { |
608 if( !IsCalendarEntryValidL( ids[i] ) ) |
678 if( !IsCalendarEntryValidL( ids[i] ) ) |
609 { |
679 { |
610 TLookupItem lookupItem; |
680 iMyLocationsDatabaseManager->UpdateCalendarLocationById(ids[i],EEntryDeleted,KNullDesC); |
|
681 MaptileLookupItem lookupItem; |
611 lookupItem.iSource = ESourceCalendar; |
682 lookupItem.iSource = ESourceCalendar; |
612 lookupItem.iUid = ids[i]; |
683 lookupItem.iUid = ids[i]; |
613 TRAP_IGNORE( ManipulateMapTileDataBaseL( lookupItem ) ); |
684 TRAP_IGNORE( ManipulateMapTileDataBaseL( lookupItem ) ); |
614 TRAP_IGNORE( UpdateDatabaseL( NULL, |
685 TRAP_IGNORE( UpdateDatabaseL( NULL, |
615 ids[i], ESourceCalendar, EEntryDeleted ) ); |
686 ids[i], ESourceCalendar, EEntryDeleted ) ); |
622 // CMyLocationsEngine::IsCalendarEntryValidL() |
693 // CMyLocationsEngine::IsCalendarEntryValidL() |
623 // ----------------------------------------------------------------------------- |
694 // ----------------------------------------------------------------------------- |
624 // |
695 // |
625 TBool CMyLocationsEngine::IsCalendarEntryValidL( TUint32 aId ) |
696 TBool CMyLocationsEngine::IsCalendarEntryValidL( TUint32 aId ) |
626 { |
697 { |
|
698 __TRACE_CALLSTACK; |
627 return ( ( iCalView->FetchL( aId ) == NULL ) ? EFalse:ETrue ); |
699 return ( ( iCalView->FetchL( aId ) == NULL ) ? EFalse:ETrue ); |
628 } |
700 } |
|
701 |
|
702 // ----------------------------------------------------------------------------- |
|
703 // CMyLocationsEngine::MaptileDbSyncStatusL() |
|
704 // ----------------------------------------------------------------------------- |
|
705 // |
|
706 void CMyLocationsEngine::MaptileDbSyncStatusL(const TCenrepSetting& aSettingType , TInt& aValue) |
|
707 { |
|
708 __TRACE_CALLSTACK; |
|
709 CRepository* centralRepository = NULL; |
|
710 centralRepository = CRepository::NewL( KUidMapTileInterface ) ; |
|
711 CleanupStack::PushL( centralRepository ); |
|
712 switch(aSettingType) |
|
713 { |
|
714 case EMapTileDbStatusGet: |
|
715 { |
|
716 centralRepository->Get( KMaptileDbSyncState , aValue ); |
|
717 break; |
|
718 } |
|
719 case EMapTileDbStatusSet: |
|
720 { |
|
721 centralRepository->Set( KMaptileDbSyncState , aValue ); |
|
722 MaptileLookupItem item; |
|
723 item.iSource = ESourceCalendar; |
|
724 item.iUid = iLastCalendarId; |
|
725 iMaptileDatabase->getEntry(item); |
|
726 if(iLastCalendarId >0) |
|
727 { |
|
728 PublishEntry(iLastCalendarId,item); |
|
729 } |
|
730 break; |
|
731 } |
|
732 } |
|
733 CleanupStack::PopAndDestroy(centralRepository); |
|
734 } |
|
735 |
629 // ----------------------------------------------------------------------------- |
736 // ----------------------------------------------------------------------------- |
630 // CMyLocationsEngine::CalenderEntryAddedL() |
737 // CMyLocationsEngine::CalenderEntryAddedL() |
631 // ----------------------------------------------------------------------------- |
738 // ----------------------------------------------------------------------------- |
632 // |
739 // |
633 void CMyLocationsEngine::CalenderEntryAddedL(TCalChangeEntry aCalChangeEntry) |
740 void CMyLocationsEngine::CalenderEntryAddedL(TCalChangeEntry aCalChangeEntry) |
634 { |
741 { |
635 __TRACE_CALLSTACK; |
742 __TRACE_CALLSTACK; |
636 |
743 |
637 TUint32 entryId=0; |
744 TUint32 entryId=0; |
638 entryId=aCalChangeEntry.iEntryId; |
745 entryId=aCalChangeEntry.iEntryId; |
639 //create entry in the data base and maintain a fetching state. |
746 //create entry in the data base and maintain a fetching state. |
640 TLookupItem lookupItem; |
747 MaptileLookupItem lookupItem; |
641 lookupItem.iUid = entryId ; |
748 lookupItem.iUid = entryId ; |
642 lookupItem.iSource = ESourceCalendar; |
749 lookupItem.iSource = ESourceCalendar; |
643 lookupItem.iFilePath.Zero(); |
750 lookupItem.iFilePath.clear(); |
644 lookupItem.iFetchingStatus = EMapTileFetchingInProgress; |
751 lookupItem.iFetchingStatus = EMapTileFetchingInProgress; |
645 TRAP_IGNORE( iMaptileDatabase->CreateEntryL(lookupItem) ); |
752 iMaptileDatabase->createEntry(lookupItem) ; |
646 CCalEntry* calEntry = NULL; |
753 CCalEntry* calEntry = NULL; |
647 calEntry = iCalView->FetchL( entryId ); |
754 calEntry = iCalView->FetchL( entryId ); |
648 CleanupStack::PushL(calEntry); |
755 if(calEntry!=NULL) |
649 TPtrC address(calEntry->LocationL()); |
756 { |
650 if (address.Length() > 0) |
757 CleanupStack::PushL(calEntry); |
651 { |
758 TPtrC address(calEntry->LocationL()); |
652 RequestMapTileImageL( address, ESourceCalendar, entryId , EChangeAdd ); |
759 iMyLocationsDatabaseManager->UpdateCalendarLocationById(entryId,EEntryAdded,address); |
653 } |
760 if (address.Length() > 0) |
654 CleanupStack::PopAndDestroy(calEntry); |
761 { |
|
762 RequestMapTileImageL( address, ESourceCalendar, entryId , EChangeAdd ); |
|
763 } |
|
764 CleanupStack::PopAndDestroy(calEntry); |
|
765 } |
655 } |
766 } |
656 |
767 |
657 // ----------------------------------------------------------------------------- |
768 // ----------------------------------------------------------------------------- |
658 // CMyLocationsEngine::CalenderEntryModifyL() |
769 // CMyLocationsEngine::CalenderEntryModifyL() |
659 // ----------------------------------------------------------------------------- |
770 // ----------------------------------------------------------------------------- |
661 void CMyLocationsEngine::CalenderEntryModifyL(TCalChangeEntry aCalChangeEntry) |
772 void CMyLocationsEngine::CalenderEntryModifyL(TCalChangeEntry aCalChangeEntry) |
662 { |
773 { |
663 __TRACE_CALLSTACK; |
774 __TRACE_CALLSTACK; |
664 TUint32 entryId = 0; |
775 TUint32 entryId = 0; |
665 entryId = aCalChangeEntry.iEntryId; |
776 entryId = aCalChangeEntry.iEntryId; |
666 TLookupItem lookupItem; |
777 MaptileLookupItem lookupItem; |
667 lookupItem.iSource = ESourceCalendar; |
778 lookupItem.iSource = ESourceCalendar; |
668 lookupItem.iUid = entryId; |
779 lookupItem.iUid = entryId; |
|
780 iMaptileDatabase->getEntry(lookupItem); |
|
781 QString maptilePath= lookupItem.iFilePath; |
669 CCalEntry* calEntry = NULL; |
782 CCalEntry* calEntry = NULL; |
670 calEntry = iCalView->FetchL(entryId); |
783 calEntry = iCalView->FetchL(entryId); |
671 CleanupStack::PushL(calEntry); |
784 CleanupStack::PushL(calEntry); |
672 if(iGeocodeUpdate->isGeocodeNotAvailable(entryId)) |
785 TPtrC address(calEntry->LocationL()); |
673 { |
786 TBool retGeo=EFalse; |
674 TPtrC address(calEntry->LocationL()); |
787 retGeo=iGeocodeUpdate->isGeocodeNotAvailable(entryId); |
675 if (iMyLocationsDatabaseManager->CheckIfAddressChanged(address, entryId, |
788 TBool addressChanged=EFalse; |
676 ESourceCalendar)) |
789 addressChanged=iMyLocationsDatabaseManager->CheckIfAddressChanged(address, entryId, |
677 { |
790 ESourceCalendar); |
678 lookupItem.iFilePath.Zero(); |
791 // retGeo , true if geo-code not available otherwise false. |
679 lookupItem.iFetchingStatus = EMapTileFetchingInProgress; |
792 if(!retGeo ) |
680 TRAP_IGNORE( iMaptileDatabase->ReSetEntryL(lookupItem) ); |
793 { |
681 if (address.Length() > 0) |
794 if( lookupItem.iUserSetting && addressChanged ) |
682 { |
795 { |
683 RequestMapTileImageL(address, ESourceCalendar, entryId , EChangeModify); |
796 //sync to local db |
684 } |
797 //reset the user setting flag |
685 else |
798 //update maptile all previous status |
686 { |
799 //return; |
687 UpdateDatabaseL(NULL, entryId, ESourceCalendar, EEntryDeleted); |
800 iMaptileDatabase->updateEntry(lookupItem); |
688 } |
801 iLastCalendarId=entryId; |
689 if ( lookupItem.iFilePath.Length() > 0 ) |
802 PublishEntry(entryId,lookupItem); |
690 { |
803 //TRAP_IGNORE(iMyLocationsDatabaseManager->UpdateCalendarLocationL( address, entryId, |
691 iMaptileDatabase->DeleteMapTileL(lookupItem); |
804 // ESourceCalendar) ); |
692 } |
805 } |
693 |
806 else if(lookupItem.iFetchingStatus==EMapTileFetchingInProgress || lookupItem.iFetchingStatus==EMapTileFetchingNetworkError) |
694 } |
807 { |
695 } |
808 //normal scenario , |
696 CleanupStack::PopAndDestroy(calEntry); |
809 // go for geo-coding |
697 } |
810 //return; |
698 |
811 lookupItem.iFilePath.clear(); |
|
812 lookupItem.iFetchingStatus = EMapTileFetchingInProgress; |
|
813 iMaptileDatabase->updateEntry(lookupItem) ; |
|
814 TRAP_IGNORE( UpdateDatabaseL( NULL, |
|
815 entryId, ESourceCalendar, EEntryDeleted ) ); |
|
816 if (maptilePath.length() > 0) |
|
817 { |
|
818 lookupItem.iFilePath=maptilePath; |
|
819 iMaptileDatabase->deleteMapTile(lookupItem); |
|
820 } |
|
821 RequestMapTileImageL(address, ESourceCalendar, entryId, EChangeModify); |
|
822 } |
|
823 else |
|
824 { |
|
825 PublishEntry(entryId,lookupItem); |
|
826 } |
|
827 } |
|
828 else |
|
829 { |
|
830 if(addressChanged) |
|
831 { |
|
832 // go for geo-coding |
|
833 // return; |
|
834 lookupItem.iFilePath.clear(); |
|
835 lookupItem.iFetchingStatus = EMapTileFetchingInProgress; |
|
836 iMaptileDatabase->updateEntry(lookupItem); |
|
837 TRAP_IGNORE( UpdateDatabaseL( NULL, |
|
838 entryId, ESourceCalendar, EEntryDeleted ) ); |
|
839 if (maptilePath.length() > 0) |
|
840 { |
|
841 lookupItem.iFilePath = maptilePath; |
|
842 iMaptileDatabase->deleteMapTile(lookupItem); |
|
843 } |
|
844 RequestMapTileImageL(address, ESourceCalendar, entryId, |
|
845 EChangeModify); |
|
846 } |
|
847 else |
|
848 { |
|
849 // dont do anything |
|
850 QLookupItem locationItem; |
|
851 LocationDataLookupDb lookupDb; |
|
852 if(lookupDb.findEntryBySourceIdAndType(locationItem)) |
|
853 { |
|
854 MYLOCLOGSTRING("entry found in loocation lookupdb "); |
|
855 iGeocodeUpdate->updateGeocodeToCalenderDB(entryId,locationItem.mLatitude,locationItem.mLongitude); |
|
856 } |
|
857 iLastCalendarId=entryId; |
|
858 PublishEntry(entryId,lookupItem); |
|
859 |
|
860 //return; |
|
861 } |
|
862 |
|
863 } |
|
864 CleanupStack::PopAndDestroy(calEntry); |
|
865 |
|
866 } |
|
867 // ----------------------------------------------------------------------------- |
|
868 // CMyLocationsEngine::PublishEntry() |
|
869 // maptile db updated, publishing the calendar entry. |
|
870 // ----------------------------------------------------------------------------- |
|
871 // |
|
872 void CMyLocationsEngine::PublishEntry(TInt32 aEntryId, MaptileLookupItem& aLookupItem) |
|
873 { |
|
874 __TRACE_CALLSTACK; |
|
875 //Publish the maptile status ,if it was from calendar |
|
876 if (iLastCalendarId == aEntryId) |
|
877 { |
|
878 TBuf8<KProtocolBufferSize> buffer; |
|
879 buffer.Zero(); |
|
880 buffer.Format(KMaptileStatusFormat, iLastCalendarId, |
|
881 aLookupItem.iSource, aLookupItem.iFetchingStatus); |
|
882 RProperty::Set(KMaptileStatusPublish, EMaptileStatusInteger, |
|
883 buffer); |
|
884 } |
|
885 } |
699 // ----------------------------------------------------------------------------- |
886 // ----------------------------------------------------------------------------- |
700 // CMyLocationsEngine::HandleDatabaseEventL() |
887 // CMyLocationsEngine::HandleDatabaseEventL() |
701 // Callback that provides information about the contact database change event. |
888 // Callback that provides information about the contact database change event. |
702 // ----------------------------------------------------------------------------- |
889 // ----------------------------------------------------------------------------- |
703 // |
890 // |
810 |
997 |
811 if ( iMyLocationsDatabaseManager->CheckIfAddressChanged(*preferedAddressLm, |
998 if ( iMyLocationsDatabaseManager->CheckIfAddressChanged(*preferedAddressLm, |
812 aEvent.iContactId, ESourceContactsPref) ) |
999 aEvent.iContactId, ESourceContactsPref) ) |
813 |
1000 |
814 { |
1001 { |
815 lookupItem.iFilePath.Zero(); |
1002 lookupItem.iFilePath.clear(); |
816 lookupItem.iFetchingStatus = EMapTileFetchingInProgress; |
1003 lookupItem.iFetchingStatus = EMapTileFetchingInProgress; |
817 TRAP_IGNORE( iMaptileDatabase->ReSetEntryL(lookupItem) ); |
1004 iMaptileDatabase->resetEntry(lookupItem); |
818 |
1005 |
819 RequestMapTileImageL(*preferedAddressLm, ESourceContactsPref, |
1006 RequestMapTileImageL(*preferedAddressLm, ESourceContactsPref, |
820 aEvent.iContactId, iEventType ); |
1007 aEvent.iContactId, iEventType ); |
821 |
1008 |
822 if ( lookupItem.iFilePath.Length() > 0 ) |
1009 if ( lookupItem.iFilePath.isEmpty() != false ) |
823 { |
1010 { |
824 iMaptileDatabase->DeleteMapTileL(lookupItem); |
1011 iMaptileDatabase->deleteMapTile(lookupItem); |
825 } |
1012 } |
826 |
1013 |
827 } |
1014 } |
828 } |
1015 } |
829 else |
1016 else |
842 landmarkName ); |
1029 landmarkName ); |
843 MYLOCLOGSTRING("homeAddressLm address changed" ); |
1030 MYLOCLOGSTRING("homeAddressLm address changed" ); |
844 if ( iMyLocationsDatabaseManager->CheckIfAddressChanged(*homeAddressLm, |
1031 if ( iMyLocationsDatabaseManager->CheckIfAddressChanged(*homeAddressLm, |
845 aEvent.iContactId, ESourceContactsHome) ) |
1032 aEvent.iContactId, ESourceContactsHome) ) |
846 { |
1033 { |
847 lookupItem.iFilePath.Zero(); |
1034 lookupItem.iFilePath.clear(); |
848 lookupItem.iFetchingStatus = EMapTileFetchingInProgress; |
1035 lookupItem.iFetchingStatus = EMapTileFetchingInProgress; |
849 TRAP_IGNORE( iMaptileDatabase->ReSetEntryL(lookupItem) ) |
1036 iMaptileDatabase->resetEntry(lookupItem); |
850 //remove entry from databse |
1037 //remove entry from databse |
851 RequestMapTileImageL(*homeAddressLm, ESourceContactsHome, aEvent.iContactId, |
1038 RequestMapTileImageL(*homeAddressLm, ESourceContactsHome, aEvent.iContactId, |
852 iEventType); |
1039 iEventType); |
853 if (lookupItem.iFilePath.Length() > 0) |
1040 if (lookupItem.iFilePath.isEmpty() != false ) |
854 { |
1041 { |
855 iMaptileDatabase->DeleteMapTileL(lookupItem); |
1042 iMaptileDatabase->deleteMapTile(lookupItem); |
856 } |
1043 } |
857 } |
1044 } |
858 } |
1045 } |
859 else |
1046 else |
860 { |
1047 { |
874 |
1061 |
875 MYLOCLOGSTRING("workAddressLm address changed" ); |
1062 MYLOCLOGSTRING("workAddressLm address changed" ); |
876 if ( iMyLocationsDatabaseManager->CheckIfAddressChanged(*workAddressLm, |
1063 if ( iMyLocationsDatabaseManager->CheckIfAddressChanged(*workAddressLm, |
877 aEvent.iContactId, ESourceContactsWork) ) |
1064 aEvent.iContactId, ESourceContactsWork) ) |
878 { |
1065 { |
879 lookupItem.iFilePath.Zero(); |
1066 lookupItem.iFilePath.clear(); |
880 lookupItem.iFetchingStatus = EMapTileFetchingInProgress; |
1067 lookupItem.iFetchingStatus = EMapTileFetchingInProgress; |
881 TRAP_IGNORE( iMaptileDatabase->ReSetEntryL(lookupItem) ) |
1068 iMaptileDatabase->resetEntry(lookupItem); |
882 |
1069 |
883 RequestMapTileImageL(*workAddressLm, ESourceContactsWork, |
1070 RequestMapTileImageL(*workAddressLm, ESourceContactsWork, |
884 aEvent.iContactId, iEventType); |
1071 aEvent.iContactId, iEventType); |
885 if (lookupItem.iFilePath.Length() > 0) |
1072 if (lookupItem.iFilePath.isEmpty() != false ) |
886 { |
1073 { |
887 iMaptileDatabase->DeleteMapTileL(lookupItem); |
1074 iMaptileDatabase->deleteMapTile(lookupItem); |
888 } |
1075 } |
889 } |
1076 } |
890 } |
1077 } |
891 else |
1078 else |
892 { |
1079 { |
897 } |
1084 } |
898 break; |
1085 break; |
899 } |
1086 } |
900 case EContactDbObserverEventContactAdded: |
1087 case EContactDbObserverEventContactAdded: |
901 { |
1088 { |
902 TLookupItem lookupItem; |
1089 MaptileLookupItem lookupItem; |
903 lookupItem.iUid = aEvent.iContactId; |
1090 lookupItem.iUid = aEvent.iContactId; |
904 lookupItem.iFilePath.Zero(); |
1091 lookupItem.iFilePath.clear(); |
905 lookupItem.iFetchingStatus = EMapTileFetchingInProgress; |
1092 lookupItem.iFetchingStatus = EMapTileFetchingInProgress; |
906 |
1093 |
907 MYLOCLOGSTRING("EContactDbObserverEventContactAdded" ); |
1094 MYLOCLOGSTRING("EContactDbObserverEventContactAdded" ); |
908 if (preferedAddressLm) |
1095 if (preferedAddressLm) |
909 { |
1096 { |
910 //create entry in the data base and maintain a fetching state. |
1097 //create entry in the data base and maintain a fetching state. |
911 lookupItem.iSource = ESourceContactsPref; |
1098 lookupItem.iSource = ESourceContactsPref; |
912 iMaptileDatabase->CreateEntryL(lookupItem); |
1099 iMaptileDatabase->createEntry(lookupItem); |
913 RequestMapTileImageL(*preferedAddressLm, ESourceContactsPref, |
1100 RequestMapTileImageL(*preferedAddressLm, ESourceContactsPref, |
914 aEvent.iContactId, iEventType); |
1101 aEvent.iContactId, iEventType); |
915 } |
1102 } |
916 if (homeAddressLm) |
1103 if (homeAddressLm) |
917 { |
1104 { |
918 lookupItem.iSource = ESourceContactsHome; |
1105 lookupItem.iSource = ESourceContactsHome; |
919 iMaptileDatabase->CreateEntryL(lookupItem); |
1106 iMaptileDatabase->createEntry(lookupItem); |
920 RequestMapTileImageL(*homeAddressLm, ESourceContactsHome, |
1107 RequestMapTileImageL(*homeAddressLm, ESourceContactsHome, |
921 aEvent.iContactId, iEventType); |
1108 aEvent.iContactId, iEventType); |
922 } |
1109 } |
923 if (workAddressLm) |
1110 if (workAddressLm) |
924 { |
1111 { |
925 lookupItem.iSource = ESourceContactsWork; |
1112 lookupItem.iSource = ESourceContactsWork; |
926 iMaptileDatabase->CreateEntryL(lookupItem); |
1113 iMaptileDatabase->createEntry(lookupItem); |
927 RequestMapTileImageL(*workAddressLm, ESourceContactsWork, |
1114 RequestMapTileImageL(*workAddressLm, ESourceContactsWork, |
928 aEvent.iContactId, iEventType); |
1115 aEvent.iContactId, iEventType); |
929 } |
1116 } |
930 break; |
1117 break; |
931 } |
1118 } |
1302 |
1489 |
1303 if (iMapTileRequestQueue.Count() > 0) |
1490 if (iMapTileRequestQueue.Count() > 0) |
1304 { |
1491 { |
1305 MYLOCLOGSTRING1("No.of RequestQueue - %d",iMapTileRequestQueue.Count()); |
1492 MYLOCLOGSTRING1("No.of RequestQueue - %d",iMapTileRequestQueue.Count()); |
1306 |
1493 |
1307 TLookupItem lookupItem; |
1494 MaptileLookupItem lookupItem; |
1308 lookupItem.iSource = iMapTileRequestQueue[0]->iAddressType; |
1495 lookupItem.iSource = iMapTileRequestQueue[0]->iAddressType; |
1309 lookupItem.iUid = iMapTileRequestQueue[0]->iUId; |
1496 lookupItem.iUid = iMapTileRequestQueue[0]->iUId; |
1310 |
1497 |
1311 if (aErrCode == KErrNone) |
1498 if (aErrCode == KErrNone) |
1312 { |
1499 { |
1313 UpdateGeoCodeToAppDataBase( aLatitude, aLongitude ); |
1500 UpdateGeoCodeToAppDataBase( aLatitude, aLongitude ); |
1314 |
1501 |
1315 TBool flag = EFalse; |
1502 TBool flag = EFalse; |
1316 TRAP_IGNORE( flag = iMaptileDatabase->FindEntryByFilePathL(aMapTilePath) ); |
1503 QString str = QString( (QChar*)aMapTilePath.Ptr(), aMapTilePath.Length()); |
|
1504 flag = iMaptileDatabase->findEntryByFilePath( str ); |
1317 if ( flag ) |
1505 if ( flag ) |
1318 { |
1506 { |
1319 MYLOCLOGSTRING1("%S - found in the DB",&aMapTilePath); |
1507 MYLOCLOGSTRING1("%S - found in the DB",&aMapTilePath); |
1320 |
1508 lookupItem.iFilePath = QString( (QChar*)aMapTilePath.Ptr(), aMapTilePath.Length()); |
1321 |
|
1322 lookupItem.iFilePath.Copy(aMapTilePath); |
|
1323 lookupItem.iFetchingStatus = EMapTileFectchingCompleted; |
1509 lookupItem.iFetchingStatus = EMapTileFectchingCompleted; |
1324 TRAP_IGNORE( UpdateMaptileDatabaseL(iMapTileRequestQueue[0]->iEventType, lookupItem ) ); |
1510 TRAP_IGNORE( UpdateMaptileDatabaseL(iMapTileRequestQueue[0]->iEventType, lookupItem ) ); |
1325 //Publish the maptile status |
1511 //Publish the maptile status |
1326 if( iLastContactId == iMapTileRequestQueue[0]->iUId ) |
1512 if( iLastContactId == iMapTileRequestQueue[0]->iUId ) |
1327 { |
1513 { |
1398 void CMyLocationsEngine::MyLocationThreeAMTimerExpiredL() |
1584 void CMyLocationsEngine::MyLocationThreeAMTimerExpiredL() |
1399 { |
1585 { |
1400 //Forward the event for maptile fetching only if maptile plugin available |
1586 //Forward the event for maptile fetching only if maptile plugin available |
1401 if( iMaptileGeocoderPluginAvailable ) |
1587 if( iMaptileGeocoderPluginAvailable ) |
1402 { |
1588 { |
1403 RArray<TLookupItem> iLookupItems; |
1589 QList<MaptileLookupItem> iLookupItems; |
1404 iMaptileDatabase->FindEntriesByMapTileFetchingStateL((TUint32)EMapTileFetchingNetworkError, |
1590 iMaptileDatabase->findEntriesByMapTileFetchingState((quint32)EMapTileFetchingNetworkError, |
1405 iLookupItems); |
1591 iLookupItems); |
1406 for( TUint32 i = 0; i < iLookupItems.Count(); i++ ) |
1592 for( TUint32 i = 0; i < iLookupItems.count(); i++ ) |
1407 { |
1593 { |
1408 TLookupItem iItem = iLookupItems[i]; |
1594 MaptileLookupItem iItem = iLookupItems[i]; |
1409 switch( iItem.iSource ) |
1595 switch( iItem.iSource ) |
1410 { |
1596 { |
1411 // Get the home address details |
1597 // Get the home address details |
1412 case ESourceContactsHome: |
1598 case ESourceContactsHome: |
1413 case ESourceContactsWork: |
1599 case ESourceContactsWork: |
1484 if ( iMapTileRequestQueue.Count() > 0 ) |
1670 if ( iMapTileRequestQueue.Count() > 0 ) |
1485 { |
1671 { |
1486 |
1672 |
1487 MYLOCLOGSTRING1("No.of RequestQueue - %d",iMapTileRequestQueue.Count()); |
1673 MYLOCLOGSTRING1("No.of RequestQueue - %d",iMapTileRequestQueue.Count()); |
1488 |
1674 |
1489 TLookupItem lookupItem; |
1675 MaptileLookupItem lookupItem; |
1490 lookupItem.iSource = iMapTileRequestQueue[0]->iAddressType; |
1676 lookupItem.iSource = iMapTileRequestQueue[0]->iAddressType; |
1491 lookupItem.iUid = iMapTileRequestQueue[0]->iUId; |
1677 lookupItem.iUid = iMapTileRequestQueue[0]->iUId; |
1492 |
1678 |
1493 if ( aErrCode == KErrNone ) |
1679 if ( aErrCode == KErrNone ) |
1494 { |
1680 { |
1495 CreateMultipleMaptiles( aMapTilePath ); |
1681 CreateMultipleMaptiles( aMapTilePath ); |
1496 lookupItem.iFilePath.Copy(aMapTilePath); |
1682 lookupItem.iFilePath = QString( (QChar*)aMapTilePath.Ptr(), aMapTilePath.Length()); |
1497 lookupItem.iFetchingStatus = EMapTileFectchingCompleted; |
1683 lookupItem.iFetchingStatus = EMapTileFectchingCompleted; |
1498 |
1684 |
1499 } |
1685 } |
1500 else if ( aErrCode == KErrCouldNotConnect ) |
1686 else |
1501 { |
1687 { |
1502 lookupItem.iFetchingStatus = EMapTileFetchingNetworkError; |
1688 lookupItem.iFetchingStatus = EMapTileFetchingNetworkError; |
1503 iMyLocationThreeAMTimer->StartTimer(); |
1689 iMyLocationThreeAMTimer->StartTimer(); |
1504 |
1690 |
1505 } |
1691 } |
1506 else |
|
1507 { |
|
1508 lookupItem.iFetchingStatus = EMapTileFetchingUnknownError; |
|
1509 } |
|
1510 |
1692 |
1511 TRAP_IGNORE( UpdateMaptileDatabaseL( iMapTileRequestQueue[0]->iEventType,lookupItem ) ); |
1693 TRAP_IGNORE( UpdateMaptileDatabaseL( iMapTileRequestQueue[0]->iEventType,lookupItem ) ); |
1512 |
1694 |
1513 // if the source type is contacts, update the contact name into the locationdatalookupdb. |
1695 // if the source type is contacts, update the contact name into the locationdatalookupdb. |
1514 // This has to be done, because there is a possibility that the user might change the |
1696 // This has to be done, because there is a possibility that the user might change the |
1590 // CMyLocationsEngine::HandleMaptileDatabaseL() |
1772 // CMyLocationsEngine::HandleMaptileDatabaseL() |
1591 // Handle maptile database(find/create/update/delete). |
1773 // Handle maptile database(find/create/update/delete). |
1592 // ----------------------------------------------------------------------------- |
1774 // ----------------------------------------------------------------------------- |
1593 // |
1775 // |
1594 void CMyLocationsEngine::UpdateMaptileDatabaseL( |
1776 void CMyLocationsEngine::UpdateMaptileDatabaseL( |
1595 TInt aEventType, TLookupItem& aLookupItem) |
1777 TInt aEventType, MaptileLookupItem& aLookupItem) |
1596 { |
1778 { |
1597 __TRACE_CALLSTACK; |
1779 __TRACE_CALLSTACK; |
1598 if (aEventType == EContactDbObserverEventContactChanged || aEventType |
1780 if (aEventType == EContactDbObserverEventContactChanged || aEventType |
1599 == EChangeModify || aEventType == EContactDbObserverEventContactAdded || |
1781 == EChangeModify || aEventType == EContactDbObserverEventContactAdded || |
1600 aEventType == EChangeAdd ) |
1782 aEventType == EChangeAdd ) |
1601 { |
1783 { |
1602 |
1784 |
1603 if (iMaptileDatabase->FindEntryL(aLookupItem)) |
1785 if ( iMaptileDatabase->findEntry(aLookupItem) ) |
1604 { |
1786 { |
1605 iMaptileDatabase->UpdateEntryL(aLookupItem); |
1787 iMaptileDatabase->updateEntry(aLookupItem); |
1606 } |
1788 } |
1607 else |
1789 else |
1608 { |
1790 { |
1609 iMaptileDatabase->CreateEntryL(aLookupItem); |
1791 iMaptileDatabase->createEntry(aLookupItem); |
1610 } |
1792 } |
1611 } |
1793 } |
1612 if (aLookupItem.iFetchingStatus == EMapTileFetchingUnknownError |
1794 if ( aLookupItem.iFetchingStatus == EMapTileFetchingUnknownError |
1613 || aLookupItem.iFetchingStatus == EMapTileFetchingNetworkError) |
1795 || aLookupItem.iFetchingStatus == EMapTileFetchingNetworkError ) |
1614 { |
1796 { |
1615 TRAP_IGNORE( UpdateDatabaseL( NULL, |
1797 TRAP_IGNORE( UpdateDatabaseL( NULL, |
1616 aLookupItem.iUid, aLookupItem.iSource, EEntryDeleted ) ); |
1798 aLookupItem.iUid, aLookupItem.iSource, EEntryDeleted ) ); |
1617 |
1799 |
1618 } |
1800 } |
1622 HBufC* buffer = NULL; |
1804 HBufC* buffer = NULL; |
1623 buffer=HBufC::NewLC(ptr.Length()); |
1805 buffer=HBufC::NewLC(ptr.Length()); |
1624 buffer->Des().Copy(ptr); |
1806 buffer->Des().Copy(ptr); |
1625 if(buffer) |
1807 if(buffer) |
1626 { |
1808 { |
1627 aLookupItem.iFilePath.Append(*buffer); |
1809 QString str = QString( (QChar*)buffer->Ptr(), buffer->Length()); |
|
1810 aLookupItem.iFilePath.append( str ); |
1628 } |
1811 } |
1629 CleanupStack::PopAndDestroy(buffer); |
1812 CleanupStack::PopAndDestroy(buffer); |
1630 iMyLocationsDatabaseManager->UpdateMapTilePath(aLookupItem.iUid, |
1813 TBuf<KBufSize> filePath( aLookupItem.iFilePath.utf16() ); |
1631 aLookupItem.iSource, aLookupItem.iFilePath); |
1814 iMyLocationsDatabaseManager->UpdateMapTilePath( aLookupItem.iUid, |
|
1815 aLookupItem.iSource, filePath ); |
1632 } |
1816 } |
1633 } |
1817 } |
1634 |
1818 |
1635 // ----------------------------------------------------------------------------- |
1819 // ----------------------------------------------------------------------------- |
1636 // CMyLocationsEngine::RestGeoCodeCompleted() |
1820 // CMyLocationsEngine::RestGeoCodeCompleted() |