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