locationdataharvester/mylocationsengine/src/mylocationsengine.cpp
changeset 20 cd10d5b85554
parent 17 0f22fb80ebba
child 26 f3533f6eae3f
equal deleted inserted replaced
17:0f22fb80ebba 20:cd10d5b85554
    18 
    18 
    19 // INCLUDE FILES
    19 // INCLUDE FILES
    20 #include <f32file.h>
    20 #include <f32file.h>
    21 #include <calchangecallback.h> 
    21 #include <calchangecallback.h> 
    22 #include <cntitem.h>
    22 #include <cntitem.h>
    23 #include <CNTFLDST.H>
    23 #include <cntfldst.h>
    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 "mylocationsengine.h"
    29 #include "mylocationsengine.h"
    29 #include "mylocationsdefines.h"
    30 #include "mylocationsdefines.h"
    30 #include "geocodeupdate.h" //header for CGeocodeUpdate class
    31 #include "geocodeupdate.h" //header for GeocodeUpdate class
    31 //handle for CMyLocationsHistoryDbObserver class
    32 //handle for CMyLocationsHistoryDbObserver class
    32 #include "mylocationlogger.h"
    33 #include "mylocationlogger.h"
    33 #if ( defined __WINSCW__ ) || ( defined __WINS__ )
    34 #if ( defined __WINSCW__ ) || ( defined __WINS__ )
    34 _LIT ( KImageStorageDrive, "C:\\Maptile\\");
    35 _LIT ( KImageStorageDrive, "C:\\Maptile\\");
    35 #endif
    36 #endif
    36 _LIT(KFolderName,":\\MapTile\\");
    37 _LIT(KFolderName,":\\MapTile\\");
    37 const TInt KImagePathSize=36;
    38 const TInt KImagePathSize=36;
    38 const TInt KBufSize=256;
       
    39 const TInt KDefaultFilePathSize = 20;
    39 const TInt KDefaultFilePathSize = 20;
    40 
    40 
    41 // separator
    41 // separator
    42 _LIT( KSeparator, ",");
    42 _LIT( KSeparator, ",");
    43 _LIT(KContactPrefered, "Contact Prefered");
       
    44 _LIT(KContactHome, "Contact Home");
       
    45 _LIT(KContactWork, "Contact Work");
       
    46 _LIT(KPNGType, ".png");
    43 _LIT(KPNGType, ".png");
    47 _LIT(KSingleSpace, " ");
    44 _LIT(KSingleSpace, " ");
    48 
    45 
    49 // ============================ MEMBER FUNCTIONS ===============================
    46 // ============================ MEMBER FUNCTIONS ===============================
    50 
    47 
    65 void CMyLocationsEngine::ConstructL()
    62 void CMyLocationsEngine::ConstructL()
    66 {
    63 {
    67     __TRACE_CALLSTACK;
    64     __TRACE_CALLSTACK;
    68     CActiveScheduler::Add(this);
    65     CActiveScheduler::Add(this);
    69 
    66 
    70    
       
    71 
       
    72     //Connection to Landmark DB
    67     //Connection to Landmark DB
    73     iLandmarkDb = CPosLandmarkDatabase::OpenL();
    68     iLandmarkDb = CPosLandmarkDatabase::OpenL();
    74     ExecuteAndDeleteLD(iLandmarkDb->InitializeL());
    69     ExecuteAndDeleteLD(iLandmarkDb->InitializeL());
    75 
    70 
    76     MYLOCLOGSTRING("Connection to Landmark DB.");
    71     MYLOCLOGSTRING("Connection to Landmark DB.");
    94     
    89     
    95     iAddressCompare = CAddressComparision::NewL();
    90     iAddressCompare = CAddressComparision::NewL();
    96 
    91 
    97     MYLOCLOGSTRING(" start contact db observation ");
    92     MYLOCLOGSTRING(" start contact db observation ");
    98     StartContactsChangeNotifierL();
    93     StartContactsChangeNotifierL();
    99     MYLOCLOGSTRING(" start landmark db observation ");
       
   100     StartLandmarksChangeNotifier();
       
   101 
    94 
   102     //set the folder path to store maptile
    95     //set the folder path to store maptile
   103     imageFilePath.Zero();
    96     imageFilePath.Zero();
   104     SetFolderPathL();
    97     SetFolderPathL();
   105 
    98 
   106     TInt status;
    99     TInt status;
   107     iCalSession = CCalSession::NewL();
   100     iCalSession = CCalSession::NewL();
   108     NotifyChangeL(status);
   101     NotifyChangeL(status);
       
   102 
       
   103     // Start listening to landmarks db changes
       
   104     StartLandmarksChangeNotifier();
   109 
   105 
   110 }
   106 }
   111 // -----------------------------------------------------------------------------
   107 // -----------------------------------------------------------------------------
   112 // CMyLocationsEngine::SetFolderPath()
   108 // CMyLocationsEngine::SetFolderPath()
   113 // set folder path structure
   109 // set folder path structure
   205 // CMyLocationsEngine::CMyLocationsEngine()
   201 // CMyLocationsEngine::CMyLocationsEngine()
   206 // C++ default constructor can NOT contain any code, that might leave.
   202 // C++ default constructor can NOT contain any code, that might leave.
   207 // -----------------------------------------------------------------------------
   203 // -----------------------------------------------------------------------------
   208 //
   204 //
   209 CMyLocationsEngine::CMyLocationsEngine() :
   205 CMyLocationsEngine::CMyLocationsEngine() :
   210     CActive(EPriorityStandard), iCalSession(NULL), iCalView(NULL), iContactsDb(
   206             CActive(EPriorityStandard), 
   211             NULL), iContactChangeNotifier(NULL), iLandmarkDb(NULL),
   207             iCalSession(NULL), iCalView(NULL), 
       
   208 	        iContactsDb(NULL), iContactChangeNotifier(NULL), 
       
   209 			iLandmarkDb(NULL),
   212             iMapTileInterface(NULL), iMyLocationsDatabaseManager(NULL),
   210             iMapTileInterface(NULL), iMyLocationsDatabaseManager(NULL),
   213             iMaptileDatabase(NULL), iAddressCompare(NULL),
   211             iMaptileDatabase(NULL), iAddressCompare(NULL),
   214             iMaptileGeocoderPluginAvailable(EFalse),iCalenderNotification(NULL)
   212             iMaptileGeocoderPluginAvailable(EFalse),iCalenderNotification(NULL)
   215 {
   213 {
   216 
   214 
   255 void CMyLocationsEngine::NotifyChangeL(TInt &aStatus)
   253 void CMyLocationsEngine::NotifyChangeL(TInt &aStatus)
   256 {
   254 {
   257     __TRACE_CALLSTACK;
   255     __TRACE_CALLSTACK;
   258     
   256     
   259     TBufC<KDefaultFilePathSize> defaultFile = iCalSession->DefaultFileNameL();
   257     TBufC<KDefaultFilePathSize> defaultFile = iCalSession->DefaultFileNameL();
   260     TChar drive = defaultFile[0];
   258     TChar drive = defaultFile[0];    
   261     
       
   262     TRAP(aStatus, iCalSession->OpenL( defaultFile ));
   259     TRAP(aStatus, iCalSession->OpenL( defaultFile ));
   263     MYLOCLOGSTRING1("iCalSession->OpenL() status-%d",aStatus);
   260     MYLOCLOGSTRING1("iCalSession->OpenL() status-%d",aStatus);
   264     if ( KErrNone == aStatus )
   261     if ( KErrNone == aStatus )
   265     {
   262     {
   266         // create a calendar entry view with the opened session
   263         // create a calendar entry view with the opened session
   326 //
   323 //
   327 void CMyLocationsEngine::StartContactsChangeNotifierL()
   324 void CMyLocationsEngine::StartContactsChangeNotifierL()
   328 {
   325 {
   329     __TRACE_CALLSTACK;
   326     __TRACE_CALLSTACK;
   330    
   327    
   331     GeocodeUpdate::CreateContactdb();
   328     GeocodeUpdate::createContactdb();
   332     iContactsDb = CContactDatabase::OpenL();
   329     iContactsDb = CContactDatabase::OpenL();
   333     // Create CContactChangeNotifier object with 'this' object. 
   330     // Create CContactChangeNotifier object with 'this' object. 
   334     iContactChangeNotifier = CContactChangeNotifier::NewL(*iContactsDb,this);
   331     iContactChangeNotifier = CContactChangeNotifier::NewL(*iContactsDb,this);
   335 }
   332 }
   336 
   333 
   344     __TRACE_CALLSTACK;// Resume event listening
   341     __TRACE_CALLSTACK;// Resume event listening
   345     iLandmarkDb->NotifyDatabaseEvent(iLmEvent, iStatus);
   342     iLandmarkDb->NotifyDatabaseEvent(iLmEvent, iStatus);
   346     SetActive();
   343     SetActive();
   347 }
   344 }
   348 
   345 
   349 
       
   350 // -----------------------------------------------------------------------------
   346 // -----------------------------------------------------------------------------
   351 // CMyLocationsEngine::CalChangeNotification()
   347 // CMyLocationsEngine::CalChangeNotification()
   352 // Callback when there is a change in the calendar database.
   348 // Callback when there is a change in the calendar database.
   353 // -----------------------------------------------------------------------------
   349 // -----------------------------------------------------------------------------
   354 //
   350 //
   355 
   351 
   356 void CMyLocationsEngine::CalChangeNotification(
   352 void CMyLocationsEngine::CalChangeNotification(
   357         RArray<TCalChangeEntry>& aChangeItems)
   353         RArray<TCalChangeEntry>& aChangeItems)
   358 {
   354 {
   359     __TRACE_CALLSTACK;
   355     __TRACE_CALLSTACK;
   360     
   356        
   361     if(iCalenderNotification)
   357     if(iCalenderNotification)
   362     {
   358     {
   363         delete iCalenderNotification;
   359         delete iCalenderNotification;
   364         iCalenderNotification = NULL;
   360         iCalenderNotification = NULL;
   365     }
   361     }
   379             break;
   375             break;
   380         }
   376         }
   381 
   377 
   382         case EChangeModify:
   378         case EChangeModify:
   383         {
   379         {
   384 
   380             if (iMapTileRequestQueue.Count() > 0)
       
   381             {
       
   382                 if (calChangeEntry.iEntryId == iMapTileRequestQueue[0]->iUId)
       
   383                 {
       
   384                     return;
       
   385                 }
       
   386             }
   385             TLookupItem lookupItem;
   387             TLookupItem lookupItem;
   386             lookupItem.iSource = ESourceCalendar;
   388             lookupItem.iSource = ESourceCalendar;
   387             lookupItem.iUid = calChangeEntry.iEntryId;
   389             lookupItem.iUid = calChangeEntry.iEntryId;
   388             //TODO: comapare address and then delete 
   390             //TODO: comapare address and then delete 
   389             TRAP_IGNORE( iMaptileDatabase->DeleteEntryL(lookupItem) );
   391             TRAP_IGNORE( iMaptileDatabase->DeleteEntryL(lookupItem) );
   394         {
   396         {
   395             TLookupItem lookupItem;
   397             TLookupItem lookupItem;
   396             lookupItem.iSource = ESourceCalendar;
   398             lookupItem.iSource = ESourceCalendar;
   397             lookupItem.iUid = calChangeEntry.iEntryId;
   399             lookupItem.iUid = calChangeEntry.iEntryId;
   398            TRAP_IGNORE( iMaptileDatabase->DeleteEntryL(lookupItem));
   400            TRAP_IGNORE( iMaptileDatabase->DeleteEntryL(lookupItem));
       
   401            
       
   402            TRAP_IGNORE( UpdateDatabaseL( NULL, 
       
   403                               calChangeEntry.iEntryId, ESourceCalendar, EEntryDeleted ) );
   399             break;
   404             break;
   400         }
   405         }
   401         };
   406         };
   402 
   407 
   403     }
   408     }
   404 }
   409 }
   405 
   410 
       
   411 // -----------------------------------------------------------------------------
       
   412 // CMyLocationsEngine::CalenderEntryAddedL()
       
   413 // -----------------------------------------------------------------------------
       
   414 //
   406 void CMyLocationsEngine::CalenderEntryAddedL(TCalChangeEntry aCalChangeEntry)
   415 void CMyLocationsEngine::CalenderEntryAddedL(TCalChangeEntry aCalChangeEntry)
   407 {
   416 {
   408     __TRACE_CALLSTACK;
   417     __TRACE_CALLSTACK;
   409     CCalEntry* calEntry = NULL;
   418     CCalEntry* calEntry = NULL;
   410     calEntry = iCalView->FetchL(aCalChangeEntry.iEntryId);
   419     calEntry = iCalView->FetchL(aCalChangeEntry.iEntryId);
   472             {
   481             {
   473                 if (aEvent.iType == EContactDbObserverEventContactChanged)
   482                 if (aEvent.iType == EContactDbObserverEventContactChanged)
   474                 {
   483                 {
   475                     // If the contact is a modified one and it might already exist in
   484                     // If the contact is a modified one and it might already exist in
   476                     // mylocations db, so delete it
   485                     // mylocations db, so delete it
   477                     iMyLocationsDatabaseManager->UpdateDatabaseL(NULL,
   486                     UpdateDatabaseL(NULL,
   478                             aEvent.iContactId, ESourceContactsPref,
   487                             aEvent.iContactId, ESourceContactsPref,
   479                             EEntryDeleted);
   488                             EEntryDeleted);
   480                     iMyLocationsDatabaseManager->UpdateDatabaseL(NULL,
   489                     UpdateDatabaseL(NULL,
   481                             aEvent.iContactId, ESourceContactsWork,
   490                             aEvent.iContactId, ESourceContactsWork,
   482                             EEntryDeleted);
   491                             EEntryDeleted);
   483                     iMyLocationsDatabaseManager->UpdateDatabaseL(NULL,
   492                     UpdateDatabaseL(NULL,
   484                             aEvent.iContactId, ESourceContactsHome,
   493                             aEvent.iContactId, ESourceContactsHome,
   485                             EEntryDeleted);
   494                             EEntryDeleted);
   486                 }
   495                 }
   487             }
   496             }
   488             else
   497             else
   494                         ESourceContactsPref, aEvent.iType);
   503                         ESourceContactsPref, aEvent.iType);
   495 
   504 
   496                 // if home address available, update Mylocations.  
   505                 // if home address available, update Mylocations.  
   497                 if (homeAddressLm)
   506                 if (homeAddressLm)
   498                 {
   507                 {
   499                     iMyLocationsDatabaseManager->UpdateDatabaseL(homeAddressLm,
   508                     UpdateDatabaseL(homeAddressLm,
   500                             aEvent.iContactId, ESourceContactsHome, changeType);
   509                             aEvent.iContactId, ESourceContactsHome, changeType);
   501                     CleanupStack::PopAndDestroy(homeAddressLm);
   510                     CleanupStack::PopAndDestroy(homeAddressLm);
   502                 }
   511                 }
   503 
   512 
   504                 // if work address available, update Mylocations.  
   513                 // if work address available, update Mylocations.  
   505                 if (workAddressLm)
   514                 if (workAddressLm)
   506                 {
   515                 {
   507                     iMyLocationsDatabaseManager->UpdateDatabaseL(workAddressLm,
   516                     UpdateDatabaseL(workAddressLm,
   508                             aEvent.iContactId, ESourceContactsWork, changeType);
   517                             aEvent.iContactId, ESourceContactsWork, changeType);
   509                     CleanupStack::PopAndDestroy(workAddressLm);
   518                     CleanupStack::PopAndDestroy(workAddressLm);
   510                 }
   519                 }
   511 
   520 
   512                 // if prefered address available, update Mylocations.  
   521                 // if prefered address available, update Mylocations.  
   513                 if (preferedAddressLm)
   522                 if (preferedAddressLm)
   514                 {
   523                 {
   515                     iMyLocationsDatabaseManager->UpdateDatabaseL(
   524                     UpdateDatabaseL(
   516                             preferedAddressLm, aEvent.iContactId,
   525                             preferedAddressLm, aEvent.iContactId,
   517                             ESourceContactsPref, changeType);
   526                             ESourceContactsPref, changeType);
   518                     CleanupStack::PopAndDestroy(preferedAddressLm);
   527                     CleanupStack::PopAndDestroy(preferedAddressLm);
   519                 }
   528                 }
   520 
   529 
   527     else if (aEvent.iType == EContactDbObserverEventContactDeleted)
   536     else if (aEvent.iType == EContactDbObserverEventContactDeleted)
   528     {
   537     {
   529         // the contact is deleted, so delete the corresponding entries from database.
   538         // the contact is deleted, so delete the corresponding entries from database.
   530 
   539 
   531         // delete prefered address in database
   540         // delete prefered address in database
   532         iMyLocationsDatabaseManager->UpdateDatabaseL(NULL, aEvent.iContactId,
   541         UpdateDatabaseL(NULL, aEvent.iContactId,
   533                 ESourceContactsPref, EEntryDeleted);
   542                 ESourceContactsPref, EEntryDeleted);
   534 
   543 
   535         // delete work address in database
   544         // delete work address in database
   536         iMyLocationsDatabaseManager->UpdateDatabaseL(NULL, aEvent.iContactId,
   545         UpdateDatabaseL(NULL, aEvent.iContactId,
   537                 ESourceContactsWork, EEntryDeleted);
   546                 ESourceContactsWork, EEntryDeleted);
   538 
   547 
   539         // delete home address in database
   548         // delete home address in database
   540         iMyLocationsDatabaseManager->UpdateDatabaseL(NULL, aEvent.iContactId,
   549         UpdateDatabaseL(NULL, aEvent.iContactId,
   541                 ESourceContactsHome, EEntryDeleted);
   550                 ESourceContactsHome, EEntryDeleted);
   542     }
   551     }
   543 }
   552 }
   544 
   553 
   545 // -----------------------------------------------------------------------------
   554 // -----------------------------------------------------------------------------
   552 {
   561 {
   553     __TRACE_CALLSTACK;
   562     __TRACE_CALLSTACK;
   554     TLookupItem lookupItem;
   563     TLookupItem lookupItem;
   555     lookupItem.iUid = aEvent.iContactId;
   564     lookupItem.iUid = aEvent.iContactId;
   556     // If contact is deleted delete from mylocations db
   565     // If contact is deleted delete from mylocations db
   557     /*    if (aEvent.iType == EContactDbObserverEventContactDeleted)
   566         if (aEvent.iType == EContactDbObserverEventContactDeleted)
   558      {
   567      {
   559      MYLOCLOGSTRING("EContactDbObserverEventContactDeleted" );
   568         lookupItem.iSource = ESourceContactsPref;
   560      // delete prefered address in database
   569         iMaptileDatabase->DeleteEntryL(lookupItem);
   561      lookupItem.iSource = ESourceContactsPref;
   570 
   562      FindEntryAndDeleteL(lookupItem);
   571         lookupItem.iSource = ESourceContactsWork;
   563 
   572         iMaptileDatabase->DeleteEntryL(lookupItem);
   564      lookupItem.iSource = ESourceContactsWork;
   573 
   565      FindEntryAndDeleteL(lookupItem);
   574         lookupItem.iSource = ESourceContactsHome;
   566 
   575         iMaptileDatabase->DeleteEntryL(lookupItem);
   567      lookupItem.iSource = ESourceContactsHome;
   576 
   568      FindEntryAndDeleteL(lookupItem);
   577         MYLOCLOGSTRING("EContactDbObserverEventContactDeleted ");
   569      }*/
   578         return;
       
   579      }
   570 
   580 
   571     //Get the contact item
   581     //Get the contact item
   572     iEventType = aEvent.iType;
   582     iEventType = aEvent.iType;
   573     CContactItem* contactItem = iContactsDb->ReadContactL(aEvent.iContactId);
   583     CContactItem* contactItem = iContactsDb->ReadContactL(aEvent.iContactId);
   574     CleanupStack::PushL(contactItem);
   584     CleanupStack::PushL(contactItem);
   707         {
   717         {
   708             iMaptileDatabase->DeleteEntryL(lookupItem);
   718             iMaptileDatabase->DeleteEntryL(lookupItem);
   709         }
   719         }
   710         // }
   720         // }
   711         break;
   721         break;
   712     }
   722     }    
   713     case EContactDbObserverEventContactDeleted:
       
   714     {
       
   715 
       
   716         lookupItem.iSource = ESourceContactsPref;
       
   717         iMaptileDatabase->DeleteEntryL(lookupItem);
       
   718 
       
   719         lookupItem.iSource = ESourceContactsWork;
       
   720         iMaptileDatabase->DeleteEntryL(lookupItem);
       
   721 
       
   722         lookupItem.iSource = ESourceContactsHome;
       
   723         iMaptileDatabase->DeleteEntryL(lookupItem);
       
   724 
       
   725         MYLOCLOGSTRING("EContactDbObserverEventContactDeleted ");
       
   726         /*             // the contact is deleted, so delete the corresponding entries from database.
       
   727          TLookupItem lookupItem;
       
   728          lookupItem.iUid = aEvent.iContactId;
       
   729          iMaptileDatabase->DeleteEntryL(lookupItem);*/
       
   730         break;
       
   731     }
       
   732     case EContactDbObserverEventContactAdded:
   723     case EContactDbObserverEventContactAdded:
   733     {
   724     {
   734         MYLOCLOGSTRING("EContactDbObserverEventContactAdded" );
   725         MYLOCLOGSTRING("EContactDbObserverEventContactAdded" );
   735         if (preferedAddressLm)
   726         if (preferedAddressLm)
   736         {
   727         {
   848    
   839    
   849 }
   840 }
   850 TInt CMyLocationsEngine::RequestExecute( CMapTileRequest* aMapTileRequest)
   841 TInt CMyLocationsEngine::RequestExecute( CMapTileRequest* aMapTileRequest)
   851 {
   842 {
   852     __TRACE_CALLSTACK;
   843     __TRACE_CALLSTACK;
   853     TInt errorCode;
   844     TInt errorCode = KErrNone;
   854     switch (aMapTileRequest->iAddressType)
   845     switch (aMapTileRequest->iAddressType)
   855     {
   846     {
   856         case ESourceCalendar:
   847         case ESourceCalendar:
   857         {
   848         {
   858             TRAP(errorCode,iMapTileInterface->GetMapTileImageL(aMapTileRequest->iAddressDetails->Des(),
   849             TRAP(errorCode,iMapTileInterface->GetMapTileImageL(aMapTileRequest->iAddressDetails->Des(),
   865         {
   856         {
   866             TRAP(errorCode, iMapTileInterface->GetMapTileImageL(aMapTileRequest->iLandmarkInfo,
   857             TRAP(errorCode, iMapTileInterface->GetMapTileImageL(aMapTileRequest->iLandmarkInfo,
   867                             aMapTileRequest->iImagePath, this));            
   858                             aMapTileRequest->iImagePath, this));            
   868             break;
   859             break;
   869         }
   860         }
       
   861         default:
       
   862             break;
   870     };  
   863     };  
   871 
   864 
   872     return errorCode;
   865     return errorCode;
   873 }
   866 }
   874  
   867  
  1047                                         aContactItem->CardFields()[sNameInd].TextStorage()->Text();
  1040                                         aContactItem->CardFields()[sNameInd].TextStorage()->Text();
  1048                         sName1.Append(sName);
  1041                         sName1.Append(sName);
  1049                     }
  1042                     }
  1050 
  1043 
  1051                     TRAP_IGNORE( landmark->SetLandmarkNameL( sName1 ) );
  1044                     TRAP_IGNORE( landmark->SetLandmarkNameL( sName1 ) );
  1052 
       
  1053                     if (aAddressType == EAddressPref) // default/prefered address
       
  1054                     {
       
  1055                         TRAP_IGNORE( landmark->SetLandmarkDescriptionL(KContactPrefered) );
       
  1056                     }
       
  1057                     else if (aAddressType == EAddressWork) // work address
       
  1058                     {
       
  1059                         TRAP_IGNORE( landmark->SetLandmarkDescriptionL(KContactWork) );
       
  1060                     }
       
  1061                     else // home address
       
  1062                     {
       
  1063                         TRAP_IGNORE( landmark->SetLandmarkDescriptionL(KContactHome) );
       
  1064                     }
       
  1065 
  1045 
  1066                     // Set the street
  1046                     // Set the street
  1067                     TInt adrId = FindContactsField(aContactItem, aAddressType,
  1047                     TInt adrId = FindContactsField(aContactItem, aAddressType,
  1068                             KUidContactFieldVCardMapADR);
  1048                             KUidContactFieldVCardMapADR);
  1069                     if (adrId != KErrNotFound)
  1049                     if (adrId != KErrNotFound)
  1182     __TRACE_CALLSTACK;// return value
  1162     __TRACE_CALLSTACK;// return value
  1183     TEntryChangeType retVal = EEntryUnknown;
  1163     TEntryChangeType retVal = EEntryUnknown;
  1184 
  1164 
  1185     switch (aSrcType)
  1165     switch (aSrcType)
  1186     {
  1166     {
       
  1167     // if source type is calendar
       
  1168     case ESourceCalendar:
       
  1169     {
       
  1170         switch( aChangeType )
       
  1171             {
       
  1172             case EChangeAdd:
       
  1173                 retVal = EEntryAdded;
       
  1174                 break;
       
  1175             case EChangeDelete:
       
  1176                 retVal =  EEntryDeleted;
       
  1177                 break;
       
  1178             case EChangeModify:
       
  1179                 retVal =  EEntryModified;
       
  1180                 break;
       
  1181             }
       
  1182         break;
       
  1183     }
  1187     // if source type is contacts
  1184     // if source type is contacts
  1188     case ESourceContactsPref:
  1185     case ESourceContactsPref:
  1189     case ESourceContactsWork:
  1186     case ESourceContactsWork:
  1190     case ESourceContactsHome:
  1187     case ESourceContactsHome:
  1191     {
  1188     {
  1234     }
  1231     }
  1235     return retVal;
  1232     return retVal;
  1236 }
  1233 }
  1237 
  1234 
  1238 // -----------------------------------------------------------------------------
  1235 // -----------------------------------------------------------------------------
  1239 // CMyLocationsEngine::MyLocationsDbManager()
       
  1240 // Gets handle to mylocations database manager.
       
  1241 // -----------------------------------------------------------------------------
       
  1242 //
       
  1243 CMyLocationsDatabaseManager& CMyLocationsEngine::MyLocationsDbManager()
       
  1244 {
       
  1245     __TRACE_CALLSTACK;
       
  1246     return *iMyLocationsDatabaseManager;
       
  1247 }
       
  1248 // -----------------------------------------------------------------------------
       
  1249 // CMyLocationsEngine::RunL()
  1236 // CMyLocationsEngine::RunL()
  1250 // Handles active object's request completion event.
  1237 // Handles active object's request completion event.
  1251 // -----------------------------------------------------------------------------
  1238 // -----------------------------------------------------------------------------
  1252 //
  1239 //
  1253 void CMyLocationsEngine::RunL()
  1240 void CMyLocationsEngine::RunL()
  1254 {
  1241 {
  1255     __TRACE_CALLSTACK;
  1242     __TRACE_CALLSTACK;
  1256     switch (iLmEvent.iEventType)
  1243     switch (iLmEvent.iEventType)
  1257     {
  1244     {
  1258     case EPosLmEventLandmarkCreated:
  1245         case EPosLmEventLandmarkCreated:
  1259     case EPosLmEventLandmarkUpdated:
  1246         case EPosLmEventLandmarkUpdated:
  1260     {
  1247         {
  1261         TBuf<KMaxAddressLength> lmAddress;
  1248             CPosLandmark* readLandmark = iLandmarkDb->ReadLandmarkLC(
  1262         CPosLandmark* readLandmark = iLandmarkDb->ReadLandmarkLC(
  1249                     iLmEvent.iLandmarkItemId);
  1263                 iLmEvent.iLandmarkItemId);
  1250     
  1264 
  1251             if (readLandmark)
  1265         if (readLandmark)
  1252             {    
  1266         {
  1253                 // update the entry in database.
  1267             iMyLocationsDatabaseManager->GetLandmarkFullAddress(lmAddress,
  1254                 UpdateDatabaseL( readLandmark,
  1268                     readLandmark);
  1255                         iLmEvent.iLandmarkItemId, ESourceLandmarks, MapChangeType(
  1269 
  1256                                 ESourceLandmarks, iLmEvent.iEventType ) );
  1270             CPosLandmark* landmark = CPosLandmark::NewL();
  1257     
  1271             CleanupStack::PushL(landmark);
  1258                 CleanupStack::PopAndDestroy(readLandmark);
  1272 
  1259             }
  1273             TRAP_IGNORE( landmark->SetLandmarkNameL( lmAddress ));
  1260         }
  1274 
       
  1275             TPtrC iconFileName;
       
  1276             TInt iconIndex;
       
  1277             TInt iconMaskIndex;
       
  1278             TInt err = readLandmark->GetIcon(iconFileName, iconIndex,
       
  1279                     iconMaskIndex);
       
  1280 
       
  1281             if (err == KErrNone)
       
  1282             {
       
  1283                 TRAP_IGNORE( landmark->SetIconL(
       
  1284                                 iconFileName, iconIndex, iconMaskIndex ) );
       
  1285             }
       
  1286 
       
  1287             // update the entry in mylocations database.
       
  1288             iMyLocationsDatabaseManager->UpdateDatabaseL(landmark,
       
  1289                     iLmEvent.iLandmarkItemId, ESourceLandmarks, MapChangeType(
       
  1290                             ESourceLandmarks, iLmEvent.iEventType));
       
  1291 
       
  1292             CleanupStack::PopAndDestroy(landmark);
       
  1293             CleanupStack::PopAndDestroy(readLandmark);
       
  1294         }
       
  1295     }
       
  1296         break;
  1261         break;
  1297     case EPosLmEventLandmarkDeleted:
  1262         case EPosLmEventLandmarkDeleted:
  1298     {
  1263         {
  1299         // delete the corresponding entries in mylocations database.
  1264             // delete the corresponding entries in mylocations database.
  1300         iMyLocationsDatabaseManager->UpdateDatabaseL(NULL,
  1265             UpdateDatabaseL(NULL,
  1301                 iLmEvent.iLandmarkItemId, ESourceLandmarks, EEntryDeleted);
  1266                     iLmEvent.iLandmarkItemId, ESourceLandmarks, EEntryDeleted);
  1302     }
  1267         }
  1303         break;
  1268         break;
  1304 
       
  1305     case EPosLmEventCategoryCreated:
       
  1306     {
       
  1307         // delete the corresponding entries in mylocations database.
       
  1308         iMyLocationsDatabaseManager->UpdateDatabaseL(NULL,
       
  1309                 iLmEvent.iLandmarkItemId, ESourceLandmarksCategory,
       
  1310                 MapChangeType(ESourceLandmarksCategory, iLmEvent.iEventType));
       
  1311     }
       
  1312         break;
       
  1313 
       
  1314 
  1269 
  1315     }
  1270     }
  1316 
  1271 
  1317     // start the change notifier again;
  1272     // start the change notifier again;
  1318     StartLandmarksChangeNotifier();
  1273     StartLandmarksChangeNotifier();
  1319 
  1274 
  1320 }
  1275 }
  1321 
       
  1322 // -----------------------------------------------------------------------------
  1276 // -----------------------------------------------------------------------------
  1323 // CMyLocationsEngine::DoCancel()
  1277 // CMyLocationsEngine::DoCancel()
  1324 // Implements cancellation of an outstanding request.
  1278 // Implements cancellation of an outstanding request.
  1325 // -----------------------------------------------------------------------------
  1279 // -----------------------------------------------------------------------------
  1326 //
  1280 //
  1327 void CMyLocationsEngine::DoCancel()
  1281 void CMyLocationsEngine::DoCancel()
  1328 {
  1282 {
  1329     __TRACE_CALLSTACK;
  1283     __TRACE_CALLSTACK;
  1330     iLandmarkDb->CancelNotifyDatabaseEvent();
  1284     iLandmarkDb->CancelNotifyDatabaseEvent();
  1331 }
       
  1332 
       
  1333 // -----------------------------------------------------------------------------
       
  1334 // CMyLocationsEngine::RunError()
       
  1335 // Implements cancellation of an outstanding request.
       
  1336 // -----------------------------------------------------------------------------
       
  1337 //
       
  1338 TInt CMyLocationsEngine::RunError(TInt /*aError*/)
       
  1339 {
       
  1340     __TRACE_CALLSTACK;
       
  1341     return KErrNone;
       
  1342 }
  1285 }
  1343 
  1286 
  1344 // -----------------------------------------------------------------------------
  1287 // -----------------------------------------------------------------------------
  1345 // CMyLocationsEngine::MapTilefetchingCompleted()
  1288 // CMyLocationsEngine::MapTilefetchingCompleted()
  1346 // Handles the maptile fetching completion event and updates the maptile lookup db.
  1289 // Handles the maptile fetching completion event and updates the maptile lookup db.
  1423             == EChangeAdd)
  1366             == EChangeAdd)
  1424     {
  1367     {
  1425         iMaptileDatabase->CreateEntryL(aLookupItem);
  1368         iMaptileDatabase->CreateEntryL(aLookupItem);
  1426 
  1369 
  1427     }
  1370     }
       
  1371     iMyLocationsDatabaseManager->UpdateMapTilePath( aLookupItem.iUid, aLookupItem.iSource, 
       
  1372                                             aLookupItem.iFilePath );    
  1428 }
  1373 }
  1429 
  1374 
  1430 // -----------------------------------------------------------------------------
  1375 // -----------------------------------------------------------------------------
  1431 // CMyLocationsEngine::RestGeoCodeCompleted()
  1376 // CMyLocationsEngine::RestGeoCodeCompleted()
  1432 // observed when rest geo codeing completed.
  1377 // observed when rest geo codeing completed.
  1440     MYLOCLOGSTRING1("No. of iMapTileRequestQueue - %d",iMapTileRequestQueue.Count());
  1385     MYLOCLOGSTRING1("No. of iMapTileRequestQueue - %d",iMapTileRequestQueue.Count());
  1441     if (iMapTileRequestQueue.Count() > 0)
  1386     if (iMapTileRequestQueue.Count() > 0)
  1442     {
  1387     {
  1443         switch (iMapTileRequestQueue[0]->iAddressType)
  1388         switch (iMapTileRequestQueue[0]->iAddressType)
  1444         {
  1389         {
  1445             /*//TODO:
  1390         //TODO:
  1446             case ESourceCalendar:
  1391         case ESourceCalendar:
  1447             {
  1392         {
  1448                 break;
  1393            
  1449             }*/
  1394             CPosLandmark *landmark=NULL;
  1450             case ESourceContactsPref:
  1395             landmark=iMapTileInterface->GetLandMarkDetails();
  1451             case ESourceContactsWork:
  1396             TRAP_IGNORE( UpdateDatabaseL( landmark, iMapTileRequestQueue[0]->iUId,
  1452             case ESourceContactsHome:
  1397                 ESourceCalendar,
  1453             {
  1398                 MapChangeType( ESourceCalendar, iMapTileRequestQueue[0]->iEventType ) ) );
  1454                 GeocodeUpdate::UpDate(iMapTileRequestQueue[0]->iUId,
  1399             MYLOCLOGSTRING("Geo-codinate updated to calender db");                     
  1455                         iMapTileRequestQueue[0]->iAddressType, aLatitude,
  1400             break;
  1456                         aLongitude);
  1401         }
  1457                 MYLOCLOGSTRING("Geo code updated into contact db");
  1402         case ESourceContactsPref:
  1458                 break;
  1403         case ESourceContactsWork:
  1459             }
  1404         case ESourceContactsHome:
       
  1405         {
       
  1406             GeocodeUpdate::updateGeocodeToContactDB(
       
  1407                     iMapTileRequestQueue[0]->iUId,
       
  1408                     iMapTileRequestQueue[0]->iAddressType, aLatitude,
       
  1409                     aLongitude);
       
  1410             MYLOCLOGSTRING("Geo-codinate updated to contact db");
       
  1411             break;
       
  1412         }
  1460         };
  1413         };
  1461 
  1414 
  1462         
  1415         
  1463     }
  1416     }
  1464 
  1417 
  1465 }
  1418 }
  1466 
  1419 
       
  1420 // -----------------------------------------------------------------------------
       
  1421 // CMyLocationsEngine::UpdateDatabaseL()
       
  1422 // -----------------------------------------------------------------------------
       
  1423 //
       
  1424 void CMyLocationsEngine::UpdateDatabaseL( CPosLandmark* aLandmark, const TUint32 aUid, 
       
  1425         const TUint32 aSourceType, const TEntryChangeType aChangeType )
       
  1426 {
       
  1427     __TRACE_CALLSTACK;
       
  1428     Cancel();
       
  1429     iMyLocationsDatabaseManager->UpdateDatabaseL( aLandmark, aUid, 
       
  1430         aSourceType, aChangeType );
       
  1431     if( aSourceType != ESourceLandmarks )
       
  1432     {
       
  1433         StartLandmarksChangeNotifier();
       
  1434     }
       
  1435     
       
  1436 }
       
  1437 
  1467 //End of file
  1438 //End of file
       
  1439