phoneengine/PhoneCntFinder/ContactService/src/CPhCntMatcherImpl.cpp
branchRCL_3
changeset 81 c26cc2a7c548
parent 62 5266b1f337bd
--- a/phoneengine/PhoneCntFinder/ContactService/src/CPhCntMatcherImpl.cpp	Wed Sep 15 12:12:21 2010 +0300
+++ b/phoneengine/PhoneCntFinder/ContactService/src/CPhCntMatcherImpl.cpp	Wed Oct 13 14:31:22 2010 +0300
@@ -15,16 +15,15 @@
 *
 */
 
+
+
 #include <CVPbkPhoneNumberMatchStrategy.h>
 #include <MVPbkContactLinkArray.h>
 #include <CPbk2StoreConfiguration.h>
 #include <MVPbkContactStoreProperties.h>
 #include <MVPbkContactStore.h>
 #include <CVPbkContactStoreUriArray.h>
-#include <talogger.h>
-#include <telephonyvariant.hrh>
-#include <telinternalcrkeys.h>
-#include <centralrepository.h>
+
 
 #include "CPhCntMatcherImpl.h"
 #include "cphcntmatchcontact.h"
@@ -36,28 +35,8 @@
 #include "MPhoneCntPbkOwner.h"
 #include "cphcntvpbkcontactid.h"
 #include "cphcntcontactmatchstrategy.h"
+#include <talogger.h>
 
-// Local functions
-/**
- * Gets contact selection strategy from localvariation flag.
- */
-TPhCntContactSelectionStrategy::TAllowSeveralMatches 
-    GetContactSelectionStrategyL()
-    {
-    CRepository* repository = CRepository::NewLC( KCRUidTelVariation );
-    TInt variationFlag;
-    User::LeaveIfError( repository->Get( KTelVariationFlags, variationFlag ) );
-    CleanupStack::PopAndDestroy( repository );
-    
-    if( variationFlag & KTelephonyLVFlagShowContactWhenSeveralMatches ) 
-        {
-        return TPhCntContactSelectionStrategy::EAllowSeveralMatches;
-        }
-    else
-        {
-        return TPhCntContactSelectionStrategy::EAllowSingleMatch;
-        }
-    }
 
 
 // ---------------------------------------------------------------------------
@@ -212,8 +191,12 @@
     TEFLOGSTRING( KTAOBJECT, "CNT CPhCntMatcherImpl::GetContactL" );
     // Try to find matching contact.
     const MVPbkContactLinkArray* linkArray = NULL;
-    TInt err = MatchContactL( linkArray, aTelNumber, 
-        MPhCntContactManager::EDontRemoveDuplicates );
+    delete iCSMatchStrategy;
+    iCSMatchStrategy = 0;
+    iCSMatchStrategy = iContactManager.CreateContactMatchStrategyL( *iMatchContact,
+            MPhCntContactManager::EDontRemoveDuplicates ); 
+    TInt err( iMatchContact->MatchContact( linkArray, aTelNumber,
+        *iCSMatchStrategy ) );
 
     CPhCntContact* match( NULL );
     TInt index( KErrNotFound );
@@ -221,22 +204,18 @@
     // Apply exact match on additional stores first.
     // If match is found, don't care about other stores as
     // these come first.
