summaryrefslogtreecommitdiffabout
path: root/korganizer/koeditorrecurrence.cpp
Unidiff
Diffstat (limited to 'korganizer/koeditorrecurrence.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/koeditorrecurrence.cpp172
1 files changed, 89 insertions, 83 deletions
diff --git a/korganizer/koeditorrecurrence.cpp b/korganizer/koeditorrecurrence.cpp
index de4e4f7..89504db 100644
--- a/korganizer/koeditorrecurrence.cpp
+++ b/korganizer/koeditorrecurrence.cpp
@@ -804,308 +804,314 @@ void KOEditorRecurrence::setEnabled( bool enabled )
804 if ( mRecurrenceRangeWidget ) mRecurrenceRangeWidget->setEnabled( enabled ); 804 if ( mRecurrenceRangeWidget ) mRecurrenceRangeWidget->setEnabled( enabled );
805 if ( mRecurrenceRangeButton ) mRecurrenceRangeButton->setEnabled( enabled ); 805 if ( mRecurrenceRangeButton ) mRecurrenceRangeButton->setEnabled( enabled );
806 if ( mExceptionsWidget ) mExceptionsWidget->setEnabled( enabled ); 806 if ( mExceptionsWidget ) mExceptionsWidget->setEnabled( enabled );
807 if ( mExceptionsButton ) mExceptionsButton->setEnabled( enabled ); 807 if ( mExceptionsButton ) mExceptionsButton->setEnabled( enabled );
808 mRuleBox->setEnabled( enabled ); 808 mRuleBox->setEnabled( enabled );
809} 809}
810 810
811void KOEditorRecurrence::showCurrentRule( int current ) 811void KOEditorRecurrence::showCurrentRule( int current )
812{ 812{
813 switch ( current ) { 813 switch ( 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
830void KOEditorRecurrence::setDateTimes( QDateTime start, QDateTime end ) 830void 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}
838void KOEditorRecurrence::setDefaultsDates( QDateTime from, QDateTime to ) 838void KOEditorRecurrence::setDefaultsDates( QDateTime from, QDateTime to )
839{ 839{
840 setDateTimes( from, to ); 840 setDateTimes( from, to );
841 QBitArray days( 7 ); 841 QBitArray days( 7 );
842 days.fill( 0 ); 842 days.fill( 0 );
843 days.setBit( from.date().dayOfWeek()- 1); 843 days.setBit( from.date().dayOfWeek()- 1);
844 mWeekly->setDays( days ); 844 mWeekly->setDays( days );
845 bool byPos = mMonthly->byPos(); 845 bool byPos = mMonthly->byPos();
846 if ( byPos ) 846 if ( byPos )
847 mMonthly->setByDay( from.date().day()-1 ); 847 mMonthly->setByDay( from.date().day()-1 );
848 mMonthly->setByPos((from.date().day()/7), from.date().dayOfWeek()-1 ); 848 mMonthly->setByPos((from.date().day()/7), from.date().dayOfWeek()-1 );
849 if ( ! byPos) 849 if ( ! byPos)
850 mMonthly->setByDay( from.date().day()-1 ); 850 mMonthly->setByDay( from.date().day()-1 );
851 851
852 bool byDay = mYearly->byDay(); 852 bool byDay = mYearly->byDay();
853 if ( ! byDay ) 853 if ( ! byDay )
854 mYearly->setByDay( from.date().dayOfYear() ); 854 mYearly->setByDay( from.date().dayOfYear() );
855 mYearly->setByMonth( from.date().month(), from.date().day() ); 855 mYearly->setByMonth( from.date().month(), from.date().day() );
856 if ( byDay ) 856 if ( byDay )
857 mYearly->setByDay( from.date().dayOfYear() ); 857 mYearly->setByDay( from.date().dayOfYear() );
858} 858}
859void KOEditorRecurrence::setDefaults( QDateTime from, QDateTime to ) 859void KOEditorRecurrence::setDefaults( QDateTime from, QDateTime to )
860{ 860{
861 861
862 // qDebug("KOEditorRecurrence::setDefaults %s %s ",from.toString().latin1(),to.toString().latin1() ); 862 // qDebug("KOEditorRecurrence::setDefaults %s %s ",from.toString().latin1(),to.toString().latin1() );
863 //setDateTimes( from, to ); 863 //setDateTimes( from, to );
864 864
865 bool enabled = false; 865 bool enabled = false;
866 mEnabledCheck->setChecked( enabled ); 866 mEnabledCheck->setChecked( enabled );
867 setEnabled( enabled ); 867 setEnabled( enabled );
868 868
869 mExceptions->setDefaults( to ); 869 mExceptions->setDefaults( to );
870 mRecurrenceRange->setDefaults( to ); 870 mRecurrenceRange->setDefaults( to );
871 871
872 mRecurrenceChooser->setType( RecurrenceChooser::Weekly ); 872 mRecurrenceChooser->setType( RecurrenceChooser::Weekly );
873 showCurrentRule( mRecurrenceChooser->type() ); 873 showCurrentRule( mRecurrenceChooser->type() );
874 874
875 mDaily->setFrequency( 1 ); 875 mDaily->setFrequency( 1 );
876 mWeekly->setFrequency( 1 ); 876 mWeekly->setFrequency( 1 );
877 mMonthly->setFrequency( 1 ); 877 mMonthly->setFrequency( 1 );
878 mYearly->setFrequency( 1 ); 878 mYearly->setFrequency( 1 );
879 setDefaultsDates( from, to ); 879 setDefaultsDates( from, to );
880} 880}
881 881
882void KOEditorRecurrence::readEvent(Incidence *event) 882void KOEditorRecurrence::readEvent(Incidence *event)
883{ 883{
884 884
885 QDateTime dtEnd; 885 QDateTime dtEnd;
886 if ( event->typeID() == eventID ) 886 if ( event->typeID() == eventID )
887 dtEnd = ((Event*)event)->dtEnd(); 887 dtEnd = ((Event*)event)->dtEnd();
888 else 888 else
889 dtEnd = ((Todo*)event)->dtDue(); 889 dtEnd = ((Todo*)event)->dtDue();
890 890
891 setDefaults( event->dtStart(), dtEnd ); 891 setDefaults( event->dtStart(), dtEnd );
892 QBitArray rDays( 7 ); 892 QBitArray rDays( 7 );
893 QPtrList<Recurrence::rMonthPos> rmp; 893 QPtrList<Recurrence::rMonthPos> rmp;
894 QPtrList<int> rmd; 894 QPtrList<int> rmd;
895 int day = 0; 895 int day = 0;
896 int count = 0; 896 int count = 0;
897 int month = 0; 897 int month = 0;
898 setDateTimes( event->dtStart(), dtEnd ); 898 setDateTimes( event->dtStart(), dtEnd );
899 899
900 Recurrence *r = event->recurrence(); 900
901 int f = r->frequency();
902 901
903 int recurs = r->doesRecur(); 902 int recurs = event->doesRecur();
904 903
905 mEnabledCheck->setChecked( recurs ); 904 mEnabledCheck->setChecked( recurs );
906 setEnabled( recurs ); 905 setEnabled( recurs );
907 906
908 int recurrenceType = RecurrenceChooser::Weekly; 907 int recurrenceType = RecurrenceChooser::Weekly;
909 908 if ( recurs ) {
910 switch ( recurs ) { 909 Recurrence *r = event->recurrence();
911 case Recurrence::rNone: 910 int f = r->frequency();
912 setDefaults( event->dtStart(), dtEnd ); 911 switch ( recurs ) {
913 break; 912 case Recurrence::rNone:
914 case Recurrence::rDaily: 913 setDefaults( event->dtStart(), dtEnd );
915 recurrenceType = RecurrenceChooser::Daily; 914 break;
916 mDaily->setFrequency( f ); 915 case Recurrence::rDaily:
917 break; 916 recurrenceType = RecurrenceChooser::Daily;
918 case Recurrence::rWeekly: 917 mDaily->setFrequency( f );
919 recurrenceType = RecurrenceChooser::Weekly; 918 break;
920 mWeekly->setFrequency( f ); 919 case Recurrence::rWeekly:
921 mWeekly->setDays( r->days() ); 920 recurrenceType = RecurrenceChooser::Weekly;
922 break; 921 mWeekly->setFrequency( f );
923 case Recurrence::rMonthlyPos: 922 mWeekly->setDays( r->days() );
924 // we only handle one possibility in the list right now, 923 break;
925 // so I have hardcoded calls with first(). If we make the GUI 924 case Recurrence::rMonthlyPos:
926 // more extended, this can be changed. 925 // we only handle one possibility in the list right now,
927 recurrenceType = RecurrenceChooser::Monthly; 926 // so I have hardcoded calls with first(). If we make the GUI
928 927 // more extended, this can be changed.
929 rmp = r->monthPositions(); 928 recurrenceType = RecurrenceChooser::Monthly;
930 if ( rmp.first()->negative ) 929
931 count = 5 - rmp.first()->rPos - 1; 930 rmp = r->monthPositions();
932 else 931 if ( rmp.first()->negative )
933 count = rmp.first()->rPos - 1; 932 count = 5 - rmp.first()->rPos - 1;
934 day = 0; 933 else
935 while ( !rmp.first()->rDays.testBit( day ) ) ++day; 934 count = rmp.first()->rPos - 1;
936 mMonthly->setByPos( count, day ); 935 day = 0;
937 936 while ( !rmp.first()->rDays.testBit( day ) ) ++day;
938 mMonthly->setFrequency( f ); 937 mMonthly->setByPos( count, day );
939 938
940 break; 939 mMonthly->setFrequency( f );
941 case Recurrence::rMonthlyDay: 940
942 recurrenceType = RecurrenceChooser::Monthly; 941 break;
943 942 case Recurrence::rMonthlyDay:
944 rmd = r->monthDays(); 943 recurrenceType = RecurrenceChooser::Monthly;
945 day = *rmd.first() - 1; 944
946 mMonthly->setByDay( day ); 945 rmd = r->monthDays();
947 946 day = *rmd.first() - 1;
948 mMonthly->setFrequency( f ); 947 mMonthly->setByDay( day );
949 948
950 break; 949 mMonthly->setFrequency( f );
951 case Recurrence::rYearlyMonth: 950
952 { 951 break;
953 recurrenceType = RecurrenceChooser::Yearly; 952 case Recurrence::rYearlyMonth:
954 //qDebug("Recurrence::rYearlyMonth: "); 953 {
955 day = event->dtStart().date().day(); 954 recurrenceType = RecurrenceChooser::Yearly;
956 rmd = r->yearNums(); 955 //qDebug("Recurrence::rYearlyMonth: ");
957 if ( rmd.count() > 0 ) 956 day = event->dtStart().date().day();
958 month = *rmd.first(); 957 rmd = r->yearNums();
959 else 958 if ( rmd.count() > 0 )
960 month = event->dtStart().date().month() ; 959 month = *rmd.first();
961 mYearly->setByMonth( month, day ); 960 else
961 month = event->dtStart().date().month() ;
962 mYearly->setByMonth( month, day );
962#if 0 963#if 0
963 //qDebug("2day = %d ",day ); 964 //qDebug("2day = %d ",day );
964 QPtrList<Recurrence::rMonthPos> monthlist = r->yearMonthPositions(); 965 QPtrList<Recurrence::rMonthPos> monthlist = r->yearMonthPositions();
965 int month; 966 int month;
966 if ( !monthlist.isEmpty() ) { 967 if ( !monthlist.isEmpty() ) {
967 month = monthlist.first()->rPos ; 968 month = monthlist.first()->rPos ;
968 } else { 969 } else {
969 month = event->dtStart().date().month() ; 970 month = event->dtStart().date().month() ;
970 } 971 }
971 mYearly->setByMonth( day, month ); 972 mYearly->setByMonth( day, month );
972#endif 973#endif
973 mYearly->setFrequency( f ); 974 mYearly->setFrequency( f );
974 } 975 }
975 976
976 break; 977 break;
977 case Recurrence::rYearlyDay: 978 case Recurrence::rYearlyDay:
978 //qDebug("Recurrence::rYearlyDay: "); 979 //qDebug("Recurrence::rYearlyDay: ");
979 recurrenceType = RecurrenceChooser::Yearly; 980 recurrenceType = RecurrenceChooser::Yearly;
980 mYearly->setByDay( event->dtStart().date().dayOfYear() ); 981 mYearly->setByDay( event->dtStart().date().dayOfYear() );
981 mYearly->setFrequency( f ); 982 mYearly->setFrequency( f );
982 break; 983 break;
983 default: 984 default:
984 setDefaults( event->dtStart(), dtEnd ); 985 setDefaults( event->dtStart(), dtEnd );
985 break; 986 break;
987 }
986 } 988 }
987
988 mRecurrenceChooser->setType( recurrenceType ); 989 mRecurrenceChooser->setType( recurrenceType );
989 showCurrentRule( recurrenceType ); 990 showCurrentRule( recurrenceType );
990 991
991 mRecurrenceRange->setDateTimes( event->dtStart() ); 992 mRecurrenceRange->setDateTimes( event->dtStart() );
992 993
993 if ( r->doesRecur() ) { 994 if ( event->doesRecur() ) {
995 Recurrence *r = event->recurrence();
994 mRecurrenceRange->setDuration( r->duration() ); 996 mRecurrenceRange->setDuration( r->duration() );
995 if ( r->duration() == 0 ) 997 if ( r->duration() == 0 )
996 { 998 {
997 if ( r->endDate() < event->dtStart().date() ) 999 if ( r->endDate() < event->dtStart().date() )
998 mRecurrenceRange->setEndDate( event->dtStart().date() ); 1000 mRecurrenceRange->setEndDate( event->dtStart().date() );
999 else 1001 else
1000 mRecurrenceRange->setEndDate( r->endDate() ); 1002 mRecurrenceRange->setEndDate( r->endDate() );
1001 } else 1003 } else
1002 mRecurrenceRange->setEndDate( event->dtStart().date() ); 1004 mRecurrenceRange->setEndDate( event->dtStart().date() );
1003 } 1005 }
1004 1006
1005 mExceptions->setDates( event->exDates() ); 1007 mExceptions->setDates( event->exDates() );
1006} 1008}
1007 1009
1008void KOEditorRecurrence::writeEvent( Incidence *event ) 1010void KOEditorRecurrence::writeEvent( Incidence *event )
1009{ 1011{
1010 Recurrence *r = event->recurrence(); 1012
1011 1013
1012 // clear out any old settings; 1014 if ( !mEnabledCheck->isChecked() ) {
1013 r->unsetRecurs(); 1015 if ( event->doesRecur() )
1016 event->recurrence()->unsetRecurs();
1017 } else {
1018 Recurrence *r = event->recurrence();
1014 1019
1015 if ( mEnabledCheck->isChecked() ) { 1020 // clear out any old settings;
1021 r->unsetRecurs();
1016 int duration = mRecurrenceRange->duration(); 1022 int duration = mRecurrenceRange->duration();
1017 QDate endDate; 1023 QDate endDate;
1018 if ( duration == 0 ) endDate = mRecurrenceRange->endDate(); 1024 if ( duration == 0 ) endDate = mRecurrenceRange->endDate();
1019 1025
1020 int recurrenceType = mRecurrenceChooser->type(); 1026 int recurrenceType = mRecurrenceChooser->type();
1021 1027
1022 if ( recurrenceType == RecurrenceChooser::Daily ) { 1028 if ( recurrenceType == RecurrenceChooser::Daily ) {
1023 int freq = mDaily->frequency(); 1029 int freq = mDaily->frequency();
1024 if ( duration != 0 ) r->setDaily( freq, duration ); 1030 if ( duration != 0 ) r->setDaily( freq, duration );
1025 else r->setDaily( freq, endDate ); 1031 else r->setDaily( freq, endDate );
1026 } else if ( recurrenceType == RecurrenceChooser::Weekly ) { 1032 } else if ( recurrenceType == RecurrenceChooser::Weekly ) {
1027 int freq = mWeekly->frequency(); 1033 int freq = mWeekly->frequency();
1028 QBitArray days = mWeekly->days(); 1034 QBitArray days = mWeekly->days();
1029 int j; 1035 int j;
1030 bool found = false; 1036 bool found = false;
1031 for (j = 0; j < 7 ; ++j ) { 1037 for (j = 0; j < 7 ; ++j ) {
1032 found |=days.at(j); 1038 found |=days.at(j);
1033 } 1039 }
1034 if ( !found ) { 1040 if ( !found ) {
1035 days.setBit( event->dtStart().date().dayOfWeek()-1); 1041 days.setBit( event->dtStart().date().dayOfWeek()-1);
1036 //qDebug("bit set %d ", event->dtStart().date().dayOfWeek()-1); 1042 //qDebug("bit set %d ", event->dtStart().date().dayOfWeek()-1);
1037 } 1043 }
1038 if ( duration != 0 ) r->setWeekly( freq, days, duration ); 1044 if ( duration != 0 ) r->setWeekly( freq, days, duration );
1039 else r->setWeekly( freq, days, endDate ); 1045 else r->setWeekly( freq, days, endDate );
1040 } else if ( recurrenceType == RecurrenceChooser::Monthly ) { 1046 } else if ( recurrenceType == RecurrenceChooser::Monthly ) {
1041 int freq = mMonthly->frequency(); 1047 int freq = mMonthly->frequency();
1042 if ( mMonthly->byPos() ) { 1048 if ( mMonthly->byPos() ) {
1043 int pos = mMonthly->count(); 1049 int pos = mMonthly->count();
1044 1050
1045 QBitArray days( 7 ); 1051 QBitArray days( 7 );
1046 days.fill( false ); 1052 days.fill( false );
1047 1053
1048 days.setBit( mMonthly->weekday() ); 1054 days.setBit( mMonthly->weekday() );
1049 if ( duration != 0 ) 1055 if ( duration != 0 )
1050 r->setMonthly( Recurrence::rMonthlyPos, freq, duration ); 1056 r->setMonthly( Recurrence::rMonthlyPos, freq, duration );
1051 else 1057 else
1052 r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); 1058 r->setMonthly( Recurrence::rMonthlyPos, freq, endDate );
1053 r->addMonthlyPos( pos, days ); 1059 r->addMonthlyPos( pos, days );
1054 } else { 1060 } else {
1055 // it's by day 1061 // it's by day
1056 int day = mMonthly->day(); 1062 int day = mMonthly->day();
1057 1063
1058 if ( duration != 0 ) { 1064 if ( duration != 0 ) {
1059 r->setMonthly( Recurrence::rMonthlyDay, freq, duration ); 1065 r->setMonthly( Recurrence::rMonthlyDay, freq, duration );
1060 } else { 1066 } else {
1061 r->setMonthly( Recurrence::rMonthlyDay, freq, endDate ); 1067 r->setMonthly( Recurrence::rMonthlyDay, freq, endDate );
1062 } 1068 }
1063 r->addMonthlyDay( day ); 1069 r->addMonthlyDay( day );
1064 } 1070 }
1065 } else if ( recurrenceType == RecurrenceChooser::Yearly ) { 1071 } else if ( recurrenceType == RecurrenceChooser::Yearly ) {
1066 //qDebug("RecurrenceChooser::Yearly "); 1072 //qDebug("RecurrenceChooser::Yearly ");
1067 int freq = mYearly->frequency(); 1073 int freq = mYearly->frequency();
1068 if ( mYearly->byDay() ) { 1074 if ( mYearly->byDay() ) {
1069 if ( duration != 0 ) { 1075 if ( duration != 0 ) {
1070 r->setYearly( Recurrence::rYearlyDay, freq, duration ); 1076 r->setYearly( Recurrence::rYearlyDay, freq, duration );
1071 } else { 1077 } else {
1072 r->setYearly( Recurrence::rYearlyDay, freq, endDate ); 1078 r->setYearly( Recurrence::rYearlyDay, freq, endDate );
1073 } 1079 }
1074 r->addYearlyNum( event->dtStart().date().dayOfYear() ); 1080 r->addYearlyNum( event->dtStart().date().dayOfYear() );
1075 } else { 1081 } else {
1076 if ( duration != 0 ) { 1082 if ( duration != 0 ) {
1077 r->setYearly( Recurrence::rYearlyMonth, freq, duration ); 1083 r->setYearly( Recurrence::rYearlyMonth, freq, duration );
1078 } else { 1084 } else {
1079 r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); 1085 r->setYearly( Recurrence::rYearlyMonth, freq, endDate );
1080 } 1086 }
1081 r->addYearlyNum( mYearly->month() ); 1087 r->addYearlyNum( mYearly->month() );
1082 } 1088 }
1083 1089
1084 } 1090 }
1085 1091
1086 event->setExDates( mExceptions->dates() ); 1092 event->setExDates( mExceptions->dates() );
1087 } 1093 }
1088} 1094}
1089 1095
1090void KOEditorRecurrence::setDateTimeStr( const QString &str ) 1096void KOEditorRecurrence::setDateTimeStr( const QString &str )
1091{ 1097{
1092 mDateTimeLabel->setText( str ); 1098 mDateTimeLabel->setText( str );
1093} 1099}
1094 1100
1095bool KOEditorRecurrence::validateInput() 1101bool KOEditorRecurrence::validateInput()
1096{ 1102{
1097 // Check input here 1103 // Check input here
1098 1104
1099 return true; 1105 return true;
1100} 1106}
1101 1107
1102void KOEditorRecurrence::showExceptionsDialog() 1108void KOEditorRecurrence::showExceptionsDialog()
1103{ 1109{
1104 DateList dates = mExceptions->dates(); 1110 DateList dates = mExceptions->dates();
1105 int result = mExceptionsDialog->exec(); 1111 int result = mExceptionsDialog->exec();
1106 if ( result == QDialog::Rejected ) mExceptions->setDates( dates ); 1112 if ( result == QDialog::Rejected ) mExceptions->setDates( dates );
1107} 1113}
1108 1114
1109void KOEditorRecurrence::showRecurrenceRangeDialog() 1115void KOEditorRecurrence::showRecurrenceRangeDialog()
1110{ 1116{
1111 int duration = mRecurrenceRange->duration(); 1117 int duration = mRecurrenceRange->duration();