Revision: 201021
authorDremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Fri, 11 Jun 2010 13:33:47 +0300
changeset 26 f3533f6eae3f
parent 24 ccec19943943
child 27 ed104fb472d9
child 30 96df3ab41000
Revision: 201021 Kit: 2010123
location_plat/location_data_harvester_api/inc/locationdatalookupdb.h
location_plat/location_data_harvester_api/inc/locationservicedefines.h
location_plat/location_data_harvester_api/inc/maptilegeocoderplugin.h
locationdataharvester/bwins/locationdatalookupdbu.def
locationdataharvester/bwins/mylocationsdatabasemanageru.def
locationdataharvester/eabi/locationdatalookupdbu.def
locationdataharvester/eabi/mylocationsdatabasemanageru.def
locationdataharvester/geocodeupdate/src/geocodeupdate.cpp
locationdataharvester/inc/mylocationsdefines.h
locationdataharvester/locationdataharvester.pro
locationdataharvester/locationdatalookupdb/locationdatalookupdb.cpp
locationdataharvester/locationdatalookupdb/tsrc/ut_locationdatalookupdb/ut_locationdatalookupdb.cpp
locationdataharvester/locationdatalookupdb/tsrc/ut_locationdatalookupdb/ut_locationdatalookupdb.pro
locationdataharvester/maptileservice/inc/maptiledblookuptable.h
locationdataharvester/maptileservice/src/maptiledblookuptable.cpp
locationdataharvester/maptileservice/src/maptileservice.cpp
locationdataharvester/mylocationsdatabasemanager/inc/mylocationsdatabasemanager.h
locationdataharvester/mylocationsdatabasemanager/mylocationsdatabasemanager.pro
locationdataharvester/mylocationsdatabasemanager/src/mylocationsdatabasemanager.cpp
locationdataharvester/mylocationsdatabasemanager/tsrc/ut_mylocationsdatabasemanager.cpp
locationdataharvester/mylocationsdatabasemanager/tsrc/ut_mylocationsdatabasemanager.pro
locationdataharvester/mylocationsengine/inc/addresscomparision.h
locationdataharvester/mylocationsengine/inc/lookupmaptiledb.h
locationdataharvester/mylocationsengine/inc/maptileinterface.h
locationdataharvester/mylocationsengine/inc/mylocationgeotagtimerao.h
locationdataharvester/mylocationsengine/inc/mylocationsdatabasemanager.h
locationdataharvester/mylocationsengine/inc/mylocationsengine.h
locationdataharvester/mylocationsengine/inc/mylocationslookupdb.h
locationdataharvester/mylocationsengine/mylocationsengine.pro
locationdataharvester/mylocationsengine/src/addresscomparision.cpp
locationdataharvester/mylocationsengine/src/calendernotification.cpp
locationdataharvester/mylocationsengine/src/lookupmaptiledb.cpp
locationdataharvester/mylocationsengine/src/maptileinterface.cpp
locationdataharvester/mylocationsengine/src/mylocationgeotagtimerao.cpp
locationdataharvester/mylocationsengine/src/mylocationsdatabasemanager.cpp
locationdataharvester/mylocationsengine/src/mylocationsengine.cpp
locationdataharvester/mylocationsengine/src/mylocationslookupdb.cpp
locationdataharvester/rom/mylocations.iby
locationpickerservice/rom/locationpickerservice.iby
locationpickerservice/src/locationpickerlandscapeview.cpp
locationpickerservice/src/locationpickerpotraitview.cpp
locationpickerservice/src/main.cpp
--- a/location_plat/location_data_harvester_api/inc/locationdatalookupdb.h	Thu May 27 12:49:34 2010 +0300
+++ b/location_plat/location_data_harvester_api/inc/locationdatalookupdb.h	Fri Jun 11 13:33:47 2010 +0300
@@ -136,7 +136,7 @@
     * Creates an entry in the lookup table.
     * @param[in] aLookupItem The lookup item to be created in the database.
     */
-    void createEntry( const QLookupItem& aLookupItem );
+    void createEntry( QLookupItem& aLookupItem );
 
     /**
     * Updates an entry in the lookup table.
@@ -167,13 +167,6 @@
     void deleteEntryBySourceIdAndType( const QLookupItem& aLookupItem );
 
     /**
-    * Deletes an entry from the lookup table.
-    * The id is used to find the entry in db
-    * @param[in] aLookupItem The lookup item to be deleted from the database.
-    */
-    void deleteEntryById( const QLookupItem& aLookupItem );
-
-    /**
     * Finds an entry in the lookup table.
     * @param[in/out] aLookupItem The lookup item to be found in the database. The source id and source type 
     * is passed in the lookup item. If the entry is found, all other fields are updated in the lookup item.
@@ -197,16 +190,7 @@
     void findEntriesByLandmarkId( const quint32 aLandmarkId, 
             QList<QLookupItem>& aLookupItemArray );
 
-    /**
-    * Finds list of lookup items given a source type.
-    * @param[in] aSourceType The source type to be found in the lookup database.  
-    * @param[out] aLookupItemArray List of lookup entries found.  
-    */
-    void findEntriesBySourceType( const quint32 aSourceType, 
-            QList<QLookupItem>& aLookupItemArray );
-
-
-    /**
+   /**
     * Gets list of lookup items.
     * @param[in] aCollectionId The collection id, whose whose corresponding entries needs to be fetched.
     *            By default all the entries in the lookup db are fetched.  
@@ -222,6 +206,9 @@
     
     // Handle to the items database
     QSqlDatabase *mDb;
+
+    // Flag to indicate if db is open
+    bool mDbOpen;
 };
 #endif  // LOCATIONDATA_LOOKUPDB_H
 
--- a/location_plat/location_data_harvester_api/inc/locationservicedefines.h	Thu May 27 12:49:34 2010 +0300
+++ b/location_plat/location_data_harvester_api/inc/locationservicedefines.h	Fri Jun 11 13:33:47 2010 +0300
@@ -49,4 +49,19 @@
     ESourceInvalid
 };
 
+/** Defines entry change type
+*/
+enum TEntryChangeType
+    {
+    /** Entry added */
+    EEntryAdded,
+    /** Entry modified */
+    EEntryModified,
+    /** Entry deleted */
+    EEntryDeleted,
+    /** Entry change unknown */
+    EEntryUnknown
+    };
+
+
 #endif // QLOCATIONPICKERITEM_H
--- a/location_plat/location_data_harvester_api/inc/maptilegeocoderplugin.h	Thu May 27 12:49:34 2010 +0300
+++ b/location_plat/location_data_harvester_api/inc/maptilegeocoderplugin.h	Fri Jun 11 13:33:47 2010 +0300
@@ -133,8 +133,9 @@
      * @param aSize requested maptile size
      *
      */
-    TMapTileParam( const TReal aLatitude, const TReal aLongitude, const TInt aZoom, const TInt aSize ):
-        iLattitude( aLatitude ), iLongitude( aLongitude ), iZoomLevel( aZoom ), iSize( aSize )
+    TMapTileParam( const TReal aLatitude, const TReal aLongitude, 
+            const TInt aZoom, const TInt aWidth, const TInt aHeight ): iLattitude( aLatitude ),
+            iLongitude( aLongitude ), iZoomLevel( aZoom ), iWidth( aWidth ), iHeight( aHeight )
     {
     }
 		
@@ -155,8 +156,10 @@
     TReal iLongitude;
     //Zoom level
     TInt iZoomLevel;
-    //Required image size
-    TInt iSize;
+    //Required image width
+    TInt iWidth;
+    //Required image height
+    TInt iHeight;
 };
 
 
--- a/locationdataharvester/bwins/locationdatalookupdbu.def	Thu May 27 12:49:34 2010 +0300
+++ b/locationdataharvester/bwins/locationdatalookupdbu.def	Fri Jun 11 13:33:47 2010 +0300
@@ -1,19 +1,17 @@
 EXPORTS
 	?updateMaptileBySourceIdAndType@LocationDataLookupDb@@QAEXIIVQString@@@Z @ 1 NONAME ; void LocationDataLookupDb::updateMaptileBySourceIdAndType(unsigned int, unsigned int, class QString)
 	?deleteEntryBySourceIdAndType@LocationDataLookupDb@@QAEXABVQLookupItem@@@Z @ 2 NONAME ; void LocationDataLookupDb::deleteEntryBySourceIdAndType(class QLookupItem const &)
-	?deleteEntryById@LocationDataLookupDb@@QAEXABVQLookupItem@@@Z @ 3 NONAME ; void LocationDataLookupDb::deleteEntryById(class QLookupItem const &)
-	?updateEntryBySourceIdAndType@LocationDataLookupDb@@QAEXABVQLookupItem@@@Z @ 4 NONAME ; void LocationDataLookupDb::updateEntryBySourceIdAndType(class QLookupItem const &)
-	?getEntries@LocationDataLookupDb@@QAEXAAV?$QList@VQLookupItem@@@@I@Z @ 5 NONAME ; void LocationDataLookupDb::getEntries(class QList<class QLookupItem> &, unsigned int)
-	?updateEntryById@LocationDataLookupDb@@QAEXABVQLookupItem@@@Z @ 6 NONAME ; void LocationDataLookupDb::updateEntryById(class QLookupItem const &)
-	??0LocationDataLookupDb@@QAE@PAVQObject@@@Z @ 7 NONAME ; LocationDataLookupDb::LocationDataLookupDb(class QObject *)
-	?findEntryBySourceIdAndType@LocationDataLookupDb@@QAE_NAAVQLookupItem@@@Z @ 8 NONAME ; bool LocationDataLookupDb::findEntryBySourceIdAndType(class QLookupItem &)
-	??1LocationDataLookupDb@@UAE@XZ @ 9 NONAME ; LocationDataLookupDb::~LocationDataLookupDb(void)
-	?findEntriesByLandmarkId@LocationDataLookupDb@@QAEXIAAV?$QList@VQLookupItem@@@@@Z @ 10 NONAME ; void LocationDataLookupDb::findEntriesByLandmarkId(unsigned int, class QList<class QLookupItem> &)
-	?close@LocationDataLookupDb@@QAEXXZ @ 11 NONAME ; void LocationDataLookupDb::close(void)
+	?updateEntryBySourceIdAndType@LocationDataLookupDb@@QAEXABVQLookupItem@@@Z @ 3 NONAME ; void LocationDataLookupDb::updateEntryBySourceIdAndType(class QLookupItem const &)
+	?getEntries@LocationDataLookupDb@@QAEXAAV?$QList@VQLookupItem@@@@I@Z @ 4 NONAME ; void LocationDataLookupDb::getEntries(class QList<class QLookupItem> &, unsigned int)
+	?updateEntryById@LocationDataLookupDb@@QAEXABVQLookupItem@@@Z @ 5 NONAME ; void LocationDataLookupDb::updateEntryById(class QLookupItem const &)
+	??0LocationDataLookupDb@@QAE@PAVQObject@@@Z @ 6 NONAME ; LocationDataLookupDb::LocationDataLookupDb(class QObject *)
+	?findEntryBySourceIdAndType@LocationDataLookupDb@@QAE_NAAVQLookupItem@@@Z @ 7 NONAME ; bool LocationDataLookupDb::findEntryBySourceIdAndType(class QLookupItem &)
+	??1LocationDataLookupDb@@UAE@XZ @ 8 NONAME ; LocationDataLookupDb::~LocationDataLookupDb(void)
+	?findEntriesByLandmarkId@LocationDataLookupDb@@QAEXIAAV?$QList@VQLookupItem@@@@@Z @ 9 NONAME ; void LocationDataLookupDb::findEntriesByLandmarkId(unsigned int, class QList<class QLookupItem> &)
+	?close@LocationDataLookupDb@@QAEXXZ @ 10 NONAME ; void LocationDataLookupDb::close(void)
+	?createEntry@LocationDataLookupDb@@QAEXAAVQLookupItem@@@Z @ 11 NONAME ; void LocationDataLookupDb::createEntry(class QLookupItem &)
 	?findEntryById@LocationDataLookupDb@@QAE_NAAVQLookupItem@@@Z @ 12 NONAME ; bool LocationDataLookupDb::findEntryById(class QLookupItem &)
-	?createEntry@LocationDataLookupDb@@QAEXABVQLookupItem@@@Z @ 13 NONAME ; void LocationDataLookupDb::createEntry(class QLookupItem const &)
-	?fillLookupEntry@LocationDataLookupDb@@AAEXAAVQSqlQuery@@AAVQLookupItem@@@Z @ 14 NONAME ; void LocationDataLookupDb::fillLookupEntry(class QSqlQuery &, class QLookupItem &)
-	?open@LocationDataLookupDb@@QAE_NXZ @ 15 NONAME ; bool LocationDataLookupDb::open(void)
-	??_ELocationDataLookupDb@@UAE@I@Z @ 16 NONAME ; LocationDataLookupDb::~LocationDataLookupDb(unsigned int)
-	?findEntriesBySourceType@LocationDataLookupDb@@QAEXIAAV?$QList@VQLookupItem@@@@@Z @ 17 NONAME ; void LocationDataLookupDb::findEntriesBySourceType(unsigned int, class QList<class QLookupItem> &)
+	?fillLookupEntry@LocationDataLookupDb@@AAEXAAVQSqlQuery@@AAVQLookupItem@@@Z @ 13 NONAME ; void LocationDataLookupDb::fillLookupEntry(class QSqlQuery &, class QLookupItem &)
+	?open@LocationDataLookupDb@@QAE_NXZ @ 14 NONAME ; bool LocationDataLookupDb::open(void)
+	??_ELocationDataLookupDb@@UAE@I@Z @ 15 NONAME ; LocationDataLookupDb::~LocationDataLookupDb(unsigned int)
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/locationdataharvester/bwins/mylocationsdatabasemanageru.def	Fri Jun 11 13:33:47 2010 +0300
@@ -0,0 +1,7 @@
+EXPORTS
+	?GetLandmarkFullAddress@CMyLocationsDatabaseManager@@QAEXAAV?$TBuf@$0PP@@@PBVCPosLandmark@@@Z @ 1 NONAME ; void CMyLocationsDatabaseManager::GetLandmarkFullAddress(class TBuf<255> &, class CPosLandmark const *)
+	?ConstructL@CMyLocationsDatabaseManager@@QAEXXZ @ 2 NONAME ; void CMyLocationsDatabaseManager::ConstructL(void)
+	?UpdateMapTilePath@CMyLocationsDatabaseManager@@QAEXKKV?$TBuf@$0BAA@@@@Z @ 3 NONAME ; void CMyLocationsDatabaseManager::UpdateMapTilePath(unsigned long, unsigned long, class TBuf<256>)
+	?UpdateDatabaseL@CMyLocationsDatabaseManager@@QAEXPAVCPosLandmark@@KKK@Z @ 4 NONAME ; void CMyLocationsDatabaseManager::UpdateDatabaseL(class CPosLandmark *, unsigned long, unsigned long, unsigned long)
+	??0CMyLocationsDatabaseManager@@QAE@XZ @ 5 NONAME ; CMyLocationsDatabaseManager::CMyLocationsDatabaseManager(void)
+
--- a/locationdataharvester/eabi/locationdatalookupdbu.def	Thu May 27 12:49:34 2010 +0300
+++ b/locationdataharvester/eabi/locationdatalookupdbu.def	Fri Jun 11 13:33:47 2010 +0300
@@ -1,23 +1,21 @@
 EXPORTS
 	_ZN20LocationDataLookupDb10getEntriesER5QListI11QLookupItemEj @ 1 NONAME
-	_ZN20LocationDataLookupDb11createEntryERK11QLookupItem @ 2 NONAME
+	_ZN20LocationDataLookupDb11createEntryER11QLookupItem @ 2 NONAME
 	_ZN20LocationDataLookupDb13findEntryByIdER11QLookupItem @ 3 NONAME
-	_ZN20LocationDataLookupDb15deleteEntryByIdERK11QLookupItem @ 4 NONAME
-	_ZN20LocationDataLookupDb15fillLookupEntryER9QSqlQueryR11QLookupItem @ 5 NONAME
-	_ZN20LocationDataLookupDb15updateEntryByIdERK11QLookupItem @ 6 NONAME
-	_ZN20LocationDataLookupDb23findEntriesByLandmarkIdEjR5QListI11QLookupItemE @ 7 NONAME
-	_ZN20LocationDataLookupDb23findEntriesBySourceTypeEjR5QListI11QLookupItemE @ 8 NONAME
-	_ZN20LocationDataLookupDb26findEntryBySourceIdAndTypeER11QLookupItem @ 9 NONAME
-	_ZN20LocationDataLookupDb28deleteEntryBySourceIdAndTypeERK11QLookupItem @ 10 NONAME
-	_ZN20LocationDataLookupDb28updateEntryBySourceIdAndTypeERK11QLookupItem @ 11 NONAME
-	_ZN20LocationDataLookupDb30updateMaptileBySourceIdAndTypeEjj7QString @ 12 NONAME
-	_ZN20LocationDataLookupDb4openEv @ 13 NONAME
-	_ZN20LocationDataLookupDb5closeEv @ 14 NONAME
-	_ZN20LocationDataLookupDbC1EP7QObject @ 15 NONAME
-	_ZN20LocationDataLookupDbC2EP7QObject @ 16 NONAME
-	_ZN20LocationDataLookupDbD0Ev @ 17 NONAME
-	_ZN20LocationDataLookupDbD1Ev @ 18 NONAME
-	_ZN20LocationDataLookupDbD2Ev @ 19 NONAME
-	_ZTI20LocationDataLookupDb @ 20 NONAME
-	_ZTV20LocationDataLookupDb @ 21 NONAME
+	_ZN20LocationDataLookupDb15fillLookupEntryER9QSqlQueryR11QLookupItem @ 4 NONAME
+	_ZN20LocationDataLookupDb15updateEntryByIdERK11QLookupItem @ 5 NONAME
+	_ZN20LocationDataLookupDb23findEntriesByLandmarkIdEjR5QListI11QLookupItemE @ 6 NONAME
+	_ZN20LocationDataLookupDb26findEntryBySourceIdAndTypeER11QLookupItem @ 7 NONAME
+	_ZN20LocationDataLookupDb28deleteEntryBySourceIdAndTypeERK11QLookupItem @ 8 NONAME
+	_ZN20LocationDataLookupDb28updateEntryBySourceIdAndTypeERK11QLookupItem @ 9 NONAME
+	_ZN20LocationDataLookupDb30updateMaptileBySourceIdAndTypeEjj7QString @ 10 NONAME
+	_ZN20LocationDataLookupDb4openEv @ 11 NONAME
+	_ZN20LocationDataLookupDb5closeEv @ 12 NONAME
+	_ZN20LocationDataLookupDbC1EP7QObject @ 13 NONAME
+	_ZN20LocationDataLookupDbC2EP7QObject @ 14 NONAME
+	_ZN20LocationDataLookupDbD0Ev @ 15 NONAME
+	_ZN20LocationDataLookupDbD1Ev @ 16 NONAME
+	_ZN20LocationDataLookupDbD2Ev @ 17 NONAME
+	_ZTI20LocationDataLookupDb @ 18 NONAME
+	_ZTV20LocationDataLookupDb @ 19 NONAME
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/locationdataharvester/eabi/mylocationsdatabasemanageru.def	Fri Jun 11 13:33:47 2010 +0300
@@ -0,0 +1,8 @@
+EXPORTS
+	_ZN27CMyLocationsDatabaseManager10ConstructLEv @ 1 NONAME
+	_ZN27CMyLocationsDatabaseManager15UpdateDatabaseLEP12CPosLandmarkmmm @ 2 NONAME
+	_ZN27CMyLocationsDatabaseManager17UpdateMapTilePathEmm4TBufILi256EE @ 3 NONAME
+	_ZN27CMyLocationsDatabaseManager22GetLandmarkFullAddressER4TBufILi255EEPK12CPosLandmark @ 4 NONAME
+	_ZN27CMyLocationsDatabaseManagerC1Ev @ 5 NONAME
+	_ZN27CMyLocationsDatabaseManagerC2Ev @ 6 NONAME
+
--- a/locationdataharvester/geocodeupdate/src/geocodeupdate.cpp	Thu May 27 12:49:34 2010 +0300
+++ b/locationdataharvester/geocodeupdate/src/geocodeupdate.cpp	Fri Jun 11 13:33:47 2010 +0300
@@ -56,8 +56,7 @@
     MYLOCLOGSTRING("contactManger object created .");
 
     MYLOCLOGSTRING("contactManger object is not null .");
-    QStringList definitionRestrictions;
-    QContact contact = contactManger->contact(contactId ,definitionRestrictions);
+    QContact contact = contactManger->contact( contactId );
     QContactGeoLocation location;
 
     switch (addressType)
--- a/locationdataharvester/inc/mylocationsdefines.h	Thu May 27 12:49:34 2010 +0300
+++ b/locationdataharvester/inc/mylocationsdefines.h	Fri Jun 11 13:33:47 2010 +0300
@@ -38,9 +38,27 @@
    
     // File Path
     TFileName iFilePath;
+    
+    //MK  map tile fetching status
+    TUint32 iFetchingStatus;
 };
 
+/** Defines map tile fetching states.
+ */
 
+enum TMapTileFetchingState
+    {
+    /** Map tile fetching completed */
+    EMapTileFectchingCompleted,
+    /** Map tile fetching in progress */
+    EMapTileFetchingInProgress,
+    /** Map  tile fetching n/w error */
+    EMapTileFetchingNetworkError,
+    /** Map tile fetching invalid address */
+    EMapTileFetchingInvalidAddress,
+    /** Map tile fetching unknown erro */
+    EMapTileFetchingUnknownError
+    };
 // contacts category in landmarks db
 _LIT( KContactsCategory, "Contacts" );
 
@@ -79,6 +97,7 @@
 // maptile database column names
 _LIT( NCntColUid, "cntuid" );
 _LIT( NCntColFilePath, "filepath" );
+_LIT( MapTileFetchingStatus, "fetchingstatus" );
 
 // database table name
 _LIT( KLookupTable, "lookuptable" );
@@ -97,6 +116,8 @@
 const TInt KColumncntUid = 1;
 // source type column number
 const TInt KColumnFilePath = 3;
+// fetching state  column number
+const TInt KColumnMapTileFetchingStatus = 4;
 
 const TInt KBufSize=256;
 
--- a/locationdataharvester/locationdataharvester.pro	Thu May 27 12:49:34 2010 +0300
+++ b/locationdataharvester/locationdataharvester.pro	Fri Jun 11 13:33:47 2010 +0300
@@ -20,7 +20,7 @@
 
 
 TEMPLATE = subdirs
-SUBDIRS = locationdatalookupdb maptileservice geocodeupdate mylocationsengine
+SUBDIRS = locationdatalookupdb maptileservice geocodeupdate mylocationsdatabasemanager mylocationsengine
 
 
 # Exports
--- a/locationdataharvester/locationdatalookupdb/locationdatalookupdb.cpp	Thu May 27 12:49:34 2010 +0300
+++ b/locationdataharvester/locationdatalookupdb/locationdatalookupdb.cpp	Fri Jun 11 13:33:47 2010 +0300
@@ -34,7 +34,10 @@
 // Constructor
 // ---------------------------------------------------------
 //
