author | zautrix <zautrix> | 2004-10-13 13:18:51 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-13 13:18:51 (UTC) |
commit | d41893fb0a49fbb080326a4c1fd98e1a032a182a (patch) (unidiff) | |
tree | 9b95603ff93801accaa94de4b73d88ea9c5c9386 | |
parent | efdd0735bda81dcd82dfb6d6dc0d0c143f249336 (diff) | |
download | kdepimpi-d41893fb0a49fbb080326a4c1fd98e1a032a182a.zip kdepimpi-d41893fb0a49fbb080326a4c1fd98e1a032a182a.tar.gz kdepimpi-d41893fb0a49fbb080326a4c1fd98e1a032a182a.tar.bz2 |
merge contact fixes
-rw-r--r-- | kabc/addressbook.cpp | 8 | ||||
-rw-r--r-- | kabc/addressbook.h | 4 | ||||
-rw-r--r-- | kabc/addressee.cpp | 82 | ||||
-rw-r--r-- | kabc/addressee.h | 2 | ||||
-rw-r--r-- | kaddressbook/kabcore.cpp | 6 |
5 files changed, 68 insertions, 34 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 19c26eb..8882259 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp | |||
@@ -482,718 +482,718 @@ void AddressBook::importFromFile( QString fileName, bool replaceLabel, bool rem | |||
482 | file.open( IO_ReadOnly ); | 482 | file.open( IO_ReadOnly ); |
483 | QByteArray rawData = file.readAll(); | 483 | QByteArray rawData = file.readAll(); |
484 | file.close(); | 484 | file.close(); |
485 | QString data; | 485 | QString data; |
486 | if ( replaceLabel ) { | 486 | if ( replaceLabel ) { |
487 | data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); | 487 | data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); |
488 | data.replace ( QRegExp("LABEL") , "ADR" ); | 488 | data.replace ( QRegExp("LABEL") , "ADR" ); |
489 | data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); | 489 | data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); |
490 | } else | 490 | } else |
491 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); | 491 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); |
492 | KABC::VCardTool tool; | 492 | KABC::VCardTool tool; |
493 | list = tool.parseVCards( data ); | 493 | list = tool.parseVCards( data ); |
494 | KABC::Addressee::List::Iterator it; | 494 | KABC::Addressee::List::Iterator it; |
495 | for ( it = list.begin(); it != list.end(); ++it ) { | 495 | for ( it = list.begin(); it != list.end(); ++it ) { |
496 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); | 496 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); |
497 | if ( !id.isEmpty() ) | 497 | if ( !id.isEmpty() ) |
498 | (*it).setIDStr(id ); | 498 | (*it).setIDStr(id ); |
499 | (*it).setResource( 0 ); | 499 | (*it).setResource( 0 ); |
500 | if ( replaceLabel ) | 500 | if ( replaceLabel ) |
501 | (*it).removeVoice(); | 501 | (*it).removeVoice(); |
502 | if ( removeOld ) | 502 | if ( removeOld ) |
503 | (*it).setTagged( true ); | 503 | (*it).setTagged( true ); |
504 | insertAddressee( (*it), false, true ); | 504 | insertAddressee( (*it), false, true ); |
505 | } | 505 | } |
506 | if ( removeOld ) | 506 | if ( removeOld ) |
507 | removeUntagged(); | 507 | removeUntagged(); |
508 | } | 508 | } |
509 | void AddressBook::setUntagged() | 509 | void AddressBook::setUntagged() |
510 | { | 510 | { |
511 | Iterator ait; | 511 | Iterator ait; |
512 | for ( ait = begin(); ait != end(); ++ait ) { | 512 | for ( ait = begin(); ait != end(); ++ait ) { |
513 | (*ait).setTagged( false ); | 513 | (*ait).setTagged( false ); |
514 | } | 514 | } |
515 | } | 515 | } |
516 | void AddressBook::removeUntagged() | 516 | void AddressBook::removeUntagged() |
517 | { | 517 | { |
518 | Iterator ait; | 518 | Iterator ait; |
519 | bool todelete = false; | 519 | bool todelete = false; |
520 | Iterator todel; | 520 | Iterator todel; |
521 | for ( ait = begin(); ait != end(); ++ait ) { | 521 | for ( ait = begin(); ait != end(); ++ait ) { |
522 | if ( todelete ) | 522 | if ( todelete ) |
523 | removeAddressee( todel ); | 523 | removeAddressee( todel ); |
524 | if (!(*ait).tagged()) { | 524 | if (!(*ait).tagged()) { |
525 | todelete = true; | 525 | todelete = true; |
526 | todel = ait; | 526 | todel = ait; |
527 | } else | 527 | } else |
528 | todelete = false; | 528 | todelete = false; |
529 | } | 529 | } |
530 | if ( todelete ) | 530 | if ( todelete ) |
531 | removeAddressee( todel ); | 531 | removeAddressee( todel ); |
532 | deleteRemovedAddressees(); | 532 | deleteRemovedAddressees(); |
533 | } | 533 | } |
534 | void AddressBook::smplifyAddressees() | 534 | void AddressBook::smplifyAddressees() |
535 | { | 535 | { |
536 | Iterator ait; | 536 | Iterator ait; |
537 | for ( ait = begin(); ait != end(); ++ait ) { | 537 | for ( ait = begin(); ait != end(); ++ait ) { |
538 | (*ait).simplifyEmails(); | 538 | (*ait).simplifyEmails(); |
539 | (*ait).simplifyPhoneNumbers(); | 539 | (*ait).simplifyPhoneNumbers(); |
540 | (*ait).simplifyPhoneNumberTypes(); | 540 | (*ait).simplifyPhoneNumberTypes(); |
541 | (*ait).simplifyAddresses(); | 541 | (*ait).simplifyAddresses(); |
542 | } | 542 | } |
543 | } | 543 | } |
544 | void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) | 544 | void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) |
545 | { | 545 | { |
546 | Iterator ait; | 546 | Iterator ait; |
547 | for ( ait = begin(); ait != end(); ++ait ) { | 547 | for ( ait = begin(); ait != end(); ++ait ) { |
548 | QString id = (*ait).IDStr(); | 548 | QString id = (*ait).IDStr(); |
549 | (*ait).setIDStr( ":"); | 549 | (*ait).setIDStr( ":"); |
550 | (*ait).setExternalUID( id ); | 550 | (*ait).setExternalUID( id ); |
551 | (*ait).setOriginalExternalUID( id ); | 551 | (*ait).setOriginalExternalUID( id ); |
552 | if ( isPreSync ) | 552 | if ( isPreSync ) |
553 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 553 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
554 | else { | 554 | else { |
555 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 555 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
556 | (*ait).setID( currentSyncDevice,id ); | 556 | (*ait).setID( currentSyncDevice,id ); |
557 | 557 | ||
558 | } | 558 | } |
559 | } | 559 | } |
560 | } | 560 | } |
561 | void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice ) | 561 | void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice ) |
562 | { | 562 | { |
563 | 563 | ||
564 | setUntagged(); | 564 | setUntagged(); |
565 | KABC::Addressee::List list; | 565 | KABC::Addressee::List list; |
566 | QFile file( fileName ); | 566 | QFile file( fileName ); |
567 | file.open( IO_ReadOnly ); | 567 | file.open( IO_ReadOnly ); |
568 | QByteArray rawData = file.readAll(); | 568 | QByteArray rawData = file.readAll(); |
569 | file.close(); | 569 | file.close(); |
570 | QString data; | 570 | QString data; |
571 | 571 | ||
572 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); | 572 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); |
573 | KABC::VCardTool tool; | 573 | KABC::VCardTool tool; |
574 | list = tool.parseVCards( data ); | 574 | list = tool.parseVCards( data ); |
575 | KABC::Addressee::List::Iterator it; | 575 | KABC::Addressee::List::Iterator it; |
576 | for ( it = list.begin(); it != list.end(); ++it ) { | 576 | for ( it = list.begin(); it != list.end(); ++it ) { |
577 | Iterator ait; | 577 | Iterator ait; |
578 | for ( ait = begin(); ait != end(); ++ait ) { | 578 | for ( ait = begin(); ait != end(); ++ait ) { |
579 | if ( !(*ait).tagged() ) { | 579 | if ( !(*ait).tagged() ) { |
580 | if ( (*ait).containsAdr(*it)) { | 580 | if ( (*ait).containsAdr(*it)) { |
581 | (*ait).setTagged(true); | 581 | (*ait).setTagged(true); |
582 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); | 582 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); |
583 | (*it).setIDStr( ":"); | 583 | (*it).setIDStr( ":"); |
584 | (*it).setID( currentSyncDevice,id ); | 584 | (*it).setID( currentSyncDevice,id ); |
585 | (*it).setExternalUID( id ); | 585 | (*it).setExternalUID( id ); |
586 | (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 586 | (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
587 | (*it).setUid( ( (*ait).uid() )); | 587 | (*it).setUid( ( (*ait).uid() )); |
588 | break; | 588 | break; |
589 | } | 589 | } |
590 | } | 590 | } |
591 | 591 | ||
592 | } | 592 | } |
593 | if ( ait == end() ) | 593 | if ( ait == end() ) |
594 | qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1()); | 594 | qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1()); |
595 | } | 595 | } |
596 | clear(); | 596 | clear(); |
597 | for ( it = list.begin(); it != list.end(); ++it ) { | 597 | for ( it = list.begin(); it != list.end(); ++it ) { |
598 | insertAddressee( (*it) ); | 598 | insertAddressee( (*it) ); |
599 | } | 599 | } |
600 | } | 600 | } |
601 | 601 | ||
602 | bool AddressBook::saveABphone( QString fileName ) | 602 | bool AddressBook::saveABphone( QString fileName ) |
603 | { | 603 | { |
604 | //smplifyAddressees(); | 604 | //smplifyAddressees(); |
605 | qDebug("saveABphone:: saving AB... "); | 605 | qDebug("saveABphone:: saving AB... "); |
606 | if ( ! export2PhoneFormat( QStringList() ,fileName ) ) | 606 | if ( ! export2PhoneFormat( QStringList() ,fileName ) ) |
607 | return false; | 607 | return false; |
608 | qDebug("saveABphone:: writing to phone... "); | 608 | qDebug("saveABphone:: writing to phone... "); |
609 | if ( !PhoneAccess::writeToPhone( fileName) ) { | 609 | if ( !PhoneAccess::writeToPhone( fileName) ) { |
610 | return false; | 610 | return false; |
611 | } | 611 | } |
612 | qDebug("saveABphone:: re-reading from phone... "); | 612 | qDebug("saveABphone:: re-reading from phone... "); |
613 | if ( !PhoneAccess::readFromPhone( fileName) ) { | 613 | if ( !PhoneAccess::readFromPhone( fileName) ) { |
614 | return false; | 614 | return false; |
615 | } | 615 | } |
616 | return true; | 616 | return true; |
617 | } | 617 | } |
618 | bool AddressBook::saveAB() | 618 | bool AddressBook::saveAB() |
619 | { | 619 | { |
620 | bool ok = true; | 620 | bool ok = true; |
621 | 621 | ||
622 | deleteRemovedAddressees(); | 622 | deleteRemovedAddressees(); |
623 | Iterator ait; | 623 | Iterator ait; |
624 | for ( ait = begin(); ait != end(); ++ait ) { | 624 | for ( ait = begin(); ait != end(); ++ait ) { |
625 | if ( !(*ait).IDStr().isEmpty() ) { | 625 | if ( !(*ait).IDStr().isEmpty() ) { |
626 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); | 626 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); |
627 | } | 627 | } |
628 | } | 628 | } |
629 | KRES::Manager<Resource>::ActiveIterator it; | 629 | KRES::Manager<Resource>::ActiveIterator it; |
630 | KRES::Manager<Resource> *manager = d->mManager; | 630 | KRES::Manager<Resource> *manager = d->mManager; |
631 | qDebug("SaveAB::saving..." ); | 631 | qDebug("SaveAB::saving..." ); |
632 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 632 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
633 | qDebug("SaveAB::checking resource..." ); | 633 | qDebug("SaveAB::checking resource..." ); |
634 | if ( (*it)->readOnly() ) | 634 | if ( (*it)->readOnly() ) |
635 | qDebug("resource is readonly." ); | 635 | qDebug("resource is readonly." ); |
636 | if ( (*it)->isOpen() ) | 636 | if ( (*it)->isOpen() ) |
637 | qDebug("resource is open" ); | 637 | qDebug("resource is open" ); |
638 | 638 | ||
639 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { | 639 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { |
640 | Ticket *ticket = requestSaveTicket( *it ); | 640 | Ticket *ticket = requestSaveTicket( *it ); |
641 | qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); | 641 | qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); |
642 | if ( !ticket ) { | 642 | if ( !ticket ) { |
643 | qDebug( i18n( "Unable to save to resource '%1'. It is locked." ) | 643 | qDebug( i18n( "Unable to save to resource '%1'. It is locked." ) |
644 | .arg( (*it)->resourceName() ) ); | 644 | .arg( (*it)->resourceName() ) ); |
645 | return false; | 645 | return false; |
646 | } | 646 | } |
647 | 647 | ||
648 | //if ( !save( ticket ) ) | 648 | //if ( !save( ticket ) ) |
649 | if ( ticket->resource() ) { | 649 | if ( ticket->resource() ) { |
650 | QString name = ticket->resource()->resourceName(); | 650 | QString name = ticket->resource()->resourceName(); |
651 | if ( ! ticket->resource()->save( ticket ) ) | 651 | if ( ! ticket->resource()->save( ticket ) ) |
652 | ok = false; | 652 | ok = false; |
653 | else | 653 | else |
654 | qDebug("StdAddressBook::resource saved '%s'", name.latin1() ); | 654 | qDebug("StdAddressBook::resource saved '%s'", name.latin1() ); |
655 | 655 | ||
656 | } else | 656 | } else |
657 | ok = false; | 657 | ok = false; |
658 | 658 | ||
659 | } | 659 | } |
660 | } | 660 | } |
661 | return ok; | 661 | return ok; |
662 | } | 662 | } |
663 | 663 | ||
664 | AddressBook::Iterator AddressBook::begin() | 664 | AddressBook::Iterator AddressBook::begin() |
665 | { | 665 | { |
666 | Iterator it = Iterator(); | 666 | Iterator it = Iterator(); |
667 | it.d->mIt = d->mAddressees.begin(); | 667 | it.d->mIt = d->mAddressees.begin(); |
668 | return it; | 668 | return it; |
669 | } | 669 | } |
670 | 670 | ||
671 | AddressBook::ConstIterator AddressBook::begin() const | 671 | AddressBook::ConstIterator AddressBook::begin() const |
672 | { | 672 | { |
673 | ConstIterator it = ConstIterator(); | 673 | ConstIterator it = ConstIterator(); |
674 | it.d->mIt = d->mAddressees.begin(); | 674 | it.d->mIt = d->mAddressees.begin(); |
675 | return it; | 675 | return it; |
676 | } | 676 | } |
677 | 677 | ||
678 | AddressBook::Iterator AddressBook::end() | 678 | AddressBook::Iterator AddressBook::end() |
679 | { | 679 | { |
680 | Iterator it = Iterator(); | 680 | Iterator it = Iterator(); |
681 | it.d->mIt = d->mAddressees.end(); | 681 | it.d->mIt = d->mAddressees.end(); |
682 | return it; | 682 | return it; |
683 | } | 683 | } |
684 | 684 | ||
685 | AddressBook::ConstIterator AddressBook::end() const | 685 | AddressBook::ConstIterator AddressBook::end() const |
686 | { | 686 | { |
687 | ConstIterator it = ConstIterator(); | 687 | ConstIterator it = ConstIterator(); |
688 | it.d->mIt = d->mAddressees.end(); | 688 | it.d->mIt = d->mAddressees.end(); |
689 | return it; | 689 | return it; |
690 | } | 690 | } |
691 | 691 | ||
692 | void AddressBook::clear() | 692 | void AddressBook::clear() |
693 | { | 693 | { |
694 | d->mAddressees.clear(); | 694 | d->mAddressees.clear(); |
695 | } | 695 | } |
696 | 696 | ||
697 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) | 697 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) |
698 | { | 698 | { |
699 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; | 699 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; |
700 | 700 | ||
701 | if ( !resource ) | 701 | if ( !resource ) |
702 | { | 702 | { |
703 | qDebug("AddressBook::requestSaveTicket no resource" ); | 703 | qDebug("AddressBook::requestSaveTicket no resource" ); |
704 | resource = standardResource(); | 704 | resource = standardResource(); |
705 | } | 705 | } |
706 | 706 | ||
707 | KRES::Manager<Resource>::ActiveIterator it; | 707 | KRES::Manager<Resource>::ActiveIterator it; |
708 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 708 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
709 | if ( (*it) == resource ) { | 709 | if ( (*it) == resource ) { |
710 | if ( (*it)->readOnly() || !(*it)->isOpen() ) | 710 | if ( (*it)->readOnly() || !(*it)->isOpen() ) |
711 | return 0; | 711 | return 0; |
712 | else | 712 | else |
713 | return (*it)->requestSaveTicket(); | 713 | return (*it)->requestSaveTicket(); |
714 | } | 714 | } |
715 | } | 715 | } |
716 | 716 | ||
717 | return 0; | 717 | return 0; |
718 | } | 718 | } |
719 | //void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); | 719 | //void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); |
720 | void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) | 720 | void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) |
721 | { | 721 | { |
722 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { | 722 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { |
723 | //qDebug("block insert "); | 723 | //qDebug("block insert "); |
724 | return; | 724 | return; |
725 | } | 725 | } |
726 | //qDebug("inserting.... %s ",a.uid().latin1() ); | 726 | //qDebug("inserting.... %s ",a.uid().latin1() ); |
727 | bool found = false; | 727 | bool found = false; |
728 | Addressee::List::Iterator it; | 728 | Addressee::List::Iterator it; |
729 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { | 729 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { |
730 | if ( a.uid() == (*it).uid() ) { | 730 | if ( a.uid() == (*it).uid() ) { |
731 | 731 | ||
732 | bool changed = false; | 732 | bool changed = false; |
733 | Addressee addr = a; | 733 | Addressee addr = a; |
734 | if ( addr != (*it) ) | 734 | if ( addr != (*it) ) |
735 | changed = true; | 735 | changed = true; |
736 | 736 | ||
737 | if ( takeResource ) { | 737 | if ( takeResource ) { |
738 | Resource * res = (*it).resource(); | 738 | Resource * res = (*it).resource(); |
739 | (*it) = a; | 739 | (*it) = a; |
740 | (*it).setResource( res ); | 740 | (*it).setResource( res ); |
741 | } else { | 741 | } else { |
742 | (*it) = a; | 742 | (*it) = a; |
743 | if ( (*it).resource() == 0 ) | 743 | if ( (*it).resource() == 0 ) |
744 | (*it).setResource( standardResource() ); | 744 | (*it).setResource( standardResource() ); |
745 | } | 745 | } |
746 | if ( changed ) { | 746 | if ( changed ) { |
747 | if ( setRev ) { | 747 | if ( setRev ) { |
748 | 748 | ||
749 | // get rid of micro seconds | 749 | // get rid of micro seconds |
750 | QDateTime dt = QDateTime::currentDateTime(); | 750 | QDateTime dt = QDateTime::currentDateTime(); |
751 | QTime t = dt.time(); | 751 | QTime t = dt.time(); |
752 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 752 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
753 | (*it).setRevision( dt ); | 753 | (*it).setRevision( dt ); |
754 | } | 754 | } |
755 | (*it).setChanged( true ); | 755 | (*it).setChanged( true ); |
756 | } | 756 | } |
757 | 757 | ||
758 | found = true; | 758 | found = true; |
759 | } else { | 759 | } else { |
760 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 760 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
761 | QString name = (*it).uid().mid( 19 ); | 761 | QString name = (*it).uid().mid( 19 ); |
762 | Addressee b = a; | 762 | Addressee b = a; |
763 | QString id = b.getID( name ); | 763 | QString id = b.getID( name ); |
764 | if ( ! id.isEmpty() ) { | 764 | if ( ! id.isEmpty() ) { |
765 | QString des = (*it).note(); | 765 | QString des = (*it).note(); |
766 | int startN; | 766 | int startN; |
767 | if( (startN = des.find( id ) ) >= 0 ) { | 767 | if( (startN = des.find( id ) ) >= 0 ) { |
768 | int endN = des.find( ",", startN+1 ); | 768 | int endN = des.find( ",", startN+1 ); |
769 | des = des.left( startN ) + des.mid( endN+1 ); | 769 | des = des.left( startN ) + des.mid( endN+1 ); |
770 | (*it).setNote( des ); | 770 | (*it).setNote( des ); |
771 | } | 771 | } |
772 | } | 772 | } |
773 | } | 773 | } |
774 | } | 774 | } |
775 | } | 775 | } |
776 | if ( found ) | 776 | if ( found ) |
777 | return; | 777 | return; |
778 | d->mAddressees.append( a ); | 778 | d->mAddressees.append( a ); |
779 | Addressee& addr = d->mAddressees.last(); | 779 | Addressee& addr = d->mAddressees.last(); |
780 | if ( addr.resource() == 0 ) | 780 | if ( addr.resource() == 0 ) |
781 | addr.setResource( standardResource() ); | 781 | addr.setResource( standardResource() ); |
782 | 782 | ||
783 | addr.setChanged( true ); | 783 | addr.setChanged( true ); |
784 | } | 784 | } |
785 | 785 | ||
786 | void AddressBook::removeAddressee( const Addressee &a ) | 786 | void AddressBook::removeAddressee( const Addressee &a ) |
787 | { | 787 | { |
788 | Iterator it; | 788 | Iterator it; |
789 | Iterator it2; | 789 | Iterator it2; |
790 | bool found = false; | 790 | bool found = false; |
791 | for ( it = begin(); it != end(); ++it ) { | 791 | for ( it = begin(); it != end(); ++it ) { |
792 | if ( a.uid() == (*it).uid() ) { | 792 | if ( a.uid() == (*it).uid() ) { |
793 | found = true; | 793 | found = true; |
794 | it2 = it; | 794 | it2 = it; |
795 | } else { | 795 | } else { |
796 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 796 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
797 | QString name = (*it).uid().mid( 19 ); | 797 | QString name = (*it).uid().mid( 19 ); |
798 | Addressee b = a; | 798 | Addressee b = a; |
799 | QString id = b.getID( name ); | 799 | QString id = b.getID( name ); |
800 | if ( ! id.isEmpty() ) { | 800 | if ( ! id.isEmpty() ) { |
801 | QString des = (*it).note(); | 801 | QString des = (*it).note(); |
802 | if( des.find( id ) < 0 ) { | 802 | if( des.find( id ) < 0 ) { |
803 | des += id + ","; | 803 | des += id + ","; |
804 | (*it).setNote( des ); | 804 | (*it).setNote( des ); |
805 | } | 805 | } |
806 | } | 806 | } |
807 | } | 807 | } |
808 | 808 | ||
809 | } | 809 | } |
810 | } | 810 | } |
811 | 811 | ||
812 | if ( found ) | 812 | if ( found ) |
813 | removeAddressee( it2 ); | 813 | removeAddressee( it2 ); |
814 | 814 | ||
815 | } | 815 | } |
816 | 816 | ||
817 | void AddressBook::removeSyncAddressees( bool removeDeleted ) | 817 | void AddressBook::removeSyncAddressees( bool removeDeleted ) |
818 | { | 818 | { |
819 | Iterator it = begin(); | 819 | Iterator it = begin(); |
820 | Iterator it2 ; | 820 | Iterator it2 ; |
821 | QDateTime dt ( QDate( 2004,1,1) ); | 821 | QDateTime dt ( QDate( 2004,1,1) ); |
822 | while ( it != end() ) { | 822 | while ( it != end() ) { |
823 | (*it).setRevision( dt ); | 823 | (*it).setRevision( dt ); |
824 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); | 824 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); |
825 | (*it).setIDStr(""); | 825 | (*it).setIDStr(""); |
826 | if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { | 826 | if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { |
827 | it2 = it; | 827 | it2 = it; |
828 | //qDebug("removing %s ",(*it).uid().latin1() ); | 828 | //qDebug("removing %s ",(*it).uid().latin1() ); |
829 | ++it; | 829 | ++it; |
830 | removeAddressee( it2 ); | 830 | removeAddressee( it2 ); |
831 | } else { | 831 | } else { |
832 | //qDebug("skipping %s ",(*it).uid().latin1() ); | 832 | //qDebug("skipping %s ",(*it).uid().latin1() ); |
833 | ++it; | 833 | ++it; |
834 | } | 834 | } |
835 | } | 835 | } |
836 | deleteRemovedAddressees(); | 836 | deleteRemovedAddressees(); |
837 | } | 837 | } |
838 | 838 | ||
839 | void AddressBook::removeAddressee( const Iterator &it ) | 839 | void AddressBook::removeAddressee( const Iterator &it ) |
840 | { | 840 | { |
841 | d->mRemovedAddressees.append( (*it) ); | 841 | d->mRemovedAddressees.append( (*it) ); |
842 | d->mAddressees.remove( it.d->mIt ); | 842 | d->mAddressees.remove( it.d->mIt ); |
843 | } | 843 | } |
844 | 844 | ||
845 | AddressBook::Iterator AddressBook::find( const Addressee &a ) | 845 | AddressBook::Iterator AddressBook::find( const Addressee &a ) |
846 | { | 846 | { |
847 | Iterator it; | 847 | Iterator it; |
848 | for ( it = begin(); it != end(); ++it ) { | 848 | for ( it = begin(); it != end(); ++it ) { |
849 | if ( a.uid() == (*it).uid() ) { | 849 | if ( a.uid() == (*it).uid() ) { |
850 | return it; | 850 | return it; |
851 | } | 851 | } |
852 | } | 852 | } |
853 | return end(); | 853 | return end(); |
854 | } | 854 | } |
855 | 855 | ||
856 | Addressee AddressBook::findByUid( const QString &uid ) | 856 | Addressee AddressBook::findByUid( const QString &uid ) |
857 | { | 857 | { |
858 | Iterator it; | 858 | Iterator it; |
859 | for ( it = begin(); it != end(); ++it ) { | 859 | for ( it = begin(); it != end(); ++it ) { |
860 | if ( uid == (*it).uid() ) { | 860 | if ( uid == (*it).uid() ) { |
861 | return *it; | 861 | return *it; |
862 | } | 862 | } |
863 | } | 863 | } |
864 | return Addressee(); | 864 | return Addressee(); |
865 | } | 865 | } |
866 | void AddressBook::preExternSync( AddressBook* aBook, const QString& csd ) | 866 | void AddressBook::preExternSync( AddressBook* aBook, const QString& csd , bool isSubset ) |
867 | { | 867 | { |
868 | //qDebug("AddressBook::preExternSync "); | 868 | //qDebug("AddressBook::preExternSync "); |
869 | AddressBook::Iterator it; | 869 | AddressBook::Iterator it; |
870 | for ( it = begin(); it != end(); ++it ) { | 870 | for ( it = begin(); it != end(); ++it ) { |
871 | (*it).setID( csd, (*it).externalUID() ); | 871 | (*it).setID( csd, (*it).externalUID() ); |
872 | (*it).computeCsum( csd ); | 872 | (*it).computeCsum( csd ); |
873 | } | 873 | } |
874 | mergeAB( aBook ,csd ); | 874 | mergeAB( aBook ,csd, isSubset ); |
875 | } | 875 | } |
876 | void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) | 876 | void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) |
877 | { | 877 | { |
878 | //qDebug("AddressBook::postExternSync "); | 878 | //qDebug("AddressBook::postExternSync "); |
879 | AddressBook::Iterator it; | 879 | AddressBook::Iterator it; |
880 | for ( it = begin(); it != end(); ++it ) { | 880 | for ( it = begin(); it != end(); ++it ) { |
881 | // qDebug("check uid %s ", (*it).uid().latin1() ); | 881 | // qDebug("check uid %s ", (*it).uid().latin1() ); |
882 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || | 882 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || |
883 | (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { | 883 | (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { |
884 | Addressee ad = aBook->findByUid( ( (*it).uid() )); | 884 | Addressee ad = aBook->findByUid( ( (*it).uid() )); |
885 | if ( ad.isEmpty() ) { | 885 | if ( ad.isEmpty() ) { |
886 | qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); | 886 | qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); |
887 | } else { | 887 | } else { |
888 | (*it).computeCsum( csd ); | 888 | (*it).computeCsum( csd ); |
889 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) | 889 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) |
890 | ad.setID( csd, (*it).externalUID() ); | 890 | ad.setID( csd, (*it).externalUID() ); |
891 | ad.setCsum( csd, (*it).getCsum( csd ) ); | 891 | ad.setCsum( csd, (*it).getCsum( csd ) ); |
892 | aBook->insertAddressee( ad ); | 892 | aBook->insertAddressee( ad ); |
893 | } | 893 | } |
894 | } | 894 | } |
895 | } | 895 | } |
896 | } | 896 | } |
897 | 897 | ||
898 | bool AddressBook::containsExternalUid( const QString& uid ) | 898 | bool AddressBook::containsExternalUid( const QString& uid ) |
899 | { | 899 | { |
900 | Iterator it; | 900 | Iterator it; |
901 | for ( it = begin(); it != end(); ++it ) { | 901 | for ( it = begin(); it != end(); ++it ) { |
902 | if ( uid == (*it).externalUID( ) ) | 902 | if ( uid == (*it).externalUID( ) ) |
903 | return true; | 903 | return true; |
904 | } | 904 | } |
905 | return false; | 905 | return false; |
906 | } | 906 | } |
907 | Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) | 907 | Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) |
908 | { | 908 | { |
909 | Iterator it; | 909 | Iterator it; |
910 | for ( it = begin(); it != end(); ++it ) { | 910 | for ( it = begin(); it != end(); ++it ) { |
911 | if ( uid == (*it).getID( profile ) ) | 911 | if ( uid == (*it).getID( profile ) ) |
912 | return (*it); | 912 | return (*it); |
913 | } | 913 | } |
914 | return Addressee(); | 914 | return Addressee(); |
915 | } | 915 | } |
916 | void AddressBook::mergeAB( AddressBook *aBook, const QString& profile ) | 916 | void AddressBook::mergeAB( AddressBook *aBook, const QString& profile , bool isSubset ) |
917 | { | 917 | { |
918 | Iterator it; | 918 | Iterator it; |
919 | Addressee ad; | 919 | Addressee ad; |
920 | for ( it = begin(); it != end(); ++it ) { | 920 | for ( it = begin(); it != end(); ++it ) { |
921 | ad = aBook->findByExternUid( (*it).externalUID(), profile ); | 921 | ad = aBook->findByExternUid( (*it).externalUID(), profile ); |
922 | if ( !ad.isEmpty() ) { | 922 | if ( !ad.isEmpty() ) { |
923 | (*it).mergeContact( ad ); | 923 | (*it).mergeContact( ad ,isSubset); |
924 | } | 924 | } |
925 | } | 925 | } |
926 | #if 0 | 926 | #if 0 |
927 | // test only | 927 | // test only |
928 | for ( it = begin(); it != end(); ++it ) { | 928 | for ( it = begin(); it != end(); ++it ) { |
929 | 929 | ||
930 | qDebug("uid %s ", (*it).uid().latin1()); | 930 | qDebug("uid %s ", (*it).uid().latin1()); |
931 | } | 931 | } |
932 | #endif | 932 | #endif |
933 | } | 933 | } |
934 | 934 | ||
935 | #if 0 | 935 | #if 0 |
936 | Addressee::List AddressBook::getExternLastSyncAddressees() | 936 | Addressee::List AddressBook::getExternLastSyncAddressees() |
937 | { | 937 | { |
938 | Addressee::List results; | 938 | Addressee::List results; |
939 | 939 | ||
940 | Iterator it; | 940 | Iterator it; |
941 | for ( it = begin(); it != end(); ++it ) { | 941 | for ( it = begin(); it != end(); ++it ) { |
942 | if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { | 942 | if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { |
943 | if ( (*it).familyName().left(4) == "!E: " ) | 943 | if ( (*it).familyName().left(4) == "!E: " ) |
944 | results.append( *it ); | 944 | results.append( *it ); |
945 | } | 945 | } |
946 | } | 946 | } |
947 | 947 | ||
948 | return results; | 948 | return results; |
949 | } | 949 | } |
950 | #endif | 950 | #endif |
951 | void AddressBook::resetTempSyncStat() | 951 | void AddressBook::resetTempSyncStat() |
952 | { | 952 | { |
953 | Iterator it; | 953 | Iterator it; |
954 | for ( it = begin(); it != end(); ++it ) { | 954 | for ( it = begin(); it != end(); ++it ) { |
955 | (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); | 955 | (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); |
956 | } | 956 | } |
957 | 957 | ||
958 | } | 958 | } |
959 | 959 | ||
960 | QStringList AddressBook:: uidList() | 960 | QStringList AddressBook:: uidList() |
961 | { | 961 | { |
962 | QStringList results; | 962 | QStringList results; |
963 | Iterator it; | 963 | Iterator it; |
964 | for ( it = begin(); it != end(); ++it ) { | 964 | for ( it = begin(); it != end(); ++it ) { |
965 | results.append( (*it).uid() ); | 965 | results.append( (*it).uid() ); |
966 | } | 966 | } |
967 | return results; | 967 | return results; |
968 | } | 968 | } |
969 | 969 | ||
970 | 970 | ||
971 | Addressee::List AddressBook::allAddressees() | 971 | Addressee::List AddressBook::allAddressees() |
972 | { | 972 | { |
973 | return d->mAddressees; | 973 | return d->mAddressees; |
974 | 974 | ||
975 | } | 975 | } |
976 | 976 | ||
977 | Addressee::List AddressBook::findByName( const QString &name ) | 977 | Addressee::List AddressBook::findByName( const QString &name ) |
978 | { | 978 | { |
979 | Addressee::List results; | 979 | Addressee::List results; |
980 | 980 | ||
981 | Iterator it; | 981 | Iterator it; |
982 | for ( it = begin(); it != end(); ++it ) { | 982 | for ( it = begin(); it != end(); ++it ) { |
983 | if ( name == (*it).realName() ) { | 983 | if ( name == (*it).realName() ) { |
984 | results.append( *it ); | 984 | results.append( *it ); |
985 | } | 985 | } |
986 | } | 986 | } |
987 | 987 | ||
988 | return results; | 988 | return results; |
989 | } | 989 | } |
990 | 990 | ||
991 | Addressee::List AddressBook::findByEmail( const QString &email ) | 991 | Addressee::List AddressBook::findByEmail( const QString &email ) |
992 | { | 992 | { |
993 | Addressee::List results; | 993 | Addressee::List results; |
994 | QStringList mailList; | 994 | QStringList mailList; |
995 | 995 | ||
996 | Iterator it; | 996 | Iterator it; |
997 | for ( it = begin(); it != end(); ++it ) { | 997 | for ( it = begin(); it != end(); ++it ) { |
998 | mailList = (*it).emails(); | 998 | mailList = (*it).emails(); |
999 | for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { | 999 | for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { |
1000 | if ( email == (*ite) ) { | 1000 | if ( email == (*ite) ) { |
1001 | results.append( *it ); | 1001 | results.append( *it ); |
1002 | } | 1002 | } |
1003 | } | 1003 | } |
1004 | } | 1004 | } |
1005 | 1005 | ||
1006 | return results; | 1006 | return results; |
1007 | } | 1007 | } |
1008 | 1008 | ||
1009 | Addressee::List AddressBook::findByCategory( const QString &category ) | 1009 | Addressee::List AddressBook::findByCategory( const QString &category ) |
1010 | { | 1010 | { |
1011 | Addressee::List results; | 1011 | Addressee::List results; |
1012 | 1012 | ||
1013 | Iterator it; | 1013 | Iterator it; |
1014 | for ( it = begin(); it != end(); ++it ) { | 1014 | for ( it = begin(); it != end(); ++it ) { |
1015 | if ( (*it).hasCategory( category) ) { | 1015 | if ( (*it).hasCategory( category) ) { |
1016 | results.append( *it ); | 1016 | results.append( *it ); |
1017 | } | 1017 | } |
1018 | } | 1018 | } |
1019 | 1019 | ||
1020 | return results; | 1020 | return results; |
1021 | } | 1021 | } |
1022 | 1022 | ||
1023 | void AddressBook::dump() const | 1023 | void AddressBook::dump() const |
1024 | { | 1024 | { |
1025 | kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; | 1025 | kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; |
1026 | 1026 | ||
1027 | ConstIterator it; | 1027 | ConstIterator it; |
1028 | for( it = begin(); it != end(); ++it ) { | 1028 | for( it = begin(); it != end(); ++it ) { |
1029 | (*it).dump(); | 1029 | (*it).dump(); |
1030 | } | 1030 | } |
1031 | 1031 | ||
1032 | kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; | 1032 | kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; |
1033 | } | 1033 | } |
1034 | 1034 | ||
1035 | QString AddressBook::identifier() | 1035 | QString AddressBook::identifier() |
1036 | { | 1036 | { |
1037 | QStringList identifier; | 1037 | QStringList identifier; |
1038 | 1038 | ||
1039 | 1039 | ||
1040 | KRES::Manager<Resource>::ActiveIterator it; | 1040 | KRES::Manager<Resource>::ActiveIterator it; |
1041 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 1041 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
1042 | if ( !(*it)->identifier().isEmpty() ) | 1042 | if ( !(*it)->identifier().isEmpty() ) |
1043 | identifier.append( (*it)->identifier() ); | 1043 | identifier.append( (*it)->identifier() ); |
1044 | } | 1044 | } |
1045 | 1045 | ||
1046 | return identifier.join( ":" ); | 1046 | return identifier.join( ":" ); |
1047 | } | 1047 | } |
1048 | 1048 | ||
1049 | Field::List AddressBook::fields( int category ) | 1049 | Field::List AddressBook::fields( int category ) |
1050 | { | 1050 | { |
1051 | if ( d->mAllFields.isEmpty() ) { | 1051 | if ( d->mAllFields.isEmpty() ) { |
1052 | d->mAllFields = Field::allFields(); | 1052 | d->mAllFields = Field::allFields(); |
1053 | } | 1053 | } |
1054 | 1054 | ||
1055 | if ( category == Field::All ) return d->mAllFields; | 1055 | if ( category == Field::All ) return d->mAllFields; |
1056 | 1056 | ||
1057 | Field::List result; | 1057 | Field::List result; |
1058 | Field::List::ConstIterator it; | 1058 | Field::List::ConstIterator it; |
1059 | for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { | 1059 | for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { |
1060 | if ( (*it)->category() & category ) result.append( *it ); | 1060 | if ( (*it)->category() & category ) result.append( *it ); |
1061 | } | 1061 | } |
1062 | 1062 | ||
1063 | return result; | 1063 | return result; |
1064 | } | 1064 | } |
1065 | 1065 | ||
1066 | bool AddressBook::addCustomField( const QString &label, int category, | 1066 | bool AddressBook::addCustomField( const QString &label, int category, |
1067 | const QString &key, const QString &app ) | 1067 | const QString &key, const QString &app ) |
1068 | { | 1068 | { |
1069 | if ( d->mAllFields.isEmpty() ) { | 1069 | if ( d->mAllFields.isEmpty() ) { |
1070 | d->mAllFields = Field::allFields(); | 1070 | d->mAllFields = Field::allFields(); |
1071 | } | 1071 | } |
1072 | //US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; | 1072 | //US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; |
1073 | QString a = app.isNull() ? KGlobal::getAppName() : app; | 1073 | QString a = app.isNull() ? KGlobal::getAppName() : app; |
1074 | 1074 | ||
1075 | QString k = key.isNull() ? label : key; | 1075 | QString k = key.isNull() ? label : key; |
1076 | 1076 | ||
1077 | Field *field = Field::createCustomField( label, category, k, a ); | 1077 | Field *field = Field::createCustomField( label, category, k, a ); |
1078 | 1078 | ||
1079 | if ( !field ) return false; | 1079 | if ( !field ) return false; |
1080 | 1080 | ||
1081 | d->mAllFields.append( field ); | 1081 | d->mAllFields.append( field ); |
1082 | 1082 | ||
1083 | return true; | 1083 | return true; |
1084 | } | 1084 | } |
1085 | 1085 | ||
1086 | QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) | 1086 | QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) |
1087 | { | 1087 | { |
1088 | if (!ab.d) return s; | 1088 | if (!ab.d) return s; |
1089 | 1089 | ||
1090 | return s << ab.d->mAddressees; | 1090 | return s << ab.d->mAddressees; |
1091 | } | 1091 | } |
1092 | 1092 | ||
1093 | QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) | 1093 | QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) |
1094 | { | 1094 | { |
1095 | if (!ab.d) return s; | 1095 | if (!ab.d) return s; |
1096 | 1096 | ||
1097 | s >> ab.d->mAddressees; | 1097 | s >> ab.d->mAddressees; |
1098 | 1098 | ||
1099 | return s; | 1099 | return s; |
1100 | } | 1100 | } |
1101 | 1101 | ||
1102 | bool AddressBook::addResource( Resource *resource ) | 1102 | bool AddressBook::addResource( Resource *resource ) |
1103 | { | 1103 | { |
1104 | if ( !resource->open() ) { | 1104 | if ( !resource->open() ) { |
1105 | kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; | 1105 | kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; |
1106 | return false; | 1106 | return false; |
1107 | } | 1107 | } |
1108 | 1108 | ||
1109 | resource->setAddressBook( this ); | 1109 | resource->setAddressBook( this ); |
1110 | 1110 | ||
1111 | d->mManager->add( resource ); | 1111 | d->mManager->add( resource ); |
1112 | return true; | 1112 | return true; |
1113 | } | 1113 | } |
1114 | 1114 | ||
1115 | bool AddressBook::removeResource( Resource *resource ) | 1115 | bool AddressBook::removeResource( Resource *resource ) |
1116 | { | 1116 | { |
1117 | resource->close(); | 1117 | resource->close(); |
1118 | 1118 | ||
1119 | if ( resource == standardResource() ) | 1119 | if ( resource == standardResource() ) |
1120 | d->mManager->setStandardResource( 0 ); | 1120 | d->mManager->setStandardResource( 0 ); |
1121 | 1121 | ||
1122 | resource->setAddressBook( 0 ); | 1122 | resource->setAddressBook( 0 ); |
1123 | 1123 | ||
1124 | d->mManager->remove( resource ); | 1124 | d->mManager->remove( resource ); |
1125 | return true; | 1125 | return true; |
1126 | } | 1126 | } |
1127 | 1127 | ||
1128 | QPtrList<Resource> AddressBook::resources() | 1128 | QPtrList<Resource> AddressBook::resources() |
1129 | { | 1129 | { |
1130 | QPtrList<Resource> list; | 1130 | QPtrList<Resource> list; |
1131 | 1131 | ||
1132 | // qDebug("AddressBook::resources() 1"); | 1132 | // qDebug("AddressBook::resources() 1"); |
1133 | 1133 | ||
1134 | KRES::Manager<Resource>::ActiveIterator it; | 1134 | KRES::Manager<Resource>::ActiveIterator it; |
1135 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) | 1135 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) |
1136 | list.append( *it ); | 1136 | list.append( *it ); |
1137 | 1137 | ||
1138 | return list; | 1138 | return list; |
1139 | } | 1139 | } |
1140 | 1140 | ||
1141 | /*US | 1141 | /*US |
1142 | void AddressBook::setErrorHandler( ErrorHandler *handler ) | 1142 | void AddressBook::setErrorHandler( ErrorHandler *handler ) |
1143 | { | 1143 | { |
1144 | delete d->mErrorHandler; | 1144 | delete d->mErrorHandler; |
1145 | d->mErrorHandler = handler; | 1145 | d->mErrorHandler = handler; |
1146 | } | 1146 | } |
1147 | */ | 1147 | */ |
1148 | 1148 | ||
1149 | void AddressBook::error( const QString& msg ) | 1149 | void AddressBook::error( const QString& msg ) |
1150 | { | 1150 | { |
1151 | /*US | 1151 | /*US |
1152 | if ( !d->mErrorHandler ) // create default error handler | 1152 | if ( !d->mErrorHandler ) // create default error handler |
1153 | d->mErrorHandler = new ConsoleErrorHandler; | 1153 | d->mErrorHandler = new ConsoleErrorHandler; |
1154 | 1154 | ||
1155 | if ( d->mErrorHandler ) | 1155 | if ( d->mErrorHandler ) |
1156 | d->mErrorHandler->error( msg ); | 1156 | d->mErrorHandler->error( msg ); |
1157 | else | 1157 | else |
1158 | kdError(5700) << "no error handler defined" << endl; | 1158 | kdError(5700) << "no error handler defined" << endl; |
1159 | */ | 1159 | */ |
1160 | kdDebug(5700) << "msg" << endl; | 1160 | kdDebug(5700) << "msg" << endl; |
1161 | qDebug(msg); | 1161 | qDebug(msg); |
1162 | } | 1162 | } |
1163 | 1163 | ||
1164 | void AddressBook::deleteRemovedAddressees() | 1164 | void AddressBook::deleteRemovedAddressees() |
1165 | { | 1165 | { |
1166 | Addressee::List::Iterator it; | 1166 | Addressee::List::Iterator it; |
1167 | for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { | 1167 | for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { |
1168 | Resource *resource = (*it).resource(); | 1168 | Resource *resource = (*it).resource(); |
1169 | if ( resource && !resource->readOnly() && resource->isOpen() ) | 1169 | if ( resource && !resource->readOnly() && resource->isOpen() ) |
1170 | resource->removeAddressee( *it ); | 1170 | resource->removeAddressee( *it ); |
1171 | } | 1171 | } |
1172 | 1172 | ||
1173 | d->mRemovedAddressees.clear(); | 1173 | d->mRemovedAddressees.clear(); |
1174 | } | 1174 | } |
1175 | 1175 | ||
1176 | void AddressBook::setStandardResource( Resource *resource ) | 1176 | void AddressBook::setStandardResource( Resource *resource ) |
1177 | { | 1177 | { |
1178 | // qDebug("AddressBook::setStandardResource 1"); | 1178 | // qDebug("AddressBook::setStandardResource 1"); |
1179 | d->mManager->setStandardResource( resource ); | 1179 | d->mManager->setStandardResource( resource ); |
1180 | } | 1180 | } |
1181 | 1181 | ||
1182 | Resource *AddressBook::standardResource() | 1182 | Resource *AddressBook::standardResource() |
1183 | { | 1183 | { |
1184 | return d->mManager->standardResource(); | 1184 | return d->mManager->standardResource(); |
1185 | } | 1185 | } |
1186 | 1186 | ||
1187 | KRES::Manager<Resource> *AddressBook::resourceManager() | 1187 | KRES::Manager<Resource> *AddressBook::resourceManager() |
1188 | { | 1188 | { |
1189 | return d->mManager; | 1189 | return d->mManager; |
1190 | } | 1190 | } |
1191 | 1191 | ||
1192 | void AddressBook::cleanUp() | 1192 | void AddressBook::cleanUp() |
1193 | { | 1193 | { |
1194 | KRES::Manager<Resource>::ActiveIterator it; | 1194 | KRES::Manager<Resource>::ActiveIterator it; |
1195 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 1195 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
1196 | if ( !(*it)->readOnly() && (*it)->isOpen() ) | 1196 | if ( !(*it)->readOnly() && (*it)->isOpen() ) |
1197 | (*it)->cleanUp(); | 1197 | (*it)->cleanUp(); |
1198 | } | 1198 | } |
1199 | } | 1199 | } |
diff --git a/kabc/addressbook.h b/kabc/addressbook.h index df9048b..a6bf451 100644 --- a/kabc/addressbook.h +++ b/kabc/addressbook.h | |||
@@ -1,348 +1,348 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkabc. | 2 | This file is part of libkabc. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /* | 21 | /* |
22 | Enhanced Version of the file for platform independent KDE tools. | 22 | Enhanced Version of the file for platform independent KDE tools. |
23 | Copyright (c) 2004 Ulf Schenk | 23 | Copyright (c) 2004 Ulf Schenk |
24 | 24 | ||
25 | $Id$ | 25 | $Id$ |
26 | */ | 26 | */ |
27 | 27 | ||
28 | #ifndef KABC_ADDRESSBOOK_H | 28 | #ifndef KABC_ADDRESSBOOK_H |
29 | #define KABC_ADDRESSBOOK_H | 29 | #define KABC_ADDRESSBOOK_H |
30 | 30 | ||
31 | #include <qobject.h> | 31 | #include <qobject.h> |
32 | 32 | ||
33 | #include <kresources/manager.h> | 33 | #include <kresources/manager.h> |
34 | #include <qptrlist.h> | 34 | #include <qptrlist.h> |
35 | 35 | ||
36 | #include "addressee.h" | 36 | #include "addressee.h" |
37 | #include "field.h" | 37 | #include "field.h" |
38 | 38 | ||
39 | namespace KABC { | 39 | namespace KABC { |
40 | 40 | ||
41 | class ErrorHandler; | 41 | class ErrorHandler; |
42 | class Resource; | 42 | class Resource; |
43 | class Ticket; | 43 | class Ticket; |
44 | 44 | ||
45 | /** | 45 | /** |
46 | @short Address Book | 46 | @short Address Book |
47 | 47 | ||
48 | This class provides access to a collection of address book entries. | 48 | This class provides access to a collection of address book entries. |
49 | */ | 49 | */ |
50 | class AddressBook : public QObject | 50 | class AddressBook : public QObject |
51 | { | 51 | { |
52 | Q_OBJECT | 52 | Q_OBJECT |
53 | 53 | ||
54 | friend QDataStream &operator<<( QDataStream &, const AddressBook & ); | 54 | friend QDataStream &operator<<( QDataStream &, const AddressBook & ); |
55 | friend QDataStream &operator>>( QDataStream &, AddressBook & ); | 55 | friend QDataStream &operator>>( QDataStream &, AddressBook & ); |
56 | friend class StdAddressBook; | 56 | friend class StdAddressBook; |
57 | 57 | ||
58 | public: | 58 | public: |
59 | /** | 59 | /** |
60 | @short Address Book Iterator | 60 | @short Address Book Iterator |
61 | 61 | ||
62 | This class provides an iterator for address book entries. | 62 | This class provides an iterator for address book entries. |
63 | */ | 63 | */ |
64 | class Iterator | 64 | class Iterator |
65 | { | 65 | { |
66 | public: | 66 | public: |
67 | Iterator(); | 67 | Iterator(); |
68 | Iterator( const Iterator & ); | 68 | Iterator( const Iterator & ); |
69 | ~Iterator(); | 69 | ~Iterator(); |
70 | 70 | ||
71 | Iterator &operator=( const Iterator & ); | 71 | Iterator &operator=( const Iterator & ); |
72 | const Addressee &operator*() const; | 72 | const Addressee &operator*() const; |
73 | Addressee &operator*(); | 73 | Addressee &operator*(); |
74 | Addressee* operator->(); | 74 | Addressee* operator->(); |
75 | Iterator &operator++(); | 75 | Iterator &operator++(); |
76 | Iterator &operator++(int); | 76 | Iterator &operator++(int); |
77 | Iterator &operator--(); | 77 | Iterator &operator--(); |
78 | Iterator &operator--(int); | 78 | Iterator &operator--(int); |
79 | bool operator==( const Iterator &it ); | 79 | bool operator==( const Iterator &it ); |
80 | bool operator!=( const Iterator &it ); | 80 | bool operator!=( const Iterator &it ); |
81 | 81 | ||
82 | struct IteratorData; | 82 | struct IteratorData; |
83 | IteratorData *d; | 83 | IteratorData *d; |
84 | }; | 84 | }; |
85 | 85 | ||
86 | /** | 86 | /** |
87 | @short Address Book Const Iterator | 87 | @short Address Book Const Iterator |
88 | 88 | ||
89 | This class provides a const iterator for address book entries. | 89 | This class provides a const iterator for address book entries. |
90 | */ | 90 | */ |
91 | class ConstIterator | 91 | class ConstIterator |
92 | { | 92 | { |
93 | public: | 93 | public: |
94 | ConstIterator(); | 94 | ConstIterator(); |
95 | ConstIterator( const ConstIterator & ); | 95 | ConstIterator( const ConstIterator & ); |
96 | ~ConstIterator(); | 96 | ~ConstIterator(); |
97 | 97 | ||
98 | ConstIterator &operator=( const ConstIterator & ); | 98 | ConstIterator &operator=( const ConstIterator & ); |
99 | const Addressee &operator*() const; | 99 | const Addressee &operator*() const; |
100 | const Addressee* operator->() const; | 100 | const Addressee* operator->() const; |
101 | ConstIterator &operator++(); | 101 | ConstIterator &operator++(); |
102 | ConstIterator &operator++(int); | 102 | ConstIterator &operator++(int); |
103 | ConstIterator &operator--(); | 103 | ConstIterator &operator--(); |
104 | ConstIterator &operator--(int); | 104 | ConstIterator &operator--(int); |
105 | bool operator==( const ConstIterator &it ); | 105 | bool operator==( const ConstIterator &it ); |
106 | bool operator!=( const ConstIterator &it ); | 106 | bool operator!=( const ConstIterator &it ); |
107 | 107 | ||
108 | struct ConstIteratorData; | 108 | struct ConstIteratorData; |
109 | ConstIteratorData *d; | 109 | ConstIteratorData *d; |
110 | }; | 110 | }; |
111 | 111 | ||
112 | /** | 112 | /** |
113 | Constructs a address book object. | 113 | Constructs a address book object. |
114 | 114 | ||
115 | @param format File format class. | 115 | @param format File format class. |
116 | */ | 116 | */ |
117 | AddressBook(); | 117 | AddressBook(); |
118 | AddressBook( const QString &config ); | 118 | AddressBook( const QString &config ); |
119 | AddressBook( const QString &config, const QString &family ); | 119 | AddressBook( const QString &config, const QString &family ); |
120 | virtual ~AddressBook(); | 120 | virtual ~AddressBook(); |
121 | 121 | ||
122 | /** | 122 | /** |
123 | Requests a ticket for saving the addressbook. Calling this function locks | 123 | Requests a ticket for saving the addressbook. Calling this function locks |
124 | the addressbook for all other processes. If the address book is already | 124 | the addressbook for all other processes. If the address book is already |
125 | locked the function returns 0. You need the returned @ref Ticket object | 125 | locked the function returns 0. You need the returned @ref Ticket object |
126 | for calling the @ref save() function. | 126 | for calling the @ref save() function. |
127 | 127 | ||
128 | @see save() | 128 | @see save() |
129 | */ | 129 | */ |
130 | Ticket *requestSaveTicket( Resource *resource=0 ); | 130 | Ticket *requestSaveTicket( Resource *resource=0 ); |
131 | 131 | ||
132 | /** | 132 | /** |
133 | Load address book from file. | 133 | Load address book from file. |
134 | */ | 134 | */ |
135 | bool load(); | 135 | bool load(); |
136 | 136 | ||
137 | /** | 137 | /** |
138 | Save address book. The address book is saved to the file, the Ticket | 138 | Save address book. The address book is saved to the file, the Ticket |
139 | object has been requested for by @ref requestSaveTicket(). | 139 | object has been requested for by @ref requestSaveTicket(). |
140 | 140 | ||
141 | @param ticket a ticket object returned by @ref requestSaveTicket() | 141 | @param ticket a ticket object returned by @ref requestSaveTicket() |
142 | */ | 142 | */ |
143 | bool save( Ticket *ticket ); | 143 | bool save( Ticket *ticket ); |
144 | bool saveAB( ); | 144 | bool saveAB( ); |
145 | bool saveABphone( QString fileName ); | 145 | bool saveABphone( QString fileName ); |
146 | void smplifyAddressees(); | 146 | void smplifyAddressees(); |
147 | void preparePhoneSync( QString currentSyncDevice, bool isPreSync ); | 147 | void preparePhoneSync( QString currentSyncDevice, bool isPreSync ); |
148 | void export2File( QString fileName ); | 148 | void export2File( QString fileName ); |
149 | bool export2PhoneFormat( QStringList uids ,QString fileName ); | 149 | bool export2PhoneFormat( QStringList uids ,QString fileName ); |
150 | void importFromFile( QString fileName, bool replaceLabel = false, bool removeOld = false ); | 150 | void importFromFile( QString fileName, bool replaceLabel = false, bool removeOld = false ); |
151 | void setUntagged(); | 151 | void setUntagged(); |
152 | void removeUntagged(); | 152 | void removeUntagged(); |
153 | void findNewExtIds( QString fileName, QString currentSyncDevice ); | 153 | void findNewExtIds( QString fileName, QString currentSyncDevice ); |
154 | /** | 154 | /** |
155 | Returns a iterator for first entry of address book. | 155 | Returns a iterator for first entry of address book. |
156 | */ | 156 | */ |
157 | Iterator begin(); | 157 | Iterator begin(); |
158 | 158 | ||
159 | /** | 159 | /** |
160 | Returns a const iterator for first entry of address book. | 160 | Returns a const iterator for first entry of address book. |
161 | */ | 161 | */ |
162 | ConstIterator begin() const; | 162 | ConstIterator begin() const; |
163 | 163 | ||
164 | /** | 164 | /** |
165 | Returns a iterator for first entry of address book. | 165 | Returns a iterator for first entry of address book. |
166 | */ | 166 | */ |
167 | Iterator end(); | 167 | Iterator end(); |
168 | 168 | ||
169 | /** | 169 | /** |
170 | Returns a const iterator for first entry of address book. | 170 | Returns a const iterator for first entry of address book. |
171 | */ | 171 | */ |
172 | ConstIterator end() const; | 172 | ConstIterator end() const; |
173 | 173 | ||
174 | /** | 174 | /** |
175 | Removes all entries from address book. | 175 | Removes all entries from address book. |
176 | */ | 176 | */ |
177 | void clear(); | 177 | void clear(); |
178 | 178 | ||
179 | /** | 179 | /** |
180 | Insert an Addressee object into address book. If an object with the same | 180 | Insert an Addressee object into address book. If an object with the same |
181 | unique id already exists in the address book it it replaced by the new | 181 | unique id already exists in the address book it it replaced by the new |
182 | one. If not the new object is appended to the address book. | 182 | one. If not the new object is appended to the address book. |
183 | */ | 183 | */ |
184 | void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); | 184 | void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); |
185 | 185 | ||
186 | /** | 186 | /** |
187 | Removes entry from the address book. | 187 | Removes entry from the address book. |
188 | */ | 188 | */ |
189 | void removeAddressee( const Addressee & ); | 189 | void removeAddressee( const Addressee & ); |
190 | 190 | ||
191 | /** | 191 | /** |
192 | This is like @ref removeAddressee() just above, with the difference that | 192 | This is like @ref removeAddressee() just above, with the difference that |
193 | the first element is a iterator, returned by @ref begin(). | 193 | the first element is a iterator, returned by @ref begin(). |
194 | */ | 194 | */ |
195 | void removeAddressee( const Iterator & ); | 195 | void removeAddressee( const Iterator & ); |
196 | 196 | ||
197 | /** | 197 | /** |
198 | Find the specified entry in address book. Returns end(), if the entry | 198 | Find the specified entry in address book. Returns end(), if the entry |
199 | couldn't be found. | 199 | couldn't be found. |
200 | */ | 200 | */ |
201 | Iterator find( const Addressee & ); | 201 | Iterator find( const Addressee & ); |
202 | 202 | ||
203 | /** | 203 | /** |
204 | Find the entry specified by an unique id. Returns an empty Addressee | 204 | Find the entry specified by an unique id. Returns an empty Addressee |
205 | object, if the address book does not contain an entry with this id. | 205 | object, if the address book does not contain an entry with this id. |
206 | */ | 206 | */ |
207 | Addressee findByUid( const QString & ); | 207 | Addressee findByUid( const QString & ); |
208 | 208 | ||
209 | 209 | ||
210 | /** | 210 | /** |
211 | Returns a list of all addressees in the address book. This list can | 211 | Returns a list of all addressees in the address book. This list can |
212 | be sorted with @ref KABC::AddresseeList for example. | 212 | be sorted with @ref KABC::AddresseeList for example. |
213 | */ | 213 | */ |
214 | Addressee::List allAddressees(); | 214 | Addressee::List allAddressees(); |
215 | 215 | ||
216 | /** | 216 | /** |
217 | Find all entries with the specified name in the address book. Returns | 217 | Find all entries with the specified name in the address book. Returns |
218 | an empty list, if no entries could be found. | 218 | an empty list, if no entries could be found. |
219 | */ | 219 | */ |
220 | Addressee::List findByName( const QString & ); | 220 | Addressee::List findByName( const QString & ); |
221 | 221 | ||
222 | /** | 222 | /** |
223 | Find all entries with the specified email address in the address book. | 223 | Find all entries with the specified email address in the address book. |
224 | Returns an empty list, if no entries could be found. | 224 | Returns an empty list, if no entries could be found. |
225 | */ | 225 | */ |
226 | Addressee::List findByEmail( const QString & ); | 226 | Addressee::List findByEmail( const QString & ); |
227 | 227 | ||
228 | /** | 228 | /** |
229 | Find all entries wich have the specified category in the address book. | 229 | Find all entries wich have the specified category in the address book. |
230 | Returns an empty list, if no entries could be found. | 230 | Returns an empty list, if no entries could be found. |
231 | */ | 231 | */ |
232 | Addressee::List findByCategory( const QString & ); | 232 | Addressee::List findByCategory( const QString & ); |
233 | 233 | ||
234 | /** | 234 | /** |
235 | Return a string identifying this addressbook. | 235 | Return a string identifying this addressbook. |
236 | */ | 236 | */ |
237 | virtual QString identifier(); | 237 | virtual QString identifier(); |
238 | 238 | ||
239 | /** | 239 | /** |
240 | Used for debug output. | 240 | Used for debug output. |
241 | */ | 241 | */ |
242 | void dump() const; | 242 | void dump() const; |
243 | 243 | ||
244 | void emitAddressBookLocked() { emit addressBookLocked( this ); } | 244 | void emitAddressBookLocked() { emit addressBookLocked( this ); } |
245 | void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); } | 245 | void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); } |
246 | void emitAddressBookChanged() { emit addressBookChanged( this ); } | 246 | void emitAddressBookChanged() { emit addressBookChanged( this ); } |
247 | 247 | ||
248 | /** | 248 | /** |
249 | Return list of all Fields known to the address book which are associated | 249 | Return list of all Fields known to the address book which are associated |
250 | with the given field category. | 250 | with the given field category. |
251 | */ | 251 | */ |
252 | Field::List fields( int category = Field::All ); | 252 | Field::List fields( int category = Field::All ); |
253 | 253 | ||
254 | /** | 254 | /** |
255 | Add custom field to address book. | 255 | Add custom field to address book. |
256 | 256 | ||
257 | @param label User visible label of the field. | 257 | @param label User visible label of the field. |
258 | @param category Ored list of field categories. | 258 | @param category Ored list of field categories. |
259 | @param key Identifier used as key for reading and writing the field. | 259 | @param key Identifier used as key for reading and writing the field. |
260 | @param app String used as application key for reading and writing | 260 | @param app String used as application key for reading and writing |
261 | the field. | 261 | the field. |
262 | */ | 262 | */ |
263 | bool addCustomField( const QString &label, int category = Field::All, | 263 | bool addCustomField( const QString &label, int category = Field::All, |
264 | const QString &key = QString::null, | 264 | const QString &key = QString::null, |
265 | const QString &app = QString::null ); | 265 | const QString &app = QString::null ); |
266 | 266 | ||
267 | 267 | ||
268 | /** | 268 | /** |
269 | Add address book resource. | 269 | Add address book resource. |
270 | */ | 270 | */ |
271 | bool addResource( Resource * ); | 271 | bool addResource( Resource * ); |
272 | 272 | ||
273 | /** | 273 | /** |
274 | Remove address book resource. | 274 | Remove address book resource. |
275 | */ | 275 | */ |
276 | bool removeResource( Resource * ); | 276 | bool removeResource( Resource * ); |
277 | 277 | ||
278 | /** | 278 | /** |
279 | Return pointer list of all resources. | 279 | Return pointer list of all resources. |
280 | */ | 280 | */ |
281 | QPtrList<Resource> resources(); | 281 | QPtrList<Resource> resources(); |
282 | 282 | ||
283 | /** | 283 | /** |
284 | Set the @p ErrorHandler, that is used by @ref error() to | 284 | Set the @p ErrorHandler, that is used by @ref error() to |
285 | provide gui-independend error messages. | 285 | provide gui-independend error messages. |
286 | */ | 286 | */ |
287 | void setErrorHandler( ErrorHandler * ); | 287 | void setErrorHandler( ErrorHandler * ); |
288 | 288 | ||
289 | /** | 289 | /** |
290 | Shows gui independend error messages. | 290 | Shows gui independend error messages. |
291 | */ | 291 | */ |
292 | void error( const QString& ); | 292 | void error( const QString& ); |
293 | 293 | ||
294 | /** | 294 | /** |
295 | Query all resources to clean up their lock files | 295 | Query all resources to clean up their lock files |
296 | */ | 296 | */ |
297 | void cleanUp(); | 297 | void cleanUp(); |
298 | 298 | ||
299 | // sync stuff | 299 | // sync stuff |
300 | //Addressee::List getExternLastSyncAddressees(); | 300 | //Addressee::List getExternLastSyncAddressees(); |
301 | void resetTempSyncStat(); | 301 | void resetTempSyncStat(); |
302 | QStringList uidList(); | 302 | QStringList uidList(); |
303 | void removeSyncAddressees( bool removeDeleted = false ); | 303 | void removeSyncAddressees( bool removeDeleted = false ); |
304 | void mergeAB( AddressBook *aBook, const QString& profile ); | 304 | void mergeAB( AddressBook *aBook, const QString& profile, bool isSubset ); |
305 | Addressee findByExternUid( const QString& uid , const QString& profile ); | 305 | Addressee findByExternUid( const QString& uid , const QString& profile ); |
306 | bool containsExternalUid( const QString& uid ); | 306 | bool containsExternalUid( const QString& uid ); |
307 | 307 | ||
308 | void preExternSync( AddressBook* aBook, const QString& csd ); | 308 | void preExternSync( AddressBook* aBook, const QString& csd, bool isSubset ); |
309 | void postExternSync( AddressBook* aBook, const QString& csd ); | 309 | void postExternSync( AddressBook* aBook, const QString& csd ); |
310 | signals: | 310 | signals: |
311 | /** | 311 | /** |
312 | Emitted, when the address book has changed on disk. | 312 | Emitted, when the address book has changed on disk. |
313 | */ | 313 | */ |
314 | void addressBookChanged( AddressBook * ); | 314 | void addressBookChanged( AddressBook * ); |
315 | 315 | ||
316 | /** | 316 | /** |
317 | Emitted, when the address book has been locked for writing. | 317 | Emitted, when the address book has been locked for writing. |
318 | */ | 318 | */ |
319 | void addressBookLocked( AddressBook * ); | 319 | void addressBookLocked( AddressBook * ); |
320 | 320 | ||
321 | /** | 321 | /** |
322 | Emitted, when the address book has been unlocked. | 322 | Emitted, when the address book has been unlocked. |
323 | */ | 323 | */ |
324 | void addressBookUnlocked( AddressBook * ); | 324 | void addressBookUnlocked( AddressBook * ); |
325 | 325 | ||
326 | protected: | 326 | protected: |
327 | void deleteRemovedAddressees(); | 327 | void deleteRemovedAddressees(); |
328 | void setStandardResource( Resource * ); | 328 | void setStandardResource( Resource * ); |
329 | Resource *standardResource(); | 329 | Resource *standardResource(); |
330 | KRES::Manager<Resource> *resourceManager(); | 330 | KRES::Manager<Resource> *resourceManager(); |
331 | 331 | ||
332 | void init(const QString &config, const QString &family); | 332 | void init(const QString &config, const QString &family); |
333 | 333 | ||
334 | private: | 334 | private: |
335 | //US QPtrList<Resource> mDummy; // Remove in KDE 4 | 335 | //US QPtrList<Resource> mDummy; // Remove in KDE 4 |
336 | 336 | ||
337 | 337 | ||
338 | struct AddressBookData; | 338 | struct AddressBookData; |
339 | AddressBookData *d; | 339 | AddressBookData *d; |
340 | bool blockLSEchange; | 340 | bool blockLSEchange; |
341 | }; | 341 | }; |
342 | 342 | ||
343 | QDataStream &operator<<( QDataStream &, const AddressBook & ); | 343 | QDataStream &operator<<( QDataStream &, const AddressBook & ); |
344 | QDataStream &operator>>( QDataStream &, AddressBook & ); | 344 | QDataStream &operator>>( QDataStream &, AddressBook & ); |
345 | 345 | ||
346 | } | 346 | } |
347 | 347 | ||
348 | #endif | 348 | #endif |
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index 2aca559..295ee4f 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp | |||
@@ -1,866 +1,900 @@ | |||
1 | /*** Warning! This file has been generated by the script makeaddressee ***/ | 1 | /*** Warning! This file has been generated by the script makeaddressee ***/ |
2 | /* | 2 | /* |
3 | This file is part of libkabc. | 3 | This file is part of libkabc. |
4 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. |
10 | 10 | ||
11 | This library is distributed in the hope that it will be useful, | 11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. | 14 | Library General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU Library General Public License | 16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to | 17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. | 19 | Boston, MA 02111-1307, USA. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | /* | 22 | /* |
23 | Enhanced Version of the file for platform independent KDE tools. | 23 | Enhanced Version of the file for platform independent KDE tools. |
24 | Copyright (c) 2004 Ulf Schenk | 24 | Copyright (c) 2004 Ulf Schenk |
25 | 25 | ||
26 | $Id$ | 26 | $Id$ |
27 | */ | 27 | */ |
28 | 28 | ||
29 | #include <kconfig.h> | 29 | #include <kconfig.h> |
30 | 30 | ||
31 | #include <ksharedptr.h> | 31 | #include <ksharedptr.h> |
32 | #include <kdebug.h> | 32 | #include <kdebug.h> |
33 | #include <kapplication.h> | 33 | #include <kapplication.h> |
34 | #include <klocale.h> | 34 | #include <klocale.h> |
35 | #include <kidmanager.h> | 35 | #include <kidmanager.h> |
36 | //US | 36 | //US |
37 | #include <kstandarddirs.h> | 37 | #include <kstandarddirs.h> |
38 | #include <libkcal/syncdefines.h> | 38 | #include <libkcal/syncdefines.h> |
39 | 39 | ||
40 | //US #include "resource.h" | 40 | //US #include "resource.h" |
41 | #include "addressee.h" | 41 | #include "addressee.h" |
42 | 42 | ||
43 | using namespace KABC; | 43 | using namespace KABC; |
44 | 44 | ||
45 | static bool matchBinaryPattern( int value, int pattern ); | 45 | static bool matchBinaryPattern( int value, int pattern ); |
46 | static bool matchBinaryPatternA( int value, int pattern ); | 46 | static bool matchBinaryPatternA( int value, int pattern ); |
47 | static bool matchBinaryPatternP( int value, int pattern ); | 47 | static bool matchBinaryPatternP( int value, int pattern ); |
48 | 48 | ||
49 | struct Addressee::AddresseeData : public KShared | 49 | struct Addressee::AddresseeData : public KShared |
50 | { | 50 | { |
51 | QString uid; | 51 | QString uid; |
52 | QString name; | 52 | QString name; |
53 | QString formattedName; | 53 | QString formattedName; |
54 | QString familyName; | 54 | QString familyName; |
55 | QString givenName; | 55 | QString givenName; |
56 | QString additionalName; | 56 | QString additionalName; |
57 | QString prefix; | 57 | QString prefix; |
58 | QString suffix; | 58 | QString suffix; |
59 | QString nickName; | 59 | QString nickName; |
60 | QDateTime birthday; | 60 | QDateTime birthday; |
61 | QString mailer; | 61 | QString mailer; |
62 | TimeZone timeZone; | 62 | TimeZone timeZone; |
63 | Geo geo; | 63 | Geo geo; |
64 | QString title; | 64 | QString title; |
65 | QString role; | 65 | QString role; |
66 | QString organization; | 66 | QString organization; |
67 | QString note; | 67 | QString note; |
68 | QString productId; | 68 | QString productId; |
69 | QDateTime revision; | 69 | QDateTime revision; |
70 | QString sortString; | 70 | QString sortString; |
71 | QString externalUID; | 71 | QString externalUID; |
72 | QString originalExternalUID; | 72 | QString originalExternalUID; |
73 | KURL url; | 73 | KURL url; |
74 | Secrecy secrecy; | 74 | Secrecy secrecy; |
75 | Picture logo; | 75 | Picture logo; |
76 | Picture photo; | 76 | Picture photo; |
77 | Sound sound; | 77 | Sound sound; |
78 | Agent agent; | 78 | Agent agent; |
79 | QString mExternalId; | 79 | QString mExternalId; |
80 | PhoneNumber::List phoneNumbers; | 80 | PhoneNumber::List phoneNumbers; |
81 | Address::List addresses; | 81 | Address::List addresses; |
82 | Key::List keys; | 82 | Key::List keys; |
83 | QStringList emails; | 83 | QStringList emails; |
84 | QStringList categories; | 84 | QStringList categories; |
85 | QStringList custom; | 85 | QStringList custom; |
86 | int mTempSyncStat; | 86 | int mTempSyncStat; |
87 | Resource *resource; | 87 | Resource *resource; |
88 | 88 | ||
89 | bool empty :1; | 89 | bool empty :1; |
90 | bool changed :1; | 90 | bool changed :1; |
91 | bool tagged :1; | 91 | bool tagged :1; |
92 | }; | 92 | }; |
93 | 93 | ||
94 | Addressee::Addressee() | 94 | Addressee::Addressee() |
95 | { | 95 | { |
96 | mData = new AddresseeData; | 96 | mData = new AddresseeData; |
97 | mData->empty = true; | 97 | mData->empty = true; |
98 | mData->changed = false; | 98 | mData->changed = false; |
99 | mData->resource = 0; | 99 | mData->resource = 0; |
100 | mData->mExternalId = ":"; | 100 | mData->mExternalId = ":"; |
101 | mData->revision = QDateTime ( QDate( 2003,1,1)); | 101 | mData->revision = QDateTime ( QDate( 2003,1,1)); |
102 | mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL; | 102 | mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL; |
103 | } | 103 | } |
104 | 104 | ||
105 | Addressee::~Addressee() | 105 | Addressee::~Addressee() |
106 | { | 106 | { |
107 | } | 107 | } |
108 | 108 | ||
109 | Addressee::Addressee( const Addressee &a ) | 109 | Addressee::Addressee( const Addressee &a ) |
110 | { | 110 | { |
111 | mData = a.mData; | 111 | mData = a.mData; |
112 | } | 112 | } |
113 | 113 | ||
114 | Addressee &Addressee::operator=( const Addressee &a ) | 114 | Addressee &Addressee::operator=( const Addressee &a ) |
115 | { | 115 | { |
116 | mData = a.mData; | 116 | mData = a.mData; |
117 | return (*this); | 117 | return (*this); |
118 | } | 118 | } |
119 | 119 | ||
120 | Addressee Addressee::copy() | 120 | Addressee Addressee::copy() |
121 | { | 121 | { |
122 | Addressee a; | 122 | Addressee a; |
123 | *(a.mData) = *mData; | 123 | *(a.mData) = *mData; |
124 | return a; | 124 | return a; |
125 | } | 125 | } |
126 | 126 | ||
127 | void Addressee::detach() | 127 | void Addressee::detach() |
128 | { | 128 | { |
129 | if ( mData.count() == 1 ) return; | 129 | if ( mData.count() == 1 ) return; |
130 | *this = copy(); | 130 | *this = copy(); |
131 | } | 131 | } |
132 | 132 | ||
133 | bool Addressee::operator==( const Addressee &a ) const | 133 | bool Addressee::operator==( const Addressee &a ) const |
134 | { | 134 | { |
135 | if ( uid() != a.uid() ) return false; | 135 | if ( uid() != a.uid() ) return false; |
136 | if ( mData->name != a.mData->name ) return false; | 136 | if ( mData->name != a.mData->name ) return false; |
137 | if ( mData->formattedName != a.mData->formattedName ) return false; | 137 | if ( mData->formattedName != a.mData->formattedName ) return false; |
138 | if ( mData->familyName != a.mData->familyName ) return false; | 138 | if ( mData->familyName != a.mData->familyName ) return false; |
139 | if ( mData->givenName != a.mData->givenName ) return false; | 139 | if ( mData->givenName != a.mData->givenName ) return false; |
140 | if ( mData->additionalName != a.mData->additionalName ) return false; | 140 | if ( mData->additionalName != a.mData->additionalName ) return false; |
141 | if ( mData->prefix != a.mData->prefix ) return false; | 141 | if ( mData->prefix != a.mData->prefix ) return false; |
142 | if ( mData->suffix != a.mData->suffix ) return false; | 142 | if ( mData->suffix != a.mData->suffix ) return false; |
143 | if ( mData->nickName != a.mData->nickName ) return false; | 143 | if ( mData->nickName != a.mData->nickName ) return false; |
144 | if ( mData->birthday != a.mData->birthday ) return false; | 144 | if ( mData->birthday != a.mData->birthday ) return false; |
145 | if ( mData->mailer != a.mData->mailer ) return false; | 145 | if ( mData->mailer != a.mData->mailer ) return false; |
146 | if ( mData->timeZone != a.mData->timeZone ) return false; | 146 | if ( mData->timeZone != a.mData->timeZone ) return false; |
147 | if ( mData->geo != a.mData->geo ) return false; | 147 | if ( mData->geo != a.mData->geo ) return false; |
148 | if ( mData->title != a.mData->title ) return false; | 148 | if ( mData->title != a.mData->title ) return false; |
149 | if ( mData->role != a.mData->role ) return false; | 149 | if ( mData->role != a.mData->role ) return false; |
150 | if ( mData->organization != a.mData->organization ) return false; | 150 | if ( mData->organization != a.mData->organization ) return false; |
151 | if ( mData->note != a.mData->note ) return false; | 151 | if ( mData->note != a.mData->note ) return false; |
152 | if ( mData->productId != a.mData->productId ) return false; | 152 | if ( mData->productId != a.mData->productId ) return false; |
153 | //if ( mData->revision != a.mData->revision ) return false; | 153 | //if ( mData->revision != a.mData->revision ) return false; |
154 | if ( mData->sortString != a.mData->sortString ) return false; | 154 | if ( mData->sortString != a.mData->sortString ) return false; |
155 | if ( mData->secrecy != a.mData->secrecy ) return false; | 155 | if ( mData->secrecy != a.mData->secrecy ) return false; |
156 | if ( mData->logo != a.mData->logo ) return false; | 156 | if ( mData->logo != a.mData->logo ) return false; |
157 | if ( mData->photo != a.mData->photo ) return false; | 157 | if ( mData->photo != a.mData->photo ) return false; |
158 | if ( mData->sound != a.mData->sound ) return false; | 158 | if ( mData->sound != a.mData->sound ) return false; |
159 | if ( mData->agent != a.mData->agent ) return false; | 159 | if ( mData->agent != a.mData->agent ) return false; |
160 | if ( ( mData->url.isValid() || a.mData->url.isValid() ) && | 160 | if ( ( mData->url.isValid() || a.mData->url.isValid() ) && |
161 | ( mData->url != a.mData->url ) ) return false; | 161 | ( mData->url != a.mData->url ) ) return false; |
162 | if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false; | 162 | if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false; |
163 | if ( mData->addresses != a.mData->addresses ) return false; | 163 | if ( mData->addresses != a.mData->addresses ) return false; |
164 | if ( mData->keys != a.mData->keys ) return false; | 164 | if ( mData->keys != a.mData->keys ) return false; |
165 | if ( mData->emails != a.mData->emails ) return false; | 165 | if ( mData->emails != a.mData->emails ) return false; |
166 | if ( mData->categories != a.mData->categories ) return false; | 166 | if ( mData->categories != a.mData->categories ) return false; |
167 | if ( mData->custom != a.mData->custom ) return false; | 167 | if ( mData->custom != a.mData->custom ) return false; |
168 | 168 | ||
169 | return true; | 169 | return true; |
170 | } | 170 | } |
171 | 171 | ||
172 | bool Addressee::operator!=( const Addressee &a ) const | 172 | bool Addressee::operator!=( const Addressee &a ) const |
173 | { | 173 | { |
174 | return !( a == *this ); | 174 | return !( a == *this ); |
175 | } | 175 | } |
176 | 176 | ||
177 | bool Addressee::isEmpty() const | 177 | bool Addressee::isEmpty() const |
178 | { | 178 | { |
179 | return mData->empty; | 179 | return mData->empty; |
180 | } | 180 | } |
181 | ulong Addressee::getCsum4List( const QStringList & attList) | 181 | ulong Addressee::getCsum4List( const QStringList & attList) |
182 | { | 182 | { |
183 | int max = attList.count(); | 183 | int max = attList.count(); |
184 | ulong cSum = 0; | 184 | ulong cSum = 0; |
185 | int j,k,i; | 185 | int j,k,i; |
186 | int add; | 186 | int add; |
187 | for ( i = 0; i < max ; ++i ) { | 187 | for ( i = 0; i < max ; ++i ) { |
188 | QString s = attList[i]; | 188 | QString s = attList[i]; |
189 | if ( ! s.isEmpty() ){ | 189 | if ( ! s.isEmpty() ){ |
190 | j = s.length(); | 190 | j = s.length(); |
191 | for ( k = 0; k < j; ++k ) { | 191 | for ( k = 0; k < j; ++k ) { |
192 | int mul = k +1; | 192 | int mul = k +1; |
193 | add = s[k].unicode (); | 193 | add = s[k].unicode (); |
194 | if ( k < 16 ) | 194 | if ( k < 16 ) |
195 | mul = mul * mul; | 195 | mul = mul * mul; |
196 | int ii = i+1; | 196 | int ii = i+1; |
197 | add = add * mul *ii*ii*ii; | 197 | add = add * mul *ii*ii*ii; |
198 | cSum += add; | 198 | cSum += add; |
199 | } | 199 | } |
200 | } | 200 | } |
201 | 201 | ||
202 | } | 202 | } |
203 | //QString dump = attList.join(","); | 203 | //QString dump = attList.join(","); |
204 | //qDebug("csum: %d %s", cSum,dump.latin1()); | 204 | //qDebug("csum: %d %s", cSum,dump.latin1()); |
205 | 205 | ||
206 | return cSum; | 206 | return cSum; |
207 | 207 | ||
208 | } | 208 | } |
209 | void Addressee::computeCsum(const QString &dev) | 209 | void Addressee::computeCsum(const QString &dev) |
210 | { | 210 | { |
211 | QStringList l; | 211 | QStringList l; |
212 | if ( !mData->name.isEmpty() ) l.append(mData->name); | 212 | if ( !mData->name.isEmpty() ) l.append(mData->name); |
213 | if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName ); | 213 | if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName ); |
214 | if ( !mData->familyName.isEmpty() ) l.append( mData->familyName ); | 214 | if ( !mData->familyName.isEmpty() ) l.append( mData->familyName ); |
215 | if ( !mData->givenName.isEmpty() ) l.append(mData->givenName ); | 215 | if ( !mData->givenName.isEmpty() ) l.append(mData->givenName ); |
216 | if ( !mData->additionalName ) l.append( mData->additionalName ); | 216 | if ( !mData->additionalName ) l.append( mData->additionalName ); |
217 | if ( !mData->prefix.isEmpty() ) l.append( mData->prefix ); | 217 | if ( !mData->prefix.isEmpty() ) l.append( mData->prefix ); |
218 | if ( !mData->suffix.isEmpty() ) l.append( mData->suffix ); | 218 | if ( !mData->suffix.isEmpty() ) l.append( mData->suffix ); |
219 | if ( !mData->nickName.isEmpty() ) l.append( mData->nickName ); | 219 | if ( !mData->nickName.isEmpty() ) l.append( mData->nickName ); |
220 | if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() ); | 220 | if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() ); |
221 | if ( !mData->mailer.isEmpty() ) l.append( mData->mailer ); | 221 | if ( !mData->mailer.isEmpty() ) l.append( mData->mailer ); |
222 | if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() ); | 222 | if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() ); |
223 | if ( mData->geo.isValid() ) l.append( mData->geo.asString() ); | 223 | if ( mData->geo.isValid() ) l.append( mData->geo.asString() ); |
224 | if ( !mData->title .isEmpty() ) l.append( mData->title ); | 224 | if ( !mData->title .isEmpty() ) l.append( mData->title ); |
225 | if ( !mData->role.isEmpty() ) l.append( mData->role ); | 225 | if ( !mData->role.isEmpty() ) l.append( mData->role ); |
226 | if ( !mData->organization.isEmpty() ) l.append( mData->organization ); | 226 | if ( !mData->organization.isEmpty() ) l.append( mData->organization ); |
227 | if ( !mData->note.isEmpty() ) l.append( mData->note ); | 227 | if ( !mData->note.isEmpty() ) l.append( mData->note ); |
228 | if ( !mData->productId.isEmpty() ) l.append(mData->productId ); | 228 | if ( !mData->productId.isEmpty() ) l.append(mData->productId ); |
229 | if ( !mData->sortString.isEmpty() ) l.append( mData->sortString ); | 229 | if ( !mData->sortString.isEmpty() ) l.append( mData->sortString ); |
230 | if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString()); | 230 | if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString()); |
231 | // if ( !mData->logo.isEmpty() ) l.append( ); | 231 | // if ( !mData->logo.isEmpty() ) l.append( ); |
232 | //if ( !mData->photo.isEmpty() ) l.append( ); | 232 | //if ( !mData->photo.isEmpty() ) l.append( ); |
233 | //if ( !mData->sound.isEmpty() ) l.append( ); | 233 | //if ( !mData->sound.isEmpty() ) l.append( ); |
234 | //if ( !mData->agent.isEmpty() ) l.append( ); | 234 | //if ( !mData->agent.isEmpty() ) l.append( ); |
235 | if ( mData->url.isValid() ) | 235 | if ( mData->url.isValid() ) |
236 | if ( ! mData->url.path().isEmpty()) l.append( mData->url.path() ); | 236 | if ( ! mData->url.path().isEmpty()) l.append( mData->url.path() ); |
237 | KABC::PhoneNumber::List phoneNumbers; | 237 | KABC::PhoneNumber::List phoneNumbers; |
238 | KABC::PhoneNumber::List::Iterator phoneIter; | 238 | KABC::PhoneNumber::List::Iterator phoneIter; |
239 | 239 | ||
240 | QStringList t; | 240 | QStringList t; |
241 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); | 241 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); |
242 | ++phoneIter ) | 242 | ++phoneIter ) |
243 | t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) ); | 243 | t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) ); |
244 | t.sort(); | 244 | t.sort(); |
245 | uint iii; | 245 | uint iii; |
246 | for ( iii = 0; iii < t.count(); ++iii) | 246 | for ( iii = 0; iii < t.count(); ++iii) |
247 | l.append( t[iii] ); | 247 | l.append( t[iii] ); |
248 | t = mData->emails; | 248 | t = mData->emails; |
249 | t.sort(); | 249 | t.sort(); |
250 | for ( iii = 0; iii < t.count(); ++iii) | 250 | for ( iii = 0; iii < t.count(); ++iii) |
251 | l.append( t[iii] ); | 251 | l.append( t[iii] ); |
252 | t = mData->categories; | 252 | t = mData->categories; |
253 | t.sort(); | 253 | t.sort(); |
254 | for ( iii = 0; iii < t.count(); ++iii) | 254 | for ( iii = 0; iii < t.count(); ++iii) |
255 | l.append( t[iii] ); | 255 | l.append( t[iii] ); |
256 | t = mData->custom; | 256 | t = mData->custom; |
257 | t.sort(); | 257 | t.sort(); |
258 | for ( iii = 0; iii < t.count(); ++iii) | 258 | for ( iii = 0; iii < t.count(); ++iii) |
259 | l.append( t[iii] ); | 259 | l.append( t[iii] ); |
260 | KABC::Address::List::Iterator addressIter; | 260 | KABC::Address::List::Iterator addressIter; |
261 | for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); | 261 | for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); |
262 | ++addressIter ) { | 262 | ++addressIter ) { |
263 | t = (*addressIter).asList(); | 263 | t = (*addressIter).asList(); |
264 | t.sort(); | 264 | t.sort(); |
265 | for ( iii = 0; iii < t.count(); ++iii) | 265 | for ( iii = 0; iii < t.count(); ++iii) |
266 | l.append( t[iii] ); | 266 | l.append( t[iii] ); |
267 | } | 267 | } |
268 | uint cs = getCsum4List(l); | 268 | uint cs = getCsum4List(l); |
269 | // qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() ); | 269 | // qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() ); |
270 | setCsum( dev, QString::number (cs )); | 270 | setCsum( dev, QString::number (cs )); |
271 | } | 271 | } |
272 | 272 | ||
273 | void Addressee::mergeContact( const Addressee& ad , bool isSubSet) // = false) | 273 | void Addressee::mergeContact( const Addressee& ad , bool isSubSet) // = false) |
274 | { | 274 | { |
275 | 275 | ||
276 | detach(); | 276 | detach(); |
277 | if ( mData->name.isEmpty() ) mData->name = ad.mData->name; | 277 | if ( mData->name.isEmpty() ) mData->name = ad.mData->name; |
278 | if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName; | 278 | if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName; |
279 | if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName; | 279 | if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName; |
280 | if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ; | 280 | if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ; |
281 | if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName; | 281 | if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName; |
282 | if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix; | 282 | if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix; |
283 | if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix; | 283 | if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix; |
284 | if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName; | 284 | if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName; |
285 | if ( !mData->birthday.isValid() ) | 285 | if ( !mData->birthday.isValid() ) |
286 | if ( ad.mData->birthday.isValid()) | 286 | if ( ad.mData->birthday.isValid()) |
287 | mData->birthday = ad.mData->birthday; | 287 | mData->birthday = ad.mData->birthday; |
288 | if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer; | 288 | if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer; |
289 | if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone; | 289 | if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone; |
290 | if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo; | 290 | if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo; |
291 | if ( mData->title .isEmpty() ) mData->title = ad.mData->title ; | 291 | if ( mData->title .isEmpty() ) mData->title = ad.mData->title ; |
292 | if ( mData->role.isEmpty() ) mData->role = ad.mData->role ; | 292 | if ( mData->role.isEmpty() ) mData->role = ad.mData->role ; |
293 | if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ; | 293 | if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ; |
294 | if ( mData->note.isEmpty() ) mData->note = ad.mData->note ; | 294 | if ( mData->note.isEmpty() ) mData->note = ad.mData->note ; |
295 | if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId; | 295 | if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId; |
296 | if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString; | 296 | if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString; |
297 | if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy; | 297 | if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy; |
298 | if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ; | 298 | if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ; |
299 | QStringList t; | 299 | QStringList t; |
300 | QStringList tAD; | 300 | QStringList tAD; |
301 | uint iii; | 301 | uint iii; |
302 | if ( isSubSet ) { | 302 | |
303 | // ********** phone numbers | 303 | // ********** phone numbers |
304 | PhoneNumber::List phoneAD = ad.phoneNumbers(); | 304 | PhoneNumber::List phoneAD = ad.phoneNumbers(); |
305 | PhoneNumber::List::Iterator phoneItAD; | 305 | PhoneNumber::List::Iterator phoneItAD; |
306 | for ( phoneItAD = phoneAD.begin(); phoneItAD != phoneAD.end(); ++phoneItAD ) { | 306 | for ( phoneItAD = phoneAD.begin(); phoneItAD != phoneAD.end(); ++phoneItAD ) { |
307 | bool found = false; | 307 | bool found = false; |
308 | PhoneNumber::List::Iterator it; | 308 | PhoneNumber::List::Iterator it; |
309 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { | 309 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { |
310 | if ( ( *phoneItAD ).contains( (*it) ) ) { | 310 | if ( ( *phoneItAD ).contains( (*it) ) ) { |
311 | found = true; | 311 | found = true; |
312 | (*it).setType( ( *phoneItAD ).type() ); | 312 | (*it).setType( ( *phoneItAD ).type() ); |
313 | break; | 313 | break; |
314 | } | ||
315 | } | 314 | } |
316 | if ( ! found ) | ||
317 | mData->phoneNumbers.append( *phoneItAD ); | ||
318 | } | 315 | } |
316 | if ( isSubSet && ! found ) | ||
317 | mData->phoneNumbers.append( *phoneItAD ); | ||
318 | } | ||
319 | if ( isSubSet ) { | ||
319 | // ************* emails; | 320 | // ************* emails; |
320 | t = mData->emails; | 321 | t = mData->emails; |
321 | tAD = ad.mData->emails; | 322 | tAD = ad.mData->emails; |
322 | for ( iii = 0; iii < tAD.count(); ++iii) | 323 | for ( iii = 0; iii < tAD.count(); ++iii) |
323 | if ( !t.contains(tAD[iii] ) ) | 324 | if ( !t.contains(tAD[iii] ) ) |
324 | mData->emails.append( tAD[iii] ); | 325 | mData->emails.append( tAD[iii] ); |
325 | // ************* categories; | ||
326 | t = mData->categories; | ||
327 | tAD = ad.mData->categories; | ||
328 | for ( iii = 0; iii < tAD.count(); ++iii) | ||
329 | if ( !t.contains(tAD[iii] ) ) | ||
330 | mData->categories.append( tAD[iii] ); | ||
331 | |||
332 | |||
333 | } | 326 | } |
334 | 327 | ||
328 | // ************* categories; | ||
329 | t = mData->categories; | ||
330 | tAD = ad.mData->categories; | ||
331 | for ( iii = 0; iii < tAD.count(); ++iii) | ||
332 | if ( !t.contains(tAD[iii] ) ) | ||
333 | mData->categories.append( tAD[iii] ); | ||
335 | QStringList::ConstIterator it; | 334 | QStringList::ConstIterator it; |
336 | for( it = ad.mData->custom.begin(); it != ad.mData->custom.end(); ++it ) { | 335 | for( it = ad.mData->custom.begin(); it != ad.mData->custom.end(); ++it ) { |
337 | QString qualifiedName = (*it).left( (*it).find( ":" )); | 336 | QString qualifiedName = (*it).left( (*it).find( ":" )); |
338 | bool found = false; | 337 | bool found = false; |
339 | QStringList::ConstIterator itL; | 338 | QStringList::ConstIterator itL; |
340 | for( itL = mData->custom.begin(); itL != mData->custom.end(); ++itL ) { | 339 | for( itL = mData->custom.begin(); itL != mData->custom.end(); ++itL ) { |
341 | if ( (*itL).startsWith( qualifiedName ) ) { | 340 | if ( (*itL).startsWith( qualifiedName ) ) { |
342 | found = true; | 341 | found = true; |
343 | break; | 342 | break; |
344 | } | 343 | } |
345 | } | 344 | } |
346 | if ( ! found ) { | 345 | if ( ! found ) { |
347 | mData->custom.append( *it ); | 346 | mData->custom.append( *it ); |
348 | } | 347 | } |
349 | } | 348 | } |
350 | if ( mData->logo.undefined() && !ad.mData->logo.undefined() ) mData->logo = ad.mData->logo; | 349 | if ( mData->logo.undefined() && !ad.mData->logo.undefined() ) mData->logo = ad.mData->logo; |
351 | if ( mData->photo.undefined() && !ad.mData->photo.undefined() ) mData->photo = ad.mData->photo; | 350 | if ( mData->photo.undefined() && !ad.mData->photo.undefined() ) mData->photo = ad.mData->photo; |
352 | if ( !mData->sound.isIntern() ) { | 351 | if ( !mData->sound.isIntern() ) { |
353 | if ( mData->sound.url().isEmpty() ) { | 352 | if ( mData->sound.url().isEmpty() ) { |
354 | mData->sound = ad.mData->sound; | 353 | mData->sound = ad.mData->sound; |
355 | } | 354 | } |
356 | } | 355 | } |
357 | if ( !mData->agent.isIntern() ) { | 356 | if ( !mData->agent.isIntern() ) { |
358 | if ( mData->agent.url().isEmpty() ) { | 357 | if ( mData->agent.url().isEmpty() ) { |
359 | mData->agent = ad.mData->agent; | 358 | mData->agent = ad.mData->agent; |
360 | } | 359 | } |
361 | } | 360 | } |
362 | { | 361 | { |
363 | Key::List::Iterator itA; | 362 | Key::List::Iterator itA; |
364 | for( itA = ad.mData->keys.begin(); itA != ad.mData->keys.end(); ++itA ) { | 363 | for( itA = ad.mData->keys.begin(); itA != ad.mData->keys.end(); ++itA ) { |
365 | bool found = false; | 364 | bool found = false; |
366 | Key::List::Iterator it; | 365 | Key::List::Iterator it; |
367 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { | 366 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { |
368 | if ( (*it) == (*itA)) { | 367 | if ( (*it) == (*itA)) { |
369 | found = true; | 368 | found = true; |
370 | break; | 369 | break; |
371 | 370 | ||
372 | } | 371 | } |
373 | } | 372 | } |
374 | if ( ! found ) { | 373 | if ( ! found ) { |
375 | mData->keys.append( *itA ); | 374 | mData->keys.append( *itA ); |
376 | } | 375 | } |
377 | } | 376 | } |
378 | } | 377 | } |
379 | KABC::Address::List::Iterator addressIterA; | 378 | KABC::Address::List::Iterator addressIterA; |
380 | for ( addressIterA = ad.mData->addresses.begin(); addressIterA != ad.mData->addresses.end(); ++addressIterA ) { | 379 | for ( addressIterA = ad.mData->addresses.begin(); addressIterA != ad.mData->addresses.end(); ++addressIterA ) { |
381 | bool found = false; | 380 | bool found = false; |
382 | KABC::Address::List::Iterator addressIter; | 381 | KABC::Address::List::Iterator addressIter; |
383 | for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); | 382 | for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); |
384 | ++addressIter ) { | 383 | ++addressIter ) { |
385 | if ( (*addressIter) == (*addressIterA)) { | 384 | if ( (*addressIter) == (*addressIterA)) { |
386 | found = true; | 385 | found = true; |
387 | (*addressIter).setType( (*addressIterA).type() ); | 386 | (*addressIter).setType( (*addressIterA).type() ); |
388 | break; | 387 | break; |
389 | } | 388 | } |
390 | 389 | ||
391 | } | 390 | } |
392 | if ( ! found ) { | 391 | if ( isSubSet && ! found ) { |
393 | mData->addresses.append( *addressIterA ); | 392 | mData->addresses.append( *addressIterA ); |
394 | } | 393 | } |
395 | } | 394 | } |
396 | //qDebug("merge contact %s ", ad.uid().latin1()); | 395 | //qDebug("merge contact %s ", ad.uid().latin1()); |
397 | setUid( ad.uid() ); | 396 | setUid( ad.uid() ); |
398 | setRevision( ad.revision() ); | 397 | setRevision( ad.revision() ); |
399 | } | 398 | } |
400 | 399 | ||
401 | bool Addressee::removeVoice() | 400 | bool Addressee::removeVoice() |
402 | { | 401 | { |
403 | PhoneNumber::List phoneN = phoneNumbers(); | 402 | PhoneNumber::List phoneN = phoneNumbers(); |
404 | PhoneNumber::List::Iterator phoneIt; | 403 | PhoneNumber::List::Iterator phoneIt; |
405 | bool found = false; | 404 | bool found = false; |
406 | for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { | 405 | for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { |
407 | if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found | 406 | if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found |
408 | if ((*phoneIt).type() - PhoneNumber::Voice ) { | 407 | if ((*phoneIt).type() - PhoneNumber::Voice ) { |
409 | (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice ); | 408 | (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice ); |
410 | insertPhoneNumber( (*phoneIt) ); | 409 | insertPhoneNumber( (*phoneIt) ); |
411 | found = true; | 410 | found = true; |
412 | } | 411 | } |
413 | } | 412 | } |
414 | 413 | ||
415 | } | 414 | } |
416 | return found; | 415 | return found; |
417 | } | 416 | } |
418 | 417 | ||
419 | bool Addressee::containsAdr(const Addressee& ad ) | 418 | bool Addressee::containsAdr(const Addressee& ad ) |
420 | { | 419 | { |
421 | 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; |
422 | 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; |
423 | 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 ; |
424 | 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 ; |
425 | 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 ; |
426 | 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 ; |
427 | 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 ; |
428 | 427 | ||
429 | // compare phone numbers | 428 | // compare phone numbers |
430 | PhoneNumber::List phoneN = ad.phoneNumbers(); | 429 | PhoneNumber::List phoneN = ad.phoneNumbers(); |
431 | PhoneNumber::List::Iterator phoneIt; | 430 | PhoneNumber::List::Iterator phoneIt; |
432 | bool found = false; | 431 | bool found = false; |
433 | for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { | 432 | for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { |
434 | bool found = false; | 433 | bool found = false; |
435 | PhoneNumber::List phoneL = ad.phoneNumbers(); | 434 | PhoneNumber::List phoneL = ad.phoneNumbers(); |
436 | PhoneNumber::List::Iterator phoneItL; | 435 | PhoneNumber::List::Iterator phoneItL; |
437 | for ( phoneItL = phoneL.begin(); phoneItL != phoneL.end(); ++phoneItL ) { | 436 | for ( phoneItL = phoneL.begin(); phoneItL != phoneL.end(); ++phoneItL ) { |
438 | if ( ( *phoneItL ).number() == ( *phoneIt ).number() ) { | 437 | if ( ( *phoneItL ).number() == ( *phoneIt ).number() ) { |
439 | found = true; | 438 | found = true; |
440 | break; | 439 | break; |
441 | } | 440 | } |
442 | } | 441 | } |
443 | if ( ! found ) | 442 | if ( ! found ) |
444 | return false; | 443 | return false; |
445 | } | 444 | } |
446 | return true; | 445 | return true; |
447 | 446 | ||
448 | } | 447 | } |
449 | void Addressee::simplifyAddresses() | 448 | void Addressee::simplifyAddresses() |
450 | { | 449 | { |
451 | int max = 2; | 450 | int max = 2; |
452 | if ( mData->url.isValid() ) | 451 | if ( mData->url.isValid() ) |
453 | max = 1; | 452 | max = 1; |
454 | if ( mData->addresses.count() <= max ) return ; | 453 | if ( mData->addresses.count() <= max ) return ; |
455 | int count = 0; | 454 | int count = 0; |
456 | Address::List list; | 455 | Address::List list; |
457 | Address::List::Iterator it; | 456 | Address::List::Iterator it; |
458 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { | 457 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { |
459 | if ( count >= max ) | 458 | if ( count >= max ) |
460 | list.append( *it ); | 459 | list.append( *it ); |
461 | ++count; | 460 | ++count; |
462 | } | 461 | } |
463 | for( it = list.begin(); it != list.end(); ++it ) { | 462 | for( it = list.begin(); it != list.end(); ++it ) { |
464 | removeAddress( (*it) ); | 463 | removeAddress( (*it) ); |
465 | } | 464 | } |
466 | } | 465 | } |
467 | 466 | ||
468 | // removes all emails but the first | 467 | // removes all emails but the first |
469 | // needed by phone sync | 468 | // needed by phone sync |
470 | void Addressee::simplifyEmails() | 469 | void Addressee::simplifyEmails() |
471 | { | 470 | { |
472 | if ( mData->emails.count() == 0 ) return ; | 471 | if ( mData->emails.count() == 0 ) return ; |
473 | QString email = mData->emails.first(); | 472 | QString email = mData->emails.first(); |
474 | detach(); | 473 | detach(); |
475 | mData->emails.clear(); | 474 | mData->emails.clear(); |
476 | mData->emails.append( email ); | 475 | mData->emails.append( email ); |
477 | } | 476 | } |
478 | 477 | ||
479 | void Addressee::simplifyPhoneNumbers() | 478 | void Addressee::simplifyPhoneNumbers() |
480 | { | 479 | { |
480 | int max = 4; | ||
481 | int inList = mData->phoneNumbers.count(); | ||
481 | KABC::PhoneNumber::List removeNumbers; | 482 | KABC::PhoneNumber::List removeNumbers; |
482 | KABC::PhoneNumber::List::Iterator phoneIter; | 483 | KABC::PhoneNumber::List::Iterator phoneIter; |
484 | if ( inList > max ) { | ||
485 | // delete non-preferred numbers | ||
486 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); | ||
487 | ++phoneIter ) { | ||
488 | if ( inList > max ) { | ||
489 | if ( ! (( *phoneIter ).type() & PhoneNumber::Pref )) { | ||
490 | removeNumbers.append( ( *phoneIter ) ); | ||
491 | --inList; | ||
492 | } | ||
493 | } else | ||
494 | break; | ||
495 | } | ||
496 | for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); | ||
497 | ++phoneIter ) { | ||
498 | removePhoneNumber(( *phoneIter )); | ||
499 | } | ||
500 | // delete preferred numbers | ||
501 | if ( inList > max ) { | ||
502 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); | ||
503 | ++phoneIter ) { | ||
504 | if ( inList > max ) { | ||
505 | removeNumbers.append( ( *phoneIter ) ); | ||
506 | --inList; | ||
507 | } else | ||
508 | break; | ||
509 | } | ||
510 | for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); | ||
511 | ++phoneIter ) { | ||
512 | removePhoneNumber(( *phoneIter )); | ||
513 | } | ||
514 | } | ||
515 | } | ||
516 | // remove non-numeric characters | ||
483 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); | 517 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); |
484 | ++phoneIter ) { | 518 | ++phoneIter ) { |
485 | if ( ! ( *phoneIter ).simplifyNumber() ) | 519 | if ( ! ( *phoneIter ).simplifyNumber() ) |
486 | removeNumbers.append( ( *phoneIter ) ); | 520 | removeNumbers.append( ( *phoneIter ) ); |
487 | } | 521 | } |
488 | for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); | 522 | for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); |
489 | ++phoneIter ) { | 523 | ++phoneIter ) { |
490 | removePhoneNumber(( *phoneIter )); | 524 | removePhoneNumber(( *phoneIter )); |
491 | } | 525 | } |
492 | } | 526 | } |
493 | void Addressee::simplifyPhoneNumberTypes() | 527 | void Addressee::simplifyPhoneNumberTypes() |
494 | { | 528 | { |
495 | KABC::PhoneNumber::List::Iterator phoneIter; | 529 | KABC::PhoneNumber::List::Iterator phoneIter; |
496 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); | 530 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); |
497 | ++phoneIter ) | 531 | ++phoneIter ) |
498 | ( *phoneIter ).simplifyType(); | 532 | ( *phoneIter ).simplifyType(); |
499 | } | 533 | } |
500 | void Addressee::removeID(const QString &prof) | 534 | void Addressee::removeID(const QString &prof) |
501 | { | 535 | { |
502 | detach(); | 536 | detach(); |
503 | mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof); | 537 | mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof); |
504 | 538 | ||
505 | } | 539 | } |
506 | void Addressee::setID( const QString & prof , const QString & id ) | 540 | void Addressee::setID( const QString & prof , const QString & id ) |
507 | { | 541 | { |
508 | detach(); | 542 | detach(); |
509 | mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id ); | 543 | mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id ); |
510 | //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); | 544 | //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); |
511 | } | 545 | } |
512 | void Addressee::setTempSyncStat( int id ) | 546 | void Addressee::setTempSyncStat( int id ) |
513 | { | 547 | { |
514 | if ( mData->mTempSyncStat == id ) return; | 548 | if ( mData->mTempSyncStat == id ) return; |
515 | detach(); | 549 | detach(); |
516 | mData->mTempSyncStat = id; | 550 | mData->mTempSyncStat = id; |
517 | } | 551 | } |
518 | int Addressee::tempSyncStat() const | 552 | int Addressee::tempSyncStat() const |
519 | { | 553 | { |
520 | return mData->mTempSyncStat; | 554 | return mData->mTempSyncStat; |
521 | } | 555 | } |
522 | 556 | ||
523 | QString Addressee::getID( const QString & prof) | 557 | QString Addressee::getID( const QString & prof) |
524 | { | 558 | { |
525 | return KIdManager::getId ( mData->mExternalId, prof ); | 559 | return KIdManager::getId ( mData->mExternalId, prof ); |
526 | } | 560 | } |
527 | 561 | ||
528 | void Addressee::setCsum( const QString & prof , const QString & id ) | 562 | void Addressee::setCsum( const QString & prof , const QString & id ) |
529 | { | 563 | { |
530 | detach(); | 564 | detach(); |
531 | //qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); | 565 | //qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); |
532 | mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id ); | 566 | mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id ); |
533 | //qDebug("setcsum2 %s ",mData->mExternalId.latin1() ); | 567 | //qDebug("setcsum2 %s ",mData->mExternalId.latin1() ); |
534 | } | 568 | } |
535 | 569 | ||
536 | QString Addressee::getCsum( const QString & prof) | 570 | QString Addressee::getCsum( const QString & prof) |
537 | { | 571 | { |
538 | return KIdManager::getCsum ( mData->mExternalId, prof ); | 572 | return KIdManager::getCsum ( mData->mExternalId, prof ); |
539 | } | 573 | } |
540 | 574 | ||
541 | void Addressee::setIDStr( const QString & s ) | 575 | void Addressee::setIDStr( const QString & s ) |
542 | { | 576 | { |
543 | detach(); | 577 | detach(); |
544 | mData->mExternalId = s; | 578 | mData->mExternalId = s; |
545 | } | 579 | } |
546 | 580 | ||
547 | QString Addressee::IDStr() const | 581 | QString Addressee::IDStr() const |
548 | { | 582 | { |
549 | return mData->mExternalId; | 583 | return mData->mExternalId; |
550 | } | 584 | } |
551 | 585 | ||
552 | void Addressee::setExternalUID( const QString &id ) | 586 | void Addressee::setExternalUID( const QString &id ) |
553 | { | 587 | { |
554 | if ( id == mData->externalUID ) return; | 588 | if ( id == mData->externalUID ) return; |
555 | detach(); | 589 | detach(); |
556 | mData->empty = false; | 590 | mData->empty = false; |
557 | mData->externalUID = id; | 591 | mData->externalUID = id; |
558 | } | 592 | } |
559 | 593 | ||
560 | QString Addressee::externalUID() const | 594 | QString Addressee::externalUID() const |
561 | { | 595 | { |
562 | return mData->externalUID; | 596 | return mData->externalUID; |
563 | } | 597 | } |
564 | void Addressee::setOriginalExternalUID( const QString &id ) | 598 | void Addressee::setOriginalExternalUID( const QString &id ) |
565 | { | 599 | { |
566 | if ( id == mData->originalExternalUID ) return; | 600 | if ( id == mData->originalExternalUID ) return; |
567 | detach(); | 601 | detach(); |
568 | mData->empty = false; | 602 | mData->empty = false; |
569 | //qDebug("*******Set orig uid %s ", id.latin1()); | 603 | //qDebug("*******Set orig uid %s ", id.latin1()); |
570 | mData->originalExternalUID = id; | 604 | mData->originalExternalUID = id; |
571 | } | 605 | } |
572 | 606 | ||
573 | QString Addressee::originalExternalUID() const | 607 | QString Addressee::originalExternalUID() const |
574 | { | 608 | { |
575 | return mData->originalExternalUID; | 609 | return mData->originalExternalUID; |
576 | } | 610 | } |
577 | 611 | ||
578 | void Addressee::setUid( const QString &id ) | 612 | void Addressee::setUid( const QString &id ) |
579 | { | 613 | { |
580 | if ( id == mData->uid ) return; | 614 | if ( id == mData->uid ) return; |
581 | detach(); | 615 | detach(); |
582 | //qDebug("****setuid %s ", id.latin1()); | 616 | //qDebug("****setuid %s ", id.latin1()); |
583 | mData->empty = false; | 617 | mData->empty = false; |
584 | mData->uid = id; | 618 | mData->uid = id; |
585 | } | 619 | } |
586 | 620 | ||
587 | QString Addressee::uid() const | 621 | QString Addressee::uid() const |
588 | { | 622 | { |
589 | if ( mData->uid.isEmpty() ) | 623 | if ( mData->uid.isEmpty() ) |
590 | mData->uid = KApplication::randomString( 10 ); | 624 | mData->uid = KApplication::randomString( 10 ); |
591 | 625 | ||
592 | return mData->uid; | 626 | return mData->uid; |
593 | } | 627 | } |
594 | 628 | ||
595 | QString Addressee::uidLabel() | 629 | QString Addressee::uidLabel() |
596 | { | 630 | { |
597 | return i18n("Unique Identifier"); | 631 | return i18n("Unique Identifier"); |
598 | } | 632 | } |
599 | 633 | ||
600 | void Addressee::setName( const QString &name ) | 634 | void Addressee::setName( const QString &name ) |
601 | { | 635 | { |
602 | if ( name == mData->name ) return; | 636 | if ( name == mData->name ) return; |
603 | detach(); | 637 | detach(); |
604 | mData->empty = false; | 638 | mData->empty = false; |
605 | mData->name = name; | 639 | mData->name = name; |
606 | } | 640 | } |
607 | 641 | ||
608 | QString Addressee::name() const | 642 | QString Addressee::name() const |
609 | { | 643 | { |
610 | return mData->name; | 644 | return mData->name; |
611 | } | 645 | } |
612 | 646 | ||
613 | QString Addressee::nameLabel() | 647 | QString Addressee::nameLabel() |
614 | { | 648 | { |
615 | return i18n("Name"); | 649 | return i18n("Name"); |
616 | } | 650 | } |
617 | 651 | ||
618 | 652 | ||
619 | void Addressee::setFormattedName( const QString &formattedName ) | 653 | void Addressee::setFormattedName( const QString &formattedName ) |
620 | { | 654 | { |
621 | if ( formattedName == mData->formattedName ) return; | 655 | if ( formattedName == mData->formattedName ) return; |
622 | detach(); | 656 | detach(); |
623 | mData->empty = false; | 657 | mData->empty = false; |
624 | mData->formattedName = formattedName; | 658 | mData->formattedName = formattedName; |
625 | } | 659 | } |
626 | 660 | ||
627 | QString Addressee::formattedName() const | 661 | QString Addressee::formattedName() const |
628 | { | 662 | { |
629 | return mData->formattedName; | 663 | return mData->formattedName; |
630 | } | 664 | } |
631 | 665 | ||
632 | QString Addressee::formattedNameLabel() | 666 | QString Addressee::formattedNameLabel() |
633 | { | 667 | { |
634 | return i18n("Formatted Name"); | 668 | return i18n("Formatted Name"); |
635 | } | 669 | } |
636 | 670 | ||
637 | 671 | ||
638 | void Addressee::setFamilyName( const QString &familyName ) | 672 | void Addressee::setFamilyName( const QString &familyName ) |
639 | { | 673 | { |
640 | if ( familyName == mData->familyName ) return; | 674 | if ( familyName == mData->familyName ) return; |
641 | detach(); | 675 | detach(); |
642 | mData->empty = false; | 676 | mData->empty = false; |
643 | mData->familyName = familyName; | 677 | mData->familyName = familyName; |
644 | } | 678 | } |
645 | 679 | ||
646 | QString Addressee::familyName() const | 680 | QString Addressee::familyName() const |
647 | { | 681 | { |
648 | return mData->familyName; | 682 | return mData->familyName; |
649 | } | 683 | } |
650 | 684 | ||
651 | QString Addressee::familyNameLabel() | 685 | QString Addressee::familyNameLabel() |
652 | { | 686 | { |
653 | return i18n("Family Name"); | 687 | return i18n("Family Name"); |
654 | } | 688 | } |
655 | 689 | ||
656 | 690 | ||
657 | void Addressee::setGivenName( const QString &givenName ) | 691 | void Addressee::setGivenName( const QString &givenName ) |
658 | { | 692 | { |
659 | if ( givenName == mData->givenName ) return; | 693 | if ( givenName == mData->givenName ) return; |
660 | detach(); | 694 | detach(); |
661 | mData->empty = false; | 695 | mData->empty = false; |
662 | mData->givenName = givenName; | 696 | mData->givenName = givenName; |
663 | } | 697 | } |
664 | 698 | ||
665 | QString Addressee::givenName() const | 699 | QString Addressee::givenName() const |
666 | { | 700 | { |
667 | return mData->givenName; | 701 | return mData->givenName; |
668 | } | 702 | } |
669 | 703 | ||
670 | QString Addressee::givenNameLabel() | 704 | QString Addressee::givenNameLabel() |
671 | { | 705 | { |
672 | return i18n("Given Name"); | 706 | return i18n("Given Name"); |
673 | } | 707 | } |
674 | 708 | ||
675 | 709 | ||
676 | void Addressee::setAdditionalName( const QString &additionalName ) | 710 | void Addressee::setAdditionalName( const QString &additionalName ) |
677 | { | 711 | { |
678 | if ( additionalName == mData->additionalName ) return; | 712 | if ( additionalName == mData->additionalName ) return; |
679 | detach(); | 713 | detach(); |
680 | mData->empty = false; | 714 | mData->empty = false; |
681 | mData->additionalName = additionalName; | 715 | mData->additionalName = additionalName; |
682 | } | 716 | } |
683 | 717 | ||
684 | QString Addressee::additionalName() const | 718 | QString Addressee::additionalName() const |
685 | { | 719 | { |
686 | return mData->additionalName; | 720 | return mData->additionalName; |
687 | } | 721 | } |
688 | 722 | ||
689 | QString Addressee::additionalNameLabel() | 723 | QString Addressee::additionalNameLabel() |
690 | { | 724 | { |
691 | return i18n("Additional Names"); | 725 | return i18n("Additional Names"); |
692 | } | 726 | } |
693 | 727 | ||
694 | 728 | ||
695 | void Addressee::setPrefix( const QString &prefix ) | 729 | void Addressee::setPrefix( const QString &prefix ) |
696 | { | 730 | { |
697 | if ( prefix == mData->prefix ) return; | 731 | if ( prefix == mData->prefix ) return; |
698 | detach(); | 732 | detach(); |
699 | mData->empty = false; | 733 | mData->empty = false; |
700 | mData->prefix = prefix; | 734 | mData->prefix = prefix; |
701 | } | 735 | } |
702 | 736 | ||
703 | QString Addressee::prefix() const | 737 | QString Addressee::prefix() const |
704 | { | 738 | { |
705 | return mData->prefix; | 739 | return mData->prefix; |
706 | } | 740 | } |
707 | 741 | ||
708 | QString Addressee::prefixLabel() | 742 | QString Addressee::prefixLabel() |
709 | { | 743 | { |
710 | return i18n("Honorific Prefixes"); | 744 | return i18n("Honorific Prefixes"); |
711 | } | 745 | } |
712 | 746 | ||
713 | 747 | ||
714 | void Addressee::setSuffix( const QString &suffix ) | 748 | void Addressee::setSuffix( const QString &suffix ) |
715 | { | 749 | { |
716 | if ( suffix == mData->suffix ) return; | 750 | if ( suffix == mData->suffix ) return; |
717 | detach(); | 751 | detach(); |
718 | mData->empty = false; | 752 | mData->empty = false; |
719 | mData->suffix = suffix; | 753 | mData->suffix = suffix; |
720 | } | 754 | } |
721 | 755 | ||
722 | QString Addressee::suffix() const | 756 | QString Addressee::suffix() const |
723 | { | 757 | { |
724 | return mData->suffix; | 758 | return mData->suffix; |
725 | } | 759 | } |
726 | 760 | ||
727 | QString Addressee::suffixLabel() | 761 | QString Addressee::suffixLabel() |
728 | { | 762 | { |
729 | return i18n("Honorific Suffixes"); | 763 | return i18n("Honorific Suffixes"); |
730 | } | 764 | } |
731 | 765 | ||
732 | 766 | ||
733 | void Addressee::setNickName( const QString &nickName ) | 767 | void Addressee::setNickName( const QString &nickName ) |
734 | { | 768 | { |
735 | if ( nickName == mData->nickName ) return; | 769 | if ( nickName == mData->nickName ) return; |
736 | detach(); | 770 | detach(); |
737 | mData->empty = false; | 771 | mData->empty = false; |
738 | mData->nickName = nickName; | 772 | mData->nickName = nickName; |
739 | } | 773 | } |
740 | 774 | ||
741 | QString Addressee::nickName() const | 775 | QString Addressee::nickName() const |
742 | { | 776 | { |
743 | return mData->nickName; | 777 | return mData->nickName; |
744 | } | 778 | } |
745 | 779 | ||
746 | QString Addressee::nickNameLabel() | 780 | QString Addressee::nickNameLabel() |
747 | { | 781 | { |
748 | return i18n("Nick Name"); | 782 | return i18n("Nick Name"); |
749 | } | 783 | } |
750 | 784 | ||
751 | 785 | ||
752 | void Addressee::setBirthday( const QDateTime &birthday ) | 786 | void Addressee::setBirthday( const QDateTime &birthday ) |
753 | { | 787 | { |
754 | if ( birthday == mData->birthday ) return; | 788 | if ( birthday == mData->birthday ) return; |
755 | detach(); | 789 | detach(); |
756 | mData->empty = false; | 790 | mData->empty = false; |
757 | mData->birthday = birthday; | 791 | mData->birthday = birthday; |
758 | } | 792 | } |
759 | 793 | ||
760 | QDateTime Addressee::birthday() const | 794 | QDateTime Addressee::birthday() const |
761 | { | 795 | { |
762 | return mData->birthday; | 796 | return mData->birthday; |
763 | } | 797 | } |
764 | 798 | ||
765 | QString Addressee::birthdayLabel() | 799 | QString Addressee::birthdayLabel() |
766 | { | 800 | { |
767 | return i18n("Birthday"); | 801 | return i18n("Birthday"); |
768 | } | 802 | } |
769 | 803 | ||
770 | 804 | ||
771 | QString Addressee::homeAddressStreetLabel() | 805 | QString Addressee::homeAddressStreetLabel() |
772 | { | 806 | { |
773 | return i18n("Home Address Street"); | 807 | return i18n("Home Address Street"); |
774 | } | 808 | } |
775 | 809 | ||
776 | 810 | ||
777 | QString Addressee::homeAddressLocalityLabel() | 811 | QString Addressee::homeAddressLocalityLabel() |
778 | { | 812 | { |
779 | return i18n("Home Address Locality"); | 813 | return i18n("Home Address Locality"); |
780 | } | 814 | } |
781 | 815 | ||
782 | 816 | ||
783 | QString Addressee::homeAddressRegionLabel() | 817 | QString Addressee::homeAddressRegionLabel() |
784 | { | 818 | { |
785 | return i18n("Home Address Region"); | 819 | return i18n("Home Address Region"); |
786 | } | 820 | } |
787 | 821 | ||
788 | 822 | ||
789 | QString Addressee::homeAddressPostalCodeLabel() | 823 | QString Addressee::homeAddressPostalCodeLabel() |
790 | { | 824 | { |
791 | return i18n("Home Address Postal Code"); | 825 | return i18n("Home Address Postal Code"); |
792 | } | 826 | } |
793 | 827 | ||
794 | 828 | ||
795 | QString Addressee::homeAddressCountryLabel() | 829 | QString Addressee::homeAddressCountryLabel() |
796 | { | 830 | { |
797 | return i18n("Home Address Country"); | 831 | return i18n("Home Address Country"); |
798 | } | 832 | } |
799 | 833 | ||
800 | 834 | ||
801 | QString Addressee::homeAddressLabelLabel() | 835 | QString Addressee::homeAddressLabelLabel() |
802 | { | 836 | { |
803 | return i18n("Home Address Label"); | 837 | return i18n("Home Address Label"); |
804 | } | 838 | } |
805 | 839 | ||
806 | 840 | ||
807 | QString Addressee::businessAddressStreetLabel() | 841 | QString Addressee::businessAddressStreetLabel() |
808 | { | 842 | { |
809 | return i18n("Business Address Street"); | 843 | return i18n("Business Address Street"); |
810 | } | 844 | } |
811 | 845 | ||
812 | 846 | ||
813 | QString Addressee::businessAddressLocalityLabel() | 847 | QString Addressee::businessAddressLocalityLabel() |
814 | { | 848 | { |
815 | return i18n("Business Address Locality"); | 849 | return i18n("Business Address Locality"); |
816 | } | 850 | } |
817 | 851 | ||
818 | 852 | ||
819 | QString Addressee::businessAddressRegionLabel() | 853 | QString Addressee::businessAddressRegionLabel() |
820 | { | 854 | { |
821 | return i18n("Business Address Region"); | 855 | return i18n("Business Address Region"); |
822 | } | 856 | } |
823 | 857 | ||
824 | 858 | ||
825 | QString Addressee::businessAddressPostalCodeLabel() | 859 | QString Addressee::businessAddressPostalCodeLabel() |
826 | { | 860 | { |
827 | return i18n("Business Address Postal Code"); | 861 | return i18n("Business Address Postal Code"); |
828 | } | 862 | } |
829 | 863 | ||
830 | 864 | ||
831 | QString Addressee::businessAddressCountryLabel() | 865 | QString Addressee::businessAddressCountryLabel() |
832 | { | 866 | { |
833 | return i18n("Business Address Country"); | 867 | return i18n("Business Address Country"); |
834 | } | 868 | } |
835 | 869 | ||
836 | 870 | ||
837 | QString Addressee::businessAddressLabelLabel() | 871 | QString Addressee::businessAddressLabelLabel() |
838 | { | 872 | { |
839 | return i18n("Business Address Label"); | 873 | return i18n("Business Address Label"); |
840 | } | 874 | } |
841 | 875 | ||
842 | 876 | ||
843 | QString Addressee::homePhoneLabel() | 877 | QString Addressee::homePhoneLabel() |
844 | { | 878 | { |
845 | return i18n("Home Phone"); | 879 | return i18n("Home Phone"); |
846 | } | 880 | } |
847 | 881 | ||
848 | 882 | ||
849 | QString Addressee::businessPhoneLabel() | 883 | QString Addressee::businessPhoneLabel() |
850 | { | 884 | { |
851 | return i18n("Business Phone"); | 885 | return i18n("Business Phone"); |
852 | } | 886 | } |
853 | 887 | ||
854 | 888 | ||
855 | QString Addressee::mobilePhoneLabel() | 889 | QString Addressee::mobilePhoneLabel() |
856 | { | 890 | { |
857 | return i18n("Mobile Phone"); | 891 | return i18n("Mobile Phone"); |
858 | } | 892 | } |
859 | 893 | ||
860 | 894 | ||
861 | QString Addressee::homeFaxLabel() | 895 | QString Addressee::homeFaxLabel() |
862 | { | 896 | { |
863 | return i18n("Home Fax"); | 897 | return i18n("Home Fax"); |
864 | } | 898 | } |
865 | 899 | ||
866 | 900 | ||
diff --git a/kabc/addressee.h b/kabc/addressee.h index e7900c6..2c81c1a 100644 --- a/kabc/addressee.h +++ b/kabc/addressee.h | |||
@@ -1,503 +1,503 @@ | |||
1 | /*** Warning! This file has been generated by the script makeaddressee ***/ | 1 | /*** Warning! This file has been generated by the script makeaddressee ***/ |
2 | /* | 2 | /* |
3 | This file is part of libkabc. | 3 | This file is part of libkabc. |
4 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. |
10 | 10 | ||
11 | This library is distributed in the hope that it will be useful, | 11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. | 14 | Library General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU Library General Public License | 16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to | 17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. | 19 | Boston, MA 02111-1307, USA. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | /* | 22 | /* |
23 | Enhanced Version of the file for platform independent KDE tools. | 23 | Enhanced Version of the file for platform independent KDE tools. |
24 | Copyright (c) 2004 Ulf Schenk | 24 | Copyright (c) 2004 Ulf Schenk |
25 | 25 | ||
26 | $Id$ | 26 | $Id$ |
27 | */ | 27 | */ |
28 | 28 | ||
29 | #ifndef KABC_ADDRESSEE_H | 29 | #ifndef KABC_ADDRESSEE_H |
30 | #define KABC_ADDRESSEE_H | 30 | #define KABC_ADDRESSEE_H |
31 | 31 | ||
32 | #include <qdatetime.h> | 32 | #include <qdatetime.h> |
33 | #include <qstring.h> | 33 | #include <qstring.h> |
34 | #include <qstringlist.h> | 34 | #include <qstringlist.h> |
35 | #include <qvaluelist.h> | 35 | #include <qvaluelist.h> |
36 | 36 | ||
37 | #include <ksharedptr.h> | 37 | #include <ksharedptr.h> |
38 | #include <kurl.h> | 38 | #include <kurl.h> |
39 | 39 | ||
40 | #include "address.h" | 40 | #include "address.h" |
41 | #include "agent.h" | 41 | #include "agent.h" |
42 | #include "geo.h" | 42 | #include "geo.h" |
43 | #include "key.h" | 43 | #include "key.h" |
44 | #include "phonenumber.h" | 44 | #include "phonenumber.h" |
45 | #include "picture.h" | 45 | #include "picture.h" |
46 | #include "secrecy.h" | 46 | #include "secrecy.h" |
47 | #include "sound.h" | 47 | #include "sound.h" |
48 | #include "timezone.h" | 48 | #include "timezone.h" |
49 | 49 | ||
50 | namespace KABC { | 50 | namespace KABC { |
51 | 51 | ||
52 | class Resource; | 52 | class Resource; |
53 | 53 | ||
54 | /** | 54 | /** |
55 | @short address book entry | 55 | @short address book entry |
56 | 56 | ||
57 | This class represents an entry in the address book. | 57 | This class represents an entry in the address book. |
58 | 58 | ||
59 | The data of this class is implicitly shared. You can pass this class by value. | 59 | The data of this class is implicitly shared. You can pass this class by value. |
60 | 60 | ||
61 | If you need the name of a field for presenting it to the user you should use | 61 | If you need the name of a field for presenting it to the user you should use |
62 | the functions ending in Label(). They return a translated string which can be | 62 | the functions ending in Label(). They return a translated string which can be |
63 | used as label for the corresponding field. | 63 | used as label for the corresponding field. |
64 | 64 | ||
65 | About the name fields: | 65 | About the name fields: |
66 | 66 | ||
67 | givenName() is the first name and familyName() the last name. In some | 67 | givenName() is the first name and familyName() the last name. In some |
68 | countries the family name comes first, that's the reason for the | 68 | countries the family name comes first, that's the reason for the |
69 | naming. formattedName() is the full name with the correct formatting. | 69 | naming. formattedName() is the full name with the correct formatting. |
70 | It is used as an override, when the correct formatting can't be generated | 70 | It is used as an override, when the correct formatting can't be generated |
71 | from the other name fields automatically. | 71 | from the other name fields automatically. |
72 | 72 | ||
73 | realName() returns a fully formatted name(). It uses formattedName, if set, | 73 | realName() returns a fully formatted name(). It uses formattedName, if set, |
74 | otherwise it constucts the name from the name fields. As fallback, if | 74 | otherwise it constucts the name from the name fields. As fallback, if |
75 | nothing else is set it uses name(). | 75 | nothing else is set it uses name(). |
76 | 76 | ||
77 | name() is the NAME type of RFC2426. It can be used as internal name for the | 77 | name() is the NAME type of RFC2426. It can be used as internal name for the |
78 | data enty, but shouldn't be used for displaying the data to the user. | 78 | data enty, but shouldn't be used for displaying the data to the user. |
79 | */ | 79 | */ |
80 | class Addressee | 80 | class Addressee |
81 | { | 81 | { |
82 | friend QDataStream &operator<<( QDataStream &, const Addressee & ); | 82 | friend QDataStream &operator<<( QDataStream &, const Addressee & ); |
83 | friend QDataStream &operator>>( QDataStream &, Addressee & ); | 83 | friend QDataStream &operator>>( QDataStream &, Addressee & ); |
84 | 84 | ||
85 | public: | 85 | public: |
86 | typedef QValueList<Addressee> List; | 86 | typedef QValueList<Addressee> List; |
87 | 87 | ||
88 | /** | 88 | /** |
89 | Construct an empty address book entry. | 89 | Construct an empty address book entry. |
90 | */ | 90 | */ |
91 | Addressee(); | 91 | Addressee(); |
92 | ~Addressee(); | 92 | ~Addressee(); |
93 | 93 | ||
94 | Addressee( const Addressee & ); | 94 | Addressee( const Addressee & ); |
95 | Addressee &operator=( const Addressee & ); | 95 | Addressee &operator=( const Addressee & ); |
96 | 96 | ||
97 | bool operator==( const Addressee & ) const; | 97 | bool operator==( const Addressee & ) const; |
98 | bool operator!=( const Addressee & ) const; | 98 | bool operator!=( const Addressee & ) const; |
99 | // sync stuff | 99 | // sync stuff |
100 | void setTempSyncStat(int id); | 100 | void setTempSyncStat(int id); |
101 | int tempSyncStat() const; | 101 | int tempSyncStat() const; |
102 | void setIDStr( const QString & ); | 102 | void setIDStr( const QString & ); |
103 | QString IDStr() const; | 103 | QString IDStr() const; |
104 | void setID( const QString &, const QString & ); | 104 | void setID( const QString &, const QString & ); |
105 | QString getID( const QString & ); | 105 | QString getID( const QString & ); |
106 | void setCsum( const QString &, const QString & ); | 106 | void setCsum( const QString &, const QString & ); |
107 | QString getCsum( const QString & ); | 107 | QString getCsum( const QString & ); |
108 | void removeID(const QString &); | 108 | void removeID(const QString &); |
109 | void computeCsum(const QString &dev); | 109 | void computeCsum(const QString &dev); |
110 | ulong getCsum4List( const QStringList & attList); | 110 | ulong getCsum4List( const QStringList & attList); |
111 | /** | 111 | /** |
112 | Return, if the address book entry is empty. | 112 | Return, if the address book entry is empty. |
113 | */ | 113 | */ |
114 | bool isEmpty() const; | 114 | bool isEmpty() const; |
115 | void setExternalUID( const QString &id ); | 115 | void setExternalUID( const QString &id ); |
116 | QString externalUID() const; | 116 | QString externalUID() const; |
117 | void setOriginalExternalUID( const QString &id ); | 117 | void setOriginalExternalUID( const QString &id ); |
118 | QString originalExternalUID() const; | 118 | QString originalExternalUID() const; |
119 | void mergeContact( const Addressee& ad, bool isSubSet = false ); | 119 | void mergeContact( const Addressee& ad, bool isSubSet ); |
120 | void simplifyEmails(); | 120 | void simplifyEmails(); |
121 | void simplifyAddresses(); | 121 | void simplifyAddresses(); |
122 | void simplifyPhoneNumbers(); | 122 | void simplifyPhoneNumbers(); |
123 | void simplifyPhoneNumberTypes(); | 123 | void simplifyPhoneNumberTypes(); |
124 | bool removeVoice(); | 124 | bool removeVoice(); |
125 | bool containsAdr(const Addressee& addr ); | 125 | bool containsAdr(const Addressee& addr ); |
126 | 126 | ||
127 | /** | 127 | /** |
128 | Set unique identifier. | 128 | Set unique identifier. |
129 | */ | 129 | */ |
130 | void setUid( const QString &uid ); | 130 | void setUid( const QString &uid ); |
131 | /** | 131 | /** |
132 | Return unique identifier. | 132 | Return unique identifier. |
133 | */ | 133 | */ |
134 | QString uid() const; | 134 | QString uid() const; |
135 | /** | 135 | /** |
136 | Return translated label for uid field. | 136 | Return translated label for uid field. |
137 | */ | 137 | */ |
138 | static QString uidLabel(); | 138 | static QString uidLabel(); |
139 | 139 | ||
140 | /** | 140 | /** |
141 | Set name. | 141 | Set name. |
142 | */ | 142 | */ |
143 | void setName( const QString &name ); | 143 | void setName( const QString &name ); |
144 | /** | 144 | /** |
145 | Return name. | 145 | Return name. |
146 | */ | 146 | */ |
147 | QString name() const; | 147 | QString name() const; |
148 | /** | 148 | /** |
149 | Return translated label for name field. | 149 | Return translated label for name field. |
150 | */ | 150 | */ |
151 | static QString nameLabel(); | 151 | static QString nameLabel(); |
152 | 152 | ||
153 | /** | 153 | /** |
154 | Set formatted name. | 154 | Set formatted name. |
155 | */ | 155 | */ |
156 | void setFormattedName( const QString &formattedName ); | 156 | void setFormattedName( const QString &formattedName ); |
157 | /** | 157 | /** |
158 | Return formatted name. | 158 | Return formatted name. |
159 | */ | 159 | */ |
160 | QString formattedName() const; | 160 | QString formattedName() const; |
161 | /** | 161 | /** |
162 | Return translated label for formattedName field. | 162 | Return translated label for formattedName field. |
163 | */ | 163 | */ |
164 | static QString formattedNameLabel(); | 164 | static QString formattedNameLabel(); |
165 | 165 | ||
166 | /** | 166 | /** |
167 | Set family name. | 167 | Set family name. |
168 | */ | 168 | */ |
169 | void setFamilyName( const QString &familyName ); | 169 | void setFamilyName( const QString &familyName ); |
170 | /** | 170 | /** |
171 | Return family name. | 171 | Return family name. |
172 | */ | 172 | */ |
173 | QString familyName() const; | 173 | QString familyName() const; |
174 | /** | 174 | /** |
175 | Return translated label for familyName field. | 175 | Return translated label for familyName field. |
176 | */ | 176 | */ |
177 | static QString familyNameLabel(); | 177 | static QString familyNameLabel(); |
178 | 178 | ||
179 | /** | 179 | /** |
180 | Set given name. | 180 | Set given name. |
181 | */ | 181 | */ |
182 | void setGivenName( const QString &givenName ); | 182 | void setGivenName( const QString &givenName ); |
183 | /** | 183 | /** |
184 | Return given name. | 184 | Return given name. |
185 | */ | 185 | */ |
186 | QString givenName() const; | 186 | QString givenName() const; |
187 | /** | 187 | /** |
188 | Return translated label for givenName field. | 188 | Return translated label for givenName field. |
189 | */ | 189 | */ |
190 | static QString givenNameLabel(); | 190 | static QString givenNameLabel(); |
191 | 191 | ||
192 | /** | 192 | /** |
193 | Set additional names. | 193 | Set additional names. |
194 | */ | 194 | */ |
195 | void setAdditionalName( const QString &additionalName ); | 195 | void setAdditionalName( const QString &additionalName ); |
196 | /** | 196 | /** |
197 | Return additional names. | 197 | Return additional names. |
198 | */ | 198 | */ |
199 | QString additionalName() const; | 199 | QString additionalName() const; |
200 | /** | 200 | /** |
201 | Return translated label for additionalName field. | 201 | Return translated label for additionalName field. |
202 | */ | 202 | */ |
203 | static QString additionalNameLabel(); | 203 | static QString additionalNameLabel(); |
204 | 204 | ||
205 | /** | 205 | /** |
206 | Set honorific prefixes. | 206 | Set honorific prefixes. |
207 | */ | 207 | */ |
208 | void setPrefix( const QString &prefix ); | 208 | void setPrefix( const QString &prefix ); |
209 | /** | 209 | /** |
210 | Return honorific prefixes. | 210 | Return honorific prefixes. |
211 | */ | 211 | */ |
212 | QString prefix() const; | 212 | QString prefix() const; |
213 | /** | 213 | /** |
214 | Return translated label for prefix field. | 214 | Return translated label for prefix field. |
215 | */ | 215 | */ |
216 | static QString prefixLabel(); | 216 | static QString prefixLabel(); |
217 | 217 | ||
218 | /** | 218 | /** |
219 | Set honorific suffixes. | 219 | Set honorific suffixes. |
220 | */ | 220 | */ |
221 | void setSuffix( const QString &suffix ); | 221 | void setSuffix( const QString &suffix ); |
222 | /** | 222 | /** |
223 | Return honorific suffixes. | 223 | Return honorific suffixes. |
224 | */ | 224 | */ |
225 | QString suffix() const; | 225 | QString suffix() const; |
226 | /** | 226 | /** |
227 | Return translated label for suffix field. | 227 | Return translated label for suffix field. |
228 | */ | 228 | */ |
229 | static QString suffixLabel(); | 229 | static QString suffixLabel(); |
230 | 230 | ||
231 | /** | 231 | /** |
232 | Set nick name. | 232 | Set nick name. |
233 | */ | 233 | */ |
234 | void setNickName( const QString &nickName ); | 234 | void setNickName( const QString &nickName ); |
235 | /** | 235 | /** |
236 | Return nick name. | 236 | Return nick name. |
237 | */ | 237 | */ |
238 | QString nickName() const; | 238 | QString nickName() const; |
239 | /** | 239 | /** |
240 | Return translated label for nickName field. | 240 | Return translated label for nickName field. |
241 | */ | 241 | */ |
242 | static QString nickNameLabel(); | 242 | static QString nickNameLabel(); |
243 | 243 | ||
244 | /** | 244 | /** |
245 | Set birthday. | 245 | Set birthday. |
246 | */ | 246 | */ |
247 | void setBirthday( const QDateTime &birthday ); | 247 | void setBirthday( const QDateTime &birthday ); |
248 | /** | 248 | /** |
249 | Return birthday. | 249 | Return birthday. |
250 | */ | 250 | */ |
251 | QDateTime birthday() const; | 251 | QDateTime birthday() const; |
252 | /** | 252 | /** |
253 | Return translated label for birthday field. | 253 | Return translated label for birthday field. |
254 | */ | 254 | */ |
255 | static QString birthdayLabel(); | 255 | static QString birthdayLabel(); |
256 | 256 | ||
257 | /** | 257 | /** |
258 | Return translated label for homeAddressStreet field. | 258 | Return translated label for homeAddressStreet field. |
259 | */ | 259 | */ |
260 | static QString homeAddressStreetLabel(); | 260 | static QString homeAddressStreetLabel(); |
261 | 261 | ||
262 | /** | 262 | /** |
263 | Return translated label for homeAddressLocality field. | 263 | Return translated label for homeAddressLocality field. |
264 | */ | 264 | */ |
265 | static QString homeAddressLocalityLabel(); | 265 | static QString homeAddressLocalityLabel(); |
266 | 266 | ||
267 | /** | 267 | /** |
268 | Return translated label for homeAddressRegion field. | 268 | Return translated label for homeAddressRegion field. |
269 | */ | 269 | */ |
270 | static QString homeAddressRegionLabel(); | 270 | static QString homeAddressRegionLabel(); |
271 | 271 | ||
272 | /** | 272 | /** |
273 | Return translated label for homeAddressPostalCode field. | 273 | Return translated label for homeAddressPostalCode field. |
274 | */ | 274 | */ |
275 | static QString homeAddressPostalCodeLabel(); | 275 | static QString homeAddressPostalCodeLabel(); |
276 | 276 | ||
277 | /** | 277 | /** |
278 | Return translated label for homeAddressCountry field. | 278 | Return translated label for homeAddressCountry field. |
279 | */ | 279 | */ |
280 | static QString homeAddressCountryLabel(); | 280 | static QString homeAddressCountryLabel(); |
281 | 281 | ||
282 | /** | 282 | /** |
283 | Return translated label for homeAddressLabel field. | 283 | Return translated label for homeAddressLabel field. |
284 | */ | 284 | */ |
285 | static QString homeAddressLabelLabel(); | 285 | static QString homeAddressLabelLabel(); |
286 | 286 | ||
287 | /** | 287 | /** |
288 | Return translated label for businessAddressStreet field. | 288 | Return translated label for businessAddressStreet field. |
289 | */ | 289 | */ |
290 | static QString businessAddressStreetLabel(); | 290 | static QString businessAddressStreetLabel(); |
291 | 291 | ||
292 | /** | 292 | /** |
293 | Return translated label for businessAddressLocality field. | 293 | Return translated label for businessAddressLocality field. |
294 | */ | 294 | */ |
295 | static QString businessAddressLocalityLabel(); | 295 | static QString businessAddressLocalityLabel(); |
296 | 296 | ||
297 | /** | 297 | /** |
298 | Return translated label for businessAddressRegion field. | 298 | Return translated label for businessAddressRegion field. |
299 | */ | 299 | */ |
300 | static QString businessAddressRegionLabel(); | 300 | static QString businessAddressRegionLabel(); |
301 | 301 | ||
302 | /** | 302 | /** |
303 | Return translated label for businessAddressPostalCode field. | 303 | Return translated label for businessAddressPostalCode field. |
304 | */ | 304 | */ |
305 | static QString businessAddressPostalCodeLabel(); | 305 | static QString businessAddressPostalCodeLabel(); |
306 | 306 | ||
307 | /** | 307 | /** |
308 | Return translated label for businessAddressCountry field. | 308 | Return translated label for businessAddressCountry field. |
309 | */ | 309 | */ |
310 | static QString businessAddressCountryLabel(); | 310 | static QString businessAddressCountryLabel(); |
311 | 311 | ||
312 | /** | 312 | /** |
313 | Return translated label for businessAddressLabel field. | 313 | Return translated label for businessAddressLabel field. |
314 | */ | 314 | */ |
315 | static QString businessAddressLabelLabel(); | 315 | static QString businessAddressLabelLabel(); |
316 | 316 | ||
317 | /** | 317 | /** |
318 | Return translated label for homePhone field. | 318 | Return translated label for homePhone field. |
319 | */ | 319 | */ |
320 | static QString homePhoneLabel(); | 320 | static QString homePhoneLabel(); |
321 | 321 | ||
322 | /** | 322 | /** |
323 | Return translated label for businessPhone field. | 323 | Return translated label for businessPhone field. |
324 | */ | 324 | */ |
325 | static QString businessPhoneLabel(); | 325 | static QString businessPhoneLabel(); |
326 | 326 | ||
327 | /** | 327 | /** |
328 | Return translated label for mobilePhone field. | 328 | Return translated label for mobilePhone field. |
329 | */ | 329 | */ |
330 | static QString mobilePhoneLabel(); | 330 | static QString mobilePhoneLabel(); |
331 | 331 | ||
332 | /** | 332 | /** |
333 | Return translated label for homeFax field. | 333 | Return translated label for homeFax field. |
334 | */ | 334 | */ |
335 | static QString homeFaxLabel(); | 335 | static QString homeFaxLabel(); |
336 | 336 | ||
337 | /** | 337 | /** |
338 | Return translated label for businessFax field. | 338 | Return translated label for businessFax field. |
339 | */ | 339 | */ |
340 | static QString businessFaxLabel(); | 340 | static QString businessFaxLabel(); |
341 | 341 | ||
342 | /** | 342 | /** |
343 | Return translated label for carPhone field. | 343 | Return translated label for carPhone field. |
344 | */ | 344 | */ |
345 | static QString carPhoneLabel(); | 345 | static QString carPhoneLabel(); |
346 | 346 | ||
347 | /** | 347 | /** |
348 | Return translated label for isdn field. | 348 | Return translated label for isdn field. |
349 | */ | 349 | */ |
350 | static QString isdnLabel(); | 350 | static QString isdnLabel(); |
351 | 351 | ||
352 | /** | 352 | /** |
353 | Return translated label for pager field. | 353 | Return translated label for pager field. |
354 | */ | 354 | */ |
355 | static QString pagerLabel(); | 355 | static QString pagerLabel(); |
356 | 356 | ||
357 | /** | 357 | /** |
358 | Return translated label for sip field. | 358 | Return translated label for sip field. |
359 | */ | 359 | */ |
360 | static QString sipLabel(); | 360 | static QString sipLabel(); |
361 | 361 | ||
362 | /** | 362 | /** |
363 | Return translated label for email field. | 363 | Return translated label for email field. |
364 | */ | 364 | */ |
365 | static QString emailLabel(); | 365 | static QString emailLabel(); |
366 | 366 | ||
367 | /** | 367 | /** |
368 | Set mail client. | 368 | Set mail client. |
369 | */ | 369 | */ |
370 | void setMailer( const QString &mailer ); | 370 | void setMailer( const QString &mailer ); |
371 | /** | 371 | /** |
372 | Return mail client. | 372 | Return mail client. |
373 | */ | 373 | */ |
374 | QString mailer() const; | 374 | QString mailer() const; |
375 | /** | 375 | /** |
376 | Return translated label for mailer field. | 376 | Return translated label for mailer field. |
377 | */ | 377 | */ |
378 | static QString mailerLabel(); | 378 | static QString mailerLabel(); |
379 | 379 | ||
380 | /** | 380 | /** |
381 | Set time zone. | 381 | Set time zone. |
382 | */ | 382 | */ |
383 | void setTimeZone( const TimeZone &timeZone ); | 383 | void setTimeZone( const TimeZone &timeZone ); |
384 | /** | 384 | /** |
385 | Return time zone. | 385 | Return time zone. |
386 | */ | 386 | */ |
387 | TimeZone timeZone() const; | 387 | TimeZone timeZone() const; |
388 | /** | 388 | /** |
389 | Return translated label for timeZone field. | 389 | Return translated label for timeZone field. |
390 | */ | 390 | */ |
391 | static QString timeZoneLabel(); | 391 | static QString timeZoneLabel(); |
392 | 392 | ||
393 | /** | 393 | /** |
394 | Set geographic position. | 394 | Set geographic position. |
395 | */ | 395 | */ |
396 | void setGeo( const Geo &geo ); | 396 | void setGeo( const Geo &geo ); |
397 | /** | 397 | /** |
398 | Return geographic position. | 398 | Return geographic position. |
399 | */ | 399 | */ |
400 | Geo geo() const; | 400 | Geo geo() const; |
401 | /** | 401 | /** |
402 | Return translated label for geo field. | 402 | Return translated label for geo field. |
403 | */ | 403 | */ |
404 | static QString geoLabel(); | 404 | static QString geoLabel(); |
405 | 405 | ||
406 | /** | 406 | /** |
407 | Set title. | 407 | Set title. |
408 | */ | 408 | */ |
409 | void setTitle( const QString &title ); | 409 | void setTitle( const QString &title ); |
410 | /** | 410 | /** |
411 | Return title. | 411 | Return title. |
412 | */ | 412 | */ |
413 | QString title() const; | 413 | QString title() const; |
414 | /** | 414 | /** |
415 | Return translated label for title field. | 415 | Return translated label for title field. |
416 | */ | 416 | */ |
417 | static QString titleLabel(); | 417 | static QString titleLabel(); |
418 | 418 | ||
419 | /** | 419 | /** |
420 | Set role. | 420 | Set role. |
421 | */ | 421 | */ |
422 | void setRole( const QString &role ); | 422 | void setRole( const QString &role ); |
423 | /** | 423 | /** |
424 | Return role. | 424 | Return role. |
425 | */ | 425 | */ |
426 | QString role() const; | 426 | QString role() const; |
427 | /** | 427 | /** |
428 | Return translated label for role field. | 428 | Return translated label for role field. |
429 | */ | 429 | */ |
430 | static QString roleLabel(); | 430 | static QString roleLabel(); |
431 | 431 | ||
432 | /** | 432 | /** |
433 | Set organization. | 433 | Set organization. |
434 | */ | 434 | */ |
435 | void setOrganization( const QString &organization ); | 435 | void setOrganization( const QString &organization ); |
436 | /** | 436 | /** |
437 | Return organization. | 437 | Return organization. |
438 | */ | 438 | */ |
439 | QString organization() const; | 439 | QString organization() const; |
440 | /** | 440 | /** |
441 | Return translated label for organization field. | 441 | Return translated label for organization field. |
442 | */ | 442 | */ |
443 | static QString organizationLabel(); | 443 | static QString organizationLabel(); |
444 | 444 | ||
445 | /** | 445 | /** |
446 | Set note. | 446 | Set note. |
447 | */ | 447 | */ |
448 | void setNote( const QString ¬e ); | 448 | void setNote( const QString ¬e ); |
449 | /** | 449 | /** |
450 | Return note. | 450 | Return note. |
451 | */ | 451 | */ |
452 | QString note() const; | 452 | QString note() const; |
453 | /** | 453 | /** |
454 | Return translated label for note field. | 454 | Return translated label for note field. |
455 | */ | 455 | */ |
456 | static QString noteLabel(); | 456 | static QString noteLabel(); |
457 | 457 | ||
458 | /** | 458 | /** |
459 | Set product identifier. | 459 | Set product identifier. |
460 | */ | 460 | */ |
461 | void setProductId( const QString &productId ); | 461 | void setProductId( const QString &productId ); |
462 | /** | 462 | /** |
463 | Return product identifier. | 463 | Return product identifier. |
464 | */ | 464 | */ |
465 | QString productId() const; | 465 | QString productId() const; |
466 | /** | 466 | /** |
467 | Return translated label for productId field. | 467 | Return translated label for productId field. |
468 | */ | 468 | */ |
469 | static QString productIdLabel(); | 469 | static QString productIdLabel(); |
470 | 470 | ||
471 | /** | 471 | /** |
472 | Set revision date. | 472 | Set revision date. |
473 | */ | 473 | */ |
474 | void setRevision( const QDateTime &revision ); | 474 | void setRevision( const QDateTime &revision ); |
475 | /** | 475 | /** |
476 | Return revision date. | 476 | Return revision date. |
477 | */ | 477 | */ |
478 | QDateTime revision() const; | 478 | QDateTime revision() const; |
479 | /** | 479 | /** |
480 | Return translated label for revision field. | 480 | Return translated label for revision field. |
481 | */ | 481 | */ |
482 | static QString revisionLabel(); | 482 | static QString revisionLabel(); |
483 | 483 | ||
484 | /** | 484 | /** |
485 | Set sort string. | 485 | Set sort string. |
486 | */ | 486 | */ |
487 | void setSortString( const QString &sortString ); | 487 | void setSortString( const QString &sortString ); |
488 | /** | 488 | /** |
489 | Return sort string. | 489 | Return sort string. |
490 | */ | 490 | */ |
491 | QString sortString() const; | 491 | QString sortString() const; |
492 | /** | 492 | /** |
493 | Return translated label for sortString field. | 493 | Return translated label for sortString field. |
494 | */ | 494 | */ |
495 | static QString sortStringLabel(); | 495 | static QString sortStringLabel(); |
496 | 496 | ||
497 | /** | 497 | /** |
498 | Set URL. | 498 | Set URL. |
499 | */ | 499 | */ |
500 | void setUrl( const KURL &url ); | 500 | void setUrl( const KURL &url ); |
501 | /** | 501 | /** |
502 | Return URL. | 502 | Return URL. |
503 | */ | 503 | */ |
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index 205dbc8..ea34be2 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp | |||
@@ -2351,525 +2351,525 @@ int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, i | |||
2351 | //qDebug("both not changed "); | 2351 | //qDebug("both not changed "); |
2352 | lastSync = localMod.addDays(1); | 2352 | lastSync = localMod.addDays(1); |
2353 | if ( mode <= SYNC_PREF_ASK ) | 2353 | if ( mode <= SYNC_PREF_ASK ) |
2354 | return 0; | 2354 | return 0; |
2355 | } else { | 2355 | } else { |
2356 | if ( locCh ) { | 2356 | if ( locCh ) { |
2357 | //qDebug("loc changed %s %s", localMod.toString().latin1(), mLastAddressbookSync.toString().latin1()); | 2357 | //qDebug("loc changed %s %s", localMod.toString().latin1(), mLastAddressbookSync.toString().latin1()); |
2358 | lastSync = localMod.addDays( -1 ); | 2358 | lastSync = localMod.addDays( -1 ); |
2359 | if ( !remCh ) | 2359 | if ( !remCh ) |
2360 | remoteMod =( lastSync.addDays( -1 ) ); | 2360 | remoteMod =( lastSync.addDays( -1 ) ); |
2361 | } else { | 2361 | } else { |
2362 | //qDebug(" not loc changed "); | 2362 | //qDebug(" not loc changed "); |
2363 | lastSync = localMod.addDays( 1 ); | 2363 | lastSync = localMod.addDays( 1 ); |
2364 | if ( remCh ) | 2364 | if ( remCh ) |
2365 | remoteMod =( lastSync.addDays( 1 ) ); | 2365 | remoteMod =( lastSync.addDays( 1 ) ); |
2366 | 2366 | ||
2367 | } | 2367 | } |
2368 | } | 2368 | } |
2369 | full = true; | 2369 | full = true; |
2370 | if ( mode < SYNC_PREF_ASK ) | 2370 | if ( mode < SYNC_PREF_ASK ) |
2371 | mode = SYNC_PREF_ASK; | 2371 | mode = SYNC_PREF_ASK; |
2372 | } else { | 2372 | } else { |
2373 | if ( localMod == remoteMod ) | 2373 | if ( localMod == remoteMod ) |
2374 | return 0; | 2374 | return 0; |
2375 | 2375 | ||
2376 | } | 2376 | } |
2377 | // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); | 2377 | // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); |
2378 | 2378 | ||
2379 | //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); | 2379 | //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); |
2380 | //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); | 2380 | //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); |
2381 | //full = true; //debug only | 2381 | //full = true; //debug only |
2382 | if ( full ) { | 2382 | if ( full ) { |
2383 | bool equ = ( (*local) == (*remote) ); | 2383 | bool equ = ( (*local) == (*remote) ); |
2384 | if ( equ ) { | 2384 | if ( equ ) { |
2385 | //qDebug("equal "); | 2385 | //qDebug("equal "); |
2386 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2386 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2387 | local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); | 2387 | local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); |
2388 | } | 2388 | } |
2389 | if ( mode < SYNC_PREF_FORCE_LOCAL ) | 2389 | if ( mode < SYNC_PREF_FORCE_LOCAL ) |
2390 | return 0; | 2390 | return 0; |
2391 | 2391 | ||
2392 | }//else //debug only | 2392 | }//else //debug only |
2393 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); | 2393 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); |
2394 | } | 2394 | } |
2395 | int result; | 2395 | int result; |
2396 | bool localIsNew; | 2396 | bool localIsNew; |
2397 | //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); | 2397 | //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); |
2398 | 2398 | ||
2399 | if ( full && mode < SYNC_PREF_NEWEST ) | 2399 | if ( full && mode < SYNC_PREF_NEWEST ) |
2400 | mode = SYNC_PREF_ASK; | 2400 | mode = SYNC_PREF_ASK; |
2401 | 2401 | ||
2402 | switch( mode ) { | 2402 | switch( mode ) { |
2403 | case SYNC_PREF_LOCAL: | 2403 | case SYNC_PREF_LOCAL: |
2404 | if ( lastSync > remoteMod ) | 2404 | if ( lastSync > remoteMod ) |
2405 | return 1; | 2405 | return 1; |
2406 | if ( lastSync > localMod ) | 2406 | if ( lastSync > localMod ) |
2407 | return 2; | 2407 | return 2; |
2408 | return 1; | 2408 | return 1; |
2409 | break; | 2409 | break; |
2410 | case SYNC_PREF_REMOTE: | 2410 | case SYNC_PREF_REMOTE: |
2411 | if ( lastSync > remoteMod ) | 2411 | if ( lastSync > remoteMod ) |
2412 | return 1; | 2412 | return 1; |
2413 | if ( lastSync > localMod ) | 2413 | if ( lastSync > localMod ) |
2414 | return 2; | 2414 | return 2; |
2415 | return 2; | 2415 | return 2; |
2416 | break; | 2416 | break; |
2417 | case SYNC_PREF_NEWEST: | 2417 | case SYNC_PREF_NEWEST: |
2418 | if ( localMod > remoteMod ) | 2418 | if ( localMod > remoteMod ) |
2419 | return 1; | 2419 | return 1; |
2420 | else | 2420 | else |
2421 | return 2; | 2421 | return 2; |
2422 | break; | 2422 | break; |
2423 | case SYNC_PREF_ASK: | 2423 | case SYNC_PREF_ASK: |
2424 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); | 2424 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); |
2425 | if ( lastSync > remoteMod ) | 2425 | if ( lastSync > remoteMod ) |
2426 | return 1; | 2426 | return 1; |
2427 | if ( lastSync > localMod ) | 2427 | if ( lastSync > localMod ) |
2428 | return 2; | 2428 | return 2; |
2429 | localIsNew = localMod >= remoteMod; | 2429 | localIsNew = localMod >= remoteMod; |
2430 | //qDebug("conflict! ************************************** "); | 2430 | //qDebug("conflict! ************************************** "); |
2431 | { | 2431 | { |
2432 | KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this ); | 2432 | KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this ); |
2433 | result = acd.executeD(localIsNew); | 2433 | result = acd.executeD(localIsNew); |
2434 | return result; | 2434 | return result; |
2435 | } | 2435 | } |
2436 | break; | 2436 | break; |
2437 | case SYNC_PREF_FORCE_LOCAL: | 2437 | case SYNC_PREF_FORCE_LOCAL: |
2438 | return 1; | 2438 | return 1; |
2439 | break; | 2439 | break; |
2440 | case SYNC_PREF_FORCE_REMOTE: | 2440 | case SYNC_PREF_FORCE_REMOTE: |
2441 | return 2; | 2441 | return 2; |
2442 | break; | 2442 | break; |
2443 | 2443 | ||
2444 | default: | 2444 | default: |
2445 | // SYNC_PREF_TAKE_BOTH not implemented | 2445 | // SYNC_PREF_TAKE_BOTH not implemented |
2446 | break; | 2446 | break; |
2447 | } | 2447 | } |
2448 | return 0; | 2448 | return 0; |
2449 | } | 2449 | } |
2450 | 2450 | ||
2451 | 2451 | ||
2452 | bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) | 2452 | bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) |
2453 | { | 2453 | { |
2454 | bool syncOK = true; | 2454 | bool syncOK = true; |
2455 | int addedAddressee = 0; | 2455 | int addedAddressee = 0; |
2456 | int addedAddresseeR = 0; | 2456 | int addedAddresseeR = 0; |
2457 | int deletedAddresseeR = 0; | 2457 | int deletedAddresseeR = 0; |
2458 | int deletedAddresseeL = 0; | 2458 | int deletedAddresseeL = 0; |
2459 | int changedLocal = 0; | 2459 | int changedLocal = 0; |
2460 | int changedRemote = 0; | 2460 | int changedRemote = 0; |
2461 | 2461 | ||
2462 | QString mCurrentSyncName = syncManager->getCurrentSyncName(); | 2462 | QString mCurrentSyncName = syncManager->getCurrentSyncName(); |
2463 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); | 2463 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); |
2464 | 2464 | ||
2465 | //QPtrList<Addressee> el = local->rawAddressees(); | 2465 | //QPtrList<Addressee> el = local->rawAddressees(); |
2466 | Addressee addresseeR; | 2466 | Addressee addresseeR; |
2467 | QString uid; | 2467 | QString uid; |
2468 | int take; | 2468 | int take; |
2469 | Addressee addresseeL; | 2469 | Addressee addresseeL; |
2470 | Addressee addresseeRSync; | 2470 | Addressee addresseeRSync; |
2471 | Addressee addresseeLSync; | 2471 | Addressee addresseeLSync; |
2472 | // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); | 2472 | // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); |
2473 | //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); | 2473 | //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); |
2474 | bool fullDateRange = false; | 2474 | bool fullDateRange = false; |
2475 | local->resetTempSyncStat(); | 2475 | local->resetTempSyncStat(); |
2476 | mLastAddressbookSync = QDateTime::currentDateTime(); | 2476 | mLastAddressbookSync = QDateTime::currentDateTime(); |
2477 | QDateTime modifiedCalendar = mLastAddressbookSync;; | 2477 | QDateTime modifiedCalendar = mLastAddressbookSync;; |
2478 | addresseeLSync = getLastSyncAddressee(); | 2478 | addresseeLSync = getLastSyncAddressee(); |
2479 | qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); | 2479 | qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); |
2480 | addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); | 2480 | addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); |
2481 | if ( !addresseeR.isEmpty() ) { | 2481 | if ( !addresseeR.isEmpty() ) { |
2482 | addresseeRSync = addresseeR; | 2482 | addresseeRSync = addresseeR; |
2483 | remote->removeAddressee(addresseeR ); | 2483 | remote->removeAddressee(addresseeR ); |
2484 | 2484 | ||
2485 | } else { | 2485 | } else { |
2486 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2486 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2487 | addresseeRSync = addresseeLSync ; | 2487 | addresseeRSync = addresseeLSync ; |
2488 | } else { | 2488 | } else { |
2489 | qDebug("FULLDATE 1"); | 2489 | qDebug("FULLDATE 1"); |
2490 | fullDateRange = true; | 2490 | fullDateRange = true; |
2491 | Addressee newAdd; | 2491 | Addressee newAdd; |
2492 | addresseeRSync = newAdd; | 2492 | addresseeRSync = newAdd; |
2493 | addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); | 2493 | addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); |
2494 | addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); | 2494 | addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); |
2495 | addresseeRSync.setRevision( mLastAddressbookSync ); | 2495 | addresseeRSync.setRevision( mLastAddressbookSync ); |
2496 | addresseeRSync.setCategories( i18n("SyncAddressee") ); | 2496 | addresseeRSync.setCategories( i18n("SyncAddressee") ); |
2497 | } | 2497 | } |
2498 | } | 2498 | } |
2499 | if ( addresseeLSync.revision() == mLastAddressbookSync ) { | 2499 | if ( addresseeLSync.revision() == mLastAddressbookSync ) { |
2500 | qDebug("FULLDATE 2"); | 2500 | qDebug("FULLDATE 2"); |
2501 | fullDateRange = true; | 2501 | fullDateRange = true; |
2502 | } | 2502 | } |
2503 | if ( ! fullDateRange ) { | 2503 | if ( ! fullDateRange ) { |
2504 | if ( addresseeLSync.revision() != addresseeRSync.revision() ) { | 2504 | if ( addresseeLSync.revision() != addresseeRSync.revision() ) { |
2505 | 2505 | ||
2506 | // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); | 2506 | // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); |
2507 | //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); | 2507 | //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); |
2508 | fullDateRange = true; | 2508 | fullDateRange = true; |
2509 | qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); | 2509 | qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); |
2510 | } | 2510 | } |
2511 | } | 2511 | } |
2512 | // fullDateRange = true; // debug only! | 2512 | // fullDateRange = true; // debug only! |
2513 | if ( fullDateRange ) | 2513 | if ( fullDateRange ) |
2514 | mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); | 2514 | mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); |
2515 | else | 2515 | else |
2516 | mLastAddressbookSync = addresseeLSync.revision(); | 2516 | mLastAddressbookSync = addresseeLSync.revision(); |
2517 | // for resyncing if own file has changed | 2517 | // for resyncing if own file has changed |
2518 | // PENDING fixme later when implemented | 2518 | // PENDING fixme later when implemented |
2519 | #if 0 | 2519 | #if 0 |
2520 | if ( mCurrentSyncDevice == "deleteaftersync" ) { | 2520 | if ( mCurrentSyncDevice == "deleteaftersync" ) { |
2521 | mLastAddressbookSync = loadedFileVersion; | 2521 | mLastAddressbookSync = loadedFileVersion; |
2522 | qDebug("setting mLastAddressbookSync "); | 2522 | qDebug("setting mLastAddressbookSync "); |
2523 | } | 2523 | } |
2524 | #endif | 2524 | #endif |
2525 | 2525 | ||
2526 | //qDebug("*************************** "); | 2526 | //qDebug("*************************** "); |
2527 | // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); | 2527 | // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); |
2528 | QStringList er = remote->uidList(); | 2528 | QStringList er = remote->uidList(); |
2529 | Addressee inR ;//= er.first(); | 2529 | Addressee inR ;//= er.first(); |
2530 | Addressee inL; | 2530 | Addressee inL; |
2531 | 2531 | ||
2532 | syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); | 2532 | syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); |
2533 | 2533 | ||
2534 | int modulo = (er.count()/10)+1; | 2534 | int modulo = (er.count()/10)+1; |
2535 | int incCounter = 0; | 2535 | int incCounter = 0; |
2536 | while ( incCounter < er.count()) { | 2536 | while ( incCounter < er.count()) { |
2537 | if (syncManager->isProgressBarCanceled()) | 2537 | if (syncManager->isProgressBarCanceled()) |
2538 | return false; | 2538 | return false; |
2539 | if ( incCounter % modulo == 0 ) | 2539 | if ( incCounter % modulo == 0 ) |
2540 | syncManager->showProgressBar(incCounter); | 2540 | syncManager->showProgressBar(incCounter); |
2541 | 2541 | ||
2542 | uid = er[ incCounter ]; | 2542 | uid = er[ incCounter ]; |
2543 | bool skipIncidence = false; | 2543 | bool skipIncidence = false; |
2544 | if ( uid.left(19) == QString("last-syncAddressee-") ) | 2544 | if ( uid.left(19) == QString("last-syncAddressee-") ) |
2545 | skipIncidence = true; | 2545 | skipIncidence = true; |
2546 | QString idS,OidS; | 2546 | QString idS,OidS; |
2547 | qApp->processEvents(); | 2547 | qApp->processEvents(); |
2548 | if ( !skipIncidence ) { | 2548 | if ( !skipIncidence ) { |
2549 | inL = local->findByUid( uid ); | 2549 | inL = local->findByUid( uid ); |
2550 | inR = remote->findByUid( uid ); | 2550 | inR = remote->findByUid( uid ); |
2551 | //inL.setResource( 0 ); | 2551 | //inL.setResource( 0 ); |
2552 | //inR.setResource( 0 ); | 2552 | //inR.setResource( 0 ); |
2553 | if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars | 2553 | if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars |
2554 | if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) { | 2554 | if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) { |
2555 | //qDebug("take %d %s ", take, inL.summary().latin1()); | 2555 | //qDebug("take %d %s ", take, inL.summary().latin1()); |
2556 | if ( take == 3 ) | 2556 | if ( take == 3 ) |
2557 | return false; | 2557 | return false; |
2558 | if ( take == 1 ) {// take local | 2558 | if ( take == 1 ) {// take local |
2559 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2559 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2560 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); | 2560 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); |
2561 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); | 2561 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); |
2562 | local->insertAddressee( inL, false ); | 2562 | local->insertAddressee( inL, false ); |
2563 | idS = inR.externalUID(); | 2563 | idS = inR.externalUID(); |
2564 | OidS = inR.originalExternalUID(); | 2564 | OidS = inR.originalExternalUID(); |
2565 | } | 2565 | } |
2566 | else | 2566 | else |
2567 | idS = inR.IDStr(); | 2567 | idS = inR.IDStr(); |
2568 | remote->removeAddressee( inR ); | 2568 | remote->removeAddressee( inR ); |
2569 | inR = inL; | 2569 | inR = inL; |
2570 | inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 2570 | inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
2571 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2571 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2572 | inR.setOriginalExternalUID( OidS ); | 2572 | inR.setOriginalExternalUID( OidS ); |
2573 | inR.setExternalUID( idS ); | 2573 | inR.setExternalUID( idS ); |
2574 | } else { | 2574 | } else { |
2575 | inR.setIDStr( idS ); | 2575 | inR.setIDStr( idS ); |
2576 | } | 2576 | } |
2577 | inR.setResource( 0 ); | 2577 | inR.setResource( 0 ); |
2578 | remote->insertAddressee( inR , false); | 2578 | remote->insertAddressee( inR , false); |
2579 | ++changedRemote; | 2579 | ++changedRemote; |
2580 | } else { // take == 2 take remote | 2580 | } else { // take == 2 take remote |
2581 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2581 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2582 | if ( inR.revision().date().year() < 2004 ) | 2582 | if ( inR.revision().date().year() < 2004 ) |
2583 | inR.setRevision( modifiedCalendar ); | 2583 | inR.setRevision( modifiedCalendar ); |
2584 | } | 2584 | } |
2585 | idS = inL.IDStr(); | 2585 | idS = inL.IDStr(); |
2586 | local->removeAddressee( inL ); | 2586 | local->removeAddressee( inL ); |
2587 | inL = inR; | 2587 | inL = inR; |
2588 | inL.setIDStr( idS ); | 2588 | inL.setIDStr( idS ); |
2589 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2589 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2590 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); | 2590 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); |
2591 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); | 2591 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); |
2592 | } | 2592 | } |
2593 | inL.setResource( 0 ); | 2593 | inL.setResource( 0 ); |
2594 | local->insertAddressee( inL , false ); | 2594 | local->insertAddressee( inL , false ); |
2595 | ++changedLocal; | 2595 | ++changedLocal; |
2596 | } | 2596 | } |
2597 | } | 2597 | } |
2598 | } else { // no conflict | 2598 | } else { // no conflict |
2599 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2599 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2600 | QString des = addresseeLSync.note(); | 2600 | QString des = addresseeLSync.note(); |
2601 | if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it | 2601 | if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it |
2602 | inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); | 2602 | inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); |
2603 | remote->insertAddressee( inR, false ); | 2603 | remote->insertAddressee( inR, false ); |
2604 | ++deletedAddresseeR; | 2604 | ++deletedAddresseeR; |
2605 | } else { | 2605 | } else { |
2606 | inR.setRevision( modifiedCalendar ); | 2606 | inR.setRevision( modifiedCalendar ); |
2607 | remote->insertAddressee( inR, false ); | 2607 | remote->insertAddressee( inR, false ); |
2608 | inL = inR; | 2608 | inL = inR; |
2609 | inL.setResource( 0 ); | 2609 | inL.setResource( 0 ); |
2610 | local->insertAddressee( inL , false); | 2610 | local->insertAddressee( inL , false); |
2611 | ++addedAddressee; | 2611 | ++addedAddressee; |
2612 | } | 2612 | } |
2613 | } else { | 2613 | } else { |
2614 | if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { | 2614 | if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { |
2615 | inR.setRevision( modifiedCalendar ); | 2615 | inR.setRevision( modifiedCalendar ); |
2616 | remote->insertAddressee( inR, false ); | 2616 | remote->insertAddressee( inR, false ); |
2617 | inR.setResource( 0 ); | 2617 | inR.setResource( 0 ); |
2618 | local->insertAddressee( inR, false ); | 2618 | local->insertAddressee( inR, false ); |
2619 | ++addedAddressee; | 2619 | ++addedAddressee; |
2620 | } else { | 2620 | } else { |
2621 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); | 2621 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); |
2622 | remote->removeAddressee( inR ); | 2622 | remote->removeAddressee( inR ); |
2623 | ++deletedAddresseeR; | 2623 | ++deletedAddresseeR; |
2624 | } | 2624 | } |
2625 | } | 2625 | } |
2626 | } | 2626 | } |
2627 | } | 2627 | } |
2628 | ++incCounter; | 2628 | ++incCounter; |
2629 | } | 2629 | } |
2630 | er.clear(); | 2630 | er.clear(); |
2631 | QStringList el = local->uidList(); | 2631 | QStringList el = local->uidList(); |
2632 | modulo = (el.count()/10)+1; | 2632 | modulo = (el.count()/10)+1; |
2633 | 2633 | ||
2634 | syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); | 2634 | syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); |
2635 | incCounter = 0; | 2635 | incCounter = 0; |
2636 | while ( incCounter < el.count()) { | 2636 | while ( incCounter < el.count()) { |
2637 | qApp->processEvents(); | 2637 | qApp->processEvents(); |
2638 | if (syncManager->isProgressBarCanceled()) | 2638 | if (syncManager->isProgressBarCanceled()) |
2639 | return false; | 2639 | return false; |
2640 | if ( incCounter % modulo == 0 ) | 2640 | if ( incCounter % modulo == 0 ) |
2641 | syncManager->showProgressBar(incCounter); | 2641 | syncManager->showProgressBar(incCounter); |
2642 | uid = el[ incCounter ]; | 2642 | uid = el[ incCounter ]; |
2643 | bool skipIncidence = false; | 2643 | bool skipIncidence = false; |
2644 | if ( uid.left(19) == QString("last-syncAddressee-") ) | 2644 | if ( uid.left(19) == QString("last-syncAddressee-") ) |
2645 | skipIncidence = true; | 2645 | skipIncidence = true; |
2646 | if ( !skipIncidence ) { | 2646 | if ( !skipIncidence ) { |
2647 | inL = local->findByUid( uid ); | 2647 | inL = local->findByUid( uid ); |
2648 | inR = remote->findByUid( uid ); | 2648 | inR = remote->findByUid( uid ); |
2649 | if ( inR.isEmpty() ) { | 2649 | if ( inR.isEmpty() ) { |
2650 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2650 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2651 | if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { | 2651 | if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { |
2652 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); | 2652 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); |
2653 | local->removeAddressee( inL ); | 2653 | local->removeAddressee( inL ); |
2654 | ++deletedAddresseeL; | 2654 | ++deletedAddresseeL; |
2655 | } else { | 2655 | } else { |
2656 | if ( ! syncManager->mWriteBackExistingOnly ) { | 2656 | if ( ! syncManager->mWriteBackExistingOnly ) { |
2657 | inL.removeID(mCurrentSyncDevice ); | 2657 | inL.removeID(mCurrentSyncDevice ); |
2658 | ++addedAddresseeR; | 2658 | ++addedAddresseeR; |
2659 | inL.setRevision( modifiedCalendar ); | 2659 | inL.setRevision( modifiedCalendar ); |
2660 | local->insertAddressee( inL, false ); | 2660 | local->insertAddressee( inL, false ); |
2661 | inR = inL; | 2661 | inR = inL; |
2662 | inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); | 2662 | inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); |
2663 | inR.setResource( 0 ); | 2663 | inR.setResource( 0 ); |
2664 | remote->insertAddressee( inR, false ); | 2664 | remote->insertAddressee( inR, false ); |
2665 | } | 2665 | } |
2666 | } | 2666 | } |
2667 | } else { | 2667 | } else { |
2668 | if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { | 2668 | if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { |
2669 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); | 2669 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); |
2670 | local->removeAddressee( inL ); | 2670 | local->removeAddressee( inL ); |
2671 | ++deletedAddresseeL; | 2671 | ++deletedAddresseeL; |
2672 | } else { | 2672 | } else { |
2673 | if ( ! syncManager->mWriteBackExistingOnly ) { | 2673 | if ( ! syncManager->mWriteBackExistingOnly ) { |
2674 | ++addedAddresseeR; | 2674 | ++addedAddresseeR; |
2675 | inL.setRevision( modifiedCalendar ); | 2675 | inL.setRevision( modifiedCalendar ); |
2676 | local->insertAddressee( inL, false ); | 2676 | local->insertAddressee( inL, false ); |
2677 | inR = inL; | 2677 | inR = inL; |
2678 | inR.setResource( 0 ); | 2678 | inR.setResource( 0 ); |
2679 | remote->insertAddressee( inR, false ); | 2679 | remote->insertAddressee( inR, false ); |
2680 | } | 2680 | } |
2681 | } | 2681 | } |
2682 | } | 2682 | } |
2683 | } | 2683 | } |
2684 | } | 2684 | } |
2685 | ++incCounter; | 2685 | ++incCounter; |
2686 | } | 2686 | } |
2687 | el.clear(); | 2687 | el.clear(); |
2688 | syncManager->hideProgressBar(); | 2688 | syncManager->hideProgressBar(); |
2689 | mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); | 2689 | mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); |
2690 | // get rid of micro seconds | 2690 | // get rid of micro seconds |
2691 | QTime t = mLastAddressbookSync.time(); | 2691 | QTime t = mLastAddressbookSync.time(); |
2692 | mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 2692 | mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
2693 | addresseeLSync.setRevision( mLastAddressbookSync ); | 2693 | addresseeLSync.setRevision( mLastAddressbookSync ); |
2694 | addresseeRSync.setRevision( mLastAddressbookSync ); | 2694 | addresseeRSync.setRevision( mLastAddressbookSync ); |
2695 | addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; | 2695 | addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; |
2696 | addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); | 2696 | addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); |
2697 | addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; | 2697 | addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; |
2698 | addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); | 2698 | addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); |
2699 | addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; | 2699 | addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; |
2700 | addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); | 2700 | addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); |
2701 | addresseeRSync.setNote( "" ) ; | 2701 | addresseeRSync.setNote( "" ) ; |
2702 | addresseeLSync.setNote( "" ); | 2702 | addresseeLSync.setNote( "" ); |
2703 | 2703 | ||
2704 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL) | 2704 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL) |
2705 | remote->insertAddressee( addresseeRSync, false ); | 2705 | remote->insertAddressee( addresseeRSync, false ); |
2706 | local->insertAddressee( addresseeLSync, false ); | 2706 | local->insertAddressee( addresseeLSync, false ); |
2707 | QString mes; | 2707 | QString mes; |
2708 | mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR ); | 2708 | mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR ); |
2709 | if ( syncManager->mShowSyncSummary ) { | 2709 | if ( syncManager->mShowSyncSummary ) { |
2710 | KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") ); | 2710 | KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") ); |
2711 | } | 2711 | } |
2712 | qDebug( mes ); | 2712 | qDebug( mes ); |
2713 | return syncOK; | 2713 | return syncOK; |
2714 | } | 2714 | } |
2715 | 2715 | ||
2716 | 2716 | ||
2717 | //this is a overwritten callbackmethods from the syncinterface | 2717 | //this is a overwritten callbackmethods from the syncinterface |
2718 | bool KABCore::sync(KSyncManager* manager, QString filename, int mode) | 2718 | bool KABCore::sync(KSyncManager* manager, QString filename, int mode) |
2719 | { | 2719 | { |
2720 | 2720 | ||
2721 | //pending prepare addresseeview for output | 2721 | //pending prepare addresseeview for output |
2722 | //pending detect, if remote file has REV field. if not switch to external sync | 2722 | //pending detect, if remote file has REV field. if not switch to external sync |
2723 | mGlobalSyncMode = SYNC_MODE_NORMAL; | 2723 | mGlobalSyncMode = SYNC_MODE_NORMAL; |
2724 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); | 2724 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); |
2725 | 2725 | ||
2726 | AddressBook abLocal(filename,"syncContact"); | 2726 | AddressBook abLocal(filename,"syncContact"); |
2727 | bool syncOK = false; | 2727 | bool syncOK = false; |
2728 | if ( abLocal.load() ) { | 2728 | if ( abLocal.load() ) { |
2729 | qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); | 2729 | qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); |
2730 | bool external = false; | 2730 | bool external = false; |
2731 | bool isXML = false; | 2731 | bool isXML = false; |
2732 | if ( filename.right(4) == ".xml") { | 2732 | if ( filename.right(4) == ".xml") { |
2733 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 2733 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
2734 | isXML = true; | 2734 | isXML = true; |
2735 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); | 2735 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); |
2736 | } else { | 2736 | } else { |
2737 | external = !manager->mIsKapiFile; | 2737 | external = !manager->mIsKapiFile; |
2738 | if ( external ) { | 2738 | if ( external ) { |
2739 | qDebug("Setting vcf mode to external "); | 2739 | qDebug("Setting vcf mode to external "); |
2740 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 2740 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
2741 | AddressBook::Iterator it; | 2741 | AddressBook::Iterator it; |
2742 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { | 2742 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { |
2743 | (*it).setID( mCurrentSyncDevice, (*it).uid() ); | 2743 | (*it).setID( mCurrentSyncDevice, (*it).uid() ); |
2744 | (*it).computeCsum( mCurrentSyncDevice ); | 2744 | (*it).computeCsum( mCurrentSyncDevice ); |
2745 | } | 2745 | } |
2746 | } | 2746 | } |
2747 | } | 2747 | } |
2748 | //AddressBook::Iterator it; | 2748 | //AddressBook::Iterator it; |
2749 | //QStringList vcards; | 2749 | //QStringList vcards; |
2750 | //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { | 2750 | //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { |
2751 | // qDebug("Name %s ", (*it).familyName().latin1()); | 2751 | // qDebug("Name %s ", (*it).familyName().latin1()); |
2752 | //} | 2752 | //} |
2753 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); | 2753 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); |
2754 | if ( syncOK ) { | 2754 | if ( syncOK ) { |
2755 | if ( syncManager->mWriteBackFile ) | 2755 | if ( syncManager->mWriteBackFile ) |
2756 | { | 2756 | { |
2757 | if ( external ) | 2757 | if ( external ) |
2758 | abLocal.removeSyncAddressees( !isXML); | 2758 | abLocal.removeSyncAddressees( !isXML); |
2759 | qDebug("Saving remote AB "); | 2759 | qDebug("Saving remote AB "); |
2760 | if ( ! abLocal.saveAB()) | 2760 | if ( ! abLocal.saveAB()) |
2761 | qDebug("Error writing back AB to file "); | 2761 | qDebug("Error writing back AB to file "); |
2762 | if ( isXML ) { | 2762 | if ( isXML ) { |
2763 | // afterwrite processing | 2763 | // afterwrite processing |
2764 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); | 2764 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); |
2765 | } | 2765 | } |
2766 | } | 2766 | } |
2767 | } | 2767 | } |
2768 | setModified(); | 2768 | setModified(); |
2769 | 2769 | ||
2770 | } | 2770 | } |
2771 | if ( syncOK ) | 2771 | if ( syncOK ) |
2772 | mViewManager->refreshView(); | 2772 | mViewManager->refreshView(); |
2773 | return syncOK; | 2773 | return syncOK; |
2774 | 2774 | ||
2775 | } | 2775 | } |
2776 | 2776 | ||
2777 | 2777 | ||
2778 | //this is a overwritten callbackmethods from the syncinterface | 2778 | //this is a overwritten callbackmethods from the syncinterface |
2779 | bool KABCore::syncExternal(KSyncManager* manager, QString resource) | 2779 | bool KABCore::syncExternal(KSyncManager* manager, QString resource) |
2780 | { | 2780 | { |
2781 | if ( resource == "phone" ) | 2781 | if ( resource == "phone" ) |
2782 | return syncPhone(); | 2782 | return syncPhone(); |
2783 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); | 2783 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); |
2784 | 2784 | ||
2785 | AddressBook abLocal( resource,"syncContact"); | 2785 | AddressBook abLocal( resource,"syncContact"); |
2786 | bool syncOK = false; | 2786 | bool syncOK = false; |
2787 | if ( abLocal.load() ) { | 2787 | if ( abLocal.load() ) { |
2788 | qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); | 2788 | qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); |
2789 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 2789 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
2790 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); | 2790 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, false ); |
2791 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); | 2791 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); |
2792 | if ( syncOK ) { | 2792 | if ( syncOK ) { |
2793 | if ( syncManager->mWriteBackFile ) { | 2793 | if ( syncManager->mWriteBackFile ) { |
2794 | abLocal.removeSyncAddressees( false ); | 2794 | abLocal.removeSyncAddressees( false ); |
2795 | abLocal.saveAB(); | 2795 | abLocal.saveAB(); |
2796 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); | 2796 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); |
2797 | } | 2797 | } |
2798 | } | 2798 | } |
2799 | setModified(); | 2799 | setModified(); |
2800 | } | 2800 | } |
2801 | if ( syncOK ) | 2801 | if ( syncOK ) |
2802 | mViewManager->refreshView(); | 2802 | mViewManager->refreshView(); |
2803 | return syncOK; | 2803 | return syncOK; |
2804 | 2804 | ||
2805 | } | 2805 | } |
2806 | void KABCore::message( QString m ) | 2806 | void KABCore::message( QString m ) |
2807 | { | 2807 | { |
2808 | 2808 | ||
2809 | topLevelWidget()->setCaption( m ); | 2809 | topLevelWidget()->setCaption( m ); |
2810 | QTimer::singleShot( 15000, this , SLOT ( setCaptionBack())); | 2810 | QTimer::singleShot( 15000, this , SLOT ( setCaptionBack())); |
2811 | } | 2811 | } |
2812 | bool KABCore::syncPhone() | 2812 | bool KABCore::syncPhone() |
2813 | { | 2813 | { |
2814 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); | 2814 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); |
2815 | QString fileName; | 2815 | QString fileName; |
2816 | #ifdef _WIN32_ | 2816 | #ifdef _WIN32_ |
2817 | fileName = locateLocal("tmp", "phonefile.vcf"); | 2817 | fileName = locateLocal("tmp", "phonefile.vcf"); |
2818 | #else | 2818 | #else |
2819 | fileName = "/tmp/phonefile.vcf"; | 2819 | fileName = "/tmp/phonefile.vcf"; |
2820 | #endif | 2820 | #endif |
2821 | if ( !PhoneAccess::readFromPhone( fileName) ) { | 2821 | if ( !PhoneAccess::readFromPhone( fileName) ) { |
2822 | message(i18n("Phone access failed!")); | 2822 | message(i18n("Phone access failed!")); |
2823 | return false; | 2823 | return false; |
2824 | } | 2824 | } |
2825 | AddressBook abLocal( fileName,"syncContact"); | 2825 | AddressBook abLocal( fileName,"syncContact"); |
2826 | bool syncOK = false; | 2826 | bool syncOK = false; |
2827 | { | 2827 | { |
2828 | abLocal.importFromFile( fileName ); | 2828 | abLocal.importFromFile( fileName ); |
2829 | qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1()); | 2829 | qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1()); |
2830 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 2830 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
2831 | abLocal.preparePhoneSync( mCurrentSyncDevice, true ); | 2831 | abLocal.preparePhoneSync( mCurrentSyncDevice, true ); |
2832 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); | 2832 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); |
2833 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); | 2833 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); |
2834 | if ( syncOK ) { | 2834 | if ( syncOK ) { |
2835 | if ( syncManager->mWriteBackFile ) { | 2835 | if ( syncManager->mWriteBackFile ) { |
2836 | abLocal.removeSyncAddressees( true ); | 2836 | abLocal.removeSyncAddressees( true ); |
2837 | abLocal.saveABphone( fileName ); | 2837 | abLocal.saveABphone( fileName ); |
2838 | abLocal.findNewExtIds( fileName, mCurrentSyncDevice ); | 2838 | abLocal.findNewExtIds( fileName, mCurrentSyncDevice ); |
2839 | //abLocal.preparePhoneSync( mCurrentSyncDevice, false ); | 2839 | //abLocal.preparePhoneSync( mCurrentSyncDevice, false ); |
2840 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); | 2840 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); |
2841 | } | 2841 | } |
2842 | } | 2842 | } |
2843 | setModified(); | 2843 | setModified(); |
2844 | } | 2844 | } |
2845 | if ( syncOK ) | 2845 | if ( syncOK ) |
2846 | mViewManager->refreshView(); | 2846 | mViewManager->refreshView(); |
2847 | return syncOK; | 2847 | return syncOK; |
2848 | } | 2848 | } |
2849 | void KABCore::getFile( bool success ) | 2849 | void KABCore::getFile( bool success ) |
2850 | { | 2850 | { |
2851 | if ( ! success ) { | 2851 | if ( ! success ) { |
2852 | message( i18n("Error receiving file. Nothing changed!") ); | 2852 | message( i18n("Error receiving file. Nothing changed!") ); |
2853 | return; | 2853 | return; |
2854 | } | 2854 | } |
2855 | mAddressBook->importFromFile( sentSyncFile() , false, true ); | 2855 | mAddressBook->importFromFile( sentSyncFile() , false, true ); |
2856 | message( i18n("Pi-Sync successful!") ); | 2856 | message( i18n("Pi-Sync successful!") ); |
2857 | mViewManager->refreshView(); | 2857 | mViewManager->refreshView(); |
2858 | } | 2858 | } |
2859 | void KABCore::syncFileRequest() | 2859 | void KABCore::syncFileRequest() |
2860 | { | 2860 | { |
2861 | mAddressBook->export2File( sentSyncFile() ); | 2861 | mAddressBook->export2File( sentSyncFile() ); |
2862 | } | 2862 | } |
2863 | QString KABCore::sentSyncFile() | 2863 | QString KABCore::sentSyncFile() |
2864 | { | 2864 | { |
2865 | #ifdef _WIN32_ | 2865 | #ifdef _WIN32_ |
2866 | return locateLocal( "tmp", "copysyncab.vcf" ); | 2866 | return locateLocal( "tmp", "copysyncab.vcf" ); |
2867 | #else | 2867 | #else |
2868 | return QString( "/tmp/copysyncab.vcf" ); | 2868 | return QString( "/tmp/copysyncab.vcf" ); |
2869 | #endif | 2869 | #endif |
2870 | } | 2870 | } |
2871 | 2871 | ||
2872 | void KABCore::setCaptionBack() | 2872 | void KABCore::setCaptionBack() |
2873 | { | 2873 | { |
2874 | topLevelWidget()->setCaption( i18n("KAddressbook/Pi") ); | 2874 | topLevelWidget()->setCaption( i18n("KAddressbook/Pi") ); |
2875 | } | 2875 | } |