phonebookui/Phonebook2/UIControls/src/CPbk2ContactEditorDlg.cpp
changeset 0 e686773b3f54
child 8 5586b4d2ec3e
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:  Phonebook2 contact editor dialog.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <CPbk2ContactEditorDlg.h>
       
    21 
       
    22 // Phonebook 2
       
    23 #include "CPbk2ContactEditorDlgImpl.h"
       
    24 #include "Pbk2ContactEditorStrategyFactory.h"
       
    25 #include "MPbk2ContactEditorStrategy.h"
       
    26 #include <CPbk2ContactRelocator.h>
       
    27 #include <CPbk2FieldPropertyArray.h>
       
    28 #include <MPbk2ContactEditorEventObserver.h>
       
    29 #include <MPbk2EditedContactObserver.h>
       
    30 #include <CPbk2PresentationContact.h>
       
    31 #include <CPbk2StoreSpecificFieldPropertyArray.h>
       
    32 #include <CPbk2PresentationContactFieldCollection.h>
       
    33 #include <MPbk2FieldProperty.h>
       
    34 #include <MPbk2ApplicationServices.h>
       
    35 #include <MPbk2AppUi.h>
       
    36 
       
    37 // Virtual Phonebook
       
    38 #include <CVPbkContactManager.h>
       
    39 #include <MVPbkStoreContact.h>
       
    40 #include <MVPbkContactStore.h>
       
    41 #include <MVPbkContactFieldTextData.h>
       
    42 #include <MVPbkContactStoreProperties.h>
       
    43 #include <MVPbkFieldType.h>
       
    44 #include <barsread.h>
       
    45 
       
    46 
       
    47 // System includes
       
    48 #include <coemain.h>
       
    49 
       
    50 /// Unnamed namespace for local definitions
       
    51 namespace {
       
    52 
       
    53 #ifdef _DEBUG
       
    54 enum TPanicCode
       
    55     {
       
    56     ENullPointer,
       
    57     EPanicPreCond_ResetWhenDestroyed
       
    58     };
       
    59 
       
    60 void Panic(TPanicCode aReason)
       
    61     {
       
    62     _LIT(KPanicText, "CPbk2ContactEditorDlg");
       
    63     User::Panic(KPanicText,aReason);
       
    64     }
       
    65 #endif // _DEBUG
       
    66 
       
    67 } /// namespace
       
    68 
       
    69 // --------------------------------------------------------------------------
       
    70 // CPbk2ContactEditorDlg::CPbk2ContactEditorDlg
       
    71 // --------------------------------------------------------------------------
       
    72 //
       
    73 CPbk2ContactEditorDlg::CPbk2ContactEditorDlg
       
    74     ( TPbk2ContactEditorParams& aParams,
       
    75       MPbk2EditedContactObserver& aContactObserver,
       
    76       MPbk2ApplicationServices* aAppServices,
       
    77       TInt aEditorFieldsId ) :
       
    78         iParams( aParams ),
       
    79         iContactObserver( aContactObserver ),
       
    80         iAddItemFieldTypeResourceId( KErrNotFound ),
       
    81         iAppServices( aAppServices ),
       
    82         iEditorFieldsId( aEditorFieldsId )
       
    83     {
       
    84     }
       
    85 
       
    86 // --------------------------------------------------------------------------
       
    87 // CPbk2ContactEditorDlg::~CPbk2ContactEditorDlg
       
    88 // --------------------------------------------------------------------------
       
    89 //
       
    90 CPbk2ContactEditorDlg::~CPbk2ContactEditorDlg()
       
    91     {
       
    92 	delete iTitleText;
       
    93     if ( iSelfPtr )
       
    94         {
       
    95         *iSelfPtr = NULL;
       
    96         }
       
    97     if ( iDestroyedPtr )
       
    98         {
       
    99         *iDestroyedPtr = ETrue;
       
   100         }
       
   101     delete iContact;
       
   102     delete iSpecificFieldProperties;
       
   103     delete iFieldProperties;
       
   104     delete iEditorStrategy;
       
   105     delete iContactRelocator;
       
   106     delete iStoreContact;
       
   107     delete iAddItemFieldTypeXspName;
       
   108     }
       
   109 
       
   110 
       
   111 // --------------------------------------------------------------------------
       
   112 // CPbk2ContactEditorDlg::NewL
       
   113 // --------------------------------------------------------------------------
       
   114 //
       
   115 EXPORT_C CPbk2ContactEditorDlg* CPbk2ContactEditorDlg::NewL(
       
   116         TPbk2ContactEditorParams& aParams, MVPbkStoreContact* aContact,
       
   117         MPbk2EditedContactObserver& aContactObserver)
       
   118     {
       
   119     CPbk2ContactEditorDlg* self =
       
   120         new(ELeave) CPbk2ContactEditorDlg(aParams, aContactObserver);
       
   121     CleanupStack::PushL(self);
       
   122     self->ConstructL( aContact );
       
   123     CleanupStack::Pop(self);
       
   124     return self;
       
   125     }
       
   126 
       
   127 
       
   128 // --------------------------------------------------------------------------
       
   129 // CPbk2ContactEditorDlg::NewL
       
   130 // --------------------------------------------------------------------------
       
   131 //
       
   132 EXPORT_C CPbk2ContactEditorDlg* CPbk2ContactEditorDlg::NewL(
       
   133         TPbk2ContactEditorParams& aParams, 
       
   134         MVPbkStoreContact* aContact,
       
   135         MPbk2EditedContactObserver& aContactObserver,
       
   136         MPbk2ApplicationServices* aAppServices,
       
   137         HBufC* aTitleText,
       
   138         TInt aEditorFieldsId )
       
   139     {
       
   140     CPbk2ContactEditorDlg* self =
       
   141         new(ELeave) CPbk2ContactEditorDlg(aParams, aContactObserver,aAppServices,aEditorFieldsId );
       
   142     CleanupStack::PushL(self);
       
   143     self->ConstructL( aContact );
       
   144 	self->iTitleText = aTitleText;
       
   145     CleanupStack::Pop(self);
       
   146     return self;
       
   147     }
       
   148 
       
   149 
       
   150 // --------------------------------------------------------------------------
       
   151 // CPbk2ContactEditorDlg::ConstructL
       
   152 // --------------------------------------------------------------------------
       
   153 //
       
   154 void CPbk2ContactEditorDlg::ConstructL( MVPbkStoreContact* aStoreContact )
       
   155     {
       
   156     CreatePresentationContactL( *aStoreContact );
       
   157 
       
   158     iEditorStrategy =
       
   159         Pbk2ContactEditorStrategyFactory::CreateL
       
   160             (iParams, iContact);
       
   161 
       
   162     // Take ownership of the contact after all leaving initialization has
       
   163     // been done.
       
   164     iStoreContact = aStoreContact;
       
   165     }
       
   166 
       
   167 // --------------------------------------------------------------------------
       
   168 // CPbk2ContactEditorDlg::ExecuteLD
       
   169 // --------------------------------------------------------------------------
       
   170 //
       
   171 EXPORT_C void CPbk2ContactEditorDlg::ExecuteLD()
       
   172     {
       
   173     CleanupStack::PushL( this );
       
   174 
       
   175     TBool destroyed = EFalse;
       
   176     iDestroyedPtr = &destroyed;
       
   177 
       
   178     // Implementation dialog must be run again e.g when relocation
       
   179     // is done due to item addition.
       
   180     do
       
   181         {
       
   182         // Reset state
       
   183         iRelocationState.ClearAll();
       
   184 
       
   185         iImplementation = CPbk2ContactEditorDlgImpl::NewL
       
   186             ( iParams, *iContact, *iFieldProperties, *this,
       
   187               *iEditorStrategy, *this, iAppServices, iTitleText ); 
       
   188         // ownership is passed
       
   189         iTitleText = NULL;
       
   190         iEliminator = iImplementation;
       
   191         iImplementation->ResetWhenDestroyed( &iEliminator );
       
   192         iImplementation->ExecuteLD();
       
   193         } while ( ContinueAfterRelocation() );
       
   194 
       
   195     if ( destroyed )
       
   196         {
       
   197         CleanupStack::Pop( this );
       
   198         }
       
   199     else
       
   200         {
       
   201         CleanupStack::PopAndDestroy( this );
       
   202         }
       
   203     }
       
   204 
       
   205 // --------------------------------------------------------------------------
       
   206 // CPbk2ContactEditorDlg::RequestExitL
       
   207 // --------------------------------------------------------------------------
       
   208 //
       
   209 void CPbk2ContactEditorDlg::RequestExitL( TInt aCommandId )
       
   210     {
       
   211     __ASSERT_DEBUG( iEliminator, Panic( ENullPointer ) );
       
   212     iEliminator->RequestExitL( aCommandId );
       
   213     }
       
   214 
       
   215 // --------------------------------------------------------------------------
       
   216 // CPbk2ContactEditorDlg::ForceExit
       
   217 // --------------------------------------------------------------------------
       
   218 //
       
   219 void CPbk2ContactEditorDlg::ForceExit()
       
   220     {
       
   221     if ( iEliminator )
       
   222         {
       
   223         iEliminator->ForceExit();
       
   224         }
       
   225     // The contact relocator should be destructed 
       
   226     // if the edit dialog has been destructed
       
   227     if ( iContactRelocator )
       
   228         {   	
       
   229         iRelocationState.ClearAll();
       
   230         delete iContactRelocator;
       
   231         iContactRelocator = NULL;
       
   232         }
       
   233     }
       
   234 
       
   235 // --------------------------------------------------------------------------
       
   236 // CPbk2ContactEditorDlg::ResetWhenDestroyed
       
   237 // --------------------------------------------------------------------------
       
   238 //
       
   239 void CPbk2ContactEditorDlg::ResetWhenDestroyed(
       
   240         MPbk2DialogEliminator** aSelfPtr )
       
   241     {
       
   242     __ASSERT_DEBUG(!aSelfPtr || *aSelfPtr == this,
       
   243         Panic(EPanicPreCond_ResetWhenDestroyed));
       
   244     iSelfPtr = aSelfPtr;  
       
   245     }
       
   246     
       
   247 // --------------------------------------------------------------------------
       
   248 // CPbk2ContactEditorDlg::ContactRelocatedL
       
   249 // --------------------------------------------------------------------------
       
   250 //
       
   251 void CPbk2ContactEditorDlg::ContactRelocatedL
       
   252         (MVPbkStoreContact* aRelocatedContact)
       
   253     {
       
   254     iStoreContact = aRelocatedContact; // take ownership
       
   255     }
       
   256 
       
   257 // --------------------------------------------------------------------------
       
   258 // CPbk2ContactEditorDlg::ContactRelocationFailed
       
   259 // --------------------------------------------------------------------------
       
   260 //
       
   261 void CPbk2ContactEditorDlg::ContactRelocationFailed
       
   262         ( TInt aReason, MVPbkStoreContact* aContact )
       
   263     {
       
   264     // Take the contact back
       
   265     iStoreContact = aContact;
       
   266     iAddItemFieldTypeResourceId = KErrNotFound;
       
   267     iAddItemFieldTypeXspName = NULL;
       
   268 
       
   269     if ( aReason != KErrCancel )
       
   270         {
       
   271         // Reset state
       
   272         iRelocationState.Set( ERelocationFailed );
       
   273         // No error note is to be shown to the user when she
       
   274         // manually cancels the relocation process, therefore
       
   275         // the error code must be converted
       
   276         CCoeEnv::Static()->HandleError( aReason );
       
   277         }
       
   278     else
       
   279         {
       
   280         // Relocation cancelled
       
   281         iRelocationState.Set( ERelocationCancelled );
       
   282         }
       
   283     }
       
   284 
       
   285 // --------------------------------------------------------------------------
       
   286 // CPbk2ContactEditorDlg::ContactsRelocationFailed
       
   287 // --------------------------------------------------------------------------
       
   288 //
       
   289 void CPbk2ContactEditorDlg::ContactsRelocationFailed
       
   290         ( TInt /*aReason*/, CVPbkContactLinkArray* /*aContacts*/ )
       
   291     {
       
   292     // Not called in editor case
       
   293     }
       
   294 
       
   295 // --------------------------------------------------------------------------
       
   296 // CPbk2ContactEditorDlg::RelocationProcessComplete
       
   297 // --------------------------------------------------------------------------
       
   298 //
       
   299 void CPbk2ContactEditorDlg::RelocationProcessComplete()
       
   300     {
       
   301     TRAPD( res, HandleRelocationProcessCompleteL() );
       
   302     if ( res != KErrNone )
       
   303         {
       
   304         // Shows system messages
       
   305         CCoeEnv::Static()->HandleError( res );
       
   306         // If application is not closed then at least destroy
       
   307         // the dialog
       
   308         iRelocationState.ClearAll();
       
   309         iRelocationState.Set( ERelocationFailed );
       
   310         delete iImplementation;
       
   311         iImplementation = NULL;
       
   312         }
       
   313     }
       
   314 
       
   315 // --------------------------------------------------------------------------
       
   316 // CPbk2ContactEditorDlg::RelocateContactL
       
   317 // --------------------------------------------------------------------------
       
   318 //
       
   319 TBool CPbk2ContactEditorDlg::RelocateContactL(
       
   320         TPbk2RelocationQyeryPolicy aQueryPolicy )
       
   321     {
       
   322     TBool result = RelocateContactL( KErrNotFound, KNullDesC, aQueryPolicy );
       
   323     // Clear the add item state because this is called in other cases than
       
   324     // relocation due to add item.
       
   325     iRelocationState.Clear( ERelocationDueToItemAddition );
       
   326     
       
   327     return result;
       
   328     }
       
   329 
       
   330 // --------------------------------------------------------------------------
       
   331 // CPbk2ContactEditorDlg::RelocateContactL
       
   332 // --------------------------------------------------------------------------
       
   333 //
       
   334 TBool CPbk2ContactEditorDlg::RelocateContactL( 
       
   335         TInt aAddItemFieldTypeResourceId,
       
   336         const TDesC& aAddItemXspName,
       
   337         TPbk2RelocationQyeryPolicy aQueryPolicy )
       
   338     {
       
   339     iRelocationState.ClearAll();
       
   340     delete iContactRelocator;
       
   341     iContactRelocator = NULL;
       
   342     iContactRelocator = CPbk2ContactRelocator::NewL();
       
   343 
       
   344     TBool result = EFalse;
       
   345     if (iContactRelocator->IsPhoneMemoryInConfigurationL())
       
   346         {
       
   347         CPbk2ContactRelocator::TFlags flags =
       
   348             CPbk2ContactRelocator::EPbk2RelocatorExistingContact;
       
   349         if ( iParams.iFlags & TPbk2ContactEditorParams::ENewContact )
       
   350             {
       
   351             flags = CPbk2ContactRelocator::EPbk2RelocatorNewContact;
       
   352             }
       
   353 
       
   354         result = iContactRelocator->RelocateAndLockContactL(
       
   355             iStoreContact, *this,
       
   356             aQueryPolicy,
       
   357             flags );
       
   358         iStoreContact = NULL; // relocator took away ownership
       
   359         iAddItemFieldTypeResourceId = aAddItemFieldTypeResourceId;
       
   360         if (aAddItemXspName != KNullDesC())
       
   361             {
       
   362             delete iAddItemFieldTypeXspName;
       
   363             iAddItemFieldTypeXspName = NULL;
       
   364             iAddItemFieldTypeXspName = aAddItemXspName.AllocL();
       
   365             }
       
   366         // else not needed because iAddItemFieldTypeXspName is NULL
       
   367 
       
   368         /// Dialog must be started again if relocation is done due to
       
   369         /// item addition.
       
   370         if ( iContactRelocator )
       
   371             {
       
   372             iRelocationState.Set( ERelocationDueToItemAddition );
       
   373             }
       
   374         }
       
   375     return result;        
       
   376     }
       
   377 
       
   378 // --------------------------------------------------------------------------
       
   379 // CPbk2ContactEditorDlg::IsPhoneMemoryInConfigurationL
       
   380 // --------------------------------------------------------------------------
       
   381 //
       
   382 TBool CPbk2ContactEditorDlg::IsPhoneMemoryInConfigurationL()
       
   383     {
       
   384     CPbk2ContactRelocator* contactRelocator = CPbk2ContactRelocator::NewL();
       
   385     CleanupStack::PushL( contactRelocator );
       
   386     TBool ret = contactRelocator->IsPhoneMemoryInConfigurationL();
       
   387     CleanupStack::PopAndDestroy( contactRelocator );
       
   388     return ret;
       
   389     }
       
   390 
       
   391 // --------------------------------------------------------------------------
       
   392 // CPbk2ContactEditorDlg::IsTemplateFieldL
       
   393 // --------------------------------------------------------------------------
       
   394 //
       
   395 TBool CPbk2ContactEditorDlg::IsTemplateFieldL( TInt aResId,
       
   396         const TDesC& aXSpName )
       
   397     {
       
   398     TBool result( EFalse );
       
   399     const MVPbkFieldType* fieldType =
       
   400         Phonebook2::Pbk2AppUi()->ApplicationServices().ContactManager().
       
   401             FieldTypes().Find( aResId );
       
   402     if ( fieldType )
       
   403         {
       
   404         const MPbk2FieldProperty* fieldProp =
       
   405             iFieldProperties->FindProperty( *fieldType, aXSpName );
       
   406         if ( fieldProp
       
   407             && ( fieldProp->Flags() & KPbk2FieldFlagTemplateField ) )
       
   408             {
       
   409             result = ETrue;
       
   410             }
       
   411         }
       
   412     return result;
       
   413     }
       
   414 
       
   415 // --------------------------------------------------------------------------
       
   416 // CPbk2ContactEditorDlg::EditorReadyL
       
   417 // --------------------------------------------------------------------------
       
   418 //
       
   419 void CPbk2ContactEditorDlg::EditorReadyL()
       
   420     {
       
   421     // Editor is ready
       
   422     if (iAddItemFieldTypeResourceId != KErrNotFound)
       
   423         {
       
   424         TPtrC xSpName = iAddItemFieldTypeXspName ? *iAddItemFieldTypeXspName :
       
   425                 KNullDesC();
       
   426         // If new field is template field in relocated contact,
       
   427         // do not add new field. Just focus the field in contact.
       
   428         if ( IsTemplateFieldL( iAddItemFieldTypeResourceId, xSpName ) )
       
   429             {
       
   430             iImplementation->TryChangeFocusWithTypeIdL
       
   431                 ( iAddItemFieldTypeResourceId, xSpName );
       
   432             }
       
   433         else
       
   434             {
       
   435             // Lets run the add item dialog silently
       
   436             iImplementation->AddItemToContactL
       
   437                 ( iAddItemFieldTypeResourceId, xSpName );
       
   438             }
       
   439         }
       
   440     }
       
   441 
       
   442 // --------------------------------------------------------------------------
       
   443 // CPbk2ContactEditorDlg::ContactEditingComplete
       
   444 //
       
   445 // aEditedContact is commented because it is called from the
       
   446 // CPbk2ContactEditorDlgImpl who actually don't own it. So against
       
   447 // observer documentation ownership is not changed. This is
       
   448 // an implementation detail of
       
   449 // CPbk2ContactEditorDlg <-> CPbk2ContactEditorDlgImpl
       
   450 // --------------------------------------------------------------------------
       
   451 //
       
   452 void CPbk2ContactEditorDlg::ContactEditingComplete(
       
   453         MVPbkStoreContact* /*aEditedContact*/ )
       
   454     {
       
   455     // Don't inform observer if the dialog need to be run again
       
   456     if ( !ContinueAfterRelocation() )
       
   457         {
       
   458         // Give ownership of the iStoreContact to the observer
       
   459         MVPbkStoreContact* contact = iStoreContact;
       
   460         iStoreContact = NULL;
       
   461         iContactObserver.ContactEditingComplete( contact );
       
   462         }
       
   463     }
       
   464 
       
   465 // --------------------------------------------------------------------------
       
   466 // CPbk2ContactEditorDlg::ContactEditingDeletedContact
       
   467 //
       
   468 // aEditedContact is commented because it is called from the
       
   469 // CPbk2ContactEditorDlgImpl who actually don't own it. So against
       
   470 // observer documentation ownership is not changed. This is
       
   471 // an implementation detail of
       
   472 // CPbk2ContactEditorDlg <-> CPbk2ContactEditorDlgImpl
       
   473 // --------------------------------------------------------------------------
       
   474 //
       
   475 void CPbk2ContactEditorDlg::ContactEditingDeletedContact(
       
   476     MVPbkStoreContact* /*aEditedContact*/ )
       
   477     {
       
   478     // Don't inform observer if the dialog need to be run again
       
   479     if ( !ContinueAfterRelocation() )
       
   480         {
       
   481         // Give ownership of the iStoreContact to the observer
       
   482         MVPbkStoreContact* contact = iStoreContact;
       
   483         iStoreContact = NULL;
       
   484         iContactObserver.ContactEditingDeletedContact( contact );
       
   485         }
       
   486     }
       
   487 
       
   488 // --------------------------------------------------------------------------
       
   489 // CPbk2ContactEditorDlg::ContactEditingAborted
       
   490 // --------------------------------------------------------------------------
       
   491 //
       
   492 void CPbk2ContactEditorDlg::ContactEditingAborted()
       
   493     {
       
   494     // Forward from implementation dialog to the actual client
       
   495     iContactObserver.ContactEditingAborted();
       
   496     }
       
   497 
       
   498 // --------------------------------------------------------------------------
       
   499 // CPbk2ContactEditorDlg::HandleRelocationProcessCompleteL
       
   500 // --------------------------------------------------------------------------
       
   501 //
       
   502 void CPbk2ContactEditorDlg::HandleRelocationProcessCompleteL()
       
   503     {
       
   504     if ( !iRelocationState.IsSet( ERelocationCancelled ) &&
       
   505          !iRelocationState.IsSet( ERelocationFailed ) )
       
   506         {
       
   507         // Update contact
       
   508         CreatePresentationContactL();
       
   509 
       
   510         // Contact has been relocated which means that the state changes
       
   511         // from creating a new contact to editing an relocated contact.
       
   512 
       
   513         // Remove the new contact flag...
       
   514         iParams.iFlags &=  ~TPbk2ContactEditorParams::ENewContact;
       
   515         // ... and set the editing flag
       
   516         iParams.iFlags |= TPbk2ContactEditorParams::EModified;
       
   517         // Update strategy
       
   518         delete iEditorStrategy;
       
   519         iEditorStrategy = NULL;
       
   520         iEditorStrategy = Pbk2ContactEditorStrategyFactory::CreateL
       
   521             ( iParams, iContact );
       
   522 
       
   523         // Set iFocusedContactField to NULL so that
       
   524         // the right field (new field) will be focused
       
   525         iParams.iFocusedContactField = NULL;
       
   526 
       
   527         TBool informObserver = EFalse;
       
   528         if ( !iRelocationState.IsSet( ERelocationDueToItemAddition ) )
       
   529             {
       
   530             informObserver = ETrue;
       
   531             }
       
   532         // Delete current implementation dialog nicely and create
       
   533         // a new dialog in ExecuteLD if needed.        
       
   534         iImplementation->CloseWithoutSaving( informObserver );
       
   535         }
       
   536     else
       
   537         {
       
   538         // Reset state if dialog is not closed -> continued with old contact
       
   539         iRelocationState.ClearAll();
       
   540         }
       
   541     }
       
   542 
       
   543 // --------------------------------------------------------------------------
       
   544 // CPbk2ContactEditorDlg::CreatePresentationContactL
       
   545 // --------------------------------------------------------------------------
       
   546 //
       
   547 void CPbk2ContactEditorDlg::CreatePresentationContactL()
       
   548     {
       
   549     CreatePresentationContactL( *iStoreContact );
       
   550     }
       
   551 
       
   552 // --------------------------------------------------------------------------
       
   553 // CPbk2ContactEditorDlg::CreatePresentationContactL
       
   554 // --------------------------------------------------------------------------
       
   555 //
       
   556 void CPbk2ContactEditorDlg::CreatePresentationContactL(
       
   557         MVPbkStoreContact& aStoreContact)
       
   558     {
       
   559     delete iSpecificFieldProperties;
       
   560     iSpecificFieldProperties = NULL;
       
   561     delete iFieldProperties;
       
   562     iFieldProperties = NULL;
       
   563     
       
   564     const MVPbkFieldTypeList& supportedFieldTypes =
       
   565         aStoreContact.ParentStore().StoreProperties().SupportedFields();
       
   566 
       
   567     //If custom fields are provided (social phonebook)
       
   568     if( iEditorFieldsId != KErrNotFound )
       
   569     	{
       
   570     	HBufC8* res = CCoeEnv::Static()->AllocReadResourceAsDes8L( iEditorFieldsId );
       
   571     	CleanupStack::PushL( res );
       
   572     	TResourceReader reader;
       
   573     	reader.SetBuffer( res );
       
   574     	// Create a field property list of the provided fields on reader
       
   575 		iFieldProperties = CPbk2FieldPropertyArray::NewL
       
   576 		   ( supportedFieldTypes, reader, CCoeEnv::Static()->FsSession() );
       
   577 		CleanupStack::PopAndDestroy( res );
       
   578 		}
       
   579     else
       
   580     	{
       
   581     	// Create a field property list of the supported
       
   582 		// field types of the used store
       
   583 		iFieldProperties = CPbk2FieldPropertyArray::NewL
       
   584 			( supportedFieldTypes, CCoeEnv::Static()->FsSession() );
       
   585     	}
       
   586     
       
   587     // if iAppServices is set. This is used if EditorDlg is used outside of Pbk2 context
       
   588     if( iAppServices )
       
   589     	{
       
   590     	iSpecificFieldProperties = CPbk2StoreSpecificFieldPropertyArray::NewL
       
   591 			( *iFieldProperties,
       
   592 			  iAppServices->StoreProperties(),
       
   593 			  supportedFieldTypes, aStoreContact.ParentStore() );
       
   594     	}
       
   595     else
       
   596     	{
       
   597     	iSpecificFieldProperties = CPbk2StoreSpecificFieldPropertyArray::NewL
       
   598 			( *iFieldProperties,
       
   599 			  Phonebook2::Pbk2AppUi()->ApplicationServices().StoreProperties(),
       
   600 			  supportedFieldTypes, aStoreContact.ParentStore() );
       
   601     	}
       
   602 
       
   603     delete iContact;
       
   604     iContact = NULL;
       
   605     iContact = CPbk2PresentationContact::NewL
       
   606         ( aStoreContact, *iSpecificFieldProperties );
       
   607     }
       
   608 
       
   609 // --------------------------------------------------------------------------
       
   610 // CPbk2ContactEditorDlg::ContinueAfterRelocation
       
   611 // --------------------------------------------------------------------------
       
   612 //
       
   613 TBool CPbk2ContactEditorDlg::ContinueAfterRelocation()
       
   614     {
       
   615     TBool ret = EFalse;
       
   616 
       
   617     // Currently 4 ways to continue after relocation:
       
   618     // 1) User cancels relocation -> editor stays open with the OLD contact.
       
   619     // 2) Relocation done due to add item and user approves
       
   620     //    relocation -> editor stays open with the NEW contact
       
   621     // 3) Relocation done due to other reason than add item.
       
   622     //    User approves relocation -> editor is closed.
       
   623     // 4) Error case
       
   624 
       
   625     if ( iRelocationState.IsSet( ERelocationDueToItemAddition ) &&
       
   626          !iRelocationState.IsSet( ERelocationCancelled ) &&
       
   627          !iRelocationState.IsSet( ERelocationFailed )  )
       
   628         {
       
   629         // Continue only in case 2
       
   630         ret = ETrue;
       
   631         }
       
   632 
       
   633     return ret;
       
   634     }
       
   635 
       
   636 // End of File