summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-07-10 17:03:16 (UTC)
committer zautrix <zautrix>2004-07-10 17:03:16 (UTC)
commitcf2f3f98a4811668f9e9d0d5f44ea5b51d268cef (patch) (unidiff)
tree963322cd4c539c084feb43dfde5eabe52ae4385f
parent8cc6d456812b5a9a386e81c9e46baccd56029537 (diff)
downloadkdepimpi-cf2f3f98a4811668f9e9d0d5f44ea5b51d268cef.zip
kdepimpi-cf2f3f98a4811668f9e9d0d5f44ea5b51d268cef.tar.gz
kdepimpi-cf2f3f98a4811668f9e9d0d5f44ea5b51d268cef.tar.bz2
Fixed some problems with the recurrence
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/koeditorrecurrence.cpp125
-rw-r--r--korganizer/koeditorrecurrence.h9
-rw-r--r--libkcal/icalformatimpl.cpp20
-rw-r--r--libkcal/recurrence.cpp17
-rw-r--r--libkcal/recurrence.h6
5 files changed, 110 insertions, 67 deletions
diff --git a/korganizer/koeditorrecurrence.cpp b/korganizer/koeditorrecurrence.cpp
index 98356fe..ffc0fac 100644
--- a/korganizer/koeditorrecurrence.cpp
+++ b/korganizer/koeditorrecurrence.cpp
@@ -283,113 +283,112 @@ int RecurMonthly::weekday()
283/////////////////////////// RecurYearly /////////////////////////////// 283/////////////////////////// RecurYearly ///////////////////////////////
284 284
285RecurYearly::RecurYearly( QWidget *parent, const char *name ) : 285RecurYearly::RecurYearly( QWidget *parent, const char *name ) :
286 RecurBase( parent, name ) 286 RecurBase( parent, name )
287{ 287{
288 QBoxLayout *topLayout = new QVBoxLayout( this ); 288 QBoxLayout *topLayout = new QVBoxLayout( this );
289 topLayout->setSpacing( KDialog::spacingHint() ); 289 topLayout->setSpacing( KDialog::spacingHint() );
290 290
291 291
292 QBoxLayout *freqLayout = new QHBoxLayout( topLayout ); 292 QBoxLayout *freqLayout = new QHBoxLayout( topLayout );
293 293
294 QLabel *preLabel = new QLabel( i18n("every"), this ); 294 QLabel *preLabel = new QLabel( i18n("every"), this );
295 freqLayout->addWidget( preLabel ); 295 freqLayout->addWidget( preLabel );
296 296
297 freqLayout->addWidget( frequencyEdit() ); 297 freqLayout->addWidget( frequencyEdit() );
298 298
299 QLabel *postLabel = new QLabel( i18n("year(s)"), this ); 299 QLabel *postLabel = new QLabel( i18n("year(s)"), this );
300 freqLayout->addWidget( postLabel ); 300 freqLayout->addWidget( postLabel );
301 301
302 302
303 QButtonGroup *buttonGroup = new QButtonGroup( this ); 303 QButtonGroup *buttonGroup = new QButtonGroup( this );
304 buttonGroup->setFrameStyle( QFrame::NoFrame ); 304 buttonGroup->setFrameStyle( QFrame::NoFrame );
305 topLayout->addWidget( buttonGroup, 1, AlignVCenter ); 305 topLayout->addWidget( buttonGroup, 1, AlignVCenter );
306 306
307 QGridLayout *buttonLayout = new QGridLayout( buttonGroup, 3, 2 ); 307 QGridLayout *buttonLayout = new QGridLayout( buttonGroup, 2, 3 );
308
309 QString recurInMonthText;
310 if ( !KOPrefs::instance()->mCompactDialogs ) {
311 recurInMonthText = i18n("Recur in the month of");
312 }
313
314 mByMonthRadio = new QRadioButton( recurInMonthText, buttonGroup);
315 buttonLayout->addWidget( mByMonthRadio, 0, 0 );
316 308
309 mByMonthRadio = new QRadioButton( i18n("On day "), buttonGroup);
310 buttonLayout->addWidget( mByMonthRadio, 0, 0 , Qt::AlignRight);
311 mByDayLabel = new QLabel( i18n(" 1 of "), buttonGroup );
312
313 buttonLayout->addWidget( mByDayLabel, 0, 1 );
317 mByMonthCombo = new QComboBox( buttonGroup ); 314 mByMonthCombo = new QComboBox( buttonGroup );
318 mByMonthCombo->insertItem( i18n("January") ); 315 mByMonthCombo->insertItem( i18n("January") );
319 mByMonthCombo->insertItem( i18n("February") ); 316 mByMonthCombo->insertItem( i18n("February") );
320 mByMonthCombo->insertItem( i18n("March") ); 317 mByMonthCombo->insertItem( i18n("March") );
321 mByMonthCombo->insertItem( i18n("April") ); 318 mByMonthCombo->insertItem( i18n("April") );
322 mByMonthCombo->insertItem( i18n("May") ); 319 mByMonthCombo->insertItem( i18n("May") );
323 mByMonthCombo->insertItem( i18n("June") ); 320 mByMonthCombo->insertItem( i18n("June") );
324 mByMonthCombo->insertItem( i18n("July") ); 321 mByMonthCombo->insertItem( i18n("July") );
325 mByMonthCombo->insertItem( i18n("August") ); 322 mByMonthCombo->insertItem( i18n("August") );
326 mByMonthCombo->insertItem( i18n("September") ); 323 mByMonthCombo->insertItem( i18n("September") );
327 mByMonthCombo->insertItem( i18n("October") ); 324 mByMonthCombo->insertItem( i18n("October") );
328 mByMonthCombo->insertItem( i18n("November") ); 325 mByMonthCombo->insertItem( i18n("November") );
329 mByMonthCombo->insertItem( i18n("December") ); 326 mByMonthCombo->insertItem( i18n("December") );
330 buttonLayout->addWidget( mByMonthCombo, 0, 1 ); 327 buttonLayout->addWidget( mByMonthCombo, 0, 2,Qt::AlignLeft );
331 328 if ( QApplication::desktop()->width() <= 640 ) {
332 mByMonthCombo->setSizeLimit( 6 ); 329 mByMonthCombo->setSizeLimit( 6 );
333 330 }
334 buttonLayout->setRowStretch( 1, 1 ); 331
335 332 mByDayRadio = new QRadioButton( i18n("On day "), buttonGroup);
336 QString recurOnDayText; 333 buttonLayout->addWidget( mByDayRadio, 1, 0 , Qt::AlignRight);
337 if ( KOPrefs::instance()->mCompactDialogs ) { 334 mDayOfLabel = new QLabel( i18n("1 of the year"), buttonGroup );
338 recurOnDayText = i18n("This day"); 335 buttonLayout->addMultiCellWidget( mDayOfLabel, 1, 1, 1,3 );
339 } else { 336
340 recurOnDayText = i18n("Recur on this day");
341 }
342
343 mByDayRadio = new QRadioButton( recurOnDayText, buttonGroup);
344 buttonLayout->addMultiCellWidget( mByDayRadio, 2, 2, 0, 1 );
345} 337}
346 338
347void RecurYearly::setByDay() 339void RecurYearly::setByDay( int doy )
348{ 340{
349 mByDayRadio->setChecked( true ); 341 mByDayRadio->setChecked( true );
342 mDayOfLabel->setText(i18n("%1 of the year").arg( doy ) );
350} 343}
351 344
352void RecurYearly::setByMonth( int month ) 345void RecurYearly::setByMonth( int month, int day )
353{ 346{
354 mByMonthRadio->setChecked( true ); 347 mByMonthRadio->setChecked( true );
355 mByMonthCombo->setCurrentItem( month - 1 ); 348 mByMonthCombo->setCurrentItem( month - 1 );
349 mByDayLabel->setText(i18n("%1 of ").arg( day ) );
350 mDay = day;
356} 351}
357 352
358bool RecurYearly::byMonth() 353bool RecurYearly::byMonth()
359{ 354{
360 return mByMonthRadio->isChecked(); 355 return mByMonthRadio->isChecked();
361} 356}
362 357
363bool RecurYearly::byDay() 358bool RecurYearly::byDay()
364{ 359{
365 return mByDayRadio->isChecked(); 360 return mByDayRadio->isChecked();
366} 361}
367 362
368int RecurYearly::month() 363int RecurYearly::month()
369{ 364{
370 return mByMonthCombo->currentItem() + 1; 365 return mByMonthCombo->currentItem() + 1;
371} 366}
367int RecurYearly::day()
368{
369 return mDay;//mByDayCombo->currentItem() + 1;
370}
372 371
373//////////////////////////// ExceptionsWidget ////////////////////////// 372//////////////////////////// ExceptionsWidget //////////////////////////
374 373
375ExceptionsWidget::ExceptionsWidget( QWidget *parent, const char *name ) : 374ExceptionsWidget::ExceptionsWidget( QWidget *parent, const char *name ) :
376 QWidget( parent, name ) 375 QWidget( parent, name )
377{ 376{
378 QBoxLayout *topLayout = new QVBoxLayout( this ); 377 QBoxLayout *topLayout = new QVBoxLayout( this );
379 378
380 QGroupBox *groupBox = new QGroupBox( 1, Horizontal, i18n("Exceptions"), 379 QGroupBox *groupBox = new QGroupBox( 1, Horizontal, i18n("Exceptions"),
381 this ); 380 this );
382 topLayout->addWidget( groupBox ); 381 topLayout->addWidget( groupBox );
383 382
384 QWidget *box = new QWidget( groupBox ); 383 QWidget *box = new QWidget( groupBox );
385 384
386 QGridLayout *boxLayout = new QGridLayout( box ); 385 QGridLayout *boxLayout = new QGridLayout( box );
387 386
388 mExceptionDateEdit = new KDateEdit( box ); 387 mExceptionDateEdit = new KDateEdit( box );
389 boxLayout->addWidget( mExceptionDateEdit, 0, 0 ); 388 boxLayout->addWidget( mExceptionDateEdit, 0, 0 );
390 389
391 QPushButton *addExceptionButton = new QPushButton( i18n("Add"), box ); 390 QPushButton *addExceptionButton = new QPushButton( i18n("Add"), box );
392 boxLayout->addWidget( addExceptionButton, 1, 0 ); 391 boxLayout->addWidget( addExceptionButton, 1, 0 );
393 QPushButton *changeExceptionButton = new QPushButton( i18n("Change"), box ); 392 QPushButton *changeExceptionButton = new QPushButton( i18n("Change"), box );
394 boxLayout->addWidget( changeExceptionButton, 2, 0 ); 393 boxLayout->addWidget( changeExceptionButton, 2, 0 );
395 QPushButton *deleteExceptionButton = new QPushButton( i18n("Delete"), box ); 394 QPushButton *deleteExceptionButton = new QPushButton( i18n("Delete"), box );
@@ -823,48 +822,49 @@ KOEditorRecurrence::KOEditorRecurrence( QWidget* parent, const char *name ) :
823 mRecurrenceRangeButton = 0; 822 mRecurrenceRangeButton = 0;
824 topLayout->addWidget( mRecurrenceRangeWidget, 3, 0 ); 823 topLayout->addWidget( mRecurrenceRangeWidget, 3, 0 );
825 824
826 mExceptionsWidget = new ExceptionsWidget( this ); 825 mExceptionsWidget = new ExceptionsWidget( this );
827 mExceptionsDialog = 0; 826 mExceptionsDialog = 0;
828 mExceptions = mExceptionsWidget; 827 mExceptions = mExceptionsWidget;
829 mExceptionsButton = 0; 828 mExceptionsButton = 0;
830 topLayout->addWidget( mExceptionsWidget, 3, 1 ); 829 topLayout->addWidget( mExceptionsWidget, 3, 1 );
831 } 830 }
832} 831}
833 832
834KOEditorRecurrence::~KOEditorRecurrence() 833KOEditorRecurrence::~KOEditorRecurrence()
835{ 834{
836} 835}
837 836
838void KOEditorRecurrence::setEnabled( bool enabled ) 837void KOEditorRecurrence::setEnabled( bool enabled )
839{ 838{
840// kdDebug() << "KOEditorRecurrence::setEnabled(): " << (enabled ? "on" : "off") << endl; 839// kdDebug() << "KOEditorRecurrence::setEnabled(): " << (enabled ? "on" : "off") << endl;
841 840
842 mTimeGroupBox->setEnabled( enabled ); 841 mTimeGroupBox->setEnabled( enabled );
843 if ( mRecurrenceRangeWidget ) mRecurrenceRangeWidget->setEnabled( enabled ); 842 if ( mRecurrenceRangeWidget ) mRecurrenceRangeWidget->setEnabled( enabled );
844 if ( mRecurrenceRangeButton ) mRecurrenceRangeButton->setEnabled( enabled ); 843 if ( mRecurrenceRangeButton ) mRecurrenceRangeButton->setEnabled( enabled );
845 if ( mExceptionsWidget ) mExceptionsWidget->setEnabled( enabled ); 844 if ( mExceptionsWidget ) mExceptionsWidget->setEnabled( enabled );
846 if ( mExceptionsButton ) mExceptionsButton->setEnabled( enabled ); 845 if ( mExceptionsButton ) mExceptionsButton->setEnabled( enabled );
846 mRuleBox->setEnabled( enabled );
847} 847}
848 848
849void KOEditorRecurrence::showCurrentRule( int current ) 849void KOEditorRecurrence::showCurrentRule( int current )
850{ 850{
851 switch ( current ) { 851 switch ( current ) {
852 case Daily: 852 case Daily:
853 mRuleStack->raiseWidget( mDaily ); 853 mRuleStack->raiseWidget( mDaily );
854 break; 854 break;
855 case Weekly: 855 case Weekly:
856 mRuleStack->raiseWidget( mWeekly ); 856 mRuleStack->raiseWidget( mWeekly );
857 break; 857 break;
858 case Monthly: 858 case Monthly:
859 mRuleStack->raiseWidget( mMonthly ); 859 mRuleStack->raiseWidget( mMonthly );
860 break; 860 break;
861 default: 861 default:
862 case Yearly: 862 case Yearly:
863 mRuleStack->raiseWidget( mYearly ); 863 mRuleStack->raiseWidget( mYearly );
864 break; 864 break;
865 } 865 }
866} 866}
867 867
868void KOEditorRecurrence::setDateTimes( QDateTime start, QDateTime end ) 868void KOEditorRecurrence::setDateTimes( QDateTime start, QDateTime end )
869{ 869{
870// kdDebug() << "KOEditorRecurrence::setDateTimes" << endl; 870// kdDebug() << "KOEditorRecurrence::setDateTimes" << endl;
@@ -874,59 +874,61 @@ void KOEditorRecurrence::setDateTimes( QDateTime start, QDateTime end )
874 874
875} 875}
876 876
877void KOEditorRecurrence::setDefaults( QDateTime from, QDateTime to, bool ) 877void KOEditorRecurrence::setDefaults( QDateTime from, QDateTime to, bool )
878{ 878{
879 879
880 // qDebug("KOEditorRecurrence::setDefaults %s %s ",from.toString().latin1(),to.toString().latin1() ); 880 // qDebug("KOEditorRecurrence::setDefaults %s %s ",from.toString().latin1(),to.toString().latin1() );
881 setDateTimes( from, to ); 881 setDateTimes( from, to );
882 882
883 bool enabled = false; 883 bool enabled = false;
884 mEnabledCheck->setChecked( enabled ); 884 mEnabledCheck->setChecked( enabled );
885 setEnabled( enabled ); 885 setEnabled( enabled );
886 886
887 mExceptions->setDefaults( to ); 887 mExceptions->setDefaults( to );
888 mRecurrenceRange->setDefaults( to ); 888 mRecurrenceRange->setDefaults( to );
889 889
890 mRecurrenceChooser->setType( RecurrenceChooser::Weekly ); 890 mRecurrenceChooser->setType( RecurrenceChooser::Weekly );
891 showCurrentRule( mRecurrenceChooser->type() ); 891 showCurrentRule( mRecurrenceChooser->type() );
892 892
893 mDaily->setFrequency( 1 ); 893 mDaily->setFrequency( 1 );
894 894
895 mWeekly->setFrequency( 1 ); 895 mWeekly->setFrequency( 1 );
896 QBitArray days( 7 ); 896 QBitArray days( 7 );
897 days.fill( 0 ); 897 days.fill( 0 );
898 days.setBit( from.date().dayOfWeek()- 1);
898 mWeekly->setDays( days ); 899 mWeekly->setDays( days );
899
900 mMonthly->setFrequency( 1 ); 900 mMonthly->setFrequency( 1 );
901 mMonthly->setByPos((from.date().day()/7), from.date().dayOfWeek()-1 );
901 mMonthly->setByDay( from.date().day()-1 ); 902 mMonthly->setByDay( from.date().day()-1 );
902
903 mYearly->setFrequency( 1 ); 903 mYearly->setFrequency( 1 );
904 mYearly->setByDay(); 904 mYearly->setByDay( from.date().dayOfYear() );
905 mYearly->setByMonth( from.date().month(), from.date().day() );
905} 906}
906 907
907void KOEditorRecurrence::readEvent(Event *event) 908void KOEditorRecurrence::readEvent(Event *event)
908{ 909{
910 setDefaults( event->dtStart(), event->dtEnd(), true );
909 QBitArray rDays( 7 ); 911 QBitArray rDays( 7 );
910 QPtrList<Recurrence::rMonthPos> rmp; 912 QPtrList<Recurrence::rMonthPos> rmp;
911 QPtrList<int> rmd; 913 QPtrList<int> rmd;
912 int day = 0; 914 int day = 0;
913 int count = 0; 915 int count = 0;
914 int month = 0; 916 int month = 0;
915 setDateTimes( event->dtStart(), event->dtEnd() ); 917 setDateTimes( event->dtStart(), event->dtEnd() );
916 918
917 Recurrence *r = event->recurrence(); 919 Recurrence *r = event->recurrence();
918 int f = r->frequency(); 920 int f = r->frequency();
919 921
920 int recurs = r->doesRecur(); 922 int recurs = r->doesRecur();
921 923
922 mEnabledCheck->setChecked( recurs ); 924 mEnabledCheck->setChecked( recurs );
923 setEnabled( recurs ); 925 setEnabled( recurs );
924 926
925 int recurrenceType = RecurrenceChooser::Weekly; 927 int recurrenceType = RecurrenceChooser::Weekly;
926 928
927 switch ( recurs ) { 929 switch ( recurs ) {
928 case Recurrence::rNone: 930 case Recurrence::rNone:
929 setDefaults( event->dtStart(), event->dtEnd(), true ); 931 setDefaults( event->dtStart(), event->dtEnd(), true );
930 break; 932 break;
931 case Recurrence::rDaily: 933 case Recurrence::rDaily:
932 recurrenceType = RecurrenceChooser::Daily; 934 recurrenceType = RecurrenceChooser::Daily;
@@ -945,61 +947,79 @@ void KOEditorRecurrence::readEvent(Event *event)
945 947
946 rmp = r->monthPositions(); 948 rmp = r->monthPositions();
947 if ( rmp.first()->negative ) 949 if ( rmp.first()->negative )
948 count = 5 - rmp.first()->rPos - 1; 950 count = 5 - rmp.first()->rPos - 1;
949 else 951 else
950 count = rmp.first()->rPos - 1; 952 count = rmp.first()->rPos - 1;
951 day = 0; 953 day = 0;
952 while ( !rmp.first()->rDays.testBit( day ) ) ++day; 954 while ( !rmp.first()->rDays.testBit( day ) ) ++day;
953 mMonthly->setByPos( count, day ); 955 mMonthly->setByPos( count, day );
954 956
955 mMonthly->setFrequency( f ); 957 mMonthly->setFrequency( f );
956 958
957 break; 959 break;
958 case Recurrence::rMonthlyDay: 960 case Recurrence::rMonthlyDay:
959 recurrenceType = RecurrenceChooser::Monthly; 961 recurrenceType = RecurrenceChooser::Monthly;
960 962
961 rmd = r->monthDays(); 963 rmd = r->monthDays();
962 day = *rmd.first() - 1; 964 day = *rmd.first() - 1;
963 mMonthly->setByDay( day ); 965 mMonthly->setByDay( day );
964 966
965 mMonthly->setFrequency( f ); 967 mMonthly->setFrequency( f );
966 968
967 break; 969 break;
968 case Recurrence::rYearlyMonth: 970 case Recurrence::rYearlyMonth:
969 case Recurrence::rYearlyDay: 971 {
970 recurrenceType = RecurrenceChooser::Yearly; 972 recurrenceType = RecurrenceChooser::Yearly;
971 973 qDebug("Recurrence::rYearlyMonth: ");
972 rmd = r->yearNums(); 974 day = event->dtStart().date().day();
973 month = *rmd.first(); 975 rmd = r->yearNums();
974 if ( month == event->dtStart().date().month() ) { 976 if ( rmd.count() > 0 )
975 mYearly->setByDay(); 977 month = *rmd.first();
976 } else { 978 else
977 mYearly->setByMonth( month ); 979 month = event->dtStart().date().month() ;
978 } 980 mYearly->setByMonth( month, day );
981#if 0
982 qDebug("2day = %d ",day );
983 QPtrList<Recurrence::rMonthPos> monthlist = r->yearMonthPositions();
984 int month;
985 if ( !monthlist.isEmpty() ) {
986 month = monthlist.first()->rPos ;
987 } else {
988 month = event->dtStart().date().month() ;
989 }
990 mYearly->setByMonth( day, month );
991#endif
992 mYearly->setFrequency( f );
993 }
979 994
980 mYearly->setFrequency( f );
981 break; 995 break;
996 case Recurrence::rYearlyDay:
997 qDebug("Recurrence::rYearlyDay: ");
998 recurrenceType = RecurrenceChooser::Yearly;
999 mYearly->setByDay( event->dtStart().date().dayOfYear() );
1000 mYearly->setFrequency( f );
1001 break;
982 default: 1002 default:
983 setDefaults( event->dtStart(), event->dtEnd(), true ); 1003 setDefaults( event->dtStart(), event->dtEnd(), true );
984 break; 1004 break;
985 } 1005 }
986 1006
987 mRecurrenceChooser->setType( recurrenceType ); 1007 mRecurrenceChooser->setType( recurrenceType );
988 showCurrentRule( recurrenceType ); 1008 showCurrentRule( recurrenceType );
989 1009
990 mRecurrenceRange->setDateTimes( event->dtStart() ); 1010 mRecurrenceRange->setDateTimes( event->dtStart() );
991 1011
992 if ( r->doesRecur() ) { 1012 if ( r->doesRecur() ) {
993 mRecurrenceRange->setDuration( r->duration() ); 1013 mRecurrenceRange->setDuration( r->duration() );
994 if ( r->duration() == 0 ) 1014 if ( r->duration() == 0 )
995 { 1015 {
996 if ( r->endDate() < event->dtStart().date() ) 1016 if ( r->endDate() < event->dtStart().date() )
997 mRecurrenceRange->setEndDate( event->dtStart().date() ); 1017 mRecurrenceRange->setEndDate( event->dtStart().date() );
998 else 1018 else
999 mRecurrenceRange->setEndDate( r->endDate() ); 1019 mRecurrenceRange->setEndDate( r->endDate() );
1000 } else 1020 } else
1001 mRecurrenceRange->setEndDate( event->dtStart().date() ); 1021 mRecurrenceRange->setEndDate( event->dtStart().date() );
1002 } 1022 }
1003 1023
1004 mExceptions->setDates( event->exDates() ); 1024 mExceptions->setDates( event->exDates() );
1005} 1025}
@@ -1041,63 +1061,66 @@ void KOEditorRecurrence::writeEvent( Event *event )
1041 if ( mMonthly->byPos() ) { 1061 if ( mMonthly->byPos() ) {
1042 int pos = mMonthly->count(); 1062 int pos = mMonthly->count();
1043 1063
1044 QBitArray days( 7 ); 1064 QBitArray days( 7 );
1045 days.fill( false ); 1065 days.fill( false );
1046 1066
1047 days.setBit( mMonthly->weekday() ); 1067 days.setBit( mMonthly->weekday() );
1048 if ( duration != 0 ) 1068 if ( duration != 0 )
1049 r->setMonthly( Recurrence::rMonthlyPos, freq, duration ); 1069 r->setMonthly( Recurrence::rMonthlyPos, freq, duration );
1050 else 1070 else
1051 r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); 1071 r->setMonthly( Recurrence::rMonthlyPos, freq, endDate );
1052 r->addMonthlyPos( pos, days ); 1072 r->addMonthlyPos( pos, days );
1053 } else { 1073 } else {
1054 // it's by day 1074 // it's by day
1055 int day = mMonthly->day(); 1075 int day = mMonthly->day();
1056 1076
1057 if ( duration != 0 ) { 1077 if ( duration != 0 ) {
1058 r->setMonthly( Recurrence::rMonthlyDay, freq, duration ); 1078 r->setMonthly( Recurrence::rMonthlyDay, freq, duration );
1059 } else { 1079 } else {
1060 r->setMonthly( Recurrence::rMonthlyDay, freq, endDate ); 1080 r->setMonthly( Recurrence::rMonthlyDay, freq, endDate );
1061 } 1081 }
1062 r->addMonthlyDay( day ); 1082 r->addMonthlyDay( day );
1063 } 1083 }
1064 } else if ( recurrenceType == RecurrenceChooser::Yearly ) { 1084 } else if ( recurrenceType == RecurrenceChooser::Yearly ) {
1085 qDebug("RecurrenceChooser::Yearly ");
1065 int freq = mYearly->frequency(); 1086 int freq = mYearly->frequency();
1066 1087 if ( mYearly->byDay() ) {
1067 int month; 1088 if ( duration != 0 ) {
1068 if ( mYearly->byMonth() ) { 1089 r->setYearly( Recurrence::rYearlyDay, freq, duration );
1069 month = mYearly->month(); 1090 } else {
1070 } else { 1091 r->setYearly( Recurrence::rYearlyDay, freq, endDate );
1071 month = event->dtStart().date().month(); 1092 }
1072 } 1093 r->addYearlyNum( event->dtStart().date().dayOfYear() );
1073 if ( duration != 0 ) {
1074 r->setYearly( Recurrence::rYearlyMonth, freq, duration );
1075 } else { 1094 } else {
1076 r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); 1095 if ( duration != 0 ) {
1096 r->setYearly( Recurrence::rYearlyMonth, freq, duration );
1097 } else {
1098 r->setYearly( Recurrence::rYearlyMonth, freq, endDate );
1099 }
1100 r->addYearlyNum( mYearly->month() );
1077 } 1101 }
1078 1102
1079 r->addYearlyNum( month );
1080 } 1103 }
1081 1104
1082 event->setExDates( mExceptions->dates() ); 1105 event->setExDates( mExceptions->dates() );
1083 } 1106 }
1084} 1107}
1085 1108
1086void KOEditorRecurrence::setDateTimeStr( const QString &str ) 1109void KOEditorRecurrence::setDateTimeStr( const QString &str )
1087{ 1110{
1088 mDateTimeLabel->setText( str ); 1111 mDateTimeLabel->setText( str );
1089} 1112}
1090 1113
1091bool KOEditorRecurrence::validateInput() 1114bool KOEditorRecurrence::validateInput()
1092{ 1115{
1093 // Check input here 1116 // Check input here
1094 1117
1095 return true; 1118 return true;
1096} 1119}
1097 1120
1098void KOEditorRecurrence::showExceptionsDialog() 1121void KOEditorRecurrence::showExceptionsDialog()
1099{ 1122{
1100 DateList dates = mExceptions->dates(); 1123 DateList dates = mExceptions->dates();
1101 int result = mExceptionsDialog->exec(); 1124 int result = mExceptionsDialog->exec();
1102 if ( result == QDialog::Rejected ) mExceptions->setDates( dates ); 1125 if ( result == QDialog::Rejected ) mExceptions->setDates( dates );
1103} 1126}
diff --git a/korganizer/koeditorrecurrence.h b/korganizer/koeditorrecurrence.h
index 4f0f0b2..2b59085 100644
--- a/korganizer/koeditorrecurrence.h
+++ b/korganizer/koeditorrecurrence.h
@@ -88,60 +88,63 @@ class RecurMonthly : public RecurBase
88 void setByPos( int count, int weekday ); 88 void setByPos( int count, int weekday );
89 89
90 bool byDay(); 90 bool byDay();
91 bool byPos(); 91 bool byPos();
92 92
93 int day(); 93 int day();
94 94
95 int count(); 95 int count();
96 int weekday(); 96 int weekday();
97 97
98 private: 98 private:
99 QRadioButton *mByDayRadio; 99 QRadioButton *mByDayRadio;
100 QComboBox *mByDayCombo; 100 QComboBox *mByDayCombo;
101 101
102 QRadioButton *mByPosRadio; 102 QRadioButton *mByPosRadio;
103 QComboBox *mByPosCountCombo; 103 QComboBox *mByPosCountCombo;
104 QComboBox *mByPosWeekdayCombo; 104 QComboBox *mByPosWeekdayCombo;
105}; 105};
106 106
107class RecurYearly : public RecurBase 107class RecurYearly : public RecurBase
108{ 108{
109 public: 109 public:
110 RecurYearly( QWidget *parent = 0, const char *name = 0 ); 110 RecurYearly( QWidget *parent = 0, const char *name = 0 );
111 111
112 void setByDay(); 112 void setByDay( int doy );
113 void setByMonth( int month ); 113 void setByMonth( int month, int day );
114 114
115 bool byMonth(); 115 bool byMonth();
116 bool byDay(); 116 bool byDay();
117 117
118 int month(); 118 int month();
119 int day();
119 120
120 private: 121 private:
122 int mDay;
121 QRadioButton *mByMonthRadio; 123 QRadioButton *mByMonthRadio;
122 QComboBox *mByMonthCombo; 124 QComboBox *mByMonthCombo;
123 125 QLabel* mByDayLabel;
126 QLabel* mDayOfLabel;
124 QRadioButton *mByDayRadio; 127 QRadioButton *mByDayRadio;
125}; 128};
126 129
127class RecurrenceChooser : public QWidget 130class RecurrenceChooser : public QWidget
128{ 131{
129 Q_OBJECT 132 Q_OBJECT
130 public: 133 public:
131 RecurrenceChooser( QWidget *parent = 0, const char *name = 0 ); 134 RecurrenceChooser( QWidget *parent = 0, const char *name = 0 );
132 135
133 enum { Daily, Weekly, Monthly, Yearly }; 136 enum { Daily, Weekly, Monthly, Yearly };
134 137
135 void setType( int ); 138 void setType( int );
136 int type(); 139 int type();
137 140
138 signals: 141 signals:
139 void chosen( int ); 142 void chosen( int );
140 143
141 protected slots: 144 protected slots:
142 void emitChoice(); 145 void emitChoice();
143 146
144 private: 147 private:
145 QComboBox *mTypeCombo; 148 QComboBox *mTypeCombo;
146 149
147 QRadioButton *mDailyButton; 150 QRadioButton *mDailyButton;
diff --git a/libkcal/icalformatimpl.cpp b/libkcal/icalformatimpl.cpp
index 32a1337..964ffe3 100644
--- a/libkcal/icalformatimpl.cpp
+++ b/libkcal/icalformatimpl.cpp
@@ -1371,49 +1371,49 @@ void ICalFormatImpl::readRecurrenceRule(struct icalrecurrencetype rrule,Incidenc
1371 struct icalrecurrencetype r = rrule; 1371 struct icalrecurrencetype r = rrule;
1372 1372
1373 dumpIcalRecurrence(r); 1373 dumpIcalRecurrence(r);
1374 readRecurrence( r, recur, incidence); 1374 readRecurrence( r, recur, incidence);
1375} 1375}
1376 1376
1377void ICalFormatImpl::readRecurrence( const struct icalrecurrencetype &r, Recurrence* recur, Incidence *incidence) 1377void ICalFormatImpl::readRecurrence( const struct icalrecurrencetype &r, Recurrence* recur, Incidence *incidence)
1378{ 1378{
1379 int wkst; 1379 int wkst;
1380 int index = 0; 1380 int index = 0;
1381 short day = 0; 1381 short day = 0;
1382 QBitArray qba(7); 1382 QBitArray qba(7);
1383 int frequ = r.freq; 1383 int frequ = r.freq;
1384 int interv = r.interval; 1384 int interv = r.interval;
1385 // preprocessing for odd recurrence definitions 1385 // preprocessing for odd recurrence definitions
1386 1386
1387 if ( r.freq == ICAL_MONTHLY_RECURRENCE ) { 1387 if ( r.freq == ICAL_MONTHLY_RECURRENCE ) {
1388 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1388 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1389 interv = 12; 1389 interv = 12;
1390 } 1390 }
1391 } 1391 }
1392 if ( r.freq == ICAL_YEARLY_RECURRENCE ) { 1392 if ( r.freq == ICAL_YEARLY_RECURRENCE ) {
1393 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX && r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX ) { 1393 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX && r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX ) {
1394 frequ = ICAL_MONTHLY_RECURRENCE; 1394 frequ = ICAL_MONTHLY_RECURRENCE;
1395 interv = 12; 1395 interv = 12* r.interval;
1396 } 1396 }
1397 } 1397 }
1398 1398
1399 switch (frequ) { 1399 switch (frequ) {
1400 case ICAL_MINUTELY_RECURRENCE: 1400 case ICAL_MINUTELY_RECURRENCE:
1401 if (!icaltime_is_null_time(r.until)) { 1401 if (!icaltime_is_null_time(r.until)) {
1402 recur->setMinutely(interv,readICalDateTime(r.until)); 1402 recur->setMinutely(interv,readICalDateTime(r.until));
1403 } else { 1403 } else {
1404 if (r.count == 0) 1404 if (r.count == 0)
1405 recur->setMinutely(interv,-1); 1405 recur->setMinutely(interv,-1);
1406 else 1406 else
1407 recur->setMinutely(interv,r.count); 1407 recur->setMinutely(interv,r.count);
1408 } 1408 }
1409 break; 1409 break;
1410 case ICAL_HOURLY_RECURRENCE: 1410 case ICAL_HOURLY_RECURRENCE:
1411 if (!icaltime_is_null_time(r.until)) { 1411 if (!icaltime_is_null_time(r.until)) {
1412 recur->setHourly(interv,readICalDateTime(r.until)); 1412 recur->setHourly(interv,readICalDateTime(r.until));
1413 } else { 1413 } else {
1414 if (r.count == 0) 1414 if (r.count == 0)
1415 recur->setHourly(interv,-1); 1415 recur->setHourly(interv,-1);
1416 else 1416 else
1417 recur->setHourly(interv,r.count); 1417 recur->setHourly(interv,r.count);
1418 } 1418 }
1419 break; 1419 break;
@@ -1478,110 +1478,114 @@ void ICalFormatImpl::readRecurrence( const struct icalrecurrencetype &r, Recurre
1478 } 1478 }
1479 if (useSetPos) { 1479 if (useSetPos) {
1480 if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1480 if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1481 recur->addMonthlyPos(r.by_set_pos[0],qba); 1481 recur->addMonthlyPos(r.by_set_pos[0],qba);
1482 } 1482 }
1483 } 1483 }
1484 } else if (r.by_month_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1484 } else if (r.by_month_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1485 if (!icaltime_is_null_time(r.until)) { 1485 if (!icaltime_is_null_time(r.until)) {
1486 recur->setMonthly(Recurrence::rMonthlyDay,interv, 1486 recur->setMonthly(Recurrence::rMonthlyDay,interv,
1487 readICalDate(r.until)); 1487 readICalDate(r.until));
1488 } else { 1488 } else {
1489 if (r.count == 0) 1489 if (r.count == 0)
1490 recur->setMonthly(Recurrence::rMonthlyDay,interv,-1); 1490 recur->setMonthly(Recurrence::rMonthlyDay,interv,-1);
1491 else 1491 else
1492 recur->setMonthly(Recurrence::rMonthlyDay,interv,r.count); 1492 recur->setMonthly(Recurrence::rMonthlyDay,interv,r.count);
1493 } 1493 }
1494 while((day = r.by_month_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 1494 while((day = r.by_month_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
1495 // kdDebug(5800) << "----b " << day << endl; 1495 // kdDebug(5800) << "----b " << day << endl;
1496 recur->addMonthlyDay(day); 1496 recur->addMonthlyDay(day);
1497 } 1497 }
1498 } 1498 }
1499 break; 1499 break;
1500 case ICAL_YEARLY_RECURRENCE: 1500 case ICAL_YEARLY_RECURRENCE:
1501 if (r.by_year_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1501 if (r.by_year_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1502 qDebug(" YEARLY DAY OF YEAR");
1502 if (!icaltime_is_null_time(r.until)) { 1503 if (!icaltime_is_null_time(r.until)) {
1503 recur->setYearly(Recurrence::rYearlyDay,interv, 1504 recur->setYearly(Recurrence::rYearlyDay,interv,
1504 readICalDate(r.until)); 1505 readICalDate(r.until));
1505 } else { 1506 } else {
1506 if (r.count == 0) 1507 if (r.count == 0)
1507 recur->setYearly(Recurrence::rYearlyDay,interv,-1); 1508 recur->setYearly(Recurrence::rYearlyDay,interv,-1);
1508 else 1509 else
1509 recur->setYearly(Recurrence::rYearlyDay,interv,r.count); 1510 recur->setYearly(Recurrence::rYearlyDay,interv,r.count);
1510 } 1511 }
1511 while((day = r.by_year_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 1512 while((day = r.by_year_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
1512 recur->addYearlyNum(day); 1513 recur->addYearlyNum(day);
1513 } 1514 }
1514 } else if ( true /*r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX*/) { 1515 } else if ( true /*r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX*/) {
1515 if (r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1516 if (r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1517 qDebug("YEARLY POS NOT SUPPORTED BY GUI");
1516 if (!icaltime_is_null_time(r.until)) { 1518 if (!icaltime_is_null_time(r.until)) {
1517 recur->setYearly(Recurrence::rYearlyPos,interv, 1519 recur->setYearly(Recurrence::rYearlyPos,interv,
1518 readICalDate(r.until)); 1520 readICalDate(r.until));
1519 } else { 1521 } else {
1520 if (r.count == 0) 1522 if (r.count == 0)
1521 recur->setYearly(Recurrence::rYearlyPos,interv,-1); 1523 recur->setYearly(Recurrence::rYearlyPos,interv,-1);
1522 else 1524 else
1523 recur->setYearly(Recurrence::rYearlyPos,interv,r.count); 1525 recur->setYearly(Recurrence::rYearlyPos,interv,r.count);
1524 } 1526 }
1525 bool useSetPos = false; 1527 bool useSetPos = false;
1526 short pos = 0; 1528 short pos = 0;
1527 while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 1529 while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
1528 // kdDebug(5800) << "----a " << index << ": " << day << endl; 1530 // kdDebug(5800) << "----a " << index << ": " << day << endl;
1529 pos = icalrecurrencetype_day_position(day); 1531 pos = icalrecurrencetype_day_position(day);
1530 if (pos) { 1532 if (pos) {
1531 day = icalrecurrencetype_day_day_of_week(day); 1533 day = icalrecurrencetype_day_day_of_week(day);
1532 QBitArray ba(7); // don't wipe qba 1534 QBitArray ba(7); // don't wipe qba
1533 ba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 1535 ba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0
1534 recur->addYearlyMonthPos(pos,ba); 1536 recur->addYearlyMonthPos(pos,ba);
1535 } else { 1537 } else {
1536 qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 1538 qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0
1537 useSetPos = true; 1539 useSetPos = true;
1538 } 1540 }
1539 } 1541 }
1540 if (useSetPos) { 1542 if (useSetPos) {
1541 if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1543 if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1542 recur->addYearlyMonthPos(r.by_set_pos[0],qba); 1544 recur->addYearlyMonthPos(r.by_set_pos[0],qba);
1543 } 1545 }
1544 } 1546 }
1545 } else { 1547 } else {
1548 qDebug("YEARLY MONTH ");
1546 if (!icaltime_is_null_time(r.until)) { 1549 if (!icaltime_is_null_time(r.until)) {
1547 recur->setYearly(Recurrence::rYearlyMonth,interv, 1550 recur->setYearly(Recurrence::rYearlyMonth,interv,
1548 readICalDate(r.until)); 1551 readICalDate(r.until));
1549 } else { 1552 } else {
1550 if (r.count == 0) 1553 if (r.count == 0)
1551 recur->setYearly(Recurrence::rYearlyMonth,interv,-1); 1554 recur->setYearly(Recurrence::rYearlyMonth,interv,-1);
1552 else 1555 else
1553 recur->setYearly(Recurrence::rYearlyMonth,interv,r.count); 1556 recur->setYearly(Recurrence::rYearlyMonth,interv,r.count);
1554 } 1557 }
1555 } 1558 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX ) {
1556 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX ) { 1559 index = 0;
1557 index = 0; 1560 while((day = r.by_month[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
1558 while((day = r.by_month[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 1561 recur->addYearlyNum(day);
1559 recur->addYearlyNum(day); 1562 }
1563 } else {
1564 recur->addYearlyNum(incidence->dtStart().date().month());
1560 } 1565 }
1561 } else {
1562 recur->addYearlyNum(incidence->dtStart().date().month());
1563 } 1566 }
1567
1564 } 1568 }
1565 break; 1569 break;
1566 default: 1570 default:
1567 ; 1571 ;
1568 break; 1572 break;
1569 } 1573 }
1570} 1574}
1571 1575
1572void ICalFormatImpl::readAlarm(icalcomponent *alarm,Incidence *incidence) 1576void ICalFormatImpl::readAlarm(icalcomponent *alarm,Incidence *incidence)
1573{ 1577{
1574 //kdDebug(5800) << "Read alarm for " << incidence->summary() << endl; 1578 //kdDebug(5800) << "Read alarm for " << incidence->summary() << endl;
1575 1579
1576 Alarm* ialarm = incidence->newAlarm(); 1580 Alarm* ialarm = incidence->newAlarm();
1577 ialarm->setRepeatCount(0); 1581 ialarm->setRepeatCount(0);
1578 ialarm->setEnabled(true); 1582 ialarm->setEnabled(true);
1579 1583
1580 // Determine the alarm's action type 1584 // Determine the alarm's action type
1581 icalproperty *p = icalcomponent_get_first_property(alarm,ICAL_ACTION_PROPERTY); 1585 icalproperty *p = icalcomponent_get_first_property(alarm,ICAL_ACTION_PROPERTY);
1582 if ( !p ) { 1586 if ( !p ) {
1583 return; 1587 return;
1584 } 1588 }
1585 1589
1586 icalproperty_action action = icalproperty_get_action(p); 1590 icalproperty_action action = icalproperty_get_action(p);
1587 Alarm::Type type = Alarm::Display; 1591 Alarm::Type type = Alarm::Display;
diff --git a/libkcal/recurrence.cpp b/libkcal/recurrence.cpp
index 5fc5d1f..dd74e10 100644
--- a/libkcal/recurrence.cpp
+++ b/libkcal/recurrence.cpp
@@ -633,49 +633,49 @@ void Recurrence::addMonthlyPos_(short _rPos, const QBitArray &_rDays)
633 } else { 633 } else {
634 tmpPos->rPos = -_rPos; // take abs() 634 tmpPos->rPos = -_rPos; // take abs()
635 tmpPos->negative = true; 635 tmpPos->negative = true;
636 } 636 }
637 tmpPos->rDays = _rDays; 637 tmpPos->rDays = _rDays;
638 tmpPos->rDays.detach(); 638 tmpPos->rDays.detach();
639 rMonthPositions.append(tmpPos); 639 rMonthPositions.append(tmpPos);
640 640
641 if (mCompatVersion < 310 && mCompatDuration > 0) { 641 if (mCompatVersion < 310 && mCompatDuration > 0) {
642 // Backwards compatibility for KDE < 3.1. 642 // Backwards compatibility for KDE < 3.1.
643 // rDuration was set to the number of time periods to recur. 643 // rDuration was set to the number of time periods to recur.
644 // Convert this to the number of occurrences. 644 // Convert this to the number of occurrences.
645 int monthsAhead = (mCompatDuration-1+mRecurExDatesCount) * rFreq; 645 int monthsAhead = (mCompatDuration-1+mRecurExDatesCount) * rFreq;
646 int month = mRecurStart.date().month() - 1 + monthsAhead; 646 int month = mRecurStart.date().month() - 1 + monthsAhead;
647 QDate end(mRecurStart.date().year() + month/12, month%12 + 1, 31); 647 QDate end(mRecurStart.date().year() + month/12, month%12 + 1, 31);
648 rDuration = INT_MAX; // ensure that recurCalc() does its job correctly 648 rDuration = INT_MAX; // ensure that recurCalc() does its job correctly
649 rDuration = recurCalc(COUNT_TO_DATE, end); 649 rDuration = recurCalc(COUNT_TO_DATE, end);
650 } 650 }
651 651
652 if (mParent) mParent->updated(); 652 if (mParent) mParent->updated();
653} 653}
654 654
655void Recurrence::addMonthlyDay(short _rDay) 655void Recurrence::addMonthlyDay(short _rDay)
656{ 656{
657 if (mRecurReadOnly || recurs != rMonthlyDay 657 if (mRecurReadOnly || (recurs != rMonthlyDay && recurs != rYearlyMonth)
658 || _rDay == 0 || _rDay > 31 || _rDay < -31) // invalid day number 658 || _rDay == 0 || _rDay > 31 || _rDay < -31) // invalid day number
659 return; 659 return;
660 for (int* it = rMonthDays.first(); it; it = rMonthDays.next()) { 660 for (int* it = rMonthDays.first(); it; it = rMonthDays.next()) {
661 if (_rDay == *it) 661 if (_rDay == *it)
662 return; // this day is already in the list - avoid duplication 662 return; // this day is already in the list - avoid duplication
663 } 663 }
664 int *tmpDay = new int; 664 int *tmpDay = new int;
665 *tmpDay = _rDay; 665 *tmpDay = _rDay;
666 rMonthDays.append(tmpDay); 666 rMonthDays.append(tmpDay);
667 667
668 if (mCompatVersion < 310 && mCompatDuration > 0) { 668 if (mCompatVersion < 310 && mCompatDuration > 0) {
669 // Backwards compatibility for KDE < 3.1. 669 // Backwards compatibility for KDE < 3.1.
670 // rDuration was set to the number of time periods to recur. 670 // rDuration was set to the number of time periods to recur.
671 // Convert this to the number of occurrences. 671 // Convert this to the number of occurrences.
672 int monthsAhead = (mCompatDuration-1+mRecurExDatesCount) * rFreq; 672 int monthsAhead = (mCompatDuration-1+mRecurExDatesCount) * rFreq;
673 int month = mRecurStart.date().month() - 1 + monthsAhead; 673 int month = mRecurStart.date().month() - 1 + monthsAhead;
674 QDate end(mRecurStart.date().year() + month/12, month%12 + 1, 31); 674 QDate end(mRecurStart.date().year() + month/12, month%12 + 1, 31);
675 rDuration = INT_MAX; // ensure that recurCalc() does its job correctly 675 rDuration = INT_MAX; // ensure that recurCalc() does its job correctly
676 rDuration = recurCalc(COUNT_TO_DATE, end); 676 rDuration = recurCalc(COUNT_TO_DATE, end);
677 } 677 }
678 678
679 if (mParent) mParent->updated(); 679 if (mParent) mParent->updated();
680} 680}
681 681
@@ -704,49 +704,62 @@ void Recurrence::setYearlyByDate(Feb29Type type, int _rFreq, int _rDuration)
704 if (mCompatVersion < 310) 704 if (mCompatVersion < 310)
705 mCompatDuration = (_rDuration > 0) ? _rDuration : 0; 705 mCompatDuration = (_rDuration > 0) ? _rDuration : 0;
706 setYearly_(rYearlyMonth, type, _rFreq, _rDuration); 706 setYearly_(rYearlyMonth, type, _rFreq, _rDuration);
707} 707}
708 708
709void Recurrence::setYearlyByDate(Feb29Type type, int _rFreq, const QDate &_rEndDate) 709void Recurrence::setYearlyByDate(Feb29Type type, int _rFreq, const QDate &_rEndDate)
710{ 710{
711 if (mRecurReadOnly) return; 711 if (mRecurReadOnly) return;
712 rEndDateTime.setDate(_rEndDate); 712 rEndDateTime.setDate(_rEndDate);
713 rEndDateTime.setTime(mRecurStart.time()); 713 rEndDateTime.setTime(mRecurStart.time());
714 mCompatDuration = 0; 714 mCompatDuration = 0;
715 setYearly_(rYearlyMonth, type, _rFreq, 0); 715 setYearly_(rYearlyMonth, type, _rFreq, 0);
716} 716}
717 717
718void Recurrence::addYearlyMonthPos(short _rPos, const QBitArray &_rDays) 718void Recurrence::addYearlyMonthPos(short _rPos, const QBitArray &_rDays)
719{ 719{
720 if (recurs == rYearlyPos) 720 if (recurs == rYearlyPos)
721 addMonthlyPos_(_rPos, _rDays); 721 addMonthlyPos_(_rPos, _rDays);
722} 722}
723 723
724const QPtrList<int> &Recurrence::yearNums() const 724const QPtrList<int> &Recurrence::yearNums() const
725{ 725{
726 return rYearNums; 726 return rYearNums;
727} 727}
728 728void Recurrence::addYearlyMonth(short _rPos )
729{
730 if (mRecurReadOnly || recurs != rYearlyMonth) // invalid day/month number
731 return;
732 rMonthPos *tmpPos = new rMonthPos;
733 if ( _rPos > 0) {
734 tmpPos->rPos = _rPos;
735 tmpPos->negative = false;
736 } else {
737 tmpPos->rPos = -_rPos; // take abs()
738 tmpPos->negative = true;
739 }
740 rMonthPositions.append(tmpPos);
741}
729void Recurrence::addYearlyNum(short _rNum) 742void Recurrence::addYearlyNum(short _rNum)
730{ 743{
731 if (mRecurReadOnly 744 if (mRecurReadOnly
732 || (recurs != rYearlyMonth && recurs != rYearlyDay && recurs != rYearlyPos) 745 || (recurs != rYearlyMonth && recurs != rYearlyDay && recurs != rYearlyPos)
733 || _rNum <= 0) // invalid day/month number 746 || _rNum <= 0) // invalid day/month number
734 return; 747 return;
735 748
736 if (mCompatVersion < 310 && mCompatRecurs == rYearlyDay) { 749 if (mCompatVersion < 310 && mCompatRecurs == rYearlyDay) {
737 // Backwards compatibility for KDE < 3.1. 750 // Backwards compatibility for KDE < 3.1.
738 // Dates were stored as day numbers, with a fiddle to take account of leap years. 751 // Dates were stored as day numbers, with a fiddle to take account of leap years.
739 // Convert the day number to a month. 752 // Convert the day number to a month.
740 if (_rNum <= 0 || _rNum > 366 || (_rNum == 366 && mRecurStart.date().daysInYear() < 366)) 753 if (_rNum <= 0 || _rNum > 366 || (_rNum == 366 && mRecurStart.date().daysInYear() < 366))
741 return; // invalid day number 754 return; // invalid day number
742 _rNum = QDate(mRecurStart.date().year(), 1, 1).addDays(_rNum - 1).month(); 755 _rNum = QDate(mRecurStart.date().year(), 1, 1).addDays(_rNum - 1).month();
743 } else 756 } else
744 if ((recurs == rYearlyMonth || recurs == rYearlyPos) && _rNum > 12 757 if ((recurs == rYearlyMonth || recurs == rYearlyPos) && _rNum > 12
745 || recurs == rYearlyDay && _rNum > 366) 758 || recurs == rYearlyDay && _rNum > 366)
746 return; // invalid day number 759 return; // invalid day number
747 760
748 uint i = 0; 761 uint i = 0;
749 for (int* it = rYearNums.first(); it && _rNum >= *it; it = rYearNums.next()) { 762 for (int* it = rYearNums.first(); it && _rNum >= *it; it = rYearNums.next()) {
750 if (_rNum == *it) 763 if (_rNum == *it)
751 return; // this day/month is already in the list - avoid duplication 764 return; // this day/month is already in the list - avoid duplication
752 ++i; 765 ++i;
diff --git a/libkcal/recurrence.h b/libkcal/recurrence.h
index a0f6d84..b13d14f 100644
--- a/libkcal/recurrence.h
+++ b/libkcal/recurrence.h
@@ -267,54 +267,56 @@ class Recurrence
267 * @var duration the number of times the event is to occur, or -1 to recur indefinitely. 267 * @var duration the number of times the event is to occur, or -1 to recur indefinitely.
268 */ 268 */
269 void setYearlyByDate(Feb29Type type, int freq, int duration); 269 void setYearlyByDate(Feb29Type type, int freq, int duration);
270 /** Sets an event to recur yearly ending at \a endDate. */ 270 /** Sets an event to recur yearly ending at \a endDate. */
271 void setYearlyByDate(Feb29Type type, int freq, const QDate &endDate); 271 void setYearlyByDate(Feb29Type type, int freq, const QDate &endDate);
272 /** Adds position of day or month in year. 272 /** Adds position of day or month in year.
273 * N.B. for recursYearlyPos, addYearlyMonthPos() must also be called 273 * N.B. for recursYearlyPos, addYearlyMonthPos() must also be called
274 * to add positions within the month. */ 274 * to add positions within the month. */
275 void addYearlyNum(short _rNum); 275 void addYearlyNum(short _rNum);
276 /** Adds a position to the recursYearlyPos recurrence rule, if it is set. 276 /** Adds a position to the recursYearlyPos recurrence rule, if it is set.
277 * N.B. addYearlyNum() must also be called to add recurrence months. 277 * N.B. addYearlyNum() must also be called to add recurrence months.
278 * Parameters are the same as for addMonthlyPos(). 278 * Parameters are the same as for addMonthlyPos().
279 */ 279 */
280 void addYearlyMonthPos(short _rPos, const QBitArray &_rDays); 280 void addYearlyMonthPos(short _rPos, const QBitArray &_rDays);
281 /** Returns positions of days or months in year. */ 281 /** Returns positions of days or months in year. */
282 const QPtrList<int> &yearNums() const; 282 const QPtrList<int> &yearNums() const;
283 /** Returns list of day positions in months, for a recursYearlyPos recurrence rule. */ 283 /** Returns list of day positions in months, for a recursYearlyPos recurrence rule. */
284 const QPtrList<rMonthPos> &yearMonthPositions() const; 284 const QPtrList<rMonthPos> &yearMonthPositions() const;
285 /** Returns how yearly recurrences of February 29th are handled. */ 285 /** Returns how yearly recurrences of February 29th are handled. */
286 Feb29Type feb29YearlyType() const { return mFeb29YearlyType; } 286 Feb29Type feb29YearlyType() const { return mFeb29YearlyType; }
287 /** Sets the default method for handling yearly recurrences of February 29th. */ 287 /** Sets the default method for handling yearly recurrences of February 29th. */
288 static void setFeb29YearlyTypeDefault(Feb29Type t) { mFeb29YearlyDefaultType = t; } 288 static void setFeb29YearlyTypeDefault(Feb29Type t) { mFeb29YearlyDefaultType = t; }
289 /** Returns the default method for handling yearly recurrences of February 29th. */ 289 /** Returns the default method for handling yearly recurrences of February 29th. */
290 static Feb29Type setFeb29YearlyTypeDefault() { return mFeb29YearlyDefaultType; } 290 static Feb29Type setFeb29YearlyTypeDefault() { return mFeb29YearlyDefaultType; }
291 291 void addYearlyMonth(short _rPos ); // added LR
292 /** 292 /**
293 Debug output. 293 Debug output.
294 */ 294 */
295 void dump() const; 295 void dump() const;
296 QString recurrenceText() const; 296 QString recurrenceText() const;
297 bool getYearlyMonthMonths(int day, QValueList<int>&,
298 QValueList<int> &leaplist) const;
297 299
298 protected: 300 protected:
299 enum PeriodFunc { END_DATE_AND_COUNT, COUNT_TO_DATE, NEXT_AFTER_DATE }; 301 enum PeriodFunc { END_DATE_AND_COUNT, COUNT_TO_DATE, NEXT_AFTER_DATE };
300 struct MonthlyData; friend struct MonthlyData; 302 struct MonthlyData; friend struct MonthlyData;
301 struct YearlyMonthData; friend struct YearlyMonthData; 303 struct YearlyMonthData; friend struct YearlyMonthData;
302 struct YearlyPosData; friend struct YearlyPosData; 304 struct YearlyPosData; friend struct YearlyPosData;
303 struct YearlyDayData; friend struct YearlyDayData; 305 struct YearlyDayData; friend struct YearlyDayData;
304 306
305 bool recursSecondly(const QDate &, int secondFreq) const; 307 bool recursSecondly(const QDate &, int secondFreq) const;
306 bool recursMinutelyAt(const QDateTime &dt, int minuteFreq) const; 308 bool recursMinutelyAt(const QDateTime &dt, int minuteFreq) const;
307 bool recursDaily(const QDate &) const; 309 bool recursDaily(const QDate &) const;
308 bool recursWeekly(const QDate &) const; 310 bool recursWeekly(const QDate &) const;
309 bool recursMonthly(const QDate &) const; 311 bool recursMonthly(const QDate &) const;
310 bool recursYearlyByMonth(const QDate &) const; 312 bool recursYearlyByMonth(const QDate &) const;
311 bool recursYearlyByPos(const QDate &) const; 313 bool recursYearlyByPos(const QDate &) const;
312 bool recursYearlyByDay(const QDate &) const; 314 bool recursYearlyByDay(const QDate &) const;
313 315
314 QDate getNextDateNoTime(const QDate& preDate, bool* last) const; 316 QDate getNextDateNoTime(const QDate& preDate, bool* last) const;
315 QDate getPreviousDateNoTime(const QDate& afterDate, bool* last) const; 317 QDate getPreviousDateNoTime(const QDate& afterDate, bool* last) const;
316 318
317 void addMonthlyPos_(short _rPos, const QBitArray &_rDays); 319 void addMonthlyPos_(short _rPos, const QBitArray &_rDays);
318 void setDailySub(short type, int freq, int duration); 320 void setDailySub(short type, int freq, int duration);
319 void setYearly_(short type, Feb29Type, int freq, int duration); 321 void setYearly_(short type, Feb29Type, int freq, int duration);
320 int recurCalc(PeriodFunc, QDate &enddate) const; 322 int recurCalc(PeriodFunc, QDate &enddate) const;
@@ -325,50 +327,48 @@ class Recurrence
325 int weeklyCalcEndDate(QDate& enddate, int daysPerWeek) const; 327 int weeklyCalcEndDate(QDate& enddate, int daysPerWeek) const;
326 int weeklyCalcToDate(const QDate& enddate, int daysPerWeek) const; 328 int weeklyCalcToDate(const QDate& enddate, int daysPerWeek) const;
327 int weeklyCalcNextAfter(QDate& enddate, int daysPerWeek) const; 329 int weeklyCalcNextAfter(QDate& enddate, int daysPerWeek) const;
328 int monthlyCalc(PeriodFunc, QDate &enddate) const; 330 int monthlyCalc(PeriodFunc, QDate &enddate) const;
329 int monthlyCalcEndDate(QDate& enddate, MonthlyData&) const; 331 int monthlyCalcEndDate(QDate& enddate, MonthlyData&) const;
330 int monthlyCalcToDate(const QDate& enddate, MonthlyData&) const; 332 int monthlyCalcToDate(const QDate& enddate, MonthlyData&) const;
331 int monthlyCalcNextAfter(QDate& enddate, MonthlyData&) const; 333 int monthlyCalcNextAfter(QDate& enddate, MonthlyData&) const;
332 int yearlyMonthCalc(PeriodFunc, QDate &enddate) const; 334 int yearlyMonthCalc(PeriodFunc, QDate &enddate) const;
333 int yearlyMonthCalcEndDate(QDate& enddate, YearlyMonthData&) const; 335 int yearlyMonthCalcEndDate(QDate& enddate, YearlyMonthData&) const;
334 int yearlyMonthCalcToDate(const QDate& enddate, YearlyMonthData&) const; 336 int yearlyMonthCalcToDate(const QDate& enddate, YearlyMonthData&) const;
335 int yearlyMonthCalcNextAfter(QDate& enddate, YearlyMonthData&) const; 337 int yearlyMonthCalcNextAfter(QDate& enddate, YearlyMonthData&) const;
336 int yearlyPosCalc(PeriodFunc, QDate &enddate) const; 338 int yearlyPosCalc(PeriodFunc, QDate &enddate) const;
337 int yearlyPosCalcEndDate(QDate& enddate, YearlyPosData&) const; 339 int yearlyPosCalcEndDate(QDate& enddate, YearlyPosData&) const;
338 int yearlyPosCalcToDate(const QDate& enddate, YearlyPosData&) const; 340 int yearlyPosCalcToDate(const QDate& enddate, YearlyPosData&) const;
339 int yearlyPosCalcNextAfter(QDate& enddate, YearlyPosData&) const; 341 int yearlyPosCalcNextAfter(QDate& enddate, YearlyPosData&) const;
340 int yearlyDayCalc(PeriodFunc, QDate &enddate) const; 342 int yearlyDayCalc(PeriodFunc, QDate &enddate) const;
341 int yearlyDayCalcEndDate(QDate& enddate, YearlyDayData&) const; 343 int yearlyDayCalcEndDate(QDate& enddate, YearlyDayData&) const;
342 int yearlyDayCalcToDate(const QDate& enddate, YearlyDayData&) const; 344 int yearlyDayCalcToDate(const QDate& enddate, YearlyDayData&) const;
343 int yearlyDayCalcNextAfter(QDate& enddate, YearlyDayData&) const; 345 int yearlyDayCalcNextAfter(QDate& enddate, YearlyDayData&) const;
344 346
345 int countMonthlyPosDays() const; 347 int countMonthlyPosDays() const;
346 void getMonthlyPosDays(QValueList<int>&, int daysInMonth, 348 void getMonthlyPosDays(QValueList<int>&, int daysInMonth,
347 int startDayOfWeek) const; 349 int startDayOfWeek) const;
348 bool getMonthlyDayDays(QValueList<int>&, int daysInMonth) const; 350 bool getMonthlyDayDays(QValueList<int>&, int daysInMonth) const;
349 bool getYearlyMonthMonths(int day, QValueList<int>&,
350 QValueList<int> &leaplist) const;
351 351
352 int getFirstDayInWeek(int startDay, bool useWeekStart = true) const; 352 int getFirstDayInWeek(int startDay, bool useWeekStart = true) const;
353 int getLastDayInWeek(int endDay, bool useWeekStart = true) const; 353 int getLastDayInWeek(int endDay, bool useWeekStart = true) const;
354 QDate getFirstDateInMonth(const QDate& earliestDate) const; 354 QDate getFirstDateInMonth(const QDate& earliestDate) const;
355 QDate getLastDateInMonth(const QDate& latestDate) const; 355 QDate getLastDateInMonth(const QDate& latestDate) const;
356 QDate getFirstDateInYear(const QDate& earliestDate) const; 356 QDate getFirstDateInYear(const QDate& earliestDate) const;
357 QDate getLastDateInYear(const QDate& latestDate) const; 357 QDate getLastDateInYear(const QDate& latestDate) const;
358 358
359 private: 359 private:
360 // Prohibit copying 360 // Prohibit copying
361 Recurrence(const Recurrence&); 361 Recurrence(const Recurrence&);
362 Recurrence &operator=(const Recurrence&); 362 Recurrence &operator=(const Recurrence&);
363 363
364 short recurs; // should be one of the enums. 364 short recurs; // should be one of the enums.
365 365
366 int rWeekStart; // day which starts the week, Monday=1 .. Sunday=7 366 int rWeekStart; // day which starts the week, Monday=1 .. Sunday=7
367 QBitArray rDays; // array of days during week it recurs 367 QBitArray rDays; // array of days during week it recurs
368 368
369 QPtrList<rMonthPos> rMonthPositions; // list of positions during a month 369 QPtrList<rMonthPos> rMonthPositions; // list of positions during a month
370 // on which an event recurs 370 // on which an event recurs
371 371
372 QPtrList<int> rMonthDays; // list of days during a month on 372 QPtrList<int> rMonthDays; // list of days during a month on
373 // which the event recurs 373 // which the event recurs
374 374