summaryrefslogtreecommitdiff
path: root/library/backend/event.h
Unidiff
Diffstat (limited to 'library/backend/event.h') (more/less context) (ignore whitespace changes)
-rw-r--r--library/backend/event.h173
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,10 +1,10 @@
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**
@@ -20,28 +20,37 @@
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
35static const QColor colorNormal = QColor(255, 0 , 0 );
36static const QColor colorRepeat = QColor(0 , 0 , 255);
37static const QColor colorNormalLight = QColor(255, 220, 220);
38static const QColor colorRepeatLight = QColor(200, 200, 255);
39
34class EventPrivate; 40class EventPrivate;
35class QPC_EXPORT Event : public Qtopia::Record 41class QPC_EXPORT Event : public Qtopia::Record
36{ 42{
37public: 43public:
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;
@@ -67,12 +76,13 @@ public:
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;
@@ -80,53 +90,81 @@ public:
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 &notes() 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 &notes() 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
128private: 166private:
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;
@@ -208,12 +246,115 @@ private:
208 QDate mDate; 246 QDate mDate;
209 QTime mStart, 247 QTime mStart,
210 mEnd; 248 mEnd;
211 249
212}; 250};
213 251
252inline void Event::setAlarm( int minutes, SoundTypeChoice s )
253{
254 setAlarm(TRUE, minutes, s);
255}
256
257inline void Event::clearAlarm()
258{
259 setAlarm(FALSE, 0, Silent);
260}
261
262inline int Event::alarmDelay() const
263{
264 return alarmTime();
265}
266
267inline void Event::setAllDay(bool enable)
268{
269 if (enable)
270 setType(AllDay);
271 else
272 setType(Normal);
273};
274
275inline bool Event::isAllDay() const
276{
277 return type() == AllDay;
278}
279
280inline Event::RepeatType Event::repeatType() const
281{
282 return repeatPattern().type;
283}
284
285inline int Event::frequency() const
286{
287 return repeatPattern().frequency;
288}
289
290inline int Event::weekOffset() const
291{
292 if (start().date().day() == 1)
293 return 1;
294 return (start().date().day() - 1) / 7 + 1;
295}
296
297inline QDate Event::repeatTill() const
298{
299 return repeatPattern().endDate();
300}
301
302inline bool Event::repeatForever() const
303{
304 return !repeatPattern().hasEndDate;
305}
306
307inline void Event::setRepeatType(RepeatType t)
308{
309 pattern.type = t;
310}
311
312inline void Event::setFrequency(int f)
313{
314 pattern.frequency = f;
315}
316
317inline void Event::setRepeatTill(const QDate &d)
318{
319 pattern.setEndDate(d);
320 pattern.hasEndDate = TRUE;
321}
322
323inline 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
332inline 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
339inline void Event::setRepeatOnWeekDay(int day, bool enable)
340{
341 if ( repeatOnWeekDay( day ) != enable )
342 pattern.days ^= 1 << (day - 1);
343}
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
214#ifdef PALMTOPCENTER 355#ifdef PALMTOPCENTER
215class QPC_EXPORT EffectiveEventSizeSorter : public QSorter<EffectiveEvent> 356class QPC_EXPORT EffectiveEventSizeSorter : public QSorter<EffectiveEvent>
216{ 357{
217public: 358public:
218 int compare( const EffectiveEvent& a, const EffectiveEvent& b ) const 359 int compare( const EffectiveEvent& a, const EffectiveEvent& b ) const
219 { 360 {