25
|
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 |
MPhCntMatch* match = NULL;
|
|
119 |
if( !err )
|
|
120 |
{
|
|
121 |
// Fetch all the matched contacts, because iVoipMatchStrategy
|
|
122 |
// could give us a match that is matched to wrong contact field.
|
|
123 |
const TInt matchedContacts( linkArray->Count() );
|
|
124 |
|
|
125 |
// Find real matches.
|
|
126 |
TPhCntVoipMatchArray voipMatches;
|
|
127 |
for( TInt i = 0; i < matchedContacts; i++ )
|
|
128 |
{
|
|
129 |
// Get contacts from phone book.
|
|
130 |
CPhCntContact* match = NULL;
|
|
131 |
err = FetchContact( match, linkArray->At( i ), sipUri.SipURI() );
|
|
132 |
if( !err )
|
|
133 |
{
|
|
134 |
TRAP_IGNORE( voipMatches.AppendL( match ) );
|
|
135 |
}
|
|
136 |
else
|
|
137 |
{
|
|
138 |
// Error in fetching contacts
|
|
139 |
break;
|
|
140 |
}
|
|
141 |
}
|
|
142 |
|
|
143 |
if( aAllowUserNameMatch || aCharsForMatching )
|
|
144 |
{
|
|
145 |
match = voipMatches.FindFullOrUsernameMatch( sipUri, aCharsForMatching );
|
|
146 |
}
|
|
147 |
else
|
|
148 |
{
|
|
149 |
// Take the first match, that is voip contact. Gives NULL if match not found.
|
|
150 |
match = voipMatches.FindFullMatch( sipUri );
|
|
151 |
}
|
|
152 |
|
|
153 |
// Release extra matches
|
|
154 |
voipMatches.ReleaseMatches();
|
|
155 |
}
|
|
156 |
|
|
157 |
// If no error and match still null pointer, then no contacts were found.
|
|
158 |
if( !err && !match )
|
|
159 |
{
|
|
160 |
err = KErrNotFound;
|
|
161 |
}
|
|
162 |
else
|
|
163 |
{
|
|
164 |
aMatch = match;
|
|
165 |
}
|
|
166 |
}
|
|
167 |
else
|
|
168 |
{
|
|
169 |
aMatch = existingContact;
|
|
170 |
}
|
|
171 |
}
|
|
172 |
|
|
173 |
return err;
|
|
174 |
}
|
|
175 |
|
|
176 |
// ---------------------------------------------------------------------------
|
|
177 |
// From class CPhCntMatcher
|
|
178 |
// Matches voip contacts
|
|
179 |
// ---------------------------------------------------------------------------
|
|
180 |
TInt CPhCntMatcherVoIPImpl::MatchVoipNumber(
|
|
181 |
MPhCntMatch*& aMatch,
|
|
182 |
const TDesC& aMatchString,
|
|
183 |
const CPhCntContactId& aContactId )
|
|
184 |
{
|
|
185 |
const CPhCntVPbkContactId& contactId =
|
|
186 |
static_cast<const CPhCntVPbkContactId&>( aContactId );
|
|
187 |
|
|
188 |
const MVPbkContactLink& contactLink = contactId.ContactLink();
|
|
189 |
|
|
190 |
TInt err = CreateMatcher();
|
|
191 |
|
|
192 |
const TVPbkContactStoreUriPtr uri
|
|
193 |
= contactLink.ContactStore().StoreProperties().Uri();
|
|
194 |
|
|
195 |
// Open contact store if not opened earlier
|
|
196 |
iContactStoreLoader->LoadContactStoreWithUri( uri.UriDes() );
|
|
197 |
|
|
198 |
if ( err == KErrNone )
|
|
199 |
{
|
|
200 |
CPhCntContact* existingContact =
|
|
201 |
iFoundContacts->FindContact( contactLink );
|
|
202 |
|
|
203 |
if ( !existingContact )
|
|
204 |
{
|
|
205 |
CPhCntContact* contact = NULL;
|
|
206 |
err = iFetchContact->FetchContact( contactLink, contact );
|
|
207 |
|
|
208 |
if ( !err )
|
|
209 |
{
|
|
210 |
SetMatchedVoIPNumberIfExists( *contact, aMatchString );
|
|
211 |
|
|
212 |
TPhCntSipURI sipUri( contact->Number() );
|
|
213 |
TRAP( err, iFoundContacts->AddL( contact, sipUri.SipURI() ) );
|
|
214 |
if ( err )
|
|
215 |
{
|
|
216 |
delete contact;
|
|
217 |
}
|
|
218 |
else
|
|
219 |
{
|
|
220 |
aMatch = contact;
|
|
221 |
}
|
|
222 |
}
|
|
223 |
}
|
|
224 |
else
|
|
225 |
{
|
|
226 |
aMatch = existingContact;
|
|
227 |
}
|
|
228 |
}
|
|
229 |
return err;
|
|
230 |
}
|
|
231 |
|
|
232 |
|
|
233 |
// ---------------------------------------------------------------------------
|
|
234 |
// Sets matched VoIP number if it was found.
|
|
235 |
// ---------------------------------------------------------------------------
|
|
236 |
//
|
|
237 |
void CPhCntMatcherVoIPImpl::SetMatchedVoIPNumberIfExists(
|
|
238 |
CPhCntContact& aContact,
|
|
239 |
const TDesC& aMatchString )
|
|
240 |
{
|
|
241 |
const RArray<TPhCntNumber>& allNumbers = aContact.AllNumbers();
|
|
242 |
const TInt numberCount( allNumbers.Count() );
|
|
243 |
TPhCntSipURI sipUri( aMatchString );
|
|
244 |
|
|
245 |
for ( TInt i = 0; i < numberCount; i++ )
|
|
246 |
{
|
|
247 |
TPhCntNumber number = allNumbers[i];
|
|
248 |
if ( number.Type() == CPhCntContact::EVoipNumber ||
|
|
249 |
number.Type() == CPhCntContact::EMobileNumber ||
|
|
250 |
number.Type() == CPhCntContact::EStandardNumber ||
|
|
251 |
number.Type() == CPhCntContact::EPagerNumber ||
|
|
252 |
number.Type() == CPhCntContact::EVideoNumber ||
|
|
253 |
number.Type() == CPhCntContact::EAssistantNumber ||
|
|
254 |
number.Type() == CPhCntContact::EFaxNumber ||
|
|
255 |
number.Type() == CPhCntContact::ECarNumber )
|
|
256 |
{
|
|
257 |
// If uris are the same then we have a full match.
|
|
258 |
// (usernamepart requires case sensitive match, domain is not sensitive)
|
|
259 |
TPhCntSipURI matchURI( number.Number() );
|
|
260 |
if ( matchURI.SipURI().CompareF( sipUri.SipURI() ) == KErrNone &&
|
|
261 |
matchURI.UserNamePart().Compare( sipUri.UserNamePart() ) == KErrNone )
|
|
262 |
{
|
|
263 |
aContact.SetMatchedVoipNumber( matchURI );
|
|
264 |
break;
|
|
265 |
}
|
|
266 |
}
|
|
267 |
}
|
|
268 |
}
|
|
269 |
|
|
270 |
// ---------------------------------------------------------------------------
|
|
271 |
// From class CPhCntMatcher
|
|
272 |
// Determines if contact has CS numbers.
|
|
273 |
// ---------------------------------------------------------------------------
|
|
274 |
//
|
|
275 |
TBool CPhCntMatcherVoIPImpl::HasCSNumbers(
|
|
276 |
const CPhCntContactId& aContactId )
|
|
277 |
{
|
|
278 |
TBool hasCSNumbers = EFalse;
|
|
279 |
const CPhCntVPbkContactId& contactId =
|
|
280 |
static_cast<const CPhCntVPbkContactId&>( aContactId );
|
|
281 |
|
|
282 |
if ( CreateMatcher() == KErrNone )
|
|
283 |
{
|
|
284 |
// Check if we have contact already.
|
|
285 |
CPhCntContact* contact =
|
|
286 |
iFoundContacts->FindContact( contactId.ContactLink() );
|
|
287 |
|
|
288 |
if ( contact )
|
|
289 |
{
|
|
290 |
hasCSNumbers = HasCSNumbers( contact );
|
|
291 |
contact->Release();
|
|
292 |
}
|
|
293 |
else
|
|
294 |
{
|
|
295 |
// Fetch the contact from Virtual phonebook.
|
|
296 |
const TInt err =
|
|
297 |
iFetchContact->FetchContact( contactId.ContactLink(), contact );
|
|
298 |
hasCSNumbers = HasCSNumbers( contact );
|
|
299 |
|
|
300 |
// We can delete the contact, because it is not added to
|
|
301 |
// iFoundContacts.
|
|
302 |
delete contact;
|
|
303 |
}
|
|
304 |
}
|
|
305 |
|
|
306 |
return hasCSNumbers;
|
|
307 |
}
|
|
308 |
|
|
309 |
// ---------------------------------------------------------------------------
|
|
310 |
// Constructor
|
|
311 |
// ---------------------------------------------------------------------------
|
|
312 |
//
|
|
313 |
CPhCntMatcherVoIPImpl::CPhCntMatcherVoIPImpl(
|
|
314 |
const MPhoneCntPbkOwner& aOwner ) :
|
|
315 |
CPhCntMatcherImpl( aOwner )
|
|
316 |
{
|
|
317 |
}
|
|
318 |
|
|
319 |
|
|
320 |
// ---------------------------------------------------------------------------
|
|
321 |
// Second phase constructor
|
|
322 |
// ---------------------------------------------------------------------------
|
|
323 |
//
|
|
324 |
void CPhCntMatcherVoIPImpl::ConstructL()
|
|
325 |
{
|
|
326 |
CPhCntMatcherImpl::ConstructL();
|
|
327 |
iContactStoreLoader = CPhCntStoreLoaderImpl::NewL( iContactManager );
|
|
328 |
}
|
|
329 |
|
|
330 |
|
|
331 |
// ---------------------------------------------------------------------------
|
|
332 |
// Determines if contat has other phone numbers than CS numbers.
|
|
333 |
// ---------------------------------------------------------------------------
|
|
334 |
//
|
|
335 |
TBool CPhCntMatcherVoIPImpl::HasCSNumbers(
|
|
336 |
const CPhCntContact* const aContact )
|
|
337 |
{
|
|
338 |
|
|
339 |
TBool hasCSNumbers = EFalse;
|
|
340 |
if ( aContact )
|
|
341 |
{
|
|
342 |
const RArray<TPhCntNumber>& allNumbers = aContact->AllNumbers();
|
|
343 |
const TInt count( allNumbers.Count() );
|
|
344 |
for( TInt i = 0; i < count; i++ )
|
|
345 |
{
|
|
346 |
const MPhCntMatch::TNumberType type = allNumbers[i].Type();
|
|
347 |
if ( type != MPhCntMatch::ENone &&
|
|
348 |
type != MPhCntMatch::EFaxNumber &&
|
|
349 |
type != MPhCntMatch::EPagerNumber &&
|
|
350 |
type != MPhCntMatch::EVoipNumber
|
|
351 |
)
|
|
352 |
{
|
|
353 |
hasCSNumbers = ETrue;
|
|
354 |
}
|
|
355 |
}
|
|
356 |
}
|
|
357 |
return hasCSNumbers;
|
|
358 |
}
|
|
359 |
|
|
360 |
// ---------------------------------------------------------------------------
|
|
361 |
// Creates the contact matcher.
|
|
362 |
// ---------------------------------------------------------------------------
|
|
363 |
//
|
|
364 |
TInt CPhCntMatcherVoIPImpl::CreateMatcher()
|
|
365 |
{
|
|
366 |
TInt err = CPhCntMatcherImpl::CreateMatcher();
|
|
367 |
if ( !err && !iVoipMatchStrategy )
|
|
368 |
{
|
|
369 |
TRAP( err, iVoipMatchStrategy =
|
|
370 |
CPhCntVoipContactMatchStrategy::NewL( iContactManager,
|
|
371 |
*iMatchContact ) );
|
|
372 |
}
|
|
373 |
return err;
|
|
374 |
}
|
|
375 |
|
|
376 |
|
|
377 |
// End of File
|