mapnavproviderrefapp/src/mnrpmapviewservice.cpp
branchRCL_3
changeset 17 1fc85118c3ae
parent 16 8173571d354e
child 18 870918037e16
equal deleted inserted replaced
16:8173571d354e 17:1fc85118c3ae
     1 /*
       
     2 * Copyright (c) 2006 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:  CMnrpMapViewService class implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32base.h>
       
    20 #include <eikenv.h>
       
    21 
       
    22 #include <lbsposition.h>
       
    23 
       
    24 #include <EPos_CPosLandmark.h>
       
    25 #include <EPos_CPosLandmarkDatabase.h>
       
    26 
       
    27 #include "debug.h"
       
    28 #include <mnmapviewservicebase.h>
       
    29 
       
    30 #include "mnrpappui.h"
       
    31 #include "mnrpmapview.h"
       
    32 #include "mnrpengine.h"
       
    33 #include "mnrpdocument.h"
       
    34 #include "mnrpappserver.h"
       
    35 
       
    36 #include "mnrpmapviewservice.h"
       
    37 
       
    38 // ============================ MEMBER FUNCTIONS ===============================
       
    39 
       
    40 // ---------------------------------------------------------------------------
       
    41 // ---------------------------------------------------------------------------
       
    42 //
       
    43 CMnrpMapViewService* CMnrpMapViewService::NewL()
       
    44     {
       
    45     CMnrpMapViewService* self = new (ELeave) CMnrpMapViewService();
       
    46     CleanupStack::PushL( self );
       
    47     self->ConstructL();
       
    48     CleanupStack::Pop( self );
       
    49     return self;
       
    50     }
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // ---------------------------------------------------------------------------
       
    54 //
       
    55 CMnrpMapViewService::CMnrpMapViewService()
       
    56     {
       
    57     }
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // ---------------------------------------------------------------------------
       
    61 //
       
    62 CMnrpMapViewService::~CMnrpMapViewService()
       
    63     {
       
    64     if ( iSelecting )
       
    65         {
       
    66         DoCancel();
       
    67         CompleteRequest( KErrCancel );
       
    68         }
       
    69     }
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 // ---------------------------------------------------------------------------
       
    73 //
       
    74 void CMnrpMapViewService::ConstructL()
       
    75     {
       
    76     BaseConstructL();
       
    77     }
       
    78 
       
    79 // ---------------------------------------------------------------------------
       
    80 // ---------------------------------------------------------------------------
       
    81 //
       
    82 CMnrpAppUi* CMnrpMapViewService::AppUi()
       
    83     {
       
    84     CMnrpAppServer* server = ( CMnrpAppServer* ) Server();
       
    85     if ( server )
       
    86         {
       
    87         return server->AppUi();
       
    88         }
       
    89     return NULL;
       
    90     }
       
    91 
       
    92 // ---------------------------------------------------------------------------
       
    93 // From class CMnMapViewServiceBase
       
    94 // ---------------------------------------------------------------------------
       
    95 //
       
    96 void CMnrpMapViewService::HandleShowMapL()
       
    97     {
       
    98     LOG("MnRefProvider::HandleShowMapL in");
       
    99 
       
   100     /** This implementation cannot show map if selection is active */
       
   101     if ( iSelecting )
       
   102         {
       
   103         User::Leave( KErrInUse );
       
   104         }
       
   105 
       
   106     if ( AppUi() )
       
   107         {
       
   108         AppUi()->ShowMapL( *this );
       
   109         }
       
   110 
       
   111     LOG("MnRefProvider::HandleShowMapL out");
       
   112     }
       
   113 
       
   114 // ---------------------------------------------------------------------------
       
   115 //  From class CMnMapViewServiceBase
       
   116 //
       
   117 //  This callback differs from HandleShowMapL in a way that central point
       
   118 //  setting is ignored and current location is used instead as central point.
       
   119 //
       
   120 //  The implementation is the example of how to reject unsupported requests 
       
   121 // ---------------------------------------------------------------------------
       
   122 //
       
   123 void CMnrpMapViewService::HandleShowCurrentLocationL()
       
   124     {
       
   125     User::Leave( KErrNotSupported );
       
   126     }
       
   127 
       
   128 // ---------------------------------------------------------------------------
       
   129 //  From class CMnMapViewServiceBase
       
   130 // ---------------------------------------------------------------------------
       
   131 //
       
   132 void CMnrpMapViewService::HandleSelectFromMapL()
       
   133     {
       
   134     LOG("MnRefProvider::HandleSelectFromMapL in");
       
   135 
       
   136     /** Only one selection must be active */
       
   137     if ( iSelecting )
       
   138         {
       
   139         User::Leave( KErrInUse );
       
   140         }
       
   141 
       
   142     if ( AppUi() )
       
   143         {
       
   144         iSelecting = ETrue;
       
   145         AppUi()->StartSelectionL( *this, *this );
       
   146         }
       
   147 
       
   148     LOG("MnRefProvider::HandleSelectFromMapL out");
       
   149     }
       
   150 
       
   151 // ---------------------------------------------------------------------------
       
   152 //  From class CMnServiceBase
       
   153 // ---------------------------------------------------------------------------
       
   154 //
       
   155 void CMnrpMapViewService::DoCancel()
       
   156     {
       
   157     if ( iSelecting )
       
   158         {
       
   159         iSelecting = EFalse;
       
   160         StopSelection();
       
   161         }
       
   162     }
       
   163 
       
   164 // ---------------------------------------------------------------------------
       
   165 //  From class MMapSelectionCallback
       
   166 // ---------------------------------------------------------------------------
       
   167 //
       
   168 void CMnrpMapViewService::HandleSelectionErrorL( TInt aError )
       
   169     {
       
   170     __ASSERT_DEBUG( iSelecting, Panic( KErrGeneral ) );
       
   171 
       
   172     iSelecting = EFalse;
       
   173     // selection view dismissed
       
   174     CompleteRequest( aError );
       
   175     }
       
   176 
       
   177 // ---------------------------------------------------------------------------
       
   178 //  From class MMapSelectionCallback
       
   179 // ---------------------------------------------------------------------------
       
   180 //
       
   181 void CMnrpMapViewService::HandleSelectionL( const TCoordinate& aSelection )
       
   182     {
       
   183     __ASSERT_DEBUG( iSelecting, Panic( KErrGeneral ) );
       
   184 
       
   185     iSelecting = EFalse;
       
   186     TInt err = KErrNone;
       
   187     TRAP( err, CompleteSelectionL( aSelection ) );
       
   188     if ( err )
       
   189         {
       
   190         CompleteRequest( err );
       
   191         }
       
   192     StopSelection();
       
   193     }
       
   194 
       
   195 // ---------------------------------------------------------------------------
       
   196 // ---------------------------------------------------------------------------
       
   197 //
       
   198 void CMnrpMapViewService::CompleteSelectionL( const TCoordinate& aSelection )
       
   199     {
       
   200     TLocality loc( aSelection, 0 );
       
   201     CPosLandmark* lm = CPosLandmark::NewLC();
       
   202     lm->SetPositionL( loc );
       
   203 
       
   204     // send landmark to client
       
   205     CompleteSelectionRequestL( *lm );
       
   206 
       
   207     CleanupStack::PopAndDestroy( lm );
       
   208     }
       
   209 
       
   210 // ---------------------------------------------------------------------------
       
   211 // ---------------------------------------------------------------------------
       
   212 //
       
   213 void CMnrpMapViewService::StopSelection()
       
   214     {
       
   215     if ( AppUi() )
       
   216         {
       
   217         AppUi()->StopSelection();
       
   218         }
       
   219     }
       
   220     
       
   221 // ---------------------------------------------------------------------------
       
   222 //  From class MMapSelectionCallback
       
   223 // ---------------------------------------------------------------------------
       
   224 //
       
   225 void CMnrpMapViewService::HandleSelectionL( TInt aLandmarkIndex )
       
   226     {
       
   227     __ASSERT_DEBUG( iSelecting, Panic( KErrGeneral ) );
       
   228 
       
   229     iSelecting = EFalse;
       
   230     CompleteSelectionRequest( aLandmarkIndex );
       
   231     StopSelection();
       
   232     }
       
   233     
       
   234 // ---------------------------------------------------------------------------
       
   235 //  From class MMapSelectionCallback
       
   236 // ---------------------------------------------------------------------------
       
   237 //
       
   238 void CMnrpMapViewService::HandleSelectionL( TPosLmItemId aLandmarkId, TInt aDbIndex )
       
   239     {
       
   240     __ASSERT_DEBUG( iSelecting, Panic( KErrGeneral ) );
       
   241 
       
   242     iSelecting = EFalse;
       
   243     CompleteSelectionRequest( aLandmarkId, aDbIndex );
       
   244     StopSelection();
       
   245     }