-    if( !err )
-        {        
-        const CVPbkContactStoreUriArray& additionalStores = iContactManager.AdditionalContactStoreUris();
-        index = iContactSelectionStrategy.ApplyAdditonalStoreStrategy( *linkArray, additionalStores );  
-        
-        const TBool manyContactsFound = index == KManyContacts;
-        const TBool singleContactFound = 
-            index != KNoContact && index != KManyContacts;
-        
-        if ( singleContactFound )
+    if(  !err && ( linkArray->Count() > 1 ) )
+        {
+        index = MatchFromAdditionalStore( *linkArray );
+
+        // Single match on additonal stores
+        if ( index != KErrNotFound && index != KErrAlreadyExists )
             {
             FetchContact( match, linkArray->At( index ), aTelNumber );
             aMatch = match;
             return err;
             }
-        else if ( manyContactsFound ) 
+        else if ( index == KErrAlreadyExists ) //Several matches on additional stores
             {
             aMatch = match;
             return KErrNotFound;
@@ -245,46 +224,30 @@
 
     if(  !err && ( linkArray->Count() > 1 ) )
         {
-        err = MatchContactL( linkArray, aTelNumber,
-            MPhCntContactManager::ERemoveDuplicates );
+        delete iCSMatchStrategy;
+        iCSMatchStrategy = 0;
+        iCSMatchStrategy = iContactManager.CreateContactMatchStrategyL(
+            *iMatchContact, MPhCntContactManager::ERemoveDuplicates ); 
+        err = iMatchContact->MatchContact( linkArray, aTelNumber,
+            *iCSMatchStrategy );
         }
     if ( !err )
         {
-        index = iContactSelectionStrategy.ApplyStrategy( *linkArray );        
+        // If only one contact, no additional checks needed
+        if ( linkArray->Count() == 1 )
+            {
+            index = 0;
+            }
         }
 
+
     // Finally fetch contact details
-    if ( index != KNoContact )
+    if ( index != KErrNotFound )
         {
         FetchContact( match, linkArray->At( index ), aTelNumber );
-        aMatch = match;
         }
-    else
-        {
-        err = KErrNotFound;
-        }
-    
-    TEFLOGSTRING2( KTAMESIN,"CNT CPhCntMatcherImpl::GetContactL,err: %d", err );    
-    return err;
-    }
 
-// ---------------------------------------------------------------------------
-// Matches contact
-// ---------------------------------------------------------------------------
-//
-TInt CPhCntMatcherImpl::MatchContactL( 
-    const MVPbkContactLinkArray*& aContactLinkArray, 
-    const TDesC& aTelNumber,
-    MPhCntContactManager::TDuplicateRemovalStrategy aRemoveDuplicatesStrategy )
-    {
-    delete iCSMatchStrategy;
-    iCSMatchStrategy = NULL;
-    iCSMatchStrategy = iContactManager.CreateContactMatchStrategyL( 
-        *iMatchContact,
-        aRemoveDuplicatesStrategy );
-    
-    const TInt err( iMatchContact->MatchContact( aContactLinkArray, aTelNumber,
-        *iCSMatchStrategy ) );
+    aMatch = match;
     return err;
     }
 
@@ -331,9 +294,6 @@
 //
 void CPhCntMatcherImpl::ConstructL()
     {
-    const TPhCntContactSelectionStrategy::TAllowSeveralMatches strategy = 
-        GetContactSelectionStrategyL();
-    iContactSelectionStrategy.SetContactSelectionStrategy( strategy );    
     }
 
 // ---------------------------------------------------------------------------
@@ -363,3 +323,37 @@
     return err;
     }
 
+// --------------------------------------------------------------------------
+// CPhCntMatcherImpl::MatchFromAdditionalStore
+// --------------------------------------------------------------------------
+//
+TInt CPhCntMatcherImpl::MatchFromAdditionalStore(
+    const MVPbkContactLinkArray& linkArray ) const
+    {
+    TEFLOGSTRING( KTAOBJECT, "CNT CPhCntMatcherImpl::MatchFromAdditionalStore" );
+    TInt ret( KErrNotFound );
+    TInt found(0); // count of found contacts from additional stores.
+
+    for ( TInt i = 0; i < linkArray.Count(); i++ )
+        {
+        TVPbkContactStoreUriPtr uri =
+            linkArray.At( i ).ContactStore().StoreProperties().Uri();
+
+        // Compare if contact is from additional store.
+        if ( iContactManager.AdditionalContactStoreUris().IsIncluded( uri ) )
+            {
+            // Contact found from additional store.
+            found++;
+            ret = i;
+            }
+        }
+
+    if ( found > 1)
+        {
+        // Multiple matches from additional stores -> no match.
+        ret = KErrAlreadyExists;
+        }
+
+    return ret;
+    }
+