phonebookengines/VirtualPhonebook/VPbkCntModel/src/CFindView.cpp
branchRCL_3
changeset 32 2828b4d142c0
parent 0 e686773b3f54
child 64 c1e8ba0c2b16
equal deleted inserted replaced
26:0d28c1c5b6dd 32:2828b4d142c0
   128 // --------------------------------------------------------------------------
   128 // --------------------------------------------------------------------------
   129 //
   129 //
   130 void CFindView::MatchL(
   130 void CFindView::MatchL(
   131         RPointerArray<CCntModelViewContact>& aMatchedContacts )
   131         RPointerArray<CCntModelViewContact>& aMatchedContacts )
   132     {
   132     {
       
   133     CleanupClosePushL( aMatchedContacts );
   133     iContactsModelMatchContacts.ResetAndDestroy();
   134     iContactsModelMatchContacts.ResetAndDestroy();
   134 
   135 
   135     VPBK_PROFILE_START(VPbkProfile::ECntModelFind);
   136     VPBK_PROFILE_START(VPbkProfile::ECntModelFind);
   136     // Get matches from Contacts Model
   137     // Get matches from Contacts Model
   137     iBaseView.NativeView().ContactsMatchingPrefixL(
   138     iBaseView.NativeView().ContactsMatchingPrefixL(
   161             }
   162             }
   162         CleanupStack::PopAndDestroy( viewContact );
   163         CleanupStack::PopAndDestroy( viewContact );
   163         }
   164         }
   164     else
   165     else
   165         {
   166         {
       
   167         // Sort the matched contacts again with the CCompareView::CompareFieldsL
       
   168         // compare function. Mark sure the result of binary search is correct in
       
   169         // function FindFromMatchArray().
       
   170         // See defect ou1cimx1#333760 
       
   171         // Title: "Adding contacts (add recipent) issue while creating new message"
       
   172         // Root cause: When contact's first or last name contain blank spaces, 
       
   173         // the comparison result may be different between CCompareView::CompareFieldsL
       
   174         // and CntSortPlugin. e.g. "AB" and "A khan"
       
   175         HeapSortL( iContactsModelMatchContacts );
       
   176 		
   166         // Do it slowly by looping all the parent view contacts.
   177         // Do it slowly by looping all the parent view contacts.
   167         const TInt contactCount = iParentView.ContactCountL();
   178         const TInt contactCount = iParentView.ContactCountL();
   168         for ( TInt i = 0; i < contactCount; ++i )
   179         for ( TInt i = 0; i < contactCount; ++i )
   169             {
   180             {
   170             // iParentView is always VPbkCntModel view and the contacts type
   181             // iParentView is always VPbkCntModel view and the contacts type
   174             MatchContactL( candidate, aMatchedContacts );
   185             MatchContactL( candidate, aMatchedContacts );
   175             }
   186             }
   176         }
   187         }
   177 
   188 
   178     iContactsModelMatchContacts.ResetAndDestroy();
   189     iContactsModelMatchContacts.ResetAndDestroy();
       
   190     CleanupStack::Pop();
   179     }
   191     }
   180 
   192 
   181 // --------------------------------------------------------------------------
   193 // --------------------------------------------------------------------------
   182 // CFindView::DoContactAddedToViewL
   194 // CFindView::DoContactAddedToViewL
   183 // --------------------------------------------------------------------------
   195 // --------------------------------------------------------------------------
   221 // --------------------------------------------------------------------------
   233 // --------------------------------------------------------------------------
   222 //
   234 //
   223 void CFindView::MatchContactL( const CViewContact& aViewContact,
   235 void CFindView::MatchContactL( const CViewContact& aViewContact,
   224         RPointerArray<CCntModelViewContact>& aMatchedContacts )
   236         RPointerArray<CCntModelViewContact>& aMatchedContacts )
   225     {
   237     {
       
   238     CleanupResetAndDestroyPushL( aMatchedContacts );
   226     // aContact matches if it's one of the always included contacts OR
   239     // aContact matches if it's one of the always included contacts OR
   227     // if it's one of Contacts Model matched contacts AND it also
   240     // if it's one of Contacts Model matched contacts AND it also
   228     // passes our own match.
   241     // passes our own match.
   229     TInt matchArrayIndex = KErrNotFound;
   242     TInt matchArrayIndex = KErrNotFound;
   230     TBool matched = EFalse;
   243     TBool matched = EFalse;
   254             CCntModelViewContact::NewL( *aViewContact.NativeContact() );
   267             CCntModelViewContact::NewL( *aViewContact.NativeContact() );
   255         CleanupStack::PushL( cnt );
   268         CleanupStack::PushL( cnt );
   256         aMatchedContacts.AppendL( cnt );
   269         aMatchedContacts.AppendL( cnt );
   257         CleanupStack::Pop( cnt );
   270         CleanupStack::Pop( cnt );
   258         }
   271         }
       
   272     CleanupStack::Pop( &aMatchedContacts );
   259     }
   273     }
   260 
   274 
   261 // --------------------------------------------------------------------------
   275 // --------------------------------------------------------------------------
   262 // CFindView::IsContactAlwaysIncluded
   276 // CFindView::IsContactAlwaysIncluded
   263 // --------------------------------------------------------------------------
   277 // --------------------------------------------------------------------------
   303     {
   317     {
   304     return iContactsModelMatchContacts.FindInOrder(
   318     return iContactsModelMatchContacts.FindInOrder(
   305         aContact.NativeContact(),
   319         aContact.NativeContact(),
   306         TLinearOrder<CCntModelViewContact>( CCompareView::CompareFieldsL ) );
   320         TLinearOrder<CCntModelViewContact>( CCompareView::CompareFieldsL ) );
   307     }
   321     }
       
   322 
       
   323 /** 
       
   324 Heap sort the give view contacts array.
       
   325 
       
   326 This function only be called one time when some contacts be marked and we input
       
   327 the first letter to the FindBox for searching.
       
   328 
       
   329 @param  aContacts the array of view contacts to be sorted.
       
   330 @leave  leave errors from CCompareView::CompareFieldsL
       
   331 */
       
   332 void CFindView::HeapSortL(RPointerArray<CCntModelViewContact> aContacts)
       
   333     {
       
   334     // HeapSort (copied from RPointerArrayBase)
       
   335     TInt ss = aContacts.Count();
       
   336     if ( ss>1 )
       
   337         {
       
   338         TInt sh = ss>>1;
       
   339         FOREVER
       
   340             {
       
   341             CCntModelViewContact* si;
       
   342             if (sh != 0)
       
   343                 {
       
   344                 // make heap
       
   345                 --sh;
       
   346                 si = aContacts[sh];
       
   347                 }
       
   348             else
       
   349                 {
       
   350                 // sort heap
       
   351                 --ss;
       
   352                 si = aContacts[ss];
       
   353                 aContacts[ss] = aContacts[0];
       
   354                 if (ss == 1)
       
   355                     {
       
   356                     aContacts[0] = si;
       
   357                     break;
       
   358                     }
       
   359                 }
       
   360 
       
   361             // sift down
       
   362             TInt ii = sh;
       
   363             TInt jj = sh;
       
   364             FOREVER
       
   365                 {
       
   366                 jj = (jj+1)<<1;
       
   367                 if ((jj >= ss) || (CCompareView::CompareFieldsL(*(aContacts[jj-1]),*(aContacts[jj])) > 0))
       
   368                     {
       
   369                     --jj;
       
   370                     }
       
   371 					
       
   372                 if ((jj >= ss) || (CCompareView::CompareFieldsL(*(aContacts[jj]),*si) <= 0))
       
   373                     {
       
   374                     break;
       
   375                     }
       
   376 					
       
   377                 aContacts[ii] = aContacts[jj];
       
   378                 ii = jj;
       
   379                 } //FOREVER
       
   380 				
       
   381             aContacts[ii] = si;
       
   382             } //FOREVER
       
   383         } //if (ss > 1)
       
   384     }
   308 } // namespace VPbkCntModel
   385 } // namespace VPbkCntModel
   309 // End of File
   386 // End of File