|
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: Contact data. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <CPbk2ImageManager.h> |
|
20 |
|
21 #include <featmgr.h> // Feature Manager |
|
22 #include "CPhCntContact.h" |
|
23 #include "mphcntcontactfields.h" |
|
24 #include "cphcntfoundcontacts.h" |
|
25 #include "MPhCntContactManager.h" |
|
26 #include "MVPbkContactLink.h" |
|
27 #include "MVPbkContactLinkArray.h" |
|
28 #include "PhCntTrace.h" |
|
29 #include "cphcntvpbkcontactid.h" |
|
30 #include "tphcnttxttospeech.h" |
|
31 |
|
32 #include "tphcntsipuri.h" |
|
33 #include "CPhoneRawMatchNumberExtractor.h" |
|
34 |
|
35 // --------------------------------------------------------------------------- |
|
36 // Constructor |
|
37 // --------------------------------------------------------------------------- |
|
38 // |
|
39 CPhCntContact* CPhCntContact::NewL( |
|
40 MPhCntContactFields* aContactFields, |
|
41 MPhCntContactManager& aContactManager ) |
|
42 { |
|
43 CPhCntContact* self = |
|
44 new( ELeave )CPhCntContact( |
|
45 aContactFields, aContactManager ); |
|
46 |
|
47 CleanupStack::PushL( self); |
|
48 self->ConstructL(); |
|
49 CleanupStack::Pop( self ); |
|
50 return self; |
|
51 } |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 // Destructor |
|
55 // --------------------------------------------------------------------------- |
|
56 // |
|
57 CPhCntContact::~CPhCntContact() |
|
58 { |
|
59 delete iContactFields; |
|
60 delete iOriginalNumber; |
|
61 delete iContactId; |
|
62 |
|
63 delete iMatchedVoipNumber; |
|
64 if( iNumberExtractor ) |
|
65 { |
|
66 iNumberExtractor->Release(); |
|
67 } |
|
68 FeatureManager::UnInitializeLib(); |
|
69 } |
|
70 |
|
71 // --------------------------------------------------------------------------- |
|
72 // Setter |
|
73 // --------------------------------------------------------------------------- |
|
74 // |
|
75 void CPhCntContact::SetOriginalNumberL( const TDesC& aNumber ) |
|
76 { |
|
77 HBufC* number = aNumber.AllocL(); |
|
78 delete iOriginalNumber; |
|
79 iOriginalNumber = number; |
|
80 } |
|
81 |
|
82 // --------------------------------------------------------------------------- |
|
83 // Getter |
|
84 // --------------------------------------------------------------------------- |
|
85 // |
|
86 const TDesC& CPhCntContact::OriginalNumber() const |
|
87 { |
|
88 return *iOriginalNumber; |
|
89 } |
|
90 |
|
91 // --------------------------------------------------------------------------- |
|
92 // Sets the owner. |
|
93 // --------------------------------------------------------------------------- |
|
94 // |
|
95 void CPhCntContact::SetOwner( CPhCntFoundContacts* aOwner ) |
|
96 { |
|
97 iOwner = aOwner; |
|
98 } |
|
99 |
|
100 // --------------------------------------------------------------------------- |
|
101 // Increases reference count. |
|
102 // --------------------------------------------------------------------------- |
|
103 // |
|
104 void CPhCntContact::IncreaseReferenceCount() |
|
105 { |
|
106 iReferenceCount++; |
|
107 } |
|
108 |
|
109 // --------------------------------------------------------------------------- |
|
110 // All phone numbers |
|
111 // --------------------------------------------------------------------------- |
|
112 // |
|
113 const RArray<TPhCntNumber>& CPhCntContact::AllNumbers() const |
|
114 { |
|
115 return iContactFields->AllNumbers(); |
|
116 } |
|
117 |
|
118 // --------------------------------------------------------------------------- |
|
119 // DTMF number |
|
120 // --------------------------------------------------------------------------- |
|
121 // |
|
122 TPtrC CPhCntContact::Dtmf() const |
|
123 { |
|
124 return iContactFields->Dtmf(); |
|
125 } |
|
126 |
|
127 // --------------------------------------------------------------------------- |
|
128 // Sets matched number in Voip case. |
|
129 // --------------------------------------------------------------------------- |
|
130 // |
|
131 void CPhCntContact::SetMatchedVoipNumber( |
|
132 const TPhCntSipURI& aSipUri ) |
|
133 { |
|
134 delete iMatchedVoipNumber; |
|
135 iMatchedVoipNumber = NULL; |
|
136 //just ignore possible alloc failure |
|
137 TRAP_IGNORE( iMatchedVoipNumber = HBufC::NewL( |
|
138 aSipUri.SipURI().Length() ) ) |
|
139 if( iMatchedVoipNumber ) |
|
140 { |
|
141 iMatchedVoipNumber->Des().Append( aSipUri.SipURI() ); |
|
142 } |
|
143 } |
|
144 |
|
145 // --------------------------------------------------------------------------- |
|
146 // Releases this contact if no more references found. |
|
147 // --------------------------------------------------------------------------- |
|
148 // |
|
149 void CPhCntContact::Release() |
|
150 { |
|
151 iReferenceCount--; |
|
152 // TODO: Panic if reference count < 0 |
|
153 if( iReferenceCount == 0 ) |
|
154 { |
|
155 // TODO: Panic if iOwner == NULL; |
|
156 iOwner->Remove( this ); |
|
157 } |
|
158 } |
|
159 |
|
160 // --------------------------------------------------------------------------- |
|
161 // From base class MPhCntMatch |
|
162 // Getter |
|
163 // --------------------------------------------------------------------------- |
|
164 // |
|
165 CPhCntContactId* CPhCntContact::ContactId() const |
|
166 { |
|
167 return iContactId; |
|
168 } |
|
169 |
|
170 // --------------------------------------------------------------------------- |
|
171 // From base class MPhCntMatch |
|
172 // Getter |
|
173 // --------------------------------------------------------------------------- |
|
174 // |
|
175 MVPbkContactLink* CPhCntContact::ContactLink() const |
|
176 { |
|
177 return iContactFields->ContactLink(); |
|
178 } |
|
179 |
|
180 // --------------------------------------------------------------------------- |
|
181 // From base class MPhCntMatch |
|
182 // Getter |
|
183 // --------------------------------------------------------------------------- |
|
184 // |
|
185 MPhCntMatch::TNumberType CPhCntContact::NumberType() const |
|
186 { |
|
187 MPhCntMatch::TNumberType numberType = iContactFields->NumberType(); |
|
188 // check if numbertype was found |
|
189 if ( numberType == MPhCntMatch::ENone ) |
|
190 { |
|
191 // if not, then try to find numbertype among all numbers |
|
192 if ( iOriginalNumber ) |
|
193 { |
|
194 numberType = NumberType( *iOriginalNumber ); |
|
195 } |
|
196 } |
|
197 if( FeatureManager::FeatureSupported( KFeatureIdCommonVoip ) ) |
|
198 { |
|
199 // If we have iMatchedNumber then there was voip match. |
|
200 if( iMatchedVoipNumber ) |
|
201 { |
|
202 numberType = MPhCntMatch::EVoipNumber; |
|
203 } |
|
204 } |
|
205 return numberType; |
|
206 } |
|
207 |
|
208 // --------------------------------------------------------------------------- |
|
209 // Get number type from number that matches to supplied number |
|
210 // Getter |
|
211 // --------------------------------------------------------------------------- |
|
212 // |
|
213 MPhCntMatch::TNumberType CPhCntContact::NumberType( const TDesC& aNumber ) const |
|
214 { |
|
215 const RArray<TPhCntNumber>& allNumbers = AllNumbers(); |
|
216 MPhCntMatch::TNumberType numberType = MPhCntMatch::ENone; |
|
217 // try to find number from allnumbers array |
|
218 for ( TInt i = 0; i < allNumbers.Count(); i++ ) |
|
219 { |
|
220 TPhCntNumber number( allNumbers[i] ); |
|
221 // compare 7 last digits |
|
222 TBuf<KPhMatcherNumberCount> contactNumber; |
|
223 TBuf<KPhMatcherNumberCount> originalNumber; |
|
224 iNumberExtractor->ExtractRawNumber( number.Number(), contactNumber ); |
|
225 iNumberExtractor->ExtractRawNumber( aNumber, originalNumber ); |
|
226 |
|
227 if ( originalNumber.Compare( contactNumber ) == KErrNone ) |
|
228 { |
|
229 // number found, get numbertype |
|
230 numberType = number.Type(); |
|
231 break; |
|
232 } |
|
233 } |
|
234 return numberType; |
|
235 } |
|
236 |
|
237 // --------------------------------------------------------------------------- |
|
238 // From base class MPhCntMatch |
|
239 // Constructs the cli |
|
240 // --------------------------------------------------------------------------- |
|
241 // |
|
242 MPhCntMatch::TCliType CPhCntContact::Cli( HBufC*& aCliText ) const |
|
243 { |
|
244 TCliType cliType = ECliEmpty; |
|
245 |
|
246 HBufC* contactTitle = NULL; |
|
247 TRAP_IGNORE( contactTitle = iContactFields->GetContactTitleL() ); |
|
248 |
|
249 if( contactTitle ) |
|
250 { |
|
251 aCliText = contactTitle; |
|
252 cliType = ECliName; |
|
253 } |
|
254 else |
|
255 { |
|
256 // No contact title so try to use phonenumber |
|
257 const TPtrC phoneNumber = Number(); |
|
258 if( phoneNumber.Length() > 0 ) |
|
259 { |
|
260 contactTitle = phoneNumber.Alloc(); |
|
261 if( contactTitle ) |
|
262 { |
|
263 cliType = ECliNumber; |
|
264 } |
|
265 } |
|
266 } |
|
267 |
|
268 if( cliType == ECliName ) |
|
269 { |
|
270 // Is the contact title as contact title. |
|
271 if( CompanyName().Compare( contactTitle->Des() ) == 0 && |
|
272 FirstName().Length() == 0 && |
|
273 LastName().Length() == 0 ) |
|
274 { |
|
275 cliType = ECliCompany; |
|
276 } |
|
277 } |
|
278 |
|
279 aCliText = contactTitle; |
|
280 return cliType; |
|
281 } |
|
282 |
|
283 // --------------------------------------------------------------------------- |
|
284 // From base class MPhCntMatch |
|
285 // Getter |
|
286 // --------------------------------------------------------------------------- |
|
287 // |
|
288 TPtrC CPhCntContact::FirstName() const |
|
289 { |
|
290 return iContactFields->FirstName(); |
|
291 } |
|
292 |
|
293 // --------------------------------------------------------------------------- |
|
294 // From base class MPhCntMatch |
|
295 // Getter |
|
296 // --------------------------------------------------------------------------- |
|
297 // |
|
298 TPtrC CPhCntContact::LastName() const |
|
299 { |
|
300 return iContactFields->LastName(); |
|
301 } |
|
302 |
|
303 // --------------------------------------------------------------------------- |
|
304 // From base class MPhCntMatch |
|
305 // Getter |
|
306 // --------------------------------------------------------------------------- |
|
307 // |
|
308 TPtrC CPhCntContact::CompanyName() const |
|
309 { |
|
310 return iContactFields->CompanyName(); |
|
311 } |
|
312 |
|
313 // --------------------------------------------------------------------------- |
|
314 // From base class MPhCntMatch |
|
315 // Getter |
|
316 // --------------------------------------------------------------------------- |
|
317 // |
|
318 TPtrC CPhCntContact::Number() const |
|
319 { |
|
320 TPtrC number = iContactFields->Number(); |
|
321 if( FeatureManager::FeatureSupported( KFeatureIdCommonVoip ) ) |
|
322 { |
|
323 if( iMatchedVoipNumber ) |
|
324 { |
|
325 number.Set( *iMatchedVoipNumber ); |
|
326 } |
|
327 } |
|
328 return number; |
|
329 } |
|
330 |
|
331 // --------------------------------------------------------------------------- |
|
332 // Finds a phone number for the requested speed dial position. |
|
333 // --------------------------------------------------------------------------- |
|
334 // |
|
335 TPhCntNumber CPhCntContact::SpeedDialNumber( const TInt aPosition ) |
|
336 { |
|
337 TPhCntNumber contactNumber; |
|
338 const RArray<TPhCntNumber>& allNumbers = AllNumbers(); |
|
339 const TInt count( allNumbers.Count() ); |
|
340 for ( TInt numberIndex = 0; numberIndex < count && contactNumber.Type() == MPhCntMatch::ENone; numberIndex++ ) |
|
341 { |
|
342 TPhCntNumber number( allNumbers[numberIndex] ); |
|
343 if ( number.Position() == aPosition ) |
|
344 { |
|
345 contactNumber.Set( number.Number(), number.Type(), number.Position() ); |
|
346 } |
|
347 } |
|
348 return contactNumber; |
|
349 } |
|
350 |
|
351 // --------------------------------------------------------------------------- |
|
352 // From base class MPhCntMatch |
|
353 // Getter |
|
354 // --------------------------------------------------------------------------- |
|
355 // |
|
356 TPtrC CPhCntContact::PersonalRingingTone() const |
|
357 { |
|
358 return iContactFields->PersonalRingingTone(); |
|
359 } |
|
360 |
|
361 // --------------------------------------------------------------------------- |
|
362 // From base class MPhCntMatch |
|
363 // Getter |
|
364 // --------------------------------------------------------------------------- |
|
365 // |
|
366 CDesCArray& CPhCntContact::AllDtmfNumbers() const |
|
367 { |
|
368 return *iContactFields->AllDtmfNumbers(); |
|
369 } |
|
370 |
|
371 // --------------------------------------------------------------------------- |
|
372 // From base class MPhCntMatch |
|
373 // Determines if this contact belongs to some of the groups |
|
374 // --------------------------------------------------------------------------- |
|
375 // |
|
376 TBool CPhCntContact::BelongsToGroups( |
|
377 const CArrayFix<TContactItemId>& aGroupArray ) const |
|
378 { |
|
379 PRINT( "PhCnt: Contact.BelongsToGroups" ); |
|
380 TBool belongsToGroup = EFalse; |
|
381 MVPbkContactLinkArray* groupLinks = NULL; |
|
382 TRAP_IGNORE( |
|
383 groupLinks = |
|
384 iContactManager.ConvertContactIdsToLinksL( aGroupArray ); |
|
385 belongsToGroup = BelongsToGroupsL( groupLinks ); |
|
386 ); |
|
387 delete groupLinks; |
|
388 return belongsToGroup; |
|
389 } |
|
390 |
|
391 // --------------------------------------------------------------------------- |
|
392 // From base class MPhCntMatch |
|
393 // Getter |
|
394 // --------------------------------------------------------------------------- |
|
395 // |
|
396 HBufC* CPhCntContact::TextToSpeechTextL() const |
|
397 { |
|
398 TPhCntTxtToSpeech txtToSpeech( |
|
399 iContactFields->FirstName(), |
|
400 iContactFields->SecondName(), |
|
401 iContactFields->LastName(), |
|
402 iContactFields->CompanyName(), |
|
403 iContactFields->FirstNamePronunciation(), |
|
404 iContactFields->LastNamePronunciation(), |
|
405 iContactFields->CompanyNamePronunciation(), |
|
406 User::Language() ); |
|
407 |
|
408 HBufC* textToSpeech = NULL; |
|
409 txtToSpeech.GetTextToSpeechL( textToSpeech ); |
|
410 return textToSpeech; |
|
411 } |
|
412 |
|
413 // --------------------------------------------------------------------------- |
|
414 // From base class MPhCntMatch |
|
415 // Getter |
|
416 // --------------------------------------------------------------------------- |
|
417 // |
|
418 TPtrC CPhCntContact::CallImage() const |
|
419 { |
|
420 return iContactFields->CallImage(); |
|
421 } |
|
422 |
|
423 // --------------------------------------------------------------------------- |
|
424 // From base class MPhCntMatch |
|
425 // Getter |
|
426 // --------------------------------------------------------------------------- |
|
427 // |
|
428 TPtrC CPhCntContact::CallText() const |
|
429 { |
|
430 return iContactFields->CallText(); |
|
431 } |
|
432 |
|
433 // --------------------------------------------------------------------------- |
|
434 // From base class MPhCntMatch |
|
435 // Getter |
|
436 // --------------------------------------------------------------------------- |
|
437 // |
|
438 TBool CPhCntContact::HasThumbnailImage() const |
|
439 { |
|
440 return iContactFields->HasThumbnail(); |
|
441 } |
|
442 |
|
443 // --------------------------------------------------------------------------- |
|
444 // Loads thumbnail of this contact. |
|
445 // --------------------------------------------------------------------------- |
|
446 // |
|
447 MPbk2ImageOperation* CPhCntContact::LoadThumbnailL( |
|
448 MPbk2ImageGetObserver& aObserver ) |
|
449 { |
|
450 const MVPbkFieldType* thumbnailFieldType = |
|
451 iContactFields->ThumbnailField(); |
|
452 |
|
453 MPbk2ImageOperation* oper = NULL; |
|
454 if( thumbnailFieldType ) |
|
455 { |
|
456 oper = iContactManager.RetrieveImageL( |
|
457 iContactFields->StoreContact(), |
|
458 *thumbnailFieldType, |
|
459 aObserver ); |
|
460 } |
|
461 else |
|
462 { |
|
463 User::Leave( KErrNotFound ); |
|
464 } |
|
465 return oper; |
|
466 } |
|
467 |
|
468 // --------------------------------------------------------------------------- |
|
469 // Constructor |
|
470 // --------------------------------------------------------------------------- |
|
471 // |
|
472 CPhCntContact::CPhCntContact( |
|
473 MPhCntContactFields* aContactFields, |
|
474 MPhCntContactManager& aContactManager ) : |
|
475 iContactFields( aContactFields ), |
|
476 iContactManager( aContactManager ) |
|
477 { |
|
478 |
|
479 } |
|
480 |
|
481 // --------------------------------------------------------------------------- |
|
482 // Secondphase constructor |
|
483 // --------------------------------------------------------------------------- |
|
484 // |
|
485 void CPhCntContact::ConstructL( ) |
|
486 { |
|
487 iOriginalNumber = KNullDesC().AllocL(); |
|
488 MVPbkContactLink* contactLink = iContactFields->ContactLink(); |
|
489 MVPbkContactLink* clonedLink = NULL; |
|
490 if( contactLink ) |
|
491 { |
|
492 clonedLink = contactLink->CloneLC(); |
|
493 CleanupStack::Pop(); // clonedLink |
|
494 } |
|
495 iContactId = CPhCntVPbkContactId::NewL( clonedLink, iContactManager ); |
|
496 iNumberExtractor = new( ELeave )CCntRawPhoneNumberExtractor(); |
|
497 iNumberExtractor->ConstructL(); |
|
498 FeatureManager::InitializeLibL(); |
|
499 } |
|
500 |
|
501 // --------------------------------------------------------------------------- |
|
502 // Checks if this belongs to any of the groups. |
|
503 // --------------------------------------------------------------------------- |
|
504 // |
|
505 TBool CPhCntContact::BelongsToGroupsL( |
|
506 MVPbkContactLinkArray* aGroups ) const |
|
507 { |
|
508 TBool belongsToGroups = EFalse; |
|
509 if( aGroups ) |
|
510 { |
|
511 MVPbkContactLinkArray* groupsThisContactBelongsTo = |
|
512 iContactFields->ContactGroupsLC(); |
|
513 |
|
514 if( groupsThisContactBelongsTo ) |
|
515 { |
|
516 PRINTF( "PhCnt: Contact.BelongsToGroups.group count.%d", groupsThisContactBelongsTo->Count() ); |
|
517 for( TInt i = 0; i < aGroups->Count() && !belongsToGroups; i++ ) |
|
518 { |
|
519 const MVPbkContactLink& linkToGroup( aGroups->At( i ) ); |
|
520 |
|
521 // Find returns index if found from array. |
|
522 if( groupsThisContactBelongsTo->Find( linkToGroup ) >= 0 ) |
|
523 { |
|
524 belongsToGroups = ETrue; |
|
525 } |
|
526 } |
|
527 CleanupStack::PopAndDestroy(); // groupsThisContactBelongsTo |
|
528 } |
|
529 } |
|
530 return belongsToGroups; |
|
531 } |