summaryrefslogtreecommitdiffabout
path: root/kabc/addressee.cpp
authorzautrix <zautrix>2004-09-13 21:35:12 (UTC)
committer zautrix <zautrix>2004-09-13 21:35:12 (UTC)
commitbd6b4acb39498ffea3beea7d9b5f7620b60c14db (patch) (unidiff)
treee2d7425b7bb49fbcb7acb5ced497ac1fed06dfaf /kabc/addressee.cpp
parent06eabf6e82c0390699d11fd12580d91261829431 (diff)
downloadkdepimpi-bd6b4acb39498ffea3beea7d9b5f7620b60c14db.zip
kdepimpi-bd6b4acb39498ffea3beea7d9b5f7620b60c14db.tar.gz
kdepimpi-bd6b4acb39498ffea3beea7d9b5f7620b60c14db.tar.bz2
Many bugfixes
Diffstat (limited to 'kabc/addressee.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressee.cpp62
1 files changed, 33 insertions, 29 deletions
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index 6b282e2..4cdd5e5 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -420,797 +420,801 @@ QString Addressee::businessAddressPostalCodeLabel()
420 return i18n("Business Address Postal Code"); 420 return i18n("Business Address Postal Code");
421} 421}
422 422
423 423
424QString Addressee::businessAddressCountryLabel() 424QString Addressee::businessAddressCountryLabel()
425{ 425{
426 return i18n("Business Address Country"); 426 return i18n("Business Address Country");
427} 427}
428 428
429 429
430QString Addressee::businessAddressLabelLabel() 430QString Addressee::businessAddressLabelLabel()
431{ 431{
432 return i18n("Business Address Label"); 432 return i18n("Business Address Label");
433} 433}
434 434
435 435
436QString Addressee::homePhoneLabel() 436QString Addressee::homePhoneLabel()
437{ 437{
438 return i18n("Home Phone"); 438 return i18n("Home Phone");
439} 439}
440 440
441 441
442QString Addressee::businessPhoneLabel() 442QString Addressee::businessPhoneLabel()
443{ 443{
444 return i18n("Business Phone"); 444 return i18n("Business Phone");
445} 445}
446 446
447 447
448QString Addressee::mobilePhoneLabel() 448QString Addressee::mobilePhoneLabel()
449{ 449{
450 return i18n("Mobile Phone"); 450 return i18n("Mobile Phone");
451} 451}
452 452
453 453
454QString Addressee::homeFaxLabel() 454QString Addressee::homeFaxLabel()
455{ 455{
456 return i18n("Home Fax"); 456 return i18n("Home Fax");
457} 457}
458 458
459 459
460QString Addressee::businessFaxLabel() 460QString Addressee::businessFaxLabel()
461{ 461{
462 return i18n("Business Fax"); 462 return i18n("Business Fax");
463} 463}
464 464
465 465
466QString Addressee::carPhoneLabel() 466QString Addressee::carPhoneLabel()
467{ 467{
468 return i18n("Car Phone"); 468 return i18n("Car Phone");
469} 469}
470 470
471 471
472QString Addressee::isdnLabel() 472QString Addressee::isdnLabel()
473{ 473{
474 return i18n("ISDN"); 474 return i18n("ISDN");
475} 475}
476 476
477 477
478QString Addressee::pagerLabel() 478QString Addressee::pagerLabel()
479{ 479{
480 return i18n("Pager"); 480 return i18n("Pager");
481} 481}
482 482
483QString Addressee::sipLabel() 483QString Addressee::sipLabel()
484{ 484{
485 return i18n("SIP"); 485 return i18n("SIP");
486} 486}
487 487
488QString Addressee::emailLabel() 488QString Addressee::emailLabel()
489{ 489{
490 return i18n("Email Address"); 490 return i18n("Email Address");
491} 491}
492 492
493 493
494void Addressee::setMailer( const QString &mailer ) 494void Addressee::setMailer( const QString &mailer )
495{ 495{
496 if ( mailer == mData->mailer ) return; 496 if ( mailer == mData->mailer ) return;
497 detach(); 497 detach();
498 mData->empty = false; 498 mData->empty = false;
499 mData->mailer = mailer; 499 mData->mailer = mailer;
500} 500}
501 501
502QString Addressee::mailer() const 502QString Addressee::mailer() const
503{ 503{
504 return mData->mailer; 504 return mData->mailer;
505} 505}
506 506
507QString Addressee::mailerLabel() 507QString Addressee::mailerLabel()
508{ 508{
509 return i18n("Mail Client"); 509 return i18n("Mail Client");
510} 510}
511 511
512 512
513void Addressee::setTimeZone( const TimeZone &timeZone ) 513void Addressee::setTimeZone( const TimeZone &timeZone )
514{ 514{
515 if ( timeZone == mData->timeZone ) return; 515 if ( timeZone == mData->timeZone ) return;
516 detach(); 516 detach();
517 mData->empty = false; 517 mData->empty = false;
518 mData->timeZone = timeZone; 518 mData->timeZone = timeZone;
519} 519}
520 520
521TimeZone Addressee::timeZone() const 521TimeZone Addressee::timeZone() const
522{ 522{
523 return mData->timeZone; 523 return mData->timeZone;
524} 524}
525 525
526QString Addressee::timeZoneLabel() 526QString Addressee::timeZoneLabel()
527{ 527{
528 return i18n("Time Zone"); 528 return i18n("Time Zone");
529} 529}
530 530
531 531
532void Addressee::setGeo( const Geo &geo ) 532void Addressee::setGeo( const Geo &geo )
533{ 533{
534 if ( geo == mData->geo ) return; 534 if ( geo == mData->geo ) return;
535 detach(); 535 detach();
536 mData->empty = false; 536 mData->empty = false;
537 mData->geo = geo; 537 mData->geo = geo;
538} 538}
539 539
540Geo Addressee::geo() const 540Geo Addressee::geo() const
541{ 541{
542 return mData->geo; 542 return mData->geo;
543} 543}
544 544
545QString Addressee::geoLabel() 545QString Addressee::geoLabel()
546{ 546{
547 return i18n("Geographic Position"); 547 return i18n("Geographic Position");
548} 548}
549 549
550 550
551void Addressee::setTitle( const QString &title ) 551void Addressee::setTitle( const QString &title )
552{ 552{
553 if ( title == mData->title ) return; 553 if ( title == mData->title ) return;
554 detach(); 554 detach();
555 mData->empty = false; 555 mData->empty = false;
556 mData->title = title; 556 mData->title = title;
557} 557}
558 558
559QString Addressee::title() const 559QString Addressee::title() const
560{ 560{
561 return mData->title; 561 return mData->title;
562} 562}
563 563
564QString Addressee::titleLabel() 564QString Addressee::titleLabel()
565{ 565{
566 return i18n("Title"); 566 return i18n("Title");
567} 567}
568 568
569 569
570void Addressee::setRole( const QString &role ) 570void Addressee::setRole( const QString &role )
571{ 571{
572 if ( role == mData->role ) return; 572 if ( role == mData->role ) return;
573 detach(); 573 detach();
574 mData->empty = false; 574 mData->empty = false;
575 mData->role = role; 575 mData->role = role;
576} 576}
577 577
578QString Addressee::role() const 578QString Addressee::role() const
579{ 579{
580 return mData->role; 580 return mData->role;
581} 581}
582 582
583QString Addressee::roleLabel() 583QString Addressee::roleLabel()
584{ 584{
585 return i18n("Role"); 585 return i18n("Role");
586} 586}
587 587
588 588
589void Addressee::setOrganization( const QString &organization ) 589void Addressee::setOrganization( const QString &organization )
590{ 590{
591 if ( organization == mData->organization ) return; 591 if ( organization == mData->organization ) return;
592 detach(); 592 detach();
593 mData->empty = false; 593 mData->empty = false;
594 mData->organization = organization; 594 mData->organization = organization;
595} 595}
596 596
597QString Addressee::organization() const 597QString Addressee::organization() const
598{ 598{
599 return mData->organization; 599 return mData->organization;
600} 600}
601 601
602QString Addressee::organizationLabel() 602QString Addressee::organizationLabel()
603{ 603{
604 return i18n("Organization"); 604 return i18n("Organization");
605} 605}
606 606
607 607
608void Addressee::setNote( const QString &note ) 608void Addressee::setNote( const QString &note )
609{ 609{
610 if ( note == mData->note ) return; 610 if ( note == mData->note ) return;
611 detach(); 611 detach();
612 mData->empty = false; 612 mData->empty = false;
613 mData->note = note; 613 mData->note = note;
614} 614}
615 615
616QString Addressee::note() const 616QString Addressee::note() const
617{ 617{
618 return mData->note; 618 return mData->note;
619} 619}
620 620
621QString Addressee::noteLabel() 621QString Addressee::noteLabel()
622{ 622{
623 return i18n("Note"); 623 return i18n("Note");
624} 624}
625 625
626 626
627void Addressee::setProductId( const QString &productId ) 627void Addressee::setProductId( const QString &productId )
628{ 628{
629 if ( productId == mData->productId ) return; 629 if ( productId == mData->productId ) return;
630 detach(); 630 detach();
631 mData->empty = false; 631 mData->empty = false;
632 mData->productId = productId; 632 mData->productId = productId;
633} 633}
634 634
635QString Addressee::productId() const 635QString Addressee::productId() const
636{ 636{
637 return mData->productId; 637 return mData->productId;
638} 638}
639 639
640QString Addressee::productIdLabel() 640QString Addressee::productIdLabel()
641{ 641{
642 return i18n("Product Identifier"); 642 return i18n("Product Identifier");
643} 643}
644 644
645 645
646void Addressee::setRevision( const QDateTime &revision ) 646void Addressee::setRevision( const QDateTime &revision )
647{ 647{
648 if ( revision == mData->revision ) return; 648 if ( revision == mData->revision ) return;
649 detach(); 649 detach();
650 mData->empty = false; 650 mData->empty = false;
651 mData->revision = revision; 651 mData->revision = revision;
652} 652}
653 653
654QDateTime Addressee::revision() const 654QDateTime Addressee::revision() const
655{ 655{
656 return mData->revision; 656 return mData->revision;
657} 657}
658 658
659QString Addressee::revisionLabel() 659QString Addressee::revisionLabel()
660{ 660{
661 return i18n("Revision Date"); 661 return i18n("Revision Date");
662} 662}
663 663
664 664
665void Addressee::setSortString( const QString &sortString ) 665void Addressee::setSortString( const QString &sortString )
666{ 666{
667 if ( sortString == mData->sortString ) return; 667 if ( sortString == mData->sortString ) return;
668 detach(); 668 detach();
669 mData->empty = false; 669 mData->empty = false;
670 mData->sortString = sortString; 670 mData->sortString = sortString;
671} 671}
672 672
673QString Addressee::sortString() const 673QString Addressee::sortString() const
674{ 674{
675 return mData->sortString; 675 return mData->sortString;
676} 676}
677 677
678QString Addressee::sortStringLabel() 678QString Addressee::sortStringLabel()
679{ 679{
680 return i18n("Sort String"); 680 return i18n("Sort String");
681} 681}
682 682
683 683
684void Addressee::setUrl( const KURL &url ) 684void Addressee::setUrl( const KURL &url )
685{ 685{
686 if ( url == mData->url ) return; 686 if ( url == mData->url ) return;
687 detach(); 687 detach();
688 mData->empty = false; 688 mData->empty = false;
689 mData->url = url; 689 mData->url = url;
690} 690}
691 691
692KURL Addressee::url() const 692KURL Addressee::url() const
693{ 693{
694 return mData->url; 694 return mData->url;
695} 695}
696 696
697QString Addressee::urlLabel() 697QString Addressee::urlLabel()
698{ 698{
699 return i18n("URL"); 699 return i18n("URL");
700} 700}
701 701
702 702
703void Addressee::setSecrecy( const Secrecy &secrecy ) 703void Addressee::setSecrecy( const Secrecy &secrecy )
704{ 704{
705 if ( secrecy == mData->secrecy ) return; 705 if ( secrecy == mData->secrecy ) return;
706 detach(); 706 detach();
707 mData->empty = false; 707 mData->empty = false;
708 mData->secrecy = secrecy; 708 mData->secrecy = secrecy;
709} 709}
710 710
711Secrecy Addressee::secrecy() const 711Secrecy Addressee::secrecy() const
712{ 712{
713 return mData->secrecy; 713 return mData->secrecy;
714} 714}
715 715
716QString Addressee::secrecyLabel() 716QString Addressee::secrecyLabel()
717{ 717{
718 return i18n("Security Class"); 718 return i18n("Security Class");
719} 719}
720 720
721 721
722void Addressee::setLogo( const Picture &logo ) 722void Addressee::setLogo( const Picture &logo )
723{ 723{
724 if ( logo == mData->logo ) return; 724 if ( logo == mData->logo ) return;
725 detach(); 725 detach();
726 mData->empty = false; 726 mData->empty = false;
727 mData->logo = logo; 727 mData->logo = logo;
728} 728}
729 729
730Picture Addressee::logo() const 730Picture Addressee::logo() const
731{ 731{
732 return mData->logo; 732 return mData->logo;
733} 733}
734 734
735QString Addressee::logoLabel() 735QString Addressee::logoLabel()
736{ 736{
737 return i18n("Logo"); 737 return i18n("Logo");
738} 738}
739 739
740 740
741void Addressee::setPhoto( const Picture &photo ) 741void Addressee::setPhoto( const Picture &photo )
742{ 742{
743 if ( photo == mData->photo ) return; 743 if ( photo == mData->photo ) return;
744 detach(); 744 detach();
745 mData->empty = false; 745 mData->empty = false;
746 mData->photo = photo; 746 mData->photo = photo;
747} 747}
748 748
749Picture Addressee::photo() const 749Picture Addressee::photo() const
750{ 750{
751 return mData->photo; 751 return mData->photo;
752} 752}
753 753
754QString Addressee::photoLabel() 754QString Addressee::photoLabel()
755{ 755{
756 return i18n("Photo"); 756 return i18n("Photo");
757} 757}
758 758
759 759
760void Addressee::setSound( const Sound &sound ) 760void Addressee::setSound( const Sound &sound )
761{ 761{
762 if ( sound == mData->sound ) return; 762 if ( sound == mData->sound ) return;
763 detach(); 763 detach();
764 mData->empty = false; 764 mData->empty = false;
765 mData->sound = sound; 765 mData->sound = sound;
766} 766}
767 767
768Sound Addressee::sound() const 768Sound Addressee::sound() const
769{ 769{
770 return mData->sound; 770 return mData->sound;
771} 771}
772 772
773QString Addressee::soundLabel() 773QString Addressee::soundLabel()
774{ 774{
775 return i18n("Sound"); 775 return i18n("Sound");
776} 776}
777 777
778 778
779void Addressee::setAgent( const Agent &agent ) 779void Addressee::setAgent( const Agent &agent )
780{ 780{
781 if ( agent == mData->agent ) return; 781 if ( agent == mData->agent ) return;
782 detach(); 782 detach();
783 mData->empty = false; 783 mData->empty = false;
784 mData->agent = agent; 784 mData->agent = agent;
785} 785}
786 786
787Agent Addressee::agent() const 787Agent Addressee::agent() const
788{ 788{
789 return mData->agent; 789 return mData->agent;
790} 790}
791 791
792QString Addressee::agentLabel() 792QString Addressee::agentLabel()
793{ 793{
794 return i18n("Agent"); 794 return i18n("Agent");
795} 795}
796 796
797 797
798 798
799void Addressee::setNameFromString( const QString &str ) 799void Addressee::setNameFromString( const QString &str )
800{ 800{
801 setFormattedName( str ); 801 setFormattedName( str );
802 setName( str ); 802 setName( str );
803 803
804 QStringList titles; 804 static bool first = true;
805 titles += i18n( "Dr." ); 805 static QStringList titles;
806 titles += i18n( "Miss" ); 806 static QStringList suffixes;
807 titles += i18n( "Mr." ); 807 static QStringList prefixes;
808 titles += i18n( "Mrs." ); 808
809 titles += i18n( "Ms." ); 809 if ( first ) {
810 titles += i18n( "Prof." ); 810 first = false;
811 811 titles += i18n( "Dr." );
812 QStringList suffixes; 812 titles += i18n( "Miss" );
813 suffixes += i18n( "I" ); 813 titles += i18n( "Mr." );
814 suffixes += i18n( "II" ); 814 titles += i18n( "Mrs." );
815 suffixes += i18n( "III" ); 815 titles += i18n( "Ms." );
816 suffixes += i18n( "Jr." ); 816 titles += i18n( "Prof." );
817 suffixes += i18n( "Sr." ); 817
818 818 suffixes += i18n( "I" );
819 QStringList prefixes; 819 suffixes += i18n( "II" );
820 prefixes += "van"; 820 suffixes += i18n( "III" );
821 prefixes += "von"; 821 suffixes += i18n( "Jr." );
822 prefixes += "de"; 822 suffixes += i18n( "Sr." );
823 823
824//US KConfig config( "kabcrc" ); 824 prefixes += "van";
825 KConfig config( locateLocal( "config", "kabcrc") ); 825 prefixes += "von";
826 config.setGroup( "General" ); 826 prefixes += "de";
827 titles += config.readListEntry( "Prefixes" ); 827
828 titles.remove( "" ); 828 KConfig config( locateLocal( "config", "kabcrc") );
829 prefixes += config.readListEntry( "Inclusions" ); 829 config.setGroup( "General" );
830 prefixes.remove( "" ); 830 titles += config.readListEntry( "Prefixes" );
831 suffixes += config.readListEntry( "Suffixes" ); 831 titles.remove( "" );
832 suffixes.remove( "" ); 832 prefixes += config.readListEntry( "Inclusions" );
833 prefixes.remove( "" );
834 suffixes += config.readListEntry( "Suffixes" );
835 suffixes.remove( "" );
836 }
833 837
834 // clear all name parts 838 // clear all name parts
835 setPrefix( "" ); 839 setPrefix( "" );
836 setGivenName( "" ); 840 setGivenName( "" );
837 setAdditionalName( "" ); 841 setAdditionalName( "" );
838 setFamilyName( "" ); 842 setFamilyName( "" );
839 setSuffix( "" ); 843 setSuffix( "" );
840 844
841 if ( str.isEmpty() ) 845 if ( str.isEmpty() )
842 return; 846 return;
843 847
844 int i = str.find(','); 848 int i = str.find(',');
845 if( i < 0 ) { 849 if( i < 0 ) {
846 QStringList parts = QStringList::split( " ", str ); 850 QStringList parts = QStringList::split( " ", str );
847 int leftOffset = 0; 851 int leftOffset = 0;
848 int rightOffset = parts.count() - 1; 852 int rightOffset = parts.count() - 1;
849 853
850 QString suffix; 854 QString suffix;
851 while ( rightOffset >= 0 ) { 855 while ( rightOffset >= 0 ) {
852 if ( suffixes.contains( parts[ rightOffset ] ) ) { 856 if ( suffixes.contains( parts[ rightOffset ] ) ) {
853 suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " ")); 857 suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " "));
854 rightOffset--; 858 rightOffset--;
855 } else 859 } else
856 break; 860 break;
857 } 861 }
858 setSuffix( suffix ); 862 setSuffix( suffix );
859 863
860 if ( rightOffset < 0 ) 864 if ( rightOffset < 0 )
861 return; 865 return;
862 866
863 if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) { 867 if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) {
864 setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] ); 868 setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] );
865 rightOffset--; 869 rightOffset--;
866 } else 870 } else
867 setFamilyName( parts[ rightOffset ] ); 871 setFamilyName( parts[ rightOffset ] );
868 872
869 QString prefix; 873 QString prefix;
870 while ( leftOffset < rightOffset ) { 874 while ( leftOffset < rightOffset ) {
871 if ( titles.contains( parts[ leftOffset ] ) ) { 875 if ( titles.contains( parts[ leftOffset ] ) ) {
872 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); 876 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] );
873 leftOffset++; 877 leftOffset++;
874 } else 878 } else
875 break; 879 break;
876 } 880 }
877 setPrefix( prefix ); 881 setPrefix( prefix );
878 882
879 if ( leftOffset < rightOffset ) { 883 if ( leftOffset < rightOffset ) {
880 setGivenName( parts[ leftOffset ] ); 884 setGivenName( parts[ leftOffset ] );
881 leftOffset++; 885 leftOffset++;
882 } 886 }
883 887
884 QString additionalName; 888 QString additionalName;
885 while ( leftOffset < rightOffset ) { 889 while ( leftOffset < rightOffset ) {
886 additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] ); 890 additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] );
887 leftOffset++; 891 leftOffset++;
888 } 892 }
889 setAdditionalName( additionalName ); 893 setAdditionalName( additionalName );
890 } else { 894 } else {
891 QString part1 = str.left( i ); 895 QString part1 = str.left( i );
892 QString part2 = str.mid( i + 1 ); 896 QString part2 = str.mid( i + 1 );
893 897
894 QStringList parts = QStringList::split( " ", part1 ); 898 QStringList parts = QStringList::split( " ", part1 );
895 int leftOffset = 0; 899 int leftOffset = 0;
896 int rightOffset = parts.count() - 1; 900 int rightOffset = parts.count() - 1;
897 901
898 QString suffix; 902 QString suffix;
899 while ( rightOffset >= 0 ) { 903 while ( rightOffset >= 0 ) {
900 if ( suffixes.contains( parts[ rightOffset ] ) ) { 904 if ( suffixes.contains( parts[ rightOffset ] ) ) {
901 suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " ")); 905 suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " "));
902 rightOffset--; 906 rightOffset--;
903 } else 907 } else
904 break; 908 break;
905 } 909 }
906 setSuffix( suffix ); 910 setSuffix( suffix );
907 911
908 if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) { 912 if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) {
909 setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] ); 913 setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] );
910 rightOffset--; 914 rightOffset--;
911 } else 915 } else
912 setFamilyName( parts[ rightOffset ] ); 916 setFamilyName( parts[ rightOffset ] );
913 917
914 QString prefix; 918 QString prefix;
915 while ( leftOffset < rightOffset ) { 919 while ( leftOffset < rightOffset ) {
916 if ( titles.contains( parts[ leftOffset ] ) ) { 920 if ( titles.contains( parts[ leftOffset ] ) ) {
917 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); 921 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] );
918 leftOffset++; 922 leftOffset++;
919 } else 923 } else
920 break; 924 break;
921 } 925 }
922 926
923 parts = QStringList::split( " ", part2 ); 927 parts = QStringList::split( " ", part2 );
924 928
925 leftOffset = 0; 929 leftOffset = 0;
926 rightOffset = parts.count(); 930 rightOffset = parts.count();
927 931
928 while ( leftOffset < rightOffset ) { 932 while ( leftOffset < rightOffset ) {
929 if ( titles.contains( parts[ leftOffset ] ) ) { 933 if ( titles.contains( parts[ leftOffset ] ) ) {
930 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); 934 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] );
931 leftOffset++; 935 leftOffset++;
932 } else 936 } else
933 break; 937 break;
934 } 938 }
935 setPrefix( prefix ); 939 setPrefix( prefix );
936 940
937 if ( leftOffset < rightOffset ) { 941 if ( leftOffset < rightOffset ) {
938 setGivenName( parts[ leftOffset ] ); 942 setGivenName( parts[ leftOffset ] );
939 leftOffset++; 943 leftOffset++;
940 } 944 }
941 945
942 QString additionalName; 946 QString additionalName;
943 while ( leftOffset < rightOffset ) { 947 while ( leftOffset < rightOffset ) {
944 additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] ); 948 additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] );
945 leftOffset++; 949 leftOffset++;
946 } 950 }
947 setAdditionalName( additionalName ); 951 setAdditionalName( additionalName );
948 } 952 }
949} 953}
950 954
951QString Addressee::realName() const 955QString Addressee::realName() const
952{ 956{
953 if ( !formattedName().isEmpty() ) 957 if ( !formattedName().isEmpty() )
954 return formattedName(); 958 return formattedName();
955 959
956 QString n = assembledName(); 960 QString n = assembledName();
957 961
958 if ( n.isEmpty() ) 962 if ( n.isEmpty() )
959 n = name(); 963 n = name();
960 964
961 return n; 965 return n;
962} 966}
963 967
964QString Addressee::assembledName() const 968QString Addressee::assembledName() const
965{ 969{
966 QString name = prefix() + " " + givenName() + " " + additionalName() + " " + 970 QString name = prefix() + " " + givenName() + " " + additionalName() + " " +
967 familyName() + " " + suffix(); 971 familyName() + " " + suffix();
968 972
969 return name.simplifyWhiteSpace(); 973 return name.simplifyWhiteSpace();
970} 974}
971 975
972QString Addressee::fullEmail( const QString &email ) const 976QString Addressee::fullEmail( const QString &email ) const
973{ 977{
974 QString e; 978 QString e;
975 if ( email.isNull() ) { 979 if ( email.isNull() ) {
976 e = preferredEmail(); 980 e = preferredEmail();
977 } else { 981 } else {
978 e = email; 982 e = email;
979 } 983 }
980 if ( e.isEmpty() ) return QString::null; 984 if ( e.isEmpty() ) return QString::null;
981 985
982 QString text; 986 QString text;
983 if ( realName().isEmpty() ) 987 if ( realName().isEmpty() )
984 text = e; 988 text = e;
985 else 989 else
986 text = assembledName() + " <" + e + ">"; 990 text = assembledName() + " <" + e + ">";
987 991
988 return text; 992 return text;
989} 993}
990 994
991void Addressee::insertEmail( const QString &email, bool preferred ) 995void Addressee::insertEmail( const QString &email, bool preferred )
992{ 996{
993 detach(); 997 detach();
994 998
995 QStringList::Iterator it = mData->emails.find( email ); 999 QStringList::Iterator it = mData->emails.find( email );
996 1000
997 if ( it != mData->emails.end() ) { 1001 if ( it != mData->emails.end() ) {
998 if ( !preferred || it == mData->emails.begin() ) return; 1002 if ( !preferred || it == mData->emails.begin() ) return;
999 mData->emails.remove( it ); 1003 mData->emails.remove( it );
1000 mData->emails.prepend( email ); 1004 mData->emails.prepend( email );
1001 } else { 1005 } else {
1002 if ( preferred ) { 1006 if ( preferred ) {
1003 mData->emails.prepend( email ); 1007 mData->emails.prepend( email );
1004 } else { 1008 } else {
1005 mData->emails.append( email ); 1009 mData->emails.append( email );
1006 } 1010 }
1007 } 1011 }
1008} 1012}
1009 1013
1010void Addressee::removeEmail( const QString &email ) 1014void Addressee::removeEmail( const QString &email )
1011{ 1015{
1012 detach(); 1016 detach();
1013 1017
1014 QStringList::Iterator it = mData->emails.find( email ); 1018 QStringList::Iterator it = mData->emails.find( email );
1015 if ( it == mData->emails.end() ) return; 1019 if ( it == mData->emails.end() ) return;
1016 1020
1017 mData->emails.remove( it ); 1021 mData->emails.remove( it );
1018} 1022}
1019 1023
1020QString Addressee::preferredEmail() const 1024QString Addressee::preferredEmail() const
1021{ 1025{
1022 if ( mData->emails.count() == 0 ) return QString::null; 1026 if ( mData->emails.count() == 0 ) return QString::null;
1023 else return mData->emails.first(); 1027 else return mData->emails.first();
1024} 1028}
1025 1029
1026QStringList Addressee::emails() const 1030QStringList Addressee::emails() const
1027{ 1031{
1028 return mData->emails; 1032 return mData->emails;
1029} 1033}
1030void Addressee::setEmails( const QStringList& emails ) { 1034void Addressee::setEmails( const QStringList& emails ) {
1031 detach(); 1035 detach();
1032 mData->emails = emails; 1036 mData->emails = emails;
1033} 1037}
1034void Addressee::insertPhoneNumber( const PhoneNumber &phoneNumber ) 1038void Addressee::insertPhoneNumber( const PhoneNumber &phoneNumber )
1035{ 1039{
1036 detach(); 1040 detach();
1037 mData->empty = false; 1041 mData->empty = false;
1038 1042
1039 PhoneNumber::List::Iterator it; 1043 PhoneNumber::List::Iterator it;
1040 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 1044 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1041 if ( (*it).id() == phoneNumber.id() ) { 1045 if ( (*it).id() == phoneNumber.id() ) {
1042 *it = phoneNumber; 1046 *it = phoneNumber;
1043 return; 1047 return;
1044 } 1048 }
1045 } 1049 }
1046 mData->phoneNumbers.append( phoneNumber ); 1050 mData->phoneNumbers.append( phoneNumber );
1047} 1051}
1048 1052
1049void Addressee::removePhoneNumber( const PhoneNumber &phoneNumber ) 1053void Addressee::removePhoneNumber( const PhoneNumber &phoneNumber )
1050{ 1054{
1051 detach(); 1055 detach();
1052 1056
1053 PhoneNumber::List::Iterator it; 1057 PhoneNumber::List::Iterator it;
1054 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 1058 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1055 if ( (*it).id() == phoneNumber.id() ) { 1059 if ( (*it).id() == phoneNumber.id() ) {
1056 mData->phoneNumbers.remove( it ); 1060 mData->phoneNumbers.remove( it );
1057 return; 1061 return;
1058 } 1062 }
1059 } 1063 }
1060} 1064}
1061 1065
1062PhoneNumber Addressee::phoneNumber( int type ) const 1066PhoneNumber Addressee::phoneNumber( int type ) const
1063{ 1067{
1064 PhoneNumber phoneNumber( "", type ); 1068 PhoneNumber phoneNumber( "", type );
1065 PhoneNumber::List::ConstIterator it; 1069 PhoneNumber::List::ConstIterator it;
1066 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 1070 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1067 if ( matchBinaryPattern( (*it).type(), type ) ) { 1071 if ( matchBinaryPattern( (*it).type(), type ) ) {
1068 if ( (*it).type() & PhoneNumber::Pref ) 1072 if ( (*it).type() & PhoneNumber::Pref )
1069 return (*it); 1073 return (*it);
1070 else if ( phoneNumber.number().isEmpty() ) 1074 else if ( phoneNumber.number().isEmpty() )
1071 phoneNumber = (*it); 1075 phoneNumber = (*it);
1072 } 1076 }
1073 } 1077 }
1074 1078
1075 return phoneNumber; 1079 return phoneNumber;
1076} 1080}
1077 1081
1078PhoneNumber::List Addressee::phoneNumbers() const 1082PhoneNumber::List Addressee::phoneNumbers() const
1079{ 1083{
1080 return mData->phoneNumbers; 1084 return mData->phoneNumbers;
1081} 1085}
1082 1086
1083PhoneNumber::List Addressee::phoneNumbers( int type ) const 1087PhoneNumber::List Addressee::phoneNumbers( int type ) const
1084{ 1088{
1085 PhoneNumber::List list; 1089 PhoneNumber::List list;
1086 1090
1087 PhoneNumber::List::ConstIterator it; 1091 PhoneNumber::List::ConstIterator it;
1088 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 1092 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1089 if ( matchBinaryPattern( (*it).type(), type ) ) { 1093 if ( matchBinaryPattern( (*it).type(), type ) ) {
1090 list.append( *it ); 1094 list.append( *it );
1091 } 1095 }
1092 } 1096 }
1093 return list; 1097 return list;
1094} 1098}
1095 1099
1096PhoneNumber Addressee::findPhoneNumber( const QString &id ) const 1100PhoneNumber Addressee::findPhoneNumber( const QString &id ) const
1097{ 1101{
1098 PhoneNumber::List::ConstIterator it; 1102 PhoneNumber::List::ConstIterator it;
1099 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 1103 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1100 if ( (*it).id() == id ) { 1104 if ( (*it).id() == id ) {
1101 return *it; 1105 return *it;
1102 } 1106 }
1103 } 1107 }
1104 return PhoneNumber(); 1108 return PhoneNumber();
1105} 1109}
1106 1110
1107void Addressee::insertKey( const Key &key ) 1111void Addressee::insertKey( const Key &key )
1108{ 1112{
1109 detach(); 1113 detach();
1110 mData->empty = false; 1114 mData->empty = false;
1111 1115
1112 Key::List::Iterator it; 1116 Key::List::Iterator it;
1113 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1117 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1114 if ( (*it).id() == key.id() ) { 1118 if ( (*it).id() == key.id() ) {
1115 *it = key; 1119 *it = key;
1116 return; 1120 return;
1117 } 1121 }
1118 } 1122 }
1119 mData->keys.append( key ); 1123 mData->keys.append( key );
1120} 1124}
1121 1125
1122void Addressee::removeKey( const Key &key ) 1126void Addressee::removeKey( const Key &key )
1123{ 1127{
1124 detach(); 1128 detach();
1125 1129
1126 Key::List::Iterator it; 1130 Key::List::Iterator it;
1127 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1131 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1128 if ( (*it).id() == key.id() ) { 1132 if ( (*it).id() == key.id() ) {
1129 mData->keys.remove( key ); 1133 mData->keys.remove( key );
1130 return; 1134 return;
1131 } 1135 }
1132 } 1136 }
1133} 1137}
1134 1138
1135Key Addressee::key( int type, QString customTypeString ) const 1139Key Addressee::key( int type, QString customTypeString ) const
1136{ 1140{
1137 Key::List::ConstIterator it; 1141 Key::List::ConstIterator it;
1138 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1142 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1139 if ( (*it).type() == type ) { 1143 if ( (*it).type() == type ) {
1140 if ( type == Key::Custom ) { 1144 if ( type == Key::Custom ) {
1141 if ( customTypeString.isEmpty() ) { 1145 if ( customTypeString.isEmpty() ) {
1142 return *it; 1146 return *it;
1143 } else { 1147 } else {
1144 if ( (*it).customTypeString() == customTypeString ) 1148 if ( (*it).customTypeString() == customTypeString )
1145 return (*it); 1149 return (*it);
1146 } 1150 }
1147 } else { 1151 } else {
1148 return *it; 1152 return *it;
1149 } 1153 }
1150 } 1154 }
1151 } 1155 }
1152 return Key( QString(), type ); 1156 return Key( QString(), type );
1153} 1157}
1154void Addressee::setKeys( const Key::List& list ) { 1158void Addressee::setKeys( const Key::List& list ) {
1155 detach(); 1159 detach();
1156 mData->keys = list; 1160 mData->keys = list;
1157} 1161}
1158 1162
1159Key::List Addressee::keys() const 1163Key::List Addressee::keys() const
1160{ 1164{
1161 return mData->keys; 1165 return mData->keys;
1162} 1166}
1163 1167
1164Key::List Addressee::keys( int type, QString customTypeString ) const 1168Key::List Addressee::keys( int type, QString customTypeString ) const
1165{ 1169{
1166 Key::List list; 1170 Key::List list;
1167 1171
1168 Key::List::ConstIterator it; 1172 Key::List::ConstIterator it;
1169 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1173 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1170 if ( (*it).type() == type ) { 1174 if ( (*it).type() == type ) {
1171 if ( type == Key::Custom ) { 1175 if ( type == Key::Custom ) {
1172 if ( customTypeString.isEmpty() ) { 1176 if ( customTypeString.isEmpty() ) {
1173 list.append(*it); 1177 list.append(*it);
1174 } else { 1178 } else {
1175 if ( (*it).customTypeString() == customTypeString ) 1179 if ( (*it).customTypeString() == customTypeString )
1176 list.append(*it); 1180 list.append(*it);
1177 } 1181 }
1178 } else { 1182 } else {
1179 list.append(*it); 1183 list.append(*it);
1180 } 1184 }
1181 } 1185 }
1182 } 1186 }
1183 return list; 1187 return list;
1184} 1188}
1185 1189
1186Key Addressee::findKey( const QString &id ) const 1190Key Addressee::findKey( const QString &id ) const
1187{ 1191{
1188 Key::List::ConstIterator it; 1192 Key::List::ConstIterator it;
1189 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1193 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1190 if ( (*it).id() == id ) { 1194 if ( (*it).id() == id ) {
1191 return *it; 1195 return *it;
1192 } 1196 }
1193 } 1197 }
1194 return Key(); 1198 return Key();
1195} 1199}
1196 1200
1197QString Addressee::asString() const 1201QString Addressee::asString() const
1198{ 1202{
1199 return "Smith, agent Smith..."; 1203 return "Smith, agent Smith...";
1200} 1204}
1201 1205
1202void Addressee::dump() const 1206void Addressee::dump() const
1203{ 1207{
1204 return; 1208 return;
1205 kdDebug(5700) << "Addressee {" << endl; 1209 kdDebug(5700) << "Addressee {" << endl;
1206 1210
1207 kdDebug(5700) << " Uid: '" << uid() << "'" << endl; 1211 kdDebug(5700) << " Uid: '" << uid() << "'" << endl;
1208 1212
1209 kdDebug(5700) << " Name: '" << name() << "'" << endl; 1213 kdDebug(5700) << " Name: '" << name() << "'" << endl;
1210 kdDebug(5700) << " FormattedName: '" << formattedName() << "'" << endl; 1214 kdDebug(5700) << " FormattedName: '" << formattedName() << "'" << endl;
1211 kdDebug(5700) << " FamilyName: '" << familyName() << "'" << endl; 1215 kdDebug(5700) << " FamilyName: '" << familyName() << "'" << endl;
1212 kdDebug(5700) << " GivenName: '" << givenName() << "'" << endl; 1216 kdDebug(5700) << " GivenName: '" << givenName() << "'" << endl;
1213 kdDebug(5700) << " AdditionalName: '" << additionalName() << "'" << endl; 1217 kdDebug(5700) << " AdditionalName: '" << additionalName() << "'" << endl;
1214 kdDebug(5700) << " Prefix: '" << prefix() << "'" << endl; 1218 kdDebug(5700) << " Prefix: '" << prefix() << "'" << endl;
1215 kdDebug(5700) << " Suffix: '" << suffix() << "'" << endl; 1219 kdDebug(5700) << " Suffix: '" << suffix() << "'" << endl;
1216 kdDebug(5700) << " NickName: '" << nickName() << "'" << endl; 1220 kdDebug(5700) << " NickName: '" << nickName() << "'" << endl;