locationdataharvester/mylocationsengine/src/mylocationsengine.cpp
changeset 30 96df3ab41000
parent 26 f3533f6eae3f
child 31 8db05346071b
equal deleted inserted replaced
26:f3533f6eae3f 30:96df3ab41000
    24 #include <EPos_CPosLmDatabaseManager.h>
    24 #include <EPos_CPosLmDatabaseManager.h>
    25 #include <lbsposition.h>
    25 #include <lbsposition.h>
    26 #include <bautils.h>
    26 #include <bautils.h>
    27 #include <f32file.h>
    27 #include <f32file.h>
    28 #include <locationservicedefines.h>
    28 #include <locationservicedefines.h>
       
    29 #include <e32property.h>
       
    30 #include "contactsubscriber.h"
       
    31 #include "calendarsubscriber.h"
    29 #include "mylocationsengine.h"
    32 #include "mylocationsengine.h"
    30 #include "mylocationsdefines.h"
    33 #include "mylocationsdefines.h"
    31 #include "geocodeupdate.h" //header for GeocodeUpdate class
    34 #include "geocodeupdate.h" //header for GeocodeUpdate class
    32 //handle for CMyLocationsHistoryDbObserver class
    35 //handle for CMyLocationsHistoryDbObserver class
    33 #include "mylocationlogger.h"
    36 #include "mylocationlogger.h"
    35 _LIT ( KImageStorageDrive, "C:\\MapTile\\");
    38 _LIT ( KImageStorageDrive, "C:\\MapTile\\");
    36 #endif
    39 #endif
    37 _LIT(KFolderName,":\\MapTile\\");
    40 _LIT(KFolderName,":\\MapTile\\");
    38 const TInt KImagePathSize=36;
    41 const TInt KImagePathSize=36;
    39 const TInt KDefaultFilePathSize = 20;
    42 const TInt KDefaultFilePathSize = 20;
       
    43 const TUid KMaptileStatusPublish={0x2002680A};
       
    44 enum TMaptileStatusKeys {EMaptileStatusInteger=0x1};
       
    45 
       
    46 //Protocol : [appid-addresstype-maptilestatus]
       
    47 _LIT8( KMaptileStatusFormat, "%d-%d-%d" );
       
    48 const TInt KProtocolBufferSize = 16;
    40 
    49 
    41 // ============================ MEMBER FUNCTIONS ===============================
    50 // ============================ MEMBER FUNCTIONS ===============================
    42 
    51 
    43 CMyLocationsEngine* CMyLocationsEngine::NewL()
    52 CMyLocationsEngine* CMyLocationsEngine::NewL()
    44 {
    53 {
    79     MYLOCLOGSTRING("iMapTileInterface = CMapTileInterface::NewL()");
    88     MYLOCLOGSTRING("iMapTileInterface = CMapTileInterface::NewL()");
    80     //Maptile Db instance
    89     //Maptile Db instance
    81     iMaptileDatabase = CLookupMapTileDatabase::NewL(KMapTileLookupDatabaseName);
    90     iMaptileDatabase = CLookupMapTileDatabase::NewL(KMapTileLookupDatabaseName);
    82 
    91 
    83     MYLOCLOGSTRING("Maptile Db instance created ");
    92     MYLOCLOGSTRING("Maptile Db instance created ");
    84     
       
    85     iAddressCompare = CAddressComparision::NewL();
       
    86 	
    93 	
    87     iMyLocationThreeAMTimer = CLocationGeoTagTimerAO::NewL(*this);
    94     iMyLocationThreeAMTimer = CLocationGeoTagTimerAO::NewL(*this);
    88   
    95   
    89     iMyLocationThreeAMTimer->StartTimer();
    96     iMyLocationThreeAMTimer->StartTimer();
    90     
    97     
   104     iCalSession = CCalSession::NewL();
   111     iCalSession = CCalSession::NewL();
   105     NotifyChangeL(status);
   112     NotifyChangeL(status);
   106 
   113 
   107     // Start listening to landmarks db changes
   114     // Start listening to landmarks db changes
   108     StartLandmarksChangeNotifier();   
   115     StartLandmarksChangeNotifier();   
       
   116     iContactSubscriber = CContactSubscriber::NewL(this);
       
   117     iCalendarSubscriber = CCalendarSubscriber::NewL(this);
       
   118     TInt ret = RProperty::Define( KMaptileStatusPublish, EMaptileStatusInteger, RProperty::EByteArray  );
   109 
   119 
   110 }
   120 }
   111 // -----------------------------------------------------------------------------
   121 // -----------------------------------------------------------------------------
   112 // CMyLocationsEngine::SetFolderPath()
   122 // CMyLocationsEngine::SetFolderPath()
   113 // set folder path structure
   123 // set folder path structure
   207 // C++ default constructor can NOT contain any code, that might leave.
   217 // C++ default constructor can NOT contain any code, that might leave.
   208 // -----------------------------------------------------------------------------
   218 // -----------------------------------------------------------------------------
   209 //
   219 //
   210 CMyLocationsEngine::CMyLocationsEngine() :
   220 CMyLocationsEngine::CMyLocationsEngine() :
   211             CActive(EPriorityStandard), 
   221             CActive(EPriorityStandard), 
   212             iCalSession(NULL), iCalView(NULL), 
   222             iCalSession(NULL),
   213 	        iContactsDb(NULL), iContactChangeNotifier(NULL), 
   223             iCalView(NULL), 
       
   224 	        iContactsDb(NULL), 
       
   225 	        iContactChangeNotifier(NULL), 
   214 			iLandmarkDb(NULL),
   226 			iLandmarkDb(NULL),
   215             iMapTileInterface(NULL), iMyLocationsDatabaseManager(NULL),
   227             iMapTileInterface(NULL),
   216             iMaptileDatabase(NULL), iAddressCompare(NULL),
   228             iMyLocationsDatabaseManager(NULL),
       
   229             iMaptileDatabase(NULL),
   217             iMyLocationThreeAMTimer(NULL),
   230             iMyLocationThreeAMTimer(NULL),
   218             iMaptileGeocoderPluginAvailable(EFalse),iCalenderNotification(NULL),
   231             iMaptileGeocoderPluginAvailable(EFalse),
   219             iContactManager(NULL)
   232             iCalenderNotification(NULL),
       
   233             iContactManager(NULL),
       
   234             iContactSubscriber(NULL),
       
   235             iCalendarSubscriber(NULL),
       
   236             iLastContactId( -1 ) ,
       
   237             iLastCalendarId( 0 )
   220 {
   238 {
   221 
   239 
   222 }
   240 }
   223 
   241 
   224 // -----------------------------------------------------------------------------
   242 // -----------------------------------------------------------------------------
   228 //
   246 //
   229 CMyLocationsEngine::~CMyLocationsEngine()
   247 CMyLocationsEngine::~CMyLocationsEngine()
   230 {
   248 {
   231     __TRACE_CALLSTACK;// delete the member variables.
   249     __TRACE_CALLSTACK;// delete the member variables.
   232    
   250    
       
   251     Cancel();
       
   252     
   233     delete iContactChangeNotifier;
   253     delete iContactChangeNotifier;
   234 
   254 
   235     delete iMyLocationsDatabaseManager;
   255     delete iMyLocationsDatabaseManager;
   236 
   256 
   237     delete iLandmarkDb;
   257     delete iLandmarkDb;
   243     delete iCalSession;
   263     delete iCalSession;
   244 	 
   264 	 
   245 	delete iMapTileInterface;
   265 	delete iMapTileInterface;
   246 
   266 
   247     delete iMaptileDatabase;
   267     delete iMaptileDatabase;
   248 
   268        
   249     delete iAddressCompare;
       
   250     
       
   251     delete iCalenderNotification;
   269     delete iCalenderNotification;
   252     
   270     
   253 	delete iMyLocationThreeAMTimer;
   271 	delete iMyLocationThreeAMTimer;
   254 		
   272 		
   255     delete iContactManager;
   273     delete iContactManager;
       
   274     
       
   275     delete iContactSubscriber;
       
   276 
       
   277     delete iCalendarSubscriber;
       
   278     
       
   279 	//free the allocated memory
       
   280     for( TInt index = 0; index < iAddressInfo.Count(); index++ )
       
   281     {
       
   282         delete iAddressInfo[index];
       
   283         iAddressInfo.Remove(index);
       
   284         iAddressInfo.Compress();
       
   285     }
       
   286     
       
   287     iAddressInfo.Reset();
   256     
   288     
   257 }
   289 }
   258 
   290 
   259 // -----------------------------------------------------------------------------
   291 // -----------------------------------------------------------------------------
   260 // CMyLocationsEngine::NotifyChangeL()
   292 // CMyLocationsEngine::NotifyChangeL()
   283         }
   315         }
   284         
   316         
   285         
   317         
   286         iCalenderNotification->CheckCalenderDbFileStructure( drive );
   318         iCalenderNotification->CheckCalenderDbFileStructure( drive );
   287     }
   319     }
       
   320 }
       
   321 // -----------------------------------------------------------------------------
       
   322 // CMyLocationsEngine::GetChangeNoficationL()
       
   323 // To get callbacks through publisher from contact context
       
   324 // -----------------------------------------------------------------------------
       
   325 //
       
   326 void CMyLocationsEngine::GetChangeNotificationL( TInt &aId, TInt& addressType, TInt& addressCount  )
       
   327 {
       
   328     __TRACE_CALLSTACK;
       
   329    
       
   330     iLastContactId = aId;
       
   331     
       
   332     TAppAddressInfo* addressInfo = new (ELeave) TAppAddressInfo;
       
   333     addressInfo->iUid = aId;
       
   334     addressInfo->iAddressType =  addressType;
       
   335     //Memory will be freed when the queue is deleted
       
   336     if( iAddressInfo.Append(addressInfo) != KErrNone )
       
   337     {
       
   338         delete addressInfo;
       
   339     }
       
   340     
       
   341     //Get all 3 adress
       
   342     if( addressCount > 1 && iAddressInfo.Count() < addressCount )
       
   343         return;
       
   344    
       
   345     //If the requested id is already in queue, just return
       
   346     for( TInt index = 0 ; index < iMapTileRequestQueue.Count(); index++ )
       
   347     {
       
   348         if( iLastContactId == iMapTileRequestQueue[index]->iUId )
       
   349         {
       
   350             return;
       
   351         }
       
   352     }
       
   353     
       
   354     for( TInt index = 0; index < iAddressInfo.Count(); index++ )
       
   355     {
       
   356         TUidSourceType type = static_cast<TUidSourceType>(iAddressInfo[index]->iAddressType );
       
   357     
       
   358         //if type is contact
       
   359         if( type == ESourceContactsPref || type == ESourceContactsWork || 
       
   360                       type == ESourceContactsHome )
       
   361         {
       
   362             QContact contactInfo = iContactManager->contact( iAddressInfo[index]->iUid );
       
   363             
       
   364             CPosLandmark *contactAddressLm = NULL;
       
   365           
       
   366             TInt itemCount = 0;
       
   367             
       
   368             foreach ( QContactAddress address, contactInfo.details<QContactAddress>() )
       
   369             {
       
   370                 QStringList context = address.contexts();
       
   371                 if ( context.isEmpty()  && type ==  ESourceContactsPref ) // no context
       
   372                 {
       
   373                     contactAddressLm = GetContactAddressDetailsLC( address );
       
   374                     itemCount++;
       
   375                     break;
       
   376                 }
       
   377                 else if ( !context.isEmpty() && context.first() == QContactAddress::ContextHome &&
       
   378                                     type == ESourceContactsHome )
       
   379                 {
       
   380                     contactAddressLm = GetContactAddressDetailsLC( address );
       
   381                     itemCount++;
       
   382                     break;
       
   383                 }
       
   384                 else if ( !context.isEmpty() && context.first() == QContactAddress::ContextWork  && 
       
   385                                 type == ESourceContactsWork )
       
   386                 {
       
   387                     contactAddressLm = GetContactAddressDetailsLC( address );
       
   388                     itemCount++;
       
   389                     break;
       
   390                 }
       
   391             }
       
   392 
       
   393             //Update the entry with inprogress status
       
   394             TLookupItem lookupItem;
       
   395             lookupItem.iUid = iAddressInfo[index]->iUid;
       
   396             lookupItem.iSource = type;
       
   397             lookupItem.iFilePath.Zero();
       
   398             lookupItem.iFetchingStatus = EMapTileFetchingInProgress;
       
   399             iMaptileDatabase->UpdateEntryL( lookupItem );
       
   400             
       
   401             //Request for maptile fetching
       
   402             RequestMapTileImageL( *contactAddressLm, type, 
       
   403                          iAddressInfo[index]->iUid, EContactDbObserverEventContactChanged );
       
   404             
       
   405             CleanupStack::PopAndDestroy( itemCount );
       
   406         }
       
   407     }
       
   408     for( TInt index = 0; index < iAddressInfo.Count(); index++ )
       
   409     {
       
   410 	    //free the allocated memory
       
   411         delete iAddressInfo[index];
       
   412 		iAddressInfo.Remove(index);
       
   413         iAddressInfo.Compress();
       
   414 	}
       
   415     
       
   416     iAddressInfo.Reset();
       
   417 }
       
   418 
       
   419 // -----------------------------------------------------------------------------
       
   420 // CMyLocationsEngine::SubscribeFromCalendarL()
       
   421 // To get callbacks through publisher from calendar context
       
   422 // -----------------------------------------------------------------------------
       
   423 //
       
   424 void CMyLocationsEngine::SubscribeFromCalendarL(TInt aId)
       
   425 {
       
   426     __TRACE_CALLSTACK;
       
   427     iLastCalendarId = aId;
       
   428     for ( int index =0;iMapTileRequestQueue.Count()>index ;index++)
       
   429     {
       
   430         if( iLastCalendarId == iMapTileRequestQueue[index]->iUId )
       
   431         {            
       
   432             return;
       
   433         }
       
   434     }
       
   435     
       
   436     CCalEntry* calEntry = NULL;
       
   437     calEntry = iCalView->FetchL(aId);
       
   438     CleanupStack::PushL(calEntry);
       
   439     TPtrC address(calEntry->LocationL());
       
   440     if( address.Length()>0 )
       
   441     {
       
   442         TLookupItem lookupItem;
       
   443         lookupItem.iUid = aId;
       
   444         lookupItem.iSource = ESourceCalendar;
       
   445         lookupItem.iFilePath.Zero();
       
   446         lookupItem.iFetchingStatus = EMapTileFetchingInProgress;
       
   447         iMaptileDatabase->UpdateEntryL( lookupItem );
       
   448         RequestMapTileImageL( address, ESourceCalendar, aId , EChangeModify );
       
   449     }
       
   450     CleanupStack::PopAndDestroy(calEntry);
   288 }
   451 }
   289 // -----------------------------------------------------------------------------
   452 // -----------------------------------------------------------------------------
   290 // CMyLocationsEngine::StartCalenderChangeNotifierL()
   453 // CMyLocationsEngine::StartCalenderChangeNotifierL()
   291 // Starts calender change notification method to get callbacks when entries are 
   454 // Starts calender change notification method to get callbacks when entries are 
   292 // added/modified/deleted in contacts
   455 // added/modified/deleted in contacts
   334 //
   497 //
   335 void CMyLocationsEngine::StartContactsChangeNotifierL()
   498 void CMyLocationsEngine::StartContactsChangeNotifierL()
   336 {
   499 {
   337     __TRACE_CALLSTACK;
   500     __TRACE_CALLSTACK;
   338    
   501    
   339     GeocodeUpdate::createContactdb();
   502     GeocodeUpdate geocodeUpdate;
       
   503     geocodeUpdate.createContactdb();
   340     iContactsDb = CContactDatabase::OpenL();
   504     iContactsDb = CContactDatabase::OpenL();
   341     // Create CContactChangeNotifier object with 'this' object. 
   505     // Create CContactChangeNotifier object with 'this' object. 
   342     iContactChangeNotifier = CContactChangeNotifier::NewL(*iContactsDb,this);
   506     iContactChangeNotifier = CContactChangeNotifier::NewL(*iContactsDb,this);
   343 }
   507 }
   344 
   508 
   393                 if (calChangeEntry.iEntryId == iMapTileRequestQueue[0]->iUId)
   557                 if (calChangeEntry.iEntryId == iMapTileRequestQueue[0]->iUId)
   394                 {
   558                 {
   395                     return;
   559                     return;
   396                 }
   560                 }
   397             }
   561             }
   398             TLookupItem lookupItem;
   562             TRAP_IGNORE( CalenderEntryModifyL(calChangeEntry) ) ;
   399             lookupItem.iSource = ESourceCalendar;
       
   400             lookupItem.iUid = calChangeEntry.iEntryId;
       
   401             TRAP_IGNORE(ManipulateMapTileDataBaseL(lookupItem));
       
   402             //TODO: comapare address and then delete 
       
   403             TRAP_IGNORE( CalenderEntryAddedL(calChangeEntry) );
       
   404             break;
   563             break;
   405         }
   564         }
   406         case EChangeDelete:
   565         case EChangeDelete:
   407         {
   566         {
   408             TLookupItem lookupItem;
   567             TLookupItem lookupItem;
   423 // -----------------------------------------------------------------------------
   582 // -----------------------------------------------------------------------------
   424 //
   583 //
   425 void CMyLocationsEngine::CalenderEntryAddedL(TCalChangeEntry aCalChangeEntry)
   584 void CMyLocationsEngine::CalenderEntryAddedL(TCalChangeEntry aCalChangeEntry)
   426 {
   585 {
   427     __TRACE_CALLSTACK;
   586     __TRACE_CALLSTACK;
       
   587     
       
   588     TUint32 entryId=0;
       
   589     entryId=aCalChangeEntry.iEntryId;
       
   590     //create entry in the data base and maintain a fetching state.
       
   591     TLookupItem lookupItem;
       
   592     lookupItem.iUid = entryId ;
       
   593     lookupItem.iSource = ESourceCalendar;
       
   594     lookupItem.iFilePath.Zero();
       
   595     lookupItem.iFetchingStatus = EMapTileFetchingInProgress;     
       
   596     TRAP_IGNORE( iMaptileDatabase->CreateEntryL(lookupItem) );
   428     CCalEntry* calEntry = NULL;
   597     CCalEntry* calEntry = NULL;
   429     calEntry = iCalView->FetchL(aCalChangeEntry.iEntryId);
   598     calEntry = iCalView->FetchL( entryId );
       
   599     CleanupStack::PushL(calEntry);
       
   600     TPtrC address(calEntry->LocationL());     
       
   601     if (address.Length() > 0)
       
   602     {
       
   603         RequestMapTileImageL( address, ESourceCalendar, entryId , EChangeAdd );
       
   604     }  
       
   605     CleanupStack::PopAndDestroy(calEntry);
       
   606 }
       
   607 
       
   608 // -----------------------------------------------------------------------------
       
   609 // CMyLocationsEngine::CalenderEntryModifyL()
       
   610 // -----------------------------------------------------------------------------
       
   611 //
       
   612 void CMyLocationsEngine::CalenderEntryModifyL(TCalChangeEntry aCalChangeEntry)
       
   613 {
       
   614     __TRACE_CALLSTACK;
       
   615     TUint32 entryId = 0;
       
   616     entryId = aCalChangeEntry.iEntryId;
       
   617     TLookupItem lookupItem;
       
   618     lookupItem.iSource = ESourceCalendar;
       
   619     lookupItem.iUid = entryId;
       
   620     CCalEntry* calEntry = NULL;
       
   621     calEntry = iCalView->FetchL(entryId);
       
   622     CleanupStack::PushL(calEntry);
   430     TPtrC address(calEntry->LocationL());
   623     TPtrC address(calEntry->LocationL());
   431     if(address.Length()>0)
   624     if (iMyLocationsDatabaseManager->CheckIfAddressChanged(address, entryId,
   432     {        
   625             ESourceCalendar))
   433     //create entry in the data base and maintain a fetching state.
   626     {
   434         TLookupItem lookupItem;
       
   435         lookupItem.iUid = aCalChangeEntry.iEntryId;
       
   436         lookupItem.iSource = ESourceCalendar;
       
   437         lookupItem.iFilePath.Zero();
   627         lookupItem.iFilePath.Zero();
   438         lookupItem.iFetchingStatus = EMapTileFetchingInProgress;
   628         lookupItem.iFetchingStatus = EMapTileFetchingInProgress;
   439         iMaptileDatabase->CreateEntryL(lookupItem);  
   629         TRAP_IGNORE( iMaptileDatabase->ReSetEntryL(lookupItem) );
   440         
   630         if (address.Length() > 0)
   441         RequestMapTileImageL(address,ESourceCalendar, aCalChangeEntry.iEntryId);
   631         {
   442     }
   632             RequestMapTileImageL(address, ESourceCalendar, entryId , EChangeModify);
   443     delete calEntry;
   633         }
       
   634         else
       
   635         {
       
   636             UpdateDatabaseL(NULL, entryId, ESourceCalendar, EEntryDeleted);
       
   637         }
       
   638         if ( lookupItem.iFilePath.Length() > 0 )
       
   639         {
       
   640             iMaptileDatabase->DeleteMapTileL(lookupItem);
       
   641         }
       
   642 
       
   643     }
       
   644     CleanupStack::PopAndDestroy(calEntry);
   444 }
   645 }
   445 
   646 
   446 // -----------------------------------------------------------------------------
   647 // -----------------------------------------------------------------------------
   447 // CMyLocationsEngine::HandleDatabaseEventL()
   648 // CMyLocationsEngine::HandleDatabaseEventL()
   448 // Callback that provides information about the contact database change event.
   649 // Callback that provides information about the contact database change event.
   450 //
   651 //
   451 void CMyLocationsEngine::HandleDatabaseEventL(TContactDbObserverEvent aEvent)
   652 void CMyLocationsEngine::HandleDatabaseEventL(TContactDbObserverEvent aEvent)
   452 {
   653 {
   453     __TRACE_CALLSTACK;
   654     __TRACE_CALLSTACK;
   454     
   655     
   455     HandlelandmarkDatabaseL(aEvent);
       
   456     
       
   457     //Forward the event for maptile fetching only if maptile plugin available
   656     //Forward the event for maptile fetching only if maptile plugin available
   458     if( iMaptileGeocoderPluginAvailable )
   657     if( iMaptileGeocoderPluginAvailable )
   459     {
   658     {
   460         TriggerMaptileRequestL(aEvent);
   659         TriggerMaptileRequestL(aEvent);
   461     }
   660     }
   462     
   661     
       
   662     HandlelandmarkDatabaseL(aEvent);
   463 }
   663 }
   464 
   664 
   465 // -----------------------------------------------------------------------------
   665 // -----------------------------------------------------------------------------
   466 // CMyLocationsEngine::HandlelandmarkDatabaseL()
   666 // CMyLocationsEngine::HandlelandmarkDatabaseL()
   467 // Process the contact database event and updates the landmark database
   667 // Process the contact database event and updates the landmark database
   559                 // If the contact is a modified one and it might already exist in
   759                 // If the contact is a modified one and it might already exist in
   560                 // mylocations db, so delete it
   760                 // mylocations db, so delete it
   561                 UpdateDatabaseL(NULL,
   761                 UpdateDatabaseL(NULL,
   562                         aEvent.iContactId, ESourceContactsPref,
   762                         aEvent.iContactId, ESourceContactsPref,
   563                         EEntryDeleted);
   763                         EEntryDeleted);
       
   764                 
       
   765                 UpdateDatabaseL(NULL,
       
   766                                  aEvent.iContactId, ESourceContactsHome,
       
   767                                  EEntryDeleted);
       
   768                   
   564                 UpdateDatabaseL(NULL,
   769                 UpdateDatabaseL(NULL,
   565                         aEvent.iContactId, ESourceContactsWork,
   770                         aEvent.iContactId, ESourceContactsWork,
   566                         EEntryDeleted);
   771                         EEntryDeleted);
   567                 UpdateDatabaseL(NULL,
       
   568                         aEvent.iContactId, ESourceContactsHome,
       
   569                         EEntryDeleted);
       
   570             }
   772             }
   571         }
   773         }
   572         else
   774         else
   573         {
   775         {
   574             // There is atleast one valid address present.       
   776             // There is atleast one valid address present.       
   575 
   777 
   576             // Get the TEntryChangeType for contacts.
   778             // Get the TEntryChangeType for contacts.
   577             TEntryChangeType changeType = MapChangeType(
   779             TEntryChangeType changeType = MapChangeType(
   578                     ESourceContactsPref, aEvent.iType);
   780                     ESourceContactsPref, aEvent.iType);
   579 
   781 
   580             // if home address available, update Mylocations.  
       
   581             if (homeAddressLm)
       
   582             {
       
   583                 UpdateDatabaseL(homeAddressLm,
       
   584                         aEvent.iContactId, ESourceContactsHome, changeType);
       
   585            }
       
   586 
       
   587             // if work address available, update Mylocations.  
       
   588             if (workAddressLm)
       
   589             {
       
   590                 UpdateDatabaseL(workAddressLm,
       
   591                         aEvent.iContactId, ESourceContactsWork, changeType);
       
   592             }
       
   593 
       
   594             // if prefered address available, update Mylocations.  
   782             // if prefered address available, update Mylocations.  
   595             if (preferedAddressLm)
   783             if (preferedAddressLm)
   596             {
   784             {
   597                 UpdateDatabaseL(
   785                 UpdateDatabaseL(
   598                         preferedAddressLm, aEvent.iContactId,
   786                         preferedAddressLm, aEvent.iContactId,
   599                         ESourceContactsPref, changeType);
   787                         ESourceContactsPref, changeType);
   600            }
   788             }
       
   789             // if home address available, update Mylocations.  
       
   790             if (homeAddressLm)
       
   791             {
       
   792                 UpdateDatabaseL(homeAddressLm,
       
   793                         aEvent.iContactId, ESourceContactsHome, changeType);
       
   794             }
       
   795 
       
   796             // if work address available, update Mylocations.  
       
   797             if (workAddressLm)
       
   798             {
       
   799                 UpdateDatabaseL(workAddressLm,
       
   800                         aEvent.iContactId, ESourceContactsWork, changeType);
       
   801             }
       
   802 
   601             CleanupStack::PopAndDestroy( itemCount );
   803             CleanupStack::PopAndDestroy( itemCount );
   602         }  
   804         }  
   603 
   805 
   604     }
   806     }
   605     else if (aEvent.iType == EContactDbObserverEventContactDeleted)
   807     else if (aEvent.iType == EContactDbObserverEventContactDeleted)
   698             lookupItem.iSource = ESourceContactsPref;
   900             lookupItem.iSource = ESourceContactsPref;
   699             if (preferedAddressLm)
   901             if (preferedAddressLm)
   700             {
   902             {
   701                 MYLOCLOGSTRING("preferedAddressLm address changed" );
   903                 MYLOCLOGSTRING("preferedAddressLm address changed" );
   702 
   904 
   703                 if (iAddressCompare->IsAddressChangedL(*preferedAddressLm,
   905                 if ( iMyLocationsDatabaseManager->CheckIfAddressChanged(*preferedAddressLm,
   704                     aEvent.iContactId, ESourceContactsPref))
   906                     aEvent.iContactId, ESourceContactsPref) )
   705 
   907 
   706                 {
   908                 {
       
   909                     lookupItem.iFilePath.Zero();
       
   910                     lookupItem.iFetchingStatus = EMapTileFetchingInProgress;
       
   911                     TRAP_IGNORE( iMaptileDatabase->ReSetEntryL(lookupItem) );
       
   912                     
       
   913                     RequestMapTileImageL(*preferedAddressLm, ESourceContactsPref,
       
   914                             aEvent.iContactId, iEventType );
       
   915 
       
   916                     if ( lookupItem.iFilePath.Length() > 0 )
       
   917                     {
       
   918                         iMaptileDatabase->DeleteMapTileL(lookupItem);
       
   919                     }
   707                     //remove entry from database
   920                     //remove entry from database
   708                     TRAP_IGNORE( ManipulateMapTileDataBaseL(lookupItem));
   921                     //TRAP_IGNORE( ManipulateMapTileDataBaseL(lookupItem));
   709                     RequestMapTileImageL(*preferedAddressLm, ESourceContactsPref,
       
   710                             aEvent.iContactId);
       
   711                 }
   922                 }
   712             }
   923             }
   713             else
   924             else
   714             {
   925             {
   715                 TRAP_IGNORE( ManipulateMapTileDataBaseL(lookupItem));
   926                 TRAP_IGNORE( ManipulateMapTileDataBaseL(lookupItem));
   716                 
   927                 
   717             }  
   928             }
       
   929             
       
   930             // if home address available, update Mylocations.
       
   931             lookupItem.iSource = ESourceContactsHome;
       
   932             if (homeAddressLm)
       
   933             {
       
   934                 MYLOCLOGSTRING("homeAddressLm address changed" );
       
   935                 if ( iMyLocationsDatabaseManager->CheckIfAddressChanged(*homeAddressLm,
       
   936                         aEvent.iContactId, ESourceContactsHome) )
       
   937                 {
       
   938                     lookupItem.iFilePath.Zero();
       
   939                     lookupItem.iFetchingStatus = EMapTileFetchingInProgress;
       
   940                     TRAP_IGNORE( iMaptileDatabase->ReSetEntryL(lookupItem) )
       
   941                     //remove entry from databse                    
       
   942                     //TRAP_IGNORE( ManipulateMapTileDataBaseL(lookupItem));
       
   943                     RequestMapTileImageL(*homeAddressLm, ESourceContactsHome, aEvent.iContactId,
       
   944                         iEventType);
       
   945                     if (lookupItem.iFilePath.Length() > 0) 
       
   946                     {
       
   947                         iMaptileDatabase->DeleteMapTileL(lookupItem);
       
   948                     }                 
       
   949                 }
       
   950             }
       
   951             else
       
   952             {
       
   953                 TRAP_IGNORE( ManipulateMapTileDataBaseL(lookupItem));
       
   954                 
       
   955             }
       
   956  
   718 
   957 
   719             // if work address available, update Mylocations.
   958             // if work address available, update Mylocations.
   720             lookupItem.iSource = ESourceContactsWork;
   959             lookupItem.iSource = ESourceContactsWork;
   721             if (workAddressLm)
   960             if (workAddressLm)
   722             {
   961             {
   723                 MYLOCLOGSTRING("workAddressLm address changed" );
   962                 MYLOCLOGSTRING("workAddressLm address changed" );
   724                 if (iAddressCompare->IsAddressChangedL(*workAddressLm,
   963                 if ( iMyLocationsDatabaseManager->CheckIfAddressChanged(*workAddressLm,
   725                         aEvent.iContactId, ESourceContactsWork))
   964                         aEvent.iContactId, ESourceContactsWork) )
   726                 //remove entry from database
       
   727                 {
   965                 {
   728                     
   966                     lookupItem.iFilePath.Zero();
   729                     TRAP_IGNORE( ManipulateMapTileDataBaseL(lookupItem));
   967                     lookupItem.iFetchingStatus = EMapTileFetchingInProgress;
       
   968                     TRAP_IGNORE( iMaptileDatabase->ReSetEntryL(lookupItem) )
       
   969 
       
   970                     //remove entry from databse                    
       
   971                     //TRAP_IGNORE( ManipulateMapTileDataBaseL(lookupItem));
   730                     RequestMapTileImageL(*workAddressLm, ESourceContactsWork,
   972                     RequestMapTileImageL(*workAddressLm, ESourceContactsWork,
   731                             aEvent.iContactId);
   973                             aEvent.iContactId, iEventType);
       
   974                     if (lookupItem.iFilePath.Length() > 0) 
       
   975                     {
       
   976                         iMaptileDatabase->DeleteMapTileL(lookupItem);
       
   977                     }
   732                 }
   978                 }
       
   979  
   733             }
   980             }
   734             else
   981             else
   735             {
   982             {
   736                 TRAP_IGNORE( ManipulateMapTileDataBaseL(lookupItem));
   983                 TRAP_IGNORE( ManipulateMapTileDataBaseL(lookupItem));
   737                
   984                
   738             }
   985             }
   739     
       
   740             // if home address available, update Mylocations.
       
   741             lookupItem.iSource = ESourceContactsHome;
       
   742             if (homeAddressLm)
       
   743             {
       
   744                 MYLOCLOGSTRING("homeAddressLm address changed" );
       
   745     
       
   746                 if (iAddressCompare->IsAddressChangedL(*homeAddressLm,
       
   747                         aEvent.iContactId, ESourceContactsHome))
       
   748     
       
   749                 {
       
   750                     //remove entry from databse                    
       
   751                     TRAP_IGNORE( ManipulateMapTileDataBaseL(lookupItem));
       
   752                     RequestMapTileImageL(*homeAddressLm, ESourceContactsHome,
       
   753                             aEvent.iContactId);
       
   754                 }
       
   755  
       
   756             }
       
   757             else
       
   758             {
       
   759                 TRAP_IGNORE( ManipulateMapTileDataBaseL(lookupItem));
       
   760                 
       
   761             }
       
   762             // }
       
   763             break;
   986             break;
   764         }    
   987         }    
   765         case EContactDbObserverEventContactAdded:
   988         case EContactDbObserverEventContactAdded:
   766         {
   989         {
       
   990             TLookupItem lookupItem;
       
   991             lookupItem.iUid = aEvent.iContactId;
       
   992             lookupItem.iFilePath.Zero();
       
   993             lookupItem.iFetchingStatus = EMapTileFetchingInProgress;
       
   994             
   767             MYLOCLOGSTRING("EContactDbObserverEventContactAdded" );
   995             MYLOCLOGSTRING("EContactDbObserverEventContactAdded" );
   768             if (preferedAddressLm)
   996             if (preferedAddressLm)
   769             {
   997             {
       
   998                 //create entry in the data base and maintain a fetching state.
       
   999                 lookupItem.iSource = ESourceContactsPref;
       
  1000                 iMaptileDatabase->CreateEntryL(lookupItem);
   770                 RequestMapTileImageL(*preferedAddressLm, ESourceContactsPref,
  1001                 RequestMapTileImageL(*preferedAddressLm, ESourceContactsPref,
   771                         aEvent.iContactId);
  1002                         aEvent.iContactId, iEventType);
       
  1003             }
       
  1004             if (homeAddressLm)
       
  1005             {
       
  1006                 lookupItem.iSource = ESourceContactsHome;
       
  1007                 iMaptileDatabase->CreateEntryL(lookupItem);
       
  1008                 RequestMapTileImageL(*homeAddressLm, ESourceContactsHome,
       
  1009                         aEvent.iContactId, iEventType);
   772             }
  1010             }
   773             if (workAddressLm)
  1011             if (workAddressLm)
   774             {
  1012             {
       
  1013                 lookupItem.iSource = ESourceContactsWork;
       
  1014                 iMaptileDatabase->CreateEntryL(lookupItem);
   775                 RequestMapTileImageL(*workAddressLm, ESourceContactsWork,
  1015                 RequestMapTileImageL(*workAddressLm, ESourceContactsWork,
   776                         aEvent.iContactId);
  1016                         aEvent.iContactId, iEventType);
   777             }
       
   778             if (homeAddressLm)
       
   779             {
       
   780                 RequestMapTileImageL(*homeAddressLm, ESourceContactsHome,
       
   781                         aEvent.iContactId);
       
   782             }
  1017             }
   783             break;
  1018             break;
   784         }
  1019         }
   785 
  1020 
   786     }
  1021     }
   794 // CMyLocationsEngine::RequestMapTileImageL()
  1029 // CMyLocationsEngine::RequestMapTileImageL()
   795 // Request to get maptiel
  1030 // Request to get maptiel
   796 // -----------------------------------------------------------------------------
  1031 // -----------------------------------------------------------------------------
   797 //
  1032 //
   798 void CMyLocationsEngine::RequestMapTileImageL(const TDesC& aAddressDetails,
  1033 void CMyLocationsEngine::RequestMapTileImageL(const TDesC& aAddressDetails,
   799         const TUidSourceType aAddressType, const TInt32 aUId)
  1034         const TUidSourceType aAddressType, const TInt32 aUId ,const TInt aEventType)
   800 {
  1035 {
   801     __TRACE_CALLSTACK;
  1036     __TRACE_CALLSTACK;
   802     SetFolderPathL();
  1037     SetFolderPathL();
   803     TBuf<KImagePathSize> mImagePath;
  1038     TBuf<KImagePathSize> mImagePath;
   804     mImagePath.Copy(imageFilePath);
  1039     mImagePath.Copy(imageFilePath);
   807     CMapTileRequest* mapTileRequest = new (ELeave) CMapTileRequest;
  1042     CMapTileRequest* mapTileRequest = new (ELeave) CMapTileRequest;
   808 
  1043 
   809     mapTileRequest->iAddressDetails = aAddressDetails.AllocL();
  1044     mapTileRequest->iAddressDetails = aAddressDetails.AllocL();
   810     mapTileRequest->iUId = aUId;
  1045     mapTileRequest->iUId = aUId;
   811     mapTileRequest->iAddressType = aAddressType;
  1046     mapTileRequest->iAddressType = aAddressType;
   812     mapTileRequest->iEventType = iEventType;
  1047     mapTileRequest->iEventType = aEventType;
   813     mapTileRequest->iImagePath.Zero();
  1048     mapTileRequest->iImagePath.Zero();
   814     mapTileRequest->iImagePath.Copy(mImagePath);
  1049     mapTileRequest->iImagePath.Copy(mImagePath);
       
  1050     
       
  1051     TInt error = KErrNone;
       
  1052     
   815     if (iMapTileRequestQueue.Count() <= 0)
  1053     if (iMapTileRequestQueue.Count() <= 0)
   816     {
  1054     {
   817         if ( KErrNone == RequestExecute(mapTileRequest) )
  1055         error = iMapTileRequestQueue.Append(mapTileRequest);
   818         {
  1056         if ( KErrNone == error )
   819             iMapTileRequestQueue.Append(mapTileRequest);
  1057         {
   820         }
  1058             error = RequestExecute(mapTileRequest);    
   821         else
  1059         }
   822         {
       
   823             delete mapTileRequest;
       
   824         }       
       
   825     }
  1060     }
   826     else
  1061     else
   827     {
  1062     {
   828         MYLOCLOGSTRING("Added one more request to request queue" );
  1063         MYLOCLOGSTRING("Added one more request to request queue" );
   829         iMapTileRequestQueue.Append(mapTileRequest);
  1064         error = iMapTileRequestQueue.Append(mapTileRequest);
   830     }
  1065     }
       
  1066     
       
  1067     //If any error , free the allocated memory
       
  1068     if( error != KErrNone )
       
  1069     {
       
  1070         delete mapTileRequest;
       
  1071     }
       
  1072     
   831 }
  1073 }
   832 // -----------------------------------------------------------------------------
  1074 // -----------------------------------------------------------------------------
   833 // CMyLocationsEngine::RequestMapTileImageL()
  1075 // CMyLocationsEngine::RequestMapTileImageL()
   834 // Request to get maptiel
  1076 // Request to get maptiel
   835 // -----------------------------------------------------------------------------
  1077 // -----------------------------------------------------------------------------
   836 //
  1078 //
   837 void CMyLocationsEngine::RequestMapTileImageL(CPosLandmark& aLandmark,
  1079 void CMyLocationsEngine::RequestMapTileImageL(CPosLandmark& aLandmark,
   838         const TUidSourceType aAddressType, const TInt32 aUId)
  1080                     const TUidSourceType aAddressType, const TInt32 aUId,
       
  1081                     const TInt aEventType )
   839 {
  1082 {
   840     __TRACE_CALLSTACK;
  1083     __TRACE_CALLSTACK;
   841 
  1084 
   842     MYLOCLOGSTRING("check folder path existance!");
  1085     MYLOCLOGSTRING("check folder path existance!");
   843     SetFolderPathL();
  1086     SetFolderPathL();
   846     CMapTileRequest* mapTileRequest = new (ELeave) CMapTileRequest;
  1089     CMapTileRequest* mapTileRequest = new (ELeave) CMapTileRequest;
   847 
  1090 
   848     mapTileRequest->iLandmarkInfo = CPosLandmark::NewL(aLandmark);
  1091     mapTileRequest->iLandmarkInfo = CPosLandmark::NewL(aLandmark);
   849     mapTileRequest->iUId = aUId;
  1092     mapTileRequest->iUId = aUId;
   850     mapTileRequest->iAddressType = aAddressType;
  1093     mapTileRequest->iAddressType = aAddressType;
   851     mapTileRequest->iEventType = iEventType;
  1094     mapTileRequest->iEventType = aEventType;
   852     mapTileRequest->iImagePath.Zero();
  1095     mapTileRequest->iImagePath.Zero();
   853     mapTileRequest->iImagePath.Copy(imageFilePath);
  1096     mapTileRequest->iImagePath.Copy(imageFilePath);
   854     MYLOCLOGSTRING1("RequestMapTileImageL() Queue count -%d",iMapTileRequestQueue.Count());
  1097     MYLOCLOGSTRING1("RequestMapTileImageL() Queue count -%d",iMapTileRequestQueue.Count());
   855 
  1098 
       
  1099     TInt error = KErrNone;
       
  1100     
   856     if (iMapTileRequestQueue.Count() <= 0)
  1101     if (iMapTileRequestQueue.Count() <= 0)
   857        {
  1102        {
   858           
  1103            error = iMapTileRequestQueue.Append(mapTileRequest);
   859            if( KErrNone == RequestExecute(mapTileRequest) )
  1104            //error = RequestExecute(mapTileRequest);
       
  1105            if( KErrNone == error  )
   860            {
  1106            {
   861                iMapTileRequestQueue.Append(mapTileRequest);
  1107                //error = iMapTileRequestQueue.Append(mapTileRequest);
       
  1108                error = RequestExecute(mapTileRequest);
   862            }
  1109            }
   863            else
  1110   
   864            {
       
   865                delete mapTileRequest;
       
   866            }          
       
   867        }
  1111        }
   868        else
  1112        else
   869        {
  1113        {
   870            MYLOCLOGSTRING("Added one more request to request queue" );
  1114            MYLOCLOGSTRING("Added one more request to request queue" );
   871            iMapTileRequestQueue.Append(mapTileRequest);
  1115            error = iMapTileRequestQueue.Append(mapTileRequest);
   872        }
  1116        }
   873     
  1117     
   874    
  1118        //If any error, free the memory allocated
       
  1119        if( error != KErrNone )
       
  1120        {
       
  1121            delete mapTileRequest;
       
  1122        }
   875 }
  1123 }
   876 
  1124 
   877 // -----------------------------------------------------------------------------
  1125 // -----------------------------------------------------------------------------
   878 // CMyLocationsEngine::RequestExecute()
  1126 // CMyLocationsEngine::RequestExecute()
   879 // Executes the maptile image processing request
  1127 // Executes the maptile image processing request
  1091         case EPosLmEventLandmarkUpdated:
  1339         case EPosLmEventLandmarkUpdated:
  1092         {
  1340         {
  1093             CPosLandmark* readLandmark = iLandmarkDb->ReadLandmarkLC(
  1341             CPosLandmark* readLandmark = iLandmarkDb->ReadLandmarkLC(
  1094                     iLmEvent.iLandmarkItemId);
  1342                     iLmEvent.iLandmarkItemId);
  1095     
  1343     
  1096             if (readLandmark)
       
  1097             {    
       
  1098                 // update the entry in database.
  1344                 // update the entry in database.
  1099                 UpdateDatabaseL( readLandmark,
  1345                 UpdateDatabaseL( readLandmark,
  1100                         iLmEvent.iLandmarkItemId, ESourceLandmarks, MapChangeType(
  1346                         iLmEvent.iLandmarkItemId, ESourceLandmarks, MapChangeType(
  1101                                 ESourceLandmarks, iLmEvent.iEventType ) );
  1347                                 ESourceLandmarks, iLmEvent.iEventType ) );
  1102     
  1348     
  1103                 CleanupStack::PopAndDestroy(readLandmark);
  1349                 CleanupStack::PopAndDestroy(readLandmark);
  1104             }
       
  1105         }
  1350         }
  1106         break;
  1351         break;
  1107         case EPosLmEventLandmarkDeleted:
  1352         case EPosLmEventLandmarkDeleted:
  1108         {
  1353         {
  1109             // delete the corresponding entries in mylocations database.
  1354             // delete the corresponding entries in mylocations database.
  1136 //
  1381 //
  1137 void CMyLocationsEngine::GeoCodefetchingCompleted( TInt aErrCode, const TReal& aLatitude,
  1382 void CMyLocationsEngine::GeoCodefetchingCompleted( TInt aErrCode, const TReal& aLatitude,
  1138             const TReal& aLongitude, const TDesC& aMapTilePath )
  1383             const TReal& aLongitude, const TDesC& aMapTilePath )
  1139 {
  1384 {
  1140     __TRACE_CALLSTACK;
  1385     __TRACE_CALLSTACK;
  1141     MYLOCLOGSTRING1("MapTilefetchingCompleted aErrCode - %d ",aErrCode);
  1386     MYLOCLOGSTRING1("GeoCodefetchingCompleted aErrCode - %d ",aErrCode);
  1142     MYLOCLOGSTRING1("iMapTileRequestQueue.Count - %d",iMapTileRequestQueue.Count());
  1387     MYLOCLOGSTRING1("iMapTileRequestQueue.Count - %d",iMapTileRequestQueue.Count());
  1143 
  1388 
       
  1389     TBuf8<KProtocolBufferSize> buffer;
       
  1390     
  1144     if (iMapTileRequestQueue.Count() > 0)
  1391     if (iMapTileRequestQueue.Count() > 0)
  1145     {
  1392     {
  1146         MYLOCLOGSTRING1("No.of RequestQueue - %d",iMapTileRequestQueue.Count());
  1393         MYLOCLOGSTRING1("No.of RequestQueue - %d",iMapTileRequestQueue.Count());
  1147        
  1394        
  1148 	    TLookupItem lookupItem;
  1395 	    TLookupItem lookupItem;
  1161             
  1408             
  1162              				
  1409              				
  1163                 lookupItem.iFilePath.Copy(aMapTilePath);
  1410                 lookupItem.iFilePath.Copy(aMapTilePath);
  1164                 lookupItem.iFetchingStatus = EMapTileFectchingCompleted;
  1411                 lookupItem.iFetchingStatus = EMapTileFectchingCompleted;
  1165                 TRAP_IGNORE( UpdateMaptileDatabaseL(iMapTileRequestQueue[0]->iEventType, lookupItem ) );              
  1412                 TRAP_IGNORE( UpdateMaptileDatabaseL(iMapTileRequestQueue[0]->iEventType, lookupItem ) );              
  1166 
  1413                 //Publish the maptile status
       
  1414                 if( iLastContactId == iMapTileRequestQueue[0]->iUId )
       
  1415                 {
       
  1416                     buffer.Zero();
       
  1417                     buffer.Format( KMaptileStatusFormat, iLastContactId, lookupItem.iSource, lookupItem.iFetchingStatus );
       
  1418                     RProperty::Set( KMaptileStatusPublish, EMaptileStatusInteger, buffer );
       
  1419                 }
       
  1420                 //Publish the maptile status ,if it was from calendar
       
  1421                 if( iLastCalendarId == iMapTileRequestQueue[0]->iUId )
       
  1422                 {
       
  1423                     buffer.Zero();
       
  1424                     buffer.Format( KMaptileStatusFormat, iLastCalendarId, lookupItem.iSource, lookupItem.iFetchingStatus );
       
  1425                     RProperty::Set( KMaptileStatusPublish, EMaptileStatusInteger, buffer );
       
  1426                 }
  1167                 MYLOCLOGSTRING("UpdateMaptileDatabaseL handled");
  1427                 MYLOCLOGSTRING("UpdateMaptileDatabaseL handled");
  1168 
  1428 
  1169                 //Process the pending maptile requests
  1429                 //Process the pending maptile requests
  1170                 ProcessNextMaptileRequest();
  1430                 ProcessNextMaptileRequest();
  1171                 
  1431                 
  1193 		   {
  1453 		   {
  1194 		       lookupItem.iFetchingStatus = EMapTileFetchingUnknownError;
  1454 		       lookupItem.iFetchingStatus = EMapTileFetchingUnknownError;
  1195 		   }
  1455 		   }
  1196            TRAP_IGNORE( UpdateMaptileDatabaseL(iMapTileRequestQueue[0]->iEventType,lookupItem ) );
  1456            TRAP_IGNORE( UpdateMaptileDatabaseL(iMapTileRequestQueue[0]->iEventType,lookupItem ) );
  1197            
  1457            
       
  1458            //Publish the maptile status
       
  1459 		   if( iLastContactId == iMapTileRequestQueue[0]->iUId )
       
  1460 		   {
       
  1461 		      buffer.Zero();
       
  1462 		      buffer.Format( KMaptileStatusFormat, iLastContactId, lookupItem.iSource, lookupItem.iFetchingStatus );
       
  1463 		      RProperty::Set( KMaptileStatusPublish, EMaptileStatusInteger, buffer );
       
  1464 		   }
       
  1465             //Publish the maptile status ,if it was from calendar
       
  1466 		   if( iLastCalendarId == iMapTileRequestQueue[0]->iUId )
       
  1467             {
       
  1468 		      buffer.Zero();
       
  1469               buffer.Format( KMaptileStatusFormat, iLastCalendarId, lookupItem.iSource, lookupItem.iFetchingStatus );
       
  1470               RProperty::Set( KMaptileStatusPublish, EMaptileStatusInteger, buffer );
       
  1471             }
       
  1472 		   
  1198 		   ProcessNextMaptileRequest();
  1473 		   ProcessNextMaptileRequest();
  1199         }
  1474         }
  1200     }    
  1475     }    
  1201 }
  1476 }
  1202 
  1477 
  1222                         CPosLandmark *addressLm = NULL;
  1497                         CPosLandmark *addressLm = NULL;
  1223     
  1498     
  1224                         foreach ( QContactAddress address, contactInfo.details<QContactAddress>() )
  1499                         foreach ( QContactAddress address, contactInfo.details<QContactAddress>() )
  1225                         {
  1500                         {
  1226                             QStringList context = address.contexts();
  1501                             QStringList context = address.contexts();
  1227                             if ( ( context.isEmpty() && iItem.iSource == ESourceContactsPref ) ||
  1502                             if ( ( context.isEmpty() && iItem.iSource == ESourceContactsPref  ) 
  1228                                    ( context.first() == QContactAddress::ContextHome  && iItem.iSource == ESourceContactsHome ) ||
  1503                                  ||
  1229                                    ( context.first() == QContactAddress::ContextWork  && iItem.iSource == ESourceContactsWork ) ) 
  1504                                  ( !context.isEmpty() && 
       
  1505                                     ( ( context.first() == QContactAddress::ContextHome  && iItem.iSource == ESourceContactsHome ) ||
       
  1506                                       ( context.first() == QContactAddress::ContextWork  && iItem.iSource == ESourceContactsWork ) ) ) )
  1230                             {
  1507                             {
  1231                                 // Get the default/prefered address details
  1508                                 // Get the default/prefered address details
  1232                                 addressLm = GetContactAddressDetailsLC( address );
  1509                                 addressLm = GetContactAddressDetailsLC( address );
  1233                                 if( addressLm ) 
  1510                                 if( addressLm ) 
  1234                                 {
  1511                                 {
  1235                                     RequestMapTileImageL( *addressLm,
  1512                                     RequestMapTileImageL( *addressLm,
  1236                                            ( TUidSourceType )iItem.iSource, iItem.iUid );
  1513                                            ( TUidSourceType )iItem.iSource, iItem.iUid, EContactDbObserverEventContactChanged );
  1237                                     CleanupStack::PopAndDestroy( addressLm );
  1514                                     CleanupStack::PopAndDestroy( addressLm );
  1238                                     break;
  1515                                     break;
  1239                                 }
  1516                                 }
  1240                             }
  1517                             }
  1241                         }                    
  1518                         }                    
  1250                         {
  1527                         {
  1251                             CleanupStack::PushL(calEntry);
  1528                             CleanupStack::PushL(calEntry);
  1252                             TPtrC address(calEntry->LocationL());
  1529                             TPtrC address(calEntry->LocationL());
  1253                             if(address.Length()>0)
  1530                             if(address.Length()>0)
  1254                             {        
  1531                             {        
  1255                                 RequestMapTileImageL( address, ESourceCalendar, iItem.iUid);
  1532                                 RequestMapTileImageL( address, ESourceCalendar, iItem.iUid , EChangeModify);
  1256                             }
  1533                             }
  1257                             CleanupStack::PopAndDestroy(calEntry);
  1534                             CleanupStack::PopAndDestroy(calEntry);
  1258                         }
  1535                         }
  1259                         else
  1536                         else
  1260                         {
  1537                         {
  1289         MYLOCLOGSTRING1("No.of RequestQueue - %d",iMapTileRequestQueue.Count());
  1566         MYLOCLOGSTRING1("No.of RequestQueue - %d",iMapTileRequestQueue.Count());
  1290 
  1567 
  1291         TLookupItem lookupItem;
  1568         TLookupItem lookupItem;
  1292         lookupItem.iSource = iMapTileRequestQueue[0]->iAddressType;
  1569         lookupItem.iSource = iMapTileRequestQueue[0]->iAddressType;
  1293         lookupItem.iUid = iMapTileRequestQueue[0]->iUId;
  1570         lookupItem.iUid = iMapTileRequestQueue[0]->iUId;
  1294 
  1571        
  1295         if ( aErrCode == KErrNone )
  1572         if ( aErrCode == KErrNone )
  1296         {           
  1573         {           
  1297             lookupItem.iFilePath.Copy(aMapTilePath);
  1574             lookupItem.iFilePath.Copy(aMapTilePath);
  1298    		    lookupItem.iFetchingStatus = EMapTileFectchingCompleted;
  1575             lookupItem.iFetchingStatus = EMapTileFectchingCompleted;
  1299  
  1576  
  1300         }
  1577         }
  1301         else if ( aErrCode == KErrCouldNotConnect )
  1578         else if ( aErrCode == KErrCouldNotConnect )
  1302 		{
  1579 		{
  1303 		    lookupItem.iFetchingStatus = EMapTileFetchingNetworkError;
  1580 		    lookupItem.iFetchingStatus = EMapTileFetchingNetworkError;
  1308 		{
  1585 		{
  1309 		    lookupItem.iFetchingStatus = EMapTileFetchingUnknownError;
  1586 		    lookupItem.iFetchingStatus = EMapTileFetchingUnknownError;
  1310 		}
  1587 		}
  1311 		
  1588 		
  1312         TRAP_IGNORE( UpdateMaptileDatabaseL(iMapTileRequestQueue[0]->iEventType,lookupItem ) );
  1589         TRAP_IGNORE( UpdateMaptileDatabaseL(iMapTileRequestQueue[0]->iEventType,lookupItem ) );
       
  1590 
       
  1591         //Publish the maptile status , if it was from contact
       
  1592         if( iLastContactId == iMapTileRequestQueue[0]->iUId )
       
  1593         {
       
  1594              TBuf8<KProtocolBufferSize> buffer;
       
  1595              buffer.Format( KMaptileStatusFormat, iLastContactId, lookupItem.iSource, lookupItem.iFetchingStatus );
       
  1596              RProperty::Set( KMaptileStatusPublish, EMaptileStatusInteger, buffer );
       
  1597         }
       
  1598         //Publish the maptile status ,if it was from calendar
       
  1599         if( iLastCalendarId == iMapTileRequestQueue[0]->iUId )
       
  1600         {
       
  1601             TBuf8<KProtocolBufferSize> buffer;
       
  1602             buffer.Format( KMaptileStatusFormat, iLastCalendarId, lookupItem.iSource, lookupItem.iFetchingStatus );
       
  1603             RProperty::Set( KMaptileStatusPublish, EMaptileStatusInteger, buffer );
       
  1604         }
  1313     }
  1605     }
  1314     
  1606     
  1315     ProcessNextMaptileRequest();
  1607     ProcessNextMaptileRequest();
  1316 }
  1608 }
  1317 
  1609 
  1365     __TRACE_CALLSTACK;
  1657     __TRACE_CALLSTACK;
  1366     if (aEventType == EContactDbObserverEventContactChanged || aEventType
  1658     if (aEventType == EContactDbObserverEventContactChanged || aEventType
  1367             == EChangeModify || aEventType == EContactDbObserverEventContactAdded ||
  1659             == EChangeModify || aEventType == EContactDbObserverEventContactAdded ||
  1368             aEventType == EChangeAdd )
  1660             aEventType == EChangeAdd )
  1369     {
  1661     {
       
  1662         
  1370         if (iMaptileDatabase->FindEntryL(aLookupItem))
  1663         if (iMaptileDatabase->FindEntryL(aLookupItem))
  1371         {
  1664         {
  1372             iMaptileDatabase->UpdateEntryL(aLookupItem);
  1665             iMaptileDatabase->UpdateEntryL(aLookupItem);
  1373         }
  1666         }
  1374         else
  1667         else
  1395     {
  1688     {
  1396         switch (iMapTileRequestQueue[0]->iAddressType)
  1689         switch (iMapTileRequestQueue[0]->iAddressType)
  1397         {
  1690         {
  1398         //TODO:
  1691         //TODO:
  1399         case ESourceCalendar:
  1692         case ESourceCalendar:
  1400         {
  1693         {                   
  1401            
  1694             CPosLandmark *landmark = NULL;
  1402             CPosLandmark *landmark=NULL;
  1695             landmark = iMapTileInterface->GetLandMarkDetails();
  1403             landmark=iMapTileInterface->GetLandMarkDetails();
  1696             if (NULL != landmark)
  1404             TRAP_IGNORE( UpdateDatabaseL( landmark, iMapTileRequestQueue[0]->iUId,
  1697             {
  1405                 ESourceCalendar,
  1698                 TRAP_IGNORE( landmark->SetPositionFieldL(EPositionFieldComment,
  1406                 MapChangeType( ESourceCalendar, iMapTileRequestQueue[0]->iEventType ) ) );
  1699                         iMapTileRequestQueue[0]->iAddressDetails->Des() ) );
  1407             MYLOCLOGSTRING("Geo-codinate updated to calender db");                     
  1700                 TRAP_IGNORE( UpdateDatabaseL( landmark, iMapTileRequestQueue[0]->iUId,
       
  1701                                 ESourceCalendar,
       
  1702                                 MapChangeType( ESourceCalendar, iMapTileRequestQueue[0]->iEventType ) ) );
       
  1703             }
       
  1704             MYLOCLOGSTRING("Geo-codinate updated to calender db");
  1408             break;
  1705             break;
  1409         }
  1706         }
  1410         case ESourceContactsPref:
  1707         case ESourceContactsPref:
  1411         case ESourceContactsWork:
  1708         case ESourceContactsWork:
  1412         case ESourceContactsHome:
  1709         case ESourceContactsHome:
  1413         {
  1710         {
  1414             GeocodeUpdate::updateGeocodeToContactDB(
  1711             GeocodeUpdate geocodeUpdate;
       
  1712             geocodeUpdate.updateGeocodeToContactDB(
  1415                     iMapTileRequestQueue[0]->iUId,
  1713                     iMapTileRequestQueue[0]->iUId,
  1416                     iMapTileRequestQueue[0]->iAddressType, aLatitude,
  1714                     iMapTileRequestQueue[0]->iAddressType, aLatitude,
  1417                     aLongitude);
  1715                     aLongitude);
  1418             MYLOCLOGSTRING("Geo-codinate updated to contact db");
  1716             MYLOCLOGSTRING("Geo-codinate updated to contact db");
  1419             break;
  1717             break;
  1445 
  1743 
  1446 // -----------------------------------------------------------------------------
  1744 // -----------------------------------------------------------------------------
  1447 // CMyLocationsEngine::ManipulateMapTileDataBaseL()
  1745 // CMyLocationsEngine::ManipulateMapTileDataBaseL()
  1448 // -----------------------------------------------------------------------------
  1746 // -----------------------------------------------------------------------------
  1449 //
  1747 //
  1450 void CMyLocationsEngine::ManipulateMapTileDataBaseL(TLookupItem aLookupItem)
  1748 void CMyLocationsEngine::ManipulateMapTileDataBaseL(TLookupItem& aLookupItem)
  1451 {
  1749 {
  1452     __TRACE_CALLSTACK;
  1750     __TRACE_CALLSTACK;
  1453     TBool entryAvailable=EFalse;
  1751     TBool entryAvailable=EFalse;
  1454     entryAvailable = iMaptileDatabase->FindEntryL(aLookupItem);
  1752     entryAvailable = iMaptileDatabase->FindEntryL(aLookupItem);
  1455     iMaptileDatabase->DeleteEntryL(aLookupItem);
  1753     iMaptileDatabase->DeleteEntryL(aLookupItem);
  1456     if (entryAvailable)
  1754     if (entryAvailable)
  1457     {
  1755     {
  1458         iMaptileDatabase->DeleteMapTileL(aLookupItem);
  1756         iMaptileDatabase->DeleteMapTileL(aLookupItem);
  1459     }
  1757     }            
  1460             
  1758 }
  1461 }
  1759 
  1462 //End of file
  1760 //End of file
  1463 
  1761