~ubuntu-branches/ubuntu/oneiric/kdepim/oneiric-updates

« back to all changes in this revision

Viewing changes to kalarm/cal/repetition.h

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2011-06-28 19:33:24 UTC
  • mfrom: (0.2.13) (0.1.13 sid)
  • Revision ID: package-import@ubuntu.com-20110628193324-8yvjs8sdv9rdoo6c
Tags: 4:4.7.0-0ubuntu1
* New upstream release
  - update install files
  - add missing kdepim-doc package to control file
  - Fix Vcs lines
  - kontact breaks/replaces korganizer << 4:4.6.80
  - tighten the dependency of kdepim-dev on libkdepim4 to fix lintian error

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#define REPETITION_H
23
23
 
24
24
#include "kalarm_cal_export.h"
 
25
#ifdef USE_AKONADI
 
26
#include <kcalcore/duration.h>
 
27
#else
25
28
#include <kcal/duration.h>
 
29
#endif
26
30
#include <kdatetime.h>
27
31
 
28
32
/**
35
39
class KALARM_CAL_EXPORT Repetition
36
40
{
37
41
    public:
38
 
        Repetition() : mInterval(0), mCount(0) {}
39
 
        Repetition(const KCal::Duration& interval, int count)
40
 
                : mInterval(interval), mCount(count)
41
 
        {
42
 
                if ((!count && interval) || (count && !interval))
43
 
                {
44
 
                        mCount = 0;
45
 
                        mInterval = 0;
46
 
                }
47
 
        }
48
 
 
49
 
        void set(const KCal::Duration& interval, int count)
50
 
        {
51
 
                if (!count || !interval)
52
 
                {
53
 
                        mCount = 0;
54
 
                        mInterval = 0;
55
 
                }
56
 
                else
57
 
                {
58
 
                        mCount = count;
59
 
                        mInterval = interval;
60
 
                }
61
 
        }
62
 
 
63
 
        void set(const KCal::Duration& interval)
64
 
        {
65
 
                if (mCount)
66
 
                {
67
 
                        mInterval = interval;
68
 
                        if (!interval)
69
 
                                mCount = 0;
70
 
                }
71
 
        }
72
 
 
73
 
        operator bool() const                       { return mCount; }
74
 
        bool operator!() const                      { return !mCount; }
75
 
        bool operator==(const Repetition& r) const  { return mInterval == r.mInterval && mCount == r.mCount; }
76
 
        bool operator!=(const Repetition& r) const  { return mInterval != r.mInterval || mCount != r.mCount; }
77
 
 
78
 
        /** Return the number of repetitions. */
79
 
        int count() const     { return mCount; }
80
 
 
81
 
        /** Return the interval between repetitions. */
82
 
        const KCal::Duration& interval() const  { return mInterval; }
83
 
 
84
 
        /** Return the overall duration of the repetition. */
85
 
        KCal::Duration duration() const  { return mInterval * mCount; }
86
 
 
87
 
        /** Return the overall duration of a specified number of repetitions.
88
 
         *  @param count the number of repetitions to find the duration of.
89
 
         */
90
 
        KCal::Duration duration(int count) const  { return mInterval * count; }
91
 
 
92
 
        /** Check whether the repetition interval is in terms of days (as opposed to minutes). */
93
 
        bool isDaily() const          { return mInterval.isDaily(); }
94
 
 
95
 
        /** Return the repetition interval in terms of days.
96
 
         *  If necessary, the interval is rounded down to a whole number of days.
97
 
         */
98
 
        int intervalDays() const      { return mInterval.asDays(); }
99
 
 
100
 
        /** Return the repetition interval in terms of minutes.
101
 
         *  If necessary, the interval is rounded down to a whole number of minutes.
102
 
         */
103
 
        int intervalMinutes() const   { return mInterval.asSeconds() / 60; }
104
 
 
105
 
        /** Return the repetition interval in terms of seconds. */
106
 
        int intervalSeconds() const   { return mInterval.asSeconds(); }
107
 
 
108
 
        /** Find the repetition count for the next repetition after a specified time.
109
 
         *  @param from         repetition start time, which should not be a date-only value
110
 
         *  @param preDateTime  time after which the desired repetition occurs
111
 
         */
112
 
        int nextRepeatCount(const KDateTime& from, const KDateTime& preDateTime) const
113
 
        {
114
 
                return mInterval.isDaily()
115
 
                     ? from.daysTo(preDateTime) / mInterval.asDays() + 1
116
 
                     : static_cast<int>(from.secsTo_long(preDateTime) / mInterval.asSeconds()) + 1;
117
 
        }
118
 
 
119
 
        /** Find the repetition count for the last repetition before a specified time.
120
 
         *  @param from           repetition start time, which should not be a date-only value
121
 
         *  @param afterDateTime  time after which the desired repetition occurs
122
 
         */
123
 
        int previousRepeatCount(const KDateTime& from, const KDateTime& afterDateTime) const
124
 
        {
125
 
                return mInterval.isDaily()
126
 
                     ? from.daysTo(afterDateTime.addSecs(-1)) / mInterval.asDays()
127
 
                     : static_cast<int>((from.secsTo_long(afterDateTime) - 1) / mInterval.asSeconds());
128
 
        }
 
42
        Repetition() : mInterval(0), mCount(0) {}
 
43
#ifdef USE_AKONADI
 
44
        Repetition(const KCalCore::Duration& interval, int count)
 
45
#else
 
46
        Repetition(const KCal::Duration& interval, int count)
 
