Diffstat (limited to 'korganizer/koeditorrecurrence.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | korganizer/koeditorrecurrence.cpp | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/korganizer/koeditorrecurrence.cpp b/korganizer/koeditorrecurrence.cpp index dea8981..de4e4f7 100644 --- a/korganizer/koeditorrecurrence.cpp +++ b/korganizer/koeditorrecurrence.cpp | |||
@@ -814,111 +814,123 @@ void KOEditorRecurrence::showCurrentRule( int current ) | |||
814 | case Daily: | 814 | case Daily: |
815 | mRuleStack->raiseWidget( mDaily ); | 815 | mRuleStack->raiseWidget( mDaily ); |
816 | break; | 816 | break; |
817 | case Weekly: | 817 | case Weekly: |
818 | mRuleStack->raiseWidget( mWeekly ); | 818 | mRuleStack->raiseWidget( mWeekly ); |
819 | break; | 819 | break; |
820 | case Monthly: | 820 | case Monthly: |
821 | mRuleStack->raiseWidget( mMonthly ); | 821 | mRuleStack->raiseWidget( mMonthly ); |
822 | break; | 822 | break; |
823 | default: | 823 | default: |
824 | case Yearly: | 824 | case Yearly: |
825 | mRuleStack->raiseWidget( mYearly ); | 825 | mRuleStack->raiseWidget( mYearly ); |
826 | break; | 826 | break; |
827 | } | 827 | } |
828 | } | 828 | } |
829 | 829 | ||
830 | void KOEditorRecurrence::setDateTimes( QDateTime start, QDateTime end ) | 830 | void KOEditorRecurrence::setDateTimes( QDateTime start, QDateTime end ) |
831 | { | 831 | { |
832 | // kdDebug() << "KOEditorRecurrence::setDateTimes" << endl; | 832 | // kdDebug() << "KOEditorRecurrence::setDateTimes" << endl; |
833 | 833 | ||
834 | mRecurrenceRange->setDateTimes( start, end ); | 834 | mRecurrenceRange->setDateTimes( start, end ); |
835 | mExceptions->setDefaults( end ); | 835 | mExceptions->setDefaults( end ); |
836 | 836 | ||
837 | } | 837 | } |
838 | void KOEditorRecurrence::setDefaultsDates( QDateTime from, QDateTime to ) | ||
839 | { | ||
840 | setDateTimes( from, to ); | ||
841 | QBitArray days( 7 ); | ||
842 | days.fill( 0 ); | ||
843 | days.setBit( from.date().dayOfWeek()- 1); | ||
844 | mWeekly->setDays( days ); | ||
845 | bool byPos = mMonthly->byPos(); | ||
846 | if ( byPos ) | ||
847 | mMonthly->setByDay( from.date().day()-1 ); | ||
848 | mMonthly->setByPos((from.date().day()/7), from.date().dayOfWeek()-1 ); | ||
849 | if ( ! byPos) | ||
850 | mMonthly->setByDay( from.date().day()-1 ); | ||
838 | 851 | ||
839 | void KOEditorRecurrence::setDefaults( QDateTime from, QDateTime to, bool ) | 852 | bool byDay = mYearly->byDay(); |
853 | if ( ! byDay ) | ||
854 | mYearly->setByDay( from.date().dayOfYear() ); | ||
855 | mYearly->setByMonth( from.date().month(), from.date().day() ); | ||
856 | if ( byDay ) | ||
857 | mYearly->setByDay( from.date().dayOfYear() ); | ||
858 | } | ||
859 | void KOEditorRecurrence::setDefaults( QDateTime from, QDateTime to ) | ||
840 | { | 860 | { |
841 | 861 | ||
842 | // qDebug("KOEditorRecurrence::setDefaults %s %s ",from.toString().latin1(),to.toString().latin1() ); | 862 | // qDebug("KOEditorRecurrence::setDefaults %s %s ",from.toString().latin1(),to.toString().latin1() ); |
843 | setDateTimes( from, to ); | 863 | //setDateTimes( from, to ); |
844 | 864 | ||
845 | bool enabled = false; | 865 | bool enabled = false; |
846 | mEnabledCheck->setChecked( enabled ); | 866 | mEnabledCheck->setChecked( enabled ); |
847 | setEnabled( enabled ); | 867 | setEnabled( enabled ); |
848 | 868 | ||
849 | mExceptions->setDefaults( to ); | 869 | mExceptions->setDefaults( to ); |
850 | mRecurrenceRange->setDefaults( to ); | 870 | mRecurrenceRange->setDefaults( to ); |
851 | 871 | ||
852 | mRecurrenceChooser->setType( RecurrenceChooser::Weekly ); | 872 | mRecurrenceChooser->setType( RecurrenceChooser::Weekly ); |
853 | showCurrentRule( mRecurrenceChooser->type() ); | 873 | showCurrentRule( mRecurrenceChooser->type() ); |
854 | 874 | ||
855 | mDaily->setFrequency( 1 ); | 875 | mDaily->setFrequency( 1 ); |
856 | |||
857 | mWeekly->setFrequency( 1 ); | 876 | mWeekly->setFrequency( 1 ); |
858 | QBitArray days( 7 ); | ||
859 | days.fill( 0 ); | ||
860 | days.setBit( from.date().dayOfWeek()- 1); | ||
861 | mWeekly->setDays( days ); | ||
862 | mMonthly->setFrequency( 1 ); | 877 | mMonthly->setFrequency( 1 ); |
863 | mMonthly->setByPos((from.date().day()/7), from.date().dayOfWeek()-1 ); | ||
864 | mMonthly->setByDay( from.date().day()-1 ); | ||
865 | mYearly->setFrequency( 1 ); | 878 | mYearly->setFrequency( 1 ); |
866 | mYearly->setByDay( from.date().dayOfYear() ); | 879 | setDefaultsDates( from, to ); |
867 | mYearly->setByMonth( from.date().month(), from.date().day() ); | ||
868 | } | 880 | } |
869 | 881 | ||
870 | void KOEditorRecurrence::readEvent(Incidence *event) | 882 | void KOEditorRecurrence::readEvent(Incidence *event) |
871 | { | 883 | { |
872 | 884 | ||
873 | QDateTime dtEnd; | 885 | QDateTime dtEnd; |
874 | if ( event->typeID() == eventID ) | 886 | if ( event->typeID() == eventID ) |
875 | dtEnd = ((Event*)event)->dtEnd(); | 887 | dtEnd = ((Event*)event)->dtEnd(); |
876 | else | 888 | else |
877 | dtEnd = ((Todo*)event)->dtDue(); | 889 | dtEnd = ((Todo*)event)->dtDue(); |
878 | 890 | ||
879 | setDefaults( event->dtStart(), dtEnd, true ); | 891 | setDefaults( event->dtStart(), dtEnd ); |
880 | QBitArray rDays( 7 ); | 892 | QBitArray rDays( 7 ); |
881 | QPtrList<Recurrence::rMonthPos> rmp; | 893 | QPtrList<Recurrence::rMonthPos> rmp; |
882 | QPtrList<int> rmd; | 894 | QPtrList<int> rmd; |
883 | int day = 0; | 895 | int day = 0; |
884 | int count = 0; | 896 | int count = 0; |
885 | int month = 0; | 897 | int month = 0; |
886 | setDateTimes( event->dtStart(), dtEnd ); | 898 | setDateTimes( event->dtStart(), dtEnd ); |
887 | 899 | ||
888 | Recurrence *r = event->recurrence(); | 900 | Recurrence *r = event->recurrence(); |
889 | int f = r->frequency(); | 901 | int f = r->frequency(); |
890 | 902 | ||
891 | int recurs = r->doesRecur(); | 903 | int recurs = r->doesRecur(); |
892 | 904 | ||
893 | mEnabledCheck->setChecked( recurs ); | 905 | mEnabledCheck->setChecked( recurs ); |
894 | setEnabled( recurs ); | 906 | setEnabled( recurs ); |
895 | 907 | ||
896 | int recurrenceType = RecurrenceChooser::Weekly; | 908 | int recurrenceType = RecurrenceChooser::Weekly; |
897 | 909 | ||
898 | switch ( recurs ) { | 910 | switch ( recurs ) { |
899 | case Recurrence::rNone: | 911 | case Recurrence::rNone: |
900 | setDefaults( event->dtStart(), dtEnd, true ); | 912 | setDefaults( event->dtStart(), dtEnd ); |
901 | break; | 913 | break; |
902 | case Recurrence::rDaily: | 914 | case Recurrence::rDaily: |
903 | recurrenceType = RecurrenceChooser::Daily; | 915 | recurrenceType = RecurrenceChooser::Daily; |
904 | mDaily->setFrequency( f ); | 916 | mDaily->setFrequency( f ); |
905 | break; | 917 | break; |
906 | case Recurrence::rWeekly: | 918 | case Recurrence::rWeekly: |
907 | recurrenceType = RecurrenceChooser::Weekly; | 919 | recurrenceType = RecurrenceChooser::Weekly; |
908 | mWeekly->setFrequency( f ); | 920 | mWeekly->setFrequency( f ); |
909 | mWeekly->setDays( r->days() ); | 921 | mWeekly->setDays( r->days() ); |
910 | break; | 922 | break; |
911 | case Recurrence::rMonthlyPos: | 923 | case Recurrence::rMonthlyPos: |
912 | // we only handle one possibility in the list right now, | 924 | // we only handle one possibility in the list right now, |
913 | // so I have hardcoded calls with first(). If we make the GUI | 925 | // so I have hardcoded calls with first(). If we make the GUI |
914 | // more extended, this can be changed. | 926 | // more extended, this can be changed. |
915 | recurrenceType = RecurrenceChooser::Monthly; | 927 | recurrenceType = RecurrenceChooser::Monthly; |
916 | 928 | ||
917 | rmp = r->monthPositions(); | 929 | rmp = r->monthPositions(); |
918 | if ( rmp.first()->negative ) | 930 | if ( rmp.first()->negative ) |
919 | count = 5 - rmp.first()->rPos - 1; | 931 | count = 5 - rmp.first()->rPos - 1; |
920 | else | 932 | else |
921 | count = rmp.first()->rPos - 1; | 933 | count = rmp.first()->rPos - 1; |
922 | day = 0; | 934 | day = 0; |
923 | while ( !rmp.first()->rDays.testBit( day ) ) ++day; | 935 | while ( !rmp.first()->rDays.testBit( day ) ) ++day; |
924 | mMonthly->setByPos( count, day ); | 936 | mMonthly->setByPos( count, day ); |
@@ -948,49 +960,49 @@ void KOEditorRecurrence::readEvent(Incidence *event) | |||
948 | month = event->dtStart().date().month() ; | 960 | month = event->dtStart().date().month() ; |
949 | mYearly->setByMonth( month, day ); | 961 | mYearly->setByMonth( month, day ); |
950 | #if 0 | 962 | #if 0 |
951 | //qDebug("2day = %d ",day ); | 963 | //qDebug("2day = %d ",day ); |
952 | QPtrList<Recurrence::rMonthPos> monthlist = r->yearMonthPositions(); | 964 | QPtrList<Recurrence::rMonthPos> monthlist = r->yearMonthPositions(); |
953 | int month; | 965 | int month; |
954 | if ( !monthlist.isEmpty() ) { | 966 | if ( !monthlist.isEmpty() ) { |
955 | month = monthlist.first()->rPos ; | 967 | month = monthlist.first()->rPos ; |
956 | } else { | 968 | } else { |
957 | month = event->dtStart().date().month() ; | 969 | month = event->dtStart().date().month() ; |
958 | } | 970 | } |
959 | mYearly->setByMonth( day, month ); | 971 | mYearly->setByMonth( day, month ); |
960 | #endif | 972 | #endif |
961 | mYearly->setFrequency( f ); | 973 | mYearly->setFrequency( f ); |
962 | } | 974 | } |
963 | 975 | ||
964 | break; | 976 | break; |
965 | case Recurrence::rYearlyDay: | 977 | case Recurrence::rYearlyDay: |
966 | //qDebug("Recurrence::rYearlyDay: "); | 978 | //qDebug("Recurrence::rYearlyDay: "); |
967 | recurrenceType = RecurrenceChooser::Yearly; | 979 | recurrenceType = RecurrenceChooser::Yearly; |
968 | mYearly->setByDay( event->dtStart().date().dayOfYear() ); | 980 | mYearly->setByDay( event->dtStart().date().dayOfYear() ); |
969 | mYearly->setFrequency( f ); | 981 | mYearly->setFrequency( f ); |
970 | break; | 982 | break; |
971 | default: | 983 | default: |
972 | setDefaults( event->dtStart(), dtEnd, true ); | 984 | setDefaults( event->dtStart(), dtEnd ); |
973 | break; | 985 | break; |
974 | } | 986 | } |
975 | 987 | ||
976 | mRecurrenceChooser->setType( recurrenceType ); | 988 | mRecurrenceChooser->setType( recurrenceType ); |
977 | showCurrentRule( recurrenceType ); | 989 | showCurrentRule( recurrenceType ); |
978 | 990 | ||
979 | mRecurrenceRange->setDateTimes( event->dtStart() ); | 991 | mRecurrenceRange->setDateTimes( event->dtStart() ); |
980 | 992 | ||
981 | if ( r->doesRecur() ) { | 993 | if ( r->doesRecur() ) { |
982 | mRecurrenceRange->setDuration( r->duration() ); | 994 | mRecurrenceRange->setDuration( r->duration() ); |
983 | if ( r->duration() == 0 ) | 995 | if ( r->duration() == 0 ) |
984 | { | 996 | { |
985 | if ( r->endDate() < event->dtStart().date() ) | 997 | if ( r->endDate() < event->dtStart().date() ) |
986 | mRecurrenceRange->setEndDate( event->dtStart().date() ); | 998 | mRecurrenceRange->setEndDate( event->dtStart().date() ); |
987 | else | 999 | else |
988 | mRecurrenceRange->setEndDate( r->endDate() ); | 1000 | mRecurrenceRange->setEndDate( r->endDate() ); |
989 | } else | 1001 | } else |
990 | mRecurrenceRange->setEndDate( event->dtStart().date() ); | 1002 | mRecurrenceRange->setEndDate( event->dtStart().date() ); |
991 | } | 1003 | } |
992 | 1004 | ||
993 | mExceptions->setDates( event->exDates() ); | 1005 | mExceptions->setDates( event->exDates() ); |
994 | } | 1006 | } |
995 | 1007 | ||
996 | void KOEditorRecurrence::writeEvent( Incidence *event ) | 1008 | void KOEditorRecurrence::writeEvent( Incidence *event ) |