Changeset View
Changeset View
Standalone View
Standalone View
src/recurrencerule.cpp
Show All 18 Lines | 1 | /* | |||
---|---|---|---|---|---|
19 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 19 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
20 | Boston, MA 02110-1301, USA. | 20 | Boston, MA 02110-1301, USA. | ||
21 | */ | 21 | */ | ||
22 | #include "recurrencerule.h" | 22 | #include "recurrencerule.h" | ||
23 | #include "utils.h" | 23 | #include "utils.h" | ||
24 | #include "kcalcore_debug.h" | 24 | #include "kcalcore_debug.h" | ||
25 | #include "recurrencehelper_p.h" | 25 | #include "recurrencehelper_p.h" | ||
26 | 26 | | |||
27 | #include <QDataStream> | ||||
27 | #include <QStringList> | 28 | #include <QStringList> | ||
28 | #include <QTime> | 29 | #include <QTime> | ||
29 | #include <QTimeZone> | 30 | #include <QTimeZone> | ||
30 | #include <QVector> | 31 | #include <QVector> | ||
31 | 32 | | |||
32 | using namespace KCalCore; | 33 | using namespace KCalCore; | ||
33 | 34 | | |||
34 | // Maximum number of intervals to process | 35 | // Maximum number of intervals to process | ||
▲ Show 20 Lines • Show All 685 Lines • ▼ Show 20 Line(s) | 706 | public: | |||
720 | Private &operator=(const Private &other); | 721 | Private &operator=(const Private &other); | ||
721 | bool operator==(const Private &other) const; | 722 | bool operator==(const Private &other) const; | ||
722 | void clear(); | 723 | void clear(); | ||
723 | void setDirty(); | 724 | void setDirty(); | ||
724 | void buildConstraints(); | 725 | void buildConstraints(); | ||
725 | bool buildCache() const; | 726 | bool buildCache() const; | ||
726 | Constraint getNextValidDateInterval(const QDateTime &preDate, PeriodType type) const; | 727 | Constraint getNextValidDateInterval(const QDateTime &preDate, PeriodType type) const; | ||
727 | Constraint getPreviousValidDateInterval(const QDateTime &afterDate, PeriodType type) const; | 728 | Constraint getPreviousValidDateInterval(const QDateTime &afterDate, PeriodType type) const; | ||
728 | SortableList<QDateTime> datesForInterval(const Constraint &interval, PeriodType type) const; | 729 | QList<QDateTime> datesForInterval(const Constraint &interval, PeriodType type) const; | ||
729 | 730 | | |||
730 | RecurrenceRule *mParent; | 731 | RecurrenceRule *mParent; | ||
731 | QString mRRule; // RRULE string | 732 | QString mRRule; // RRULE string | ||
732 | PeriodType mPeriod; | 733 | PeriodType mPeriod; | ||
733 | QDateTime mDateStart; // start of recurrence (but mDateStart is not an occurrence | 734 | QDateTime mDateStart; // start of recurrence (but mDateStart is not an occurrence | ||
734 | // unless it matches the rule) | 735 | // unless it matches the rule) | ||
735 | uint mFrequency; | 736 | uint mFrequency; | ||
736 | /** how often it recurs: | 737 | /** how often it recurs: | ||
Show All 14 Lines | |||||
751 | QList<int> mByMonths; // values: month 1-12 | 752 | QList<int> mByMonths; // values: month 1-12 | ||
752 | QList<int> mBySetPos; // values: position -366 to -1 and 1-366 | 753 | QList<int> mBySetPos; // values: position -366 to -1 and 1-366 | ||
753 | short mWeekStart; // first day of the week (1=Monday, 7=Sunday) | 754 | short mWeekStart; // first day of the week (1=Monday, 7=Sunday) | ||
754 | 755 | | |||
755 | Constraint::List mConstraints; | 756 | Constraint::List mConstraints; | ||
756 | QList<RuleObserver *> mObservers; | 757 | QList<RuleObserver *> mObservers; | ||
757 | 758 | | |||
758 | // Cache for duration | 759 | // Cache for duration | ||
759 | mutable SortableList<QDateTime> mCachedDates; | 760 | mutable QList<QDateTime> mCachedDates; | ||
760 | mutable QDateTime mCachedDateEnd; | 761 | mutable QDateTime mCachedDateEnd; | ||
761 | mutable QDateTime mCachedLastDate; // when mCachedDateEnd invalid, last date checked | 762 | mutable QDateTime mCachedLastDate; // when mCachedDateEnd invalid, last date checked | ||
762 | mutable bool mCached; | 763 | mutable bool mCached; | ||
763 | 764 | | |||
764 | bool mIsReadOnly; | 765 | bool mIsReadOnly; | ||
765 | bool mAllDay; | 766 | bool mAllDay; | ||
766 | bool mNoByRules; // no BySeconds, ByMinutes, ... rules exist | 767 | bool mNoByRules; // no BySeconds, ByMinutes, ... rules exist | ||
767 | uint mTimedRepetition; // repeats at a regular number of seconds interval, or 0 | 768 | uint mTimedRepetition; // repeats at a regular number of seconds interval, or 0 | ||
▲ Show 20 Lines • Show All 964 Lines • ▼ Show 20 Line(s) | 1727 | if (!dts.isEmpty()) { | |||
1732 | } | 1733 | } | ||
1733 | } | 1734 | } | ||
1734 | interval.increase(recurrenceType(), frequency()); | 1735 | interval.increase(recurrenceType(), frequency()); | ||
1735 | } while (++loop < LOOP_LIMIT && | 1736 | } while (++loop < LOOP_LIMIT && | ||
1736 | (d->mDuration < 0 || interval.intervalDateTime(recurrenceType()) < end)); | 1737 | (d->mDuration < 0 || interval.intervalDateTime(recurrenceType()) < end)); | ||
1737 | return QDateTime(); | 1738 | return QDateTime(); | ||
1738 | } | 1739 | } | ||
1739 | 1740 | | |||
1740 | SortableList<QDateTime> RecurrenceRule::timesInInterval(const QDateTime &dtStart, | 1741 | QList<QDateTime> RecurrenceRule::timesInInterval(const QDateTime &dtStart, | ||
1741 | const QDateTime &dtEnd) const | 1742 | const QDateTime &dtEnd) const | ||
1742 | { | 1743 | { | ||
1743 | const QDateTime start = dtStart.toTimeZone(d->mDateStart.timeZone()); | 1744 | const QDateTime start = dtStart.toTimeZone(d->mDateStart.timeZone()); | ||
1744 | const QDateTime end = dtEnd.toTimeZone(d->mDateStart.timeZone()); | 1745 | const QDateTime end = dtEnd.toTimeZone(d->mDateStart.timeZone()); | ||
1745 | SortableList<QDateTime> result; | 1746 | QList<QDateTime> result; | ||
1746 | if (end < d->mDateStart) { | 1747 | if (end < d->mDateStart) { | ||
1747 | return result; // before start of recurrence | 1748 | return result; // before start of recurrence | ||
1748 | } | 1749 | } | ||
1749 | QDateTime enddt = end; | 1750 | QDateTime enddt = end; | ||
1750 | if (d->mDuration >= 0) { | 1751 | if (d->mDuration >= 0) { | ||
1751 | const QDateTime endRecur = endDt(); | 1752 | const QDateTime endRecur = endDt(); | ||
1752 | if (endRecur.isValid()) { | 1753 | if (endRecur.isValid()) { | ||
1753 | if (start > endRecur) { | 1754 | if (start > endRecur) { | ||
▲ Show 20 Lines • Show All 228 Lines • ▼ Show 20 Line(s) | 1976 | case rYearly: | |||
1982 | break; | 1983 | break; | ||
1983 | default: | 1984 | default: | ||
1984 | break; | 1985 | break; | ||
1985 | } | 1986 | } | ||
1986 | 1987 | | |||
1987 | return Constraint(nextValid, type, mWeekStart); | 1988 | return Constraint(nextValid, type, mWeekStart); | ||
1988 | } | 1989 | } | ||
1989 | 1990 | | |||
1990 | SortableList<QDateTime> RecurrenceRule::Private::datesForInterval(const Constraint &interval, | 1991 | QList<QDateTime> RecurrenceRule::Private::datesForInterval(const Constraint &interval, | ||
1991 | PeriodType type) const | 1992 | PeriodType type) const | ||
1992 | { | 1993 | { | ||
1993 | /* -) Loop through constraints, | 1994 | /* -) Loop through constraints, | ||
1994 | -) merge interval with each constraint | 1995 | -) merge interval with each constraint | ||
1995 | -) if merged constraint is not consistent => ignore that constraint | 1996 | -) if merged constraint is not consistent => ignore that constraint | ||
1996 | -) if complete => add that one date to the date list | 1997 | -) if complete => add that one date to the date list | ||
1997 | -) Loop through all missing fields => For each add the resulting | 1998 | -) Loop through all missing fields => For each add the resulting | ||
1998 | */ | 1999 | */ | ||
1999 | SortableList<QDateTime> lst; | 2000 | QList<QDateTime> lst; | ||
2000 | for (int i = 0, iend = mConstraints.count(); i < iend; ++i) { | 2001 | for (int i = 0, iend = mConstraints.count(); i < iend; ++i) { | ||
2001 | Constraint merged(interval); | 2002 | Constraint merged(interval); | ||
2002 | if (merged.merge(mConstraints[i])) { | 2003 | if (merged.merge(mConstraints[i])) { | ||
2003 | // If the information is incomplete, we can't use this constraint | 2004 | // If the information is incomplete, we can't use this constraint | ||
2004 | if (merged.year > 0 && merged.hour >= 0 && merged.minute >= 0 && merged.second >= 0) { | 2005 | if (merged.year > 0 && merged.hour >= 0 && merged.minute >= 0 && merged.second >= 0) { | ||
2005 | // We have a valid constraint, so get all datetimes that match it andd | 2006 | // We have a valid constraint, so get all datetimes that match it andd | ||
2006 | // append it to all date/times of this interval | 2007 | // append it to all date/times of this interval | ||
2007 | QList<QDateTime> lstnew = merged.dateTimes(type); | 2008 | QList<QDateTime> lstnew = merged.dateTimes(type); | ||
▲ Show 20 Lines • Show All 325 Lines • Show Last 20 Lines |