summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/calendar.cpp14
-rw-r--r--libkcal/calendar.h9
-rw-r--r--libkcal/calendarlocal.cpp80
-rw-r--r--libkcal/calendarlocal.h3
-rw-r--r--libkcal/calfilter.cpp9
-rw-r--r--libkcal/calfilter.h1
-rw-r--r--libkcal/event.cpp4
-rw-r--r--libkcal/incidencebase.cpp33
-rw-r--r--libkcal/incidencebase.h9
-rw-r--r--libkcal/todo.cpp2
10 files changed, 146 insertions, 18 deletions
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp
index 7e8e2c5..f4350d9 100644
--- a/libkcal/calendar.cpp
+++ b/libkcal/calendar.cpp
@@ -1,211 +1,218 @@
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 mModified = false; 56 mModified = false;
57 57 mDefaultCalendar = 1;
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 115void Calendar::setDefaultCalendar( int d )
116{
117 mDefaultCalendar = d;
118}
119int Calendar::defaultCalendar()
120{
121 return mDefaultCalendar;
122}
116const QString &Calendar::getOwner() const 123const QString &Calendar::getOwner() const
117{ 124{
118 return mOwner; 125 return mOwner;
119} 126}
120 127
121bool Calendar::undoDeleteIncidence() 128bool Calendar::undoDeleteIncidence()
122{ 129{
123 if (!mUndoIncidence) 130 if (!mUndoIncidence)
124 return false; 131 return false;
125 addIncidence(mUndoIncidence); 132 addIncidence(mUndoIncidence);
126 mUndoIncidence = 0; 133 mUndoIncidence = 0;
127 return true; 134 return true;
128} 135}
129void Calendar::setOwner(const QString &os) 136void Calendar::setOwner(const QString &os)
130{ 137{
131 int i; 138 int i;
132 mOwner = os; 139 mOwner = os;
133 i = mOwner.find(','); 140 i = mOwner.find(',');
134 if (i != -1) 141 if (i != -1)
135 mOwner = mOwner.left(i); 142 mOwner = mOwner.left(i);
136 143
137 setModified( true ); 144 setModified( true );
138} 145}
139 146
140void Calendar::setTimeZone(const QString & tz) 147void Calendar::setTimeZone(const QString & tz)
141{ 148{
142 bool neg = FALSE; 149 bool neg = FALSE;
143 int hours, minutes; 150 int hours, minutes;
144 QString tmpStr(tz); 151 QString tmpStr(tz);
145 152
146 if (tmpStr.left(1) == "-") 153 if (tmpStr.left(1) == "-")
147 neg = TRUE; 154 neg = TRUE;
148 if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+") 155 if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+")
149 tmpStr.remove(0, 1); 156 tmpStr.remove(0, 1);
150 hours = tmpStr.left(2).toInt(); 157 hours = tmpStr.left(2).toInt();
151 if (tmpStr.length() > 2) 158 if (tmpStr.length() > 2)
152 minutes = tmpStr.right(2).toInt(); 159 minutes = tmpStr.right(2).toInt();
153 else 160 else
154 minutes = 0; 161 minutes = 0;
155 mTimeZone = (60*hours+minutes); 162 mTimeZone = (60*hours+minutes);
156 if (neg) 163 if (neg)
157 mTimeZone = -mTimeZone; 164 mTimeZone = -mTimeZone;
158 mLocalTime = false; 165 mLocalTime = false;
159 166
160 setModified( true ); 167 setModified( true );
161} 168}
162 169
163QString Calendar::getTimeZoneStr() const 170QString Calendar::getTimeZoneStr() const
164{ 171{
165 if (mLocalTime) 172 if (mLocalTime)
166 return ""; 173 return "";
167 QString tmpStr; 174 QString tmpStr;
168 int hours = abs(mTimeZone / 60); 175 int hours = abs(mTimeZone / 60);
169 int minutes = abs(mTimeZone % 60); 176 int minutes = abs(mTimeZone % 60);
170 bool neg = mTimeZone < 0; 177 bool neg = mTimeZone < 0;
171 178
172 tmpStr.sprintf("%c%.2d%.2d", 179 tmpStr.sprintf("%c%.2d%.2d",
173 (neg ? '-' : '+'), 180 (neg ? '-' : '+'),
174 hours, minutes); 181 hours, minutes);
175 return tmpStr; 182 return tmpStr;
176} 183}
177 184
178void Calendar::setTimeZone(int tz) 185void Calendar::setTimeZone(int tz)
179{ 186{
180 mTimeZone = tz; 187 mTimeZone = tz;
181 mLocalTime = false; 188 mLocalTime = false;
182 189
183 setModified( true ); 190 setModified( true );
184} 191}
185 192
186int Calendar::getTimeZone() const 193int Calendar::getTimeZone() const
187{ 194{
188 return mTimeZone; 195 return mTimeZone;
189} 196}
190 197
191void Calendar::setTimeZoneId(const QString &id) 198void Calendar::setTimeZoneId(const QString &id)
192{ 199{
193 mTimeZoneId = id; 200 mTimeZoneId = id;
194 mLocalTime = false; 201 mLocalTime = false;
195 mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId); 202 mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId);
196 if ( mTimeZone > 1000) 203 if ( mTimeZone > 1000)
197 setLocalTime(); 204 setLocalTime();
198 //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone); 205 //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone);
199 setModified( true ); 206 setModified( true );
200} 207}
201 208
202QString Calendar::timeZoneId() const 209QString Calendar::timeZoneId() const
203{ 210{
204 return mTimeZoneId; 211 return mTimeZoneId;
205} 212}
206 213
207void Calendar::setLocalTime() 214void Calendar::setLocalTime()
208{ 215{
209 //qDebug("Calendar::setLocalTime() "); 216 //qDebug("Calendar::setLocalTime() ");
210 mLocalTime = true; 217 mLocalTime = true;
211 mTimeZone = 0; 218 mTimeZone = 0;
@@ -255,193 +262,194 @@ QPtrList<Incidence> Calendar::incidences()
255 262
256 QPtrList<Journal> j = journals(); 263 QPtrList<Journal> j = journals();
257 for( i = j.first(); i; i = j.next() ) incidences.append( i ); 264 for( i = j.first(); i; i = j.next() ) incidences.append( i );
258 265
259 return incidences; 266 return incidences;
260} 267}
261 268
262void Calendar::resetPilotStat(int id ) 269void Calendar::resetPilotStat(int id )
263{ 270{
264 QPtrList<Incidence> incidences; 271 QPtrList<Incidence> incidences;
265 272
266 Incidence *i; 273 Incidence *i;
267 274
268 QPtrList<Event> e = rawEvents(); 275 QPtrList<Event> e = rawEvents();
269 for( i = e.first(); i; i = e.next() ) i->setPilotId( id ); 276 for( i = e.first(); i; i = e.next() ) i->setPilotId( id );
270 277
271 QPtrList<Todo> t = rawTodos(); 278 QPtrList<Todo> t = rawTodos();
272 for( i = t.first(); i; i = t.next() ) i->setPilotId( id ); 279 for( i = t.first(); i; i = t.next() ) i->setPilotId( id );
273 280
274 QPtrList<Journal> j = journals(); 281 QPtrList<Journal> j = journals();
275 for( i = j.first(); i; i = j.next() ) i->setPilotId( id ); 282 for( i = j.first(); i; i = j.next() ) i->setPilotId( id );
276} 283}
277void Calendar::resetTempSyncStat() 284void Calendar::resetTempSyncStat()
278{ 285{
279 QPtrList<Incidence> incidences; 286 QPtrList<Incidence> incidences;
280 287
281 Incidence *i; 288 Incidence *i;
282 289
283 QPtrList<Event> e = rawEvents(); 290 QPtrList<Event> e = rawEvents();
284 for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 291 for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
285 292
286 QPtrList<Todo> t = rawTodos(); 293 QPtrList<Todo> t = rawTodos();
287 for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 294 for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
288 295
289 QPtrList<Journal> j = journals(); 296 QPtrList<Journal> j = journals();
290 for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 297 for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
291} 298}
292QPtrList<Incidence> Calendar::rawIncidences() 299QPtrList<Incidence> Calendar::rawIncidences()
293{ 300{
294 QPtrList<Incidence> incidences; 301 QPtrList<Incidence> incidences;
295 302
296 Incidence *i; 303 Incidence *i;
297 304
298 QPtrList<Event> e = rawEvents(); 305 QPtrList<Event> e = rawEvents();
299 for( i = e.first(); i; i = e.next() ) incidences.append( i ); 306 for( i = e.first(); i; i = e.next() ) incidences.append( i );
300 307
301 QPtrList<Todo> t = rawTodos(); 308 QPtrList<Todo> t = rawTodos();
302 for( i = t.first(); i; i = t.next() ) incidences.append( i ); 309 for( i = t.first(); i; i = t.next() ) incidences.append( i );
303 310
304 QPtrList<Journal> j = journals(); 311 QPtrList<Journal> j = journals();
305 for( i = j.first(); i; i = j.next() ) incidences.append( i ); 312 for( i = j.first(); i; i = j.next() ) incidences.append( i );
306 313
307 return incidences; 314 return incidences;
308} 315}
309 316
310QPtrList<Event> Calendar::events( const QDate &date, bool sorted ) 317QPtrList<Event> Calendar::events( const QDate &date, bool sorted )
311{ 318{
312 QPtrList<Event> el = rawEventsForDate(date,sorted); 319 QPtrList<Event> el = rawEventsForDate(date,sorted);
313 mFilter->apply(&el); 320 mFilter->apply(&el);
314 return el; 321 return el;
315} 322}
316 323
317QPtrList<Event> Calendar::events( const QDateTime &qdt ) 324QPtrList<Event> Calendar::events( const QDateTime &qdt )
318{ 325{
319 QPtrList<Event> el = rawEventsForDate(qdt); 326 QPtrList<Event> el = rawEventsForDate(qdt);
320 mFilter->apply(&el); 327 mFilter->apply(&el);
321 return el; 328 return el;
322} 329}
323 330
324QPtrList<Event> Calendar::events( const QDate &start, const QDate &end, 331QPtrList<Event> Calendar::events( const QDate &start, const QDate &end,
325 bool inclusive) 332 bool inclusive)
326{ 333{
327 QPtrList<Event> el = rawEvents(start,end,inclusive); 334 QPtrList<Event> el = rawEvents(start,end,inclusive);
328 mFilter->apply(&el); 335 mFilter->apply(&el);
329 return el; 336 return el;
330} 337}
331 338
332QPtrList<Event> Calendar::events() 339QPtrList<Event> Calendar::events()
333{ 340{
334 QPtrList<Event> el = rawEvents(); 341 QPtrList<Event> el = rawEvents();
335 mFilter->apply(&el); 342 mFilter->apply(&el);
336 return el; 343 return el;
337} 344}
338void Calendar::addIncidenceBranch(Incidence *i) 345void Calendar::addIncidenceBranch(Incidence *i)
339{ 346{
340 addIncidence( i ); 347 addIncidence( i );
341 Incidence * inc; 348 Incidence * inc;
342 QPtrList<Incidence> Relations = i->relations(); 349 QPtrList<Incidence> Relations = i->relations();
343 for (inc=Relations.first();inc;inc=Relations.next()) { 350 for (inc=Relations.first();inc;inc=Relations.next()) {
344 addIncidenceBranch( inc ); 351 addIncidenceBranch( inc );
345 } 352 }
346} 353}
347 354
348bool Calendar::addIncidence(Incidence *i) 355bool Calendar::addIncidence(Incidence *i)
349{ 356{
350 Incidence::AddVisitor<Calendar> v(this); 357 Incidence::AddVisitor<Calendar> v(this);
351 358 i->setCalID( mDefaultCalendar );
359 i->setCalEnabled( true );
352 return i->accept(v); 360 return i->accept(v);
353} 361}
354void Calendar::deleteIncidence(Incidence *in) 362void Calendar::deleteIncidence(Incidence *in)
355{ 363{
356 if ( in->typeID() == eventID ) 364 if ( in->typeID() == eventID )
357 deleteEvent( (Event*) in ); 365 deleteEvent( (Event*) in );
358 else if ( in->typeID() == todoID ) 366 else if ( in->typeID() == todoID )
359 deleteTodo( (Todo*) in); 367 deleteTodo( (Todo*) in);
360 else if ( in->typeID() == journalID ) 368 else if ( in->typeID() == journalID )
361 deleteJournal( (Journal*) in ); 369 deleteJournal( (Journal*) in );
362} 370}
363 371
364Incidence* Calendar::incidence( const QString& uid ) 372Incidence* Calendar::incidence( const QString& uid )
365{ 373{
366 Incidence* i; 374 Incidence* i;
367 375
368 if( (i = todo( uid )) != 0 ) 376 if( (i = todo( uid )) != 0 )
369 return i; 377 return i;
370 if( (i = event( uid )) != 0 ) 378 if( (i = event( uid )) != 0 )
371 return i; 379 return i;
372 if( (i = journal( uid )) != 0 ) 380 if( (i = journal( uid )) != 0 )
373 return i; 381 return i;
374 382
375 return 0; 383 return 0;
376} 384}
377 385
378QPtrList<Todo> Calendar::todos() 386QPtrList<Todo> Calendar::todos()
379{ 387{
380 QPtrList<Todo> tl = rawTodos(); 388 QPtrList<Todo> tl = rawTodos();
381 mFilter->apply( &tl ); 389 mFilter->apply( &tl );
382 return tl; 390 return tl;
383} 391}
384 392
385// When this is called, the todo have already been added to the calendar. 393// When this is called, the todo have already been added to the calendar.
386// This method is only about linking related todos 394// This method is only about linking related todos
387void Calendar::setupRelations( Incidence *incidence ) 395void Calendar::setupRelations( Incidence *incidence )
388{ 396{
389 QString uid = incidence->uid(); 397 QString uid = incidence->uid();
390 //qDebug("Calendar::setupRelations "); 398 //qDebug("Calendar::setupRelations ");
391 // First, go over the list of orphans and see if this is their parent 399 // First, go over the list of orphans and see if this is their parent
392 while( Incidence* i = mOrphans[ uid ] ) { 400 while( Incidence* i = mOrphans[ uid ] ) {
393 mOrphans.remove( uid ); 401 mOrphans.remove( uid );
394 i->setRelatedTo( incidence ); 402 i->setRelatedTo( incidence );
395 incidence->addRelation( i ); 403 incidence->addRelation( i );
396 mOrphanUids.remove( i->uid() ); 404 mOrphanUids.remove( i->uid() );
397 } 405 }
398 406
399 // Now see about this incidences parent 407 // Now see about this incidences parent
400 if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) { 408 if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) {
401 // This incidence has a uid it is related to, but is not registered to it yet 409 // This incidence has a uid it is related to, but is not registered to it yet
402 // Try to find it 410 // Try to find it
403 Incidence* parent = this->incidence( incidence->relatedToUid() ); 411 Incidence* parent = this->incidence( incidence->relatedToUid() );
404 if( parent ) { 412 if( parent ) {
405 // Found it 413 // Found it
406 incidence->setRelatedTo( parent ); 414 incidence->setRelatedTo( parent );
407 parent->addRelation( incidence ); 415 parent->addRelation( incidence );
408 } else { 416 } else {
409 // Not found, put this in the mOrphans list 417 // Not found, put this in the mOrphans list
410 mOrphans.insert( incidence->relatedToUid(), incidence ); 418 mOrphans.insert( incidence->relatedToUid(), incidence );
411 mOrphanUids.insert( incidence->uid(), incidence ); 419 mOrphanUids.insert( incidence->uid(), incidence );
412 } 420 }
413 } 421 }
414} 422}
415 423
416// If a task with subtasks is deleted, move it's subtasks to the orphans list 424// If a task with subtasks is deleted, move it's subtasks to the orphans list
417void Calendar::removeRelations( Incidence *incidence ) 425void Calendar::removeRelations( Incidence *incidence )
418{ 426{
419 // qDebug("Calendar::removeRelations "); 427 // qDebug("Calendar::removeRelations ");
420 QString uid = incidence->uid(); 428 QString uid = incidence->uid();
421 429
422 QPtrList<Incidence> relations = incidence->relations(); 430 QPtrList<Incidence> relations = incidence->relations();
423 for( Incidence* i = relations.first(); i; i = relations.next() ) 431 for( Incidence* i = relations.first(); i; i = relations.next() )
424 if( !mOrphanUids.find( i->uid() ) ) { 432 if( !mOrphanUids.find( i->uid() ) ) {
425 mOrphans.insert( uid, i ); 433 mOrphans.insert( uid, i );
426 mOrphanUids.insert( i->uid(), i ); 434 mOrphanUids.insert( i->uid(), i );
427 i->setRelatedTo( 0 ); 435 i->setRelatedTo( 0 );
428 i->setRelatedToUid( uid ); 436 i->setRelatedToUid( uid );
429 } 437 }
430 438
431 // If this incidence is related to something else, tell that about it 439 // If this incidence is related to something else, tell that about it
432 if( incidence->relatedTo() ) 440 if( incidence->relatedTo() )
433 incidence->relatedTo()->removeRelation( incidence ); 441 incidence->relatedTo()->removeRelation( incidence );
434 442
435 // Remove this one from the orphans list 443 // Remove this one from the orphans list
436 if( mOrphanUids.remove( uid ) ) 444 if( mOrphanUids.remove( uid ) )
437 // This incidence is located in the orphans list - it should be removed 445 // This incidence is located in the orphans list - it should be removed
438 if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) { 446 if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) {
439 // Removing wasn't that easy 447 // Removing wasn't that easy
440 for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) { 448 for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) {
441 if( it.current()->uid() == uid ) { 449 if( it.current()->uid() == uid ) {
442 mOrphans.remove( it.currentKey() ); 450 mOrphans.remove( it.currentKey() );
443 break; 451 break;
444 } 452 }
445 } 453 }
446 } 454 }
447} 455}
diff --git a/libkcal/calendar.h b/libkcal/calendar.h
index ab40970..4c6760f 100644
--- a/libkcal/calendar.h
+++ b/libkcal/calendar.h
@@ -209,151 +209,158 @@ public:
209 Remove a todo from the todolist. 209 Remove a todo from the todolist.
210 */ 210 */
211 virtual void deleteTodo( Todo * ) = 0; 211 virtual void deleteTodo( Todo * ) = 0;
212 virtual void deleteJournal( Journal * ) = 0; 212 virtual void deleteJournal( Journal * ) = 0;
213 /** 213 /**
214 Return filterd list of todos. 214 Return filterd list of todos.
215 */ 215 */
216 virtual QPtrList<Todo> todos(); 216 virtual QPtrList<Todo> todos();
217 /** 217 /**
218 Searches todolist for an event with this unique string identifier, 218 Searches todolist for an event with this unique string identifier,
219 returns a pointer or null. 219 returns a pointer or null.
220 */ 220 */
221 virtual Todo *todo( const QString &uid ) = 0; 221 virtual Todo *todo( const QString &uid ) = 0;
222 virtual Todo *todo( QString, QString ) = 0; 222 virtual Todo *todo( QString, QString ) = 0;
223 /** 223 /**
224 Returns list of todos due on the specified date. 224 Returns list of todos due on the specified date.
225 */ 225 */
226 virtual QPtrList<Todo> todos( const QDate &date ) = 0; 226 virtual QPtrList<Todo> todos( const QDate &date ) = 0;
227 /** 227 /**
228 Return unfiltered list of todos. 228 Return unfiltered list of todos.
229 */ 229 */
230 virtual QPtrList<Todo> rawTodos() = 0; 230 virtual QPtrList<Todo> rawTodos() = 0;
231 231
232 /** 232 /**
233 Add a Journal entry to calendar. 233 Add a Journal entry to calendar.
234 234
235 @return true on success, false on error. 235 @return true on success, false on error.
236 */ 236 */
237 virtual bool addJournal( Journal * ) = 0; 237 virtual bool addJournal( Journal * ) = 0;
238 /** 238 /**
239 Return Journal for given date. 239 Return Journal for given date.
240 */ 240 */
241 virtual Journal *journal( const QDate & ) = 0; 241 virtual Journal *journal( const QDate & ) = 0;
242 /** 242 /**
243 Return Journal with given UID. 243 Return Journal with given UID.
244 */ 244 */
245 virtual Journal *journal( const QString &UID ) = 0; 245 virtual Journal *journal( const QString &UID ) = 0;
246 /** 246 /**
247 Return list of all Journal entries. 247 Return list of all Journal entries.
248 */ 248 */
249 virtual QPtrList<Journal> journals() = 0; 249 virtual QPtrList<Journal> journals() = 0;
250 250
251 /** 251 /**
252 Searches all incidence types for an incidence with this unique 252 Searches all incidence types for an incidence with this unique
253 string identifier, returns a pointer or null. 253 string identifier, returns a pointer or null.
254 */ 254 */
255 Incidence* incidence( const QString&UID ); 255 Incidence* incidence( const QString&UID );
256 256
257 /** 257 /**
258 Setup relations for an incidence. 258 Setup relations for an incidence.
259 */ 259 */
260 virtual void setupRelations( Incidence * ); 260 virtual void setupRelations( Incidence * );
261 /** 261 /**
262 Remove all relations to an incidence 262 Remove all relations to an incidence
263 */ 263 */
264 virtual void removeRelations( Incidence * ); 264 virtual void removeRelations( Incidence * );
265 265
266 /** 266 /**
267 Set calendar filter, which filters events for the events() functions. 267 Set calendar filter, which filters events for the events() functions.
268 The Filter object is owned by the caller. 268 The Filter object is owned by the caller.
269 */ 269 */
270 void setFilter( CalFilter * ); 270 void setFilter( CalFilter * );
271 /** 271 /**
272 Return calendar filter. 272 Return calendar filter.
273 */ 273 */
274 CalFilter *filter(); 274 CalFilter *filter();
275 virtual QDateTime nextAlarm( int daysTo ) = 0; 275 virtual QDateTime nextAlarm( int daysTo ) = 0;
276 virtual QString nextSummary( ) const = 0; 276 virtual QString nextSummary( ) const = 0;
277 virtual void reInitAlarmSettings() = 0; 277 virtual void reInitAlarmSettings() = 0;
278 virtual QDateTime nextAlarmEventDateTime() const = 0; 278 virtual QDateTime nextAlarmEventDateTime() const = 0;
279 virtual void checkAlarmForIncidence( Incidence *, bool ) = 0; 279 virtual void checkAlarmForIncidence( Incidence *, bool ) = 0;
280 /** 280 /**
281 Return all alarms, which ocur in the given time interval. 281 Return all alarms, which ocur in the given time interval.
282 */ 282 */
283 virtual Alarm::List alarms( const QDateTime &from, 283 virtual Alarm::List alarms( const QDateTime &from,
284 const QDateTime &to ) = 0; 284 const QDateTime &to ) = 0;
285 285
286 class Observer { 286 class Observer {
287 public: 287 public:
288 virtual void calendarModified( bool, Calendar * ) = 0; 288 virtual void calendarModified( bool, Calendar * ) = 0;
289 }; 289 };
290 290
291 void registerObserver( Observer * ); 291 void registerObserver( Observer * );
292 292
293 void setModified( bool ); 293 void setModified( bool );
294 294
295 /** 295 /**
296 Set product id returned by loadedProductId(). This function is only 296 Set product id returned by loadedProductId(). This function is only
297 useful for the calendar loading code. 297 useful for the calendar loading code.
298 */ 298 */
299 void setLoadedProductId( const QString & ); 299 void setLoadedProductId( const QString & );
300 /** 300 /**
301 Return product id taken from file that has been loaded. Returns 301 Return product id taken from file that has been loaded. Returns
302 QString::null, if no calendar has been loaded. 302 QString::null, if no calendar has been loaded.
303 */ 303 */
304 QString loadedProductId(); 304 QString loadedProductId();
305 305 void setDefaultCalendar( int );
306 int defaultCalendar();
307 virtual void setCalendarEnabled( int id, bool enable ) = 0;
308 virtual void setAlarmEnabled( int id, bool enable ) = 0;
309 virtual void setDefaultCalendarEnabledOnly() = 0;
306 signals: 310 signals:
307 void calendarChanged(); 311 void calendarChanged();
308 void calendarSaved(); 312 void calendarSaved();
309 void calendarLoaded(); 313 void calendarLoaded();
310 void addAlarm(const QDateTime &qdt, const QString &noti ); 314 void addAlarm(const QDateTime &qdt, const QString &noti );
311 void removeAlarm(const QDateTime &qdt, const QString &noti ); 315 void removeAlarm(const QDateTime &qdt, const QString &noti );
312 316
313 protected: 317 protected:
314 /** 318 /**
315 Get unfiltered events, which occur on the given date. 319 Get unfiltered events, which occur on the given date.
316 */ 320 */
317 virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0; 321 virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0;
318 /** 322 /**
319 Get unfiltered events, which occur on the given date. 323 Get unfiltered events, which occur on the given date.
320 */ 324 */
321 virtual QPtrList<Event> rawEventsForDate( const QDate &date, 325 virtual QPtrList<Event> rawEventsForDate( const QDate &date,
322 bool sorted = false ) = 0; 326 bool sorted = false ) = 0;
323 /** 327 /**
324 Get events in a range of dates. If inclusive is set to true, only events 328 Get events in a range of dates. If inclusive is set to true, only events
325 are returned, which are completely included in the range. 329 are returned, which are completely included in the range.
326 */ 330 */
327 virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end, 331 virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end,
328 bool inclusive = false ) = 0; 332 bool inclusive = false ) = 0;
333
329 Incidence *mNextAlarmIncidence; 334 Incidence *mNextAlarmIncidence;
330 Incidence *mUndoIncidence; 335 Incidence *mUndoIncidence;
336 int mDefaultCalendar;
331 337
332private: 338private:
333 void init(); 339 void init();
334 340
335 QString mOwner; // who the calendar belongs to 341 QString mOwner; // who the calendar belongs to
336 QString mOwnerEmail; // email address of the owner 342 QString mOwnerEmail; // email address of the owner
337 int mTimeZone; // timezone OFFSET from GMT (MINUTES) 343 int mTimeZone; // timezone OFFSET from GMT (MINUTES)
338 bool mLocalTime; // use local time, not UTC or a time zone 344 bool mLocalTime; // use local time, not UTC or a time zone
339 345
340 CalFilter *mFilter; 346 CalFilter *mFilter;
341 CalFilter *mDefaultFilter; 347 CalFilter *mDefaultFilter;
348
342 349
343 QString mTimeZoneId; 350 QString mTimeZoneId;
344 351
345 Observer *mObserver; 352 Observer *mObserver;
346 bool mNewObserver; 353 bool mNewObserver;
347 354
348 bool mModified; 355 bool mModified;
349 356
350 QString mLoadedProductId; 357 QString mLoadedProductId;
351 358
352 // This list is used to put together related todos 359 // This list is used to put together related todos
353 QDict<Incidence> mOrphans; 360 QDict<Incidence> mOrphans;
354 QDict<Incidence> mOrphanUids; 361 QDict<Incidence> mOrphanUids;
355}; 362};
356 363
357} 364}
358 365
359#endif 366#endif
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp
index fe74052..c5500bf 100644
--- a/libkcal/calendarlocal.cpp
+++ b/libkcal/calendarlocal.cpp
@@ -57,670 +57,726 @@ CalendarLocal::CalendarLocal(const QString &timeZoneId)
57 init(); 57 init();
58} 58}
59 59
60void CalendarLocal::init() 60void CalendarLocal::init()
61{ 61{
62 mNextAlarmIncidence = 0; 62 mNextAlarmIncidence = 0;
63} 63}
64 64
65 65
66CalendarLocal::~CalendarLocal() 66CalendarLocal::~CalendarLocal()
67{ 67{
68 close(); 68 close();
69} 69}
70 70
71bool CalendarLocal::load( const QString &fileName ) 71bool CalendarLocal::load( const QString &fileName )
72{ 72{
73 FileStorage storage( this, fileName ); 73 FileStorage storage( this, fileName );
74 return storage.load(); 74 return storage.load();
75} 75}
76 76
77bool CalendarLocal::save( const QString &fileName, CalFormat *format ) 77bool CalendarLocal::save( const QString &fileName, CalFormat *format )
78{ 78{
79 FileStorage storage( this, fileName, format ); 79 FileStorage storage( this, fileName, format );
80 return storage.save(); 80 return storage.save();
81} 81}
82 82
83void CalendarLocal::close() 83void CalendarLocal::close()
84{ 84{
85 85
86 Todo * i; 86 Todo * i;
87 for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); 87 for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false);
88 88
89 mEventList.setAutoDelete( true ); 89 mEventList.setAutoDelete( true );
90 mTodoList.setAutoDelete( true ); 90 mTodoList.setAutoDelete( true );
91 mJournalList.setAutoDelete( false ); 91 mJournalList.setAutoDelete( false );
92 92
93 mEventList.clear(); 93 mEventList.clear();
94 mTodoList.clear(); 94 mTodoList.clear();
95 mJournalList.clear(); 95 mJournalList.clear();
96 96
97 mEventList.setAutoDelete( false ); 97 mEventList.setAutoDelete( false );
98 mTodoList.setAutoDelete( false ); 98 mTodoList.setAutoDelete( false );
99 mJournalList.setAutoDelete( false ); 99 mJournalList.setAutoDelete( false );
100 100
101 setModified( false ); 101 setModified( false );
102} 102}
103 103
104bool CalendarLocal::addAnniversaryNoDup( Event *event ) 104bool CalendarLocal::addAnniversaryNoDup( Event *event )
105{ 105{
106 QString cat; 106 QString cat;
107 bool isBirthday = true; 107 bool isBirthday = true;
108 if( event->categoriesStr() == i18n( "Anniversary" ) ) { 108 if( event->categoriesStr() == i18n( "Anniversary" ) ) {
109 isBirthday = false; 109 isBirthday = false;
110 cat = i18n( "Anniversary" ); 110 cat = i18n( "Anniversary" );
111 } else if( event->categoriesStr() == i18n( "Birthday" ) ) { 111 } else if( event->categoriesStr() == i18n( "Birthday" ) ) {
112 isBirthday = true; 112 isBirthday = true;
113 cat = i18n( "Birthday" ); 113 cat = i18n( "Birthday" );
114 } else { 114 } else {
115 qDebug("addAnniversaryNoDup called without fitting category! "); 115 qDebug("addAnniversaryNoDup called without fitting category! ");
116 return false; 116 return false;
117 } 117 }
118 Event * eve; 118 Event * eve;
119 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 119 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
120 if ( !(eve->categories().contains( cat ) )) 120 if ( !(eve->categories().contains( cat ) ))
121 continue; 121 continue;
122 // now we have an event with fitting category 122 // now we have an event with fitting category
123 if ( eve->dtStart().date() != event->dtStart().date() ) 123 if ( eve->dtStart().date() != event->dtStart().date() )
124 continue; 124 continue;
125 // now we have an event with fitting category+date 125 // now we have an event with fitting category+date
126 if ( eve->summary() != event->summary() ) 126 if ( eve->summary() != event->summary() )
127 continue; 127 continue;
128 // now we have an event with fitting category+date+summary 128 // now we have an event with fitting category+date+summary
129 return false; 129 return false;
130 } 130 }
131 return addEvent( event ); 131 return addEvent( event );
132 132
133} 133}
134bool CalendarLocal::addEventNoDup( Event *event ) 134bool CalendarLocal::addEventNoDup( Event *event )
135{ 135{
136 Event * eve; 136 Event * eve;
137 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 137 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
138 if ( *eve == *event ) { 138 if ( *eve == *event ) {
139 //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); 139 //qDebug("CalendarLocal::Duplicate event found! Not inserted! ");
140 return false; 140 return false;
141 } 141 }
142 } 142 }
143 return addEvent( event ); 143 return addEvent( event );
144} 144}
145 145
146bool CalendarLocal::addEvent( Event *event ) 146bool CalendarLocal::addEvent( Event *event )
147{ 147{
148 insertEvent( event ); 148 insertEvent( event );
149 149
150 event->registerObserver( this ); 150 event->registerObserver( this );
151 151
152 setModified( true ); 152 setModified( true );
153 event->setCalID( mDefaultCalendar );
154 event->setCalEnabled( true );
153 155
154 return true; 156 return true;
155} 157}
156 158
157void CalendarLocal::deleteEvent( Event *event ) 159void CalendarLocal::deleteEvent( Event *event )
158{ 160{
159 if ( mUndoIncidence ) delete mUndoIncidence; 161 if ( mUndoIncidence ) delete mUndoIncidence;
160 mUndoIncidence = event->clone(); 162 mUndoIncidence = event->clone();
161 if ( mEventList.removeRef( event ) ) { 163 if ( mEventList.removeRef( event ) ) {
162 setModified( true ); 164 setModified( true );
163 } 165 }
164} 166}
165 167
166 168
167Event *CalendarLocal::event( const QString &uid ) 169Event *CalendarLocal::event( const QString &uid )
168{ 170{
169 171
170 Event *event; 172 Event *event;
171 173
172 for ( event = mEventList.first(); event; event = mEventList.next() ) { 174 for ( event = mEventList.first(); event; event = mEventList.next() ) {
173 if ( event->uid() == uid ) { 175 if ( event->uid() == uid && event->calEnabled() ) {
174 return event; 176 return event;
175 } 177 }
176 } 178 }
177 179
178 return 0; 180 return 0;
179} 181}
180bool CalendarLocal::addTodoNoDup( Todo *todo ) 182bool CalendarLocal::addTodoNoDup( Todo *todo )
181{ 183{
182 Todo * eve; 184 Todo * eve;
183 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { 185 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) {
184 if ( *eve == *todo ) { 186 if ( *eve == *todo ) {
185 //qDebug("duplicate todo found! not inserted! "); 187 //qDebug("duplicate todo found! not inserted! ");
186 return false; 188 return false;
187 } 189 }
188 } 190 }
189 return addTodo( todo ); 191 return addTodo( todo );
190} 192}
191bool CalendarLocal::addTodo( Todo *todo ) 193bool CalendarLocal::addTodo( Todo *todo )
192{ 194{
193 mTodoList.append( todo ); 195 mTodoList.append( todo );
194 196
195 todo->registerObserver( this ); 197 todo->registerObserver( this );
196 198
197 // Set up subtask relations 199 // Set up subtask relations
198 setupRelations( todo ); 200 setupRelations( todo );
199 201
200 setModified( true ); 202 setModified( true );
201 203 todo->setCalID( mDefaultCalendar );
204 todo->setCalEnabled( true );
202 return true; 205 return true;
203} 206}
204 207
205void CalendarLocal::deleteTodo( Todo *todo ) 208void CalendarLocal::deleteTodo( Todo *todo )
206{ 209{
207 // Handle orphaned children 210 // Handle orphaned children
208 if ( mUndoIncidence ) delete mUndoIncidence; 211 if ( mUndoIncidence ) delete mUndoIncidence;
209 removeRelations( todo ); 212 removeRelations( todo );
210 mUndoIncidence = todo->clone(); 213 mUndoIncidence = todo->clone();
211 214
212 if ( mTodoList.removeRef( todo ) ) { 215 if ( mTodoList.removeRef( todo ) ) {
213 setModified( true ); 216 setModified( true );
214 } 217 }
215} 218}
216 219
217QPtrList<Todo> CalendarLocal::rawTodos() 220QPtrList<Todo> CalendarLocal::rawTodos()
218{ 221{
219 return mTodoList; 222 QPtrList<Todo> el;
223 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
224 if ( it->calEnabled() ) el.append( it );
225 return el;
220} 226}
221Todo *CalendarLocal::todo( QString syncProf, QString id ) 227Todo *CalendarLocal::todo( QString syncProf, QString id )
222{ 228{
223 Todo *todo; 229 Todo *todo;
224 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 230 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
225 if ( todo->getID( syncProf ) == id ) return todo; 231 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo;
226 } 232 }
227 233
228 return 0; 234 return 0;
229} 235}
230void CalendarLocal::removeSyncInfo( QString syncProfile) 236void CalendarLocal::removeSyncInfo( QString syncProfile)
231{ 237{
232 QPtrList<Incidence> all = rawIncidences() ; 238 QPtrList<Incidence> all = rawIncidences() ;
233 Incidence *inc; 239 Incidence *inc;
234 for ( inc = all.first(); inc; inc = all.next() ) { 240 for ( inc = all.first(); inc; inc = all.next() ) {
235 inc->removeID( syncProfile ); 241 inc->removeID( syncProfile );
236 } 242 }
237 if ( syncProfile.isEmpty() ) { 243 if ( syncProfile.isEmpty() ) {
238 QPtrList<Event> el; 244 QPtrList<Event> el;
239 Event *todo; 245 Event *todo;
240 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 246 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
241 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) 247 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
242 el.append( todo ); 248 el.append( todo );
243 } 249 }
244 for ( todo = el.first(); todo; todo = el.next() ) { 250 for ( todo = el.first(); todo; todo = el.next() ) {
245 deleteIncidence ( todo ); 251 deleteIncidence ( todo );
246 } 252 }
247 } else { 253 } else {
248 Event *lse = event( "last-syncEvent-"+ syncProfile); 254 Event *lse = event( "last-syncEvent-"+ syncProfile);
249 if ( lse ) 255 if ( lse )
250 deleteIncidence ( lse ); 256 deleteIncidence ( lse );
251 } 257 }
252} 258}
253QPtrList<Event> CalendarLocal::getExternLastSyncEvents() 259QPtrList<Event> CalendarLocal::getExternLastSyncEvents()
254{ 260{
255 QPtrList<Event> el; 261 QPtrList<Event> el;
256 Event *todo; 262 Event *todo;
257 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 263 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
258 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) 264 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
259 if ( todo->summary().left(3) == "E: " ) 265 if ( todo->summary().left(3) == "E: " )
260 el.append( todo ); 266 el.append( todo );
261 } 267 }
262 268
263 return el; 269 return el;
264 270
265} 271}
266Event *CalendarLocal::event( QString syncProf, QString id ) 272Event *CalendarLocal::event( QString syncProf, QString id )
267{ 273{
268 Event *todo; 274 Event *todo;
269 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 275 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
270 if ( todo->getID( syncProf ) == id ) return todo; 276 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo;
271 } 277 }
272 278
273 return 0; 279 return 0;
274} 280}
275Todo *CalendarLocal::todo( const QString &uid ) 281Todo *CalendarLocal::todo( const QString &uid )
276{ 282{
277 Todo *todo; 283 Todo *todo;
278 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 284 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
279 if ( todo->uid() == uid ) return todo; 285 if ( todo->calEnabled() && todo->uid() == uid ) return todo;
280 } 286 }
281 287
282 return 0; 288 return 0;
283} 289}
284QString CalendarLocal::nextSummary() const 290QString CalendarLocal::nextSummary() const
285{ 291{
286 return mNextSummary; 292 return mNextSummary;
287} 293}
288QDateTime CalendarLocal::nextAlarmEventDateTime() const 294QDateTime CalendarLocal::nextAlarmEventDateTime() const
289{ 295{
290 return mNextAlarmEventDateTime; 296 return mNextAlarmEventDateTime;
291} 297}
292void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) 298void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted)
293{ 299{
294 //mNextAlarmIncidence 300 //mNextAlarmIncidence
295 //mNextAlarmDateTime 301 //mNextAlarmDateTime
296 //return mNextSummary; 302 //return mNextSummary;
297 //return mNextAlarmEventDateTime; 303 //return mNextAlarmEventDateTime;
298 bool newNextAlarm = false; 304 bool newNextAlarm = false;
299 bool computeNextAlarm = false; 305 bool computeNextAlarm = false;
300 bool ok; 306 bool ok;
301 int offset; 307 int offset;
302 QDateTime nextA; 308 QDateTime nextA;
303 // QString nextSum; 309 // QString nextSum;
304 //QDateTime nextEvent; 310 //QDateTime nextEvent;
305 if ( mNextAlarmIncidence == 0 || incidence == 0 ) { 311 if ( mNextAlarmIncidence == 0 || incidence == 0 ) {
306 computeNextAlarm = true; 312 computeNextAlarm = true;
307 } else { 313 } else {
308 if ( ! deleted ) { 314 if ( ! deleted ) {
309 nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; 315 nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
310 if ( ok ) { 316 if ( ok ) {
311 if ( nextA < mNextAlarmDateTime ) { 317 if ( nextA < mNextAlarmDateTime ) {
312 deRegisterAlarm(); 318 deRegisterAlarm();
313 mNextAlarmDateTime = nextA; 319 mNextAlarmDateTime = nextA;
314 mNextSummary = incidence->summary(); 320 mNextSummary = incidence->summary();
315 mNextAlarmEventDateTime = nextA.addSecs(offset ) ; 321 mNextAlarmEventDateTime = nextA.addSecs(offset ) ;
316 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); 322 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime);
317 newNextAlarm = true; 323 newNextAlarm = true;
318 mNextAlarmIncidence = incidence; 324 mNextAlarmIncidence = incidence;
319 } else { 325 } else {
320 if ( incidence == mNextAlarmIncidence ) { 326 if ( incidence == mNextAlarmIncidence ) {
321 computeNextAlarm = true; 327 computeNextAlarm = true;
322 } 328 }
323 } 329 }
324 } else { 330 } else {
325 if ( mNextAlarmIncidence == incidence ) { 331 if ( mNextAlarmIncidence == incidence ) {
326 computeNextAlarm = true; 332 computeNextAlarm = true;
327 } 333 }
328 } 334 }
329 } else { // deleted 335 } else { // deleted
330 if ( incidence == mNextAlarmIncidence ) { 336 if ( incidence == mNextAlarmIncidence ) {
331 computeNextAlarm = true; 337 computeNextAlarm = true;
332 } 338 }
333 } 339 }
334 } 340 }
335 if ( computeNextAlarm ) { 341 if ( computeNextAlarm ) {
336 deRegisterAlarm(); 342 deRegisterAlarm();
337 nextA = nextAlarm( 1000 ); 343 nextA = nextAlarm( 1000 );
338 if (! mNextAlarmIncidence ) { 344 if (! mNextAlarmIncidence ) {
339 return; 345 return;
340 } 346 }
341 newNextAlarm = true; 347 newNextAlarm = true;
342 } 348 }
343 if ( newNextAlarm ) 349 if ( newNextAlarm )
344 registerAlarm(); 350 registerAlarm();
345} 351}
346QString CalendarLocal:: getAlarmNotification() 352QString CalendarLocal:: getAlarmNotification()
347{ 353{
348 QString ret; 354 QString ret;
349 // this should not happen 355 // this should not happen
350 if (! mNextAlarmIncidence ) 356 if (! mNextAlarmIncidence )
351 return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; 357 return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString;
352 Alarm* alarm = mNextAlarmIncidence->alarms().first(); 358 Alarm* alarm = mNextAlarmIncidence->alarms().first();
353 if ( alarm->type() == Alarm::Procedure ) { 359 if ( alarm->type() == Alarm::Procedure ) {
354 ret = "proc_alarm" + alarm->programFile()+"+++"; 360 ret = "proc_alarm" + alarm->programFile()+"+++";
355 } else { 361 } else {
356 ret = "audio_alarm" +alarm->audioFile() +"+++"; 362 ret = "audio_alarm" +alarm->audioFile() +"+++";
357 } 363 }
358 ret += "cal_alarm"+ mNextSummary.left( 25 ); 364 ret += "cal_alarm"+ mNextSummary.left( 25 );
359 if ( mNextSummary.length() > 25 ) 365 if ( mNextSummary.length() > 25 )
360 ret += "\n" + mNextSummary.mid(25, 25 ); 366 ret += "\n" + mNextSummary.mid(25, 25 );
361 ret+= "\n"+mNextAlarmEventDateTimeString; 367 ret+= "\n"+mNextAlarmEventDateTimeString;
362 return ret; 368 return ret;
363} 369}
364void CalendarLocal::registerAlarm() 370void CalendarLocal::registerAlarm()
365{ 371{
366 mLastAlarmNotificationString = getAlarmNotification(); 372 mLastAlarmNotificationString = getAlarmNotification();
367 // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); 373 // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() );
368 emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); 374 emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString );
369// #ifndef DESKTOP_VERSION 375// #ifndef DESKTOP_VERSION
370// AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); 376// AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() );
371// #endif 377// #endif
372} 378}
373void CalendarLocal::deRegisterAlarm() 379void CalendarLocal::deRegisterAlarm()
374{ 380{
375 if ( mLastAlarmNotificationString.isNull() ) 381 if ( mLastAlarmNotificationString.isNull() )
376 return; 382 return;
377 //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); 383 //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() );
378 384
379 emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); 385 emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString );
380 mNextAlarmEventDateTime = QDateTime(); 386 mNextAlarmEventDateTime = QDateTime();
381// #ifndef DESKTOP_VERSION 387// #ifndef DESKTOP_VERSION
382// AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); 388// AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() );
383// #endif 389// #endif
384} 390}
385 391
386QPtrList<Todo> CalendarLocal::todos( const QDate &date ) 392QPtrList<Todo> CalendarLocal::todos( const QDate &date )
387{ 393{
388 QPtrList<Todo> todos; 394 QPtrList<Todo> todos;
389 395
390 Todo *todo; 396 Todo *todo;
391 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 397 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
398 if ( !todo->calEnabled() ) continue;
392 if ( todo->hasDueDate() && todo->dtDue().date() == date ) { 399 if ( todo->hasDueDate() && todo->dtDue().date() == date ) {
393 todos.append( todo ); 400 todos.append( todo );
394 } 401 }
395 } 402 }
396 403
397 filter()->apply( &todos ); 404 filter()->apply( &todos );
398 return todos; 405 return todos;
399} 406}
400void CalendarLocal::reInitAlarmSettings() 407void CalendarLocal::reInitAlarmSettings()
401{ 408{
402 if ( !mNextAlarmIncidence ) { 409 if ( !mNextAlarmIncidence ) {
403 nextAlarm( 1000 ); 410 nextAlarm( 1000 );
404 } 411 }
405 deRegisterAlarm(); 412 deRegisterAlarm();
406 mNextAlarmIncidence = 0; 413 mNextAlarmIncidence = 0;
407 checkAlarmForIncidence( 0, false ); 414 checkAlarmForIncidence( 0, false );
408 415
409} 416}
410 417
411 418
412 419
413QDateTime CalendarLocal::nextAlarm( int daysTo ) 420QDateTime CalendarLocal::nextAlarm( int daysTo )
414{ 421{
415 QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); 422 QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo );
416 QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); 423 QDateTime start = QDateTime::currentDateTime().addSecs( 30 );
417 QDateTime next; 424 QDateTime next;
418 Event *e; 425 Event *e;
419 bool ok; 426 bool ok;
420 bool found = false; 427 bool found = false;
421 int offset; 428 int offset;
422 mNextAlarmIncidence = 0; 429 mNextAlarmIncidence = 0;
423 for( e = mEventList.first(); e; e = mEventList.next() ) { 430 for( e = mEventList.first(); e; e = mEventList.next() ) {
431 if ( !e->calEnabled() ) continue;
424 next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; 432 next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
425 if ( ok ) { 433 if ( ok ) {
426 if ( next < nextA ) { 434 if ( next < nextA ) {
427 nextA = next; 435 nextA = next;
428 found = true; 436 found = true;
429 mNextSummary = e->summary(); 437 mNextSummary = e->summary();
430 mNextAlarmEventDateTime = next.addSecs(offset ) ; 438 mNextAlarmEventDateTime = next.addSecs(offset ) ;
431 mNextAlarmIncidence = (Incidence *) e; 439 mNextAlarmIncidence = (Incidence *) e;
432 } 440 }
433 } 441 }
434 } 442 }
435 Todo *t; 443 Todo *t;
436 for( t = mTodoList.first(); t; t = mTodoList.next() ) { 444 for( t = mTodoList.first(); t; t = mTodoList.next() ) {
445 if ( !t->calEnabled() ) continue;
437 next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; 446 next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
438 if ( ok ) { 447 if ( ok ) {
439 if ( next < nextA ) { 448 if ( next < nextA ) {
440 nextA = next; 449 nextA = next;
441 found = true; 450 found = true;
442 mNextSummary = t->summary(); 451 mNextSummary = t->summary();
443 mNextAlarmEventDateTime = next.addSecs(offset ); 452 mNextAlarmEventDateTime = next.addSecs(offset );
444 mNextAlarmIncidence = (Incidence *) t; 453 mNextAlarmIncidence = (Incidence *) t;
445 } 454 }
446 } 455 }
447 } 456 }
448 if ( mNextAlarmIncidence ) { 457 if ( mNextAlarmIncidence ) {
449 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); 458 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime);
450 mNextAlarmDateTime = nextA; 459 mNextAlarmDateTime = nextA;
451 } 460 }
452 return nextA; 461 return nextA;
453} 462}
454Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) 463Alarm::List CalendarLocal::alarmsTo( const QDateTime &to )
455{ 464{
456 return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); 465 return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to );
457} 466}
458 467
459Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) 468Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to )
460{ 469{
461 470
462 Alarm::List alarms; 471 Alarm::List alarms;
463 472
464 Event *e; 473 Event *e;
465 474
466 for( e = mEventList.first(); e; e = mEventList.next() ) { 475 for( e = mEventList.first(); e; e = mEventList.next() ) {
476 if ( !e->calEnabled() ) continue;
467 if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); 477 if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to );
468 else appendAlarms( alarms, e, from, to ); 478 else appendAlarms( alarms, e, from, to );
469 } 479 }
470 480
471 Todo *t; 481 Todo *t;
472 for( t = mTodoList.first(); t; t = mTodoList.next() ) { 482 for( t = mTodoList.first(); t; t = mTodoList.next() ) {
473 appendAlarms( alarms, t, from, to ); 483 if ( !t->calEnabled() ) continue;
484 appendAlarms( alarms, t, from, to );
474 } 485 }
475 486
476 return alarms; 487 return alarms;
477} 488}
478 489
479void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, 490void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence,
480 const QDateTime &from, const QDateTime &to ) 491 const QDateTime &from, const QDateTime &to )
481{ 492{
482 QPtrList<Alarm> alarmList = incidence->alarms(); 493 QPtrList<Alarm> alarmList = incidence->alarms();
483 Alarm *alarm; 494 Alarm *alarm;
484 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { 495 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) {
485// kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() 496// kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text()
486// << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; 497// << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl;
487 if ( alarm->enabled() ) { 498 if ( alarm->enabled() ) {
488 if ( alarm->time() >= from && alarm->time() <= to ) { 499 if ( alarm->time() >= from && alarm->time() <= to ) {
489 alarms.append( alarm ); 500 alarms.append( alarm );
490 } 501 }
491 } 502 }
492 } 503 }
493} 504}
494 505
495void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, 506void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms,
496 Incidence *incidence, 507 Incidence *incidence,
497 const QDateTime &from, 508 const QDateTime &from,
498 const QDateTime &to ) 509 const QDateTime &to )
499{ 510{
500 511
501 QPtrList<Alarm> alarmList = incidence->alarms(); 512 QPtrList<Alarm> alarmList = incidence->alarms();
502 Alarm *alarm; 513 Alarm *alarm;
503 QDateTime qdt; 514 QDateTime qdt;
504 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { 515 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) {
505 if (incidence->recursOn(from.date())) { 516 if (incidence->recursOn(from.date())) {
506 qdt.setTime(alarm->time().time()); 517 qdt.setTime(alarm->time().time());
507 qdt.setDate(from.date()); 518 qdt.setDate(from.date());
508 } 519 }
509 else qdt = alarm->time(); 520 else qdt = alarm->time();
510 // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); 521 // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1());
511 if ( alarm->enabled() ) { 522 if ( alarm->enabled() ) {
512 if ( qdt >= from && qdt <= to ) { 523 if ( qdt >= from && qdt <= to ) {
513 alarms.append( alarm ); 524 alarms.append( alarm );
514 } 525 }
515 } 526 }
516 } 527 }
517} 528}
518 529
519 530
520/****************************** PROTECTED METHODS ****************************/ 531/****************************** PROTECTED METHODS ****************************/
521 532
522// after changes are made to an event, this should be called. 533// after changes are made to an event, this should be called.
523void CalendarLocal::update( IncidenceBase *incidence ) 534void CalendarLocal::update( IncidenceBase *incidence )
524{ 535{
525 incidence->setSyncStatus( Event::SYNCMOD ); 536 incidence->setSyncStatus( Event::SYNCMOD );
526 incidence->setLastModified( QDateTime::currentDateTime() ); 537 incidence->setLastModified( QDateTime::currentDateTime() );
527 // we should probably update the revision number here, 538 // we should probably update the revision number here,
528 // or internally in the Event itself when certain things change. 539 // or internally in the Event itself when certain things change.
529 // need to verify with ical documentation. 540 // need to verify with ical documentation.
530 541
531 setModified( true ); 542 setModified( true );
532} 543}
533 544
534void CalendarLocal::insertEvent( Event *event ) 545void CalendarLocal::insertEvent( Event *event )
535{ 546{
536 if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); 547 if ( mEventList.findRef( event ) < 0 ) mEventList.append( event );
537} 548}
538 549
539 550
540QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) 551QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted )
541{ 552{
542 QPtrList<Event> eventList; 553 QPtrList<Event> eventList;
543 554
544 Event *event; 555 Event *event;
545 for( event = mEventList.first(); event; event = mEventList.next() ) { 556 for( event = mEventList.first(); event; event = mEventList.next() ) {
557 if ( !event->calEnabled() ) continue;
546 if ( event->doesRecur() ) { 558 if ( event->doesRecur() ) {
547 if ( event->isMultiDay() ) { 559 if ( event->isMultiDay() ) {
548 int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); 560 int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() );
549 int i; 561 int i;
550 for ( i = 0; i <= extraDays; i++ ) { 562 for ( i = 0; i <= extraDays; i++ ) {
551 if ( event->recursOn( qd.addDays( -i ) ) ) { 563 if ( event->recursOn( qd.addDays( -i ) ) ) {
552 eventList.append( event ); 564 eventList.append( event );
553 break; 565 break;
554 } 566 }
555 } 567 }
556 } else { 568 } else {
557 if ( event->recursOn( qd ) ) 569 if ( event->recursOn( qd ) )
558 eventList.append( event ); 570 eventList.append( event );
559 } 571 }
560 } else { 572 } else {
561 if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { 573 if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) {
562 eventList.append( event ); 574 eventList.append( event );
563 } 575 }
564 } 576 }
565 } 577 }
566 578
567 if ( !sorted ) { 579 if ( !sorted ) {
568 return eventList; 580 return eventList;
569 } 581 }
570 582
571 // kdDebug(5800) << "Sorting events for date\n" << endl; 583 // kdDebug(5800) << "Sorting events for date\n" << endl;
572 // now, we have to sort it based on dtStart.time() 584 // now, we have to sort it based on dtStart.time()
573 QPtrList<Event> eventListSorted; 585 QPtrList<Event> eventListSorted;
574 Event *sortEvent; 586 Event *sortEvent;
575 for ( event = eventList.first(); event; event = eventList.next() ) { 587 for ( event = eventList.first(); event; event = eventList.next() ) {
576 sortEvent = eventListSorted.first(); 588 sortEvent = eventListSorted.first();
577 int i = 0; 589 int i = 0;
578 while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) 590 while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() )
579 { 591 {
580 i++; 592 i++;
581 sortEvent = eventListSorted.next(); 593 sortEvent = eventListSorted.next();
582 } 594 }
583 eventListSorted.insert( i, event ); 595 eventListSorted.insert( i, event );
584 } 596 }
585 return eventListSorted; 597 return eventListSorted;
586} 598}
587 599
588 600
589QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, 601QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end,
590 bool inclusive ) 602 bool inclusive )
591{ 603{
592 Event *event = 0; 604 Event *event = 0;
593 605
594 QPtrList<Event> eventList; 606 QPtrList<Event> eventList;
595 607
596 // Get non-recurring events 608 // Get non-recurring events
597 for( event = mEventList.first(); event; event = mEventList.next() ) { 609 for( event = mEventList.first(); event; event = mEventList.next() ) {
610 if ( !event->calEnabled() ) continue;
598 if ( event->doesRecur() ) { 611 if ( event->doesRecur() ) {
599 QDate rStart = event->dtStart().date(); 612 QDate rStart = event->dtStart().date();
600 bool found = false; 613 bool found = false;
601 if ( inclusive ) { 614 if ( inclusive ) {
602 if ( rStart >= start && rStart <= end ) { 615 if ( rStart >= start && rStart <= end ) {
603 // Start date of event is in range. Now check for end date. 616 // Start date of event is in range. Now check for end date.
604 // if duration is negative, event recurs forever, so do not include it. 617 // if duration is negative, event recurs forever, so do not include it.
605 if ( event->recurrence()->duration() == 0 ) { // End date set 618 if ( event->recurrence()->duration() == 0 ) { // End date set
606 QDate rEnd = event->recurrence()->endDate(); 619 QDate rEnd = event->recurrence()->endDate();
607 if ( rEnd >= start && rEnd <= end ) { // End date within range 620 if ( rEnd >= start && rEnd <= end ) { // End date within range
608 found = true; 621 found = true;
609 } 622 }
610 } else if ( event->recurrence()->duration() > 0 ) { // Duration set 623 } else if ( event->recurrence()->duration() > 0 ) { // Duration set
611 // TODO: Calculate end date from duration. Should be done in Event 624 // TODO: Calculate end date from duration. Should be done in Event
612 // For now exclude all events with a duration. 625 // For now exclude all events with a duration.
613 } 626 }
614 } 627 }
615 } else { 628 } else {
616 bool founOne; 629 bool founOne;
617 QDate next = event->getNextOccurence( start, &founOne ).date(); 630 QDate next = event->getNextOccurence( start, &founOne ).date();
618 if ( founOne ) { 631 if ( founOne ) {
619 if ( next <= end ) { 632 if ( next <= end ) {
620 found = true; 633 found = true;
621 } 634 }
622 } 635 }
623 636
624 /* 637 /*
625 // crap !!! 638 // crap !!!
626 if ( rStart <= end ) { // Start date not after range 639 if ( rStart <= end ) { // Start date not after range
627 if ( rStart >= start ) { // Start date within range 640 if ( rStart >= start ) { // Start date within range
628 found = true; 641 found = true;
629 } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever 642 } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever
630 found = true; 643 found = true;
631 } else if ( event->recurrence()->duration() == 0 ) { // End date set 644 } else if ( event->recurrence()->duration() == 0 ) { // End date set
632 QDate rEnd = event->recurrence()->endDate(); 645 QDate rEnd = event->recurrence()->endDate();
633 if ( rEnd >= start && rEnd <= end ) { // End date within range 646 if ( rEnd >= start && rEnd <= end ) { // End date within range
634 found = true; 647 found = true;
635 } 648 }
636 } else { // Duration set 649 } else { // Duration set
637 // TODO: Calculate end date from duration. Should be done in Event 650 // TODO: Calculate end date from duration. Should be done in Event
638 // For now include all events with a duration. 651 // For now include all events with a duration.
639 found = true; 652 found = true;
640 } 653 }
641 } 654 }
642 */ 655 */
643 656
644 } 657 }
645 658
646 if ( found ) eventList.append( event ); 659 if ( found ) eventList.append( event );
647 } else { 660 } else {
648 QDate s = event->dtStart().date(); 661 QDate s = event->dtStart().date();
649 QDate e = event->dtEnd().date(); 662 QDate e = event->dtEnd().date();
650 663
651 if ( inclusive ) { 664 if ( inclusive ) {
652 if ( s >= start && e <= end ) { 665 if ( s >= start && e <= end ) {
653 eventList.append( event ); 666 eventList.append( event );
654 } 667 }
655 } else { 668 } else {
656 if ( ( s >= start && s <= end ) || ( e >= start && e <= end ) ) { 669 if ( ( s >= start && s <= end ) || ( e >= start && e <= end ) ) {
657 eventList.append( event ); 670 eventList.append( event );
658 } 671 }
659 } 672 }
660 } 673 }
661 } 674 }
662 675
663 return eventList; 676 return eventList;
664} 677}
665 678
666QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) 679QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt )
667{ 680{
668 return rawEventsForDate( qdt.date() ); 681 return rawEventsForDate( qdt.date() );
669} 682}
670 683
671QPtrList<Event> CalendarLocal::rawEvents() 684QPtrList<Event> CalendarLocal::rawEvents()
672{ 685{
673 return mEventList; 686 QPtrList<Event> el;
687 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
688 if ( it->calEnabled() ) el.append( it );
689 return el;
674} 690}
675 691
676bool CalendarLocal::addJournal(Journal *journal) 692bool CalendarLocal::addJournal(Journal *journal)
677{ 693{
678 if ( journal->dtStart().isValid()) 694 if ( journal->dtStart().isValid())
679 kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl; 695 kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl;
680 else 696 else
681 kdDebug(5800) << "Adding Journal without a DTSTART" << endl; 697 kdDebug(5800) << "Adding Journal without a DTSTART" << endl;
682 698
683 mJournalList.append(journal); 699 mJournalList.append(journal);
684 700
685 journal->registerObserver( this ); 701 journal->registerObserver( this );
686 702
687 setModified( true ); 703 setModified( true );
688 704 journal->setCalID( mDefaultCalendar );
705 journal->setCalEnabled( true );
689 return true; 706 return true;
690} 707}
691 708
692void CalendarLocal::deleteJournal( Journal *journal ) 709void CalendarLocal::deleteJournal( Journal *journal )
693{ 710{
694 if ( mUndoIncidence ) delete mUndoIncidence; 711 if ( mUndoIncidence ) delete mUndoIncidence;
695 mUndoIncidence = journal->clone(); 712 mUndoIncidence = journal->clone();
696 mUndoIncidence->setSummary( mUndoIncidence->description().left(25)); 713 mUndoIncidence->setSummary( mUndoIncidence->description().left(25));
697 if ( mJournalList.removeRef(journal) ) { 714 if ( mJournalList.removeRef(journal) ) {
698 setModified( true ); 715 setModified( true );
699 } 716 }
700} 717}
701 718
702Journal *CalendarLocal::journal( const QDate &date ) 719Journal *CalendarLocal::journal( const QDate &date )
703{ 720{
704// kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; 721// kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl;
705 722
706 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 723 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
707 if ( it->dtStart().date() == date ) 724 if ( it->calEnabled() && it->dtStart().date() == date )
708 return it; 725 return it;
709 726
710 return 0; 727 return 0;
711} 728}
712 729
713Journal *CalendarLocal::journal( const QString &uid ) 730Journal *CalendarLocal::journal( const QString &uid )
714{ 731{
715 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 732 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
716 if ( it->uid() == uid ) 733 if ( it->calEnabled() && it->uid() == uid )
717 return it; 734 return it;
718 735
719 return 0; 736 return 0;
720} 737}
721 738
722QPtrList<Journal> CalendarLocal::journals() 739QPtrList<Journal> CalendarLocal::journals()
723{ 740{
724 return mJournalList; 741 QPtrList<Journal> el;
742 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
743 if ( it->calEnabled() ) el.append( it );
744 return el;
725} 745}
726 746
747void CalendarLocal::setCalendarEnabled( int id, bool enable )
748{
749 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
750 if ( it->calID() == id ) it->setCalEnabled( enable );
751
752 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
753 if ( it->calID() == id ) it->setCalEnabled( enable );
754
755 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
756 if ( it->calID() == id ) it->setCalEnabled( enable );
757
758}
759void CalendarLocal::setAlarmEnabled( int id, bool enable )
760{
761 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
762 if ( it->calID() == id ) it->setAlarmEnabled( enable );
763
764 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
765 if ( it->calID() == id ) it->setAlarmEnabled( enable );
766
767 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
768 if ( it->calID() == id ) it->setAlarmEnabled( enable );
769
770}
771void CalendarLocal::setDefaultCalendarEnabledOnly()
772{
773 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
774 it->setCalEnabled( it->calID() == mDefaultCalendar );
775
776 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
777 it->setCalEnabled( it->calID() == mDefaultCalendar);
778
779 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
780 it->setCalEnabled( it->calID() == mDefaultCalendar);
781
782}
diff --git a/libkcal/calendarlocal.h b/libkcal/calendarlocal.h
index 98ec710..b25fcbe 100644
--- a/libkcal/calendarlocal.h
+++ b/libkcal/calendarlocal.h
@@ -87,132 +87,135 @@ class CalendarLocal : public Calendar
87 */ 87 */
88 QPtrList<Event> rawEvents(); 88 QPtrList<Event> rawEvents();
89 QPtrList<Event> getExternLastSyncEvents(); 89 QPtrList<Event> getExternLastSyncEvents();
90 /** 90 /**
91 Add a todo to the todolist. 91 Add a todo to the todolist.
92 */ 92 */
93 bool addTodo( Todo *todo ); 93 bool addTodo( Todo *todo );
94 bool addTodoNoDup( Todo *todo ); 94 bool addTodoNoDup( Todo *todo );
95 /** 95 /**
96 Remove a todo from the todolist. 96 Remove a todo from the todolist.
97 */ 97 */
98 void deleteTodo( Todo * ); 98 void deleteTodo( Todo * );
99 /** 99 /**
100 Searches todolist for an event with this unique string identifier, 100 Searches todolist for an event with this unique string identifier,
101 returns a pointer or null. 101 returns a pointer or null.
102 */ 102 */
103 Todo *todo( const QString &uid ); 103 Todo *todo( const QString &uid );
104 /** 104 /**
105 Return list of all todos. 105 Return list of all todos.
106 */ 106 */
107 QPtrList<Todo> rawTodos(); 107 QPtrList<Todo> rawTodos();
108 /** 108 /**
109 Returns list of todos due on the specified date. 109 Returns list of todos due on the specified date.
110 */ 110 */
111 QPtrList<Todo> todos( const QDate &date ); 111 QPtrList<Todo> todos( const QDate &date );
112 /** 112 /**
113 Return list of all todos. 113 Return list of all todos.
114 114
115 Workaround because compiler does not recognize function of base class. 115 Workaround because compiler does not recognize function of base class.
116 */ 116 */
117 QPtrList<Todo> todos() { return Calendar::todos(); } 117 QPtrList<Todo> todos() { return Calendar::todos(); }
118 118
119 /** 119 /**
120 Add a Journal entry to calendar. 120 Add a Journal entry to calendar.
121 */ 121 */
122 bool addJournal( Journal * ); 122 bool addJournal( Journal * );
123 /** 123 /**
124 Remove a Journal from the calendar. 124 Remove a Journal from the calendar.
125 */ 125 */
126 void deleteJournal( Journal * ); 126 void deleteJournal( Journal * );
127 /** 127 /**
128 Return Journal for given date. 128 Return Journal for given date.
129 */ 129 */
130 Journal *journal( const QDate & ); 130 Journal *journal( const QDate & );
131 /** 131 /**
132 Return Journal with given UID. 132 Return Journal with given UID.
133 */ 133 */
134 Journal *journal( const QString &uid ); 134 Journal *journal( const QString &uid );
135 /** 135 /**
136 Return list of all Journals stored in calendar. 136 Return list of all Journals stored in calendar.
137 */ 137 */
138 QPtrList<Journal> journals(); 138 QPtrList<Journal> journals();
139 139
140 /** 140 /**
141 Return all alarms, which ocur in the given time interval. 141 Return all alarms, which ocur in the given time interval.
142 */ 142 */
143 Alarm::List alarms( const QDateTime &from, const QDateTime &to ); 143 Alarm::List alarms( const QDateTime &from, const QDateTime &to );
144 144
145 /** 145 /**
146 Return all alarms, which ocur before given date. 146 Return all alarms, which ocur before given date.
147 */ 147 */
148 Alarm::List alarmsTo( const QDateTime &to ); 148 Alarm::List alarmsTo( const QDateTime &to );
149 149
150 QDateTime nextAlarm( int daysTo ) ; 150 QDateTime nextAlarm( int daysTo ) ;
151 QDateTime nextAlarmEventDateTime() const; 151 QDateTime nextAlarmEventDateTime() const;
152 void checkAlarmForIncidence( Incidence *, bool deleted ) ; 152 void checkAlarmForIncidence( Incidence *, bool deleted ) ;
153 void registerAlarm(); 153 void registerAlarm();
154 void deRegisterAlarm(); 154 void deRegisterAlarm();
155 QString getAlarmNotification(); 155 QString getAlarmNotification();
156 QString nextSummary() const ; 156 QString nextSummary() const ;
157 /** 157 /**
158 This method should be called whenever a Event is modified directly 158 This method should be called whenever a Event is modified directly
159 via it's pointer. It makes sure that the calendar is internally 159 via it's pointer. It makes sure that the calendar is internally
160 consistent. 160 consistent.
161 */ 161 */
162 void update( IncidenceBase *incidence ); 162 void update( IncidenceBase *incidence );
163 163
164 /** 164 /**
165 Builds and then returns a list of all events that match for the 165 Builds and then returns a list of all events that match for the
166 date specified. useful for dayView, etc. etc. 166 date specified. useful for dayView, etc. etc.
167 */ 167 */
168 QPtrList<Event> rawEventsForDate( const QDate &date, bool sorted = false ); 168 QPtrList<Event> rawEventsForDate( const QDate &date, bool sorted = false );
169 /** 169 /**
170 Get unfiltered events for date \a qdt. 170 Get unfiltered events for date \a qdt.
171 */ 171 */
172 QPtrList<Event> rawEventsForDate( const QDateTime &qdt ); 172 QPtrList<Event> rawEventsForDate( const QDateTime &qdt );
173 /** 173 /**
174 Get unfiltered events in a range of dates. If inclusive is set to true, 174 Get unfiltered events in a range of dates. If inclusive is set to true,
175 only events are returned, which are completely included in the range. 175 only events are returned, which are completely included in the range.
176 */ 176 */
177 QPtrList<Event> rawEvents( const QDate &start, const QDate &end, 177 QPtrList<Event> rawEvents( const QDate &start, const QDate &end,
178 bool inclusive = false ); 178 bool inclusive = false );
179 Todo *todo( QString, QString ); 179 Todo *todo( QString, QString );
180 Event *event( QString, QString ); 180 Event *event( QString, QString );
181 181
182 182
183 void setCalendarEnabled( int id, bool enable );
184 void setAlarmEnabled( int id, bool enable );
185 void setDefaultCalendarEnabledOnly();
183 186
184 protected: 187 protected:
185 188
186 // Event* mNextAlarmEvent; 189 // Event* mNextAlarmEvent;
187 QString mNextSummary; 190 QString mNextSummary;
188 QString mNextAlarmEventDateTimeString; 191 QString mNextAlarmEventDateTimeString;
189 QString mLastAlarmNotificationString; 192 QString mLastAlarmNotificationString;
190 QDateTime mNextAlarmEventDateTime; 193 QDateTime mNextAlarmEventDateTime;
191 QDateTime mNextAlarmDateTime; 194 QDateTime mNextAlarmDateTime;
192 void reInitAlarmSettings(); 195 void reInitAlarmSettings();
193 196
194 /** Notification function of IncidenceBase::Observer. */ 197 /** Notification function of IncidenceBase::Observer. */
195 void incidenceUpdated( IncidenceBase *i ) { update( i ); } 198 void incidenceUpdated( IncidenceBase *i ) { update( i ); }
196 199
197 /** inserts an event into its "proper place" in the calendar. */ 200 /** inserts an event into its "proper place" in the calendar. */
198 void insertEvent( Event *event ); 201 void insertEvent( Event *event );
199 202
200 /** Append alarms of incidence in interval to list of alarms. */ 203 /** Append alarms of incidence in interval to list of alarms. */
201 void appendAlarms( Alarm::List &alarms, Incidence *incidence, 204 void appendAlarms( Alarm::List &alarms, Incidence *incidence,
202 const QDateTime &from, const QDateTime &to ); 205 const QDateTime &from, const QDateTime &to );
203 206
204 /** Append alarms of recurring events in interval to list of alarms. */ 207 /** Append alarms of recurring events in interval to list of alarms. */
205 void appendRecurringAlarms( Alarm::List &alarms, Incidence *incidence, 208 void appendRecurringAlarms( Alarm::List &alarms, Incidence *incidence,
206 const QDateTime &from, const QDateTime &to ); 209 const QDateTime &from, const QDateTime &to );
207 210
208 private: 211 private:
209 void init(); 212 void init();
210 213
211 QPtrList<Event> mEventList; 214 QPtrList<Event> mEventList;
212 QPtrList<Todo> mTodoList; 215 QPtrList<Todo> mTodoList;
213 QPtrList<Journal> mJournalList; 216 QPtrList<Journal> mJournalList;
214}; 217};
215 218
216} 219}
217 220
218#endif 221#endif
diff --git a/libkcal/calfilter.cpp b/libkcal/calfilter.cpp
index 20078a7..3510c7d 100644
--- a/libkcal/calfilter.cpp
+++ b/libkcal/calfilter.cpp
@@ -1,202 +1,211 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
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 <kdebug.h> 21#include <kdebug.h>
22 22
23#include "calfilter.h" 23#include "calfilter.h"
24 24
25using namespace KCal; 25using namespace KCal;
26 26
27CalFilter::CalFilter() 27CalFilter::CalFilter()
28{ 28{
29 mEnabled = true; 29 mEnabled = true;
30 mCriteria = ShowPublic | ShowPrivate| ShowConfidential ; 30 mCriteria = ShowPublic | ShowPrivate| ShowConfidential ;
31} 31}
32 32
33CalFilter::CalFilter(const QString &name) 33CalFilter::CalFilter(const QString &name)
34{ 34{
35 mName = name; 35 mName = name;
36 mEnabled = true; 36 mEnabled = true;
37 mCriteria = ShowPublic | ShowPrivate| ShowConfidential ; 37 mCriteria = ShowPublic | ShowPrivate| ShowConfidential ;
38} 38}
39 39
40CalFilter::~CalFilter() 40CalFilter::~CalFilter()
41{ 41{
42} 42}
43 43
44void CalFilter::apply(QPtrList<Event> *eventlist) 44void CalFilter::apply(QPtrList<Event> *eventlist)
45{ 45{
46 if (!mEnabled) return; 46 if (!mEnabled) return;
47 47
48// kdDebug(5800) << "CalFilter::apply()" << endl; 48// kdDebug(5800) << "CalFilter::apply()" << endl;
49 49
50 Event *event = eventlist->first(); 50 Event *event = eventlist->first();
51 while(event) { 51 while(event) {
52 if (!filterEvent(event)) { 52 if (!filterEvent(event)) {
53 eventlist->remove(); 53 eventlist->remove();
54 event = eventlist->current(); 54 event = eventlist->current();
55 } else { 55 } else {
56 event = eventlist->next(); 56 event = eventlist->next();
57 } 57 }
58 } 58 }
59 59
60// kdDebug(5800) << "CalFilter::apply() done" << endl; 60// kdDebug(5800) << "CalFilter::apply() done" << endl;
61} 61}
62 62
63// TODO: avoid duplicating apply() code 63// TODO: avoid duplicating apply() code
64void CalFilter::apply(QPtrList<Todo> *eventlist) 64void CalFilter::apply(QPtrList<Todo> *eventlist)
65{ 65{
66 if (!mEnabled) return; 66 if (!mEnabled) return;
67 Todo *event = eventlist->first(); 67 Todo *event = eventlist->first();
68 while(event) { 68 while(event) {
69 if (!filterTodo(event)) { 69 if (!filterTodo(event)) {
70 eventlist->remove(); 70 eventlist->remove();
71 event = eventlist->current(); 71 event = eventlist->current();
72 } else { 72 } else {
73 event = eventlist->next(); 73 event = eventlist->next();
74 } 74 }
75 } 75 }
76 76
77// kdDebug(5800) << "CalFilter::apply() done" << endl; 77// kdDebug(5800) << "CalFilter::apply() done" << endl;
78} 78}
79bool CalFilter::filterCalendarItem(Incidence *in) 79bool CalFilter::filterCalendarItem(Incidence *in)
80{ 80{
81 if ( !in->calEnabled() )
82 return false;
81 if ( in->typeID() == eventID ) 83 if ( in->typeID() == eventID )
82 return filterEvent( (Event*) in ); 84 return filterEvent( (Event*) in );
83 else if ( in->typeID() == todoID ) 85 else if ( in->typeID() == todoID )
84 return filterTodo( (Todo*) in); 86 return filterTodo( (Todo*) in);
85 else if ( in->typeID () == journalID ) 87 else if ( in->typeID () == journalID )
86 return filterJournal( (Journal*) in ); 88 return filterJournal( (Journal*) in );
87 return false; 89 return false;
88} 90}
89bool CalFilter::filterEvent(Event *event) 91bool CalFilter::filterEvent(Event *event)
90{ 92{
93
94 if ( !event->calEnabled() )
95 return false;
91 if (mCriteria & HideEvents) 96 if (mCriteria & HideEvents)
92 return false; 97 return false;
93 if (mCriteria & HideRecurring) { 98 if (mCriteria & HideRecurring) {
94 if (event->recurrence()->doesRecur()) return false; 99 if (event->recurrence()->doesRecur()) return false;
95 } 100 }
96 101
97 return filterIncidence(event); 102 return filterIncidence(event);
98} 103}
99bool CalFilter::filterJournal(Journal *j) 104bool CalFilter::filterJournal(Journal *j)
100{ 105{
106 if ( !j->calEnabled() )
107 return false;
101 if (mCriteria & HideJournals) 108 if (mCriteria & HideJournals)
102 return false; 109 return false;
103 return true; 110 return true;
104} 111}
105bool CalFilter::filterTodo(Todo *todo) 112bool CalFilter::filterTodo(Todo *todo)
106{ 113{
114 if ( !todo->calEnabled() )
115 return false;
107 if (mCriteria & HideTodos) 116 if (mCriteria & HideTodos)
108 return false; 117 return false;
109 if (mCriteria & HideCompleted) { 118 if (mCriteria & HideCompleted) {
110 if (todo->isCompleted()) return false; 119 if (todo->isCompleted()) return false;
111 } 120 }
112 121
113 return filterIncidence(todo); 122 return filterIncidence(todo);
114} 123}
115bool CalFilter::showCategories() 124bool CalFilter::showCategories()
116{ 125{
117 return mCriteria & ShowCategories; 126 return mCriteria & ShowCategories;
118} 127}
119int CalFilter::getSecrecy() 128int CalFilter::getSecrecy()
120{ 129{
121 if ( (mCriteria & ShowPublic )) 130 if ( (mCriteria & ShowPublic ))
122 return Incidence::SecrecyPublic; 131 return Incidence::SecrecyPublic;
123 if ( (mCriteria & ShowPrivate )) 132 if ( (mCriteria & ShowPrivate ))
124 return Incidence::SecrecyPrivate; 133 return Incidence::SecrecyPrivate;
125 if ( (mCriteria & ShowConfidential )) 134 if ( (mCriteria & ShowConfidential ))
126 return Incidence::SecrecyConfidential; 135 return Incidence::SecrecyConfidential;
127 return Incidence::SecrecyPublic; 136 return Incidence::SecrecyPublic;
128} 137}
129bool CalFilter::filterIncidence(Incidence *incidence) 138bool CalFilter::filterIncidence(Incidence *incidence)
130{ 139{
131 if ( mCriteria > 7 ) { 140 if ( mCriteria > 7 ) {
132 switch (incidence->secrecy()) { 141 switch (incidence->secrecy()) {
133 case Incidence::SecrecyPublic: 142 case Incidence::SecrecyPublic:
134 if (! (mCriteria & ShowPublic )) 143 if (! (mCriteria & ShowPublic ))
135 return false; 144 return false;
136 break; 145 break;
137 case Incidence::SecrecyPrivate: 146 case Incidence::SecrecyPrivate:
138 if (! (mCriteria & ShowPrivate )) 147 if (! (mCriteria & ShowPrivate ))
139 return false; 148 return false;
140 break; 149 break;
141 case Incidence::SecrecyConfidential: 150 case Incidence::SecrecyConfidential:
142 if (! (mCriteria & ShowConfidential )) 151 if (! (mCriteria & ShowConfidential ))
143 return false; 152 return false;
144 break; 153 break;
145 default: 154 default:
146 return false; 155 return false;
147 break; 156 break;
148 } 157 }
149 } 158 }
150 159
151 // kdDebug(5800) << "CalFilter::filterEvent(): " << event->getSummary() << endl; 160 // kdDebug(5800) << "CalFilter::filterEvent(): " << event->getSummary() << endl;
152 161
153 if (mCriteria & ShowCategories) { 162 if (mCriteria & ShowCategories) {
154 for (QStringList::Iterator it = mCategoryList.begin(); 163 for (QStringList::Iterator it = mCategoryList.begin();
155 it != mCategoryList.end(); ++it ) { 164 it != mCategoryList.end(); ++it ) {
156 QStringList incidenceCategories = incidence->categories(); 165 QStringList incidenceCategories = incidence->categories();
157 for (QStringList::Iterator it2 = incidenceCategories.begin(); 166 for (QStringList::Iterator it2 = incidenceCategories.begin();
158 it2 != incidenceCategories.end(); ++it2 ) { 167 it2 != incidenceCategories.end(); ++it2 ) {
159 if ((*it) == (*it2)) { 168 if ((*it) == (*it2)) {
160 return true; 169 return true;
161 } 170 }
162 } 171 }
163 } 172 }
164 return false; 173 return false;
165 } else { 174 } else {
166 for (QStringList::Iterator it = mCategoryList.begin(); 175 for (QStringList::Iterator it = mCategoryList.begin();
167 it != mCategoryList.end(); ++it ) { 176 it != mCategoryList.end(); ++it ) {
168 QStringList incidenceCategories = incidence->categories(); 177 QStringList incidenceCategories = incidence->categories();
169 for (QStringList::Iterator it2 = incidenceCategories.begin(); 178 for (QStringList::Iterator it2 = incidenceCategories.begin();
170 it2 != incidenceCategories.end(); ++it2 ) { 179 it2 != incidenceCategories.end(); ++it2 ) {
171 if ((*it) == (*it2)) { 180 if ((*it) == (*it2)) {
172 return false; 181 return false;
173 } 182 }
174 } 183 }
175 } 184 }
176 return true; 185 return true;
177 } 186 }
178 187
179// kdDebug(5800) << "CalFilter::filterEvent(): passed" << endl; 188// kdDebug(5800) << "CalFilter::filterEvent(): passed" << endl;
180 189
181 return true; 190 return true;
182} 191}
183 192
184void CalFilter::setEnabled(bool enabled) 193void CalFilter::setEnabled(bool enabled)
185{ 194{
186 mEnabled = enabled; 195 mEnabled = enabled;
187} 196}
188 197
189bool CalFilter::isEnabled() 198bool CalFilter::isEnabled()
190{ 199{
191 return mEnabled; 200 return mEnabled;
192} 201}
193 202
194void CalFilter::setCriteria(int criteria) 203void CalFilter::setCriteria(int criteria)
195{ 204{
196 mCriteria = criteria; 205 mCriteria = criteria;
197} 206}
198 207
199int CalFilter::criteria() 208int CalFilter::criteria()
200{ 209{
201 return mCriteria; 210 return mCriteria;
202} 211}
diff --git a/libkcal/calfilter.h b/libkcal/calfilter.h
index 29db441..e349770 100644
--- a/libkcal/calfilter.h
+++ b/libkcal/calfilter.h
@@ -1,124 +1,125 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
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#ifndef _CALFILTER_H 21#ifndef _CALFILTER_H
22#define _CALFILTER_H 22#define _CALFILTER_H
23 23
24#include <qstring.h> 24#include <qstring.h>
25#include <qptrlist.h> 25#include <qptrlist.h>
26 26
27#include "event.h" 27#include "event.h"
28#include "todo.h" 28#include "todo.h"
29#include "journal.h"
29 30
30namespace KCal { 31namespace KCal {
31 32
32/** 33/**
33 Filter for calendar objects. 34 Filter for calendar objects.
34*/ 35*/
35class CalFilter { 36class CalFilter {
36 public: 37 public:
37 /** Construct filter. */ 38 /** Construct filter. */
38 CalFilter(); 39 CalFilter();
39 /** Construct filter with name */ 40 /** Construct filter with name */
40 CalFilter(const QString &name); 41 CalFilter(const QString &name);
41 /** Destruct filter. */ 42 /** Destruct filter. */
42 ~CalFilter(); 43 ~CalFilter();
43 44
44 /** 45 /**
45 Set name of filter. 46 Set name of filter.
46 */ 47 */
47 void setName(const QString &name) { mName = name; } 48 void setName(const QString &name) { mName = name; }
48 /** 49 /**
49 Return name of filter. 50 Return name of filter.
50 */ 51 */
51 QString name() const { return mName; } 52 QString name() const { return mName; }
52 53
53 /** 54 /**
54 Apply filter to eventlist, all events not matching filter criterias are 55 Apply filter to eventlist, all events not matching filter criterias are
55 removed from the list. 56 removed from the list.
56 */ 57 */
57 void apply(QPtrList<Event> *eventlist); 58 void apply(QPtrList<Event> *eventlist);
58 59
59 /** 60 /**
60 Apply filter to todolist, all todos not matching filter criterias are 61 Apply filter to todolist, all todos not matching filter criterias are
61 removed from the list. 62 removed from the list.
62 */ 63 */
63 void apply(QPtrList<Todo> *todolist); 64 void apply(QPtrList<Todo> *todolist);
64 bool CalFilter::filterCalendarItem(Incidence *in); 65 bool CalFilter::filterCalendarItem(Incidence *in);
65 bool CalFilter::filterJournal(Journal *in); 66 bool CalFilter::filterJournal(Journal *in);
66 /** 67 /**
67 Apply filter criteria on the specified event. Return true, if event passes 68 Apply filter criteria on the specified event. Return true, if event passes
68 criteria, otherwise return false. 69 criteria, otherwise return false.
69 */ 70 */
70 bool filterEvent(Event *); 71 bool filterEvent(Event *);
71 72
72 /** 73 /**
73 Apply filter criteria on the specified todo. Return true, if event passes 74 Apply filter criteria on the specified todo. Return true, if event passes
74 criteria, otherwise return false. 75 criteria, otherwise return false.
75 */ 76 */
76 bool filterTodo(Todo *); 77 bool filterTodo(Todo *);
77 78
78 /** 79 /**
79 Apply filter criteria on the specified incidence. Return true, if event passes 80 Apply filter criteria on the specified incidence. Return true, if event passes
80 criteria, otherwise return false. 81 criteria, otherwise return false.
81 */ 82 */
82 bool filterIncidence(Incidence *); 83 bool filterIncidence(Incidence *);
83 84
84 /** 85 /**
85 Enable or disable filter. 86 Enable or disable filter.
86 */ 87 */
87 void setEnabled(bool); 88 void setEnabled(bool);
88 /** 89 /**
89 Return wheter the filter is enabled or not. 90 Return wheter the filter is enabled or not.
90 */ 91 */
91 bool isEnabled(); 92 bool isEnabled();
92 bool showCategories(); 93 bool showCategories();
93 int getSecrecy(); 94 int getSecrecy();
94 /** 95 /**
95 Set list of categories, which is used for showing/hiding categories of 96 Set list of categories, which is used for showing/hiding categories of
96 events. 97 events.
97 See related functions. 98 See related functions.
98 */ 99 */
99 void setCategoryList(const QStringList &); 100 void setCategoryList(const QStringList &);
100 /** 101 /**
101 Return category list, used for showing/hiding categories of events. 102 Return category list, used for showing/hiding categories of events.
102 See related functions. 103 See related functions.
103 */ 104 */
104 QStringList categoryList(); 105 QStringList categoryList();
105 106
106 enum { HideRecurring = 1, HideCompleted = 2, ShowCategories = 4 ,ShowPublic = 8, ShowPrivate = 16, ShowConfidential = 32, HideEvents = 64, HideTodos = 128, HideJournals = 256 }; 107 enum { HideRecurring = 1, HideCompleted = 2, ShowCategories = 4 ,ShowPublic = 8, ShowPrivate = 16, ShowConfidential = 32, HideEvents = 64, HideTodos = 128, HideJournals = 256 };
107 108
108 /** 109 /**
109 Set criteria, which have to be fulfilled by events passing the filter. 110 Set criteria, which have to be fulfilled by events passing the filter.
110 */ 111 */
111 void setCriteria(int); 112 void setCriteria(int);
112 /** 113 /**
113 Get inclusive filter criteria. 114 Get inclusive filter criteria.
114 */ 115 */
115 int criteria(); 116 int criteria();
116 117
117 private: 118 private:
118 QString mName; 119 QString mName;
119 120
120 int mCriteria; 121 int mCriteria;
121 122
122 bool mEnabled; 123 bool mEnabled;
123 124
124 QStringList mCategoryList; 125 QStringList mCategoryList;
diff --git a/libkcal/event.cpp b/libkcal/event.cpp
index 9b99855..7cd81fa 100644
--- a/libkcal/event.cpp
+++ b/libkcal/event.cpp
@@ -80,142 +80,144 @@ bool Event::contains ( Event* from )
80 if ( !alarms().count() ) 80 if ( !alarms().count() )
81 return false; 81 return false;
82 Alarm *b = alarms().first(); 82 Alarm *b = alarms().first();
83 if( ! b->enabled() ) 83 if( ! b->enabled() )
84 return false; 84 return false;
85 if ( ! (a->offset() == b->offset() )) 85 if ( ! (a->offset() == b->offset() ))
86 return false; 86 return false;
87 } 87 }
88 } 88 }
89 QStringList cat = categories(); 89 QStringList cat = categories();
90 QStringList catFrom = from->categories(); 90 QStringList catFrom = from->categories();
91 QString nCat; 91 QString nCat;
92 unsigned int iii; 92 unsigned int iii;
93 for ( iii = 0; iii < catFrom.count();++iii ) { 93 for ( iii = 0; iii < catFrom.count();++iii ) {
94 nCat = catFrom[iii]; 94 nCat = catFrom[iii];
95 if ( !nCat.isEmpty() ) 95 if ( !nCat.isEmpty() )
96 if ( !cat.contains( nCat )) { 96 if ( !cat.contains( nCat )) {
97 return false; 97 return false;
98 } 98 }
99 } 99 }
100 if ( from->doesRecur() ) 100 if ( from->doesRecur() )
101 if ( from->doesRecur() != doesRecur() && ! (from->doesRecur()== Recurrence::rYearlyMonth && doesRecur()== Recurrence::rYearlyDay) ) 101 if ( from->doesRecur() != doesRecur() && ! (from->doesRecur()== Recurrence::rYearlyMonth && doesRecur()== Recurrence::rYearlyDay) )
102 return false; 102 return false;
103 return true; 103 return true;
104} 104}
105 105
106void Event::setDtEnd(const QDateTime &dtEnd) 106void Event::setDtEnd(const QDateTime &dtEnd)
107{ 107{
108 if (mReadOnly) return; 108 if (mReadOnly) return;
109 109
110 mDtEnd = getEvenTime( dtEnd ); 110 mDtEnd = getEvenTime( dtEnd );
111 111
112 setHasEndDate(true); 112 setHasEndDate(true);
113 setHasDuration(false); 113 setHasDuration(false);
114 114
115 updated(); 115 updated();
116} 116}
117 117
118QDateTime Event::dtEnd() const 118QDateTime Event::dtEnd() const
119{ 119{
120 if (hasEndDate()) return mDtEnd; 120 if (hasEndDate()) return mDtEnd;
121 if (hasDuration()) return dtStart().addSecs(duration()); 121 if (hasDuration()) return dtStart().addSecs(duration());
122 122
123 return dtStart(); 123 return dtStart();
124} 124}
125 125
126QString Event::dtEndTimeStr() const 126QString Event::dtEndTimeStr() const
127{ 127{
128 return KGlobal::locale()->formatTime(mDtEnd.time()); 128 return KGlobal::locale()->formatTime(mDtEnd.time());
129} 129}
130 130
131QString Event::dtEndDateStr(bool shortfmt) const 131QString Event::dtEndDateStr(bool shortfmt) const
132{ 132{
133 return KGlobal::locale()->formatDate(mDtEnd.date(),shortfmt); 133 return KGlobal::locale()->formatDate(mDtEnd.date(),shortfmt);
134} 134}
135 135
136QString Event::dtEndStr(bool shortfmt) const 136QString Event::dtEndStr(bool shortfmt) const
137{ 137{
138 return KGlobal::locale()->formatDateTime(mDtEnd, shortfmt); 138 return KGlobal::locale()->formatDateTime(mDtEnd, shortfmt);
139} 139}
140 140
141void Event::setHasEndDate(bool b) 141void Event::setHasEndDate(bool b)
142{ 142{
143 mHasEndDate = b; 143 mHasEndDate = b;
144} 144}
145 145
146bool Event::hasEndDate() const 146bool Event::hasEndDate() const
147{ 147{
148 return mHasEndDate; 148 return mHasEndDate;
149} 149}
150 150
151bool Event::isMultiDay() const 151bool Event::isMultiDay() const
152{ 152{
153 bool multi = !(dtStart().date() == dtEnd().date()); 153 bool multi = !(dtStart().date() == dtEnd().date());
154 return multi; 154 return multi;
155} 155}
156 156
157void Event::setTransparency(Event::Transparency transparency) 157void Event::setTransparency(Event::Transparency transparency)
158{ 158{
159 if (mReadOnly) return; 159 if (mReadOnly) return;
160 mTransparency = transparency; 160 mTransparency = transparency;
161 updated(); 161 updated();
162} 162}
163 163
164Event::Transparency Event::transparency() const 164Event::Transparency Event::transparency() const
165{ 165{
166 return mTransparency; 166 return mTransparency;
167} 167}
168 168
169void Event::setDuration(int seconds) 169void Event::setDuration(int seconds)
170{ 170{
171 setHasEndDate(false); 171 setHasEndDate(false);
172 Incidence::setDuration(seconds); 172 Incidence::setDuration(seconds);
173} 173}
174QDateTime Event::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const 174QDateTime Event::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const
175{ 175{
176 176 *ok = false;
177 if ( !alarmEnabled() )
178 return QDateTime ();
177 bool yes; 179 bool yes;
178 QDateTime incidenceStart = getNextOccurence( start_dt, &yes ); 180 QDateTime incidenceStart = getNextOccurence( start_dt, &yes );
179 if ( ! yes || cancelled() ) { 181 if ( ! yes || cancelled() ) {
180 *ok = false; 182 *ok = false;
181 return QDateTime (); 183 return QDateTime ();
182 } 184 }
183 185
184 bool enabled = false; 186 bool enabled = false;
185 Alarm* alarm; 187 Alarm* alarm;
186 int off = 0; 188 int off = 0;
187 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; 189 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );;
188 // if ( QDateTime::currentDateTime() > incidenceStart ){ 190 // if ( QDateTime::currentDateTime() > incidenceStart ){
189// *ok = false; 191// *ok = false;
190// return incidenceStart; 192// return incidenceStart;
191// } 193// }
192 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { 194 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) {
193 if (alarm->enabled()) { 195 if (alarm->enabled()) {
194 if ( alarm->hasTime () ) { 196 if ( alarm->hasTime () ) {
195 if ( alarm->time() < alarmStart ) { 197 if ( alarm->time() < alarmStart ) {
196 alarmStart = alarm->time(); 198 alarmStart = alarm->time();
197 enabled = true; 199 enabled = true;
198 off = alarmStart.secsTo( incidenceStart ); 200 off = alarmStart.secsTo( incidenceStart );
199 } 201 }
200 202
201 } else { 203 } else {
202 int secs = alarm->startOffset().asSeconds(); 204 int secs = alarm->startOffset().asSeconds();
203 if ( incidenceStart.addSecs( secs ) < alarmStart ) { 205 if ( incidenceStart.addSecs( secs ) < alarmStart ) {
204 alarmStart = incidenceStart.addSecs( secs ); 206 alarmStart = incidenceStart.addSecs( secs );
205 enabled = true; 207 enabled = true;
206 off = -secs; 208 off = -secs;
207 } 209 }
208 } 210 }
209 } 211 }
210 } 212 }
211 if ( enabled ) { 213 if ( enabled ) {
212 if ( alarmStart > start_dt ) { 214 if ( alarmStart > start_dt ) {
213 *ok = true; 215 *ok = true;
214 * offset = off; 216 * offset = off;
215 return alarmStart; 217 return alarmStart;
216 } 218 }
217 } 219 }
218 *ok = false; 220 *ok = false;
219 return QDateTime (); 221 return QDateTime ();
220 222
221} 223}
diff --git a/libkcal/incidencebase.cpp b/libkcal/incidencebase.cpp
index b5fe2e6..2ddbb01 100644
--- a/libkcal/incidencebase.cpp
+++ b/libkcal/incidencebase.cpp
@@ -1,230 +1,263 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
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 <kglobal.h> 21#include <kglobal.h>
22#include <klocale.h> 22#include <klocale.h>
23#include <kdebug.h> 23#include <kdebug.h>
24#include <kidmanager.h> 24#include <kidmanager.h>
25 25
26#include "calformat.h" 26#include "calformat.h"
27#include "syncdefines.h" 27#include "syncdefines.h"
28 28
29#include "incidencebase.h" 29#include "incidencebase.h"
30 30
31using namespace KCal; 31using namespace KCal;
32 32
33IncidenceBase::IncidenceBase() : 33IncidenceBase::IncidenceBase() :
34 mReadOnly(false), mFloats(true), mDuration(0), mHasDuration(false), 34 mReadOnly(false), mFloats(true), mDuration(0), mHasDuration(false),
35 mPilotId(0), mSyncStatus(SYNCMOD) 35 mPilotId(0), mSyncStatus(SYNCMOD)
36{ 36{
37 setUid(CalFormat::createUniqueId()); 37 setUid(CalFormat::createUniqueId());
38 mOrganizer = ""; 38 mOrganizer = "";
39 mFloats = false; 39 mFloats = false;
40 mDuration = 0; 40 mDuration = 0;
41 mHasDuration = false; 41 mHasDuration = false;
42 mPilotId = 0; 42 mPilotId = 0;
43 mExternalId = ":"; 43 mExternalId = ":";
44 mTempSyncStat = SYNC_TEMPSTATE_INITIAL; 44 mTempSyncStat = SYNC_TEMPSTATE_INITIAL;
45 mSyncStatus = 0; 45 mSyncStatus = 0;
46 mAttendees.setAutoDelete( true ); 46 mAttendees.setAutoDelete( true );
47 mCalEnabled = true;
48 mAlarmEnabled = true;
49 mCalID = 0;
47} 50}
48 51
49IncidenceBase::IncidenceBase(const IncidenceBase &i) : 52IncidenceBase::IncidenceBase(const IncidenceBase &i) :
50 CustomProperties( i ) 53 CustomProperties( i )
51{ 54{
55
52 mReadOnly = i.mReadOnly; 56 mReadOnly = i.mReadOnly;
53 mDtStart = i.mDtStart; 57 mDtStart = i.mDtStart;
54 mDuration = i.mDuration; 58 mDuration = i.mDuration;
55 mHasDuration = i.mHasDuration; 59 mHasDuration = i.mHasDuration;
56 mOrganizer = i.mOrganizer; 60 mOrganizer = i.mOrganizer;
57 mUid = i.mUid; 61 mUid = i.mUid;
62 mCalEnabled = i.mCalEnabled;
63 mAlarmEnabled = i.mAlarmEnabled;
64 mCalID = i.mCalID;
58 QPtrList<Attendee> attendees = i.attendees(); 65 QPtrList<Attendee> attendees = i.attendees();
59 for( Attendee *a = attendees.first(); a; a = attendees.next() ) { 66 for( Attendee *a = attendees.first(); a; a = attendees.next() ) {
60 mAttendees.append( new Attendee( *a ) ); 67 mAttendees.append( new Attendee( *a ) );
61 } 68 }
62 mFloats = i.mFloats; 69 mFloats = i.mFloats;
63 mLastModified = i.mLastModified; 70 mLastModified = i.mLastModified;
64 mPilotId = i.mPilotId; 71 mPilotId = i.mPilotId;
65 mTempSyncStat = i.mTempSyncStat; 72 mTempSyncStat = i.mTempSyncStat;
66 mSyncStatus = i.mSyncStatus; 73 mSyncStatus = i.mSyncStatus;
67 mExternalId = i.mExternalId; 74 mExternalId = i.mExternalId;
68 // The copied object is a new one, so it isn't observed by the observer 75 // The copied object is a new one, so it isn't observed by the observer
69 // of the original object. 76 // of the original object.
70 mObservers.clear(); 77 mObservers.clear();
71 78
72 mAttendees.setAutoDelete( true ); 79 mAttendees.setAutoDelete( true );
73} 80}
74 81
75IncidenceBase::~IncidenceBase() 82IncidenceBase::~IncidenceBase()
76{ 83{
77} 84}
78 85
79 86
80bool KCal::operator==( const IncidenceBase& i1, const IncidenceBase& i2 ) 87bool KCal::operator==( const IncidenceBase& i1, const IncidenceBase& i2 )
81{ 88{
82 // do not compare mSyncStatus and mExternalId 89 // do not compare mSyncStatus and mExternalId
83 if( i1.attendees().count() != i2.attendees().count() ) { 90 if( i1.attendees().count() != i2.attendees().count() ) {
84 return false; // no need to check further 91 return false; // no need to check further
85 } 92 }
86 if ( i1.attendees().count() > 0 ) { 93 if ( i1.attendees().count() > 0 ) {
87 Attendee * a1 = i1.attendees().first(), *a2 =i2.attendees().first() ; 94 Attendee * a1 = i1.attendees().first(), *a2 =i2.attendees().first() ;
88 while ( a1 ) { 95 while ( a1 ) {
89 if ( !( (*a1) == (*a2)) ) 96 if ( !( (*a1) == (*a2)) )
90 { 97 {
91 //qDebug("Attendee not equal "); 98 //qDebug("Attendee not equal ");
92 return false; 99 return false;
93 } 100 }
94 a1 = i1.attendees().next(); 101 a1 = i1.attendees().next();
95 a2 = i2.attendees().next(); 102 a2 = i2.attendees().next();
96 } 103 }
97 } 104 }
98 //if ( i1.dtStart() != i2.dtStart() ) 105 //if ( i1.dtStart() != i2.dtStart() )
99 // return false; 106 // return false;
100#if 0 107#if 0
101 qDebug("1 %d ",i1.doesFloat() == i2.doesFloat() ); 108 qDebug("1 %d ",i1.doesFloat() == i2.doesFloat() );
102 qDebug("1 %d ",i1.duration() == i2.duration() ); 109 qDebug("1 %d ",i1.duration() == i2.duration() );
103 qDebug("3 %d ",i1.hasDuration() == i2.hasDuration() ); 110 qDebug("3 %d ",i1.hasDuration() == i2.hasDuration() );
104 qDebug("1 %d ",i1.pilotId() == i2.pilotId() ); 111 qDebug("1 %d ",i1.pilotId() == i2.pilotId() );
105 qDebug("1 %d %d %d",i1.syncStatus() == i2.syncStatus() , i1.syncStatus(),i2.syncStatus() ); 112 qDebug("1 %d %d %d",i1.syncStatus() == i2.syncStatus() , i1.syncStatus(),i2.syncStatus() );
106 qDebug("6 %d ",i1.organizer() == i2.organizer() ); 113 qDebug("6 %d ",i1.organizer() == i2.organizer() );
107 114
108#endif 115#endif
109 if ( i1.hasDuration() == i2.hasDuration() ) { 116 if ( i1.hasDuration() == i2.hasDuration() ) {
110 if ( i1.hasDuration() ) { 117 if ( i1.hasDuration() ) {
111 if ( i1.duration() != i2.duration() ) 118 if ( i1.duration() != i2.duration() )
112 return false; 119 return false;
113 } 120 }
114 } else { 121 } else {
115 return false; 122 return false;
116 } 123 }
117 124
118 return ( i1.organizer() == i2.organizer() && 125 return ( i1.organizer() == i2.organizer() &&
119 // i1.uid() == i2.uid() && 126 // i1.uid() == i2.uid() &&
120 // Don't compare lastModified, otherwise the operator is not 127 // Don't compare lastModified, otherwise the operator is not
121 // of much use. We are not comparing for identity, after all. 128 // of much use. We are not comparing for identity, after all.
122 i1.doesFloat() == i2.doesFloat() && 129 i1.doesFloat() == i2.doesFloat() &&
123 i1.pilotId() == i2.pilotId() );// && i1.syncStatus() == i2.syncStatus() ); 130 i1.pilotId() == i2.pilotId() );// && i1.syncStatus() == i2.syncStatus() );
124 // no need to compare mObserver 131 // no need to compare mObserver
125} 132}
126 133
127 134
128QDateTime IncidenceBase::getEvenTime( QDateTime dt ) 135QDateTime IncidenceBase::getEvenTime( QDateTime dt )
129{ 136{
130 QTime t = dt.time(); 137 QTime t = dt.time();
131 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 138 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) );
132 return dt; 139 return dt;
133} 140}
134 141
142void IncidenceBase::setCalID( int id )
143{
144 mCalID = id;
145}
146int IncidenceBase::calID() const
147{
148 return mCalID;
149}
150void IncidenceBase::setCalEnabled( bool b )
151{
152 mCalEnabled = b;
153}
154bool IncidenceBase::calEnabled() const
155{
156 return mCalEnabled;
157}
158
159void IncidenceBase::setAlarmEnabled( bool b )
160{
161 mAlarmEnabled = b;
162}
163bool IncidenceBase::alarmEnabled() const
164{
165 return mAlarmEnabled;
166}
167
135 168
136void IncidenceBase::setUid(const QString &uid) 169void IncidenceBase::setUid(const QString &uid)
137{ 170{
138 mUid = uid; 171 mUid = uid;
139 updated(); 172 updated();
140} 173}
141 174
142QString IncidenceBase::uid() const 175QString IncidenceBase::uid() const
143{ 176{
144 return mUid; 177 return mUid;
145} 178}
146 179
147void IncidenceBase::setLastModified(const QDateTime &lm) 180void IncidenceBase::setLastModified(const QDateTime &lm)
148{ 181{
149 // DON'T! updated() because we call this from 182 // DON'T! updated() because we call this from
150 // Calendar::updateEvent(). 183 // Calendar::updateEvent().
151 mLastModified = getEvenTime(lm); 184 mLastModified = getEvenTime(lm);
152 //qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1()); 185 //qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1());
153} 186}
154 187
155QDateTime IncidenceBase::lastModified() const 188QDateTime IncidenceBase::lastModified() const
156{ 189{
157 return mLastModified; 190 return mLastModified;
158} 191}
159 192
160void IncidenceBase::setOrganizer(const QString &o) 193void IncidenceBase::setOrganizer(const QString &o)
161{ 194{
162 // we don't check for readonly here, because it is 195 // we don't check for readonly here, because it is
163 // possible that by setting the organizer we are changing 196 // possible that by setting the organizer we are changing
164 // the event's readonly status... 197 // the event's readonly status...
165 mOrganizer = o; 198 mOrganizer = o;
166 if (mOrganizer.left(7).upper() == "MAILTO:") 199 if (mOrganizer.left(7).upper() == "MAILTO:")
167 mOrganizer = mOrganizer.remove(0,7); 200 mOrganizer = mOrganizer.remove(0,7);
168 201
169 updated(); 202 updated();
170} 203}
171 204
172QString IncidenceBase::organizer() const 205QString IncidenceBase::organizer() const
173{ 206{
174 return mOrganizer; 207 return mOrganizer;
175} 208}
176 209
177void IncidenceBase::setReadOnly( bool readOnly ) 210void IncidenceBase::setReadOnly( bool readOnly )
178{ 211{
179 mReadOnly = readOnly; 212 mReadOnly = readOnly;
180} 213}
181 214
182void IncidenceBase::setDtStart(const QDateTime &dtStart) 215void IncidenceBase::setDtStart(const QDateTime &dtStart)
183{ 216{
184// if (mReadOnly) return; 217// if (mReadOnly) return;
185 mDtStart = getEvenTime(dtStart); 218 mDtStart = getEvenTime(dtStart);
186 updated(); 219 updated();
187} 220}
188 221
189 222
190QDateTime IncidenceBase::dtStart() const 223QDateTime IncidenceBase::dtStart() const
191{ 224{
192 return mDtStart; 225 return mDtStart;
193} 226}
194 227
195QString IncidenceBase::dtStartTimeStr() const 228QString IncidenceBase::dtStartTimeStr() const
196{ 229{
197 return KGlobal::locale()->formatTime(dtStart().time()); 230 return KGlobal::locale()->formatTime(dtStart().time());
198} 231}
199 232
200QString IncidenceBase::dtStartDateStr(bool shortfmt) const 233QString IncidenceBase::dtStartDateStr(bool shortfmt) const
201{ 234{
202 return KGlobal::locale()->formatDate(dtStart().date(),shortfmt); 235 return KGlobal::locale()->formatDate(dtStart().date(),shortfmt);
203} 236}
204 237
205QString IncidenceBase::dtStartStr(bool shortfmt) const 238QString IncidenceBase::dtStartStr(bool shortfmt) const
206{ 239{
207 if ( doesFloat() ) 240 if ( doesFloat() )
208 return KGlobal::locale()->formatDate(dtStart().date(),shortfmt); 241 return KGlobal::locale()->formatDate(dtStart().date(),shortfmt);
209 return KGlobal::locale()->formatDateTime(dtStart(), shortfmt); 242 return KGlobal::locale()->formatDateTime(dtStart(), shortfmt);
210} 243}
211 244
212 245
213bool IncidenceBase::doesFloat() const 246bool IncidenceBase::doesFloat() const
214{ 247{
215 return mFloats; 248 return mFloats;
216} 249}
217 250
218void IncidenceBase::setFloats(bool f) 251void IncidenceBase::setFloats(bool f)
219{ 252{
220 if (mReadOnly) return; 253 if (mReadOnly) return;
221 mFloats = f; 254 mFloats = f;
222 updated(); 255 updated();
223} 256}
224 257
225 258
226bool IncidenceBase::addAttendee(Attendee *a, bool doupdate) 259bool IncidenceBase::addAttendee(Attendee *a, bool doupdate)
227{ 260{
228 if (mReadOnly) return false; 261 if (mReadOnly) return false;
229 if (a->name().left(7).upper() == "MAILTO:") 262 if (a->name().left(7).upper() == "MAILTO:")
230 a->setName(a->name().remove(0,7)); 263 a->setName(a->name().remove(0,7));
diff --git a/libkcal/incidencebase.h b/libkcal/incidencebase.h
index 05209e0..dc6024a 100644
--- a/libkcal/incidencebase.h
+++ b/libkcal/incidencebase.h
@@ -48,127 +48,136 @@ class IncidenceBase : public CustomProperties
48 }; 48 };
49 49
50 IncidenceBase(); 50 IncidenceBase();
51 IncidenceBase(const IncidenceBase &); 51 IncidenceBase(const IncidenceBase &);
52 virtual ~IncidenceBase(); 52 virtual ~IncidenceBase();
53 53
54 virtual QCString type() const = 0; 54 virtual QCString type() const = 0;
55 virtual IncTypeID typeID() const = 0; 55 virtual IncTypeID typeID() const = 0;
56 56
57 /** Set the unique id for the event */ 57 /** Set the unique id for the event */
58 void setUid(const QString &); 58 void setUid(const QString &);
59 /** Return the unique id for the event */ 59 /** Return the unique id for the event */
60 QString uid() const; 60 QString uid() const;
61 61
62 /** Sets the time the incidence was last modified. */ 62 /** Sets the time the incidence was last modified. */
63 void setLastModified(const QDateTime &lm); 63 void setLastModified(const QDateTime &lm);
64 /** Return the time the incidence was last modified. */ 64 /** Return the time the incidence was last modified. */
65 QDateTime lastModified() const; 65 QDateTime lastModified() const;
66 66
67 /** sets the organizer for the event */ 67 /** sets the organizer for the event */
68 void setOrganizer(const QString &o); 68 void setOrganizer(const QString &o);
69 QString organizer() const; 69 QString organizer() const;
70 70
71 /** Set readonly status. */ 71 /** Set readonly status. */
72 virtual void setReadOnly( bool ); 72 virtual void setReadOnly( bool );
73 /** Return if the object is read-only. */ 73 /** Return if the object is read-only. */
74 bool isReadOnly() const { return mReadOnly; } 74 bool isReadOnly() const { return mReadOnly; }
75 75
76 /** for setting the event's starting date/time with a QDateTime. */ 76 /** for setting the event's starting date/time with a QDateTime. */
77 virtual void setDtStart(const QDateTime &dtStart); 77 virtual void setDtStart(const QDateTime &dtStart);
78 /** returns an event's starting date/time as a QDateTime. */ 78 /** returns an event's starting date/time as a QDateTime. */
79 virtual QDateTime dtStart() const; 79 virtual QDateTime dtStart() const;
80 /** returns an event's starting time as a string formatted according to the 80 /** returns an event's starting time as a string formatted according to the
81 users locale settings */ 81 users locale settings */
82 QString dtStartTimeStr() const; 82 QString dtStartTimeStr() const;
83 /** returns an event's starting date as a string formatted according to the 83 /** returns an event's starting date as a string formatted according to the
84 users locale settings */ 84 users locale settings */
85 QString dtStartDateStr(bool shortfmt=true) const; 85 QString dtStartDateStr(bool shortfmt=true) const;
86 /** returns an event's starting date and time as a string formatted according 86 /** returns an event's starting date and time as a string formatted according
87 to the users locale settings */ 87 to the users locale settings */
88 QString dtStartStr(bool shortfmt=true) const; 88 QString dtStartStr(bool shortfmt=true) const;
89 89
90 virtual void setDuration(int seconds); 90 virtual void setDuration(int seconds);
91 int duration() const; 91 int duration() const;
92 void setHasDuration(bool); 92 void setHasDuration(bool);
93 bool hasDuration() const; 93 bool hasDuration() const;
94 94
95 /** Return true or false depending on whether the incidence "floats," 95 /** Return true or false depending on whether the incidence "floats,"
96 * i.e. has a date but no time attached to it. */ 96 * i.e. has a date but no time attached to it. */
97 bool doesFloat() const; 97 bool doesFloat() const;
98 /** Set whether the incidence floats, i.e. has a date but no time attached to it. */ 98 /** Set whether the incidence floats, i.e. has a date but no time attached to it. */
99 void setFloats(bool f); 99 void setFloats(bool f);
100 100
101 /** 101 /**
102 Add Attendee to this incidence. IncidenceBase takes ownership of the 102 Add Attendee to this incidence. IncidenceBase takes ownership of the
103 Attendee object. 103 Attendee object.
104 */ 104 */
105 bool addAttendee(Attendee *a, bool doupdate=true ); 105 bool addAttendee(Attendee *a, bool doupdate=true );
106// void removeAttendee(Attendee *a); 106// void removeAttendee(Attendee *a);
107// void removeAttendee(const char *n); 107// void removeAttendee(const char *n);
108 /** Remove all Attendees. */ 108 /** Remove all Attendees. */
109 void clearAttendees(); 109 void clearAttendees();
110 /** Return list of attendees. */ 110 /** Return list of attendees. */
111 QPtrList<Attendee> attendees() const { return mAttendees; }; 111 QPtrList<Attendee> attendees() const { return mAttendees; };
112 /** Return number of attendees. */ 112 /** Return number of attendees. */
113 int attendeeCount() const { return mAttendees.count(); }; 113 int attendeeCount() const { return mAttendees.count(); };
114 /** Return the Attendee with this email */ 114 /** Return the Attendee with this email */
115 Attendee* attendeeByMail(const QString &); 115 Attendee* attendeeByMail(const QString &);
116 /** Return first Attendee with one of this emails */ 116 /** Return first Attendee with one of this emails */
117 Attendee* attendeeByMails(const QStringList &, const QString& email = QString::null); 117 Attendee* attendeeByMails(const QStringList &, const QString& email = QString::null);
118 118
119 /** pilot syncronization states */ 119 /** pilot syncronization states */
120 enum { SYNCNONE = 0, SYNCMOD = 1, SYNCDEL = 3 }; 120 enum { SYNCNONE = 0, SYNCMOD = 1, SYNCDEL = 3 };
121 /** Set synchronisation satus. */ 121 /** Set synchronisation satus. */
122 void setSyncStatus(int stat); 122 void setSyncStatus(int stat);
123 /** Return synchronisation status. */ 123 /** Return synchronisation status. */
124 int syncStatus() const; 124 int syncStatus() const;
125 125
126 /** Set Pilot Id. */ 126 /** Set Pilot Id. */
127 void setPilotId(int id); 127 void setPilotId(int id);
128 /** Return Pilot Id. */ 128 /** Return Pilot Id. */
129 int pilotId() const; 129 int pilotId() const;
130 130
131 void setTempSyncStat(int id); 131 void setTempSyncStat(int id);
132 int tempSyncStat() const; 132 int tempSyncStat() const;
133 void setIDStr( const QString & ); 133 void setIDStr( const QString & );
134 QString IDStr() const; 134 QString IDStr() const;
135 void setID( const QString &, const QString & ); 135 void setID( const QString &, const QString & );
136 QString getID( const QString & ); 136 QString getID( const QString & );
137 void setCsum( const QString &, const QString & ); 137 void setCsum( const QString &, const QString & );
138 QString getCsum( const QString & ); 138 QString getCsum( const QString & );
139 void removeID(const QString &); 139 void removeID(const QString &);
140 140
141 void registerObserver( Observer * ); 141 void registerObserver( Observer * );
142 void unRegisterObserver( Observer * ); 142 void unRegisterObserver( Observer * );
143 void updated(); 143 void updated();
144 void setCalID( int id );
145 int calID() const;
146 void setCalEnabled( bool );
147 bool calEnabled() const;
148 void setAlarmEnabled( bool );
149 bool alarmEnabled() const;
144 150
145 protected: 151 protected:
146 QDateTime mDtStart; 152 QDateTime mDtStart;
147 bool mReadOnly; 153 bool mReadOnly;
148 QDateTime getEvenTime( QDateTime ); 154 QDateTime getEvenTime( QDateTime );
149 155
150 private: 156 private:
151 // base components 157 // base components
152 QString mOrganizer; 158 QString mOrganizer;
153 QString mUid; 159 QString mUid;
160 int mCalID;
161 bool mCalEnabled;
162 bool mAlarmEnabled;
154 QDateTime mLastModified; 163 QDateTime mLastModified;
155 QPtrList<Attendee> mAttendees; 164 QPtrList<Attendee> mAttendees;
156 165
157 bool mFloats; 166 bool mFloats;
158 167
159 int mDuration; 168 int mDuration;
160 bool mHasDuration; 169 bool mHasDuration;
161 QString mExternalId; 170 QString mExternalId;
162 int mTempSyncStat; 171 int mTempSyncStat;
163 172
164 // PILOT SYNCHRONIZATION STUFF 173 // PILOT SYNCHRONIZATION STUFF
165 int mPilotId; // unique id for pilot sync 174 int mPilotId; // unique id for pilot sync
166 int mSyncStatus; // status (for sync) 175 int mSyncStatus; // status (for sync)
167 176
168 QPtrList<Observer> mObservers; 177 QPtrList<Observer> mObservers;
169}; 178};
170 179
171bool operator==( const IncidenceBase&, const IncidenceBase& ); 180bool operator==( const IncidenceBase&, const IncidenceBase& );
172} 181}
173 182
174#endif 183#endif
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp
index c97a61e..42274ff 100644
--- a/libkcal/todo.cpp
+++ b/libkcal/todo.cpp
@@ -424,158 +424,158 @@ QString Todo::statusStr() const
424 case DELEGATED: 424 case DELEGATED:
425 return QString("DELEGATED"); 425 return QString("DELEGATED");
426 break; 426 break;
427 } 427 }
428 return QString(""); 428 return QString("");
429} 429}
430#endif 430#endif
431 431
432bool Todo::isCompleted() const 432bool Todo::isCompleted() const
433{ 433{
434 if (mPercentComplete == 100) { 434 if (mPercentComplete == 100) {
435 return true; 435 return true;
436 } 436 }
437 else return false; 437 else return false;
438} 438}
439 439
440void Todo::setCompleted(bool completed) 440void Todo::setCompleted(bool completed)
441{ 441{
442 if ( mHasRecurrenceID && completed && mPercentComplete != 100 ) { 442 if ( mHasRecurrenceID && completed && mPercentComplete != 100 ) {
443 if ( !setRecurDates() ) 443 if ( !setRecurDates() )
444 completed = false; 444 completed = false;
445 } 445 }
446 if (completed) mPercentComplete = 100; 446 if (completed) mPercentComplete = 100;
447 else { 447 else {
448 mPercentComplete = 0; 448 mPercentComplete = 0;
449 mHasCompletedDate = false; 449 mHasCompletedDate = false;
450 } 450 }
451 updated(); 451 updated();
452} 452}
453 453
454QDateTime Todo::completed() const 454QDateTime Todo::completed() const
455{ 455{
456 return mCompleted; 456 return mCompleted;
457} 457}
458 458
459QString Todo::completedStr( bool shortF ) const 459QString Todo::completedStr( bool shortF ) const
460{ 460{
461 return KGlobal::locale()->formatDateTime(mCompleted, shortF); 461 return KGlobal::locale()->formatDateTime(mCompleted, shortF);
462} 462}
463 463
464void Todo::setCompleted(const QDateTime &completed) 464void Todo::setCompleted(const QDateTime &completed)
465{ 465{
466 //qDebug("Todo::setCompleted "); 466 //qDebug("Todo::setCompleted ");
467 if ( mHasCompletedDate ) { 467 if ( mHasCompletedDate ) {
468 // qDebug("has completed data - return "); 468 // qDebug("has completed data - return ");
469 return; 469 return;
470 } 470 }
471 mHasCompletedDate = true; 471 mHasCompletedDate = true;
472 mPercentComplete = 100; 472 mPercentComplete = 100;
473 mCompleted = getEvenTime(completed); 473 mCompleted = getEvenTime(completed);
474 updated(); 474 updated();
475} 475}
476 476
477bool Todo::hasCompletedDate() const 477bool Todo::hasCompletedDate() const
478{ 478{
479 return mHasCompletedDate; 479 return mHasCompletedDate;
480} 480}
481 481
482int Todo::percentComplete() const 482int Todo::percentComplete() const
483{ 483{
484 return mPercentComplete; 484 return mPercentComplete;
485} 485}
486bool Todo::setRecurDates() 486bool Todo::setRecurDates()
487{ 487{
488 if ( !mHasRecurrenceID ) 488 if ( !mHasRecurrenceID )
489 return true; 489 return true;
490 int secs = mDtStart.secsTo( dtDue() ); 490 int secs = mDtStart.secsTo( dtDue() );
491 bool ok; 491 bool ok;
492 qDebug("T:setRecurDates() "); 492 qDebug("T:setRecurDates() ");
493 //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); 493 //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() );
494 QDateTime next = getNextOccurence( mRecurrenceID, &ok ); 494 QDateTime next = getNextOccurence( mRecurrenceID, &ok );
495 if ( ok ) { 495 if ( ok ) {
496 mRecurrenceID = next; 496 mRecurrenceID = next;
497 mDtStart = next; 497 mDtStart = next;
498 setDtDue( next.addSecs( secs ) ); 498 setDtDue( next.addSecs( secs ) );
499 if ( QDateTime::currentDateTime() > next) 499 if ( QDateTime::currentDateTime() > next)
500 return false; 500 return false;
501 } else { 501 } else {
502 setHasRecurrenceID( false ); 502 setHasRecurrenceID( false );
503 recurrence()->unsetRecurs(); 503 recurrence()->unsetRecurs();
504 } 504 }
505 return true; 505 return true;
506} 506}
507void Todo::setPercentComplete(int v) 507void Todo::setPercentComplete(int v)
508{ 508{
509 if ( mHasRecurrenceID && v == 100 && mPercentComplete != 100 ) { 509 if ( mHasRecurrenceID && v == 100 && mPercentComplete != 100 ) {
510 if ( !setRecurDates() ) 510 if ( !setRecurDates() )
511 v = 0; 511 v = 0;
512 } 512 }
513 mPercentComplete = v; 513 mPercentComplete = v;
514 if ( v != 100 ) 514 if ( v != 100 )
515 mHasCompletedDate = false; 515 mHasCompletedDate = false;
516 updated(); 516 updated();
517} 517}
518QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const 518QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const
519{ 519{
520 if ( isCompleted() || ! hasDueDate() || cancelled() ) { 520 if ( isCompleted() || ! hasDueDate() || cancelled() || !alarmEnabled() ) {
521 *ok = false; 521 *ok = false;
522 return QDateTime (); 522 return QDateTime ();
523 } 523 }
524 QDateTime incidenceStart; 524 QDateTime incidenceStart;
525 incidenceStart = dtDue(); 525 incidenceStart = dtDue();
526 bool enabled = false; 526 bool enabled = false;
527 Alarm* alarm; 527 Alarm* alarm;
528 int off = 0; 528 int off = 0;
529 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; 529 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );;
530 // if ( QDateTime::currentDateTime() > incidenceStart ){ 530 // if ( QDateTime::currentDateTime() > incidenceStart ){
531// *ok = false; 531// *ok = false;
532// return incidenceStart; 532// return incidenceStart;
533// } 533// }
534 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { 534 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) {
535 if (alarm->enabled()) { 535 if (alarm->enabled()) {
536 if ( alarm->hasTime () ) { 536 if ( alarm->hasTime () ) {
537 if ( alarm->time() < alarmStart ) { 537 if ( alarm->time() < alarmStart ) {
538 alarmStart = alarm->time(); 538 alarmStart = alarm->time();
539 enabled = true; 539 enabled = true;
540 off = alarmStart.secsTo( incidenceStart ); 540 off = alarmStart.secsTo( incidenceStart );
541 } 541 }
542 542
543 } else { 543 } else {
544 int secs = alarm->startOffset().asSeconds(); 544 int secs = alarm->startOffset().asSeconds();
545 if ( incidenceStart.addSecs( secs ) < alarmStart ) { 545 if ( incidenceStart.addSecs( secs ) < alarmStart ) {
546 alarmStart = incidenceStart.addSecs( secs ); 546 alarmStart = incidenceStart.addSecs( secs );
547 enabled = true; 547 enabled = true;
548 off = -secs; 548 off = -secs;
549 } 549 }
550 } 550 }
551 } 551 }
552 } 552 }
553 if ( enabled ) { 553 if ( enabled ) {
554 if ( alarmStart > start_dt ) { 554 if ( alarmStart > start_dt ) {
555 *ok = true; 555 *ok = true;
556 * offset = off; 556 * offset = off;
557 return alarmStart; 557 return alarmStart;
558 } 558 }
559 } 559 }
560 *ok = false; 560 *ok = false;
561 return QDateTime (); 561 return QDateTime ();
562 562
563} 563}
564 564
565void Todo::checkSetCompletedFalse() 565void Todo::checkSetCompletedFalse()
566{ 566{
567 if ( !mHasRecurrenceID ) { 567 if ( !mHasRecurrenceID ) {
568 qDebug("ERROR 1 in Todo::checkSetCompletedFalse"); 568 qDebug("ERROR 1 in Todo::checkSetCompletedFalse");
569 return; 569 return;
570 } 570 }
571 // qDebug("Todo::checkSetCompletedFalse()"); 571 // qDebug("Todo::checkSetCompletedFalse()");
572 //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); 572 //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() );
573 if ( mPercentComplete == 100 ) { 573 if ( mPercentComplete == 100 ) {
574 QDateTime dt = QDateTime::currentDateTime(); 574 QDateTime dt = QDateTime::currentDateTime();
575 if ( dt > mDtStart && dt > mRecurrenceID ) { 575 if ( dt > mDtStart && dt > mRecurrenceID ) {
576 qDebug("start: %s --due: %s --recID: %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); 576 qDebug("start: %s --due: %s --recID: %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() );
577 setCompleted( false ); 577 setCompleted( false );
578 qDebug("Todo::checkSetCompletedFalse "); 578 qDebug("Todo::checkSetCompletedFalse ");
579 } 579 }
580 } 580 }
581} 581}