eventsui/eventseditor/src/evtmgmtuimapnavigationadapter.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:   Applications interface class to map and navigation use cases
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <AiwGenericParam.h>
       
    20 #include <epos_poslandmarkserialization.h>
       
    21 #include <lbsposition.h>
       
    22 #include <eikenv.h>
       
    23 #include <StringLoader.h>
       
    24 #include <evtmgmteditorui.rsg>
       
    25 #include <EPos_CPosLandmarkDatabase.h>
       
    26 #include <EPos_CPosLmOperation.h>
       
    27 #include <EPos_CPosLandmark.h>
       
    28 #include <EPos_Landmarks.h>
       
    29 #include <e32math.h>
       
    30 #include <TLmkItemIdDbCombiInfo.h> 
       
    31 #include <AiwServiceHandler.h>
       
    32 #include <AiwCommon.h> 
       
    33 #include <mnaiwservices.h>
       
    34 #include <mnmapview.h>
       
    35 #include <mnprovider.h>
       
    36 #include <mnproviderfinder.h>
       
    37 
       
    38 #include "evtdebug.h"
       
    39 #include "evtmgmtuimapnavigationadapter.h"
       
    40 #include "evteditorconsts.h"
       
    41 
       
    42 // ============================ MEMBER FUNCTIONS ===============================
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // CEvtMgmtUiMapNavigationAdapter::CLmkMapNavigationInterface
       
    46 // C++ default constructor can NOT contain any code, that
       
    47 // might leave.
       
    48 // -----------------------------------------------------------------------------
       
    49 CEvtMgmtUiMapNavigationAdapter::CEvtMgmtUiMapNavigationAdapter()
       
    50 	{	
       
    51 	}
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // CEvtMgmtUiMapNavigationAdapter::ConstructL
       
    55 // Symbian 2nd phase constructor can leave.
       
    56 // -----------------------------------------------------------------------------
       
    57 void CEvtMgmtUiMapNavigationAdapter::ConstructL()
       
    58 	{
       
    59 	iAiwServiceHandler = CAiwServiceHandler::NewL();
       
    60 	iInList = CAiwGenericParamList::NewL();
       
    61     iOutList = CAiwGenericParamList::NewL();  
       
    62 	}
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // CEvtMgmtUiMapNavigationAdapter::NewL
       
    66 // Symbian 1st phase constructor can leave.
       
    67 // -----------------------------------------------------------------------------
       
    68 CEvtMgmtUiMapNavigationAdapter* CEvtMgmtUiMapNavigationAdapter::NewL()
       
    69 	{	
       
    70 	CEvtMgmtUiMapNavigationAdapter* self = new (ELeave) CEvtMgmtUiMapNavigationAdapter();
       
    71 	CleanupStack::PushL( self );
       
    72 	self->ConstructL();
       
    73 	CleanupStack::Pop();//self
       
    74 	return self;
       
    75 	}
       
    76 	
       
    77 // -----------------------------------------------------------------------------
       
    78 // CEvtMgmtUiMapNavigationAdapter::NewLC
       
    79 // Symbian 1st phase constructor can leave.
       
    80 // -----------------------------------------------------------------------------
       
    81 CEvtMgmtUiMapNavigationAdapter* CEvtMgmtUiMapNavigationAdapter::NewLC()
       
    82     {   
       
    83     CEvtMgmtUiMapNavigationAdapter* self = new (ELeave) CEvtMgmtUiMapNavigationAdapter();
       
    84     CleanupStack::PushL( self );
       
    85     self->ConstructL();
       
    86     CleanupStack::Pop();//self
       
    87     return self;
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // CEvtMgmtUiMapNavigationAdapter::~CEvtMgmtUiMapNavigationAdapter
       
    92 // C++ Destructor
       
    93 // -----------------------------------------------------------------------------
       
    94  CEvtMgmtUiMapNavigationAdapter::~CEvtMgmtUiMapNavigationAdapter()
       
    95 	{	
       
    96 	delete iAiwServiceHandler;    
       
    97 	iAiwServiceHandler = NULL;
       
    98     delete iInList;
       
    99     iInList = NULL;
       
   100     delete iOutList;   
       
   101     iOutList = NULL;
       
   102     if(iPlace)
       
   103         {
       
   104         delete iPlace;
       
   105         iPlace = NULL;
       
   106         }
       
   107 	}
       
   108  
       
   109  // -----------------------------------------------------------------------------
       
   110  // CEvtMgmtUiMapNavigationAdapter::SetObserver
       
   111  // It will set observer to notify completion of map operation
       
   112  // -----------------------------------------------------------------------------
       
   113  void CEvtMgmtUiMapNavigationAdapter::SetObserver( MEvtMgmtUiMapAndNavigationObserver* aObserver )
       
   114      {
       
   115      iObserver = aObserver;
       
   116      } 
       
   117  
       
   118  // -----------------------------------------------------------------------------
       
   119  // CEvtMgmtUiMapNavigationAdapter::SetPlaceL
       
   120  // It will set place.
       
   121  // @param [in] aPlace - place of existing event
       
   122  //                    - empty for newly created event
       
   123  // ----------------------------------------------------------------------------- 
       
   124  void CEvtMgmtUiMapNavigationAdapter::SetPlaceL( const TPtrC& aPlace )
       
   125      {
       
   126      iPlace = aPlace.AllocL();
       
   127      }
       
   128  
       
   129  // -----------------------------------------------------------------------------
       
   130  // CEvtMgmtUiMapNavigationAdapter::SetLocation
       
   131  // It will set location.
       
   132  // param[in] aTriggerLocation - location of trigger of existing event
       
   133  //                            - NaN for newly created event
       
   134  // -----------------------------------------------------------------------------
       
   135  void CEvtMgmtUiMapNavigationAdapter::SetLocation( TCoordinate  aTriggerLocation )
       
   136      {
       
   137      iTriggerLocation = aTriggerLocation;
       
   138      }
       
   139 
       
   140  // -----------------------------------------------------------------------------
       
   141  // CEvtMgmtUiMapNavigationAdapter::Place()
       
   142  // It will return place value recieved from map.
       
   143  // @ret selected place
       
   144  // -----------------------------------------------------------------------------
       
   145  TPtrC CEvtMgmtUiMapNavigationAdapter::Place() const
       
   146      {
       
   147      //if place, it is set otherwise empty string
       
   148      if(iPlace)
       
   149          return *iPlace;
       
   150      else
       
   151          return KNullDesC();
       
   152      }
       
   153 
       
   154 // -----------------------------------------------------------------------------
       
   155 // CEvtMgmtUiMapNavigationAdapter::PlaceFromMapL
       
   156 // This method is called for the get landmarks from map use case.
       
   157 // -----------------------------------------------------------------------------
       
   158     void CEvtMgmtUiMapNavigationAdapter::PlaceFromMapL()
       
   159 	{
       
   160 	// This string will be sent to the provider to display it in the map view
       
   161     HBufC* buf = StringLoader::LoadLC( R_EVTUI_CREATENEW_FORM_PLACEPOPUP_TITLE , CEikonEnv::Static() );    
       
   162 	TAiwGenericParam param( EGenericParamRequestText, TAiwVariant( *buf ) );
       
   163     iInList->Reset();
       
   164     iInList->AppendL( param );
       
   165     iOutList->Reset(); 
       
   166     iAiwServiceHandler->AttachL( R_EVTMGMTUI_AIW_INTEREST_SELECTFROMMAP );
       
   167 	iAiwServiceHandler->ExecuteServiceCmdL( KAiwCmdMnSelectFromMap, *iInList, *iOutList, 0, this );	
       
   168 	CleanupStack::PopAndDestroy( buf ); 
       
   169 	}
       
   170 
       
   171 // -----------------------------------------------------------------------------
       
   172 // CEvtMgmtUiMapNavigationAdapter::ShowOnMapL
       
   173 // It will show location on map
       
   174 // -----------------------------------------------------------------------------
       
   175 void CEvtMgmtUiMapNavigationAdapter::ShowOnMapL()
       
   176     {
       
   177     CPosLandmark* lmk = CPosLandmark::NewLC();
       
   178     TLocality locality;
       
   179     HBufC8* lmBuf;
       
   180     
       
   181     //set location
       
   182     locality.SetCoordinate( iTriggerLocation.Latitude(), iTriggerLocation.Longitude(), iTriggerLocation.Altitude() );
       
   183  
       
   184     lmk->SetPositionL(locality);
       
   185     
       
   186     //set  in parameters
       
   187     iInList->Reset();
       
   188     lmBuf =PosLandmarkSerialization::PackL( *lmk );
       
   189     CleanupStack::PushL( lmBuf );
       
   190     TAiwGenericParam param( EGenericParamLandmark, TAiwVariant( *lmBuf ) );     
       
   191     iInList->AppendL( param );       
       
   192     TMnAiwCommonOptionsParam options;
       
   193     options.iRunChained = EFalse;
       
   194     TPckg<TMnAiwCommonOptionsParam> optionsPack( options );
       
   195     TAiwGenericParam optParam( EGenericParamMnCommonOptions, TAiwVariant( optionsPack ) );
       
   196     iInList->AppendL( optParam );
       
   197             
       
   198     //show location on map
       
   199     iAiwServiceHandler->AttachL( R_EVTMGMTUI_AIW_INTEREST_SHOWONMAP );
       
   200     iAiwServiceHandler->ExecuteServiceCmdL( KAiwCmdMnShowMap, *iInList, *iOutList, 0, this ); 
       
   201     
       
   202     CleanupStack::PopAndDestroy( 2 ); //lmbuf, lmk
       
   203     }
       
   204 
       
   205 // -----------------------------------------------------------------------------
       
   206 // CEvtMgmtUiMapNavigationAdapter::NavigateToPlaceL
       
   207 // It will navigate to location
       
   208 // -----------------------------------------------------------------------------
       
   209 void CEvtMgmtUiMapNavigationAdapter::NavigateToPlaceL()
       
   210     {
       
   211     CPosLandmark* lmk = CPosLandmark::NewLC();
       
   212     TLocality locality;
       
   213     HBufC8* lmBuf;
       
   214     
       
   215     //set location
       
   216     locality.SetCoordinate( iTriggerLocation.Latitude(), iTriggerLocation.Longitude(), iTriggerLocation.Altitude() );
       
   217     lmk->SetPositionL(locality);
       
   218     
       
   219     //set in parameters
       
   220     iInList->Reset();
       
   221     lmBuf =PosLandmarkSerialization::PackL( *lmk );
       
   222     CleanupStack::PushL( lmBuf );
       
   223     TAiwGenericParam param( EGenericParamLandmark, TAiwVariant( *lmBuf ) );     
       
   224     iInList->AppendL( param );       
       
   225     TMnAiwCommonOptionsParam options;
       
   226     options.iRunChained = EFalse;
       
   227     TPckg<TMnAiwCommonOptionsParam> optionsPack( options );
       
   228     TAiwGenericParam optParam( EGenericParamMnCommonOptions, TAiwVariant( optionsPack ) );
       
   229     iInList->AppendL( optParam );
       
   230         
       
   231     //navigate to location
       
   232     iAiwServiceHandler->AttachL( R_EVTMGMTUI_AIW_INTEREST_NAVIGATETO );
       
   233     iAiwServiceHandler->ExecuteServiceCmdL( KAiwCmdMnNavigateTo, *iInList, *iOutList, 0, this ); 
       
   234     
       
   235     CleanupStack::PopAndDestroy( 2 ); //lmbuf, lmk
       
   236     }
       
   237         
       
   238         
       
   239 // -----------------------------------------------------------------------------
       
   240 // CEvtMgmtUiMapNavigationAdapter::MapServiceProvidersL
       
   241 // It will return total map service providers.
       
   242 // @ret total number of map service providers
       
   243 // -----------------------------------------------------------------------------
       
   244 //
       
   245 TInt CEvtMgmtUiMapNavigationAdapter::MapServiceProvidersL()
       
   246     {
       
   247     RPointerArray<CMnProvider> providers;
       
   248     // get all providers
       
   249     MnProviderFinder::FindProvidersL( providers );
       
   250     TInt total = providers.Count();
       
   251     providers.ResetAndDestroy();
       
   252     providers.Close();
       
   253     Debug(_L("Total map service providers = %d"), total);
       
   254     return total;
       
   255     }
       
   256 
       
   257 // -----------------------------------------------------------------------------
       
   258 // CEvtMgmtUiMapNavigationAdapter::HandleNotifyL
       
   259 // Derived from MAiwNotifyCallback
       
   260 // -----------------------------------------------------------------------------
       
   261  TInt CEvtMgmtUiMapNavigationAdapter::HandleNotifyL( TInt /*aCmdId*/, 
       
   262                                                         TInt /*aEventId*/, 
       
   263                                                         CAiwGenericParamList& /*aEventParamList*/,
       
   264                                                         const CAiwGenericParamList& /*aInParamList*/ )
       
   265     {
       
   266     if ( iOutList->Count() ) //if location is selected on map
       
   267         {
       
   268         const TAiwGenericParam& param = ( *iOutList )[0];
       
   269         if ( EGenericParamLandmark == param.SemanticId() )
       
   270             {
       
   271             TPtrC8 landmarkData( param.Value().AsData() );
       
   272             CPosLandmark* lm = PosLandmarkSerialization::UnpackL( landmarkData );
       
   273             CleanupStack::PushL( lm );           
       
   274             
       
   275             SetPlaceFromLandmarkL( *lm );
       
   276             CleanupStack::PopAndDestroy( lm );
       
   277             iOutList->Reset(); 
       
   278             iObserver->HandleMapAndNavigationResponseL( KErrNone, *iPlace, iTriggerLocation );
       
   279             }
       
   280         else
       
   281             {
       
   282             iOutList->Reset(); 
       
   283             iObserver->HandleMapAndNavigationResponseL( KErrCancel, *iPlace, iTriggerLocation );             
       
   284             }         
       
   285         }
       
   286     else //if map application is cancelled
       
   287         iObserver->HandleMapAndNavigationResponseL( KErrCancel, *iPlace, iTriggerLocation );
       
   288     return KErrNone;
       
   289     }
       
   290  
       
   291  // -----------------------------------------------------------------------------
       
   292  // CEvtMgmtUiMapNavigationAdapter::PlaceFromLandmarkL
       
   293  // It will set place details from landmark recieved from map
       
   294  // @param[in] aLandmark - landmark selected on map 
       
   295  // -----------------------------------------------------------------------------
       
   296  void CEvtMgmtUiMapNavigationAdapter::SetPlaceFromLandmarkL( CPosLandmark& aLandmark )
       
   297      {            
       
   298     _LIT(KCommaSeparator,", ");
       
   299     
       
   300     //retrieve lat long info
       
   301     TLocality locality;
       
   302     aLandmark.GetPosition( locality );
       
   303     iTriggerLocation = locality;
       
   304     
       
   305     //retrive position description
       
   306     delete iPlace;
       
   307     iPlace = NULL;
       
   308     iPlace = HBufC::NewL(KPlaceMaxLength);       
       
   309     TPtr placePtr = iPlace->Des();
       
   310     
       
   311     TPtrC ptr(KNullDesC);
       
   312     
       
   313     //Landmark Name
       
   314     if( aLandmark.GetLandmarkName(ptr) == KErrNone && ptr.Compare(KNullDesC)!=0 )
       
   315         {                      
       
   316         placePtr.Copy(ptr);           
       
   317         placePtr.Append(_L(" "));            
       
   318         }
       
   319              
       
   320     //retrieve street
       
   321     if(aLandmark.GetPositionField(EPositionFieldStreet,ptr)!=KErrNotFound && ptr.Compare(KNullDesC)!=0)
       
   322        {           
       
   323        placePtr.Append(ptr);
       
   324        placePtr.Append(KCommaSeparator);
       
   325        }
       
   326     //retrieve city
       
   327     if(aLandmark.GetPositionField(EPositionFieldCity,ptr)!=KErrNotFound && ptr.Compare(KNullDesC)!=0)
       
   328       { 
       
   329       placePtr.Append(ptr);
       
   330       placePtr.Append(KCommaSeparator);
       
   331       }  
       
   332     //retrieve state
       
   333     if(aLandmark.GetPositionField(EPositionFieldState,ptr)!=KErrNotFound && ptr.Compare(KNullDesC)!=0)
       
   334       {           
       
   335       placePtr.Append(ptr);
       
   336       placePtr.Append(KCommaSeparator);
       
   337       }
       
   338     //retrieve county
       
   339     if(aLandmark.GetPositionField(EPositionFieldCounty,ptr)!=KErrNotFound && ptr.Compare(KNullDesC)!=0)
       
   340       { 
       
   341       placePtr.Append(KCommaSeparator);
       
   342       placePtr.Append(ptr);
       
   343       }
       
   344     //retrieve country
       
   345     if(aLandmark.GetPositionField(EPositionFieldCountry,ptr)!=KErrNotFound && ptr.Compare(KNullDesC)!=0)
       
   346       {           
       
   347       placePtr.Append(ptr);
       
   348       placePtr.Append(KCommaSeparator);
       
   349       }      
       
   350        
       
   351     // if address is not present, set place to timestamp
       
   352     if( placePtr.Compare( KNullDesC ) != 0 )
       
   353         {
       
   354         TInt commaDesLen = KCommaSeparator().Length();
       
   355         if(placePtr.Mid(placePtr.Length()-commaDesLen,commaDesLen).Compare(KCommaSeparator)==0)
       
   356             placePtr.Delete(placePtr.Length()-commaDesLen, commaDesLen);
       
   357         else
       
   358             placePtr.Delete(placePtr.Length()-1,1); 
       
   359         }
       
   360     }
       
   361 // End of file