--- a/phoneengine/PhoneCntFinder/ContactService/src/cphcntcontactmatchstrategy.cpp Wed Sep 15 12:12:21 2010 +0300
+++ b/phoneengine/PhoneCntFinder/ContactService/src/cphcntcontactmatchstrategy.cpp Wed Oct 13 14:31:22 2010 +0300
@@ -17,16 +17,15 @@
#include <CVPbkContactManager.h>
+#include <centralrepository.h>
+#include <telconfigcrkeys.h>
#include <CVPbkContactStoreUriArray.h>
-#include <cntdb.h> // KBestMatchingPhoneNumbers
#include "cphcntcontactmatchstrategy.h"
#include "cphcntcontactstoreuris.h"
#include "CPhoneRawMatchNumberExtractor.h"
-
-
// ======== MEMBER FUNCTIONS ========
@@ -34,11 +33,11 @@
CVPbkContactManager& aContactManager,
CPhCntContactStoreUris& aContactStoreUris,
MVPbkContactFindObserver& aObserver,
- TUint32 aMatchFlags ) :
+ MPhCntContactManager::TDuplicateRemovalStrategy aRemoveDuplicatesStrategy ) :
iContactManager( aContactManager ),
iContactStoreUris( aContactStoreUris ),
iObserver( aObserver ),
- iMatchFlags( aMatchFlags )
+ iRemoveDuplicatesStrategy( aRemoveDuplicatesStrategy )
{
iContactStoreUris.SetObserver( *this );
}
@@ -49,13 +48,42 @@
// ---------------------------------------------------------------------------
//
void CPhCntContactMatchStrategy::ConstructL()
- {
+ {
+ iNumberOfDigits = KPhCntMatchDefault;
+
+ TInt matchDigitsValue = ReadMatchDigitsValueL();
+
+ // If we can find a proper value from the cenrep, use it.
+ if ( matchDigitsValue >= KPhCntMatchMin && matchDigitsValue <= KPhCntMatchMax )
+ {
+ iNumberOfDigits = matchDigitsValue;
+ }
+ else if ( matchDigitsValue == KBestMatchingPhoneNumbers )
+ {
+ iNumberOfDigits = matchDigitsValue;
+ }
+
User::LeaveIfError( CreateContactMatchStrategy() );
iNumberExtractor = new( ELeave )CCntRawPhoneNumberExtractor();
iNumberExtractor->ConstructL();
}
+// ---------------------------------------------------------------------------
+//
+// ---------------------------------------------------------------------------
+//
+TInt CPhCntContactMatchStrategy::ReadMatchDigitsValueL()
+ {
+ CRepository* cenRepSession = CRepository::NewL( KCRUidTelConfiguration );
+
+ TInt matchDigitsValue (KErrNotFound);
+ // Find digit count to be used with matching.
+ cenRepSession->Get( KTelMatchDigits, matchDigitsValue );
+
+ delete cenRepSession;
+ return matchDigitsValue;
+ }
// ---------------------------------------------------------------------------
// Static constructor.
@@ -65,14 +93,14 @@
CVPbkContactManager& aContactManager,
CPhCntContactStoreUris& aContactStoreUris,
MVPbkContactFindObserver& aObserver,
- TUint32 aMatchFlags )
+ MPhCntContactManager::TDuplicateRemovalStrategy aRemoveDuplicatesStrategy )
{
CPhCntContactMatchStrategy* self =
new( ELeave ) CPhCntContactMatchStrategy(
aContactManager,
aContactStoreUris,
aObserver,
- aMatchFlags );
+ aRemoveDuplicatesStrategy );
CleanupStack::PushL( self );
self->ConstructL();
CleanupStack::Pop( self );
@@ -89,6 +117,7 @@
{
iNumberExtractor->Release();
}
+
delete iMatchStrategy;
delete iUriArray;
}
@@ -145,6 +174,7 @@
return err;
}
+
// ---------------------------------------------------------------------------
// From base class MPhCntContactStoreEventObserver
// Updates match strategy.
@@ -162,13 +192,16 @@
// ---------------------------------------------------------------------------
//
TInt CPhCntContactMatchStrategy::DoCreateMatchStrategy()
- {
+ {
+ TUint32 flags = FillMatchFlags();
+
CVPbkPhoneNumberMatchStrategy::TConfig config(
- KBestMatchingPhoneNumbers,
- *iUriArray,
- CVPbkPhoneNumberMatchStrategy::EVPbkSequentialMatch,
- iMatchFlags
- );
+ iNumberOfDigits,
+ *iUriArray,
+ CVPbkPhoneNumberMatchStrategy::EVPbkSequentialMatch,
+ flags
+ );
+
TRAPD( err, iMatchStrategy = CVPbkPhoneNumberMatchStrategy::NewL(
config,
iContactManager,
@@ -177,11 +210,68 @@
}
// ---------------------------------------------------------------------------
+//
+// ---------------------------------------------------------------------------
+//
+TUint32 CPhCntContactMatchStrategy::FillMatchFlags() const
+ {
+ TUint32 flags = CVPbkPhoneNumberMatchStrategy::EVPbkMatchFlagsNone;
+
+ if ( iRemoveDuplicatesStrategy == MPhCntContactManager::ERemoveDuplicates )
+ {
+ flags |= CVPbkPhoneNumberMatchStrategy::EVPbkDuplicatedContactsMatchFlag;
+ }
+
+ if ( iNumberOfDigits == KBestMatchingPhoneNumbers )
+ {
+ flags |= CVPbkPhoneNumberMatchStrategy::EVPbkBestMatchingFlag;
+ }
+
+ return flags;
+ }
+
+
+// ---------------------------------------------------------------------------
// Makes the actual matching request.
// ---------------------------------------------------------------------------
//
void CPhCntContactMatchStrategy::DoMatchL(
const TDesC& aNumber )
{
- iMatchStrategy->MatchL( aNumber );
+
+ //extra characters should not be removed when using BestMatching algorithm
+ if ( iNumberOfDigits == KBestMatchingPhoneNumbers )
+ {
+ iMatchStrategy->MatchL( aNumber );
+ }
+ else
+ {
+ TDesC* rawNumber = RemoveExtraCharactersLC( aNumber );
+ iMatchStrategy->MatchL( *rawNumber );
+ CleanupStack::PopAndDestroy( rawNumber );
+ }
}
+
+// ---------------------------------------------------------------------------
+// Removes postfix from aNumber
+// ---------------------------------------------------------------------------
+//
+TDesC* CPhCntContactMatchStrategy::RemoveExtraCharactersLC( const TDesC& aNumber )
+ {
+ HBufC* rawNumber = HBufC::NewLC( aNumber.Length() );
+ TPtr rawNumberPtr = rawNumber->Des();
+ iNumberExtractor->ExtractRawNumber( aNumber, rawNumberPtr );
+ return rawNumber;
+ }
+
+// ---------------------------------------------------------------------------
+// Enables to inject match strategy to ease unit testing
+// ---------------------------------------------------------------------------
+//
+void CPhCntContactMatchStrategy::SetVPbkPhoneNumberMatchStrategy(
+ CVPbkPhoneNumberMatchStrategy* aMatchStrategy )
+ {
+ delete iMatchStrategy;
+ iMatchStrategy = aMatchStrategy;
+ }
+