Changeset View
Changeset View
Standalone View
Standalone View
incidenceeditor-ng/incidencerecurrence.cpp
Show First 20 Lines • Show All 248 Lines • ▼ Show 20 Lines | void IncidenceRecurrence::load( const KCalCore::Incidence::Ptr &incidence ) | ||||
handleDateTimeToggle(); | handleDateTimeToggle(); | ||||
mWasDirty = false; | mWasDirty = false; | ||||
} | } | ||||
void IncidenceRecurrence::writeToIncidence( const KCalCore::Incidence::Ptr &incidence ) const | void IncidenceRecurrence::writeToIncidence( const KCalCore::Incidence::Ptr &incidence ) const | ||||
{ | { | ||||
// clear out any old settings; | // clear out any old settings; | ||||
KCalCore::Recurrence *r = incidence->recurrence(); | KCalCore::Recurrence *r = incidence->recurrence(); | ||||
const QSet<KCalCore::IncidenceBase::Field> dirtyFields(incidence->dirtyFields()); | |||||
KCalCore::Recurrence rOld = *r; | |||||
r->unsetRecurs(); // Why not clear() ? | r->unsetRecurs(); // Why not clear() ? | ||||
const RecurrenceType recurrenceType = currentRecurrenceType(); | const RecurrenceType recurrenceType = currentRecurrenceType(); | ||||
if ( recurrenceType == RecurrenceTypeException ) { | if ( recurrenceType == RecurrenceTypeException ) { | ||||
incidence->setThisAndFuture( mUi->mThisAndFutureCheck->isChecked() ); | incidence->setThisAndFuture( mUi->mThisAndFutureCheck->isChecked() ); | ||||
return; | return; | ||||
} | } | ||||
Show All 11 Lines | void IncidenceRecurrence::writeToIncidence( const KCalCore::Incidence::Ptr &incidence ) const | ||||
if ( recurrenceType == RecurrenceTypeDaily ) { | if ( recurrenceType == RecurrenceTypeDaily ) { | ||||
r->setDaily( mUi->mFrequencyEdit->value() ); | r->setDaily( mUi->mFrequencyEdit->value() ); | ||||
} else if ( recurrenceType == RecurrenceTypeWeekly ) { | } else if ( recurrenceType == RecurrenceTypeWeekly ) { | ||||
r->setWeekly( mUi->mFrequencyEdit->value(), mUi->mWeekDayCombo->days() ); | r->setWeekly( mUi->mFrequencyEdit->value(), mUi->mWeekDayCombo->days() ); | ||||
} else if ( recurrenceType == RecurrenceTypeMonthly ) { | } else if ( recurrenceType == RecurrenceTypeMonthly ) { | ||||
r->setMonthly( mUi->mFrequencyEdit->value() ); | r->setMonthly( mUi->mFrequencyEdit->value() ); | ||||
if ( mUi->mMonthlyCombo->currentIndex() == ComboIndexMonthlyDay ) { | if ( mUi->mMonthlyCombo->currentIndex() == ComboIndexMonthlyDay ) { | ||||
mollekopf: Put into the local scope of every if as necessary.
That way it's obvious when it's empty and… | |||||
// Every nth | // Every nth | ||||
r->addMonthlyDate( dayOfMonthFromStart() ); | r->addMonthlyDate( dayOfMonthFromStart() ); | ||||
} else if ( mUi->mMonthlyCombo->currentIndex() == ComboIndexMonthlyDayInverted ) { | } else if ( mUi->mMonthlyCombo->currentIndex() == ComboIndexMonthlyDayInverted ) { | ||||
// Every (last - n)th last day | // Every (last - n)th last day | ||||
r->addMonthlyDate( -dayOfMonthFromEnd() ); | r->addMonthlyDate( -dayOfMonthFromEnd() ); | ||||
} else if ( mUi->mMonthlyCombo->currentIndex() == ComboIndexMonthlyPos ) { | } else if ( mUi->mMonthlyCombo->currentIndex() == ComboIndexMonthlyPos ) { | ||||
// Every ith weekday | // Every ith weekday | ||||
r->addMonthlyPos( monthWeekFromStart(), weekday() ); | r->addMonthlyPos( monthWeekFromStart(), weekday() ); | ||||
} else { | } else { | ||||
Not Done Inline ActionsExtract into static function and reuse below. mollekopf: Extract into static function and reuse below. | |||||
// Every (last - i)th last weekday | // Every (last - i)th last weekday | ||||
r->addMonthlyPos( -monthWeekFromEnd(), weekday() ); | r->addMonthlyPos( -monthWeekFromEnd(), weekday() ); | ||||
} | } | ||||
Not Done Inline Actionsreuse function from above mollekopf: reuse function from above | |||||
} else if ( recurrenceType == RecurrenceTypeYearly ) { | } else if ( recurrenceType == RecurrenceTypeYearly ) { | ||||
r->setYearly( mUi->mFrequencyEdit->value() ); | r->setYearly( mUi->mFrequencyEdit->value() ); | ||||
if ( mUi->mYearlyCombo->currentIndex() == ComboIndexYearlyMonth ) { | if ( mUi->mYearlyCombo->currentIndex() == ComboIndexYearlyMonth ) { | ||||
//Every nth of month | //Every nth of month | ||||
r->addYearlyDate( dayOfMonthFromStart() ); | r->addYearlyDate( dayOfMonthFromStart() ); | ||||
r->addYearlyMonth( currentDate().month() ); | r->addYearlyMonth( currentDate().month() ); | ||||
} else if ( mUi->mYearlyCombo->currentIndex() == ComboIndexYearlyMonthInverted ) { | } else if ( mUi->mYearlyCombo->currentIndex() == ComboIndexYearlyMonthInverted ) { | ||||
//Every (last - n)th last day of month | //Every (last - n)th last day of month | ||||
r->addYearlyDate( -dayOfMonthFromEnd() ); | r->addYearlyDate( -dayOfMonthFromEnd() ); | ||||
r->addYearlyMonth( currentDate().month() ); | r->addYearlyMonth( currentDate().month() ); | ||||
} else if ( mUi->mYearlyCombo->currentIndex() == ComboIndexYearlyPos ) { | } else if ( mUi->mYearlyCombo->currentIndex() == ComboIndexYearlyPos ) { | ||||
//Every ith weekday of month | //Every ith weekday of month | ||||
r->addYearlyMonth( currentDate().month() ); | r->addYearlyMonth( currentDate().month() ); | ||||
r->addYearlyPos( monthWeekFromStart(), weekday() ); | r->addYearlyPos( monthWeekFromStart(), weekday() ); | ||||
} else if ( mUi->mYearlyCombo->currentIndex() == ComboIndexYearlyPosInverted ) { | } else if ( mUi->mYearlyCombo->currentIndex() == ComboIndexYearlyPosInverted ) { | ||||
//Every (last - i)th last weekday of month | //Every (last - i)th last weekday of month | ||||
r->addYearlyMonth( currentDate().month() ); | r->addYearlyMonth( currentDate().month() ); | ||||
r->addYearlyPos( -monthWeekFromEnd(), weekday() ); | r->addYearlyPos( -monthWeekFromEnd(), weekday() ); | ||||
} else { | } else { | ||||
// The lth day of the year (l : 1 - 356) | // The lth day of the year (l : 1 - 356) | ||||
r->addYearlyDay( dayOfYearFromStart() ); | r->addYearlyDay( dayOfYearFromStart() ); | ||||
} | } | ||||
} | } | ||||
Not Done Inline Actionsreuse function from above mollekopf: reuse function from above | |||||
r->setDuration( lDuration ); | r->setDuration( lDuration ); | ||||
if ( lDuration == 0 ) { | if ( lDuration == 0 ) { | ||||
r->setEndDate( endDate ); | r->setEndDate( endDate ); | ||||
} | } | ||||
Not Done Inline Actionsreuse function from above mollekopf: reuse function from above | |||||
r->setExDates( mExceptionDates ); | r->setExDates( mExceptionDates ); | ||||
if (*r == rOld) { | |||||
incidence->setDirtyFields(dirtyFields); | |||||
} | |||||
} | } | ||||
void IncidenceRecurrence::save( const KCalCore::Incidence::Ptr &incidence ) | void IncidenceRecurrence::save( const KCalCore::Incidence::Ptr &incidence ) | ||||
{ | { | ||||
writeToIncidence( incidence ); | writeToIncidence( incidence ); | ||||
mMonthlyInitialType = mUi->mMonthlyCombo->currentIndex(); | mMonthlyInitialType = mUi->mMonthlyCombo->currentIndex(); | ||||
mYearlyInitialType = mUi->mYearlyCombo->currentIndex(); | mYearlyInitialType = mUi->mYearlyCombo->currentIndex(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 689 Lines • Show Last 20 Lines |
Put into the local scope of every if as necessary.
That way it's obvious when it's empty and when it's not and that the list is always empty in the beginning.