author | zautrix <zautrix> | 2004-10-27 19:44:10 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-27 19:44:10 (UTC) |
commit | bb82cac85cc196b3f60921ab27e84204036b54b8 (patch) (unidiff) | |
tree | 518629480b983b6b85a4cf1e5542f94fe1687e41 | |
parent | 85a0e0d9b1d60805cb4947be1c296c18e73c82b8 (diff) | |
download | kdepimpi-bb82cac85cc196b3f60921ab27e84204036b54b8.zip kdepimpi-bb82cac85cc196b3f60921ab27e84204036b54b8.tar.gz kdepimpi-bb82cac85cc196b3f60921ab27e84204036b54b8.tar.bz2 |
sync fixes
-rw-r--r-- | kabc/addressbook.cpp | 19 | ||||
-rw-r--r-- | kabc/addressbook.h | 2 | ||||
-rw-r--r-- | kabc/addressee.cpp | 2 | ||||
-rw-r--r-- | kaddressbook/kabcore.cpp | 16 |
4 files changed, 26 insertions, 13 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 9b196b5..5774c36 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp | |||
@@ -493,751 +493,762 @@ int AddressBook::importFromFile( QString fileName, bool replaceLabel, bool remo | |||
493 | data.replace ( QRegExp("LABEL") , "ADR" ); | 493 | data.replace ( QRegExp("LABEL") , "ADR" ); |
494 | data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); | 494 | data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); |
495 | } else | 495 | } else |
496 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); | 496 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); |
497 | KABC::VCardTool tool; | 497 | KABC::VCardTool tool; |
498 | list = tool.parseVCards( data ); | 498 | list = tool.parseVCards( data ); |
499 | KABC::Addressee::List::Iterator it; | 499 | KABC::Addressee::List::Iterator it; |
500 | for ( it = list.begin(); it != list.end(); ++it ) { | 500 | for ( it = list.begin(); it != list.end(); ++it ) { |
501 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); | 501 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); |
502 | if ( !id.isEmpty() ) | 502 | if ( !id.isEmpty() ) |
503 | (*it).setIDStr(id ); | 503 | (*it).setIDStr(id ); |
504 | (*it).setResource( 0 ); | 504 | (*it).setResource( 0 ); |
505 | if ( replaceLabel ) | 505 | if ( replaceLabel ) |
506 | (*it).removeVoice(); | 506 | (*it).removeVoice(); |
507 | if ( removeOld ) | 507 | if ( removeOld ) |
508 | (*it).setTagged( true ); | 508 | (*it).setTagged( true ); |
509 | insertAddressee( (*it), false, true ); | 509 | insertAddressee( (*it), false, true ); |
510 | } | 510 | } |
511 | if ( removeOld ) | 511 | if ( removeOld ) |
512 | removeUntagged(); | 512 | removeUntagged(); |
513 | return list.count(); | 513 | return list.count(); |
514 | } | 514 | } |
515 | void AddressBook::setUntagged(bool setNonSyncTagged) // = false) | 515 | void AddressBook::setUntagged(bool setNonSyncTagged) // = false) |
516 | { | 516 | { |
517 | Iterator ait; | 517 | Iterator ait; |
518 | for ( ait = begin(); ait != end(); ++ait ) { | 518 | for ( ait = begin(); ait != end(); ++ait ) { |
519 | if ( setNonSyncTagged ) { | 519 | if ( setNonSyncTagged ) { |
520 | if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) { | 520 | if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) { |
521 | (*ait).setTagged( true ); | 521 | (*ait).setTagged( true ); |
522 | } else | 522 | } else |
523 | (*ait).setTagged( false ); | 523 | (*ait).setTagged( false ); |
524 | } else | 524 | } else |
525 | (*ait).setTagged( false ); | 525 | (*ait).setTagged( false ); |
526 | } | 526 | } |
527 | } | 527 | } |
528 | void AddressBook::removeUntagged() | 528 | void AddressBook::removeUntagged() |
529 | { | 529 | { |
530 | Iterator ait; | 530 | Iterator ait; |
531 | bool todelete = false; | 531 | bool todelete = false; |
532 | Iterator todel; | 532 | Iterator todel; |
533 | for ( ait = begin(); ait != end(); ++ait ) { | 533 | for ( ait = begin(); ait != end(); ++ait ) { |
534 | if ( todelete ) | 534 | if ( todelete ) |
535 | removeAddressee( todel ); | 535 | removeAddressee( todel ); |
536 | if (!(*ait).tagged()) { | 536 | if (!(*ait).tagged()) { |
537 | todelete = true; | 537 | todelete = true; |
538 | todel = ait; | 538 | todel = ait; |
539 | } else | 539 | } else |
540 | todelete = false; | 540 | todelete = false; |
541 | } | 541 | } |
542 | if ( todelete ) | 542 | if ( todelete ) |
543 | removeAddressee( todel ); | 543 | removeAddressee( todel ); |
544 | deleteRemovedAddressees(); | 544 | deleteRemovedAddressees(); |
545 | } | 545 | } |
546 | void AddressBook::smplifyAddressees() | 546 | void AddressBook::smplifyAddressees() |
547 | { | 547 | { |
548 | Iterator ait; | 548 | Iterator ait; |
549 | for ( ait = begin(); ait != end(); ++ait ) { | 549 | for ( ait = begin(); ait != end(); ++ait ) { |
550 | (*ait).simplifyEmails(); | 550 | (*ait).simplifyEmails(); |
551 | (*ait).simplifyPhoneNumbers(); | 551 | (*ait).simplifyPhoneNumbers(); |
552 | (*ait).simplifyPhoneNumberTypes(); | 552 | (*ait).simplifyPhoneNumberTypes(); |
553 | (*ait).simplifyAddresses(); | 553 | (*ait).simplifyAddresses(); |
554 | } | 554 | } |
555 | } | 555 | } |
556 | void AddressBook::removeSyncInfo( QString syncProfile) | 556 | void AddressBook::removeSyncInfo( QString syncProfile) |
557 | { | 557 | { |
558 | Iterator ait; | 558 | Iterator ait; |
559 | for ( ait = begin(); ait != end(); ++ait ) { | 559 | for ( ait = begin(); ait != end(); ++ait ) { |
560 | (*ait).removeID( syncProfile ); | 560 | (*ait).removeID( syncProfile ); |
561 | } | 561 | } |
562 | if ( syncProfile.isEmpty() ) { | 562 | if ( syncProfile.isEmpty() ) { |
563 | Iterator it = begin(); | 563 | Iterator it = begin(); |
564 | Iterator it2 ; | 564 | Iterator it2 ; |
565 | QDateTime dt ( QDate( 2004,1,1) ); | 565 | QDateTime dt ( QDate( 2004,1,1) ); |
566 | while ( it != end() ) { | 566 | while ( it != end() ) { |
567 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 567 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
568 | it2 = it; | 568 | it2 = it; |
569 | //qDebug("removing %s ",(*it).uid().latin1() ); | 569 | //qDebug("removing %s ",(*it).uid().latin1() ); |
570 | ++it; | 570 | ++it; |
571 | removeAddressee( it2 ); | 571 | removeAddressee( it2 ); |
572 | } else { | 572 | } else { |
573 | //qDebug("skipping %s ",(*it).uid().latin1() ); | 573 | //qDebug("skipping %s ",(*it).uid().latin1() ); |
574 | ++it; | 574 | ++it; |
575 | } | 575 | } |
576 | } | 576 | } |
577 | } else { | 577 | } else { |
578 | Addressee lse; | 578 | Addressee lse; |
579 | lse = findByUid( "last-syncAddressee-"+ syncProfile ); | 579 | lse = findByUid( "last-syncAddressee-"+ syncProfile ); |
580 | if ( ! lse.isEmpty() ) | 580 | if ( ! lse.isEmpty() ) |
581 | removeAddressee( lse ); | 581 | removeAddressee( lse ); |
582 | } | 582 | } |
583 | 583 | ||
584 | } | 584 | } |
585 | void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) | 585 | void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) |
586 | { | 586 | { |
587 | Iterator ait; | 587 | Iterator ait; |
588 | for ( ait = begin(); ait != end(); ++ait ) { | 588 | for ( ait = begin(); ait != end(); ++ait ) { |
589 | QString id = (*ait).IDStr(); | 589 | QString id = (*ait).IDStr(); |
590 | (*ait).setIDStr( ":"); | 590 | (*ait).setIDStr( ":"); |
591 | (*ait).setExternalUID( id ); | 591 | (*ait).setExternalUID( id ); |
592 | (*ait).setOriginalExternalUID( id ); | 592 | (*ait).setOriginalExternalUID( id ); |
593 | if ( isPreSync ) | 593 | if ( isPreSync ) |
594 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 594 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
595 | else { | 595 | else { |
596 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 596 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
597 | (*ait).setID( currentSyncDevice,id ); | 597 | (*ait).setID( currentSyncDevice,id ); |
598 | 598 | ||
599 | } | 599 | } |
600 | } | 600 | } |
601 | } | 601 | } |
602 | void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice ) | 602 | void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice ) |
603 | { | 603 | { |
604 | 604 | ||
605 | setUntagged(); | 605 | setUntagged(); |
606 | KABC::Addressee::List list; | 606 | KABC::Addressee::List list; |
607 | QFile file( fileName ); | 607 | QFile file( fileName ); |
608 | file.open( IO_ReadOnly ); | 608 | file.open( IO_ReadOnly ); |
609 | QByteArray rawData = file.readAll(); | 609 | QByteArray rawData = file.readAll(); |
610 | file.close(); | 610 | file.close(); |
611 | QString data; | 611 | QString data; |
612 | 612 | ||
613 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); | 613 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); |
614 | KABC::VCardTool tool; | 614 | KABC::VCardTool tool; |
615 | list = tool.parseVCards( data ); | 615 | list = tool.parseVCards( data ); |
616 | KABC::Addressee::List::Iterator it; | 616 | KABC::Addressee::List::Iterator it; |
617 | for ( it = list.begin(); it != list.end(); ++it ) { | 617 | for ( it = list.begin(); it != list.end(); ++it ) { |
618 | Iterator ait; | 618 | Iterator ait; |
619 | for ( ait = begin(); ait != end(); ++ait ) { | 619 | for ( ait = begin(); ait != end(); ++ait ) { |
620 | if ( !(*ait).tagged() ) { | 620 | if ( !(*ait).tagged() ) { |
621 | if ( (*ait).containsAdr(*it)) { | 621 | if ( (*ait).containsAdr(*it)) { |
622 | (*ait).setTagged(true); | 622 | (*ait).setTagged(true); |
623 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); | 623 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); |
624 | (*it).setIDStr( ":"); | 624 | (*it).setIDStr( ":"); |
625 | (*it).setID( currentSyncDevice,id ); | 625 | (*it).setID( currentSyncDevice,id ); |
626 | (*it).setExternalUID( id ); | 626 | (*it).setExternalUID( id ); |
627 | (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 627 | (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
628 | (*it).setUid( ( (*ait).uid() )); | 628 | (*it).setUid( ( (*ait).uid() )); |
629 | break; | 629 | break; |
630 | } | 630 | } |
631 | } | 631 | } |
632 | 632 | ||
633 | } | 633 | } |
634 | if ( ait == end() ) | 634 | if ( ait == end() ) |
635 | qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1()); | 635 | qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1()); |
636 | } | 636 | } |
637 | clear(); | 637 | clear(); |
638 | for ( it = list.begin(); it != list.end(); ++it ) { | 638 | for ( it = list.begin(); it != list.end(); ++it ) { |
639 | insertAddressee( (*it) ); | 639 | insertAddressee( (*it) ); |
640 | } | 640 | } |
641 | } | 641 | } |
642 | 642 | ||
643 | bool AddressBook::saveABphone( QString fileName ) | 643 | bool AddressBook::saveABphone( QString fileName ) |
644 | { | 644 | { |
645 | //smplifyAddressees(); | 645 | //smplifyAddressees(); |
646 | qDebug("saveABphone:: saving AB... "); | 646 | qDebug("saveABphone:: saving AB... "); |
647 | if ( ! export2PhoneFormat( QStringList() ,fileName ) ) | 647 | if ( ! export2PhoneFormat( QStringList() ,fileName ) ) |
648 | return false; | 648 | return false; |
649 | qDebug("saveABphone:: writing to phone... "); | 649 | qDebug("saveABphone:: writing to phone... "); |
650 | if ( !PhoneAccess::writeToPhone( fileName) ) { | 650 | if ( !PhoneAccess::writeToPhone( fileName) ) { |
651 | return false; | 651 | return false; |
652 | } | 652 | } |
653 | qDebug("saveABphone:: re-reading from phone... "); | 653 | qDebug("saveABphone:: re-reading from phone... "); |
654 | if ( !PhoneAccess::readFromPhone( fileName) ) { | 654 | if ( !PhoneAccess::readFromPhone( fileName) ) { |
655 | return false; | 655 | return false; |
656 | } | 656 | } |
657 | return true; | 657 | return true; |
658 | } | 658 | } |
659 | bool AddressBook::saveAB() | 659 | bool AddressBook::saveAB() |
660 | { | 660 | { |
661 | bool ok = true; | 661 | bool ok = true; |
662 | 662 | ||
663 | deleteRemovedAddressees(); | 663 | deleteRemovedAddressees(); |
664 | Iterator ait; | 664 | Iterator ait; |
665 | for ( ait = begin(); ait != end(); ++ait ) { | 665 | for ( ait = begin(); ait != end(); ++ait ) { |
666 | if ( !(*ait).IDStr().isEmpty() ) { | 666 | if ( !(*ait).IDStr().isEmpty() ) { |
667 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); | 667 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); |
668 | } | 668 | } |
669 | } | 669 | } |
670 | KRES::Manager<Resource>::ActiveIterator it; | 670 | KRES::Manager<Resource>::ActiveIterator it; |
671 | KRES::Manager<Resource> *manager = d->mManager; | 671 | KRES::Manager<Resource> *manager = d->mManager; |
672 | qDebug("SaveAB::saving..." ); | 672 | qDebug("SaveAB::saving..." ); |
673 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 673 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
674 | qDebug("SaveAB::checking resource..." ); | 674 | qDebug("SaveAB::checking resource..." ); |
675 | if ( (*it)->readOnly() ) | 675 | if ( (*it)->readOnly() ) |
676 | qDebug("resource is readonly." ); | 676 | qDebug("resource is readonly." ); |
677 | if ( (*it)->isOpen() ) | 677 | if ( (*it)->isOpen() ) |
678 | qDebug("resource is open" ); | 678 | qDebug("resource is open" ); |
679 | 679 | ||
680 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { | 680 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { |
681 | Ticket *ticket = requestSaveTicket( *it ); | 681 | Ticket *ticket = requestSaveTicket( *it ); |
682 | qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); | 682 | qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); |
683 | if ( !ticket ) { | 683 | if ( !ticket ) { |
684 | qDebug( i18n( "Unable to save to resource '%1'. It is locked." ) | 684 | qDebug( i18n( "Unable to save to resource '%1'. It is locked." ) |
685 | .arg( (*it)->resourceName() ) ); | 685 | .arg( (*it)->resourceName() ) ); |
686 | return false; | 686 | return false; |
687 | } | 687 | } |
688 | 688 | ||
689 | //if ( !save( ticket ) ) | 689 | //if ( !save( ticket ) ) |
690 | if ( ticket->resource() ) { | 690 | if ( ticket->resource() ) { |
691 | QString name = ticket->resource()->resourceName(); | 691 | QString name = ticket->resource()->resourceName(); |
692 | if ( ! ticket->resource()->save( ticket ) ) | 692 | if ( ! ticket->resource()->save( ticket ) ) |
693 | ok = false; | 693 | ok = false; |
694 | else | 694 | else |
695 | qDebug("StdAddressBook::resource saved '%s'", name.latin1() ); | 695 | qDebug("StdAddressBook::resource saved '%s'", name.latin1() ); |
696 | 696 | ||
697 | } else | 697 | } else |
698 | ok = false; | 698 | ok = false; |
699 | 699 | ||
700 | } | 700 | } |
701 | } | 701 | } |
702 | return ok; | 702 | return ok; |
703 | } | 703 | } |
704 | 704 | ||
705 | AddressBook::Iterator AddressBook::begin() | 705 | AddressBook::Iterator AddressBook::begin() |
706 | { | 706 | { |
707 | Iterator it = Iterator(); | 707 | Iterator it = Iterator(); |
708 | it.d->mIt = d->mAddressees.begin(); | 708 | it.d->mIt = d->mAddressees.begin(); |
709 | return it; | 709 | return it; |
710 | } | 710 | } |
711 | 711 | ||
712 | AddressBook::ConstIterator AddressBook::begin() const | 712 | AddressBook::ConstIterator AddressBook::begin() const |
713 | { | 713 | { |
714 | ConstIterator it = ConstIterator(); | 714 | ConstIterator it = ConstIterator(); |
715 | it.d->mIt = d->mAddressees.begin(); | 715 | it.d->mIt = d->mAddressees.begin(); |
716 | return it; | 716 | return it; |
717 | } | 717 | } |
718 | 718 | ||
719 | AddressBook::Iterator AddressBook::end() | 719 | AddressBook::Iterator AddressBook::end() |
720 | { | 720 | { |
721 | Iterator it = Iterator(); | 721 | Iterator it = Iterator(); |
722 | it.d->mIt = d->mAddressees.end(); | 722 | it.d->mIt = d->mAddressees.end(); |
723 | return it; | 723 | return it; |
724 | } | 724 | } |
725 | 725 | ||
726 | AddressBook::ConstIterator AddressBook::end() const | 726 | AddressBook::ConstIterator AddressBook::end() const |
727 | { | 727 | { |
728 | ConstIterator it = ConstIterator(); | 728 | ConstIterator it = ConstIterator(); |
729 | it.d->mIt = d->mAddressees.end(); | 729 | it.d->mIt = d->mAddressees.end(); |
730 | return it; | 730 | return it; |
731 | } | 731 | } |
732 | 732 | ||
733 | void AddressBook::clear() | 733 | void AddressBook::clear() |
734 | { | 734 | { |
735 | d->mAddressees.clear(); | 735 | d->mAddressees.clear(); |
736 | } | 736 | } |
737 | 737 | ||
738 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) | 738 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) |
739 | { | 739 | { |
740 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; | 740 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; |
741 | 741 | ||
742 | if ( !resource ) | 742 | if ( !resource ) |
743 | { | 743 | { |
744 | qDebug("AddressBook::requestSaveTicket no resource" ); | 744 | qDebug("AddressBook::requestSaveTicket no resource" ); |
745 | resource = standardResource(); | 745 | resource = standardResource(); |
746 | } | 746 | } |
747 | 747 | ||
748 | KRES::Manager<Resource>::ActiveIterator it; | 748 | KRES::Manager<Resource>::ActiveIterator it; |
749 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 749 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
750 | if ( (*it) == resource ) { | 750 | if ( (*it) == resource ) { |
751 | if ( (*it)->readOnly() || !(*it)->isOpen() ) | 751 | if ( (*it)->readOnly() || !(*it)->isOpen() ) |
752 | return 0; | 752 | return 0; |
753 | else | 753 | else |
754 | return (*it)->requestSaveTicket(); | 754 | return (*it)->requestSaveTicket(); |
755 | } | 755 | } |
756 | } | 756 | } |
757 | 757 | ||
758 | return 0; | 758 | return 0; |
759 | } | 759 | } |
760 | //void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); | 760 | //void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); |
761 | void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) | 761 | void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) |
762 | { | 762 | { |
763 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { | 763 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { |
764 | //qDebug("block insert "); | 764 | //qDebug("block insert "); |
765 | return; | 765 | return; |
766 | } | 766 | } |
767 | //qDebug("inserting.... %s ",a.uid().latin1() ); | 767 | //qDebug("inserting.... %s ",a.uid().latin1() ); |
768 | bool found = false; | 768 | bool found = false; |
769 | Addressee::List::Iterator it; | 769 | Addressee::List::Iterator it; |
770 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { | 770 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { |
771 | if ( a.uid() == (*it).uid() ) { | 771 | if ( a.uid() == (*it).uid() ) { |
772 | 772 | ||
773 | bool changed = false; | 773 | bool changed = false; |
774 | Addressee addr = a; | 774 | Addressee addr = a; |
775 | if ( addr != (*it) ) | 775 | if ( addr != (*it) ) |
776 | changed = true; | 776 | changed = true; |
777 | 777 | ||
778 | if ( takeResource ) { | 778 | if ( takeResource ) { |
779 | Resource * res = (*it).resource(); | 779 | Resource * res = (*it).resource(); |
780 | (*it) = a; | 780 | (*it) = a; |
781 | (*it).setResource( res ); | 781 | (*it).setResource( res ); |
782 | } else { | 782 | } else { |
783 | (*it) = a; | 783 | (*it) = a; |
784 | if ( (*it).resource() == 0 ) | 784 | if ( (*it).resource() == 0 ) |
785 | (*it).setResource( standardResource() ); | 785 | (*it).setResource( standardResource() ); |
786 | } | 786 | } |
787 | if ( changed ) { | 787 | if ( changed ) { |
788 | if ( setRev ) { | 788 | if ( setRev ) { |
789 | 789 | ||
790 | // get rid of micro seconds | 790 | // get rid of micro seconds |
791 | QDateTime dt = QDateTime::currentDateTime(); | 791 | QDateTime dt = QDateTime::currentDateTime(); |
792 | QTime t = dt.time(); | 792 | QTime t = dt.time(); |
793 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 793 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
794 | (*it).setRevision( dt ); | 794 | (*it).setRevision( dt ); |
795 | } | 795 | } |
796 | (*it).setChanged( true ); | 796 | (*it).setChanged( true ); |
797 | } | 797 | } |
798 | 798 | ||
799 | found = true; | 799 | found = true; |
800 | } else { | 800 | } else { |
801 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 801 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
802 | QString name = (*it).uid().mid( 19 ); | 802 | QString name = (*it).uid().mid( 19 ); |
803 | Addressee b = a; | 803 | Addressee b = a; |
804 | QString id = b.getID( name ); | 804 | QString id = b.getID( name ); |
805 | if ( ! id.isEmpty() ) { | 805 | if ( ! id.isEmpty() ) { |
806 | QString des = (*it).note(); | 806 | QString des = (*it).note(); |
807 | int startN; | 807 | int startN; |
808 | if( (startN = des.find( id ) ) >= 0 ) { | 808 | if( (startN = des.find( id ) ) >= 0 ) { |
809 | int endN = des.find( ",", startN+1 ); | 809 | int endN = des.find( ",", startN+1 ); |
810 | des = des.left( startN ) + des.mid( endN+1 ); | 810 | des = des.left( startN ) + des.mid( endN+1 ); |
811 | (*it).setNote( des ); | 811 | (*it).setNote( des ); |
812 | } | 812 | } |
813 | } | 813 | } |
814 | } | 814 | } |
815 | } | 815 | } |
816 | } | 816 | } |
817 | if ( found ) | 817 | if ( found ) |
818 | return; | 818 | return; |
819 | d->mAddressees.append( a ); | 819 | d->mAddressees.append( a ); |
820 | Addressee& addr = d->mAddressees.last(); | 820 | Addressee& addr = d->mAddressees.last(); |
821 | if ( addr.resource() == 0 ) | 821 | if ( addr.resource() == 0 ) |
822 | addr.setResource( standardResource() ); | 822 | addr.setResource( standardResource() ); |
823 | 823 | ||
824 | addr.setChanged( true ); | 824 | addr.setChanged( true ); |
825 | } | 825 | } |
826 | 826 | ||
827 | void AddressBook::removeAddressee( const Addressee &a ) | 827 | void AddressBook::removeAddressee( const Addressee &a ) |
828 | { | 828 | { |
829 | Iterator it; | 829 | Iterator it; |
830 | Iterator it2; | 830 | Iterator it2; |
831 | bool found = false; | 831 | bool found = false; |
832 | for ( it = begin(); it != end(); ++it ) { | 832 | for ( it = begin(); it != end(); ++it ) { |
833 | if ( a.uid() == (*it).uid() ) { | 833 | if ( a.uid() == (*it).uid() ) { |
834 | found = true; | 834 | found = true; |
835 | it2 = it; | 835 | it2 = it; |
836 | } else { | 836 | } else { |
837 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 837 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
838 | QString name = (*it).uid().mid( 19 ); | 838 | QString name = (*it).uid().mid( 19 ); |
839 | Addressee b = a; | 839 | Addressee b = a; |
840 | QString id = b.getID( name ); | 840 | QString id = b.getID( name ); |
841 | if ( ! id.isEmpty() ) { | 841 | if ( ! id.isEmpty() ) { |
842 | QString des = (*it).note(); | 842 | QString des = (*it).note(); |
843 | if( des.find( id ) < 0 ) { | 843 | if( des.find( id ) < 0 ) { |
844 | des += id + ","; | 844 | des += id + ","; |
845 | (*it).setNote( des ); | 845 | (*it).setNote( des ); |
846 | } | 846 | } |
847 | } | 847 | } |
848 | } | 848 | } |
849 | 849 | ||
850 | } | 850 | } |
851 | } | 851 | } |
852 | 852 | ||
853 | if ( found ) | 853 | if ( found ) |
854 | removeAddressee( it2 ); | 854 | removeAddressee( it2 ); |
855 | 855 | ||
856 | } | 856 | } |
857 | 857 | ||
858 | void AddressBook::removeSyncAddressees( bool removeDeleted ) | 858 | void AddressBook::removeSyncAddressees( bool removeDeleted ) |
859 | { | 859 | { |
860 | Iterator it = begin(); | 860 | Iterator it = begin(); |
861 | Iterator it2 ; | 861 | Iterator it2 ; |
862 | QDateTime dt ( QDate( 2004,1,1) ); | 862 | QDateTime dt ( QDate( 2004,1,1) ); |
863 | while ( it != end() ) { | 863 | while ( it != end() ) { |
864 | (*it).setRevision( dt ); | 864 | (*it).setRevision( dt ); |
865 | if (( *it).IDStr() != "changed" ) { | 865 | if (( *it).IDStr() != "changed" ) { |
866 | // "changed" is used for tagging changed addressees when syncing with KDE or OL | 866 | // "changed" is used for tagging changed addressees when syncing with KDE or OL |
867 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); | 867 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); |
868 | (*it).setIDStr(""); | 868 | (*it).setIDStr(""); |
869 | } | 869 | } |
870 | if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { | 870 | if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { |
871 | it2 = it; | 871 | it2 = it; |
872 | //qDebug("removing %s ",(*it).uid().latin1() ); | 872 | //qDebug("removing %s ",(*it).uid().latin1() ); |
873 | ++it; | 873 | ++it; |
874 | removeAddressee( it2 ); | 874 | removeAddressee( it2 ); |
875 | } else { | 875 | } else { |
876 | //qDebug("skipping %s ",(*it).uid().latin1() ); | 876 | //qDebug("skipping %s ",(*it).uid().latin1() ); |
877 | if ( removeDeleted ) { | ||
878 | // we have no postprocessing in the resource, we have to do it here | ||
879 | // we have to compute csum for all, because it could be the first sync | ||
880 | (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM ); | ||
881 | |||
882 | |||
883 | } | ||
877 | ++it; | 884 | ++it; |
878 | } | 885 | } |
879 | } | 886 | } |
880 | deleteRemovedAddressees(); | 887 | deleteRemovedAddressees(); |
881 | } | 888 | } |
882 | 889 | ||
883 | void AddressBook::removeAddressee( const Iterator &it ) | 890 | void AddressBook::removeAddressee( const Iterator &it ) |
884 | { | 891 | { |
885 | d->mRemovedAddressees.append( (*it) ); | 892 | d->mRemovedAddressees.append( (*it) ); |
886 | d->mAddressees.remove( it.d->mIt ); | 893 | d->mAddressees.remove( it.d->mIt ); |
887 | } | 894 | } |
888 | 895 | ||
889 | AddressBook::Iterator AddressBook::find( const Addressee &a ) | 896 | AddressBook::Iterator AddressBook::find( const Addressee &a ) |
890 | { | 897 | { |
891 | Iterator it; | 898 | Iterator it; |
892 | for ( it = begin(); it != end(); ++it ) { | 899 | for ( it = begin(); it != end(); ++it ) { |
893 | if ( a.uid() == (*it).uid() ) { | 900 | if ( a.uid() == (*it).uid() ) { |
894 | return it; | 901 | return it; |
895 | } | 902 | } |
896 | } | 903 | } |
897 | return end(); | 904 | return end(); |
898 | } | 905 | } |
899 | 906 | ||
900 | Addressee AddressBook::findByUid( const QString &uid ) | 907 | Addressee AddressBook::findByUid( const QString &uid ) |
901 | { | 908 | { |
902 | Iterator it; | 909 | Iterator it; |
903 | for ( it = begin(); it != end(); ++it ) { | 910 | for ( it = begin(); it != end(); ++it ) { |
904 | if ( uid == (*it).uid() ) { | 911 | if ( uid == (*it).uid() ) { |
905 | return *it; | 912 | return *it; |
906 | } | 913 | } |
907 | } | 914 | } |
908 | return Addressee(); | 915 | return Addressee(); |
909 | } | 916 | } |
910 | void AddressBook::preExternSync( AddressBook* aBook, const QString& csd , bool isSubset ) | 917 | void AddressBook::preExternSync( AddressBook* aBook, const QString& csd , bool isSubset ) |
911 | { | 918 | { |
912 | //qDebug("AddressBook::preExternSync "); | 919 | //qDebug("AddressBook::preExternSync "); |
913 | AddressBook::Iterator it; | 920 | AddressBook::Iterator it; |
914 | for ( it = begin(); it != end(); ++it ) { | 921 | for ( it = begin(); it != end(); ++it ) { |
915 | (*it).setID( csd, (*it).externalUID() ); | 922 | (*it).setID( csd, (*it).externalUID() ); |
916 | (*it).computeCsum( csd ); | 923 | (*it).computeCsum( csd ); |
917 | } | 924 | } |
918 | mergeAB( aBook ,csd, isSubset ); | 925 | mergeAB( aBook ,csd, isSubset ); |
919 | } | 926 | } |
920 | void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) | 927 | void AddressBook::postExternSync( AddressBook* aBook , const QString& csd, bool setID) |
921 | { | 928 | { |
922 | //qDebug("AddressBook::postExternSync "); | 929 | //qDebug("AddressBook::postExternSync "); |
923 | AddressBook::Iterator it; | 930 | AddressBook::Iterator it; |
924 | for ( it = begin(); it != end(); ++it ) { | 931 | for ( it = begin(); it != end(); ++it ) { |
925 | // qDebug("check uid %s ", (*it).uid().latin1() ); | 932 | //qDebug("check uid %s ", (*it).uid().latin1() ); |
926 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || | 933 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || |
927 | (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { | 934 | (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { |
928 | Addressee ad = aBook->findByUid( ( (*it).uid() )); | 935 | Addressee ad = aBook->findByUid( ( (*it).uid() )); |
929 | if ( ad.isEmpty() ) { | 936 | if ( ad.isEmpty() ) { |
930 | qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); | 937 | qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); |
931 | } else { | 938 | } else { |
939 | (*it).setIDStr(":"); | ||
932 | (*it).computeCsum( csd ); | 940 | (*it).computeCsum( csd ); |
933 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) | 941 | if ( setID ) { |
934 | ad.setID( csd, (*it).externalUID() ); | 942 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) |
943 | ad.setID( csd, (*it).externalUID() ); | ||
944 | } else | ||
945 | ad.setID( csd, "_" ); | ||
935 | ad.setCsum( csd, (*it).getCsum( csd ) ); | 946 | ad.setCsum( csd, (*it).getCsum( csd ) ); |
936 | aBook->insertAddressee( ad ); | 947 | aBook->insertAddressee( ad ); |
937 | } | 948 | } |
938 | } | 949 | } |
939 | } | 950 | } |
940 | } | 951 | } |
941 | 952 | ||
942 | bool AddressBook::containsExternalUid( const QString& uid ) | 953 | bool AddressBook::containsExternalUid( const QString& uid ) |
943 | { | 954 | { |
944 | Iterator it; | 955 | Iterator it; |
945 | for ( it = begin(); it != end(); ++it ) { | 956 | for ( it = begin(); it != end(); ++it ) { |
946 | if ( uid == (*it).externalUID( ) ) | 957 | if ( uid == (*it).externalUID( ) ) |
947 | return true; | 958 | return true; |
948 | } | 959 | } |
949 | return false; | 960 | return false; |
950 | } | 961 | } |
951 | Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) | 962 | Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) |
952 | { | 963 | { |
953 | Iterator it; | 964 | Iterator it; |
954 | for ( it = begin(); it != end(); ++it ) { | 965 | for ( it = begin(); it != end(); ++it ) { |
955 | if ( uid == (*it).getID( profile ) ) | 966 | if ( uid == (*it).getID( profile ) ) |
956 | return (*it); | 967 | return (*it); |
957 | } | 968 | } |
958 | return Addressee(); | 969 | return Addressee(); |
959 | } | 970 | } |
960 | void AddressBook::mergeAB( AddressBook *aBook, const QString& profile , bool isSubset ) | 971 | void AddressBook::mergeAB( AddressBook *aBook, const QString& profile , bool isSubset ) |
961 | { | 972 | { |
962 | Iterator it; | 973 | Iterator it; |
963 | Addressee ad; | 974 | Addressee ad; |
964 | for ( it = begin(); it != end(); ++it ) { | 975 | for ( it = begin(); it != end(); ++it ) { |
965 | ad = aBook->findByExternUid( (*it).externalUID(), profile ); | 976 | ad = aBook->findByExternUid( (*it).externalUID(), profile ); |
966 | if ( !ad.isEmpty() ) { | 977 | if ( !ad.isEmpty() ) { |
967 | (*it).mergeContact( ad ,isSubset); | 978 | (*it).mergeContact( ad ,isSubset); |
968 | } | 979 | } |
969 | } | 980 | } |
970 | #if 0 | 981 | #if 0 |
971 | // test only | 982 | // test only |
972 | for ( it = begin(); it != end(); ++it ) { | 983 | for ( it = begin(); it != end(); ++it ) { |
973 | 984 | ||
974 | qDebug("uid %s ", (*it).uid().latin1()); | 985 | qDebug("uid %s ", (*it).uid().latin1()); |
975 | } | 986 | } |
976 | #endif | 987 | #endif |
977 | } | 988 | } |
978 | 989 | ||
979 | #if 0 | 990 | #if 0 |
980 | Addressee::List AddressBook::getExternLastSyncAddressees() | 991 | Addressee::List AddressBook::getExternLastSyncAddressees() |
981 | { | 992 | { |
982 | Addressee::List results; | 993 | Addressee::List results; |
983 | 994 | ||
984 | Iterator it; | 995 | Iterator it; |
985 | for ( it = begin(); it != end(); ++it ) { | 996 | for ( it = begin(); it != end(); ++it ) { |
986 | if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { | 997 | if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { |
987 | if ( (*it).familyName().left(4) == "!E: " ) | 998 | if ( (*it).familyName().left(4) == "!E: " ) |
988 | results.append( *it ); | 999 | results.append( *it ); |
989 | } | 1000 | } |
990 | } | 1001 | } |
991 | 1002 | ||
992 | return results; | 1003 | return results; |
993 | } | 1004 | } |
994 | #endif | 1005 | #endif |
995 | void AddressBook::resetTempSyncStat() | 1006 | void AddressBook::resetTempSyncStat() |
996 | { | 1007 | { |
997 | Iterator it; | 1008 | Iterator it; |
998 | for ( it = begin(); it != end(); ++it ) { | 1009 | for ( it = begin(); it != end(); ++it ) { |
999 | (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); | 1010 | (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); |
1000 | } | 1011 | } |
1001 | 1012 | ||
1002 | } | 1013 | } |
1003 | 1014 | ||
1004 | QStringList AddressBook:: uidList() | 1015 | QStringList AddressBook:: uidList() |
1005 | { | 1016 | { |
1006 | QStringList results; | 1017 | QStringList results; |
1007 | Iterator it; | 1018 | Iterator it; |
1008 | for ( it = begin(); it != end(); ++it ) { | 1019 | for ( it = begin(); it != end(); ++it ) { |
1009 | results.append( (*it).uid() ); | 1020 | results.append( (*it).uid() ); |
1010 | } | 1021 | } |
1011 | return results; | 1022 | return results; |
1012 | } | 1023 | } |
1013 | 1024 | ||
1014 | 1025 | ||
1015 | Addressee::List AddressBook::allAddressees() | 1026 | Addressee::List AddressBook::allAddressees() |
1016 | { | 1027 | { |
1017 | return d->mAddressees; | 1028 | return d->mAddressees; |
1018 | 1029 | ||
1019 | } | 1030 | } |
1020 | 1031 | ||
1021 | Addressee::List AddressBook::findByName( const QString &name ) | 1032 | Addressee::List AddressBook::findByName( const QString &name ) |
1022 | { | 1033 | { |
1023 | Addressee::List results; | 1034 | Addressee::List results; |
1024 | 1035 | ||
1025 | Iterator it; | 1036 | Iterator it; |
1026 | for ( it = begin(); it != end(); ++it ) { | 1037 | for ( it = begin(); it != end(); ++it ) { |
1027 | if ( name == (*it).realName() ) { | 1038 | if ( name == (*it).realName() ) { |
1028 | results.append( *it ); | 1039 | results.append( *it ); |
1029 | } | 1040 | } |
1030 | } | 1041 | } |
1031 | 1042 | ||
1032 | return results; | 1043 | return results; |
1033 | } | 1044 | } |
1034 | 1045 | ||
1035 | Addressee::List AddressBook::findByEmail( const QString &email ) | 1046 | Addressee::List AddressBook::findByEmail( const QString &email ) |
1036 | { | 1047 | { |
1037 | Addressee::List results; | 1048 | Addressee::List results; |
1038 | QStringList mailList; | 1049 | QStringList mailList; |
1039 | 1050 | ||
1040 | Iterator it; | 1051 | Iterator it; |
1041 | for ( it = begin(); it != end(); ++it ) { | 1052 | for ( it = begin(); it != end(); ++it ) { |
1042 | mailList = (*it).emails(); | 1053 | mailList = (*it).emails(); |
1043 | for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { | 1054 | for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { |
1044 | if ( email == (*ite) ) { | 1055 | if ( email == (*ite) ) { |
1045 | results.append( *it ); | 1056 | results.append( *it ); |
1046 | } | 1057 | } |
1047 | } | 1058 | } |
1048 | } | 1059 | } |
1049 | 1060 | ||
1050 | return results; | 1061 | return results; |
1051 | } | 1062 | } |
1052 | 1063 | ||
1053 | Addressee::List AddressBook::findByCategory( const QString &category ) | 1064 | Addressee::List AddressBook::findByCategory( const QString &category ) |
1054 | { | 1065 | { |
1055 | Addressee::List results; | 1066 | Addressee::List results; |
1056 | 1067 | ||
1057 | Iterator it; | 1068 | Iterator it; |
1058 | for ( it = begin(); it != end(); ++it ) { | 1069 | for ( it = begin(); it != end(); ++it ) { |
1059 | if ( (*it).hasCategory( category) ) { | 1070 | if ( (*it).hasCategory( category) ) { |
1060 | results.append( *it ); | 1071 | results.append( *it ); |
1061 | } | 1072 | } |
1062 | } | 1073 | } |
1063 | 1074 | ||
1064 | return results; | 1075 | return results; |
1065 | } | 1076 | } |
1066 | 1077 | ||
1067 | void AddressBook::dump() const | 1078 | void AddressBook::dump() const |
1068 | { | 1079 | { |
1069 | kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; | 1080 | kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; |
1070 | 1081 | ||
1071 | ConstIterator it; | 1082 | ConstIterator it; |
1072 | for( it = begin(); it != end(); ++it ) { | 1083 | for( it = begin(); it != end(); ++it ) { |
1073 | (*it).dump(); | 1084 | (*it).dump(); |
1074 | } | 1085 | } |
1075 | 1086 | ||
1076 | kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; | 1087 | kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; |
1077 | } | 1088 | } |
1078 | 1089 | ||
1079 | QString AddressBook::identifier() | 1090 | QString AddressBook::identifier() |
1080 | { | 1091 | { |
1081 | QStringList identifier; | 1092 | QStringList identifier; |
1082 | 1093 | ||
1083 | 1094 | ||
1084 | KRES::Manager<Resource>::ActiveIterator it; | 1095 | KRES::Manager<Resource>::ActiveIterator it; |
1085 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 1096 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
1086 | if ( !(*it)->identifier().isEmpty() ) | 1097 | if ( !(*it)->identifier().isEmpty() ) |
1087 | identifier.append( (*it)->identifier() ); | 1098 | identifier.append( (*it)->identifier() ); |
1088 | } | 1099 | } |
1089 | 1100 | ||
1090 | return identifier.join( ":" ); | 1101 | return identifier.join( ":" ); |
1091 | } | 1102 | } |
1092 | 1103 | ||
1093 | Field::List AddressBook::fields( int category ) | 1104 | Field::List AddressBook::fields( int category ) |
1094 | { | 1105 | { |
1095 | if ( d->mAllFields.isEmpty() ) { | 1106 | if ( d->mAllFields.isEmpty() ) { |
1096 | d->mAllFields = Field::allFields(); | 1107 | d->mAllFields = Field::allFields(); |
1097 | } | 1108 | } |
1098 | 1109 | ||
1099 | if ( category == Field::All ) return d->mAllFields; | 1110 | if ( category == Field::All ) return d->mAllFields; |
1100 | 1111 | ||
1101 | Field::List result; | 1112 | Field::List result; |
1102 | Field::List::ConstIterator it; | 1113 | Field::List::ConstIterator it; |
1103 | for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { | 1114 | for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { |
1104 | if ( (*it)->category() & category ) result.append( *it ); | 1115 | if ( (*it)->category() & category ) result.append( *it ); |
1105 | } | 1116 | } |
1106 | 1117 | ||
1107 | return result; | 1118 | return result; |
1108 | } | 1119 | } |
1109 | 1120 | ||
1110 | bool AddressBook::addCustomField( const QString &label, int category, | 1121 | bool AddressBook::addCustomField( const QString &label, int category, |
1111 | const QString &key, const QString &app ) | 1122 | const QString &key, const QString &app ) |
1112 | { | 1123 | { |
1113 | if ( d->mAllFields.isEmpty() ) { | 1124 | if ( d->mAllFields.isEmpty() ) { |
1114 | d->mAllFields = Field::allFields(); | 1125 | d->mAllFields = Field::allFields(); |
1115 | } | 1126 | } |
1116 | //US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; | 1127 | //US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; |
1117 | QString a = app.isNull() ? KGlobal::getAppName() : app; | 1128 | QString a = app.isNull() ? KGlobal::getAppName() : app; |
1118 | 1129 | ||
1119 | QString k = key.isNull() ? label : key; | 1130 | QString k = key.isNull() ? label : key; |
1120 | 1131 | ||
1121 | Field *field = Field::createCustomField( label, category, k, a ); | 1132 | Field *field = Field::createCustomField( label, category, k, a ); |
1122 | 1133 | ||
1123 | if ( !field ) return false; | 1134 | if ( !field ) return false; |
1124 | 1135 | ||
1125 | d->mAllFields.append( field ); | 1136 | d->mAllFields.append( field ); |
1126 | 1137 | ||
1127 | return true; | 1138 | return true; |
1128 | } | 1139 | } |
1129 | 1140 | ||
1130 | QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) | 1141 | QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) |
1131 | { | 1142 | { |
1132 | if (!ab.d) return s; | 1143 | if (!ab.d) return s; |
1133 | 1144 | ||
1134 | return s << ab.d->mAddressees; | 1145 | return s << ab.d->mAddressees; |
1135 | } | 1146 | } |
1136 | 1147 | ||
1137 | QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) | 1148 | QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) |
1138 | { | 1149 | { |
1139 | if (!ab.d) return s; | 1150 | if (!ab.d) return s; |
1140 | 1151 | ||
1141 | s >> ab.d->mAddressees; | 1152 | s >> ab.d->mAddressees; |
1142 | 1153 | ||
1143 | return s; | 1154 | return s; |
1144 | } | 1155 | } |
1145 | 1156 | ||
1146 | bool AddressBook::addResource( Resource *resource ) | 1157 | bool AddressBook::addResource( Resource *resource ) |
1147 | { | 1158 | { |
1148 | if ( !resource->open() ) { | 1159 | if ( !resource->open() ) { |
1149 | kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; | 1160 | kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; |
1150 | return false; | 1161 | return false; |
1151 | } | 1162 | } |
1152 | 1163 | ||
1153 | resource->setAddressBook( this ); | 1164 | resource->setAddressBook( this ); |
1154 | 1165 | ||
1155 | d->mManager->add( resource ); | 1166 | d->mManager->add( resource ); |
1156 | return true; | 1167 | return true; |
1157 | } | 1168 | } |
1158 | 1169 | ||
1159 | bool AddressBook::removeResource( Resource *resource ) | 1170 | bool AddressBook::removeResource( Resource *resource ) |
1160 | { | 1171 | { |
1161 | resource->close(); | 1172 | resource->close(); |
1162 | 1173 | ||
1163 | if ( resource == standardResource() ) | 1174 | if ( resource == standardResource() ) |
1164 | d->mManager->setStandardResource( 0 ); | 1175 | d->mManager->setStandardResource( 0 ); |
1165 | 1176 | ||
1166 | resource->setAddressBook( 0 ); | 1177 | resource->setAddressBook( 0 ); |
1167 | 1178 | ||
1168 | d->mManager->remove( resource ); | 1179 | d->mManager->remove( resource ); |
1169 | return true; | 1180 | return true; |
1170 | } | 1181 | } |
1171 | 1182 | ||
1172 | QPtrList<Resource> AddressBook::resources() | 1183 | QPtrList<Resource> AddressBook::resources() |
1173 | { | 1184 | { |
1174 | QPtrList<Resource> list; | 1185 | QPtrList<Resource> list; |
1175 | 1186 | ||
1176 | // qDebug("AddressBook::resources() 1"); | 1187 | // qDebug("AddressBook::resources() 1"); |
1177 | 1188 | ||
1178 | KRES::Manager<Resource>::ActiveIterator it; | 1189 | KRES::Manager<Resource>::ActiveIterator it; |
1179 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) | 1190 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) |
1180 | list.append( *it ); | 1191 | list.append( *it ); |
1181 | 1192 | ||
1182 | return list; | 1193 | return list; |
1183 | } | 1194 | } |
1184 | 1195 | ||
1185 | /*US | 1196 | /*US |
1186 | void AddressBook::setErrorHandler( ErrorHandler *handler ) | 1197 | void AddressBook::setErrorHandler( ErrorHandler *handler ) |
1187 | { | 1198 | { |
1188 | delete d->mErrorHandler; | 1199 | delete d->mErrorHandler; |
1189 | d->mErrorHandler = handler; | 1200 | d->mErrorHandler = handler; |
1190 | } | 1201 | } |
1191 | */ | 1202 | */ |
1192 | 1203 | ||
1193 | void AddressBook::error( const QString& msg ) | 1204 | void AddressBook::error( const QString& msg ) |
1194 | { | 1205 | { |
1195 | /*US | 1206 | /*US |
1196 | if ( !d->mErrorHandler ) // create default error handler | 1207 | if ( !d->mErrorHandler ) // create default error handler |
1197 | d->mErrorHandler = new ConsoleErrorHandler; | 1208 | d->mErrorHandler = new ConsoleErrorHandler; |
1198 | 1209 | ||
1199 | if ( d->mErrorHandler ) | 1210 | if ( d->mErrorHandler ) |
1200 | d->mErrorHandler->error( msg ); | 1211 | d->mErrorHandler->error( msg ); |
1201 | else | 1212 | else |
1202 | kdError(5700) << "no error handler defined" << endl; | 1213 | kdError(5700) << "no error handler defined" << endl; |
1203 | */ | 1214 | */ |
1204 | kdDebug(5700) << "msg" << endl; | 1215 | kdDebug(5700) << "msg" << endl; |
1205 | qDebug(msg); | 1216 | qDebug(msg); |
1206 | } | 1217 | } |
1207 | 1218 | ||
1208 | void AddressBook::deleteRemovedAddressees() | 1219 | void AddressBook::deleteRemovedAddressees() |
1209 | { | 1220 | { |
1210 | Addressee::List::Iterator it; | 1221 | Addressee::List::Iterator it; |
1211 | for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { | 1222 | for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { |
1212 | Resource *resource = (*it).resource(); | 1223 | Resource *resource = (*it).resource(); |
1213 | if ( resource && !resource->readOnly() && resource->isOpen() ) | 1224 | if ( resource && !resource->readOnly() && resource->isOpen() ) |
1214 | resource->removeAddressee( *it ); | 1225 | resource->removeAddressee( *it ); |
1215 | } | 1226 | } |
1216 | 1227 | ||
1217 | d->mRemovedAddressees.clear(); | 1228 | d->mRemovedAddressees.clear(); |
1218 | } | 1229 | } |
1219 | 1230 | ||
1220 | void AddressBook::setStandardResource( Resource *resource ) | 1231 | void AddressBook::setStandardResource( Resource *resource ) |
1221 | { | 1232 | { |
1222 | // qDebug("AddressBook::setStandardResource 1"); | 1233 | // qDebug("AddressBook::setStandardResource 1"); |
1223 | d->mManager->setStandardResource( resource ); | 1234 | d->mManager->setStandardResource( resource ); |
1224 | } | 1235 | } |
1225 | 1236 | ||
1226 | Resource *AddressBook::standardResource() | 1237 | Resource *AddressBook::standardResource() |
1227 | { | 1238 | { |
1228 | return d->mManager->standardResource(); | 1239 | return d->mManager->standardResource(); |
1229 | } | 1240 | } |
1230 | 1241 | ||
1231 | KRES::Manager<Resource> *AddressBook::resourceManager() | 1242 | KRES::Manager<Resource> *AddressBook::resourceManager() |
1232 | { | 1243 | { |
1233 | return d->mManager; | 1244 | return d->mManager; |
1234 | } | 1245 | } |
1235 | 1246 | ||
1236 | void AddressBook::cleanUp() | 1247 | void AddressBook::cleanUp() |
1237 | { | 1248 | { |
1238 | KRES::Manager<Resource>::ActiveIterator it; | 1249 | KRES::Manager<Resource>::ActiveIterator it; |
1239 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 1250 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
1240 | if ( !(*it)->readOnly() && (*it)->isOpen() ) | 1251 | if ( !(*it)->readOnly() && (*it)->isOpen() ) |
1241 | (*it)->cleanUp(); | 1252 | (*it)->cleanUp(); |
1242 | } | 1253 | } |
1243 | } | 1254 | } |
diff --git a/kabc/addressbook.h b/kabc/addressbook.h index f124dc9..75f8b51 100644 --- a/kabc/addressbook.h +++ b/kabc/addressbook.h | |||
@@ -1,349 +1,349 @@ | |||
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 removeSyncInfo( QString syncProfile); | 147 | void removeSyncInfo( QString syncProfile); |
148 | void preparePhoneSync( QString currentSyncDevice, bool isPreSync ); | 148 | void preparePhoneSync( QString currentSyncDevice, bool isPreSync ); |
149 | void export2File( QString fileName ); | 149 | void export2File( QString fileName ); |
150 | bool export2PhoneFormat( QStringList uids ,QString fileName ); | 150 | bool export2PhoneFormat( QStringList uids ,QString fileName ); |
151 | int importFromFile( QString fileName, bool replaceLabel = false, bool removeOld = false ); | 151 | int importFromFile( QString fileName, bool replaceLabel = false, bool removeOld = false ); |
152 | void setUntagged( bool setNonSyncTagged = false ); | 152 | void setUntagged( bool setNonSyncTagged = false ); |
153 | void removeUntagged(); | 153 | void removeUntagged(); |
154 | void findNewExtIds( QString fileName, QString currentSyncDevice ); | 154 | void findNewExtIds( QString fileName, QString currentSyncDevice ); |
155 | /** | 155 | /** |
156 | Returns a iterator for first entry of address book. | 156 | Returns a iterator for first entry of address book. |
157 | */ | 157 | */ |
158 | Iterator begin(); | 158 | Iterator begin(); |
159 | 159 | ||
160 | /** | 160 | /** |
161 | Returns a const iterator for first entry of address book. | 161 | Returns a const iterator for first entry of address book. |
162 | */ | 162 | */ |
163 | ConstIterator begin() const; | 163 | ConstIterator begin() const; |
164 | 164 | ||
165 | /** | 165 | /** |
166 | Returns a iterator for first entry of address book. | 166 | Returns a iterator for first entry of address book. |
167 | */ | 167 | */ |
168 | Iterator end(); | 168 | Iterator end(); |
169 | 169 | ||
170 | /** | 170 | /** |
171 | Returns a const iterator for first entry of address book. | 171 | Returns a const iterator for first entry of address book. |
172 | */ | 172 | */ |
173 | ConstIterator end() const; | 173 | ConstIterator end() const; |
174 | 174 | ||
175 | /** | 175 | /** |
176 | Removes all entries from address book. | 176 | Removes all entries from address book. |
177 | */ | 177 | */ |
178 | void clear(); | 178 | void clear(); |
179 | 179 | ||
180 | /** | 180 | /** |
181 | Insert an Addressee object into address book. If an object with the same | 181 | Insert an Addressee object into address book. If an object with the same |
182 | unique id already exists in the address book it it replaced by the new | 182 | unique id already exists in the address book it it replaced by the new |
183 | one. If not the new object is appended to the address book. | 183 | one. If not the new object is appended to the address book. |
184 | */ | 184 | */ |
185 | void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); | 185 | void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); |
186 | 186 | ||
187 | /** | 187 | /** |
188 | Removes entry from the address book. | 188 | Removes entry from the address book. |
189 | */ | 189 | */ |
190 | void removeAddressee( const Addressee & ); | 190 | void removeAddressee( const Addressee & ); |
191 | 191 | ||
192 | /** | 192 | /** |
193 | This is like @ref removeAddressee() just above, with the difference that | 193 | This is like @ref removeAddressee() just above, with the difference that |
194 | the first element is a iterator, returned by @ref begin(). | 194 | the first element is a iterator, returned by @ref begin(). |
195 | */ | 195 | */ |
196 | void removeAddressee( const Iterator & ); | 196 | void removeAddressee( const Iterator & ); |
197 | 197 | ||
198 | /** | 198 | /** |
199 | Find the specified entry in address book. Returns end(), if the entry | 199 | Find the specified entry in address book. Returns end(), if the entry |
200 | couldn't be found. | 200 | couldn't be found. |
201 | */ | 201 | */ |
202 | Iterator find( const Addressee & ); | 202 | Iterator find( const Addressee & ); |
203 | 203 | ||
204 | /** | 204 | /** |
205 | Find the entry specified by an unique id. Returns an empty Addressee | 205 | Find the entry specified by an unique id. Returns an empty Addressee |
206 | object, if the address book does not contain an entry with this id. | 206 | object, if the address book does not contain an entry with this id. |
207 | */ | 207 | */ |
208 | Addressee findByUid( const QString & ); | 208 | Addressee findByUid( const QString & ); |
209 | 209 | ||
210 | 210 | ||
211 | /** | 211 | /** |
212 | Returns a list of all addressees in the address book. This list can | 212 | Returns a list of all addressees in the address book. This list can |
213 | be sorted with @ref KABC::AddresseeList for example. | 213 | be sorted with @ref KABC::AddresseeList for example. |
214 | */ | 214 | */ |
215 | Addressee::List allAddressees(); | 215 | Addressee::List allAddressees(); |
216 | 216 | ||
217 | /** | 217 | /** |
218 | Find all entries with the specified name in the address book. Returns | 218 | Find all entries with the specified name in the address book. Returns |
219 | an empty list, if no entries could be found. | 219 | an empty list, if no entries could be found. |
220 | */ | 220 | */ |
221 | Addressee::List findByName( const QString & ); | 221 | Addressee::List findByName( const QString & ); |
222 | 222 | ||
223 | /** | 223 | /** |
224 | Find all entries with the specified email address in the address book. | 224 | Find all entries with the specified email address in the address book. |
225 | Returns an empty list, if no entries could be found. | 225 | Returns an empty list, if no entries could be found. |
226 | */ | 226 | */ |
227 | Addressee::List findByEmail( const QString & ); | 227 | Addressee::List findByEmail( const QString & ); |
228 | 228 | ||
229 | /** | 229 | /** |
230 | Find all entries wich have the specified category in the address book. | 230 | Find all entries wich have the specified category in the address book. |
231 | Returns an empty list, if no entries could be found. | 231 | Returns an empty list, if no entries could be found. |
232 | */ | 232 | */ |
233 | Addressee::List findByCategory( const QString & ); | 233 | Addressee::List findByCategory( const QString & ); |
234 | 234 | ||
235 | /** | 235 | /** |
236 | Return a string identifying this addressbook. | 236 | Return a string identifying this addressbook. |
237 | */ | 237 | */ |
238 | virtual QString identifier(); | 238 | virtual QString identifier(); |
239 | 239 | ||
240 | /** | 240 | /** |
241 | Used for debug output. | 241 | Used for debug output. |
242 | */ | 242 | */ |
243 | void dump() const; | 243 | void dump() const; |
244 | 244 | ||
245 | void emitAddressBookLocked() { emit addressBookLocked( this ); } | 245 | void emitAddressBookLocked() { emit addressBookLocked( this ); } |
246 | void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); } | 246 | void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); } |
247 | void emitAddressBookChanged() { emit addressBookChanged( this ); } | 247 | void emitAddressBookChanged() { emit addressBookChanged( this ); } |
248 | 248 | ||
249 | /** | 249 | /** |
250 | Return list of all Fields known to the address book which are associated | 250 | Return list of all Fields known to the address book which are associated |
251 | with the given field category. | 251 | with the given field category. |
252 | */ | 252 | */ |
253 | Field::List fields( int category = Field::All ); | 253 | Field::List fields( int category = Field::All ); |
254 | 254 | ||
255 | /** | 255 | /** |
256 | Add custom field to address book. | 256 | Add custom field to address book. |
257 | 257 | ||
258 | @param label User visible label of the field. | 258 | @param label User visible label of the field. |
259 | @param category Ored list of field categories. | 259 | @param category Ored list of field categories. |
260 | @param key Identifier used as key for reading and writing the field. | 260 | @param key Identifier used as key for reading and writing the field. |
261 | @param app String used as application key for reading and writing | 261 | @param app String used as application key for reading and writing |
262 | the field. | 262 | the field. |
263 | */ | 263 | */ |
264 | bool addCustomField( const QString &label, int category = Field::All, | 264 | bool addCustomField( const QString &label, int category = Field::All, |
265 | const QString &key = QString::null, | 265 | const QString &key = QString::null, |
266 | const QString &app = QString::null ); | 266 | const QString &app = QString::null ); |
267 | 267 | ||
268 | 268 | ||
269 | /** | 269 | /** |
270 | Add address book resource. | 270 | Add address book resource. |
271 | */ | 271 | */ |
272 | bool addResource( Resource * ); | 272 | bool addResource( Resource * ); |
273 | 273 | ||
274 | /** | 274 | /** |
275 | Remove address book resource. | 275 | Remove address book resource. |
276 | */ | 276 | */ |
277 | bool removeResource( Resource * ); | 277 | bool removeResource( Resource * ); |
278 | 278 | ||
279 | /** | 279 | /** |
280 | Return pointer list of all resources. | 280 | Return pointer list of all resources. |
281 | */ | 281 | */ |
282 | QPtrList<Resource> resources(); | 282 | QPtrList<Resource> resources(); |
283 | 283 | ||
284 | /** | 284 | /** |
285 | Set the @p ErrorHandler, that is used by @ref error() to | 285 | Set the @p ErrorHandler, that is used by @ref error() to |
286 | provide gui-independend error messages. | 286 | provide gui-independend error messages. |
287 | */ | 287 | */ |
288 | void setErrorHandler( ErrorHandler * ); | 288 | void setErrorHandler( ErrorHandler * ); |
289 | 289 | ||
290 | /** | 290 | /** |
291 | Shows gui independend error messages. | 291 | Shows gui independend error messages. |
292 | */ | 292 | */ |
293 | void error( const QString& ); | 293 | void error( const QString& ); |
294 | 294 | ||
295 | /** | 295 | /** |
296 | Query all resources to clean up their lock files | 296 | Query all resources to clean up their lock files |
297 | */ | 297 | */ |
298 | void cleanUp(); | 298 | void cleanUp(); |
299 | 299 | ||
300 | // sync stuff | 300 | // sync stuff |
301 | //Addressee::List getExternLastSyncAddressees(); | 301 | //Addressee::List getExternLastSyncAddressees(); |
302 | void resetTempSyncStat(); | 302 | void resetTempSyncStat(); |
303 | QStringList uidList(); | 303 | QStringList uidList(); |
304 | void removeSyncAddressees( bool removeDeleted = false ); | 304 | void removeSyncAddressees( bool removeDeleted = false ); |
305 | void mergeAB( AddressBook *aBook, const QString& profile, bool isSubset ); | 305 | void mergeAB( AddressBook *aBook, const QString& profile, bool isSubset ); |
306 | Addressee findByExternUid( const QString& uid , const QString& profile ); | 306 | Addressee findByExternUid( const QString& uid , const QString& profile ); |
307 | bool containsExternalUid( const QString& uid ); | 307 | bool containsExternalUid( const QString& uid ); |
308 | 308 | ||
309 | void preExternSync( AddressBook* aBook, const QString& csd, bool isSubset ); | 309 | void preExternSync( AddressBook* aBook, const QString& csd, bool isSubset ); |
310 | void postExternSync( AddressBook* aBook, const QString& csd ); | 310 | void postExternSync( AddressBook* aBook, const QString& csd , bool setID ); |
311 | signals: | 311 | signals: |
312 | /** | 312 | /** |
313 | Emitted, when the address book has changed on disk. | 313 | Emitted, when the address book has changed on disk. |
314 | */ | 314 | */ |
315 | void addressBookChanged( AddressBook * ); | 315 | void addressBookChanged( AddressBook * ); |
316 | 316 | ||
317 | /** | 317 | /** |
318 | Emitted, when the address book has been locked for writing. | 318 | Emitted, when the address book has been locked for writing. |
319 | */ | 319 | */ |
320 | void addressBookLocked( AddressBook * ); | 320 | void addressBookLocked( AddressBook * ); |
321 | 321 | ||
322 | /** | 322 | /** |
323 | Emitted, when the address book has been unlocked. | 323 | Emitted, when the address book has been unlocked. |
324 | */ | 324 | */ |
325 | void addressBookUnlocked( AddressBook * ); | 325 | void addressBookUnlocked( AddressBook * ); |
326 | 326 | ||
327 | protected: | 327 | protected: |
328 | void deleteRemovedAddressees(); | 328 | void deleteRemovedAddressees(); |
329 | void setStandardResource( Resource * ); | 329 | void setStandardResource( Resource * ); |
330 | Resource *standardResource(); | 330 | Resource *standardResource(); |
331 | KRES::Manager<Resource> *resourceManager(); | 331 | KRES::Manager<Resource> *resourceManager(); |
332 | 332 | ||
333 | void init(const QString &config, const QString &family); | 333 | void init(const QString &config, const QString &family); |
334 | 334 | ||
335 | private: | 335 | private: |
336 | //US QPtrList<Resource> mDummy; // Remove in KDE 4 | 336 | //US QPtrList<Resource> mDummy; // Remove in KDE 4 |
337 | 337 | ||
338 | 338 | ||
339 | struct AddressBookData; | 339 | struct AddressBookData; |
340 | AddressBookData *d; | 340 | AddressBookData *d; |
341 | bool blockLSEchange; | 341 | bool blockLSEchange; |
342 | }; | 342 | }; |
343 | 343 | ||
344 | QDataStream &operator<<( QDataStream &, const AddressBook & ); | 344 | QDataStream &operator<<( QDataStream &, const AddressBook & ); |
345 | QDataStream &operator>>( QDataStream &, AddressBook & ); | 345 | QDataStream &operator>>( QDataStream &, AddressBook & ); |
346 | 346 | ||
347 | } | 347 | } |
348 | 348 | ||
349 | #endif | 349 | #endif |
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index a660a9d..d5a110a 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp | |||
@@ -1,653 +1,653 @@ | |||
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 | 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 | (*it).setNumber( ( *phoneItAD ).number() ); | 313 | (*it).setNumber( ( *phoneItAD ).number() ); |
314 | break; | 314 | break; |
315 | } | 315 | } |
316 | } | 316 | } |
317 | if ( isSubSet && ! found ) | 317 | if ( isSubSet && ! found ) |
318 | mData->phoneNumbers.append( *phoneItAD ); | 318 | mData->phoneNumbers.append( *phoneItAD ); |
319 | } | 319 | } |
320 | if ( isSubSet ) { | 320 | if ( isSubSet ) { |
321 | // ************* emails; | 321 | // ************* emails; |
322 | t = mData->emails; | 322 | t = mData->emails; |
323 | tAD = ad.mData->emails; | 323 | tAD = ad.mData->emails; |
324 | for ( iii = 0; iii < tAD.count(); ++iii) | 324 | for ( iii = 0; iii < tAD.count(); ++iii) |
325 | if ( !t.contains(tAD[iii] ) ) | 325 | if ( !t.contains(tAD[iii] ) ) |
326 | mData->emails.append( tAD[iii] ); | 326 | mData->emails.append( tAD[iii] ); |
327 | } | 327 | } |
328 | 328 | ||
329 | // ************* categories; | 329 | // ************* categories; |
330 | t = mData->categories; | 330 | t = mData->categories; |
331 | tAD = ad.mData->categories; | 331 | tAD = ad.mData->categories; |
332 | for ( iii = 0; iii < tAD.count(); ++iii) | 332 | for ( iii = 0; iii < tAD.count(); ++iii) |
333 | if ( !t.contains(tAD[iii] ) ) | 333 | if ( !t.contains(tAD[iii] ) ) |
334 | mData->categories.append( tAD[iii] ); | 334 | mData->categories.append( tAD[iii] ); |
335 | QStringList::ConstIterator it; | 335 | QStringList::ConstIterator it; |
336 | for( it = ad.mData->custom.begin(); it != ad.mData->custom.end(); ++it ) { | 336 | for( it = ad.mData->custom.begin(); it != ad.mData->custom.end(); ++it ) { |
337 | QString qualifiedName = (*it).left( (*it).find( ":" )); | 337 | QString qualifiedName = (*it).left( (*it).find( ":" )); |
338 | bool found = false; | 338 | bool found = false; |
339 | QStringList::ConstIterator itL; | 339 | QStringList::ConstIterator itL; |
340 | for( itL = mData->custom.begin(); itL != mData->custom.end(); ++itL ) { | 340 | for( itL = mData->custom.begin(); itL != mData->custom.end(); ++itL ) { |
341 | if ( (*itL).startsWith( qualifiedName ) ) { | 341 | if ( (*itL).startsWith( qualifiedName ) ) { |
342 | found = true; | 342 | found = true; |
343 | break; | 343 | break; |
344 | } | 344 | } |
345 | } | 345 | } |
346 | if ( ! found ) { | 346 | if ( ! found ) { |
347 | mData->custom.append( *it ); | 347 | mData->custom.append( *it ); |
348 | } | 348 | } |
349 | } | 349 | } |
350 | if ( mData->logo.undefined() && !ad.mData->logo.undefined() ) mData->logo = ad.mData->logo; | 350 | 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; | 351 | if ( mData->photo.undefined() && !ad.mData->photo.undefined() ) mData->photo = ad.mData->photo; |
352 | if ( !mData->sound.isIntern() ) { | 352 | if ( !mData->sound.isIntern() ) { |
353 | if ( mData->sound.url().isEmpty() ) { | 353 | if ( mData->sound.url().isEmpty() ) { |
354 | mData->sound = ad.mData->sound; | 354 | mData->sound = ad.mData->sound; |
355 | } | 355 | } |
356 | } | 356 | } |
357 | if ( !mData->agent.isIntern() ) { | 357 | if ( !mData->agent.isIntern() ) { |
358 | if ( mData->agent.url().isEmpty() ) { | 358 | if ( mData->agent.url().isEmpty() ) { |
359 | mData->agent = ad.mData->agent; | 359 | mData->agent = ad.mData->agent; |
360 | } | 360 | } |
361 | } | 361 | } |
362 | { | 362 | { |
363 | Key::List::Iterator itA; | 363 | Key::List::Iterator itA; |
364 | for( itA = ad.mData->keys.begin(); itA != ad.mData->keys.end(); ++itA ) { | 364 | for( itA = ad.mData->keys.begin(); itA != ad.mData->keys.end(); ++itA ) { |
365 | bool found = false; | 365 | bool found = false; |
366 | Key::List::Iterator it; | 366 | Key::List::Iterator it; |
367 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { | 367 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { |
368 | if ( (*it) == (*itA)) { | 368 | if ( (*it) == (*itA)) { |
369 | found = true; | 369 | found = true; |
370 | break; | 370 | break; |
371 | 371 | ||
372 | } | 372 | } |
373 | } | 373 | } |
374 | if ( ! found ) { | 374 | if ( ! found ) { |
375 | mData->keys.append( *itA ); | 375 | mData->keys.append( *itA ); |
376 | } | 376 | } |
377 | } | 377 | } |
378 | } | 378 | } |
379 | KABC::Address::List::Iterator addressIterA; | 379 | KABC::Address::List::Iterator addressIterA; |
380 | for ( addressIterA = ad.mData->addresses.begin(); addressIterA != ad.mData->addresses.end(); ++addressIterA ) { | 380 | for ( addressIterA = ad.mData->addresses.begin(); addressIterA != ad.mData->addresses.end(); ++addressIterA ) { |
381 | bool found = false; | 381 | bool found = false; |
382 | KABC::Address::List::Iterator addressIter; | 382 | KABC::Address::List::Iterator addressIter; |
383 | for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); | 383 | for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); |
384 | ++addressIter ) { | 384 | ++addressIter ) { |
385 | if ( (*addressIter) == (*addressIterA)) { | 385 | if ( (*addressIter) == (*addressIterA)) { |
386 | found = true; | 386 | found = true; |
387 | (*addressIter).setType( (*addressIterA).type() ); | 387 | (*addressIter).setType( (*addressIterA).type() ); |
388 | break; | 388 | break; |
389 | } | 389 | } |
390 | 390 | ||
391 | } | 391 | } |
392 | if ( isSubSet && ! found ) { | 392 | if ( isSubSet && ! found ) { |
393 | mData->addresses.append( *addressIterA ); | 393 | mData->addresses.append( *addressIterA ); |
394 | } | 394 | } |
395 | } | 395 | } |
396 | //qDebug("merge contact %s ", ad.uid().latin1()); | 396 | //qDebug("merge contact %s ", ad.uid().latin1()); |
397 | setUid( ad.uid() ); | 397 | setUid( ad.uid() ); |
398 | setRevision( ad.revision() ); | 398 | setRevision( ad.revision() ); |
399 | } | 399 | } |
400 | 400 | ||
401 | bool Addressee::removeVoice() | 401 | bool Addressee::removeVoice() |
402 | { | 402 | { |
403 | PhoneNumber::List phoneN = phoneNumbers(); | 403 | PhoneNumber::List phoneN = phoneNumbers(); |
404 | PhoneNumber::List::Iterator phoneIt; | 404 | PhoneNumber::List::Iterator phoneIt; |
405 | bool found = false; | 405 | bool found = false; |
406 | for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { | 406 | for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { |
407 | if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found | 407 | if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found |
408 | if ((*phoneIt).type() - PhoneNumber::Voice ) { | 408 | if ((*phoneIt).type() - PhoneNumber::Voice ) { |
409 | (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice ); | 409 | (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice ); |
410 | insertPhoneNumber( (*phoneIt) ); | 410 | insertPhoneNumber( (*phoneIt) ); |
411 | found = true; | 411 | found = true; |
412 | } | 412 | } |
413 | } | 413 | } |
414 | 414 | ||
415 | } | 415 | } |
416 | return found; | 416 | return found; |
417 | } | 417 | } |
418 | 418 | ||
419 | bool Addressee::containsAdr(const Addressee& ad ) | 419 | bool Addressee::containsAdr(const Addressee& ad ) |
420 | { | 420 | { |
421 | if ( ! ad.mData->familyName.isEmpty() ) if ( mData->familyName != ad.mData->familyName) return false; | 421 | 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; | 422 | 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 ; | 423 | 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 ; | 424 | 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 ; | 425 | 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 ; | 426 | 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 ; | 427 | if ( ! ad.mData->title .isEmpty() ) if (mData->title != ad.mData->title ) return false ; |
428 | 428 | ||
429 | // compare phone numbers | 429 | // compare phone numbers |
430 | PhoneNumber::List phoneN = ad.phoneNumbers(); | 430 | PhoneNumber::List phoneN = ad.phoneNumbers(); |
431 | PhoneNumber::List::Iterator phoneIt; | 431 | PhoneNumber::List::Iterator phoneIt; |
432 | bool found = false; | 432 | bool found = false; |
433 | for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { | 433 | for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { |
434 | bool found = false; | 434 | bool found = false; |
435 | PhoneNumber::List phoneL = ad.phoneNumbers(); | 435 | PhoneNumber::List phoneL = ad.phoneNumbers(); |
436 | PhoneNumber::List::Iterator phoneItL; | 436 | PhoneNumber::List::Iterator phoneItL; |
437 | for ( phoneItL = phoneL.begin(); phoneItL != phoneL.end(); ++phoneItL ) { | 437 | for ( phoneItL = phoneL.begin(); phoneItL != phoneL.end(); ++phoneItL ) { |
438 | if ( ( *phoneItL ).number() == ( *phoneIt ).number() ) { | 438 | if ( ( *phoneItL ).number() == ( *phoneIt ).number() ) { |
439 | found = true; | 439 | found = true; |
440 | break; | 440 | break; |
441 | } | 441 | } |
442 | } | 442 | } |
443 | if ( ! found ) | 443 | if ( ! found ) |
444 | return false; | 444 | return false; |
445 | } | 445 | } |
446 | return true; | 446 | return true; |
447 | 447 | ||
448 | } | 448 | } |
449 | void Addressee::simplifyAddresses() | 449 | void Addressee::simplifyAddresses() |
450 | { | 450 | { |
451 | 451 | ||
452 | 452 | ||
453 | Address::List list; | 453 | Address::List list; |
454 | Address::List::Iterator it; | 454 | Address::List::Iterator it; |
455 | Address::List::Iterator it2; | 455 | Address::List::Iterator it2; |
456 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { | 456 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { |
457 | it2 = it; | 457 | it2 = it; |
458 | ++it2; | 458 | ++it2; |
459 | for( ; it2 != mData->addresses.end(); ++it2 ) { | 459 | for( ; it2 != mData->addresses.end(); ++it2 ) { |
460 | if ( (*it) == (*it2) ) { | 460 | if ( (*it) == (*it2) ) { |
461 | list.append( *it ); | 461 | list.append( *it ); |
462 | break; | 462 | break; |
463 | } | 463 | } |
464 | } | 464 | } |
465 | } | 465 | } |
466 | for( it = list.begin(); it != list.end(); ++it ) { | 466 | for( it = list.begin(); it != list.end(); ++it ) { |
467 | removeAddress( (*it) ); | 467 | removeAddress( (*it) ); |
468 | } | 468 | } |
469 | 469 | ||
470 | list.clear(); | 470 | list.clear(); |
471 | int max = 2; | 471 | int max = 2; |
472 | if ( mData->url.isValid() ) | 472 | if ( mData->url.isValid() ) |
473 | max = 1; | 473 | max = 1; |
474 | if ( mData->addresses.count() <= max ) return ; | 474 | if ( mData->addresses.count() <= max ) return ; |
475 | int count = 0; | 475 | int count = 0; |
476 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { | 476 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { |
477 | if ( count >= max ) | 477 | if ( count >= max ) |
478 | list.append( *it ); | 478 | list.append( *it ); |
479 | ++count; | 479 | ++count; |
480 | } | 480 | } |
481 | for( it = list.begin(); it != list.end(); ++it ) { | 481 | for( it = list.begin(); it != list.end(); ++it ) { |
482 | removeAddress( (*it) ); | 482 | removeAddress( (*it) ); |
483 | } | 483 | } |
484 | } | 484 | } |
485 | 485 | ||
486 | // removes all emails but the first | 486 | // removes all emails but the first |
487 | // needed by phone sync | 487 | // needed by phone sync |
488 | void Addressee::simplifyEmails() | 488 | void Addressee::simplifyEmails() |
489 | { | 489 | { |
490 | if ( mData->emails.count() == 0 ) return ; | 490 | if ( mData->emails.count() == 0 ) return ; |
491 | QString email = mData->emails.first(); | 491 | QString email = mData->emails.first(); |
492 | detach(); | 492 | detach(); |
493 | mData->emails.clear(); | 493 | mData->emails.clear(); |
494 | mData->emails.append( email ); | 494 | mData->emails.append( email ); |
495 | } | 495 | } |
496 | 496 | ||
497 | void Addressee::simplifyPhoneNumbers() | 497 | void Addressee::simplifyPhoneNumbers() |
498 | { | 498 | { |
499 | int max = 4; | 499 | int max = 4; |
500 | int inList = mData->phoneNumbers.count(); | 500 | int inList = mData->phoneNumbers.count(); |
501 | KABC::PhoneNumber::List removeNumbers; | 501 | KABC::PhoneNumber::List removeNumbers; |
502 | KABC::PhoneNumber::List::Iterator phoneIter; | 502 | KABC::PhoneNumber::List::Iterator phoneIter; |
503 | if ( inList > max ) { | 503 | if ( inList > max ) { |
504 | // delete non-preferred numbers | 504 | // delete non-preferred numbers |
505 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); | 505 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); |
506 | ++phoneIter ) { | 506 | ++phoneIter ) { |
507 | if ( inList > max ) { | 507 | if ( inList > max ) { |
508 | if ( ! (( *phoneIter ).type() & PhoneNumber::Pref )) { | 508 | if ( ! (( *phoneIter ).type() & PhoneNumber::Pref )) { |
509 | removeNumbers.append( ( *phoneIter ) ); | 509 | removeNumbers.append( ( *phoneIter ) ); |
510 | --inList; | 510 | --inList; |
511 | } | 511 | } |
512 | } else | 512 | } else |
513 | break; | 513 | break; |
514 | } | 514 | } |
515 | for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); | 515 | for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); |
516 | ++phoneIter ) { | 516 | ++phoneIter ) { |
517 | removePhoneNumber(( *phoneIter )); | 517 | removePhoneNumber(( *phoneIter )); |
518 | } | 518 | } |
519 | // delete preferred numbers | 519 | // delete preferred numbers |
520 | if ( inList > max ) { | 520 | if ( inList > max ) { |
521 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); | 521 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); |
522 | ++phoneIter ) { | 522 | ++phoneIter ) { |
523 | if ( inList > max ) { | 523 | if ( inList > max ) { |
524 | removeNumbers.append( ( *phoneIter ) ); | 524 | removeNumbers.append( ( *phoneIter ) ); |
525 | --inList; | 525 | --inList; |
526 | } else | 526 | } else |
527 | break; | 527 | break; |
528 | } | 528 | } |
529 | for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); | 529 | for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); |
530 | ++phoneIter ) { | 530 | ++phoneIter ) { |
531 | removePhoneNumber(( *phoneIter )); | 531 | removePhoneNumber(( *phoneIter )); |
532 | } | 532 | } |
533 | } | 533 | } |
534 | } | 534 | } |
535 | // remove non-numeric characters | 535 | // remove non-numeric characters |
536 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); | 536 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); |
537 | ++phoneIter ) { | 537 | ++phoneIter ) { |
538 | if ( ! ( *phoneIter ).simplifyNumber() ) | 538 | if ( ! ( *phoneIter ).simplifyNumber() ) |
539 | removeNumbers.append( ( *phoneIter ) ); | 539 | removeNumbers.append( ( *phoneIter ) ); |
540 | } | 540 | } |
541 | for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); | 541 | for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); |
542 | ++phoneIter ) { | 542 | ++phoneIter ) { |
543 | removePhoneNumber(( *phoneIter )); | 543 | removePhoneNumber(( *phoneIter )); |
544 | } | 544 | } |
545 | } | 545 | } |
546 | void Addressee::simplifyPhoneNumberTypes() | 546 | void Addressee::simplifyPhoneNumberTypes() |
547 | { | 547 | { |
548 | KABC::PhoneNumber::List::Iterator phoneIter; | 548 | KABC::PhoneNumber::List::Iterator phoneIter; |
549 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); | 549 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); |
550 | ++phoneIter ) | 550 | ++phoneIter ) |
551 | ( *phoneIter ).simplifyType(); | 551 | ( *phoneIter ).simplifyType(); |
552 | } | 552 | } |
553 | void Addressee::removeID(const QString &prof) | 553 | void Addressee::removeID(const QString &prof) |
554 | { | 554 | { |
555 | detach(); | 555 | detach(); |
556 | if ( prof.isEmpty() ) | 556 | if ( prof.isEmpty() ) |
557 | mData->mExternalId = ":"; | 557 | mData->mExternalId = ":"; |
558 | else | 558 | else |
559 | mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof); | 559 | mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof); |
560 | 560 | ||
561 | } | 561 | } |
562 | void Addressee::setID( const QString & prof , const QString & id ) | 562 | void Addressee::setID( const QString & prof , const QString & id ) |
563 | { | 563 | { |
564 | detach(); | 564 | detach(); |
565 | mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id ); | 565 | mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id ); |
566 | //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); | 566 | //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); |
567 | } | 567 | } |
568 | void Addressee::setTempSyncStat( int id ) | 568 | void Addressee::setTempSyncStat( int id ) |
569 | { | 569 | { |
570 | if ( mData->mTempSyncStat == id ) return; | 570 | if ( mData->mTempSyncStat == id ) return; |
571 | detach(); | 571 | detach(); |
572 | mData->mTempSyncStat = id; | 572 | mData->mTempSyncStat = id; |
573 | } | 573 | } |
574 | int Addressee::tempSyncStat() const | 574 | int Addressee::tempSyncStat() const |
575 | { | 575 | { |
576 | return mData->mTempSyncStat; | 576 | return mData->mTempSyncStat; |
577 | } | 577 | } |
578 | 578 | ||
579 | QString Addressee::getID( const QString & prof) | 579 | QString Addressee::getID( const QString & prof) |
580 | { | 580 | { |
581 | return KIdManager::getId ( mData->mExternalId, prof ); | 581 | return KIdManager::getId ( mData->mExternalId, prof ); |
582 | } | 582 | } |
583 | 583 | ||
584 | void Addressee::setCsum( const QString & prof , const QString & id ) | 584 | void Addressee::setCsum( const QString & prof , const QString & id ) |
585 | { | 585 | { |
586 | detach(); | 586 | detach(); |
587 | //qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); | 587 | //qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); |
588 | mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id ); | 588 | mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id ); |
589 | //qDebug("setcsum2 %s ",mData->mExternalId.latin1() ); | 589 | //qDebug("setcsum2 %s ",mData->mExternalId.latin1() ); |
590 | } | 590 | } |
591 | 591 | ||
592 | QString Addressee::getCsum( const QString & prof) | 592 | QString Addressee::getCsum( const QString & prof) |
593 | { | 593 | { |
594 | return KIdManager::getCsum ( mData->mExternalId, prof ); | 594 | return KIdManager::getCsum ( mData->mExternalId, prof ); |
595 | } | 595 | } |
596 | 596 | ||
597 | void Addressee::setIDStr( const QString & s ) | 597 | void Addressee::setIDStr( const QString & s ) |
598 | { | 598 | { |
599 | detach(); | 599 | detach(); |
600 | mData->mExternalId = s; | 600 | mData->mExternalId = s; |
601 | } | 601 | } |
602 | 602 | ||
603 | QString Addressee::IDStr() const | 603 | QString Addressee::IDStr() const |
604 | { | 604 | { |
605 | return mData->mExternalId; | 605 | return mData->mExternalId; |
606 | } | 606 | } |
607 | 607 | ||
608 | void Addressee::setExternalUID( const QString &id ) | 608 | void Addressee::setExternalUID( const QString &id ) |
609 | { | 609 | { |
610 | if ( id == mData->externalUID ) return; | 610 | if ( id == mData->externalUID ) return; |
611 | detach(); | 611 | detach(); |
612 | mData->empty = false; | 612 | mData->empty = false; |
613 | mData->externalUID = id; | 613 | mData->externalUID = id; |
614 | } | 614 | } |
615 | 615 | ||
616 | QString Addressee::externalUID() const | 616 | QString Addressee::externalUID() const |
617 | { | 617 | { |
618 | return mData->externalUID; | 618 | return mData->externalUID; |
619 | } | 619 | } |
620 | void Addressee::setOriginalExternalUID( const QString &id ) | 620 | void Addressee::setOriginalExternalUID( const QString &id ) |
621 | { | 621 | { |
622 | if ( id == mData->originalExternalUID ) return; | 622 | if ( id == mData->originalExternalUID ) return; |
623 | detach(); | 623 | detach(); |
624 | mData->empty = false; | 624 | mData->empty = false; |
625 | //qDebug("*******Set orig uid %s ", id.latin1()); | 625 | //qDebug("*******Set orig uid %s ", id.latin1()); |
626 | mData->originalExternalUID = id; | 626 | mData->originalExternalUID = id; |
627 | } | 627 | } |
628 | 628 | ||
629 | QString Addressee::originalExternalUID() const | 629 | QString Addressee::originalExternalUID() const |
630 | { | 630 | { |
631 | return mData->originalExternalUID; | 631 | return mData->originalExternalUID; |
632 | } | 632 | } |
633 | 633 | ||
634 | void Addressee::setUid( const QString &id ) | 634 | void Addressee::setUid( const QString &id ) |
635 | { | 635 | { |
636 | if ( id == mData->uid ) return; | 636 | if ( id == mData->uid ) return; |
637 | detach(); | 637 | detach(); |
638 | //qDebug("****setuid %s ", id.latin1()); | 638 | //qDebug("****setuid %s ", id.latin1()); |
639 | mData->empty = false; | 639 | mData->empty = false; |
640 | mData->uid = id; | 640 | mData->uid = id; |
641 | } | 641 | } |
642 | 642 | ||
643 | QString Addressee::uid() const | 643 | QString Addressee::uid() const |
644 | { | 644 | { |
645 | if ( mData->uid.isEmpty() ) | 645 | if ( mData->uid.isEmpty() ) |
646 | mData->uid = KApplication::randomString( 10 ); | 646 | mData->uid = KApplication::randomString( 10 ); |
647 | 647 | ||
648 | return mData->uid; | 648 | return mData->uid; |
649 | } | 649 | } |
650 | 650 | ||
651 | QString Addressee::uidLabel() | 651 | QString Addressee::uidLabel() |
652 | { | 652 | { |
653 | return i18n("Unique Identifier"); | 653 | return i18n("Unique Identifier"); |
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index ea87929..b0cb986 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp | |||
@@ -2132,804 +2132,806 @@ void KABCore::configureKeyBindings() | |||
2132 | } | 2132 | } |
2133 | 2133 | ||
2134 | #ifdef KAB_EMBEDDED | 2134 | #ifdef KAB_EMBEDDED |
2135 | void KABCore::configureResources() | 2135 | void KABCore::configureResources() |
2136 | { | 2136 | { |
2137 | KRES::KCMKResources dlg( this, "" , 0 ); | 2137 | KRES::KCMKResources dlg( this, "" , 0 ); |
2138 | 2138 | ||
2139 | if ( !dlg.exec() ) | 2139 | if ( !dlg.exec() ) |
2140 | return; | 2140 | return; |
2141 | KMessageBox::information( this, i18n("Please restart to get the \nchanged resources (re)loaded!\n") ); | 2141 | KMessageBox::information( this, i18n("Please restart to get the \nchanged resources (re)loaded!\n") ); |
2142 | } | 2142 | } |
2143 | #endif //KAB_EMBEDDED | 2143 | #endif //KAB_EMBEDDED |
2144 | 2144 | ||
2145 | 2145 | ||
2146 | /* this method will be called through the QCop interface from Ko/Pi to select addresses | 2146 | /* this method will be called through the QCop interface from Ko/Pi to select addresses |
2147 | * for the attendees list of an event. | 2147 | * for the attendees list of an event. |
2148 | */ | 2148 | */ |
2149 | void KABCore::requestForNameEmailUidList(const QString& sourceChannel, const QString& uid) | 2149 | void KABCore::requestForNameEmailUidList(const QString& sourceChannel, const QString& uid) |
2150 | { | 2150 | { |
2151 | QStringList nameList; | 2151 | QStringList nameList; |
2152 | QStringList emailList; | 2152 | QStringList emailList; |
2153 | QStringList uidList; | 2153 | QStringList uidList; |
2154 | 2154 | ||
2155 | KABC::Addressee::List list = KABC::AddresseeDialog::getAddressees(this); | 2155 | KABC::Addressee::List list = KABC::AddresseeDialog::getAddressees(this); |
2156 | uint i=0; | 2156 | uint i=0; |
2157 | for (i=0; i < list.count(); i++) | 2157 | for (i=0; i < list.count(); i++) |
2158 | { | 2158 | { |
2159 | nameList.append(list[i].realName()); | 2159 | nameList.append(list[i].realName()); |
2160 | emailList.append(list[i].preferredEmail()); | 2160 | emailList.append(list[i].preferredEmail()); |
2161 | uidList.append(list[i].uid()); | 2161 | uidList.append(list[i].uid()); |
2162 | } | 2162 | } |
2163 | 2163 | ||
2164 | bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI(sourceChannel, uid, nameList, emailList, uidList); | 2164 | bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI(sourceChannel, uid, nameList, emailList, uidList); |
2165 | 2165 | ||
2166 | } | 2166 | } |
2167 | 2167 | ||
2168 | /* this method will be called through the QCop interface from Ko/Pi to select birthdays | 2168 | /* this method will be called through the QCop interface from Ko/Pi to select birthdays |
2169 | * to put them into the calendar. | 2169 | * to put them into the calendar. |
2170 | */ | 2170 | */ |
2171 | void KABCore::requestForBirthdayList(const QString& sourceChannel, const QString& uid) | 2171 | void KABCore::requestForBirthdayList(const QString& sourceChannel, const QString& uid) |
2172 | { | 2172 | { |
2173 | // qDebug("KABCore::requestForBirthdayList"); | 2173 | // qDebug("KABCore::requestForBirthdayList"); |
2174 | QStringList birthdayList; | 2174 | QStringList birthdayList; |
2175 | QStringList anniversaryList; | 2175 | QStringList anniversaryList; |
2176 | QStringList realNameList; | 2176 | QStringList realNameList; |
2177 | QStringList preferredEmailList; | 2177 | QStringList preferredEmailList; |
2178 | QStringList assembledNameList; | 2178 | QStringList assembledNameList; |
2179 | QStringList uidList; | 2179 | QStringList uidList; |
2180 | 2180 | ||
2181 | KABC::AddressBook::Iterator it; | 2181 | KABC::AddressBook::Iterator it; |
2182 | 2182 | ||
2183 | int count = 0; | 2183 | int count = 0; |
2184 | for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { | 2184 | for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { |
2185 | ++count; | 2185 | ++count; |
2186 | } | 2186 | } |
2187 | QProgressBar bar(count,0 ); | 2187 | QProgressBar bar(count,0 ); |
2188 | int w = 300; | 2188 | int w = 300; |
2189 | if ( QApplication::desktop()->width() < 320 ) | 2189 | if ( QApplication::desktop()->width() < 320 ) |
2190 | w = 220; | 2190 | w = 220; |
2191 | int h = bar.sizeHint().height() ; | 2191 | int h = bar.sizeHint().height() ; |
2192 | int dw = QApplication::desktop()->width(); | 2192 | int dw = QApplication::desktop()->width(); |
2193 | int dh = QApplication::desktop()->height(); | 2193 | int dh = QApplication::desktop()->height(); |
2194 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 2194 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
2195 | bar.show(); | 2195 | bar.show(); |
2196 | bar.setCaption (i18n("Collecting birthdays - close to abort!") ); | 2196 | bar.setCaption (i18n("Collecting birthdays - close to abort!") ); |
2197 | qApp->processEvents(); | 2197 | qApp->processEvents(); |
2198 | 2198 | ||
2199 | QDate bday; | 2199 | QDate bday; |
2200 | QString anni; | 2200 | QString anni; |
2201 | QString formattedbday; | 2201 | QString formattedbday; |
2202 | 2202 | ||
2203 | for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) | 2203 | for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) |
2204 | { | 2204 | { |
2205 | if ( ! bar.isVisible() ) | 2205 | if ( ! bar.isVisible() ) |
2206 | return; | 2206 | return; |
2207 | bar.setProgress( count++ ); | 2207 | bar.setProgress( count++ ); |
2208 | qApp->processEvents(); | 2208 | qApp->processEvents(); |
2209 | bday = (*it).birthday().date(); | 2209 | bday = (*it).birthday().date(); |
2210 | anni = (*it).custom("KADDRESSBOOK", "X-Anniversary" ); | 2210 | anni = (*it).custom("KADDRESSBOOK", "X-Anniversary" ); |
2211 | 2211 | ||
2212 | if ( bday.isValid() || !anni.isEmpty()) | 2212 | if ( bday.isValid() || !anni.isEmpty()) |
2213 | { | 2213 | { |
2214 | if (bday.isValid()) | 2214 | if (bday.isValid()) |
2215 | formattedbday = KGlobal::locale()->formatDate(bday, true, KLocale::ISODate); | 2215 | formattedbday = KGlobal::locale()->formatDate(bday, true, KLocale::ISODate); |
2216 | else | 2216 | else |
2217 | formattedbday = "NOTVALID"; | 2217 | formattedbday = "NOTVALID"; |
2218 | if (anni.isEmpty()) | 2218 | if (anni.isEmpty()) |
2219 | anni = "INVALID"; | 2219 | anni = "INVALID"; |
2220 | 2220 | ||
2221 | birthdayList.append(formattedbday); | 2221 | birthdayList.append(formattedbday); |
2222 | anniversaryList.append(anni); //should be ISODate | 2222 | anniversaryList.append(anni); //should be ISODate |
2223 | realNameList.append((*it).realName()); | 2223 | realNameList.append((*it).realName()); |
2224 | preferredEmailList.append((*it).preferredEmail()); | 2224 | preferredEmailList.append((*it).preferredEmail()); |
2225 | assembledNameList.append((*it).assembledName()); | 2225 | assembledNameList.append((*it).assembledName()); |
2226 | uidList.append((*it).uid()); | 2226 | uidList.append((*it).uid()); |
2227 | 2227 | ||
2228 | qDebug("found birthday in KA/Pi: %s,%s,%s,%s: %s, %s", (*it).realName().latin1(), (*it).preferredEmail().latin1(), (*it).assembledName().latin1(), (*it).uid().latin1(), formattedbday.latin1(), anni.latin1() ); | 2228 | qDebug("found birthday in KA/Pi: %s,%s,%s,%s: %s, %s", (*it).realName().latin1(), (*it).preferredEmail().latin1(), (*it).assembledName().latin1(), (*it).uid().latin1(), formattedbday.latin1(), anni.latin1() ); |
2229 | } | 2229 | } |
2230 | } | 2230 | } |
2231 | 2231 | ||
2232 | bool res = ExternalAppHandler::instance()->returnBirthdayListFromKAPI(sourceChannel, uid, birthdayList, anniversaryList, realNameList, preferredEmailList, assembledNameList, uidList); | 2232 | bool res = ExternalAppHandler::instance()->returnBirthdayListFromKAPI(sourceChannel, uid, birthdayList, anniversaryList, realNameList, preferredEmailList, assembledNameList, uidList); |
2233 | 2233 | ||
2234 | } | 2234 | } |
2235 | 2235 | ||
2236 | /* this method will be called through the QCop interface from other apps to show details of a contact. | 2236 | /* this method will be called through the QCop interface from other apps to show details of a contact. |
2237 | */ | 2237 | */ |
2238 | void KABCore::requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid) | 2238 | void KABCore::requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid) |
2239 | { | 2239 | { |
2240 | qDebug("KABCore::requestForDetails %s %s %s %s %s", sourceChannel.latin1(), sessionuid.latin1(), name.latin1(), email.latin1(), uid.latin1()); | 2240 | qDebug("KABCore::requestForDetails %s %s %s %s %s", sourceChannel.latin1(), sessionuid.latin1(), name.latin1(), email.latin1(), uid.latin1()); |
2241 | 2241 | ||
2242 | QString foundUid = QString::null; | 2242 | QString foundUid = QString::null; |
2243 | if ( ! uid.isEmpty() ) { | 2243 | if ( ! uid.isEmpty() ) { |
2244 | Addressee adrr = mAddressBook->findByUid( uid ); | 2244 | Addressee adrr = mAddressBook->findByUid( uid ); |
2245 | if ( !adrr.isEmpty() ) { | 2245 | if ( !adrr.isEmpty() ) { |
2246 | foundUid = uid; | 2246 | foundUid = uid; |
2247 | } | 2247 | } |
2248 | if ( email == "sendbacklist" ) { | 2248 | if ( email == "sendbacklist" ) { |
2249 | //qDebug("ssssssssssssssssssssssend "); | 2249 | //qDebug("ssssssssssssssssssssssend "); |
2250 | QStringList nameList; | 2250 | QStringList nameList; |
2251 | QStringList emailList; | 2251 | QStringList emailList; |
2252 | QStringList uidList; | 2252 | QStringList uidList; |
2253 | nameList.append(adrr.realName()); | 2253 | nameList.append(adrr.realName()); |
2254 | emailList = adrr.emails(); | 2254 | emailList = adrr.emails(); |
2255 | uidList.append( adrr.preferredEmail()); | 2255 | uidList.append( adrr.preferredEmail()); |
2256 | bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI("QPE/Application/ompi", uid, nameList, emailList, uidList); | 2256 | bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI("QPE/Application/ompi", uid, nameList, emailList, uidList); |
2257 | return; | 2257 | return; |
2258 | } | 2258 | } |
2259 | 2259 | ||
2260 | } | 2260 | } |
2261 | 2261 | ||
2262 | if ( email == "sendbacklist" ) | 2262 | if ( email == "sendbacklist" ) |
2263 | return; | 2263 | return; |
2264 | if (foundUid.isEmpty()) | 2264 | if (foundUid.isEmpty()) |
2265 | { | 2265 | { |
2266 | //find the uid of the person first | 2266 | //find the uid of the person first |
2267 | Addressee::List namelist; | 2267 | Addressee::List namelist; |
2268 | Addressee::List emaillist; | 2268 | Addressee::List emaillist; |
2269 | 2269 | ||
2270 | if (!name.isEmpty()) | 2270 | if (!name.isEmpty()) |
2271 | namelist = mAddressBook->findByName( name ); | 2271 | namelist = mAddressBook->findByName( name ); |
2272 | 2272 | ||
2273 | if (!email.isEmpty()) | 2273 | if (!email.isEmpty()) |
2274 | emaillist = mAddressBook->findByEmail( email ); | 2274 | emaillist = mAddressBook->findByEmail( email ); |
2275 | qDebug("count %d %d ", namelist.count(),emaillist.count() ); | 2275 | qDebug("count %d %d ", namelist.count(),emaillist.count() ); |
2276 | //check if we have a match in Namelist and Emaillist | 2276 | //check if we have a match in Namelist and Emaillist |
2277 | if ((namelist.count() == 0) && (emaillist.count() > 0)) { | 2277 | if ((namelist.count() == 0) && (emaillist.count() > 0)) { |
2278 | foundUid = emaillist[0].uid(); | 2278 | foundUid = emaillist[0].uid(); |
2279 | } | 2279 | } |
2280 | else if ((namelist.count() > 0) && (emaillist.count() == 0)) | 2280 | else if ((namelist.count() > 0) && (emaillist.count() == 0)) |
2281 | foundUid = namelist[0].uid(); | 2281 | foundUid = namelist[0].uid(); |
2282 | else | 2282 | else |
2283 | { | 2283 | { |
2284 | for (int i = 0; i < namelist.count(); i++) | 2284 | for (int i = 0; i < namelist.count(); i++) |
2285 | { | 2285 | { |
2286 | for (int j = 0; j < emaillist.count(); j++) | 2286 | for (int j = 0; j < emaillist.count(); j++) |
2287 | { | 2287 | { |
2288 | if (namelist[i] == emaillist[j]) | 2288 | if (namelist[i] == emaillist[j]) |
2289 | { | 2289 | { |
2290 | foundUid = namelist[i].uid(); | 2290 | foundUid = namelist[i].uid(); |
2291 | } | 2291 | } |
2292 | } | 2292 | } |
2293 | } | 2293 | } |
2294 | } | 2294 | } |
2295 | } | 2295 | } |
2296 | else | 2296 | else |
2297 | { | 2297 | { |
2298 | foundUid = uid; | 2298 | foundUid = uid; |
2299 | } | 2299 | } |
2300 | 2300 | ||
2301 | if (!foundUid.isEmpty()) | 2301 | if (!foundUid.isEmpty()) |
2302 | { | 2302 | { |
2303 | 2303 | ||
2304 | // raise Ka/Pi if it is in the background | 2304 | // raise Ka/Pi if it is in the background |
2305 | #ifndef DESKTOP_VERSION | 2305 | #ifndef DESKTOP_VERSION |
2306 | #ifndef KORG_NODCOP | 2306 | #ifndef KORG_NODCOP |
2307 | //QCopEnvelope e("QPE/Application/kapi", "raise()"); | 2307 | //QCopEnvelope e("QPE/Application/kapi", "raise()"); |
2308 | #endif | 2308 | #endif |
2309 | #endif | 2309 | #endif |
2310 | 2310 | ||
2311 | mMainWindow->showMaximized(); | 2311 | mMainWindow->showMaximized(); |
2312 | mMainWindow-> raise(); | 2312 | mMainWindow-> raise(); |
2313 | 2313 | ||
2314 | mViewManager->setSelected( "", false); | 2314 | mViewManager->setSelected( "", false); |
2315 | mViewManager->refreshView( "" ); | 2315 | mViewManager->refreshView( "" ); |
2316 | mViewManager->setSelected( foundUid, true ); | 2316 | mViewManager->setSelected( foundUid, true ); |
2317 | mViewManager->refreshView( foundUid ); | 2317 | mViewManager->refreshView( foundUid ); |
2318 | 2318 | ||
2319 | if ( !mMultipleViewsAtOnce ) | 2319 | if ( !mMultipleViewsAtOnce ) |
2320 | { | 2320 | { |
2321 | setDetailsVisible( true ); | 2321 | setDetailsVisible( true ); |
2322 | mActionDetails->setChecked(true); | 2322 | mActionDetails->setChecked(true); |
2323 | } | 2323 | } |
2324 | } | 2324 | } |
2325 | } | 2325 | } |
2326 | 2326 | ||
2327 | void KABCore::whatsnew() | 2327 | void KABCore::whatsnew() |
2328 | { | 2328 | { |
2329 | KApplication::showFile( "KDE-Pim/Pi Version Info", "kdepim/WhatsNew.txt" ); | 2329 | KApplication::showFile( "KDE-Pim/Pi Version Info", "kdepim/WhatsNew.txt" ); |
2330 | } | 2330 | } |
2331 | void KABCore::synchowto() | 2331 | void KABCore::synchowto() |
2332 | { | 2332 | { |
2333 | KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/SyncHowto.txt" ); | 2333 | KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/SyncHowto.txt" ); |
2334 | } | 2334 | } |
2335 | 2335 | ||
2336 | void KABCore::faq() | 2336 | void KABCore::faq() |
2337 | { | 2337 | { |
2338 | KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" ); | 2338 | KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" ); |
2339 | } | 2339 | } |
2340 | 2340 | ||
2341 | #include <libkcal/syncdefines.h> | 2341 | #include <libkcal/syncdefines.h> |
2342 | 2342 | ||
2343 | KABC::Addressee KABCore::getLastSyncAddressee() | 2343 | KABC::Addressee KABCore::getLastSyncAddressee() |
2344 | { | 2344 | { |
2345 | Addressee lse; | 2345 | Addressee lse; |
2346 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); | 2346 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); |
2347 | 2347 | ||
2348 | //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); | 2348 | //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); |
2349 | lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); | 2349 | lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); |
2350 | if (lse.isEmpty()) { | 2350 | if (lse.isEmpty()) { |
2351 | qDebug("Creating new last-syncAddressee "); | 2351 | qDebug("Creating new last-syncAddressee "); |
2352 | lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice ); | 2352 | lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice ); |
2353 | QString sum = ""; | 2353 | QString sum = ""; |
2354 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) | 2354 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) |
2355 | sum = "E: "; | 2355 | sum = "E: "; |
2356 | lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event")); | 2356 | lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event")); |
2357 | lse.setRevision( mLastAddressbookSync ); | 2357 | lse.setRevision( mLastAddressbookSync ); |
2358 | lse.setCategories( i18n("SyncEvent") ); | 2358 | lse.setCategories( i18n("SyncEvent") ); |
2359 | mAddressBook->insertAddressee( lse ); | 2359 | mAddressBook->insertAddressee( lse ); |
2360 | } | 2360 | } |
2361 | return lse; | 2361 | return lse; |
2362 | } | 2362 | } |
2363 | int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full ) | 2363 | int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full ) |
2364 | { | 2364 | { |
2365 | 2365 | ||
2366 | //void setZaurusId(int id); | 2366 | //void setZaurusId(int id); |
2367 | // int zaurusId() const; | 2367 | // int zaurusId() const; |
2368 | // void setZaurusUid(int id); | 2368 | // void setZaurusUid(int id); |
2369 | // int zaurusUid() const; | 2369 | // int zaurusUid() const; |
2370 | // void setZaurusStat(int id); | 2370 | // void setZaurusStat(int id); |
2371 | // int zaurusStat() const; | 2371 | // int zaurusStat() const; |
2372 | // 0 equal | 2372 | // 0 equal |
2373 | // 1 take local | 2373 | // 1 take local |
2374 | // 2 take remote | 2374 | // 2 take remote |
2375 | // 3 cancel | 2375 | // 3 cancel |
2376 | QDateTime lastSync = mLastAddressbookSync; | 2376 | QDateTime lastSync = mLastAddressbookSync; |
2377 | QDateTime localMod = local->revision(); | 2377 | QDateTime localMod = local->revision(); |
2378 | QDateTime remoteMod = remote->revision(); | 2378 | QDateTime remoteMod = remote->revision(); |
2379 | 2379 | ||
2380 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); | 2380 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); |
2381 | 2381 | ||
2382 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2382 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2383 | bool remCh, locCh; | 2383 | bool remCh, locCh; |
2384 | remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); | 2384 | remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); |
2385 | 2385 | ||
2386 | //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); | 2386 | //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); |
2387 | locCh = ( localMod > mLastAddressbookSync ); | 2387 | locCh = ( localMod > mLastAddressbookSync ); |
2388 | if ( !remCh && ! locCh ) { | 2388 | if ( !remCh && ! locCh ) { |
2389 | //qDebug("both not changed "); | 2389 | //qDebug("both not changed "); |
2390 | lastSync = localMod.addDays(1); | 2390 | lastSync = localMod.addDays(1); |
2391 | if ( mode <= SYNC_PREF_ASK ) | 2391 | if ( mode <= SYNC_PREF_ASK ) |
2392 | return 0; | 2392 | return 0; |
2393 | } else { | 2393 | } else { |
2394 | if ( locCh ) { | 2394 | if ( locCh ) { |
2395 | //qDebug("loc changed %s %s", localMod.toString().latin1(), mLastAddressbookSync.toString().latin1()); | 2395 | //qDebug("loc changed %s %s", localMod.toString().latin1(), mLastAddressbookSync.toString().latin1()); |
2396 | lastSync = localMod.addDays( -1 ); | 2396 | lastSync = localMod.addDays( -1 ); |
2397 | if ( !remCh ) | 2397 | if ( !remCh ) |
2398 | remoteMod =( lastSync.addDays( -1 ) ); | 2398 | remoteMod =( lastSync.addDays( -1 ) ); |
2399 | } else { | 2399 | } else { |
2400 | //qDebug(" not loc changed "); | 2400 | //qDebug(" not loc changed "); |
2401 | lastSync = localMod.addDays( 1 ); | 2401 | lastSync = localMod.addDays( 1 ); |
2402 | if ( remCh ) | 2402 | if ( remCh ) |
2403 | remoteMod =( lastSync.addDays( 1 ) ); | 2403 | remoteMod =( lastSync.addDays( 1 ) ); |
2404 | 2404 | ||
2405 | } | 2405 | } |
2406 | } | 2406 | } |
2407 | full = true; | 2407 | full = true; |
2408 | if ( mode < SYNC_PREF_ASK ) | 2408 | if ( mode < SYNC_PREF_ASK ) |
2409 | mode = SYNC_PREF_ASK; | 2409 | mode = SYNC_PREF_ASK; |
2410 | } else { | 2410 | } else { |
2411 | if ( localMod == remoteMod ) | 2411 | if ( localMod == remoteMod ) |
2412 | return 0; | 2412 | return 0; |
2413 | 2413 | ||
2414 | } | 2414 | } |
2415 | // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); | 2415 | // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); |
2416 | 2416 | ||
2417 | //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); | 2417 | //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); |
2418 | //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); | 2418 | //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); |
2419 | //full = true; //debug only | 2419 | //full = true; //debug only |
2420 | if ( full ) { | 2420 | if ( full ) { |
2421 | bool equ = ( (*local) == (*remote) ); | 2421 | bool equ = ( (*local) == (*remote) ); |
2422 | if ( equ ) { | 2422 | if ( equ ) { |
2423 | //qDebug("equal "); | 2423 | //qDebug("equal "); |
2424 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2424 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2425 | local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); | 2425 | local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); |
2426 | } | 2426 | } |
2427 | if ( mode < SYNC_PREF_FORCE_LOCAL ) | 2427 | if ( mode < SYNC_PREF_FORCE_LOCAL ) |
2428 | return 0; | 2428 | return 0; |
2429 | 2429 | ||
2430 | }//else //debug only | 2430 | }//else //debug only |
2431 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); | 2431 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); |
2432 | } | 2432 | } |
2433 | int result; | 2433 | int result; |
2434 | bool localIsNew; | 2434 | bool localIsNew; |
2435 | //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() ); | 2435 | //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() ); |
2436 | 2436 | ||
2437 | if ( full && mode < SYNC_PREF_NEWEST ) | 2437 | if ( full && mode < SYNC_PREF_NEWEST ) |
2438 | mode = SYNC_PREF_ASK; | 2438 | mode = SYNC_PREF_ASK; |
2439 | 2439 | ||
2440 | switch( mode ) { | 2440 | switch( mode ) { |
2441 | case SYNC_PREF_LOCAL: | 2441 | case SYNC_PREF_LOCAL: |
2442 | if ( lastSync > remoteMod ) | 2442 | if ( lastSync > remoteMod ) |
2443 | return 1; | 2443 | return 1; |
2444 | if ( lastSync > localMod ) | 2444 | if ( lastSync > localMod ) |
2445 | return 2; | 2445 | return 2; |
2446 | return 1; | 2446 | return 1; |
2447 | break; | 2447 | break; |
2448 | case SYNC_PREF_REMOTE: | 2448 | case SYNC_PREF_REMOTE: |
2449 | if ( lastSync > remoteMod ) | 2449 | if ( lastSync > remoteMod ) |
2450 | return 1; | 2450 | return 1; |
2451 | if ( lastSync > localMod ) | 2451 | if ( lastSync > localMod ) |
2452 | return 2; | 2452 | return 2; |
2453 | return 2; | 2453 | return 2; |
2454 | break; | 2454 | break; |
2455 | case SYNC_PREF_NEWEST: | 2455 | case SYNC_PREF_NEWEST: |
2456 | if ( localMod > remoteMod ) | 2456 | if ( localMod > remoteMod ) |
2457 | return 1; | 2457 | return 1; |
2458 | else | 2458 | else |
2459 | return 2; | 2459 | return 2; |
2460 | break; | 2460 | break; |
2461 | case SYNC_PREF_ASK: | 2461 | case SYNC_PREF_ASK: |
2462 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); | 2462 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); |
2463 | if ( lastSync > remoteMod ) | 2463 | if ( lastSync > remoteMod ) |
2464 | return 1; | 2464 | return 1; |
2465 | if ( lastSync > localMod ) | 2465 | if ( lastSync > localMod ) |
2466 | return 2; | 2466 | return 2; |
2467 | localIsNew = localMod >= remoteMod; | 2467 | localIsNew = localMod >= remoteMod; |
2468 | //qDebug("conflict! ************************************** "); | 2468 | //qDebug("conflict! ************************************** "); |
2469 | { | 2469 | { |
2470 | KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this ); | 2470 | KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this ); |
2471 | result = acd.executeD(localIsNew); | 2471 | result = acd.executeD(localIsNew); |
2472 | return result; | 2472 | return result; |
2473 | } | 2473 | } |
2474 | break; | 2474 | break; |
2475 | case SYNC_PREF_FORCE_LOCAL: | 2475 | case SYNC_PREF_FORCE_LOCAL: |
2476 | return 1; | 2476 | return 1; |
2477 | break; | 2477 | break; |
2478 | case SYNC_PREF_FORCE_REMOTE: | 2478 | case SYNC_PREF_FORCE_REMOTE: |
2479 | return 2; | 2479 | return 2; |
2480 | break; | 2480 | break; |
2481 | 2481 | ||
2482 | default: | 2482 | default: |
2483 | // SYNC_PREF_TAKE_BOTH not implemented | 2483 | // SYNC_PREF_TAKE_BOTH not implemented |
2484 | break; | 2484 | break; |
2485 | } | 2485 | } |
2486 | return 0; | 2486 | return 0; |
2487 | } | 2487 | } |
2488 | 2488 | ||
2489 | 2489 | ||
2490 | bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) | 2490 | bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) |
2491 | { | 2491 | { |
2492 | bool syncOK = true; | 2492 | bool syncOK = true; |
2493 | int addedAddressee = 0; | 2493 | int addedAddressee = 0; |
2494 | int addedAddresseeR = 0; | 2494 | int addedAddresseeR = 0; |
2495 | int deletedAddresseeR = 0; | 2495 | int deletedAddresseeR = 0; |
2496 | int deletedAddresseeL = 0; | 2496 | int deletedAddresseeL = 0; |
2497 | int changedLocal = 0; | 2497 | int changedLocal = 0; |
2498 | int changedRemote = 0; | 2498 | int changedRemote = 0; |
2499 | 2499 | ||
2500 | QString mCurrentSyncName = syncManager->getCurrentSyncName(); | 2500 | QString mCurrentSyncName = syncManager->getCurrentSyncName(); |
2501 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); | 2501 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); |
2502 | 2502 | ||
2503 | //QPtrList<Addressee> el = local->rawAddressees(); | 2503 | //QPtrList<Addressee> el = local->rawAddressees(); |
2504 | Addressee addresseeR; | 2504 | Addressee addresseeR; |
2505 | QString uid; | 2505 | QString uid; |
2506 | int take; | 2506 | int take; |
2507 | Addressee addresseeL; | 2507 | Addressee addresseeL; |
2508 | Addressee addresseeRSync; | 2508 | Addressee addresseeRSync; |
2509 | Addressee addresseeLSync; | 2509 | Addressee addresseeLSync; |
2510 | // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); | 2510 | // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); |
2511 | //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); | 2511 | //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); |
2512 | bool fullDateRange = false; | 2512 | bool fullDateRange = false; |
2513 | local->resetTempSyncStat(); | 2513 | local->resetTempSyncStat(); |
2514 | mLastAddressbookSync = QDateTime::currentDateTime(); | 2514 | mLastAddressbookSync = QDateTime::currentDateTime(); |
2515 | if ( syncManager->syncWithDesktop() ) { | 2515 | if ( syncManager->syncWithDesktop() ) { |
2516 | remote->removeSyncInfo( QString());//remove all info | 2516 | // remote->removeSyncInfo( QString());//remove all info |
2517 | if ( KSyncManager::mRequestedSyncEvent.isValid() ) { | 2517 | if ( KSyncManager::mRequestedSyncEvent.isValid() ) { |
2518 | mLastAddressbookSync = KSyncManager::mRequestedSyncEvent; | 2518 | mLastAddressbookSync = KSyncManager::mRequestedSyncEvent; |
2519 | qDebug("using extern time for calendar sync: %s ", mLastAddressbookSync.toString().latin1() ); | 2519 | qDebug("using extern time for calendar sync: %s ", mLastAddressbookSync.toString().latin1() ); |
2520 | } else { | 2520 | } else { |
2521 | qDebug("ERROR: KSyncManager::mRequestedSyncEvent has invalid datatime "); | 2521 | qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); |
2522 | } | 2522 | } |
2523 | } | 2523 | } |
2524 | QDateTime modifiedCalendar = mLastAddressbookSync; | 2524 | QDateTime modifiedCalendar = mLastAddressbookSync; |
2525 | addresseeLSync = getLastSyncAddressee(); | 2525 | addresseeLSync = getLastSyncAddressee(); |
2526 | qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); | 2526 | qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); |
2527 | addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); | 2527 | addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); |
2528 | if ( !addresseeR.isEmpty() ) { | 2528 | if ( !addresseeR.isEmpty() ) { |
2529 | addresseeRSync = addresseeR; | 2529 | addresseeRSync = addresseeR; |
2530 | remote->removeAddressee(addresseeR ); | 2530 | remote->removeAddressee(addresseeR ); |
2531 | 2531 | ||
2532 | } else { | 2532 | } else { |
2533 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2533 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2534 | addresseeRSync = addresseeLSync ; | 2534 | addresseeRSync = addresseeLSync ; |
2535 | } else { | 2535 | } else { |
2536 | qDebug("FULLDATE 1"); | 2536 | qDebug("FULLDATE 1"); |
2537 | fullDateRange = true; | 2537 | fullDateRange = true; |
2538 | Addressee newAdd; | 2538 | Addressee newAdd; |
2539 | addresseeRSync = newAdd; | 2539 | addresseeRSync = newAdd; |
2540 | addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); | 2540 | addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); |
2541 | addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); | 2541 | addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); |
2542 | addresseeRSync.setRevision( mLastAddressbookSync ); | 2542 | addresseeRSync.setRevision( mLastAddressbookSync ); |
2543 | addresseeRSync.setCategories( i18n("SyncAddressee") ); | 2543 | addresseeRSync.setCategories( i18n("SyncAddressee") ); |
2544 | } | 2544 | } |
2545 | } | 2545 | } |
2546 | if ( addresseeLSync.revision() == mLastAddressbookSync ) { | 2546 | if ( addresseeLSync.revision() == mLastAddressbookSync ) { |
2547 | qDebug("FULLDATE 2"); | 2547 | qDebug("FULLDATE 2"); |
2548 | fullDateRange = true; | 2548 | fullDateRange = true; |
2549 | } | 2549 | } |
2550 | if ( ! fullDateRange ) { | 2550 | if ( ! fullDateRange ) { |
2551 | if ( addresseeLSync.revision() != addresseeRSync.revision() ) { | 2551 | if ( addresseeLSync.revision() != addresseeRSync.revision() ) { |
2552 | 2552 | ||
2553 | // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); | 2553 | // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); |
2554 | //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); | 2554 | //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); |
2555 | fullDateRange = true; | 2555 | fullDateRange = true; |
2556 | qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); | 2556 | qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); |
2557 | } | 2557 | } |
2558 | } | 2558 | } |
2559 | // fullDateRange = true; // debug only! | 2559 | // fullDateRange = true; // debug only! |
2560 | if ( fullDateRange ) | 2560 | if ( fullDateRange ) |
2561 | mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); | 2561 | mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); |
2562 | else | 2562 | else |
2563 | mLastAddressbookSync = addresseeLSync.revision(); | 2563 | mLastAddressbookSync = addresseeLSync.revision(); |
2564 | // for resyncing if own file has changed | 2564 | // for resyncing if own file has changed |
2565 | // PENDING fixme later when implemented | 2565 | // PENDING fixme later when implemented |
2566 | #if 0 | 2566 | #if 0 |
2567 | if ( mCurrentSyncDevice == "deleteaftersync" ) { | 2567 | if ( mCurrentSyncDevice == "deleteaftersync" ) { |
2568 | mLastAddressbookSync = loadedFileVersion; | 2568 | mLastAddressbookSync = loadedFileVersion; |
2569 | qDebug("setting mLastAddressbookSync "); | 2569 | qDebug("setting mLastAddressbookSync "); |
2570 | } | 2570 | } |
2571 | #endif | 2571 | #endif |
2572 | 2572 | ||
2573 | //qDebug("*************************** "); | 2573 | //qDebug("*************************** "); |
2574 | // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); | 2574 | // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); |
2575 | QStringList er = remote->uidList(); | 2575 | QStringList er = remote->uidList(); |
2576 | Addressee inR ;//= er.first(); | 2576 | Addressee inR ;//= er.first(); |
2577 | Addressee inL; | 2577 | Addressee inL; |
2578 | 2578 | ||
2579 | syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); | 2579 | syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); |
2580 | 2580 | ||
2581 | int modulo = (er.count()/10)+1; | 2581 | int modulo = (er.count()/10)+1; |
2582 | int incCounter = 0; | 2582 | int incCounter = 0; |
2583 | while ( incCounter < er.count()) { | 2583 | while ( incCounter < er.count()) { |
2584 | if (syncManager->isProgressBarCanceled()) | 2584 | if (syncManager->isProgressBarCanceled()) |
2585 | return false; | 2585 | return false; |
2586 | if ( incCounter % modulo == 0 ) | 2586 | if ( incCounter % modulo == 0 ) |
2587 | syncManager->showProgressBar(incCounter); | 2587 | syncManager->showProgressBar(incCounter); |
2588 | 2588 | ||
2589 | uid = er[ incCounter ]; | 2589 | uid = er[ incCounter ]; |
2590 | bool skipIncidence = false; | 2590 | bool skipIncidence = false; |
2591 | if ( uid.left(19) == QString("last-syncAddressee-") ) | 2591 | if ( uid.left(19) == QString("last-syncAddressee-") ) |
2592 | skipIncidence = true; | 2592 | skipIncidence = true; |
2593 | QString idS,OidS; | 2593 | QString idS,OidS; |
2594 | qApp->processEvents(); | 2594 | qApp->processEvents(); |
2595 | if ( !skipIncidence ) { | 2595 | if ( !skipIncidence ) { |
2596 | inL = local->findByUid( uid ); | 2596 | inL = local->findByUid( uid ); |
2597 | inR = remote->findByUid( uid ); | 2597 | inR = remote->findByUid( uid ); |
2598 | //inL.setResource( 0 ); | 2598 | //inL.setResource( 0 ); |
2599 | //inR.setResource( 0 ); | 2599 | //inR.setResource( 0 ); |
2600 | if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars | 2600 | if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars |
2601 | if ( !inL.resource() || inL.resource()->includeInSync() ) { | 2601 | if ( !inL.resource() || inL.resource()->includeInSync() ) { |
2602 | if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) { | 2602 | if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) { |
2603 | //qDebug("take %d %s ", take, inL.summary().latin1()); | 2603 | //qDebug("take %d %s ", take, inL.summary().latin1()); |
2604 | if ( take == 3 ) | 2604 | if ( take == 3 ) |
2605 | return false; | 2605 | return false; |
2606 | if ( take == 1 ) {// take local | 2606 | if ( take == 1 ) {// take local |
2607 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2607 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2608 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); | 2608 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); |
2609 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); | 2609 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); |
2610 | local->insertAddressee( inL, false ); | 2610 | local->insertAddressee( inL, false ); |
2611 | idS = inR.externalUID(); | 2611 | idS = inR.externalUID(); |
2612 | OidS = inR.originalExternalUID(); | 2612 | OidS = inR.originalExternalUID(); |
2613 | } | 2613 | } |
2614 | else | 2614 | else |
2615 | idS = inR.IDStr(); | 2615 | idS = inR.IDStr(); |
2616 | remote->removeAddressee( inR ); | 2616 | remote->removeAddressee( inR ); |
2617 | inR = inL; | 2617 | inR = inL; |
2618 | inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 2618 | inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
2619 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2619 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2620 | inR.setOriginalExternalUID( OidS ); | 2620 | inR.setOriginalExternalUID( OidS ); |
2621 | inR.setExternalUID( idS ); | 2621 | inR.setExternalUID( idS ); |
2622 | if ( syncManager->syncWithDesktop() ) | 2622 | if ( syncManager->syncWithDesktop() ) |
2623 | inR.setIDStr( "changed" ); | 2623 | inR.setIDStr("changed" ); |
2624 | //inR.insertCustom( "KADDRESSBOOK", "X-KDESYNC","changed" ); | ||
2624 | } else { | 2625 | } else { |
2625 | inR.setIDStr( idS ); | 2626 | inR.setIDStr( idS ); |
2626 | } | 2627 | } |
2627 | inR.setResource( 0 ); | 2628 | inR.setResource( 0 ); |
2628 | remote->insertAddressee( inR , false); | 2629 | remote->insertAddressee( inR , false); |
2629 | ++changedRemote; | 2630 | ++changedRemote; |
2630 | } else { // take == 2 take remote | 2631 | } else { // take == 2 take remote |
2631 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2632 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2632 | if ( inR.revision().date().year() < 2004 ) | 2633 | if ( inR.revision().date().year() < 2004 ) |
2633 | inR.setRevision( modifiedCalendar ); | 2634 | inR.setRevision( modifiedCalendar ); |
2634 | } | 2635 | } |
2635 | idS = inL.IDStr(); | 2636 | idS = inL.IDStr(); |
2636 | local->removeAddressee( inL ); | 2637 | local->removeAddressee( inL ); |
2637 | inL = inR; | 2638 | inL = inR; |
2638 | inL.setIDStr( idS ); | 2639 | inL.setIDStr( idS ); |
2639 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2640 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2640 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); | 2641 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); |
2641 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); | 2642 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); |
2642 | } | 2643 | } |
2643 | inL.setResource( 0 ); | 2644 | inL.setResource( 0 ); |
2644 | local->insertAddressee( inL , false ); | 2645 | local->insertAddressee( inL , false ); |
2645 | ++changedLocal; | 2646 | ++changedLocal; |
2646 | } | 2647 | } |
2647 | } | 2648 | } |
2648 | } | 2649 | } |
2649 | } else { // no conflict | 2650 | } else { // no conflict |
2650 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2651 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2651 | QString des = addresseeLSync.note(); | 2652 | QString des = addresseeLSync.note(); |
2652 | if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it | 2653 | if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it |
2653 | inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); | 2654 | inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); |
2654 | remote->insertAddressee( inR, false ); | 2655 | remote->insertAddressee( inR, false ); |
2655 | ++deletedAddresseeR; | 2656 | ++deletedAddresseeR; |
2656 | } else { | 2657 | } else { |
2657 | inR.setRevision( modifiedCalendar ); | 2658 | inR.setRevision( modifiedCalendar ); |
2658 | remote->insertAddressee( inR, false ); | 2659 | remote->insertAddressee( inR, false ); |
2659 | inL = inR; | 2660 | inL = inR; |
2660 | inL.setResource( 0 ); | 2661 | inL.setResource( 0 ); |
2661 | local->insertAddressee( inL , false); | 2662 | local->insertAddressee( inL , false); |
2662 | ++addedAddressee; | 2663 | ++addedAddressee; |
2663 | } | 2664 | } |
2664 | } else { | 2665 | } else { |
2665 | if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { | 2666 | if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { |
2666 | inR.setRevision( modifiedCalendar ); | 2667 | inR.setRevision( modifiedCalendar ); |
2667 | remote->insertAddressee( inR, false ); | 2668 | remote->insertAddressee( inR, false ); |
2668 | inR.setResource( 0 ); | 2669 | inR.setResource( 0 ); |
2669 | local->insertAddressee( inR, false ); | 2670 | local->insertAddressee( inR, false ); |
2670 | ++addedAddressee; | 2671 | ++addedAddressee; |
2671 | } else { | 2672 | } else { |
2672 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); | 2673 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); |
2673 | remote->removeAddressee( inR ); | 2674 | remote->removeAddressee( inR ); |
2674 | ++deletedAddresseeR; | 2675 | ++deletedAddresseeR; |
2675 | } | 2676 | } |
2676 | } | 2677 | } |
2677 | } | 2678 | } |
2678 | } | 2679 | } |
2679 | ++incCounter; | 2680 | ++incCounter; |
2680 | } | 2681 | } |
2681 | er.clear(); | 2682 | er.clear(); |
2682 | QStringList el = local->uidList(); | 2683 | QStringList el = local->uidList(); |
2683 | modulo = (el.count()/10)+1; | 2684 | modulo = (el.count()/10)+1; |
2684 | 2685 | ||
2685 | syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); | 2686 | syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); |
2686 | incCounter = 0; | 2687 | incCounter = 0; |
2687 | while ( incCounter < el.count()) { | 2688 | while ( incCounter < el.count()) { |
2688 | qApp->processEvents(); | 2689 | qApp->processEvents(); |
2689 | if (syncManager->isProgressBarCanceled()) | 2690 | if (syncManager->isProgressBarCanceled()) |
2690 | return false; | 2691 | return false; |
2691 | if ( incCounter % modulo == 0 ) | 2692 | if ( incCounter % modulo == 0 ) |
2692 | syncManager->showProgressBar(incCounter); | 2693 | syncManager->showProgressBar(incCounter); |
2693 | uid = el[ incCounter ]; | 2694 | uid = el[ incCounter ]; |
2694 | bool skipIncidence = false; | 2695 | bool skipIncidence = false; |
2695 | if ( uid.left(19) == QString("last-syncAddressee-") ) | 2696 | if ( uid.left(19) == QString("last-syncAddressee-") ) |
2696 | skipIncidence = true; | 2697 | skipIncidence = true; |
2697 | if ( !skipIncidence ) { | 2698 | if ( !skipIncidence ) { |
2698 | inL = local->findByUid( uid ); | 2699 | inL = local->findByUid( uid ); |
2699 | if ( !inL.resource() || inL.resource()->includeInSync() ) { | 2700 | if ( !inL.resource() || inL.resource()->includeInSync() ) { |
2700 | inR = remote->findByUid( uid ); | 2701 | inR = remote->findByUid( uid ); |
2701 | if ( inR.isEmpty() ) { | 2702 | if ( inR.isEmpty() ) { |
2702 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2703 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2703 | if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { | 2704 | if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { |
2704 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); | 2705 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); |
2705 | local->removeAddressee( inL ); | 2706 | local->removeAddressee( inL ); |
2706 | ++deletedAddresseeL; | 2707 | ++deletedAddresseeL; |
2707 | } else { | 2708 | } else { |
2708 | if ( ! syncManager->mWriteBackExistingOnly ) { | 2709 | if ( ! syncManager->mWriteBackExistingOnly ) { |
2709 | inL.removeID(mCurrentSyncDevice ); | 2710 | inL.removeID(mCurrentSyncDevice ); |
2710 | ++addedAddresseeR; | 2711 | ++addedAddresseeR; |
2711 | inL.setRevision( modifiedCalendar ); | 2712 | inL.setRevision( modifiedCalendar ); |
2712 | local->insertAddressee( inL, false ); | 2713 | local->insertAddressee( inL, false ); |
2713 | inR = inL; | 2714 | inR = inL; |
2714 | inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); | 2715 | inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); |
2715 | inR.setResource( 0 ); | 2716 | inR.setResource( 0 ); |
2716 | remote->insertAddressee( inR, false ); | 2717 | remote->insertAddressee( inR, false ); |
2717 | } | 2718 | } |
2718 | } | 2719 | } |
2719 | } else { | 2720 | } else { |
2720 | if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { | 2721 | if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { |
2721 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); | 2722 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); |
2722 | local->removeAddressee( inL ); | 2723 | local->removeAddressee( inL ); |
2723 | ++deletedAddresseeL; | 2724 | ++deletedAddresseeL; |
2724 | } else { | 2725 | } else { |
2725 | if ( ! syncManager->mWriteBackExistingOnly ) { | 2726 | if ( ! syncManager->mWriteBackExistingOnly ) { |
2726 | ++addedAddresseeR; | 2727 | ++addedAddresseeR; |
2727 | inL.setRevision( modifiedCalendar ); | 2728 | inL.setRevision( modifiedCalendar ); |
2728 | local->insertAddressee( inL, false ); | 2729 | local->insertAddressee( inL, false ); |
2729 | inR = inL; | 2730 | inR = inL; |
2730 | inR.setResource( 0 ); | 2731 | inR.setResource( 0 ); |
2731 | remote->insertAddressee( inR, false ); | 2732 | remote->insertAddressee( inR, false ); |
2732 | } | 2733 | } |
2733 | } | 2734 | } |
2734 | } | 2735 | } |
2735 | } | 2736 | } |
2736 | } | 2737 | } |
2737 | } | 2738 | } |
2738 | ++incCounter; | 2739 | ++incCounter; |
2739 | } | 2740 | } |
2740 | el.clear(); | 2741 | el.clear(); |
2741 | syncManager->hideProgressBar(); | 2742 | syncManager->hideProgressBar(); |
2742 | mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); | 2743 | mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); |
2743 | // get rid of micro seconds | 2744 | // get rid of micro seconds |
2744 | QTime t = mLastAddressbookSync.time(); | 2745 | QTime t = mLastAddressbookSync.time(); |
2745 | mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 2746 | mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
2746 | addresseeLSync.setRevision( mLastAddressbookSync ); | 2747 | addresseeLSync.setRevision( mLastAddressbookSync ); |
2747 | addresseeRSync.setRevision( mLastAddressbookSync ); | 2748 | addresseeRSync.setRevision( mLastAddressbookSync ); |
2748 | addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; | 2749 | addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; |
2749 | addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); | 2750 | addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); |
2750 | addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; | 2751 | addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; |
2751 | addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); | 2752 | addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); |
2752 | addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; | 2753 | addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; |
2753 | addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); | 2754 | addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); |
2754 | addresseeRSync.setNote( "" ) ; | 2755 | addresseeRSync.setNote( "" ) ; |
2755 | addresseeLSync.setNote( "" ); | 2756 | addresseeLSync.setNote( "" ); |
2756 | 2757 | ||
2757 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL) | 2758 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL) |
2758 | remote->insertAddressee( addresseeRSync, false ); | 2759 | remote->insertAddressee( addresseeRSync, false ); |
2759 | local->insertAddressee( addresseeLSync, false ); | 2760 | local->insertAddressee( addresseeLSync, false ); |
2760 | QString mes; | 2761 | QString mes; |
2761 | 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 ); | 2762 | 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 ); |
2762 | if ( syncManager->mShowSyncSummary ) { | 2763 | if ( syncManager->mShowSyncSummary ) { |
2763 | KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") ); | 2764 | KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") ); |
2764 | } | 2765 | } |
2765 | qDebug( mes ); | 2766 | qDebug( mes ); |
2766 | return syncOK; | 2767 | return syncOK; |
2767 | } | 2768 | } |
2768 | 2769 | ||
2769 | 2770 | ||
2770 | //this is a overwritten callbackmethods from the syncinterface | 2771 | //this is a overwritten callbackmethods from the syncinterface |
2771 | bool KABCore::sync(KSyncManager* manager, QString filename, int mode) | 2772 | bool KABCore::sync(KSyncManager* manager, QString filename, int mode) |
2772 | { | 2773 | { |
2773 | 2774 | ||
2774 | //pending prepare addresseeview for output | 2775 | //pending prepare addresseeview for output |
2775 | //pending detect, if remote file has REV field. if not switch to external sync | 2776 | //pending detect, if remote file has REV field. if not switch to external sync |
2776 | mGlobalSyncMode = SYNC_MODE_NORMAL; | 2777 | mGlobalSyncMode = SYNC_MODE_NORMAL; |
2777 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); | 2778 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); |
2778 | 2779 | ||
2779 | AddressBook abLocal(filename,"syncContact"); | 2780 | AddressBook abLocal(filename,"syncContact"); |
2780 | bool syncOK = false; | 2781 | bool syncOK = false; |
2781 | if ( abLocal.load() ) { | 2782 | if ( abLocal.load() ) { |
2782 | qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); | 2783 | qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); |
2783 | bool external = false; | 2784 | bool external = false; |
2784 | bool isXML = false; | 2785 | bool isXML = false; |
2785 | if ( filename.right(4) == ".xml") { | 2786 | if ( filename.right(4) == ".xml") { |
2786 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 2787 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
2787 | isXML = true; | 2788 | isXML = true; |
2788 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); | 2789 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); |
2789 | } else { | 2790 | } else { |
2790 | external = !manager->mIsKapiFile; | 2791 | external = !manager->mIsKapiFile; |
2791 | if ( external ) { | 2792 | if ( external ) { |
2792 | qDebug("Setting vcf mode to external "); | 2793 | qDebug("Setting vcf mode to external "); |
2793 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 2794 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
2794 | AddressBook::Iterator it; | 2795 | AddressBook::Iterator it; |
2795 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { | 2796 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { |
2796 | (*it).setID( mCurrentSyncDevice, (*it).uid() ); | 2797 | (*it).setID( mCurrentSyncDevice, (*it).uid() ); |
2797 | (*it).computeCsum( mCurrentSyncDevice ); | 2798 | (*it).computeCsum( mCurrentSyncDevice ); |
2798 | } | 2799 | } |
2799 | } | 2800 | } |
2800 | } | 2801 | } |
2801 | //AddressBook::Iterator it; | 2802 | //AddressBook::Iterator it; |
2802 | //QStringList vcards; | 2803 | //QStringList vcards; |
2803 | //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { | 2804 | //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { |
2804 | // qDebug("Name %s ", (*it).familyName().latin1()); | 2805 | // qDebug("Name %s ", (*it).familyName().latin1()); |
2805 | //} | 2806 | //} |
2806 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); | 2807 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); |
2807 | if ( syncOK ) { | 2808 | if ( syncOK ) { |
2808 | if ( syncManager->mWriteBackFile ) | 2809 | if ( syncManager->mWriteBackFile ) |
2809 | { | 2810 | { |
2810 | if ( external ) | 2811 | if ( external ) |
2811 | abLocal.removeSyncAddressees( !isXML); | 2812 | abLocal.removeSyncAddressees( !isXML); |
2812 | qDebug("Saving remote AB "); | 2813 | qDebug("Saving remote AB "); |
2813 | if ( ! abLocal.saveAB()) | 2814 | if ( ! abLocal.saveAB()) |
2814 | qDebug("Error writing back AB to file "); | 2815 | qDebug("Error writing back AB to file "); |
2815 | if ( isXML ) { | 2816 | if ( external ) { |
2816 | // afterwrite processing | 2817 | // afterwrite processing |
2817 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); | 2818 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ,isXML); |
2818 | } | 2819 | } |
2819 | } | 2820 | } |
2820 | } | 2821 | } |
2821 | setModified(); | 2822 | setModified(); |
2822 | 2823 | ||
2823 | } | 2824 | } |
2824 | if ( syncOK ) | 2825 | if ( syncOK ) |
2825 | mViewManager->refreshView(); | 2826 | mViewManager->refreshView(); |
2826 | return syncOK; | 2827 | return syncOK; |
2827 | 2828 | ||
2828 | } | 2829 | } |
2829 | void KABCore::removeSyncInfo( QString syncProfile) | 2830 | void KABCore::removeSyncInfo( QString syncProfile) |
2830 | { | 2831 | { |
2831 | qDebug("AB:removeSyncInfo for profile %s ", syncProfile.latin1()); | 2832 | qDebug("AB:removeSyncInfo for profile %s ", syncProfile.latin1()); |
2832 | mAddressBook->removeSyncInfo( syncProfile ); | 2833 | mAddressBook->removeSyncInfo( syncProfile ); |
2834 | setModified(); | ||
2833 | } | 2835 | } |
2834 | 2836 | ||
2835 | 2837 | ||
2836 | //this is a overwritten callbackmethods from the syncinterface | 2838 | //this is a overwritten callbackmethods from the syncinterface |
2837 | bool KABCore::syncExternal(KSyncManager* manager, QString resource) | 2839 | bool KABCore::syncExternal(KSyncManager* manager, QString resource) |
2838 | { | 2840 | { |
2839 | if ( resource == "phone" ) | 2841 | if ( resource == "phone" ) |
2840 | return syncPhone(); | 2842 | return syncPhone(); |
2841 | disableBR( true ); | 2843 | disableBR( true ); |
2842 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); | 2844 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); |
2843 | 2845 | ||
2844 | AddressBook abLocal( resource,"syncContact"); | 2846 | AddressBook abLocal( resource,"syncContact"); |
2845 | bool syncOK = false; | 2847 | bool syncOK = false; |
2846 | if ( abLocal.load() ) { | 2848 | if ( abLocal.load() ) { |
2847 | qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); | 2849 | qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); |
2848 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 2850 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
2849 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, false ); | 2851 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, false ); |
2850 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); | 2852 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); |
2851 | if ( syncOK ) { | 2853 | if ( syncOK ) { |
2852 | if ( syncManager->mWriteBackFile ) { | 2854 | if ( syncManager->mWriteBackFile ) { |
2853 | abLocal.removeSyncAddressees( false ); | 2855 | abLocal.removeSyncAddressees( false ); |
2854 | abLocal.saveAB(); | 2856 | abLocal.saveAB(); |
2855 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); | 2857 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true ); |
2856 | } | 2858 | } |
2857 | } | 2859 | } |
2858 | setModified(); | 2860 | setModified(); |
2859 | } | 2861 | } |
2860 | if ( syncOK ) | 2862 | if ( syncOK ) |
2861 | mViewManager->refreshView(); | 2863 | mViewManager->refreshView(); |
2862 | disableBR( false ); | 2864 | disableBR( false ); |
2863 | return syncOK; | 2865 | return syncOK; |
2864 | 2866 | ||
2865 | } | 2867 | } |
2866 | void KABCore::message( QString m ) | 2868 | void KABCore::message( QString m ) |
2867 | { | 2869 | { |
2868 | topLevelWidget()->setCaption( m ); | 2870 | topLevelWidget()->setCaption( m ); |
2869 | mMessageTimer->start( 15000, true ); | 2871 | mMessageTimer->start( 15000, true ); |
2870 | } | 2872 | } |
2871 | bool KABCore::syncPhone() | 2873 | bool KABCore::syncPhone() |
2872 | { | 2874 | { |
2873 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); | 2875 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); |
2874 | QString fileName = getPhoneFile(); | 2876 | QString fileName = getPhoneFile(); |
2875 | if ( !PhoneAccess::readFromPhone( fileName) ) { | 2877 | if ( !PhoneAccess::readFromPhone( fileName) ) { |
2876 | message(i18n("Phone access failed!")); | 2878 | message(i18n("Phone access failed!")); |
2877 | return false; | 2879 | return false; |
2878 | } | 2880 | } |
2879 | AddressBook abLocal( fileName,"syncContact"); | 2881 | AddressBook abLocal( fileName,"syncContact"); |
2880 | bool syncOK = false; | 2882 | bool syncOK = false; |
2881 | { | 2883 | { |
2882 | abLocal.importFromFile( fileName ); | 2884 | abLocal.importFromFile( fileName ); |
2883 | qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1()); | 2885 | qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1()); |
2884 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 2886 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
2885 | abLocal.preparePhoneSync( mCurrentSyncDevice, true ); | 2887 | abLocal.preparePhoneSync( mCurrentSyncDevice, true ); |
2886 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); | 2888 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); |
2887 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); | 2889 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); |
2888 | if ( syncOK ) { | 2890 | if ( syncOK ) { |
2889 | if ( syncManager->mWriteBackFile ) { | 2891 | if ( syncManager->mWriteBackFile ) { |
2890 | abLocal.removeSyncAddressees( true ); | 2892 | abLocal.removeSyncAddressees( true ); |
2891 | abLocal.saveABphone( fileName ); | 2893 | abLocal.saveABphone( fileName ); |
2892 | abLocal.findNewExtIds( fileName, mCurrentSyncDevice ); | 2894 | abLocal.findNewExtIds( fileName, mCurrentSyncDevice ); |
2893 | //abLocal.preparePhoneSync( mCurrentSyncDevice, false ); | 2895 | //abLocal.preparePhoneSync( mCurrentSyncDevice, false ); |
2894 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); | 2896 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true ); |
2895 | } | 2897 | } |
2896 | } | 2898 | } |
2897 | setModified(); | 2899 | setModified(); |
2898 | } | 2900 | } |
2899 | if ( syncOK ) | 2901 | if ( syncOK ) |
2900 | mViewManager->refreshView(); | 2902 | mViewManager->refreshView(); |
2901 | return syncOK; | 2903 | return syncOK; |
2902 | } | 2904 | } |
2903 | void KABCore::getFile( bool success ) | 2905 | void KABCore::getFile( bool success ) |
2904 | { | 2906 | { |
2905 | if ( ! success ) { | 2907 | if ( ! success ) { |
2906 | message( i18n("Error receiving file. Nothing changed!") ); | 2908 | message( i18n("Error receiving file. Nothing changed!") ); |
2907 | return; | 2909 | return; |
2908 | } | 2910 | } |
2909 | int count = mAddressBook->importFromFile( sentSyncFile() , false, true ); | 2911 | int count = mAddressBook->importFromFile( sentSyncFile() , false, true ); |
2910 | if ( count ) | 2912 | if ( count ) |
2911 | setModified( true ); | 2913 | setModified( true ); |
2912 | message( i18n("Pi-Sync successful!") ); | 2914 | message( i18n("Pi-Sync successful!") ); |
2913 | mViewManager->refreshView(); | 2915 | mViewManager->refreshView(); |
2914 | } | 2916 | } |
2915 | void KABCore::syncFileRequest() | 2917 | void KABCore::syncFileRequest() |
2916 | { | 2918 | { |
2917 | if ( KABPrefs::instance()->mPassiveSyncWithDesktop ) { | 2919 | if ( KABPrefs::instance()->mPassiveSyncWithDesktop ) { |
2918 | syncManager->slotSyncMenu( 999 ); | 2920 | syncManager->slotSyncMenu( 999 ); |
2919 | } | 2921 | } |
2920 | mAddressBook->export2File( sentSyncFile() ); | 2922 | mAddressBook->export2File( sentSyncFile() ); |
2921 | } | 2923 | } |
2922 | QString KABCore::sentSyncFile() | 2924 | QString KABCore::sentSyncFile() |
2923 | { | 2925 | { |
2924 | #ifdef DESKTOP_VERSION | 2926 | #ifdef DESKTOP_VERSION |
2925 | return locateLocal( "tmp", "copysyncab.vcf" ); | 2927 | return locateLocal( "tmp", "copysyncab.vcf" ); |
2926 | #else | 2928 | #else |
2927 | return QString( "/tmp/copysyncab.vcf" ); | 2929 | return QString( "/tmp/copysyncab.vcf" ); |
2928 | #endif | 2930 | #endif |
2929 | } | 2931 | } |
2930 | 2932 | ||
2931 | void KABCore::setCaptionBack() | 2933 | void KABCore::setCaptionBack() |
2932 | { | 2934 | { |
2933 | mMessageTimer->stop(); | 2935 | mMessageTimer->stop(); |
2934 | topLevelWidget()->setCaption( i18n("KAddressbook/Pi") ); | 2936 | topLevelWidget()->setCaption( i18n("KAddressbook/Pi") ); |
2935 | } | 2937 | } |