diff -r 8db05346071b -r 59575560d1e6 locationdataharvester/mylocationsengine/src/mylocationsengine.cpp --- a/locationdataharvester/mylocationsengine/src/mylocationsengine.cpp Tue Jul 06 14:10:28 2010 +0300 +++ b/locationdataharvester/mylocationsengine/src/mylocationsengine.cpp Wed Aug 18 09:43:18 2010 +0300 @@ -47,6 +47,8 @@ _LIT8( KMaptileStatusFormat, "%d-%d-%d" ); const TInt KProtocolBufferSize = 16; +const QString KSpace(" "); + // ============================ MEMBER FUNCTIONS =============================== CMyLocationsEngine* CMyLocationsEngine::NewL() @@ -332,6 +334,16 @@ iLastContactId = aId; + //If the requested id is already in queue, just return + for( TInt index = 0 ; index < iMapTileRequestQueue.Count(); index++ ) + { + if( iLastContactId == iMapTileRequestQueue[index]->iUId ) + { + MYLOCLOGSTRING("contact id is in queue"); + return; + } + } + TAppAddressInfo* addressInfo = new (ELeave) TAppAddressInfo; addressInfo->iUid = aId; addressInfo->iAddressType = addressType; @@ -343,16 +355,8 @@ //Get all 3 adress if( addressCount > 1 && iAddressInfo.Count() < addressCount ) - return; - - //If the requested id is already in queue, just return - for( TInt index = 0 ; index < iMapTileRequestQueue.Count(); index++ ) - { - if( iLastContactId == iMapTileRequestQueue[index]->iUId ) - { - return; - } - } + return; + for( TInt index = 0; index < iAddressInfo.Count(); index++ ) { @@ -402,8 +406,11 @@ iMaptileDatabase->UpdateEntryL( lookupItem ); //Request for maptile fetching - RequestMapTileImageL( *contactAddressLm, type, + if( contactAddressLm ) + { + RequestMapTileImageL( *contactAddressLm, type, iAddressInfo[index]->iUid, EContactDbObserverEventContactChanged ); + } CleanupStack::PopAndDestroy( itemCount ); } @@ -541,6 +548,13 @@ for (int i = 0; i < aChangeItems.Count(); i++) { + // Check if this is some undefined change in calendar db. + if( aChangeItems[0].iChangeType == EChangeUndefined && aChangeItems[0].iEntryType == EChangeEntryAll ) + { + // Refresh the calendar related entries in the location and maptiledb. + RefreshCalendarEntryListL(); + break; + } TCalChangeEntry calChangeEntry = aChangeItems[i]; iEventType = calChangeEntry.iChangeType; switch (calChangeEntry.iChangeType) @@ -580,6 +594,39 @@ } // ----------------------------------------------------------------------------- +// CMyLocationsEngine::RefreshCalendarEntryListL() +// ----------------------------------------------------------------------------- +// +void CMyLocationsEngine::RefreshCalendarEntryListL() +{ + //Get all the calendar ids and check its validity. + //Delete if they are no more valid. + RArray ids; + iMaptileDatabase->GetAllCalendarIdsL( ids ); + for( TInt i = 0; i < ids.Count(); i++ ) + { + if( !IsCalendarEntryValidL( ids[i] ) ) + { + TLookupItem lookupItem; + lookupItem.iSource = ESourceCalendar; + lookupItem.iUid = ids[i]; + TRAP_IGNORE( ManipulateMapTileDataBaseL( lookupItem ) ); + TRAP_IGNORE( UpdateDatabaseL( NULL, + ids[i], ESourceCalendar, EEntryDeleted ) ); + + } + } +} + +// ----------------------------------------------------------------------------- +// CMyLocationsEngine::IsCalendarEntryValidL() +// ----------------------------------------------------------------------------- +// +TBool CMyLocationsEngine::IsCalendarEntryValidL( TUint32 aId ) +{ + return ( ( iCalView->FetchL( aId ) == NULL ) ? EFalse:ETrue ); +} +// ----------------------------------------------------------------------------- // CMyLocationsEngine::CalenderEntryAddedL() // ----------------------------------------------------------------------------- // @@ -677,7 +724,7 @@ TLookupItem lookupItem; lookupItem.iUid = aEvent.iContactId; // If contact is deleted delete from mylocations db - if (aEvent.iType == EContactDbObserverEventContactDeleted) + if ( aEvent.iType == EContactDbObserverEventContactDeleted || aEvent.iType == EContactDbObserverEventOwnCardDeleted ) { //Delete the entries from maptile database lookupItem.iSource = ESourceContactsPref; @@ -705,19 +752,7 @@ //Get the contact item iEventType = aEvent.iType; - QContact contactInfo = iContactManager->contact( aEvent.iContactId ); - - //Get the contact name details - QContactName name = contactInfo.detail( QContactName::DefinitionName ); - QString firstName = name.firstName(); - QString lastName = name.lastName(); - TPtrC16 tempPtr1(reinterpret_cast(firstName.utf16())); - TPtrC16 tempPtr2( reinterpret_cast (lastName.utf16())); - - TBuf landmarkName; - landmarkName.Append( tempPtr1 ); - landmarkName.Append( tempPtr2 ); - + QContact contactInfo = iContactManager->contact( aEvent.iContactId ); CPosLandmark *preferedAddressLm = NULL; CPosLandmark *workAddressLm = NULL; CPosLandmark *homeAddressLm = NULL; @@ -747,6 +782,7 @@ switch (aEvent.iType) { case EContactDbObserverEventContactChanged: + case EContactDbObserverEventOwnCardChanged: { MYLOCLOGSTRING("EContactDbObserverEventContactChanged" ); MYLOCLOGSTRING1("iMapTileRequestQueue.Count()-%d",iMapTileRequestQueue.Count() ); @@ -760,12 +796,16 @@ return; } } - + + TBuf landmarkName; + GetContactName(aEvent.iContactId,landmarkName); + // if default address available, update Mylocations. lookupItem.iSource = ESourceContactsPref; if (preferedAddressLm) { - preferedAddressLm->SetLandmarkNameL( landmarkName ); + iMyLocationsDatabaseManager->UpdateEntryName( aEvent.iContactId, ESourceContactsPref, + landmarkName ); MYLOCLOGSTRING("preferedAddressLm address changed" ); if ( iMyLocationsDatabaseManager->CheckIfAddressChanged(*preferedAddressLm, @@ -783,12 +823,13 @@ { iMaptileDatabase->DeleteMapTileL(lookupItem); } - //remove entry from database - //TRAP_IGNORE( ManipulateMapTileDataBaseL(lookupItem)); + } } else { + TRAP_IGNORE( UpdateDatabaseL( NULL, aEvent.iContactId, + ESourceContactsPref, EEntryDeleted )); TRAP_IGNORE( ManipulateMapTileDataBaseL(lookupItem)); } @@ -797,7 +838,8 @@ lookupItem.iSource = ESourceContactsHome; if (homeAddressLm) { - homeAddressLm->SetLandmarkNameL( landmarkName ); + iMyLocationsDatabaseManager->UpdateEntryName( aEvent.iContactId, ESourceContactsHome, + landmarkName ); MYLOCLOGSTRING("homeAddressLm address changed" ); if ( iMyLocationsDatabaseManager->CheckIfAddressChanged(*homeAddressLm, aEvent.iContactId, ESourceContactsHome) ) @@ -806,7 +848,6 @@ lookupItem.iFetchingStatus = EMapTileFetchingInProgress; TRAP_IGNORE( iMaptileDatabase->ReSetEntryL(lookupItem) ) //remove entry from databse - //TRAP_IGNORE( ManipulateMapTileDataBaseL(lookupItem)); RequestMapTileImageL(*homeAddressLm, ESourceContactsHome, aEvent.iContactId, iEventType); if (lookupItem.iFilePath.Length() > 0) @@ -817,6 +858,8 @@ } else { + TRAP_IGNORE( UpdateDatabaseL( NULL, aEvent.iContactId, + ESourceContactsHome, EEntryDeleted )); TRAP_IGNORE( ManipulateMapTileDataBaseL(lookupItem)); } @@ -826,7 +869,9 @@ lookupItem.iSource = ESourceContactsWork; if (workAddressLm) { - workAddressLm->SetLandmarkNameL( landmarkName ); + iMyLocationsDatabaseManager->UpdateEntryName( aEvent.iContactId, ESourceContactsWork, + landmarkName ); + MYLOCLOGSTRING("workAddressLm address changed" ); if ( iMyLocationsDatabaseManager->CheckIfAddressChanged(*workAddressLm, aEvent.iContactId, ESourceContactsWork) ) @@ -835,19 +880,18 @@ lookupItem.iFetchingStatus = EMapTileFetchingInProgress; TRAP_IGNORE( iMaptileDatabase->ReSetEntryL(lookupItem) ) - //remove entry from databse - //TRAP_IGNORE( ManipulateMapTileDataBaseL(lookupItem)); RequestMapTileImageL(*workAddressLm, ESourceContactsWork, aEvent.iContactId, iEventType); if (lookupItem.iFilePath.Length() > 0) { iMaptileDatabase->DeleteMapTileL(lookupItem); } - } - + } } else { + TRAP_IGNORE( UpdateDatabaseL( NULL, aEvent.iContactId, + ESourceContactsWork, EEntryDeleted )); TRAP_IGNORE( ManipulateMapTileDataBaseL(lookupItem)); } @@ -863,7 +907,6 @@ MYLOCLOGSTRING("EContactDbObserverEventContactAdded" ); if (preferedAddressLm) { - preferedAddressLm->SetLandmarkNameL( landmarkName ); //create entry in the data base and maintain a fetching state. lookupItem.iSource = ESourceContactsPref; iMaptileDatabase->CreateEntryL(lookupItem); @@ -872,7 +915,6 @@ } if (homeAddressLm) { - homeAddressLm->SetLandmarkNameL( landmarkName ); lookupItem.iSource = ESourceContactsHome; iMaptileDatabase->CreateEntryL(lookupItem); RequestMapTileImageL(*homeAddressLm, ESourceContactsHome, @@ -880,7 +922,6 @@ } if (workAddressLm) { - workAddressLm->SetLandmarkNameL( landmarkName ); lookupItem.iSource = ESourceContactsWork; iMaptileDatabase->CreateEntryL(lookupItem); RequestMapTileImageL(*workAddressLm, ESourceContactsWork, @@ -1027,7 +1068,7 @@ } // ----------------------------------------------------------------------------- -// CMyLocationsEngine::GetLocationDetailsLC() +// CMyLocationsEngine::GetContactAddressDetailsLC() // get locatin details // ----------------------------------------------------------------------------- // @@ -1374,17 +1415,6 @@ { QContact contactInfo = iContactManager->contact( iItem.iUid ); - //Get the contact name details - QContactName name = contactInfo.detail( QContactName::DefinitionName ); - QString firstName = name.firstName(); - QString lastName = name.lastName(); - TPtrC16 tempPtr1(reinterpret_cast(firstName.utf16())); - TPtrC16 tempPtr2( reinterpret_cast (lastName.utf16())); - - TBuf landmarkName; - landmarkName.Append( tempPtr1 ); - landmarkName.Append( tempPtr2 ); - CPosLandmark *addressLm = NULL; foreach ( QContactAddress address, contactInfo.details() ) @@ -1400,7 +1430,6 @@ addressLm = GetContactAddressDetailsLC( address ); if( addressLm ) { - addressLm->SetLandmarkNameL( landmarkName ); RequestMapTileImageL( *addressLm, ( TUidSourceType )iItem.iSource, iItem.iUid, EContactDbObserverEventContactChanged ); CleanupStack::PopAndDestroy( addressLm ); @@ -1479,7 +1508,25 @@ lookupItem.iFetchingStatus = EMapTileFetchingUnknownError; } - TRAP_IGNORE( UpdateMaptileDatabaseL(iMapTileRequestQueue[0]->iEventType,lookupItem ) ); + TRAP_IGNORE( UpdateMaptileDatabaseL( iMapTileRequestQueue[0]->iEventType,lookupItem ) ); + + // if the source type is contacts, update the contact name into the locationdatalookupdb. + // This has to be done, because there is a possibility that the user might change the + // contact name between geocodefetchingcomplete and maptilefetchingcomplete. + if( iMapTileRequestQueue[0]->iAddressType == ESourceContactsPref || + iMapTileRequestQueue[0]->iAddressType == ESourceContactsHome || + iMapTileRequestQueue[0]->iAddressType == ESourceContactsWork ) + { + TBuf landmarkName; + GetContactName( iMapTileRequestQueue[0]->iUId, landmarkName ); + + iMyLocationsDatabaseManager->UpdateEntryName( + iMapTileRequestQueue[0]->iUId, ESourceContactsPref, landmarkName ); + iMyLocationsDatabaseManager->UpdateEntryName( + iMapTileRequestQueue[0]->iUId, ESourceContactsHome, landmarkName ); + iMyLocationsDatabaseManager->UpdateEntryName( + iMapTileRequestQueue[0]->iUId, ESourceContactsWork, landmarkName ); + } //Publish the maptile status , if it was from contact if( iLastContactId == iMapTileRequestQueue[0]->iUId ) @@ -1626,7 +1673,10 @@ iMapTileRequestQueue[0]->iUId, iMapTileRequestQueue[0]->iAddressType, aLatitude, aLongitude); + TBuf landmarkName; + GetContactName(iMapTileRequestQueue[0]->iUId,landmarkName); //Update mylocation database + iMapTileRequestQueue[0]->iLandmarkInfo->SetLandmarkNameL( landmarkName ); TRAP_IGNORE( UpdateDatabaseL( iMapTileRequestQueue[0]->iLandmarkInfo, iMapTileRequestQueue[0]->iUId, @@ -1643,6 +1693,35 @@ } + +// ----------------------------------------------------------------------------- +// CMyLocationsEngine::GetContactName() +// ----------------------------------------------------------------------------- +// +void CMyLocationsEngine::GetContactName( TInt32 aUId,TDes& aName) +{ + QContact contactInfo = iContactManager->contact( aUId ); + QContactName name = contactInfo.detail( QContactName::DefinitionName ); + QString firstName = name.firstName(); + QString lastName = name.lastName(); + QString fullName(""); + + if( lastName.isEmpty() ) + { + fullName = firstName; + } + else + { + if( !firstName.isEmpty() ) + { + fullName = firstName + KSpace; + } + fullName = fullName + lastName; + } + + aName.Copy( reinterpret_cast(fullName.utf16()) ); +} + // ----------------------------------------------------------------------------- // CMyLocationsEngine::UpdateDatabaseL() // ----------------------------------------------------------------------------- @@ -1651,7 +1730,10 @@ const TUint32 aSourceType, const TEntryChangeType aChangeType ) { __TRACE_CALLSTACK; - Cancel(); + if(IsActive()) + { + Cancel(); + } iMyLocationsDatabaseManager->UpdateDatabaseL( aLandmark, aUid, aSourceType, aChangeType ); if( aSourceType != ESourceLandmarks )