summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-07-10 17:03:16 (UTC)
committer zautrix <zautrix>2004-07-10 17:03:16 (UTC)
commitcf2f3f98a4811668f9e9d0d5f44ea5b51d268cef (patch) (side-by-side diff)
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()
/////////////////////////// RecurYearly ///////////////////////////////
RecurYearly::RecurYearly( QWidget *parent, const char *name ) :
RecurBase( parent, name )
{
QBoxLayout *topLayout = new QVBoxLayout( this );
topLayout->setSpacing( KDialog::spacingHint() );
QBoxLayout *freqLayout = new QHBoxLayout( topLayout );
QLabel *preLabel = new QLabel( i18n("every"), this );
freqLayout->addWidget( preLabel );
freqLayout->addWidget( frequencyEdit() );
QLabel *postLabel = new QLabel( i18n("year(s)"), this );
freqLayout->addWidget( postLabel );
QButtonGroup *buttonGroup = new QButtonGroup( this );
buttonGroup->setFrameStyle( QFrame::NoFrame );
topLayout->addWidget( buttonGroup, 1, AlignVCenter );
- QGridLayout *buttonLayout = new QGridLayout( buttonGroup, 3, 2 );
-
- QString recurInMonthText;
- if ( !KOPrefs::instance()->mCompactDialogs ) {
- recurInMonthText = i18n("Recur in the month of");
- }
-
- mByMonthRadio = new QRadioButton( recurInMonthText, buttonGroup);
- buttonLayout->addWidget( mByMonthRadio, 0, 0 );
+ QGridLayout *buttonLayout = new QGridLayout( buttonGroup, 2, 3 );
+ mByMonthRadio = new QRadioButton( i18n("On day "), buttonGroup);
+ buttonLayout->addWidget( mByMonthRadio, 0, 0 , Qt::AlignRight);
+ mByDayLabel = new QLabel( i18n(" 1 of "), buttonGroup );
+
+ buttonLayout->addWidget( mByDayLabel, 0, 1 );
mByMonthCombo = new QComboBox( buttonGroup );
mByMonthCombo->insertItem( i18n("January") );
mByMonthCombo->insertItem( i18n("February") );
mByMonthCombo->insertItem( i18n("March") );
mByMonthCombo->insertItem( i18n("April") );
mByMonthCombo->insertItem( i18n("May") );
mByMonthCombo->insertItem( i18n("June") );
mByMonthCombo->insertItem( i18n("July") );
mByMonthCombo->insertItem( i18n("August") );
mByMonthCombo->insertItem( i18n("September") );
mByMonthCombo->insertItem( i18n("October") );
mByMonthCombo->insertItem( i18n("November") );
mByMonthCombo->insertItem( i18n("December") );
- buttonLayout->addWidget( mByMonthCombo, 0, 1 );
-
- mByMonthCombo->setSizeLimit( 6 );
-
- buttonLayout->setRowStretch( 1, 1 );
-
- QString recurOnDayText;
- if ( KOPrefs::instance()->mCompactDialogs ) {
- recurOnDayText = i18n("This day");
- } else {
- recurOnDayText = i18n("Recur on this day");
- }
-
- mByDayRadio = new QRadioButton( recurOnDayText, buttonGroup);
- buttonLayout->addMultiCellWidget( mByDayRadio, 2, 2, 0, 1 );
+ buttonLayout->addWidget( mByMonthCombo, 0, 2,Qt::AlignLeft );
+ if ( QApplication::desktop()->width() <= 640 ) {
+ mByMonthCombo->setSizeLimit( 6 );
+ }
+
+ mByDayRadio = new QRadioButton( i18n("On day "), buttonGroup);
+ buttonLayout->addWidget( mByDayRadio, 1, 0 , Qt::AlignRight);
+ mDayOfLabel = new QLabel( i18n("1 of the year"), buttonGroup );
+ buttonLayout->addMultiCellWidget( mDayOfLabel, 1, 1, 1,3 );
+
}
-void RecurYearly::setByDay()
+void RecurYearly::setByDay( int doy )
{
mByDayRadio->setChecked( true );
+ mDayOfLabel->setText(i18n("%1 of the year").arg( doy ) );
}
-void RecurYearly::setByMonth( int month )
+void RecurYearly::setByMonth( int month, int day )
{
mByMonthRadio->setChecked( true );
mByMonthCombo->setCurrentItem( month - 1 );
+ mByDayLabel->setText(i18n("%1 of ").arg( day ) );
+ mDay = day;
}
bool RecurYearly::byMonth()
{
return mByMonthRadio->isChecked();
}
bool RecurYearly::byDay()
{
return mByDayRadio->isChecked();
}
int RecurYearly::month()
{
return mByMonthCombo->currentItem() + 1;
}
+int RecurYearly::day()
+{
+ return mDay;//mByDayCombo->currentItem() + 1;
+}
//////////////////////////// ExceptionsWidget //////////////////////////
ExceptionsWidget::ExceptionsWidget( QWidget *parent, const char *name ) :
QWidget( parent, name )
{
QBoxLayout *topLayout = new QVBoxLayout( this );
QGroupBox *groupBox = new QGroupBox( 1, Horizontal, i18n("Exceptions"),
this );
topLayout->addWidget( groupBox );
QWidget *box = new QWidget( groupBox );
QGridLayout *boxLayout = new QGridLayout( box );
mExceptionDateEdit = new KDateEdit( box );
boxLayout->addWidget( mExceptionDateEdit, 0, 0 );
QPushButton *addExceptionButton = new QPushButton( i18n("Add"), box );
boxLayout->addWidget( addExceptionButton, 1, 0 );
QPushButton *changeExceptionButton = new QPushButton( i18n("Change"), box );
boxLayout->addWidget( changeExceptionButton, 2, 0 );
QPushButton *deleteExceptionButton = new QPushButton( i18n("Delete"), box );
@@ -823,48 +822,49 @@ KOEditorRecurrence::KOEditorRecurrence( QWidget* parent, const char *name ) :
mRecurrenceRangeButton = 0;
topLayout->addWidget( mRecurrenceRangeWidget, 3, 0 );
mExceptionsWidget = new ExceptionsWidget( this );
mExceptionsDialog = 0;
mExceptions = mExceptionsWidget;
mExceptionsButton = 0;
topLayout->addWidget( mExceptionsWidget, 3, 1 );
}
}
KOEditorRecurrence::~KOEditorRecurrence()
{
}
void KOEditorRecurrence::setEnabled( bool enabled )
{
// kdDebug() << "KOEditorRecurrence::setEnabled(): " << (enabled ? "on" : "off") << endl;
mTimeGroupBox->setEnabled( enabled );
if ( mRecurrenceRangeWidget ) mRecurrenceRangeWidget->setEnabled( enabled );
if ( mRecurrenceRangeButton ) mRecurrenceRangeButton->setEnabled( enabled );
if ( mExceptionsWidget ) mExceptionsWidget->setEnabled( enabled );
if ( mExceptionsButton ) mExceptionsButton->setEnabled( enabled );
+ mRuleBox->setEnabled( enabled );
}
void KOEditorRecurrence::showCurrentRule( int current )
{
switch ( current ) {
case Daily:
mRuleStack->raiseWidget( mDaily );
break;
case Weekly:
mRuleStack->raiseWidget( mWeekly );
break;
case Monthly:
mRuleStack->raiseWidget( mMonthly );
break;
default:
case Yearly:
mRuleStack->raiseWidget( mYearly );
break;
}
}
void KOEditorRecurrence::setDateTimes( QDateTime start, QDateTime end )
{
// kdDebug() << "KOEditorRecurrence::setDateTimes" << endl;
@@ -874,59 +874,61 @@ void KOEditorRecurrence::setDateTimes( QDateTime start, QDateTime end )
}
void KOEditorRecurrence::setDefaults( QDateTime from, QDateTime to, bool )
{
// qDebug("KOEditorRecurrence::setDefaults %s %s ",from.toString().latin1(),to.toString().latin1() );
setDateTimes( from, to );
bool enabled = false;
mEnabledCheck->setChecked( enabled );
setEnabled( enabled );
mExceptions->setDefaults( to );
mRecurrenceRange->setDefaults( to );
mRecurrenceChooser->setType( RecurrenceChooser::Weekly );
showCurrentRule( mRecurrenceChooser->type() );
mDaily->setFrequency( 1 );
mWeekly->setFrequency( 1 );
QBitArray days( 7 );
days.fill( 0 );
+ days.setBit( from.date().dayOfWeek()- 1);
mWeekly->setDays( days );
-
mMonthly->setFrequency( 1 );
+ mMonthly->setByPos((from.date().day()/7), from.date().dayOfWeek()-1 );
mMonthly->setByDay( from.date().day()-1 );
-
mYearly->setFrequency( 1 );
- mYearly->setByDay();
+ mYearly->setByDay( from.date().dayOfYear() );
+ mYearly->setByMonth( from.date().month(), from.date().day() );
}
void KOEditorRecurrence::readEvent(Event *event)
{
+ setDefaults( event->dtStart(), event->dtEnd(), true );
QBitArray rDays( 7 );
QPtrList<Recurrence::rMonthPos> rmp;
QPtrList<int> rmd;
int day = 0;
int count = 0;
int month = 0;
setDateTimes( event->dtStart(), event->dtEnd() );
Recurrence *r = event->recurrence();
int f = r->frequency();
int recurs = r->doesRecur();
mEnabledCheck->setChecked( recurs );
setEnabled( recurs );
int recurrenceType = RecurrenceChooser::Weekly;
switch ( recurs ) {
case Recurrence::rNone:
setDefaults( event->dtStart(), event->dtEnd(), true );
break;
case Recurrence::rDaily:
recurrenceType = RecurrenceChooser::Daily;
@@ -945,61 +947,79 @@ void KOEditorRecurrence::readEvent(Event *event)
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:
- case Recurrence::rYearlyDay:
- recurrenceType = RecurrenceChooser::Yearly;
-
- rmd = r->yearNums();
- month = *rmd.first();
- if ( month == event->dtStart().date().month() ) {
- mYearly->setByDay();
- } else {
- mYearly->setByMonth( month );
- }
+ {
+ 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 );
+#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(), event->dtEnd(), true );
break;
}
mRecurrenceChooser->setType( recurrenceType );
showCurrentRule( recurrenceType );
mRecurrenceRange->setDateTimes( event->dtStart() );
if ( r->doesRecur() ) {
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() );
}
@@ -1041,63 +1061,66 @@ void KOEditorRecurrence::writeEvent( Event *event )
if ( mMonthly->byPos() ) {
int pos = mMonthly->count();
QBitArray days( 7 );
days.fill( false );
days.setBit( mMonthly->weekday() );
if ( duration != 0 )
r->setMonthly( Recurrence::rMonthlyPos, freq, duration );
else
r->setMonthly( Recurrence::rMonthlyPos, freq, endDate );
r->addMonthlyPos( pos, days );
} else {
// it's by day
int day = mMonthly->day();
if ( duration != 0 ) {
r->setMonthly( Recurrence::rMonthlyDay, freq, duration );
} else {
r->setMonthly( Recurrence::rMonthlyDay, freq, endDate );
}
r->addMonthlyDay( day );
}
} else if ( recurrenceType == RecurrenceChooser::Yearly ) {
+ qDebug("RecurrenceChooser::Yearly ");
int freq = mYearly->frequency();
-
- int month;
- if ( mYearly->byMonth() ) {
- month = mYearly->month();
- } else {
- month = event->dtStart().date().month();
- }
- if ( duration != 0 ) {
- r->setYearly( Recurrence::rYearlyMonth, freq, duration );
+ if ( mYearly->byDay() ) {
+ if ( duration != 0 ) {
+ r->setYearly( Recurrence::rYearlyDay, freq, duration );
+ } else {
+ r->setYearly( Recurrence::rYearlyDay, freq, endDate );
+ }
+ r->addYearlyNum( event->dtStart().date().dayOfYear() );
} else {
- r->setYearly( Recurrence::rYearlyMonth, freq, endDate );
+ if ( duration != 0 ) {
+ r->setYearly( Recurrence::rYearlyMonth, freq, duration );
+ } else {
+ r->setYearly( Recurrence::rYearlyMonth, freq, endDate );
+ }
+ r->addYearlyNum( mYearly->month() );
}
- r->addYearlyNum( month );
}
event->setExDates( mExceptions->dates() );
}
}
void KOEditorRecurrence::setDateTimeStr( const QString &str )
{
mDateTimeLabel->setText( str );
}
bool KOEditorRecurrence::validateInput()
{
// Check input here
return true;
}
void KOEditorRecurrence::showExceptionsDialog()
{
DateList dates = mExceptions->dates();
int result = mExceptionsDialog->exec();
if ( result == QDialog::Rejected ) mExceptions->setDates( dates );
}
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
void setByPos( int count, int weekday );
bool byDay();
bool byPos();
int day();
int count();
int weekday();
private:
QRadioButton *mByDayRadio;
QComboBox *mByDayCombo;
QRadioButton *mByPosRadio;
QComboBox *mByPosCountCombo;
QComboBox *mByPosWeekdayCombo;
};
class RecurYearly : public RecurBase
{
public:
RecurYearly( QWidget *parent = 0, const char *name = 0 );
- void setByDay();
- void setByMonth( int month );
+ void setByDay( int doy );
+ void setByMonth( int month, int day );
bool byMonth();
bool byDay();
int month();
+ int day();
private:
+ int mDay;
QRadioButton *mByMonthRadio;
QComboBox *mByMonthCombo;
-
+ QLabel* mByDayLabel;
+ QLabel* mDayOfLabel;
QRadioButton *mByDayRadio;
};
class RecurrenceChooser : public QWidget
{
Q_OBJECT
public:
RecurrenceChooser( QWidget *parent = 0, const char *name = 0 );
enum { Daily, Weekly, Monthly, Yearly };
void setType( int );
int type();
signals:
void chosen( int );
protected slots:
void emitChoice();
private:
QComboBox *mTypeCombo;
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
struct icalrecurrencetype r = rrule;
dumpIcalRecurrence(r);
readRecurrence( r, recur, incidence);
}
void ICalFormatImpl::readRecurrence( const struct icalrecurrencetype &r, Recurrence* recur, Incidence *incidence)
{
int wkst;
int index = 0;
short day = 0;
QBitArray qba(7);
int frequ = r.freq;
int interv = r.interval;
// preprocessing for odd recurrence definitions
if ( r.freq == ICAL_MONTHLY_RECURRENCE ) {
if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX) {
interv = 12;
}
}
if ( r.freq == ICAL_YEARLY_RECURRENCE ) {
if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX && r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX ) {
frequ = ICAL_MONTHLY_RECURRENCE;
- interv = 12;
+ interv = 12* r.interval;
}
}
switch (frequ) {
case ICAL_MINUTELY_RECURRENCE:
if (!icaltime_is_null_time(r.until)) {
recur->setMinutely(interv,readICalDateTime(r.until));
} else {
if (r.count == 0)
recur->setMinutely(interv,-1);
else
recur->setMinutely(interv,r.count);
}
break;
case ICAL_HOURLY_RECURRENCE:
if (!icaltime_is_null_time(r.until)) {
recur->setHourly(interv,readICalDateTime(r.until));
} else {
if (r.count == 0)
recur->setHourly(interv,-1);
else
recur->setHourly(interv,r.count);
}
break;
@@ -1478,110 +1478,114 @@ void ICalFormatImpl::readRecurrence( const struct icalrecurrencetype &r, Recurre
}
if (useSetPos) {
if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) {
recur->addMonthlyPos(r.by_set_pos[0],qba);
}
}
} else if (r.by_month_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
if (!icaltime_is_null_time(r.until)) {
recur->setMonthly(Recurrence::rMonthlyDay,interv,
readICalDate(r.until));
} else {
if (r.count == 0)
recur->setMonthly(Recurrence::rMonthlyDay,interv,-1);
else
recur->setMonthly(Recurrence::rMonthlyDay,interv,r.count);
}
while((day = r.by_month_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
// kdDebug(5800) << "----b " << day << endl;
recur->addMonthlyDay(day);
}
}
break;
case ICAL_YEARLY_RECURRENCE:
if (r.by_year_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
+ qDebug(" YEARLY DAY OF YEAR");
if (!icaltime_is_null_time(r.until)) {
recur->setYearly(Recurrence::rYearlyDay,interv,
readICalDate(r.until));
} else {
if (r.count == 0)
recur->setYearly(Recurrence::rYearlyDay,interv,-1);
else
recur->setYearly(Recurrence::rYearlyDay,interv,r.count);
}
while((day = r.by_year_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
recur->addYearlyNum(day);
}
} else if ( true /*r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX*/) {
if (r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
+ qDebug("YEARLY POS NOT SUPPORTED BY GUI");
if (!icaltime_is_null_time(r.until)) {
recur->setYearly(Recurrence::rYearlyPos,interv,
readICalDate(r.until));
} else {
if (r.count == 0)
recur->setYearly(Recurrence::rYearlyPos,interv,-1);
else
recur->setYearly(Recurrence::rYearlyPos,interv,r.count);
}
bool useSetPos = false;
short pos = 0;
while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
// kdDebug(5800) << "----a " << index << ": " << day << endl;
pos = icalrecurrencetype_day_position(day);
if (pos) {
day = icalrecurrencetype_day_day_of_week(day);
QBitArray ba(7); // don't wipe qba
ba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0
recur->addYearlyMonthPos(pos,ba);
} else {
qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0
useSetPos = true;
}
}
if (useSetPos) {
if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) {
recur->addYearlyMonthPos(r.by_set_pos[0],qba);
}
}
} else {
+ qDebug("YEARLY MONTH ");
if (!icaltime_is_null_time(r.until)) {
recur->setYearly(Recurrence::rYearlyMonth,interv,
readICalDate(r.until));
} else {
if (r.count == 0)
recur->setYearly(Recurrence::rYearlyMonth,interv,-1);
else
recur->setYearly(Recurrence::rYearlyMonth,interv,r.count);
}
- }
- if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX ) {
- index = 0;
- while((day = r.by_month[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
- recur->addYearlyNum(day);
+ if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX ) {
+ index = 0;
+ while((day = r.by_month[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
+ recur->addYearlyNum(day);
+ }
+ } else {
+ recur->addYearlyNum(incidence->dtStart().date().month());
}
- } else {
- recur->addYearlyNum(incidence->dtStart().date().month());
}
+
}
break;
default:
;
break;
}
}
void ICalFormatImpl::readAlarm(icalcomponent *alarm,Incidence *incidence)
{
//kdDebug(5800) << "Read alarm for " << incidence->summary() << endl;
Alarm* ialarm = incidence->newAlarm();
ialarm->setRepeatCount(0);
ialarm->setEnabled(true);
// Determine the alarm's action type
icalproperty *p = icalcomponent_get_first_property(alarm,ICAL_ACTION_PROPERTY);
if ( !p ) {
return;
}
icalproperty_action action = icalproperty_get_action(p);
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)
} else {
tmpPos->rPos = -_rPos; // take abs()
tmpPos->negative = true;
}
tmpPos->rDays = _rDays;
tmpPos->rDays.detach();
rMonthPositions.append(tmpPos);
if (mCompatVersion < 310 && mCompatDuration > 0) {
// Backwards compatibility for KDE < 3.1.
// rDuration was set to the number of time periods to recur.
// Convert this to the number of occurrences.
int monthsAhead = (mCompatDuration-1+mRecurExDatesCount) * rFreq;
int month = mRecurStart.date().month() - 1 + monthsAhead;
QDate end(mRecurStart.date().year() + month/12, month%12 + 1, 31);
rDuration = INT_MAX; // ensure that recurCalc() does its job correctly
rDuration = recurCalc(COUNT_TO_DATE, end);
}
if (mParent) mParent->updated();
}
void Recurrence::addMonthlyDay(short _rDay)
{
- if (mRecurReadOnly || recurs != rMonthlyDay
+ if (mRecurReadOnly || (recurs != rMonthlyDay && recurs != rYearlyMonth)
|| _rDay == 0 || _rDay > 31 || _rDay < -31) // invalid day number
return;
for (int* it = rMonthDays.first(); it; it = rMonthDays.next()) {
if (_rDay == *it)
return; // this day is already in the list - avoid duplication
}
int *tmpDay = new int;
*tmpDay = _rDay;
rMonthDays.append(tmpDay);
if (mCompatVersion < 310 && mCompatDuration > 0) {
// Backwards compatibility for KDE < 3.1.
// rDuration was set to the number of time periods to recur.
// Convert this to the number of occurrences.
int monthsAhead = (mCompatDuration-1+mRecurExDatesCount) * rFreq;
int month = mRecurStart.date().month() - 1 + monthsAhead;
QDate end(mRecurStart.date().year() + month/12, month%12 + 1, 31);
rDuration = INT_MAX; // ensure that recurCalc() does its job correctly
rDuration = recurCalc(COUNT_TO_DATE, end);
}
if (mParent) mParent->updated();
}
@@ -704,49 +704,62 @@ void Recurrence::setYearlyByDate(Feb29Type type, int _rFreq, int _rDuration)
if (mCompatVersion < 310)
mCompatDuration = (_rDuration > 0) ? _rDuration : 0;
setYearly_(rYearlyMonth, type, _rFreq, _rDuration);
}
void Recurrence::setYearlyByDate(Feb29Type type, int _rFreq, const QDate &_rEndDate)
{
if (mRecurReadOnly) return;
rEndDateTime.setDate(_rEndDate);
rEndDateTime.setTime(mRecurStart.time());
mCompatDuration = 0;
setYearly_(rYearlyMonth, type, _rFreq, 0);
}
void Recurrence::addYearlyMonthPos(short _rPos, const QBitArray &_rDays)
{
if (recurs == rYearlyPos)
addMonthlyPos_(_rPos, _rDays);
}
const QPtrList<int> &Recurrence::yearNums() const
{
return rYearNums;
}
-
+void Recurrence::addYearlyMonth(short _rPos )
+{
+ if (mRecurReadOnly || recurs != rYearlyMonth) // invalid day/month number
+ return;
+ rMonthPos *tmpPos = new rMonthPos;
+ if ( _rPos > 0) {
+ tmpPos->rPos = _rPos;
+ tmpPos->negative = false;
+ } else {
+ tmpPos->rPos = -_rPos; // take abs()
+ tmpPos->negative = true;
+ }
+ rMonthPositions.append(tmpPos);
+}
void Recurrence::addYearlyNum(short _rNum)
{
if (mRecurReadOnly
|| (recurs != rYearlyMonth && recurs != rYearlyDay && recurs != rYearlyPos)
|| _rNum <= 0) // invalid day/month number
return;
if (mCompatVersion < 310 && mCompatRecurs == rYearlyDay) {
// Backwards compatibility for KDE < 3.1.
// Dates were stored as day numbers, with a fiddle to take account of leap years.
// Convert the day number to a month.
if (_rNum <= 0 || _rNum > 366 || (_rNum == 366 && mRecurStart.date().daysInYear() < 366))
return; // invalid day number
_rNum = QDate(mRecurStart.date().year(), 1, 1).addDays(_rNum - 1).month();
} else
if ((recurs == rYearlyMonth || recurs == rYearlyPos) && _rNum > 12
|| recurs == rYearlyDay && _rNum > 366)
return; // invalid day number
uint i = 0;
for (int* it = rYearNums.first(); it && _rNum >= *it; it = rYearNums.next()) {
if (_rNum == *it)
return; // this day/month is already in the list - avoid duplication
++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
* @var duration the number of times the event is to occur, or -1 to recur indefinitely.
*/
void setYearlyByDate(Feb29Type type, int freq, int duration);
/** Sets an event to recur yearly ending at \a endDate. */
void setYearlyByDate(Feb29Type type, int freq, const QDate &endDate);
/** Adds position of day or month in year.
* N.B. for recursYearlyPos, addYearlyMonthPos() must also be called
* to add positions within the month. */
void addYearlyNum(short _rNum);
/** Adds a position to the recursYearlyPos recurrence rule, if it is set.
* N.B. addYearlyNum() must also be called to add recurrence months.
* Parameters are the same as for addMonthlyPos().
*/
void addYearlyMonthPos(short _rPos, const QBitArray &_rDays);
/** Returns positions of days or months in year. */
const QPtrList<int> &yearNums() const;
/** Returns list of day positions in months, for a recursYearlyPos recurrence rule. */
const QPtrList<rMonthPos> &yearMonthPositions() const;
/** Returns how yearly recurrences of February 29th are handled. */
Feb29Type feb29YearlyType() const { return mFeb29YearlyType; }
/** Sets the default method for handling yearly recurrences of February 29th. */
static void setFeb29YearlyTypeDefault(Feb29Type t) { mFeb29YearlyDefaultType = t; }
/** Returns the default method for handling yearly recurrences of February 29th. */
static Feb29Type setFeb29YearlyTypeDefault() { return mFeb29YearlyDefaultType; }
-
+ void addYearlyMonth(short _rPos ); // added LR
/**
Debug output.
*/
void dump() const;
QString recurrenceText() const;
+ bool getYearlyMonthMonths(int day, QValueList<int>&,
+ QValueList<int> &leaplist) const;
protected:
enum PeriodFunc { END_DATE_AND_COUNT, COUNT_TO_DATE, NEXT_AFTER_DATE };
struct MonthlyData; friend struct MonthlyData;
struct YearlyMonthData; friend struct YearlyMonthData;
struct YearlyPosData; friend struct YearlyPosData;
struct YearlyDayData; friend struct YearlyDayData;
bool recursSecondly(const QDate &, int secondFreq) const;
bool recursMinutelyAt(const QDateTime &dt, int minuteFreq) const;
bool recursDaily(const QDate &) const;
bool recursWeekly(const QDate &) const;
bool recursMonthly(const QDate &) const;
bool recursYearlyByMonth(const QDate &) const;
bool recursYearlyByPos(const QDate &) const;
bool recursYearlyByDay(const QDate &) const;
QDate getNextDateNoTime(const QDate& preDate, bool* last) const;
QDate getPreviousDateNoTime(const QDate& afterDate, bool* last) const;
void addMonthlyPos_(short _rPos, const QBitArray &_rDays);
void setDailySub(short type, int freq, int duration);
void setYearly_(short type, Feb29Type, int freq, int duration);
int recurCalc(PeriodFunc, QDate &enddate) const;
@@ -325,50 +327,48 @@ class Recurrence
int weeklyCalcEndDate(QDate& enddate, int daysPerWeek) const;
int weeklyCalcToDate(const QDate& enddate, int daysPerWeek) const;
int weeklyCalcNextAfter(QDate& enddate, int daysPerWeek) const;
int monthlyCalc(PeriodFunc, QDate &enddate) const;
int monthlyCalcEndDate(QDate& enddate, MonthlyData&) const;
int monthlyCalcToDate(const QDate& enddate, MonthlyData&) const;
int monthlyCalcNextAfter(QDate& enddate, MonthlyData&) const;
int yearlyMonthCalc(PeriodFunc, QDate &enddate) const;
int yearlyMonthCalcEndDate(QDate& enddate, YearlyMonthData&) const;
int yearlyMonthCalcToDate(const QDate& enddate, YearlyMonthData&) const;
int yearlyMonthCalcNextAfter(QDate& enddate, YearlyMonthData&) const;
int yearlyPosCalc(PeriodFunc, QDate &enddate) const;
int yearlyPosCalcEndDate(QDate& enddate, YearlyPosData&) const;
int yearlyPosCalcToDate(const QDate& enddate, YearlyPosData&) const;
int yearlyPosCalcNextAfter(QDate& enddate, YearlyPosData&) const;
int yearlyDayCalc(PeriodFunc, QDate &enddate) const;
int yearlyDayCalcEndDate(QDate& enddate, YearlyDayData&) const;
int yearlyDayCalcToDate(const QDate& enddate, YearlyDayData&) const;
int yearlyDayCalcNextAfter(QDate& enddate, YearlyDayData&) const;
int countMonthlyPosDays() const;
void getMonthlyPosDays(QValueList<int>&, int daysInMonth,
int startDayOfWeek) const;
bool getMonthlyDayDays(QValueList<int>&, int daysInMonth) const;
- bool getYearlyMonthMonths(int day, QValueList<int>&,
- QValueList<int> &leaplist) const;
int getFirstDayInWeek(int startDay, bool useWeekStart = true) const;
int getLastDayInWeek(int endDay, bool useWeekStart = true) const;
QDate getFirstDateInMonth(const QDate& earliestDate) const;
QDate getLastDateInMonth(const QDate& latestDate) const;
QDate getFirstDateInYear(const QDate& earliestDate) const;
QDate getLastDateInYear(const QDate& latestDate) const;
private:
// Prohibit copying
Recurrence(const Recurrence&);
Recurrence &operator=(const Recurrence&);
short recurs; // should be one of the enums.
int rWeekStart; // day which starts the week, Monday=1 .. Sunday=7
QBitArray rDays; // array of days during week it recurs
QPtrList<rMonthPos> rMonthPositions; // list of positions during a month
// on which an event recurs
QPtrList<int> rMonthDays; // list of days during a month on
// which the event recurs