Diffstat (limited to 'korganizer/koeditorrecurrence.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | korganizer/koeditorrecurrence.cpp | 172 |
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 @@ -884,148 +884,154 @@ void KOEditorRecurrence::readEvent(Incidence *event) QDateTime dtEnd; if ( event->typeID() == eventID ) dtEnd = ((Event*)event)->dtEnd(); else dtEnd = ((Todo*)event)->dtDue(); setDefaults( event->dtStart(), dtEnd ); QBitArray rDays( 7 ); QPtrList<Recurrence::rMonthPos> rmp; QPtrList<int> rmd; int day = 0; int count = 0; int month = 0; setDateTimes( event->dtStart(), dtEnd ); - Recurrence *r = event->recurrence(); - int f = r->frequency(); + - int recurs = r->doesRecur(); + int recurs = event->doesRecur(); mEnabledCheck->setChecked( recurs ); setEnabled( recurs ); int recurrenceType = RecurrenceChooser::Weekly; - - switch ( recurs ) { - case Recurrence::rNone: - setDefaults( event->dtStart(), dtEnd ); - break; - case Recurrence::rDaily: - recurrenceType = RecurrenceChooser::Daily; - mDaily->setFrequency( f ); - break; - case Recurrence::rWeekly: - recurrenceType = RecurrenceChooser::Weekly; - mWeekly->setFrequency( f ); - mWeekly->setDays( r->days() ); - break; - case Recurrence::rMonthlyPos: - // we only handle one possibility in the list right now, - // so I have hardcoded calls with first(). If we make the GUI - // more extended, this can be changed. - recurrenceType = RecurrenceChooser::Monthly; - - rmp = r->monthPositions(); - if ( rmp.first()->negative ) - count = 5 - rmp.first()->rPos - 1; - else - count = rmp.first()->rPos - 1; - day = 0; - while ( !rmp.first()->rDays.testBit( day ) ) ++day; - mMonthly->setByPos( count, day ); - - mMonthly->setFrequency( f ); - - break; - case Recurrence::rMonthlyDay: - recurrenceType = RecurrenceChooser::Monthly; - - rmd = r->monthDays(); - day = *rmd.first() - 1; - mMonthly->setByDay( day ); - - mMonthly->setFrequency( f ); - - break; - case Recurrence::rYearlyMonth: - { - recurrenceType = RecurrenceChooser::Yearly; - //qDebug("Recurrence::rYearlyMonth: "); - day = event->dtStart().date().day(); - rmd = r->yearNums(); - if ( rmd.count() > 0 ) - month = *rmd.first(); - else - month = event->dtStart().date().month() ; - mYearly->setByMonth( month, day ); + if ( recurs ) { + Recurrence *r = event->recurrence(); + int f = r->frequency(); + switch ( recurs ) { + case Recurrence::rNone: + setDefaults( event->dtStart(), dtEnd ); + break; + case Recurrence::rDaily: + recurrenceType = RecurrenceChooser::Daily; + mDaily->setFrequency( f ); + break; + case Recurrence::rWeekly: + recurrenceType = RecurrenceChooser::Weekly; + mWeekly->setFrequency( f ); + mWeekly->setDays( r->days() ); + break; + case Recurrence::rMonthlyPos: + // we only handle one possibility in the list right now, + // so I have hardcoded calls with first(). If we make the GUI + // more extended, this can be changed. + recurrenceType = RecurrenceChooser::Monthly; + + rmp = r->monthPositions(); + if ( rmp.first()->negative ) + count = 5 - rmp.first()->rPos - 1; + else + count = rmp.first()->rPos - 1; + day = 0; + while ( !rmp.first()->rDays.testBit( day ) ) ++day; + mMonthly->setByPos( count, day ); + + mMonthly->setFrequency( f ); + + break; + case Recurrence::rMonthlyDay: + recurrenceType = RecurrenceChooser::Monthly; + + rmd = r->monthDays(); + day = *rmd.first() - 1; + mMonthly->setByDay( day ); + + mMonthly->setFrequency( f ); + + break; + case Recurrence::rYearlyMonth: + { + recurrenceType = RecurrenceChooser::Yearly; + //qDebug("Recurrence::rYearlyMonth: "); + day = event->dtStart().date().day(); + rmd = r->yearNums(); + if ( rmd.count() > 0 ) + month = *rmd.first(); + else + month = event->dtStart().date().month() ; + mYearly->setByMonth( month, day ); #if 0 - //qDebug("2day = %d ",day ); - QPtrList<Recurrence::rMonthPos> monthlist = r->yearMonthPositions(); - int month; - if ( !monthlist.isEmpty() ) { - month = monthlist.first()->rPos ; - } else { - month = event->dtStart().date().month() ; - } - mYearly->setByMonth( day, month ); + //qDebug("2day = %d ",day ); + QPtrList<Recurrence::rMonthPos> monthlist = r->yearMonthPositions(); + int month; + if ( !monthlist.isEmpty() ) { + month = monthlist.first()->rPos ; + } else { + month = event->dtStart().date().month() ; + } + mYearly->setByMonth( day, month ); #endif - mYearly->setFrequency( f ); - } + mYearly->setFrequency( f ); + } - break; - case Recurrence::rYearlyDay: - //qDebug("Recurrence::rYearlyDay: "); - recurrenceType = RecurrenceChooser::Yearly; - mYearly->setByDay( event->dtStart().date().dayOfYear() ); - mYearly->setFrequency( f ); - break; - default: - setDefaults( event->dtStart(), dtEnd ); - break; + break; + case Recurrence::rYearlyDay: + //qDebug("Recurrence::rYearlyDay: "); + recurrenceType = RecurrenceChooser::Yearly; + mYearly->setByDay( event->dtStart().date().dayOfYear() ); + mYearly->setFrequency( f ); + break; + default: + setDefaults( event->dtStart(), dtEnd ); + break; + } } - mRecurrenceChooser->setType( recurrenceType ); showCurrentRule( recurrenceType ); mRecurrenceRange->setDateTimes( event->dtStart() ); - if ( r->doesRecur() ) { + if ( event->doesRecur() ) { + Recurrence *r = event->recurrence(); mRecurrenceRange->setDuration( r->duration() ); if ( r->duration() == 0 ) { if ( r->endDate() < event->dtStart().date() ) mRecurrenceRange->setEndDate( event->dtStart().date() ); else mRecurrenceRange->setEndDate( r->endDate() ); } else mRecurrenceRange->setEndDate( event->dtStart().date() ); } mExceptions->setDates( event->exDates() ); } void KOEditorRecurrence::writeEvent( Incidence *event ) { - Recurrence *r = event->recurrence(); + - // clear out any old settings; - r->unsetRecurs(); + if ( !mEnabledCheck->isChecked() ) { + if ( event->doesRecur() ) + event->recurrence()->unsetRecurs(); + } else { + Recurrence *r = event->recurrence(); - if ( mEnabledCheck->isChecked() ) { + // clear out any old settings; + r->unsetRecurs(); int duration = mRecurrenceRange->duration(); QDate endDate; if ( duration == 0 ) endDate = mRecurrenceRange->endDate(); int recurrenceType = mRecurrenceChooser->type(); if ( recurrenceType == RecurrenceChooser::Daily ) { int freq = mDaily->frequency(); if ( duration != 0 ) r->setDaily( freq, duration ); else r->setDaily( freq, endDate ); } else if ( recurrenceType == RecurrenceChooser::Weekly ) { int freq = mWeekly->frequency(); QBitArray days = mWeekly->days(); int j; bool found = false; for (j = 0; j < 7 ; ++j ) { |