|
1 /* |
|
2 * Copyright (c) 2005-2007 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: Provide interface for the client requestin availability class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "musavacontactavailability.h" |
|
21 #include "musavaavailabilityobserver.h" |
|
22 #include "musavasettingsimp.h" |
|
23 #include "musavaobserver.h" |
|
24 #include "muslogger.h" |
|
25 #include "mussettings.h" |
|
26 #include "musavacalleventmonitor.h" |
|
27 |
|
28 #include <CPbkContactItem.h> |
|
29 #include <CPbkContactEngine.h> |
|
30 #include <CPbkFieldInfo.h> |
|
31 #include <TPbkContactItemField.h> |
|
32 #include <cntviewbase.h> |
|
33 #ifdef UNIT_TESTING // if unit testing |
|
34 #include <digia/eunit/eunitdecorators.h> |
|
35 #endif // UNIT_TESTING |
|
36 |
|
37 const TInt KNumberMatchingDigitsRequired = 7; |
|
38 const TInt KContactsArraySize = 10; |
|
39 |
|
40 |
|
41 _LIT( KMusAvaSip, "sip:" ); |
|
42 _LIT( KMusAvaTel, "tel:" ); |
|
43 _LIT( KMusAvaPlus, "+" ); |
|
44 _LIT( KMusAvaAtSign , "@" ); |
|
45 _LIT( KMusEmptyStringSymbol, "" ); |
|
46 _LIT( KMusSpaceSymbol, " " ); |
|
47 _LIT( KMusAvaTestString, "*#" ); |
|
48 |
|
49 |
|
50 CMusAvaContactAvailability* CMusAvaContactAvailability::NewL( |
|
51 MMusAvaAvailabilityObserver& aObserver, |
|
52 CMusAvaSettingsImp& aSettings ) |
|
53 { |
|
54 MUS_LOG( "mus: [MUSAVA] -> CMusAvaContactAvailability::NewL()" ) |
|
55 |
|
56 CMusAvaContactAvailability* self = |
|
57 CMusAvaContactAvailability::NewLC( |
|
58 aObserver, |
|
59 aSettings ); |
|
60 CleanupStack::Pop( self ); |
|
61 |
|
62 MUS_LOG( "mus: [MUSAVA] <- CMusAvaContactAvailability::NewL()" ) |
|
63 return self; |
|
64 } |
|
65 |
|
66 |
|
67 CMusAvaContactAvailability* CMusAvaContactAvailability::NewLC( |
|
68 MMusAvaAvailabilityObserver& aObserver, |
|
69 CMusAvaSettingsImp& aSettings ) |
|
70 { |
|
71 MUS_LOG( "mus: [MUSAVA] -> CMusAvaContactAvailability::NewL()" ) |
|
72 CMusAvaContactAvailability* self = |
|
73 new( ELeave ) CMusAvaContactAvailability( |
|
74 aObserver, |
|
75 aSettings ); |
|
76 CleanupStack::PushL( self ); |
|
77 self->ConstructL(); |
|
78 |
|
79 MUS_LOG( "mus: [MUSAVA] <- CMusAvaContactAvailability::NewL()" ) |
|
80 return self; |
|
81 } |
|
82 |
|
83 |
|
84 CMusAvaContactAvailability::~CMusAvaContactAvailability() |
|
85 { |
|
86 MUS_LOG( "mus: [MUSAVA] -> CMusAvaContactAvailability::\ |
|
87 ~CMusAvaContactAvailability()" ) |
|
88 delete iContactName; |
|
89 iContactName = NULL; |
|
90 if ( iPhoneStatus ) |
|
91 { |
|
92 iPhoneStatus->Cancel(); |
|
93 } |
|
94 delete iPhoneStatus; |
|
95 iPhoneStatus = NULL; |
|
96 MUS_LOG( "mus: [MUSAVA] <- CMusAvaContactAvailability::\ |
|
97 ~CMusAvaContactAvailability()" ) |
|
98 } |
|
99 |
|
100 |
|
101 CMusAvaContactAvailability::CMusAvaContactAvailability( |
|
102 MMusAvaAvailabilityObserver& aObserver, |
|
103 CMusAvaSettingsImp& aSettings ) |
|
104 :CMusAvaAvailability( aObserver ), |
|
105 iContactName( NULL ), |
|
106 iSettings( aSettings ) |
|
107 { |
|
108 } |
|
109 |
|
110 |
|
111 void CMusAvaContactAvailability::ConstructL() |
|
112 { |
|
113 MUS_LOG( "mus: [MUSAVA] -> CMusAvaContactAvailability::ConstructL()" ) |
|
114 iOperatorVariant = MultimediaSharingSettings::OperatorVariantSettingL(); |
|
115 iPhoneStatus = CMusAvaCallEventMonitor::NewL( *this ); |
|
116 MUS_LOG( "mus: [MUSAVA] <- CMusAvaContactAvailability::ConstructL()" ) |
|
117 } |
|
118 |
|
119 |
|
120 // ------------------------------------------------------------------------- |
|
121 // Starts the loopy execution. |
|
122 // ------------------------------------------------------------------------- |
|
123 // |
|
124 void CMusAvaContactAvailability::DoExecuteL() |
|
125 { |
|
126 MUS_LOG( "mus: [MUSAVA] -> CMusAvaContactAvailability::DoExecuteL()" ) |
|
127 iPhoneStatus->StartMonitoringL(); |
|
128 |
|
129 CContactIdArray* idArray = NULL; |
|
130 |
|
131 #ifdef UNIT_TESTING // if unit testing |
|
132 EUNIT_DISABLE_ALLOC_DECORATOR; |
|
133 #endif // UNIT_TESTING |
|
134 CPbkContactEngine* pbkContactEngine = CPbkContactEngine::NewL(); |
|
135 CleanupStack::PushL( pbkContactEngine ); |
|
136 |
|
137 // resolve the name order |
|
138 CContactViewBase& contactView = pbkContactEngine->AllContactsView(); |
|
139 const RContactViewSortOrder& sortOrder = contactView.SortOrderL(); |
|
140 #ifdef UNIT_TESTING // if unit testing |
|
141 EUNIT_ENABLE_ALLOC_DECORATOR; |
|
142 #endif // UNIT_TESTING |
|
143 |
|
144 iBeginWithFirstName = ETrue; |
|
145 TBool foundOrder = EFalse; |
|
146 for( TInt i = 0; i < sortOrder.Count() && !foundOrder; ++i ) |
|
147 { |
|
148 if ( sortOrder[i] == KUidContactFieldFamilyName ) |
|
149 { |
|
150 iBeginWithFirstName = EFalse; |
|
151 foundOrder = ETrue; |
|
152 } |
|
153 else if ( sortOrder[i] == KUidContactFieldGivenName ) |
|
154 { |
|
155 iBeginWithFirstName = ETrue; |
|
156 foundOrder = ETrue; |
|
157 } |
|
158 } |
|
159 |
|
160 CDesCArrayFlat* contactsArray |
|
161 = new ( ELeave ) CDesCArrayFlat( KContactsArraySize ); |
|
162 CleanupStack::PushL( contactsArray ); |
|
163 |
|
164 if ( ContactL( idArray, *pbkContactEngine ) ) |
|
165 { |
|
166 CleanupStack::PushL( idArray ); |
|
167 |
|
168 TInt idArrayCount = idArray->Count(); |
|
169 MUS_LOG1( "mus: [MUSAVA] idArray->Count %d", idArrayCount ) |
|
170 CPbkContactItem* pbkItem = NULL; |
|
171 TPbkFieldId fieldId = ContactIdSearch( *idArray, *pbkContactEngine ); |
|
172 |
|
173 for ( TInt i = 0; i < idArrayCount; i++ ) |
|
174 { |
|
175 MUS_LOG1( "mus: [MUSAVA] i %d", i ) |
|
176 TContactItemId itemId( KErrNotFound ); |
|
177 itemId = ( *idArray )[i]; |
|
178 |
|
179 TRAPD( error, pbkItem = pbkContactEngine->ReadContactL( itemId ) ); |
|
180 |
|
181 if ( !error ) |
|
182 { |
|
183 TBool found = EFalse; |
|
184 if ( fieldId == EPbkFieldIdShareView ) |
|
185 { |
|
186 found = ResolveAddressesL( |
|
187 *pbkItem, contactsArray, EPbkFieldIdShareView ); |
|
188 } |
|
189 else if( fieldId == EPbkFieldIdSIPID) |
|
190 { |
|
191 found = ResolveAddressesL( |
|
192 *pbkItem, contactsArray, EPbkFieldIdSIPID ); |
|
193 } |
|
194 |
|
195 if ( !found ) |
|
196 { |
|
197 PhoneResolutionL( *pbkItem, contactsArray ); |
|
198 } |
|
199 |
|
200 // tbd: causes test case to fail |
|
201 // break; |
|
202 } |
|
203 |
|
204 delete pbkItem; |
|
205 pbkItem = NULL; |
|
206 } |
|
207 |
|
208 idArray->Reset(); |
|
209 CleanupStack::PopAndDestroy( idArray ); |
|
210 } |
|
211 else |
|
212 { |
|
213 ActiveCallL( contactsArray ); |
|
214 } |
|
215 |
|
216 iSettings.SetSipAddressesL( *contactsArray ); |
|
217 |
|
218 contactsArray->Reset(); |
|
219 |
|
220 CleanupStack::PopAndDestroy( contactsArray ); |
|
221 |
|
222 CleanupStack::PopAndDestroy( pbkContactEngine ); |
|
223 |
|
224 SetState( MMusAvaObserver::EMusAvaStatusAvailable ); |
|
225 |
|
226 MUS_LOG( "mus: [MUSAVA] <- CMusAvaContactAvailability::DoExecuteL()" ) |
|
227 } |
|
228 |
|
229 // ------------------------------------------------------------------------- |
|
230 // This function is called when a cs call is connected. |
|
231 // ------------------------------------------------------------------------- |
|
232 // |
|
233 void CMusAvaContactAvailability::CallConnectedL( const TDesC& aTelNumber ) |
|
234 { |
|
235 MUS_LOG( "mus: [MUSAVA] \ |
|
236 -> CMusAvaContactAvailability::CallConnectedL()" ) |
|
237 |
|
238 iSettings.SetTelNumberL(aTelNumber); |
|
239 DoExecuteL(); |
|
240 |
|
241 MUS_LOG( "mus: [MUSAVA] \ |
|
242 <- CMusAvaContactAvailability::CallConnectedL()" ) |
|
243 } |
|
244 void CMusAvaContactAvailability::ConferenceCallL() |
|
245 { |
|
246 } |
|
247 |
|
248 |
|
249 // ------------------------------------------------------------------------- |
|
250 // This function is called when a cs call goes hold |
|
251 // ------------------------------------------------------------------------- |
|
252 // |
|
253 void CMusAvaContactAvailability::CallHoldL( const TDesC& /*aTelNumber*/ ) |
|
254 { |
|
255 } |
|
256 |
|
257 |
|
258 // ------------------------------------------------------------------------- |
|
259 // This function is called when a cs call goes into a state |
|
260 // that is not connected. |
|
261 // ------------------------------------------------------------------------- |
|
262 // |
|
263 void CMusAvaContactAvailability::NoActiveCallL() |
|
264 { |
|
265 } |
|
266 |
|
267 // ------------------------------------------------------------------------- |
|
268 // |
|
269 // ------------------------------------------------------------------------- |
|
270 // |
|
271 TBool CMusAvaContactAvailability::ActiveCallL( CDesCArrayFlat*& aContactsArray ) |
|
272 { |
|
273 MUS_LOG( "mus: [MUSAVA] -> CMusAvaContactAvailability::ActiveCallL()" ) |
|
274 |
|
275 const TDesC& phoneNumber = iSettings.TelNumber(); |
|
276 TInt retval = EFalse; |
|
277 |
|
278 if ( phoneNumber.Length() > 0 && |
|
279 ( iOperatorVariant == MusSettingsKeys::EOperatorSpecific || |
|
280 phoneNumber.Left(1).Compare( KMusAvaPlus() ) == 0 ) ) |
|
281 { |
|
282 MUS_LOG( "mus: [MUSAVA] Phone number found with + prefix \ |
|
283 (or operator variant)" ) |
|
284 // No, it doesn't, so add the prefix to the new address. |
|
285 MUS_LOG( "mus: [MUSAVA] Prefix to the new address is added" ) |
|
286 //Create contact array |
|
287 //Create tel bufer |
|
288 HBufC* tmpDescriptor = HBufC::NewLC( KMusAvaTel().Length() + |
|
289 phoneNumber.Length() ); |
|
290 tmpDescriptor->Des().Append( KMusAvaTel() ); |
|
291 tmpDescriptor->Des().Append( phoneNumber ); |
|
292 //Add to array |
|
293 aContactsArray->AppendL( tmpDescriptor->Des() ); |
|
294 CleanupStack::PopAndDestroy( tmpDescriptor ); |
|
295 retval = ETrue; |
|
296 } |
|
297 else |
|
298 { |
|
299 MUS_LOG( "mus: [MUSAVA] Phone number not found " ) |
|
300 retval = EFalse; |
|
301 } |
|
302 MUS_LOG1( "mus: [MUSAVA] <- CMusAvaContactAvailability::\ |
|
303 ActiveCallL return %d", retval ) |
|
304 |
|
305 return retval; |
|
306 } |
|
307 |
|
308 |
|
309 // ------------------------------------------------------------------------- |
|
310 // |
|
311 // ------------------------------------------------------------------------- |
|
312 // |
|
313 TBool CMusAvaContactAvailability::ContactL( |
|
314 CContactIdArray*& aContactIdArray, |
|
315 CPbkContactEngine& aPbkContactEngine ) |
|
316 { |
|
317 MUS_LOG( "mus: [MUSAVA] -> CMusAvaContactAvailability::ContactL()" ) |
|
318 CPbkContactItem* pbkContactItem = NULL; |
|
319 |
|
320 TInt conRes = EFalse; |
|
321 |
|
322 TInt err = ContactArrayL( aContactIdArray, aPbkContactEngine ); |
|
323 if ( !err ) |
|
324 { |
|
325 err = ContactItem( *aContactIdArray, pbkContactItem, aPbkContactEngine ); |
|
326 // NOTE: KErrNotSupported means there is more than one contact id. |
|
327 if ( err == KErrNotSupported ) |
|
328 { |
|
329 iSettings.SetContactId( KErrNotSupported ); |
|
330 conRes = ETrue; |
|
331 } |
|
332 else if( err != KErrNone ) |
|
333 { |
|
334 MUS_LOG( "mus: [MUSAVA] No contact item found; contact id = \ |
|
335 KErrNotFound" ) |
|
336 conRes = EFalse; |
|
337 } |
|
338 else |
|
339 { |
|
340 TContactItemId itemId = pbkContactItem->Id(); |
|
341 MUS_LOG1( "mus: [MUSAVA] Setting contact id to be %d", |
|
342 itemId ) |
|
343 CleanupStack::PushL( pbkContactItem ); |
|
344 iSettings.SetContactId( itemId ); |
|
345 UpdateContactNameL( pbkContactItem->ContactItem() ); |
|
346 CleanupStack::Pop( pbkContactItem ); |
|
347 conRes = ETrue; |
|
348 } |
|
349 } |
|
350 MUS_LOG1( "mus: [MUSAVA] <- CMusAvaContactAvailability::\ |
|
351 ContactL return %d", conRes ) |
|
352 |
|
353 delete pbkContactItem; |
|
354 pbkContactItem = NULL; |
|
355 |
|
356 return conRes; |
|
357 } |
|
358 |
|
359 |
|
360 // ------------------------------------------------------------------------- |
|
361 // |
|
362 // ------------------------------------------------------------------------- |
|
363 // |
|
364 void CMusAvaContactAvailability::UpdateContactNameL( |
|
365 CContactItem& aContactItem ) |
|
366 { |
|
367 MUS_LOG( "mus: [MUSAVA ] -> CMusAvaContactAvailability::\ |
|
368 UpdateContactName" ) |
|
369 //TBuf<KMusNameFieldMaxLength> givenName; |
|
370 //TBuf<KMusNameFieldMaxLength> familyName; |
|
371 |
|
372 HBufC* givenName = NULL; |
|
373 HBufC* familyName = NULL; |
|
374 |
|
375 delete iContactName; |
|
376 iContactName = NULL; |
|
377 iContactName = HBufC::NewL( 0 ); |
|
378 |
|
379 CContactItemFieldSet& fieldSet = aContactItem.CardFields(); |
|
380 |
|
381 TInt pos = fieldSet.Find( KUidContactFieldGivenName ); |
|
382 if ( pos != KErrNotFound ) |
|
383 { |
|
384 CContactItemField& itemField = fieldSet[pos]; |
|
385 //givenName = HBufC::NewL( itemField.TextStorage()->Text().Length() ); |
|
386 |
|
387 //givenName.Copy( itemField.TextStorage()->Text().Alloc() ); |
|
388 givenName = itemField.TextStorage()->Text().AllocLC(); |
|
389 |
|
390 } |
|
391 else |
|
392 { |
|
393 //givenName = KMusEmptyStringSymbol; |
|
394 givenName = KMusEmptyStringSymbol().AllocLC(); |
|
395 } |
|
396 |
|
397 pos = fieldSet.Find( KUidContactFieldFamilyName ); |
|
398 if ( pos != KErrNotFound ) |
|
399 { |
|
400 CContactItemField& itemField = fieldSet[pos]; |
|
401 //familyName = HBufC::NewL( itemField.TextStorage()->Text().Length() ); |
|
402 //familyName.Copy( field.TextStorage()->Text() ); |
|
403 familyName = itemField.TextStorage()->Text().AllocLC(); |
|
404 } |
|
405 else |
|
406 { |
|
407 familyName = KMusEmptyStringSymbol().AllocLC(); |
|
408 } |
|
409 |
|
410 TInt strLength = NULL; |
|
411 TBool bothNames = givenName->Length() > 0 && familyName->Length() > 0; |
|
412 |
|
413 if ( bothNames ) |
|
414 { |
|
415 strLength = givenName->Length() + |
|
416 KMusSpaceSymbol().Length() + |
|
417 familyName->Length(); |
|
418 } |
|
419 else |
|
420 { |
|
421 strLength = givenName->Length() + familyName->Length(); |
|
422 } |
|
423 |
|
424 if ( strLength > iContactName->Length() ) |
|
425 { |
|
426 iContactName = iContactName->ReAllocL( strLength ); |
|
427 } |
|
428 |
|
429 if ( strLength > 1 ) |
|
430 { |
|
431 TPtr ptr = iContactName->Des(); |
|
432 if ( iBeginWithFirstName ) |
|
433 { |
|
434 if ( bothNames ) |
|
435 { |
|
436 ptr.Append( givenName->Des() ); |
|
437 ptr.Append( KMusSpaceSymbol ); |
|
438 ptr.Append( familyName->Des() ); |
|
439 } |
|
440 else |
|
441 { |
|
442 ptr.Append( givenName->Des() ); |
|
443 ptr.Append( familyName->Des() ); |
|
444 } |
|
445 } |
|
446 else |
|
447 { |
|
448 if ( bothNames ) |
|
449 { |
|
450 ptr.Append( familyName->Des() ); |
|
451 ptr.Append( KMusSpaceSymbol ); |
|
452 ptr.Append( givenName->Des() ); |
|
453 } |
|
454 else |
|
455 { |
|
456 ptr.Append( familyName->Des() ); |
|
457 ptr.Append( givenName->Des() ); |
|
458 } |
|
459 } |
|
460 } |
|
461 |
|
462 CleanupStack::PopAndDestroy( familyName ); |
|
463 CleanupStack::PopAndDestroy( givenName ); |
|
464 |
|
465 TRAP_IGNORE( iSettings.SetContactNameL( iContactName->Des() ) ) |
|
466 |
|
467 MUS_LOG( "mus: [MUSAVA ] <- CMusAvaContactAvailability::\ |
|
468 UpdateContactName" ) |
|
469 } |
|
470 |
|
471 |
|
472 // ------------------------------------------------------------------------- |
|
473 // |
|
474 // ------------------------------------------------------------------------- |
|
475 // |
|
476 TInt CMusAvaContactAvailability::ContactArrayL( |
|
477 CContactIdArray*& aContactIdArray, |
|
478 CPbkContactEngine& aPbkContactEngine ) |
|
479 { |
|
480 MUS_LOG( "mus: [MUSAVA] -> CMusAvaContactAvailability::ContactArrayL()" ) |
|
481 |
|
482 const TDesC& phoneNumber = iSettings.TelNumber(); |
|
483 TInt retval = KErrNotFound; |
|
484 |
|
485 if ( phoneNumber.Length() > 0 ) |
|
486 { |
|
487 MUS_LOG( "mus: [MUSAVA] Phone number found " ) |
|
488 // Instantiate a PhonebookContactEngine object, which represents a |
|
489 // connection to the Phonebook contact database: |
|
490 #ifdef UNIT_TESTING // if unit testing |
|
491 EUNIT_DISABLE_ALLOC_DECORATOR; |
|
492 #endif // UNIT_TESTING |
|
493 CContactIdArray* tmpContactIdArray = |
|
494 aPbkContactEngine.MatchPhoneNumberL( |
|
495 phoneNumber, |
|
496 KNumberMatchingDigitsRequired ); |
|
497 #ifdef UNIT_TESTING // if unit testing |
|
498 EUNIT_ENABLE_ALLOC_DECORATOR; |
|
499 #endif // UNIT_TESTING |
|
500 if ( tmpContactIdArray->Count() > 0 ) |
|
501 { |
|
502 aContactIdArray = tmpContactIdArray; |
|
503 retval = KErrNone; |
|
504 } |
|
505 else |
|
506 { |
|
507 tmpContactIdArray->Reset(); |
|
508 delete tmpContactIdArray; |
|
509 MUS_LOG( |
|
510 "mus: [MUSAVA] Phone number not found in CPbkContactEngine" ) |
|
511 } |
|
512 } |
|
513 else |
|
514 { |
|
515 MUS_LOG( "mus: [MUSAVA] Phone number not found " ) |
|
516 } |
|
517 |
|
518 MUS_LOG1( "mus: [MUSAVA] <- CMusAvaContactAvailability::\ |
|
519 ContactArrayL return %d", retval ) |
|
520 |
|
521 return retval; |
|
522 } |
|
523 |
|
524 |
|
525 // ------------------------------------------------------------------------- |
|
526 // |
|
527 // ------------------------------------------------------------------------- |
|
528 // |
|
529 TInt CMusAvaContactAvailability::ContactItem( |
|
530 CContactIdArray& aContactIdArray, |
|
531 CPbkContactItem*& aPbkContactItem, |
|
532 CPbkContactEngine& aPbkContactEngine ) |
|
533 { |
|
534 MUS_LOG( "mus: [MUSAVA] -> CMusAvaContactAvailability::ContactItem()" ) |
|
535 CPbkContactItem* pbkItem = NULL; |
|
536 TInt retval = KErrNotFound; |
|
537 TInt contactIdsCount = aContactIdArray.Count(); |
|
538 |
|
539 if( contactIdsCount > 1 ) |
|
540 { |
|
541 // NOTE: KErrNotSupported means there is more than one contact id. |
|
542 MUS_LOG( "mus: [MUSAVA] More than one Contact ID found." ) |
|
543 retval = KErrNotSupported; |
|
544 } |
|
545 else if ( contactIdsCount == 1 ) |
|
546 { |
|
547 // Contact card whose phone number matches that of the other party |
|
548 // was found. The ID(s) of the contacts are recorded in iIdArray. |
|
549 MUS_LOG( "mus: [MUSAVA] Contact ID found." ) |
|
550 |
|
551 TContactItemId itemId( KErrNotFound ); |
|
552 |
|
553 MUS_LOG1( "mus: [MUSAVA] ID array has <%d> elements", |
|
554 contactIdsCount ) |
|
555 // iterate through the contact cards we consider as belonging to |
|
556 // the other party, that is, those saved in iIdArray: |
|
557 for ( TInt i = 0; i < contactIdsCount; i++ ) |
|
558 { |
|
559 itemId = ( aContactIdArray )[i]; |
|
560 MUS_LOG2( "mus: [MUSAVA] Current array index == <%d>, \ |
|
561 contact ID == <%d>", i, itemId ) |
|
562 TRAPD( pbkFailure, pbkItem = |
|
563 aPbkContactEngine.ReadContactL( itemId ) ); |
|
564 |
|
565 if ( pbkFailure ) |
|
566 { |
|
567 // Contact lookup failed. |
|
568 MUS_LOG1( "mus: [MUSAVA] Leave code <%d> occurred at call \ |
|
569 of ReadContactL.", pbkFailure ) |
|
570 } |
|
571 else |
|
572 { |
|
573 aPbkContactItem = pbkItem; |
|
574 retval = KErrNone; |
|
575 } |
|
576 } |
|
577 } |
|
578 else |
|
579 { |
|
580 MUS_LOG( "mus: [MUSAVA] No contact card whose phone number\ |
|
581 matches that of the other party" ) |
|
582 } |
|
583 |
|
584 MUS_LOG1( "mus: [MUSAVA] <- CMusAvaContactAvailability::\ |
|
585 ContactItem() return %d", retval ) |
|
586 |
|
587 return retval; |
|
588 } |
|
589 |
|
590 // ------------------------------------------------------------------------- |
|
591 // |
|
592 // ------------------------------------------------------------------------- |
|
593 // |
|
594 TBool CMusAvaContactAvailability::PhoneResolutionL( CPbkContactItem& aPbkItem, |
|
595 CDesCArrayFlat*& aContactsArray ) |
|
596 { |
|
597 MUS_LOG( "mus: [MUSAVA] -> CMusAvaContactAvailability::PhoneResolutionL()" ) |
|
598 TInt retval = ETrue; |
|
599 if ( ResolvePhoneContactL( aPbkItem, aContactsArray ) ) |
|
600 { |
|
601 MUS_LOG( "mus: [MUSAVA] Stop Execution" ) |
|
602 } |
|
603 else |
|
604 { |
|
605 if ( ActiveCallL( aContactsArray ) ) |
|
606 { |
|
607 MUS_LOG( "mus: [MUSAVA] Stop Execution" ) |
|
608 } |
|
609 else |
|
610 { |
|
611 MUS_LOG( "mus: [MUSAVA] Stop Execution" ) |
|
612 retval = EFalse; |
|
613 } |
|
614 } |
|
615 |
|
616 MUS_LOG1( "mus: [MUSAVA] <- CMusAvaContactAvailability::\ |
|
617 PhoneResolutionL() return %d", retval ) |
|
618 return retval; |
|
619 } |
|
620 |
|
621 |
|
622 // ------------------------------------------------------------------------- |
|
623 // |
|
624 // ------------------------------------------------------------------------- |
|
625 // |
|
626 TBool CMusAvaContactAvailability::ContactId( CPbkContactItem& aPbkItem, |
|
627 TPbkFieldId aTPbkFieldId ) |
|
628 { |
|
629 MUS_LOG( "mus: [MUSAVA] -> CMusAvaContactAvailability::ContactId()" ) |
|
630 |
|
631 CPbkFieldArray& fieldArray = aPbkItem.CardFields(); |
|
632 TPbkContactItemField itemField; |
|
633 TBool returnValue = EFalse; |
|
634 |
|
635 // Get the number of detail fields of the phonebook contact item. |
|
636 const TInt fieldCount( fieldArray.Count() ); |
|
637 |
|
638 for ( TInt index = 0; index < fieldCount && returnValue == EFalse; |
|
639 index++ ) |
|
640 { |
|
641 itemField = fieldArray.At( index ); |
|
642 |
|
643 if ( itemField.FieldInfo().Match( aTPbkFieldId ) && |
|
644 itemField.Text().Find( KMusAvaAtSign() ) != KErrNotFound ) |
|
645 { |
|
646 returnValue = ETrue; |
|
647 MUS_LOG( "mus: [MUSAVA] Contact id found" ) |
|
648 } |
|
649 } |
|
650 MUS_LOG1( "mus: [MUSAVA] <- CMusAvaContactAvailability::\ |
|
651 ContactId() return %d", returnValue ) |
|
652 return returnValue; |
|
653 } |
|
654 |
|
655 |
|
656 // ------------------------------------------------------------------------- |
|
657 // |
|
658 // ------------------------------------------------------------------------- |
|
659 // |
|
660 TPbkFieldId CMusAvaContactAvailability::ContactIdSearch( |
|
661 CContactIdArray& aContactIdArray, |
|
662 CPbkContactEngine& aPbkContactEngine ) |
|
663 { |
|
664 MUS_LOG( "mus: [MUSAVA] -> CMusAvaContactAvailability::\ |
|
665 ContactIdSearch()" ) |
|
666 |
|
667 TInt contactIdsCount = aContactIdArray.Count(); |
|
668 MUS_LOG1( "mus: [MUSAVA] aContactIdArray.Count %d", \ |
|
669 contactIdsCount ) |
|
670 |
|
671 CPbkContactItem* pbkItem = NULL; |
|
672 TPbkFieldId retFieldId = EPbkFieldIdNone; |
|
673 |
|
674 for ( TInt i = 0; |
|
675 i < contactIdsCount && retFieldId == EPbkFieldIdNone; |
|
676 i++ ) |
|
677 { |
|
678 MUS_LOG1( "mus: [MUSAVA] i %d", i ) |
|
679 TContactItemId itemId( KErrNotFound ); |
|
680 itemId = ( aContactIdArray )[i]; |
|
681 |
|
682 #ifdef UNIT_TESTING // if unit testing |
|
683 EUNIT_DISABLE_ALLOC_DECORATOR; |
|
684 #endif // UNIT_TESTING |
|
685 TRAPD( error, pbkItem = aPbkContactEngine.ReadContactL( itemId ) ) |
|
686 #ifdef UNIT_TESTING // if unit testing |
|
687 EUNIT_ENABLE_ALLOC_DECORATOR; |
|
688 #endif // UNIT_TESTING |
|
689 if ( error != KErrNone ) |
|
690 { |
|
691 return retFieldId; |
|
692 } |
|
693 if ( ContactId( *pbkItem, EPbkFieldIdShareView ) ) |
|
694 { |
|
695 MUS_LOG( "mus: [MUSAVA] Contact have a prefix = \ |
|
696 EPbkFieldIdShareView" ) |
|
697 delete pbkItem; |
|
698 retFieldId = EPbkFieldIdShareView; |
|
699 } |
|
700 else if ( ContactId( *pbkItem, EPbkFieldIdSIPID ) ) |
|
701 { |
|
702 MUS_LOG( "mus: [MUSAVA] Contact have a prefix = \ |
|
703 EPbkFieldIdSIPID" ) |
|
704 delete pbkItem; |
|
705 retFieldId = EPbkFieldIdSIPID; |
|
706 } |
|
707 else if ( ContactId( *pbkItem, EPbkFieldIdPhoneNumberGeneral ) ) |
|
708 { |
|
709 // this part never run!!!! |
|
710 MUS_LOG( "mus: [MUSAVA] Contact have a prefix = \ |
|
711 EPbkFieldIdPhoneNumberGeneral" ) |
|
712 delete pbkItem; |
|
713 retFieldId = EPbkFieldIdPhoneNumberGeneral; |
|
714 } |
|
715 else |
|
716 { |
|
717 MUS_LOG( "mus: [MUSAVA] Contact have no prefix " ) |
|
718 delete pbkItem; |
|
719 } |
|
720 } |
|
721 return retFieldId; |
|
722 } |
|
723 |
|
724 |
|
725 // ------------------------------------------------------------------------- |
|
726 // |
|
727 // ------------------------------------------------------------------------- |
|
728 // |
|
729 TBool CMusAvaContactAvailability::ResolveAddressesL( CPbkContactItem& aPbkItem, |
|
730 CDesCArrayFlat*& aContactsArray, |
|
731 TPbkFieldId aTPbkFieldId ) |
|
732 { |
|
733 MUS_LOG( "mus: [MUSAVA] -> CMusAvaContactAvailability::\ |
|
734 ResolveAddressesL()" ) |
|
735 |
|
736 CPbkFieldArray& fieldArray = aPbkItem.CardFields(); |
|
737 TPbkContactItemField itemField; |
|
738 HBufC* tmpDescriptor( NULL ); |
|
739 TBool returnValue( EFalse ); |
|
740 |
|
741 // Get the number of detail fields of the phonebook contact item. |
|
742 const TInt fieldCount( fieldArray.Count() ); |
|
743 |
|
744 for ( TInt index = 0; index < fieldCount; index++ ) |
|
745 { |
|
746 itemField = fieldArray.At( index ); |
|
747 |
|
748 if ( itemField.FieldInfo().Match( aTPbkFieldId ) && |
|
749 itemField.Text().Find( KMusAvaAtSign() ) != KErrNotFound && |
|
750 ( iOperatorVariant != MusSettingsKeys::EOperatorSpecific || |
|
751 itemField.Text().Find( KMusAvaTestString() ) != KErrNotFound ) ) |
|
752 { |
|
753 returnValue = ETrue; |
|
754 MUS_LOG( "mus: [MUSAVA] Contact id found" ) |
|
755 |
|
756 HBufC* sipAddress; |
|
757 if ( iOperatorVariant == MusSettingsKeys::EOperatorSpecific ) |
|
758 { |
|
759 sipAddress = HBufC::NewLC( itemField.Text().Length() - |
|
760 KMusAvaTestString().Length() ); |
|
761 TInt pos = itemField.Text().Find( KMusAvaTestString() ); |
|
762 sipAddress->Des().Append( itemField.Text().Left( pos ) ); |
|
763 sipAddress->Des().Append( itemField.Text().Right( |
|
764 itemField.Text().Length() - |
|
765 pos - KMusAvaTestString().Length() ) ); |
|
766 } |
|
767 else |
|
768 { |
|
769 sipAddress = itemField.Text().AllocLC(); |
|
770 } |
|
771 |
|
772 if ( sipAddress->Find( KMusAvaSip() ) == KErrNotFound ) |
|
773 { |
|
774 // No, it doesn't, so add the prefix to the new address. |
|
775 MUS_LOG( "mus: [MUSAVA] Prefix to the new address is added" ) |
|
776 tmpDescriptor = HBufC::NewLC( KMusAvaSip().Length() + |
|
777 sipAddress->Length() ); |
|
778 tmpDescriptor->Des().Append( KMusAvaSip() ); |
|
779 tmpDescriptor->Des().Append( *sipAddress ); |
|
780 // if multiple contact have same phone number then |
|
781 // sip address can be repeated . To avoid this check |
|
782 // whether sip address exist already in array |
|
783 // it not exist then add it to array. |
|
784 if(! IsExistAlready(*aContactsArray,*tmpDescriptor)) |
|
785 { |
|
786 aContactsArray->AppendL( *tmpDescriptor ); |
|
787 } |
|
788 CleanupStack::PopAndDestroy( tmpDescriptor ); |
|
789 } |
|
790 else |
|
791 { |
|
792 MUS_LOG( "mus: [MUSAVA] Contact have a prefix" ) |
|
793 // if multiple contact have same phone number then |
|
794 // sip address can be repeated . To avoid this check |
|
795 // whether sip address exist already in array |
|
796 // it not exist then add it to array. |
|
797 if(! IsExistAlready(*aContactsArray,*sipAddress)) |
|
798 { |
|
799 aContactsArray->AppendL( *sipAddress ); |
|
800 } |
|
801 } |
|
802 |
|
803 CleanupStack::PopAndDestroy( sipAddress ); |
|
804 } |
|
805 } |
|
806 MUS_LOG1( "mus: [MUSAVA] <- CMusAvaContactAvailability::\ |
|
807 ResolveAddressesL() return %d", returnValue ) |
|
808 return returnValue; |
|
809 } |
|
810 |
|
811 |
|
812 // ------------------------------------------------------------------------- |
|
813 // |
|
814 // ------------------------------------------------------------------------- |
|
815 // |
|
816 TBool CMusAvaContactAvailability::ResolvePhoneContactL( |
|
817 CPbkContactItem& aPbkItem, |
|
818 CDesCArrayFlat*& aContactsArray ) |
|
819 { |
|
820 MUS_LOG( "mus: [MUSAVA] -> CMusAvaContactAvailability::\ |
|
821 ResolvePhoneContactL()" ) |
|
822 CPbkFieldArray& fieldArray = aPbkItem.CardFields(); |
|
823 TPbkContactItemField itemField; |
|
824 HBufC* tmpDescriptor( NULL ); |
|
825 TBool returnValue = EFalse; |
|
826 |
|
827 // Get the number of detail fields of the phonebook contact item. |
|
828 const TInt fieldCount( fieldArray.Count() ); |
|
829 |
|
830 for ( TInt index = 0; index < fieldCount; index++ ) |
|
831 { |
|
832 itemField = fieldArray.At( index ); |
|
833 |
|
834 if ( itemField.FieldInfo().IsPhoneNumberField() && |
|
835 ( iOperatorVariant == MusSettingsKeys::EOperatorSpecific || |
|
836 itemField.Text().Left(1) == KMusAvaPlus() ) ) |
|
837 { |
|
838 MUS_LOG( "mus: [MUSAVA] Contact id found" ) |
|
839 // No, it doesn't, so add the prefix to the new address. |
|
840 MUS_LOG( "mus: [MUSAVA] Prefix to the new address is added" ) |
|
841 tmpDescriptor = HBufC::NewLC( KMusAvaTel().Length() + |
|
842 itemField.Text().Length() ); |
|
843 tmpDescriptor->Des().Append( KMusAvaTel() ); |
|
844 tmpDescriptor->Des().Append( itemField.Text() ); |
|
845 aContactsArray->AppendL( *tmpDescriptor ); |
|
846 CleanupStack::PopAndDestroy( tmpDescriptor ); |
|
847 returnValue = ETrue; |
|
848 } |
|
849 } |
|
850 |
|
851 MUS_LOG( "mus: [MUSAVA] <- CMusAvaContactAvailability::\ |
|
852 ResolvePhoneContactL()" ) |
|
853 return returnValue; |
|
854 } |
|
855 |
|
856 |
|
857 MMusAvaObserver::TAvailabilityName CMusAvaContactAvailability::Name() |
|
858 { |
|
859 return MMusAvaObserver::EMusAvaNameContactStatus; |
|
860 } |
|
861 |
|
862 |
|
863 // ------------------------------------------------------------------------- |
|
864 // Checks that whether aDesItem present in aDesArray. |
|
865 // Utility function used to avoid dublication. |
|
866 // ------------------------------------------------------------------------- |
|
867 // |
|
868 TBool CMusAvaContactAvailability::IsExistAlready(const MDesCArray& aDesArray, |
|
869 const TDesC& aDesItem) |
|
870 { |
|
871 for ( TInt i=0;i<aDesArray.MdcaCount();i++) |
|
872 { |
|
873 if (! aDesArray.MdcaPoint(i).Compare( aDesItem ) ) |
|
874 { |
|
875 return ETrue; |
|
876 } |
|
877 } |
|
878 return EFalse; |
|
879 } |