-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,53 +1,62 @@ | |||
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 |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #ifndef __EVENT_H__ | 21 | #ifndef __EVENT_H__ |
22 | #define __EVENT_H__ | 22 | #define __EVENT_H__ |
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() { |
45 | type = NoRepeat; frequency = -1; days = 0; position = 0; createTime = -1; | 54 | type = NoRepeat; frequency = -1; days = 0; position = 0; createTime = -1; |
46 | hasEndDate = FALSE; endDateUTC = 0; } | 55 | hasEndDate = FALSE; endDateUTC = 0; } |
47 | bool operator ==( const RepeatPattern &right ) const; | 56 | bool operator ==( const RepeatPattern &right ) const; |
48 | 57 | ||
49 | RepeatType type; | 58 | RepeatType type; |
50 | int frequency; | 59 | int frequency; |
51 | int position;// the posistion in the month (e.g. the first sunday, etc) positive, count from the front negative count from the end... | 60 | int position;// the posistion in the month (e.g. the first sunday, etc) positive, count from the front negative count from the end... |
52 | char days; // a mask for days OR in your days! | 61 | char days; // a mask for days OR in your days! |
53 | bool hasEndDate; | 62 | bool hasEndDate; |
@@ -61,78 +70,107 @@ public: | |||
61 | Event( const QMap<int, QString > & map ); | 70 | Event( const QMap<int, QString > & map ); |
62 | virtual ~Event(); | 71 | virtual ~Event(); |
63 | 72 | ||
64 | QMap<int, QString> toMap() const; | 73 | QMap<int, QString> toMap() const; |
65 | 74 | ||
66 | static void writeVCalendar( const QString &filename, const QValueList<Event> &events); | 75 | static void writeVCalendar( const QString &filename, const QValueList<Event> &events); |
67 | static void writeVCalendar( const QString &filename, const Event &event); | 76 | static void writeVCalendar( const QString &filename, const Event &event); |
68 | static QValueList<Event> readVCalendar( const QString &filename ); | 77 | static QValueList<Event> readVCalendar( const QString &filename ); |
69 | 78 | ||
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 ); }; |
76 | bool operator>( const Event &e1 ) const { return start() > e1.start(); }; | 86 | bool operator>( const Event &e1 ) const { return start() > e1.start(); }; |
77 | bool operator>=(const Event &e1 ) const { return start() >= e1.start(); }; | 87 | bool operator>=(const Event &e1 ) const { return start() >= e1.start(); }; |
78 | bool operator==( const Event &e ) const; | 88 | bool operator==( const Event &e ) const; |
79 | 89 | ||
80 | void setDescription( const QString &s ); | 90 | void setDescription( const QString &s ); |
81 | const QString &description() const; | 91 | const QString &description() const; |
82 | 92 | ||
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 |
117 | // the given date from the start of the month | 156 | // the given date from the start of the month |
118 | static int occurrence( const QDate& date ); | 157 | static int occurrence( const QDate& date ); |
119 | // returns a proper days-char for a given dayOfWeek() | 158 | // returns a proper days-char for a given dayOfWeek() |
120 | static char day( int dayOfWeek ) { return 1 << ( dayOfWeek - 1 ); } | 159 | static char day( int dayOfWeek ) { return 1 << ( dayOfWeek - 1 ); } |
121 | // returns the dayOfWeek for the *first* day it finds (ignores | 160 | // returns the dayOfWeek for the *first* day it finds (ignores |
122 | // any further days!). Returns 1 (Monday) if there isn't any day found | 161 | // any further days!). Returns 1 (Monday) if there isn't any day found |
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; } |
130 | static Qtopia::UidGen sUidGen; | 168 | static Qtopia::UidGen sUidGen; |
131 | 169 | ||
132 | QString descript, locat, categ; | 170 | QString descript, locat, categ; |
133 | Type typ : 4; | 171 | Type typ : 4; |
134 | bool startTimeDirty : 1; | 172 | bool startTimeDirty : 1; |
135 | bool endTimeDirty : 1; | 173 | bool endTimeDirty : 1; |
136 | time_t startUTC, endUTC; | 174 | time_t startUTC, endUTC; |
137 | QString tz; | 175 | QString tz; |
138 | bool hAlarm, hRepeat; | 176 | bool hAlarm, hRepeat; |
@@ -202,24 +240,127 @@ public: | |||
202 | QDate startDate() const; | 240 | QDate startDate() const; |
203 | QDate endDate() const; | 241 | QDate endDate() const; |
204 | 242 | ||
205 | private: | 243 | private: |
206 | class EffectiveEventPrivate *d; | 244 | class EffectiveEventPrivate *d; |
207 | Event mEvent; | 245 | Event mEvent; |
208 | QDate mDate; | 246 | QDate mDate; |
209 | QTime mStart, | 247 | QTime mStart, |
210 | mEnd; | 248 | mEnd; |
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 | { |
217 | public: | 358 | public: |
218 | int compare( const EffectiveEvent& a, const EffectiveEvent& b ) const | 359 | int compare( const EffectiveEvent& a, const EffectiveEvent& b ) const |
219 | { | 360 | { |
220 | return a.size() - b.size(); | 361 | return a.size() - b.size(); |
221 | } | 362 | } |
222 | }; | 363 | }; |
223 | 364 | ||
224 | class QPC_EXPORT EffectiveEventTimeSorter : public QSorter<EffectiveEvent> | 365 | class QPC_EXPORT EffectiveEventTimeSorter : public QSorter<EffectiveEvent> |
225 | { | 366 | { |