-rw-r--r-- | libkcal/calendar.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp index 52daaaa..88351eb 100644 --- a/libkcal/calendar.cpp +++ b/libkcal/calendar.cpp | |||
@@ -1,457 +1,466 @@ | |||
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( i18n (" 00:00 Europe/London(UTC)") ); | 41 | setTimeZoneId( i18n (" 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 | 55 | mUndoIncidence = 0; | |
56 | mModified = false; | 56 | mModified = false; |
57 | 57 | ||
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 ) | ||
113 | delete mUndoIncidence; | ||
112 | } | 114 | } |
113 | 115 | ||
114 | const QString &Calendar::getOwner() const | 116 | const QString &Calendar::getOwner() const |
115 | { | 117 | { |
116 | return mOwner; | 118 | return mOwner; |
117 | } | 119 | } |
118 | 120 | ||
121 | bool Calendar::undoDeleteIncidence() | ||
122 | { | ||
123 | if (!mUndoIncidence) | ||
124 | return false; | ||
125 | addIncidence(mUndoIncidence); | ||
126 | mUndoIncidence = 0; | ||
127 | } | ||
119 | void Calendar::setOwner(const QString &os) | 128 | void Calendar::setOwner(const QString &os) |
120 | { | 129 | { |
121 | int i; | 130 | int i; |
122 | mOwner = os; | 131 | mOwner = os; |
123 | i = mOwner.find(','); | 132 | i = mOwner.find(','); |
124 | if (i != -1) | 133 | if (i != -1) |
125 | mOwner = mOwner.left(i); | 134 | mOwner = mOwner.left(i); |
126 | 135 | ||
127 | setModified( true ); | 136 | setModified( true ); |
128 | } | 137 | } |
129 | 138 | ||
130 | void Calendar::setTimeZone(const QString & tz) | 139 | void Calendar::setTimeZone(const QString & tz) |
131 | { | 140 | { |
132 | bool neg = FALSE; | 141 | bool neg = FALSE; |
133 | int hours, minutes; | 142 | int hours, minutes; |
134 | QString tmpStr(tz); | 143 | QString tmpStr(tz); |
135 | 144 | ||
136 | if (tmpStr.left(1) == "-") | 145 | if (tmpStr.left(1) == "-") |
137 | neg = TRUE; | 146 | neg = TRUE; |
138 | if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+") | 147 | if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+") |
139 | tmpStr.remove(0, 1); | 148 | tmpStr.remove(0, 1); |
140 | hours = tmpStr.left(2).toInt(); | 149 | hours = tmpStr.left(2).toInt(); |
141 | if (tmpStr.length() > 2) | 150 | if (tmpStr.length() > 2) |
142 | minutes = tmpStr.right(2).toInt(); | 151 | minutes = tmpStr.right(2).toInt(); |
143 | else | 152 | else |
144 | minutes = 0; | 153 | minutes = 0; |
145 | mTimeZone = (60*hours+minutes); | 154 | mTimeZone = (60*hours+minutes); |
146 | if (neg) | 155 | if (neg) |
147 | mTimeZone = -mTimeZone; | 156 | mTimeZone = -mTimeZone; |
148 | mLocalTime = false; | 157 | mLocalTime = false; |
149 | 158 | ||
150 | setModified( true ); | 159 | setModified( true ); |
151 | } | 160 | } |
152 | 161 | ||
153 | QString Calendar::getTimeZoneStr() const | 162 | QString Calendar::getTimeZoneStr() const |
154 | { | 163 | { |
155 | if (mLocalTime) | 164 | if (mLocalTime) |
156 | return ""; | 165 | return ""; |
157 | QString tmpStr; | 166 | QString tmpStr; |
158 | int hours = abs(mTimeZone / 60); | 167 | int hours = abs(mTimeZone / 60); |
159 | int minutes = abs(mTimeZone % 60); | 168 | int minutes = abs(mTimeZone % 60); |
160 | bool neg = mTimeZone < 0; | 169 | bool neg = mTimeZone < 0; |
161 | 170 | ||
162 | tmpStr.sprintf("%c%.2d%.2d", | 171 | tmpStr.sprintf("%c%.2d%.2d", |
163 | (neg ? '-' : '+'), | 172 | (neg ? '-' : '+'), |
164 | hours, minutes); | 173 | hours, minutes); |
165 | return tmpStr; | 174 | return tmpStr; |
166 | } | 175 | } |
167 | 176 | ||
168 | void Calendar::setTimeZone(int tz) | 177 | void Calendar::setTimeZone(int tz) |
169 | { | 178 | { |
170 | mTimeZone = tz; | 179 | mTimeZone = tz; |
171 | mLocalTime = false; | 180 | mLocalTime = false; |
172 | 181 | ||
173 | setModified( true ); | 182 | setModified( true ); |
174 | } | 183 | } |
175 | 184 | ||
176 | int Calendar::getTimeZone() const | 185 | int Calendar::getTimeZone() const |
177 | { | 186 | { |
178 | return mTimeZone; | 187 | return mTimeZone; |
179 | } | 188 | } |
180 | 189 | ||
181 | void Calendar::setTimeZoneId(const QString &id) | 190 | void Calendar::setTimeZoneId(const QString &id) |
182 | { | 191 | { |
183 | mTimeZoneId = id; | 192 | mTimeZoneId = id; |
184 | mLocalTime = false; | 193 | mLocalTime = false; |
185 | mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId); | 194 | mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId); |
186 | if ( mTimeZone > 1000) | 195 | if ( mTimeZone > 1000) |
187 | setLocalTime(); | 196 | setLocalTime(); |
188 | //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone); | 197 | //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone); |
189 | setModified( true ); | 198 | setModified( true ); |
190 | } | 199 | } |
191 | 200 | ||
192 | QString Calendar::timeZoneId() const | 201 | QString Calendar::timeZoneId() const |
193 | { | 202 | { |
194 | return mTimeZoneId; | 203 | return mTimeZoneId; |
195 | } | 204 | } |
196 | 205 | ||
197 | void Calendar::setLocalTime() | 206 | void Calendar::setLocalTime() |
198 | { | 207 | { |
199 | //qDebug("Calendar::setLocalTime() "); | 208 | //qDebug("Calendar::setLocalTime() "); |
200 | mLocalTime = true; | 209 | mLocalTime = true; |
201 | mTimeZone = 0; | 210 | mTimeZone = 0; |
202 | mTimeZoneId = ""; | 211 | mTimeZoneId = ""; |
203 | 212 | ||
204 | setModified( true ); | 213 | setModified( true ); |
205 | } | 214 | } |
206 | 215 | ||
207 | bool Calendar::isLocalTime() const | 216 | bool Calendar::isLocalTime() const |
208 | { | 217 | { |
209 | return mLocalTime; | 218 | return mLocalTime; |
210 | } | 219 | } |
211 | 220 | ||
212 | const QString &Calendar::getEmail() | 221 | const QString &Calendar::getEmail() |
213 | { | 222 | { |
214 | return mOwnerEmail; | 223 | return mOwnerEmail; |
215 | } | 224 | } |
216 | 225 | ||
217 | void Calendar::setEmail(const QString &e) | 226 | void Calendar::setEmail(const QString &e) |
218 | { | 227 | { |
219 | mOwnerEmail = e; | 228 | mOwnerEmail = e; |
220 | 229 | ||
221 | setModified( true ); | 230 | setModified( true ); |
222 | } | 231 | } |
223 | 232 | ||
224 | void Calendar::setFilter(CalFilter *filter) | 233 | void Calendar::setFilter(CalFilter *filter) |
225 | { | 234 | { |
226 | mFilter = filter; | 235 | mFilter = filter; |
227 | } | 236 | } |
228 | 237 | ||
229 | CalFilter *Calendar::filter() | 238 | CalFilter *Calendar::filter() |
230 | { | 239 | { |
231 | return mFilter; | 240 | return mFilter; |
232 | } | 241 | } |
233 | 242 | ||
234 | QPtrList<Incidence> Calendar::incidences() | 243 | QPtrList<Incidence> Calendar::incidences() |
235 | { | 244 | { |
236 | QPtrList<Incidence> incidences; | 245 | QPtrList<Incidence> incidences; |
237 | 246 | ||
238 | Incidence *i; | 247 | Incidence *i; |
239 | 248 | ||
240 | QPtrList<Event> e = events(); | 249 | QPtrList<Event> e = events(); |
241 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); | 250 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); |
242 | 251 | ||
243 | QPtrList<Todo> t = todos(); | 252 | QPtrList<Todo> t = todos(); |
244 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); | 253 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); |
245 | 254 | ||
246 | QPtrList<Journal> j = journals(); | 255 | QPtrList<Journal> j = journals(); |
247 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); | 256 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); |
248 | 257 | ||
249 | return incidences; | 258 | return incidences; |
250 | } | 259 | } |
251 | 260 | ||
252 | void Calendar::resetPilotStat(int id ) | 261 | void Calendar::resetPilotStat(int id ) |
253 | { | 262 | { |
254 | QPtrList<Incidence> incidences; | 263 | QPtrList<Incidence> incidences; |
255 | 264 | ||
256 | Incidence *i; | 265 | Incidence *i; |
257 | 266 | ||
258 | QPtrList<Event> e = rawEvents(); | 267 | QPtrList<Event> e = rawEvents(); |
259 | for( i = e.first(); i; i = e.next() ) i->setPilotId( id ); | 268 | for( i = e.first(); i; i = e.next() ) i->setPilotId( id ); |
260 | 269 | ||
261 | QPtrList<Todo> t = rawTodos(); | 270 | QPtrList<Todo> t = rawTodos(); |
262 | for( i = t.first(); i; i = t.next() ) i->setPilotId( id ); | 271 | for( i = t.first(); i; i = t.next() ) i->setPilotId( id ); |
263 | 272 | ||
264 | QPtrList<Journal> j = journals(); | 273 | QPtrList<Journal> j = journals(); |
265 | for( i = j.first(); i; i = j.next() ) i->setPilotId( id ); | 274 | for( i = j.first(); i; i = j.next() ) i->setPilotId( id ); |
266 | } | 275 | } |
267 | void Calendar::resetTempSyncStat() | 276 | void Calendar::resetTempSyncStat() |
268 | { | 277 | { |
269 | QPtrList<Incidence> incidences; | 278 | QPtrList<Incidence> incidences; |
270 | 279 | ||
271 | Incidence *i; | 280 | Incidence *i; |
272 | 281 | ||
273 | QPtrList<Event> e = rawEvents(); | 282 | QPtrList<Event> e = rawEvents(); |
274 | for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 283 | for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
275 | 284 | ||
276 | QPtrList<Todo> t = rawTodos(); | 285 | QPtrList<Todo> t = rawTodos(); |
277 | for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 286 | for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
278 | 287 | ||
279 | QPtrList<Journal> j = journals(); | 288 | QPtrList<Journal> j = journals(); |
280 | for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 289 | for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
281 | } | 290 | } |
282 | QPtrList<Incidence> Calendar::rawIncidences() | 291 | QPtrList<Incidence> Calendar::rawIncidences() |
283 | { | 292 | { |
284 | QPtrList<Incidence> incidences; | 293 | QPtrList<Incidence> incidences; |
285 | 294 | ||
286 | Incidence *i; | 295 | Incidence *i; |
287 | 296 | ||
288 | QPtrList<Event> e = rawEvents(); | 297 | QPtrList<Event> e = rawEvents(); |
289 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); | 298 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); |
290 | 299 | ||
291 | QPtrList<Todo> t = rawTodos(); | 300 | QPtrList<Todo> t = rawTodos(); |
292 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); | 301 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); |
293 | 302 | ||
294 | QPtrList<Journal> j = journals(); | 303 | QPtrList<Journal> j = journals(); |
295 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); | 304 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); |
296 | 305 | ||
297 | return incidences; | 306 | return incidences; |
298 | } | 307 | } |
299 | 308 | ||
300 | QPtrList<Event> Calendar::events( const QDate &date, bool sorted ) | 309 | QPtrList<Event> Calendar::events( const QDate &date, bool sorted ) |
301 | { | 310 | { |
302 | QPtrList<Event> el = rawEventsForDate(date,sorted); | 311 | QPtrList<Event> el = rawEventsForDate(date,sorted); |
303 | mFilter->apply(&el); | 312 | mFilter->apply(&el); |
304 | return el; | 313 | return el; |
305 | } | 314 | } |
306 | 315 | ||
307 | QPtrList<Event> Calendar::events( const QDateTime &qdt ) | 316 | QPtrList<Event> Calendar::events( const QDateTime &qdt ) |
308 | { | 317 | { |
309 | QPtrList<Event> el = rawEventsForDate(qdt); | 318 | QPtrList<Event> el = rawEventsForDate(qdt); |
310 | mFilter->apply(&el); | 319 | mFilter->apply(&el); |
311 | return el; | 320 | return el; |
312 | } | 321 | } |
313 | 322 | ||
314 | QPtrList<Event> Calendar::events( const QDate &start, const QDate &end, | 323 | QPtrList<Event> Calendar::events( const QDate &start, const QDate &end, |
315 | bool inclusive) | 324 | bool inclusive) |
316 | { | 325 | { |
317 | QPtrList<Event> el = rawEvents(start,end,inclusive); | 326 | QPtrList<Event> el = rawEvents(start,end,inclusive); |
318 | mFilter->apply(&el); | 327 | mFilter->apply(&el); |
319 | return el; | 328 | return el; |
320 | } | 329 | } |
321 | 330 | ||
322 | QPtrList<Event> Calendar::events() | 331 | QPtrList<Event> Calendar::events() |
323 | { | 332 | { |
324 | QPtrList<Event> el = rawEvents(); | 333 | QPtrList<Event> el = rawEvents(); |
325 | mFilter->apply(&el); | 334 | mFilter->apply(&el); |
326 | return el; | 335 | return el; |
327 | } | 336 | } |
328 | 337 | ||
329 | 338 | ||
330 | bool Calendar::addIncidence(Incidence *i) | 339 | bool Calendar::addIncidence(Incidence *i) |
331 | { | 340 | { |
332 | Incidence::AddVisitor<Calendar> v(this); | 341 | Incidence::AddVisitor<Calendar> v(this); |
333 | 342 | ||
334 | return i->accept(v); | 343 | return i->accept(v); |
335 | } | 344 | } |
336 | void Calendar::deleteIncidence(Incidence *in) | 345 | void Calendar::deleteIncidence(Incidence *in) |
337 | { | 346 | { |
338 | if ( in->type() == "Event" ) | 347 | if ( in->type() == "Event" ) |
339 | deleteEvent( (Event*) in ); | 348 | deleteEvent( (Event*) in ); |
340 | else if ( in->type() =="Todo" ) | 349 | else if ( in->type() =="Todo" ) |
341 | deleteTodo( (Todo*) in); | 350 | deleteTodo( (Todo*) in); |
342 | else if ( in->type() =="Journal" ) | 351 | else if ( in->type() =="Journal" ) |
343 | deleteJournal( (Journal*) in ); | 352 | deleteJournal( (Journal*) in ); |
344 | } | 353 | } |
345 | 354 | ||
346 | Incidence* Calendar::incidence( const QString& uid ) | 355 | Incidence* Calendar::incidence( const QString& uid ) |
347 | { | 356 | { |
348 | Incidence* i; | 357 | Incidence* i; |
349 | 358 | ||
350 | if( (i = todo( uid )) != 0 ) | 359 | if( (i = todo( uid )) != 0 ) |
351 | return i; | 360 | return i; |
352 | if( (i = event( uid )) != 0 ) | 361 | if( (i = event( uid )) != 0 ) |
353 | return i; | 362 | return i; |
354 | if( (i = journal( uid )) != 0 ) | 363 | if( (i = journal( uid )) != 0 ) |
355 | return i; | 364 | return i; |
356 | 365 | ||
357 | return 0; | 366 | return 0; |
358 | } | 367 | } |
359 | 368 | ||
360 | QPtrList<Todo> Calendar::todos() | 369 | QPtrList<Todo> Calendar::todos() |
361 | { | 370 | { |
362 | QPtrList<Todo> tl = rawTodos(); | 371 | QPtrList<Todo> tl = rawTodos(); |
363 | mFilter->apply( &tl ); | 372 | mFilter->apply( &tl ); |
364 | return tl; | 373 | return tl; |
365 | } | 374 | } |
366 | 375 | ||
367 | // When this is called, the todo have already been added to the calendar. | 376 | // When this is called, the todo have already been added to the calendar. |
368 | // This method is only about linking related todos | 377 | // This method is only about linking related todos |
369 | void Calendar::setupRelations( Incidence *incidence ) | 378 | void Calendar::setupRelations( Incidence *incidence ) |
370 | { | 379 | { |
371 | QString uid = incidence->uid(); | 380 | QString uid = incidence->uid(); |
372 | //qDebug("Calendar::setupRelations "); | 381 | //qDebug("Calendar::setupRelations "); |
373 | // First, go over the list of orphans and see if this is their parent | 382 | // First, go over the list of orphans and see if this is their parent |
374 | while( Incidence* i = mOrphans[ uid ] ) { | 383 | while( Incidence* i = mOrphans[ uid ] ) { |
375 | mOrphans.remove( uid ); | 384 | mOrphans.remove( uid ); |
376 | i->setRelatedTo( incidence ); | 385 | i->setRelatedTo( incidence ); |
377 | incidence->addRelation( i ); | 386 | incidence->addRelation( i ); |
378 | mOrphanUids.remove( i->uid() ); | 387 | mOrphanUids.remove( i->uid() ); |
379 | } | 388 | } |
380 | 389 | ||
381 | // Now see about this incidences parent | 390 | // Now see about this incidences parent |
382 | if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) { | 391 | if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) { |
383 | // This incidence has a uid it is related to, but is not registered to it yet | 392 | // This incidence has a uid it is related to, but is not registered to it yet |
384 | // Try to find it | 393 | // Try to find it |
385 | Incidence* parent = this->incidence( incidence->relatedToUid() ); | 394 | Incidence* parent = this->incidence( incidence->relatedToUid() ); |
386 | if( parent ) { | 395 | if( parent ) { |
387 | // Found it | 396 | // Found it |
388 | incidence->setRelatedTo( parent ); | 397 | incidence->setRelatedTo( parent ); |
389 | parent->addRelation( incidence ); | 398 | parent->addRelation( incidence ); |
390 | } else { | 399 | } else { |
391 | // Not found, put this in the mOrphans list | 400 | // Not found, put this in the mOrphans list |
392 | mOrphans.insert( incidence->relatedToUid(), incidence ); | 401 | mOrphans.insert( incidence->relatedToUid(), incidence ); |
393 | mOrphanUids.insert( incidence->uid(), incidence ); | 402 | mOrphanUids.insert( incidence->uid(), incidence ); |
394 | } | 403 | } |
395 | } | 404 | } |
396 | } | 405 | } |
397 | 406 | ||
398 | // If a task with subtasks is deleted, move it's subtasks to the orphans list | 407 | // If a task with subtasks is deleted, move it's subtasks to the orphans list |
399 | void Calendar::removeRelations( Incidence *incidence ) | 408 | void Calendar::removeRelations( Incidence *incidence ) |
400 | { | 409 | { |
401 | // qDebug("Calendar::removeRelations "); | 410 | // qDebug("Calendar::removeRelations "); |
402 | QString uid = incidence->uid(); | 411 | QString uid = incidence->uid(); |
403 | 412 | ||
404 | QPtrList<Incidence> relations = incidence->relations(); | 413 | QPtrList<Incidence> relations = incidence->relations(); |
405 | for( Incidence* i = relations.first(); i; i = relations.next() ) | 414 | for( Incidence* i = relations.first(); i; i = relations.next() ) |
406 | if( !mOrphanUids.find( i->uid() ) ) { | 415 | if( !mOrphanUids.find( i->uid() ) ) { |
407 | mOrphans.insert( uid, i ); | 416 | mOrphans.insert( uid, i ); |
408 | mOrphanUids.insert( i->uid(), i ); | 417 | mOrphanUids.insert( i->uid(), i ); |
409 | i->setRelatedTo( 0 ); | 418 | i->setRelatedTo( 0 ); |
410 | i->setRelatedToUid( uid ); | 419 | i->setRelatedToUid( uid ); |
411 | } | 420 | } |
412 | 421 | ||
413 | // If this incidence is related to something else, tell that about it | 422 | // If this incidence is related to something else, tell that about it |
414 | if( incidence->relatedTo() ) | 423 | if( incidence->relatedTo() ) |
415 | incidence->relatedTo()->removeRelation( incidence ); | 424 | incidence->relatedTo()->removeRelation( incidence ); |
416 | 425 | ||
417 | // Remove this one from the orphans list | 426 | // Remove this one from the orphans list |
418 | if( mOrphanUids.remove( uid ) ) | 427 | if( mOrphanUids.remove( uid ) ) |
419 | // This incidence is located in the orphans list - it should be removed | 428 | // This incidence is located in the orphans list - it should be removed |
420 | if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) { | 429 | if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) { |
421 | // Removing wasn't that easy | 430 | // Removing wasn't that easy |
422 | for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) { | 431 | for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) { |
423 | if( it.current()->uid() == uid ) { | 432 | if( it.current()->uid() == uid ) { |
424 | mOrphans.remove( it.currentKey() ); | 433 | mOrphans.remove( it.currentKey() ); |
425 | break; | 434 | break; |
426 | } | 435 | } |
427 | } | 436 | } |
428 | } | 437 | } |
429 | } | 438 | } |
430 | 439 | ||
431 | void Calendar::registerObserver( Observer *observer ) | 440 | void Calendar::registerObserver( Observer *observer ) |
432 | { | 441 | { |
433 | mObserver = observer; | 442 | mObserver = observer; |
434 | mNewObserver = true; | 443 | mNewObserver = true; |
435 | } | 444 | } |
436 | 445 | ||
437 | void Calendar::setModified( bool modified ) | 446 | void Calendar::setModified( bool modified ) |
438 | { | 447 | { |
439 | if ( mObserver ) mObserver->calendarModified( modified, this ); | 448 | if ( mObserver ) mObserver->calendarModified( modified, this ); |
440 | if ( modified != mModified || mNewObserver ) { | 449 | if ( modified != mModified || mNewObserver ) { |
441 | mNewObserver = false; | 450 | mNewObserver = false; |
442 | // if ( mObserver ) mObserver->calendarModified( modified, this ); | 451 | // if ( mObserver ) mObserver->calendarModified( modified, this ); |
443 | mModified = modified; | 452 | mModified = modified; |
444 | } | 453 | } |
445 | } | 454 | } |
446 | 455 | ||
447 | void Calendar::setLoadedProductId( const QString &id ) | 456 | void Calendar::setLoadedProductId( const QString &id ) |
448 | { | 457 | { |
449 | mLoadedProductId = id; | 458 | mLoadedProductId = id; |
450 | } | 459 | } |
451 | 460 | ||
452 | QString Calendar::loadedProductId() | 461 | QString Calendar::loadedProductId() |
453 | { | 462 | { |
454 | return mLoadedProductId; | 463 | return mLoadedProductId; |
455 | } | 464 | } |
456 | 465 | ||
457 | //#include "calendar.moc" | 466 | //#include "calendar.moc" |