-rw-r--r-- | library/backend/event.h | 173 |
1 files changed, 157 insertions, 16 deletions
diff --git a/library/backend/event.h b/library/backend/event.h index 277aadd..7fe41a5 100644 --- a/library/backend/event.h +++ b/library/backend/event.h | |||
@@ -1,7 +1,7 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2001 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
@@ -23,22 +23,31 @@ | |||
23 | 23 | ||
24 | #include <qdatetime.h> | 24 | #include <qdatetime.h> |
25 | #include <qvaluelist.h> | 25 | #include <qvaluelist.h> |
26 | #include <qcolor.h> | ||
26 | 27 | ||
27 | #ifdef PALMTOPCENTER | 28 | #ifdef PALMTOPCENTER |
28 | #include <qpc/qsorter.h> | 29 | #include <qpc/qsorter.h> |
29 | #endif | 30 | #endif |
30 | #include <qpe/palmtoprecord.h> | 31 | #include <qtopia/private/palmtoprecord.h> |
31 | 32 | ||
32 | #include <qpe/timeconversion.h> | 33 | #include <qpe/timeconversion.h> |
33 | 34 | ||
35 | static const QColor colorNormal = QColor(255, 0 , 0 ); | ||
36 | static const QColor colorRepeat = QColor(0 , 0 , 255); | ||
37 | static const QColor colorNormalLight = QColor(255, 220, 220); | ||
38 | static const QColor colorRepeatLight = QColor(200, 200, 255); | ||
39 | |||
34 | class EventPrivate; | 40 | class EventPrivate; |
35 | class QPC_EXPORT Event : public Qtopia::Record | 41 | class QPC_EXPORT Event : public Qtopia::Record |
36 | { | 42 | { |
37 | public: | 43 | public: |
38 | enum RepeatType { NoRepeat = -1, Daily, Weekly, MonthlyDay, | 44 | enum RepeatType { NoRepeat = -1, Daily, Weekly, MonthlyDay, |
39 | MonthlyDate, Yearly }; | 45 | MonthlyDate, Yearly }; |
46 | |||
47 | // Don't use this. | ||
40 | enum Days { MON = 0x01, TUE = 0x02, WED = 0x04, THU = 0x08, | 48 | enum Days { MON = 0x01, TUE = 0x02, WED = 0x04, THU = 0x08, |
41 | FRI = 0x10, SAT = 0x20, SUN = 0x40 }; | 49 | FRI = 0x10, SAT = 0x20, SUN = 0x40 }; |
50 | // Don't use this. | ||
42 | struct QPC_EXPORT RepeatPattern | 51 | struct QPC_EXPORT RepeatPattern |
43 | { | 52 | { |
44 | RepeatPattern() { | 53 | RepeatPattern() { |
@@ -70,6 +79,7 @@ public: | |||
70 | enum Type { Normal, AllDay }; | 79 | enum Type { Normal, AllDay }; |
71 | enum SoundTypeChoice { Silent, Loud }; | 80 | enum SoundTypeChoice { Silent, Loud }; |
72 | 81 | ||
82 | // Don't use these, there are essentially meaningless. | ||
73 | bool operator<( const Event &e1) const { return start() < e1.start(); }; | 83 | bool operator<( const Event &e1) const { return start() < e1.start(); }; |
74 | bool operator<=( const Event &e1 ) const { return start() <= e1.start(); }; | 84 | bool operator<=( const Event &e1 ) const { return start() <= e1.start(); }; |
75 | bool operator!=( const Event &e1 ) const { return !( *this == e1 ); }; | 85 | bool operator!=( const Event &e1 ) const { return !( *this == e1 ); }; |
@@ -83,34 +93,63 @@ public: | |||
83 | void setLocation( const QString &s ); | 93 | void setLocation( const QString &s ); |
84 | const QString &location() const; | 94 | const QString &location() const; |
85 | 95 | ||
86 | void setType( Type t ); | 96 | void setNotes( const QString &n ); |
87 | Type type() const; | 97 | const QString ¬es() const; |
98 | |||
99 | void setType( Type t ); // Don't use me. | ||
100 | Type type() const; // Don't use me. | ||
101 | |||
102 | void setAllDay(bool); | ||
103 | bool isAllDay() const; | ||
104 | |||
88 | void setStart( const QDateTime &d ); | 105 | void setStart( const QDateTime &d ); |
89 | void setStart( time_t time ); | 106 | void setStart( time_t time ); // don't use me. |
90 | QDateTime start( bool actual = FALSE ) const; | 107 | QDateTime start( ) const; |
91 | time_t startTime() const { return startUTC; } | 108 | QDateTime start( bool actual ) const; // don't use me. |
109 | time_t startTime() const { return startUTC; } // don't use me. | ||
92 | void setEnd( const QDateTime &e ); | 110 | void setEnd( const QDateTime &e ); |
93 | void setEnd( time_t time ); | 111 | void setEnd( time_t time ); // don't use me |
94 | QDateTime end( bool actual = FALSE ) const; | 112 | QDateTime end( ) const; |
95 | time_t endTime() const { return endUTC; } | 113 | QDateTime end( bool actual ) const; // don't use me. |
114 | time_t endTime() const { return endUTC; } // don't use me. | ||
96 | void setTimeZone( const QString & ); | 115 | void setTimeZone( const QString & ); |
97 | const QString &timeZone() const; | 116 | const QString &timeZone() const; |
98 | void setAlarm( bool b, int minutes, SoundTypeChoice ); | 117 | void setAlarm( int minutes, SoundTypeChoice ); |
118 | void clearAlarm(); | ||
119 | void setAlarm( bool b, int minutes, SoundTypeChoice ); // Don't use me. | ||
99 | bool hasAlarm() const; | 120 | bool hasAlarm() const; |
100 | int alarmTime() const; | 121 | int alarmDelay() const; |
122 | int alarmTime() const; // Don't use me. | ||
101 | SoundTypeChoice alarmSound() const; | 123 | SoundTypeChoice alarmSound() const; |
124 | |||
125 | RepeatType repeatType() const; | ||
126 | int frequency() const; | ||
127 | int weekOffset() const; | ||
128 | QDate repeatTill() const; | ||
129 | bool repeatForever() const; | ||
130 | bool repeatOnWeekDay(int day) const; | ||
131 | |||
132 | void setRepeatType(RepeatType); | ||
133 | void setFrequency(int); | ||
134 | void setRepeatTill(const QDate &); | ||
135 | void setRepeatForever(bool); | ||
136 | void setRepeatOnWeekDay(int day, bool enable); | ||
137 | |||
138 | // Don't use any of these. | ||
102 | void setRepeat( bool b, const RepeatPattern &p ); | 139 | void setRepeat( bool b, const RepeatPattern &p ); |
103 | void setRepeat( const RepeatPattern &p ); | 140 | void setRepeat( const RepeatPattern &p ); |
104 | bool hasRepeat() const; | 141 | bool hasRepeat() const; |
105 | const RepeatPattern &repeatPattern() const; | 142 | const RepeatPattern &repeatPattern() const; |
106 | RepeatPattern &repeatPattern(); | 143 | RepeatPattern &repeatPattern(); |
107 | void setNotes( const QString &n ); | ||
108 | const QString ¬es() const; | ||
109 | bool doRepeat() const { return pattern.type != NoRepeat; } | 144 | bool doRepeat() const { return pattern.type != NoRepeat; } |
110 | 145 | ||
111 | void save( QString& buf ); | 146 | void save( QString& buf ); |
112 | //void load( Node *n ); | 147 | //void load( Node *n ); |
113 | 148 | ||
149 | bool match( const QRegExp &r ) const; | ||
150 | |||
151 | // Don't use these either. Functionality will be moved elsewhere. | ||
152 | |||
114 | // helper function to calculate the week of the given date | 153 | // helper function to calculate the week of the given date |
115 | static int week( const QDate& date ); | 154 | static int week( const QDate& date ); |
116 | // calculates the number of occurrences of the week day of | 155 | // calculates the number of occurrences of the week day of |
@@ -123,7 +162,6 @@ public: | |||
123 | static int dayOfWeek( char day ); | 162 | static int dayOfWeek( char day ); |
124 | // returns the difference of months from first to second. | 163 | // returns the difference of months from first to second. |
125 | static int monthDiff( const QDate& first, const QDate& second ); | 164 | static int monthDiff( const QDate& first, const QDate& second ); |
126 | bool match( const QRegExp &r ) const; | ||
127 | 165 | ||
128 | private: | 166 | private: |
129 | Qtopia::UidGen &uidGen() { return sUidGen; } | 167 | Qtopia::UidGen &uidGen() { return sUidGen; } |
@@ -211,6 +249,109 @@ private: | |||
211 | 249 | ||
212 | }; | 250 | }; |
213 | 251 | ||
252 | inline void Event::setAlarm( int minutes, SoundTypeChoice s ) | ||
253 | { | ||
254 | setAlarm(TRUE, minutes, s); | ||
255 | } | ||
256 | |||
257 | inline void Event::clearAlarm() | ||
258 | { | ||
259 | setAlarm(FALSE, 0, Silent); | ||
260 | } | ||
261 | |||
262 | inline int Event::alarmDelay() const | ||
263 | { | ||
264 | return alarmTime(); | ||
265 | } | ||
266 | |||
267 | inline void Event::setAllDay(bool enable) | ||
268 | { | ||
269 | if (enable) | ||
270 | setType(AllDay); | ||
271 | else | ||
272 | setType(Normal); | ||
273 | }; | ||
274 | |||
275 | inline bool Event::isAllDay() const | ||
276 | { | ||
277 | return type() == AllDay; | ||
278 | } | ||
279 | |||
280 | inline Event::RepeatType Event::repeatType() const | ||
281 | { | ||
282 | return repeatPattern().type; | ||
283 | } | ||
284 | |||
285 | inline int Event::frequency() const | ||
286 | { | ||
287 | return repeatPattern().frequency; | ||
288 | } | ||
289 | |||
290 | inline int Event::weekOffset() const | ||
291 | { | ||
292 | if (start().date().day() == 1) | ||
293 | return 1; | ||
294 | return (start().date().day() - 1) / 7 + 1; | ||
295 | } | ||
296 | |||
297 | inline QDate Event::repeatTill() const | ||
298 | { | ||
299 | return repeatPattern().endDate(); | ||
300 | } | ||
301 | |||
302 | inline bool Event::repeatForever() const | ||
303 | { | ||
304 | return !repeatPattern().hasEndDate; | ||
305 | } | ||
306 | |||
307 | inline void Event::setRepeatType(RepeatType t) | ||
308 | { | ||
309 | pattern.type = t; | ||
310 | } | ||
311 | |||
312 | inline void Event::setFrequency(int f) | ||
313 | { | ||
314 | pattern.frequency = f; | ||
315 | } | ||
316 | |||
317 | inline void Event::setRepeatTill(const QDate &d) | ||
318 | { | ||
319 | pattern.setEndDate(d); | ||
320 | pattern.hasEndDate = TRUE; | ||
321 | } | ||
322 | |||
323 | inline void Event::setRepeatForever(bool b) | ||
324 | { | ||
325 | if (!b == pattern.hasEndDate) | ||
326 | return; | ||
327 | if (!b && !pattern.hasEndDate) | ||
328 | pattern.setEndDate(end().date()); | ||
329 | pattern.hasEndDate = !b; | ||
330 | } | ||
331 | |||
332 | inline bool Event::repeatOnWeekDay(int day) const | ||
333 | { | ||
334 | if (pattern.type != Weekly) | ||
335 | return FALSE; | ||
336 | return ( (1 << (day - 1)) & pattern.days ) != 0; | ||
337 | } | ||
338 | |||
339 | inline void Event::setRepeatOnWeekDay(int day, bool enable) | ||
340 | { | ||
341 | if ( repeatOnWeekDay( day ) != enable ) | ||
342 | pattern.days ^= 1 << (day - 1); | ||
343 | } | ||
344 | |||
345 | inline QDateTime Event::start( ) const | ||
346 | { | ||
347 | return start(FALSE); | ||
348 | } | ||
349 | |||
350 | inline QDateTime Event::end( ) const | ||
351 | { | ||
352 | return end(FALSE); | ||
353 | } | ||
354 | |||
214 | #ifdef PALMTOPCENTER | 355 | #ifdef PALMTOPCENTER |
215 | class QPC_EXPORT EffectiveEventSizeSorter : public QSorter<EffectiveEvent> | 356 | class QPC_EXPORT EffectiveEventSizeSorter : public QSorter<EffectiveEvent> |
216 | { | 357 | { |