summaryrefslogtreecommitdiffabout
path: root/libkcal/calendarlocal.cpp
Unidiff
Diffstat (limited to 'libkcal/calendarlocal.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/calendarlocal.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp
index 8c4dde1..18f1af8 100644
--- a/libkcal/calendarlocal.cpp
+++ b/libkcal/calendarlocal.cpp
@@ -1,919 +1,925 @@
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 if ( mDeleteIncidencesOnClose ) 68 if ( mDeleteIncidencesOnClose )
69 close(); 69 close();
70} 70}
71bool CalendarLocal::addCalendarFile( QString name, int id ) 71bool CalendarLocal::addCalendarFile( QString name, int id )
72{ 72{
73 CalendarLocal calendar( timeZoneId() ); 73 CalendarLocal calendar( timeZoneId() );
74 calendar.setDefaultCalendar( id ); 74 calendar.setDefaultCalendar( id );
75 if ( calendar.load( name ) ) { 75 if ( calendar.load( name ) ) {
76 addCalendar( &calendar ); 76 addCalendar( &calendar );
77 return true; 77 return true;
78 } 78 }
79 return false; 79 return false;
80} 80}
81void CalendarLocal::setSyncEventsReadOnly() 81void CalendarLocal::setSyncEventsReadOnly()
82{ 82{
83 Event * ev; 83 Event * ev;
84 ev = mEventList.first(); 84 ev = mEventList.first();
85 while ( ev ) { 85 while ( ev ) {
86 if ( ev->uid().left(15) == QString("last-syncEvent-") ) 86 if ( ev->uid().left(15) == QString("last-syncEvent-") )
87 ev->setReadOnly( true ); 87 ev->setReadOnly( true );
88 ev = mEventList.next(); 88 ev = mEventList.next();
89 } 89 }
90} 90}
91void CalendarLocal::addCalendar( Calendar* cal ) 91void CalendarLocal::addCalendar( Calendar* cal )
92{ 92{
93 cal->setDontDeleteIncidencesOnClose(); 93 cal->setDontDeleteIncidencesOnClose();
94 { 94 {
95 QPtrList<Event> EventList = cal->rawEvents(); 95 QPtrList<Event> EventList = cal->rawEvents();
96 Event * ev = EventList.first(); 96 Event * ev = EventList.first();
97 while ( ev ) { 97 while ( ev ) {
98 ev->unRegisterObserver( cal ); 98 ev->unRegisterObserver( cal );
99 ev->registerObserver( this ); 99 ev->registerObserver( this );
100 mEventList.append( ev ); 100 mEventList.append( ev );
101 ev = EventList.next(); 101 ev = EventList.next();
102 } 102 }
103 } 103 }
104 { 104 {
105 105
106 QPtrList<Todo> TodoList = cal->rawTodos(); 106 QPtrList<Todo> TodoList = cal->rawTodos();
107 Todo * ev = TodoList.first(); 107 Todo * ev = TodoList.first();
108 while ( ev ) { 108 while ( ev ) {
109 QString rel = ev->relatedToUid(); 109 QString rel = ev->relatedToUid();
110 if ( !rel.isEmpty() ){ 110 if ( !rel.isEmpty() ){
111 ev->setRelatedTo ( 0 ); 111 ev->setRelatedTo ( 0 );
112 ev->setRelatedToUid( rel ); 112 ev->setRelatedToUid( rel );
113 } 113 }
114 ev = TodoList.next(); 114 ev = TodoList.next();
115 } 115 }
116 //TodoList = cal->rawTodos(); 116 //TodoList = cal->rawTodos();
117 ev = TodoList.first(); 117 ev = TodoList.first();
118 while ( ev ) { 118 while ( ev ) {
119 ev->unRegisterObserver( cal ); 119 ev->unRegisterObserver( cal );
120 ev->registerObserver( this ); 120 ev->registerObserver( this );
121 mTodoList.append( ev ); 121 mTodoList.append( ev );
122 setupRelations( ev ); 122 setupRelations( ev );
123 ev = TodoList.next(); 123 ev = TodoList.next();
124 } 124 }
125 } 125 }
126 { 126 {
127 QPtrList<Journal> JournalList = cal->journals(); 127 QPtrList<Journal> JournalList = cal->journals();
128 Journal * ev = JournalList.first(); 128 Journal * ev = JournalList.first();
129 while ( ev ) { 129 while ( ev ) {
130 ev->unRegisterObserver( cal ); 130 ev->unRegisterObserver( cal );
131 ev->registerObserver( this ); 131 ev->registerObserver( this );
132 mJournalList.append( ev ); 132 mJournalList.append( ev );
133 ev = JournalList.next(); 133 ev = JournalList.next();
134 } 134 }
135 } 135 }
136 setModified( true ); 136 setModified( true );
137} 137}
138bool CalendarLocal::load( const QString &fileName ) 138bool CalendarLocal::load( const QString &fileName )
139{ 139{
140 FileStorage storage( this, fileName ); 140 FileStorage storage( this, fileName );
141 return storage.load(); 141 return storage.load();
142} 142}
143 143
144bool CalendarLocal::save( const QString &fileName, CalFormat *format ) 144bool CalendarLocal::save( const QString &fileName, CalFormat *format )
145{ 145{
146 FileStorage storage( this, fileName, format ); 146 FileStorage storage( this, fileName, format );
147 return storage.save(); 147 return storage.save();
148} 148}
149 149
150void CalendarLocal::stopAllTodos()
151{
152 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
153 it->setRunning( false );
154
155}
150void CalendarLocal::close() 156void CalendarLocal::close()
151{ 157{
152 158
153 Todo * i; 159 Todo * i;
154 for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); 160 for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false);
155 161
156 mEventList.setAutoDelete( true ); 162 mEventList.setAutoDelete( true );
157 mTodoList.setAutoDelete( true ); 163 mTodoList.setAutoDelete( true );
158 mJournalList.setAutoDelete( false ); 164 mJournalList.setAutoDelete( false );
159 165
160 mEventList.clear(); 166 mEventList.clear();
161 mTodoList.clear(); 167 mTodoList.clear();
162 mJournalList.clear(); 168 mJournalList.clear();
163 169
164 mEventList.setAutoDelete( false ); 170 mEventList.setAutoDelete( false );
165 mTodoList.setAutoDelete( false ); 171 mTodoList.setAutoDelete( false );
166 mJournalList.setAutoDelete( false ); 172 mJournalList.setAutoDelete( false );
167 173
168 setModified( false ); 174 setModified( false );
169} 175}
170 176
171bool CalendarLocal::addAnniversaryNoDup( Event *event ) 177bool CalendarLocal::addAnniversaryNoDup( Event *event )
172{ 178{
173 QString cat; 179 QString cat;
174 bool isBirthday = true; 180 bool isBirthday = true;
175 if( event->categoriesStr() == i18n( "Anniversary" ) ) { 181 if( event->categoriesStr() == i18n( "Anniversary" ) ) {
176 isBirthday = false; 182 isBirthday = false;
177 cat = i18n( "Anniversary" ); 183 cat = i18n( "Anniversary" );
178 } else if( event->categoriesStr() == i18n( "Birthday" ) ) { 184 } else if( event->categoriesStr() == i18n( "Birthday" ) ) {
179 isBirthday = true; 185 isBirthday = true;
180 cat = i18n( "Birthday" ); 186 cat = i18n( "Birthday" );
181 } else { 187 } else {
182 qDebug("addAnniversaryNoDup called without fitting category! "); 188 qDebug("addAnniversaryNoDup called without fitting category! ");
183 return false; 189 return false;
184 } 190 }
185 Event * eve; 191 Event * eve;
186 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 192 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
187 if ( !(eve->categories().contains( cat ) )) 193 if ( !(eve->categories().contains( cat ) ))
188 continue; 194 continue;
189 // now we have an event with fitting category 195 // now we have an event with fitting category
190 if ( eve->dtStart().date() != event->dtStart().date() ) 196 if ( eve->dtStart().date() != event->dtStart().date() )
191 continue; 197 continue;
192 // now we have an event with fitting category+date 198 // now we have an event with fitting category+date
193 if ( eve->summary() != event->summary() ) 199 if ( eve->summary() != event->summary() )
194 continue; 200 continue;
195 // now we have an event with fitting category+date+summary 201 // now we have an event with fitting category+date+summary
196 return false; 202 return false;
197 } 203 }
198 return addEvent( event ); 204 return addEvent( event );
199 205
200} 206}
201bool CalendarLocal::addEventNoDup( Event *event ) 207bool CalendarLocal::addEventNoDup( Event *event )
202{ 208{
203 Event * eve; 209 Event * eve;
204 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 210 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
205 if ( *eve == *event ) { 211 if ( *eve == *event ) {
206 //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); 212 //qDebug("CalendarLocal::Duplicate event found! Not inserted! ");
207 return false; 213 return false;
208 } 214 }
209 } 215 }
210 return addEvent( event ); 216 return addEvent( event );
211} 217}
212 218
213bool CalendarLocal::addEvent( Event *event ) 219bool CalendarLocal::addEvent( Event *event )
214{ 220{
215 insertEvent( event ); 221 insertEvent( event );
216 222
217 event->registerObserver( this ); 223 event->registerObserver( this );
218 224
219 setModified( true ); 225 setModified( true );
220 event->setCalID( mDefaultCalendar ); 226 event->setCalID( mDefaultCalendar );
221 event->setCalEnabled( true ); 227 event->setCalEnabled( true );
222 228
223 return true; 229 return true;
224} 230}
225 231
226void CalendarLocal::deleteEvent( Event *event ) 232void CalendarLocal::deleteEvent( Event *event )
227{ 233{
228 if ( mUndoIncidence ) delete mUndoIncidence; 234 if ( mUndoIncidence ) delete mUndoIncidence;
229 mUndoIncidence = event->clone(); 235 mUndoIncidence = event->clone();
230 if ( mEventList.removeRef( event ) ) { 236 if ( mEventList.removeRef( event ) ) {
231 setModified( true ); 237 setModified( true );
232 } 238 }
233} 239}
234 240
235 241
236Event *CalendarLocal::event( const QString &uid ) 242Event *CalendarLocal::event( const QString &uid )
237{ 243{
238 Event *event; 244 Event *event;
239 Event *retVal = 0; 245 Event *retVal = 0;
240 for ( event = mEventList.first(); event; event = mEventList.next() ) { 246 for ( event = mEventList.first(); event; event = mEventList.next() ) {
241 if ( event->calEnabled() && event->uid() == uid ) { 247 if ( event->calEnabled() && event->uid() == uid ) {
242 if ( retVal ) { 248 if ( retVal ) {
243 if ( retVal->calID() > event->calID() ) { 249 if ( retVal->calID() > event->calID() ) {
244 retVal = event; 250 retVal = event;
245 } 251 }
246 } else { 252 } else {
247 retVal = event; 253 retVal = event;
248 } 254 }
249 } 255 }
250 } 256 }
251 return retVal; 257 return retVal;
252} 258}
253bool CalendarLocal::addTodoNoDup( Todo *todo ) 259bool CalendarLocal::addTodoNoDup( Todo *todo )
254{ 260{
255 Todo * eve; 261 Todo * eve;
256 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { 262 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) {
257 if ( *eve == *todo ) { 263 if ( *eve == *todo ) {
258 //qDebug("duplicate todo found! not inserted! "); 264 //qDebug("duplicate todo found! not inserted! ");
259 return false; 265 return false;
260 } 266 }
261 } 267 }
262 return addTodo( todo ); 268 return addTodo( todo );
263} 269}
264bool CalendarLocal::addTodo( Todo *todo ) 270bool CalendarLocal::addTodo( Todo *todo )
265{ 271{
266 mTodoList.append( todo ); 272 mTodoList.append( todo );
267 273
268 todo->registerObserver( this ); 274 todo->registerObserver( this );
269 275
270 // Set up subtask relations 276 // Set up subtask relations
271 setupRelations( todo ); 277 setupRelations( todo );
272 278
273 setModified( true ); 279 setModified( true );
274 todo->setCalID( mDefaultCalendar ); 280 todo->setCalID( mDefaultCalendar );
275 todo->setCalEnabled( true ); 281 todo->setCalEnabled( true );
276 return true; 282 return true;
277} 283}
278 284
279void CalendarLocal::deleteTodo( Todo *todo ) 285void CalendarLocal::deleteTodo( Todo *todo )
280{ 286{
281 // Handle orphaned children 287 // Handle orphaned children
282 if ( mUndoIncidence ) delete mUndoIncidence; 288 if ( mUndoIncidence ) delete mUndoIncidence;
283 removeRelations( todo ); 289 removeRelations( todo );
284 mUndoIncidence = todo->clone(); 290 mUndoIncidence = todo->clone();
285 291
286 if ( mTodoList.removeRef( todo ) ) { 292 if ( mTodoList.removeRef( todo ) ) {
287 setModified( true ); 293 setModified( true );
288 } 294 }
289} 295}
290 296
291QPtrList<Todo> CalendarLocal::rawTodos() 297QPtrList<Todo> CalendarLocal::rawTodos()
292{ 298{
293 QPtrList<Todo> el; 299 QPtrList<Todo> el;
294 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 300 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
295 if ( it->calEnabled() ) el.append( it ); 301 if ( it->calEnabled() ) el.append( it );
296 return el; 302 return el;
297} 303}
298Todo *CalendarLocal::todo( QString syncProf, QString id ) 304Todo *CalendarLocal::todo( QString syncProf, QString id )
299{ 305{
300 Todo *todo; 306 Todo *todo;
301 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 307 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
302 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; 308 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo;
303 } 309 }
304 310
305 return 0; 311 return 0;
306} 312}
307void CalendarLocal::removeSyncInfo( QString syncProfile) 313void CalendarLocal::removeSyncInfo( QString syncProfile)
308{ 314{
309 QPtrList<Incidence> all = rawIncidences() ; 315 QPtrList<Incidence> all = rawIncidences() ;
310 Incidence *inc; 316 Incidence *inc;
311 for ( inc = all.first(); inc; inc = all.next() ) { 317 for ( inc = all.first(); inc; inc = all.next() ) {
312 inc->removeID( syncProfile ); 318 inc->removeID( syncProfile );
313 } 319 }
314 if ( syncProfile.isEmpty() ) { 320 if ( syncProfile.isEmpty() ) {
315 QPtrList<Event> el; 321 QPtrList<Event> el;
316 Event *todo; 322 Event *todo;
317 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 323 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
318 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) 324 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
319 el.append( todo ); 325 el.append( todo );
320 } 326 }
321 for ( todo = el.first(); todo; todo = el.next() ) { 327 for ( todo = el.first(); todo; todo = el.next() ) {
322 deleteIncidence ( todo ); 328 deleteIncidence ( todo );
323 } 329 }
324 } else { 330 } else {
325 Event *lse = event( "last-syncEvent-"+ syncProfile); 331 Event *lse = event( "last-syncEvent-"+ syncProfile);
326 if ( lse ) 332 if ( lse )
327 deleteIncidence ( lse ); 333 deleteIncidence ( lse );
328 } 334 }
329} 335}
330QPtrList<Event> CalendarLocal::getExternLastSyncEvents() 336QPtrList<Event> CalendarLocal::getExternLastSyncEvents()
331{ 337{
332 QPtrList<Event> el; 338 QPtrList<Event> el;
333 Event *todo; 339 Event *todo;
334 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 340 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
335 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) 341 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
336 if ( todo->summary().left(3) == "E: " ) 342 if ( todo->summary().left(3) == "E: " )
337 el.append( todo ); 343 el.append( todo );
338 } 344 }
339 345
340 return el; 346 return el;
341 347
342} 348}
343Event *CalendarLocal::event( QString syncProf, QString id ) 349Event *CalendarLocal::event( QString syncProf, QString id )
344{ 350{
345 Event *todo; 351 Event *todo;
346 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 352 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
347 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; 353 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo;
348 } 354 }
349 355
350 return 0; 356 return 0;
351} 357}
352Todo *CalendarLocal::todo( const QString &uid ) 358Todo *CalendarLocal::todo( const QString &uid )
353{ 359{
354 Todo *todo;; 360 Todo *todo;;
355 Todo *retVal = 0; 361 Todo *retVal = 0;
356 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 362 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
357 if ( todo->calEnabled() && todo->uid() == uid ) { 363 if ( todo->calEnabled() && todo->uid() == uid ) {
358 if ( retVal ) { 364 if ( retVal ) {
359 if ( retVal->calID() > todo->calID() ) { 365 if ( retVal->calID() > todo->calID() ) {
360 retVal = todo; 366 retVal = todo;
361 } 367 }
362 } else { 368 } else {
363 retVal = todo; 369 retVal = todo;
364 } 370 }
365 } 371 }
366 } 372 }
367 return retVal; 373 return retVal;
368} 374}
369QString CalendarLocal::nextSummary() const 375QString CalendarLocal::nextSummary() const
370{ 376{
371 return mNextSummary; 377 return mNextSummary;
372} 378}
373QDateTime CalendarLocal::nextAlarmEventDateTime() const 379QDateTime CalendarLocal::nextAlarmEventDateTime() const
374{ 380{
375 return mNextAlarmEventDateTime; 381 return mNextAlarmEventDateTime;
376} 382}
377void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) 383void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted)
378{ 384{
379 //mNextAlarmIncidence 385 //mNextAlarmIncidence
380 //mNextAlarmDateTime 386 //mNextAlarmDateTime
381 //return mNextSummary; 387 //return mNextSummary;
382 //return mNextAlarmEventDateTime; 388 //return mNextAlarmEventDateTime;
383 bool newNextAlarm = false; 389 bool newNextAlarm = false;
384 bool computeNextAlarm = false; 390 bool computeNextAlarm = false;
385 bool ok; 391 bool ok;
386 int offset; 392 int offset;
387 QDateTime nextA; 393 QDateTime nextA;
388 // QString nextSum; 394 // QString nextSum;
389 //QDateTime nextEvent; 395 //QDateTime nextEvent;
390 if ( mNextAlarmIncidence == 0 || incidence == 0 ) { 396 if ( mNextAlarmIncidence == 0 || incidence == 0 ) {
391 computeNextAlarm = true; 397 computeNextAlarm = true;
392 } else { 398 } else {
393 if ( ! deleted ) { 399 if ( ! deleted ) {
394 nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; 400 nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
395 if ( ok ) { 401 if ( ok ) {
396 if ( nextA < mNextAlarmDateTime ) { 402 if ( nextA < mNextAlarmDateTime ) {
397 deRegisterAlarm(); 403 deRegisterAlarm();
398 mNextAlarmDateTime = nextA; 404 mNextAlarmDateTime = nextA;
399 mNextSummary = incidence->summary(); 405 mNextSummary = incidence->summary();
400 mNextAlarmEventDateTime = nextA.addSecs(offset ) ; 406 mNextAlarmEventDateTime = nextA.addSecs(offset ) ;
401 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); 407 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime);
402 newNextAlarm = true; 408 newNextAlarm = true;
403 mNextAlarmIncidence = incidence; 409 mNextAlarmIncidence = incidence;
404 } else { 410 } else {
405 if ( incidence == mNextAlarmIncidence ) { 411 if ( incidence == mNextAlarmIncidence ) {
406 computeNextAlarm = true; 412 computeNextAlarm = true;
407 } 413 }
408 } 414 }
409 } else { 415 } else {
410 if ( mNextAlarmIncidence == incidence ) { 416 if ( mNextAlarmIncidence == incidence ) {
411 computeNextAlarm = true; 417 computeNextAlarm = true;
412 } 418 }
413 } 419 }
414 } else { // deleted 420 } else { // deleted
415 if ( incidence == mNextAlarmIncidence ) { 421 if ( incidence == mNextAlarmIncidence ) {
416 computeNextAlarm = true; 422 computeNextAlarm = true;
417 } 423 }
418 } 424 }
419 } 425 }
420 if ( computeNextAlarm ) { 426 if ( computeNextAlarm ) {
421 deRegisterAlarm(); 427 deRegisterAlarm();
422 nextA = nextAlarm( 1000 ); 428 nextA = nextAlarm( 1000 );
423 if (! mNextAlarmIncidence ) { 429 if (! mNextAlarmIncidence ) {
424 return; 430 return;
425 } 431 }
426 newNextAlarm = true; 432 newNextAlarm = true;
427 } 433 }
428 if ( newNextAlarm ) 434 if ( newNextAlarm )
429 registerAlarm(); 435 registerAlarm();
430} 436}
431QString CalendarLocal:: getAlarmNotification() 437QString CalendarLocal:: getAlarmNotification()
432{ 438{
433 QString ret; 439 QString ret;
434 // this should not happen 440 // this should not happen
435 if (! mNextAlarmIncidence ) 441 if (! mNextAlarmIncidence )
436 return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; 442 return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString;
437 Alarm* alarm = mNextAlarmIncidence->alarms().first(); 443 Alarm* alarm = mNextAlarmIncidence->alarms().first();
438 if ( alarm->type() == Alarm::Procedure ) { 444 if ( alarm->type() == Alarm::Procedure ) {
439 ret = "proc_alarm" + alarm->programFile()+"+++"; 445 ret = "proc_alarm" + alarm->programFile()+"+++";
440 } else { 446 } else {
441 ret = "audio_alarm" +alarm->audioFile() +"+++"; 447 ret = "audio_alarm" +alarm->audioFile() +"+++";
442 } 448 }
443 ret += "cal_alarm"+ mNextSummary.left( 25 ); 449 ret += "cal_alarm"+ mNextSummary.left( 25 );
444 if ( mNextSummary.length() > 25 ) 450 if ( mNextSummary.length() > 25 )
445 ret += "\n" + mNextSummary.mid(25, 25 ); 451 ret += "\n" + mNextSummary.mid(25, 25 );
446 ret+= "\n"+mNextAlarmEventDateTimeString; 452 ret+= "\n"+mNextAlarmEventDateTimeString;
447 return ret; 453 return ret;
448} 454}
449void CalendarLocal::registerAlarm() 455void CalendarLocal::registerAlarm()
450{ 456{
451 mLastAlarmNotificationString = getAlarmNotification(); 457 mLastAlarmNotificationString = getAlarmNotification();
452 // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); 458 // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() );
453 emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); 459 emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString );
454// #ifndef DESKTOP_VERSION 460// #ifndef DESKTOP_VERSION
455// AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); 461// AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() );
456// #endif 462// #endif
457} 463}
458void CalendarLocal::deRegisterAlarm() 464void CalendarLocal::deRegisterAlarm()
459{ 465{
460 if ( mLastAlarmNotificationString.isNull() ) 466 if ( mLastAlarmNotificationString.isNull() )
461 return; 467 return;
462 //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); 468 //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() );
463 469
464 emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); 470 emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString );
465 mNextAlarmEventDateTime = QDateTime(); 471 mNextAlarmEventDateTime = QDateTime();
466// #ifndef DESKTOP_VERSION 472// #ifndef DESKTOP_VERSION
467// AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); 473// AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() );
468// #endif 474// #endif
469} 475}
470 476
471QPtrList<Todo> CalendarLocal::todos( const QDate &date ) 477QPtrList<Todo> CalendarLocal::todos( const QDate &date )
472{ 478{
473 QPtrList<Todo> todos; 479 QPtrList<Todo> todos;
474 480
475 Todo *todo; 481 Todo *todo;
476 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 482 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
477 if ( !todo->calEnabled() ) continue; 483 if ( !todo->calEnabled() ) continue;
478 if ( todo->hasDueDate() && todo->dtDue().date() == date ) { 484 if ( todo->hasDueDate() && todo->dtDue().date() == date ) {
479 todos.append( todo ); 485 todos.append( todo );
480 } 486 }
481 } 487 }
482 488
483 filter()->apply( &todos ); 489 filter()->apply( &todos );
484 return todos; 490 return todos;
485} 491}
486void CalendarLocal::reInitAlarmSettings() 492void CalendarLocal::reInitAlarmSettings()
487{ 493{
488 if ( !mNextAlarmIncidence ) { 494 if ( !mNextAlarmIncidence ) {
489 nextAlarm( 1000 ); 495 nextAlarm( 1000 );
490 } 496 }
491 deRegisterAlarm(); 497 deRegisterAlarm();
492 mNextAlarmIncidence = 0; 498 mNextAlarmIncidence = 0;
493 checkAlarmForIncidence( 0, false ); 499 checkAlarmForIncidence( 0, false );
494 500
495} 501}
496 502
497 503
498 504
499QDateTime CalendarLocal::nextAlarm( int daysTo ) 505QDateTime CalendarLocal::nextAlarm( int daysTo )
500{ 506{
501 QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); 507 QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo );
502 QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); 508 QDateTime start = QDateTime::currentDateTime().addSecs( 30 );
503 QDateTime next; 509 QDateTime next;
504 Event *e; 510 Event *e;
505 bool ok; 511 bool ok;
506 bool found = false; 512 bool found = false;
507 int offset; 513 int offset;
508 mNextAlarmIncidence = 0; 514 mNextAlarmIncidence = 0;
509 for( e = mEventList.first(); e; e = mEventList.next() ) { 515 for( e = mEventList.first(); e; e = mEventList.next() ) {
510 if ( !e->calEnabled() ) continue; 516 if ( !e->calEnabled() ) continue;
511 next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; 517 next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
512 if ( ok ) { 518 if ( ok ) {
513 if ( next < nextA ) { 519 if ( next < nextA ) {
514 nextA = next; 520 nextA = next;
515 found = true; 521 found = true;
516 mNextSummary = e->summary(); 522 mNextSummary = e->summary();
517 mNextAlarmEventDateTime = next.addSecs(offset ) ; 523 mNextAlarmEventDateTime = next.addSecs(offset ) ;
518 mNextAlarmIncidence = (Incidence *) e; 524 mNextAlarmIncidence = (Incidence *) e;
519 } 525 }
520 } 526 }
521 } 527 }
522 Todo *t; 528 Todo *t;
523 for( t = mTodoList.first(); t; t = mTodoList.next() ) { 529 for( t = mTodoList.first(); t; t = mTodoList.next() ) {
524 if ( !t->calEnabled() ) continue; 530 if ( !t->calEnabled() ) continue;
525 next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; 531 next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
526 if ( ok ) { 532 if ( ok ) {
527 if ( next < nextA ) { 533 if ( next < nextA ) {
528 nextA = next; 534 nextA = next;
529 found = true; 535 found = true;
530 mNextSummary = t->summary(); 536 mNextSummary = t->summary();
531 mNextAlarmEventDateTime = next.addSecs(offset ); 537 mNextAlarmEventDateTime = next.addSecs(offset );
532 mNextAlarmIncidence = (Incidence *) t; 538 mNextAlarmIncidence = (Incidence *) t;
533 } 539 }
534 } 540 }
535 } 541 }
536 if ( mNextAlarmIncidence ) { 542 if ( mNextAlarmIncidence ) {
537 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); 543 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime);
538 mNextAlarmDateTime = nextA; 544 mNextAlarmDateTime = nextA;
539 } 545 }
540 return nextA; 546 return nextA;
541} 547}
542Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) 548Alarm::List CalendarLocal::alarmsTo( const QDateTime &to )
543{ 549{
544 return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); 550 return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to );
545} 551}
546 552
547Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) 553Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to )
548{ 554{
549 555
550 Alarm::List alarms; 556 Alarm::List alarms;
551 557
552 Event *e; 558 Event *e;
553 559
554 for( e = mEventList.first(); e; e = mEventList.next() ) { 560 for( e = mEventList.first(); e; e = mEventList.next() ) {
555 if ( !e->calEnabled() ) continue; 561 if ( !e->calEnabled() ) continue;
556 if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); 562 if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to );
557 else appendAlarms( alarms, e, from, to ); 563 else appendAlarms( alarms, e, from, to );
558 } 564 }
559 565
560 Todo *t; 566 Todo *t;
561 for( t = mTodoList.first(); t; t = mTodoList.next() ) { 567 for( t = mTodoList.first(); t; t = mTodoList.next() ) {
562 if ( !t->calEnabled() ) continue; 568 if ( !t->calEnabled() ) continue;
563 appendAlarms( alarms, t, from, to ); 569 appendAlarms( alarms, t, from, to );
564 } 570 }
565 571
566 return alarms; 572 return alarms;
567} 573}
568 574
569void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, 575void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence,
570 const QDateTime &from, const QDateTime &to ) 576 const QDateTime &from, const QDateTime &to )
571{ 577{
572 QPtrList<Alarm> alarmList = incidence->alarms(); 578 QPtrList<Alarm> alarmList = incidence->alarms();
573 Alarm *alarm; 579 Alarm *alarm;
574 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { 580 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) {
575// kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() 581// kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text()
576// << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; 582// << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl;
577 if ( alarm->enabled() ) { 583 if ( alarm->enabled() ) {
578 if ( alarm->time() >= from && alarm->time() <= to ) { 584 if ( alarm->time() >= from && alarm->time() <= to ) {
579 alarms.append( alarm ); 585 alarms.append( alarm );
580 } 586 }
581 } 587 }
582 } 588 }
583} 589}
584 590
585void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, 591void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms,
586 Incidence *incidence, 592 Incidence *incidence,
587 const QDateTime &from, 593 const QDateTime &from,
588 const QDateTime &to ) 594 const QDateTime &to )
589{ 595{
590 596
591 QPtrList<Alarm> alarmList = incidence->alarms(); 597 QPtrList<Alarm> alarmList = incidence->alarms();
592 Alarm *alarm; 598 Alarm *alarm;
593 QDateTime qdt; 599 QDateTime qdt;
594 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { 600 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) {
595 if (incidence->recursOn(from.date())) { 601 if (incidence->recursOn(from.date())) {
596 qdt.setTime(alarm->time().time()); 602 qdt.setTime(alarm->time().time());
597 qdt.setDate(from.date()); 603 qdt.setDate(from.date());
598 } 604 }
599 else qdt = alarm->time(); 605 else qdt = alarm->time();
600 // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); 606 // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1());
601 if ( alarm->enabled() ) { 607 if ( alarm->enabled() ) {
602 if ( qdt >= from && qdt <= to ) { 608 if ( qdt >= from && qdt <= to ) {
603 alarms.append( alarm ); 609 alarms.append( alarm );
604 } 610 }
605 } 611 }
606 } 612 }
607} 613}
608 614
609 615
610/****************************** PROTECTED METHODS ****************************/ 616/****************************** PROTECTED METHODS ****************************/
611 617
612// after changes are made to an event, this should be called. 618// after changes are made to an event, this should be called.
613void CalendarLocal::update( IncidenceBase *incidence ) 619void CalendarLocal::update( IncidenceBase *incidence )
614{ 620{
615 incidence->setSyncStatus( Event::SYNCMOD ); 621 incidence->setSyncStatus( Event::SYNCMOD );
616 incidence->setLastModified( QDateTime::currentDateTime() ); 622 incidence->setLastModified( QDateTime::currentDateTime() );
617 // we should probably update the revision number here, 623 // we should probably update the revision number here,
618 // or internally in the Event itself when certain things change. 624 // or internally in the Event itself when certain things change.
619 // need to verify with ical documentation. 625 // need to verify with ical documentation.
620 626
621 setModified( true ); 627 setModified( true );
622} 628}
623 629
624void CalendarLocal::insertEvent( Event *event ) 630void CalendarLocal::insertEvent( Event *event )
625{ 631{
626 if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); 632 if ( mEventList.findRef( event ) < 0 ) mEventList.append( event );
627} 633}
628 634
629 635
630QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) 636QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted )
631{ 637{
632 QPtrList<Event> eventList; 638 QPtrList<Event> eventList;
633 639
634 Event *event; 640 Event *event;
635 for( event = mEventList.first(); event; event = mEventList.next() ) { 641 for( event = mEventList.first(); event; event = mEventList.next() ) {
636 if ( !event->calEnabled() ) continue; 642 if ( !event->calEnabled() ) continue;
637 if ( event->doesRecur() ) { 643 if ( event->doesRecur() ) {
638 if ( event->isMultiDay() ) { 644 if ( event->isMultiDay() ) {
639 int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); 645 int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() );
640 int i; 646 int i;
641 for ( i = 0; i <= extraDays; i++ ) { 647 for ( i = 0; i <= extraDays; i++ ) {
642 if ( event->recursOn( qd.addDays( -i ) ) ) { 648 if ( event->recursOn( qd.addDays( -i ) ) ) {
643 eventList.append( event ); 649 eventList.append( event );
644 break; 650 break;
645 } 651 }
646 } 652 }
647 } else { 653 } else {
648 if ( event->recursOn( qd ) ) 654 if ( event->recursOn( qd ) )
649 eventList.append( event ); 655 eventList.append( event );
650 } 656 }
651 } else { 657 } else {
652 if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { 658 if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) {
653 eventList.append( event ); 659 eventList.append( event );
654 } 660 }
655 } 661 }
656 } 662 }
657 663
658 if ( !sorted ) { 664 if ( !sorted ) {
659 return eventList; 665 return eventList;
660 } 666 }
661 667
662 // kdDebug(5800) << "Sorting events for date\n" << endl; 668 // kdDebug(5800) << "Sorting events for date\n" << endl;
663 // now, we have to sort it based on dtStart.time() 669 // now, we have to sort it based on dtStart.time()
664 QPtrList<Event> eventListSorted; 670 QPtrList<Event> eventListSorted;
665 Event *sortEvent; 671 Event *sortEvent;
666 for ( event = eventList.first(); event; event = eventList.next() ) { 672 for ( event = eventList.first(); event; event = eventList.next() ) {
667 sortEvent = eventListSorted.first(); 673 sortEvent = eventListSorted.first();
668 int i = 0; 674 int i = 0;
669 while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) 675 while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() )
670 { 676 {
671 i++; 677 i++;
672 sortEvent = eventListSorted.next(); 678 sortEvent = eventListSorted.next();
673 } 679 }
674 eventListSorted.insert( i, event ); 680 eventListSorted.insert( i, event );
675 } 681 }
676 return eventListSorted; 682 return eventListSorted;
677} 683}
678 684
679 685
680QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, 686QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end,
681 bool inclusive ) 687 bool inclusive )
682{ 688{
683 Event *event = 0; 689 Event *event = 0;
684 690
685 QPtrList<Event> eventList; 691 QPtrList<Event> eventList;
686 692
687 // Get non-recurring events 693 // Get non-recurring events
688 for( event = mEventList.first(); event; event = mEventList.next() ) { 694 for( event = mEventList.first(); event; event = mEventList.next() ) {
689 if ( !event->calEnabled() ) continue; 695 if ( !event->calEnabled() ) continue;
690 if ( event->doesRecur() ) { 696 if ( event->doesRecur() ) {
691 QDate rStart = event->dtStart().date(); 697 QDate rStart = event->dtStart().date();
692 bool found = false; 698 bool found = false;
693 if ( inclusive ) { 699 if ( inclusive ) {
694 if ( rStart >= start && rStart <= end ) { 700 if ( rStart >= start && rStart <= end ) {
695 // Start date of event is in range. Now check for end date. 701 // Start date of event is in range. Now check for end date.
696 // if duration is negative, event recurs forever, so do not include it. 702 // if duration is negative, event recurs forever, so do not include it.
697 if ( event->recurrence()->duration() == 0 ) { // End date set 703 if ( event->recurrence()->duration() == 0 ) { // End date set
698 QDate rEnd = event->recurrence()->endDate(); 704 QDate rEnd = event->recurrence()->endDate();
699 if ( rEnd >= start && rEnd <= end ) { // End date within range 705 if ( rEnd >= start && rEnd <= end ) { // End date within range
700 found = true; 706 found = true;
701 } 707 }
702 } else if ( event->recurrence()->duration() > 0 ) { // Duration set 708 } else if ( event->recurrence()->duration() > 0 ) { // Duration set
703 // TODO: Calculate end date from duration. Should be done in Event 709 // TODO: Calculate end date from duration. Should be done in Event
704 // For now exclude all events with a duration. 710 // For now exclude all events with a duration.
705 } 711 }
706 } 712 }
707 } else { 713 } else {
708 bool founOne; 714 bool founOne;
709 QDate next = event->getNextOccurence( start, &founOne ).date(); 715 QDate next = event->getNextOccurence( start, &founOne ).date();
710 if ( founOne ) { 716 if ( founOne ) {
711 if ( next <= end ) { 717 if ( next <= end ) {
712 found = true; 718 found = true;
713 } 719 }
714 } 720 }
715 721
716 /* 722 /*
717 // crap !!! 723 // crap !!!
718 if ( rStart <= end ) { // Start date not after range 724 if ( rStart <= end ) { // Start date not after range
719 if ( rStart >= start ) { // Start date within range 725 if ( rStart >= start ) { // Start date within range
720 found = true; 726 found = true;
721 } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever 727 } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever
722 found = true; 728 found = true;
723 } else if ( event->recurrence()->duration() == 0 ) { // End date set 729 } else if ( event->recurrence()->duration() == 0 ) { // End date set
724 QDate rEnd = event->recurrence()->endDate(); 730 QDate rEnd = event->recurrence()->endDate();
725 if ( rEnd >= start && rEnd <= end ) { // End date within range 731 if ( rEnd >= start && rEnd <= end ) { // End date within range
726 found = true; 732 found = true;
727 } 733 }
728 } else { // Duration set 734 } else { // Duration set
729 // TODO: Calculate end date from duration. Should be done in Event 735 // TODO: Calculate end date from duration. Should be done in Event
730 // For now include all events with a duration. 736 // For now include all events with a duration.
731 found = true; 737 found = true;
732 } 738 }
733 } 739 }
734 */ 740 */
735 741
736 } 742 }
737 743
738 if ( found ) eventList.append( event ); 744 if ( found ) eventList.append( event );
739 } else { 745 } else {
740 QDate s = event->dtStart().date(); 746 QDate s = event->dtStart().date();
741 QDate e = event->dtEnd().date(); 747 QDate e = event->dtEnd().date();
742 748
743 if ( inclusive ) { 749 if ( inclusive ) {
744 if ( s >= start && e <= end ) { 750 if ( s >= start && e <= end ) {
745 eventList.append( event ); 751 eventList.append( event );
746 } 752 }
747 } else { 753 } else {
748 if ( ( s >= start && s <= end ) || ( e >= start && e <= end ) ) { 754 if ( ( s >= start && s <= end ) || ( e >= start && e <= end ) ) {
749 eventList.append( event ); 755 eventList.append( event );
750 } 756 }
751 } 757 }
752 } 758 }
753 } 759 }
754 760
755 return eventList; 761 return eventList;
756} 762}
757 763
758QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) 764QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt )
759{ 765{
760 return rawEventsForDate( qdt.date() ); 766 return rawEventsForDate( qdt.date() );
761} 767}
762 768
763QPtrList<Event> CalendarLocal::rawEvents() 769QPtrList<Event> CalendarLocal::rawEvents()
764{ 770{
765 QPtrList<Event> el; 771 QPtrList<Event> el;
766 for ( Event *it = mEventList.first(); it; it = mEventList.next() ) 772 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
767 if ( it->calEnabled() ) el.append( it ); 773 if ( it->calEnabled() ) el.append( it );
768 return el; 774 return el;
769} 775}
770 776
771bool CalendarLocal::addJournal(Journal *journal) 777bool CalendarLocal::addJournal(Journal *journal)
772{ 778{
773 if ( journal->dtStart().isValid()) 779 if ( journal->dtStart().isValid())
774 kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl; 780 kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl;
775 else 781 else
776 kdDebug(5800) << "Adding Journal without a DTSTART" << endl; 782 kdDebug(5800) << "Adding Journal without a DTSTART" << endl;
777 783
778 mJournalList.append(journal); 784 mJournalList.append(journal);
779 785
780 journal->registerObserver( this ); 786 journal->registerObserver( this );
781 787
782 setModified( true ); 788 setModified( true );
783 journal->setCalID( mDefaultCalendar ); 789 journal->setCalID( mDefaultCalendar );
784 journal->setCalEnabled( true ); 790 journal->setCalEnabled( true );
785 return true; 791 return true;
786} 792}
787 793
788void CalendarLocal::deleteJournal( Journal *journal ) 794void CalendarLocal::deleteJournal( Journal *journal )
789{ 795{
790 if ( mUndoIncidence ) delete mUndoIncidence; 796 if ( mUndoIncidence ) delete mUndoIncidence;
791 mUndoIncidence = journal->clone(); 797 mUndoIncidence = journal->clone();
792 mUndoIncidence->setSummary( mUndoIncidence->description().left(25)); 798 mUndoIncidence->setSummary( mUndoIncidence->description().left(25));
793 if ( mJournalList.removeRef(journal) ) { 799 if ( mJournalList.removeRef(journal) ) {
794 setModified( true ); 800 setModified( true );
795 } 801 }
796} 802}
797 803
798Journal *CalendarLocal::journal( const QDate &date ) 804Journal *CalendarLocal::journal( const QDate &date )
799{ 805{
800// kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; 806// kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl;
801 807
802 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 808 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
803 if ( it->calEnabled() && it->dtStart().date() == date ) 809 if ( it->calEnabled() && it->dtStart().date() == date )
804 return it; 810 return it;
805 811
806 return 0; 812 return 0;
807} 813}
808 814
809Journal *CalendarLocal::journal( const QString &uid ) 815Journal *CalendarLocal::journal( const QString &uid )
810{ 816{
811 Journal * retVal = 0; 817 Journal * retVal = 0;
812 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 818 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
813 if ( it->calEnabled() && it->uid() == uid ) { 819 if ( it->calEnabled() && it->uid() == uid ) {
814 if ( retVal ) { 820 if ( retVal ) {
815 if ( retVal->calID() > it->calID() ) { 821 if ( retVal->calID() > it->calID() ) {
816 retVal = it; 822 retVal = it;
817 } 823 }
818 } else { 824 } else {
819 retVal = it; 825 retVal = it;
820 } 826 }
821 } 827 }
822 return retVal; 828 return retVal;
823} 829}
824 830
825QPtrList<Journal> CalendarLocal::journals() 831QPtrList<Journal> CalendarLocal::journals()
826{ 832{
827 QPtrList<Journal> el; 833 QPtrList<Journal> el;
828 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 834 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
829 if ( it->calEnabled() ) el.append( it ); 835 if ( it->calEnabled() ) el.append( it );
830 return el; 836 return el;
831} 837}
832void CalendarLocal::setCalendarRemove( int id ) 838void CalendarLocal::setCalendarRemove( int id )
833{ 839{
834 840
835 { 841 {
836 QPtrList<Event> EventList = mEventList; 842 QPtrList<Event> EventList = mEventList;
837 Event * ev = EventList.first(); 843 Event * ev = EventList.first();
838 while ( ev ) { 844 while ( ev ) {
839 if ( ev->calID() == id ) 845 if ( ev->calID() == id )
840 deleteEvent( ev ); 846 deleteEvent( ev );
841 ev = EventList.next(); 847 ev = EventList.next();
842 } 848 }
843 } 849 }
844 { 850 {
845 851
846 QPtrList<Todo> TodoList = mTodoList; 852 QPtrList<Todo> TodoList = mTodoList;
847 Todo * ev = TodoList.first(); 853 Todo * ev = TodoList.first();
848 while ( ev ) { 854 while ( ev ) {
849 if ( ev->calID() == id ) 855 if ( ev->calID() == id )
850 deleteTodo( ev ); 856 deleteTodo( ev );
851 ev = TodoList.next(); 857 ev = TodoList.next();
852 } 858 }
853 } 859 }
854 { 860 {
855 QPtrList<Journal> JournalList = mJournalList; 861 QPtrList<Journal> JournalList = mJournalList;
856 Journal * ev = JournalList.first(); 862 Journal * ev = JournalList.first();
857 while ( ev ) { 863 while ( ev ) {
858 if ( ev->calID() == id ) 864 if ( ev->calID() == id )
859 deleteJournal( ev ); 865 deleteJournal( ev );
860 ev = JournalList.next(); 866 ev = JournalList.next();
861 } 867 }
862 } 868 }
863 869
864 if ( mUndoIncidence ) delete mUndoIncidence; 870 if ( mUndoIncidence ) delete mUndoIncidence;
865 mUndoIncidence = 0; 871 mUndoIncidence = 0;
866 872
867} 873}
868 874
869void CalendarLocal::setCalendarEnabled( int id, bool enable ) 875void CalendarLocal::setCalendarEnabled( int id, bool enable )
870{ 876{
871 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 877 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
872 if ( it->calID() == id ) it->setCalEnabled( enable ); 878 if ( it->calID() == id ) it->setCalEnabled( enable );
873 879
874 for ( Event *it = mEventList.first(); it; it = mEventList.next() ) 880 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
875 if ( it->calID() == id ) it->setCalEnabled( enable ); 881 if ( it->calID() == id ) it->setCalEnabled( enable );
876 882
877 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 883 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
878 if ( it->calID() == id ) it->setCalEnabled( enable ); 884 if ( it->calID() == id ) it->setCalEnabled( enable );
879 885
880} 886}
881 887
882void CalendarLocal::setReadOnly( int id, bool enable ) 888void CalendarLocal::setReadOnly( int id, bool enable )
883{ 889{
884 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 890 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
885 if ( it->calID() == id ) it->setReadOnly( enable ); 891 if ( it->calID() == id ) it->setReadOnly( enable );
886 892
887 for ( Event *it = mEventList.first(); it; it = mEventList.next() ) 893 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
888 if ( it->calID() == id ) it->setReadOnly( enable ); 894 if ( it->calID() == id ) it->setReadOnly( enable );
889 895
890 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 896 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
891 if ( it->calID() == id ) it->setReadOnly( enable ); 897 if ( it->calID() == id ) it->setReadOnly( enable );
892 898
893} 899}
894 900
895void CalendarLocal::setAlarmEnabled( int id, bool enable ) 901void CalendarLocal::setAlarmEnabled( int id, bool enable )
896{ 902{
897 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 903 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
898 if ( it->calID() == id ) it->setAlarmEnabled( enable ); 904 if ( it->calID() == id ) it->setAlarmEnabled( enable );
899 905
900 for ( Event *it = mEventList.first(); it; it = mEventList.next() ) 906 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
901 if ( it->calID() == id ) it->setAlarmEnabled( enable ); 907 if ( it->calID() == id ) it->setAlarmEnabled( enable );
902 908
903 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 909 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
904 if ( it->calID() == id ) it->setAlarmEnabled( enable ); 910 if ( it->calID() == id ) it->setAlarmEnabled( enable );
905 reInitAlarmSettings(); 911 reInitAlarmSettings();
906 912
907} 913}
908void CalendarLocal::setDefaultCalendarEnabledOnly() 914void CalendarLocal::setDefaultCalendarEnabledOnly()
909{ 915{
910 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 916 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
911 it->setCalEnabled( it->calID() == mDefaultCalendar ); 917 it->setCalEnabled( it->calID() == mDefaultCalendar );
912 918
913 for ( Event *it = mEventList.first(); it; it = mEventList.next() ) 919 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
914 it->setCalEnabled( it->calID() == mDefaultCalendar); 920 it->setCalEnabled( it->calID() == mDefaultCalendar);
915 921
916 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 922 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
917 it->setCalEnabled( it->calID() == mDefaultCalendar); 923 it->setCalEnabled( it->calID() == mDefaultCalendar);
918 924
919} 925}