|
1 /* |
|
2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Implements VoIP specific matching methods. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <MVPbkContactLinkArray.h> |
|
20 #include <TVPbkContactStoreUriPtr.h> |
|
21 #include <MVPbkContactStore.h> |
|
22 #include <MVPbkContactStoreProperties.h> |
|
23 |
|
24 #include "cphcntmatchervoipimpl.h" |
|
25 #include "tphcntsipuri.h" |
|
26 #include "cphcntfoundcontacts.h" |
|
27 #include "cphcntmatchcontact.h" |
|
28 #include "cphcntvoipcontactmatchstrategy.h" |
|
29 #include "tphcntvoipmatchArray.h" |
|
30 #include "MPhCntMatch.h" |
|
31 #include "CPhCntContact.h" |
|
32 #include "cphcntvpbkcontactid.h" |
|
33 #include "cphcntfetchcontact.h" |
|
34 #include "CPhCntContactManager.h" |
|
35 |
|
36 #include "cphcntstoreloaderimpl.h" // |
|
37 |
|
38 // ======== MEMBER FUNCTIONS ======== |
|
39 |
|
40 // --------------------------------------------------------------------------- |
|
41 // Static constructor |
|
42 // --------------------------------------------------------------------------- |
|
43 // |
|
44 CPhCntMatcherVoIPImpl* CPhCntMatcherVoIPImpl::NewL( |
|
45 const MPhoneCntPbkOwner& aOwner ) |
|
46 { |
|
47 CPhCntMatcherVoIPImpl* self = |
|
48 new( ELeave ) CPhCntMatcherVoIPImpl( aOwner ); |
|
49 CleanupStack::PushL( self ); |
|
50 self->ConstructL(); |
|
51 CleanupStack::Pop( self ); |
|
52 return self; |
|
53 } |
|
54 |
|
55 // --------------------------------------------------------------------------- |
|
56 // Destructor |
|
57 // --------------------------------------------------------------------------- |
|
58 // |
|
59 CPhCntMatcherVoIPImpl::~CPhCntMatcherVoIPImpl() |
|
60 { |
|
61 delete iVoipMatchStrategy; |
|
62 delete iContactStoreLoader; |
|
63 } |
|
64 |
|
65 // --------------------------------------------------------------------------- |
|
66 // From class CPhCntMatcher |
|
67 // Matches voip contacts |
|
68 // --------------------------------------------------------------------------- |
|
69 // |
|
70 TInt CPhCntMatcherVoIPImpl::MatchVoipNumber( |
|
71 MPhCntMatch*& aMatch, |
|
72 const TDesC& aMatchString, |
|
73 TBool aAllowUserNameMatch, |
|
74 MDesCArray* aContactStoreUris, |
|
75 TInt aCharsForMatching ) |
|
76 { |
|
77 TPhCntSipURI sipUri( aMatchString, aCharsForMatching ); |
|
78 TInt err = CreateMatcher(); |
|
79 |
|
80 if ( err == KErrNone ) |
|
81 { |
|
82 CPhCntContact* existingContact = |
|
83 iFoundContacts->FindContact( sipUri.SipURI() ); |
|
84 if( !existingContact ) |
|
85 { |
|
86 // Check for service specific contact stores and |
|
87 // open stores if not open |
|
88 if ( aContactStoreUris ) |
|
89 { |
|
90 TInt storeCount = aContactStoreUris->MdcaCount(); |
|
91 for( TInt i = 0; i < storeCount ; i++ ) |
|
92 { |
|
93 TPtrC storeUri = aContactStoreUris->MdcaPoint( i ); |
|
94 |
|
95 err = iContactStoreLoader->LoadContactStoreWithUri( storeUri ); |
|
96 } |
|
97 } |
|
98 |
|
99 const MVPbkContactLinkArray* linkArray = NULL; |
|
100 |
|
101 // Find possible contacts. |
|
102 if( aAllowUserNameMatch && !aCharsForMatching ) |
|
103 { |
|
104 err = iMatchContact->MatchContact( |
|
105 linkArray, sipUri.UserNamePart(), *iVoipMatchStrategy ); |
|
106 } |
|
107 else if ( aCharsForMatching ) |
|
108 { |
|
109 err = iMatchContact->MatchContact( |
|
110 linkArray, sipUri.FixedUserNamePart(), *iVoipMatchStrategy ); |
|
111 } |
|
112 else |
|
113 { |
|
114 err = iMatchContact->MatchContact( |
|
115 linkArray, sipUri.SipURI() , *iVoipMatchStrategy ); |
|
116 } |
|
117 |
|
118 |
|
119 MPhCntMatch* match = NULL; |
|
120 if( !err ) |
|
121 { |
|
122 // Fetch all the matched contacts, because iVoipMatchStrategy |
|
123 // could give us a match that is matched to wrong contact field. |
|
124 const TInt matchedContacts( linkArray->Count() ); |
|
125 |
|
126 // Find real matches. |
|
127 TPhCntVoipMatchArray voipMatches; |
|
128 for( TInt i = 0; i < matchedContacts; i++ ) |
|
129 { |
|
130 // Get contacts from phone book. |
|
131 CPhCntContact* match = NULL; |
|
132 err = FetchContact( match, linkArray->At( i ), sipUri.SipURI() ); |
|
133 if( !err ) |
|
134 { |
|
135 TRAP_IGNORE( voipMatches.AppendL( match ) ); |
|
136 } |
|
137 else |
|
138 { |
|
139 // Error in fetching contacts |
|
140 break; |
|
141 } |
|
142 } |
|
143 |
|
144 if( aAllowUserNameMatch || aCharsForMatching ) |
|
145 { |
|
146 match = voipMatches.FindFullOrUsernameMatch( sipUri, aCharsForMatching ); |
|
147 } |
|
148 else |
|
149 { |
|
150 // Take the first match, that is voip contact. Gives NULL if match not found. |
|
151 match = voipMatches.FindFullMatch( sipUri ); |
|
152 } |
|
153 |
|
154 // Release extra matches |
|
155 voipMatches.ReleaseMatches(); |
|
156 } |
|
157 |
|
158 // If no error and match still null pointer, then no contacts were found. |
|
159 if( !err && !match ) |
|
160 { |
|
161 err = KErrNotFound; |
|
162 } |
|
163 else |
|
164 { |
|
165 aMatch = match; |
|
166 } |
|
167 } |
|
168 else |
|
169 { |
|
170 aMatch = existingContact; |
|
171 } |
|
172 } |
|
173 |
|
174 return err; |
|
175 } |
|
176 |
|
177 // --------------------------------------------------------------------------- |
|
178 // From class CPhCntMatcher |
|
179 // Matches voip contacts |
|
180 // --------------------------------------------------------------------------- |
|
181 TInt CPhCntMatcherVoIPImpl::MatchVoipNumber( |
|
182 MPhCntMatch*& aMatch, |
|
183 const CPhCntContactId& aContactId ) |
|
184 { |
|
185 const CPhCntVPbkContactId& contactId = |
|
186 static_cast<const CPhCntVPbkContactId&>( aContactId ); |
|
187 |
|
188 const MVPbkContactLink& contactLink = contactId.ContactLink(); |
|
189 |
|
190 |
|
191 TInt err = CreateMatcher(); |
|
192 |
|
193 const TVPbkContactStoreUriPtr uri |
|
194 = contactLink.ContactStore().StoreProperties().Uri(); |
|
195 |
|
196 // Open contact store if not opened earlier |
|
197 iContactStoreLoader->LoadContactStoreWithUri( uri.UriDes() ); |
|
198 |
|
199 if ( err == KErrNone ) |
|
200 { |
|
201 CPhCntContact* existingContact = |
|
202 iFoundContacts->FindContact( contactLink ); |
|
203 |
|
204 |
|
205 if( !existingContact ) |
|
206 { |
|
207 CPhCntContact* contact = NULL; |
|
208 err = iFetchContact->FetchContact( contactLink, contact ); |
|
209 |
|
210 if( !err ) |
|
211 { |
|
212 const RArray<TPhCntNumber>& allNumbers = |
|
213 contact->AllNumbers(); |
|
214 const TInt count( allNumbers.Count() ); |
|
215 for( TInt i = 0; i < count; i++ ) |
|
216 { |
|
217 // Take first voip number and set it as contacts number. |
|
218 TPhCntNumber number = allNumbers[i]; |
|
219 if( number.Type() == MPhCntMatch::EVoipNumber || |
|
220 number.Type() == MPhCntMatch::EMobileNumber || |
|
221 number.Type() == MPhCntMatch::EStandardNumber || |
|
222 number.Type() == CPhCntContact::EPagerNumber || |
|
223 number.Type() == CPhCntContact::EVideoNumber || |
|
224 number.Type() == CPhCntContact::EAssistantNumber || |
|
225 number.Type() == CPhCntContact::EFaxNumber || |
|
226 number.Type() == CPhCntContact::ECarNumber ) |
|
227 { |
|
228 contact->SetMatchedVoipNumber( TPhCntSipURI( number.Number() ) ); |
|
229 break; |
|
230 } |
|
231 } |
|
232 TPhCntSipURI sipUri( contact->Number() ); |
|
233 TRAP( err, iFoundContacts->AddL( contact, sipUri.SipURI() ) ); |
|
234 if( err ) |
|
235 { |
|
236 delete contact; |
|
237 } |
|
238 else |
|
239 { |
|
240 aMatch = contact; |
|
241 } |
|
242 |
|
243 } |
|
244 } |
|
245 else |
|
246 { |
|
247 aMatch = existingContact; |
|
248 } |
|
249 } |
|
250 return err; |
|
251 } |
|
252 |
|
253 |
|
254 // --------------------------------------------------------------------------- |
|
255 // From class CPhCntMatcher |
|
256 // Determines if contact has CS numbers. |
|
257 // --------------------------------------------------------------------------- |
|
258 // |
|
259 TBool CPhCntMatcherVoIPImpl::HasCSNumbers( |
|
260 const CPhCntContactId& aContactId ) |
|
261 { |
|
262 TBool hasCSNumbers = EFalse; |
|
263 const CPhCntVPbkContactId& contactId = |
|
264 static_cast<const CPhCntVPbkContactId&>( aContactId ); |
|
265 |
|
266 if ( CreateMatcher() == KErrNone ) |
|
267 { |
|
268 |
|
269 // Check if we have contact already. |
|
270 CPhCntContact* contact = |
|
271 iFoundContacts->FindContact( contactId.ContactLink() ); |
|
272 |
|
273 if( contact ) |
|
274 { |
|
275 hasCSNumbers = HasCSNumbers( contact ); |
|
276 contact->Release(); |
|
277 } |
|
278 else |
|
279 { |
|
280 // Fetch the contact from Virtual phonebook. |
|
281 const TInt err = |
|
282 iFetchContact->FetchContact( contactId.ContactLink(), contact ); |
|
283 hasCSNumbers = HasCSNumbers( contact ); |
|
284 |
|
285 // We can delete the contact, because it is not added to |
|
286 // iFoundContacts. |
|
287 delete contact; |
|
288 } |
|
289 |
|
290 } |
|
291 |
|
292 return hasCSNumbers; |
|
293 } |
|
294 |
|
295 // --------------------------------------------------------------------------- |
|
296 // Constructor |
|
297 // --------------------------------------------------------------------------- |
|
298 // |
|
299 CPhCntMatcherVoIPImpl::CPhCntMatcherVoIPImpl( |
|
300 const MPhoneCntPbkOwner& aOwner ) : |
|
301 CPhCntMatcherImpl( aOwner ) |
|
302 { |
|
303 } |
|
304 |
|
305 |
|
306 // --------------------------------------------------------------------------- |
|
307 // Second phase constructor |
|
308 // --------------------------------------------------------------------------- |
|
309 // |
|
310 void CPhCntMatcherVoIPImpl::ConstructL() |
|
311 { |
|
312 CPhCntMatcherImpl::ConstructL(); |
|
313 iContactStoreLoader = CPhCntStoreLoaderImpl::NewL( iContactManager ); |
|
314 } |
|
315 |
|
316 |
|
317 // --------------------------------------------------------------------------- |
|
318 // Determines if contat has other phone numbers than CS numbers. |
|
319 // --------------------------------------------------------------------------- |
|
320 // |
|
321 TBool CPhCntMatcherVoIPImpl::HasCSNumbers( |
|
322 const CPhCntContact* const aContact ) |
|
323 { |
|
324 |
|
325 TBool hasCSNumbers = EFalse; |
|
326 if( aContact ) |
|
327 { |
|
328 const RArray<TPhCntNumber>& allNumbers = aContact->AllNumbers(); |
|
329 const TInt count( allNumbers.Count() ); |
|
330 for( TInt i = 0; i < count; i++ ) |
|
331 { |
|
332 const MPhCntMatch::TNumberType type = allNumbers[i].Type(); |
|
333 if( type != MPhCntMatch::ENone && |
|
334 type != MPhCntMatch::EFaxNumber && |
|
335 type != MPhCntMatch::EPagerNumber && |
|
336 type != MPhCntMatch::EVoipNumber |
|
337 ) |
|
338 { |
|
339 hasCSNumbers = ETrue; |
|
340 } |
|
341 } |
|
342 } |
|
343 return hasCSNumbers; |
|
344 } |
|
345 |
|
346 TInt CPhCntMatcherVoIPImpl::CreateMatcher() |
|
347 { |
|
348 TInt err = CPhCntMatcherImpl::CreateMatcher(); |
|
349 if (!err && !iVoipMatchStrategy ) |
|
350 { |
|
351 TRAP( err, iVoipMatchStrategy = |
|
352 CPhCntVoipContactMatchStrategy::NewL( iContactManager, |
|
353 *iMatchContact ) ); |
|
354 } |
|
355 return err; |
|
356 } |
|
357 |
|
358 |
|
359 // End of File |