-rw-r--r-- | libkcal/calendar.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp index 32aac7a..a3977d7 100644 --- a/libkcal/calendar.cpp +++ b/libkcal/calendar.cpp | |||
@@ -1,128 +1,129 @@ | |||
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 | 34 | ||
34 | using namespace KCal; | 35 | using namespace KCal; |
35 | 36 | ||
36 | Calendar::Calendar() | 37 | Calendar::Calendar() |
37 | { | 38 | { |
38 | 39 | ||
39 | init(); | 40 | init(); |
40 | setTimeZoneId( i18n (" 00:00 Europe/London(UTC)") ); | 41 | setTimeZoneId( i18n (" 00:00 Europe/London(UTC)") ); |
41 | } | 42 | } |
42 | 43 | ||
43 | Calendar::Calendar( const QString &timeZoneId ) | 44 | Calendar::Calendar( const QString &timeZoneId ) |
44 | { | 45 | { |
45 | 46 | ||
46 | init(); | 47 | init(); |
47 | setTimeZoneId(timeZoneId); | 48 | setTimeZoneId(timeZoneId); |
48 | } | 49 | } |
49 | 50 | ||
50 | void Calendar::init() | 51 | void Calendar::init() |
51 | { | 52 | { |
52 | mObserver = 0; | 53 | mObserver = 0; |
53 | mNewObserver = false; | 54 | mNewObserver = false; |
54 | 55 | ||
55 | mModified = false; | 56 | mModified = false; |
56 | 57 | ||
57 | // Setup default filter, which does nothing | 58 | // Setup default filter, which does nothing |
58 | mDefaultFilter = new CalFilter; | 59 | mDefaultFilter = new CalFilter; |
59 | mFilter = mDefaultFilter; | 60 | mFilter = mDefaultFilter; |
60 | mFilter->setEnabled(false); | 61 | mFilter->setEnabled(false); |
61 | 62 | ||
62 | // initialize random numbers. This is a hack, and not | 63 | // initialize random numbers. This is a hack, and not |
63 | // even that good of one at that. | 64 | // even that good of one at that. |
64 | // srandom(time(0)); | 65 | // srandom(time(0)); |
65 | 66 | ||
66 | // user information... | 67 | // user information... |
67 | setOwner(i18n("Unknown Name")); | 68 | setOwner(i18n("Unknown Name")); |
68 | setEmail(i18n("unknown@nowhere")); | 69 | setEmail(i18n("unknown@nowhere")); |
69 | 70 | ||
70 | #if 0 | 71 | #if 0 |
71 | tmpStr = KOPrefs::instance()->mTimeZone; | 72 | tmpStr = KOPrefs::instance()->mTimeZone; |
72 | // kdDebug(5800) << "Calendar::Calendar(): TimeZone: " << tmpStr << endl; | 73 | // kdDebug(5800) << "Calendar::Calendar(): TimeZone: " << tmpStr << endl; |
73 | int dstSetting = KOPrefs::instance()->mDaylightSavings; | 74 | int dstSetting = KOPrefs::instance()->mDaylightSavings; |
74 | extern long int timezone; | 75 | extern long int timezone; |
75 | struct tm *now; | 76 | struct tm *now; |
76 | time_t curtime; | 77 | time_t curtime; |
77 | curtime = time(0); | 78 | curtime = time(0); |
78 | now = localtime(&curtime); | 79 | now = localtime(&curtime); |
79 | int hourOff = - ((timezone / 60) / 60); | 80 | int hourOff = - ((timezone / 60) / 60); |
80 | if (now->tm_isdst) | 81 | if (now->tm_isdst) |
81 | hourOff += 1; | 82 | hourOff += 1; |
82 | QString tzStr; | 83 | QString tzStr; |
83 | tzStr.sprintf("%.2d%.2d", | 84 | tzStr.sprintf("%.2d%.2d", |
84 | hourOff, | 85 | hourOff, |
85 | abs((timezone / 60) % 60)); | 86 | abs((timezone / 60) % 60)); |
86 | 87 | ||
87 | // 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. |
88 | if (tmpStr.isEmpty()) { | 89 | if (tmpStr.isEmpty()) { |
89 | // KOPrefs::instance()->mTimeZone = tzStr; | 90 | // KOPrefs::instance()->mTimeZone = tzStr; |
90 | } else { | 91 | } else { |
91 | tzStr = tmpStr; | 92 | tzStr = tmpStr; |
92 | } | 93 | } |
93 | 94 | ||
94 | // if daylight savings has changed since last load time, we need | 95 | // if daylight savings has changed since last load time, we need |
95 | // to rewrite these settings to the config file. | 96 | // to rewrite these settings to the config file. |
96 | if ((now->tm_isdst && !dstSetting) || | 97 | if ((now->tm_isdst && !dstSetting) || |
97 | (!now->tm_isdst && dstSetting)) { | 98 | (!now->tm_isdst && dstSetting)) { |
98 | KOPrefs::instance()->mTimeZone = tzStr; | 99 | KOPrefs::instance()->mTimeZone = tzStr; |
99 | KOPrefs::instance()->mDaylightSavings = now->tm_isdst; | 100 | KOPrefs::instance()->mDaylightSavings = now->tm_isdst; |
100 | } | 101 | } |
101 | 102 | ||
102 | setTimeZone(tzStr); | 103 | setTimeZone(tzStr); |
103 | #endif | 104 | #endif |
104 | 105 | ||
105 | // KOPrefs::instance()->writeConfig(); | 106 | // KOPrefs::instance()->writeConfig(); |
106 | } | 107 | } |
107 | 108 | ||
108 | Calendar::~Calendar() | 109 | Calendar::~Calendar() |
109 | { | 110 | { |
110 | delete mDefaultFilter; | 111 | delete mDefaultFilter; |
111 | } | 112 | } |
112 | 113 | ||
113 | const QString &Calendar::getOwner() const | 114 | const QString &Calendar::getOwner() const |
114 | { | 115 | { |
115 | return mOwner; | 116 | return mOwner; |
116 | } | 117 | } |
117 | 118 | ||
118 | void Calendar::setOwner(const QString &os) | 119 | void Calendar::setOwner(const QString &os) |
119 | { | 120 | { |
120 | int i; | 121 | int i; |
121 | mOwner = os; | 122 | mOwner = os; |
122 | i = mOwner.find(','); | 123 | i = mOwner.find(','); |
123 | if (i != -1) | 124 | if (i != -1) |
124 | mOwner = mOwner.left(i); | 125 | mOwner = mOwner.left(i); |
125 | 126 | ||
126 | setModified( true ); | 127 | setModified( true ); |
127 | } | 128 | } |
128 | 129 | ||
@@ -154,193 +155,207 @@ QString Calendar::getTimeZoneStr() const | |||
154 | if (mLocalTime) | 155 | if (mLocalTime) |
155 | return ""; | 156 | return ""; |
156 | QString tmpStr; | 157 | QString tmpStr; |
157 | int hours = abs(mTimeZone / 60); | 158 | int hours = abs(mTimeZone / 60); |
158 | int minutes = abs(mTimeZone % 60); | 159 | int minutes = abs(mTimeZone % 60); |
159 | bool neg = mTimeZone < 0; | 160 | bool neg = mTimeZone < 0; |
160 | 161 | ||
161 | tmpStr.sprintf("%c%.2d%.2d", | 162 | tmpStr.sprintf("%c%.2d%.2d", |
162 | (neg ? '-' : '+'), | 163 | (neg ? '-' : '+'), |
163 | hours, minutes); | 164 | hours, minutes); |
164 | return tmpStr; | 165 | return tmpStr; |
165 | } | 166 | } |
166 | 167 | ||
167 | void Calendar::setTimeZone(int tz) | 168 | void Calendar::setTimeZone(int tz) |
168 | { | 169 | { |
169 | mTimeZone = tz; | 170 | mTimeZone = tz; |
170 | mLocalTime = false; | 171 | mLocalTime = false; |
171 | 172 | ||
172 | setModified( true ); | 173 | setModified( true ); |
173 | } | 174 | } |
174 | 175 | ||
175 | int Calendar::getTimeZone() const | 176 | int Calendar::getTimeZone() const |
176 | { | 177 | { |
177 | return mTimeZone; | 178 | return mTimeZone; |
178 | } | 179 | } |
179 | 180 | ||
180 | void Calendar::setTimeZoneId(const QString &id) | 181 | void Calendar::setTimeZoneId(const QString &id) |
181 | { | 182 | { |
182 | mTimeZoneId = id; | 183 | mTimeZoneId = id; |
183 | mLocalTime = false; | 184 | mLocalTime = false; |
184 | mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId); | 185 | mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId); |
185 | if ( mTimeZone > 1000) | 186 | if ( mTimeZone > 1000) |
186 | setLocalTime(); | 187 | setLocalTime(); |
187 | //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone); | 188 | //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone); |
188 | setModified( true ); | 189 | setModified( true ); |
189 | } | 190 | } |
190 | 191 | ||
191 | QString Calendar::timeZoneId() const | 192 | QString Calendar::timeZoneId() const |
192 | { | 193 | { |
193 | return mTimeZoneId; | 194 | return mTimeZoneId; |
194 | } | 195 | } |
195 | 196 | ||
196 | void Calendar::setLocalTime() | 197 | void Calendar::setLocalTime() |
197 | { | 198 | { |
198 | //qDebug("Calendar::setLocalTime() "); | 199 | //qDebug("Calendar::setLocalTime() "); |
199 | mLocalTime = true; | 200 | mLocalTime = true; |
200 | mTimeZone = 0; | 201 | mTimeZone = 0; |
201 | mTimeZoneId = ""; | 202 | mTimeZoneId = ""; |
202 | 203 | ||
203 | setModified( true ); | 204 | setModified( true ); |
204 | } | 205 | } |
205 | 206 | ||
206 | bool Calendar::isLocalTime() const | 207 | bool Calendar::isLocalTime() const |
207 | { | 208 | { |
208 | return mLocalTime; | 209 | return mLocalTime; |
209 | } | 210 | } |
210 | 211 | ||
211 | const QString &Calendar::getEmail() | 212 | const QString &Calendar::getEmail() |
212 | { | 213 | { |
213 | return mOwnerEmail; | 214 | return mOwnerEmail; |
214 | } | 215 | } |
215 | 216 | ||
216 | void Calendar::setEmail(const QString &e) | 217 | void Calendar::setEmail(const QString &e) |
217 | { | 218 | { |
218 | mOwnerEmail = e; | 219 | mOwnerEmail = e; |
219 | 220 | ||
220 | setModified( true ); | 221 | setModified( true ); |
221 | } | 222 | } |
222 | 223 | ||
223 | void Calendar::setFilter(CalFilter *filter) | 224 | void Calendar::setFilter(CalFilter *filter) |
224 | { | 225 | { |
225 | mFilter = filter; | 226 | mFilter = filter; |
226 | } | 227 | } |
227 | 228 | ||
228 | CalFilter *Calendar::filter() | 229 | CalFilter *Calendar::filter() |
229 | { | 230 | { |
230 | return mFilter; | 231 | return mFilter; |
231 | } | 232 | } |
232 | 233 | ||
233 | QPtrList<Incidence> Calendar::incidences() | 234 | QPtrList<Incidence> Calendar::incidences() |
234 | { | 235 | { |
235 | QPtrList<Incidence> incidences; | 236 | QPtrList<Incidence> incidences; |
236 | 237 | ||
237 | Incidence *i; | 238 | Incidence *i; |
238 | 239 | ||
239 | QPtrList<Event> e = events(); | 240 | QPtrList<Event> e = events(); |
240 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); | 241 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); |
241 | 242 | ||
242 | QPtrList<Todo> t = todos(); | 243 | QPtrList<Todo> t = todos(); |
243 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); | 244 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); |
244 | 245 | ||
245 | QPtrList<Journal> j = journals(); | 246 | QPtrList<Journal> j = journals(); |
246 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); | 247 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); |
247 | 248 | ||
248 | return incidences; | 249 | return incidences; |
249 | } | 250 | } |
251 | void Calendar::resetTempSyncStat() | ||
252 | { | ||
253 | QPtrList<Incidence> incidences; | ||
254 | |||
255 | Incidence *i; | ||
256 | |||
257 | QPtrList<Event> e = rawEvents(); | ||
258 | for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | ||
250 | 259 | ||
260 | QPtrList<Todo> t = rawTodos(); | ||
261 | for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | ||
262 | |||
263 | QPtrList<Journal> j = journals(); | ||
264 | for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | ||
265 | } | ||
251 | QPtrList<Incidence> Calendar::rawIncidences() | 266 | QPtrList<Incidence> Calendar::rawIncidences() |
252 | { | 267 | { |
253 | QPtrList<Incidence> incidences; | 268 | QPtrList<Incidence> incidences; |
254 | 269 | ||
255 | Incidence *i; | 270 | Incidence *i; |
256 | 271 | ||
257 | QPtrList<Event> e = rawEvents(); | 272 | QPtrList<Event> e = rawEvents(); |
258 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); | 273 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); |
259 | 274 | ||
260 | QPtrList<Todo> t = rawTodos(); | 275 | QPtrList<Todo> t = rawTodos(); |
261 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); | 276 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); |
262 | 277 | ||
263 | QPtrList<Journal> j = journals(); | 278 | QPtrList<Journal> j = journals(); |
264 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); | 279 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); |
265 | 280 | ||
266 | return incidences; | 281 | return incidences; |
267 | } | 282 | } |
268 | 283 | ||
269 | QPtrList<Event> Calendar::events( const QDate &date, bool sorted ) | 284 | QPtrList<Event> Calendar::events( const QDate &date, bool sorted ) |
270 | { | 285 | { |
271 | QPtrList<Event> el = rawEventsForDate(date,sorted); | 286 | QPtrList<Event> el = rawEventsForDate(date,sorted); |
272 | mFilter->apply(&el); | 287 | mFilter->apply(&el); |
273 | return el; | 288 | return el; |
274 | } | 289 | } |
275 | 290 | ||
276 | QPtrList<Event> Calendar::events( const QDateTime &qdt ) | 291 | QPtrList<Event> Calendar::events( const QDateTime &qdt ) |
277 | { | 292 | { |
278 | QPtrList<Event> el = rawEventsForDate(qdt); | 293 | QPtrList<Event> el = rawEventsForDate(qdt); |
279 | mFilter->apply(&el); | 294 | mFilter->apply(&el); |
280 | return el; | 295 | return el; |
281 | } | 296 | } |
282 | 297 | ||
283 | QPtrList<Event> Calendar::events( const QDate &start, const QDate &end, | 298 | QPtrList<Event> Calendar::events( const QDate &start, const QDate &end, |
284 | bool inclusive) | 299 | bool inclusive) |
285 | { | 300 | { |
286 | QPtrList<Event> el = rawEvents(start,end,inclusive); | 301 | QPtrList<Event> el = rawEvents(start,end,inclusive); |
287 | mFilter->apply(&el); | 302 | mFilter->apply(&el); |
288 | return el; | 303 | return el; |
289 | } | 304 | } |
290 | 305 | ||
291 | QPtrList<Event> Calendar::events() | 306 | QPtrList<Event> Calendar::events() |
292 | { | 307 | { |
293 | QPtrList<Event> el = rawEvents(); | 308 | QPtrList<Event> el = rawEvents(); |
294 | mFilter->apply(&el); | 309 | mFilter->apply(&el); |
295 | return el; | 310 | return el; |
296 | } | 311 | } |
297 | 312 | ||
298 | 313 | ||
299 | bool Calendar::addIncidence(Incidence *i) | 314 | bool Calendar::addIncidence(Incidence *i) |
300 | { | 315 | { |
301 | Incidence::AddVisitor<Calendar> v(this); | 316 | Incidence::AddVisitor<Calendar> v(this); |
302 | 317 | ||
303 | return i->accept(v); | 318 | return i->accept(v); |
304 | } | 319 | } |
305 | void Calendar::deleteIncidence(Incidence *in) | 320 | void Calendar::deleteIncidence(Incidence *in) |
306 | { | 321 | { |
307 | if ( in->type() == "Event" ) | 322 | if ( in->type() == "Event" ) |
308 | deleteEvent( (Event*) in ); | 323 | deleteEvent( (Event*) in ); |
309 | else if ( in->type() =="Todo" ) | 324 | else if ( in->type() =="Todo" ) |
310 | deleteTodo( (Todo*) in); | 325 | deleteTodo( (Todo*) in); |
311 | else if ( in->type() =="Journal" ) | 326 | else if ( in->type() =="Journal" ) |
312 | deleteJournal( (Journal*) in ); | 327 | deleteJournal( (Journal*) in ); |
313 | } | 328 | } |
314 | 329 | ||
315 | Incidence* Calendar::incidence( const QString& uid ) | 330 | Incidence* Calendar::incidence( const QString& uid ) |
316 | { | 331 | { |
317 | Incidence* i; | 332 | Incidence* i; |
318 | 333 | ||
319 | if( (i = todo( uid )) != 0 ) | 334 | if( (i = todo( uid )) != 0 ) |
320 | return i; | 335 | return i; |
321 | if( (i = event( uid )) != 0 ) | 336 | if( (i = event( uid )) != 0 ) |
322 | return i; | 337 | return i; |
323 | if( (i = journal( uid )) != 0 ) | 338 | if( (i = journal( uid )) != 0 ) |
324 | return i; | 339 | return i; |
325 | 340 | ||
326 | return 0; | 341 | return 0; |
327 | } | 342 | } |
328 | 343 | ||
329 | QPtrList<Todo> Calendar::todos() | 344 | QPtrList<Todo> Calendar::todos() |
330 | { | 345 | { |
331 | QPtrList<Todo> tl = rawTodos(); | 346 | QPtrList<Todo> tl = rawTodos(); |
332 | mFilter->apply( &tl ); | 347 | mFilter->apply( &tl ); |
333 | return tl; | 348 | return tl; |
334 | } | 349 | } |
335 | 350 | ||
336 | // When this is called, the todo have already been added to the calendar. | 351 | // When this is called, the todo have already been added to the calendar. |
337 | // This method is only about linking related todos | 352 | // This method is only about linking related todos |
338 | void Calendar::setupRelations( Incidence *incidence ) | 353 | void Calendar::setupRelations( Incidence *incidence ) |
339 | { | 354 | { |
340 | QString uid = incidence->uid(); | 355 | QString uid = incidence->uid(); |
341 | //qDebug("Calendar::setupRelations "); | 356 | //qDebug("Calendar::setupRelations "); |
342 | // First, go over the list of orphans and see if this is their parent | 357 | // First, go over the list of orphans and see if this is their parent |
343 | while( Incidence* i = mOrphans[ uid ] ) { | 358 | while( Incidence* i = mOrphans[ uid ] ) { |
344 | mOrphans.remove( uid ); | 359 | mOrphans.remove( uid ); |
345 | i->setRelatedTo( incidence ); | 360 | i->setRelatedTo( incidence ); |
346 | incidence->addRelation( i ); | 361 | incidence->addRelation( i ); |