phonebookengines/VirtualPhonebook/VPbkCntModel/src/CRefineView.cpp
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 filtered contact view implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDES
       
    20 #include "CRefineView.h"
       
    21 
       
    22 // VPbkCntModel
       
    23 #include "CViewBase.h"
       
    24 #include <MVPbkContactLink.h>
       
    25 
       
    26 // Debugging headers
       
    27 #include <VPbkProfile.h>
       
    28 
       
    29 namespace VPbkCntModel {
       
    30 
       
    31 // --------------------------------------------------------------------------
       
    32 // CRefineView::CRefineView
       
    33 // --------------------------------------------------------------------------
       
    34 //
       
    35 inline CRefineView::CRefineView( MParentViewForFiltering& aParentView,
       
    36         CViewBase& aBaseView,
       
    37         MAlwaysIncludedContacts& aAlwaysIncluded ) 
       
    38         :   CFindViewBase( aParentView, aBaseView, EFalse ),
       
    39             iAlwaysIncluded( aAlwaysIncluded )    
       
    40     {
       
    41     }
       
    42 
       
    43 // --------------------------------------------------------------------------
       
    44 // CRefineView::~CRefineView
       
    45 // --------------------------------------------------------------------------
       
    46 //
       
    47 CRefineView::~CRefineView()
       
    48     {
       
    49     delete iIdleUpdate;
       
    50     }
       
    51 
       
    52 // --------------------------------------------------------------------------
       
    53 // CRefineView::NewLC
       
    54 // --------------------------------------------------------------------------
       
    55 //
       
    56 CRefineView* CRefineView::NewLC(      
       
    57         const MDesCArray& aFindStrings,
       
    58         MParentViewForFiltering& aParentView,
       
    59         CViewBase& aBaseView,
       
    60         MVPbkContactViewObserver& aExternalViewObserver,
       
    61         MVPbkContactFindPolicy& aContactFindPolicy,
       
    62         MAlwaysIncludedContacts& aAlwaysIncluded )
       
    63     {
       
    64     CRefineView* self = new ( ELeave ) CRefineView( aParentView, aBaseView, 
       
    65             aAlwaysIncluded );
       
    66     CleanupStack::PushL( self );
       
    67     self->BaseConstructL( aFindStrings, 
       
    68         aContactFindPolicy, aExternalViewObserver  );
       
    69     return self; 
       
    70     }
       
    71 
       
    72 // --------------------------------------------------------------------------
       
    73 // CRefineView::MatchL
       
    74 // --------------------------------------------------------------------------
       
    75 //
       
    76 void CRefineView::MatchL( 
       
    77         RPointerArray<CCntModelViewContact>& aMatchedContacts )
       
    78     {
       
    79     CleanupClosePushL( aMatchedContacts ); 
       
    80     if ( iIdleUpdate )
       
    81         {
       
    82         iIdleUpdate->Cancel();
       
    83         }
       
    84         
       
    85     const TInt contactCount = iParentView.ContactCountL();
       
    86     for ( TInt i = 0; i < contactCount; ++i )
       
    87         {
       
    88         // iParentView is always VPbkCntModel view and the contacts type
       
    89         // is CViewContact
       
    90         const CViewContact& candidate = static_cast<const CViewContact&>(
       
    91             iParentView.ContactAtL( i ) );
       
    92         if ( IsContactAlwaysIncluded( candidate ) || IsMatchL( candidate ) )
       
    93             {
       
    94             // iParentView is always CFindView or CRefineView. The contacts type
       
    95             // is CViewContact. It can be safely casted. Const cast be done
       
    96             // because aContact is actually owned by CFindView.
       
    97             CCntModelViewContact* nativeContact = 
       
    98                 const_cast<CCntModelViewContact*>( candidate.NativeContact() );
       
    99             aMatchedContacts.AppendL( nativeContact );
       
   100             }
       
   101         }    
       
   102     CleanupStack::Pop();
       
   103     }
       
   104 
       
   105 // --------------------------------------------------------------------------
       
   106 // CRefineView::DoContactAddedToViewL
       
   107 // --------------------------------------------------------------------------
       
   108 //    
       
   109 void CRefineView::DoContactAddedToViewL( MVPbkContactViewBase& aView,
       
   110         TInt aIndex, const MVPbkContactLink& /*aContactLink*/,
       
   111         RPointerArray<CCntModelViewContact>& aMatchedContacts )
       
   112     {
       
   113     if ( &iParentView == &aView && 
       
   114          IsMatchL( iParentView.ContactAtL( aIndex )))
       
   115         {
       
   116         // iParentView is always CFindView or CRefineView the contacts type
       
   117         // is CViewContact. It can be safely casted.
       
   118         const CViewContact& contact = static_cast<const CViewContact&>(
       
   119             iParentView.ContactAtL( aIndex ) );
       
   120         CCntModelViewContact* nativeContact = 
       
   121             const_cast<CCntModelViewContact*>( contact.NativeContact() );
       
   122         // Insert in correct location.
       
   123         aMatchedContacts.InsertInOrderL( nativeContact, 
       
   124                 TLinearOrder<CCntModelViewContact>(
       
   125                     CCompareView::CompareFieldsL ) );
       
   126         }
       
   127     }
       
   128 
       
   129 // --------------------------------------------------------------------------
       
   130 // CRefineView::UpdateFilterL
       
   131 // --------------------------------------------------------------------------
       
   132 //
       
   133 void CRefineView::UpdateFilterL( 
       
   134         const MDesCArray& aFindWords,
       
   135         const MVPbkContactBookmarkCollection* /*aAlwaysIncludedContacts*/ )
       
   136     {
       
   137     if ( !iIdleUpdate )
       
   138         {
       
   139         iIdleUpdate = CIdle::NewL( CActive::EPriorityStandard );
       
   140         }
       
   141         
       
   142     // Ignore aAlwaysIncludedContacts. This is
       
   143     // because in VPbkCntModel implementation CRefineView is bound to
       
   144     // it parent view CFindView. CFindView owns always included contacts.
       
   145     SetFindStringsL( aFindWords );
       
   146     // Start idle update.
       
   147     if ( !iIdleUpdate->IsActive() )
       
   148         {
       
   149         iIdleUpdate->Start( TCallBack( StartUpdateCallback, this ) ); 
       
   150         }
       
   151     }
       
   152     
       
   153 // --------------------------------------------------------------------------
       
   154 // CRefineView::IsContactAlwaysIncluded
       
   155 // --------------------------------------------------------------------------
       
   156 //
       
   157 TBool CRefineView::IsContactAlwaysIncluded( 
       
   158         const CViewContact& aContact ) const
       
   159     {
       
   160     // Refine view doesn't keep always included contacts itself but it
       
   161     // forwards request to CFindView
       
   162     return iAlwaysIncluded.IsContactAlwaysIncluded( aContact );
       
   163     }
       
   164 
       
   165 // --------------------------------------------------------------------------
       
   166 // CRefineView::StartUpdateCallback
       
   167 // --------------------------------------------------------------------------
       
   168 //
       
   169 TInt CRefineView::StartUpdateCallback( TAny* aThis )
       
   170     {
       
   171     CRefineView* view = static_cast<CRefineView*>( aThis );
       
   172     TRAPD( res, view->ActivateContactMatchL() )
       
   173     if ( res != KErrNone )
       
   174         {
       
   175         view->ContactViewError( *view, res, EFalse );
       
   176         }
       
   177     // Do not continue idle
       
   178     return EFalse;
       
   179     }
       
   180 } // namespace VPbkCntModel
       
   181 
       
   182 // End of File