qtmobility/plugins/contacts/symbian/src/filtering/cntsymbianfilterdbms.cpp
changeset 8 71781823f776
parent 4 90517678cc4f
child 11 06b8e2af4411
--- a/qtmobility/plugins/contacts/symbian/src/filtering/cntsymbianfilterdbms.cpp	Fri May 14 16:41:33 2010 +0300
+++ b/qtmobility/plugins/contacts/symbian/src/filtering/cntsymbianfilterdbms.cpp	Thu May 27 13:42:11 2010 +0300
@@ -327,7 +327,17 @@
             TRAP_IGNORE(getMatchLengthL(matchLength));
 
             TInt err = matchContacts(idArray, commPtr, matchLength);
-            if(err != KErrNone) {
+            if (err == KErrNone) {
+                // Phone number matching sometimes includes nonexisting contacts to
+                // the result for some reason. Remove them.
+                for (TInt i(0); i < idArray->Count(); ) {
+                    if(!contactExists((*idArray)[i])) {
+                        idArray->Remove(i);
+                    } else {
+                        i++;
+                    }
+                }
+            } else {
                 CntSymbianTransformError::transformError(err, error);
             }
         // Names, e-mail, display label (other flags)
@@ -413,6 +423,12 @@
     return value;
 }
 
+bool CntSymbianFilter::contactExists(const TContactItemId &contactId)
+{
+    TRAPD(err, m_contactDatabase.ReadMinimalContactL(contactId));
+    return err == KErrNone;
+}
+
 /*!
  * Transform detail filter into a contact item field definition that can be
  * used with CContactDatabase finds.