summaryrefslogtreecommitdiffabout
path: root/libkcal
Unidiff
Diffstat (limited to 'libkcal') (more/less context) (show whitespace changes)
-rw-r--r--libkcal/icalformatimpl.cpp8
-rw-r--r--libkcal/recurrence.cpp17
-rw-r--r--libkcal/recurrence.h6
3 files changed, 24 insertions, 7 deletions
diff --git a/libkcal/icalformatimpl.cpp b/libkcal/icalformatimpl.cpp
index 32a1337..964ffe3 100644
--- a/libkcal/icalformatimpl.cpp
+++ b/libkcal/icalformatimpl.cpp
@@ -1383,25 +1383,25 @@ void ICalFormatImpl::readRecurrence( const struct icalrecurrencetype &r, Recurre
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);
@@ -1490,38 +1490,40 @@ void ICalFormatImpl::readRecurrence( const struct icalrecurrencetype &r, Recurre
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) {
@@ -1534,43 +1536,45 @@ void ICalFormatImpl::readRecurrence( const struct icalrecurrencetype &r, Recurre
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 }
1556 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX ) { 1558 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX ) {
1557 index = 0; 1559 index = 0;
1558 while((day = r.by_month[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 1560 while((day = r.by_month[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
1559 recur->addYearlyNum(day); 1561 recur->addYearlyNum(day);
1560 } 1562 }
1561 } else { 1563 } else {
1562 recur->addYearlyNum(incidence->dtStart().date().month()); 1564 recur->addYearlyNum(incidence->dtStart().date().month());
1563 } 1565 }
1564 } 1566 }
1567
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();
diff --git a/libkcal/recurrence.cpp b/libkcal/recurrence.cpp
index 5fc5d1f..dd74e10 100644
--- a/libkcal/recurrence.cpp
+++ b/libkcal/recurrence.cpp
@@ -645,25 +645,25 @@ void Recurrence::addMonthlyPos_(short _rPos, const QBitArray &_rDays)
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.
@@ -716,25 +716,38 @@ void Recurrence::setYearlyByDate(Feb29Type type, int _rFreq, const QDate &_rEndD
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))
diff --git a/libkcal/recurrence.h b/libkcal/recurrence.h
index a0f6d84..b13d14f 100644
--- a/libkcal/recurrence.h
+++ b/libkcal/recurrence.h
@@ -279,30 +279,32 @@ class Recurrence
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;
@@ -337,26 +339,24 @@ class Recurrence
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&);