meetingrequest/mrgui/mrlocationplugin/src/cesmrlocationpluginimpl.cpp
changeset 0 8466d47a6819
child 1 12c456ceeff2
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2008-2008 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:  Location plugin implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "emailtrace.h"
       
    20 #include <mnproviderfinder.h>
       
    21 #include <mnprovider.h>
       
    22 //<cmail>
       
    23 #include "mnmapview.h"
       
    24 #include <EPos_CPosLandmark.h>
       
    25 #include <StringLoader.h>
       
    26 #include <esmrgui.rsg>
       
    27 #include "cesmrurlparserplugin.h"
       
    28 //</cmail>
       
    29 #include <ct/rcpointerarray.h>
       
    30 
       
    31 #include "cesmrlocationpluginimpl.h"
       
    32 #include "mesmrlocationpluginobserver.h"
       
    33 
       
    34 // ======== MEMBER FUNCTIONS ========
       
    35 
       
    36 // ---------------------------------------------------------------------------
       
    37 // CESMRLocationPluginImpl::CESMRLocationPluginImpl
       
    38 // ---------------------------------------------------------------------------
       
    39 //
       
    40 CESMRLocationPluginImpl::CESMRLocationPluginImpl()
       
    41 	: CESMRLocationPlugin( CActive::EPriorityStandard )
       
    42     {
       
    43     FUNC_LOG;
       
    44     }
       
    45 
       
    46 // ---------------------------------------------------------------------------
       
    47 // CESMRLocationPluginImpl::ConstructL
       
    48 // ---------------------------------------------------------------------------
       
    49 //
       
    50 void CESMRLocationPluginImpl::ConstructL()
       
    51     {
       
    52     FUNC_LOG;
       
    53     // Find Map & Navigation provider
       
    54     RCPointerArray<CMnProvider> providers;
       
    55     CleanupClosePushL( providers );
       
    56     MnProviderFinder::FindProvidersL( providers,
       
    57     							      CMnProvider::EServiceMapView
       
    58     							      | CMnProvider::EServiceNavigation
       
    59     							      | CMnProvider::EServiceGeocoding );
       
    60     if ( providers.Count() == 0 )
       
    61     	{
       
    62     	User::Leave( KErrNotSupported );
       
    63     	}
       
    64     iProvider = providers[ 0 ];
       
    65     providers.Remove( 0 );    
       
    66     // PopAndDestroy provides from cleanupstack
       
    67     CleanupStack::PopAndDestroy( &providers );
       
    68     
       
    69     // Create Map & Navigation view
       
    70     CreateMapViewL();
       
    71 	
       
    72     iUrlParser = CESMRUrlParserPlugin::NewL();
       
    73     
       
    74     CActiveScheduler::Add( this );
       
    75     }
       
    76 
       
    77 
       
    78 // ---------------------------------------------------------------------------
       
    79 // CESMRLocationPluginImpl::NewL
       
    80 // ---------------------------------------------------------------------------
       
    81 //
       
    82 CESMRLocationPluginImpl* CESMRLocationPluginImpl::NewL()
       
    83     {
       
    84     FUNC_LOG;
       
    85     CESMRLocationPluginImpl* self = new( ELeave ) CESMRLocationPluginImpl();
       
    86     CleanupStack::PushL( self );
       
    87     self->ConstructL();
       
    88     CleanupStack::Pop( self );
       
    89     return self;
       
    90     }
       
    91 
       
    92 // ---------------------------------------------------------------------------
       
    93 // CESMRLocationPluginImpl::SetObserver
       
    94 // ---------------------------------------------------------------------------
       
    95 //
       
    96 void CESMRLocationPluginImpl::SetObserver ( MESMRLocationPluginObserver* aObserver )
       
    97     {
       
    98     FUNC_LOG;
       
    99     iObserver = aObserver;
       
   100     }
       
   101 // ---------------------------------------------------------------------------
       
   102 // CESMRLocationPluginImpl::~CESMRLocationPluginImpl
       
   103 // ---------------------------------------------------------------------------
       
   104 //
       
   105 CESMRLocationPluginImpl::~CESMRLocationPluginImpl()
       
   106     {
       
   107     FUNC_LOG;
       
   108     Cancel();
       
   109     if ( iMapView )
       
   110         {
       
   111         iMapView->RemoveExitObserver();
       
   112         delete iMapView;
       
   113         }
       
   114     delete iProvider;
       
   115     delete iUrlParser;
       
   116     
       
   117     iLandMarks.ResetAndDestroy();
       
   118     }
       
   119 
       
   120 // ---------------------------------------------------------------------------
       
   121 // CESMRLocationPluginImpl::CreateMapViewL
       
   122 // ---------------------------------------------------------------------------
       
   123 //
       
   124 void CESMRLocationPluginImpl::CreateMapViewL()
       
   125     {
       
   126     FUNC_LOG;
       
   127     if ( !iMapView )
       
   128         {
       
   129         iMapView = CMnMapView::NewChainedL( *iProvider );
       
   130         iMapView->SetExitObserverL( *this );
       
   131         }
       
   132     }
       
   133 
       
   134 // ---------------------------------------------------------------------------
       
   135 // CESMRLocationPluginImpl::SelectFromMapL
       
   136 // From class MESMRLocationPlugin.
       
   137 // ---------------------------------------------------------------------------
       
   138 //
       
   139 void CESMRLocationPluginImpl::SelectFromMapL( const TDesC& aSearchQuery,
       
   140 								      	      const TDesC& aLocationUrl )
       
   141 	{
       
   142     FUNC_LOG;
       
   143 	iLandMarks.ResetAndDestroy();
       
   144 	
       
   145 	if ( IsActive() )
       
   146 		{
       
   147 		User::Leave( KErrInUse );
       
   148 		}
       
   149 	
       
   150 	CreateMapViewL();
       
   151 	
       
   152 	iMapView->ResetMapArea();
       
   153 	
       
   154 	// Create landmark from location URL. TRAP errors because URL is optional.
       
   155 	CPosLandmark* location = NULL;
       
   156 	TRAP_IGNORE( location = //codescanner::forgottoputptroncleanupstack
       
   157                  iUrlParser->CreateLandmarkFromUrlL( aLocationUrl ) )
       
   158 	
       
   159 	if ( location ) // Landmark created. Set search string as landmark name
       
   160 	    {
       
   161 	    if ( aSearchQuery.Length() > 0 )
       
   162 	        {
       
   163 	        CleanupStack::PushL( location );
       
   164 	    
       
   165 	        location->SetLandmarkNameL( aSearchQuery );
       
   166 	    
       
   167 	        iLandMarks.AppendL( location );
       
   168 	        CleanupStack::Pop( location );
       
   169 	    
       
   170 	        iMapView->ResetLandmarksToShow();
       
   171 	        iMapView->AddLandmarksToShowL( iLandMarks );
       
   172 	        }
       
   173 	    }
       
   174 	else
       
   175         {
       
   176         // No location url provided, let's search from maps
       
   177         // with search string. It was agreed that search is done by
       
   178         // passing a landmark with search string as the name of the landmark
       
   179         // forward
       
   180          if ( aSearchQuery.Length() > 0 )
       
   181             {
       
   182             location = CPosLandmark::NewLC();
       
   183             location->SetLandmarkNameL( aSearchQuery );
       
   184 
       
   185             iLandMarks.AppendL( location );
       
   186             CleanupStack::Pop( location );
       
   187             
       
   188             iMapView->ResetLandmarksToShow();
       
   189             iMapView->AddLandmarksToShowL( iLandMarks );
       
   190             }        
       
   191         
       
   192         // Enable current location focus on map
       
   193         iMapView->
       
   194             SetCurrentLocationOption( CMnMapView::ECurrentLocationEnabled );
       
   195         }
       
   196 	
       
   197 	SetActive();
       
   198 	iMapView->SelectFromMapL( iStatus );
       
   199 	}
       
   200 
       
   201 // ---------------------------------------------------------------------------
       
   202 // CESMRLocationPluginImpl::SearchFromMapL
       
   203 // From class MESMRLocationPlugin.
       
   204 // ---------------------------------------------------------------------------
       
   205 //
       
   206 void CESMRLocationPluginImpl::SearchFromMapL( const TDesC& aSearchQuery )
       
   207     {
       
   208     FUNC_LOG;
       
   209     iLandMarks.ResetAndDestroy();
       
   210     
       
   211     CPosLandmark* location = CPosLandmark::NewLC();
       
   212     location->SetLandmarkNameL( aSearchQuery );
       
   213 
       
   214     iLandMarks.AppendL( location );
       
   215     CleanupStack::Pop( location );
       
   216             
       
   217     iMapView->ResetLandmarksToShow();
       
   218     iMapView->AddLandmarksToShowL( iLandMarks );
       
   219     iMapView->ShowMapL();
       
   220     }
       
   221 
       
   222 // ---------------------------------------------------------------------------
       
   223 // CESMRLocationPluginImpl::ShowOnMapL
       
   224 // From class MESMRLocationPlugin.
       
   225 // ---------------------------------------------------------------------------
       
   226 //
       
   227 void CESMRLocationPluginImpl::ShowOnMapL( const TDesC& aLocationUrl )
       
   228 	{
       
   229     FUNC_LOG;
       
   230 	CreateMapViewL();
       
   231 
       
   232 	iMapView->ResetLandmarksToShow();
       
   233     RCPointerArray<CPosLandmark> landmarks;
       
   234     CleanupClosePushL( landmarks );
       
   235     CPosLandmark* landmark = iUrlParser->CreateLandmarkFromUrlL( aLocationUrl );
       
   236     CleanupStack::PushL( landmark ); 
       
   237     landmarks.AppendL( landmark );
       
   238     CleanupStack::Pop( landmark );
       
   239     iMapView->AddLandmarksToShowL( landmarks );
       
   240     CleanupStack::PopAndDestroy( &landmarks );
       
   241     iMapView->ShowMapL();
       
   242 	}
       
   243 
       
   244 // ---------------------------------------------------------------------------
       
   245 // CESMRLocationPluginImpl::DoCancel
       
   246 // From class CActive.
       
   247 // Cancels outstanding request to iMapView
       
   248 // ---------------------------------------------------------------------------
       
   249 //
       
   250 void CESMRLocationPluginImpl::DoCancel()
       
   251     {
       
   252     FUNC_LOG;
       
   253     if( iMapView )
       
   254     	{
       
   255     	iMapView->Cancel();
       
   256     	}
       
   257     }
       
   258 
       
   259 // ---------------------------------------------------------------------------
       
   260 // CESMRLocationPluginImpl::RunL
       
   261 // From class CActive.
       
   262 // Process asynchronous SelectFromMap completion from CMnMapView
       
   263 // ---------------------------------------------------------------------------
       
   264 //
       
   265 void CESMRLocationPluginImpl::RunL()
       
   266     {
       
   267     FUNC_LOG;
       
   268     HandleSelectFromMapCompletedL();
       
   269     }
       
   270     
       
   271 // ---------------------------------------------------------------------------
       
   272 // CESMRLocationPluginImpl::HandleSelectFromMapCompletedL
       
   273 // ---------------------------------------------------------------------------
       
   274 //
       
   275 void CESMRLocationPluginImpl::HandleSelectFromMapCompletedL()
       
   276     {
       
   277     FUNC_LOG;
       
   278     if ( iStatus == KErrNone )
       
   279         {
       
   280         CMnMapView::TSelectionResultType type;
       
   281         type = iMapView->SelectionResultType();
       
   282         
       
   283         if ( iObserver )
       
   284             {
       
   285             switch ( type )
       
   286                 {
       
   287                 case CMnMapView::ESelectionFreeLandmark:
       
   288                     {
       
   289                     // Read selection from map view, send result to observer
       
   290                     CPosLandmark* landmark = 
       
   291                                 iMapView->RetrieveSelectionResultL();
       
   292                     iObserver->SelectFromMapCompleted( iStatus.Int(), 
       
   293                                                        landmark );
       
   294                     break;
       
   295                     }
       
   296                 case CMnMapView::ESelectionLandmarkIndex:
       
   297                     {
       
   298                     TInt landmarkIndex = 0;
       
   299                     iMapView->RetrieveSelectionResultL( landmarkIndex );
       
   300             
       
   301                     if ( landmarkIndex < iLandMarks.Count() )
       
   302                         {
       
   303                         iObserver->SelectFromMapCompleted( 
       
   304                             iStatus.Int(), 
       
   305                             iLandMarks[landmarkIndex] );
       
   306                         iLandMarks.Remove( landmarkIndex );
       
   307                         }
       
   308                     else
       
   309                         {
       
   310                         User::Leave( KErrGeneral );
       
   311                         }
       
   312                     break;
       
   313                     }
       
   314                 default:
       
   315                     {
       
   316                     User::Leave( KErrNotSupported );
       
   317                     break;
       
   318                     }
       
   319                 }
       
   320             }
       
   321         }
       
   322     else if (iObserver)
       
   323         {
       
   324         // Notify error to observer
       
   325         iObserver->SelectFromMapCompleted( iStatus.Int(), NULL );
       
   326         }
       
   327 
       
   328     // Close Map view 
       
   329     delete iMapView;
       
   330     iMapView = NULL;        
       
   331     }
       
   332 
       
   333 // ---------------------------------------------------------------------------
       
   334 // CESMRLocationPluginImpl::RunError
       
   335 // From class CActive.
       
   336 // ---------------------------------------------------------------------------
       
   337 //
       
   338 TInt CESMRLocationPluginImpl::RunError( TInt aError )
       
   339 	{
       
   340     FUNC_LOG;
       
   341 	// Notify error to observer
       
   342 	if(iObserver)
       
   343 	    {
       
   344 	    iObserver->SelectFromMapCompleted( aError, NULL );
       
   345 	    }
       
   346 	
       
   347 	// Close Map view
       
   348 	delete iMapView;
       
   349 	iMapView = NULL;
       
   350 	
       
   351 	return KErrNone;
       
   352 	}
       
   353 
       
   354 // ---------------------------------------------------------------------------
       
   355 // CESMRLocationPluginImpl::HandleServerAppExit
       
   356 // From class MAknServerAppExitObserver.
       
   357 // ---------------------------------------------------------------------------
       
   358 //
       
   359 void CESMRLocationPluginImpl::HandleServerAppExit( TInt aReason )
       
   360     {
       
   361     FUNC_LOG;
       
   362     Cancel();
       
   363     
       
   364     if ( iObserver )
       
   365         {
       
   366         // Notify observer that application has been closed without selection.
       
   367         iObserver->SelectFromMapCompleted( aReason, NULL );
       
   368         }
       
   369     
       
   370     delete iMapView;
       
   371     iMapView = NULL;
       
   372     }
       
   373