summaryrefslogtreecommitdiffabout
path: root/libkcal/calendar.cpp
authorzautrix <zautrix>2005-11-25 23:24:37 (UTC)
committer zautrix <zautrix>2005-11-25 23:24:37 (UTC)
commit3cd0013c04172b312ee21e80224a3b7734b4d413 (patch) (unidiff)
tree9c5557ecfe874a8a4901a674c5eddcc91f585b0c /libkcal/calendar.cpp
parent0e18027f386280bf427ef9d0ffec61a5516cebda (diff)
downloadkdepimpi-3cd0013c04172b312ee21e80224a3b7734b4d413.zip
kdepimpi-3cd0013c04172b312ee21e80224a3b7734b4d413.tar.gz
kdepimpi-3cd0013c04172b312ee21e80224a3b7734b4d413.tar.bz2
sync
Diffstat (limited to 'libkcal/calendar.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/calendar.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp
index b1806ee..8535191 100644
--- a/libkcal/calendar.cpp
+++ b/libkcal/calendar.cpp
@@ -1,523 +1,523 @@
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
35using namespace KCal; 35using namespace KCal;
36 36
37Calendar::Calendar() 37Calendar::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
44Calendar::Calendar( const QString &timeZoneId ) 44Calendar::Calendar( const QString &timeZoneId )
45{ 45{
46 46
47 init(); 47 init();
48 setTimeZoneId(timeZoneId); 48 setTimeZoneId(timeZoneId);
49} 49}
50 50
51void Calendar::init() 51void 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
110Calendar::~Calendar() 110Calendar::~Calendar()
111{ 111{
112 delete mDefaultFilter; 112 delete mDefaultFilter;
113 clearUndo( 0 ); 113 clearUndo( 0 );
114} 114}
115void Calendar::clearUndo( Incidence * newUndo ) 115void Calendar::clearUndo( Incidence * newUndo )
116{ 116{
117 117
118 if ( mUndoIncidence ) { 118 if ( mUndoIncidence ) {
119 if ( mUndoIncidence->typeID() == eventID ) 119 if ( mUndoIncidence->typeID() == eventID )
120 delete ((Event*) mUndoIncidence) ; 120 delete ((Event*) mUndoIncidence) ;
121 else if ( mUndoIncidence->typeID() == todoID ) 121 else if ( mUndoIncidence->typeID() == todoID )
122 delete ( (Todo*) mUndoIncidence ); 122 delete ( (Todo*) mUndoIncidence );
123 else if ( mUndoIncidence->typeID() == journalID ) 123 else if ( mUndoIncidence->typeID() == journalID )
124 delete ( (Journal*) mUndoIncidence ); 124 delete ( (Journal*) mUndoIncidence );
125 else 125 else
126 delete mUndoIncidence; 126 delete mUndoIncidence;
127 } 127 }
128 mUndoIncidence = newUndo; 128 mUndoIncidence = newUndo;
129 if ( mUndoIncidence ) { 129 if ( mUndoIncidence ) {
130 mUndoIncidence->clearRelations(); 130 mUndoIncidence->clearRelations();
131 } 131 }
132 132
133} 133}
134 134
135void Calendar::setDontDeleteIncidencesOnClose () 135void Calendar::setDontDeleteIncidencesOnClose ()
136{ 136{
137 mDeleteIncidencesOnClose = false; 137 mDeleteIncidencesOnClose = false;
138} 138}
139void Calendar::setDefaultCalendar( int d ) 139void Calendar::setDefaultCalendar( int d )
140{ 140{
141 mDefaultCalendar = d; 141 mDefaultCalendar = d;
142} 142}
143int Calendar::defaultCalendar() 143int Calendar::defaultCalendar()
144{ 144{
145 return mDefaultCalendar; 145 return mDefaultCalendar;
146} 146}
147const QString &Calendar::getOwner() const 147const QString &Calendar::getOwner() const
148{ 148{
149 return mOwner; 149 return mOwner;
150} 150}
151 151
152bool Calendar::undoDeleteIncidence() 152bool Calendar::undoDeleteIncidence()
153{ 153{
154 if (!mUndoIncidence) 154 if (!mUndoIncidence)
155 return false; 155 return false;
156 addIncidence(mUndoIncidence); 156 addIncidence(mUndoIncidence);
157 mUndoIncidence = 0; 157 mUndoIncidence = 0;
158 return true; 158 return true;
159} 159}
160void Calendar::setOwner(const QString &os) 160void Calendar::setOwner(const QString &os)
161{ 161{
162 int i; 162 int i;
163 mOwner = os; 163 mOwner = os;
164 i = mOwner.find(','); 164 i = mOwner.find(',');
165 if (i != -1) 165 if (i != -1)
166 mOwner = mOwner.left(i); 166 mOwner = mOwner.left(i);
167 167
168 setModified( true ); 168 setModified( true );
169} 169}
170 170
171void Calendar::setTimeZone(const QString & tz) 171void Calendar::setTimeZone(const QString & tz)
172{ 172{
173 bool neg = FALSE; 173 bool neg = FALSE;
174 int hours, minutes; 174 int hours, minutes;
175 QString tmpStr(tz); 175 QString tmpStr(tz);
176 176
177 if (tmpStr.left(1) == "-") 177 if (tmpStr.left(1) == "-")
178 neg = TRUE; 178 neg = TRUE;
179 if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+") 179 if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+")
180 tmpStr.remove(0, 1); 180 tmpStr.remove(0, 1);
181 hours = tmpStr.left(2).toInt(); 181 hours = tmpStr.left(2).toInt();
182 if (tmpStr.length() > 2) 182 if (tmpStr.length() > 2)
183 minutes = tmpStr.right(2).toInt(); 183 minutes = tmpStr.right(2).toInt();
184 else 184 else
185 minutes = 0; 185 minutes = 0;
186 mTimeZone = (60*hours+minutes); 186 mTimeZone = (60*hours+minutes);
187 if (neg) 187 if (neg)
188 mTimeZone = -mTimeZone; 188 mTimeZone = -mTimeZone;
189 mLocalTime = false; 189 mLocalTime = false;
190 190
191 setModified( true ); 191 setModified( true );
192} 192}
193 193
194QString Calendar::getTimeZoneStr() const 194QString Calendar::getTimeZoneStr() const
195{ 195{
196 if (mLocalTime) 196 if (mLocalTime)
197 return ""; 197 return "";
198 QString tmpStr; 198 QString tmpStr;
199 int hours = abs(mTimeZone / 60); 199 int hours = abs(mTimeZone / 60);
200 int minutes = abs(mTimeZone % 60); 200 int minutes = abs(mTimeZone % 60);
201 bool neg = mTimeZone < 0; 201 bool neg = mTimeZone < 0;
202 202
203 tmpStr.sprintf("%c%.2d%.2d", 203 tmpStr.sprintf("%c%.2d%.2d",
204 (neg ? '-' : '+'), 204 (neg ? '-' : '+'),
205 hours, minutes); 205 hours, minutes);
206 return tmpStr; 206 return tmpStr;
207} 207}
208 208
209void Calendar::setTimeZone(int tz) 209void Calendar::setTimeZone(int tz)
210{ 210{
211 mTimeZone = tz; 211 mTimeZone = tz;
212 mLocalTime = false; 212 mLocalTime = false;
213 213
214 setModified( true ); 214 setModified( true );
215} 215}
216 216
217int Calendar::getTimeZone() const 217int Calendar::getTimeZone() const
218{ 218{
219 return mTimeZone; 219 return mTimeZone;
220} 220}
221 221
222void Calendar::setTimeZoneId(const QString &id) 222void Calendar::setTimeZoneId(const QString &id)
223{ 223{
224 mTimeZoneId = id; 224 mTimeZoneId = id;
225 mLocalTime = false; 225 mLocalTime = false;
226 mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId); 226 mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId);
227 if ( mTimeZone > 1000) 227 if ( mTimeZone > 1000)
228 setLocalTime(); 228 setLocalTime();
229 //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone); 229 //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone);
230 setModified( true ); 230 setModified( true );
231} 231}
232 232
233QString Calendar::timeZoneId() const 233QString Calendar::timeZoneId() const
234{ 234{
235 return mTimeZoneId; 235 return mTimeZoneId;
236} 236}
237 237
238void Calendar::setLocalTime() 238void Calendar::setLocalTime()
239{ 239{
240 //qDebug("Calendar::setLocalTime() "); 240 //qDebug("Calendar::setLocalTime() ");
241 mLocalTime = true; 241 mLocalTime = true;
242 mTimeZone = 0; 242 mTimeZone = 0;
243 mTimeZoneId = ""; 243 mTimeZoneId = "";
244 244
245 setModified( true ); 245 setModified( true );
246} 246}
247 247
248bool Calendar::isLocalTime() const 248bool Calendar::isLocalTime() const
249{ 249{
250 return mLocalTime; 250 return mLocalTime;
251} 251}
252 252
253const QString &Calendar::getEmail() 253const QString &Calendar::getEmail()
254{ 254{
255 return mOwnerEmail; 255 return mOwnerEmail;
256} 256}
257 257
258void Calendar::setEmail(const QString &e) 258void Calendar::setEmail(const QString &e)
259{ 259{
260 mOwnerEmail = e; 260 mOwnerEmail = e;
261 261
262 setModified( true ); 262 setModified( true );
263} 263}
264 264
265void Calendar::setFilter(CalFilter *filter) 265void Calendar::setFilter(CalFilter *filter)
266{ 266{
267 mFilter = filter; 267 mFilter = filter;
268} 268}
269 269
270CalFilter *Calendar::filter() 270CalFilter *Calendar::filter()
271{ 271{
272 return mFilter; 272 return mFilter;
273} 273}
274 274
275QPtrList<Incidence> Calendar::incidences() 275QPtrList<Incidence> Calendar::incidences()
276{ 276{
277 QPtrList<Incidence> incidences; 277 QPtrList<Incidence> incidences;
278 278
279 Incidence *i; 279 Incidence *i;
280 280
281 QPtrList<Event> e = events(); 281 QPtrList<Event> e = events();
282 for( i = e.first(); i; i = e.next() ) incidences.append( i ); 282 for( i = e.first(); i; i = e.next() ) incidences.append( i );
283 283
284 QPtrList<Todo> t = todos(); 284 QPtrList<Todo> t = todos();
285 for( i = t.first(); i; i = t.next() ) incidences.append( i ); 285 for( i = t.first(); i; i = t.next() ) incidences.append( i );
286 286
287 QPtrList<Journal> j = journals(); 287 QPtrList<Journal> j = journals();
288 for( i = j.first(); i; i = j.next() ) incidences.append( i ); 288 for( i = j.first(); i; i = j.next() ) incidences.append( i );
289 289
290 return incidences; 290 return incidences;
291} 291}
292 292
293void Calendar::resetPilotStat(int id ) 293void Calendar::resetPilotStat(int id )
294{ 294{
295 QPtrList<Incidence> incidences; 295 QPtrList<Incidence> incidences;
296 296
297 Incidence *i; 297 Incidence *i;
298 298
299 QPtrList<Event> e = rawEvents(); 299 QPtrList<Event> e = rawEvents();
300 for( i = e.first(); i; i = e.next() ) i->setPilotId( id ); 300 for( i = e.first(); i; i = e.next() ) i->setPilotId( id );
301 301
302 QPtrList<Todo> t = rawTodos(); 302 QPtrList<Todo> t = rawTodos();
303 for( i = t.first(); i; i = t.next() ) i->setPilotId( id ); 303 for( i = t.first(); i; i = t.next() ) i->setPilotId( id );
304 304
305 QPtrList<Journal> j = journals(); 305 QPtrList<Journal> j = journals();
306 for( i = j.first(); i; i = j.next() ) i->setPilotId( id ); 306 for( i = j.first(); i; i = j.next() ) i->setPilotId( id );
307} 307}
308void Calendar::resetTempSyncStat() 308void Calendar::resetTempSyncStat()
309{ 309{
310 QPtrList<Incidence> incidences; 310 QPtrList<Incidence> incidences;
311 311
312 Incidence *i; 312 Incidence *i;
313 313
314 QPtrList<Event> e = rawEvents(); 314 QPtrList<Event> e = rawEvents();
315 for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 315 for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
316 316
317 QPtrList<Todo> t = rawTodos(); 317 QPtrList<Todo> t = rawTodos();
318 for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 318 for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
319 319
320 QPtrList<Journal> j = journals(); 320 QPtrList<Journal> j = journals();
321 for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 321 for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
322} 322}
323QPtrList<Incidence> Calendar::rawIncidences() 323QPtrList<Incidence> Calendar::rawIncidences()
324{ 324{
325 QPtrList<Incidence> incidences; 325 QPtrList<Incidence> incidences;
326 326
327 Incidence *i; 327 Incidence *i;
328 328
329 QPtrList<Event> e = rawEvents(); 329 QPtrList<Event> e = rawEvents();
330 for( i = e.first(); i; i = e.next() ) incidences.append( i ); 330 for( i = e.first(); i; i = e.next() ) incidences.append( i );
331 331
332 QPtrList<Todo> t = rawTodos(); 332 QPtrList<Todo> t = rawTodos();
333 for( i = t.first(); i; i = t.next() ) incidences.append( i ); 333 for( i = t.first(); i; i = t.next() ) incidences.append( i );
334 334
335 QPtrList<Journal> j = journals(); 335 QPtrList<Journal> j = journals();
336 for( i = j.first(); i; i = j.next() ) incidences.append( i ); 336 for( i = j.first(); i; i = j.next() ) incidences.append( i );
337 337
338 return incidences; 338 return incidences;
339} 339}
340 340
341QPtrList<Event> Calendar::events( const QDate &date, bool sorted ) 341QPtrList<Event> Calendar::events( const QDate &date, bool sorted )
342{ 342{
343 QPtrList<Event> el = rawEventsForDate(date,sorted); 343 QPtrList<Event> el = rawEventsForDate(date,sorted);
344 mFilter->apply(&el); 344 mFilter->apply(&el);
345 return el; 345 return el;
346} 346}
347 347
348QPtrList<Event> Calendar::events( const QDateTime &qdt ) 348QPtrList<Event> Calendar::events( const QDateTime &qdt )
349{ 349{
350 QPtrList<Event> el = rawEventsForDate(qdt); 350 QPtrList<Event> el = rawEventsForDate(qdt);
351 mFilter->apply(&el); 351 mFilter->apply(&el);
352 return el; 352 return el;
353} 353}
354 354
355QPtrList<Event> Calendar::events( const QDate &start, const QDate &end, 355QPtrList<Event> Calendar::events( const QDate &start, const QDate &end,
356 bool inclusive) 356 bool inclusive)
357{ 357{
358 QPtrList<Event> el = rawEvents(start,end,inclusive); 358 QPtrList<Event> el = rawEvents(start,end,inclusive);
359 mFilter->apply(&el); 359 mFilter->apply(&el);
360 return el; 360 return el;
361} 361}
362 362
363QPtrList<Event> Calendar::events() 363QPtrList<Event> Calendar::events()
364{ 364{
365 QPtrList<Event> el = rawEvents(); 365 QPtrList<Event> el = rawEvents();
366 mFilter->apply(&el); 366 mFilter->apply(&el);
367 return el; 367 return el;
368} 368}
369void Calendar::addIncidenceBranch(Incidence *i) 369void Calendar::addIncidenceBranch(Incidence *i)
370{ 370{
371 addIncidence( i ); 371 addIncidence( i );
372 Incidence * inc; 372 Incidence * inc;
373 QPtrList<Incidence> Relations = i->relations(); 373 QPtrList<Incidence> Relations = i->relations();
374 for (inc=Relations.first();inc;inc=Relations.next()) { 374 for (inc=Relations.first();inc;inc=Relations.next()) {
375 addIncidenceBranch( inc ); 375 addIncidenceBranch( inc );
376 } 376 }
377} 377}
378 378
379bool Calendar::addIncidence(Incidence *i) 379bool Calendar::addIncidence(Incidence *i)
380{ 380{
381 Incidence::AddVisitor<Calendar> v(this); 381 Incidence::AddVisitor<Calendar> v(this);
382 if ( i->calID() == 0 ) 382 if ( i->calID() == 0 )
383 i->setCalID( mDefaultCalendar ); 383 i->setCalID_block( mDefaultCalendar );
384 i->setCalEnabled( true ); 384 i->setCalEnabled( true );
385 return i->accept(v); 385 return i->accept(v);
386} 386}
387void Calendar::deleteIncidence(Incidence *in) 387void Calendar::deleteIncidence(Incidence *in)
388{ 388{
389 if ( in->typeID() == eventID ) 389 if ( in->typeID() == eventID )
390 deleteEvent( (Event*) in ); 390 deleteEvent( (Event*) in );
391 else if ( in->typeID() == todoID ) 391 else if ( in->typeID() == todoID )
392 deleteTodo( (Todo*) in); 392 deleteTodo( (Todo*) in);
393 else if ( in->typeID() == journalID ) 393 else if ( in->typeID() == journalID )
394 deleteJournal( (Journal*) in ); 394 deleteJournal( (Journal*) in );
395} 395}
396 396
397Incidence* Calendar::incidence( const QString& uid ) 397Incidence* Calendar::incidence( const QString& uid )
398{ 398{
399 Incidence* i; 399 Incidence* i;
400 400
401 if( (i = todo( uid )) != 0 ) 401 if( (i = todo( uid )) != 0 )
402 return i; 402 return i;
403 if( (i = event( uid )) != 0 ) 403 if( (i = event( uid )) != 0 )
404 return i; 404 return i;
405 if( (i = journal( uid )) != 0 ) 405 if( (i = journal( uid )) != 0 )
406 return i; 406 return i;
407 407
408 return 0; 408 return 0;
409} 409}
410 410
411QPtrList<Todo> Calendar::todos() 411QPtrList<Todo> Calendar::todos()
412{ 412{
413 QPtrList<Todo> tl = rawTodos(); 413 QPtrList<Todo> tl = rawTodos();
414 mFilter->apply( &tl ); 414 mFilter->apply( &tl );
415 return tl; 415 return tl;
416} 416}
417 417
418// When this is called, the todo have already been added to the calendar. 418// When this is called, the todo have already been added to the calendar.
419// This method is only about linking related todos 419// This method is only about linking related todos
420void Calendar::setupRelations( Incidence *incidence ) 420void Calendar::setupRelations( Incidence *incidence )
421{ 421{
422 QString uid = incidence->uid(); 422 QString uid = incidence->uid();
423 //qDebug("Calendar::setupRelations "); 423 //qDebug("Calendar::setupRelations ");
424 // First, go over the list of orphans and see if this is their parent 424 // First, go over the list of orphans and see if this is their parent
425 while( Incidence* i = mOrphans[ uid ] ) { 425 while( Incidence* i = mOrphans[ uid ] ) {
426 mOrphans.remove( uid ); 426 mOrphans.remove( uid );
427 i->setRelatedTo( incidence ); 427 i->setRelatedTo( incidence );
428 incidence->addRelation( i ); 428 incidence->addRelation( i );
429 mOrphanUids.remove( i->uid() ); 429 mOrphanUids.remove( i->uid() );
430 } 430 }
431 431
432 // Now see about this incidences parent 432 // Now see about this incidences parent
433 if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) { 433 if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) {
434 // This incidence has a uid it is related to, but is not registered to it yet 434 // This incidence has a uid it is related to, but is not registered to it yet
435 // Try to find it 435 // Try to find it
436 Incidence* parent = this->incidence( incidence->relatedToUid() ); 436 Incidence* parent = this->incidence( incidence->relatedToUid() );
437 if( parent ) { 437 if( parent ) {
438 // Found it 438 // Found it
439 incidence->setRelatedTo( parent ); 439 incidence->setRelatedTo( parent );
440 parent->addRelation( incidence ); 440 parent->addRelation( incidence );
441 } else { 441 } else {
442 // Not found, put this in the mOrphans list 442 // Not found, put this in the mOrphans list
443 mOrphans.insert( incidence->relatedToUid(), incidence ); 443 mOrphans.insert( incidence->relatedToUid(), incidence );
444 mOrphanUids.insert( incidence->uid(), incidence ); 444 mOrphanUids.insert( incidence->uid(), incidence );
445 } 445 }
446 } 446 }
447} 447}
448 448
449// If a task with subtasks is deleted, move it's subtasks to the orphans list 449// If a task with subtasks is deleted, move it's subtasks to the orphans list
450void Calendar::removeRelations( Incidence *incidence ) 450void Calendar::removeRelations( Incidence *incidence )
451{ 451{
452 // qDebug("Calendar::removeRelations "); 452 // qDebug("Calendar::removeRelations ");
453 QString uid = incidence->uid(); 453 QString uid = incidence->uid();
454 454
455 QPtrList<Incidence> relations = incidence->relations(); 455 QPtrList<Incidence> relations = incidence->relations();
456 for( Incidence* i = relations.first(); i; i = relations.next() ) 456 for( Incidence* i = relations.first(); i; i = relations.next() )
457 if( !mOrphanUids.find( i->uid() ) ) { 457 if( !mOrphanUids.find( i->uid() ) ) {
458 mOrphans.insert( uid, i ); 458 mOrphans.insert( uid, i );
459 mOrphanUids.insert( i->uid(), i ); 459 mOrphanUids.insert( i->uid(), i );
460 i->setRelatedTo( 0 ); 460 i->setRelatedTo( 0 );
461 i->setRelatedToUid( uid ); 461 i->setRelatedToUid( uid );
462 } 462 }
463 463
464 // If this incidence is related to something else, tell that about it 464 // If this incidence is related to something else, tell that about it
465 if( incidence->relatedTo() ) 465 if( incidence->relatedTo() )
466 incidence->relatedTo()->removeRelation( incidence ); 466 incidence->relatedTo()->removeRelation( incidence );
467 467
468 // Remove this one from the orphans list 468 // Remove this one from the orphans list
469 if( mOrphanUids.remove( uid ) ) { 469 if( mOrphanUids.remove( uid ) ) {
470 QString r2uid = incidence->relatedToUid(); 470 QString r2uid = incidence->relatedToUid();
471 QPtrList<Incidence> tempList; 471 QPtrList<Incidence> tempList;
472 while( Incidence* i = mOrphans[ r2uid ] ) { 472 while( Incidence* i = mOrphans[ r2uid ] ) {
473 mOrphans.remove( r2uid ); 473 mOrphans.remove( r2uid );
474 if ( i != incidence ) tempList.append( i ); 474 if ( i != incidence ) tempList.append( i );
475 } 475 }
476 Incidence* inc = tempList.first(); 476 Incidence* inc = tempList.first();
477 while ( inc ) { 477 while ( inc ) {
478 mOrphans.insert( r2uid, inc ); 478 mOrphans.insert( r2uid, inc );
479 inc = tempList.next(); 479 inc = tempList.next();
480 } 480 }
481 } 481 }
482 // LR: and another big bad bug found 482 // LR: and another big bad bug found
483#if 0 483#if 0
484 // This incidence is located in the orphans list - it should be removed 484 // This incidence is located in the orphans list - it should be removed
485 if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) { 485 if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) {
486 // Removing wasn't that easy 486 // Removing wasn't that easy
487 for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) { 487 for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) {
488 if( it.current()->uid() == uid ) { 488 if( it.current()->uid() == uid ) {
489 mOrphans.remove( it.currentKey() ); 489 mOrphans.remove( it.currentKey() );
490 break; 490 break;
491 } 491 }
492 } 492 }
493 } 493 }
494#endif 494#endif
495} 495}
496 496
497void Calendar::registerObserver( Observer *observer ) 497void Calendar::registerObserver( Observer *observer )
498{ 498{
499 mObserver = observer; 499 mObserver = observer;
500 mNewObserver = true; 500 mNewObserver = true;
501} 501}
502 502
503void Calendar::setModified( bool modified ) 503void Calendar::setModified( bool modified )
504{ 504{
505 if ( mObserver ) mObserver->calendarModified( modified, this ); 505 if ( mObserver ) mObserver->calendarModified( modified, this );
506 if ( modified != mModified || mNewObserver ) { 506 if ( modified != mModified || mNewObserver ) {
507 mNewObserver = false; 507 mNewObserver = false;
508 // if ( mObserver ) mObserver->calendarModified( modified, this ); 508 // if ( mObserver ) mObserver->calendarModified( modified, this );
509 mModified = modified; 509 mModified = modified;
510 } 510 }
511} 511}
512 512
513void Calendar::setLoadedProductId( const QString &id ) 513void Calendar::setLoadedProductId( const QString &id )
514{ 514{
515 mLoadedProductId = id; 515 mLoadedProductId = id;
516} 516}
517 517
518QString Calendar::loadedProductId() 518QString Calendar::loadedProductId()
519{ 519{
520 return mLoadedProductId; 520 return mLoadedProductId;
521} 521}
522 522
523//#include "calendar.moc" 523//#include "calendar.moc"