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