15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 |
18 |
19 #include <CVPbkContactManager.h> |
19 #include <CVPbkContactManager.h> |
|
20 #include <centralrepository.h> |
|
21 #include <telconfigcrkeys.h> |
20 #include <CVPbkContactStoreUriArray.h> |
22 #include <CVPbkContactStoreUriArray.h> |
21 #include <cntdb.h> // KBestMatchingPhoneNumbers |
|
22 |
23 |
23 #include "cphcntcontactmatchstrategy.h" |
24 #include "cphcntcontactmatchstrategy.h" |
24 #include "cphcntcontactstoreuris.h" |
25 #include "cphcntcontactstoreuris.h" |
25 #include "CPhoneRawMatchNumberExtractor.h" |
26 #include "CPhoneRawMatchNumberExtractor.h" |
26 |
|
27 |
|
28 |
27 |
29 |
28 |
30 // ======== MEMBER FUNCTIONS ======== |
29 // ======== MEMBER FUNCTIONS ======== |
31 |
30 |
32 |
31 |
33 CPhCntContactMatchStrategy::CPhCntContactMatchStrategy( |
32 CPhCntContactMatchStrategy::CPhCntContactMatchStrategy( |
34 CVPbkContactManager& aContactManager, |
33 CVPbkContactManager& aContactManager, |
35 CPhCntContactStoreUris& aContactStoreUris, |
34 CPhCntContactStoreUris& aContactStoreUris, |
36 MVPbkContactFindObserver& aObserver, |
35 MVPbkContactFindObserver& aObserver, |
37 TUint32 aMatchFlags ) : |
36 MPhCntContactManager::TDuplicateRemovalStrategy aRemoveDuplicatesStrategy ) : |
38 iContactManager( aContactManager ), |
37 iContactManager( aContactManager ), |
39 iContactStoreUris( aContactStoreUris ), |
38 iContactStoreUris( aContactStoreUris ), |
40 iObserver( aObserver ), |
39 iObserver( aObserver ), |
41 iMatchFlags( aMatchFlags ) |
40 iRemoveDuplicatesStrategy( aRemoveDuplicatesStrategy ) |
42 { |
41 { |
43 iContactStoreUris.SetObserver( *this ); |
42 iContactStoreUris.SetObserver( *this ); |
44 } |
43 } |
45 |
44 |
46 |
45 |
47 // --------------------------------------------------------------------------- |
46 // --------------------------------------------------------------------------- |
48 // Second phase constructor |
47 // Second phase constructor |
49 // --------------------------------------------------------------------------- |
48 // --------------------------------------------------------------------------- |
50 // |
49 // |
51 void CPhCntContactMatchStrategy::ConstructL() |
50 void CPhCntContactMatchStrategy::ConstructL() |
52 { |
51 { |
|
52 iNumberOfDigits = KPhCntMatchDefault; |
|
53 |
|
54 TInt matchDigitsValue = ReadMatchDigitsValueL(); |
|
55 |
|
56 // If we can find a proper value from the cenrep, use it. |
|
57 if ( matchDigitsValue >= KPhCntMatchMin && matchDigitsValue <= KPhCntMatchMax ) |
|
58 { |
|
59 iNumberOfDigits = matchDigitsValue; |
|
60 } |
|
61 else if ( matchDigitsValue == KBestMatchingPhoneNumbers ) |
|
62 { |
|
63 iNumberOfDigits = matchDigitsValue; |
|
64 } |
|
65 |
53 User::LeaveIfError( CreateContactMatchStrategy() ); |
66 User::LeaveIfError( CreateContactMatchStrategy() ); |
54 |
67 |
55 iNumberExtractor = new( ELeave )CCntRawPhoneNumberExtractor(); |
68 iNumberExtractor = new( ELeave )CCntRawPhoneNumberExtractor(); |
56 iNumberExtractor->ConstructL(); |
69 iNumberExtractor->ConstructL(); |
57 } |
70 } |
58 |
71 |
|
72 // --------------------------------------------------------------------------- |
|
73 // |
|
74 // --------------------------------------------------------------------------- |
|
75 // |
|
76 TInt CPhCntContactMatchStrategy::ReadMatchDigitsValueL() |
|
77 { |
|
78 CRepository* cenRepSession = CRepository::NewL( KCRUidTelConfiguration ); |
|
79 |
|
80 TInt matchDigitsValue (KErrNotFound); |
|
81 // Find digit count to be used with matching. |
|
82 cenRepSession->Get( KTelMatchDigits, matchDigitsValue ); |
|
83 |
|
84 delete cenRepSession; |
|
85 return matchDigitsValue; |
|
86 } |
59 |
87 |
60 // --------------------------------------------------------------------------- |
88 // --------------------------------------------------------------------------- |
61 // Static constructor. |
89 // Static constructor. |
62 // --------------------------------------------------------------------------- |
90 // --------------------------------------------------------------------------- |
63 // |
91 // |
64 CPhCntContactMatchStrategy* CPhCntContactMatchStrategy::NewL( |
92 CPhCntContactMatchStrategy* CPhCntContactMatchStrategy::NewL( |
65 CVPbkContactManager& aContactManager, |
93 CVPbkContactManager& aContactManager, |
66 CPhCntContactStoreUris& aContactStoreUris, |
94 CPhCntContactStoreUris& aContactStoreUris, |
67 MVPbkContactFindObserver& aObserver, |
95 MVPbkContactFindObserver& aObserver, |
68 TUint32 aMatchFlags ) |
96 MPhCntContactManager::TDuplicateRemovalStrategy aRemoveDuplicatesStrategy ) |
69 { |
97 { |
70 CPhCntContactMatchStrategy* self = |
98 CPhCntContactMatchStrategy* self = |
71 new( ELeave ) CPhCntContactMatchStrategy( |
99 new( ELeave ) CPhCntContactMatchStrategy( |
72 aContactManager, |
100 aContactManager, |
73 aContactStoreUris, |
101 aContactStoreUris, |
74 aObserver, |
102 aObserver, |
75 aMatchFlags ); |
103 aRemoveDuplicatesStrategy ); |
76 CleanupStack::PushL( self ); |
104 CleanupStack::PushL( self ); |
77 self->ConstructL(); |
105 self->ConstructL(); |
78 CleanupStack::Pop( self ); |
106 CleanupStack::Pop( self ); |
79 return self; |
107 return self; |
80 } |
108 } |
160 // --------------------------------------------------------------------------- |
190 // --------------------------------------------------------------------------- |
161 // Creates contact match strategy |
191 // Creates contact match strategy |
162 // --------------------------------------------------------------------------- |
192 // --------------------------------------------------------------------------- |
163 // |
193 // |
164 TInt CPhCntContactMatchStrategy::DoCreateMatchStrategy() |
194 TInt CPhCntContactMatchStrategy::DoCreateMatchStrategy() |
165 { |
195 { |
|
196 TUint32 flags = FillMatchFlags(); |
|
197 |
166 CVPbkPhoneNumberMatchStrategy::TConfig config( |
198 CVPbkPhoneNumberMatchStrategy::TConfig config( |
167 KBestMatchingPhoneNumbers, |
199 iNumberOfDigits, |
168 *iUriArray, |
200 *iUriArray, |
169 CVPbkPhoneNumberMatchStrategy::EVPbkSequentialMatch, |
201 CVPbkPhoneNumberMatchStrategy::EVPbkSequentialMatch, |
170 iMatchFlags |
202 flags |
171 ); |
203 ); |
|
204 |
172 TRAPD( err, iMatchStrategy = CVPbkPhoneNumberMatchStrategy::NewL( |
205 TRAPD( err, iMatchStrategy = CVPbkPhoneNumberMatchStrategy::NewL( |
173 config, |
206 config, |
174 iContactManager, |
207 iContactManager, |
175 iObserver ) ); |
208 iObserver ) ); |
176 return err; |
209 return err; |
177 } |
210 } |
178 |
211 |
179 // --------------------------------------------------------------------------- |
212 // --------------------------------------------------------------------------- |
|
213 // |
|
214 // --------------------------------------------------------------------------- |
|
215 // |
|
216 TUint32 CPhCntContactMatchStrategy::FillMatchFlags() const |
|
217 { |
|
218 TUint32 flags = CVPbkPhoneNumberMatchStrategy::EVPbkMatchFlagsNone; |
|
219 |
|
220 if ( iRemoveDuplicatesStrategy == MPhCntContactManager::ERemoveDuplicates ) |
|
221 { |
|
222 flags |= CVPbkPhoneNumberMatchStrategy::EVPbkDuplicatedContactsMatchFlag; |
|
223 } |
|
224 |
|
225 if ( iNumberOfDigits == KBestMatchingPhoneNumbers ) |
|
226 { |
|
227 flags |= CVPbkPhoneNumberMatchStrategy::EVPbkBestMatchingFlag; |
|
228 } |
|
229 |
|
230 return flags; |
|
231 } |
|
232 |
|
233 |
|
234 // --------------------------------------------------------------------------- |
180 // Makes the actual matching request. |
235 // Makes the actual matching request. |
181 // --------------------------------------------------------------------------- |
236 // --------------------------------------------------------------------------- |
182 // |
237 // |
183 void CPhCntContactMatchStrategy::DoMatchL( |
238 void CPhCntContactMatchStrategy::DoMatchL( |
184 const TDesC& aNumber ) |
239 const TDesC& aNumber ) |
185 { |
240 { |
186 iMatchStrategy->MatchL( aNumber ); |
241 |
187 } |
242 //extra characters should not be removed when using BestMatching algorithm |
|
243 if ( iNumberOfDigits == KBestMatchingPhoneNumbers ) |
|
244 { |
|
245 iMatchStrategy->MatchL( aNumber ); |
|
246 } |
|
247 else |
|
248 { |
|
249 TDesC* rawNumber = RemoveExtraCharactersLC( aNumber ); |
|
250 iMatchStrategy->MatchL( *rawNumber ); |
|
251 CleanupStack::PopAndDestroy( rawNumber ); |
|
252 } |
|
253 } |
|
254 |
|
255 // --------------------------------------------------------------------------- |
|
256 // Removes postfix from aNumber |
|
257 // --------------------------------------------------------------------------- |
|
258 // |
|
259 TDesC* CPhCntContactMatchStrategy::RemoveExtraCharactersLC( const TDesC& aNumber ) |
|
260 { |
|
261 HBufC* rawNumber = HBufC::NewLC( aNumber.Length() ); |
|
262 TPtr rawNumberPtr = rawNumber->Des(); |
|
263 iNumberExtractor->ExtractRawNumber( aNumber, rawNumberPtr ); |
|
264 return rawNumber; |
|
265 } |
|
266 |
|
267 // --------------------------------------------------------------------------- |
|
268 // Enables to inject match strategy to ease unit testing |
|
269 // --------------------------------------------------------------------------- |
|
270 // |
|
271 void CPhCntContactMatchStrategy::SetVPbkPhoneNumberMatchStrategy( |
|
272 CVPbkPhoneNumberMatchStrategy* aMatchStrategy ) |
|
273 { |
|
274 delete iMatchStrategy; |
|
275 iMatchStrategy = aMatchStrategy; |
|
276 } |
|
277 |