pimprotocols/pbap/server/pbapvcardexporterutil.cpp
branchRCL_3
changeset 21 9da50d567e3c
parent 20 f4a778e096c2
--- a/pimprotocols/pbap/server/pbapvcardexporterutil.cpp	Wed Sep 01 12:29:52 2010 +0100
+++ b/pimprotocols/pbap/server/pbapvcardexporterutil.cpp	Tue Sep 14 20:54:53 2010 +0300
@@ -21,6 +21,8 @@
 #include <s32strm.h>
 #include <vprop.h>
 #include <vcard.h>
+#include <centralrepository.h>
+
 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
 #include "vcard3.h"
 #include "cntdb_internal.h"
@@ -29,6 +31,13 @@
 #include "pbaplogeng.h"
 #include "btaccesshostlog.h"
 
+/* These constants are properly defined in telconfigcrkeys.h, however we 
+are not allowed to include that from here.  As a temporary fix the constants 
+from that file are re-defined here. */
+const TUid KCRUidTelConfiguration = {0x102828B8};
+const TUint32 KTelMatchDigits = 0x00000001;
+/* And similarly this constant is defined in ccsdefs.h */
+const TInt KDefaultGsmNumberMatchLength = 7;
 
 //constants
 _LIT8(KVersitTokenCALLDATETIME,"X-IRMC-CALL-DATETIME");
@@ -59,6 +68,23 @@
 	LOG_FUNC
 	CVersitTlsData::VersitTlsDataL();		
 	User::LeaveIfError(iTzClient.Connect());
+	
+	// Read the amount of digits to be used in contact matching
+	// The key is properly owned by PhoneApp, however we cannot include
+	// that header file from here, so a temporary fix has been done to 
+	// use locally defined versions.  If there is a problem here it is 
+	// likely because these values have gone out of sync.
+	CRepository* repository = CRepository::NewLC(KCRUidTelConfiguration);
+    if ( repository->Get(KTelMatchDigits, iMatchDigitCount) == KErrNone )
+        {
+        // Min is 7
+        iMatchDigitCount = Max(iMatchDigitCount, KDefaultGsmNumberMatchLength);
+        }
+    else
+        {
+        iMatchDigitCount = KDefaultGsmNumberMatchLength;
+        }
+	CleanupStack::PopAndDestroy(repository);
 	}
 
 CPbapVCardExporterUtil::~CPbapVCardExporterUtil()
@@ -161,16 +187,12 @@
 TContactItemId CPbapVCardExporterUtil::FindContactIdFromNumberL(const TDesC& aNumber)
 	{
 	TContactItemId ret = KNullContactId;
-	CContactItemFieldDef* fieldDef;
-	fieldDef = new(ELeave) CContactItemFieldDef;
-	CleanupStack::PushL(fieldDef);
-	fieldDef->AppendL(KUidContactFieldPhoneNumber);
-	CContactIdArray* contactIdArray = iDatabase.FindLC(aNumber, fieldDef);
+	CContactIdArray* contactIdArray = iDatabase.MatchPhoneNumberL(aNumber, iMatchDigitCount);
 	if (contactIdArray->Count() > 0)
 		{
 		ret = (*contactIdArray)[0];
 		}
-	CleanupStack::PopAndDestroy(2); // contactIdArray, fieldDef
+	delete contactIdArray;
 	return ret;
 	}