13 * |
13 * |
14 * Description: Matcher implementation |
14 * Description: Matcher implementation |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 |
|
19 |
|
20 #include <CVPbkPhoneNumberMatchStrategy.h> |
18 #include <CVPbkPhoneNumberMatchStrategy.h> |
21 #include <MVPbkContactLinkArray.h> |
19 #include <MVPbkContactLinkArray.h> |
22 #include <CPbk2StoreConfiguration.h> |
20 #include <CPbk2StoreConfiguration.h> |
23 #include <MVPbkContactStoreProperties.h> |
21 #include <MVPbkContactStoreProperties.h> |
24 #include <MVPbkContactStore.h> |
22 #include <MVPbkContactStore.h> |
25 #include <CVPbkContactStoreUriArray.h> |
23 #include <CVPbkContactStoreUriArray.h> |
26 |
24 #include <talogger.h> |
|
25 #include <telephonyvariant.hrh> |
|
26 #include <telinternalcrkeys.h> |
|
27 #include <centralrepository.h> |
27 |
28 |
28 #include "CPhCntMatcherImpl.h" |
29 #include "CPhCntMatcherImpl.h" |
29 #include "cphcntmatchcontact.h" |
30 #include "cphcntmatchcontact.h" |
30 #include "cphcntfetchcontact.h" |
31 #include "cphcntfetchcontact.h" |
31 #include "cphcntfoundcontacts.h" |
32 #include "cphcntfoundcontacts.h" |
33 #include "CPhCntContactManager.h" |
34 #include "CPhCntContactManager.h" |
34 #include "CPhCntContactStores.h" |
35 #include "CPhCntContactStores.h" |
35 #include "MPhoneCntPbkOwner.h" |
36 #include "MPhoneCntPbkOwner.h" |
36 #include "cphcntvpbkcontactid.h" |
37 #include "cphcntvpbkcontactid.h" |
37 #include "cphcntcontactmatchstrategy.h" |
38 #include "cphcntcontactmatchstrategy.h" |
38 #include <talogger.h> |
39 |
39 |
40 // Local functions |
|
41 /** |
|
42 * Gets contact selection strategy from localvariation flag. |
|
43 */ |
|
44 TPhCntContactSelectionStrategy::TAllowSeveralMatches |
|
45 GetContactSelectionStrategyL() |
|
46 { |
|
47 CRepository* repository = CRepository::NewLC( KCRUidTelVariation ); |
|
48 TInt variationFlag; |
|
49 User::LeaveIfError( repository->Get( KTelVariationFlags, variationFlag ) ); |
|
50 CleanupStack::PopAndDestroy( repository ); |
|
51 |
|
52 if( variationFlag & KTelephonyLVFlagShowContactWhenSeveralMatches ) |
|
53 { |
|
54 return TPhCntContactSelectionStrategy::EAllowSeveralMatches; |
|
55 } |
|
56 else |
|
57 { |
|
58 return TPhCntContactSelectionStrategy::EAllowSingleMatch; |
|
59 } |
|
60 } |
40 |
61 |
41 |
62 |
42 // --------------------------------------------------------------------------- |
63 // --------------------------------------------------------------------------- |
43 // Static constructor |
64 // Static constructor |
44 // --------------------------------------------------------------------------- |
65 // --------------------------------------------------------------------------- |
189 const TDesC& aTelNumber ) |
210 const TDesC& aTelNumber ) |
190 { |
211 { |
191 TEFLOGSTRING( KTAOBJECT, "CNT CPhCntMatcherImpl::GetContactL" ); |
212 TEFLOGSTRING( KTAOBJECT, "CNT CPhCntMatcherImpl::GetContactL" ); |
192 // Try to find matching contact. |
213 // Try to find matching contact. |
193 const MVPbkContactLinkArray* linkArray = NULL; |
214 const MVPbkContactLinkArray* linkArray = NULL; |
194 delete iCSMatchStrategy; |
215 TInt err = MatchContactL( linkArray, aTelNumber, |
195 iCSMatchStrategy = 0; |
216 MPhCntContactManager::EDontRemoveDuplicates ); |
196 iCSMatchStrategy = iContactManager.CreateContactMatchStrategyL( *iMatchContact, |
|
197 EFalse ); // don't remove duplicates |
|
198 TInt err( iMatchContact->MatchContact( linkArray, aTelNumber, |
|
199 *iCSMatchStrategy ) ); |
|
200 |
217 |
201 CPhCntContact* match( NULL ); |
218 CPhCntContact* match( NULL ); |
202 TInt index( KErrNotFound ); |
219 TInt index( KErrNotFound ); |
203 |
220 |
204 // Apply exact match on additional stores first. |
221 // Apply exact match on additional stores first. |
205 // If match is found, don't care about other stores as |
222 // If match is found, don't care about other stores as |
206 // these come first. |
223 // these come first. |
207 if( !err && ( linkArray->Count() > 1 ) ) |
224 if( !err ) |
208 { |
225 { |
209 index = MatchFromAdditionalStore( *linkArray ); |
226 const CVPbkContactStoreUriArray& additionalStores = iContactManager.AdditionalContactStoreUris(); |
210 |
227 index = iContactSelectionStrategy.ApplyAdditonalStoreStrategy( *linkArray, additionalStores ); |
211 // Single match on additonal stores |
228 |
212 if ( index != KErrNotFound && index != KErrAlreadyExists ) |
229 const TBool manyContactsFound = index == KManyContacts; |
|
230 const TBool singleContactFound = |
|
231 index != KNoContact && index != KManyContacts; |
|
232 |
|
233 if ( singleContactFound ) |
213 { |
234 { |
214 FetchContact( match, linkArray->At( index ), aTelNumber ); |
235 FetchContact( match, linkArray->At( index ), aTelNumber ); |
215 aMatch = match; |
236 aMatch = match; |
216 return err; |
237 return err; |
217 } |
238 } |
218 else if ( index == KErrAlreadyExists ) //Several matches on additional stores |
239 else if ( manyContactsFound ) |
219 { |
240 { |
220 aMatch = match; |
241 aMatch = match; |
221 return KErrNotFound; |
242 return KErrNotFound; |
222 } |
243 } |
223 } |
244 } |
224 |
245 |
225 if( !err && ( linkArray->Count() > 1 ) ) |
246 if( !err && ( linkArray->Count() > 1 ) ) |
226 { |
247 { |
227 delete iCSMatchStrategy; |
248 err = MatchContactL( linkArray, aTelNumber, |
228 iCSMatchStrategy = 0; |
249 MPhCntContactManager::ERemoveDuplicates ); |
229 iCSMatchStrategy = iContactManager.CreateContactMatchStrategyL( |
|
230 *iMatchContact, ETrue ); //remove duplicates |
|
231 err = iMatchContact->MatchContact( linkArray, aTelNumber, |
|
232 *iCSMatchStrategy ); |
|
233 } |
250 } |
234 if ( !err ) |
251 if ( !err ) |
235 { |
252 { |
236 // If only one contact, no additional checks needed |
253 index = iContactSelectionStrategy.ApplyStrategy( *linkArray ); |
237 if ( linkArray->Count() == 1 ) |
254 } |
238 { |
|
239 index = 0; |
|
240 } |
|
241 } |
|
242 |
|
243 |
255 |
244 // Finally fetch contact details |
256 // Finally fetch contact details |
245 if ( index != KErrNotFound ) |
257 if ( index != KNoContact ) |
246 { |
258 { |
247 FetchContact( match, linkArray->At( index ), aTelNumber ); |
259 FetchContact( match, linkArray->At( index ), aTelNumber ); |
248 } |
260 aMatch = match; |
249 |
261 } |
250 aMatch = match; |
262 else |
|
263 { |
|
264 err = KErrNotFound; |
|
265 } |
|
266 |
|
267 TEFLOGSTRING2( KTAMESIN,"CNT CPhCntMatcherImpl::GetContactL,err: %d", err ); |
|
268 return err; |
|
269 } |
|
270 |
|
271 // --------------------------------------------------------------------------- |
|
272 // Matches contact |
|
273 // --------------------------------------------------------------------------- |
|
274 // |
|
275 TInt CPhCntMatcherImpl::MatchContactL( |
|
276 const MVPbkContactLinkArray*& aContactLinkArray, |
|
277 const TDesC& aTelNumber, |
|
278 MPhCntContactManager::TDuplicateRemovalStrategy aRemoveDuplicatesStrategy ) |
|
279 { |
|
280 delete iCSMatchStrategy; |
|
281 iCSMatchStrategy = NULL; |
|
282 iCSMatchStrategy = iContactManager.CreateContactMatchStrategyL( |
|
283 *iMatchContact, |
|
284 aRemoveDuplicatesStrategy ); |
|
285 |
|
286 const TInt err( iMatchContact->MatchContact( aContactLinkArray, aTelNumber, |
|
287 *iCSMatchStrategy ) ); |
251 return err; |
288 return err; |
252 } |
289 } |
253 |
290 |
254 |
291 |
255 // --------------------------------------------------------------------------- |
292 // --------------------------------------------------------------------------- |