diff --git a/incidenceeditor-ng/incidencerecurrence.cpp b/incidenceeditor-ng/incidencerecurrence.cpp --- a/incidenceeditor-ng/incidencerecurrence.cpp +++ b/incidenceeditor-ng/incidencerecurrence.cpp @@ -252,9 +252,12 @@ void IncidenceRecurrence::writeToIncidence( const KCalCore::Incidence::Ptr &incidence ) const { + // clear out any old settings; KCalCore::Recurrence *r = incidence->recurrence(); - r->unsetRecurs(); // Why not clear() ? + if (r->rRules().count() > 1) { //if we have more rules, delete them + r->unsetRecurs(); // Why not clear() ? + } const RecurrenceType recurrenceType = currentRecurrenceType(); @@ -281,48 +284,96 @@ } else if ( recurrenceType == RecurrenceTypeMonthly ) { r->setMonthly( mUi->mFrequencyEdit->value() ); + QList wdays; + if ( mUi->mMonthlyCombo->currentIndex() == ComboIndexMonthlyDay ) { // Every nth - r->addMonthlyDate( dayOfMonthFromStart() ); + r->setMonthlyDate(QList() << dayOfMonthFromStart()); + r->setMonthlyPos(wdays); } else if ( mUi->mMonthlyCombo->currentIndex() == ComboIndexMonthlyDayInverted ) { // Every (last - n)th last day - r->addMonthlyDate( -dayOfMonthFromEnd() ); + r->setMonthlyDate(QList() << -dayOfMonthFromEnd()); + r->setMonthlyPos(wdays); } else if ( mUi->mMonthlyCombo->currentIndex() == ComboIndexMonthlyPos ) { // Every ith weekday - r->addMonthlyPos( monthWeekFromStart(), weekday() ); + const QBitArray w = weekday(); + for (int i = 0; i < 7; ++i) { + if (w.testBit(i)) { + const KCalCore::RecurrenceRule::WDayPos p(monthWeekFromStart(), i + 1); + wdays.append(p); + } + } + r->setMonthlyDate(QList()); + r->setMonthlyPos(wdays); } else { // Every (last - i)th last weekday - r->addMonthlyPos( -monthWeekFromEnd(), weekday() ); + QList wdays; + const QBitArray w = weekday(); + for (int i = 0; i < 7; ++i) { + if (w.testBit(i)) { + const KCalCore::RecurrenceRule::WDayPos p(-monthWeekFromEnd(), i + 1); + wdays.append(p); + } + } + r->setMonthlyDate(QList()); + r->setMonthlyPos(wdays); } } else if ( recurrenceType == RecurrenceTypeYearly ) { r->setYearly( mUi->mFrequencyEdit->value() ); + QList wdays; if ( mUi->mYearlyCombo->currentIndex() == ComboIndexYearlyMonth ) { //Every nth of month - r->addYearlyDate( dayOfMonthFromStart() ); - r->addYearlyMonth( currentDate().month() ); + r->setYearlyDate(QList() << dayOfMonthFromStart()); + r->setYearlyMonth(QList() << currentDate().month()); + r->setYearlyPos(wdays); + r->setYearlyDay(QList()); } else if ( mUi->mYearlyCombo->currentIndex() == ComboIndexYearlyMonthInverted ) { //Every (last - n)th last day of month - r->addYearlyDate( -dayOfMonthFromEnd() ); - r->addYearlyMonth( currentDate().month() ); + r->setYearlyDate(QList() << -dayOfMonthFromEnd()); + r->setYearlyMonth(QList() << currentDate().month()); + r->setYearlyPos(wdays); + r->setYearlyDay(QList()); } else if ( mUi->mYearlyCombo->currentIndex() == ComboIndexYearlyPos ) { //Every ith weekday of month - r->addYearlyMonth( currentDate().month() ); - r->addYearlyPos( monthWeekFromStart(), weekday() ); + r->setYearlyDate(QList()); + r->setYearlyMonth(QList() << currentDate().month()); + + const QBitArray w = weekday(); + for (int i = 0; i < 7; ++i) { + if (w.testBit(i)) { + const KCalCore::RecurrenceRule::WDayPos p(monthWeekFromStart(), i + 1); + wdays.append(p); + } + } + r->setYearlyPos(wdays); + r->setYearlyDay(QList()); } else if ( mUi->mYearlyCombo->currentIndex() == ComboIndexYearlyPosInverted ) { //Every (last - i)th last weekday of month - r->addYearlyMonth( currentDate().month() ); - r->addYearlyPos( -monthWeekFromEnd(), weekday() ); + r->setYearlyDate(QList()); + r->setYearlyMonth(QList() << currentDate().month()); + + QList wdays; + const QBitArray w = weekday(); + for (int i = 0; i < 7; ++i) { + if (w.testBit(i)) { + const KCalCore::RecurrenceRule::WDayPos p(-monthWeekFromEnd(), i + 1); + wdays.append(p); + } + } + r->setYearlyPos(wdays); + r->setYearlyDay(QList()); } else { // The lth day of the year (l : 1 - 356) - r->addYearlyDay( dayOfYearFromStart() ); + r->setYearlyDate(QList()); + r->setYearlyMonth(QList()); + r->setYearlyPos(wdays); + r->setYearlyDay(QList() << dayOfYearFromStart()); } } + r->setEndDate( endDate ); r->setDuration( lDuration ); - if ( lDuration == 0 ) { - r->setEndDate( endDate ); - } r->setExDates( mExceptionDates ); } @@ -460,7 +511,7 @@ incidence->recurrence()->getNextDateTime( referenceDate ).isValid() ) ) { mLastErrorString = i18n( "A recurring event or to-do must occur at least once. " "Adjust the recurring parameters." ); - kDebug() << mLastErrorString; + kiDebug() << mLastErrorString; return false; } } else {