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