phonebookui/Phonebook2/UIPolicy/src/CPbk2ContactCopyPolicy.cpp
changeset 0 e686773b3f54
child 68 9da50d567e3c
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2002-2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Phonebook 2 contact copy policy.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "CPbk2ContactCopyPolicy.h"
       
    20 
       
    21 // Phonebook 2
       
    22 #include <MPbk2FieldProperty.h>
       
    23 #include <MPbk2ContactNameFormatter.h>
       
    24 #include <Pbk2ContactNameFormatterFactory.h>
       
    25 #include <CPbk2SortOrderManager.h>
       
    26 #include <CPbk2FieldPropertyArray.h>
       
    27 #include <CPbk2PresentationContact.h>
       
    28 #include <CPbk2ContactMerge.h>
       
    29 #include <Pbk2ContactFieldCopy.h>
       
    30 #include <RPbk2LocalizedResourceFile.h>
       
    31 #include <Pbk2DataCaging.hrh>
       
    32 #include <Pbk2Presentation.rsg>
       
    33 
       
    34 // Virtual Phonebook
       
    35 #include <MVPbkContactFieldCopyObserver.h>
       
    36 #include <CVPbkContactFieldIterator.h>
       
    37 #include <CVPbkContactLinkArray.h>
       
    38 #include <CVPbkContactManager.h>
       
    39 #include <MVPbkContactFieldDateTimeData.h>
       
    40 #include <MVPbkContactFieldTextData.h>
       
    41 #include <MVPbkContactFieldBinaryData.h>
       
    42 #include <MVPbkContactFieldUriData.h>
       
    43 #include <MVPbkFieldType.h>
       
    44 #include <MVPbkContactStore.h>
       
    45 #include <MVPbkContactStoreProperties.h>
       
    46 #include <MVPbkContactObserver.h>
       
    47 #include <MVPbkContactCopyObserver.h>
       
    48 #include <MVPbkContactOperationBase.h>
       
    49 #include <MVPbkContactAttributeManager.h>
       
    50 #include <VPbkUtils.h>
       
    51 #include <VPbkEng.rsg>
       
    52 
       
    53 // System includes
       
    54 #include <coemain.h>
       
    55 
       
    56 /// Unnamed namespace for local definitions
       
    57 namespace {
       
    58 
       
    59 _LIT(KResourceFile, "pbk2presentation.rsc");
       
    60 
       
    61 
       
    62 /**
       
    63  * Add field operation.
       
    64  * Responsible for adding a field to given contact.
       
    65  */
       
    66 class CPbk2AddFieldOperation : public CActive,
       
    67                                public MVPbkContactOperationBase,
       
    68                                public MVPbkSetAttributeObserver
       
    69     {
       
    70     public: // Construction and destruction
       
    71 
       
    72         /**
       
    73          * Creates a new instance of this class.
       
    74          *
       
    75          * @param aCopyPolicy           Copy policy.
       
    76          * @param aContactManager       Contact manager.
       
    77          * @param aContact              Store contact.
       
    78          * @param aFieldType            Field type.
       
    79          * @param aFieldData            Field data.
       
    80          * @param aFieldLabel           Field label.
       
    81          * @param aContactAttribute     Contact attribute.
       
    82          * @param aCopyObserver         Copy observer.
       
    83          * @return  A new instance of this class.
       
    84          */
       
    85         static CPbk2AddFieldOperation* NewL(
       
    86                 CPbk2ContactCopyPolicy& aCopyPolicy,
       
    87                 CVPbkContactManager& aContactManager,
       
    88                 MVPbkStoreContact& aContact,
       
    89                 const MVPbkFieldType& aFieldType,
       
    90                 const TDateTime& aFieldData,
       
    91                 const TDesC* aFieldLabel,
       
    92                 const MVPbkContactAttribute* aContactAttribute,
       
    93                 MVPbkContactFieldCopyObserver& aCopyObserver );
       
    94 
       
    95         /**
       
    96          * Creates a new instance of this class.
       
    97          *
       
    98          * @param aCopyPolicy           Copy policy.
       
    99          * @param aContactManager       Contact manager.
       
   100          * @param aContact              Store contact.
       
   101          * @param aFieldType            Field type.
       
   102          * @param aFieldData            Field data.
       
   103          * @param aFieldLabel           Field label.
       
   104          * @param aContactAttribute     Contact attribute.
       
   105          * @param aCopyObserver         Copy observer.
       
   106          * @return  A new instance of this class.
       
   107          */
       
   108         static CPbk2AddFieldOperation* NewL(
       
   109                 CPbk2ContactCopyPolicy& aCopyPolicy,
       
   110                 CVPbkContactManager& aContactManager,
       
   111                 MVPbkStoreContact& aContact,
       
   112                 const MVPbkFieldType& aFieldType,
       
   113                 const TDesC& aFieldData,
       
   114                 const TDesC* aFieldLabel,
       
   115                 const MVPbkContactAttribute* aContactAttribute,
       
   116                 MVPbkContactFieldCopyObserver& aCopyObserver );
       
   117 
       
   118         /**
       
   119          * Creates a new instance of this class.
       
   120          *
       
   121          * @param aCopyPolicy           Copy policy.
       
   122          * @param aContactManager       Contact manager.
       
   123          * @param aContact              Store contact.
       
   124          * @param aFieldType            Field type.
       
   125          * @param aFieldData            Field data.
       
   126          * @param aFieldLabel           Field label.
       
   127          * @param aContactAttribute     Contact attribute.
       
   128          * @param aCopyObserver         Copy observer.
       
   129          * @return  A new instance of this class.
       
   130          */
       
   131         static CPbk2AddFieldOperation* NewL(
       
   132                 CPbk2ContactCopyPolicy& aCopyPolicy,
       
   133                 CVPbkContactManager& aContactManager,
       
   134                 MVPbkStoreContact& aContact,
       
   135                 const MVPbkFieldType& aFieldType,
       
   136                 const TDesC8& aFieldData,
       
   137                 const TDesC* aFieldLabel,
       
   138                 const MVPbkContactAttribute* aContactAttribute,
       
   139                 MVPbkContactFieldCopyObserver& aCopyObserver );
       
   140 
       
   141         /**
       
   142          * Destructor.
       
   143          */
       
   144         ~CPbk2AddFieldOperation();
       
   145 
       
   146     public: // From CActive
       
   147         void RunL();
       
   148         void DoCancel();
       
   149         TInt RunError(
       
   150                 TInt aError );
       
   151 
       
   152     public: // From MVPbkSetAttributeObserver
       
   153         void AttributeOperationComplete(
       
   154                 MVPbkContactOperationBase& aOperation );
       
   155         void AttributeOperationFailed(
       
   156                 MVPbkContactOperationBase& aOperation,
       
   157                 TInt aError );
       
   158 
       
   159     private: // Implementation
       
   160         CPbk2AddFieldOperation(
       
   161                 CPbk2ContactCopyPolicy& aCopyPolicy,
       
   162                 CVPbkContactManager& aContactManager );
       
   163         void CommonConstructL(
       
   164                 MVPbkStoreContact& aContact,
       
   165                 const MVPbkFieldType& aFieldType,
       
   166                 const TDesC* aFieldLabel,
       
   167                 const MVPbkContactAttribute* aContactAttribute,
       
   168                 MVPbkContactFieldCopyObserver& aCopyObserver );
       
   169         TBool CanAddFieldL(
       
   170                 MVPbkStoreContact& aContact,
       
   171                 const MVPbkFieldType& aFieldType );
       
   172         void IssueRequest();
       
   173 
       
   174     private: // Data
       
   175         /// Ref: Copy policy
       
   176         CPbk2ContactCopyPolicy& iCopyPolicy;
       
   177         /// Ref: Contact manager
       
   178         CVPbkContactManager& iContactManager;
       
   179         /// Own: Field to be added
       
   180         MVPbkStoreContactField* iField;
       
   181         /// Ref: Contact to add the fields to
       
   182         MVPbkStoreContact* iContact;
       
   183         /// Ref: Copy observer
       
   184         MVPbkContactFieldCopyObserver* iCopyObserver;
       
   185         /// Ref: Contact attribute
       
   186         const MVPbkContactAttribute* iContactAttribute;
       
   187         /// Own: Attribute set operation
       
   188         MVPbkContactOperationBase* iSetOperation;
       
   189     };
       
   190 
       
   191 /**
       
   192  * Save contact operation.
       
   193  * Responsible for saving the contact to the target store.
       
   194  */
       
   195 class CPbk2SaveContactOperation : public CBase,
       
   196                                   public MVPbkContactOperationBase,
       
   197                                   public MVPbkContactObserver
       
   198     {
       
   199     public: // Construction and destruction
       
   200 
       
   201         /**
       
   202          * Creates a new instance of this class.
       
   203          *
       
   204          * @param aContactToCommit  Contact to commit.
       
   205          * @param aCopyObserver     Copy observer.
       
   206          * @param aFs               File server handle
       
   207          * @return  A new instance of this class.
       
   208          */
       
   209         static CPbk2SaveContactOperation* NewL(
       
   210                 MVPbkStoreContact* aContactToCommit,
       
   211                 MVPbkContactCopyObserver& aCopyObserver,
       
   212                 RFs& aFs );
       
   213 
       
   214         /**
       
   215          * Creates a new instance of this class.
       
   216          *
       
   217          * @param aSourceContact    Contact to copy.
       
   218          * @param aCopyObserver     Copy observer.
       
   219          * @param aTargetStore      Target store.
       
   220          * @param aFs               File server handle
       
   221          * @param aCopyNameToFirstName If source contact does not have
       
   222          *           first name field, name is copied to first name field.
       
   223          * @return  A new instance of this class.
       
   224          */
       
   225         static CPbk2SaveContactOperation* NewL(
       
   226                 MVPbkStoreContact& aSourceContact,
       
   227                 MVPbkContactCopyObserver& aCopyObserver,
       
   228                 MVPbkContactStore& aTargetStore,
       
   229                 RFs& aFs, 
       
   230                 TBool aCopyNameToFirstName );
       
   231         /**
       
   232          * Destructor.
       
   233          */
       
   234         ~CPbk2SaveContactOperation();
       
   235 
       
   236     public: // From MVPbkContactObserver
       
   237         void ContactOperationCompleted(
       
   238                 TContactOpResult aResult );
       
   239         void ContactOperationFailed(
       
   240                 TContactOp aOpCode,
       
   241                 TInt aErrorCode,
       
   242                 TBool aErrorNotified );
       
   243 
       
   244     private: // Implementation
       
   245         CPbk2SaveContactOperation(
       
   246                 MVPbkContactCopyObserver& aCopyObserver );
       
   247         void ConstructL(
       
   248                 MVPbkStoreContact& aContact,
       
   249                 MVPbkContactStore* aTargetStore, RFs& aFs, 
       
   250                 TBool aCopyNameToFirstName );
       
   251         void CopyContactDataL(
       
   252                 MVPbkStoreContact& aSourceContact,
       
   253                 MVPbkStoreContact& aTargetContact,
       
   254                 TBool aCopyNameToFirstName );
       
   255 
       
   256     private: // Data
       
   257         /// Ref: Copy observer
       
   258         MVPbkContactCopyObserver& iCopyObserver;
       
   259         /// Own: A new contact in case of a copy
       
   260         MVPbkStoreContact* iContact;
       
   261 
       
   262     };
       
   263 
       
   264 /**
       
   265  * Merge and save contact operation.
       
   266  * Responsible for merging contacts into a one.
       
   267  */
       
   268 class CPbk2MergeAndSaveOperation : public CActive,
       
   269                                    public MVPbkContactOperationBase,
       
   270                                    public MVPbkContactObserver
       
   271     {
       
   272     public: // Construction and destruction
       
   273 
       
   274         /**
       
   275          * Creates a new instance of this class.
       
   276          *
       
   277          * @param aContactMerge     Contact merger.
       
   278          * @param aSourceContacts   Source contacts to merge.
       
   279          * @param aTarget           Target contact.
       
   280          * @param aCopyObserver     Copy observer.
       
   281          * @return  A new instance of this class.
       
   282          */
       
   283         static CPbk2MergeAndSaveOperation* NewL(
       
   284                 CPbk2ContactMerge& aContactMerge,
       
   285                 RPointerArray<MVPbkStoreContact>& aSourceContacts,
       
   286                 MVPbkStoreContact& aTarget,
       
   287                 MVPbkContactCopyObserver& aCopyObserver );
       
   288 
       
   289         /**
       
   290          * Destructor.
       
   291          */
       
   292         ~CPbk2MergeAndSaveOperation();
       
   293 
       
   294     public: // From CActive
       
   295         void RunL();
       
   296         void DoCancel();
       
   297 
       
   298     public: // From MVPbkContactObserver
       
   299         void ContactOperationCompleted(
       
   300                 TContactOpResult aResult );
       
   301         void ContactOperationFailed(
       
   302                 TContactOp aOpCode,
       
   303                 TInt aErrorCode,
       
   304                 TBool aErrorNotified );
       
   305 
       
   306     private: // Implementation
       
   307         CPbk2MergeAndSaveOperation(
       
   308                 CPbk2ContactMerge& aContactMerge,
       
   309                 MVPbkStoreContact& aTarget,
       
   310                 MVPbkContactCopyObserver& aCopyObserver );
       
   311         void ConstructL(
       
   312                 RPointerArray<MVPbkStoreContact>& aSourceContacts );
       
   313         void IssueRequest();
       
   314         void MergeL();
       
   315         void HandleContactOperationL(
       
   316                 TContactOp aOpCode );
       
   317         void SendOperationCompleted();
       
   318 
       
   319     private: // Data
       
   320         /// Ref: Contact merger
       
   321         CPbk2ContactMerge& iContactMerge;
       
   322         /// Ref: The target of the merge
       
   323         MVPbkStoreContact& iTarget;
       
   324         /// Ref: Copy observer
       
   325         MVPbkContactCopyObserver& iCopyObserver;
       
   326         /// Own: Source contacts for the merge
       
   327         RPointerArray<MVPbkStoreContact> iSourceContacts;
       
   328         /// Own: Saved contacts
       
   329         CVPbkContactLinkArray* iResults;
       
   330     };
       
   331 
       
   332 /**
       
   333  * Copy titles operation.
       
   334  * Responsible for copying title fields.
       
   335  */
       
   336 class CPbk2CopyTitlesOperation : public CActive,
       
   337                                  public MVPbkContactOperationBase
       
   338     {
       
   339     public: // Construction and destruction
       
   340 
       
   341         /**
       
   342          * Creates a new instance of this class.
       
   343          *
       
   344          * @param aSourceContact    Source contact
       
   345          * @param aTargetContact    Target contact.
       
   346          * @param aCopyObserver     Copy observer.
       
   347          * @param aNameFormatter    Name formatter.
       
   348          * @return  A new instance of this class.
       
   349          */
       
   350         static CPbk2CopyTitlesOperation* NewL(
       
   351                 const MVPbkStoreContact& aSourceContact,
       
   352                 MVPbkStoreContact& aTargetContact,
       
   353                 MVPbkContactFieldsCopyObserver& aCopyObserver,
       
   354                 MPbk2ContactNameFormatter& aNameFormatter );
       
   355 
       
   356         /**
       
   357          * Destructor.
       
   358          */
       
   359         ~CPbk2CopyTitlesOperation();
       
   360 
       
   361     public: // From CActive
       
   362         void RunL();
       
   363         void DoCancel();
       
   364 
       
   365     private: // Implementation
       
   366         CPbk2CopyTitlesOperation(
       
   367                 const MVPbkStoreContact& aSourceContact,
       
   368                 MVPbkStoreContact& aTargetContact,
       
   369                 MVPbkContactFieldsCopyObserver& aCopyObserver,
       
   370                 MPbk2ContactNameFormatter& aNameFormatter );
       
   371         void ConstructL();
       
   372         void IssueRequest();
       
   373 
       
   374     private: // Data
       
   375         /// Ref: The source of the title fields
       
   376         const MVPbkStoreContact& iSourceContact;
       
   377         /// Ref: Target of the copy
       
   378         MVPbkStoreContact& iTargetContact;
       
   379         /// Ref: An observer for asynchronous operation
       
   380         MVPbkContactFieldsCopyObserver& iCopyObserver;
       
   381         /// Ref: The name formatter for title field checking
       
   382         MPbk2ContactNameFormatter& iNameFormatter;
       
   383     };
       
   384 
       
   385 // --------------------------------------------------------------------------
       
   386 // CPbk2AddFieldOperation::CPbk2AddFieldOperation
       
   387 // --------------------------------------------------------------------------
       
   388 //
       
   389 CPbk2AddFieldOperation::CPbk2AddFieldOperation(
       
   390         CPbk2ContactCopyPolicy& aCopyPolicy,
       
   391         CVPbkContactManager& aContactManager) :
       
   392             CActive(EPriorityStandard),
       
   393             iCopyPolicy(aCopyPolicy),
       
   394             iContactManager(aContactManager)
       
   395     {
       
   396     CActiveScheduler::Add(this);
       
   397     }
       
   398 
       
   399 // --------------------------------------------------------------------------
       
   400 // CPbk2AddFieldOperation::~CPbk2AddFieldOperation
       
   401 // --------------------------------------------------------------------------
       
   402 //
       
   403 CPbk2AddFieldOperation::~CPbk2AddFieldOperation()
       
   404     {
       
   405     Cancel();
       
   406     delete iField;
       
   407     delete iSetOperation;
       
   408     }
       
   409 
       
   410 // --------------------------------------------------------------------------
       
   411 // CPbk2AddFieldOperation::NewL
       
   412 // --------------------------------------------------------------------------
       
   413 //
       
   414 CPbk2AddFieldOperation* CPbk2AddFieldOperation::NewL(
       
   415         CPbk2ContactCopyPolicy& aCopyPolicy,
       
   416         CVPbkContactManager& aContactManager,
       
   417         MVPbkStoreContact& aContact,
       
   418         const MVPbkFieldType& aFieldType,
       
   419         const TDateTime& aFieldData,
       
   420         const TDesC* aFieldLabel,
       
   421         const MVPbkContactAttribute* aContactAttribute,
       
   422         MVPbkContactFieldCopyObserver& aCopyObserver)
       
   423     {
       
   424     CPbk2AddFieldOperation* self = new(ELeave) CPbk2AddFieldOperation(
       
   425             aCopyPolicy, aContactManager);
       
   426     CleanupStack::PushL(self);
       
   427     self->CommonConstructL
       
   428         (aContact, aFieldType, aFieldLabel,
       
   429         aContactAttribute, aCopyObserver);
       
   430     if (self->iField)
       
   431         {
       
   432         MVPbkContactFieldDateTimeData::Cast(
       
   433             self->iField->FieldData()).SetDateTime(aFieldData);
       
   434         }
       
   435     CleanupStack::Pop(self);
       
   436     return self;
       
   437     }
       
   438 
       
   439 // --------------------------------------------------------------------------
       
   440 // CPbk2AddFieldOperation::NewL
       
   441 // --------------------------------------------------------------------------
       
   442 //
       
   443 CPbk2AddFieldOperation* CPbk2AddFieldOperation::NewL(
       
   444         CPbk2ContactCopyPolicy& aCopyPolicy,
       
   445         CVPbkContactManager& aContactManager,
       
   446         MVPbkStoreContact& aContact,
       
   447         const MVPbkFieldType& aFieldType,
       
   448         const TDesC& aFieldData,
       
   449         const TDesC* aFieldLabel,
       
   450         const MVPbkContactAttribute* aContactAttribute,
       
   451         MVPbkContactFieldCopyObserver& aCopyObserver)
       
   452     {
       
   453     CPbk2AddFieldOperation* self = new(ELeave) CPbk2AddFieldOperation(
       
   454             aCopyPolicy, aContactManager);
       
   455     CleanupStack::PushL(self);
       
   456     self->CommonConstructL
       
   457         (aContact, aFieldType, aFieldLabel,
       
   458         aContactAttribute, aCopyObserver);
       
   459     if (self->iField)
       
   460         {
       
   461         if ( self->iField->FieldData().DataType() == EVPbkFieldStorageTypeText )
       
   462         	{
       
   463 	        MVPbkContactFieldTextData::Cast(
       
   464 	            self->iField->FieldData()).SetTextL(aFieldData);
       
   465         	}
       
   466 		else if ( self->iField->FieldData().DataType() == EVPbkFieldStorageTypeUri )
       
   467 	  	    {
       
   468 	        MVPbkContactFieldUriData::Cast(
       
   469 		            self->iField->FieldData()).SetUriL(aFieldData);
       
   470 	    	}        	
       
   471         }
       
   472         	        
       
   473     CleanupStack::Pop(self);
       
   474     return self;
       
   475     }
       
   476 
       
   477 // --------------------------------------------------------------------------
       
   478 // CPbk2AddFieldOperation::NewL
       
   479 // --------------------------------------------------------------------------
       
   480 //
       
   481 CPbk2AddFieldOperation* CPbk2AddFieldOperation::NewL(
       
   482         CPbk2ContactCopyPolicy& aCopyPolicy,
       
   483         CVPbkContactManager& aContactManager,
       
   484         MVPbkStoreContact& aContact,
       
   485         const MVPbkFieldType& aFieldType,
       
   486         const TDesC8& aFieldData,
       
   487         const TDesC* aFieldLabel,
       
   488         const MVPbkContactAttribute* aContactAttribute,
       
   489         MVPbkContactFieldCopyObserver& aCopyObserver)
       
   490     {
       
   491     CPbk2AddFieldOperation* self = new(ELeave) CPbk2AddFieldOperation(
       
   492             aCopyPolicy, aContactManager);
       
   493     CleanupStack::PushL(self);
       
   494     self->CommonConstructL(aContact, aFieldType, aFieldLabel,
       
   495             aContactAttribute, aCopyObserver);
       
   496     if (self->iField)
       
   497         {
       
   498         MVPbkContactFieldBinaryData::Cast(
       
   499             self->iField->FieldData()).SetBinaryDataL(aFieldData);
       
   500         }
       
   501     CleanupStack::Pop(self);
       
   502     return self;
       
   503     }
       
   504 
       
   505 // --------------------------------------------------------------------------
       
   506 // CPbk2AddFieldOperation::CommonConstructL
       
   507 // --------------------------------------------------------------------------
       
   508 //
       
   509 void CPbk2AddFieldOperation::CommonConstructL(
       
   510         MVPbkStoreContact& aContact,
       
   511         const MVPbkFieldType& aFieldType,
       
   512         const TDesC* aFieldLabel,
       
   513         const MVPbkContactAttribute* aContactAttribute,
       
   514         MVPbkContactFieldCopyObserver& aCopyObserver)
       
   515     {
       
   516     if (iCopyObserver)
       
   517         {
       
   518         User::Leave(KErrInUse);
       
   519         }
       
   520     iContactAttribute = aContactAttribute;
       
   521     iCopyObserver = &aCopyObserver;
       
   522     iContact = &aContact;
       
   523     delete iField;
       
   524     iField = NULL;
       
   525 
       
   526     if (CanAddFieldL(aContact, aFieldType))
       
   527         {
       
   528         iField = aContact.CreateFieldLC(aFieldType);
       
   529         CleanupStack::Pop();
       
   530         if (aFieldLabel && aFieldLabel->Length() > 0)
       
   531             {
       
   532             iField->SetFieldLabelL(*aFieldLabel);
       
   533             }
       
   534         }
       
   535     IssueRequest();
       
   536     }
       
   537 
       
   538 // --------------------------------------------------------------------------
       
   539 // CPbk2AddFieldOperation::RunL
       
   540 // --------------------------------------------------------------------------
       
   541 //
       
   542 void CPbk2AddFieldOperation::RunL()
       
   543     {
       
   544     // If both are set, add the attribute first because the AddFieldL
       
   545     // takes the ownership of the iField.
       
   546     if (iField && iContactAttribute)
       
   547         {
       
   548         // if contact attribute is set, set it for the field
       
   549         iSetOperation =
       
   550             iContactManager.ContactAttributeManagerL().SetFieldAttributeL(
       
   551                 *iField, *iContactAttribute, *this);
       
   552         // If the operation wont be created, try to add the field atleast.
       
   553         if (!iSetOperation)
       
   554             {
       
   555             iContactAttribute = NULL;
       
   556             IssueRequest();
       
   557             }
       
   558         }
       
   559     else if(iField && !iContactAttribute)
       
   560         {
       
   561         iContact->AddFieldL(iField);
       
   562         iField = NULL; // Ownership taken by iContact
       
   563         iCopyObserver->FieldAddedToContact(*this);
       
   564         }
       
   565     else if (!iField)
       
   566         {
       
   567         // If field can not be added to contact, inform client
       
   568         iCopyObserver->FieldAddingFailed(*this, KErrNotSupported);
       
   569         }
       
   570     }
       
   571 
       
   572 // --------------------------------------------------------------------------
       
   573 // CPbk2AddFieldOperation::DoCancel
       
   574 // --------------------------------------------------------------------------
       
   575 //
       
   576 void CPbk2AddFieldOperation::DoCancel()
       
   577     {
       
   578     }
       
   579 
       
   580 // --------------------------------------------------------------------------
       
   581 // CPbk2AddFieldOperation::RunError
       
   582 // --------------------------------------------------------------------------
       
   583 //
       
   584 TInt CPbk2AddFieldOperation::RunError(TInt aError)
       
   585     {
       
   586     iCopyObserver->FieldAddingFailed(*this, aError);
       
   587     return KErrNone;
       
   588     }
       
   589 
       
   590 // --------------------------------------------------------------------------
       
   591 // CPbk2AddFieldOperation::AttributeOperationComplete
       
   592 // --------------------------------------------------------------------------
       
   593 //
       
   594 void CPbk2AddFieldOperation::AttributeOperationComplete(
       
   595     MVPbkContactOperationBase& aOperation)
       
   596     {
       
   597     if (iSetOperation == &aOperation)
       
   598         {
       
   599         delete iSetOperation;
       
   600         iSetOperation = NULL;
       
   601 
       
   602         // Attribute has been set. Set to NULL to indicate that.
       
   603         iContactAttribute = NULL;
       
   604         IssueRequest();
       
   605         }
       
   606     }
       
   607 
       
   608 // --------------------------------------------------------------------------
       
   609 // CPbk2AddFieldOperation::AttributeOperationFailed
       
   610 // --------------------------------------------------------------------------
       
   611 //
       
   612 void CPbk2AddFieldOperation::AttributeOperationFailed(
       
   613     MVPbkContactOperationBase& aOperation, TInt aError)
       
   614     {
       
   615     if (iSetOperation == &aOperation)
       
   616         {
       
   617         delete iSetOperation;
       
   618         iSetOperation = NULL;
       
   619         iCopyObserver->FieldAddingFailed(*this, aError);
       
   620         }
       
   621     }
       
   622 
       
   623 // --------------------------------------------------------------------------
       
   624 // CPbk2AddFieldOperation::CanAddFieldL
       
   625 // --------------------------------------------------------------------------
       
   626 //
       
   627 TBool CPbk2AddFieldOperation::CanAddFieldL(
       
   628         MVPbkStoreContact& aContact, const MVPbkFieldType& aFieldType)
       
   629     {
       
   630     const MPbk2FieldProperty* fieldProperty =
       
   631         iCopyPolicy.FieldProperties().FindProperty(aFieldType);
       
   632     if (fieldProperty)
       
   633         {
       
   634         if (fieldProperty->Multiplicity() == EPbk2FieldMultiplicityOne)
       
   635             {
       
   636             const MVPbkStoreContactFieldCollection& fields =
       
   637                 aContact.Fields();
       
   638             const TInt fieldCount = fields.FieldCount();
       
   639 
       
   640             const TInt maxMatchPriority =
       
   641                 iContactManager.FieldTypes().MaxMatchPriority();
       
   642             for (TInt matchPriority = 0;
       
   643                     matchPriority <= maxMatchPriority; ++matchPriority)
       
   644                 {
       
   645                 for (TInt i = 0; i < fieldCount; ++i)
       
   646                     {
       
   647                     const MVPbkFieldType* fieldType =
       
   648                             fields.FieldAt(i).MatchFieldType(matchPriority);
       
   649                     if (fieldType && fieldType->IsSame(aFieldType))
       
   650                         {
       
   651                         return EFalse;
       
   652                         }
       
   653                     }
       
   654                 }
       
   655             }
       
   656         }
       
   657 
       
   658     return ETrue;
       
   659     }
       
   660 
       
   661 // --------------------------------------------------------------------------
       
   662 // CPbk2AddFieldOperation::IssueRequest
       
   663 // --------------------------------------------------------------------------
       
   664 //
       
   665 void CPbk2AddFieldOperation::IssueRequest()
       
   666     {
       
   667     TRequestStatus* status = &iStatus;
       
   668     User::RequestComplete(status, KErrNone);
       
   669     SetActive();
       
   670     }
       
   671 
       
   672 // --------------------------------------------------------------------------
       
   673 // CPbk2SaveContactOperation::CPbk2SaveContactOperation
       
   674 // --------------------------------------------------------------------------
       
   675 //
       
   676 CPbk2SaveContactOperation::CPbk2SaveContactOperation(
       
   677         MVPbkContactCopyObserver& aCopyObserver) :
       
   678             iCopyObserver(aCopyObserver)
       
   679     {
       
   680     }
       
   681 
       
   682 // --------------------------------------------------------------------------
       
   683 // CPbk2SaveContactOperation::~CPbk2SaveContactOperation
       
   684 // --------------------------------------------------------------------------
       
   685 //
       
   686 CPbk2SaveContactOperation::~CPbk2SaveContactOperation()
       
   687     {
       
   688     delete iContact;
       
   689     }
       
   690 
       
   691 // --------------------------------------------------------------------------
       
   692 // CPbk2SaveContactOperation::NewL
       
   693 // --------------------------------------------------------------------------
       
   694 //
       
   695 CPbk2SaveContactOperation* CPbk2SaveContactOperation::NewL(
       
   696         MVPbkStoreContact* aContactToCommit,
       
   697         MVPbkContactCopyObserver& aCopyObserver,
       
   698         RFs& aFs)
       
   699     {
       
   700     CPbk2SaveContactOperation* self = new(ELeave) CPbk2SaveContactOperation(
       
   701         aCopyObserver);
       
   702     CleanupStack::PushL(self);
       
   703     self->ConstructL(*aContactToCommit, NULL, aFs, EFalse);
       
   704     // Take ownership
       
   705     self->iContact = aContactToCommit;
       
   706     CleanupStack::Pop(self);
       
   707     return self;
       
   708     }
       
   709 
       
   710 // --------------------------------------------------------------------------
       
   711 // CPbk2SaveContactOperation::NewL
       
   712 // --------------------------------------------------------------------------
       
   713 //
       
   714 CPbk2SaveContactOperation* CPbk2SaveContactOperation::NewL(
       
   715         MVPbkStoreContact& aSourceContact,
       
   716         MVPbkContactCopyObserver& aCopyObserver,
       
   717         MVPbkContactStore& aTargetStore,
       
   718         RFs& aFs,
       
   719         TBool aCopyNameToFirstName )
       
   720     {
       
   721     CPbk2SaveContactOperation* self = new(ELeave) CPbk2SaveContactOperation(
       
   722         aCopyObserver);
       
   723     CleanupStack::PushL(self);
       
   724     self->ConstructL(aSourceContact, &aTargetStore, aFs, aCopyNameToFirstName );
       
   725     CleanupStack::Pop(self);
       
   726     return self;
       
   727     }
       
   728 
       
   729 // --------------------------------------------------------------------------
       
   730 // CPbk2SaveContactOperation::ConstructL
       
   731 // --------------------------------------------------------------------------
       
   732 //
       
   733 void CPbk2SaveContactOperation::ConstructL(
       
   734         MVPbkStoreContact& aContact,
       
   735         MVPbkContactStore* aTargetStore,
       
   736         RFs& aFs,
       
   737         TBool aCopyNameToFirstName )
       
   738     {
       
   739     if (aTargetStore)
       
   740         {
       
   741         iContact = aTargetStore->CreateNewContactLC();
       
   742         CleanupStack::Pop(); // data
       
   743         CopyContactDataL(aContact, *iContact, aCopyNameToFirstName );
       
   744 
       
   745         // Verify syncronization field existance and content
       
   746         VPbkUtils::VerifySyncronizationFieldL(
       
   747             aFs,
       
   748             iContact->ParentStore().StoreProperties().
       
   749             SupportedFields(), *iContact);
       
   750 
       
   751         iContact->CommitL(*this);
       
   752         }
       
   753     else
       
   754         {
       
   755         // Verify syncronization field existance and content
       
   756         VPbkUtils::VerifySyncronizationFieldL(
       
   757             aFs,
       
   758             aContact.ParentStore().StoreProperties().
       
   759             SupportedFields(), aContact);
       
   760 
       
   761         aContact.CommitL(*this);
       
   762         }
       
   763     }
       
   764 
       
   765 // --------------------------------------------------------------------------
       
   766 // CPbk2SaveContactOperation::ContactOperationCompleted
       
   767 // --------------------------------------------------------------------------
       
   768 //
       
   769 void CPbk2SaveContactOperation::ContactOperationCompleted
       
   770         ( TContactOpResult /*aResult*/ )
       
   771     {
       
   772     TRAPD( error,
       
   773         CVPbkContactLinkArray* linkArray = CVPbkContactLinkArray::NewLC();
       
   774         // Copying contacts to contact model data base
       
   775         // results always only one contact
       
   776         MVPbkContactLink* link = iContact->CreateLinkLC();
       
   777         linkArray->AppendL(link);
       
   778         CleanupStack::Pop(); // link
       
   779 
       
   780         // Ownership of array is given to observer
       
   781         iCopyObserver.ContactsSaved(*this, linkArray);
       
   782         CleanupStack::Pop(linkArray);
       
   783     ); // TRAPD
       
   784     if ( error != KErrNone )
       
   785         {
       
   786         iCopyObserver.ContactsSavingFailed(*this, error);
       
   787         }
       
   788     }
       
   789 
       
   790 // --------------------------------------------------------------------------
       
   791 // CPbk2SaveContactOperation::ContactOperationFailed
       
   792 // --------------------------------------------------------------------------
       
   793 //
       
   794 void CPbk2SaveContactOperation::ContactOperationFailed
       
   795         (TContactOp /*aOpCode*/,  TInt aErrorCode,
       
   796         TBool /*aErrorNotified*/)
       
   797     {
       
   798     iCopyObserver.ContactsSavingFailed(*this, aErrorCode);
       
   799     }
       
   800 
       
   801 // --------------------------------------------------------------------------
       
   802 // CPbk2SaveContactOperation::CopyContactDataL
       
   803 // --------------------------------------------------------------------------
       
   804 //
       
   805 void CPbk2SaveContactOperation::CopyContactDataL(
       
   806         MVPbkStoreContact& aSourceContact,
       
   807         MVPbkStoreContact& aTargetContact,
       
   808         TBool aCopyNameToFirstName )
       
   809     {
       
   810     const TInt maxMatchPriority = aSourceContact.ContactStore().
       
   811             StoreProperties().SupportedFields().MaxMatchPriority();
       
   812 
       
   813     // If source store does not support first name, copy last name to
       
   814     // first name if aCopyNameToFirstName is set
       
   815     TBool copyNameToFirstName( EFalse );
       
   816     if ( aCopyNameToFirstName )
       
   817         {
       
   818         const MVPbkFieldType* fieldType = 
       
   819             aSourceContact.ContactStore().StoreProperties().SupportedFields().
       
   820              Find( R_VPBK_FIELD_TYPE_FIRSTNAME );
       
   821         if ( !fieldType )
       
   822             {
       
   823             copyNameToFirstName = ETrue;
       
   824             }
       
   825         }
       
   826 
       
   827     MVPbkStoreContactFieldCollection& fields = aSourceContact.Fields();
       
   828     const TInt fieldCount = fields.FieldCount();
       
   829     for (TInt i = 0; i < fieldCount; ++i)
       
   830         {
       
   831         MVPbkStoreContactField& field = fields.FieldAt(i);
       
   832         const MVPbkFieldType* fieldType = NULL;
       
   833 
       
   834         for (TInt matchPriority = 0;
       
   835              !fieldType && matchPriority <= maxMatchPriority;
       
   836              ++matchPriority)
       
   837             {
       
   838             fieldType = field.MatchFieldType(matchPriority);
       
   839             }
       
   840 
       
   841         if (fieldType)
       
   842             {
       
   843             if ( copyNameToFirstName && fieldType->FieldTypeResId() == 
       
   844                  R_VPBK_FIELD_TYPE_LASTNAME )
       
   845                 {
       
   846                 const MVPbkFieldType* firstNamefieldType(
       
   847                             aTargetContact.ContactStore().
       
   848                             StoreProperties().SupportedFields().
       
   849                             Find( R_VPBK_FIELD_TYPE_FIRSTNAME ) );
       
   850                 // Change type to first name
       
   851                 if ( firstNamefieldType )
       
   852                     {
       
   853                     fieldType = firstNamefieldType;
       
   854                     }
       
   855                 }
       
   856             Pbk2ContactFieldCopy::CopyFieldL( field, *fieldType,
       
   857                 aTargetContact );
       
   858             }
       
   859         }
       
   860     }
       
   861 
       
   862 // --------------------------------------------------------------------------
       
   863 // CPbk2MergeAndSaveOperation::CPbk2MergeAndSaveOperation
       
   864 // --------------------------------------------------------------------------
       
   865 //
       
   866 CPbk2MergeAndSaveOperation::CPbk2MergeAndSaveOperation(
       
   867         CPbk2ContactMerge& aContactMerge,
       
   868         MVPbkStoreContact& aTarget,
       
   869         MVPbkContactCopyObserver& aCopyObserver ) :
       
   870             CActive( EPriorityStandard ),
       
   871             iContactMerge( aContactMerge ),
       
   872             iTarget( aTarget ),
       
   873             iCopyObserver( aCopyObserver )
       
   874     {
       
   875     }
       
   876 
       
   877 // --------------------------------------------------------------------------
       
   878 // CPbk2MergeAndSaveOperation::~CPbk2MergeAndSaveOperation
       
   879 // --------------------------------------------------------------------------
       
   880 //
       
   881 CPbk2MergeAndSaveOperation::~CPbk2MergeAndSaveOperation()
       
   882     {
       
   883     Cancel();
       
   884     delete iResults;
       
   885     iSourceContacts.ResetAndDestroy();
       
   886     }
       
   887 
       
   888 // --------------------------------------------------------------------------
       
   889 // CPbk2MergeAndSaveOperation::NewL
       
   890 // --------------------------------------------------------------------------
       
   891 //
       
   892 CPbk2MergeAndSaveOperation* CPbk2MergeAndSaveOperation::NewL(
       
   893         CPbk2ContactMerge& aContactMerge,
       
   894         RPointerArray<MVPbkStoreContact>& aSourceContacts,
       
   895         MVPbkStoreContact& aTarget,
       
   896         MVPbkContactCopyObserver& aCopyObserver )
       
   897     {
       
   898     CPbk2MergeAndSaveOperation* self =
       
   899         new( ELeave ) CPbk2MergeAndSaveOperation( aContactMerge, aTarget,
       
   900             aCopyObserver );
       
   901     CleanupStack::PushL( self );
       
   902     self->ConstructL( aSourceContacts );
       
   903     CleanupStack::Pop( self );
       
   904     return self;
       
   905     }
       
   906 
       
   907 // --------------------------------------------------------------------------
       
   908 // CPbk2MergeAndSaveOperation::ConstructL
       
   909 // --------------------------------------------------------------------------
       
   910 //
       
   911 void CPbk2MergeAndSaveOperation::ConstructL(
       
   912         RPointerArray<MVPbkStoreContact>& aSourceContacts )
       
   913     {
       
   914     CActiveScheduler::Add( this );
       
   915     iResults = CVPbkContactLinkArray::NewL();
       
   916 
       
   917     const TInt count = aSourceContacts.Count();
       
   918     for ( TInt i = count - 1; i >= 0; --i )
       
   919         {
       
   920         // Take ownerships of the contacts
       
   921         iSourceContacts.InsertL( aSourceContacts[i], 0 );
       
   922         aSourceContacts.Remove( i );
       
   923         }
       
   924 
       
   925     if ( iSourceContacts.Count() == 0 )
       
   926         {
       
   927         IssueRequest();
       
   928         }
       
   929     else
       
   930         {
       
   931         iTarget.LockL( *this );
       
   932         }
       
   933     }
       
   934 
       
   935 // --------------------------------------------------------------------------
       
   936 // CPbk2MergeAndSaveOperation::RunL
       
   937 // --------------------------------------------------------------------------
       
   938 //
       
   939 void CPbk2MergeAndSaveOperation::RunL()
       
   940     {
       
   941     SendOperationCompleted();
       
   942     }
       
   943 
       
   944 // --------------------------------------------------------------------------
       
   945 // CPbk2MergeAndSaveOperation::DoCancel
       
   946 // --------------------------------------------------------------------------
       
   947 //
       
   948 void CPbk2MergeAndSaveOperation::DoCancel()
       
   949     {
       
   950     }
       
   951 
       
   952 // --------------------------------------------------------------------------
       
   953 // CPbk2MergeAndSaveOperation::ContactOperationCompleted
       
   954 // --------------------------------------------------------------------------
       
   955 //
       
   956 void CPbk2MergeAndSaveOperation::ContactOperationCompleted(
       
   957         TContactOpResult aResult )
       
   958     {
       
   959     TRAPD( res, HandleContactOperationL( aResult.iOpCode ) );
       
   960     if ( res != KErrNone )
       
   961         {
       
   962         iCopyObserver.ContactsSavingFailed( *this, res );
       
   963         }
       
   964     }
       
   965 
       
   966 // --------------------------------------------------------------------------
       
   967 // CPbk2MergeAndSaveOperation::ContactOperationFailed
       
   968 // --------------------------------------------------------------------------
       
   969 //
       
   970 void CPbk2MergeAndSaveOperation::ContactOperationFailed(
       
   971         TContactOp /*aOpCode*/, TInt aErrorCode, TBool /*aErrorNotified*/ )
       
   972     {
       
   973     iCopyObserver.ContactsSavingFailed( *this, aErrorCode );
       
   974     }
       
   975 
       
   976 // --------------------------------------------------------------------------
       
   977 // CPbk2MergeAndSaveOperation::IssueRequest
       
   978 // --------------------------------------------------------------------------
       
   979 //
       
   980 void CPbk2MergeAndSaveOperation::IssueRequest()
       
   981     {
       
   982     TRequestStatus* st = &iStatus;
       
   983     User::RequestComplete( st, KErrNone );
       
   984     SetActive();
       
   985     }
       
   986 
       
   987 // --------------------------------------------------------------------------
       
   988 // CPbk2MergeAndSaveOperation::MergeL
       
   989 // --------------------------------------------------------------------------
       
   990 //
       
   991 void CPbk2MergeAndSaveOperation::MergeL()
       
   992     {
       
   993     const TInt fieldCount = iTarget.Fields().FieldCount();
       
   994     const TInt sourceCount = iSourceContacts.Count();
       
   995     for ( TInt i = sourceCount - 1; i >= 0; --i )
       
   996         {
       
   997         iContactMerge.MergeDataL( *iSourceContacts[i], iTarget );
       
   998         }
       
   999 
       
  1000     // The logic of the merge and save for contact model contacts is
       
  1001     // that if contact was merged somehow then the existing contact
       
  1002     // is committed and source contacts deleted. If there was nothing to
       
  1003     // merge then nothing is saved i.e. source contacts are ignored.
       
  1004     if ( iTarget.Fields().FieldCount() > fieldCount )
       
  1005         {
       
  1006         // Commit the existing contact
       
  1007         iTarget.CommitL( *this );
       
  1008         }
       
  1009     else
       
  1010         {
       
  1011         SendOperationCompleted();
       
  1012         }
       
  1013     }
       
  1014 
       
  1015 // --------------------------------------------------------------------------
       
  1016 // CPbk2MergeAndSaveOperation::HandleContactOperationL
       
  1017 // --------------------------------------------------------------------------
       
  1018 //
       
  1019 void CPbk2MergeAndSaveOperation::HandleContactOperationL
       
  1020         ( TContactOp aOpCode )
       
  1021     {
       
  1022     if ( aOpCode == EContactLock )
       
  1023         {
       
  1024         MergeL();
       
  1025         }
       
  1026     else if ( aOpCode == EContactCommit )
       
  1027         {
       
  1028         iResults->AppendL( iTarget.CreateLinkLC() );
       
  1029         CleanupStack::Pop(); // link
       
  1030         SendOperationCompleted();
       
  1031         }
       
  1032     else
       
  1033         {
       
  1034         // Should never come here
       
  1035         iCopyObserver.ContactsSavingFailed( *this, KErrUnknown );
       
  1036         }
       
  1037     }
       
  1038 
       
  1039 // --------------------------------------------------------------------------
       
  1040 // CPbk2MergeAndSaveOperation::SendOperationCompleted
       
  1041 // --------------------------------------------------------------------------
       
  1042 //
       
  1043 void CPbk2MergeAndSaveOperation::SendOperationCompleted()
       
  1044     {
       
  1045     CVPbkContactLinkArray* links = iResults;
       
  1046     iResults = NULL;
       
  1047     // Client takes the ownership of the links
       
  1048     iCopyObserver.ContactsSaved( *this, links );
       
  1049     }
       
  1050 
       
  1051 // --------------------------------------------------------------------------
       
  1052 // CPbk2CopyTitlesOperation::CPbk2CopyTitlesOperation
       
  1053 // --------------------------------------------------------------------------
       
  1054 //
       
  1055 CPbk2CopyTitlesOperation::CPbk2CopyTitlesOperation(
       
  1056         const MVPbkStoreContact& aSourceContact,
       
  1057         MVPbkStoreContact& aTargetContact,
       
  1058         MVPbkContactFieldsCopyObserver& aCopyObserver,
       
  1059         MPbk2ContactNameFormatter& aNameFormatter ) :
       
  1060             CActive( EPriorityStandard ),
       
  1061             iSourceContact( aSourceContact ),
       
  1062             iTargetContact( aTargetContact ),
       
  1063             iCopyObserver( aCopyObserver ),
       
  1064             iNameFormatter( aNameFormatter )
       
  1065     {
       
  1066     }
       
  1067 
       
  1068 // --------------------------------------------------------------------------
       
  1069 // CPbk2CopyTitlesOperation::~CPbk2CopyTitlesOperation
       
  1070 // --------------------------------------------------------------------------
       
  1071 //
       
  1072 CPbk2CopyTitlesOperation::~CPbk2CopyTitlesOperation()
       
  1073     {
       
  1074     Cancel();
       
  1075     }
       
  1076 
       
  1077 // --------------------------------------------------------------------------
       
  1078 // CPbk2CopyTitlesOperation::NewL
       
  1079 // --------------------------------------------------------------------------
       
  1080 //
       
  1081 CPbk2CopyTitlesOperation* CPbk2CopyTitlesOperation::NewL(
       
  1082         const MVPbkStoreContact& aSourceContact,
       
  1083         MVPbkStoreContact& aTargetContact,
       
  1084         MVPbkContactFieldsCopyObserver& aCopyObserver,
       
  1085         MPbk2ContactNameFormatter& aNameFormatter )
       
  1086     {
       
  1087     CPbk2CopyTitlesOperation* self =
       
  1088         new( ELeave ) CPbk2CopyTitlesOperation( aSourceContact, aTargetContact,
       
  1089             aCopyObserver, aNameFormatter );
       
  1090     CleanupStack::PushL( self );
       
  1091     self->ConstructL();
       
  1092     CleanupStack::Pop( self );
       
  1093     return self;
       
  1094     }
       
  1095 
       
  1096 // --------------------------------------------------------------------------
       
  1097 // CPbk2CopyTitlesOperation::ConstructL
       
  1098 // --------------------------------------------------------------------------
       
  1099 //
       
  1100 void CPbk2CopyTitlesOperation::ConstructL()
       
  1101     {
       
  1102     CActiveScheduler::Add( this );
       
  1103 
       
  1104     Pbk2ContactFieldCopy::CopyTitleFieldsL( iSourceContact,
       
  1105         iTargetContact, iNameFormatter );
       
  1106     IssueRequest();
       
  1107     }
       
  1108 
       
  1109 // --------------------------------------------------------------------------
       
  1110 // CPbk2CopyTitlesOperation::RunL
       
  1111 // --------------------------------------------------------------------------
       
  1112 //
       
  1113 void CPbk2CopyTitlesOperation::RunL()
       
  1114     {
       
  1115     iCopyObserver.FieldsCopiedToContact( *this );
       
  1116     }
       
  1117 
       
  1118 // --------------------------------------------------------------------------
       
  1119 // CPbk2CopyTitlesOperation::DoCancel
       
  1120 // --------------------------------------------------------------------------
       
  1121 //
       
  1122 void CPbk2CopyTitlesOperation::DoCancel()
       
  1123     {
       
  1124     }
       
  1125 
       
  1126 // --------------------------------------------------------------------------
       
  1127 // CPbk2CopyTitlesOperation::IssueRequest
       
  1128 // --------------------------------------------------------------------------
       
  1129 //
       
  1130 void CPbk2CopyTitlesOperation::IssueRequest()
       
  1131     {
       
  1132     TRequestStatus* st = &iStatus;
       
  1133     User::RequestComplete( st, KErrNone );
       
  1134     SetActive();
       
  1135     }
       
  1136 
       
  1137 } /// namespace
       
  1138 
       
  1139 
       
  1140 // --------------------------------------------------------------------------
       
  1141 // CPbk2ContactCopyPolicy::CPbk2ContactCopyPolicy
       
  1142 // --------------------------------------------------------------------------
       
  1143 //
       
  1144 CPbk2ContactCopyPolicy::CPbk2ContactCopyPolicy
       
  1145         ( CVPbkContactManager& aContactManager ) :
       
  1146             iContactManager(aContactManager)
       
  1147     {
       
  1148     }
       
  1149 
       
  1150 // --------------------------------------------------------------------------
       
  1151 // CPbk2ContactCopyPolicy::~CPbk2ContactCopyPolicy
       
  1152 // --------------------------------------------------------------------------
       
  1153 //
       
  1154 CPbk2ContactCopyPolicy::~CPbk2ContactCopyPolicy()
       
  1155     {
       
  1156     delete iContactMerge;
       
  1157     delete iFieldProperties;
       
  1158     delete iNameFormatter;
       
  1159     delete iSortOrderManager;
       
  1160     }
       
  1161 
       
  1162 // --------------------------------------------------------------------------
       
  1163 // CPbk2ContactCopyPolicy::NewL
       
  1164 // --------------------------------------------------------------------------
       
  1165 //
       
  1166 CPbk2ContactCopyPolicy* CPbk2ContactCopyPolicy::NewL( TParam* aParam )
       
  1167     {
       
  1168     CPbk2ContactCopyPolicy* self = new ( ELeave ) CPbk2ContactCopyPolicy
       
  1169         ( aParam->iContactManager );
       
  1170     CleanupStack::PushL( self );
       
  1171     self->ConstructL();
       
  1172     CleanupStack::Pop( self );
       
  1173     return self;
       
  1174     }
       
  1175 
       
  1176 // --------------------------------------------------------------------------
       
  1177 // CPbk2ContactCopyPolicy::ConstructL
       
  1178 // --------------------------------------------------------------------------
       
  1179 //
       
  1180 inline void CPbk2ContactCopyPolicy::ConstructL()
       
  1181     {
       
  1182 
       
  1183     iFieldProperties = CPbk2FieldPropertyArray::NewL
       
  1184         ( iContactManager.FieldTypes(), iContactManager.FsSession() );
       
  1185     
       
  1186     RPbk2LocalizedResourceFile resFile( &iContactManager.FsSession() );
       
  1187     resFile.OpenLC( KPbk2RomFileDrive, KDC_RESOURCE_FILES_DIR,
       
  1188         KResourceFile );
       
  1189 
       
  1190     HBufC8* buffer = resFile.AllocReadLC( R_QTN_PHOB_SIM_NAME_COPY_TO_FIRST_NAME );
       
  1191 
       
  1192     _LIT8(KPbk2SimNameCopyFirstNameCompareStr, "*1*");
       
  1193     if ( buffer->MatchF( KPbk2SimNameCopyFirstNameCompareStr ) == 0 )
       
  1194         {
       
  1195         iCopyNameToFirstName = ETrue;
       
  1196         }
       
  1197     CleanupStack::PopAndDestroy( 2 ); // buffer, resFile
       
  1198 
       
  1199     }
       
  1200 
       
  1201 // --------------------------------------------------------------------------
       
  1202 // CPbk2ContactCopyPolicy::FieldProperties
       
  1203 // --------------------------------------------------------------------------
       
  1204 //
       
  1205 CPbk2FieldPropertyArray& CPbk2ContactCopyPolicy::FieldProperties() const
       
  1206     {
       
  1207     return *iFieldProperties;
       
  1208     }
       
  1209 
       
  1210 // --------------------------------------------------------------------------
       
  1211 // CPbk2ContactCopyPolicy::AddFieldToContactL
       
  1212 // --------------------------------------------------------------------------
       
  1213 //
       
  1214 MVPbkContactOperationBase* CPbk2ContactCopyPolicy::AddFieldToContactL(
       
  1215         MVPbkStoreContact& aContact,
       
  1216         const MVPbkFieldType& aFieldType,
       
  1217         const TDateTime& aFieldData,
       
  1218         const TDesC* aFieldLabel,
       
  1219         const MVPbkContactAttribute* aContactAttribute,
       
  1220         MVPbkContactFieldCopyObserver& aCopyObserver)
       
  1221     {
       
  1222     return CPbk2AddFieldOperation::NewL(*this, iContactManager, aContact,
       
  1223             aFieldType, aFieldData, aFieldLabel, aContactAttribute,
       
  1224             aCopyObserver);
       
  1225     }
       
  1226 
       
  1227 // --------------------------------------------------------------------------
       
  1228 // CPbk2ContactCopyPolicy::AddFieldToContactL
       
  1229 // --------------------------------------------------------------------------
       
  1230 //
       
  1231 MVPbkContactOperationBase* CPbk2ContactCopyPolicy::AddFieldToContactL(
       
  1232         MVPbkStoreContact& aContact,
       
  1233         const MVPbkFieldType& aFieldType,
       
  1234         const TDesC& aFieldData,
       
  1235         const TDesC* aFieldLabel,
       
  1236         const MVPbkContactAttribute* aContactAttribute,
       
  1237         MVPbkContactFieldCopyObserver& aCopyObserver)
       
  1238     {
       
  1239     return CPbk2AddFieldOperation::NewL(*this, iContactManager, aContact,
       
  1240             aFieldType, aFieldData, aFieldLabel, aContactAttribute,
       
  1241             aCopyObserver);
       
  1242     }
       
  1243 
       
  1244 // --------------------------------------------------------------------------
       
  1245 // CPbk2ContactCopyPolicy::AddFieldToContactL
       
  1246 // --------------------------------------------------------------------------
       
  1247 //
       
  1248 MVPbkContactOperationBase* CPbk2ContactCopyPolicy::AddFieldToContactL(
       
  1249         MVPbkStoreContact& aContact,
       
  1250         const MVPbkFieldType& aFieldType,
       
  1251         const TDesC8& aFieldData,
       
  1252         const TDesC* aFieldLabel,
       
  1253         const MVPbkContactAttribute* aContactAttribute,
       
  1254         MVPbkContactFieldCopyObserver& aCopyObserver)
       
  1255     {
       
  1256     return CPbk2AddFieldOperation::NewL(*this, iContactManager, aContact,
       
  1257             aFieldType, aFieldData, aFieldLabel, aContactAttribute,
       
  1258             aCopyObserver);
       
  1259     }
       
  1260 
       
  1261 // --------------------------------------------------------------------------
       
  1262 // CPbk2ContactCopyPolicy::CopyTitleFieldsL
       
  1263 // --------------------------------------------------------------------------
       
  1264 //
       
  1265 MVPbkContactOperationBase* CPbk2ContactCopyPolicy::CopyTitleFieldsL(
       
  1266         const MVPbkStoreContact& aSourceContact,
       
  1267         MVPbkStoreContact& aTargetContact,
       
  1268         MVPbkContactFieldsCopyObserver& aCopyObserver)
       
  1269     {
       
  1270     return CPbk2CopyTitlesOperation::NewL(
       
  1271         aSourceContact,
       
  1272         aTargetContact,
       
  1273         aCopyObserver,
       
  1274         NameFormatterL() );
       
  1275     }
       
  1276 
       
  1277 // --------------------------------------------------------------------------
       
  1278 // CPbk2ContactCopyPolicy::CommitContactL
       
  1279 // --------------------------------------------------------------------------
       
  1280 //
       
  1281 MVPbkContactOperationBase* CPbk2ContactCopyPolicy::CommitContactL(
       
  1282         MVPbkStoreContact* aContact,
       
  1283         MVPbkContactCopyObserver& aCopyObserver)
       
  1284     {
       
  1285     return CPbk2SaveContactOperation::NewL(aContact, aCopyObserver,
       
  1286             iContactManager.FsSession());
       
  1287     }
       
  1288 
       
  1289 // --------------------------------------------------------------------------
       
  1290 // CPbk2ContactCopyPolicy::CopyContactL
       
  1291 // --------------------------------------------------------------------------
       
  1292 //
       
  1293 MVPbkContactOperationBase* CPbk2ContactCopyPolicy::CopyContactL(
       
  1294         MVPbkStoreContact& aContact,
       
  1295         MVPbkContactStore& aTargetStore,
       
  1296         MVPbkContactCopyObserver& aCopyObserver)
       
  1297     {
       
  1298     return CPbk2SaveContactOperation::NewL
       
  1299         (aContact, aCopyObserver, aTargetStore,
       
  1300         iContactManager.FsSession(), iCopyNameToFirstName );
       
  1301     }
       
  1302 
       
  1303 // --------------------------------------------------------------------------
       
  1304 // CPbk2ContactCopyPolicy::SupportsContactMerge
       
  1305 // --------------------------------------------------------------------------
       
  1306 //
       
  1307 TBool CPbk2ContactCopyPolicy::SupportsContactMerge() const
       
  1308     {
       
  1309     return ETrue;
       
  1310     }
       
  1311 
       
  1312 // --------------------------------------------------------------------------
       
  1313 // CPbk2ContactCopyPolicy::MergeAndSaveContactsL
       
  1314 // --------------------------------------------------------------------------
       
  1315 //
       
  1316 MVPbkContactOperationBase* CPbk2ContactCopyPolicy::MergeAndSaveContactsL(
       
  1317         RPointerArray<MVPbkStoreContact>& aSourceContacts,
       
  1318         MVPbkStoreContact& aTarget,
       
  1319         MVPbkContactCopyObserver& aCopyObserver )
       
  1320     {
       
  1321     return CPbk2MergeAndSaveOperation::NewL( ContactMergeL(), aSourceContacts,
       
  1322         aTarget, aCopyObserver );
       
  1323     }
       
  1324 
       
  1325 // --------------------------------------------------------------------------
       
  1326 // CPbk2ContactCopyPolicy::NameFormatterL
       
  1327 // --------------------------------------------------------------------------
       
  1328 //
       
  1329 MPbk2ContactNameFormatter& CPbk2ContactCopyPolicy::NameFormatterL()
       
  1330     {
       
  1331     if ( !iSortOrderManager )
       
  1332         {
       
  1333         iSortOrderManager = CPbk2SortOrderManager::NewL
       
  1334             ( iContactManager.FieldTypes() );
       
  1335         }
       
  1336 
       
  1337     if ( !iNameFormatter )
       
  1338         {
       
  1339         iNameFormatter = Pbk2ContactNameFormatterFactory::CreateL
       
  1340             ( iContactManager.FieldTypes(), *iSortOrderManager,
       
  1341               &iContactManager.FsSession() );
       
  1342         }
       
  1343     return *iNameFormatter;
       
  1344     }
       
  1345 
       
  1346 // --------------------------------------------------------------------------
       
  1347 // CPbk2ContactCopyPolicy::ContactMergeL
       
  1348 // --------------------------------------------------------------------------
       
  1349 //
       
  1350 CPbk2ContactMerge& CPbk2ContactCopyPolicy::ContactMergeL()
       
  1351     {
       
  1352     if ( !iContactMerge )
       
  1353         {
       
  1354         iContactMerge = CPbk2ContactMerge::NewL( iContactManager,
       
  1355             NameFormatterL(), *iFieldProperties );
       
  1356         }
       
  1357     return *iContactMerge;
       
  1358     }
       
  1359 
       
  1360 // End of File