-rw-r--r-- | library/backend/contact.cpp | 79 |
1 files changed, 47 insertions, 32 deletions
diff --git a/library/backend/contact.cpp b/library/backend/contact.cpp index a5f10ab..b10b19a 100644 --- a/library/backend/contact.cpp +++ b/library/backend/contact.cpp | |||
@@ -9,24 +9,26 @@ | |||
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #define QTOPIA_INTERNAL_CONTACT_MRE | ||
22 | |||
21 | #include "contact.h" | 23 | #include "contact.h" |
22 | #include "vobject_p.h" | 24 | #include "vobject_p.h" |
23 | #include "qfiledirect_p.h" | 25 | #include "qfiledirect_p.h" |
24 | 26 | ||
25 | #include <qpe/stringutil.h> | 27 | #include <qpe/stringutil.h> |
26 | #include <qpe/timeconversion.h> | 28 | #include <qpe/timeconversion.h> |
27 | 29 | ||
28 | #include <qobject.h> | 30 | #include <qobject.h> |
29 | #include <qregexp.h> | 31 | #include <qregexp.h> |
30 | #include <qstylesheet.h> | 32 | #include <qstylesheet.h> |
31 | #include <qfileinfo.h> | 33 | #include <qfileinfo.h> |
32 | 34 | ||
@@ -377,117 +379,125 @@ void Contact::save( QString &buf ) const | |||
377 | 379 | ||
378 | QStringList Contact::fields() | 380 | QStringList Contact::fields() |
379 | { | 381 | { |
380 | QStringList list; | 382 | QStringList list; |
381 | 383 | ||
382 | list.append( "Title" ); // Not Used! | 384 | list.append( "Title" ); // Not Used! |
383 | list.append( "FirstName" ); | 385 | list.append( "FirstName" ); |
384 | list.append( "MiddleName" ); | 386 | list.append( "MiddleName" ); |
385 | list.append( "LastName" ); | 387 | list.append( "LastName" ); |
386 | list.append( "Suffix" ); | 388 | list.append( "Suffix" ); |
387 | list.append( "FileAs" ); | 389 | list.append( "FileAs" ); |
388 | 390 | ||
391 | list.append( "JobTitle" ); | ||
392 | list.append( "Department" ); | ||
393 | list.append( "Company" ); | ||
394 | list.append( "BusinessPhone" ); | ||
395 | list.append( "BusinessFax" ); | ||
396 | list.append( "BusinessMobile" ); | ||
397 | |||
389 | list.append( "DefaultEmail" ); | 398 | list.append( "DefaultEmail" ); |
390 | list.append( "Emails" ); | 399 | list.append( "Emails" ); |
391 | 400 | ||
392 | list.append( "HomeStreet" ); | ||
393 | list.append( "HomeCity" ); | ||
394 | list.append( "HomeState" ); | ||
395 | list.append( "HomeZip" ); | ||
396 | list.append( "HomeCountry" ); | ||
397 | list.append( "HomePhone" ); | 401 | list.append( "HomePhone" ); |
398 | list.append( "HomeFax" ); | 402 | list.append( "HomeFax" ); |
399 | list.append( "HomeMobile" ); | 403 | list.append( "HomeMobile" ); |
400 | list.append( "HomeWebPage" ); | ||
401 | 404 | ||
402 | list.append( "Company" ); | ||
403 | list.append( "BusinessStreet" ); | 405 | list.append( "BusinessStreet" ); |
404 | list.append( "BusinessCity" ); | 406 | list.append( "BusinessCity" ); |
405 | list.append( "BusinessState" ); | 407 | list.append( "BusinessState" ); |
406 | list.append( "BusinessZip" ); | 408 | list.append( "BusinessZip" ); |
407 | list.append( "BusinessCountry" ); | 409 | list.append( "BusinessCountry" ); |
410 | list.append( "BusinessPager" ); | ||
408 | list.append( "BusinessWebPage" ); | 411 | list.append( "BusinessWebPage" ); |
409 | list.append( "JobTitle" ); | 412 | |
410 | list.append( "Department" ); | ||
411 | list.append( "Office" ); | 413 | list.append( "Office" ); |
412 | list.append( "BusinessPhone" ); | ||
413 | list.append( "BusinessFax" ); | ||
414 | list.append( "BusinessMobile" ); | ||
415 | list.append( "BusinessPager" ); | ||
416 | list.append( "Profession" ); | 414 | list.append( "Profession" ); |
417 | list.append( "Assistant" ); | 415 | list.append( "Assistant" ); |
418 | list.append( "Manager" ); | 416 | list.append( "Manager" ); |
419 | 417 | ||
418 | list.append( "HomeStreet" ); | ||
419 | list.append( "HomeCity" ); | ||
420 | list.append( "HomeState" ); | ||
421 | list.append( "HomeZip" ); | ||
422 | list.append( "HomeCountry" ); | ||
423 | list.append( "HomeWebPage" ); | ||
424 | |||
420 | list.append( "Spouse" ); | 425 | list.append( "Spouse" ); |
421 | list.append( "Gender" ); | 426 | list.append( "Gender" ); |
422 | list.append( "Birthday" ); | 427 | list.append( "Birthday" ); |
423 | list.append( "Anniversary" ); | 428 | list.append( "Anniversary" ); |
424 | list.append( "Nickname" ); | 429 | list.append( "Nickname" ); |
425 | |||
426 | list.append( "Children" ); | 430 | list.append( "Children" ); |
431 | |||
427 | list.append( "Notes" ); | 432 | list.append( "Notes" ); |
433 | list.append( "Groups" ); | ||
428 | 434 | ||
429 | return list; | 435 | return list; |
430 | } | 436 | } |
431 | 437 | ||
432 | QStringList Contact::trfields() | 438 | QStringList Contact::trfields() |
433 | { | 439 | { |
434 | QStringList list; | 440 | QStringList list; |
435 | 441 | ||
436 | list.append( QObject::tr( "Name Title") ); | 442 | list.append( QObject::tr( "Name Title") ); |
437 | list.append( QObject::tr( "First Name" ) ); | 443 | list.append( QObject::tr( "First Name" ) ); |
438 | list.append( QObject::tr( "Middle Name" ) ); | 444 | list.append( QObject::tr( "Middle Name" ) ); |
439 | list.append( QObject::tr( "Last Name" ) ); | 445 | list.append( QObject::tr( "Last Name" ) ); |
440 | list.append( QObject::tr( "Suffix" ) ); | 446 | list.append( QObject::tr( "Suffix" ) ); |
441 | list.append( QObject::tr( "File As" ) ); | 447 | list.append( QObject::tr( "File As" ) ); |
442 | 448 | ||
449 | list.append( QObject::tr( "Job Title" ) ); | ||
450 | list.append( QObject::tr( "Department" ) ); | ||
451 | list.append( QObject::tr( "Company" ) ); | ||
452 | list.append( QObject::tr( "Business Phone" ) ); | ||
453 | list.append( QObject::tr( "Business Fax" ) ); | ||
454 | list.append( QObject::tr( "Business Mobile" ) ); | ||
455 | |||
443 | list.append( QObject::tr( "Default Email" ) ); | 456 | list.append( QObject::tr( "Default Email" ) ); |
444 | list.append( QObject::tr( "Emails" ) ); | 457 | list.append( QObject::tr( "Emails" ) ); |
445 | 458 | ||
446 | list.append( QObject::tr( "Home Street" ) ); | ||
447 | list.append( QObject::tr( "Home City" ) ); | ||
448 | list.append( QObject::tr( "Home State" ) ); | ||
449 | list.append( QObject::tr( "Home Zip" ) ); | ||
450 | list.append( QObject::tr( "Home Country" ) ); | ||
451 | list.append( QObject::tr( "Home Phone" ) ); | 459 | list.append( QObject::tr( "Home Phone" ) ); |
452 | list.append( QObject::tr( "Home Fax" ) ); | 460 | list.append( QObject::tr( "Home Fax" ) ); |
453 | list.append( QObject::tr( "Home Mobile" ) ); | 461 | list.append( QObject::tr( "Home Mobile" ) ); |
454 | list.append( QObject::tr( "Home Web Page" ) ); | ||
455 | 462 | ||
456 | list.append( QObject::tr( "Company" ) ); | ||
457 | list.append( QObject::tr( "Business Street" ) ); | 463 | list.append( QObject::tr( "Business Street" ) ); |
458 | list.append( QObject::tr( "Business City" ) ); | 464 | list.append( QObject::tr( "Business City" ) ); |
459 | list.append( QObject::tr( "Business State" ) ); | 465 | list.append( QObject::tr( "Business State" ) ); |
460 | list.append( QObject::tr( "Business Zip" ) ); | 466 | list.append( QObject::tr( "Business Zip" ) ); |
461 | list.append( QObject::tr( "Business Country" ) ); | 467 | list.append( QObject::tr( "Business Country" ) ); |
468 | list.append( QObject::tr( "Business Pager" ) ); | ||
462 | list.append( QObject::tr( "Business WebPage" ) ); | 469 | list.append( QObject::tr( "Business WebPage" ) ); |
463 | list.append( QObject::tr( "Job Title" ) ); | 470 | |
464 | list.append( QObject::tr( "Department" ) ); | ||
465 | list.append( QObject::tr( "Office" ) ); | 471 | list.append( QObject::tr( "Office" ) ); |
466 | list.append( QObject::tr( "Business Phone" ) ); | ||
467 | list.append( QObject::tr( "Business Fax" ) ); | ||
468 | list.append( QObject::tr( "Business Mobile" ) ); | ||
469 | list.append( QObject::tr( "Business Pager" ) ); | ||
470 | list.append( QObject::tr( "Profession" ) ); | 472 | list.append( QObject::tr( "Profession" ) ); |
471 | list.append( QObject::tr( "Assistant" ) ); | 473 | list.append( QObject::tr( "Assistant" ) ); |
472 | list.append( QObject::tr( "Manager" ) ); | 474 | list.append( QObject::tr( "Manager" ) ); |
473 | 475 | ||
476 | list.append( QObject::tr( "Home Street" ) ); | ||
477 | list.append( QObject::tr( "Home City" ) ); | ||
478 | list.append( QObject::tr( "Home State" ) ); | ||
479 | list.append( QObject::tr( "Home Zip" ) ); | ||
480 | list.append( QObject::tr( "Home Country" ) ); | ||
481 | list.append( QObject::tr( "Home Web Page" ) ); | ||
482 | |||
474 | list.append( QObject::tr( "Spouse" ) ); | 483 | list.append( QObject::tr( "Spouse" ) ); |
475 | list.append( QObject::tr( "Gender" ) ); | 484 | list.append( QObject::tr( "Gender" ) ); |
476 | list.append( QObject::tr( "Birthday" ) ); | 485 | list.append( QObject::tr( "Birthday" ) ); |
477 | list.append( QObject::tr( "Anniversary" ) ); | 486 | list.append( QObject::tr( "Anniversary" ) ); |
478 | list.append( QObject::tr( "Nickname" ) ); | 487 | list.append( QObject::tr( "Nickname" ) ); |
479 | |||
480 | list.append( QObject::tr( "Children" ) ); | 488 | list.append( QObject::tr( "Children" ) ); |
489 | |||
481 | list.append( QObject::tr( "Notes" ) ); | 490 | list.append( QObject::tr( "Notes" ) ); |
491 | list.append( QObject::tr( "Groups" ) ); | ||
482 | 492 | ||
483 | return list; | 493 | return list; |
484 | } | 494 | } |
485 | 495 | ||
486 | void Contact::setEmails( const QString &v ) | 496 | void Contact::setEmails( const QString &v ) |
487 | { | 497 | { |
488 | replace( Qtopia::Emails, v ); | 498 | replace( Qtopia::Emails, v ); |
489 | if ( v.isEmpty() ) | 499 | if ( v.isEmpty() ) |
490 | setDefaultEmail( QString::null ); | 500 | setDefaultEmail( QString::null ); |
491 | } | 501 | } |
492 | 502 | ||
493 | void Contact::setChildren( const QString &v ) | 503 | void Contact::setChildren( const QString &v ) |
@@ -620,25 +630,25 @@ static Contact parseVObject( VObject *obj ) | |||
620 | 630 | ||
621 | VObjectIterator it; | 631 | VObjectIterator it; |
622 | initPropIterator( &it, obj ); | 632 | initPropIterator( &it, obj ); |
623 | while( moreIteration( &it ) ) { | 633 | while( moreIteration( &it ) ) { |
624 | VObject *o = nextVObject( &it ); | 634 | VObject *o = nextVObject( &it ); |
625 | QCString name = vObjectName( o ); | 635 | QCString name = vObjectName( o ); |
626 | QCString value = vObjectStringZValue( o ); | 636 | QCString value = vObjectStringZValue( o ); |
627 | if ( name == VCNameProp ) { | 637 | if ( name == VCNameProp ) { |
628 | VObjectIterator nit; | 638 | VObjectIterator nit; |
629 | initPropIterator( &nit, o ); | 639 | initPropIterator( &nit, o ); |
630 | while( moreIteration( &nit ) ) { | 640 | while( moreIteration( &nit ) ) { |
631 | VObject *o = nextVObject( &nit ); | 641 | VObject *o = nextVObject( &nit ); |
632 | QCString name = vObjectName( o ); | 642 | QCString name = vObjectTypeInfo( o ); |
633 | QString value = vObjectStringZValue( o ); | 643 | QString value = vObjectStringZValue( o ); |
634 | if ( name == VCNamePrefixesProp ) | 644 | if ( name == VCNamePrefixesProp ) |
635 | c.setTitle( value ); | 645 | c.setTitle( value ); |
636 | else if ( name == VCNameSuffixesProp ) | 646 | else if ( name == VCNameSuffixesProp ) |
637 | c.setSuffix( value ); | 647 | c.setSuffix( value ); |
638 | else if ( name == VCFamilyNameProp ) | 648 | else if ( name == VCFamilyNameProp ) |
639 | c.setLastName( value ); | 649 | c.setLastName( value ); |
640 | else if ( name == VCGivenNameProp ) | 650 | else if ( name == VCGivenNameProp ) |
641 | c.setFirstName( value ); | 651 | c.setFirstName( value ); |
642 | else if ( name == VCAdditionalNamesProp ) | 652 | else if ( name == VCAdditionalNamesProp ) |
643 | c.setMiddleName( value ); | 653 | c.setMiddleName( value ); |
644 | } | 654 | } |
@@ -693,25 +703,25 @@ static Contact parseVObject( VObject *obj ) | |||
693 | VOICE = 0x04, | 703 | VOICE = 0x04, |
694 | CELL = 0x08, | 704 | CELL = 0x08, |
695 | FAX = 0x10, | 705 | FAX = 0x10, |
696 | PAGER = 0x20, | 706 | PAGER = 0x20, |
697 | UNKNOWN = 0x80 | 707 | UNKNOWN = 0x80 |
698 | }; | 708 | }; |
699 | int type = 0; | 709 | int type = 0; |
700 | 710 | ||
701 | VObjectIterator nit; | 711 | VObjectIterator nit; |
702 | initPropIterator( &nit, o ); | 712 | initPropIterator( &nit, o ); |
703 | while( moreIteration( &nit ) ) { | 713 | while( moreIteration( &nit ) ) { |
704 | VObject *o = nextVObject( &nit ); | 714 | VObject *o = nextVObject( &nit ); |
705 | QCString name = vObjectName( o ); | 715 | QCString name = vObjectTypeInfo( o ); |
706 | if ( name == VCHomeProp ) | 716 | if ( name == VCHomeProp ) |
707 | type |= HOME; | 717 | type |= HOME; |
708 | else if ( name == VCWorkProp ) | 718 | else if ( name == VCWorkProp ) |
709 | type |= WORK; | 719 | type |= WORK; |
710 | else if ( name == VCVoiceProp ) | 720 | else if ( name == VCVoiceProp ) |
711 | type |= VOICE; | 721 | type |= VOICE; |
712 | else if ( name == VCCellularProp ) | 722 | else if ( name == VCCellularProp ) |
713 | type |= CELL; | 723 | type |= CELL; |
714 | else if ( name == VCFaxProp ) | 724 | else if ( name == VCFaxProp ) |
715 | type |= FAX; | 725 | type |= FAX; |
716 | else if ( name == VCPagerProp ) | 726 | else if ( name == VCPagerProp ) |
717 | type |= PAGER; | 727 | type |= PAGER; |
@@ -740,48 +750,48 @@ static Contact parseVObject( VObject *obj ) | |||
740 | c.setBusinessMobile( value ); | 750 | c.setBusinessMobile( value ); |
741 | if ( ( type & (PAGER|WORK) ) == (PAGER|WORK) ) | 751 | if ( ( type & (PAGER|WORK) ) == (PAGER|WORK) ) |
742 | c.setBusinessPager( value ); | 752 | c.setBusinessPager( value ); |
743 | } | 753 | } |
744 | } | 754 | } |
745 | else if ( name == VCEmailAddressProp ) { | 755 | else if ( name == VCEmailAddressProp ) { |
746 | QString email = vObjectStringZValue( o ); | 756 | QString email = vObjectStringZValue( o ); |
747 | bool valid = TRUE; | 757 | bool valid = TRUE; |
748 | VObjectIterator nit; | 758 | VObjectIterator nit; |
749 | initPropIterator( &nit, o ); | 759 | initPropIterator( &nit, o ); |
750 | while( moreIteration( &nit ) ) { | 760 | while( moreIteration( &nit ) ) { |
751 | VObject *o = nextVObject( &nit ); | 761 | VObject *o = nextVObject( &nit ); |
752 | QCString name = vObjectName( o ); | 762 | QCString name = vObjectTypeInfo( o ); |
753 | if ( name != VCInternetProp && name != VCHomeProp && | 763 | if ( name != VCInternetProp && name != VCHomeProp && |
754 | name != VCWorkProp && | 764 | name != VCWorkProp && |
755 | name != VCPreferredProp ) | 765 | name != VCPreferredProp ) |
756 | // ### preffered should map to default email | 766 | // ### preffered should map to default email |
757 | valid = FALSE; | 767 | valid = FALSE; |
758 | } | 768 | } |
759 | if ( valid ) { | 769 | if ( valid ) { |
760 | if ( haveDefaultEmail ) { | 770 | if ( haveDefaultEmail ) { |
761 | QString str = c.emails(); | 771 | QString str = c.emails(); |
762 | if ( !str.isEmpty() ) | 772 | if ( !str.isEmpty() ) |
763 | str += ","+email; | 773 | str += ","+email; |
764 | c.setEmails( str ); | 774 | c.setEmails( str ); |
765 | } else { | 775 | } else { |
766 | c.setDefaultEmail( email ); | 776 | c.setDefaultEmail( email ); |
767 | } | 777 | } |
768 | } | 778 | } |
769 | } | 779 | } |
770 | else if ( name == VCURLProp ) { | 780 | else if ( name == VCURLProp ) { |
771 | VObjectIterator nit; | 781 | VObjectIterator nit; |
772 | initPropIterator( &nit, o ); | 782 | initPropIterator( &nit, o ); |
773 | while( moreIteration( &nit ) ) { | 783 | while( moreIteration( &nit ) ) { |
774 | VObject *o = nextVObject( &nit ); | 784 | VObject *o = nextVObject( &nit ); |
775 | QCString name = vObjectName( o ); | 785 | QCString name = vObjectTypeInfo( o ); |
776 | if ( name == VCHomeProp ) | 786 | if ( name == VCHomeProp ) |
777 | c.setHomeWebpage( value ); | 787 | c.setHomeWebpage( value ); |
778 | else if ( name == VCWorkProp ) | 788 | else if ( name == VCWorkProp ) |
779 | c.setBusinessWebpage( value ); | 789 | c.setBusinessWebpage( value ); |
780 | } | 790 | } |
781 | } | 791 | } |
782 | else if ( name == VCOrgProp ) { | 792 | else if ( name == VCOrgProp ) { |
783 | VObjectIterator nit; | 793 | VObjectIterator nit; |
784 | initPropIterator( &nit, o ); | 794 | initPropIterator( &nit, o ); |
785 | while( moreIteration( &nit ) ) { | 795 | while( moreIteration( &nit ) ) { |
786 | VObject *o = nextVObject( &nit ); | 796 | VObject *o = nextVObject( &nit ); |
787 | QCString name = vObjectName( o ); | 797 | QCString name = vObjectName( o ); |
@@ -885,24 +895,29 @@ QValueList<Contact> Contact::readVCard( const QString &filename ) | |||
885 | 895 | ||
886 | while ( obj ) { | 896 | while ( obj ) { |
887 | contacts.append( parseVObject( obj ) ); | 897 | contacts.append( parseVObject( obj ) ); |
888 | 898 | ||
889 | VObject *t = obj; | 899 | VObject *t = obj; |
890 | obj = nextVObjectInList(obj); | 900 | obj = nextVObjectInList(obj); |
891 | cleanVObject( t ); | 901 | cleanVObject( t ); |
892 | } | 902 | } |
893 | 903 | ||
894 | return contacts; | 904 | return contacts; |
895 | } | 905 | } |
896 | 906 | ||
907 | bool Contact::match( const QString ®exp ) const | ||
908 | { | ||
909 | return match(QRegExp(regexp)); | ||
910 | } | ||
911 | |||
897 | bool Contact::match( const QRegExp &r ) const | 912 | bool Contact::match( const QRegExp &r ) const |
898 | { | 913 | { |
899 | bool match; | 914 | bool match; |
900 | match = false; | 915 | match = false; |
901 | QMap<int, QString>::ConstIterator it; | 916 | QMap<int, QString>::ConstIterator it; |
902 | for ( it = mMap.begin(); it != mMap.end(); ++it ) { | 917 | for ( it = mMap.begin(); it != mMap.end(); ++it ) { |
903 | if ( (*it).find( r ) > -1 ) { | 918 | if ( (*it).find( r ) > -1 ) { |
904 | match = true; | 919 | match = true; |
905 | break; | 920 | break; |
906 | } | 921 | } |
907 | } | 922 | } |
908 | return match; | 923 | return match; |