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