locationmapnavfw/library/src/mnmapview.cpp
branchRCL_3
changeset 44 2b4ea9893b66
parent 42 02ba3f1733c6
child 45 6b6920c56e2f
equal deleted inserted replaced
42:02ba3f1733c6 44:2b4ea9893b66
     1 /*
       
     2 * Copyright (c) 2005-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:  CMnMapView class implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32base.h>
       
    20 #include <f32file.h>
       
    21 #include <e32math.h>
       
    22 #include <barsc2.h>
       
    23 #include <barsread2.h>
       
    24 #include <bautils.h>
       
    25 #include <eikenv.h>
       
    26 #include <AknServerApp.h>
       
    27 #include <apaserverapp.h>
       
    28 
       
    29 #include <lbsposition.h>
       
    30 
       
    31 #include <mnclientlib.rsg>
       
    32 
       
    33 #include "mnerrors.h"
       
    34 #include "mninternal.h"
       
    35 #include "mndebug.h"
       
    36 #include "mnutils.h"
       
    37 
       
    38 #include "mnprovider.h"
       
    39 #include "mnmapviewserviceclient.h"
       
    40 #include "mnmapview.h"
       
    41 
       
    42 // ======== LOCAL FUNCTIONS ========
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 // ---------------------------------------------------------------------------
       
    46 //
       
    47 
       
    48 // ======== MEMBER FUNCTIONS ========
       
    49 
       
    50 // ---------------------------------------------------------------------------
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 CMnMapView::CMnMapView()
       
    54     {
       
    55     ResetMapArea();
       
    56     }
       
    57 
       
    58 // ---------------------------------------------------------------------------
       
    59 // ---------------------------------------------------------------------------
       
    60 //
       
    61 EXPORT_C CMnMapView* CMnMapView::NewL( CMnProvider& aProvider )
       
    62     {
       
    63     CMnMapView* self = new (ELeave) CMnMapView();
       
    64     CleanupStack::PushL( self );
       
    65     self->ConstructNewL( aProvider );
       
    66     CleanupStack::Pop( self );
       
    67     return self;
       
    68     }
       
    69 
       
    70 // ---------------------------------------------------------------------------
       
    71 // ---------------------------------------------------------------------------
       
    72 //
       
    73 EXPORT_C CMnMapView* CMnMapView::NewChainedL( CMnProvider& aProvider )
       
    74     {
       
    75     CMnMapView* self = new (ELeave) CMnMapView();
       
    76     CleanupStack::PushL( self );
       
    77     self->ConstructChainedL( aProvider );
       
    78     CleanupStack::Pop( self );
       
    79     return self;
       
    80     }
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // ---------------------------------------------------------------------------
       
    84 //
       
    85 void CMnMapView::ConstructCommonL( CMnProvider& aProvider )
       
    86     {
       
    87     if ( !( aProvider.SupportedServices() & CMnProvider::EServiceMapView ) )
       
    88         {
       
    89         User::Leave( KErrNotSupported );
       
    90         }
       
    91     
       
    92     // default request text
       
    93     RFs fs;
       
    94     User::LeaveIfError( fs.Connect() );
       
    95     CleanupClosePushL( fs );
       
    96 
       
    97     iDefaultRequestText = LoadResourceTextL( fs, KLibResourceFile, R_MN_LIBRARY_REQUEST_TEXT );
       
    98 
       
    99     CleanupStack::PopAndDestroy( &fs );
       
   100     
       
   101     // session with provider
       
   102     iSession = new (ELeave) RMnMapViewServiceClient;
       
   103     }
       
   104 
       
   105 // ---------------------------------------------------------------------------
       
   106 // ---------------------------------------------------------------------------
       
   107 //
       
   108 void CMnMapView::ConstructNewL( CMnProvider& aProvider )
       
   109     {
       
   110     ConstructCommonL( aProvider );
       
   111     iSession->ConnectL( aProvider.Uid() );
       
   112     PostConstructL();            
       
   113     }
       
   114 
       
   115 // ---------------------------------------------------------------------------
       
   116 // ---------------------------------------------------------------------------
       
   117 //
       
   118 void CMnMapView::ConstructChainedL( CMnProvider& aProvider )
       
   119     {
       
   120     ConstructCommonL( aProvider );
       
   121     iSession->ConnectChainedL( aProvider.Uid() );
       
   122 LOG("CMnMapView::ConstructChainedL, after connect chained");
       
   123     PostConstructL();            
       
   124     }
       
   125 
       
   126 // ---------------------------------------------------------------------------
       
   127 // ---------------------------------------------------------------------------
       
   128 //
       
   129 void CMnMapView::PostConstructL()
       
   130     {
       
   131     iSession->InitSelectionRequestTextL( iDefaultRequestText );            
       
   132     }
       
   133 
       
   134 // ---------------------------------------------------------------------------
       
   135 // ---------------------------------------------------------------------------
       
   136 //
       
   137 EXPORT_C CMnMapView::~CMnMapView()
       
   138     {
       
   139     delete iDefaultRequestText;
       
   140     delete iExitMonitor;
       
   141     
       
   142     if ( iSession )
       
   143         {
       
   144         iSession->Close();
       
   145         delete iSession;
       
   146         }
       
   147     }
       
   148 
       
   149 // ---------------------------------------------------------------------------
       
   150 // ---------------------------------------------------------------------------
       
   151 //
       
   152 EXPORT_C void CMnMapView::ShowMapL()
       
   153     {
       
   154     TMnMapOptions options;
       
   155     options.iOptions = iOptions;
       
   156     options.iCurrentLocationOption = iCurrentLocationOption;
       
   157     options.iCentralPoint = iCentralPoint;
       
   158     options.iRadius = iRadius;
       
   159 
       
   160     iSession->ShowMapL( options );
       
   161     }
       
   162 
       
   163 // ---------------------------------------------------------------------------
       
   164 // ---------------------------------------------------------------------------
       
   165 //
       
   166 EXPORT_C void CMnMapView::ShowCurrentLocationL()
       
   167     {
       
   168     TMnMapOptions options;
       
   169     options.iOptions = iOptions;
       
   170     options.iCurrentLocationOption = iCurrentLocationOption;
       
   171     options.iCentralPoint = iCentralPoint;
       
   172     options.iRadius = iRadius;
       
   173 
       
   174     iSession->ShowCurrentLocationL( options );
       
   175     }
       
   176 
       
   177 // ---------------------------------------------------------------------------
       
   178 // ---------------------------------------------------------------------------
       
   179 //
       
   180 EXPORT_C void CMnMapView::SelectFromMapL( TRequestStatus& aStatus )
       
   181     {
       
   182     TMnMapOptions options;
       
   183     options.iOptions = iOptions;
       
   184     options.iCurrentLocationOption = iCurrentLocationOption;
       
   185     options.iCentralPoint = iCentralPoint;
       
   186     options.iRadius = iRadius;
       
   187 
       
   188     iSession->SelectFromMap( options, aStatus );
       
   189     }
       
   190 
       
   191 // ---------------------------------------------------------------------------
       
   192 // ---------------------------------------------------------------------------
       
   193 //
       
   194 EXPORT_C void CMnMapView::AddLandmarksToShowL(
       
   195     const TDesC& aDatabaseUri,
       
   196     RArray<TPosLmItemId>& aLandmarkIds)
       
   197     {
       
   198     iSession->AddLandmarksToShowL( aDatabaseUri, aLandmarkIds );
       
   199     }
       
   200     
       
   201 // ---------------------------------------------------------------------------
       
   202 // ---------------------------------------------------------------------------
       
   203 //
       
   204 EXPORT_C void CMnMapView::AddLandmarksToShowL( RPointerArray<CPosLandmark>& aLandmarks )
       
   205     {
       
   206     iSession->AddLandmarksToShowL( aLandmarks );
       
   207     }
       
   208 
       
   209 // ---------------------------------------------------------------------------
       
   210 // ---------------------------------------------------------------------------
       
   211 //
       
   212 EXPORT_C void CMnMapView::AddLandmarksToShowL( RArray<TPtrC8>& aPackedLandmarks )
       
   213     {
       
   214     iSession->AddLandmarksToShowL( aPackedLandmarks );
       
   215     }
       
   216 
       
   217 // ---------------------------------------------------------------------------
       
   218 // ---------------------------------------------------------------------------
       
   219 //
       
   220 EXPORT_C void CMnMapView::ResetLandmarksToShow()
       
   221     {
       
   222     iSession->ResetLandmarksToShow();
       
   223     }
       
   224 
       
   225 // ---------------------------------------------------------------------------
       
   226 // ---------------------------------------------------------------------------
       
   227 //
       
   228 EXPORT_C void CMnMapView::SetMapAreaL(const TCoordinate& aCentralPoint, TReal aRadius)
       
   229     {
       
   230     iCentralPoint = aCentralPoint;
       
   231     iRadius = aRadius;
       
   232     }
       
   233     
       
   234 // ---------------------------------------------------------------------------
       
   235 // ---------------------------------------------------------------------------
       
   236 //
       
   237 EXPORT_C void CMnMapView::ResetMapArea()
       
   238     {
       
   239     TCoordinate empty;
       
   240     iCentralPoint = empty;
       
   241     
       
   242     TRealX nan;
       
   243     nan.SetNaN();
       
   244     iRadius = nan;
       
   245     }
       
   246 
       
   247 // ---------------------------------------------------------------------------
       
   248 // ---------------------------------------------------------------------------
       
   249 //
       
   250 EXPORT_C void CMnMapView::SetCustomRequestTextL(const TDesC& aCustomText)
       
   251     {
       
   252     iSession->SetSelectionRequestTextL( aCustomText );
       
   253     }
       
   254 
       
   255 // ---------------------------------------------------------------------------
       
   256 // ---------------------------------------------------------------------------
       
   257 //
       
   258 EXPORT_C void CMnMapView::SetUseDefaultRequestText()
       
   259     {
       
   260     iSession->SetSelectionRequestText( iDefaultRequestText );
       
   261     }
       
   262 
       
   263 // ---------------------------------------------------------------------------
       
   264 // ---------------------------------------------------------------------------
       
   265 //
       
   266 EXPORT_C void CMnMapView::SetCurrentLocationOption(TCurrentLocationOption aCurrentLocationOption)
       
   267     {
       
   268     iCurrentLocationOption = aCurrentLocationOption;
       
   269     }
       
   270 
       
   271 // ---------------------------------------------------------------------------
       
   272 // ---------------------------------------------------------------------------
       
   273 //
       
   274 EXPORT_C CMnMapView::TCurrentLocationOption CMnMapView::CurrentLocationOption() const
       
   275     {
       
   276     return iCurrentLocationOption;
       
   277     }
       
   278 
       
   279 // ---------------------------------------------------------------------------
       
   280 // ---------------------------------------------------------------------------
       
   281 //
       
   282 EXPORT_C void CMnMapView::SetOptions(TOptions aOptions)
       
   283     {
       
   284     iOptions = aOptions;
       
   285     }
       
   286 
       
   287 // ---------------------------------------------------------------------------
       
   288 // ---------------------------------------------------------------------------
       
   289 //
       
   290 EXPORT_C CMnMapView::TOptions CMnMapView::Options() const
       
   291     {
       
   292     return iOptions;
       
   293     }
       
   294 
       
   295 // ---------------------------------------------------------------------------
       
   296 // ---------------------------------------------------------------------------
       
   297 //
       
   298 EXPORT_C CMnMapView::TSelectionResultType CMnMapView::SelectionResultType() const
       
   299     {
       
   300     return iSession->SelectionResultType();
       
   301     }
       
   302 
       
   303 // ---------------------------------------------------------------------------
       
   304 // ---------------------------------------------------------------------------
       
   305 //
       
   306 EXPORT_C CPosLandmark* CMnMapView::RetrieveSelectionResultL()
       
   307     {
       
   308     return iSession->GetSelectedLandmarkL();
       
   309     }
       
   310 
       
   311 // ---------------------------------------------------------------------------
       
   312 // ---------------------------------------------------------------------------
       
   313 //
       
   314 EXPORT_C void CMnMapView::RetrieveSelectionResultL( TInt& aLandmarkIndex )
       
   315     {
       
   316     iSession->GetSelectedLandmarkL( aLandmarkIndex );
       
   317     }
       
   318 
       
   319 // ---------------------------------------------------------------------------
       
   320 // ---------------------------------------------------------------------------
       
   321 //
       
   322 EXPORT_C void CMnMapView::RetrieveSelectionResultL( 
       
   323     TPosLmItemId& aLandmarkId,
       
   324     HBufC*& aDatabaseUri )
       
   325     {
       
   326     iSession->GetSelectedLandmarkL( aLandmarkId, aDatabaseUri );
       
   327     }
       
   328 
       
   329 // ---------------------------------------------------------------------------
       
   330 // ---------------------------------------------------------------------------
       
   331 //
       
   332 EXPORT_C void CMnMapView::Cancel()
       
   333     {
       
   334     iSession->Cancel();
       
   335     }
       
   336 
       
   337 // ---------------------------------------------------------------------------
       
   338 // ---------------------------------------------------------------------------
       
   339 //
       
   340 EXPORT_C void CMnMapView::SetExitObserverL( MAknServerAppExitObserver& aObserver )
       
   341 	{
       
   342 	LOG("CMnMapView::SetExitObserverL in");	
       
   343 	if ( iExitMonitor )
       
   344 		{
       
   345 		User::Leave( KErrAlreadyExists );
       
   346 		}
       
   347 	else
       
   348 		{
       
   349 		iExitMonitor = CApaServerAppExitMonitor::NewL( 
       
   350 			*iSession, aObserver, CActive::EPriorityStandard );
       
   351 		}
       
   352 	LOG("CMnMapView::SetExitObserverL out");	
       
   353 	}
       
   354 
       
   355 // ---------------------------------------------------------------------------
       
   356 // ---------------------------------------------------------------------------
       
   357 //
       
   358 EXPORT_C void CMnMapView::RemoveExitObserver()
       
   359 	{
       
   360 	delete iExitMonitor;
       
   361 	iExitMonitor = NULL;
       
   362 	}
       
   363 
       
   364 // ======== INTERNAL FUNCTIONS ========
       
   365 
       
   366 // ---------------------------------------------------------------------------
       
   367 // ---------------------------------------------------------------------------
       
   368 //
       
   369 HBufC* CMnMapView::LoadResourceTextL( 
       
   370     RFs& aFsSession, 
       
   371     const TDesC& aRscFile, 
       
   372     TInt aResourceId )
       
   373     {
       
   374     TFileName fileName;
       
   375     MnUtils::FindLocalizedResourceFileL( aFsSession, aRscFile, fileName );
       
   376 
       
   377     CResourceFile* resFile = CResourceFile::NewL( aFsSession, fileName, 0, 0 );
       
   378     CleanupStack::PushL( resFile );
       
   379     resFile->ConfirmSignatureL( 0 );
       
   380     
       
   381     RResourceReader reader;
       
   382     reader.OpenL( resFile, aResourceId );
       
   383     CleanupClosePushL( reader );
       
   384     
       
   385     HBufC* text = reader.ReadHBufC16L();
       
   386     
       
   387     CleanupStack::PopAndDestroy( &reader );
       
   388     CleanupStack::PopAndDestroy( resFile );
       
   389         
       
   390     return text;        
       
   391     }