phonebookengines/VirtualPhonebook/VPbkEng/inc/CVPbkTopContactOperation.h
changeset 0 e686773b3f54
child 39 a6539d1e8e43
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:  Top Contact opeartion.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef VPBKTOPCONTACTOPERATION_H
       
    20 #define VPBKTOPCONTACTOPERATION_H
       
    21 
       
    22 // INCLUDES
       
    23 #include <e32base.h>
       
    24 #include <MVPbkContactOperationBase.h>
       
    25 #include <MVPbkContactViewObserver.h>
       
    26 #include <MVPbkContactStoreObserver.h>
       
    27 #include <MVPbkBatchOperationObserver.h>
       
    28 #include <MVPbkContactSelector.h>
       
    29 #include <MVPbkOperationObserver.h>
       
    30 #include <MVPbkBatchOperationObserver.h>
       
    31 #include <MVPbkStoreContact.h>
       
    32 
       
    33 
       
    34 // FORWARD DECLARATIONS
       
    35 class MVPbkContactLink;
       
    36 class MVPbkContactLinkArray;
       
    37 class CVPbkContactLinkArray;
       
    38 class CVPbkContactManager;
       
    39 class MVPbkContactViewBase;
       
    40 class CVPbkSortOrder;
       
    41 class MVPbkContactStore;
       
    42 class CVPbkContactEasyManager;
       
    43 class MVPbkBaseContact;
       
    44 class MVPbkContactFieldTextData;
       
    45 class TVPbkContactStoreUriPtr;
       
    46 class CVPbkSortOrderAcquirer;
       
    47 
       
    48 // CLASS DECLARATION
       
    49 
       
    50 /**
       
    51  * Top contact manager operation. One class used for all operations, a new instance 
       
    52  * is created for each client request.
       
    53  */
       
    54 NONSHARABLE_CLASS( CVPbkTopContactOperation ) : public CActive,
       
    55     public MVPbkContactOperationBase,
       
    56     public MVPbkContactViewObserver,
       
    57     public MVPbkContactStoreObserver,
       
    58     public MVPbkBatchOperationObserver,
       
    59     public MVPbkOperationObserver,
       
    60     public MVPbkOperationErrorObserver,
       
    61     public MVPbkContactSelector
       
    62     {
       
    63     public:
       
    64         /**
       
    65          * Top contacts operation
       
    66          */
       
    67         enum TTopOperation
       
    68             {
       
    69             EGetTopContacts,
       
    70             EGetTopContactLinks,
       
    71             EGetNonTopContacts,
       
    72             EGetNonTopContactLinks, 
       
    73             EAddToTop,
       
    74             ERemoveFromTop,
       
    75             EReorderTop
       
    76             };
       
    77         
       
    78     public:
       
    79         /**
       
    80          * Creates a top contact manager operation that returns a view. Used to 
       
    81          * create top and non-top contact views.
       
    82          * 
       
    83          * @param aContactManager Contact manager which already has its stores opened.
       
    84          * @param aObserver Receives view when it's ready
       
    85          * @param aErrorObserver Error observer is notified in case of an error
       
    86          * @param aOperation Valid values EGetTopContacts and EGetNonTopContacts
       
    87          * 
       
    88          * @return Contact operation handle 
       
    89          */
       
    90         static MVPbkContactOperationBase* NewGetViewOperationL(
       
    91                 CVPbkContactManager& aContactManager,
       
    92                 MVPbkOperationResultObserver<MVPbkContactViewBase*>& aObserver,
       
    93                 MVPbkOperationErrorObserver& aErrorObserver,
       
    94                 TTopOperation aOperation );
       
    95 
       
    96         /**
       
    97          * Creates a top contact manager operation that returns a contact link array. Used to 
       
    98          * receive top and non-top contact links.
       
    99          * 
       
   100          * @param aContactManager Contact manager which already has its stores opened.
       
   101          * @param aObserver Receives contact link array when it's ready
       
   102          * @param aErrorObserver Error observer is notified in case of an error
       
   103          * @param aOperation Valid values EGetTopContactLinks and EGetNonTopContactLinks 
       
   104          *
       
   105          * @return Contact operation handle  
       
   106          */
       
   107         static MVPbkContactOperationBase* NewGetViewLinksOperationL(
       
   108                 CVPbkContactManager& aContactManager,
       
   109                 MVPbkOperationResultObserver<MVPbkContactLinkArray*>& aObserver,
       
   110                 MVPbkOperationErrorObserver& aErrorObserver,
       
   111                 TTopOperation aOperation );
       
   112 
       
   113         /**
       
   114          * Creates a top contact manager operation that manipulates top contacts:
       
   115          * add to top contacts, remove from top contacts, reorder top contacts.
       
   116          * 
       
   117          * @param aContactManager Contact manager which already has its stores opened.
       
   118          * @param aObserver Receives notification when operation is complete
       
   119          * @param aErrorObserver Error observer is notified in case of an error
       
   120          * @param aOperation valid values EAddToTop,
       
   121          *                                ERemoveFromTop,
       
   122          *                                EReorderTop
       
   123          * 
       
   124          * @return Contact operation handle 
       
   125          */
       
   126         static MVPbkContactOperationBase* NewTopOperationL(
       
   127                 CVPbkContactManager& aContactManager,
       
   128                 const MVPbkContactLinkArray& aContactLinks,
       
   129                 MVPbkOperationObserver& aObserver,
       
   130                 MVPbkOperationErrorObserver& aErrorObserver,
       
   131                 TTopOperation aOperation );
       
   132         
       
   133         /**
       
   134          * Destructor. Cancels any ongoing requests.
       
   135          */ 
       
   136         ~CVPbkTopContactOperation();
       
   137         
       
   138         /**
       
   139          * Return contact's top index or KErrNotFound
       
   140          * 
       
   141          * @param aContact contact item 
       
   142          * 
       
   143          * @return top index or KErrNotFound
       
   144          */
       
   145         static TInt TopOrder( const MVPbkBaseContact& aContact );
       
   146 
       
   147     private: //From CActive
       
   148         void DoCancel();
       
   149         void RunL();
       
   150         TInt RunError( TInt aError );
       
   151         
       
   152     private: // from MVPbkContactViewObserver
       
   153         void ContactViewReady(
       
   154                 MVPbkContactViewBase& aView );
       
   155         void ContactViewUnavailable(
       
   156                 MVPbkContactViewBase& aView );
       
   157         void ContactAddedToView(
       
   158                 MVPbkContactViewBase& aView, 
       
   159                 TInt aIndex, 
       
   160                 const MVPbkContactLink& aContactLink );
       
   161         void ContactRemovedFromView(
       
   162                 MVPbkContactViewBase& aView, 
       
   163                 TInt aIndex, 
       
   164                 const MVPbkContactLink& aContactLink );
       
   165         void ContactViewError(
       
   166                 MVPbkContactViewBase& aView, 
       
   167                 TInt aError, 
       
   168                 TBool aErrorNotified );
       
   169     
       
   170     private: // from MVPbkContactStoreObserver
       
   171         void StoreReady(MVPbkContactStore& aContactStore);
       
   172         void StoreUnavailable(MVPbkContactStore& aContactStore, 
       
   173             TInt aReason);
       
   174         void HandleStoreEventL(
       
   175             MVPbkContactStore& aContactStore, 
       
   176             TVPbkContactStoreEvent aStoreEvent);
       
   177 
       
   178     private: // from MVPbkBatchOperationObserver
       
   179         void StepComplete( 
       
   180             MVPbkContactOperationBase& aOperation,
       
   181             TInt aStepSize );
       
   182         TBool StepFailed(
       
   183             MVPbkContactOperationBase& aOperation,
       
   184             TInt aStepSize, TInt aError );
       
   185         void OperationComplete( 
       
   186             MVPbkContactOperationBase& aOperation );
       
   187 
       
   188     private: // from MVPbkOperationObserver
       
   189         void VPbkOperationCompleted( MVPbkContactOperationBase* aOperation );
       
   190         void VPbkOperationFailed( MVPbkContactOperationBase* aOperation,
       
   191                 TInt aError );
       
   192 
       
   193     private: // From MVPbkContactSelector
       
   194         TBool IsContactIncluded( const MVPbkBaseContact& aContact );    
       
   195 
       
   196     private: // construction        
       
   197         static CVPbkTopContactOperation* NewLC(
       
   198                 CVPbkContactManager& aContactManager,
       
   199                 MVPbkOperationErrorObserver& aErrorObserver,
       
   200                 TTopOperation aOperation);
       
   201         void ConstructL();
       
   202         CVPbkTopContactOperation(
       
   203                 CVPbkContactManager& aContactManager,
       
   204                 MVPbkOperationErrorObserver& aErrorObserver,
       
   205                 TTopOperation aOperation);
       
   206         
       
   207     private: // new methods
       
   208         static void SetTopOrderL(
       
   209             MVPbkContactFieldTextData& aTextData, TInt aTopOrderIndex );
       
   210         void SetTopOrderL(
       
   211             MVPbkStoreContact& aContact, TInt aTopOrderIndex );
       
   212         static const MVPbkContactFieldTextData* FindTopFieldTextData(
       
   213             const MVPbkBaseContact& aContact );
       
   214         static MVPbkContactFieldTextData* FindTopFieldTextData(
       
   215             MVPbkStoreContact& aContact );  
       
   216         void OpenStoreL( const TVPbkContactStoreUriPtr& aUri );
       
   217         void OpenDefaultStoreL();
       
   218         
       
   219         void RequestTopContactsViewL();
       
   220         void RequestNonTopContactsViewL();      
       
   221         
       
   222         void Top_RunL();
       
   223         void GetView_RunL();
       
   224         void DoTopOperationL();
       
   225         
       
   226         TBool SaveOneContactL();
       
   227 
       
   228         static TInt NextTopOrderIndexL(
       
   229             const MVPbkContactViewBase& aView );
       
   230 
       
   231         void CompleteOurself();
       
   232 
       
   233         static CVPbkContactLinkArray* CloneArrayL(
       
   234             const MVPbkContactLinkArray& aArray );
       
   235 
       
   236         static MVPbkContactLinkArray* ViewToLinkArrayL(
       
   237             const MVPbkContactViewBase& aView );
       
   238         
       
   239         void SetTopOrderToContactsL(
       
   240             RPointerArray<MVPbkStoreContact>& aContacts,
       
   241             TInt aHighestOrderIndex );
       
   242 
       
   243         void RemoveTopnessFromContacts(
       
   244             RPointerArray<MVPbkStoreContact>& aContacts );
       
   245 
       
   246         void RemoveTopnessFromContact( MVPbkStoreContact& aContact );
       
   247         
       
   248         void ReorderContactsL(
       
   249             RPointerArray<MVPbkStoreContact>& aContacts );
       
   250         
       
   251         const MVPbkFieldType& TopContactFieldTypeL();
       
   252         
       
   253         void NotifyResultL();
       
   254         void NotifyError(TInt aErr);
       
   255         void AbortWithError(TInt aErr);
       
   256         
       
   257         CVPbkSortOrderAcquirer* AllContactsSortOrderL() const;
       
   258         
       
   259     private:        
       
   260         enum TTopManagementState
       
   261             {
       
   262             EStateNone,
       
   263             EStateOpenStore,
       
   264             EStateCreateView,
       
   265             EStateRetrieveLock,
       
   266             EStateModifyCommit,
       
   267             EStateAbortWithError
       
   268             };
       
   269         
       
   270     private: // data
       
   271         const TTopOperation iCurrentOperation;
       
   272         TTopManagementState iNextState;
       
   273 
       
   274         CVPbkContactManager& iContactManager; // not owned
       
   275         MVPbkContactViewBase* iView; // owned
       
   276         MVPbkContactStore* iContactStore; // not owned
       
   277         CVPbkContactLinkArray* iInputLinks; // owned
       
   278         RPointerArray<MVPbkStoreContact> iContacts; // owns the contacts
       
   279         MVPbkContactOperationBase* iContactOperation; // own
       
   280         CVPbkContactEasyManager* iContactEasyManager; //own
       
   281         
       
   282         // observers, not owned
       
   283         MVPbkOperationObserver* iObserver;
       
   284         MVPbkOperationResultObserver<MVPbkContactViewBase*>* iViewObserver;
       
   285         MVPbkOperationResultObserver<MVPbkContactLinkArray*>* iLinksObserver;
       
   286         MVPbkOperationErrorObserver* iErrorObserver;
       
   287         TInt iAbortError;
       
   288     };
       
   289 
       
   290 #endif //VPBKTOPCONTACTOPERATION_H
       
   291 //End of file