-rw-r--r-- | libkcal/calendar.cpp | 5 | ||||
-rw-r--r-- | libkcal/calendar.h | 9 | ||||
-rw-r--r-- | libkcal/calendarlocal.cpp | 56 | ||||
-rw-r--r-- | libkcal/calendarlocal.h | 6 |
4 files changed, 71 insertions, 5 deletions
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp index f4350d9..5092d1a 100644 --- a/libkcal/calendar.cpp +++ b/libkcal/calendar.cpp | |||
@@ -1,483 +1,488 @@ | |||
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) 2000,2001 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2000,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 | #include <stdlib.h> | 22 | #include <stdlib.h> |
23 | #include <time.h> | 23 | #include <time.h> |
24 | 24 | ||
25 | #include <kdebug.h> | 25 | #include <kdebug.h> |
26 | #include <kglobal.h> | 26 | #include <kglobal.h> |
27 | #include <klocale.h> | 27 | #include <klocale.h> |
28 | 28 | ||
29 | #include "exceptions.h" | 29 | #include "exceptions.h" |
30 | #include "calfilter.h" | 30 | #include "calfilter.h" |
31 | 31 | ||
32 | #include "calendar.h" | 32 | #include "calendar.h" |
33 | #include "syncdefines.h" | 33 | #include "syncdefines.h" |
34 | 34 | ||
35 | using namespace KCal; | 35 | using namespace KCal; |
36 | 36 | ||
37 | Calendar::Calendar() | 37 | Calendar::Calendar() |
38 | { | 38 | { |
39 | 39 | ||
40 | init(); | 40 | init(); |
41 | setTimeZoneId( " 00:00 Europe/London(UTC)" ); | 41 | setTimeZoneId( " 00:00 Europe/London(UTC)" ); |
42 | } | 42 | } |
43 | 43 | ||
44 | Calendar::Calendar( const QString &timeZoneId ) | 44 | Calendar::Calendar( const QString &timeZoneId ) |
45 | { | 45 | { |
46 | 46 | ||
47 | init(); | 47 | init(); |
48 | setTimeZoneId(timeZoneId); | 48 | setTimeZoneId(timeZoneId); |
49 | } | 49 | } |
50 | 50 | ||
51 | void Calendar::init() | 51 | void Calendar::init() |
52 | { | 52 | { |
53 | mObserver = 0; | 53 | mObserver = 0; |
54 | mNewObserver = false; | 54 | mNewObserver = false; |
55 | mUndoIncidence = 0; | 55 | mUndoIncidence = 0; |
56 | mDeleteIncidencesOnClose = true; | ||
56 | mModified = false; | 57 | mModified = false; |
57 | mDefaultCalendar = 1; | 58 | mDefaultCalendar = 1; |
58 | // Setup default filter, which does nothing | 59 | // Setup default filter, which does nothing |
59 | mDefaultFilter = new CalFilter; | 60 | mDefaultFilter = new CalFilter; |
60 | mFilter = mDefaultFilter; | 61 | mFilter = mDefaultFilter; |
61 | mFilter->setEnabled(false); | 62 | mFilter->setEnabled(false); |
62 | 63 | ||
63 | // initialize random numbers. This is a hack, and not | 64 | // initialize random numbers. This is a hack, and not |
64 | // even that good of one at that. | 65 | // even that good of one at that. |
65 | // srandom(time(0)); | 66 | // srandom(time(0)); |
66 | 67 | ||
67 | // user information... | 68 | // user information... |
68 | setOwner(i18n("Unknown Name")); | 69 | setOwner(i18n("Unknown Name")); |
69 | setEmail(i18n("unknown@nowhere")); | 70 | setEmail(i18n("unknown@nowhere")); |
70 | 71 | ||
71 | #if 0 | 72 | #if 0 |
72 | tmpStr = KOPrefs::instance()->mTimeZone; | 73 | tmpStr = KOPrefs::instance()->mTimeZone; |
73 | // kdDebug(5800) << "Calendar::Calendar(): TimeZone: " << tmpStr << endl; | 74 | // kdDebug(5800) << "Calendar::Calendar(): TimeZone: " << tmpStr << endl; |
74 | int dstSetting = KOPrefs::instance()->mDaylightSavings; | 75 | int dstSetting = KOPrefs::instance()->mDaylightSavings; |
75 | extern long int timezone; | 76 | extern long int timezone; |
76 | struct tm *now; | 77 | struct tm *now; |
77 | time_t curtime; | 78 | time_t curtime; |
78 | curtime = time(0); | 79 | curtime = time(0); |
79 | now = localtime(&curtime); | 80 | now = localtime(&curtime); |
80 | int hourOff = - ((timezone / 60) / 60); | 81 | int hourOff = - ((timezone / 60) / 60); |
81 | if (now->tm_isdst) | 82 | if (now->tm_isdst) |
82 | hourOff += 1; | 83 | hourOff += 1; |
83 | QString tzStr; | 84 | QString tzStr; |
84 | tzStr.sprintf("%.2d%.2d", | 85 | tzStr.sprintf("%.2d%.2d", |
85 | hourOff, | 86 | hourOff, |
86 | abs((timezone / 60) % 60)); | 87 | abs((timezone / 60) % 60)); |
87 | 88 | ||
88 | // if no time zone was in the config file, write what we just discovered. | 89 | // if no time zone was in the config file, write what we just discovered. |
89 | if (tmpStr.isEmpty()) { | 90 | if (tmpStr.isEmpty()) { |
90 | // KOPrefs::instance()->mTimeZone = tzStr; | 91 | // KOPrefs::instance()->mTimeZone = tzStr; |
91 | } else { | 92 | } else { |
92 | tzStr = tmpStr; | 93 | tzStr = tmpStr; |
93 | } | 94 | } |
94 | 95 | ||
95 | // if daylight savings has changed since last load time, we need | 96 | // if daylight savings has changed since last load time, we need |
96 | // to rewrite these settings to the config file. | 97 | // to rewrite these settings to the config file. |
97 | if ((now->tm_isdst && !dstSetting) || | 98 | if ((now->tm_isdst && !dstSetting) || |
98 | (!now->tm_isdst && dstSetting)) { | 99 | (!now->tm_isdst && dstSetting)) { |
99 | KOPrefs::instance()->mTimeZone = tzStr; | 100 | KOPrefs::instance()->mTimeZone = tzStr; |
100 | KOPrefs::instance()->mDaylightSavings = now->tm_isdst; | 101 | KOPrefs::instance()->mDaylightSavings = now->tm_isdst; |
101 | } | 102 | } |
102 | 103 | ||
103 | setTimeZone(tzStr); | 104 | setTimeZone(tzStr); |
104 | #endif | 105 | #endif |
105 | 106 | ||
106 | // KOPrefs::instance()->writeConfig(); | 107 | // KOPrefs::instance()->writeConfig(); |
107 | } | 108 | } |
108 | 109 | ||
109 | Calendar::~Calendar() | 110 | Calendar::~Calendar() |
110 | { | 111 | { |
111 | delete mDefaultFilter; | 112 | delete mDefaultFilter; |
112 | if ( mUndoIncidence ) | 113 | if ( mUndoIncidence ) |
113 | delete mUndoIncidence; | 114 | delete mUndoIncidence; |
114 | } | 115 | } |
116 | void Calendar::setDontDeleteIncidencesOnClose () | ||
117 | { | ||
118 | mDeleteIncidencesOnClose = false; | ||
119 | } | ||
115 | void Calendar::setDefaultCalendar( int d ) | 120 | void Calendar::setDefaultCalendar( int d ) |
116 | { | 121 | { |
117 | mDefaultCalendar = d; | 122 | mDefaultCalendar = d; |
118 | } | 123 | } |
119 | int Calendar::defaultCalendar() | 124 | int Calendar::defaultCalendar() |
120 | { | 125 | { |
121 | return mDefaultCalendar; | 126 | return mDefaultCalendar; |
122 | } | 127 | } |
123 | const QString &Calendar::getOwner() const | 128 | const QString &Calendar::getOwner() const |
124 | { | 129 | { |
125 | return mOwner; | 130 | return mOwner; |
126 | } | 131 | } |
127 | 132 | ||
128 | bool Calendar::undoDeleteIncidence() | 133 | bool Calendar::undoDeleteIncidence() |
129 | { | 134 | { |
130 | if (!mUndoIncidence) | 135 | if (!mUndoIncidence) |
131 | return false; | 136 | return false; |
132 | addIncidence(mUndoIncidence); | 137 | addIncidence(mUndoIncidence); |
133 | mUndoIncidence = 0; | 138 | mUndoIncidence = 0; |
134 | return true; | 139 | return true; |
135 | } | 140 | } |
136 | void Calendar::setOwner(const QString &os) | 141 | void Calendar::setOwner(const QString &os) |
137 | { | 142 | { |
138 | int i; | 143 | int i; |
139 | mOwner = os; | 144 | mOwner = os; |
140 | i = mOwner.find(','); | 145 | i = mOwner.find(','); |
141 | if (i != -1) | 146 | if (i != -1) |
142 | mOwner = mOwner.left(i); | 147 | mOwner = mOwner.left(i); |
143 | 148 | ||
144 | setModified( true ); | 149 | setModified( true ); |
145 | } | 150 | } |
146 | 151 | ||
147 | void Calendar::setTimeZone(const QString & tz) | 152 | void Calendar::setTimeZone(const QString & tz) |
148 | { | 153 | { |
149 | bool neg = FALSE; | 154 | bool neg = FALSE; |
150 | int hours, minutes; | 155 | int hours, minutes; |
151 | QString tmpStr(tz); | 156 | QString tmpStr(tz); |
152 | 157 | ||
153 | if (tmpStr.left(1) == "-") | 158 | if (tmpStr.left(1) == "-") |
154 | neg = TRUE; | 159 | neg = TRUE; |
155 | if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+") | 160 | if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+") |
156 | tmpStr.remove(0, 1); | 161 | tmpStr.remove(0, 1); |
157 | hours = tmpStr.left(2).toInt(); | 162 | hours = tmpStr.left(2).toInt(); |
158 | if (tmpStr.length() > 2) | 163 | if (tmpStr.length() > 2) |
159 | minutes = tmpStr.right(2).toInt(); | 164 | minutes = tmpStr.right(2).toInt(); |
160 | else | 165 | else |
161 | minutes = 0; | 166 | minutes = 0; |
162 | mTimeZone = (60*hours+minutes); | 167 | mTimeZone = (60*hours+minutes); |
163 | if (neg) | 168 | if (neg) |
164 | mTimeZone = -mTimeZone; | 169 | mTimeZone = -mTimeZone; |
165 | mLocalTime = false; | 170 | mLocalTime = false; |
166 | 171 | ||
167 | setModified( true ); | 172 | setModified( true ); |
168 | } | 173 | } |
169 | 174 | ||
170 | QString Calendar::getTimeZoneStr() const | 175 | QString Calendar::getTimeZoneStr() const |
171 | { | 176 | { |
172 | if (mLocalTime) | 177 | if (mLocalTime) |
173 | return ""; | 178 | return ""; |
174 | QString tmpStr; | 179 | QString tmpStr; |
175 | int hours = abs(mTimeZone / 60); | 180 | int hours = abs(mTimeZone / 60); |
176 | int minutes = abs(mTimeZone % 60); | 181 | int minutes = abs(mTimeZone % 60); |
177 | bool neg = mTimeZone < 0; | 182 | bool neg = mTimeZone < 0; |
178 | 183 | ||
179 | tmpStr.sprintf("%c%.2d%.2d", | 184 | tmpStr.sprintf("%c%.2d%.2d", |
180 | (neg ? '-' : '+'), | 185 | (neg ? '-' : '+'), |
181 | hours, minutes); | 186 | hours, minutes); |
182 | return tmpStr; | 187 | return tmpStr; |
183 | } | 188 | } |
184 | 189 | ||
185 | void Calendar::setTimeZone(int tz) | 190 | void Calendar::setTimeZone(int tz) |
186 | { | 191 | { |
187 | mTimeZone = tz; | 192 | mTimeZone = tz; |
188 | mLocalTime = false; | 193 | mLocalTime = false; |
189 | 194 | ||
190 | setModified( true ); | 195 | setModified( true ); |
191 | } | 196 | } |
192 | 197 | ||
193 | int Calendar::getTimeZone() const | 198 | int Calendar::getTimeZone() const |
194 | { | 199 | { |
195 | return mTimeZone; | 200 | return mTimeZone; |
196 | } | 201 | } |
197 | 202 | ||
198 | void Calendar::setTimeZoneId(const QString &id) | 203 | void Calendar::setTimeZoneId(const QString &id) |
199 | { | 204 | { |
200 | mTimeZoneId = id; | 205 | mTimeZoneId = id; |
201 | mLocalTime = false; | 206 | mLocalTime = false; |
202 | mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId); | 207 | mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId); |
203 | if ( mTimeZone > 1000) | 208 | if ( mTimeZone > 1000) |
204 | setLocalTime(); | 209 | setLocalTime(); |
205 | //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone); | 210 | //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone); |
206 | setModified( true ); | 211 | setModified( true ); |
207 | } | 212 | } |
208 | 213 | ||
209 | QString Calendar::timeZoneId() const | 214 | QString Calendar::timeZoneId() const |
210 | { | 215 | { |
211 | return mTimeZoneId; | 216 | return mTimeZoneId; |
212 | } | 217 | } |
213 | 218 | ||
214 | void Calendar::setLocalTime() | 219 | void Calendar::setLocalTime() |
215 | { | 220 | { |
216 | //qDebug("Calendar::setLocalTime() "); | 221 | //qDebug("Calendar::setLocalTime() "); |
217 | mLocalTime = true; | 222 | mLocalTime = true; |
218 | mTimeZone = 0; | 223 | mTimeZone = 0; |
219 | mTimeZoneId = ""; | 224 | mTimeZoneId = ""; |
220 | 225 | ||
221 | setModified( true ); | 226 | setModified( true ); |
222 | } | 227 | } |
223 | 228 | ||
224 | bool Calendar::isLocalTime() const | 229 | bool Calendar::isLocalTime() const |
225 | { | 230 | { |
226 | return mLocalTime; | 231 | return mLocalTime; |
227 | } | 232 | } |
228 | 233 | ||
229 | const QString &Calendar::getEmail() | 234 | const QString &Calendar::getEmail() |
230 | { | 235 | { |
231 | return mOwnerEmail; | 236 | return mOwnerEmail; |
232 | } | 237 | } |
233 | 238 | ||
234 | void Calendar::setEmail(const QString &e) | 239 | void Calendar::setEmail(const QString &e) |
235 | { | 240 | { |
236 | mOwnerEmail = e; | 241 | mOwnerEmail = e; |
237 | 242 | ||
238 | setModified( true ); | 243 | setModified( true ); |
239 | } | 244 | } |
240 | 245 | ||
241 | void Calendar::setFilter(CalFilter *filter) | 246 | void Calendar::setFilter(CalFilter *filter) |
242 | { | 247 | { |
243 | mFilter = filter; | 248 | mFilter = filter; |
244 | } | 249 | } |
245 | 250 | ||
246 | CalFilter *Calendar::filter() | 251 | CalFilter *Calendar::filter() |
247 | { | 252 | { |
248 | return mFilter; | 253 | return mFilter; |
249 | } | 254 | } |
250 | 255 | ||
251 | QPtrList<Incidence> Calendar::incidences() | 256 | QPtrList<Incidence> Calendar::incidences() |
252 | { | 257 | { |
253 | QPtrList<Incidence> incidences; | 258 | QPtrList<Incidence> incidences; |
254 | 259 | ||
255 | Incidence *i; | 260 | Incidence *i; |
256 | 261 | ||
257 | QPtrList<Event> e = events(); | 262 | QPtrList<Event> e = events(); |
258 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); | 263 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); |
259 | 264 | ||
260 | QPtrList<Todo> t = todos(); | 265 | QPtrList<Todo> t = todos(); |
261 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); | 266 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); |
262 | 267 | ||
263 | QPtrList<Journal> j = journals(); | 268 | QPtrList<Journal> j = journals(); |
264 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); | 269 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); |
265 | 270 | ||
266 | return incidences; | 271 | return incidences; |
267 | } | 272 | } |
268 | 273 | ||
269 | void Calendar::resetPilotStat(int id ) | 274 | void Calendar::resetPilotStat(int id ) |
270 | { | 275 | { |
271 | QPtrList<Incidence> incidences; | 276 | QPtrList<Incidence> incidences; |
272 | 277 | ||
273 | Incidence *i; | 278 | Incidence *i; |
274 | 279 | ||
275 | QPtrList<Event> e = rawEvents(); | 280 | QPtrList<Event> e = rawEvents(); |
276 | for( i = e.first(); i; i = e.next() ) i->setPilotId( id ); | 281 | for( i = e.first(); i; i = e.next() ) i->setPilotId( id ); |
277 | 282 | ||
278 | QPtrList<Todo> t = rawTodos(); | 283 | QPtrList<Todo> t = rawTodos(); |
279 | for( i = t.first(); i; i = t.next() ) i->setPilotId( id ); | 284 | for( i = t.first(); i; i = t.next() ) i->setPilotId( id ); |
280 | 285 | ||
281 | QPtrList<Journal> j = journals(); | 286 | QPtrList<Journal> j = journals(); |
282 | for( i = j.first(); i; i = j.next() ) i->setPilotId( id ); | 287 | for( i = j.first(); i; i = j.next() ) i->setPilotId( id ); |
283 | } | 288 | } |
284 | void Calendar::resetTempSyncStat() | 289 | void Calendar::resetTempSyncStat() |
285 | { | 290 | { |
286 | QPtrList<Incidence> incidences; | 291 | QPtrList<Incidence> incidences; |
287 | 292 | ||
288 | Incidence *i; | 293 | Incidence *i; |
289 | 294 | ||
290 | QPtrList<Event> e = rawEvents(); | 295 | QPtrList<Event> e = rawEvents(); |
291 | for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 296 | for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
292 | 297 | ||
293 | QPtrList<Todo> t = rawTodos(); | 298 | QPtrList<Todo> t = rawTodos(); |
294 | for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 299 | for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
295 | 300 | ||
296 | QPtrList<Journal> j = journals(); | 301 | QPtrList<Journal> j = journals(); |
297 | for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 302 | for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
298 | } | 303 | } |
299 | QPtrList<Incidence> Calendar::rawIncidences() | 304 | QPtrList<Incidence> Calendar::rawIncidences() |
300 | { | 305 | { |
301 | QPtrList<Incidence> incidences; | 306 | QPtrList<Incidence> incidences; |
302 | 307 | ||
303 | Incidence *i; | 308 | Incidence *i; |
304 | 309 | ||
305 | QPtrList<Event> e = rawEvents(); | 310 | QPtrList<Event> e = rawEvents(); |
306 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); | 311 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); |
307 | 312 | ||
308 | QPtrList<Todo> t = rawTodos(); | 313 | QPtrList<Todo> t = rawTodos(); |
309 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); | 314 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); |
310 | 315 | ||
311 | QPtrList<Journal> j = journals(); | 316 | QPtrList<Journal> j = journals(); |
312 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); | 317 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); |
313 | 318 | ||
314 | return incidences; | 319 | return incidences; |
315 | } | 320 | } |
316 | 321 | ||
317 | QPtrList<Event> Calendar::events( const QDate &date, bool sorted ) | 322 | QPtrList<Event> Calendar::events( const QDate &date, bool sorted ) |
318 | { | 323 | { |
319 | QPtrList<Event> el = rawEventsForDate(date,sorted); | 324 | QPtrList<Event> el = rawEventsForDate(date,sorted); |
320 | mFilter->apply(&el); | 325 | mFilter->apply(&el); |
321 | return el; | 326 | return el; |
322 | } | 327 | } |
323 | 328 | ||
324 | QPtrList<Event> Calendar::events( const QDateTime &qdt ) | 329 | QPtrList<Event> Calendar::events( const QDateTime &qdt ) |
325 | { | 330 | { |
326 | QPtrList<Event> el = rawEventsForDate(qdt); | 331 | QPtrList<Event> el = rawEventsForDate(qdt); |
327 | mFilter->apply(&el); | 332 | mFilter->apply(&el); |
328 | return el; | 333 | return el; |
329 | } | 334 | } |
330 | 335 | ||
331 | QPtrList<Event> Calendar::events( const QDate &start, const QDate &end, | 336 | QPtrList<Event> Calendar::events( const QDate &start, const QDate &end, |
332 | bool inclusive) | 337 | bool inclusive) |
333 | { | 338 | { |
334 | QPtrList<Event> el = rawEvents(start,end,inclusive); | 339 | QPtrList<Event> el = rawEvents(start,end,inclusive); |
335 | mFilter->apply(&el); | 340 | mFilter->apply(&el); |
336 | return el; | 341 | return el; |
337 | } | 342 | } |
338 | 343 | ||
339 | QPtrList<Event> Calendar::events() | 344 | QPtrList<Event> Calendar::events() |
340 | { | 345 | { |
341 | QPtrList<Event> el = rawEvents(); | 346 | QPtrList<Event> el = rawEvents(); |
342 | mFilter->apply(&el); | 347 | mFilter->apply(&el); |
343 | return el; | 348 | return el; |
344 | } | 349 | } |
345 | void Calendar::addIncidenceBranch(Incidence *i) | 350 | void Calendar::addIncidenceBranch(Incidence *i) |
346 | { | 351 | { |
347 | addIncidence( i ); | 352 | addIncidence( i ); |
348 | Incidence * inc; | 353 | Incidence * inc; |
349 | QPtrList<Incidence> Relations = i->relations(); | 354 | QPtrList<Incidence> Relations = i->relations(); |
350 | for (inc=Relations.first();inc;inc=Relations.next()) { | 355 | for (inc=Relations.first();inc;inc=Relations.next()) { |
351 | addIncidenceBranch( inc ); | 356 | addIncidenceBranch( inc ); |
352 | } | 357 | } |
353 | } | 358 | } |
354 | 359 | ||
355 | bool Calendar::addIncidence(Incidence *i) | 360 | bool Calendar::addIncidence(Incidence *i) |
356 | { | 361 | { |
357 | Incidence::AddVisitor<Calendar> v(this); | 362 | Incidence::AddVisitor<Calendar> v(this); |
358 | i->setCalID( mDefaultCalendar ); | 363 | i->setCalID( mDefaultCalendar ); |
359 | i->setCalEnabled( true ); | 364 | i->setCalEnabled( true ); |
360 | return i->accept(v); | 365 | return i->accept(v); |
361 | } | 366 | } |
362 | void Calendar::deleteIncidence(Incidence *in) | 367 | void Calendar::deleteIncidence(Incidence *in) |
363 | { | 368 | { |
364 | if ( in->typeID() == eventID ) | 369 | if ( in->typeID() == eventID ) |
365 | deleteEvent( (Event*) in ); | 370 | deleteEvent( (Event*) in ); |
366 | else if ( in->typeID() == todoID ) | 371 | else if ( in->typeID() == todoID ) |
367 | deleteTodo( (Todo*) in); | 372 | deleteTodo( (Todo*) in); |
368 | else if ( in->typeID() == journalID ) | 373 | else if ( in->typeID() == journalID ) |
369 | deleteJournal( (Journal*) in ); | 374 | deleteJournal( (Journal*) in ); |
370 | } | 375 | } |
371 | 376 | ||
372 | Incidence* Calendar::incidence( const QString& uid ) | 377 | Incidence* Calendar::incidence( const QString& uid ) |
373 | { | 378 | { |
374 | Incidence* i; | 379 | Incidence* i; |
375 | 380 | ||
376 | if( (i = todo( uid )) != 0 ) | 381 | if( (i = todo( uid )) != 0 ) |
377 | return i; | 382 | return i; |
378 | if( (i = event( uid )) != 0 ) | 383 | if( (i = event( uid )) != 0 ) |
379 | return i; | 384 | return i; |
380 | if( (i = journal( uid )) != 0 ) | 385 | if( (i = journal( uid )) != 0 ) |
381 | return i; | 386 | return i; |
382 | 387 | ||
383 | return 0; | 388 | return 0; |
384 | } | 389 | } |
385 | 390 | ||
386 | QPtrList<Todo> Calendar::todos() | 391 | QPtrList<Todo> Calendar::todos() |
387 | { | 392 | { |
388 | QPtrList<Todo> tl = rawTodos(); | 393 | QPtrList<Todo> tl = rawTodos(); |
389 | mFilter->apply( &tl ); | 394 | mFilter->apply( &tl ); |
390 | return tl; | 395 | return tl; |
391 | } | 396 | } |
392 | 397 | ||
393 | // When this is called, the todo have already been added to the calendar. | 398 | // When this is called, the todo have already been added to the calendar. |
394 | // This method is only about linking related todos | 399 | // This method is only about linking related todos |
395 | void Calendar::setupRelations( Incidence *incidence ) | 400 | void Calendar::setupRelations( Incidence *incidence ) |
396 | { | 401 | { |
397 | QString uid = incidence->uid(); | 402 | QString uid = incidence->uid(); |
398 | //qDebug("Calendar::setupRelations "); | 403 | //qDebug("Calendar::setupRelations "); |
399 | // First, go over the list of orphans and see if this is their parent | 404 | // First, go over the list of orphans and see if this is their parent |
400 | while( Incidence* i = mOrphans[ uid ] ) { | 405 | while( Incidence* i = mOrphans[ uid ] ) { |
401 | mOrphans.remove( uid ); | 406 | mOrphans.remove( uid ); |
402 | i->setRelatedTo( incidence ); | 407 | i->setRelatedTo( incidence ); |
403 | incidence->addRelation( i ); | 408 | incidence->addRelation( i ); |
404 | mOrphanUids.remove( i->uid() ); | 409 | mOrphanUids.remove( i->uid() ); |
405 | } | 410 | } |
406 | 411 | ||
407 | // Now see about this incidences parent | 412 | // Now see about this incidences parent |
408 | if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) { | 413 | if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) { |
409 | // This incidence has a uid it is related to, but is not registered to it yet | 414 | // This incidence has a uid it is related to, but is not registered to it yet |
410 | // Try to find it | 415 | // Try to find it |
411 | Incidence* parent = this->incidence( incidence->relatedToUid() ); | 416 | Incidence* parent = this->incidence( incidence->relatedToUid() ); |
412 | if( parent ) { | 417 | if( parent ) { |
413 | // Found it | 418 | // Found it |
414 | incidence->setRelatedTo( parent ); | 419 | incidence->setRelatedTo( parent ); |
415 | parent->addRelation( incidence ); | 420 | parent->addRelation( incidence ); |
416 | } else { | 421 | } else { |
417 | // Not found, put this in the mOrphans list | 422 | // Not found, put this in the mOrphans list |
418 | mOrphans.insert( incidence->relatedToUid(), incidence ); | 423 | mOrphans.insert( incidence->relatedToUid(), incidence ); |
419 | mOrphanUids.insert( incidence->uid(), incidence ); | 424 | mOrphanUids.insert( incidence->uid(), incidence ); |
420 | } | 425 | } |
421 | } | 426 | } |
422 | } | 427 | } |
423 | 428 | ||
424 | // If a task with subtasks is deleted, move it's subtasks to the orphans list | 429 | // If a task with subtasks is deleted, move it's subtasks to the orphans list |
425 | void Calendar::removeRelations( Incidence *incidence ) | 430 | void Calendar::removeRelations( Incidence *incidence ) |
426 | { | 431 | { |
427 | // qDebug("Calendar::removeRelations "); | 432 | // qDebug("Calendar::removeRelations "); |
428 | QString uid = incidence->uid(); | 433 | QString uid = incidence->uid(); |
429 | 434 | ||
430 | QPtrList<Incidence> relations = incidence->relations(); | 435 | QPtrList<Incidence> relations = incidence->relations(); |
431 | for( Incidence* i = relations.first(); i; i = relations.next() ) | 436 | for( Incidence* i = relations.first(); i; i = relations.next() ) |
432 | if( !mOrphanUids.find( i->uid() ) ) { | 437 | if( !mOrphanUids.find( i->uid() ) ) { |
433 | mOrphans.insert( uid, i ); | 438 | mOrphans.insert( uid, i ); |
434 | mOrphanUids.insert( i->uid(), i ); | 439 | mOrphanUids.insert( i->uid(), i ); |
435 | i->setRelatedTo( 0 ); | 440 | i->setRelatedTo( 0 ); |
436 | i->setRelatedToUid( uid ); | 441 | i->setRelatedToUid( uid ); |
437 | } | 442 | } |
438 | 443 | ||
439 | // If this incidence is related to something else, tell that about it | 444 | // If this incidence is related to something else, tell that about it |
440 | if( incidence->relatedTo() ) | 445 | if( incidence->relatedTo() ) |
441 | incidence->relatedTo()->removeRelation( incidence ); | 446 | incidence->relatedTo()->removeRelation( incidence ); |
442 | 447 | ||
443 | // Remove this one from the orphans list | 448 | // Remove this one from the orphans list |
444 | if( mOrphanUids.remove( uid ) ) | 449 | if( mOrphanUids.remove( uid ) ) |
445 | // This incidence is located in the orphans list - it should be removed | 450 | // This incidence is located in the orphans list - it should be removed |
446 | if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) { | 451 | if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) { |
447 | // Removing wasn't that easy | 452 | // Removing wasn't that easy |
448 | for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) { | 453 | for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) { |
449 | if( it.current()->uid() == uid ) { | 454 | if( it.current()->uid() == uid ) { |
450 | mOrphans.remove( it.currentKey() ); | 455 | mOrphans.remove( it.currentKey() ); |
451 | break; | 456 | break; |
452 | } | 457 | } |
453 | } | 458 | } |
454 | } | 459 | } |
455 | } | 460 | } |
456 | 461 | ||
457 | void Calendar::registerObserver( Observer *observer ) | 462 | void Calendar::registerObserver( Observer *observer ) |
458 | { | 463 | { |
459 | mObserver = observer; | 464 | mObserver = observer; |
460 | mNewObserver = true; | 465 | mNewObserver = true; |
461 | } | 466 | } |
462 | 467 | ||
463 | void Calendar::setModified( bool modified ) | 468 | void Calendar::setModified( bool modified ) |
464 | { | 469 | { |
465 | if ( mObserver ) mObserver->calendarModified( modified, this ); | 470 | if ( mObserver ) mObserver->calendarModified( modified, this ); |
466 | if ( modified != mModified || mNewObserver ) { | 471 | if ( modified != mModified || mNewObserver ) { |
467 | mNewObserver = false; | 472 | mNewObserver = false; |
468 | // if ( mObserver ) mObserver->calendarModified( modified, this ); | 473 | // if ( mObserver ) mObserver->calendarModified( modified, this ); |
469 | mModified = modified; | 474 | mModified = modified; |
470 | } | 475 | } |
471 | } | 476 | } |
472 | 477 | ||
473 | void Calendar::setLoadedProductId( const QString &id ) | 478 | void Calendar::setLoadedProductId( const QString &id ) |
474 | { | 479 | { |
475 | mLoadedProductId = id; | 480 | mLoadedProductId = id; |
476 | } | 481 | } |
477 | 482 | ||
478 | QString Calendar::loadedProductId() | 483 | QString Calendar::loadedProductId() |
479 | { | 484 | { |
480 | return mLoadedProductId; | 485 | return mLoadedProductId; |
481 | } | 486 | } |
482 | 487 | ||
483 | //#include "calendar.moc" | 488 | //#include "calendar.moc" |
diff --git a/libkcal/calendar.h b/libkcal/calendar.h index 4c6760f..73f82bb 100644 --- a/libkcal/calendar.h +++ b/libkcal/calendar.h | |||
@@ -1,366 +1,373 @@ | |||
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; | ||
78 | virtual bool addCalendarFile( QString name, int id ) = 0; | ||
77 | 79 | ||
78 | /** | 80 | /** |
79 | Sync changes in memory to persistant storage. | 81 | Sync changes in memory to persistant storage. |
80 | */ | 82 | */ |
81 | virtual void save() = 0; | 83 | virtual void save() = 0; |
82 | virtual QPtrList<Event> getExternLastSyncEvents() = 0; | 84 | virtual QPtrList<Event> getExternLastSyncEvents() = 0; |
83 | virtual void removeSyncInfo( QString syncProfile) = 0; | 85 | virtual void removeSyncInfo( QString syncProfile) = 0; |
84 | virtual bool isSaving() { return false; } | 86 | virtual bool isSaving() { return false; } |
85 | 87 | ||
86 | /** | 88 | /** |
87 | Return the owner of the calendar's full name. | 89 | Return the owner of the calendar's full name. |
88 | */ | 90 | */ |
89 | const QString &getOwner() const; | 91 | const QString &getOwner() const; |
90 | /** | 92 | /** |
91 | Set the owner of the calendar. Should be owner's full name. | 93 | Set the owner of the calendar. Should be owner's full name. |
92 | */ | 94 | */ |
93 | void setOwner( const QString &os ); | 95 | void setOwner( const QString &os ); |
94 | /** | 96 | /** |
95 | Return the email address of the calendar owner. | 97 | Return the email address of the calendar owner. |
96 | */ | 98 | */ |
97 | const QString &getEmail(); | 99 | const QString &getEmail(); |
98 | /** | 100 | /** |
99 | Set the email address of the calendar owner. | 101 | Set the email address of the calendar owner. |
100 | */ | 102 | */ |
101 | void setEmail( const QString & ); | 103 | void setEmail( const QString & ); |
102 | 104 | ||
103 | /** | 105 | /** |
104 | Set time zone from a timezone string (e.g. -2:00) | 106 | Set time zone from a timezone string (e.g. -2:00) |
105 | */ | 107 | */ |
106 | void setTimeZone( const QString &tz ); | 108 | void setTimeZone( const QString &tz ); |
107 | /** | 109 | /** |
108 | Set time zone from a minutes value (e.g. -60) | 110 | Set time zone from a minutes value (e.g. -60) |
109 | */ | 111 | */ |
110 | void setTimeZone( int tz ); | 112 | void setTimeZone( int tz ); |
111 | /** | 113 | /** |
112 | Return time zone as offest in minutes. | 114 | Return time zone as offest in minutes. |
113 | */ | 115 | */ |
114 | int getTimeZone() const; | 116 | int getTimeZone() const; |
115 | /** | 117 | /** |
116 | Compute an ISO 8601 format string from the time zone. | 118 | Compute an ISO 8601 format string from the time zone. |
117 | */ | 119 | */ |
118 | QString getTimeZoneStr() const; | 120 | QString getTimeZoneStr() const; |
119 | /** | 121 | /** |
120 | Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal | 122 | Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal |
121 | values). | 123 | values). |
122 | */ | 124 | */ |
123 | void setTimeZoneId( const QString & ); | 125 | void setTimeZoneId( const QString & ); |
124 | /** | 126 | /** |
125 | Return time zone id. | 127 | Return time zone id. |
126 | */ | 128 | */ |
127 | QString timeZoneId() const; | 129 | QString timeZoneId() const; |
128 | /** | 130 | /** |
129 | Use local time, not UTC or a time zone. | 131 | Use local time, not UTC or a time zone. |
130 | */ | 132 | */ |
131 | void setLocalTime(); | 133 | void setLocalTime(); |
132 | /** | 134 | /** |
133 | Return whether local time is being used. | 135 | Return whether local time is being used. |
134 | */ | 136 | */ |
135 | bool isLocalTime() const; | 137 | bool isLocalTime() const; |
136 | 138 | ||
137 | /** | 139 | /** |
138 | Add an incidence to calendar. | 140 | Add an incidence to calendar. |
139 | 141 | ||
140 | @return true on success, false on error. | 142 | @return true on success, false on error. |
141 | */ | 143 | */ |
142 | virtual bool addIncidence( Incidence * ); | 144 | virtual bool addIncidence( Incidence * ); |
143 | 145 | ||
144 | // Adds an incidence and all relatedto incidences to the cal | 146 | // Adds an incidence and all relatedto incidences to the cal |
145 | void addIncidenceBranch( Incidence * ); | 147 | void addIncidenceBranch( Incidence * ); |
146 | /** | 148 | /** |
147 | Return filtered list of all incidences of this calendar. | 149 | Return filtered list of all incidences of this calendar. |
148 | */ | 150 | */ |
149 | virtual QPtrList<Incidence> incidences(); | 151 | virtual QPtrList<Incidence> incidences(); |
150 | 152 | ||
151 | /** | 153 | /** |
152 | Return unfiltered list of all incidences of this calendar. | 154 | Return unfiltered list of all incidences of this calendar. |
153 | */ | 155 | */ |
154 | virtual QPtrList<Incidence> rawIncidences(); | 156 | virtual QPtrList<Incidence> rawIncidences(); |
155 | 157 | ||
156 | /** | 158 | /** |
157 | Adds a Event to this calendar object. | 159 | Adds a Event to this calendar object. |
158 | @param anEvent a pointer to the event to add | 160 | @param anEvent a pointer to the event to add |
159 | 161 | ||
160 | @return true on success, false on error. | 162 | @return true on success, false on error. |
161 | */ | 163 | */ |
162 | virtual bool addEventNoDup( Event *event ) = 0; | 164 | virtual bool addEventNoDup( Event *event ) = 0; |
163 | virtual bool addAnniversaryNoDup( Event *event ) = 0; | 165 | virtual bool addAnniversaryNoDup( Event *event ) = 0; |
164 | virtual bool addEvent( Event *anEvent ) = 0; | 166 | virtual bool addEvent( Event *anEvent ) = 0; |
165 | /** | 167 | /** |
166 | Delete event from calendar. | 168 | Delete event from calendar. |
167 | */ | 169 | */ |
168 | virtual void deleteEvent( Event * ) = 0; | 170 | virtual void deleteEvent( Event * ) = 0; |
169 | /** | 171 | /** |
170 | Retrieves an event on the basis of the unique string ID. | 172 | Retrieves an event on the basis of the unique string ID. |
171 | */ | 173 | */ |
172 | virtual Event *event( const QString &UniqueStr ) = 0; | 174 | virtual Event *event( const QString &UniqueStr ) = 0; |
173 | virtual Event *event( QString, QString ) = 0; | 175 | virtual Event *event( QString, QString ) = 0; |
174 | /** | 176 | /** |
175 | Builds and then returns a list of all events that match for the | 177 | Builds and then returns a list of all events that match for the |
176 | date specified. useful for dayView, etc. etc. | 178 | date specified. useful for dayView, etc. etc. |
177 | The calendar filter is applied. | 179 | The calendar filter is applied. |
178 | */ | 180 | */ |
179 | QPtrList<Event> events( const QDate &date, bool sorted = false); | 181 | QPtrList<Event> events( const QDate &date, bool sorted = false); |
180 | /** | 182 | /** |
181 | Get events, which occur on the given date. | 183 | Get events, which occur on the given date. |
182 | The calendar filter is applied. | 184 | The calendar filter is applied. |
183 | */ | 185 | */ |
184 | QPtrList<Event> events( const QDateTime &qdt ); | 186 | QPtrList<Event> events( const QDateTime &qdt ); |
185 | /** | 187 | /** |
186 | Get events in a range of dates. If inclusive is set to true, only events | 188 | Get events in a range of dates. If inclusive is set to true, only events |
187 | are returned, which are completely included in the range. | 189 | are returned, which are completely included in the range. |
188 | The calendar filter is applied. | 190 | The calendar filter is applied. |
189 | */ | 191 | */ |
190 | QPtrList<Event> events( const QDate &start, const QDate &end, | 192 | QPtrList<Event> events( const QDate &start, const QDate &end, |
191 | bool inclusive = false); | 193 | bool inclusive = false); |
192 | /** | 194 | /** |
193 | Return filtered list of all events in calendar. | 195 | Return filtered list of all events in calendar. |
194 | */ | 196 | */ |
195 | virtual QPtrList<Event> events(); | 197 | virtual QPtrList<Event> events(); |
196 | /** | 198 | /** |
197 | Return unfiltered list of all events in calendar. | 199 | Return unfiltered list of all events in calendar. |
198 | */ | 200 | */ |
199 | virtual QPtrList<Event> rawEvents() = 0; | 201 | virtual QPtrList<Event> rawEvents() = 0; |
200 | 202 | ||
201 | /** | 203 | /** |
202 | Add a todo to the todolist. | 204 | Add a todo to the todolist. |
203 | 205 | ||
204 | @return true on success, false on error. | 206 | @return true on success, false on error. |
205 | */ | 207 | */ |
206 | virtual bool addTodo( Todo *todo ) = 0; | 208 | virtual bool addTodo( Todo *todo ) = 0; |
207 | virtual bool addTodoNoDup( Todo *todo ) = 0; | 209 | virtual bool addTodoNoDup( Todo *todo ) = 0; |
208 | /** | 210 | /** |
209 | Remove a todo from the todolist. | 211 | Remove a todo from the todolist. |
210 | */ | 212 | */ |
211 | virtual void deleteTodo( Todo * ) = 0; | 213 | virtual void deleteTodo( Todo * ) = 0; |
212 | virtual void deleteJournal( Journal * ) = 0; | 214 | virtual void deleteJournal( Journal * ) = 0; |
213 | /** | 215 | /** |
214 | Return filterd list of todos. | 216 | Return filterd list of todos. |
215 | */ | 217 | */ |
216 | virtual QPtrList<Todo> todos(); | 218 | virtual QPtrList<Todo> todos(); |
217 | /** | 219 | /** |
218 | Searches todolist for an event with this unique string identifier, | 220 | Searches todolist for an event with this unique string identifier, |
219 | returns a pointer or null. | 221 | returns a pointer or null. |
220 | */ | 222 | */ |
221 | virtual Todo *todo( const QString &uid ) = 0; | 223 | virtual Todo *todo( const QString &uid ) = 0; |
222 | virtual Todo *todo( QString, QString ) = 0; | 224 | virtual Todo *todo( QString, QString ) = 0; |
223 | /** | 225 | /** |
224 | Returns list of todos due on the specified date. | 226 | Returns list of todos due on the specified date. |
225 | */ | 227 | */ |
226 | virtual QPtrList<Todo> todos( const QDate &date ) = 0; | 228 | virtual QPtrList<Todo> todos( const QDate &date ) = 0; |
227 | /** | 229 | /** |
228 | Return unfiltered list of todos. | 230 | Return unfiltered list of todos. |
229 | */ | 231 | */ |
230 | virtual QPtrList<Todo> rawTodos() = 0; | 232 | virtual QPtrList<Todo> rawTodos() = 0; |
231 | 233 | ||
232 | /** | 234 | /** |
233 | Add a Journal entry to calendar. | 235 | Add a Journal entry to calendar. |
234 | 236 | ||
235 | @return true on success, false on error. | 237 | @return true on success, false on error. |
236 | */ | 238 | */ |
237 | virtual bool addJournal( Journal * ) = 0; | 239 | virtual bool addJournal( Journal * ) = 0; |
238 | /** | 240 | /** |
239 | Return Journal for given date. | 241 | Return Journal for given date. |
240 | */ | 242 | */ |
241 | virtual Journal *journal( const QDate & ) = 0; | 243 | virtual Journal *journal( const QDate & ) = 0; |
242 | /** | 244 | /** |
243 | Return Journal with given UID. | 245 | Return Journal with given UID. |
244 | */ | 246 | */ |
245 | virtual Journal *journal( const QString &UID ) = 0; | 247 | virtual Journal *journal( const QString &UID ) = 0; |
246 | /** | 248 | /** |
247 | Return list of all Journal entries. | 249 | Return list of all Journal entries. |
248 | */ | 250 | */ |
249 | virtual QPtrList<Journal> journals() = 0; | 251 | virtual QPtrList<Journal> journals() = 0; |
250 | 252 | ||
251 | /** | 253 | /** |
252 | Searches all incidence types for an incidence with this unique | 254 | Searches all incidence types for an incidence with this unique |
253 | string identifier, returns a pointer or null. | 255 | string identifier, returns a pointer or null. |
254 | */ | 256 | */ |
255 | Incidence* incidence( const QString&UID ); | 257 | Incidence* incidence( const QString&UID ); |
256 | 258 | ||
257 | /** | 259 | /** |
258 | Setup relations for an incidence. | 260 | Setup relations for an incidence. |
259 | */ | 261 | */ |
260 | virtual void setupRelations( Incidence * ); | 262 | virtual void setupRelations( Incidence * ); |
261 | /** | 263 | /** |
262 | Remove all relations to an incidence | 264 | Remove all relations to an incidence |
263 | */ | 265 | */ |
264 | virtual void removeRelations( Incidence * ); | 266 | virtual void removeRelations( Incidence * ); |
265 | 267 | ||
266 | /** | 268 | /** |
267 | Set calendar filter, which filters events for the events() functions. | 269 | Set calendar filter, which filters events for the events() functions. |
268 | The Filter object is owned by the caller. | 270 | The Filter object is owned by the caller. |
269 | */ | 271 | */ |
270 | void setFilter( CalFilter * ); | 272 | void setFilter( CalFilter * ); |
271 | /** | 273 | /** |
272 | Return calendar filter. | 274 | Return calendar filter. |
273 | */ | 275 | */ |
274 | CalFilter *filter(); | 276 | CalFilter *filter(); |
275 | virtual QDateTime nextAlarm( int daysTo ) = 0; | 277 | virtual QDateTime nextAlarm( int daysTo ) = 0; |
276 | virtual QString nextSummary( ) const = 0; | 278 | virtual QString nextSummary( ) const = 0; |
277 | virtual void reInitAlarmSettings() = 0; | 279 | virtual void reInitAlarmSettings() = 0; |
278 | virtual QDateTime nextAlarmEventDateTime() const = 0; | 280 | virtual QDateTime nextAlarmEventDateTime() const = 0; |
279 | virtual void checkAlarmForIncidence( Incidence *, bool ) = 0; | 281 | virtual void checkAlarmForIncidence( Incidence *, bool ) = 0; |
280 | /** | 282 | /** |
281 | Return all alarms, which ocur in the given time interval. | 283 | Return all alarms, which ocur in the given time interval. |
282 | */ | 284 | */ |
283 | virtual Alarm::List alarms( const QDateTime &from, | 285 | virtual Alarm::List alarms( const QDateTime &from, |
284 | const QDateTime &to ) = 0; | 286 | const QDateTime &to ) = 0; |
285 | 287 | ||
286 | class Observer { | 288 | class Observer { |
287 | public: | 289 | public: |
288 | virtual void calendarModified( bool, Calendar * ) = 0; | 290 | virtual void calendarModified( bool, Calendar * ) = 0; |
289 | }; | 291 | }; |
290 | 292 | ||
291 | void registerObserver( Observer * ); | 293 | void registerObserver( Observer * ); |
292 | 294 | ||
293 | void setModified( bool ); | 295 | void setModified( bool ); |
294 | 296 | ||
295 | /** | 297 | /** |
296 | Set product id returned by loadedProductId(). This function is only | 298 | Set product id returned by loadedProductId(). This function is only |
297 | useful for the calendar loading code. | 299 | useful for the calendar loading code. |
298 | */ | 300 | */ |
299 | void setLoadedProductId( const QString & ); | 301 | void setLoadedProductId( const QString & ); |
300 | /** | 302 | /** |
301 | Return product id taken from file that has been loaded. Returns | 303 | Return product id taken from file that has been loaded. Returns |
302 | QString::null, if no calendar has been loaded. | 304 | QString::null, if no calendar has been loaded. |
303 | */ | 305 | */ |
304 | QString loadedProductId(); | 306 | QString loadedProductId(); |
305 | void setDefaultCalendar( int ); | ||
306 | int defaultCalendar(); | 307 | int defaultCalendar(); |
308 | void setDontDeleteIncidencesOnClose (); | ||
309 | public slots: | ||
310 | void setDefaultCalendar( int ); | ||
307 | virtual void setCalendarEnabled( int id, bool enable ) = 0; | 311 | virtual void setCalendarEnabled( int id, bool enable ) = 0; |
308 | virtual void setAlarmEnabled( int id, bool enable ) = 0; | 312 | virtual void setAlarmEnabled( int id, bool enable ) = 0; |
313 | virtual void setReadOnly( int id, bool enable ) = 0; | ||
309 | virtual void setDefaultCalendarEnabledOnly() = 0; | 314 | virtual void setDefaultCalendarEnabledOnly() = 0; |
310 | signals: | 315 | signals: |
311 | void calendarChanged(); | 316 | void calendarChanged(); |
312 | void calendarSaved(); | 317 | void calendarSaved(); |
313 | void calendarLoaded(); | 318 | void calendarLoaded(); |
314 | void addAlarm(const QDateTime &qdt, const QString ¬i ); | 319 | void addAlarm(const QDateTime &qdt, const QString ¬i ); |
315 | void removeAlarm(const QDateTime &qdt, const QString ¬i ); | 320 | void removeAlarm(const QDateTime &qdt, const QString ¬i ); |
316 | 321 | ||
317 | protected: | 322 | protected: |
318 | /** | 323 | /** |
319 | Get unfiltered events, which occur on the given date. | 324 | Get unfiltered events, which occur on the given date. |
320 | */ | 325 | */ |
321 | virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0; | 326 | virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0; |
322 | /** | 327 | /** |
323 | Get unfiltered events, which occur on the given date. | 328 | Get unfiltered events, which occur on the given date. |
324 | */ | 329 | */ |
325 | virtual QPtrList<Event> rawEventsForDate( const QDate &date, | 330 | virtual QPtrList<Event> rawEventsForDate( const QDate &date, |
326 | bool sorted = false ) = 0; | 331 | bool sorted = false ) = 0; |
327 | /** | 332 | /** |
328 | Get events in a range of dates. If inclusive is set to true, only events | 333 | Get events in a range of dates. If inclusive is set to true, only events |
329 | are returned, which are completely included in the range. | 334 | are returned, which are completely included in the range. |
330 | */ | 335 | */ |
331 | virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end, | 336 | virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end, |
332 | bool inclusive = false ) = 0; | 337 | bool inclusive = false ) = 0; |
333 | 338 | ||
334 | Incidence *mNextAlarmIncidence; | 339 | Incidence *mNextAlarmIncidence; |
335 | Incidence *mUndoIncidence; | 340 | Incidence *mUndoIncidence; |
336 | int mDefaultCalendar; | 341 | int mDefaultCalendar; |
342 | bool mDeleteIncidencesOnClose; | ||
337 | 343 | ||
338 | private: | 344 | private: |
339 | void init(); | 345 | void init(); |
340 | 346 | ||
341 | QString mOwner; // who the calendar belongs to | 347 | QString mOwner; // who the calendar belongs to |
342 | QString mOwnerEmail; // email address of the owner | 348 | QString mOwnerEmail; // email address of the owner |
343 | int mTimeZone; // timezone OFFSET from GMT (MINUTES) | 349 | int mTimeZone; // timezone OFFSET from GMT (MINUTES) |
344 | bool mLocalTime; // use local time, not UTC or a time zone | 350 | bool mLocalTime; // use local time, not UTC or a time zone |
345 | 351 | ||
352 | |||
346 | CalFilter *mFilter; | 353 | CalFilter *mFilter; |
347 | CalFilter *mDefaultFilter; | 354 | CalFilter *mDefaultFilter; |
348 | 355 | ||
349 | 356 | ||
350 | QString mTimeZoneId; | 357 | QString mTimeZoneId; |
351 | 358 | ||
352 | Observer *mObserver; | 359 | Observer *mObserver; |
353 | bool mNewObserver; | 360 | bool mNewObserver; |
354 | 361 | ||
355 | bool mModified; | 362 | bool mModified; |
356 | 363 | ||
357 | QString mLoadedProductId; | 364 | QString mLoadedProductId; |
358 | 365 | ||
359 | // This list is used to put together related todos | 366 | // This list is used to put together related todos |
360 | QDict<Incidence> mOrphans; | 367 | QDict<Incidence> mOrphans; |
361 | QDict<Incidence> mOrphanUids; | 368 | QDict<Incidence> mOrphanUids; |
362 | }; | 369 | }; |
363 | 370 | ||
364 | } | 371 | } |
365 | 372 | ||
366 | #endif | 373 | #endif |
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index c5500bf..e48122a 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp | |||
@@ -1,782 +1,834 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | 3 | ||
4 | Copyright (c) 1998 Preston Brown | 4 | Copyright (c) 1998 Preston Brown |
5 | Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> | 5 | Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> |
6 | 6 | ||
7 | This library is free software; you can redistribute it and/or | 7 | This library is free software; you can redistribute it and/or |
8 | modify it under the terms of the GNU Library General Public | 8 | modify it under the terms of the GNU Library General Public |
9 | License as published by the Free Software Foundation; either | 9 | License as published by the Free Software Foundation; either |
10 | version 2 of the License, or (at your option) any later version. | 10 | version 2 of the License, or (at your option) any later version. |
11 | 11 | ||
12 | This library is distributed in the hope that it will be useful, | 12 | This library is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | Library General Public License for more details. | 15 | Library General Public License for more details. |
16 | 16 | ||
17 | You should have received a copy of the GNU Library General Public License | 17 | You should have received a copy of the GNU Library General Public License |
18 | along with this library; see the file COPYING.LIB. If not, write to | 18 | along with this library; see the file COPYING.LIB. If not, write to |
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. | 20 | Boston, MA 02111-1307, USA. |
21 | */ | 21 | */ |
22 | 22 | ||
23 | #include <qdatetime.h> | 23 | #include <qdatetime.h> |
24 | #include <qstring.h> | 24 | #include <qstring.h> |
25 | #include <qptrlist.h> | 25 | #include <qptrlist.h> |
26 | 26 | ||
27 | #include <kdebug.h> | 27 | #include <kdebug.h> |
28 | #include <kconfig.h> | 28 | #include <kconfig.h> |
29 | #include <kglobal.h> | 29 | #include <kglobal.h> |
30 | #include <klocale.h> | 30 | #include <klocale.h> |
31 | 31 | ||
32 | #include "vcaldrag.h" | 32 | #include "vcaldrag.h" |
33 | #include "vcalformat.h" | 33 | #include "vcalformat.h" |
34 | #include "icalformat.h" | 34 | #include "icalformat.h" |
35 | #include "exceptions.h" | 35 | #include "exceptions.h" |
36 | #include "incidence.h" | 36 | #include "incidence.h" |
37 | #include "journal.h" | 37 | #include "journal.h" |
38 | #include "filestorage.h" | 38 | #include "filestorage.h" |
39 | #include "calfilter.h" | 39 | #include "calfilter.h" |
40 | 40 | ||
41 | #include "calendarlocal.h" | 41 | #include "calendarlocal.h" |
42 | 42 | ||
43 | // #ifndef DESKTOP_VERSION | 43 | // #ifndef DESKTOP_VERSION |
44 | // #include <qtopia/alarmserver.h> | 44 | // #include <qtopia/alarmserver.h> |
45 | // #endif | 45 | // #endif |
46 | using namespace KCal; | 46 | using namespace KCal; |
47 | 47 | ||
48 | CalendarLocal::CalendarLocal() | 48 | CalendarLocal::CalendarLocal() |
49 | : Calendar() | 49 | : Calendar() |
50 | { | 50 | { |
51 | init(); | 51 | init(); |
52 | } | 52 | } |
53 | 53 | ||
54 | CalendarLocal::CalendarLocal(const QString &timeZoneId) | 54 | CalendarLocal::CalendarLocal(const QString &timeZoneId) |
55 | : Calendar(timeZoneId) | 55 | : Calendar(timeZoneId) |
56 | { | 56 | { |
57 | init(); | 57 | init(); |
58 | } | 58 | } |
59 | 59 | ||
60 | void CalendarLocal::init() | 60 | void CalendarLocal::init() |
61 | { | 61 | { |
62 | mNextAlarmIncidence = 0; | 62 | mNextAlarmIncidence = 0; |
63 | } | 63 | } |
64 | 64 | ||
65 | 65 | ||
66 | CalendarLocal::~CalendarLocal() | 66 | CalendarLocal::~CalendarLocal() |
67 | { | 67 | { |
68 | close(); | 68 | if ( mDeleteIncidencesOnClose ) |
69 | close(); | ||
70 | } | ||
71 | bool CalendarLocal::addCalendarFile( QString name, int id ) | ||
72 | { | ||
73 | CalendarLocal calendar( timeZoneId() ); | ||
74 | calendar.setDefaultCalendar( id ); | ||
75 | if ( calendar.load( name ) ) { | ||
76 | addCalendar( &calendar ); | ||
77 | return true; | ||
78 | } | ||
79 | return false; | ||
80 | } | ||
81 | void CalendarLocal::addCalendar( Calendar* cal ) | ||
82 | { | ||
83 | cal->setDontDeleteIncidencesOnClose(); | ||
84 | { | ||
85 | QPtrList<Event> EventList = cal->rawEvents(); | ||
86 | Event * ev = EventList.first(); | ||
87 | while ( ev ) { | ||
88 | mEventList.append( ev ); | ||
89 | ev = EventList.next(); | ||
90 | } | ||
91 | } | ||
92 | { | ||
93 | QPtrList<Todo> TodoList = cal->rawTodos(); | ||
94 | Todo * ev = TodoList.first(); | ||
95 | while ( ev ) { | ||
96 | mTodoList.append( ev ); | ||
97 | ev = TodoList.next(); | ||
98 | } | ||
99 | } | ||
100 | { | ||
101 | QPtrList<Journal> JournalList = cal->journals(); | ||
102 | Journal * ev = JournalList.first(); | ||
103 | while ( ev ) { | ||
104 | mJournalList.append( ev ); | ||
105 | ev = JournalList.next(); | ||
106 | } | ||
107 | } | ||
69 | } | 108 | } |
70 | |||
71 | bool CalendarLocal::load( const QString &fileName ) | 109 | bool CalendarLocal::load( const QString &fileName ) |
72 | { | 110 | { |
73 | FileStorage storage( this, fileName ); | 111 | FileStorage storage( this, fileName ); |
74 | return storage.load(); | 112 | return storage.load(); |
75 | } | 113 | } |
76 | 114 | ||
77 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) | 115 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) |
78 | { | 116 | { |
79 | FileStorage storage( this, fileName, format ); | 117 | FileStorage storage( this, fileName, format ); |
80 | return storage.save(); | 118 | return storage.save(); |
81 | } | 119 | } |
82 | 120 | ||
83 | void CalendarLocal::close() | 121 | void CalendarLocal::close() |
84 | { | 122 | { |
85 | 123 | ||
86 | Todo * i; | 124 | Todo * i; |
87 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); | 125 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); |
88 | 126 | ||
89 | mEventList.setAutoDelete( true ); | 127 | mEventList.setAutoDelete( true ); |
90 | mTodoList.setAutoDelete( true ); | 128 | mTodoList.setAutoDelete( true ); |
91 | mJournalList.setAutoDelete( false ); | 129 | mJournalList.setAutoDelete( false ); |
92 | 130 | ||
93 | mEventList.clear(); | 131 | mEventList.clear(); |
94 | mTodoList.clear(); | 132 | mTodoList.clear(); |
95 | mJournalList.clear(); | 133 | mJournalList.clear(); |
96 | 134 | ||
97 | mEventList.setAutoDelete( false ); | 135 | mEventList.setAutoDelete( false ); |
98 | mTodoList.setAutoDelete( false ); | 136 | mTodoList.setAutoDelete( false ); |
99 | mJournalList.setAutoDelete( false ); | 137 | mJournalList.setAutoDelete( false ); |
100 | 138 | ||
101 | setModified( false ); | 139 | setModified( false ); |
102 | } | 140 | } |
103 | 141 | ||
104 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) | 142 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) |
105 | { | 143 | { |
106 | QString cat; | 144 | QString cat; |
107 | bool isBirthday = true; | 145 | bool isBirthday = true; |
108 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { | 146 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { |
109 | isBirthday = false; | 147 | isBirthday = false; |
110 | cat = i18n( "Anniversary" ); | 148 | cat = i18n( "Anniversary" ); |
111 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { | 149 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { |
112 | isBirthday = true; | 150 | isBirthday = true; |
113 | cat = i18n( "Birthday" ); | 151 | cat = i18n( "Birthday" ); |
114 | } else { | 152 | } else { |
115 | qDebug("addAnniversaryNoDup called without fitting category! "); | 153 | qDebug("addAnniversaryNoDup called without fitting category! "); |
116 | return false; | 154 | return false; |
117 | } | 155 | } |
118 | Event * eve; | 156 | Event * eve; |
119 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 157 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
120 | if ( !(eve->categories().contains( cat ) )) | 158 | if ( !(eve->categories().contains( cat ) )) |
121 | continue; | 159 | continue; |
122 | // now we have an event with fitting category | 160 | // now we have an event with fitting category |
123 | if ( eve->dtStart().date() != event->dtStart().date() ) | 161 | if ( eve->dtStart().date() != event->dtStart().date() ) |
124 | continue; | 162 | continue; |
125 | // now we have an event with fitting category+date | 163 | // now we have an event with fitting category+date |
126 | if ( eve->summary() != event->summary() ) | 164 | if ( eve->summary() != event->summary() ) |
127 | continue; | 165 | continue; |
128 | // now we have an event with fitting category+date+summary | 166 | // now we have an event with fitting category+date+summary |
129 | return false; | 167 | return false; |
130 | } | 168 | } |
131 | return addEvent( event ); | 169 | return addEvent( event ); |
132 | 170 | ||
133 | } | 171 | } |
134 | bool CalendarLocal::addEventNoDup( Event *event ) | 172 | bool CalendarLocal::addEventNoDup( Event *event ) |
135 | { | 173 | { |
136 | Event * eve; | 174 | Event * eve; |
137 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 175 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
138 | if ( *eve == *event ) { | 176 | if ( *eve == *event ) { |
139 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); | 177 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); |
140 | return false; | 178 | return false; |
141 | } | 179 | } |
142 | } | 180 | } |
143 | return addEvent( event ); | 181 | return addEvent( event ); |
144 | } | 182 | } |
145 | 183 | ||
146 | bool CalendarLocal::addEvent( Event *event ) | 184 | bool CalendarLocal::addEvent( Event *event ) |
147 | { | 185 | { |
148 | insertEvent( event ); | 186 | insertEvent( event ); |
149 | 187 | ||
150 | event->registerObserver( this ); | 188 | event->registerObserver( this ); |
151 | 189 | ||
152 | setModified( true ); | 190 | setModified( true ); |
153 | event->setCalID( mDefaultCalendar ); | 191 | event->setCalID( mDefaultCalendar ); |
154 | event->setCalEnabled( true ); | 192 | event->setCalEnabled( true ); |
155 | 193 | ||
156 | return true; | 194 | return true; |
157 | } | 195 | } |
158 | 196 | ||
159 | void CalendarLocal::deleteEvent( Event *event ) | 197 | void CalendarLocal::deleteEvent( Event *event ) |
160 | { | 198 | { |
161 | if ( mUndoIncidence ) delete mUndoIncidence; | 199 | if ( mUndoIncidence ) delete mUndoIncidence; |
162 | mUndoIncidence = event->clone(); | 200 | mUndoIncidence = event->clone(); |
163 | if ( mEventList.removeRef( event ) ) { | 201 | if ( mEventList.removeRef( event ) ) { |
164 | setModified( true ); | 202 | setModified( true ); |
165 | } | 203 | } |
166 | } | 204 | } |
167 | 205 | ||
168 | 206 | ||
169 | Event *CalendarLocal::event( const QString &uid ) | 207 | Event *CalendarLocal::event( const QString &uid ) |
170 | { | 208 | { |
171 | 209 | ||
172 | Event *event; | 210 | Event *event; |
173 | 211 | ||
174 | for ( event = mEventList.first(); event; event = mEventList.next() ) { | 212 | for ( event = mEventList.first(); event; event = mEventList.next() ) { |
175 | if ( event->uid() == uid && event->calEnabled() ) { | 213 | if ( event->uid() == uid && event->calEnabled() ) { |
176 | return event; | 214 | return event; |
177 | } | 215 | } |
178 | } | 216 | } |
179 | 217 | ||
180 | return 0; | 218 | return 0; |
181 | } | 219 | } |
182 | bool CalendarLocal::addTodoNoDup( Todo *todo ) | 220 | bool CalendarLocal::addTodoNoDup( Todo *todo ) |
183 | { | 221 | { |
184 | Todo * eve; | 222 | Todo * eve; |
185 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { | 223 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { |
186 | if ( *eve == *todo ) { | 224 | if ( *eve == *todo ) { |
187 | //qDebug("duplicate todo found! not inserted! "); | 225 | //qDebug("duplicate todo found! not inserted! "); |
188 | return false; | 226 | return false; |
189 | } | 227 | } |
190 | } | 228 | } |
191 | return addTodo( todo ); | 229 | return addTodo( todo ); |
192 | } | 230 | } |
193 | bool CalendarLocal::addTodo( Todo *todo ) | 231 | bool CalendarLocal::addTodo( Todo *todo ) |
194 | { | 232 | { |
195 | mTodoList.append( todo ); | 233 | mTodoList.append( todo ); |
196 | 234 | ||
197 | todo->registerObserver( this ); | 235 | todo->registerObserver( this ); |
198 | 236 | ||
199 | // Set up subtask relations | 237 | // Set up subtask relations |
200 | setupRelations( todo ); | 238 | setupRelations( todo ); |
201 | 239 | ||
202 | setModified( true ); | 240 | setModified( true ); |
203 | todo->setCalID( mDefaultCalendar ); | 241 | todo->setCalID( mDefaultCalendar ); |
204 | todo->setCalEnabled( true ); | 242 | todo->setCalEnabled( true ); |
205 | return true; | 243 | return true; |
206 | } | 244 | } |
207 | 245 | ||
208 | void CalendarLocal::deleteTodo( Todo *todo ) | 246 | void CalendarLocal::deleteTodo( Todo *todo ) |
209 | { | 247 | { |
210 | // Handle orphaned children | 248 | // Handle orphaned children |
211 | if ( mUndoIncidence ) delete mUndoIncidence; | 249 | if ( mUndoIncidence ) delete mUndoIncidence; |
212 | removeRelations( todo ); | 250 | removeRelations( todo ); |
213 | mUndoIncidence = todo->clone(); | 251 | mUndoIncidence = todo->clone(); |
214 | 252 | ||
215 | if ( mTodoList.removeRef( todo ) ) { | 253 | if ( mTodoList.removeRef( todo ) ) { |
216 | setModified( true ); | 254 | setModified( true ); |
217 | } | 255 | } |
218 | } | 256 | } |
219 | 257 | ||
220 | QPtrList<Todo> CalendarLocal::rawTodos() | 258 | QPtrList<Todo> CalendarLocal::rawTodos() |
221 | { | 259 | { |
222 | QPtrList<Todo> el; | 260 | QPtrList<Todo> el; |
223 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 261 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
224 | if ( it->calEnabled() ) el.append( it ); | 262 | if ( it->calEnabled() ) el.append( it ); |
225 | return el; | 263 | return el; |
226 | } | 264 | } |
227 | Todo *CalendarLocal::todo( QString syncProf, QString id ) | 265 | Todo *CalendarLocal::todo( QString syncProf, QString id ) |
228 | { | 266 | { |
229 | Todo *todo; | 267 | Todo *todo; |
230 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 268 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
231 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; | 269 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; |
232 | } | 270 | } |
233 | 271 | ||
234 | return 0; | 272 | return 0; |
235 | } | 273 | } |
236 | void CalendarLocal::removeSyncInfo( QString syncProfile) | 274 | void CalendarLocal::removeSyncInfo( QString syncProfile) |
237 | { | 275 | { |
238 | QPtrList<Incidence> all = rawIncidences() ; | 276 | QPtrList<Incidence> all = rawIncidences() ; |
239 | Incidence *inc; | 277 | Incidence *inc; |
240 | for ( inc = all.first(); inc; inc = all.next() ) { | 278 | for ( inc = all.first(); inc; inc = all.next() ) { |
241 | inc->removeID( syncProfile ); | 279 | inc->removeID( syncProfile ); |
242 | } | 280 | } |
243 | if ( syncProfile.isEmpty() ) { | 281 | if ( syncProfile.isEmpty() ) { |
244 | QPtrList<Event> el; | 282 | QPtrList<Event> el; |
245 | Event *todo; | 283 | Event *todo; |
246 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 284 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
247 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 285 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
248 | el.append( todo ); | 286 | el.append( todo ); |
249 | } | 287 | } |
250 | for ( todo = el.first(); todo; todo = el.next() ) { | 288 | for ( todo = el.first(); todo; todo = el.next() ) { |
251 | deleteIncidence ( todo ); | 289 | deleteIncidence ( todo ); |
252 | } | 290 | } |
253 | } else { | 291 | } else { |
254 | Event *lse = event( "last-syncEvent-"+ syncProfile); | 292 | Event *lse = event( "last-syncEvent-"+ syncProfile); |
255 | if ( lse ) | 293 | if ( lse ) |
256 | deleteIncidence ( lse ); | 294 | deleteIncidence ( lse ); |
257 | } | 295 | } |
258 | } | 296 | } |
259 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() | 297 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() |
260 | { | 298 | { |
261 | QPtrList<Event> el; | 299 | QPtrList<Event> el; |
262 | Event *todo; | 300 | Event *todo; |
263 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 301 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
264 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 302 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
265 | if ( todo->summary().left(3) == "E: " ) | 303 | if ( todo->summary().left(3) == "E: " ) |
266 | el.append( todo ); | 304 | el.append( todo ); |
267 | } | 305 | } |
268 | 306 | ||
269 | return el; | 307 | return el; |
270 | 308 | ||
271 | } | 309 | } |
272 | Event *CalendarLocal::event( QString syncProf, QString id ) | 310 | Event *CalendarLocal::event( QString syncProf, QString id ) |
273 | { | 311 | { |
274 | Event *todo; | 312 | Event *todo; |
275 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 313 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
276 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; | 314 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; |
277 | } | 315 | } |
278 | 316 | ||
279 | return 0; | 317 | return 0; |
280 | } | 318 | } |
281 | Todo *CalendarLocal::todo( const QString &uid ) | 319 | Todo *CalendarLocal::todo( const QString &uid ) |
282 | { | 320 | { |
283 | Todo *todo; | 321 | Todo *todo; |
284 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 322 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
285 | if ( todo->calEnabled() && todo->uid() == uid ) return todo; | 323 | if ( todo->calEnabled() && todo->uid() == uid ) return todo; |
286 | } | 324 | } |
287 | 325 | ||
288 | return 0; | 326 | return 0; |
289 | } | 327 | } |
290 | QString CalendarLocal::nextSummary() const | 328 | QString CalendarLocal::nextSummary() const |
291 | { | 329 | { |
292 | return mNextSummary; | 330 | return mNextSummary; |
293 | } | 331 | } |
294 | QDateTime CalendarLocal::nextAlarmEventDateTime() const | 332 | QDateTime CalendarLocal::nextAlarmEventDateTime() const |
295 | { | 333 | { |
296 | return mNextAlarmEventDateTime; | 334 | return mNextAlarmEventDateTime; |
297 | } | 335 | } |
298 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) | 336 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) |
299 | { | 337 | { |
300 | //mNextAlarmIncidence | 338 | //mNextAlarmIncidence |
301 | //mNextAlarmDateTime | 339 | //mNextAlarmDateTime |
302 | //return mNextSummary; | 340 | //return mNextSummary; |
303 | //return mNextAlarmEventDateTime; | 341 | //return mNextAlarmEventDateTime; |
304 | bool newNextAlarm = false; | 342 | bool newNextAlarm = false; |
305 | bool computeNextAlarm = false; | 343 | bool computeNextAlarm = false; |
306 | bool ok; | 344 | bool ok; |
307 | int offset; | 345 | int offset; |
308 | QDateTime nextA; | 346 | QDateTime nextA; |
309 | // QString nextSum; | 347 | // QString nextSum; |
310 | //QDateTime nextEvent; | 348 | //QDateTime nextEvent; |
311 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { | 349 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { |
312 | computeNextAlarm = true; | 350 | computeNextAlarm = true; |
313 | } else { | 351 | } else { |
314 | if ( ! deleted ) { | 352 | if ( ! deleted ) { |
315 | nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; | 353 | nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; |
316 | if ( ok ) { | 354 | if ( ok ) { |
317 | if ( nextA < mNextAlarmDateTime ) { | 355 | if ( nextA < mNextAlarmDateTime ) { |
318 | deRegisterAlarm(); | 356 | deRegisterAlarm(); |
319 | mNextAlarmDateTime = nextA; | 357 | mNextAlarmDateTime = nextA; |
320 | mNextSummary = incidence->summary(); | 358 | mNextSummary = incidence->summary(); |
321 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; | 359 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; |
322 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 360 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
323 | newNextAlarm = true; | 361 | newNextAlarm = true; |
324 | mNextAlarmIncidence = incidence; | 362 | mNextAlarmIncidence = incidence; |
325 | } else { | 363 | } else { |
326 | if ( incidence == mNextAlarmIncidence ) { | 364 | if ( incidence == mNextAlarmIncidence ) { |
327 | computeNextAlarm = true; | 365 | computeNextAlarm = true; |
328 | } | 366 | } |
329 | } | 367 | } |
330 | } else { | 368 | } else { |
331 | if ( mNextAlarmIncidence == incidence ) { | 369 | if ( mNextAlarmIncidence == incidence ) { |
332 | computeNextAlarm = true; | 370 | computeNextAlarm = true; |
333 | } | 371 | } |
334 | } | 372 | } |
335 | } else { // deleted | 373 | } else { // deleted |
336 | if ( incidence == mNextAlarmIncidence ) { | 374 | if ( incidence == mNextAlarmIncidence ) { |
337 | computeNextAlarm = true; | 375 | computeNextAlarm = true; |
338 | } | 376 | } |
339 | } | 377 | } |
340 | } | 378 | } |
341 | if ( computeNextAlarm ) { | 379 | if ( computeNextAlarm ) { |
342 | deRegisterAlarm(); | 380 | deRegisterAlarm(); |
343 | nextA = nextAlarm( 1000 ); | 381 | nextA = nextAlarm( 1000 ); |
344 | if (! mNextAlarmIncidence ) { | 382 | if (! mNextAlarmIncidence ) { |
345 | return; | 383 | return; |
346 | } | 384 | } |
347 | newNextAlarm = true; | 385 | newNextAlarm = true; |
348 | } | 386 | } |
349 | if ( newNextAlarm ) | 387 | if ( newNextAlarm ) |
350 | registerAlarm(); | 388 | registerAlarm(); |
351 | } | 389 | } |
352 | QString CalendarLocal:: getAlarmNotification() | 390 | QString CalendarLocal:: getAlarmNotification() |
353 | { | 391 | { |
354 | QString ret; | 392 | QString ret; |
355 | // this should not happen | 393 | // this should not happen |
356 | if (! mNextAlarmIncidence ) | 394 | if (! mNextAlarmIncidence ) |
357 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; | 395 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; |
358 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); | 396 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); |
359 | if ( alarm->type() == Alarm::Procedure ) { | 397 | if ( alarm->type() == Alarm::Procedure ) { |
360 | ret = "proc_alarm" + alarm->programFile()+"+++"; | 398 | ret = "proc_alarm" + alarm->programFile()+"+++"; |
361 | } else { | 399 | } else { |
362 | ret = "audio_alarm" +alarm->audioFile() +"+++"; | 400 | ret = "audio_alarm" +alarm->audioFile() +"+++"; |
363 | } | 401 | } |
364 | ret += "cal_alarm"+ mNextSummary.left( 25 ); | 402 | ret += "cal_alarm"+ mNextSummary.left( 25 ); |
365 | if ( mNextSummary.length() > 25 ) | 403 | if ( mNextSummary.length() > 25 ) |
366 | ret += "\n" + mNextSummary.mid(25, 25 ); | 404 | ret += "\n" + mNextSummary.mid(25, 25 ); |
367 | ret+= "\n"+mNextAlarmEventDateTimeString; | 405 | ret+= "\n"+mNextAlarmEventDateTimeString; |
368 | return ret; | 406 | return ret; |
369 | } | 407 | } |
370 | void CalendarLocal::registerAlarm() | 408 | void CalendarLocal::registerAlarm() |
371 | { | 409 | { |
372 | mLastAlarmNotificationString = getAlarmNotification(); | 410 | mLastAlarmNotificationString = getAlarmNotification(); |
373 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); | 411 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); |
374 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 412 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
375 | // #ifndef DESKTOP_VERSION | 413 | // #ifndef DESKTOP_VERSION |
376 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); | 414 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); |
377 | // #endif | 415 | // #endif |
378 | } | 416 | } |
379 | void CalendarLocal::deRegisterAlarm() | 417 | void CalendarLocal::deRegisterAlarm() |
380 | { | 418 | { |
381 | if ( mLastAlarmNotificationString.isNull() ) | 419 | if ( mLastAlarmNotificationString.isNull() ) |
382 | return; | 420 | return; |
383 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); | 421 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); |
384 | 422 | ||
385 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 423 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
386 | mNextAlarmEventDateTime = QDateTime(); | 424 | mNextAlarmEventDateTime = QDateTime(); |
387 | // #ifndef DESKTOP_VERSION | 425 | // #ifndef DESKTOP_VERSION |
388 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); | 426 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); |
389 | // #endif | 427 | // #endif |
390 | } | 428 | } |
391 | 429 | ||
392 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) | 430 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) |
393 | { | 431 | { |
394 | QPtrList<Todo> todos; | 432 | QPtrList<Todo> todos; |
395 | 433 | ||
396 | Todo *todo; | 434 | Todo *todo; |
397 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 435 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
398 | if ( !todo->calEnabled() ) continue; | 436 | if ( !todo->calEnabled() ) continue; |
399 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { | 437 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { |
400 | todos.append( todo ); | 438 | todos.append( todo ); |
401 | } | 439 | } |
402 | } | 440 | } |
403 | 441 | ||
404 | filter()->apply( &todos ); | 442 | filter()->apply( &todos ); |
405 | return todos; | 443 | return todos; |
406 | } | 444 | } |
407 | void CalendarLocal::reInitAlarmSettings() | 445 | void CalendarLocal::reInitAlarmSettings() |
408 | { | 446 | { |
409 | if ( !mNextAlarmIncidence ) { | 447 | if ( !mNextAlarmIncidence ) { |
410 | nextAlarm( 1000 ); | 448 | nextAlarm( 1000 ); |
411 | } | 449 | } |
412 | deRegisterAlarm(); | 450 | deRegisterAlarm(); |
413 | mNextAlarmIncidence = 0; | 451 | mNextAlarmIncidence = 0; |
414 | checkAlarmForIncidence( 0, false ); | 452 | checkAlarmForIncidence( 0, false ); |
415 | 453 | ||
416 | } | 454 | } |
417 | 455 | ||
418 | 456 | ||
419 | 457 | ||
420 | QDateTime CalendarLocal::nextAlarm( int daysTo ) | 458 | QDateTime CalendarLocal::nextAlarm( int daysTo ) |
421 | { | 459 | { |
422 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); | 460 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); |
423 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); | 461 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); |
424 | QDateTime next; | 462 | QDateTime next; |
425 | Event *e; | 463 | Event *e; |
426 | bool ok; | 464 | bool ok; |
427 | bool found = false; | 465 | bool found = false; |
428 | int offset; | 466 | int offset; |
429 | mNextAlarmIncidence = 0; | 467 | mNextAlarmIncidence = 0; |
430 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 468 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
431 | if ( !e->calEnabled() ) continue; | 469 | if ( !e->calEnabled() ) continue; |
432 | next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; | 470 | next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; |
433 | if ( ok ) { | 471 | if ( ok ) { |
434 | if ( next < nextA ) { | 472 | if ( next < nextA ) { |
435 | nextA = next; | 473 | nextA = next; |
436 | found = true; | 474 | found = true; |
437 | mNextSummary = e->summary(); | 475 | mNextSummary = e->summary(); |
438 | mNextAlarmEventDateTime = next.addSecs(offset ) ; | 476 | mNextAlarmEventDateTime = next.addSecs(offset ) ; |
439 | mNextAlarmIncidence = (Incidence *) e; | 477 | mNextAlarmIncidence = (Incidence *) e; |
440 | } | 478 | } |
441 | } | 479 | } |
442 | } | 480 | } |
443 | Todo *t; | 481 | Todo *t; |
444 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 482 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
445 | if ( !t->calEnabled() ) continue; | 483 | if ( !t->calEnabled() ) continue; |
446 | next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; | 484 | next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; |
447 | if ( ok ) { | 485 | if ( ok ) { |
448 | if ( next < nextA ) { | 486 | if ( next < nextA ) { |
449 | nextA = next; | 487 | nextA = next; |
450 | found = true; | 488 | found = true; |
451 | mNextSummary = t->summary(); | 489 | mNextSummary = t->summary(); |
452 | mNextAlarmEventDateTime = next.addSecs(offset ); | 490 | mNextAlarmEventDateTime = next.addSecs(offset ); |
453 | mNextAlarmIncidence = (Incidence *) t; | 491 | mNextAlarmIncidence = (Incidence *) t; |
454 | } | 492 | } |
455 | } | 493 | } |
456 | } | 494 | } |
457 | if ( mNextAlarmIncidence ) { | 495 | if ( mNextAlarmIncidence ) { |
458 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 496 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
459 | mNextAlarmDateTime = nextA; | 497 | mNextAlarmDateTime = nextA; |
460 | } | 498 | } |
461 | return nextA; | 499 | return nextA; |
462 | } | 500 | } |
463 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) | 501 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) |
464 | { | 502 | { |
465 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); | 503 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); |
466 | } | 504 | } |
467 | 505 | ||
468 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) | 506 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) |
469 | { | 507 | { |
470 | 508 | ||
471 | Alarm::List alarms; | 509 | Alarm::List alarms; |
472 | 510 | ||
473 | Event *e; | 511 | Event *e; |
474 | 512 | ||
475 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 513 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
476 | if ( !e->calEnabled() ) continue; | 514 | if ( !e->calEnabled() ) continue; |
477 | if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); | 515 | if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); |
478 | else appendAlarms( alarms, e, from, to ); | 516 | else appendAlarms( alarms, e, from, to ); |
479 | } | 517 | } |
480 | 518 | ||
481 | Todo *t; | 519 | Todo *t; |
482 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 520 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
483 | if ( !t->calEnabled() ) continue; | 521 | if ( !t->calEnabled() ) continue; |
484 | appendAlarms( alarms, t, from, to ); | 522 | appendAlarms( alarms, t, from, to ); |
485 | } | 523 | } |
486 | 524 | ||
487 | return alarms; | 525 | return alarms; |
488 | } | 526 | } |
489 | 527 | ||
490 | void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, | 528 | void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, |
491 | const QDateTime &from, const QDateTime &to ) | 529 | const QDateTime &from, const QDateTime &to ) |
492 | { | 530 | { |
493 | QPtrList<Alarm> alarmList = incidence->alarms(); | 531 | QPtrList<Alarm> alarmList = incidence->alarms(); |
494 | Alarm *alarm; | 532 | Alarm *alarm; |
495 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { | 533 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { |
496 | // kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() | 534 | // kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() |
497 | // << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; | 535 | // << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; |
498 | if ( alarm->enabled() ) { | 536 | if ( alarm->enabled() ) { |
499 | if ( alarm->time() >= from && alarm->time() <= to ) { | 537 | if ( alarm->time() >= from && alarm->time() <= to ) { |
500 | alarms.append( alarm ); | 538 | alarms.append( alarm ); |
501 | } | 539 | } |
502 | } | 540 | } |
503 | } | 541 | } |
504 | } | 542 | } |
505 | 543 | ||
506 | void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, | 544 | void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, |
507 | Incidence *incidence, | 545 | Incidence *incidence, |
508 | const QDateTime &from, | 546 | const QDateTime &from, |
509 | const QDateTime &to ) | 547 | const QDateTime &to ) |
510 | { | 548 | { |
511 | 549 | ||
512 | QPtrList<Alarm> alarmList = incidence->alarms(); | 550 | QPtrList<Alarm> alarmList = incidence->alarms(); |
513 | Alarm *alarm; | 551 | Alarm *alarm; |
514 | QDateTime qdt; | 552 | QDateTime qdt; |
515 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { | 553 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { |
516 | if (incidence->recursOn(from.date())) { | 554 | if (incidence->recursOn(from.date())) { |
517 | qdt.setTime(alarm->time().time()); | 555 | qdt.setTime(alarm->time().time()); |
518 | qdt.setDate(from.date()); | 556 | qdt.setDate(from.date()); |
519 | } | 557 | } |
520 | else qdt = alarm->time(); | 558 | else qdt = alarm->time(); |
521 | // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); | 559 | // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); |
522 | if ( alarm->enabled() ) { | 560 | if ( alarm->enabled() ) { |
523 | if ( qdt >= from && qdt <= to ) { | 561 | if ( qdt >= from && qdt <= to ) { |
524 | alarms.append( alarm ); | 562 | alarms.append( alarm ); |
525 | } | 563 | } |
526 | } | 564 | } |
527 | } | 565 | } |
528 | } | 566 | } |
529 | 567 | ||
530 | 568 | ||
531 | /****************************** PROTECTED METHODS ****************************/ | 569 | /****************************** PROTECTED METHODS ****************************/ |
532 | 570 | ||
533 | // after changes are made to an event, this should be called. | 571 | // after changes are made to an event, this should be called. |
534 | void CalendarLocal::update( IncidenceBase *incidence ) | 572 | void CalendarLocal::update( IncidenceBase *incidence ) |
535 | { | 573 | { |
536 | incidence->setSyncStatus( Event::SYNCMOD ); | 574 | incidence->setSyncStatus( Event::SYNCMOD ); |
537 | incidence->setLastModified( QDateTime::currentDateTime() ); | 575 | incidence->setLastModified( QDateTime::currentDateTime() ); |
538 | // we should probably update the revision number here, | 576 | // we should probably update the revision number here, |
539 | // or internally in the Event itself when certain things change. | 577 | // or internally in the Event itself when certain things change. |
540 | // need to verify with ical documentation. | 578 | // need to verify with ical documentation. |
541 | 579 | ||
542 | setModified( true ); | 580 | setModified( true ); |
543 | } | 581 | } |
544 | 582 | ||
545 | void CalendarLocal::insertEvent( Event *event ) | 583 | void CalendarLocal::insertEvent( Event *event ) |
546 | { | 584 | { |
547 | if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); | 585 | if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); |
548 | } | 586 | } |
549 | 587 | ||
550 | 588 | ||
551 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) | 589 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) |
552 | { | 590 | { |
553 | QPtrList<Event> eventList; | 591 | QPtrList<Event> eventList; |
554 | 592 | ||
555 | Event *event; | 593 | Event *event; |
556 | for( event = mEventList.first(); event; event = mEventList.next() ) { | 594 | for( event = mEventList.first(); event; event = mEventList.next() ) { |
557 | if ( !event->calEnabled() ) continue; | 595 | if ( !event->calEnabled() ) continue; |
558 | if ( event->doesRecur() ) { | 596 | if ( event->doesRecur() ) { |
559 | if ( event->isMultiDay() ) { | 597 | if ( event->isMultiDay() ) { |
560 | int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); | 598 | int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); |
561 | int i; | 599 | int i; |
562 | for ( i = 0; i <= extraDays; i++ ) { | 600 | for ( i = 0; i <= extraDays; i++ ) { |
563 | if ( event->recursOn( qd.addDays( -i ) ) ) { | 601 | if ( event->recursOn( qd.addDays( -i ) ) ) { |
564 | eventList.append( event ); | 602 | eventList.append( event ); |
565 | break; | 603 | break; |
566 | } | 604 | } |
567 | } | 605 | } |
568 | } else { | 606 | } else { |
569 | if ( event->recursOn( qd ) ) | 607 | if ( event->recursOn( qd ) ) |
570 | eventList.append( event ); | 608 | eventList.append( event ); |
571 | } | 609 | } |
572 | } else { | 610 | } else { |
573 | if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { | 611 | if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { |
574 | eventList.append( event ); | 612 | eventList.append( event ); |
575 | } | 613 | } |
576 | } | 614 | } |
577 | } | 615 | } |
578 | 616 | ||
579 | if ( !sorted ) { | 617 | if ( !sorted ) { |
580 | return eventList; | 618 | return eventList; |
581 | } | 619 | } |
582 | 620 | ||
583 | // kdDebug(5800) << "Sorting events for date\n" << endl; | 621 | // kdDebug(5800) << "Sorting events for date\n" << endl; |
584 | // now, we have to sort it based on dtStart.time() | 622 | // now, we have to sort it based on dtStart.time() |
585 | QPtrList<Event> eventListSorted; | 623 | QPtrList<Event> eventListSorted; |
586 | Event *sortEvent; | 624 | Event *sortEvent; |
587 | for ( event = eventList.first(); event; event = eventList.next() ) { | 625 | for ( event = eventList.first(); event; event = eventList.next() ) { |
588 | sortEvent = eventListSorted.first(); | 626 | sortEvent = eventListSorted.first(); |
589 | int i = 0; | 627 | int i = 0; |
590 | while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) | 628 | while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) |
591 | { | 629 | { |
592 | i++; | 630 | i++; |
593 | sortEvent = eventListSorted.next(); | 631 | sortEvent = eventListSorted.next(); |
594 | } | 632 | } |
595 | eventListSorted.insert( i, event ); | 633 | eventListSorted.insert( i, event ); |
596 | } | 634 | } |
597 | return eventListSorted; | 635 | return eventListSorted; |
598 | } | 636 | } |
599 | 637 | ||
600 | 638 | ||
601 | QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, | 639 | QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, |
602 | bool inclusive ) | 640 | bool inclusive ) |
603 | { | 641 | { |
604 | Event *event = 0; | 642 | Event *event = 0; |
605 | 643 | ||
606 | QPtrList<Event> eventList; | 644 | QPtrList<Event> eventList; |
607 | 645 | ||
608 | // Get non-recurring events | 646 | // Get non-recurring events |
609 | for( event = mEventList.first(); event; event = mEventList.next() ) { | 647 | for( event = mEventList.first(); event; event = mEventList.next() ) { |
610 | if ( !event->calEnabled() ) continue; | 648 | if ( !event->calEnabled() ) continue; |
611 | if ( event->doesRecur() ) { | 649 | if ( event->doesRecur() ) { |
612 | QDate rStart = event->dtStart().date(); | 650 | QDate rStart = event->dtStart().date(); |
613 | bool found = false; | 651 | bool found = false; |
614 | if ( inclusive ) { | 652 | if ( inclusive ) { |
615 | if ( rStart >= start && rStart <= end ) { | 653 | if ( rStart >= start && rStart <= end ) { |
616 | // Start date of event is in range. Now check for end date. | 654 | // Start date of event is in range. Now check for end date. |
617 | // if duration is negative, event recurs forever, so do not include it. | 655 | // if duration is negative, event recurs forever, so do not include it. |
618 | if ( event->recurrence()->duration() == 0 ) { // End date set | 656 | if ( event->recurrence()->duration() == 0 ) { // End date set |
619 | QDate rEnd = event->recurrence()->endDate(); | 657 | QDate rEnd = event->recurrence()->endDate(); |
620 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 658 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
621 | found = true; | 659 | found = true; |
622 | } | 660 | } |
623 | } else if ( event->recurrence()->duration() > 0 ) { // Duration set | 661 | } else if ( event->recurrence()->duration() > 0 ) { // Duration set |
624 | // TODO: Calculate end date from duration. Should be done in Event | 662 | // TODO: Calculate end date from duration. Should be done in Event |
625 | // For now exclude all events with a duration. | 663 | // For now exclude all events with a duration. |
626 | } | 664 | } |
627 | } | 665 | } |
628 | } else { | 666 | } else { |
629 | bool founOne; | 667 | bool founOne; |
630 | QDate next = event->getNextOccurence( start, &founOne ).date(); | 668 | QDate next = event->getNextOccurence( start, &founOne ).date(); |
631 | if ( founOne ) { | 669 | if ( founOne ) { |
632 | if ( next <= end ) { | 670 | if ( next <= end ) { |
633 | found = true; | 671 | found = true; |
634 | } | 672 | } |
635 | } | 673 | } |
636 | 674 | ||
637 | /* | 675 | /* |
638 | // crap !!! | 676 | // crap !!! |
639 | if ( rStart <= end ) { // Start date not after range | 677 | if ( rStart <= end ) { // Start date not after range |
640 | if ( rStart >= start ) { // Start date within range | 678 | if ( rStart >= start ) { // Start date within range |
641 | found = true; | 679 | found = true; |
642 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever | 680 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever |
643 | found = true; | 681 | found = true; |
644 | } else if ( event->recurrence()->duration() == 0 ) { // End date set | 682 | } else if ( event->recurrence()->duration() == 0 ) { // End date set |
645 | QDate rEnd = event->recurrence()->endDate(); | 683 | QDate rEnd = event->recurrence()->endDate(); |
646 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 684 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
647 | found = true; | 685 | found = true; |
648 | } | 686 | } |
649 | } else { // Duration set | 687 | } else { // Duration set |
650 | // TODO: Calculate end date from duration. Should be done in Event | 688 | // TODO: Calculate end date from duration. Should be done in Event |
651 | // For now include all events with a duration. | 689 | // For now include all events with a duration. |
652 | found = true; | 690 | found = true; |
653 | } | 691 | } |
654 | } | 692 | } |
655 | */ | 693 | */ |
656 | 694 | ||
657 | } | 695 | } |
658 | 696 | ||
659 | if ( found ) eventList.append( event ); | 697 | if ( found ) eventList.append( event ); |
660 | } else { | 698 | } else { |
661 | QDate s = event->dtStart().date(); | 699 | QDate s = event->dtStart().date(); |
662 | QDate e = event->dtEnd().date(); | 700 | QDate e = event->dtEnd().date(); |
663 | 701 | ||
664 | if ( inclusive ) { | 702 | if ( inclusive ) { |
665 | if ( s >= start && e <= end ) { | 703 | if ( s >= start && e <= end ) { |
666 | eventList.append( event ); | 704 | eventList.append( event ); |
667 | } | 705 | } |
668 | } else { | 706 | } else { |
669 | if ( ( s >= start && s <= end ) || ( e >= start && e <= end ) ) { | 707 | if ( ( s >= start && s <= end ) || ( e >= start && e <= end ) ) { |
670 | eventList.append( event ); | 708 | eventList.append( event ); |
671 | } | 709 | } |
672 | } | 710 | } |
673 | } | 711 | } |
674 | } | 712 | } |
675 | 713 | ||
676 | return eventList; | 714 | return eventList; |
677 | } | 715 | } |
678 | 716 | ||
679 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) | 717 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) |
680 | { | 718 | { |
681 | return rawEventsForDate( qdt.date() ); | 719 | return rawEventsForDate( qdt.date() ); |
682 | } | 720 | } |
683 | 721 | ||
684 | QPtrList<Event> CalendarLocal::rawEvents() | 722 | QPtrList<Event> CalendarLocal::rawEvents() |
685 | { | 723 | { |
686 | QPtrList<Event> el; | 724 | QPtrList<Event> el; |
687 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 725 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
688 | if ( it->calEnabled() ) el.append( it ); | 726 | if ( it->calEnabled() ) el.append( it ); |
689 | return el; | 727 | return el; |
690 | } | 728 | } |
691 | 729 | ||
692 | bool CalendarLocal::addJournal(Journal *journal) | 730 | bool CalendarLocal::addJournal(Journal *journal) |
693 | { | 731 | { |
694 | if ( journal->dtStart().isValid()) | 732 | if ( journal->dtStart().isValid()) |
695 | kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl; | 733 | kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl; |
696 | else | 734 | else |
697 | kdDebug(5800) << "Adding Journal without a DTSTART" << endl; | 735 | kdDebug(5800) << "Adding Journal without a DTSTART" << endl; |
698 | 736 | ||
699 | mJournalList.append(journal); | 737 | mJournalList.append(journal); |
700 | 738 | ||
701 | journal->registerObserver( this ); | 739 | journal->registerObserver( this ); |
702 | 740 | ||
703 | setModified( true ); | 741 | setModified( true ); |
704 | journal->setCalID( mDefaultCalendar ); | 742 | journal->setCalID( mDefaultCalendar ); |
705 | journal->setCalEnabled( true ); | 743 | journal->setCalEnabled( true ); |
706 | return true; | 744 | return true; |
707 | } | 745 | } |
708 | 746 | ||
709 | void CalendarLocal::deleteJournal( Journal *journal ) | 747 | void CalendarLocal::deleteJournal( Journal *journal ) |
710 | { | 748 | { |
711 | if ( mUndoIncidence ) delete mUndoIncidence; | 749 | if ( mUndoIncidence ) delete mUndoIncidence; |
712 | mUndoIncidence = journal->clone(); | 750 | mUndoIncidence = journal->clone(); |
713 | mUndoIncidence->setSummary( mUndoIncidence->description().left(25)); | 751 | mUndoIncidence->setSummary( mUndoIncidence->description().left(25)); |
714 | if ( mJournalList.removeRef(journal) ) { | 752 | if ( mJournalList.removeRef(journal) ) { |
715 | setModified( true ); | 753 | setModified( true ); |
716 | } | 754 | } |
717 | } | 755 | } |
718 | 756 | ||
719 | Journal *CalendarLocal::journal( const QDate &date ) | 757 | Journal *CalendarLocal::journal( const QDate &date ) |
720 | { | 758 | { |
721 | // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; | 759 | // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; |
722 | 760 | ||
723 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 761 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
724 | if ( it->calEnabled() && it->dtStart().date() == date ) | 762 | if ( it->calEnabled() && it->dtStart().date() == date ) |
725 | return it; | 763 | return it; |
726 | 764 | ||
727 | return 0; | 765 | return 0; |
728 | } | 766 | } |
729 | 767 | ||
730 | Journal *CalendarLocal::journal( const QString &uid ) | 768 | Journal *CalendarLocal::journal( const QString &uid ) |
731 | { | 769 | { |
732 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 770 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
733 | if ( it->calEnabled() && it->uid() == uid ) | 771 | if ( it->calEnabled() && it->uid() == uid ) |
734 | return it; | 772 | return it; |
735 | 773 | ||
736 | return 0; | 774 | return 0; |
737 | } | 775 | } |
738 | 776 | ||
739 | QPtrList<Journal> CalendarLocal::journals() | 777 | QPtrList<Journal> CalendarLocal::journals() |
740 | { | 778 | { |
741 | QPtrList<Journal> el; | 779 | QPtrList<Journal> el; |
742 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 780 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
743 | if ( it->calEnabled() ) el.append( it ); | 781 | if ( it->calEnabled() ) el.append( it ); |
744 | return el; | 782 | return el; |
745 | } | 783 | } |
746 | 784 | ||
747 | void CalendarLocal::setCalendarEnabled( int id, bool enable ) | 785 | void CalendarLocal::setCalendarEnabled( int id, bool enable ) |
748 | { | 786 | { |
749 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 787 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
750 | if ( it->calID() == id ) it->setCalEnabled( enable ); | 788 | if ( it->calID() == id ) it->setCalEnabled( enable ); |
751 | 789 | ||
752 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 790 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
753 | if ( it->calID() == id ) it->setCalEnabled( enable ); | 791 | if ( it->calID() == id ) it->setCalEnabled( enable ); |
754 | 792 | ||
755 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 793 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
756 | if ( it->calID() == id ) it->setCalEnabled( enable ); | 794 | if ( it->calID() == id ) it->setCalEnabled( enable ); |
757 | 795 | ||
758 | } | 796 | } |
797 | |||
798 | void CalendarLocal::setReadOnly( int id, bool enable ) | ||
799 | { | ||
800 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | ||
801 | if ( it->calID() == id ) it->setReadOnly( enable ); | ||
802 | |||
803 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | ||
804 | if ( it->calID() == id ) it->setReadOnly( enable ); | ||
805 | |||
806 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | ||
807 | if ( it->calID() == id ) it->setReadOnly( enable ); | ||
808 | |||
809 | } | ||
810 | |||
759 | void CalendarLocal::setAlarmEnabled( int id, bool enable ) | 811 | void CalendarLocal::setAlarmEnabled( int id, bool enable ) |
760 | { | 812 | { |
761 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 813 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
762 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); | 814 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); |
763 | 815 | ||
764 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 816 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
765 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); | 817 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); |
766 | 818 | ||
767 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 819 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
768 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); | 820 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); |
769 | 821 | ||
770 | } | 822 | } |
771 | void CalendarLocal::setDefaultCalendarEnabledOnly() | 823 | void CalendarLocal::setDefaultCalendarEnabledOnly() |
772 | { | 824 | { |
773 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 825 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
774 | it->setCalEnabled( it->calID() == mDefaultCalendar ); | 826 | it->setCalEnabled( it->calID() == mDefaultCalendar ); |
775 | 827 | ||
776 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 828 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
777 | it->setCalEnabled( it->calID() == mDefaultCalendar); | 829 | it->setCalEnabled( it->calID() == mDefaultCalendar); |
778 | 830 | ||
779 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 831 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
780 | it->setCalEnabled( it->calID() == mDefaultCalendar); | 832 | it->setCalEnabled( it->calID() == mDefaultCalendar); |
781 | 833 | ||
782 | } | 834 | } |
diff --git a/libkcal/calendarlocal.h b/libkcal/calendarlocal.h index b25fcbe..65f6aa7 100644 --- a/libkcal/calendarlocal.h +++ b/libkcal/calendarlocal.h | |||
@@ -1,221 +1,223 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | 3 | ||
4 | Copyright (c) 1998 Preston Brown | 4 | Copyright (c) 1998 Preston Brown |
5 | Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> | 5 | Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> |
6 | 6 | ||
7 | This library is free software; you can redistribute it and/or | 7 | This library is free software; you can redistribute it and/or |
8 | modify it under the terms of the GNU Library General Public | 8 | modify it under the terms of the GNU Library General Public |
9 | License as published by the Free Software Foundation; either | 9 | License as published by the Free Software Foundation; either |
10 | version 2 of the License, or (at your option) any later version. | 10 | version 2 of the License, or (at your option) any later version. |
11 | 11 | ||
12 | This library is distributed in the hope that it will be useful, | 12 | This library is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | Library General Public License for more details. | 15 | Library General Public License for more details. |
16 | 16 | ||
17 | You should have received a copy of the GNU Library General Public License | 17 | You should have received a copy of the GNU Library General Public License |
18 | along with this library; see the file COPYING.LIB. If not, write to | 18 | along with this library; see the file COPYING.LIB. If not, write to |
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. | 20 | Boston, MA 02111-1307, USA. |
21 | */ | 21 | */ |
22 | #ifndef KCAL_CALENDARLOCAL_H | 22 | #ifndef KCAL_CALENDARLOCAL_H |
23 | #define KCAL_CALENDARLOCAL_H | 23 | #define KCAL_CALENDARLOCAL_H |
24 | 24 | ||
25 | #include "calendar.h" | 25 | #include "calendar.h" |
26 | 26 | ||
27 | namespace KCal { | 27 | namespace KCal { |
28 | 28 | ||
29 | class CalFormat; | 29 | class CalFormat; |
30 | 30 | ||
31 | /** | 31 | /** |
32 | This class provides a calendar stored as a local file. | 32 | This class provides a calendar stored as a local file. |
33 | */ | 33 | */ |
34 | class CalendarLocal : public Calendar | 34 | class CalendarLocal : public Calendar |
35 | { | 35 | { |
36 | public: | 36 | public: |
37 | /** | 37 | /** |
38 | Constructs a new calendar, with variables initialized to sane values. | 38 | Constructs a new calendar, with variables initialized to sane values. |
39 | */ | 39 | */ |
40 | CalendarLocal(); | 40 | CalendarLocal(); |
41 | /** | 41 | /** |
42 | Constructs a new calendar, with variables initialized to sane values. | 42 | Constructs a new calendar, with variables initialized to sane values. |
43 | */ | 43 | */ |
44 | CalendarLocal( const QString &timeZoneId ); | 44 | CalendarLocal( const QString &timeZoneId ); |
45 | ~CalendarLocal(); | 45 | ~CalendarLocal(); |
46 | 46 | void addCalendar( Calendar* ); | |
47 | bool addCalendarFile( QString name, int id ); | ||
47 | /** | 48 | /** |
48 | Loads a calendar on disk in vCalendar or iCalendar format into the current | 49 | Loads a calendar on disk in vCalendar or iCalendar format into the current |
49 | calendar. Any information already present is lost. | 50 | calendar. Any information already present is lost. |
50 | @return true, if successfull, false on error. | 51 | @return true, if successfull, false on error. |
51 | @param fileName the name of the calendar on disk. | 52 | @param fileName the name of the calendar on disk. |
52 | */ | 53 | */ |
53 | bool load( const QString &fileName ); | 54 | bool load( const QString &fileName ); |
54 | /** | 55 | /** |
55 | Writes out the calendar to disk in the specified \a format. | 56 | Writes out the calendar to disk in the specified \a format. |
56 | CalendarLocal takes ownership of the CalFormat object. | 57 | CalendarLocal takes ownership of the CalFormat object. |
57 | @return true, if successfull, false on error. | 58 | @return true, if successfull, false on error. |
58 | @param fileName the name of the file | 59 | @param fileName the name of the file |
59 | */ | 60 | */ |
60 | bool save( const QString &fileName, CalFormat *format = 0 ); | 61 | bool save( const QString &fileName, CalFormat *format = 0 ); |
61 | 62 | ||
62 | /** | 63 | /** |
63 | Clears out the current calendar, freeing all used memory etc. etc. | 64 | Clears out the current calendar, freeing all used memory etc. etc. |
64 | */ | 65 | */ |
65 | void close(); | 66 | void close(); |
66 | 67 | ||
67 | void save() {} | 68 | void save() {} |
68 | 69 | ||
69 | /** | 70 | /** |
70 | Add Event to calendar. | 71 | Add Event to calendar. |
71 | */ | 72 | */ |
72 | void removeSyncInfo( QString syncProfile); | 73 | void removeSyncInfo( QString syncProfile); |
73 | bool addAnniversaryNoDup( Event *event ); | 74 | bool addAnniversaryNoDup( Event *event ); |
74 | bool addEventNoDup( Event *event ); | 75 | bool addEventNoDup( Event *event ); |
75 | bool addEvent( Event *event ); | 76 | bool addEvent( Event *event ); |
76 | /** | 77 | /** |
77 | Deletes an event from this calendar. | 78 | Deletes an event from this calendar. |
78 | */ | 79 | */ |
79 | void deleteEvent( Event *event ); | 80 | void deleteEvent( Event *event ); |
80 | 81 | ||
81 | /** | 82 | /** |
82 | Retrieves an event on the basis of the unique string ID. | 83 | Retrieves an event on the basis of the unique string ID. |
83 | */ | 84 | */ |
84 | Event *event( const QString &uid ); | 85 | Event *event( const QString &uid ); |
85 | /** | 86 | /** |
86 | Return unfiltered list of all events in calendar. | 87 | Return unfiltered list of all events in calendar. |
87 | */ | 88 | */ |
88 | QPtrList<Event> rawEvents(); | 89 | QPtrList<Event> rawEvents(); |
89 | QPtrList<Event> getExternLastSyncEvents(); | 90 | QPtrList<Event> getExternLastSyncEvents(); |
90 | /** | 91 | /** |
91 | Add a todo to the todolist. | 92 | Add a todo to the todolist. |
92 | */ | 93 | */ |
93 | bool addTodo( Todo *todo ); | 94 | bool addTodo( Todo *todo ); |
94 | bool addTodoNoDup( Todo *todo ); | 95 | bool addTodoNoDup( Todo *todo ); |
95 | /** | 96 | /** |
96 | Remove a todo from the todolist. | 97 | Remove a todo from the todolist. |
97 | */ | 98 | */ |
98 | void deleteTodo( Todo * ); | 99 | void deleteTodo( Todo * ); |
99 | /** | 100 | /** |
100 | Searches todolist for an event with this unique string identifier, | 101 | Searches todolist for an event with this unique string identifier, |
101 | returns a pointer or null. | 102 | returns a pointer or null. |
102 | */ | 103 | */ |
103 | Todo *todo( const QString &uid ); | 104 | Todo *todo( const QString &uid ); |
104 | /** | 105 | /** |
105 | Return list of all todos. | 106 | Return list of all todos. |
106 | */ | 107 | */ |
107 | QPtrList<Todo> rawTodos(); | 108 | QPtrList<Todo> rawTodos(); |
108 | /** | 109 | /** |
109 | Returns list of todos due on the specified date. | 110 | Returns list of todos due on the specified date. |
110 | */ | 111 | */ |
111 | QPtrList<Todo> todos( const QDate &date ); | 112 | QPtrList<Todo> todos( const QDate &date ); |
112 | /** | 113 | /** |
113 | Return list of all todos. | 114 | Return list of all todos. |
114 | 115 | ||
115 | Workaround because compiler does not recognize function of base class. | 116 | Workaround because compiler does not recognize function of base class. |
116 | */ | 117 | */ |
117 | QPtrList<Todo> todos() { return Calendar::todos(); } | 118 | QPtrList<Todo> todos() { return Calendar::todos(); } |
118 | 119 | ||
119 | /** | 120 | /** |
120 | Add a Journal entry to calendar. | 121 | Add a Journal entry to calendar. |
121 | */ | 122 | */ |
122 | bool addJournal( Journal * ); | 123 | bool addJournal( Journal * ); |
123 | /** | 124 | /** |
124 | Remove a Journal from the calendar. | 125 | Remove a Journal from the calendar. |
125 | */ | 126 | */ |
126 | void deleteJournal( Journal * ); | 127 | void deleteJournal( Journal * ); |
127 | /** | 128 | /** |
128 | Return Journal for given date. | 129 | Return Journal for given date. |
129 | */ | 130 | */ |
130 | Journal *journal( const QDate & ); | 131 | Journal *journal( const QDate & ); |
131 | /** | 132 | /** |
132 | Return Journal with given UID. | 133 | Return Journal with given UID. |
133 | */ | 134 | */ |
134 | Journal *journal( const QString &uid ); | 135 | Journal *journal( const QString &uid ); |
135 | /** | 136 | /** |
136 | Return list of all Journals stored in calendar. | 137 | Return list of all Journals stored in calendar. |
137 | */ | 138 | */ |
138 | QPtrList<Journal> journals(); | 139 | QPtrList<Journal> journals(); |
139 | 140 | ||
140 | /** | 141 | /** |
141 | Return all alarms, which ocur in the given time interval. | 142 | Return all alarms, which ocur in the given time interval. |
142 | */ | 143 | */ |
143 | Alarm::List alarms( const QDateTime &from, const QDateTime &to ); | 144 | Alarm::List alarms( const QDateTime &from, const QDateTime &to ); |
144 | 145 | ||
145 | /** | 146 | /** |
146 | Return all alarms, which ocur before given date. | 147 | Return all alarms, which ocur before given date. |
147 | */ | 148 | */ |
148 | Alarm::List alarmsTo( const QDateTime &to ); | 149 | Alarm::List alarmsTo( const QDateTime &to ); |
149 | 150 | ||
150 | QDateTime nextAlarm( int daysTo ) ; | 151 | QDateTime nextAlarm( int daysTo ) ; |
151 | QDateTime nextAlarmEventDateTime() const; | 152 | QDateTime nextAlarmEventDateTime() const; |
152 | void checkAlarmForIncidence( Incidence *, bool deleted ) ; | 153 | void checkAlarmForIncidence( Incidence *, bool deleted ) ; |
153 | void registerAlarm(); | 154 | void registerAlarm(); |
154 | void deRegisterAlarm(); | 155 | void deRegisterAlarm(); |
155 | QString getAlarmNotification(); | 156 | QString getAlarmNotification(); |
156 | QString nextSummary() const ; | 157 | QString nextSummary() const ; |
157 | /** | 158 | /** |
158 | This method should be called whenever a Event is modified directly | 159 | This method should be called whenever a Event is modified directly |
159 | via it's pointer. It makes sure that the calendar is internally | 160 | via it's pointer. It makes sure that the calendar is internally |
160 | consistent. | 161 | consistent. |
161 | */ | 162 | */ |
162 | void update( IncidenceBase *incidence ); | 163 | void update( IncidenceBase *incidence ); |
163 | 164 | ||
164 | /** | 165 | /** |
165 | Builds and then returns a list of all events that match for the | 166 | Builds and then returns a list of all events that match for the |
166 | date specified. useful for dayView, etc. etc. | 167 | date specified. useful for dayView, etc. etc. |
167 | */ | 168 | */ |
168 | QPtrList<Event> rawEventsForDate( const QDate &date, bool sorted = false ); | 169 | QPtrList<Event> rawEventsForDate( const QDate &date, bool sorted = false ); |
169 | /** | 170 | /** |
170 | Get unfiltered events for date \a qdt. | 171 | Get unfiltered events for date \a qdt. |
171 | */ | 172 | */ |
172 | QPtrList<Event> rawEventsForDate( const QDateTime &qdt ); | 173 | QPtrList<Event> rawEventsForDate( const QDateTime &qdt ); |
173 | /** | 174 | /** |
174 | Get unfiltered events in a range of dates. If inclusive is set to true, | 175 | Get unfiltered events in a range of dates. If inclusive is set to true, |
175 | only events are returned, which are completely included in the range. | 176 | only events are returned, which are completely included in the range. |
176 | */ | 177 | */ |
177 | QPtrList<Event> rawEvents( const QDate &start, const QDate &end, | 178 | QPtrList<Event> rawEvents( const QDate &start, const QDate &end, |
178 | bool inclusive = false ); | 179 | bool inclusive = false ); |
179 | Todo *todo( QString, QString ); | 180 | Todo *todo( QString, QString ); |
180 | Event *event( QString, QString ); | 181 | Event *event( QString, QString ); |
181 | 182 | ||
182 | 183 | public slots: | |
183 | void setCalendarEnabled( int id, bool enable ); | 184 | void setCalendarEnabled( int id, bool enable ); |
184 | void setAlarmEnabled( int id, bool enable ); | 185 | void setAlarmEnabled( int id, bool enable ); |
186 | void setReadOnly( int id, bool enable ); | ||
185 | void setDefaultCalendarEnabledOnly(); | 187 | void setDefaultCalendarEnabledOnly(); |
186 | 188 | ||
187 | protected: | 189 | protected: |
188 | 190 | ||
189 | // Event* mNextAlarmEvent; | 191 | // Event* mNextAlarmEvent; |
190 | QString mNextSummary; | 192 | QString mNextSummary; |
191 | QString mNextAlarmEventDateTimeString; | 193 | QString mNextAlarmEventDateTimeString; |
192 | QString mLastAlarmNotificationString; | 194 | QString mLastAlarmNotificationString; |
193 | QDateTime mNextAlarmEventDateTime; | 195 | QDateTime mNextAlarmEventDateTime; |
194 | QDateTime mNextAlarmDateTime; | 196 | QDateTime mNextAlarmDateTime; |
195 | void reInitAlarmSettings(); | 197 | void reInitAlarmSettings(); |
196 | 198 | ||
197 | /** Notification function of IncidenceBase::Observer. */ | 199 | /** Notification function of IncidenceBase::Observer. */ |
198 | void incidenceUpdated( IncidenceBase *i ) { update( i ); } | 200 | void incidenceUpdated( IncidenceBase *i ) { update( i ); } |
199 | 201 | ||
200 | /** inserts an event into its "proper place" in the calendar. */ | 202 | /** inserts an event into its "proper place" in the calendar. */ |
201 | void insertEvent( Event *event ); | 203 | void insertEvent( Event *event ); |
202 | 204 | ||
203 | /** Append alarms of incidence in interval to list of alarms. */ | 205 | /** Append alarms of incidence in interval to list of alarms. */ |
204 | void appendAlarms( Alarm::List &alarms, Incidence *incidence, | 206 | void appendAlarms( Alarm::List &alarms, Incidence *incidence, |
205 | const QDateTime &from, const QDateTime &to ); | 207 | const QDateTime &from, const QDateTime &to ); |
206 | 208 | ||
207 | /** Append alarms of recurring events in interval to list of alarms. */ | 209 | /** Append alarms of recurring events in interval to list of alarms. */ |
208 | void appendRecurringAlarms( Alarm::List &alarms, Incidence *incidence, | 210 | void appendRecurringAlarms( Alarm::List &alarms, Incidence *incidence, |
209 | const QDateTime &from, const QDateTime &to ); | 211 | const QDateTime &from, const QDateTime &to ); |
210 | 212 | ||
211 | private: | 213 | private: |
212 | void init(); | 214 | void init(); |
213 | 215 | ||
214 | QPtrList<Event> mEventList; | 216 | QPtrList<Event> mEventList; |
215 | QPtrList<Todo> mTodoList; | 217 | QPtrList<Todo> mTodoList; |
216 | QPtrList<Journal> mJournalList; | 218 | QPtrList<Journal> mJournalList; |
217 | }; | 219 | }; |
218 | 220 | ||
219 | } | 221 | } |
220 | 222 | ||
221 | #endif | 223 | #endif |