locationdataharvester/mylocationsengine/src/mylocationsengine.cpp
changeset 31 8db05346071b
parent 30 96df3ab41000
child 35 59575560d1e6
equal deleted inserted replaced
30:96df3ab41000 31:8db05346071b
    15 *              and maptile service.
    15 *              and maptile service.
    16 *
    16 *
    17 */
    17 */
    18 
    18 
    19 // INCLUDE FILES
    19 // INCLUDE FILES
       
    20 #include <QFile>
    20 #include <f32file.h>
    21 #include <f32file.h>
    21 #include <calchangecallback.h> 
    22 #include <calchangecallback.h> 
    22 #include <cntitem.h>
    23 #include <cntitem.h>
    23 #include <cntfldst.h>
    24 #include <cntfldst.h>
    24 #include <EPos_CPosLmDatabaseManager.h>
    25 #include <EPos_CPosLmDatabaseManager.h>
    28 #include <locationservicedefines.h>
    29 #include <locationservicedefines.h>
    29 #include <e32property.h>
    30 #include <e32property.h>
    30 #include "contactsubscriber.h"
    31 #include "contactsubscriber.h"
    31 #include "calendarsubscriber.h"
    32 #include "calendarsubscriber.h"
    32 #include "mylocationsengine.h"
    33 #include "mylocationsengine.h"
    33 #include "mylocationsdefines.h"
       
    34 #include "geocodeupdate.h" //header for GeocodeUpdate class
    34 #include "geocodeupdate.h" //header for GeocodeUpdate class
    35 //handle for CMyLocationsHistoryDbObserver class
    35 //handle for CMyLocationsHistoryDbObserver class
    36 #include "mylocationlogger.h"
    36 #include "mylocationlogger.h"
    37 #if ( defined __WINSCW__ ) || ( defined __WINS__ )
    37 #if ( defined __WINSCW__ ) || ( defined __WINS__ )
    38 _LIT ( KImageStorageDrive, "C:\\MapTile\\");
    38 _LIT ( KImageStorageDrive, "C:\\MapTile\\");
    89     //Maptile Db instance
    89     //Maptile Db instance
    90     iMaptileDatabase = CLookupMapTileDatabase::NewL(KMapTileLookupDatabaseName);
    90     iMaptileDatabase = CLookupMapTileDatabase::NewL(KMapTileLookupDatabaseName);
    91 
    91 
    92     MYLOCLOGSTRING("Maptile Db instance created ");
    92     MYLOCLOGSTRING("Maptile Db instance created ");
    93 	
    93 	
       
    94     iGeocodeUpdate = new GeocodeUpdate();
    94     iMyLocationThreeAMTimer = CLocationGeoTagTimerAO::NewL(*this);
    95     iMyLocationThreeAMTimer = CLocationGeoTagTimerAO::NewL(*this);
    95   
    96   
    96     iMyLocationThreeAMTimer->StartTimer();
    97     iMyLocationThreeAMTimer->StartTimer();
    97     
    98     
    98     MYLOCLOGSTRING(" iMyLocationThreeAMTimer = CLocationGeoTagTimerAO::NewL(this)");
    99     MYLOCLOGSTRING(" iMyLocationThreeAMTimer = CLocationGeoTagTimerAO::NewL(this)");
   231             iMaptileGeocoderPluginAvailable(EFalse),
   232             iMaptileGeocoderPluginAvailable(EFalse),
   232             iCalenderNotification(NULL),
   233             iCalenderNotification(NULL),
   233             iContactManager(NULL),
   234             iContactManager(NULL),
   234             iContactSubscriber(NULL),
   235             iContactSubscriber(NULL),
   235             iCalendarSubscriber(NULL),
   236             iCalendarSubscriber(NULL),
       
   237             iGeocodeUpdate(NULL),
   236             iLastContactId( -1 ) ,
   238             iLastContactId( -1 ) ,
   237             iLastCalendarId( 0 )
   239             iLastCalendarId( 0 )
   238 {
   240 {
   239 
   241 
   240 }
   242 }
   274     
   276     
   275     delete iContactSubscriber;
   277     delete iContactSubscriber;
   276 
   278 
   277     delete iCalendarSubscriber;
   279     delete iCalendarSubscriber;
   278     
   280     
   279 	//free the allocated memory
   281     delete iGeocodeUpdate;
       
   282     
   280     for( TInt index = 0; index < iAddressInfo.Count(); index++ )
   283     for( TInt index = 0; index < iAddressInfo.Count(); index++ )
   281     {
   284     {
   282         delete iAddressInfo[index];
   285         delete iAddressInfo[index];
   283         iAddressInfo.Remove(index);
   286         iAddressInfo.Remove(index);
   284         iAddressInfo.Compress();
   287         iAddressInfo.Compress();
   497 //
   500 //
   498 void CMyLocationsEngine::StartContactsChangeNotifierL()
   501 void CMyLocationsEngine::StartContactsChangeNotifierL()
   499 {
   502 {
   500     __TRACE_CALLSTACK;
   503     __TRACE_CALLSTACK;
   501    
   504    
   502     GeocodeUpdate geocodeUpdate;
   505     iGeocodeUpdate->createContactdb();
   503     geocodeUpdate.createContactdb();
       
   504     iContactsDb = CContactDatabase::OpenL();
   506     iContactsDb = CContactDatabase::OpenL();
   505     // Create CContactChangeNotifier object with 'this' object. 
   507     // Create CContactChangeNotifier object with 'this' object. 
   506     iContactChangeNotifier = CContactChangeNotifier::NewL(*iContactsDb,this);
   508     iContactChangeNotifier = CContactChangeNotifier::NewL(*iContactsDb,this);
   507 }
   509 }
   508 
   510 
   618     lookupItem.iSource = ESourceCalendar;
   620     lookupItem.iSource = ESourceCalendar;
   619     lookupItem.iUid = entryId;
   621     lookupItem.iUid = entryId;
   620     CCalEntry* calEntry = NULL;
   622     CCalEntry* calEntry = NULL;
   621     calEntry = iCalView->FetchL(entryId);
   623     calEntry = iCalView->FetchL(entryId);
   622     CleanupStack::PushL(calEntry);
   624     CleanupStack::PushL(calEntry);
   623     TPtrC address(calEntry->LocationL());
   625     if(iGeocodeUpdate->isGeocodeNotAvailable(entryId))
   624     if (iMyLocationsDatabaseManager->CheckIfAddressChanged(address, entryId,
   626     {        
   625             ESourceCalendar))
   627         TPtrC address(calEntry->LocationL());
   626     {
   628         if (iMyLocationsDatabaseManager->CheckIfAddressChanged(address, entryId,
   627         lookupItem.iFilePath.Zero();
   629                 ESourceCalendar))
   628         lookupItem.iFetchingStatus = EMapTileFetchingInProgress;
   630         {
   629         TRAP_IGNORE( iMaptileDatabase->ReSetEntryL(lookupItem) );
   631             lookupItem.iFilePath.Zero();
   630         if (address.Length() > 0)
   632             lookupItem.iFetchingStatus = EMapTileFetchingInProgress;
   631         {
   633             TRAP_IGNORE( iMaptileDatabase->ReSetEntryL(lookupItem) );
   632             RequestMapTileImageL(address, ESourceCalendar, entryId , EChangeModify);
   634             if (address.Length() > 0)
   633         }
   635             {
   634         else
   636                 RequestMapTileImageL(address, ESourceCalendar, entryId , EChangeModify);
   635         {
   637             }
   636             UpdateDatabaseL(NULL, entryId, ESourceCalendar, EEntryDeleted);
   638             else
   637         }
   639             {
   638         if ( lookupItem.iFilePath.Length() > 0 )
   640                 UpdateDatabaseL(NULL, entryId, ESourceCalendar, EEntryDeleted);
   639         {
   641             }
   640             iMaptileDatabase->DeleteMapTileL(lookupItem);
   642             if ( lookupItem.iFilePath.Length() > 0 )
   641         }
   643             {
   642 
   644                 iMaptileDatabase->DeleteMapTileL(lookupItem);
   643     }
   645             }
       
   646     
       
   647         }        
       
   648     }   
   644     CleanupStack::PopAndDestroy(calEntry);
   649     CleanupStack::PopAndDestroy(calEntry);
   645 }
   650 }
   646 
   651 
   647 // -----------------------------------------------------------------------------
   652 // -----------------------------------------------------------------------------
   648 // CMyLocationsEngine::HandleDatabaseEventL()
   653 // CMyLocationsEngine::HandleDatabaseEventL()
   656     //Forward the event for maptile fetching only if maptile plugin available
   661     //Forward the event for maptile fetching only if maptile plugin available
   657     if( iMaptileGeocoderPluginAvailable )
   662     if( iMaptileGeocoderPluginAvailable )
   658     {
   663     {
   659         TriggerMaptileRequestL(aEvent);
   664         TriggerMaptileRequestL(aEvent);
   660     }
   665     }
   661     
   666 }
   662     HandlelandmarkDatabaseL(aEvent);
   667 
   663 }
       
   664 
       
   665 // -----------------------------------------------------------------------------
       
   666 // CMyLocationsEngine::HandlelandmarkDatabaseL()
       
   667 // Process the contact database event and updates the landmark database
       
   668 // -----------------------------------------------------------------------------
       
   669 //
       
   670 void CMyLocationsEngine::HandlelandmarkDatabaseL(
       
   671         TContactDbObserverEvent& aEvent)
       
   672 {
       
   673     __TRACE_CALLSTACK;// If contact is modified or added, update the mylocations db
       
   674     if (aEvent.iType == EContactDbObserverEventContactChanged || aEvent.iType
       
   675             == EContactDbObserverEventContactAdded)
       
   676     {
       
   677        
       
   678         CPosLandmark *preferedAddressLm = NULL;
       
   679         CPosLandmark *workAddressLm = NULL;
       
   680         CPosLandmark *homeAddressLm = NULL;
       
   681         
       
   682         QContact contactInfo = iContactManager->contact( aEvent.iContactId );
       
   683          
       
   684         //Get the contact name details
       
   685         QContactName name = contactInfo.detail( QContactName::DefinitionName );
       
   686         QString firstName = name.firstName();
       
   687         QString lastName = name.lastName();
       
   688         TPtrC16 tempPtr1(reinterpret_cast<const TUint16*>(firstName.utf16()));
       
   689         TPtrC16 tempPtr2( reinterpret_cast <const TUint16*>(lastName.utf16()));
       
   690         
       
   691         TBuf<KBufSize> landmarkName;
       
   692         landmarkName.Append( tempPtr1 );
       
   693         landmarkName.Append( tempPtr2 );
       
   694         
       
   695         TInt itemCount = 0;
       
   696         
       
   697   
       
   698         double longitude, latitude;
       
   699         
       
   700         foreach ( QContactAddress address, contactInfo.details<QContactAddress>() )
       
   701         {
       
   702           QStringList context = address.contexts();
       
   703           if ( context.isEmpty() ) // no context
       
   704           {
       
   705               //check whether geocordinate available
       
   706               TBool geoField = IsGeoCoordinateAvailable( 
       
   707                        contactInfo, NULL , latitude, longitude );
       
   708               if( geoField )
       
   709               {
       
   710                   // Get the default/prefered address details
       
   711                   preferedAddressLm = GetContactAddressDetailsLC( address );
       
   712                   TLocality loc( TCoordinate( latitude, longitude ), 0 );
       
   713                   // Fill the location details into the landmark object
       
   714                   preferedAddressLm->SetPositionL(loc);
       
   715                   preferedAddressLm->SetLandmarkNameL( landmarkName );
       
   716                   itemCount++;
       
   717 
       
   718               }
       
   719           }
       
   720           else if (context.first() == QContactAddress::ContextHome  )
       
   721           {
       
   722               //check whether geocordinate available
       
   723               TBool geoField = IsGeoCoordinateAvailable( 
       
   724                                contactInfo, QContactAddress::ContextHome, latitude, longitude );
       
   725               if( geoField )
       
   726               {
       
   727                   // Get the home address details
       
   728                   homeAddressLm = GetContactAddressDetailsLC( address );
       
   729                   TLocality loc(TCoordinate( latitude,longitude ), 0);
       
   730                   homeAddressLm->SetPositionL(loc);
       
   731                   homeAddressLm->SetLandmarkNameL( landmarkName );
       
   732                   itemCount++;
       
   733               }
       
   734           }
       
   735           else if (context.first() == QContactAddress::ContextWork )
       
   736           {
       
   737               //check whether geocordinate available
       
   738               TBool geoField = IsGeoCoordinateAvailable( 
       
   739                         contactInfo, QContactAddress::ContextWork, latitude, longitude );
       
   740               if( geoField )
       
   741               {
       
   742                   // Get the work address details
       
   743                   workAddressLm = GetContactAddressDetailsLC( address );
       
   744                   TLocality loc(TCoordinate( latitude, longitude ), 0);
       
   745                   // Fill the location details into the landmark object
       
   746                   workAddressLm->SetPositionL(loc);
       
   747                   workAddressLm->SetLandmarkNameL( landmarkName );
       
   748                   itemCount++;
       
   749               }
       
   750         
       
   751           }
       
   752         }
       
   753 
       
   754         // if the contact item has no validated address (preferef, home or work)
       
   755         if (!preferedAddressLm && !workAddressLm && !homeAddressLm)
       
   756         {
       
   757             if (aEvent.iType == EContactDbObserverEventContactChanged)
       
   758             {
       
   759                 // If the contact is a modified one and it might already exist in
       
   760                 // mylocations db, so delete it
       
   761                 UpdateDatabaseL(NULL,
       
   762                         aEvent.iContactId, ESourceContactsPref,
       
   763                         EEntryDeleted);
       
   764                 
       
   765                 UpdateDatabaseL(NULL,
       
   766                                  aEvent.iContactId, ESourceContactsHome,
       
   767                                  EEntryDeleted);
       
   768                   
       
   769                 UpdateDatabaseL(NULL,
       
   770                         aEvent.iContactId, ESourceContactsWork,
       
   771                         EEntryDeleted);
       
   772             }
       
   773         }
       
   774         else
       
   775         {
       
   776             // There is atleast one valid address present.       
       
   777 
       
   778             // Get the TEntryChangeType for contacts.
       
   779             TEntryChangeType changeType = MapChangeType(
       
   780                     ESourceContactsPref, aEvent.iType);
       
   781 
       
   782             // if prefered address available, update Mylocations.  
       
   783             if (preferedAddressLm)
       
   784             {
       
   785                 UpdateDatabaseL(
       
   786                         preferedAddressLm, aEvent.iContactId,
       
   787                         ESourceContactsPref, changeType);
       
   788             }
       
   789             // if home address available, update Mylocations.  
       
   790             if (homeAddressLm)
       
   791             {
       
   792                 UpdateDatabaseL(homeAddressLm,
       
   793                         aEvent.iContactId, ESourceContactsHome, changeType);
       
   794             }
       
   795 
       
   796             // if work address available, update Mylocations.  
       
   797             if (workAddressLm)
       
   798             {
       
   799                 UpdateDatabaseL(workAddressLm,
       
   800                         aEvent.iContactId, ESourceContactsWork, changeType);
       
   801             }
       
   802 
       
   803             CleanupStack::PopAndDestroy( itemCount );
       
   804         }  
       
   805 
       
   806     }
       
   807     else if (aEvent.iType == EContactDbObserverEventContactDeleted)
       
   808     {
       
   809         // the contact is deleted, so delete the corresponding entries from database.
       
   810 
       
   811         // delete prefered address in database
       
   812         UpdateDatabaseL(NULL, aEvent.iContactId,
       
   813                 ESourceContactsPref, EEntryDeleted);
       
   814 
       
   815         // delete work address in database
       
   816         UpdateDatabaseL(NULL, aEvent.iContactId,
       
   817                 ESourceContactsWork, EEntryDeleted);
       
   818 
       
   819         // delete home address in database
       
   820         UpdateDatabaseL(NULL, aEvent.iContactId,
       
   821                 ESourceContactsHome, EEntryDeleted);
       
   822     }
       
   823 }
       
   824 
   668 
   825 // -----------------------------------------------------------------------------
   669 // -----------------------------------------------------------------------------
   826 // CMyLocationsEngine::TriggerMaptileRequestL()
   670 // CMyLocationsEngine::TriggerMaptileRequestL()
   827 // Process the contact address information for fetching maptile.
   671 // Process the contact address information for fetching maptile.
   828 // -----------------------------------------------------------------------------
   672 // -----------------------------------------------------------------------------
   833     TLookupItem lookupItem;      
   677     TLookupItem lookupItem;      
   834     lookupItem.iUid = aEvent.iContactId;
   678     lookupItem.iUid = aEvent.iContactId;
   835     // If contact is deleted delete from mylocations db
   679     // If contact is deleted delete from mylocations db
   836     if (aEvent.iType == EContactDbObserverEventContactDeleted)
   680     if (aEvent.iType == EContactDbObserverEventContactDeleted)
   837     {        
   681     {        
       
   682         //Delete the entries from maptile database
   838         lookupItem.iSource = ESourceContactsPref;
   683         lookupItem.iSource = ESourceContactsPref;
   839         TRAP_IGNORE( ManipulateMapTileDataBaseL(lookupItem));
   684         TRAP_IGNORE( ManipulateMapTileDataBaseL(lookupItem));
   840 
   685 
   841         lookupItem.iSource = ESourceContactsWork;
   686         lookupItem.iSource = ESourceContactsWork;
   842         TRAP_IGNORE( ManipulateMapTileDataBaseL(lookupItem));
   687         TRAP_IGNORE( ManipulateMapTileDataBaseL(lookupItem));
   843         
   688         
   844         lookupItem.iSource = ESourceContactsHome;
   689         lookupItem.iSource = ESourceContactsHome;
   845         TRAP_IGNORE( ManipulateMapTileDataBaseL(lookupItem));
   690         TRAP_IGNORE( ManipulateMapTileDataBaseL(lookupItem));
   846               
   691               
       
   692         // Delete entries from  mylocation database
       
   693         TRAP_IGNORE( UpdateDatabaseL( NULL, aEvent.iContactId,
       
   694                      ESourceContactsPref, EEntryDeleted ));
       
   695        
       
   696         TRAP_IGNORE( UpdateDatabaseL( NULL, aEvent.iContactId,
       
   697                ESourceContactsHome, EEntryDeleted ));
       
   698 
       
   699         TRAP_IGNORE( UpdateDatabaseL( NULL, aEvent.iContactId,
       
   700                                ESourceContactsWork, EEntryDeleted ) );  
       
   701         
   847         MYLOCLOGSTRING("EContactDbObserverEventContactDeleted ");
   702         MYLOCLOGSTRING("EContactDbObserverEventContactDeleted ");
   848         return;
   703         return;
   849     }
   704     }
   850 
   705 
   851     //Get the contact item
   706     //Get the contact item
   852     iEventType = aEvent.iType;
   707     iEventType = aEvent.iType;
   853     QContact contactInfo = iContactManager->contact( aEvent.iContactId );
   708     QContact contactInfo = iContactManager->contact( aEvent.iContactId );
   854     
   709     
   855   
   710     //Get the contact name details
       
   711     QContactName name = contactInfo.detail( QContactName::DefinitionName );
       
   712     QString firstName = name.firstName();
       
   713     QString lastName = name.lastName();
       
   714     TPtrC16 tempPtr1(reinterpret_cast<const TUint16*>(firstName.utf16()));
       
   715     TPtrC16 tempPtr2( reinterpret_cast <const TUint16*>(lastName.utf16()));
       
   716     
       
   717     TBuf<KBufSize> landmarkName;
       
   718     landmarkName.Append( tempPtr1 );
       
   719     landmarkName.Append( tempPtr2 );
       
   720             
   856     CPosLandmark *preferedAddressLm = NULL;
   721     CPosLandmark *preferedAddressLm = NULL;
   857     CPosLandmark *workAddressLm = NULL;
   722     CPosLandmark *workAddressLm = NULL;
   858     CPosLandmark *homeAddressLm = NULL;
   723     CPosLandmark *homeAddressLm = NULL;
   859     
   724     
   860     TInt itemCount = 0;
   725     TInt itemCount = 0;
   898        
   763        
   899             // if default address available, update Mylocations. 
   764             // if default address available, update Mylocations. 
   900             lookupItem.iSource = ESourceContactsPref;
   765             lookupItem.iSource = ESourceContactsPref;
   901             if (preferedAddressLm)
   766             if (preferedAddressLm)
   902             {
   767             {
       
   768                 preferedAddressLm->SetLandmarkNameL( landmarkName );
   903                 MYLOCLOGSTRING("preferedAddressLm address changed" );
   769                 MYLOCLOGSTRING("preferedAddressLm address changed" );
   904 
   770 
   905                 if ( iMyLocationsDatabaseManager->CheckIfAddressChanged(*preferedAddressLm,
   771                 if ( iMyLocationsDatabaseManager->CheckIfAddressChanged(*preferedAddressLm,
   906                     aEvent.iContactId, ESourceContactsPref) )
   772                     aEvent.iContactId, ESourceContactsPref) )
   907 
   773 
   929             
   795             
   930             // if home address available, update Mylocations.
   796             // if home address available, update Mylocations.
   931             lookupItem.iSource = ESourceContactsHome;
   797             lookupItem.iSource = ESourceContactsHome;
   932             if (homeAddressLm)
   798             if (homeAddressLm)
   933             {
   799             {
       
   800                 homeAddressLm->SetLandmarkNameL( landmarkName );
   934                 MYLOCLOGSTRING("homeAddressLm address changed" );
   801                 MYLOCLOGSTRING("homeAddressLm address changed" );
   935                 if ( iMyLocationsDatabaseManager->CheckIfAddressChanged(*homeAddressLm,
   802                 if ( iMyLocationsDatabaseManager->CheckIfAddressChanged(*homeAddressLm,
   936                         aEvent.iContactId, ESourceContactsHome) )
   803                         aEvent.iContactId, ESourceContactsHome) )
   937                 {
   804                 {
   938                     lookupItem.iFilePath.Zero();
   805                     lookupItem.iFilePath.Zero();
   957 
   824 
   958             // if work address available, update Mylocations.
   825             // if work address available, update Mylocations.
   959             lookupItem.iSource = ESourceContactsWork;
   826             lookupItem.iSource = ESourceContactsWork;
   960             if (workAddressLm)
   827             if (workAddressLm)
   961             {
   828             {
       
   829                 workAddressLm->SetLandmarkNameL( landmarkName );
   962                 MYLOCLOGSTRING("workAddressLm address changed" );
   830                 MYLOCLOGSTRING("workAddressLm address changed" );
   963                 if ( iMyLocationsDatabaseManager->CheckIfAddressChanged(*workAddressLm,
   831                 if ( iMyLocationsDatabaseManager->CheckIfAddressChanged(*workAddressLm,
   964                         aEvent.iContactId, ESourceContactsWork) )
   832                         aEvent.iContactId, ESourceContactsWork) )
   965                 {
   833                 {
   966                     lookupItem.iFilePath.Zero();
   834                     lookupItem.iFilePath.Zero();
   993             lookupItem.iFetchingStatus = EMapTileFetchingInProgress;
   861             lookupItem.iFetchingStatus = EMapTileFetchingInProgress;
   994             
   862             
   995             MYLOCLOGSTRING("EContactDbObserverEventContactAdded" );
   863             MYLOCLOGSTRING("EContactDbObserverEventContactAdded" );
   996             if (preferedAddressLm)
   864             if (preferedAddressLm)
   997             {
   865             {
       
   866                 preferedAddressLm->SetLandmarkNameL( landmarkName );
   998                 //create entry in the data base and maintain a fetching state.
   867                 //create entry in the data base and maintain a fetching state.
   999                 lookupItem.iSource = ESourceContactsPref;
   868                 lookupItem.iSource = ESourceContactsPref;
  1000                 iMaptileDatabase->CreateEntryL(lookupItem);
   869                 iMaptileDatabase->CreateEntryL(lookupItem);
  1001                 RequestMapTileImageL(*preferedAddressLm, ESourceContactsPref,
   870                 RequestMapTileImageL(*preferedAddressLm, ESourceContactsPref,
  1002                         aEvent.iContactId, iEventType);
   871                         aEvent.iContactId, iEventType);
  1003             }
   872             }
  1004             if (homeAddressLm)
   873             if (homeAddressLm)
  1005             {
   874             {
       
   875                 homeAddressLm->SetLandmarkNameL( landmarkName );
  1006                 lookupItem.iSource = ESourceContactsHome;
   876                 lookupItem.iSource = ESourceContactsHome;
  1007                 iMaptileDatabase->CreateEntryL(lookupItem);
   877                 iMaptileDatabase->CreateEntryL(lookupItem);
  1008                 RequestMapTileImageL(*homeAddressLm, ESourceContactsHome,
   878                 RequestMapTileImageL(*homeAddressLm, ESourceContactsHome,
  1009                         aEvent.iContactId, iEventType);
   879                         aEvent.iContactId, iEventType);
  1010             }
   880             }
  1011             if (workAddressLm)
   881             if (workAddressLm)
  1012             {
   882             {
       
   883                 workAddressLm->SetLandmarkNameL( landmarkName );
  1013                 lookupItem.iSource = ESourceContactsWork;
   884                 lookupItem.iSource = ESourceContactsWork;
  1014                 iMaptileDatabase->CreateEntryL(lookupItem);
   885                 iMaptileDatabase->CreateEntryL(lookupItem);
  1015                 RequestMapTileImageL(*workAddressLm, ESourceContactsWork,
   886                 RequestMapTileImageL(*workAddressLm, ESourceContactsWork,
  1016                         aEvent.iContactId, iEventType);
   887                         aEvent.iContactId, iEventType);
  1017             }
   888             }
  1473 		   ProcessNextMaptileRequest();
  1344 		   ProcessNextMaptileRequest();
  1474         }
  1345         }
  1475     }    
  1346     }    
  1476 }
  1347 }
  1477 
  1348 
       
  1349 
       
  1350 
       
  1351 
       
  1352 // -----------------------------------------------------------------------------
       
  1353 // CMyLocationsEngine::MyLocationThreeAMTimerExpiredL()
       
  1354 // Triggers the maptile fetching at 3.00 for the network failure cases.
       
  1355 // -----------------------------------------------------------------------------
       
  1356 //
  1478 void CMyLocationsEngine::MyLocationThreeAMTimerExpiredL()
  1357 void CMyLocationsEngine::MyLocationThreeAMTimerExpiredL()
  1479 {
  1358 {
  1480     //Forward the event for maptile fetching only if maptile plugin available
  1359     //Forward the event for maptile fetching only if maptile plugin available
  1481     if( iMaptileGeocoderPluginAvailable )
  1360     if( iMaptileGeocoderPluginAvailable )
  1482     {
  1361     {
  1492                 case ESourceContactsHome:
  1371                 case ESourceContactsHome:
  1493                 case ESourceContactsWork:
  1372                 case ESourceContactsWork:
  1494                 case ESourceContactsPref:
  1373                 case ESourceContactsPref:
  1495                      { 
  1374                      { 
  1496                         QContact contactInfo = iContactManager->contact( iItem.iUid );
  1375                         QContact contactInfo = iContactManager->contact( iItem.iUid );
       
  1376                         
       
  1377                         //Get the contact name details
       
  1378                         QContactName name = contactInfo.detail( QContactName::DefinitionName );
       
  1379                         QString firstName = name.firstName();
       
  1380                         QString lastName = name.lastName();
       
  1381                         TPtrC16 tempPtr1(reinterpret_cast<const TUint16*>(firstName.utf16()));
       
  1382                         TPtrC16 tempPtr2( reinterpret_cast <const TUint16*>(lastName.utf16()));
       
  1383                        
       
  1384                         TBuf<KBufSize> landmarkName;
       
  1385                         landmarkName.Append( tempPtr1 );
       
  1386                         landmarkName.Append( tempPtr2 );
       
  1387                         
  1497                         CPosLandmark *addressLm = NULL;
  1388                         CPosLandmark *addressLm = NULL;
  1498     
  1389     
  1499                         foreach ( QContactAddress address, contactInfo.details<QContactAddress>() )
  1390                         foreach ( QContactAddress address, contactInfo.details<QContactAddress>() )
  1500                         {
  1391                         {
  1501                             QStringList context = address.contexts();
  1392                             QStringList context = address.contexts();
  1507                             {
  1398                             {
  1508                                 // Get the default/prefered address details
  1399                                 // Get the default/prefered address details
  1509                                 addressLm = GetContactAddressDetailsLC( address );
  1400                                 addressLm = GetContactAddressDetailsLC( address );
  1510                                 if( addressLm ) 
  1401                                 if( addressLm ) 
  1511                                 {
  1402                                 {
       
  1403                                     addressLm->SetLandmarkNameL( landmarkName );
  1512                                     RequestMapTileImageL( *addressLm,
  1404                                     RequestMapTileImageL( *addressLm,
  1513                                            ( TUidSourceType )iItem.iSource, iItem.iUid, EContactDbObserverEventContactChanged );
  1405                                            ( TUidSourceType )iItem.iSource, iItem.iUid, EContactDbObserverEventContactChanged );
  1514                                     CleanupStack::PopAndDestroy( addressLm );
  1406                                     CleanupStack::PopAndDestroy( addressLm );
  1515                                     break;
  1407                                     break;
  1516                                 }
  1408                                 }
  1569         lookupItem.iSource = iMapTileRequestQueue[0]->iAddressType;
  1461         lookupItem.iSource = iMapTileRequestQueue[0]->iAddressType;
  1570         lookupItem.iUid = iMapTileRequestQueue[0]->iUId;
  1462         lookupItem.iUid = iMapTileRequestQueue[0]->iUId;
  1571        
  1463        
  1572         if ( aErrCode == KErrNone )
  1464         if ( aErrCode == KErrNone )
  1573         {           
  1465         {           
       
  1466             CreateMultipleMaptiles( aMapTilePath );
  1574             lookupItem.iFilePath.Copy(aMapTilePath);
  1467             lookupItem.iFilePath.Copy(aMapTilePath);
  1575             lookupItem.iFetchingStatus = EMapTileFectchingCompleted;
  1468             lookupItem.iFetchingStatus = EMapTileFectchingCompleted;
  1576  
  1469  
  1577         }
  1470         }
  1578         else if ( aErrCode == KErrCouldNotConnect )
  1471         else if ( aErrCode == KErrCouldNotConnect )
  1667         else
  1560         else
  1668         {
  1561         {
  1669             iMaptileDatabase->CreateEntryL(aLookupItem);
  1562             iMaptileDatabase->CreateEntryL(aLookupItem);
  1670         }
  1563         }
  1671     }
  1564     }
  1672     iMyLocationsDatabaseManager->UpdateMapTilePath( aLookupItem.iUid, aLookupItem.iSource, 
  1565     if (aLookupItem.iFetchingStatus == EMapTileFetchingUnknownError
  1673                                             aLookupItem.iFilePath );    
  1566             || aLookupItem.iFetchingStatus == EMapTileFetchingNetworkError)
       
  1567     {
       
  1568         TRAP_IGNORE( UpdateDatabaseL( NULL,
       
  1569                         aLookupItem.iUid, aLookupItem.iSource, EEntryDeleted ) );
       
  1570 
       
  1571     }
       
  1572     else
       
  1573     {      
       
  1574         TPtrC8 ptr(reinterpret_cast<const TUint8*>(MAPTILE_IMAGE_HURRIGANES));   
       
  1575         HBufC* buffer = NULL;
       
  1576         buffer=HBufC::NewLC(ptr.Length());
       
  1577         buffer->Des().Copy(ptr);
       
  1578         if(buffer)
       
  1579         {
       
  1580             aLookupItem.iFilePath.Append(*buffer);
       
  1581         }
       
  1582         CleanupStack::PopAndDestroy(buffer);
       
  1583         iMyLocationsDatabaseManager->UpdateMapTilePath(aLookupItem.iUid,
       
  1584                 aLookupItem.iSource, aLookupItem.iFilePath);
       
  1585     }
  1674 }
  1586 }
  1675 
  1587 
  1676 // -----------------------------------------------------------------------------
  1588 // -----------------------------------------------------------------------------
  1677 // CMyLocationsEngine::RestGeoCodeCompleted()
  1589 // CMyLocationsEngine::RestGeoCodeCompleted()
  1678 // observed when rest geo codeing completed.
  1590 // observed when rest geo codeing completed.
  1688     {
  1600     {
  1689         switch (iMapTileRequestQueue[0]->iAddressType)
  1601         switch (iMapTileRequestQueue[0]->iAddressType)
  1690         {
  1602         {
  1691         //TODO:
  1603         //TODO:
  1692         case ESourceCalendar:
  1604         case ESourceCalendar:
  1693         {                   
  1605         {           
       
  1606             iGeocodeUpdate->updateGeocodeToCalenderDB(iMapTileRequestQueue[0]->iUId,
       
  1607                     aLatitude,aLongitude);                    
  1694             CPosLandmark *landmark = NULL;
  1608             CPosLandmark *landmark = NULL;
  1695             landmark = iMapTileInterface->GetLandMarkDetails();
  1609             landmark = iMapTileInterface->GetLandMarkDetails();
  1696             if (NULL != landmark)
  1610             if (NULL != landmark)
  1697             {
  1611             {
  1698                 TRAP_IGNORE( landmark->SetPositionFieldL(EPositionFieldComment,
  1612                 TRAP_IGNORE( landmark->SetPositionFieldL(EPositionFieldComment,
  1706         }
  1620         }
  1707         case ESourceContactsPref:
  1621         case ESourceContactsPref:
  1708         case ESourceContactsWork:
  1622         case ESourceContactsWork:
  1709         case ESourceContactsHome:
  1623         case ESourceContactsHome:
  1710         {
  1624         {
  1711             GeocodeUpdate geocodeUpdate;
  1625             iGeocodeUpdate->updateGeocodeToContactDB(
  1712             geocodeUpdate.updateGeocodeToContactDB(
       
  1713                     iMapTileRequestQueue[0]->iUId,
  1626                     iMapTileRequestQueue[0]->iUId,
  1714                     iMapTileRequestQueue[0]->iAddressType, aLatitude,
  1627                     iMapTileRequestQueue[0]->iAddressType, aLatitude,
  1715                     aLongitude);
  1628                     aLongitude);
       
  1629             //Update mylocation database 
       
  1630             TRAP_IGNORE( UpdateDatabaseL( 
       
  1631                     iMapTileRequestQueue[0]->iLandmarkInfo, 
       
  1632                     iMapTileRequestQueue[0]->iUId,
       
  1633                     iMapTileRequestQueue[0]->iAddressType,
       
  1634                     MapChangeType( 
       
  1635                         static_cast<TUidSourceType>( iMapTileRequestQueue[0]->iAddressType ), 
       
  1636                                                   iMapTileRequestQueue[0]->iEventType )));
       
  1637             
  1716             MYLOCLOGSTRING("Geo-codinate updated to contact db");
  1638             MYLOCLOGSTRING("Geo-codinate updated to contact db");
  1717             break;
  1639             break;
  1718         }
  1640         }
  1719         };
  1641         };
  1720 
       
  1721         
       
  1722     }
  1642     }
  1723 
  1643 
  1724 }
  1644 }
  1725 
  1645 
  1726 // -----------------------------------------------------------------------------
  1646 // -----------------------------------------------------------------------------
  1755     {
  1675     {
  1756         iMaptileDatabase->DeleteMapTileL(aLookupItem);
  1676         iMaptileDatabase->DeleteMapTileL(aLookupItem);
  1757     }            
  1677     }            
  1758 }
  1678 }
  1759 
  1679 
       
  1680 
       
  1681 // -----------------------------------------------------------------------------
       
  1682 // CMyLocationsEngine::CreateMultipleMaptiles()
       
  1683 // -----------------------------------------------------------------------------
       
  1684 //
       
  1685 void CMyLocationsEngine::CreateMultipleMaptiles( const TDesC& aMaptilePath )
       
  1686 {
       
  1687     __TRACE_CALLSTACK;
       
  1688     QString filePath =  QString::fromUtf16( aMaptilePath.Ptr(), aMaptilePath.Length() );
       
  1689     
       
  1690     //Portrait image , common for contacts/calendar/context menu
       
  1691     CropAndSaveImage( filePath, 
       
  1692                       MaptilePortraitWidth, 
       
  1693                       MaptilePortraitHeight, 
       
  1694                       QString(),
       
  1695                       QString( MAPTILE_IMAGE_PORTRAIT ) );
       
  1696     
       
  1697     //Landscape image for contacts
       
  1698     CropAndSaveImage( filePath, 
       
  1699                       MaptileContactLandscapeWidth, 
       
  1700                       MaptileContactLandscapeHeight,
       
  1701                       QString( MAPTILE_IMAGE_CONTACT ),
       
  1702                       QString( MAPTILE_IMAGE_LANDSCAPE ) );
       
  1703     
       
  1704     //Ladscape image for calendar
       
  1705     CropAndSaveImage( filePath, 
       
  1706                       MaptileCalendarLandscapeWidth, 
       
  1707                       MaptileCalendarLandscapeHeight,
       
  1708                       QString( MAPTILE_IMAGE_CALENDAR ),
       
  1709                       QString( MAPTILE_IMAGE_LANDSCAPE ) );
       
  1710     
       
  1711     //Image for hurriganes
       
  1712     CropAndSaveImage( filePath, 
       
  1713                       MaptileHurriganesWidth, 
       
  1714                       MaptileHurriganesHeight,
       
  1715                       QString( MAPTILE_IMAGE_HURRIGANES ),
       
  1716                       QString() );
       
  1717     QFile file(filePath);
       
  1718     file.remove();   
       
  1719 }
       
  1720 
       
  1721 
       
  1722 // -----------------------------------------------------------------------------
       
  1723 // CMyLocationsEngine::CropAndSaveImage()
       
  1724 // -----------------------------------------------------------------------------
       
  1725 //
       
  1726 void CMyLocationsEngine::CropAndSaveImage( QString filePath, int width, 
       
  1727                                    int height, QString appType, QString orientationType )
       
  1728 {    
       
  1729      __TRACE_CALLSTACK;
       
  1730      QImage SourcePNG( filePath );
       
  1731      QImage sourcePixmap( SourcePNG.convertToFormat(QImage::Format_Indexed8));     
       
  1732      QImage targetPixmap( sourcePixmap.copy( 
       
  1733                                ( MapTileWidth - width )/2, 
       
  1734                                ( MapTileHeight - height )/2 , 
       
  1735                                width, 
       
  1736                                height ) );
       
  1737          
       
  1738      QString targetImage;
       
  1739      targetImage.append( filePath );
       
  1740      targetImage.append( appType );
       
  1741      targetImage.append( orientationType );
       
  1742      targetPixmap.save( targetImage, MAPTILE_IMAGE_TYPE  );
       
  1743              
       
  1744 }
       
  1745 
  1760 //End of file
  1746 //End of file
  1761 
  1747