author | zautrix <zautrix> | 2004-08-07 15:02:15 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-08-07 15:02:15 (UTC) |
commit | a9a774e19c02f03de948b6064804b913abd4f08b (patch) (unidiff) | |
tree | 351a08e627bc661f9b69a0af7452f9749865e619 /korganizer | |
parent | 31764784e8753157a936e42e21dcdc41bd8e2eb7 (diff) | |
download | kdepimpi-a9a774e19c02f03de948b6064804b913abd4f08b.zip kdepimpi-a9a774e19c02f03de948b6064804b913abd4f08b.tar.gz kdepimpi-a9a774e19c02f03de948b6064804b913abd4f08b.tar.bz2 |
more Sync fixes
-rw-r--r-- | korganizer/calendarview.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp index 5150455..f859b90 100644 --- a/korganizer/calendarview.cpp +++ b/korganizer/calendarview.cpp | |||
@@ -698,401 +698,404 @@ void CalendarView::confSync() | |||
698 | sp->exec(); | 698 | sp->exec(); |
699 | KOPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames(); | 699 | KOPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames(); |
700 | KOPrefs::instance()->mLocalMachineName = sp->getLocalMachineName (); | 700 | KOPrefs::instance()->mLocalMachineName = sp->getLocalMachineName (); |
701 | } | 701 | } |
702 | 702 | ||
703 | 703 | ||
704 | //KOPrefs::instance()->mWriteBackFile | 704 | //KOPrefs::instance()->mWriteBackFile |
705 | //KOPrefs::instance()->mWriteBackExistingOnly | 705 | //KOPrefs::instance()->mWriteBackExistingOnly |
706 | 706 | ||
707 | // 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); | 707 | // 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); |
708 | // 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); | 708 | // 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); |
709 | // 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); | 709 | // 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); |
710 | // 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); | 710 | // 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); |
711 | // 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); | 711 | // 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); |
712 | // 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); | 712 | // 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); |
713 | 713 | ||
714 | int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) | 714 | int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) |
715 | { | 715 | { |
716 | 716 | ||
717 | //void setZaurusId(int id); | 717 | //void setZaurusId(int id); |
718 | // int zaurusId() const; | 718 | // int zaurusId() const; |
719 | // void setZaurusUid(int id); | 719 | // void setZaurusUid(int id); |
720 | // int zaurusUid() const; | 720 | // int zaurusUid() const; |
721 | // void setZaurusStat(int id); | 721 | // void setZaurusStat(int id); |
722 | // int zaurusStat() const; | 722 | // int zaurusStat() const; |
723 | // 0 equal | 723 | // 0 equal |
724 | // 1 take local | 724 | // 1 take local |
725 | // 2 take remote | 725 | // 2 take remote |
726 | // 3 cancel | 726 | // 3 cancel |
727 | QDateTime lastSync = mLastCalendarSync; | 727 | QDateTime lastSync = mLastCalendarSync; |
728 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 728 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
729 | bool remCh, locCh; | 729 | bool remCh, locCh; |
730 | remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); | 730 | remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); |
731 | locCh = ( local->lastModified() > mLastCalendarSync ); | 731 | locCh = ( local->lastModified() > mLastCalendarSync ); |
732 | //qDebug("locCh %d remCh %d locuid %d remuid %d", locCh, remCh,local->zaurusUid(), remote->zaurusUid() ); | 732 | //qDebug("locCh %d remCh %d locuid %d remuid %d", locCh, remCh,local->zaurusUid(), remote->zaurusUid() ); |
733 | if ( !remCh && ! locCh ) { | 733 | if ( !remCh && ! locCh ) { |
734 | //qDebug("both not changed "); | 734 | //qDebug("both not changed "); |
735 | lastSync = local->lastModified().addDays(1); | 735 | lastSync = local->lastModified().addDays(1); |
736 | } else { | 736 | } else { |
737 | if ( locCh ) { | 737 | if ( locCh ) { |
738 | //qDebug("loc changed %d %d", local->zaurusStat(), local->revision() ); | 738 | //qDebug("loc changed %d %d", local->zaurusStat(), local->revision() ); |
739 | lastSync = local->lastModified().addDays( -1 ); | 739 | lastSync = local->lastModified().addDays( -1 ); |
740 | if ( !remCh ) | 740 | if ( !remCh ) |
741 | remote->setLastModified( lastSync.addDays( -1 ) ); | 741 | remote->setLastModified( lastSync.addDays( -1 ) ); |
742 | } else { | 742 | } else { |
743 | //qDebug(" not loc changed "); | 743 | //qDebug(" not loc changed "); |
744 | lastSync = local->lastModified().addDays( 1 ); | 744 | lastSync = local->lastModified().addDays( 1 ); |
745 | if ( remCh ) | 745 | if ( remCh ) |
746 | remote->setLastModified( lastSync.addDays( 1 ) ); | 746 | remote->setLastModified( lastSync.addDays( 1 ) ); |
747 | 747 | ||
748 | } | 748 | } |
749 | } | 749 | } |
750 | full = true; | 750 | full = true; |
751 | if ( mode < SYNC_PREF_ASK ) | 751 | if ( mode < SYNC_PREF_ASK ) |
752 | mode = SYNC_PREF_ASK; | 752 | mode = SYNC_PREF_ASK; |
753 | } else { | 753 | } else { |
754 | if ( local->lastModified() == remote->lastModified() ) | 754 | if ( local->lastModified() == remote->lastModified() ) |
755 | if ( local->revision() == remote->revision() ) | 755 | if ( local->revision() == remote->revision() ) |
756 | return 0; | 756 | return 0; |
757 | 757 | ||
758 | } | 758 | } |
759 | // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); | 759 | // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); |
760 | 760 | ||
761 | //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , local->revision(), remote->lastModified().toString().latin1(), remote->revision()); | 761 | //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , local->revision(), remote->lastModified().toString().latin1(), remote->revision()); |
762 | //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); | 762 | //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); |
763 | //full = true; //debug only | 763 | //full = true; //debug only |
764 | if ( full ) { | 764 | if ( full ) { |
765 | bool equ = false; | 765 | bool equ = false; |
766 | if ( local->type() == "Event" ) { | 766 | if ( local->type() == "Event" ) { |
767 | equ = (*((Event*) local) == *((Event*) remote)); | 767 | equ = (*((Event*) local) == *((Event*) remote)); |
768 | } | 768 | } |
769 | else if ( local->type() =="Todo" ) | 769 | else if ( local->type() =="Todo" ) |
770 | equ = (*((Todo*) local) == (*(Todo*) remote)); | 770 | equ = (*((Todo*) local) == (*(Todo*) remote)); |
771 | else if ( local->type() =="Journal" ) | 771 | else if ( local->type() =="Journal" ) |
772 | equ = (*((Journal*) local) == *((Journal*) remote)); | 772 | equ = (*((Journal*) local) == *((Journal*) remote)); |
773 | if ( equ ) { | 773 | if ( equ ) { |
774 | //qDebug("equal "); | 774 | //qDebug("equal "); |
775 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 775 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
776 | local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); | 776 | local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); |
777 | } | 777 | } |
778 | if ( mode < SYNC_PREF_FORCE_LOCAL ) | 778 | if ( mode < SYNC_PREF_FORCE_LOCAL ) |
779 | return 0; | 779 | return 0; |
780 | 780 | ||
781 | }//else //debug only | 781 | }//else //debug only |
782 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); | 782 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); |
783 | } | 783 | } |
784 | int result; | 784 | int result; |
785 | bool localIsNew; | 785 | bool localIsNew; |
786 | if ( full && mode < SYNC_PREF_NEWEST ) | 786 | if ( full && mode < SYNC_PREF_NEWEST ) |
787 | mode = SYNC_PREF_ASK; | 787 | mode = SYNC_PREF_ASK; |
788 | 788 | ||
789 | switch( mode ) { | 789 | switch( mode ) { |
790 | case SYNC_PREF_LOCAL: | 790 | case SYNC_PREF_LOCAL: |
791 | if ( lastSync > remote->lastModified() ) | 791 | if ( lastSync > remote->lastModified() ) |
792 | return 1; | 792 | return 1; |
793 | if ( lastSync > local->lastModified() ) | 793 | if ( lastSync > local->lastModified() ) |
794 | return 2; | 794 | return 2; |
795 | return 1; | 795 | return 1; |
796 | break; | 796 | break; |
797 | case SYNC_PREF_REMOTE: | 797 | case SYNC_PREF_REMOTE: |
798 | if ( lastSync > remote->lastModified() ) | 798 | if ( lastSync > remote->lastModified() ) |
799 | return 1; | 799 | return 1; |
800 | if ( lastSync > local->lastModified() ) | 800 | if ( lastSync > local->lastModified() ) |
801 | return 2; | 801 | return 2; |
802 | return 2; | 802 | return 2; |
803 | break; | 803 | break; |
804 | case SYNC_PREF_NEWEST: | 804 | case SYNC_PREF_NEWEST: |
805 | if ( local->lastModified() > remote->lastModified() ) | 805 | if ( local->lastModified() > remote->lastModified() ) |
806 | return 1; | 806 | return 1; |
807 | else | 807 | else |
808 | return 2; | 808 | return 2; |
809 | break; | 809 | break; |
810 | case SYNC_PREF_ASK: | 810 | case SYNC_PREF_ASK: |
811 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() ); | 811 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() ); |
812 | if ( lastSync > remote->lastModified() ) | 812 | if ( lastSync > remote->lastModified() ) |
813 | return 1; | 813 | return 1; |
814 | if ( lastSync > local->lastModified() ) | 814 | if ( lastSync > local->lastModified() ) |
815 | return 2; | 815 | return 2; |
816 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() ); | 816 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() ); |
817 | localIsNew = local->lastModified() > remote->lastModified(); | 817 | localIsNew = local->lastModified() > remote->lastModified(); |
818 | if ( localIsNew ) | 818 | if ( localIsNew ) |
819 | getEventViewerDialog()->setColorMode( 1 ); | 819 | getEventViewerDialog()->setColorMode( 1 ); |
820 | else | 820 | else |
821 | getEventViewerDialog()->setColorMode( 2 ); | 821 | getEventViewerDialog()->setColorMode( 2 ); |
822 | getEventViewerDialog()->setIncidence(local); | 822 | getEventViewerDialog()->setIncidence(local); |
823 | if ( localIsNew ) | 823 | if ( localIsNew ) |
824 | getEventViewerDialog()->setColorMode( 2 ); | 824 | getEventViewerDialog()->setColorMode( 2 ); |
825 | else | 825 | else |
826 | getEventViewerDialog()->setColorMode( 1 ); | 826 | getEventViewerDialog()->setColorMode( 1 ); |
827 | getEventViewerDialog()->addIncidence(remote); | 827 | getEventViewerDialog()->addIncidence(remote); |
828 | getEventViewerDialog()->setColorMode( 0 ); | 828 | getEventViewerDialog()->setColorMode( 0 ); |
829 | //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); | 829 | //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); |
830 | getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); | 830 | getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); |
831 | getEventViewerDialog()->showMe(); | 831 | getEventViewerDialog()->showMe(); |
832 | result = getEventViewerDialog()->executeS( localIsNew ); | 832 | result = getEventViewerDialog()->executeS( localIsNew ); |
833 | return result; | 833 | return result; |
834 | 834 | ||
835 | break; | 835 | break; |
836 | case SYNC_PREF_FORCE_LOCAL: | 836 | case SYNC_PREF_FORCE_LOCAL: |
837 | return 1; | 837 | return 1; |
838 | break; | 838 | break; |
839 | case SYNC_PREF_FORCE_REMOTE: | 839 | case SYNC_PREF_FORCE_REMOTE: |
840 | return 2; | 840 | return 2; |
841 | break; | 841 | break; |
842 | 842 | ||
843 | default: | 843 | default: |
844 | // SYNC_PREF_TAKE_BOTH not implemented | 844 | // SYNC_PREF_TAKE_BOTH not implemented |
845 | break; | 845 | break; |
846 | } | 846 | } |
847 | return 0; | 847 | return 0; |
848 | } | 848 | } |
849 | Event* CalendarView::getLastSyncEvent() | 849 | Event* CalendarView::getLastSyncEvent() |
850 | { | 850 | { |
851 | Event* lse; | 851 | Event* lse; |
852 | //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); | 852 | //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); |
853 | lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); | 853 | lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); |
854 | if (!lse) { | 854 | if (!lse) { |
855 | lse = new Event(); | 855 | lse = new Event(); |
856 | lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); | 856 | lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); |
857 | QString sum = ""; | 857 | QString sum = ""; |
858 | if ( KOPrefs::instance()->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) | 858 | if ( KOPrefs::instance()->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) |
859 | sum = "E: "; | 859 | sum = "E: "; |
860 | lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); | 860 | lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); |
861 | lse->setDtStart( mLastCalendarSync ); | 861 | lse->setDtStart( mLastCalendarSync ); |
862 | lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); | 862 | lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); |
863 | lse->setCategories( i18n("SyncEvent") ); | 863 | lse->setCategories( i18n("SyncEvent") ); |
864 | lse->setReadOnly( true ); | 864 | lse->setReadOnly( true ); |
865 | mCalendar->addEvent( lse ); | 865 | mCalendar->addEvent( lse ); |
866 | } | 866 | } |
867 | 867 | ||
868 | return lse; | 868 | return lse; |
869 | 869 | ||
870 | } | 870 | } |
871 | // probaly useless | 871 | // probaly useless |
872 | void CalendarView::setupExternSyncProfiles() | 872 | void CalendarView::setupExternSyncProfiles() |
873 | { | 873 | { |
874 | Event* lse; | 874 | Event* lse; |
875 | mExternLastSyncEvent.clear(); | 875 | mExternLastSyncEvent.clear(); |
876 | int i; | 876 | int i; |
877 | for ( i = 0; i < KOPrefs::instance()->mExternSyncProfiles.count(); ++i ) { | 877 | for ( i = 0; i < KOPrefs::instance()->mExternSyncProfiles.count(); ++i ) { |
878 | lse = mCalendar->event( "last-syncEvent-"+ KOPrefs::instance()->mExternSyncProfiles[i] ); | 878 | lse = mCalendar->event( "last-syncEvent-"+ KOPrefs::instance()->mExternSyncProfiles[i] ); |
879 | if ( lse ) | 879 | if ( lse ) |
880 | mExternLastSyncEvent.append( lse ); | 880 | mExternLastSyncEvent.append( lse ); |
881 | else | 881 | else |
882 | qDebug("Last Sync event not found for %s ", KOPrefs::instance()->mExternSyncProfiles[i].latin1()); | 882 | qDebug("Last Sync event not found for %s ", KOPrefs::instance()->mExternSyncProfiles[i].latin1()); |
883 | } | 883 | } |
884 | 884 | ||
885 | } | 885 | } |
886 | // we check, if the to delete event has a id for a profile | 886 | // we check, if the to delete event has a id for a profile |
887 | // if yes, we set this id in the profile to delete | 887 | // if yes, we set this id in the profile to delete |
888 | void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) | 888 | void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) |
889 | { | 889 | { |
890 | if ( ! lastSync.count() == 0 ) | 890 | if ( lastSync.count() == 0 ) { |
891 | //qDebug(" lastSync.count() == 0"); | ||
891 | return; | 892 | return; |
893 | } | ||
892 | if ( toDelete->type() == "Journal" ) | 894 | if ( toDelete->type() == "Journal" ) |
893 | return; | 895 | return; |
894 | 896 | ||
895 | Event* eve = lastSync.first(); | 897 | Event* eve = lastSync.first(); |
896 | 898 | ||
897 | while ( eve ) { | 899 | while ( eve ) { |
898 | QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name | 900 | QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name |
899 | if ( !id.isEmpty() ) { | 901 | if ( !id.isEmpty() ) { |
900 | QString des = eve->description(); | 902 | QString des = eve->description(); |
901 | QString pref = "e"; | 903 | QString pref = "e"; |
902 | if ( toDelete->type() == "Todo" ) | 904 | if ( toDelete->type() == "Todo" ) |
903 | pref = "t"; | 905 | pref = "t"; |
904 | des += pref+ id + ","; | 906 | des += pref+ id + ","; |
905 | eve->setReadOnly( false ); | 907 | eve->setReadOnly( false ); |
906 | eve->setDescription( des ); | 908 | eve->setDescription( des ); |
909 | //qDebug("setdes %s ", des.latin1()); | ||
907 | eve->setReadOnly( true ); | 910 | eve->setReadOnly( true ); |
908 | } | 911 | } |
909 | eve = lastSync.next(); | 912 | eve = lastSync.next(); |
910 | } | 913 | } |
911 | 914 | ||
912 | } | 915 | } |
913 | void CalendarView::checkExternalId( Incidence * inc ) | 916 | void CalendarView::checkExternalId( Incidence * inc ) |
914 | { | 917 | { |
915 | QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; | 918 | QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; |
916 | checkExternSyncEvent( lastSync, inc ); | 919 | checkExternSyncEvent( lastSync, inc ); |
917 | 920 | ||
918 | } | 921 | } |
919 | bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) | 922 | bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) |
920 | { | 923 | { |
921 | bool syncOK = true; | 924 | bool syncOK = true; |
922 | int addedEvent = 0; | 925 | int addedEvent = 0; |
923 | int addedEventR = 0; | 926 | int addedEventR = 0; |
924 | int deletedEventR = 0; | 927 | int deletedEventR = 0; |
925 | int deletedEventL = 0; | 928 | int deletedEventL = 0; |
926 | int changedLocal = 0; | 929 | int changedLocal = 0; |
927 | int changedRemote = 0; | 930 | int changedRemote = 0; |
928 | //QPtrList<Event> el = local->rawEvents(); | 931 | //QPtrList<Event> el = local->rawEvents(); |
929 | Event* eventR; | 932 | Event* eventR; |
930 | QString uid; | 933 | QString uid; |
931 | int take; | 934 | int take; |
932 | Event* eventL; | 935 | Event* eventL; |
933 | Event* eventRSync; | 936 | Event* eventRSync; |
934 | Event* eventLSync; | 937 | Event* eventLSync; |
935 | QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); | 938 | QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); |
936 | QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); | 939 | QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); |
937 | bool fullDateRange = false; | 940 | bool fullDateRange = false; |
938 | mLastCalendarSync = QDateTime::currentDateTime(); | 941 | mLastCalendarSync = QDateTime::currentDateTime(); |
939 | QDateTime modifiedCalendar = mLastCalendarSync;; | 942 | QDateTime modifiedCalendar = mLastCalendarSync;; |
940 | eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); | 943 | eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); |
941 | if ( eventR ) { | 944 | if ( eventR ) { |
942 | eventRSync = (Event*) eventR->clone(); | 945 | eventRSync = (Event*) eventR->clone(); |
943 | remote->deleteEvent(eventR ); | 946 | remote->deleteEvent(eventR ); |
944 | 947 | ||
945 | } else { | 948 | } else { |
946 | fullDateRange = true; | 949 | fullDateRange = true; |
947 | eventRSync = new Event(); | 950 | eventRSync = new Event(); |
948 | eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); | 951 | eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); |
949 | eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); | 952 | eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); |
950 | eventRSync->setDtStart( mLastCalendarSync ); | 953 | eventRSync->setDtStart( mLastCalendarSync ); |
951 | eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); | 954 | eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); |
952 | eventRSync->setCategories( i18n("SyncEvent") ); | 955 | eventRSync->setCategories( i18n("SyncEvent") ); |
953 | } | 956 | } |
954 | eventLSync = getLastSyncEvent(); | 957 | eventLSync = getLastSyncEvent(); |
955 | if ( eventLSync->dtStart() == mLastCalendarSync ) | 958 | if ( eventLSync->dtStart() == mLastCalendarSync ) |
956 | fullDateRange = true; | 959 | fullDateRange = true; |
957 | 960 | ||
958 | if ( ! fullDateRange ) { | 961 | if ( ! fullDateRange ) { |
959 | if ( eventLSync->dtStart() != eventRSync->dtStart() ) { | 962 | if ( eventLSync->dtStart() != eventRSync->dtStart() ) { |
960 | 963 | ||
961 | // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); | 964 | // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); |
962 | //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); | 965 | //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); |
963 | fullDateRange = true; | 966 | fullDateRange = true; |
964 | } | 967 | } |
965 | } | 968 | } |
966 | if ( fullDateRange ) | 969 | if ( fullDateRange ) |
967 | mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); | 970 | mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); |
968 | else | 971 | else |
969 | mLastCalendarSync = eventLSync->dtStart(); | 972 | mLastCalendarSync = eventLSync->dtStart(); |
970 | // for resyncing if own file has changed | 973 | // for resyncing if own file has changed |
971 | if ( mCurrentSyncDevice == "deleteaftersync" ) { | 974 | if ( mCurrentSyncDevice == "deleteaftersync" ) { |
972 | mLastCalendarSync = loadedFileVersion; | 975 | mLastCalendarSync = loadedFileVersion; |
973 | qDebug("setting mLastCalendarSync "); | 976 | qDebug("setting mLastCalendarSync "); |
974 | } | 977 | } |
975 | //qDebug("*************************** "); | 978 | //qDebug("*************************** "); |
976 | qDebug("mLastCalendarSync %s ",mLastCalendarSync.toString().latin1() ); | 979 | qDebug("mLastCalendarSync %s ",mLastCalendarSync.toString().latin1() ); |
977 | QPtrList<Incidence> er = remote->rawIncidences(); | 980 | QPtrList<Incidence> er = remote->rawIncidences(); |
978 | Incidence* inR = er.first(); | 981 | Incidence* inR = er.first(); |
979 | Incidence* inL; | 982 | Incidence* inL; |
980 | QProgressBar bar( er.count(),0 ); | 983 | QProgressBar bar( er.count(),0 ); |
981 | bar.setCaption (i18n("Syncing - close to abort!") ); | 984 | bar.setCaption (i18n("Syncing - close to abort!") ); |
982 | 985 | ||
983 | int w = 300; | 986 | int w = 300; |
984 | if ( QApplication::desktop()->width() < 320 ) | 987 | if ( QApplication::desktop()->width() < 320 ) |
985 | w = 220; | 988 | w = 220; |
986 | int h = bar.sizeHint().height() ; | 989 | int h = bar.sizeHint().height() ; |
987 | int dw = QApplication::desktop()->width(); | 990 | int dw = QApplication::desktop()->width(); |
988 | int dh = QApplication::desktop()->height(); | 991 | int dh = QApplication::desktop()->height(); |
989 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 992 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
990 | bar.show(); | 993 | bar.show(); |
991 | int modulo = (er.count()/10)+1; | 994 | int modulo = (er.count()/10)+1; |
992 | int incCounter = 0; | 995 | int incCounter = 0; |
993 | while ( inR ) { | 996 | while ( inR ) { |
994 | if ( ! bar.isVisible() ) | 997 | if ( ! bar.isVisible() ) |
995 | return false; | 998 | return false; |
996 | if ( incCounter % modulo == 0 ) | 999 | if ( incCounter % modulo == 0 ) |
997 | bar.setProgress( incCounter ); | 1000 | bar.setProgress( incCounter ); |
998 | ++incCounter; | 1001 | ++incCounter; |
999 | uid = inR->uid(); | 1002 | uid = inR->uid(); |
1000 | bool skipIncidence = false; | 1003 | bool skipIncidence = false; |
1001 | if ( uid.left(15) == QString("last-syncEvent-") ) | 1004 | if ( uid.left(15) == QString("last-syncEvent-") ) |
1002 | skipIncidence = true; | 1005 | skipIncidence = true; |
1003 | 1006 | ||
1004 | qApp->processEvents(); | 1007 | qApp->processEvents(); |
1005 | if ( !skipIncidence ) { | 1008 | if ( !skipIncidence ) { |
1006 | inL = local->incidence( uid ); | 1009 | inL = local->incidence( uid ); |
1007 | if ( inL ) { // maybe conflict - same uid in both calendars | 1010 | if ( inL ) { // maybe conflict - same uid in both calendars |
1008 | int maxrev = inL->revision(); | 1011 | int maxrev = inL->revision(); |
1009 | if ( maxrev < inR->revision() ) | 1012 | if ( maxrev < inR->revision() ) |
1010 | maxrev = inR->revision(); | 1013 | maxrev = inR->revision(); |
1011 | if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { | 1014 | if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { |
1012 | //qDebug("take %d %s ", take, inL->summary().latin1()); | 1015 | //qDebug("take %d %s ", take, inL->summary().latin1()); |
1013 | if ( take == 3 ) | 1016 | if ( take == 3 ) |
1014 | return false; | 1017 | return false; |
1015 | if ( take == 1 ) {// take local | 1018 | if ( take == 1 ) {// take local |
1016 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); | 1019 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); |
1017 | remote->deleteIncidence( inR ); | 1020 | remote->deleteIncidence( inR ); |
1018 | if ( inL->revision() < maxrev ) | 1021 | if ( inL->revision() < maxrev ) |
1019 | inL->setRevision( maxrev ); | 1022 | inL->setRevision( maxrev ); |
1020 | remote->addIncidence( inL->clone() ); | 1023 | remote->addIncidence( inL->clone() ); |
1021 | ++changedRemote; | 1024 | ++changedRemote; |
1022 | } else { | 1025 | } else { |
1023 | if ( inR->revision() < maxrev ) | 1026 | if ( inR->revision() < maxrev ) |
1024 | inR->setRevision( maxrev ); | 1027 | inR->setRevision( maxrev ); |
1025 | local->deleteIncidence( inL ); | 1028 | local->deleteIncidence( inL ); |
1026 | local->addIncidence( inR->clone() ); | 1029 | local->addIncidence( inR->clone() ); |
1027 | ++changedLocal; | 1030 | ++changedLocal; |
1028 | } | 1031 | } |
1029 | } | 1032 | } |
1030 | } else { // no conflict | 1033 | } else { // no conflict |
1031 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 1034 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
1032 | QString des = eventLSync->description(); | 1035 | QString des = eventLSync->description(); |
1033 | QString pref = "e"; | 1036 | QString pref = "e"; |
1034 | if ( inR->type() == "Todo" ) | 1037 | if ( inR->type() == "Todo" ) |
1035 | pref = "t"; | 1038 | pref = "t"; |
1036 | if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it | 1039 | if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it |
1037 | inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); | 1040 | inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); |
1038 | //remote->deleteIncidence( inR ); | 1041 | //remote->deleteIncidence( inR ); |
1039 | ++deletedEventR; | 1042 | ++deletedEventR; |
1040 | } else { | 1043 | } else { |
1041 | inR->setLastModified( modifiedCalendar ); | 1044 | inR->setLastModified( modifiedCalendar ); |
1042 | local->addIncidence( inR->clone() ); | 1045 | local->addIncidence( inR->clone() ); |
1043 | ++addedEvent; | 1046 | ++addedEvent; |
1044 | } | 1047 | } |
1045 | } else { | 1048 | } else { |
1046 | if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { | 1049 | if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { |
1047 | inR->setLastModified( modifiedCalendar ); | 1050 | inR->setLastModified( modifiedCalendar ); |
1048 | local->addIncidence( inR->clone() ); | 1051 | local->addIncidence( inR->clone() ); |
1049 | ++addedEvent; | 1052 | ++addedEvent; |
1050 | } else { | 1053 | } else { |
1051 | checkExternSyncEvent(eventRSyncSharp, inR); | 1054 | checkExternSyncEvent(eventRSyncSharp, inR); |
1052 | remote->deleteIncidence( inR ); | 1055 | remote->deleteIncidence( inR ); |
1053 | ++deletedEventR; | 1056 | ++deletedEventR; |
1054 | } | 1057 | } |
1055 | } | 1058 | } |
1056 | } | 1059 | } |
1057 | } | 1060 | } |
1058 | inR = er.next(); | 1061 | inR = er.next(); |
1059 | } | 1062 | } |
1060 | QPtrList<Incidence> el = local->rawIncidences(); | 1063 | QPtrList<Incidence> el = local->rawIncidences(); |
1061 | inL = el.first(); | 1064 | inL = el.first(); |
1062 | modulo = (el.count()/10)+1; | 1065 | modulo = (el.count()/10)+1; |
1063 | bar.setCaption (i18n("Add / remove events") ); | 1066 | bar.setCaption (i18n("Add / remove events") ); |
1064 | bar.setTotalSteps ( el.count() ) ; | 1067 | bar.setTotalSteps ( el.count() ) ; |
1065 | bar.show(); | 1068 | bar.show(); |
1066 | incCounter = 0; | 1069 | incCounter = 0; |
1067 | 1070 | ||
1068 | while ( inL ) { | 1071 | while ( inL ) { |
1069 | 1072 | ||
1070 | qApp->processEvents(); | 1073 | qApp->processEvents(); |
1071 | if ( ! bar.isVisible() ) | 1074 | if ( ! bar.isVisible() ) |
1072 | return false; | 1075 | return false; |
1073 | if ( incCounter % modulo == 0 ) | 1076 | if ( incCounter % modulo == 0 ) |
1074 | bar.setProgress( incCounter ); | 1077 | bar.setProgress( incCounter ); |
1075 | ++incCounter; | 1078 | ++incCounter; |
1076 | uid = inL->uid(); | 1079 | uid = inL->uid(); |
1077 | bool skipIncidence = false; | 1080 | bool skipIncidence = false; |
1078 | if ( uid.left(15) == QString("last-syncEvent-") ) | 1081 | if ( uid.left(15) == QString("last-syncEvent-") ) |
1079 | skipIncidence = true; | 1082 | skipIncidence = true; |
1080 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) | 1083 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) |
1081 | skipIncidence = true; | 1084 | skipIncidence = true; |
1082 | if ( !skipIncidence ) { | 1085 | if ( !skipIncidence ) { |
1083 | inR = remote->incidence( uid ); | 1086 | inR = remote->incidence( uid ); |
1084 | if ( ! inR ) { | 1087 | if ( ! inR ) { |
1085 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 1088 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
1086 | if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { | 1089 | if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { |
1087 | local->deleteIncidence( inL ); | 1090 | local->deleteIncidence( inL ); |
1088 | ++deletedEventL; | 1091 | ++deletedEventL; |
1089 | } else { | 1092 | } else { |
1090 | if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { | 1093 | if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { |
1091 | inL->removeID(mCurrentSyncDevice ); | 1094 | inL->removeID(mCurrentSyncDevice ); |
1092 | ++addedEventR; | 1095 | ++addedEventR; |
1093 | inL->setLastModified( modifiedCalendar ); | 1096 | inL->setLastModified( modifiedCalendar ); |
1094 | remote->addIncidence( inL->clone() ); | 1097 | remote->addIncidence( inL->clone() ); |
1095 | } | 1098 | } |
1096 | } | 1099 | } |
1097 | } else { | 1100 | } else { |
1098 | if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { | 1101 | if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { |