phonebookengines/VirtualPhonebook/VPbkVCardEng/inc/CVPbkImportToContactsMergeOperation.h
changeset 0 e686773b3f54
child 17 2666d9724c76
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2007-2008 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:  An operation for Updating a contact in the store
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CVPbkImportToContactsMergeOperation_H
       
    20 #define CVPbkImportToContactsMergeOperation_H
       
    21 
       
    22 // INCLUDE FILES
       
    23 #include <e32base.h>
       
    24 #include <MVPbkContactOperationBase.h>
       
    25 #include <MVPbkSingleContactOperationObserver.h>
       
    26 #include <MVPbkContactObserver.h>
       
    27 #include <MVPbkContactOperation.h>
       
    28 #include "MVPbkImportOperationImpl.h"
       
    29 #include "CVPbkGroupCardHandler.h"
       
    30 #include "MVPbkContactCopyObserver.h"
       
    31 
       
    32 
       
    33 // FORWARD DECLARATIONS
       
    34 class MVPbkStoreContact;
       
    35 class MVPbkContactStore;
       
    36 class MVPbkSingleContactOperationObserver;
       
    37 class MVPbkContactLink;
       
    38 class MVPbkStoreContactField;
       
    39 class MVPbkFieldType;
       
    40 class MVPbkSingleContactOperationObserver;
       
    41 class MVPbkContactCopyObserver;
       
    42 class CVPbkVCardEng;
       
    43 class CVPbkVCardImporter;
       
    44 class CVPbkContactManager;
       
    45 
       
    46 /**
       
    47  *  An operation for Updating a contact in the store
       
    48  */
       
    49 NONSHARABLE_CLASS(CVPbkImportToContactsMergeOperation) 
       
    50     :   public CActive,
       
    51         public MVPbkContactOperation,
       
    52         public MVPbkImportOperationObserver,
       
    53         public MVPbkSingleContactOperationObserver,
       
    54         public MVPbkContactObserver
       
    55     {
       
    56 public:
       
    57      static CVPbkImportToContactsMergeOperation *NewL( 
       
    58              TVPbkImportCardType aType,
       
    59              CVPbkVCardData& aData, 
       
    60              const MVPbkContactLink& aReplaceContact, 
       
    61              MVPbkContactStore& aTargetStore, 
       
    62              RReadStream& aSourceStream, 
       
    63              MVPbkSingleContactOperationObserver& aObserver );
       
    64 
       
    65 	/**
       
    66 	* Destructor.
       
    67 	*/
       
    68     ~CVPbkImportToContactsMergeOperation();
       
    69         
       
    70 protected: // CActive
       
    71 	/**
       
    72 	* From CActive. Called when asynchronous operation completes.
       
    73 	*/
       
    74     void RunL();
       
    75 	/**
       
    76 	* From CActive. Called when RunL leaves.
       
    77 	*/    
       
    78 
       
    79     TInt RunError( TInt aError );
       
    80 	/**
       
    81 	* From CActive. Cancels operation.
       
    82 	*/
       
    83 
       
    84     void DoCancel();        
       
    85 
       
    86 private:
       
    87 
       
    88     CVPbkImportToContactsMergeOperation( 
       
    89             const MVPbkContactLink& aReplaceContact,
       
    90             MVPbkSingleContactOperationObserver& aObserver,
       
    91             MVPbkContactStore& aTargetStore,
       
    92             CVPbkVCardData & aData
       
    93             );
       
    94 	/**
       
    95 	* Second phase constructor.
       
    96 	*/
       
    97     void ConstructL( TVPbkImportCardType aType, RReadStream& aSourceStream);
       
    98 
       
    99 public:
       
   100     // from base class MVPbkImportOperationObserver
       
   101       /**
       
   102 		* From MVPbkImportOperationObserver  
       
   103 		* Called when a contact import operation has Completed.
       
   104 		*/
       
   105      void ContactsImported();
       
   106       /**
       
   107 		* From MVPbkImportOperationObserver  
       
   108 		* Called when a contact import operation has failed.
       
   109 		*/
       
   110      void ContactImportingFailed( TInt aError );
       
   111       /**
       
   112 		* From MVPbkImportOperationObserver  
       
   113 		* Called when a contact import operation has Completed Fully.
       
   114 		*/
       
   115      void ContactsImportingCompleted();
       
   116         
       
   117 public:
       
   118     // from base class MVPbkContactOperation
       
   119      /**
       
   120 		* From MVPbkContactOperation  
       
   121 		* Called when a contact operation has to be started
       
   122 		*/
       
   123      void StartL();
       
   124       /**
       
   125 		* From MVPbkContactOperation  
       
   126 		* Called when a contact operation has to be cancled
       
   127 		*/
       
   128      void Cancel();
       
   129      
       
   130 public: // from MVPbkSingleContactOperationObserver
       
   131 
       
   132 	/**
       
   133 		* From MVPbkSingleContactOperationObserver  
       
   134 		* Called when the contact operation is complete
       
   135 		* Client takes Ownership in deleting returned aContact.
       
   136 		*/
       
   137     void VPbkSingleContactOperationComplete(
       
   138                     MVPbkContactOperationBase& aOperation,
       
   139                     MVPbkStoreContact* aContact );
       
   140     /**
       
   141 		* From MVPbkSingleContactOperationObserver  
       
   142 		* Called when the contact operation fails
       
   143 		*/                
       
   144     void VPbkSingleContactOperationFailed(
       
   145                     MVPbkContactOperationBase& aOperation, 
       
   146                     TInt aError );
       
   147 public:
       
   148 
       
   149     // from MVPbkContactObserver
       
   150     /**
       
   151 		* From MVPbkContactObserver  
       
   152 		* Called when a contact operation has succesfully completed.
       
   153 		* Client takes Ownership in deleting returned aResult.
       
   154 		*/
       
   155     void ContactOperationCompleted(TContactOpResult aResult);
       
   156     /**
       
   157 		* From MVPbkContactObserver  
       
   158 		* Called when a contact operation has failed.
       
   159 		*/
       
   160     void ContactOperationFailed
       
   161                 (TContactOp aOpCode, TInt aErrorCode, TBool aErrorNotified);
       
   162     
       
   163 private: // types
       
   164 	enum TState
       
   165 		{
       
   166         EImport,
       
   167         ERetrieve,
       
   168         ELock,
       
   169         EReplaceFields,
       
   170         ECommit,
       
   171         EReRetrieve, //Reload contact to have valid lastmodified datetime
       
   172         EComplete
       
   173         };
       
   174 
       
   175 private:    
       
   176     void NextState( TState aNextState );
       
   177 	/**
       
   178 	* Retrive the contact to be updated
       
   179 	*/
       
   180     void RetrieveContactL();
       
   181 	/**
       
   182 	* Lock the contact for editing
       
   183 	*/
       
   184     void LockContactL();
       
   185     /**
       
   186 	* Commit the updated contact
       
   187 	*/
       
   188     void CommitContactL();
       
   189 	/**
       
   190 	* Update imported contacts
       
   191 	*/
       
   192     void UpdateContactL();
       
   193 	/**
       
   194 	* Retrieve the contact after updation
       
   195 	*/
       
   196     void ReRetrieveContactL();
       
   197     
       
   198     void HandleError(TInt aError);
       
   199     void HandleContactReplacing(MVPbkStoreContact* aContact);
       
   200 	/**
       
   201 	* Replace the fields of target contact
       
   202 	*/
       
   203     void ReplaceContactL( const MVPbkStoreContact& aSrc, MVPbkStoreContact& aTarget );
       
   204 	/**
       
   205 	* Copy the fields of source contact to target contact
       
   206 	*/
       
   207     void CopyFieldL( const MVPbkStoreContactField& aSourceField,
       
   208     		const MVPbkFieldType& aType,
       
   209             MVPbkStoreContact& aTargetContact );
       
   210     
       
   211 private: // data
       
   212 	/// Own: state
       
   213 	TState iState;
       
   214     /// Own: the imported contacts
       
   215     RPointerArray<MVPbkStoreContact> iImportedContacts;
       
   216     /// Own: the implementation of the import operation
       
   217     MVPbkImportOperationImpl* iOperationImpl;
       
   218     /// Ref: the target store of the operation
       
   219     MVPbkContactStore& iTargetStore;
       
   220     //Ref: Vcard Data
       
   221     CVPbkVCardData& iData;
       
   222 	/// Ref: contact to replace
       
   223 	const MVPbkContactLink& iReplaceContact;
       
   224     /// Own: current contact
       
   225     MVPbkStoreContact* iContact;
       
   226     /// Ref: client that waits importing
       
   227     MVPbkSingleContactOperationObserver& iObserver;
       
   228     /// Own: the operation for import and retrieve
       
   229     MVPbkContactOperationBase* iVPbkOperation;
       
   230     //Own: Group Card Handler
       
   231     CVPbkGroupCardHandler* iGroupcardHandler;
       
   232     };
       
   233 
       
   234 #endif