-rw-r--r-- | libkcal/calendar.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp index a662eeb..b7990d4 100644 --- a/libkcal/calendar.cpp +++ b/libkcal/calendar.cpp | |||
@@ -1,488 +1,489 @@ | |||
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 | mDeleteIncidencesOnClose = true; |
57 | mModified = false; | 57 | mModified = false; |
58 | mDefaultCalendar = 1; | 58 | mDefaultCalendar = 1; |
59 | // Setup default filter, which does nothing | 59 | // Setup default filter, which does nothing |
60 | mDefaultFilter = new CalFilter; | 60 | mDefaultFilter = new CalFilter; |
61 | mFilter = mDefaultFilter; | 61 | mFilter = mDefaultFilter; |
62 | mFilter->setEnabled(false); | 62 | mFilter->setEnabled(false); |
63 | 63 | ||
64 | // initialize random numbers. This is a hack, and not | 64 | // initialize random numbers. This is a hack, and not |
65 | // even that good of one at that. | 65 | // even that good of one at that. |
66 | // srandom(time(0)); | 66 | // srandom(time(0)); |
67 | 67 | ||
68 | // user information... | 68 | // user information... |
69 | setOwner(i18n("Unknown Name")); | 69 | setOwner(i18n("Unknown Name")); |
70 | setEmail(i18n("unknown@nowhere")); | 70 | setEmail(i18n("unknown@nowhere")); |
71 | 71 | ||
72 | #if 0 | 72 | #if 0 |
73 | tmpStr = KOPrefs::instance()->mTimeZone; | 73 | tmpStr = KOPrefs::instance()->mTimeZone; |
74 | // kdDebug(5800) << "Calendar::Calendar(): TimeZone: " << tmpStr << endl; | 74 | // kdDebug(5800) << "Calendar::Calendar(): TimeZone: " << tmpStr << endl; |
75 | int dstSetting = KOPrefs::instance()->mDaylightSavings; | 75 | int dstSetting = KOPrefs::instance()->mDaylightSavings; |
76 | extern long int timezone; | 76 | extern long int timezone; |
77 | struct tm *now; | 77 | struct tm *now; |
78 | time_t curtime; | 78 | time_t curtime; |
79 | curtime = time(0); | 79 | curtime = time(0); |
80 | now = localtime(&curtime); | 80 | now = localtime(&curtime); |
81 | int hourOff = - ((timezone / 60) / 60); | 81 | int hourOff = - ((timezone / 60) / 60); |
82 | if (now->tm_isdst) | 82 | if (now->tm_isdst) |
83 | hourOff += 1; | 83 | hourOff += 1; |
84 | QString tzStr; | 84 | QString tzStr; |
85 | tzStr.sprintf("%.2d%.2d", | 85 | tzStr.sprintf("%.2d%.2d", |
86 | hourOff, | 86 | hourOff, |
87 | abs((timezone / 60) % 60)); | 87 | abs((timezone / 60) % 60)); |
88 | 88 | ||
89 | // 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. |
90 | if (tmpStr.isEmpty()) { | 90 | if (tmpStr.isEmpty()) { |
91 | // KOPrefs::instance()->mTimeZone = tzStr; | 91 | // KOPrefs::instance()->mTimeZone = tzStr; |
92 | } else { | 92 | } else { |
93 | tzStr = tmpStr; | 93 | tzStr = tmpStr; |
94 | } | 94 | } |
95 | 95 | ||
96 | // if daylight savings has changed since last load time, we need | 96 | // if daylight savings has changed since last load time, we need |
97 | // to rewrite these settings to the config file. | 97 | // to rewrite these settings to the config file. |
98 | if ((now->tm_isdst && !dstSetting) || | 98 | if ((now->tm_isdst && !dstSetting) || |
99 | (!now->tm_isdst && dstSetting)) { | 99 | (!now->tm_isdst && dstSetting)) { |
100 | KOPrefs::instance()->mTimeZone = tzStr; | 100 | KOPrefs::instance()->mTimeZone = tzStr; |
101 | KOPrefs::instance()->mDaylightSavings = now->tm_isdst; | 101 | KOPrefs::instance()->mDaylightSavings = now->tm_isdst; |
102 | } | 102 | } |
103 | 103 | ||
104 | setTimeZone(tzStr); | 104 | setTimeZone(tzStr); |
105 | #endif | 105 | #endif |
106 | 106 | ||
107 | // KOPrefs::instance()->writeConfig(); | 107 | // KOPrefs::instance()->writeConfig(); |
108 | } | 108 | } |
109 | 109 | ||
110 | Calendar::~Calendar() | 110 | Calendar::~Calendar() |
111 | { | 111 | { |
112 | delete mDefaultFilter; | 112 | delete mDefaultFilter; |
113 | if ( mUndoIncidence ) | 113 | if ( mUndoIncidence ) |
114 | delete mUndoIncidence; | 114 | delete mUndoIncidence; |
115 | } | 115 | } |
116 | void Calendar::setDontDeleteIncidencesOnClose () | 116 | void Calendar::setDontDeleteIncidencesOnClose () |
117 | { | 117 | { |
118 | mDeleteIncidencesOnClose = false; | 118 | mDeleteIncidencesOnClose = false; |
119 | } | 119 | } |
120 | void Calendar::setDefaultCalendar( int d ) | 120 | void Calendar::setDefaultCalendar( int d ) |
121 | { | 121 | { |
122 | mDefaultCalendar = d; | 122 | mDefaultCalendar = d; |
123 | } | 123 | } |
124 | int Calendar::defaultCalendar() | 124 | int Calendar::defaultCalendar() |
125 | { | 125 | { |
126 | return mDefaultCalendar; | 126 | return mDefaultCalendar; |
127 | } | 127 | } |
128 | const QString &Calendar::getOwner() const | 128 | const QString &Calendar::getOwner() const |
129 | { | 129 | { |
130 | return mOwner; | 130 | return mOwner; |
131 | } | 131 | } |
132 | 132 | ||
133 | bool Calendar::undoDeleteIncidence() | 133 | bool Calendar::undoDeleteIncidence() |
134 | { | 134 | { |
135 | if (!mUndoIncidence) | 135 | if (!mUndoIncidence) |
136 | return false; | 136 | return false; |
137 | addIncidence(mUndoIncidence); | 137 | addIncidence(mUndoIncidence); |
138 | mUndoIncidence = 0; | 138 | mUndoIncidence = 0; |
139 | return true; | 139 | return true; |
140 | } | 140 | } |
141 | void Calendar::setOwner(const QString &os) | 141 | void Calendar::setOwner(const QString &os) |
142 | { | 142 | { |
143 | int i; | 143 | int i; |
144 | mOwner = os; | 144 | mOwner = os; |
145 | i = mOwner.find(','); | 145 | i = mOwner.find(','); |
146 | if (i != -1) | 146 | if (i != -1) |
147 | mOwner = mOwner.left(i); | 147 | mOwner = mOwner.left(i); |
148 | 148 | ||
149 | setModified( true ); | 149 | setModified( true ); |
150 | } | 150 | } |
151 | 151 | ||
152 | void Calendar::setTimeZone(const QString & tz) | 152 | void Calendar::setTimeZone(const QString & tz) |
153 | { | 153 | { |
154 | bool neg = FALSE; | 154 | bool neg = FALSE; |
155 | int hours, minutes; | 155 | int hours, minutes; |
156 | QString tmpStr(tz); | 156 | QString tmpStr(tz); |
157 | 157 | ||
158 | if (tmpStr.left(1) == "-") | 158 | if (tmpStr.left(1) == "-") |
159 | neg = TRUE; | 159 | neg = TRUE; |
160 | if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+") | 160 | if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+") |
161 | tmpStr.remove(0, 1); | 161 | tmpStr.remove(0, 1); |
162 | hours = tmpStr.left(2).toInt(); | 162 | hours = tmpStr.left(2).toInt(); |
163 | if (tmpStr.length() > 2) | 163 | if (tmpStr.length() > 2) |
164 | minutes = tmpStr.right(2).toInt(); | 164 | minutes = tmpStr.right(2).toInt(); |
165 | else | 165 | else |
166 | minutes = 0; | 166 | minutes = 0; |
167 | mTimeZone = (60*hours+minutes); | 167 | mTimeZone = (60*hours+minutes); |
168 | if (neg) | 168 | if (neg) |
169 | mTimeZone = -mTimeZone; | 169 | mTimeZone = -mTimeZone; |
170 | mLocalTime = false; | 170 | mLocalTime = false; |
171 | 171 | ||
172 | setModified( true ); | 172 | setModified( true ); |
173 | } | 173 | } |
174 | 174 | ||
175 | QString Calendar::getTimeZoneStr() const | 175 | QString Calendar::getTimeZoneStr() const |
176 | { | 176 | { |
177 | if (mLocalTime) | 177 | if (mLocalTime) |
178 | return ""; | 178 | return ""; |
179 | QString tmpStr; | 179 | QString tmpStr; |
180 | int hours = abs(mTimeZone / 60); | 180 | int hours = abs(mTimeZone / 60); |
181 | int minutes = abs(mTimeZone % 60); | 181 | int minutes = abs(mTimeZone % 60); |
182 | bool neg = mTimeZone < 0; | 182 | bool neg = mTimeZone < 0; |
183 | 183 | ||
184 | tmpStr.sprintf("%c%.2d%.2d", | 184 | tmpStr.sprintf("%c%.2d%.2d", |
185 | (neg ? '-' : '+'), | 185 | (neg ? '-' : '+'), |
186 | hours, minutes); | 186 | hours, minutes); |
187 | return tmpStr; | 187 | return tmpStr; |
188 | } | 188 | } |
189 | 189 | ||
190 | void Calendar::setTimeZone(int tz) | 190 | void Calendar::setTimeZone(int tz) |
191 | { | 191 | { |
192 | mTimeZone = tz; | 192 | mTimeZone = tz; |
193 | mLocalTime = false; | 193 | mLocalTime = false; |
194 | 194 | ||
195 | setModified( true ); | 195 | setModified( true ); |
196 | } | 196 | } |
197 | 197 | ||
198 | int Calendar::getTimeZone() const | 198 | int Calendar::getTimeZone() const |
199 | { | 199 | { |
200 | return mTimeZone; | 200 | return mTimeZone; |
201 | } | 201 | } |
202 | 202 | ||
203 | void Calendar::setTimeZoneId(const QString &id) | 203 | void Calendar::setTimeZoneId(const QString &id) |
204 | { | 204 | { |
205 | mTimeZoneId = id; | 205 | mTimeZoneId = id; |
206 | mLocalTime = false; | 206 | mLocalTime = false; |
207 | mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId); | 207 | mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId); |
208 | if ( mTimeZone > 1000) | 208 | if ( mTimeZone > 1000) |
209 | setLocalTime(); | 209 | setLocalTime(); |
210 | //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone); | 210 | //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone); |
211 | setModified( true ); | 211 | setModified( true ); |
212 | } | 212 | } |
213 | 213 | ||
214 | QString Calendar::timeZoneId() const | 214 | QString Calendar::timeZoneId() const |
215 | { | 215 | { |
216 | return mTimeZoneId; | 216 | return mTimeZoneId; |
217 | } | 217 | } |
218 | 218 | ||
219 | void Calendar::setLocalTime() | 219 | void Calendar::setLocalTime() |
220 | { | 220 | { |
221 | //qDebug("Calendar::setLocalTime() "); | 221 | //qDebug("Calendar::setLocalTime() "); |
222 | mLocalTime = true; | 222 | mLocalTime = true; |
223 | mTimeZone = 0; | 223 | mTimeZone = 0; |
224 | mTimeZoneId = ""; | 224 | mTimeZoneId = ""; |
225 | 225 | ||
226 | setModified( true ); | 226 | setModified( true ); |
227 | } | 227 | } |
228 | 228 | ||
229 | bool Calendar::isLocalTime() const | 229 | bool Calendar::isLocalTime() const |
230 | { | 230 | { |
231 | return mLocalTime; | 231 | return mLocalTime; |
232 | } | 232 | } |
233 | 233 | ||
234 | const QString &Calendar::getEmail() | 234 | const QString &Calendar::getEmail() |
235 | { | 235 | { |
236 | return mOwnerEmail; | 236 | return mOwnerEmail; |
237 | } | 237 | } |
238 | 238 | ||
239 | void Calendar::setEmail(const QString &e) | 239 | void Calendar::setEmail(const QString &e) |
240 | { | 240 | { |
241 | mOwnerEmail = e; | 241 | mOwnerEmail = e; |
242 | 242 | ||
243 | setModified( true ); | 243 | setModified( true ); |
244 | } | 244 | } |
245 | 245 | ||
246 | void Calendar::setFilter(CalFilter *filter) | 246 | void Calendar::setFilter(CalFilter *filter) |
247 | { | 247 | { |
248 | mFilter = filter; | 248 | mFilter = filter; |
249 | } | 249 | } |
250 | 250 | ||
251 | CalFilter *Calendar::filter() | 251 | CalFilter *Calendar::filter() |
252 | { | 252 | { |
253 | return mFilter; | 253 | return mFilter; |
254 | } | 254 | } |
255 | 255 | ||
256 | QPtrList<Incidence> Calendar::incidences() | 256 | QPtrList<Incidence> Calendar::incidences() |
257 | { | 257 | { |
258 | QPtrList<Incidence> incidences; | 258 | QPtrList<Incidence> incidences; |
259 | 259 | ||
260 | Incidence *i; | 260 | Incidence *i; |
261 | 261 | ||
262 | QPtrList<Event> e = events(); | 262 | QPtrList<Event> e = events(); |
263 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); | 263 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); |
264 | 264 | ||
265 | QPtrList<Todo> t = todos(); | 265 | QPtrList<Todo> t = todos(); |
266 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); | 266 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); |
267 | 267 | ||
268 | QPtrList<Journal> j = journals(); | 268 | QPtrList<Journal> j = journals(); |
269 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); | 269 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); |
270 | 270 | ||
271 | return incidences; | 271 | return incidences; |
272 | } | 272 | } |
273 | 273 | ||
274 | void Calendar::resetPilotStat(int id ) | 274 | void Calendar::resetPilotStat(int id ) |
275 | { | 275 | { |
276 | QPtrList<Incidence> incidences; | 276 | QPtrList<Incidence> incidences; |
277 | 277 | ||
278 | Incidence *i; | 278 | Incidence *i; |
279 | 279 | ||
280 | QPtrList<Event> e = rawEvents(); | 280 | QPtrList<Event> e = rawEvents(); |
281 | for( i = e.first(); i; i = e.next() ) i->setPilotId( id ); | 281 | for( i = e.first(); i; i = e.next() ) i->setPilotId( id ); |
282 | 282 | ||
283 | QPtrList<Todo> t = rawTodos(); | 283 | QPtrList<Todo> t = rawTodos(); |
284 | for( i = t.first(); i; i = t.next() ) i->setPilotId( id ); | 284 | for( i = t.first(); i; i = t.next() ) i->setPilotId( id ); |
285 | 285 | ||
286 | QPtrList<Journal> j = journals(); | 286 | QPtrList<Journal> j = journals(); |
287 | for( i = j.first(); i; i = j.next() ) i->setPilotId( id ); | 287 | for( i = j.first(); i; i = j.next() ) i->setPilotId( id ); |
288 | } | 288 | } |
289 | void Calendar::resetTempSyncStat() | 289 | void Calendar::resetTempSyncStat() |
290 | { | 290 | { |
291 | QPtrList<Incidence> incidences; | 291 | QPtrList<Incidence> incidences; |
292 | 292 | ||
293 | Incidence *i; | 293 | Incidence *i; |
294 | 294 | ||
295 | QPtrList<Event> e = rawEvents(); | 295 | QPtrList<Event> e = rawEvents(); |
296 | 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 ); |
297 | 297 | ||
298 | QPtrList<Todo> t = rawTodos(); | 298 | QPtrList<Todo> t = rawTodos(); |
299 | 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 ); |
300 | 300 | ||
301 | QPtrList<Journal> j = journals(); | 301 | QPtrList<Journal> j = journals(); |
302 | 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 ); |
303 | } | 303 | } |
304 | QPtrList<Incidence> Calendar::rawIncidences() | 304 | QPtrList<Incidence> Calendar::rawIncidences() |
305 | { | 305 | { |
306 | QPtrList<Incidence> incidences; | 306 | QPtrList<Incidence> incidences; |
307 | 307 | ||
308 | Incidence *i; | 308 | Incidence *i; |
309 | 309 | ||
310 | QPtrList<Event> e = rawEvents(); | 310 | QPtrList<Event> e = rawEvents(); |
311 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); | 311 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); |
312 | 312 | ||
313 | QPtrList<Todo> t = rawTodos(); | 313 | QPtrList<Todo> t = rawTodos(); |
314 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); | 314 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); |
315 | 315 | ||
316 | QPtrList<Journal> j = journals(); | 316 | QPtrList<Journal> j = journals(); |
317 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); | 317 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); |
318 | 318 | ||
319 | return incidences; | 319 | return incidences; |
320 | } | 320 | } |
321 | 321 | ||
322 | QPtrList<Event> Calendar::events( const QDate &date, bool sorted ) | 322 | QPtrList<Event> Calendar::events( const QDate &date, bool sorted ) |
323 | { | 323 | { |
324 | QPtrList<Event> el = rawEventsForDate(date,sorted); | 324 | QPtrList<Event> el = rawEventsForDate(date,sorted); |
325 | mFilter->apply(&el); | 325 | mFilter->apply(&el); |
326 | return el; | 326 | return el; |
327 | } | 327 | } |
328 | 328 | ||
329 | QPtrList<Event> Calendar::events( const QDateTime &qdt ) | 329 | QPtrList<Event> Calendar::events( const QDateTime &qdt ) |
330 | { | 330 | { |
331 | QPtrList<Event> el = rawEventsForDate(qdt); | 331 | QPtrList<Event> el = rawEventsForDate(qdt); |
332 | mFilter->apply(&el); | 332 | mFilter->apply(&el); |
333 | return el; | 333 | return el; |
334 | } | 334 | } |
335 | 335 | ||
336 | QPtrList<Event> Calendar::events( const QDate &start, const QDate &end, | 336 | QPtrList<Event> Calendar::events( const QDate &start, const QDate &end, |
337 | bool inclusive) | 337 | bool inclusive) |
338 | { | 338 | { |
339 | QPtrList<Event> el = rawEvents(start,end,inclusive); | 339 | QPtrList<Event> el = rawEvents(start,end,inclusive); |
340 | mFilter->apply(&el); | 340 | mFilter->apply(&el); |
341 | return el; | 341 | return el; |
342 | } | 342 | } |
343 | 343 | ||
344 | QPtrList<Event> Calendar::events() | 344 | QPtrList<Event> Calendar::events() |
345 | { | 345 | { |
346 | QPtrList<Event> el = rawEvents(); | 346 | QPtrList<Event> el = rawEvents(); |
347 | mFilter->apply(&el); | 347 | mFilter->apply(&el); |
348 | return el; | 348 | return el; |
349 | } | 349 | } |
350 | void Calendar::addIncidenceBranch(Incidence *i) | 350 | void Calendar::addIncidenceBranch(Incidence *i) |
351 | { | 351 | { |
352 | addIncidence( i ); | 352 | addIncidence( i ); |
353 | Incidence * inc; | 353 | Incidence * inc; |
354 | QPtrList<Incidence> Relations = i->relations(); | 354 | QPtrList<Incidence> Relations = i->relations(); |
355 | for (inc=Relations.first();inc;inc=Relations.next()) { | 355 | for (inc=Relations.first();inc;inc=Relations.next()) { |
356 | addIncidenceBranch( inc ); | 356 | addIncidenceBranch( inc ); |
357 | } | 357 | } |
358 | } | 358 | } |
359 | 359 | ||
360 | bool Calendar::addIncidence(Incidence *i) | 360 | bool Calendar::addIncidence(Incidence *i) |
361 | { | 361 | { |
362 | Incidence::AddVisitor<Calendar> v(this); | 362 | Incidence::AddVisitor<Calendar> v(this); |
363 | i->setCalID( mDefaultCalendar ); | 363 | if ( i->calID() == 0 ) |
364 | i->setCalID( mDefaultCalendar ); | ||
364 | i->setCalEnabled( true ); | 365 | i->setCalEnabled( true ); |
365 | return i->accept(v); | 366 | return i->accept(v); |
366 | } | 367 | } |
367 | void Calendar::deleteIncidence(Incidence *in) | 368 | void Calendar::deleteIncidence(Incidence *in) |
368 | { | 369 | { |
369 | if ( in->typeID() == eventID ) | 370 | if ( in->typeID() == eventID ) |
370 | deleteEvent( (Event*) in ); | 371 | deleteEvent( (Event*) in ); |
371 | else if ( in->typeID() == todoID ) | 372 | else if ( in->typeID() == todoID ) |
372 | deleteTodo( (Todo*) in); | 373 | deleteTodo( (Todo*) in); |
373 | else if ( in->typeID() == journalID ) | 374 | else if ( in->typeID() == journalID ) |
374 | deleteJournal( (Journal*) in ); | 375 | deleteJournal( (Journal*) in ); |
375 | } | 376 | } |
376 | 377 | ||
377 | Incidence* Calendar::incidence( const QString& uid ) | 378 | Incidence* Calendar::incidence( const QString& uid ) |
378 | { | 379 | { |
379 | Incidence* i; | 380 | Incidence* i; |
380 | 381 | ||
381 | if( (i = todo( uid )) != 0 ) | 382 | if( (i = todo( uid )) != 0 ) |
382 | return i; | 383 | return i; |
383 | if( (i = event( uid )) != 0 ) | 384 | if( (i = event( uid )) != 0 ) |
384 | return i; | 385 | return i; |
385 | if( (i = journal( uid )) != 0 ) | 386 | if( (i = journal( uid )) != 0 ) |
386 | return i; | 387 | return i; |
387 | 388 | ||
388 | return 0; | 389 | return 0; |
389 | } | 390 | } |
390 | 391 | ||
391 | QPtrList<Todo> Calendar::todos() | 392 | QPtrList<Todo> Calendar::todos() |
392 | { | 393 | { |
393 | QPtrList<Todo> tl = rawTodos(); | 394 | QPtrList<Todo> tl = rawTodos(); |
394 | mFilter->apply( &tl ); | 395 | mFilter->apply( &tl ); |
395 | return tl; | 396 | return tl; |
396 | } | 397 | } |
397 | 398 | ||
398 | // When this is called, the todo have already been added to the calendar. | 399 | // When this is called, the todo have already been added to the calendar. |
399 | // This method is only about linking related todos | 400 | // This method is only about linking related todos |
400 | void Calendar::setupRelations( Incidence *incidence ) | 401 | void Calendar::setupRelations( Incidence *incidence ) |
401 | { | 402 | { |
402 | QString uid = incidence->uid(); | 403 | QString uid = incidence->uid(); |
403 | //qDebug("Calendar::setupRelations "); | 404 | //qDebug("Calendar::setupRelations "); |
404 | // First, go over the list of orphans and see if this is their parent | 405 | // First, go over the list of orphans and see if this is their parent |
405 | while( Incidence* i = mOrphans[ uid ] ) { | 406 | while( Incidence* i = mOrphans[ uid ] ) { |
406 | mOrphans.remove( uid ); | 407 | mOrphans.remove( uid ); |
407 | i->setRelatedTo( incidence ); | 408 | i->setRelatedTo( incidence ); |
408 | incidence->addRelation( i ); | 409 | incidence->addRelation( i ); |
409 | mOrphanUids.remove( i->uid() ); | 410 | mOrphanUids.remove( i->uid() ); |
410 | } | 411 | } |
411 | 412 | ||
412 | // Now see about this incidences parent | 413 | // Now see about this incidences parent |
413 | if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) { | 414 | if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) { |
414 | // This incidence has a uid it is related to, but is not registered to it yet | 415 | // This incidence has a uid it is related to, but is not registered to it yet |
415 | // Try to find it | 416 | // Try to find it |
416 | Incidence* parent = this->incidence( incidence->relatedToUid() ); | 417 | Incidence* parent = this->incidence( incidence->relatedToUid() ); |
417 | if( parent ) { | 418 | if( parent ) { |
418 | // Found it | 419 | // Found it |
419 | incidence->setRelatedTo( parent ); | 420 | incidence->setRelatedTo( parent ); |
420 | parent->addRelation( incidence ); | 421 | parent->addRelation( incidence ); |
421 | } else { | 422 | } else { |
422 | // Not found, put this in the mOrphans list | 423 | // Not found, put this in the mOrphans list |
423 | mOrphans.insert( incidence->relatedToUid(), incidence ); | 424 | mOrphans.insert( incidence->relatedToUid(), incidence ); |
424 | mOrphanUids.insert( incidence->uid(), incidence ); | 425 | mOrphanUids.insert( incidence->uid(), incidence ); |
425 | } | 426 | } |
426 | } | 427 | } |
427 | } | 428 | } |
428 | 429 | ||
429 | // If a task with subtasks is deleted, move it's subtasks to the orphans list | 430 | // If a task with subtasks is deleted, move it's subtasks to the orphans list |
430 | void Calendar::removeRelations( Incidence *incidence ) | 431 | void Calendar::removeRelations( Incidence *incidence ) |
431 | { | 432 | { |
432 | // qDebug("Calendar::removeRelations "); | 433 | // qDebug("Calendar::removeRelations "); |
433 | QString uid = incidence->uid(); | 434 | QString uid = incidence->uid(); |
434 | 435 | ||
435 | QPtrList<Incidence> relations = incidence->relations(); | 436 | QPtrList<Incidence> relations = incidence->relations(); |
436 | for( Incidence* i = relations.first(); i; i = relations.next() ) | 437 | for( Incidence* i = relations.first(); i; i = relations.next() ) |
437 | if( !mOrphanUids.find( i->uid() ) ) { | 438 | if( !mOrphanUids.find( i->uid() ) ) { |
438 | mOrphans.insert( uid, i ); | 439 | mOrphans.insert( uid, i ); |
439 | mOrphanUids.insert( i->uid(), i ); | 440 | mOrphanUids.insert( i->uid(), i ); |
440 | i->setRelatedTo( 0 ); | 441 | i->setRelatedTo( 0 ); |
441 | i->setRelatedToUid( uid ); | 442 | i->setRelatedToUid( uid ); |
442 | } | 443 | } |
443 | 444 | ||
444 | // If this incidence is related to something else, tell that about it | 445 | // If this incidence is related to something else, tell that about it |
445 | if( incidence->relatedTo() ) | 446 | if( incidence->relatedTo() ) |
446 | incidence->relatedTo()->removeRelation( incidence ); | 447 | incidence->relatedTo()->removeRelation( incidence ); |
447 | 448 | ||
448 | // Remove this one from the orphans list | 449 | // Remove this one from the orphans list |
449 | if( mOrphanUids.remove( uid ) ) | 450 | if( mOrphanUids.remove( uid ) ) |
450 | // This incidence is located in the orphans list - it should be removed | 451 | // This incidence is located in the orphans list - it should be removed |
451 | if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) { | 452 | if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) { |
452 | // Removing wasn't that easy | 453 | // Removing wasn't that easy |
453 | for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) { | 454 | for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) { |
454 | if( it.current()->uid() == uid ) { | 455 | if( it.current()->uid() == uid ) { |
455 | mOrphans.remove( it.currentKey() ); | 456 | mOrphans.remove( it.currentKey() ); |
456 | break; | 457 | break; |
457 | } | 458 | } |
458 | } | 459 | } |
459 | } | 460 | } |
460 | } | 461 | } |
461 | 462 | ||
462 | void Calendar::registerObserver( Observer *observer ) | 463 | void Calendar::registerObserver( Observer *observer ) |
463 | { | 464 | { |
464 | mObserver = observer; | 465 | mObserver = observer; |
465 | mNewObserver = true; | 466 | mNewObserver = true; |
466 | } | 467 | } |
467 | 468 | ||
468 | void Calendar::setModified( bool modified ) | 469 | void Calendar::setModified( bool modified ) |
469 | { | 470 | { |
470 | if ( mObserver ) mObserver->calendarModified( modified, this ); | 471 | if ( mObserver ) mObserver->calendarModified( modified, this ); |
471 | if ( modified != mModified || mNewObserver ) { | 472 | if ( modified != mModified || mNewObserver ) { |
472 | mNewObserver = false; | 473 | mNewObserver = false; |
473 | // if ( mObserver ) mObserver->calendarModified( modified, this ); | 474 | // if ( mObserver ) mObserver->calendarModified( modified, this ); |
474 | mModified = modified; | 475 | mModified = modified; |
475 | } | 476 | } |
476 | } | 477 | } |
477 | 478 | ||
478 | void Calendar::setLoadedProductId( const QString &id ) | 479 | void Calendar::setLoadedProductId( const QString &id ) |
479 | { | 480 | { |
480 | mLoadedProductId = id; | 481 | mLoadedProductId = id; |
481 | } | 482 | } |
482 | 483 | ||
483 | QString Calendar::loadedProductId() | 484 | QString Calendar::loadedProductId() |
484 | { | 485 | { |
485 | return mLoadedProductId; | 486 | return mLoadedProductId; |
486 | } | 487 | } |
487 | 488 | ||
488 | //#include "calendar.moc" | 489 | //#include "calendar.moc" |