phonebookengines/VirtualPhonebook/VPbkCntModel/src/CRefineView.cpp
changeset 0 e686773b3f54
child 32 2828b4d142c0
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     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     if ( iIdleUpdate )
       
    80         {
       
    81         iIdleUpdate->Cancel();
       
    82         }
       
    83         
       
    84     const TInt contactCount = iParentView.ContactCountL();
       
    85     for ( TInt i = 0; i < contactCount; ++i )
       
    86         {
       
    87         // iParentView is always VPbkCntModel view and the contacts type
       
    88         // is CViewContact
       
    89         const CViewContact& candidate = static_cast<const CViewContact&>(
       
    90             iParentView.ContactAtL( i ) );
       
    91         if ( IsContactAlwaysIncluded( candidate ) || IsMatchL( candidate ) )
       
    92             {
       
    93             // iParentView is always CFindView or CRefineView. The contacts type
       
    94             // is CViewContact. It can be safely casted. Const cast be done
       
    95             // because aContact is actually owned by CFindView.
       
    96             CCntModelViewContact* nativeContact = 
       
    97                 const_cast<CCntModelViewContact*>( candidate.NativeContact() );
       
    98             aMatchedContacts.AppendL( nativeContact );
       
    99             }
       
   100         }    
       
   101     }
       
   102 
       
   103 // --------------------------------------------------------------------------
       
   104 // CRefineView::DoContactAddedToViewL
       
   105 // --------------------------------------------------------------------------
       
   106 //    
       
   107 void CRefineView::DoContactAddedToViewL( MVPbkContactViewBase& aView,
       
   108         TInt aIndex, const MVPbkContactLink& /*aContactLink*/,
       
   109         RPointerArray<CCntModelViewContact>& aMatchedContacts )
       
   110     {
       
   111     if ( &iParentView == &aView && 
       
   112          IsMatchL( iParentView.ContactAtL( aIndex )))
       
   113         {
       
   114         // iParentView is always CFindView or CRefineView the contacts type
       
   115         // is CViewContact. It can be safely casted.
       
   116         const CViewContact& contact = static_cast<const CViewContact&>(
       
   117             iParentView.ContactAtL( aIndex ) );
       
   118         CCntModelViewContact* nativeContact = 
       
   119             const_cast<CCntModelViewContact*>( contact.NativeContact() );
       
   120         // Insert in correct location.
       
   121         aMatchedContacts.InsertInOrderL( nativeContact, 
       
   122                 TLinearOrder<CCntModelViewContact>(
       
   123                     CCompareView::CompareFieldsL ) );
       
   124         }
       
   125     }
       
   126 
       
   127 // --------------------------------------------------------------------------
       
   128 // CRefineView::UpdateFilterL
       
   129 // --------------------------------------------------------------------------
       
   130 //
       
   131 void CRefineView::UpdateFilterL( 
       
   132         const MDesCArray& aFindWords,
       
   133         const MVPbkContactBookmarkCollection* /*aAlwaysIncludedContacts*/ )
       
   134     {
       
   135     if ( !iIdleUpdate )
       
   136         {
       
   137         iIdleUpdate = CIdle::NewL( CActive::EPriorityStandard );
       
   138         }
       
   139         
       
   140     // Ignore aAlwaysIncludedContacts. This is
       
   141     // because in VPbkCntModel implementation CRefineView is bound to
       
   142     // it parent view CFindView. CFindView owns always included contacts.
       
   143     SetFindStringsL( aFindWords );
       
   144     // Start idle update.
       
   145     if ( !iIdleUpdate->IsActive() )
       
   146         {
       
   147         iIdleUpdate->Start( TCallBack( StartUpdateCallback, this ) ); 
       
   148         }
       
   149     }
       
   150     
       
   151 // --------------------------------------------------------------------------
       
   152 // CRefineView::IsContactAlwaysIncluded
       
   153 // --------------------------------------------------------------------------
       
   154 //
       
   155 TBool CRefineView::IsContactAlwaysIncluded( 
       
   156         const CViewContact& aContact ) const
       
   157     {
       
   158     // Refine view doesn't keep always included contacts itself but it
       
   159     // forwards request to CFindView
       
   160     return iAlwaysIncluded.IsContactAlwaysIncluded( aContact );
       
   161     }
       
   162 
       
   163 // --------------------------------------------------------------------------
       
   164 // CRefineView::StartUpdateCallback
       
   165 // --------------------------------------------------------------------------
       
   166 //
       
   167 TInt CRefineView::StartUpdateCallback( TAny* aThis )
       
   168     {
       
   169     CRefineView* view = static_cast<CRefineView*>( aThis );
       
   170     TRAPD( res, view->ActivateContactMatchL() )
       
   171     if ( res != KErrNone )
       
   172         {
       
   173         view->ContactViewError( *view, res, EFalse );
       
   174         }
       
   175     // Do not continue idle
       
   176     return EFalse;
       
   177     }
       
   178 } // namespace VPbkCntModel
       
   179 
       
   180 // End of File