phonebookengines/VirtualPhonebook/VPbkEng/inc/CVPbkCopyContactsOperation.h
changeset 0 e686773b3f54
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:  Copy contacts operation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CVPBKCOPYCONTACTSOPERATION_H
       
    20 #define CVPBKCOPYCONTACTSOPERATION_H
       
    21 
       
    22 // INCLUDE FILES
       
    23 #include <e32base.h>
       
    24 #include <MVPbkContactOperation.h>
       
    25 #include <MVPbkSingleContactOperationObserver.h>
       
    26 #include <MVPbkContactCopyObserver.h>
       
    27 #include <MVPbkContactObserver.h>
       
    28 #include <MVPbkContactFindObserver.h>
       
    29 
       
    30 // FORWARD DECLARAIONS
       
    31 class CVPbkContactManager;
       
    32 class MVPbkBatchOperationObserver;
       
    33 class MVPbkContactStore;
       
    34 class MVPbkContactLink;
       
    35 class MVPbkContactLinkArray;
       
    36 class CVPbkContactCopyPolicyManager;
       
    37 class MVPbkContactCopyPolicy;
       
    38 class CVPbkContactDuplicatePolicy;
       
    39 class CVPbkContactLinkArray;
       
    40 
       
    41 
       
    42 /**
       
    43  * Virtual phonebook copy contacts operation
       
    44  */
       
    45 NONSHARABLE_CLASS(CVPbkCopyContactsOperation) 
       
    46     :   public CActive,
       
    47         public MVPbkContactOperation,
       
    48         private MVPbkSingleContactOperationObserver,
       
    49         private MVPbkContactCopyObserver,
       
    50         private MVPbkContactObserver,
       
    51         private MVPbkContactFindObserver
       
    52     {
       
    53     public:
       
    54         /**
       
    55          * Creates a new instance of this class
       
    56          * @param aCopyContactFlags Copy contact flags
       
    57          * @param aContactManager Contact manager
       
    58          * @param aLinks Contact link array
       
    59          * @param aTargetStore Target store
       
    60          * @param aCopiedContactLinks Copied contact links
       
    61          * @param aObserver Observer who is notified when completed
       
    62          * @return A new instance of this class
       
    63          */
       
    64         static CVPbkCopyContactsOperation* NewLC(
       
    65                 TUint32 aCopyContactFlags,
       
    66                 CVPbkContactManager& aContactManager,
       
    67                 const MVPbkContactLinkArray& aLinks, 
       
    68 				MVPbkContactStore* aTargetStore,
       
    69 				CVPbkContactLinkArray* aCopiedContactLinks,
       
    70                 MVPbkBatchOperationObserver& aObserver);
       
    71         ~CVPbkCopyContactsOperation();
       
    72 
       
    73     private: // From CActive
       
    74         void DoCancel();
       
    75         void RunL();
       
    76         TInt RunError(TInt aError);
       
    77 
       
    78     private: // From MVPbkContactOperation
       
    79         void StartL();
       
    80         void Cancel();
       
    81 
       
    82     private: // From MVPbkSingleContactOperationObserver
       
    83         void VPbkSingleContactOperationComplete(
       
    84                 MVPbkContactOperationBase& aOperation,
       
    85                 MVPbkStoreContact* aContact);
       
    86         void VPbkSingleContactOperationFailed(
       
    87                 MVPbkContactOperationBase& aOperation, 
       
    88                 TInt aError);
       
    89     private: // From MVPbkContactCopyObserver
       
    90 
       
    91         void ContactsSaved(MVPbkContactOperationBase& aOperation,
       
    92                 MVPbkContactLinkArray* aResults);
       
    93         void ContactsSavingFailed(MVPbkContactOperationBase& aOperation,
       
    94                 TInt aError);
       
    95 
       
    96     private: // From MVPbkContactObserver
       
    97         void ContactOperationCompleted( TContactOpResult aResult );
       
    98         void ContactOperationFailed( TContactOp aOpCode, TInt aErrorCode, 
       
    99             TBool aErrorNotified );
       
   100     
       
   101     private: // From MVPbkContactFindObserver
       
   102         void FindCompleteL( MVPbkContactLinkArray* aResults );
       
   103         void FindFailed( TInt aError );
       
   104         
       
   105     private: // Implementation
       
   106         CVPbkCopyContactsOperation(
       
   107                 CVPbkContactManager& aContactManager,
       
   108                 const MVPbkContactLinkArray& aLinks,
       
   109                 MVPbkContactStore* aTargetStore,
       
   110                 CVPbkContactLinkArray* aCopiedContactLinks,
       
   111                 MVPbkBatchOperationObserver& aObserver);
       
   112         void ConstructL( TUint32 aCopyContactFlags );
       
   113         void IssueRequest();
       
   114         void SetTargetStoreL();
       
   115         void RetrieveNextContactL();
       
   116         void DefaultCopyL();
       
   117         void CopyUsingPolicyL();
       
   118         void FindDuplicatesL();
       
   119         void ContinueAfterFailure( TInt aError );
       
   120         void AppendResultsL( MVPbkContactLinkArray& aLinks );
       
   121         
       
   122     private: // Data
       
   123         CVPbkContactManager& iContactManager;
       
   124         const MVPbkContactLinkArray& iLinks;
       
   125         /// Ref: the target of the copy
       
   126 		MVPbkContactStore* iTargetStore;
       
   127 		/// Ref: the array from the client for copied contacts
       
   128 		CVPbkContactLinkArray* iCopiedContactLinks;
       
   129 		/// Ref: ETrue if contacts are duplicated.
       
   130 		TBool iDuplicateContacts;
       
   131         MVPbkBatchOperationObserver& iObserver;
       
   132         TInt iCurrentLinkIndex;
       
   133         /// Own: the operation instance for async operation
       
   134         MVPbkContactOperationBase* iOperation;
       
   135         /// Own: Currently copied contact
       
   136         MVPbkStoreContact* iStoreContact;
       
   137         /// Own: Copy contacts manager
       
   138         CVPbkContactCopyPolicyManager* iCopyPolicyManager;
       
   139         /// Ref: The copy policy for the target store
       
   140         MVPbkContactCopyPolicy* iCopyPolicy;
       
   141         /// Own: a duplicate policy for duplicate checking
       
   142         CVPbkContactDuplicatePolicy* iDuplicatePolicy;
       
   143         enum TState
       
   144             {
       
   145             ERetrieveNextContact,
       
   146             EDefaultCopy,
       
   147             ECopyUsingPolicy,
       
   148             EFindDuplicates,
       
   149             ECommit,
       
   150             EComplete
       
   151             };
       
   152         TState iState;
       
   153         /// Own: The duplicate contacts that has been found
       
   154         RPointerArray<MVPbkStoreContact> iDuplicates;
       
   155         /// Ref: An array for merge and save. Doesn't own contact.
       
   156         RPointerArray<MVPbkStoreContact> iSourceContactsForMerge;
       
   157     };
       
   158 
       
   159 #endif // CVPBKCOPYCONTACTSOPERATION_H
       
   160 //End of file