-rw-r--r-- | libkcal/calendar.h | 1 | ||||
-rw-r--r-- | libkcal/calendarlocal.cpp | 6 | ||||
-rw-r--r-- | libkcal/calendarlocal.h | 1 | ||||
-rw-r--r-- | libkcal/todo.cpp | 4 |
4 files changed, 10 insertions, 2 deletions
diff --git a/libkcal/calendar.h b/libkcal/calendar.h index 3b7b183..2efa355 100644 --- a/libkcal/calendar.h +++ b/libkcal/calendar.h | |||
@@ -1,375 +1,376 @@ | |||
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 | #include "calfilter.h" | 35 | #include "calfilter.h" |
36 | 36 | ||
37 | //#define _TIME_ZONE "-0500" /* hardcoded, overridden in config file. */ | 37 | //#define _TIME_ZONE "-0500" /* hardcoded, overridden in config file. */ |
38 | 38 | ||
39 | class KConfig; | 39 | class KConfig; |
40 | 40 | ||
41 | namespace KCal { | 41 | namespace KCal { |
42 | 42 | ||
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 | Incidence * undoIncidence() { return mUndoIncidence; }; | 68 | Incidence * undoIncidence() { return mUndoIncidence; }; |
69 | bool undoDeleteIncidence(); | 69 | bool undoDeleteIncidence(); |
70 | void deleteIncidence(Incidence *in); | 70 | void deleteIncidence(Incidence *in); |
71 | void resetTempSyncStat(); | 71 | void resetTempSyncStat(); |
72 | void resetPilotStat(int id); | 72 | void resetPilotStat(int id); |
73 | /** | 73 | /** |
74 | Clears out the current calendar, freeing all used memory etc. | 74 | Clears out the current calendar, freeing all used memory etc. |
75 | */ | 75 | */ |
76 | virtual void close() = 0; | 76 | virtual void close() = 0; |
77 | virtual void addCalendar( Calendar* ) = 0; | 77 | virtual void addCalendar( Calendar* ) = 0; |
78 | virtual bool addCalendarFile( QString name, int id ) = 0; | 78 | virtual bool addCalendarFile( QString name, int id ) = 0; |
79 | virtual void setSyncEventsReadOnly() = 0; | 79 | virtual void setSyncEventsReadOnly() = 0; |
80 | virtual void stopAllTodos() = 0; | ||
80 | 81 | ||
81 | /** | 82 | /** |
82 | Sync changes in memory to persistant storage. | 83 | Sync changes in memory to persistant storage. |
83 | */ | 84 | */ |
84 | virtual void save() = 0; | 85 | virtual void save() = 0; |
85 | virtual QPtrList<Event> getExternLastSyncEvents() = 0; | 86 | virtual QPtrList<Event> getExternLastSyncEvents() = 0; |
86 | virtual void removeSyncInfo( QString syncProfile) = 0; | 87 | virtual void removeSyncInfo( QString syncProfile) = 0; |
87 | virtual bool isSaving() { return false; } | 88 | virtual bool isSaving() { return false; } |
88 | 89 | ||
89 | /** | 90 | /** |
90 | Return the owner of the calendar's full name. | 91 | Return the owner of the calendar's full name. |
91 | */ | 92 | */ |
92 | const QString &getOwner() const; | 93 | const QString &getOwner() const; |
93 | /** | 94 | /** |
94 | Set the owner of the calendar. Should be owner's full name. | 95 | Set the owner of the calendar. Should be owner's full name. |
95 | */ | 96 | */ |
96 | void setOwner( const QString &os ); | 97 | void setOwner( const QString &os ); |
97 | /** | 98 | /** |
98 | Return the email address of the calendar owner. | 99 | Return the email address of the calendar owner. |
99 | */ | 100 | */ |
100 | const QString &getEmail(); | 101 | const QString &getEmail(); |
101 | /** | 102 | /** |
102 | Set the email address of the calendar owner. | 103 | Set the email address of the calendar owner. |
103 | */ | 104 | */ |
104 | void setEmail( const QString & ); | 105 | void setEmail( const QString & ); |
105 | 106 | ||
106 | /** | 107 | /** |
107 | Set time zone from a timezone string (e.g. -2:00) | 108 | Set time zone from a timezone string (e.g. -2:00) |
108 | */ | 109 | */ |
109 | void setTimeZone( const QString &tz ); | 110 | void setTimeZone( const QString &tz ); |
110 | /** | 111 | /** |
111 | Set time zone from a minutes value (e.g. -60) | 112 | Set time zone from a minutes value (e.g. -60) |
112 | */ | 113 | */ |
113 | void setTimeZone( int tz ); | 114 | void setTimeZone( int tz ); |
114 | /** | 115 | /** |
115 | Return time zone as offest in minutes. | 116 | Return time zone as offest in minutes. |
116 | */ | 117 | */ |
117 | int getTimeZone() const; | 118 | int getTimeZone() const; |
118 | /** | 119 | /** |
119 | Compute an ISO 8601 format string from the time zone. | 120 | Compute an ISO 8601 format string from the time zone. |
120 | */ | 121 | */ |
121 | QString getTimeZoneStr() const; | 122 | QString getTimeZoneStr() const; |
122 | /** | 123 | /** |
123 | Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal | 124 | Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal |
124 | values). | 125 | values). |
125 | */ | 126 | */ |
126 | void setTimeZoneId( const QString & ); | 127 | void setTimeZoneId( const QString & ); |
127 | /** | 128 | /** |
128 | Return time zone id. | 129 | Return time zone id. |
129 | */ | 130 | */ |
130 | QString timeZoneId() const; | 131 | QString timeZoneId() const; |
131 | /** | 132 | /** |
132 | Use local time, not UTC or a time zone. | 133 | Use local time, not UTC or a time zone. |
133 | */ | 134 | */ |
134 | void setLocalTime(); | 135 | void setLocalTime(); |
135 | /** | 136 | /** |
136 | Return whether local time is being used. | 137 | Return whether local time is being used. |
137 | */ | 138 | */ |
138 | bool isLocalTime() const; | 139 | bool isLocalTime() const; |
139 | 140 | ||
140 | /** | 141 | /** |
141 | Add an incidence to calendar. | 142 | Add an incidence to calendar. |
142 | 143 | ||
143 | @return true on success, false on error. | 144 | @return true on success, false on error. |
144 | */ | 145 | */ |
145 | virtual bool addIncidence( Incidence * ); | 146 | virtual bool addIncidence( Incidence * ); |
146 | 147 | ||
147 | // Adds an incidence and all relatedto incidences to the cal | 148 | // Adds an incidence and all relatedto incidences to the cal |
148 | void addIncidenceBranch( Incidence * ); | 149 | void addIncidenceBranch( Incidence * ); |
149 | /** | 150 | /** |
150 | Return filtered list of all incidences of this calendar. | 151 | Return filtered list of all incidences of this calendar. |
151 | */ | 152 | */ |
152 | virtual QPtrList<Incidence> incidences(); | 153 | virtual QPtrList<Incidence> incidences(); |
153 | 154 | ||
154 | /** | 155 | /** |
155 | Return unfiltered list of all incidences of this calendar. | 156 | Return unfiltered list of all incidences of this calendar. |
156 | */ | 157 | */ |
157 | virtual QPtrList<Incidence> rawIncidences(); | 158 | virtual QPtrList<Incidence> rawIncidences(); |
158 | 159 | ||
159 | /** | 160 | /** |
160 | Adds a Event to this calendar object. | 161 | Adds a Event to this calendar object. |
161 | @param anEvent a pointer to the event to add | 162 | @param anEvent a pointer to the event to add |
162 | 163 | ||
163 | @return true on success, false on error. | 164 | @return true on success, false on error. |
164 | */ | 165 | */ |
165 | virtual bool addEventNoDup( Event *event ) = 0; | 166 | virtual bool addEventNoDup( Event *event ) = 0; |
166 | virtual bool addAnniversaryNoDup( Event *event ) = 0; | 167 | virtual bool addAnniversaryNoDup( Event *event ) = 0; |
167 | virtual bool addEvent( Event *anEvent ) = 0; | 168 | virtual bool addEvent( Event *anEvent ) = 0; |
168 | /** | 169 | /** |
169 | Delete event from calendar. | 170 | Delete event from calendar. |
170 | */ | 171 | */ |
171 | virtual void deleteEvent( Event * ) = 0; | 172 | virtual void deleteEvent( Event * ) = 0; |
172 | /** | 173 | /** |
173 | Retrieves an event on the basis of the unique string ID. | 174 | Retrieves an event on the basis of the unique string ID. |
174 | */ | 175 | */ |
175 | virtual Event *event( const QString &UniqueStr ) = 0; | 176 | virtual Event *event( const QString &UniqueStr ) = 0; |
176 | virtual Event *event( QString, QString ) = 0; | 177 | virtual Event *event( QString, QString ) = 0; |
177 | /** | 178 | /** |
178 | Builds and then returns a list of all events that match for the | 179 | Builds and then returns a list of all events that match for the |
179 | date specified. useful for dayView, etc. etc. | 180 | date specified. useful for dayView, etc. etc. |
180 | The calendar filter is applied. | 181 | The calendar filter is applied. |
181 | */ | 182 | */ |
182 | QPtrList<Event> events( const QDate &date, bool sorted = false); | 183 | QPtrList<Event> events( const QDate &date, bool sorted = false); |
183 | /** | 184 | /** |
184 | Get events, which occur on the given date. | 185 | Get events, which occur on the given date. |
185 | The calendar filter is applied. | 186 | The calendar filter is applied. |
186 | */ | 187 | */ |
187 | QPtrList<Event> events( const QDateTime &qdt ); | 188 | QPtrList<Event> events( const QDateTime &qdt ); |
188 | /** | 189 | /** |
189 | Get events in a range of dates. If inclusive is set to true, only events | 190 | Get events in a range of dates. If inclusive is set to true, only events |
190 | are returned, which are completely included in the range. | 191 | are returned, which are completely included in the range. |
191 | The calendar filter is applied. | 192 | The calendar filter is applied. |
192 | */ | 193 | */ |
193 | QPtrList<Event> events( const QDate &start, const QDate &end, | 194 | QPtrList<Event> events( const QDate &start, const QDate &end, |
194 | bool inclusive = false); | 195 | bool inclusive = false); |
195 | /** | 196 | /** |
196 | Return filtered list of all events in calendar. | 197 | Return filtered list of all events in calendar. |
197 | */ | 198 | */ |
198 | virtual QPtrList<Event> events(); | 199 | virtual QPtrList<Event> events(); |
199 | /** | 200 | /** |
200 | Return unfiltered list of all events in calendar. | 201 | Return unfiltered list of all events in calendar. |
201 | */ | 202 | */ |
202 | virtual QPtrList<Event> rawEvents() = 0; | 203 | virtual QPtrList<Event> rawEvents() = 0; |
203 | 204 | ||
204 | /** | 205 | /** |
205 | Add a todo to the todolist. | 206 | Add a todo to the todolist. |
206 | 207 | ||
207 | @return true on success, false on error. | 208 | @return true on success, false on error. |
208 | */ | 209 | */ |
209 | virtual bool addTodo( Todo *todo ) = 0; | 210 | virtual bool addTodo( Todo *todo ) = 0; |
210 | virtual bool addTodoNoDup( Todo *todo ) = 0; | 211 | virtual bool addTodoNoDup( Todo *todo ) = 0; |
211 | /** | 212 | /** |
212 | Remove a todo from the todolist. | 213 | Remove a todo from the todolist. |
213 | */ | 214 | */ |
214 | virtual void deleteTodo( Todo * ) = 0; | 215 | virtual void deleteTodo( Todo * ) = 0; |
215 | virtual void deleteJournal( Journal * ) = 0; | 216 | virtual void deleteJournal( Journal * ) = 0; |
216 | /** | 217 | /** |
217 | Return filterd list of todos. | 218 | Return filterd list of todos. |
218 | */ | 219 | */ |
219 | virtual QPtrList<Todo> todos(); | 220 | virtual QPtrList<Todo> todos(); |
220 | /** | 221 | /** |
221 | Searches todolist for an event with this unique string identifier, | 222 | Searches todolist for an event with this unique string identifier, |
222 | returns a pointer or null. | 223 | returns a pointer or null. |
223 | */ | 224 | */ |
224 | virtual Todo *todo( const QString &uid ) = 0; | 225 | virtual Todo *todo( const QString &uid ) = 0; |
225 | virtual Todo *todo( QString, QString ) = 0; | 226 | virtual Todo *todo( QString, QString ) = 0; |
226 | /** | 227 | /** |
227 | Returns list of todos due on the specified date. | 228 | Returns list of todos due on the specified date. |
228 | */ | 229 | */ |
229 | virtual QPtrList<Todo> todos( const QDate &date ) = 0; | 230 | virtual QPtrList<Todo> todos( const QDate &date ) = 0; |
230 | /** | 231 | /** |
231 | Return unfiltered list of todos. | 232 | Return unfiltered list of todos. |
232 | */ | 233 | */ |
233 | virtual QPtrList<Todo> rawTodos() = 0; | 234 | virtual QPtrList<Todo> rawTodos() = 0; |
234 | 235 | ||
235 | /** | 236 | /** |
236 | Add a Journal entry to calendar. | 237 | Add a Journal entry to calendar. |
237 | 238 | ||
238 | @return true on success, false on error. | 239 | @return true on success, false on error. |
239 | */ | 240 | */ |
240 | virtual bool addJournal( Journal * ) = 0; | 241 | virtual bool addJournal( Journal * ) = 0; |
241 | /** | 242 | /** |
242 | Return Journal for given date. | 243 | Return Journal for given date. |
243 | */ | 244 | */ |
244 | virtual Journal *journal( const QDate & ) = 0; | 245 | virtual Journal *journal( const QDate & ) = 0; |
245 | /** | 246 | /** |
246 | Return Journal with given UID. | 247 | Return Journal with given UID. |
247 | */ | 248 | */ |
248 | virtual Journal *journal( const QString &UID ) = 0; | 249 | virtual Journal *journal( const QString &UID ) = 0; |
249 | /** | 250 | /** |
250 | Return list of all Journal entries. | 251 | Return list of all Journal entries. |
251 | */ | 252 | */ |
252 | virtual QPtrList<Journal> journals() = 0; | 253 | virtual QPtrList<Journal> journals() = 0; |
253 | 254 | ||
254 | /** | 255 | /** |
255 | Searches all incidence types for an incidence with this unique | 256 | Searches all incidence types for an incidence with this unique |
256 | string identifier, returns a pointer or null. | 257 | string identifier, returns a pointer or null. |
257 | */ | 258 | */ |
258 | Incidence* incidence( const QString&UID ); | 259 | Incidence* incidence( const QString&UID ); |
259 | 260 | ||
260 | /** | 261 | /** |
261 | Setup relations for an incidence. | 262 | Setup relations for an incidence. |
262 | */ | 263 | */ |
263 | virtual void setupRelations( Incidence * ); | 264 | virtual void setupRelations( Incidence * ); |
264 | /** | 265 | /** |
265 | Remove all relations to an incidence | 266 | Remove all relations to an incidence |
266 | */ | 267 | */ |
267 | virtual void removeRelations( Incidence * ); | 268 | virtual void removeRelations( Incidence * ); |
268 | 269 | ||
269 | /** | 270 | /** |
270 | Set calendar filter, which filters events for the events() functions. | 271 | Set calendar filter, which filters events for the events() functions. |
271 | The Filter object is owned by the caller. | 272 | The Filter object is owned by the caller. |
272 | */ | 273 | */ |
273 | void setFilter( CalFilter * ); | 274 | void setFilter( CalFilter * ); |
274 | /** | 275 | /** |
275 | Return calendar filter. | 276 | Return calendar filter. |
276 | */ | 277 | */ |
277 | CalFilter *filter(); | 278 | CalFilter *filter(); |
278 | virtual QDateTime nextAlarm( int daysTo ) = 0; | 279 | virtual QDateTime nextAlarm( int daysTo ) = 0; |
279 | virtual QString nextSummary( ) const = 0; | 280 | virtual QString nextSummary( ) const = 0; |
280 | virtual void reInitAlarmSettings() = 0; | 281 | virtual void reInitAlarmSettings() = 0; |
281 | virtual QDateTime nextAlarmEventDateTime() const = 0; | 282 | virtual QDateTime nextAlarmEventDateTime() const = 0; |
282 | virtual void checkAlarmForIncidence( Incidence *, bool ) = 0; | 283 | virtual void checkAlarmForIncidence( Incidence *, bool ) = 0; |
283 | /** | 284 | /** |
284 | Return all alarms, which ocur in the given time interval. | 285 | Return all alarms, which ocur in the given time interval. |
285 | */ | 286 | */ |
286 | virtual Alarm::List alarms( const QDateTime &from, | 287 | virtual Alarm::List alarms( const QDateTime &from, |
287 | const QDateTime &to ) = 0; | 288 | const QDateTime &to ) = 0; |
288 | 289 | ||
289 | class Observer { | 290 | class Observer { |
290 | public: | 291 | public: |
291 | virtual void calendarModified( bool, Calendar * ) = 0; | 292 | virtual void calendarModified( bool, Calendar * ) = 0; |
292 | }; | 293 | }; |
293 | 294 | ||
294 | void registerObserver( Observer * ); | 295 | void registerObserver( Observer * ); |
295 | 296 | ||
296 | void setModified( bool ); | 297 | void setModified( bool ); |
297 | 298 | ||
298 | /** | 299 | /** |
299 | Set product id returned by loadedProductId(). This function is only | 300 | Set product id returned by loadedProductId(). This function is only |
300 | useful for the calendar loading code. | 301 | useful for the calendar loading code. |
301 | */ | 302 | */ |
302 | void setLoadedProductId( const QString & ); | 303 | void setLoadedProductId( const QString & ); |
303 | /** | 304 | /** |
304 | Return product id taken from file that has been loaded. Returns | 305 | Return product id taken from file that has been loaded. Returns |
305 | QString::null, if no calendar has been loaded. | 306 | QString::null, if no calendar has been loaded. |
306 | */ | 307 | */ |
307 | QString loadedProductId(); | 308 | QString loadedProductId(); |
308 | int defaultCalendar(); | 309 | int defaultCalendar(); |
309 | void setDontDeleteIncidencesOnClose (); | 310 | void setDontDeleteIncidencesOnClose (); |
310 | public slots: | 311 | public slots: |
311 | void setDefaultCalendar( int ); | 312 | void setDefaultCalendar( int ); |
312 | virtual void setCalendarEnabled( int id, bool enable ) = 0; | 313 | virtual void setCalendarEnabled( int id, bool enable ) = 0; |
313 | virtual void setAlarmEnabled( int id, bool enable ) = 0; | 314 | virtual void setAlarmEnabled( int id, bool enable ) = 0; |
314 | virtual void setReadOnly( int id, bool enable ) = 0; | 315 | virtual void setReadOnly( int id, bool enable ) = 0; |
315 | virtual void setDefaultCalendarEnabledOnly() = 0; | 316 | virtual void setDefaultCalendarEnabledOnly() = 0; |
316 | virtual void setCalendarRemove( int id ) = 0; | 317 | virtual void setCalendarRemove( int id ) = 0; |
317 | signals: | 318 | signals: |
318 | void calendarChanged(); | 319 | void calendarChanged(); |
319 | void calendarSaved(); | 320 | void calendarSaved(); |
320 | void calendarLoaded(); | 321 | void calendarLoaded(); |
321 | void addAlarm(const QDateTime &qdt, const QString ¬i ); | 322 | void addAlarm(const QDateTime &qdt, const QString ¬i ); |
322 | void removeAlarm(const QDateTime &qdt, const QString ¬i ); | 323 | void removeAlarm(const QDateTime &qdt, const QString ¬i ); |
323 | 324 | ||
324 | protected: | 325 | protected: |
325 | /** | 326 | /** |
326 | Get unfiltered events, which occur on the given date. | 327 | Get unfiltered events, which occur on the given date. |
327 | */ | 328 | */ |
328 | virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0; | 329 | virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0; |
329 | /** | 330 | /** |
330 | Get unfiltered events, which occur on the given date. | 331 | Get unfiltered events, which occur on the given date. |
331 | */ | 332 | */ |
332 | virtual QPtrList<Event> rawEventsForDate( const QDate &date, | 333 | virtual QPtrList<Event> rawEventsForDate( const QDate &date, |
333 | bool sorted = false ) = 0; | 334 | bool sorted = false ) = 0; |
334 | /** | 335 | /** |
335 | Get events in a range of dates. If inclusive is set to true, only events | 336 | Get events in a range of dates. If inclusive is set to true, only events |
336 | are returned, which are completely included in the range. | 337 | are returned, which are completely included in the range. |
337 | */ | 338 | */ |
338 | virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end, | 339 | virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end, |
339 | bool inclusive = false ) = 0; | 340 | bool inclusive = false ) = 0; |
340 | 341 | ||
341 | Incidence *mNextAlarmIncidence; | 342 | Incidence *mNextAlarmIncidence; |
342 | Incidence *mUndoIncidence; | 343 | Incidence *mUndoIncidence; |
343 | int mDefaultCalendar; | 344 | int mDefaultCalendar; |
344 | bool mDeleteIncidencesOnClose; | 345 | bool mDeleteIncidencesOnClose; |
345 | 346 | ||
346 | private: | 347 | private: |
347 | void init(); | 348 | void init(); |
348 | 349 | ||
349 | QString mOwner; // who the calendar belongs to | 350 | QString mOwner; // who the calendar belongs to |
350 | QString mOwnerEmail; // email address of the owner | 351 | QString mOwnerEmail; // email address of the owner |
351 | int mTimeZone; // timezone OFFSET from GMT (MINUTES) | 352 | int mTimeZone; // timezone OFFSET from GMT (MINUTES) |
352 | bool mLocalTime; // use local time, not UTC or a time zone | 353 | bool mLocalTime; // use local time, not UTC or a time zone |
353 | 354 | ||
354 | 355 | ||
355 | CalFilter *mFilter; | 356 | CalFilter *mFilter; |
356 | CalFilter *mDefaultFilter; | 357 | CalFilter *mDefaultFilter; |
357 | 358 | ||
358 | 359 | ||
359 | QString mTimeZoneId; | 360 | QString mTimeZoneId; |
360 | 361 | ||
361 | Observer *mObserver; | 362 | Observer *mObserver; |
362 | bool mNewObserver; | 363 | bool mNewObserver; |
363 | 364 | ||
364 | bool mModified; | 365 | bool mModified; |
365 | 366 | ||
366 | QString mLoadedProductId; | 367 | QString mLoadedProductId; |
367 | 368 | ||
368 | // This list is used to put together related todos | 369 | // This list is used to put together related todos |
369 | QDict<Incidence> mOrphans; | 370 | QDict<Incidence> mOrphans; |
370 | QDict<Incidence> mOrphanUids; | 371 | QDict<Incidence> mOrphanUids; |
371 | }; | 372 | }; |
372 | 373 | ||
373 | } | 374 | } |
374 | 375 | ||
375 | #endif | 376 | #endif |
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index 8c4dde1..18f1af8 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp | |||
@@ -1,533 +1,539 @@ | |||
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 | if ( mDeleteIncidencesOnClose ) | 68 | if ( mDeleteIncidencesOnClose ) |
69 | close(); | 69 | close(); |
70 | } | 70 | } |
71 | bool CalendarLocal::addCalendarFile( QString name, int id ) | 71 | bool CalendarLocal::addCalendarFile( QString name, int id ) |
72 | { | 72 | { |
73 | CalendarLocal calendar( timeZoneId() ); | 73 | CalendarLocal calendar( timeZoneId() ); |
74 | calendar.setDefaultCalendar( id ); | 74 | calendar.setDefaultCalendar( id ); |
75 | if ( calendar.load( name ) ) { | 75 | if ( calendar.load( name ) ) { |
76 | addCalendar( &calendar ); | 76 | addCalendar( &calendar ); |
77 | return true; | 77 | return true; |
78 | } | 78 | } |
79 | return false; | 79 | return false; |
80 | } | 80 | } |
81 | void CalendarLocal::setSyncEventsReadOnly() | 81 | void CalendarLocal::setSyncEventsReadOnly() |
82 | { | 82 | { |
83 | Event * ev; | 83 | Event * ev; |
84 | ev = mEventList.first(); | 84 | ev = mEventList.first(); |
85 | while ( ev ) { | 85 | while ( ev ) { |
86 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) | 86 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) |
87 | ev->setReadOnly( true ); | 87 | ev->setReadOnly( true ); |
88 | ev = mEventList.next(); | 88 | ev = mEventList.next(); |
89 | } | 89 | } |
90 | } | 90 | } |
91 | void CalendarLocal::addCalendar( Calendar* cal ) | 91 | void CalendarLocal::addCalendar( Calendar* cal ) |
92 | { | 92 | { |
93 | cal->setDontDeleteIncidencesOnClose(); | 93 | cal->setDontDeleteIncidencesOnClose(); |
94 | { | 94 | { |
95 | QPtrList<Event> EventList = cal->rawEvents(); | 95 | QPtrList<Event> EventList = cal->rawEvents(); |
96 | Event * ev = EventList.first(); | 96 | Event * ev = EventList.first(); |
97 | while ( ev ) { | 97 | while ( ev ) { |
98 | ev->unRegisterObserver( cal ); | 98 | ev->unRegisterObserver( cal ); |
99 | ev->registerObserver( this ); | 99 | ev->registerObserver( this ); |
100 | mEventList.append( ev ); | 100 | mEventList.append( ev ); |
101 | ev = EventList.next(); | 101 | ev = EventList.next(); |
102 | } | 102 | } |
103 | } | 103 | } |
104 | { | 104 | { |
105 | 105 | ||
106 | QPtrList<Todo> TodoList = cal->rawTodos(); | 106 | QPtrList<Todo> TodoList = cal->rawTodos(); |
107 | Todo * ev = TodoList.first(); | 107 | Todo * ev = TodoList.first(); |
108 | while ( ev ) { | 108 | while ( ev ) { |
109 | QString rel = ev->relatedToUid(); | 109 | QString rel = ev->relatedToUid(); |
110 | if ( !rel.isEmpty() ){ | 110 | if ( !rel.isEmpty() ){ |
111 | ev->setRelatedTo ( 0 ); | 111 | ev->setRelatedTo ( 0 ); |
112 | ev->setRelatedToUid( rel ); | 112 | ev->setRelatedToUid( rel ); |
113 | } | 113 | } |
114 | ev = TodoList.next(); | 114 | ev = TodoList.next(); |
115 | } | 115 | } |
116 | //TodoList = cal->rawTodos(); | 116 | //TodoList = cal->rawTodos(); |
117 | ev = TodoList.first(); | 117 | ev = TodoList.first(); |
118 | while ( ev ) { | 118 | while ( ev ) { |
119 | ev->unRegisterObserver( cal ); | 119 | ev->unRegisterObserver( cal ); |
120 | ev->registerObserver( this ); | 120 | ev->registerObserver( this ); |
121 | mTodoList.append( ev ); | 121 | mTodoList.append( ev ); |
122 | setupRelations( ev ); | 122 | setupRelations( ev ); |
123 | ev = TodoList.next(); | 123 | ev = TodoList.next(); |
124 | } | 124 | } |
125 | } | 125 | } |
126 | { | 126 | { |
127 | QPtrList<Journal> JournalList = cal->journals(); | 127 | QPtrList<Journal> JournalList = cal->journals(); |
128 | Journal * ev = JournalList.first(); | 128 | Journal * ev = JournalList.first(); |
129 | while ( ev ) { | 129 | while ( ev ) { |
130 | ev->unRegisterObserver( cal ); | 130 | ev->unRegisterObserver( cal ); |
131 | ev->registerObserver( this ); | 131 | ev->registerObserver( this ); |
132 | mJournalList.append( ev ); | 132 | mJournalList.append( ev ); |
133 | ev = JournalList.next(); | 133 | ev = JournalList.next(); |
134 | } | 134 | } |
135 | } | 135 | } |
136 | setModified( true ); | 136 | setModified( true ); |
137 | } | 137 | } |
138 | bool CalendarLocal::load( const QString &fileName ) | 138 | bool CalendarLocal::load( const QString &fileName ) |
139 | { | 139 | { |
140 | FileStorage storage( this, fileName ); | 140 | FileStorage storage( this, fileName ); |
141 | return storage.load(); | 141 | return storage.load(); |
142 | } | 142 | } |
143 | 143 | ||
144 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) | 144 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) |
145 | { | 145 | { |
146 | FileStorage storage( this, fileName, format ); | 146 | FileStorage storage( this, fileName, format ); |
147 | return storage.save(); | 147 | return storage.save(); |
148 | } | 148 | } |
149 | 149 | ||
150 | void CalendarLocal::stopAllTodos() | ||
151 | { | ||
152 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | ||
153 | it->setRunning( false ); | ||
154 | |||
155 | } | ||
150 | void CalendarLocal::close() | 156 | void CalendarLocal::close() |
151 | { | 157 | { |
152 | 158 | ||
153 | Todo * i; | 159 | Todo * i; |
154 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); | 160 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); |
155 | 161 | ||
156 | mEventList.setAutoDelete( true ); | 162 | mEventList.setAutoDelete( true ); |
157 | mTodoList.setAutoDelete( true ); | 163 | mTodoList.setAutoDelete( true ); |
158 | mJournalList.setAutoDelete( false ); | 164 | mJournalList.setAutoDelete( false ); |
159 | 165 | ||
160 | mEventList.clear(); | 166 | mEventList.clear(); |
161 | mTodoList.clear(); | 167 | mTodoList.clear(); |
162 | mJournalList.clear(); | 168 | mJournalList.clear(); |
163 | 169 | ||
164 | mEventList.setAutoDelete( false ); | 170 | mEventList.setAutoDelete( false ); |
165 | mTodoList.setAutoDelete( false ); | 171 | mTodoList.setAutoDelete( false ); |
166 | mJournalList.setAutoDelete( false ); | 172 | mJournalList.setAutoDelete( false ); |
167 | 173 | ||
168 | setModified( false ); | 174 | setModified( false ); |
169 | } | 175 | } |
170 | 176 | ||
171 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) | 177 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) |
172 | { | 178 | { |
173 | QString cat; | 179 | QString cat; |
174 | bool isBirthday = true; | 180 | bool isBirthday = true; |
175 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { | 181 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { |
176 | isBirthday = false; | 182 | isBirthday = false; |
177 | cat = i18n( "Anniversary" ); | 183 | cat = i18n( "Anniversary" ); |
178 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { | 184 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { |
179 | isBirthday = true; | 185 | isBirthday = true; |
180 | cat = i18n( "Birthday" ); | 186 | cat = i18n( "Birthday" ); |
181 | } else { | 187 | } else { |
182 | qDebug("addAnniversaryNoDup called without fitting category! "); | 188 | qDebug("addAnniversaryNoDup called without fitting category! "); |
183 | return false; | 189 | return false; |
184 | } | 190 | } |
185 | Event * eve; | 191 | Event * eve; |
186 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 192 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
187 | if ( !(eve->categories().contains( cat ) )) | 193 | if ( !(eve->categories().contains( cat ) )) |
188 | continue; | 194 | continue; |
189 | // now we have an event with fitting category | 195 | // now we have an event with fitting category |
190 | if ( eve->dtStart().date() != event->dtStart().date() ) | 196 | if ( eve->dtStart().date() != event->dtStart().date() ) |
191 | continue; | 197 | continue; |
192 | // now we have an event with fitting category+date | 198 | // now we have an event with fitting category+date |
193 | if ( eve->summary() != event->summary() ) | 199 | if ( eve->summary() != event->summary() ) |
194 | continue; | 200 | continue; |
195 | // now we have an event with fitting category+date+summary | 201 | // now we have an event with fitting category+date+summary |
196 | return false; | 202 | return false; |
197 | } | 203 | } |
198 | return addEvent( event ); | 204 | return addEvent( event ); |
199 | 205 | ||
200 | } | 206 | } |
201 | bool CalendarLocal::addEventNoDup( Event *event ) | 207 | bool CalendarLocal::addEventNoDup( Event *event ) |
202 | { | 208 | { |
203 | Event * eve; | 209 | Event * eve; |
204 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 210 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
205 | if ( *eve == *event ) { | 211 | if ( *eve == *event ) { |
206 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); | 212 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); |
207 | return false; | 213 | return false; |
208 | } | 214 | } |
209 | } | 215 | } |
210 | return addEvent( event ); | 216 | return addEvent( event ); |
211 | } | 217 | } |
212 | 218 | ||
213 | bool CalendarLocal::addEvent( Event *event ) | 219 | bool CalendarLocal::addEvent( Event *event ) |
214 | { | 220 | { |
215 | insertEvent( event ); | 221 | insertEvent( event ); |
216 | 222 | ||
217 | event->registerObserver( this ); | 223 | event->registerObserver( this ); |
218 | 224 | ||
219 | setModified( true ); | 225 | setModified( true ); |
220 | event->setCalID( mDefaultCalendar ); | 226 | event->setCalID( mDefaultCalendar ); |
221 | event->setCalEnabled( true ); | 227 | event->setCalEnabled( true ); |
222 | 228 | ||
223 | return true; | 229 | return true; |
224 | } | 230 | } |
225 | 231 | ||
226 | void CalendarLocal::deleteEvent( Event *event ) | 232 | void CalendarLocal::deleteEvent( Event *event ) |
227 | { | 233 | { |
228 | if ( mUndoIncidence ) delete mUndoIncidence; | 234 | if ( mUndoIncidence ) delete mUndoIncidence; |
229 | mUndoIncidence = event->clone(); | 235 | mUndoIncidence = event->clone(); |
230 | if ( mEventList.removeRef( event ) ) { | 236 | if ( mEventList.removeRef( event ) ) { |
231 | setModified( true ); | 237 | setModified( true ); |
232 | } | 238 | } |
233 | } | 239 | } |
234 | 240 | ||
235 | 241 | ||
236 | Event *CalendarLocal::event( const QString &uid ) | 242 | Event *CalendarLocal::event( const QString &uid ) |
237 | { | 243 | { |
238 | Event *event; | 244 | Event *event; |
239 | Event *retVal = 0; | 245 | Event *retVal = 0; |
240 | for ( event = mEventList.first(); event; event = mEventList.next() ) { | 246 | for ( event = mEventList.first(); event; event = mEventList.next() ) { |
241 | if ( event->calEnabled() && event->uid() == uid ) { | 247 | if ( event->calEnabled() && event->uid() == uid ) { |
242 | if ( retVal ) { | 248 | if ( retVal ) { |
243 | if ( retVal->calID() > event->calID() ) { | 249 | if ( retVal->calID() > event->calID() ) { |
244 | retVal = event; | 250 | retVal = event; |
245 | } | 251 | } |
246 | } else { | 252 | } else { |
247 | retVal = event; | 253 | retVal = event; |
248 | } | 254 | } |
249 | } | 255 | } |
250 | } | 256 | } |
251 | return retVal; | 257 | return retVal; |
252 | } | 258 | } |
253 | bool CalendarLocal::addTodoNoDup( Todo *todo ) | 259 | bool CalendarLocal::addTodoNoDup( Todo *todo ) |
254 | { | 260 | { |
255 | Todo * eve; | 261 | Todo * eve; |
256 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { | 262 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { |
257 | if ( *eve == *todo ) { | 263 | if ( *eve == *todo ) { |
258 | //qDebug("duplicate todo found! not inserted! "); | 264 | //qDebug("duplicate todo found! not inserted! "); |
259 | return false; | 265 | return false; |
260 | } | 266 | } |
261 | } | 267 | } |
262 | return addTodo( todo ); | 268 | return addTodo( todo ); |
263 | } | 269 | } |
264 | bool CalendarLocal::addTodo( Todo *todo ) | 270 | bool CalendarLocal::addTodo( Todo *todo ) |
265 | { | 271 | { |
266 | mTodoList.append( todo ); | 272 | mTodoList.append( todo ); |
267 | 273 | ||
268 | todo->registerObserver( this ); | 274 | todo->registerObserver( this ); |
269 | 275 | ||
270 | // Set up subtask relations | 276 | // Set up subtask relations |
271 | setupRelations( todo ); | 277 | setupRelations( todo ); |
272 | 278 | ||
273 | setModified( true ); | 279 | setModified( true ); |
274 | todo->setCalID( mDefaultCalendar ); | 280 | todo->setCalID( mDefaultCalendar ); |
275 | todo->setCalEnabled( true ); | 281 | todo->setCalEnabled( true ); |
276 | return true; | 282 | return true; |
277 | } | 283 | } |
278 | 284 | ||
279 | void CalendarLocal::deleteTodo( Todo *todo ) | 285 | void CalendarLocal::deleteTodo( Todo *todo ) |
280 | { | 286 | { |
281 | // Handle orphaned children | 287 | // Handle orphaned children |
282 | if ( mUndoIncidence ) delete mUndoIncidence; | 288 | if ( mUndoIncidence ) delete mUndoIncidence; |
283 | removeRelations( todo ); | 289 | removeRelations( todo ); |
284 | mUndoIncidence = todo->clone(); | 290 | mUndoIncidence = todo->clone(); |
285 | 291 | ||
286 | if ( mTodoList.removeRef( todo ) ) { | 292 | if ( mTodoList.removeRef( todo ) ) { |
287 | setModified( true ); | 293 | setModified( true ); |
288 | } | 294 | } |
289 | } | 295 | } |
290 | 296 | ||
291 | QPtrList<Todo> CalendarLocal::rawTodos() | 297 | QPtrList<Todo> CalendarLocal::rawTodos() |
292 | { | 298 | { |
293 | QPtrList<Todo> el; | 299 | QPtrList<Todo> el; |
294 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 300 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
295 | if ( it->calEnabled() ) el.append( it ); | 301 | if ( it->calEnabled() ) el.append( it ); |
296 | return el; | 302 | return el; |
297 | } | 303 | } |
298 | Todo *CalendarLocal::todo( QString syncProf, QString id ) | 304 | Todo *CalendarLocal::todo( QString syncProf, QString id ) |
299 | { | 305 | { |
300 | Todo *todo; | 306 | Todo *todo; |
301 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 307 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
302 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; | 308 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; |
303 | } | 309 | } |
304 | 310 | ||
305 | return 0; | 311 | return 0; |
306 | } | 312 | } |
307 | void CalendarLocal::removeSyncInfo( QString syncProfile) | 313 | void CalendarLocal::removeSyncInfo( QString syncProfile) |
308 | { | 314 | { |
309 | QPtrList<Incidence> all = rawIncidences() ; | 315 | QPtrList<Incidence> all = rawIncidences() ; |
310 | Incidence *inc; | 316 | Incidence *inc; |
311 | for ( inc = all.first(); inc; inc = all.next() ) { | 317 | for ( inc = all.first(); inc; inc = all.next() ) { |
312 | inc->removeID( syncProfile ); | 318 | inc->removeID( syncProfile ); |
313 | } | 319 | } |
314 | if ( syncProfile.isEmpty() ) { | 320 | if ( syncProfile.isEmpty() ) { |
315 | QPtrList<Event> el; | 321 | QPtrList<Event> el; |
316 | Event *todo; | 322 | Event *todo; |
317 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 323 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
318 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 324 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
319 | el.append( todo ); | 325 | el.append( todo ); |
320 | } | 326 | } |
321 | for ( todo = el.first(); todo; todo = el.next() ) { | 327 | for ( todo = el.first(); todo; todo = el.next() ) { |
322 | deleteIncidence ( todo ); | 328 | deleteIncidence ( todo ); |
323 | } | 329 | } |
324 | } else { | 330 | } else { |
325 | Event *lse = event( "last-syncEvent-"+ syncProfile); | 331 | Event *lse = event( "last-syncEvent-"+ syncProfile); |
326 | if ( lse ) | 332 | if ( lse ) |
327 | deleteIncidence ( lse ); | 333 | deleteIncidence ( lse ); |
328 | } | 334 | } |
329 | } | 335 | } |
330 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() | 336 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() |
331 | { | 337 | { |
332 | QPtrList<Event> el; | 338 | QPtrList<Event> el; |
333 | Event *todo; | 339 | Event *todo; |
334 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 340 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
335 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 341 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
336 | if ( todo->summary().left(3) == "E: " ) | 342 | if ( todo->summary().left(3) == "E: " ) |
337 | el.append( todo ); | 343 | el.append( todo ); |
338 | } | 344 | } |
339 | 345 | ||
340 | return el; | 346 | return el; |
341 | 347 | ||
342 | } | 348 | } |
343 | Event *CalendarLocal::event( QString syncProf, QString id ) | 349 | Event *CalendarLocal::event( QString syncProf, QString id ) |
344 | { | 350 | { |
345 | Event *todo; | 351 | Event *todo; |
346 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 352 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
347 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; | 353 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; |
348 | } | 354 | } |
349 | 355 | ||
350 | return 0; | 356 | return 0; |
351 | } | 357 | } |
352 | Todo *CalendarLocal::todo( const QString &uid ) | 358 | Todo *CalendarLocal::todo( const QString &uid ) |
353 | { | 359 | { |
354 | Todo *todo;; | 360 | Todo *todo;; |
355 | Todo *retVal = 0; | 361 | Todo *retVal = 0; |
356 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 362 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
357 | if ( todo->calEnabled() && todo->uid() == uid ) { | 363 | if ( todo->calEnabled() && todo->uid() == uid ) { |
358 | if ( retVal ) { | 364 | if ( retVal ) { |
359 | if ( retVal->calID() > todo->calID() ) { | 365 | if ( retVal->calID() > todo->calID() ) { |
360 | retVal = todo; | 366 | retVal = todo; |
361 | } | 367 | } |
362 | } else { | 368 | } else { |
363 | retVal = todo; | 369 | retVal = todo; |
364 | } | 370 | } |
365 | } | 371 | } |
366 | } | 372 | } |
367 | return retVal; | 373 | return retVal; |
368 | } | 374 | } |
369 | QString CalendarLocal::nextSummary() const | 375 | QString CalendarLocal::nextSummary() const |
370 | { | 376 | { |
371 | return mNextSummary; | 377 | return mNextSummary; |
372 | } | 378 | } |
373 | QDateTime CalendarLocal::nextAlarmEventDateTime() const | 379 | QDateTime CalendarLocal::nextAlarmEventDateTime() const |
374 | { | 380 | { |
375 | return mNextAlarmEventDateTime; | 381 | return mNextAlarmEventDateTime; |
376 | } | 382 | } |
377 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) | 383 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) |
378 | { | 384 | { |
379 | //mNextAlarmIncidence | 385 | //mNextAlarmIncidence |
380 | //mNextAlarmDateTime | 386 | //mNextAlarmDateTime |
381 | //return mNextSummary; | 387 | //return mNextSummary; |
382 | //return mNextAlarmEventDateTime; | 388 | //return mNextAlarmEventDateTime; |
383 | bool newNextAlarm = false; | 389 | bool newNextAlarm = false; |
384 | bool computeNextAlarm = false; | 390 | bool computeNextAlarm = false; |
385 | bool ok; | 391 | bool ok; |
386 | int offset; | 392 | int offset; |
387 | QDateTime nextA; | 393 | QDateTime nextA; |
388 | // QString nextSum; | 394 | // QString nextSum; |
389 | //QDateTime nextEvent; | 395 | //QDateTime nextEvent; |
390 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { | 396 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { |
391 | computeNextAlarm = true; | 397 | computeNextAlarm = true; |
392 | } else { | 398 | } else { |
393 | if ( ! deleted ) { | 399 | if ( ! deleted ) { |
394 | nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; | 400 | nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; |
395 | if ( ok ) { | 401 | if ( ok ) { |
396 | if ( nextA < mNextAlarmDateTime ) { | 402 | if ( nextA < mNextAlarmDateTime ) { |
397 | deRegisterAlarm(); | 403 | deRegisterAlarm(); |
398 | mNextAlarmDateTime = nextA; | 404 | mNextAlarmDateTime = nextA; |
399 | mNextSummary = incidence->summary(); | 405 | mNextSummary = incidence->summary(); |
400 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; | 406 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; |
401 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 407 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
402 | newNextAlarm = true; | 408 | newNextAlarm = true; |
403 | mNextAlarmIncidence = incidence; | 409 | mNextAlarmIncidence = incidence; |
404 | } else { | 410 | } else { |
405 | if ( incidence == mNextAlarmIncidence ) { | 411 | if ( incidence == mNextAlarmIncidence ) { |
406 | computeNextAlarm = true; | 412 | computeNextAlarm = true; |
407 | } | 413 | } |
408 | } | 414 | } |
409 | } else { | 415 | } else { |
410 | if ( mNextAlarmIncidence == incidence ) { | 416 | if ( mNextAlarmIncidence == incidence ) { |
411 | computeNextAlarm = true; | 417 | computeNextAlarm = true; |
412 | } | 418 | } |
413 | } | 419 | } |
414 | } else { // deleted | 420 | } else { // deleted |
415 | if ( incidence == mNextAlarmIncidence ) { | 421 | if ( incidence == mNextAlarmIncidence ) { |
416 | computeNextAlarm = true; | 422 | computeNextAlarm = true; |
417 | } | 423 | } |
418 | } | 424 | } |
419 | } | 425 | } |
420 | if ( computeNextAlarm ) { | 426 | if ( computeNextAlarm ) { |
421 | deRegisterAlarm(); | 427 | deRegisterAlarm(); |
422 | nextA = nextAlarm( 1000 ); | 428 | nextA = nextAlarm( 1000 ); |
423 | if (! mNextAlarmIncidence ) { | 429 | if (! mNextAlarmIncidence ) { |
424 | return; | 430 | return; |
425 | } | 431 | } |
426 | newNextAlarm = true; | 432 | newNextAlarm = true; |
427 | } | 433 | } |
428 | if ( newNextAlarm ) | 434 | if ( newNextAlarm ) |
429 | registerAlarm(); | 435 | registerAlarm(); |
430 | } | 436 | } |
431 | QString CalendarLocal:: getAlarmNotification() | 437 | QString CalendarLocal:: getAlarmNotification() |
432 | { | 438 | { |
433 | QString ret; | 439 | QString ret; |
434 | // this should not happen | 440 | // this should not happen |
435 | if (! mNextAlarmIncidence ) | 441 | if (! mNextAlarmIncidence ) |
436 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; | 442 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; |
437 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); | 443 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); |
438 | if ( alarm->type() == Alarm::Procedure ) { | 444 | if ( alarm->type() == Alarm::Procedure ) { |
439 | ret = "proc_alarm" + alarm->programFile()+"+++"; | 445 | ret = "proc_alarm" + alarm->programFile()+"+++"; |
440 | } else { | 446 | } else { |
441 | ret = "audio_alarm" +alarm->audioFile() +"+++"; | 447 | ret = "audio_alarm" +alarm->audioFile() +"+++"; |
442 | } | 448 | } |
443 | ret += "cal_alarm"+ mNextSummary.left( 25 ); | 449 | ret += "cal_alarm"+ mNextSummary.left( 25 ); |
444 | if ( mNextSummary.length() > 25 ) | 450 | if ( mNextSummary.length() > 25 ) |
445 | ret += "\n" + mNextSummary.mid(25, 25 ); | 451 | ret += "\n" + mNextSummary.mid(25, 25 ); |
446 | ret+= "\n"+mNextAlarmEventDateTimeString; | 452 | ret+= "\n"+mNextAlarmEventDateTimeString; |
447 | return ret; | 453 | return ret; |
448 | } | 454 | } |
449 | void CalendarLocal::registerAlarm() | 455 | void CalendarLocal::registerAlarm() |
450 | { | 456 | { |
451 | mLastAlarmNotificationString = getAlarmNotification(); | 457 | mLastAlarmNotificationString = getAlarmNotification(); |
452 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); | 458 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); |
453 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 459 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
454 | // #ifndef DESKTOP_VERSION | 460 | // #ifndef DESKTOP_VERSION |
455 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); | 461 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); |
456 | // #endif | 462 | // #endif |
457 | } | 463 | } |
458 | void CalendarLocal::deRegisterAlarm() | 464 | void CalendarLocal::deRegisterAlarm() |
459 | { | 465 | { |
460 | if ( mLastAlarmNotificationString.isNull() ) | 466 | if ( mLastAlarmNotificationString.isNull() ) |
461 | return; | 467 | return; |
462 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); | 468 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); |
463 | 469 | ||
464 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 470 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
465 | mNextAlarmEventDateTime = QDateTime(); | 471 | mNextAlarmEventDateTime = QDateTime(); |
466 | // #ifndef DESKTOP_VERSION | 472 | // #ifndef DESKTOP_VERSION |
467 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); | 473 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); |
468 | // #endif | 474 | // #endif |
469 | } | 475 | } |
470 | 476 | ||
471 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) | 477 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) |
472 | { | 478 | { |
473 | QPtrList<Todo> todos; | 479 | QPtrList<Todo> todos; |
474 | 480 | ||
475 | Todo *todo; | 481 | Todo *todo; |
476 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 482 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
477 | if ( !todo->calEnabled() ) continue; | 483 | if ( !todo->calEnabled() ) continue; |
478 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { | 484 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { |
479 | todos.append( todo ); | 485 | todos.append( todo ); |
480 | } | 486 | } |
481 | } | 487 | } |
482 | 488 | ||
483 | filter()->apply( &todos ); | 489 | filter()->apply( &todos ); |
484 | return todos; | 490 | return todos; |
485 | } | 491 | } |
486 | void CalendarLocal::reInitAlarmSettings() | 492 | void CalendarLocal::reInitAlarmSettings() |
487 | { | 493 | { |
488 | if ( !mNextAlarmIncidence ) { | 494 | if ( !mNextAlarmIncidence ) { |
489 | nextAlarm( 1000 ); | 495 | nextAlarm( 1000 ); |
490 | } | 496 | } |
491 | deRegisterAlarm(); | 497 | deRegisterAlarm(); |
492 | mNextAlarmIncidence = 0; | 498 | mNextAlarmIncidence = 0; |
493 | checkAlarmForIncidence( 0, false ); | 499 | checkAlarmForIncidence( 0, false ); |
494 | 500 | ||
495 | } | 501 | } |
496 | 502 | ||
497 | 503 | ||
498 | 504 | ||
499 | QDateTime CalendarLocal::nextAlarm( int daysTo ) | 505 | QDateTime CalendarLocal::nextAlarm( int daysTo ) |
500 | { | 506 | { |
501 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); | 507 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); |
502 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); | 508 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); |
503 | QDateTime next; | 509 | QDateTime next; |
504 | Event *e; | 510 | Event *e; |
505 | bool ok; | 511 | bool ok; |
506 | bool found = false; | 512 | bool found = false; |
507 | int offset; | 513 | int offset; |
508 | mNextAlarmIncidence = 0; | 514 | mNextAlarmIncidence = 0; |
509 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 515 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
510 | if ( !e->calEnabled() ) continue; | 516 | if ( !e->calEnabled() ) continue; |
511 | next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; | 517 | next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; |
512 | if ( ok ) { | 518 | if ( ok ) { |
513 | if ( next < nextA ) { | 519 | if ( next < nextA ) { |
514 | nextA = next; | 520 | nextA = next; |
515 | found = true; | 521 | found = true; |
516 | mNextSummary = e->summary(); | 522 | mNextSummary = e->summary(); |
517 | mNextAlarmEventDateTime = next.addSecs(offset ) ; | 523 | mNextAlarmEventDateTime = next.addSecs(offset ) ; |
518 | mNextAlarmIncidence = (Incidence *) e; | 524 | mNextAlarmIncidence = (Incidence *) e; |
519 | } | 525 | } |
520 | } | 526 | } |
521 | } | 527 | } |
522 | Todo *t; | 528 | Todo *t; |
523 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 529 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
524 | if ( !t->calEnabled() ) continue; | 530 | if ( !t->calEnabled() ) continue; |
525 | next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; | 531 | next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; |
526 | if ( ok ) { | 532 | if ( ok ) { |
527 | if ( next < nextA ) { | 533 | if ( next < nextA ) { |
528 | nextA = next; | 534 | nextA = next; |
529 | found = true; | 535 | found = true; |
530 | mNextSummary = t->summary(); | 536 | mNextSummary = t->summary(); |
531 | mNextAlarmEventDateTime = next.addSecs(offset ); | 537 | mNextAlarmEventDateTime = next.addSecs(offset ); |
532 | mNextAlarmIncidence = (Incidence *) t; | 538 | mNextAlarmIncidence = (Incidence *) t; |
533 | } | 539 | } |
diff --git a/libkcal/calendarlocal.h b/libkcal/calendarlocal.h index 0286b48..d32597f 100644 --- a/libkcal/calendarlocal.h +++ b/libkcal/calendarlocal.h | |||
@@ -1,225 +1,226 @@ | |||
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 | void addCalendar( Calendar* ); | 46 | void addCalendar( Calendar* ); |
47 | bool addCalendarFile( QString name, int id ); | 47 | bool addCalendarFile( QString name, int id ); |
48 | void setSyncEventsReadOnly(); | 48 | void setSyncEventsReadOnly(); |
49 | void stopAllTodos(); | ||
49 | /** | 50 | /** |
50 | Loads a calendar on disk in vCalendar or iCalendar format into the current | 51 | Loads a calendar on disk in vCalendar or iCalendar format into the current |
51 | calendar. Any information already present is lost. | 52 | calendar. Any information already present is lost. |
52 | @return true, if successfull, false on error. | 53 | @return true, if successfull, false on error. |
53 | @param fileName the name of the calendar on disk. | 54 | @param fileName the name of the calendar on disk. |
54 | */ | 55 | */ |
55 | bool load( const QString &fileName ); | 56 | bool load( const QString &fileName ); |
56 | /** | 57 | /** |
57 | Writes out the calendar to disk in the specified \a format. | 58 | Writes out the calendar to disk in the specified \a format. |
58 | CalendarLocal takes ownership of the CalFormat object. | 59 | CalendarLocal takes ownership of the CalFormat object. |
59 | @return true, if successfull, false on error. | 60 | @return true, if successfull, false on error. |
60 | @param fileName the name of the file | 61 | @param fileName the name of the file |
61 | */ | 62 | */ |
62 | bool save( const QString &fileName, CalFormat *format = 0 ); | 63 | bool save( const QString &fileName, CalFormat *format = 0 ); |
63 | 64 | ||
64 | /** | 65 | /** |
65 | Clears out the current calendar, freeing all used memory etc. etc. | 66 | Clears out the current calendar, freeing all used memory etc. etc. |
66 | */ | 67 | */ |
67 | void close(); | 68 | void close(); |
68 | 69 | ||
69 | void save() {} | 70 | void save() {} |
70 | 71 | ||
71 | /** | 72 | /** |
72 | Add Event to calendar. | 73 | Add Event to calendar. |
73 | */ | 74 | */ |
74 | void removeSyncInfo( QString syncProfile); | 75 | void removeSyncInfo( QString syncProfile); |
75 | bool addAnniversaryNoDup( Event *event ); | 76 | bool addAnniversaryNoDup( Event *event ); |
76 | bool addEventNoDup( Event *event ); | 77 | bool addEventNoDup( Event *event ); |
77 | bool addEvent( Event *event ); | 78 | bool addEvent( Event *event ); |
78 | /** | 79 | /** |
79 | Deletes an event from this calendar. | 80 | Deletes an event from this calendar. |
80 | */ | 81 | */ |
81 | void deleteEvent( Event *event ); | 82 | void deleteEvent( Event *event ); |
82 | 83 | ||
83 | /** | 84 | /** |
84 | Retrieves an event on the basis of the unique string ID. | 85 | Retrieves an event on the basis of the unique string ID. |
85 | */ | 86 | */ |
86 | Event *event( const QString &uid ); | 87 | Event *event( const QString &uid ); |
87 | /** | 88 | /** |
88 | Return unfiltered list of all events in calendar. | 89 | Return unfiltered list of all events in calendar. |
89 | */ | 90 | */ |
90 | QPtrList<Event> rawEvents(); | 91 | QPtrList<Event> rawEvents(); |
91 | QPtrList<Event> getExternLastSyncEvents(); | 92 | QPtrList<Event> getExternLastSyncEvents(); |
92 | /** | 93 | /** |
93 | Add a todo to the todolist. | 94 | Add a todo to the todolist. |
94 | */ | 95 | */ |
95 | bool addTodo( Todo *todo ); | 96 | bool addTodo( Todo *todo ); |
96 | bool addTodoNoDup( Todo *todo ); | 97 | bool addTodoNoDup( Todo *todo ); |
97 | /** | 98 | /** |
98 | Remove a todo from the todolist. | 99 | Remove a todo from the todolist. |
99 | */ | 100 | */ |
100 | void deleteTodo( Todo * ); | 101 | void deleteTodo( Todo * ); |
101 | /** | 102 | /** |
102 | Searches todolist for an event with this unique string identifier, | 103 | Searches todolist for an event with this unique string identifier, |
103 | returns a pointer or null. | 104 | returns a pointer or null. |
104 | */ | 105 | */ |
105 | Todo *todo( const QString &uid ); | 106 | Todo *todo( const QString &uid ); |
106 | /** | 107 | /** |
107 | Return list of all todos. | 108 | Return list of all todos. |
108 | */ | 109 | */ |
109 | QPtrList<Todo> rawTodos(); | 110 | QPtrList<Todo> rawTodos(); |
110 | /** | 111 | /** |
111 | Returns list of todos due on the specified date. | 112 | Returns list of todos due on the specified date. |
112 | */ | 113 | */ |
113 | QPtrList<Todo> todos( const QDate &date ); | 114 | QPtrList<Todo> todos( const QDate &date ); |
114 | /** | 115 | /** |
115 | Return list of all todos. | 116 | Return list of all todos. |
116 | 117 | ||
117 | Workaround because compiler does not recognize function of base class. | 118 | Workaround because compiler does not recognize function of base class. |
118 | */ | 119 | */ |
119 | QPtrList<Todo> todos() { return Calendar::todos(); } | 120 | QPtrList<Todo> todos() { return Calendar::todos(); } |
120 | 121 | ||
121 | /** | 122 | /** |
122 | Add a Journal entry to calendar. | 123 | Add a Journal entry to calendar. |
123 | */ | 124 | */ |
124 | bool addJournal( Journal * ); | 125 | bool addJournal( Journal * ); |
125 | /** | 126 | /** |
126 | Remove a Journal from the calendar. | 127 | Remove a Journal from the calendar. |
127 | */ | 128 | */ |
128 | void deleteJournal( Journal * ); | 129 | void deleteJournal( Journal * ); |
129 | /** | 130 | /** |
130 | Return Journal for given date. | 131 | Return Journal for given date. |
131 | */ | 132 | */ |
132 | Journal *journal( const QDate & ); | 133 | Journal *journal( const QDate & ); |
133 | /** | 134 | /** |
134 | Return Journal with given UID. | 135 | Return Journal with given UID. |
135 | */ | 136 | */ |
136 | Journal *journal( const QString &uid ); | 137 | Journal *journal( const QString &uid ); |
137 | /** | 138 | /** |
138 | Return list of all Journals stored in calendar. | 139 | Return list of all Journals stored in calendar. |
139 | */ | 140 | */ |
140 | QPtrList<Journal> journals(); | 141 | QPtrList<Journal> journals(); |
141 | 142 | ||
142 | /** | 143 | /** |
143 | Return all alarms, which ocur in the given time interval. | 144 | Return all alarms, which ocur in the given time interval. |
144 | */ | 145 | */ |
145 | Alarm::List alarms( const QDateTime &from, const QDateTime &to ); | 146 | Alarm::List alarms( const QDateTime &from, const QDateTime &to ); |
146 | 147 | ||
147 | /** | 148 | /** |
148 | Return all alarms, which ocur before given date. | 149 | Return all alarms, which ocur before given date. |
149 | */ | 150 | */ |
150 | Alarm::List alarmsTo( const QDateTime &to ); | 151 | Alarm::List alarmsTo( const QDateTime &to ); |
151 | 152 | ||
152 | QDateTime nextAlarm( int daysTo ) ; | 153 | QDateTime nextAlarm( int daysTo ) ; |
153 | QDateTime nextAlarmEventDateTime() const; | 154 | QDateTime nextAlarmEventDateTime() const; |
154 | void checkAlarmForIncidence( Incidence *, bool deleted ) ; | 155 | void checkAlarmForIncidence( Incidence *, bool deleted ) ; |
155 | void registerAlarm(); | 156 | void registerAlarm(); |
156 | void deRegisterAlarm(); | 157 | void deRegisterAlarm(); |
157 | QString getAlarmNotification(); | 158 | QString getAlarmNotification(); |
158 | QString nextSummary() const ; | 159 | QString nextSummary() const ; |
159 | /** | 160 | /** |
160 | This method should be called whenever a Event is modified directly | 161 | This method should be called whenever a Event is modified directly |
161 | via it's pointer. It makes sure that the calendar is internally | 162 | via it's pointer. It makes sure that the calendar is internally |
162 | consistent. | 163 | consistent. |
163 | */ | 164 | */ |
164 | void update( IncidenceBase *incidence ); | 165 | void update( IncidenceBase *incidence ); |
165 | 166 | ||
166 | /** | 167 | /** |
167 | Builds and then returns a list of all events that match for the | 168 | Builds and then returns a list of all events that match for the |
168 | date specified. useful for dayView, etc. etc. | 169 | date specified. useful for dayView, etc. etc. |
169 | */ | 170 | */ |
170 | QPtrList<Event> rawEventsForDate( const QDate &date, bool sorted = false ); | 171 | QPtrList<Event> rawEventsForDate( const QDate &date, bool sorted = false ); |
171 | /** | 172 | /** |
172 | Get unfiltered events for date \a qdt. | 173 | Get unfiltered events for date \a qdt. |
173 | */ | 174 | */ |
174 | QPtrList<Event> rawEventsForDate( const QDateTime &qdt ); | 175 | QPtrList<Event> rawEventsForDate( const QDateTime &qdt ); |
175 | /** | 176 | /** |
176 | Get unfiltered events in a range of dates. If inclusive is set to true, | 177 | Get unfiltered events in a range of dates. If inclusive is set to true, |
177 | only events are returned, which are completely included in the range. | 178 | only events are returned, which are completely included in the range. |
178 | */ | 179 | */ |
179 | QPtrList<Event> rawEvents( const QDate &start, const QDate &end, | 180 | QPtrList<Event> rawEvents( const QDate &start, const QDate &end, |
180 | bool inclusive = false ); | 181 | bool inclusive = false ); |
181 | Todo *todo( QString, QString ); | 182 | Todo *todo( QString, QString ); |
182 | Event *event( QString, QString ); | 183 | Event *event( QString, QString ); |
183 | 184 | ||
184 | public slots: | 185 | public slots: |
185 | void setCalendarEnabled( int id, bool enable ); | 186 | void setCalendarEnabled( int id, bool enable ); |
186 | void setAlarmEnabled( int id, bool enable ); | 187 | void setAlarmEnabled( int id, bool enable ); |
187 | void setReadOnly( int id, bool enable ); | 188 | void setReadOnly( int id, bool enable ); |
188 | void setDefaultCalendarEnabledOnly(); | 189 | void setDefaultCalendarEnabledOnly(); |
189 | void setCalendarRemove( int id ); | 190 | void setCalendarRemove( int id ); |
190 | 191 | ||
191 | protected: | 192 | protected: |
192 | 193 | ||
193 | // Event* mNextAlarmEvent; | 194 | // Event* mNextAlarmEvent; |
194 | QString mNextSummary; | 195 | QString mNextSummary; |
195 | QString mNextAlarmEventDateTimeString; | 196 | QString mNextAlarmEventDateTimeString; |
196 | QString mLastAlarmNotificationString; | 197 | QString mLastAlarmNotificationString; |
197 | QDateTime mNextAlarmEventDateTime; | 198 | QDateTime mNextAlarmEventDateTime; |
198 | QDateTime mNextAlarmDateTime; | 199 | QDateTime mNextAlarmDateTime; |
199 | void reInitAlarmSettings(); | 200 | void reInitAlarmSettings(); |
200 | 201 | ||
201 | /** Notification function of IncidenceBase::Observer. */ | 202 | /** Notification function of IncidenceBase::Observer. */ |
202 | void incidenceUpdated( IncidenceBase *i ) { update( i ); } | 203 | void incidenceUpdated( IncidenceBase *i ) { update( i ); } |
203 | 204 | ||
204 | /** inserts an event into its "proper place" in the calendar. */ | 205 | /** inserts an event into its "proper place" in the calendar. */ |
205 | void insertEvent( Event *event ); | 206 | void insertEvent( Event *event ); |
206 | 207 | ||
207 | /** Append alarms of incidence in interval to list of alarms. */ | 208 | /** Append alarms of incidence in interval to list of alarms. */ |
208 | void appendAlarms( Alarm::List &alarms, Incidence *incidence, | 209 | void appendAlarms( Alarm::List &alarms, Incidence *incidence, |
209 | const QDateTime &from, const QDateTime &to ); | 210 | const QDateTime &from, const QDateTime &to ); |
210 | 211 | ||
211 | /** Append alarms of recurring events in interval to list of alarms. */ | 212 | /** Append alarms of recurring events in interval to list of alarms. */ |
212 | void appendRecurringAlarms( Alarm::List &alarms, Incidence *incidence, | 213 | void appendRecurringAlarms( Alarm::List &alarms, Incidence *incidence, |
213 | const QDateTime &from, const QDateTime &to ); | 214 | const QDateTime &from, const QDateTime &to ); |
214 | 215 | ||
215 | private: | 216 | private: |
216 | void init(); | 217 | void init(); |
217 | 218 | ||
218 | QPtrList<Event> mEventList; | 219 | QPtrList<Event> mEventList; |
219 | QPtrList<Todo> mTodoList; | 220 | QPtrList<Todo> mTodoList; |
220 | QPtrList<Journal> mJournalList; | 221 | QPtrList<Journal> mJournalList; |
221 | }; | 222 | }; |
222 | 223 | ||
223 | } | 224 | } |
224 | 225 | ||
225 | #endif | 226 | #endif |
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp index 9a8b6e4..5260051 100644 --- a/libkcal/todo.cpp +++ b/libkcal/todo.cpp | |||
@@ -1,499 +1,499 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include <kglobal.h> | 21 | #include <kglobal.h> |
22 | #include <kglobalsettings.h> | 22 | #include <kglobalsettings.h> |
23 | #include <klocale.h> | 23 | #include <klocale.h> |
24 | #include <kdebug.h> | 24 | #include <kdebug.h> |
25 | #include <qregexp.h> | 25 | #include <qregexp.h> |
26 | #include <qfileinfo.h> | 26 | #include <qfileinfo.h> |
27 | 27 | ||
28 | #include "calendarlocal.h" | 28 | #include "calendarlocal.h" |
29 | #include "icalformat.h" | 29 | #include "icalformat.h" |
30 | #include "todo.h" | 30 | #include "todo.h" |
31 | 31 | ||
32 | using namespace KCal; | 32 | using namespace KCal; |
33 | 33 | ||
34 | Todo::Todo(): QObject(), Incidence() | 34 | Todo::Todo(): QObject(), Incidence() |
35 | { | 35 | { |
36 | // mStatus = TENTATIVE; | 36 | // mStatus = TENTATIVE; |
37 | 37 | ||
38 | mHasDueDate = false; | 38 | mHasDueDate = false; |
39 | setHasStartDate( false ); | 39 | setHasStartDate( false ); |
40 | mCompleted = getEvenTime(QDateTime::currentDateTime()); | 40 | mCompleted = getEvenTime(QDateTime::currentDateTime()); |
41 | mHasCompletedDate = false; | 41 | mHasCompletedDate = false; |
42 | mPercentComplete = 0; | 42 | mPercentComplete = 0; |
43 | mRunning = false; | 43 | mRunning = false; |
44 | mRunSaveTimer = 0; | 44 | mRunSaveTimer = 0; |
45 | } | 45 | } |
46 | 46 | ||
47 | Todo::Todo(const Todo &t) : QObject(),Incidence(t) | 47 | Todo::Todo(const Todo &t) : QObject(),Incidence(t) |
48 | { | 48 | { |
49 | mDtDue = t.mDtDue; | 49 | mDtDue = t.mDtDue; |
50 | mHasDueDate = t.mHasDueDate; | 50 | mHasDueDate = t.mHasDueDate; |
51 | mCompleted = t.mCompleted; | 51 | mCompleted = t.mCompleted; |
52 | mHasCompletedDate = t.mHasCompletedDate; | 52 | mHasCompletedDate = t.mHasCompletedDate; |
53 | mPercentComplete = t.mPercentComplete; | 53 | mPercentComplete = t.mPercentComplete; |
54 | mRunning = false; | 54 | mRunning = false; |
55 | mRunSaveTimer = 0; | 55 | mRunSaveTimer = 0; |
56 | } | 56 | } |
57 | 57 | ||
58 | Todo::~Todo() | 58 | Todo::~Todo() |
59 | { | 59 | { |
60 | setRunning( false ); | 60 | setRunning( false ); |
61 | //qDebug("Todo::~Todo() "); | 61 | //qDebug("Todo::~Todo() "); |
62 | } | 62 | } |
63 | 63 | ||
64 | void Todo::setRunningFalse( QString s ) | 64 | void Todo::setRunningFalse( QString s ) |
65 | { | 65 | { |
66 | if ( ! mRunning ) | 66 | if ( ! mRunning ) |
67 | return; | 67 | return; |
68 | mRunning = false; | 68 | mRunning = false; |
69 | mRunSaveTimer->stop(); | 69 | mRunSaveTimer->stop(); |
70 | saveRunningInfoToFile( s ); | 70 | saveRunningInfoToFile( s ); |
71 | } | 71 | } |
72 | void Todo::stopRunning() | 72 | void Todo::stopRunning() |
73 | { | 73 | { |
74 | if ( !mRunning ) | 74 | if ( !mRunning ) |
75 | return; | 75 | return; |
76 | if ( mRunSaveTimer ) | 76 | if ( mRunSaveTimer ) |
77 | mRunSaveTimer->stop(); | 77 | mRunSaveTimer->stop(); |
78 | mRunning = false; | 78 | mRunning = false; |
79 | } | 79 | } |
80 | void Todo::setRunning( bool run ) | 80 | void Todo::setRunning( bool run ) |
81 | { | 81 | { |
82 | if ( run == mRunning ) | 82 | if ( run == mRunning ) |
83 | return; | 83 | return; |
84 | //qDebug("Todo::setRunning %d ", run); | 84 | //qDebug("Todo::setRunning %d ", run); |
85 | if ( !mRunSaveTimer ) { | 85 | if ( !mRunSaveTimer ) { |
86 | mRunSaveTimer = new QTimer ( this ); | 86 | mRunSaveTimer = new QTimer ( this ); |
87 | connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) ); | 87 | connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) ); |
88 | } | 88 | } |
89 | mRunning = run; | 89 | mRunning = run; |
90 | if ( mRunning ) { | 90 | if ( mRunning ) { |
91 | mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min | 91 | mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min |
92 | mRunStart = QDateTime::currentDateTime(); | 92 | mRunStart = QDateTime::currentDateTime(); |
93 | } else { | 93 | } else { |
94 | mRunSaveTimer->stop(); | 94 | mRunSaveTimer->stop(); |
95 | saveRunningInfoToFile(); | 95 | saveRunningInfoToFile(); |
96 | } | 96 | } |
97 | } | 97 | } |
98 | void Todo::saveRunningInfo( QString comment, QDateTime start, QDateTime end ) | 98 | void Todo::saveRunningInfo( QString comment, QDateTime start, QDateTime end ) |
99 | { | 99 | { |
100 | if ( !mRunning) return; | 100 | if ( !mRunning) return; |
101 | mRunning = false; | 101 | mRunning = false; |
102 | mRunStart = start; | 102 | mRunStart = start; |
103 | mRunEnd = end; | 103 | mRunEnd = end; |
104 | saveRunningInfoToFile( comment ); | 104 | saveRunningInfoToFile( comment ); |
105 | } | 105 | } |
106 | void Todo::saveRunningInfoToFile() | 106 | void Todo::saveRunningInfoToFile() |
107 | { | 107 | { |
108 | mRunEnd = QDateTime::currentDateTime(); | 108 | mRunEnd = QDateTime::currentDateTime(); |
109 | saveRunningInfoToFile( QString::null ); | 109 | saveRunningInfoToFile( QString::null ); |
110 | } | 110 | } |
111 | void Todo::saveRunningInfoToFile( QString comment ) | 111 | void Todo::saveRunningInfoToFile( QString comment ) |
112 | { | 112 | { |
113 | //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); | 113 | //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); |
114 | if ( mRunStart.secsTo ( QDateTime::currentDateTime() ) < 10 ) { | 114 | if ( mRunStart.secsTo ( mRunEnd) < 15 ) { |
115 | qDebug("Running time < 30 seconds. Skipped. "); | 115 | qDebug("Running time < 15 seconds. Skipped. "); |
116 | return; | 116 | return; |
117 | } | 117 | } |
118 | QString dir = KGlobalSettings::timeTrackerDir(); | 118 | QString dir = KGlobalSettings::timeTrackerDir(); |
119 | //qDebug("%s ", dir.latin1()); | 119 | //qDebug("%s ", dir.latin1()); |
120 | QString file = "%1%2%3-%4%5%6-"; | 120 | QString file = "%1%2%3-%4%5%6-"; |
121 | file = file.arg( mRunStart.date().year(), 4).arg( mRunStart.date().month(),2 ).arg( mRunStart.date().day(), 2 ).arg( mRunStart.time().hour(),2 ).arg( mRunStart.time().minute(),2 ).arg( mRunStart.time().second(),2 ); | 121 | file = file.arg( mRunStart.date().year(), 4).arg( mRunStart.date().month(),2 ).arg( mRunStart.date().day(), 2 ).arg( mRunStart.time().hour(),2 ).arg( mRunStart.time().minute(),2 ).arg( mRunStart.time().second(),2 ); |
122 | file.replace ( QRegExp (" "), "0" ); | 122 | file.replace ( QRegExp (" "), "0" ); |
123 | file += uid(); | 123 | file += uid(); |
124 | //qDebug("File %s ",file.latin1() ); | 124 | //qDebug("File %s ",file.latin1() ); |
125 | CalendarLocal cal; | 125 | CalendarLocal cal; |
126 | cal.setLocalTime(); | 126 | cal.setLocalTime(); |
127 | Todo * to = (Todo*) clone(); | 127 | Todo * to = (Todo*) clone(); |
128 | to->setFloats( false ); | 128 | to->setFloats( false ); |
129 | to->setDtStart( mRunStart ); | 129 | to->setDtStart( mRunStart ); |
130 | to->setHasStartDate( true ); | 130 | to->setHasStartDate( true ); |
131 | to->setDtDue( mRunEnd ); | 131 | to->setDtDue( mRunEnd ); |
132 | to->setHasDueDate( true ); | 132 | to->setHasDueDate( true ); |
133 | to->setUid( file ); | 133 | to->setUid( file ); |
134 | if ( !comment.isEmpty() ) { | 134 | if ( !comment.isEmpty() ) { |
135 | QString des = to->description(); | 135 | QString des = to->description(); |
136 | if ( des.isEmpty () ) | 136 | if ( des.isEmpty () ) |
137 | to->setDescription( "TT-Note: " + comment ); | 137 | to->setDescription( "TT-Note: " + comment ); |
138 | else | 138 | else |
139 | to->setDescription( "TT-Note: " + comment +"\n" + des ); | 139 | to->setDescription( "TT-Note: " + comment +"\n" + des ); |
140 | } | 140 | } |
141 | cal.addIncidence( to ); | 141 | cal.addIncidence( to ); |
142 | ICalFormat format; | 142 | ICalFormat format; |
143 | file = dir +"/" +file +".ics"; | 143 | file = dir +"/" +file +".ics"; |
144 | format.save( &cal, file ); | 144 | format.save( &cal, file ); |
145 | saveParents(); | 145 | saveParents(); |
146 | 146 | ||
147 | } | 147 | } |
148 | void Todo::saveParents() | 148 | void Todo::saveParents() |
149 | { | 149 | { |
150 | if (!relatedTo() ) | 150 | if (!relatedTo() ) |
151 | return; | 151 | return; |
152 | Incidence * inc = relatedTo(); | 152 | Incidence * inc = relatedTo(); |
153 | if ( inc->typeID() != todoID ) | 153 | if ( inc->typeID() != todoID ) |
154 | return; | 154 | return; |
155 | Todo* to = (Todo*)inc; | 155 | Todo* to = (Todo*)inc; |
156 | bool saveTodo = false; | 156 | bool saveTodo = false; |
157 | QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics"; | 157 | QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics"; |
158 | QFileInfo fi ( file ); | 158 | QFileInfo fi ( file ); |
159 | if ( fi.exists() ) { | 159 | if ( fi.exists() ) { |
160 | if ( fi.lastModified () < to->lastModified ()) | 160 | if ( fi.lastModified () < to->lastModified ()) |
161 | saveTodo = true; | 161 | saveTodo = true; |
162 | } else { | 162 | } else { |
163 | saveTodo = true; | 163 | saveTodo = true; |
164 | } | 164 | } |
165 | if ( saveTodo ) { | 165 | if ( saveTodo ) { |
166 | CalendarLocal cal; | 166 | CalendarLocal cal; |
167 | cal.setLocalTime(); | 167 | cal.setLocalTime(); |
168 | Todo * par = (Todo *) to->clone(); | 168 | Todo * par = (Todo *) to->clone(); |
169 | cal.addIncidence( par ); | 169 | cal.addIncidence( par ); |
170 | ICalFormat format; | 170 | ICalFormat format; |
171 | format.save( &cal, file ); | 171 | format.save( &cal, file ); |
172 | } | 172 | } |
173 | to->saveParents(); | 173 | to->saveParents(); |
174 | } | 174 | } |
175 | 175 | ||
176 | int Todo::runTime() | 176 | int Todo::runTime() |
177 | { | 177 | { |
178 | if ( !mRunning ) | 178 | if ( !mRunning ) |
179 | return 0; | 179 | return 0; |
180 | return mRunStart.secsTo( QDateTime::currentDateTime() ); | 180 | return mRunStart.secsTo( QDateTime::currentDateTime() ); |
181 | } | 181 | } |
182 | bool Todo::hasRunningSub() | 182 | bool Todo::hasRunningSub() |
183 | { | 183 | { |
184 | if ( mRunning ) | 184 | if ( mRunning ) |
185 | return true; | 185 | return true; |
186 | Incidence *aTodo; | 186 | Incidence *aTodo; |
187 | for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { | 187 | for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { |
188 | if ( ((Todo*)aTodo)->hasRunningSub() ) | 188 | if ( ((Todo*)aTodo)->hasRunningSub() ) |
189 | return true; | 189 | return true; |
190 | } | 190 | } |
191 | return false; | 191 | return false; |
192 | } | 192 | } |
193 | Incidence *Todo::clone() | 193 | Incidence *Todo::clone() |
194 | { | 194 | { |
195 | return new Todo(*this); | 195 | return new Todo(*this); |
196 | } | 196 | } |
197 | 197 | ||
198 | bool Todo::contains ( Todo* from ) | 198 | bool Todo::contains ( Todo* from ) |
199 | { | 199 | { |
200 | 200 | ||
201 | if ( !from->summary().isEmpty() ) | 201 | if ( !from->summary().isEmpty() ) |
202 | if ( !summary().startsWith( from->summary() )) | 202 | if ( !summary().startsWith( from->summary() )) |
203 | return false; | 203 | return false; |
204 | if ( from->hasStartDate() ) { | 204 | if ( from->hasStartDate() ) { |
205 | if ( !hasStartDate() ) | 205 | if ( !hasStartDate() ) |
206 | return false; | 206 | return false; |
207 | if ( from->dtStart() != dtStart()) | 207 | if ( from->dtStart() != dtStart()) |
208 | return false; | 208 | return false; |
209 | } | 209 | } |
210 | if ( from->hasDueDate() ){ | 210 | if ( from->hasDueDate() ){ |
211 | if ( !hasDueDate() ) | 211 | if ( !hasDueDate() ) |
212 | return false; | 212 | return false; |
213 | if ( from->dtDue() != dtDue()) | 213 | if ( from->dtDue() != dtDue()) |
214 | return false; | 214 | return false; |
215 | } | 215 | } |
216 | if ( !from->location().isEmpty() ) | 216 | if ( !from->location().isEmpty() ) |
217 | if ( !location().startsWith( from->location() ) ) | 217 | if ( !location().startsWith( from->location() ) ) |
218 | return false; | 218 | return false; |
219 | if ( !from->description().isEmpty() ) | 219 | if ( !from->description().isEmpty() ) |
220 | if ( !description().startsWith( from->description() )) | 220 | if ( !description().startsWith( from->description() )) |
221 | return false; | 221 | return false; |
222 | if ( from->alarms().count() ) { | 222 | if ( from->alarms().count() ) { |
223 | Alarm *a = from->alarms().first(); | 223 | Alarm *a = from->alarms().first(); |
224 | if ( a->enabled() ){ | 224 | if ( a->enabled() ){ |
225 | if ( !alarms().count() ) | 225 | if ( !alarms().count() ) |
226 | return false; | 226 | return false; |
227 | Alarm *b = alarms().first(); | 227 | Alarm *b = alarms().first(); |
228 | if( ! b->enabled() ) | 228 | if( ! b->enabled() ) |
229 | return false; | 229 | return false; |
230 | if ( ! (a->offset() == b->offset() )) | 230 | if ( ! (a->offset() == b->offset() )) |
231 | return false; | 231 | return false; |
232 | } | 232 | } |
233 | } | 233 | } |
234 | 234 | ||
235 | QStringList cat = categories(); | 235 | QStringList cat = categories(); |
236 | QStringList catFrom = from->categories(); | 236 | QStringList catFrom = from->categories(); |
237 | QString nCat; | 237 | QString nCat; |
238 | unsigned int iii; | 238 | unsigned int iii; |
239 | for ( iii = 0; iii < catFrom.count();++iii ) { | 239 | for ( iii = 0; iii < catFrom.count();++iii ) { |
240 | nCat = catFrom[iii]; | 240 | nCat = catFrom[iii]; |
241 | if ( !nCat.isEmpty() ) | 241 | if ( !nCat.isEmpty() ) |
242 | if ( !cat.contains( nCat )) { | 242 | if ( !cat.contains( nCat )) { |
243 | return false; | 243 | return false; |
244 | } | 244 | } |
245 | } | 245 | } |
246 | if ( from->isCompleted() ) { | 246 | if ( from->isCompleted() ) { |
247 | if ( !isCompleted() ) | 247 | if ( !isCompleted() ) |
248 | return false; | 248 | return false; |
249 | } | 249 | } |
250 | if( priority() != from->priority() ) | 250 | if( priority() != from->priority() ) |
251 | return false; | 251 | return false; |
252 | 252 | ||
253 | 253 | ||
254 | return true; | 254 | return true; |
255 | 255 | ||
256 | } | 256 | } |
257 | bool KCal::operator==( const Todo& t1, const Todo& t2 ) | 257 | bool KCal::operator==( const Todo& t1, const Todo& t2 ) |
258 | { | 258 | { |
259 | 259 | ||
260 | bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 ); | 260 | bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 ); |
261 | if ( ! ret ) | 261 | if ( ! ret ) |
262 | return false; | 262 | return false; |
263 | if ( t1.hasDueDate() == t2.hasDueDate() ) { | 263 | if ( t1.hasDueDate() == t2.hasDueDate() ) { |
264 | if ( t1.hasDueDate() ) { | 264 | if ( t1.hasDueDate() ) { |
265 | if ( t1.doesFloat() == t2.doesFloat() ) { | 265 | if ( t1.doesFloat() == t2.doesFloat() ) { |
266 | if ( t1.doesFloat() ) { | 266 | if ( t1.doesFloat() ) { |
267 | if ( t1.dtDue().date() != t2.dtDue().date() ) | 267 | if ( t1.dtDue().date() != t2.dtDue().date() ) |
268 | return false; | 268 | return false; |
269 | } else | 269 | } else |
270 | if ( t1.dtDue() != t2.dtDue() ) | 270 | if ( t1.dtDue() != t2.dtDue() ) |
271 | return false; | 271 | return false; |
272 | } else | 272 | } else |
273 | return false;// float != | 273 | return false;// float != |
274 | } | 274 | } |
275 | 275 | ||
276 | } else | 276 | } else |
277 | return false; | 277 | return false; |
278 | if ( t1.percentComplete() != t2.percentComplete() ) | 278 | if ( t1.percentComplete() != t2.percentComplete() ) |
279 | return false; | 279 | return false; |
280 | if ( t1.isCompleted() ) { | 280 | if ( t1.isCompleted() ) { |
281 | if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) { | 281 | if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) { |
282 | if ( t1.hasCompletedDate() ) { | 282 | if ( t1.hasCompletedDate() ) { |
283 | if ( t1.completed() != t2.completed() ) | 283 | if ( t1.completed() != t2.completed() ) |
284 | return false; | 284 | return false; |
285 | } | 285 | } |
286 | 286 | ||
287 | } else | 287 | } else |
288 | return false; | 288 | return false; |
289 | } | 289 | } |
290 | return true; | 290 | return true; |
291 | 291 | ||
292 | } | 292 | } |
293 | 293 | ||
294 | void Todo::setDtDue(const QDateTime &dtDue) | 294 | void Todo::setDtDue(const QDateTime &dtDue) |
295 | { | 295 | { |
296 | //int diffsecs = mDtDue.secsTo(dtDue); | 296 | //int diffsecs = mDtDue.secsTo(dtDue); |
297 | 297 | ||
298 | /*if (mReadOnly) return; | 298 | /*if (mReadOnly) return; |
299 | const QPtrList<Alarm>& alarms = alarms(); | 299 | const QPtrList<Alarm>& alarms = alarms(); |
300 | for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) { | 300 | for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) { |
301 | if (alarm->enabled()) { | 301 | if (alarm->enabled()) { |
302 | alarm->setTime(alarm->time().addSecs(diffsecs)); | 302 | alarm->setTime(alarm->time().addSecs(diffsecs)); |
303 | } | 303 | } |
304 | }*/ | 304 | }*/ |
305 | mDtDue = getEvenTime(dtDue); | 305 | mDtDue = getEvenTime(dtDue); |
306 | 306 | ||
307 | //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl; | 307 | //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl; |
308 | 308 | ||
309 | /*const QPtrList<Alarm>& alarms = alarms(); | 309 | /*const QPtrList<Alarm>& alarms = alarms(); |
310 | for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) | 310 | for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) |
311 | alarm->setAlarmStart(mDtDue);*/ | 311 | alarm->setAlarmStart(mDtDue);*/ |
312 | updated(); | 312 | updated(); |
313 | } | 313 | } |
314 | 314 | ||
315 | QDateTime Todo::dtDue() const | 315 | QDateTime Todo::dtDue() const |
316 | { | 316 | { |
317 | return mDtDue; | 317 | return mDtDue; |
318 | } | 318 | } |
319 | 319 | ||
320 | QString Todo::dtDueTimeStr() const | 320 | QString Todo::dtDueTimeStr() const |
321 | { | 321 | { |
322 | return KGlobal::locale()->formatTime(mDtDue.time()); | 322 | return KGlobal::locale()->formatTime(mDtDue.time()); |
323 | } | 323 | } |
324 | 324 | ||
325 | QString Todo::dtDueDateStr(bool shortfmt) const | 325 | QString Todo::dtDueDateStr(bool shortfmt) const |
326 | { | 326 | { |
327 | return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); | 327 | return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); |
328 | } | 328 | } |
329 | 329 | ||
330 | QString Todo::dtDueStr(bool shortfmt) const | 330 | QString Todo::dtDueStr(bool shortfmt) const |
331 | { | 331 | { |
332 | if ( doesFloat() ) | 332 | if ( doesFloat() ) |
333 | return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); | 333 | return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); |
334 | return KGlobal::locale()->formatDateTime(mDtDue, shortfmt); | 334 | return KGlobal::locale()->formatDateTime(mDtDue, shortfmt); |
335 | } | 335 | } |
336 | // retval 0 : no found | 336 | // retval 0 : no found |
337 | // 1 : due for date found | 337 | // 1 : due for date found |
338 | // 2 : overdue for date found | 338 | // 2 : overdue for date found |
339 | int Todo::hasDueSubTodoForDate( const QDate & date, bool checkSubtodos ) | 339 | int Todo::hasDueSubTodoForDate( const QDate & date, bool checkSubtodos ) |
340 | { | 340 | { |
341 | int retval = 0; | 341 | int retval = 0; |
342 | if ( isCompleted() ) | 342 | if ( isCompleted() ) |
343 | return 0; | 343 | return 0; |
344 | if ( hasDueDate() ) { | 344 | if ( hasDueDate() ) { |
345 | if ( dtDue().date() < date ) | 345 | if ( dtDue().date() < date ) |
346 | return 2; | 346 | return 2; |
347 | // we do not return, because we may find an overdue sub todo | 347 | // we do not return, because we may find an overdue sub todo |
348 | if ( dtDue().date() == date ) | 348 | if ( dtDue().date() == date ) |
349 | retval = 1; | 349 | retval = 1; |
350 | } | 350 | } |
351 | if ( checkSubtodos ) { | 351 | if ( checkSubtodos ) { |
352 | Incidence *aTodo; | 352 | Incidence *aTodo; |
353 | for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { | 353 | for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { |
354 | int ret = ((Todo*)aTodo)->hasDueSubTodoForDate( date ,checkSubtodos ); | 354 | int ret = ((Todo*)aTodo)->hasDueSubTodoForDate( date ,checkSubtodos ); |
355 | if ( ret == 2 ) | 355 | if ( ret == 2 ) |
356 | return 2; | 356 | return 2; |
357 | if ( ret == 1) | 357 | if ( ret == 1) |
358 | retval = 1; | 358 | retval = 1; |
359 | } | 359 | } |
360 | } | 360 | } |
361 | return retval; | 361 | return retval; |
362 | } | 362 | } |
363 | int Todo::hasDueSubTodo( bool checkSubtodos ) //= true | 363 | int Todo::hasDueSubTodo( bool checkSubtodos ) //= true |
364 | { | 364 | { |
365 | return hasDueSubTodoForDate(QDate::currentDate(), checkSubtodos ); | 365 | return hasDueSubTodoForDate(QDate::currentDate(), checkSubtodos ); |
366 | } | 366 | } |
367 | bool Todo::hasDueDate() const | 367 | bool Todo::hasDueDate() const |
368 | { | 368 | { |
369 | return mHasDueDate; | 369 | return mHasDueDate; |
370 | } | 370 | } |
371 | 371 | ||
372 | void Todo::setHasDueDate(bool f) | 372 | void Todo::setHasDueDate(bool f) |
373 | { | 373 | { |
374 | if (mReadOnly) return; | 374 | if (mReadOnly) return; |
375 | mHasDueDate = f; | 375 | mHasDueDate = f; |
376 | updated(); | 376 | updated(); |
377 | } | 377 | } |
378 | 378 | ||
379 | 379 | ||
380 | #if 0 | 380 | #if 0 |
381 | void Todo::setStatus(const QString &statStr) | 381 | void Todo::setStatus(const QString &statStr) |
382 | { | 382 | { |
383 | if (mReadOnly) return; | 383 | if (mReadOnly) return; |
384 | QString ss(statStr.upper()); | 384 | QString ss(statStr.upper()); |
385 | 385 | ||
386 | if (ss == "X-ACTION") | 386 | if (ss == "X-ACTION") |
387 | mStatus = NEEDS_ACTION; | 387 | mStatus = NEEDS_ACTION; |
388 | else if (ss == "NEEDS ACTION") | 388 | else if (ss == "NEEDS ACTION") |
389 | mStatus = NEEDS_ACTION; | 389 | mStatus = NEEDS_ACTION; |
390 | else if (ss == "ACCEPTED") | 390 | else if (ss == "ACCEPTED") |
391 | mStatus = ACCEPTED; | 391 | mStatus = ACCEPTED; |
392 | else if (ss == "SENT") | 392 | else if (ss == "SENT") |
393 | mStatus = SENT; | 393 | mStatus = SENT; |
394 | else if (ss == "TENTATIVE") | 394 | else if (ss == "TENTATIVE") |
395 | mStatus = TENTATIVE; | 395 | mStatus = TENTATIVE; |
396 | else if (ss == "CONFIRMED") | 396 | else if (ss == "CONFIRMED") |
397 | mStatus = CONFIRMED; | 397 | mStatus = CONFIRMED; |
398 | else if (ss == "DECLINED") | 398 | else if (ss == "DECLINED") |
399 | mStatus = DECLINED; | 399 | mStatus = DECLINED; |
400 | else if (ss == "COMPLETED") | 400 | else if (ss == "COMPLETED") |
401 | mStatus = COMPLETED; | 401 | mStatus = COMPLETED; |
402 | else if (ss == "DELEGATED") | 402 | else if (ss == "DELEGATED") |
403 | mStatus = DELEGATED; | 403 | mStatus = DELEGATED; |
404 | 404 | ||
405 | updated(); | 405 | updated(); |
406 | } | 406 | } |
407 | 407 | ||
408 | void Todo::setStatus(int status) | 408 | void Todo::setStatus(int status) |
409 | { | 409 | { |
410 | if (mReadOnly) return; | 410 | if (mReadOnly) return; |
411 | mStatus = status; | 411 | mStatus = status; |
412 | updated(); | 412 | updated(); |
413 | } | 413 | } |
414 | 414 | ||
415 | int Todo::status() const | 415 | int Todo::status() const |
416 | { | 416 | { |
417 | return mStatus; | 417 | return mStatus; |
418 | } | 418 | } |
419 | 419 | ||
420 | QString Todo::statusStr() const | 420 | QString Todo::statusStr() const |
421 | { | 421 | { |
422 | switch(mStatus) { | 422 | switch(mStatus) { |
423 | case NEEDS_ACTION: | 423 | case NEEDS_ACTION: |
424 | return QString("NEEDS ACTION"); | 424 | return QString("NEEDS ACTION"); |
425 | break; | 425 | break; |
426 | case ACCEPTED: | 426 | case ACCEPTED: |
427 | return QString("ACCEPTED"); | 427 | return QString("ACCEPTED"); |
428 | break; | 428 | break; |
429 | case SENT: | 429 | case SENT: |
430 | return QString("SENT"); | 430 | return QString("SENT"); |
431 | break; | 431 | break; |
432 | case TENTATIVE: | 432 | case TENTATIVE: |
433 | return QString("TENTATIVE"); | 433 | return QString("TENTATIVE"); |
434 | break; | 434 | break; |
435 | case CONFIRMED: | 435 | case CONFIRMED: |
436 | return QString("CONFIRMED"); | 436 | return QString("CONFIRMED"); |
437 | break; | 437 | break; |
438 | case DECLINED: | 438 | case DECLINED: |
439 | return QString("DECLINED"); | 439 | return QString("DECLINED"); |
440 | break; | 440 | break; |
441 | case COMPLETED: | 441 | case COMPLETED: |
442 | return QString("COMPLETED"); | 442 | return QString("COMPLETED"); |
443 | break; | 443 | break; |
444 | case DELEGATED: | 444 | case DELEGATED: |
445 | return QString("DELEGATED"); | 445 | return QString("DELEGATED"); |
446 | break; | 446 | break; |
447 | } | 447 | } |
448 | return QString(""); | 448 | return QString(""); |
449 | } | 449 | } |
450 | #endif | 450 | #endif |
451 | 451 | ||
452 | bool Todo::isCompleted() const | 452 | bool Todo::isCompleted() const |
453 | { | 453 | { |
454 | if (mPercentComplete == 100) { | 454 | if (mPercentComplete == 100) { |
455 | return true; | 455 | return true; |
456 | } | 456 | } |
457 | else return false; | 457 | else return false; |
458 | } | 458 | } |
459 | 459 | ||
460 | void Todo::setCompleted(bool completed) | 460 | void Todo::setCompleted(bool completed) |
461 | { | 461 | { |
462 | if ( mHasRecurrenceID && completed && mPercentComplete != 100 ) { | 462 | if ( mHasRecurrenceID && completed && mPercentComplete != 100 ) { |
463 | if ( !setRecurDates() ) | 463 | if ( !setRecurDates() ) |
464 | completed = false; | 464 | completed = false; |
465 | } | 465 | } |
466 | if (completed) mPercentComplete = 100; | 466 | if (completed) mPercentComplete = 100; |
467 | else { | 467 | else { |
468 | mPercentComplete = 0; | 468 | mPercentComplete = 0; |
469 | mHasCompletedDate = false; | 469 | mHasCompletedDate = false; |
470 | } | 470 | } |
471 | updated(); | 471 | updated(); |
472 | } | 472 | } |
473 | 473 | ||
474 | QDateTime Todo::completed() const | 474 | QDateTime Todo::completed() const |
475 | { | 475 | { |
476 | return mCompleted; | 476 | return mCompleted; |
477 | } | 477 | } |
478 | 478 | ||
479 | QString Todo::completedStr( bool shortF ) const | 479 | QString Todo::completedStr( bool shortF ) const |
480 | { | 480 | { |
481 | return KGlobal::locale()->formatDateTime(mCompleted, shortF); | 481 | return KGlobal::locale()->formatDateTime(mCompleted, shortF); |
482 | } | 482 | } |
483 | 483 | ||
484 | void Todo::setCompleted(const QDateTime &completed) | 484 | void Todo::setCompleted(const QDateTime &completed) |
485 | { | 485 | { |
486 | //qDebug("Todo::setCompleted "); | 486 | //qDebug("Todo::setCompleted "); |
487 | if ( mHasCompletedDate ) { | 487 | if ( mHasCompletedDate ) { |
488 | // qDebug("has completed data - return "); | 488 | // qDebug("has completed data - return "); |
489 | return; | 489 | return; |
490 | } | 490 | } |
491 | mHasCompletedDate = true; | 491 | mHasCompletedDate = true; |
492 | mPercentComplete = 100; | 492 | mPercentComplete = 100; |
493 | mCompleted = getEvenTime(completed); | 493 | mCompleted = getEvenTime(completed); |
494 | updated(); | 494 | updated(); |
495 | } | 495 | } |
496 | 496 | ||
497 | bool Todo::hasCompletedDate() const | 497 | bool Todo::hasCompletedDate() const |
498 | { | 498 | { |
499 | return mHasCompletedDate; | 499 | return mHasCompletedDate; |