--- a/meetingrequest/mrgui/src/cesmrlocationpluginhandler.cpp Mon Mar 15 12:39:10 2010 +0200
+++ b/meetingrequest/mrgui/src/cesmrlocationpluginhandler.cpp Wed Mar 31 21:08:33 2010 +0300
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
@@ -16,20 +16,25 @@
*/
#include "emailtrace.h"
#include "cesmrlocationpluginhandler.h"
+#include "esmrconfig.hrh"
#include <calentry.h>
-#include <StringLoader.h>
-#include <AknQueryDialog.h>
+#include <stringloader.h>
+#include <aknquerydialog.h>
#include <esmrgui.rsg>
//<cmail>
#include "cesmrurlparserplugin.h"
//</cmail>
-#include <CLmkLandmarkSelectorDlg.h>
-#include <TLmkItemIdDbCombiInfo.h>
-#include <EPos_CPosLandmark.h>
-#include <AknUtils.h>
+#include <clmklandmarkselectordlg.h>
+#include <tlmkitemiddbcombiinfo.h>
+#include <epos_cposlandmark.h>
+#include <aknutils.h>
#include <ct/rcpointerarray.h>
+#ifdef RD_USE_MYLOCATIONUI
+#include <mylocationui.h>
+#endif //RD_USE_MYLOCATIONUI
+
#include "cesmrlocationplugin.h"
#include "esmrcommands.h"
#include "mesmrcalentry.h"
@@ -57,101 +62,91 @@
//
CESMRLocationPluginHandler::CESMRLocationPluginHandler( MObjectProvider& aParent )
: iParent(&aParent)
- {
+ {
FUNC_LOG;
-
- }
+
+ }
// -----------------------------------------------------------------------------
// CESMRLocationPluginHandler::~CESMRLocationPluginHandler
// -----------------------------------------------------------------------------
//
CESMRLocationPluginHandler::~CESMRLocationPluginHandler()
- {
+ {
FUNC_LOG;
delete iWait;
delete iLocationPlugin;
delete iLandmark;
delete iUrlParser;
- delete iLocationHistoryManager;
- }
+ delete iLocationHistoryManager;
+ }
// -----------------------------------------------------------------------------
// CESMRLocationPluginHandler::NewL
// -----------------------------------------------------------------------------
//
-CESMRLocationPluginHandler* CESMRLocationPluginHandler::NewL(
+CESMRLocationPluginHandler* CESMRLocationPluginHandler::NewL(
MObjectProvider& aParent )
- {
+ {
FUNC_LOG;
- CESMRLocationPluginHandler* self =
- new (ELeave) CESMRLocationPluginHandler( aParent );
- CleanupStack::PushL( self );
- self->ConstructL();
- CleanupStack::Pop( self );
- return self;
- }
-
+ CESMRLocationPluginHandler* self =
+ new (ELeave) CESMRLocationPluginHandler( aParent );
+ CleanupStack::PushL( self );
+ self->ConstructL();
+ CleanupStack::Pop( self );
+ return self;
+ }
+
// -----------------------------------------------------------------------------
// CESMRLocationPluginHandler::ConstructL
// -----------------------------------------------------------------------------
//
void CESMRLocationPluginHandler::ConstructL()
- {
+ {
FUNC_LOG;
- iWait = new( ELeave ) CActiveSchedulerWait;
- }
+ iWait = new( ELeave ) CActiveSchedulerWait;
+ }
// -----------------------------------------------------------------------------
// CESMRLocationPluginHandler::HandleCommandL
// -----------------------------------------------------------------------------
//
TBool CESMRLocationPluginHandler::HandleCommandL( TInt aCommand,
- MESMRCalEntry& aEntry,
- TBool aIgnoreQuery )
- {
+ MESMRCalEntry& aEntry,
+ TBool aIgnoreQuery )
+ {
FUNC_LOG;
- iIgnoreQuery = aIgnoreQuery;
- iEntryUpdated = EFalse;
-
- switch ( aCommand )
- {
- case EESMRCmdAssignFromMap:
- {
- if( !(iWait->IsStarted()) )
- {
- const TDesC& location = aEntry.Entry().LocationL();
-
- // Extract location URL from description
- TPtrC locationUrl;
- UrlParserL().FindLocationUrl( aEntry.Entry().DescriptionL(),
- locationUrl );
-
- // Launch Maps
- LocationPluginL().SelectFromMapL( location, locationUrl );
- iWait->Start(); // codescanner::callActiveObjectWithoutCheckingOrStopping
-
- // iLandmark is set in async callback SelectFromMapCompleted
- // from Maps application.
- if ( iLandmark )
- {
- UpdateEntryFromLandmarkL( aEntry, *iLandmark );
- delete iLandmark;
- iLandmark = NULL;
- }
- }
- }
- break;
- case EESMRCmdUpdateFromMap:
+ iIgnoreQuery = aIgnoreQuery;
+ iEntryUpdated = EFalse;
+
+ switch ( aCommand )
+ {
+ case EESMRCmdAssignFromMap:
{
- if ( !(iWait->IsStarted()) )
+ if( !(iWait->IsStarted()) )
{
- // Launch Maps and ignore existing coordinates,
- // because location has been updated
- LocationPluginL().SelectFromMapL( aEntry.Entry().LocationL(),
- KNullDesC );
+ CCalEntry& entry = aEntry.Entry();
+ const TDesC& location = entry.LocationL();
+
+ CCalGeoValue* geoVal = entry.GeoValueL();
+
+ if ( geoVal )
+ {
+ // Launch Maps
+ LocationPluginL().SelectFromMapL( location, geoVal );
+ }
+ else
+ {
+ // Extract location URL from description
+ TPtrC locationUrl;
+ UrlParserL().FindLocationUrl( entry.DescriptionL(),
+ locationUrl );
+
+ // Launch Maps
+ LocationPluginL().SelectFromMapL( location, locationUrl );
+ }
iWait->Start(); // codescanner::callActiveObjectWithoutCheckingOrStopping
-
+
// iLandmark is set in async callback SelectFromMapCompleted
// from Maps application.
if ( iLandmark )
@@ -159,45 +154,96 @@
UpdateEntryFromLandmarkL( aEntry, *iLandmark );
delete iLandmark;
iLandmark = NULL;
- }
+ }
+ }
+ }
+ break;
+ case EESMRCmdUpdateFromMap:
+ {
+ if ( !(iWait->IsStarted()) )
+ {
+ // Launch Maps and ignore existing coordinates,
+ // because location has been updated
+ LocationPluginL().SelectFromMapL( aEntry.Entry().LocationL(),
+ KNullDesC );
+ iWait->Start(); // codescanner::callActiveObjectWithoutCheckingOrStopping
+
+ // iLandmark is set in async callback SelectFromMapCompleted
+ // from Maps application.
+ if ( iLandmark )
+ {
+ UpdateEntryFromLandmarkL( aEntry, *iLandmark );
+ delete iLandmark;
+ iLandmark = NULL;
+ }
}
break;
}
- case EESMRCmdSearchFromMap:
- {
- const TDesC& location = aEntry.Entry().LocationL();
- LocationPluginL().SearchFromMapL( location );
- }
- break;
- case EESMRCmdShowOnMap:
- {
- const TDesC& description = aEntry.Entry().DescriptionL();
- TPtrC locationUrl;
- TInt position = iUrlParser->FindLocationUrl( description,
- locationUrl );
- const TDesC& location = aEntry.Entry().LocationL();
- if ( position >= 0 )
- {
- LocationPluginL().ShowOnMapL( location, locationUrl );
- }
- break;
- }
- case EESMRCmdLandmarks:
- {
+ case EESMRCmdSearchFromMap:
+ {
+ const TDesC& location = aEntry.Entry().LocationL();
+ LocationPluginL().SearchFromMapL( location );
+ }
+ break;
+ case EESMRCmdShowOnMap:
+ {
+ CCalGeoValue* geoVal = aEntry.Entry().GeoValueL();
+ TReal lat, lon;
+ if ( geoVal && geoVal->GetLatLong( lat, lon ) )
+ {
+ LocationPluginL().ShowOnMapL( *geoVal );
+ }
+ else
+ {
+ const TDesC& description = aEntry.Entry().DescriptionL();
+ TPtrC locationUrl;
+ TInt position = UrlParserL().FindLocationUrl( description,
+ locationUrl );
+ if ( position >= 0 )
+ {
+ LocationPluginL().ShowOnMapL( locationUrl );
+ }
+ }
+ break;
+ }
+ case EESMRCmdLandmarks:
+ {
SearchFromLandmarksL( iParent, aEntry );
- break;
- }
- case EESMRCmdPreviousLocations:
- {
- ShowSelectPreviousLocationQueryL( aEntry );
- break;
- }
- default:
- User::Leave( KErrGeneral );
- }
-
- return iEntryUpdated;
- }
+ break;
+ }
+ case EESMRCmdPreviousLocations:
+ {
+ ShowSelectPreviousLocationQueryL( aEntry );
+ break;
+ }
+ case EMRCommandMyLocations:
+ {
+#ifdef RD_USE_MYLOCATIONUI
+ CMyLocationSelectorUi* ui = CMyLocationSelectorUi::NewL();
+ CleanupStack::PushL( ui );
+
+ CPosLandmark* landmark = ui->LaunchMyLocationSelectorUiL();
+
+ if ( landmark )
+ {
+ CleanupStack::PushL( landmark );
+ UpdateEntryFromLandmarkL( aEntry, *landmark );
+ CleanupStack::PopAndDestroy( landmark );
+ }
+
+ CleanupStack::PopAndDestroy( ui );
+#else // RD_USE_MYLOCATIONUI
+ ASSERT( EFalse );
+#endif //RD_USE_MYLOCATIONUI
+ break;
+ }
+
+ default:
+ User::Leave( KErrGeneral );
+ }
+
+ return iEntryUpdated;
+ }
// -----------------------------------------------------------------------------
// CESMRLocationPluginHandler::IsCommandAvailableL
@@ -209,7 +255,7 @@
{
FUNC_LOG;
TBool res( EFalse );
-
+
switch ( aCommand )
{
case EESMRCmdAssignFromMap: //fallthrough
@@ -230,22 +276,41 @@
}
case EESMRCmdShowOnMap:
{
- const TDesC& description = aEntry.Entry().DescriptionL();
- TPtrC locationUrl;
- TInt position = UrlParserL().FindLocationUrl( description,
- locationUrl );
- if ( position >= 0 )
+ // Try to fetch vCal GEO value from entry
+ CCalGeoValue* geoVal = aEntry.Entry().GeoValueL();
+ TReal lat, lon;
+ if ( geoVal && geoVal->GetLatLong( lat, lon ) )
{
res = ETrue;
}
+ else
+ {
+ // Check if description field has location url
+ const TDesC& description = aEntry.Entry().DescriptionL();
+ TPtrC locationUrl;
+ TInt position = UrlParserL().FindLocationUrl( description,
+ locationUrl );
+ if ( position >= 0 )
+ {
+ res = ETrue;
+ }
+ }
+
break;
}
+#ifdef RD_USE_MYLOCATIONUI
+ case EMRCommandMyLocations:
+ {
+ res = ETrue;
+ break;
+ }
+#endif
default:
{
break;
}
}
-
+
return res;
}
@@ -259,23 +324,23 @@
FUNC_LOG;
const CCalEntry& entry = aEntry.Entry();
const TDesC& entryLocation = entry.LocationL();
-
+
// Store location only if location field contains text.
if ( entryLocation.Length() > 0 )
{
const TDesC& entryDescription = entry.DescriptionL();
-
+
// Search for location url from description.
TPtrC locationUrl;
TInt position = UrlParserL().FindLocationUrl( entryDescription,
locationUrl );
-
+
// If url was not found.
if ( position < 0 )
{
locationUrl.Set( KNullDesC );
}
-
+
// Check if history item with same location and url
// is already stored.
TInt existingHistoryItemIndex = KErrNotFound;
@@ -284,7 +349,7 @@
{
const MESMRLocationHistoryItem& item =
iLocationHistoryManager->LocationHistoryItemL( i );
-
+
if ( item.Address().Compare( entryLocation ) == 0 &&
item.Url().Compare( locationUrl ) == 0 )
{
@@ -292,7 +357,7 @@
break;
}
}
-
+
// If history item with same location and url existed
// update it's position in history array only.
if ( existingHistoryItemIndex >= 0 )
@@ -301,7 +366,7 @@
// existing item is already owned by location manager.
const MESMRLocationHistoryItem& item =
iLocationHistoryManager->LocationHistoryItemL( existingHistoryItemIndex );
-
+
iLocationHistoryManager->UpdateLocationHistoryL( &item );
}
else
@@ -311,7 +376,7 @@
iLocationHistoryManager->CreateLocationHistoryItemL(
entryLocation,
locationUrl );
-
+
// Store new item to history.
CleanupDeletePushL( historyItem );
iLocationHistoryManager->UpdateLocationHistoryL( historyItem );
@@ -326,33 +391,35 @@
//
TBool CESMRLocationPluginHandler::UpdateEntryLocationL( MESMRCalEntry& aEntry,
const TDesC& aLocation,
- TBool aIgnoreQuery )
+ TBool aIgnoreQuery,
+ TBool& aLocationReplaced )
{
FUNC_LOG;
TBool entryUpdated = EFalse;
-
+
if ( aLocation.Length() > 0 )
{
CCalEntry& entry = aEntry.Entry();
const TDesC& location = entry.LocationL();
-
+
// Replace old location field content.
TBool replace = ETrue;
-
+
if ( !aIgnoreQuery
&& location.Length() > 0
&& location != aLocation )
{
- // Query for replacing old location field content
- replace = CESMRConfirmationQuery::ExecuteL( location );
+ // Query for replacing old location field content
+ replace = CESMRConfirmationQuery::ExecuteL( location );
}
-
+
// If previous location was empty or user selects to
// replace previous location with new one.
if ( location.Length() == 0 || replace )
{
entry.SetLocationL( aLocation.Left( KMaxLocationTextLength ) );
- entryUpdated = ETrue;
+ entryUpdated = ETrue;
+ aLocationReplaced = ETrue;
}
else
{
@@ -370,7 +437,7 @@
CleanupStack::PopAndDestroy( 2, strings );
}
}
-
+
return entryUpdated;
}
@@ -381,57 +448,57 @@
//
void CESMRLocationPluginHandler::SelectFromMapCompleted( TInt aError,
CPosLandmark* aLandmark )
- {
+ {
FUNC_LOG;
- // Remove previous landmark if one is set.
+ // Remove previous landmark if one is set.
if ( iLandmark )
{
delete iLandmark;
iLandmark = NULL;
}
-
- if ( aError == KErrNone )
- {
- // pointer to the result of landmark fetch
- iLandmark = aLandmark;
- }
-
- if ( iWait->IsStarted() )
- {
- iWait->AsyncStop();
- }
- }
+
+ if ( aError == KErrNone )
+ {
+ // pointer to the result of landmark fetch
+ iLandmark = aLandmark;
+ }
+
+ if ( iWait->IsStarted() )
+ {
+ iWait->AsyncStop();
+ }
+ }
// -----------------------------------------------------------------------------
// CESMRLocationPluginHandler::LocationPluginL
// -----------------------------------------------------------------------------
//
CESMRLocationPlugin& CESMRLocationPluginHandler::LocationPluginL()
- {
+ {
FUNC_LOG;
- if ( !iLocationPlugin )
- {
- // Lazy construction of Location ECom plugin
- iLocationPlugin = CESMRLocationPlugin::NewL();
- iLocationPlugin->SetObserver(this);
- }
-
- return *iLocationPlugin;
- }
+ if ( !iLocationPlugin )
+ {
+ // Lazy construction of Location ECom plugin
+ iLocationPlugin = CESMRLocationPlugin::NewL();
+ iLocationPlugin->SetObserver(this);
+ }
+
+ return *iLocationPlugin;
+ }
// ---------------------------------------------------------------------------
// Creates adress descriptor from a landmark object
// ---------------------------------------------------------------------------
//
-HBufC* CESMRLocationPluginHandler::CreateAddressFromLandmarkL(
+HBufC* CESMRLocationPluginHandler::CreateAddressFromLandmarkL(
const CPosLandmark& aLandmark )
{
FUNC_LOG;
CPtrCArray* addressStrings = new( ELeave ) CPtrCArray( 2 );
CleanupStack::PushL( addressStrings );
-
+
TBool streetAvailable = aLandmark.IsPositionFieldAvailable( EPositionFieldStreet );
TBool cityAvailable = aLandmark.IsPositionFieldAvailable( EPositionFieldCity );
-
+
if ( streetAvailable )
{
TPtrC streetPtr( KNullDesC );
@@ -453,13 +520,13 @@
addressStrings->AppendL( cityPtr );
}
}
-
+
HBufC* address(NULL);
-
+
if ( addressStrings->Count() == 2 )
{
//format street and city to buffer
- address = StringLoader::LoadL( R_MEET_REQ_ADDRESS_STREET_CITY,
+ address = StringLoader::LoadL( R_MEET_REQ_ADDRESS_STREET_CITY,
*addressStrings );
}
else if ( addressStrings->Count() == 1 )
@@ -476,9 +543,9 @@
address = namePtr.AllocL();
}
}
-
- CleanupStack::PopAndDestroy( addressStrings );
-
+
+ CleanupStack::PopAndDestroy( addressStrings );
+
//Transfer ownership of address
return address;
}
@@ -488,8 +555,10 @@
// Updates location information into calendar entry from aLandmark.
// -----------------------------------------------------------------------------
//
-void CESMRLocationPluginHandler::UpdateEntryFromLandmarkL( MESMRCalEntry& aEntry, const CPosLandmark& aLandmark )
- {
+void CESMRLocationPluginHandler::UpdateEntryFromLandmarkL(
+ MESMRCalEntry& aEntry,
+ const CPosLandmark& aLandmark )
+ {
FUNC_LOG;
//parse and add address to calendar entry
HBufC* streetAddress = CreateAddressFromLandmarkL( aLandmark );
@@ -499,18 +568,38 @@
UpdateEntryLocationL( aEntry, *streetAddress );
CleanupStack::PopAndDestroy( streetAddress );
}
-
- //parse and add location url to calendar entry
- HBufC* locationUrl = NULL;
- TRAP_IGNORE( locationUrl = UrlParserL().CreateUrlFromLandmarkL( aLandmark ) )
- if ( locationUrl )
+
+ CCalEntry& entry = aEntry.Entry();
+ TLocality locality;
+ if ( aLandmark.GetPosition( locality ) == KErrNone )
{
+ // Store GEO value to entry
+ CCalGeoValue* geoVal = CCalGeoValue::NewL();
+ CleanupStack::PushL( geoVal );
+ geoVal->SetLatLongL( locality.Latitude(), locality.Longitude() );
+ entry.SetGeoValueL( *geoVal );
+ CleanupStack::PopAndDestroy( geoVal );
+
+ //parse and add location url to calendar entry
+ HBufC* locationUrl = UrlParserL().CreateUrlFromLandmarkL( aLandmark );
CleanupDeletePushL( locationUrl );
UpdateEntryDescriptionL( aEntry, *locationUrl );
CleanupStack::PopAndDestroy( locationUrl );
}
-
- }
+ else if ( iLocationReplaced )// Location field content from this landmark
+ {
+ // Clear GEO value and location URL
+ entry.ClearGeoValueL();
+ const TDesC& description = entry.DescriptionL();
+ TPtrC url;
+ TInt pos = UrlParserL().FindLocationUrl( description, url );
+ if ( pos > KErrNotFound )
+ {
+ TPtrC desc = description.Mid( pos + url.Length() );
+ entry.SetDescriptionL( desc );
+ }
+ }
+ }
// -----------------------------------------------------------------------------
// CESMRLocationPluginHandler::SearchFromLandmarksL
@@ -523,7 +612,7 @@
CleanupStack::PushL( landmarkDlg );
landmarkDlg->SetMopParent( aParent );
TLmkItemIdDbCombiInfo selectedItem;
-
+
// Execute landmark selection dialog
TInt isAccepted = landmarkDlg->ExecuteLD( selectedItem );
CleanupStack::Pop( landmarkDlg );
@@ -532,12 +621,12 @@
TPosLmItemId itemId = selectedItem.GetItemId();
CPosLandmarkDatabase* lmDataBase = selectedItem.GetLmDb();
CleanupStack::PushL( lmDataBase );
-
+
// Read selected landmark from landmarks database
CPosLandmark* landmark = lmDataBase->ReadLandmarkLC( itemId );
UpdateEntryFromLandmarkL( aEntry, *landmark );
CleanupStack::PopAndDestroy( landmark );
- CleanupStack::PopAndDestroy( lmDataBase );
+ CleanupStack::PopAndDestroy( lmDataBase );
ReleaseLandmarkResources();
}
}
@@ -554,7 +643,7 @@
// Array for listbox items.
RCPointerArray<HBufC> addressArray;
CleanupClosePushL( addressArray );
-
+
// Populate address array.
TInt itemCount = LocationHistoryManagerL().ItemCount();
for ( TInt i = 0; i < itemCount; ++i )
@@ -565,26 +654,26 @@
addressArray.AppendL( address );
CleanupStack::Pop( address );
}
-
+
CESMRDynamicItemSelectionList* selectionQuery =
CESMRDynamicItemSelectionList::NewL();
CleanupStack::PushL( selectionQuery );
-
+
// Execute selection query.
TInt idx = selectionQuery->ExecuteL( addressArray,
CESMRDynamicItemSelectionList::EESMRRecentLocationList );
-
+
CleanupStack::PopAndDestroy( selectionQuery );
-
+
if ( idx >= 0 && idx < addressArray.Count() )
{
const MESMRLocationHistoryItem& item =
iLocationHistoryManager->LocationHistoryItemL( idx );
-
+
// Update entry location.
const TDesC& selectedLocation = item.Address();
UpdateEntryLocationL( aEntry, selectedLocation );
-
+
// Update entry description if url available.
const TDesC& selectedLocationUrl = item.Url();
if ( selectedLocationUrl.Length() > 0 )
@@ -592,7 +681,7 @@
UpdateEntryDescriptionL( aEntry, selectedLocationUrl );
}
}
-
+
CleanupStack::PopAndDestroy( &addressArray );
}
@@ -605,7 +694,10 @@
MESMRCalEntry& aEntry, const TDesC& aLocation )
{
FUNC_LOG;
- iEntryUpdated |= UpdateEntryLocationL( aEntry, aLocation, iIgnoreQuery );
+ iEntryUpdated |= UpdateEntryLocationL( aEntry,
+ aLocation,
+ iIgnoreQuery,
+ iLocationReplaced );
}
// -----------------------------------------------------------------------------
@@ -620,18 +712,18 @@
if ( aLocationUrl.Length() > 0 )
{
CCalEntry& entry = aEntry.Entry();
- HBufC* description = HBufC::NewL( entry.DescriptionL().Length() +
+ HBufC* description = HBufC::NewL( entry.DescriptionL().Length() +
aLocationUrl.Length() + 1);
CleanupStack::PushL( description );
TPtr descriptionPointer( description->Des() );
TPtrC urlPointer;
TInt position;
position = UrlParserL().FindLocationUrl( entry.DescriptionL(), urlPointer);
-
+
if ( position >= KErrNone )
{
descriptionPointer.Copy( entry.DescriptionL() );
- if ( ( position > 0 ) && ( entry.DescriptionL().Length() >
+ if ( ( position > 0 ) && ( entry.DescriptionL().Length() >
(position + aLocationUrl.Length() ) ) )
{
descriptionPointer.Delete( position, ( urlPointer.Length() + 1 ) );
@@ -675,7 +767,7 @@
{
iUrlParser = CESMRUrlParserPlugin::NewL();
}
-
+
return *iUrlParser;
}
@@ -691,7 +783,7 @@
{
iLocationHistoryManager = CESMRLocationHistoryManager::NewL();
}
-
+
return *iLocationHistoryManager;
}