meetingrequest/mrgui/mrlocationplugin/src/cesmrlocationpluginimpl.cpp
branchRCL_3
changeset 25 3533d4323edc
equal deleted inserted replaced
24:d189ee25cf9d 25:3533d4323edc
       
     1 /*
       
     2 * Copyright (c) 2009 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 "cesmrlocationpluginimpl.h"
       
    20 #include "mesmrlocationpluginobserver.h"
       
    21 #include "cesmrurlparserplugin.h"
       
    22 
       
    23 #include <mnproviderfinder.h>
       
    24 #include <mnprovider.h>
       
    25 #include <mnmapview.h>
       
    26 #include <EPos_CPosLandmark.h>
       
    27 #include <StringLoader.h>
       
    28 #include <esmrgui.rsg>
       
    29 #include <ct/rcpointerarray.h>
       
    30 #include <calentry.h>
       
    31 
       
    32 #include "emailtrace.h"
       
    33 
       
    34 // ======== LOCAL FUNCTIONS ========
       
    35 
       
    36 namespace
       
    37     {
       
    38 /**
       
    39  * Converts vCal GEO value to landmark with coordinates
       
    40  *
       
    41  * @param aGeoValue coordinates
       
    42  * @return a landmark with coordinates
       
    43  */
       
    44 CPosLandmark* CreateLandmarkL( const CCalGeoValue& aGeoValue )
       
    45     {
       
    46     TReal lat;
       
    47     TReal lon;
       
    48 
       
    49     if( !aGeoValue.GetLatLong( lat, lon ) )
       
    50         {
       
    51         User::Leave( KErrArgument );
       
    52         }
       
    53 
       
    54     CPosLandmark* landmark = CPosLandmark::NewLC();
       
    55     TLocality coordinate;
       
    56     coordinate.SetCoordinate( lat, lon );
       
    57     landmark->SetPositionL( coordinate );
       
    58     CleanupStack::Pop( landmark );
       
    59     return landmark;
       
    60     }
       
    61 
       
    62     }
       
    63 // ======== MEMBER FUNCTIONS ========
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // CESMRLocationPluginImpl::CESMRLocationPluginImpl
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 CESMRLocationPluginImpl::CESMRLocationPluginImpl()
       
    70     : CESMRLocationPlugin( CActive::EPriorityStandard )
       
    71     {
       
    72     FUNC_LOG;
       
    73     }
       
    74 
       
    75 // ---------------------------------------------------------------------------
       
    76 // CESMRLocationPluginImpl::ConstructL
       
    77 // ---------------------------------------------------------------------------
       
    78 //
       
    79 void CESMRLocationPluginImpl::ConstructL()
       
    80     {
       
    81     FUNC_LOG;
       
    82     // Find Map & Navigation provider
       
    83     RCPointerArray<CMnProvider> providers;
       
    84     CleanupClosePushL( providers );
       
    85     MnProviderFinder::FindProvidersL( providers,
       
    86                                       CMnProvider::EServiceMapView
       
    87                                       | CMnProvider::EServiceNavigation );
       
    88     if ( providers.Count() == 0 )
       
    89         {
       
    90         User::Leave( KErrNotSupported );
       
    91         }
       
    92     iProvider = providers[ 0 ];
       
    93     providers.Remove( 0 );
       
    94     // PopAndDestroy provides from cleanupstack
       
    95     CleanupStack::PopAndDestroy( &providers );
       
    96 
       
    97     // Create Map & Navigation view
       
    98     CreateMapViewL();
       
    99 
       
   100     CActiveScheduler::Add( this );
       
   101     }
       
   102 
       
   103 
       
   104 // ---------------------------------------------------------------------------
       
   105 // CESMRLocationPluginImpl::NewL
       
   106 // ---------------------------------------------------------------------------
       
   107 //
       
   108 CESMRLocationPluginImpl* CESMRLocationPluginImpl::NewL()
       
   109     {
       
   110     FUNC_LOG;
       
   111     CESMRLocationPluginImpl* self = new( ELeave ) CESMRLocationPluginImpl();
       
   112     CleanupStack::PushL( self );
       
   113     self->ConstructL();
       
   114     CleanupStack::Pop( self );
       
   115     return self;
       
   116     }
       
   117 
       
   118 // ---------------------------------------------------------------------------
       
   119 // CESMRLocationPluginImpl::SetObserver
       
   120 // ---------------------------------------------------------------------------
       
   121 //
       
   122 void CESMRLocationPluginImpl::SetObserver ( MESMRLocationPluginObserver* aObserver )
       
   123     {
       
   124     FUNC_LOG;
       
   125     iObserver = aObserver;
       
   126     }
       
   127 // ---------------------------------------------------------------------------
       
   128 // CESMRLocationPluginImpl::~CESMRLocationPluginImpl
       
   129 // ---------------------------------------------------------------------------
       
   130 //
       
   131 CESMRLocationPluginImpl::~CESMRLocationPluginImpl()
       
   132     {
       
   133     FUNC_LOG;
       
   134     Cancel();
       
   135     if ( iMapView )
       
   136         {
       
   137         iMapView->RemoveExitObserver();
       
   138         delete iMapView;
       
   139         }
       
   140     delete iProvider;
       
   141     delete iUrlParser;
       
   142 
       
   143     iLandMarks.ResetAndDestroy();
       
   144     }
       
   145 
       
   146 // ---------------------------------------------------------------------------
       
   147 // CESMRLocationPluginImpl::CreateMapViewL
       
   148 // ---------------------------------------------------------------------------
       
   149 //
       
   150 void CESMRLocationPluginImpl::CreateMapViewL()
       
   151     {
       
   152     FUNC_LOG;
       
   153     if ( !iMapView )
       
   154         {
       
   155         iMapView = CMnMapView::NewChainedL( *iProvider );
       
   156         iMapView->SetExitObserverL( *this );
       
   157         }
       
   158     }
       
   159 
       
   160 // ---------------------------------------------------------------------------
       
   161 // CESMRLocationPluginImpl::SelectFromMapL
       
   162 // From class MESMRLocationPlugin.
       
   163 // ---------------------------------------------------------------------------
       
   164 //
       
   165 void CESMRLocationPluginImpl::SelectFromMapL( const TDesC& aSearchQuery,
       
   166                                               const TDesC& aLocationUrl )
       
   167     {
       
   168     FUNC_LOG;
       
   169 
       
   170     // Create landmark from location URL. TRAP errors because URL is optional.
       
   171     CPosLandmark* location = NULL;
       
   172     TRAP_IGNORE( location = //codescanner::forgottoputptroncleanupstack
       
   173             UrlParserL().CreateLandmarkFromUrlL( aLocationUrl ) )
       
   174 
       
   175     SelectFromMapL( aSearchQuery, location );
       
   176     }
       
   177 
       
   178 // ---------------------------------------------------------------------------
       
   179 // CESMRLocationPluginImpl::SelectFromMapL
       
   180 // From class MESMRLocationPlugin.
       
   181 // ---------------------------------------------------------------------------
       
   182 //
       
   183 void CESMRLocationPluginImpl::SelectFromMapL(
       
   184             const TDesC& aSearchQuery,
       
   185             const CCalGeoValue* aGeoValue )
       
   186     {
       
   187     FUNC_LOG;
       
   188 
       
   189     CPosLandmark* location = NULL;
       
   190 
       
   191     if ( aGeoValue )
       
   192         {
       
   193         location = CreateLandmarkL( *aGeoValue );
       
   194         }
       
   195 
       
   196     SelectFromMapL( aSearchQuery, location );
       
   197     }
       
   198 
       
   199 // ---------------------------------------------------------------------------
       
   200 // CESMRLocationPluginImpl::SearchFromMapL
       
   201 // From class MESMRLocationPlugin.
       
   202 // ---------------------------------------------------------------------------
       
   203 //
       
   204 void CESMRLocationPluginImpl::SearchFromMapL( const TDesC& aSearchQuery )
       
   205     {
       
   206     FUNC_LOG;
       
   207     iLandMarks.ResetAndDestroy();
       
   208 
       
   209     CPosLandmark* location = CPosLandmark::NewLC();
       
   210     location->SetLandmarkNameL( aSearchQuery );
       
   211 
       
   212     iLandMarks.AppendL( location );
       
   213     CleanupStack::Pop( location );
       
   214 
       
   215     CreateMapViewL();
       
   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 
       
   231     CPosLandmark* landmark =
       
   232         UrlParserL().CreateLandmarkFromUrlL( aLocationUrl );
       
   233     ShowLandmarkL( landmark );
       
   234     }
       
   235 
       
   236 // ---------------------------------------------------------------------------
       
   237 // CESMRLocationPluginImpl::ShowOnMapL
       
   238 // From class MESMRLocationPlugin.
       
   239 // ---------------------------------------------------------------------------
       
   240 //
       
   241 void CESMRLocationPluginImpl::ShowOnMapL( const CCalGeoValue& aGeoValue )
       
   242     {
       
   243     FUNC_LOG;
       
   244 
       
   245     CPosLandmark* landmark = CreateLandmarkL( aGeoValue );
       
   246     ShowLandmarkL( landmark );
       
   247     }
       
   248 
       
   249 // ---------------------------------------------------------------------------
       
   250 // CESMRLocationPluginImpl::DoCancel
       
   251 // From class CActive.
       
   252 // Cancels outstanding request to iMapView
       
   253 // ---------------------------------------------------------------------------
       
   254 //
       
   255 void CESMRLocationPluginImpl::DoCancel()
       
   256     {
       
   257     FUNC_LOG;
       
   258     if( iMapView )
       
   259         {
       
   260         iMapView->Cancel();
       
   261         }
       
   262     }
       
   263 
       
   264 // ---------------------------------------------------------------------------
       
   265 // CESMRLocationPluginImpl::RunL
       
   266 // From class CActive.
       
   267 // Process asynchronous SelectFromMap completion from CMnMapView
       
   268 // ---------------------------------------------------------------------------
       
   269 //
       
   270 void CESMRLocationPluginImpl::RunL()
       
   271     {
       
   272     FUNC_LOG;
       
   273     HandleSelectFromMapCompletedL();
       
   274     }
       
   275 
       
   276 // ---------------------------------------------------------------------------
       
   277 // CESMRLocationPluginImpl::HandleSelectFromMapCompletedL
       
   278 // ---------------------------------------------------------------------------
       
   279 //
       
   280 void CESMRLocationPluginImpl::HandleSelectFromMapCompletedL()
       
   281     {
       
   282     FUNC_LOG;
       
   283     if ( iStatus == KErrNone )
       
   284         {
       
   285         CMnMapView::TSelectionResultType type;
       
   286         type = iMapView->SelectionResultType();
       
   287 
       
   288         if ( iObserver )
       
   289             {
       
   290             switch ( type )
       
   291                 {
       
   292                 case CMnMapView::ESelectionFreeLandmark:
       
   293                     {
       
   294                     // Read selection from map view, send result to observer
       
   295                     CPosLandmark* landmark =
       
   296                                 iMapView->RetrieveSelectionResultL();
       
   297                     iObserver->SelectFromMapCompleted( iStatus.Int(),
       
   298                                                        landmark );
       
   299                     break;
       
   300                     }
       
   301                 case CMnMapView::ESelectionLandmarkIndex:
       
   302                     {
       
   303                     TInt landmarkIndex = 0;
       
   304                     iMapView->RetrieveSelectionResultL( landmarkIndex );
       
   305 
       
   306                     if ( landmarkIndex < iLandMarks.Count() )
       
   307                         {
       
   308                         iObserver->SelectFromMapCompleted(
       
   309                             iStatus.Int(),
       
   310                             iLandMarks[landmarkIndex] );
       
   311                         iLandMarks.Remove( landmarkIndex );
       
   312                         }
       
   313                     else
       
   314                         {
       
   315                         User::Leave( KErrGeneral );
       
   316                         }
       
   317                     break;
       
   318                     }
       
   319                 default:
       
   320                     {
       
   321                     User::Leave( KErrNotSupported );
       
   322                     break;
       
   323                     }
       
   324                 }
       
   325             }
       
   326         }
       
   327     else if (iObserver)
       
   328         {
       
   329         // Notify error to observer
       
   330         iObserver->SelectFromMapCompleted( iStatus.Int(), NULL );
       
   331         }
       
   332 
       
   333     // Close Map view
       
   334     delete iMapView;
       
   335     iMapView = NULL;
       
   336     }
       
   337 
       
   338 // ---------------------------------------------------------------------------
       
   339 // CESMRLocationPluginImpl::RunError
       
   340 // From class CActive.
       
   341 // ---------------------------------------------------------------------------
       
   342 //
       
   343 TInt CESMRLocationPluginImpl::RunError( TInt aError )
       
   344     {
       
   345     FUNC_LOG;
       
   346     // Notify error to observer
       
   347     if(iObserver)
       
   348         {
       
   349         iObserver->SelectFromMapCompleted( aError, NULL );
       
   350         }
       
   351 
       
   352     // Close Map view
       
   353     delete iMapView;
       
   354     iMapView = NULL;
       
   355 
       
   356     return KErrNone;
       
   357     }
       
   358 
       
   359 // ---------------------------------------------------------------------------
       
   360 // CESMRLocationPluginImpl::HandleServerAppExit
       
   361 // From class MAknServerAppExitObserver.
       
   362 // ---------------------------------------------------------------------------
       
   363 //
       
   364 void CESMRLocationPluginImpl::HandleServerAppExit( TInt aReason )
       
   365     {
       
   366     FUNC_LOG;
       
   367     Cancel();
       
   368 
       
   369     if ( iObserver )
       
   370         {
       
   371         // Notify observer that application has been closed without selection.
       
   372         iObserver->SelectFromMapCompleted( aReason, NULL );
       
   373         }
       
   374 
       
   375     delete iMapView;
       
   376     iMapView = NULL;
       
   377     }
       
   378 
       
   379 // ---------------------------------------------------------------------------
       
   380 // CESMRLocationPluginImpl::ShowLandmarkL
       
   381 // ---------------------------------------------------------------------------
       
   382 //
       
   383 void CESMRLocationPluginImpl::SelectFromMapL(
       
   384         const TDesC& aSearchQuery,
       
   385         CPosLandmark* aLandmark )
       
   386     {
       
   387     iLandMarks.ResetAndDestroy();
       
   388 
       
   389     if ( IsActive() )
       
   390         {
       
   391         User::Leave( KErrInUse );
       
   392         }
       
   393 
       
   394     CreateMapViewL();
       
   395 
       
   396     iMapView->ResetMapArea();
       
   397 
       
   398     CPosLandmark* location = aLandmark;
       
   399 
       
   400     if ( location ) // Landmark created. Set search string as landmark name
       
   401         {
       
   402         if ( aSearchQuery.Length() > 0 )
       
   403             {
       
   404             CleanupStack::PushL( location );
       
   405 
       
   406             location->SetLandmarkNameL( aSearchQuery );
       
   407 
       
   408             iLandMarks.AppendL( location );
       
   409             CleanupStack::Pop( location );
       
   410 
       
   411             iMapView->ResetLandmarksToShow();
       
   412             iMapView->AddLandmarksToShowL( iLandMarks );
       
   413             }
       
   414         }
       
   415     else
       
   416         {
       
   417         // No location url provided, let's search from maps
       
   418         // with search string. It was agreed that search is done by
       
   419         // passing a landmark with search string as the name of the landmark
       
   420         // forward
       
   421          if ( aSearchQuery.Length() > 0 )
       
   422             {
       
   423             location = CPosLandmark::NewLC();
       
   424             location->SetLandmarkNameL( aSearchQuery );
       
   425 
       
   426             iLandMarks.AppendL( location );
       
   427             CleanupStack::Pop( location );
       
   428 
       
   429             iMapView->ResetLandmarksToShow();
       
   430             iMapView->AddLandmarksToShowL( iLandMarks );
       
   431             }
       
   432 
       
   433         // Enable current location focus on map
       
   434         iMapView->
       
   435             SetCurrentLocationOption( CMnMapView::ECurrentLocationEnabled );
       
   436         }
       
   437 
       
   438     SetActive();
       
   439     iMapView->SelectFromMapL( iStatus );
       
   440     }
       
   441 
       
   442 // ---------------------------------------------------------------------------
       
   443 // CESMRLocationPluginImpl::ShowLandmarkL
       
   444 // ---------------------------------------------------------------------------
       
   445 //
       
   446 void CESMRLocationPluginImpl::ShowLandmarkL( CPosLandmark* aLandmark )
       
   447     {
       
   448     CreateMapViewL();
       
   449 
       
   450     iMapView->ResetLandmarksToShow();
       
   451     RCPointerArray<CPosLandmark> landmarks;
       
   452     CleanupClosePushL( landmarks );
       
   453     CleanupStack::PushL( aLandmark );
       
   454     landmarks.AppendL( aLandmark );
       
   455     CleanupStack::Pop( aLandmark );
       
   456     iMapView->AddLandmarksToShowL( landmarks );
       
   457     CleanupStack::PopAndDestroy( &landmarks );
       
   458     iMapView->ShowMapL();
       
   459     }
       
   460 
       
   461 // ---------------------------------------------------------------------------
       
   462 // CESMRLocationPluginImpl::UrlParserL
       
   463 // ---------------------------------------------------------------------------
       
   464 //
       
   465 CESMRUrlParserPlugin& CESMRLocationPluginImpl::UrlParserL()
       
   466     {
       
   467     if ( !iUrlParser )
       
   468         {
       
   469         iUrlParser = CESMRUrlParserPlugin::NewL();
       
   470         }
       
   471 
       
   472     return *iUrlParser;
       
   473     }
       
   474 
       
   475 // EOF