phonebookengines/VirtualPhonebook/VPbkCntModel/inc/CFindView.h
branchRCL_3
changeset 20 f4a778e096c2
equal deleted inserted replaced
19:5b6f26637ad3 20: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_CFINDVIEW_H
       
    20 #define VPBKCNTMODEL_CFINDVIEW_H
       
    21 
       
    22 // INCLUDES
       
    23 #include "CFindViewBase.h"
       
    24 
       
    25 // FORWARD DECLARATIONS
       
    26 class CVPbkContactFindPolicy;
       
    27 
       
    28 namespace VPbkCntModel {
       
    29 
       
    30 
       
    31 /**
       
    32  * Virtual phonebook view that holds the search results from Contact model
       
    33  */
       
    34 NONSHARABLE_CLASS( CFindView ): public CFindViewBase
       
    35     {
       
    36     public: // Constructor and destructor
       
    37 
       
    38         /**
       
    39          * Creates a new instance of this class.
       
    40          *
       
    41          * @param aFindStrings Search words
       
    42          * @param aBaseView Virtual phonebook's view where the search
       
    43          *                  is pointed
       
    44          * @param aExternalViewObserver An observer that was given
       
    45          *        by the Virtual Phonebook client
       
    46          * @param aAlwaysIncludedContacts A collection of contacts that
       
    47          *        must be included even they don't match to find words.
       
    48          * @param aRFs File session
       
    49          * @return  A new instance of this class.
       
    50          */
       
    51         static CFindView* NewLC(
       
    52                 const MDesCArray& aFindStrings,
       
    53                 CViewBase& aBaseView,
       
    54                 MVPbkContactViewObserver& aExternalViewObserver,
       
    55                 const MVPbkContactBookmarkCollection* aAlwaysIncludedContacts,
       
    56                 RFs& aRFs );
       
    57 
       
    58         /**
       
    59          * Destructor.
       
    60          */
       
    61         ~CFindView();
       
    62 
       
    63     private: // From CFindViewBase
       
    64         void MatchL( RPointerArray<CCntModelViewContact>& aMatchedContacts );
       
    65         void DoContactAddedToViewL( MVPbkContactViewBase& aView,
       
    66                 TInt aIndex, const MVPbkContactLink& aContactLink,
       
    67                 RPointerArray<CCntModelViewContact>& aMatchedContacts );
       
    68 
       
    69     private: // From MVPbkContactViewFiltering
       
    70         /// Subclasses must implement this
       
    71         void UpdateFilterL(
       
    72             const MDesCArray& aFindWords,
       
    73             const MVPbkContactBookmarkCollection* aAlwaysIncludedContacts );
       
    74 
       
    75     private: // From MAlwaysIncludedContacts
       
    76         TBool IsContactAlwaysIncluded( const CViewContact& aContact ) const;
       
    77 
       
    78     private: // Implementation
       
    79         CFindView( CViewBase& aBaseView );
       
    80         void ConstructL( const MDesCArray& aFindStrings,
       
    81             const MVPbkContactBookmarkCollection* aAlwaysIncludedContacts,
       
    82             MVPbkContactViewObserver& aExternalViewObserver, RFs& aRFs );
       
    83         void SetAlwaysIncludedContactsL(
       
    84             const MVPbkContactBookmarkCollection* aAlwaysIncludedContacts );
       
    85         void MatchContactL( const CViewContact& aViewContact,
       
    86             RPointerArray<CCntModelViewContact>& aMatchedContacts );
       
    87         TBool IsContactsModelMatchL( const CViewContact& aContact,
       
    88             TInt& aMatchArrayIndex ) const;
       
    89         void RemoveFromMatchArrayIfFound( const CViewContact& aContact );
       
    90         TInt FindFromMatchArray( const CViewContact& aContact ) const;
       
    91         void HeapSortL(RPointerArray<CCntModelViewContact> aViewContacts);
       
    92 
       
    93     private: // Data
       
    94         /// Own: the find policy
       
    95         CVPbkContactFindPolicy* iFindPolicy;
       
    96         /// Own: always included contacts
       
    97         RArray<TContactItemId> iAlwaysIncluded;
       
    98         /// Own: Matched contacts from Contacts Model
       
    99         RPointerArray<CCntModelViewContact> iContactsModelMatchContacts;
       
   100     };
       
   101 
       
   102 // CleanupStack helpers for item owning RPointerArrays
       
   103 template <class T>
       
   104 class CleanupResetAndDestroy
       
   105     {
       
   106 public:
       
   107     inline static void PushL(T& aRef)
       
   108         { CleanupStack::PushL(TCleanupItem(&ResetAndDestroy,&aRef)); }
       
   109 private:
       
   110     inline static void ResetAndDestroy(TAny *aPtr)
       
   111         { static_cast<T*>(aPtr)->ResetAndDestroy(); }
       
   112     };
       
   113 
       
   114 template <class T>
       
   115 inline void CleanupResetAndDestroyPushL(T& aRef)
       
   116     { CleanupResetAndDestroy<T>::PushL(aRef); }
       
   117 } // namespace VPbkCntModel
       
   118 
       
   119 #endif // VPBKCNTMODEL_CFINDVIEW_H
       
   120 
       
   121 // End of File