47
#endif
 
48
            : mInterval(interval), mCount(count)
 
49
        {
 
50
            if ((!count && interval) || (count && !interval))
 
51
            {
 
52
                mCount = 0;
 
53
                mInterval = 0;
 
54
            }
 
55
        }
 
56
 
 
57
#ifdef USE_AKONADI
 
58
        void set(const KCalCore::Duration& interval, int count)
 
59
#else
 
60
        void set(const KCal::Duration& interval, int count)
 
61
#endif
 
62
        {
 
63
            if (!count || !interval)
 
64
            {
 
65
                mCount = 0;
 
66
                mInterval = 0;
 
67
            }
 
68
            else
 
69
            {
 
70
                mCount = count;
 
71
                mInterval = interval;
 
72
            }
 
73
        }
 
74
 
 
75
#ifdef USE_AKONADI
 
76
        void set(const KCalCore::Duration& interval)
 
77
#else
 
78
        void set(const KCal::Duration& interval)
 
79
#endif
 
80
        {
 
81
            if (mCount)
 
82
            {
 
83
                mInterval = interval;
 
84
                if (!interval)
 
85
                    mCount = 0;
 
86
            }
 
87
        }
 
88
 
 
89
        operator bool() const                       { return mCount; }
 
90
        bool operator!() const                      { return !mCount; }
 
91
        bool operator==(const Repetition& r) const  { return mInterval == r.mInterval && mCount == r.mCount; }
 
92
        bool operator!=(const Repetition& r) const  { return mInterval != r.mInterval || mCount != r.mCount; }
 
93
 
 
94
        /** Return the number of repetitions. */
 
95
        int count() const     { return mCount; }
 
96
 
 
97
#ifdef USE_AKONADI
 
98
        /** Return the interval between repetitions. */
 
99
        const KCalCore::Duration& interval() const  { return mInterval; }
 
100
 
 
101
        /** Return the overall duration of the repetition. */
 
102
        KCalCore::Duration duration() const  { return mInterval * mCount; }
 
103
 
 
104
        /** Return the overall duration of a specified number of repetitions.
 
105
         *  @param count the number of repetitions to find the duration of.
 
106
         */
 
107
        KCalCore::Duration duration(int count) const  { return mInterval * count; }
 
108
#else
 
109
        /** Return the interval between repetitions. */
 
110
        const KCal::Duration& interval() const  { return mInterval; }
 
111
 
 
112
        /** Return the overall duration of the repetition. */
 
113
        KCal::Duration duration() const  { return mInterval * mCount; }
 
114
 
 
115
        /** Return the overall duration of a specified number of repetitions.
 
116
         *  @param count the number of repetitions to find the duration of.
 
117
         */
 
118
        KCal::Duration duration(int count) const  { return mInterval * count; }
 
119
#endif
 
120
 
 
121
        /** Check whether the repetition interval is in terms of days (as opposed to minutes). */
 
122
        bool isDaily() const          { return mInterval.isDaily(); }
 
123
 
 
124
        /** Return the repetition interval in terms of days.
 
125
         *  If necessary, the interval is rounded down to a whole number of days.
 
126
         */
 
127
        int intervalDays() const      { return mInterval.asDays(); }
 
128
 
 
129
        /** Return the repetition interval in terms of minutes.
 
130
         *  If necessary, the interval is rounded down to a whole number of minutes.
 
131
         */
 
132
        int intervalMinutes() const   { return mInterval.asSeconds() / 60; }
 
133
 
 
134
        /** Return the repetition interval in terms of seconds. */
 
135
        int intervalSeconds() const   { return mInterval.asSeconds(); }
 
136
 
 
137
        /** Find the repetition count for the next repetition after a specified time.
 
138
         *  @param from         repetition start time, which should not be a date-only value
 
139
         *  @param preDateTime  time after which the desired repetition occurs
 
140
         */
 
141
        int nextRepeatCount(const KDateTime& from, const KDateTime& preDateTime) const
 
142
        {
 
143
            return mInterval.isDaily()
 
144
                 ? from.daysTo(preDateTime) / mInterval.asDays() + 1
 
145
                 : static_cast<int>(from.secsTo_long(preDateTime) / mInterval.asSeconds()) + 1;
 
146
        }
 
147
 
 
148
        /** Find the repetition count for the last repetition before a specified time.
 
149
         *  @param from           repetition start time, which should not be a date-only value
 
150
         *  @param afterDateTime  time after which the desired repetition occurs
 
151
         */
 
152
        int previousRepeatCount(const KDateTime& from, const KDateTime& afterDateTime) const
 
153
        {
 
154
            return mInterval.isDaily()
 
155
                 ? from.daysTo(afterDateTime.addSecs(-1)) / mInterval.asDays()
 
156
                 : static_cast<int>((from.secsTo_long(afterDateTime) - 1) / mInterval.asSeconds());
 
157
        }
129
158
 
130
159
    private:
131
 
        KCal::Duration mInterval;   // sub-repetition interval
132
 
        int            mCount;      // sub-repetition count (excluding the first time)
 
160
#ifdef USE_AKONADI
 
161
        KCalCore::Duration mInterval;   // sub-repetition interval
 
162
#else
 
163
        KCal::Duration mInterval;   // sub-repetition interval
 
164
#endif
 
165
        int            mCount;      // sub-repetition count (excluding the first time)
133
166
};
134
167
 
135
168
#endif // REPETITION_H
 
169
 
 
170
// vim: et sw=4: