summaryrefslogtreecommitdiffabout
path: root/korganizer/koeditorrecurrence.cpp
Unidiff
Diffstat (limited to 'korganizer/koeditorrecurrence.cpp') (more/less context) (show whitespace changes)
-rw-r--r--korganizer/koeditorrecurrence.cpp40
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
@@ -790,231 +790,243 @@ KOEditorRecurrence::KOEditorRecurrence( QWidget* parent, const char *name ) :
790 } 790 }
791 connect( mExceptionsButton, SIGNAL( clicked() ), 791 connect( mExceptionsButton, SIGNAL( clicked() ),
792 SLOT( showExceptionsDialog() ) ); 792 SLOT( showExceptionsDialog() ) );
793} 793}
794 794
795KOEditorRecurrence::~KOEditorRecurrence() 795KOEditorRecurrence::~KOEditorRecurrence()
796{ 796{
797} 797}
798 798
799void KOEditorRecurrence::setEnabled( bool enabled ) 799void KOEditorRecurrence::setEnabled( bool enabled )
800{ 800{
801// kdDebug() << "KOEditorRecurrence::setEnabled(): " << (enabled ? "on" : "off") << endl; 801// kdDebug() << "KOEditorRecurrence::setEnabled(): " << (enabled ? "on" : "off") << endl;
802 802
803 mTimeGroupBox->setEnabled( enabled ); 803 mTimeGroupBox->setEnabled( 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 )
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
839void 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}
859void 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
870void KOEditorRecurrence::readEvent(Incidence *event) 882void 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 );
925 937
926 mMonthly->setFrequency( f ); 938 mMonthly->setFrequency( f );
927 939
928 break; 940 break;
929 case Recurrence::rMonthlyDay: 941 case Recurrence::rMonthlyDay:
930 recurrenceType = RecurrenceChooser::Monthly; 942 recurrenceType = RecurrenceChooser::Monthly;
931 943
932 rmd = r->monthDays(); 944 rmd = r->monthDays();
933 day = *rmd.first() - 1; 945 day = *rmd.first() - 1;
934 mMonthly->setByDay( day ); 946 mMonthly->setByDay( day );
935 947
936 mMonthly->setFrequency( f ); 948 mMonthly->setFrequency( f );
937 949
938 break; 950 break;
939 case Recurrence::rYearlyMonth: 951 case Recurrence::rYearlyMonth:
940 { 952 {
941 recurrenceType = RecurrenceChooser::Yearly; 953 recurrenceType = RecurrenceChooser::Yearly;
942 //qDebug("Recurrence::rYearlyMonth: "); 954 //qDebug("Recurrence::rYearlyMonth: ");
943 day = event->dtStart().date().day(); 955 day = event->dtStart().date().day();
944 rmd = r->yearNums(); 956 rmd = r->yearNums();
945 if ( rmd.count() > 0 ) 957 if ( rmd.count() > 0 )
946 month = *rmd.first(); 958 month = *rmd.first();
947 else 959 else
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
996void KOEditorRecurrence::writeEvent( Incidence *event ) 1008void KOEditorRecurrence::writeEvent( Incidence *event )
997{ 1009{
998 Recurrence *r = event->recurrence(); 1010 Recurrence *r = event->recurrence();
999 1011
1000 // clear out any old settings; 1012 // clear out any old settings;
1001 r->unsetRecurs(); 1013 r->unsetRecurs();
1002 1014
1003 if ( mEnabledCheck->isChecked() ) { 1015 if ( mEnabledCheck->isChecked() ) {
1004 int duration = mRecurrenceRange->duration(); 1016 int duration = mRecurrenceRange->duration();
1005 QDate endDate; 1017 QDate endDate;
1006 if ( duration == 0 ) endDate = mRecurrenceRange->endDate(); 1018 if ( duration == 0 ) endDate = mRecurrenceRange->endDate();
1007 1019
1008 int recurrenceType = mRecurrenceChooser->type(); 1020 int recurrenceType = mRecurrenceChooser->type();
1009 1021
1010 if ( recurrenceType == RecurrenceChooser::Daily ) { 1022 if ( recurrenceType == RecurrenceChooser::Daily ) {
1011 int freq = mDaily->frequency(); 1023 int freq = mDaily->frequency();
1012 if ( duration != 0 ) r->setDaily( freq, duration ); 1024 if ( duration != 0 ) r->setDaily( freq, duration );
1013 else r->setDaily( freq, endDate ); 1025 else r->setDaily( freq, endDate );
1014 } else if ( recurrenceType == RecurrenceChooser::Weekly ) { 1026 } else if ( recurrenceType == RecurrenceChooser::Weekly ) {
1015 int freq = mWeekly->frequency(); 1027 int freq = mWeekly->frequency();
1016 QBitArray days = mWeekly->days(); 1028 QBitArray days = mWeekly->days();
1017 int j; 1029 int j;
1018 bool found = false; 1030 bool found = false;
1019 for (j = 0; j < 7 ; ++j ) { 1031 for (j = 0; j < 7 ; ++j ) {
1020 found |=days.at(j); 1032 found |=days.at(j);