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.h229
1 files changed, 229 insertions, 0 deletions
diff --git a/library/backend/event.h b/library/backend/event.h
new file mode 100644
index 0000000..0ebe9ea
--- a/dev/null
+++ b/library/backend/event.h
@@ -0,0 +1,229 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
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
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
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.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#ifndef __EVENT_H__
22#define __EVENT_H__
23
24#include <qdatetime.h>
25#include <qvaluelist.h>
26
27#ifdef PALMTOPCENTER
28#include <qpc/qsorter.h>
29#endif
30#include <qpe/palmtoprecord.h>
31
32#include <qpe/timeconversion.h>
33
34class EventPrivate;
35class QPC_EXPORT Event : public Qtopia::Record
36{
37public:
38 enum RepeatType { NoRepeat = -1, Daily, Weekly, MonthlyDay,
39 MonthlyDate, Yearly };
40 enum Days { MON = 0x01, TUE = 0x02, WED = 0x04, THU = 0x08,
41 FRI = 0x10, SAT = 0x20, SUN = 0x40 };
42 struct QPC_EXPORT RepeatPattern
43 {
44 RepeatPattern() {
45 type = NoRepeat; frequency = -1; days = 0; position = 0; createTime = -1;
46 hasEndDate = FALSE; endDateUTC = 0; }
47 bool operator ==( const RepeatPattern &right ) const;
48
49 RepeatType type;
50 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...
52 char days; // a mask for days OR in your days!
53 bool hasEndDate;
54 QDate endDate() const { return TimeConversion::fromUTC( endDateUTC ).date(); }
55 void setEndDate( const QDate &dt ) { endDateUTC = TimeConversion::toUTC( dt ); }
56 time_t endDateUTC;
57 time_t createTime;
58 };
59
60 Event();
61 Event( const QMap<int, QString > & map );
62 virtual ~Event();
63
64 QMap<int, QString> toMap() const;
65
66 static void writeVCalendar( const QString &filename, const QValueList<Event> &events);
67 static void writeVCalendar( const QString &filename, const Event &event);
68 static QValueList<Event> readVCalendar( const QString &filename );
69
70 enum Type { Normal, AllDay };
71 enum SoundTypeChoice { Silent, Loud };
72
73 bool operator<( const Event &e1) const { return start() < e1.start(); };
74 bool operator<=( const Event &e1 ) const { return start() <= e1.start(); };
75 bool operator!=( const Event &e1 ) const { return !( *this == e1 ); };
76 bool operator>( const Event &e1 ) const { return start() > e1.start(); };
77 bool operator>=(const Event &e1 ) const { return start() >= e1.start(); };
78 bool operator==( const Event &e ) const;
79
80 void setDescription( const QString &s );
81 const QString &description() const;
82
83 void setLocation( const QString &s );
84 const QString &location() const;
85
86 void setType( Type t );
87 Type type() const;
88 void setStart( const QDateTime &d );
89 void setStart( time_t time );
90 QDateTime start( bool actual = FALSE ) const;
91 time_t startTime() const { return startUTC; }
92 void setEnd( const QDateTime &e );
93 void setEnd( time_t time );
94 QDateTime end( bool actual = FALSE ) const;
95 time_t endTime() const { return endUTC; }
96 void setTimeZone( const QString & );
97 const QString &timeZone() const;
98 void setAlarm( bool b, int minutes, SoundTypeChoice );
99 bool hasAlarm() const;
100 int alarmTime() const;
101 SoundTypeChoice alarmSound() const;
102 void setRepeat( bool b, const RepeatPattern &p );
103 void setRepeat( const RepeatPattern &p );
104 bool hasRepeat() const;
105 const RepeatPattern &repeatPattern() const;
106 RepeatPattern &repeatPattern();
107 void setNotes( const QString &n );
108 const QString &notes() const;
109 bool doRepeat() const { return pattern.type != NoRepeat; }
110
111 void save( QString& buf );
112 //void load( Node *n );
113
114 // helper function to calculate the week of the given date
115 static int week( const QDate& date );
116 // calculates the number of occurrences of the week day of
117 // the given date from the start of the month
118 static int occurrence( const QDate& date );
119 // returns a proper days-char for a given dayOfWeek()
120 static char day( int dayOfWeek ) { return 1 << ( dayOfWeek - 1 ); }
121 // returns the dayOfWeek for the *first* day it finds (ignores
122 // any further days!). Returns 1 (Monday) if there isn't any day found
123 static int dayOfWeek( char day );
124 // returns the difference of months from first to second.
125 static int monthDiff( const QDate& first, const QDate& second );
126 bool match( const QRegExp &r ) const;
127
128private:
129 Qtopia::UidGen &uidGen() { return sUidGen; }
130 static Qtopia::UidGen sUidGen;
131
132 QString descript, locat, categ;
133 Type typ : 4;
134 bool startTimeDirty : 1;
135 bool endTimeDirty : 1;
136 time_t startUTC, endUTC;
137 QString tz;
138 bool hAlarm, hRepeat;
139 int aMinutes;
140 SoundTypeChoice aSound;
141 RepeatPattern pattern;
142 QString note;
143 EventPrivate *d;
144};
145
146// Since an event spans multiple day, it is better to have this
147// class to represent a day instead of creating many
148// dummy events...
149
150class EffectiveEventPrivate;
151class QPC_EXPORT EffectiveEvent
152{
153public:
154 // If we calculate the effective event of a multi-day event
155 // we have to figure out whether we are at the first day,
156 // at the end, or anywhere else ("middle"). This is important
157 // for the start/end times (00:00/23:59)
158 // MidWay: 00:00 -> 23:59, as we are "in the middle" of a multi-
159 // day event
160 // Start: start time -> 23:59
161 // End: 00:00 -> end time
162 // Start | End == StartEnd: for single-day events (default)
163 // here we draw start time -> end time
164 enum Position { MidWay = 0, Start = 1, End = 2, StartEnd = 3 };
165
166 EffectiveEvent();
167 EffectiveEvent( const Event &event, const QDate &startDate, Position pos = StartEnd );
168 EffectiveEvent( const EffectiveEvent & );
169 EffectiveEvent& operator=( const EffectiveEvent & );
170 ~EffectiveEvent();
171
172
173 bool operator<( const EffectiveEvent &e ) const;
174 bool operator<=( const EffectiveEvent &e ) const;
175 bool operator==( const EffectiveEvent &e ) const;
176 bool operator!=( const EffectiveEvent &e ) const;
177 bool operator>( const EffectiveEvent &e ) const;
178 bool operator>= ( const EffectiveEvent &e ) const;
179
180 void setStart( const QTime &start );
181 void setEnd( const QTime &end );
182 void setEvent( Event e );
183 void setDate( const QDate &date );
184 void setEffectiveDates( const QDate &from, const QDate &to );
185
186 // QString category() const;
187 const QString &description() const;
188 const QString &location() const;
189 const QString &notes() const;
190 const Event &event() const;
191 const QTime &start() const;
192 const QTime &end() const;
193 const QDate &date() const;
194 int length() const;
195 int size() const;
196
197 QDate startDate() const;
198 QDate endDate() const;
199
200private:
201 class EffectiveEventPrivate *d;
202 Event mEvent;
203 QDate mDate;
204 QTime mStart,
205 mEnd;
206
207};
208
209#ifdef PALMTOPCENTER
210class QPC_EXPORT EffectiveEventSizeSorter : public QSorter<EffectiveEvent>
211{
212public:
213 int compare( const EffectiveEvent& a, const EffectiveEvent& b ) const
214 {
215 return a.size() - b.size();
216 }
217};
218
219class QPC_EXPORT EffectiveEventTimeSorter : public QSorter<EffectiveEvent>
220{
221public:
222 int compare( const EffectiveEvent& a, const EffectiveEvent& b ) const
223 {
224 return a.start().secsTo( b.start() );
225 }
226};
227#endif
228
229#endif