author | zautrix <zautrix> | 2004-09-14 01:59:37 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-09-14 01:59:37 (UTC) |
commit | 739fec31c8cea89dd40ff1ce7dd7b84b05e4e973 (patch) (unidiff) | |
tree | e632528a6825911b1b7ae9db9af4e4c8984e6dbf | |
parent | 30762fe125216362e1a6c1d5ec5d22d9525aa336 (diff) | |
download | kdepimpi-739fec31c8cea89dd40ff1ce7dd7b84b05e4e973.zip kdepimpi-739fec31c8cea89dd40ff1ce7dd7b84b05e4e973.tar.gz kdepimpi-739fec31c8cea89dd40ff1ce7dd7b84b05e4e973.tar.bz2 |
Sync fixes
-rw-r--r-- | korganizer/calendarview.cpp | 15 | ||||
-rw-r--r-- | libkcal/event.cpp | 1 |
2 files changed, 12 insertions, 4 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp index 94cc97d..ce41fbd 100644 --- a/korganizer/calendarview.cpp +++ b/korganizer/calendarview.cpp | |||
@@ -760,599 +760,608 @@ int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , b | |||
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("%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() ); | 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; |
814 | break; | 814 | break; |
815 | case SYNC_PREF_ASK: | 815 | case SYNC_PREF_ASK: |
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 | if ( lastSync > remote->lastModified() ) | 817 | if ( lastSync > remote->lastModified() ) |
818 | return 1; | 818 | return 1; |
819 | if ( lastSync > local->lastModified() ) | 819 | if ( lastSync > local->lastModified() ) |
820 | return 2; | 820 | return 2; |
821 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() ); | 821 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() ); |
822 | localIsNew = local->lastModified() >= remote->lastModified(); | 822 | localIsNew = local->lastModified() >= remote->lastModified(); |
823 | if ( localIsNew ) | 823 | if ( localIsNew ) |
824 | getEventViewerDialog()->setColorMode( 1 ); | 824 | getEventViewerDialog()->setColorMode( 1 ); |
825 | else | 825 | else |
826 | getEventViewerDialog()->setColorMode( 2 ); | 826 | getEventViewerDialog()->setColorMode( 2 ); |
827 | getEventViewerDialog()->setIncidence(local); | 827 | getEventViewerDialog()->setIncidence(local); |
828 | if ( localIsNew ) | 828 | if ( localIsNew ) |
829 | getEventViewerDialog()->setColorMode( 2 ); | 829 | getEventViewerDialog()->setColorMode( 2 ); |
830 | else | 830 | else |
831 | getEventViewerDialog()->setColorMode( 1 ); | 831 | getEventViewerDialog()->setColorMode( 1 ); |
832 | getEventViewerDialog()->addIncidence(remote); | 832 | getEventViewerDialog()->addIncidence(remote); |
833 | getEventViewerDialog()->setColorMode( 0 ); | 833 | getEventViewerDialog()->setColorMode( 0 ); |
834 | //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); | 834 | //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); |
835 | getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); | 835 | getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); |
836 | getEventViewerDialog()->showMe(); | 836 | getEventViewerDialog()->showMe(); |
837 | result = getEventViewerDialog()->executeS( localIsNew ); | 837 | result = getEventViewerDialog()->executeS( localIsNew ); |
838 | return result; | 838 | return result; |
839 | 839 | ||
840 | break; | 840 | break; |
841 | case SYNC_PREF_FORCE_LOCAL: | 841 | case SYNC_PREF_FORCE_LOCAL: |
842 | return 1; | 842 | return 1; |
843 | break; | 843 | break; |
844 | case SYNC_PREF_FORCE_REMOTE: | 844 | case SYNC_PREF_FORCE_REMOTE: |
845 | return 2; | 845 | return 2; |
846 | break; | 846 | break; |
847 | 847 | ||
848 | default: | 848 | default: |
849 | // SYNC_PREF_TAKE_BOTH not implemented | 849 | // SYNC_PREF_TAKE_BOTH not implemented |
850 | break; | 850 | break; |
851 | } | 851 | } |
852 | return 0; | 852 | return 0; |
853 | } | 853 | } |
854 | Event* CalendarView::getLastSyncEvent() | 854 | Event* CalendarView::getLastSyncEvent() |
855 | { | 855 | { |
856 | Event* lse; | 856 | Event* lse; |
857 | //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); | 857 | //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); |
858 | lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); | 858 | lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); |
859 | if (!lse) { | 859 | if (!lse) { |
860 | lse = new Event(); | 860 | lse = new Event(); |
861 | lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); | 861 | lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); |
862 | QString sum = ""; | 862 | QString sum = ""; |
863 | if ( KOPrefs::instance()->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) | 863 | if ( KOPrefs::instance()->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) |
864 | sum = "E: "; | 864 | sum = "E: "; |
865 | lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); | 865 | lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); |
866 | lse->setDtStart( mLastCalendarSync ); | 866 | lse->setDtStart( mLastCalendarSync ); |
867 | lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); | 867 | lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); |
868 | lse->setCategories( i18n("SyncEvent") ); | 868 | lse->setCategories( i18n("SyncEvent") ); |
869 | lse->setReadOnly( true ); | 869 | lse->setReadOnly( true ); |
870 | mCalendar->addEvent( lse ); | 870 | mCalendar->addEvent( lse ); |
871 | } | 871 | } |
872 | 872 | ||
873 | return lse; | 873 | return lse; |
874 | 874 | ||
875 | } | 875 | } |
876 | // probaly useless | 876 | // probaly useless |
877 | void CalendarView::setupExternSyncProfiles() | 877 | void CalendarView::setupExternSyncProfiles() |
878 | { | 878 | { |
879 | Event* lse; | 879 | Event* lse; |
880 | mExternLastSyncEvent.clear(); | 880 | mExternLastSyncEvent.clear(); |
881 | int i; | 881 | int i; |
882 | for ( i = 0; i < KOPrefs::instance()->mExternSyncProfiles.count(); ++i ) { | 882 | for ( i = 0; i < KOPrefs::instance()->mExternSyncProfiles.count(); ++i ) { |
883 | lse = mCalendar->event( "last-syncEvent-"+ KOPrefs::instance()->mExternSyncProfiles[i] ); | 883 | lse = mCalendar->event( "last-syncEvent-"+ KOPrefs::instance()->mExternSyncProfiles[i] ); |
884 | if ( lse ) | 884 | if ( lse ) |
885 | mExternLastSyncEvent.append( lse ); | 885 | mExternLastSyncEvent.append( lse ); |
886 | else | 886 | else |
887 | qDebug("Last Sync event not found for %s ", KOPrefs::instance()->mExternSyncProfiles[i].latin1()); | 887 | qDebug("Last Sync event not found for %s ", KOPrefs::instance()->mExternSyncProfiles[i].latin1()); |
888 | } | 888 | } |
889 | 889 | ||
890 | } | 890 | } |
891 | // we check, if the to delete event has a id for a profile | 891 | // we check, if the to delete event has a id for a profile |
892 | // if yes, we set this id in the profile to delete | 892 | // if yes, we set this id in the profile to delete |
893 | void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) | 893 | void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) |
894 | { | 894 | { |
895 | if ( lastSync.count() == 0 ) { | 895 | if ( lastSync.count() == 0 ) { |
896 | //qDebug(" lastSync.count() == 0"); | 896 | //qDebug(" lastSync.count() == 0"); |
897 | return; | 897 | return; |
898 | } | 898 | } |
899 | if ( toDelete->type() == "Journal" ) | 899 | if ( toDelete->type() == "Journal" ) |
900 | return; | 900 | return; |
901 | 901 | ||
902 | Event* eve = lastSync.first(); | 902 | Event* eve = lastSync.first(); |
903 | 903 | ||
904 | while ( eve ) { | 904 | while ( eve ) { |
905 | QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name | 905 | QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name |
906 | if ( !id.isEmpty() ) { | 906 | if ( !id.isEmpty() ) { |
907 | QString des = eve->description(); | 907 | QString des = eve->description(); |
908 | QString pref = "e"; | 908 | QString pref = "e"; |
909 | if ( toDelete->type() == "Todo" ) | 909 | if ( toDelete->type() == "Todo" ) |
910 | pref = "t"; | 910 | pref = "t"; |
911 | des += pref+ id + ","; | 911 | des += pref+ id + ","; |
912 | eve->setReadOnly( false ); | 912 | eve->setReadOnly( false ); |
913 | eve->setDescription( des ); | 913 | eve->setDescription( des ); |
914 | //qDebug("setdes %s ", des.latin1()); | 914 | //qDebug("setdes %s ", des.latin1()); |
915 | eve->setReadOnly( true ); | 915 | eve->setReadOnly( true ); |
916 | } | 916 | } |
917 | eve = lastSync.next(); | 917 | eve = lastSync.next(); |
918 | } | 918 | } |
919 | 919 | ||
920 | } | 920 | } |
921 | void CalendarView::checkExternalId( Incidence * inc ) | 921 | void CalendarView::checkExternalId( Incidence * inc ) |
922 | { | 922 | { |
923 | QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; | 923 | QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; |
924 | checkExternSyncEvent( lastSync, inc ); | 924 | checkExternSyncEvent( lastSync, inc ); |
925 | 925 | ||
926 | } | 926 | } |
927 | bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) | 927 | bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) |
928 | { | 928 | { |
929 | bool syncOK = true; | 929 | bool syncOK = true; |
930 | int addedEvent = 0; | 930 | int addedEvent = 0; |
931 | int addedEventR = 0; | 931 | int addedEventR = 0; |
932 | int deletedEventR = 0; | 932 | int deletedEventR = 0; |
933 | int deletedEventL = 0; | 933 | int deletedEventL = 0; |
934 | int changedLocal = 0; | 934 | int changedLocal = 0; |
935 | int changedRemote = 0; | 935 | int changedRemote = 0; |
936 | //QPtrList<Event> el = local->rawEvents(); | 936 | //QPtrList<Event> el = local->rawEvents(); |
937 | Event* eventR; | 937 | Event* eventR; |
938 | QString uid; | 938 | QString uid; |
939 | int take; | 939 | int take; |
940 | Event* eventL; | 940 | Event* eventL; |
941 | Event* eventRSync; | 941 | Event* eventRSync; |
942 | Event* eventLSync; | 942 | Event* eventLSync; |
943 | QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); | 943 | QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); |
944 | QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); | 944 | QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); |
945 | bool fullDateRange = false; | 945 | bool fullDateRange = false; |
946 | local->resetTempSyncStat(); | 946 | local->resetTempSyncStat(); |
947 | mLastCalendarSync = QDateTime::currentDateTime(); | 947 | mLastCalendarSync = QDateTime::currentDateTime(); |
948 | QDateTime modifiedCalendar = mLastCalendarSync;; | 948 | QDateTime modifiedCalendar = mLastCalendarSync;; |
949 | eventLSync = getLastSyncEvent(); | 949 | eventLSync = getLastSyncEvent(); |
950 | eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); | 950 | eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); |
951 | if ( eventR ) { | 951 | if ( eventR ) { |
952 | eventRSync = (Event*) eventR->clone(); | 952 | eventRSync = (Event*) eventR->clone(); |
953 | remote->deleteEvent(eventR ); | 953 | remote->deleteEvent(eventR ); |
954 | 954 | ||
955 | } else { | 955 | } else { |
956 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 956 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
957 | eventRSync = (Event*)eventLSync->clone(); | 957 | eventRSync = (Event*)eventLSync->clone(); |
958 | } else { | 958 | } else { |
959 | fullDateRange = true; | 959 | fullDateRange = true; |
960 | eventRSync = new Event(); | 960 | eventRSync = new Event(); |
961 | eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); | 961 | eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); |
962 | eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); | 962 | eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); |
963 | eventRSync->setDtStart( mLastCalendarSync ); | 963 | eventRSync->setDtStart( mLastCalendarSync ); |
964 | eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); | 964 | eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); |
965 | eventRSync->setCategories( i18n("SyncEvent") ); | 965 | eventRSync->setCategories( i18n("SyncEvent") ); |
966 | } | 966 | } |
967 | } | 967 | } |
968 | if ( eventLSync->dtStart() == mLastCalendarSync ) | 968 | if ( eventLSync->dtStart() == mLastCalendarSync ) |
969 | fullDateRange = true; | 969 | fullDateRange = true; |
970 | 970 | ||
971 | if ( ! fullDateRange ) { | 971 | if ( ! fullDateRange ) { |
972 | if ( eventLSync->dtStart() != eventRSync->dtStart() ) { | 972 | if ( eventLSync->dtStart() != eventRSync->dtStart() ) { |
973 | 973 | ||
974 | // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); | 974 | // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); |
975 | //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); | 975 | //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); |
976 | fullDateRange = true; | 976 | fullDateRange = true; |
977 | } | 977 | } |
978 | } | 978 | } |
979 | if ( fullDateRange ) | 979 | if ( fullDateRange ) |
980 | mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); | 980 | mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); |
981 | else | 981 | else |
982 | mLastCalendarSync = eventLSync->dtStart(); | 982 | mLastCalendarSync = eventLSync->dtStart(); |
983 | // for resyncing if own file has changed | 983 | // for resyncing if own file has changed |
984 | if ( mCurrentSyncDevice == "deleteaftersync" ) { | 984 | if ( mCurrentSyncDevice == "deleteaftersync" ) { |
985 | mLastCalendarSync = loadedFileVersion; | 985 | mLastCalendarSync = loadedFileVersion; |
986 | qDebug("setting mLastCalendarSync "); | 986 | qDebug("setting mLastCalendarSync "); |
987 | } | 987 | } |
988 | //qDebug("*************************** "); | 988 | //qDebug("*************************** "); |
989 | qDebug("mLastCalendarSync %s ",mLastCalendarSync.toString().latin1() ); | 989 | qDebug("mLastCalendarSync %s ",mLastCalendarSync.toString().latin1() ); |
990 | QPtrList<Incidence> er = remote->rawIncidences(); | 990 | QPtrList<Incidence> er = remote->rawIncidences(); |
991 | Incidence* inR = er.first(); | 991 | Incidence* inR = er.first(); |
992 | Incidence* inL; | 992 | Incidence* inL; |
993 | QProgressBar bar( er.count(),0 ); | 993 | QProgressBar bar( er.count(),0 ); |
994 | bar.setCaption (i18n("Syncing - close to abort!") ); | 994 | bar.setCaption (i18n("Syncing - close to abort!") ); |
995 | 995 | ||
996 | int w = 300; | 996 | int w = 300; |
997 | if ( QApplication::desktop()->width() < 320 ) | 997 | if ( QApplication::desktop()->width() < 320 ) |
998 | w = 220; | 998 | w = 220; |
999 | int h = bar.sizeHint().height() ; | 999 | int h = bar.sizeHint().height() ; |
1000 | int dw = QApplication::desktop()->width(); | 1000 | int dw = QApplication::desktop()->width(); |
1001 | int dh = QApplication::desktop()->height(); | 1001 | int dh = QApplication::desktop()->height(); |
1002 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 1002 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
1003 | bar.show(); | 1003 | bar.show(); |
1004 | int modulo = (er.count()/10)+1; | 1004 | int modulo = (er.count()/10)+1; |
1005 | int incCounter = 0; | 1005 | int incCounter = 0; |
1006 | while ( inR ) { | 1006 | while ( inR ) { |
1007 | if ( ! bar.isVisible() ) | 1007 | if ( ! bar.isVisible() ) |
1008 | return false; | 1008 | return false; |
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 | QString idS; | |
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 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) |
1030 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); | ||
1031 | else | ||
1032 | idS = inR->IDStr(); | ||
1030 | remote->deleteIncidence( inR ); | 1033 | remote->deleteIncidence( inR ); |
1031 | if ( inL->revision() < maxrev ) | 1034 | if ( inL->revision() < maxrev ) |
1032 | inL->setRevision( maxrev ); | 1035 | inL->setRevision( maxrev ); |
1033 | inR = inL->clone(); | 1036 | inR = inL->clone(); |
1034 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 1037 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
1038 | if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) | ||
1039 | inR->setIDStr( idS ); | ||
1035 | remote->addIncidence( inR ); | 1040 | remote->addIncidence( inR ); |
1036 | ++changedRemote; | 1041 | ++changedRemote; |
1037 | } else { | 1042 | } else { |
1038 | if ( inR->revision() < maxrev ) | 1043 | if ( inR->revision() < maxrev ) |
1039 | inR->setRevision( maxrev ); | 1044 | inR->setRevision( maxrev ); |
1045 | idS = inL->IDStr(); | ||
1040 | local->deleteIncidence( inL ); | 1046 | local->deleteIncidence( inL ); |
1041 | local->addIncidence( inR->clone() ); | 1047 | inL = inR->clone(); |
1048 | inL->setIDStr( idS ); | ||
1049 | local->addIncidence( inL ); | ||
1042 | ++changedLocal; | 1050 | ++changedLocal; |
1043 | } | 1051 | } |
1044 | } | 1052 | } |
1045 | } else { // no conflict | 1053 | } else { // no conflict |
1046 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 1054 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
1047 | QString des = eventLSync->description(); | 1055 | QString des = eventLSync->description(); |
1048 | QString pref = "e"; | 1056 | QString pref = "e"; |
1049 | if ( inR->type() == "Todo" ) | 1057 | if ( inR->type() == "Todo" ) |
1050 | pref = "t"; | 1058 | pref = "t"; |
1051 | if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it | 1059 | if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it |
1052 | inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); | 1060 | inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); |
1053 | //remote->deleteIncidence( inR ); | 1061 | //remote->deleteIncidence( inR ); |
1054 | ++deletedEventR; | 1062 | ++deletedEventR; |
1055 | } else { | 1063 | } else { |
1056 | inR->setLastModified( modifiedCalendar ); | 1064 | inR->setLastModified( modifiedCalendar ); |
1057 | inL = inR->clone(); | 1065 | inL = inR->clone(); |
1058 | local->addIncidence( inL ); | 1066 | local->addIncidence( inL ); |
1059 | ++addedEvent; | 1067 | ++addedEvent; |
1060 | } | 1068 | } |
1061 | } else { | 1069 | } else { |
1062 | if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { | 1070 | if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { |
1063 | inR->setLastModified( modifiedCalendar ); | 1071 | inR->setLastModified( modifiedCalendar ); |
1064 | local->addIncidence( inR->clone() ); | 1072 | local->addIncidence( inR->clone() ); |
1065 | ++addedEvent; | 1073 | ++addedEvent; |
1066 | } else { | 1074 | } else { |
1067 | checkExternSyncEvent(eventRSyncSharp, inR); | 1075 | checkExternSyncEvent(eventRSyncSharp, inR); |
1068 | remote->deleteIncidence( inR ); | 1076 | remote->deleteIncidence( inR ); |
1069 | ++deletedEventR; | 1077 | ++deletedEventR; |
1070 | } | 1078 | } |
1071 | } | 1079 | } |
1072 | } | 1080 | } |
1073 | } | 1081 | } |
1074 | inR = er.next(); | 1082 | inR = er.next(); |
1075 | } | 1083 | } |
1076 | QPtrList<Incidence> el = local->rawIncidences(); | 1084 | QPtrList<Incidence> el = local->rawIncidences(); |
1077 | inL = el.first(); | 1085 | inL = el.first(); |
1078 | modulo = (el.count()/10)+1; | 1086 | modulo = (el.count()/10)+1; |
1079 | bar.setCaption (i18n("Add / remove events") ); | 1087 | bar.setCaption (i18n("Add / remove events") ); |
1080 | bar.setTotalSteps ( el.count() ) ; | 1088 | bar.setTotalSteps ( el.count() ) ; |
1081 | bar.show(); | 1089 | bar.show(); |
1082 | incCounter = 0; | 1090 | incCounter = 0; |
1083 | 1091 | ||
1084 | while ( inL ) { | 1092 | while ( inL ) { |
1085 | 1093 | ||
1086 | qApp->processEvents(); | 1094 | qApp->processEvents(); |
1087 | if ( ! bar.isVisible() ) | 1095 | if ( ! bar.isVisible() ) |
1088 | return false; | 1096 | return false; |
1089 | if ( incCounter % modulo == 0 ) | 1097 | if ( incCounter % modulo == 0 ) |
1090 | bar.setProgress( incCounter ); | 1098 | bar.setProgress( incCounter ); |
1091 | ++incCounter; | 1099 | ++incCounter; |
1092 | uid = inL->uid(); | 1100 | uid = inL->uid(); |
1093 | bool skipIncidence = false; | 1101 | bool skipIncidence = false; |
1094 | if ( uid.left(15) == QString("last-syncEvent-") ) | 1102 | if ( uid.left(15) == QString("last-syncEvent-") ) |
1095 | skipIncidence = true; | 1103 | skipIncidence = true; |
1096 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) | 1104 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) |
1097 | skipIncidence = true; | 1105 | skipIncidence = true; |
1098 | if ( !skipIncidence ) { | 1106 | if ( !skipIncidence ) { |
1099 | inR = remote->incidence( uid ); | 1107 | inR = remote->incidence( uid ); |
1100 | if ( ! inR ) { | 1108 | if ( ! inR ) { |
1101 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 1109 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
1102 | if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { | 1110 | if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { |
1111 | checkExternSyncEvent(eventLSyncSharp, inL); | ||
1103 | local->deleteIncidence( inL ); | 1112 | local->deleteIncidence( inL ); |
1104 | ++deletedEventL; | 1113 | ++deletedEventL; |
1105 | } else { | 1114 | } else { |
1106 | if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { | 1115 | if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { |
1107 | inL->removeID(mCurrentSyncDevice ); | 1116 | inL->removeID(mCurrentSyncDevice ); |
1108 | ++addedEventR; | 1117 | ++addedEventR; |
1109 | qDebug("remote added Incidence %s ", inL->summary().latin1()); | 1118 | qDebug("remote added Incidence %s ", inL->summary().latin1()); |
1110 | inL->setLastModified( modifiedCalendar ); | 1119 | inL->setLastModified( modifiedCalendar ); |
1111 | inR = inL->clone(); | 1120 | inR = inL->clone(); |
1112 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 1121 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
1113 | remote->addIncidence( inR ); | 1122 | remote->addIncidence( inR ); |
1114 | } | 1123 | } |
1115 | } | 1124 | } |
1116 | } else { | 1125 | } else { |
1117 | if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { | 1126 | if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { |
1118 | checkExternSyncEvent(eventLSyncSharp, inL); | 1127 | checkExternSyncEvent(eventLSyncSharp, inL); |
1119 | local->deleteIncidence( inL ); | 1128 | local->deleteIncidence( inL ); |
1120 | ++deletedEventL; | 1129 | ++deletedEventL; |
1121 | } else { | 1130 | } else { |
1122 | if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { | 1131 | if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { |
1123 | ++addedEventR; | 1132 | ++addedEventR; |
1124 | inL->setLastModified( modifiedCalendar ); | 1133 | inL->setLastModified( modifiedCalendar ); |
1125 | remote->addIncidence( inL->clone() ); | 1134 | remote->addIncidence( inL->clone() ); |
1126 | } | 1135 | } |
1127 | } | 1136 | } |
1128 | } | 1137 | } |
1129 | } | 1138 | } |
1130 | } | 1139 | } |
1131 | inL = el.next(); | 1140 | inL = el.next(); |
1132 | } | 1141 | } |
1133 | int delFut = 0; | 1142 | int delFut = 0; |
1134 | if ( KOPrefs::instance()->mWriteBackInFuture ) { | 1143 | if ( KOPrefs::instance()->mWriteBackInFuture ) { |
1135 | er = remote->rawIncidences(); | 1144 | er = remote->rawIncidences(); |
1136 | inR = er.first(); | 1145 | inR = er.first(); |
1137 | QDateTime dt; | 1146 | QDateTime dt; |
1138 | QDateTime cur = QDateTime::currentDateTime(); | 1147 | QDateTime cur = QDateTime::currentDateTime(); |
1139 | QDateTime end = cur.addSecs( KOPrefs::instance()->mWriteBackInFuture * 3600 *24 *7 ); | 1148 | QDateTime end = cur.addSecs( KOPrefs::instance()->mWriteBackInFuture * 3600 *24 *7 ); |
1140 | while ( inR ) { | 1149 | while ( inR ) { |
1141 | if ( inR->type() == "Todo" ) { | 1150 | if ( inR->type() == "Todo" ) { |
1142 | Todo * t = (Todo*)inR; | 1151 | Todo * t = (Todo*)inR; |
1143 | if ( t->hasDueDate() ) | 1152 | if ( t->hasDueDate() ) |
1144 | dt = t->dtDue(); | 1153 | dt = t->dtDue(); |
1145 | else | 1154 | else |
1146 | dt = cur.addSecs( 62 ); | 1155 | dt = cur.addSecs( 62 ); |
1147 | } | 1156 | } |
1148 | else if (inR->type() == "Event" ) { | 1157 | else if (inR->type() == "Event" ) { |
1149 | bool ok; | 1158 | bool ok; |
1150 | dt = inR->getNextOccurence( cur, &ok ); | 1159 | dt = inR->getNextOccurence( cur, &ok ); |
1151 | if ( !ok ) | 1160 | if ( !ok ) |
1152 | dt = cur.addSecs( -62 ); | 1161 | dt = cur.addSecs( -62 ); |
1153 | } | 1162 | } |
1154 | else | 1163 | else |
1155 | dt = inR->dtStart(); | 1164 | dt = inR->dtStart(); |
1156 | if ( dt < cur || dt > end ) { | 1165 | if ( dt < cur || dt > end ) { |
1157 | remote->deleteIncidence( inR ); | 1166 | remote->deleteIncidence( inR ); |
1158 | ++delFut; | 1167 | ++delFut; |
1159 | } | 1168 | } |
1160 | inR = er.next(); | 1169 | inR = er.next(); |
1161 | } | 1170 | } |
1162 | } | 1171 | } |
1163 | bar.hide(); | 1172 | bar.hide(); |
1164 | mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); | 1173 | mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); |
1165 | eventLSync->setReadOnly( false ); | 1174 | eventLSync->setReadOnly( false ); |
1166 | eventLSync->setDtStart( mLastCalendarSync ); | 1175 | eventLSync->setDtStart( mLastCalendarSync ); |
1167 | eventRSync->setDtStart( mLastCalendarSync ); | 1176 | eventRSync->setDtStart( mLastCalendarSync ); |
1168 | eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); | 1177 | eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); |
1169 | eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); | 1178 | eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); |
1170 | eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; | 1179 | eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; |
1171 | eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); | 1180 | eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); |
1172 | eventLSync->setReadOnly( true ); | 1181 | eventLSync->setReadOnly( true ); |
1173 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL) | 1182 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL) |
1174 | remote->addEvent( eventRSync ); | 1183 | remote->addEvent( eventRSync ); |
1175 | QString mes; | 1184 | QString mes; |
1176 | 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"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR ); | 1185 | 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"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR ); |
1177 | QString delmess; | 1186 | QString delmess; |
1178 | if ( delFut ) { | 1187 | if ( delFut ) { |
1179 | delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\n"),delFut, KOPrefs::instance()->mWriteBackInFuture ); | 1188 | delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\n"),delFut, KOPrefs::instance()->mWriteBackInFuture ); |
1180 | mes += delmess; | 1189 | mes += delmess; |
1181 | } | 1190 | } |
1182 | if ( KOPrefs::instance()->mShowSyncSummary ) { | 1191 | if ( KOPrefs::instance()->mShowSyncSummary ) { |
1183 | KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") ); | 1192 | KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") ); |
1184 | } | 1193 | } |
1185 | qDebug( mes ); | 1194 | qDebug( mes ); |
1186 | mCalendar->checkAlarmForIncidence( 0, true ); | 1195 | mCalendar->checkAlarmForIncidence( 0, true ); |
1187 | return syncOK; | 1196 | return syncOK; |
1188 | } | 1197 | } |
1189 | 1198 | ||
1190 | void CalendarView::setSyncDevice( QString s ) | 1199 | void CalendarView::setSyncDevice( QString s ) |
1191 | { | 1200 | { |
1192 | mCurrentSyncDevice= s; | 1201 | mCurrentSyncDevice= s; |
1193 | } | 1202 | } |
1194 | void CalendarView::setSyncName( QString s ) | 1203 | void CalendarView::setSyncName( QString s ) |
1195 | { | 1204 | { |
1196 | mCurrentSyncName= s; | 1205 | mCurrentSyncName= s; |
1197 | } | 1206 | } |
1198 | bool CalendarView::syncCalendar(QString filename, int mode) | 1207 | bool CalendarView::syncCalendar(QString filename, int mode) |
1199 | { | 1208 | { |
1200 | mGlobalSyncMode = SYNC_MODE_NORMAL; | 1209 | mGlobalSyncMode = SYNC_MODE_NORMAL; |
1201 | CalendarLocal* calendar = new CalendarLocal(); | 1210 | CalendarLocal* calendar = new CalendarLocal(); |
1202 | calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); | 1211 | calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); |
1203 | FileStorage* storage = new FileStorage( calendar ); | 1212 | FileStorage* storage = new FileStorage( calendar ); |
1204 | bool syncOK = false; | 1213 | bool syncOK = false; |
1205 | storage->setFileName( filename ); | 1214 | storage->setFileName( filename ); |
1206 | // qDebug("loading ... "); | 1215 | // qDebug("loading ... "); |
1207 | if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { | 1216 | if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { |
1208 | getEventViewerDialog()->setSyncMode( true ); | 1217 | getEventViewerDialog()->setSyncMode( true ); |
1209 | syncOK = synchronizeCalendar( mCalendar, calendar, mode ); | 1218 | syncOK = synchronizeCalendar( mCalendar, calendar, mode ); |
1210 | getEventViewerDialog()->setSyncMode( false ); | 1219 | getEventViewerDialog()->setSyncMode( false ); |
1211 | if ( syncOK ) { | 1220 | if ( syncOK ) { |
1212 | if ( KOPrefs::instance()->mWriteBackFile ) | 1221 | if ( KOPrefs::instance()->mWriteBackFile ) |
1213 | { | 1222 | { |
1214 | storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); | 1223 | storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); |
1215 | storage->save(); | 1224 | storage->save(); |
1216 | } | 1225 | } |
1217 | } | 1226 | } |
1218 | setModified( true ); | 1227 | setModified( true ); |
1219 | } | 1228 | } |
1220 | delete storage; | 1229 | delete storage; |
1221 | delete calendar; | 1230 | delete calendar; |
1222 | if ( syncOK ) | 1231 | if ( syncOK ) |
1223 | updateView(); | 1232 | updateView(); |
1224 | return syncOK; | 1233 | return syncOK; |
1225 | } | 1234 | } |
1226 | void CalendarView::syncPhone() | 1235 | void CalendarView::syncPhone() |
1227 | { | 1236 | { |
1228 | syncExternal( 1 ); | 1237 | syncExternal( 1 ); |
1229 | } | 1238 | } |
1230 | void CalendarView::syncExternal( int mode ) | 1239 | void CalendarView::syncExternal( int mode ) |
1231 | { | 1240 | { |
1232 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 1241 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
1233 | //mCurrentSyncDevice = "sharp-DTM"; | 1242 | //mCurrentSyncDevice = "sharp-DTM"; |
1234 | if ( KOPrefs::instance()->mAskForPreferences ) | 1243 | if ( KOPrefs::instance()->mAskForPreferences ) |
1235 | edit_sync_options(); | 1244 | edit_sync_options(); |
1236 | qApp->processEvents(); | 1245 | qApp->processEvents(); |
1237 | CalendarLocal* calendar = new CalendarLocal(); | 1246 | CalendarLocal* calendar = new CalendarLocal(); |
1238 | calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); | 1247 | calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); |
1239 | bool syncOK = false; | 1248 | bool syncOK = false; |
1240 | bool loadSuccess = false; | 1249 | bool loadSuccess = false; |
1241 | PhoneFormat* phoneFormat = 0; | 1250 | PhoneFormat* phoneFormat = 0; |
1242 | #ifndef DESKTOP_VERSION | 1251 | #ifndef DESKTOP_VERSION |
1243 | SharpFormat* sharpFormat = 0; | 1252 | SharpFormat* sharpFormat = 0; |
1244 | if ( mode == 0 ) { // sharp | 1253 | if ( mode == 0 ) { // sharp |
1245 | sharpFormat = new SharpFormat () ; | 1254 | sharpFormat = new SharpFormat () ; |
1246 | loadSuccess = sharpFormat->load( calendar, mCalendar ); | 1255 | loadSuccess = sharpFormat->load( calendar, mCalendar ); |
1247 | 1256 | ||
1248 | } else | 1257 | } else |
1249 | #endif | 1258 | #endif |
1250 | if ( mode == 1 ) { // phone | 1259 | if ( mode == 1 ) { // phone |
1251 | phoneFormat = new PhoneFormat (mCurrentSyncDevice, | 1260 | phoneFormat = new PhoneFormat (mCurrentSyncDevice, |
1252 | KOPrefs::instance()->mPhoneDevice, | 1261 | KOPrefs::instance()->mPhoneDevice, |
1253 | KOPrefs::instance()->mPhoneConnection, | 1262 | KOPrefs::instance()->mPhoneConnection, |
1254 | KOPrefs::instance()->mPhoneModel); | 1263 | KOPrefs::instance()->mPhoneModel); |
1255 | loadSuccess = phoneFormat->load( calendar,mCalendar); | 1264 | loadSuccess = phoneFormat->load( calendar,mCalendar); |
1256 | 1265 | ||
1257 | } else | 1266 | } else |
1258 | return; | 1267 | return; |
1259 | if ( loadSuccess ) { | 1268 | if ( loadSuccess ) { |
1260 | getEventViewerDialog()->setSyncMode( true ); | 1269 | getEventViewerDialog()->setSyncMode( true ); |
1261 | syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs ); | 1270 | syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs ); |
1262 | getEventViewerDialog()->setSyncMode( false ); | 1271 | getEventViewerDialog()->setSyncMode( false ); |
1263 | qApp->processEvents(); | 1272 | qApp->processEvents(); |
1264 | if ( syncOK ) { | 1273 | if ( syncOK ) { |
1265 | if ( KOPrefs::instance()->mWriteBackFile ) | 1274 | if ( KOPrefs::instance()->mWriteBackFile ) |
1266 | { | 1275 | { |
1267 | QPtrList<Incidence> iL = mCalendar->rawIncidences(); | 1276 | QPtrList<Incidence> iL = mCalendar->rawIncidences(); |
1268 | Incidence* inc = iL.first(); | 1277 | Incidence* inc = iL.first(); |
1269 | if ( phoneFormat ) { | 1278 | if ( phoneFormat ) { |
1270 | while ( inc ) { | 1279 | while ( inc ) { |
1271 | inc->removeID(mCurrentSyncDevice); | 1280 | inc->removeID(mCurrentSyncDevice); |
1272 | inc = iL.next(); | 1281 | inc = iL.next(); |
1273 | } | 1282 | } |
1274 | } | 1283 | } |
1275 | #ifndef DESKTOP_VERSION | 1284 | #ifndef DESKTOP_VERSION |
1276 | if ( sharpFormat ) | 1285 | if ( sharpFormat ) |
1277 | sharpFormat->save(calendar); | 1286 | sharpFormat->save(calendar); |
1278 | #endif | 1287 | #endif |
1279 | if ( phoneFormat ) | 1288 | if ( phoneFormat ) |
1280 | phoneFormat->save(calendar); | 1289 | phoneFormat->save(calendar); |
1281 | iL = calendar->rawIncidences(); | 1290 | iL = calendar->rawIncidences(); |
1282 | inc = iL.first(); | 1291 | inc = iL.first(); |
1283 | Incidence* loc; | 1292 | Incidence* loc; |
1284 | while ( inc ) { | 1293 | while ( inc ) { |
1285 | if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { | 1294 | if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { |
1286 | loc = mCalendar->incidence(inc->uid() ); | 1295 | loc = mCalendar->incidence(inc->uid() ); |
1287 | if ( loc ) { | 1296 | if ( loc ) { |
1288 | loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); | 1297 | loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); |
1289 | loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); | 1298 | loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); |
1290 | } | 1299 | } |
1291 | } | 1300 | } |
1292 | inc = iL.next(); | 1301 | inc = iL.next(); |
1293 | } | 1302 | } |
1294 | Incidence* lse = getLastSyncEvent(); | 1303 | Incidence* lse = getLastSyncEvent(); |
1295 | if ( lse ) { | 1304 | if ( lse ) { |
1296 | lse->setReadOnly( false ); | 1305 | lse->setReadOnly( false ); |
1297 | lse->setDescription( "" ); | 1306 | lse->setDescription( "" ); |
1298 | lse->setReadOnly( true ); | 1307 | lse->setReadOnly( true ); |
1299 | } | 1308 | } |
1300 | } | 1309 | } |
1301 | } | 1310 | } |
1302 | setModified( true ); | 1311 | setModified( true ); |
1303 | } else { | 1312 | } else { |
1304 | QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; | 1313 | QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; |
1305 | QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), | 1314 | QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), |
1306 | question, i18n("Ok")) ; | 1315 | question, i18n("Ok")) ; |
1307 | 1316 | ||
1308 | } | 1317 | } |
1309 | delete calendar; | 1318 | delete calendar; |
1310 | updateView(); | 1319 | updateView(); |
1311 | return ;//syncOK; | 1320 | return ;//syncOK; |
1312 | 1321 | ||
1313 | } | 1322 | } |
1314 | void CalendarView::syncSharp() | 1323 | void CalendarView::syncSharp() |
1315 | { | 1324 | { |
1316 | syncExternal( 0 ); | 1325 | syncExternal( 0 ); |
1317 | 1326 | ||
1318 | } | 1327 | } |
1319 | 1328 | ||
1320 | 1329 | ||
1321 | #include <kabc/stdaddressbook.h> | 1330 | #include <kabc/stdaddressbook.h> |
1322 | bool CalendarView::importBday() | 1331 | bool CalendarView::importBday() |
1323 | { | 1332 | { |
1324 | KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); | 1333 | KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); |
1325 | KABC::AddressBook::Iterator it; | 1334 | KABC::AddressBook::Iterator it; |
1326 | int count = 0; | 1335 | int count = 0; |
1327 | for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { | 1336 | for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { |
1328 | ++count; | 1337 | ++count; |
1329 | } | 1338 | } |
1330 | QProgressBar bar(count,0 ); | 1339 | QProgressBar bar(count,0 ); |
1331 | int w = 300; | 1340 | int w = 300; |
1332 | if ( QApplication::desktop()->width() < 320 ) | 1341 | if ( QApplication::desktop()->width() < 320 ) |
1333 | w = 220; | 1342 | w = 220; |
1334 | int h = bar.sizeHint().height() ; | 1343 | int h = bar.sizeHint().height() ; |
1335 | int dw = QApplication::desktop()->width(); | 1344 | int dw = QApplication::desktop()->width(); |
1336 | int dh = QApplication::desktop()->height(); | 1345 | int dh = QApplication::desktop()->height(); |
1337 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 1346 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
1338 | bar.show(); | 1347 | bar.show(); |
1339 | bar.setCaption (i18n("Reading addressbook - close to abort!") ); | 1348 | bar.setCaption (i18n("Reading addressbook - close to abort!") ); |
1340 | qApp->processEvents(); | 1349 | qApp->processEvents(); |
1341 | count = 0; | 1350 | count = 0; |
1342 | int addCount = 0; | 1351 | int addCount = 0; |
1343 | KCal::Attendee* a = 0; | 1352 | KCal::Attendee* a = 0; |
1344 | for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { | 1353 | for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { |
1345 | if ( ! bar.isVisible() ) | 1354 | if ( ! bar.isVisible() ) |
1346 | return false; | 1355 | return false; |
1347 | bar.setProgress( count++ ); | 1356 | bar.setProgress( count++ ); |
1348 | qApp->processEvents(); | 1357 | qApp->processEvents(); |
1349 | //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); | 1358 | //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); |
1350 | if ( (*it).birthday().date().isValid() ){ | 1359 | if ( (*it).birthday().date().isValid() ){ |
1351 | a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; | 1360 | a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; |
1352 | if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) | 1361 | if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) |
1353 | ++addCount; | 1362 | ++addCount; |
1354 | } | 1363 | } |
1355 | QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); | 1364 | QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); |
1356 | if ( anni.isValid() ){ | 1365 | if ( anni.isValid() ){ |
1357 | a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; | 1366 | a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; |
1358 | if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) | 1367 | if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) |
diff --git a/libkcal/event.cpp b/libkcal/event.cpp index dd67252..dfa265b 100644 --- a/libkcal/event.cpp +++ b/libkcal/event.cpp | |||
@@ -1,178 +1,177 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
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 | #include <kglobal.h> | 21 | #include <kglobal.h> |
22 | #include <klocale.h> | 22 | #include <klocale.h> |
23 | #include <kdebug.h> | 23 | #include <kdebug.h> |
24 | 24 | ||
25 | #include "event.h" | 25 | #include "event.h" |
26 | 26 | ||
27 | using namespace KCal; | 27 | using namespace KCal; |
28 | 28 | ||
29 | Event::Event() : | 29 | Event::Event() : |
30 | mHasEndDate( false ), mTransparency( Opaque ) | 30 | mHasEndDate( false ), mTransparency( Opaque ) |
31 | { | 31 | { |
32 | } | 32 | } |
33 | 33 | ||
34 | Event::Event(const Event &e) : Incidence(e) | 34 | Event::Event(const Event &e) : Incidence(e) |
35 | { | 35 | { |
36 | mDtEnd = e.mDtEnd; | 36 | mDtEnd = e.mDtEnd; |
37 | mHasEndDate = e.mHasEndDate; | 37 | mHasEndDate = e.mHasEndDate; |
38 | mTransparency = e.mTransparency; | 38 | mTransparency = e.mTransparency; |
39 | } | 39 | } |
40 | 40 | ||
41 | Event::~Event() | 41 | Event::~Event() |
42 | { | 42 | { |
43 | } | 43 | } |
44 | 44 | ||
45 | Incidence *Event::clone() | 45 | Incidence *Event::clone() |
46 | { | 46 | { |
47 | kdDebug(5800) << "Event::clone()" << endl; | ||
48 | return new Event(*this); | 47 | return new Event(*this); |
49 | } | 48 | } |
50 | 49 | ||
51 | bool KCal::operator==( const Event& e1, const Event& e2 ) | 50 | bool KCal::operator==( const Event& e1, const Event& e2 ) |
52 | { | 51 | { |
53 | return operator==( (const Incidence&)e1, (const Incidence&)e2 ) && | 52 | return operator==( (const Incidence&)e1, (const Incidence&)e2 ) && |
54 | e1.dtEnd() == e2.dtEnd() && | 53 | e1.dtEnd() == e2.dtEnd() && |
55 | e1.hasEndDate() == e2.hasEndDate() && | 54 | e1.hasEndDate() == e2.hasEndDate() && |
56 | e1.transparency() == e2.transparency(); | 55 | e1.transparency() == e2.transparency(); |
57 | } | 56 | } |
58 | 57 | ||
59 | 58 | ||
60 | 59 | ||
61 | void Event::setDtEnd(const QDateTime &dtEnd) | 60 | void Event::setDtEnd(const QDateTime &dtEnd) |
62 | { | 61 | { |
63 | if (mReadOnly) return; | 62 | if (mReadOnly) return; |
64 | 63 | ||
65 | mDtEnd = getEvenTime( dtEnd ); | 64 | mDtEnd = getEvenTime( dtEnd ); |
66 | 65 | ||
67 | setHasEndDate(true); | 66 | setHasEndDate(true); |
68 | setHasDuration(false); | 67 | setHasDuration(false); |
69 | 68 | ||
70 | updated(); | 69 | updated(); |
71 | } | 70 | } |
72 | 71 | ||
73 | QDateTime Event::dtEnd() const | 72 | QDateTime Event::dtEnd() const |
74 | { | 73 | { |
75 | if (hasEndDate()) return mDtEnd; | 74 | if (hasEndDate()) return mDtEnd; |
76 | if (hasDuration()) return dtStart().addSecs(duration()); | 75 | if (hasDuration()) return dtStart().addSecs(duration()); |
77 | 76 | ||
78 | kdDebug(5800) << "Warning! Event '" << summary() | 77 | kdDebug(5800) << "Warning! Event '" << summary() |
79 | << "' does have neither end date nor duration." << endl; | 78 | << "' does have neither end date nor duration." << endl; |
80 | return dtStart(); | 79 | return dtStart(); |
81 | } | 80 | } |
82 | 81 | ||
83 | QString Event::dtEndTimeStr() const | 82 | QString Event::dtEndTimeStr() const |
84 | { | 83 | { |
85 | return KGlobal::locale()->formatTime(mDtEnd.time()); | 84 | return KGlobal::locale()->formatTime(mDtEnd.time()); |
86 | } | 85 | } |
87 | 86 | ||
88 | QString Event::dtEndDateStr(bool shortfmt) const | 87 | QString Event::dtEndDateStr(bool shortfmt) const |
89 | { | 88 | { |
90 | return KGlobal::locale()->formatDate(mDtEnd.date(),shortfmt); | 89 | return KGlobal::locale()->formatDate(mDtEnd.date(),shortfmt); |
91 | } | 90 | } |
92 | 91 | ||
93 | QString Event::dtEndStr(bool shortfmt) const | 92 | QString Event::dtEndStr(bool shortfmt) const |
94 | { | 93 | { |
95 | return KGlobal::locale()->formatDateTime(mDtEnd, shortfmt); | 94 | return KGlobal::locale()->formatDateTime(mDtEnd, shortfmt); |
96 | } | 95 | } |
97 | 96 | ||
98 | void Event::setHasEndDate(bool b) | 97 | void Event::setHasEndDate(bool b) |
99 | { | 98 | { |
100 | mHasEndDate = b; | 99 | mHasEndDate = b; |
101 | } | 100 | } |
102 | 101 | ||
103 | bool Event::hasEndDate() const | 102 | bool Event::hasEndDate() const |
104 | { | 103 | { |
105 | return mHasEndDate; | 104 | return mHasEndDate; |
106 | } | 105 | } |
107 | 106 | ||
108 | bool Event::isMultiDay() const | 107 | bool Event::isMultiDay() const |
109 | { | 108 | { |
110 | bool multi = !(dtStart().date() == dtEnd().date()); | 109 | bool multi = !(dtStart().date() == dtEnd().date()); |
111 | return multi; | 110 | return multi; |
112 | } | 111 | } |
113 | 112 | ||
114 | void Event::setTransparency(Event::Transparency transparency) | 113 | void Event::setTransparency(Event::Transparency transparency) |
115 | { | 114 | { |
116 | if (mReadOnly) return; | 115 | if (mReadOnly) return; |
117 | mTransparency = transparency; | 116 | mTransparency = transparency; |
118 | updated(); | 117 | updated(); |
119 | } | 118 | } |
120 | 119 | ||
121 | Event::Transparency Event::transparency() const | 120 | Event::Transparency Event::transparency() const |
122 | { | 121 | { |
123 | return mTransparency; | 122 | return mTransparency; |
124 | } | 123 | } |
125 | 124 | ||
126 | void Event::setDuration(int seconds) | 125 | void Event::setDuration(int seconds) |
127 | { | 126 | { |
128 | setHasEndDate(false); | 127 | setHasEndDate(false); |
129 | Incidence::setDuration(seconds); | 128 | Incidence::setDuration(seconds); |
130 | } | 129 | } |
131 | QDateTime Event::getNextAlarmDateTime( bool * ok, int * offset ) const | 130 | QDateTime Event::getNextAlarmDateTime( bool * ok, int * offset ) const |
132 | { | 131 | { |
133 | 132 | ||
134 | bool yes; | 133 | bool yes; |
135 | QDateTime incidenceStart = getNextOccurence( QDateTime::currentDateTime(), &yes ); | 134 | QDateTime incidenceStart = getNextOccurence( QDateTime::currentDateTime(), &yes ); |
136 | if ( ! yes || cancelled() ) { | 135 | if ( ! yes || cancelled() ) { |
137 | *ok = false; | 136 | *ok = false; |
138 | return QDateTime (); | 137 | return QDateTime (); |
139 | } | 138 | } |
140 | 139 | ||
141 | bool enabled = false; | 140 | bool enabled = false; |
142 | Alarm* alarm; | 141 | Alarm* alarm; |
143 | int off; | 142 | int off; |
144 | QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; | 143 | QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; |
145 | // if ( QDateTime::currentDateTime() > incidenceStart ){ | 144 | // if ( QDateTime::currentDateTime() > incidenceStart ){ |
146 | // *ok = false; | 145 | // *ok = false; |
147 | // return incidenceStart; | 146 | // return incidenceStart; |
148 | // } | 147 | // } |
149 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { | 148 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { |
150 | if (alarm->enabled()) { | 149 | if (alarm->enabled()) { |
151 | if ( alarm->hasTime () ) { | 150 | if ( alarm->hasTime () ) { |
152 | if ( alarm->time() < alarmStart ) { | 151 | if ( alarm->time() < alarmStart ) { |
153 | alarmStart = alarm->time(); | 152 | alarmStart = alarm->time(); |
154 | enabled = true; | 153 | enabled = true; |
155 | off = alarmStart.secsTo( incidenceStart ); | 154 | off = alarmStart.secsTo( incidenceStart ); |
156 | } | 155 | } |
157 | 156 | ||
158 | } else { | 157 | } else { |
159 | int secs = alarm->startOffset().asSeconds(); | 158 | int secs = alarm->startOffset().asSeconds(); |
160 | if ( incidenceStart.addSecs( secs ) < alarmStart ) { | 159 | if ( incidenceStart.addSecs( secs ) < alarmStart ) { |
161 | alarmStart = incidenceStart.addSecs( secs ); | 160 | alarmStart = incidenceStart.addSecs( secs ); |
162 | enabled = true; | 161 | enabled = true; |
163 | off = -secs; | 162 | off = -secs; |
164 | } | 163 | } |
165 | } | 164 | } |
166 | } | 165 | } |
167 | } | 166 | } |
168 | if ( enabled ) { | 167 | if ( enabled ) { |
169 | if ( alarmStart > QDateTime::currentDateTime() ) { | 168 | if ( alarmStart > QDateTime::currentDateTime() ) { |
170 | *ok = true; | 169 | *ok = true; |
171 | * offset = off; | 170 | * offset = off; |
172 | return alarmStart; | 171 | return alarmStart; |
173 | } | 172 | } |
174 | } | 173 | } |
175 | *ok = false; | 174 | *ok = false; |
176 | return QDateTime (); | 175 | return QDateTime (); |
177 | 176 | ||
178 | } | 177 | } |