phonebookengines/VirtualPhonebook/VPbkSimStore/inc/CFindViewBase.h
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2006-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:  Sim store contact view implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef VPBKSIMSTORE_CFINDVIEWBASE_H
       
    20 #define VPBKSIMSTORE_CFINDVIEWBASE_H
       
    21 
       
    22 // INCLUDES
       
    23 #include <e32base.h>
       
    24 
       
    25 #include <MVPbkContactViewFiltering.h>
       
    26 #include <MVPbkContactViewObserver.h>
       
    27 #include <badesca.h>
       
    28 #include <VPbkSimCntFieldTypes.hrh>
       
    29 #include "MParentViewForFiltering.h"
       
    30 
       
    31 // FORWARD DECLARATIONS
       
    32 class MVPbkSimContact;
       
    33 class MVPbkSimStoreOperation;
       
    34 class MVPbkContactFindPolicy;
       
    35 class CVPbkFieldTypeRefsList;
       
    36 template<class MVPbkContactViewObserver> class CVPbkAsyncObjectOperation;
       
    37 template<class MFilteredViewSupportObserver> class CVPbkAsyncObjectOperation;
       
    38 
       
    39 namespace VPbkSimStore {
       
    40 
       
    41 // FORWARD DECLARATIONS
       
    42 class MParentViewForFiltering;
       
    43 class CContactView;
       
    44 class CViewContact;
       
    45 
       
    46 /**
       
    47  * An interface for checking if the contact is one of the
       
    48  * always included contacts
       
    49  */
       
    50 NONSHARABLE_CLASS( MAlwaysIncludedContacts )
       
    51     {
       
    52     public: 
       
    53         /**
       
    54          * Return ETrue aContact is always included
       
    55          */
       
    56         virtual TBool IsContactAlwaysIncluded( 
       
    57             const CViewContact& aContact ) const = 0;
       
    58     
       
    59     protected:
       
    60         ~MAlwaysIncludedContacts() {}
       
    61     };
       
    62 
       
    63 /**
       
    64  * A base class for filtered views that implements most of
       
    65  * the MVPbkContactView functions.
       
    66  */
       
    67 NONSHARABLE_CLASS( CFindViewBase ): public CBase,
       
    68                                     public MParentViewForFiltering,
       
    69                                     public MFilteredViewSupportObserver,
       
    70                                     public MVPbkContactViewFiltering,
       
    71                                     protected MAlwaysIncludedContacts
       
    72     {
       
    73     public: // Constructor and destructor
       
    74         /**
       
    75          * Destructor.
       
    76          */
       
    77         ~CFindViewBase();    
       
    78 
       
    79     public: //New functions
       
    80         
       
    81         /**
       
    82          * Starts matching asynchrnously. Sends event
       
    83          * using MVPbkContactViewObserver when the find is ready.
       
    84          */ 
       
    85         void ActivateContactMatchL();
       
    86                                             
       
    87     public: // Functions from MVPbkContactView
       
    88         MVPbkObjectHierarchy& ParentObject() const;
       
    89         void RefreshL();
       
    90         TInt ContactCountL() const;
       
    91         const MVPbkViewContact& ContactAtL(
       
    92                 TInt aIndex ) const;  
       
    93         MVPbkContactLink* CreateLinkLC(
       
    94                 TInt aIndex ) const;
       
    95         TInt IndexOfLinkL(
       
    96                 const MVPbkContactLink& aContactLink ) const;
       
    97         TVPbkContactViewType Type() const;
       
    98         void ChangeSortOrderL(const MVPbkFieldTypeList& aSortOrder);
       
    99         const MVPbkFieldTypeList& SortOrder() const;        
       
   100         void AddObserverL(MVPbkContactViewObserver& aObserver);
       
   101         void RemoveObserver(MVPbkContactViewObserver& aObserver);        
       
   102         TBool MatchContactStore(const TDesC& aContactStoreUri) const;
       
   103         TBool MatchContactStoreDomain(const TDesC& aContactStoreDomain) const;
       
   104         MVPbkContactBookmark* CreateBookmarkLC(
       
   105                 TInt aIndex ) const;
       
   106         TInt IndexOfBookmarkL(
       
   107                 const MVPbkContactBookmark& aContactBookmark ) const;
       
   108         MVPbkContactViewFiltering* ViewFiltering();
       
   109     
       
   110     public: // From MParentViewForFiltering
       
   111         void AddFilteringObserverL( MFilteredViewSupportObserver& aObserver );
       
   112         void RemoveFilteringObserver( MFilteredViewSupportObserver& aObserver );
       
   113         
       
   114     public: // Functions from MVPbkContactViewFiltering
       
   115         MVPbkContactViewBase* CreateFilteredViewLC( 
       
   116                 MVPbkContactViewObserver& aObserver,
       
   117                 const MDesCArray& aFindWords,
       
   118                 const MVPbkContactBookmarkCollection* aAlwaysIncludedContacts );
       
   119         /// Subclasses must implement these
       
   120         virtual void UpdateFilterL( 
       
   121             const MDesCArray& aFindWords,
       
   122             const MVPbkContactBookmarkCollection* aAlwaysIncludedContacts ) = 0;
       
   123         virtual TBool IsNativeMatchingRequestActive() = 0;
       
   124                 
       
   125     public: // From MVPbkContactViewObserver
       
   126         virtual void ContactViewReady( MVPbkContactViewBase& aView ) = 0;
       
   127         void ContactViewUnavailable( MVPbkContactViewBase& aView );
       
   128         void ContactAddedToView(
       
   129                 MVPbkContactViewBase& aView, 
       
   130                 TInt aIndex, 
       
   131                 const MVPbkContactLink& aContactLink );
       
   132         void ContactRemovedFromView(
       
   133                 MVPbkContactViewBase& aView, 
       
   134                 TInt aIndex, 
       
   135                 const MVPbkContactLink& aContactLink );
       
   136         void ContactViewError(
       
   137                 MVPbkContactViewBase& aView, 
       
   138                 TInt aError, 
       
   139                 TBool aErrorNotified );
       
   140         /**
       
   141          * Subclass handles the logic after the parent view is ready
       
   142          * for filtering
       
   143          */
       
   144         virtual void ContactViewReadyForFiltering( 
       
   145                 MParentViewForFiltering& aView ) = 0;
       
   146         void ContactViewUnavailableForFiltering( 
       
   147                 MParentViewForFiltering& aView );
       
   148                       
       
   149     protected: // Implementation
       
   150         /**
       
   151          * @param aParentView the view whose contacts are filtered
       
   152          * @param aAllContactsView the all contacts view.
       
   153          * @param aOwnsMatchedContacts ETrue if this instance owns
       
   154          *          contacts in iMatchedContacts
       
   155          */
       
   156         CFindViewBase( MParentViewForFiltering& aParentView,
       
   157             CContactView& aAllContactsView,
       
   158             TBool aOwnsMatchedContacts );
       
   159         
       
   160         /**
       
   161          * @param aExternalViewObserver an observer that was given
       
   162          *        by the Virtual Phonebook client
       
   163          * @param aFindString the find words for filtering
       
   164          * @param aFindPolicy a policy for matching.
       
   165          */
       
   166         void BaseConstructL( MVPbkContactViewObserver& aExternalViewObserver,
       
   167             const MDesCArray& aFindStrings,
       
   168             MVPbkContactFindPolicy& aFindPolicy );
       
   169         
       
   170         /**
       
   171          * Start synchrnous contact match.
       
   172          * Calls first MatchL and then sends events to obserers.
       
   173          */
       
   174         void MatchContactsL();
       
   175         
       
   176         /**
       
   177          * Checks if aViewContact matches to iFindStrings
       
   178          *
       
   179          * @param aViewContact the contact to be cheked
       
   180          */
       
   181         TBool IsMatchL( const MVPbkViewContact& aViewContact );
       
   182         
       
   183         /**
       
   184          * Returns the find words used in filtering
       
   185          *
       
   186          * @return the find words used in filtering
       
   187          */
       
   188         const MDesCArray& FindStrings() const;
       
   189         
       
   190         /**
       
   191          * Deletes old find strings and allocates new ones based on
       
   192          * aFindStrings.
       
   193          *
       
   194          * @param aFindStrings new find strings
       
   195          */
       
   196         void SetFindStringsL( const MDesCArray& aFindStrings );
       
   197         
       
   198         /**
       
   199          * Sends ViewReady or ViewUnavailable event depending on view state
       
   200          */
       
   201         void SendViewStateEventToObservers();
       
   202                 
       
   203     private: // New functions
       
   204         /**
       
   205          * Subclass defines the match logic. This is called from
       
   206          * MatchContactsL.
       
   207          *
       
   208          * @param aMatchedContacts an array that is filled by subclass.
       
   209          */
       
   210         virtual void MatchL( 
       
   211                 RPointerArray<MVPbkSimContact>& aMatchedContacts ) = 0;
       
   212         
       
   213         /**
       
   214          * Subclass handles matching of added contact and adds it
       
   215          * to the correct location in aMatchedContacts.
       
   216          *
       
   217          * @see MVPbkContactViewObserver::ContactAddedToView
       
   218          * @param aMatchedContacts an array of contacts in which the new
       
   219          *                         contact is inserted if it matches.
       
   220          */
       
   221         virtual void DoContactAddedToViewL( MVPbkContactViewBase& aView,
       
   222                 TInt aIndex, const MVPbkContactLink& aContactLink,
       
   223                 RPointerArray<MVPbkSimContact>& aMatchedContacts ) = 0;
       
   224     
       
   225     private: // Implementation
       
   226         void DoAddObserver( MVPbkContactViewObserver& aObserver );
       
   227         void DoAddObserverError( MVPbkContactViewObserver& aObserver,
       
   228                 TInt aError );
       
   229         void DoAddFilteringObserverL( MFilteredViewSupportObserver& aObserver );
       
   230         void DoAddFilteringObserverError( 
       
   231                 MFilteredViewSupportObserver& aObserver, TInt aError );
       
   232         void HandleContactAddedToViewL( MVPbkContactViewBase& aView,
       
   233                 TInt aIndex, const MVPbkContactLink& aContactLink );
       
   234         void HandleContactRemovedFromViewL( MVPbkContactViewBase& aView, 
       
   235                 TInt aIndex, const MVPbkContactLink& aContactLink );
       
   236         void ResetContacts();
       
   237         
       
   238     protected: // Data
       
   239         /// Ref: The view that cretead this filtered view
       
   240         MParentViewForFiltering& iParentView;
       
   241         /// Ref: The all contacts view
       
   242         CContactView& iAllContactsView;
       
   243         
       
   244     private: // Data    
       
   245         /// Own: find words from the client
       
   246         CDesCArrayFlat* iFindStrings;
       
   247         /// Own or Not Own: depends on iOwnsContacts
       
   248         RPointerArray<MVPbkSimContact> iMatchedContacts;
       
   249         /// Own: the current view contact
       
   250         CViewContact* iCurrentContact;
       
   251         /// Ref: a policy for match
       
   252         MVPbkContactFindPolicy* iContactFindPolicy;
       
   253         /// Own: a field type list for name construction policy
       
   254         CVPbkFieldTypeRefsList* iFieldTypeRefsList;
       
   255         /// Ref: an array of view observers
       
   256         RPointerArray<MVPbkContactViewObserver> iObservers;
       
   257         /// Ref: an array of observers that filters this view.
       
   258         RPointerArray<MFilteredViewSupportObserver> iFilteringObservers;
       
   259         /// Own: an async operation for MVPbkContactViewObserver
       
   260         CVPbkAsyncObjectOperation<MVPbkContactViewObserver>* iObserverOp;
       
   261         /// Own: an async operation for MFilteredViewSupportObserver
       
   262         CVPbkAsyncObjectOperation<MFilteredViewSupportObserver>* iFilterObsOp;
       
   263         /// Own: ETrue if this view owns contacts in iMatchedContacts
       
   264         TBool iOwnsContacts;
       
   265         /// Own: ETrue if this view is ready
       
   266         TBool iViewReady;
       
   267     };
       
   268     
       
   269 } // namespace VPbkSimStore    
       
   270 
       
   271 #endif // VPBKSIMSTORE_CFINDVIEWBASE_H
       
   272 
       
   273 // End of File