summaryrefslogtreecommitdiffabout
path: root/libkcal/calendar.cpp
Unidiff
Diffstat (limited to 'libkcal/calendar.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/calendar.cpp66
1 files changed, 34 insertions, 32 deletions
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp
index 9b38d3f..bf095cf 100644
--- a/libkcal/calendar.cpp
+++ b/libkcal/calendar.cpp
@@ -1,526 +1,528 @@
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 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21#include <stdlib.h> 21#include <stdlib.h>
22#include <time.h> 22#include <time.h>
23 23
24#include <kdebug.h> 24#include <kdebug.h>
25#include <kglobal.h> 25#include <kglobal.h>
26#include <klocale.h> 26#include <klocale.h>
27 27
28#include "exceptions.h" 28#include "exceptions.h"
29#include "calfilter.h" 29#include "calfilter.h"
30 30
31#include "calendar.h" 31#include "calendar.h"
32#include "syncdefines.h" 32#include "syncdefines.h"
33//Added by qt3to4:
34#include <Q3PtrList>
33 35
34using namespace KCal; 36using namespace KCal;
35 37
36Calendar::Calendar() 38Calendar::Calendar()
37{ 39{
38 40
39 init(); 41 init();
40 setTimeZoneId( " 00:00 Europe/London(UTC)" ); 42 setTimeZoneId( " 00:00 Europe/London(UTC)" );
41} 43}
42 44
43Calendar::Calendar( const QString &timeZoneId ) 45Calendar::Calendar( const QString &timeZoneId )
44{ 46{
45 47
46 init(); 48 init();
47 setTimeZoneId(timeZoneId); 49 setTimeZoneId(timeZoneId);
48} 50}
49 51
50void Calendar::init() 52void Calendar::init()
51{ 53{
52 mObserver = 0; 54 mObserver = 0;
53 mNewObserver = false; 55 mNewObserver = false;
54 mUndoIncidence = 0; 56 mUndoIncidence = 0;
55 mDeleteIncidencesOnClose = true; 57 mDeleteIncidencesOnClose = true;
56 mModified = false; 58 mModified = false;
57 mDefaultCalendar = 1; 59 mDefaultCalendar = 1;
58 // Setup default filter, which does nothing 60 // Setup default filter, which does nothing
59 mDefaultFilter = new CalFilter; 61 mDefaultFilter = new CalFilter;
60 mFilter = mDefaultFilter; 62 mFilter = mDefaultFilter;
61 mFilter->setEnabled(false); 63 mFilter->setEnabled(false);
62 64
63 // initialize random numbers. This is a hack, and not 65 // initialize random numbers. This is a hack, and not
64 // even that good of one at that. 66 // even that good of one at that.
65// srandom(time(0)); 67// srandom(time(0));
66 68
67 // user information... 69 // user information...
68 setOwner(i18n("Unknown Name")); 70 setOwner(i18n("Unknown Name"));
69 setEmail(i18n("unknown@nowhere")); 71 setEmail(i18n("unknown@nowhere"));
70 72
71#if 0 73#if 0
72 tmpStr = KOPrefs::instance()->mTimeZone; 74 tmpStr = KOPrefs::instance()->mTimeZone;
73// kdDebug(5800) << "Calendar::Calendar(): TimeZone: " << tmpStr << endl; 75// kdDebug(5800) << "Calendar::Calendar(): TimeZone: " << tmpStr << endl;
74 int dstSetting = KOPrefs::instance()->mDaylightSavings; 76 int dstSetting = KOPrefs::instance()->mDaylightSavings;
75 extern long int timezone; 77 extern long int timezone;
76 struct tm *now; 78 struct tm *now;
77 time_t curtime; 79 time_t curtime;
78 curtime = time(0); 80 curtime = time(0);
79 now = localtime(&curtime); 81 now = localtime(&curtime);
80 int hourOff = - ((timezone / 60) / 60); 82 int hourOff = - ((timezone / 60) / 60);
81 if (now->tm_isdst) 83 if (now->tm_isdst)
82 hourOff += 1; 84 hourOff += 1;
83 QString tzStr; 85 QString tzStr;
84 tzStr.sprintf("%.2d%.2d", 86 tzStr.sprintf("%.2d%.2d",
85 hourOff, 87 hourOff,
86 abs((timezone / 60) % 60)); 88 abs((timezone / 60) % 60));
87 89
88 // if no time zone was in the config file, write what we just discovered. 90 // if no time zone was in the config file, write what we just discovered.
89 if (tmpStr.isEmpty()) { 91 if (tmpStr.isEmpty()) {
90// KOPrefs::instance()->mTimeZone = tzStr; 92// KOPrefs::instance()->mTimeZone = tzStr;
91 } else { 93 } else {
92 tzStr = tmpStr; 94 tzStr = tmpStr;
93 } 95 }
94 96
95 // if daylight savings has changed since last load time, we need 97 // if daylight savings has changed since last load time, we need
96 // to rewrite these settings to the config file. 98 // to rewrite these settings to the config file.
97 if ((now->tm_isdst && !dstSetting) || 99 if ((now->tm_isdst && !dstSetting) ||
98 (!now->tm_isdst && dstSetting)) { 100 (!now->tm_isdst && dstSetting)) {
99 KOPrefs::instance()->mTimeZone = tzStr; 101 KOPrefs::instance()->mTimeZone = tzStr;
100 KOPrefs::instance()->mDaylightSavings = now->tm_isdst; 102 KOPrefs::instance()->mDaylightSavings = now->tm_isdst;
101 } 103 }
102 104
103 setTimeZone(tzStr); 105 setTimeZone(tzStr);
104#endif 106#endif
105 107
106// KOPrefs::instance()->writeConfig(); 108// KOPrefs::instance()->writeConfig();
107} 109}
108 110
109Calendar::~Calendar() 111Calendar::~Calendar()
110{ 112{
111 delete mDefaultFilter; 113 delete mDefaultFilter;
112 clearUndo( 0 ); 114 clearUndo( 0 );
113} 115}
114void Calendar::clearUndo( Incidence * newUndo ) 116void Calendar::clearUndo( Incidence * newUndo )
115{ 117{
116 118
117 if ( mUndoIncidence ) { 119 if ( mUndoIncidence ) {
118 if ( mUndoIncidence->typeID() == eventID ) 120 if ( mUndoIncidence->typeID() == eventID )
119 delete ((Event*) mUndoIncidence) ; 121 delete ((Event*) mUndoIncidence) ;
120 else if ( mUndoIncidence->typeID() == todoID ) 122 else if ( mUndoIncidence->typeID() == todoID )
121 delete ( (Todo*) mUndoIncidence ); 123 delete ( (Todo*) mUndoIncidence );
122 else if ( mUndoIncidence->typeID() == journalID ) 124 else if ( mUndoIncidence->typeID() == journalID )
123 delete ( (Journal*) mUndoIncidence ); 125 delete ( (Journal*) mUndoIncidence );
124 else 126 else
125 delete mUndoIncidence; 127 delete mUndoIncidence;
126 } 128 }
127 mUndoIncidence = newUndo; 129 mUndoIncidence = newUndo;
128 if ( mUndoIncidence ) { 130 if ( mUndoIncidence ) {
129 mUndoIncidence->clearRelations(); 131 mUndoIncidence->clearRelations();
130 } 132 }
131 133
132} 134}
133 135
134void Calendar::setDontDeleteIncidencesOnClose () 136void Calendar::setDontDeleteIncidencesOnClose ()
135{ 137{
136 mDeleteIncidencesOnClose = false; 138 mDeleteIncidencesOnClose = false;
137} 139}
138void Calendar::setDefaultCalendar( int d ) 140void Calendar::setDefaultCalendar( int d )
139{ 141{
140 mDefaultCalendar = d; 142 mDefaultCalendar = d;
141} 143}
142int Calendar::defaultCalendar() 144int Calendar::defaultCalendar()
143{ 145{
144 return mDefaultCalendar; 146 return mDefaultCalendar;
145} 147}
146const QString &Calendar::getOwner() const 148const QString &Calendar::getOwner() const
147{ 149{
148 return mOwner; 150 return mOwner;
149} 151}
150 152
151bool Calendar::undoDeleteIncidence() 153bool Calendar::undoDeleteIncidence()
152{ 154{
153 if (!mUndoIncidence) 155 if (!mUndoIncidence)
154 return false; 156 return false;
155 addIncidence(mUndoIncidence); 157 addIncidence(mUndoIncidence);
156 mUndoIncidence = 0; 158 mUndoIncidence = 0;
157 return true; 159 return true;
158} 160}
159void Calendar::setOwner(const QString &os) 161void Calendar::setOwner(const QString &os)
160{ 162{
161 int i; 163 int i;
162 mOwner = os; 164 mOwner = os;
163 i = mOwner.find(','); 165 i = mOwner.find(',');
164 if (i != -1) 166 if (i != -1)
165 mOwner = mOwner.left(i); 167 mOwner = mOwner.left(i);
166 168
167 setModified( true ); 169 setModified( true );
168} 170}
169 171
170void Calendar::setTimeZone(const QString & tz) 172void Calendar::setTimeZone(const QString & tz)
171{ 173{
172 bool neg = FALSE; 174 bool neg = FALSE;
173 int hours, minutes; 175 int hours, minutes;
174 QString tmpStr(tz); 176 QString tmpStr(tz);
175 177
176 if (tmpStr.left(1) == "-") 178 if (tmpStr.left(1) == "-")
177 neg = TRUE; 179 neg = TRUE;
178 if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+") 180 if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+")
179 tmpStr.remove(0, 1); 181 tmpStr.remove(0, 1);
180 hours = tmpStr.left(2).toInt(); 182 hours = tmpStr.left(2).toInt();
181 if (tmpStr.length() > 2) 183 if (tmpStr.length() > 2)
182 minutes = tmpStr.right(2).toInt(); 184 minutes = tmpStr.right(2).toInt();
183 else 185 else
184 minutes = 0; 186 minutes = 0;
185 mTimeZone = (60*hours+minutes); 187 mTimeZone = (60*hours+minutes);
186 if (neg) 188 if (neg)
187 mTimeZone = -mTimeZone; 189 mTimeZone = -mTimeZone;
188 mLocalTime = false; 190 mLocalTime = false;
189 191
190 setModified( true ); 192 setModified( true );
191} 193}
192 194
193QString Calendar::getTimeZoneStr() const 195QString Calendar::getTimeZoneStr() const
194{ 196{
195 if (mLocalTime) 197 if (mLocalTime)
196 return ""; 198 return "";
197 QString tmpStr; 199 QString tmpStr;
198 int hours = abs(mTimeZone / 60); 200 int hours = abs(mTimeZone / 60);
199 int minutes = abs(mTimeZone % 60); 201 int minutes = abs(mTimeZone % 60);
200 bool neg = mTimeZone < 0; 202 bool neg = mTimeZone < 0;
201 203
202 tmpStr.sprintf("%c%.2d%.2d", 204 tmpStr.sprintf("%c%.2d%.2d",
203 (neg ? '-' : '+'), 205 (neg ? '-' : '+'),
204 hours, minutes); 206 hours, minutes);
205 return tmpStr; 207 return tmpStr;
206} 208}
207 209
208void Calendar::setTimeZone(int tz) 210void Calendar::setTimeZone(int tz)
209{ 211{
210 mTimeZone = tz; 212 mTimeZone = tz;
211 mLocalTime = false; 213 mLocalTime = false;
212 214
213 setModified( true ); 215 setModified( true );
214} 216}
215 217
216int Calendar::getTimeZone() const 218int Calendar::getTimeZone() const
217{ 219{
218 return mTimeZone; 220 return mTimeZone;
219} 221}
220 222
221void Calendar::setTimeZoneId(const QString &id) 223void Calendar::setTimeZoneId(const QString &id)
222{ 224{
223 mTimeZoneId = id; 225 mTimeZoneId = id;
224 mLocalTime = false; 226 mLocalTime = false;
225 mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId); 227 mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId);
226 if ( mTimeZone > 1000) 228 if ( mTimeZone > 1000)
227 setLocalTime(); 229 setLocalTime();
228 //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone); 230 //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone);
229 setModified( true ); 231 setModified( true );
230} 232}
231 233
232QString Calendar::timeZoneId() const 234QString Calendar::timeZoneId() const
233{ 235{
234 return mTimeZoneId; 236 return mTimeZoneId;
235} 237}
236 238
237void Calendar::setLocalTime() 239void Calendar::setLocalTime()
238{ 240{
239 //qDebug("Calendar::setLocalTime() "); 241 //qDebug("Calendar::setLocalTime() ");
240 mLocalTime = true; 242 mLocalTime = true;
241 mTimeZone = 0; 243 mTimeZone = 0;
242 mTimeZoneId = ""; 244 mTimeZoneId = "";
243 245
244 setModified( true ); 246 setModified( true );
245} 247}
246 248
247bool Calendar::isLocalTime() const 249bool Calendar::isLocalTime() const
248{ 250{
249 return mLocalTime; 251 return mLocalTime;
250} 252}
251 253
252const QString &Calendar::getEmail() 254const QString &Calendar::getEmail()
253{ 255{
254 return mOwnerEmail; 256 return mOwnerEmail;
255} 257}
256 258
257void Calendar::setEmail(const QString &e) 259void Calendar::setEmail(const QString &e)
258{ 260{
259 mOwnerEmail = e; 261 mOwnerEmail = e;
260 262
261 setModified( true ); 263 setModified( true );
262} 264}
263 265
264void Calendar::setFilter(CalFilter *filter) 266void Calendar::setFilter(CalFilter *filter)
265{ 267{
266 mFilter = filter; 268 mFilter = filter;
267} 269}
268 270
269CalFilter *Calendar::filter() 271CalFilter *Calendar::filter()
270{ 272{
271 return mFilter; 273 return mFilter;
272} 274}
273 275
274QPtrList<Incidence> Calendar::incidences() 276Q3PtrList<Incidence> Calendar::incidences()
275{ 277{
276 QPtrList<Incidence> incidences; 278 Q3PtrList<Incidence> incidences;
277 279
278 Incidence *i; 280 Incidence *i;
279 281
280 QPtrList<Event> e = events(); 282 Q3PtrList<Event> e = events();
281 for( i = e.first(); i; i = e.next() ) incidences.append( i ); 283 for( i = e.first(); i; i = e.next() ) incidences.append( i );
282 284
283 QPtrList<Todo> t = todos(); 285 Q3PtrList<Todo> t = todos();
284 for( i = t.first(); i; i = t.next() ) incidences.append( i ); 286 for( i = t.first(); i; i = t.next() ) incidences.append( i );
285 287
286 QPtrList<Journal> j = journals(); 288 Q3PtrList<Journal> j = journals();
287 for( i = j.first(); i; i = j.next() ) incidences.append( i ); 289 for( i = j.first(); i; i = j.next() ) incidences.append( i );
288 290
289 return incidences; 291 return incidences;
290} 292}
291 293
292void Calendar::resetPilotStat(int id ) 294void Calendar::resetPilotStat(int id )
293{ 295{
294 QPtrList<Incidence> incidences; 296 Q3PtrList<Incidence> incidences;
295 297
296 Incidence *i; 298 Incidence *i;
297 299
298 QPtrList<Event> e = rawEvents(); 300 Q3PtrList<Event> e = rawEvents();
299 for( i = e.first(); i; i = e.next() ) i->setPilotId( id ); 301 for( i = e.first(); i; i = e.next() ) i->setPilotId( id );
300 302
301 QPtrList<Todo> t = rawTodos(); 303 Q3PtrList<Todo> t = rawTodos();
302 for( i = t.first(); i; i = t.next() ) i->setPilotId( id ); 304 for( i = t.first(); i; i = t.next() ) i->setPilotId( id );
303 305
304 QPtrList<Journal> j = journals(); 306 Q3PtrList<Journal> j = journals();
305 for( i = j.first(); i; i = j.next() ) i->setPilotId( id ); 307 for( i = j.first(); i; i = j.next() ) i->setPilotId( id );
306} 308}
307void Calendar::resetTempSyncStat() 309void Calendar::resetTempSyncStat()
308{ 310{
309 QPtrList<Incidence> incidences; 311 Q3PtrList<Incidence> incidences;
310 312
311 Incidence *i; 313 Incidence *i;
312 314
313 QPtrList<Event> e = rawEvents(); 315 Q3PtrList<Event> e = rawEvents();
314 for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 316 for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
315 317
316 QPtrList<Todo> t = rawTodos(); 318 Q3PtrList<Todo> t = rawTodos();
317 for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 319 for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
318 320
319 QPtrList<Journal> j = journals(); 321 Q3PtrList<Journal> j = journals();
320 for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 322 for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
321} 323}
322QPtrList<Incidence> Calendar::rawIncidences() 324Q3PtrList<Incidence> Calendar::rawIncidences()
323{ 325{
324 QPtrList<Incidence> incidences; 326 Q3PtrList<Incidence> incidences;
325 327
326 Incidence *i; 328 Incidence *i;
327 329
328 QPtrList<Event> e = rawEvents(); 330 Q3PtrList<Event> e = rawEvents();
329 for( i = e.first(); i; i = e.next() ) incidences.append( i ); 331 for( i = e.first(); i; i = e.next() ) incidences.append( i );
330 332
331 QPtrList<Todo> t = rawTodos(); 333 Q3PtrList<Todo> t = rawTodos();
332 for( i = t.first(); i; i = t.next() ) incidences.append( i ); 334 for( i = t.first(); i; i = t.next() ) incidences.append( i );
333 335
334 QPtrList<Journal> j = journals(); 336 Q3PtrList<Journal> j = journals();
335 for( i = j.first(); i; i = j.next() ) incidences.append( i ); 337 for( i = j.first(); i; i = j.next() ) incidences.append( i );
336 338
337 return incidences; 339 return incidences;
338} 340}
339 341
340QPtrList<Event> Calendar::events( const QDate &date, bool sorted ) 342Q3PtrList<Event> Calendar::events( const QDate &date, bool sorted )
341{ 343{
342 QPtrList<Event> el = rawEventsForDate(date,sorted); 344 Q3PtrList<Event> el = rawEventsForDate(date,sorted);
343 mFilter->apply(&el); 345 mFilter->apply(&el);
344 return el; 346 return el;
345} 347}
346 348
347QPtrList<Event> Calendar::events( const QDateTime &qdt ) 349Q3PtrList<Event> Calendar::events( const QDateTime &qdt )
348{ 350{
349 QPtrList<Event> el = rawEventsForDate(qdt); 351 Q3PtrList<Event> el = rawEventsForDate(qdt);
350 mFilter->apply(&el); 352 mFilter->apply(&el);
351 return el; 353 return el;
352} 354}
353 355
354QPtrList<Event> Calendar::events( const QDate &start, const QDate &end, 356Q3PtrList<Event> Calendar::events( const QDate &start, const QDate &end,
355 bool inclusive) 357 bool inclusive)
356{ 358{
357 QPtrList<Event> el = rawEvents(start,end,inclusive); 359 Q3PtrList<Event> el = rawEvents(start,end,inclusive);
358 mFilter->apply(&el); 360 mFilter->apply(&el);
359 return el; 361 return el;
360} 362}
361 363
362QPtrList<Event> Calendar::events() 364Q3PtrList<Event> Calendar::events()
363{ 365{
364 QPtrList<Event> el = rawEvents(); 366 Q3PtrList<Event> el = rawEvents();
365 mFilter->apply(&el); 367 mFilter->apply(&el);
366 return el; 368 return el;
367} 369}
368void Calendar::addIncidenceBranch(Incidence *i) 370void Calendar::addIncidenceBranch(Incidence *i)
369{ 371{
370 addIncidence( i ); 372 addIncidence( i );
371 Incidence * inc; 373 Incidence * inc;
372 QPtrList<Incidence> Relations = i->relations(); 374 Q3PtrList<Incidence> Relations = i->relations();
373 for (inc=Relations.first();inc;inc=Relations.next()) { 375 for (inc=Relations.first();inc;inc=Relations.next()) {
374 addIncidenceBranch( inc ); 376 addIncidenceBranch( inc );
375 } 377 }
376} 378}
377 379
378bool Calendar::addIncidence(Incidence *i) 380bool Calendar::addIncidence(Incidence *i)
379{ 381{
380 Incidence::AddVisitor<Calendar> v(this); 382 Incidence::AddVisitor<Calendar> v(this);
381 if ( i->calID() == 0 ) 383 if ( i->calID() == 0 )
382 i->setCalID_block( mDefaultCalendar ); 384 i->setCalID_block( mDefaultCalendar );
383 i->setCalEnabled( true ); 385 i->setCalEnabled( true );
384 return i->accept(v); 386 return i->accept(v);
385} 387}
386void Calendar::deleteIncidence(Incidence *in) 388void Calendar::deleteIncidence(Incidence *in)
387{ 389{
388 if ( in->typeID() == eventID ) 390 if ( in->typeID() == eventID )
389 deleteEvent( (Event*) in ); 391 deleteEvent( (Event*) in );
390 else if ( in->typeID() == todoID ) 392 else if ( in->typeID() == todoID )
391 deleteTodo( (Todo*) in); 393 deleteTodo( (Todo*) in);
392 else if ( in->typeID() == journalID ) 394 else if ( in->typeID() == journalID )
393 deleteJournal( (Journal*) in ); 395 deleteJournal( (Journal*) in );
394} 396}
395 397
396Incidence* Calendar::incidence( const QString& uid ) 398Incidence* Calendar::incidence( const QString& uid )
397{ 399{
398 Incidence* i; 400 Incidence* i;
399 401
400 if( (i = todo( uid )) != 0 ) 402 if( (i = todo( uid )) != 0 )
401 return i; 403 return i;
402 if( (i = event( uid )) != 0 ) 404 if( (i = event( uid )) != 0 )
403 return i; 405 return i;
404 if( (i = journal( uid )) != 0 ) 406 if( (i = journal( uid )) != 0 )
405 return i; 407 return i;
406 408
407 return 0; 409 return 0;
408} 410}
409 411
410QPtrList<Todo> Calendar::todos() 412Q3PtrList<Todo> Calendar::todos()
411{ 413{
412 QPtrList<Todo> tl = rawTodos(); 414 Q3PtrList<Todo> tl = rawTodos();
413 mFilter->apply( &tl ); 415 mFilter->apply( &tl );
414 return tl; 416 return tl;
415} 417}
416 418
417// When this is called, the todo have already been added to the calendar. 419// When this is called, the todo have already been added to the calendar.
418// This method is only about linking related todos 420// This method is only about linking related todos
419void Calendar::setupRelations( Incidence *incidence ) 421void Calendar::setupRelations( Incidence *incidence )
420{ 422{
421 QString uid = incidence->uid(); 423 QString uid = incidence->uid();
422 qDebug("Calendar::setupRelations %s", incidence->summary().latin1()); 424 qDebug("Calendar::setupRelations %s", incidence->summary().latin1());
423 // First, go over the list of orphans and see if this is their parent 425 // First, go over the list of orphans and see if this is their parent
424 while( Incidence* i = mOrphans[ uid ] ) { 426 while( Incidence* i = mOrphans[ uid ] ) {
425 mOrphans.remove( uid ); 427 mOrphans.remove( uid );
426 i->setRelatedTo( incidence ); 428 i->setRelatedTo( incidence );
427 qDebug("Add child %s ti inc %s", i->summary().latin1(),incidence->summary().latin1()); 429 qDebug("Add child %s ti inc %s", i->summary().latin1(),incidence->summary().latin1());
428 incidence->addRelation( i ); 430 incidence->addRelation( i );
429 mOrphanUids.remove( i->uid() ); 431 mOrphanUids.remove( i->uid() );
430 } 432 }
431 433
432 // Now see about this incidences parent 434 // Now see about this incidences parent
433 if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) { 435 if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) {
434 // This incidence has a uid it is related to, but is not registered to it yet 436 // This incidence has a uid it is related to, but is not registered to it yet
435 // Try to find it 437 // Try to find it
436 qDebug("Test parent for %s", incidence->summary().latin1()); 438 qDebug("Test parent for %s", incidence->summary().latin1());
437 Incidence* parent = this->incidenceForUid( incidence->relatedToUid(), true ); 439 Incidence* parent = this->incidenceForUid( incidence->relatedToUid(), true );
438 if( parent ) { 440 if( parent ) {
439 // Found it 441 // Found it
440 qDebug("parent found for for %s", incidence->summary().latin1()); 442 qDebug("parent found for for %s", incidence->summary().latin1());
441 incidence->setRelatedTo( parent ); 443 incidence->setRelatedTo( parent );
442 parent->addRelation( incidence ); 444 parent->addRelation( incidence );
443 } else { 445 } else {
444 qDebug("NO parent found for for %s", incidence->summary().latin1()); 446 qDebug("NO parent found for for %s", incidence->summary().latin1());
445 // Not found, put this in the mOrphans list 447 // Not found, put this in the mOrphans list
446 mOrphans.insert( incidence->relatedToUid(), incidence ); 448 mOrphans.insert( incidence->relatedToUid(), incidence );
447 mOrphanUids.insert( incidence->uid(), incidence ); 449 mOrphanUids.insert( incidence->uid(), incidence );
448 } 450 }
449 } 451 }
450} 452}
451 453
452// If a task with subtasks is deleted, move it's subtasks to the orphans list 454// If a task with subtasks is deleted, move it's subtasks to the orphans list
453void Calendar::removeRelations( Incidence *incidence ) 455void Calendar::removeRelations( Incidence *incidence )
454{ 456{
455 // qDebug("Calendar::removeRelations "); 457 // qDebug("Calendar::removeRelations ");
456 QString uid = incidence->uid(); 458 QString uid = incidence->uid();
457 459
458 QPtrList<Incidence> relations = incidence->relations(); 460 Q3PtrList<Incidence> relations = incidence->relations();
459 for( Incidence* i = relations.first(); i; i = relations.next() ) 461 for( Incidence* i = relations.first(); i; i = relations.next() )
460 if( !mOrphanUids.find( i->uid() ) ) { 462 if( !mOrphanUids.find( i->uid() ) ) {
461 mOrphans.insert( uid, i ); 463 mOrphans.insert( uid, i );
462 mOrphanUids.insert( i->uid(), i ); 464 mOrphanUids.insert( i->uid(), i );
463 i->setRelatedTo( 0 ); 465 i->setRelatedTo( 0 );
464 i->setRelatedToUid( uid ); 466 i->setRelatedToUid( uid );
465 } 467 }
466 468
467 // If this incidence is related to something else, tell that about it 469 // If this incidence is related to something else, tell that about it
468 if( incidence->relatedTo() ) 470 if( incidence->relatedTo() )
469 incidence->relatedTo()->removeRelation( incidence ); 471 incidence->relatedTo()->removeRelation( incidence );
470 472
471 // Remove this one from the orphans list 473 // Remove this one from the orphans list
472 if( mOrphanUids.remove( uid ) ) { 474 if( mOrphanUids.remove( uid ) ) {
473 QString r2uid = incidence->relatedToUid(); 475 QString r2uid = incidence->relatedToUid();
474 QPtrList<Incidence> tempList; 476 Q3PtrList<Incidence> tempList;
475 while( Incidence* i = mOrphans[ r2uid ] ) { 477 while( Incidence* i = mOrphans[ r2uid ] ) {
476 mOrphans.remove( r2uid ); 478 mOrphans.remove( r2uid );
477 if ( i != incidence ) tempList.append( i ); 479 if ( i != incidence ) tempList.append( i );
478 } 480 }
479 Incidence* inc = tempList.first(); 481 Incidence* inc = tempList.first();
480 while ( inc ) { 482 while ( inc ) {
481 mOrphans.insert( r2uid, inc ); 483 mOrphans.insert( r2uid, inc );
482 inc = tempList.next(); 484 inc = tempList.next();
483 } 485 }
484 } 486 }
485 // LR: and another big bad bug found 487 // LR: and another big bad bug found
486#if 0 488#if 0
487 // This incidence is located in the orphans list - it should be removed 489 // This incidence is located in the orphans list - it should be removed
488 if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) { 490 if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) {
489 // Removing wasn't that easy 491 // Removing wasn't that easy
490 for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) { 492 for( Q3DictIterator<Incidence> it( mOrphans ); it.current(); ++it ) {
491 if( it.current()->uid() == uid ) { 493 if( it.current()->uid() == uid ) {
492 mOrphans.remove( it.currentKey() ); 494 mOrphans.remove( it.currentKey() );
493 break; 495 break;
494 } 496 }
495 } 497 }
496 } 498 }
497#endif 499#endif
498} 500}
499 501
500void Calendar::registerObserver( Observer *observer ) 502void Calendar::registerObserver( Observer *observer )
501{ 503{
502 mObserver = observer; 504 mObserver = observer;
503 mNewObserver = true; 505 mNewObserver = true;
504} 506}
505 507
506void Calendar::setModified( bool modified ) 508void Calendar::setModified( bool modified )
507{ 509{
508 if ( mObserver ) mObserver->calendarModified( modified, this ); 510 if ( mObserver ) mObserver->calendarModified( modified, this );
509 if ( modified != mModified || mNewObserver ) { 511 if ( modified != mModified || mNewObserver ) {
510 mNewObserver = false; 512 mNewObserver = false;
511 // if ( mObserver ) mObserver->calendarModified( modified, this ); 513 // if ( mObserver ) mObserver->calendarModified( modified, this );
512 mModified = modified; 514 mModified = modified;
513 } 515 }
514} 516}
515 517
516void Calendar::setLoadedProductId( const QString &id ) 518void Calendar::setLoadedProductId( const QString &id )
517{ 519{
518 mLoadedProductId = id; 520 mLoadedProductId = id;
519} 521}
520 522
521QString Calendar::loadedProductId() 523QString Calendar::loadedProductId()
522{ 524{
523 return mLoadedProductId; 525 return mLoadedProductId;
524} 526}
525 527
526//#include "calendar.moc" 528//#include "calendar.moc"