1 /* |
|
2 * Copyright (c) 2002-2008 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: This module contains the implementation of CPEContactMatch class |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include "cpecontacthandling.h" |
|
20 #include "cpecontactmatch.h" |
|
21 #include <cphonecntfactory.h> |
|
22 #include <cphcntmatcher.h> |
|
23 #include <mpeclientinformation.h> |
|
24 #include <mpedatastore.h> |
|
25 #include <mphcntmatch.h> |
|
26 #include <pepanic.pan> |
|
27 #include <pevirtualengine.h> |
|
28 #include <talogger.h> |
|
29 |
|
30 // CONSTANTS |
|
31 |
|
32 // Space - used as a separator between concatenated first and last name |
|
33 _LIT( KPESpace," "); |
|
34 |
|
35 // For parsing protocol prefix and domain part out of a VoIP call URI |
|
36 _LIT( KPhoneColon, ":" ); |
|
37 _LIT( KPhoneAt, "@" ); |
|
38 |
|
39 // Contact group array granularity |
|
40 const TInt KPEContactGroupArrayGranularity = 5; |
|
41 |
|
42 // ================= MEMBER FUNCTIONS ======================= |
|
43 |
|
44 // --------------------------------------------------------------------------- |
|
45 // CPEContactMatch::NewL |
|
46 // --------------------------------------------------------------------------- |
|
47 // |
|
48 CPEContactMatch* CPEContactMatch::NewL( |
|
49 CPEContactHandling& aOwner, |
|
50 MPEDataStore& aDataStore |
|
51 ) |
|
52 { |
|
53 CPEContactMatch* self = |
|
54 new ( ELeave ) CPEContactMatch( aOwner, aDataStore ); |
|
55 |
|
56 CleanupStack::PushL( self ); |
|
57 self->ConstructL(); |
|
58 CleanupStack::Pop( self ); |
|
59 |
|
60 return self; |
|
61 } |
|
62 |
|
63 // --------------------------------------------------------------------------- |
|
64 // Destructor |
|
65 // --------------------------------------------------------------------------- |
|
66 // |
|
67 CPEContactMatch::~CPEContactMatch() |
|
68 { |
|
69 |
|
70 delete iContactMatcher; |
|
71 delete iContactFactory; |
|
72 iLibrary.Close(); |
|
73 } |
|
74 |
|
75 |
|
76 // ----------------------------------------------------------------------------- |
|
77 // CPEContactMatch::CreateContactIdL |
|
78 // ----------------------------------------------------------------------------- |
|
79 // |
|
80 CPhCntContactId* CPEContactMatch::CreateContactIdL( const TDesC8& aContactId ) |
|
81 { |
|
82 return iContactFactory->CreateContactIdL( aContactId ); |
|
83 } |
|
84 |
|
85 // ----------------------------------------------------------------------------- |
|
86 // CPEContactMatch::CreateContactIdL |
|
87 // ----------------------------------------------------------------------------- |
|
88 // |
|
89 CPhCntContactId* CPEContactMatch::CreateContactIdL( |
|
90 TContactItemId aContactId ) |
|
91 { |
|
92 return iContactFactory->CreateContactIdL( aContactId ); |
|
93 } |
|
94 |
|
95 // ----------------------------------------------------------------------------- |
|
96 // CPEContactMatch::CPEContactMatch |
|
97 // ----------------------------------------------------------------------------- |
|
98 // |
|
99 CPEContactMatch::CPEContactMatch( |
|
100 CPEContactHandling& aOwner, |
|
101 MPEDataStore& aDataStore ) |
|
102 : iOwner( aOwner ), iDataStore( aDataStore ) |
|
103 { |
|
104 } |
|
105 |
|
106 // ----------------------------------------------------------------------------- |
|
107 // CPEContactMatch::ConstructL |
|
108 // ----------------------------------------------------------------------------- |
|
109 // |
|
110 void CPEContactMatch::ConstructL() |
|
111 { |
|
112 //Mandatory services for providing contact match functionality |
|
113 TEFLOGSTRING( KTAOBJECT, "CNT CPEContactMatch::ConstructL > RLibrary::Load" ); |
|
114 iContactFactory = CreateCntFactoryL(); |
|
115 TEFLOGSTRING( KTAOBJECT, "CNT CPEContactMatch::ConstructL > CPhCntFactory::CreateContactMatcherL" ); |
|
116 iContactMatcher = iContactFactory->CreateContactMatcherL(); |
|
117 |
|
118 } |
|
119 |
|
120 |
|
121 // ----------------------------------------------------------------------------- |
|
122 // CPEContactMatch::MatchWithContactIdL |
|
123 // Synchronous method for finding contact data specified |
|
124 // with aContactId. |
|
125 // ----------------------------------------------------------------------------- |
|
126 // |
|
127 void CPEContactMatch::MatchWithContactIdL( |
|
128 const TInt aCallId |
|
129 ) |
|
130 |
|
131 { |
|
132 TEFLOGSTRING( KTAINT, "CNT CPEContactMatch::MatchWithContactIdL" ); |
|
133 MPhCntMatch* match( NULL ); |
|
134 CPhCntContactId* contactId = NULL; |
|
135 contactId = CreateContactIdL( iDataStore.CallClientInformation( aCallId ).ContactLink() ); |
|
136 CleanupStack::PushL( contactId ); |
|
137 if ( iDataStore.CallType( aCallId ) == EPECallTypeVoIP ) |
|
138 { |
|
139 if ( contactId && contactId->IsValid() ) |
|
140 { |
|
141 TEFLOGSTRING( KTAINT, "CNT CPEContactMatch::MatchWithContactIdL > CPhCntMatcher::MatchVoipNumber" ); |
|
142 // Get contact based on contact id. |
|
143 iContactMatcher->MatchVoipNumber( match, |
|
144 *contactId ); |
|
145 } |
|
146 else |
|
147 { |
|
148 User::Leave( KErrArgument ); |
|
149 } |
|
150 } |
|
151 else |
|
152 { |
|
153 if ( contactId && contactId->IsValid() ) |
|
154 { |
|
155 TEFLOGSTRING( KTAINT, "CNT CPEContactMatch::MatchWithContactIdL > CPhCntMatcher::MatchNumber" ); |
|
156 iContactMatcher->MatchNumber( match, |
|
157 iDataStore.RemotePhoneNumber( aCallId ), |
|
158 *contactId ); |
|
159 } |
|
160 else |
|
161 { |
|
162 User::Leave( KErrArgument ); |
|
163 } |
|
164 } |
|
165 |
|
166 if ( match != NULL ) |
|
167 { |
|
168 TEFLOGSTRING( KTAINT, "CNT CPEContactMatch::MatchWithContactIdL, Contact match found" ); |
|
169 CopyContactFieldsDataL( *match, aCallId ); |
|
170 |
|
171 if ( match->HasThumbnailImage() ) |
|
172 { |
|
173 TEFLOGSTRING( KTAINT, "CNT CPEContactMatch::MatchWithContactIdL, Thumbnail image found" ); |
|
174 // Start loading thumbnail for this contact |
|
175 // Error code may be ignored since this is not a critical function |
|
176 //LoadThumbnail( iDataStore.ContactId( aCallId ), aCallId ); |
|
177 } |
|
178 match->Release(); |
|
179 match = NULL; |
|
180 } |
|
181 CleanupStack::PopAndDestroy( contactId ); //contactId |
|
182 |
|
183 } |
|
184 |
|
185 // ----------------------------------------------------------------------------- |
|
186 // CPEContactMatch::MatchWithNumberL |
|
187 // Synchronous method for finding contact data specified with phone number. |
|
188 // ----------------------------------------------------------------------------- |
|
189 // |
|
190 void CPEContactMatch::MatchWithNumberL( |
|
191 const TInt aCallId |
|
192 ) |
|
193 { |
|
194 MPhCntMatch* match( NULL ); |
|
195 |
|
196 if ( iDataStore.CallType( aCallId ) == EPECallTypeVoIP ) |
|
197 { |
|
198 TEFLOGSTRING2( KTAINT, "CNT CPEContactMatch::MatchWithNumberL > CPhCntMatcher::MatchVoipNumber, call id: %d", aCallId ); |
|
199 TPEPhoneNumber remoteNumber = iDataStore.RemotePhoneNumber( aCallId ); |
|
200 |
|
201 |
|
202 // TODO: Determine whether domain part of the URI should be ignored |
|
203 // This could be done via RCSE (which is in my understanding: depricated) |
|
204 // but needs to be studied if SP Settings need to support this service |
|
205 // setting instead |
|
206 |
|
207 // Parse protocol prefix and domain part out of a VoIP call URI |
|
208 TInt pos( remoteNumber.Find( KPhoneColon ) ); |
|
209 if ( pos > KErrNotFound ) |
|
210 { |
|
211 remoteNumber.Delete( 0, pos+1 ); |
|
212 } |
|
213 |
|
214 pos = remoteNumber.Find( KPhoneAt ); |
|
215 if ( pos > KErrNotFound ) |
|
216 { |
|
217 remoteNumber.Delete( pos, remoteNumber.Length() - pos ); |
|
218 } |
|
219 |
|
220 TEFLOGSTRING3( KTAINT, "CNT CPEContactMatch::MatchWithNumberL > CPhCntMatcher::MatchNumber, number: %S, call id: %d", |
|
221 &remoteNumber, aCallId ); |
|
222 iContactMatcher->MatchVoipNumber( match, remoteNumber, ETrue, remoteNumber.Length() ); |
|
223 |
|
224 |
|
225 } |
|
226 else |
|
227 { |
|
228 TPEPhoneNumber remoteNumber = iDataStore.RemotePhoneNumber( aCallId ); |
|
229 |
|
230 TEFLOGSTRING3( KTAINT, "CNT CPEContactMatch::MatchWithNumberL > CPhCntMatcher::MatchNumber, number: %S, call id: %d", |
|
231 &remoteNumber, aCallId ); |
|
232 |
|
233 TInt id = KErrNotFound; |
|
234 id = iDataStore.ContactId2(); |
|
235 id == KErrNotFound? iContactMatcher->MatchNumber( match, remoteNumber ) : |
|
236 iContactMatcher->MatchNumber(match, remoteNumber, id); |
|
237 //reset contact-id |
|
238 iDataStore.SetContactId2(KErrNotFound); |
|
239 |
|
240 |
|
241 } |
|
242 |
|
243 if ( match != NULL ) |
|
244 { |
|
245 TEFLOGSTRING( KTAINT, "CNT CPEContactMatch::MatchWithNumberL, Contact match found" ); |
|
246 CopyContactFieldsDataL( *match, aCallId ); |
|
247 |
|
248 if ( match->HasThumbnailImage() ) |
|
249 { |
|
250 TEFLOGSTRING( KTAINT, "CNT CPEContactMatch::MatchWithNumberL, Thumbnail image found" ); |
|
251 // Start loading thumbnail for this contact |
|
252 // Error code may be ignored since this is not a critical function |
|
253 iDataStore.SetHasCallerThumbnail( ETrue, aCallId ); |
|
254 //LoadThumbnail( iDataStore.ContactId( aCallId ), aCallId ); |
|
255 } |
|
256 match->Release(); |
|
257 match = NULL; |
|
258 } |
|
259 } |
|
260 |
|
261 |
|
262 |
|
263 // --------------------------------------------------------- |
|
264 // CPEContactMatch::ContactThumbnail |
|
265 // Returns contact thumbnail image, NULL if not found |
|
266 // --------------------------------------------------------- |
|
267 // |
|
268 CFbsBitmap* CPEContactMatch::ContactThumbnail() |
|
269 { |
|
270 return NULL; |
|
271 |
|
272 } |
|
273 |
|
274 // ----------------------------------------------------------------------------- |
|
275 // CPEContactMatch::CopyContactFieldsDataL |
|
276 // Copies contact information to remote info struct |
|
277 // ----------------------------------------------------------------------------- |
|
278 // |
|
279 void CPEContactMatch::CopyContactFieldsDataL( |
|
280 const MPhCntMatch& aMatch, |
|
281 const TInt aCallId |
|
282 ) |
|
283 { |
|
284 TEFLOGSTRING( KTAINT, "CNT CPEContactMatch::CopyContactFieldsDataL: start" ); |
|
285 |
|
286 // Set ringing tone's filename |
|
287 iDataStore.SetPersonalRingingTone( aMatch.PersonalRingingTone(), aCallId ); |
|
288 |
|
289 // Set name |
|
290 // The following logic determines if one of the languages that require |
|
291 // swapping of first/last name order is selected and performs the operation. |
|
292 HBufC* lastname( NULL ); |
|
293 HBufC* firstname( NULL ); |
|
294 |
|
295 if ( aMatch.LastName().Length() > 0 ) |
|
296 { |
|
297 TEFLOGSTRING( KTAINT, "CNT CPEContactMatch::CopyContactFieldsDataL, alloc last name" ); |
|
298 lastname = aMatch.LastName().Alloc(); |
|
299 } |
|
300 if ( aMatch.FirstName().Length() > 0 ) |
|
301 { |
|
302 TEFLOGSTRING( KTAINT, "CNT CPEContactMatch::CopyContactFieldsDataL, alloc first name" ); |
|
303 firstname = aMatch.FirstName().Alloc(); |
|
304 } |
|
305 |
|
306 if ( ( lastname ) && ( firstname ) ) |
|
307 { |
|
308 //Swap name order, if required by the current language setting |
|
309 const TLanguage language = User::Language(); |
|
310 |
|
311 for ( TInt index = 0; index < KPENumberOfSwappedLanguages; index++ ) |
|
312 { |
|
313 if ( KPESwappedLanguages[index] == language ) |
|
314 { |
|
315 HBufC* tempfirstname( firstname ); |
|
316 firstname = lastname; |
|
317 lastname = tempfirstname; |
|
318 break; |
|
319 } |
|
320 } |
|
321 } |
|
322 |
|
323 TPEContactName finalName; |
|
324 // Parse name by concatenating lastname and firstname |
|
325 if ( firstname ) |
|
326 { |
|
327 finalName = *firstname; |
|
328 if ( finalName.Length() < KCntMaxTextFieldLength && lastname ) |
|
329 { |
|
330 TEFLOGSTRING( KTAINT, "CNT CPEContactMatch::CopyContactFieldsDataL, append with space" ); |
|
331 finalName.Append( KPESpace ); |
|
332 } |
|
333 delete firstname; |
|
334 firstname = NULL; |
|
335 } |
|
336 if ( lastname ) |
|
337 { |
|
338 if ( finalName.Length() < KCntMaxTextFieldLength ) |
|
339 { |
|
340 // Check how long last name can be added to the iName string. |
|
341 TInt lastNameMaxLength = KCntMaxTextFieldLength - finalName.Length(); |
|
342 if ( lastname->Length() > lastNameMaxLength ) |
|
343 { |
|
344 TEFLOGSTRING( KTAINT, "CNT CPEContactMatch::CopyContactFieldsDataL, append with part of last name" ); |
|
345 // Cut extra chars from the string. |
|
346 finalName.Append( lastname->Left( lastNameMaxLength ) ); |
|
347 } |
|
348 else |
|
349 { |
|
350 TEFLOGSTRING( KTAINT, "CNT CPEContactMatch::CopyContactFieldsDataL, append with last name" ); |
|
351 finalName.Append( *lastname ); |
|
352 } |
|
353 } |
|
354 delete lastname; |
|
355 lastname = NULL; |
|
356 } |
|
357 |
|
358 // Replace paragraph separator with space character |
|
359 const TText ps(0x2029); |
|
360 |
|
361 while ( finalName.Locate( ps ) != KErrNotFound ) |
|
362 { |
|
363 finalName[ finalName.Locate( ps )] = ' '; |
|
364 } |
|
365 TEFLOGSTRING3( KTAINT, "CNT CPEContactMatch::iDataStore.SetRemoteName( finalName, aCallId ): finalName: %S callid: %d ", &finalName, aCallId); |
|
366 iDataStore.SetRemoteName( finalName, aCallId ); |
|
367 |
|
368 iDataStore.SetRemoteTextToSpeechText( aMatch.TextToSpeechTextL(), aCallId ); |
|
369 |
|
370 TInt phcntfinderNumberType = aMatch.NumberType(); |
|
371 |
|
372 switch ( phcntfinderNumberType ) |
|
373 { |
|
374 case MPhCntMatch::EMobileNumber: |
|
375 iDataStore.SetRemotePhoneNumberType( EPEMobileNumber, aCallId ); |
|
376 break; |
|
377 case MPhCntMatch::EStandardNumber: |
|
378 iDataStore.SetRemotePhoneNumberType( EPETelephoneNumber, aCallId ); |
|
379 break; |
|
380 case MPhCntMatch::EFaxNumber: |
|
381 iDataStore.SetRemotePhoneNumberType( EPEFaxNumber, aCallId ); |
|
382 break; |
|
383 case MPhCntMatch::EPagerNumber: |
|
384 iDataStore.SetRemotePhoneNumberType( EPEPager, aCallId ); |
|
385 break; |
|
386 case MPhCntMatch::EVoipNumber: |
|
387 iDataStore.SetRemotePhoneNumberType( EPEVoipNumber, aCallId ); |
|
388 break; |
|
389 case MPhCntMatch::EVideoNumber: |
|
390 iDataStore.SetRemotePhoneNumberType( EPEVideoNumber, aCallId ); |
|
391 break; |
|
392 case MPhCntMatch::EAssistantNumber: |
|
393 iDataStore.SetRemotePhoneNumberType( EPEAssistantNumber, aCallId ); |
|
394 break; |
|
395 case MPhCntMatch::ECarNumber: |
|
396 iDataStore.SetRemotePhoneNumberType( EPECarNumber, aCallId ); |
|
397 break; |
|
398 case MPhCntMatch::EHomeNumber: |
|
399 iDataStore.SetRemotePhoneNumberType( EPEHomeNumber, aCallId ); |
|
400 break; |
|
401 case MPhCntMatch::EWorkNumber: |
|
402 iDataStore.SetRemotePhoneNumberType( EPEWorkNumber, aCallId ); |
|
403 break; |
|
404 case MPhCntMatch::ENone: // fall through |
|
405 default: |
|
406 iDataStore.SetRemotePhoneNumberType( EPEUnknownNumber, aCallId ); |
|
407 break; |
|
408 } |
|
409 |
|
410 // Replace paragraph separator with space character |
|
411 TPEContactName companyName; |
|
412 companyName = aMatch.CompanyName(); |
|
413 while ( companyName.Locate( ps ) != KErrNotFound ) |
|
414 { |
|
415 companyName[ companyName.Locate( ps )] = ' '; |
|
416 } |
|
417 // Set Company name |
|
418 iDataStore.SetRemoteCompanyName( companyName, aCallId ); |
|
419 |
|
420 // Set Call text |
|
421 iDataStore.SetCallerText( aMatch.CallText(), aCallId ); |
|
422 |
|
423 // Set Call image |
|
424 iDataStore.SetCallerImage( aMatch.CallImage(), aCallId ); |
|
425 |
|
426 // Set Contact ID |
|
427 iDataStore.SetContactId( aMatch.ContactId()->CloneL(), aCallId ); |
|
428 |
|
429 CArrayFixFlat< TContactItemId >* groupList |
|
430 = new ( ELeave ) CArrayFixFlat< TContactItemId > |
|
431 ( KPEContactGroupArrayGranularity ); |
|
432 |
|
433 TArray<TContactItemId> alertFor = iDataStore.AlertForGroup(); |
|
434 const TInt groupLength = alertFor.Count(); |
|
435 for ( TInt i = 0; i < groupLength; i++ ) |
|
436 { |
|
437 groupList->AppendL( alertFor[ i ] ); |
|
438 } |
|
439 |
|
440 if ( aMatch.BelongsToGroups( *groupList ) ) |
|
441 { |
|
442 // Convert array type here to ease further handling |
|
443 TArray<TContactItemId> list = groupList->Array(); |
|
444 // Set group information |
|
445 iDataStore.SetContactGroups( list, aCallId ); |
|
446 } |
|
447 delete groupList; |
|
448 groupList = NULL; |
|
449 |
|
450 // Set dtmf array |
|
451 iDataStore.SetPredefinedDtmfStrings( aMatch.AllDtmfNumbers(), aCallId ); |
|
452 TEFLOGSTRING( KTAINT, "CNT CPEContactMatch::CopyContactFieldsDataL: complete" ); |
|
453 } |
|
454 |
|
455 // ----------------------------------------------------------------------------- |
|
456 // CPEContactMatch::GetSpeedDialLocationL |
|
457 // Get's phone number from given location. |
|
458 // ----------------------------------------------------------------------------- |
|
459 // |
|
460 void CPEContactMatch::GetSpeedDialLocationL( |
|
461 TInt /*aLocationIndex*/, |
|
462 TPEPhoneNumber& /*aNumber*/ ) |
|
463 { |
|
464 |
|
465 } |
|
466 |
|
467 // End of File |
|