diff -r a3a1ae9acec6 -r da5135c61bad meetingrequest/mrgui/mrlocationplugin/src/cesmrlocationpluginimpl.cpp --- a/meetingrequest/mrgui/mrlocationplugin/src/cesmrlocationpluginimpl.cpp Mon Mar 15 12:39:10 2010 +0200 +++ b/meetingrequest/mrgui/mrlocationplugin/src/cesmrlocationpluginimpl.cpp Wed Mar 31 21:08:33 2010 +0300 @@ -1,5 +1,5 @@ /* -* Copyright (c) 2008-2008 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,21 +16,50 @@ */ -#include "emailtrace.h" +#include "cesmrlocationpluginimpl.h" +#include "mesmrlocationpluginobserver.h" +#include "cesmrurlparserplugin.h" + #include #include -// -#include "mnmapview.h" -#include -#include +#include +#include +#include #include -#include "cesmrurlparserplugin.h" -// #include +#include + +#include "emailtrace.h" + +// ======== LOCAL FUNCTIONS ======== -#include "cesmrlocationpluginimpl.h" -#include "mesmrlocationpluginobserver.h" +namespace + { +/** + * Converts vCal GEO value to landmark with coordinates + * + * @param aGeoValue coordinates + * @return a landmark with coordinates + */ +CPosLandmark* CreateLandmarkL( const CCalGeoValue& aGeoValue ) + { + TReal lat; + TReal lon; + if( !aGeoValue.GetLatLong( lat, lon ) ) + { + User::Leave( KErrArgument ); + } + + CPosLandmark* landmark = CPosLandmark::NewLC(); + TLocality coordinate; + coordinate.SetCoordinate( lat, lon ); + landmark->SetPositionL( coordinate ); + CleanupStack::Pop( landmark ); + return landmark; + } + + } // ======== MEMBER FUNCTIONS ======== // --------------------------------------------------------------------------- @@ -38,7 +67,7 @@ // --------------------------------------------------------------------------- // CESMRLocationPluginImpl::CESMRLocationPluginImpl() - : CESMRLocationPlugin( CActive::EPriorityStandard ) + : CESMRLocationPlugin( CActive::EPriorityStandard ) { FUNC_LOG; } @@ -54,23 +83,20 @@ RCPointerArray providers; CleanupClosePushL( providers ); MnProviderFinder::FindProvidersL( providers, - CMnProvider::EServiceMapView - | CMnProvider::EServiceNavigation - | CMnProvider::EServiceGeocoding ); + CMnProvider::EServiceMapView + | CMnProvider::EServiceNavigation ); if ( providers.Count() == 0 ) - { - User::Leave( KErrNotSupported ); - } + { + User::Leave( KErrNotSupported ); + } iProvider = providers[ 0 ]; - providers.Remove( 0 ); + providers.Remove( 0 ); // PopAndDestroy provides from cleanupstack CleanupStack::PopAndDestroy( &providers ); - + // Create Map & Navigation view CreateMapViewL(); - - iUrlParser = CESMRUrlParserPlugin::NewL(); - + CActiveScheduler::Add( this ); } @@ -113,7 +139,7 @@ } delete iProvider; delete iUrlParser; - + iLandMarks.ResetAndDestroy(); } @@ -137,66 +163,38 @@ // --------------------------------------------------------------------------- // void CESMRLocationPluginImpl::SelectFromMapL( const TDesC& aSearchQuery, - const TDesC& aLocationUrl ) - { + const TDesC& aLocationUrl ) + { FUNC_LOG; - iLandMarks.ResetAndDestroy(); - - if ( IsActive() ) - { - User::Leave( KErrInUse ); - } - - CreateMapViewL(); - - iMapView->ResetMapArea(); - - // Create landmark from location URL. TRAP errors because URL is optional. - CPosLandmark* location = NULL; - TRAP_IGNORE( location = //codescanner::forgottoputptroncleanupstack - iUrlParser->CreateLandmarkFromUrlL( aLocationUrl ) ) - - if ( location ) // Landmark created. Set search string as landmark name - { - if ( aSearchQuery.Length() > 0 ) - { - CleanupStack::PushL( location ); - - location->SetLandmarkNameL( aSearchQuery ); - - iLandMarks.AppendL( location ); - CleanupStack::Pop( location ); - - iMapView->ResetLandmarksToShow(); - iMapView->AddLandmarksToShowL( iLandMarks ); - } - } - else + + // Create landmark from location URL. TRAP errors because URL is optional. + CPosLandmark* location = NULL; + TRAP_IGNORE( location = //codescanner::forgottoputptroncleanupstack + UrlParserL().CreateLandmarkFromUrlL( aLocationUrl ) ) + + SelectFromMapL( aSearchQuery, location ); + } + +// --------------------------------------------------------------------------- +// CESMRLocationPluginImpl::SelectFromMapL +// From class MESMRLocationPlugin. +// --------------------------------------------------------------------------- +// +void CESMRLocationPluginImpl::SelectFromMapL( + const TDesC& aSearchQuery, + const CCalGeoValue* aGeoValue ) + { + FUNC_LOG; + + CPosLandmark* location = NULL; + + if ( aGeoValue ) { - // No location url provided, let's search from maps - // with search string. It was agreed that search is done by - // passing a landmark with search string as the name of the landmark - // forward - if ( aSearchQuery.Length() > 0 ) - { - location = CPosLandmark::NewLC(); - location->SetLandmarkNameL( aSearchQuery ); + location = CreateLandmarkL( *aGeoValue ); + } - iLandMarks.AppendL( location ); - CleanupStack::Pop( location ); - - iMapView->ResetLandmarksToShow(); - iMapView->AddLandmarksToShowL( iLandMarks ); - } - - // Enable current location focus on map - iMapView-> - SetCurrentLocationOption( CMnMapView::ECurrentLocationEnabled ); - } - - SetActive(); - iMapView->SelectFromMapL( iStatus ); - } + SelectFromMapL( aSearchQuery, location ); + } // --------------------------------------------------------------------------- // CESMRLocationPluginImpl::SearchFromMapL @@ -207,13 +205,13 @@ { FUNC_LOG; iLandMarks.ResetAndDestroy(); - + CPosLandmark* location = CPosLandmark::NewLC(); location->SetLandmarkNameL( aSearchQuery ); iLandMarks.AppendL( location ); CleanupStack::Pop( location ); - + iMapView->ResetLandmarksToShow(); iMapView->AddLandmarksToShowL( iLandMarks ); iMapView->ShowMapL(); @@ -224,23 +222,27 @@ // From class MESMRLocationPlugin. // --------------------------------------------------------------------------- // -void CESMRLocationPluginImpl::ShowOnMapL( const TDesC& aLocation, const TDesC& aLocationUrl ) - { +void CESMRLocationPluginImpl::ShowOnMapL( const TDesC& aLocationUrl ) + { FUNC_LOG; - CreateMapViewL(); + + CPosLandmark* landmark = + UrlParserL().CreateLandmarkFromUrlL( aLocationUrl ); + ShowLandmarkL( landmark ); + } - iMapView->ResetLandmarksToShow(); - RCPointerArray landmarks; - CleanupClosePushL( landmarks ); - CPosLandmark* landmark = iUrlParser->CreateLandmarkFromUrlL( aLocationUrl ); - landmark->SetLandmarkNameL(aLocation); - CleanupStack::PushL( landmark ); - landmarks.AppendL( landmark ); - CleanupStack::Pop( landmark ); - iMapView->AddLandmarksToShowL( landmarks ); - CleanupStack::PopAndDestroy( &landmarks ); - iMapView->ShowMapL(); - } +// --------------------------------------------------------------------------- +// CESMRLocationPluginImpl::ShowOnMapL +// From class MESMRLocationPlugin. +// --------------------------------------------------------------------------- +// +void CESMRLocationPluginImpl::ShowOnMapL( const CCalGeoValue& aGeoValue ) + { + FUNC_LOG; + + CPosLandmark* landmark = CreateLandmarkL( aGeoValue ); + ShowLandmarkL( landmark ); + } // --------------------------------------------------------------------------- // CESMRLocationPluginImpl::DoCancel @@ -252,9 +254,9 @@ { FUNC_LOG; if( iMapView ) - { - iMapView->Cancel(); - } + { + iMapView->Cancel(); + } } // --------------------------------------------------------------------------- @@ -268,7 +270,7 @@ FUNC_LOG; HandleSelectFromMapCompletedL(); } - + // --------------------------------------------------------------------------- // CESMRLocationPluginImpl::HandleSelectFromMapCompletedL // --------------------------------------------------------------------------- @@ -280,7 +282,7 @@ { CMnMapView::TSelectionResultType type; type = iMapView->SelectionResultType(); - + if ( iObserver ) { switch ( type ) @@ -288,9 +290,9 @@ case CMnMapView::ESelectionFreeLandmark: { // Read selection from map view, send result to observer - CPosLandmark* landmark = + CPosLandmark* landmark = iMapView->RetrieveSelectionResultL(); - iObserver->SelectFromMapCompleted( iStatus.Int(), + iObserver->SelectFromMapCompleted( iStatus.Int(), landmark ); break; } @@ -298,11 +300,11 @@ { TInt landmarkIndex = 0; iMapView->RetrieveSelectionResultL( landmarkIndex ); - + if ( landmarkIndex < iLandMarks.Count() ) { - iObserver->SelectFromMapCompleted( - iStatus.Int(), + iObserver->SelectFromMapCompleted( + iStatus.Int(), iLandMarks[landmarkIndex] ); iLandMarks.Remove( landmarkIndex ); } @@ -326,9 +328,9 @@ iObserver->SelectFromMapCompleted( iStatus.Int(), NULL ); } - // Close Map view + // Close Map view delete iMapView; - iMapView = NULL; + iMapView = NULL; } // --------------------------------------------------------------------------- @@ -337,20 +339,20 @@ // --------------------------------------------------------------------------- // TInt CESMRLocationPluginImpl::RunError( TInt aError ) - { + { FUNC_LOG; - // Notify error to observer - if(iObserver) - { - iObserver->SelectFromMapCompleted( aError, NULL ); - } - - // Close Map view - delete iMapView; - iMapView = NULL; - - return KErrNone; - } + // Notify error to observer + if(iObserver) + { + iObserver->SelectFromMapCompleted( aError, NULL ); + } + + // Close Map view + delete iMapView; + iMapView = NULL; + + return KErrNone; + } // --------------------------------------------------------------------------- // CESMRLocationPluginImpl::HandleServerAppExit @@ -361,14 +363,111 @@ { FUNC_LOG; Cancel(); - + if ( iObserver ) { // Notify observer that application has been closed without selection. iObserver->SelectFromMapCompleted( aReason, NULL ); } - + delete iMapView; iMapView = NULL; } +// --------------------------------------------------------------------------- +// CESMRLocationPluginImpl::ShowLandmarkL +// --------------------------------------------------------------------------- +// +void CESMRLocationPluginImpl::SelectFromMapL( + const TDesC& aSearchQuery, + CPosLandmark* aLandmark ) + { + iLandMarks.ResetAndDestroy(); + + if ( IsActive() ) + { + User::Leave( KErrInUse ); + } + + CreateMapViewL(); + + iMapView->ResetMapArea(); + + CPosLandmark* location = aLandmark; + + if ( location ) // Landmark created. Set search string as landmark name + { + if ( aSearchQuery.Length() > 0 ) + { + CleanupStack::PushL( location ); + + location->SetLandmarkNameL( aSearchQuery ); + + iLandMarks.AppendL( location ); + CleanupStack::Pop( location ); + + iMapView->ResetLandmarksToShow(); + iMapView->AddLandmarksToShowL( iLandMarks ); + } + } + else + { + // No location url provided, let's search from maps + // with search string. It was agreed that search is done by + // passing a landmark with search string as the name of the landmark + // forward + if ( aSearchQuery.Length() > 0 ) + { + location = CPosLandmark::NewLC(); + location->SetLandmarkNameL( aSearchQuery ); + + iLandMarks.AppendL( location ); + CleanupStack::Pop( location ); + + iMapView->ResetLandmarksToShow(); + iMapView->AddLandmarksToShowL( iLandMarks ); + } + + // Enable current location focus on map + iMapView-> + SetCurrentLocationOption( CMnMapView::ECurrentLocationEnabled ); + } + + SetActive(); + iMapView->SelectFromMapL( iStatus ); + } + +// --------------------------------------------------------------------------- +// CESMRLocationPluginImpl::ShowLandmarkL +// --------------------------------------------------------------------------- +// +void CESMRLocationPluginImpl::ShowLandmarkL( CPosLandmark* aLandmark ) + { + CreateMapViewL(); + + iMapView->ResetLandmarksToShow(); + RCPointerArray landmarks; + CleanupClosePushL( landmarks ); + CleanupStack::PushL( aLandmark ); + landmarks.AppendL( aLandmark ); + CleanupStack::Pop( aLandmark ); + iMapView->AddLandmarksToShowL( landmarks ); + CleanupStack::PopAndDestroy( &landmarks ); + iMapView->ShowMapL(); + } + +// --------------------------------------------------------------------------- +// CESMRLocationPluginImpl::UrlParserL +// --------------------------------------------------------------------------- +// +CESMRUrlParserPlugin& CESMRLocationPluginImpl::UrlParserL() + { + if ( !iUrlParser ) + { + iUrlParser = CESMRUrlParserPlugin::NewL(); + } + + return *iUrlParser; + } + +// EOF