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