phonebookengines/VirtualPhonebook/VPbkEng/src/CVPbkFindView.cpp
changeset 0 e686773b3f54
child 35 4ae315f230bc
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2005-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:  Filtered contact view
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "CVPbkFindView.h"
       
    20 #include <MVPbkFieldType.h>
       
    21 #include <CVPbkSortOrder.h>
       
    22 #include <CVPbkAsyncCallback.h>
       
    23 #include <MVPbkViewContact.h>
       
    24 #include <CVPbkAsyncOperation.h>
       
    25 #include <VPbkError.h>
       
    26 
       
    27 #include <CVPbkFieldTypeRefsList.h>
       
    28 #include <CVPbkContactNameConstructionPolicy.h>
       
    29 #include <CVPbkContactFindPolicy.h>
       
    30 #include <MVPbkContactBookmarkCollection.h>
       
    31 #include <CVPbkContactFieldIterator.h>
       
    32 #include <MVPbkContactFieldData.h>
       
    33 #include <MVPbkContactFieldTextData.h>
       
    34 
       
    35 #include <VPbkDebug.h>
       
    36 
       
    37 namespace {
       
    38 const TInt KObserverArrayGranularity( 4 );
       
    39 const TInt KGranularity( 2 );
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // Event sending function for one reference parameter
       
    43 // ---------------------------------------------------------------------------
       
    44 // 
       
    45 template <class NotifyFunc>
       
    46 void SendEventToObservers(MVPbkContactViewBase& aView,
       
    47                           RPointerArray<MVPbkContactViewObserver>& iObservers,
       
    48                           NotifyFunc aNotifyFunc)
       
    49     {
       
    50     const TInt count = iObservers.Count();
       
    51     for (TInt i = count - 1; i >= 0; --i)
       
    52         {
       
    53         MVPbkContactViewObserver* observer = iObservers[i];
       
    54         (observer->*aNotifyFunc)(aView);
       
    55         }
       
    56     }
       
    57 
       
    58 // ---------------------------------------------------------------------------
       
    59 // Event sending functions for 3 parameters
       
    60 // ---------------------------------------------------------------------------
       
    61 // 
       
    62 template <class NotifyFunc, class ParamType1, class ParamType2>
       
    63 void SendEventToObservers(MVPbkContactViewBase& aView,
       
    64                           RPointerArray<MVPbkContactViewObserver>& iObservers,
       
    65                           NotifyFunc aNotifyFunc,
       
    66                           ParamType1 aParam1,
       
    67                           const ParamType2& aParam2)
       
    68     {
       
    69     const TInt count = iObservers.Count();
       
    70     for (TInt i = count - 1; i >= 0; --i)
       
    71         {
       
    72         MVPbkContactViewObserver* observer = iObservers[i];
       
    73         (observer->*aNotifyFunc)(aView, aParam1, aParam2);
       
    74         }
       
    75     }
       
    76 
       
    77 } // namespace
       
    78 
       
    79 
       
    80 // ---------------------------------------------------------------------------
       
    81 // CVPbkFindView::CVPbkFindView
       
    82 // ---------------------------------------------------------------------------
       
    83 // 
       
    84 CVPbkFindView::CVPbkFindView(
       
    85         MVPbkContactViewBase& aBaseView,        
       
    86         const MVPbkFieldTypeList* aMasterFieldTypeList ) :
       
    87     iBaseView(aBaseView),
       
    88     iMasterFieldTypeList( aMasterFieldTypeList ),
       
    89     iObservers( KObserverArrayGranularity )
       
    90     {
       
    91     }
       
    92 
       
    93 // ---------------------------------------------------------------------------
       
    94 // CVPbkFindView::ConstructL
       
    95 // ---------------------------------------------------------------------------
       
    96 // 
       
    97 inline void CVPbkFindView::ConstructL( 
       
    98         const MDesCArray& aFindWords,
       
    99         const MVPbkContactBookmarkCollection* aAlwaysIncludedContacts )
       
   100     {
       
   101     VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
       
   102         ("CVPbkFindView::ConstructL(0x%x)"), this);
       
   103     
       
   104     iAsyncOperation = new(ELeave) VPbkEngUtils::CVPbkAsyncOperation;
       
   105     
       
   106     iFindStrings = new(ELeave)CDesCArrayFlat( KGranularity );
       
   107     SetFindStringsL( aFindWords );
       
   108     
       
   109     SetAlwaysIncludedContactsL( aAlwaysIncludedContacts );
       
   110 
       
   111     // Create contact find policy
       
   112     iContactFindPolicy = CVPbkContactFindPolicy::NewL();
       
   113     
       
   114     CVPbkContactNameConstructionPolicy::TParam param( *iMasterFieldTypeList );
       
   115     iNameConstructionPolicy =
       
   116         CVPbkContactNameConstructionPolicy::NewL( param );
       
   117         
       
   118     //Create field type list
       
   119     iFieldTypeRefsList = CVPbkFieldTypeRefsList::NewL();        
       
   120             
       
   121     iBaseView.AddObserverL(*this);
       
   122 
       
   123     VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
       
   124         ("CVPbkFindView::ConstructL(0x%x) end"), this);
       
   125     }
       
   126 
       
   127 // ---------------------------------------------------------------------------
       
   128 // CVPbkFindView::NewL
       
   129 // ---------------------------------------------------------------------------
       
   130 // 
       
   131 CVPbkFindView* CVPbkFindView::NewLC(
       
   132         MVPbkContactViewBase& aBaseView,
       
   133         MVPbkContactViewObserver& aObserver,
       
   134         const MDesCArray& aFindWords,
       
   135         const MVPbkContactBookmarkCollection* aAlwaysIncludedContacts,
       
   136         const MVPbkFieldTypeList& aMasterFieldTypeList )
       
   137     {
       
   138     CVPbkFindView* self = 
       
   139         new(ELeave) CVPbkFindView(
       
   140             aBaseView, &aMasterFieldTypeList );
       
   141     CleanupStack::PushL(self);
       
   142     self->ConstructL( aFindWords, aAlwaysIncludedContacts );
       
   143     self->AddObserverL(aObserver);
       
   144     return self;
       
   145     }
       
   146 
       
   147 // ---------------------------------------------------------------------------
       
   148 // CVPbkFindView::~CVPbkFindView
       
   149 // ---------------------------------------------------------------------------
       
   150 // 
       
   151 CVPbkFindView::~CVPbkFindView()
       
   152     {    
       
   153     iContactMapping.Reset();   
       
   154     iBaseView.RemoveObserver(*this); 
       
   155     iObservers.Close();
       
   156     delete iFindStrings;
       
   157     delete iFieldTypeRefsList;
       
   158     delete iNameConstructionPolicy;
       
   159     delete iContactFindPolicy;
       
   160     delete iAsyncOperation;        
       
   161     }
       
   162 
       
   163 // ---------------------------------------------------------------------------
       
   164 // CVPbkFindView::Type
       
   165 // ---------------------------------------------------------------------------
       
   166 // 
       
   167 TVPbkContactViewType CVPbkFindView::Type() const
       
   168     {
       
   169     return iBaseView.Type();
       
   170     }
       
   171 
       
   172 // ---------------------------------------------------------------------------
       
   173 // CVPbkFindView::ChangeSortOrderL
       
   174 // ---------------------------------------------------------------------------
       
   175 // 
       
   176 void CVPbkFindView::ChangeSortOrderL(
       
   177         const MVPbkFieldTypeList& aSortOrder )
       
   178     {
       
   179     VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
       
   180         ("CVPbkFindView::ChangeSortOrderL(0x%x)"), &aSortOrder);
       
   181 
       
   182     iBaseView.ChangeSortOrderL(aSortOrder);
       
   183     }
       
   184 
       
   185 // ---------------------------------------------------------------------------
       
   186 // CVPbkFindView::SortOrder
       
   187 // ---------------------------------------------------------------------------
       
   188 // 
       
   189 const MVPbkFieldTypeList& CVPbkFindView::SortOrder() const
       
   190     {
       
   191     return iBaseView.SortOrder();
       
   192     }
       
   193 
       
   194 // ---------------------------------------------------------------------------
       
   195 // CVPbkFindView::RefreshL
       
   196 // ---------------------------------------------------------------------------
       
   197 // 
       
   198 void CVPbkFindView::RefreshL()
       
   199     {
       
   200     iBaseView.RefreshL();
       
   201     }
       
   202 
       
   203 // ---------------------------------------------------------------------------
       
   204 // CVPbkFindView::ContactCountL
       
   205 // ---------------------------------------------------------------------------
       
   206 // 
       
   207 TInt CVPbkFindView::ContactCountL() const
       
   208     {
       
   209     return iContactMapping.Count();
       
   210     }
       
   211 
       
   212 // ---------------------------------------------------------------------------
       
   213 // CVPbkFindView::ContactAtL
       
   214 // ---------------------------------------------------------------------------
       
   215 // 
       
   216 const MVPbkViewContact& CVPbkFindView::ContactAtL(
       
   217         TInt aIndex ) const
       
   218     {
       
   219     __ASSERT_ALWAYS( aIndex >= 0,
       
   220         VPbkError::Panic( VPbkError::EInvalidContactIndex ) );
       
   221     if ( aIndex >= iContactMapping.Count() )
       
   222         {
       
   223         User::Leave( KErrArgument );
       
   224         }
       
   225 
       
   226     return iBaseView.ContactAtL(iContactMapping[aIndex]);
       
   227     }
       
   228 
       
   229 // ---------------------------------------------------------------------------
       
   230 // CVPbkFindView::CreateLinkLC
       
   231 // ---------------------------------------------------------------------------
       
   232 // 
       
   233 MVPbkContactLink* CVPbkFindView::CreateLinkLC( TInt aIndex ) const
       
   234     {
       
   235     __ASSERT_ALWAYS( aIndex >= 0,
       
   236         VPbkError::Panic( VPbkError::EInvalidContactIndex ) );
       
   237     if ( aIndex >= iContactMapping.Count() )
       
   238         {
       
   239         User::Leave( KErrArgument );
       
   240         }
       
   241 
       
   242     return iBaseView.ContactAtL(iContactMapping[aIndex]).CreateLinkLC();
       
   243     }
       
   244 
       
   245 // ---------------------------------------------------------------------------
       
   246 // CVPbkFindView::IndexOfLinkL
       
   247 // ---------------------------------------------------------------------------
       
   248 // 
       
   249 TInt CVPbkFindView::IndexOfLinkL(
       
   250         const MVPbkContactLink& aContactLink ) const
       
   251     {
       
   252     TInt baseIndex = iBaseView.IndexOfLinkL(aContactLink);
       
   253     return iContactMapping.Find(baseIndex);
       
   254     }
       
   255 
       
   256 // ---------------------------------------------------------------------------
       
   257 // CVPbkFindView::AddObserverL
       
   258 // ---------------------------------------------------------------------------
       
   259 // 
       
   260 void CVPbkFindView::AddObserverL( 
       
   261         MVPbkContactViewObserver& aObserver )
       
   262     {
       
   263     VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
       
   264         ("CVPbkFindView::AddObserverL(0x%x)"), &aObserver);
       
   265 
       
   266     VPbkEngUtils::MAsyncCallback* notifyObserver =
       
   267         VPbkEngUtils::CreateAsyncCallbackLC(*this,
       
   268                 &CVPbkFindView::DoAddObserverL,
       
   269                 &CVPbkFindView::AddObserverError,
       
   270                 aObserver);
       
   271     iAsyncOperation->CallbackL(notifyObserver);
       
   272     CleanupStack::Pop(notifyObserver);
       
   273 
       
   274     /// Insert to first position because event are send in reverse order.
       
   275     /// Last inserted gets notifcation last.
       
   276     iObservers.InsertL( &aObserver, 0 );
       
   277     
       
   278     VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
       
   279         ("CVPbkFindView::AddObserverL(0x%x) end"), &aObserver);
       
   280     }
       
   281 
       
   282 // ---------------------------------------------------------------------------
       
   283 // CVPbkFindView::DoAddObserverL
       
   284 // ---------------------------------------------------------------------------
       
   285 // 
       
   286 void CVPbkFindView::DoAddObserverL(
       
   287         MVPbkContactViewObserver& aObserver )
       
   288     {
       
   289     VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
       
   290         ("CVPbkFindView::DoAddObserverL(0x%x)"), &aObserver);
       
   291 
       
   292     if ( iObservers.Find( &aObserver ) != KErrNotFound )
       
   293         {
       
   294         if ( iIsReady )
       
   295             {
       
   296             VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
       
   297             ("CVPbkFindView::DoAddObserverL(0x%x) contact view ready"), 
       
   298                 &aObserver);
       
   299 
       
   300             // If this view is ready and there was no error,
       
   301             // tell it to the observer
       
   302             aObserver.ContactViewReady( *this );
       
   303             }
       
   304         else
       
   305             {
       
   306             aObserver.ContactViewUnavailable( *this );
       
   307             }    
       
   308         }
       
   309     VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
       
   310         ("CVPbkFindView::DoAddObserverL(0x%x) end"), &aObserver);
       
   311     }
       
   312 
       
   313 // ---------------------------------------------------------------------------
       
   314 // CVPbkFindView::AddObserverError
       
   315 // ---------------------------------------------------------------------------
       
   316 // 
       
   317 void CVPbkFindView::AddObserverError(
       
   318         MVPbkContactViewObserver& aObserver, TInt aError )
       
   319     {
       
   320     VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
       
   321         ("CVPbkFindView::AddObserverError(0x%x, %d)"), &aObserver, aError);
       
   322 
       
   323     aObserver.ContactViewError(*this, aError, EFalse);
       
   324     }
       
   325 
       
   326 // ---------------------------------------------------------------------------
       
   327 // CVPbkFindView::RemoveObserver
       
   328 // ---------------------------------------------------------------------------
       
   329 // 
       
   330 void CVPbkFindView::RemoveObserver(
       
   331         MVPbkContactViewObserver& aObserver )
       
   332     {
       
   333     VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
       
   334         ("CVPbkFindView::RemoveObserverError(0x%x)"), &aObserver);
       
   335 
       
   336     const TInt index = iObservers.Find( &aObserver );
       
   337     if (index != KErrNotFound)
       
   338         {
       
   339         iObservers.Remove(index);
       
   340         }
       
   341     }
       
   342 
       
   343 // ---------------------------------------------------------------------------
       
   344 // CVPbkFindView::MatchContactStore
       
   345 // ---------------------------------------------------------------------------
       
   346 // 
       
   347 TBool CVPbkFindView::MatchContactStore(
       
   348         const TDesC& aContactStoreUri ) const
       
   349     {
       
   350     return iBaseView.MatchContactStore(aContactStoreUri);
       
   351     }
       
   352 
       
   353 // ---------------------------------------------------------------------------
       
   354 // CVPbkFindView::MatchContactStoreDomain
       
   355 // ---------------------------------------------------------------------------
       
   356 // 
       
   357 TBool CVPbkFindView::MatchContactStoreDomain(
       
   358         const TDesC& aContactStoreDomain ) const
       
   359     {
       
   360     return iBaseView.MatchContactStoreDomain(aContactStoreDomain);
       
   361     }
       
   362 
       
   363 // ---------------------------------------------------------------------------
       
   364 // CVPbkFindView::CreateBookmarkLC
       
   365 // ---------------------------------------------------------------------------
       
   366 // 
       
   367 MVPbkContactBookmark* CVPbkFindView::CreateBookmarkLC(
       
   368         TInt aIndex ) const
       
   369     {
       
   370     return iBaseView.ContactAtL(iContactMapping[aIndex]).CreateBookmarkLC();
       
   371     }
       
   372 
       
   373 // ---------------------------------------------------------------------------
       
   374 // CVPbkFindView::IndexOfBookmarkL
       
   375 // ---------------------------------------------------------------------------
       
   376 // 
       
   377 TInt CVPbkFindView::IndexOfBookmarkL(
       
   378         const MVPbkContactBookmark& aContactBookmark ) const
       
   379     {
       
   380     TInt baseIndex = iBaseView.IndexOfBookmarkL(aContactBookmark);
       
   381     return iContactMapping.Find(baseIndex);
       
   382     }
       
   383 
       
   384 // ---------------------------------------------------------------------------
       
   385 // CVPbkFindView::ViewFiltering
       
   386 // ---------------------------------------------------------------------------
       
   387 //         
       
   388 MVPbkContactViewFiltering* CVPbkFindView::ViewFiltering()
       
   389     {    
       
   390     return this;
       
   391     }
       
   392 
       
   393 // ---------------------------------------------------------------------------
       
   394 // CVPbkFindView::CreateFilteredViewLC
       
   395 // ---------------------------------------------------------------------------
       
   396 //    
       
   397 MVPbkContactViewBase* CVPbkFindView::CreateFilteredViewLC( 
       
   398         MVPbkContactViewObserver& aObserver,
       
   399         const MDesCArray& aFindWords,
       
   400         const MVPbkContactBookmarkCollection* aAlwaysIncludedContacts )
       
   401     {
       
   402     VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
       
   403         ("CVPbkFindView::CreateFilteredViewLC(0x%x)"), this);
       
   404         
       
   405     return CVPbkFindView::NewLC( *this, 
       
   406                                  aObserver, 
       
   407                                  aFindWords, 
       
   408                                  aAlwaysIncludedContacts,
       
   409                                  *iMasterFieldTypeList );    
       
   410     }
       
   411 
       
   412 // ---------------------------------------------------------------------------
       
   413 // CVPbkFindView::UpdateFilterL
       
   414 // ---------------------------------------------------------------------------
       
   415 //     
       
   416 void CVPbkFindView::UpdateFilterL( 
       
   417         const MDesCArray& aFindWords,
       
   418         const MVPbkContactBookmarkCollection* aAlwaysIncludedContacts )
       
   419     {
       
   420     VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
       
   421         ("CVPbkFindView::UpdateFilterL(0x%x)"), this);
       
   422         
       
   423     SetFindStringsL( aFindWords );
       
   424     SetAlwaysIncludedContactsL( aAlwaysIncludedContacts );
       
   425     
       
   426     // Remove first if this called second time when updating.
       
   427     iBaseView.RemoveObserver( *this );
       
   428     // This will cause an asynchrnous view event to this view from the
       
   429     // parent view.
       
   430     iBaseView.AddObserverL( *this );
       
   431     }
       
   432     
       
   433 // ---------------------------------------------------------------------------
       
   434 // CVPbkFindView::BuildViewMappingL
       
   435 // ---------------------------------------------------------------------------
       
   436 //         
       
   437 void CVPbkFindView::BuildViewMappingL()
       
   438     {
       
   439     VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
       
   440         ("CVPbkFindView::BuildViewMappingL(0x%x)"), this);
       
   441 
       
   442     iContactMapping.Reset();
       
   443 
       
   444     // Append always included contact
       
   445     if ( iAlwaysIncludedContacts )
       
   446         {
       
   447         const TInt alwaysIncluded( iAlwaysIncludedContacts->Count() );
       
   448         for ( TInt i(0); i < alwaysIncluded; ++i )
       
   449             {
       
   450             TInt index( 
       
   451                 iBaseView.IndexOfBookmarkL( 
       
   452                     iAlwaysIncludedContacts->At( i ) ) );
       
   453             if ( index > KErrNotFound )
       
   454                 {
       
   455                 User::LeaveIfError( iContactMapping.InsertInOrder(index) );
       
   456                 }        
       
   457             }    
       
   458         }
       
   459     
       
   460     // Append matched contacts    
       
   461     const TInt countContacts = iBaseView.ContactCountL();
       
   462     for (TInt i(0); i < countContacts; ++i)
       
   463         {
       
   464         const MVPbkViewContact& contact = iBaseView.ContactAtL( i );
       
   465         
       
   466         TBool match( ETrue );
       
   467         const TInt countStrings( iFindStrings->MdcaCount() );
       
   468         for ( TInt j(0); j < countStrings; ++j )
       
   469             {
       
   470             if ( !ContactMatchRefineL( contact, iFindStrings->MdcaPoint( j ) ) )
       
   471                 {                
       
   472                 match = EFalse;                
       
   473                 }            
       
   474             }                
       
   475 
       
   476         if ( match && iContactMapping.FindInOrder( i ) == KErrNotFound ) 
       
   477             {                    
       
   478             User::LeaveIfError( iContactMapping.InsertInOrder( i ) );
       
   479             }            
       
   480         }
       
   481 
       
   482     VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
       
   483         ("CVPbkFindView::BuildViewMappingL(0x%x) end"), this);
       
   484     }
       
   485 
       
   486 // ---------------------------------------------------------------------------
       
   487 // CVPbkFindView::HandleBuildViewMapping
       
   488 // ---------------------------------------------------------------------------
       
   489 //         
       
   490 void CVPbkFindView::HandleBuildViewMapping()
       
   491     {
       
   492     TRAPD( res, BuildViewMappingL() );
       
   493     if ( res == KErrNone )
       
   494         {
       
   495         // Mapping was succesfully built. Send ready event
       
   496         SendViewEventToObservers( 
       
   497             &MVPbkContactViewObserver::ContactViewReady );
       
   498         }
       
   499     else
       
   500         {
       
   501         // Building the mapping failed. Leave mappings as they are and
       
   502         // send error
       
   503         SendViewErrorEventToObservers( res, EFalse );
       
   504         }
       
   505     }
       
   506     
       
   507 // ---------------------------------------------------------------------------
       
   508 // From class MVPbkContactViewBase.
       
   509 // CVPbkFindView::ContactViewReady
       
   510 // ---------------------------------------------------------------------------
       
   511 //         
       
   512 void CVPbkFindView::ContactViewReady( MVPbkContactViewBase& aView )
       
   513     {
       
   514     VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
       
   515         ("CVPbkFindView::ContactViewReady(0x%x)"), &aView);
       
   516 
       
   517     iIsReady = ETrue;
       
   518     HandleBuildViewMapping();
       
   519     
       
   520     VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
       
   521         ("CVPbkFindView::ContactViewReady(0x%x) end"), &aView);
       
   522     }
       
   523 
       
   524 // ---------------------------------------------------------------------------
       
   525 // From class MVPbkContactViewBase.
       
   526 // CVPbkFindView::ContactViewUnavailable
       
   527 // ---------------------------------------------------------------------------
       
   528 //         
       
   529 void CVPbkFindView::ContactViewUnavailable( 
       
   530         MVPbkContactViewBase& aView )
       
   531     {
       
   532     VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
       
   533         ("CVPbkFindView::ContactViewUnavailable(0x%x)"), &aView);
       
   534 
       
   535     iIsReady = EFalse;
       
   536     SendViewEventToObservers(
       
   537         &MVPbkContactViewObserver::ContactViewUnavailable );
       
   538 
       
   539     VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
       
   540         ("CVPbkFindView::ContactViewUnavailable(0x%x)"), &aView);
       
   541     }
       
   542 
       
   543 // ---------------------------------------------------------------------------
       
   544 // From class MVPbkContactViewBase.
       
   545 // CVPbkFindView::ContactViewError
       
   546 // ---------------------------------------------------------------------------
       
   547 //         
       
   548 void CVPbkFindView::ContactViewError( MVPbkContactViewBase& aView, 
       
   549         TInt aError, TBool aErrorNotified )
       
   550     {
       
   551     VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
       
   552         ("CVPbkFindView::ContactViewError(0x%x)"), &aView);
       
   553 
       
   554     iIsReady = EFalse;
       
   555     SendViewErrorEventToObservers( aError, aErrorNotified );
       
   556 
       
   557     VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
       
   558         ("CVPbkFindView::ContactViewError(0x%x)"), &aView);
       
   559     }
       
   560 
       
   561 // ---------------------------------------------------------------------------
       
   562 // From class MVPbkContactViewBase.
       
   563 // CVPbkFindView::ContactAddedToView
       
   564 // ---------------------------------------------------------------------------
       
   565 //         
       
   566 void CVPbkFindView::ContactAddedToView
       
   567         (MVPbkContactViewBase& /*aView*/, TInt aIndex,
       
   568         const MVPbkContactLink& aContactLink)
       
   569     {
       
   570     // To keep indexes in iContactMapping up to date rebuild mappings.
       
   571     TRAPD( res, BuildViewMappingL() );
       
   572     if ( res == KErrNone )
       
   573         {
       
   574         // Do a binary search to mapping
       
   575         TInt index = iContactMapping.FindInOrder( aIndex );
       
   576         if ( index != KErrNotFound )
       
   577             {
       
   578             // Mapping was succesfully updated and the new contact
       
   579             // belongs to filter.
       
   580             SendEventToObservers( *this, iObservers,
       
   581                 &MVPbkContactViewObserver::ContactAddedToView, index, 
       
   582                 aContactLink );
       
   583             }
       
   584         }
       
   585     else
       
   586         {
       
   587         SendViewErrorEventToObservers( res, EFalse );
       
   588         }
       
   589     }
       
   590 
       
   591 // ---------------------------------------------------------------------------
       
   592 // From class MVPbkContactViewBase.
       
   593 // CVPbkFindView::ContactRemovedFromView
       
   594 // ---------------------------------------------------------------------------
       
   595 //         
       
   596 void CVPbkFindView::ContactRemovedFromView(
       
   597         MVPbkContactViewBase& /*aView*/, TInt aIndex, 
       
   598         const MVPbkContactLink& aContactLink)
       
   599     {
       
   600     // Do a binary search to mapping
       
   601     TInt index = iContactMapping.FindInOrder( aIndex );
       
   602     
       
   603     // To keep indexes in iContactMapping up to date rebuild mappings.
       
   604     TRAPD( res, BuildViewMappingL() );
       
   605     if ( res == KErrNone )
       
   606         {
       
   607         if ( index != KErrNotFound )
       
   608             {
       
   609             // Mapping was succesfully updated and the new contact
       
   610             // belongs to filter.
       
   611             SendEventToObservers( *this, iObservers,
       
   612                 &MVPbkContactViewObserver::ContactRemovedFromView, index, 
       
   613                 aContactLink );
       
   614             }
       
   615         }
       
   616     else
       
   617         {
       
   618         SendViewErrorEventToObservers( res, EFalse );
       
   619         }
       
   620     }
       
   621     
       
   622 // --------------------------------------------------------------------------
       
   623 // CVPbkFindView::ContactMatchRefineL
       
   624 // --------------------------------------------------------------------------
       
   625 //    
       
   626 TBool CVPbkFindView::ContactMatchRefineL(         
       
   627         const MVPbkViewContact& aViewContact,
       
   628         TPtrC aFindWord )
       
   629     {
       
   630     TBool match( EFalse );
       
   631     iFieldTypeRefsList->Reset(); 
       
   632     
       
   633     // Create iterator                        
       
   634     MVPbkBaseContactFieldIterator* iterator = 
       
   635         iNameConstructionPolicy->NameConstructionFieldsLC( 
       
   636             aViewContact.Fields(),
       
   637             *iFieldTypeRefsList );                            
       
   638              
       
   639     // Loop iterator
       
   640     while ( iterator->HasNext() )
       
   641         {                    
       
   642         const MVPbkBaseContactField* field = iterator->Next();
       
   643         
       
   644         // Check field's type
       
   645         if ( field->FieldData().DataType() == EVPbkFieldStorageTypeText )
       
   646             {                    
       
   647             const MVPbkContactFieldTextData& data = 
       
   648                 MVPbkContactFieldTextData::Cast( field->FieldData() );
       
   649                 
       
   650             // Match refine
       
   651             if ( iContactFindPolicy->MatchRefineL( data.Text(), aFindWord ) )
       
   652                 {
       
   653                 match = ETrue;
       
   654                 break;
       
   655                 }                
       
   656             }
       
   657         }           
       
   658     CleanupStack::PopAndDestroy( 1 ); //iterator    
       
   659     
       
   660     return match;    
       
   661     }    
       
   662 
       
   663 // --------------------------------------------------------------------------
       
   664 // CVPbkFindView::SetFindStringsL
       
   665 // --------------------------------------------------------------------------
       
   666 // 
       
   667 void CVPbkFindView::SetFindStringsL( const MDesCArray& aFindWords )
       
   668     {
       
   669     iFindStrings->Reset();
       
   670     
       
   671     const TInt count( aFindWords.MdcaCount() );
       
   672     for ( TInt i(0); i < count; ++i )
       
   673         {
       
   674         iFindStrings->AppendL( aFindWords.MdcaPoint( i ) );
       
   675         }
       
   676     }
       
   677 
       
   678 // --------------------------------------------------------------------------
       
   679 // CVPbkFindView::SetAlwaysIncludedContactsL
       
   680 // --------------------------------------------------------------------------
       
   681 // 
       
   682 void CVPbkFindView::SetAlwaysIncludedContactsL( 
       
   683         const MVPbkContactBookmarkCollection* aAlwaysIncludedContacts )
       
   684     {
       
   685     iAlwaysIncludedContacts = aAlwaysIncludedContacts;
       
   686     }
       
   687 
       
   688 // --------------------------------------------------------------------------
       
   689 // CVPbkFindView::SendViewEventToObservers
       
   690 // --------------------------------------------------------------------------
       
   691 // 
       
   692 void CVPbkFindView::SendViewEventToObservers( 
       
   693     void( MVPbkContactViewObserver::* aObserverFunc)( MVPbkContactViewBase& ) )
       
   694     {
       
   695     // Cancel async operation to avoid duplicate event sending to observers
       
   696     iAsyncOperation->Purge();
       
   697     SendEventToObservers( *this, iObservers, aObserverFunc );
       
   698     }
       
   699 
       
   700 // --------------------------------------------------------------------------
       
   701 // CVPbkFindView::SendViewErrorEventToObservers
       
   702 // --------------------------------------------------------------------------
       
   703 // 
       
   704 void CVPbkFindView::SendViewErrorEventToObservers( TInt aError, TBool 
       
   705         aErrorNotified )
       
   706     {
       
   707     // Cancel async operation to avoid duplicate event sending to observers
       
   708     iAsyncOperation->Purge();
       
   709     SendEventToObservers( *this, iObservers,
       
   710         &MVPbkContactViewObserver::ContactViewError, 
       
   711         aError, aErrorNotified );
       
   712     }
       
   713 // End of File