-rw-r--r-- | korganizer/calendarview.cpp | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp index 258bd43..94cc97d 100644 --- a/korganizer/calendarview.cpp +++ b/korganizer/calendarview.cpp | |||
@@ -717,97 +717,97 @@ int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , b | |||
717 | 717 | ||
718 | //void setZaurusId(int id); | 718 | //void setZaurusId(int id); |
719 | // int zaurusId() const; | 719 | // int zaurusId() const; |
720 | // void setZaurusUid(int id); | 720 | // void setZaurusUid(int id); |
721 | // int zaurusUid() const; | 721 | // int zaurusUid() const; |
722 | // void setZaurusStat(int id); | 722 | // void setZaurusStat(int id); |
723 | // int zaurusStat() const; | 723 | // int zaurusStat() const; |
724 | // 0 equal | 724 | // 0 equal |
725 | // 1 take local | 725 | // 1 take local |
726 | // 2 take remote | 726 | // 2 take remote |
727 | // 3 cancel | 727 | // 3 cancel |
728 | QDateTime lastSync = mLastCalendarSync; | 728 | QDateTime lastSync = mLastCalendarSync; |
729 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 729 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
730 | bool remCh, locCh; | 730 | bool remCh, locCh; |
731 | remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); | 731 | remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); |
732 | if ( remCh ) | 732 | if ( remCh ) |
733 | qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); | 733 | qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); |
734 | locCh = ( local->lastModified() > mLastCalendarSync ); | 734 | locCh = ( local->lastModified() > mLastCalendarSync ); |
735 | //qDebug("locCh %d remCh %d locuid %d remuid %d", locCh, remCh,local->zaurusUid(), remote->zaurusUid() ); | 735 | //qDebug("locCh %d remCh %d locuid %d remuid %d", locCh, remCh,local->zaurusUid(), remote->zaurusUid() ); |
736 | if ( !remCh && ! locCh ) { | 736 | if ( !remCh && ! locCh ) { |
737 | qDebug("both not changed "); | 737 | qDebug("both not changed "); |
738 | lastSync = local->lastModified().addDays(1); | 738 | lastSync = local->lastModified().addDays(1); |
739 | } else { | 739 | } else { |
740 | if ( locCh ) { | 740 | if ( locCh ) { |
741 | qDebug("loc changed %d", local->revision() ); | 741 | qDebug("loc changed %d %s %s", local->revision() , local->lastModified().toString().latin1(), mLastCalendarSync.toString().latin1()); |
742 | lastSync = local->lastModified().addDays( -1 ); | 742 | lastSync = local->lastModified().addDays( -1 ); |
743 | if ( !remCh ) | 743 | if ( !remCh ) |
744 | remote->setLastModified( lastSync.addDays( -1 ) ); | 744 | remote->setLastModified( lastSync.addDays( -1 ) ); |
745 | } else { | 745 | } else { |
746 | qDebug(" not loc changed "); | 746 | qDebug(" not loc changed "); |
747 | lastSync = local->lastModified().addDays( 1 ); | 747 | lastSync = local->lastModified().addDays( 1 ); |
748 | if ( remCh ) | 748 | if ( remCh ) |
749 | remote->setLastModified( lastSync.addDays( 1 ) ); | 749 | remote->setLastModified( lastSync.addDays( 1 ) ); |
750 | 750 | ||
751 | } | 751 | } |
752 | } | 752 | } |
753 | full = true; | 753 | full = true; |
754 | if ( mode < SYNC_PREF_ASK ) | 754 | if ( mode < SYNC_PREF_ASK ) |
755 | mode = SYNC_PREF_ASK; | 755 | mode = SYNC_PREF_ASK; |
756 | } else { | 756 | } else { |
757 | if ( local->lastModified() == remote->lastModified() ) | 757 | if ( local->lastModified() == remote->lastModified() ) |
758 | if ( local->revision() == remote->revision() ) | 758 | if ( local->revision() == remote->revision() ) |
759 | return 0; | 759 | return 0; |
760 | 760 | ||
761 | } | 761 | } |
762 | // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); | 762 | // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); |
763 | 763 | ||
764 | //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , local->revision(), remote->lastModified().toString().latin1(), remote->revision()); | 764 | //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , local->revision(), remote->lastModified().toString().latin1(), remote->revision()); |
765 | //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); | 765 | //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); |
766 | //full = true; //debug only | 766 | //full = true; //debug only |
767 | if ( full ) { | 767 | if ( full ) { |
768 | bool equ = false; | 768 | bool equ = false; |
769 | if ( local->type() == "Event" ) { | 769 | if ( local->type() == "Event" ) { |
770 | equ = (*((Event*) local) == *((Event*) remote)); | 770 | equ = (*((Event*) local) == *((Event*) remote)); |
771 | } | 771 | } |
772 | else if ( local->type() =="Todo" ) | 772 | else if ( local->type() =="Todo" ) |
773 | equ = (*((Todo*) local) == (*(Todo*) remote)); | 773 | equ = (*((Todo*) local) == (*(Todo*) remote)); |
774 | else if ( local->type() =="Journal" ) | 774 | else if ( local->type() =="Journal" ) |
775 | equ = (*((Journal*) local) == *((Journal*) remote)); | 775 | equ = (*((Journal*) local) == *((Journal*) remote)); |
776 | if ( equ ) { | 776 | if ( equ ) { |
777 | //qDebug("equal "); | 777 | //qDebug("equal "); |
778 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 778 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
779 | local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); | 779 | local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); |
780 | } | 780 | } |
781 | if ( mode < SYNC_PREF_FORCE_LOCAL ) | 781 | if ( mode < SYNC_PREF_FORCE_LOCAL ) |
782 | return 0; | 782 | return 0; |
783 | 783 | ||
784 | }//else //debug only | 784 | }//else //debug only |
785 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); | 785 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); |
786 | } | 786 | } |
787 | int result; | 787 | int result; |
788 | bool localIsNew; | 788 | bool localIsNew; |
789 | qDebug("mLastCalendarSync %s lastsync %s --- local %s remote %s ",mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); | 789 | //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() ); |
790 | 790 | ||
791 | if ( full && mode < SYNC_PREF_NEWEST ) | 791 | if ( full && mode < SYNC_PREF_NEWEST ) |
792 | mode = SYNC_PREF_ASK; | 792 | mode = SYNC_PREF_ASK; |
793 | 793 | ||
794 | switch( mode ) { | 794 | switch( mode ) { |
795 | case SYNC_PREF_LOCAL: | 795 | case SYNC_PREF_LOCAL: |
796 | if ( lastSync > remote->lastModified() ) | 796 | if ( lastSync > remote->lastModified() ) |
797 | return 1; | 797 | return 1; |
798 | if ( lastSync > local->lastModified() ) | 798 | if ( lastSync > local->lastModified() ) |
799 | return 2; | 799 | return 2; |
800 | return 1; | 800 | return 1; |
801 | break; | 801 | break; |
802 | case SYNC_PREF_REMOTE: | 802 | case SYNC_PREF_REMOTE: |
803 | if ( lastSync > remote->lastModified() ) | 803 | if ( lastSync > remote->lastModified() ) |
804 | return 1; | 804 | return 1; |
805 | if ( lastSync > local->lastModified() ) | 805 | if ( lastSync > local->lastModified() ) |
806 | return 2; | 806 | return 2; |
807 | return 2; | 807 | return 2; |
808 | break; | 808 | break; |
809 | case SYNC_PREF_NEWEST: | 809 | case SYNC_PREF_NEWEST: |
810 | if ( local->lastModified() > remote->lastModified() ) | 810 | if ( local->lastModified() > remote->lastModified() ) |
811 | return 1; | 811 | return 1; |
812 | else | 812 | else |
813 | return 2; | 813 | return 2; |
@@ -1009,71 +1009,74 @@ bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int | |||
1009 | if ( incCounter % modulo == 0 ) | 1009 | if ( incCounter % modulo == 0 ) |
1010 | bar.setProgress( incCounter ); | 1010 | bar.setProgress( incCounter ); |
1011 | ++incCounter; | 1011 | ++incCounter; |
1012 | uid = inR->uid(); | 1012 | uid = inR->uid(); |
1013 | bool skipIncidence = false; | 1013 | bool skipIncidence = false; |
1014 | if ( uid.left(15) == QString("last-syncEvent-") ) | 1014 | if ( uid.left(15) == QString("last-syncEvent-") ) |
1015 | skipIncidence = true; | 1015 | skipIncidence = true; |
1016 | 1016 | ||
1017 | qApp->processEvents(); | 1017 | qApp->processEvents(); |
1018 | if ( !skipIncidence ) { | 1018 | if ( !skipIncidence ) { |
1019 | inL = local->incidence( uid ); | 1019 | inL = local->incidence( uid ); |
1020 | if ( inL ) { // maybe conflict - same uid in both calendars | 1020 | if ( inL ) { // maybe conflict - same uid in both calendars |
1021 | int maxrev = inL->revision(); | 1021 | int maxrev = inL->revision(); |
1022 | if ( maxrev < inR->revision() ) | 1022 | if ( maxrev < inR->revision() ) |
1023 | maxrev = inR->revision(); | 1023 | maxrev = inR->revision(); |
1024 | if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { | 1024 | if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { |
1025 | //qDebug("take %d %s ", take, inL->summary().latin1()); | 1025 | //qDebug("take %d %s ", take, inL->summary().latin1()); |
1026 | if ( take == 3 ) | 1026 | if ( take == 3 ) |
1027 | return false; | 1027 | return false; |
1028 | if ( take == 1 ) {// take local | 1028 | if ( take == 1 ) {// take local |
1029 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); | 1029 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); |
1030 | remote->deleteIncidence( inR ); | 1030 | remote->deleteIncidence( inR ); |
1031 | if ( inL->revision() < maxrev ) | 1031 | if ( inL->revision() < maxrev ) |
1032 | inL->setRevision( maxrev ); | 1032 | inL->setRevision( maxrev ); |
1033 | remote->addIncidence( inL->clone() ); | 1033 | inR = inL->clone(); |
1034 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | ||
1035 | remote->addIncidence( inR ); | ||
1034 | ++changedRemote; | 1036 | ++changedRemote; |
1035 | } else { | 1037 | } else { |
1036 | if ( inR->revision() < maxrev ) | 1038 | if ( inR->revision() < maxrev ) |
1037 | inR->setRevision( maxrev ); | 1039 | inR->setRevision( maxrev ); |
1038 | local->deleteIncidence( inL ); | 1040 | local->deleteIncidence( inL ); |
1039 | local->addIncidence( inR->clone() ); | 1041 | local->addIncidence( inR->clone() ); |
1040 | ++changedLocal; | 1042 | ++changedLocal; |
1041 | } | 1043 | } |
1042 | } | 1044 | } |
1043 | } else { // no conflict | 1045 | } else { // no conflict |
1044 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 1046 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
1045 | QString des = eventLSync->description(); | 1047 | QString des = eventLSync->description(); |
1046 | QString pref = "e"; | 1048 | QString pref = "e"; |
1047 | if ( inR->type() == "Todo" ) | 1049 | if ( inR->type() == "Todo" ) |
1048 | pref = "t"; | 1050 | pref = "t"; |
1049 | if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it | 1051 | if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it |
1050 | inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); | 1052 | inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); |
1051 | //remote->deleteIncidence( inR ); | 1053 | //remote->deleteIncidence( inR ); |
1052 | ++deletedEventR; | 1054 | ++deletedEventR; |
1053 | } else { | 1055 | } else { |
1054 | inR->setLastModified( modifiedCalendar ); | 1056 | inR->setLastModified( modifiedCalendar ); |
1055 | local->addIncidence( inR->clone() ); | 1057 | inL = inR->clone(); |
1058 | local->addIncidence( inL ); | ||
1056 | ++addedEvent; | 1059 | ++addedEvent; |
1057 | } | 1060 | } |
1058 | } else { | 1061 | } else { |
1059 | if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { | 1062 | if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { |
1060 | inR->setLastModified( modifiedCalendar ); | 1063 | inR->setLastModified( modifiedCalendar ); |
1061 | local->addIncidence( inR->clone() ); | 1064 | local->addIncidence( inR->clone() ); |
1062 | ++addedEvent; | 1065 | ++addedEvent; |
1063 | } else { | 1066 | } else { |
1064 | checkExternSyncEvent(eventRSyncSharp, inR); | 1067 | checkExternSyncEvent(eventRSyncSharp, inR); |
1065 | remote->deleteIncidence( inR ); | 1068 | remote->deleteIncidence( inR ); |
1066 | ++deletedEventR; | 1069 | ++deletedEventR; |
1067 | } | 1070 | } |
1068 | } | 1071 | } |
1069 | } | 1072 | } |
1070 | } | 1073 | } |
1071 | inR = er.next(); | 1074 | inR = er.next(); |
1072 | } | 1075 | } |
1073 | QPtrList<Incidence> el = local->rawIncidences(); | 1076 | QPtrList<Incidence> el = local->rawIncidences(); |
1074 | inL = el.first(); | 1077 | inL = el.first(); |
1075 | modulo = (el.count()/10)+1; | 1078 | modulo = (el.count()/10)+1; |
1076 | bar.setCaption (i18n("Add / remove events") ); | 1079 | bar.setCaption (i18n("Add / remove events") ); |
1077 | bar.setTotalSteps ( el.count() ) ; | 1080 | bar.setTotalSteps ( el.count() ) ; |
1078 | bar.show(); | 1081 | bar.show(); |
1079 | incCounter = 0; | 1082 | incCounter = 0; |
@@ -1082,50 +1085,53 @@ bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int | |||
1082 | 1085 | ||
1083 | qApp->processEvents(); | 1086 | qApp->processEvents(); |
1084 | if ( ! bar.isVisible() ) | 1087 | if ( ! bar.isVisible() ) |
1085 | return false; | 1088 | return false; |
1086 | if ( incCounter % modulo == 0 ) | 1089 | if ( incCounter % modulo == 0 ) |
1087 | bar.setProgress( incCounter ); | 1090 | bar.setProgress( incCounter ); |
1088 | ++incCounter; | 1091 | ++incCounter; |
1089 | uid = inL->uid(); | 1092 | uid = inL->uid(); |
1090 | bool skipIncidence = false; | 1093 | bool skipIncidence = false; |
1091 | if ( uid.left(15) == QString("last-syncEvent-") ) | 1094 | if ( uid.left(15) == QString("last-syncEvent-") ) |
1092 | skipIncidence = true; | 1095 | skipIncidence = true; |
1093 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) | 1096 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) |
1094 | skipIncidence = true; | 1097 | skipIncidence = true; |
1095 | if ( !skipIncidence ) { | 1098 | if ( !skipIncidence ) { |
1096 | inR = remote->incidence( uid ); | 1099 | inR = remote->incidence( uid ); |
1097 | if ( ! inR ) { | 1100 | if ( ! inR ) { |
1098 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 1101 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
1099 | if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { | 1102 | if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { |
1100 | local->deleteIncidence( inL ); | 1103 | local->deleteIncidence( inL ); |
1101 | ++deletedEventL; | 1104 | ++deletedEventL; |
1102 | } else { | 1105 | } else { |
1103 | if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { | 1106 | if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { |
1104 | inL->removeID(mCurrentSyncDevice ); | 1107 | inL->removeID(mCurrentSyncDevice ); |
1105 | ++addedEventR; | 1108 | ++addedEventR; |
1109 | qDebug("remote added Incidence %s ", inL->summary().latin1()); | ||
1106 | inL->setLastModified( modifiedCalendar ); | 1110 | inL->setLastModified( modifiedCalendar ); |
1107 | remote->addIncidence( inL->clone() ); | 1111 | inR = inL->clone(); |
1112 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | ||
1113 | remote->addIncidence( inR ); | ||
1108 | } | 1114 | } |
1109 | } | 1115 | } |
1110 | } else { | 1116 | } else { |
1111 | if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { | 1117 | if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { |
1112 | checkExternSyncEvent(eventLSyncSharp, inL); | 1118 | checkExternSyncEvent(eventLSyncSharp, inL); |
1113 | local->deleteIncidence( inL ); | 1119 | local->deleteIncidence( inL ); |
1114 | ++deletedEventL; | 1120 | ++deletedEventL; |
1115 | } else { | 1121 | } else { |
1116 | if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { | 1122 | if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { |
1117 | ++addedEventR; | 1123 | ++addedEventR; |
1118 | inL->setLastModified( modifiedCalendar ); | 1124 | inL->setLastModified( modifiedCalendar ); |
1119 | remote->addIncidence( inL->clone() ); | 1125 | remote->addIncidence( inL->clone() ); |
1120 | } | 1126 | } |
1121 | } | 1127 | } |
1122 | } | 1128 | } |
1123 | } | 1129 | } |
1124 | } | 1130 | } |
1125 | inL = el.next(); | 1131 | inL = el.next(); |
1126 | } | 1132 | } |
1127 | int delFut = 0; | 1133 | int delFut = 0; |
1128 | if ( KOPrefs::instance()->mWriteBackInFuture ) { | 1134 | if ( KOPrefs::instance()->mWriteBackInFuture ) { |
1129 | er = remote->rawIncidences(); | 1135 | er = remote->rawIncidences(); |
1130 | inR = er.first(); | 1136 | inR = er.first(); |
1131 | QDateTime dt; | 1137 | QDateTime dt; |