phonebookui/Phonebook2/UIControls/src/CPbk2ContactEditorDlgImpl.cpp
changeset 0 e686773b3f54
child 3 04ab22b956c2
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:  Phonebook 2 contact editor dialog implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "CPbk2ContactEditorDlgImpl.h"
       
    21 
       
    22 // Phonebook 2
       
    23 #include "Pbk2UIControls.hrh"
       
    24 #include "MPbk2ContactEditorStrategy.h"
       
    25 #include "CPbk2ContactEditorFieldArray.h"
       
    26 #include "MPbk2ContactEditorField.h"
       
    27 #include <MPbk2ContactEditorField2.h>
       
    28 #include "CPbk2AddItemManager.h"
       
    29 #include "Pbk2TitlePanePictureFactory.h"
       
    30 #include "TPbk2DeleteItemManager.h"
       
    31 #include <MPbk2StoreObservationRegister.h>
       
    32 #include <MPbk2ApplicationServices.h>
       
    33 #include <CPbk2PresentationContact.h>
       
    34 #include <CPbk2PresentationContactField.h>
       
    35 #include <CPbk2PresentationContactFieldCollection.h>
       
    36 #include <MPbk2FieldProperty.h>
       
    37 #include <MPbk2FieldProperty2.h>
       
    38 #include <CPbk2FieldPropertyArray.h>
       
    39 #include <Pbk2UIControls.rsg>
       
    40 #include <MPbk2ContactNameFormatter.h>
       
    41 #include <MPbk2ContactEditorExtension.h>
       
    42 #include <CPbk2StoreConfiguration.h>
       
    43 #include <CPbk2ContactRelocator.h>
       
    44 #include <MPbk2ContactEditorEventObserver.h>
       
    45 #include <MPbk2EditedContactObserver.h>
       
    46 #include <CPbk2UIExtensionManager.h>
       
    47 #include <MPbk2UIExtensionFactory.h>
       
    48 #include <MPbk2ContactEditorContactRelocator.h>
       
    49 #include <CPbk2AppUiBase.h>
       
    50 #include <CPbk2StorePropertyArray.h>
       
    51 #include <CPbk2StoreProperty.h>
       
    52 #include <MPbk2ExitCallback.h>
       
    53 #include <CPbk2IconInfoContainer.h>
       
    54 #include <CPbk2IconFactory.h>
       
    55 #include "Pbk2RingtoneCommands.h" 
       
    56 #include "Pbk2ImageCommands.h"
       
    57 #include "CPbk2ContactEditorUIAddressField.h"
       
    58 #include "MPbk2ContactEditorUIField.h"
       
    59 #include "Pbk2ContactEditorFieldFactory.h"
       
    60 #include "Pbk2AddressTools.h"
       
    61 #include "MPbk2UIField.h"
       
    62 #include "CPbk2ContactEditorRingtoneField.h"
       
    63 #include "CPbk2ContactEditorImageField.h"
       
    64 #include "CPbk2ContactEditorReadonlyField.h" 
       
    65 #include "Pbk2EditorLineIds.hrh" 
       
    66 #include <Pbk2Config.hrh>
       
    67 #include <Pbk2Commands.hrh>
       
    68 #include "Pbk2FieldProperty.hrh"
       
    69 #include "Pbk2IconId.hrh"
       
    70 #include <Pbk2UID.h>
       
    71 #include <pbk2mapcommands.hrh>
       
    72 
       
    73 // Virtual Phonebook
       
    74 #include <CVPbkContactManager.h>
       
    75 #include <MVPbkStoreContact.h>
       
    76 #include <MVPbkContactStore.h>
       
    77 #include <MVPbkContactFieldTextData.h>
       
    78 #include <MVPbkContactStoreProperties.h>
       
    79 #include <MVPbkContactFieldData.h>
       
    80 #include <MVPbkFieldType.h>
       
    81 #include <TVPbkFieldVersitProperty.h>
       
    82 #include <ccappmycardpluginrsc.rsg>
       
    83 
       
    84 #include <VPbkEng.rsg> 
       
    85 #include <VPbkFieldType.hrh>
       
    86 #include <VPbkContactStoreUris.h>
       
    87 
       
    88 // System includes
       
    89 #include <akntitle.h>
       
    90 #include <aknnavi.h>
       
    91 #include <StringLoader.h>
       
    92 #include <eikcapc.h>
       
    93 #include <barsread.h>
       
    94 #include <aknnotewrappers.h>
       
    95 #include <hlplch.h>
       
    96 #include <aknnavide.h>
       
    97 #include <akninputblock.h>
       
    98 #include <coemain.h>
       
    99 
       
   100 _LIT( KCCAppMyCardPluginResFileName, "\\resource\\ccappmycardpluginrsc.rsc");
       
   101 
       
   102 /// Unnamed namespace for local definitions
       
   103 namespace {
       
   104 
       
   105 const TInt KEditorNameFormatFlags = MPbk2ContactNameFormatter::EUseSeparator;
       
   106 
       
   107 #ifdef _DEBUG
       
   108 enum TPanicCode
       
   109     {
       
   110     EHandleControlStateChangeL_NullField = 1,
       
   111     EPanic_IsControlEmptyL_OOB,
       
   112     EPanic_EditorField_OOB
       
   113     };
       
   114 
       
   115 void Panic(TInt aReason)
       
   116     {
       
   117     _LIT(KPanicText, "CPbk2ContactEditorDlgImpl");
       
   118     User::Panic(KPanicText, aReason);
       
   119     }
       
   120 #endif // _DEBUG
       
   121 
       
   122 /**
       
   123  * Displays a store not available note.
       
   124  *
       
   125  * @param aName     Store name.
       
   126  */
       
   127 void ShowStoreNotAvailableNoteL( const TDesC& aName )
       
   128     {
       
   129     if ( aName.Length() > 0 )
       
   130         {
       
   131         HBufC* text = StringLoader::LoadLC( R_QTN_PHOB_STORE_NOT_AVAILABLE,
       
   132             aName );
       
   133         CAknInformationNote* note = new ( ELeave ) CAknInformationNote;
       
   134         note->ExecuteLD( *text );
       
   135         CleanupStack::PopAndDestroy( text );
       
   136         }
       
   137     }
       
   138 
       
   139 /**
       
   140  * Decides whether to leave or not in case of an error.
       
   141  * Performs some filtering of errors.
       
   142  *
       
   143  * @param aError    Error code.
       
   144  */
       
   145 void DecideToLeaveL( TInt aError )
       
   146     {
       
   147     if ( aError != KErrInUse && aError != KErrNone )
       
   148         {
       
   149         User::Leave( aError );
       
   150         }
       
   151     }
       
   152 
       
   153 } /// namespace
       
   154 
       
   155 
       
   156 // --------------------------------------------------------------------------
       
   157 // CPbk2ContactEditorDlgImpl::CPbk2ContactEditorDlgImpl
       
   158 // --------------------------------------------------------------------------
       
   159 //
       
   160 CPbk2ContactEditorDlgImpl::CPbk2ContactEditorDlgImpl
       
   161     ( TPbk2ContactEditorParams& aParams,
       
   162       CPbk2PresentationContact& aContact,
       
   163       CPbk2FieldPropertyArray& aFieldProperties,
       
   164       MPbk2EditedContactObserver& aContactObserver,
       
   165       MPbk2ContactEditorStrategy& aEditorStrategy,
       
   166       MPbk2ContactEditorContactRelocator& aRelocator,
       
   167       MPbk2ApplicationServices* aAppServices,
       
   168       HBufC* aTitleText ) :
       
   169         iParams( aParams ),
       
   170         iEditorStrategy( aEditorStrategy ),
       
   171         iFieldProperties( aFieldProperties ),
       
   172         iContact( aContact ),
       
   173         iContactObserver( aContactObserver ),
       
   174         iRelocator( aRelocator ),
       
   175         iEndKeyWasPressed( EFalse ),
       
   176         iAddressViewStandalone( EFalse ),
       
   177         iAppServices( aAppServices ),
       
   178         iTitleText( aTitleText ),
       
   179         iPbk2UiResource( *CCoeEnv::Static() )        
       
   180     {
       
   181     // Exit is approved by default
       
   182     iExitRecord.Set( EExitApproved );
       
   183     }
       
   184 
       
   185 // --------------------------------------------------------------------------
       
   186 // CPbk2ContactEditorDlgImpl::~CPbk2ContactEditorDlgImpl
       
   187 // --------------------------------------------------------------------------
       
   188 //
       
   189 CPbk2ContactEditorDlgImpl::~CPbk2ContactEditorDlgImpl()
       
   190     {
       
   191     if ( iWaitFinish && iWaitFinish->IsStarted() )
       
   192         {
       
   193         iWaitFinish->AsyncStop();
       
   194         }
       
   195     delete iWaitFinish;
       
   196     delete iInputBlock;
       
   197     
       
   198     if ( iSelfPtr )
       
   199         {
       
   200         *iSelfPtr = NULL;
       
   201         }
       
   202     
       
   203     if( iAppServices )
       
   204     	{
       
   205     	iAppServices->StoreObservationRegister().DeregisterStoreEvents( *this );
       
   206     	}
       
   207     else
       
   208     	{
       
   209     	Phonebook2::Pbk2AppUi()->ApplicationServices().
       
   210     	        StoreObservationRegister().DeregisterStoreEvents( *this );
       
   211     	}
       
   212               
       
   213     if ( iEikonEnv && iContextMenuBar )
       
   214         {
       
   215         iEikonEnv->EikAppUi()->RemoveFromStack( iContextMenuBar );
       
   216         delete iContextMenuBar;
       
   217         }
       
   218 
       
   219     // Restore the titlepane text
       
   220     if (iTitlePane && iStoredTitlePaneText)
       
   221         {
       
   222         // iTitlePane takes ownership of iStoredTitlePaneText
       
   223         iTitlePane->SetText(iStoredTitlePaneText);
       
   224         }
       
   225 
       
   226     // Reset title pane picture
       
   227     if( iTitlePane )
       
   228         {
       
   229         iTitlePane->SetSmallPicture( NULL, NULL, EFalse );
       
   230         }
       
   231 
       
   232     // Remove empty status pane
       
   233     if (iNaviContainer)
       
   234         {
       
   235         iNaviContainer->Pop();
       
   236         }
       
   237 
       
   238     delete iStoreContact;
       
   239     delete iFieldFactory;
       
   240     delete iPbk2BaseCommand;
       
   241     delete iEditorExtension;
       
   242     delete iUiFieldArray;
       
   243     Release(iExtensionManager);
       
   244         
       
   245     if( iCommandId == EEikCmdExit || iCommandId == EAknCmdExit )
       
   246 		{	
       
   247 		CAknAppUi* appUi = static_cast<CAknAppUi*>( CCoeEnv::Static()->AppUi() );      		
       
   248 			
       
   249 		if( appUi )
       
   250 			{
       
   251 			TFileName file;
       
   252 			file.Copy( KCCAppMyCardPluginResFileName );
       
   253 			iPbk2UiResource.OpenL( file );
       
   254 		
       
   255 			HBufC* title = StringLoader::LoadLC( R_QTN_MYCARD_EDITOR_TITLE );	
       
   256 			
       
   257 			iPbk2UiResource.Close();			
       
   258 			TBool okToExit = EFalse;
       
   259 			
       
   260 			if( iTitleText && iTitleText->CompareC( title->Des() ) == 0 )
       
   261 				{
       
   262 				okToExit = ETrue;
       
   263 				}
       
   264 			
       
   265 			CleanupStack::PopAndDestroy(); // title
       
   266 								
       
   267 			if ( okToExit )
       
   268 				{
       
   269 				appUi->ProcessCommandL( EAknCmdExit );
       
   270 				}								
       
   271 			}
       
   272 		}    
       
   273     
       
   274 	delete iTitleText;    
       
   275     }
       
   276 
       
   277 // --------------------------------------------------------------------------
       
   278 // CPbk2ContactEditorDlgImpl::NewL
       
   279 // --------------------------------------------------------------------------
       
   280 //
       
   281 CPbk2ContactEditorDlgImpl* CPbk2ContactEditorDlgImpl::NewL(
       
   282         TPbk2ContactEditorParams& aParams,
       
   283         CPbk2PresentationContact& aContact,
       
   284         CPbk2FieldPropertyArray& aFieldProperties,
       
   285         MPbk2EditedContactObserver& aContactObserver,
       
   286         MPbk2ContactEditorStrategy& aEditorStrategy,
       
   287         MPbk2ContactEditorContactRelocator& aRelocator)
       
   288     {	
       
   289     CPbk2ContactEditorDlgImpl* self =
       
   290         new ( ELeave ) CPbk2ContactEditorDlgImpl(aParams, aContact,
       
   291             aFieldProperties, aContactObserver,
       
   292             aEditorStrategy, aRelocator);
       
   293     CleanupStack::PushL(self);
       
   294     self->ConstructL();
       
   295     CleanupStack::Pop(self);
       
   296     return self;
       
   297     }
       
   298 
       
   299 // --------------------------------------------------------------------------
       
   300 // CPbk2ContactEditorDlgImpl::NewL
       
   301 // --------------------------------------------------------------------------
       
   302 //
       
   303 CPbk2ContactEditorDlgImpl* CPbk2ContactEditorDlgImpl::NewL(
       
   304 		TPbk2ContactEditorParams& aParams,
       
   305 		CPbk2PresentationContact& aContact,
       
   306 		CPbk2FieldPropertyArray& aFieldProperties,
       
   307 		MPbk2EditedContactObserver& aContactObserver,
       
   308 		MPbk2ContactEditorStrategy& aEditorStrategy,
       
   309 		MPbk2ContactEditorContactRelocator& aRelocator,
       
   310 		MPbk2ApplicationServices* aAppServices,
       
   311 		HBufC* aTitleText )
       
   312 	{
       
   313 	CPbk2ContactEditorDlgImpl* self =
       
   314 		new ( ELeave ) CPbk2ContactEditorDlgImpl(aParams, aContact,
       
   315 			aFieldProperties, aContactObserver,
       
   316 			aEditorStrategy, aRelocator, aAppServices, aTitleText );
       
   317 	CleanupStack::PushL(self);
       
   318 	self->ConstructL();
       
   319 	CleanupStack::Pop(self);
       
   320 	return self;
       
   321 	}
       
   322 
       
   323 // --------------------------------------------------------------------------
       
   324 // CPbk2ContactEditorDlgImpl::ConstructL
       
   325 // --------------------------------------------------------------------------
       
   326 //
       
   327 void CPbk2ContactEditorDlgImpl::ConstructL()
       
   328     {
       
   329     CAknDialog::ConstructL(R_PBK2_CONTACTEDITOR_MENUBAR);
       
   330     
       
   331     if(iParams.iActiveView != TPbk2ContactEditorParams::EEditorView)
       
   332         {
       
   333         iParams.iFocusedContactField = NULL;
       
   334         }
       
   335     if(iParams.iFocusedContactField)
       
   336         {
       
   337         const MVPbkFieldType* type = iParams.iFocusedContactField->BestMatchingFieldType();
       
   338         const TArray<TVPbkFieldVersitProperty> propArr = type->VersitProperties();
       
   339         if(propArr.Count())
       
   340             {
       
   341             const TVPbkFieldVersitProperty prop = propArr[0];
       
   342             if(prop.Name() == EVPbkVersitNameADR)
       
   343                 {
       
   344                 if(prop.Parameters().Contains(EVPbkVersitParamHOME))
       
   345                     {
       
   346                     iParams.iActiveView = TPbk2ContactEditorParams::EEditorAddressHomeView;
       
   347                     }
       
   348                 else if(prop.Parameters().Contains(EVPbkVersitParamWORK))
       
   349                     {
       
   350                     iParams.iActiveView = TPbk2ContactEditorParams::EEditorAddressOfficeView;
       
   351                     }
       
   352                 else
       
   353                     {
       
   354                     iParams.iActiveView = TPbk2ContactEditorParams::EEditorAddressView;
       
   355                     }
       
   356                 iAddressViewStandalone = ETrue;
       
   357                 iParams.iFocusedContactField = NULL;
       
   358                 }
       
   359             }
       
   360         }
       
   361     
       
   362     // Register to listen store events, so that we can close editor if
       
   363     // iContact's store becomes unavailable.
       
   364     
       
   365     /*
       
   366 	 * Use iAppServices if provided. This is to enable editor use outside from pbk2 context
       
   367 	 */
       
   368     if( iAppServices )
       
   369     	{
       
   370     	iAppServices->StoreObservationRegister().RegisterStoreEventsL( *this );
       
   371     	iNameFormatter = &iAppServices->NameFormatter();
       
   372     	}
       
   373     else
       
   374     	{
       
   375     	Phonebook2::Pbk2AppUi()->ApplicationServices().
       
   376 			StoreObservationRegister().RegisterStoreEventsL( *this );
       
   377     	iNameFormatter =
       
   378     	        &Phonebook2::Pbk2AppUi()->ApplicationServices().NameFormatter();
       
   379     	}
       
   380 
       
   381    
       
   382     StoreTitlePaneTextL();
       
   383     ConstructContextMenuL();
       
   384     ConstructNaviPaneL();
       
   385 
       
   386     iExtensionManager = CPbk2UIExtensionManager::InstanceL();
       
   387     
       
   388     /*
       
   389 	 * Use iAppServices if provided. This is to enable editor use outside from pbk2 context
       
   390 	 */
       
   391     CVPbkContactManager* manager = NULL;
       
   392     if( iAppServices )
       
   393     	{
       
   394     	manager = &iAppServices->ContactManager();
       
   395     	}
       
   396     else
       
   397     	{
       
   398     	manager = &Phonebook2::Pbk2AppUi()->ApplicationServices().ContactManager();
       
   399     	}
       
   400     
       
   401     iEditorExtension = iExtensionManager->FactoryL()->
       
   402         CreatePbk2ContactEditorExtensionL( *manager, iContact, *this );
       
   403 
       
   404     iFieldFactory = CPbk2ContactEditorFieldFactory::NewL(*this, *iEditorExtension);
       
   405     iUiFieldArray = CPbk2ContactEditorFieldArray::NewL(
       
   406     *manager, iContact, *this, *iFieldFactory, iAppServices );	
       
   407     
       
   408     iUseState = EUseReady;
       
   409     }
       
   410 
       
   411 // --------------------------------------------------------------------------
       
   412 // CPbk2ContactEditorDlgImpl::ExecuteLD
       
   413 // --------------------------------------------------------------------------
       
   414 //
       
   415 void CPbk2ContactEditorDlgImpl::ExecuteLD()
       
   416     {
       
   417     CleanupStack::PushL( this );
       
   418 
       
   419     // Set status pane layout to the Phonebook 2 one
       
   420     CEikStatusPane* statusPane = iAvkonAppUi->StatusPane();
       
   421     if (statusPane)
       
   422         {
       
   423         statusPane->SwitchLayoutL(R_AVKON_STATUS_PANE_LAYOUT_USUAL);
       
   424         }
       
   425 
       
   426     CleanupStack::Pop( this );
       
   427     CAknForm::ExecuteLD(R_PBK2_EDIT_MEMORY_ENTRY_DIALOG);
       
   428     }
       
   429 
       
   430 // --------------------------------------------------------------------------
       
   431 // CPbk2ContactEditorDlgImpl::CreateCustomControlL
       
   432 // --------------------------------------------------------------------------
       
   433 //
       
   434 SEikControlInfo CPbk2ContactEditorDlgImpl::CreateCustomControlL(
       
   435     TInt /*aControlType*/ )
       
   436     {
       
   437     iLastCreatedCustomControl = NULL;
       
   438     SEikControlInfo control = {NULL, 0, 0};
       
   439     iLastCreatedCustomControl = new (ELeave) CPbk2ContactEditorReadonlyField();  
       
   440     control.iControl = iLastCreatedCustomControl; 
       
   441     control.iTrailerTextId = 0;
       
   442     control.iFlags = 0;
       
   443     return control;
       
   444     }
       
   445 
       
   446 // --------------------------------------------------------------------------
       
   447 // CPbk2ContactEditorDlgImpl::ContactEditorUiBuilderExtension
       
   448 // --------------------------------------------------------------------------
       
   449 //
       
   450 TAny* CPbk2ContactEditorDlgImpl::ContactEditorUiBuilderExtension( 
       
   451     TUid /*aExtensionUid*/ )
       
   452     {
       
   453     //return extension point of MPbk2ContactEditorUiBuilderExtension
       
   454     return static_cast<MPbk2ContactEditorUiBuilderExtension*>(this);
       
   455     }
       
   456 
       
   457 // --------------------------------------------------------------------------
       
   458 // CPbk2ContactEditorDlgImpl::AddCustomFieldToFormL
       
   459 // --------------------------------------------------------------------------
       
   460 //   
       
   461 CCoeControl* CPbk2ContactEditorDlgImpl::AddCustomFieldToFormL(
       
   462     TInt aIndex,TInt aResourceId)
       
   463     {
       
   464     InsertLineL(aIndex, aResourceId);
       
   465     // Return value is updated in CreateCustomControlL()
       
   466     return iLastCreatedCustomControl;
       
   467     }
       
   468 
       
   469 // --------------------------------------------------------------------------
       
   470 // CPbk2ContactEditorDlgImpl::HandleCustomFieldCommandL
       
   471 // --------------------------------------------------------------------------
       
   472 //   
       
   473 TBool CPbk2ContactEditorDlgImpl::HandleCustomFieldCommandL(TInt aCommand )
       
   474     {
       
   475     ProcessCommandL( aCommand );
       
   476     return ETrue;
       
   477     }
       
   478 
       
   479 // -----------------------------------------------------------------------------
       
   480 // CPbk2ContactEditorDlgImpl::ConvertCustomControlTypeToBaseControlType()
       
   481 // Provide correct base type for custom contols
       
   482 // -----------------------------------------------------------------------------
       
   483 //
       
   484 MEikDialogPageObserver::TFormControlTypes CPbk2ContactEditorDlgImpl::
       
   485     ConvertCustomControlTypeToBaseControlType(TInt aControlType) const
       
   486     {
       
   487     MEikDialogPageObserver::TFormControlTypes ret = 
       
   488         MEikDialogPageObserver::EUnknownType;
       
   489     
       
   490     switch(aControlType)
       
   491         {
       
   492         case EPbk2FieldCtrlTypeImageEditor:
       
   493         case EPbk2FieldCtrlTypeRingtoneEditor:
       
   494         case EPbk2FieldCtrlTypeExtAddressEditor:
       
   495         case EPbk2FieldCtrlTypeExtAddressHomeEditor:
       
   496         case EPbk2FieldCtrlTypeExtAddressOfficeEditor:
       
   497         case EPbk2FieldCtrlTypeExtAssignFromMapsEditor:
       
   498         {
       
   499             ret = MEikDialogPageObserver::EEdwinDerived;
       
   500             }
       
   501             break;
       
   502         default:
       
   503             {
       
   504             ret = MEikDialogPageObserver::EUnknownType;
       
   505             }
       
   506             break;
       
   507         }
       
   508     return ret;
       
   509     }
       
   510 
       
   511 // --------------------------------------------------------------------------
       
   512 // CPbk2ContactEditorDlgImpl::HandlePointerEventL
       
   513 // --------------------------------------------------------------------------
       
   514 //
       
   515 void CPbk2ContactEditorDlgImpl::HandlePointerEventL( 
       
   516     const TPointerEvent& aPointerEvent )
       
   517     {
       
   518     //Here we can prevent recursive execution of ExecuteBaseCommandL if needed 
       
   519     //as touch events are handled in it too. So it may case multiple callbacks to here if 
       
   520     //user repeats the same pointer event very quickly using options menu.
       
   521     // if(!iCommandPending) //seems that this check is not needed
       
   522         {
       
   523         CAknForm::HandlePointerEventL( aPointerEvent );
       
   524         }
       
   525     }
       
   526 
       
   527 // --------------------------------------------------------------------------
       
   528 // CPbk2ContactEditorDlgImpl::HandleResourceChange
       
   529 // --------------------------------------------------------------------------
       
   530 //
       
   531 void CPbk2ContactEditorDlgImpl::HandleResourceChange( TInt aType )
       
   532     {
       
   533     // Handle change in layout orientation
       
   534     if ( aType == KEikDynamicLayoutVariantSwitch )
       
   535         {
       
   536         // Set status pane layout to the Phonebook 2 one
       
   537         CEikStatusPane* statusPane = iAvkonAppUi->StatusPane();
       
   538         if ( statusPane )
       
   539             {
       
   540             TRAP_IGNORE(
       
   541                     statusPane->SwitchLayoutL(
       
   542                             R_AVKON_STATUS_PANE_LAYOUT_USUAL
       
   543                             )
       
   544             );
       
   545             }
       
   546         }
       
   547     
       
   548     CAknForm::HandleResourceChange( aType );
       
   549     }
       
   550 
       
   551 // --------------------------------------------------------------------------
       
   552 // CPbk2ContactEditorDlgImpl::AddItemToContactL
       
   553 // --------------------------------------------------------------------------
       
   554 //
       
   555 void CPbk2ContactEditorDlgImpl::AddItemToContactL
       
   556       ( TInt aFieldTypeResourceId,
       
   557         const TDesC& aFieldTypeXspName, 
       
   558         TBool aSetFocus )
       
   559     {
       
   560     // Store the original parameter value, since it is
       
   561     // changed by AddFieldsL
       
   562     TInt origParam = aFieldTypeResourceId;
       
   563     TPtrC xSpName = aFieldTypeXspName;
       
   564 
       
   565     CPbk2AddItemManager* addItemManager = CPbk2AddItemManager::NewL
       
   566             (iContact, *iUiFieldArray, iParams, iAppServices );
       
   567     CleanupStack::PushL(addItemManager);
       
   568     CPbk2AddItemManager::TReturnValue ret = addItemManager->AddFieldsL(
       
   569             aFieldTypeResourceId, xSpName);
       
   570 
       
   571     if (ret.iControlId == KErrAlreadyExists)
       
   572         {
       
   573         // cannot add more than one of this field type
       
   574         // find and focus that
       
   575         TInt fieldArrayCount( iUiFieldArray->Count() );
       
   576         for (TInt i(0); i < fieldArrayCount && ret.iControlId
       
   577                 == KErrAlreadyExists; ++i)
       
   578             {
       
   579             if (!iUiFieldArray->At(i).ContactEditorField())
       
   580                 {
       
   581                 continue;
       
   582                 }
       
   583             const MVPbkFieldType* fieldType =
       
   584                 iUiFieldArray->At(i).ContactEditorField()->ContactField().
       
   585                     BestMatchingFieldType();
       
   586             if(fieldType && fieldType->FieldTypeResId() == aFieldTypeResourceId)
       
   587                 {
       
   588                 ret.iControlId = iUiFieldArray->At(i).ControlId();
       
   589                 }
       
   590             }
       
   591         }
       
   592 
       
   593     if (ret.iControlId > 0)
       
   594         {
       
   595         if (aSetFocus)
       
   596             {
       
   597             TryChangeFocusL(ret.iControlId);
       
   598             MPbk2ContactEditorField* editorField = iUiFieldArray->Find( ret.iControlId )->ContactEditorField();
       
   599             MVPbkStoreContactField& storeContactField = editorField->ContactField();
       
   600             iParams.iFocusedContactField = &storeContactField;
       
   601             // Call this after adding or deleting lines
       
   602             UpdatePageL( ETrue );
       
   603             // Must be DrawNow and not DrawDeferred otherwise field label
       
   604             // and content of the following field will be incorrect
       
   605             DrawNow();
       
   606             }
       
   607         }
       
   608     else if (ret.iControlId == KErrNotSupported && origParam == KErrNotFound)
       
   609         {
       
   610         iUiFieldArray->SaveFieldsL();
       
   611         iRelocator.RelocateContactL(aFieldTypeResourceId, xSpName,
       
   612             Pbk2ContactRelocator::EPbk2DisplayStoreDoesNotSupportQuery);
       
   613         }
       
   614     else if ( iParams.iActiveView == TPbk2ContactEditorParams::EEditorView )
       
   615         {
       
   616         switch( ret.iGruopId )
       
   617             {
       
   618             case EPbk2FieldGroupIdPostalAddress:
       
   619                 if(iUiFieldArray->Count())
       
   620                     {
       
   621                     iUiFieldArray->AddNewFieldL( ret.iGruopId );
       
   622                     ExecuteAddressDlgL( TPbk2ContactEditorParams::EEditorAddressView );
       
   623                     }
       
   624                 break;
       
   625             case EPbk2FieldGroupIdHomeAddress:
       
   626                 iUiFieldArray->AddNewFieldL( ret.iGruopId );
       
   627                 ExecuteAddressDlgL( TPbk2ContactEditorParams::EEditorAddressHomeView );
       
   628                 break;
       
   629             case EPbk2FieldGroupIdCompanyAddress:
       
   630                 iUiFieldArray->AddNewFieldL( ret.iGruopId );
       
   631                 ExecuteAddressDlgL( TPbk2ContactEditorParams::EEditorAddressOfficeView );
       
   632                 break;
       
   633             }
       
   634         }
       
   635     CleanupStack::PopAndDestroy(addItemManager);
       
   636     }
       
   637 
       
   638 // --------------------------------------------------------------------------
       
   639 // CPbk2ContactEditorDlgImpl::CloseWithoutSaving
       
   640 // --------------------------------------------------------------------------
       
   641 //
       
   642 void CPbk2ContactEditorDlgImpl::CloseWithoutSaving( TBool aInformObserver )
       
   643     {
       
   644     CloseDialog( 
       
   645         MVPbkContactObserver::EContactOperationUnknown, 
       
   646         aInformObserver );
       
   647     }
       
   648 
       
   649 // --------------------------------------------------------------------------
       
   650 // CPbk2ContactEditorDlgImpl::TryChangeFocusWithTypeIdL
       
   651 // --------------------------------------------------------------------------
       
   652 //
       
   653 void CPbk2ContactEditorDlgImpl::TryChangeFocusWithTypeIdL
       
   654         ( TInt aFieldTypeResId, const TDesC& aFieldTypeXSpName )
       
   655     {
       
   656     const TInt count( iUiFieldArray->Count() );
       
   657     for ( TInt i = 0; i < count; ++i )
       
   658         {
       
   659         if (!iUiFieldArray->At(i).ContactEditorField())
       
   660             {
       
   661             continue;
       
   662             }
       
   663         MPbk2ContactEditorField& uiEditorField =
       
   664                 *(iUiFieldArray->At(i).ContactEditorField());
       
   665         const MVPbkFieldType* fieldType =
       
   666             uiEditorField.ContactField().BestMatchingFieldType();
       
   667         TInt candidate( KErrNotFound );
       
   668         if ( fieldType )
       
   669             {
       
   670             candidate = fieldType->FieldTypeResId();
       
   671             }
       
   672 
       
   673         MPbk2FieldProperty2* fieldPropertyExtension =
       
   674             reinterpret_cast<MPbk2FieldProperty2*>(
       
   675                 const_cast<MPbk2FieldProperty&>( uiEditorField.FieldProperty() ).
       
   676                     FieldPropertyExtension(
       
   677                         KMPbk2FieldPropertyExtension2Uid ) );
       
   678         
       
   679         if ( fieldPropertyExtension != NULL ) 
       
   680             {
       
   681             if ( (aFieldTypeResId == candidate ) &&
       
   682                     !fieldPropertyExtension->XSpName().CompareF(
       
   683                         aFieldTypeXSpName) )
       
   684                 {
       
   685                 TryChangeFocusL( uiEditorField.ControlId() );
       
   686                 MVPbkStoreContactField& storeContactField = uiEditorField.ContactField();
       
   687                 iParams.iFocusedContactField = &storeContactField;
       
   688                 // Must be DrawNow and not DrawDeferred otherwise field label
       
   689                 // and content of the following field will be incorrect
       
   690                 DrawNow();
       
   691                 break;
       
   692                 }
       
   693             }
       
   694         }
       
   695     }
       
   696 
       
   697 // --------------------------------------------------------------------------
       
   698 // CPbk2ContactEditorDlgImpl::OfferKeyEventL
       
   699 // --------------------------------------------------------------------------
       
   700 //
       
   701 TKeyResponse CPbk2ContactEditorDlgImpl::OfferKeyEventL
       
   702         ( const TKeyEvent& aKeyEvent, TEventCode aType )
       
   703     {
       
   704      TKeyResponse ret(EKeyWasNotConsumed);    
       
   705 
       
   706      if(iAddressView)
       
   707          {
       
   708          return ret;
       
   709          }
       
   710      
       
   711      /* Uncomment this code if it is necessary to enable navigation hardware keys
       
   712       * on devices which have these keys (its Map Extension feature) 
       
   713      if( aKeyEvent.iScanCode == EStdKeyApplicationD && aType == EEventKeyUp )
       
   714          {
       
   715          HandleCustomFieldCommandL(EPbk2ExtensionAssignFromMap);
       
   716          return EKeyWasConsumed;
       
   717          }
       
   718              
       
   719      if( aKeyEvent.iScanCode == EStdKeyApplicationE && aType == EEventKeyUp )
       
   720          {
       
   721          HandleCustomFieldCommandL(EPbk2ExtensionShowOnMap);
       
   722          return EKeyWasConsumed;
       
   723          }*/
       
   724 
       
   725     // Display menu bar if the focused control doesnt consume selection keys
       
   726     CPbk2ContactEditorArrayItem* currentField = iUiFieldArray->Find(
       
   727             IdOfFocusControl());
       
   728 
       
   729     if (currentField)
       
   730         {
       
   731         if (currentField->ContactEditorField()
       
   732                 && currentField->ContactEditorField()->ConsumesKeyEvent(
       
   733                         aKeyEvent, aType))
       
   734             {
       
   735             ret = CAknForm::OfferKeyEventL(aKeyEvent, aType);
       
   736             }
       
   737         else if (currentField->ContactEditorUIField()
       
   738                 && currentField->ContactEditorUIField()->ConsumesKeyEvent(
       
   739                         aKeyEvent, aType))
       
   740             {
       
   741             ret = CAknForm::OfferKeyEventL(aKeyEvent, aType);
       
   742             }
       
   743         }
       
   744 
       
   745     if (ret != EKeyWasConsumed && aType == EEventKey && aKeyEvent.iCode
       
   746             == EKeyOK)
       
   747         {
       
   748         iContextMenuBar->TryDisplayMenuBarL();
       
   749         ret = EKeyWasConsumed;
       
   750         }
       
   751 
       
   752     if ( ret != EKeyWasConsumed && !iEndKeyWasPressed )
       
   753         {
       
   754         if ( aKeyEvent.iCode == EKeyEscape )
       
   755             {
       
   756             iEditorStrategy.StopQuery();
       
   757             iEndKeyWasPressed = ETrue;
       
   758             }
       
   759         ret = CAknForm::OfferKeyEventL( aKeyEvent, aType );
       
   760         if ( ret == EKeyWasConsumed && 
       
   761             aKeyEvent.iCode != EKeyPhoneEnd && aKeyEvent.iCode != EKeyEscape )
       
   762             {
       
   763             UpdateCbasL();
       
   764             }        
       
   765         }
       
   766 
       
   767     return ret;
       
   768     }
       
   769 
       
   770 // --------------------------------------------------------------------------
       
   771 // CPbk2ContactEditorDlgImpl::GetHelpContext
       
   772 // --------------------------------------------------------------------------
       
   773 //
       
   774 void CPbk2ContactEditorDlgImpl::GetHelpContext
       
   775         ( TCoeHelpContext& aContext ) const
       
   776     {
       
   777     if (iParams.iHelpContext)
       
   778         {
       
   779         // If external help context has been set, return it..
       
   780         aContext = *iParams.iHelpContext;
       
   781         }
       
   782     else
       
   783         {
       
   784         // ..otherwise go with the default context
       
   785         iEditorStrategy.GetHelpContext(aContext);
       
   786         }
       
   787     }
       
   788 
       
   789 // --------------------------------------------------------------------------
       
   790 // CPbk2ContactEditorDlgImpl::PreLayoutDynInitL
       
   791 // --------------------------------------------------------------------------
       
   792 //
       
   793 void CPbk2ContactEditorDlgImpl::PreLayoutDynInitL()
       
   794     {
       
   795     SetEditableL(ETrue);
       
   796 
       
   797     if (!ContactHasAddress(EPbk2FieldGroupIdPostalAddress)
       
   798             && !ContactHasAddress(EPbk2FieldGroupIdHomeAddress)
       
   799             && !ContactHasAddress(EPbk2FieldGroupIdCompanyAddress))
       
   800         {
       
   801         AddGroupFieldsL(EPbk2FieldGroupIdPostalAddress);
       
   802         }
       
   803     
       
   804     if(iAddressViewStandalone)
       
   805         {
       
   806         AddGroupFieldsL(Pbk2AddressTools::MapViewTypeToAddress(iParams.iActiveView));
       
   807         }
       
   808 
       
   809     iUiFieldArray->CreateFieldsFromContactL(iParams);
       
   810     SetAddressValidationIconsL();
       
   811 
       
   812     // Offer button group container to extensions.
       
   813     // This is needed here because previous settings might override extension's
       
   814     // buttons.
       
   815     iEditorExtension->ModifyButtonGroupContainerL(ButtonGroupContainer());
       
   816     }
       
   817 
       
   818 // --------------------------------------------------------------------------
       
   819 // CPbk2ContactEditorDlgImpl::PostLayoutDynInitL
       
   820 // --------------------------------------------------------------------------
       
   821 //
       
   822 void CPbk2ContactEditorDlgImpl::PostLayoutDynInitL()
       
   823     {
       
   824     UpdateTitleL();
       
   825     UpdateTitlePictureL();
       
   826     if(iParams.iFocusedContactField)
       
   827         {
       
   828         const TInt count = iUiFieldArray->Count();
       
   829         for (TInt i = 0; i < count; ++i)
       
   830             {
       
   831                 if(iUiFieldArray->At(i).ContactEditorField())
       
   832                 {
       
   833                 MVPbkBaseContactField & field =
       
   834                         iUiFieldArray->At(i).ContactEditorField()->ContactField();
       
   835                 if (field.IsSame(*iParams.iFocusedContactField))
       
   836                     {
       
   837                     UpdateCbasL(&(iUiFieldArray->At(i)));
       
   838                     break;
       
   839                     }
       
   840                 }
       
   841             }
       
   842         }
       
   843     else if(iUiFieldArray->Count())
       
   844         {
       
   845         UpdateCbasL(&(iUiFieldArray->At(0)));
       
   846         }
       
   847     
       
   848     // Notify relocator, that editor is ready
       
   849     iRelocator.EditorReadyL();
       
   850     }
       
   851 
       
   852 // --------------------------------------------------------------------------
       
   853 // CPbk2ContactEditorDlgImpl::SetInitialCurrentLine
       
   854 // --------------------------------------------------------------------------
       
   855 //
       
   856 void CPbk2ContactEditorDlgImpl::SetInitialCurrentLine()
       
   857     {
       
   858     TRAPD( err, ActivateFirstPageL() );
       
   859     if(err)
       
   860         {
       
   861         return;
       
   862         }
       
   863 
       
   864     TInt focusedIndex = 0;
       
   865     if ( iParams.iFocusedContactField )
       
   866         {
       
   867         const TInt count = iUiFieldArray->Count();
       
   868         for (TInt i = 0; i < count; ++i)
       
   869             {
       
   870                 if (iUiFieldArray->At(i).ContactEditorField())
       
   871                 {
       
   872                 MVPbkBaseContactField & field =
       
   873                         iUiFieldArray->At(i).ContactEditorField()->ContactField();
       
   874                 if (field.IsSame(*iParams.iFocusedContactField))
       
   875                     {
       
   876                     focusedIndex = i;
       
   877                     break;
       
   878                     }
       
   879                 }
       
   880             }
       
   881         CAknForm::SetInitialCurrentLine();
       
   882         iUiFieldArray->SetFocus(focusedIndex);
       
   883         }
       
   884     else
       
   885         {
       
   886         CAknForm::SetInitialCurrentLine();
       
   887         iUiFieldArray->SetFocus(focusedIndex);
       
   888         }
       
   889     }
       
   890 
       
   891 // --------------------------------------------------------------------------
       
   892 // CPbk2ContactEditorDlgImpl::ProcessCommandL
       
   893 // --------------------------------------------------------------------------
       
   894 //
       
   895 void CPbk2ContactEditorDlgImpl::ProcessCommandL(TInt aCommandId)
       
   896     {
       
   897     HideMenu();
       
   898 
       
   899     iContextMenuBar->StopDisplayingMenuBar();
       
   900 
       
   901     // Extensions get the command first
       
   902     // If decide to exit already, do not handle new commands until this exit cmd clear
       
   903     if (!iEditorExtension->ProcessCommandL(aCommandId) &&
       
   904         !CheckBaseCommandL(aCommandId) &&
       
   905         !CheckFieldSpecificCommandL(aCommandId) &&
       
   906         iExitRecord.IsClear( EExitOrdered ) )
       
   907         {
       
   908 		iCommandId = aCommandId;
       
   909     
       
   910         switch (aCommandId)
       
   911             {
       
   912             case EPbk2CmdAddItem:
       
   913                 {
       
   914                 CmdAddItemL();
       
   915                 break;
       
   916                 }
       
   917 
       
   918             case EPbk2CmdDeleteItem:
       
   919                 {
       
   920                 CmdDeleteItemL();
       
   921                 break;
       
   922                 }
       
   923 
       
   924             case EPbk2CmdEditItemLabel:
       
   925                 {
       
   926                 CmdEditItemLabelL();
       
   927                 break;
       
   928                 }
       
   929 #ifdef ECE_DISABLE_CONTEXT_MENU
       
   930             case EPbk2CmdEditorContextMenu:
       
   931                 {
       
   932                 iContextMenuBar->TryDisplayMenuBarL();
       
   933                 break;
       
   934                 }
       
   935 #endif
       
   936             case EEikCmdExit:
       
   937             case EAknCmdExit:
       
   938                 {
       
   939                 // Exit Phonebook and if existing save 
       
   940                 // contact (happens later on in OkToExit..)
       
   941                 
       
   942                 // Escape or end key pressed.
       
   943                 // We must save changes and exit the application
       
   944                 
       
   945                 if( iParams.iActiveView == TPbk2ContactEditorParams::EEditorView || iAddressViewStandalone )
       
   946                     {
       
   947                     if (!iExitRecord.IsSet(EOkToExitWithoutHandlingIt))
       
   948                         {
       
   949                         if( OkToExitApplicationL( EAknCmdExit ) )
       
   950                             {
       
   951                             iExitRecord.Set(EExitOrdered);
       
   952                             // Remove empty status pane
       
   953                             if (iNaviContainer)
       
   954                                 {
       
   955                                 iNaviContainer->Pop();
       
   956                                 iNaviContainer = NULL;
       
   957                                 }
       
   958     
       
   959                             MPbk2ContactEditorEventObserver::TParams params;
       
   960                             params.iFlags = EPbk2EditorCommandId;
       
   961                             params.iKeyCode = EKeyEscape;
       
   962                             params.iCommandId = EAknCmdExit;
       
   963                             
       
   964                             CmdDoneL(params);
       
   965                             if ( iUseState == EUseOperatingContact ) 
       
   966                                  {
       
   967                                  WaitFinishL();
       
   968                                  }
       
   969                             }
       
   970                         }
       
   971                     break;    
       
   972                     }
       
   973                 else
       
   974                     {
       
   975                     if (!iExitRecord.IsSet(EOkToExitWithoutHandlingIt))
       
   976                         {
       
   977                         iExitRecord.Set(EOkToExitWithoutHandlingIt);
       
   978                         OkToExitApplicationL(EAknCmdExit);
       
   979                             {
       
   980                             // Remove empty status pane
       
   981                             if (iNaviContainer)
       
   982                                 {
       
   983                                 iNaviContainer->Pop();
       
   984                                 iNaviContainer = NULL;
       
   985                                 }
       
   986     
       
   987                             MPbk2ContactEditorEventObserver::TParams params;
       
   988                             params.iFlags = EPbk2EditorKeyCode;
       
   989                             params.iKeyCode = EKeyEscape;
       
   990                             params.iCommandId = EAknCmdExit;
       
   991                             
       
   992                             CmdDoneL(params);
       
   993                             if ( iUseState == EUseOperatingContact ) 
       
   994                                  {
       
   995                                  WaitFinishL();
       
   996                                  }
       
   997                             }
       
   998                         }
       
   999                     }                                
       
  1000                 
       
  1001                 break;
       
  1002                 }
       
  1003             case EAknCmdHelp:
       
  1004                 {
       
  1005                 HlpLauncher::LaunchHelpApplicationL(
       
  1006                         CCoeEnv::Static()->WsSession(),
       
  1007                         iEikonEnv->EikAppUi()->AppHelpContextL());
       
  1008                 break;
       
  1009                 }
       
  1010             default:
       
  1011                 {
       
  1012                 // Command not handled here, forward it to the app ui.
       
  1013                 iEikonEnv->EikAppUi()->HandleCommandL(aCommandId);
       
  1014                 break;
       
  1015                 }
       
  1016             }
       
  1017         }
       
  1018     }
       
  1019 
       
  1020 // --------------------------------------------------------------------------
       
  1021 // CPbk2ContactEditorDlgImpl::CheckBaseCommandL
       
  1022 // Check whether there is a base command to execute
       
  1023 // --------------------------------------------------------------------------
       
  1024 //
       
  1025 TBool CPbk2ContactEditorDlgImpl::CheckBaseCommandL(TInt aCommandId)
       
  1026     {
       
  1027     TBool ret(ETrue);
       
  1028     if (!iCommandPending)
       
  1029         {
       
  1030         //Prevent recursive execution of ExecuteBaseCommandL as touch events are  
       
  1031         //handled in it too. So it causes multiple callback to here if 
       
  1032         //user repeats the same pointer event very quickly.
       
  1033         iCommandPending = ETrue;
       
  1034 
       
  1035         if (iPbk2BaseCommand)
       
  1036             {
       
  1037             //Cancel and delete previous possible pending command. 
       
  1038             delete iPbk2BaseCommand;
       
  1039             iPbk2BaseCommand = NULL;
       
  1040             }
       
  1041         TRAPD(err, ret = ExecuteBaseCommandL(aCommandId));
       
  1042         iCommandPending = EFalse;
       
  1043         User::LeaveIfError(err);
       
  1044         }
       
  1045 
       
  1046     return ret;
       
  1047     }
       
  1048 
       
  1049 // --------------------------------------------------------------------------
       
  1050 // CPbk2ContactEditorDlgImpl::ExecuteBaseCommandL
       
  1051 // --------------------------------------------------------------------------
       
  1052 //
       
  1053 TBool CPbk2ContactEditorDlgImpl::ExecuteBaseCommandL(TInt aCommandId)
       
  1054     {
       
  1055     TBool executingCommand(ETrue);
       
  1056 
       
  1057     switch (aCommandId)
       
  1058         {
       
  1059         case EPbk2CmdEditorChangeRingtone:
       
  1060             {
       
  1061             iPbk2BaseCommand = Pbk2RingtoneCommands::SetRingtoneL(
       
  1062                     &iContact.StoreContact());
       
  1063             break;
       
  1064             }
       
  1065 
       
  1066         case EPbk2CmdEditorRemoveRingtone:
       
  1067             {
       
  1068             iPbk2BaseCommand = Pbk2RingtoneCommands::RemoveRingtoneL(
       
  1069                     &iContact.StoreContact());
       
  1070             break;
       
  1071             }
       
  1072 
       
  1073         case EPbk2CmdEditorSelectAddress:
       
  1074             {
       
  1075             ExecuteAddressDlgL(TPbk2ContactEditorParams::EEditorAddressView);
       
  1076             return executingCommand;
       
  1077             }
       
  1078 
       
  1079         case EPbk2CmdEditorSelectAddressHome:
       
  1080             {
       
  1081             ExecuteAddressDlgL(TPbk2ContactEditorParams::EEditorAddressHomeView);
       
  1082             return executingCommand;
       
  1083             }
       
  1084 
       
  1085         case EPbk2CmdEditorSelectAddressOffice:
       
  1086             {
       
  1087             ExecuteAddressDlgL(
       
  1088                     TPbk2ContactEditorParams::EEditorAddressOfficeView);
       
  1089             return executingCommand;
       
  1090             }
       
  1091 
       
  1092         case EPbk2CmdEditorOpen:
       
  1093             {
       
  1094             CPbk2ContactEditorArrayItem* currentField = iUiFieldArray->Find(
       
  1095                     IdOfFocusControl());
       
  1096 
       
  1097             if (currentField->ContactEditorUIField())
       
  1098                 {
       
  1099                 TPbk2ContactEditorParams::TActiveView
       
  1100                         viewType =
       
  1101                                 Pbk2AddressTools::MapCtrlTypeToViewType(
       
  1102                                         currentField->ContactEditorUIField()->UIField()->CtrlType());
       
  1103                 if (viewType != TPbk2ContactEditorParams::EEditorUndefinied)
       
  1104                     {
       
  1105                     ExecuteAddressDlgL(viewType);
       
  1106                     return executingCommand;
       
  1107                     }
       
  1108                 }
       
  1109             break;
       
  1110             }
       
  1111         case EPbk2CmdEditorSelectAssignFromMaps:
       
  1112             {
       
  1113             HandleCustomFieldCommandL(EPbk2ExtensionAssignFromMap);
       
  1114             break;
       
  1115             }
       
  1116 
       
  1117         case EPbk2CmdEditorAddImage:
       
  1118         case EPbk2CmdEditorChangeImage:
       
  1119             {
       
  1120             iPbk2BaseCommand = Pbk2ImageCommands::SetImageL(
       
  1121                 &iContact,this);
       
  1122             break;
       
  1123             }
       
  1124 
       
  1125         case EPbk2CmdEditorViewImage:
       
  1126             {
       
  1127             iPbk2BaseCommand = Pbk2ImageCommands::ViewImageL(
       
  1128                     &iContact.StoreContact());
       
  1129             break;
       
  1130             }
       
  1131 
       
  1132         case EPbk2CmdEditorRemoveImage:
       
  1133             {
       
  1134             iPbk2BaseCommand = Pbk2ImageCommands::RemoveImageL(&iContact);
       
  1135             break;
       
  1136             }
       
  1137 
       
  1138         default:
       
  1139             {
       
  1140             executingCommand = EFalse;
       
  1141             break;
       
  1142             }
       
  1143         }
       
  1144 
       
  1145     if (executingCommand)
       
  1146         {
       
  1147         CPbk2ContactEditorArrayItem* currentField = iUiFieldArray->Find(
       
  1148                 IdOfFocusControl());
       
  1149 
       
  1150         if (currentField && currentField->ContactEditorField())
       
  1151             {
       
  1152             TInt id = currentField->ControlId();
       
  1153             TAny
       
  1154                     * ext =
       
  1155                             currentField->ContactEditorField()->ContactEditorFieldExtension(
       
  1156                                     TUid::Uid(NULL));
       
  1157             if (id == EPbk2EditorLineRingtone)
       
  1158                 {
       
  1159                 CPbk2ContactEditorRingtoneField* fld =
       
  1160                         static_cast<CPbk2ContactEditorRingtoneField*> (ext);
       
  1161                 fld->SetTextL();
       
  1162                 }
       
  1163             else if( id == EPbk2EditorLineImage && 
       
  1164                      aCommandId == EPbk2CmdEditorRemoveImage)
       
  1165                 {
       
  1166                 //If image removed, no callback to ImageLoadingComplete() so do it here
       
  1167                 DoImageLoadingCompleteL();
       
  1168                 }
       
  1169             }
       
  1170         }
       
  1171 
       
  1172     return executingCommand;
       
  1173     }
       
  1174 
       
  1175 // --------------------------------------------------------------------------
       
  1176 // CPbk2ContactEditorDlgImpl::SwitchView
       
  1177 // --------------------------------------------------------------------------
       
  1178 //
       
  1179 void CPbk2ContactEditorDlgImpl::ExecuteAddressDlgL(
       
  1180         TPbk2ContactEditorParams::TActiveView aActiveView)
       
  1181     {
       
  1182     if (iParams.iActiveView == TPbk2ContactEditorParams::EEditorView)
       
  1183         {
       
  1184         AddGroupFieldsL(Pbk2AddressTools::MapViewTypeToAddress(aActiveView));
       
  1185         }
       
  1186 
       
  1187     iParams.iActiveView = aActiveView;
       
  1188     
       
  1189     CPbk2ContactEditorDlgImpl* adressDlg = CPbk2ContactEditorDlgImpl::NewL(
       
  1190             iParams, iContact, iFieldProperties, iContactObserver,
       
  1191             iEditorStrategy, iRelocator, iAppServices );
       
  1192     
       
  1193     iAddressView = adressDlg;
       
  1194     adressDlg->ExecuteLD();
       
  1195     iAddressView = NULL;
       
  1196     iParams.iActiveView = TPbk2ContactEditorParams::EEditorView;
       
  1197     UpdateControlsL();
       
  1198     }
       
  1199 
       
  1200 // --------------------------------------------------------------------------
       
  1201 // CPbk2ContactEditorDlgImpl::AddAddressFields
       
  1202 // --------------------------------------------------------------------------
       
  1203 //
       
  1204 void CPbk2ContactEditorDlgImpl::AddGroupFieldsL(TPbk2FieldGroupId aGroupId)
       
  1205     {
       
  1206     if (aGroupId == EPbk2FieldGroupIdNone)
       
  1207         return;
       
  1208 
       
  1209     TInt count = iFieldProperties.Count();
       
  1210     for (TInt idx = 0; idx < count; idx++)
       
  1211         {
       
  1212         const MPbk2FieldProperty& fieldProp = iFieldProperties.At(idx);
       
  1213         if (fieldProp.GroupId() == aGroupId)
       
  1214             {
       
  1215             AddItemToContactL(fieldProp.FieldType().FieldTypeResId(),
       
  1216                     KNullDesC(), EFalse);
       
  1217             }
       
  1218         }
       
  1219     }
       
  1220 
       
  1221 // --------------------------------------------------------------------------
       
  1222 // CPbk2ContactEditorDlgImpl::AreAllFieldsEmpty
       
  1223 // --------------------------------------------------------------------------
       
  1224 //
       
  1225 TBool CPbk2ContactEditorDlgImpl::AreAllFieldsEmpty()
       
  1226     {
       
  1227     TBool result(ETrue);
       
  1228     TInt countAll = iContact.PresentationFields().FieldCount();
       
  1229     for (TInt idx = 0; idx < countAll; idx++)
       
  1230         {
       
  1231         CPbk2PresentationContactField& field =
       
  1232                 iContact.PresentationFields().At(idx);
       
  1233         
       
  1234         MVPbkContactFieldData& data = field.FieldData();
       
  1235         TInt fld = field.FieldProperty().FieldType().FieldTypeResId();        
       
  1236         if(fld != R_VPBK_FIELD_TYPE_RINGTONE && 
       
  1237            fld != R_VPBK_FIELD_TYPE_THUMBNAILPIC &&
       
  1238            fld != R_VPBK_FIELD_TYPE_CALLEROBJIMG &&
       
  1239            fld != R_VPBK_FIELD_TYPE_SYNCCLASS && 
       
  1240            fld != R_VPBK_FIELD_TYPE_TOPCONTACT) 
       
  1241             {                   
       
  1242             if(!data.IsEmpty())
       
  1243                 {
       
  1244                 if(data.DataType() == EVPbkFieldStorageTypeText)
       
  1245                     {
       
  1246                     HBufC* fieldText = MVPbkContactFieldTextData::Cast(data).Text().AllocL();
       
  1247                     fieldText->Des().TrimAll();                    
       
  1248                     if(fieldText->Length() > 0)
       
  1249                         {
       
  1250                         result = EFalse;
       
  1251                         }
       
  1252                     delete fieldText;                      
       
  1253                     }
       
  1254                 else                
       
  1255                     {
       
  1256                     result = EFalse;
       
  1257                     }
       
  1258                 }
       
  1259             }           
       
  1260         }
       
  1261     return result;
       
  1262     }
       
  1263 
       
  1264 // --------------------------------------------------------------------------
       
  1265 // CPbk2ContactEditorDlgImpl::ContactHasAddress
       
  1266 // --------------------------------------------------------------------------
       
  1267 //
       
  1268 TBool CPbk2ContactEditorDlgImpl::ContactHasAddress(
       
  1269         TPbk2FieldGroupId aAddressGroup)
       
  1270     {
       
  1271     TInt countAll = iContact.PresentationFields().FieldCount();
       
  1272     for (TInt idx = 0; idx < countAll; idx++)
       
  1273         {
       
  1274         CPbk2PresentationContactField& field =
       
  1275                 iContact.PresentationFields().At(idx);
       
  1276         if (field.FieldProperty().GroupId() == aAddressGroup)
       
  1277             {
       
  1278             return ETrue;
       
  1279             }
       
  1280         }
       
  1281     return EFalse;
       
  1282     }
       
  1283 
       
  1284 // --------------------------------------------------------------------------
       
  1285 // CPbk2ContactEditorDlgImpl::ClearControls
       
  1286 // --------------------------------------------------------------------------
       
  1287 //
       
  1288 void CPbk2ContactEditorDlgImpl::ClearControls()
       
  1289     {
       
  1290     TInt count = iUiFieldArray->Count();
       
  1291     for (TInt idx = count - 1; idx >= 0; idx--)
       
  1292         {
       
  1293         iUiFieldArray->RemoveFieldFromUI(idx);
       
  1294         }
       
  1295     }
       
  1296 
       
  1297 // --------------------------------------------------------------------------
       
  1298 // CPbk2ContactEditorDlgImpl::ContactEditorControlExtension
       
  1299 // --------------------------------------------------------------------------
       
  1300 //
       
  1301 TAny* CPbk2ContactEditorDlgImpl::ContactEditorControlExtension(TUid /*aExtensionUid*/)
       
  1302     {
       
  1303     return static_cast<MPbk2ContactEditorControlExtension*> (this);
       
  1304     }
       
  1305 
       
  1306 // --------------------------------------------------------------------------
       
  1307 // CPbk2ContactEditorDlgImpl::UpdateControlsL
       
  1308 // --------------------------------------------------------------------------
       
  1309 //
       
  1310 void CPbk2ContactEditorDlgImpl::UpdateControlsL()
       
  1311     {
       
  1312     iUiFieldArray->UpdateControlsL();
       
  1313     SetAddressValidationIconsL();
       
  1314     UpdatePageL(ETrue);
       
  1315     }
       
  1316 
       
  1317 // --------------------------------------------------------------------------
       
  1318 // CPbk2ContactEditorDlgImpl::CheckFieldSpecificCommandL
       
  1319 // --------------------------------------------------------------------------
       
  1320 //
       
  1321 TBool CPbk2ContactEditorDlgImpl::CheckFieldSpecificCommandL(TInt aCommandId)
       
  1322     {
       
  1323     TBool ret(EFalse);
       
  1324     CPbk2ContactEditorArrayItem* currentField = iUiFieldArray->Find(
       
  1325             IdOfFocusControl());
       
  1326 
       
  1327     if (currentField)
       
  1328         {
       
  1329         if (currentField->ContactEditorUIField())
       
  1330             {
       
  1331             ret = currentField->ContactEditorUIField()->HandleCustomFieldCommandL(
       
  1332                         aCommandId);
       
  1333             }
       
  1334         else
       
  1335             {
       
  1336             MPbk2ContactEditorField2* tempCurrentField =
       
  1337                 reinterpret_cast<MPbk2ContactEditorField2*> 
       
  1338                     (currentField->ContactEditorField()->ContactEditorFieldExtension(
       
  1339                         KMPbk2ContactEditorFieldExtension2Uid));
       
  1340             if (tempCurrentField)
       
  1341                 {
       
  1342                 ret = tempCurrentField->HandleCustomFieldCommandL(aCommandId);
       
  1343                 }
       
  1344             }
       
  1345         }
       
  1346 
       
  1347     return ret;
       
  1348     }
       
  1349 
       
  1350 // --------------------------------------------------------------------------
       
  1351 // CPbk2ContactEditorDlgImpl::DynInitMenuPaneL
       
  1352 // --------------------------------------------------------------------------
       
  1353 //
       
  1354 void CPbk2ContactEditorDlgImpl::DynInitMenuPaneL(TInt aResourceId,
       
  1355         CEikMenuPane* aMenuPane)
       
  1356     {
       
  1357     iEditorExtension->DynInitMenuPaneL(aResourceId, aMenuPane);
       
  1358 
       
  1359     if (aResourceId == R_PBK2_CONTACTEDITOR_MENUPANE ||
       
  1360         aResourceId == R_PBK2_CONTACTEDITOR_CONTEXT_MENUPANE)
       
  1361         {
       
  1362         //Label editing not anymore supported. Remove later all code
       
  1363         //related to editing labels
       
  1364         DimItem( aMenuPane,  EPbk2CmdEditItemLabel);
       
  1365         // Filter delete item away from menu for first and last name fields
       
  1366         CPbk2ContactEditorArrayItem* current = iUiFieldArray->Find(
       
  1367                 IdOfFocusControl());
       
  1368         MPbk2ContactEditorField* currentField = current->ContactEditorField();
       
  1369         if (currentField)
       
  1370             {
       
  1371             if (currentField->FieldProperty().Flags()
       
  1372                     & KPbk2FieldFlagCanNotBeRemoved)
       
  1373                 {
       
  1374                 DimItem(aMenuPane, EPbk2CmdDeleteItem);
       
  1375                 }
       
  1376             //Label editing not anymore supported. Remove later all code
       
  1377             //related to editing labels
       
  1378             //MVPbkStoreContactField& field = currentField->ContactField();
       
  1379             //if (!field.SupportsLabel())
       
  1380             //    {
       
  1381             //    DimItem( aMenuPane,  EPbk2CmdEditItemLabel);                
       
  1382             //    }
       
  1383             //else
       
  1384             //    {
       
  1385             //    TVPbkFieldVersitProperty prop;
       
  1386             //    prop.SetName(EVPbkVersitNameIMPP);
       
  1387             //    if (field.BestMatchingFieldType()->Matches(prop, 0))
       
  1388             //        {
       
  1389             //        DimItem( aMenuPane,  EPbk2CmdEditItemLabel);                
       
  1390             //        }
       
  1391             //    }
       
  1392             DynInitRingtoneL(aResourceId, aMenuPane, *currentField);
       
  1393             DynInitImageL(aResourceId, aMenuPane, *currentField);
       
  1394             DynInitSyncL(aResourceId, aMenuPane, *currentField);
       
  1395             }
       
  1396         else
       
  1397             {
       
  1398             DimItem(aMenuPane, EPbk2CmdDeleteItem);
       
  1399             DimItem(aMenuPane, EPbk2CmdEditorChangeRingtone);
       
  1400             DimItem(aMenuPane, EPbk2CmdEditorRemoveRingtone);
       
  1401             DimItem(aMenuPane, EPbk2CmdEditorAddImage);
       
  1402             DimItem(aMenuPane, EPbk2CmdEditorViewImage);
       
  1403             DimItem(aMenuPane, EPbk2CmdEditorChangeImage);
       
  1404             DimItem(aMenuPane, EPbk2CmdEditorRemoveImage);
       
  1405             DimItem(aMenuPane, EPbk2CmdEditorChangeSync);
       
  1406             }
       
  1407 
       
  1408         DynInitAddressL(aResourceId, aMenuPane);
       
  1409         // If there are no available fields to add, do not show
       
  1410         // the add item dialog. If phone memory is in configuration
       
  1411         // this check is not needed.
       
  1412         if (!iRelocator.IsPhoneMemoryInConfigurationL())
       
  1413             {
       
  1414             CArrayPtr<const MPbk2FieldProperty>* availableFields =
       
  1415                     iContact.AvailableFieldsToAddL();
       
  1416             if (!availableFields || availableFields->Count() == 0)
       
  1417                 {
       
  1418                 DimItem(aMenuPane, EPbk2CmdAddItem);
       
  1419                 }
       
  1420             delete availableFields;
       
  1421             }
       
  1422 
       
  1423         if (aResourceId == R_PBK2_CONTACTEDITOR_MENUPANE)
       
  1424             {
       
  1425             // Hide exit, if wanted. Exit command is available only in
       
  1426             // main menu.
       
  1427             if (iParams.iFlags & TPbk2ContactEditorParams::EHideExit)
       
  1428                 {
       
  1429                 DimItem(aMenuPane, EAknCmdExit);
       
  1430                 }
       
  1431             }
       
  1432         }
       
  1433     }
       
  1434 
       
  1435 // --------------------------------------------------------------------------
       
  1436 // CPbk2ContactEditorDlgImpl::DynInitRingtoneL
       
  1437 // --------------------------------------------------------------------------
       
  1438 //
       
  1439 void CPbk2ContactEditorDlgImpl::DynInitRingtoneL(
       
  1440     TInt /*aResourceId*/, 
       
  1441     CEikMenuPane* aMenuPane, 
       
  1442     MPbk2ContactEditorField& aCurrentField )
       
  1443     {
       
  1444     TInt id = aCurrentField.FieldProperty().FieldType().FieldTypeResId();  
       
  1445     
       
  1446     if(id != R_VPBK_FIELD_TYPE_RINGTONE)
       
  1447         {
       
  1448         DimItem( aMenuPane,  EPbk2CmdEditorChangeRingtone);
       
  1449         DimItem( aMenuPane,  EPbk2CmdEditorRemoveRingtone);
       
  1450         }
       
  1451     else 
       
  1452         {
       
  1453         if( aCurrentField.ContactField().FieldData().DataType() != 
       
  1454             EVPbkFieldStorageTypeText || 
       
  1455             aCurrentField.ContactField().FieldData().IsEmpty()  )
       
  1456             {
       
  1457             DimItem( aMenuPane,  EPbk2CmdEditorRemoveRingtone);
       
  1458             }
       
  1459         //Label editing not anymore supported (is dimmed in DynInitMenuPaneL)
       
  1460         //DimItem( aMenuPane,  EPbk2CmdEditItemLabel);
       
  1461         DimItem( aMenuPane,  EPbk2CmdDeleteItem);
       
  1462         }
       
  1463     }
       
  1464 
       
  1465 // --------------------------------------------------------------------------
       
  1466 // CPbk2ContactEditorDlgImpl::DynInitImageL
       
  1467 // --------------------------------------------------------------------------
       
  1468 //
       
  1469 void CPbk2ContactEditorDlgImpl::DynInitImageL(
       
  1470     TInt /*aResourceId*/, 
       
  1471     CEikMenuPane* aMenuPane, 
       
  1472     MPbk2ContactEditorField& aCurrentField )
       
  1473     {
       
  1474     TInt id = aCurrentField.FieldProperty().FieldType().FieldTypeResId(); 
       
  1475     
       
  1476     if( id != R_VPBK_FIELD_TYPE_CALLEROBJIMG )
       
  1477         {
       
  1478         DimItem( aMenuPane,  EPbk2CmdEditorAddImage );
       
  1479         DimItem( aMenuPane,  EPbk2CmdEditorViewImage);
       
  1480         DimItem( aMenuPane,  EPbk2CmdEditorChangeImage);
       
  1481         DimItem( aMenuPane,  EPbk2CmdEditorRemoveImage);
       
  1482         }
       
  1483     else 
       
  1484         {
       
  1485         if( aCurrentField.ContactField().FieldData().DataType() == 
       
  1486             EVPbkFieldStorageTypeText && 
       
  1487             !aCurrentField.ContactField().FieldData().IsEmpty() )
       
  1488             {
       
  1489             //'View' shown even if there would be cold file name, i.e. no file 
       
  1490             //available the moment (e.g other mem card). Gallery takes care of
       
  1491             //error message. So just dim add option.
       
  1492             DimItem( aMenuPane, EPbk2CmdEditorAddImage );
       
  1493             }
       
  1494         else
       
  1495             {
       
  1496             DimItem( aMenuPane,  EPbk2CmdEditorViewImage);                    
       
  1497             DimItem( aMenuPane,  EPbk2CmdEditorChangeImage);
       
  1498             DimItem( aMenuPane,  EPbk2CmdEditorRemoveImage);
       
  1499             }
       
  1500 
       
  1501         //Label editing not anymore supported (is dimmed in DynInitMenuPaneL)        
       
  1502         //DimItem( aMenuPane,  EPbk2CmdEditItemLabel);
       
  1503         DimItem( aMenuPane,  EPbk2CmdDeleteItem);
       
  1504         }
       
  1505     }
       
  1506 
       
  1507 // --------------------------------------------------------------------------
       
  1508 // CPbk2ContactEditorDlgImpl::DynInitSyncL
       
  1509 // --------------------------------------------------------------------------
       
  1510 //
       
  1511 void CPbk2ContactEditorDlgImpl::DynInitSyncL(
       
  1512     TInt /*aResourceId*/, 
       
  1513     CEikMenuPane* aMenuPane, 
       
  1514     MPbk2ContactEditorField& aCurrentField )
       
  1515     {
       
  1516     TInt id = aCurrentField.FieldProperty().FieldType().FieldTypeResId();  
       
  1517     
       
  1518     if(id != R_VPBK_FIELD_TYPE_SYNCCLASS) 
       
  1519         {
       
  1520         DimItem( aMenuPane,  EPbk2CmdEditorChangeSync);
       
  1521         }
       
  1522     else 
       
  1523         {
       
  1524         //Label editing not anymore supported (is dimmed in DynInitMenuPaneL)
       
  1525         //DimItem( aMenuPane,  EPbk2CmdEditItemLabel);
       
  1526         }
       
  1527     }
       
  1528 // CPbk2ContactEditorDlgImpl::DynInitAddressL
       
  1529 // --------------------------------------------------------------------------
       
  1530 //
       
  1531 void CPbk2ContactEditorDlgImpl::DynInitAddressL(TInt /*aResourceId*/,
       
  1532         CEikMenuPane* aMenuPane)
       
  1533     {
       
  1534     CPbk2ContactEditorArrayItem* current = iUiFieldArray->Find(
       
  1535             IdOfFocusControl());
       
  1536     if (iParams.iActiveView == TPbk2ContactEditorParams::EEditorView)
       
  1537         {
       
  1538         DimItem(aMenuPane, EPbk2ExtensionAssignFromMapSelect);
       
  1539         DimItem(aMenuPane, EPbk2ExtensionAssignFromMap);
       
  1540         if (current && current->ContactEditorUIField()
       
  1541                 && Pbk2AddressTools::MapCtrlTypeToAddress(
       
  1542                         current->ContactEditorUIField()->UIField()->CtrlType())
       
  1543                         != EPbk2FieldGroupIdNone)
       
  1544             {
       
  1545             UnDimItem(aMenuPane, EPbk2CmdEditorOpen);
       
  1546             UnDimItem(aMenuPane, EPbk2CmdDeleteItem); 
       
  1547             }
       
  1548         else
       
  1549             {
       
  1550             DimItem(aMenuPane, EPbk2CmdEditorOpen);
       
  1551             }
       
  1552         }
       
  1553     else
       
  1554         {
       
  1555         if (!current || !current->ContactEditorUIField()
       
  1556                 || current->ContactEditorUIField()->UIField()->CtrlType()
       
  1557                         != EPbk2FieldCtrlTypeExtAssignFromMapsEditor)
       
  1558             {
       
  1559             DimItem(aMenuPane, EPbk2ExtensionAssignFromMapSelect);
       
  1560             }
       
  1561         DimItem(aMenuPane, EPbk2CmdAddItem);
       
  1562         DimItem(aMenuPane, EPbk2CmdEditorOpen);
       
  1563         DimItem(aMenuPane, EPbk2CmdDeleteItem); 
       
  1564         }
       
  1565     }
       
  1566 
       
  1567 // --------------------------------------------------------------------------
       
  1568 // CPbk2ContactEditorDlgImpl::DimItem
       
  1569 // --------------------------------------------------------------------------
       
  1570 //
       
  1571 void CPbk2ContactEditorDlgImpl::DimItem(CEikMenuPane* aMenuPane, TInt aCmd)
       
  1572     {
       
  1573     TInt pos;
       
  1574     if (aMenuPane->MenuItemExists(aCmd, pos))
       
  1575         {
       
  1576         aMenuPane->SetItemDimmed(aCmd, ETrue);
       
  1577         }
       
  1578     }
       
  1579 
       
  1580 // --------------------------------------------------------------------------
       
  1581 // CPbk2ContactEditorDlgImpl::UnDimItem
       
  1582 // --------------------------------------------------------------------------
       
  1583 //
       
  1584 void CPbk2ContactEditorDlgImpl::UnDimItem(CEikMenuPane* aMenuPane, TInt aCmd)
       
  1585     {
       
  1586     TInt pos;
       
  1587     if (aMenuPane->MenuItemExists(aCmd, pos))
       
  1588         {
       
  1589         aMenuPane->SetItemDimmed(aCmd, EFalse);
       
  1590         }
       
  1591     }
       
  1592 
       
  1593 // --------------------------------------------------------------------------
       
  1594 // CPbk2ContactEditorDlgImpl::OkToExitL
       
  1595 // --------------------------------------------------------------------------
       
  1596 //
       
  1597 TBool CPbk2ContactEditorDlgImpl::OkToExitL(TInt aKeycode)
       
  1598     {
       
  1599     TBool ret = EFalse;
       
  1600     if( iCommandPending )
       
  1601         {
       
  1602         //When command in process prevent further processing
       
  1603         ret = EFalse;
       
  1604         }
       
  1605     else if ( iExitRecord.IsSet( EOkToExitWithoutHandlingIt ) )
       
  1606         {
       
  1607         ret = ETrue;
       
  1608         }
       
  1609     else if ( aKeycode == EAknSoftkeyDone )
       
  1610         {
       
  1611         // Done key pressed
       
  1612         MPbk2ContactEditorEventObserver::TParams params;
       
  1613         params.iFlags = EPbk2EditorKeyCode;
       
  1614         params.iKeyCode = aKeycode;
       
  1615         CmdDoneL( params );
       
  1616         }
       
  1617     else if (aKeycode == EKeyEscape || aKeycode == EEikBidCancel)
       
  1618         {
       
  1619         // this happens when service is canceled, so in this case, 
       
  1620         // do nothing but give ret ETrue, so that this object
       
  1621         // is able to be deleted later.
       
  1622         if( iServiceCanceled )
       
  1623             {
       
  1624             ret = ETrue;
       
  1625             }
       
  1626         // Escape or end key pressed.
       
  1627         // We must save changes and exit the applicatio
       
  1628         else if( !iExitRecord.IsSet( EExitOrdered ) )
       
  1629             {
       
  1630             // Remove empty status pane
       
  1631             if (iNaviContainer)
       
  1632                 {
       
  1633                  iNaviContainer->Pop();
       
  1634                  iNaviContainer = NULL;
       
  1635                  }
       
  1636             if ( iStoredTitlePaneText )
       
  1637                 {
       
  1638                 delete iStoredTitlePaneText;
       
  1639                 iStoredTitlePaneText = NULL;
       
  1640                 }
       
  1641             MakeVisible( EFalse );
       
  1642             MPbk2ContactEditorEventObserver::TParams params;
       
  1643             params.iFlags = EPbk2EditorKeyCode;
       
  1644             params.iKeyCode = aKeycode;
       
  1645 
       
  1646             // If the application is not allowed to hide itself in the
       
  1647             // background, end of the dialog is also end of the 
       
  1648             // application. 
       
  1649             if ( !iAvkonAppUi->ExitHidesInBackground() )
       
  1650                 {
       
  1651                 iExitRecord.Set( EExitOrdered );
       
  1652                 
       
  1653                 if( OkToExitApplicationL( EAknCmdExit ) )
       
  1654                     {
       
  1655                     params.iCommandId = EAknCmdExit;
       
  1656                     }
       
  1657                 }
       
  1658             
       
  1659             CmdDoneL( params );
       
  1660             }
       
  1661         }
       
  1662     else if (aKeycode == EAknSoftkeyContextOptions)
       
  1663         {
       
  1664         // Launch context menu if the control is not popup control
       
  1665         CEikCaptionedControl* line = CurrentLine();
       
  1666         TInt type = line->iControlType;
       
  1667         TBool isPopUp = ( type == EAknCtPopupFieldText ) ||
       
  1668             ( type == EAknCtPopupField );
       
  1669         if (isPopUp)
       
  1670             {
       
  1671             CAknPopupField* ctrl =
       
  1672                 static_cast<CAknPopupField*>( line->iControl );
       
  1673             ctrl->ActivateSelectionListL();
       
  1674             }
       
  1675         else
       
  1676             {
       
  1677             CPbk2ContactEditorArrayItem* current = iUiFieldArray->Find(
       
  1678                     IdOfFocusControl());
       
  1679             if (current && current->ContactEditorUIField())
       
  1680                 {
       
  1681                 TPbk2ContactEditorParams::TActiveView
       
  1682                         viewType =
       
  1683                                 Pbk2AddressTools::MapCtrlTypeToViewType(
       
  1684                                         current->ContactEditorUIField()->UIField()->CtrlType());
       
  1685                 if (viewType != TPbk2ContactEditorParams::EEditorUndefinied)
       
  1686                     {
       
  1687                     ExecuteAddressDlgL(viewType);
       
  1688                     return ret;
       
  1689                     }
       
  1690                 else if (current->ContactEditorUIField()->UIField()->CtrlType()
       
  1691                         == EPbk2FieldCtrlTypeExtAssignFromMapsEditor)
       
  1692                     {
       
  1693                     HandleCustomFieldCommandL(EPbk2ExtensionAssignFromMap);
       
  1694                     return ret;
       
  1695                     }
       
  1696                 }
       
  1697 
       
  1698             iContextMenuBar->SetMenuTitleResourceId(
       
  1699                     R_PBK2_CONTACTEDITOR_CONTEXT_MENUBAR);
       
  1700             iContextMenuBar->SetMenuType(CEikMenuBar::EMenuContext);
       
  1701             iContextMenuBar->StopDisplayingMenuBar();
       
  1702             iContextMenuBar->TryDisplayMenuBarL();
       
  1703             iContextMenuBar->SetMenuTitleResourceId
       
  1704                 ( R_PBK2_CONTACTEDITOR_MENUBAR );
       
  1705             iContextMenuBar->SetMenuType( CEikMenuBar::EMenuOptions );
       
  1706             }
       
  1707         }
       
  1708     else if( aKeycode == EAknSoftkeyChange ) 
       
  1709         {
       
  1710         //For custom controls (ringtone, image) msk middle key press need to be 
       
  1711         //caught here
       
  1712         CPbk2ContactEditorArrayItem* current = iUiFieldArray->Find(
       
  1713                 IdOfFocusControl());
       
  1714         MPbk2ContactEditorField* currentField = NULL;
       
  1715         if (current)
       
  1716             {
       
  1717             currentField = current->ContactEditorField();
       
  1718             }
       
  1719 
       
  1720         if (currentField)
       
  1721             {
       
  1722             TInt id = currentField->ControlId();
       
  1723             if (id == EPbk2EditorLineRingtone || id == EPbk2EditorLineImage)
       
  1724                 {
       
  1725                 MPbk2ContactEditorField2
       
  1726                         * tempCurrentField =
       
  1727                                 reinterpret_cast<MPbk2ContactEditorField2*> (currentField->ContactEditorFieldExtension(
       
  1728                                         KMPbk2ContactEditorFieldExtension2Uid));
       
  1729                 if (tempCurrentField)
       
  1730                     {
       
  1731                     tempCurrentField->HandleCustomFieldCommandL(
       
  1732                             EPbk2CmdEditorHandleCustomSelect);
       
  1733                     }
       
  1734                 }
       
  1735             else
       
  1736                 {
       
  1737                 //For non-custom fields (sync...) forward to framework 
       
  1738                 ForwardOkToExitL( aKeycode );
       
  1739                 }
       
  1740             }
       
  1741         }
       
  1742     else
       
  1743         {
       
  1744         ForwardOkToExitL( aKeycode );
       
  1745         }
       
  1746 
       
  1747     // Clear the exit state after usage.
       
  1748     iExitRecord.Clear( EOkToExitWithoutHandlingIt );
       
  1749     return ret;
       
  1750     }
       
  1751 
       
  1752 // --------------------------------------------------------------------------
       
  1753 // CPbk2ContactEditorDlgImpl::ForwardOkToExitL
       
  1754 // --------------------------------------------------------------------------
       
  1755 //
       
  1756 void CPbk2ContactEditorDlgImpl::ForwardOkToExitL( TInt aKeycode )
       
  1757     {
       
  1758     //Prevent further execution of menu commands while a command is running.  
       
  1759     //In touch tapping RSK very quickly for ringtone gets otherwise through 
       
  1760     //when ringtone fetch command is running.
       
  1761     TBool okToSkip = iCommandPending && aKeycode != EAknSoftkeyDone && 
       
  1762                      aKeycode != EAknCmdExit && aKeycode != EAknCmdExit;  
       
  1763     if(!okToSkip)
       
  1764         {
       
  1765         CAknForm::OkToExitL( aKeycode );
       
  1766         }
       
  1767     }
       
  1768 
       
  1769 // --------------------------------------------------------------------------
       
  1770 // CPbk2ContactEditorDlgImpl::HandleControlStateChangeL
       
  1771 // --------------------------------------------------------------------------
       
  1772 //
       
  1773 void CPbk2ContactEditorDlgImpl::HandleControlStateChangeL(TInt aControlId)
       
  1774     {
       
  1775     CPbk2ContactEditorArrayItem* current = iUiFieldArray->Find(
       
  1776             aControlId);
       
  1777     MPbk2ContactEditorField* changedField = current->ContactEditorField();
       
  1778     __ASSERT_DEBUG(changedField, Panic(EHandleControlStateChangeL_NullField));
       
  1779     if (changedField && iNameFormatter->IsTitleField(
       
  1780             changedField->ContactField()))
       
  1781         {
       
  1782         UpdateTitleL();
       
  1783         }
       
  1784     }
       
  1785 
       
  1786 // --------------------------------------------------------------------------
       
  1787 // CPbk2ContactEditorDlgImpl::CreateLineL
       
  1788 // --------------------------------------------------------------------------
       
  1789 //
       
  1790 CCoeControl* CPbk2ContactEditorDlgImpl::CreateLineL
       
  1791         ( const TDesC& aCaption, TInt aControlId, TInt aControlType )
       
  1792     {
       
  1793     return CreateLineByTypeL( aCaption, aControlId, aControlType, NULL );
       
  1794     }
       
  1795 
       
  1796 // --------------------------------------------------------------------------
       
  1797 // CPbk2ContactEditorDlgImpl::LineControl
       
  1798 // --------------------------------------------------------------------------
       
  1799 //
       
  1800 CEikCaptionedControl* CPbk2ContactEditorDlgImpl::LineControl
       
  1801         ( TInt aControlId ) const
       
  1802     {
       
  1803     return Line( aControlId );
       
  1804     }
       
  1805 
       
  1806 // --------------------------------------------------------------------------
       
  1807 // CPbk2ContactEditorDlgImpl::DeleteControl
       
  1808 // --------------------------------------------------------------------------
       
  1809 //
       
  1810 void CPbk2ContactEditorDlgImpl::DeleteControl(TInt aControlId)
       
  1811     {
       
  1812     DeleteLine( aControlId );
       
  1813     }
       
  1814 
       
  1815 // --------------------------------------------------------------------------
       
  1816 // CPbk2ContactEditorDlgImpl::TryChangeFocusL
       
  1817 // --------------------------------------------------------------------------
       
  1818 //
       
  1819 void CPbk2ContactEditorDlgImpl::TryChangeFocusL(TInt aControlId)
       
  1820     {
       
  1821     //Ensure current line is set before trying to change focus
       
  1822     if(!CurrentLine())
       
  1823         {
       
  1824         SetInitialCurrentLine(); 
       
  1825         }
       
  1826 
       
  1827     //Attempt setting the focus
       
  1828     if ( ControlOrNull( aControlId ) )
       
  1829         {
       
  1830         TryChangeFocusToL( aControlId );
       
  1831         }
       
  1832     }
       
  1833 
       
  1834 // --------------------------------------------------------------------------
       
  1835 // CPbk2ContactEditorDlgImpl::SetCurrentLineCaptionL
       
  1836 // --------------------------------------------------------------------------
       
  1837 //
       
  1838 void CPbk2ContactEditorDlgImpl::SetCurrentLineCaptionL(const TDesC& aText)
       
  1839     {
       
  1840     SetControlCaptionL(IdOfFocusControl(), aText);
       
  1841     }
       
  1842 
       
  1843 // --------------------------------------------------------------------------
       
  1844 // CPbk2ContactEditorDlgImpl::Control
       
  1845 // --------------------------------------------------------------------------
       
  1846 //
       
  1847 CCoeControl* CPbk2ContactEditorDlgImpl::Control(TInt aControlId) const
       
  1848     {
       
  1849     return ControlOrNull(aControlId);
       
  1850     }
       
  1851 
       
  1852 // --------------------------------------------------------------------------
       
  1853 // CPbk2ContactEditorDlgImpl::SetEditableL
       
  1854 // --------------------------------------------------------------------------
       
  1855 //
       
  1856 void CPbk2ContactEditorDlgImpl::SetEditableL( TBool aState )
       
  1857     {
       
  1858     CAknForm::SetEditableL( aState );
       
  1859     }
       
  1860 
       
  1861 // --------------------------------------------------------------------------
       
  1862 // CPbk2ContactEditorDlgImpl::LoadBitmapToFieldL
       
  1863 // --------------------------------------------------------------------------
       
  1864 //
       
  1865 void CPbk2ContactEditorDlgImpl::LoadBitmapToFieldL
       
  1866         ( const MPbk2FieldProperty& aFieldProperty,
       
  1867           const CPbk2IconInfoContainer& aIconInfoContainer,
       
  1868           TInt aControlId )
       
  1869     {
       
  1870     CPbk2IconFactory* factory = CPbk2IconFactory::NewLC( aIconInfoContainer );
       
  1871     CEikImage* image = factory->CreateImageLC( aFieldProperty.IconId() );
       
  1872     
       
  1873     if ( image )
       
  1874         {
       
  1875         image->SetPictureOwnedExternally( EFalse );
       
  1876         image->CopyControlContextFrom( LineControl( aControlId ) );
       
  1877         image->SetContainerWindowL( *LineControl( aControlId ) );
       
  1878         image->SetNonFocusing();
       
  1879         image->SetBrushStyle( CGraphicsContext::ENullBrush );
       
  1880 
       
  1881         delete LineControl( aControlId )->iBitmap;
       
  1882         LineControl( aControlId )->iBitmap = image;
       
  1883         CleanupStack::Pop( image );
       
  1884 
       
  1885         TRect rect = LineControl( aControlId )->Rect();
       
  1886         rect.Resize( -1, -1 );
       
  1887         LineControl( aControlId )->SetRect( rect );
       
  1888         rect.Resize( 1, 1 );
       
  1889         LineControl( aControlId )->SetRect( rect );
       
  1890         }
       
  1891 
       
  1892     CleanupStack::PopAndDestroy( factory );
       
  1893     }
       
  1894 
       
  1895 // --------------------------------------------------------------------------
       
  1896 // CPbk2ContactEditorDlgImpl::ContactEditorOperationCompleted
       
  1897 // --------------------------------------------------------------------------
       
  1898 //
       
  1899 void CPbk2ContactEditorDlgImpl::ContactEditorOperationCompleted
       
  1900         ( MVPbkContactObserver::TContactOpResult aResult,
       
  1901           MPbk2ContactEditorEventObserver::TParams aParams )
       
  1902     {
       
  1903     iUseState = EUseFinished;
       
  1904     
       
  1905     // Notify extensions
       
  1906     iEditorExtension->ContactEditorOperationCompleted
       
  1907         ( aResult, aParams );
       
  1908 
       
  1909     switch ( aResult.iOpCode )
       
  1910         {
       
  1911         case MVPbkContactObserver::EContactOperationUnknown: // FALLTHROUGH
       
  1912             {
       
  1913             CloseDialog( aResult.iOpCode, ETrue );
       
  1914             break;
       
  1915             }
       
  1916         case MVPbkContactObserver::EContactCommit: // FALLTHROUGH
       
  1917         case MVPbkContactObserver::EContactDelete:
       
  1918             {
       
  1919             if ( aParams.iFlags & EPbk2EditorKeyCode &&
       
  1920                  aParams.iKeyCode == EAknSoftkeyDone )
       
  1921                 {
       
  1922                 CloseDialog( aResult.iOpCode, ETrue );
       
  1923                 }
       
  1924             else if ( ( aParams.iFlags & EPbk2EditorKeyCode &&
       
  1925                         aParams.iKeyCode == EEikBidCancel ) ||
       
  1926                      ( aParams.iFlags & EPbk2EditorCommandId &&
       
  1927                        aParams.iCommandId == EEikBidCancel ) ) 
       
  1928                 {
       
  1929                 if( iExitRecord.IsSet( EExitOrdered ) )
       
  1930                     {
       
  1931                     ExitApplication( aResult.iOpCode, EAknCmdExit );
       
  1932                     }
       
  1933                 else
       
  1934                     {
       
  1935                     CloseDialog( aResult.iOpCode, ETrue );
       
  1936                     }
       
  1937                 }
       
  1938             else if ( ( aParams.iFlags & EPbk2EditorCommandId ) &&
       
  1939                         ( ( aParams.iCommandId == EEikCmdExit ) ||
       
  1940                         ( aParams.iCommandId == EAknCmdExit ) ) )
       
  1941                 {
       
  1942                 ExitApplication( aResult.iOpCode, aParams.iCommandId );
       
  1943                 }
       
  1944             break;
       
  1945             }
       
  1946         default:
       
  1947             {
       
  1948             // Do nothing
       
  1949             break;
       
  1950             }
       
  1951         }
       
  1952     }
       
  1953 
       
  1954 // --------------------------------------------------------------------------
       
  1955 // CPbk2ContactEditorDlgImpl::CloseDialog
       
  1956 // --------------------------------------------------------------------------
       
  1957 //
       
  1958 void CPbk2ContactEditorDlgImpl::CloseDialog()
       
  1959 	{
       
  1960     // Ignor error and close editor without further user interaction
       
  1961     MVPbkContactObserver::TContactOpResult exitResult;
       
  1962     exitResult.iExtension = NULL;
       
  1963     exitResult.iStoreContact = NULL;
       
  1964     exitResult.iOpCode = MVPbkContactObserver::EContactDelete;
       
  1965     MPbk2ContactEditorEventObserver::TParams exitParams;
       
  1966     if ( iAvkonAppUi->ExitHidesInBackground() )
       
  1967         {
       
  1968         exitParams.iCommandId = 0;
       
  1969         exitParams.iFlags = EPbk2EditorKeyCode;
       
  1970         exitParams.iKeyCode = EAknSoftkeyDone;
       
  1971         }
       
  1972     else
       
  1973         {
       
  1974         exitParams.iCommandId = EAknCmdExit;
       
  1975         exitParams.iFlags = EPbk2EditorCommandId;
       
  1976         exitParams.iKeyCode = 0;
       
  1977           
       
  1978         iExitRecord.Set( EExitApproved );
       
  1979         iExitRecord.Set( EExitOrdered );
       
  1980         }
       
  1981       
       
  1982     ContactEditorOperationCompleted(exitResult, exitParams);
       
  1983 	}
       
  1984 
       
  1985 // --------------------------------------------------------------------------
       
  1986 // CPbk2ContactEditorDlgImpl::ContactEditorOperationFailed
       
  1987 // --------------------------------------------------------------------------
       
  1988 //
       
  1989 void CPbk2ContactEditorDlgImpl::ContactEditorOperationFailed
       
  1990         ( MVPbkContactObserver::TContactOp aOpCode,
       
  1991           TInt aErrorCode, MPbk2ContactEditorEventObserver::TParams aParams,
       
  1992           MPbk2ContactEditorEventObserver::TFailParams& aFailParams )
       
  1993     {
       
  1994     iUseState = EUseReady;
       
  1995     
       
  1996     if( iEndKeyWasPressed )
       
  1997     {
       
  1998     CloseDialog();
       
  1999     }
       
  2000     else
       
  2001     {
       
  2002     // Offer the failure to the extensions first
       
  2003     iEditorExtension->ContactEditorOperationFailed(aOpCode,
       
  2004         aErrorCode, aParams, aFailParams );
       
  2005 
       
  2006     // If extensions did not handle the error, handle it here
       
  2007     if ( !aFailParams.iErrorNotified )
       
  2008         {
       
  2009         CCoeEnv::Static()->HandleError( aErrorCode );
       
  2010         }
       
  2011 
       
  2012     if ( aFailParams.iErrorCode != KErrNone  )
       
  2013         {
       
  2014         TPbk2RelocationQyeryPolicy policy(
       
  2015             Pbk2ContactRelocator::EPbk2DisplayNoQueries );
       
  2016 
       
  2017         if ( aFailParams.iErrorCode == KErrNotSupported )
       
  2018             {
       
  2019             policy = Pbk2ContactRelocator::EPbk2DisplayStoreDoesNotSupportQuery;
       
  2020             }
       
  2021         else if ( aFailParams.iErrorCode == KErrGeneral )
       
  2022             {
       
  2023             policy = Pbk2ContactRelocator::EPbk2DisplayBasicQuery;
       
  2024             }
       
  2025         
       
  2026         TBool result( EFalse );
       
  2027         TRAPD( err, result = iRelocator.RelocateContactL( policy ) );
       
  2028         
       
  2029         if ( result )
       
  2030             {
       
  2031             // Do not close editor if contact need to relocate the first.
       
  2032             aFailParams.iCloseEditor = EFalse;
       
  2033             }
       
  2034                     
       
  2035         if ( err != KErrNone )
       
  2036             {
       
  2037             CCoeEnv::Static()->HandleError( err );
       
  2038             }
       
  2039         }
       
  2040     // Clear EExitOrdered to let next exit cmd available
       
  2041     iExitRecord.Clear(EExitOrdered);
       
  2042     if ( aFailParams.iCloseEditor )
       
  2043         {
       
  2044         CloseDialog( MVPbkContactObserver::EContactOperationUnknown, ETrue );
       
  2045             }
       
  2046         }
       
  2047     }
       
  2048 
       
  2049 // --------------------------------------------------------------------------
       
  2050 // CPbk2ContactEditorDlgImpl::RequestExitL
       
  2051 // --------------------------------------------------------------------------
       
  2052 //
       
  2053 void CPbk2ContactEditorDlgImpl::RequestExitL(TInt aCommandId)
       
  2054     {
       
  2055     if (iAddressView)
       
  2056         {
       
  2057         iAddressView->RequestExitL(aCommandId);
       
  2058         }
       
  2059     
       
  2060     if ( iUseState == EUseFinished )
       
  2061         {
       
  2062         ForceExit();
       
  2063         }
       
  2064     else if ( iUseState == EUseOperatingContact  )
       
  2065         {
       
  2066         iEditorStrategy.StopQuery();
       
  2067         iExitRecord.Set( EExitApproved );
       
  2068         iExitRecord.Set( EExitOrdered );
       
  2069         }
       
  2070     else
       
  2071         { 
       
  2072         if ( aCommandId == EKeyEscape )
       
  2073             {
       
  2074             iEndKeyWasPressed = ETrue;
       
  2075             OkToExitL( EAknSoftkeyDone );
       
  2076             // If iUseState is set EUseOperatingContact by above function 
       
  2077             if ( iUseState == EUseOperatingContact )
       
  2078                 {
       
  2079                 WaitFinishL();
       
  2080                 }
       
  2081             }
       
  2082         else
       
  2083             {
       
  2084             iExitRecord.Set( EExitApproved );
       
  2085             iExitRecord.Set( EExitOrdered );
       
  2086             MPbk2ContactEditorEventObserver::TParams params;
       
  2087             params.iFlags = EPbk2EditorCommandId;
       
  2088             params.iCommandId = aCommandId;
       
  2089             CmdDoneL( params );
       
  2090             }
       
  2091         }
       
  2092     }
       
  2093 
       
  2094 // --------------------------------------------------------------------------
       
  2095 // CPbk2ContactEditorDlgImpl::ForceExit
       
  2096 // --------------------------------------------------------------------------
       
  2097 //
       
  2098 void CPbk2ContactEditorDlgImpl::ForceExit()
       
  2099     {
       
  2100     iServiceCanceled = ETrue;
       
  2101     
       
  2102     if (iAddressView)
       
  2103         {
       
  2104         iAddressView->ForceExit();
       
  2105         }
       
  2106     
       
  2107     if ( iUseState == EUseOperatingContact )
       
  2108         {
       
  2109         iEditorStrategy.StopQuery();
       
  2110         iExitRecord.Set( EExitApproved );
       
  2111         iExitRecord.Set( EExitOrdered );
       
  2112         // It is ignored for dlg would exit
       
  2113         // Leave is not valuable
       
  2114         TRAP_IGNORE( WaitFinishL() );
       
  2115         }
       
  2116     else
       
  2117         {
       
  2118         iExitRecord.Set( EOkToExitWithoutHandlingIt );
       
  2119 
       
  2120         TRAPD( err, TryExitL( EAknSoftkeyBack ) );
       
  2121         if ( err != KErrNone )
       
  2122             {
       
  2123             // If not nicely then use the force
       
  2124             delete this;
       
  2125             }
       
  2126         }
       
  2127     }
       
  2128 
       
  2129 // --------------------------------------------------------------------------
       
  2130 // CPbk2ContactEditorDlgImpl::ResetWhenDestroyed
       
  2131 // --------------------------------------------------------------------------
       
  2132 //
       
  2133 void CPbk2ContactEditorDlgImpl::ResetWhenDestroyed
       
  2134         ( MPbk2DialogEliminator** aSelfPtr )
       
  2135     {
       
  2136     iSelfPtr = aSelfPtr;
       
  2137     }
       
  2138 
       
  2139 // --------------------------------------------------------------------------
       
  2140 // CPbk2ContactEditorDlgImpl::SetFocus
       
  2141 // --------------------------------------------------------------------------
       
  2142 //
       
  2143 void CPbk2ContactEditorDlgImpl::SetFocus(TInt aIndex)
       
  2144     {
       
  2145     TBool found = EFalse;
       
  2146     TInt count = 0;
       
  2147     TInt idx;
       
  2148     for (idx = 0; idx < iUiFieldArray->Count(); idx++)
       
  2149         {
       
  2150         if (iUiFieldArray->At(idx).ContactEditorField())
       
  2151             {
       
  2152             if (count == aIndex)
       
  2153                 {
       
  2154                 found = ETrue;
       
  2155                 break;
       
  2156                 }
       
  2157             count++;
       
  2158             }
       
  2159         }
       
  2160     if (found)
       
  2161         {
       
  2162         iUiFieldArray->SetFocus(idx);
       
  2163         }
       
  2164     }
       
  2165 
       
  2166 // --------------------------------------------------------------------------
       
  2167 // CPbk2ContactEditorDlgImpl::NumberOfControls
       
  2168 // --------------------------------------------------------------------------
       
  2169 //
       
  2170 TInt CPbk2ContactEditorDlgImpl::NumberOfControls() const
       
  2171     {
       
  2172     TInt count = 0;
       
  2173     for (TInt idx = 0; idx < iUiFieldArray->Count(); idx++)
       
  2174         {
       
  2175         if (iUiFieldArray->At(idx).ContactEditorField())
       
  2176             {
       
  2177             count++;
       
  2178             }
       
  2179         }
       
  2180     return count;
       
  2181     }
       
  2182 
       
  2183 // --------------------------------------------------------------------------
       
  2184 // CPbk2ContactEditorDlgImpl::IndexOfCtrlType
       
  2185 // --------------------------------------------------------------------------
       
  2186 //
       
  2187 TInt CPbk2ContactEditorDlgImpl::IndexOfCtrlType(TPbk2FieldCtrlType aType,
       
  2188         TInt& aIndex) const
       
  2189     {
       
  2190     TInt ret = KErrNotFound;
       
  2191     const TInt fieldCount = iUiFieldArray->Count();
       
  2192     for (TInt i = Max(aIndex, 0); i < fieldCount; ++i)
       
  2193         {
       
  2194         if (iUiFieldArray->At(i).ContactEditorField())
       
  2195             {
       
  2196             const MPbk2FieldProperty & property =
       
  2197                     iUiFieldArray->At(i).ContactEditorField()->FieldProperty();
       
  2198             if (property.CtrlType() == aType)
       
  2199                 {
       
  2200                 ret = i;
       
  2201                 break;
       
  2202                 }
       
  2203             }
       
  2204         }
       
  2205     return ret;
       
  2206     }
       
  2207 
       
  2208 // --------------------------------------------------------------------------
       
  2209 // CPbk2ContactEditorDlgImpl::AreAllControlsEmpty
       
  2210 // --------------------------------------------------------------------------
       
  2211 //
       
  2212 TBool CPbk2ContactEditorDlgImpl::AreAllControlsEmpty() const
       
  2213     {
       
  2214     return iUiFieldArray->AreAllUiFieldsEmpty();
       
  2215     }
       
  2216 
       
  2217 // --------------------------------------------------------------------------
       
  2218 // CPbk2ContactEditorDlgImpl::IsControlEmptyL
       
  2219 // --------------------------------------------------------------------------
       
  2220 //
       
  2221 TBool CPbk2ContactEditorDlgImpl::IsControlEmptyL(TInt aIndex) const
       
  2222     {
       
  2223     __ASSERT_DEBUG( iUiFieldArray->Count()> aIndex,
       
  2224             Panic( EPanic_IsControlEmptyL_OOB ) );
       
  2225     TBool ret = EFalse;
       
  2226     
       
  2227     // There are two types field controls in the edit dialog, one is the editor
       
  2228     // field control and the other is editor ui field control. The editor field 
       
  2229     // control are concreted field mapping to one field, it also can be divided
       
  2230     // into two types, custom control and normal control. The editor ui field 
       
  2231     // control are more like a container, currently only be used as the address
       
  2232     // container which can contain several editor field controls.
       
  2233     if ( iUiFieldArray->At(aIndex).ContactEditorField() )
       
  2234         {
       
  2235         // The custom control are special controls, like image, ring tone or date,
       
  2236         // they need use special way to judge if empty.
       
  2237         TBool empty = ETrue;
       
  2238         if( IsCustomControlEmptyL(aIndex, empty ) )
       
  2239             {
       
  2240             ret = empty;
       
  2241             }
       
  2242         // The control is normal editor field control.
       
  2243         else
       
  2244             {
       
  2245             ret = iUiFieldArray->IsEditorFieldControlEmpty( aIndex );
       
  2246             }
       
  2247         }
       
  2248     // If it's not an editor field control, judge if it's an editor ui field control.
       
  2249     else
       
  2250         {
       
  2251         // Check if contact editor ui field like address field is empty.
       
  2252         if ( iUiFieldArray->At( aIndex ).ContactEditorUIField() )
       
  2253             {
       
  2254             ret = iUiFieldArray->IsEditorUiFieldControlEmpty( aIndex );
       
  2255             }
       
  2256         }
       
  2257 
       
  2258 
       
  2259     return ret;
       
  2260     }
       
  2261 
       
  2262 // --------------------------------------------------------------------------
       
  2263 // CPbk2ContactEditorDlgImpl::IsCustomControlEmptyL
       
  2264 //
       
  2265 // Check emptiness of those fields that technically may contain data although
       
  2266 // in view of user and ui are considered as empty (e.g. "Add image" text)
       
  2267 // --------------------------------------------------------------------------
       
  2268 //
       
  2269 TBool CPbk2ContactEditorDlgImpl::IsCustomControlEmptyL(TInt aIndex, TBool& aRet) const
       
  2270     {
       
  2271     __ASSERT_DEBUG( iUiFieldArray->Count()> aIndex,
       
  2272             Panic( EPanic_IsControlEmptyL_OOB ) );
       
  2273     TBool isCustom(EFalse);
       
  2274     if (!iUiFieldArray->At(aIndex).ContactEditorField())
       
  2275         {
       
  2276         return isCustom;
       
  2277         }
       
  2278     MPbk2ContactEditorField& currentField =
       
  2279             *(iUiFieldArray->At(aIndex).ContactEditorField());
       
  2280     TPbk2FieldCtrlType type = currentField.FieldProperty().CtrlType();
       
  2281     TAny* ext = currentField.ContactEditorFieldExtension(TUid::Uid(NULL));
       
  2282 
       
  2283     if (type == EPbk2FieldCtrlTypeImageEditor && ext)
       
  2284         {
       
  2285         CPbk2ContactEditorImageField* fld =
       
  2286                 static_cast<CPbk2ContactEditorImageField*> (ext);
       
  2287         aRet = fld->TextState() == CPbk2ContactEditorImageField::ENoData;
       
  2288         isCustom = ETrue;
       
  2289         }
       
  2290     else if (type == EPbk2FieldCtrlTypeRingtoneEditor && ext)
       
  2291         {
       
  2292         CPbk2ContactEditorRingtoneField* fld =
       
  2293                 static_cast<CPbk2ContactEditorRingtoneField*> (ext);
       
  2294         aRet = fld->TextState() == CPbk2ContactEditorRingtoneField::ENoData;
       
  2295         isCustom = ETrue;
       
  2296         }
       
  2297     else if (type == EPbk2FieldCtrlTypeDateEditor)
       
  2298         {
       
  2299         // If contact has a date field, for index counting
       
  2300         // date editor field is considered as a custom control
       
  2301         // and it is not empty.
       
  2302         isCustom = ETrue;
       
  2303         aRet = EFalse;
       
  2304         }
       
  2305 
       
  2306     return isCustom;
       
  2307     }
       
  2308 // CPbk2ContactEditorDlgImpl::EditorField
       
  2309 // --------------------------------------------------------------------------
       
  2310 //
       
  2311 MPbk2ContactEditorField& CPbk2ContactEditorDlgImpl::EditorField(TInt aIndex) const
       
  2312     {
       
  2313     __ASSERT_DEBUG( iUiFieldArray->Count()> aIndex,
       
  2314             Panic( EPanic_EditorField_OOB ) );
       
  2315 
       
  2316     TBool found = EFalse;
       
  2317     TInt count = 0;
       
  2318     TInt idx;
       
  2319     for (idx = 0; idx < iUiFieldArray->Count(); idx++)
       
  2320         {
       
  2321         if (iUiFieldArray->At(idx).ContactEditorField())
       
  2322             {
       
  2323             if (count == aIndex)
       
  2324                 {
       
  2325                 found = ETrue;
       
  2326                 break;
       
  2327                 }
       
  2328             count++;
       
  2329             }
       
  2330         }
       
  2331 
       
  2332     __ASSERT_DEBUG( found,
       
  2333             Panic( EPanic_EditorField_OOB ) );
       
  2334     return *(iUiFieldArray->At(idx).ContactEditorField());
       
  2335     }
       
  2336 
       
  2337 // --------------------------------------------------------------------------
       
  2338 // CPbk2ContactEditorDlgImpl::StoreReady
       
  2339 // --------------------------------------------------------------------------
       
  2340 //
       
  2341 void CPbk2ContactEditorDlgImpl::StoreReady(MVPbkContactStore& /*aContactStore*/)
       
  2342     {
       
  2343     // Do nothing
       
  2344     }
       
  2345 
       
  2346 // --------------------------------------------------------------------------
       
  2347 // CPbk2ContactEditorDlgImpl::StoreUnavailable
       
  2348 // --------------------------------------------------------------------------
       
  2349 //
       
  2350 void CPbk2ContactEditorDlgImpl::StoreUnavailable
       
  2351     ( MVPbkContactStore& aContactStore, TInt /*aReason*/ )
       
  2352     {
       
  2353     if ( &aContactStore == &iContact.ParentStore() )
       
  2354         {
       
  2355         /*
       
  2356 		 * Use iAppServices if provided. This is to enable editor use outside from pbk2 context
       
  2357 		 */
       
  2358         const CPbk2StoreProperty* property = NULL;
       
  2359         if( iAppServices )
       
  2360         	{
       
  2361         	property =
       
  2362 					iAppServices->StoreProperties().FindProperty
       
  2363 							( aContactStore.StoreProperties().Uri() );
       
  2364         	}
       
  2365         else
       
  2366         	{
       
  2367         	property =
       
  2368 					Phonebook2::Pbk2AppUi()->ApplicationServices().
       
  2369 						StoreProperties().FindProperty
       
  2370 							( aContactStore.StoreProperties().Uri() );
       
  2371         	}
       
  2372         
       
  2373 
       
  2374         TPtrC storeName;
       
  2375         if ( property )
       
  2376             {
       
  2377             storeName.Set( property->StoreName() );
       
  2378             }
       
  2379 
       
  2380         // If this leaves the note is not shown.
       
  2381         // Cannot do anything about that
       
  2382         TRAP_IGNORE( ShowStoreNotAvailableNoteL( storeName ) );
       
  2383 
       
  2384         // Close editor if store which came unavailable is iContact's store
       
  2385         iContactObserver.ContactEditingAborted();
       
  2386         // TryExitL is not called because it would call OkToExitL
       
  2387         // which is not wanted
       
  2388         delete this;
       
  2389         }
       
  2390     }
       
  2391 
       
  2392 // --------------------------------------------------------------------------
       
  2393 // CPbk2ContactEditorDlgImpl::HandleStoreEventL
       
  2394 // --------------------------------------------------------------------------
       
  2395 //
       
  2396 void CPbk2ContactEditorDlgImpl::HandleStoreEventL(
       
  2397         MVPbkContactStore& /*aContactStore*/,
       
  2398         TVPbkContactStoreEvent /*aStoreEvent*/ )
       
  2399     {
       
  2400     // Do nothing
       
  2401     }
       
  2402 
       
  2403 // --------------------------------------------------------------------------
       
  2404 // CPbk2ContactEditorDlgImpl::LineChangedL
       
  2405 // --------------------------------------------------------------------------
       
  2406 //
       
  2407 void CPbk2ContactEditorDlgImpl::LineChangedL( TInt /*aControlId*/ )
       
  2408     {
       
  2409     SetCbaButtonsL();
       
  2410     }
       
  2411 
       
  2412 // --------------------------------------------------------------------------
       
  2413 // CPbk2ContactEditorDlgImpl::StoreTitlePaneTextL
       
  2414 // --------------------------------------------------------------------------
       
  2415 //
       
  2416 inline void CPbk2ContactEditorDlgImpl::StoreTitlePaneTextL()
       
  2417     {
       
  2418     CEikStatusPane* statusPane = iEikonEnv->AppUiFactory()->StatusPane();
       
  2419     if (statusPane && statusPane->PaneCapabilities(
       
  2420         TUid::Uid(EEikStatusPaneUidTitle)).IsPresent())
       
  2421         {
       
  2422         iTitlePane = static_cast<CAknTitlePane*>
       
  2423             (statusPane->ControlL(TUid::Uid(EEikStatusPaneUidTitle)));
       
  2424         if (iTitlePane->Text())
       
  2425             {
       
  2426             iStoredTitlePaneText = iTitlePane->Text()->AllocL();
       
  2427             }
       
  2428         }
       
  2429     }
       
  2430 
       
  2431 // --------------------------------------------------------------------------
       
  2432 // CPbk2ContactEditorDlgImpl::FocusedControlType
       
  2433 // --------------------------------------------------------------------------
       
  2434 //
       
  2435 TInt CPbk2ContactEditorDlgImpl::FocusedControlType()
       
  2436     {
       
  2437     CPbk2ContactEditorArrayItem* current = iUiFieldArray->Find(
       
  2438             IdOfFocusControl());
       
  2439     if (current && current->ContactEditorField())
       
  2440         {
       
  2441         return current->ContactEditorField()->FieldProperty().CtrlType();
       
  2442         }
       
  2443     else if (current && current->ContactEditorUIField())
       
  2444         {
       
  2445         return current->ContactEditorUIField()->UIField()->CtrlType();
       
  2446         }
       
  2447 
       
  2448     return EPbk2FieldCtrlTypeNone;
       
  2449     }
       
  2450 
       
  2451 // --------------------------------------------------------------------------
       
  2452 // CPbk2ContactEditorDlgImpl::ConstructContextMenuL
       
  2453 // --------------------------------------------------------------------------
       
  2454 //
       
  2455 inline void CPbk2ContactEditorDlgImpl::ConstructContextMenuL()
       
  2456     {
       
  2457     CEikMenuBar* newMenuBar = new ( ELeave ) CEikMenuBar();
       
  2458     CleanupStack::PushL( newMenuBar );
       
  2459     newMenuBar->ConstructL
       
  2460         ( this, NULL, R_PBK2_CONTACTEDITOR_CONTEXT_MENUBAR );
       
  2461     iEikonEnv->EikAppUi()->AddToStackL( newMenuBar, ECoeStackPriorityMenu,
       
  2462         ECoeStackFlagRefusesFocus );
       
  2463     iContextMenuBar = newMenuBar;
       
  2464     CleanupStack::Pop( newMenuBar );
       
  2465     iContextMenuBar->SetMenuType( CEikMenuBar::EMenuContext );
       
  2466     }
       
  2467 
       
  2468 // --------------------------------------------------------------------------
       
  2469 // CPbk2ContactEditorDlgImpl::ConstructNaviPaneL
       
  2470 // --------------------------------------------------------------------------
       
  2471 //
       
  2472 inline void CPbk2ContactEditorDlgImpl::ConstructNaviPaneL()
       
  2473     {
       
  2474     CEikStatusPane* statusPane = iEikonEnv->AppUiFactory()->StatusPane();
       
  2475     if (statusPane && statusPane->PaneCapabilities(TUid::Uid(
       
  2476             EEikStatusPaneUidNavi)).IsPresent())
       
  2477         {
       
  2478         // Create a default empty status pane, otherwise sync field will show
       
  2479         iNaviContainer
       
  2480                 = static_cast<CAknNavigationControlContainer *> (statusPane->ControlL(
       
  2481                         TUid::Uid(EEikStatusPaneUidNavi)));
       
  2482         iNaviContainer->PushDefaultL(ETrue);
       
  2483         }
       
  2484     }
       
  2485 
       
  2486 // --------------------------------------------------------------------------
       
  2487 // CPbk2ContactEditorDlgImpl::UpdateTitleL
       
  2488 // --------------------------------------------------------------------------
       
  2489 //
       
  2490 void CPbk2ContactEditorDlgImpl::UpdateTitleL()
       
  2491     {
       
  2492     if (iTitlePane)
       
  2493         {
       
  2494         HBufC* title = NULL;
       
  2495         switch (iParams.iActiveView)
       
  2496             {
       
  2497             case TPbk2ContactEditorParams::EEditorAddressView:
       
  2498             	if( !iTitleText )
       
  2499             		{
       
  2500             		title = StringLoader::LoadL(R_QTN_PHOB_HEADER_ADDRESS);
       
  2501             		}
       
  2502                 break;
       
  2503             case TPbk2ContactEditorParams::EEditorAddressHomeView:
       
  2504             	if( !iTitleText )
       
  2505             		{
       
  2506             		title = StringLoader::LoadL(
       
  2507             				R_QTN_PHOB_HEADER_ADDRESS_HOME);
       
  2508             		}
       
  2509                 break;
       
  2510             case TPbk2ContactEditorParams::EEditorAddressOfficeView:
       
  2511             	if( !iTitleText )
       
  2512             		{
       
  2513             		title = StringLoader::LoadL(
       
  2514             				R_QTN_PHOB_HEADER_ADDRESS_WORK);
       
  2515             		}
       
  2516                 break;
       
  2517             case TPbk2ContactEditorParams::EEditorView:
       
  2518                 {
       
  2519                 if ( !iStoreContact )
       
  2520                     {
       
  2521                     // Create the contact once
       
  2522                     iStoreContact = iContact.StoreContact().ParentStore().CreateNewContactLC();
       
  2523                     CleanupStack::Pop();
       
  2524                     }
       
  2525                     
       
  2526                 // Remove all fields before re-add
       
  2527                 iStoreContact->RemoveAllFields();
       
  2528                 
       
  2529                 const TInt fieldCount = iUiFieldArray->Count();
       
  2530                 for (TInt i = 0; i < fieldCount; ++i)
       
  2531                     {
       
  2532                     CPbk2ContactEditorArrayItem& item = iUiFieldArray->At(i);
       
  2533                     MPbk2ContactEditorField* uiField = item.ContactEditorField();
       
  2534                     if (uiField && iNameFormatter->IsTitleField(uiField->ContactField()))
       
  2535                         {
       
  2536                         HBufC* uiData = uiField->ControlTextL();
       
  2537                         if (uiData)
       
  2538                             {
       
  2539                             CleanupStack::PushL(uiData);
       
  2540                             const MVPbkFieldType& type =
       
  2541                                 uiField->FieldProperty().FieldType();
       
  2542                             MVPbkStoreContactField* field = iStoreContact->CreateFieldLC(type);
       
  2543                             MVPbkContactFieldTextData::Cast(
       
  2544                                 field->FieldData()).SetTextL(*uiData);
       
  2545                             iStoreContact->AddFieldL(field);
       
  2546                             CleanupStack::Pop(); // field
       
  2547                             CleanupStack::PopAndDestroy(uiData);
       
  2548                             }
       
  2549                         }
       
  2550                     }
       
  2551                 if( !iTitleText )
       
  2552                 	{
       
  2553                 	title = iNameFormatter->GetContactTitleOrNullL(iStoreContact->Fields(),
       
  2554                 			KEditorNameFormatFlags);
       
  2555                 	}
       
  2556                 break;
       
  2557                 }
       
  2558             default:
       
  2559                 break;
       
  2560             }
       
  2561         
       
  2562         // if custom title text is provided
       
  2563         if( iTitleText )
       
  2564         	{
       
  2565         	iTitlePane->SetTextL( iTitleText->Des() );
       
  2566         	}
       
  2567         else 
       
  2568         	{
       
  2569         	 if (title)
       
  2570 				{
       
  2571 				iTitlePane->SetText(title);
       
  2572 				}
       
  2573 			else
       
  2574 				{
       
  2575 				iTitlePane->SetTextL(iEditorStrategy.DefaultTitle());
       
  2576 				}
       
  2577         	}
       
  2578         }
       
  2579     }
       
  2580 
       
  2581 // --------------------------------------------------------------------------
       
  2582 // CPbk2ContactEditorDlgImpl::UpdateTitlePictureL
       
  2583 // --------------------------------------------------------------------------
       
  2584 //
       
  2585 void CPbk2ContactEditorDlgImpl::UpdateTitlePictureL()
       
  2586     {
       
  2587     if (iTitlePane)
       
  2588         {
       
  2589         // Update picture in title pane
       
  2590         
       
  2591         /*
       
  2592 		 * Use iAppServices if provided. This is to enable editor use outside from pbk2 context
       
  2593 		 */
       
  2594         CEikImage* image = NULL;
       
  2595         if( iAppServices )
       
  2596         	{
       
  2597         	image =
       
  2598 				Pbk2TitlePanePictureFactory::CreateTitlePanePictureLC
       
  2599 					( &iContact.StoreContact(),
       
  2600 							iAppServices->StoreProperties() );
       
  2601         	}
       
  2602         else
       
  2603         	{
       
  2604         	image =
       
  2605 				Pbk2TitlePanePictureFactory::CreateTitlePanePictureLC
       
  2606 					( &iContact.StoreContact(),
       
  2607 					  Phonebook2::Pbk2AppUi()->ApplicationServices().
       
  2608 						StoreProperties() );
       
  2609         	}
       
  2610         
       
  2611         
       
  2612         // ownership of the picture is transfered to title pane
       
  2613         image->SetPictureOwnedExternally( ETrue );
       
  2614         iTitlePane->SetSmallPicture(
       
  2615             image->Bitmap(), image->Mask(), image->Bitmap() != NULL );
       
  2616         // bitmap and mask from image were transfered to title pane,
       
  2617         // so image can be destroyed now
       
  2618         CleanupStack::PopAndDestroy( image );
       
  2619         }
       
  2620     }
       
  2621 
       
  2622 // --------------------------------------------------------------------------
       
  2623 // CPbk2ContactEditorDlgImpl::CloseDialog
       
  2624 // --------------------------------------------------------------------------
       
  2625 //
       
  2626 void CPbk2ContactEditorDlgImpl::CloseDialog(
       
  2627         MVPbkContactObserver::TContactOp aOpCode, TBool aInformObserver)
       
  2628     {
       
  2629     if (aInformObserver && iParams.iActiveView
       
  2630             == TPbk2ContactEditorParams::EEditorView || iAddressViewStandalone)
       
  2631         {
       
  2632         switch (aOpCode)
       
  2633             {
       
  2634             case MVPbkContactObserver::EContactOperationUnknown: // FALLTHROUGH
       
  2635             case MVPbkContactObserver::EContactCommit:
       
  2636                 {
       
  2637                 iContactObserver.ContactEditingComplete(
       
  2638                         &iContact.StoreContact());
       
  2639                 break;
       
  2640                 }
       
  2641             case MVPbkContactObserver::EContactDelete:
       
  2642                 {
       
  2643                 iContactObserver.ContactEditingDeletedContact(
       
  2644                         &iContact.StoreContact());
       
  2645                 break;
       
  2646                 }
       
  2647             default:
       
  2648                 {
       
  2649                 // Either end key was pressed or some uncommon scenario took place,
       
  2650                 // abort
       
  2651                 iContactObserver.ContactEditingAborted();
       
  2652                 break;
       
  2653                 }
       
  2654             };
       
  2655         }
       
  2656 
       
  2657     // Don't save any contact data (already saved)
       
  2658     iExitRecord.Set(EOkToExitWithoutHandlingIt);
       
  2659     iExitRecord.Clear(EExitOrdered);
       
  2660 
       
  2661     // Close dialog using TryExitL and returning ETrue from OkToExit
       
  2662     TInt err = KErrNone;
       
  2663         TRAP( err, TryExitL( EAknSoftkeyBack ) );
       
  2664     if (err != KErrNone)
       
  2665         {
       
  2666         // If not nicely then use the force.
       
  2667         delete this;
       
  2668         }
       
  2669     }
       
  2670 
       
  2671 // --------------------------------------------------------------------------
       
  2672 // CPbk2ContactEditorDlgImpl::ExitApplication
       
  2673 // --------------------------------------------------------------------------
       
  2674 //
       
  2675 void CPbk2ContactEditorDlgImpl::ExitApplication(
       
  2676         MVPbkContactObserver::TContactOp aOpCode,
       
  2677         TInt aCommandId )
       
  2678     {
       
  2679     if ( iExitRecord.IsSet( EExitOrdered ) &&
       
  2680          iExitRecord.IsSet( EExitApproved ) )
       
  2681         {
       
  2682 
       
  2683         CloseDialog( aOpCode, ETrue );
       
  2684 
       
  2685         // Dialog is closed so there is nothing to do if
       
  2686         // HandleCommandL leaves. 
       
  2687 		TRAP_IGNORE(CEikonEnv::Static()->EikAppUi()->HandleCommandL(aCommandId)); 
       
  2688         }
       
  2689     }
       
  2690 
       
  2691 // --------------------------------------------------------------------------
       
  2692 // CPbk2ContactEditorDlgImpl::CmdAddItemL
       
  2693 // --------------------------------------------------------------------------
       
  2694 //
       
  2695 void CPbk2ContactEditorDlgImpl::CmdAddItemL()
       
  2696     {
       
  2697     AddItemToContactL(KErrNotFound, KNullDesC);
       
  2698     }
       
  2699 
       
  2700 // --------------------------------------------------------------------------
       
  2701 // CPbk2ContactEditorDlgImpl::CmdDeleteItemL
       
  2702 // --------------------------------------------------------------------------
       
  2703 //
       
  2704 void CPbk2ContactEditorDlgImpl::CmdDeleteItemL()
       
  2705     {
       
  2706     TPbk2DeleteItemManager deleteItem( iContact, *iUiFieldArray, iAppServices );
       
  2707     if (deleteItem.DeleteFieldL(IdOfFocusControl()))
       
  2708         {
       
  2709         // Redraw using DrawNow, DrawDeferred does not get the job done
       
  2710         DrawNow();
       
  2711         }
       
  2712     }
       
  2713 
       
  2714 // --------------------------------------------------------------------------
       
  2715 // CPbk2ContactEditorDlgImpl::CmdEditItemLabelL
       
  2716 // --------------------------------------------------------------------------
       
  2717 //
       
  2718 void CPbk2ContactEditorDlgImpl::CmdEditItemLabelL()
       
  2719     {
       
  2720     CPbk2ContactEditorArrayItem* current = iUiFieldArray->Find(
       
  2721             IdOfFocusControl());
       
  2722     MPbk2ContactEditorField* field = current->ContactEditorField();
       
  2723     if (field && field->ContactField().SupportsLabel())
       
  2724         {
       
  2725         // Find out the presentation contact index and then label length
       
  2726         TInt fieldIndx = iContact.PresentationFields().FindFieldIndex(
       
  2727             field->ContactField() );
       
  2728         TInt maxLabelLength = iContact.PresentationFields().
       
  2729             FieldAt( fieldIndx ).MaxLabelLength();
       
  2730 
       
  2731         HBufC* textBuf = HBufC::NewLC(maxLabelLength);
       
  2732         TPtr text = textBuf->Des();
       
  2733         text.Copy(field->FieldLabel().Left(text.MaxLength()));
       
  2734         HBufC* prompt = StringLoader::LoadLC(R_QTN_FORM_PRMPT_FIELD_LABEL);
       
  2735 
       
  2736         CAknTextQueryDialog* dlg = CAknTextQueryDialog::NewL(text);
       
  2737         dlg->SetMaxLength(maxLabelLength);
       
  2738         if (dlg->ExecuteLD(R_PBK2_EDIT_FIELD_LABEL_QUERY, *prompt))
       
  2739             {
       
  2740             if (text != field->FieldLabel())
       
  2741                 {
       
  2742                 field->SetFieldLabelL(text);
       
  2743                 }
       
  2744             }
       
  2745         CleanupStack::PopAndDestroy(2); // prompt, textBuf
       
  2746         }
       
  2747     }
       
  2748 
       
  2749 // --------------------------------------------------------------------------
       
  2750 // CPbk2ContactEditorDlgImpl::IsUIDataChanged
       
  2751 // --------------------------------------------------------------------------
       
  2752 //
       
  2753 TBool CPbk2ContactEditorDlgImpl::IsUIDataChanged()
       
  2754     {
       
  2755     TInt count = iUiFieldArray->Count();
       
  2756     for(TInt idx1 = 0; idx1 < count; idx1++)
       
  2757         {
       
  2758         CPbk2ContactEditorArrayItem& item = iUiFieldArray->At(idx1);
       
  2759         if(item.ContactEditorField() && item.ContactEditorField()->FieldDataChanged())
       
  2760             {
       
  2761             return ETrue;
       
  2762             }
       
  2763         }
       
  2764     return EFalse;
       
  2765     }
       
  2766 
       
  2767 // --------------------------------------------------------------------------
       
  2768 // CPbk2ContactEditorDlgImpl::IsAddressValidated
       
  2769 // --------------------------------------------------------------------------
       
  2770 //
       
  2771 TBool CPbk2ContactEditorDlgImpl::IsAddressValidated(TPbk2FieldGroupId aGroupId)
       
  2772     {
       
  2773     CPbk2PresentationContactFieldCollection& fields = iContact.PresentationFields();
       
  2774     for(TInt idx = 0; idx < fields.FieldCount(); idx++)
       
  2775         {
       
  2776         MVPbkStoreContactField& field = fields.FieldAt(idx);
       
  2777         TInt countProps =
       
  2778             field.BestMatchingFieldType()->VersitProperties().Count();
       
  2779         TArray<TVPbkFieldVersitProperty> props =
       
  2780             field.BestMatchingFieldType()->VersitProperties();
       
  2781         for ( TInt idx2 = 0; idx2 < countProps; idx2++ )
       
  2782             {
       
  2783             if ( props[ idx2 ].Name() == EVPbkVersitNameGEO &&
       
  2784                  ( ( props[ idx2 ].Parameters().Contains( EVPbkVersitParamHOME ) &&
       
  2785                  aGroupId == EPbk2FieldGroupIdHomeAddress ) ||
       
  2786                    ( props[ idx2 ].Parameters().Contains( EVPbkVersitParamWORK ) &&
       
  2787                    aGroupId == EPbk2FieldGroupIdCompanyAddress ) ||
       
  2788                      ( !props[ idx2 ].Parameters().Contains( EVPbkVersitParamHOME ) &&
       
  2789                        !props[ idx2 ].Parameters().Contains( EVPbkVersitParamWORK ) &&
       
  2790                        aGroupId == EPbk2FieldGroupIdPostalAddress ) ) )
       
  2791                 {
       
  2792                 return ETrue;
       
  2793                 }
       
  2794             }
       
  2795         }
       
  2796     return EFalse;
       
  2797     }
       
  2798 
       
  2799 // --------------------------------------------------------------------------
       
  2800 // CPbk2ContactEditorDlgImpl::SetAddressValidationIconsL
       
  2801 // --------------------------------------------------------------------------
       
  2802 //
       
  2803 void CPbk2ContactEditorDlgImpl::SetAddressValidationIconsL()
       
  2804     {
       
  2805     TInt count = iUiFieldArray->Count();
       
  2806     for(TInt idx = 0; idx < count; idx++)
       
  2807         {
       
  2808         CPbk2ContactEditorArrayItem& uiItem = iUiFieldArray->At(idx);
       
  2809         MPbk2ContactEditorUIField* uiField = uiItem.ContactEditorUIField();
       
  2810         if(uiField)
       
  2811             {
       
  2812             switch(uiField->UIField()->CtrlType())
       
  2813                 {
       
  2814                 case EPbk2FieldCtrlTypeExtAddressEditor:
       
  2815                 case EPbk2FieldCtrlTypeExtAddressHomeEditor:
       
  2816                 case EPbk2FieldCtrlTypeExtAddressOfficeEditor:
       
  2817                     if(IsAddressValidated(Pbk2AddressTools::MapCtrlTypeToAddress(
       
  2818                             uiField->UIField()->CtrlType())))
       
  2819                         {
       
  2820                         TPbk2IconId iconID(TUid::Uid(KPbk2UID3), EPbk2qgn_prop_locev_map);
       
  2821                         uiField->LoadBitmapToFieldL(iconID);
       
  2822                         }
       
  2823                     else
       
  2824                         {
       
  2825                         TPbk2IconId iconID(TUid::Uid(KPbk2UID3), EPbk2qgn_prop_pb_no_valid_lm);
       
  2826                         uiField->LoadBitmapToFieldL(iconID);
       
  2827                         }
       
  2828                     break;
       
  2829                 case EPbk2FieldCtrlTypeExtAssignFromMapsEditor:
       
  2830                     if(IsAddressValidated( Pbk2AddressTools::MapViewTypeToAddress(iParams.iActiveView)))
       
  2831                         {
       
  2832                           TPbk2IconId iconID(TUid::Uid(KPbk2UID3), EPbk2qgn_prop_locev_map);
       
  2833                           uiField->LoadBitmapToFieldL(iconID);
       
  2834                           }
       
  2835                       else
       
  2836                           {
       
  2837                           TPbk2IconId iconID(TUid::Uid(KPbk2UID3), EPbk2qgn_prop_pb_no_valid_lm);
       
  2838                           uiField->LoadBitmapToFieldL(iconID);
       
  2839                           }
       
  2840                     break;  
       
  2841                 default:
       
  2842                     return;
       
  2843                 }
       
  2844             }
       
  2845         }
       
  2846     }
       
  2847 
       
  2848 // --------------------------------------------------------------------------
       
  2849 // CPbk2ContactEditorDlgImpl::DeleteActiveAddressGeoCoords
       
  2850 // --------------------------------------------------------------------------
       
  2851 //
       
  2852 void CPbk2ContactEditorDlgImpl::DeleteActiveAddressGeoCoords()
       
  2853     {
       
  2854     CPbk2PresentationContactFieldCollection& fields = iContact.PresentationFields();
       
  2855     for(TInt idx = 0; idx < fields.FieldCount(); idx++)
       
  2856         {
       
  2857         MVPbkStoreContactField& field = fields.FieldAt(idx);
       
  2858         TInt countProps =
       
  2859             field.BestMatchingFieldType()->VersitProperties().Count();
       
  2860         TArray<TVPbkFieldVersitProperty> props =
       
  2861             field.BestMatchingFieldType()->VersitProperties();
       
  2862         for ( TInt idx2 = 0; idx2 < countProps; idx2++ )
       
  2863             {
       
  2864             if ( props[ idx2 ].Name() == EVPbkVersitNameGEO &&
       
  2865                  ( ( props[ idx2 ].Parameters().Contains( EVPbkVersitParamHOME ) &&
       
  2866                  iParams.iActiveView ==
       
  2867                    TPbk2ContactEditorParams::EEditorAddressHomeView ) ||
       
  2868                    ( props[ idx2 ].Parameters().Contains( EVPbkVersitParamWORK ) &&
       
  2869                    iParams.iActiveView ==
       
  2870                      TPbk2ContactEditorParams::EEditorAddressOfficeView ) ||
       
  2871                      ( !props[ idx2 ].Parameters().Contains( EVPbkVersitParamHOME ) &&
       
  2872                        !props[ idx2 ].Parameters().Contains( EVPbkVersitParamWORK ) &&
       
  2873                        iParams.iActiveView ==
       
  2874                          TPbk2ContactEditorParams::EEditorAddressView ) ) )
       
  2875                 {
       
  2876                 iContact.RemoveField(idx);
       
  2877                 return;
       
  2878                 }
       
  2879             }
       
  2880         }
       
  2881     }
       
  2882 
       
  2883 // --------------------------------------------------------------------------
       
  2884 // CPbk2ContactEditorDlgImpl::CmdDoneL
       
  2885 // --------------------------------------------------------------------------
       
  2886 //
       
  2887 void CPbk2ContactEditorDlgImpl::CmdDoneL(
       
  2888         MPbk2ContactEditorEventObserver::TParams& aParams)
       
  2889     {
       
  2890     // The event that "end" key is pressed is informed into 
       
  2891     // CPsu2ContactEditorExtension to do some process
       
  2892     if( iEndKeyWasPressed )
       
  2893         {
       
  2894         iEditorExtension->ProcessCommandL( EAknCmdHideInBackground );
       
  2895         }
       
  2896     
       
  2897     // Saving/deleting is asynchronic so it is never to ok exit rightaway
       
  2898     // No need to save fields when all field are empty.
       
  2899     // To estimate dialog is a contact editor or a address dialog.  
       
  2900     // If it is address dialog, then save all field.
       
  2901     if (iUseState != EUseOperatingContact)
       
  2902         {
       
  2903         if ( !iUiFieldArray->AreAllUiFieldsEmpty() 
       
  2904                 || iParams.iActiveView == TPbk2ContactEditorParams::EEditorAddressView 
       
  2905                 || iParams.iActiveView == TPbk2ContactEditorParams::EEditorAddressHomeView
       
  2906                 || iParams.iActiveView == TPbk2ContactEditorParams::EEditorAddressOfficeView )
       
  2907             {
       
  2908             iUiFieldArray->SaveFieldsL();
       
  2909             }
       
  2910     
       
  2911         if(iParams.iActiveView != TPbk2ContactEditorParams::EEditorView && IsUIDataChanged() && 
       
  2912            IsAddressValidated(Pbk2AddressTools::MapViewTypeToAddress(iParams.iActiveView)))
       
  2913             {
       
  2914             if(iUiFieldArray->AreAllUiFieldsEmpty())
       
  2915                 {
       
  2916                 DeleteActiveAddressGeoCoords();
       
  2917                 }
       
  2918             else
       
  2919                 {
       
  2920                 HBufC* prompt = StringLoader::LoadLC(R_QTN_PHOB_CONFIRM_KEEP_COORDINATES);
       
  2921                 CAknQueryDialog* dlg = CAknQueryDialog::NewL();
       
  2922                 if(!dlg->ExecuteLD(R_PBK2_GENERAL_CONFIRMATION_QUERY, *prompt))
       
  2923                     {
       
  2924                     DeleteActiveAddressGeoCoords();
       
  2925                     }
       
  2926                 CleanupStack::PopAndDestroy( prompt );
       
  2927                 }
       
  2928             }
       
  2929         
       
  2930         TInt error(KErrNone);
       
  2931         if (iParams.iActiveView == TPbk2ContactEditorParams::EEditorView || 
       
  2932             iAddressViewStandalone)
       
  2933             {
       
  2934             // Estimate all field are empty by UI field.
       
  2935         if (( AreAllControlsEmpty() && !iAddressViewStandalone )||
       
  2936             (iAddressViewStandalone && AreAllFieldsEmpty()))
       
  2937                 {
       
  2938                 if (iEditorExtension->OkToDeleteContactL(aParams))
       
  2939                     {
       
  2940                     // iUseState must be set before DeleteContactL() because 
       
  2941                     // during deletion ForceExit() might be entered and needs to 
       
  2942                     // check the state to make sure operation finished.
       
  2943                     iUseState = EUseOperatingContact;
       
  2944 
       
  2945                     // If Endkey is pressed, no need of query dialog in DeleteContactL()
       
  2946                     if ( iEndKeyWasPressed )
       
  2947                         {
       
  2948                         aParams.iCommandId = EEikBidCancel;
       
  2949                         }
       
  2950 
       
  2951                     TRAP( error, iEditorStrategy.DeleteContactL( *this, aParams ) );
       
  2952 
       
  2953                     DecideToLeaveL( error );
       
  2954                     }
       
  2955                 }
       
  2956             else
       
  2957                 {
       
  2958                 iParams.iFocusedIndex = FocusedFieldIndexL();
       
  2959                 if (iEditorExtension->OkToSaveContactL(aParams))
       
  2960                     {
       
  2961                     iUseState = EUseOperatingContact;
       
  2962                     
       
  2963                     TRAP( error, iEditorStrategy.SaveContactL( *this, aParams ) );
       
  2964                 
       
  2965                     // Close the dialog if save contact fail caused by the
       
  2966                     // memory full
       
  2967                     if ( error == KErrDiskFull )
       
  2968                         {
       
  2969                         CloseDialog( MVPbkContactObserver::EContactCommit, ETrue );
       
  2970                         }
       
  2971                     
       
  2972                     DecideToLeaveL(error);
       
  2973                     }
       
  2974                 else
       
  2975                     {
       
  2976                     if ( iEndKeyWasPressed )
       
  2977                         {
       
  2978                         CloseDialog();
       
  2979                         }
       
  2980                     }
       
  2981                 }
       
  2982             }
       
  2983        else
       
  2984             {
       
  2985             CloseWithoutSaving(EFalse);
       
  2986             }
       
  2987         }
       
  2988     }
       
  2989 
       
  2990 // --------------------------------------------------------------------------
       
  2991 // CPbk2ContactEditorDlgImpl::FocusedFieldIndexL
       
  2992 // --------------------------------------------------------------------------
       
  2993 //
       
  2994 TInt CPbk2ContactEditorDlgImpl::FocusedFieldIndexL()
       
  2995     {
       
  2996     if( iAddressViewStandalone )
       
  2997         {
       
  2998         return KErrNotFound;
       
  2999         }
       
  3000     
       
  3001     const TInt idOfFocusedControl(IdOfFocusControl());
       
  3002     TInt fieldIndex(0);
       
  3003     const TInt count(iUiFieldArray->Count());
       
  3004     
       
  3005     for (TInt i(0); i < count; ++i)
       
  3006         {
       
  3007         CPbk2ContactEditorArrayItem& uiField = iUiFieldArray->At(i);
       
  3008 
       
  3009         if(uiField.ControlId() == idOfFocusedControl)
       
  3010             {
       
  3011             if( IsControlEmptyL(i) )
       
  3012                 {
       
  3013                 break;
       
  3014                 }
       
  3015             return fieldIndex;
       
  3016             }
       
  3017         else
       
  3018             {
       
  3019             if( !IsControlEmptyL(i) )
       
  3020                 {
       
  3021                 fieldIndex++;
       
  3022                 }
       
  3023             }
       
  3024         }
       
  3025     return KErrNotFound;
       
  3026     }
       
  3027 
       
  3028 // --------------------------------------------------------------------------
       
  3029 // CPbk2ContactEditorDlgImpl::SetCbaButtonsL
       
  3030 // --------------------------------------------------------------------------
       
  3031 //
       
  3032 void CPbk2ContactEditorDlgImpl::SetCbaButtonsL()
       
  3033     {
       
  3034     if ( AknLayoutUtils::MSKEnabled() )
       
  3035         {
       
  3036         TBool hideMsk(EFalse);
       
  3037 
       
  3038         if ( !iRelocator.IsPhoneMemoryInConfigurationL() )
       
  3039             {
       
  3040             if ( EmptyContextMenuL() )
       
  3041                 {
       
  3042                 hideMsk = ETrue;
       
  3043                 }
       
  3044             }
       
  3045 
       
  3046         ButtonGroupContainer().DimCommandByPosition(
       
  3047                 CEikButtonGroupContainer::EMiddleSoftkeyPosition,
       
  3048                 hideMsk );
       
  3049 
       
  3050         ButtonGroupContainer().MakeCommandVisibleByPosition(
       
  3051                 CEikButtonGroupContainer::EMiddleSoftkeyPosition,
       
  3052                 !hideMsk );
       
  3053 
       
  3054         ButtonGroupContainer().DrawDeferred();
       
  3055         }
       
  3056     }
       
  3057 
       
  3058 // --------------------------------------------------------------------------
       
  3059 // CPbk2ContactEditorDlgImpl::EmptyContextMenuL
       
  3060 // --------------------------------------------------------------------------
       
  3061 //
       
  3062 TBool CPbk2ContactEditorDlgImpl::EmptyContextMenuL()
       
  3063     {
       
  3064     TBool empty(EFalse);
       
  3065 
       
  3066     CPbk2ContactEditorArrayItem* current = iUiFieldArray->Find(
       
  3067             IdOfFocusControl());
       
  3068             
       
  3069     if( current )
       
  3070         {
       
  3071         MPbk2ContactEditorField* currentField = current->ContactEditorField();
       
  3072 
       
  3073         CArrayPtr<const MPbk2FieldProperty>* availableFields =
       
  3074             iContact.AvailableFieldsToAddL();
       
  3075 
       
  3076         if ( ( !currentField ||
       
  3077              ( currentField->FieldProperty().Flags()
       
  3078                & KPbk2FieldFlagCanNotBeRemoved ) ) &&
       
  3079              ( !currentField ||
       
  3080                !currentField->ContactField().SupportsLabel() ) &&
       
  3081              ( !availableFields || availableFields->Count() == 0 ) ) 
       
  3082             {
       
  3083             empty = ETrue;
       
  3084             }
       
  3085         delete availableFields;
       
  3086         }
       
  3087     else
       
  3088         {
       
  3089         empty = EFalse;
       
  3090         }
       
  3091 
       
  3092     return empty;
       
  3093     }
       
  3094 
       
  3095 // --------------------------------------------------------------------------
       
  3096 // CPbk2ContactEditorDlgImpl::OkToExitApplicationL
       
  3097 // --------------------------------------------------------------------------
       
  3098 //
       
  3099 TBool CPbk2ContactEditorDlgImpl::OkToExitApplicationL
       
  3100         ( TInt aCommandId )
       
  3101     {
       
  3102     TBool okToExit = ETrue;
       
  3103 
       
  3104     // If exit callback returned EFalse, the exit is cancelled
       
  3105     if ( iParams.iExitCallback &&
       
  3106          !iParams.iExitCallback->OkToExitL( aCommandId ) )
       
  3107         {
       
  3108         okToExit = EFalse;
       
  3109         }
       
  3110 
       
  3111     if ( !okToExit )
       
  3112         {
       
  3113         iExitRecord.Clear( EExitApproved );
       
  3114         }
       
  3115 
       
  3116     return okToExit;
       
  3117     }
       
  3118 
       
  3119 // --------------------------------------------------------------------------
       
  3120 // CPbk2ContactEditorDlgImpl::SetCbaCommandSetL
       
  3121 // --------------------------------------------------------------------------
       
  3122 //    
       
  3123 void CPbk2ContactEditorDlgImpl::SetCbaCommandSetL( TInt aResourceId )
       
  3124     {
       
  3125     CEikButtonGroupContainer& cba = ButtonGroupContainer();
       
  3126     cba.SetCommandSetL( aResourceId );
       
  3127     iCbaCommandSet = aResourceId;
       
  3128     cba.DrawDeferred();
       
  3129     }    
       
  3130 
       
  3131 // --------------------------------------------------------------------------
       
  3132 // CPbk2ContactEditorDlgImpl::UpdateCbasL
       
  3133 // --------------------------------------------------------------------------
       
  3134 //    
       
  3135 void CPbk2ContactEditorDlgImpl::UpdateCbasL(CPbk2ContactEditorArrayItem* aItemToUpdate)
       
  3136     {
       
  3137     CPbk2ContactEditorArrayItem* current = aItemToUpdate;
       
  3138     if(!current)
       
  3139         {
       
  3140         current = iUiFieldArray->Find(IdOfFocusControl());
       
  3141         }
       
  3142 
       
  3143     MPbk2ContactEditorField* currentField = current->ContactEditorField();
       
  3144     MPbk2ContactEditorUIField* currentUIField = current->ContactEditorUIField();
       
  3145     if ( currentField )
       
  3146         {
       
  3147         TPbk2FieldCtrlType type =
       
  3148             currentField->FieldProperty().CtrlType();
       
  3149         if (type == EPbk2FieldCtrlTypeImageEditor )
       
  3150             {
       
  3151             TInt id  = currentField->ControlId();  
       
  3152             TAny* ext = currentField->ContactEditorFieldExtension(TUid::Uid(NULL));
       
  3153             CPbk2ContactEditorImageField* fld = 
       
  3154                 static_cast<CPbk2ContactEditorImageField*>(ext);
       
  3155             if(fld->TextState() == CPbk2ContactEditorImageField::ENoData)
       
  3156                 {
       
  3157                 if ( iCbaCommandSet != R_PBK2_SOFTKEYS_OPTIONS_DONE_ADD )
       
  3158                     {
       
  3159                     SetCbaCommandSetL( R_PBK2_SOFTKEYS_OPTIONS_DONE_ADD  );   
       
  3160                     } 
       
  3161                 }
       
  3162             else
       
  3163                 {
       
  3164                 if ( iCbaCommandSet != R_PBK2_SOFTKEYS_OPTIONS_DONE_CHANGE )
       
  3165                     {
       
  3166                     SetCbaCommandSetL( R_PBK2_SOFTKEYS_OPTIONS_DONE_CHANGE  );   
       
  3167                     } 
       
  3168                 }
       
  3169             }
       
  3170         else if ( type == EPbk2FieldCtrlTypeChoiceItems ||
       
  3171                   type == EPbk2FieldCtrlTypeRingtoneEditor )
       
  3172             {
       
  3173             if ( iCbaCommandSet != R_PBK2_SOFTKEYS_OPTIONS_DONE_CHANGE )
       
  3174                 {
       
  3175                 SetCbaCommandSetL( R_PBK2_SOFTKEYS_OPTIONS_DONE_CHANGE  );   
       
  3176                 } 
       
  3177             }
       
  3178         else
       
  3179             {
       
  3180 #ifndef ECE_DISABLE_CONTEXT_MENU            
       
  3181             if ( iCbaCommandSet != R_PBK2_SOFTKEYS_OPTIONS_DONE_CONTEXT )
       
  3182                 {
       
  3183                 SetCbaCommandSetL( R_PBK2_SOFTKEYS_OPTIONS_DONE_CONTEXT );
       
  3184                 }
       
  3185 #else
       
  3186             if ( iCbaCommandSet != R_PBK2_SOFTKEYS_OPTIONS_DONE_EMPTY )
       
  3187                 {
       
  3188                 SetCbaCommandSetL( R_PBK2_SOFTKEYS_OPTIONS_DONE_EMPTY );
       
  3189                 }
       
  3190 #endif            
       
  3191             }
       
  3192         }
       
  3193    
       
  3194    if(currentUIField)
       
  3195        {
       
  3196        TPbk2FieldCtrlTypeExt type =
       
  3197            currentUIField->UIField()->CtrlType();
       
  3198        switch(type)
       
  3199            {
       
  3200            case EPbk2FieldCtrlTypeExtAddressEditor:
       
  3201            case EPbk2FieldCtrlTypeExtAddressHomeEditor:
       
  3202            case EPbk2FieldCtrlTypeExtAddressOfficeEditor:
       
  3203                if ( iCbaCommandSet != R_PBK2_SOFTKEYS_OPTIONS_DONE_CHANGE )
       
  3204                    {
       
  3205                    SetCbaCommandSetL( R_PBK2_SOFTKEYS_OPTIONS_DONE_CHANGE  );   
       
  3206                    } 
       
  3207                break;
       
  3208            case EPbk2FieldCtrlTypeExtAssignFromMapsEditor:
       
  3209                if ( iCbaCommandSet != R_PBK2_SOFTKEYS_OPTIONS_DONE_SELECT )
       
  3210                    {
       
  3211                    SetCbaCommandSetL( R_PBK2_SOFTKEYS_OPTIONS_DONE_SELECT  );   
       
  3212                    } 
       
  3213                break;
       
  3214            }
       
  3215        }
       
  3216 
       
  3217     // Offer button group container to extensions.
       
  3218     // This is needed here because previous settings might override extension's
       
  3219     // buttons.
       
  3220     iEditorExtension->ModifyButtonGroupContainerL(ButtonGroupContainer());
       
  3221     }
       
  3222 
       
  3223 // --------------------------------------------------------------------------
       
  3224 // CPbk2ContactEditorDlgImpl::ImageLoadingComplete
       
  3225 // --------------------------------------------------------------------------
       
  3226 //    
       
  3227 TInt CPbk2ContactEditorDlgImpl::ImageLoadingComplete()
       
  3228     {
       
  3229     TRAPD(err,DoImageLoadingCompleteL())
       
  3230     return err;
       
  3231     }
       
  3232 
       
  3233 // --------------------------------------------------------------------------
       
  3234 // CPbk2ContactEditorDlgImpl::DoImageLoadingCompleteL
       
  3235 // --------------------------------------------------------------------------
       
  3236 //    
       
  3237 void CPbk2ContactEditorDlgImpl::DoImageLoadingCompleteL()
       
  3238     {
       
  3239     CPbk2ContactEditorArrayItem* currentField =
       
  3240         iUiFieldArray->Find(IdOfFocusControl());
       
  3241     if (currentField && currentField->ContactEditorField())
       
  3242         {
       
  3243         TInt id  = currentField->ContactEditorField()->ControlId();  
       
  3244         TAny* ext = currentField->ContactEditorField()->ContactEditorFieldExtension(TUid::Uid(NULL));
       
  3245         if( id == EPbk2EditorLineImage )
       
  3246             {
       
  3247             CPbk2ContactEditorImageField* fld = 
       
  3248                 static_cast<CPbk2ContactEditorImageField*>(ext);
       
  3249             fld->SetTextL();
       
  3250             }
       
  3251         }
       
  3252     }
       
  3253 
       
  3254 // --------------------------------------------------------------------------
       
  3255 // CPbk2ContactEditorDlgImpl::ImageLoadingFailed
       
  3256 // --------------------------------------------------------------------------
       
  3257 //    
       
  3258 TInt CPbk2ContactEditorDlgImpl::ImageLoadingFailed() 
       
  3259     {
       
  3260     return KErrNone;
       
  3261     }
       
  3262 // --------------------------------------------------------------------------
       
  3263 // CPbk2ContactEditorDlgImpl::ImageLoadingCancelled
       
  3264 // --------------------------------------------------------------------------
       
  3265 //    
       
  3266 TInt CPbk2ContactEditorDlgImpl::ImageLoadingCancelled() 
       
  3267     {
       
  3268     return KErrNone;
       
  3269     }
       
  3270 
       
  3271 // --------------------------------------------------------------------------
       
  3272 // CPbk2ContactEditorDlgImpl::WaitFinish
       
  3273 // --------------------------------------------------------------------------
       
  3274 //    
       
  3275 void CPbk2ContactEditorDlgImpl::WaitFinishL()
       
  3276     {
       
  3277     if ( !iWaitFinish && *iSelfPtr )
       
  3278         {
       
  3279         iInputBlock = CAknInputBlock::NewLC();
       
  3280         CleanupStack::Pop( iInputBlock );
       
  3281         
       
  3282         iWaitFinish = new (ELeave) CActiveSchedulerWait();
       
  3283         iWaitFinish->Start();
       
  3284         }
       
  3285     }
       
  3286 
       
  3287 // End of File