-LocationDataLookupDb::LocationDataLookupDb( QObject *parent) : QObject(parent)
+LocationDataLookupDb::LocationDataLookupDb( QObject *parent) : 
+        QObject( parent ),
+        mDb( NULL ),
+        mDbOpen( false )
 {
     mDb = new QSqlDatabase();
     *mDb = QSqlDatabase::addDatabase( "QSQLITE" );
@@ -83,7 +86,11 @@
 // ---------------------------------------------------------
 bool LocationDataLookupDb::open()
 {
-    return mDb->open();
+    if( !mDbOpen )
+    {
+        mDbOpen = mDb->open();
+    }
+    return mDbOpen;
 }
 
 // ---------------------------------------------------------
@@ -91,16 +98,17 @@
 // ---------------------------------------------------------
 void LocationDataLookupDb::close()
 {
-    if( mDb )
+    if( mDbOpen )
         mDb->close();
+    mDbOpen = false;
 }
 
 // ---------------------------------------------------------
 // LocationDataLookupDb::createEntry()
 // ---------------------------------------------------------
-void LocationDataLookupDb::createEntry( const QLookupItem& aLookupItem )
+void LocationDataLookupDb::createEntry( QLookupItem& aLookupItem )
 {
-    if( mDb )
+    if( mDbOpen )
     {
         QSqlQuery query(*mDb);
         query.prepare("INSERT INTO lplookup ("
@@ -153,6 +161,10 @@
         query.bindValue(":iconpath", aLookupItem.mIconPath);
         query.bindValue(":maptile", aLookupItem.mMapTilePath);
         query.exec();
+        
+        QVariant var = query.lastInsertId();
+        aLookupItem.mId = var.toInt();
+        
     }
 }
 
@@ -161,7 +173,7 @@
 // ---------------------------------------------------------
 void LocationDataLookupDb::updateEntryBySourceIdAndType( const QLookupItem& aLookupItem )
 {
-    if( mDb )
+    if( mDbOpen )
     {
         QSqlQuery query(*mDb);
         query.prepare("UPDATE lplookup SET "
@@ -213,7 +225,7 @@
 void LocationDataLookupDb::updateMaptileBySourceIdAndType( quint32 aSourceId, 
         quint32 aSourceType, QString aImagePath )
 {
-    if( mDb )
+    if( mDbOpen )
     {
         QSqlQuery query(*mDb);
         query.prepare("UPDATE lplookup SET "
@@ -233,7 +245,7 @@
 // ---------------------------------------------------------
 void LocationDataLookupDb::updateEntryById( const QLookupItem& aLookupItem )
 {
-    if( mDb )
+    if( mDbOpen )
     {
         QSqlQuery query(*mDb);
         query.prepare("UPDATE lplookup SET "
@@ -283,7 +295,7 @@
 // ---------------------------------------------------------
 void LocationDataLookupDb::deleteEntryBySourceIdAndType( const QLookupItem& aLookupItem )
 {
-    if( mDb )
+    if( mDbOpen )
     {
         QSqlQuery query(*mDb);
         query.prepare( "DELETE FROM lplookup "
@@ -297,27 +309,11 @@
 }
 
 // ---------------------------------------------------------
-// LocationDataLookupDb::deleteEntryById()
-// ---------------------------------------------------------
-void LocationDataLookupDb::deleteEntryById( const QLookupItem& aLookupItem )
-{
-    if( mDb )
-    {
-        QSqlQuery query(*mDb);
-        query.prepare( "DELETE FROM lplookup "
-                       "WHERE id = ?" );
-    
-        query.addBindValue( aLookupItem.mId );
-        query.exec();
-    }
-}
-
-// ---------------------------------------------------------
 // LocationDataLookupDb::findEntryBySourceIdAndType()
 // ---------------------------------------------------------
 bool LocationDataLookupDb::findEntryBySourceIdAndType( QLookupItem& aLookupItem )
 {
-    if( mDb )
+    if( mDbOpen )
     {
         QSqlQuery query(*mDb);
         query.prepare( "SELECT * FROM lplookup "    
@@ -343,7 +339,7 @@
 // ---------------------------------------------------------
 bool LocationDataLookupDb::findEntryById( QLookupItem& aLookupItem )
 {
-    if( mDb )
+    if( mDbOpen )
     {
         QSqlQuery query(*mDb);
         query.prepare( "SELECT * FROM lplookup "    
@@ -371,7 +367,7 @@
 void LocationDataLookupDb::findEntriesByLandmarkId( const quint32 aLandmarkId, 
         QList<QLookupItem>& aLookupItemArray )
 {
-    if( mDb )
+    if( mDbOpen )
     {
 
         QSqlQuery query(*mDb);
@@ -389,36 +385,12 @@
         } 
     }   
 }
-
-// ---------------------------------------------------------
-// LocationDataLookupDb::findEntriesBySourceType()
-// ---------------------------------------------------------
-void LocationDataLookupDb::findEntriesBySourceType( const quint32 aSourceType, 
-        QList<QLookupItem>& aLookupItemArray )
-{
-    if( mDb )
-    {
-        QSqlQuery query(*mDb);
-        query.prepare( "SELECT * FROM lplookup "    
-                       "WHERE sourceType = ?" );
-        query.addBindValue( aSourceType );
-        query.exec();
-       
-        while( query.next() )
-        {    
-            QLookupItem lookupItem;
-            fillLookupEntry( query, lookupItem );
-            aLookupItemArray.append( lookupItem );
-        }
-    }
-}
-
 // ---------------------------------------------------------
 // LocationDataLookupDb::getEntries()
 // ---------------------------------------------------------
 void LocationDataLookupDb::getEntries( QList<QLookupItem>& aLookupItemArray, const quint32 aCollectionId )
 {
-    if( mDb )
+    if( mDbOpen )
     {
         QSqlQuery query(*mDb);
         if( aCollectionId == ESourceLandmarksContactsCat )
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/locationdataharvester/locationdatalookupdb/tsrc/ut_locationdatalookupdb/ut_locationdatalookupdb.cpp	Fri Jun 11 13:33:47 2010 +0300
@@ -0,0 +1,307 @@
+/*
+* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description: location data lookup db unit test cases
+*
+*/
+
+#include <QtTest/QtTest>
+#include <QtGui>
+#include <QString>
+
+#include <locationdatalookupdb.h>
+#include <locationservicedefines.h>
+
+
+//Lookup db test interface class
+class LocationDataLookupDbTest: public QObject
+{
+    Q_OBJECT
+    
+public: 
+    void fillLookupItem( QLookupItem &aItem );
+    
+private slots:
+    
+    void testLocationDataLookupDb();
+    void testNegative(); 
+    void testCase1(); 
+    void testCase2();
+    void testFindEntriesByLandmarkId();
+    void testGetEntries();
+};
+
+
+//Checks whether location data lookup db created.
+void LocationDataLookupDbTest::testLocationDataLookupDb()
+{
+    LocationDataLookupDb* lDb = new LocationDataLookupDb();   
+    QVERIFY( lDb != NULL );
+    delete lDb;
+}
+
+//Checks the create entry function
+void LocationDataLookupDbTest::testNegative()
+{
+    LocationDataLookupDb* lDb = new LocationDataLookupDb();
+    QLookupItem item;
+    QList<QLookupItem> itemArray;
+    lDb->createEntry( item );
+    lDb->updateEntryById( item );
+    lDb->updateEntryBySourceIdAndType( item );
+    lDb->updateMaptileBySourceIdAndType( item.mSourceUid, item.mSourceType, "" );
+    lDb->deleteEntryBySourceIdAndType( item );
+    lDb->getEntries( itemArray );
+    QVERIFY( itemArray.count() == 0 );
+    lDb->findEntriesByLandmarkId( item.mDestId, itemArray );
+    QVERIFY( itemArray.count() == 0 );
+    bool returnFlag = lDb->findEntryBySourceIdAndType( item );
+    QVERIFY( returnFlag == false );
+    returnFlag = lDb->findEntryById( item );
+    QVERIFY( returnFlag == false );
+    lDb->close();
+    delete lDb;
+}
+
+// tests open(), createEntry(), findEntryById(), findEntryBySourceIdAndType(),
+// deleteEntryBySourceIdAndType(), close() apis
+void LocationDataLookupDbTest::testCase1()
+{
+    LocationDataLookupDb* lDb = new LocationDataLookupDb();
+    bool flag = lDb->open();
+    QVERIFY( flag == true );
+    
+    flag == false;
+    flag = lDb->open();
+    QVERIFY( flag == true );
+    
+    QLookupItem item1, item2;    
+
+    // find a lookup item with invalid id. return value should be false
+    item2.mId = 0;
+    flag = true;
+    flag = lDb->findEntryById( item2 );
+    QVERIFY( flag == false );
+
+    // find a lookup item using source id and type. Item not found condition verified
+    item2.mSourceType = ESourceCalendar;
+    item2.mSourceUid = 0;
+    flag = true;
+    flag = lDb->findEntryBySourceIdAndType( item2 );
+    QVERIFY( flag == false );
+
+    // add an item1, check the mId is valid
+    fillLookupItem( item1 );
+    lDb->createEntry( item1 );
+    QVERIFY( item1.mId != 0 );
+
+    // Find entry by id. Try to find the entry just added.
+    item2.mId = item1.mId;
+    flag = false;
+    flag = lDb->findEntryById( item2 );
+    QVERIFY( flag == true );
+    
+    // Find entry by source id and type. Try to find the entry just added.
+    item2.mSourceType = item1.mSourceType;
+    item2.mSourceUid = item1.mSourceUid;
+    flag = false;
+    flag = lDb->findEntryBySourceIdAndType( item2 );
+    QVERIFY( flag == true );    
+    
+    // delete the entry just added
+    item2.mSourceType = item1.mSourceType;
+    item2.mSourceUid = item1.mSourceUid;
+    lDb->deleteEntryBySourceIdAndType( item2 );
+    
+    // verify that the deleted entry is not found.
+    flag = true;
+    flag = lDb->findEntryById( item1 );
+    QVERIFY( flag == false );
+    
+    lDb->close();
+    delete lDb;    
+}
+
+// tests updateEntryBySourceIdAndType(), updateEntryById(),
+// updateMaptileBySourceIdAndType() apis
+void LocationDataLookupDbTest::testCase2()
+{
+    LocationDataLookupDb* lDb = new LocationDataLookupDb();
+    bool flag = lDb->open();
+    QVERIFY( flag == true );
+    
+    QLookupItem item1, item2;    
+
+    // add an item1, check the mId is valid
+    fillLookupItem( item1 );
+    lDb->createEntry( item1 );
+    QVERIFY( item1.mId != 0 );
+
+    // Find entry by id. Try to find the entry just added.
+    item2.mId = item1.mId;
+    item2.mName = "new name";
+    lDb->updateEntryById( item2 );
+    flag = false;
+    flag = lDb->findEntryById( item1 );
+    QVERIFY( flag == true );
+    QVERIFY( item1.mName == "new name" );
+    
+    item1.mName = "new name2";
+    lDb->updateEntryBySourceIdAndType( item1 );
+    lDb->updateMaptileBySourceIdAndType( item1.mSourceUid,
+            item1.mSourceType, "new maptile" );
+    
+    flag = false;
+    flag = lDb->findEntryById( item2 );
+    QVERIFY( flag == true );
+    QVERIFY( item2.mName == "new name2" );
+    QVERIFY( item2.mMapTilePath == "new maptile" );
+    
+    // delete the entry just added
+    lDb->deleteEntryBySourceIdAndType( item2 );    
+    
+    lDb->close();
+    delete lDb;
+}
+
+// tests findEntriesByLandmarkId()
+void LocationDataLookupDbTest::testFindEntriesByLandmarkId()
+{
+    LocationDataLookupDb* lDb = new LocationDataLookupDb();
+    bool flag = lDb->open();
+    QVERIFY( flag == true );
+    
+    QLookupItem item1, item2;    
+
+    // add an item1, check the mId is valid
+    item1.mDestId = 10;
+    item1.mName = "lm1";
+    item1.mSourceType = ESourceCalendar;
+    item1.mSourceUid = 1;
+    
+    item2.mDestId = 10;
+    item2.mName = "lm2";
+    item2.mSourceType = ESourceCalendar;
+    item2.mSourceUid = 2;
+    
+    lDb->createEntry( item1 );
+    lDb->createEntry( item2 );
+    QVERIFY( item1.mId != 0 );
+    QVERIFY( item2.mId != 0 );
+
+    // Find entry by id. Try to find the entry just added.
+    QList<QLookupItem> itemArray;
+    lDb->findEntriesByLandmarkId( 10, itemArray );
+    QVERIFY( itemArray.count() == 2 );
+    QVERIFY( itemArray[0].mName == "lm1" );
+    QVERIFY( itemArray[1].mName == "lm2" );
+
+    // delete the entry just added
+    lDb->deleteEntryBySourceIdAndType( item1 );    
+    lDb->deleteEntryBySourceIdAndType( item2 );    
+    
+    lDb->close();
+    delete lDb;
+}
+
+// tests getEntries()
+void LocationDataLookupDbTest::testGetEntries()
+{
+    LocationDataLookupDb* lDb = new LocationDataLookupDb();
+    bool flag = lDb->open();
+    QVERIFY( flag == true );
+
+    // Find entry by id. Try to find the entry just added.
+    QList<QLookupItem> itemArray;
+    lDb->getEntries( itemArray );
+    QVERIFY( itemArray.count() == 0 );
+    
+    itemArray.clear();
+
+    QLookupItem item;    
+
+    // add an item1, check the mId is valid
+    item.mDestId = 10;
+    item.mName = "contact1";
+    item.mSourceType = ESourceContactsHome;
+    item.mSourceUid = 1;
+    lDb->createEntry( item );
+
+    item.mDestId = 11;
+    item.mName = "contact2";
+    item.mSourceType = ESourceContactsHome;
+    item.mSourceUid = 2;
+    lDb->createEntry( item );
+
+    item.mDestId = 12;
+    item.mName = "calendar entry";
+    item.mSourceType = ESourceCalendar;
+    item.mSourceUid = 2;
+    lDb->createEntry( item );
+
+
+    item.mDestId = 13;
+    item.mName = "landmark";
+    item.mSourceType = ESourceLandmarks;
+    item.mSourceUid = 13;
+    lDb->createEntry( item );
+
+    lDb->getEntries( itemArray, ESourceLandmarksContactsCat );
+    QVERIFY( itemArray.count() == 2 );
+
+    itemArray.clear();
+    lDb->getEntries( itemArray, ESourceLandmarksCalendarCat );
+    QVERIFY( itemArray.count() == 1 );
+    QVERIFY( itemArray[0].mName == "calendar entry" );
+
+    itemArray.clear();
+    lDb->getEntries( itemArray, ESourceLandmarks );
+    QVERIFY( itemArray.count() == 1 );
+    QVERIFY( itemArray[0].mName == "landmark" );
+
+    itemArray.clear();
+    lDb->getEntries( itemArray );
+    QVERIFY( itemArray.count() == 4 );
+
+    for( int i = 0; i < itemArray.count(); i++ )
+        lDb->deleteEntryBySourceIdAndType( itemArray[i] );    
+    
+    lDb->close();
+    delete lDb;
+}
+
+
+void LocationDataLookupDbTest::fillLookupItem( QLookupItem &aItem )
+{
+    aItem.mId = 0;
+    aItem.mCity = "city";
+    aItem.mCountry = "country";
+    aItem.mDestId = 2;
+    aItem.mIconPath = "iconpath";
+    aItem.mIconType = QLookupItem::EIconTypeDefault;
+    aItem.mIsDuplicate = 0;
+    aItem.mLatitude = 0.1;
+    aItem.mLongitude = 0.2;
+    aItem.mMapTilePath = "maptilepath";
+    aItem.mName = "name";
+    aItem.mPostalCode = "postalcode";
+    aItem.mSourceType = ESourceCalendar;
+    aItem.mSourceUid = 3;
+    aItem.mState = "state";
+    aItem.mStreet = "street";
+}
+
+QTEST_MAIN(LocationDataLookupDbTest)
+#include "ut_locationdatalookupdb.moc"
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/locationdataharvester/locationdatalookupdb/tsrc/ut_locationdatalookupdb/ut_locationdatalookupdb.pro	Fri Jun 11 13:33:47 2010 +0300
@@ -0,0 +1,33 @@
+#/*
+#* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+#* All rights reserved.
+#* This component and the accompanying materials are made available
+#* under the terms of "Eclipse Public License v1.0"
+#* which accompanies this distribution, and is available
+#* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+#*
+#* Initial Contributors:
+#* Nokia Corporation - initial contribution.
+#*
+#* Contributors:
+#*
+#* Description: location data lookup db unit test case pro file
+#*
+#*/
+
+TEMPLATE = app
+CONFIG += hb
+QT += testlib
+
+symbian:
+{
+   SYSTEMINCLUDEPATH += \epoc32\include\stdapis
+}
+
+SOURCES += ut_locationdatalookupdb.cpp
+
+
+LIBS += -llocationdatalookupdb
+
+TARGET.CAPABILITY = ALL -TCB    
+
--- a/locationdataharvester/maptileservice/inc/maptiledblookuptable.h	Thu May 27 12:49:34 2010 +0300
+++ b/locationdataharvester/maptileservice/inc/maptiledblookuptable.h	Fri Jun 11 13:33:47 2010 +0300
@@ -43,6 +43,8 @@
 // source type column number
 const TInt KColumnFilePath = 3;
 
+const TInt KColumnMapTileFetchingStatus = 4;
+
 
 /**
  *  Maptile database lookup entry
@@ -64,6 +66,8 @@
     
     // File Path
     TFileName iFilePath;
+    //MK  map tile fetching status
+     TUint32 iFetchingStatus;    
 };
 
 /**
--- a/locationdataharvester/maptileservice/src/maptiledblookuptable.cpp	Thu May 27 12:49:34 2010 +0300
+++ b/locationdataharvester/maptileservice/src/maptiledblookuptable.cpp	Fri Jun 11 13:33:47 2010 +0300
@@ -32,6 +32,8 @@
 _LIT( KStringAnd, " AND " );
 
 
+
+
 // -----------------------------------------------------------------------------
 // CLookupMapTileDatabase::CLookupMapTileDatabase()
 // Default constructor.
--- a/locationdataharvester/maptileservice/src/maptileservice.cpp	Thu May 27 12:49:34 2010 +0300
+++ b/locationdataharvester/maptileservice/src/maptileservice.cpp	Fri Jun 11 13:33:47 2010 +0300
@@ -28,6 +28,7 @@
 // Central Repository Key IDs
 const TInt KEnableLocationFeature  = 0x1;
 
+
 // -----------------------------------------------------------------------------
 // MapTileService::isLocationFeatureEnabled()
 // Checks whether location feature is enabled or disabled
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/locationdataharvester/mylocationsdatabasemanager/inc/mylocationsdatabasemanager.h	Fri Jun 11 13:33:47 2010 +0300
@@ -0,0 +1,228 @@
+/*
+* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description: Database manager implementation 
+*
+*/
+
+#ifndef __MYLOCATIONSDATABASEMANAGER_H__
+#define __MYLOCATIONSDATABASEMANAGER_H__
+
+
+#include <EPos_CPosLandmark.h>
+
+#include <locationservicedefines.h>
+// lookup database
+#include <locationdatalookupdb.h>
+
+
+class CPosLandmarkDatabase;
+class CPosLmCategoryManager;
+
+
+/**
+ * CMyLocationsDatabaseManager class.
+ *  This class handles all the operations related to mylocations landmark database.
+ *
+ */
+class  CMyLocationsDatabaseManager : public CBase
+    {
+    public:
+
+        // Constructors and destructor
+    
+        /**
+         * CMyLocationsDatabaseManager.
+         * C++ default constructor. 
+         */
+        IMPORT_C CMyLocationsDatabaseManager();
+
+        /**
+         * ConstructL.
+         * 2nd phase constructor.
+         */
+        IMPORT_C void ConstructL();
+        
+        /**
+         * ~CMyLocationsDatabaseManager.
+         * Virtual Destructor.
+         */
+        virtual ~CMyLocationsDatabaseManager();
+        
+    public:
+        /**
+         * UpdateDatabaseL.
+         * Updates the location into the landmark database and lookup table. 
+         * Based on the entry source type and the entry change type the updation can be 
+         * addition/modification/deletion.
+         * 
+         * @param[in] aLandmark Landmark object to be updated in the database.
+         * @param[in] aUid Uid of the changed source entry.
+         * @param[in] aSourceType Source type of the aUid.
+         * @param[in] aChangeType Type of change to the entry ( added/modified/deleted )
+         */
+        IMPORT_C void UpdateDatabaseL( CPosLandmark* aLandmark, const TUint32 aUid, 
+                              const TUint32 aSourceType, const TUint32 aChangeType );
+        
+        /** Gets the full address from a given landmark object
+         *
+         * @param[out] aLandmarkAddress comma separated landmark's full address
+         * @param[in] aLandmark landmark object whose address needs to be found.
+         */      
+        IMPORT_C void GetLandmarkFullAddress( TBuf<255>& aLandmarkAddress, 
+                                     const CPosLandmark* aLandmark );
+       
+	    /** Update the maptile path to mylocation lookup table
+         *
+         * @param[in] aSourceId Uid of the changed source entry.
+		 * @param[in] aSourceType Source type of the aSourceId.
+         * @param[in] aFilePath Maptile file path.
+         */                               
+        IMPORT_C void UpdateMapTilePath( TUint32 aSourceId, TUint32 aSourceType, 
+                                            TFileName aFilePath );
+
+#ifdef LOCATION_DATA_HARVESTER_UNIT_TEST
+public:
+#else
+private:
+#endif
+        
+        /**
+         * AddMylocationsCategory.
+         * Adds the category to landmarks database. 
+         * Used to add location picker specific categories.
+         * @param[in] aCategoryName defines the category name to be added.
+         * @returns The category id. 
+         */
+        TUint32 AddMylocationsCategoryL(  const TDesC&  aCategoryName  );
+
+        /**
+         * CheckIfDuplicateExistsL.
+         * Checks if this landmark is already present in database. 
+         * If present returns the landmark id, else 0.
+         * @param[in] aLandmark A landmark object to be checked for.
+         * @returns If no duplicate is found in database returns 0 
+         * else returns the id of the found landmark.
+         */
+        TPosLmItemId CheckIfDuplicateExistsL( const CPosLandmark* aLandmark );
+        
+        /**
+         * CompareLandmarks.
+         * Compares two landmarks. Only the text fields, landmark name, 
+         * street, city, state country and postal code are compared. 
+         * @param[in] aLandmark1 First landmark object to be compared.
+         * @param[in] aLandmark2 Second landmark object to be compared.
+         * @returns ETrue if the landmarks are same, else returns EFalse.
+         */
+       TBool CompareLandmarks( const CPosLandmark* alandmark1, 
+                               const CPosLandmark* alandmark2 );
+        
+       /**
+         * HandleEntryAdditionL.
+         * Handles the entry addition in lookup table and landmarks db
+         * @param[in] aLandmark Landmark object added.
+         * @param[in] aUid Uid of the source entry corresponding to aLandmark..
+         * @param[in] aSourceType source type of the aUid passed.
+        */
+       void HandleEntryAdditionL( CPosLandmark*  aLandmark, const TUint32 aUid,
+                                  const TUint32 aSourceType );
+
+       /**
+         * HandleEntryModificationL.
+         * Handles the entry modification in lookup table and landmarks db
+         * @param[in] aLandmark Landmark object modified.
+         * @param[in] aUid Uid of the source entry corresponding to aLandmark..
+         * @param[in] aSourceType source type of the aUid passed.
+        */
+       void HandleEntryModificationL( CPosLandmark*  aLandmark, const TUint32 aUid,
+                                      const TUint32 aSourceType );
+
+       /**
+         * HandleEntryDeletionL.
+         * Handles the entry deletion in lookup table and landmarks db
+         * @param[in] aUid Uid of the source entry corresponding to aLandmark..
+         * @param[in] aSourceType source type of the aUid passed.
+        */
+       void HandleEntryDeletionL( const TUint32 aUid, const TUint32 aSourceType );
+
+       /**
+         * HandleLandmarkModificationL.
+         * Handles a landmark modification
+         * @param[in] aLandmark Landmark object modified.
+         * @param[in] aUid Uid of the source entry corresponding to aLandmark..
+        */
+       void HandleLandmarkModificationL( CPosLandmark* aLandmark, const TUint32 aUid );
+       /**
+          * CheckAndReadLandmarkL.
+          * Checks whether a category is available in database pointed by category manager.
+          * @param[in] CPosLandmarkDatabase handle to the database manager
+          * @param[in] aLmId Id of the landmark
+          * @returns landmark object if found else NULL
+         */
+       CPosLandmark* CheckAndReadLandmarkL( 
+                       CPosLandmarkDatabase* aDb, const TUint32 aLmId );
+        /**
+          * FillLookupItemAddressDetails.
+          * Fills address details into QLookupItem from CPosLandmark.
+          * @param[in] aLandmark a landmark object
+          * @param[out] aLookupItem, a lookup item in which the address details are filled
+         */
+       void FillLookupItemAddressDetails( CPosLandmark* aLandmark, QLookupItem &aLookupItem );
+
+        /**
+          * UnsetDuplicateNextCalEntry.
+          * Finds a calendar lookup entry whose detination id  is aLandmarkId
+		  * and unsets it duplcate flag.
+          * @param[in] aLandmarkId a landmark id.
+         */
+       void UnsetDuplicateNextCalEntry( quint32 aLandmarkId );
+
+        /**
+          * IsDuplicateCalEntry.
+          * Checks if there is a duplicate entry present whose destination id 
+		  * is aLandmarkId
+          * @param[in] aLandmarkId a landmark id.
+         */
+       bool IsDuplicateEntry( quint32 aLandmarkId );
+
+        /**
+          * CreateLandmarkItemLC.
+          * Creates a landmark from a QLookupItem
+          * @param[in] aLookupItem a lookup item.
+          * @returns CPosLandmark a newly created landmark.
+         */
+       CPosLandmark* CreateLandmarkItemLC( const QLookupItem &aLookupItem );
+       
+#ifdef LOCATION_DATA_HARVESTER_UNIT_TEST
+public:
+#else
+private:
+#endif
+        // Handle to the landmark database
+        CPosLandmarkDatabase* iLandmarkDb;
+
+        // Calendar category to be created for calendar related location entries in landmark database
+        TPosLmItemId iLmCalendarCatId;  
+        // Contacts category to be created for contacts related location entries in landmark database
+        TPosLmItemId iLmContactsCatId;  
+       
+        // handle to the location app lookup database.
+        LocationDataLookupDb*  iLocationAppLookupDb;
+
+        // handle to landmarks category manager
+        CPosLmCategoryManager* iLandmarksCatManager;
+
+        // handle to the file session
+        RFs iFsSession;
+    };
+#endif  // __MYLOCATIONSDATABASEMANAGER_H__
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/locationdataharvester/mylocationsdatabasemanager/mylocationsdatabasemanager.pro	Fri Jun 11 13:33:47 2010 +0300
@@ -0,0 +1,61 @@
+#
+# Copyright (c) 2010  Nokia Corporation and/or its subsidiary(-ies).
+
+
+#
+# All rights reserved.
+# This component and the accompanying materials are made available
+# under the terms of "Eclipse Public License v1.0"
+# which accompanies this distribution, and is available
+# at the URL "http://www.eclipse.org/legal/epl-v10.html".
+#
+# Initial Contributors:
+# Nokia Corporation - initial contribution.
+#
+# Contributors:
+# 
+# Description:
+#
+#
+
+TEMPLATE = lib
+TARGET = mylocationsdatabasemanager   
+
+CONFIG += dll
+CONFIG += Qt
+
+DEPENDPATH += .
+INCLUDEPATH += .
+INCLUDEPATH += ../inc
+INCLUDEPATH += ../mylocationlogger/inc
+
+defines += EPOCALLOWDLLDATA
+
+symbian: { 
+
+    TARGET.EPOCALLOWDLLDATA = 1
+    TARGET.CAPABILITY = All -Tcb
+    TARGET.UID3 = 0x2002FF5C
+    
+    LIBS += -llbs \
+        -leposlandmarks \
+        -leposlmsearchlib \
+        -leuser \
+        -leposlmdbmanlib \
+        -lcntmodel \
+        -lefsrv \
+        -lflogger \
+        -ledbms \
+        -lbafl \
+        -lcalinterimapi \
+        -llocationdatalookupdb
+
+}
+
+SOURCES += src/mylocationsdatabasemanager.cpp 
+
+HEADERS += inc/mylocationsdatabasemanager.h 
+
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/locationdataharvester/mylocationsdatabasemanager/src/mylocationsdatabasemanager.cpp	Fri Jun 11 13:33:47 2010 +0300
@@ -0,0 +1,1086 @@
+/*
+* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description: Database manager implementation 
+*
+*/
+
+#include <EPos_CPosLandmarkCategory.h>
+#include <EPos_CPosLmTextCriteria.h>
+#include <EPos_CPosLandmarkSearch.h>
+#include <EPos_CPosLmDatabaseManager.h>
+#include <EPos_CPosLmNearestCriteria.h>
+#include <EPos_CPosLandmarkDatabase.h>
+#include <EPos_CPosLmCategoryManager.h>
+
+#include <lbsposition.h>
+#include <barsread.h>
+#include <barsc.h>
+#include <locationservicedefines.h>
+#include "mylocationsdatabasemanager.h"
+#include "mylocationlogger.h"
+#include "mylocationsdefines.h"
+
+#include <locationdatalookupdb.h>
+
+// separator
+_LIT( KSeparator, ",");
+// space
+_LIT( KSpace, " ");
+
+// QString separator
+const QString KQStringSeparator = ",";
+// QString space
+const QString KQStringSpace = " ";
+
+// Used to set nearest landmarks search distance criteria
+const TUint32 KSearchCriteriaDistance = 100; 
+
+// Maximum string length of landmark address.
+const TUint32 KMaxAddressLength = 255; 
+
+// -----------------------------------------------------------------------------
+// CMyLocationsDatabaseManager::ConstructL()
+// 2nd phase constructor.
+// -----------------------------------------------------------------------------
+//
+EXPORT_C void CMyLocationsDatabaseManager::ConstructL()
+{
+    __TRACE_CALLSTACK;//Open and intialize Landmark DB
+    iLandmarkDb = CPosLandmarkDatabase::OpenL();
+    ExecuteAndDeleteLD(iLandmarkDb->InitializeL());
+ 
+    iLocationAppLookupDb = new LocationDataLookupDb();
+    if( !iLocationAppLookupDb->open() )
+    {
+        User::Leave( KErrUnknown );
+    }
+    
+    // Create category manager for landmarks
+    iLandmarksCatManager = CPosLmCategoryManager::NewL(*iLandmarkDb);
+
+    // open file session
+    User::LeaveIfError(iFsSession.Connect());
+
+    // Add contacts and calendar  categories
+    iLmContactsCatId = AddMylocationsCategoryL(KContactsCategory);
+    iLmCalendarCatId = AddMylocationsCategoryL( KCalendarCategory );
+
+}
+
+// -----------------------------------------------------------------------------
+// CMyLocationsDatabaseManager::CMyLocationsDatabaseManager()
+// Default constructor.
+// -----------------------------------------------------------------------------
+//
+EXPORT_C  CMyLocationsDatabaseManager::CMyLocationsDatabaseManager() : iLandmarkDb( NULL ),
+                iLmContactsCatId( 0 ), //iLandmarksLookupDb( NULL ), 
+                iLocationAppLookupDb( NULL ),
+                iLandmarksCatManager( NULL )
+{
+}
+
+// -----------------------------------------------------------------------------
+// CMyLocationsDatabaseManager::_CMyLocationsDatabaseManager()
+// Destructor.
+// -----------------------------------------------------------------------------
+//
+CMyLocationsDatabaseManager::~CMyLocationsDatabaseManager()
+{
+    __TRACE_CALLSTACK;// delete member variables.
+
+    if (iLocationAppLookupDb)
+    {
+        iLocationAppLookupDb->close();
+        delete iLocationAppLookupDb;
+    }
+
+    delete iLandmarksCatManager;
+
+    delete iLandmarkDb;
+
+    // close the file session
+    iFsSession.Close();
+
+}
+
+// -----------------------------------------------------------------------------
+// CMyLocationsDatabaseManager::AddMylocationsCategoryL()
+// Adds the category to the mylocations and landmarks database..
+// -----------------------------------------------------------------------------
+//
+TUint32 CMyLocationsDatabaseManager::AddMylocationsCategoryL( const TDesC&  aCategoryName )
+{
+    __TRACE_CALLSTACK;//Open the resource file
+    
+    TPosLmItemId catId = 0;
+    
+    //create category
+    CPosLandmarkCategory *category = CPosLandmarkCategory::NewL();
+    CleanupStack::PushL(category);
+    category->SetCategoryNameL( aCategoryName );
+    
+    // Add category to landmarks database
+    TRAPD ( error, ( catId = iLandmarksCatManager->AddCategoryL( *category ) ) );
+    if (error == KErrNone || error == KErrAlreadyExists)
+    {
+        catId = iLandmarksCatManager->GetCategoryL( aCategoryName );
+    }
+
+    CleanupStack::PopAndDestroy(category);
+
+    return catId;
+}
+
+// -----------------------------------------------------------------------------
+// CMyLocationsDatabaseManager::UpdateDatabaseL()
+// Updates the location into the landmark database and lookup table. Based on 
+// the entry source type and the entry change type the updation can be 
+// addition/modification/deletion.
+// -----------------------------------------------------------------------------
+//
+EXPORT_C void CMyLocationsDatabaseManager::UpdateDatabaseL(CPosLandmark* aLandmark,
+        const TUint32 aUid, const TUint32 aSourceType, const TUint32 aChangeType)
+{
+    __TRACE_CALLSTACK;//open the lookup database
+    switch (aChangeType)
+    {
+    // if the entry is added
+    case EEntryAdded:
+    {
+        // Handle this entry in the lookup table and update landmarks db.
+        HandleEntryAdditionL(aLandmark, aUid, aSourceType);
+        break;
+    }
+        // if the entry is modified
+    case EEntryModified:
+    {
+        // Handle this entry in the lookup table and update landmarks db.
+        HandleEntryModificationL(aLandmark, aUid, aSourceType);
+        break;
+    }
+        // if the entry is deleted
+    case EEntryDeleted:
+    {
+        // Handle this entry in the lookup table and update landmarks db.
+        HandleEntryDeletionL(aUid, aSourceType);
+        break;
+    }
+    }
+
+}
+
+// -----------------------------------------------------------------------------
+// CMyLocationsDatabaseManager::CheckIfDuplicateExistsL()
+// Checks if this landmark is already present in database. If present returns the landmark id, else 0
+// -----------------------------------------------------------------------------
+//
+TPosLmItemId CMyLocationsDatabaseManager::CheckIfDuplicateExistsL(
+                                    const CPosLandmark* aLandmark)
+{
+    __TRACE_CALLSTACK;// Stores the found duplicate landmark's id. 
+    TPosLmItemId retId = 0;
+
+    // Initially filter only the landmarks which are nearer to the current landmark.
+    // Then we can make a duplicate check on each of the found landmarks.
+
+    // create a search object.
+    CPosLandmarkSearch* search = CPosLandmarkSearch::NewL(
+            *iLandmarkDb);
+    CleanupStack::PushL(search);
+
+    TBuf<KMaxAddressLength> lmAddress1;
+    GetLandmarkFullAddress( lmAddress1, aLandmark );
+    QString str1 = QString( (QChar*)lmAddress1.Ptr(), lmAddress1.Length());
+
+    // create nearest search criteria object
+    TLocality position( TCoordinate( 0, 0), 0 );
+    aLandmark->GetPosition( position );
+    CPosLmNearestCriteria* nearestCriteria = 
+                CPosLmNearestCriteria::NewLC( 
+                        TCoordinate( position.Latitude(), position.Longitude() ) );
+    nearestCriteria->SetMaxDistance( KSearchCriteriaDistance );
+    
+    // Start the search and execute it at once.
+    ExecuteAndDeleteLD( search->StartLandmarkSearchL( *nearestCriteria ) );
+    CleanupStack::PopAndDestroy( nearestCriteria );
+
+    // Retrieve an iterator to access the matching landmarks.
+    CPosLmItemIterator* iter = search->MatchIteratorL();
+    CleanupStack::PushL(iter);
+
+    // Iterate the search matches.
+    TPosLmItemId lmId;
+
+    while( ( lmId = iter->NextL() ) != KPosLmNullItemId )
+    {
+        CPosLandmark* lm = iLandmarkDb->ReadLandmarkLC( lmId );
+        TBuf<KMaxAddressLength> lmAddress2;
+        GetLandmarkFullAddress( lmAddress2, lm );
+        QString str2 = QString( (QChar*)lmAddress2.Ptr(), lmAddress2.Length());
+        CleanupStack::PopAndDestroy( lm );
+        
+        if( str1 == str2 )
+        {
+            retId = lmId;
+            break;
+        }
+    }
+
+    CleanupStack::PopAndDestroy(iter);
+    CleanupStack::PopAndDestroy(search);
+
+    return retId;
+}
+
+// -----------------------------------------------------------------------------
+// CMyLocationsDatabaseManager::CompareLandmarks()
+// Compares two landmarks. Only the text fields, landmark name, street, city, state country and 
+// postal code are compared.
+// -----------------------------------------------------------------------------
+//
+TBool CMyLocationsDatabaseManager::CompareLandmarks(
+        const CPosLandmark* aLandmark1, const CPosLandmark* aLandmark2 )
+{
+    __TRACE_CALLSTACK;
+
+    TBuf<KMaxAddressLength> lmAddress1;
+    GetLandmarkFullAddress( lmAddress1, aLandmark1 );
+    QString str1 = QString( (QChar*)lmAddress1.Ptr(), lmAddress1.Length());
+
+    TBuf<KMaxAddressLength> lmAddress2;
+    GetLandmarkFullAddress( lmAddress2, aLandmark2 );
+    QString str2 = QString( (QChar*)lmAddress2.Ptr(), lmAddress2.Length());
+
+    if( str1 == str2 )
+        return ETrue;
+    else
+        return EFalse;
+    
+    
+}
+
+// -----------------------------------------------------------------------------
+// CMyLocationsDatabaseManager::HandleEntryAdditionL()
+// Handles the entry addition in lookup table and landmarks db
+// -----------------------------------------------------------------------------
+//
+void CMyLocationsDatabaseManager::HandleEntryAdditionL(CPosLandmark* aLandmark,
+        const TUint32 aUid, const TUint32 aSourceType)
+{
+    __TRACE_CALLSTACK;
+    // Create a lookup item
+    QLookupItem lookupItem;
+    lookupItem.mSourceUid = aUid;
+    lookupItem.mSourceType = aSourceType;
+    lookupItem.mDestId = 0;
+    lookupItem.mIconType = QLookupItem::EIconTypeDefault;
+    lookupItem.mIsDuplicate = 0;
+    lookupItem.mIconPath = "";
+    lookupItem.mMapTilePath = "";
+    
+    //fill address into lookup item.
+    FillLookupItemAddressDetails( aLandmark, lookupItem );
+
+    if ( aSourceType == ESourceLandmarks )
+    {
+        // Logic: check if the entry is already present in lookupdb. 
+        // If present, it means the landmark corresponds to a contact/calendar. So ignore it.
+        // If not present, it means the landmark is created directly into the landmarks db. So add
+        // it in lookupdb as well.
+        
+        // check if the entry is already present in lookup db.
+        QList<QLookupItem> itemArray;
+        iLocationAppLookupDb->findEntriesByLandmarkId( aUid, itemArray );
+        if( itemArray.count() )
+        {
+            return;
+        }
+        else
+        {
+            lookupItem.mDestId = aUid;
+            iLocationAppLookupDb->createEntry( lookupItem );
+            return;
+        }
+    }
+
+    TPosLmItemId catId;
+    if( aSourceType == ESourceCalendar )
+    {
+        // category id to calendar
+        catId = iLmCalendarCatId;
+    }
+    else 
+    {
+        // remove landmark name, which is basically contact's name.
+        aLandmark->SetLandmarkNameL( KNullDesC );
+        // category id to contacts
+        catId = iLmContactsCatId;
+    }
+    // check if this landmark is already present in database
+    TPosLmItemId dupLmId = CheckIfDuplicateExistsL( aLandmark );
+    if ( dupLmId )
+    {
+        // landmark already present in db. get the details
+        CPosLandmark* dupLandmark = iLandmarkDb->ReadLandmarkLC(dupLmId);
+        if( dupLandmark )
+        {
+            // add category.
+            dupLandmark->AddCategoryL( catId );
+            // update the landmark object in the db
+            iLandmarkDb->UpdateLandmarkL( *dupLandmark );
+            CleanupStack::PopAndDestroy( dupLandmark );
+        }
+
+        // point the lookup item's landmark uid to the existing landmark.
+        lookupItem.mDestId = dupLmId;
+        if( aSourceType == ESourceCalendar )
+        {
+            // set duplicate flag to true. only if it is calendar entry.
+            // for contacts duplicate doesnot hold good as the location name is the contact name.
+        
+            // set duplicate only if there are calendar entries already pointing to this landmark. 
+            if( IsDuplicateEntry( dupLmId ) )
+            {
+                lookupItem.mIsDuplicate = 1;
+            }
+        }
+    }
+    else // it is a new entry, so add into the database
+    {
+        // add category.
+        aLandmark->AddCategoryL( catId );
+        // add the landmark into the db. 
+        // point the lookup item's landmark uid to the newly created landmark in the db.
+        lookupItem.mDestId = iLandmarkDb->AddLandmarkL( *aLandmark );
+    }
+
+    // create the entry in the lookup table.
+    iLocationAppLookupDb->createEntry( lookupItem );
+}
+
+// -----------------------------------------------------------------------------
+// CMyLocationsDatabaseManager::HandleEntryModificationL()
+// Handles the entry modification in the lookup table and landmarks db.
+// -----------------------------------------------------------------------------
+//
+void CMyLocationsDatabaseManager::HandleEntryModificationL(
+        CPosLandmark* aLandmark, const TUint32 aUid, const TUint32 aSourceType )
+{
+    __TRACE_CALLSTACK;
+    if ( aSourceType == ESourceLandmarks )
+    {
+        HandleLandmarkModificationL( aLandmark, aUid );
+        return;
+    }
+
+    QLookupItem lookupItem;
+    lookupItem.mSourceUid = aUid;
+    lookupItem.mSourceType = aSourceType;
+    lookupItem.mIconType = QLookupItem::EIconTypeDefault;
+
+    // Behavior: If an entry is modified, 
+    // If this entry is not present in lookup table. add the entry and update the landmarks db.
+    // If this entry is already present in lookup table, check if the location info is modified or not.
+    // If the location info is modified, delete the landmark from db and add the new landmark
+    // into the db. 
+    // Before deletion make sure that the landmark is not being refered by other lookup entries.
+
+    // find the entry in the lookup table.
+    if ( iLocationAppLookupDb->findEntryBySourceIdAndType( lookupItem ) )
+    {
+        //fill address into lookup item.
+        FillLookupItemAddressDetails( aLandmark, lookupItem );
+        
+        QString locationName = lookupItem.mName;
+    
+        TPosLmItemId catId;
+        
+        if( aSourceType == ESourceCalendar )
+        {
+            catId = iLmCalendarCatId;
+        }
+        else
+        {
+            // remove landmark name, which is basically contact's name.
+            aLandmark->SetLandmarkNameL( KNullDesC );
+            
+            // category id to contacts
+            catId = iLmContactsCatId;
+        }
+
+        
+        // check if the location info is modified by comparing the new landmark with the existing landmark
+        CPosLandmark* existingLandmark = NULL;
+        TRAPD( error, ( existingLandmark = 
+               CheckAndReadLandmarkL( iLandmarkDb, lookupItem.mDestId ) ) );
+        CleanupStack::PushL( existingLandmark );
+        if ( error == KErrNotFound )
+        {
+            // Landmarks item deleted. So delete corresponding lookup entries.
+            QList<QLookupItem> itemArray;
+            iLocationAppLookupDb->findEntriesByLandmarkId( lookupItem.mDestId, itemArray );
+            for ( int i = 0; i < itemArray.count(); i++)
+            {
+                iLocationAppLookupDb->deleteEntryBySourceIdAndType( itemArray[i] );
+            }
+
+            // Add the entry into the lookup table and update landmarks db.
+            HandleEntryAdditionL( aLandmark, aUid, aSourceType );
+            
+            CleanupStack::PopAndDestroy( existingLandmark );
+            return;
+        }
+
+        if ( !CompareLandmarks( existingLandmark, aLandmark ) )
+        {
+            // landmarks are not same, means location information is modified.
+
+            // Check if the new landmark is already in db.
+            TPosLmItemId dupLmId = CheckIfDuplicateExistsL( aLandmark );
+            if ( dupLmId )
+            {
+                // landmark already present in db. get the details
+                CPosLandmark* dupLandmark = iLandmarkDb->ReadLandmarkLC( dupLmId );
+                if ( dupLandmark )
+                {
+                    // add category.
+                    dupLandmark->AddCategoryL( catId );
+
+                    // update the landmark object in the db
+                    iLandmarkDb->UpdateLandmarkL( *dupLandmark );
+                }
+                CleanupStack::PopAndDestroy( dupLandmark );
+
+                // update the lookup item to refer to the newly created landmark.
+                lookupItem.mDestId = dupLmId;
+                if( aSourceType == ESourceCalendar )
+                {
+                    // for contacts duplicate doesnot hold good as the location name is the contact name.
+                    if( !lookupItem.mIsDuplicate )
+                    {
+                        // if current lookup item duplicate property is 0, then remove next corresponding
+                        // calendar lookup entry duplicate property.
+                        // this is required because the current entry will be pointing to a new landmark.
+                        UnsetDuplicateNextCalEntry( existingLandmark->LandmarkId() );
+                    } 
+
+                    // set duplicate only if there are calendar entries already pointing to this landmark. 
+                    if( IsDuplicateEntry( dupLmId ) )
+                    {
+                        lookupItem.mIsDuplicate = 1;
+                    }
+
+                }
+                
+                iLocationAppLookupDb->updateEntryBySourceIdAndType( lookupItem );
+            }
+            else
+            {
+                // landmark not already present in db.
+                // Create a new entry in the db
+                aLandmark->AddCategoryL( catId );
+                lookupItem.mDestId = iLandmarkDb->AddLandmarkL( *aLandmark );
+                if( aSourceType == ESourceCalendar )
+                {
+                    // for contacts duplicate doesnot hold good as the location name is the contact name.
+                    if( !lookupItem.mIsDuplicate )
+                    {
+                        // if current lookup item duplicate property is 0, then remove next corresponding
+                        // calendar lookup entry duplicate property.
+                        // this is required because the current entry will be pointing to a new landmark.
+                        UnsetDuplicateNextCalEntry( existingLandmark->LandmarkId() );
+                    } 
+                }
+                
+                lookupItem.mIsDuplicate = 0;
+                // update the lookup table
+                iLocationAppLookupDb->updateEntryBySourceIdAndType( lookupItem );
+            }
+        }
+        else
+        {
+            // landmarks are same, means location not modified. So return.
+            if( aSourceType == ESourceContactsPref
+                                    || aSourceType == ESourceContactsWork
+                                    || aSourceType == ESourceContactsHome
+                                    )
+            {
+                // in case of contacts, there is a chance that contact name is modified. 
+                // so update the lookup database entry with that name.
+                lookupItem.mName = locationName;
+                iLocationAppLookupDb->updateEntryBySourceIdAndType( lookupItem );
+            }
+
+            CleanupStack::PopAndDestroy( existingLandmark );
+            return;
+        }
+
+        // delete the existing landmark only if it not being refered by other lookup entries.
+
+        // Check if any other entries are refering this landmark.
+        QList<QLookupItem> itemArray;
+        iLocationAppLookupDb->findEntriesByLandmarkId(
+                existingLandmark->LandmarkId(), itemArray );
+
+        if ( itemArray.count() )
+        {
+            // There are other lookup entries refering this landmark. So do not delete the landmark
+
+            // If none of these lookup item's source type is current source type, disassociate 'catId' category
+            // from this landmark.
+            TInt i = 0;
+            while ( i < itemArray.count() )
+            {
+                if( aSourceType == ESourceCalendar )
+                {
+                    if ( itemArray[i].mSourceType == aSourceType )
+                    {
+                        // a lookup item exists which is from calendar, so 'catId' is still valid.
+                        break;
+                    }
+                 }
+                else 
+                {
+                    // a lookup item exists which is from contacts, so 'catId' is still valid.
+                    break;
+                }
+                i++;
+            }
+            if ( i == itemArray.count() )
+            {
+                // no lookup items from current source type exists refering this landmark.
+                // so disassociate 'catId' from this landmark
+
+                existingLandmark->RemoveCategory( catId );
+                iLandmarkDb->UpdateLandmarkL( *existingLandmark );
+            }
+        }
+        else
+        {
+            // no other lookup entry is refering this landmark. 
+            // delete the landmark.
+            iLandmarkDb->RemoveLandmarkL( existingLandmark->LandmarkId() );
+        }
+        CleanupStack::PopAndDestroy( existingLandmark );
+
+    }
+    else // entry not present in lookup table
+    {
+        // Add the entry into the lookup table and update landmarks db.
+        HandleEntryAdditionL( aLandmark, aUid, aSourceType );
+    }
+}
+
+// -----------------------------------------------------------------------------
+// CMyLocationsDatabaseManager::HandleEntryDeletionL()
+// Handles the entry deletion in lookup table and landmarks db.
+// -----------------------------------------------------------------------------
+//
+void CMyLocationsDatabaseManager::HandleEntryDeletionL(const TUint32 aUid,
+                                                const TUint32 aSourceType)
+{
+    __TRACE_CALLSTACK;
+    QLookupItem lookupItem;
+    lookupItem.mSourceUid = aUid;
+    lookupItem.mSourceType = aSourceType;
+
+    // Behavior: if an entry is deleted, delete the corresponding entries from 
+    // both lookup table and iLandmarkDb.  
+    // Before deleting the entry from iLandmarkDb, make sure that this entry is not being refered by
+    // other entries of the lookup table. If it is being refered by other entries in lookup table, then
+    // do not delete the landmark.
+ 
+    if ( !iLocationAppLookupDb->findEntryBySourceIdAndType( lookupItem ) )
+    {
+        if( aSourceType == ESourceLandmarks )
+        {
+            lookupItem.mDestId = aUid;
+        }
+        else
+        {
+            return;
+        }
+    }
+    
+    // Find the corresponding landmark uid
+    
+
+    // delete the lookup entry.
+    iLocationAppLookupDb->deleteEntryBySourceIdAndType( lookupItem );
+
+    // Check if any other entries are refering this landmark.
+    QList<QLookupItem> itemArray;
+    iLocationAppLookupDb->findEntriesByLandmarkId( lookupItem.mDestId, itemArray );
+
+    if ( itemArray.count() )
+    {
+    
+        if( aSourceType == ESourceLandmarks )
+        {
+            CPosLandmark* lm = NULL;
+        
+            for( int i = 0; i < itemArray.count(); i++ )
+            {
+                if( itemArray[i].mSourceType == ESourceCalendar )
+                {
+                    // add landmark entry since a calendar item is present with this location.
+                   if( !lm )
+                   {
+                       lm = CreateLandmarkItemLC( itemArray[i] );
+                   }
+                   lm->AddCategoryL( iLmCalendarCatId );
+                }
+                else
+                {
+                   // add landmark entry since a contact item is present with this location.
+                   if( !lm )
+                   {
+                       QString tempStr = itemArray[i].mName;
+                       itemArray[i].mName = "";
+                       lm = CreateLandmarkItemLC( itemArray[i] );
+                       itemArray[i].mName = tempStr;
+                   }
+                   lm->AddCategoryL( iLmCalendarCatId );
+                }    
+            }
+
+            lookupItem.mDestId = iLandmarkDb->AddLandmarkL( *lm );
+            CleanupStack::PopAndDestroy( lm );
+
+            bool dupUnset = false;
+            for( int i=0; i<itemArray.count(); i++ )
+            {
+                itemArray[i].mDestId = lookupItem.mDestId;
+                if( itemArray[i].mSourceType == ESourceCalendar && dupUnset == false )
+                {
+                    dupUnset = true;
+                    itemArray[i].mIsDuplicate = 0;
+                }
+                iLocationAppLookupDb->updateEntryById( itemArray[i] );
+            }   
+            
+            return;
+        }
+
+        // There are other lookup entries refering this landmark. So do not delete the landmark
+
+        // If none of these lookup item's source type is current source type, disassociate current source category
+        // from this landmark.
+        TInt i = 0;
+        while ( i < itemArray.count() )
+        {
+            if( aSourceType == ESourceCalendar )
+            {
+                if( itemArray[i].mSourceType == aSourceType )
+                {
+                    if( lookupItem.mIsDuplicate == 0 )
+                    {
+                        itemArray[i].mIsDuplicate = 0;
+                        iLocationAppLookupDb->updateEntryById( itemArray[i] );
+                    }
+                    // a lookup item exists which is from calendar, so 'iLmCalendarCatId' is still valid.
+                    break;
+                }
+        
+            }
+            else if ( itemArray[i].mSourceType == ESourceContactsPref
+                    || itemArray[i].mSourceType == ESourceContactsWork
+                    || itemArray[i].mSourceType == ESourceContactsHome)
+            {
+                // a lookup item exists which is from contacts, so 'iLmContactsCatId' is still valid.
+                break;
+            }
+            i++;
+        }
+        if ( i == itemArray.count() )
+        {
+            // no lookup items from current source type exists refering this landmark.
+            // so disassociate current source category from this landmark
+
+            CPosLandmark* landmark = iLandmarkDb->ReadLandmarkLC( lookupItem.mDestId );
+            if( aSourceType == ESourceCalendar )
+            {
+                landmark->RemoveCategory( iLmCalendarCatId );
+            }
+            else
+            {
+                landmark->RemoveCategory( iLmContactsCatId );
+            }
+            
+            iLandmarkDb->UpdateLandmarkL( *landmark );
+            CleanupStack::PopAndDestroy( landmark );
+        }
+    }
+    else
+    {
+        // no other lookup entry is refering this landmark. 
+        // delete the landmark.
+        if ( aSourceType != ESourceLandmarks )
+        {
+            iLandmarkDb->RemoveLandmarkL( lookupItem.mDestId );
+        }
+    }
+}
+
+// -----------------------------------------------------------------------------
+// CMyLocationsDatabaseManager::HandleLandmarkModificationL()
+// -----------------------------------------------------------------------------
+//
+void CMyLocationsDatabaseManager::HandleLandmarkModificationL(
+        CPosLandmark* aLandmark, const TUint32 aUid )
+{
+    // logic: if a landmark is modified, 
+    // first update the corresponding landmark lookup entry if present, else create a new entry.
+    // Check for any contact/calendar entries refering this landmark entry,
+    // if exists, create a new landmark entry with that location details and update all those 
+    // lookup entry's destid with the newly created landmark id.
+    
+    QLookupItem lookupItem;
+    lookupItem.mSourceUid = aUid;
+    lookupItem.mSourceType = ESourceLandmarks;
+    lookupItem.mIconType = QLookupItem::EIconTypeDefault;
+
+    bool found = iLocationAppLookupDb->findEntryBySourceIdAndType( lookupItem );
+    //fill address into lookup item.
+    FillLookupItemAddressDetails( aLandmark, lookupItem );
+    lookupItem.mDestId = aUid;
+    lookupItem.mIsDuplicate = 0;
+    lookupItem.mIconType = QLookupItem::EIconTypeDefault;
+    lookupItem.mIconPath = "";
+    lookupItem.mMapTilePath = "";
+
+    // update entry in lookup table.
+    if ( found )
+    {
+        iLocationAppLookupDb->updateEntryById( lookupItem );
+    }
+    else
+    {
+        iLocationAppLookupDb->createEntry( lookupItem );
+    }
+    
+    QList<QLookupItem> itemArray;
+    iLocationAppLookupDb->findEntriesByLandmarkId( lookupItem.mDestId, itemArray );
+    
+    if( itemArray.count() == 1 )
+    {
+        //only one entry ie the entry corresponding to landmark db is present.
+        return;
+    }
+    
+    CPosLandmark* lm = NULL;
+    
+    for( int i = 0; i < itemArray.count(); i++ )
+    {
+        if( itemArray[i].mSourceType != ESourceLandmarks )
+        {
+            if( itemArray[i].mSourceType == ESourceCalendar )
+            {
+                // add landmark entry since a calendar item is present with this location.
+               if( !lm )
+               {
+                   lm = CreateLandmarkItemLC( itemArray[i] );
+               }
+               lm->AddCategoryL( iLmCalendarCatId );
+            }
+            else
+            {
+               // add landmark entry since a calendar item is present with this location.
+               if( !lm )
+               {
+                   QString tempStr = itemArray[i].mName;
+                   itemArray[i].mName = "";
+                   lm = CreateLandmarkItemLC( itemArray[i] );
+                   itemArray[i].mName = tempStr;
+               }
+               lm->AddCategoryL( iLmCalendarCatId );
+            }    
+        }
+    }
+    
+    // add the entry to landmarks db
+    quint32 newDestId = iLandmarkDb->AddLandmarkL( *lm );
+    CleanupStack::PopAndDestroy( lm );
+
+    bool calDuplicateUnset = false;
+    // update all the lookup entries with new landmark id
+    for( int i = 0; i < itemArray.count(); i++ )
+    {
+        if( itemArray[i].mSourceType != ESourceLandmarks )
+        {
+            itemArray[i].mDestId = newDestId;
+            
+            if( itemArray[i].mSourceType == ESourceCalendar )
+            {
+                if( !calDuplicateUnset )
+                {
+                    itemArray[i].mIsDuplicate = 0;
+                    calDuplicateUnset = true;
+                }
+                else
+                {
+                    itemArray[i].mIsDuplicate = 1;
+                }
+            }
+            iLocationAppLookupDb->updateEntryById( itemArray[i] );
+        }
+    }
+}
+// -----------------------------------------------------------------------------
+// CMyLocationsDatabaseManager::GetLandmarkFullAddress()
+// Gets the comma separated full address of the given landmark.
+// -----------------------------------------------------------------------------
+//
+EXPORT_C void CMyLocationsDatabaseManager::GetLandmarkFullAddress(
+        TBuf<KMaxAddressLength>& aLandmarkAddress,
+        const CPosLandmark* aLandmark)
+{
+    TPtrC tempStr;
+    TInt retStatus;
+    TBool addressEmtpy = ETrue;
+    retStatus = aLandmark->GetPositionField(EPositionFieldStreet, tempStr);
+    if (retStatus == KErrNone && tempStr.Length())
+    {
+        {
+            aLandmarkAddress.Copy(tempStr);
+            addressEmtpy = EFalse;
+        }
+    }
+
+    retStatus = aLandmark->GetPositionField(EPositionFieldCity, tempStr);
+    if (retStatus == KErrNone && tempStr.Length())
+    {
+        if (!addressEmtpy)
+        {
+            aLandmarkAddress.Append(KSeparator);
+            aLandmarkAddress.Append(KSpace);
+            aLandmarkAddress.Append(tempStr);
+        }
+        else
+        {
+            aLandmarkAddress.Copy(tempStr);
+            addressEmtpy = EFalse;
+        }
+    }
+
+    retStatus = aLandmark->GetPositionField(EPositionFieldState, tempStr);
+    if (retStatus == KErrNone && tempStr.Length())
+    {
+        if (!addressEmtpy)
+        {
+            aLandmarkAddress.Append(KSeparator);
+            aLandmarkAddress.Append(KSpace);
+            aLandmarkAddress.Append(tempStr);
+        }
+        else
+        {
+            aLandmarkAddress.Copy(tempStr);
+            addressEmtpy = EFalse;
+        }
+    }
+
+    retStatus = aLandmark->GetPositionField(EPositionFieldCountry, tempStr);
+    if (retStatus == KErrNone && tempStr.Length())
+    {
+        if (!addressEmtpy)
+        {
+            aLandmarkAddress.Append(KSeparator);
+            aLandmarkAddress.Append(KSpace);
+            aLandmarkAddress.Append(tempStr);
+        }
+        else
+        {
+            aLandmarkAddress.Copy(tempStr);
+            addressEmtpy = EFalse;
+        }
+    }
+}
+
+// -----------------------------------------------------------------------------
+// CMyLocationsDatabaseManager::CheckAndReadLandmarkL()
+// Checks if given landmark id is found in the database and returns the read landmark.
+// -----------------------------------------------------------------------------
+//
+CPosLandmark* CMyLocationsDatabaseManager::CheckAndReadLandmarkL(
+        CPosLandmarkDatabase* aDb, const TUint32 aLmId)
+{
+    __TRACE_CALLSTACK;
+    CPosLandmark* lm = aDb->ReadLandmarkLC(aLmId);
+    CleanupStack::Pop(lm);    
+    return lm;
+}
+
+// -----------------------------------------------------------------------------
+// CMyLocationsDatabaseManager::FillLookupItemAddressDetails()
+// Creates a new category in Mylocations Db and adds a corresponding entry in 
+// mylocations lookup table.
+// -----------------------------------------------------------------------------
+//
+void CMyLocationsDatabaseManager::FillLookupItemAddressDetails( CPosLandmark* aLandmark, QLookupItem& aLookupItem )
+{
+    __TRACE_CALLSTACK;// Read the category.
+
+    // fill geo-coordinates
+    TLocality position;
+    aLandmark->GetPosition( position );
+    aLookupItem.mLatitude = position.Latitude();
+    aLookupItem.mLongitude = position.Longitude();
+
+    TPtrC tempStr;
+    TInt retStatus;
+
+    // Copy landmark name in address 1
+    retStatus = aLandmark->GetLandmarkName( tempStr );
+    aLookupItem.mName = "";
+    if( retStatus == KErrNone && tempStr.Length() > 0 )
+    {
+        aLookupItem.mName = QString( (QChar*)tempStr.Ptr(), tempStr.Length() );
+    }
+
+    // get street
+    aLookupItem.mStreet = "";
+    retStatus = aLandmark->GetPositionField( EPositionFieldStreet, tempStr );
+    if( retStatus == KErrNone && tempStr.Length() )
+    {
+        aLookupItem.mStreet = QString( (QChar*)tempStr.Ptr(), tempStr.Length());
+    }
+
+    // get postal code
+    aLookupItem.mPostalCode = "";
+    retStatus = aLandmark->GetPositionField( EPositionFieldPostalCode, tempStr );
+    if( retStatus == KErrNone && tempStr.Length() )
+    {
+        aLookupItem.mPostalCode = QString( (QChar*)tempStr.Ptr(), tempStr.Length());
+    }
+
+    // get city
+    aLookupItem.mCity = "";
+    retStatus = aLandmark->GetPositionField( EPositionFieldCity, tempStr );
+    if( retStatus == KErrNone && tempStr.Length() )
+    {
+        aLookupItem.mCity = QString( (QChar*)tempStr.Ptr(), tempStr.Length());
+    }
+
+    // get State
+    aLookupItem.mState = "";
+    retStatus = aLandmark->GetPositionField( EPositionFieldState, tempStr );
+    if( retStatus == KErrNone && tempStr.Length() )
+    {
+        aLookupItem.mState = QString( (QChar*)tempStr.Ptr(), tempStr.Length());
+    }
+
+    // get country
+    aLookupItem.mCountry = "";
+    retStatus = aLandmark->GetPositionField( EPositionFieldCountry, tempStr );
+    if( retStatus == KErrNone && tempStr.Length() )
+    {
+        aLookupItem.mCountry = QString( (QChar*)tempStr.Ptr(), tempStr.Length());
+    }
+}
+
+// -----------------------------------------------------------------------------
+// CMyLocationsDatabaseManager::UnsetDuplicateNextCalEntry()
+// -----------------------------------------------------------------------------
+//
+void CMyLocationsDatabaseManager::UnsetDuplicateNextCalEntry( quint32 aLandmarkId )
+{
+    // get next duplicate item
+    QList<QLookupItem> itemArray;
+    iLocationAppLookupDb->findEntriesByLandmarkId( aLandmarkId, itemArray );
+    for ( int i = 0; i < itemArray.count(); i++)
+    {
+        if( itemArray[i].mSourceType == ESourceCalendar )
+        {
+            itemArray[i].mIsDuplicate = 0;
+            iLocationAppLookupDb->updateEntryById( itemArray[i] );
+            break;
+        }
+    }
+
+}
+// -----------------------------------------------------------------------------
+// CMyLocationsDatabaseManager::IsDuplicateEntry()
+// -----------------------------------------------------------------------------
+//
+bool CMyLocationsDatabaseManager::IsDuplicateEntry( quint32 aLandmarkId )
+{
+    // get next duplicate item
+    QList<QLookupItem> itemArray;
+    iLocationAppLookupDb->findEntriesByLandmarkId( aLandmarkId, itemArray );
+    for ( int i = 0; i < itemArray.count(); i++)
+    {
+        if( itemArray[i].mSourceType == ESourceCalendar ||
+            itemArray[i].mSourceType == ESourceLandmarks )
+        {
+            return true;
+        }
+    }
+    
+    return false;
+}
+
+// -----------------------------------------------------------------------------
+// CMyLocationsDatabaseManager::CreateLandmarkItemLC()
+// -----------------------------------------------------------------------------
+//
+CPosLandmark* CMyLocationsDatabaseManager::CreateLandmarkItemLC( const QLookupItem &aLookupItem )
+{
+    __TRACE_CALLSTACK;//return value
+    CPosLandmark *landmark = NULL;
+    TLocality loc( TCoordinate( aLookupItem.mLatitude, aLookupItem.mLongitude ), 0 );
+
+    landmark = CPosLandmark::NewL();
+    CleanupStack::PushL( landmark );
+
+    // Fill the location details into the landmark object
+    landmark->SetPositionL( loc );
+
+    // Set the landmark name as contact name
+    TBuf<KBufSize> text( aLookupItem.mName.utf16() );
+    TRAP_IGNORE( landmark->SetLandmarkNameL( text ) );
+
+    text.Copy( aLookupItem.mStreet.utf16() );
+    landmark->SetPositionFieldL( EPositionFieldStreet, text );
+    
+    // Set the City
+    text.Copy( aLookupItem.mCity.utf16() );
+    landmark->SetPositionFieldL( EPositionFieldCity, text );
+
+    // Set the state/region
+    text.Copy( aLookupItem.mState.utf16() );
+    landmark->SetPositionFieldL( EPositionFieldState, text );
+
+    // Set the Postal code
+    text.Copy( aLookupItem.mPostalCode.utf16() );
+    landmark->SetPositionFieldL( EPositionFieldPostalCode, text );
+
+    // Set the country
+    text.Copy( aLookupItem.mCountry.utf16() );
+    landmark->SetPositionFieldL( EPositionFieldCountry, text );
+
+    return landmark;
+}
+
+// -----------------------------------------------------------------------------
+// CMyLocationsDatabaseManager::UpdateMapTilePath()
+// -----------------------------------------------------------------------------
+//
+EXPORT_C void CMyLocationsDatabaseManager::UpdateMapTilePath( TUint32 aSourceId, TUint32 aSourceType, 
+                                            TFileName aFilePath )
+{
+    QString filePath = QString( (QChar*)aFilePath.Ptr(), aFilePath.Length() );
+    iLocationAppLookupDb->updateMaptileBySourceIdAndType( aSourceId, aSourceType, filePath );
+}
+
+// End of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/locationdataharvester/mylocationsdatabasemanager/tsrc/ut_mylocationsdatabasemanager.cpp	Fri Jun 11 13:33:47 2010 +0300
@@ -0,0 +1,207 @@
+/*
+* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description: mylocations database manager unit test cases
+*
+*/
+
+#include <QtTest/QtTest>
+#include <QtGui>
+#include <QString>
+
+#include <mylocationsdatabasemanager.h>
+#include <locationservicedefines.h>
+#include <EPos_CPosLandmark.h>
+#include <lbsposition.h>
+
+
+//Lookup db test interface class
+class CMyLocationsDatabaseManagerTest: public QObject
+{
+    Q_OBJECT
+        
+private slots:
+    
+    void testCase1();
+    void testCase2();
+    void testCase3();
+    void testCase4();
+};
+
+
+//Tests basic construction and destruction
+void CMyLocationsDatabaseManagerTest::testCase1()
+{
+    // tests just new and delete operation.
+	CMyLocationsDatabaseManager* dbm = new CMyLocationsDatabaseManager();
+	QVERIFY( dbm != NULL );
+    delete dbm;
+    dbm = NULL;
+
+    // tests ConstructL()
+    dbm = new CMyLocationsDatabaseManager();
+	dbm->ConstructL();
+	QVERIFY( dbm->iLocationAppLookupDb != NULL );
+	delete dbm;
+}
+
+//Tests UpdateDatabaseL()
+void CMyLocationsDatabaseManagerTest::testCase2()
+{
+    // tests just new and delete operation.
+    CMyLocationsDatabaseManager* dbm = new CMyLocationsDatabaseManager();
+    QVERIFY( dbm != NULL );
+    dbm->ConstructL();
+    
+    CPosLandmark* lm = CPosLandmark::NewL();
+    lm->SetLandmarkNameL(_L("John"));
+    lm->SetPositionFieldL( EPositionFieldStreet, _L("MG Road") );
+    TLocality loc( TCoordinate( 0.1, 0.2 ), 0 );
+    lm->SetPositionL(loc);
+    
+    // test add
+    dbm->UpdateDatabaseL( lm, 1, ESourceContactsPref, EEntryAdded );
+    QLookupItem item;
+    item.mSourceType = ESourceContactsPref;
+    item.mSourceUid = 1;
+    bool flag = dbm->iLocationAppLookupDb->findEntryBySourceIdAndType( item );
+    QVERIFY( flag == true );
+    QVERIFY( item.mStreet == "MG Road" );
+    
+    // test modify
+    lm->SetPositionFieldL( EPositionFieldStreet, _L("Brigade Road") );
+    dbm->UpdateDatabaseL( lm, 1, ESourceContactsPref, EEntryModified );
+    flag = dbm->iLocationAppLookupDb->findEntryBySourceIdAndType( item );
+    QVERIFY( flag == true );
+    QVERIFY( item.mStreet == "Brigade Road" );
+
+    dbm->UpdateDatabaseL( lm, 1, ESourceContactsPref, EEntryModified );
+    flag = dbm->iLocationAppLookupDb->findEntryBySourceIdAndType( item );
+    QVERIFY( flag == true );
+    QVERIFY( item.mStreet == "Brigade Road" );
+
+    // test delete
+    dbm->UpdateDatabaseL( NULL, 1, ESourceContactsPref, EEntryDeleted );
+    flag = dbm->iLocationAppLookupDb->findEntryBySourceIdAndType( item );
+    QVERIFY( flag == false );
+
+    // check invalid
+    dbm->UpdateDatabaseL( NULL, 1, ESourceContactsPref, EEntryUnknown );
+    flag = dbm->iLocationAppLookupDb->findEntryBySourceIdAndType( item );
+    QVERIFY( flag == false );
+
+    delete lm;
+    delete dbm;
+}
+
+//Tests GetLandmarkFullAddress() and FillLookupItemAddressDetails()
+void CMyLocationsDatabaseManagerTest::testCase3()
+{
+    CMyLocationsDatabaseManager* dbm = new CMyLocationsDatabaseManager();
+    dbm->ConstructL();
+    QVERIFY( dbm->iLocationAppLookupDb != NULL );
+    
+    QLookupItem item;
+    
+    CPosLandmark* lm = CPosLandmark::NewL();
+    TBuf<255> buff;
+    dbm->GetLandmarkFullAddress( buff, lm );
+    QString str1 = QString( (QChar*)buff.Ptr(), buff.Length());
+    QVERIFY( str1 == "" );
+    
+    dbm->FillLookupItemAddressDetails( lm, item );
+    QVERIFY( item.mName == "" );
+    QVERIFY( item.mStreet == "" );
+    QVERIFY( item.mPostalCode == "" );
+    QVERIFY( item.mCity == "" );
+    QVERIFY( item.mState == "" );
+    QVERIFY( item.mCountry == "" );
+    
+    lm->SetLandmarkNameL( _L("name") );
+    lm->SetPositionFieldL( EPositionFieldCountry, _L("india") );
+    dbm->GetLandmarkFullAddress( buff, lm );
+    str1 = QString( (QChar*)buff.Ptr(), buff.Length());
+    QVERIFY( str1 == "india" );
+    dbm->FillLookupItemAddressDetails( lm, item );
+    QVERIFY( item.mName == "name" );
+    QVERIFY( item.mCountry == "india" );
+
+    lm->SetPositionFieldL( EPositionFieldState, _L("kar") );
+    dbm->GetLandmarkFullAddress( buff, lm );
+    str1 = QString( (QChar*)buff.Ptr(), buff.Length());
+    QVERIFY( str1 == "kar, india" );
+    dbm->FillLookupItemAddressDetails( lm, item );
+    QVERIFY( item.mState == "kar" );
+
+    lm->SetPositionFieldL( EPositionFieldCity, _L("blr") );
+    dbm->GetLandmarkFullAddress( buff, lm );
+    str1 = QString( (QChar*)buff.Ptr(), buff.Length());
+    QVERIFY( str1 == "blr, kar, india" );
+    dbm->FillLookupItemAddressDetails( lm, item );
+    QVERIFY( item.mCity == "blr" );
+
+    lm->SetPositionFieldL( EPositionFieldPostalCode, _L("postalcode") );
+    lm->SetPositionFieldL( EPositionFieldStreet, _L("mg road") );
+    dbm->GetLandmarkFullAddress( buff, lm );
+    str1 = QString( (QChar*)buff.Ptr(), buff.Length());
+    QVERIFY( str1 == "mg road, blr, kar, india" );
+    dbm->FillLookupItemAddressDetails( lm, item );
+    QVERIFY( item.mPostalCode == "postalcode" );
+    QVERIFY( item.mStreet == "mg road" );
+    
+    lm->SetLandmarkNameL(_L(""));
+    lm->SetPositionFieldL( EPositionFieldStreet, _L("") );
+    lm->SetPositionFieldL( EPositionFieldPostalCode, _L("") );
+    lm->SetPositionFieldL( EPositionFieldCity, _L("") );
+    lm->SetPositionFieldL( EPositionFieldState, _L("") );
+    lm->SetPositionFieldL( EPositionFieldCountry, _L("") );
+    dbm->GetLandmarkFullAddress( buff, lm );
+    str1 = QString( (QChar*)buff.Ptr(), buff.Length());
+    dbm->FillLookupItemAddressDetails( lm, item );
+    QVERIFY( str1 == "" );
+    QVERIFY( item.mName == "" );
+    QVERIFY( item.mStreet == "" );
+    QVERIFY( item.mPostalCode == "" );
+    QVERIFY( item.mCity == "" );
+    QVERIFY( item.mState == "" );
+    QVERIFY( item.mCountry == "" );
+    
+    delete lm;
+    delete dbm;
+}
+
+//Tests UpdateMapTilePath()
+void CMyLocationsDatabaseManagerTest::testCase4()
+{
+    // tests just new and delete operation.
+    CMyLocationsDatabaseManager* dbm = new CMyLocationsDatabaseManager();
+    dbm->ConstructL();
+    QVERIFY( dbm->iLocationAppLookupDb != NULL );
+    
+    QLookupItem item;
+    item.mSourceType = ESourceCalendar;
+    item.mSourceUid = 1;
+    dbm->iLocationAppLookupDb->createEntry( item );
+    dbm->UpdateMapTilePath( item.mSourceUid, item.mSourceType, _L("maptile.png") );
+    dbm->iLocationAppLookupDb->findEntryBySourceIdAndType( item );
+    
+    QVERIFY( item.mMapTilePath == "maptile.png" );
+    
+    dbm->iLocationAppLookupDb->deleteEntryBySourceIdAndType( item );
+    delete dbm;
+}
+
+QTEST_MAIN(CMyLocationsDatabaseManagerTest)
+#include "ut_mylocationsdatabasemanager.moc"
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/locationdataharvester/mylocationsdatabasemanager/tsrc/ut_mylocationsdatabasemanager.pro	Fri Jun 11 13:33:47 2010 +0300
@@ -0,0 +1,67 @@
+#
+# Copyright (c) 2010  Nokia Corporation and/or its subsidiary(-ies).
+
+
+#
+# All rights reserved.
+# This component and the accompanying materials are made available
+# under the terms of "Eclipse Public License v1.0"
+# which accompanies this distribution, and is available
+# at the URL "http://www.eclipse.org/legal/epl-v10.html".
+#
+# Initial Contributors:
+# Nokia Corporation - initial contribution.
+#
+# Contributors:
+# 
+# Description:
+#
+#
+
+TEMPLATE = app
+TARGET = ut_mylocationsdatabasemanager   
+
+CONFIG += hb
+QT += testlib
+
+symbian:
+{
+   SYSTEMINCLUDEPATH += \epoc32\include\stdapis
+}
+
+DEPENDPATH += .
+INCLUDEPATH += .
+INCLUDEPATH += ../../inc
+INCLUDEPATH += ../../mylocationlogger/inc
+
+defines += EPOCALLOWDLLDATA
+DEFINES += LOCATION_DATA_HARVESTER_UNIT_TEST
+
+symbian: { 
+
+    TARGET.EPOCALLOWDLLDATA = 1
+    TARGET.CAPABILITY = All -Tcb
+    
+    LIBS += -llbs \
+        -leposlandmarks \
+        -leposlmsearchlib \
+        -leuser \
+        -leposlmdbmanlib \
+        -lcntmodel \
+        -lefsrv \
+        -lflogger \
+        -ledbms \
+        -lbafl \
+        -lcalinterimapi \
+        -llocationdatalookupdb
+
+}
+
+SOURCES += ../src/mylocationsdatabasemanager.cpp \
+ut_mylocationsdatabasemanager.cpp
+
+HEADERS += ../inc/mylocationsdatabasemanager.h 
+
+
+
+
--- a/locationdataharvester/mylocationsengine/inc/addresscomparision.h	Thu May 27 12:49:34 2010 +0300
+++ b/locationdataharvester/mylocationsengine/inc/addresscomparision.h	Fri Jun 11 13:33:47 2010 +0300
@@ -17,8 +17,10 @@
 
 #ifndef ADDRESSCOMPARISION_H_
 #define ADDRESSCOMPARISION_H_
+#include <locationservicedefines.h>
 #include <EPos_CPosLandmarkDatabase.h>
-#include "mylocationslookupdb.h"
+
+
 class CAddressComparision : public CBase
     {
 public:
@@ -45,7 +47,5 @@
     // Handle to landmarks db
     CPosLandmarkDatabase* iLandmarkDb;
 
-    // Handle to the My locations database manager
-    CLookupDatabase *iLookUpDatabase;
     };
 #endif /* ADDRESSCOMPARISION_H_ */
--- a/locationdataharvester/mylocationsengine/inc/lookupmaptiledb.h	Thu May 27 12:49:34 2010 +0300
+++ b/locationdataharvester/mylocationsengine/inc/lookupmaptiledb.h	Fri Jun 11 13:33:47 2010 +0300
@@ -79,7 +79,13 @@
     * Deletes an entry from the lookup table.
     * @param[in] aLookupItem The lookup item to be deleted from the database.
     */
-    void DeleteEntryL( const TLookupItem& aLookupItem );
+    void DeleteEntryL( TLookupItem& aLookupItem );
+    
+    /**
+    * Deletes maptile from the repository if the ref to that maptile in the db reaches one
+    * @param[in] aLookupItem The lookup item containing the path to the maptile
+    */
+    void DeleteMapTileL( const TLookupItem& aLookupItem );
 
     /**
     * Finds an entry in the lookup table.
@@ -88,7 +94,16 @@
     * @return ETrue if found, else EFalse
     */
     TBool FindEntryL( TLookupItem& aLookupItem);
+    
+    /**
+    * Finds an entry in the lookup table for the given maptile name.
+    * @param[in] aFilePath The lookup item to be found in the database. maptile file path is passed
+    * @return ETrue if found, else EFalse
+    */
+    TBool FindEntryByFilePathL(const TDesC& aFilePath);
 
+    void FindEntriesByMapTileFetchingStateL(const TUint32 aFetchingState,
+            RArray<TLookupItem>& aLookupItemArray);
 
 
 private:
--- a/locationdataharvester/mylocationsengine/inc/maptileinterface.h	Thu May 27 12:49:34 2010 +0300
+++ b/locationdataharvester/mylocationsengine/inc/maptileinterface.h	Fri Jun 11 13:33:47 2010 +0300
@@ -43,13 +43,16 @@
     */    
     virtual void MapTilefetchingCompleted( TInt aErrCode,const TDesC& aMapTilePath ) = 0;
     
-    /** Informs once geocoding completed 
-     * 
-     * @param[in] aLatitude converted latitude value
-     * @param[in] aLongitude converted longitude value
-     * 
-     */       
-    virtual void RestGeoCodeCompleted( TReal aLatitude,TReal aLongitude ) = 0;
+    /** Informs once geo coordinates  retrived from the REST server
+    * 
+    * @param[in] aErrCode Error code
+    * @param[in] aMapTilePath Path where the maptile image staroed
+    * 
+    */    
+    virtual void GeoCodefetchingCompleted( TInt aErrCode, const TReal& aLatitude,
+	                const TReal& aLongitude, const TDesC& aMapTilePath ) = 0;
+    
+  
     
     };
 
@@ -70,23 +73,24 @@
     static CMapTileInterface* NewL(); 
     
     /**
-     * Interface for requesting maptile image for a landmark object
+     * Interface for requesting GEO fields a landmark object containing address
      * 
      * @param[in] aLandmark Landmark containing address details
      * @param[in] aFilePath Path where the maptile image to be stored
      * @param[in] aObserver Observer for callback notification
+     * 
      */
-    void GetMapTileImageL(  CPosLandmark*  aLandmark , 
-            const TDesC& aFilePath,   MMapTileObserver* aObserver  );
+    void GetGeoCodeFromAddressL(  CPosLandmark*  aLandmark , 
+            const TDesC& aFilePath, MMapTileObserver* aObserver  );
     
     /**
-     * Interface for requesting maptile image for a landmark object
+     * Interface for requesting GEO fields for the address
      * 
      * @param[in] aAddressDetails containing address details
      * @param[in] aFilePath Path where the maptile image to be stored
      * @param[in] aObserver Observer for callback notification
      */
-    void GetMapTileImageL(const TDesC& aAddressDetails,
+    void GetGeoCodeFromAddressL(const TDesC& aAddressDetails,
             const TDesC& aFilePath, MMapTileObserver* aObserver);
     
     /**
@@ -105,16 +109,19 @@
      * Destructor
      */
     ~CMapTileInterface();
+    
+    /**
+     * Function for Retrieving maptile     
+     */
+    void GetMapTileL( const TReal& aLatitude, const TReal& aLongitude );    
 
 private:
-
-    /**
-     * Function for Retrieving latitude & longitude information
-     * 
-     * @param[in] aLatitude latitude value
-     * @param[in] aLongitude Longitude value
-     */
-	void GetMapTileL( TReal aLatitude, TReal aLongitude	);
+	
+	/**
+	 * Converts geocoordinates to maptile pixel coordinate and update the 
+	 * image saving file path to MaptileFolder\RowCol.png
+	 */	
+	void UpdateFilePathL( const TReal& aLatitude, const TReal& aLongitude );
 	
     /**
      * Interface for requesting  for a landmark object.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/locationdataharvester/mylocationsengine/inc/mylocationgeotagtimerao.h	Fri Jun 11 13:33:47 2010 +0300
@@ -0,0 +1,87 @@
+/*
+* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:  3AM geo tagger handler
+*
+*/
+
+#ifndef __MYLOCATIONGEOTAGTIMERAO_H__
+#define __MYLOCATIONGEOTAGTIMERAO_H__
+
+
+// INCLUDES
+#include <e32std.h>
+#include <e32base.h>
+
+/*
+ * MyLocationTimerObserver class
+ * observer class to notify the mylocation engine about the 3AM timer expiry.
+ */
+class MyLocationTimerObserver
+{
+public:
+   virtual void MyLocationThreeAMTimerExpiredL() = 0; 
+};
+
+/*
+ * CLocationGeoTagTimerAO class
+ * Class to handle 3AM timer expiry.
+ */
+class CLocationGeoTagTimerAO : public CTimer
+{
+    
+public:
+     /**
+      * 1st phase constructor.
+      * @param aObserver, 3AM timer observer
+      */
+     static CLocationGeoTagTimerAO* NewL(
+             MyLocationTimerObserver& aObserver ); 
+
+     /**
+      * Destructor
+      */
+     ~CLocationGeoTagTimerAO();
+
+     /**
+      * Start 3AM timer
+      */
+     void StartTimer();
+
+     
+protected:
+     /*
+      * @see CActive::RunL()
+      */
+     void RunL();
+    
+     /**
+      * 2nd Phase constructor
+      */
+     void ConstructL();
+    
+     /**
+	  * CLocationGeoTagTimerAO
+	  * Constructor
+	  * @param aObserver, 3AM timer observer
+	  */
+     CLocationGeoTagTimerAO( MyLocationTimerObserver& aObserver );
+      
+private:      
+      MyLocationTimerObserver* iTimerObserver;
+};
+
+
+#endif /*__MYLOCATIONGEOTAGTIMERAO_H__*/
+
+// End of file
--- a/locationdataharvester/mylocationsengine/inc/mylocationsdatabasemanager.h	Thu May 27 12:49:34 2010 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,239 +0,0 @@
-/*
-* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
-* All rights reserved.
-* This component and the accompanying materials are made available
-* under the terms of "Eclipse Public License v1.0"
-* which accompanies this distribution, and is available
-* at the URL "http://www.eclipse.org/legal/epl-v10.html".
-*
-* Initial Contributors:
-* Nokia Corporation - initial contribution.
-*
-* Contributors:
-*
-* Description: Database manager implementation for location picker and
-*              maptile service.
-*
-*/
-
-#ifndef __MYLOCATIONSDATABASEMANAGER_H__
-#define __MYLOCATIONSDATABASEMANAGER_H__
-
-// Landmarks
-#include<EPos_CPosLandmarkDatabase.h>
-#include <EPos_CPosLmCategoryManager.h>
-
-#include <locationservicedefines.h>
-
-// lookup database
-#include <locationdatalookupdb.h>
-
-// mylocations lookup db
-#include "mylocationslookupdb.h"
-
-// Maximum string length of landmark address.
-const TUint32 KMaxAddressLength = 255; 
-
-/** Defines entry change type
-*/
-enum TEntryChangeType
-    {
-    /** Entry added */
-    EEntryAdded,
-    /** Entry modified */
-    EEntryModified,
-    /** Entry deleted */
-    EEntryDeleted,
-    /** Entry change unknown */
-    EEntryUnknown
-    };
-
-
-/**
- * CMyLocationsDatabaseManager class.
- *  This class handles all the operations related to mylocations landmark database.
- *
- */
-class CMyLocationsDatabaseManager : public CBase
-    {
-    public:
-        // Constructors and destructor
-    
-        /**
-         * ConstructL.
-         * 2nd phase constructor.
-         */
-        void ConstructL();
-    
-        /**
-         * CMyLocationsDatabaseManager.
-         * C++ default constructor. 
-         */
-        CMyLocationsDatabaseManager();
-    
-        /**
-         * ~CMyLocationsDatabaseManager.
-         * Virtual Destructor.
-         */
-        virtual ~CMyLocationsDatabaseManager();
-        
-    public:
-        /**
-         * UpdateDatabaseL.
-         * Updates the location into the landmark database and lookup table. 
-         * Based on the entry source type and the entry change type the updation can be 
-         * addition/modification/deletion.
-         * 
-         * @param[in] aLandmark Landmark object to be updated in the database.
-         * @param[in] aUid Uid of the changed source entry.
-         * @param[in] aSourceType Source type of the aUid.
-         * @param[in] aChangeType Type of change to the entry ( added/modified/deleted )
-         */
-        void UpdateDatabaseL( CPosLandmark* aLandmark, const TUint32 aUid, 
-                              const TUint32 aSourceType, const TEntryChangeType aChangeType );
-        
-        /** Gets the full address from a given landmark object
-         *
-         * @param[out] aLandmarkAddress comma separated landmark's full address
-         * @param[in] aLandmark landmark object whose address needs to be found.
-         */      
-        void GetLandmarkFullAddress( TBuf<KMaxAddressLength>& aLandmarkAddress, 
-                                     const CPosLandmark* aLandmark );
-       
-	    /** Update the maptile path to mylocation lookup table
-         *
-         * @param[in] aSourceId Uid of the changed source entry.
-		 * @param[in] aSourceType Source type of the aSourceId.
-         * @param[in] aFilePath Maptile file path.
-         */                               
-        void UpdateMapTilePath( TUint32 aSourceId, TUint32 aSourceType, 
-                                            TFileName aFilePath );
-    private:
-        
-        /**
-         * AddMylocationsCategory.
-         * Adds the category to landmarks database. 
-         * Used to add location picker specific categories.
-         * @param[in] aCategoryName defines the category name to be added.
-         * @returns The category id. 
-         */
-        TUint32 AddMylocationsCategoryL(  const TDesC&  aCategoryName  );
-
-        /**
-         * CheckIfDuplicateExistsL.
-         * Checks if this landmark is already present in database. 
-         * If present returns the landmark id, else 0.
-         * @param[in] aLandmark A landmark object to be checked for.
-         * @returns If no duplicate is found in database returns 0 
-         * else returns the id of the found landmark.
-         */
-        TPosLmItemId CheckIfDuplicateExistsL( const CPosLandmark* aLandmark );
-        
-        /**
-         * CompareLandmarks.
-         * Compares two landmarks. Only the text fields, landmark name, 
-         * street, city, state country and postal code are compared. 
-         * @param[in] aLandmark1 First landmark object to be compared.
-         * @param[in] aLandmark2 Second landmark object to be compared.
-         * @returns ETrue if the landmarks are same, else returns EFalse.
-         */
-       TBool CompareLandmarks( const CPosLandmark* alandmark1, 
-                               const CPosLandmark* alandmark2 );
-        
-       /**
-         * HandleEntryAdditionL.
-         * Handles the entry addition in lookup table and landmarks db
-         * @param[in] aLandmark Landmark object added.
-         * @param[in] aUid Uid of the source entry corresponding to aLandmark..
-         * @param[in] aSourceType source type of the aUid passed.
-        */
-       void HandleEntryAdditionL( CPosLandmark*  aLandmark, const TUint32 aUid,
-                                  const TUint32 aSourceType );
-
-       /**
-         * HandleEntryModificationL.
-         * Handles the entry modification in lookup table and landmarks db
-         * @param[in] aLandmark Landmark object modified.
-         * @param[in] aUid Uid of the source entry corresponding to aLandmark..
-         * @param[in] aSourceType source type of the aUid passed.
-        */
-       void HandleEntryModificationL( CPosLandmark*  aLandmark, const TUint32 aUid,
-                                      const TUint32 aSourceType );
-
-       /**
-         * HandleEntryDeletionL.
-         * Handles the entry deletion in lookup table and landmarks db
-         * @param[in] aUid Uid of the source entry corresponding to aLandmark..
-         * @param[in] aSourceType source type of the aUid passed.
-        */
-       void HandleEntryDeletionL( const TUint32 aUid, const TUint32 aSourceType );
-
-       /**
-         * HandleLandmarkModificationL.
-         * Handles a landmark modification
-         * @param[in] aLandmark Landmark object modified.
-         * @param[in] aUid Uid of the source entry corresponding to aLandmark..
-        */
-       void HandleLandmarkModificationL( CPosLandmark* aLandmark, const TUint32 aUid );
-       /**
-          * CheckAndReadLandmarkL.
-          * Checks whether a category is available in database pointed by category manager.
-          * @param[in] CPosLandmarkDatabase handle to the database manager
-          * @param[in] aLmId Id of the landmark
-          * @returns landmark object if found else NULL
-         */
-       CPosLandmark* CheckAndReadLandmarkL( 
-                       CPosLandmarkDatabase* aDb, const TUint32 aLmId );
-        /**
-          * FillLookupItemAddressDetails.
-          * Fills address details into QLookupItem from CPosLandmark.
-          * @param[in] aLandmark a landmark object
-          * @param[out] aLookupItem, a lookup item in which the address details are filled
-         */
-       void FillLookupItemAddressDetails( CPosLandmark* aLandmark, QLookupItem &aLookupItem );
-
-        /**
-          * UnsetDuplicateNextCalEntry.
-          * Finds a calendar lookup entry whose detination id  is aLandmarkId
-		  * and unsets it duplcate flag.
-          * @param[in] aLandmarkId a landmark id.
-         */
-       void UnsetDuplicateNextCalEntry( quint32 aLandmarkId );
-
-        /**
-          * IsDuplicateCalEntry.
-          * Checks if there is a duplicate entry present whose destination id 
-		  * is aLandmarkId
-          * @param[in] aLandmarkId a landmark id.
-         */
-       bool IsDuplicateEntry( quint32 aLandmarkId );
-
-        /**
-          * CreateLandmarkItemLC.
-          * Creates a landmark from a QLookupItem
-          * @param[in] aLookupItem a lookup item.
-          * @returns CPosLandmark a newly created landmark.
-         */
-       CPosLandmark* CreateLandmarkItemLC( const QLookupItem &aLookupItem );
-       
-    private:
-        // Handle to the landmark database
-        CPosLandmarkDatabase* iLandmarkDb;
-
-        // Calendar category to be created for calendar related location entries in landmark database
-        TPosLmItemId iLmCalendarCatId;  
-        // Contacts category to be created for contacts related location entries in landmark database
-        TPosLmItemId iLmContactsCatId;  
-        // handle to landmarks lookup database.
-        CLookupDatabase*  iLandmarksLookupDb;
-
-        // handle to the location app lookup database.
-        LocationDataLookupDb*  iLocationAppLookupDb;
-
-        // handle to landmarks category manager
-        CPosLmCategoryManager* iLandmarksCatManager;
-
-        // handle to the file session
-        RFs iFsSession;
-    };
-#endif  // __MYLOCATIONSDATABASEMANAGER_H__
--- a/locationdataharvester/mylocationsengine/inc/mylocationsengine.h	Thu May 27 12:49:34 2010 +0300
+++ b/locationdataharvester/mylocationsengine/inc/mylocationsengine.h	Fri Jun 11 13:33:47 2010 +0300
@@ -20,7 +20,6 @@
 #define __MYLOCATIONSENGINE_H__
 
 // INCLUDES
-
 // calendar related headers
 #include <calsession.h>
 #include <calentryview.h>
@@ -28,6 +27,10 @@
 // Header for contact DB
 #include <cntdb.h>
 
+//Qt contacts mobility apis
+#include <qtcontacts.h>
+#include <qcontactmanager.h>
+
 // Header for landmarks db
 #include<EPos_CPosLandmarkDatabase.h>
 
@@ -37,6 +40,9 @@
 #include "lookupmaptiledb.h"
 #include "addresscomparision.h"
 #include "calendernotification.h"
+#include "mylocationgeotagtimerao.h"
+
+using namespace QTM_NAMESPACE;
 
 /**  
  * This class contains the required data  for maptile image  processing.
@@ -74,7 +80,8 @@
  * This process starts on phone bootup and always runs in the background.
  */
 class CMyLocationsEngine : public CActive, public MCalChangeCallBack2,
-				 public MContactDbObserver, public MMapTileObserver,public MNotifyChange
+				 public MContactDbObserver, public MMapTileObserver,public MNotifyChange,
+				 public MyLocationTimerObserver
 			
 {
     
@@ -130,8 +137,11 @@
      */      
     TEntryChangeType MapChangeType( TUidSourceType aSrcType, TUint32 aChangeType );    
  
-
+#ifdef MYLOCATIONENGINE_UNIT_TEST
+public:
+#else
 private:
+#endif
     
     /**
      * ConstructL.
@@ -146,30 +156,11 @@
     CMyLocationsEngine();
     
     /** Creates a landmark object from contact item's location details and checks whether address available.
-    * @param[in] aContactItem A contact item whose location details needs to be used to create landmark object.
-    * @param[in] aAddressType Mentions the address type ( prefered/work/home ) of the contact item to be used.
-    * @returns A valid landmark object if location in the contact item is validated, NULL otherwise.
+     * @param[in] aContactAddress A contact address whose location details needs to be used to create landmark object.
+     * @returns A valid landmark object if location in the contact item is validated, NULL otherwise.
      */      
-    CPosLandmark* GetContactAddressDetailsLC( const CContactItem *aContactItem, 
-            TContactAddressType aAddressType );
+    CPosLandmark* GetContactAddressDetailsLC( QContactAddress& aContactAddress );
             
-    /** Creates a landmark object from contact item's location details
-    * @param[in] aContactItem A contact item whose location details needs to be used to create landmark object.
-    * @param[in] aAddressType Mentions the address type ( prefered/work/home ) of the contact item to be used.
-    * @returns A valid landmark object if location in the contact item is validated, NULL otherwise.
-    */    
-    CPosLandmark* GetContactLocationDetailsLC( const CContactItem *aContactItem, 
-           TContactAddressType aAddressType );
-
-    /** Finds the contact's field type id
-    * @param[in] aContactItem A contact item whose field details needs to found.
-    * @param[in] aAddressType Mentions the address type ( prefered/work/home ) of the contact item to be used.
-    * @param[in] aField The field type of interest.
-    * @return If found, the index of the field within the field set, or KErrNotFound if not found.
-    */      
-    TInt FindContactsField( const CContactItem *aContactItem, TContactAddressType aAddressType, 
-            TUid aField );
-
     /**
      *  A call back function for calendar change notification
 	 *	@param aChangeItems  List of changes since the last notification.	
@@ -198,9 +189,9 @@
     * @param aEventType  Provides information about the type of request address.
     * @param aLookupItem Provides information about single address of contact.  
     */  
-	void HandleMaptileDatabaseL(TInt aEventType ,
+	void UpdateMaptileDatabaseL(TInt aEventType ,
 	                             TLookupItem& aLookupItem );
-
+	
     /**
      *  Handles active object's request completion event. 
      */
@@ -211,6 +202,7 @@
      */
     void DoCancel();
  
+    
     /** 
      * Requests for map tile image , structure serch.
      * @param aLandmark  Provides information about the address.
@@ -228,6 +220,17 @@
      */
     void RequestMapTileImageL(const TDesC& aAddressDetails,
             const TUidSourceType aAddressType, const TInt32 aUId);
+ 
+    /** 
+     * Checks whether contact has a valid geocoordinates.
+     * @param aContact  Provides all the required information about the contact.
+     * @param aAddressType Provides information about address type .  
+     * @param aLatitude, Latitude information.
+     * @param aLongitude, Longitude information.
+     * @return If geocoordinate available returns TRUE otherwise FALSE
+     */    
+    TBool IsGeoCoordinateAvailable( QContact& aContact, 
+            QString aAddressType, double& aLatitude , double& aLongitude );
     
     /** 
      * Add to maptile request queue.
@@ -250,8 +253,21 @@
     */
     void UpdateDatabaseL( CPosLandmark* aLandmark, const TUint32 aUid, 
             const TUint32 aSourceType, const TEntryChangeType aChangeType );
-
-
+			
+    /** 
+     * Informs the geocode completion
+     */
+    void UpdateGeoCodeToAppDataBase( TReal latitude,TReal longitude );		
+    
+    /** 
+     * Process the pending maptile requests
+     */
+    void ProcessNextMaptileRequest();
+    
+    /**
+     * maptile database manipulation.
+     */
+    void ManipulateMapTileDataBaseL(TLookupItem aLookupItem);
 public:  //From MMapTileObserver
     
     /**
@@ -259,13 +275,23 @@
      */ 
     void MapTilefetchingCompleted( TInt aErrCode,const TDesC& aMapTilePath );
     
-    /** 
-     * Informs the geocode completion
+    /**
+     *  Informs the geo codes fetching completion  
      */
-    void RestGeoCodeCompleted( TReal latitude,TReal longitude);
+    void GeoCodefetchingCompleted( TInt aErrCode, const TReal& aLatitude,
+	                                   const TReal& aLongitude, const TDesC& aMapTilePath );
+    
+
     
 public://from MNotifychange
     void NotifyChangeL(TInt &aStatus);
+	
+public: //from MyLocationTimerObserver
+    /** 
+     * Notifies the timer expiry when 3AM timer was started to notify. 
+     */
+    void MyLocationThreeAMTimerExpiredL();
+
     
 private:
 
@@ -307,14 +333,21 @@
     //Maptile image request queue
     RArray<CMapTileRequest*> iMapTileRequestQueue;
     
+    // 3am Timer
+    CLocationGeoTagTimerAO *iMyLocationThreeAMTimer;
+    
     //Flag to check maptilegeocoder plugin availability
     TBool iMaptileGeocoderPluginAvailable;
 	
 	//Maptile image path
     TFileName imageFilePath;
+    
     //Object to listen calender db create notification.    
     CCalenderNotification  *iCalenderNotification;
     
+    //Contact manager instance for retrieving contact info.
+    QContactManager* iContactManager;
+    
 };
 
 #endif // __MYLOCATIONSENGINE_H__
--- a/locationdataharvester/mylocationsengine/inc/mylocationslookupdb.h	Thu May 27 12:49:34 2010 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,139 +0,0 @@
-/*
-* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
-* All rights reserved.
-* This component and the accompanying materials are made available
-* under the terms of "Eclipse Public License v1.0"
-* which accompanies this distribution, and is available
-* at the URL "http://www.eclipse.org/legal/epl-v10.html".
-*
-* Initial Contributors:
-* Nokia Corporation - initial contribution.
-*
-* Contributors:
-*
-* Description: Header file for mylocation database lookup table.
-*
-*/
-
-#ifndef __MYLOCATIONSLOOKUPDB_H__
-#define __MYLOCATIONSLOOKUPDB_H__
-
-//Headers needed
-#include <f32file.h> //RFs
-#include <d32dbms.h>  //RDbNamedDatabase,RDbView 
-
-#include "mylocationsdefines.h"
-#include "locationservicedefines.h"
- 
-/**
- * CLookupDatabase class.
- * This class handles all the operations related to mylocations lookup database.
- *
- */
- 
-class CLookupDatabase : public CBase
-{
-public:
-    // Two phase constructors
- 
-    /**
-    * This is a static function, which creates and returns an instance of this class.
-    */
-    static CLookupDatabase* NewL( const TDesC& aLookupTableName );
-
-    /**
-    * This is a static function, which creates and returns an instance of this class. Pushes the created object 
-    * to the cleanup stack.
-    */
-    static CLookupDatabase* NewLC( const TDesC& aLookupTableName );
-
-    /**
-    * Destructor
-    */
-    ~CLookupDatabase();
-
-public:
-
-    /**
-    * Opens the lookup database.
-    */
-    TInt Open();
-
-    /**
-    * Closes the lookup database.
-    */
-    void Close();
-
-    /**
-    * Creates an entry in the lookup table.
-    * @param[in] aLookupItem The lookup item to be created in the database.
-    */
-    void CreateEntryL( const TLookupItem& aLookupItem );
-
-    /**
-    * Updates an entry in the lookup table.
-    * @param[in] aLookupItem The lookup item to be updated in the database.
-    */
-    void UpdateEntryL( const TLookupItem& aLookupItem );
-
-    /**
-    * Deletes an entry from the lookup table.
-    * @param[in] aLookupItem The lookup item to be deleted from the database.
-    */
-    void DeleteEntryL( const TLookupItem& aLookupItem );
-
-    /**
-    * Finds an entry in the lookup table.
-    * @param[in/out] aLookupItem The lookup item to be found in the database. The source iUid and source type 
-    * iSource is passed in the lookup item, if the entry is found, then the iLmId is copied to the lookup item
-    * @return ETrue if found, else EFalse
-    */
-    TBool FindEntryL( TLookupItem& aLookupItem );
-
-    /**
-    * Finds list of lookup items given a landmark id.
-    * @param[in] aLandmarkId The landmark id to be found in the lookup database.  
-    * @param[out] aLookupItemArray List of lookup entried found.  
-    */
-    void FindEntriesByLandmarkIdL( const TUint32 aLandmarkId, 
-            RArray<TLookupItem>& aLookupItemArray );
-
-    /**
-    * Finds list of lookup items given a source type.
-    * @param[in] aSourceType The source type to be found in the lookup database.  
-    * @param[out] aLookupItemArray List of lookup entried found.  
-    */
-    void FindEntriesBySourceTypeL( const TUint32 aSourceType, 
-            RArray<TLookupItem>& aLookupItemArray );
-
-
-
-private:
-    
-    // default constructor
-    CLookupDatabase();
-    
-    // Second phase constructor
-    void ConstructL( const TDesC& aLookupTableName );
-    
-    // Creates a lookup table in the lookup database.
-    void CreateTableL(RDbDatabase& aDatabase);
-    
-private:
-    
-    // Handle to the items database
-    RDbNamedDatabase iItemsDatabase;
-    
-    // handle to the file session
-    RFs iFsSession;
-        
-    // holds the database file name
-    TFileName iDbFileName;
-
-};
-
-
-#endif  // __MYLOCATIONSLOOKUP_H__
-
-// End of file
-
--- a/locationdataharvester/mylocationsengine/mylocationsengine.pro	Thu May 27 12:49:34 2010 +0300
+++ b/locationdataharvester/mylocationsengine/mylocationsengine.pro	Fri Jun 11 13:33:47 2010 +0300
@@ -1,18 +1,3 @@
-#
-# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
-# All rights reserved.
-# This component and the accompanying materials are made available
-# under the terms of "Eclipse Public License v1.0"
-# which accompanies this distribution, and is available
-# at the URL "http://www.eclipse.org/legal/epl-v10.html".
-#
-# Initial Contributors:
-# Nokia Corporation - initial contribution.
-#
-# Contributors:
-#
-# Description: 
-#
 
 TEMPLATE=app
 TARGET=mylocationsengine
@@ -23,11 +8,13 @@
 INCLUDEPATH += ../../inc
 INCLUDEPATH += ../geocodeupdate/inc
 INCLUDEPATH += ../mylocationlogger/inc
+INCLUDEPATH += ../mylocationsdatabasemanager/inc
+INCLUDEPATH += /epoc32/include/app
 
 symbian: { 
 
     TARGET.UID3 = 0x2002680A 
-    isEmpty(TARGET.EPOCSTACKSIZE):TARGET.EPOCSTACKSIZE = 0x6000
+    isEmpty(TARGET.EPOCSTACKSIZE):TARGET.EPOCSTACKSIZE = 0x8000
     isEmpty(TARGET.EPOCHEAPSIZE):TARGET.EPOCHEAPSIZE = 20480 \
         16943040
     TARGET.CAPABILITY = ALL -TCB
@@ -46,27 +33,26 @@
         -lgeocodeupdate \
         -lecom \
 	-lcalinterimapi \
-	-llocationdatalookupdb
+	-llocationdatalookupdb \
+	-lmylocationsdatabasemanager
 
 }
 
 SOURCES += src/appmain.cpp \
     src/mylocationsengine.cpp \
-    src/mylocationsdatabasemanager.cpp \
-    src/mylocationslookupdb.cpp \
     src/maptileinterface.cpp \
     src/addresscomparision.cpp \   
     src/lookupmaptiledb.cpp    \
-    src/calendernotification.cpp 
+    src/calendernotification.cpp \
+    src/mylocationgeotagtimerao.cpp 
 
 HEADERS += inc/appmain.h \
     inc/mylocationsengine.h \
-    inc/mylocationslookupdb.h \
-    inc/mylocationsdatabasemanager.h \
     inc/maptileinterface.h \
     inc/addresscomparision.h \
     inc/lookupmaptiledb.h \
-    inc/calendernotification.h
+    inc/calendernotification.h \
+    inc/mylocationgeotagtimerao.h
 
 
 
--- a/locationdataharvester/mylocationsengine/src/addresscomparision.cpp	Thu May 27 12:49:34 2010 +0300
+++ b/locationdataharvester/mylocationsengine/src/addresscomparision.cpp	Fri Jun 11 13:33:47 2010 +0300
@@ -19,37 +19,36 @@
 #include "mylocationlogger.h"
 #include "addresscomparision.h"
 
-
+// -----------------------------------------------------------------------------
+// CAddressComparision::NewL()
+// -----------------------------------------------------------------------------
+//
 CAddressComparision* CAddressComparision::NewL()
 {
     CAddressComparision* self = new (ELeave) CAddressComparision();
     return self;
 }
-
+// -----------------------------------------------------------------------------
+// CAddressComparision::CAddressComparision()
+// -----------------------------------------------------------------------------
+//
 CAddressComparision::CAddressComparision()
 {
 
 }
-
+// -----------------------------------------------------------------------------
+// CAddressComparision::IsAddressChangedL()
 // Need to enhance the functionality for address comparison
+// -----------------------------------------------------------------------------
+//
+
 TBool CAddressComparision::IsAddressChangedL(const CPosLandmark& /*aLandmarks*/,
-        const TInt32 aCntId, const TUidSourceType aAddressType)
+        const TInt32 /*aCntId*/, const TUidSourceType/* aAddressType*/)
 {
     __TRACE_CALLSTACK;
     
     
     TBool addressChanged = ETrue;
-    CLookupDatabase* lookupdb = NULL;
-    lookupdb = CLookupDatabase::NewLC(KMylocationsLookupDatabaseName);
-
-    TLookupItem lookupItem;
-    lookupItem.iUid = aCntId;
-    lookupItem.iSource = aAddressType;
-    User::LeaveIfError(lookupdb->Open());
-    addressChanged=lookupdb->FindEntryL(lookupItem);
-	addressChanged=ETrue;
-    lookupdb->Close();
-    CleanupStack::PopAndDestroy(lookupdb);
     return addressChanged;//addressChanged;
 }
 
--- a/locationdataharvester/mylocationsengine/src/calendernotification.cpp	Thu May 27 12:49:34 2010 +0300
+++ b/locationdataharvester/mylocationsengine/src/calendernotification.cpp	Fri Jun 11 13:33:47 2010 +0300
@@ -89,10 +89,7 @@
 //
 CCalenderNotification::~CCalenderNotification()
 {
-    if (IsActive())
-    {
-        Cancel();
-    }
+    Cancel();
     iFsession.Close();
 }
 // -----------------------------------------------------------------------------
@@ -104,10 +101,6 @@
 {
     TInt status;
     iNotifyChange.NotifyChangeL( status );
-    if ( KErrNone == status )
-    {
-        iFsession.NotifyChangeCancel();
-    }
 }
 // -----------------------------------------------------------------------------
 // CMyLocationsEngine::DoCancel()
@@ -116,6 +109,7 @@
 //
 void CCalenderNotification::DoCancel()
 {
+    iFsession.NotifyChangeCancel();
 }
 
 //End of file
--- a/locationdataharvester/mylocationsengine/src/lookupmaptiledb.cpp	Thu May 27 12:49:34 2010 +0300
+++ b/locationdataharvester/mylocationsengine/src/lookupmaptiledb.cpp	Fri Jun 11 13:33:47 2010 +0300
@@ -21,6 +21,14 @@
 
 _LIT( KSelectAllFrom, "SELECT * FROM " );
 _LIT(KQueryToDB,"SELECT * FROM cntmaptilelookuptable WHERE cntuid = %d AND source = %d");
+_LIT( KSelectfilepathFrom, "SELECT filepath FROM " );
+_LIT(KQueryMaptile, "SELECT filepath FROM cntmaptilelookuptable WHERE filepath = '%S'");
+// string 'where'
+_LIT( KStringWhere, " WHERE " );
+// string ' = '
+_LIT( KStringEqual, " = " );
+
+_LIT(KQueryByMaptileFetchingState,"SELECT * FROM cntmaptilelookuptable WHERE fetchingstatus = %d");
 
 // -----------------------------------------------------------------------------
 // CLookupMapTileDatabase::CLookupMapTileDatabase()
@@ -148,6 +156,11 @@
 
     // add file path type column
     columns->AddL(TDbCol(NCntColFilePath, EDbColText16));
+    
+    //MK 
+    // add map tile fetching status to the db
+    columns->AddL(TDbCol(MapTileFetchingStatus, EDbColUint32));
+    
 
     // Create a table
     User::LeaveIfError(aDatabase.CreateTable(KMapTileLookupTable, *columns));
@@ -187,6 +200,7 @@
     myView.SetColL(KColumncntUid, aLookupItem.iUid);
     myView.SetColL(KColumnSource, aLookupItem.iSource);
     myView.SetColL(KColumnFilePath, aLookupItem.iFilePath);
+    myView.SetColL(KColumnMapTileFetchingStatus, aLookupItem.iFetchingStatus); //MK
 
     myView.PutL();
 
@@ -227,6 +241,7 @@
         // found the entry. update it.
         myView.UpdateL();
         myView.SetColL(KColumnFilePath, aLookupItem.iFilePath);
+        myView.SetColL(KColumnMapTileFetchingStatus, aLookupItem.iFetchingStatus); //MK
         myView.PutL();
     }
 
@@ -242,7 +257,7 @@
 // Deletes an entry from the lookup table.
 // -----------------------------------------------------------------------------
 //
-void CLookupMapTileDatabase::DeleteEntryL(const TLookupItem& aLookupItem)
+void CLookupMapTileDatabase::DeleteEntryL(TLookupItem& aLookupItem)
 {
     __TRACE_CALLSTACK;// Create the query to find the row to be deleted.
 
@@ -274,7 +289,8 @@
         myView.GetL();
         if (aLookupItem.iUid == myView.ColUint(KColumncntUid))
         {
-            ret = iFsSession.Delete(myView.ColDes16(KColumnFilePath));
+            aLookupItem.iFilePath.Copy(myView.ColDes16(KColumnFilePath));
+            
         }
         myView.DeleteL();
     }
@@ -288,6 +304,92 @@
 }
 
 // -----------------------------------------------------------------------------
+// CLookupMapTileDatabase::DeleteMapTileL()
+// Deletes an maptile if there's no reference to maptile in lookupdb
+// -----------------------------------------------------------------------------
+//
+void CLookupMapTileDatabase::DeleteMapTileL( const TLookupItem& aLookupItem)
+{
+    __TRACE_CALLSTACK;// Create the query to find the row to be deleted.
+
+    TFileName queryBuffer;    
+    queryBuffer.Format(KQueryMaptile, &aLookupItem.iFilePath);
+    
+    TInt ret = Open();
+    if (ret != KErrNone)
+    {
+       Close();
+       Open();      
+    }
+    
+    iItemsDatabase.Begin();
+
+    RDbView myView;
+    // query buffer finds only the selected item row.
+    myView.Prepare(iItemsDatabase, TDbQuery(queryBuffer));
+    CleanupClosePushL(myView);
+
+    myView.EvaluateAll();
+
+    // positions the cursor on the first row of the rowset
+    myView.FirstL();
+
+    // Delete if no reference to maptile
+    if (!myView.AtRow())
+    {
+        ret = iFsSession.Delete(aLookupItem.iFilePath);     
+    }
+        
+    CleanupStack::PopAndDestroy(&myView); // myView
+
+    Close();
+}
+
+
+// -----------------------------------------------------------------------------
+// CLookupMapTileDatabase::FindEntriesByMapTileFetchingStatusL()
+// Finds a list of lookup items given a landmark uid.
+// -----------------------------------------------------------------------------
+//
+void CLookupMapTileDatabase::FindEntriesByMapTileFetchingStateL(const TUint32 aFetchingState,
+        RArray<TLookupItem>& aLookupItemArray)
+{
+    __TRACE_CALLSTACK;// Create a query to find the item.
+    TFileName queryBuffer;
+    queryBuffer.Format(KQueryByMaptileFetchingState,aFetchingState);
+    
+    TInt ret = Open();
+        if (ret != KErrNone)
+        {
+           Close();
+           ret= Open();
+           
+        }
+      iItemsDatabase.Begin();
+
+    
+    // Create a view of the table with the above query.
+    RDbView myView;
+    myView.Prepare(iItemsDatabase, TDbQuery(queryBuffer));
+    CleanupClosePushL(myView);
+    myView.EvaluateAll();
+    myView.FirstL();
+
+    while (myView.AtRow())
+    {
+        // Item found. get the details.
+        myView.GetL();
+        TLookupItem newItem;
+        newItem.iUid = myView.ColUint(KColumnUid);
+        newItem.iSource = myView.ColUint(KColumnSource);
+        aLookupItemArray.Append(newItem);
+        myView.NextL();
+    }
+
+    CleanupStack::PopAndDestroy(&myView); // myView
+}
+
+// -----------------------------------------------------------------------------
 // CLookupMapTileDatabase::FindEntryL()
 // Finds an entry in the lookup table.
 // -----------------------------------------------------------------------------
@@ -320,10 +422,6 @@
     {
         // Item found. get the details.
         myView.GetL();
-        if (aLookupItem.iUid == myView.ColUint(KColumncntUid))
-        {
-            aLookupItem.iFilePath.Copy(myView.ColDes16(KColumnFilePath));
-        }
         retVal = ETrue;
     }
 
@@ -331,5 +429,57 @@
     Close();
     return retVal;
 }
+
+// -----------------------------------------------------------------------------
+// CLookupMapTileDatabase::FindEntryByFIlePathLL()
+// Finds an entry in the lookup table for maptile image file
+// -----------------------------------------------------------------------------
+//
+TBool CLookupMapTileDatabase::FindEntryByFilePathL(const TDesC& aFilePath)
+{
+    __TRACE_CALLSTACK;// used to store return value
+    TBool retVal = EFalse;
+   
+    TInt ret = Open();
+    if (ret != KErrNone)
+    {
+        Close();
+        Open();
+       
+    }
+    
+    iItemsDatabase.Begin();
+    
+    // Create a query to find the item.
+    TFileName queryBuffer;
+    _LIT(KFormatSpec, "%S%S%S%S%S'%S'");
+    
+    queryBuffer.Format(KFormatSpec, 
+        &KSelectfilepathFrom(), 
+        &KMapTileLookupTable(),
+        &KStringWhere(),
+        &NCntColFilePath(),
+        &KStringEqual(),
+        &aFilePath);
+    
+    // Create a view of the table with the above query.
+    RDbView myView;
+    TInt retPrep = myView.Prepare(iItemsDatabase, TDbQuery(queryBuffer));
+    CleanupClosePushL(myView);
+    myView.EvaluateAll();
+    myView.FirstL();
+
+    if (myView.AtRow())
+    {
+        // Item found, return true
+        retVal = ETrue;
+    }
+
+    CleanupStack::PopAndDestroy(&myView); // myView
+    Close();
+
+    return retVal;
+}
+
 // End of file
 
--- a/locationdataharvester/mylocationsengine/src/maptileinterface.cpp	Thu May 27 12:49:34 2010 +0300
+++ b/locationdataharvester/mylocationsengine/src/maptileinterface.cpp	Fri Jun 11 13:33:47 2010 +0300
@@ -24,12 +24,19 @@
 #include <bautils.h>
 #include "maptileinterface.h"
 #include "mylocationlogger.h"
+#include "mylocationsdefines.h"
+#include "lookupmaptiledb.h"
+#include <math.h>
 
 //Invalid latitude & longitude value
 const TReal KInvalidLatitudeLongitude = 200.00;
-const TInt KStreetLvelZoom = 14;
-const TInt KCityLevelZoom = 7;
-const TInt KMapTileSize= 256;
+const TInt KStreetLvelZoom = 15;
+const TInt KCityLevelZoom = 11;
+const TInt KMapTileWidth= 330;
+const TInt KMapTileHeight= 128;
+const TInt KImagePathSize=36;
+const TInt KMapTileWidthHeight = 256 ;
+_LIT(KFileExtn, ".png");
 
 // -----------------------------------------------------------------------------
 // CMapTileInterface::NewL()
@@ -89,11 +96,11 @@
     iMaptileGeocoder->SetMaptileGeocoderObserver( *this );
 }
 // -----------------------------------------------------------------------------
-// CMapTileInterface::GetMapTileImageL()
-// Interface for requesting maptile image for a landmark object
+// CMapTileInterface::GetGeoCodeFromAddressL()
+// Interface for requesting GEO fields for the given address
 // -----------------------------------------------------------------------------
 //
-void CMapTileInterface::GetMapTileImageL(const TDesC& aAddressDetails,
+void CMapTileInterface::GetGeoCodeFromAddressL(const TDesC& aAddressDetails,
         const TDesC& aFilePath, MMapTileObserver* aObserver)
 {
     __TRACE_CALLSTACK;
@@ -103,15 +110,15 @@
     iFilePath = HBufC::NewL(aFilePath.Length());
     iFilePath->Des().Copy(aFilePath);
     iStreetAvailable = EFalse;
-    TConnectionOption conn = ESilent;
-    iMaptileGeocoder->GetCoordinateByAddressL(aAddressDetails, conn);
+    iMaptileGeocoder->GetCoordinateByAddressL(aAddressDetails, ESilent);
+     
 }
 // -----------------------------------------------------------------------------
-// CMapTileInterface::GetMapTileImageL()
-// Interface for requesting maptile image for a landmark object
+// CMapTileInterface::GetGeoCodeFromAddressL()
+// Interface for requesting GEO fields for the given landmark adress
 // -----------------------------------------------------------------------------
 //
-void CMapTileInterface::GetMapTileImageL(CPosLandmark* aLandmark,
+void CMapTileInterface::GetGeoCodeFromAddressL(CPosLandmark* aLandmark,
         const TDesC& aFilePath, MMapTileObserver* aObserver)
 {
     __TRACE_CALLSTACK;
@@ -121,15 +128,17 @@
     iFilePath = HBufC::NewL(aFilePath.Length());
     iFilePath->Des().Copy(aFilePath);
 
+    //Reset the street level available flag
+	iStreetAvailable = EFalse;
+	
     TPtrC getStreet;
     aLandmark->GetPositionField(EPositionFieldStreet, getStreet);
 
     if (getStreet.Length() > 0)
-    {
+   {
         iStreetAvailable = ETrue;
     }
-    TConnectionOption conn = ESilent;
-    iMaptileGeocoder->GetCoordinateByAddressL(*aLandmark, conn);
+    iMaptileGeocoder->GetCoordinateByAddressL(*aLandmark, ESilent);
 }
 
 // -----------------------------------------------------------------------------
@@ -137,18 +146,16 @@
 // Function for Retrieving latitude & longitude information
 // -----------------------------------------------------------------------------
 //
-void CMapTileInterface::GetMapTileL(TReal aLatitude, TReal aLongitude)
+void CMapTileInterface::GetMapTileL( const TReal& aLatitude, const TReal& aLongitude)
 {
     __TRACE_CALLSTACK;//Notification to observer , to update contact db,
-    iObserver->RestGeoCodeCompleted(aLatitude, aLongitude);
     TInt zoom = KCityLevelZoom;
-    TInt size = KMapTileSize;
     if (iStreetAvailable)
     {
         zoom = KStreetLvelZoom;
     }
     iStreetAvailable = EFalse;
-    TMapTileParam mapTileparam(aLatitude, aLongitude, zoom, size);
+    TMapTileParam mapTileparam(aLatitude, aLongitude, zoom, KMapTileWidth, KMapTileHeight );
     iMaptileGeocoder->GetMapTileByGeoCodeL( mapTileparam, *iFilePath );
 }
 
@@ -162,7 +169,46 @@
     __TRACE_CALLSTACK;
     MYLOCLOGSTRING1("MapComplete() status-%d ",aErrCode );
     iObserver->MapTilefetchingCompleted( aErrCode, aMapTilePath );
+}
 
+// ----------------------------------------------------------------------------
+// CMapTileInterface::UpdateFilePathL()
+// Converts the geocoordinate to maptile pixel coordinate and updates the
+// file path to Maptilefolder\RowCol.png
+// ----------------------------------------------------------------------------
+//
+void CMapTileInterface::UpdateFilePathL( const TReal& aLatitude, const TReal& aLongitude )
+{
+    TInt iZoomLvl = KCityLevelZoom;
+    if ( iStreetAvailable )
+        iZoomLvl = KStreetLvelZoom;
+    
+    TInt totalTilesHorizontal = 1 << iZoomLvl;
+    TInt totalTilesVertical = 1 << iZoomLvl;
+
+    TInt totalMapWidth = totalTilesHorizontal * KMapTileWidthHeight;
+    TInt totalMapHeight = totalTilesVertical * KMapTileWidthHeight;
+    
+    TReal pi = 3.14159265;
+
+    TInt convertedx = (( aLongitude + 180.0) * totalMapWidth)
+            / 360.0;
+    TReal convertedtemp = log(tan(( aLatitude + 90) * pi
+            / 360.0));
+    int convertedy = (1 - convertedtemp / pi) * totalMapHeight / 2.0;
+
+    //Get the image row,col
+    TInt iMapTileImageRow = convertedy / 256.0;
+    TInt iMapTileImageCol = convertedx / 256.0;
+    
+    TBuf<KImagePathSize> mImagePath;
+
+    mImagePath.AppendNum(iMapTileImageRow);
+    mImagePath.AppendNum(iMapTileImageCol);
+    mImagePath.Append(KFileExtn);   
+    
+    iFilePath = iFilePath->ReAllocL(iFilePath->Length() + mImagePath.Length() );
+    iFilePath->Des().Append(mImagePath);
 }
 
 // -----------------------------------------------------------------------------
@@ -187,24 +233,22 @@
         if ( latitude != KInvalidLatitudeLongitude
                 && longitude != KInvalidLatitudeLongitude)
         {           
-            TRAP_IGNORE( SetLandMarkDetailsL(aAddressInfo) );            
-            TRAPD( error, GetMapTileL(latitude, longitude) );
-            if ( error != KErrNone )
-            {
-                //Log error message
-				 MYLOCLOGSTRING1("GetMapTileL() status-%d",error);
-				 iObserver->MapTilefetchingCompleted(error, KNullDesC);
-            }
+            TRAP_IGNORE( SetLandMarkDetailsL(aAddressInfo) );
+			      TRAP_IGNORE( UpdateFilePathL( latitude, longitude ) );
+	      
+            iObserver->GeoCodefetchingCompleted(KErrNone,  latitude, longitude, iFilePath->Des());
+
         }
         else
         {
-            iObserver->MapTilefetchingCompleted(KErrGeneral, KNullDesC);
-        }
+            iObserver->GeoCodefetchingCompleted(KErrGeneral,
+		      KInvalidLatitudeLongitude, KInvalidLatitudeLongitude, KNullDesC);
+        }        
     }
     else
     {
-        iObserver->MapTilefetchingCompleted(aErrorcode, KNullDesC);
-
+        iObserver->GeoCodefetchingCompleted(aErrorcode,
+		       KInvalidLatitudeLongitude, KInvalidLatitudeLongitude, KNullDesC );
     }
 }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/locationdataharvester/mylocationsengine/src/mylocationgeotagtimerao.cpp	Fri Jun 11 13:33:47 2010 +0300
@@ -0,0 +1,155 @@
+/*
+* Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies). 
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:  Implements geotagging 3AM timer
+*
+*/
+
+#include "mylocationgeotagtimerao.h"
+#include <mylocationlogger.h>
+#include <aknappui.h>
+#include <aknnotewrappers.h>
+#include <avkon.hrh>
+
+//Time at which the geotagging should be triggered( 3.00 AM )
+const TInt GEOTAGGING_TIME_IN_HOURS = 3;
+//Hour specified in minutes
+const TInt HOUR_VALUE_IN_MINUTES = 60;
+//Hour specified in seconds
+const TInt HOUR_VALUE_IN_SECONDS = 3600;
+
+// --------------------------------------------------------------------------
+// CLocationGeoTagTimerAO::CLocationGeoTagTimerAO
+// --------------------------------------------------------------------------
+//
+CLocationGeoTagTimerAO::CLocationGeoTagTimerAO( MyLocationTimerObserver& aObserver ):
+            CTimer(EPriorityStandard ),
+            iTimerObserver(&aObserver)
+{
+
+}
+
+
+// --------------------------------------------------------------------------
+// CLocationGeoTagTimerAO::~CLocationGeoTagTimerAO
+// --------------------------------------------------------------------------
+//
+CLocationGeoTagTimerAO::~CLocationGeoTagTimerAO()
+{
+    MYLOCLOGSTRING ("CLocationGeoTagTimerAO::~CLocationGeoTagTimerAO(), begin");
+    DoCancel();
+    MYLOCLOGSTRING ("CLocationGeoTagTimerAO::~CLocationGeoTagTimerAO(), end");
+}
+
+// --------------------------------------------------------------------------
+// CLocationGeoTagTimerAO::NewL
+// --------------------------------------------------------------------------
+//
+CLocationGeoTagTimerAO* CLocationGeoTagTimerAO::NewL( MyLocationTimerObserver& aObserver )
+{
+    CLocationGeoTagTimerAO* self = 
+         new( ELeave ) CLocationGeoTagTimerAO( aObserver);
+    CleanupStack::PushL( self );
+    self->ConstructL();
+    CleanupStack::Pop();
+   
+    return self;
+}
+
+
+// --------------------------------------------------------------------------
+// CLocationGeoTagTimerAO::ConstructL
+// --------------------------------------------------------------------------
+//
+void CLocationGeoTagTimerAO::ConstructL()
+{
+    MYLOCLOGSTRING ("CLocationGeoTagTimerAO::ConstructL(), begin");
+    CActiveScheduler::Add(this);
+    CTimer::ConstructL();
+    MYLOCLOGSTRING ("CLocationGeoTagTimerAO::ConstructL(), end");
+}
+
+// --------------------------------------------------------------------------
+// CLocationGeoTagTimerAO::StartTimer
+// --------------------------------------------------------------------------
+//
+void CLocationGeoTagTimerAO::StartTimer()
+{
+    MYLOCLOGSTRING ("CLocationGeoTagTimerAO::StartTimer(), begin");
+    if(!IsActive())
+    {
+        TTime hometime;
+        hometime.HomeTime();
+        
+        //Get the current time in Hour,Minute, Second
+        TDateTime  currentDateTime = hometime.DateTime();
+        TInt currentHr = currentDateTime.Hour(); 
+        TInt currentMin = currentDateTime.Minute();
+        TInt currentSec = currentDateTime.Second();
+        
+        //3 AM in seconds
+        TInt targetTimeInSeconds = GEOTAGGING_TIME_IN_HOURS * HOUR_VALUE_IN_SECONDS;
+        TInt timeDifference;
+        
+        //Find the time difference in seconds between current time to 3.00 AM 
+        //Either on same day or next day.
+        if ( currentHr < GEOTAGGING_TIME_IN_HOURS )
+        {
+           timeDifference = targetTimeInSeconds - 
+                    ( ( currentHr * HOUR_VALUE_IN_SECONDS  ) + ( currentMin * HOUR_VALUE_IN_MINUTES ) + currentSec );
+        }
+        else
+        {
+           timeDifference = ( 24 * HOUR_VALUE_IN_SECONDS - ( 
+                    ( currentHr * HOUR_VALUE_IN_SECONDS ) + ( currentMin * HOUR_VALUE_IN_MINUTES ) + currentSec ) )  +
+                    targetTimeInSeconds ;
+        }
+        
+        //Add the time difference to current time to set the target time ( 3.00 AM )
+        TTimeIntervalSeconds interval( timeDifference );
+        TTime timeToSet;
+        timeToSet.HomeTime();
+        timeToSet+= interval;
+        
+        At( timeToSet );
+    }
+    MYLOCLOGSTRING ("CLocationGeoTagTimerAO::StartTimer(), end");
+}
+
+
+// --------------------------------------------------------------------------
+// CLocationGeoTagTimerAO::RunL
+// --------------------------------------------------------------------------
+//
+void CLocationGeoTagTimerAO::RunL( )
+{
+    MYLOCLOGSTRING ("CLocationGeoTagTimerAO::RunL(), begin");
+    TInt status = iStatus.Int();
+    
+    switch( status )
+    {
+        case KErrNone:
+            //Trigger the reverse geocoding and start the timer again
+            //Create the instance of geotagger class
+            iTimerObserver->MyLocationThreeAMTimerExpiredL();
+            
+            break;
+        default:
+            StartTimer();
+            break;
+    }
+    MYLOCLOGSTRING ( "CLocationGeoTagTimerAO::RunL(), end" );
+}
+
+// End of file
+
--- a/locationdataharvester/mylocationsengine/src/mylocationsdatabasemanager.cpp	Thu May 27 12:49:34 2010 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1090 +0,0 @@
-/*
-* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
-* All rights reserved.
-* This component and the accompanying materials are made available
-* under the terms of "Eclipse Public License v1.0"
-* which accompanies this distribution, and is available
-* at the URL "http://www.eclipse.org/legal/epl-v10.html".
-*
-* Initial Contributors:
-* Nokia Corporation - initial contribution.
-*
-* Contributors:
-*
-* Description: Database manager implementation for location picker and
-*              maptile service.
-*
-*/
-
-#include <EPos_CPosLandmark.h>
-#include <EPos_CPosLandmarkCategory.h>
-#include <EPos_CPosLmTextCriteria.h>
-#include <EPos_CPosLandmarkSearch.h>
-#include <EPos_CPosLmDatabaseManager.h>
-#include <EPos_CPosLmNearestCriteria.h>
-
-#include <lbsposition.h>
-//#include <mylocations.rsg>
-#include <barsread.h>
-#include <barsc.h>
-#include <locationservicedefines.h>
-#include "mylocationsdatabasemanager.h"
-#include "mylocationlogger.h"
-#include "mylocationsdefines.h"
-
-// separator
-_LIT( KSeparator, ",");
-// space
-_LIT( KSpace, " ");
-
-// QString separator
-const QString KQStringSeparator = ",";
-// QString space
-const QString KQStringSpace = " ";
-
-// Used to set nearest landmarks search distance criteria
-const TUint32 KSearchCriteriaDistance = 100; 
-
-// -----------------------------------------------------------------------------
-// CMyLocationsDatabaseManager::ConstructL()
-// 2nd phase constructor.
-// -----------------------------------------------------------------------------
-//
-void CMyLocationsDatabaseManager::ConstructL()
-{
-    __TRACE_CALLSTACK;//Open and intialize Landmark DB
-    iLandmarkDb = CPosLandmarkDatabase::OpenL();
-    ExecuteAndDeleteLD(iLandmarkDb->InitializeL());
-
-    // create landmarks lookup database.
-    iLandmarksLookupDb = CLookupDatabase::NewL(KLandmarksLookupDatabaseName);
-    User::LeaveIfError( iLandmarksLookupDb->Open() );
- 
-    iLocationAppLookupDb = new LocationDataLookupDb();
-    if( !iLocationAppLookupDb->open() )
-    {
-        User::Leave( KErrUnknown );
-    }
-    
-    // Create category manager for landmarks
-    iLandmarksCatManager = CPosLmCategoryManager::NewL(*iLandmarkDb);
-
-    // open file session
-    User::LeaveIfError(iFsSession.Connect());
-
-    // Add contacts and calendar  categories
-    iLmContactsCatId = AddMylocationsCategoryL(KContactsCategory);
-    iLmCalendarCatId = AddMylocationsCategoryL( KCalendarCategory );
-
-}
-
-// -----------------------------------------------------------------------------
-// CMyLocationsDatabaseManager::CMyLocationsDatabaseManager()
-// Default constructor.
-// -----------------------------------------------------------------------------
-//
-CMyLocationsDatabaseManager::CMyLocationsDatabaseManager() : iLandmarkDb( NULL ),
-                iLmContactsCatId( 0 ), iLandmarksLookupDb( NULL ), 
-                iLocationAppLookupDb( NULL ),
-                iLandmarksCatManager( NULL )
-{
-}
-
-// -----------------------------------------------------------------------------
-// CMyLocationsDatabaseManager::_CMyLocationsDatabaseManager()
-// Destructor.
-// -----------------------------------------------------------------------------
-//
-CMyLocationsDatabaseManager::~CMyLocationsDatabaseManager()
-{
-    __TRACE_CALLSTACK;// delete member variables.
-    if (iLandmarksLookupDb)
-    {
-        iLandmarksLookupDb->Close();
-        delete iLandmarksLookupDb;
-    }
-    if (iLocationAppLookupDb)
-    {
-        iLocationAppLookupDb->close();
-        delete iLocationAppLookupDb;
-    }
-
-    delete iLandmarksCatManager;
-
-    delete iLandmarkDb;
-
-    // close the file session
-    iFsSession.Close();
-
-}
-
-// -----------------------------------------------------------------------------
-// CMyLocationsDatabaseManager::AddMylocationsCategoryL()
-// Adds the category to the mylocations and landmarks database..
-// -----------------------------------------------------------------------------
-//
-TUint32 CMyLocationsDatabaseManager::AddMylocationsCategoryL( const TDesC&  aCategoryName )
-{
-    __TRACE_CALLSTACK;//Open the resource file
-    
-    TPosLmItemId catId = 0;
-    
-    //create category
-    CPosLandmarkCategory *category = CPosLandmarkCategory::NewL();
-    CleanupStack::PushL(category);
-    category->SetCategoryNameL( aCategoryName );
-    
-    // Add category to landmarks database
-    TRAPD ( error, ( catId = iLandmarksCatManager->AddCategoryL( *category ) ) );
-    if (error == KErrNone || error == KErrAlreadyExists)
-    {
-        catId = iLandmarksCatManager->GetCategoryL( aCategoryName );
-    }
-
-    CleanupStack::PopAndDestroy(category);
-
-    return catId;
-}
-
-// -----------------------------------------------------------------------------
-// CMyLocationsDatabaseManager::UpdateDatabaseL()
-// Updates the location into the landmark database and lookup table. Based on 
-// the entry source type and the entry change type the updation can be 
-// addition/modification/deletion.
-// -----------------------------------------------------------------------------
-//
-void CMyLocationsDatabaseManager::UpdateDatabaseL(CPosLandmark* aLandmark,
-        const TUint32 aUid, const TUint32 aSourceType, const TEntryChangeType aChangeType)
-{
-    __TRACE_CALLSTACK;//open the lookup database
-    switch (aChangeType)
-    {
-    // if the entry is added
-    case EEntryAdded:
-    {
-        // Handle this entry in the lookup table and update landmarks db.
-        HandleEntryAdditionL(aLandmark, aUid, aSourceType);
-        break;
-    }
-        // if the entry is modified
-    case EEntryModified:
-    {
-        // Handle this entry in the lookup table and update landmarks db.
-        HandleEntryModificationL(aLandmark, aUid, aSourceType);
-        break;
-    }
-        // if the entry is deleted
-    case EEntryDeleted:
-    {
-        // Handle this entry in the lookup table and update landmarks db.
-        HandleEntryDeletionL(aUid, aSourceType);
-        break;
-    }
-    }
-
-}
-
-// -----------------------------------------------------------------------------
-// CMyLocationsDatabaseManager::CheckIfDuplicateExistsL()
-// Checks if this landmark is already present in database. If present returns the landmark id, else 0
-// -----------------------------------------------------------------------------
-//
-TPosLmItemId CMyLocationsDatabaseManager::CheckIfDuplicateExistsL(
-                                    const CPosLandmark* aLandmark)
-{
-    __TRACE_CALLSTACK;// Stores the found duplicate landmark's id. 
-    TPosLmItemId retId = 0;
-
-    // Initially filter only the landmarks which are nearer to the current landmark.
-    // Then we can make a duplicate check on each of the found landmarks.
-
-    // create a search object.
-    CPosLandmarkSearch* search = CPosLandmarkSearch::NewL(
-            *iLandmarkDb);
-    CleanupStack::PushL(search);
-
-    TBuf<KMaxAddressLength> lmAddress1;
-    GetLandmarkFullAddress( lmAddress1, aLandmark );
-    QString str1 = QString( (QChar*)lmAddress1.Ptr(), lmAddress1.Length());
-
-    // create nearest search criteria object
-    TLocality position( TCoordinate( 0, 0), 0 );
-    aLandmark->GetPosition( position );
-    CPosLmNearestCriteria* nearestCriteria = 
-                CPosLmNearestCriteria::NewLC( 
-                        TCoordinate( position.Latitude(), position.Longitude() ) );
-    nearestCriteria->SetMaxDistance( KSearchCriteriaDistance );
-    
-    // Start the search and execute it at once.
-    ExecuteAndDeleteLD( search->StartLandmarkSearchL( *nearestCriteria ) );
-    CleanupStack::PopAndDestroy( nearestCriteria );
-
-    // Retrieve an iterator to access the matching landmarks.
-    CPosLmItemIterator* iter = search->MatchIteratorL();
-    CleanupStack::PushL(iter);
-
-    // Iterate the search matches.
-    TPosLmItemId lmId;
-
-    while( ( lmId = iter->NextL() ) != KPosLmNullItemId )
-    {
-        CPosLandmark* lm = iLandmarkDb->ReadLandmarkLC( lmId );
-        TBuf<KMaxAddressLength> lmAddress2;
-        GetLandmarkFullAddress( lmAddress2, lm );
-        QString str2 = QString( (QChar*)lmAddress2.Ptr(), lmAddress2.Length());
-        CleanupStack::PopAndDestroy( lm );
-        
-        if( str1 == str2 )
-        {
-            retId = lmId;
-            break;
-        }
-    }
-
-    CleanupStack::PopAndDestroy(iter);
-    CleanupStack::PopAndDestroy(search);
-
-    return retId;
-}
-
-// -----------------------------------------------------------------------------
-// CMyLocationsDatabaseManager::CompareLandmarks()
-// Compares two landmarks. Only the text fields, landmark name, street, city, state country and 
-// postal code are compared.
-// -----------------------------------------------------------------------------
-//
-TBool CMyLocationsDatabaseManager::CompareLandmarks(
-        const CPosLandmark* aLandmark1, const CPosLandmark* aLandmark2 )
-{
-    __TRACE_CALLSTACK;
-
-    TBuf<KMaxAddressLength> lmAddress1;
-    GetLandmarkFullAddress( lmAddress1, aLandmark1 );
-    QString str1 = QString( (QChar*)lmAddress1.Ptr(), lmAddress1.Length());
-
-    TBuf<KMaxAddressLength> lmAddress2;
-    GetLandmarkFullAddress( lmAddress2, aLandmark2 );
-    QString str2 = QString( (QChar*)lmAddress2.Ptr(), lmAddress2.Length());
-
-    if( str1 == str2 )
-        return ETrue;
-    else
-        return EFalse;
-    
-    
-}
-
-// -----------------------------------------------------------------------------
-// CMyLocationsDatabaseManager::HandleEntryAdditionL()
-// Handles the entry addition in lookup table and landmarks db
-// -----------------------------------------------------------------------------
-//
-void CMyLocationsDatabaseManager::HandleEntryAdditionL(CPosLandmark* aLandmark,
-        const TUint32 aUid, const TUint32 aSourceType)
-{
-    __TRACE_CALLSTACK;
-    // Create a lookup item
-    QLookupItem lookupItem;
-    lookupItem.mSourceUid = aUid;
-    lookupItem.mSourceType = aSourceType;
-    lookupItem.mDestId = 0;
-    lookupItem.mIconType = QLookupItem::EIconTypeDefault;
-    lookupItem.mIsDuplicate = 0;
-    lookupItem.mIconPath = "";
-    lookupItem.mMapTilePath = "";
-    
-    //fill address into lookup item.
-    FillLookupItemAddressDetails( aLandmark, lookupItem );
-
-    if ( aSourceType == ESourceLandmarks )
-    {
-        // Logic: check if the entry is already present in lookupdb. 
-        // If present, it means the landmark corresponds to a contact/calendar. So ignore it.
-        // If not present, it means the landmark is created directly into the landmarks db. So add
-        // it in lookupdb as well.
-        
-        // check if the entry is already present in lookup db.
-        QList<QLookupItem> itemArray;
-        iLocationAppLookupDb->findEntriesByLandmarkId( aUid, itemArray );
-        if( itemArray.count() )
-        {
-            return;
-        }
-        else
-        {
-            lookupItem.mDestId = aUid;
-            iLocationAppLookupDb->createEntry( lookupItem );
-            return;
-        }
-    }
-
-    TPosLmItemId catId;
-    if( aSourceType == ESourceCalendar )
-    {
-        // category id to calendar
-        catId = iLmCalendarCatId;
-    }
-    else 
-    {
-        // remove landmark name, which is basically contact's name.
-        aLandmark->SetLandmarkNameL( KNullDesC );
-        // category id to contacts
-        catId = iLmContactsCatId;
-    }
-    // check if this landmark is already present in database
-    TPosLmItemId dupLmId = CheckIfDuplicateExistsL( aLandmark );
-    if ( dupLmId )
-    {
-        // landmark already present in db. get the details
-        CPosLandmark* dupLandmark = iLandmarkDb->ReadLandmarkLC(dupLmId);
-        if( dupLandmark )
-        {
-            // add category.
-            dupLandmark->AddCategoryL( catId );
-            // update the landmark object in the db
-            iLandmarkDb->UpdateLandmarkL( *dupLandmark );
-            CleanupStack::PopAndDestroy( dupLandmark );
-        }
-
-        // point the lookup item's landmark uid to the existing landmark.
-        lookupItem.mDestId = dupLmId;
-        if( aSourceType == ESourceCalendar )
-        {
-            // set duplicate flag to true. only if it is calendar entry.
-            // for contacts duplicate doesnot hold good as the location name is the contact name.
-        
-            // set duplicate only if there are calendar entries already pointing to this landmark. 
-            if( IsDuplicateEntry( dupLmId ) )
-            {
-                lookupItem.mIsDuplicate = 1;
-            }
-        }
-    }
-    else // it is a new entry, so add into the database
-    {
-        // add category.
-        aLandmark->AddCategoryL( catId );
-        // add the landmark into the db. 
-        // point the lookup item's landmark uid to the newly created landmark in the db.
-        lookupItem.mDestId = iLandmarkDb->AddLandmarkL( *aLandmark );
-    }
-
-    // create the entry in the lookup table.
-    iLocationAppLookupDb->createEntry( lookupItem );
-}
-
-// -----------------------------------------------------------------------------
-// CMyLocationsDatabaseManager::HandleEntryModificationL()
-// Handles the entry modification in the lookup table and landmarks db.
-// -----------------------------------------------------------------------------
-//
-void CMyLocationsDatabaseManager::HandleEntryModificationL(
-        CPosLandmark* aLandmark, const TUint32 aUid, const TUint32 aSourceType )
-{
-    __TRACE_CALLSTACK;
-    if ( aSourceType == ESourceLandmarks )
-    {
-        HandleLandmarkModificationL( aLandmark, aUid );
-        return;
-    }
-
-    QLookupItem lookupItem;
-    lookupItem.mSourceUid = aUid;
-    lookupItem.mSourceType = aSourceType;
-    lookupItem.mIconType = QLookupItem::EIconTypeDefault;
-
-    // Behavior: If an entry is modified, 
-    // If this entry is not present in lookup table. add the entry and update the landmarks db.
-    // If this entry is already present in lookup table, check if the location info is modified or not.
-    // If the location info is modified, delete the landmark from db and add the new landmark
-    // into the db. 
-    // Before deletion make sure that the landmark is not being refered by other lookup entries.
-
-    // find the entry in the lookup table.
-    if ( iLocationAppLookupDb->findEntryBySourceIdAndType( lookupItem ) )
-    {
-        //fill address into lookup item.
-        FillLookupItemAddressDetails( aLandmark, lookupItem );
-        
-        QString locationName = lookupItem.mName;
-    
-        TPosLmItemId catId;
-        
-        if( aSourceType == ESourceCalendar )
-        {
-            catId = iLmCalendarCatId;
-        }
-        else
-        {
-            // remove landmark name, which is basically contact's name.
-            aLandmark->SetLandmarkNameL( KNullDesC );
-            
-            // category id to contacts
-            catId = iLmContactsCatId;
-        }
-
-        
-        // check if the location info is modified by comparing the new landmark with the existing landmark
-        CPosLandmark* existingLandmark = NULL;
-        TRAPD( error, ( existingLandmark = 
-               CheckAndReadLandmarkL( iLandmarkDb, lookupItem.mDestId ) ) );
-        CleanupStack::PushL( existingLandmark );
-        if ( error == KErrNotFound )
-        {
-            // Landmarks item deleted. So delete corresponding lookup entries.
-            QList<QLookupItem> itemArray;
-            iLocationAppLookupDb->findEntriesByLandmarkId( lookupItem.mDestId, itemArray );
-            for ( int i = 0; i < itemArray.count(); i++)
-            {
-                iLocationAppLookupDb->deleteEntryBySourceIdAndType( itemArray[i] );
-            }
-
-            // Add the entry into the lookup table and update landmarks db.
-            HandleEntryAdditionL( aLandmark, aUid, aSourceType );
-            
-            CleanupStack::PopAndDestroy( existingLandmark );
-            return;
-        }
-
-        if ( !CompareLandmarks( existingLandmark, aLandmark ) )
-        {
-            // landmarks are not same, means location information is modified.
-
-            // Check if the new landmark is already in db.
-            TPosLmItemId dupLmId = CheckIfDuplicateExistsL( aLandmark );
-            if ( dupLmId )
-            {
-                // landmark already present in db. get the details
-                CPosLandmark* dupLandmark = iLandmarkDb->ReadLandmarkLC( dupLmId );
-                if ( dupLandmark )
-                {
-                    // add category.
-                    dupLandmark->AddCategoryL( catId );
-
-                    // update the landmark object in the db
-                    iLandmarkDb->UpdateLandmarkL( *dupLandmark );
-                }
-                CleanupStack::PopAndDestroy( dupLandmark );
-
-                // update the lookup item to refer to the newly created landmark.
-                lookupItem.mDestId = dupLmId;
-                if( aSourceType == ESourceCalendar )
-                {
-                    // for contacts duplicate doesnot hold good as the location name is the contact name.
-                    if( !lookupItem.mIsDuplicate )
-                    {
-                        // if current lookup item duplicate property is 0, then remove next corresponding
-                        // calendar lookup entry duplicate property.
-                        // this is required because the current entry will be pointing to a new landmark.
-                        UnsetDuplicateNextCalEntry( existingLandmark->LandmarkId() );
-                    } 
-
-                    // set duplicate only if there are calendar entries already pointing to this landmark. 
-                    if( IsDuplicateEntry( dupLmId ) )
-                    {
-                        lookupItem.mIsDuplicate = 1;
-                    }
-
-                }
-                
-                iLocationAppLookupDb->updateEntryBySourceIdAndType( lookupItem );
-            }
-            else
-            {
-                // landmark not already present in db.
-                // Create a new entry in the db
-                aLandmark->AddCategoryL( catId );
-                lookupItem.mDestId = iLandmarkDb->AddLandmarkL( *aLandmark );
-                if( aSourceType == ESourceCalendar )
-                {
-                    // for contacts duplicate doesnot hold good as the location name is the contact name.
-                    if( !lookupItem.mIsDuplicate )
-                    {
-                        // if current lookup item duplicate property is 0, then remove next corresponding
-                        // calendar lookup entry duplicate property.
-                        // this is required because the current entry will be pointing to a new landmark.
-                        UnsetDuplicateNextCalEntry( existingLandmark->LandmarkId() );
-                    } 
-                }
-                
-                lookupItem.mIsDuplicate = 0;
-                // update the lookup table
-                iLocationAppLookupDb->updateEntryBySourceIdAndType( lookupItem );
-            }
-        }
-        else
-        {
-            // landmarks are same, means location not modified. So return.
-            if( aSourceType == ESourceContactsPref
-                                    || aSourceType == ESourceContactsWork
-                                    || aSourceType == ESourceContactsHome
-                                    )
-            {
-                // in case of contacts, there is a chance that contact name is modified. 
-                // so update the lookup database entry with that name.
-                lookupItem.mName = locationName;
-                iLocationAppLookupDb->updateEntryBySourceIdAndType( lookupItem );
-            }
-
-            CleanupStack::PopAndDestroy( existingLandmark );
-            return;
-        }
-
-        // delete the existing landmark only if it not being refered by other lookup entries.
-
-        // Check if any other entries are refering this landmark.
-        QList<QLookupItem> itemArray;
-        iLocationAppLookupDb->findEntriesByLandmarkId(
-                existingLandmark->LandmarkId(), itemArray );
-
-        if ( itemArray.count() )
-        {
-            // There are other lookup entries refering this landmark. So do not delete the landmark
-
-            // If none of these lookup item's source type is current source type, disassociate 'catId' category
-            // from this landmark.
-            TInt i = 0;
-            while ( i < itemArray.count() )
-            {
-                if( aSourceType == ESourceCalendar )
-                {
-                    if ( itemArray[i].mSourceType == aSourceType )
-                    {
-                        // a lookup item exists which is from calendar, so 'catId' is still valid.
-                        break;
-                    }
-                 }
-                else 
-                {
-                    // a lookup item exists which is from contacts, so 'catId' is still valid.
-                    break;
-                }
-                i++;
-            }
-            if ( i == itemArray.count() )
-            {
-                // no lookup items from current source type exists refering this landmark.
-                // so disassociate 'catId' from this landmark
-
-                existingLandmark->RemoveCategory( catId );
-                iLandmarkDb->UpdateLandmarkL( *existingLandmark );
-            }
-        }
-        else
-        {
-            // no other lookup entry is refering this landmark. 
-            // delete the landmark.
-            iLandmarkDb->RemoveLandmarkL( existingLandmark->LandmarkId() );
-        }
-        CleanupStack::PopAndDestroy( existingLandmark );
-
-    }
-    else // entry not present in lookup table
-    {
-        // Add the entry into the lookup table and update landmarks db.
-        HandleEntryAdditionL( aLandmark, aUid, aSourceType );
-    }
-}
-
-// -----------------------------------------------------------------------------
-// CMyLocationsDatabaseManager::HandleEntryDeletionL()
-// Handles the entry deletion in lookup table and landmarks db.
-// -----------------------------------------------------------------------------
-//
-void CMyLocationsDatabaseManager::HandleEntryDeletionL(const TUint32 aUid,
-                                                const TUint32 aSourceType)
-{
-    __TRACE_CALLSTACK;
-    QLookupItem lookupItem;
-    lookupItem.mSourceUid = aUid;
-    lookupItem.mSourceType = aSourceType;
-
-    // Behavior: if an entry is deleted, delete the corresponding entries from 
-    // both lookup table and iLandmarkDb.  
-    // Before deleting the entry from iLandmarkDb, make sure that this entry is not being refered by
-    // other entries of the lookup table. If it is being refered by other entries in lookup table, then
-    // do not delete the landmark.
- 
-    if ( !iLocationAppLookupDb->findEntryBySourceIdAndType( lookupItem ) )
-    {
-        if( aSourceType == ESourceLandmarks )
-        {
-            lookupItem.mDestId = aUid;
-        }
-        else
-        {
-            return;
-        }
-    }
-    
-    // Find the corresponding landmark uid
-    
-
-    // delete the lookup entry.
-    iLocationAppLookupDb->deleteEntryBySourceIdAndType( lookupItem );
-
-    // Check if any other entries are refering this landmark.
-    QList<QLookupItem> itemArray;
-    iLocationAppLookupDb->findEntriesByLandmarkId( lookupItem.mDestId, itemArray );
-
-    if ( itemArray.count() )
-    {
-    
-        if( aSourceType == ESourceLandmarks )
-        {
-            CPosLandmark* lm = NULL;
-        
-            for( int i = 0; i < itemArray.count(); i++ )
-            {
-                if( itemArray[i].mSourceType == ESourceCalendar )
-                {
-                    // add landmark entry since a calendar item is present with this location.
-                   if( !lm )
-                   {
-                       lm = CreateLandmarkItemLC( itemArray[i] );
-                   }
-                   lm->AddCategoryL( iLmCalendarCatId );
-                }
-                else
-                {
-                   // add landmark entry since a contact item is present with this location.
-                   if( !lm )
-                   {
-                       QString tempStr = itemArray[i].mName;
-                       itemArray[i].mName = "";
-                       lm = CreateLandmarkItemLC( itemArray[i] );
-                       itemArray[i].mName = tempStr;
-                   }
-                   lm->AddCategoryL( iLmCalendarCatId );
-                }    
-            }
-
-            lookupItem.mDestId = iLandmarkDb->AddLandmarkL( *lm );
-            CleanupStack::PopAndDestroy( lm );
-
-            bool dupUnset = false;
-            for( int i=0; i<itemArray.count(); i++ )
-            {
-                itemArray[i].mDestId = lookupItem.mDestId;
-                if( itemArray[i].mSourceType == ESourceCalendar && dupUnset == false )
-                {
-                    dupUnset = true;
-                    itemArray[i].mIsDuplicate = 0;
-                }
-                iLocationAppLookupDb->updateEntryById( itemArray[i] );
-            }   
-            
-            return;
-        }
-
-        // There are other lookup entries refering this landmark. So do not delete the landmark
-
-        // If none of these lookup item's source type is current source type, disassociate current source category
-        // from this landmark.
-        TInt i = 0;
-        while ( i < itemArray.count() )
-        {
-            if( aSourceType == ESourceCalendar )
-            {
-                if( itemArray[i].mSourceType == aSourceType )
-                {
-                    if( lookupItem.mIsDuplicate == 0 )
-                    {
-                        itemArray[i].mIsDuplicate = 0;
-                        iLocationAppLookupDb->updateEntryById( itemArray[i] );
-                    }
-                    // a lookup item exists which is from calendar, so 'iLmCalendarCatId' is still valid.
-                    break;
-                }
-        
-            }
-            else if ( itemArray[i].mSourceType == ESourceContactsPref
-                    || itemArray[i].mSourceType == ESourceContactsWork
-                    || itemArray[i].mSourceType == ESourceContactsHome)
-            {
-                // a lookup item exists which is from contacts, so 'iLmContactsCatId' is still valid.
-                break;
-            }
-            i++;
-        }
-        if ( i == itemArray.count() )
-        {
-            // no lookup items from current source type exists refering this landmark.
-            // so disassociate current source category from this landmark
-
-            CPosLandmark* landmark = iLandmarkDb->ReadLandmarkLC( lookupItem.mDestId );
-            if( aSourceType == ESourceCalendar )
-            {
-                landmark->RemoveCategory( iLmCalendarCatId );
-            }
-            else
-            {
-                landmark->RemoveCategory( iLmContactsCatId );
-            }
-            
-            iLandmarkDb->UpdateLandmarkL( *landmark );
-            CleanupStack::PopAndDestroy( landmark );
-        }
-    }
-    else
-    {
-        // no other lookup entry is refering this landmark. 
-        // delete the landmark.
-        if ( aSourceType != ESourceLandmarks )
-        {
-            iLandmarkDb->RemoveLandmarkL( lookupItem.mDestId );
-        }
-    }
-}
-
-// -----------------------------------------------------------------------------
-// CMyLocationsDatabaseManager::HandleLandmarkModificationL()
-// -----------------------------------------------------------------------------
-//
-void CMyLocationsDatabaseManager::HandleLandmarkModificationL(
-        CPosLandmark* aLandmark, const TUint32 aUid )
-{
-    // logic: if a landmark is modified, 
-    // first update the corresponding landmark lookup entry if present, else create a new entry.
-    // Check for any contact/calendar entries refering this landmark entry,
-    // if exists, create a new landmark entry with that location details and update all those 
-    // lookup entry's destid with the newly created landmark id.
-    
-    QLookupItem lookupItem;
-    lookupItem.mSourceUid = aUid;
-    lookupItem.mSourceType = ESourceLandmarks;
-    lookupItem.mIconType = QLookupItem::EIconTypeDefault;
-
-    bool found = iLocationAppLookupDb->findEntryBySourceIdAndType( lookupItem );
-    //fill address into lookup item.
-    FillLookupItemAddressDetails( aLandmark, lookupItem );
-    lookupItem.mDestId = aUid;
-    lookupItem.mIsDuplicate = 0;
-    lookupItem.mIconType = QLookupItem::EIconTypeDefault;
-    lookupItem.mIconPath = "";
-    lookupItem.mMapTilePath = "";
-
-    // update entry in lookup table.
-    if ( found )
-    {
-        iLocationAppLookupDb->updateEntryById( lookupItem );
-    }
-    else
-    {
-        iLocationAppLookupDb->createEntry( lookupItem );
-    }
-    
-    QList<QLookupItem> itemArray;
-    iLocationAppLookupDb->findEntriesByLandmarkId( lookupItem.mDestId, itemArray );
-    
-    if( itemArray.count() == 1 )
-    {
-        //only one entry ie the entry corresponding to landmark db is present.
-        return;
-    }
-    
-    CPosLandmark* lm = NULL;
-    
-    for( int i = 0; i < itemArray.count(); i++ )
-    {
-        if( itemArray[i].mSourceType != ESourceLandmarks )
-        {
-            if( itemArray[i].mSourceType == ESourceCalendar )
-            {
-                // add landmark entry since a calendar item is present with this location.
-               if( !lm )
-               {
-                   lm = CreateLandmarkItemLC( itemArray[i] );
-               }
-               lm->AddCategoryL( iLmCalendarCatId );
-            }
-            else
-            {
-               // add landmark entry since a calendar item is present with this location.
-               if( !lm )
-               {
-                   QString tempStr = itemArray[i].mName;
-                   itemArray[i].mName = "";
-                   lm = CreateLandmarkItemLC( itemArray[i] );
-                   itemArray[i].mName = tempStr;
-               }
-               lm->AddCategoryL( iLmCalendarCatId );
-            }    
-        }
-    }
-    
-    // add the entry to landmarks db
-    quint32 newDestId = iLandmarkDb->AddLandmarkL( *lm );
-    CleanupStack::PopAndDestroy( lm );
-
-    bool calDuplicateUnset = false;
-    // update all the lookup entries with new landmark id
-    for( int i = 0; i < itemArray.count(); i++ )
-    {
-        if( itemArray[i].mSourceType != ESourceLandmarks )
-        {
-            itemArray[i].mDestId = newDestId;
-            
-            if( itemArray[i].mSourceType == ESourceCalendar )
-            {
-                if( !calDuplicateUnset )
-                {
-                    itemArray[i].mIsDuplicate = 0;
-                    calDuplicateUnset = true;
-                }
-                else
-                {
-                    itemArray[i].mIsDuplicate = 1;
-                }
-            }
-            iLocationAppLookupDb->updateEntryById( itemArray[i] );
-        }
-    }
-}
-// -----------------------------------------------------------------------------
-// CMyLocationsDatabaseManager::GetLandmarkFullAddress()
-// Gets the comma separated full address of the given landmark.
-// -----------------------------------------------------------------------------
-//
-void CMyLocationsDatabaseManager::GetLandmarkFullAddress(
-        TBuf<KMaxAddressLength>& aLandmarkAddress,
-        const CPosLandmark* aLandmark)
-{
-    TPtrC tempStr;
-    TInt retStatus;
-    TBool addressEmtpy = ETrue;
-    retStatus = aLandmark->GetPositionField(EPositionFieldStreet, tempStr);
-    if (retStatus == KErrNone && tempStr.Length())
-    {
-        {
-            aLandmarkAddress.Copy(tempStr);
-            addressEmtpy = EFalse;
-        }
-    }
-
-    retStatus = aLandmark->GetPositionField(EPositionFieldCity, tempStr);
-    if (retStatus == KErrNone && tempStr.Length())
-    {
-        if (!addressEmtpy)
-        {
-            aLandmarkAddress.Append(KSeparator);
-            aLandmarkAddress.Append(KSpace);
-            aLandmarkAddress.Append(tempStr);
-        }
-        else
-        {
-            aLandmarkAddress.Copy(tempStr);
-            addressEmtpy = EFalse;
-        }
-    }
-
-    retStatus = aLandmark->GetPositionField(EPositionFieldState, tempStr);
-    if (retStatus == KErrNone && tempStr.Length())
-    {
-        if (!addressEmtpy)
-        {
-            aLandmarkAddress.Append(KSeparator);
-            aLandmarkAddress.Append(KSpace);
-            aLandmarkAddress.Append(tempStr);
-        }
-        else
-        {
-            aLandmarkAddress.Copy(tempStr);
-            addressEmtpy = EFalse;
-        }
-    }
-
-    retStatus = aLandmark->GetPositionField(EPositionFieldCountry, tempStr);
-    if (retStatus == KErrNone && tempStr.Length())
-    {
-        if (!addressEmtpy)
-        {
-            aLandmarkAddress.Append(KSeparator);
-            aLandmarkAddress.Append(KSpace);
-            aLandmarkAddress.Append(tempStr);
-        }
-        else
-        {
-            aLandmarkAddress.Copy(tempStr);
-            addressEmtpy = EFalse;
-        }
-    }
-}
-
-// -----------------------------------------------------------------------------
-// CMyLocationsDatabaseManager::CheckAndReadLandmarkL()
-// Checks if given landmark id is found in the database and returns the read landmark.
-// -----------------------------------------------------------------------------
-//
-CPosLandmark* CMyLocationsDatabaseManager::CheckAndReadLandmarkL(
-        CPosLandmarkDatabase* aDb, const TUint32 aLmId)
-{
-    __TRACE_CALLSTACK;
-    CPosLandmark* lm = aDb->ReadLandmarkLC(aLmId);
-    CleanupStack::Pop(lm);    
-    return lm;
-}
-
-// -----------------------------------------------------------------------------
-// CMyLocationsDatabaseManager::FillLookupItemAddressDetails()
-// Creates a new category in Mylocations Db and adds a corresponding entry in 
-// mylocations lookup table.
-// -----------------------------------------------------------------------------
-//
-void CMyLocationsDatabaseManager::FillLookupItemAddressDetails( CPosLandmark* aLandmark, QLookupItem& aLookupItem )
-{
-    __TRACE_CALLSTACK;// Read the category.
-
-    // fill geo-coordinates
-    TLocality position;
-    aLandmark->GetPosition( position );
-    aLookupItem.mLatitude = position.Latitude();
-    aLookupItem.mLongitude = position.Longitude();
-
-    TPtrC tempStr;
-    TInt retStatus;
-
-    // Copy landmark name in address 1
-    retStatus = aLandmark->GetLandmarkName( tempStr );
-    aLookupItem.mName = "";
-    if( retStatus == KErrNone && tempStr.Length() > 0 )
-    {
-        aLookupItem.mName = QString( (QChar*)tempStr.Ptr(), tempStr.Length() );
-    }
-
-    // get street
-    aLookupItem.mStreet = "";
-    retStatus = aLandmark->GetPositionField( EPositionFieldStreet, tempStr );
-    if( retStatus == KErrNone && tempStr.Length() )
-    {
-        aLookupItem.mStreet = QString( (QChar*)tempStr.Ptr(), tempStr.Length());
-    }
-
-    // get postal code
-    aLookupItem.mPostalCode = "";
-    retStatus = aLandmark->GetPositionField( EPositionFieldPostalCode, tempStr );
-    if( retStatus == KErrNone && tempStr.Length() )
-    {
-        aLookupItem.mPostalCode = QString( (QChar*)tempStr.Ptr(), tempStr.Length());
-    }
-
-    // get city
-    aLookupItem.mCity = "";
-    retStatus = aLandmark->GetPositionField( EPositionFieldCity, tempStr );
-    if( retStatus == KErrNone && tempStr.Length() )
-    {
-        aLookupItem.mCity = QString( (QChar*)tempStr.Ptr(), tempStr.Length());
-    }
-
-    // get State
-    aLookupItem.mState = "";
-    retStatus = aLandmark->GetPositionField( EPositionFieldState, tempStr );
-    if( retStatus == KErrNone && tempStr.Length() )
-    {
-        aLookupItem.mState = QString( (QChar*)tempStr.Ptr(), tempStr.Length());
-    }
-
-    // get country
-    aLookupItem.mCountry = "";
-    retStatus = aLandmark->GetPositionField( EPositionFieldCountry, tempStr );
-    if( retStatus == KErrNone && tempStr.Length() )
-    {
-        aLookupItem.mCountry = QString( (QChar*)tempStr.Ptr(), tempStr.Length());
-    }
-}
-
-// -----------------------------------------------------------------------------
-// CMyLocationsDatabaseManager::UnsetDuplicateNextCalEntry()
-// -----------------------------------------------------------------------------
-//
-void CMyLocationsDatabaseManager::UnsetDuplicateNextCalEntry( quint32 aLandmarkId )
-{
-    // get next duplicate item
-    QList<QLookupItem> itemArray;
-    iLocationAppLookupDb->findEntriesByLandmarkId( aLandmarkId, itemArray );
-    for ( int i = 0; i < itemArray.count(); i++)
-    {
-        if( itemArray[i].mSourceType == ESourceCalendar )
-        {
-            itemArray[i].mIsDuplicate = 0;
-            iLocationAppLookupDb->updateEntryById( itemArray[i] );
-            break;
-        }
-    }
-
-}
-// -----------------------------------------------------------------------------
-// CMyLocationsDatabaseManager::IsDuplicateEntry()
-// -----------------------------------------------------------------------------
-//
-bool CMyLocationsDatabaseManager::IsDuplicateEntry( quint32 aLandmarkId )
-{
-    // get next duplicate item
-    QList<QLookupItem> itemArray;
-    iLocationAppLookupDb->findEntriesByLandmarkId( aLandmarkId, itemArray );
-    for ( int i = 0; i < itemArray.count(); i++)
-    {
-        if( itemArray[i].mSourceType == ESourceCalendar ||
-            itemArray[i].mSourceType == ESourceLandmarks )
-        {
-            return true;
-        }
-    }
-    
-    return false;
-}
-
-// -----------------------------------------------------------------------------
-// CMyLocationsDatabaseManager::CreateLandmarkItemLC()
-// -----------------------------------------------------------------------------
-//
-CPosLandmark* CMyLocationsDatabaseManager::CreateLandmarkItemLC( const QLookupItem &aLookupItem )
-{
-    __TRACE_CALLSTACK;//return value
-    CPosLandmark *landmark = NULL;
-    TLocality loc( TCoordinate( aLookupItem.mLatitude, aLookupItem.mLongitude ), 0 );
-
-    landmark = CPosLandmark::NewL();
-    CleanupStack::PushL( landmark );
-
-    // Fill the location details into the landmark object
-    landmark->SetPositionL( loc );
-
-    // Set the landmark name as contact name
-    TBuf<KBufSize> text( aLookupItem.mName.utf16() );
-    TRAP_IGNORE( landmark->SetLandmarkNameL( text ) );
-
-    text.Copy( aLookupItem.mStreet.utf16() );
-    landmark->SetPositionFieldL( EPositionFieldStreet, text );
-    
-    // Set the City
-    text.Copy( aLookupItem.mCity.utf16() );
-    landmark->SetPositionFieldL( EPositionFieldCity, text );
-
-    // Set the state/region
-    text.Copy( aLookupItem.mState.utf16() );
-    landmark->SetPositionFieldL( EPositionFieldState, text );
-
-    // Set the Postal code
-    text.Copy( aLookupItem.mPostalCode.utf16() );
-    landmark->SetPositionFieldL( EPositionFieldPostalCode, text );
-
-    // Set the country
-    text.Copy( aLookupItem.mCountry.utf16() );
-    landmark->SetPositionFieldL( EPositionFieldCountry, text );
-
-    return landmark;
-}
-
-// -----------------------------------------------------------------------------
-// CMyLocationsDatabaseManager::UpdateMapTilePath()
-// -----------------------------------------------------------------------------
-//
-void CMyLocationsDatabaseManager::UpdateMapTilePath( TUint32 aSourceId, TUint32 aSourceType, 
-                                            TFileName aFilePath )
-{
-    QString filePath = QString( (QChar*)aFilePath.Ptr(), aFilePath.Length() );
-    iLocationAppLookupDb->updateMaptileBySourceIdAndType( aSourceId, aSourceType, filePath );
-}
-
-// End of file
--- a/locationdataharvester/mylocationsengine/src/mylocationsengine.cpp	Thu May 27 12:49:34 2010 +0300
+++ b/locationdataharvester/mylocationsengine/src/mylocationsengine.cpp	Fri Jun 11 13:33:47 2010 +0300
@@ -32,17 +32,12 @@
 //handle for CMyLocationsHistoryDbObserver class
 #include "mylocationlogger.h"
 #if ( defined __WINSCW__ ) || ( defined __WINS__ )
-_LIT ( KImageStorageDrive, "C:\\Maptile\\");
+_LIT ( KImageStorageDrive, "C:\\MapTile\\");
 #endif
 _LIT(KFolderName,":\\MapTile\\");
 const TInt KImagePathSize=36;
 const TInt KDefaultFilePathSize = 20;
 
-// separator
-_LIT( KSeparator, ",");
-_LIT(KPNGType, ".png");
-_LIT(KSingleSpace, " ");
-
 // ============================ MEMBER FUNCTIONS ===============================
 
 CMyLocationsEngine* CMyLocationsEngine::NewL()
@@ -88,6 +83,15 @@
     MYLOCLOGSTRING("Maptile Db instance created ");
     
     iAddressCompare = CAddressComparision::NewL();
+	
+    iMyLocationThreeAMTimer = CLocationGeoTagTimerAO::NewL(*this);
+  
+    iMyLocationThreeAMTimer->StartTimer();
+    
+    MYLOCLOGSTRING(" iMyLocationThreeAMTimer = CLocationGeoTagTimerAO::NewL(this)");
+  
+    //Create instance of contact manager 
+    iContactManager = new QContactManager();
 
     MYLOCLOGSTRING(" start contact db observation ");
     StartContactsChangeNotifierL();
@@ -96,12 +100,12 @@
     imageFilePath.Zero();
     SetFolderPathL();
 
-    TInt status;
+    TInt status = KErrNone;
     iCalSession = CCalSession::NewL();
     NotifyChangeL(status);
 
     // Start listening to landmarks db changes
-    StartLandmarksChangeNotifier();
+    StartLandmarksChangeNotifier();   
 
 }
 // -----------------------------------------------------------------------------
@@ -114,6 +118,7 @@
     __TRACE_CALLSTACK;
     RFs session;
     User::LeaveIfError(session.Connect());
+   
     if ( imageFilePath.Length() > 0 && BaflUtils::FolderExists(session, imageFilePath))
     {
         session.Close();
@@ -209,7 +214,9 @@
 			iLandmarkDb(NULL),
             iMapTileInterface(NULL), iMyLocationsDatabaseManager(NULL),
             iMaptileDatabase(NULL), iAddressCompare(NULL),
-            iMaptileGeocoderPluginAvailable(EFalse),iCalenderNotification(NULL)
+            iMyLocationThreeAMTimer(NULL),
+            iMaptileGeocoderPluginAvailable(EFalse),iCalenderNotification(NULL),
+            iContactManager(NULL)
 {
 
 }
@@ -243,6 +250,10 @@
     
     delete iCalenderNotification;
     
+	delete iMyLocationThreeAMTimer;
+		
+    delete iContactManager;
+    
 }
 
 // -----------------------------------------------------------------------------
@@ -387,8 +398,8 @@
             TLookupItem lookupItem;
             lookupItem.iSource = ESourceCalendar;
             lookupItem.iUid = calChangeEntry.iEntryId;
+            TRAP_IGNORE(ManipulateMapTileDataBaseL(lookupItem));
             //TODO: comapare address and then delete 
-            TRAP_IGNORE( iMaptileDatabase->DeleteEntryL(lookupItem) );
             TRAP_IGNORE( CalenderEntryAddedL(calChangeEntry) );
             break;
         }
@@ -397,9 +408,8 @@
             TLookupItem lookupItem;
             lookupItem.iSource = ESourceCalendar;
             lookupItem.iUid = calChangeEntry.iEntryId;
-           TRAP_IGNORE( iMaptileDatabase->DeleteEntryL(lookupItem));
-           
-           TRAP_IGNORE( UpdateDatabaseL( NULL, 
+            TRAP_IGNORE(ManipulateMapTileDataBaseL(lookupItem));           
+            TRAP_IGNORE( UpdateDatabaseL( NULL, 
                               calChangeEntry.iEntryId, ESourceCalendar, EEntryDeleted ) );
             break;
         }
@@ -420,6 +430,14 @@
     TPtrC address(calEntry->LocationL());
     if(address.Length()>0)
     {        
+    //create entry in the data base and maintain a fetching state.
+        TLookupItem lookupItem;
+        lookupItem.iUid = aCalChangeEntry.iEntryId;
+        lookupItem.iSource = ESourceCalendar;
+        lookupItem.iFilePath.Zero();
+        lookupItem.iFetchingStatus = EMapTileFetchingInProgress;
+        iMaptileDatabase->CreateEntryL(lookupItem);  
+        
         RequestMapTileImageL(address,ESourceCalendar, aCalChangeEntry.iEntryId);
     }
     delete calEntry;
@@ -456,82 +474,133 @@
     if (aEvent.iType == EContactDbObserverEventContactChanged || aEvent.iType
             == EContactDbObserverEventContactAdded)
     {
-        //Get the contact item
-        CContactItem* contactItem =
-                iContactsDb->ReadContactL(aEvent.iContactId);
-
-        if (contactItem)
+       
+        CPosLandmark *preferedAddressLm = NULL;
+        CPosLandmark *workAddressLm = NULL;
+        CPosLandmark *homeAddressLm = NULL;
+        
+        QContact contactInfo = iContactManager->contact( aEvent.iContactId );
+         
+        //Get the contact name details
+        QContactName name = contactInfo.detail( QContactName::DefinitionName );
+        QString firstName = name.firstName();
+        QString lastName = name.lastName();
+        TPtrC16 tempPtr1(reinterpret_cast<const TUint16*>(firstName.utf16()));
+        TPtrC16 tempPtr2( reinterpret_cast <const TUint16*>(lastName.utf16()));
+        
+        TBuf<KBufSize> landmarkName;
+        landmarkName.Append( tempPtr1 );
+        landmarkName.Append( tempPtr2 );
+        
+        TInt itemCount = 0;
+        
+  
+        double longitude, latitude;
+        
+        foreach ( QContactAddress address, contactInfo.details<QContactAddress>() )
         {
-            CleanupStack::PushL(contactItem);
+          QStringList context = address.contexts();
+          if ( context.isEmpty() ) // no context
+          {
+              //check whether geocordinate available
+              TBool geoField = IsGeoCoordinateAvailable( 
+                       contactInfo, NULL , latitude, longitude );
+              if( geoField )
+              {
+                  // Get the default/prefered address details
+                  preferedAddressLm = GetContactAddressDetailsLC( address );
+                  TLocality loc( TCoordinate( latitude, longitude ), 0 );
+                  // Fill the location details into the landmark object
+                  preferedAddressLm->SetPositionL(loc);
+                  preferedAddressLm->SetLandmarkNameL( landmarkName );
+                  itemCount++;
 
-            // Get the default/prefered address details
-            CPosLandmark *preferedAddressLm = GetContactLocationDetailsLC(
-                    contactItem, EAddressPref);
+              }
+          }
+          else if (context.first() == QContactAddress::ContextHome  )
+          {
+              //check whether geocordinate available
+              TBool geoField = IsGeoCoordinateAvailable( 
+                               contactInfo, QContactAddress::ContextHome, latitude, longitude );
+              if( geoField )
+              {
+                  // Get the home address details
+                  homeAddressLm = GetContactAddressDetailsLC( address );
+                  TLocality loc(TCoordinate( latitude,longitude ), 0);
+                  homeAddressLm->SetPositionL(loc);
+                  homeAddressLm->SetLandmarkNameL( landmarkName );
+                  itemCount++;
+              }
+          }
+          else if (context.first() == QContactAddress::ContextWork )
+          {
+              //check whether geocordinate available
+              TBool geoField = IsGeoCoordinateAvailable( 
+                        contactInfo, QContactAddress::ContextWork, latitude, longitude );
+              if( geoField )
+              {
+                  // Get the work address details
+                  workAddressLm = GetContactAddressDetailsLC( address );
+                  TLocality loc(TCoordinate( latitude, longitude ), 0);
+                  // Fill the location details into the landmark object
+                  workAddressLm->SetPositionL(loc);
+                  workAddressLm->SetLandmarkNameL( landmarkName );
+                  itemCount++;
+              }
+        
+          }
+        }
 
-            // Get the work address details
-            CPosLandmark *workAddressLm = GetContactLocationDetailsLC(
-                    contactItem, EAddressWork);
-
-            // Get the home address details
-            CPosLandmark *homeAddressLm = GetContactLocationDetailsLC(
-                    contactItem, EAddressHome);
-
-            // if the contact item has no validated address (preferef, home or work)
-            if (!preferedAddressLm && !workAddressLm && !homeAddressLm)
+        // if the contact item has no validated address (preferef, home or work)
+        if (!preferedAddressLm && !workAddressLm && !homeAddressLm)
+        {
+            if (aEvent.iType == EContactDbObserverEventContactChanged)
             {
-                if (aEvent.iType == EContactDbObserverEventContactChanged)
-                {
-                    // If the contact is a modified one and it might already exist in
-                    // mylocations db, so delete it
-                    UpdateDatabaseL(NULL,
-                            aEvent.iContactId, ESourceContactsPref,
-                            EEntryDeleted);
-                    UpdateDatabaseL(NULL,
-                            aEvent.iContactId, ESourceContactsWork,
-                            EEntryDeleted);
-                    UpdateDatabaseL(NULL,
-                            aEvent.iContactId, ESourceContactsHome,
-                            EEntryDeleted);
-                }
+                // If the contact is a modified one and it might already exist in
+                // mylocations db, so delete it
+                UpdateDatabaseL(NULL,
+                        aEvent.iContactId, ESourceContactsPref,
+                        EEntryDeleted);
+                UpdateDatabaseL(NULL,
+                        aEvent.iContactId, ESourceContactsWork,
+                        EEntryDeleted);
+                UpdateDatabaseL(NULL,
+                        aEvent.iContactId, ESourceContactsHome,
+                        EEntryDeleted);
             }
-            else
-            {
-                // There is atleast one valid address present.       
-
-                // Get the TEntryChangeType for contacts.
-                TEntryChangeType changeType = MapChangeType(
-                        ESourceContactsPref, aEvent.iType);
+        }
+        else
+        {
+            // There is atleast one valid address present.       
 
-                // if home address available, update Mylocations.  
-                if (homeAddressLm)
-                {
-                    UpdateDatabaseL(homeAddressLm,
-                            aEvent.iContactId, ESourceContactsHome, changeType);
-                    CleanupStack::PopAndDestroy(homeAddressLm);
-                }
+            // Get the TEntryChangeType for contacts.
+            TEntryChangeType changeType = MapChangeType(
+                    ESourceContactsPref, aEvent.iType);
 
-                // if work address available, update Mylocations.  
-                if (workAddressLm)
-                {
-                    UpdateDatabaseL(workAddressLm,
-                            aEvent.iContactId, ESourceContactsWork, changeType);
-                    CleanupStack::PopAndDestroy(workAddressLm);
-                }
+            // if home address available, update Mylocations.  
+            if (homeAddressLm)
+            {
+                UpdateDatabaseL(homeAddressLm,
+                        aEvent.iContactId, ESourceContactsHome, changeType);
+           }
 
-                // if prefered address available, update Mylocations.  
-                if (preferedAddressLm)
-                {
-                    UpdateDatabaseL(
-                            preferedAddressLm, aEvent.iContactId,
-                            ESourceContactsPref, changeType);
-                    CleanupStack::PopAndDestroy(preferedAddressLm);
-                }
-
+            // if work address available, update Mylocations.  
+            if (workAddressLm)
+            {
+                UpdateDatabaseL(workAddressLm,
+                        aEvent.iContactId, ESourceContactsWork, changeType);
             }
 
-            // Pop and destroy the contactItem
-            CleanupStack::PopAndDestroy(contactItem);
-        }
+            // if prefered address available, update Mylocations.  
+            if (preferedAddressLm)
+            {
+                UpdateDatabaseL(
+                        preferedAddressLm, aEvent.iContactId,
+                        ESourceContactsPref, changeType);
+           }
+            CleanupStack::PopAndDestroy( itemCount );
+        }  
+
     }
     else if (aEvent.iType == EContactDbObserverEventContactDeleted)
     {
@@ -553,215 +622,187 @@
 
 // -----------------------------------------------------------------------------
 // CMyLocationsEngine::TriggerMaptileRequestL()
-// Callback that provides information about the contact database change event.
+// Process the contact address information for fetching maptile.
 // -----------------------------------------------------------------------------
 //
-
 void CMyLocationsEngine::TriggerMaptileRequestL(TContactDbObserverEvent& aEvent)
 {
     __TRACE_CALLSTACK;
-    TLookupItem lookupItem;
+    TLookupItem lookupItem;      
     lookupItem.iUid = aEvent.iContactId;
     // If contact is deleted delete from mylocations db
-        if (aEvent.iType == EContactDbObserverEventContactDeleted)
-     {
+    if (aEvent.iType == EContactDbObserverEventContactDeleted)
+    {        
         lookupItem.iSource = ESourceContactsPref;
-        iMaptileDatabase->DeleteEntryL(lookupItem);
+        TRAP_IGNORE( ManipulateMapTileDataBaseL(lookupItem));
 
         lookupItem.iSource = ESourceContactsWork;
-        iMaptileDatabase->DeleteEntryL(lookupItem);
-
+        TRAP_IGNORE( ManipulateMapTileDataBaseL(lookupItem));
+        
         lookupItem.iSource = ESourceContactsHome;
-        iMaptileDatabase->DeleteEntryL(lookupItem);
-
+        TRAP_IGNORE( ManipulateMapTileDataBaseL(lookupItem));
+              
         MYLOCLOGSTRING("EContactDbObserverEventContactDeleted ");
         return;
-     }
+    }
 
     //Get the contact item
     iEventType = aEvent.iType;
-    CContactItem* contactItem = iContactsDb->ReadContactL(aEvent.iContactId);
-    CleanupStack::PushL(contactItem);
-
+    QContact contactInfo = iContactManager->contact( aEvent.iContactId );
+    
+  
     CPosLandmark *preferedAddressLm = NULL;
     CPosLandmark *workAddressLm = NULL;
     CPosLandmark *homeAddressLm = NULL;
-
-    // If contact is modified or added, update the mylocations db
-    /* if (contactItem)
-     {
-     CleanupStack::PushL(contactItem);
-     */
-    // Get the home address details
-    homeAddressLm = GetContactAddressDetailsLC(contactItem, EAddressHome);
-
-    // Get the work address details
-    workAddressLm = GetContactAddressDetailsLC(contactItem, EAddressWork);
-
-    // Get the default/prefered address details
-    preferedAddressLm = GetContactAddressDetailsLC(contactItem, EAddressPref);
-
-    // iContactUid = aEvent.iContactId;
+    
+    TInt itemCount = 0;
+    
+    foreach ( QContactAddress address, contactInfo.details<QContactAddress>() )
+    {
+        QStringList context = address.contexts();
+        if ( context.isEmpty() ) // no context
+        {
+            preferedAddressLm = GetContactAddressDetailsLC( address );
+            itemCount++;
+        }
+        else if ( context.first() == QContactAddress::ContextHome  )
+        {
+            homeAddressLm = GetContactAddressDetailsLC( address );
+            itemCount++;
+        }
+        else if ( context.first() == QContactAddress::ContextWork )
+        {
+            workAddressLm = GetContactAddressDetailsLC( address );
+            itemCount++;
+        }
+    }
+   
     switch (aEvent.iType)
     {
-    case EContactDbObserverEventContactChanged:
-    {
-        MYLOCLOGSTRING("EContactDbObserverEventContactChanged" );MYLOCLOGSTRING1("iMapTileRequestQueue.Count()-%d",iMapTileRequestQueue.Count() );
-
-        if (iMapTileRequestQueue.Count() > 0)
+        case EContactDbObserverEventContactChanged:
         {
-            if (iMapTileRequestQueue[0]->iUId == aEvent.iContactId)
+            MYLOCLOGSTRING("EContactDbObserverEventContactChanged" );
+            MYLOCLOGSTRING1("iMapTileRequestQueue.Count()-%d",iMapTileRequestQueue.Count() );
+
+            if (iMapTileRequestQueue.Count() > 0)
             {
-                if (preferedAddressLm)
+                if (iMapTileRequestQueue[0]->iUId == aEvent.iContactId)
                 {
-                    CleanupStack::PopAndDestroy(preferedAddressLm);
+                    CleanupStack::PopAndDestroy( itemCount );
+                    MYLOCLOGSTRING("retrun from geolocation callback" );
+                    return;
                 }
-                if (workAddressLm)
-                {
-                    CleanupStack::PopAndDestroy(workAddressLm);
-                }
-                if (homeAddressLm)
-                {
-                    CleanupStack::PopAndDestroy(homeAddressLm);
-                }
-
-                CleanupStack::PopAndDestroy(contactItem);
-                MYLOCLOGSTRING("retrun from geolocation callback" );
-                return;
             }
-        }
-        /*
-         // if the contact item has no validated address (preferef, home or work)
-         if (!preferedAddressLm && !workAddressLm && !homeAddressLm)
-         {
-         MYLOCLOGSTRING("Contact changed no  address" );
-         //Delete the entries from maptile lookup table
-         lookupItem.iSource = ESourceContactsPref;
-         iMaptileDatabase->DeleteEntryL(lookupItem);
-
-         lookupItem.iSource = ESourceContactsWork;
-         iMaptileDatabase->DeleteEntryL(lookupItem);
+       
+            // if default address available, update Mylocations. 
+            lookupItem.iSource = ESourceContactsPref;
+            if (preferedAddressLm)
+            {
+                MYLOCLOGSTRING("preferedAddressLm address changed" );
 
-         lookupItem.iSource = ESourceContactsHome;
-         iMaptileDatabase->DeleteEntryL(lookupItem);
-
-         }*/
-        /* else
-         {*/
-        MYLOCLOGSTRING("Contact address changed" );
-
-        // if default address available, update Mylocations. 
-        lookupItem.iSource = ESourceContactsPref;
-        if (preferedAddressLm)
-        {
-            MYLOCLOGSTRING("preferedAddressLm address changed" );
-
-            if (iAddressCompare->IsAddressChangedL(*preferedAddressLm,
+                if (iAddressCompare->IsAddressChangedL(*preferedAddressLm,
                     aEvent.iContactId, ESourceContactsPref))
 
+                {
+                    //remove entry from database
+                    TRAP_IGNORE( ManipulateMapTileDataBaseL(lookupItem));
+                    RequestMapTileImageL(*preferedAddressLm, ESourceContactsPref,
+                            aEvent.iContactId);
+                }
+            }
+            else
             {
+                TRAP_IGNORE( ManipulateMapTileDataBaseL(lookupItem));
+                
+            }  
+
+            // if work address available, update Mylocations.
+            lookupItem.iSource = ESourceContactsWork;
+            if (workAddressLm)
+            {
+                MYLOCLOGSTRING("workAddressLm address changed" );
+                if (iAddressCompare->IsAddressChangedL(*workAddressLm,
+                        aEvent.iContactId, ESourceContactsWork))
                 //remove entry from database
-                iMaptileDatabase->DeleteEntryL(lookupItem);
+                {
+                    
+                    TRAP_IGNORE( ManipulateMapTileDataBaseL(lookupItem));
+                    RequestMapTileImageL(*workAddressLm, ESourceContactsWork,
+                            aEvent.iContactId);
+                }
+            }
+            else
+            {
+                TRAP_IGNORE( ManipulateMapTileDataBaseL(lookupItem));
+               
+            }
+    
+            // if home address available, update Mylocations.
+            lookupItem.iSource = ESourceContactsHome;
+            if (homeAddressLm)
+            {
+                MYLOCLOGSTRING("homeAddressLm address changed" );
+    
+                if (iAddressCompare->IsAddressChangedL(*homeAddressLm,
+                        aEvent.iContactId, ESourceContactsHome))
+    
+                {
+                    //remove entry from databse                    
+                    TRAP_IGNORE( ManipulateMapTileDataBaseL(lookupItem));
+                    RequestMapTileImageL(*homeAddressLm, ESourceContactsHome,
+                            aEvent.iContactId);
+                }
+ 
+            }
+            else
+            {
+                TRAP_IGNORE( ManipulateMapTileDataBaseL(lookupItem));
+                
+            }
+            // }
+            break;
+        }    
+        case EContactDbObserverEventContactAdded:
+        {
+            MYLOCLOGSTRING("EContactDbObserverEventContactAdded" );
+            if (preferedAddressLm)
+            {
                 RequestMapTileImageL(*preferedAddressLm, ESourceContactsPref,
                         aEvent.iContactId);
             }
-
-            CleanupStack::PopAndDestroy(preferedAddressLm);
-
-        }
-        else
-        {
-            iMaptileDatabase->DeleteEntryL(lookupItem);
-        }
-
-        // if work address available, update Mylocations.
-        lookupItem.iSource = ESourceContactsWork;
-        if (workAddressLm)
-        {
-            MYLOCLOGSTRING("workAddressLm address changed" );
-            if (iAddressCompare->IsAddressChangedL(*workAddressLm,
-                    aEvent.iContactId, ESourceContactsWork))
-            //remove entry from database
+            if (workAddressLm)
             {
-                iMaptileDatabase->DeleteEntryL(lookupItem);
                 RequestMapTileImageL(*workAddressLm, ESourceContactsWork,
                         aEvent.iContactId);
             }
-
-            CleanupStack::PopAndDestroy(workAddressLm);
-
-        }
-        else
-        {
-            iMaptileDatabase->DeleteEntryL(lookupItem);
-        }
-
-        // if home address available, update Mylocations.
-        lookupItem.iSource = ESourceContactsHome;
-        if (homeAddressLm)
-        {
-            MYLOCLOGSTRING("homeAddressLm address changed" );
-
-            if (iAddressCompare->IsAddressChangedL(*homeAddressLm,
-                    aEvent.iContactId, ESourceContactsHome))
-
+            if (homeAddressLm)
             {
-                //remove entry from databse
-                iMaptileDatabase->DeleteEntryL(lookupItem);
                 RequestMapTileImageL(*homeAddressLm, ESourceContactsHome,
                         aEvent.iContactId);
             }
-            CleanupStack::PopAndDestroy(homeAddressLm);
-        }
-        else
-        {
-            iMaptileDatabase->DeleteEntryL(lookupItem);
-        }
-        // }
-        break;
-    }    
-    case EContactDbObserverEventContactAdded:
-    {
-        MYLOCLOGSTRING("EContactDbObserverEventContactAdded" );
-        if (preferedAddressLm)
-        {
-            RequestMapTileImageL(*preferedAddressLm, ESourceContactsPref,
-                    aEvent.iContactId);
-            CleanupStack::PopAndDestroy(preferedAddressLm);
+            break;
         }
-        if (workAddressLm)
-        {
-            RequestMapTileImageL(*workAddressLm, ESourceContactsWork,
-                    aEvent.iContactId);
-            CleanupStack::PopAndDestroy(workAddressLm);
-        }
-        if (homeAddressLm)
-        {
-            RequestMapTileImageL(*homeAddressLm, ESourceContactsHome,
-                    aEvent.iContactId);
-            CleanupStack::PopAndDestroy(homeAddressLm);
-        }
-        break;
+
     }
-
-    };
-    CleanupStack::PopAndDestroy(contactItem);
-    //}
+ 
+    CleanupStack::PopAndDestroy( itemCount );
 
 }
 
+
+// -----------------------------------------------------------------------------
+// CMyLocationsEngine::RequestMapTileImageL()
+// Request to get maptiel
+// -----------------------------------------------------------------------------
+//
 void CMyLocationsEngine::RequestMapTileImageL(const TDesC& aAddressDetails,
         const TUidSourceType aAddressType, const TInt32 aUId)
 {
     __TRACE_CALLSTACK;
     SetFolderPathL();
     TBuf<KImagePathSize> mImagePath;
-
-    //mImagePath.Append(KImageStorageDrive);
     mImagePath.Copy(imageFilePath);
-    mImagePath.AppendNum(aUId);
-    mImagePath.AppendNum(aAddressType);
-    mImagePath.Append(KPNGType);
+ 
 
     CMapTileRequest* mapTileRequest = new (ELeave) CMapTileRequest;
 
@@ -800,13 +841,7 @@
 
     MYLOCLOGSTRING("check folder path existance!");
     SetFolderPathL();
-    TBuf<KImagePathSize> mImagePath;
-
-    //mImagePath.Append(KImageStorageDrive);
-    mImagePath.Copy(imageFilePath);
-    mImagePath.AppendNum(aUId);
-    mImagePath.AppendNum(aAddressType);
-    mImagePath.Append(KPNGType);
+ 
 
     CMapTileRequest* mapTileRequest = new (ELeave) CMapTileRequest;
 
@@ -815,12 +850,12 @@
     mapTileRequest->iAddressType = aAddressType;
     mapTileRequest->iEventType = iEventType;
     mapTileRequest->iImagePath.Zero();
-    mapTileRequest->iImagePath.Copy(mImagePath);
+    mapTileRequest->iImagePath.Copy(imageFilePath);
     MYLOCLOGSTRING1("RequestMapTileImageL() Queue count -%d",iMapTileRequestQueue.Count());
 
     if (iMapTileRequestQueue.Count() <= 0)
        {
-          // iMapTileRequestQueue.Append(mapTileRequest);
+          
            if( KErrNone == RequestExecute(mapTileRequest) )
            {
                iMapTileRequestQueue.Append(mapTileRequest);
@@ -838,15 +873,22 @@
     
    
 }
+
+// -----------------------------------------------------------------------------
+// CMyLocationsEngine::RequestExecute()
+// Executes the maptile image processing request
+// -----------------------------------------------------------------------------
+//
 TInt CMyLocationsEngine::RequestExecute( CMapTileRequest* aMapTileRequest)
 {
     __TRACE_CALLSTACK;
     TInt errorCode = KErrNone;
+    MYLOCLOGSTRING1("Request address type - %d ",aMapTileRequest->iAddressType);
     switch (aMapTileRequest->iAddressType)
     {
         case ESourceCalendar:
         {
-            TRAP(errorCode,iMapTileInterface->GetMapTileImageL(aMapTileRequest->iAddressDetails->Des(),
+            TRAP(errorCode,iMapTileInterface->GetGeoCodeFromAddressL(*(aMapTileRequest->iAddressDetails),
                             aMapTileRequest->iImagePath, this ));        
             break;
         }
@@ -854,7 +896,7 @@
         case ESourceContactsWork:
         case ESourceContactsHome:
         {
-            TRAP(errorCode, iMapTileInterface->GetMapTileImageL(aMapTileRequest->iLandmarkInfo,
+            TRAP(errorCode, iMapTileInterface->GetGeoCodeFromAddressL(aMapTileRequest->iLandmarkInfo,
                             aMapTileRequest->iImagePath, this));            
             break;
         }
@@ -870,285 +912,43 @@
 // get locatin details
 // -----------------------------------------------------------------------------
 //
-CPosLandmark* CMyLocationsEngine::GetContactAddressDetailsLC(
-        const CContactItem *aContactItem, TContactAddressType aAddressType)
+CPosLandmark* CMyLocationsEngine::GetContactAddressDetailsLC( 
+                                   QContactAddress& aContactAddress )
 {
     __TRACE_CALLSTACK;
     CPosLandmark *landmark = NULL;
-
-    // Set the street
-    TInt adrId = FindContactsField(aContactItem, aAddressType,
-            KUidContactFieldVCardMapADR);
-
-    if (adrId != KErrNotFound)
-    {
-        TPtrC tempText =
-                aContactItem->CardFields()[adrId].TextStorage()->Text();
-        if (tempText.Length() > 0)
-        {
-            if (!landmark)
-            {
-                landmark = CPosLandmark::NewL();
-                CleanupStack::PushL(landmark);
-            }
-
-            landmark->SetPositionFieldL(EPositionFieldStreet, tempText);
-        }
-    }
-
-    // Set the City
-    adrId = FindContactsField(aContactItem, aAddressType,
-            KUidContactFieldVCardMapLOCALITY);
-    if (adrId != KErrNotFound)
+    
+    QString country = aContactAddress.country();
+    QString locality = aContactAddress.locality();
+    QString street = aContactAddress.street();
+    QString region = aContactAddress.region();
+    QString postalcode = aContactAddress.postcode();
+    
+    landmark = CPosLandmark::NewL();
+    CleanupStack::PushL(landmark);
+    
+    if ( !country.isEmpty() )
     {
-        TPtrC tempText =
-                aContactItem->CardFields()[adrId].TextStorage()->Text();
-        if (tempText.Length() > 0)
-        {
-            if (!landmark)
-            {
-                landmark = CPosLandmark::NewL();
-                CleanupStack::PushL(landmark);
-            }
-            landmark->SetPositionFieldL(EPositionFieldCity, tempText);
-        }
+        TPtrC16 tempText(reinterpret_cast<const TUint16*>(country.utf16()));
+        landmark->SetPositionFieldL( EPositionFieldCountry, tempText );
     }
-
-    // Set the state/region
-    adrId = FindContactsField(aContactItem, aAddressType,
-            KUidContactFieldVCardMapREGION);
-    if (adrId != KErrNotFound)
+    if ( !locality.isEmpty() )
     {
-        TPtrC tempText =
-                aContactItem->CardFields()[adrId].TextStorage()->Text();
-        if (tempText.Length() > 0)
-        {
-            if (!landmark)
-            {
-                landmark = CPosLandmark::NewL();
-                CleanupStack::PushL(landmark);
-            }
-            landmark->SetPositionFieldL(EPositionFieldState, tempText);
-        }
+        TPtrC16 tempText(reinterpret_cast<const TUint16*>(locality.utf16())); 
+        landmark->SetPositionFieldL(EPositionFieldCity, tempText);
     }
-
-    // Set the Postal code
-    adrId = FindContactsField(aContactItem, aAddressType,
-            KUidContactFieldVCardMapPOSTCODE);
-    if (adrId != KErrNotFound)
+    if ( !street.isEmpty() )
+    { 
+        TPtrC16 tempText(reinterpret_cast<const TUint16*>(street.utf16()));
+        landmark->SetPositionFieldL(EPositionFieldStreet, tempText);
+    }
+    if ( !postalcode.isEmpty() )
     {
-        TPtrC tempText =
-                aContactItem->CardFields()[adrId].TextStorage()->Text();
-        if (tempText.Length() > 0)
-        {
-            if (!landmark)
-            {
-                landmark = CPosLandmark::NewL();
-                CleanupStack::PushL(landmark);
-            }
-            landmark->SetPositionFieldL(EPositionFieldPostalCode, tempText);
-        }
+        TPtrC16 tempText(reinterpret_cast<const TUint16*>(postalcode.utf16()));
+        landmark->SetPositionFieldL(EPositionFieldPostalCode, tempText);
     }
 
-    // Set the country
-    adrId = FindContactsField(aContactItem, aAddressType,
-            KUidContactFieldVCardMapCOUNTRY);
-    if (adrId != KErrNotFound)
-    {
-        TPtrC tempText =
-                aContactItem->CardFields()[adrId].TextStorage()->Text();
-        if (tempText.Length() > 0)
-        {
-            if (!landmark)
-            {
-                landmark = CPosLandmark::NewL();
-                CleanupStack::PushL(landmark);
-            }
-            landmark->SetPositionFieldL(EPositionFieldCountry, tempText);
-        }
-    }
-       
-    return landmark;
-
-}
-
-// -----------------------------------------------------------------------------
-// CMyLocationsEngine::GetContactLocationDetailsLC()
-// Finds the contact's location details
-// -----------------------------------------------------------------------------
-//
-CPosLandmark* CMyLocationsEngine::GetContactLocationDetailsLC(
-        const CContactItem *aContactItem, TContactAddressType aAddressType)
-{
-    __TRACE_CALLSTACK;//return value
-    CPosLandmark *landmark = NULL;
-    // Get the geo field
-    TInt addrInd = FindContactsField(aContactItem, aAddressType,
-            KUidContactFieldVCardMapGEO);
-    if (addrInd != KErrNotFound)
-    {
-        // Geo field present. 
-
-        TPtrC addrText =
-                aContactItem->CardFields()[addrInd].TextStorage()->Text();
-        if (addrText.Length() > 0)
-        {
-            //Parse the addresstext to get the latitude and longitude
-            TInt separator = addrText.Find(KSeparator);
-            if (separator != KErrNotFound)
-            {
-                TReal64 latitude = 0;
-                TReal64 longitude = 0;
-                TLex lexLatitude(addrText.Left(addrText.Length() - separator));
-                TLex lexLongitude(addrText.Right(addrText.Length() - separator
-                        - 1));
-                if (lexLatitude.Val(latitude) == KErrNone && lexLongitude.Val(
-                        longitude) == KErrNone)
-                {
-                    TLocality loc(TCoordinate(latitude, longitude), 0);
-
-                    landmark = CPosLandmark::NewL();
-                    CleanupStack::PushL(landmark);
-
-                    // Fill the location details into the landmark object
-                    landmark->SetPositionL(loc);
-
-                    // Set the landmark name as contact name
-                    TBuf<KBufSize> sName1;
-                    TBool nameEmpty = ETrue;
-                    //get the second name and
-                    TInt sNameInd = aContactItem->CardFields().Find(
-                            KUidContactFieldGivenName);
-                    if (sNameInd != KErrNotFound)
-                    {
-                        TPtrC      sName =
-                                        aContactItem->CardFields()[sNameInd].TextStorage()->Text();
-                        sName1.Copy(sName);
-                        nameEmpty = EFalse;
-                    }
-
-                    sNameInd = aContactItem->CardFields().Find(
-                            KUidContactFieldFamilyName);
-                    if (sNameInd != KErrNotFound)
-                    {
-                        if (!nameEmpty)
-                        {
-                            sName1.Append(KSingleSpace);
-                        }
-                        TPtrC
-                                sName =
-                                        aContactItem->CardFields()[sNameInd].TextStorage()->Text();
-                        sName1.Append(sName);
-                    }
-
-                    TRAP_IGNORE( landmark->SetLandmarkNameL( sName1 ) );
-
-                    // Set the street
-                    TInt adrId = FindContactsField(aContactItem, aAddressType,
-                            KUidContactFieldVCardMapADR);
-                    if (adrId != KErrNotFound)
-                    {
-                        TPtrC
-                                tempText =
-                                        aContactItem->CardFields()[adrId].TextStorage()->Text();
-                        if (tempText.Length() > 0)
-                        {
-                            landmark->SetPositionFieldL(EPositionFieldStreet,
-                                    tempText);
-                        }
-                    }
-
-                    // Set the City
-                    adrId = FindContactsField(aContactItem, aAddressType,
-                            KUidContactFieldVCardMapLOCALITY);
-                    if (adrId != KErrNotFound)
-                    {
-                        TPtrC
-                                tempText =
-                                        aContactItem->CardFields()[adrId].TextStorage()->Text();
-                        if (tempText.Length() > 0)
-                        {
-                            landmark->SetPositionFieldL(EPositionFieldCity,
-                                    tempText);
-                        }
-                    }
-
-                    // Set the state/region
-                    adrId = FindContactsField(aContactItem, aAddressType,
-                            KUidContactFieldVCardMapREGION);
-                    if (adrId != KErrNotFound)
-                    {
-                        TPtrC
-                                tempText =
-                                        aContactItem->CardFields()[adrId].TextStorage()->Text();
-                        if (tempText.Length() > 0)
-                        {
-                            landmark->SetPositionFieldL(EPositionFieldState,
-                                    tempText);
-                        }
-                    }
-
-                    // Set the Postal code
-                    adrId = FindContactsField(aContactItem, aAddressType,
-                            KUidContactFieldVCardMapPOSTCODE);
-                    if (adrId != KErrNotFound)
-                    {
-                        TPtrC
-                                tempText =
-                                        aContactItem->CardFields()[adrId].TextStorage()->Text();
-                        if (tempText.Length() > 0)
-                        {
-                            landmark->SetPositionFieldL(
-                                    EPositionFieldPostalCode, tempText);
-                        }
-                    }
-
-                    // Set the country
-                    adrId = FindContactsField(aContactItem, aAddressType,
-                            KUidContactFieldVCardMapCOUNTRY);
-                    if (adrId != KErrNotFound)
-                    {
-                        TPtrC
-                                tempText =
-                                        aContactItem->CardFields()[adrId].TextStorage()->Text();
-                        if (tempText.Length() > 0)
-                        {
-                            landmark->SetPositionFieldL(EPositionFieldCountry,
-                                    tempText);
-                        }
-                    }
-                }
-            }
-        }
-    }
-
-    return landmark;
-}
-
-// -----------------------------------------------------------------------------
-// CMyLocationsEngine::FindContactsField()
-// Finds the contact's field type id
-// -----------------------------------------------------------------------------
-//
-
-TInt CMyLocationsEngine::FindContactsField(const CContactItem *aContactItem,
-        TContactAddressType aAddressType, TUid aField)
-{
-    __TRACE_CALLSTACK;
-    if (aAddressType == EAddressPref) // default/prefered address
-    {
-        return aContactItem->CardFields().Find(aField);
-    }
-    else if (aAddressType == EAddressWork) // work address
-    {
-        return aContactItem->CardFields().Find(KUidContactFieldVCardMapWORK,
-                aField);
-    }
-    else // home address
-    {
-        return aContactItem->CardFields().Find(KUidContactFieldVCardMapHOME,
-                aField);
-    }
+     return landmark;
 }
 
 // -----------------------------------------------------------------------------
@@ -1232,6 +1032,51 @@
     return retVal;
 }
 
+
+// -----------------------------------------------------------------------------
+// CMyLocationsEngine::IsGeoCoordinateAvailable()
+// Checks whether geocoordinate available in the contact detail.
+// -----------------------------------------------------------------------------
+//
+TBool CMyLocationsEngine::IsGeoCoordinateAvailable( QContact& aContact, 
+        QString aAddressType, double& aLatitude , double& aLongitude )
+
+{
+      TBool geoFieldAvailable = EFalse;
+      QContactGeoLocation geoLocation;
+      
+      foreach( geoLocation, aContact.details<QContactGeoLocation>() )
+      {
+          if( !geoLocation.isEmpty())
+          {
+              QStringList context = geoLocation.contexts();
+              if ( context.isEmpty() )
+              {
+                  if ( aAddressType.isEmpty() )
+                  {
+                      geoFieldAvailable = ETrue;
+                      break;
+                  }
+              }
+              else if( context.first() == aAddressType )
+              {
+                  geoFieldAvailable = ETrue;
+                  break;
+              }
+              
+          }
+          
+      }
+      if( geoFieldAvailable )
+      {
+          aLatitude = geoLocation.latitude();
+          aLongitude = geoLocation.longitude();
+      }
+      return geoFieldAvailable;
+}
+
+
+
 // -----------------------------------------------------------------------------
 // CMyLocationsEngine::RunL()
 // Handles active object's request completion event.
@@ -1285,6 +1130,148 @@
 }
 
 // -----------------------------------------------------------------------------
+// CMyLocationsEngine::GeoCodefetchingCompleted()
+// Handles the maptile fetching completion event and updates the maptile lookup db.
+// -----------------------------------------------------------------------------
+//
+void CMyLocationsEngine::GeoCodefetchingCompleted( TInt aErrCode, const TReal& aLatitude,
+            const TReal& aLongitude, const TDesC& aMapTilePath )
+{
+    __TRACE_CALLSTACK;
+    MYLOCLOGSTRING1("MapTilefetchingCompleted aErrCode - %d ",aErrCode);
+    MYLOCLOGSTRING1("iMapTileRequestQueue.Count - %d",iMapTileRequestQueue.Count());
+
+    if (iMapTileRequestQueue.Count() > 0)
+    {
+        MYLOCLOGSTRING1("No.of RequestQueue - %d",iMapTileRequestQueue.Count());
+       
+	    TLookupItem lookupItem;
+        lookupItem.iSource = iMapTileRequestQueue[0]->iAddressType;
+        lookupItem.iUid = iMapTileRequestQueue[0]->iUId;
+
+        if (aErrCode == KErrNone)
+        {
+            UpdateGeoCodeToAppDataBase( aLatitude, aLongitude );
+            
+            TBool flag = EFalse;
+            TRAP_IGNORE( flag = iMaptileDatabase->FindEntryByFilePathL(aMapTilePath) );
+            if ( flag )
+            {  
+                MYLOCLOGSTRING1("%S - found in the DB",&aMapTilePath);
+            
+             				
+                lookupItem.iFilePath.Copy(aMapTilePath);
+                lookupItem.iFetchingStatus = EMapTileFectchingCompleted;
+                TRAP_IGNORE( UpdateMaptileDatabaseL(iMapTileRequestQueue[0]->iEventType, lookupItem ) );              
+
+                MYLOCLOGSTRING("UpdateMaptileDatabaseL handled");
+
+                //Process the pending maptile requests
+                ProcessNextMaptileRequest();
+                
+            }
+            else
+            {
+                TRAPD( error, iMapTileInterface->GetMapTileL( aLatitude, aLongitude ) );
+                if ( error != KErrNone )
+                {
+                    //Log error message
+                     MYLOCLOGSTRING1("iMapTileInterface->GetMapTileL() status-%d",error);
+                     MapTilefetchingCompleted(error, KNullDesC);
+                }            
+            }            
+        }
+        else
+        {
+		   if ( aErrCode == KErrCouldNotConnect )
+		   {
+		       lookupItem.iFetchingStatus = EMapTileFetchingNetworkError;
+               iMyLocationThreeAMTimer->StartTimer();
+              
+		   }
+		   else
+		   {
+		       lookupItem.iFetchingStatus = EMapTileFetchingUnknownError;
+		   }
+           TRAP_IGNORE( UpdateMaptileDatabaseL(iMapTileRequestQueue[0]->iEventType,lookupItem ) );
+           
+		   ProcessNextMaptileRequest();
+        }
+    }    
+}
+
+void CMyLocationsEngine::MyLocationThreeAMTimerExpiredL()
+{
+    //Forward the event for maptile fetching only if maptile plugin available
+    if( iMaptileGeocoderPluginAvailable )
+    {
+        RArray<TLookupItem> iLookupItems;
+        iMaptileDatabase->FindEntriesByMapTileFetchingStateL((TUint32)EMapTileFetchingNetworkError,
+                                            iLookupItems);
+        for( TUint32 i = 0; i < iLookupItems.Count(); i++ )
+        {
+            TLookupItem iItem = iLookupItems[i];
+            switch( iItem.iSource )
+            {
+                // Get the home address details
+                case ESourceContactsHome:
+                case ESourceContactsWork:
+                case ESourceContactsPref:
+                     { 
+                        QContact contactInfo = iContactManager->contact( iItem.iUid );
+                        CPosLandmark *addressLm = NULL;
+    
+                        foreach ( QContactAddress address, contactInfo.details<QContactAddress>() )
+                        {
+                            QStringList context = address.contexts();
+                            if ( ( context.isEmpty() && iItem.iSource == ESourceContactsPref ) ||
+                                   ( context.first() == QContactAddress::ContextHome  && iItem.iSource == ESourceContactsHome ) ||
+                                   ( context.first() == QContactAddress::ContextWork  && iItem.iSource == ESourceContactsWork ) ) 
+                            {
+                                // Get the default/prefered address details
+                                addressLm = GetContactAddressDetailsLC( address );
+                                if( addressLm ) 
+                                {
+                                    RequestMapTileImageL( *addressLm,
+                                           ( TUidSourceType )iItem.iSource, iItem.iUid );
+                                    CleanupStack::PopAndDestroy( addressLm );
+                                    break;
+                                }
+                            }
+                        }                    
+                     }
+                     break;
+                
+                case ESourceCalendar:
+                     {
+                        CCalEntry* calEntry = NULL;
+                        calEntry = iCalView->FetchL(iItem.iUid);
+                        if( calEntry )
+                        {
+                            CleanupStack::PushL(calEntry);
+                            TPtrC address(calEntry->LocationL());
+                            if(address.Length()>0)
+                            {        
+                                RequestMapTileImageL( address, ESourceCalendar, iItem.iUid);
+                            }
+                            CleanupStack::PopAndDestroy(calEntry);
+                        }
+                        else
+                        {
+                            iMaptileDatabase->DeleteEntryL( iItem );
+                        }
+                     }
+                     break;
+                 
+                 default:
+                     break;
+              }
+         }// end for
+     }
+}
+
+
+// -----------------------------------------------------------------------------
 // CMyLocationsEngine::MapTilefetchingCompleted()
 // Handles the maptile fetching completion event and updates the maptile lookup db.
 // -----------------------------------------------------------------------------
@@ -1296,62 +1283,89 @@
     MYLOCLOGSTRING1("MapTilefetchingCompleted aErrCode - %d ",aErrCode);
     MYLOCLOGSTRING1("iMapTileRequestQueue.Count - %d",iMapTileRequestQueue.Count());
 
-    if (iMapTileRequestQueue.Count() > 0)
+    if ( iMapTileRequestQueue.Count() > 0 )
     {
 
         MYLOCLOGSTRING1("No.of RequestQueue - %d",iMapTileRequestQueue.Count());
 
-        if (aErrCode == KErrNone )
+        TLookupItem lookupItem;
+        lookupItem.iSource = iMapTileRequestQueue[0]->iAddressType;
+        lookupItem.iUid = iMapTileRequestQueue[0]->iUId;
+
+        if ( aErrCode == KErrNone )
         {           
-            TLookupItem lookupItem;
-            lookupItem.iSource = iMapTileRequestQueue[0]->iAddressType;
-            lookupItem.iUid = iMapTileRequestQueue[0]->iUId;
             lookupItem.iFilePath.Copy(aMapTilePath);
-            TRAP_IGNORE( HandleMaptileDatabaseL(iMapTileRequestQueue[0]->iEventType,lookupItem ) );
+   		    lookupItem.iFetchingStatus = EMapTileFectchingCompleted;
+ 
         }
-
-            delete iMapTileRequestQueue[0];
-            iMapTileRequestQueue.Remove(0);
-            iMapTileRequestQueue.Compress();
+        else if ( aErrCode == KErrCouldNotConnect )
+		{
+		    lookupItem.iFetchingStatus = EMapTileFetchingNetworkError;
+            iMyLocationThreeAMTimer->StartTimer();
+              
+		}
+		else
+		{
+		    lookupItem.iFetchingStatus = EMapTileFetchingUnknownError;
+		}
+		
+        TRAP_IGNORE( UpdateMaptileDatabaseL(iMapTileRequestQueue[0]->iEventType,lookupItem ) );
     }
     
+    ProcessNextMaptileRequest();
+}
+
+
+// -----------------------------------------------------------------------------
+// CMyLocationsEngine::ProcessNextMaptileRequest()
+// Process the next maptile request if any pending.
+// -----------------------------------------------------------------------------
+//
+void CMyLocationsEngine::ProcessNextMaptileRequest()
+{
+    //Process the next request if it is pending
+    if ( iMapTileRequestQueue.Count() > 0)
+    {
+        //Remove the current top request 
+        delete iMapTileRequestQueue[0];
+        iMapTileRequestQueue.Remove(0);
+        iMapTileRequestQueue.Compress();
     
-    //Process the next request
-    if (iMapTileRequestQueue.Count() > 0)
-    {
+        //Process the next request in queue
         MYLOCLOGSTRING1("MapTile fetch completed request-%d",iMapTileRequestQueue.Count());
         for (TInt cnt = 0; cnt < iMapTileRequestQueue.Count(); cnt++)
         {          
-            if ( KErrNone == RequestExecute(iMapTileRequestQueue[0]) )
+            if ( KErrNone == RequestExecute( iMapTileRequestQueue[0]) )
             {
-                break;
+                   break;
             }
             else
             {
-                delete iMapTileRequestQueue[0];
-                iMapTileRequestQueue.Remove(0);
-                iMapTileRequestQueue.Compress();
+               //Process the next request in queue
+               ProcessNextMaptileRequest();
+
             }
         }
     }
     else
     {
-        MYLOCLOGSTRING("MapTile fetch completed no request in queue");
-        iMapTileRequestQueue.Reset();
-    }
+       MYLOCLOGSTRING("MapTile fetch completed no request in queue");
+           iMapTileRequestQueue.Reset();
+    }    
+}
 
-}
 // -----------------------------------------------------------------------------
 // CMyLocationsEngine::HandleMaptileDatabaseL()
 // Handle maptile database(find/create/update/delete).
 // -----------------------------------------------------------------------------
 //
-void CMyLocationsEngine::HandleMaptileDatabaseL(
+void CMyLocationsEngine::UpdateMaptileDatabaseL(
         TInt aEventType, TLookupItem& aLookupItem)
 {
     __TRACE_CALLSTACK;
     if (aEventType == EContactDbObserverEventContactChanged || aEventType
-            == EChangeModify)
+            == EChangeModify || aEventType == EContactDbObserverEventContactAdded ||
+            aEventType == EChangeAdd )
     {
         if (iMaptileDatabase->FindEntryL(aLookupItem))
         {
@@ -1362,12 +1376,6 @@
             iMaptileDatabase->CreateEntryL(aLookupItem);
         }
     }
-    else if (aEventType == EContactDbObserverEventContactAdded || aEventType
-            == EChangeAdd)
-    {
-        iMaptileDatabase->CreateEntryL(aLookupItem);
-
-    }
     iMyLocationsDatabaseManager->UpdateMapTilePath( aLookupItem.iUid, aLookupItem.iSource, 
                                             aLookupItem.iFilePath );    
 }
@@ -1378,7 +1386,7 @@
 // started lat and lon field updation into contact db.
 // -----------------------------------------------------------------------------
 //
-void CMyLocationsEngine::RestGeoCodeCompleted(TReal aLatitude, TReal aLongitude)
+void CMyLocationsEngine::UpdateGeoCodeToAppDataBase( TReal aLatitude, TReal aLongitude )
 {
     __TRACE_CALLSTACK;
 
@@ -1435,5 +1443,21 @@
     
 }
 
+// -----------------------------------------------------------------------------
+// CMyLocationsEngine::ManipulateMapTileDataBaseL()
+// -----------------------------------------------------------------------------
+//
+void CMyLocationsEngine::ManipulateMapTileDataBaseL(TLookupItem aLookupItem)
+{
+    __TRACE_CALLSTACK;
+    TBool entryAvailable=EFalse;
+    entryAvailable = iMaptileDatabase->FindEntryL(aLookupItem);
+    iMaptileDatabase->DeleteEntryL(aLookupItem);
+    if (entryAvailable)
+    {
+        iMaptileDatabase->DeleteMapTileL(aLookupItem);
+    }
+            
+}
 //End of file
 
--- a/locationdataharvester/mylocationsengine/src/mylocationslookupdb.cpp	Thu May 27 12:49:34 2010 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,410 +0,0 @@
-/*
-* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
-* All rights reserved.
-* This component and the accompanying materials are made available
-* under the terms of "Eclipse Public License v1.0"
-* which accompanies this distribution, and is available
-* at the URL "http://www.eclipse.org/legal/epl-v10.html".
-*
-* Initial Contributors:
-* Nokia Corporation - initial contribution.
-*
-* Contributors:
-*
-* Description: Mylocation database lookup table implementation.
-*
-*/
-
-#include <bautils.h>
-#include <EPos_CPosLmCategoryManager.h>
-#include "mylocationslookupdb.h"
-#include "mylocationlogger.h"
-// select all from
-_LIT( KSelectAllFrom, "SELECT * FROM " );
-// string 'where'
-_LIT( KStringWhere, " WHERE " );
-// string ' = '
-_LIT( KStringEqual, " = " );
-// string 'And'
-_LIT( KStringAnd, " AND " );
-
-// -----------------------------------------------------------------------------
-// CLookupDatabase::CLookupDatabase()
-// Default constructor.
-// -----------------------------------------------------------------------------
-//
-CLookupDatabase::CLookupDatabase()
-{
-}
-
-// -----------------------------------------------------------------------------
-// CLookupDatabase::~CLookupDatabase()
-// Destructor.
-// -----------------------------------------------------------------------------
-//
-CLookupDatabase::~CLookupDatabase()
-{
-    __TRACE_CALLSTACK;// close the database
-    iItemsDatabase.Close();
-    // close the file session
-    iFsSession.Close();
-}
-
-// -----------------------------------------------------------------------------
-// CLookupDatabase::~CLookupDatabase()
-// Creates an object of this class and pushes to cleanup stack.
-// -----------------------------------------------------------------------------
-//
-CLookupDatabase* CLookupDatabase::NewLC(const TDesC& aLookupTableName)
-{
-    CLookupDatabase* self = new (ELeave) CLookupDatabase;
-    CleanupStack::PushL(self);
-    self->ConstructL(aLookupTableName);
-    return self;
-}
-
-// -----------------------------------------------------------------------------
-// CLookupDatabase::NewL()
-// Creates an object of this class.
-// -----------------------------------------------------------------------------
-//
-CLookupDatabase* CLookupDatabase::NewL(const TDesC& aLookupTableName)
-{
-    CLookupDatabase* self = CLookupDatabase::NewLC(aLookupTableName);
-    CleanupStack::Pop(self);
-    return self;
-}
-
-// -----------------------------------------------------------------------------
-// CLookupDatabase::ConstructL()
-// 2nd phase contructor.
-// -----------------------------------------------------------------------------
-//
-void CLookupDatabase::ConstructL(const TDesC& aLookupTableName)
-{
-    __TRACE_CALLSTACK;
-    User::LeaveIfError(iFsSession.Connect());
-
-    //create private path
-    User::LeaveIfError(iFsSession.CreatePrivatePath(RFs::GetSystemDrive()));
-    // private path with no drive on it
-    iFsSession.PrivatePath(iDbFileName);
-
-    TFindFile PrivFolder(iFsSession);
-    // find out the drive
-    if (KErrNone == PrivFolder.FindByDir(iDbFileName, KNullDesC))
-    {
-        iFsSession.MkDir(KLookupDbPath);
-        iDbFileName.Copy(KLookupDbPath);
-        iDbFileName.Append(aLookupTableName);
-
-        if (!BaflUtils::FileExists(iFsSession, iDbFileName))
-        { // no database exists so we make one
-            User::LeaveIfError(iItemsDatabase.Create(iFsSession, iDbFileName));
-            // and will create the only table needed for it
-            CreateTableL(iItemsDatabase);
-
-            //close the database
-            iItemsDatabase.Close();
-        }
-    }
-}
-
-// -----------------------------------------------------------------------------
-// CLookupDatabase::Open()
-// Opens the lookup database.
-// -----------------------------------------------------------------------------
-//
-TInt CLookupDatabase::Open()
-{
-    __TRACE_CALLSTACK;
-    return iItemsDatabase.Open(iFsSession, iDbFileName);
-}
-
-// -----------------------------------------------------------------------------
-// CLookupDatabase::Close()
-// Closes the lookup database.
-// -----------------------------------------------------------------------------
-//
-void CLookupDatabase::Close()
-{
-    __TRACE_CALLSTACK;
-    iItemsDatabase.Close();
-}
-
-// -----------------------------------------------------------------------------
-// CLookupDatabase::CreateTableL()
-// Creates a lookup table.
-// -----------------------------------------------------------------------------
-//
-void CLookupDatabase::CreateTableL(RDbDatabase& aDatabase)
-{
-    __TRACE_CALLSTACK;// Create a table definition
-    CDbColSet* columns = CDbColSet::NewLC();
-
-    // Add Columns
-
-    // Add uid column
-    columns->AddL(TDbCol(NColUid, EDbColUint32));
-
-    // add source type column
-    columns->AddL(TDbCol(NColSource, EDbColUint32));
-
-    // add landmark uid column
-    columns->AddL(TDbCol(NColLmUid, EDbColUint32));
-
-    // Create a table
-    User::LeaveIfError(aDatabase.CreateTable(KLookupTable, *columns));
-
-    // cleanup the column set
-    CleanupStack::PopAndDestroy(columns);
-}
-
-
-// -----------------------------------------------------------------------------
-// CLookupDatabase::CreateEntryL()
-// Creates an entry in the lookup table.
-// -----------------------------------------------------------------------------
-//
-void CLookupDatabase::CreateEntryL(const TLookupItem& aLookupItem)
-{
-    __TRACE_CALLSTACK;// create a query for the view
-    TFileName queryBuffer;
-    queryBuffer.Copy(KSelectAllFrom);
-    queryBuffer.Append(KLookupTable);
-
-    iItemsDatabase.Begin();
-
-    RDbView myView;
-    myView.Prepare(iItemsDatabase, TDbQuery(queryBuffer));
-    CleanupClosePushL(myView);
-
-    // Inert the item
-    myView.InsertL();
-
-    // set the fields
-    myView.SetColL(KColumnUid, aLookupItem.iUid);
-    myView.SetColL(KColumnSource, aLookupItem.iSource);
-    myView.SetColL(KColumnLmkUid, aLookupItem.iLmId);
-
-    myView.PutL();
-
-    CleanupStack::PopAndDestroy(&myView); // myView
-    iItemsDatabase.Commit();
-}
-
-// -----------------------------------------------------------------------------
-// CLookupDatabase::UpdateEntryL()
-// Updates an entry in the lookup table.
-// -----------------------------------------------------------------------------
-//
-void CLookupDatabase::UpdateEntryL(const TLookupItem& aLookupItem)
-{
-    __TRACE_CALLSTACK;// Create the query to find the row to be updated.
-    TFileName queryBuffer;
-    queryBuffer.Copy(KSelectAllFrom);
-    queryBuffer.Append(KLookupTable);
-    queryBuffer.Append(KStringWhere);
-    queryBuffer.Append(NColUid);
-    queryBuffer.Append(KStringEqual);
-    queryBuffer.AppendNum(aLookupItem.iUid);
-    queryBuffer.Append(KStringAnd);
-    queryBuffer.Append(NColSource);
-    queryBuffer.Append(KStringEqual);
-    queryBuffer.AppendNum(aLookupItem.iSource);
-
-    iItemsDatabase.Begin();
-
-    // Create a view of the table based on the query created.
-    RDbView myView;
-    myView.Prepare(iItemsDatabase, TDbQuery(queryBuffer));
-    CleanupClosePushL(myView);
-
-    myView.EvaluateAll();
-    myView.FirstL();
-
-    if (myView.AtRow())
-    {
-        // found the entry. update it.
-        myView.UpdateL();
-        myView.SetColL(KColumnLmkUid, aLookupItem.iLmId);
-        myView.PutL();
-    }
-
-    CleanupStack::PopAndDestroy(&myView); // myView
-    iItemsDatabase.Commit();
-
-}
-
-// -----------------------------------------------------------------------------
-// CLookupDatabase::DeleteEntryL()
-// Deletes an entry from the lookup table.
-// -----------------------------------------------------------------------------
-//
-void CLookupDatabase::DeleteEntryL(const TLookupItem& aLookupItem)
-{
-    __TRACE_CALLSTACK;// Create the query to find the row to be deleted.
-    TFileName queryBuffer;
-    queryBuffer.Copy(KSelectAllFrom);
-    queryBuffer.Append(KLookupTable);
-    queryBuffer.Append(KStringWhere);
-    queryBuffer.Append(NColUid);
-    queryBuffer.Append(KStringEqual);
-    queryBuffer.AppendNum(aLookupItem.iUid);
-    queryBuffer.Append(KStringAnd);
-    queryBuffer.Append(NColSource);
-    queryBuffer.Append(KStringEqual);
-    queryBuffer.AppendNum(aLookupItem.iSource);
-
-    iItemsDatabase.Begin();
-
-    RDbView myView;
-    // query buffer finds only the selected item row.
-    myView.Prepare(iItemsDatabase, TDbQuery(queryBuffer));
-    CleanupClosePushL(myView);
-
-    myView.EvaluateAll();
-
-    // positions the cursor on the first row of the rowset
-    myView.FirstL();
-
-    // Delete the entry found.
-    if (myView.AtRow())
-    {
-        myView.GetL();
-        myView.DeleteL();
-    }
-
-    CleanupStack::PopAndDestroy(&myView); // myView
-    iItemsDatabase.Commit();
-    // compacts the databse, by physicaly removing deleted data.
-    iItemsDatabase.Compact();
-}
-
-// -----------------------------------------------------------------------------
-// CLookupDatabase::FindEntryL()
-// Finds an entry in the lookup table.
-// -----------------------------------------------------------------------------
-//
-TBool CLookupDatabase::FindEntryL(TLookupItem& aLookupItem)
-{
-    __TRACE_CALLSTACK;// used to store return value
-    TBool retVal = EFalse;
-
-    // Create a query to find the item.
-    TFileName queryBuffer;
-    queryBuffer.Copy(KSelectAllFrom);
-    queryBuffer.Append(KLookupTable);
-    queryBuffer.Append(KStringWhere);
-    queryBuffer.Append(NColUid);
-    queryBuffer.Append(KStringEqual);
-    queryBuffer.AppendNum(aLookupItem.iUid);
-    queryBuffer.Append(KStringAnd);
-    queryBuffer.Append(NColSource);
-    queryBuffer.Append(KStringEqual);
-    queryBuffer.AppendNum(aLookupItem.iSource);
-
-    // Create a view of the table with the above query.
-    RDbView myView;
-    myView.Prepare(iItemsDatabase, TDbQuery(queryBuffer));
-    CleanupClosePushL(myView);
-    myView.EvaluateAll();
-    myView.FirstL();
-
-    if (myView.AtRow())
-    {
-        // Item found. get the details.
-        myView.GetL();
-
-        aLookupItem.iUid = myView.ColUint(KColumnUid);
-        aLookupItem.iSource = myView.ColUint(KColumnSource);
-        aLookupItem.iLmId = myView.ColUint(KColumnLmkUid);
-        retVal = ETrue;
-    }
-
-    CleanupStack::PopAndDestroy(&myView); // myView
-
-    return retVal;
-}
-
-// -----------------------------------------------------------------------------
-// CLookupDatabase::FindEntriesByLandmarkIdL()
-// Finds a list of lookup items given a landmark uid.
-// -----------------------------------------------------------------------------
-//
-void CLookupDatabase::FindEntriesByLandmarkIdL(const TUint32 aLandmarkId,
-        RArray<TLookupItem>& aLookupItemArray)
-{
-    __TRACE_CALLSTACK;// Create a query to find the item.
-    TFileName queryBuffer;
-    queryBuffer.Copy(KSelectAllFrom);
-    queryBuffer.Append(KLookupTable);
-    queryBuffer.Append(KStringWhere);
-    queryBuffer.Append(NColLmUid);
-    queryBuffer.Append(KStringEqual);
-    queryBuffer.AppendNum(aLandmarkId);
-
-    // Create a view of the table with the above query.
-    RDbView myView;
-    myView.Prepare(iItemsDatabase, TDbQuery(queryBuffer));
-    CleanupClosePushL(myView);
-    myView.EvaluateAll();
-    myView.FirstL();
-
-    while (myView.AtRow())
-    {
-        // Item found. get the details.
-        myView.GetL();
-        TLookupItem newItem;
-        newItem.iUid = myView.ColUint(KColumnUid);
-        newItem.iSource = myView.ColUint(KColumnSource);
-        newItem.iLmId = myView.ColUint(KColumnLmkUid);
-        aLookupItemArray.Append(newItem);
-        myView.NextL();
-    }
-
-    CleanupStack::PopAndDestroy(&myView); // myView
-}
-
-// -----------------------------------------------------------------------------
-// CLookupDatabase::FindEntriesByLandmarkIdL()
-// Finds a list of lookup items given a landmark uid.
-// -----------------------------------------------------------------------------
-//
-void CLookupDatabase::FindEntriesBySourceTypeL(const TUint32 aSourceType,
-        RArray<TLookupItem>& aLookupItemArray)
-{
-    __TRACE_CALLSTACK;// Create a query to find the item.
-    TFileName queryBuffer;
-    queryBuffer.Copy(KSelectAllFrom);
-    queryBuffer.Append(KLookupTable);
-    queryBuffer.Append(KStringWhere);
-    queryBuffer.Append(NColSource);
-    queryBuffer.Append(KStringEqual);
-    queryBuffer.AppendNum(aSourceType);
-
-    // Create a view of the table with the above query.
-    RDbView myView;
-    myView.Prepare(iItemsDatabase, TDbQuery(queryBuffer));
-    CleanupClosePushL(myView);
-    myView.EvaluateAll();
-    myView.FirstL();
-
-    while (myView.AtRow())
-    {
-        // Item found. get the details.
-        myView.GetL();
-
-        TLookupItem newItem;
-        newItem.iUid = myView.ColUint(KColumnUid);
-        newItem.iSource = myView.ColUint(KColumnSource);
-        newItem.iLmId = myView.ColUint(KColumnLmkUid);
-        aLookupItemArray.Append(newItem);
-        myView.NextL();
-    }
-
-    CleanupStack::PopAndDestroy(&myView); // myView
-}
-
-// End of file
-
--- a/locationdataharvester/rom/mylocations.iby	Thu May 27 12:49:34 2010 +0300
+++ b/locationdataharvester/rom/mylocations.iby	Fri Jun 11 13:33:47 2010 +0300
@@ -23,8 +23,10 @@
 file=ABI_DIR\BUILD_DIR\geocodeupdate.dll PROGRAMS_DIR\geocodeupdate.dll
 file=ABI_DIR\BUILD_DIR\maptileservice.dll PROGRAMS_DIR\maptileservice.dll
 file=ABI_DIR\BUILD_DIR\locationdatalookupdb.dll PROGRAMS_DIR\locationdatalookupdb.dll
+file=ABI_DIR\BUILD_DIR\mylocationsdatabasemanager.dll PROGRAMS_DIR\mylocationsdatabasemanager.dll
+
 
 //Resource file(s) for Mylocations application (mylocations.iby)
-data=DATAZ_\APP_RESOURCE_DIR\mylocations.rsc APP_RESOURCE_DIR\mylocations.rsc
+data=DATAZ_\APP_RESOURCE_DIR\mylocations.rsc APP_RESOURCE_DIR\mylocationsengine.rsc
 
 #endif
--- a/locationpickerservice/rom/locationpickerservice.iby	Thu May 27 12:49:34 2010 +0300
+++ b/locationpickerservice/rom/locationpickerservice.iby	Fri Jun 11 13:33:47 2010 +0300
@@ -22,5 +22,7 @@
 file=ABI_DIR/BUILD_DIR/locationpickerservice.exe                   PROGRAMS_DIR/locationpickerservice.exe
 data=ZPRIVATE/10003a3f/import/apps/locationpickerservice_reg.rsc		/private/10003a3f/import/apps/locationpickerservice_reg.rsc	
 data=DATAZ_/resource/apps/locationpickerservice.rsc		/resource/apps/locationpickerservice.rsc
+// Localizations
+data=DATAZ_\QT_TRANSLATIONS_DIR\lilpicker_en.qm     QT_TRANSLATIONS_DIR\lilpicker_en.qm
 
 #endif // __LOCATION_PICKER_SERVICE_IBY__
--- a/locationpickerservice/src/locationpickerlandscapeview.cpp	Thu May 27 12:49:34 2010 +0300
+++ b/locationpickerservice/src/locationpickerlandscapeview.cpp	Fri Jun 11 13:33:47 2010 +0300
@@ -314,15 +314,16 @@
     if(mCollectionContent->locationFound())
     {
         mGridView->setModel(mCollectionContent->getProxyModel(),mGridViewItem);
+        //Enable the options
+        mAscendingAction->setEnabled(true);
+        mDescendingAction->setEnabled(true);
     }
     else
     {
         mGridView->setModel(mCollectionContent->getStandardModel(),mGridViewItem);
     }
     mViewType = ELocationPickerCollectionContent;
-    //Enable the options
-    mAscendingAction->setEnabled(true);
-    mDescendingAction->setEnabled(true);
+    
     mCollectionAction->setChecked(true);
 }
 
--- a/locationpickerservice/src/locationpickerpotraitview.cpp	Thu May 27 12:49:34 2010 +0300
+++ b/locationpickerservice/src/locationpickerpotraitview.cpp	Fri Jun 11 13:33:47 2010 +0300
@@ -377,15 +377,16 @@
     if(mCollectionContent->locationFound())
     {
         mListView->setModel(mCollectionContent->getProxyModel(),mListItem);
+        //Enable the options
+        mAscendingAction->setEnabled(true);
+        mDescendingAction->setEnabled(true);
     }
     else
     {
         mListView->setModel(mCollectionContent->getStandardModel(),mListItem);
     }
     mViewType = ELocationPickerCollectionContent;
-    //Enable the options
-    mAscendingAction->setEnabled(true);
-    mDescendingAction->setEnabled(true);
+    
     mCollectionAction->setChecked(true);
 }
 
--- a/locationpickerservice/src/main.cpp	Thu May 27 12:49:34 2010 +0300
+++ b/locationpickerservice/src/main.cpp	Fri Jun 11 13:33:47 2010 +0300
@@ -16,20 +16,13 @@
 */
 
 #include <HbApplication>
-#include <QTranslator>
-#include <QLocale>
+#include <HbTranslator>
 #include "locationpickerappwindow.h"
-#include "locationpickertypes.h"
 
 int main(int argc, char *argv[])
 {
-    HbApplication app(argc, argv);
-    
-    QTranslator translator;
-    QString lang = QLocale::system().name();
-    translator.load("lilpicker_" + lang);
-    app.installTranslator(&translator);
-    
+    HbApplication app(argc, argv);   
+    HbTranslator translator("lilpicker");    
     app.setApplicationName( hbTrId("txt_lint_title_select_location") );
     LocationPickerAppWindow mainWindow;
     mainWindow.show();