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