phonebookui/Phonebook2/inc/CPbk2ContactRelocator.h
branchRCL_3
changeset 63 f4a778e096c2
child 64 c1e8ba0c2b16
equal deleted inserted replaced
62:5b6f26637ad3 63:f4a778e096c2
       
     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:  Phonebook 2 contacts relocator.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CPBK2CONTACTRELOCATOR_H
       
    20 #define CPBK2CONTACTRELOCATOR_H
       
    21 
       
    22 //  INCLUDES
       
    23 #include <e32base.h>
       
    24 #include <MVPbkContactStoreObserver.h>
       
    25 #include <MVPbkContactCopyObserver.h>
       
    26 #include <MVPbkSingleContactOperationObserver.h>
       
    27 #include <MVPbkContactObserver.h>
       
    28 
       
    29 // FORWARD DECLARATIONS
       
    30 class MVPbkStoreContact;
       
    31 class MVPbkContactOperationBase;
       
    32 class CVPbkContactLinkArray;
       
    33 class MVPbkContactStore;
       
    34 class MPbk2ContactRelocatorObserver;
       
    35 class MVPbkContactCopyPolicy;
       
    36 class CVPbkContactCopyPolicyManager;
       
    37 class MVPbkContactLinkArray;
       
    38 class CAknQueryDialog;
       
    39 class CPbk2ApplicationServices;
       
    40 
       
    41 // CLASS DECLARATION
       
    42 
       
    43 namespace Pbk2ContactRelocator {
       
    44 
       
    45 /**
       
    46  * Query policy.
       
    47  */
       
    48 enum TPbk2ContactRelocationQueryPolicy
       
    49     {
       
    50     /// Do not display any queries
       
    51     EPbk2DisplayNoQueries,
       
    52     /// Display 'copy %U to phone memory' query
       
    53     EPbk2DisplayBasicQuery,
       
    54     /// Display 'store does not support, copy/move to %U memory' query
       
    55     EPbk2DisplayStoreDoesNotSupportQuery
       
    56     };
       
    57     
       
    58     /**
       
    59      * Relocation policy.
       
    60      */
       
    61 enum TPbk2ContactRelocationPolicy
       
    62     {
       
    63     /// Copy contact to phone memory, value used from CenRep
       
    64     EPbk2CopyContactToPhoneMemory,
       
    65     /// Move contact to phone memory, value used from CenRep
       
    66     EPbk2MoveContactToPhoneMemory,
       
    67     /// Copy contact to phone memory and lock it
       
    68     EPbk2CopyContactToPhoneMemoryAndLock,
       
    69     /// Move contact to phone memory and lock it
       
    70     EPbk2MoveContactToPhoneMemoryAndLock
       
    71     };
       
    72 } /// namespace
       
    73 
       
    74 /**
       
    75  * Phonebook 2 contacts relocator.
       
    76  */
       
    77 class CPbk2ContactRelocator : public CActive,
       
    78                               public MVPbkContactStoreObserver,
       
    79                               public MVPbkContactCopyObserver,
       
    80                               public MVPbkSingleContactOperationObserver,
       
    81                               public MVPbkContactObserver
       
    82     {
       
    83     public: // Data structure
       
    84 
       
    85         enum TFlags
       
    86             {
       
    87             /// The contact exists in the store and can be deleted
       
    88             /// if the relocation policy is to move contact.
       
    89             EPbk2RelocatorExistingContact   = 0x01,
       
    90             /// Relocator assumes that contact is new and doesn't try to
       
    91             /// delete the contact if the policy is move contact.
       
    92             EPbk2RelocatorNewContact        = 0x02
       
    93             };
       
    94 
       
    95     public:  // Constructors and destructor
       
    96 
       
    97         /**
       
    98          * Creates and returns a new instance of this class.
       
    99          *
       
   100          * @return A new instance of this class.
       
   101          */
       
   102         IMPORT_C static CPbk2ContactRelocator* NewL();
       
   103 
       
   104         /**
       
   105          * Destructor.
       
   106          */
       
   107         ~CPbk2ContactRelocator();
       
   108 
       
   109     public: // Interface
       
   110 
       
   111         /**
       
   112          * Relocates given contact to phone memory store.
       
   113          *
       
   114          * @param aContact      The contact to relocate. Ownership of
       
   115          *                      the contact is taken.
       
   116          * @param aObserver     Observer for the relocation process.
       
   117          * @param aQueryPolicy  Query policy.
       
   118          * @param aFlags        A set of TFlags
       
   119          * @return  ETrue if user has accepted relocation, otherwise EFalse.
       
   120          *          NOTE! Do not delete relocator instance. Relocator will
       
   121          *                be completed asynchronusly through aObserver.
       
   122          */
       
   123         IMPORT_C TBool RelocateContactL(
       
   124                 MVPbkStoreContact* aContact,
       
   125                 MPbk2ContactRelocatorObserver& aObserver,
       
   126                 Pbk2ContactRelocator::TPbk2ContactRelocationQueryPolicy 
       
   127                     aQueryPolicy,
       
   128                 TUint32 aFlags );
       
   129 
       
   130         /**
       
   131          * Relocates given contact to phone memory store.
       
   132          * After the contact has been relocated, the contact
       
   133          * is locked.
       
   134          *
       
   135          * @param aContact      The contact to relocate. Ownership of
       
   136          *                      the contact is taken.
       
   137          * @param aObserver     Observer for the relocation process.
       
   138          * @param aQueryPolicy  Query policy.
       
   139          * @param aFlags        A set of TFlags
       
   140          * @return  ETrue if user has accepted relocation, otherwise EFalse.
       
   141          *          NOTE! Do not delete relocator instance. Relocator will
       
   142          *                be completed asynchronusly through aObserver.
       
   143          */
       
   144         IMPORT_C TBool RelocateAndLockContactL(
       
   145                 MVPbkStoreContact* aContact,
       
   146                 MPbk2ContactRelocatorObserver& aObserver,
       
   147                 Pbk2ContactRelocator::TPbk2ContactRelocationQueryPolicy 
       
   148                     aQueryPolicy,
       
   149                 TUint32 aFlags );
       
   150 
       
   151         /**
       
   152          * Relocates given contacts to phone memory store.
       
   153          *
       
   154          * @param aContacts     The contacts to relocate. Ownership of
       
   155          *                      the link array is taken.
       
   156          * @param aObserver     Observer for the relocation process.
       
   157          * @param aQueryPolicy  Query policy, this function ignores
       
   158          *                      this parameter currently.
       
   159          * @return  ETrue if user has accepted relocation, otherwise EFalse.
       
   160          *          NOTE! Do not delete relocator instance. Relocator will
       
   161          *                be completed asynchronusly through aObserver.
       
   162          */
       
   163         IMPORT_C TBool RelocateContactsL(
       
   164                 CVPbkContactLinkArray* aContacts,
       
   165                 MPbk2ContactRelocatorObserver& aObserver,
       
   166                 Pbk2ContactRelocator::TPbk2ContactRelocationQueryPolicy 
       
   167                     aQueryPolicy );
       
   168 
       
   169         /**
       
   170          * Checks is the given contact a phone memory contact.
       
   171          *
       
   172          * @param aContact  The contact to inspect.
       
   173          * @return  ETrue if aContact belongs to phone memory store.
       
   174          */
       
   175         IMPORT_C TBool IsPhoneMemoryContact(
       
   176                 const MVPbkStoreContact& aContact ) const;
       
   177 
       
   178         /**
       
   179          * Inspects is phone memory part of the current Phonebook 2
       
   180          * store configuration.
       
   181          *
       
   182          * @return  ETrue if phone memory belongs to configuration.
       
   183          */
       
   184         IMPORT_C TBool IsPhoneMemoryInConfigurationL() const;
       
   185 
       
   186     private: // From CActive
       
   187         void RunL();
       
   188         void DoCancel();
       
   189         TInt RunError(
       
   190                 TInt aError );
       
   191 
       
   192     private: // From MVPbkContactStoreObserver
       
   193         void StoreReady(
       
   194                 MVPbkContactStore& aContactStore );
       
   195         void StoreUnavailable(
       
   196                 MVPbkContactStore& aContactStore,
       
   197                 TInt aReason );
       
   198         void HandleStoreEventL(
       
   199                 MVPbkContactStore& aContactStore,
       
   200                 TVPbkContactStoreEvent aStoreEvent );
       
   201 
       
   202     private: // From MVPbkContactCopyObserver
       
   203         void FieldAddedToContact(
       
   204                 MVPbkContactOperationBase& aOperation );
       
   205         void FieldAddingFailed(
       
   206                 MVPbkContactOperationBase& aOperation,
       
   207                 TInt aError );
       
   208         void ContactsSaved(
       
   209                 MVPbkContactOperationBase& aOperation,
       
   210                 MVPbkContactLinkArray* aResults );
       
   211         void ContactsSavingFailed(
       
   212                 MVPbkContactOperationBase& aOperation,
       
   213                 TInt aError );
       
   214 
       
   215     private: // From MVPbkSingleContactOperationObserver
       
   216         void VPbkSingleContactOperationComplete(
       
   217                 MVPbkContactOperationBase& aOperation,
       
   218                 MVPbkStoreContact* aContact );
       
   219         void VPbkSingleContactOperationFailed(
       
   220                 MVPbkContactOperationBase& aOperation,
       
   221                 TInt aError );
       
   222 
       
   223     private: // From MVPbkContactObserver
       
   224         void ContactOperationCompleted(
       
   225                 TContactOpResult aResult );
       
   226         void ContactOperationFailed(
       
   227                 TContactOp aOpCode,
       
   228                 TInt aErrorCode,
       
   229                 TBool aErrorNotified );
       
   230 
       
   231     private: // Data structures
       
   232         /**
       
   233          * Relocaltion query type
       
   234          */
       
   235         enum TPbk2RelocationQueryType
       
   236             {
       
   237             /// No relocation query
       
   238             EPbk2NoRelocationQuery,
       
   239             /// §qtn.phob.query.copy.to.store§ query
       
   240             EPbk2CopyOneToStoreQuery,
       
   241             /// §qtn.phob.query.move.to.store§ query
       
   242             EPbk2MoveOneToStoreQuery,
       
   243             /// §qtn.phob.query.copy.to.phone.mem§ query            
       
   244             EPbk2CopyOneToPhoneQuery,
       
   245             /// §qtn.phob.query.move.to.phone.mem§ query
       
   246             EPbk2MoveOneToPhoneQuery,
       
   247             /// §qtn.phob.query.copy.many.to.store§ query
       
   248             EPbk2CopyManyToStoreQuery,
       
   249             /// §qtn.phob.query.move.many.to.store§
       
   250             EPbk2MoveManyToStoreQuery
       
   251             };
       
   252 
       
   253     private: // Implementation
       
   254         CPbk2ContactRelocator();
       
   255         void ConstructL();
       
   256         Pbk2ContactRelocator::TPbk2ContactRelocationPolicy ReadRelocationPolicyL();
       
   257         void OpenTargetStoreL();
       
   258         void DoRelocateContactL();
       
   259         void InitCopyPolicyL();
       
   260         void DoHandleContactRelocated();
       
   261         void DeleteSourceContact();
       
   262         TBool AskConfirmationL(
       
   263                 MVPbkStoreContact* aContact,
       
   264                 CVPbkContactLinkArray* aContacts,
       
   265                 TPbk2RelocationQueryType aRelocationQueryType );
       
   266         void RetrieveSavedContactL(
       
   267                 const MVPbkContactLink& aLink );
       
   268         void VerifyPolicy(
       
   269                 MVPbkStoreContact* aContact, TUint32 aFlags );
       
   270         TBool PrepareToRelocateContactL(
       
   271                 MVPbkStoreContact* aContact,
       
   272                 CVPbkContactLinkArray* aContacts,
       
   273                 MPbk2ContactRelocatorObserver& aObserver,
       
   274                 Pbk2ContactRelocator::TPbk2ContactRelocationQueryPolicy 
       
   275                     aQueryPolicy,
       
   276                 TUint32 aFlags );
       
   277         void CopyContactL(
       
   278                 MVPbkStoreContact& aContact );
       
   279         void FinalizeIfReady();
       
   280         TPbk2RelocationQueryType SelectRelocationQueryType(
       
   281                 MVPbkStoreContact* aContact,
       
   282                 CVPbkContactLinkArray* aContacts,
       
   283                 Pbk2ContactRelocator::TPbk2ContactRelocationQueryPolicy
       
   284                 aQueryPolicy );
       
   285         void IssueRequest();
       
   286 
       
   287     private: // Data
       
   288         /// Own: Relocation policy
       
   289     	Pbk2ContactRelocator::TPbk2ContactRelocationPolicy iRelocationPolicy;
       
   290         /// Own: Relocation policy
       
   291     	Pbk2ContactRelocator::TPbk2ContactRelocationPolicy iActivePolicy;
       
   292         /// Ref: Target store for copied contacts
       
   293         MVPbkContactStore* iTargetStore;
       
   294         /// Own: Indication of target store state
       
   295         TBool iTargetStoreOpen;
       
   296         /// Own: Copy policy manager
       
   297         CVPbkContactCopyPolicyManager* iCopyPolicyManager;
       
   298         /// Ref: Copy policy
       
   299         MVPbkContactCopyPolicy* iCopyPolicy;
       
   300         /// Own: Contact retriever
       
   301         MVPbkContactOperationBase* iSavedContactsRetriever;
       
   302         /// Own: Relocatable contact retriever
       
   303         MVPbkContactOperationBase* iContactRetriever;
       
   304         /// Own: Copy operation
       
   305         MVPbkContactOperationBase* iContactCopier;
       
   306         /// Own: Relocated contact
       
   307         MVPbkStoreContact* iRelocatedContact;
       
   308         /// Ref: Observer for the relocation process
       
   309         MPbk2ContactRelocatorObserver* iObserver;
       
   310         /// Own: The contact to relocate
       
   311         MVPbkStoreContact* iSourceContact;
       
   312         /// Own: The contacts to relocate
       
   313         CVPbkContactLinkArray* iSourceContacts;
       
   314         /// Own: Error code for asynchronous error notification
       
   315         TInt iErrorCode;
       
   316         /// Own: Query dialog
       
   317         CAknQueryDialog* iQueryDialog;
       
   318         /// Own: To check is this destroyed
       
   319         TBool* iDestroyedPtr;
       
   320         /// Own: Application services
       
   321         CPbk2ApplicationServices* iAppServices; 
       
   322         };
       
   323 
       
   324 #endif // CPBK2CONTACTRELOCATOR_H
       
   325 
       
   326 // End of File