-rw-r--r-- | kabc/addressee.cpp | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index 295ee4f..2564894 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp | |||
@@ -402,103 +402,121 @@ bool Addressee::removeVoice() | |||
402 | PhoneNumber::List phoneN = phoneNumbers(); | 402 | PhoneNumber::List phoneN = phoneNumbers(); |
403 | PhoneNumber::List::Iterator phoneIt; | 403 | PhoneNumber::List::Iterator phoneIt; |
404 | bool found = false; | 404 | bool found = false; |
405 | for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { | 405 | for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { |
406 | if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found | 406 | if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found |
407 | if ((*phoneIt).type() - PhoneNumber::Voice ) { | 407 | if ((*phoneIt).type() - PhoneNumber::Voice ) { |
408 | (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice ); | 408 | (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice ); |
409 | insertPhoneNumber( (*phoneIt) ); | 409 | insertPhoneNumber( (*phoneIt) ); |
410 | found = true; | 410 | found = true; |
411 | } | 411 | } |
412 | } | 412 | } |
413 | 413 | ||
414 | } | 414 | } |
415 | return found; | 415 | return found; |
416 | } | 416 | } |
417 | 417 | ||
418 | bool Addressee::containsAdr(const Addressee& ad ) | 418 | bool Addressee::containsAdr(const Addressee& ad ) |
419 | { | 419 | { |
420 | if ( ! ad.mData->familyName.isEmpty() ) if ( mData->familyName != ad.mData->familyName) return false; | 420 | if ( ! ad.mData->familyName.isEmpty() ) if ( mData->familyName != ad.mData->familyName) return false; |
421 | if ( ! ad.mData->givenName.isEmpty() )if ( mData->givenName != ad.mData->givenName ) return false; | 421 | if ( ! ad.mData->givenName.isEmpty() )if ( mData->givenName != ad.mData->givenName ) return false; |
422 | if ( ad.mData->url.isValid() ) if (mData->url != ad.mData->url) return false ; | 422 | if ( ad.mData->url.isValid() ) if (mData->url != ad.mData->url) return false ; |
423 | if ( ! ad.mData->role.isEmpty() ) if (mData->role != ad.mData->role) return false ; | 423 | if ( ! ad.mData->role.isEmpty() ) if (mData->role != ad.mData->role) return false ; |
424 | if ( ! ad.mData->organization.isEmpty() ) if (mData->organization != ad.mData->organization) return false ; | 424 | if ( ! ad.mData->organization.isEmpty() ) if (mData->organization != ad.mData->organization) return false ; |
425 | if ( ! ad.mData->note.isEmpty() ) if (mData->note != ad.mData->note) return false ; | 425 | if ( ! ad.mData->note.isEmpty() ) if (mData->note != ad.mData->note) return false ; |
426 | if ( ! ad.mData->title .isEmpty() ) if (mData->title != ad.mData->title ) return false ; | 426 | if ( ! ad.mData->title .isEmpty() ) if (mData->title != ad.mData->title ) return false ; |
427 | 427 | ||
428 | // compare phone numbers | 428 | // compare phone numbers |
429 | PhoneNumber::List phoneN = ad.phoneNumbers(); | 429 | PhoneNumber::List phoneN = ad.phoneNumbers(); |
430 | PhoneNumber::List::Iterator phoneIt; | 430 | PhoneNumber::List::Iterator phoneIt; |
431 | bool found = false; | 431 | bool found = false; |
432 | for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { | 432 | for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { |
433 | bool found = false; | 433 | bool found = false; |
434 | PhoneNumber::List phoneL = ad.phoneNumbers(); | 434 | PhoneNumber::List phoneL = ad.phoneNumbers(); |
435 | PhoneNumber::List::Iterator phoneItL; | 435 | PhoneNumber::List::Iterator phoneItL; |
436 | for ( phoneItL = phoneL.begin(); phoneItL != phoneL.end(); ++phoneItL ) { | 436 | for ( phoneItL = phoneL.begin(); phoneItL != phoneL.end(); ++phoneItL ) { |
437 | if ( ( *phoneItL ).number() == ( *phoneIt ).number() ) { | 437 | if ( ( *phoneItL ).number() == ( *phoneIt ).number() ) { |
438 | found = true; | 438 | found = true; |
439 | break; | 439 | break; |
440 | } | 440 | } |
441 | } | 441 | } |
442 | if ( ! found ) | 442 | if ( ! found ) |
443 | return false; | 443 | return false; |
444 | } | 444 | } |
445 | return true; | 445 | return true; |
446 | 446 | ||
447 | } | 447 | } |
448 | void Addressee::simplifyAddresses() | 448 | void Addressee::simplifyAddresses() |
449 | { | 449 | { |
450 | |||
451 | |||
452 | Address::List list; | ||
453 | Address::List::Iterator it; | ||
454 | Address::List::Iterator it2; | ||
455 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { | ||
456 | it2 = it; | ||
457 | ++it2; | ||
458 | for( ; it2 != mData->addresses.end(); ++it2 ) { | ||
459 | if ( (*it) == (*it2) ) { | ||
460 | list.append( *it ); | ||
461 | break; | ||
462 | } | ||
463 | } | ||
464 | } | ||
465 | for( it = list.begin(); it != list.end(); ++it ) { | ||
466 | removeAddress( (*it) ); | ||
467 | } | ||
468 | |||
469 | list.clear(); | ||
450 | int max = 2; | 470 | int max = 2; |
451 | if ( mData->url.isValid() ) | 471 | if ( mData->url.isValid() ) |
452 | max = 1; | 472 | max = 1; |
453 | if ( mData->addresses.count() <= max ) return ; | 473 | if ( mData->addresses.count() <= max ) return ; |
454 | int count = 0; | 474 | int count = 0; |
455 | Address::List list; | ||
456 | Address::List::Iterator it; | ||
457 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { | 475 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { |
458 | if ( count >= max ) | 476 | if ( count >= max ) |
459 | list.append( *it ); | 477 | list.append( *it ); |
460 | ++count; | 478 | ++count; |
461 | } | 479 | } |
462 | for( it = list.begin(); it != list.end(); ++it ) { | 480 | for( it = list.begin(); it != list.end(); ++it ) { |
463 | removeAddress( (*it) ); | 481 | removeAddress( (*it) ); |
464 | } | 482 | } |
465 | } | 483 | } |
466 | 484 | ||
467 | // removes all emails but the first | 485 | // removes all emails but the first |
468 | // needed by phone sync | 486 | // needed by phone sync |
469 | void Addressee::simplifyEmails() | 487 | void Addressee::simplifyEmails() |
470 | { | 488 | { |
471 | if ( mData->emails.count() == 0 ) return ; | 489 | if ( mData->emails.count() == 0 ) return ; |
472 | QString email = mData->emails.first(); | 490 | QString email = mData->emails.first(); |
473 | detach(); | 491 | detach(); |
474 | mData->emails.clear(); | 492 | mData->emails.clear(); |
475 | mData->emails.append( email ); | 493 | mData->emails.append( email ); |
476 | } | 494 | } |
477 | 495 | ||
478 | void Addressee::simplifyPhoneNumbers() | 496 | void Addressee::simplifyPhoneNumbers() |
479 | { | 497 | { |
480 | int max = 4; | 498 | int max = 4; |
481 | int inList = mData->phoneNumbers.count(); | 499 | int inList = mData->phoneNumbers.count(); |
482 | KABC::PhoneNumber::List removeNumbers; | 500 | KABC::PhoneNumber::List removeNumbers; |
483 | KABC::PhoneNumber::List::Iterator phoneIter; | 501 | KABC::PhoneNumber::List::Iterator phoneIter; |
484 | if ( inList > max ) { | 502 | if ( inList > max ) { |
485 | // delete non-preferred numbers | 503 | // delete non-preferred numbers |
486 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); | 504 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); |
487 | ++phoneIter ) { | 505 | ++phoneIter ) { |
488 | if ( inList > max ) { | 506 | if ( inList > max ) { |
489 | if ( ! (( *phoneIter ).type() & PhoneNumber::Pref )) { | 507 | if ( ! (( *phoneIter ).type() & PhoneNumber::Pref )) { |
490 | removeNumbers.append( ( *phoneIter ) ); | 508 | removeNumbers.append( ( *phoneIter ) ); |
491 | --inList; | 509 | --inList; |
492 | } | 510 | } |
493 | } else | 511 | } else |
494 | break; | 512 | break; |
495 | } | 513 | } |
496 | for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); | 514 | for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); |
497 | ++phoneIter ) { | 515 | ++phoneIter ) { |
498 | removePhoneNumber(( *phoneIter )); | 516 | removePhoneNumber(( *phoneIter )); |
499 | } | 517 | } |
500 | // delete preferred numbers | 518 | // delete preferred numbers |
501 | if ( inList > max ) { | 519 | if ( inList > max ) { |
502 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); | 520 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); |
503 | ++phoneIter ) { | 521 | ++phoneIter ) { |
504 | if ( inList > max ) { | 522 | if ( inList > max ) { |