101 // ------------------------------------------------------------------------- |
122 // ------------------------------------------------------------------------- |
102 // |
123 // |
103 void CMusAvaContactAvailability::DoExecuteL() |
124 void CMusAvaContactAvailability::DoExecuteL() |
104 { |
125 { |
105 MUS_LOG( "mus: [MUSAVA] -> CMusAvaContactAvailability::DoExecuteL()" ) |
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 } |
106 |
159 |
107 CDesCArrayFlat* contactsArray |
160 CDesCArrayFlat* contactsArray |
108 = new ( ELeave ) CDesCArrayFlat( KContactsArraySize ); |
161 = new ( ELeave ) CDesCArrayFlat( KContactsArraySize ); |
109 CleanupStack::PushL( contactsArray ); |
162 CleanupStack::PushL( contactsArray ); |
110 |
163 |
111 ActiveCallL( contactsArray ); |
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 } |
112 |
215 |
113 iSettings.SetSipAddressesL( *contactsArray ); |
216 iSettings.SetSipAddressesL( *contactsArray ); |
114 |
217 |
115 contactsArray->Reset(); |
218 contactsArray->Reset(); |
116 |
219 |
117 CleanupStack::PopAndDestroy( contactsArray ); |
220 CleanupStack::PopAndDestroy( contactsArray ); |
118 |
221 |
|
222 CleanupStack::PopAndDestroy( pbkContactEngine ); |
|
223 |
119 SetState( MMusAvaObserver::EMusAvaStatusAvailable ); |
224 SetState( MMusAvaObserver::EMusAvaStatusAvailable ); |
120 |
225 |
121 MUS_LOG( "mus: [MUSAVA] <- CMusAvaContactAvailability::DoExecuteL()" ) |
226 MUS_LOG( "mus: [MUSAVA] <- CMusAvaContactAvailability::DoExecuteL()" ) |
122 } |
227 } |
123 |
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 void CMusAvaContactAvailability::ConferenceCallLTerminated () |
|
269 { |
|
270 } |
124 |
271 |
125 // ------------------------------------------------------------------------- |
272 // ------------------------------------------------------------------------- |
126 // |
273 // |
127 // ------------------------------------------------------------------------- |
274 // ------------------------------------------------------------------------- |
128 // |
275 // |
152 //Add to array |
297 //Add to array |
153 aContactsArray->AppendL( tmpDescriptor->Des() ); |
298 aContactsArray->AppendL( tmpDescriptor->Des() ); |
154 CleanupStack::PopAndDestroy( tmpDescriptor ); |
299 CleanupStack::PopAndDestroy( tmpDescriptor ); |
155 retval = ETrue; |
300 retval = ETrue; |
156 } |
301 } |
157 else if ( addressesCount > 0 ) |
|
158 { |
|
159 MUS_LOG1( "mus: [MUSAVA] addresses.MdcaCount() %d", |
|
160 addressesCount ) |
|
161 const TDesC& sipAddress = addresses.MdcaPoint( 0 ); |
|
162 MUS_LOG_TDESC( "mus: [MUSAVA] SIP Address: ", |
|
163 sipAddress ) |
|
164 aContactsArray->AppendL( sipAddress ); |
|
165 retval = ETrue; |
|
166 } |
|
167 else |
302 else |
168 { |
303 { |
169 MUS_LOG( "mus: [MUSAVA] Phone number or SIP URL not found " ) |
304 MUS_LOG( "mus: [MUSAVA] Phone number not found " ) |
170 retval = EFalse; |
305 retval = EFalse; |
171 } |
306 } |
172 MUS_LOG1( "mus: [MUSAVA] <- CMusAvaContactAvailability::\ |
307 MUS_LOG1( "mus: [MUSAVA] <- CMusAvaContactAvailability::\ |
173 ActiveCallL return %d", retval ) |
308 ActiveCallL return %d", retval ) |
174 |
309 |
175 return retval; |
310 return retval; |
176 } |
311 } |
177 |
312 |
|
313 |
|
314 // ------------------------------------------------------------------------- |
|
315 // |
|
316 // ------------------------------------------------------------------------- |
|
317 // |
|
318 TBool CMusAvaContactAvailability::ContactL( |
|
319 CContactIdArray*& aContactIdArray, |
|
320 CPbkContactEngine& aPbkContactEngine ) |
|
321 { |
|
322 MUS_LOG( "mus: [MUSAVA] -> CMusAvaContactAvailability::ContactL()" ) |
|
323 CPbkContactItem* pbkContactItem = NULL; |
|
324 |
|
325 TInt conRes = EFalse; |
|
326 |
|
327 TInt err = ContactArrayL( aContactIdArray, aPbkContactEngine ); |
|
328 if ( !err ) |
|
329 { |
|
330 err = ContactItem( *aContactIdArray, pbkContactItem, aPbkContactEngine ); |
|
331 // NOTE: KErrNotSupported means there is more than one contact id. |
|
332 if ( err == KErrNotSupported ) |
|
333 { |
|
334 iSettings.SetContactId( KErrNotSupported ); |
|
335 conRes = ETrue; |
|
336 } |
|
337 else if( err != KErrNone ) |
|
338 { |
|
339 MUS_LOG( "mus: [MUSAVA] No contact item found; contact id = \ |
|
340 KErrNotFound" ) |
|
341 conRes = EFalse; |
|
342 } |
|
343 else |
|
344 { |
|
345 TContactItemId itemId = pbkContactItem->Id(); |
|
346 MUS_LOG1( "mus: [MUSAVA] Setting contact id to be %d", |
|
347 itemId ) |
|
348 CleanupStack::PushL( pbkContactItem ); |
|
349 iSettings.SetContactId( itemId ); |
|
350 UpdateContactNameL( pbkContactItem->ContactItem() ); |
|
351 CleanupStack::Pop( pbkContactItem ); |
|
352 conRes = ETrue; |
|
353 } |
|
354 } |
|
355 MUS_LOG1( "mus: [MUSAVA] <- CMusAvaContactAvailability::\ |
|
356 ContactL return %d", conRes ) |
|
357 |
|
358 delete pbkContactItem; |
|
359 pbkContactItem = NULL; |
|
360 |
|
361 return conRes; |
|
362 } |
|
363 |
|
364 |
|
365 // ------------------------------------------------------------------------- |
|
366 // |
|
367 // ------------------------------------------------------------------------- |
|
368 // |
|
369 void CMusAvaContactAvailability::UpdateContactNameL( |
|
370 CContactItem& aContactItem ) |
|
371 { |
|
372 MUS_LOG( "mus: [MUSAVA ] -> CMusAvaContactAvailability::\ |
|
373 UpdateContactName" ) |
|
374 //TBuf<KMusNameFieldMaxLength> givenName; |
|
375 //TBuf<KMusNameFieldMaxLength> familyName; |
|
376 |
|
377 HBufC* givenName = NULL; |
|
378 HBufC* familyName = NULL; |
|
379 |
|
380 delete iContactName; |
|
381 iContactName = NULL; |
|
382 iContactName = HBufC::NewL( 0 ); |
|
383 |
|
384 CContactItemFieldSet& fieldSet = aContactItem.CardFields(); |
|
385 |
|
386 TInt pos = fieldSet.Find( KUidContactFieldGivenName ); |
|
387 if ( pos != KErrNotFound ) |
|
388 { |
|
389 CContactItemField& itemField = fieldSet[pos]; |
|
390 //givenName = HBufC::NewL( itemField.TextStorage()->Text().Length() ); |
|
391 |
|
392 //givenName.Copy( itemField.TextStorage()->Text().Alloc() ); |
|
393 givenName = itemField.TextStorage()->Text().AllocLC(); |
|
394 |
|
395 } |
|
396 else |
|
397 { |
|
398 //givenName = KMusEmptyStringSymbol; |
|
399 givenName = KMusEmptyStringSymbol().AllocLC(); |
|
400 } |
|
401 |
|
402 pos = fieldSet.Find( KUidContactFieldFamilyName ); |
|
403 if ( pos != KErrNotFound ) |
|
404 { |
|
405 CContactItemField& itemField = fieldSet[pos]; |
|
406 //familyName = HBufC::NewL( itemField.TextStorage()->Text().Length() ); |
|
407 //familyName.Copy( field.TextStorage()->Text() ); |
|
408 familyName = itemField.TextStorage()->Text().AllocLC(); |
|
409 } |
|
410 else |
|
411 { |
|
412 familyName = KMusEmptyStringSymbol().AllocLC(); |
|
413 } |
|
414 |
|
415 TInt strLength = NULL; |
|
416 TBool bothNames = givenName->Length() > 0 && familyName->Length() > 0; |
|
417 |
|
418 if ( bothNames ) |
|
419 { |
|
420 strLength = givenName->Length() + |
|
421 KMusSpaceSymbol().Length() + |
|
422 familyName->Length(); |
|
423 } |
|
424 else |
|
425 { |
|
426 strLength = givenName->Length() + familyName->Length(); |
|
427 } |
|
428 |
|
429 if ( strLength > iContactName->Length() ) |
|
430 { |
|
431 iContactName = iContactName->ReAllocL( strLength ); |
|
432 } |
|
433 |
|
434 if ( strLength > 0 ) |
|
435 { |
|
436 TPtr ptr = iContactName->Des(); |
|
437 if ( iBeginWithFirstName ) |
|
438 { |
|
439 if ( bothNames ) |
|
440 { |
|
441 ptr.Append( givenName->Des() ); |
|
442 ptr.Append( KMusSpaceSymbol ); |
|
443 ptr.Append( familyName->Des() ); |
|
444 } |
|
445 else |
|
446 { |
|
447 ptr.Append( givenName->Des() ); |
|
448 ptr.Append( familyName->Des() ); |
|
449 } |
|
450 } |
|
451 else |
|
452 { |
|
453 if ( bothNames ) |
|
454 { |
|
455 ptr.Append( familyName->Des() ); |
|
456 ptr.Append( KMusSpaceSymbol ); |
|
457 ptr.Append( givenName->Des() ); |
|
458 } |
|
459 else |
|
460 { |
|
461 ptr.Append( familyName->Des() ); |
|
462 ptr.Append( givenName->Des() ); |
|
463 } |
|
464 } |
|
465 } |
|
466 |
|
467 CleanupStack::PopAndDestroy( familyName ); |
|
468 CleanupStack::PopAndDestroy( givenName ); |
|
469 |
|
470 TRAP_IGNORE( iSettings.SetContactNameL( iContactName->Des() ) ) |
|
471 |
|
472 MUS_LOG( "mus: [MUSAVA ] <- CMusAvaContactAvailability::\ |
|
473 UpdateContactName" ) |
|
474 } |
|
475 |
|
476 |
|
477 // ------------------------------------------------------------------------- |
|
478 // |
|
479 // ------------------------------------------------------------------------- |
|
480 // |
|
481 TInt CMusAvaContactAvailability::ContactArrayL( |
|
482 CContactIdArray*& aContactIdArray, |
|
483 CPbkContactEngine& aPbkContactEngine ) |
|
484 { |
|
485 MUS_LOG( "mus: [MUSAVA] -> CMusAvaContactAvailability::ContactArrayL()" ) |
|
486 |
|
487 const TDesC& phoneNumber = iSettings.TelNumber(); |
|
488 TInt retval = KErrNotFound; |
|
489 |
|
490 if ( phoneNumber.Length() > 0 ) |
|
491 { |
|
492 MUS_LOG( "mus: [MUSAVA] Phone number found " ) |
|
493 // Instantiate a PhonebookContactEngine object, which represents a |
|
494 // connection to the Phonebook contact database: |
|
495 #ifdef UNIT_TESTING // if unit testing |
|
496 EUNIT_DISABLE_ALLOC_DECORATOR; |
|
497 #endif // UNIT_TESTING |
|
498 CContactIdArray* tmpContactIdArray = |
|
499 aPbkContactEngine.MatchPhoneNumberL( |
|
500 phoneNumber, |
|
501 KNumberMatchingDigitsRequired ); |
|
502 #ifdef UNIT_TESTING // if unit testing |
|
503 EUNIT_ENABLE_ALLOC_DECORATOR; |
|
504 #endif // UNIT_TESTING |
|
505 if ( tmpContactIdArray->Count() > 0 ) |
|
506 { |
|
507 aContactIdArray = tmpContactIdArray; |
|
508 retval = KErrNone; |
|
509 } |
|
510 else |
|
511 { |
|
512 tmpContactIdArray->Reset(); |
|
513 delete tmpContactIdArray; |
|
514 MUS_LOG( |
|
515 "mus: [MUSAVA] Phone number not found in CPbkContactEngine" ) |
|
516 } |
|
517 } |
|
518 else |
|
519 { |
|
520 MUS_LOG( "mus: [MUSAVA] Phone number not found " ) |
|
521 } |
|
522 |
|
523 MUS_LOG1( "mus: [MUSAVA] <- CMusAvaContactAvailability::\ |
|
524 ContactArrayL return %d", retval ) |
|
525 |
|
526 return retval; |
|
527 } |
|
528 |
|
529 |
|
530 // ------------------------------------------------------------------------- |
|
531 // |
|
532 // ------------------------------------------------------------------------- |
|
533 // |
|
534 TInt CMusAvaContactAvailability::ContactItem( |
|
535 CContactIdArray& aContactIdArray, |
|
536 CPbkContactItem*& aPbkContactItem, |
|
537 CPbkContactEngine& aPbkContactEngine ) |
|
538 { |
|
539 MUS_LOG( "mus: [MUSAVA] -> CMusAvaContactAvailability::ContactItem()" ) |
|
540 CPbkContactItem* pbkItem = NULL; |
|
541 TInt retval = KErrNotFound; |
|
542 TInt contactIdsCount = aContactIdArray.Count(); |
|
543 |
|
544 if( contactIdsCount > 1 ) |
|
545 { |
|
546 // NOTE: KErrNotSupported means there is more than one contact id. |
|
547 MUS_LOG( "mus: [MUSAVA] More than one Contact ID found." ) |
|
548 retval = KErrNotSupported; |
|
549 } |
|
550 else if ( contactIdsCount == 1 ) |
|
551 { |
|
552 // Contact card whose phone number matches that of the other party |
|
553 // was found. The ID(s) of the contacts are recorded in iIdArray. |
|
554 MUS_LOG( "mus: [MUSAVA] Contact ID found." ) |
|
555 |
|
556 TContactItemId itemId( KErrNotFound ); |
|
557 |
|
558 MUS_LOG1( "mus: [MUSAVA] ID array has <%d> elements", |
|
559 contactIdsCount ) |
|
560 // iterate through the contact cards we consider as belonging to |
|
561 // the other party, that is, those saved in iIdArray: |
|
562 for ( TInt i = 0; i < contactIdsCount; i++ ) |
|
563 { |
|
564 itemId = ( aContactIdArray )[i]; |
|
565 MUS_LOG2( "mus: [MUSAVA] Current array index == <%d>, \ |
|
566 contact ID == <%d>", i, itemId ) |
|
567 TRAPD( pbkFailure, pbkItem = |
|
568 aPbkContactEngine.ReadContactL( itemId ) ); |
|
569 |
|
570 if ( pbkFailure ) |
|
571 { |
|
572 // Contact lookup failed. |
|
573 MUS_LOG1( "mus: [MUSAVA] Leave code <%d> occurred at call \ |
|
574 of ReadContactL.", pbkFailure ) |
|
575 } |
|
576 else |
|
577 { |
|
578 aPbkContactItem = pbkItem; |
|
579 retval = KErrNone; |
|
580 } |
|
581 } |
|
582 } |
|
583 else |
|
584 { |
|
585 MUS_LOG( "mus: [MUSAVA] No contact card whose phone number\ |
|
586 matches that of the other party" ) |
|
587 } |
|
588 |
|
589 MUS_LOG1( "mus: [MUSAVA] <- CMusAvaContactAvailability::\ |
|
590 ContactItem() return %d", retval ) |
|
591 |
|
592 return retval; |
|
593 } |
|
594 |
|
595 // ------------------------------------------------------------------------- |
|
596 // |
|
597 // ------------------------------------------------------------------------- |
|
598 // |
|
599 TBool CMusAvaContactAvailability::PhoneResolutionL( CPbkContactItem& aPbkItem, |
|
600 CDesCArrayFlat*& aContactsArray ) |
|
601 { |
|
602 MUS_LOG( "mus: [MUSAVA] -> CMusAvaContactAvailability::PhoneResolutionL()" ) |
|
603 TInt retval = ETrue; |
|
604 if ( ResolvePhoneContactL( aPbkItem, aContactsArray ) ) |
|
605 { |
|
606 MUS_LOG( "mus: [MUSAVA] Stop Execution" ) |
|
607 } |
|
608 else |
|
609 { |
|
610 if ( ActiveCallL( aContactsArray ) ) |
|
611 { |
|
612 MUS_LOG( "mus: [MUSAVA] Stop Execution" ) |
|
613 } |
|
614 else |
|
615 { |
|
616 MUS_LOG( "mus: [MUSAVA] Stop Execution" ) |
|
617 retval = EFalse; |
|
618 } |
|
619 } |
|
620 |
|
621 MUS_LOG1( "mus: [MUSAVA] <- CMusAvaContactAvailability::\ |
|
622 PhoneResolutionL() return %d", retval ) |
|
623 return retval; |
|
624 } |
|
625 |
|
626 |
|
627 // ------------------------------------------------------------------------- |
|
628 // |
|
629 // ------------------------------------------------------------------------- |
|
630 // |
|
631 TBool CMusAvaContactAvailability::ContactId( CPbkContactItem& aPbkItem, |
|
632 TPbkFieldId aTPbkFieldId ) |
|
633 { |
|
634 MUS_LOG( "mus: [MUSAVA] -> CMusAvaContactAvailability::ContactId()" ) |
|
635 |
|
636 CPbkFieldArray& fieldArray = aPbkItem.CardFields(); |
|
637 TPbkContactItemField itemField; |
|
638 TBool returnValue = EFalse; |
|
639 |
|
640 // Get the number of detail fields of the phonebook contact item. |
|
641 const TInt fieldCount( fieldArray.Count() ); |
|
642 |
|
643 for ( TInt index = 0; index < fieldCount && returnValue == EFalse; |
|
644 index++ ) |
|
645 { |
|
646 itemField = fieldArray.At( index ); |
|
647 |
|
648 if ( itemField.FieldInfo().Match( aTPbkFieldId ) && |
|
649 itemField.Text().Find( KMusAvaAtSign() ) != KErrNotFound ) |
|
650 { |
|
651 returnValue = ETrue; |
|
652 MUS_LOG( "mus: [MUSAVA] Contact id found" ) |
|
653 } |
|
654 } |
|
655 MUS_LOG1( "mus: [MUSAVA] <- CMusAvaContactAvailability::\ |
|
656 ContactId() return %d", returnValue ) |
|
657 return returnValue; |
|
658 } |
|
659 |
|
660 |
|
661 // ------------------------------------------------------------------------- |
|
662 // |
|
663 // ------------------------------------------------------------------------- |
|
664 // |
|
665 TPbkFieldId CMusAvaContactAvailability::ContactIdSearch( |
|
666 CContactIdArray& aContactIdArray, |
|
667 CPbkContactEngine& aPbkContactEngine ) |
|
668 { |
|
669 MUS_LOG( "mus: [MUSAVA] -> CMusAvaContactAvailability::\ |
|
670 ContactIdSearch()" ) |
|
671 |
|
672 TInt contactIdsCount = aContactIdArray.Count(); |
|
673 MUS_LOG1( "mus: [MUSAVA] aContactIdArray.Count %d", \ |
|
674 contactIdsCount ) |
|
675 |
|
676 CPbkContactItem* pbkItem = NULL; |
|
677 TPbkFieldId retFieldId = EPbkFieldIdNone; |
|
678 |
|
679 for ( TInt i = 0; |
|
680 i < contactIdsCount && retFieldId == EPbkFieldIdNone; |
|
681 i++ ) |
|
682 { |
|
683 MUS_LOG1( "mus: [MUSAVA] i %d", i ) |
|
684 TContactItemId itemId( KErrNotFound ); |
|
685 itemId = ( aContactIdArray )[i]; |
|
686 |
|
687 #ifdef UNIT_TESTING // if unit testing |
|
688 EUNIT_DISABLE_ALLOC_DECORATOR; |
|
689 #endif // UNIT_TESTING |
|
690 TRAPD( error, pbkItem = aPbkContactEngine.ReadContactL( itemId ) ) |
|
691 #ifdef UNIT_TESTING // if unit testing |
|
692 EUNIT_ENABLE_ALLOC_DECORATOR; |
|
693 #endif // UNIT_TESTING |
|
694 if ( error != KErrNone ) |
|
695 { |
|
696 return retFieldId; |
|
697 } |
|
698 if ( ContactId( *pbkItem, EPbkFieldIdShareView ) ) |
|
699 { |
|
700 MUS_LOG( "mus: [MUSAVA] Contact have a prefix = \ |
|
701 EPbkFieldIdShareView" ) |
|
702 delete pbkItem; |
|
703 retFieldId = EPbkFieldIdShareView; |
|
704 } |
|
705 else if ( ContactId( *pbkItem, EPbkFieldIdSIPID ) ) |
|
706 { |
|
707 MUS_LOG( "mus: [MUSAVA] Contact have a prefix = \ |
|
708 EPbkFieldIdSIPID" ) |
|
709 delete pbkItem; |
|
710 retFieldId = EPbkFieldIdSIPID; |
|
711 } |
|
712 else if ( ContactId( *pbkItem, EPbkFieldIdPhoneNumberGeneral ) ) |
|
713 { |
|
714 // this part never run!!!! |
|
715 MUS_LOG( "mus: [MUSAVA] Contact have a prefix = \ |
|
716 EPbkFieldIdPhoneNumberGeneral" ) |
|
717 delete pbkItem; |
|
718 retFieldId = EPbkFieldIdPhoneNumberGeneral; |
|
719 } |
|
720 else |
|
721 { |
|
722 MUS_LOG( "mus: [MUSAVA] Contact have no prefix " ) |
|
723 delete pbkItem; |
|
724 } |
|
725 } |
|
726 return retFieldId; |
|
727 } |
|
728 |
|
729 |
|
730 // ------------------------------------------------------------------------- |
|
731 // |
|
732 // ------------------------------------------------------------------------- |
|
733 // |
|
734 TBool CMusAvaContactAvailability::ResolveAddressesL( CPbkContactItem& aPbkItem, |
|
735 CDesCArrayFlat*& aContactsArray, |
|
736 TPbkFieldId aTPbkFieldId ) |
|
737 { |
|
738 MUS_LOG( "mus: [MUSAVA] -> CMusAvaContactAvailability::\ |
|
739 ResolveAddressesL()" ) |
|
740 |
|
741 CPbkFieldArray& fieldArray = aPbkItem.CardFields(); |
|
742 TPbkContactItemField itemField; |
|
743 HBufC* tmpDescriptor( NULL ); |
|
744 TBool returnValue( EFalse ); |
|
745 |
|
746 // Get the number of detail fields of the phonebook contact item. |
|
747 const TInt fieldCount( fieldArray.Count() ); |
|
748 |
|
749 for ( TInt index = 0; index < fieldCount; index++ ) |
|
750 { |
|
751 itemField = fieldArray.At( index ); |
|
752 |
|
753 if ( itemField.FieldInfo().Match( aTPbkFieldId ) && |
|
754 itemField.Text().Find( KMusAvaAtSign() ) != KErrNotFound && |
|
755 ( iOperatorVariant != MusSettingsKeys::EOperatorSpecific || |
|
756 itemField.Text().Find( KMusAvaTestString() ) != KErrNotFound ) ) |
|
757 { |
|
758 returnValue = ETrue; |
|
759 MUS_LOG( "mus: [MUSAVA] Contact id found" ) |
|
760 |
|
761 HBufC* sipAddress; |
|
762 if ( iOperatorVariant == MusSettingsKeys::EOperatorSpecific ) |
|
763 { |
|
764 sipAddress = HBufC::NewLC( itemField.Text().Length() - |
|
765 KMusAvaTestString().Length() ); |
|
766 TInt pos = itemField.Text().Find( KMusAvaTestString() ); |
|
767 sipAddress->Des().Append( itemField.Text().Left( pos ) ); |
|
768 sipAddress->Des().Append( itemField.Text().Right( |
|
769 itemField.Text().Length() - |
|
770 pos - KMusAvaTestString().Length() ) ); |
|
771 } |
|
772 else |
|
773 { |
|
774 sipAddress = itemField.Text().AllocLC(); |
|
775 } |
|
776 |
|
777 if ( sipAddress->Find( KMusAvaSip() ) == KErrNotFound ) |
|
778 { |
|
779 // No, it doesn't, so add the prefix to the new address. |
|
780 MUS_LOG( "mus: [MUSAVA] Prefix to the new address is added" ) |
|
781 tmpDescriptor = HBufC::NewLC( KMusAvaSip().Length() + |
|
782 sipAddress->Length() ); |
|
783 tmpDescriptor->Des().Append( KMusAvaSip() ); |
|
784 tmpDescriptor->Des().Append( *sipAddress ); |
|
785 // if multiple contact have same phone number then |
|
786 // sip address can be repeated . To avoid this check |
|
787 // whether sip address exist already in array |
|
788 // it not exist then add it to array. |
|
789 if(! IsExistAlready(*aContactsArray,*tmpDescriptor)) |
|
790 { |
|
791 aContactsArray->AppendL( *tmpDescriptor ); |
|
792 } |
|
793 CleanupStack::PopAndDestroy( tmpDescriptor ); |
|
794 } |
|
795 else |
|
796 { |
|
797 MUS_LOG( "mus: [MUSAVA] Contact have a prefix" ) |
|
798 // if multiple contact have same phone number then |
|
799 // sip address can be repeated . To avoid this check |
|
800 // whether sip address exist already in array |
|
801 // it not exist then add it to array. |
|
802 if(! IsExistAlready(*aContactsArray,*sipAddress)) |
|
803 { |
|
804 aContactsArray->AppendL( *sipAddress ); |
|
805 } |
|
806 } |
|
807 |
|
808 CleanupStack::PopAndDestroy( sipAddress ); |
|
809 } |
|
810 } |
|
811 MUS_LOG1( "mus: [MUSAVA] <- CMusAvaContactAvailability::\ |
|
812 ResolveAddressesL() return %d", returnValue ) |
|
813 return returnValue; |
|
814 } |
|
815 |
|
816 |
|
817 // ------------------------------------------------------------------------- |
|
818 // |
|
819 // ------------------------------------------------------------------------- |
|
820 // |
|
821 TBool CMusAvaContactAvailability::ResolvePhoneContactL( |
|
822 CPbkContactItem& aPbkItem, |
|
823 CDesCArrayFlat*& aContactsArray ) |
|
824 { |
|
825 MUS_LOG( "mus: [MUSAVA] -> CMusAvaContactAvailability::\ |
|
826 ResolvePhoneContactL()" ) |
|
827 CPbkFieldArray& fieldArray = aPbkItem.CardFields(); |
|
828 TPbkContactItemField itemField; |
|
829 HBufC* tmpDescriptor( NULL ); |
|
830 TBool returnValue = EFalse; |
|
831 |
|
832 // Get the number of detail fields of the phonebook contact item. |
|
833 const TInt fieldCount( fieldArray.Count() ); |
|
834 |
|
835 for ( TInt index = 0; index < fieldCount; index++ ) |
|
836 { |
|
837 itemField = fieldArray.At( index ); |
|
838 |
|
839 if ( itemField.FieldInfo().IsPhoneNumberField() && |
|
840 ( iOperatorVariant == MusSettingsKeys::EOperatorSpecific || |
|
841 itemField.Text().Left(1) == KMusAvaPlus() ) ) |
|
842 { |
|
843 MUS_LOG( "mus: [MUSAVA] Contact id found" ) |
|
844 // No, it doesn't, so add the prefix to the new address. |
|
845 MUS_LOG( "mus: [MUSAVA] Prefix to the new address is added" ) |
|
846 tmpDescriptor = HBufC::NewLC( KMusAvaTel().Length() + |
|
847 itemField.Text().Length() ); |
|
848 tmpDescriptor->Des().Append( KMusAvaTel() ); |
|
849 tmpDescriptor->Des().Append( itemField.Text() ); |
|
850 aContactsArray->AppendL( *tmpDescriptor ); |
|
851 CleanupStack::PopAndDestroy( tmpDescriptor ); |
|
852 returnValue = ETrue; |
|
853 } |
|
854 } |
|
855 |
|
856 MUS_LOG( "mus: [MUSAVA] <- CMusAvaContactAvailability::\ |
|
857 ResolvePhoneContactL()" ) |
|
858 return returnValue; |
|
859 } |
|
860 |
|
861 |
178 MMusAvaObserver::TAvailabilityName CMusAvaContactAvailability::Name() |
862 MMusAvaObserver::TAvailabilityName CMusAvaContactAvailability::Name() |
179 { |
863 { |
180 return MMusAvaObserver::EMusAvaNameContactStatus; |
864 return MMusAvaObserver::EMusAvaNameContactStatus; |
181 } |
865 } |
182 |
866 |
183 |
867 |
184 |
868 // ------------------------------------------------------------------------- |
185 |
869 // Checks that whether aDesItem present in aDesArray. |
186 // End of file |
870 // Utility function used to avoid dublication. |
|
871 // ------------------------------------------------------------------------- |
|
872 // |
|
873 TBool CMusAvaContactAvailability::IsExistAlready(const MDesCArray& aDesArray, |
|
874 const TDesC& aDesItem) |
|
875 { |
|
876 for ( TInt i=0;i<aDesArray.MdcaCount();i++) |
|
877 { |
|
878 if (! aDesArray.MdcaPoint(i).Compare( aDesItem ) ) |
|
879 { |
|
880 return ETrue; |
|
881 } |
|
882 } |
|
883 return EFalse; |
|
884 } |