phonebookui/Phonebook2/UIControls/src/CPbk2ContactEditorDlgImpl.cpp
branchRCL_3
changeset 85 38bb213f60ba
parent 74 6b5524b4f673
equal deleted inserted replaced
74:6b5524b4f673 85:38bb213f60ba
    34 #include <CPbk2PresentationContactField.h>
    34 #include <CPbk2PresentationContactField.h>
    35 #include <CPbk2PresentationContactFieldCollection.h>
    35 #include <CPbk2PresentationContactFieldCollection.h>
    36 #include <MPbk2FieldProperty.h>
    36 #include <MPbk2FieldProperty.h>
    37 #include <MPbk2FieldProperty2.h>
    37 #include <MPbk2FieldProperty2.h>
    38 #include <CPbk2FieldPropertyArray.h>
    38 #include <CPbk2FieldPropertyArray.h>
    39 #include <pbk2uicontrols.rsg>
    39 #include <Pbk2UIControls.rsg>
    40 #include <MPbk2ContactNameFormatter.h>
    40 #include <MPbk2ContactNameFormatter.h>
    41 #include <MPbk2ContactEditorExtension.h>
    41 #include <MPbk2ContactEditorExtension.h>
    42 #include <CPbk2StoreConfiguration.h>
    42 #include <CPbk2StoreConfiguration.h>
    43 #include <CPbk2ContactRelocator.h>
    43 #include <CPbk2ContactRelocator.h>
    44 #include <MPbk2ContactEditorEventObserver.h>
    44 #include <MPbk2ContactEditorEventObserver.h>
    68 #include "Pbk2FieldProperty.hrh"
    68 #include "Pbk2FieldProperty.hrh"
    69 #include "Pbk2IconId.hrh"
    69 #include "Pbk2IconId.hrh"
    70 #include <Pbk2UID.h>
    70 #include <Pbk2UID.h>
    71 #include <pbk2mapcommands.hrh>
    71 #include <pbk2mapcommands.hrh>
    72 #include <MPbk2StartupMonitor.h>
    72 #include <MPbk2StartupMonitor.h>
    73 #include <featmgr.h>
       
    74 
    73 
    75 // Virtual Phonebook
    74 // Virtual Phonebook
    76 #include <CVPbkContactManager.h>
    75 #include <CVPbkContactManager.h>
    77 #include <MVPbkStoreContact.h>
    76 #include <MVPbkStoreContact.h>
    78 #include <MVPbkContactStore.h>
    77 #include <MVPbkContactStore.h>
    80 #include <MVPbkContactStoreProperties.h>
    79 #include <MVPbkContactStoreProperties.h>
    81 #include <MVPbkContactFieldData.h>
    80 #include <MVPbkContactFieldData.h>
    82 #include <MVPbkFieldType.h>
    81 #include <MVPbkFieldType.h>
    83 #include <TVPbkFieldVersitProperty.h>
    82 #include <TVPbkFieldVersitProperty.h>
    84 
    83 
    85 #include <vpbkeng.rsg> 
    84 #include <VPbkEng.rsg> 
    86 #include <VPbkFieldType.hrh>
    85 #include <VPbkFieldType.hrh>
    87 #include <VPbkContactStoreUris.h>
    86 #include <VPbkContactStoreUris.h>
    88 
    87 
    89 // System includes
    88 // System includes
    90 #include <akntitle.h>
    89 #include <akntitle.h>
    95 #include <aknnotewrappers.h>
    94 #include <aknnotewrappers.h>
    96 #include <hlplch.h>
    95 #include <hlplch.h>
    97 #include <aknnavide.h>
    96 #include <aknnavide.h>
    98 #include <akninputblock.h>
    97 #include <akninputblock.h>
    99 #include <charconv.h>
    98 #include <charconv.h>
   100 #include <aknpriv.hrh>
       
   101 
    99 
   102 /// Unnamed namespace for local definitions
   100 /// Unnamed namespace for local definitions
   103 namespace {
   101 namespace {
   104 
   102 
   105 const TInt KEditorNameFormatFlags = MPbk2ContactNameFormatter::EUseSeparator;
   103 const TInt KEditorNameFormatFlags = MPbk2ContactNameFormatter::EUseSeparator;
   175         iContactObserver( aContactObserver ),
   173         iContactObserver( aContactObserver ),
   176         iRelocator( aRelocator ),
   174         iRelocator( aRelocator ),
   177         iEndKeyWasPressed( EFalse ),
   175         iEndKeyWasPressed( EFalse ),
   178         iAddressViewStandalone( EFalse ),
   176         iAddressViewStandalone( EFalse ),
   179         iAppServices( aAppServices ),
   177         iAppServices( aAppServices ),
   180         iTitleText( aTitleText ),
   178         iTitleText( aTitleText )
   181         iExitApp( EFalse ),
       
   182         iIsInputPaneOpen( EFalse )
       
   183     {
   179     {
   184     // Exit is approved by default
   180     // Exit is approved by default
   185     iExitRecord.Set( EExitApproved );
   181     iExitRecord.Set( EExitApproved );
   186     }
   182     }
   187 
   183 
   203     if ( iSelfPtr )
   199     if ( iSelfPtr )
   204         {
   200         {
   205         *iSelfPtr = NULL;
   201         *iSelfPtr = NULL;
   206         }
   202         }
   207     // Make the variable in CloseDialog() to ETrue.
   203     // Make the variable in CloseDialog() to ETrue.
   208     if ( iDestroyedPtrForCloseDlg )
   204     if ( iDestroyedPtr )
   209         {
   205         {
   210         *iDestroyedPtrForCloseDlg = ETrue;
   206         *iDestroyedPtr = ETrue;
   211         }
       
   212     
       
   213     // Make the variable in AddItemToContactL() to ETrue.
       
   214     if ( iDestroyedPtrForAddItem )
       
   215         {
       
   216         *iDestroyedPtrForAddItem = ETrue;
       
   217         }
   207         }
   218     
   208     
   219     if( iAppServices )
   209     if( iAppServices )
   220         {
   210     	{
   221         iAppServices->StoreObservationRegister().DeregisterStoreEvents( *this );
   211     	iAppServices->StoreObservationRegister().DeregisterStoreEvents( *this );
   222         }
   212     	}
   223     else
   213     else
   224         {
   214     	{
   225         Phonebook2::Pbk2AppUi()->ApplicationServices().
   215     	Phonebook2::Pbk2AppUi()->ApplicationServices().
   226                 StoreObservationRegister().DeregisterStoreEvents( *this );
   216     	        StoreObservationRegister().DeregisterStoreEvents( *this );
   227         }
   217     	}
   228               
   218               
   229     if ( iEikonEnv && iContextMenuBar )
   219     if ( iEikonEnv && iContextMenuBar )
   230         {
   220         {
   231         iEikonEnv->EikAppUi()->RemoveFromStack( iContextMenuBar );
   221         iEikonEnv->EikAppUi()->RemoveFromStack( iContextMenuBar );
   232         delete iContextMenuBar;
   222         delete iContextMenuBar;
   236 
   226 
   237     // Remove empty status pane
   227     // Remove empty status pane
   238     if (iNaviContainer)
   228     if (iNaviContainer)
   239         {
   229         {
   240         iNaviContainer->Pop();
   230         iNaviContainer->Pop();
   241         TRAP_IGNORE(RestorePrevNaviDecoratorL());
   231         TRAP_IGNORE(RestorePrevNaviDecoratorL());        
   242         }
   232         }
   243 
   233 
   244     delete iStoreContact;
   234     delete iStoreContact;
   245     delete iFieldFactory;
   235     delete iFieldFactory;
   246     delete iPbk2BaseCommand;
   236     delete iPbk2BaseCommand;
   247     delete iEditorExtension;
   237     delete iEditorExtension;
   248     delete iUiFieldArray;
   238     delete iUiFieldArray;
   249     Release(iExtensionManager);
   239     Release(iExtensionManager);
   250     delete iTitleText;    
   240 	delete iTitleText;    
   251     iTitleText = NULL;
   241     iTitleText = NULL;
   252     delete iStoredTitlePaneText;
   242     delete iStoredTitlePaneText;
   253     iStoredTitlePaneText = NULL;
   243     iStoredTitlePaneText = NULL;
   254 
   244 
   255     delete iConverter;
   245     delete iConverter;
   256     delete iDelayDelete;
       
   257     
       
   258     // The if-expression is used here to Exit Phonebook2 for the case 
       
   259     // that Exit phonebook2 with the EditorDlg opened.
       
   260     if ( iExitApp )
       
   261         {
       
   262         TRAP_IGNORE( ((CAknViewAppUi*)CEikonEnv::Static()->EikAppUi())->ProcessCommandL( EAknCmdExit ) );
       
   263         }
       
   264     }
   246     }
   265 
   247 
   266 // --------------------------------------------------------------------------
   248 // --------------------------------------------------------------------------
   267 // CPbk2ContactEditorDlgImpl::NewL
   249 // CPbk2ContactEditorDlgImpl::NewL
   268 // --------------------------------------------------------------------------
   250 // --------------------------------------------------------------------------
   272         CPbk2PresentationContact& aContact,
   254         CPbk2PresentationContact& aContact,
   273         CPbk2FieldPropertyArray& aFieldProperties,
   255         CPbk2FieldPropertyArray& aFieldProperties,
   274         MPbk2EditedContactObserver& aContactObserver,
   256         MPbk2EditedContactObserver& aContactObserver,
   275         MPbk2ContactEditorStrategy& aEditorStrategy,
   257         MPbk2ContactEditorStrategy& aEditorStrategy,
   276         MPbk2ContactEditorContactRelocator& aRelocator)
   258         MPbk2ContactEditorContactRelocator& aRelocator)
   277     {    
   259     {	
   278     CPbk2ContactEditorDlgImpl* self =
   260     CPbk2ContactEditorDlgImpl* self =
   279         new ( ELeave ) CPbk2ContactEditorDlgImpl(aParams, aContact,
   261         new ( ELeave ) CPbk2ContactEditorDlgImpl(aParams, aContact,
   280             aFieldProperties, aContactObserver,
   262             aFieldProperties, aContactObserver,
   281             aEditorStrategy, aRelocator);
   263             aEditorStrategy, aRelocator);
   282     CleanupStack::PushL(self);
   264     CleanupStack::PushL(self);
   288 // --------------------------------------------------------------------------
   270 // --------------------------------------------------------------------------
   289 // CPbk2ContactEditorDlgImpl::NewL
   271 // CPbk2ContactEditorDlgImpl::NewL
   290 // --------------------------------------------------------------------------
   272 // --------------------------------------------------------------------------
   291 //
   273 //
   292 CPbk2ContactEditorDlgImpl* CPbk2ContactEditorDlgImpl::NewL(
   274 CPbk2ContactEditorDlgImpl* CPbk2ContactEditorDlgImpl::NewL(
   293         TPbk2ContactEditorParams& aParams,
   275 		TPbk2ContactEditorParams& aParams,
   294         CPbk2PresentationContact& aContact,
   276 		CPbk2PresentationContact& aContact,
   295         CPbk2FieldPropertyArray& aFieldProperties,
   277 		CPbk2FieldPropertyArray& aFieldProperties,
   296         MPbk2EditedContactObserver& aContactObserver,
   278 		MPbk2EditedContactObserver& aContactObserver,
   297         MPbk2ContactEditorStrategy& aEditorStrategy,
   279 		MPbk2ContactEditorStrategy& aEditorStrategy,
   298         MPbk2ContactEditorContactRelocator& aRelocator,
   280 		MPbk2ContactEditorContactRelocator& aRelocator,
   299         MPbk2ApplicationServices* aAppServices,
   281 		MPbk2ApplicationServices* aAppServices,
   300         HBufC* aTitleText )
   282 		HBufC* aTitleText )
   301     {
   283 	{
   302     CPbk2ContactEditorDlgImpl* self =
   284 	CPbk2ContactEditorDlgImpl* self =
   303         new ( ELeave ) CPbk2ContactEditorDlgImpl(aParams, aContact,
   285 		new ( ELeave ) CPbk2ContactEditorDlgImpl(aParams, aContact,
   304             aFieldProperties, aContactObserver,
   286 			aFieldProperties, aContactObserver,
   305             aEditorStrategy, aRelocator, aAppServices, aTitleText );
   287 			aEditorStrategy, aRelocator, aAppServices, aTitleText );
   306     CleanupStack::PushL(self);
   288 	CleanupStack::PushL(self);
   307     self->ConstructL();
   289 	self->ConstructL();
   308     CleanupStack::Pop(self);
   290 	CleanupStack::Pop(self);
   309     return self;
   291 	return self;
   310     }
   292 	}
   311 
   293 
   312 // --------------------------------------------------------------------------
   294 // --------------------------------------------------------------------------
   313 // CPbk2ContactEditorDlgImpl::ConstructL
   295 // CPbk2ContactEditorDlgImpl::ConstructL
   314 // --------------------------------------------------------------------------
   296 // --------------------------------------------------------------------------
   315 //
   297 //
   351     
   333     
   352     // Register to listen store events, so that we can close editor if
   334     // Register to listen store events, so that we can close editor if
   353     // iContact's store becomes unavailable.
   335     // iContact's store becomes unavailable.
   354     
   336     
   355     /*
   337     /*
   356      * Use iAppServices if provided. This is to enable editor use outside from pbk2 context
   338 	 * Use iAppServices if provided. This is to enable editor use outside from pbk2 context
   357      */
   339 	 */
   358     if( iAppServices )
   340     if( iAppServices )
   359         {
   341     	{
   360         iAppServices->StoreObservationRegister().RegisterStoreEventsL( *this );
   342     	iAppServices->StoreObservationRegister().RegisterStoreEventsL( *this );
   361         iNameFormatter = &iAppServices->NameFormatter();
   343     	iNameFormatter = &iAppServices->NameFormatter();
   362         }
   344     	}
   363     else
   345     else
   364         {
   346     	{
   365         Phonebook2::Pbk2AppUi()->ApplicationServices().
   347     	Phonebook2::Pbk2AppUi()->ApplicationServices().
   366             StoreObservationRegister().RegisterStoreEventsL( *this );
   348 			StoreObservationRegister().RegisterStoreEventsL( *this );
   367         iNameFormatter =
   349     	iNameFormatter =
   368                 &Phonebook2::Pbk2AppUi()->ApplicationServices().NameFormatter();
   350     	        &Phonebook2::Pbk2AppUi()->ApplicationServices().NameFormatter();
   369         }
   351     	}
   370 
   352 
   371    
   353    
   372     StoreTitlePaneTextL();
   354     StoreTitlePaneTextL();
   373     ConstructContextMenuL();
   355     ConstructContextMenuL();
   374 
   356 
   375     iExtensionManager = CPbk2UIExtensionManager::InstanceL();
   357     iExtensionManager = CPbk2UIExtensionManager::InstanceL();
   376     
   358     
   377     /*
   359     /*
   378      * Use iAppServices if provided. This is to enable editor use outside from pbk2 context
   360 	 * Use iAppServices if provided. This is to enable editor use outside from pbk2 context
   379      */
   361 	 */
   380     CVPbkContactManager* manager = NULL;
   362     CVPbkContactManager* manager = NULL;
   381     if( iAppServices )
   363     if( iAppServices )
   382         {
   364     	{
   383         manager = &iAppServices->ContactManager();
   365     	manager = &iAppServices->ContactManager();
   384         }
   366     	}
   385     else
   367     else
   386         {
   368     	{
   387         manager = &Phonebook2::Pbk2AppUi()->ApplicationServices().ContactManager();
   369     	manager = &Phonebook2::Pbk2AppUi()->ApplicationServices().ContactManager();
   388         }
   370     	}
   389     
   371     
   390     iEditorExtension = iExtensionManager->FactoryL()->
   372     iEditorExtension = iExtensionManager->FactoryL()->
   391         CreatePbk2ContactEditorExtensionL( *manager, iContact, *this );
   373         CreatePbk2ContactEditorExtensionL( *manager, iContact, *this );
   392 
   374 
   393     iFieldFactory = CPbk2ContactEditorFieldFactory::NewL(*this, *iEditorExtension);
   375     iFieldFactory = CPbk2ContactEditorFieldFactory::NewL(*this, *iEditorExtension);
   394     iUiFieldArray = CPbk2ContactEditorFieldArray::NewL(
   376     iUiFieldArray = CPbk2ContactEditorFieldArray::NewL(
   395     *manager, iContact, *this, *iFieldFactory, iAppServices );    
   377     *manager, iContact, *this, *iFieldFactory, iAppServices );	
   396     
   378     
   397     iUseState = EUseReady;
   379     iUseState = EUseReady;
   398     }
   380     }
   399 
   381 
   400 // --------------------------------------------------------------------------
   382 // --------------------------------------------------------------------------
   510 // CPbk2ContactEditorDlgImpl::HandleResourceChange
   492 // CPbk2ContactEditorDlgImpl::HandleResourceChange
   511 // --------------------------------------------------------------------------
   493 // --------------------------------------------------------------------------
   512 //
   494 //
   513 void CPbk2ContactEditorDlgImpl::HandleResourceChange( TInt aType )
   495 void CPbk2ContactEditorDlgImpl::HandleResourceChange( TInt aType )
   514     {
   496     {
   515     switch ( aType )
   497     // Handle change in layout orientation
   516         {
   498     if ( aType == KEikDynamicLayoutVariantSwitch )
   517         case KEikDynamicLayoutVariantSwitch: // Handle change in layout orientation
   499         {
   518             {
   500         // Set status pane layout to the Phonebook 2 one
   519             // Set status pane layout to the Phonebook 2 one
   501         CEikStatusPane* statusPane = iAvkonAppUi->StatusPane();
   520             CEikStatusPane* statusPane = iAvkonAppUi->StatusPane();
   502         if ( statusPane )
   521             if ( statusPane )
   503             {
   522                 {
   504             iCurrentstatuspane = statusPane->CurrentLayoutResId();
   523                 iCurrentstatuspane = statusPane->CurrentLayoutResId();
   505             if( iCurrentstatuspane != R_AVKON_STATUS_PANE_LAYOUT_USUAL )
   524                 if( iCurrentstatuspane != R_AVKON_STATUS_PANE_LAYOUT_USUAL )
   506                 {
   525                     {
   507                 TRAP_IGNORE( statusPane->SwitchLayoutL(R_AVKON_STATUS_PANE_LAYOUT_USUAL) );
   526                     TRAP_IGNORE( 
   508                 }
   527                         statusPane->SwitchLayoutL(
   509             }
   528                             R_AVKON_STATUS_PANE_LAYOUT_USUAL )
       
   529                         );
       
   530                     }
       
   531                 }
       
   532             }
       
   533             break;
       
   534         case KAknSplitInputEnabled:     // Handle split input keyboard
       
   535             {
       
   536             // Sometimes this function will be called continuously
       
   537             // with the same parameter.
       
   538             // Add a flag iIsInputPaneOpen to ensure the dialog
       
   539             // only draw one time.
       
   540             if( !iIsInputPaneOpen )
       
   541                 {
       
   542                 Layout();
       
   543                 DrawNow();
       
   544                 iIsInputPaneOpen = ETrue;
       
   545                 }
       
   546             }
       
   547             break;
       
   548         case KAknSplitInputDisabled:
       
   549             {
       
   550             // Sometimes this function will be called continuously
       
   551             // with the same parameter.
       
   552             // Add a flag iIsInputPaneOpen to ensure the dialog
       
   553             // only draw one time.
       
   554             if( iIsInputPaneOpen )
       
   555                 {
       
   556                 // Set status pane layout to the Phonebook 2 one
       
   557                 Layout();
       
   558                 DrawNow();
       
   559                 CEikStatusPane* statusPane = iAvkonAppUi->StatusPane();
       
   560                 if ( statusPane )
       
   561                     {
       
   562                     TRAP_IGNORE(
       
   563                             statusPane->SwitchLayoutL(
       
   564                                     R_AVKON_STATUS_PANE_LAYOUT_USUAL )
       
   565                         );
       
   566                     }
       
   567                 iIsInputPaneOpen = EFalse;
       
   568                 }
       
   569             }
       
   570             break;
       
   571         default:
       
   572             break;
       
   573         }
   510         }
   574     
   511     
   575     CAknForm::HandleResourceChange( aType );
   512     CAknForm::HandleResourceChange( aType );
   576     }
   513     }
   577 
   514 
   582 void CPbk2ContactEditorDlgImpl::AddItemToContactL
   519 void CPbk2ContactEditorDlgImpl::AddItemToContactL
   583       ( TInt aFieldTypeResourceId,
   520       ( TInt aFieldTypeResourceId,
   584         const TDesC& aFieldTypeXspName, 
   521         const TDesC& aFieldTypeXspName, 
   585         TBool aSetFocus )
   522         TBool aSetFocus )
   586     {
   523     {
   587     // For knowing whether the destructor has been called
       
   588     TBool destroyed = EFalse;
       
   589     iDestroyedPtrForAddItem = &destroyed;
       
   590     // Store the original parameter value, since it is
   524     // Store the original parameter value, since it is
   591     // changed by AddFieldsL
   525     // changed by AddFieldsL
   592     TInt origParam = aFieldTypeResourceId;
   526     TInt origParam = aFieldTypeResourceId;
   593     TPtrC xSpName = aFieldTypeXspName;
   527     TPtrC xSpName = aFieldTypeXspName;
   594 
   528 
   595     CPbk2AddItemManager* addItemManager = CPbk2AddItemManager::NewL
   529     CPbk2AddItemManager* addItemManager = CPbk2AddItemManager::NewL
   596             (iContact, *iUiFieldArray, iParams, iAppServices );
   530             (iContact, *iUiFieldArray, iParams, iAppServices );
   597     CleanupStack::PushL(addItemManager);
   531     CleanupStack::PushL(addItemManager);
   598     CPbk2AddItemManager::TReturnValue ret = addItemManager->AddFieldsL(
   532     CPbk2AddItemManager::TReturnValue ret = addItemManager->AddFieldsL(
   599             aFieldTypeResourceId, xSpName);
   533             aFieldTypeResourceId, xSpName);
   600     
   534 
   601     // In case that pop list for adding item is closed by FSW, this object 
   535     if (ret.iControlId == KErrAlreadyExists)
   602     // will be destructed by CPbk2ContactEditorOperator::ForceExit().
   536         {
   603     // If this object is destructed, don't execute the following anymore.
   537         // cannot add more than one of this field type
   604     if ( !destroyed )
   538         // find and focus that
   605         {
   539         TInt fieldArrayCount( iUiFieldArray->Count() );
   606         if (ret.iControlId == KErrAlreadyExists)
   540         for (TInt i(0); i < fieldArrayCount && ret.iControlId
   607             {
   541                 == KErrAlreadyExists; ++i)
   608             // cannot add more than one of this field type
   542             {
   609             // find and focus that
   543             if (!iUiFieldArray->At(i).ContactEditorField())
   610             TInt fieldArrayCount( iUiFieldArray->Count() );
   544                 {
   611             for (TInt i(0); i < fieldArrayCount && ret.iControlId
   545                 continue;
   612                     == KErrAlreadyExists; ++i)
   546                 }
   613                 {
   547             const MVPbkFieldType* fieldType =
   614                 if (!iUiFieldArray->At(i).ContactEditorField())
   548                 iUiFieldArray->At(i).ContactEditorField()->ContactField().
       
   549                     BestMatchingFieldType();
       
   550             if(fieldType && fieldType->FieldTypeResId() == aFieldTypeResourceId)
       
   551                 {
       
   552                 ret.iControlId = iUiFieldArray->At(i).ControlId();
       
   553                 }
       
   554             }
       
   555         }
       
   556 
       
   557     if (ret.iControlId > 0)
       
   558         {
       
   559         if (aSetFocus)
       
   560             {
       
   561             TryChangeFocusL(ret.iControlId);
       
   562             MPbk2ContactEditorField* editorField = iUiFieldArray->Find( ret.iControlId )->ContactEditorField();
       
   563             MVPbkStoreContactField& storeContactField = editorField->ContactField();
       
   564             iParams.iFocusedContactField = &storeContactField;
       
   565             // Call this after adding or deleting lines
       
   566             UpdatePageL( ETrue );
       
   567             // Must be DrawNow and not DrawDeferred otherwise field label
       
   568             // and content of the following field will be incorrect
       
   569             DrawNow();
       
   570             }
       
   571         }
       
   572     else if (ret.iControlId == KErrNotSupported && origParam == KErrNotFound)
       
   573         {
       
   574         iUiFieldArray->SaveFieldsL();
       
   575         iRelocator.RelocateContactL(aFieldTypeResourceId, xSpName,
       
   576             Pbk2ContactRelocator::EPbk2DisplayStoreDoesNotSupportQuery);
       
   577         }
       
   578     else if ( iParams.iActiveView == TPbk2ContactEditorParams::EEditorView )
       
   579         {
       
   580         switch( ret.iGruopId )
       
   581             {
       
   582             case EPbk2FieldGroupIdPostalAddress:
       
   583                 if(iUiFieldArray->Count())
   615                     {
   584                     {
   616                     continue;
   585                     iUiFieldArray->AddNewFieldL( ret.iGruopId );
       
   586                     ExecuteAddressDlgL( TPbk2ContactEditorParams::EEditorAddressView );
   617                     }
   587                     }
   618                 const MVPbkFieldType* fieldType =
   588                 break;
   619                     iUiFieldArray->At(i).ContactEditorField()->ContactField().
   589             case EPbk2FieldGroupIdHomeAddress:
   620                         BestMatchingFieldType();
   590                 iUiFieldArray->AddNewFieldL( ret.iGruopId );
   621                 if(fieldType && fieldType->FieldTypeResId() == aFieldTypeResourceId)
   591                 ExecuteAddressDlgL( TPbk2ContactEditorParams::EEditorAddressHomeView );
   622                     {
   592                 break;
   623                     ret.iControlId = iUiFieldArray->At(i).ControlId();
   593             case EPbk2FieldGroupIdCompanyAddress:
   624                     }
   594                 iUiFieldArray->AddNewFieldL( ret.iGruopId );
   625                 }
   595                 ExecuteAddressDlgL( TPbk2ContactEditorParams::EEditorAddressOfficeView );
   626             }
   596                 break;
   627     
   597             }
   628         if (ret.iControlId > 0)
       
   629             {
       
   630             if (aSetFocus)
       
   631                 {
       
   632                 TryChangeFocusL(ret.iControlId);
       
   633                 MPbk2ContactEditorField* editorField = iUiFieldArray->Find( ret.iControlId )->ContactEditorField();
       
   634                 MVPbkStoreContactField& storeContactField = editorField->ContactField();
       
   635                 iParams.iFocusedContactField = &storeContactField;
       
   636                 // Call this after adding or deleting lines
       
   637                 UpdatePageL( ETrue );
       
   638                 // Must be DrawNow and not DrawDeferred otherwise field label
       
   639                 // and content of the following field will be incorrect
       
   640                 DrawNow();
       
   641                 }
       
   642             }
       
   643         else if (ret.iControlId == KErrNotSupported && origParam == KErrNotFound)
       
   644             {
       
   645             iUiFieldArray->SaveFieldsL();
       
   646             iRelocator.RelocateContactL(aFieldTypeResourceId, xSpName,
       
   647                 Pbk2ContactRelocator::EPbk2DisplayStoreDoesNotSupportQuery);
       
   648             }
       
   649         else if ( iParams.iActiveView == TPbk2ContactEditorParams::EEditorView )
       
   650             {
       
   651             switch( ret.iGruopId )
       
   652                 {
       
   653                 case EPbk2FieldGroupIdPostalAddress:
       
   654                     if(iUiFieldArray->Count())
       
   655                         {
       
   656                         iUiFieldArray->AddNewFieldL( ret.iGruopId );
       
   657                         ExecuteAddressDlgL( TPbk2ContactEditorParams::EEditorAddressView );
       
   658                         }
       
   659                     break;
       
   660                 case EPbk2FieldGroupIdHomeAddress:
       
   661                     iUiFieldArray->AddNewFieldL( ret.iGruopId );
       
   662                     ExecuteAddressDlgL( TPbk2ContactEditorParams::EEditorAddressHomeView );
       
   663                     break;
       
   664                 case EPbk2FieldGroupIdCompanyAddress:
       
   665                     iUiFieldArray->AddNewFieldL( ret.iGruopId );
       
   666                     ExecuteAddressDlgL( TPbk2ContactEditorParams::EEditorAddressOfficeView );
       
   667                     break;
       
   668                 }
       
   669             }
       
   670         iDestroyedPtrForAddItem = NULL;
       
   671         }
   598         }
   672     CleanupStack::PopAndDestroy(addItemManager);
   599     CleanupStack::PopAndDestroy(addItemManager);
   673     }
   600     }
   674 
   601 
   675 // --------------------------------------------------------------------------
   602 // --------------------------------------------------------------------------
   757          {
   684          {
   758          HandleCustomFieldCommandL(EPbk2ExtensionShowOnMap);
   685          HandleCustomFieldCommandL(EPbk2ExtensionShowOnMap);
   759          return EKeyWasConsumed;
   686          return EKeyWasConsumed;
   760          }*/
   687          }*/
   761 
   688 
   762      // When the end key is pressed and OfferKeyEventL() is called for the first time,
       
   763      // set the edit dialog to be not editable to close the partial input
       
   764      // screen if it is open.
       
   765      if( aKeyEvent.iCode == EKeyEscape && !iEndKeyWasPressed )
       
   766          {
       
   767          SetEditableL( EFalse );
       
   768          }
       
   769 
       
   770     // Display menu bar if the focused control doesnt consume selection keys
   689     // Display menu bar if the focused control doesnt consume selection keys
   771     CPbk2ContactEditorArrayItem* currentField = iUiFieldArray->Find(
   690     CPbk2ContactEditorArrayItem* currentField = iUiFieldArray->Find(
   772             IdOfFocusControl());
   691             IdOfFocusControl());
   773 
   692 
   774     if (currentField)
   693     if (currentField)
   794         {
   713         {
   795         iContextMenuBar->TryDisplayMenuBarL();
   714         iContextMenuBar->TryDisplayMenuBarL();
   796         ret = EKeyWasConsumed;
   715         ret = EKeyWasConsumed;
   797         }
   716         }
   798 
   717 
   799     if ( ret != EKeyWasConsumed )
   718     if ( ret != EKeyWasConsumed && !iEndKeyWasPressed )
   800         {
   719         {
   801         // If the iEndKeyWasPressed equels to true, which illustrates
   720         if ( aKeyEvent.iCode == EKeyEscape )
   802         // the EditorDlgImpl get the Escape key event one more time 
   721             {
   803         // for the case that Exit phonebook2 with the EditorDlg opened,
   722             iEditorStrategy.StopQuery();
   804         // sush as save VOIP settings,there will be two event,
   723             iEndKeyWasPressed = ETrue;
   805         // one is to close dialog and the other is to exit phonebook2. 
   724             }
   806         if ( iEndKeyWasPressed )
   725         ret = CAknForm::OfferKeyEventL( aKeyEvent, aType );
   807             {
   726         if ( ret == EKeyWasConsumed && 
   808             if ( aKeyEvent.iCode == EKeyEscape && iAvkonAppUi->IsAppShutterRunning() )
   727             aKeyEvent.iCode != EKeyPhoneEnd && aKeyEvent.iCode != EKeyEscape )
   809                 {
   728             {
   810                 // Use the iExitApp to record whether the AppShutter is running.
   729             UpdateCbasL();
   811                 // According to the value of iExitApp to Exit Phonebook2 app ui 
   730             }        
   812                 // after the EditorDlg close completely. 
       
   813                 iExitApp = ETrue;
       
   814                 }
       
   815             }
       
   816         else
       
   817             {
       
   818             if ( aKeyEvent.iCode == EKeyEscape )
       
   819                 {
       
   820                 iEditorStrategy.StopQuery();
       
   821                 iEndKeyWasPressed = ETrue;
       
   822                 }
       
   823             ret = CAknForm::OfferKeyEventL( aKeyEvent, aType );
       
   824             if ( ret == EKeyWasConsumed && aKeyEvent.iCode != EKeyPhoneEnd
       
   825                 && aKeyEvent.iCode != EKeyEscape )
       
   826                 {
       
   827                 UpdateCbasL();
       
   828                 }
       
   829             }
       
   830         }
   731         }
   831 
   732 
   832     return ret;
   733     return ret;
   833     }
   734     }
   834 
   735 
   878     // This is needed here because previous settings might override extension's
   779     // This is needed here because previous settings might override extension's
   879     // buttons.
   780     // buttons.
   880     iEditorExtension->ModifyButtonGroupContainerL(ButtonGroupContainer());
   781     iEditorExtension->ModifyButtonGroupContainerL(ButtonGroupContainer());
   881 
   782 
   882     ConstructNaviPaneL();
   783     ConstructNaviPaneL();
   883     UpdateTitleL();
   784 	UpdateTitleL();
   884     UpdateTitlePictureL();
   785     UpdateTitlePictureL();
   885     }
   786     }
   886 
   787 
   887 // --------------------------------------------------------------------------
   788 // --------------------------------------------------------------------------
   888 // CPbk2ContactEditorDlgImpl::PostLayoutDynInitL
   789 // CPbk2ContactEditorDlgImpl::PostLayoutDynInitL
  1255     iAddressView = adressDlg;
  1156     iAddressView = adressDlg;
  1256     adressDlg->ExecuteLD();
  1157     adressDlg->ExecuteLD();
  1257     iAddressView = NULL;
  1158     iAddressView = NULL;
  1258     iParams.iActiveView = TPbk2ContactEditorParams::EEditorView;
  1159     iParams.iActiveView = TPbk2ContactEditorParams::EEditorView;
  1259     UpdateControlsL();
  1160     UpdateControlsL();
  1260     
       
  1261     // The if-expression refers to the situation that need to
       
  1262     // delete editor dialog after address dialog exit completely,
       
  1263     // such as the store-unavailable situation    
       
  1264     if ( iDelayDelete )
       
  1265         {
       
  1266         iDelayDelete->Start( TCallBack( &DelayDlgDeleteCallBack, this ) );
       
  1267         }
       
  1268     }
       
  1269 
       
  1270 // --------------------------------------------------------------------------
       
  1271 // CPbk2ContactEditorDlgImpl::DelayDlgDeleteCallBack
       
  1272 // --------------------------------------------------------------------------
       
  1273 //
       
  1274 TInt CPbk2ContactEditorDlgImpl::DelayDlgDeleteCallBack( TAny* aCallBack )
       
  1275     {
       
  1276     static_cast<CPbk2ContactEditorDlgImpl*>( aCallBack )->DelayDlgDelete();
       
  1277     return EFalse;    
       
  1278     }
       
  1279 
       
  1280 // --------------------------------------------------------------------------
       
  1281 // CPbk2ContactEditorDlgImpl::DelayDlgDelete
       
  1282 // --------------------------------------------------------------------------
       
  1283 //
       
  1284 void CPbk2ContactEditorDlgImpl::DelayDlgDelete()
       
  1285     {
       
  1286     // Need to inform editor-observer that contact editing is
       
  1287     // aborted, at the same time, exit editor dialog directly 
       
  1288     // without saving the changes.
       
  1289     iContactObserver.ContactEditingAborted();
       
  1290     delete this;
       
  1291     }
  1161     }
  1292 
  1162 
  1293 // --------------------------------------------------------------------------
  1163 // --------------------------------------------------------------------------
  1294 // CPbk2ContactEditorDlgImpl::AddAddressFields
  1164 // CPbk2ContactEditorDlgImpl::AddAddressFields
  1295 // --------------------------------------------------------------------------
  1165 // --------------------------------------------------------------------------
  1313 
  1183 
  1314 // --------------------------------------------------------------------------
  1184 // --------------------------------------------------------------------------
  1315 // CPbk2ContactEditorDlgImpl::AreAllFieldsEmpty
  1185 // CPbk2ContactEditorDlgImpl::AreAllFieldsEmpty
  1316 // --------------------------------------------------------------------------
  1186 // --------------------------------------------------------------------------
  1317 //
  1187 //
  1318 TBool CPbk2ContactEditorDlgImpl::AreAllFieldsEmptyL()
  1188 TBool CPbk2ContactEditorDlgImpl::AreAllFieldsEmpty()
  1319     {
  1189     {
  1320     TBool result(ETrue);
  1190     TBool result(ETrue);
  1321     TInt countAll = iContact.PresentationFields().FieldCount();
  1191     TInt countAll = iContact.PresentationFields().FieldCount();
  1322     for (TInt idx = 0; idx < countAll; idx++)
  1192     for (TInt idx = 0; idx < countAll; idx++)
  1323         {
  1193         {
  1743                 {
  1613                 {
  1744                  iNaviContainer->Pop();
  1614                  iNaviContainer->Pop();
  1745                  RestorePrevNaviDecoratorL();
  1615                  RestorePrevNaviDecoratorL();
  1746                  iNaviContainer = NULL;
  1616                  iNaviContainer = NULL;
  1747                  }
  1617                  }
  1748             
  1618             MakeVisible( EFalse );
  1749             if ( !iAvkonAppUi->IsAppShutterRunning() )
       
  1750                 {
       
  1751                 MakeVisible( EFalse );
       
  1752                 }
       
  1753            
       
  1754             MPbk2ContactEditorEventObserver::TParams params;
  1619             MPbk2ContactEditorEventObserver::TParams params;
  1755             params.iFlags = EPbk2EditorKeyCode;
  1620             params.iFlags = EPbk2EditorKeyCode;
  1756             params.iKeyCode = aKeycode;
  1621             params.iKeyCode = aKeycode;
  1757 
  1622 
  1758             // If the application is not allowed to hide itself in the
  1623             // If the application is not allowed to hide itself in the
  2066 // --------------------------------------------------------------------------
  1931 // --------------------------------------------------------------------------
  2067 // CPbk2ContactEditorDlgImpl::CloseDialog
  1932 // CPbk2ContactEditorDlgImpl::CloseDialog
  2068 // --------------------------------------------------------------------------
  1933 // --------------------------------------------------------------------------
  2069 //
  1934 //
  2070 void CPbk2ContactEditorDlgImpl::CloseDialog()
  1935 void CPbk2ContactEditorDlgImpl::CloseDialog()
  2071     {
  1936 	{
  2072     // Ignore error and close editor without further user interaction
  1937     // Ignor error and close editor without further user interaction
  2073     MVPbkContactObserver::TContactOpResult exitResult;
  1938     MVPbkContactObserver::TContactOpResult exitResult;
  2074     exitResult.iExtension = NULL;
  1939     exitResult.iExtension = NULL;
  2075     exitResult.iStoreContact = NULL;
  1940     exitResult.iStoreContact = NULL;
  2076     exitResult.iOpCode = MVPbkContactObserver::EContactDelete;
  1941     exitResult.iOpCode = MVPbkContactObserver::EContactDelete;
  2077     MPbk2ContactEditorEventObserver::TParams exitParams;
  1942     MPbk2ContactEditorEventObserver::TParams exitParams;
  2090         iExitRecord.Set( EExitApproved );
  1955         iExitRecord.Set( EExitApproved );
  2091         iExitRecord.Set( EExitOrdered );
  1956         iExitRecord.Set( EExitOrdered );
  2092         }
  1957         }
  2093       
  1958       
  2094     ContactEditorOperationCompleted(exitResult, exitParams);
  1959     ContactEditorOperationCompleted(exitResult, exitParams);
  2095     }
  1960 	}
  2096 
  1961 
  2097 // --------------------------------------------------------------------------
  1962 // --------------------------------------------------------------------------
  2098 // CPbk2ContactEditorDlgImpl::ContactEditorOperationFailed
  1963 // CPbk2ContactEditorDlgImpl::ContactEditorOperationFailed
  2099 // --------------------------------------------------------------------------
  1964 // --------------------------------------------------------------------------
  2100 //
  1965 //
  2462 void CPbk2ContactEditorDlgImpl::StoreUnavailable
  2327 void CPbk2ContactEditorDlgImpl::StoreUnavailable
  2463     ( MVPbkContactStore& aContactStore, TInt /*aReason*/ )
  2328     ( MVPbkContactStore& aContactStore, TInt /*aReason*/ )
  2464     {
  2329     {
  2465     if ( &aContactStore == &iContact.ParentStore() )
  2330     if ( &aContactStore == &iContact.ParentStore() )
  2466         {
  2331         {
  2467         // Use iAppServices if provided. This is to enable editor use outside from pbk2 context		
  2332         /*
       
  2333 		 * Use iAppServices if provided. This is to enable editor use outside from pbk2 context
       
  2334 		 */
  2468         const CPbk2StoreProperty* property = NULL;
  2335         const CPbk2StoreProperty* property = NULL;
  2469         if( iAppServices )
  2336         if( iAppServices )
  2470             {
  2337         	{
  2471             property =
  2338         	property =
  2472                     iAppServices->StoreProperties().FindProperty
  2339 					iAppServices->StoreProperties().FindProperty
  2473                             ( aContactStore.StoreProperties().Uri() );
  2340 							( aContactStore.StoreProperties().Uri() );
  2474             }
  2341         	}
  2475         else
  2342         else
  2476             {
  2343         	{
  2477             property =
  2344         	property =
  2478                     Phonebook2::Pbk2AppUi()->ApplicationServices().
  2345 					Phonebook2::Pbk2AppUi()->ApplicationServices().
  2479                         StoreProperties().FindProperty
  2346 						StoreProperties().FindProperty
  2480                             ( aContactStore.StoreProperties().Uri() );
  2347 							( aContactStore.StoreProperties().Uri() );
  2481             }
  2348         	}
  2482 
  2349         
  2483 
  2350 
  2484         TPtrC storeName;
  2351         TPtrC storeName;
  2485         if ( property )
  2352         if ( property )
  2486             {
  2353             {
  2487             storeName.Set( property->StoreName() );
  2354             storeName.Set( property->StoreName() );
  2489 
  2356 
  2490         // If this leaves the note is not shown.
  2357         // If this leaves the note is not shown.
  2491         // Cannot do anything about that
  2358         // Cannot do anything about that
  2492         TRAP_IGNORE( ShowStoreNotAvailableNoteL( storeName ) );
  2359         TRAP_IGNORE( ShowStoreNotAvailableNoteL( storeName ) );
  2493 
  2360 
  2494         // If the address dialog is opened, delete address dialog first,
  2361         // Close editor if store which came unavailable is iContact's store
  2495         // then after address dialog exit completely, delete the editor dialog
  2362         iContactObserver.ContactEditingAborted();
  2496         // via DelayDlgDeleteCallBack; if there isn't the address dialog, 
  2363         // TryExitL is not called because it would call OkToExitL
  2497         // delete editor dialog directly.         
  2364         // which is not wanted
  2498         if (iAddressView )
  2365         delete this;
  2499             {
       
  2500             // Create the CIdle object to delete editor dialog later.
       
  2501             if ( !iDelayDelete )
       
  2502                 {
       
  2503                 iDelayDelete = CIdle::NewL( CActive::EPriorityStandard );
       
  2504                 }
       
  2505             delete iAddressView;
       
  2506             iAddressView = NULL;
       
  2507             }
       
  2508        else
       
  2509             {
       
  2510             // At the store unavailable situation, informs editor observer 
       
  2511             // that contact editing is aborted without saving the changes.
       
  2512             iContactObserver.ContactEditingAborted();
       
  2513             delete this;
       
  2514             }
       
  2515         }
  2366         }
  2516     }
  2367     }
  2517 
  2368 
  2518 // --------------------------------------------------------------------------
  2369 // --------------------------------------------------------------------------
  2519 // CPbk2ContactEditorDlgImpl::HandleStoreEventL
  2370 // CPbk2ContactEditorDlgImpl::HandleStoreEventL
  2622         {
  2473         {
  2623         HBufC* title = NULL;
  2474         HBufC* title = NULL;
  2624         switch (iParams.iActiveView)
  2475         switch (iParams.iActiveView)
  2625             {
  2476             {
  2626             case TPbk2ContactEditorParams::EEditorAddressView:
  2477             case TPbk2ContactEditorParams::EEditorAddressView:
  2627                 if( !iTitleText )
  2478             	if( !iTitleText )
  2628                     {
  2479             		{
  2629                     title = StringLoader::LoadL(R_QTN_PHOB_HEADER_ADDRESS);
  2480             		title = StringLoader::LoadL(R_QTN_PHOB_HEADER_ADDRESS);
  2630                     }
  2481             		}
  2631                 break;
  2482                 break;
  2632             case TPbk2ContactEditorParams::EEditorAddressHomeView:
  2483             case TPbk2ContactEditorParams::EEditorAddressHomeView:
  2633                 if( !iTitleText )
  2484             	if( !iTitleText )
  2634                     {
  2485             		{
  2635                     title = StringLoader::LoadL(
  2486             		title = StringLoader::LoadL(
  2636                             R_QTN_PHOB_HEADER_ADDRESS_HOME);
  2487             				R_QTN_PHOB_HEADER_ADDRESS_HOME);
  2637                     }
  2488             		}
  2638                 break;
  2489                 break;
  2639             case TPbk2ContactEditorParams::EEditorAddressOfficeView:
  2490             case TPbk2ContactEditorParams::EEditorAddressOfficeView:
  2640                 if( !iTitleText )
  2491             	if( !iTitleText )
  2641                     {
  2492             		{
  2642                     title = StringLoader::LoadL(
  2493             		title = StringLoader::LoadL(
  2643                             R_QTN_PHOB_HEADER_ADDRESS_WORK);
  2494             				R_QTN_PHOB_HEADER_ADDRESS_WORK);
  2644                     }
  2495             		}
  2645                 break;
  2496                 break;
  2646             case TPbk2ContactEditorParams::EEditorView:
  2497             case TPbk2ContactEditorParams::EEditorView:
  2647                 {
  2498                 {
  2648                 if ( !iStoreContact )
  2499                 if ( !iStoreContact )
  2649                     {
  2500                     {
  2676                             CleanupStack::PopAndDestroy(uiData);
  2527                             CleanupStack::PopAndDestroy(uiData);
  2677                             }
  2528                             }
  2678                         }
  2529                         }
  2679                     }
  2530                     }
  2680                 if( !iTitleText )
  2531                 if( !iTitleText )
  2681                     {
  2532                 	{
  2682                     title = iNameFormatter->GetContactTitleOrNullL(iStoreContact->Fields(),
  2533                 	title = iNameFormatter->GetContactTitleOrNullL(iStoreContact->Fields(),
  2683                             KEditorNameFormatFlags);
  2534                 			KEditorNameFormatFlags);
  2684                     }
  2535                 	}
  2685                 break;
  2536                 break;
  2686                 }
  2537                 }
  2687             default:
  2538             default:
  2688                 break;
  2539                 break;
  2689             }
  2540             }
  2690         
  2541         
  2691         // if custom title text is provided
  2542         // if custom title text is provided
  2692         if( iTitleText )
  2543         if( iTitleText )
  2693             {
  2544         	{
  2694             iTitlePane->SetTextL( iTitleText->Des() );
  2545         	iTitlePane->SetTextL( iTitleText->Des() );
  2695             }
  2546         	}
  2696         else 
  2547         else 
  2697             {
  2548         	{
  2698              if (title)
  2549         	 if (title)
  2699                 {
  2550 				{
  2700                 iTitlePane->SetText(title);
  2551 				iTitlePane->SetText(title);
  2701                 }
  2552 				}
  2702             else
  2553 			else
  2703                 {
  2554 				{
  2704                 iTitlePane->SetTextL(iEditorStrategy.DefaultTitle());
  2555 				iTitlePane->SetTextL(iEditorStrategy.DefaultTitle());
  2705                 }
  2556 				}
  2706             }
  2557         	}
  2707         }
  2558         }
  2708     CEikStatusPane* statusPane = iAvkonAppUi->StatusPane();
  2559     CEikStatusPane* statusPane = iAvkonAppUi->StatusPane();
  2709     
  2560     
  2710     if (statusPane)
  2561     if (statusPane)
  2711         {
  2562         {
  2727     if (iTitlePane)
  2578     if (iTitlePane)
  2728         {
  2579         {
  2729         // Update picture in title pane
  2580         // Update picture in title pane
  2730         
  2581         
  2731         /*
  2582         /*
  2732          * Use iAppServices if provided. This is to enable editor use outside from pbk2 context
  2583 		 * Use iAppServices if provided. This is to enable editor use outside from pbk2 context
  2733          */
  2584 		 */
  2734         CEikImage* image = NULL;
  2585         CEikImage* image = NULL;
  2735         if( iAppServices )
  2586         if( iAppServices )
  2736             {
  2587         	{
  2737             image =
  2588         	image =
  2738                 Pbk2TitlePanePictureFactory::CreateTitlePanePictureLC
  2589 				Pbk2TitlePanePictureFactory::CreateTitlePanePictureLC
  2739                     ( &iContact.StoreContact(),
  2590 					( &iContact.StoreContact(),
  2740                             iAppServices->StoreProperties() );
  2591 							iAppServices->StoreProperties() );
  2741             }
  2592         	}
  2742         else
  2593         else
  2743             {
  2594         	{
  2744             image =
  2595         	image =
  2745                 Pbk2TitlePanePictureFactory::CreateTitlePanePictureLC
  2596 				Pbk2TitlePanePictureFactory::CreateTitlePanePictureLC
  2746                     ( &iContact.StoreContact(),
  2597 					( &iContact.StoreContact(),
  2747                       Phonebook2::Pbk2AppUi()->ApplicationServices().
  2598 					  Phonebook2::Pbk2AppUi()->ApplicationServices().
  2748                         StoreProperties() );
  2599 						StoreProperties() );
  2749             }
  2600         	}
  2750         
  2601         
  2751         
  2602         
  2752         // ownership of the picture is transfered to title pane
  2603         // ownership of the picture is transfered to title pane
  2753         image->SetPictureOwnedExternally( ETrue );
  2604         image->SetPictureOwnedExternally( ETrue );
  2754         iTitlePane->SetSmallPicture(
  2605         iTitlePane->SetSmallPicture(
  2766 void CPbk2ContactEditorDlgImpl::CloseDialog(
  2617 void CPbk2ContactEditorDlgImpl::CloseDialog(
  2767         MVPbkContactObserver::TContactOp aOpCode, TBool aInformObserver)
  2618         MVPbkContactObserver::TContactOp aOpCode, TBool aInformObserver)
  2768     {
  2619     {
  2769     // For knowing if the destructor has been called
  2620     // For knowing if the destructor has been called
  2770     TBool destroyed = EFalse;
  2621     TBool destroyed = EFalse;
  2771     iDestroyedPtrForCloseDlg = &destroyed;
  2622     iDestroyedPtr = &destroyed;
  2772 
  2623 
  2773     if (aInformObserver && iParams.iActiveView
  2624     if (aInformObserver && iParams.iActiveView
  2774             == TPbk2ContactEditorParams::EEditorView || iAddressViewStandalone)
  2625             == TPbk2ContactEditorParams::EEditorView || iAddressViewStandalone)
  2775         {
  2626         {
  2776         switch (aOpCode)
  2627         switch (aOpCode)
  2799         }
  2650         }
  2800 
  2651 
  2801     // In VOIP/new contacts/exit case, this object will be destructed by
  2652     // In VOIP/new contacts/exit case, this object will be destructed by
  2802     // iContactObserver.ContactEditingComplete() above.
  2653     // iContactObserver.ContactEditingComplete() above.
  2803     // If this object is destructed, don't excute the following anymore
  2654     // If this object is destructed, don't excute the following anymore
  2804     if ( !destroyed )
  2655     if ( destroyed )
  2805         {
  2656         {
  2806         // Don't save any contact data (already saved)
  2657         return;
  2807         iExitRecord.Set(EOkToExitWithoutHandlingIt);
  2658         }
  2808         iExitRecord.Clear(EExitOrdered);
  2659 
  2809     
  2660     // Don't save any contact data (already saved)
  2810         // Close dialog using TryExitL and returning ETrue from OkToExit
  2661     iExitRecord.Set(EOkToExitWithoutHandlingIt);
  2811         TInt err = KErrNone;
  2662     iExitRecord.Clear(EExitOrdered);
  2812             TRAP( err, TryExitL( EAknSoftkeyBack ) );
  2663 
  2813         if (err != KErrNone)
  2664     // Close dialog using TryExitL and returning ETrue from OkToExit
  2814             {
  2665     TInt err = KErrNone;
  2815             // If not nicely then use the force.
  2666         TRAP( err, TryExitL( EAknSoftkeyBack ) );
  2816             delete this;
  2667     if (err != KErrNone)
  2817             }
  2668         {
  2818         iDestroyedPtrForCloseDlg = NULL;
  2669         // If not nicely then use the force.
       
  2670         delete this;
  2819         }
  2671         }
  2820     }
  2672     }
  2821 
  2673 
  2822 // --------------------------------------------------------------------------
  2674 // --------------------------------------------------------------------------
  2823 // CPbk2ContactEditorDlgImpl::ExitApplication
  2675 // CPbk2ContactEditorDlgImpl::ExitApplication
  2833 
  2685 
  2834         CloseDialog( aOpCode, ETrue );
  2686         CloseDialog( aOpCode, ETrue );
  2835 
  2687 
  2836         // Dialog is closed so there is nothing to do if
  2688         // Dialog is closed so there is nothing to do if
  2837         // HandleCommandL leaves. 
  2689         // HandleCommandL leaves. 
  2838         TRAP_IGNORE(CEikonEnv::Static()->EikAppUi()->HandleCommandL(aCommandId)); 
  2690 		TRAP_IGNORE(CEikonEnv::Static()->EikAppUi()->HandleCommandL(aCommandId)); 
  2839         }
  2691         }
  2840     }
  2692     }
  2841 
  2693 
  2842 // --------------------------------------------------------------------------
  2694 // --------------------------------------------------------------------------
  2843 // CPbk2ContactEditorDlgImpl::CmdAddItemL
  2695 // CPbk2ContactEditorDlgImpl::CmdAddItemL
  2963             switch(uiField->UIField()->CtrlType())
  2815             switch(uiField->UIField()->CtrlType())
  2964                 {
  2816                 {
  2965                 case EPbk2FieldCtrlTypeExtAddressEditor:
  2817                 case EPbk2FieldCtrlTypeExtAddressEditor:
  2966                 case EPbk2FieldCtrlTypeExtAddressHomeEditor:
  2818                 case EPbk2FieldCtrlTypeExtAddressHomeEditor:
  2967                 case EPbk2FieldCtrlTypeExtAddressOfficeEditor:
  2819                 case EPbk2FieldCtrlTypeExtAddressOfficeEditor:
  2968                     {
  2820                     if(IsAddressValidated(Pbk2AddressTools::MapCtrlTypeToAddress(
  2969                 	TInt iconId = 0;
  2821                             uiField->UIField()->CtrlType())))
  2970                     // UnSync feature indicator flag and chinese flag
       
  2971                     TBool supportUnSyncFeature = 
       
  2972                           FeatureManager::FeatureSupported( 
       
  2973                           KFeatureIdFfTdUnSyncabPbfieldsInd );
       
  2974                     TBool supportChinese = 
       
  2975                         FeatureManager::FeatureSupported( KFeatureIdChinese ); 
       
  2976                     // Valid address
       
  2977                     TBool addressValidated = 
       
  2978                          IsAddressValidated( 
       
  2979                             Pbk2AddressTools::MapCtrlTypeToAddress(
       
  2980                             uiField->UIField()->CtrlType()));
       
  2981                     if(supportChinese && supportUnSyncFeature)
       
  2982                         {
  2822                         {
  2983                         // Unsync icon
  2823                         TPbk2IconId iconID(TUid::Uid(KPbk2UID3), EPbk2qgn_prop_locev_map);
  2984                         iconId = EPbk2qgn_prop_phonebook2_unsync;
  2824                         uiField->LoadBitmapToFieldL(iconID);
  2985                         }
  2825                         }
  2986                     else
  2826                     else
  2987                         {
  2827                         {
  2988                         iconId = addressValidated ?
  2828                         TPbk2IconId iconID(TUid::Uid(KPbk2UID3), EPbk2qgn_prop_pb_no_valid_lm);
  2989                             EPbk2qgn_prop_locev_map : EPbk2qgn_prop_pb_no_valid_lm;
  2829                         uiField->LoadBitmapToFieldL(iconID);
  2990                         }
  2830                         }
  2991                     TPbk2IconId pbkIconId(TUid::Uid(KPbk2UID3),iconId);
       
  2992                     uiField->LoadBitmapToFieldL(pbkIconId); 
       
  2993                     }
       
  2994                     break;
  2831                     break;
  2995                 case EPbk2FieldCtrlTypeExtAssignFromMapsEditor:
  2832                 case EPbk2FieldCtrlTypeExtAssignFromMapsEditor:
  2996                     {
  2833                     if(IsAddressValidated( Pbk2AddressTools::MapViewTypeToAddress(iParams.iActiveView)))
  2997                     // UnSync feature indicator flag and chinese flag
       
  2998                     TBool supportUnSyncFeature = 
       
  2999                            FeatureManager::FeatureSupported(
       
  3000                            KFeatureIdFfTdUnSyncabPbfieldsInd );
       
  3001                     TBool supportChinese = 
       
  3002                            FeatureManager::FeatureSupported( KFeatureIdChinese ); 
       
  3003 
       
  3004                     TBool addressValidated = 
       
  3005                            IsAddressValidated( 
       
  3006                            Pbk2AddressTools::MapViewTypeToAddress( iParams.iActiveView ));
       
  3007                     TInt iconId = 0;
       
  3008                     if( supportChinese && supportUnSyncFeature )
       
  3009                         {
  2834                         {
  3010                         iconId = EPbk2qgn_prop_phonebook2_unsync;
  2835                           TPbk2IconId iconID(TUid::Uid(KPbk2UID3), EPbk2qgn_prop_locev_map);
  3011                         }
  2836                           uiField->LoadBitmapToFieldL(iconID);
  3012                     else
  2837                           }
  3013                         {
  2838                       else
  3014                         iconId = addressValidated ?
  2839                           {
  3015                             EPbk2qgn_prop_locev_map : EPbk2qgn_prop_pb_no_valid_lm;
  2840                           TPbk2IconId iconID(TUid::Uid(KPbk2UID3), EPbk2qgn_prop_pb_no_valid_lm);
  3016                         }
  2841                           uiField->LoadBitmapToFieldL(iconID);
  3017                     TPbk2IconId pbkIconId(TUid::Uid(KPbk2UID3),iconId);
  2842                           }
  3018                     uiField->LoadBitmapToFieldL(pbkIconId); 
  2843                     break;  
  3019                     }
       
  3020                     break;
       
  3021                 default:
  2844                 default:
  3022                     return;
  2845                     return;
  3023                 }
  2846                 }
  3024             }
  2847             }
  3025         }
  2848         }
  3111         if (iParams.iActiveView == TPbk2ContactEditorParams::EEditorView || 
  2934         if (iParams.iActiveView == TPbk2ContactEditorParams::EEditorView || 
  3112             iAddressViewStandalone)
  2935             iAddressViewStandalone)
  3113             {
  2936             {
  3114             // Estimate all field are empty by UI field.
  2937             // Estimate all field are empty by UI field.
  3115         if (( AreAllControlsEmpty() && !iAddressViewStandalone )||
  2938         if (( AreAllControlsEmpty() && !iAddressViewStandalone )||
  3116             (iAddressViewStandalone && AreAllFieldsEmptyL()))
  2939             (iAddressViewStandalone && AreAllFieldsEmpty()))
  3117                 {
  2940                 {
  3118                 if (iEditorExtension->OkToDeleteContactL(aParams))
  2941                 if (iEditorExtension->OkToDeleteContactL(aParams))
  3119                     {
  2942                     {
  3120                     // iUseState must be set before DeleteContactL() because 
  2943                     // iUseState must be set before DeleteContactL() because 
  3121                     // during deletion ForceExit() might be entered and needs to 
  2944                     // during deletion ForceExit() might be entered and needs to 
  3156                     if ( iEndKeyWasPressed )
  2979                     if ( iEndKeyWasPressed )
  3157                         {
  2980                         {
  3158                         CloseDialog();
  2981                         CloseDialog();
  3159                         }
  2982                         }
  3160                     else
  2983                     else
  3161                         {
  2984                     	{
  3162                         iExitRecord.Clear( EExitOrdered );
  2985                     	iExitRecord.Clear( EExitOrdered );
  3163                         }
  2986                     	}
  3164                     }
  2987                     }
  3165                 }
  2988                 }
  3166             }
  2989             }
  3167        else
  2990        else
  3168             {
  2991             {
  3283 TBool CPbk2ContactEditorDlgImpl::OkToExitApplicationL
  3106 TBool CPbk2ContactEditorDlgImpl::OkToExitApplicationL
  3284         ( TInt aCommandId )
  3107         ( TInt aCommandId )
  3285     {
  3108     {
  3286     TBool okToExit = ETrue;
  3109     TBool okToExit = ETrue;
  3287 
  3110 
  3288     // The exit callback must be invoked only once when editor dlg is exiting.
       
  3289     if ( (iParams.iActiveView == TPbk2ContactEditorParams::EEditorView || 
       
  3290             iAddressViewStandalone) && iParams.iExitCallback )
       
  3291         {
       
  3292         okToExit = iParams.iExitCallback->OkToExitL( aCommandId );
       
  3293         }
       
  3294     
       
  3295     // If exit callback returned EFalse, the exit is cancelled
  3111     // If exit callback returned EFalse, the exit is cancelled
       
  3112     if ( iParams.iExitCallback &&
       
  3113          !iParams.iExitCallback->OkToExitL( aCommandId ) )
       
  3114         {
       
  3115         okToExit = EFalse;
       
  3116         }
       
  3117 
  3296     if ( !okToExit )
  3118     if ( !okToExit )
  3297         {
  3119         {
  3298         iExitRecord.Clear( EExitApproved );
  3120         iExitRecord.Clear( EExitApproved );
  3299         }
  3121         }
  3300 
  3122 
  3536 // CPbk2ContactEditorDlgImpl::CheckCurrentFieldTextL
  3358 // CPbk2ContactEditorDlgImpl::CheckCurrentFieldTextL
  3537 // --------------------------------------------------------------------------
  3359 // --------------------------------------------------------------------------
  3538 //    
  3360 //    
  3539 void CPbk2ContactEditorDlgImpl::CheckCurrentFieldTextL( 
  3361 void CPbk2ContactEditorDlgImpl::CheckCurrentFieldTextL( 
  3540         CPbk2ContactEditorArrayItem* aCurrentField,
  3362         CPbk2ContactEditorArrayItem* aCurrentField,
  3541         const TKeyEvent& aKeyEvent, 
  3363 		const TKeyEvent& aKeyEvent, 
  3542         TEventCode aType )
  3364 		TEventCode aType )
  3543     {
  3365     {
  3544     MPbk2ContactEditorField* editorField = aCurrentField->ContactEditorField();
  3366     MPbk2ContactEditorField* editorField = aCurrentField->ContactEditorField();
  3545     if ( editorField )
  3367     if ( editorField )
  3546         {
  3368         {
  3547         MVPbkStoreContactField& contactField = editorField->ContactField();
  3369         MVPbkStoreContactField& contactField = editorField->ContactField();