-rw-r--r-- | kabc/addressee.cpp | 74 |
1 files changed, 68 insertions, 6 deletions
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index 7e1e414..661bdf6 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp | |||
@@ -525,129 +525,181 @@ bool Addressee::containsAdr(const Addressee& ad ) | |||
525 | bool found = false; | 525 | bool found = false; |
526 | for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { | 526 | for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { |
527 | bool found = false; | 527 | bool found = false; |
528 | PhoneNumber::List phoneL = ad.phoneNumbers(); | 528 | PhoneNumber::List phoneL = ad.phoneNumbers(); |
529 | PhoneNumber::List::Iterator phoneItL; | 529 | PhoneNumber::List::Iterator phoneItL; |
530 | for ( phoneItL = phoneL.begin(); phoneItL != phoneL.end(); ++phoneItL ) { | 530 | for ( phoneItL = phoneL.begin(); phoneItL != phoneL.end(); ++phoneItL ) { |
531 | if ( ( *phoneItL ).number() == ( *phoneIt ).number() ) { | 531 | if ( ( *phoneItL ).number() == ( *phoneIt ).number() ) { |
532 | found = true; | 532 | found = true; |
533 | break; | 533 | break; |
534 | } | 534 | } |
535 | } | 535 | } |
536 | if ( ! found ) | 536 | if ( ! found ) |
537 | return false; | 537 | return false; |
538 | } | 538 | } |
539 | return true; | 539 | return true; |
540 | 540 | ||
541 | } | 541 | } |
542 | void Addressee::simplifyAddresses() | 542 | void Addressee::simplifyAddresses() |
543 | { | 543 | { |
544 | 544 | ||
545 | 545 | ||
546 | Address::List list; | 546 | Address::List list; |
547 | Address::List::Iterator it; | 547 | Address::List::Iterator it; |
548 | Address::List::Iterator it2; | 548 | Address::List::Iterator it2; |
549 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { | 549 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { |
550 | it2 = it; | 550 | it2 = it; |
551 | ++it2; | 551 | ++it2; |
552 | for( ; it2 != mData->addresses.end(); ++it2 ) { | 552 | for( ; it2 != mData->addresses.end(); ++it2 ) { |
553 | if ( (*it) == (*it2) ) { | 553 | if ( (*it) == (*it2) ) { |
554 | list.append( *it ); | 554 | list.append( *it ); |
555 | break; | 555 | break; |
556 | } | 556 | } |
557 | } | 557 | } |
558 | } | 558 | } |
559 | for( it = list.begin(); it != list.end(); ++it ) { | 559 | for( it = list.begin(); it != list.end(); ++it ) { |
560 | removeAddress( (*it) ); | 560 | removeAddress( (*it) ); |
561 | } | 561 | } |
562 | 562 | ||
563 | list.clear(); | 563 | list.clear(); |
564 | int max = 2; | 564 | int max = 2; |
565 | if ( mData->url.isValid() ) | 565 | if ( mData->url.isValid() ) |
566 | max = 1; | 566 | max = 1; |
567 | if ( mData->addresses.count() <= max ) return ; | 567 | if ( mData->addresses.count() <= max ) return ; |
568 | int count = 0; | 568 | int count = 0; |
569 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { | 569 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { |
570 | if ( count >= max ) | 570 | if ( count >= max ) |
571 | list.append( *it ); | 571 | list.append( *it ); |
572 | ++count; | 572 | ++count; |
573 | } | 573 | } |
574 | for( it = list.begin(); it != list.end(); ++it ) { | 574 | for( it = list.begin(); it != list.end(); ++it ) { |
575 | removeAddress( (*it) ); | 575 | removeAddress( (*it) ); |
576 | } | 576 | } |
577 | } | 577 | } |
578 | 578 | ||
579 | // removes all emails but the first | 579 | // removes all emails but the first |
580 | // needed by phone sync | 580 | // needed by phone sync |
581 | void Addressee::simplifyEmails() | 581 | void Addressee::simplifyEmails() |
582 | { | 582 | { |
583 | if ( mData->emails.count() == 0 ) return ; | 583 | if ( mData->emails.count() == 0 ) return ; |
584 | QString email = mData->emails.first(); | 584 | QString email = mData->emails.first(); |
585 | detach(); | 585 | detach(); |
586 | mData->emails.clear(); | 586 | mData->emails.clear(); |
587 | mData->emails.append( email ); | 587 | mData->emails.append( email ); |
588 | } | 588 | } |
589 | void Addressee::makePhoneNumbersOLcompatible() | ||
590 | { | ||
591 | KABC::PhoneNumber::List::Iterator phoneIter; | ||
592 | KABC::PhoneNumber::List::Iterator phoneIter2; | ||
593 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); | ||
594 | ++phoneIter ) { | ||
595 | ( *phoneIter ).makeCompat(); | ||
596 | } | ||
597 | int hasHome = hasPhoneNumberType( PhoneNumber::Home | PhoneNumber::Pref ); | ||
598 | int hasHome2 = hasPhoneNumberType( PhoneNumber::Home ); | ||
599 | int hasWork = hasPhoneNumberType( PhoneNumber::Work | PhoneNumber::Pref ); | ||
600 | int hasWork2 = hasPhoneNumberType( PhoneNumber::Work ); | ||
601 | int hasCell = hasPhoneNumberType( PhoneNumber::Cell ); | ||
602 | int hasCell2 = hasPhoneNumberType( PhoneNumber::Car ); | ||
603 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); | ||
604 | ++phoneIter ) { | ||
605 | if ( (*phoneIter).type() == PhoneNumber::Home && ! hasHome ) { | ||
606 | (*phoneIter).setType( PhoneNumber::Home | PhoneNumber::Pref ); | ||
607 | ++hasHome; | ||
608 | if ( hasHome2 ) --hasHome2; | ||
609 | } else if ( ( (*phoneIter).type() == PhoneNumber::Home | PhoneNumber::Pref) && hasHome>1 && !hasHome2 ) { | ||
610 | (*phoneIter).setType( PhoneNumber::Home ); | ||
611 | --hasHome; | ||
612 | ++hasHome2; | ||
613 | } else if ( (*phoneIter).type() == PhoneNumber::Work && ! hasWork ) { | ||
614 | (*phoneIter).setType( PhoneNumber::Work | PhoneNumber::Pref ); | ||
615 | ++hasWork; | ||
616 | if ( hasWork2 ) --hasWork2; | ||
617 | } else if ( ( (*phoneIter).type() == PhoneNumber::Work | PhoneNumber::Pref) && hasWork > 1 && ! hasWork2 ) { | ||
618 | (*phoneIter).setType( PhoneNumber::Work ); | ||
619 | --hasWork; | ||
620 | ++hasWork2; | ||
621 | } else if ( (*phoneIter).type() == PhoneNumber::Cell && hasCell > 1 && !hasCell2) { | ||
622 | (*phoneIter).setType( PhoneNumber::Car ); | ||
623 | ++hasCell2; | ||
624 | --hasCell; | ||
625 | } else if ( (*phoneIter).type() == PhoneNumber::Car && hasCell2 > 1 && !hasCell) { | ||
626 | (*phoneIter).setType( PhoneNumber::Cell ); | ||
627 | ++hasCell; | ||
628 | --hasCell2; | ||
629 | } else{ | ||
630 | phoneIter2 = phoneIter; | ||
631 | ++phoneIter2; | ||
632 | for ( ; phoneIter2 != mData->phoneNumbers.end(); | ||
633 | ++phoneIter2 ) { | ||
634 | if ( (*phoneIter2).type() == (*phoneIter).type() ) { | ||
635 | (*phoneIter2).setType( PhoneNumber::Voice ); | ||
589 | 636 | ||
637 | } | ||
638 | } | ||
639 | } | ||
640 | } | ||
641 | } | ||
590 | void Addressee::simplifyPhoneNumbers() | 642 | void Addressee::simplifyPhoneNumbers() |
591 | { | 643 | { |
592 | int max = 4; | 644 | int max = 4; |
593 | int inList = mData->phoneNumbers.count(); | 645 | int inList = mData->phoneNumbers.count(); |
594 | KABC::PhoneNumber::List removeNumbers; | 646 | KABC::PhoneNumber::List removeNumbers; |
595 | KABC::PhoneNumber::List::Iterator phoneIter; | 647 | KABC::PhoneNumber::List::Iterator phoneIter; |
596 | if ( inList > max ) { | 648 | if ( inList > max ) { |
597 | // delete non-preferred numbers | 649 | // delete non-preferred numbers |
598 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); | 650 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); |
599 | ++phoneIter ) { | 651 | ++phoneIter ) { |
600 | if ( inList > max ) { | 652 | if ( inList > max ) { |
601 | if ( ! (( *phoneIter ).type() & PhoneNumber::Pref )) { | 653 | if ( ! (( *phoneIter ).type() & PhoneNumber::Pref )) { |
602 | removeNumbers.append( ( *phoneIter ) ); | 654 | removeNumbers.append( ( *phoneIter ) ); |
603 | --inList; | 655 | --inList; |
604 | } | 656 | } |
605 | } else | 657 | } else |
606 | break; | 658 | break; |
607 | } | 659 | } |
608 | for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); | 660 | for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); |
609 | ++phoneIter ) { | 661 | ++phoneIter ) { |
610 | removePhoneNumber(( *phoneIter )); | 662 | removePhoneNumber(( *phoneIter )); |
611 | } | 663 | } |
612 | // delete preferred numbers | 664 | // delete preferred numbers |
613 | if ( inList > max ) { | 665 | if ( inList > max ) { |
614 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); | 666 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); |
615 | ++phoneIter ) { | 667 | ++phoneIter ) { |
616 | if ( inList > max ) { | 668 | if ( inList > max ) { |
617 | removeNumbers.append( ( *phoneIter ) ); | 669 | removeNumbers.append( ( *phoneIter ) ); |
618 | --inList; | 670 | --inList; |
619 | } else | 671 | } else |
620 | break; | 672 | break; |
621 | } | 673 | } |
622 | for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); | 674 | for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); |
623 | ++phoneIter ) { | 675 | ++phoneIter ) { |
624 | removePhoneNumber(( *phoneIter )); | 676 | removePhoneNumber(( *phoneIter )); |
625 | } | 677 | } |
626 | } | 678 | } |
627 | } | 679 | } |
628 | // remove non-numeric characters | 680 | // remove non-numeric characters |
629 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); | 681 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); |
630 | ++phoneIter ) { | 682 | ++phoneIter ) { |
631 | if ( ! ( *phoneIter ).simplifyNumber() ) | 683 | if ( ! ( *phoneIter ).simplifyNumber() ) |
632 | removeNumbers.append( ( *phoneIter ) ); | 684 | removeNumbers.append( ( *phoneIter ) ); |
633 | } | 685 | } |
634 | for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); | 686 | for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); |
635 | ++phoneIter ) { | 687 | ++phoneIter ) { |
636 | removePhoneNumber(( *phoneIter )); | 688 | removePhoneNumber(( *phoneIter )); |
637 | } | 689 | } |
638 | } | 690 | } |
639 | void Addressee::simplifyPhoneNumberTypes() | 691 | void Addressee::simplifyPhoneNumberTypes() |
640 | { | 692 | { |
641 | KABC::PhoneNumber::List::Iterator phoneIter; | 693 | KABC::PhoneNumber::List::Iterator phoneIter; |
642 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); | 694 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); |
643 | ++phoneIter ) | 695 | ++phoneIter ) |
644 | ( *phoneIter ).simplifyType(); | 696 | ( *phoneIter ).simplifyType(); |
645 | } | 697 | } |
646 | void Addressee::removeID(const QString &prof) | 698 | void Addressee::removeID(const QString &prof) |
647 | { | 699 | { |
648 | detach(); | 700 | detach(); |
649 | if ( prof.isEmpty() ) | 701 | if ( prof.isEmpty() ) |
650 | mData->mExternalId = ":"; | 702 | mData->mExternalId = ":"; |
651 | else | 703 | else |
652 | mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof); | 704 | mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof); |
653 | 705 | ||
@@ -936,161 +988,161 @@ QString Addressee::homeAddressRegionLabel() | |||
936 | 988 | ||
937 | 989 | ||
938 | QString Addressee::homeAddressPostalCodeLabel() | 990 | QString Addressee::homeAddressPostalCodeLabel() |
939 | { | 991 | { |
940 | return i18n("Home Address Postal Code"); | 992 | return i18n("Home Address Postal Code"); |
941 | } | 993 | } |
942 | 994 | ||
943 | 995 | ||
944 | QString Addressee::homeAddressCountryLabel() | 996 | QString Addressee::homeAddressCountryLabel() |
945 | { | 997 | { |
946 | return i18n("Home Address Country"); | 998 | return i18n("Home Address Country"); |
947 | } | 999 | } |
948 | 1000 | ||
949 | 1001 | ||
950 | QString Addressee::homeAddressLabelLabel() | 1002 | QString Addressee::homeAddressLabelLabel() |
951 | { | 1003 | { |
952 | return i18n("Home Address Label"); | 1004 | return i18n("Home Address Label"); |
953 | } | 1005 | } |
954 | 1006 | ||
955 | 1007 | ||
956 | QString Addressee::businessAddressStreetLabel() | 1008 | QString Addressee::businessAddressStreetLabel() |
957 | { | 1009 | { |
958 | return i18n("Business Address Street"); | 1010 | return i18n("Business Address Street"); |
959 | } | 1011 | } |
960 | 1012 | ||
961 | 1013 | ||
962 | QString Addressee::businessAddressLocalityLabel() | 1014 | QString Addressee::businessAddressLocalityLabel() |
963 | { | 1015 | { |
964 | return i18n("Business Address Locality"); | 1016 | return i18n("Business Address Locality"); |
965 | } | 1017 | } |
966 | 1018 | ||
967 | 1019 | ||
968 | QString Addressee::businessAddressRegionLabel() | 1020 | QString Addressee::businessAddressRegionLabel() |
969 | { | 1021 | { |
970 | return i18n("Business Address Region"); | 1022 | return i18n("Business Address Region"); |
971 | } | 1023 | } |
972 | 1024 | ||
973 | 1025 | ||
974 | QString Addressee::businessAddressPostalCodeLabel() | 1026 | QString Addressee::businessAddressPostalCodeLabel() |
975 | { | 1027 | { |
976 | return i18n("Business Address Postal Code"); | 1028 | return i18n("Business Address Postal Code"); |
977 | } | 1029 | } |
978 | 1030 | ||
979 | 1031 | ||
980 | QString Addressee::businessAddressCountryLabel() | 1032 | QString Addressee::businessAddressCountryLabel() |
981 | { | 1033 | { |
982 | return i18n("Business Address Country"); | 1034 | return i18n("Business Address Country"); |
983 | } | 1035 | } |
984 | 1036 | ||
985 | 1037 | ||
986 | QString Addressee::businessAddressLabelLabel() | 1038 | QString Addressee::businessAddressLabelLabel() |
987 | { | 1039 | { |
988 | return i18n("Business Address Label"); | 1040 | return i18n("Business Address Label"); |
989 | } | 1041 | } |
990 | 1042 | ||
991 | 1043 | ||
992 | QString Addressee::homePhoneLabel() | 1044 | QString Addressee::homePhoneLabel() |
993 | { | 1045 | { |
994 | return i18n("Home Phone"); | 1046 | return i18n("Home Phone"); |
995 | } | 1047 | } |
996 | 1048 | ||
997 | 1049 | ||
998 | QString Addressee::businessPhoneLabel() | 1050 | QString Addressee::businessPhoneLabel() |
999 | { | 1051 | { |
1000 | return i18n("Business Phone"); | 1052 | return i18n("Work Phone"); |
1001 | } | 1053 | } |
1002 | 1054 | ||
1003 | 1055 | ||
1004 | QString Addressee::mobilePhoneLabel() | 1056 | QString Addressee::mobilePhoneLabel() |
1005 | { | 1057 | { |
1006 | return i18n("Mobile Phone"); | 1058 | return i18n("Mobile Phone"); |
1007 | } | 1059 | } |
1008 | QString Addressee::mobileWorkPhoneLabel() | 1060 | QString Addressee::mobileWorkPhoneLabel() |
1009 | { | 1061 | { |
1010 | return i18n("Mobile (work)"); | 1062 | return i18n("Mobile2 (work)"); |
1011 | } | 1063 | } |
1012 | QString Addressee::mobileHomePhoneLabel() | 1064 | QString Addressee::mobileHomePhoneLabel() |
1013 | { | 1065 | { |
1014 | return i18n("Mobile (home)"); | 1066 | return i18n("Mobile"); |
1015 | } | 1067 | } |
1016 | 1068 | ||
1017 | 1069 | ||
1018 | QString Addressee::homeFaxLabel() | 1070 | QString Addressee::homeFaxLabel() |
1019 | { | 1071 | { |
1020 | return i18n("Home Fax"); | 1072 | return i18n("Fax (Home)"); |
1021 | } | 1073 | } |
1022 | 1074 | ||
1023 | 1075 | ||
1024 | QString Addressee::businessFaxLabel() | 1076 | QString Addressee::businessFaxLabel() |
1025 | { | 1077 | { |
1026 | return i18n("Business Fax"); | 1078 | return i18n("Fax (Work)"); |
1027 | } | 1079 | } |
1028 | 1080 | ||
1029 | 1081 | ||
1030 | QString Addressee::carPhoneLabel() | 1082 | QString Addressee::carPhoneLabel() |
1031 | { | 1083 | { |
1032 | return i18n("Car Phone"); | 1084 | return i18n("Mobile2 (work)"); |
1033 | } | 1085 | } |
1034 | 1086 | ||
1035 | 1087 | ||
1036 | QString Addressee::isdnLabel() | 1088 | QString Addressee::isdnLabel() |
1037 | { | 1089 | { |
1038 | return i18n("ISDN"); | 1090 | return i18n("ISDN"); |
1039 | } | 1091 | } |
1040 | 1092 | ||
1041 | 1093 | ||
1042 | QString Addressee::pagerLabel() | 1094 | QString Addressee::pagerLabel() |
1043 | { | 1095 | { |
1044 | return i18n("Pager"); | 1096 | return i18n("Pager"); |
1045 | } | 1097 | } |
1046 | 1098 | ||
1047 | QString Addressee::sipLabel() | 1099 | QString Addressee::sipLabel() |
1048 | { | 1100 | { |
1049 | return i18n("SIP"); | 1101 | return i18n("SIP"); |
1050 | } | 1102 | } |
1051 | 1103 | ||
1052 | QString Addressee::emailLabel() | 1104 | QString Addressee::emailLabel() |
1053 | { | 1105 | { |
1054 | return i18n("Email Address"); | 1106 | return i18n("Email Address"); |
1055 | } | 1107 | } |
1056 | 1108 | ||
1057 | 1109 | ||
1058 | void Addressee::setMailer( const QString &mailer ) | 1110 | void Addressee::setMailer( const QString &mailer ) |
1059 | { | 1111 | { |
1060 | if ( mailer == mData->mailer ) return; | 1112 | if ( mailer == mData->mailer ) return; |
1061 | detach(); | 1113 | detach(); |
1062 | mData->empty = false; | 1114 | mData->empty = false; |
1063 | mData->mailer = mailer; | 1115 | mData->mailer = mailer; |
1064 | } | 1116 | } |
1065 | 1117 | ||
1066 | QString Addressee::mailer() const | 1118 | QString Addressee::mailer() const |
1067 | { | 1119 | { |
1068 | return mData->mailer; | 1120 | return mData->mailer; |
1069 | } | 1121 | } |
1070 | 1122 | ||
1071 | QString Addressee::mailerLabel() | 1123 | QString Addressee::mailerLabel() |
1072 | { | 1124 | { |
1073 | return i18n("Mail Client"); | 1125 | return i18n("Mail Client"); |
1074 | } | 1126 | } |
1075 | 1127 | ||
1076 | 1128 | ||
1077 | void Addressee::setTimeZone( const TimeZone &timeZone ) | 1129 | void Addressee::setTimeZone( const TimeZone &timeZone ) |
1078 | { | 1130 | { |
1079 | if ( timeZone == mData->timeZone ) return; | 1131 | if ( timeZone == mData->timeZone ) return; |
1080 | detach(); | 1132 | detach(); |
1081 | mData->empty = false; | 1133 | mData->empty = false; |
1082 | mData->timeZone = timeZone; | 1134 | mData->timeZone = timeZone; |
1083 | } | 1135 | } |
1084 | 1136 | ||
1085 | TimeZone Addressee::timeZone() const | 1137 | TimeZone Addressee::timeZone() const |
1086 | { | 1138 | { |
1087 | return mData->timeZone; | 1139 | return mData->timeZone; |
1088 | } | 1140 | } |
1089 | 1141 | ||
1090 | QString Addressee::timeZoneLabel() | 1142 | QString Addressee::timeZoneLabel() |
1091 | { | 1143 | { |
1092 | return i18n("Time Zone"); | 1144 | return i18n("Time Zone"); |
1093 | } | 1145 | } |
1094 | 1146 | ||
1095 | 1147 | ||
1096 | void Addressee::setGeo( const Geo &geo ) | 1148 | void Addressee::setGeo( const Geo &geo ) |
@@ -1591,128 +1643,138 @@ void Addressee::removeEmail( const QString &email ) | |||
1591 | 1643 | ||
1592 | QString Addressee::preferredEmail() const | 1644 | QString Addressee::preferredEmail() const |
1593 | { | 1645 | { |
1594 | if ( mData->emails.count() == 0 ) return QString::null; | 1646 | if ( mData->emails.count() == 0 ) return QString::null; |
1595 | else return mData->emails.first(); | 1647 | else return mData->emails.first(); |
1596 | } | 1648 | } |
1597 | 1649 | ||
1598 | QStringList Addressee::emails() const | 1650 | QStringList Addressee::emails() const |
1599 | { | 1651 | { |
1600 | return mData->emails; | 1652 | return mData->emails; |
1601 | } | 1653 | } |
1602 | void Addressee::setEmails( const QStringList& emails ) { | 1654 | void Addressee::setEmails( const QStringList& emails ) { |
1603 | detach(); | 1655 | detach(); |
1604 | mData->emails = emails; | 1656 | mData->emails = emails; |
1605 | } | 1657 | } |
1606 | void Addressee::insertPhoneNumber( const PhoneNumber &phoneNumber ) | 1658 | void Addressee::insertPhoneNumber( const PhoneNumber &phoneNumber ) |
1607 | { | 1659 | { |
1608 | detach(); | 1660 | detach(); |
1609 | mData->empty = false; | 1661 | mData->empty = false; |
1610 | 1662 | ||
1611 | PhoneNumber::List::Iterator it; | 1663 | PhoneNumber::List::Iterator it; |
1612 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { | 1664 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { |
1613 | if ( (*it).id() == phoneNumber.id() ) { | 1665 | if ( (*it).id() == phoneNumber.id() ) { |
1614 | *it = phoneNumber; | 1666 | *it = phoneNumber; |
1615 | return; | 1667 | return; |
1616 | } | 1668 | } |
1617 | } | 1669 | } |
1618 | mData->phoneNumbers.append( phoneNumber ); | 1670 | mData->phoneNumbers.append( phoneNumber ); |
1619 | } | 1671 | } |
1620 | 1672 | ||
1621 | void Addressee::removePhoneNumber( const PhoneNumber &phoneNumber ) | 1673 | void Addressee::removePhoneNumber( const PhoneNumber &phoneNumber ) |
1622 | { | 1674 | { |
1623 | detach(); | 1675 | detach(); |
1624 | 1676 | ||
1625 | PhoneNumber::List::Iterator it; | 1677 | PhoneNumber::List::Iterator it; |
1626 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { | 1678 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { |
1627 | if ( (*it).id() == phoneNumber.id() ) { | 1679 | if ( (*it).id() == phoneNumber.id() ) { |
1628 | mData->phoneNumbers.remove( it ); | 1680 | mData->phoneNumbers.remove( it ); |
1629 | return; | 1681 | return; |
1630 | } | 1682 | } |
1631 | } | 1683 | } |
1632 | } | 1684 | } |
1633 | 1685 | ||
1634 | PhoneNumber Addressee::phoneNumber( int type ) const | 1686 | PhoneNumber Addressee::phoneNumber( int type ) const |
1635 | { | 1687 | { |
1636 | PhoneNumber phoneNumber( "", type ); | 1688 | PhoneNumber phoneNumber( "", type ); |
1637 | PhoneNumber::List::ConstIterator it; | 1689 | PhoneNumber::List::ConstIterator it; |
1638 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { | 1690 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { |
1639 | if ( matchBinaryPatternP( (*it).type(), type ) ) { | 1691 | if ( matchBinaryPatternP( (*it).type(), type ) ) { |
1640 | if ( (*it).type() & PhoneNumber::Pref ) | 1692 | if ( (*it).type() & PhoneNumber::Pref ) |
1641 | return (*it); | 1693 | return (*it); |
1642 | else if ( phoneNumber.number().isEmpty() ) | 1694 | else if ( phoneNumber.number().isEmpty() ) |
1643 | phoneNumber = (*it); | 1695 | phoneNumber = (*it); |
1644 | } | 1696 | } |
1645 | } | 1697 | } |
1646 | 1698 | ||
1647 | return phoneNumber; | 1699 | return phoneNumber; |
1648 | } | 1700 | } |
1649 | 1701 | ||
1650 | PhoneNumber::List Addressee::phoneNumbers() const | 1702 | PhoneNumber::List Addressee::phoneNumbers() const |
1651 | { | 1703 | { |
1652 | return mData->phoneNumbers; | 1704 | return mData->phoneNumbers; |
1653 | } | 1705 | } |
1654 | 1706 | ||
1707 | int Addressee::hasPhoneNumberType( int type ) | ||
1708 | { | ||
1709 | int retval = 0; | ||
1710 | PhoneNumber::List::ConstIterator it; | ||
1711 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { | ||
1712 | if ( (*it).type() == type ) | ||
1713 | ++retval; | ||
1714 | } | ||
1715 | return retval; | ||
1716 | } | ||
1655 | PhoneNumber::List Addressee::phoneNumbers( int type ) const | 1717 | PhoneNumber::List Addressee::phoneNumbers( int type ) const |
1656 | { | 1718 | { |
1657 | PhoneNumber::List list; | 1719 | PhoneNumber::List list; |
1658 | 1720 | ||
1659 | PhoneNumber::List::ConstIterator it; | 1721 | PhoneNumber::List::ConstIterator it; |
1660 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { | 1722 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { |
1661 | if ( matchBinaryPattern( (*it).type(), type ) ) { | 1723 | if ( matchBinaryPattern( (*it).type(), type ) ) { |
1662 | list.append( *it ); | 1724 | list.append( *it ); |
1663 | } | 1725 | } |
1664 | } | 1726 | } |
1665 | return list; | 1727 | return list; |
1666 | } | 1728 | } |
1667 | 1729 | ||
1668 | PhoneNumber Addressee::findPhoneNumber( const QString &id ) const | 1730 | PhoneNumber Addressee::findPhoneNumber( const QString &id ) const |
1669 | { | 1731 | { |
1670 | PhoneNumber::List::ConstIterator it; | 1732 | PhoneNumber::List::ConstIterator it; |
1671 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { | 1733 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { |
1672 | if ( (*it).id() == id ) { | 1734 | if ( (*it).id() == id ) { |
1673 | return *it; | 1735 | return *it; |
1674 | } | 1736 | } |
1675 | } | 1737 | } |
1676 | return PhoneNumber(); | 1738 | return PhoneNumber(); |
1677 | } | 1739 | } |
1678 | 1740 | ||
1679 | void Addressee::insertKey( const Key &key ) | 1741 | void Addressee::insertKey( const Key &key ) |
1680 | { | 1742 | { |
1681 | detach(); | 1743 | detach(); |
1682 | mData->empty = false; | 1744 | mData->empty = false; |
1683 | 1745 | ||
1684 | Key::List::Iterator it; | 1746 | Key::List::Iterator it; |
1685 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { | 1747 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { |
1686 | if ( (*it).id() == key.id() ) { | 1748 | if ( (*it).id() == key.id() ) { |
1687 | *it = key; | 1749 | *it = key; |
1688 | return; | 1750 | return; |
1689 | } | 1751 | } |
1690 | } | 1752 | } |
1691 | mData->keys.append( key ); | 1753 | mData->keys.append( key ); |
1692 | } | 1754 | } |
1693 | 1755 | ||
1694 | void Addressee::removeKey( const Key &key ) | 1756 | void Addressee::removeKey( const Key &key ) |
1695 | { | 1757 | { |
1696 | detach(); | 1758 | detach(); |
1697 | 1759 | ||
1698 | Key::List::Iterator it; | 1760 | Key::List::Iterator it; |
1699 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { | 1761 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { |
1700 | if ( (*it).id() == key.id() ) { | 1762 | if ( (*it).id() == key.id() ) { |
1701 | mData->keys.remove( key ); | 1763 | mData->keys.remove( key ); |
1702 | return; | 1764 | return; |
1703 | } | 1765 | } |
1704 | } | 1766 | } |
1705 | } | 1767 | } |
1706 | 1768 | ||
1707 | Key Addressee::key( int type, QString customTypeString ) const | 1769 | Key Addressee::key( int type, QString customTypeString ) const |
1708 | { | 1770 | { |
1709 | Key::List::ConstIterator it; | 1771 | Key::List::ConstIterator it; |
1710 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { | 1772 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { |
1711 | if ( (*it).type() == type ) { | 1773 | if ( (*it).type() == type ) { |
1712 | if ( type == Key::Custom ) { | 1774 | if ( type == Key::Custom ) { |
1713 | if ( customTypeString.isEmpty() ) { | 1775 | if ( customTypeString.isEmpty() ) { |
1714 | return *it; | 1776 | return *it; |
1715 | } else { | 1777 | } else { |
1716 | if ( (*it).customTypeString() == customTypeString ) | 1778 | if ( (*it).customTypeString() == customTypeString ) |
1717 | return (*it); | 1779 | return (*it); |
1718 | } | 1780 | } |