summaryrefslogtreecommitdiffabout
path: root/libkcal
authorzautrix <zautrix>2005-06-03 23:10:45 (UTC)
committer zautrix <zautrix>2005-06-03 23:10:45 (UTC)
commit858b047efb5627824438cb3877e7bec0cebb3751 (patch) (unidiff)
tree7b36963344d4f5019f3a1ecb5eb9290f27c3b3c7 /libkcal
parent0207d193bdb6c66201562a17e68872e018ec223c (diff)
downloadkdepimpi-858b047efb5627824438cb3877e7bec0cebb3751.zip
kdepimpi-858b047efb5627824438cb3877e7bec0cebb3751.tar.gz
kdepimpi-858b047efb5627824438cb3877e7bec0cebb3751.tar.bz2
fixxx
Diffstat (limited to 'libkcal') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/calendarlocal.cpp6
-rw-r--r--libkcal/event.cpp6
-rw-r--r--libkcal/event.h2
-rw-r--r--libkcal/incidence.h2
-rw-r--r--libkcal/journal.cpp2
-rw-r--r--libkcal/journal.h2
-rw-r--r--libkcal/todo.cpp4
-rw-r--r--libkcal/todo.h2
8 files changed, 13 insertions, 13 deletions
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp
index e75df70..bc76c0b 100644
--- a/libkcal/calendarlocal.cpp
+++ b/libkcal/calendarlocal.cpp
@@ -1,730 +1,730 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 3
4 Copyright (c) 1998 Preston Brown 4 Copyright (c) 1998 Preston Brown
5 Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> 5 Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org>
6 6
7 This library is free software; you can redistribute it and/or 7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public 8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either 9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version. 10 version 2 of the License, or (at your option) any later version.
11 11
12 This library is distributed in the hope that it will be useful, 12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details. 15 Library General Public License for more details.
16 16
17 You should have received a copy of the GNU Library General Public License 17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to 18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. 20 Boston, MA 02111-1307, USA.
21*/ 21*/
22 22
23#include <qdatetime.h> 23#include <qdatetime.h>
24#include <qstring.h> 24#include <qstring.h>
25#include <qptrlist.h> 25#include <qptrlist.h>
26 26
27#include <kdebug.h> 27#include <kdebug.h>
28#include <kconfig.h> 28#include <kconfig.h>
29#include <kglobal.h> 29#include <kglobal.h>
30#include <klocale.h> 30#include <klocale.h>
31 31
32#include "vcaldrag.h" 32#include "vcaldrag.h"
33#include "vcalformat.h" 33#include "vcalformat.h"
34#include "icalformat.h" 34#include "icalformat.h"
35#include "exceptions.h" 35#include "exceptions.h"
36#include "incidence.h" 36#include "incidence.h"
37#include "journal.h" 37#include "journal.h"
38#include "filestorage.h" 38#include "filestorage.h"
39#include "calfilter.h" 39#include "calfilter.h"
40 40
41#include "calendarlocal.h" 41#include "calendarlocal.h"
42 42
43// #ifndef DESKTOP_VERSION 43// #ifndef DESKTOP_VERSION
44// #include <qtopia/alarmserver.h> 44// #include <qtopia/alarmserver.h>
45// #endif 45// #endif
46using namespace KCal; 46using namespace KCal;
47 47
48CalendarLocal::CalendarLocal() 48CalendarLocal::CalendarLocal()
49 : Calendar() 49 : Calendar()
50{ 50{
51 init(); 51 init();
52} 52}
53 53
54CalendarLocal::CalendarLocal(const QString &timeZoneId) 54CalendarLocal::CalendarLocal(const QString &timeZoneId)
55 : Calendar(timeZoneId) 55 : Calendar(timeZoneId)
56{ 56{
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 153
154 return true; 154 return true;
155} 155}
156 156
157void CalendarLocal::deleteEvent( Event *event ) 157void CalendarLocal::deleteEvent( Event *event )
158{ 158{
159 if ( mUndoIncidence ) delete mUndoIncidence; 159 if ( mUndoIncidence ) delete mUndoIncidence;
160 mUndoIncidence = event->clone(); 160 mUndoIncidence = event->clone();
161 if ( mEventList.removeRef( event ) ) { 161 if ( mEventList.removeRef( event ) ) {
162 setModified( true ); 162 setModified( true );
163 } 163 }
164} 164}
165 165
166 166
167Event *CalendarLocal::event( const QString &uid ) 167Event *CalendarLocal::event( const QString &uid )
168{ 168{
169 169
170 Event *event; 170 Event *event;
171 171
172 for ( event = mEventList.first(); event; event = mEventList.next() ) { 172 for ( event = mEventList.first(); event; event = mEventList.next() ) {
173 if ( event->uid() == uid ) { 173 if ( event->uid() == uid ) {
174 return event; 174 return event;
175 } 175 }
176 } 176 }
177 177
178 return 0; 178 return 0;
179} 179}
180bool CalendarLocal::addTodoNoDup( Todo *todo ) 180bool CalendarLocal::addTodoNoDup( Todo *todo )
181{ 181{
182 Todo * eve; 182 Todo * eve;
183 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { 183 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) {
184 if ( *eve == *todo ) { 184 if ( *eve == *todo ) {
185 //qDebug("duplicate todo found! not inserted! "); 185 //qDebug("duplicate todo found! not inserted! ");
186 return false; 186 return false;
187 } 187 }
188 } 188 }
189 return addTodo( todo ); 189 return addTodo( todo );
190} 190}
191bool CalendarLocal::addTodo( Todo *todo ) 191bool CalendarLocal::addTodo( Todo *todo )
192{ 192{
193 mTodoList.append( todo ); 193 mTodoList.append( todo );
194 194
195 todo->registerObserver( this ); 195 todo->registerObserver( this );
196 196
197 // Set up subtask relations 197 // Set up subtask relations
198 setupRelations( todo ); 198 setupRelations( todo );
199 199
200 setModified( true ); 200 setModified( true );
201 201
202 return true; 202 return true;
203} 203}
204 204
205void CalendarLocal::deleteTodo( Todo *todo ) 205void CalendarLocal::deleteTodo( Todo *todo )
206{ 206{
207 // Handle orphaned children 207 // Handle orphaned children
208 if ( mUndoIncidence ) delete mUndoIncidence; 208 if ( mUndoIncidence ) delete mUndoIncidence;
209 removeRelations( todo ); 209 removeRelations( todo );
210 mUndoIncidence = todo->clone(); 210 mUndoIncidence = todo->clone();
211 211
212 if ( mTodoList.removeRef( todo ) ) { 212 if ( mTodoList.removeRef( todo ) ) {
213 setModified( true ); 213 setModified( true );
214 } 214 }
215} 215}
216 216
217QPtrList<Todo> CalendarLocal::rawTodos() 217QPtrList<Todo> CalendarLocal::rawTodos()
218{ 218{
219 return mTodoList; 219 return mTodoList;
220} 220}
221Todo *CalendarLocal::todo( QString syncProf, QString id ) 221Todo *CalendarLocal::todo( QString syncProf, QString id )
222{ 222{
223 Todo *todo; 223 Todo *todo;
224 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 224 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
225 if ( todo->getID( syncProf ) == id ) return todo; 225 if ( todo->getID( syncProf ) == id ) return todo;
226 } 226 }
227 227
228 return 0; 228 return 0;
229} 229}
230void CalendarLocal::removeSyncInfo( QString syncProfile) 230void CalendarLocal::removeSyncInfo( QString syncProfile)
231{ 231{
232 QPtrList<Incidence> all = rawIncidences() ; 232 QPtrList<Incidence> all = rawIncidences() ;
233 Incidence *inc; 233 Incidence *inc;
234 for ( inc = all.first(); inc; inc = all.next() ) { 234 for ( inc = all.first(); inc; inc = all.next() ) {
235 inc->removeID( syncProfile ); 235 inc->removeID( syncProfile );
236 } 236 }
237 if ( syncProfile.isEmpty() ) { 237 if ( syncProfile.isEmpty() ) {
238 QPtrList<Event> el; 238 QPtrList<Event> el;
239 Event *todo; 239 Event *todo;
240 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 240 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
241 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) 241 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
242 el.append( todo ); 242 el.append( todo );
243 } 243 }
244 for ( todo = el.first(); todo; todo = el.next() ) { 244 for ( todo = el.first(); todo; todo = el.next() ) {
245 deleteIncidence ( todo ); 245 deleteIncidence ( todo );
246 } 246 }
247 } else { 247 } else {
248 Event *lse = event( "last-syncEvent-"+ syncProfile); 248 Event *lse = event( "last-syncEvent-"+ syncProfile);
249 if ( lse ) 249 if ( lse )
250 deleteIncidence ( lse ); 250 deleteIncidence ( lse );
251 } 251 }
252} 252}
253QPtrList<Event> CalendarLocal::getExternLastSyncEvents() 253QPtrList<Event> CalendarLocal::getExternLastSyncEvents()
254{ 254{
255 QPtrList<Event> el; 255 QPtrList<Event> el;
256 Event *todo; 256 Event *todo;
257 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 257 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
258 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) 258 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
259 if ( todo->summary().left(3) == "E: " ) 259 if ( todo->summary().left(3) == "E: " )
260 el.append( todo ); 260 el.append( todo );
261 } 261 }
262 262
263 return el; 263 return el;
264 264
265} 265}
266Event *CalendarLocal::event( QString syncProf, QString id ) 266Event *CalendarLocal::event( QString syncProf, QString id )
267{ 267{
268 Event *todo; 268 Event *todo;
269 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 269 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
270 if ( todo->getID( syncProf ) == id ) return todo; 270 if ( todo->getID( syncProf ) == id ) return todo;
271 } 271 }
272 272
273 return 0; 273 return 0;
274} 274}
275Todo *CalendarLocal::todo( const QString &uid ) 275Todo *CalendarLocal::todo( const QString &uid )
276{ 276{
277 Todo *todo; 277 Todo *todo;
278 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 278 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
279 if ( todo->uid() == uid ) return todo; 279 if ( todo->uid() == uid ) return todo;
280 } 280 }
281 281
282 return 0; 282 return 0;
283} 283}
284QString CalendarLocal::nextSummary() const 284QString CalendarLocal::nextSummary() const
285{ 285{
286 return mNextSummary; 286 return mNextSummary;
287} 287}
288QDateTime CalendarLocal::nextAlarmEventDateTime() const 288QDateTime CalendarLocal::nextAlarmEventDateTime() const
289{ 289{
290 return mNextAlarmEventDateTime; 290 return mNextAlarmEventDateTime;
291} 291}
292void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) 292void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted)
293{ 293{
294 //mNextAlarmIncidence 294 //mNextAlarmIncidence
295 //mNextAlarmDateTime 295 //mNextAlarmDateTime
296 //return mNextSummary; 296 //return mNextSummary;
297 //return mNextAlarmEventDateTime; 297 //return mNextAlarmEventDateTime;
298 bool newNextAlarm = false; 298 bool newNextAlarm = false;
299 bool computeNextAlarm = false; 299 bool computeNextAlarm = false;
300 bool ok; 300 bool ok;
301 int offset; 301 int offset;
302 QDateTime nextA; 302 QDateTime nextA;
303 // QString nextSum; 303 // QString nextSum;
304 //QDateTime nextEvent; 304 //QDateTime nextEvent;
305 if ( mNextAlarmIncidence == 0 || incidence == 0 ) { 305 if ( mNextAlarmIncidence == 0 || incidence == 0 ) {
306 computeNextAlarm = true; 306 computeNextAlarm = true;
307 } else { 307 } else {
308 if ( ! deleted ) { 308 if ( ! deleted ) {
309 nextA = incidence->getNextAlarmDateTime(& ok, &offset ) ; 309 nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
310 if ( ok ) { 310 if ( ok ) {
311 if ( nextA < mNextAlarmDateTime ) { 311 if ( nextA < mNextAlarmDateTime ) {
312 deRegisterAlarm(); 312 deRegisterAlarm();
313 mNextAlarmDateTime = nextA; 313 mNextAlarmDateTime = nextA;
314 mNextSummary = incidence->summary(); 314 mNextSummary = incidence->summary();
315 mNextAlarmEventDateTime = nextA.addSecs(offset ) ; 315 mNextAlarmEventDateTime = nextA.addSecs(offset ) ;
316 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); 316 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime);
317 newNextAlarm = true; 317 newNextAlarm = true;
318 mNextAlarmIncidence = incidence; 318 mNextAlarmIncidence = incidence;
319 } else { 319 } else {
320 if ( incidence == mNextAlarmIncidence ) { 320 if ( incidence == mNextAlarmIncidence ) {
321 computeNextAlarm = true; 321 computeNextAlarm = true;
322 } 322 }
323 } 323 }
324 } else { 324 } else {
325 if ( mNextAlarmIncidence == incidence ) { 325 if ( mNextAlarmIncidence == incidence ) {
326 computeNextAlarm = true; 326 computeNextAlarm = true;
327 } 327 }
328 } 328 }
329 } else { // deleted 329 } else { // deleted
330 if ( incidence == mNextAlarmIncidence ) { 330 if ( incidence == mNextAlarmIncidence ) {
331 computeNextAlarm = true; 331 computeNextAlarm = true;
332 } 332 }
333 } 333 }
334 } 334 }
335 if ( computeNextAlarm ) { 335 if ( computeNextAlarm ) {
336 deRegisterAlarm(); 336 deRegisterAlarm();
337 nextA = nextAlarm( 1000 ); 337 nextA = nextAlarm( 1000 );
338 if (! mNextAlarmIncidence ) { 338 if (! mNextAlarmIncidence ) {
339 return; 339 return;
340 } 340 }
341 newNextAlarm = true; 341 newNextAlarm = true;
342 } 342 }
343 if ( newNextAlarm ) 343 if ( newNextAlarm )
344 registerAlarm(); 344 registerAlarm();
345} 345}
346QString CalendarLocal:: getAlarmNotification() 346QString CalendarLocal:: getAlarmNotification()
347{ 347{
348 QString ret; 348 QString ret;
349 // this should not happen 349 // this should not happen
350 if (! mNextAlarmIncidence ) 350 if (! mNextAlarmIncidence )
351 return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; 351 return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString;
352 Alarm* alarm = mNextAlarmIncidence->alarms().first(); 352 Alarm* alarm = mNextAlarmIncidence->alarms().first();
353 if ( alarm->type() == Alarm::Procedure ) { 353 if ( alarm->type() == Alarm::Procedure ) {
354 ret = "proc_alarm" + alarm->programFile()+"+++"; 354 ret = "proc_alarm" + alarm->programFile()+"+++";
355 } else { 355 } else {
356 ret = "audio_alarm" +alarm->audioFile() +"+++"; 356 ret = "audio_alarm" +alarm->audioFile() +"+++";
357 } 357 }
358 ret += "cal_alarm"+ mNextSummary.left( 25 ); 358 ret += "cal_alarm"+ mNextSummary.left( 25 );
359 if ( mNextSummary.length() > 25 ) 359 if ( mNextSummary.length() > 25 )
360 ret += "\n" + mNextSummary.mid(25, 25 ); 360 ret += "\n" + mNextSummary.mid(25, 25 );
361 ret+= "\n"+mNextAlarmEventDateTimeString; 361 ret+= "\n"+mNextAlarmEventDateTimeString;
362 return ret; 362 return ret;
363} 363}
364void CalendarLocal::registerAlarm() 364void CalendarLocal::registerAlarm()
365{ 365{
366 mLastAlarmNotificationString = getAlarmNotification(); 366 mLastAlarmNotificationString = getAlarmNotification();
367 // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); 367 // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() );
368 emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); 368 emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString );
369// #ifndef DESKTOP_VERSION 369// #ifndef DESKTOP_VERSION
370// AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); 370// AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() );
371// #endif 371// #endif
372} 372}
373void CalendarLocal::deRegisterAlarm() 373void CalendarLocal::deRegisterAlarm()
374{ 374{
375 if ( mLastAlarmNotificationString.isNull() ) 375 if ( mLastAlarmNotificationString.isNull() )
376 return; 376 return;
377 //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); 377 //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() );
378 378
379 emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); 379 emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString );
380 mNextAlarmEventDateTime = QDateTime(); 380 mNextAlarmEventDateTime = QDateTime();
381// #ifndef DESKTOP_VERSION 381// #ifndef DESKTOP_VERSION
382// AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); 382// AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() );
383// #endif 383// #endif
384} 384}
385 385
386QPtrList<Todo> CalendarLocal::todos( const QDate &date ) 386QPtrList<Todo> CalendarLocal::todos( const QDate &date )
387{ 387{
388 QPtrList<Todo> todos; 388 QPtrList<Todo> todos;
389 389
390 Todo *todo; 390 Todo *todo;
391 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 391 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
392 if ( todo->hasDueDate() && todo->dtDue().date() == date ) { 392 if ( todo->hasDueDate() && todo->dtDue().date() == date ) {
393 todos.append( todo ); 393 todos.append( todo );
394 } 394 }
395 } 395 }
396 396
397 filter()->apply( &todos ); 397 filter()->apply( &todos );
398 return todos; 398 return todos;
399} 399}
400void CalendarLocal::reInitAlarmSettings() 400void CalendarLocal::reInitAlarmSettings()
401{ 401{
402 if ( !mNextAlarmIncidence ) { 402 if ( !mNextAlarmIncidence ) {
403 nextAlarm( 1000 ); 403 nextAlarm( 1000 );
404 } 404 }
405 deRegisterAlarm(); 405 deRegisterAlarm();
406 mNextAlarmIncidence = 0; 406 mNextAlarmIncidence = 0;
407 checkAlarmForIncidence( 0, false ); 407 checkAlarmForIncidence( 0, false );
408 408
409} 409}
410 410
411 411
412 412
413QDateTime CalendarLocal::nextAlarm( int daysTo ) 413QDateTime CalendarLocal::nextAlarm( int daysTo )
414{ 414{
415 QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); 415 QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo );
416 QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); 416 QDateTime start = QDateTime::currentDateTime().addSecs( 30 );
417 QDateTime next; 417 QDateTime next;
418 Event *e; 418 Event *e;
419 bool ok; 419 bool ok;
420 bool found = false; 420 bool found = false;
421 int offset; 421 int offset;
422 mNextAlarmIncidence = 0; 422 mNextAlarmIncidence = 0;
423 for( e = mEventList.first(); e; e = mEventList.next() ) { 423 for( e = mEventList.first(); e; e = mEventList.next() ) {
424 next = e->getNextAlarmDateTime(& ok, &offset ) ; 424 next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
425 if ( ok ) { 425 if ( ok ) {
426 if ( next < nextA ) { 426 if ( next < nextA ) {
427 nextA = next; 427 nextA = next;
428 found = true; 428 found = true;
429 mNextSummary = e->summary(); 429 mNextSummary = e->summary();
430 mNextAlarmEventDateTime = next.addSecs(offset ) ; 430 mNextAlarmEventDateTime = next.addSecs(offset ) ;
431 mNextAlarmIncidence = (Incidence *) e; 431 mNextAlarmIncidence = (Incidence *) e;
432 } 432 }
433 } 433 }
434 } 434 }
435 Todo *t; 435 Todo *t;
436 for( t = mTodoList.first(); t; t = mTodoList.next() ) { 436 for( t = mTodoList.first(); t; t = mTodoList.next() ) {
437 next = t->getNextAlarmDateTime(& ok, &offset ) ; 437 next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
438 if ( ok ) { 438 if ( ok ) {
439 if ( next < nextA ) { 439 if ( next < nextA ) {
440 nextA = next; 440 nextA = next;
441 found = true; 441 found = true;
442 mNextSummary = t->summary(); 442 mNextSummary = t->summary();
443 mNextAlarmEventDateTime = next.addSecs(offset ); 443 mNextAlarmEventDateTime = next.addSecs(offset );
444 mNextAlarmIncidence = (Incidence *) t; 444 mNextAlarmIncidence = (Incidence *) t;
445 } 445 }
446 } 446 }
447 } 447 }
448 if ( mNextAlarmIncidence ) { 448 if ( mNextAlarmIncidence ) {
449 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); 449 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime);
450 mNextAlarmDateTime = nextA; 450 mNextAlarmDateTime = nextA;
451 } 451 }
452 return nextA; 452 return nextA;
453} 453}
454Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) 454Alarm::List CalendarLocal::alarmsTo( const QDateTime &to )
455{ 455{
456 return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); 456 return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to );
457} 457}
458 458
459Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) 459Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to )
460{ 460{
461 kdDebug(5800) << "CalendarLocal::alarms(" << from.toString() << " - " 461 kdDebug(5800) << "CalendarLocal::alarms(" << from.toString() << " - "
462 << to.toString() << ")\n"; 462 << to.toString() << ")\n";
463 463
464 Alarm::List alarms; 464 Alarm::List alarms;
465 465
466 Event *e; 466 Event *e;
467 467
468 for( e = mEventList.first(); e; e = mEventList.next() ) { 468 for( e = mEventList.first(); e; e = mEventList.next() ) {
469 if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); 469 if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to );
470 else appendAlarms( alarms, e, from, to ); 470 else appendAlarms( alarms, e, from, to );
471 } 471 }
472 472
473 Todo *t; 473 Todo *t;
474 for( t = mTodoList.first(); t; t = mTodoList.next() ) { 474 for( t = mTodoList.first(); t; t = mTodoList.next() ) {
475 appendAlarms( alarms, t, from, to ); 475 appendAlarms( alarms, t, from, to );
476 } 476 }
477 477
478 return alarms; 478 return alarms;
479} 479}
480 480
481void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, 481void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence,
482 const QDateTime &from, const QDateTime &to ) 482 const QDateTime &from, const QDateTime &to )
483{ 483{
484 QPtrList<Alarm> alarmList = incidence->alarms(); 484 QPtrList<Alarm> alarmList = incidence->alarms();
485 Alarm *alarm; 485 Alarm *alarm;
486 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { 486 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) {
487// kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() 487// kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text()
488// << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; 488// << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl;
489 if ( alarm->enabled() ) { 489 if ( alarm->enabled() ) {
490 if ( alarm->time() >= from && alarm->time() <= to ) { 490 if ( alarm->time() >= from && alarm->time() <= to ) {
491 kdDebug(5800) << "CalendarLocal::appendAlarms() '" << incidence->summary() 491 kdDebug(5800) << "CalendarLocal::appendAlarms() '" << incidence->summary()
492 << "': " << alarm->time().toString() << endl; 492 << "': " << alarm->time().toString() << endl;
493 alarms.append( alarm ); 493 alarms.append( alarm );
494 } 494 }
495 } 495 }
496 } 496 }
497} 497}
498 498
499void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, 499void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms,
500 Incidence *incidence, 500 Incidence *incidence,
501 const QDateTime &from, 501 const QDateTime &from,
502 const QDateTime &to ) 502 const QDateTime &to )
503{ 503{
504 504
505 QPtrList<Alarm> alarmList = incidence->alarms(); 505 QPtrList<Alarm> alarmList = incidence->alarms();
506 Alarm *alarm; 506 Alarm *alarm;
507 QDateTime qdt; 507 QDateTime qdt;
508 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { 508 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) {
509 if (incidence->recursOn(from.date())) { 509 if (incidence->recursOn(from.date())) {
510 qdt.setTime(alarm->time().time()); 510 qdt.setTime(alarm->time().time());
511 qdt.setDate(from.date()); 511 qdt.setDate(from.date());
512 } 512 }
513 else qdt = alarm->time(); 513 else qdt = alarm->time();
514 // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); 514 // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1());
515 if ( alarm->enabled() ) { 515 if ( alarm->enabled() ) {
516 if ( qdt >= from && qdt <= to ) { 516 if ( qdt >= from && qdt <= to ) {
517 alarms.append( alarm ); 517 alarms.append( alarm );
518 } 518 }
519 } 519 }
520 } 520 }
521} 521}
522 522
523 523
524/****************************** PROTECTED METHODS ****************************/ 524/****************************** PROTECTED METHODS ****************************/
525 525
526// after changes are made to an event, this should be called. 526// after changes are made to an event, this should be called.
527void CalendarLocal::update( IncidenceBase *incidence ) 527void CalendarLocal::update( IncidenceBase *incidence )
528{ 528{
529 incidence->setSyncStatus( Event::SYNCMOD ); 529 incidence->setSyncStatus( Event::SYNCMOD );
530 incidence->setLastModified( QDateTime::currentDateTime() ); 530 incidence->setLastModified( QDateTime::currentDateTime() );
531 // we should probably update the revision number here, 531 // we should probably update the revision number here,
532 // or internally in the Event itself when certain things change. 532 // or internally in the Event itself when certain things change.
533 // need to verify with ical documentation. 533 // need to verify with ical documentation.
534 534
535 setModified( true ); 535 setModified( true );
536} 536}
537 537
538void CalendarLocal::insertEvent( Event *event ) 538void CalendarLocal::insertEvent( Event *event )
539{ 539{
540 if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); 540 if ( mEventList.findRef( event ) < 0 ) mEventList.append( event );
541} 541}
542 542
543 543
544QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) 544QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted )
545{ 545{
546 QPtrList<Event> eventList; 546 QPtrList<Event> eventList;
547 547
548 Event *event; 548 Event *event;
549 for( event = mEventList.first(); event; event = mEventList.next() ) { 549 for( event = mEventList.first(); event; event = mEventList.next() ) {
550 if ( event->doesRecur() ) { 550 if ( event->doesRecur() ) {
551 if ( event->isMultiDay() ) { 551 if ( event->isMultiDay() ) {
552 int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); 552 int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() );
553 int i; 553 int i;
554 for ( i = 0; i <= extraDays; i++ ) { 554 for ( i = 0; i <= extraDays; i++ ) {
555 if ( event->recursOn( qd.addDays( -i ) ) ) { 555 if ( event->recursOn( qd.addDays( -i ) ) ) {
556 eventList.append( event ); 556 eventList.append( event );
557 break; 557 break;
558 } 558 }
559 } 559 }
560 } else { 560 } else {
561 if ( event->recursOn( qd ) ) 561 if ( event->recursOn( qd ) )
562 eventList.append( event ); 562 eventList.append( event );
563 } 563 }
564 } else { 564 } else {
565 if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { 565 if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) {
566 eventList.append( event ); 566 eventList.append( event );
567 } 567 }
568 } 568 }
569 } 569 }
570 570
571 if ( !sorted ) { 571 if ( !sorted ) {
572 return eventList; 572 return eventList;
573 } 573 }
574 574
575 // kdDebug(5800) << "Sorting events for date\n" << endl; 575 // kdDebug(5800) << "Sorting events for date\n" << endl;
576 // now, we have to sort it based on dtStart.time() 576 // now, we have to sort it based on dtStart.time()
577 QPtrList<Event> eventListSorted; 577 QPtrList<Event> eventListSorted;
578 Event *sortEvent; 578 Event *sortEvent;
579 for ( event = eventList.first(); event; event = eventList.next() ) { 579 for ( event = eventList.first(); event; event = eventList.next() ) {
580 sortEvent = eventListSorted.first(); 580 sortEvent = eventListSorted.first();
581 int i = 0; 581 int i = 0;
582 while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) 582 while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() )
583 { 583 {
584 i++; 584 i++;
585 sortEvent = eventListSorted.next(); 585 sortEvent = eventListSorted.next();
586 } 586 }
587 eventListSorted.insert( i, event ); 587 eventListSorted.insert( i, event );
588 } 588 }
589 return eventListSorted; 589 return eventListSorted;
590} 590}
591 591
592 592
593QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, 593QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end,
594 bool inclusive ) 594 bool inclusive )
595{ 595{
596 Event *event = 0; 596 Event *event = 0;
597 597
598 QPtrList<Event> eventList; 598 QPtrList<Event> eventList;
599 599
600 // Get non-recurring events 600 // Get non-recurring events
601 for( event = mEventList.first(); event; event = mEventList.next() ) { 601 for( event = mEventList.first(); event; event = mEventList.next() ) {
602 if ( event->doesRecur() ) { 602 if ( event->doesRecur() ) {
603 QDate rStart = event->dtStart().date(); 603 QDate rStart = event->dtStart().date();
604 bool found = false; 604 bool found = false;
605 if ( inclusive ) { 605 if ( inclusive ) {
606 if ( rStart >= start && rStart <= end ) { 606 if ( rStart >= start && rStart <= end ) {
607 // Start date of event is in range. Now check for end date. 607 // Start date of event is in range. Now check for end date.
608 // if duration is negative, event recurs forever, so do not include it. 608 // if duration is negative, event recurs forever, so do not include it.
609 if ( event->recurrence()->duration() == 0 ) { // End date set 609 if ( event->recurrence()->duration() == 0 ) { // End date set
610 QDate rEnd = event->recurrence()->endDate(); 610 QDate rEnd = event->recurrence()->endDate();
611 if ( rEnd >= start && rEnd <= end ) { // End date within range 611 if ( rEnd >= start && rEnd <= end ) { // End date within range
612 found = true; 612 found = true;
613 } 613 }
614 } else if ( event->recurrence()->duration() > 0 ) { // Duration set 614 } else if ( event->recurrence()->duration() > 0 ) { // Duration set
615 // TODO: Calculate end date from duration. Should be done in Event 615 // TODO: Calculate end date from duration. Should be done in Event
616 // For now exclude all events with a duration. 616 // For now exclude all events with a duration.
617 } 617 }
618 } 618 }
619 } else { 619 } else {
620 bool founOne; 620 bool founOne;
621 QDate next = event->getNextOccurence( start, &founOne ).date(); 621 QDate next = event->getNextOccurence( start, &founOne ).date();
622 if ( founOne ) { 622 if ( founOne ) {
623 if ( next <= end ) { 623 if ( next <= end ) {
624 found = true; 624 found = true;
625 } 625 }
626 } 626 }
627 627
628 /* 628 /*
629 // crap !!! 629 // crap !!!
630 if ( rStart <= end ) { // Start date not after range 630 if ( rStart <= end ) { // Start date not after range
631 if ( rStart >= start ) { // Start date within range 631 if ( rStart >= start ) { // Start date within range
632 found = true; 632 found = true;
633 } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever 633 } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever
634 found = true; 634 found = true;
635 } else if ( event->recurrence()->duration() == 0 ) { // End date set 635 } else if ( event->recurrence()->duration() == 0 ) { // End date set
636 QDate rEnd = event->recurrence()->endDate(); 636 QDate rEnd = event->recurrence()->endDate();
637 if ( rEnd >= start && rEnd <= end ) { // End date within range 637 if ( rEnd >= start && rEnd <= end ) { // End date within range
638 found = true; 638 found = true;
639 } 639 }
640 } else { // Duration set 640 } else { // Duration set
641 // TODO: Calculate end date from duration. Should be done in Event 641 // TODO: Calculate end date from duration. Should be done in Event
642 // For now include all events with a duration. 642 // For now include all events with a duration.
643 found = true; 643 found = true;
644 } 644 }
645 } 645 }
646 */ 646 */
647 647
648 } 648 }
649 649
650 if ( found ) eventList.append( event ); 650 if ( found ) eventList.append( event );
651 } else { 651 } else {
652 QDate s = event->dtStart().date(); 652 QDate s = event->dtStart().date();
653 QDate e = event->dtEnd().date(); 653 QDate e = event->dtEnd().date();
654 654
655 if ( inclusive ) { 655 if ( inclusive ) {
656 if ( s >= start && e <= end ) { 656 if ( s >= start && e <= end ) {
657 eventList.append( event ); 657 eventList.append( event );
658 } 658 }
659 } else { 659 } else {
660 if ( ( s >= start && s <= end ) || ( e >= start && e <= end ) ) { 660 if ( ( s >= start && s <= end ) || ( e >= start && e <= end ) ) {
661 eventList.append( event ); 661 eventList.append( event );
662 } 662 }
663 } 663 }
664 } 664 }
665 } 665 }
666 666
667 return eventList; 667 return eventList;
668} 668}
669 669
670QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) 670QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt )
671{ 671{
672 return rawEventsForDate( qdt.date() ); 672 return rawEventsForDate( qdt.date() );
673} 673}
674 674
675QPtrList<Event> CalendarLocal::rawEvents() 675QPtrList<Event> CalendarLocal::rawEvents()
676{ 676{
677 return mEventList; 677 return mEventList;
678} 678}
679 679
680bool CalendarLocal::addJournal(Journal *journal) 680bool CalendarLocal::addJournal(Journal *journal)
681{ 681{
682 if ( journal->dtStart().isValid()) 682 if ( journal->dtStart().isValid())
683 kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl; 683 kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl;
684 else 684 else
685 kdDebug(5800) << "Adding Journal without a DTSTART" << endl; 685 kdDebug(5800) << "Adding Journal without a DTSTART" << endl;
686 686
687 mJournalList.append(journal); 687 mJournalList.append(journal);
688 688
689 journal->registerObserver( this ); 689 journal->registerObserver( this );
690 690
691 setModified( true ); 691 setModified( true );
692 692
693 return true; 693 return true;
694} 694}
695 695
696void CalendarLocal::deleteJournal( Journal *journal ) 696void CalendarLocal::deleteJournal( Journal *journal )
697{ 697{
698 if ( mUndoIncidence ) delete mUndoIncidence; 698 if ( mUndoIncidence ) delete mUndoIncidence;
699 mUndoIncidence = journal->clone(); 699 mUndoIncidence = journal->clone();
700 mUndoIncidence->setSummary( mUndoIncidence->description().left(25)); 700 mUndoIncidence->setSummary( mUndoIncidence->description().left(25));
701 if ( mJournalList.removeRef(journal) ) { 701 if ( mJournalList.removeRef(journal) ) {
702 setModified( true ); 702 setModified( true );
703 } 703 }
704} 704}
705 705
706Journal *CalendarLocal::journal( const QDate &date ) 706Journal *CalendarLocal::journal( const QDate &date )
707{ 707{
708// kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; 708// kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl;
709 709
710 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 710 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
711 if ( it->dtStart().date() == date ) 711 if ( it->dtStart().date() == date )
712 return it; 712 return it;
713 713
714 return 0; 714 return 0;
715} 715}
716 716
717Journal *CalendarLocal::journal( const QString &uid ) 717Journal *CalendarLocal::journal( const QString &uid )
718{ 718{
719 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 719 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
720 if ( it->uid() == uid ) 720 if ( it->uid() == uid )
721 return it; 721 return it;
722 722
723 return 0; 723 return 0;
724} 724}
725 725
726QPtrList<Journal> CalendarLocal::journals() 726QPtrList<Journal> CalendarLocal::journals()
727{ 727{
728 return mJournalList; 728 return mJournalList;
729} 729}
730 730
diff --git a/libkcal/event.cpp b/libkcal/event.cpp
index de8dceb..9b99855 100644
--- a/libkcal/event.cpp
+++ b/libkcal/event.cpp
@@ -1,221 +1,221 @@
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 24
25#include "event.h" 25#include "event.h"
26 26
27using namespace KCal; 27using namespace KCal;
28 28
29Event::Event() : 29Event::Event() :
30 mHasEndDate( false ), mTransparency( Opaque ) 30 mHasEndDate( false ), mTransparency( Opaque )
31{ 31{
32} 32}
33 33
34Event::Event(const Event &e) : Incidence(e) 34Event::Event(const Event &e) : Incidence(e)
35{ 35{
36 mDtEnd = e.mDtEnd; 36 mDtEnd = e.mDtEnd;
37 mHasEndDate = e.mHasEndDate; 37 mHasEndDate = e.mHasEndDate;
38 mTransparency = e.mTransparency; 38 mTransparency = e.mTransparency;
39} 39}
40 40
41Event::~Event() 41Event::~Event()
42{ 42{
43} 43}
44 44
45Incidence *Event::clone() 45Incidence *Event::clone()
46{ 46{
47 return new Event(*this); 47 return new Event(*this);
48} 48}
49 49
50bool KCal::operator==( const Event& e1, const Event& e2 ) 50bool KCal::operator==( const Event& e1, const Event& e2 )
51{ 51{
52 return operator==( (const Incidence&)e1, (const Incidence&)e2 ) && 52 return operator==( (const Incidence&)e1, (const Incidence&)e2 ) &&
53 e1.dtEnd() == e2.dtEnd() && 53 e1.dtEnd() == e2.dtEnd() &&
54 e1.hasEndDate() == e2.hasEndDate() && 54 e1.hasEndDate() == e2.hasEndDate() &&
55 e1.transparency() == e2.transparency(); 55 e1.transparency() == e2.transparency();
56} 56}
57 57
58 58
59bool Event::contains ( Event* from ) 59bool Event::contains ( Event* from )
60{ 60{
61 61
62 if ( !from->summary().isEmpty() ) 62 if ( !from->summary().isEmpty() )
63 if ( !summary().startsWith( from->summary() )) 63 if ( !summary().startsWith( from->summary() ))
64 return false; 64 return false;
65 if ( from->dtStart().isValid() ) 65 if ( from->dtStart().isValid() )
66 if (dtStart() != from->dtStart() ) 66 if (dtStart() != from->dtStart() )
67 return false; 67 return false;
68 if ( from->dtEnd().isValid() ) 68 if ( from->dtEnd().isValid() )
69 if ( dtEnd() != from->dtEnd() ) 69 if ( dtEnd() != from->dtEnd() )
70 return false; 70 return false;
71 if ( !from->location().isEmpty() ) 71 if ( !from->location().isEmpty() )
72 if ( !location().startsWith( from->location() ) ) 72 if ( !location().startsWith( from->location() ) )
73 return false; 73 return false;
74 if ( !from->description().isEmpty() ) 74 if ( !from->description().isEmpty() )
75 if ( !description().startsWith( from->description() )) 75 if ( !description().startsWith( from->description() ))
76 return false; 76 return false;
77 if ( from->alarms().count() ) { 77 if ( from->alarms().count() ) {
78 Alarm *a = from->alarms().first(); 78 Alarm *a = from->alarms().first();
79 if ( a->enabled() ){ 79 if ( a->enabled() ){
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 ) const 174QDateTime Event::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const
175{ 175{
176 176
177 bool yes; 177 bool yes;
178 QDateTime incidenceStart = getNextOccurence( QDateTime::currentDateTime(), &yes ); 178 QDateTime incidenceStart = getNextOccurence( start_dt, &yes );
179 if ( ! yes || cancelled() ) { 179 if ( ! yes || cancelled() ) {
180 *ok = false; 180 *ok = false;
181 return QDateTime (); 181 return QDateTime ();
182 } 182 }
183 183
184 bool enabled = false; 184 bool enabled = false;
185 Alarm* alarm; 185 Alarm* alarm;
186 int off = 0; 186 int off = 0;
187 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; 187 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );;
188 // if ( QDateTime::currentDateTime() > incidenceStart ){ 188 // if ( QDateTime::currentDateTime() > incidenceStart ){
189// *ok = false; 189// *ok = false;
190// return incidenceStart; 190// return incidenceStart;
191// } 191// }
192 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { 192 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) {
193 if (alarm->enabled()) { 193 if (alarm->enabled()) {
194 if ( alarm->hasTime () ) { 194 if ( alarm->hasTime () ) {
195 if ( alarm->time() < alarmStart ) { 195 if ( alarm->time() < alarmStart ) {
196 alarmStart = alarm->time(); 196 alarmStart = alarm->time();
197 enabled = true; 197 enabled = true;
198 off = alarmStart.secsTo( incidenceStart ); 198 off = alarmStart.secsTo( incidenceStart );
199 } 199 }
200 200
201 } else { 201 } else {
202 int secs = alarm->startOffset().asSeconds(); 202 int secs = alarm->startOffset().asSeconds();
203 if ( incidenceStart.addSecs( secs ) < alarmStart ) { 203 if ( incidenceStart.addSecs( secs ) < alarmStart ) {
204 alarmStart = incidenceStart.addSecs( secs ); 204 alarmStart = incidenceStart.addSecs( secs );
205 enabled = true; 205 enabled = true;
206 off = -secs; 206 off = -secs;
207 } 207 }
208 } 208 }
209 } 209 }
210 } 210 }
211 if ( enabled ) { 211 if ( enabled ) {
212 if ( alarmStart > QDateTime::currentDateTime() ) { 212 if ( alarmStart > start_dt ) {
213 *ok = true; 213 *ok = true;
214 * offset = off; 214 * offset = off;
215 return alarmStart; 215 return alarmStart;
216 } 216 }
217 } 217 }
218 *ok = false; 218 *ok = false;
219 return QDateTime (); 219 return QDateTime ();
220 220
221} 221}
diff --git a/libkcal/event.h b/libkcal/event.h
index 3bc8adc..8729956 100644
--- a/libkcal/event.h
+++ b/libkcal/event.h
@@ -1,90 +1,90 @@
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 EVENT_H 21#ifndef EVENT_H
22#define EVENT_H 22#define EVENT_H
23// 23//
24// Event component, representing a VEVENT object 24// Event component, representing a VEVENT object
25// 25//
26 26
27#include "incidence.h" 27#include "incidence.h"
28namespace KCal { 28namespace KCal {
29 29
30/** 30/**
31 This class provides an Event in the sense of RFC2445. 31 This class provides an Event in the sense of RFC2445.
32*/ 32*/
33class Event : public Incidence 33class Event : public Incidence
34{ 34{
35 public: 35 public:
36 enum Transparency { Opaque, Transparent }; 36 enum Transparency { Opaque, Transparent };
37 typedef ListBase<Event> List; 37 typedef ListBase<Event> List;
38 Event(); 38 Event();
39 Event(const Event &); 39 Event(const Event &);
40 ~Event(); 40 ~Event();
41 41
42 QCString type() const { return "Event"; } 42 QCString type() const { return "Event"; }
43 43
44 Incidence *clone(); 44 Incidence *clone();
45 QDateTime getNextAlarmDateTime( bool * ok, int * offset ) const; 45 QDateTime getNextAlarmDateTime( bool * ok, int * offset ,QDateTime start_dt ) const;
46 46
47 /** for setting an event's ending date/time with a QDateTime. */ 47 /** for setting an event's ending date/time with a QDateTime. */
48 void setDtEnd(const QDateTime &dtEnd); 48 void setDtEnd(const QDateTime &dtEnd);
49 /** Return the event's ending date/time as a QDateTime. */ 49 /** Return the event's ending date/time as a QDateTime. */
50 virtual QDateTime dtEnd() const; 50 virtual QDateTime dtEnd() const;
51 /** returns an event's end time as a string formatted according to the 51 /** returns an event's end time as a string formatted according to the
52 users locale settings */ 52 users locale settings */
53 QString dtEndTimeStr() const; 53 QString dtEndTimeStr() const;
54 /** returns an event's end date as a string formatted according to the 54 /** returns an event's end date as a string formatted according to the
55 users locale settings */ 55 users locale settings */
56 QString dtEndDateStr(bool shortfmt=true) const; 56 QString dtEndDateStr(bool shortfmt=true) const;
57 /** returns an event's end date and time as a string formatted according 57 /** returns an event's end date and time as a string formatted according
58 to the users locale settings */ 58 to the users locale settings */
59 QString dtEndStr(bool shortfmt=true) const; 59 QString dtEndStr(bool shortfmt=true) const;
60 void setHasEndDate(bool); 60 void setHasEndDate(bool);
61 /** Return whether the event has an end date/time. */ 61 /** Return whether the event has an end date/time. */
62 bool hasEndDate() const; 62 bool hasEndDate() const;
63 63
64 /** Return true if the event spans multiple days, otherwise return false. */ 64 /** Return true if the event spans multiple days, otherwise return false. */
65 bool isMultiDay() const; 65 bool isMultiDay() const;
66 66
67 /** set the event's time transparency level. */ 67 /** set the event's time transparency level. */
68 void setTransparency(Transparency transparency); 68 void setTransparency(Transparency transparency);
69 /** get the event's time transparency level. */ 69 /** get the event's time transparency level. */
70 Transparency transparency() const; 70 Transparency transparency() const;
71 71
72 void setDuration(int seconds); 72 void setDuration(int seconds);
73 73
74 bool contains ( Event*); 74 bool contains ( Event*);
75 75
76 private: 76 private:
77 bool accept(Visitor &v) { return v.visit(this); } 77 bool accept(Visitor &v) { return v.visit(this); }
78 78
79 QDateTime mDtEnd; 79 QDateTime mDtEnd;
80 bool mHasEndDate; 80 bool mHasEndDate;
81 Transparency mTransparency; 81 Transparency mTransparency;
82}; 82};
83 83
84bool operator==( const Event&, const Event& ); 84bool operator==( const Event&, const Event& );
85 85
86 86
87} 87}
88 88
89 89
90#endif 90#endif
diff --git a/libkcal/incidence.h b/libkcal/incidence.h
index ebd50d0..aa51e84 100644
--- a/libkcal/incidence.h
+++ b/libkcal/incidence.h
@@ -1,317 +1,317 @@
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#ifndef INCIDENCE_H 20#ifndef INCIDENCE_H
21#define INCIDENCE_H 21#define INCIDENCE_H
22// 22//
23// Incidence - base class of calendaring components 23// Incidence - base class of calendaring components
24// 24//
25 25
26#include <qdatetime.h> 26#include <qdatetime.h>
27#include <qstringlist.h> 27#include <qstringlist.h>
28#include <qvaluelist.h> 28#include <qvaluelist.h>
29 29
30#include "recurrence.h" 30#include "recurrence.h"
31#include "alarm.h" 31#include "alarm.h"
32#include "attachment.h" 32#include "attachment.h"
33#include "listbase.h" 33#include "listbase.h"
34#include "incidencebase.h" 34#include "incidencebase.h"
35 35
36namespace KCal { 36namespace KCal {
37 37
38class Event; 38class Event;
39class Todo; 39class Todo;
40class Journal; 40class Journal;
41 41
42/** 42/**
43 This class provides the base class common to all calendar components. 43 This class provides the base class common to all calendar components.
44*/ 44*/
45class Incidence : public IncidenceBase 45class Incidence : public IncidenceBase
46{ 46{
47 public: 47 public:
48 /** 48 /**
49 This class provides the interface for a visitor of calendar components. It 49 This class provides the interface for a visitor of calendar components. It
50 serves as base class for concrete visitors, which implement certain actions on 50 serves as base class for concrete visitors, which implement certain actions on
51 calendar components. It allows to add functions, which operate on the concrete 51 calendar components. It allows to add functions, which operate on the concrete
52 types of calendar components, without changing the calendar component classes. 52 types of calendar components, without changing the calendar component classes.
53 */ 53 */
54 class Visitor 54 class Visitor
55 { 55 {
56 public: 56 public:
57 /** Destruct Incidence::Visitor */ 57 /** Destruct Incidence::Visitor */
58 virtual ~Visitor() {} 58 virtual ~Visitor() {}
59 59
60 /** 60 /**
61 Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions 61 Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions
62 on an Event object. 62 on an Event object.
63 */ 63 */
64 virtual bool visit(Event *) { return false; } 64 virtual bool visit(Event *) { return false; }
65 /** 65 /**
66 Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions 66 Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions
67 on an Todo object. 67 on an Todo object.
68 */ 68 */
69 virtual bool visit(Todo *) { return false; } 69 virtual bool visit(Todo *) { return false; }
70 /** 70 /**
71 Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions 71 Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions
72 on an Journal object. 72 on an Journal object.
73 */ 73 */
74 virtual bool visit(Journal *) { return false; } 74 virtual bool visit(Journal *) { return false; }
75 75
76 protected: 76 protected:
77 /** Constructor is protected to prevent direct creation of visitor base class. */ 77 /** Constructor is protected to prevent direct creation of visitor base class. */
78 Visitor() {} 78 Visitor() {}
79 }; 79 };
80 80
81 /** 81 /**
82 This class implements a visitor for adding an Incidence to a resource 82 This class implements a visitor for adding an Incidence to a resource
83 supporting addEvent(), addTodo() and addJournal() calls. 83 supporting addEvent(), addTodo() and addJournal() calls.
84 */ 84 */
85 template<class T> 85 template<class T>
86 class AddVisitor : public Visitor 86 class AddVisitor : public Visitor
87 { 87 {
88 public: 88 public:
89 AddVisitor( T *r ) : mResource( r ) {} 89 AddVisitor( T *r ) : mResource( r ) {}
90 bool visit( Event *e ) { return mResource->addEvent( e ); } 90 bool visit( Event *e ) { return mResource->addEvent( e ); }
91 bool visit( Todo *t ) { return mResource->addTodo( t ); } 91 bool visit( Todo *t ) { return mResource->addTodo( t ); }
92 bool visit( Journal *j ) { return mResource->addJournal( j ); } 92 bool visit( Journal *j ) { return mResource->addJournal( j ); }
93 93
94 private: 94 private:
95 T *mResource; 95 T *mResource;
96 }; 96 };
97 97
98 /** enumeration for describing an event's secrecy. */ 98 /** enumeration for describing an event's secrecy. */
99 enum { SecrecyPublic = 0, SecrecyPrivate = 1, SecrecyConfidential = 2 }; 99 enum { SecrecyPublic = 0, SecrecyPrivate = 1, SecrecyConfidential = 2 };
100 typedef ListBase<Incidence> List; 100 typedef ListBase<Incidence> List;
101 Incidence(); 101 Incidence();
102 Incidence(const Incidence &); 102 Incidence(const Incidence &);
103 ~Incidence(); 103 ~Incidence();
104 104
105 /** 105 /**
106 Accept IncidenceVisitor. A class taking part in the visitor mechanism has to 106 Accept IncidenceVisitor. A class taking part in the visitor mechanism has to
107 provide this implementation: 107 provide this implementation:
108 <pre> 108 <pre>
109 bool accept(Visitor &v) { return v.visit(this); } 109 bool accept(Visitor &v) { return v.visit(this); }
110 </pre> 110 </pre>
111 */ 111 */
112 virtual bool accept(Visitor &) { return false; } 112 virtual bool accept(Visitor &) { return false; }
113 113
114 virtual Incidence *clone() = 0; 114 virtual Incidence *clone() = 0;
115 virtual void cloneRelations( Incidence * ); 115 virtual void cloneRelations( Incidence * );
116 116
117 virtual QDateTime getNextAlarmDateTime( bool * ok, int * offset ) const = 0; 117 virtual QDateTime getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const = 0;
118 void setReadOnly( bool ); 118 void setReadOnly( bool );
119 119
120 /** 120 /**
121 Recreate event. The event is made a new unique event, but already stored 121 Recreate event. The event is made a new unique event, but already stored
122 event information is preserved. Sets uniquie id, creation date, last 122 event information is preserved. Sets uniquie id, creation date, last
123 modification date and revision number. 123 modification date and revision number.
124 */ 124 */
125 void recreate(); 125 void recreate();
126 Incidence* recreateCloneException(QDate); 126 Incidence* recreateCloneException(QDate);
127 127
128 /** set creation date */ 128 /** set creation date */
129 void setCreated(QDateTime); 129 void setCreated(QDateTime);
130 /** return time and date of creation. */ 130 /** return time and date of creation. */
131 QDateTime created() const; 131 QDateTime created() const;
132 132
133 /** set the number of revisions this event has seen */ 133 /** set the number of revisions this event has seen */
134 void setRevision(int rev); 134 void setRevision(int rev);
135 /** return the number of revisions this event has seen */ 135 /** return the number of revisions this event has seen */
136 int revision() const; 136 int revision() const;
137 137
138 /** Set starting date/time. */ 138 /** Set starting date/time. */
139 virtual void setDtStart(const QDateTime &dtStart); 139 virtual void setDtStart(const QDateTime &dtStart);
140 /** Return the incidence's ending date/time as a QDateTime. */ 140 /** Return the incidence's ending date/time as a QDateTime. */
141 virtual QDateTime dtEnd() const { return QDateTime(); } 141 virtual QDateTime dtEnd() const { return QDateTime(); }
142 142
143 /** sets the event's lengthy description. */ 143 /** sets the event's lengthy description. */
144 void setDescription(const QString &description); 144 void setDescription(const QString &description);
145 /** returns a reference to the event's description. */ 145 /** returns a reference to the event's description. */
146 QString description() const; 146 QString description() const;
147 147
148 /** sets the event's short summary. */ 148 /** sets the event's short summary. */
149 void setSummary(const QString &summary); 149 void setSummary(const QString &summary);
150 /** returns a reference to the event's summary. */ 150 /** returns a reference to the event's summary. */
151 QString summary() const; 151 QString summary() const;
152 152
153 /** set event's applicable categories */ 153 /** set event's applicable categories */
154 void setCategories(const QStringList &categories, bool setForRelations = false); 154 void setCategories(const QStringList &categories, bool setForRelations = false);
155 void addCategories(const QStringList &categories, bool addToRelations = false); 155 void addCategories(const QStringList &categories, bool addToRelations = false);
156 /** set event's categories based on a comma delimited string */ 156 /** set event's categories based on a comma delimited string */
157 void setCategories(const QString &catStr); 157 void setCategories(const QString &catStr);
158 /** return categories in a list */ 158 /** return categories in a list */
159 QStringList categories() const; 159 QStringList categories() const;
160 /** return categories as a comma separated string */ 160 /** return categories as a comma separated string */
161 QString categoriesStr(); 161 QString categoriesStr();
162 QString categoriesStrWithSpace(); 162 QString categoriesStrWithSpace();
163 163
164 /** point at some other event to which the event relates. This function should 164 /** point at some other event to which the event relates. This function should
165 * only be used when constructing a calendar before the related Event 165 * only be used when constructing a calendar before the related Event
166 * exists. */ 166 * exists. */
167 void setRelatedToUid(const QString &); 167 void setRelatedToUid(const QString &);
168 /** what event does this one relate to? This function should 168 /** what event does this one relate to? This function should
169 * only be used when constructing a calendar before the related Event 169 * only be used when constructing a calendar before the related Event
170 * exists. */ 170 * exists. */
171 QString relatedToUid() const; 171 QString relatedToUid() const;
172 /** point at some other event to which the event relates */ 172 /** point at some other event to which the event relates */
173 void setRelatedTo(Incidence *relatedTo); 173 void setRelatedTo(Incidence *relatedTo);
174 /** what event does this one relate to? */ 174 /** what event does this one relate to? */
175 Incidence *relatedTo() const; 175 Incidence *relatedTo() const;
176 /** All events that are related to this event */ 176 /** All events that are related to this event */
177 QPtrList<Incidence> relations() const; 177 QPtrList<Incidence> relations() const;
178 /** Add an event which is related to this event */ 178 /** Add an event which is related to this event */
179 void addRelation(Incidence *); 179 void addRelation(Incidence *);
180 /** Remove event that is related to this event */ 180 /** Remove event that is related to this event */
181 void removeRelation(Incidence *); 181 void removeRelation(Incidence *);
182 182
183 /** returns the list of dates which are exceptions to the recurrence rule */ 183 /** returns the list of dates which are exceptions to the recurrence rule */
184 DateList exDates() const; 184 DateList exDates() const;
185 /** sets the list of dates which are exceptions to the recurrence rule */ 185 /** sets the list of dates which are exceptions to the recurrence rule */
186 void setExDates(const DateList &_exDates); 186 void setExDates(const DateList &_exDates);
187 void setExDates(const char *dates); 187 void setExDates(const char *dates);
188 /** Add a date to the list of exceptions of the recurrence rule. */ 188 /** Add a date to the list of exceptions of the recurrence rule. */
189 void addExDate(const QDate &date); 189 void addExDate(const QDate &date);
190 190
191 /** returns true if there is an exception for this date in the recurrence 191 /** returns true if there is an exception for this date in the recurrence
192 rule set, or false otherwise. */ 192 rule set, or false otherwise. */
193 bool isException(const QDate &qd) const; 193 bool isException(const QDate &qd) const;
194 194
195 /** add attachment to this event */ 195 /** add attachment to this event */
196 void addAttachment(Attachment *attachment); 196 void addAttachment(Attachment *attachment);
197 /** remove and delete a specific attachment */ 197 /** remove and delete a specific attachment */
198 void deleteAttachment(Attachment *attachment); 198 void deleteAttachment(Attachment *attachment);
199 /** remove and delete all attachments with this mime type */ 199 /** remove and delete all attachments with this mime type */
200 void deleteAttachments(const QString& mime); 200 void deleteAttachments(const QString& mime);
201 /** return list of all associated attachments */ 201 /** return list of all associated attachments */
202 QPtrList<Attachment> attachments() const; 202 QPtrList<Attachment> attachments() const;
203 /** find a list of attachments with this mime type */ 203 /** find a list of attachments with this mime type */
204 QPtrList<Attachment> attachments(const QString& mime) const; 204 QPtrList<Attachment> attachments(const QString& mime) const;
205 205
206 /** sets the event's status the value specified. See the enumeration 206 /** sets the event's status the value specified. See the enumeration
207 * above for possible values. */ 207 * above for possible values. */
208 void setSecrecy(int); 208 void setSecrecy(int);
209 /** return the event's secrecy. */ 209 /** return the event's secrecy. */
210 int secrecy() const; 210 int secrecy() const;
211 /** return the event's secrecy in string format. */ 211 /** return the event's secrecy in string format. */
212 QString secrecyStr() const; 212 QString secrecyStr() const;
213 /** return list of all availbale secrecy classes */ 213 /** return list of all availbale secrecy classes */
214 static QStringList secrecyList(); 214 static QStringList secrecyList();
215 /** return human-readable name of secrecy class */ 215 /** return human-readable name of secrecy class */
216 static QString secrecyName(int); 216 static QString secrecyName(int);
217 217
218 /** returns TRUE if the date specified is one on which the event will 218 /** returns TRUE if the date specified is one on which the event will
219 * recur. */ 219 * recur. */
220 bool recursOn(const QDate &qd) const; 220 bool recursOn(const QDate &qd) const;
221 221
222 // VEVENT and VTODO, but not VJOURNAL (move to EventBase class?): 222 // VEVENT and VTODO, but not VJOURNAL (move to EventBase class?):
223 223
224 /** set resources used, such as Office, Car, etc. */ 224 /** set resources used, such as Office, Car, etc. */
225 void setResources(const QStringList &resources); 225 void setResources(const QStringList &resources);
226 /** return list of current resources */ 226 /** return list of current resources */
227 QStringList resources() const; 227 QStringList resources() const;
228 228
229 /** set the event's priority, 0 is undefined, 1 highest (decreasing order) */ 229 /** set the event's priority, 0 is undefined, 1 highest (decreasing order) */
230 void setPriority(int priority); 230 void setPriority(int priority);
231 /** get the event's priority */ 231 /** get the event's priority */
232 int priority() const; 232 int priority() const;
233 233
234 /** All alarms that are associated with this incidence */ 234 /** All alarms that are associated with this incidence */
235 QPtrList<Alarm> alarms() const; 235 QPtrList<Alarm> alarms() const;
236 /** Create a new alarm which is associated with this incidence */ 236 /** Create a new alarm which is associated with this incidence */
237 Alarm* newAlarm(); 237 Alarm* newAlarm();
238 /** Add an alarm which is associated with this incidence */ 238 /** Add an alarm which is associated with this incidence */
239 void addAlarm(Alarm*); 239 void addAlarm(Alarm*);
240 /** Remove an alarm that is associated with this incidence */ 240 /** Remove an alarm that is associated with this incidence */
241 void removeAlarm(Alarm*); 241 void removeAlarm(Alarm*);
242 /** Remove all alarms that are associated with this incidence */ 242 /** Remove all alarms that are associated with this incidence */
243 void clearAlarms(); 243 void clearAlarms();
244 /** return whether any alarm associated with this incidence is enabled */ 244 /** return whether any alarm associated with this incidence is enabled */
245 bool isAlarmEnabled() const; 245 bool isAlarmEnabled() const;
246 246
247 /** 247 /**
248 Return the recurrence rule associated with this incidence. If there is 248 Return the recurrence rule associated with this incidence. If there is
249 none, returns an appropriate (non-0) object. 249 none, returns an appropriate (non-0) object.
250 */ 250 */
251 Recurrence *recurrence() const; 251 Recurrence *recurrence() const;
252 void setRecurrence(Recurrence * r); 252 void setRecurrence(Recurrence * r);
253 /** 253 /**
254 Forward to Recurrence::doesRecur(). 254 Forward to Recurrence::doesRecur().
255 */ 255 */
256 ushort doesRecur() const; 256 ushort doesRecur() const;
257 257
258 /** set the event's/todo's location. Do _not_ use it with journal */ 258 /** set the event's/todo's location. Do _not_ use it with journal */
259 void setLocation(const QString &location); 259 void setLocation(const QString &location);
260 /** return the event's/todo's location. Do _not_ use it with journal */ 260 /** return the event's/todo's location. Do _not_ use it with journal */
261 QString location() const; 261 QString location() const;
262 /** returns TRUE or FALSE depending on whether the todo has a start date */ 262 /** returns TRUE or FALSE depending on whether the todo has a start date */
263 bool hasStartDate() const; 263 bool hasStartDate() const;
264 /** sets the event's hasStartDate value. */ 264 /** sets the event's hasStartDate value. */
265 void setHasStartDate(bool f); 265 void setHasStartDate(bool f);
266 QDateTime getNextOccurence( const QDateTime& dt, bool* yes ) const; 266 QDateTime getNextOccurence( const QDateTime& dt, bool* yes ) const;
267 bool cancelled() const; 267 bool cancelled() const;
268 void setCancelled( bool b ); 268 void setCancelled( bool b );
269 269
270 bool hasRecurrenceID() const; 270 bool hasRecurrenceID() const;
271 void setHasRecurrenceID( bool b ); 271 void setHasRecurrenceID( bool b );
272 272
273 void setRecurrenceID(QDateTime); 273 void setRecurrenceID(QDateTime);
274 QDateTime recurrenceID () const; 274 QDateTime recurrenceID () const;
275 QDateTime dtStart() const; 275 QDateTime dtStart() const;
276 bool isHoliday() const; 276 bool isHoliday() const;
277 bool isBirthday() const; 277 bool isBirthday() const;
278 bool isAnniversary() const; 278 bool isAnniversary() const;
279 279
280 280
281protected: 281protected:
282 QPtrList<Alarm> mAlarms; 282 QPtrList<Alarm> mAlarms;
283 QPtrList<Incidence> mRelations; 283 QPtrList<Incidence> mRelations;
284 QDateTime mRecurrenceID; 284 QDateTime mRecurrenceID;
285 bool mHasRecurrenceID; 285 bool mHasRecurrenceID;
286 private: 286 private:
287 void checkCategories(); 287 void checkCategories();
288 bool mHoliday, mBirthday, mAnniversary; 288 bool mHoliday, mBirthday, mAnniversary;
289 int mRevision; 289 int mRevision;
290 bool mCancelled; 290 bool mCancelled;
291 291
292 // base components of jounal, event and todo 292 // base components of jounal, event and todo
293 QDateTime mCreated; 293 QDateTime mCreated;
294 QString mDescription; 294 QString mDescription;
295 QString mSummary; 295 QString mSummary;
296 QStringList mCategories; 296 QStringList mCategories;
297 Incidence *mRelatedTo; 297 Incidence *mRelatedTo;
298 QString mRelatedToUid; 298 QString mRelatedToUid;
299 DateList mExDates; 299 DateList mExDates;
300 QPtrList<Attachment> mAttachments; 300 QPtrList<Attachment> mAttachments;
301 QStringList mResources; 301 QStringList mResources;
302 bool mHasStartDate; // if todo has associated start date 302 bool mHasStartDate; // if todo has associated start date
303 303
304 int mSecrecy; 304 int mSecrecy;
305 int mPriority; // 1 = highest, 2 = less, etc. 305 int mPriority; // 1 = highest, 2 = less, etc.
306 306
307 //QPtrList<Alarm> mAlarms; 307 //QPtrList<Alarm> mAlarms;
308 Recurrence *mRecurrence; 308 Recurrence *mRecurrence;
309 309
310 QString mLocation; 310 QString mLocation;
311}; 311};
312 312
313bool operator==( const Incidence&, const Incidence& ); 313bool operator==( const Incidence&, const Incidence& );
314 314
315} 315}
316 316
317#endif 317#endif
diff --git a/libkcal/journal.cpp b/libkcal/journal.cpp
index 351fb32..859161f 100644
--- a/libkcal/journal.cpp
+++ b/libkcal/journal.cpp
@@ -1,49 +1,49 @@
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 "journal.h" 21#include "journal.h"
22 22
23using namespace KCal; 23using namespace KCal;
24 24
25Journal::Journal() 25Journal::Journal()
26{ 26{
27} 27}
28 28
29Journal::~Journal() 29Journal::~Journal()
30{ 30{
31} 31}
32 32
33Incidence *Journal::clone() 33Incidence *Journal::clone()
34{ 34{
35 return new Journal(*this); 35 return new Journal(*this);
36} 36}
37 37
38 38
39bool KCal::operator==( const Journal& j1, const Journal& j2 ) 39bool KCal::operator==( const Journal& j1, const Journal& j2 )
40{ 40{
41 return operator==( (const Incidence&)j1, (const Incidence&)j2 ); 41 return operator==( (const Incidence&)j1, (const Incidence&)j2 );
42} 42}
43 43
44 44
45QDateTime Journal::getNextAlarmDateTime( bool * ok, int * offset ) const 45QDateTime Journal::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const
46{ 46{
47 *ok = false; 47 *ok = false;
48 return QDateTime (); 48 return QDateTime ();
49} 49}
diff --git a/libkcal/journal.h b/libkcal/journal.h
index cb90c7a..2c1d7ea 100644
--- a/libkcal/journal.h
+++ b/libkcal/journal.h
@@ -1,50 +1,50 @@
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#ifndef JOURNAL_H 20#ifndef JOURNAL_H
21#define JOURNAL_H 21#define JOURNAL_H
22// 22//
23// Journal component, representing a VJOURNAL object 23// Journal component, representing a VJOURNAL object
24// 24//
25 25
26#include "incidence.h" 26#include "incidence.h"
27 27
28namespace KCal { 28namespace KCal {
29 29
30/** 30/**
31 This class provides a Journal in the sense of RFC2445. 31 This class provides a Journal in the sense of RFC2445.
32*/ 32*/
33class Journal : public Incidence 33class Journal : public Incidence
34{ 34{
35 public: 35 public:
36 Journal(); 36 Journal();
37 ~Journal(); 37 ~Journal();
38 38
39 QCString type() const { return "Journal"; } 39 QCString type() const { return "Journal"; }
40 40
41 Incidence *clone(); 41 Incidence *clone();
42 QDateTime getNextAlarmDateTime( bool * ok, int * offset ) const; 42 QDateTime getNextAlarmDateTime( bool * ok, int * offset ,QDateTime start_dt ) const;
43private: 43private:
44 bool accept(Visitor &v) { return v.visit(this); } 44 bool accept(Visitor &v) { return v.visit(this); }
45}; 45};
46 46
47 bool operator==( const Journal&, const Journal& ); 47 bool operator==( const Journal&, const Journal& );
48} 48}
49 49
50#endif 50#endif
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp
index d7431c7..473247a 100644
--- a/libkcal/todo.cpp
+++ b/libkcal/todo.cpp
@@ -1,577 +1,577 @@
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 <kglobalsettings.h> 22#include <kglobalsettings.h>
23#include <klocale.h> 23#include <klocale.h>
24#include <kdebug.h> 24#include <kdebug.h>
25#include <qregexp.h> 25#include <qregexp.h>
26#include <qfileinfo.h> 26#include <qfileinfo.h>
27 27
28#include "calendarlocal.h" 28#include "calendarlocal.h"
29#include "icalformat.h" 29#include "icalformat.h"
30#include "todo.h" 30#include "todo.h"
31 31
32using namespace KCal; 32using namespace KCal;
33 33
34Todo::Todo(): QObject(), Incidence() 34Todo::Todo(): QObject(), Incidence()
35{ 35{
36// mStatus = TENTATIVE; 36// mStatus = TENTATIVE;
37 37
38 mHasDueDate = false; 38 mHasDueDate = false;
39 setHasStartDate( false ); 39 setHasStartDate( false );
40 mCompleted = getEvenTime(QDateTime::currentDateTime()); 40 mCompleted = getEvenTime(QDateTime::currentDateTime());
41 mHasCompletedDate = false; 41 mHasCompletedDate = false;
42 mPercentComplete = 0; 42 mPercentComplete = 0;
43 mRunning = false; 43 mRunning = false;
44 mRunSaveTimer = 0; 44 mRunSaveTimer = 0;
45} 45}
46 46
47Todo::Todo(const Todo &t) : QObject(),Incidence(t) 47Todo::Todo(const Todo &t) : QObject(),Incidence(t)
48{ 48{
49 mDtDue = t.mDtDue; 49 mDtDue = t.mDtDue;
50 mHasDueDate = t.mHasDueDate; 50 mHasDueDate = t.mHasDueDate;
51 mCompleted = t.mCompleted; 51 mCompleted = t.mCompleted;
52 mHasCompletedDate = t.mHasCompletedDate; 52 mHasCompletedDate = t.mHasCompletedDate;
53 mPercentComplete = t.mPercentComplete; 53 mPercentComplete = t.mPercentComplete;
54 mRunning = false; 54 mRunning = false;
55 mRunSaveTimer = 0; 55 mRunSaveTimer = 0;
56} 56}
57 57
58Todo::~Todo() 58Todo::~Todo()
59{ 59{
60 setRunning( false ); 60 setRunning( false );
61 //qDebug("Todo::~Todo() "); 61 //qDebug("Todo::~Todo() ");
62} 62}
63 63
64void Todo::setRunningFalse( QString s ) 64void Todo::setRunningFalse( QString s )
65{ 65{
66 if ( ! mRunning ) 66 if ( ! mRunning )
67 return; 67 return;
68 mRunning = false; 68 mRunning = false;
69 mRunSaveTimer->stop(); 69 mRunSaveTimer->stop();
70 saveRunningInfoToFile( s ); 70 saveRunningInfoToFile( s );
71} 71}
72void Todo::setRunning( bool run ) 72void Todo::setRunning( bool run )
73{ 73{
74 if ( run == mRunning ) 74 if ( run == mRunning )
75 return; 75 return;
76 //qDebug("Todo::setRunning %d ", run); 76 //qDebug("Todo::setRunning %d ", run);
77 if ( !mRunSaveTimer ) { 77 if ( !mRunSaveTimer ) {
78 mRunSaveTimer = new QTimer ( this ); 78 mRunSaveTimer = new QTimer ( this );
79 connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) ); 79 connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) );
80 } 80 }
81 mRunning = run; 81 mRunning = run;
82 if ( mRunning ) { 82 if ( mRunning ) {
83 mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min 83 mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min
84 mRunStart = QDateTime::currentDateTime(); 84 mRunStart = QDateTime::currentDateTime();
85 } else { 85 } else {
86 mRunSaveTimer->stop(); 86 mRunSaveTimer->stop();
87 saveRunningInfoToFile(); 87 saveRunningInfoToFile();
88 } 88 }
89} 89}
90 90
91void Todo::saveRunningInfoToFile( QString comment ) 91void Todo::saveRunningInfoToFile( QString comment )
92{ 92{
93 //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); 93 //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1());
94 if ( mRunStart.secsTo ( QDateTime::currentDateTime() ) < 30 ) { 94 if ( mRunStart.secsTo ( QDateTime::currentDateTime() ) < 30 ) {
95 qDebug("Running time < 30 seconds. Skipped. "); 95 qDebug("Running time < 30 seconds. Skipped. ");
96 return; 96 return;
97 } 97 }
98 QString dir = KGlobalSettings::timeTrackerDir(); 98 QString dir = KGlobalSettings::timeTrackerDir();
99 //qDebug("%s ", dir.latin1()); 99 //qDebug("%s ", dir.latin1());
100 QString file = "%1%2%3-%4%5%6-"; 100 QString file = "%1%2%3-%4%5%6-";
101 file = file.arg( mRunStart.date().year(), 4).arg( mRunStart.date().month(),2 ).arg( mRunStart.date().day(), 2 ).arg( mRunStart.time().hour(),2 ).arg( mRunStart.time().minute(),2 ).arg( mRunStart.time().second(),2 ); 101 file = file.arg( mRunStart.date().year(), 4).arg( mRunStart.date().month(),2 ).arg( mRunStart.date().day(), 2 ).arg( mRunStart.time().hour(),2 ).arg( mRunStart.time().minute(),2 ).arg( mRunStart.time().second(),2 );
102 file.replace ( QRegExp (" "), "0" ); 102 file.replace ( QRegExp (" "), "0" );
103 file += uid(); 103 file += uid();
104 //qDebug("File %s ",file.latin1() ); 104 //qDebug("File %s ",file.latin1() );
105 CalendarLocal cal; 105 CalendarLocal cal;
106 cal.setLocalTime(); 106 cal.setLocalTime();
107 Todo * to = (Todo*) clone(); 107 Todo * to = (Todo*) clone();
108 to->setFloats( false ); 108 to->setFloats( false );
109 to->setDtStart( mRunStart ); 109 to->setDtStart( mRunStart );
110 to->setHasStartDate( true ); 110 to->setHasStartDate( true );
111 to->setDtDue( QDateTime::currentDateTime() ); 111 to->setDtDue( QDateTime::currentDateTime() );
112 to->setHasDueDate( true ); 112 to->setHasDueDate( true );
113 to->setUid( file ); 113 to->setUid( file );
114 if ( !comment.isEmpty() ) { 114 if ( !comment.isEmpty() ) {
115 QString des = to->description(); 115 QString des = to->description();
116 if ( des.isEmpty () ) 116 if ( des.isEmpty () )
117 to->setDescription( "TT-Note: " + comment ); 117 to->setDescription( "TT-Note: " + comment );
118 else 118 else
119 to->setDescription( "TT-Note: " + comment +"\n" + des ); 119 to->setDescription( "TT-Note: " + comment +"\n" + des );
120 } 120 }
121 cal.addIncidence( to ); 121 cal.addIncidence( to );
122 ICalFormat format; 122 ICalFormat format;
123 file = dir +"/" +file +".ics"; 123 file = dir +"/" +file +".ics";
124 format.save( &cal, file ); 124 format.save( &cal, file );
125 saveParents(); 125 saveParents();
126 126
127} 127}
128void Todo::saveParents() 128void Todo::saveParents()
129{ 129{
130 if (!relatedTo() ) 130 if (!relatedTo() )
131 return; 131 return;
132 Incidence * inc = relatedTo(); 132 Incidence * inc = relatedTo();
133 if ( inc->type() != "Todo" ) 133 if ( inc->type() != "Todo" )
134 return; 134 return;
135 Todo* to = (Todo*)inc; 135 Todo* to = (Todo*)inc;
136 bool saveTodo = false; 136 bool saveTodo = false;
137 QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics"; 137 QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics";
138 QFileInfo fi ( file ); 138 QFileInfo fi ( file );
139 if ( fi.exists() ) { 139 if ( fi.exists() ) {
140 if ( fi.lastModified () < to->lastModified ()) 140 if ( fi.lastModified () < to->lastModified ())
141 saveTodo = true; 141 saveTodo = true;
142 } else { 142 } else {
143 saveTodo = true; 143 saveTodo = true;
144 } 144 }
145 if ( saveTodo ) { 145 if ( saveTodo ) {
146 CalendarLocal cal; 146 CalendarLocal cal;
147 cal.setLocalTime(); 147 cal.setLocalTime();
148 Todo * par = (Todo *) to->clone(); 148 Todo * par = (Todo *) to->clone();
149 cal.addIncidence( par ); 149 cal.addIncidence( par );
150 ICalFormat format; 150 ICalFormat format;
151 format.save( &cal, file ); 151 format.save( &cal, file );
152 } 152 }
153 to->saveParents(); 153 to->saveParents();
154} 154}
155 155
156int Todo::runTime() 156int Todo::runTime()
157{ 157{
158 if ( !mRunning ) 158 if ( !mRunning )
159 return 0; 159 return 0;
160 return mRunStart.secsTo( QDateTime::currentDateTime() ); 160 return mRunStart.secsTo( QDateTime::currentDateTime() );
161} 161}
162bool Todo::hasRunningSub() 162bool Todo::hasRunningSub()
163{ 163{
164 if ( mRunning ) 164 if ( mRunning )
165 return true; 165 return true;
166 Incidence *aTodo; 166 Incidence *aTodo;
167 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { 167 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) {
168 if ( ((Todo*)aTodo)->hasRunningSub() ) 168 if ( ((Todo*)aTodo)->hasRunningSub() )
169 return true; 169 return true;
170 } 170 }
171 return false; 171 return false;
172} 172}
173Incidence *Todo::clone() 173Incidence *Todo::clone()
174{ 174{
175 return new Todo(*this); 175 return new Todo(*this);
176} 176}
177 177
178bool Todo::contains ( Todo* from ) 178bool Todo::contains ( Todo* from )
179{ 179{
180 180
181 if ( !from->summary().isEmpty() ) 181 if ( !from->summary().isEmpty() )
182 if ( !summary().startsWith( from->summary() )) 182 if ( !summary().startsWith( from->summary() ))
183 return false; 183 return false;
184 if ( from->hasStartDate() ) { 184 if ( from->hasStartDate() ) {
185 if ( !hasStartDate() ) 185 if ( !hasStartDate() )
186 return false; 186 return false;
187 if ( from->dtStart() != dtStart()) 187 if ( from->dtStart() != dtStart())
188 return false; 188 return false;
189 } 189 }
190 if ( from->hasDueDate() ){ 190 if ( from->hasDueDate() ){
191 if ( !hasDueDate() ) 191 if ( !hasDueDate() )
192 return false; 192 return false;
193 if ( from->dtDue() != dtDue()) 193 if ( from->dtDue() != dtDue())
194 return false; 194 return false;
195 } 195 }
196 if ( !from->location().isEmpty() ) 196 if ( !from->location().isEmpty() )
197 if ( !location().startsWith( from->location() ) ) 197 if ( !location().startsWith( from->location() ) )
198 return false; 198 return false;
199 if ( !from->description().isEmpty() ) 199 if ( !from->description().isEmpty() )
200 if ( !description().startsWith( from->description() )) 200 if ( !description().startsWith( from->description() ))
201 return false; 201 return false;
202 if ( from->alarms().count() ) { 202 if ( from->alarms().count() ) {
203 Alarm *a = from->alarms().first(); 203 Alarm *a = from->alarms().first();
204 if ( a->enabled() ){ 204 if ( a->enabled() ){
205 if ( !alarms().count() ) 205 if ( !alarms().count() )
206 return false; 206 return false;
207 Alarm *b = alarms().first(); 207 Alarm *b = alarms().first();
208 if( ! b->enabled() ) 208 if( ! b->enabled() )
209 return false; 209 return false;
210 if ( ! (a->offset() == b->offset() )) 210 if ( ! (a->offset() == b->offset() ))
211 return false; 211 return false;
212 } 212 }
213 } 213 }
214 214
215 QStringList cat = categories(); 215 QStringList cat = categories();
216 QStringList catFrom = from->categories(); 216 QStringList catFrom = from->categories();
217 QString nCat; 217 QString nCat;
218 unsigned int iii; 218 unsigned int iii;
219 for ( iii = 0; iii < catFrom.count();++iii ) { 219 for ( iii = 0; iii < catFrom.count();++iii ) {
220 nCat = catFrom[iii]; 220 nCat = catFrom[iii];
221 if ( !nCat.isEmpty() ) 221 if ( !nCat.isEmpty() )
222 if ( !cat.contains( nCat )) { 222 if ( !cat.contains( nCat )) {
223 return false; 223 return false;
224 } 224 }
225 } 225 }
226 if ( from->isCompleted() ) { 226 if ( from->isCompleted() ) {
227 if ( !isCompleted() ) 227 if ( !isCompleted() )
228 return false; 228 return false;
229 } 229 }
230 if( priority() != from->priority() ) 230 if( priority() != from->priority() )
231 return false; 231 return false;
232 232
233 233
234 return true; 234 return true;
235 235
236} 236}
237bool KCal::operator==( const Todo& t1, const Todo& t2 ) 237bool KCal::operator==( const Todo& t1, const Todo& t2 )
238{ 238{
239 239
240 bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 ); 240 bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 );
241 if ( ! ret ) 241 if ( ! ret )
242 return false; 242 return false;
243 if ( t1.hasDueDate() == t2.hasDueDate() ) { 243 if ( t1.hasDueDate() == t2.hasDueDate() ) {
244 if ( t1.hasDueDate() ) { 244 if ( t1.hasDueDate() ) {
245 if ( t1.doesFloat() == t2.doesFloat() ) { 245 if ( t1.doesFloat() == t2.doesFloat() ) {
246 if ( t1.doesFloat() ) { 246 if ( t1.doesFloat() ) {
247 if ( t1.dtDue().date() != t2.dtDue().date() ) 247 if ( t1.dtDue().date() != t2.dtDue().date() )
248 return false; 248 return false;
249 } else 249 } else
250 if ( t1.dtDue() != t2.dtDue() ) 250 if ( t1.dtDue() != t2.dtDue() )
251 return false; 251 return false;
252 } else 252 } else
253 return false;// float != 253 return false;// float !=
254 } 254 }
255 255
256 } else 256 } else
257 return false; 257 return false;
258 if ( t1.percentComplete() != t2.percentComplete() ) 258 if ( t1.percentComplete() != t2.percentComplete() )
259 return false; 259 return false;
260 if ( t1.isCompleted() ) { 260 if ( t1.isCompleted() ) {
261 if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) { 261 if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) {
262 if ( t1.hasCompletedDate() ) { 262 if ( t1.hasCompletedDate() ) {
263 if ( t1.completed() != t2.completed() ) 263 if ( t1.completed() != t2.completed() )
264 return false; 264 return false;
265 } 265 }
266 266
267 } else 267 } else
268 return false; 268 return false;
269 } 269 }
270 return true; 270 return true;
271 271
272} 272}
273 273
274void Todo::setDtDue(const QDateTime &dtDue) 274void Todo::setDtDue(const QDateTime &dtDue)
275{ 275{
276 //int diffsecs = mDtDue.secsTo(dtDue); 276 //int diffsecs = mDtDue.secsTo(dtDue);
277 277
278 /*if (mReadOnly) return; 278 /*if (mReadOnly) return;
279 const QPtrList<Alarm>& alarms = alarms(); 279 const QPtrList<Alarm>& alarms = alarms();
280 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) { 280 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) {
281 if (alarm->enabled()) { 281 if (alarm->enabled()) {
282 alarm->setTime(alarm->time().addSecs(diffsecs)); 282 alarm->setTime(alarm->time().addSecs(diffsecs));
283 } 283 }
284 }*/ 284 }*/
285 mDtDue = getEvenTime(dtDue); 285 mDtDue = getEvenTime(dtDue);
286 286
287 //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl; 287 //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl;
288 288
289 /*const QPtrList<Alarm>& alarms = alarms(); 289 /*const QPtrList<Alarm>& alarms = alarms();
290 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) 290 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next())
291 alarm->setAlarmStart(mDtDue);*/ 291 alarm->setAlarmStart(mDtDue);*/
292 updated(); 292 updated();
293} 293}
294 294
295QDateTime Todo::dtDue() const 295QDateTime Todo::dtDue() const
296{ 296{
297 return mDtDue; 297 return mDtDue;
298} 298}
299 299
300QString Todo::dtDueTimeStr() const 300QString Todo::dtDueTimeStr() const
301{ 301{
302 return KGlobal::locale()->formatTime(mDtDue.time()); 302 return KGlobal::locale()->formatTime(mDtDue.time());
303} 303}
304 304
305QString Todo::dtDueDateStr(bool shortfmt) const 305QString Todo::dtDueDateStr(bool shortfmt) const
306{ 306{
307 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); 307 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt);
308} 308}
309 309
310QString Todo::dtDueStr(bool shortfmt) const 310QString Todo::dtDueStr(bool shortfmt) const
311{ 311{
312 if ( doesFloat() ) 312 if ( doesFloat() )
313 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); 313 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt);
314 return KGlobal::locale()->formatDateTime(mDtDue, shortfmt); 314 return KGlobal::locale()->formatDateTime(mDtDue, shortfmt);
315} 315}
316// retval 0 : no found 316// retval 0 : no found
317// 1 : due for date found 317// 1 : due for date found
318// 2 : overdue for date found 318// 2 : overdue for date found
319int Todo::hasDueSubTodoForDate( const QDate & date, bool checkSubtodos ) 319int Todo::hasDueSubTodoForDate( const QDate & date, bool checkSubtodos )
320{ 320{
321 int retval = 0; 321 int retval = 0;
322 if ( isCompleted() ) 322 if ( isCompleted() )
323 return 0; 323 return 0;
324 if ( hasDueDate() ) { 324 if ( hasDueDate() ) {
325 if ( dtDue().date() < date ) 325 if ( dtDue().date() < date )
326 return 2; 326 return 2;
327 // we do not return, because we may find an overdue sub todo 327 // we do not return, because we may find an overdue sub todo
328 if ( dtDue().date() == date ) 328 if ( dtDue().date() == date )
329 retval = 1; 329 retval = 1;
330 } 330 }
331 if ( checkSubtodos ) { 331 if ( checkSubtodos ) {
332 Incidence *aTodo; 332 Incidence *aTodo;
333 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { 333 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) {
334 int ret = ((Todo*)aTodo)->hasDueSubTodoForDate( date ,checkSubtodos ); 334 int ret = ((Todo*)aTodo)->hasDueSubTodoForDate( date ,checkSubtodos );
335 if ( ret == 2 ) 335 if ( ret == 2 )
336 return 2; 336 return 2;
337 if ( ret == 1) 337 if ( ret == 1)
338 retval = 1; 338 retval = 1;
339 } 339 }
340 } 340 }
341 return retval; 341 return retval;
342} 342}
343int Todo::hasDueSubTodo( bool checkSubtodos ) //= true 343int Todo::hasDueSubTodo( bool checkSubtodos ) //= true
344{ 344{
345 return hasDueSubTodoForDate(QDate::currentDate(), checkSubtodos ); 345 return hasDueSubTodoForDate(QDate::currentDate(), checkSubtodos );
346} 346}
347bool Todo::hasDueDate() const 347bool Todo::hasDueDate() const
348{ 348{
349 return mHasDueDate; 349 return mHasDueDate;
350} 350}
351 351
352void Todo::setHasDueDate(bool f) 352void Todo::setHasDueDate(bool f)
353{ 353{
354 if (mReadOnly) return; 354 if (mReadOnly) return;
355 mHasDueDate = f; 355 mHasDueDate = f;
356 updated(); 356 updated();
357} 357}
358 358
359 359
360#if 0 360#if 0
361void Todo::setStatus(const QString &statStr) 361void Todo::setStatus(const QString &statStr)
362{ 362{
363 if (mReadOnly) return; 363 if (mReadOnly) return;
364 QString ss(statStr.upper()); 364 QString ss(statStr.upper());
365 365
366 if (ss == "X-ACTION") 366 if (ss == "X-ACTION")
367 mStatus = NEEDS_ACTION; 367 mStatus = NEEDS_ACTION;
368 else if (ss == "NEEDS ACTION") 368 else if (ss == "NEEDS ACTION")
369 mStatus = NEEDS_ACTION; 369 mStatus = NEEDS_ACTION;
370 else if (ss == "ACCEPTED") 370 else if (ss == "ACCEPTED")
371 mStatus = ACCEPTED; 371 mStatus = ACCEPTED;
372 else if (ss == "SENT") 372 else if (ss == "SENT")
373 mStatus = SENT; 373 mStatus = SENT;
374 else if (ss == "TENTATIVE") 374 else if (ss == "TENTATIVE")
375 mStatus = TENTATIVE; 375 mStatus = TENTATIVE;
376 else if (ss == "CONFIRMED") 376 else if (ss == "CONFIRMED")
377 mStatus = CONFIRMED; 377 mStatus = CONFIRMED;
378 else if (ss == "DECLINED") 378 else if (ss == "DECLINED")
379 mStatus = DECLINED; 379 mStatus = DECLINED;
380 else if (ss == "COMPLETED") 380 else if (ss == "COMPLETED")
381 mStatus = COMPLETED; 381 mStatus = COMPLETED;
382 else if (ss == "DELEGATED") 382 else if (ss == "DELEGATED")
383 mStatus = DELEGATED; 383 mStatus = DELEGATED;
384 384
385 updated(); 385 updated();
386} 386}
387 387
388void Todo::setStatus(int status) 388void Todo::setStatus(int status)
389{ 389{
390 if (mReadOnly) return; 390 if (mReadOnly) return;
391 mStatus = status; 391 mStatus = status;
392 updated(); 392 updated();
393} 393}
394 394
395int Todo::status() const 395int Todo::status() const
396{ 396{
397 return mStatus; 397 return mStatus;
398} 398}
399 399
400QString Todo::statusStr() const 400QString Todo::statusStr() const
401{ 401{
402 switch(mStatus) { 402 switch(mStatus) {
403 case NEEDS_ACTION: 403 case NEEDS_ACTION:
404 return QString("NEEDS ACTION"); 404 return QString("NEEDS ACTION");
405 break; 405 break;
406 case ACCEPTED: 406 case ACCEPTED:
407 return QString("ACCEPTED"); 407 return QString("ACCEPTED");
408 break; 408 break;
409 case SENT: 409 case SENT:
410 return QString("SENT"); 410 return QString("SENT");
411 break; 411 break;
412 case TENTATIVE: 412 case TENTATIVE:
413 return QString("TENTATIVE"); 413 return QString("TENTATIVE");
414 break; 414 break;
415 case CONFIRMED: 415 case CONFIRMED:
416 return QString("CONFIRMED"); 416 return QString("CONFIRMED");
417 break; 417 break;
418 case DECLINED: 418 case DECLINED:
419 return QString("DECLINED"); 419 return QString("DECLINED");
420 break; 420 break;
421 case COMPLETED: 421 case COMPLETED:
422 return QString("COMPLETED"); 422 return QString("COMPLETED");
423 break; 423 break;
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 ) const 518QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const
519{ 519{
520 if ( isCompleted() || ! hasDueDate() || cancelled() ) { 520 if ( isCompleted() || ! hasDueDate() || cancelled() ) {
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 > QDateTime::currentDateTime() ) { 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 ( !hasRecurrenceID() ) { 567 if ( !hasRecurrenceID() ) {
568 qDebug("ERROR 1 in Todo::checkSetCompletedFalse"); 568 qDebug("ERROR 1 in Todo::checkSetCompletedFalse");
569 } 569 }
570 // qDebug("Todo::checkSetCompletedFalse()"); 570 // qDebug("Todo::checkSetCompletedFalse()");
571 //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); 571 //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() );
572 if ( mPercentComplete == 100 && mDtStart == mRecurrenceID && QDateTime::currentDateTime() > mDtStart) { 572 if ( mPercentComplete == 100 && mDtStart == mRecurrenceID && QDateTime::currentDateTime() > mDtStart) {
573 qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); 573 qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() );
574 setCompleted( false ); 574 setCompleted( false );
575 qDebug("Todo::checkSetCompletedFalse "); 575 qDebug("Todo::checkSetCompletedFalse ");
576 } 576 }
577} 577}
diff --git a/libkcal/todo.h b/libkcal/todo.h
index a5354ce..ab8fdf1 100644
--- a/libkcal/todo.h
+++ b/libkcal/todo.h
@@ -1,150 +1,150 @@
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#ifndef TODO_H 20#ifndef TODO_H
21#define TODO_H 21#define TODO_H
22// 22//
23// Todo component, representing a VTODO object 23// Todo component, representing a VTODO object
24// 24//
25 25
26#include "incidence.h" 26#include "incidence.h"
27 27
28#include <qtimer.h> 28#include <qtimer.h>
29 29
30namespace KCal { 30namespace KCal {
31 31
32/** 32/**
33 This class provides a Todo in the sense of RFC2445. 33 This class provides a Todo in the sense of RFC2445.
34*/ 34*/
35 class Todo : public QObject,public Incidence 35 class Todo : public QObject,public Incidence
36{ 36{
37 Q_OBJECT 37 Q_OBJECT
38 public: 38 public:
39 Todo(); 39 Todo();
40 Todo(const Todo &); 40 Todo(const Todo &);
41 ~Todo(); 41 ~Todo();
42 typedef ListBase<Todo> List; 42 typedef ListBase<Todo> List;
43 QCString type() const { return "Todo"; } 43 QCString type() const { return "Todo"; }
44 44
45 /** Return an exact copy of this todo. */ 45 /** Return an exact copy of this todo. */
46 Incidence *clone(); 46 Incidence *clone();
47 QDateTime getNextAlarmDateTime( bool * ok, int * offset ) const; 47 QDateTime getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const;
48 48
49 /** for setting the todo's due date/time with a QDateTime. */ 49 /** for setting the todo's due date/time with a QDateTime. */
50 void setDtDue(const QDateTime &dtDue); 50 void setDtDue(const QDateTime &dtDue);
51 /** returns an event's Due date/time as a QDateTime. */ 51 /** returns an event's Due date/time as a QDateTime. */
52 QDateTime dtDue() const; 52 QDateTime dtDue() const;
53 /** returns an event's due time as a string formatted according to the 53 /** returns an event's due time as a string formatted according to the
54 users locale settings */ 54 users locale settings */
55 QString dtDueTimeStr() const; 55 QString dtDueTimeStr() const;
56 /** returns an event's due date as a string formatted according to the 56 /** returns an event's due date as a string formatted according to the
57 users locale settings */ 57 users locale settings */
58 QString dtDueDateStr(bool shortfmt=true) const; 58 QString dtDueDateStr(bool shortfmt=true) const;
59 /** returns an event's due date and time as a string formatted according 59 /** returns an event's due date and time as a string formatted according
60 to the users locale settings */ 60 to the users locale settings */
61 QString dtDueStr(bool shortfmt=true) const; 61 QString dtDueStr(bool shortfmt=true) const;
62 62
63 /** returns TRUE or FALSE depending on whether the todo has a due date */ 63 /** returns TRUE or FALSE depending on whether the todo has a due date */
64 bool hasDueDate() const; 64 bool hasDueDate() const;
65 /** sets the event's hasDueDate value. */ 65 /** sets the event's hasDueDate value. */
66 void setHasDueDate(bool f); 66 void setHasDueDate(bool f);
67 67
68 /* 68 /*
69 Looks for a subtodo (including itself ) which is not complete and is 69 Looks for a subtodo (including itself ) which is not complete and is
70 - overdue, or 70 - overdue, or
71 - due today. 71 - due today.
72 It returns 0 for nothing found, 72 It returns 0 for nothing found,
73 1 for found a todo which is due today and no overdue found 73 1 for found a todo which is due today and no overdue found
74 2 for found a overdue todo 74 2 for found a overdue todo
75 */ 75 */
76 int hasDueSubTodo( bool checkSubtodos = true ); 76 int hasDueSubTodo( bool checkSubtodos = true );
77 /* same as above, but a specific date can be specified*/ 77 /* same as above, but a specific date can be specified*/
78 int hasDueSubTodoForDate( const QDate & date, bool checkSubtodos ); 78 int hasDueSubTodoForDate( const QDate & date, bool checkSubtodos );
79 79
80 80
81 /** sets the event's status to the string specified. The string 81 /** sets the event's status to the string specified. The string
82 * must be a recognized value for the status field, i.e. a string 82 * must be a recognized value for the status field, i.e. a string
83 * equivalent of the possible status enumerations previously described. */ 83 * equivalent of the possible status enumerations previously described. */
84// void setStatus(const QString &statStr); 84// void setStatus(const QString &statStr);
85 /** sets the event's status to the value specified. See the enumeration 85 /** sets the event's status to the value specified. See the enumeration
86 * above for possible values. */ 86 * above for possible values. */
87// void setStatus(int); 87// void setStatus(int);
88 /** return the event's status. */ 88 /** return the event's status. */
89// int status() const; 89// int status() const;
90 /** return the event's status in string format. */ 90 /** return the event's status in string format. */
91// QString statusStr() const; 91// QString statusStr() const;
92 92
93 /** return, if this todo is completed */ 93 /** return, if this todo is completed */
94 bool isCompleted() const; 94 bool isCompleted() const;
95 /** set completed state of this todo */ 95 /** set completed state of this todo */
96 void setCompleted(bool); 96 void setCompleted(bool);
97 97
98 /** 98 /**
99 Return how many percent of the task are completed. Returns a value 99 Return how many percent of the task are completed. Returns a value
100 between 0 and 100. 100 between 0 and 100.
101 */ 101 */
102 int percentComplete() const; 102 int percentComplete() const;
103 /** 103 /**
104 Set how many percent of the task are completed. Valid values are in the 104 Set how many percent of the task are completed. Valid values are in the
105 range from 0 to 100. 105 range from 0 to 100.
106 */ 106 */
107 void setPercentComplete(int); 107 void setPercentComplete(int);
108 108
109 /** return date and time when todo was completed */ 109 /** return date and time when todo was completed */
110 QDateTime completed() const; 110 QDateTime completed() const;
111 QString completedStr(bool shortF = true) const; 111 QString completedStr(bool shortF = true) const;
112 /** set date and time of completion */ 112 /** set date and time of completion */
113 void setCompleted(const QDateTime &completed); 113 void setCompleted(const QDateTime &completed);
114 114
115 /** Return true, if todo has a date associated with completion */ 115 /** Return true, if todo has a date associated with completion */
116 bool hasCompletedDate() const; 116 bool hasCompletedDate() const;
117 bool contains ( Todo*); 117 bool contains ( Todo*);
118 void checkSetCompletedFalse(); 118 void checkSetCompletedFalse();
119 bool setRecurDates(); 119 bool setRecurDates();
120 bool isRunning() {return mRunning;} 120 bool isRunning() {return mRunning;}
121 bool hasRunningSub(); 121 bool hasRunningSub();
122 void setRunning( bool ); 122 void setRunning( bool );
123 void setRunningFalse( QString ); 123 void setRunningFalse( QString );
124 int runTime(); 124 int runTime();
125 QDateTime runStart () const { return mRunStart;} 125 QDateTime runStart () const { return mRunStart;}
126 public slots: 126 public slots:
127 void saveRunningInfoToFile( QString st = QString::null ); 127 void saveRunningInfoToFile( QString st = QString::null );
128 void saveParents(); 128 void saveParents();
129 private: 129 private:
130 bool mRunning; 130 bool mRunning;
131 QTimer * mRunSaveTimer; 131 QTimer * mRunSaveTimer;
132 QDateTime mRunStart; 132 QDateTime mRunStart;
133 bool accept(Visitor &v) { return v.visit(this); } 133 bool accept(Visitor &v) { return v.visit(this); }
134 134
135 QDateTime mDtDue; // due date of todo 135 QDateTime mDtDue; // due date of todo
136 136
137 bool mHasDueDate; // if todo has associated due date 137 bool mHasDueDate; // if todo has associated due date
138 138
139// int mStatus; // confirmed/delegated/tentative/etc 139// int mStatus; // confirmed/delegated/tentative/etc
140 140
141 QDateTime mCompleted; 141 QDateTime mCompleted;
142 bool mHasCompletedDate; 142 bool mHasCompletedDate;
143 143
144 int mPercentComplete; 144 int mPercentComplete;
145}; 145};
146 146
147 bool operator==( const Todo&, const Todo& ); 147 bool operator==( const Todo&, const Todo& );
148} 148}
149 149
150#endif 150#endif