618 lookupItem.iSource = ESourceCalendar; |
620 lookupItem.iSource = ESourceCalendar; |
619 lookupItem.iUid = entryId; |
621 lookupItem.iUid = entryId; |
620 CCalEntry* calEntry = NULL; |
622 CCalEntry* calEntry = NULL; |
621 calEntry = iCalView->FetchL(entryId); |
623 calEntry = iCalView->FetchL(entryId); |
622 CleanupStack::PushL(calEntry); |
624 CleanupStack::PushL(calEntry); |
623 TPtrC address(calEntry->LocationL()); |
625 if(iGeocodeUpdate->isGeocodeNotAvailable(entryId)) |
624 if (iMyLocationsDatabaseManager->CheckIfAddressChanged(address, entryId, |
626 { |
625 ESourceCalendar)) |
627 TPtrC address(calEntry->LocationL()); |
626 { |
628 if (iMyLocationsDatabaseManager->CheckIfAddressChanged(address, entryId, |
627 lookupItem.iFilePath.Zero(); |
629 ESourceCalendar)) |
628 lookupItem.iFetchingStatus = EMapTileFetchingInProgress; |
630 { |
629 TRAP_IGNORE( iMaptileDatabase->ReSetEntryL(lookupItem) ); |
631 lookupItem.iFilePath.Zero(); |
630 if (address.Length() > 0) |
632 lookupItem.iFetchingStatus = EMapTileFetchingInProgress; |
631 { |
633 TRAP_IGNORE( iMaptileDatabase->ReSetEntryL(lookupItem) ); |
632 RequestMapTileImageL(address, ESourceCalendar, entryId , EChangeModify); |
634 if (address.Length() > 0) |
633 } |
635 { |
634 else |
636 RequestMapTileImageL(address, ESourceCalendar, entryId , EChangeModify); |
635 { |
637 } |
636 UpdateDatabaseL(NULL, entryId, ESourceCalendar, EEntryDeleted); |
638 else |
637 } |
639 { |
638 if ( lookupItem.iFilePath.Length() > 0 ) |
640 UpdateDatabaseL(NULL, entryId, ESourceCalendar, EEntryDeleted); |
639 { |
641 } |
640 iMaptileDatabase->DeleteMapTileL(lookupItem); |
642 if ( lookupItem.iFilePath.Length() > 0 ) |
641 } |
643 { |
642 |
644 iMaptileDatabase->DeleteMapTileL(lookupItem); |
643 } |
645 } |
|
646 |
|
647 } |
|
648 } |
644 CleanupStack::PopAndDestroy(calEntry); |
649 CleanupStack::PopAndDestroy(calEntry); |
645 } |
650 } |
646 |
651 |
647 // ----------------------------------------------------------------------------- |
652 // ----------------------------------------------------------------------------- |
648 // CMyLocationsEngine::HandleDatabaseEventL() |
653 // CMyLocationsEngine::HandleDatabaseEventL() |
656 //Forward the event for maptile fetching only if maptile plugin available |
661 //Forward the event for maptile fetching only if maptile plugin available |
657 if( iMaptileGeocoderPluginAvailable ) |
662 if( iMaptileGeocoderPluginAvailable ) |
658 { |
663 { |
659 TriggerMaptileRequestL(aEvent); |
664 TriggerMaptileRequestL(aEvent); |
660 } |
665 } |
661 |
666 } |
662 HandlelandmarkDatabaseL(aEvent); |
667 |
663 } |
|
664 |
|
665 // ----------------------------------------------------------------------------- |
|
666 // CMyLocationsEngine::HandlelandmarkDatabaseL() |
|
667 // Process the contact database event and updates the landmark database |
|
668 // ----------------------------------------------------------------------------- |
|
669 // |
|
670 void CMyLocationsEngine::HandlelandmarkDatabaseL( |
|
671 TContactDbObserverEvent& aEvent) |
|
672 { |
|
673 __TRACE_CALLSTACK;// If contact is modified or added, update the mylocations db |
|
674 if (aEvent.iType == EContactDbObserverEventContactChanged || aEvent.iType |
|
675 == EContactDbObserverEventContactAdded) |
|
676 { |
|
677 |
|
678 CPosLandmark *preferedAddressLm = NULL; |
|
679 CPosLandmark *workAddressLm = NULL; |
|
680 CPosLandmark *homeAddressLm = NULL; |
|
681 |
|
682 QContact contactInfo = iContactManager->contact( aEvent.iContactId ); |
|
683 |
|
684 //Get the contact name details |
|
685 QContactName name = contactInfo.detail( QContactName::DefinitionName ); |
|
686 QString firstName = name.firstName(); |
|
687 QString lastName = name.lastName(); |
|
688 TPtrC16 tempPtr1(reinterpret_cast<const TUint16*>(firstName.utf16())); |
|
689 TPtrC16 tempPtr2( reinterpret_cast <const TUint16*>(lastName.utf16())); |
|
690 |
|
691 TBuf<KBufSize> landmarkName; |
|
692 landmarkName.Append( tempPtr1 ); |
|
693 landmarkName.Append( tempPtr2 ); |
|
694 |
|
695 TInt itemCount = 0; |
|
696 |
|
697 |
|
698 double longitude, latitude; |
|
699 |
|
700 foreach ( QContactAddress address, contactInfo.details<QContactAddress>() ) |
|
701 { |
|
702 QStringList context = address.contexts(); |
|
703 if ( context.isEmpty() ) // no context |
|
704 { |
|
705 //check whether geocordinate available |
|
706 TBool geoField = IsGeoCoordinateAvailable( |
|
707 contactInfo, NULL , latitude, longitude ); |
|
708 if( geoField ) |
|
709 { |
|
710 // Get the default/prefered address details |
|
711 preferedAddressLm = GetContactAddressDetailsLC( address ); |
|
712 TLocality loc( TCoordinate( latitude, longitude ), 0 ); |
|
713 // Fill the location details into the landmark object |
|
714 preferedAddressLm->SetPositionL(loc); |
|
715 preferedAddressLm->SetLandmarkNameL( landmarkName ); |
|
716 itemCount++; |
|
717 |
|
718 } |
|
719 } |
|
720 else if (context.first() == QContactAddress::ContextHome ) |
|
721 { |
|
722 //check whether geocordinate available |
|
723 TBool geoField = IsGeoCoordinateAvailable( |
|
724 contactInfo, QContactAddress::ContextHome, latitude, longitude ); |
|
725 if( geoField ) |
|
726 { |
|
727 // Get the home address details |
|
728 homeAddressLm = GetContactAddressDetailsLC( address ); |
|
729 TLocality loc(TCoordinate( latitude,longitude ), 0); |
|
730 homeAddressLm->SetPositionL(loc); |
|
731 homeAddressLm->SetLandmarkNameL( landmarkName ); |
|
732 itemCount++; |
|
733 } |
|
734 } |
|
735 else if (context.first() == QContactAddress::ContextWork ) |
|
736 { |
|
737 //check whether geocordinate available |
|
738 TBool geoField = IsGeoCoordinateAvailable( |
|
739 contactInfo, QContactAddress::ContextWork, latitude, longitude ); |
|
740 if( geoField ) |
|
741 { |
|
742 // Get the work address details |
|
743 workAddressLm = GetContactAddressDetailsLC( address ); |
|
744 TLocality loc(TCoordinate( latitude, longitude ), 0); |
|
745 // Fill the location details into the landmark object |
|
746 workAddressLm->SetPositionL(loc); |
|
747 workAddressLm->SetLandmarkNameL( landmarkName ); |
|
748 itemCount++; |
|
749 } |
|
750 |
|
751 } |
|
752 } |
|
753 |
|
754 // if the contact item has no validated address (preferef, home or work) |
|
755 if (!preferedAddressLm && !workAddressLm && !homeAddressLm) |
|
756 { |
|
757 if (aEvent.iType == EContactDbObserverEventContactChanged) |
|
758 { |
|
759 // If the contact is a modified one and it might already exist in |
|
760 // mylocations db, so delete it |
|
761 UpdateDatabaseL(NULL, |
|
762 aEvent.iContactId, ESourceContactsPref, |
|
763 EEntryDeleted); |
|
764 |
|
765 UpdateDatabaseL(NULL, |
|
766 aEvent.iContactId, ESourceContactsHome, |
|
767 EEntryDeleted); |
|
768 |
|
769 UpdateDatabaseL(NULL, |
|
770 aEvent.iContactId, ESourceContactsWork, |
|
771 EEntryDeleted); |
|
772 } |
|
773 } |
|
774 else |
|
775 { |
|
776 // There is atleast one valid address present. |
|
777 |
|
778 // Get the TEntryChangeType for contacts. |
|
779 TEntryChangeType changeType = MapChangeType( |
|
780 ESourceContactsPref, aEvent.iType); |
|
781 |
|
782 // if prefered address available, update Mylocations. |
|
783 if (preferedAddressLm) |
|
784 { |
|
785 UpdateDatabaseL( |
|
786 preferedAddressLm, aEvent.iContactId, |
|
787 ESourceContactsPref, changeType); |
|
788 } |
|
789 // if home address available, update Mylocations. |
|
790 if (homeAddressLm) |
|
791 { |
|
792 UpdateDatabaseL(homeAddressLm, |
|
793 aEvent.iContactId, ESourceContactsHome, changeType); |
|
794 } |
|
795 |
|
796 // if work address available, update Mylocations. |
|
797 if (workAddressLm) |
|
798 { |
|
799 UpdateDatabaseL(workAddressLm, |
|
800 aEvent.iContactId, ESourceContactsWork, changeType); |
|
801 } |
|
802 |
|
803 CleanupStack::PopAndDestroy( itemCount ); |
|
804 } |
|
805 |
|
806 } |
|
807 else if (aEvent.iType == EContactDbObserverEventContactDeleted) |
|
808 { |
|
809 // the contact is deleted, so delete the corresponding entries from database. |
|
810 |
|
811 // delete prefered address in database |
|
812 UpdateDatabaseL(NULL, aEvent.iContactId, |
|
813 ESourceContactsPref, EEntryDeleted); |
|
814 |
|
815 // delete work address in database |
|
816 UpdateDatabaseL(NULL, aEvent.iContactId, |
|
817 ESourceContactsWork, EEntryDeleted); |
|
818 |
|
819 // delete home address in database |
|
820 UpdateDatabaseL(NULL, aEvent.iContactId, |
|
821 ESourceContactsHome, EEntryDeleted); |
|
822 } |
|
823 } |
|
824 |
668 |
825 // ----------------------------------------------------------------------------- |
669 // ----------------------------------------------------------------------------- |
826 // CMyLocationsEngine::TriggerMaptileRequestL() |
670 // CMyLocationsEngine::TriggerMaptileRequestL() |
827 // Process the contact address information for fetching maptile. |
671 // Process the contact address information for fetching maptile. |
828 // ----------------------------------------------------------------------------- |
672 // ----------------------------------------------------------------------------- |
833 TLookupItem lookupItem; |
677 TLookupItem lookupItem; |
834 lookupItem.iUid = aEvent.iContactId; |
678 lookupItem.iUid = aEvent.iContactId; |
835 // If contact is deleted delete from mylocations db |
679 // If contact is deleted delete from mylocations db |
836 if (aEvent.iType == EContactDbObserverEventContactDeleted) |
680 if (aEvent.iType == EContactDbObserverEventContactDeleted) |
837 { |
681 { |
|
682 //Delete the entries from maptile database |
838 lookupItem.iSource = ESourceContactsPref; |
683 lookupItem.iSource = ESourceContactsPref; |
839 TRAP_IGNORE( ManipulateMapTileDataBaseL(lookupItem)); |
684 TRAP_IGNORE( ManipulateMapTileDataBaseL(lookupItem)); |
840 |
685 |
841 lookupItem.iSource = ESourceContactsWork; |
686 lookupItem.iSource = ESourceContactsWork; |
842 TRAP_IGNORE( ManipulateMapTileDataBaseL(lookupItem)); |
687 TRAP_IGNORE( ManipulateMapTileDataBaseL(lookupItem)); |
843 |
688 |
844 lookupItem.iSource = ESourceContactsHome; |
689 lookupItem.iSource = ESourceContactsHome; |
845 TRAP_IGNORE( ManipulateMapTileDataBaseL(lookupItem)); |
690 TRAP_IGNORE( ManipulateMapTileDataBaseL(lookupItem)); |
846 |
691 |
|
692 // Delete entries from mylocation database |
|
693 TRAP_IGNORE( UpdateDatabaseL( NULL, aEvent.iContactId, |
|
694 ESourceContactsPref, EEntryDeleted )); |
|
695 |
|
696 TRAP_IGNORE( UpdateDatabaseL( NULL, aEvent.iContactId, |
|
697 ESourceContactsHome, EEntryDeleted )); |
|
698 |
|
699 TRAP_IGNORE( UpdateDatabaseL( NULL, aEvent.iContactId, |
|
700 ESourceContactsWork, EEntryDeleted ) ); |
|
701 |
847 MYLOCLOGSTRING("EContactDbObserverEventContactDeleted "); |
702 MYLOCLOGSTRING("EContactDbObserverEventContactDeleted "); |
848 return; |
703 return; |
849 } |
704 } |
850 |
705 |
851 //Get the contact item |
706 //Get the contact item |
852 iEventType = aEvent.iType; |
707 iEventType = aEvent.iType; |
853 QContact contactInfo = iContactManager->contact( aEvent.iContactId ); |
708 QContact contactInfo = iContactManager->contact( aEvent.iContactId ); |
854 |
709 |
855 |
710 //Get the contact name details |
|
711 QContactName name = contactInfo.detail( QContactName::DefinitionName ); |
|
712 QString firstName = name.firstName(); |
|
713 QString lastName = name.lastName(); |
|
714 TPtrC16 tempPtr1(reinterpret_cast<const TUint16*>(firstName.utf16())); |
|
715 TPtrC16 tempPtr2( reinterpret_cast <const TUint16*>(lastName.utf16())); |
|
716 |
|
717 TBuf<KBufSize> landmarkName; |
|
718 landmarkName.Append( tempPtr1 ); |
|
719 landmarkName.Append( tempPtr2 ); |
|
720 |
856 CPosLandmark *preferedAddressLm = NULL; |
721 CPosLandmark *preferedAddressLm = NULL; |
857 CPosLandmark *workAddressLm = NULL; |
722 CPosLandmark *workAddressLm = NULL; |
858 CPosLandmark *homeAddressLm = NULL; |
723 CPosLandmark *homeAddressLm = NULL; |
859 |
724 |
860 TInt itemCount = 0; |
725 TInt itemCount = 0; |
993 lookupItem.iFetchingStatus = EMapTileFetchingInProgress; |
861 lookupItem.iFetchingStatus = EMapTileFetchingInProgress; |
994 |
862 |
995 MYLOCLOGSTRING("EContactDbObserverEventContactAdded" ); |
863 MYLOCLOGSTRING("EContactDbObserverEventContactAdded" ); |
996 if (preferedAddressLm) |
864 if (preferedAddressLm) |
997 { |
865 { |
|
866 preferedAddressLm->SetLandmarkNameL( landmarkName ); |
998 //create entry in the data base and maintain a fetching state. |
867 //create entry in the data base and maintain a fetching state. |
999 lookupItem.iSource = ESourceContactsPref; |
868 lookupItem.iSource = ESourceContactsPref; |
1000 iMaptileDatabase->CreateEntryL(lookupItem); |
869 iMaptileDatabase->CreateEntryL(lookupItem); |
1001 RequestMapTileImageL(*preferedAddressLm, ESourceContactsPref, |
870 RequestMapTileImageL(*preferedAddressLm, ESourceContactsPref, |
1002 aEvent.iContactId, iEventType); |
871 aEvent.iContactId, iEventType); |
1003 } |
872 } |
1004 if (homeAddressLm) |
873 if (homeAddressLm) |
1005 { |
874 { |
|
875 homeAddressLm->SetLandmarkNameL( landmarkName ); |
1006 lookupItem.iSource = ESourceContactsHome; |
876 lookupItem.iSource = ESourceContactsHome; |
1007 iMaptileDatabase->CreateEntryL(lookupItem); |
877 iMaptileDatabase->CreateEntryL(lookupItem); |
1008 RequestMapTileImageL(*homeAddressLm, ESourceContactsHome, |
878 RequestMapTileImageL(*homeAddressLm, ESourceContactsHome, |
1009 aEvent.iContactId, iEventType); |
879 aEvent.iContactId, iEventType); |
1010 } |
880 } |
1011 if (workAddressLm) |
881 if (workAddressLm) |
1012 { |
882 { |
|
883 workAddressLm->SetLandmarkNameL( landmarkName ); |
1013 lookupItem.iSource = ESourceContactsWork; |
884 lookupItem.iSource = ESourceContactsWork; |
1014 iMaptileDatabase->CreateEntryL(lookupItem); |
885 iMaptileDatabase->CreateEntryL(lookupItem); |
1015 RequestMapTileImageL(*workAddressLm, ESourceContactsWork, |
886 RequestMapTileImageL(*workAddressLm, ESourceContactsWork, |
1016 aEvent.iContactId, iEventType); |
887 aEvent.iContactId, iEventType); |
1017 } |
888 } |
1706 } |
1620 } |
1707 case ESourceContactsPref: |
1621 case ESourceContactsPref: |
1708 case ESourceContactsWork: |
1622 case ESourceContactsWork: |
1709 case ESourceContactsHome: |
1623 case ESourceContactsHome: |
1710 { |
1624 { |
1711 GeocodeUpdate geocodeUpdate; |
1625 iGeocodeUpdate->updateGeocodeToContactDB( |
1712 geocodeUpdate.updateGeocodeToContactDB( |
|
1713 iMapTileRequestQueue[0]->iUId, |
1626 iMapTileRequestQueue[0]->iUId, |
1714 iMapTileRequestQueue[0]->iAddressType, aLatitude, |
1627 iMapTileRequestQueue[0]->iAddressType, aLatitude, |
1715 aLongitude); |
1628 aLongitude); |
|
1629 //Update mylocation database |
|
1630 TRAP_IGNORE( UpdateDatabaseL( |
|
1631 iMapTileRequestQueue[0]->iLandmarkInfo, |
|
1632 iMapTileRequestQueue[0]->iUId, |
|
1633 iMapTileRequestQueue[0]->iAddressType, |
|
1634 MapChangeType( |
|
1635 static_cast<TUidSourceType>( iMapTileRequestQueue[0]->iAddressType ), |
|
1636 iMapTileRequestQueue[0]->iEventType ))); |
|
1637 |
1716 MYLOCLOGSTRING("Geo-codinate updated to contact db"); |
1638 MYLOCLOGSTRING("Geo-codinate updated to contact db"); |
1717 break; |
1639 break; |
1718 } |
1640 } |
1719 }; |
1641 }; |
1720 |
|
1721 |
|
1722 } |
1642 } |
1723 |
1643 |
1724 } |
1644 } |
1725 |
1645 |
1726 // ----------------------------------------------------------------------------- |
1646 // ----------------------------------------------------------------------------- |
1755 { |
1675 { |
1756 iMaptileDatabase->DeleteMapTileL(aLookupItem); |
1676 iMaptileDatabase->DeleteMapTileL(aLookupItem); |
1757 } |
1677 } |
1758 } |
1678 } |
1759 |
1679 |
|
1680 |
|
1681 // ----------------------------------------------------------------------------- |
|
1682 // CMyLocationsEngine::CreateMultipleMaptiles() |
|
1683 // ----------------------------------------------------------------------------- |
|
1684 // |
|
1685 void CMyLocationsEngine::CreateMultipleMaptiles( const TDesC& aMaptilePath ) |
|
1686 { |
|
1687 __TRACE_CALLSTACK; |
|
1688 QString filePath = QString::fromUtf16( aMaptilePath.Ptr(), aMaptilePath.Length() ); |
|
1689 |
|
1690 //Portrait image , common for contacts/calendar/context menu |
|
1691 CropAndSaveImage( filePath, |
|
1692 MaptilePortraitWidth, |
|
1693 MaptilePortraitHeight, |
|
1694 QString(), |
|
1695 QString( MAPTILE_IMAGE_PORTRAIT ) ); |
|
1696 |
|
1697 //Landscape image for contacts |
|
1698 CropAndSaveImage( filePath, |
|
1699 MaptileContactLandscapeWidth, |
|
1700 MaptileContactLandscapeHeight, |
|
1701 QString( MAPTILE_IMAGE_CONTACT ), |
|
1702 QString( MAPTILE_IMAGE_LANDSCAPE ) ); |
|
1703 |
|
1704 //Ladscape image for calendar |
|
1705 CropAndSaveImage( filePath, |
|
1706 MaptileCalendarLandscapeWidth, |
|
1707 MaptileCalendarLandscapeHeight, |
|
1708 QString( MAPTILE_IMAGE_CALENDAR ), |
|
1709 QString( MAPTILE_IMAGE_LANDSCAPE ) ); |
|
1710 |
|
1711 //Image for hurriganes |
|
1712 CropAndSaveImage( filePath, |
|
1713 MaptileHurriganesWidth, |
|
1714 MaptileHurriganesHeight, |
|
1715 QString( MAPTILE_IMAGE_HURRIGANES ), |
|
1716 QString() ); |
|
1717 QFile file(filePath); |
|
1718 file.remove(); |
|
1719 } |
|
1720 |
|
1721 |
|
1722 // ----------------------------------------------------------------------------- |
|
1723 // CMyLocationsEngine::CropAndSaveImage() |
|
1724 // ----------------------------------------------------------------------------- |
|
1725 // |
|
1726 void CMyLocationsEngine::CropAndSaveImage( QString filePath, int width, |
|
1727 int height, QString appType, QString orientationType ) |
|
1728 { |
|
1729 __TRACE_CALLSTACK; |
|
1730 QImage SourcePNG( filePath ); |
|
1731 QImage sourcePixmap( SourcePNG.convertToFormat(QImage::Format_Indexed8)); |
|
1732 QImage targetPixmap( sourcePixmap.copy( |
|
1733 ( MapTileWidth - width )/2, |
|
1734 ( MapTileHeight - height )/2 , |
|
1735 width, |
|
1736 height ) ); |
|
1737 |
|
1738 QString targetImage; |
|
1739 targetImage.append( filePath ); |
|
1740 targetImage.append( appType ); |
|
1741 targetImage.append( orientationType ); |
|
1742 targetPixmap.save( targetImage, MAPTILE_IMAGE_TYPE ); |
|
1743 |
|
1744 } |
|
1745 |
1760 //End of file |
1746 //End of file |
1761 |
1747 |