summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--library/backend/event.h17
1 files changed, 2 insertions, 15 deletions
diff --git a/library/backend/event.h b/library/backend/event.h
index 4610d85..118523f 100644
--- a/library/backend/event.h
+++ b/library/backend/event.h
@@ -1,375 +1,362 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the 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#include <qcolor.h>
27 27
28#ifdef PALMTOPCENTER 28#ifdef PALMTOPCENTER
29#include <qpc/qsorter.h> 29#include <qpc/qsorter.h>
30#endif 30#endif
31#include <qtopia/private/palmtoprecord.h> 31#include <qtopia/private/palmtoprecord.h>
32 32
33#include <qpe/timeconversion.h> 33#include <qpe/timeconversion.h>
34 34
35static const QColor colorNormal = QColor(255, 0 , 0 ); 35static const QColor colorNormal = QColor(255, 0 , 0 );
36static const QColor colorRepeat = QColor(0 , 0 , 255); 36static const QColor colorRepeat = QColor(0 , 0 , 255);
37static const QColor colorNormalLight = QColor(255, 220, 220); 37static const QColor colorNormalLight = QColor(255, 220, 220);
38static const QColor colorRepeatLight = QColor(200, 200, 255); 38static const QColor colorRepeatLight = QColor(200, 200, 255);
39 39
40class EventPrivate; 40class EventPrivate;
41class QPC_EXPORT Event : public Qtopia::Record 41class QPC_EXPORT Event : public Qtopia::Record
42{ 42{
43public: 43public:
44 enum RepeatType { NoRepeat = -1, Daily, Weekly, MonthlyDay, 44 enum RepeatType { NoRepeat = -1, Daily, Weekly, MonthlyDay,
45 MonthlyDate, Yearly }; 45 MonthlyDate, Yearly };
46 46
47 // Don't use this. 47 // Don't use this.
48 enum Days { MON = 0x01, TUE = 0x02, WED = 0x04, THU = 0x08, 48 enum Days { MON = 0x01, TUE = 0x02, WED = 0x04, THU = 0x08,
49 FRI = 0x10, SAT = 0x20, SUN = 0x40 }; 49 FRI = 0x10, SAT = 0x20, SUN = 0x40 };
50 // Don't use this. 50 // Don't use this.
51 struct QPC_EXPORT RepeatPattern 51 struct QPC_EXPORT RepeatPattern
52 { 52 {
53 RepeatPattern() { 53 RepeatPattern() {
54 type = NoRepeat; frequency = -1; days = 0; position = 0; createTime = -1; 54 type = NoRepeat; frequency = -1; days = 0; position = 0; createTime = -1;
55 hasEndDate = FALSE; endDateUTC = 0; } 55 hasEndDate = FALSE; endDateUTC = 0; }
56 bool operator ==( const RepeatPattern &right ) const; 56 bool operator ==( const RepeatPattern &right ) const;
57 57
58 RepeatType type; 58 RepeatType type;
59 int frequency; 59 int frequency;
60 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...
61 char days; // a mask for days OR in your days! 61 char days; // a mask for days OR in your days!
62 bool hasEndDate; 62 bool hasEndDate;
63 QDate endDate() const { return TimeConversion::fromUTC( endDateUTC ).date(); } 63 QDate endDate() const { return TimeConversion::fromUTC( endDateUTC ).date(); }
64 void setEndDate( const QDate &dt ) { endDateUTC = TimeConversion::toUTC( dt ); } 64 void setEndDate( const QDate &dt ) { endDateUTC = TimeConversion::toUTC( dt ); }
65 time_t endDateUTC; 65 time_t endDateUTC;
66 time_t createTime; 66 time_t createTime;
67 }; 67 };
68 68
69 Event(); 69 Event();
70 Event( const QMap<int, QString > & map ); 70 Event( const QMap<int, QString > & map );
71 virtual ~Event(); 71 virtual ~Event();
72 72
73 QMap<int, QString> toMap() const; 73 QMap<int, QString> toMap() const;
74 74
75 static void writeVCalendar( const QString &filename, const QValueList<Event> &events); 75 static void writeVCalendar( const QString &filename, const QValueList<Event> &events);
76 static void writeVCalendar( const QString &filename, const Event &event); 76 static void writeVCalendar( const QString &filename, const Event &event);
77 static QValueList<Event> readVCalendar( const QString &filename ); 77 static QValueList<Event> readVCalendar( const QString &filename );
78 78
79 enum Type { Normal, AllDay }; 79 enum Type { Normal, AllDay };
80 enum SoundTypeChoice { Silent, Loud }; 80 enum SoundTypeChoice { Silent, Loud };
81 81
82 // Don't use these, there are essentially meaningless. 82 // Don't use these, there are essentially meaningless.
83 bool operator<( const Event &e1) const { return start() < e1.start(); }; 83 bool operator<( const Event &e1) const { return start() < e1.start(); };
84 bool operator<=( const Event &e1 ) const { return start() <= e1.start(); }; 84 bool operator<=( const Event &e1 ) const { return start() <= e1.start(); };
85 bool operator!=( const Event &e1 ) const { return !( *this == e1 ); }; 85 bool operator!=( const Event &e1 ) const { return !( *this == e1 ); };
86 bool operator>( const Event &e1 ) const { return start() > e1.start(); }; 86 bool operator>( const Event &e1 ) const { return start() > e1.start(); };
87 bool operator>=(const Event &e1 ) const { return start() >= e1.start(); }; 87 bool operator>=(const Event &e1 ) const { return start() >= e1.start(); };
88 bool operator==( const Event &e ) const; 88 bool operator==( const Event &e ) const;
89 89
90 void setDescription( const QString &s ); 90 void setDescription( const QString &s );
91 const QString &description() const; 91 const QString &description() const;
92 92
93 void setLocation( const QString &s ); 93 void setLocation( const QString &s );
94 const QString &location() const; 94 const QString &location() const;
95 95
96 void setNotes( const QString &n ); 96 void setNotes( const QString &n );
97 const QString &notes() const; 97 const QString &notes() const;
98 98
99 void setType( Type t ); // Don't use me. 99 void setType( Type t ); // Don't use me.
100 Type type() const; // Don't use me. 100 Type type() const; // Don't use me.
101 101
102 void setAllDay(bool); 102 void setAllDay(bool);
103 bool isAllDay() const; 103 bool isAllDay() const;
104 104
105 void setStart( const QDateTime &d ); 105 void setStart( const QDateTime &d );
106 void setStart( time_t time ); // don't use me. 106 void setStart( time_t time ); // don't use me.
107 QDateTime start( ) const; 107 QDateTime start( bool actual = FALSE) const; // don't use me.
108 QDateTime start( bool actual ) const; // don't use me.
109 time_t startTime() const { return startUTC; } // don't use me. 108 time_t startTime() const { return startUTC; } // don't use me.
110 void setEnd( const QDateTime &e ); 109 void setEnd( const QDateTime &e );
111 void setEnd( time_t time ); // don't use me 110 void setEnd( time_t time ); // don't use me
112 QDateTime end( ) const; 111 QDateTime end( bool actual = FALSE ) const; // don't use me.
113 QDateTime end( bool actual ) const; // don't use me.
114 time_t endTime() const { return endUTC; } // don't use me. 112 time_t endTime() const { return endUTC; } // don't use me.
115 void setTimeZone( const QString & ); 113 void setTimeZone( const QString & );
116 const QString &timeZone() const; 114 const QString &timeZone() const;
117 void setAlarm( int minutes, SoundTypeChoice ); 115 void setAlarm( int minutes, SoundTypeChoice );
118 void clearAlarm(); 116 void clearAlarm();
119 void setAlarm( bool b, int minutes, SoundTypeChoice ); // Don't use me. 117 void setAlarm( bool b, int minutes, SoundTypeChoice ); // Don't use me.
120 bool hasAlarm() const; 118 bool hasAlarm() const;
121 int alarmDelay() const; 119 int alarmDelay() const;
122 int alarmTime() const; // Don't use me. 120 int alarmTime() const; // Don't use me.
123 SoundTypeChoice alarmSound() const; 121 SoundTypeChoice alarmSound() const;
124 122
125 RepeatType repeatType() const; 123 RepeatType repeatType() const;
126 int frequency() const; 124 int frequency() const;
127 int weekOffset() const; 125 int weekOffset() const;
128 QDate repeatTill() const; 126 QDate repeatTill() const;
129 bool repeatForever() const; 127 bool repeatForever() const;
130 bool repeatOnWeekDay(int day) const; 128 bool repeatOnWeekDay(int day) const;
131 129
132 void setRepeatType(RepeatType); 130 void setRepeatType(RepeatType);
133 void setFrequency(int); 131 void setFrequency(int);
134 void setRepeatTill(const QDate &); 132 void setRepeatTill(const QDate &);
135 void setRepeatForever(bool); 133 void setRepeatForever(bool);
136 void setRepeatOnWeekDay(int day, bool enable); 134 void setRepeatOnWeekDay(int day, bool enable);
137 135
138 // Don't use any of these. 136 // Don't use any of these.
139 void setRepeat( bool b, const RepeatPattern &p ); 137 void setRepeat( bool b, const RepeatPattern &p );
140 void setRepeat( const RepeatPattern &p ); 138 void setRepeat( const RepeatPattern &p );
141 bool hasRepeat() const; 139 bool hasRepeat() const;
142 const RepeatPattern &repeatPattern() const; 140 const RepeatPattern &repeatPattern() const;
143 RepeatPattern &repeatPattern(); 141 RepeatPattern &repeatPattern();
144 bool doRepeat() const { return pattern.type != NoRepeat; } 142 bool doRepeat() const { return pattern.type != NoRepeat; }
145 143
146 void save( QString& buf ); 144 void save( QString& buf );
147 //void load( Node *n ); 145 //void load( Node *n );
148 146
149 bool match( const QRegExp &r ) const; 147 bool match( const QRegExp &r ) const;
150 148
151 // Don't use these either. Functionality will be moved elsewhere. 149 // Don't use these either. Functionality will be moved elsewhere.
152 150
153 // helper function to calculate the week of the given date 151 // helper function to calculate the week of the given date
154 static int week( const QDate& date ); 152 static int week( const QDate& date );
155 // calculates the number of occurrences of the week day of 153 // calculates the number of occurrences of the week day of
156 // the given date from the start of the month 154 // the given date from the start of the month
157 static int occurrence( const QDate& date ); 155 static int occurrence( const QDate& date );
158 // returns a proper days-char for a given dayOfWeek() 156 // returns a proper days-char for a given dayOfWeek()
159 static char day( int dayOfWeek ) { return 1 << ( dayOfWeek - 1 ); } 157 static char day( int dayOfWeek ) { return 1 << ( dayOfWeek - 1 ); }
160 // returns the dayOfWeek for the *first* day it finds (ignores 158 // returns the dayOfWeek for the *first* day it finds (ignores
161 // any further days!). Returns 1 (Monday) if there isn't any day found 159 // any further days!). Returns 1 (Monday) if there isn't any day found
162 static int dayOfWeek( char day ); 160 static int dayOfWeek( char day );
163 // returns the difference of months from first to second. 161 // returns the difference of months from first to second.
164 static int monthDiff( const QDate& first, const QDate& second ); 162 static int monthDiff( const QDate& first, const QDate& second );
165 163
166private: 164private:
167 Qtopia::UidGen &uidGen() { return sUidGen; } 165 Qtopia::UidGen &uidGen() { return sUidGen; }
168 static Qtopia::UidGen sUidGen; 166 static Qtopia::UidGen sUidGen;
169 167
170 QString descript, locat, categ; 168 QString descript, locat, categ;
171 Type typ : 4; 169 Type typ : 4;
172 bool startTimeDirty : 1; 170 bool startTimeDirty : 1;
173 bool endTimeDirty : 1; 171 bool endTimeDirty : 1;
174 time_t startUTC, endUTC; 172 time_t startUTC, endUTC;
175 QString tz; 173 QString tz;
176 bool hAlarm, hRepeat; 174 bool hAlarm, hRepeat;
177 int aMinutes; 175 int aMinutes;
178 SoundTypeChoice aSound; 176 SoundTypeChoice aSound;
179 RepeatPattern pattern; 177 RepeatPattern pattern;
180 QString note; 178 QString note;
181 // ADDITION 179 // ADDITION
182 int mRid;// Recode ID 180 int mRid;// Recode ID
183 int mRinfo;// Recode Info 181 int mRinfo;// Recode Info
184 // 182 //
185 EventPrivate *d; 183 EventPrivate *d;
186 184
187}; 185};
188 186
189// Since an event spans multiple day, it is better to have this 187// Since an event spans multiple day, it is better to have this
190// class to represent a day instead of creating many 188// class to represent a day instead of creating many
191// dummy events... 189// dummy events...
192 190
193class EffectiveEventPrivate; 191class EffectiveEventPrivate;
194class QPC_EXPORT EffectiveEvent 192class QPC_EXPORT EffectiveEvent
195{ 193{
196public: 194public:
197 // If we calculate the effective event of a multi-day event 195 // If we calculate the effective event of a multi-day event
198 // we have to figure out whether we are at the first day, 196 // we have to figure out whether we are at the first day,
199 // at the end, or anywhere else ("middle"). This is important 197 // at the end, or anywhere else ("middle"). This is important
200 // for the start/end times (00:00/23:59) 198 // for the start/end times (00:00/23:59)
201 // MidWay: 00:00 -> 23:59, as we are "in the middle" of a multi- 199 // MidWay: 00:00 -> 23:59, as we are "in the middle" of a multi-
202 // day event 200 // day event
203 // Start: start time -> 23:59 201 // Start: start time -> 23:59
204 // End: 00:00 -> end time 202 // End: 00:00 -> end time
205 // Start | End == StartEnd: for single-day events (default) 203 // Start | End == StartEnd: for single-day events (default)
206 // here we draw start time -> end time 204 // here we draw start time -> end time
207 enum Position { MidWay = 0, Start = 1, End = 2, StartEnd = 3 }; 205 enum Position { MidWay = 0, Start = 1, End = 2, StartEnd = 3 };
208 206
209 EffectiveEvent(); 207 EffectiveEvent();
210 EffectiveEvent( const Event &event, const QDate &startDate, Position pos = StartEnd ); 208 EffectiveEvent( const Event &event, const QDate &startDate, Position pos = StartEnd );
211 EffectiveEvent( const EffectiveEvent & ); 209 EffectiveEvent( const EffectiveEvent & );
212 EffectiveEvent& operator=( const EffectiveEvent & ); 210 EffectiveEvent& operator=( const EffectiveEvent & );
213 ~EffectiveEvent(); 211 ~EffectiveEvent();
214 212
215 213
216 bool operator<( const EffectiveEvent &e ) const; 214 bool operator<( const EffectiveEvent &e ) const;
217 bool operator<=( const EffectiveEvent &e ) const; 215 bool operator<=( const EffectiveEvent &e ) const;
218 bool operator==( const EffectiveEvent &e ) const; 216 bool operator==( const EffectiveEvent &e ) const;
219 bool operator!=( const EffectiveEvent &e ) const; 217 bool operator!=( const EffectiveEvent &e ) const;
220 bool operator>( const EffectiveEvent &e ) const; 218 bool operator>( const EffectiveEvent &e ) const;
221 bool operator>= ( const EffectiveEvent &e ) const; 219 bool operator>= ( const EffectiveEvent &e ) const;
222 220
223 void setStart( const QTime &start ); 221 void setStart( const QTime &start );
224 void setEnd( const QTime &end ); 222 void setEnd( const QTime &end );
225 void setEvent( Event e ); 223 void setEvent( Event e );
226 void setDate( const QDate &date ); 224 void setDate( const QDate &date );
227 void setEffectiveDates( const QDate &from, const QDate &to ); 225 void setEffectiveDates( const QDate &from, const QDate &to );
228 226
229 // QString category() const; 227 // QString category() const;
230 const QString &description() const; 228 const QString &description() const;
231 const QString &location() const; 229 const QString &location() const;
232 const QString &notes() const; 230 const QString &notes() const;
233 const Event &event() const; 231 const Event &event() const;
234 const QTime &start() const; 232 const QTime &start() const;
235 const QTime &end() const; 233 const QTime &end() const;
236 const QDate &date() const; 234 const QDate &date() const;
237 int length() const; 235 int length() const;
238 int size() const; 236 int size() const;
239 237
240 QDate startDate() const; 238 QDate startDate() const;
241 QDate endDate() const; 239 QDate endDate() const;
242 240
243private: 241private:
244 class EffectiveEventPrivate *d; 242 class EffectiveEventPrivate *d;
245 Event mEvent; 243 Event mEvent;
246 QDate mDate; 244 QDate mDate;
247 QTime mStart, 245 QTime mStart,
248 mEnd; 246 mEnd;
249 247
250}; 248};
251 249
252inline void Event::setAlarm( int minutes, SoundTypeChoice s ) 250inline void Event::setAlarm( int minutes, SoundTypeChoice s )
253{ 251{
254 setAlarm(TRUE, minutes, s); 252 setAlarm(TRUE, minutes, s);
255} 253}
256 254
257inline void Event::clearAlarm() 255inline void Event::clearAlarm()
258{ 256{
259 setAlarm(FALSE, 0, Silent); 257 setAlarm(FALSE, 0, Silent);
260} 258}
261 259
262inline int Event::alarmDelay() const 260inline int Event::alarmDelay() const
263{ 261{
264 return alarmTime(); 262 return alarmTime();
265} 263}
266 264
267inline void Event::setAllDay(bool enable) 265inline void Event::setAllDay(bool enable)
268{ 266{
269 if (enable) 267 if (enable)
270 setType(AllDay); 268 setType(AllDay);
271 else 269 else
272 setType(Normal); 270 setType(Normal);
273}; 271};
274 272
275inline bool Event::isAllDay() const 273inline bool Event::isAllDay() const
276{ 274{
277 return type() == AllDay; 275 return type() == AllDay;
278} 276}
279 277
280inline Event::RepeatType Event::repeatType() const 278inline Event::RepeatType Event::repeatType() const
281{ 279{
282 return repeatPattern().type; 280 return repeatPattern().type;
283} 281}
284 282
285inline int Event::frequency() const 283inline int Event::frequency() const
286{ 284{
287 return repeatPattern().frequency; 285 return repeatPattern().frequency;
288} 286}
289 287
290inline int Event::weekOffset() const 288inline int Event::weekOffset() const
291{ 289{
292 if (start().date().day() == 1) 290 if (start().date().day() == 1)
293 return 1; 291 return 1;
294 return (start().date().day() - 1) / 7 + 1; 292 return (start().date().day() - 1) / 7 + 1;
295} 293}
296 294
297inline QDate Event::repeatTill() const 295inline QDate Event::repeatTill() const
298{ 296{
299 return repeatPattern().endDate(); 297 return repeatPattern().endDate();
300} 298}
301 299
302inline bool Event::repeatForever() const 300inline bool Event::repeatForever() const
303{ 301{
304 return !repeatPattern().hasEndDate; 302 return !repeatPattern().hasEndDate;
305} 303}
306 304
307inline void Event::setRepeatType(RepeatType t) 305inline void Event::setRepeatType(RepeatType t)
308{ 306{
309 pattern.type = t; 307 pattern.type = t;
310} 308}
311 309
312inline void Event::setFrequency(int f) 310inline void Event::setFrequency(int f)
313{ 311{
314 pattern.frequency = f; 312 pattern.frequency = f;
315} 313}
316 314
317inline void Event::setRepeatTill(const QDate &d) 315inline void Event::setRepeatTill(const QDate &d)
318{ 316{
319 pattern.setEndDate(d); 317 pattern.setEndDate(d);
320 pattern.hasEndDate = TRUE; 318 pattern.hasEndDate = TRUE;
321} 319}
322 320
323inline void Event::setRepeatForever(bool b) 321inline void Event::setRepeatForever(bool b)
324{ 322{
325 if (!b == pattern.hasEndDate) 323 if (!b == pattern.hasEndDate)
326 return; 324 return;
327 if (!b && !pattern.hasEndDate) 325 if (!b && !pattern.hasEndDate)
328 pattern.setEndDate(end().date()); 326 pattern.setEndDate(end().date());
329 pattern.hasEndDate = !b; 327 pattern.hasEndDate = !b;
330} 328}
331 329
332inline bool Event::repeatOnWeekDay(int day) const 330inline bool Event::repeatOnWeekDay(int day) const
333{ 331{
334 if (pattern.type != Weekly) 332 if (pattern.type != Weekly)
335 return FALSE; 333 return FALSE;
336 return ( (1 << (day - 1)) & pattern.days ) != 0; 334 return ( (1 << (day - 1)) & pattern.days ) != 0;
337} 335}
338 336
339inline void Event::setRepeatOnWeekDay(int day, bool enable) 337inline void Event::setRepeatOnWeekDay(int day, bool enable)
340{ 338{
341 if ( repeatOnWeekDay( day ) != enable ) 339 if ( repeatOnWeekDay( day ) != enable )
342 pattern.days ^= 1 << (day - 1); 340 pattern.days ^= 1 << (day - 1);
343} 341}
344
345inline QDateTime Event::start( ) const
346{
347 return start(FALSE);
348}
349
350inline QDateTime Event::end( ) const
351{
352 return end(FALSE);
353}
354
355#ifdef PALMTOPCENTER 342#ifdef PALMTOPCENTER
356class QPC_EXPORT EffectiveEventSizeSorter : public QSorter<EffectiveEvent> 343class QPC_EXPORT EffectiveEventSizeSorter : public QSorter<EffectiveEvent>
357{ 344{
358public: 345public:
359 int compare( const EffectiveEvent& a, const EffectiveEvent& b ) const 346 int compare( const EffectiveEvent& a, const EffectiveEvent& b ) const
360 { 347 {
361 return a.size() - b.size(); 348 return a.size() - b.size();
362 } 349 }
363}; 350};
364 351
365class QPC_EXPORT EffectiveEventTimeSorter : public QSorter<EffectiveEvent> 352class QPC_EXPORT EffectiveEventTimeSorter : public QSorter<EffectiveEvent>
366{ 353{
367public: 354public:
368 int compare( const EffectiveEvent& a, const EffectiveEvent& b ) const 355 int compare( const EffectiveEvent& a, const EffectiveEvent& b ) const
369 { 356 {
370 return a.start().secsTo( b.start() ); 357 return a.start().secsTo( b.start() );
371 } 358 }
372}; 359};
373#endif 360#endif
374 361
375#endif 362#endif