author | zautrix <zautrix> | 2004-08-02 00:09:04 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-08-02 00:09:04 (UTC) |
commit | 3ebd85e83e6f9d4ac59ce1828548f7236e2b1af0 (patch) (unidiff) | |
tree | fdff56329649c084b6f5af8d8e96c0157686575e /libkcal | |
parent | 3b4aa1cd78395c0f94b99decd901842944765746 (diff) | |
download | kdepimpi-3ebd85e83e6f9d4ac59ce1828548f7236e2b1af0.zip kdepimpi-3ebd85e83e6f9d4ac59ce1828548f7236e2b1af0.tar.gz kdepimpi-3ebd85e83e6f9d4ac59ce1828548f7236e2b1af0.tar.bz2 |
More sync hacking
-rw-r--r-- | libkcal/calendar.h | 2 | ||||
-rw-r--r-- | libkcal/calendarlocal.cpp | 14 | ||||
-rw-r--r-- | libkcal/calendarlocal.h | 2 |
3 files changed, 15 insertions, 3 deletions
diff --git a/libkcal/calendar.h b/libkcal/calendar.h index 7d23619..df5bbcf 100644 --- a/libkcal/calendar.h +++ b/libkcal/calendar.h | |||
@@ -1,350 +1,350 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 1998 Preston Brown | 3 | Copyright (c) 1998 Preston Brown |
4 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. |
10 | 10 | ||
11 | This library is distributed in the hope that it will be useful, | 11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. | 14 | Library General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU Library General Public License | 16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to | 17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. | 19 | Boston, MA 02111-1307, USA. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #ifndef CALENDAR_H | 22 | #ifndef CALENDAR_H |
23 | #define CALENDAR_H | 23 | #define CALENDAR_H |
24 | 24 | ||
25 | #include <qobject.h> | 25 | #include <qobject.h> |
26 | #include <qstring.h> | 26 | #include <qstring.h> |
27 | #include <qdatetime.h> | 27 | #include <qdatetime.h> |
28 | #include <qptrlist.h> | 28 | #include <qptrlist.h> |
29 | #include <qdict.h> | 29 | #include <qdict.h> |
30 | 30 | ||
31 | #include "customproperties.h" | 31 | #include "customproperties.h" |
32 | #include "event.h" | 32 | #include "event.h" |
33 | #include "todo.h" | 33 | #include "todo.h" |
34 | #include "journal.h" | 34 | #include "journal.h" |
35 | 35 | ||
36 | #define _TIME_ZONE "-0500" /* hardcoded, overridden in config file. */ | 36 | #define _TIME_ZONE "-0500" /* hardcoded, overridden in config file. */ |
37 | 37 | ||
38 | class KConfig; | 38 | class KConfig; |
39 | 39 | ||
40 | namespace KCal { | 40 | namespace KCal { |
41 | 41 | ||
42 | class CalFilter; | 42 | class CalFilter; |
43 | 43 | ||
44 | /** | 44 | /** |
45 | This is the main "calendar" object class for KOrganizer. It holds | 45 | This is the main "calendar" object class for KOrganizer. It holds |
46 | information like all appointments/events, user information, etc. etc. | 46 | information like all appointments/events, user information, etc. etc. |
47 | one calendar is associated with each CalendarView (@see calendarview.h). | 47 | one calendar is associated with each CalendarView (@see calendarview.h). |
48 | This is an abstract base class defining the interface to a calendar. It is | 48 | This is an abstract base class defining the interface to a calendar. It is |
49 | implemented by subclasses like @see CalendarLocal, which use different | 49 | implemented by subclasses like @see CalendarLocal, which use different |
50 | methods to store and access the data. | 50 | methods to store and access the data. |
51 | 51 | ||
52 | Ownership of events etc. is handled by the following policy: As soon as an | 52 | Ownership of events etc. is handled by the following policy: As soon as an |
53 | event (or any other subclass of IncidenceBase) object is added to the | 53 | event (or any other subclass of IncidenceBase) object is added to the |
54 | Calendar by addEvent() it is owned by the Calendar object. The Calendar takes | 54 | Calendar by addEvent() it is owned by the Calendar object. The Calendar takes |
55 | care of deleting it. All Events returned by the query functions are returned | 55 | care of deleting it. All Events returned by the query functions are returned |
56 | as pointers, that means all changes to the returned events are immediately | 56 | as pointers, that means all changes to the returned events are immediately |
57 | visible in the Calendar. You shouldn't delete any Event object you get from | 57 | visible in the Calendar. You shouldn't delete any Event object you get from |
58 | Calendar. | 58 | Calendar. |
59 | */ | 59 | */ |
60 | class Calendar : public QObject, public CustomProperties, | 60 | class Calendar : public QObject, public CustomProperties, |
61 | public IncidenceBase::Observer | 61 | public IncidenceBase::Observer |
62 | { | 62 | { |
63 | Q_OBJECT | 63 | Q_OBJECT |
64 | public: | 64 | public: |
65 | Calendar(); | 65 | Calendar(); |
66 | Calendar(const QString &timeZoneId); | 66 | Calendar(const QString &timeZoneId); |
67 | virtual ~Calendar(); | 67 | virtual ~Calendar(); |
68 | void deleteIncidence(Incidence *in); | 68 | void deleteIncidence(Incidence *in); |
69 | /** | 69 | /** |
70 | Clears out the current calendar, freeing all used memory etc. | 70 | Clears out the current calendar, freeing all used memory etc. |
71 | */ | 71 | */ |
72 | virtual void close() = 0; | 72 | virtual void close() = 0; |
73 | 73 | ||
74 | /** | 74 | /** |
75 | Sync changes in memory to persistant storage. | 75 | Sync changes in memory to persistant storage. |
76 | */ | 76 | */ |
77 | virtual void save() = 0; | 77 | virtual void save() = 0; |
78 | 78 | virtual QPtrList<Event> getExternLastSyncEvents() = 0; | |
79 | virtual bool isSaving() { return false; } | 79 | virtual bool isSaving() { return false; } |
80 | 80 | ||
81 | /** | 81 | /** |
82 | Return the owner of the calendar's full name. | 82 | Return the owner of the calendar's full name. |
83 | */ | 83 | */ |
84 | const QString &getOwner() const; | 84 | const QString &getOwner() const; |
85 | /** | 85 | /** |
86 | Set the owner of the calendar. Should be owner's full name. | 86 | Set the owner of the calendar. Should be owner's full name. |
87 | */ | 87 | */ |
88 | void setOwner( const QString &os ); | 88 | void setOwner( const QString &os ); |
89 | /** | 89 | /** |
90 | Return the email address of the calendar owner. | 90 | Return the email address of the calendar owner. |
91 | */ | 91 | */ |
92 | const QString &getEmail(); | 92 | const QString &getEmail(); |
93 | /** | 93 | /** |
94 | Set the email address of the calendar owner. | 94 | Set the email address of the calendar owner. |
95 | */ | 95 | */ |
96 | void setEmail( const QString & ); | 96 | void setEmail( const QString & ); |
97 | 97 | ||
98 | /** | 98 | /** |
99 | Set time zone from a timezone string (e.g. -2:00) | 99 | Set time zone from a timezone string (e.g. -2:00) |
100 | */ | 100 | */ |
101 | void setTimeZone( const QString &tz ); | 101 | void setTimeZone( const QString &tz ); |
102 | /** | 102 | /** |
103 | Set time zone from a minutes value (e.g. -60) | 103 | Set time zone from a minutes value (e.g. -60) |
104 | */ | 104 | */ |
105 | void setTimeZone( int tz ); | 105 | void setTimeZone( int tz ); |
106 | /** | 106 | /** |
107 | Return time zone as offest in minutes. | 107 | Return time zone as offest in minutes. |
108 | */ | 108 | */ |
109 | int getTimeZone() const; | 109 | int getTimeZone() const; |
110 | /** | 110 | /** |
111 | Compute an ISO 8601 format string from the time zone. | 111 | Compute an ISO 8601 format string from the time zone. |
112 | */ | 112 | */ |
113 | QString getTimeZoneStr() const; | 113 | QString getTimeZoneStr() const; |
114 | /** | 114 | /** |
115 | Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal | 115 | Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal |
116 | values). | 116 | values). |
117 | */ | 117 | */ |
118 | void setTimeZoneId( const QString & ); | 118 | void setTimeZoneId( const QString & ); |
119 | /** | 119 | /** |
120 | Return time zone id. | 120 | Return time zone id. |
121 | */ | 121 | */ |
122 | QString timeZoneId() const; | 122 | QString timeZoneId() const; |
123 | /** | 123 | /** |
124 | Use local time, not UTC or a time zone. | 124 | Use local time, not UTC or a time zone. |
125 | */ | 125 | */ |
126 | void setLocalTime(); | 126 | void setLocalTime(); |
127 | /** | 127 | /** |
128 | Return whether local time is being used. | 128 | Return whether local time is being used. |
129 | */ | 129 | */ |
130 | bool isLocalTime() const; | 130 | bool isLocalTime() const; |
131 | 131 | ||
132 | /** | 132 | /** |
133 | Add an incidence to calendar. | 133 | Add an incidence to calendar. |
134 | 134 | ||
135 | @return true on success, false on error. | 135 | @return true on success, false on error. |
136 | */ | 136 | */ |
137 | virtual bool addIncidence( Incidence * ); | 137 | virtual bool addIncidence( Incidence * ); |
138 | /** | 138 | /** |
139 | Return filtered list of all incidences of this calendar. | 139 | Return filtered list of all incidences of this calendar. |
140 | */ | 140 | */ |
141 | virtual QPtrList<Incidence> incidences(); | 141 | virtual QPtrList<Incidence> incidences(); |
142 | 142 | ||
143 | /** | 143 | /** |
144 | Return unfiltered list of all incidences of this calendar. | 144 | Return unfiltered list of all incidences of this calendar. |
145 | */ | 145 | */ |
146 | virtual QPtrList<Incidence> rawIncidences(); | 146 | virtual QPtrList<Incidence> rawIncidences(); |
147 | 147 | ||
148 | /** | 148 | /** |
149 | Adds a Event to this calendar object. | 149 | Adds a Event to this calendar object. |
150 | @param anEvent a pointer to the event to add | 150 | @param anEvent a pointer to the event to add |
151 | 151 | ||
152 | @return true on success, false on error. | 152 | @return true on success, false on error. |
153 | */ | 153 | */ |
154 | virtual bool addEventNoDup( Event *event ) = 0; | 154 | virtual bool addEventNoDup( Event *event ) = 0; |
155 | virtual bool addAnniversaryNoDup( Event *event ) = 0; | 155 | virtual bool addAnniversaryNoDup( Event *event ) = 0; |
156 | virtual bool addEvent( Event *anEvent ) = 0; | 156 | virtual bool addEvent( Event *anEvent ) = 0; |
157 | /** | 157 | /** |
158 | Delete event from calendar. | 158 | Delete event from calendar. |
159 | */ | 159 | */ |
160 | virtual void deleteEvent( Event * ) = 0; | 160 | virtual void deleteEvent( Event * ) = 0; |
161 | /** | 161 | /** |
162 | Retrieves an event on the basis of the unique string ID. | 162 | Retrieves an event on the basis of the unique string ID. |
163 | */ | 163 | */ |
164 | virtual Event *event( const QString &UniqueStr ) = 0; | 164 | virtual Event *event( const QString &UniqueStr ) = 0; |
165 | virtual Event *event( int ) = 0; | 165 | virtual Event *event( int ) = 0; |
166 | /** | 166 | /** |
167 | Builds and then returns a list of all events that match for the | 167 | Builds and then returns a list of all events that match for the |
168 | date specified. useful for dayView, etc. etc. | 168 | date specified. useful for dayView, etc. etc. |
169 | The calendar filter is applied. | 169 | The calendar filter is applied. |
170 | */ | 170 | */ |
171 | QPtrList<Event> events( const QDate &date, bool sorted = false); | 171 | QPtrList<Event> events( const QDate &date, bool sorted = false); |
172 | /** | 172 | /** |
173 | Get events, which occur on the given date. | 173 | Get events, which occur on the given date. |
174 | The calendar filter is applied. | 174 | The calendar filter is applied. |
175 | */ | 175 | */ |
176 | QPtrList<Event> events( const QDateTime &qdt ); | 176 | QPtrList<Event> events( const QDateTime &qdt ); |
177 | /** | 177 | /** |
178 | Get events in a range of dates. If inclusive is set to true, only events | 178 | Get events in a range of dates. If inclusive is set to true, only events |
179 | are returned, which are completely included in the range. | 179 | are returned, which are completely included in the range. |
180 | The calendar filter is applied. | 180 | The calendar filter is applied. |
181 | */ | 181 | */ |
182 | QPtrList<Event> events( const QDate &start, const QDate &end, | 182 | QPtrList<Event> events( const QDate &start, const QDate &end, |
183 | bool inclusive = false); | 183 | bool inclusive = false); |
184 | /** | 184 | /** |
185 | Return filtered list of all events in calendar. | 185 | Return filtered list of all events in calendar. |
186 | */ | 186 | */ |
187 | virtual QPtrList<Event> events(); | 187 | virtual QPtrList<Event> events(); |
188 | /** | 188 | /** |
189 | Return unfiltered list of all events in calendar. | 189 | Return unfiltered list of all events in calendar. |
190 | */ | 190 | */ |
191 | virtual QPtrList<Event> rawEvents() = 0; | 191 | virtual QPtrList<Event> rawEvents() = 0; |
192 | 192 | ||
193 | /** | 193 | /** |
194 | Add a todo to the todolist. | 194 | Add a todo to the todolist. |
195 | 195 | ||
196 | @return true on success, false on error. | 196 | @return true on success, false on error. |
197 | */ | 197 | */ |
198 | virtual bool addTodo( Todo *todo ) = 0; | 198 | virtual bool addTodo( Todo *todo ) = 0; |
199 | virtual bool addTodoNoDup( Todo *todo ) = 0; | 199 | virtual bool addTodoNoDup( Todo *todo ) = 0; |
200 | /** | 200 | /** |
201 | Remove a todo from the todolist. | 201 | Remove a todo from the todolist. |
202 | */ | 202 | */ |
203 | virtual void deleteTodo( Todo * ) = 0; | 203 | virtual void deleteTodo( Todo * ) = 0; |
204 | virtual void deleteJournal( Journal * ) = 0; | 204 | virtual void deleteJournal( Journal * ) = 0; |
205 | /** | 205 | /** |
206 | Return filterd list of todos. | 206 | Return filterd list of todos. |
207 | */ | 207 | */ |
208 | virtual QPtrList<Todo> todos(); | 208 | virtual QPtrList<Todo> todos(); |
209 | /** | 209 | /** |
210 | Searches todolist for an event with this unique string identifier, | 210 | Searches todolist for an event with this unique string identifier, |
211 | returns a pointer or null. | 211 | returns a pointer or null. |
212 | */ | 212 | */ |
213 | virtual Todo *todo( const QString &uid ) = 0; | 213 | virtual Todo *todo( const QString &uid ) = 0; |
214 | virtual Todo *todo( int ) = 0; | 214 | virtual Todo *todo( int ) = 0; |
215 | /** | 215 | /** |
216 | Returns list of todos due on the specified date. | 216 | Returns list of todos due on the specified date. |
217 | */ | 217 | */ |
218 | virtual QPtrList<Todo> todos( const QDate &date ) = 0; | 218 | virtual QPtrList<Todo> todos( const QDate &date ) = 0; |
219 | /** | 219 | /** |
220 | Return unfiltered list of todos. | 220 | Return unfiltered list of todos. |
221 | */ | 221 | */ |
222 | virtual QPtrList<Todo> rawTodos() = 0; | 222 | virtual QPtrList<Todo> rawTodos() = 0; |
223 | 223 | ||
224 | /** | 224 | /** |
225 | Add a Journal entry to calendar. | 225 | Add a Journal entry to calendar. |
226 | 226 | ||
227 | @return true on success, false on error. | 227 | @return true on success, false on error. |
228 | */ | 228 | */ |
229 | virtual bool addJournal( Journal * ) = 0; | 229 | virtual bool addJournal( Journal * ) = 0; |
230 | /** | 230 | /** |
231 | Return Journal for given date. | 231 | Return Journal for given date. |
232 | */ | 232 | */ |
233 | virtual Journal *journal( const QDate & ) = 0; | 233 | virtual Journal *journal( const QDate & ) = 0; |
234 | /** | 234 | /** |
235 | Return Journal with given UID. | 235 | Return Journal with given UID. |
236 | */ | 236 | */ |
237 | virtual Journal *journal( const QString &UID ) = 0; | 237 | virtual Journal *journal( const QString &UID ) = 0; |
238 | /** | 238 | /** |
239 | Return list of all Journal entries. | 239 | Return list of all Journal entries. |
240 | */ | 240 | */ |
241 | virtual QPtrList<Journal> journals() = 0; | 241 | virtual QPtrList<Journal> journals() = 0; |
242 | 242 | ||
243 | /** | 243 | /** |
244 | Searches all incidence types for an incidence with this unique | 244 | Searches all incidence types for an incidence with this unique |
245 | string identifier, returns a pointer or null. | 245 | string identifier, returns a pointer or null. |
246 | */ | 246 | */ |
247 | Incidence* incidence( const QString&UID ); | 247 | Incidence* incidence( const QString&UID ); |
248 | 248 | ||
249 | /** | 249 | /** |
250 | Setup relations for an incidence. | 250 | Setup relations for an incidence. |
251 | */ | 251 | */ |
252 | virtual void setupRelations( Incidence * ); | 252 | virtual void setupRelations( Incidence * ); |
253 | /** | 253 | /** |
254 | Remove all relations to an incidence | 254 | Remove all relations to an incidence |
255 | */ | 255 | */ |
256 | virtual void removeRelations( Incidence * ); | 256 | virtual void removeRelations( Incidence * ); |
257 | 257 | ||
258 | /** | 258 | /** |
259 | Set calendar filter, which filters events for the events() functions. | 259 | Set calendar filter, which filters events for the events() functions. |
260 | The Filter object is owned by the caller. | 260 | The Filter object is owned by the caller. |
261 | */ | 261 | */ |
262 | void setFilter( CalFilter * ); | 262 | void setFilter( CalFilter * ); |
263 | /** | 263 | /** |
264 | Return calendar filter. | 264 | Return calendar filter. |
265 | */ | 265 | */ |
266 | CalFilter *filter(); | 266 | CalFilter *filter(); |
267 | virtual QDateTime nextAlarm( int daysTo ) = 0; | 267 | virtual QDateTime nextAlarm( int daysTo ) = 0; |
268 | virtual QString nextSummary( ) const = 0; | 268 | virtual QString nextSummary( ) const = 0; |
269 | virtual void reInitAlarmSettings() = 0; | 269 | virtual void reInitAlarmSettings() = 0; |
270 | virtual QDateTime nextAlarmEventDateTime() const = 0; | 270 | virtual QDateTime nextAlarmEventDateTime() const = 0; |
271 | virtual void checkAlarmForIncidence( Incidence *, bool ) = 0; | 271 | virtual void checkAlarmForIncidence( Incidence *, bool ) = 0; |
272 | /** | 272 | /** |
273 | Return all alarms, which ocur in the given time interval. | 273 | Return all alarms, which ocur in the given time interval. |
274 | */ | 274 | */ |
275 | virtual Alarm::List alarms( const QDateTime &from, | 275 | virtual Alarm::List alarms( const QDateTime &from, |
276 | const QDateTime &to ) = 0; | 276 | const QDateTime &to ) = 0; |
277 | 277 | ||
278 | class Observer { | 278 | class Observer { |
279 | public: | 279 | public: |
280 | virtual void calendarModified( bool, Calendar * ) = 0; | 280 | virtual void calendarModified( bool, Calendar * ) = 0; |
281 | }; | 281 | }; |
282 | 282 | ||
283 | void registerObserver( Observer * ); | 283 | void registerObserver( Observer * ); |
284 | 284 | ||
285 | void setModified( bool ); | 285 | void setModified( bool ); |
286 | 286 | ||
287 | /** | 287 | /** |
288 | Set product id returned by loadedProductId(). This function is only | 288 | Set product id returned by loadedProductId(). This function is only |
289 | useful for the calendar loading code. | 289 | useful for the calendar loading code. |
290 | */ | 290 | */ |
291 | void setLoadedProductId( const QString & ); | 291 | void setLoadedProductId( const QString & ); |
292 | /** | 292 | /** |
293 | Return product id taken from file that has been loaded. Returns | 293 | Return product id taken from file that has been loaded. Returns |
294 | QString::null, if no calendar has been loaded. | 294 | QString::null, if no calendar has been loaded. |
295 | */ | 295 | */ |
296 | QString loadedProductId(); | 296 | QString loadedProductId(); |
297 | 297 | ||
298 | signals: | 298 | signals: |
299 | void calendarChanged(); | 299 | void calendarChanged(); |
300 | void calendarSaved(); | 300 | void calendarSaved(); |
301 | void calendarLoaded(); | 301 | void calendarLoaded(); |
302 | void addAlarm(const QDateTime &qdt, const QString ¬i ); | 302 | void addAlarm(const QDateTime &qdt, const QString ¬i ); |
303 | void removeAlarm(const QDateTime &qdt, const QString ¬i ); | 303 | void removeAlarm(const QDateTime &qdt, const QString ¬i ); |
304 | 304 | ||
305 | protected: | 305 | protected: |
306 | /** | 306 | /** |
307 | Get unfiltered events, which occur on the given date. | 307 | Get unfiltered events, which occur on the given date. |
308 | */ | 308 | */ |
309 | virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0; | 309 | virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0; |
310 | /** | 310 | /** |
311 | Get unfiltered events, which occur on the given date. | 311 | Get unfiltered events, which occur on the given date. |
312 | */ | 312 | */ |
313 | virtual QPtrList<Event> rawEventsForDate( const QDate &date, | 313 | virtual QPtrList<Event> rawEventsForDate( const QDate &date, |
314 | bool sorted = false ) = 0; | 314 | bool sorted = false ) = 0; |
315 | /** | 315 | /** |
316 | Get events in a range of dates. If inclusive is set to true, only events | 316 | Get events in a range of dates. If inclusive is set to true, only events |
317 | are returned, which are completely included in the range. | 317 | are returned, which are completely included in the range. |
318 | */ | 318 | */ |
319 | virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end, | 319 | virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end, |
320 | bool inclusive = false ) = 0; | 320 | bool inclusive = false ) = 0; |
321 | Incidence *mNextAlarmIncidence; | 321 | Incidence *mNextAlarmIncidence; |
322 | 322 | ||
323 | private: | 323 | private: |
324 | void init(); | 324 | void init(); |
325 | 325 | ||
326 | QString mOwner; // who the calendar belongs to | 326 | QString mOwner; // who the calendar belongs to |
327 | QString mOwnerEmail; // email address of the owner | 327 | QString mOwnerEmail; // email address of the owner |
328 | int mTimeZone; // timezone OFFSET from GMT (MINUTES) | 328 | int mTimeZone; // timezone OFFSET from GMT (MINUTES) |
329 | bool mLocalTime; // use local time, not UTC or a time zone | 329 | bool mLocalTime; // use local time, not UTC or a time zone |
330 | 330 | ||
331 | CalFilter *mFilter; | 331 | CalFilter *mFilter; |
332 | CalFilter *mDefaultFilter; | 332 | CalFilter *mDefaultFilter; |
333 | 333 | ||
334 | QString mTimeZoneId; | 334 | QString mTimeZoneId; |
335 | 335 | ||
336 | Observer *mObserver; | 336 | Observer *mObserver; |
337 | bool mNewObserver; | 337 | bool mNewObserver; |
338 | 338 | ||
339 | bool mModified; | 339 | bool mModified; |
340 | 340 | ||
341 | QString mLoadedProductId; | 341 | QString mLoadedProductId; |
342 | 342 | ||
343 | // This list is used to put together related todos | 343 | // This list is used to put together related todos |
344 | QDict<Incidence> mOrphans; | 344 | QDict<Incidence> mOrphans; |
345 | QDict<Incidence> mOrphanUids; | 345 | QDict<Incidence> mOrphanUids; |
346 | }; | 346 | }; |
347 | 347 | ||
348 | } | 348 | } |
349 | 349 | ||
350 | #endif | 350 | #endif |
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index 3c572f0..09ce9f0 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp | |||
@@ -1,686 +1,698 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | 3 | ||
4 | Copyright (c) 1998 Preston Brown | 4 | Copyright (c) 1998 Preston Brown |
5 | Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> | 5 | Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> |
6 | 6 | ||
7 | This library is free software; you can redistribute it and/or | 7 | This library is free software; you can redistribute it and/or |
8 | modify it under the terms of the GNU Library General Public | 8 | modify it under the terms of the GNU Library General Public |
9 | License as published by the Free Software Foundation; either | 9 | License as published by the Free Software Foundation; either |
10 | version 2 of the License, or (at your option) any later version. | 10 | version 2 of the License, or (at your option) any later version. |
11 | 11 | ||
12 | This library is distributed in the hope that it will be useful, | 12 | This library is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | Library General Public License for more details. | 15 | Library General Public License for more details. |
16 | 16 | ||
17 | You should have received a copy of the GNU Library General Public License | 17 | You should have received a copy of the GNU Library General Public License |
18 | along with this library; see the file COPYING.LIB. If not, write to | 18 | along with this library; see the file COPYING.LIB. If not, write to |
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. | 20 | Boston, MA 02111-1307, USA. |
21 | */ | 21 | */ |
22 | 22 | ||
23 | #include <qdatetime.h> | 23 | #include <qdatetime.h> |
24 | #include <qstring.h> | 24 | #include <qstring.h> |
25 | #include <qptrlist.h> | 25 | #include <qptrlist.h> |
26 | 26 | ||
27 | #include <kdebug.h> | 27 | #include <kdebug.h> |
28 | #include <kconfig.h> | 28 | #include <kconfig.h> |
29 | #include <kglobal.h> | 29 | #include <kglobal.h> |
30 | #include <klocale.h> | 30 | #include <klocale.h> |
31 | 31 | ||
32 | #include "vcaldrag.h" | 32 | #include "vcaldrag.h" |
33 | #include "vcalformat.h" | 33 | #include "vcalformat.h" |
34 | #include "icalformat.h" | 34 | #include "icalformat.h" |
35 | #include "exceptions.h" | 35 | #include "exceptions.h" |
36 | #include "incidence.h" | 36 | #include "incidence.h" |
37 | #include "journal.h" | 37 | #include "journal.h" |
38 | #include "filestorage.h" | 38 | #include "filestorage.h" |
39 | #include "calfilter.h" | 39 | #include "calfilter.h" |
40 | 40 | ||
41 | #include "calendarlocal.h" | 41 | #include "calendarlocal.h" |
42 | 42 | ||
43 | // #ifndef DESKTOP_VERSION | 43 | // #ifndef DESKTOP_VERSION |
44 | // #include <qtopia/alarmserver.h> | 44 | // #include <qtopia/alarmserver.h> |
45 | // #endif | 45 | // #endif |
46 | using namespace KCal; | 46 | using namespace KCal; |
47 | 47 | ||
48 | CalendarLocal::CalendarLocal() | 48 | CalendarLocal::CalendarLocal() |
49 | : Calendar() | 49 | : Calendar() |
50 | { | 50 | { |
51 | init(); | 51 | init(); |
52 | } | 52 | } |
53 | 53 | ||
54 | CalendarLocal::CalendarLocal(const QString &timeZoneId) | 54 | CalendarLocal::CalendarLocal(const QString &timeZoneId) |
55 | : Calendar(timeZoneId) | 55 | : Calendar(timeZoneId) |
56 | { | 56 | { |
57 | init(); | 57 | init(); |
58 | } | 58 | } |
59 | 59 | ||
60 | void CalendarLocal::init() | 60 | void CalendarLocal::init() |
61 | { | 61 | { |
62 | mNextAlarmIncidence = 0; | 62 | mNextAlarmIncidence = 0; |
63 | } | 63 | } |
64 | 64 | ||
65 | 65 | ||
66 | CalendarLocal::~CalendarLocal() | 66 | CalendarLocal::~CalendarLocal() |
67 | { | 67 | { |
68 | close(); | 68 | close(); |
69 | } | 69 | } |
70 | 70 | ||
71 | bool CalendarLocal::load( const QString &fileName ) | 71 | bool CalendarLocal::load( const QString &fileName ) |
72 | { | 72 | { |
73 | FileStorage storage( this, fileName ); | 73 | FileStorage storage( this, fileName ); |
74 | return storage.load(); | 74 | return storage.load(); |
75 | } | 75 | } |
76 | 76 | ||
77 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) | 77 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) |
78 | { | 78 | { |
79 | FileStorage storage( this, fileName, format ); | 79 | FileStorage storage( this, fileName, format ); |
80 | return storage.save(); | 80 | return storage.save(); |
81 | } | 81 | } |
82 | 82 | ||
83 | void CalendarLocal::close() | 83 | void CalendarLocal::close() |
84 | { | 84 | { |
85 | mEventList.setAutoDelete( true ); | 85 | mEventList.setAutoDelete( true ); |
86 | mTodoList.setAutoDelete( true ); | 86 | mTodoList.setAutoDelete( true ); |
87 | mJournalList.setAutoDelete( false ); | 87 | mJournalList.setAutoDelete( false ); |
88 | 88 | ||
89 | mEventList.clear(); | 89 | mEventList.clear(); |
90 | mTodoList.clear(); | 90 | mTodoList.clear(); |
91 | mJournalList.clear(); | 91 | mJournalList.clear(); |
92 | 92 | ||
93 | mEventList.setAutoDelete( false ); | 93 | mEventList.setAutoDelete( false ); |
94 | mTodoList.setAutoDelete( false ); | 94 | mTodoList.setAutoDelete( false ); |
95 | mJournalList.setAutoDelete( false ); | 95 | mJournalList.setAutoDelete( false ); |
96 | 96 | ||
97 | setModified( false ); | 97 | setModified( false ); |
98 | } | 98 | } |
99 | 99 | ||
100 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) | 100 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) |
101 | { | 101 | { |
102 | QString cat; | 102 | QString cat; |
103 | bool isBirthday = true; | 103 | bool isBirthday = true; |
104 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { | 104 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { |
105 | isBirthday = false; | 105 | isBirthday = false; |
106 | cat = i18n( "Anniversary" ); | 106 | cat = i18n( "Anniversary" ); |
107 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { | 107 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { |
108 | isBirthday = true; | 108 | isBirthday = true; |
109 | cat = i18n( "Birthday" ); | 109 | cat = i18n( "Birthday" ); |
110 | } else { | 110 | } else { |
111 | qDebug("addAnniversaryNoDup called without fitting category! "); | 111 | qDebug("addAnniversaryNoDup called without fitting category! "); |
112 | return false; | 112 | return false; |
113 | } | 113 | } |
114 | Event * eve; | 114 | Event * eve; |
115 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 115 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
116 | if ( !(eve->categories().contains( cat ) )) | 116 | if ( !(eve->categories().contains( cat ) )) |
117 | continue; | 117 | continue; |
118 | // now we have an event with fitting category | 118 | // now we have an event with fitting category |
119 | if ( eve->dtStart().date() != event->dtStart().date() ) | 119 | if ( eve->dtStart().date() != event->dtStart().date() ) |
120 | continue; | 120 | continue; |
121 | // now we have an event with fitting category+date | 121 | // now we have an event with fitting category+date |
122 | if ( eve->summary() != event->summary() ) | 122 | if ( eve->summary() != event->summary() ) |
123 | continue; | 123 | continue; |
124 | // now we have an event with fitting category+date+summary | 124 | // now we have an event with fitting category+date+summary |
125 | return false; | 125 | return false; |
126 | } | 126 | } |
127 | return addEvent( event ); | 127 | return addEvent( event ); |
128 | 128 | ||
129 | } | 129 | } |
130 | bool CalendarLocal::addEventNoDup( Event *event ) | 130 | bool CalendarLocal::addEventNoDup( Event *event ) |
131 | { | 131 | { |
132 | Event * eve; | 132 | Event * eve; |
133 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 133 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
134 | if ( *eve == *event ) { | 134 | if ( *eve == *event ) { |
135 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); | 135 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); |
136 | return false; | 136 | return false; |
137 | } | 137 | } |
138 | } | 138 | } |
139 | return addEvent( event ); | 139 | return addEvent( event ); |
140 | } | 140 | } |
141 | 141 | ||
142 | bool CalendarLocal::addEvent( Event *event ) | 142 | bool CalendarLocal::addEvent( Event *event ) |
143 | { | 143 | { |
144 | insertEvent( event ); | 144 | insertEvent( event ); |
145 | 145 | ||
146 | event->registerObserver( this ); | 146 | event->registerObserver( this ); |
147 | 147 | ||
148 | setModified( true ); | 148 | setModified( true ); |
149 | 149 | ||
150 | return true; | 150 | return true; |
151 | } | 151 | } |
152 | 152 | ||
153 | void CalendarLocal::deleteEvent( Event *event ) | 153 | void CalendarLocal::deleteEvent( Event *event ) |
154 | { | 154 | { |
155 | 155 | ||
156 | 156 | ||
157 | if ( mEventList.removeRef( event ) ) { | 157 | if ( mEventList.removeRef( event ) ) { |
158 | setModified( true ); | 158 | setModified( true ); |
159 | } | 159 | } |
160 | } | 160 | } |
161 | 161 | ||
162 | 162 | ||
163 | Event *CalendarLocal::event( const QString &uid ) | 163 | Event *CalendarLocal::event( const QString &uid ) |
164 | { | 164 | { |
165 | 165 | ||
166 | Event *event; | 166 | Event *event; |
167 | 167 | ||
168 | for ( event = mEventList.first(); event; event = mEventList.next() ) { | 168 | for ( event = mEventList.first(); event; event = mEventList.next() ) { |
169 | if ( event->uid() == uid ) { | 169 | if ( event->uid() == uid ) { |
170 | return event; | 170 | return event; |
171 | } | 171 | } |
172 | } | 172 | } |
173 | 173 | ||
174 | return 0; | 174 | return 0; |
175 | } | 175 | } |
176 | bool CalendarLocal::addTodoNoDup( Todo *todo ) | 176 | bool CalendarLocal::addTodoNoDup( Todo *todo ) |
177 | { | 177 | { |
178 | Todo * eve; | 178 | Todo * eve; |
179 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { | 179 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { |
180 | if ( *eve == *todo ) { | 180 | if ( *eve == *todo ) { |
181 | //qDebug("duplicate todo found! not inserted! "); | 181 | //qDebug("duplicate todo found! not inserted! "); |
182 | return false; | 182 | return false; |
183 | } | 183 | } |
184 | } | 184 | } |
185 | return addTodo( todo ); | 185 | return addTodo( todo ); |
186 | } | 186 | } |
187 | bool CalendarLocal::addTodo( Todo *todo ) | 187 | bool CalendarLocal::addTodo( Todo *todo ) |
188 | { | 188 | { |
189 | mTodoList.append( todo ); | 189 | mTodoList.append( todo ); |
190 | 190 | ||
191 | todo->registerObserver( this ); | 191 | todo->registerObserver( this ); |
192 | 192 | ||
193 | // Set up subtask relations | 193 | // Set up subtask relations |
194 | setupRelations( todo ); | 194 | setupRelations( todo ); |
195 | 195 | ||
196 | setModified( true ); | 196 | setModified( true ); |
197 | 197 | ||
198 | return true; | 198 | return true; |
199 | } | 199 | } |
200 | 200 | ||
201 | void CalendarLocal::deleteTodo( Todo *todo ) | 201 | void CalendarLocal::deleteTodo( Todo *todo ) |
202 | { | 202 | { |
203 | // Handle orphaned children | 203 | // Handle orphaned children |
204 | removeRelations( todo ); | 204 | removeRelations( todo ); |
205 | 205 | ||
206 | if ( mTodoList.removeRef( todo ) ) { | 206 | if ( mTodoList.removeRef( todo ) ) { |
207 | setModified( true ); | 207 | setModified( true ); |
208 | } | 208 | } |
209 | } | 209 | } |
210 | 210 | ||
211 | QPtrList<Todo> CalendarLocal::rawTodos() | 211 | QPtrList<Todo> CalendarLocal::rawTodos() |
212 | { | 212 | { |
213 | return mTodoList; | 213 | return mTodoList; |
214 | } | 214 | } |
215 | Todo *CalendarLocal::todo( int id ) | 215 | Todo *CalendarLocal::todo( int id ) |
216 | { | 216 | { |
217 | Todo *todo; | 217 | Todo *todo; |
218 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 218 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
219 | if ( todo->zaurusId() == id ) return todo; | 219 | if ( todo->zaurusId() == id ) return todo; |
220 | } | 220 | } |
221 | 221 | ||
222 | return 0; | 222 | return 0; |
223 | } | 223 | } |
224 | 224 | ||
225 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() | ||
226 | { | ||
227 | QPtrList<Event> el; | ||
228 | Event *todo; | ||
229 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | ||
230 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | ||
231 | if ( todo->summary().left(3) == "E: " ) | ||
232 | el.append( todo ); | ||
233 | } | ||
234 | |||
235 | return el; | ||
236 | |||
237 | } | ||
225 | Event *CalendarLocal::event( int id ) | 238 | Event *CalendarLocal::event( int id ) |
226 | { | 239 | { |
227 | Event *todo; | 240 | Event *todo; |
228 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 241 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
229 | if ( todo->zaurusId() == id ) return todo; | 242 | if ( todo->zaurusId() == id ) return todo; |
230 | } | 243 | } |
231 | 244 | ||
232 | return 0; | 245 | return 0; |
233 | } | 246 | } |
234 | Todo *CalendarLocal::todo( const QString &uid ) | 247 | Todo *CalendarLocal::todo( const QString &uid ) |
235 | { | 248 | { |
236 | Todo *todo; | 249 | Todo *todo; |
237 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 250 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
238 | if ( todo->uid() == uid ) return todo; | 251 | if ( todo->uid() == uid ) return todo; |
239 | } | 252 | } |
240 | 253 | ||
241 | return 0; | 254 | return 0; |
242 | } | 255 | } |
243 | QString CalendarLocal::nextSummary() const | 256 | QString CalendarLocal::nextSummary() const |
244 | { | 257 | { |
245 | return mNextSummary; | 258 | return mNextSummary; |
246 | } | 259 | } |
247 | QDateTime CalendarLocal::nextAlarmEventDateTime() const | 260 | QDateTime CalendarLocal::nextAlarmEventDateTime() const |
248 | { | 261 | { |
249 | return mNextAlarmEventDateTime; | 262 | return mNextAlarmEventDateTime; |
250 | } | 263 | } |
251 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) | 264 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) |
252 | { | 265 | { |
253 | //mNextAlarmIncidence | 266 | //mNextAlarmIncidence |
254 | //mNextAlarmDateTime | 267 | //mNextAlarmDateTime |
255 | //return mNextSummary; | 268 | //return mNextSummary; |
256 | //return mNextAlarmEventDateTime; | 269 | //return mNextAlarmEventDateTime; |
257 | bool newNextAlarm = false; | 270 | bool newNextAlarm = false; |
258 | bool computeNextAlarm = false; | 271 | bool computeNextAlarm = false; |
259 | bool ok; | 272 | bool ok; |
260 | int offset; | 273 | int offset; |
261 | QDateTime nextA; | 274 | QDateTime nextA; |
262 | // QString nextSum; | 275 | // QString nextSum; |
263 | //QDateTime nextEvent; | 276 | //QDateTime nextEvent; |
264 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { | 277 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { |
265 | computeNextAlarm = true; | 278 | computeNextAlarm = true; |
266 | } else { | 279 | } else { |
267 | if ( ! deleted ) { | 280 | if ( ! deleted ) { |
268 | nextA = incidence->getNextAlarmDateTime(& ok, &offset ) ; | 281 | nextA = incidence->getNextAlarmDateTime(& ok, &offset ) ; |
269 | if ( ok ) { | 282 | if ( ok ) { |
270 | if ( nextA < mNextAlarmDateTime ) { | 283 | if ( nextA < mNextAlarmDateTime ) { |
271 | deRegisterAlarm(); | 284 | deRegisterAlarm(); |
272 | mNextAlarmDateTime = nextA; | 285 | mNextAlarmDateTime = nextA; |
273 | mNextSummary = incidence->summary(); | 286 | mNextSummary = incidence->summary(); |
274 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; | 287 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; |
275 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 288 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
276 | newNextAlarm = true; | 289 | newNextAlarm = true; |
277 | mNextAlarmIncidence = incidence; | 290 | mNextAlarmIncidence = incidence; |
278 | } else { | 291 | } else { |
279 | if ( incidence == mNextAlarmIncidence ) { | 292 | if ( incidence == mNextAlarmIncidence ) { |
280 | computeNextAlarm = true; | 293 | computeNextAlarm = true; |
281 | } | 294 | } |
282 | } | 295 | } |
283 | } else { | 296 | } else { |
284 | if ( mNextAlarmIncidence == incidence ) { | 297 | if ( mNextAlarmIncidence == incidence ) { |
285 | computeNextAlarm = true; | 298 | computeNextAlarm = true; |
286 | } | 299 | } |
287 | } | 300 | } |
288 | } else { // deleted | 301 | } else { // deleted |
289 | if ( incidence == mNextAlarmIncidence ) { | 302 | if ( incidence == mNextAlarmIncidence ) { |
290 | computeNextAlarm = true; | 303 | computeNextAlarm = true; |
291 | } | 304 | } |
292 | } | 305 | } |
293 | } | 306 | } |
294 | if ( computeNextAlarm ) { | 307 | if ( computeNextAlarm ) { |
295 | deRegisterAlarm(); | 308 | deRegisterAlarm(); |
296 | nextA = nextAlarm( 1000 ); | 309 | nextA = nextAlarm( 1000 ); |
297 | if (! mNextAlarmIncidence ) { | 310 | if (! mNextAlarmIncidence ) { |
298 | return; | 311 | return; |
299 | } | 312 | } |
300 | newNextAlarm = true; | 313 | newNextAlarm = true; |
301 | } | 314 | } |
302 | if ( newNextAlarm ) | 315 | if ( newNextAlarm ) |
303 | registerAlarm(); | 316 | registerAlarm(); |
304 | } | 317 | } |
305 | QString CalendarLocal:: getAlarmNotification() | 318 | QString CalendarLocal:: getAlarmNotification() |
306 | { | 319 | { |
307 | QString ret; | 320 | QString ret; |
308 | // this should not happen | 321 | // this should not happen |
309 | if (! mNextAlarmIncidence ) | 322 | if (! mNextAlarmIncidence ) |
310 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; | 323 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; |
311 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); | 324 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); |
312 | if ( alarm->type() == Alarm::Procedure ) { | 325 | if ( alarm->type() == Alarm::Procedure ) { |
313 | ret = "proc_alarm" + alarm->programFile()+"+++"; | 326 | ret = "proc_alarm" + alarm->programFile()+"+++"; |
314 | } else { | 327 | } else { |
315 | ret = "audio_alarm" +alarm->audioFile() +"+++"; | 328 | ret = "audio_alarm" +alarm->audioFile() +"+++"; |
316 | } | 329 | } |
317 | ret += "cal_alarm"+ mNextSummary.left( 25 ); | 330 | ret += "cal_alarm"+ mNextSummary.left( 25 ); |
318 | if ( mNextSummary.length() > 25 ) | 331 | if ( mNextSummary.length() > 25 ) |
319 | ret += "\n" + mNextSummary.mid(25, 25 ); | 332 | ret += "\n" + mNextSummary.mid(25, 25 ); |
320 | ret+= "\n"+mNextAlarmEventDateTimeString; | 333 | ret+= "\n"+mNextAlarmEventDateTimeString; |
321 | return ret; | 334 | return ret; |
322 | } | 335 | } |
323 | |||
324 | void CalendarLocal::registerAlarm() | 336 | void CalendarLocal::registerAlarm() |
325 | { | 337 | { |
326 | mLastAlarmNotificationString = getAlarmNotification(); | 338 | mLastAlarmNotificationString = getAlarmNotification(); |
327 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); | 339 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); |
328 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 340 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
329 | // #ifndef DESKTOP_VERSION | 341 | // #ifndef DESKTOP_VERSION |
330 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); | 342 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); |
331 | // #endif | 343 | // #endif |
332 | } | 344 | } |
333 | void CalendarLocal::deRegisterAlarm() | 345 | void CalendarLocal::deRegisterAlarm() |
334 | { | 346 | { |
335 | if ( mLastAlarmNotificationString.isNull() ) | 347 | if ( mLastAlarmNotificationString.isNull() ) |
336 | return; | 348 | return; |
337 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); | 349 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); |
338 | 350 | ||
339 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 351 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
340 | // #ifndef DESKTOP_VERSION | 352 | // #ifndef DESKTOP_VERSION |
341 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); | 353 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); |
342 | // #endif | 354 | // #endif |
343 | } | 355 | } |
344 | 356 | ||
345 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) | 357 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) |
346 | { | 358 | { |
347 | QPtrList<Todo> todos; | 359 | QPtrList<Todo> todos; |
348 | 360 | ||
349 | Todo *todo; | 361 | Todo *todo; |
350 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 362 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
351 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { | 363 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { |
352 | todos.append( todo ); | 364 | todos.append( todo ); |
353 | } | 365 | } |
354 | } | 366 | } |
355 | 367 | ||
356 | filter()->apply( &todos ); | 368 | filter()->apply( &todos ); |
357 | return todos; | 369 | return todos; |
358 | } | 370 | } |
359 | void CalendarLocal::reInitAlarmSettings() | 371 | void CalendarLocal::reInitAlarmSettings() |
360 | { | 372 | { |
361 | if ( !mNextAlarmIncidence ) { | 373 | if ( !mNextAlarmIncidence ) { |
362 | nextAlarm( 1000 ); | 374 | nextAlarm( 1000 ); |
363 | } | 375 | } |
364 | deRegisterAlarm(); | 376 | deRegisterAlarm(); |
365 | mNextAlarmIncidence = 0; | 377 | mNextAlarmIncidence = 0; |
366 | checkAlarmForIncidence( 0, false ); | 378 | checkAlarmForIncidence( 0, false ); |
367 | 379 | ||
368 | } | 380 | } |
369 | 381 | ||
370 | 382 | ||
371 | 383 | ||
372 | QDateTime CalendarLocal::nextAlarm( int daysTo ) | 384 | QDateTime CalendarLocal::nextAlarm( int daysTo ) |
373 | { | 385 | { |
374 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); | 386 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); |
375 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); | 387 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); |
376 | QDateTime next; | 388 | QDateTime next; |
377 | Event *e; | 389 | Event *e; |
378 | bool ok; | 390 | bool ok; |
379 | bool found = false; | 391 | bool found = false; |
380 | int offset; | 392 | int offset; |
381 | mNextAlarmIncidence = 0; | 393 | mNextAlarmIncidence = 0; |
382 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 394 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
383 | next = e->getNextAlarmDateTime(& ok, &offset ) ; | 395 | next = e->getNextAlarmDateTime(& ok, &offset ) ; |
384 | if ( ok ) { | 396 | if ( ok ) { |
385 | if ( next < nextA ) { | 397 | if ( next < nextA ) { |
386 | nextA = next; | 398 | nextA = next; |
387 | found = true; | 399 | found = true; |
388 | mNextSummary = e->summary(); | 400 | mNextSummary = e->summary(); |
389 | mNextAlarmEventDateTime = next.addSecs(offset ) ; | 401 | mNextAlarmEventDateTime = next.addSecs(offset ) ; |
390 | mNextAlarmIncidence = (Incidence *) e; | 402 | mNextAlarmIncidence = (Incidence *) e; |
391 | } | 403 | } |
392 | } | 404 | } |
393 | } | 405 | } |
394 | Todo *t; | 406 | Todo *t; |
395 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 407 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
396 | next = t->getNextAlarmDateTime(& ok, &offset ) ; | 408 | next = t->getNextAlarmDateTime(& ok, &offset ) ; |
397 | if ( ok ) { | 409 | if ( ok ) { |
398 | if ( next < nextA ) { | 410 | if ( next < nextA ) { |
399 | nextA = next; | 411 | nextA = next; |
400 | found = true; | 412 | found = true; |
401 | mNextSummary = t->summary(); | 413 | mNextSummary = t->summary(); |
402 | mNextAlarmEventDateTime = next.addSecs(offset ); | 414 | mNextAlarmEventDateTime = next.addSecs(offset ); |
403 | mNextAlarmIncidence = (Incidence *) t; | 415 | mNextAlarmIncidence = (Incidence *) t; |
404 | } | 416 | } |
405 | } | 417 | } |
406 | } | 418 | } |
407 | if ( mNextAlarmIncidence ) { | 419 | if ( mNextAlarmIncidence ) { |
408 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 420 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
409 | mNextAlarmDateTime = nextA; | 421 | mNextAlarmDateTime = nextA; |
410 | } | 422 | } |
411 | return nextA; | 423 | return nextA; |
412 | } | 424 | } |
413 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) | 425 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) |
414 | { | 426 | { |
415 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); | 427 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); |
416 | } | 428 | } |
417 | 429 | ||
418 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) | 430 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) |
419 | { | 431 | { |
420 | kdDebug(5800) << "CalendarLocal::alarms(" << from.toString() << " - " | 432 | kdDebug(5800) << "CalendarLocal::alarms(" << from.toString() << " - " |
421 | << to.toString() << ")\n"; | 433 | << to.toString() << ")\n"; |
422 | 434 | ||
423 | Alarm::List alarms; | 435 | Alarm::List alarms; |
424 | 436 | ||
425 | Event *e; | 437 | Event *e; |
426 | 438 | ||
427 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 439 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
428 | if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); | 440 | if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); |
429 | else appendAlarms( alarms, e, from, to ); | 441 | else appendAlarms( alarms, e, from, to ); |
430 | } | 442 | } |
431 | 443 | ||
432 | Todo *t; | 444 | Todo *t; |
433 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 445 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
434 | appendAlarms( alarms, t, from, to ); | 446 | appendAlarms( alarms, t, from, to ); |
435 | } | 447 | } |
436 | 448 | ||
437 | return alarms; | 449 | return alarms; |
438 | } | 450 | } |
439 | 451 | ||
440 | void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, | 452 | void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, |
441 | const QDateTime &from, const QDateTime &to ) | 453 | const QDateTime &from, const QDateTime &to ) |
442 | { | 454 | { |
443 | QPtrList<Alarm> alarmList = incidence->alarms(); | 455 | QPtrList<Alarm> alarmList = incidence->alarms(); |
444 | Alarm *alarm; | 456 | Alarm *alarm; |
445 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { | 457 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { |
446 | // kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() | 458 | // kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() |
447 | // << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; | 459 | // << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; |
448 | if ( alarm->enabled() ) { | 460 | if ( alarm->enabled() ) { |
449 | if ( alarm->time() >= from && alarm->time() <= to ) { | 461 | if ( alarm->time() >= from && alarm->time() <= to ) { |
450 | kdDebug(5800) << "CalendarLocal::appendAlarms() '" << incidence->summary() | 462 | kdDebug(5800) << "CalendarLocal::appendAlarms() '" << incidence->summary() |
451 | << "': " << alarm->time().toString() << endl; | 463 | << "': " << alarm->time().toString() << endl; |
452 | alarms.append( alarm ); | 464 | alarms.append( alarm ); |
453 | } | 465 | } |
454 | } | 466 | } |
455 | } | 467 | } |
456 | } | 468 | } |
457 | 469 | ||
458 | void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, | 470 | void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, |
459 | Incidence *incidence, | 471 | Incidence *incidence, |
460 | const QDateTime &from, | 472 | const QDateTime &from, |
461 | const QDateTime &to ) | 473 | const QDateTime &to ) |
462 | { | 474 | { |
463 | 475 | ||
464 | QPtrList<Alarm> alarmList = incidence->alarms(); | 476 | QPtrList<Alarm> alarmList = incidence->alarms(); |
465 | Alarm *alarm; | 477 | Alarm *alarm; |
466 | QDateTime qdt; | 478 | QDateTime qdt; |
467 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { | 479 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { |
468 | if (incidence->recursOn(from.date())) { | 480 | if (incidence->recursOn(from.date())) { |
469 | qdt.setTime(alarm->time().time()); | 481 | qdt.setTime(alarm->time().time()); |
470 | qdt.setDate(from.date()); | 482 | qdt.setDate(from.date()); |
471 | } | 483 | } |
472 | else qdt = alarm->time(); | 484 | else qdt = alarm->time(); |
473 | // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); | 485 | // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); |
474 | if ( alarm->enabled() ) { | 486 | if ( alarm->enabled() ) { |
475 | if ( qdt >= from && qdt <= to ) { | 487 | if ( qdt >= from && qdt <= to ) { |
476 | alarms.append( alarm ); | 488 | alarms.append( alarm ); |
477 | } | 489 | } |
478 | } | 490 | } |
479 | } | 491 | } |
480 | } | 492 | } |
481 | 493 | ||
482 | 494 | ||
483 | /****************************** PROTECTED METHODS ****************************/ | 495 | /****************************** PROTECTED METHODS ****************************/ |
484 | 496 | ||
485 | // after changes are made to an event, this should be called. | 497 | // after changes are made to an event, this should be called. |
486 | void CalendarLocal::update( IncidenceBase *incidence ) | 498 | void CalendarLocal::update( IncidenceBase *incidence ) |
487 | { | 499 | { |
488 | incidence->setSyncStatus( Event::SYNCMOD ); | 500 | incidence->setSyncStatus( Event::SYNCMOD ); |
489 | incidence->setLastModified( QDateTime::currentDateTime() ); | 501 | incidence->setLastModified( QDateTime::currentDateTime() ); |
490 | // we should probably update the revision number here, | 502 | // we should probably update the revision number here, |
491 | // or internally in the Event itself when certain things change. | 503 | // or internally in the Event itself when certain things change. |
492 | // need to verify with ical documentation. | 504 | // need to verify with ical documentation. |
493 | 505 | ||
494 | setModified( true ); | 506 | setModified( true ); |
495 | } | 507 | } |
496 | 508 | ||
497 | void CalendarLocal::insertEvent( Event *event ) | 509 | void CalendarLocal::insertEvent( Event *event ) |
498 | { | 510 | { |
499 | if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); | 511 | if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); |
500 | } | 512 | } |
501 | 513 | ||
502 | 514 | ||
503 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) | 515 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) |
504 | { | 516 | { |
505 | QPtrList<Event> eventList; | 517 | QPtrList<Event> eventList; |
506 | 518 | ||
507 | Event *event; | 519 | Event *event; |
508 | for( event = mEventList.first(); event; event = mEventList.next() ) { | 520 | for( event = mEventList.first(); event; event = mEventList.next() ) { |
509 | if ( event->doesRecur() ) { | 521 | if ( event->doesRecur() ) { |
510 | if ( event->isMultiDay() ) { | 522 | if ( event->isMultiDay() ) { |
511 | int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); | 523 | int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); |
512 | int i; | 524 | int i; |
513 | for ( i = 0; i <= extraDays; i++ ) { | 525 | for ( i = 0; i <= extraDays; i++ ) { |
514 | if ( event->recursOn( qd.addDays( -i ) ) ) { | 526 | if ( event->recursOn( qd.addDays( -i ) ) ) { |
515 | eventList.append( event ); | 527 | eventList.append( event ); |
516 | break; | 528 | break; |
517 | } | 529 | } |
518 | } | 530 | } |
519 | } else { | 531 | } else { |
520 | if ( event->recursOn( qd ) ) | 532 | if ( event->recursOn( qd ) ) |
521 | eventList.append( event ); | 533 | eventList.append( event ); |
522 | } | 534 | } |
523 | } else { | 535 | } else { |
524 | if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { | 536 | if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { |
525 | eventList.append( event ); | 537 | eventList.append( event ); |
526 | } | 538 | } |
527 | } | 539 | } |
528 | } | 540 | } |
529 | 541 | ||
530 | if ( !sorted ) { | 542 | if ( !sorted ) { |
531 | return eventList; | 543 | return eventList; |
532 | } | 544 | } |
533 | 545 | ||
534 | // kdDebug(5800) << "Sorting events for date\n" << endl; | 546 | // kdDebug(5800) << "Sorting events for date\n" << endl; |
535 | // now, we have to sort it based on dtStart.time() | 547 | // now, we have to sort it based on dtStart.time() |
536 | QPtrList<Event> eventListSorted; | 548 | QPtrList<Event> eventListSorted; |
537 | Event *sortEvent; | 549 | Event *sortEvent; |
538 | for ( event = eventList.first(); event; event = eventList.next() ) { | 550 | for ( event = eventList.first(); event; event = eventList.next() ) { |
539 | sortEvent = eventListSorted.first(); | 551 | sortEvent = eventListSorted.first(); |
540 | int i = 0; | 552 | int i = 0; |
541 | while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) | 553 | while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) |
542 | { | 554 | { |
543 | i++; | 555 | i++; |
544 | sortEvent = eventListSorted.next(); | 556 | sortEvent = eventListSorted.next(); |
545 | } | 557 | } |
546 | eventListSorted.insert( i, event ); | 558 | eventListSorted.insert( i, event ); |
547 | } | 559 | } |
548 | return eventListSorted; | 560 | return eventListSorted; |
549 | } | 561 | } |
550 | 562 | ||
551 | 563 | ||
552 | QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, | 564 | QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, |
553 | bool inclusive ) | 565 | bool inclusive ) |
554 | { | 566 | { |
555 | Event *event = 0; | 567 | Event *event = 0; |
556 | 568 | ||
557 | QPtrList<Event> eventList; | 569 | QPtrList<Event> eventList; |
558 | 570 | ||
559 | // Get non-recurring events | 571 | // Get non-recurring events |
560 | for( event = mEventList.first(); event; event = mEventList.next() ) { | 572 | for( event = mEventList.first(); event; event = mEventList.next() ) { |
561 | if ( event->doesRecur() ) { | 573 | if ( event->doesRecur() ) { |
562 | QDate rStart = event->dtStart().date(); | 574 | QDate rStart = event->dtStart().date(); |
563 | bool found = false; | 575 | bool found = false; |
564 | if ( inclusive ) { | 576 | if ( inclusive ) { |
565 | if ( rStart >= start && rStart <= end ) { | 577 | if ( rStart >= start && rStart <= end ) { |
566 | // Start date of event is in range. Now check for end date. | 578 | // Start date of event is in range. Now check for end date. |
567 | // if duration is negative, event recurs forever, so do not include it. | 579 | // if duration is negative, event recurs forever, so do not include it. |
568 | if ( event->recurrence()->duration() == 0 ) { // End date set | 580 | if ( event->recurrence()->duration() == 0 ) { // End date set |
569 | QDate rEnd = event->recurrence()->endDate(); | 581 | QDate rEnd = event->recurrence()->endDate(); |
570 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 582 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
571 | found = true; | 583 | found = true; |
572 | } | 584 | } |
573 | } else if ( event->recurrence()->duration() > 0 ) { // Duration set | 585 | } else if ( event->recurrence()->duration() > 0 ) { // Duration set |
574 | // TODO: Calculate end date from duration. Should be done in Event | 586 | // TODO: Calculate end date from duration. Should be done in Event |
575 | // For now exclude all events with a duration. | 587 | // For now exclude all events with a duration. |
576 | } | 588 | } |
577 | } | 589 | } |
578 | } else { | 590 | } else { |
579 | bool founOne; | 591 | bool founOne; |
580 | QDate next = event->getNextOccurence( start, &founOne ).date(); | 592 | QDate next = event->getNextOccurence( start, &founOne ).date(); |
581 | if ( founOne ) { | 593 | if ( founOne ) { |
582 | if ( next <= end ) { | 594 | if ( next <= end ) { |
583 | found = true; | 595 | found = true; |
584 | } | 596 | } |
585 | } | 597 | } |
586 | 598 | ||
587 | /* | 599 | /* |
588 | // crap !!! | 600 | // crap !!! |
589 | if ( rStart <= end ) { // Start date not after range | 601 | if ( rStart <= end ) { // Start date not after range |
590 | if ( rStart >= start ) { // Start date within range | 602 | if ( rStart >= start ) { // Start date within range |
591 | found = true; | 603 | found = true; |
592 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever | 604 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever |
593 | found = true; | 605 | found = true; |
594 | } else if ( event->recurrence()->duration() == 0 ) { // End date set | 606 | } else if ( event->recurrence()->duration() == 0 ) { // End date set |
595 | QDate rEnd = event->recurrence()->endDate(); | 607 | QDate rEnd = event->recurrence()->endDate(); |
596 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 608 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
597 | found = true; | 609 | found = true; |
598 | } | 610 | } |
599 | } else { // Duration set | 611 | } else { // Duration set |
600 | // TODO: Calculate end date from duration. Should be done in Event | 612 | // TODO: Calculate end date from duration. Should be done in Event |
601 | // For now include all events with a duration. | 613 | // For now include all events with a duration. |
602 | found = true; | 614 | found = true; |
603 | } | 615 | } |
604 | } | 616 | } |
605 | */ | 617 | */ |
606 | 618 | ||
607 | } | 619 | } |
608 | 620 | ||
609 | if ( found ) eventList.append( event ); | 621 | if ( found ) eventList.append( event ); |
610 | } else { | 622 | } else { |
611 | QDate s = event->dtStart().date(); | 623 | QDate s = event->dtStart().date(); |
612 | QDate e = event->dtEnd().date(); | 624 | QDate e = event->dtEnd().date(); |
613 | 625 | ||
614 | if ( inclusive ) { | 626 | if ( inclusive ) { |
615 | if ( s >= start && e <= end ) { | 627 | if ( s >= start && e <= end ) { |
616 | eventList.append( event ); | 628 | eventList.append( event ); |
617 | } | 629 | } |
618 | } else { | 630 | } else { |
619 | if ( ( s >= start && s <= end ) || ( e >= start && e <= end ) ) { | 631 | if ( ( s >= start && s <= end ) || ( e >= start && e <= end ) ) { |
620 | eventList.append( event ); | 632 | eventList.append( event ); |
621 | } | 633 | } |
622 | } | 634 | } |
623 | } | 635 | } |
624 | } | 636 | } |
625 | 637 | ||
626 | return eventList; | 638 | return eventList; |
627 | } | 639 | } |
628 | 640 | ||
629 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) | 641 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) |
630 | { | 642 | { |
631 | return rawEventsForDate( qdt.date() ); | 643 | return rawEventsForDate( qdt.date() ); |
632 | } | 644 | } |
633 | 645 | ||
634 | QPtrList<Event> CalendarLocal::rawEvents() | 646 | QPtrList<Event> CalendarLocal::rawEvents() |
635 | { | 647 | { |
636 | return mEventList; | 648 | return mEventList; |
637 | } | 649 | } |
638 | 650 | ||
639 | bool CalendarLocal::addJournal(Journal *journal) | 651 | bool CalendarLocal::addJournal(Journal *journal) |
640 | { | 652 | { |
641 | if ( journal->dtStart().isValid()) | 653 | if ( journal->dtStart().isValid()) |
642 | kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl; | 654 | kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl; |
643 | else | 655 | else |
644 | kdDebug(5800) << "Adding Journal without a DTSTART" << endl; | 656 | kdDebug(5800) << "Adding Journal without a DTSTART" << endl; |
645 | 657 | ||
646 | mJournalList.append(journal); | 658 | mJournalList.append(journal); |
647 | 659 | ||
648 | journal->registerObserver( this ); | 660 | journal->registerObserver( this ); |
649 | 661 | ||
650 | setModified( true ); | 662 | setModified( true ); |
651 | 663 | ||
652 | return true; | 664 | return true; |
653 | } | 665 | } |
654 | 666 | ||
655 | void CalendarLocal::deleteJournal( Journal *journal ) | 667 | void CalendarLocal::deleteJournal( Journal *journal ) |
656 | { | 668 | { |
657 | if ( mJournalList.removeRef(journal) ) { | 669 | if ( mJournalList.removeRef(journal) ) { |
658 | setModified( true ); | 670 | setModified( true ); |
659 | } | 671 | } |
660 | } | 672 | } |
661 | 673 | ||
662 | Journal *CalendarLocal::journal( const QDate &date ) | 674 | Journal *CalendarLocal::journal( const QDate &date ) |
663 | { | 675 | { |
664 | // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; | 676 | // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; |
665 | 677 | ||
666 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 678 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
667 | if ( it->dtStart().date() == date ) | 679 | if ( it->dtStart().date() == date ) |
668 | return it; | 680 | return it; |
669 | 681 | ||
670 | return 0; | 682 | return 0; |
671 | } | 683 | } |
672 | 684 | ||
673 | Journal *CalendarLocal::journal( const QString &uid ) | 685 | Journal *CalendarLocal::journal( const QString &uid ) |
674 | { | 686 | { |
675 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 687 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
676 | if ( it->uid() == uid ) | 688 | if ( it->uid() == uid ) |
677 | return it; | 689 | return it; |
678 | 690 | ||
679 | return 0; | 691 | return 0; |
680 | } | 692 | } |
681 | 693 | ||
682 | QPtrList<Journal> CalendarLocal::journals() | 694 | QPtrList<Journal> CalendarLocal::journals() |
683 | { | 695 | { |
684 | return mJournalList; | 696 | return mJournalList; |
685 | } | 697 | } |
686 | 698 | ||
diff --git a/libkcal/calendarlocal.h b/libkcal/calendarlocal.h index a2e50e3..3257198 100644 --- a/libkcal/calendarlocal.h +++ b/libkcal/calendarlocal.h | |||
@@ -1,217 +1,217 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | 3 | ||
4 | Copyright (c) 1998 Preston Brown | 4 | Copyright (c) 1998 Preston Brown |
5 | Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> | 5 | Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> |
6 | 6 | ||
7 | This library is free software; you can redistribute it and/or | 7 | This library is free software; you can redistribute it and/or |
8 | modify it under the terms of the GNU Library General Public | 8 | modify it under the terms of the GNU Library General Public |
9 | License as published by the Free Software Foundation; either | 9 | License as published by the Free Software Foundation; either |
10 | version 2 of the License, or (at your option) any later version. | 10 | version 2 of the License, or (at your option) any later version. |
11 | 11 | ||
12 | This library is distributed in the hope that it will be useful, | 12 | This library is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | Library General Public License for more details. | 15 | Library General Public License for more details. |
16 | 16 | ||
17 | You should have received a copy of the GNU Library General Public License | 17 | You should have received a copy of the GNU Library General Public License |
18 | along with this library; see the file COPYING.LIB. If not, write to | 18 | along with this library; see the file COPYING.LIB. If not, write to |
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. | 20 | Boston, MA 02111-1307, USA. |
21 | */ | 21 | */ |
22 | #ifndef KCAL_CALENDARLOCAL_H | 22 | #ifndef KCAL_CALENDARLOCAL_H |
23 | #define KCAL_CALENDARLOCAL_H | 23 | #define KCAL_CALENDARLOCAL_H |
24 | 24 | ||
25 | #include "calendar.h" | 25 | #include "calendar.h" |
26 | 26 | ||
27 | namespace KCal { | 27 | namespace KCal { |
28 | 28 | ||
29 | class CalFormat; | 29 | class CalFormat; |
30 | 30 | ||
31 | /** | 31 | /** |
32 | This class provides a calendar stored as a local file. | 32 | This class provides a calendar stored as a local file. |
33 | */ | 33 | */ |
34 | class CalendarLocal : public Calendar | 34 | class CalendarLocal : public Calendar |
35 | { | 35 | { |
36 | public: | 36 | public: |
37 | /** | 37 | /** |
38 | Constructs a new calendar, with variables initialized to sane values. | 38 | Constructs a new calendar, with variables initialized to sane values. |
39 | */ | 39 | */ |
40 | CalendarLocal(); | 40 | CalendarLocal(); |
41 | /** | 41 | /** |
42 | Constructs a new calendar, with variables initialized to sane values. | 42 | Constructs a new calendar, with variables initialized to sane values. |
43 | */ | 43 | */ |
44 | CalendarLocal( const QString &timeZoneId ); | 44 | CalendarLocal( const QString &timeZoneId ); |
45 | ~CalendarLocal(); | 45 | ~CalendarLocal(); |
46 | 46 | ||
47 | /** | 47 | /** |
48 | Loads a calendar on disk in vCalendar or iCalendar format into the current | 48 | Loads a calendar on disk in vCalendar or iCalendar format into the current |
49 | calendar. Any information already present is lost. | 49 | calendar. Any information already present is lost. |
50 | @return true, if successfull, false on error. | 50 | @return true, if successfull, false on error. |
51 | @param fileName the name of the calendar on disk. | 51 | @param fileName the name of the calendar on disk. |
52 | */ | 52 | */ |
53 | bool load( const QString &fileName ); | 53 | bool load( const QString &fileName ); |
54 | /** | 54 | /** |
55 | Writes out the calendar to disk in the specified \a format. | 55 | Writes out the calendar to disk in the specified \a format. |
56 | CalendarLocal takes ownership of the CalFormat object. | 56 | CalendarLocal takes ownership of the CalFormat object. |
57 | @return true, if successfull, false on error. | 57 | @return true, if successfull, false on error. |
58 | @param fileName the name of the file | 58 | @param fileName the name of the file |
59 | */ | 59 | */ |
60 | bool save( const QString &fileName, CalFormat *format = 0 ); | 60 | bool save( const QString &fileName, CalFormat *format = 0 ); |
61 | 61 | ||
62 | /** | 62 | /** |
63 | Clears out the current calendar, freeing all used memory etc. etc. | 63 | Clears out the current calendar, freeing all used memory etc. etc. |
64 | */ | 64 | */ |
65 | void close(); | 65 | void close(); |
66 | 66 | ||
67 | void save() {} | 67 | void save() {} |
68 | 68 | ||
69 | /** | 69 | /** |
70 | Add Event to calendar. | 70 | Add Event to calendar. |
71 | */ | 71 | */ |
72 | bool addAnniversaryNoDup( Event *event ); | 72 | bool addAnniversaryNoDup( Event *event ); |
73 | bool addEventNoDup( Event *event ); | 73 | bool addEventNoDup( Event *event ); |
74 | bool addEvent( Event *event ); | 74 | bool addEvent( Event *event ); |
75 | /** | 75 | /** |
76 | Deletes an event from this calendar. | 76 | Deletes an event from this calendar. |
77 | */ | 77 | */ |
78 | void deleteEvent( Event *event ); | 78 | void deleteEvent( Event *event ); |
79 | 79 | ||
80 | /** | 80 | /** |
81 | Retrieves an event on the basis of the unique string ID. | 81 | Retrieves an event on the basis of the unique string ID. |
82 | */ | 82 | */ |
83 | Event *event( const QString &uid ); | 83 | Event *event( const QString &uid ); |
84 | /** | 84 | /** |
85 | Return unfiltered list of all events in calendar. | 85 | Return unfiltered list of all events in calendar. |
86 | */ | 86 | */ |
87 | QPtrList<Event> rawEvents(); | 87 | QPtrList<Event> rawEvents(); |
88 | 88 | QPtrList<Event> getExternLastSyncEvents(); | |
89 | /** | 89 | /** |
90 | Add a todo to the todolist. | 90 | Add a todo to the todolist. |
91 | */ | 91 | */ |
92 | bool addTodo( Todo *todo ); | 92 | bool addTodo( Todo *todo ); |
93 | bool addTodoNoDup( Todo *todo ); | 93 | bool addTodoNoDup( Todo *todo ); |
94 | /** | 94 | /** |
95 | Remove a todo from the todolist. | 95 | Remove a todo from the todolist. |
96 | */ | 96 | */ |
97 | void deleteTodo( Todo * ); | 97 | void deleteTodo( Todo * ); |
98 | /** | 98 | /** |
99 | Searches todolist for an event with this unique string identifier, | 99 | Searches todolist for an event with this unique string identifier, |
100 | returns a pointer or null. | 100 | returns a pointer or null. |
101 | */ | 101 | */ |
102 | Todo *todo( const QString &uid ); | 102 | Todo *todo( const QString &uid ); |
103 | /** | 103 | /** |
104 | Return list of all todos. | 104 | Return list of all todos. |
105 | */ | 105 | */ |
106 | QPtrList<Todo> rawTodos(); | 106 | QPtrList<Todo> rawTodos(); |
107 | /** | 107 | /** |
108 | Returns list of todos due on the specified date. | 108 | Returns list of todos due on the specified date. |
109 | */ | 109 | */ |
110 | QPtrList<Todo> todos( const QDate &date ); | 110 | QPtrList<Todo> todos( const QDate &date ); |
111 | /** | 111 | /** |
112 | Return list of all todos. | 112 | Return list of all todos. |
113 | 113 | ||
114 | Workaround because compiler does not recognize function of base class. | 114 | Workaround because compiler does not recognize function of base class. |
115 | */ | 115 | */ |
116 | QPtrList<Todo> todos() { return Calendar::todos(); } | 116 | QPtrList<Todo> todos() { return Calendar::todos(); } |
117 | 117 | ||
118 | /** | 118 | /** |
119 | Add a Journal entry to calendar. | 119 | Add a Journal entry to calendar. |
120 | */ | 120 | */ |
121 | bool addJournal( Journal * ); | 121 | bool addJournal( Journal * ); |
122 | /** | 122 | /** |
123 | Remove a Journal from the calendar. | 123 | Remove a Journal from the calendar. |
124 | */ | 124 | */ |
125 | void deleteJournal( Journal * ); | 125 | void deleteJournal( Journal * ); |
126 | /** | 126 | /** |
127 | Return Journal for given date. | 127 | Return Journal for given date. |
128 | */ | 128 | */ |
129 | Journal *journal( const QDate & ); | 129 | Journal *journal( const QDate & ); |
130 | /** | 130 | /** |
131 | Return Journal with given UID. | 131 | Return Journal with given UID. |
132 | */ | 132 | */ |
133 | Journal *journal( const QString &uid ); | 133 | Journal *journal( const QString &uid ); |
134 | /** | 134 | /** |
135 | Return list of all Journals stored in calendar. | 135 | Return list of all Journals stored in calendar. |
136 | */ | 136 | */ |
137 | QPtrList<Journal> journals(); | 137 | QPtrList<Journal> journals(); |
138 | 138 | ||
139 | /** | 139 | /** |
140 | Return all alarms, which ocur in the given time interval. | 140 | Return all alarms, which ocur in the given time interval. |
141 | */ | 141 | */ |
142 | Alarm::List alarms( const QDateTime &from, const QDateTime &to ); | 142 | Alarm::List alarms( const QDateTime &from, const QDateTime &to ); |
143 | 143 | ||
144 | /** | 144 | /** |
145 | Return all alarms, which ocur before given date. | 145 | Return all alarms, which ocur before given date. |
146 | */ | 146 | */ |
147 | Alarm::List alarmsTo( const QDateTime &to ); | 147 | Alarm::List alarmsTo( const QDateTime &to ); |
148 | 148 | ||
149 | QDateTime nextAlarm( int daysTo ) ; | 149 | QDateTime nextAlarm( int daysTo ) ; |
150 | QDateTime nextAlarmEventDateTime() const; | 150 | QDateTime nextAlarmEventDateTime() const; |
151 | void checkAlarmForIncidence( Incidence *, bool deleted ) ; | 151 | void checkAlarmForIncidence( Incidence *, bool deleted ) ; |
152 | void registerAlarm(); | 152 | void registerAlarm(); |
153 | void deRegisterAlarm(); | 153 | void deRegisterAlarm(); |
154 | QString getAlarmNotification(); | 154 | QString getAlarmNotification(); |
155 | QString nextSummary() const ; | 155 | QString nextSummary() const ; |
156 | /** | 156 | /** |
157 | This method should be called whenever a Event is modified directly | 157 | This method should be called whenever a Event is modified directly |
158 | via it's pointer. It makes sure that the calendar is internally | 158 | via it's pointer. It makes sure that the calendar is internally |
159 | consistent. | 159 | consistent. |
160 | */ | 160 | */ |
161 | void update( IncidenceBase *incidence ); | 161 | void update( IncidenceBase *incidence ); |
162 | 162 | ||
163 | /** | 163 | /** |
164 | Builds and then returns a list of all events that match for the | 164 | Builds and then returns a list of all events that match for the |
165 | date specified. useful for dayView, etc. etc. | 165 | date specified. useful for dayView, etc. etc. |
166 | */ | 166 | */ |
167 | QPtrList<Event> rawEventsForDate( const QDate &date, bool sorted = false ); | 167 | QPtrList<Event> rawEventsForDate( const QDate &date, bool sorted = false ); |
168 | /** | 168 | /** |
169 | Get unfiltered events for date \a qdt. | 169 | Get unfiltered events for date \a qdt. |
170 | */ | 170 | */ |
171 | QPtrList<Event> rawEventsForDate( const QDateTime &qdt ); | 171 | QPtrList<Event> rawEventsForDate( const QDateTime &qdt ); |
172 | /** | 172 | /** |
173 | Get unfiltered events in a range of dates. If inclusive is set to true, | 173 | Get unfiltered events in a range of dates. If inclusive is set to true, |
174 | only events are returned, which are completely included in the range. | 174 | only events are returned, which are completely included in the range. |
175 | */ | 175 | */ |
176 | QPtrList<Event> rawEvents( const QDate &start, const QDate &end, | 176 | QPtrList<Event> rawEvents( const QDate &start, const QDate &end, |
177 | bool inclusive = false ); | 177 | bool inclusive = false ); |
178 | Todo *CalendarLocal::todo( int uid ); | 178 | Todo *CalendarLocal::todo( int uid ); |
179 | Event *CalendarLocal::event( int uid ); | 179 | Event *CalendarLocal::event( int uid ); |
180 | 180 | ||
181 | 181 | ||
182 | 182 | ||
183 | protected: | 183 | protected: |
184 | 184 | ||
185 | // Event* mNextAlarmEvent; | 185 | // Event* mNextAlarmEvent; |
186 | QString mNextSummary; | 186 | QString mNextSummary; |
187 | QString mNextAlarmEventDateTimeString; | 187 | QString mNextAlarmEventDateTimeString; |
188 | QString mLastAlarmNotificationString; | 188 | QString mLastAlarmNotificationString; |
189 | QDateTime mNextAlarmEventDateTime; | 189 | QDateTime mNextAlarmEventDateTime; |
190 | QDateTime mNextAlarmDateTime; | 190 | QDateTime mNextAlarmDateTime; |
191 | void reInitAlarmSettings(); | 191 | void reInitAlarmSettings(); |
192 | 192 | ||
193 | /** Notification function of IncidenceBase::Observer. */ | 193 | /** Notification function of IncidenceBase::Observer. */ |
194 | void incidenceUpdated( IncidenceBase *i ) { update( i ); } | 194 | void incidenceUpdated( IncidenceBase *i ) { update( i ); } |
195 | 195 | ||
196 | /** inserts an event into its "proper place" in the calendar. */ | 196 | /** inserts an event into its "proper place" in the calendar. */ |
197 | void insertEvent( Event *event ); | 197 | void insertEvent( Event *event ); |
198 | 198 | ||
199 | /** Append alarms of incidence in interval to list of alarms. */ | 199 | /** Append alarms of incidence in interval to list of alarms. */ |
200 | void appendAlarms( Alarm::List &alarms, Incidence *incidence, | 200 | void appendAlarms( Alarm::List &alarms, Incidence *incidence, |
201 | const QDateTime &from, const QDateTime &to ); | 201 | const QDateTime &from, const QDateTime &to ); |
202 | 202 | ||
203 | /** Append alarms of recurring events in interval to list of alarms. */ | 203 | /** Append alarms of recurring events in interval to list of alarms. */ |
204 | void appendRecurringAlarms( Alarm::List &alarms, Incidence *incidence, | 204 | void appendRecurringAlarms( Alarm::List &alarms, Incidence *incidence, |
205 | const QDateTime &from, const QDateTime &to ); | 205 | const QDateTime &from, const QDateTime &to ); |
206 | 206 | ||
207 | private: | 207 | private: |
208 | void init(); | 208 | void init(); |
209 | 209 | ||
210 | QPtrList<Event> mEventList; | 210 | QPtrList<Event> mEventList; |
211 | QPtrList<Todo> mTodoList; | 211 | QPtrList<Todo> mTodoList; |
212 | QPtrList<Journal> mJournalList; | 212 | QPtrList<Journal> mJournalList; |
213 | }; | 213 | }; |
214 | 214 | ||
215 | } | 215 | } |
216 | 216 | ||
217 | #endif | 217 | #endif |