locationdataharvester/mylocationsdatabasemanager/src/mylocationsdatabasemanager.cpp
branchRCL_3
changeset 17 1fc85118c3ae
equal deleted inserted replaced
16:8173571d354e 17:1fc85118c3ae
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: Database manager implementation 
       
    15 *
       
    16 */
       
    17 
       
    18 #include <EPos_CPosLandmarkCategory.h>
       
    19 #include <EPos_CPosLmTextCriteria.h>
       
    20 #include <EPos_CPosLandmarkSearch.h>
       
    21 #include <EPos_CPosLmDatabaseManager.h>
       
    22 #include <EPos_CPosLmNearestCriteria.h>
       
    23 #include <EPos_CPosLandmarkDatabase.h>
       
    24 #include <EPos_CPosLmCategoryManager.h>
       
    25 
       
    26 #include <lbsposition.h>
       
    27 #include <barsread.h>
       
    28 #include <barsc.h>
       
    29 #include <locationservicedefines.h>
       
    30 #include "mylocationsdatabasemanager.h"
       
    31 #include "mylocationlogger.h"
       
    32 #include "mylocationsdefines.h"
       
    33 
       
    34 #include <locationdatalookupdb.h>
       
    35 #include <QString>
       
    36 // separator
       
    37 _LIT( KSeparator, ",");
       
    38 // space
       
    39 _LIT( KSpace, " ");
       
    40 
       
    41 // QString separator
       
    42 const QString KQStringSeparator = ",";
       
    43 // QString space
       
    44 const QString KQStringSpace = " ";
       
    45 
       
    46 // Used to set nearest landmarks search distance criteria
       
    47 const TUint32 KSearchCriteriaDistance = 100; 
       
    48 
       
    49 // Maximum string length of landmark address.
       
    50 const TUint32 KMaxAddressLength = 255; 
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CMyLocationsDatabaseManager::ConstructL()
       
    54 // 2nd phase constructor.
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 EXPORT_C void CMyLocationsDatabaseManager::ConstructL()
       
    58 {
       
    59     __TRACE_CALLSTACK;//Open and intialize Landmark DB
       
    60     iLandmarkDb = CPosLandmarkDatabase::OpenL();
       
    61     ExecuteAndDeleteLD(iLandmarkDb->InitializeL());
       
    62  
       
    63     iLocationAppLookupDb = new LocationDataLookupDb();
       
    64     if( !iLocationAppLookupDb->open() )
       
    65     {
       
    66         User::Leave( KErrUnknown );
       
    67     }
       
    68     
       
    69     // Create category manager for landmarks
       
    70     iLandmarksCatManager = CPosLmCategoryManager::NewL(*iLandmarkDb);
       
    71 
       
    72     // open file session
       
    73     User::LeaveIfError(iFsSession.Connect());
       
    74 
       
    75     // Add contacts and calendar  categories
       
    76     iLmContactsCatId = AddMylocationsCategoryL(KContactsCategory);
       
    77     iLmCalendarCatId = AddMylocationsCategoryL( KCalendarCategory );
       
    78 
       
    79 }
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // CMyLocationsDatabaseManager::CMyLocationsDatabaseManager()
       
    83 // Default constructor.
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 EXPORT_C  CMyLocationsDatabaseManager::CMyLocationsDatabaseManager() : iLandmarkDb( NULL ),
       
    87                 iLmContactsCatId( 0 ), //iLandmarksLookupDb( NULL ), 
       
    88                 iLocationAppLookupDb( NULL ),
       
    89                 iLandmarksCatManager( NULL )
       
    90 {
       
    91 }
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // CMyLocationsDatabaseManager::_CMyLocationsDatabaseManager()
       
    95 // Destructor.
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 CMyLocationsDatabaseManager::~CMyLocationsDatabaseManager()
       
    99 {
       
   100     __TRACE_CALLSTACK;// delete member variables.
       
   101 
       
   102     if (iLocationAppLookupDb)
       
   103     {
       
   104         iLocationAppLookupDb->close();
       
   105         delete iLocationAppLookupDb;
       
   106     }
       
   107 
       
   108     delete iLandmarksCatManager;
       
   109 
       
   110     delete iLandmarkDb;
       
   111 
       
   112     // close the file session
       
   113     iFsSession.Close();
       
   114 
       
   115 }
       
   116 
       
   117 // -----------------------------------------------------------------------------
       
   118 // CMyLocationsDatabaseManager::AddMylocationsCategoryL()
       
   119 // Adds the category to the mylocations and landmarks database..
       
   120 // -----------------------------------------------------------------------------
       
   121 //
       
   122 TUint32 CMyLocationsDatabaseManager::AddMylocationsCategoryL( const TDesC&  aCategoryName )
       
   123 {
       
   124     __TRACE_CALLSTACK;//Open the resource file
       
   125     
       
   126     TPosLmItemId catId = 0;
       
   127     
       
   128     //create category
       
   129     CPosLandmarkCategory *category = CPosLandmarkCategory::NewL();
       
   130     CleanupStack::PushL(category);
       
   131     category->SetCategoryNameL( aCategoryName );
       
   132     
       
   133     // Add category to landmarks database
       
   134     TRAPD ( error, ( catId = iLandmarksCatManager->AddCategoryL( *category ) ) );
       
   135     if (error == KErrNone || error == KErrAlreadyExists)
       
   136     {
       
   137         catId = iLandmarksCatManager->GetCategoryL( aCategoryName );
       
   138     }
       
   139 
       
   140     CleanupStack::PopAndDestroy(category);
       
   141 
       
   142     return catId;
       
   143 }
       
   144 
       
   145 // -----------------------------------------------------------------------------
       
   146 // CMyLocationsDatabaseManager::UpdateDatabaseL()
       
   147 // Updates the location into the landmark database and lookup table. Based on 
       
   148 // the entry source type and the entry change type the updation can be 
       
   149 // addition/modification/deletion.
       
   150 // -----------------------------------------------------------------------------
       
   151 //
       
   152 EXPORT_C void CMyLocationsDatabaseManager::UpdateDatabaseL(CPosLandmark* aLandmark,
       
   153         const TUint32 aUid, const TUint32 aSourceType, const TUint32 aChangeType)
       
   154 {
       
   155     __TRACE_CALLSTACK;//open the lookup database
       
   156     switch (aChangeType)
       
   157     {
       
   158     // if the entry is added
       
   159     case EEntryAdded:
       
   160     {
       
   161         // Handle this entry in the lookup table and update landmarks db.
       
   162         HandleEntryAdditionL(aLandmark, aUid, aSourceType);
       
   163         break;
       
   164     }
       
   165         // if the entry is modified
       
   166     case EEntryModified:
       
   167     {
       
   168         // Handle this entry in the lookup table and update landmarks db.
       
   169         HandleEntryModificationL(aLandmark, aUid, aSourceType);
       
   170         break;
       
   171     }
       
   172         // if the entry is deleted
       
   173     case EEntryDeleted:
       
   174     {
       
   175         // Handle this entry in the lookup table and update landmarks db.
       
   176         HandleEntryDeletionL(aUid, aSourceType);
       
   177         break;
       
   178     }
       
   179     }
       
   180 
       
   181 }
       
   182 
       
   183 // -----------------------------------------------------------------------------
       
   184 // CMyLocationsDatabaseManager::CheckIfDuplicateExistsL()
       
   185 // Checks if this landmark is already present in database. If present returns the landmark id, else 0
       
   186 // -----------------------------------------------------------------------------
       
   187 //
       
   188 TPosLmItemId CMyLocationsDatabaseManager::CheckIfDuplicateExistsL(
       
   189                                     const CPosLandmark* aLandmark)
       
   190 {
       
   191     __TRACE_CALLSTACK;// Stores the found duplicate landmark's id. 
       
   192     TPosLmItemId retId = 0;
       
   193 
       
   194     // Initially filter only the landmarks which are nearer to the current landmark.
       
   195     // Then we can make a duplicate check on each of the found landmarks.
       
   196 
       
   197     // create a search object.
       
   198     CPosLandmarkSearch* search = CPosLandmarkSearch::NewL(
       
   199             *iLandmarkDb);
       
   200     CleanupStack::PushL(search);
       
   201 
       
   202     TBuf<KMaxAddressLength> lmAddress1;
       
   203     GetLandmarkFullAddress( lmAddress1, aLandmark );
       
   204     QString str1 = QString( (QChar*)lmAddress1.Ptr(), lmAddress1.Length());
       
   205 
       
   206     // create nearest search criteria object
       
   207     TLocality position( TCoordinate( 0, 0), 0 );
       
   208     aLandmark->GetPosition( position );
       
   209     CPosLmNearestCriteria* nearestCriteria = 
       
   210                 CPosLmNearestCriteria::NewLC( 
       
   211                         TCoordinate( position.Latitude(), position.Longitude() ) );
       
   212     nearestCriteria->SetMaxDistance( KSearchCriteriaDistance );
       
   213     
       
   214     // Start the search and execute it at once.
       
   215     ExecuteAndDeleteLD( search->StartLandmarkSearchL( *nearestCriteria ) );
       
   216     CleanupStack::PopAndDestroy( nearestCriteria );
       
   217 
       
   218     // Retrieve an iterator to access the matching landmarks.
       
   219     CPosLmItemIterator* iter = search->MatchIteratorL();
       
   220     CleanupStack::PushL(iter);
       
   221 
       
   222     // Iterate the search matches.
       
   223     TPosLmItemId lmId;
       
   224 
       
   225     while( ( lmId = iter->NextL() ) != KPosLmNullItemId )
       
   226     {
       
   227         CPosLandmark* lm = iLandmarkDb->ReadLandmarkLC( lmId );
       
   228         TBuf<KMaxAddressLength> lmAddress2;
       
   229         GetLandmarkFullAddress( lmAddress2, lm );
       
   230         QString str2 = QString( (QChar*)lmAddress2.Ptr(), lmAddress2.Length());
       
   231         CleanupStack::PopAndDestroy( lm );
       
   232         
       
   233         if( str1 == str2 )
       
   234         {
       
   235             retId = lmId;
       
   236             break;
       
   237         }
       
   238     }
       
   239 
       
   240     CleanupStack::PopAndDestroy(iter);
       
   241     CleanupStack::PopAndDestroy(search);
       
   242 
       
   243     return retId;
       
   244 }
       
   245 
       
   246 // -----------------------------------------------------------------------------
       
   247 // CMyLocationsDatabaseManager::CompareLandmarks()
       
   248 // Compares two landmarks. Only the text fields, landmark name, street, city, state country and 
       
   249 // postal code are compared.
       
   250 // -----------------------------------------------------------------------------
       
   251 //
       
   252 TBool CMyLocationsDatabaseManager::CompareLandmarks(
       
   253         const CPosLandmark* aLandmark1, const CPosLandmark* aLandmark2 )
       
   254 {
       
   255     __TRACE_CALLSTACK;
       
   256 
       
   257     TBuf<KMaxAddressLength> lmAddress1;
       
   258     GetLandmarkFullAddress( lmAddress1, aLandmark1 );
       
   259     QString str1 = QString( (QChar*)lmAddress1.Ptr(), lmAddress1.Length());
       
   260 
       
   261     TBuf<KMaxAddressLength> lmAddress2;
       
   262     GetLandmarkFullAddress( lmAddress2, aLandmark2 );
       
   263     QString str2 = QString( (QChar*)lmAddress2.Ptr(), lmAddress2.Length());
       
   264 
       
   265     if( str1 == str2 )
       
   266         return ETrue;
       
   267     else
       
   268         return EFalse;
       
   269     
       
   270     
       
   271 }
       
   272 
       
   273 // -----------------------------------------------------------------------------
       
   274 // CMyLocationsDatabaseManager::HandleEntryAdditionL()
       
   275 // Handles the entry addition in lookup table and landmarks db
       
   276 // -----------------------------------------------------------------------------
       
   277 //
       
   278 void CMyLocationsDatabaseManager::HandleEntryAdditionL(CPosLandmark* aLandmark,
       
   279         const TUint32 aUid, const TUint32 aSourceType)
       
   280 {
       
   281     __TRACE_CALLSTACK;
       
   282     // Create a lookup item
       
   283     QLookupItem lookupItem;
       
   284     lookupItem.mSourceUid = aUid;
       
   285     lookupItem.mSourceType = aSourceType;
       
   286     lookupItem.mDestId = 0;
       
   287     lookupItem.mIconType = QLookupItem::EIconTypeDefault;
       
   288     lookupItem.mIsDuplicate = 0;
       
   289     lookupItem.mIconPath = "";
       
   290     lookupItem.mMapTilePath = "";
       
   291     lookupItem.mSingleLineAddress="";
       
   292     TPtrC16 dataPtr;
       
   293     aLandmark->GetPositionField(EPositionFieldComment ,dataPtr);
       
   294     lookupItem.mSingleLineAddress=QString::fromUtf16(dataPtr.Ptr(),
       
   295             dataPtr.Length());
       
   296     //fill address into lookup item.
       
   297     FillLookupItemAddressDetails( aLandmark, lookupItem );
       
   298 
       
   299     if ( aSourceType == ESourceLandmarks )
       
   300     {
       
   301         // Logic: check if the entry is already present in lookupdb. 
       
   302         // If present, it means the landmark corresponds to a contact/calendar. So ignore it.
       
   303         // If not present, it means the landmark is created directly into the landmarks db. So add
       
   304         // it in lookupdb as well.
       
   305         
       
   306         // check if the entry is already present in lookup db.
       
   307         QList<QLookupItem> itemArray;
       
   308         iLocationAppLookupDb->findEntriesByLandmarkId( aUid, itemArray );
       
   309         if( itemArray.count() )
       
   310         {
       
   311             return;
       
   312         }
       
   313         else
       
   314         {
       
   315             lookupItem.mDestId = aUid;
       
   316             iLocationAppLookupDb->createEntry( lookupItem );
       
   317             return;
       
   318         }
       
   319     }
       
   320 
       
   321     TPosLmItemId catId;
       
   322     if( aSourceType == ESourceCalendar )
       
   323     {
       
   324         // category id to calendar
       
   325         catId = iLmCalendarCatId;
       
   326     }
       
   327     else 
       
   328     {
       
   329         // remove landmark name, which is basically contact's name.
       
   330         aLandmark->SetLandmarkNameL( KNullDesC );
       
   331         // category id to contacts
       
   332         catId = iLmContactsCatId;
       
   333     }
       
   334     // check if this landmark is already present in database
       
   335     TPosLmItemId dupLmId = CheckIfDuplicateExistsL( aLandmark );
       
   336     if ( dupLmId )
       
   337     {
       
   338         // landmark already present in db. get the details
       
   339         CPosLandmark* dupLandmark = iLandmarkDb->ReadLandmarkLC(dupLmId);
       
   340         if( dupLandmark )
       
   341         {
       
   342             // add category.
       
   343             dupLandmark->AddCategoryL( catId );
       
   344             // update the landmark object in the db
       
   345             iLandmarkDb->UpdateLandmarkL( *dupLandmark );
       
   346             CleanupStack::PopAndDestroy( dupLandmark );
       
   347         }
       
   348 
       
   349         // point the lookup item's landmark uid to the existing landmark.
       
   350         lookupItem.mDestId = dupLmId;
       
   351         if( aSourceType == ESourceCalendar )
       
   352         {
       
   353             // set duplicate flag to true. only if it is calendar entry.
       
   354             // for contacts duplicate doesnot hold good as the location name is the contact name.
       
   355         
       
   356             // set duplicate only if there are calendar entries already pointing to this landmark. 
       
   357             if( IsDuplicateEntry( dupLmId ) )
       
   358             {
       
   359                 lookupItem.mIsDuplicate = 1;
       
   360             }
       
   361         }
       
   362     }
       
   363     else // it is a new entry, so add into the database
       
   364     {
       
   365         // add category.
       
   366         aLandmark->AddCategoryL( catId );
       
   367         // add the landmark into the db. 
       
   368         // point the lookup item's landmark uid to the newly created landmark in the db.
       
   369         lookupItem.mDestId = iLandmarkDb->AddLandmarkL( *aLandmark );
       
   370     }
       
   371 
       
   372     // create the entry in the lookup table.
       
   373     iLocationAppLookupDb->createEntry( lookupItem );
       
   374 }
       
   375 
       
   376 // -----------------------------------------------------------------------------
       
   377 // CMyLocationsDatabaseManager::HandleEntryModificationL()
       
   378 // Handles the entry modification in the lookup table and landmarks db.
       
   379 // -----------------------------------------------------------------------------
       
   380 //
       
   381 void CMyLocationsDatabaseManager::HandleEntryModificationL(
       
   382         CPosLandmark* aLandmark, const TUint32 aUid, const TUint32 aSourceType )
       
   383 {
       
   384     __TRACE_CALLSTACK;
       
   385     if ( aSourceType == ESourceLandmarks )
       
   386     {
       
   387         HandleLandmarkModificationL( aLandmark, aUid );
       
   388         return;
       
   389     }
       
   390 
       
   391     QLookupItem lookupItem;
       
   392     lookupItem.mSourceUid = aUid;
       
   393     lookupItem.mSourceType = aSourceType;
       
   394     lookupItem.mIconType = QLookupItem::EIconTypeDefault;
       
   395     TPtrC16 dataPtr;
       
   396     aLandmark->GetPositionField(EPositionFieldComment ,dataPtr);
       
   397     lookupItem.mSingleLineAddress=QString::fromUtf16(dataPtr.Ptr(),
       
   398             dataPtr.Length());
       
   399 
       
   400     // Behavior: If an entry is modified, 
       
   401     // If this entry is not present in lookup table. add the entry and update the landmarks db.
       
   402     // If this entry is already present in lookup table, check if the location info is modified or not.
       
   403     // If the location info is modified, delete the landmark from db and add the new landmark
       
   404     // into the db. 
       
   405     // Before deletion make sure that the landmark is not being refered by other lookup entries.
       
   406 
       
   407     // find the entry in the lookup table.
       
   408     if ( iLocationAppLookupDb->findEntryBySourceIdAndType( lookupItem ) )
       
   409     {
       
   410         //fill address into lookup item.
       
   411         FillLookupItemAddressDetails( aLandmark, lookupItem );
       
   412         
       
   413         QString locationName = lookupItem.mName;
       
   414     
       
   415         TPosLmItemId catId;
       
   416         
       
   417         if( aSourceType == ESourceCalendar )
       
   418         {
       
   419             catId = iLmCalendarCatId;
       
   420         }
       
   421         else
       
   422         {
       
   423             // remove landmark name, which is basically contact's name.
       
   424             aLandmark->SetLandmarkNameL( KNullDesC );
       
   425             
       
   426             // category id to contacts
       
   427             catId = iLmContactsCatId;
       
   428         }
       
   429 
       
   430         
       
   431         // check if the location info is modified by comparing the new landmark with the existing landmark
       
   432         CPosLandmark* existingLandmark = NULL;
       
   433         TRAPD( error, ( existingLandmark = 
       
   434                CheckAndReadLandmarkL( iLandmarkDb, lookupItem.mDestId ) ) );
       
   435         CleanupStack::PushL( existingLandmark );
       
   436         if ( error == KErrNotFound )
       
   437         {
       
   438             // Landmarks item deleted. So delete corresponding lookup entries.
       
   439             QList<QLookupItem> itemArray;
       
   440             iLocationAppLookupDb->findEntriesByLandmarkId( lookupItem.mDestId, itemArray );
       
   441             for ( int i = 0; i < itemArray.count(); i++)
       
   442             {
       
   443                 iLocationAppLookupDb->deleteEntryBySourceIdAndType( itemArray[i] );
       
   444             }
       
   445 
       
   446             // Add the entry into the lookup table and update landmarks db.
       
   447             HandleEntryAdditionL( aLandmark, aUid, aSourceType );
       
   448             
       
   449             CleanupStack::PopAndDestroy( existingLandmark );
       
   450             return;
       
   451         }
       
   452 
       
   453         if ( !CompareLandmarks( existingLandmark, aLandmark ) )
       
   454         {
       
   455             // landmarks are not same, means location information is modified.
       
   456 
       
   457             // Check if the new landmark is already in db.
       
   458             TPosLmItemId dupLmId = CheckIfDuplicateExistsL( aLandmark );
       
   459             if ( dupLmId )
       
   460             {
       
   461                 // landmark already present in db. get the details
       
   462                 CPosLandmark* dupLandmark = iLandmarkDb->ReadLandmarkLC( dupLmId );
       
   463                 if ( dupLandmark )
       
   464                 {
       
   465                     // add category.
       
   466                     dupLandmark->AddCategoryL( catId );
       
   467 
       
   468                     // update the landmark object in the db
       
   469                     iLandmarkDb->UpdateLandmarkL( *dupLandmark );
       
   470                 }
       
   471                 CleanupStack::PopAndDestroy( dupLandmark );
       
   472 
       
   473                 // update the lookup item to refer to the newly created landmark.
       
   474                 lookupItem.mDestId = dupLmId;
       
   475                 if( aSourceType == ESourceCalendar )
       
   476                 {
       
   477                     // for contacts duplicate doesnot hold good as the location name is the contact name.
       
   478                     if( !lookupItem.mIsDuplicate )
       
   479                     {
       
   480                         // if current lookup item duplicate property is 0, then remove next corresponding
       
   481                         // calendar lookup entry duplicate property.
       
   482                         // this is required because the current entry will be pointing to a new landmark.
       
   483                         UnsetDuplicateNextCalEntry( aUid, existingLandmark->LandmarkId() );
       
   484                     } 
       
   485 
       
   486                     // set duplicate only if there are calendar entries already pointing to this landmark. 
       
   487                     if( IsDuplicateEntry( dupLmId ) )
       
   488                     {
       
   489                         lookupItem.mIsDuplicate = 1;
       
   490                     }
       
   491 
       
   492                 }
       
   493                 
       
   494                 iLocationAppLookupDb->updateEntryBySourceIdAndType( lookupItem );
       
   495             }
       
   496             else
       
   497             {
       
   498                 // landmark not already present in db.
       
   499                 // Create a new entry in the db
       
   500                 aLandmark->AddCategoryL( catId );
       
   501                 lookupItem.mDestId = iLandmarkDb->AddLandmarkL( *aLandmark );
       
   502                 if( aSourceType == ESourceCalendar )
       
   503                 {
       
   504                     // for contacts duplicate doesnot hold good as the location name is the contact name.
       
   505                     if( !lookupItem.mIsDuplicate )
       
   506                     {
       
   507                         // if current lookup item duplicate property is 0, then remove next corresponding
       
   508                         // calendar lookup entry duplicate property.
       
   509                         // this is required because the current entry will be pointing to a new landmark.
       
   510                         UnsetDuplicateNextCalEntry( aUid, existingLandmark->LandmarkId() );
       
   511                     } 
       
   512                 }
       
   513                 
       
   514                 lookupItem.mIsDuplicate = 0;
       
   515                 // update the lookup table
       
   516                 iLocationAppLookupDb->updateEntryBySourceIdAndType( lookupItem );
       
   517             }
       
   518         }
       
   519         else
       
   520         {
       
   521             // landmarks are same, means location not modified. So return.
       
   522             if( aSourceType == ESourceContactsPref
       
   523                                     || aSourceType == ESourceContactsWork
       
   524                                     || aSourceType == ESourceContactsHome
       
   525                                     )
       
   526             {
       
   527                 // in case of contacts, there is a chance that contact name is modified. 
       
   528                 // so update the lookup database entry with that name.
       
   529                 lookupItem.mName = locationName;
       
   530                 iLocationAppLookupDb->updateEntryBySourceIdAndType( lookupItem );
       
   531             }
       
   532 
       
   533             CleanupStack::PopAndDestroy( existingLandmark );
       
   534             return;
       
   535         }
       
   536 
       
   537         // delete the existing landmark only if it not being refered by other lookup entries.
       
   538 
       
   539         // Check if any other entries are refering this landmark.
       
   540         QList<QLookupItem> itemArray;
       
   541         iLocationAppLookupDb->findEntriesByLandmarkId(
       
   542                 existingLandmark->LandmarkId(), itemArray );
       
   543 
       
   544         if ( itemArray.count() )
       
   545         {
       
   546             // There are other lookup entries refering this landmark. So do not delete the landmark
       
   547 
       
   548             // If none of these lookup item's source type is current source type, disassociate 'catId' category
       
   549             // from this landmark.
       
   550             TInt i = 0;
       
   551             while ( i < itemArray.count() )
       
   552             {
       
   553                 if( aSourceType == ESourceCalendar )
       
   554                 {
       
   555                     if ( itemArray[i].mSourceType == aSourceType )
       
   556                     {
       
   557                         // a lookup item exists which is from calendar, so 'catId' is still valid.
       
   558                         break;
       
   559                     }
       
   560                  }
       
   561                 else 
       
   562                 {
       
   563                     // a lookup item exists which is from contacts, so 'catId' is still valid.
       
   564                     break;
       
   565                 }
       
   566                 i++;
       
   567             }
       
   568             if ( i == itemArray.count() )
       
   569             {
       
   570                 // no lookup items from current source type exists refering this landmark.
       
   571                 // so disassociate 'catId' from this landmark
       
   572 
       
   573                 existingLandmark->RemoveCategory( catId );
       
   574                 iLandmarkDb->UpdateLandmarkL( *existingLandmark );
       
   575             }
       
   576         }
       
   577         else
       
   578         {
       
   579             // no other lookup entry is refering this landmark. 
       
   580             // delete the landmark.
       
   581             iLandmarkDb->RemoveLandmarkL( existingLandmark->LandmarkId() );
       
   582         }
       
   583         CleanupStack::PopAndDestroy( existingLandmark );
       
   584 
       
   585     }
       
   586     else // entry not present in lookup table
       
   587     {
       
   588         // Add the entry into the lookup table and update landmarks db.
       
   589         HandleEntryAdditionL( aLandmark, aUid, aSourceType );
       
   590     }
       
   591 }
       
   592 
       
   593 // -----------------------------------------------------------------------------
       
   594 // CMyLocationsDatabaseManager::HandleEntryDeletionL()
       
   595 // Handles the entry deletion in lookup table and landmarks db.
       
   596 // -----------------------------------------------------------------------------
       
   597 //
       
   598 void CMyLocationsDatabaseManager::HandleEntryDeletionL(const TUint32 aUid,
       
   599                                                 const TUint32 aSourceType)
       
   600 {
       
   601     __TRACE_CALLSTACK;
       
   602     QLookupItem lookupItem;
       
   603     lookupItem.mSourceUid = aUid;
       
   604     lookupItem.mSourceType = aSourceType;
       
   605 
       
   606     // Behavior: if an entry is deleted, delete the corresponding entries from 
       
   607     // both lookup table and iLandmarkDb.  
       
   608     // Before deleting the entry from iLandmarkDb, make sure that this entry is not being refered by
       
   609     // other entries of the lookup table. If it is being refered by other entries in lookup table, then
       
   610     // do not delete the landmark.
       
   611  
       
   612     if ( !iLocationAppLookupDb->findEntryBySourceIdAndType( lookupItem ) )
       
   613     {
       
   614         if( aSourceType == ESourceLandmarks )
       
   615         {
       
   616             lookupItem.mDestId = aUid;
       
   617         }
       
   618         else
       
   619         {
       
   620             return;
       
   621         }
       
   622     }
       
   623     
       
   624     // Find the corresponding landmark uid
       
   625     
       
   626 
       
   627     // delete the lookup entry.
       
   628     iLocationAppLookupDb->deleteEntryBySourceIdAndType( lookupItem );
       
   629 
       
   630     // Check if any other entries are refering this landmark.
       
   631     QList<QLookupItem> itemArray;
       
   632     iLocationAppLookupDb->findEntriesByLandmarkId( lookupItem.mDestId, itemArray );
       
   633 
       
   634     if ( itemArray.count() )
       
   635     {
       
   636     
       
   637         if( aSourceType == ESourceLandmarks )
       
   638         {
       
   639             CPosLandmark* lm = NULL;
       
   640         
       
   641             for( int i = 0; i < itemArray.count(); i++ )
       
   642             {
       
   643                 if( itemArray[i].mSourceType == ESourceCalendar )
       
   644                 {
       
   645                     // add landmark entry since a calendar item is present with this location.
       
   646                    if( !lm )
       
   647                    {
       
   648                        lm = CreateLandmarkItemLC( itemArray[i] );
       
   649                    }
       
   650                    lm->AddCategoryL( iLmCalendarCatId );
       
   651                 }
       
   652                 else
       
   653                 {
       
   654                    // add landmark entry since a contact item is present with this location.
       
   655                    if( !lm )
       
   656                    {
       
   657                        QString tempStr = itemArray[i].mName;
       
   658                        itemArray[i].mName = "";
       
   659                        lm = CreateLandmarkItemLC( itemArray[i] );
       
   660                        itemArray[i].mName = tempStr;
       
   661                    }
       
   662                    lm->AddCategoryL( iLmCalendarCatId );
       
   663                 }    
       
   664             }
       
   665 
       
   666             lookupItem.mDestId = iLandmarkDb->AddLandmarkL( *lm );
       
   667             CleanupStack::PopAndDestroy( lm );
       
   668 
       
   669             bool dupUnset = false;
       
   670             for( int i=0; i<itemArray.count(); i++ )
       
   671             {
       
   672                 itemArray[i].mDestId = lookupItem.mDestId;
       
   673                 if( itemArray[i].mSourceType == ESourceCalendar && dupUnset == false )
       
   674                 {
       
   675                     dupUnset = true;
       
   676                     itemArray[i].mIsDuplicate = 0;
       
   677                 }
       
   678                 iLocationAppLookupDb->updateEntryById( itemArray[i] );
       
   679             }   
       
   680             
       
   681             return;
       
   682         }
       
   683 
       
   684         // There are other lookup entries refering this landmark. So do not delete the landmark
       
   685 
       
   686         // If none of these lookup item's source type is current source type, disassociate current source category
       
   687         // from this landmark.
       
   688         TInt i = 0;
       
   689         while ( i < itemArray.count() )
       
   690         {
       
   691             if( aSourceType == ESourceCalendar )
       
   692             {
       
   693                 if( itemArray[i].mSourceType == aSourceType )
       
   694                 {
       
   695                     if( lookupItem.mIsDuplicate == 0 )
       
   696                     {
       
   697                         itemArray[i].mIsDuplicate = 0;
       
   698                         iLocationAppLookupDb->updateEntryById( itemArray[i] );
       
   699                     }
       
   700                     // a lookup item exists which is from calendar, so 'iLmCalendarCatId' is still valid.
       
   701                     break;
       
   702                 }
       
   703         
       
   704             }
       
   705             else if ( itemArray[i].mSourceType == ESourceContactsPref
       
   706                     || itemArray[i].mSourceType == ESourceContactsWork
       
   707                     || itemArray[i].mSourceType == ESourceContactsHome)
       
   708             {
       
   709                 // a lookup item exists which is from contacts, so 'iLmContactsCatId' is still valid.
       
   710                 break;
       
   711             }
       
   712             i++;
       
   713         }
       
   714         if ( i == itemArray.count() )
       
   715         {
       
   716             // no lookup items from current source type exists refering this landmark.
       
   717             // so disassociate current source category from this landmark
       
   718 
       
   719             CPosLandmark* landmark = iLandmarkDb->ReadLandmarkLC( lookupItem.mDestId );
       
   720             if( aSourceType == ESourceCalendar )
       
   721             {
       
   722                 landmark->RemoveCategory( iLmCalendarCatId );
       
   723             }
       
   724             else
       
   725             {
       
   726                 landmark->RemoveCategory( iLmContactsCatId );
       
   727             }
       
   728             
       
   729             iLandmarkDb->UpdateLandmarkL( *landmark );
       
   730             CleanupStack::PopAndDestroy( landmark );
       
   731         }
       
   732     }
       
   733     else
       
   734     {
       
   735         // no other lookup entry is refering this landmark. 
       
   736         // delete the landmark.
       
   737         if ( aSourceType != ESourceLandmarks )
       
   738         {
       
   739             iLandmarkDb->RemoveLandmarkL( lookupItem.mDestId );
       
   740         }
       
   741     }
       
   742 }
       
   743 
       
   744 // -----------------------------------------------------------------------------
       
   745 // CMyLocationsDatabaseManager::HandleLandmarkModificationL()
       
   746 // -----------------------------------------------------------------------------
       
   747 //
       
   748 void CMyLocationsDatabaseManager::HandleLandmarkModificationL(
       
   749         CPosLandmark* aLandmark, const TUint32 aUid )
       
   750 {
       
   751     __TRACE_CALLSTACK;
       
   752     // logic: if a landmark is modified, 
       
   753     // first update the corresponding landmark lookup entry if present, else create a new entry.
       
   754     // Check for any contact/calendar entries refering this landmark entry,
       
   755     // if exists, create a new landmark entry with that location details and update all those 
       
   756     // lookup entry's destid with the newly created landmark id.
       
   757     
       
   758     QLookupItem lookupItem;
       
   759     lookupItem.mSourceUid = aUid;
       
   760     lookupItem.mSourceType = ESourceLandmarks;
       
   761     lookupItem.mIconType = QLookupItem::EIconTypeDefault;
       
   762 
       
   763     bool found = iLocationAppLookupDb->findEntryBySourceIdAndType( lookupItem );
       
   764     //fill address into lookup item.
       
   765     FillLookupItemAddressDetails( aLandmark, lookupItem );
       
   766     lookupItem.mDestId = aUid;
       
   767     lookupItem.mIsDuplicate = 0;
       
   768     lookupItem.mIconType = QLookupItem::EIconTypeDefault;
       
   769     lookupItem.mIconPath = "";
       
   770     lookupItem.mMapTilePath = "";
       
   771 
       
   772     // update entry in lookup table.
       
   773     if ( found )
       
   774     {
       
   775         iLocationAppLookupDb->updateEntryById( lookupItem );
       
   776     }
       
   777     else
       
   778     {
       
   779         iLocationAppLookupDb->createEntry( lookupItem );
       
   780     }
       
   781     
       
   782     QList<QLookupItem> itemArray;
       
   783     iLocationAppLookupDb->findEntriesByLandmarkId( lookupItem.mDestId, itemArray );
       
   784     
       
   785     if( itemArray.count() == 1 )
       
   786     {
       
   787         //only one entry ie the entry corresponding to landmark db is present.
       
   788         return;
       
   789     }
       
   790     
       
   791     CPosLandmark* lm = NULL;
       
   792     
       
   793     for( int i = 0; i < itemArray.count(); i++ )
       
   794     {
       
   795         if( itemArray[i].mSourceType != ESourceLandmarks )
       
   796         {
       
   797             if( itemArray[i].mSourceType == ESourceCalendar )
       
   798             {
       
   799                 // add landmark entry since a calendar item is present with this location.
       
   800                if( !lm )
       
   801                {
       
   802                    lm = CreateLandmarkItemLC( itemArray[i] );
       
   803                }
       
   804                lm->AddCategoryL( iLmCalendarCatId );
       
   805             }
       
   806             else
       
   807             {
       
   808                // add landmark entry since a calendar item is present with this location.
       
   809                if( !lm )
       
   810                {
       
   811                    QString tempStr = itemArray[i].mName;
       
   812                    itemArray[i].mName = "";
       
   813                    lm = CreateLandmarkItemLC( itemArray[i] );
       
   814                    itemArray[i].mName = tempStr;
       
   815                }
       
   816                lm->AddCategoryL( iLmCalendarCatId );
       
   817             }    
       
   818         }
       
   819     }
       
   820     
       
   821     // add the entry to landmarks db
       
   822     quint32 newDestId = iLandmarkDb->AddLandmarkL( *lm );
       
   823     CleanupStack::PopAndDestroy( lm );
       
   824 
       
   825     bool calDuplicateUnset = false;
       
   826     // update all the lookup entries with new landmark id
       
   827     for( int i = 0; i < itemArray.count(); i++ )
       
   828     {
       
   829         if( itemArray[i].mSourceType != ESourceLandmarks )
       
   830         {
       
   831             itemArray[i].mDestId = newDestId;
       
   832             
       
   833             if( itemArray[i].mSourceType == ESourceCalendar )
       
   834             {
       
   835                 if( !calDuplicateUnset )
       
   836                 {
       
   837                     itemArray[i].mIsDuplicate = 0;
       
   838                     calDuplicateUnset = true;
       
   839                 }
       
   840                 else
       
   841                 {
       
   842                     itemArray[i].mIsDuplicate = 1;
       
   843                 }
       
   844             }
       
   845             iLocationAppLookupDb->updateEntryById( itemArray[i] );
       
   846         }
       
   847     }
       
   848 }
       
   849 // -----------------------------------------------------------------------------
       
   850 // CMyLocationsDatabaseManager::GetLandmarkFullAddress()
       
   851 // Gets the comma separated full address of the given landmark.
       
   852 // -----------------------------------------------------------------------------
       
   853 //
       
   854 EXPORT_C void CMyLocationsDatabaseManager::GetLandmarkFullAddress(
       
   855         TBuf<KMaxAddressLength>& aLandmarkAddress,
       
   856         const CPosLandmark* aLandmark)
       
   857 {
       
   858     __TRACE_CALLSTACK;
       
   859     TPtrC tempStr;
       
   860     TInt retStatus;
       
   861     TBool addressEmtpy = ETrue;
       
   862     aLandmarkAddress.Copy( KNullDesC );
       
   863     retStatus = aLandmark->GetPositionField(EPositionFieldStreet, tempStr);
       
   864     if (retStatus == KErrNone && tempStr.Length())
       
   865     {
       
   866         {
       
   867             aLandmarkAddress.Copy(tempStr);
       
   868             addressEmtpy = EFalse;
       
   869         }
       
   870     }
       
   871 
       
   872     retStatus = aLandmark->GetPositionField(EPositionFieldCity, tempStr);
       
   873     if (retStatus == KErrNone && tempStr.Length())
       
   874     {
       
   875         if (!addressEmtpy)
       
   876         {
       
   877             aLandmarkAddress.Append(KSeparator);
       
   878             aLandmarkAddress.Append(KSpace);
       
   879             aLandmarkAddress.Append(tempStr);
       
   880         }
       
   881         else
       
   882         {
       
   883             aLandmarkAddress.Copy(tempStr);
       
   884             addressEmtpy = EFalse;
       
   885         }
       
   886     }
       
   887 
       
   888     retStatus = aLandmark->GetPositionField(EPositionFieldState, tempStr);
       
   889     if (retStatus == KErrNone && tempStr.Length())
       
   890     {
       
   891         if (!addressEmtpy)
       
   892         {
       
   893             aLandmarkAddress.Append(KSeparator);
       
   894             aLandmarkAddress.Append(KSpace);
       
   895             aLandmarkAddress.Append(tempStr);
       
   896         }
       
   897         else
       
   898         {
       
   899             aLandmarkAddress.Copy(tempStr);
       
   900             addressEmtpy = EFalse;
       
   901         }
       
   902     }
       
   903 
       
   904     retStatus = aLandmark->GetPositionField(EPositionFieldCountry, tempStr);
       
   905     if (retStatus == KErrNone && tempStr.Length())
       
   906     {
       
   907         if (!addressEmtpy)
       
   908         {
       
   909             aLandmarkAddress.Append(KSeparator);
       
   910             aLandmarkAddress.Append(KSpace);
       
   911             aLandmarkAddress.Append(tempStr);
       
   912         }
       
   913         else
       
   914         {
       
   915             aLandmarkAddress.Copy(tempStr);
       
   916             addressEmtpy = EFalse;
       
   917         }
       
   918     }
       
   919 }
       
   920 
       
   921 // -----------------------------------------------------------------------------
       
   922 // CMyLocationsDatabaseManager::CheckAndReadLandmarkL()
       
   923 // Checks if given landmark id is found in the database and returns the read landmark.
       
   924 // -----------------------------------------------------------------------------
       
   925 //
       
   926 CPosLandmark* CMyLocationsDatabaseManager::CheckAndReadLandmarkL(
       
   927         CPosLandmarkDatabase* aDb, const TUint32 aLmId)
       
   928 {
       
   929     __TRACE_CALLSTACK;
       
   930     CPosLandmark* lm = aDb->ReadLandmarkLC(aLmId);
       
   931     CleanupStack::Pop(lm);    
       
   932     return lm;
       
   933 }
       
   934 
       
   935 // -----------------------------------------------------------------------------
       
   936 // CMyLocationsDatabaseManager::FillLookupItemAddressDetails()
       
   937 // Creates a new category in Mylocations Db and adds a corresponding entry in 
       
   938 // mylocations lookup table.
       
   939 // -----------------------------------------------------------------------------
       
   940 //
       
   941 void CMyLocationsDatabaseManager::FillLookupItemAddressDetails( CPosLandmark* aLandmark, QLookupItem& aLookupItem )
       
   942 {
       
   943     __TRACE_CALLSTACK;// Read the category.
       
   944 
       
   945     // fill geo-coordinates
       
   946     TLocality position;
       
   947     aLandmark->GetPosition( position );
       
   948     aLookupItem.mLatitude = position.Latitude();
       
   949     aLookupItem.mLongitude = position.Longitude();
       
   950 
       
   951     TPtrC tempStr;
       
   952     TInt retStatus;
       
   953 
       
   954     // Copy landmark name in address 1
       
   955     retStatus = aLandmark->GetLandmarkName( tempStr );
       
   956     aLookupItem.mName = "";
       
   957     if( retStatus == KErrNone && tempStr.Length() > 0 )
       
   958     {
       
   959         aLookupItem.mName = QString( (QChar*)tempStr.Ptr(), tempStr.Length() );
       
   960     }
       
   961 
       
   962     // get street
       
   963     aLookupItem.mStreet = "";
       
   964     retStatus = aLandmark->GetPositionField( EPositionFieldStreet, tempStr );
       
   965     if( retStatus == KErrNone && tempStr.Length() )
       
   966     {
       
   967         aLookupItem.mStreet = QString( (QChar*)tempStr.Ptr(), tempStr.Length());
       
   968     }
       
   969 
       
   970     // get postal code
       
   971     aLookupItem.mPostalCode = "";
       
   972     retStatus = aLandmark->GetPositionField( EPositionFieldPostalCode, tempStr );
       
   973     if( retStatus == KErrNone && tempStr.Length() )
       
   974     {
       
   975         aLookupItem.mPostalCode = QString( (QChar*)tempStr.Ptr(), tempStr.Length());
       
   976     }
       
   977 
       
   978     // get city
       
   979     aLookupItem.mCity = "";
       
   980     retStatus = aLandmark->GetPositionField( EPositionFieldCity, tempStr );
       
   981     if( retStatus == KErrNone && tempStr.Length() )
       
   982     {
       
   983         aLookupItem.mCity = QString( (QChar*)tempStr.Ptr(), tempStr.Length());
       
   984     }
       
   985 
       
   986     // get State
       
   987     aLookupItem.mState = "";
       
   988     retStatus = aLandmark->GetPositionField( EPositionFieldState, tempStr );
       
   989     if( retStatus == KErrNone && tempStr.Length() )
       
   990     {
       
   991         aLookupItem.mState = QString( (QChar*)tempStr.Ptr(), tempStr.Length());
       
   992     }
       
   993 
       
   994     // get country
       
   995     aLookupItem.mCountry = "";
       
   996     retStatus = aLandmark->GetPositionField( EPositionFieldCountry, tempStr );
       
   997     if( retStatus == KErrNone && tempStr.Length() )
       
   998     {
       
   999         aLookupItem.mCountry = QString( (QChar*)tempStr.Ptr(), tempStr.Length());
       
  1000     }
       
  1001 }
       
  1002 
       
  1003 // -----------------------------------------------------------------------------
       
  1004 // CMyLocationsDatabaseManager::UnsetDuplicateNextCalEntry()
       
  1005 // -----------------------------------------------------------------------------
       
  1006 //
       
  1007 void CMyLocationsDatabaseManager::UnsetDuplicateNextCalEntry( quint32 aUid, quint32 aLandmarkId )
       
  1008 {
       
  1009     __TRACE_CALLSTACK;
       
  1010     // get next duplicate item
       
  1011     QList<QLookupItem> itemArray;
       
  1012     iLocationAppLookupDb->findEntriesByLandmarkId( aLandmarkId, itemArray );
       
  1013     for ( int i = 0; i < itemArray.count(); i++)
       
  1014     {
       
  1015         if( itemArray[i].mSourceType == ESourceCalendar && itemArray[i].mSourceUid != aUid )
       
  1016         {
       
  1017             itemArray[i].mIsDuplicate = 0;
       
  1018             iLocationAppLookupDb->updateEntryById( itemArray[i] );
       
  1019             break;
       
  1020         }
       
  1021     }
       
  1022 
       
  1023 }
       
  1024 // -----------------------------------------------------------------------------
       
  1025 // CMyLocationsDatabaseManager::IsDuplicateEntry()
       
  1026 // -----------------------------------------------------------------------------
       
  1027 //
       
  1028 bool CMyLocationsDatabaseManager::IsDuplicateEntry( quint32 aLandmarkId )
       
  1029 {
       
  1030     __TRACE_CALLSTACK;
       
  1031     // get next duplicate item
       
  1032     QList<QLookupItem> itemArray;
       
  1033     iLocationAppLookupDb->findEntriesByLandmarkId( aLandmarkId, itemArray );
       
  1034     for ( int i = 0; i < itemArray.count(); i++)
       
  1035     {
       
  1036         if( itemArray[i].mSourceType == ESourceCalendar ||
       
  1037             itemArray[i].mSourceType == ESourceLandmarks )
       
  1038         {
       
  1039             return true;
       
  1040         }
       
  1041     }
       
  1042     
       
  1043     return false;
       
  1044 }
       
  1045 
       
  1046 // -----------------------------------------------------------------------------
       
  1047 // CMyLocationsDatabaseManager::CreateLandmarkItemLC()
       
  1048 // -----------------------------------------------------------------------------
       
  1049 //
       
  1050 CPosLandmark* CMyLocationsDatabaseManager::CreateLandmarkItemLC( const QLookupItem &aLookupItem )
       
  1051 {
       
  1052     __TRACE_CALLSTACK;//return value
       
  1053     CPosLandmark *landmark = NULL;
       
  1054     TLocality loc( TCoordinate( aLookupItem.mLatitude, aLookupItem.mLongitude ), 0 );
       
  1055 
       
  1056     landmark = CPosLandmark::NewL();
       
  1057     CleanupStack::PushL( landmark );
       
  1058 
       
  1059     // Fill the location details into the landmark object
       
  1060     landmark->SetPositionL( loc );
       
  1061 
       
  1062     // Set the landmark name as contact name
       
  1063     TBuf<KBufSize> text( aLookupItem.mName.utf16() );
       
  1064     TRAP_IGNORE( landmark->SetLandmarkNameL( text ) );
       
  1065 
       
  1066     text.Copy( aLookupItem.mStreet.utf16() );
       
  1067     landmark->SetPositionFieldL( EPositionFieldStreet, text );
       
  1068     
       
  1069     // Set the City
       
  1070     text.Copy( aLookupItem.mCity.utf16() );
       
  1071     landmark->SetPositionFieldL( EPositionFieldCity, text );
       
  1072 
       
  1073     // Set the state/region
       
  1074     text.Copy( aLookupItem.mState.utf16() );
       
  1075     landmark->SetPositionFieldL( EPositionFieldState, text );
       
  1076 
       
  1077     // Set the Postal code
       
  1078     text.Copy( aLookupItem.mPostalCode.utf16() );
       
  1079     landmark->SetPositionFieldL( EPositionFieldPostalCode, text );
       
  1080 
       
  1081     // Set the country
       
  1082     text.Copy( aLookupItem.mCountry.utf16() );
       
  1083     landmark->SetPositionFieldL( EPositionFieldCountry, text );
       
  1084 
       
  1085     return landmark;
       
  1086 }
       
  1087 
       
  1088 // -----------------------------------------------------------------------------
       
  1089 // CMyLocationsDatabaseManager::UpdateMapTilePath()
       
  1090 // -----------------------------------------------------------------------------
       
  1091 //
       
  1092 EXPORT_C void CMyLocationsDatabaseManager::UpdateMapTilePath( TUint32 aSourceId, TUint32 aSourceType, 
       
  1093                                             TFileName& aFilePath )
       
  1094 {
       
  1095     __TRACE_CALLSTACK;
       
  1096     QString filePath = QString( (QChar*)aFilePath.Ptr(), aFilePath.Length() );
       
  1097     iLocationAppLookupDb->updateMaptileBySourceIdAndType( aSourceId, aSourceType, filePath );
       
  1098 }
       
  1099 
       
  1100 // -----------------------------------------------------------------------------
       
  1101 // CMyLocationsDatabaseManager::UpdateEntryName()
       
  1102 // -----------------------------------------------------------------------------
       
  1103 //
       
  1104 EXPORT_C void CMyLocationsDatabaseManager::UpdateEntryName( TUint32 aSourceId, TUidSourceType aSourceType, 
       
  1105                                             const TDesC& aName )
       
  1106 {
       
  1107     __TRACE_CALLSTACK;
       
  1108     QString name = QString( (QChar*)aName.Ptr(), aName.Length() );
       
  1109     iLocationAppLookupDb->updateEntryNameByIdAndType( aSourceId, aSourceType, name );
       
  1110 	
       
  1111 }
       
  1112 
       
  1113 
       
  1114 // -----------------------------------------------------------------------------
       
  1115 // CMyLocationsDatabaseManager::CheckIfAddressChanged()
       
  1116 // -----------------------------------------------------------------------------
       
  1117 //
       
  1118 EXPORT_C TBool CMyLocationsDatabaseManager::CheckIfAddressChanged(const CPosLandmark& aLandmarks,
       
  1119         const TUint32 aId, const TUidSourceType aAddressType)
       
  1120 {
       
  1121     __TRACE_CALLSTACK;
       
  1122     QString target = iLocationAppLookupDb->getAddressDetails(aId, aAddressType);
       
  1123     TBuf<KMaxAddressLength> lmAddress;
       
  1124     GetLandmarkFullAddress(lmAddress, &aLandmarks);
       
  1125     QString source = QString((QChar*) lmAddress.Ptr(), lmAddress.Length());
       
  1126     if (source == target)
       
  1127     {
       
  1128         return EFalse;
       
  1129     }
       
  1130     return ETrue;
       
  1131 
       
  1132 }
       
  1133 
       
  1134 // -----------------------------------------------------------------------------
       
  1135 // CMyLocationsDatabaseManager::CheckIfAddressChanged()
       
  1136 // -----------------------------------------------------------------------------
       
  1137 //
       
  1138 EXPORT_C TBool CMyLocationsDatabaseManager::CheckIfAddressChanged(const TDesC& aAddress,
       
  1139         const TUint32 aId, const TUidSourceType aAddressType)
       
  1140 {   
       
  1141     __TRACE_CALLSTACK;
       
  1142     TBool compareStatus = ETrue;
       
  1143     QString target=iLocationAppLookupDb->getAddressDetails( aId , aAddressType );
       
  1144     QString source = QString( (QChar*)aAddress.Ptr(), aAddress.Length());
       
  1145     if( source == target )
       
  1146     {
       
  1147         compareStatus= EFalse;
       
  1148     }
       
  1149     return compareStatus;
       
  1150 }
       
  1151 
       
  1152 // End of file