meetingrequest/mrgui/src/cesmrlocationpluginhandler.cpp
changeset 0 8466d47a6819
child 1 12c456ceeff2
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2007 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:  ESMR Location plugin handler implementation
       
    15 *
       
    16 */
       
    17 #include "emailtrace.h"
       
    18 #include "cesmrlocationpluginhandler.h"
       
    19 
       
    20 #include <calentry.h>
       
    21 #include <StringLoader.h>
       
    22 #include <AknQueryDialog.h>
       
    23 #include <esmrgui.rsg>
       
    24 //<cmail>
       
    25 #include "cesmrurlparserplugin.h"
       
    26 //</cmail>
       
    27 #include <CLmkLandmarkSelectorDlg.h>
       
    28 #include <TLmkItemIdDbCombiInfo.h>
       
    29 #include <EPos_CPosLandmark.h>
       
    30 #include <AknUtils.h>
       
    31 #include <ct/rcpointerarray.h>
       
    32 
       
    33 #include "cesmrlocationplugin.h"
       
    34 #include "esmrcommands.h"
       
    35 #include "mesmrcalentry.h"
       
    36 
       
    37 #include "cesmrdynamicitemselectionlist.h"
       
    38 #include "cesmrlocationhistorymanager.h"
       
    39 #include "mesmrlocationhistoryitem.h"
       
    40 #include "cesmrconfirmationquery.h"
       
    41 
       
    42 // Unnamed namespace for local definitions
       
    43 namespace { //codescanner::namespace
       
    44 
       
    45 _LIT(KSpace, " ");
       
    46 
       
    47 // Maximum length of the text in location field
       
    48 const TInt KMaxLocationTextLength = 255;
       
    49 
       
    50 }
       
    51 
       
    52 // ============================ MEMBER FUNCTIONS ===============================
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // CESMRLocationPluginHandler::CESMRLocationPluginHandler
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 CESMRLocationPluginHandler::CESMRLocationPluginHandler( MObjectProvider& aParent )
       
    59 : iParent(&aParent)
       
    60 	{
       
    61     FUNC_LOG;
       
    62 	
       
    63 	}
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // CESMRLocationPluginHandler::~CESMRLocationPluginHandler
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 CESMRLocationPluginHandler::~CESMRLocationPluginHandler()
       
    70 	{
       
    71     FUNC_LOG;
       
    72     delete iWait;
       
    73     delete iLocationPlugin;
       
    74     delete iLandmark;
       
    75     delete iUrlParser;
       
    76 	delete iLocationHistoryManager;
       
    77 	}
       
    78 
       
    79 // -----------------------------------------------------------------------------
       
    80 // CESMRLocationPluginHandler::NewL
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 CESMRLocationPluginHandler* CESMRLocationPluginHandler::NewL( 
       
    84         MObjectProvider& aParent )
       
    85 	{
       
    86     FUNC_LOG;
       
    87 	CESMRLocationPluginHandler* self = 
       
    88 		new (ELeave) CESMRLocationPluginHandler( aParent );
       
    89 	CleanupStack::PushL( self );
       
    90 	self->ConstructL();
       
    91 	CleanupStack::Pop( self );
       
    92 	return self;
       
    93 	}
       
    94      
       
    95 // -----------------------------------------------------------------------------
       
    96 // CESMRLocationPluginHandler::ConstructL
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 void CESMRLocationPluginHandler::ConstructL()
       
   100 	{
       
   101     FUNC_LOG;
       
   102 	iWait = new( ELeave ) CActiveSchedulerWait;
       
   103 	}
       
   104 
       
   105 // -----------------------------------------------------------------------------
       
   106 // CESMRLocationPluginHandler::HandleCommandL
       
   107 // -----------------------------------------------------------------------------
       
   108 //
       
   109 TBool CESMRLocationPluginHandler::HandleCommandL( TInt aCommand,
       
   110 												 MESMRCalEntry& aEntry,
       
   111 												 TBool aIgnoreQuery )
       
   112 	{
       
   113     FUNC_LOG;
       
   114 	iIgnoreQuery = aIgnoreQuery;
       
   115 	iEntryUpdated = EFalse;
       
   116 	
       
   117 	switch ( aCommand )
       
   118 		{
       
   119 		case EESMRCmdAssignFromMap:
       
   120 			{
       
   121 			if( !(iWait->IsStarted()) )
       
   122 			    {
       
   123 			    const TDesC& location = aEntry.Entry().LocationL();
       
   124 			    
       
   125 			    // Extract location URL from description
       
   126 			    TPtrC locationUrl;
       
   127 			    UrlParserL().FindLocationUrl( aEntry.Entry().DescriptionL(),
       
   128 			                                  locationUrl );
       
   129 			    
       
   130 			    // Launch Maps
       
   131 			    LocationPluginL().SelectFromMapL( location, locationUrl );
       
   132 			    iWait->Start(); // codescanner::callActiveObjectWithoutCheckingOrStopping
       
   133 			    
       
   134 			    // iLandmark is set in async callback SelectFromMapCompleted
       
   135 			    // from Maps application.
       
   136 			    if ( iLandmark )
       
   137 			        {
       
   138 			        UpdateEntryFromLandmarkL( aEntry, *iLandmark );
       
   139 			        delete iLandmark;
       
   140 			        iLandmark = NULL;
       
   141 			        }
       
   142 			    }
       
   143 			}
       
   144 			break;
       
   145         case EESMRCmdUpdateFromMap:
       
   146             {
       
   147             if ( !(iWait->IsStarted()) )
       
   148                 {
       
   149                 // Launch Maps and ignore existing coordinates, 
       
   150                 // because location has been updated
       
   151                 LocationPluginL().SelectFromMapL( aEntry.Entry().LocationL(), 
       
   152                                                   KNullDesC );
       
   153                 iWait->Start(); // codescanner::callActiveObjectWithoutCheckingOrStopping
       
   154                                
       
   155                 // iLandmark is set in async callback SelectFromMapCompleted
       
   156                 // from Maps application.
       
   157                 if ( iLandmark )
       
   158                     {
       
   159                     UpdateEntryFromLandmarkL( aEntry, *iLandmark );
       
   160                     delete iLandmark;
       
   161                     iLandmark = NULL;
       
   162                     }                
       
   163                 }
       
   164             break;
       
   165             }
       
   166 		case EESMRCmdSearchFromMap:
       
   167 		    {
       
   168 		    const TDesC& location = aEntry.Entry().LocationL();
       
   169 		    LocationPluginL().SearchFromMapL( location );
       
   170 		    }		    
       
   171 		    break;
       
   172 		case EESMRCmdShowOnMap:
       
   173 		    {
       
   174 		    const TDesC& description = aEntry.Entry().DescriptionL();
       
   175 		    TPtrC locationUrl;
       
   176 		    TInt position = iUrlParser->FindLocationUrl( description,
       
   177 		                                                 locationUrl );
       
   178 		    if ( position >= 0 )
       
   179 		        {
       
   180 		        LocationPluginL().ShowOnMapL( locationUrl );
       
   181 		        }
       
   182 		    break;
       
   183 		    }
       
   184 		case EESMRCmdLandmarks:
       
   185 		    {
       
   186             SearchFromLandmarksL( iParent, aEntry );
       
   187 		    break;
       
   188 		    }
       
   189 		case EESMRCmdPreviousLocations:
       
   190 		    {
       
   191 		    ShowSelectPreviousLocationQueryL( aEntry );
       
   192 		    break;
       
   193 		    }
       
   194 		default:
       
   195 			User::Leave( KErrGeneral );
       
   196 		}
       
   197 	
       
   198 	return iEntryUpdated;
       
   199 	}
       
   200 
       
   201 // -----------------------------------------------------------------------------
       
   202 // CESMRLocationPluginHandler::IsCommandAvailableL
       
   203 // -----------------------------------------------------------------------------
       
   204 //
       
   205 TBool
       
   206 CESMRLocationPluginHandler::IsCommandAvailableL( TInt aCommand,
       
   207                                                  const MESMRCalEntry& aEntry )
       
   208     {
       
   209     FUNC_LOG;
       
   210     TBool res( EFalse );
       
   211     
       
   212     switch ( aCommand )
       
   213         {
       
   214         case EESMRCmdAssignFromMap: //fallthrough
       
   215         case EESMRCmdUpdateFromMap:
       
   216         case EESMRCmdSearchFromMap:
       
   217         case EESMRCmdLandmarks:
       
   218             {
       
   219             res = ETrue;
       
   220             break;
       
   221             }
       
   222         case EESMRCmdPreviousLocations:
       
   223             {
       
   224             if ( LocationHistoryManagerL().ItemCount() > 0 )
       
   225                 {
       
   226                 res = ETrue;
       
   227                 }
       
   228             break;
       
   229             }
       
   230         case EESMRCmdShowOnMap:
       
   231             {
       
   232             const TDesC& description = aEntry.Entry().DescriptionL();
       
   233             TPtrC locationUrl;
       
   234             TInt position = UrlParserL().FindLocationUrl( description,
       
   235                                                           locationUrl );
       
   236             if ( position >= 0 )
       
   237                 {
       
   238                 res = ETrue;
       
   239                 }
       
   240             break;
       
   241             }
       
   242         default:
       
   243             {
       
   244             break;
       
   245             }
       
   246         }
       
   247     
       
   248     return res;
       
   249     }
       
   250 
       
   251 // -----------------------------------------------------------------------------
       
   252 // CESMRLocationPluginHandler::StoreLocationToHistoryL
       
   253 // -----------------------------------------------------------------------------
       
   254 //
       
   255 void CESMRLocationPluginHandler::StoreLocationToHistoryL(
       
   256         const MESMRCalEntry& aEntry  )
       
   257     {
       
   258     FUNC_LOG;
       
   259     const CCalEntry& entry = aEntry.Entry();
       
   260     const TDesC& entryLocation = entry.LocationL();
       
   261     
       
   262     // Store location only if location field contains text.
       
   263     if ( entryLocation.Length() > 0 )
       
   264         {
       
   265         const TDesC& entryDescription = entry.DescriptionL();
       
   266         
       
   267         // Search for location url from description.
       
   268         TPtrC locationUrl;
       
   269         TInt position = UrlParserL().FindLocationUrl( entryDescription,
       
   270                                                       locationUrl );
       
   271         
       
   272         // If url was not found.
       
   273         if ( position < 0 )
       
   274             {
       
   275             locationUrl.Set( KNullDesC );
       
   276             }
       
   277         
       
   278         // Check if history item with same location and url
       
   279         // is already stored.
       
   280         TInt existingHistoryItemIndex = KErrNotFound;
       
   281         TInt itemCount = LocationHistoryManagerL().ItemCount();
       
   282         for ( TInt i = 0; i < itemCount; ++i )
       
   283             {
       
   284             const MESMRLocationHistoryItem& item =
       
   285                 iLocationHistoryManager->LocationHistoryItemL( i );
       
   286             
       
   287             if ( item.Address().Compare( entryLocation ) == 0 &&
       
   288                  item.Url().Compare( locationUrl ) == 0 )
       
   289                 {
       
   290                 existingHistoryItemIndex = i;
       
   291                 break;
       
   292                 }
       
   293             }
       
   294         
       
   295         // If history item with same location and url existed
       
   296         // update it's position in history array only.
       
   297         if ( existingHistoryItemIndex >= 0 )
       
   298             {
       
   299             // Ownership is not transferred,
       
   300             // existing item is already owned by location manager.
       
   301             const MESMRLocationHistoryItem& item =
       
   302                 iLocationHistoryManager->LocationHistoryItemL( existingHistoryItemIndex );
       
   303             
       
   304             iLocationHistoryManager->UpdateLocationHistoryL( &item );
       
   305             }
       
   306         else
       
   307             {
       
   308             // Create new history item.
       
   309             MESMRLocationHistoryItem* historyItem =
       
   310                 iLocationHistoryManager->CreateLocationHistoryItemL(
       
   311                             entryLocation,
       
   312                             locationUrl );
       
   313             
       
   314             // Store new item to history.
       
   315             CleanupDeletePushL( historyItem );
       
   316             iLocationHistoryManager->UpdateLocationHistoryL( historyItem );
       
   317             CleanupStack::Pop( historyItem );
       
   318             }
       
   319         }
       
   320     }
       
   321 
       
   322 // -----------------------------------------------------------------------------
       
   323 // CESMRLocationPluginHandler::UpdateEntryLocationL
       
   324 // -----------------------------------------------------------------------------
       
   325 //
       
   326 TBool CESMRLocationPluginHandler::UpdateEntryLocationL( MESMRCalEntry& aEntry,
       
   327                                                         const TDesC& aLocation,
       
   328                                                         TBool aIgnoreQuery )
       
   329     {
       
   330     FUNC_LOG;
       
   331     TBool entryUpdated = EFalse;
       
   332     
       
   333     if ( aLocation.Length() > 0 )
       
   334         {
       
   335         CCalEntry& entry = aEntry.Entry();
       
   336         const TDesC& location = entry.LocationL();
       
   337         
       
   338         // Replace old location field content.
       
   339         TBool replace = ETrue;
       
   340         
       
   341         if ( !aIgnoreQuery
       
   342              && location.Length() > 0
       
   343              && location != aLocation )
       
   344             {
       
   345             // Query for replacing old location field content 
       
   346             replace = CESMRConfirmationQuery::ExecuteL( location ); 
       
   347             }
       
   348         
       
   349         // If previous location was empty or user selects to
       
   350         // replace previous location with new one.
       
   351         if (  location.Length() == 0 || replace )
       
   352             {
       
   353             entry.SetLocationL( aLocation.Left( KMaxLocationTextLength ) );
       
   354             entryUpdated = ETrue;                
       
   355             }
       
   356         else
       
   357             {
       
   358             // Concatenate new address to existing one
       
   359             // Create CPtrCArray for existing and new location strings
       
   360             CPtrCArray* strings = new( ELeave ) CPtrCArray( 2 );
       
   361             CleanupStack::PushL( strings );
       
   362             strings->AppendL( TPtrC( location ) );
       
   363             strings->AppendL( TPtrC( aLocation ) );
       
   364             HBufC* newLocation =
       
   365                 StringLoader::LoadLC( R_MEET_REQ_NEW_LOCATION_FORMAT,
       
   366                                       *strings );
       
   367             entry.SetLocationL( newLocation->Left( KMaxLocationTextLength ) );
       
   368             entryUpdated = ETrue;
       
   369             CleanupStack::PopAndDestroy( 2, strings );
       
   370             }
       
   371         }
       
   372     
       
   373     return entryUpdated;
       
   374     }
       
   375 
       
   376 // -----------------------------------------------------------------------------
       
   377 // From MESMRLocationPluginObserver
       
   378 // CESMRLocationPluginHandler::SelectFromMapCompleted
       
   379 // -----------------------------------------------------------------------------
       
   380 //
       
   381 void CESMRLocationPluginHandler::SelectFromMapCompleted( TInt aError,
       
   382                                                          CPosLandmark* aLandmark )
       
   383 	{
       
   384     FUNC_LOG;
       
   385 	// Remove previous landmark if one is set.
       
   386     if ( iLandmark )
       
   387         {
       
   388         delete iLandmark;
       
   389         iLandmark = NULL;
       
   390         }
       
   391 	
       
   392 	if ( aError == KErrNone )
       
   393 		{
       
   394 		// pointer to the result of landmark fetch
       
   395 		iLandmark = aLandmark;
       
   396 		}
       
   397 	
       
   398 	if ( iWait->IsStarted() )
       
   399 		{
       
   400 		iWait->AsyncStop();
       
   401 		}
       
   402 	}
       
   403 // -----------------------------------------------------------------------------
       
   404 // CESMRLocationPluginHandler::LocationPluginL
       
   405 // -----------------------------------------------------------------------------
       
   406 //
       
   407 CESMRLocationPlugin& CESMRLocationPluginHandler::LocationPluginL()
       
   408 	{
       
   409     FUNC_LOG;
       
   410 	if ( !iLocationPlugin )
       
   411 		{
       
   412 		// Lazy construction of Location ECom plugin
       
   413 		iLocationPlugin = CESMRLocationPlugin::NewL();
       
   414 		iLocationPlugin->SetObserver(this);
       
   415 		}
       
   416 	
       
   417 	return *iLocationPlugin;
       
   418 	}
       
   419 
       
   420 // ---------------------------------------------------------------------------
       
   421 // Creates adress descriptor from a  landmark object
       
   422 // ---------------------------------------------------------------------------
       
   423 //
       
   424 HBufC* CESMRLocationPluginHandler::CreateAddressFromLandmarkL( 
       
   425                                                const CPosLandmark& aLandmark )
       
   426     {
       
   427     FUNC_LOG;
       
   428     CPtrCArray* addressStrings = new( ELeave ) CPtrCArray( 2 );
       
   429     CleanupStack::PushL( addressStrings );
       
   430     
       
   431     TBool streetAvailable = aLandmark.IsPositionFieldAvailable( EPositionFieldStreet );
       
   432     TBool cityAvailable = aLandmark.IsPositionFieldAvailable( EPositionFieldCity );
       
   433     
       
   434     if ( streetAvailable )
       
   435         {
       
   436         TPtrC streetPtr( KNullDesC );
       
   437         User::LeaveIfError( aLandmark.GetPositionField( EPositionFieldStreet,
       
   438                                                          streetPtr ) );
       
   439         if ( streetPtr.Length() > 0 )
       
   440             {
       
   441             addressStrings->AppendL( streetPtr );
       
   442             }
       
   443         }
       
   444 
       
   445     if ( cityAvailable )
       
   446         {
       
   447         TPtrC cityPtr( KNullDesC );
       
   448         User::LeaveIfError( aLandmark.GetPositionField( EPositionFieldCity,
       
   449                                                          cityPtr ) );
       
   450         if ( cityPtr.Length() > 0 )
       
   451             {
       
   452             addressStrings->AppendL( cityPtr );
       
   453             }
       
   454         }
       
   455     
       
   456     HBufC* address(NULL);
       
   457     
       
   458     if ( addressStrings->Count() == 2 )
       
   459         {
       
   460         //format street and city to buffer
       
   461         address = StringLoader::LoadL( R_MEET_REQ_ADDRESS_STREET_CITY, 
       
   462                                        *addressStrings );
       
   463         }
       
   464     else if ( addressStrings->Count() == 1 )
       
   465         {
       
   466         // alloc street or city to buffer
       
   467         address = addressStrings->At( 0 ).AllocL();
       
   468         }
       
   469     else if ( addressStrings->Count() == 0 )
       
   470         {
       
   471         TPtrC namePtr( KNullDesC );
       
   472         User::LeaveIfError( aLandmark.GetLandmarkName( namePtr ));
       
   473         if ( namePtr.Length() > 0)
       
   474             {
       
   475             address = namePtr.AllocL();
       
   476             }
       
   477         }
       
   478     
       
   479     CleanupStack::PopAndDestroy( addressStrings );                       
       
   480     
       
   481     //Transfer ownership of address
       
   482     return address;
       
   483     }
       
   484 
       
   485 // -----------------------------------------------------------------------------
       
   486 // CESMRLocationPluginHandler::UpdateEntryFromLandmarkL
       
   487 // Updates location information into calendar entry from aLandmark.
       
   488 // -----------------------------------------------------------------------------
       
   489 //
       
   490 void CESMRLocationPluginHandler::UpdateEntryFromLandmarkL( MESMRCalEntry& aEntry, const CPosLandmark& aLandmark )
       
   491 	{
       
   492     FUNC_LOG;
       
   493     //parse and add address to calendar entry
       
   494     HBufC* streetAddress = CreateAddressFromLandmarkL( aLandmark );
       
   495     if ( streetAddress )
       
   496         {
       
   497         CleanupDeletePushL( streetAddress );
       
   498         UpdateEntryLocationL( aEntry, *streetAddress );
       
   499         CleanupStack::PopAndDestroy( streetAddress );
       
   500         }
       
   501     
       
   502     //parse and add location url to calendar entry
       
   503     HBufC* locationUrl = NULL;
       
   504     TRAP_IGNORE( locationUrl = UrlParserL().CreateUrlFromLandmarkL( aLandmark ) )
       
   505     if ( locationUrl )
       
   506         {
       
   507         CleanupDeletePushL( locationUrl );
       
   508         UpdateEntryDescriptionL( aEntry, *locationUrl );
       
   509         CleanupStack::PopAndDestroy( locationUrl );
       
   510         }
       
   511     
       
   512 	}
       
   513 
       
   514 // -----------------------------------------------------------------------------
       
   515 // CESMRLocationPluginHandler::SearchFromLandmarksL
       
   516 // -----------------------------------------------------------------------------
       
   517 //
       
   518 void CESMRLocationPluginHandler::SearchFromLandmarksL( MObjectProvider* aParent, MESMRCalEntry& aEntry )
       
   519     {
       
   520     FUNC_LOG;
       
   521     CLmkLandmarkSelectorDlg* landmarkDlg = CLmkLandmarkSelectorDlg::NewL();
       
   522     CleanupStack::PushL( landmarkDlg );
       
   523     landmarkDlg->SetMopParent( aParent );
       
   524     TLmkItemIdDbCombiInfo selectedItem;
       
   525     
       
   526     // Execute landmark selection dialog
       
   527     TInt isAccepted = landmarkDlg->ExecuteLD( selectedItem );
       
   528     CleanupStack::Pop( landmarkDlg );
       
   529     if ( isAccepted != 0 )
       
   530         {
       
   531         TPosLmItemId itemId = selectedItem.GetItemId();
       
   532         CPosLandmarkDatabase* lmDataBase = selectedItem.GetLmDb();
       
   533         CleanupStack::PushL( lmDataBase );
       
   534         
       
   535         // Read selected landmark from landmarks database
       
   536         CPosLandmark* landmark = lmDataBase->ReadLandmarkLC( itemId );
       
   537         UpdateEntryFromLandmarkL( aEntry, *landmark );
       
   538         CleanupStack::PopAndDestroy( landmark );
       
   539         CleanupStack::PopAndDestroy( lmDataBase ); 
       
   540         ReleaseLandmarkResources();
       
   541         }
       
   542     }
       
   543 
       
   544 // -----------------------------------------------------------------------------
       
   545 // CESMRLocationPluginHandler::ShowSelectPreviousLocationQueryL
       
   546 // Shows "Previous locations" query and updates aEntry
       
   547 // according to selection.
       
   548 // -----------------------------------------------------------------------------
       
   549 //
       
   550 void CESMRLocationPluginHandler::ShowSelectPreviousLocationQueryL( MESMRCalEntry& aEntry )
       
   551     {
       
   552     FUNC_LOG;
       
   553     // Array for listbox items.
       
   554     RCPointerArray<HBufC> addressArray;
       
   555     CleanupClosePushL( addressArray );
       
   556     
       
   557     // Populate address array.
       
   558     TInt itemCount = LocationHistoryManagerL().ItemCount();
       
   559     for ( TInt i = 0; i < itemCount; ++i )
       
   560         {
       
   561         const MESMRLocationHistoryItem& item =
       
   562             iLocationHistoryManager->LocationHistoryItemL( i );
       
   563         HBufC* address = item.Address().AllocLC();
       
   564         addressArray.AppendL( address );
       
   565         CleanupStack::Pop( address );
       
   566         }
       
   567     
       
   568     CESMRDynamicItemSelectionList* selectionQuery =
       
   569             CESMRDynamicItemSelectionList::NewL();
       
   570     CleanupStack::PushL( selectionQuery );
       
   571     
       
   572     // Execute selection query.
       
   573     TInt idx = selectionQuery->ExecuteL( addressArray,
       
   574             CESMRDynamicItemSelectionList::EESMRRecentLocationList );
       
   575     
       
   576     CleanupStack::PopAndDestroy( selectionQuery );
       
   577     
       
   578     if ( idx >= 0 && idx < addressArray.Count() )
       
   579         {
       
   580         const MESMRLocationHistoryItem& item =
       
   581             iLocationHistoryManager->LocationHistoryItemL( idx );
       
   582         
       
   583         // Update entry location.
       
   584         const TDesC& selectedLocation = item.Address();
       
   585         UpdateEntryLocationL( aEntry, selectedLocation );
       
   586         
       
   587         // Update entry description if url available.
       
   588         const TDesC& selectedLocationUrl = item.Url();
       
   589         if ( selectedLocationUrl.Length() > 0 )
       
   590             {
       
   591             UpdateEntryDescriptionL( aEntry, selectedLocationUrl );
       
   592             }
       
   593         }
       
   594     
       
   595     CleanupStack::PopAndDestroy( &addressArray );
       
   596     }
       
   597 
       
   598 // -----------------------------------------------------------------------------
       
   599 // CESMRLocationPluginHandler::UpdateEntryLocationL
       
   600 // Updates aEntry location with aLocation.
       
   601 // -----------------------------------------------------------------------------
       
   602 //
       
   603 void CESMRLocationPluginHandler::UpdateEntryLocationL(
       
   604         MESMRCalEntry& aEntry, const TDesC& aLocation )
       
   605     {
       
   606     FUNC_LOG;
       
   607     iEntryUpdated |= UpdateEntryLocationL( aEntry, aLocation, iIgnoreQuery );
       
   608     }
       
   609 
       
   610 // -----------------------------------------------------------------------------
       
   611 // CESMRLocationPluginHandler::UpdateEntryDescriptionL
       
   612 // Updates aEntry description with aLocationUrl.
       
   613 // -----------------------------------------------------------------------------
       
   614 //
       
   615 void CESMRLocationPluginHandler::UpdateEntryDescriptionL(
       
   616         MESMRCalEntry& aEntry, const TDesC& aLocationUrl )
       
   617     {
       
   618     FUNC_LOG;
       
   619     if ( aLocationUrl.Length() > 0 )
       
   620         {
       
   621         CCalEntry& entry = aEntry.Entry();
       
   622         HBufC* description = HBufC::NewL( entry.DescriptionL().Length() + 
       
   623                              aLocationUrl.Length() + 1);
       
   624         CleanupStack::PushL( description );
       
   625         TPtr descriptionPointer( description->Des() );
       
   626         TPtrC urlPointer;
       
   627         TInt position;
       
   628         position = UrlParserL().FindLocationUrl( entry.DescriptionL(), urlPointer);
       
   629         
       
   630         if ( position >= KErrNone )
       
   631             {
       
   632             descriptionPointer.Copy( entry.DescriptionL() );
       
   633             if ( ( position > 0 ) && ( entry.DescriptionL().Length() > 
       
   634                                         (position + aLocationUrl.Length() ) ) )
       
   635                 {
       
   636                 descriptionPointer.Delete( position, ( urlPointer.Length() + 1 ) );
       
   637                 }
       
   638             else
       
   639                 {
       
   640                 descriptionPointer.Delete( position, urlPointer.Length() );
       
   641                 }
       
   642             descriptionPointer.Insert( 0, aLocationUrl );
       
   643             if ( position > 0 )
       
   644                 {
       
   645                 descriptionPointer.Insert( aLocationUrl.Length(), KSpace );
       
   646                 }
       
   647             entry.SetDescriptionL( *description );
       
   648             iEntryUpdated = ETrue;
       
   649             }
       
   650         else
       
   651             {
       
   652             descriptionPointer.Copy( entry.DescriptionL() );
       
   653             descriptionPointer.Insert( 0, aLocationUrl );
       
   654             if ( entry.DescriptionL().Length() != 0 )
       
   655                 {
       
   656                 descriptionPointer.Insert( aLocationUrl.Length(), KSpace );
       
   657                 }
       
   658             entry.SetDescriptionL( *description );
       
   659             iEntryUpdated = ETrue;
       
   660             }
       
   661         CleanupStack::PopAndDestroy( description );
       
   662         }
       
   663     }
       
   664 
       
   665 // -----------------------------------------------------------------------------
       
   666 // CESMRLocationPluginHandler::UrlParserL
       
   667 // Creates and returns location URL parser.
       
   668 // -----------------------------------------------------------------------------
       
   669 //
       
   670 CESMRUrlParserPlugin& CESMRLocationPluginHandler::UrlParserL()
       
   671     {
       
   672     FUNC_LOG;
       
   673     if ( !iUrlParser )
       
   674         {
       
   675         iUrlParser = CESMRUrlParserPlugin::NewL();
       
   676         }
       
   677     
       
   678     return *iUrlParser;
       
   679     }
       
   680 
       
   681 // -----------------------------------------------------------------------------
       
   682 // CESMRLocationPluginHandler::LocationHistoryManagerL
       
   683 // Creates and returns location history manager.
       
   684 // -----------------------------------------------------------------------------
       
   685 //
       
   686 CESMRLocationHistoryManager& CESMRLocationPluginHandler::LocationHistoryManagerL()
       
   687     {
       
   688     FUNC_LOG;
       
   689     if ( !iLocationHistoryManager )
       
   690         {
       
   691         iLocationHistoryManager = CESMRLocationHistoryManager::NewL();
       
   692         }
       
   693     
       
   694     return *iLocationHistoryManager;
       
   695     }
       
   696 
       
   697 // EOF
       
   698