summaryrefslogtreecommitdiffabout
path: root/libkcal
authorzautrix <zautrix>2005-07-27 23:40:19 (UTC)
committer zautrix <zautrix>2005-07-27 23:40:19 (UTC)
commit27ffa2e08ebb38e71f613af3a214750442418e2c (patch) (unidiff)
treede2bb4c541ab8795ee3739526e82ca8f4e952c09 /libkcal
parent0e38cffd7ba745f237c659e1c48080fcb25b126c (diff)
downloadkdepimpi-27ffa2e08ebb38e71f613af3a214750442418e2c.zip
kdepimpi-27ffa2e08ebb38e71f613af3a214750442418e2c.tar.gz
kdepimpi-27ffa2e08ebb38e71f613af3a214750442418e2c.tar.bz2
fixcxcx
Diffstat (limited to 'libkcal') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/calendarlocal.cpp1
-rw-r--r--libkcal/icalformat.cpp17
-rw-r--r--libkcal/icalformat.h3
-rw-r--r--libkcal/todo.cpp7
4 files changed, 19 insertions, 9 deletions
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp
index e37a7ad..eef8327 100644
--- a/libkcal/calendarlocal.cpp
+++ b/libkcal/calendarlocal.cpp
@@ -1,835 +1,836 @@
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 registerObserver( 0 );
68 if ( mDeleteIncidencesOnClose ) 69 if ( mDeleteIncidencesOnClose )
69 close(); 70 close();
70} 71}
71bool CalendarLocal::mergeCalendarFile( QString name ) 72bool CalendarLocal::mergeCalendarFile( QString name )
72{ 73{
73 CalendarLocal calendar( timeZoneId() ); 74 CalendarLocal calendar( timeZoneId() );
74 calendar.setDefaultCalendar( 1 ); 75 calendar.setDefaultCalendar( 1 );
75 if ( calendar.load( name ) ) { 76 if ( calendar.load( name ) ) {
76 mergeCalendar( &calendar ); 77 mergeCalendar( &calendar );
77 return true; 78 return true;
78 } 79 }
79 return false; 80 return false;
80} 81}
81 82
82Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates) 83Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates)
83{ 84{
84 Todo *todo;; 85 Todo *todo;;
85 Incidence *retVal = 0; 86 Incidence *retVal = 0;
86 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 87 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
87 if ( todo->uid() == uid ) { 88 if ( todo->uid() == uid ) {
88 if ( doNotCheckDuplicates ) return todo; 89 if ( doNotCheckDuplicates ) return todo;
89 if ( retVal ) { 90 if ( retVal ) {
90 if ( retVal->calID() > todo->calID() ) { 91 if ( retVal->calID() > todo->calID() ) {
91 retVal = todo; 92 retVal = todo;
92 } 93 }
93 } else { 94 } else {
94 retVal = todo; 95 retVal = todo;
95 } 96 }
96 } 97 }
97 } 98 }
98 if ( retVal ) return retVal; 99 if ( retVal ) return retVal;
99 Event *event; 100 Event *event;
100 for ( event = mEventList.first(); event; event = mEventList.next() ) { 101 for ( event = mEventList.first(); event; event = mEventList.next() ) {
101 if ( event->uid() == uid ) { 102 if ( event->uid() == uid ) {
102 if ( doNotCheckDuplicates ) return event; 103 if ( doNotCheckDuplicates ) return event;
103 if ( retVal ) { 104 if ( retVal ) {
104 if ( retVal->calID() > event->calID() ) { 105 if ( retVal->calID() > event->calID() ) {
105 retVal = event; 106 retVal = event;
106 } 107 }
107 } else { 108 } else {
108 retVal = event; 109 retVal = event;
109 } 110 }
110 } 111 }
111 } 112 }
112 if ( retVal ) return retVal; 113 if ( retVal ) return retVal;
113 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 114 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
114 if ( it->uid() == uid ) { 115 if ( it->uid() == uid ) {
115 if ( doNotCheckDuplicates ) return it; 116 if ( doNotCheckDuplicates ) return it;
116 if ( retVal ) { 117 if ( retVal ) {
117 if ( retVal->calID() > it->calID() ) { 118 if ( retVal->calID() > it->calID() ) {
118 retVal = it; 119 retVal = it;
119 } 120 }
120 } else { 121 } else {
121 retVal = it; 122 retVal = it;
122 } 123 }
123 } 124 }
124 return retVal; 125 return retVal;
125} 126}
126 127
127bool CalendarLocal::mergeCalendar( Calendar* remote ) 128bool CalendarLocal::mergeCalendar( Calendar* remote )
128{ 129{
129 // 1 look for raw inc in local 130 // 1 look for raw inc in local
130 // if inc not in remote, delete in local 131 // if inc not in remote, delete in local
131 // 2 look for raw inc in remote 132 // 2 look for raw inc in remote
132 // if inc in local, replace it 133 // if inc in local, replace it
133 // if not in local, add it to default calendar 134 // if not in local, add it to default calendar
134 QPtrList<Incidence> localInc = rawIncidences(); 135 QPtrList<Incidence> localInc = rawIncidences();
135 Incidence* inL = localInc.first(); 136 Incidence* inL = localInc.first();
136 while ( inL ) { 137 while ( inL ) {
137 if ( ! inL->isReadOnly () ) 138 if ( ! inL->isReadOnly () )
138 if ( !remote->incidenceForUid( inL->uid(), true )) 139 if ( !remote->incidenceForUid( inL->uid(), true ))
139 deleteIncidence( inL ); 140 deleteIncidence( inL );
140 inL = localInc.next(); 141 inL = localInc.next();
141 } 142 }
142 QPtrList<Incidence> er = remote->rawIncidences(); 143 QPtrList<Incidence> er = remote->rawIncidences();
143 Incidence* inR = er.first(); 144 Incidence* inR = er.first();
144 while ( inR ) { 145 while ( inR ) {
145 inL = incidenceForUid( inR->uid(),false ); 146 inL = incidenceForUid( inR->uid(),false );
146 if ( inL ) { 147 if ( inL ) {
147 if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) { 148 if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) {
148 int calID = inL->calID(); 149 int calID = inL->calID();
149 deleteIncidence( inL ); 150 deleteIncidence( inL );
150 inL = inR->clone(); 151 inL = inR->clone();
151 inL->setCalID( calID ); 152 inL->setCalID( calID );
152 addIncidence( inL ); 153 addIncidence( inL );
153 } 154 }
154 } else { 155 } else {
155 inL = inR->clone(); 156 inL = inR->clone();
156 inL->setCalID( 0 );// add to default cal 157 inL->setCalID( 0 );// add to default cal
157 addIncidence( inL ); 158 addIncidence( inL );
158 } 159 }
159 inR = er.next(); 160 inR = er.next();
160 } 161 }
161 return true; 162 return true;
162} 163}
163 164
164 165
165bool CalendarLocal::addCalendarFile( QString name, int id ) 166bool CalendarLocal::addCalendarFile( QString name, int id )
166{ 167{
167 CalendarLocal calendar( timeZoneId() ); 168 CalendarLocal calendar( timeZoneId() );
168 calendar.setDefaultCalendar( id ); 169 calendar.setDefaultCalendar( id );
169 if ( calendar.load( name ) ) { 170 if ( calendar.load( name ) ) {
170 addCalendar( &calendar ); 171 addCalendar( &calendar );
171 return true; 172 return true;
172 } 173 }
173 return false; 174 return false;
174} 175}
175void CalendarLocal::setSyncEventsReadOnly() 176void CalendarLocal::setSyncEventsReadOnly()
176{ 177{
177 Event * ev; 178 Event * ev;
178 ev = mEventList.first(); 179 ev = mEventList.first();
179 while ( ev ) { 180 while ( ev ) {
180 if ( ev->uid().left(15) == QString("last-syncEvent-") ) 181 if ( ev->uid().left(15) == QString("last-syncEvent-") )
181 ev->setReadOnly( true ); 182 ev->setReadOnly( true );
182 ev = mEventList.next(); 183 ev = mEventList.next();
183 } 184 }
184} 185}
185void CalendarLocal::addCalendar( Calendar* cal ) 186void CalendarLocal::addCalendar( Calendar* cal )
186{ 187{
187 cal->setDontDeleteIncidencesOnClose(); 188 cal->setDontDeleteIncidencesOnClose();
188 { 189 {
189 QPtrList<Event> EventList = cal->rawEvents(); 190 QPtrList<Event> EventList = cal->rawEvents();
190 Event * ev = EventList.first(); 191 Event * ev = EventList.first();
191 while ( ev ) { 192 while ( ev ) {
192 ev->unRegisterObserver( cal ); 193 ev->unRegisterObserver( cal );
193 ev->registerObserver( this ); 194 ev->registerObserver( this );
194 mEventList.append( ev ); 195 mEventList.append( ev );
195 ev = EventList.next(); 196 ev = EventList.next();
196 } 197 }
197 } 198 }
198 { 199 {
199 200
200 QPtrList<Todo> TodoList = cal->rawTodos(); 201 QPtrList<Todo> TodoList = cal->rawTodos();
201 Todo * ev = TodoList.first(); 202 Todo * ev = TodoList.first();
202 while ( ev ) { 203 while ( ev ) {
203 QString rel = ev->relatedToUid(); 204 QString rel = ev->relatedToUid();
204 if ( !rel.isEmpty() ){ 205 if ( !rel.isEmpty() ){
205 ev->setRelatedTo ( 0 ); 206 ev->setRelatedTo ( 0 );
206 ev->setRelatedToUid( rel ); 207 ev->setRelatedToUid( rel );
207 } 208 }
208 ev = TodoList.next(); 209 ev = TodoList.next();
209 } 210 }
210 //TodoList = cal->rawTodos(); 211 //TodoList = cal->rawTodos();
211 ev = TodoList.first(); 212 ev = TodoList.first();
212 while ( ev ) { 213 while ( ev ) {
213 ev->unRegisterObserver( cal ); 214 ev->unRegisterObserver( cal );
214 ev->registerObserver( this ); 215 ev->registerObserver( this );
215 mTodoList.append( ev ); 216 mTodoList.append( ev );
216 setupRelations( ev ); 217 setupRelations( ev );
217 ev = TodoList.next(); 218 ev = TodoList.next();
218 } 219 }
219 } 220 }
220 { 221 {
221 QPtrList<Journal> JournalList = cal->journals(); 222 QPtrList<Journal> JournalList = cal->journals();
222 Journal * ev = JournalList.first(); 223 Journal * ev = JournalList.first();
223 while ( ev ) { 224 while ( ev ) {
224 ev->unRegisterObserver( cal ); 225 ev->unRegisterObserver( cal );
225 ev->registerObserver( this ); 226 ev->registerObserver( this );
226 mJournalList.append( ev ); 227 mJournalList.append( ev );
227 ev = JournalList.next(); 228 ev = JournalList.next();
228 } 229 }
229 } 230 }
230 setModified( true ); 231 setModified( true );
231} 232}
232bool CalendarLocal::load( const QString &fileName ) 233bool CalendarLocal::load( const QString &fileName )
233{ 234{
234 FileStorage storage( this, fileName ); 235 FileStorage storage( this, fileName );
235 return storage.load(); 236 return storage.load();
236} 237}
237 238
238bool CalendarLocal::save( const QString &fileName, CalFormat *format ) 239bool CalendarLocal::save( const QString &fileName, CalFormat *format )
239{ 240{
240 FileStorage storage( this, fileName, format ); 241 FileStorage storage( this, fileName, format );
241 return storage.save(); 242 return storage.save();
242} 243}
243 244
244void CalendarLocal::stopAllTodos() 245void CalendarLocal::stopAllTodos()
245{ 246{
246 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 247 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
247 it->setRunning( false ); 248 it->setRunning( false );
248 249
249} 250}
250void CalendarLocal::close() 251void CalendarLocal::close()
251{ 252{
252 253
253 Todo * i; 254 Todo * i;
254 for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); 255 for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false);
255 256
256 mEventList.setAutoDelete( true ); 257 mEventList.setAutoDelete( true );
257 mTodoList.setAutoDelete( true ); 258 mTodoList.setAutoDelete( true );
258 mJournalList.setAutoDelete( false ); 259 mJournalList.setAutoDelete( false );
259 260
260 mEventList.clear(); 261 mEventList.clear();
261 mTodoList.clear(); 262 mTodoList.clear();
262 mJournalList.clear(); 263 mJournalList.clear();
263 264
264 mEventList.setAutoDelete( false ); 265 mEventList.setAutoDelete( false );
265 mTodoList.setAutoDelete( false ); 266 mTodoList.setAutoDelete( false );
266 mJournalList.setAutoDelete( false ); 267 mJournalList.setAutoDelete( false );
267 268
268 setModified( false ); 269 setModified( false );
269} 270}
270 271
271bool CalendarLocal::addAnniversaryNoDup( Event *event ) 272bool CalendarLocal::addAnniversaryNoDup( Event *event )
272{ 273{
273 QString cat; 274 QString cat;
274 bool isBirthday = true; 275 bool isBirthday = true;
275 if( event->categoriesStr() == i18n( "Anniversary" ) ) { 276 if( event->categoriesStr() == i18n( "Anniversary" ) ) {
276 isBirthday = false; 277 isBirthday = false;
277 cat = i18n( "Anniversary" ); 278 cat = i18n( "Anniversary" );
278 } else if( event->categoriesStr() == i18n( "Birthday" ) ) { 279 } else if( event->categoriesStr() == i18n( "Birthday" ) ) {
279 isBirthday = true; 280 isBirthday = true;
280 cat = i18n( "Birthday" ); 281 cat = i18n( "Birthday" );
281 } else { 282 } else {
282 qDebug("addAnniversaryNoDup called without fitting category! "); 283 qDebug("addAnniversaryNoDup called without fitting category! ");
283 return false; 284 return false;
284 } 285 }
285 Event * eve; 286 Event * eve;
286 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 287 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
287 if ( !(eve->categories().contains( cat ) )) 288 if ( !(eve->categories().contains( cat ) ))
288 continue; 289 continue;
289 // now we have an event with fitting category 290 // now we have an event with fitting category
290 if ( eve->dtStart().date() != event->dtStart().date() ) 291 if ( eve->dtStart().date() != event->dtStart().date() )
291 continue; 292 continue;
292 // now we have an event with fitting category+date 293 // now we have an event with fitting category+date
293 if ( eve->summary() != event->summary() ) 294 if ( eve->summary() != event->summary() )
294 continue; 295 continue;
295 // now we have an event with fitting category+date+summary 296 // now we have an event with fitting category+date+summary
296 return false; 297 return false;
297 } 298 }
298 return addEvent( event ); 299 return addEvent( event );
299 300
300} 301}
301bool CalendarLocal::addEventNoDup( Event *event ) 302bool CalendarLocal::addEventNoDup( Event *event )
302{ 303{
303 Event * eve; 304 Event * eve;
304 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 305 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
305 if ( *eve == *event ) { 306 if ( *eve == *event ) {
306 //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); 307 //qDebug("CalendarLocal::Duplicate event found! Not inserted! ");
307 return false; 308 return false;
308 } 309 }
309 } 310 }
310 return addEvent( event ); 311 return addEvent( event );
311} 312}
312 313
313bool CalendarLocal::addEvent( Event *event ) 314bool CalendarLocal::addEvent( Event *event )
314{ 315{
315 insertEvent( event ); 316 insertEvent( event );
316 317
317 event->registerObserver( this ); 318 event->registerObserver( this );
318 319
319 setModified( true ); 320 setModified( true );
320 if ( event->calID() == 0 ) 321 if ( event->calID() == 0 )
321 event->setCalID( mDefaultCalendar ); 322 event->setCalID( mDefaultCalendar );
322 event->setCalEnabled( true ); 323 event->setCalEnabled( true );
323 324
324 return true; 325 return true;
325} 326}
326 327
327void CalendarLocal::deleteEvent( Event *event ) 328void CalendarLocal::deleteEvent( Event *event )
328{ 329{
329 if ( mUndoIncidence ) delete mUndoIncidence; 330 if ( mUndoIncidence ) delete mUndoIncidence;
330 mUndoIncidence = event->clone(); 331 mUndoIncidence = event->clone();
331 if ( mEventList.removeRef( event ) ) { 332 if ( mEventList.removeRef( event ) ) {
332 setModified( true ); 333 setModified( true );
333 } 334 }
334} 335}
335 336
336 337
337Event *CalendarLocal::event( const QString &uid ) 338Event *CalendarLocal::event( const QString &uid )
338{ 339{
339 Event *event; 340 Event *event;
340 Event *retVal = 0; 341 Event *retVal = 0;
341 for ( event = mEventList.first(); event; event = mEventList.next() ) { 342 for ( event = mEventList.first(); event; event = mEventList.next() ) {
342 if ( event->calEnabled() && event->uid() == uid ) { 343 if ( event->calEnabled() && event->uid() == uid ) {
343 if ( retVal ) { 344 if ( retVal ) {
344 if ( retVal->calID() > event->calID() ) { 345 if ( retVal->calID() > event->calID() ) {
345 retVal = event; 346 retVal = event;
346 } 347 }
347 } else { 348 } else {
348 retVal = event; 349 retVal = event;
349 } 350 }
350 } 351 }
351 } 352 }
352 return retVal; 353 return retVal;
353} 354}
354bool CalendarLocal::addTodoNoDup( Todo *todo ) 355bool CalendarLocal::addTodoNoDup( Todo *todo )
355{ 356{
356 Todo * eve; 357 Todo * eve;
357 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { 358 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) {
358 if ( *eve == *todo ) { 359 if ( *eve == *todo ) {
359 //qDebug("duplicate todo found! not inserted! "); 360 //qDebug("duplicate todo found! not inserted! ");
360 return false; 361 return false;
361 } 362 }
362 } 363 }
363 return addTodo( todo ); 364 return addTodo( todo );
364} 365}
365bool CalendarLocal::addTodo( Todo *todo ) 366bool CalendarLocal::addTodo( Todo *todo )
366{ 367{
367 mTodoList.append( todo ); 368 mTodoList.append( todo );
368 369
369 todo->registerObserver( this ); 370 todo->registerObserver( this );
370 371
371 // Set up subtask relations 372 // Set up subtask relations
372 setupRelations( todo ); 373 setupRelations( todo );
373 374
374 setModified( true ); 375 setModified( true );
375 if ( todo->calID() == 0 ) 376 if ( todo->calID() == 0 )
376 todo->setCalID( mDefaultCalendar ); 377 todo->setCalID( mDefaultCalendar );
377 todo->setCalEnabled( true ); 378 todo->setCalEnabled( true );
378 return true; 379 return true;
379} 380}
380 381
381void CalendarLocal::deleteTodo( Todo *todo ) 382void CalendarLocal::deleteTodo( Todo *todo )
382{ 383{
383 // Handle orphaned children 384 // Handle orphaned children
384 if ( mUndoIncidence ) delete mUndoIncidence; 385 if ( mUndoIncidence ) delete mUndoIncidence;
385 removeRelations( todo ); 386 removeRelations( todo );
386 mUndoIncidence = todo->clone(); 387 mUndoIncidence = todo->clone();
387 388
388 if ( mTodoList.removeRef( todo ) ) { 389 if ( mTodoList.removeRef( todo ) ) {
389 setModified( true ); 390 setModified( true );
390 } 391 }
391} 392}
392 393
393QPtrList<Todo> CalendarLocal::rawTodos() 394QPtrList<Todo> CalendarLocal::rawTodos()
394{ 395{
395 QPtrList<Todo> el; 396 QPtrList<Todo> el;
396 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 397 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
397 if ( it->calEnabled() ) el.append( it ); 398 if ( it->calEnabled() ) el.append( it );
398 return el; 399 return el;
399} 400}
400Todo *CalendarLocal::todo( QString syncProf, QString id ) 401Todo *CalendarLocal::todo( QString syncProf, QString id )
401{ 402{
402 Todo *todo; 403 Todo *todo;
403 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 404 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
404 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; 405 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo;
405 } 406 }
406 407
407 return 0; 408 return 0;
408} 409}
409void CalendarLocal::removeSyncInfo( QString syncProfile) 410void CalendarLocal::removeSyncInfo( QString syncProfile)
410{ 411{
411 QPtrList<Incidence> all = rawIncidences() ; 412 QPtrList<Incidence> all = rawIncidences() ;
412 Incidence *inc; 413 Incidence *inc;
413 for ( inc = all.first(); inc; inc = all.next() ) { 414 for ( inc = all.first(); inc; inc = all.next() ) {
414 inc->removeID( syncProfile ); 415 inc->removeID( syncProfile );
415 } 416 }
416 if ( syncProfile.isEmpty() ) { 417 if ( syncProfile.isEmpty() ) {
417 QPtrList<Event> el; 418 QPtrList<Event> el;
418 Event *todo; 419 Event *todo;
419 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 420 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
420 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) 421 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
421 el.append( todo ); 422 el.append( todo );
422 } 423 }
423 for ( todo = el.first(); todo; todo = el.next() ) { 424 for ( todo = el.first(); todo; todo = el.next() ) {
424 deleteIncidence ( todo ); 425 deleteIncidence ( todo );
425 } 426 }
426 } else { 427 } else {
427 Event *lse = event( "last-syncEvent-"+ syncProfile); 428 Event *lse = event( "last-syncEvent-"+ syncProfile);
428 if ( lse ) 429 if ( lse )
429 deleteIncidence ( lse ); 430 deleteIncidence ( lse );
430 } 431 }
431} 432}
432QPtrList<Event> CalendarLocal::getExternLastSyncEvents() 433QPtrList<Event> CalendarLocal::getExternLastSyncEvents()
433{ 434{
434 QPtrList<Event> el; 435 QPtrList<Event> el;
435 Event *todo; 436 Event *todo;
436 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 437 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
437 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) 438 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
438 if ( todo->summary().left(3) == "E: " ) 439 if ( todo->summary().left(3) == "E: " )
439 el.append( todo ); 440 el.append( todo );
440 } 441 }
441 442
442 return el; 443 return el;
443 444
444} 445}
445Event *CalendarLocal::event( QString syncProf, QString id ) 446Event *CalendarLocal::event( QString syncProf, QString id )
446{ 447{
447 Event *todo; 448 Event *todo;
448 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 449 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
449 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; 450 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo;
450 } 451 }
451 452
452 return 0; 453 return 0;
453} 454}
454Todo *CalendarLocal::todo( const QString &uid ) 455Todo *CalendarLocal::todo( const QString &uid )
455{ 456{
456 Todo *todo;; 457 Todo *todo;;
457 Todo *retVal = 0; 458 Todo *retVal = 0;
458 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 459 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
459 if ( todo->calEnabled() && todo->uid() == uid ) { 460 if ( todo->calEnabled() && todo->uid() == uid ) {
460 if ( retVal ) { 461 if ( retVal ) {
461 if ( retVal->calID() > todo->calID() ) { 462 if ( retVal->calID() > todo->calID() ) {
462 retVal = todo; 463 retVal = todo;
463 } 464 }
464 } else { 465 } else {
465 retVal = todo; 466 retVal = todo;
466 } 467 }
467 } 468 }
468 } 469 }
469 return retVal; 470 return retVal;
470} 471}
471QString CalendarLocal::nextSummary() const 472QString CalendarLocal::nextSummary() const
472{ 473{
473 return mNextSummary; 474 return mNextSummary;
474} 475}
475QDateTime CalendarLocal::nextAlarmEventDateTime() const 476QDateTime CalendarLocal::nextAlarmEventDateTime() const
476{ 477{
477 return mNextAlarmEventDateTime; 478 return mNextAlarmEventDateTime;
478} 479}
479void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) 480void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted)
480{ 481{
481 //mNextAlarmIncidence 482 //mNextAlarmIncidence
482 //mNextAlarmDateTime 483 //mNextAlarmDateTime
483 //return mNextSummary; 484 //return mNextSummary;
484 //return mNextAlarmEventDateTime; 485 //return mNextAlarmEventDateTime;
485 bool newNextAlarm = false; 486 bool newNextAlarm = false;
486 bool computeNextAlarm = false; 487 bool computeNextAlarm = false;
487 bool ok; 488 bool ok;
488 int offset; 489 int offset;
489 QDateTime nextA; 490 QDateTime nextA;
490 // QString nextSum; 491 // QString nextSum;
491 //QDateTime nextEvent; 492 //QDateTime nextEvent;
492 if ( mNextAlarmIncidence == 0 || incidence == 0 ) { 493 if ( mNextAlarmIncidence == 0 || incidence == 0 ) {
493 computeNextAlarm = true; 494 computeNextAlarm = true;
494 } else { 495 } else {
495 if ( ! deleted ) { 496 if ( ! deleted ) {
496 nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; 497 nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
497 if ( ok ) { 498 if ( ok ) {
498 if ( nextA < mNextAlarmDateTime ) { 499 if ( nextA < mNextAlarmDateTime ) {
499 deRegisterAlarm(); 500 deRegisterAlarm();
500 mNextAlarmDateTime = nextA; 501 mNextAlarmDateTime = nextA;
501 mNextSummary = incidence->summary(); 502 mNextSummary = incidence->summary();
502 mNextAlarmEventDateTime = nextA.addSecs(offset ) ; 503 mNextAlarmEventDateTime = nextA.addSecs(offset ) ;
503 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); 504 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime);
504 newNextAlarm = true; 505 newNextAlarm = true;
505 mNextAlarmIncidence = incidence; 506 mNextAlarmIncidence = incidence;
506 } else { 507 } else {
507 if ( incidence == mNextAlarmIncidence ) { 508 if ( incidence == mNextAlarmIncidence ) {
508 computeNextAlarm = true; 509 computeNextAlarm = true;
509 } 510 }
510 } 511 }
511 } else { 512 } else {
512 if ( mNextAlarmIncidence == incidence ) { 513 if ( mNextAlarmIncidence == incidence ) {
513 computeNextAlarm = true; 514 computeNextAlarm = true;
514 } 515 }
515 } 516 }
516 } else { // deleted 517 } else { // deleted
517 if ( incidence == mNextAlarmIncidence ) { 518 if ( incidence == mNextAlarmIncidence ) {
518 computeNextAlarm = true; 519 computeNextAlarm = true;
519 } 520 }
520 } 521 }
521 } 522 }
522 if ( computeNextAlarm ) { 523 if ( computeNextAlarm ) {
523 deRegisterAlarm(); 524 deRegisterAlarm();
524 nextA = nextAlarm( 1000 ); 525 nextA = nextAlarm( 1000 );
525 if (! mNextAlarmIncidence ) { 526 if (! mNextAlarmIncidence ) {
526 return; 527 return;
527 } 528 }
528 newNextAlarm = true; 529 newNextAlarm = true;
529 } 530 }
530 if ( newNextAlarm ) 531 if ( newNextAlarm )
531 registerAlarm(); 532 registerAlarm();
532} 533}
533QString CalendarLocal:: getAlarmNotification() 534QString CalendarLocal:: getAlarmNotification()
534{ 535{
535 QString ret; 536 QString ret;
536 // this should not happen 537 // this should not happen
537 if (! mNextAlarmIncidence ) 538 if (! mNextAlarmIncidence )
538 return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; 539 return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString;
539 Alarm* alarm = mNextAlarmIncidence->alarms().first(); 540 Alarm* alarm = mNextAlarmIncidence->alarms().first();
540 if ( alarm->type() == Alarm::Procedure ) { 541 if ( alarm->type() == Alarm::Procedure ) {
541 ret = "proc_alarm" + alarm->programFile()+"+++"; 542 ret = "proc_alarm" + alarm->programFile()+"+++";
542 } else { 543 } else {
543 ret = "audio_alarm" +alarm->audioFile() +"+++"; 544 ret = "audio_alarm" +alarm->audioFile() +"+++";
544 } 545 }
545 ret += "cal_alarm"+ mNextSummary.left( 25 ); 546 ret += "cal_alarm"+ mNextSummary.left( 25 );
546 if ( mNextSummary.length() > 25 ) 547 if ( mNextSummary.length() > 25 )
547 ret += "\n" + mNextSummary.mid(25, 25 ); 548 ret += "\n" + mNextSummary.mid(25, 25 );
548 ret+= "\n"+mNextAlarmEventDateTimeString; 549 ret+= "\n"+mNextAlarmEventDateTimeString;
549 return ret; 550 return ret;
550} 551}
551void CalendarLocal::registerAlarm() 552void CalendarLocal::registerAlarm()
552{ 553{
553 mLastAlarmNotificationString = getAlarmNotification(); 554 mLastAlarmNotificationString = getAlarmNotification();
554 // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); 555 // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() );
555 emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); 556 emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString );
556// #ifndef DESKTOP_VERSION 557// #ifndef DESKTOP_VERSION
557// AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); 558// AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() );
558// #endif 559// #endif
559} 560}
560void CalendarLocal::deRegisterAlarm() 561void CalendarLocal::deRegisterAlarm()
561{ 562{
562 if ( mLastAlarmNotificationString.isNull() ) 563 if ( mLastAlarmNotificationString.isNull() )
563 return; 564 return;
564 //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); 565 //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() );
565 566
566 emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); 567 emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString );
567 mNextAlarmEventDateTime = QDateTime(); 568 mNextAlarmEventDateTime = QDateTime();
568// #ifndef DESKTOP_VERSION 569// #ifndef DESKTOP_VERSION
569// AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); 570// AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() );
570// #endif 571// #endif
571} 572}
572 573
573QPtrList<Todo> CalendarLocal::todos( const QDate &date ) 574QPtrList<Todo> CalendarLocal::todos( const QDate &date )
574{ 575{
575 QPtrList<Todo> todos; 576 QPtrList<Todo> todos;
576 577
577 Todo *todo; 578 Todo *todo;
578 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 579 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
579 if ( !todo->calEnabled() ) continue; 580 if ( !todo->calEnabled() ) continue;
580 if ( todo->hasDueDate() && todo->dtDue().date() == date ) { 581 if ( todo->hasDueDate() && todo->dtDue().date() == date ) {
581 todos.append( todo ); 582 todos.append( todo );
582 } 583 }
583 } 584 }
584 585
585 filter()->apply( &todos ); 586 filter()->apply( &todos );
586 return todos; 587 return todos;
587} 588}
588void CalendarLocal::reInitAlarmSettings() 589void CalendarLocal::reInitAlarmSettings()
589{ 590{
590 if ( !mNextAlarmIncidence ) { 591 if ( !mNextAlarmIncidence ) {
591 nextAlarm( 1000 ); 592 nextAlarm( 1000 );
592 } 593 }
593 deRegisterAlarm(); 594 deRegisterAlarm();
594 mNextAlarmIncidence = 0; 595 mNextAlarmIncidence = 0;
595 checkAlarmForIncidence( 0, false ); 596 checkAlarmForIncidence( 0, false );
596 597
597} 598}
598 599
599 600
600 601
601QDateTime CalendarLocal::nextAlarm( int daysTo ) 602QDateTime CalendarLocal::nextAlarm( int daysTo )
602{ 603{
603 QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); 604 QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo );
604 QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); 605 QDateTime start = QDateTime::currentDateTime().addSecs( 30 );
605 QDateTime next; 606 QDateTime next;
606 Event *e; 607 Event *e;
607 bool ok; 608 bool ok;
608 bool found = false; 609 bool found = false;
609 int offset; 610 int offset;
610 mNextAlarmIncidence = 0; 611 mNextAlarmIncidence = 0;
611 for( e = mEventList.first(); e; e = mEventList.next() ) { 612 for( e = mEventList.first(); e; e = mEventList.next() ) {
612 if ( !e->calEnabled() ) continue; 613 if ( !e->calEnabled() ) continue;
613 next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; 614 next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
614 if ( ok ) { 615 if ( ok ) {
615 if ( next < nextA ) { 616 if ( next < nextA ) {
616 nextA = next; 617 nextA = next;
617 found = true; 618 found = true;
618 mNextSummary = e->summary(); 619 mNextSummary = e->summary();
619 mNextAlarmEventDateTime = next.addSecs(offset ) ; 620 mNextAlarmEventDateTime = next.addSecs(offset ) ;
620 mNextAlarmIncidence = (Incidence *) e; 621 mNextAlarmIncidence = (Incidence *) e;
621 } 622 }
622 } 623 }
623 } 624 }
624 Todo *t; 625 Todo *t;
625 for( t = mTodoList.first(); t; t = mTodoList.next() ) { 626 for( t = mTodoList.first(); t; t = mTodoList.next() ) {
626 if ( !t->calEnabled() ) continue; 627 if ( !t->calEnabled() ) continue;
627 next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; 628 next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
628 if ( ok ) { 629 if ( ok ) {
629 if ( next < nextA ) { 630 if ( next < nextA ) {
630 nextA = next; 631 nextA = next;
631 found = true; 632 found = true;
632 mNextSummary = t->summary(); 633 mNextSummary = t->summary();
633 mNextAlarmEventDateTime = next.addSecs(offset ); 634 mNextAlarmEventDateTime = next.addSecs(offset );
634 mNextAlarmIncidence = (Incidence *) t; 635 mNextAlarmIncidence = (Incidence *) t;
635 } 636 }
636 } 637 }
637 } 638 }
638 if ( mNextAlarmIncidence ) { 639 if ( mNextAlarmIncidence ) {
639 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); 640 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime);
640 mNextAlarmDateTime = nextA; 641 mNextAlarmDateTime = nextA;
641 } 642 }
642 return nextA; 643 return nextA;
643} 644}
644Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) 645Alarm::List CalendarLocal::alarmsTo( const QDateTime &to )
645{ 646{
646 return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); 647 return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to );
647} 648}
648 649
649Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) 650Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to )
650{ 651{
651 652
652 Alarm::List alarms; 653 Alarm::List alarms;
653 654
654 Event *e; 655 Event *e;
655 656
656 for( e = mEventList.first(); e; e = mEventList.next() ) { 657 for( e = mEventList.first(); e; e = mEventList.next() ) {
657 if ( !e->calEnabled() ) continue; 658 if ( !e->calEnabled() ) continue;
658 if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); 659 if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to );
659 else appendAlarms( alarms, e, from, to ); 660 else appendAlarms( alarms, e, from, to );
660 } 661 }
661 662
662 Todo *t; 663 Todo *t;
663 for( t = mTodoList.first(); t; t = mTodoList.next() ) { 664 for( t = mTodoList.first(); t; t = mTodoList.next() ) {
664 if ( !t->calEnabled() ) continue; 665 if ( !t->calEnabled() ) continue;
665 appendAlarms( alarms, t, from, to ); 666 appendAlarms( alarms, t, from, to );
666 } 667 }
667 668
668 return alarms; 669 return alarms;
669} 670}
670 671
671void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, 672void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence,
672 const QDateTime &from, const QDateTime &to ) 673 const QDateTime &from, const QDateTime &to )
673{ 674{
674 QPtrList<Alarm> alarmList = incidence->alarms(); 675 QPtrList<Alarm> alarmList = incidence->alarms();
675 Alarm *alarm; 676 Alarm *alarm;
676 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { 677 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) {
677// kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() 678// kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text()
678// << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; 679// << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl;
679 if ( alarm->enabled() ) { 680 if ( alarm->enabled() ) {
680 if ( alarm->time() >= from && alarm->time() <= to ) { 681 if ( alarm->time() >= from && alarm->time() <= to ) {
681 alarms.append( alarm ); 682 alarms.append( alarm );
682 } 683 }
683 } 684 }
684 } 685 }
685} 686}
686 687
687void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, 688void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms,
688 Incidence *incidence, 689 Incidence *incidence,
689 const QDateTime &from, 690 const QDateTime &from,
690 const QDateTime &to ) 691 const QDateTime &to )
691{ 692{
692 693
693 QPtrList<Alarm> alarmList = incidence->alarms(); 694 QPtrList<Alarm> alarmList = incidence->alarms();
694 Alarm *alarm; 695 Alarm *alarm;
695 QDateTime qdt; 696 QDateTime qdt;
696 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { 697 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) {
697 if (incidence->recursOn(from.date())) { 698 if (incidence->recursOn(from.date())) {
698 qdt.setTime(alarm->time().time()); 699 qdt.setTime(alarm->time().time());
699 qdt.setDate(from.date()); 700 qdt.setDate(from.date());
700 } 701 }
701 else qdt = alarm->time(); 702 else qdt = alarm->time();
702 // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); 703 // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1());
703 if ( alarm->enabled() ) { 704 if ( alarm->enabled() ) {
704 if ( qdt >= from && qdt <= to ) { 705 if ( qdt >= from && qdt <= to ) {
705 alarms.append( alarm ); 706 alarms.append( alarm );
706 } 707 }
707 } 708 }
708 } 709 }
709} 710}
710 711
711 712
712/****************************** PROTECTED METHODS ****************************/ 713/****************************** PROTECTED METHODS ****************************/
713 714
714// after changes are made to an event, this should be called. 715// after changes are made to an event, this should be called.
715void CalendarLocal::update( IncidenceBase *incidence ) 716void CalendarLocal::update( IncidenceBase *incidence )
716{ 717{
717 incidence->setSyncStatus( Event::SYNCMOD ); 718 incidence->setSyncStatus( Event::SYNCMOD );
718 incidence->setLastModified( QDateTime::currentDateTime() ); 719 incidence->setLastModified( QDateTime::currentDateTime() );
719 // we should probably update the revision number here, 720 // we should probably update the revision number here,
720 // or internally in the Event itself when certain things change. 721 // or internally in the Event itself when certain things change.
721 // need to verify with ical documentation. 722 // need to verify with ical documentation.
722 723
723 setModified( true ); 724 setModified( true );
724} 725}
725 726
726void CalendarLocal::insertEvent( Event *event ) 727void CalendarLocal::insertEvent( Event *event )
727{ 728{
728 if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); 729 if ( mEventList.findRef( event ) < 0 ) mEventList.append( event );
729} 730}
730 731
731 732
732QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) 733QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted )
733{ 734{
734 QPtrList<Event> eventList; 735 QPtrList<Event> eventList;
735 736
736 Event *event; 737 Event *event;
737 for( event = mEventList.first(); event; event = mEventList.next() ) { 738 for( event = mEventList.first(); event; event = mEventList.next() ) {
738 if ( !event->calEnabled() ) continue; 739 if ( !event->calEnabled() ) continue;
739 if ( event->doesRecur() ) { 740 if ( event->doesRecur() ) {
740 if ( event->isMultiDay() ) { 741 if ( event->isMultiDay() ) {
741 int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); 742 int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() );
742 int i; 743 int i;
743 for ( i = 0; i <= extraDays; i++ ) { 744 for ( i = 0; i <= extraDays; i++ ) {
744 if ( event->recursOn( qd.addDays( -i ) ) ) { 745 if ( event->recursOn( qd.addDays( -i ) ) ) {
745 eventList.append( event ); 746 eventList.append( event );
746 break; 747 break;
747 } 748 }
748 } 749 }
749 } else { 750 } else {
750 if ( event->recursOn( qd ) ) 751 if ( event->recursOn( qd ) )
751 eventList.append( event ); 752 eventList.append( event );
752 } 753 }
753 } else { 754 } else {
754 if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { 755 if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) {
755 eventList.append( event ); 756 eventList.append( event );
756 } 757 }
757 } 758 }
758 } 759 }
759 760
760 if ( !sorted ) { 761 if ( !sorted ) {
761 return eventList; 762 return eventList;
762 } 763 }
763 764
764 // kdDebug(5800) << "Sorting events for date\n" << endl; 765 // kdDebug(5800) << "Sorting events for date\n" << endl;
765 // now, we have to sort it based on dtStart.time() 766 // now, we have to sort it based on dtStart.time()
766 QPtrList<Event> eventListSorted; 767 QPtrList<Event> eventListSorted;
767 Event *sortEvent; 768 Event *sortEvent;
768 for ( event = eventList.first(); event; event = eventList.next() ) { 769 for ( event = eventList.first(); event; event = eventList.next() ) {
769 sortEvent = eventListSorted.first(); 770 sortEvent = eventListSorted.first();
770 int i = 0; 771 int i = 0;
771 while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) 772 while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() )
772 { 773 {
773 i++; 774 i++;
774 sortEvent = eventListSorted.next(); 775 sortEvent = eventListSorted.next();
775 } 776 }
776 eventListSorted.insert( i, event ); 777 eventListSorted.insert( i, event );
777 } 778 }
778 return eventListSorted; 779 return eventListSorted;
779} 780}
780 781
781 782
782QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, 783QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end,
783 bool inclusive ) 784 bool inclusive )
784{ 785{
785 Event *event = 0; 786 Event *event = 0;
786 787
787 QPtrList<Event> eventList; 788 QPtrList<Event> eventList;
788 789
789 // Get non-recurring events 790 // Get non-recurring events
790 for( event = mEventList.first(); event; event = mEventList.next() ) { 791 for( event = mEventList.first(); event; event = mEventList.next() ) {
791 if ( !event->calEnabled() ) continue; 792 if ( !event->calEnabled() ) continue;
792 if ( event->doesRecur() ) { 793 if ( event->doesRecur() ) {
793 QDate rStart = event->dtStart().date(); 794 QDate rStart = event->dtStart().date();
794 bool found = false; 795 bool found = false;
795 if ( inclusive ) { 796 if ( inclusive ) {
796 if ( rStart >= start && rStart <= end ) { 797 if ( rStart >= start && rStart <= end ) {
797 // Start date of event is in range. Now check for end date. 798 // Start date of event is in range. Now check for end date.
798 // if duration is negative, event recurs forever, so do not include it. 799 // if duration is negative, event recurs forever, so do not include it.
799 if ( event->recurrence()->duration() == 0 ) { // End date set 800 if ( event->recurrence()->duration() == 0 ) { // End date set
800 QDate rEnd = event->recurrence()->endDate(); 801 QDate rEnd = event->recurrence()->endDate();
801 if ( rEnd >= start && rEnd <= end ) { // End date within range 802 if ( rEnd >= start && rEnd <= end ) { // End date within range
802 found = true; 803 found = true;
803 } 804 }
804 } else if ( event->recurrence()->duration() > 0 ) { // Duration set 805 } else if ( event->recurrence()->duration() > 0 ) { // Duration set
805 // TODO: Calculate end date from duration. Should be done in Event 806 // TODO: Calculate end date from duration. Should be done in Event
806 // For now exclude all events with a duration. 807 // For now exclude all events with a duration.
807 } 808 }
808 } 809 }
809 } else { 810 } else {
810 bool founOne; 811 bool founOne;
811 QDate next = event->getNextOccurence( start, &founOne ).date(); 812 QDate next = event->getNextOccurence( start, &founOne ).date();
812 if ( founOne ) { 813 if ( founOne ) {
813 if ( next <= end ) { 814 if ( next <= end ) {
814 found = true; 815 found = true;
815 } 816 }
816 } 817 }
817 818
818 /* 819 /*
819 // crap !!! 820 // crap !!!
820 if ( rStart <= end ) { // Start date not after range 821 if ( rStart <= end ) { // Start date not after range
821 if ( rStart >= start ) { // Start date within range 822 if ( rStart >= start ) { // Start date within range
822 found = true; 823 found = true;
823 } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever 824 } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever
824 found = true; 825 found = true;
825 } else if ( event->recurrence()->duration() == 0 ) { // End date set 826 } else if ( event->recurrence()->duration() == 0 ) { // End date set
826 QDate rEnd = event->recurrence()->endDate(); 827 QDate rEnd = event->recurrence()->endDate();
827 if ( rEnd >= start && rEnd <= end ) { // End date within range 828 if ( rEnd >= start && rEnd <= end ) { // End date within range
828 found = true; 829 found = true;
829 } 830 }
830 } else { // Duration set 831 } else { // Duration set
831 // TODO: Calculate end date from duration. Should be done in Event 832 // TODO: Calculate end date from duration. Should be done in Event
832 // For now include all events with a duration. 833 // For now include all events with a duration.
833 found = true; 834 found = true;
834 } 835 }
835 } 836 }
diff --git a/libkcal/icalformat.cpp b/libkcal/icalformat.cpp
index 5877406..6f3a799 100644
--- a/libkcal/icalformat.cpp
+++ b/libkcal/icalformat.cpp
@@ -1,462 +1,469 @@
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 <qdatetime.h> 21#include <qdatetime.h>
22#include <qstring.h> 22#include <qstring.h>
23#include <qptrlist.h> 23#include <qptrlist.h>
24#include <qregexp.h> 24#include <qregexp.h>
25#include <qclipboard.h> 25#include <qclipboard.h>
26#include <qfile.h> 26#include <qfile.h>
27#include <qtextstream.h> 27#include <qtextstream.h>
28#include <qtextcodec.h> 28#include <qtextcodec.h>
29#include <stdlib.h> 29#include <stdlib.h>
30 30
31#include <kdebug.h> 31#include <kdebug.h>
32#include <kglobal.h> 32#include <kglobal.h>
33#include <klocale.h> 33#include <klocale.h>
34 34
35extern "C" { 35extern "C" {
36 #include <ical.h> 36 #include <ical.h>
37 #include <icalss.h> 37 #include <icalss.h>
38 #include <icalparser.h> 38 #include <icalparser.h>
39 #include <icalrestriction.h> 39 #include <icalrestriction.h>
40} 40}
41 41
42#include "calendar.h" 42#include "calendar.h"
43#include "calendarlocal.h" 43#include "calendarlocal.h"
44#include "journal.h" 44#include "journal.h"
45 45
46#include "icalformat.h" 46#include "icalformat.h"
47#include "icalformatimpl.h" 47#include "icalformatimpl.h"
48 48
49#define _ICAL_VERSION "2.0" 49#define _ICAL_VERSION "2.0"
50 50
51using namespace KCal; 51using namespace KCal;
52 52
53ICalFormat::ICalFormat( ) 53ICalFormat::ICalFormat( bool pe )
54{ 54{
55 mProcessEvents = pe;
55 mImpl = new ICalFormatImpl( this ); 56 mImpl = new ICalFormatImpl( this );
56 tzOffsetMin = 0; 57 tzOffsetMin = 0;
57 //qDebug("new ICalFormat() "); 58 //qDebug("new ICalFormat() ");
58} 59}
59 60
60ICalFormat::~ICalFormat() 61ICalFormat::~ICalFormat()
61{ 62{
62 delete mImpl; 63 delete mImpl;
63 //qDebug("delete ICalFormat "); 64 //qDebug("delete ICalFormat ");
64} 65}
65 66
66bool ICalFormat::load( Calendar *calendar, const QString &fileName) 67bool ICalFormat::load( Calendar *calendar, const QString &fileName)
67{ 68{
68 69
69 clearException(); 70 clearException();
70 71
71 QFile file( fileName ); 72 QFile file( fileName );
72 if (!file.open( IO_ReadOnly ) ) { 73 if (!file.open( IO_ReadOnly ) ) {
73 setException(new ErrorFormat(ErrorFormat::LoadError)); 74 setException(new ErrorFormat(ErrorFormat::LoadError));
74 return false; 75 return false;
75 } 76 }
76 QTextStream ts( &file ); 77 QTextStream ts( &file );
77 QString text; 78 QString text;
78 79
79 ts.setEncoding( QTextStream::Latin1 ); 80 ts.setEncoding( QTextStream::Latin1 );
80 text = ts.read(); 81 text = ts.read();
81 file.close(); 82 file.close();
82 83
83 return fromString( calendar, text ); 84 return fromString( calendar, text );
84} 85}
85 86
86//#include <qdatetime.h> 87//#include <qdatetime.h>
87bool ICalFormat::save( Calendar *calendar, const QString &fileName ) 88bool ICalFormat::save( Calendar *calendar, const QString &fileName )
88{ 89{
89 //kdDebug(5800) << "ICalFormat::save(): " << fileName << endl; 90 //kdDebug(5800) << "ICalFormat::save(): " << fileName << endl;
90 //qDebug("ICalFormat::save "); 91 //qDebug("ICalFormat::save ");
91 clearException(); 92 clearException();
92 QString text = toString( calendar ); 93 QString text = toString( calendar );
93 //return false; 94 //return false;
94 // qDebug("to string takes ms: %d ",is.elapsed() ); 95 // qDebug("to string takes ms: %d ",is.elapsed() );
95 if ( text.isNull() ) return false; 96 if ( text.isNull() ) return false;
96 97
97 // TODO: write backup file 98 // TODO: write backup file
98 //is.restart(); 99 //is.restart();
99 QFile file( fileName ); 100 QFile file( fileName );
100 if (!file.open( IO_WriteOnly ) ) { 101 if (!file.open( IO_WriteOnly ) ) {
101 setException(new ErrorFormat(ErrorFormat::SaveError, 102 setException(new ErrorFormat(ErrorFormat::SaveError,
102 i18n("Could not open file '%1'").arg(fileName))); 103 i18n("Could not open file '%1'").arg(fileName)));
103 return false; 104 return false;
104 } 105 }
105 QTextStream ts( &file ); 106 QTextStream ts( &file );
106 107
107 ts.setEncoding( QTextStream::Latin1 ); 108 ts.setEncoding( QTextStream::Latin1 );
108 ts << text; 109 ts << text;
109 file.close(); 110 file.close();
110 //qDebug("saving file takes ms: %d ", is.elapsed() ); 111 //qDebug("saving file takes ms: %d ", is.elapsed() );
111 return true; 112 return true;
112} 113}
113 114
114bool ICalFormat::fromString( Calendar *cal, const QString &text ) 115bool ICalFormat::fromString( Calendar *cal, const QString &text )
115{ 116{
116 setTimeZone( cal->timeZoneId(), !cal->isLocalTime() ); 117 setTimeZone( cal->timeZoneId(), !cal->isLocalTime() );
117 // qDebug("ICalFormat::fromString tz: %s ", cal->timeZoneId().latin1()); 118 // qDebug("ICalFormat::fromString tz: %s ", cal->timeZoneId().latin1());
118 // Get first VCALENDAR component. 119 // Get first VCALENDAR component.
119 // TODO: Handle more than one VCALENDAR or non-VCALENDAR top components 120 // TODO: Handle more than one VCALENDAR or non-VCALENDAR top components
120 icalcomponent *calendar; 121 icalcomponent *calendar;
121 122
122 //calendar = icalcomponent_new_from_string( text.local8Bit().data()); 123 //calendar = icalcomponent_new_from_string( text.local8Bit().data());
123 // good calendar = icalcomponent_new_from_string( text.utf8().data()); 124 // good calendar = icalcomponent_new_from_string( text.utf8().data());
124 calendar = icalcomponent_new_from_string( (char*)text.latin1()); 125 calendar = icalcomponent_new_from_string( (char*)text.latin1());
125 if (!calendar) { 126 if (!calendar) {
126 setException(new ErrorFormat(ErrorFormat::ParseErrorIcal)); 127 setException(new ErrorFormat(ErrorFormat::ParseErrorIcal));
127 return false; 128 return false;
128 } 129 }
129 130
130 bool success = true; 131 bool success = true;
131 132
132 if (icalcomponent_isa(calendar) != ICAL_VCALENDAR_COMPONENT) { 133 if (icalcomponent_isa(calendar) != ICAL_VCALENDAR_COMPONENT) {
133 setException(new ErrorFormat(ErrorFormat::NoCalendar)); 134 setException(new ErrorFormat(ErrorFormat::NoCalendar));
134 success = false; 135 success = false;
135 } else { 136 } else {
136 // put all objects into their proper places 137 // put all objects into their proper places
137 if ( !mImpl->populate( cal, calendar ) ) { 138 if ( !mImpl->populate( cal, calendar ) ) {
138 if ( !exception() ) { 139 if ( !exception() ) {
139 setException(new ErrorFormat(ErrorFormat::ParseErrorKcal)); 140 setException(new ErrorFormat(ErrorFormat::ParseErrorKcal));
140 } 141 }
141 success = false; 142 success = false;
142 } else 143 } else
143 mLoadedProductId = mImpl->loadedProductId(); 144 mLoadedProductId = mImpl->loadedProductId();
144 } 145 }
145 146
146 icalcomponent_free( calendar ); 147 icalcomponent_free( calendar );
147 icalmemory_free_ring(); 148 icalmemory_free_ring();
148 149
149 return success; 150 return success;
150} 151}
151 152
152Incidence *ICalFormat::fromString( const QString &text ) 153Incidence *ICalFormat::fromString( const QString &text )
153{ 154{
154 CalendarLocal cal( mTimeZoneId ); 155 CalendarLocal cal( mTimeZoneId );
155 fromString(&cal, text); 156 fromString(&cal, text);
156 157
157 Incidence *ical = 0; 158 Incidence *ical = 0;
158 QPtrList<Event> elist = cal.events(); 159 QPtrList<Event> elist = cal.events();
159 if ( elist.count() > 0 ) { 160 if ( elist.count() > 0 ) {
160 ical = elist.first(); 161 ical = elist.first();
161 } else { 162 } else {
162 QPtrList<Todo> tlist = cal.todos(); 163 QPtrList<Todo> tlist = cal.todos();
163 if ( tlist.count() > 0 ) { 164 if ( tlist.count() > 0 ) {
164 ical = tlist.first(); 165 ical = tlist.first();
165 } else { 166 } else {
166 QPtrList<Journal> jlist = cal.journals(); 167 QPtrList<Journal> jlist = cal.journals();
167 if ( jlist.count() > 0 ) { 168 if ( jlist.count() > 0 ) {
168 ical = jlist.first(); 169 ical = jlist.first();
169 } 170 }
170 } 171 }
171 } 172 }
172 return ical; 173 return ical;
173} 174}
174#include <qapp.h> 175#include <qapp.h>
175 176
176QString ICalFormat::toString( Calendar *cal ) 177QString ICalFormat::toString( Calendar *cal )
177{ 178{
178 179
179 setTimeZone( cal->timeZoneId(), !cal->isLocalTime() ); 180 setTimeZone( cal->timeZoneId(), !cal->isLocalTime() );
180 181
181 icalcomponent *calendar = mImpl->createCalendarComponent(cal); 182 icalcomponent *calendar = mImpl->createCalendarComponent(cal);
182 183
183 icalcomponent *component; 184 icalcomponent *component;
184 185
185 // todos 186 // todos
186 QPtrList<Todo> todoList = cal->rawTodos(); 187 QPtrList<Todo> todoList = cal->rawTodos();
187 QPtrListIterator<Todo> qlt(todoList); 188 QPtrListIterator<Todo> qlt(todoList);
188 for (; qlt.current(); ++qlt) { 189 for (; qlt.current(); ++qlt) {
189 component = mImpl->writeTodo(qlt.current()); 190 component = mImpl->writeTodo(qlt.current());
190 icalcomponent_add_component(calendar,component); 191 icalcomponent_add_component(calendar,component);
191 //qDebug(" todos "); 192 //qDebug(" todos ");
192 qApp->processEvents(); 193 if ( mProcessEvents ) {
194 //qDebug("mProcessEvents ");
195 qApp->processEvents();
196 }
193 } 197 }
194 // events 198 // events
195 QPtrList<Event> events = cal->rawEvents(); 199 QPtrList<Event> events = cal->rawEvents();
196 Event *ev; 200 Event *ev;
197 for(ev=events.first();ev;ev=events.next()) { 201 for(ev=events.first();ev;ev=events.next()) {
198 component = mImpl->writeEvent(ev); 202 component = mImpl->writeEvent(ev);
199 icalcomponent_add_component(calendar,component); 203 icalcomponent_add_component(calendar,component);
200 //qDebug("events "); 204 //qDebug("events ");
201 qApp->processEvents(); 205 if ( mProcessEvents )
206 qApp->processEvents();
202 } 207 }
203 208
204 // journals 209 // journals
205 QPtrList<Journal> journals = cal->journals(); 210 QPtrList<Journal> journals = cal->journals();
206 Journal *j; 211 Journal *j;
207 for(j=journals.first();j;j=journals.next()) { 212 for(j=journals.first();j;j=journals.next()) {
208 component = mImpl->writeJournal(j); 213 component = mImpl->writeJournal(j);
209 icalcomponent_add_component(calendar,component); 214 icalcomponent_add_component(calendar,component);
210 //qDebug("journals "); 215 //qDebug("journals ");
211 qApp->processEvents(); 216 if ( mProcessEvents )
217 qApp->processEvents();
212 } 218 }
213 const char *text; 219 const char *text;
214 QString ret =""; 220 QString ret ="";
215 text = icalcomponent_as_ical_string( calendar ); 221 text = icalcomponent_as_ical_string( calendar );
216 qApp->processEvents(); 222 if ( mProcessEvents )
223 qApp->processEvents();
217 224
218 // text = "BEGIN:VCALENDAR\nPRODID\n :-//K Desktop Environment//NONSGML libkcal 3.1//EN\nVERSION\n :2.0\nBEGIN:VEVENT\nDTSTAMP\n :20031231T213514Z\nORGANIZER\n :MAILTO:lutz@putz.de\nCREATED\n :20031231T213513Z\nUID\n :libkcal-1295166342.120\nSEQUENCE\n :0\nLAST-MODIFIED\n :20031231T213513Z\nSUMMARY\n :test1\nCLASS\n :PUBLIC\nPRIORITY\n :3\nDTSTART\n :20040101T090000Z\nDTEND\n :20040101T110000Z\nTRANSP\n :OPAQUE\nEND:VEVENT\nEND:VCALENDAR\n"; 225 // text = "BEGIN:VCALENDAR\nPRODID\n :-//K Desktop Environment//NONSGML libkcal 3.1//EN\nVERSION\n :2.0\nBEGIN:VEVENT\nDTSTAMP\n :20031231T213514Z\nORGANIZER\n :MAILTO:lutz@putz.de\nCREATED\n :20031231T213513Z\nUID\n :libkcal-1295166342.120\nSEQUENCE\n :0\nLAST-MODIFIED\n :20031231T213513Z\nSUMMARY\n :test1\nCLASS\n :PUBLIC\nPRIORITY\n :3\nDTSTART\n :20040101T090000Z\nDTEND\n :20040101T110000Z\nTRANSP\n :OPAQUE\nEND:VEVENT\nEND:VCALENDAR\n";
219 226
220 227
221 if ( text ) { 228 if ( text ) {
222 ret = QString ( text ); 229 ret = QString ( text );
223 } 230 }
224 icalcomponent_free( calendar ); 231 icalcomponent_free( calendar );
225 232
226 if (!text) { 233 if (!text) {
227 setException(new ErrorFormat(ErrorFormat::SaveError, 234 setException(new ErrorFormat(ErrorFormat::SaveError,
228 i18n("libical error"))); 235 i18n("libical error")));
229 icalmemory_free_ring(); 236 icalmemory_free_ring();
230 return QString::null; 237 return QString::null;
231 } 238 }
232 icalmemory_free_ring(); 239 icalmemory_free_ring();
233 return ret; 240 return ret;
234} 241}
235 242
236QString ICalFormat::toICalString( Incidence *incidence ) 243QString ICalFormat::toICalString( Incidence *incidence )
237{ 244{
238 CalendarLocal cal( mTimeZoneId ); 245 CalendarLocal cal( mTimeZoneId );
239 cal.addIncidence( incidence->clone() ); 246 cal.addIncidence( incidence->clone() );
240 return toString( &cal ); 247 return toString( &cal );
241} 248}
242 249
243QString ICalFormat::toString( Incidence *incidence ) 250QString ICalFormat::toString( Incidence *incidence )
244{ 251{
245 icalcomponent *component; 252 icalcomponent *component;
246 253
247 component = mImpl->writeIncidence( incidence ); 254 component = mImpl->writeIncidence( incidence );
248 255
249 const char *text = icalcomponent_as_ical_string( component ); 256 const char *text = icalcomponent_as_ical_string( component );
250 257
251 icalcomponent_free( component ); 258 icalcomponent_free( component );
252 259
253 return QString::fromLocal8Bit( text ); 260 return QString::fromLocal8Bit( text );
254} 261}
255 262
256QString ICalFormat::toString( Recurrence *recurrence ) 263QString ICalFormat::toString( Recurrence *recurrence )
257{ 264{
258 icalproperty *property; 265 icalproperty *property;
259 property = mImpl->writeRecurrenceRule( recurrence ); 266 property = mImpl->writeRecurrenceRule( recurrence );
260 const char *text = icalproperty_as_ical_string( property ); 267 const char *text = icalproperty_as_ical_string( property );
261 icalproperty_free( property ); 268 icalproperty_free( property );
262 return QString::fromLocal8Bit( text ); 269 return QString::fromLocal8Bit( text );
263} 270}
264/* 271/*
265bool ICalFormat::fromString( Recurrence * recurrence, const QString& rrule ) 272bool ICalFormat::fromString( Recurrence * recurrence, const QString& rrule )
266{ 273{
267 bool success = true; 274 bool success = true;
268 icalerror_clear_errno(); 275 icalerror_clear_errno();
269 struct icalrecurrencetype recur = icalrecurrencetype_from_string( rrule ); 276 struct icalrecurrencetype recur = icalrecurrencetype_from_string( rrule );
270 if ( icalerrno != ICAL_NO_ERROR ) { 277 if ( icalerrno != ICAL_NO_ERROR ) {
271 kdDebug() << "Recurrence parsing error: " << icalerror_strerror( icalerrno ) << endl; 278 kdDebug() << "Recurrence parsing error: " << icalerror_strerror( icalerrno ) << endl;
272 success = false; 279 success = false;
273 } 280 }
274 281
275 if ( success ) { 282 if ( success ) {
276 mImpl->readRecurrence( recur, recurrence ); 283 mImpl->readRecurrence( recur, recurrence );
277 } 284 }
278 285
279 return success; 286 return success;
280} 287}
281*/ 288*/
282 289
283QString ICalFormat::createScheduleMessage(IncidenceBase *incidence, 290QString ICalFormat::createScheduleMessage(IncidenceBase *incidence,
284 Scheduler::Method method) 291 Scheduler::Method method)
285{ 292{
286 icalcomponent *message = mImpl->createScheduleComponent(incidence,method); 293 icalcomponent *message = mImpl->createScheduleComponent(incidence,method);
287 294
288 QString messageText = icalcomponent_as_ical_string(message); 295 QString messageText = icalcomponent_as_ical_string(message);
289 296
290 297
291 298
292 return messageText; 299 return messageText;
293} 300}
294 301
295ScheduleMessage *ICalFormat::parseScheduleMessage( Calendar *cal, 302ScheduleMessage *ICalFormat::parseScheduleMessage( Calendar *cal,
296 const QString &messageText ) 303 const QString &messageText )
297{ 304{
298 setTimeZone( cal->timeZoneId(), !cal->isLocalTime() ); 305 setTimeZone( cal->timeZoneId(), !cal->isLocalTime() );
299 clearException(); 306 clearException();
300 307
301 if (messageText.isEmpty()) return 0; 308 if (messageText.isEmpty()) return 0;
302 309
303 icalcomponent *message; 310 icalcomponent *message;
304 message = icalparser_parse_string(messageText.local8Bit()); 311 message = icalparser_parse_string(messageText.local8Bit());
305 312
306 if (!message) return 0; 313 if (!message) return 0;
307 314
308 icalproperty *m = icalcomponent_get_first_property(message, 315 icalproperty *m = icalcomponent_get_first_property(message,
309 ICAL_METHOD_PROPERTY); 316 ICAL_METHOD_PROPERTY);
310 317
311 if (!m) return 0; 318 if (!m) return 0;
312 319
313 icalcomponent *c; 320 icalcomponent *c;
314 321
315 IncidenceBase *incidence = 0; 322 IncidenceBase *incidence = 0;
316 c = icalcomponent_get_first_component(message,ICAL_VEVENT_COMPONENT); 323 c = icalcomponent_get_first_component(message,ICAL_VEVENT_COMPONENT);
317 if (c) { 324 if (c) {
318 incidence = mImpl->readEvent(c); 325 incidence = mImpl->readEvent(c);
319 } 326 }
320 327
321 if (!incidence) { 328 if (!incidence) {
322 c = icalcomponent_get_first_component(message,ICAL_VTODO_COMPONENT); 329 c = icalcomponent_get_first_component(message,ICAL_VTODO_COMPONENT);
323 if (c) { 330 if (c) {
324 incidence = mImpl->readTodo(c); 331 incidence = mImpl->readTodo(c);
325 } 332 }
326 } 333 }
327 334
328 if (!incidence) { 335 if (!incidence) {
329 c = icalcomponent_get_first_component(message,ICAL_VFREEBUSY_COMPONENT); 336 c = icalcomponent_get_first_component(message,ICAL_VFREEBUSY_COMPONENT);
330 if (c) { 337 if (c) {
331 incidence = mImpl->readFreeBusy(c); 338 incidence = mImpl->readFreeBusy(c);
332 } 339 }
333 } 340 }
334 341
335 if (!incidence) { 342 if (!incidence) {
336 kdDebug() << "ICalFormat:parseScheduleMessage: object is not a freebusy, event or todo" << endl; 343 kdDebug() << "ICalFormat:parseScheduleMessage: object is not a freebusy, event or todo" << endl;
337 return 0; 344 return 0;
338 } 345 }
339 346
340 kdDebug(5800) << "ICalFormat::parseScheduleMessage() getting method..." << endl; 347 kdDebug(5800) << "ICalFormat::parseScheduleMessage() getting method..." << endl;
341 348
342 icalproperty_method icalmethod = icalproperty_get_method(m); 349 icalproperty_method icalmethod = icalproperty_get_method(m);
343 Scheduler::Method method; 350 Scheduler::Method method;
344 351
345 switch (icalmethod) { 352 switch (icalmethod) {
346 case ICAL_METHOD_PUBLISH: 353 case ICAL_METHOD_PUBLISH:
347 method = Scheduler::Publish; 354 method = Scheduler::Publish;
348 break; 355 break;
349 case ICAL_METHOD_REQUEST: 356 case ICAL_METHOD_REQUEST:
350 method = Scheduler::Request; 357 method = Scheduler::Request;
351 break; 358 break;
352 case ICAL_METHOD_REFRESH: 359 case ICAL_METHOD_REFRESH:
353 method = Scheduler::Refresh; 360 method = Scheduler::Refresh;
354 break; 361 break;
355 case ICAL_METHOD_CANCEL: 362 case ICAL_METHOD_CANCEL:
356 method = Scheduler::Cancel; 363 method = Scheduler::Cancel;
357 break; 364 break;
358 case ICAL_METHOD_ADD: 365 case ICAL_METHOD_ADD:
359 method = Scheduler::Add; 366 method = Scheduler::Add;
360 break; 367 break;
361 case ICAL_METHOD_REPLY: 368 case ICAL_METHOD_REPLY:
362 method = Scheduler::Reply; 369 method = Scheduler::Reply;
363 break; 370 break;
364 case ICAL_METHOD_COUNTER: 371 case ICAL_METHOD_COUNTER:
365 method = Scheduler::Counter; 372 method = Scheduler::Counter;
366 break; 373 break;
367 case ICAL_METHOD_DECLINECOUNTER: 374 case ICAL_METHOD_DECLINECOUNTER:
368 method = Scheduler::Declinecounter; 375 method = Scheduler::Declinecounter;
369 break; 376 break;
370 default: 377 default:
371 method = Scheduler::NoMethod; 378 method = Scheduler::NoMethod;
372 kdDebug(5800) << "ICalFormat::parseScheduleMessage(): Unknow method" << endl; 379 kdDebug(5800) << "ICalFormat::parseScheduleMessage(): Unknow method" << endl;
373 break; 380 break;
374 } 381 }
375 382
376 383
377 if (!icalrestriction_check(message)) { 384 if (!icalrestriction_check(message)) {
378 setException(new ErrorFormat(ErrorFormat::Restriction, 385 setException(new ErrorFormat(ErrorFormat::Restriction,
379 Scheduler::translatedMethodName(method) + ": " + 386 Scheduler::translatedMethodName(method) + ": " +
380 mImpl->extractErrorProperty(c))); 387 mImpl->extractErrorProperty(c)));
381 return 0; 388 return 0;
382 } 389 }
383 390
384 icalcomponent *calendarComponent = mImpl->createCalendarComponent(cal); 391 icalcomponent *calendarComponent = mImpl->createCalendarComponent(cal);
385 392
386 Incidence *existingIncidence = cal->event(incidence->uid()); 393 Incidence *existingIncidence = cal->event(incidence->uid());
387 if (existingIncidence) { 394 if (existingIncidence) {
388 // TODO: check, if cast is required, or if it can be done by virtual funcs. 395 // TODO: check, if cast is required, or if it can be done by virtual funcs.
389 if (existingIncidence->typeID() == todoID ) { 396 if (existingIncidence->typeID() == todoID ) {
390 Todo *todo = static_cast<Todo *>(existingIncidence); 397 Todo *todo = static_cast<Todo *>(existingIncidence);
391 icalcomponent_add_component(calendarComponent, 398 icalcomponent_add_component(calendarComponent,
392 mImpl->writeTodo(todo)); 399 mImpl->writeTodo(todo));
393 } 400 }
394 if (existingIncidence->typeID() == eventID ) { 401 if (existingIncidence->typeID() == eventID ) {
395 Event *event = static_cast<Event *>(existingIncidence); 402 Event *event = static_cast<Event *>(existingIncidence);
396 icalcomponent_add_component(calendarComponent, 403 icalcomponent_add_component(calendarComponent,
397 mImpl->writeEvent(event)); 404 mImpl->writeEvent(event));
398 } 405 }
399 } else { 406 } else {
400 calendarComponent = 0; 407 calendarComponent = 0;
401 } 408 }
402 qDebug("icalclassify commented out "); 409 qDebug("icalclassify commented out ");
403 ScheduleMessage::Status status; 410 ScheduleMessage::Status status;
404#if 0 411#if 0
405 412
406 icalclass result = icalclassify(message,calendarComponent,(char *)""); 413 icalclass result = icalclassify(message,calendarComponent,(char *)"");
407 414
408 415
409 416
410 switch (result) { 417 switch (result) {
411 case ICAL_PUBLISH_NEW_CLASS: 418 case ICAL_PUBLISH_NEW_CLASS:
412 status = ScheduleMessage::PublishNew; 419 status = ScheduleMessage::PublishNew;
413 break; 420 break;
414 case ICAL_OBSOLETE_CLASS: 421 case ICAL_OBSOLETE_CLASS:
415 status = ScheduleMessage::Obsolete; 422 status = ScheduleMessage::Obsolete;
416 break; 423 break;
417 case ICAL_REQUEST_NEW_CLASS: 424 case ICAL_REQUEST_NEW_CLASS:
418 status = ScheduleMessage::RequestNew; 425 status = ScheduleMessage::RequestNew;
419 break; 426 break;
420 case ICAL_REQUEST_UPDATE_CLASS: 427 case ICAL_REQUEST_UPDATE_CLASS:
421 status = ScheduleMessage::RequestUpdate; 428 status = ScheduleMessage::RequestUpdate;
422 break; 429 break;
423 case ICAL_UNKNOWN_CLASS: 430 case ICAL_UNKNOWN_CLASS:
424 default: 431 default:
425 status = ScheduleMessage::Unknown; 432 status = ScheduleMessage::Unknown;
426 break; 433 break;
427 } 434 }
428#endif 435#endif
429 status = ScheduleMessage::RequestUpdate; 436 status = ScheduleMessage::RequestUpdate;
430 return new ScheduleMessage(incidence,method,status); 437 return new ScheduleMessage(incidence,method,status);
431} 438}
432 439
433void ICalFormat::setTimeZone( const QString &id, bool utc ) 440void ICalFormat::setTimeZone( const QString &id, bool utc )
434{ 441{
435 442
436 443
437 mTimeZoneId = id; 444 mTimeZoneId = id;
438 mUtc = utc; 445 mUtc = utc;
439 446
440 tzOffsetMin = KGlobal::locale()->timezoneOffset(mTimeZoneId); 447 tzOffsetMin = KGlobal::locale()->timezoneOffset(mTimeZoneId);
441 448
442 //qDebug("ICalFormat::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), tzOffsetMin); 449 //qDebug("ICalFormat::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), tzOffsetMin);
443} 450}
444 451
445QString ICalFormat::timeZoneId() const 452QString ICalFormat::timeZoneId() const
446{ 453{
447 return mTimeZoneId; 454 return mTimeZoneId;
448} 455}
449 456
450bool ICalFormat::utc() const 457bool ICalFormat::utc() const
451{ 458{
452 return mUtc; 459 return mUtc;
453} 460}
454int ICalFormat::timeOffset() 461int ICalFormat::timeOffset()
455{ 462{
456 return tzOffsetMin; 463 return tzOffsetMin;
457} 464}
458const char *ICalFormat::tzString() 465const char *ICalFormat::tzString()
459{ 466{
460 const char* ret = (const char* ) mTzString; 467 const char* ret = (const char* ) mTzString;
461 return ret; 468 return ret;
462} 469}
diff --git a/libkcal/icalformat.h b/libkcal/icalformat.h
index 485ab6e..a770dbb 100644
--- a/libkcal/icalformat.h
+++ b/libkcal/icalformat.h
@@ -1,115 +1,116 @@
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 ICALFORMAT_H 20#ifndef ICALFORMAT_H
21#define ICALFORMAT_H 21#define ICALFORMAT_H
22 22
23#include <qstring.h> 23#include <qstring.h>
24 24
25#include "scheduler.h" 25#include "scheduler.h"
26 26
27#include "calformat.h" 27#include "calformat.h"
28 28
29namespace KCal { 29namespace KCal {
30 30
31class ICalFormatImpl; 31class ICalFormatImpl;
32 32
33/** 33/**
34 This class implements the iCalendar format. It provides methods for 34 This class implements the iCalendar format. It provides methods for
35 loading/saving/converting iCalendar format data into the internal KOrganizer 35 loading/saving/converting iCalendar format data into the internal KOrganizer
36 representation as Calendar and Events. 36 representation as Calendar and Events.
37 37
38 @short iCalendar format implementation 38 @short iCalendar format implementation
39*/ 39*/
40class ICalFormat : public CalFormat { 40class ICalFormat : public CalFormat {
41 public: 41 public:
42 /** Create new iCalendar format. */ 42 /** Create new iCalendar format. */
43 ICalFormat( ); 43 ICalFormat( bool pe = true);
44 virtual ~ICalFormat(); 44 virtual ~ICalFormat();
45 45
46 /** 46 /**
47 Loads a calendar on disk in iCalendar format into calendar. 47 Loads a calendar on disk in iCalendar format into calendar.
48 Returns true if successful, else returns false. Provides more error 48 Returns true if successful, else returns false. Provides more error
49 information by exception(). 49 information by exception().
50 @param calendar Calendar object to be filled. 50 @param calendar Calendar object to be filled.
51 @param fileName The name of the calendar file on disk. 51 @param fileName The name of the calendar file on disk.
52 */ 52 */
53 bool load( Calendar *, const QString &fileName ); 53 bool load( Calendar *, const QString &fileName );
54 /** 54 /**
55 Writes out the calendar to disk in iCalendar format. Returns true if 55 Writes out the calendar to disk in iCalendar format. Returns true if
56 successful and false on error. 56 successful and false on error.
57 57
58 @param calendar The Calendar object to be written. 58 @param calendar The Calendar object to be written.
59 @param fileName The name of the calendar file on disk. 59 @param fileName The name of the calendar file on disk.
60 */ 60 */
61 bool save( Calendar *, const QString &fileName ); 61 bool save( Calendar *, const QString &fileName );
62 62
63 /** 63 /**
64 Parse string and populate calendar with that information. 64 Parse string and populate calendar with that information.
65 */ 65 */
66 bool fromString( Calendar *, const QString & ); 66 bool fromString( Calendar *, const QString & );
67 /** 67 /**
68 Parse string and return first ical component. 68 Parse string and return first ical component.
69 */ 69 */
70 Incidence *fromString( const QString & ); 70 Incidence *fromString( const QString & );
71 /** 71 /**
72 Return calendar information as string. 72 Return calendar information as string.
73 */ 73 */
74 QString toString( Calendar * ); 74 QString toString( Calendar * );
75 /** 75 /**
76 Return incidence as full iCalendar formatted text. 76 Return incidence as full iCalendar formatted text.
77 */ 77 */
78 QString toICalString( Incidence * ); 78 QString toICalString( Incidence * );
79 /** 79 /**
80 Return incidence as iCalendar formatted text. 80 Return incidence as iCalendar formatted text.
81 */ 81 */
82 QString toString( Incidence * ); 82 QString toString( Incidence * );
83 /** 83 /**
84 Return recurrence as iCalendar formatted text. 84 Return recurrence as iCalendar formatted text.
85 */ 85 */
86 QString toString( Recurrence * ); 86 QString toString( Recurrence * );
87 /** 87 /**
88 Parse string and fill recurrence object with 88 Parse string and fill recurrence object with
89 that information 89 that information
90 */ 90 */
91 //bool fromString ( Recurrence *, const QString& ); 91 //bool fromString ( Recurrence *, const QString& );
92 92
93 /** Create a scheduling message for event \a e using method \m */ 93 /** Create a scheduling message for event \a e using method \m */
94 QString createScheduleMessage(IncidenceBase *e,Scheduler::Method m); 94 QString createScheduleMessage(IncidenceBase *e,Scheduler::Method m);
95 /** Parse scheduling message provided as string \s */ 95 /** Parse scheduling message provided as string \s */
96 ScheduleMessage *parseScheduleMessage( Calendar *, const QString &s); 96 ScheduleMessage *parseScheduleMessage( Calendar *, const QString &s);
97 97
98 /** Set id of used time zone and whether this time zone is UTC or not. */ 98 /** Set id of used time zone and whether this time zone is UTC or not. */
99 void setTimeZone( const QString &id, bool utc ); 99 void setTimeZone( const QString &id, bool utc );
100 QString timeZoneId() const; 100 QString timeZoneId() const;
101 int timeOffset(); 101 int timeOffset();
102 const char * tzString(); 102 const char * tzString();
103 bool utc() const; 103 bool utc() const;
104 104
105 private: 105 private:
106 bool mProcessEvents;
106 ICalFormatImpl *mImpl; 107 ICalFormatImpl *mImpl;
107 QString mTimeZoneId; 108 QString mTimeZoneId;
108 QCString mTzString; 109 QCString mTzString;
109 int tzOffsetMin; 110 int tzOffsetMin;
110 bool mUtc; 111 bool mUtc;
111}; 112};
112 113
113} 114}
114 115
115#endif 116#endif
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp
index 4ada2d8..7bf756a 100644
--- a/libkcal/todo.cpp
+++ b/libkcal/todo.cpp
@@ -1,615 +1,616 @@
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 if ( mRunSaveTimer )
70 mRunSaveTimer->stop();
70 saveRunningInfoToFile( s ); 71 saveRunningInfoToFile( s );
71} 72}
72void Todo::stopRunning() 73void Todo::stopRunning()
73{ 74{
74 if ( !mRunning ) 75 if ( !mRunning )
75 return; 76 return;
76 if ( mRunSaveTimer ) 77 if ( mRunSaveTimer )
77 mRunSaveTimer->stop(); 78 mRunSaveTimer->stop();
78 mRunning = false; 79 mRunning = false;
79} 80}
80void Todo::setRunning( bool run ) 81void Todo::setRunning( bool run )
81{ 82{
82 if ( run == mRunning ) 83 if ( run == mRunning )
83 return; 84 return;
84 //qDebug("Todo::setRunning %d ", run); 85 //qDebug("Todo::setRunning %d ", run);
85 if ( !mRunSaveTimer ) { 86 if ( !mRunSaveTimer ) {
86 mRunSaveTimer = new QTimer ( this ); 87 mRunSaveTimer = new QTimer ( this );
87 connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) ); 88 connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) );
88 } 89 }
89 mRunning = run; 90 mRunning = run;
90 if ( mRunning ) { 91 if ( mRunning ) {
91 mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min 92 mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min
92 mRunStart = QDateTime::currentDateTime(); 93 mRunStart = QDateTime::currentDateTime();
93 } else { 94 } else {
94 mRunSaveTimer->stop(); 95 mRunSaveTimer->stop();
95 saveRunningInfoToFile(); 96 saveRunningInfoToFile();
96 } 97 }
97} 98}
98void Todo::saveRunningInfo( QString comment, QDateTime start, QDateTime end ) 99void Todo::saveRunningInfo( QString comment, QDateTime start, QDateTime end )
99{ 100{
100 if ( !mRunning) return; 101 if ( !mRunning) return;
101 mRunning = false; 102 mRunning = false;
102 mRunStart = start; 103 mRunStart = start;
103 mRunEnd = end; 104 mRunEnd = end;
104 saveRunningInfoToFile( comment ); 105 saveRunningInfoToFile( comment );
105} 106}
106void Todo::saveRunningInfoToFile() 107void Todo::saveRunningInfoToFile()
107{ 108{
108 mRunEnd = QDateTime::currentDateTime(); 109 mRunEnd = QDateTime::currentDateTime();
109 saveRunningInfoToFile( QString::null ); 110 saveRunningInfoToFile( QString::null );
110} 111}
111void Todo::saveRunningInfoToFile( QString comment ) 112void Todo::saveRunningInfoToFile( QString comment )
112{ 113{
113 //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); 114 //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1());
114 if ( mRunStart.secsTo ( mRunEnd) < 15 ) { 115 if ( mRunStart.secsTo ( mRunEnd) < 15 ) {
115 qDebug("Running time < 15 seconds. Skipped. "); 116 qDebug("Running time < 15 seconds. Skipped. ");
116 return; 117 return;
117 } 118 }
118 QString dir = KGlobalSettings::timeTrackerDir(); 119 QString dir = KGlobalSettings::timeTrackerDir();
119 //qDebug("%s ", dir.latin1()); 120 //qDebug("%s ", dir.latin1());
120 QString file = "%1%2%3-%4%5%6-"; 121 QString file = "%1%2%3-%4%5%6-";
121 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 ); 122 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 );
122 file.replace ( QRegExp (" "), "0" ); 123 file.replace ( QRegExp (" "), "0" );
123 file += uid(); 124 file += uid();
124 //qDebug("File %s ",file.latin1() ); 125 //qDebug("File %s ",file.latin1() );
125 CalendarLocal cal; 126 CalendarLocal cal;
126 cal.setLocalTime(); 127 cal.setLocalTime();
127 Todo * to = (Todo*) clone(); 128 Todo * to = (Todo*) clone();
128 to->setFloats( false ); 129 to->setFloats( false );
129 to->setDtStart( mRunStart ); 130 to->setDtStart( mRunStart );
130 to->setHasStartDate( true ); 131 to->setHasStartDate( true );
131 to->setDtDue( mRunEnd ); 132 to->setDtDue( mRunEnd );
132 to->setHasDueDate( true ); 133 to->setHasDueDate( true );
133 to->setUid( file ); 134 to->setUid( file );
134 if ( !comment.isEmpty() ) { 135 if ( !comment.isEmpty() ) {
135 QString des = to->description(); 136 QString des = to->description();
136 if ( des.isEmpty () ) 137 if ( des.isEmpty () )
137 to->setDescription( "TT-Note: " + comment ); 138 to->setDescription( "TT-Note: " + comment );
138 else 139 else
139 to->setDescription( "TT-Note: " + comment +"\n" + des ); 140 to->setDescription( "TT-Note: " + comment +"\n" + des );
140 } 141 }
141 cal.addIncidence( to ); 142 cal.addIncidence( to );
142 ICalFormat format; 143 ICalFormat format( false );
143 file = dir +"/" +file +".ics"; 144 file = dir +"/" +file +".ics";
144 format.save( &cal, file ); 145 format.save( &cal, file );
145 saveParents(); 146 saveParents();
146 147
147} 148}
148void Todo::saveParents() 149void Todo::saveParents()
149{ 150{
150 if (!relatedTo() ) 151 if (!relatedTo() )
151 return; 152 return;
152 Incidence * inc = relatedTo(); 153 Incidence * inc = relatedTo();
153 if ( inc->typeID() != todoID ) 154 if ( inc->typeID() != todoID )
154 return; 155 return;
155 Todo* to = (Todo*)inc; 156 Todo* to = (Todo*)inc;
156 bool saveTodo = false; 157 bool saveTodo = false;
157 QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics"; 158 QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics";
158 QFileInfo fi ( file ); 159 QFileInfo fi ( file );
159 if ( fi.exists() ) { 160 if ( fi.exists() ) {
160 if ( fi.lastModified () < to->lastModified ()) 161 if ( fi.lastModified () < to->lastModified ())
161 saveTodo = true; 162 saveTodo = true;
162 } else { 163 } else {
163 saveTodo = true; 164 saveTodo = true;
164 } 165 }
165 if ( saveTodo ) { 166 if ( saveTodo ) {
166 CalendarLocal cal; 167 CalendarLocal cal;
167 cal.setLocalTime(); 168 cal.setLocalTime();
168 Todo * par = (Todo *) to->clone(); 169 Todo * par = (Todo *) to->clone();
169 cal.addIncidence( par ); 170 cal.addIncidence( par );
170 ICalFormat format; 171 ICalFormat format( false );
171 format.save( &cal, file ); 172 format.save( &cal, file );
172 } 173 }
173 to->saveParents(); 174 to->saveParents();
174} 175}
175 176
176int Todo::runTime() 177int Todo::runTime()
177{ 178{
178 if ( !mRunning ) 179 if ( !mRunning )
179 return 0; 180 return 0;
180 return mRunStart.secsTo( QDateTime::currentDateTime() ); 181 return mRunStart.secsTo( QDateTime::currentDateTime() );
181} 182}
182bool Todo::hasRunningSub() 183bool Todo::hasRunningSub()
183{ 184{
184 if ( mRunning ) 185 if ( mRunning )
185 return true; 186 return true;
186 Incidence *aTodo; 187 Incidence *aTodo;
187 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { 188 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) {
188 if ( ((Todo*)aTodo)->hasRunningSub() ) 189 if ( ((Todo*)aTodo)->hasRunningSub() )
189 return true; 190 return true;
190 } 191 }
191 return false; 192 return false;
192} 193}
193Incidence *Todo::clone() 194Incidence *Todo::clone()
194{ 195{
195 return new Todo(*this); 196 return new Todo(*this);
196} 197}
197 198
198bool Todo::contains ( Todo* from ) 199bool Todo::contains ( Todo* from )
199{ 200{
200 201
201 if ( !from->summary().isEmpty() ) 202 if ( !from->summary().isEmpty() )
202 if ( !summary().startsWith( from->summary() )) 203 if ( !summary().startsWith( from->summary() ))
203 return false; 204 return false;
204 if ( from->hasStartDate() ) { 205 if ( from->hasStartDate() ) {
205 if ( !hasStartDate() ) 206 if ( !hasStartDate() )
206 return false; 207 return false;
207 if ( from->dtStart() != dtStart()) 208 if ( from->dtStart() != dtStart())
208 return false; 209 return false;
209 } 210 }
210 if ( from->hasDueDate() ){ 211 if ( from->hasDueDate() ){
211 if ( !hasDueDate() ) 212 if ( !hasDueDate() )
212 return false; 213 return false;
213 if ( from->dtDue() != dtDue()) 214 if ( from->dtDue() != dtDue())
214 return false; 215 return false;
215 } 216 }
216 if ( !from->location().isEmpty() ) 217 if ( !from->location().isEmpty() )
217 if ( !location().startsWith( from->location() ) ) 218 if ( !location().startsWith( from->location() ) )
218 return false; 219 return false;
219 if ( !from->description().isEmpty() ) 220 if ( !from->description().isEmpty() )
220 if ( !description().startsWith( from->description() )) 221 if ( !description().startsWith( from->description() ))
221 return false; 222 return false;
222 if ( from->alarms().count() ) { 223 if ( from->alarms().count() ) {
223 Alarm *a = from->alarms().first(); 224 Alarm *a = from->alarms().first();
224 if ( a->enabled() ){ 225 if ( a->enabled() ){
225 if ( !alarms().count() ) 226 if ( !alarms().count() )
226 return false; 227 return false;
227 Alarm *b = alarms().first(); 228 Alarm *b = alarms().first();
228 if( ! b->enabled() ) 229 if( ! b->enabled() )
229 return false; 230 return false;
230 if ( ! (a->offset() == b->offset() )) 231 if ( ! (a->offset() == b->offset() ))
231 return false; 232 return false;
232 } 233 }
233 } 234 }
234 235
235 QStringList cat = categories(); 236 QStringList cat = categories();
236 QStringList catFrom = from->categories(); 237 QStringList catFrom = from->categories();
237 QString nCat; 238 QString nCat;
238 unsigned int iii; 239 unsigned int iii;
239 for ( iii = 0; iii < catFrom.count();++iii ) { 240 for ( iii = 0; iii < catFrom.count();++iii ) {
240 nCat = catFrom[iii]; 241 nCat = catFrom[iii];
241 if ( !nCat.isEmpty() ) 242 if ( !nCat.isEmpty() )
242 if ( !cat.contains( nCat )) { 243 if ( !cat.contains( nCat )) {
243 return false; 244 return false;
244 } 245 }
245 } 246 }
246 if ( from->isCompleted() ) { 247 if ( from->isCompleted() ) {
247 if ( !isCompleted() ) 248 if ( !isCompleted() )
248 return false; 249 return false;
249 } 250 }
250 if( priority() != from->priority() ) 251 if( priority() != from->priority() )
251 return false; 252 return false;
252 253
253 254
254 return true; 255 return true;
255 256
256} 257}
257bool KCal::operator==( const Todo& t1, const Todo& t2 ) 258bool KCal::operator==( const Todo& t1, const Todo& t2 )
258{ 259{
259 260
260 bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 ); 261 bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 );
261 if ( ! ret ) 262 if ( ! ret )
262 return false; 263 return false;
263 if ( t1.hasDueDate() == t2.hasDueDate() ) { 264 if ( t1.hasDueDate() == t2.hasDueDate() ) {
264 if ( t1.hasDueDate() ) { 265 if ( t1.hasDueDate() ) {
265 if ( t1.doesFloat() == t2.doesFloat() ) { 266 if ( t1.doesFloat() == t2.doesFloat() ) {
266 if ( t1.doesFloat() ) { 267 if ( t1.doesFloat() ) {
267 if ( t1.dtDue().date() != t2.dtDue().date() ) 268 if ( t1.dtDue().date() != t2.dtDue().date() )
268 return false; 269 return false;
269 } else 270 } else
270 if ( t1.dtDue() != t2.dtDue() ) 271 if ( t1.dtDue() != t2.dtDue() )
271 return false; 272 return false;
272 } else 273 } else
273 return false;// float != 274 return false;// float !=
274 } 275 }
275 276
276 } else 277 } else
277 return false; 278 return false;
278 if ( t1.percentComplete() != t2.percentComplete() ) 279 if ( t1.percentComplete() != t2.percentComplete() )
279 return false; 280 return false;
280 if ( t1.isCompleted() ) { 281 if ( t1.isCompleted() ) {
281 if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) { 282 if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) {
282 if ( t1.hasCompletedDate() ) { 283 if ( t1.hasCompletedDate() ) {
283 if ( t1.completed() != t2.completed() ) 284 if ( t1.completed() != t2.completed() )
284 return false; 285 return false;
285 } 286 }
286 287
287 } else 288 } else
288 return false; 289 return false;
289 } 290 }
290 return true; 291 return true;
291 292
292} 293}
293 294
294void Todo::setDtDue(const QDateTime &dtDue) 295void Todo::setDtDue(const QDateTime &dtDue)
295{ 296{
296 //int diffsecs = mDtDue.secsTo(dtDue); 297 //int diffsecs = mDtDue.secsTo(dtDue);
297 298
298 /*if (mReadOnly) return; 299 /*if (mReadOnly) return;
299 const QPtrList<Alarm>& alarms = alarms(); 300 const QPtrList<Alarm>& alarms = alarms();
300 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) { 301 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) {
301 if (alarm->enabled()) { 302 if (alarm->enabled()) {
302 alarm->setTime(alarm->time().addSecs(diffsecs)); 303 alarm->setTime(alarm->time().addSecs(diffsecs));
303 } 304 }
304 }*/ 305 }*/
305 mDtDue = getEvenTime(dtDue); 306 mDtDue = getEvenTime(dtDue);
306 307
307 //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl; 308 //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl;
308 309
309 /*const QPtrList<Alarm>& alarms = alarms(); 310 /*const QPtrList<Alarm>& alarms = alarms();
310 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) 311 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next())
311 alarm->setAlarmStart(mDtDue);*/ 312 alarm->setAlarmStart(mDtDue);*/
312 updated(); 313 updated();
313} 314}
314 315
315QDateTime Todo::dtDue() const 316QDateTime Todo::dtDue() const
316{ 317{
317 return mDtDue; 318 return mDtDue;
318} 319}
319 320
320QString Todo::dtDueTimeStr() const 321QString Todo::dtDueTimeStr() const
321{ 322{
322 return KGlobal::locale()->formatTime(mDtDue.time()); 323 return KGlobal::locale()->formatTime(mDtDue.time());
323} 324}
324 325
325QString Todo::dtDueDateStr(bool shortfmt) const 326QString Todo::dtDueDateStr(bool shortfmt) const
326{ 327{
327 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); 328 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt);
328} 329}
329 330
330QString Todo::dtDueStr(bool shortfmt) const 331QString Todo::dtDueStr(bool shortfmt) const
331{ 332{
332 if ( doesFloat() ) 333 if ( doesFloat() )
333 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); 334 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt);
334 return KGlobal::locale()->formatDateTime(mDtDue, shortfmt); 335 return KGlobal::locale()->formatDateTime(mDtDue, shortfmt);
335} 336}
336// retval 0 : no found 337// retval 0 : no found
337// 1 : due for date found 338// 1 : due for date found
338// 2 : overdue for date found 339// 2 : overdue for date found
339int Todo::hasDueSubTodoForDate( const QDate & date, bool checkSubtodos ) 340int Todo::hasDueSubTodoForDate( const QDate & date, bool checkSubtodos )
340{ 341{
341 int retval = 0; 342 int retval = 0;
342 if ( isCompleted() ) 343 if ( isCompleted() )
343 return 0; 344 return 0;
344 if ( hasDueDate() ) { 345 if ( hasDueDate() ) {
345 if ( dtDue().date() < date ) 346 if ( dtDue().date() < date )
346 return 2; 347 return 2;
347 // we do not return, because we may find an overdue sub todo 348 // we do not return, because we may find an overdue sub todo
348 if ( dtDue().date() == date ) 349 if ( dtDue().date() == date )
349 retval = 1; 350 retval = 1;
350 } 351 }
351 if ( checkSubtodos ) { 352 if ( checkSubtodos ) {
352 Incidence *aTodo; 353 Incidence *aTodo;
353 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { 354 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) {
354 int ret = ((Todo*)aTodo)->hasDueSubTodoForDate( date ,checkSubtodos ); 355 int ret = ((Todo*)aTodo)->hasDueSubTodoForDate( date ,checkSubtodos );
355 if ( ret == 2 ) 356 if ( ret == 2 )
356 return 2; 357 return 2;
357 if ( ret == 1) 358 if ( ret == 1)
358 retval = 1; 359 retval = 1;
359 } 360 }
360 } 361 }
361 return retval; 362 return retval;
362} 363}
363int Todo::hasDueSubTodo( bool checkSubtodos ) //= true 364int Todo::hasDueSubTodo( bool checkSubtodos ) //= true
364{ 365{
365 return hasDueSubTodoForDate(QDate::currentDate(), checkSubtodos ); 366 return hasDueSubTodoForDate(QDate::currentDate(), checkSubtodos );
366} 367}
367bool Todo::hasDueDate() const 368bool Todo::hasDueDate() const
368{ 369{
369 return mHasDueDate; 370 return mHasDueDate;
370} 371}
371 372
372void Todo::setHasDueDate(bool f) 373void Todo::setHasDueDate(bool f)
373{ 374{
374 if (mReadOnly) return; 375 if (mReadOnly) return;
375 mHasDueDate = f; 376 mHasDueDate = f;
376 updated(); 377 updated();
377} 378}
378 379
379 380
380#if 0 381#if 0
381void Todo::setStatus(const QString &statStr) 382void Todo::setStatus(const QString &statStr)
382{ 383{
383 if (mReadOnly) return; 384 if (mReadOnly) return;
384 QString ss(statStr.upper()); 385 QString ss(statStr.upper());
385 386
386 if (ss == "X-ACTION") 387 if (ss == "X-ACTION")
387 mStatus = NEEDS_ACTION; 388 mStatus = NEEDS_ACTION;
388 else if (ss == "NEEDS ACTION") 389 else if (ss == "NEEDS ACTION")
389 mStatus = NEEDS_ACTION; 390 mStatus = NEEDS_ACTION;
390 else if (ss == "ACCEPTED") 391 else if (ss == "ACCEPTED")
391 mStatus = ACCEPTED; 392 mStatus = ACCEPTED;
392 else if (ss == "SENT") 393 else if (ss == "SENT")
393 mStatus = SENT; 394 mStatus = SENT;
394 else if (ss == "TENTATIVE") 395 else if (ss == "TENTATIVE")
395 mStatus = TENTATIVE; 396 mStatus = TENTATIVE;
396 else if (ss == "CONFIRMED") 397 else if (ss == "CONFIRMED")
397 mStatus = CONFIRMED; 398 mStatus = CONFIRMED;
398 else if (ss == "DECLINED") 399 else if (ss == "DECLINED")
399 mStatus = DECLINED; 400 mStatus = DECLINED;
400 else if (ss == "COMPLETED") 401 else if (ss == "COMPLETED")
401 mStatus = COMPLETED; 402 mStatus = COMPLETED;
402 else if (ss == "DELEGATED") 403 else if (ss == "DELEGATED")
403 mStatus = DELEGATED; 404 mStatus = DELEGATED;
404 405
405 updated(); 406 updated();
406} 407}
407 408
408void Todo::setStatus(int status) 409void Todo::setStatus(int status)
409{ 410{
410 if (mReadOnly) return; 411 if (mReadOnly) return;
411 mStatus = status; 412 mStatus = status;
412 updated(); 413 updated();
413} 414}
414 415
415int Todo::status() const 416int Todo::status() const
416{ 417{
417 return mStatus; 418 return mStatus;
418} 419}
419 420
420QString Todo::statusStr() const 421QString Todo::statusStr() const
421{ 422{
422 switch(mStatus) { 423 switch(mStatus) {
423 case NEEDS_ACTION: 424 case NEEDS_ACTION:
424 return QString("NEEDS ACTION"); 425 return QString("NEEDS ACTION");
425 break; 426 break;
426 case ACCEPTED: 427 case ACCEPTED:
427 return QString("ACCEPTED"); 428 return QString("ACCEPTED");
428 break; 429 break;
429 case SENT: 430 case SENT:
430 return QString("SENT"); 431 return QString("SENT");
431 break; 432 break;
432 case TENTATIVE: 433 case TENTATIVE:
433 return QString("TENTATIVE"); 434 return QString("TENTATIVE");
434 break; 435 break;
435 case CONFIRMED: 436 case CONFIRMED:
436 return QString("CONFIRMED"); 437 return QString("CONFIRMED");
437 break; 438 break;
438 case DECLINED: 439 case DECLINED:
439 return QString("DECLINED"); 440 return QString("DECLINED");
440 break; 441 break;
441 case COMPLETED: 442 case COMPLETED:
442 return QString("COMPLETED"); 443 return QString("COMPLETED");
443 break; 444 break;
444 case DELEGATED: 445 case DELEGATED:
445 return QString("DELEGATED"); 446 return QString("DELEGATED");
446 break; 447 break;
447 } 448 }
448 return QString(""); 449 return QString("");
449} 450}
450#endif 451#endif
451 452
452bool Todo::isCompleted() const 453bool Todo::isCompleted() const
453{ 454{
454 if (mPercentComplete == 100) { 455 if (mPercentComplete == 100) {
455 return true; 456 return true;
456 } 457 }
457 else return false; 458 else return false;
458} 459}
459 460
460void Todo::setCompleted(bool completed) 461void Todo::setCompleted(bool completed)
461{ 462{
462 if ( mHasRecurrenceID && completed && mPercentComplete != 100 ) { 463 if ( mHasRecurrenceID && completed && mPercentComplete != 100 ) {
463 if ( !setRecurDates() ) 464 if ( !setRecurDates() )
464 completed = false; 465 completed = false;
465 } 466 }
466 if (completed) mPercentComplete = 100; 467 if (completed) mPercentComplete = 100;
467 else { 468 else {
468 mPercentComplete = 0; 469 mPercentComplete = 0;
469 mHasCompletedDate = false; 470 mHasCompletedDate = false;
470 } 471 }
471 updated(); 472 updated();
472} 473}
473 474
474QDateTime Todo::completed() const 475QDateTime Todo::completed() const
475{ 476{
476 return mCompleted; 477 return mCompleted;
477} 478}
478 479
479QString Todo::completedStr( bool shortF ) const 480QString Todo::completedStr( bool shortF ) const
480{ 481{
481 return KGlobal::locale()->formatDateTime(mCompleted, shortF); 482 return KGlobal::locale()->formatDateTime(mCompleted, shortF);
482} 483}
483 484
484void Todo::setCompleted(const QDateTime &completed) 485void Todo::setCompleted(const QDateTime &completed)
485{ 486{
486 //qDebug("Todo::setCompleted "); 487 //qDebug("Todo::setCompleted ");
487 if ( mHasCompletedDate ) { 488 if ( mHasCompletedDate ) {
488 // qDebug("has completed data - return "); 489 // qDebug("has completed data - return ");
489 return; 490 return;
490 } 491 }
491 mHasCompletedDate = true; 492 mHasCompletedDate = true;
492 mPercentComplete = 100; 493 mPercentComplete = 100;
493 mCompleted = getEvenTime(completed); 494 mCompleted = getEvenTime(completed);
494 updated(); 495 updated();
495} 496}
496 497
497bool Todo::hasCompletedDate() const 498bool Todo::hasCompletedDate() const
498{ 499{
499 return mHasCompletedDate; 500 return mHasCompletedDate;
500} 501}
501 502
502int Todo::percentComplete() const 503int Todo::percentComplete() const
503{ 504{
504 return mPercentComplete; 505 return mPercentComplete;
505} 506}
506bool Todo::setRecurDates() 507bool Todo::setRecurDates()
507{ 508{
508 if ( !mHasRecurrenceID ) 509 if ( !mHasRecurrenceID )
509 return true; 510 return true;
510 int secs = mDtStart.secsTo( dtDue() ); 511 int secs = mDtStart.secsTo( dtDue() );
511 bool ok; 512 bool ok;
512 qDebug("T:setRecurDates() "); 513 qDebug("T:setRecurDates() ");
513 //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); 514 //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() );
514 QDateTime next = getNextOccurence( mRecurrenceID, &ok ); 515 QDateTime next = getNextOccurence( mRecurrenceID, &ok );
515 if ( ok ) { 516 if ( ok ) {
516 mRecurrenceID = next; 517 mRecurrenceID = next;
517 mDtStart = next; 518 mDtStart = next;
518 setDtDue( next.addSecs( secs ) ); 519 setDtDue( next.addSecs( secs ) );
519 if ( QDateTime::currentDateTime() > next) 520 if ( QDateTime::currentDateTime() > next)
520 return false; 521 return false;
521 } else { 522 } else {
522 setHasRecurrenceID( false ); 523 setHasRecurrenceID( false );
523 recurrence()->unsetRecurs(); 524 recurrence()->unsetRecurs();
524 } 525 }
525 return true; 526 return true;
526} 527}
527void Todo::setPercentComplete(int v) 528void Todo::setPercentComplete(int v)
528{ 529{
529 if ( mHasRecurrenceID && v == 100 && mPercentComplete != 100 ) { 530 if ( mHasRecurrenceID && v == 100 && mPercentComplete != 100 ) {
530 if ( !setRecurDates() ) 531 if ( !setRecurDates() )
531 v = 0; 532 v = 0;
532 } 533 }
533 mPercentComplete = v; 534 mPercentComplete = v;
534 if ( v != 100 ) 535 if ( v != 100 )
535 mHasCompletedDate = false; 536 mHasCompletedDate = false;
536 updated(); 537 updated();
537} 538}
538QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const 539QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const
539{ 540{
540 *ok = false; 541 *ok = false;
541 if ( ! hasDueDate() || cancelled() || !alarmEnabled() ) { 542 if ( ! hasDueDate() || cancelled() || !alarmEnabled() ) {
542 return QDateTime (); 543 return QDateTime ();
543 } 544 }
544 // if the recurring todo is set to complete and requested time < start time of todo 545 // if the recurring todo is set to complete and requested time < start time of todo
545 // we want to get the alarm. 546 // we want to get the alarm.
546 bool iscompleted = isCompleted(); 547 bool iscompleted = isCompleted();
547 if ( iscompleted && doesRecur() ) { 548 if ( iscompleted && doesRecur() ) {
548 Todo * to = (Todo*) this; 549 Todo * to = (Todo*) this;
549 to->checkSetCompletedFalse(); 550 to->checkSetCompletedFalse();
550 iscompleted = isCompleted(); 551 iscompleted = isCompleted();
551 if ( hasStartDate() && start_dt < dtStart() ){ 552 if ( hasStartDate() && start_dt < dtStart() ){
552 iscompleted = false; 553 iscompleted = false;
553 } 554 }
554 } 555 }
555 if ( iscompleted ) { 556 if ( iscompleted ) {
556 return QDateTime (); 557 return QDateTime ();
557 } 558 }
558 QDateTime incidenceStart; 559 QDateTime incidenceStart;
559 incidenceStart = dtDue(); 560 incidenceStart = dtDue();
560 bool enabled = false; 561 bool enabled = false;
561 Alarm* alarm; 562 Alarm* alarm;
562 int off = 0; 563 int off = 0;
563 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; 564 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );;
564 // if ( QDateTime::currentDateTime() > incidenceStart ){ 565 // if ( QDateTime::currentDateTime() > incidenceStart ){
565// *ok = false; 566// *ok = false;
566// return incidenceStart; 567// return incidenceStart;
567// } 568// }
568 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { 569 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) {
569 if (alarm->enabled()) { 570 if (alarm->enabled()) {
570 if ( alarm->hasTime () ) { 571 if ( alarm->hasTime () ) {
571 if ( alarm->time() < alarmStart ) { 572 if ( alarm->time() < alarmStart ) {
572 alarmStart = alarm->time(); 573 alarmStart = alarm->time();
573 enabled = true; 574 enabled = true;
574 off = alarmStart.secsTo( incidenceStart ); 575 off = alarmStart.secsTo( incidenceStart );
575 } 576 }
576 577
577 } else { 578 } else {
578 int secs = alarm->startOffset().asSeconds(); 579 int secs = alarm->startOffset().asSeconds();
579 if ( incidenceStart.addSecs( secs ) < alarmStart ) { 580 if ( incidenceStart.addSecs( secs ) < alarmStart ) {
580 alarmStart = incidenceStart.addSecs( secs ); 581 alarmStart = incidenceStart.addSecs( secs );
581 enabled = true; 582 enabled = true;
582 off = -secs; 583 off = -secs;
583 } 584 }
584 } 585 }
585 } 586 }
586 } 587 }
587 if ( enabled ) { 588 if ( enabled ) {
588 if ( alarmStart > start_dt ) { 589 if ( alarmStart > start_dt ) {
589 *ok = true; 590 *ok = true;
590 * offset = off; 591 * offset = off;
591 return alarmStart; 592 return alarmStart;
592 } 593 }
593 } 594 }
594 *ok = false; 595 *ok = false;
595 return QDateTime (); 596 return QDateTime ();
596 597
597} 598}
598 599
599void Todo::checkSetCompletedFalse() 600void Todo::checkSetCompletedFalse()
600{ 601{
601 if ( !mHasRecurrenceID ) { 602 if ( !mHasRecurrenceID ) {
602 qDebug("ERROR 1 in Todo::checkSetCompletedFalse"); 603 qDebug("ERROR 1 in Todo::checkSetCompletedFalse");
603 return; 604 return;
604 } 605 }
605 // qDebug("Todo::checkSetCompletedFalse()"); 606 // qDebug("Todo::checkSetCompletedFalse()");
606 //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); 607 //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() );
607 if ( mPercentComplete == 100 ) { 608 if ( mPercentComplete == 100 ) {
608 QDateTime dt = QDateTime::currentDateTime(); 609 QDateTime dt = QDateTime::currentDateTime();
609 if ( dt > mDtStart && dt > mRecurrenceID ) { 610 if ( dt > mDtStart && dt > mRecurrenceID ) {
610 qDebug("start: %s --due: %s --recID: %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); 611 qDebug("start: %s --due: %s --recID: %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() );
611 setCompleted( false ); 612 setCompleted( false );
612 qDebug("Todo::checkSetCompletedFalse "); 613 qDebug("Todo::checkSetCompletedFalse ");
613 } 614 }
614 } 615 }
615} 616}