phonebookui/Phonebook2/MapExtension/src/cpmapcmd.cpp
changeset 0 e686773b3f54
child 14 81f8547efd4f
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2005-2007 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:  Execute Maps application.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDES
       
    19 #include "cpmapcmd.h"
       
    20 
       
    21 // Phonebook 2
       
    22 #include <MPbk2ContactUiControl.h>
       
    23 #include <MPbk2CommandObserver.h>
       
    24 #include <MPbk2CommandHandler.h>
       
    25 #include <MPbk2ApplicationServices.h>
       
    26 #include <MPbk2AppUi.h>
       
    27 #include <CPbk2FieldPropertyArray.h>
       
    28 #include <Pbk2MapUIRes.rsg>
       
    29 #include <MPbk2ContactEditorControl.h>
       
    30 #include <MPbk2ContactEditorField.h>
       
    31 #include <Pbk2UIControls.hrh>
       
    32 #include <Pbk2Commands.hrh>
       
    33 #include <Pbk2UIControls.rsg>
       
    34 #include <TPbk2AddressSelectParams.h>
       
    35 #include <CPbk2AddressSelect.h>
       
    36 #include <Pbk2AddressTools.h>
       
    37 #include <Pbk2UIControls.rsg>
       
    38 #include <CPbk2ApplicationServices.h>
       
    39 #include <pbk2mapcommands.hrh>
       
    40 
       
    41 // Virtual Phonebook
       
    42 #include <MVPbkBaseContactField.h>
       
    43 #include <MVPbkStoreContact.h>
       
    44 #include <MVPbkContactAttributeManager.h>
       
    45 #include <CVPbkVoiceTagAttribute.h>
       
    46 #include <CVPbkContactManager.h>
       
    47 #include <CVPbkFieldTypeSelector.h>
       
    48 #include <CVPbkFieldFilter.h>
       
    49 #include <MVPbkStoreContactField.h>
       
    50 #include <MVPbkContactFieldData.h>
       
    51 #include <MVPbkContactFieldTextData.h>
       
    52 #include <VPbkEng.rsg>
       
    53 #include <MVPbkFieldType.h>
       
    54 #include <TVPbkFieldVersitProperty.h>
       
    55 #include <MVPbkStoreContactFieldCollection.h>
       
    56 #include <TVPbkFieldTypeParameters.h>
       
    57 #include "MPbk2ContactEditorControlExtension.h"
       
    58 #include <MVPbkContactStoreProperties.h>
       
    59 #include <MVPbkContactStore.h>
       
    60 #include <MVPbkBaseContact.h>
       
    61 #include <MVPbkViewContact.h>
       
    62 #include <MPbk2FieldProperty.h>
       
    63 
       
    64  
       
    65 
       
    66 // System includes
       
    67 #include <lbsposition.h>
       
    68 #include <AiwServiceHandler.h>
       
    69 #include <mnaiwservices.h>
       
    70 #include <mnmapview.h>
       
    71 #include <mnproviderfinder.h>
       
    72 #include <mngeocoder.h>
       
    73 #include <EPos_CPosLandmark.h>
       
    74 #include <epos_poslandmarkserialization.h>
       
    75 #include <eikclb.h>
       
    76 #include <aknPopup.h>
       
    77 #include <eiktxlbm.h>
       
    78 #include <aknnotewrappers.h>
       
    79 #include <coemain.h>
       
    80 #include <barsread.h>
       
    81 #include <avkon.rsg>
       
    82 #include <StringLoader.h>
       
    83 
       
    84 // Debugging headers
       
    85 #include <Pbk2Debug.h>
       
    86 
       
    87 _LIT( KGeoSeparator, ",");
       
    88 const TInt KGeoSeparatorLength = 1;
       
    89 const TReal32 KGeoHorizontalAccuracy = 0;
       
    90 const TInt KGeoMaxSize = 50;
       
    91 const TInt KGeoFormatWidth = 11;
       
    92 
       
    93 // --------------------------------------------------------------------------
       
    94 // CPmapCmd::CPmapCmd
       
    95 // --------------------------------------------------------------------------
       
    96 //
       
    97 CPmapCmd::CPmapCmd( MPbk2ContactEditorControl& aEditorControl,
       
    98 		MVPbkStoreContact& aContact, TInt aCommandId ) :
       
    99 		        iEditorControl( &aEditorControl ),
       
   100 		        iContact( &aContact ),
       
   101             iCommandId( aCommandId )            
       
   102     {
       
   103     iAddressUpdatePrompt = ETrue;
       
   104     }
       
   105 
       
   106 // --------------------------------------------------------------------------
       
   107 // CPmapCmd::CPmapCmd
       
   108 // --------------------------------------------------------------------------
       
   109 //
       
   110 CPmapCmd::CPmapCmd( MPbk2ContactUiControl& aUiControl, TInt aCommandId ) :
       
   111             iUiControl( &aUiControl ),
       
   112             iCommandId( aCommandId )
       
   113     {
       
   114     iAddressUpdatePrompt = ETrue;
       
   115     }
       
   116 
       
   117 // --------------------------------------------------------------------------
       
   118 // CPmapCmd::~CPmapCmd
       
   119 // --------------------------------------------------------------------------
       
   120 //
       
   121 CPmapCmd::~CPmapCmd()
       
   122     {
       
   123     if( iUiControl )
       
   124 	    {
       
   125 	    iUiControl->RegisterCommand( NULL );
       
   126 	    }
       
   127     delete iMapViewProvider;
       
   128     }
       
   129 
       
   130 // --------------------------------------------------------------------------
       
   131 // CPmapCmd::NewL
       
   132 // --------------------------------------------------------------------------
       
   133 //
       
   134 CPmapCmd* CPmapCmd::NewL
       
   135         ( MPbk2ContactEditorControl& aEditorControl,
       
   136           MVPbkStoreContact& aContact, TInt aCommandId )
       
   137     {
       
   138     CPmapCmd* self = new ( ELeave ) CPmapCmd
       
   139         ( aEditorControl, aContact, aCommandId );
       
   140     CleanupStack::PushL( self );
       
   141     self->ConstructL();
       
   142     CleanupStack::Pop( self );
       
   143     return self;
       
   144     }
       
   145 
       
   146 // --------------------------------------------------------------------------
       
   147 // CPmapCmd::NewL
       
   148 // --------------------------------------------------------------------------
       
   149 //
       
   150 CPmapCmd* CPmapCmd::NewL
       
   151         ( MPbk2ContactUiControl& aUiControl, TInt aCommandId )
       
   152     {
       
   153     CPmapCmd* self = new ( ELeave ) CPmapCmd
       
   154         ( aUiControl, aCommandId );
       
   155     CleanupStack::PushL( self );
       
   156     self->ConstructL();
       
   157     CleanupStack::Pop( self );
       
   158     return self;
       
   159     }
       
   160 
       
   161 // --------------------------------------------------------------------------
       
   162 // CPmapCmd::ConstructL
       
   163 // --------------------------------------------------------------------------
       
   164 //
       
   165 void CPmapCmd::ConstructL()
       
   166     {
       
   167     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   168         ("CPmapCmd::ConstructL"));    
       
   169     
       
   170     RPointerArray<CMnProvider> providers;
       
   171 
       
   172     MnProviderFinder::FindProvidersL( providers, CMnProvider::EServiceMapView );
       
   173     CleanupClosePushL( providers );
       
   174     if (providers.Count() > 0)
       
   175         {
       
   176         iMapViewProvider = providers[0];
       
   177         providers.Remove(0);
       
   178         }
       
   179 
       
   180     providers.ResetAndDestroy();
       
   181     CleanupStack::PopAndDestroy( &providers );
       
   182                 
       
   183     if ( !iMapViewProvider )
       
   184         {
       
   185         User::Leave( KErrGeneral );
       
   186         }
       
   187     
       
   188     if( iUiControl && ! iContact )
       
   189     	{
       
   190     	iContact = const_cast<MVPbkStoreContact*>(iUiControl->FocusedStoreContact());
       
   191     	if( !iContact )
       
   192     		{
       
   193 	    	iUiControl->RegisterCommand( this );
       
   194 	    	const MVPbkViewContact* viewContact = iUiControl->FocusedViewContactL();
       
   195 	    	if( viewContact )
       
   196 	    		{
       
   197 	    		viewContact->ReadL(*this);
       
   198 		        CActiveScheduler::Start();
       
   199 		        }
       
   200     		}
       
   201     	}
       
   202     
       
   203     User::LeaveIfNull(iContact);
       
   204     
       
   205     if( iCommandId == EPbk2ExtensionAssignFromMapSelect )
       
   206     	{
       
   207     	iCommandId = EPbk2ExtensionAssignFromMap;
       
   208     	}
       
   209     
       
   210     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   211         ("CPmapCmd::ConstructL end"));        
       
   212     }
       
   213 
       
   214 // --------------------------------------------------------------------------
       
   215 // CPmapCmd::CheckViewProviderL
       
   216 // --------------------------------------------------------------------------
       
   217 //
       
   218 TBool CPmapCmd::CheckViewProviderL()
       
   219     {
       
   220     TBool ret = EFalse;
       
   221     RPointerArray<CMnProvider> providers;
       
   222 
       
   223     MnProviderFinder::FindProvidersL( providers, CMnProvider::EServiceMapView );
       
   224     
       
   225     CleanupClosePushL(providers);
       
   226     
       
   227     if ( providers.Count() > 0 )
       
   228         {
       
   229         ret = ETrue;
       
   230         }
       
   231 
       
   232     providers.ResetAndDestroy();
       
   233     CleanupStack::PopAndDestroy( &providers );
       
   234     return ret;
       
   235     }
       
   236 
       
   237 // --------------------------------------------------------------------------
       
   238 // CPmapCmd::ExecuteLD
       
   239 // --------------------------------------------------------------------------
       
   240 //
       
   241 void CPmapCmd::ExecuteLD()
       
   242     {
       
   243     CleanupStack::PushL( this );
       
   244 
       
   245     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   246         ("CPmapCmd::ExecuteLD"));
       
   247 
       
   248     iAddressUpdatePrompt = ETrue;
       
   249     TPbk2FieldGroupId groupId = EPbk2FieldGroupIdNone;
       
   250     if( !IsAddressInContact() )
       
   251     	{
       
   252     	if( iCommandId == EPbk2ExtensionShowOnMap )
       
   253     		{
       
   254     		HBufC* prompt = StringLoader::LoadLC( R_QTN_PHOB_NO_ADDRESS_DEFINE_NEW );
       
   255     		CAknQueryDialog* dlg = CAknQueryDialog::NewL();
       
   256 			if( dlg->ExecuteLD( R_PBK2_GENERAL_CONFIRMATION_QUERY, *prompt ) )
       
   257 				{
       
   258 				CleanupStack::PopAndDestroy( prompt );
       
   259 				groupId = EPbk2FieldGroupIdPostalAddress;
       
   260 				iCommandId = EPbk2ExtensionAssignFromMap;
       
   261 				}
       
   262 			else
       
   263 				{
       
   264 				CleanupStack::PopAndDestroy( prompt );
       
   265 				FinishProcess();
       
   266 				
       
   267 				if( !iUiControl )
       
   268 					{
       
   269 					CleanupStack::PopAndDestroy( this );
       
   270 					}
       
   271 				else
       
   272 					{
       
   273 					CleanupStack::Pop( this );
       
   274 					}
       
   275 				
       
   276 				PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   277 					("CPmapCmd::ExecuteLD end"));
       
   278 				
       
   279 				return;
       
   280 				}
       
   281 			
       
   282     		}
       
   283     	else
       
   284     		{
       
   285     		groupId = EPbk2FieldGroupIdPostalAddress;
       
   286     		}
       
   287     	iAddressUpdatePrompt = EFalse;
       
   288     	}
       
   289 
       
   290      if( groupId == EPbk2FieldGroupIdNone )
       
   291     	{
       
   292     	groupId = GetAddressFromEditorView();
       
   293     	}
       
   294     
       
   295     if( groupId == EPbk2FieldGroupIdNone )
       
   296     	{
       
   297     	groupId = GetAddressFromUiControl();
       
   298     	}
       
   299     
       
   300     if( groupId == EPbk2FieldGroupIdNone )
       
   301 		{
       
   302 		groupId = GetAddressIfIsAlone();
       
   303 		}
       
   304     
       
   305     if( groupId == EPbk2FieldGroupIdNone )
       
   306     	{
       
   307     	groupId = SelectAddressL();
       
   308     	}
       
   309     
       
   310     if( groupId != EPbk2FieldGroupIdNone )
       
   311     	{
       
   312 	    TVPbkFieldTypeParameter addressType = Pbk2AddressTools::MapAddressToVersitParam( groupId );
       
   313 	    if( iCommandId == EPbk2ExtensionShowOnMap )
       
   314     		{
       
   315     		EditorShowOnMapsL(addressType);
       
   316     		}
       
   317     	else if( iCommandId == EPbk2ExtensionAssignFromMap )
       
   318     		{
       
   319     		EditorAssignFromMapsL(addressType);
       
   320     		}
       
   321     	}
       
   322     
       
   323     FinishProcess();
       
   324 
       
   325     if( !iUiControl )
       
   326     	{
       
   327     	CleanupStack::PopAndDestroy( this );
       
   328     	}
       
   329     else
       
   330     	{
       
   331     	CleanupStack::Pop( this );
       
   332     	}
       
   333     
       
   334     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   335         ("CPmapCmd::ExecuteLD end"));
       
   336     }
       
   337 
       
   338 // --------------------------------------------------------------------------
       
   339 // CPmapCmd::GetAddressIfIsAlone
       
   340 // --------------------------------------------------------------------------
       
   341 //
       
   342 TPbk2FieldGroupId CPmapCmd::GetAddressIfIsAlone()
       
   343     {
       
   344     TPbk2FieldGroupId grupId = EPbk2FieldGroupIdNone;
       
   345     MVPbkStoreContactFieldCollection& arrFields = iContact->Fields();
       
   346 	TInt count = arrFields.FieldCount();
       
   347 	for( TInt idx = 0; idx < count; idx++)
       
   348 		{
       
   349 		MVPbkStoreContactField& field = arrFields.FieldAt(idx);
       
   350 		TArray<TVPbkFieldVersitProperty> arrProp = field.BestMatchingFieldType()->VersitProperties();
       
   351 		for( TInt idx2 = 0; idx2 < arrProp.Count(); idx2++)
       
   352 			{
       
   353 			if( arrProp[idx2].Name() == EVPbkVersitNameADR  )
       
   354 				{
       
   355 				if( arrProp[idx2].Parameters().Contains( EVPbkVersitParamHOME ) )
       
   356 					{
       
   357 					if( grupId == EPbk2FieldGroupIdNone )
       
   358 						{
       
   359 						grupId = EPbk2FieldGroupIdHomeAddress;
       
   360 						}
       
   361 					else if( grupId != EPbk2FieldGroupIdHomeAddress )
       
   362 						{
       
   363 						return EPbk2FieldGroupIdNone;
       
   364 						}
       
   365 					}
       
   366 				else if( arrProp[idx2].Parameters().Contains( EVPbkVersitParamWORK ) )
       
   367 					{
       
   368 					if( grupId == EPbk2FieldGroupIdNone )
       
   369 						{
       
   370 						grupId = EPbk2FieldGroupIdCompanyAddress;
       
   371 						}
       
   372 					else if( grupId != EPbk2FieldGroupIdCompanyAddress )
       
   373 						{
       
   374 						return EPbk2FieldGroupIdNone;
       
   375 						}
       
   376 					}
       
   377 				else
       
   378 					{
       
   379 					if( grupId == EPbk2FieldGroupIdNone )
       
   380 						{
       
   381 						grupId = EPbk2FieldGroupIdPostalAddress;
       
   382 						}
       
   383 					else if( grupId != EPbk2FieldGroupIdPostalAddress )
       
   384 						{
       
   385 						return EPbk2FieldGroupIdNone;
       
   386 						}
       
   387 					}
       
   388 				}
       
   389 			}
       
   390 		}
       
   391     
       
   392 	return grupId;
       
   393     }
       
   394 
       
   395 // --------------------------------------------------------------------------
       
   396 // CPmapCmd::GetAddressFromEditorView
       
   397 // --------------------------------------------------------------------------
       
   398 //
       
   399 TPbk2FieldGroupId CPmapCmd::GetAddressFromEditorView()
       
   400     {
       
   401     TPbk2FieldGroupId grupId = EPbk2FieldGroupIdNone;
       
   402     if( ControlExtension() )
       
   403     	{
       
   404     	grupId = Pbk2AddressTools::MapCtrlTypeToAddress( ControlExtension()->FocusedControlType() );
       
   405     	}
       
   406     
       
   407     if( iEditorControl && grupId == EPbk2FieldGroupIdNone )
       
   408     	{
       
   409 		TInt countControls = iEditorControl->NumberOfControls();
       
   410 		for ( TInt idx = 0; idx < countControls; idx++ )
       
   411 		    {
       
   412 		    MPbk2ContactEditorField& field = iEditorControl->EditorField( idx );
       
   413 		    
       
   414 		    grupId = field.FieldProperty().GroupId();
       
   415 		    if( grupId == EPbk2FieldGroupIdPostalAddress || 
       
   416 				grupId == EPbk2FieldGroupIdHomeAddress || 
       
   417 				grupId == EPbk2FieldGroupIdCompanyAddress )
       
   418 		    	{
       
   419 		    	iAddressView = ETrue;
       
   420 		    	break;
       
   421 		    	}
       
   422 		    }
       
   423     	}
       
   424     
       
   425 	return grupId;
       
   426     }
       
   427 
       
   428 // --------------------------------------------------------------------------
       
   429 // CPmapCmd::GetAddressFromUiControl
       
   430 // --------------------------------------------------------------------------
       
   431 //
       
   432 TPbk2FieldGroupId CPmapCmd::GetAddressFromUiControl()
       
   433     {
       
   434     TPbk2FieldGroupId ret = EPbk2FieldGroupIdNone;
       
   435     const MVPbkBaseContactField* field = NULL;
       
   436     if( iUiControl )
       
   437     	{
       
   438     	field = iUiControl->FocusedField();
       
   439     	}
       
   440     if( field )
       
   441     	{
       
   442     	const MVPbkFieldType* type = field->BestMatchingFieldType();
       
   443     	if( type )
       
   444     		{
       
   445     		TArray<TVPbkFieldVersitProperty> arrProp = type->VersitProperties();
       
   446     		for( TInt idx = 0; idx < arrProp.Count(); idx++)
       
   447 				{
       
   448 				if( arrProp[idx].Name() != EVPbkVersitNameADR )
       
   449 					{
       
   450 					continue;
       
   451 					}
       
   452 				
       
   453 				if( arrProp[idx].Parameters().Contains( 
       
   454 					Pbk2AddressTools::MapAddressToVersitParam( EPbk2FieldGroupIdHomeAddress ) ) )
       
   455 					{
       
   456 					ret = EPbk2FieldGroupIdHomeAddress;
       
   457 					break;
       
   458 					}
       
   459 				else if( arrProp[idx].Parameters().Contains( 
       
   460 					Pbk2AddressTools::MapAddressToVersitParam( EPbk2FieldGroupIdCompanyAddress ) ) )
       
   461 					{
       
   462 					ret = EPbk2FieldGroupIdCompanyAddress;
       
   463 					break;
       
   464 					}
       
   465 				else
       
   466 					{
       
   467 					ret = EPbk2FieldGroupIdPostalAddress;
       
   468 					break;
       
   469 					}
       
   470 				}
       
   471     		}
       
   472     	}
       
   473     
       
   474 	return ret;
       
   475     }
       
   476 
       
   477 // --------------------------------------------------------------------------
       
   478 // CPmapCmd::SelectAddressL
       
   479 // --------------------------------------------------------------------------
       
   480 //
       
   481 TPbk2FieldGroupId CPmapCmd::SelectAddressL()
       
   482    {
       
   483     TPbk2FieldGroupId ret = EPbk2FieldGroupIdNone;
       
   484 
       
   485     TResourceReader resReader;
       
   486     CCoeEnv::Static()->CreateResourceReaderLC
       
   487         (resReader, R_PBK2_ADDRESS_SELECT);
       
   488 
       
   489     CPbk2ApplicationServices* appServices =
       
   490         CPbk2ApplicationServices::InstanceLC();
       
   491 
       
   492     TPbk2AddressSelectParams params(
       
   493         *iContact,
       
   494         appServices->ContactManager(),
       
   495         appServices->NameFormatter(),
       
   496         appServices->FieldProperties(),
       
   497         resReader );
       
   498     if ( iCommandId == EPbk2ExtensionShowOnMap )
       
   499     	{
       
   500     	params.iCommMethod = VPbkFieldTypeSelectorFactory::EFindOnMapSelector;
       
   501     	}
       
   502     else
       
   503     	{
       
   504         params.iCommMethod = VPbkFieldTypeSelectorFactory::EAssignFromMapSelector;
       
   505     	}
       
   506 
       
   507     CleanupStack::PopAndDestroy( appServices );
       
   508     CPbk2AddressSelect* addressSelect = CPbk2AddressSelect::NewL( params );
       
   509     MVPbkStoreContactField* selectedField = addressSelect->ExecuteLD();
       
   510     CleanupStack::PopAndDestroy(); // resReader
       
   511 
       
   512     if ( selectedField )
       
   513     	{
       
   514     	CleanupDeletePushL( selectedField );
       
   515     	ret = GetFieldGroupL( *selectedField );
       
   516         CleanupStack::PopAndDestroy( selectedField );
       
   517     	}
       
   518 
       
   519     return ret;    
       
   520    }
       
   521 
       
   522 // --------------------------------------------------------------------------
       
   523 // CPmapCmd::ControlExtension
       
   524 // --------------------------------------------------------------------------
       
   525 //
       
   526 MPbk2ContactEditorControlExtension* CPmapCmd::ControlExtension()
       
   527     {
       
   528     if(iEditorControl && iEditorControl->ContactEditorControlExtension(TUid::Null()))
       
   529     	{
       
   530     	return static_cast<MPbk2ContactEditorControlExtension*>
       
   531     		(iEditorControl->ContactEditorControlExtension(TUid::Null()));
       
   532     	}
       
   533     return NULL;
       
   534     }
       
   535 
       
   536 // --------------------------------------------------------------------------
       
   537 // CPmapCmd::AddObserver
       
   538 // --------------------------------------------------------------------------
       
   539 //
       
   540 void CPmapCmd::AddObserver( MPbk2CommandObserver& aObserver )
       
   541     {
       
   542     iObserver = &aObserver;
       
   543     }
       
   544 
       
   545 // --------------------------------------------------------------------------
       
   546 // CPmapCmd::ResetUiControl
       
   547 // --------------------------------------------------------------------------
       
   548 //
       
   549 void CPmapCmd::ResetUiControl( MPbk2ContactUiControl& aUiControl )
       
   550     {
       
   551     if (iUiControl == &aUiControl)
       
   552         {
       
   553         iUiControl = NULL;
       
   554         }
       
   555     }
       
   556 
       
   557 // --------------------------------------------------------------------------
       
   558 // CPmapCmd::FinishProcess
       
   559 // --------------------------------------------------------------------------
       
   560 //
       
   561 void CPmapCmd::FinishProcess()
       
   562     {
       
   563     if (iObserver)
       
   564         {
       
   565         iObserver->CommandFinished( *this );
       
   566         }
       
   567     }
       
   568     
       
   569 // --------------------------------------------------------------------------
       
   570 // CPmapCmd::EditorShowMapL
       
   571 // --------------------------------------------------------------------------
       
   572 //
       
   573 void CPmapCmd::EditorShowOnMapsL(TVPbkFieldTypeParameter aAddressType)
       
   574 	{
       
   575     CMnMapView* mapview = CMnMapView::NewL( *iMapViewProvider );
       
   576 	CleanupStack::PushL( mapview );
       
   577 	        	        
       
   578 	RPointerArray<CPosLandmark> landmarks;
       
   579 	CleanupClosePushL( landmarks );
       
   580 	
       
   581 	CPosLandmark* landmark = CPosLandmark::NewL();
       
   582 	CleanupStack::PushL( landmark );
       
   583 	
       
   584 	if ( !FillGeoLandmarkL( *landmark, aAddressType ) )
       
   585 		{
       
   586 		FillLandmarkL( *landmark, aAddressType );
       
   587 		}
       
   588 	TLocality locality;
       
   589 	if( landmark->NumOfAvailablePositionFields() > 0 || landmark->GetPosition( locality ) == KErrNone )
       
   590 		{
       
   591 		landmarks.AppendL( landmark );
       
   592 		mapview->AddLandmarksToShowL( landmarks );
       
   593 		}
       
   594 	mapview->ShowMapL();
       
   595 
       
   596 	CleanupStack::PopAndDestroy( landmark );
       
   597 	CleanupStack::PopAndDestroy( &landmarks );
       
   598 	CleanupStack::PopAndDestroy( mapview );
       
   599 	}
       
   600 
       
   601 // --------------------------------------------------------------------------
       
   602 // CPmapCmd::FillLandmarkL
       
   603 // --------------------------------------------------------------------------
       
   604 //
       
   605 void CPmapCmd::FillLandmarkL(CPosLandmark& aLandmark, TVPbkFieldTypeParameter aAddressType)
       
   606 	{
       
   607 	if( iAddressView && iEditorControl )
       
   608 		{
       
   609 		TInt count = iEditorControl->NumberOfControls();
       
   610 		for( TInt idx1 = 0; idx1 < count; idx1++)
       
   611 			{
       
   612 			MPbk2ContactEditorField& field = iEditorControl->EditorField(idx1);
       
   613 			HBufC* uiData = field.ControlTextL();
       
   614 			if( !uiData || !uiData->Length() )
       
   615 				continue;
       
   616 			
       
   617 			CleanupStack::PushL(uiData);
       
   618 			TArray<TVPbkFieldVersitProperty> arrProp = field.FieldProperty().FieldType().VersitProperties();
       
   619 			for( TInt idx2 = 0; idx2 < arrProp.Count(); idx2++)
       
   620 				{
       
   621 				if( arrProp[idx2].Name() == EVPbkVersitNameADR )
       
   622 					{
       
   623 					
       
   624 					if( arrProp[idx2].SubField() == EVPbkVersitSubFieldCountry )
       
   625 						{
       
   626 						aLandmark.SetPositionFieldL( EPositionFieldCountry, uiData->Des() );
       
   627 						continue;
       
   628 						}
       
   629 					else if( arrProp[idx2].SubField() == EVPbkVersitSubFieldLocality )
       
   630 						{
       
   631 						aLandmark.SetPositionFieldL( EPositionFieldCity, uiData->Des() );
       
   632 						continue;
       
   633 						}
       
   634 					else if( arrProp[idx2].SubField() == EVPbkVersitSubFieldStreet )
       
   635 						{
       
   636 						aLandmark.SetPositionFieldL( EPositionFieldStreet, uiData->Des() );
       
   637 						continue;
       
   638 						}
       
   639 					else if( arrProp[idx2].SubField() == EVPbkVersitSubFieldPostalCode )
       
   640 						{
       
   641 						aLandmark.SetPositionFieldL( EPositionFieldPostalCode, uiData->Des() );
       
   642 						continue;
       
   643 						}
       
   644 					}
       
   645 				}
       
   646 			CleanupStack::PopAndDestroy(uiData);
       
   647 			}
       
   648 		}
       
   649 	else
       
   650 		{
       
   651 		MVPbkStoreContactFieldCollection& arrFields = iContact->Fields();
       
   652 		TInt count = arrFields.FieldCount();
       
   653 		for( TInt idx = 0; idx < count; idx++)
       
   654 			{
       
   655 			MVPbkStoreContactField& field = arrFields.FieldAt(idx);
       
   656 			const MVPbkContactFieldData& fieldData = field.FieldData();
       
   657 			if( fieldData.DataType() != EVPbkFieldStorageTypeText )
       
   658 				{
       
   659 				continue;
       
   660 				}
       
   661 			const TDesC& dataText = MVPbkContactFieldTextData::Cast( fieldData ).Text();
       
   662 			
       
   663 			if( !dataText.Length() )
       
   664 				{
       
   665 				continue;
       
   666 				}
       
   667 			
       
   668 			TArray<TVPbkFieldVersitProperty> arrProp = field.BestMatchingFieldType()->VersitProperties();
       
   669 			for( TInt idx2 = 0; idx2 < arrProp.Count(); idx2++)
       
   670 				{
       
   671 				if( arrProp[idx2].Name() == EVPbkVersitNameADR && 
       
   672 					( arrProp[idx2].Parameters().Contains(aAddressType) ||
       
   673 					  ( aAddressType == EVPbkVersitParamPREF && 
       
   674 					    !arrProp[idx2].Parameters().Contains(EVPbkVersitParamHOME) &&
       
   675 					    !arrProp[idx2].Parameters().Contains(EVPbkVersitParamWORK) ) ) )
       
   676 					{
       
   677 					if( arrProp[idx2].SubField() == EVPbkVersitSubFieldCountry )
       
   678 						{
       
   679 						aLandmark.SetPositionFieldL( EPositionFieldCountry, dataText );
       
   680 						continue;
       
   681 						}
       
   682 					else if( arrProp[idx2].SubField() == EVPbkVersitSubFieldLocality )
       
   683 						{
       
   684 						aLandmark.SetPositionFieldL( EPositionFieldCity, dataText );
       
   685 						continue;
       
   686 						}
       
   687 					else if( arrProp[idx2].SubField() == EVPbkVersitSubFieldStreet )
       
   688 						{
       
   689 						aLandmark.SetPositionFieldL( EPositionFieldStreet, dataText );
       
   690 						continue;
       
   691 						}
       
   692 					else if( arrProp[idx2].SubField() == EVPbkVersitSubFieldPostalCode )
       
   693 						{
       
   694 						aLandmark.SetPositionFieldL( EPositionFieldPostalCode, dataText );
       
   695 						continue;
       
   696 						}
       
   697 					}
       
   698 				}
       
   699 			}
       
   700 		}
       
   701 	}
       
   702 
       
   703 // --------------------------------------------------------------------------
       
   704 // CPmapCmd::FillGeoLandmarkL
       
   705 // --------------------------------------------------------------------------
       
   706 //
       
   707 TBool CPmapCmd::FillGeoLandmarkL(
       
   708 		CPosLandmark& aLandmark, TVPbkFieldTypeParameter aAddressType )
       
   709 	{
       
   710 	TBool result = EFalse;
       
   711 	MVPbkStoreContactFieldCollection& arrFields = iContact->Fields();
       
   712 	TInt count = arrFields.FieldCount();
       
   713 	for( TInt idx = 0; idx < count; idx++ )
       
   714 		{
       
   715 		MVPbkStoreContactField& field = arrFields.FieldAt( idx );
       
   716 		const MVPbkContactFieldData& fieldData = field.FieldData();
       
   717 		if( fieldData.DataType() != EVPbkFieldStorageTypeText )
       
   718 			{
       
   719 			continue;
       
   720 			}
       
   721 		const TDesC& dataText =
       
   722 		    MVPbkContactFieldTextData::Cast( fieldData ).Text();
       
   723 		TInt countProps =
       
   724 			field.BestMatchingFieldType()->VersitProperties().Count();
       
   725 		TArray<TVPbkFieldVersitProperty> props =
       
   726 			field.BestMatchingFieldType()->VersitProperties();
       
   727 		for ( TInt idx2 = 0; idx2 < countProps; idx2++ )
       
   728 			{
       
   729 		    if ( ( props[ idx2 ].Parameters().Contains( EVPbkVersitParamHOME ) &&
       
   730 		         aAddressType == EVPbkVersitParamHOME ) ||
       
   731 			     ( props[ idx2 ].Parameters().Contains( EVPbkVersitParamWORK ) &&
       
   732 		           aAddressType == EVPbkVersitParamWORK ) ||
       
   733 		           ( !props[ idx2 ].Parameters().Contains( EVPbkVersitParamHOME ) &&
       
   734 		             !props[ idx2 ].Parameters().Contains( EVPbkVersitParamWORK ) &&
       
   735 		             aAddressType == EVPbkVersitParamPREF ) )
       
   736 		    	{
       
   737 			    result = DoFillGeoLandmarkL( aLandmark, dataText );
       
   738 			    break;
       
   739 		    	}
       
   740 			}
       
   741 		}
       
   742 	return result;
       
   743 	}
       
   744 
       
   745 // --------------------------------------------------------------------------
       
   746 // CPmapCmd::DoFillGeoLandmarkL
       
   747 // --------------------------------------------------------------------------
       
   748 //
       
   749 TBool CPmapCmd::DoFillGeoLandmarkL(
       
   750 		CPosLandmark& aLandmark, const TDesC& aDataText )
       
   751 	{
       
   752 	TBool result = EFalse;
       
   753 	TInt separator = aDataText.Find( KGeoSeparator );
       
   754 	if ( separator != KErrNotFound )
       
   755 		{
       
   756 		TReal64 latitude = 0;
       
   757 		TReal64 logitude = 0;
       
   758 		TLex lexLatitude( aDataText.Left( aDataText.Length() - separator ) );
       
   759 		TLex lexLogitude( aDataText.Right( aDataText.Length()
       
   760 				- separator - KGeoSeparatorLength ) );
       
   761 		if ( lexLatitude.Val( latitude ) == KErrNone
       
   762 				&& lexLogitude.Val( logitude ) == KErrNone )
       
   763 			{
       
   764 			TLocality loc( TCoordinate( latitude, logitude ),
       
   765 					KGeoHorizontalAccuracy );
       
   766 			aLandmark.SetPositionL( loc );
       
   767 			result = ETrue;
       
   768 			}
       
   769 		}
       
   770 	return result;
       
   771 	}
       
   772 
       
   773 // --------------------------------------------------------------------------
       
   774 // CPmapCmd::EditorAssignFromMapsL
       
   775 // --------------------------------------------------------------------------
       
   776 //
       
   777 void CPmapCmd::EditorAssignFromMapsL(TVPbkFieldTypeParameter aAddressType)
       
   778 	{
       
   779    	CMnMapView* mapview = CMnMapView::NewChainedL( *iMapViewProvider );
       
   780    	CleanupStack::PushL( mapview );
       
   781    	
       
   782     RPointerArray<CPosLandmark> landmarks;
       
   783     CleanupClosePushL( landmarks );
       
   784 
       
   785     CPosLandmark* landmark = CPosLandmark::NewL();
       
   786 	CleanupStack::PushL( landmark );
       
   787 	
       
   788 	if ( !FillGeoLandmarkL( *landmark, aAddressType ) )
       
   789 		{
       
   790 		FillLandmarkL( *landmark, aAddressType );
       
   791 		}
       
   792 	TLocality locality;
       
   793 	TBool noAddress = ETrue;
       
   794 	if( landmark->NumOfAvailablePositionFields() > 0 || landmark->GetPosition( locality ) == KErrNone )
       
   795 		{
       
   796 		landmarks.AppendL( landmark );
       
   797 		mapview->AddLandmarksToShowL( landmarks );
       
   798 		noAddress = EFalse;
       
   799 		}
       
   800 
       
   801     TRequestStatus status;
       
   802 	mapview->SelectFromMapL( status );
       
   803 	User::WaitForRequest( status );
       
   804 	
       
   805 	TBool update = EFalse;
       
   806 	TBool geocoordsExist = EFalse;
       
   807 	
       
   808 	CPosLandmark* result = NULL;
       
   809 	if ( status.Int() == KErrNone )
       
   810 	    {
       
   811 	    result = mapview->RetrieveSelectionResultL();
       
   812 	    if ( result->GetPosition( locality ) == KErrNone )
       
   813 			{
       
   814 			geocoordsExist = ETrue;
       
   815 			}     
       
   816           
       
   817 	    if( result->IsPositionFieldAvailable( EPositionFieldStreet ) || 
       
   818 			result->IsPositionFieldAvailable( EPositionFieldCity ) ||
       
   819 			result->IsPositionFieldAvailable( EPositionFieldCountry ) )
       
   820 			{
       
   821 			update= ETrue;
       
   822 			}
       
   823 		
       
   824 	    }
       
   825     CleanupStack::PopAndDestroy( landmark );
       
   826 	CleanupStack::PopAndDestroy( &landmarks );
       
   827 	CleanupStack::PopAndDestroy( mapview );
       
   828 	if( result )
       
   829 		{
       
   830 		CleanupStack::PushL( result );
       
   831 		}
       
   832 	
       
   833 	if( update )
       
   834 		{
       
   835 		if( iAddressUpdatePrompt && !noAddress )
       
   836 			{
       
   837 			const TInt KGranularity = 4; 
       
   838 			CDesCArrayFlat* arrFields = new ( ELeave ) CDesCArrayFlat
       
   839 					( KGranularity );
       
   840 			CleanupStack::PushL(arrFields);
       
   841 			
       
   842 			HBufC* addrLebel = NULL;
       
   843 			
       
   844 			switch( aAddressType )
       
   845 				{
       
   846 				case EVPbkVersitParamPREF:
       
   847 					addrLebel = StringLoader::LoadLC(R_QTN_PHOB_HEADER_ADDRESS );
       
   848 					break;
       
   849 				case EVPbkVersitParamHOME:
       
   850 					addrLebel = StringLoader::LoadLC( R_QTN_PHOB_HEADER_ADDRESS_HOME );
       
   851 					break;
       
   852 				case EVPbkVersitParamWORK:
       
   853 					addrLebel = StringLoader::LoadLC( R_QTN_PHOB_HEADER_ADDRESS_WORK );
       
   854 					break;
       
   855 				default:
       
   856 					User::Leave(KErrArgument);
       
   857 				}
       
   858 			arrFields->AppendL( addrLebel->Des() );
       
   859 			
       
   860 			_LIT(KComma, ",");
       
   861 			_LIT(KSpace, " ");
       
   862 			
       
   863 			TInt lenght = 0; 
       
   864 			TPtrC street;
       
   865 			if( result->IsPositionFieldAvailable( EPositionFieldStreet ) )
       
   866 				{
       
   867 				result->GetPositionField( EPositionFieldStreet, street );
       
   868 				lenght += street.Length();
       
   869 				}
       
   870 			
       
   871 			TPtrC city;
       
   872 			if( result->IsPositionFieldAvailable( EPositionFieldCity ) )
       
   873 				{
       
   874 				result->GetPositionField( EPositionFieldCity, city );
       
   875 				if( lenght )
       
   876 					{
       
   877 					lenght += KComma().Length() + KSpace().Length();
       
   878 					}
       
   879 				lenght += city.Length();
       
   880 				}	
       
   881 			
       
   882 			TPtrC country;
       
   883 			if( result->IsPositionFieldAvailable( EPositionFieldCountry ) )
       
   884 				{
       
   885 				result->GetPositionField( EPositionFieldCountry, country );
       
   886 				if( lenght )
       
   887 					{
       
   888 					lenght += KComma().Length() + KSpace().Length();
       
   889 					}
       
   890 				lenght += country.Length();
       
   891 				}	
       
   892 			
       
   893 			RBuf newAddr;
       
   894 			newAddr.CreateL( lenght );
       
   895 			CleanupClosePushL( newAddr );
       
   896 			
       
   897 			if( street.Length() )
       
   898 				{
       
   899 				newAddr += street;
       
   900 				}
       
   901 			
       
   902 			if( city.Length() )
       
   903 				{
       
   904 				if( newAddr.Length() > 0 )
       
   905 					{
       
   906 					newAddr += KComma();
       
   907 					newAddr += KSpace();
       
   908 					}
       
   909 				newAddr += city;
       
   910 				}
       
   911 			
       
   912 			if( country.Length() )
       
   913 				{
       
   914 				if( newAddr.Length() > 0 )
       
   915 					{
       
   916 					newAddr += KComma();
       
   917 					newAddr += KSpace();
       
   918 					}
       
   919 				newAddr += country;
       
   920 				}
       
   921 	
       
   922 			arrFields->AppendL( newAddr );
       
   923 			HBufC* prompt = StringLoader::LoadLC( R_QTN_PHOB_CONFIRM_CHANGE_ADDRESS, *arrFields );
       
   924 			CAknQueryDialog* dlg = CAknQueryDialog::NewL();
       
   925 			if( !dlg->ExecuteLD( R_PBK2_GENERAL_CONFIRMATION_QUERY, *prompt ) )
       
   926 				{
       
   927 				update = EFalse;
       
   928 				}
       
   929 			CleanupStack::PopAndDestroy( prompt );
       
   930 			CleanupStack::PopAndDestroy( &newAddr );
       
   931 			CleanupStack::PopAndDestroy( addrLebel );
       
   932 			CleanupStack::PopAndDestroy( arrFields );
       
   933 			}
       
   934 			
       
   935 		if( update )
       
   936 			{
       
   937 			if ( !iEditorControl )
       
   938 				{
       
   939 				iContact->LockL( *this );
       
   940 				CActiveScheduler::Start();
       
   941 				}
       
   942 			UpdateFieldL( *result, EPositionFieldCountry, 
       
   943 							EVPbkVersitSubFieldCountry, aAddressType );
       
   944 			UpdateFieldL( *result, EPositionFieldCity, 
       
   945 							EVPbkVersitSubFieldLocality, aAddressType );
       
   946 			UpdateFieldL( *result, EPositionFieldStreet, 
       
   947 							EVPbkVersitSubFieldStreet, aAddressType );
       
   948 			UpdateFieldL( *result, EPositionFieldPostalCode, 
       
   949 							EVPbkVersitSubFieldPostalCode, aAddressType );
       
   950 			UpdateFieldL( *result, EPositionFieldLocality, 
       
   951 							EVPbkVersitSubFieldRegion, aAddressType );
       
   952 			UpdateFieldL( *result, EPositionFieldNone, 
       
   953 							EVPbkVersitSubFieldPostOfficeAddress, aAddressType );
       
   954 			UpdateFieldL( *result, EPositionFieldNone, 
       
   955 							EVPbkVersitSubFieldExtendedAddress, aAddressType );
       
   956 			
       
   957 			if( geocoordsExist )
       
   958 				{
       
   959 				UpdateCoordsL( locality, aAddressType );
       
   960 				}
       
   961 			if ( !iEditorControl )
       
   962 				{
       
   963 				iContact->CommitL( *this );
       
   964 				CActiveScheduler::Start();
       
   965 				}
       
   966 			if( ControlExtension() )
       
   967 				{
       
   968 				ControlExtension()->UpdateControlsL();
       
   969 				}
       
   970 			
       
   971 			HBufC* text = StringLoader::LoadLC( R_QTN_PHOB_NOTE_ADDRESS_UPDATED );
       
   972 			CAknInformationNote* note = new ( ELeave ) CAknInformationNote( ETrue );
       
   973 			note->ExecuteLD( *text );
       
   974 			CleanupStack::PopAndDestroy( text );
       
   975 			}
       
   976 		}
       
   977 	
       
   978 	if( result )
       
   979 		{
       
   980 		CleanupStack::PopAndDestroy( result );
       
   981 		}
       
   982 	}
       
   983 
       
   984 // --------------------------------------------------------------------------
       
   985 // CPmapCmd::UpdateCoordsL
       
   986 // --------------------------------------------------------------------------
       
   987 //
       
   988 void CPmapCmd::UpdateCoordsL( 
       
   989 		TLocality& aLocality,
       
   990 		TVPbkFieldTypeParameter aAddressType )
       
   991 	{
       
   992 	TReal64 latitude = aLocality.Latitude();
       
   993 	TReal64 longitude = aLocality.Longitude();
       
   994 	RBuf geoData;
       
   995 	RBuf textNumber;
       
   996 	CleanupClosePushL( geoData );
       
   997 	CleanupClosePushL( textNumber );
       
   998 	geoData.CreateL( KGeoMaxSize );
       
   999 	textNumber.CreateL( KGeoMaxSize );
       
  1000 	TRealFormat format( KGeoFormatWidth );
       
  1001 	textNumber.Num( latitude, format );
       
  1002 	geoData = textNumber;
       
  1003 	geoData += KGeoSeparator();
       
  1004 	textNumber.Num( longitude, format );
       
  1005 	geoData += textNumber;
       
  1006 	CleanupStack::PopAndDestroy( &textNumber );
       
  1007 	
       
  1008 	TBool updated = EFalse;
       
  1009 	MVPbkStoreContactFieldCollection& arrFields = iContact->Fields();
       
  1010 	TInt count = arrFields.FieldCount();
       
  1011 	for( TInt idx = 0; idx < count; idx++)
       
  1012 		{
       
  1013 		MVPbkStoreContactField& field = arrFields.FieldAt(idx);
       
  1014 		TInt countProps =
       
  1015 		    field.BestMatchingFieldType()->VersitProperties().Count();
       
  1016 		TArray<TVPbkFieldVersitProperty> props =
       
  1017 		    field.BestMatchingFieldType()->VersitProperties();
       
  1018 		for ( TInt idx2 = 0; idx2 < countProps; idx2++ )
       
  1019 		    {
       
  1020 		    if ( props[ idx2 ].Name() == EVPbkVersitNameGEO &&
       
  1021 		    	 ( ( props[ idx2 ].Parameters().Contains( EVPbkVersitParamHOME ) &&
       
  1022                    aAddressType == EVPbkVersitParamHOME ) ||
       
  1023 		    	   ( props[ idx2 ].Parameters().Contains( EVPbkVersitParamWORK ) &&
       
  1024                      aAddressType == EVPbkVersitParamWORK ) ||
       
  1025                      ( !props[ idx2 ].Parameters().Contains( EVPbkVersitParamHOME ) &&
       
  1026                        !props[ idx2 ].Parameters().Contains( EVPbkVersitParamWORK ) &&
       
  1027                        aAddressType == EVPbkVersitParamPREF ) ) )
       
  1028 		        {
       
  1029 		        MVPbkContactFieldData& fieldData = field.FieldData();
       
  1030 		        MVPbkContactFieldTextData& data = 
       
  1031 		            MVPbkContactFieldTextData::Cast( fieldData );
       
  1032 		        data.SetTextL( geoData );
       
  1033 		        updated = ETrue;
       
  1034 		        break;
       
  1035 		        }
       
  1036 		    }
       
  1037 		}
       
  1038 	
       
  1039 	if( !updated )
       
  1040 		{
       
  1041 		MVPbkContactStore& storeContact = iContact->ContactStore();
       
  1042 		const MVPbkContactStoreProperties& storeProp = storeContact.StoreProperties();
       
  1043 		const MVPbkFieldTypeList& fieldList = storeProp.SupportedFields();
       
  1044 		TInt count = fieldList.FieldTypeCount();
       
  1045 		for( TInt idx = 0; idx < count; idx++)
       
  1046 			{
       
  1047 			const MVPbkFieldType& fieldType = fieldList.FieldTypeAt( idx );
       
  1048 			TInt countProps = fieldType.VersitProperties().Count();
       
  1049 			TArray<TVPbkFieldVersitProperty> props =
       
  1050 			    fieldType.VersitProperties();
       
  1051 			for ( TInt idx2 = 0; idx2 < countProps; idx2++ )
       
  1052 				{
       
  1053 				if ( props[ idx2 ].Name() == EVPbkVersitNameGEO &&
       
  1054 				     ( ( props[ idx2 ].Parameters().Contains( EVPbkVersitParamHOME ) &&
       
  1055 					   aAddressType == EVPbkVersitParamHOME ) ||
       
  1056 					   ( props[ idx2 ].Parameters().Contains( EVPbkVersitParamWORK ) &&
       
  1057 			             aAddressType == EVPbkVersitParamWORK ) ||
       
  1058 			             ( !props[ idx2 ].Parameters().Contains( EVPbkVersitParamHOME ) &&
       
  1059 			               !props[ idx2 ].Parameters().Contains( EVPbkVersitParamWORK ) &&
       
  1060 			               aAddressType == EVPbkVersitParamPREF ) ) )
       
  1061 					{
       
  1062 					MVPbkStoreContactField* contactField = iContact->CreateFieldLC( fieldType );
       
  1063 					if( contactField )
       
  1064 					    {
       
  1065 					    MVPbkContactFieldData& fieldData = contactField->FieldData();
       
  1066 					    if( fieldData.DataType() == EVPbkFieldStorageTypeText )
       
  1067 					    	{
       
  1068 					    	MVPbkContactFieldTextData& data = 
       
  1069 					    		MVPbkContactFieldTextData::Cast( fieldData );
       
  1070 					    	data.SetTextL( geoData );
       
  1071 					    	iContact->AddFieldL( contactField );
       
  1072 					    	}
       
  1073 					    CleanupStack::Pop( contactField );
       
  1074 					    }
       
  1075 					break;
       
  1076 					}
       
  1077 				}
       
  1078 			}	
       
  1079 		}
       
  1080 	CleanupStack::PopAndDestroy( &geoData );
       
  1081 	}
       
  1082 
       
  1083 // --------------------------------------------------------------------------
       
  1084 // CPmapCmd::UpdateFieldL
       
  1085 // --------------------------------------------------------------------------
       
  1086 //
       
  1087 void CPmapCmd::UpdateFieldL( 
       
  1088 		const CPosLandmark& aLandmark, 
       
  1089 		_TPositionFieldId aPositionField, 
       
  1090 		TVPbkSubFieldType aVersitSubField, 
       
  1091 		TVPbkFieldTypeParameter aAddressType )
       
  1092 	{
       
  1093 	TBool updated = EFalse;
       
  1094 	TPtrC textData;
       
  1095 	if ( aPositionField != EPositionFieldNone && aLandmark.IsPositionFieldAvailable( aPositionField ) )
       
  1096         {
       
  1097         aLandmark.GetPositionField( aPositionField, textData );
       
  1098         }
       
  1099 	
       
  1100 	if( iAddressView && iEditorControl )
       
  1101 		{
       
  1102 		TInt countControls = iEditorControl->NumberOfControls();
       
  1103 		for ( TInt i = 0; i < countControls; ++i )
       
  1104 			{
       
  1105 			TArray<TVPbkFieldVersitProperty> props = iEditorControl->EditorField( i ).FieldProperty().FieldType().VersitProperties();
       
  1106 			TInt countProperties = props.Count();
       
  1107 			for ( TInt ii = 0; ii < countProperties; ++ii )
       
  1108 				{
       
  1109 				if( props[ ii ].Name() == EVPbkVersitNameADR && props[ ii ].SubField() == aVersitSubField )
       
  1110 					{
       
  1111 					if ( aLandmark.IsPositionFieldAvailable( aPositionField ) )
       
  1112 						{
       
  1113 						iEditorControl->EditorField( i ).Control()->SetTextL( &textData );
       
  1114 						}
       
  1115 					else
       
  1116 						{
       
  1117 						iEditorControl->EditorField( i ).Control()->SetTextL( &KNullDesC() );
       
  1118 						}
       
  1119 						
       
  1120 					iEditorControl->EditorField( i ).SaveFieldL();
       
  1121 					updated = ETrue;
       
  1122 					continue;
       
  1123 					}
       
  1124 				}
       
  1125 			}
       
  1126 		}
       
  1127 	else 
       
  1128 		{
       
  1129 		MVPbkStoreContactFieldCollection& arrFields = iContact->Fields();
       
  1130 		TInt count = arrFields.FieldCount();
       
  1131 		for( TInt idx = 0; idx < count; idx++)
       
  1132 			{
       
  1133 			MVPbkStoreContactField& field = arrFields.FieldAt(idx);
       
  1134 			TArray<TVPbkFieldVersitProperty> arrProp = field.BestMatchingFieldType()->VersitProperties();
       
  1135 			for( TInt idx2 = 0; idx2 < arrProp.Count(); idx2++)
       
  1136 				{
       
  1137 				if( arrProp[idx2].Name() == EVPbkVersitNameADR && 
       
  1138 					arrProp[idx2].SubField() == aVersitSubField &&
       
  1139 					( arrProp[idx2].Parameters().Contains(aAddressType) ||
       
  1140 					  ( aAddressType == EVPbkVersitParamPREF && 
       
  1141 						!arrProp[idx2].Parameters().Contains(EVPbkVersitParamHOME) &&
       
  1142 						!arrProp[idx2].Parameters().Contains(EVPbkVersitParamWORK) ) ) )
       
  1143 					{
       
  1144 					MVPbkContactFieldData& fieldData = field.FieldData();
       
  1145 					if( fieldData.DataType() != EVPbkFieldStorageTypeText )
       
  1146 						{
       
  1147 						continue;
       
  1148 						}
       
  1149 					MVPbkContactFieldTextData& data = 
       
  1150 					   MVPbkContactFieldTextData::Cast( fieldData );
       
  1151 					if ( aLandmark.IsPositionFieldAvailable( aPositionField ) )
       
  1152 						{
       
  1153 						data.SetTextL( textData );
       
  1154 						}
       
  1155 					else
       
  1156 						{
       
  1157 						data.SetTextL( KNullDesC() );
       
  1158 						}
       
  1159 					
       
  1160 					updated = ETrue;
       
  1161 					continue;
       
  1162 					}
       
  1163 				}
       
  1164 			}
       
  1165 		}
       
  1166 	
       
  1167 	if( !updated && aLandmark.IsPositionFieldAvailable( aPositionField ) )
       
  1168 		{
       
  1169 		MVPbkContactStore& storeContact = iContact->ContactStore();
       
  1170 		const MVPbkContactStoreProperties& storeProp = storeContact.StoreProperties();
       
  1171 		const MVPbkFieldTypeList& fieldList = storeProp.SupportedFields();
       
  1172 		TInt count = fieldList.FieldTypeCount();
       
  1173 		for( TInt idx = 0; idx < count; idx++)
       
  1174 			{
       
  1175 			const MVPbkFieldType& fieldType = fieldList.FieldTypeAt( idx );
       
  1176 			TArray<TVPbkFieldVersitProperty> arrProp = fieldType.VersitProperties();
       
  1177 			for( TInt idx2 = 0; idx2 < arrProp.Count(); idx2++)
       
  1178 				{
       
  1179 				if( arrProp[idx2].Name() == EVPbkVersitNameADR && 
       
  1180 					arrProp[idx2].SubField() == aVersitSubField &&
       
  1181 					( arrProp[idx2].Parameters().Contains(aAddressType) ||
       
  1182 					  ( aAddressType == EVPbkVersitParamPREF && 
       
  1183 						!arrProp[idx2].Parameters().Contains(EVPbkVersitParamHOME) &&
       
  1184 						!arrProp[idx2].Parameters().Contains(EVPbkVersitParamWORK) ) ) )
       
  1185 					{
       
  1186 					MVPbkStoreContactField* contactField = iContact->CreateFieldLC( fieldType );
       
  1187 					if( contactField )
       
  1188 						{
       
  1189 						MVPbkContactFieldData& fieldData = contactField->FieldData();
       
  1190 						if( fieldData.DataType() == EVPbkFieldStorageTypeText )
       
  1191 							{
       
  1192 							MVPbkContactFieldTextData& data = 
       
  1193 							   MVPbkContactFieldTextData::Cast( fieldData );
       
  1194 							data.SetTextL(textData);
       
  1195 							iContact->AddFieldL( contactField );
       
  1196 							}
       
  1197 						CleanupStack::Pop(contactField);
       
  1198 						}
       
  1199 					break;
       
  1200 					}
       
  1201 				}
       
  1202 			}	
       
  1203 		}
       
  1204 	}
       
  1205 
       
  1206 // --------------------------------------------------------------------------
       
  1207 // CPmapCmd::IsAddressInContact
       
  1208 // --------------------------------------------------------------------------
       
  1209 //
       
  1210 TBool CPmapCmd::IsAddressInContact()
       
  1211 	{
       
  1212 	MVPbkStoreContactFieldCollection& arrFields = iContact->Fields();
       
  1213 	TInt count = arrFields.FieldCount();
       
  1214 	for( TInt idx = 0; idx < count; idx++)
       
  1215 		{
       
  1216 		MVPbkStoreContactField& field = arrFields.FieldAt(idx);
       
  1217 		TArray<TVPbkFieldVersitProperty> arrProp = field.BestMatchingFieldType()->VersitProperties();
       
  1218 		for( TInt idx2 = 0; idx2 < arrProp.Count(); idx2++)
       
  1219 			{
       
  1220 			if( arrProp[idx2].Name() == EVPbkVersitNameADR  )
       
  1221 				{
       
  1222 				return ETrue;
       
  1223 				}
       
  1224 			}
       
  1225 		}
       
  1226 	return EFalse;
       
  1227     }
       
  1228 
       
  1229 // --------------------------------------------------------------------------
       
  1230 // CPmapCmd::GetFieldGroupL
       
  1231 // --------------------------------------------------------------------------
       
  1232 //
       
  1233 TPbk2FieldGroupId CPmapCmd::GetFieldGroupL(
       
  1234 		MVPbkStoreContactField& aField )
       
  1235 	{
       
  1236 	TPbk2FieldGroupId ret = EPbk2FieldGroupIdNone;
       
  1237 
       
  1238 	const MVPbkFieldType* type = aField.BestMatchingFieldType();
       
  1239 	if( type )
       
  1240 	    {
       
  1241 	    TArray<TVPbkFieldVersitProperty> arrProp = type->VersitProperties();
       
  1242 	    for( TInt idx = 0; idx < arrProp.Count(); idx++)
       
  1243 			{
       
  1244 			if( arrProp[idx].Name() != EVPbkVersitNameADR )
       
  1245 				{
       
  1246 				continue;
       
  1247 				}
       
  1248 					
       
  1249 			if( arrProp[idx].Parameters().Contains( 
       
  1250 				    Pbk2AddressTools::MapAddressToVersitParam(
       
  1251 				    		EPbk2FieldGroupIdHomeAddress ) ) )
       
  1252 				{
       
  1253 				ret = EPbk2FieldGroupIdHomeAddress;
       
  1254 				break;
       
  1255 				}
       
  1256 			else if( arrProp[idx].Parameters().Contains( 
       
  1257 				    Pbk2AddressTools::MapAddressToVersitParam(
       
  1258 				    		EPbk2FieldGroupIdCompanyAddress ) ) )
       
  1259 				{
       
  1260 				ret = EPbk2FieldGroupIdCompanyAddress;
       
  1261 				break;
       
  1262 				}
       
  1263 			else
       
  1264 				{
       
  1265 				ret = EPbk2FieldGroupIdPostalAddress;
       
  1266 				break;
       
  1267 				}
       
  1268 			}
       
  1269 	    }
       
  1270 
       
  1271 	return ret;
       
  1272     }
       
  1273 
       
  1274 // --------------------------------------------------------------------------
       
  1275 // CPmapCmd::ContactOperationCompleted
       
  1276 // --------------------------------------------------------------------------
       
  1277 //
       
  1278 void CPmapCmd::ContactOperationCompleted
       
  1279         (TContactOpResult aResult)
       
  1280     {
       
  1281     if (aResult.iStoreContact)
       
  1282         {
       
  1283         iContact = aResult.iStoreContact;
       
  1284         }
       
  1285     
       
  1286    	CActiveScheduler::Stop();
       
  1287     }
       
  1288 
       
  1289 // --------------------------------------------------------------------------
       
  1290 // CPmapCmd::ContactOperationFailed
       
  1291 // --------------------------------------------------------------------------
       
  1292 //
       
  1293 void CPmapCmd::ContactOperationFailed
       
  1294         (TContactOp /*aOpCode*/, TInt /*aErrorCode*/, TBool /*aErrorNotified*/)
       
  1295     {
       
  1296    	CActiveScheduler::Stop();
       
  1297     }
       
  1298 
       
  1299 // End of File