summaryrefslogtreecommitdiffabout
path: root/libkcal/calendar.cpp
authorzautrix <zautrix>2005-06-13 10:51:47 (UTC)
committer zautrix <zautrix>2005-06-13 10:51:47 (UTC)
commit4f3ff02932b39bf16b9692c3cb69c101a28b4616 (patch) (unidiff)
treebae36a7e654c788a0994bb353f3997b495e2459c /libkcal/calendar.cpp
parent2be8214908c52298ba79c8058d340edca5a8b417 (diff)
downloadkdepimpi-4f3ff02932b39bf16b9692c3cb69c101a28b4616.zip
kdepimpi-4f3ff02932b39bf16b9692c3cb69c101a28b4616.tar.gz
kdepimpi-4f3ff02932b39bf16b9692c3cb69c101a28b4616.tar.bz2
fixx
Diffstat (limited to 'libkcal/calendar.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/calendar.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp
index f4350d9..5092d1a 100644
--- a/libkcal/calendar.cpp
+++ b/libkcal/calendar.cpp
@@ -1,483 +1,488 @@
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 mModified = false; 57 mModified = false;
57 mDefaultCalendar = 1; 58 mDefaultCalendar = 1;
58 // Setup default filter, which does nothing 59 // Setup default filter, which does nothing
59 mDefaultFilter = new CalFilter; 60 mDefaultFilter = new CalFilter;
60 mFilter = mDefaultFilter; 61 mFilter = mDefaultFilter;
61 mFilter->setEnabled(false); 62 mFilter->setEnabled(false);
62 63
63 // initialize random numbers. This is a hack, and not 64 // initialize random numbers. This is a hack, and not
64 // even that good of one at that. 65 // even that good of one at that.
65// srandom(time(0)); 66// srandom(time(0));
66 67
67 // user information... 68 // user information...
68 setOwner(i18n("Unknown Name")); 69 setOwner(i18n("Unknown Name"));
69 setEmail(i18n("unknown@nowhere")); 70 setEmail(i18n("unknown@nowhere"));
70 71
71#if 0 72#if 0
72 tmpStr = KOPrefs::instance()->mTimeZone; 73 tmpStr = KOPrefs::instance()->mTimeZone;
73// kdDebug(5800) << "Calendar::Calendar(): TimeZone: " << tmpStr << endl; 74// kdDebug(5800) << "Calendar::Calendar(): TimeZone: " << tmpStr << endl;
74 int dstSetting = KOPrefs::instance()->mDaylightSavings; 75 int dstSetting = KOPrefs::instance()->mDaylightSavings;
75 extern long int timezone; 76 extern long int timezone;
76 struct tm *now; 77 struct tm *now;
77 time_t curtime; 78 time_t curtime;
78 curtime = time(0); 79 curtime = time(0);
79 now = localtime(&curtime); 80 now = localtime(&curtime);
80 int hourOff = - ((timezone / 60) / 60); 81 int hourOff = - ((timezone / 60) / 60);
81 if (now->tm_isdst) 82 if (now->tm_isdst)
82 hourOff += 1; 83 hourOff += 1;
83 QString tzStr; 84 QString tzStr;
84 tzStr.sprintf("%.2d%.2d", 85 tzStr.sprintf("%.2d%.2d",
85 hourOff, 86 hourOff,
86 abs((timezone / 60) % 60)); 87 abs((timezone / 60) % 60));
87 88
88 // 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.
89 if (tmpStr.isEmpty()) { 90 if (tmpStr.isEmpty()) {
90// KOPrefs::instance()->mTimeZone = tzStr; 91// KOPrefs::instance()->mTimeZone = tzStr;
91 } else { 92 } else {
92 tzStr = tmpStr; 93 tzStr = tmpStr;
93 } 94 }
94 95
95 // if daylight savings has changed since last load time, we need 96 // if daylight savings has changed since last load time, we need
96 // to rewrite these settings to the config file. 97 // to rewrite these settings to the config file.
97 if ((now->tm_isdst && !dstSetting) || 98 if ((now->tm_isdst && !dstSetting) ||
98 (!now->tm_isdst && dstSetting)) { 99 (!now->tm_isdst && dstSetting)) {
99 KOPrefs::instance()->mTimeZone = tzStr; 100 KOPrefs::instance()->mTimeZone = tzStr;
100 KOPrefs::instance()->mDaylightSavings = now->tm_isdst; 101 KOPrefs::instance()->mDaylightSavings = now->tm_isdst;
101 } 102 }
102 103
103 setTimeZone(tzStr); 104 setTimeZone(tzStr);
104#endif 105#endif
105 106
106// KOPrefs::instance()->writeConfig(); 107// KOPrefs::instance()->writeConfig();
107} 108}
108 109
109Calendar::~Calendar() 110Calendar::~Calendar()
110{ 111{
111 delete mDefaultFilter; 112 delete mDefaultFilter;
112 if ( mUndoIncidence ) 113 if ( mUndoIncidence )
113 delete mUndoIncidence; 114 delete mUndoIncidence;
114} 115}
116void Calendar::setDontDeleteIncidencesOnClose ()
117{
118 mDeleteIncidencesOnClose = false;
119}
115void Calendar::setDefaultCalendar( int d ) 120void Calendar::setDefaultCalendar( int d )
116{ 121{
117 mDefaultCalendar = d; 122 mDefaultCalendar = d;
118} 123}
119int Calendar::defaultCalendar() 124int Calendar::defaultCalendar()
120{ 125{
121 return mDefaultCalendar; 126 return mDefaultCalendar;
122} 127}
123const QString &Calendar::getOwner() const 128const QString &Calendar::getOwner() const
124{ 129{
125 return mOwner; 130 return mOwner;
126} 131}
127 132
128bool Calendar::undoDeleteIncidence() 133bool Calendar::undoDeleteIncidence()
129{ 134{
130 if (!mUndoIncidence) 135 if (!mUndoIncidence)
131 return false; 136 return false;
132 addIncidence(mUndoIncidence); 137 addIncidence(mUndoIncidence);
133 mUndoIncidence = 0; 138 mUndoIncidence = 0;
134 return true; 139 return true;
135} 140}
136void Calendar::setOwner(const QString &os) 141void Calendar::setOwner(const QString &os)
137{ 142{
138 int i; 143 int i;
139 mOwner = os; 144 mOwner = os;
140 i = mOwner.find(','); 145 i = mOwner.find(',');
141 if (i != -1) 146 if (i != -1)
142 mOwner = mOwner.left(i); 147 mOwner = mOwner.left(i);
143 148
144 setModified( true ); 149 setModified( true );
145} 150}
146 151
147void Calendar::setTimeZone(const QString & tz) 152void Calendar::setTimeZone(const QString & tz)
148{ 153{
149 bool neg = FALSE; 154 bool neg = FALSE;
150 int hours, minutes; 155 int hours, minutes;
151 QString tmpStr(tz); 156 QString tmpStr(tz);
152 157
153 if (tmpStr.left(1) == "-") 158 if (tmpStr.left(1) == "-")
154 neg = TRUE; 159 neg = TRUE;
155 if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+") 160 if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+")
156 tmpStr.remove(0, 1); 161 tmpStr.remove(0, 1);
157 hours = tmpStr.left(2).toInt(); 162 hours = tmpStr.left(2).toInt();
158 if (tmpStr.length() > 2) 163 if (tmpStr.length() > 2)
159 minutes = tmpStr.right(2).toInt(); 164 minutes = tmpStr.right(2).toInt();
160 else 165 else
161 minutes = 0; 166 minutes = 0;
162 mTimeZone = (60*hours+minutes); 167 mTimeZone = (60*hours+minutes);
163 if (neg) 168 if (neg)
164 mTimeZone = -mTimeZone; 169 mTimeZone = -mTimeZone;
165 mLocalTime = false; 170 mLocalTime = false;
166 171
167 setModified( true ); 172 setModified( true );
168} 173}
169 174
170QString Calendar::getTimeZoneStr() const 175QString Calendar::getTimeZoneStr() const
171{ 176{
172 if (mLocalTime) 177 if (mLocalTime)
173 return ""; 178 return "";
174 QString tmpStr; 179 QString tmpStr;
175 int hours = abs(mTimeZone / 60); 180 int hours = abs(mTimeZone / 60);
176 int minutes = abs(mTimeZone % 60); 181 int minutes = abs(mTimeZone % 60);
177 bool neg = mTimeZone < 0; 182 bool neg = mTimeZone < 0;
178 183
179 tmpStr.sprintf("%c%.2d%.2d", 184 tmpStr.sprintf("%c%.2d%.2d",
180 (neg ? '-' : '+'), 185 (neg ? '-' : '+'),
181 hours, minutes); 186 hours, minutes);
182 return tmpStr; 187 return tmpStr;
183} 188}
184 189
185void Calendar::setTimeZone(int tz) 190void Calendar::setTimeZone(int tz)
186{ 191{
187 mTimeZone = tz; 192 mTimeZone = tz;
188 mLocalTime = false; 193 mLocalTime = false;
189 194
190 setModified( true ); 195 setModified( true );
191} 196}
192 197
193int Calendar::getTimeZone() const 198int Calendar::getTimeZone() const
194{ 199{
195 return mTimeZone; 200 return mTimeZone;
196} 201}
197 202
198void Calendar::setTimeZoneId(const QString &id) 203void Calendar::setTimeZoneId(const QString &id)
199{ 204{
200 mTimeZoneId = id; 205 mTimeZoneId = id;
201 mLocalTime = false; 206 mLocalTime = false;
202 mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId); 207 mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId);
203 if ( mTimeZone > 1000) 208 if ( mTimeZone > 1000)
204 setLocalTime(); 209 setLocalTime();
205 //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone); 210 //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone);
206 setModified( true ); 211 setModified( true );
207} 212}
208 213
209QString Calendar::timeZoneId() const 214QString Calendar::timeZoneId() const
210{ 215{
211 return mTimeZoneId; 216 return mTimeZoneId;
212} 217}
213 218
214void Calendar::setLocalTime() 219void Calendar::setLocalTime()
215{ 220{
216 //qDebug("Calendar::setLocalTime() "); 221 //qDebug("Calendar::setLocalTime() ");
217 mLocalTime = true; 222 mLocalTime = true;
218 mTimeZone = 0; 223 mTimeZone = 0;
219 mTimeZoneId = ""; 224 mTimeZoneId = "";
220 225
221 setModified( true ); 226 setModified( true );
222} 227}
223 228
224bool Calendar::isLocalTime() const 229bool Calendar::isLocalTime() const
225{ 230{
226 return mLocalTime; 231 return mLocalTime;
227} 232}
228 233
229const QString &Calendar::getEmail() 234const QString &Calendar::getEmail()
230{ 235{
231 return mOwnerEmail; 236 return mOwnerEmail;
232} 237}
233 238
234void Calendar::setEmail(const QString &e) 239void Calendar::setEmail(const QString &e)
235{ 240{
236 mOwnerEmail = e; 241 mOwnerEmail = e;
237 242
238 setModified( true ); 243 setModified( true );
239} 244}
240 245
241void Calendar::setFilter(CalFilter *filter) 246void Calendar::setFilter(CalFilter *filter)
242{ 247{
243 mFilter = filter; 248 mFilter = filter;
244} 249}
245 250
246CalFilter *Calendar::filter() 251CalFilter *Calendar::filter()
247{ 252{
248 return mFilter; 253 return mFilter;
249} 254}
250 255
251QPtrList<Incidence> Calendar::incidences() 256QPtrList<Incidence> Calendar::incidences()
252{ 257{
253 QPtrList<Incidence> incidences; 258 QPtrList<Incidence> incidences;
254 259
255 Incidence *i; 260 Incidence *i;
256 261
257 QPtrList<Event> e = events(); 262 QPtrList<Event> e = events();
258 for( i = e.first(); i; i = e.next() ) incidences.append( i ); 263 for( i = e.first(); i; i = e.next() ) incidences.append( i );
259 264
260 QPtrList<Todo> t = todos(); 265 QPtrList<Todo> t = todos();
261 for( i = t.first(); i; i = t.next() ) incidences.append( i ); 266 for( i = t.first(); i; i = t.next() ) incidences.append( i );
262 267
263 QPtrList<Journal> j = journals(); 268 QPtrList<Journal> j = journals();
264 for( i = j.first(); i; i = j.next() ) incidences.append( i ); 269 for( i = j.first(); i; i = j.next() ) incidences.append( i );
265 270
266 return incidences; 271 return incidences;
267} 272}
268 273
269void Calendar::resetPilotStat(int id ) 274void Calendar::resetPilotStat(int id )
270{ 275{
271 QPtrList<Incidence> incidences; 276 QPtrList<Incidence> incidences;
272 277
273 Incidence *i; 278 Incidence *i;
274 279
275 QPtrList<Event> e = rawEvents(); 280 QPtrList<Event> e = rawEvents();
276 for( i = e.first(); i; i = e.next() ) i->setPilotId( id ); 281 for( i = e.first(); i; i = e.next() ) i->setPilotId( id );
277 282
278 QPtrList<Todo> t = rawTodos(); 283 QPtrList<Todo> t = rawTodos();
279 for( i = t.first(); i; i = t.next() ) i->setPilotId( id ); 284 for( i = t.first(); i; i = t.next() ) i->setPilotId( id );
280 285
281 QPtrList<Journal> j = journals(); 286 QPtrList<Journal> j = journals();
282 for( i = j.first(); i; i = j.next() ) i->setPilotId( id ); 287 for( i = j.first(); i; i = j.next() ) i->setPilotId( id );
283} 288}
284void Calendar::resetTempSyncStat() 289void Calendar::resetTempSyncStat()
285{ 290{
286 QPtrList<Incidence> incidences; 291 QPtrList<Incidence> incidences;
287 292
288 Incidence *i; 293 Incidence *i;
289 294
290 QPtrList<Event> e = rawEvents(); 295 QPtrList<Event> e = rawEvents();
291 for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 296 for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
292 297
293 QPtrList<Todo> t = rawTodos(); 298 QPtrList<Todo> t = rawTodos();
294 for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 299 for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
295 300
296 QPtrList<Journal> j = journals(); 301 QPtrList<Journal> j = journals();
297 for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 302 for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
298} 303}
299QPtrList<Incidence> Calendar::rawIncidences() 304QPtrList<Incidence> Calendar::rawIncidences()
300{ 305{
301 QPtrList<Incidence> incidences; 306 QPtrList<Incidence> incidences;
302 307
303 Incidence *i; 308 Incidence *i;
304 309
305 QPtrList<Event> e = rawEvents(); 310 QPtrList<Event> e = rawEvents();
306 for( i = e.first(); i; i = e.next() ) incidences.append( i ); 311 for( i = e.first(); i; i = e.next() ) incidences.append( i );
307 312
308 QPtrList<Todo> t = rawTodos(); 313 QPtrList<Todo> t = rawTodos();
309 for( i = t.first(); i; i = t.next() ) incidences.append( i ); 314 for( i = t.first(); i; i = t.next() ) incidences.append( i );
310 315
311 QPtrList<Journal> j = journals(); 316 QPtrList<Journal> j = journals();
312 for( i = j.first(); i; i = j.next() ) incidences.append( i ); 317 for( i = j.first(); i; i = j.next() ) incidences.append( i );
313 318
314 return incidences; 319 return incidences;
315} 320}
316 321
317QPtrList<Event> Calendar::events( const QDate &date, bool sorted ) 322QPtrList<Event> Calendar::events( const QDate &date, bool sorted )
318{ 323{
319 QPtrList<Event> el = rawEventsForDate(date,sorted); 324 QPtrList<Event> el = rawEventsForDate(date,sorted);
320 mFilter->apply(&el); 325 mFilter->apply(&el);
321 return el; 326 return el;
322} 327}
323 328
324QPtrList<Event> Calendar::events( const QDateTime &qdt ) 329QPtrList<Event> Calendar::events( const QDateTime &qdt )
325{ 330{
326 QPtrList<Event> el = rawEventsForDate(qdt); 331 QPtrList<Event> el = rawEventsForDate(qdt);
327 mFilter->apply(&el); 332 mFilter->apply(&el);
328 return el; 333 return el;
329} 334}
330 335
331QPtrList<Event> Calendar::events( const QDate &start, const QDate &end, 336QPtrList<Event> Calendar::events( const QDate &start, const QDate &end,
332 bool inclusive) 337 bool inclusive)
333{ 338{
334 QPtrList<Event> el = rawEvents(start,end,inclusive); 339 QPtrList<Event> el = rawEvents(start,end,inclusive);
335 mFilter->apply(&el); 340 mFilter->apply(&el);
336 return el; 341 return el;
337} 342}
338 343
339QPtrList<Event> Calendar::events() 344QPtrList<Event> Calendar::events()
340{ 345{
341 QPtrList<Event> el = rawEvents(); 346 QPtrList<Event> el = rawEvents();
342 mFilter->apply(&el); 347 mFilter->apply(&el);
343 return el; 348 return el;
344} 349}
345void Calendar::addIncidenceBranch(Incidence *i) 350void Calendar::addIncidenceBranch(Incidence *i)
346{ 351{
347 addIncidence( i ); 352 addIncidence( i );
348 Incidence * inc; 353 Incidence * inc;
349 QPtrList<Incidence> Relations = i->relations(); 354 QPtrList<Incidence> Relations = i->relations();
350 for (inc=Relations.first();inc;inc=Relations.next()) { 355 for (inc=Relations.first();inc;inc=Relations.next()) {
351 addIncidenceBranch( inc ); 356 addIncidenceBranch( inc );
352 } 357 }
353} 358}
354 359
355bool Calendar::addIncidence(Incidence *i) 360bool Calendar::addIncidence(Incidence *i)
356{ 361{
357 Incidence::AddVisitor<Calendar> v(this); 362 Incidence::AddVisitor<Calendar> v(this);
358 i->setCalID( mDefaultCalendar ); 363 i->setCalID( mDefaultCalendar );
359 i->setCalEnabled( true ); 364 i->setCalEnabled( true );
360 return i->accept(v); 365 return i->accept(v);
361} 366}
362void Calendar::deleteIncidence(Incidence *in) 367void Calendar::deleteIncidence(Incidence *in)
363{ 368{
364 if ( in->typeID() == eventID ) 369 if ( in->typeID() == eventID )
365 deleteEvent( (Event*) in ); 370 deleteEvent( (Event*) in );
366 else if ( in->typeID() == todoID ) 371 else if ( in->typeID() == todoID )
367 deleteTodo( (Todo*) in); 372 deleteTodo( (Todo*) in);
368 else if ( in->typeID() == journalID ) 373 else if ( in->typeID() == journalID )
369 deleteJournal( (Journal*) in ); 374 deleteJournal( (Journal*) in );
370} 375}
371 376
372Incidence* Calendar::incidence( const QString& uid ) 377Incidence* Calendar::incidence( const QString& uid )
373{ 378{
374 Incidence* i; 379 Incidence* i;
375 380
376 if( (i = todo( uid )) != 0 ) 381 if( (i = todo( uid )) != 0 )
377 return i; 382 return i;
378 if( (i = event( uid )) != 0 ) 383 if( (i = event( uid )) != 0 )
379 return i; 384 return i;
380 if( (i = journal( uid )) != 0 ) 385 if( (i = journal( uid )) != 0 )
381 return i; 386 return i;
382 387
383 return 0; 388 return 0;
384} 389}
385 390
386QPtrList<Todo> Calendar::todos() 391QPtrList<Todo> Calendar::todos()
387{ 392{
388 QPtrList<Todo> tl = rawTodos(); 393 QPtrList<Todo> tl = rawTodos();
389 mFilter->apply( &tl ); 394 mFilter->apply( &tl );
390 return tl; 395 return tl;
391} 396}
392 397
393// When this is called, the todo have already been added to the calendar. 398// When this is called, the todo have already been added to the calendar.
394// This method is only about linking related todos 399// This method is only about linking related todos
395void Calendar::setupRelations( Incidence *incidence ) 400void Calendar::setupRelations( Incidence *incidence )
396{ 401{
397 QString uid = incidence->uid(); 402 QString uid = incidence->uid();
398 //qDebug("Calendar::setupRelations "); 403 //qDebug("Calendar::setupRelations ");
399 // First, go over the list of orphans and see if this is their parent 404 // First, go over the list of orphans and see if this is their parent
400 while( Incidence* i = mOrphans[ uid ] ) { 405 while( Incidence* i = mOrphans[ uid ] ) {
401 mOrphans.remove( uid ); 406 mOrphans.remove( uid );
402 i->setRelatedTo( incidence ); 407 i->setRelatedTo( incidence );
403 incidence->addRelation( i ); 408 incidence->addRelation( i );
404 mOrphanUids.remove( i->uid() ); 409 mOrphanUids.remove( i->uid() );
405 } 410 }
406 411
407 // Now see about this incidences parent 412 // Now see about this incidences parent
408 if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) { 413 if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) {
409 // This incidence has a uid it is related to, but is not registered to it yet 414 // This incidence has a uid it is related to, but is not registered to it yet
410 // Try to find it 415 // Try to find it
411 Incidence* parent = this->incidence( incidence->relatedToUid() ); 416 Incidence* parent = this->incidence( incidence->relatedToUid() );
412 if( parent ) { 417 if( parent ) {
413 // Found it 418 // Found it
414 incidence->setRelatedTo( parent ); 419 incidence->setRelatedTo( parent );
415 parent->addRelation( incidence ); 420 parent->addRelation( incidence );
416 } else { 421 } else {
417 // Not found, put this in the mOrphans list 422 // Not found, put this in the mOrphans list
418 mOrphans.insert( incidence->relatedToUid(), incidence ); 423 mOrphans.insert( incidence->relatedToUid(), incidence );
419 mOrphanUids.insert( incidence->uid(), incidence ); 424 mOrphanUids.insert( incidence->uid(), incidence );
420 } 425 }
421 } 426 }
422} 427}
423 428
424// If a task with subtasks is deleted, move it's subtasks to the orphans list 429// If a task with subtasks is deleted, move it's subtasks to the orphans list
425void Calendar::removeRelations( Incidence *incidence ) 430void Calendar::removeRelations( Incidence *incidence )
426{ 431{
427 // qDebug("Calendar::removeRelations "); 432 // qDebug("Calendar::removeRelations ");
428 QString uid = incidence->uid(); 433 QString uid = incidence->uid();
429 434
430 QPtrList<Incidence> relations = incidence->relations(); 435 QPtrList<Incidence> relations = incidence->relations();
431 for( Incidence* i = relations.first(); i; i = relations.next() ) 436 for( Incidence* i = relations.first(); i; i = relations.next() )
432 if( !mOrphanUids.find( i->uid() ) ) { 437 if( !mOrphanUids.find( i->uid() ) ) {
433 mOrphans.insert( uid, i ); 438 mOrphans.insert( uid, i );
434 mOrphanUids.insert( i->uid(), i ); 439 mOrphanUids.insert( i->uid(), i );
435 i->setRelatedTo( 0 ); 440 i->setRelatedTo( 0 );
436 i->setRelatedToUid( uid ); 441 i->setRelatedToUid( uid );
437 } 442 }
438 443
439 // If this incidence is related to something else, tell that about it 444 // If this incidence is related to something else, tell that about it
440 if( incidence->relatedTo() ) 445 if( incidence->relatedTo() )
441 incidence->relatedTo()->removeRelation( incidence ); 446 incidence->relatedTo()->removeRelation( incidence );
442 447
443 // Remove this one from the orphans list 448 // Remove this one from the orphans list
444 if( mOrphanUids.remove( uid ) ) 449 if( mOrphanUids.remove( uid ) )
445 // This incidence is located in the orphans list - it should be removed 450 // This incidence is located in the orphans list - it should be removed
446 if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) { 451 if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) {
447 // Removing wasn't that easy 452 // Removing wasn't that easy
448 for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) { 453 for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) {
449 if( it.current()->uid() == uid ) { 454 if( it.current()->uid() == uid ) {
450 mOrphans.remove( it.currentKey() ); 455 mOrphans.remove( it.currentKey() );
451 break; 456 break;
452 } 457 }
453 } 458 }
454 } 459 }
455} 460}
456 461
457void Calendar::registerObserver( Observer *observer ) 462void Calendar::registerObserver( Observer *observer )
458{ 463{
459 mObserver = observer; 464 mObserver = observer;
460 mNewObserver = true; 465 mNewObserver = true;
461} 466}
462 467
463void Calendar::setModified( bool modified ) 468void Calendar::setModified( bool modified )
464{ 469{
465 if ( mObserver ) mObserver->calendarModified( modified, this ); 470 if ( mObserver ) mObserver->calendarModified( modified, this );
466 if ( modified != mModified || mNewObserver ) { 471 if ( modified != mModified || mNewObserver ) {
467 mNewObserver = false; 472 mNewObserver = false;
468 // if ( mObserver ) mObserver->calendarModified( modified, this ); 473 // if ( mObserver ) mObserver->calendarModified( modified, this );
469 mModified = modified; 474 mModified = modified;
470 } 475 }
471} 476}
472 477
473void Calendar::setLoadedProductId( const QString &id ) 478void Calendar::setLoadedProductId( const QString &id )
474{ 479{
475 mLoadedProductId = id; 480 mLoadedProductId = id;
476} 481}
477 482
478QString Calendar::loadedProductId() 483QString Calendar::loadedProductId()
479{ 484{
480 return mLoadedProductId; 485 return mLoadedProductId;
481} 486}
482 487
483//#include "calendar.moc" 488//#include "calendar.moc"