12 * Contributors: |
12 * Contributors: |
13 * |
13 * |
14 * Description: Filtered contact view |
14 * Description: Filtered contact view |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 #include <eikenv.h> |
18 |
|
19 #include "CVPbkFindView.h" |
18 #include "CVPbkFindView.h" |
20 #include <MVPbkFieldType.h> |
19 #include <MVPbkFieldType.h> |
21 #include <CVPbkSortOrder.h> |
20 #include <CVPbkSortOrder.h> |
22 #include <CVPbkAsyncCallback.h> |
21 #include <CVPbkAsyncCallback.h> |
23 #include <MVPbkViewContact.h> |
22 #include <MVPbkViewContact.h> |
24 #include <CVPbkAsyncOperation.h> |
23 #include <CVPbkAsyncOperation.h> |
25 #include <VPbkError.h> |
24 #include <VPbkError.h> |
26 |
25 |
27 #include <CVPbkFieldTypeRefsList.h> |
|
28 #include <CVPbkContactNameConstructionPolicy.h> |
|
29 #include <CVPbkContactFindPolicy.h> |
26 #include <CVPbkContactFindPolicy.h> |
30 #include <MVPbkContactBookmarkCollection.h> |
27 #include <MVPbkContactBookmarkCollection.h> |
31 #include <CVPbkContactFieldIterator.h> |
28 #include <CVPbkContactFieldIterator.h> |
32 #include <MVPbkContactFieldData.h> |
29 #include <MVPbkContactFieldData.h> |
33 #include <MVPbkContactFieldTextData.h> |
30 #include <MVPbkContactFieldTextData.h> |
|
31 |
34 |
32 |
35 #include <VPbkDebug.h> |
33 #include <VPbkDebug.h> |
36 |
34 |
37 namespace { |
35 namespace { |
38 const TInt KObserverArrayGranularity( 4 ); |
36 const TInt KObserverArrayGranularity( 4 ); |
106 iFindStrings = new(ELeave)CDesCArrayFlat( KGranularity ); |
104 iFindStrings = new(ELeave)CDesCArrayFlat( KGranularity ); |
107 SetFindStringsL( aFindWords ); |
105 SetFindStringsL( aFindWords ); |
108 |
106 |
109 SetAlwaysIncludedContactsL( aAlwaysIncludedContacts ); |
107 SetAlwaysIncludedContactsL( aAlwaysIncludedContacts ); |
110 |
108 |
111 // Create contact find policy |
109 |
112 iContactFindPolicy = CVPbkContactFindPolicy::NewL(); |
110 CEikonEnv* eikonEnv = CEikonEnv::Static(); |
113 |
111 |
114 CVPbkContactNameConstructionPolicy::TParam param( *iMasterFieldTypeList ); |
112 if ( eikonEnv ) |
115 iNameConstructionPolicy = |
113 { |
116 CVPbkContactNameConstructionPolicy::NewL( param ); |
114 CVPbkContactFindPolicy::TParam param = |
117 |
115 CVPbkContactFindPolicy::TParam( |
118 //Create field type list |
116 *iMasterFieldTypeList, |
119 iFieldTypeRefsList = CVPbkFieldTypeRefsList::NewL(); |
117 eikonEnv->FsSession() ); |
120 |
118 |
|
119 // Create contact find policy |
|
120 iContactFindPolicy = CVPbkContactFindPolicy::NewL( param ); |
|
121 } |
|
122 |
121 iBaseView.AddObserverL(*this); |
123 iBaseView.AddObserverL(*this); |
122 |
124 |
123 VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING |
125 VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING |
124 ("CVPbkFindView::ConstructL(0x%x) end"), this); |
126 ("CVPbkFindView::ConstructL(0x%x) end"), this); |
125 } |
127 } |
152 { |
154 { |
153 iContactMapping.Reset(); |
155 iContactMapping.Reset(); |
154 iBaseView.RemoveObserver(*this); |
156 iBaseView.RemoveObserver(*this); |
155 iObservers.Close(); |
157 iObservers.Close(); |
156 delete iFindStrings; |
158 delete iFindStrings; |
157 delete iFieldTypeRefsList; |
|
158 delete iNameConstructionPolicy; |
|
159 delete iContactFindPolicy; |
159 delete iContactFindPolicy; |
160 delete iAsyncOperation; |
160 delete iAsyncOperation; |
161 } |
161 } |
162 |
162 |
163 // --------------------------------------------------------------------------- |
163 // --------------------------------------------------------------------------- |
462 for (TInt i(0); i < countContacts; ++i) |
462 for (TInt i(0); i < countContacts; ++i) |
463 { |
463 { |
464 const MVPbkViewContact& contact = iBaseView.ContactAtL( i ); |
464 const MVPbkViewContact& contact = iBaseView.ContactAtL( i ); |
465 |
465 |
466 TBool match( ETrue ); |
466 TBool match( ETrue ); |
467 const TInt countStrings( iFindStrings->MdcaCount() ); |
467 |
468 for ( TInt j(0); j < countStrings; ++j ) |
468 if ( iContactFindPolicy && |
|
469 !iContactFindPolicy->MatchContactNameL( *iFindStrings, contact )) |
469 { |
470 { |
470 if ( !ContactMatchRefineL( contact, iFindStrings->MdcaPoint( j ) ) ) |
471 match = EFalse; |
471 { |
472 } |
472 match = EFalse; |
|
473 } |
|
474 } |
|
475 |
473 |
476 if ( match && iContactMapping.FindInOrder( i ) == KErrNotFound ) |
474 if ( match && iContactMapping.FindInOrder( i ) == KErrNotFound ) |
477 { |
475 { |
478 User::LeaveIfError( iContactMapping.InsertInOrder( i ) ); |
476 User::LeaveIfError( iContactMapping.InsertInOrder( i ) ); |
479 } |
477 } |
616 else |
614 else |
617 { |
615 { |
618 SendViewErrorEventToObservers( res, EFalse ); |
616 SendViewErrorEventToObservers( res, EFalse ); |
619 } |
617 } |
620 } |
618 } |
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 |
619 |
663 // -------------------------------------------------------------------------- |
620 // -------------------------------------------------------------------------- |
664 // CVPbkFindView::SetFindStringsL |
621 // CVPbkFindView::SetFindStringsL |
665 // -------------------------------------------------------------------------- |
622 // -------------------------------------------------------------------------- |
666 // |
623 // |