summaryrefslogtreecommitdiffabout
path: root/libkcal/calendarlocal.cpp
Unidiff
Diffstat (limited to 'libkcal/calendarlocal.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/calendarlocal.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp
index 336c3e8..8c4dde1 100644
--- a/libkcal/calendarlocal.cpp
+++ b/libkcal/calendarlocal.cpp
@@ -1,592 +1,602 @@
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()
82{
83 Event * ev;
84 ev = mEventList.first();
85 while ( ev ) {
86 if ( ev->uid().left(15) == QString("last-syncEvent-") )
87 ev->setReadOnly( true );
88 ev = mEventList.next();
89 }
90}
81void CalendarLocal::addCalendar( Calendar* cal ) 91void CalendarLocal::addCalendar( Calendar* cal )
82{ 92{
83 cal->setDontDeleteIncidencesOnClose(); 93 cal->setDontDeleteIncidencesOnClose();
84 { 94 {
85 QPtrList<Event> EventList = cal->rawEvents(); 95 QPtrList<Event> EventList = cal->rawEvents();
86 Event * ev = EventList.first(); 96 Event * ev = EventList.first();
87 while ( ev ) { 97 while ( ev ) {
88 ev->unRegisterObserver( cal ); 98 ev->unRegisterObserver( cal );
89 ev->registerObserver( this ); 99 ev->registerObserver( this );
90 mEventList.append( ev ); 100 mEventList.append( ev );
91 ev = EventList.next(); 101 ev = EventList.next();
92 } 102 }
93 } 103 }
94 { 104 {
95 105
96 QPtrList<Todo> TodoList = cal->rawTodos(); 106 QPtrList<Todo> TodoList = cal->rawTodos();
97 Todo * ev = TodoList.first(); 107 Todo * ev = TodoList.first();
98 while ( ev ) { 108 while ( ev ) {
99 QString rel = ev->relatedToUid(); 109 QString rel = ev->relatedToUid();
100 if ( !rel.isEmpty() ){ 110 if ( !rel.isEmpty() ){
101 ev->setRelatedTo ( 0 ); 111 ev->setRelatedTo ( 0 );
102 ev->setRelatedToUid( rel ); 112 ev->setRelatedToUid( rel );
103 } 113 }
104 ev = TodoList.next(); 114 ev = TodoList.next();
105 } 115 }
106 //TodoList = cal->rawTodos(); 116 //TodoList = cal->rawTodos();
107 ev = TodoList.first(); 117 ev = TodoList.first();
108 while ( ev ) { 118 while ( ev ) {
109 ev->unRegisterObserver( cal ); 119 ev->unRegisterObserver( cal );
110 ev->registerObserver( this ); 120 ev->registerObserver( this );
111 mTodoList.append( ev ); 121 mTodoList.append( ev );
112 setupRelations( ev ); 122 setupRelations( ev );
113 ev = TodoList.next(); 123 ev = TodoList.next();
114 } 124 }
115 } 125 }
116 { 126 {
117 QPtrList<Journal> JournalList = cal->journals(); 127 QPtrList<Journal> JournalList = cal->journals();
118 Journal * ev = JournalList.first(); 128 Journal * ev = JournalList.first();
119 while ( ev ) { 129 while ( ev ) {
120 ev->unRegisterObserver( cal ); 130 ev->unRegisterObserver( cal );
121 ev->registerObserver( this ); 131 ev->registerObserver( this );
122 mJournalList.append( ev ); 132 mJournalList.append( ev );
123 ev = JournalList.next(); 133 ev = JournalList.next();
124 } 134 }
125 } 135 }
126 setModified( true ); 136 setModified( true );
127} 137}
128bool CalendarLocal::load( const QString &fileName ) 138bool CalendarLocal::load( const QString &fileName )
129{ 139{
130 FileStorage storage( this, fileName ); 140 FileStorage storage( this, fileName );
131 return storage.load(); 141 return storage.load();
132} 142}
133 143
134bool CalendarLocal::save( const QString &fileName, CalFormat *format ) 144bool CalendarLocal::save( const QString &fileName, CalFormat *format )
135{ 145{
136 FileStorage storage( this, fileName, format ); 146 FileStorage storage( this, fileName, format );
137 return storage.save(); 147 return storage.save();
138} 148}
139 149
140void CalendarLocal::close() 150void CalendarLocal::close()
141{ 151{
142 152
143 Todo * i; 153 Todo * i;
144 for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); 154 for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false);
145 155
146 mEventList.setAutoDelete( true ); 156 mEventList.setAutoDelete( true );
147 mTodoList.setAutoDelete( true ); 157 mTodoList.setAutoDelete( true );
148 mJournalList.setAutoDelete( false ); 158 mJournalList.setAutoDelete( false );
149 159
150 mEventList.clear(); 160 mEventList.clear();
151 mTodoList.clear(); 161 mTodoList.clear();
152 mJournalList.clear(); 162 mJournalList.clear();
153 163
154 mEventList.setAutoDelete( false ); 164 mEventList.setAutoDelete( false );
155 mTodoList.setAutoDelete( false ); 165 mTodoList.setAutoDelete( false );
156 mJournalList.setAutoDelete( false ); 166 mJournalList.setAutoDelete( false );
157 167
158 setModified( false ); 168 setModified( false );
159} 169}
160 170
161bool CalendarLocal::addAnniversaryNoDup( Event *event ) 171bool CalendarLocal::addAnniversaryNoDup( Event *event )
162{ 172{
163 QString cat; 173 QString cat;
164 bool isBirthday = true; 174 bool isBirthday = true;
165 if( event->categoriesStr() == i18n( "Anniversary" ) ) { 175 if( event->categoriesStr() == i18n( "Anniversary" ) ) {
166 isBirthday = false; 176 isBirthday = false;
167 cat = i18n( "Anniversary" ); 177 cat = i18n( "Anniversary" );
168 } else if( event->categoriesStr() == i18n( "Birthday" ) ) { 178 } else if( event->categoriesStr() == i18n( "Birthday" ) ) {
169 isBirthday = true; 179 isBirthday = true;
170 cat = i18n( "Birthday" ); 180 cat = i18n( "Birthday" );
171 } else { 181 } else {
172 qDebug("addAnniversaryNoDup called without fitting category! "); 182 qDebug("addAnniversaryNoDup called without fitting category! ");
173 return false; 183 return false;
174 } 184 }
175 Event * eve; 185 Event * eve;
176 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 186 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
177 if ( !(eve->categories().contains( cat ) )) 187 if ( !(eve->categories().contains( cat ) ))
178 continue; 188 continue;
179 // now we have an event with fitting category 189 // now we have an event with fitting category
180 if ( eve->dtStart().date() != event->dtStart().date() ) 190 if ( eve->dtStart().date() != event->dtStart().date() )
181 continue; 191 continue;
182 // now we have an event with fitting category+date 192 // now we have an event with fitting category+date
183 if ( eve->summary() != event->summary() ) 193 if ( eve->summary() != event->summary() )
184 continue; 194 continue;
185 // now we have an event with fitting category+date+summary 195 // now we have an event with fitting category+date+summary
186 return false; 196 return false;
187 } 197 }
188 return addEvent( event ); 198 return addEvent( event );
189 199
190} 200}
191bool CalendarLocal::addEventNoDup( Event *event ) 201bool CalendarLocal::addEventNoDup( Event *event )
192{ 202{
193 Event * eve; 203 Event * eve;
194 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 204 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
195 if ( *eve == *event ) { 205 if ( *eve == *event ) {
196 //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); 206 //qDebug("CalendarLocal::Duplicate event found! Not inserted! ");
197 return false; 207 return false;
198 } 208 }
199 } 209 }
200 return addEvent( event ); 210 return addEvent( event );
201} 211}
202 212
203bool CalendarLocal::addEvent( Event *event ) 213bool CalendarLocal::addEvent( Event *event )
204{ 214{
205 insertEvent( event ); 215 insertEvent( event );
206 216
207 event->registerObserver( this ); 217 event->registerObserver( this );
208 218
209 setModified( true ); 219 setModified( true );
210 event->setCalID( mDefaultCalendar ); 220 event->setCalID( mDefaultCalendar );
211 event->setCalEnabled( true ); 221 event->setCalEnabled( true );
212 222
213 return true; 223 return true;
214} 224}
215 225
216void CalendarLocal::deleteEvent( Event *event ) 226void CalendarLocal::deleteEvent( Event *event )
217{ 227{
218 if ( mUndoIncidence ) delete mUndoIncidence; 228 if ( mUndoIncidence ) delete mUndoIncidence;
219 mUndoIncidence = event->clone(); 229 mUndoIncidence = event->clone();
220 if ( mEventList.removeRef( event ) ) { 230 if ( mEventList.removeRef( event ) ) {
221 setModified( true ); 231 setModified( true );
222 } 232 }
223} 233}
224 234
225 235
226Event *CalendarLocal::event( const QString &uid ) 236Event *CalendarLocal::event( const QString &uid )
227{ 237{
228 Event *event; 238 Event *event;
229 Event *retVal = 0; 239 Event *retVal = 0;
230 for ( event = mEventList.first(); event; event = mEventList.next() ) { 240 for ( event = mEventList.first(); event; event = mEventList.next() ) {
231 if ( event->calEnabled() && event->uid() == uid ) { 241 if ( event->calEnabled() && event->uid() == uid ) {
232 if ( retVal ) { 242 if ( retVal ) {
233 if ( retVal->calID() > event->calID() ) { 243 if ( retVal->calID() > event->calID() ) {
234 retVal = event; 244 retVal = event;
235 } 245 }
236 } else { 246 } else {
237 retVal = event; 247 retVal = event;
238 } 248 }
239 } 249 }
240 } 250 }
241 return retVal; 251 return retVal;
242} 252}
243bool CalendarLocal::addTodoNoDup( Todo *todo ) 253bool CalendarLocal::addTodoNoDup( Todo *todo )
244{ 254{
245 Todo * eve; 255 Todo * eve;
246 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { 256 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) {
247 if ( *eve == *todo ) { 257 if ( *eve == *todo ) {
248 //qDebug("duplicate todo found! not inserted! "); 258 //qDebug("duplicate todo found! not inserted! ");
249 return false; 259 return false;
250 } 260 }
251 } 261 }
252 return addTodo( todo ); 262 return addTodo( todo );
253} 263}
254bool CalendarLocal::addTodo( Todo *todo ) 264bool CalendarLocal::addTodo( Todo *todo )
255{ 265{
256 mTodoList.append( todo ); 266 mTodoList.append( todo );
257 267
258 todo->registerObserver( this ); 268 todo->registerObserver( this );
259 269
260 // Set up subtask relations 270 // Set up subtask relations
261 setupRelations( todo ); 271 setupRelations( todo );
262 272
263 setModified( true ); 273 setModified( true );
264 todo->setCalID( mDefaultCalendar ); 274 todo->setCalID( mDefaultCalendar );
265 todo->setCalEnabled( true ); 275 todo->setCalEnabled( true );
266 return true; 276 return true;
267} 277}
268 278
269void CalendarLocal::deleteTodo( Todo *todo ) 279void CalendarLocal::deleteTodo( Todo *todo )
270{ 280{
271 // Handle orphaned children 281 // Handle orphaned children
272 if ( mUndoIncidence ) delete mUndoIncidence; 282 if ( mUndoIncidence ) delete mUndoIncidence;
273 removeRelations( todo ); 283 removeRelations( todo );
274 mUndoIncidence = todo->clone(); 284 mUndoIncidence = todo->clone();
275 285
276 if ( mTodoList.removeRef( todo ) ) { 286 if ( mTodoList.removeRef( todo ) ) {
277 setModified( true ); 287 setModified( true );
278 } 288 }
279} 289}
280 290
281QPtrList<Todo> CalendarLocal::rawTodos() 291QPtrList<Todo> CalendarLocal::rawTodos()
282{ 292{
283 QPtrList<Todo> el; 293 QPtrList<Todo> el;
284 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 294 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
285 if ( it->calEnabled() ) el.append( it ); 295 if ( it->calEnabled() ) el.append( it );
286 return el; 296 return el;
287} 297}
288Todo *CalendarLocal::todo( QString syncProf, QString id ) 298Todo *CalendarLocal::todo( QString syncProf, QString id )
289{ 299{
290 Todo *todo; 300 Todo *todo;
291 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 301 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
292 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; 302 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo;
293 } 303 }
294 304
295 return 0; 305 return 0;
296} 306}
297void CalendarLocal::removeSyncInfo( QString syncProfile) 307void CalendarLocal::removeSyncInfo( QString syncProfile)
298{ 308{
299 QPtrList<Incidence> all = rawIncidences() ; 309 QPtrList<Incidence> all = rawIncidences() ;
300 Incidence *inc; 310 Incidence *inc;
301 for ( inc = all.first(); inc; inc = all.next() ) { 311 for ( inc = all.first(); inc; inc = all.next() ) {
302 inc->removeID( syncProfile ); 312 inc->removeID( syncProfile );
303 } 313 }
304 if ( syncProfile.isEmpty() ) { 314 if ( syncProfile.isEmpty() ) {
305 QPtrList<Event> el; 315 QPtrList<Event> el;
306 Event *todo; 316 Event *todo;
307 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 317 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
308 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) 318 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
309 el.append( todo ); 319 el.append( todo );
310 } 320 }
311 for ( todo = el.first(); todo; todo = el.next() ) { 321 for ( todo = el.first(); todo; todo = el.next() ) {
312 deleteIncidence ( todo ); 322 deleteIncidence ( todo );
313 } 323 }
314 } else { 324 } else {
315 Event *lse = event( "last-syncEvent-"+ syncProfile); 325 Event *lse = event( "last-syncEvent-"+ syncProfile);
316 if ( lse ) 326 if ( lse )
317 deleteIncidence ( lse ); 327 deleteIncidence ( lse );
318 } 328 }
319} 329}
320QPtrList<Event> CalendarLocal::getExternLastSyncEvents() 330QPtrList<Event> CalendarLocal::getExternLastSyncEvents()
321{ 331{
322 QPtrList<Event> el; 332 QPtrList<Event> el;
323 Event *todo; 333 Event *todo;
324 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 334 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
325 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) 335 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
326 if ( todo->summary().left(3) == "E: " ) 336 if ( todo->summary().left(3) == "E: " )
327 el.append( todo ); 337 el.append( todo );
328 } 338 }
329 339
330 return el; 340 return el;
331 341
332} 342}
333Event *CalendarLocal::event( QString syncProf, QString id ) 343Event *CalendarLocal::event( QString syncProf, QString id )
334{ 344{
335 Event *todo; 345 Event *todo;
336 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 346 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
337 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; 347 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo;
338 } 348 }
339 349
340 return 0; 350 return 0;
341} 351}
342Todo *CalendarLocal::todo( const QString &uid ) 352Todo *CalendarLocal::todo( const QString &uid )
343{ 353{
344 Todo *todo;; 354 Todo *todo;;
345 Todo *retVal = 0; 355 Todo *retVal = 0;
346 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 356 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
347 if ( todo->calEnabled() && todo->uid() == uid ) { 357 if ( todo->calEnabled() && todo->uid() == uid ) {
348 if ( retVal ) { 358 if ( retVal ) {
349 if ( retVal->calID() > todo->calID() ) { 359 if ( retVal->calID() > todo->calID() ) {
350 retVal = todo; 360 retVal = todo;
351 } 361 }
352 } else { 362 } else {
353 retVal = todo; 363 retVal = todo;
354 } 364 }
355 } 365 }
356 } 366 }
357 return retVal; 367 return retVal;
358} 368}
359QString CalendarLocal::nextSummary() const 369QString CalendarLocal::nextSummary() const
360{ 370{
361 return mNextSummary; 371 return mNextSummary;
362} 372}
363QDateTime CalendarLocal::nextAlarmEventDateTime() const 373QDateTime CalendarLocal::nextAlarmEventDateTime() const
364{ 374{
365 return mNextAlarmEventDateTime; 375 return mNextAlarmEventDateTime;
366} 376}
367void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) 377void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted)
368{ 378{
369 //mNextAlarmIncidence 379 //mNextAlarmIncidence
370 //mNextAlarmDateTime 380 //mNextAlarmDateTime
371 //return mNextSummary; 381 //return mNextSummary;
372 //return mNextAlarmEventDateTime; 382 //return mNextAlarmEventDateTime;
373 bool newNextAlarm = false; 383 bool newNextAlarm = false;
374 bool computeNextAlarm = false; 384 bool computeNextAlarm = false;
375 bool ok; 385 bool ok;
376 int offset; 386 int offset;
377 QDateTime nextA; 387 QDateTime nextA;
378 // QString nextSum; 388 // QString nextSum;
379 //QDateTime nextEvent; 389 //QDateTime nextEvent;
380 if ( mNextAlarmIncidence == 0 || incidence == 0 ) { 390 if ( mNextAlarmIncidence == 0 || incidence == 0 ) {
381 computeNextAlarm = true; 391 computeNextAlarm = true;
382 } else { 392 } else {
383 if ( ! deleted ) { 393 if ( ! deleted ) {
384 nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; 394 nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
385 if ( ok ) { 395 if ( ok ) {
386 if ( nextA < mNextAlarmDateTime ) { 396 if ( nextA < mNextAlarmDateTime ) {
387 deRegisterAlarm(); 397 deRegisterAlarm();
388 mNextAlarmDateTime = nextA; 398 mNextAlarmDateTime = nextA;
389 mNextSummary = incidence->summary(); 399 mNextSummary = incidence->summary();
390 mNextAlarmEventDateTime = nextA.addSecs(offset ) ; 400 mNextAlarmEventDateTime = nextA.addSecs(offset ) ;
391 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); 401 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime);
392 newNextAlarm = true; 402 newNextAlarm = true;
393 mNextAlarmIncidence = incidence; 403 mNextAlarmIncidence = incidence;
394 } else { 404 } else {
395 if ( incidence == mNextAlarmIncidence ) { 405 if ( incidence == mNextAlarmIncidence ) {
396 computeNextAlarm = true; 406 computeNextAlarm = true;
397 } 407 }
398 } 408 }
399 } else { 409 } else {
400 if ( mNextAlarmIncidence == incidence ) { 410 if ( mNextAlarmIncidence == incidence ) {
401 computeNextAlarm = true; 411 computeNextAlarm = true;
402 } 412 }
403 } 413 }
404 } else { // deleted 414 } else { // deleted
405 if ( incidence == mNextAlarmIncidence ) { 415 if ( incidence == mNextAlarmIncidence ) {
406 computeNextAlarm = true; 416 computeNextAlarm = true;
407 } 417 }
408 } 418 }
409 } 419 }
410 if ( computeNextAlarm ) { 420 if ( computeNextAlarm ) {
411 deRegisterAlarm(); 421 deRegisterAlarm();
412 nextA = nextAlarm( 1000 ); 422 nextA = nextAlarm( 1000 );
413 if (! mNextAlarmIncidence ) { 423 if (! mNextAlarmIncidence ) {
414 return; 424 return;
415 } 425 }
416 newNextAlarm = true; 426 newNextAlarm = true;
417 } 427 }
418 if ( newNextAlarm ) 428 if ( newNextAlarm )
419 registerAlarm(); 429 registerAlarm();
420} 430}
421QString CalendarLocal:: getAlarmNotification() 431QString CalendarLocal:: getAlarmNotification()
422{ 432{
423 QString ret; 433 QString ret;
424 // this should not happen 434 // this should not happen
425 if (! mNextAlarmIncidence ) 435 if (! mNextAlarmIncidence )
426 return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; 436 return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString;
427 Alarm* alarm = mNextAlarmIncidence->alarms().first(); 437 Alarm* alarm = mNextAlarmIncidence->alarms().first();
428 if ( alarm->type() == Alarm::Procedure ) { 438 if ( alarm->type() == Alarm::Procedure ) {
429 ret = "proc_alarm" + alarm->programFile()+"+++"; 439 ret = "proc_alarm" + alarm->programFile()+"+++";
430 } else { 440 } else {
431 ret = "audio_alarm" +alarm->audioFile() +"+++"; 441 ret = "audio_alarm" +alarm->audioFile() +"+++";
432 } 442 }
433 ret += "cal_alarm"+ mNextSummary.left( 25 ); 443 ret += "cal_alarm"+ mNextSummary.left( 25 );
434 if ( mNextSummary.length() > 25 ) 444 if ( mNextSummary.length() > 25 )
435 ret += "\n" + mNextSummary.mid(25, 25 ); 445 ret += "\n" + mNextSummary.mid(25, 25 );
436 ret+= "\n"+mNextAlarmEventDateTimeString; 446 ret+= "\n"+mNextAlarmEventDateTimeString;
437 return ret; 447 return ret;
438} 448}
439void CalendarLocal::registerAlarm() 449void CalendarLocal::registerAlarm()
440{ 450{
441 mLastAlarmNotificationString = getAlarmNotification(); 451 mLastAlarmNotificationString = getAlarmNotification();
442 // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); 452 // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() );
443 emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); 453 emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString );
444// #ifndef DESKTOP_VERSION 454// #ifndef DESKTOP_VERSION
445// AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); 455// AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() );
446// #endif 456// #endif
447} 457}
448void CalendarLocal::deRegisterAlarm() 458void CalendarLocal::deRegisterAlarm()
449{ 459{
450 if ( mLastAlarmNotificationString.isNull() ) 460 if ( mLastAlarmNotificationString.isNull() )
451 return; 461 return;
452 //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); 462 //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() );
453 463
454 emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); 464 emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString );
455 mNextAlarmEventDateTime = QDateTime(); 465 mNextAlarmEventDateTime = QDateTime();
456// #ifndef DESKTOP_VERSION 466// #ifndef DESKTOP_VERSION
457// AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); 467// AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() );
458// #endif 468// #endif
459} 469}
460 470
461QPtrList<Todo> CalendarLocal::todos( const QDate &date ) 471QPtrList<Todo> CalendarLocal::todos( const QDate &date )
462{ 472{
463 QPtrList<Todo> todos; 473 QPtrList<Todo> todos;
464 474
465 Todo *todo; 475 Todo *todo;
466 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 476 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
467 if ( !todo->calEnabled() ) continue; 477 if ( !todo->calEnabled() ) continue;
468 if ( todo->hasDueDate() && todo->dtDue().date() == date ) { 478 if ( todo->hasDueDate() && todo->dtDue().date() == date ) {
469 todos.append( todo ); 479 todos.append( todo );
470 } 480 }
471 } 481 }
472 482
473 filter()->apply( &todos ); 483 filter()->apply( &todos );
474 return todos; 484 return todos;
475} 485}
476void CalendarLocal::reInitAlarmSettings() 486void CalendarLocal::reInitAlarmSettings()
477{ 487{
478 if ( !mNextAlarmIncidence ) { 488 if ( !mNextAlarmIncidence ) {
479 nextAlarm( 1000 ); 489 nextAlarm( 1000 );
480 } 490 }
481 deRegisterAlarm(); 491 deRegisterAlarm();
482 mNextAlarmIncidence = 0; 492 mNextAlarmIncidence = 0;
483 checkAlarmForIncidence( 0, false ); 493 checkAlarmForIncidence( 0, false );
484 494
485} 495}
486 496
487 497
488 498
489QDateTime CalendarLocal::nextAlarm( int daysTo ) 499QDateTime CalendarLocal::nextAlarm( int daysTo )
490{ 500{
491 QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); 501 QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo );
492 QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); 502 QDateTime start = QDateTime::currentDateTime().addSecs( 30 );
493 QDateTime next; 503 QDateTime next;
494 Event *e; 504 Event *e;
495 bool ok; 505 bool ok;
496 bool found = false; 506 bool found = false;
497 int offset; 507 int offset;
498 mNextAlarmIncidence = 0; 508 mNextAlarmIncidence = 0;
499 for( e = mEventList.first(); e; e = mEventList.next() ) { 509 for( e = mEventList.first(); e; e = mEventList.next() ) {
500 if ( !e->calEnabled() ) continue; 510 if ( !e->calEnabled() ) continue;
501 next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; 511 next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
502 if ( ok ) { 512 if ( ok ) {
503 if ( next < nextA ) { 513 if ( next < nextA ) {
504 nextA = next; 514 nextA = next;
505 found = true; 515 found = true;
506 mNextSummary = e->summary(); 516 mNextSummary = e->summary();
507 mNextAlarmEventDateTime = next.addSecs(offset ) ; 517 mNextAlarmEventDateTime = next.addSecs(offset ) ;
508 mNextAlarmIncidence = (Incidence *) e; 518 mNextAlarmIncidence = (Incidence *) e;
509 } 519 }
510 } 520 }
511 } 521 }
512 Todo *t; 522 Todo *t;
513 for( t = mTodoList.first(); t; t = mTodoList.next() ) { 523 for( t = mTodoList.first(); t; t = mTodoList.next() ) {
514 if ( !t->calEnabled() ) continue; 524 if ( !t->calEnabled() ) continue;
515 next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; 525 next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
516 if ( ok ) { 526 if ( ok ) {
517 if ( next < nextA ) { 527 if ( next < nextA ) {
518 nextA = next; 528 nextA = next;
519 found = true; 529 found = true;
520 mNextSummary = t->summary(); 530 mNextSummary = t->summary();
521 mNextAlarmEventDateTime = next.addSecs(offset ); 531 mNextAlarmEventDateTime = next.addSecs(offset );
522 mNextAlarmIncidence = (Incidence *) t; 532 mNextAlarmIncidence = (Incidence *) t;
523 } 533 }
524 } 534 }
525 } 535 }
526 if ( mNextAlarmIncidence ) { 536 if ( mNextAlarmIncidence ) {
527 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); 537 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime);
528 mNextAlarmDateTime = nextA; 538 mNextAlarmDateTime = nextA;
529 } 539 }
530 return nextA; 540 return nextA;
531} 541}
532Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) 542Alarm::List CalendarLocal::alarmsTo( const QDateTime &to )
533{ 543{
534 return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); 544 return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to );
535} 545}
536 546
537Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) 547Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to )
538{ 548{
539 549
540 Alarm::List alarms; 550 Alarm::List alarms;
541 551
542 Event *e; 552 Event *e;
543 553
544 for( e = mEventList.first(); e; e = mEventList.next() ) { 554 for( e = mEventList.first(); e; e = mEventList.next() ) {
545 if ( !e->calEnabled() ) continue; 555 if ( !e->calEnabled() ) continue;
546 if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); 556 if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to );
547 else appendAlarms( alarms, e, from, to ); 557 else appendAlarms( alarms, e, from, to );
548 } 558 }
549 559
550 Todo *t; 560 Todo *t;
551 for( t = mTodoList.first(); t; t = mTodoList.next() ) { 561 for( t = mTodoList.first(); t; t = mTodoList.next() ) {
552 if ( !t->calEnabled() ) continue; 562 if ( !t->calEnabled() ) continue;
553 appendAlarms( alarms, t, from, to ); 563 appendAlarms( alarms, t, from, to );
554 } 564 }
555 565
556 return alarms; 566 return alarms;
557} 567}
558 568
559void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, 569void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence,
560 const QDateTime &from, const QDateTime &to ) 570 const QDateTime &from, const QDateTime &to )
561{ 571{
562 QPtrList<Alarm> alarmList = incidence->alarms(); 572 QPtrList<Alarm> alarmList = incidence->alarms();
563 Alarm *alarm; 573 Alarm *alarm;
564 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { 574 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) {
565// kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() 575// kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text()
566// << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; 576// << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl;
567 if ( alarm->enabled() ) { 577 if ( alarm->enabled() ) {
568 if ( alarm->time() >= from && alarm->time() <= to ) { 578 if ( alarm->time() >= from && alarm->time() <= to ) {
569 alarms.append( alarm ); 579 alarms.append( alarm );
570 } 580 }
571 } 581 }
572 } 582 }
573} 583}
574 584
575void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, 585void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms,
576 Incidence *incidence, 586 Incidence *incidence,
577 const QDateTime &from, 587 const QDateTime &from,
578 const QDateTime &to ) 588 const QDateTime &to )
579{ 589{
580 590
581 QPtrList<Alarm> alarmList = incidence->alarms(); 591 QPtrList<Alarm> alarmList = incidence->alarms();
582 Alarm *alarm; 592 Alarm *alarm;
583 QDateTime qdt; 593 QDateTime qdt;
584 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { 594 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) {
585 if (incidence->recursOn(from.date())) { 595 if (incidence->recursOn(from.date())) {
586 qdt.setTime(alarm->time().time()); 596 qdt.setTime(alarm->time().time());
587 qdt.setDate(from.date()); 597 qdt.setDate(from.date());
588 } 598 }
589 else qdt = alarm->time(); 599 else qdt = alarm->time();
590 // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); 600 // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1());
591 if ( alarm->enabled() ) { 601 if ( alarm->enabled() ) {
592 if ( qdt >= from && qdt <= to ) { 602 if ( qdt >= from && qdt <= to ) {