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, 3 insertions, 3 deletions
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp
index e75df70..bc76c0b 100644
--- a/libkcal/calendarlocal.cpp
+++ b/libkcal/calendarlocal.cpp
@@ -1,730 +1,730 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 3
4 Copyright (c) 1998 Preston Brown 4 Copyright (c) 1998 Preston Brown
5 Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> 5 Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org>
6 6
7 This library is free software; you can redistribute it and/or 7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public 8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either 9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version. 10 version 2 of the License, or (at your option) any later version.
11 11
12 This library is distributed in the hope that it will be useful, 12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details. 15 Library General Public License for more details.
16 16
17 You should have received a copy of the GNU Library General Public License 17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to 18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. 20 Boston, MA 02111-1307, USA.
21*/ 21*/
22 22
23#include <qdatetime.h> 23#include <qdatetime.h>
24#include <qstring.h> 24#include <qstring.h>
25#include <qptrlist.h> 25#include <qptrlist.h>
26 26
27#include <kdebug.h> 27#include <kdebug.h>
28#include <kconfig.h> 28#include <kconfig.h>
29#include <kglobal.h> 29#include <kglobal.h>
30#include <klocale.h> 30#include <klocale.h>
31 31
32#include "vcaldrag.h" 32#include "vcaldrag.h"
33#include "vcalformat.h" 33#include "vcalformat.h"
34#include "icalformat.h" 34#include "icalformat.h"
35#include "exceptions.h" 35#include "exceptions.h"
36#include "incidence.h" 36#include "incidence.h"
37#include "journal.h" 37#include "journal.h"
38#include "filestorage.h" 38#include "filestorage.h"
39#include "calfilter.h" 39#include "calfilter.h"
40 40
41#include "calendarlocal.h" 41#include "calendarlocal.h"
42 42
43// #ifndef DESKTOP_VERSION 43// #ifndef DESKTOP_VERSION
44// #include <qtopia/alarmserver.h> 44// #include <qtopia/alarmserver.h>
45// #endif 45// #endif
46using namespace KCal; 46using namespace KCal;
47 47
48CalendarLocal::CalendarLocal() 48CalendarLocal::CalendarLocal()
49 : Calendar() 49 : Calendar()
50{ 50{
51 init(); 51 init();
52} 52}
53 53
54CalendarLocal::CalendarLocal(const QString &timeZoneId) 54CalendarLocal::CalendarLocal(const QString &timeZoneId)
55 : Calendar(timeZoneId) 55 : Calendar(timeZoneId)
56{ 56{
57 init(); 57 init();
58} 58}
59 59
60void CalendarLocal::init() 60void CalendarLocal::init()
61{ 61{
62 mNextAlarmIncidence = 0; 62 mNextAlarmIncidence = 0;
63} 63}
64 64
65 65
66CalendarLocal::~CalendarLocal() 66CalendarLocal::~CalendarLocal()
67{ 67{
68 close(); 68 close();
69} 69}
70 70
71bool CalendarLocal::load( const QString &fileName ) 71bool CalendarLocal::load( const QString &fileName )
72{ 72{
73 FileStorage storage( this, fileName ); 73 FileStorage storage( this, fileName );
74 return storage.load(); 74 return storage.load();
75} 75}
76 76
77bool CalendarLocal::save( const QString &fileName, CalFormat *format ) 77bool CalendarLocal::save( const QString &fileName, CalFormat *format )
78{ 78{
79 FileStorage storage( this, fileName, format ); 79 FileStorage storage( this, fileName, format );
80 return storage.save(); 80 return storage.save();
81} 81}
82 82
83void CalendarLocal::close() 83void CalendarLocal::close()
84{ 84{
85 85
86 Todo * i; 86 Todo * i;
87 for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); 87 for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false);
88 88
89 mEventList.setAutoDelete( true ); 89 mEventList.setAutoDelete( true );
90 mTodoList.setAutoDelete( true ); 90 mTodoList.setAutoDelete( true );
91 mJournalList.setAutoDelete( false ); 91 mJournalList.setAutoDelete( false );
92 92
93 mEventList.clear(); 93 mEventList.clear();
94 mTodoList.clear(); 94 mTodoList.clear();
95 mJournalList.clear(); 95 mJournalList.clear();
96 96
97 mEventList.setAutoDelete( false ); 97 mEventList.setAutoDelete( false );
98 mTodoList.setAutoDelete( false ); 98 mTodoList.setAutoDelete( false );
99 mJournalList.setAutoDelete( false ); 99 mJournalList.setAutoDelete( false );
100 100
101 setModified( false ); 101 setModified( false );
102} 102}
103 103
104bool CalendarLocal::addAnniversaryNoDup( Event *event ) 104bool CalendarLocal::addAnniversaryNoDup( Event *event )
105{ 105{
106 QString cat; 106 QString cat;
107 bool isBirthday = true; 107 bool isBirthday = true;
108 if( event->categoriesStr() == i18n( "Anniversary" ) ) { 108 if( event->categoriesStr() == i18n( "Anniversary" ) ) {
109 isBirthday = false; 109 isBirthday = false;
110 cat = i18n( "Anniversary" ); 110 cat = i18n( "Anniversary" );
111 } else if( event->categoriesStr() == i18n( "Birthday" ) ) { 111 } else if( event->categoriesStr() == i18n( "Birthday" ) ) {
112 isBirthday = true; 112 isBirthday = true;
113 cat = i18n( "Birthday" ); 113 cat = i18n( "Birthday" );
114 } else { 114 } else {
115 qDebug("addAnniversaryNoDup called without fitting category! "); 115 qDebug("addAnniversaryNoDup called without fitting category! ");
116 return false; 116 return false;
117 } 117 }
118 Event * eve; 118 Event * eve;
119 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 119 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
120 if ( !(eve->categories().contains( cat ) )) 120 if ( !(eve->categories().contains( cat ) ))
121 continue; 121 continue;
122 // now we have an event with fitting category 122 // now we have an event with fitting category
123 if ( eve->dtStart().date() != event->dtStart().date() ) 123 if ( eve->dtStart().date() != event->dtStart().date() )
124 continue; 124 continue;
125 // now we have an event with fitting category+date 125 // now we have an event with fitting category+date
126 if ( eve->summary() != event->summary() ) 126 if ( eve->summary() != event->summary() )
127 continue; 127 continue;
128 // now we have an event with fitting category+date+summary 128 // now we have an event with fitting category+date+summary
129 return false; 129 return false;
130 } 130 }
131 return addEvent( event ); 131 return addEvent( event );
132 132
133} 133}
134bool CalendarLocal::addEventNoDup( Event *event ) 134bool CalendarLocal::addEventNoDup( Event *event )
135{ 135{
136 Event * eve; 136 Event * eve;
137 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 137 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
138 if ( *eve == *event ) { 138 if ( *eve == *event ) {
139 //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); 139 //qDebug("CalendarLocal::Duplicate event found! Not inserted! ");
140 return false; 140 return false;
141 } 141 }
142 } 142 }
143 return addEvent( event ); 143 return addEvent( event );
144} 144}
145 145
146bool CalendarLocal::addEvent( Event *event ) 146bool CalendarLocal::addEvent( Event *event )
147{ 147{
148 insertEvent( event ); 148 insertEvent( event );
149 149
150 event->registerObserver( this ); 150 event->registerObserver( this );
151 151
152 setModified( true ); 152 setModified( true );
153 153
154 return true; 154 return true;
155} 155}
156 156
157void CalendarLocal::deleteEvent( Event *event ) 157void CalendarLocal::deleteEvent( Event *event )
158{ 158{
159 if ( mUndoIncidence ) delete mUndoIncidence; 159 if ( mUndoIncidence ) delete mUndoIncidence;
160 mUndoIncidence = event->clone(); 160 mUndoIncidence = event->clone();
161 if ( mEventList.removeRef( event ) ) { 161 if ( mEventList.removeRef( event ) ) {
162 setModified( true ); 162 setModified( true );
163 } 163 }
164} 164}
165 165
166 166
167Event *CalendarLocal::event( const QString &uid ) 167Event *CalendarLocal::event( const QString &uid )
168{ 168{
169 169
170 Event *event; 170 Event *event;
171 171
172 for ( event = mEventList.first(); event; event = mEventList.next() ) { 172 for ( event = mEventList.first(); event; event = mEventList.next() ) {
173 if ( event->uid() == uid ) { 173 if ( event->uid() == uid ) {
174 return event; 174 return event;
175 } 175 }
176 } 176 }
177 177
178 return 0; 178 return 0;
179} 179}
180bool CalendarLocal::addTodoNoDup( Todo *todo ) 180bool CalendarLocal::addTodoNoDup( Todo *todo )
181{ 181{
182 Todo * eve; 182 Todo * eve;
183 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { 183 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) {
184 if ( *eve == *todo ) { 184 if ( *eve == *todo ) {
185 //qDebug("duplicate todo found! not inserted! "); 185 //qDebug("duplicate todo found! not inserted! ");
186 return false; 186 return false;
187 } 187 }
188 } 188 }
189 return addTodo( todo ); 189 return addTodo( todo );
190} 190}
191bool CalendarLocal::addTodo( Todo *todo ) 191bool CalendarLocal::addTodo( Todo *todo )
192{ 192{
193 mTodoList.append( todo ); 193 mTodoList.append( todo );
194 194
195 todo->registerObserver( this ); 195 todo->registerObserver( this );
196 196
197 // Set up subtask relations 197 // Set up subtask relations
198 setupRelations( todo ); 198 setupRelations( todo );
199 199
200 setModified( true ); 200 setModified( true );
201 201
202 return true; 202 return true;
203} 203}
204 204
205void CalendarLocal::deleteTodo( Todo *todo ) 205void CalendarLocal::deleteTodo( Todo *todo )
206{ 206{
207 // Handle orphaned children 207 // Handle orphaned children
208 if ( mUndoIncidence ) delete mUndoIncidence; 208 if ( mUndoIncidence ) delete mUndoIncidence;
209 removeRelations( todo ); 209 removeRelations( todo );
210 mUndoIncidence = todo->clone(); 210 mUndoIncidence = todo->clone();
211 211
212 if ( mTodoList.removeRef( todo ) ) { 212 if ( mTodoList.removeRef( todo ) ) {
213 setModified( true ); 213 setModified( true );
214 } 214 }
215} 215}
216 216
217QPtrList<Todo> CalendarLocal::rawTodos() 217QPtrList<Todo> CalendarLocal::rawTodos()
218{ 218{
219 return mTodoList; 219 return mTodoList;
220} 220}
221Todo *CalendarLocal::todo( QString syncProf, QString id ) 221Todo *CalendarLocal::todo( QString syncProf, QString id )
222{ 222{
223 Todo *todo; 223 Todo *todo;
224 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 224 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
225 if ( todo->getID( syncProf ) == id ) return todo; 225 if ( todo->getID( syncProf ) == id ) return todo;
226 } 226 }
227 227
228 return 0; 228 return 0;
229} 229}
230void CalendarLocal::removeSyncInfo( QString syncProfile) 230void CalendarLocal::removeSyncInfo( QString syncProfile)
231{ 231{
232 QPtrList<Incidence> all = rawIncidences() ; 232 QPtrList<Incidence> all = rawIncidences() ;
233 Incidence *inc; 233 Incidence *inc;
234 for ( inc = all.first(); inc; inc = all.next() ) { 234 for ( inc = all.first(); inc; inc = all.next() ) {
235 inc->removeID( syncProfile ); 235 inc->removeID( syncProfile );
236 } 236 }
237 if ( syncProfile.isEmpty() ) { 237 if ( syncProfile.isEmpty() ) {
238 QPtrList<Event> el; 238 QPtrList<Event> el;
239 Event *todo; 239 Event *todo;
240 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 240 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
241 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) 241 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
242 el.append( todo ); 242 el.append( todo );
243 } 243 }
244 for ( todo = el.first(); todo; todo = el.next() ) { 244 for ( todo = el.first(); todo; todo = el.next() ) {
245 deleteIncidence ( todo ); 245 deleteIncidence ( todo );
246 } 246 }
247 } else { 247 } else {
248 Event *lse = event( "last-syncEvent-"+ syncProfile); 248 Event *lse = event( "last-syncEvent-"+ syncProfile);
249 if ( lse ) 249 if ( lse )
250 deleteIncidence ( lse ); 250 deleteIncidence ( lse );
251 } 251 }
252} 252}
253QPtrList<Event> CalendarLocal::getExternLastSyncEvents() 253QPtrList<Event> CalendarLocal::getExternLastSyncEvents()
254{ 254{
255 QPtrList<Event> el; 255 QPtrList<Event> el;
256 Event *todo; 256 Event *todo;
257 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 257 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
258 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) 258 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
259 if ( todo->summary().left(3) == "E: " ) 259 if ( todo->summary().left(3) == "E: " )
260 el.append( todo ); 260 el.append( todo );
261 } 261 }
262 262
263 return el; 263 return el;
264 264
265} 265}
266Event *CalendarLocal::event( QString syncProf, QString id ) 266Event *CalendarLocal::event( QString syncProf, QString id )
267{ 267{
268 Event *todo; 268 Event *todo;
269 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 269 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
270 if ( todo->getID( syncProf ) == id ) return todo; 270 if ( todo->getID( syncProf ) == id ) return todo;
271 } 271 }
272 272
273 return 0; 273 return 0;
274} 274}
275Todo *CalendarLocal::todo( const QString &uid ) 275Todo *CalendarLocal::todo( const QString &uid )
276{ 276{
277 Todo *todo; 277 Todo *todo;
278 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 278 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
279 if ( todo->uid() == uid ) return todo; 279 if ( todo->uid() == uid ) return todo;
280 } 280 }
281 281
282 return 0; 282 return 0;
283} 283}
284QString CalendarLocal::nextSummary() const 284QString CalendarLocal::nextSummary() const
285{ 285{
286 return mNextSummary; 286 return mNextSummary;
287} 287}
288QDateTime CalendarLocal::nextAlarmEventDateTime() const 288QDateTime CalendarLocal::nextAlarmEventDateTime() const
289{ 289{
290 return mNextAlarmEventDateTime; 290 return mNextAlarmEventDateTime;
291} 291}
292void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) 292void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted)
293{ 293{
294 //mNextAlarmIncidence 294 //mNextAlarmIncidence
295 //mNextAlarmDateTime 295 //mNextAlarmDateTime
296 //return mNextSummary; 296 //return mNextSummary;
297 //return mNextAlarmEventDateTime; 297 //return mNextAlarmEventDateTime;
298 bool newNextAlarm = false; 298 bool newNextAlarm = false;
299 bool computeNextAlarm = false; 299 bool computeNextAlarm = false;
300 bool ok; 300 bool ok;
301 int offset; 301 int offset;
302 QDateTime nextA; 302 QDateTime nextA;
303 // QString nextSum; 303 // QString nextSum;
304 //QDateTime nextEvent; 304 //QDateTime nextEvent;
305 if ( mNextAlarmIncidence == 0 || incidence == 0 ) { 305 if ( mNextAlarmIncidence == 0 || incidence == 0 ) {
306 computeNextAlarm = true; 306 computeNextAlarm = true;
307 } else { 307 } else {
308 if ( ! deleted ) { 308 if ( ! deleted ) {
309 nextA = incidence->getNextAlarmDateTime(& ok, &offset ) ; 309 nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
310 if ( ok ) { 310 if ( ok ) {
311 if ( nextA < mNextAlarmDateTime ) { 311 if ( nextA < mNextAlarmDateTime ) {
312 deRegisterAlarm(); 312 deRegisterAlarm();
313 mNextAlarmDateTime = nextA; 313 mNextAlarmDateTime = nextA;
314 mNextSummary = incidence->summary(); 314 mNextSummary = incidence->summary();
315 mNextAlarmEventDateTime = nextA.addSecs(offset ) ; 315 mNextAlarmEventDateTime = nextA.addSecs(offset ) ;
316 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); 316 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime);
317 newNextAlarm = true; 317 newNextAlarm = true;
318 mNextAlarmIncidence = incidence; 318 mNextAlarmIncidence = incidence;
319 } else { 319 } else {
320 if ( incidence == mNextAlarmIncidence ) { 320 if ( incidence == mNextAlarmIncidence ) {
321 computeNextAlarm = true; 321 computeNextAlarm = true;
322 } 322 }
323 } 323 }
324 } else { 324 } else {
325 if ( mNextAlarmIncidence == incidence ) { 325 if ( mNextAlarmIncidence == incidence ) {
326 computeNextAlarm = true; 326 computeNextAlarm = true;
327 } 327 }
328 } 328 }
329 } else { // deleted 329 } else { // deleted
330 if ( incidence == mNextAlarmIncidence ) { 330 if ( incidence == mNextAlarmIncidence ) {
331 computeNextAlarm = true; 331 computeNextAlarm = true;
332 } 332 }
333 } 333 }
334 } 334 }
335 if ( computeNextAlarm ) { 335 if ( computeNextAlarm ) {
336 deRegisterAlarm(); 336 deRegisterAlarm();
337 nextA = nextAlarm( 1000 ); 337 nextA = nextAlarm( 1000 );
338 if (! mNextAlarmIncidence ) { 338 if (! mNextAlarmIncidence ) {
339 return; 339 return;
340 } 340 }
341 newNextAlarm = true; 341 newNextAlarm = true;
342 } 342 }
343 if ( newNextAlarm ) 343 if ( newNextAlarm )
344 registerAlarm(); 344 registerAlarm();
345} 345}
346QString CalendarLocal:: getAlarmNotification() 346QString CalendarLocal:: getAlarmNotification()
347{ 347{
348 QString ret; 348 QString ret;
349 // this should not happen 349 // this should not happen
350 if (! mNextAlarmIncidence ) 350 if (! mNextAlarmIncidence )
351 return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; 351 return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString;
352 Alarm* alarm = mNextAlarmIncidence->alarms().first(); 352 Alarm* alarm = mNextAlarmIncidence->alarms().first();
353 if ( alarm->type() == Alarm::Procedure ) { 353 if ( alarm->type() == Alarm::Procedure ) {
354 ret = "proc_alarm" + alarm->programFile()+"+++"; 354 ret = "proc_alarm" + alarm->programFile()+"+++";
355 } else { 355 } else {
356 ret = "audio_alarm" +alarm->audioFile() +"+++"; 356 ret = "audio_alarm" +alarm->audioFile() +"+++";
357 } 357 }
358 ret += "cal_alarm"+ mNextSummary.left( 25 ); 358 ret += "cal_alarm"+ mNextSummary.left( 25 );
359 if ( mNextSummary.length() > 25 ) 359 if ( mNextSummary.length() > 25 )
360 ret += "\n" + mNextSummary.mid(25, 25 ); 360 ret += "\n" + mNextSummary.mid(25, 25 );
361 ret+= "\n"+mNextAlarmEventDateTimeString; 361 ret+= "\n"+mNextAlarmEventDateTimeString;
362 return ret; 362 return ret;
363} 363}
364void CalendarLocal::registerAlarm() 364void CalendarLocal::registerAlarm()
365{ 365{
366 mLastAlarmNotificationString = getAlarmNotification(); 366 mLastAlarmNotificationString = getAlarmNotification();
367 // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); 367 // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() );
368 emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); 368 emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString );
369// #ifndef DESKTOP_VERSION 369// #ifndef DESKTOP_VERSION
370// AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); 370// AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() );
371// #endif 371// #endif
372} 372}
373void CalendarLocal::deRegisterAlarm() 373void CalendarLocal::deRegisterAlarm()
374{ 374{
375 if ( mLastAlarmNotificationString.isNull() ) 375 if ( mLastAlarmNotificationString.isNull() )
376 return; 376 return;
377 //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); 377 //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() );
378 378
379 emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); 379 emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString );
380 mNextAlarmEventDateTime = QDateTime(); 380 mNextAlarmEventDateTime = QDateTime();
381// #ifndef DESKTOP_VERSION 381// #ifndef DESKTOP_VERSION
382// AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); 382// AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() );
383// #endif 383// #endif
384} 384}
385 385
386QPtrList<Todo> CalendarLocal::todos( const QDate &date ) 386QPtrList<Todo> CalendarLocal::todos( const QDate &date )
387{ 387{
388 QPtrList<Todo> todos; 388 QPtrList<Todo> todos;
389 389
390 Todo *todo; 390 Todo *todo;
391 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 391 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
392 if ( todo->hasDueDate() && todo->dtDue().date() == date ) { 392 if ( todo->hasDueDate() && todo->dtDue().date() == date ) {
393 todos.append( todo ); 393 todos.append( todo );
394 } 394 }
395 } 395 }
396 396
397 filter()->apply( &todos ); 397 filter()->apply( &todos );
398 return todos; 398 return todos;
399} 399}
400void CalendarLocal::reInitAlarmSettings() 400void CalendarLocal::reInitAlarmSettings()
401{ 401{
402 if ( !mNextAlarmIncidence ) { 402 if ( !mNextAlarmIncidence ) {
403 nextAlarm( 1000 ); 403 nextAlarm( 1000 );
404 } 404 }
405 deRegisterAlarm(); 405 deRegisterAlarm();
406 mNextAlarmIncidence = 0; 406 mNextAlarmIncidence = 0;
407 checkAlarmForIncidence( 0, false ); 407 checkAlarmForIncidence( 0, false );
408 408
409} 409}
410 410
411 411
412 412
413QDateTime CalendarLocal::nextAlarm( int daysTo ) 413QDateTime CalendarLocal::nextAlarm( int daysTo )
414{ 414{
415 QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); 415 QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo );
416 QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); 416 QDateTime start = QDateTime::currentDateTime().addSecs( 30 );
417 QDateTime next; 417 QDateTime next;
418 Event *e; 418 Event *e;
419 bool ok; 419 bool ok;
420 bool found = false; 420 bool found = false;
421 int offset; 421 int offset;
422 mNextAlarmIncidence = 0; 422 mNextAlarmIncidence = 0;
423 for( e = mEventList.first(); e; e = mEventList.next() ) { 423 for( e = mEventList.first(); e; e = mEventList.next() ) {
424 next = e->getNextAlarmDateTime(& ok, &offset ) ; 424 next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
425 if ( ok ) { 425 if ( ok ) {
426 if ( next < nextA ) { 426 if ( next < nextA ) {
427 nextA = next; 427 nextA = next;
428 found = true; 428 found = true;
429 mNextSummary = e->summary(); 429 mNextSummary = e->summary();
430 mNextAlarmEventDateTime = next.addSecs(offset ) ; 430 mNextAlarmEventDateTime = next.addSecs(offset ) ;
431 mNextAlarmIncidence = (Incidence *) e; 431 mNextAlarmIncidence = (Incidence *) e;
432 } 432 }
433 } 433 }
434 } 434 }
435 Todo *t; 435 Todo *t;
436 for( t = mTodoList.first(); t; t = mTodoList.next() ) { 436 for( t = mTodoList.first(); t; t = mTodoList.next() ) {
437 next = t->getNextAlarmDateTime(& ok, &offset ) ; 437 next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
438 if ( ok ) { 438 if ( ok ) {
439 if ( next < nextA ) { 439 if ( next < nextA ) {
440 nextA = next; 440 nextA = next;
441 found = true; 441 found = true;
442 mNextSummary = t->summary(); 442 mNextSummary = t->summary();
443 mNextAlarmEventDateTime = next.addSecs(offset ); 443 mNextAlarmEventDateTime = next.addSecs(offset );
444 mNextAlarmIncidence = (Incidence *) t; 444 mNextAlarmIncidence = (Incidence *) t;
445 } 445 }
446 } 446 }
447 } 447 }
448 if ( mNextAlarmIncidence ) { 448 if ( mNextAlarmIncidence ) {
449 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); 449 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime);
450 mNextAlarmDateTime = nextA; 450 mNextAlarmDateTime = nextA;
451 } 451 }
452 return nextA; 452 return nextA;
453} 453}
454Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) 454Alarm::List CalendarLocal::alarmsTo( const QDateTime &to )
455{ 455{
456 return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); 456 return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to );
457} 457}
458 458
459Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) 459Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to )
460{ 460{
461 kdDebug(5800) << "CalendarLocal::alarms(" << from.toString() << " - " 461 kdDebug(5800) << "CalendarLocal::alarms(" << from.toString() << " - "
462 << to.toString() << ")\n"; 462 << to.toString() << ")\n";
463 463
464 Alarm::List alarms; 464 Alarm::List alarms;
465 465
466 Event *e; 466 Event *e;
467 467
468 for( e = mEventList.first(); e; e = mEventList.next() ) { 468 for( e = mEventList.first(); e; e = mEventList.next() ) {
469 if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); 469 if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to );
470 else appendAlarms( alarms, e, from, to ); 470 else appendAlarms( alarms, e, from, to );
471 } 471 }
472 472
473 Todo *t; 473 Todo *t;
474 for( t = mTodoList.first(); t; t = mTodoList.next() ) { 474 for( t = mTodoList.first(); t; t = mTodoList.next() ) {
475 appendAlarms( alarms, t, from, to ); 475 appendAlarms( alarms, t, from, to );
476 } 476 }
477 477
478 return alarms; 478 return alarms;
479} 479}
480 480
481void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, 481void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence,
482 const QDateTime &from, const QDateTime &to ) 482 const QDateTime &from, const QDateTime &to )
483{ 483{
484 QPtrList<Alarm> alarmList = incidence->alarms(); 484 QPtrList<Alarm> alarmList = incidence->alarms();
485 Alarm *alarm; 485 Alarm *alarm;
486 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { 486 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) {
487// kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() 487// kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text()
488// << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; 488// << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl;
489 if ( alarm->enabled() ) { 489 if ( alarm->enabled() ) {
490 if ( alarm->time() >= from && alarm->time() <= to ) { 490 if ( alarm->time() >= from && alarm->time() <= to ) {
491 kdDebug(5800) << "CalendarLocal::appendAlarms() '" << incidence->summary() 491 kdDebug(5800) << "CalendarLocal::appendAlarms() '" << incidence->summary()
492 << "': " << alarm->time().toString() << endl; 492 << "': " << alarm->time().toString() << endl;
493 alarms.append( alarm ); 493 alarms.append( alarm );
494 } 494 }
495 } 495 }
496 } 496 }
497} 497}
498 498
499void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, 499void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms,
500 Incidence *incidence, 500 Incidence *incidence,
501 const QDateTime &from, 501 const QDateTime &from,
502 const QDateTime &to ) 502 const QDateTime &to )
503{ 503{
504 504
505 QPtrList<Alarm> alarmList = incidence->alarms(); 505 QPtrList<Alarm> alarmList = incidence->alarms();
506 Alarm *alarm; 506 Alarm *alarm;
507 QDateTime qdt; 507 QDateTime qdt;
508 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { 508 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) {
509 if (incidence->recursOn(from.date())) { 509 if (incidence->recursOn(from.date())) {
510 qdt.setTime(alarm->time().time()); 510 qdt.setTime(alarm->time().time());
511 qdt.setDate(from.date()); 511 qdt.setDate(from.date());
512 } 512 }
513 else qdt = alarm->time(); 513 else qdt = alarm->time();
514 // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); 514 // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1());
515 if ( alarm->enabled() ) { 515 if ( alarm->enabled() ) {
516 if ( qdt >= from && qdt <= to ) { 516 if ( qdt >= from && qdt <= to ) {
517 alarms.append( alarm ); 517 alarms.append( alarm );
518 } 518 }
519 } 519 }
520 } 520 }
521} 521}
522 522
523 523
524/****************************** PROTECTED METHODS ****************************/ 524/****************************** PROTECTED METHODS ****************************/
525 525
526// after changes are made to an event, this should be called. 526// after changes are made to an event, this should be called.
527void CalendarLocal::update( IncidenceBase *incidence ) 527void CalendarLocal::update( IncidenceBase *incidence )
528{ 528{
529 incidence->setSyncStatus( Event::SYNCMOD ); 529 incidence->setSyncStatus( Event::SYNCMOD );
530 incidence->setLastModified( QDateTime::currentDateTime() ); 530 incidence->setLastModified( QDateTime::currentDateTime() );
531 // we should probably update the revision number here, 531 // we should probably update the revision number here,
532 // or internally in the Event itself when certain things change. 532 // or internally in the Event itself when certain things change.
533 // need to verify with ical documentation. 533 // need to verify with ical documentation.
534 534
535 setModified( true ); 535 setModified( true );
536} 536}
537 537
538void CalendarLocal::insertEvent( Event *event ) 538void CalendarLocal::insertEvent( Event *event )
539{ 539{
540 if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); 540 if ( mEventList.findRef( event ) < 0 ) mEventList.append( event );
541} 541}
542 542
543 543
544QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) 544QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted )
545{ 545{
546 QPtrList<Event> eventList; 546 QPtrList<Event> eventList;
547 547
548 Event *event; 548 Event *event;
549 for( event = mEventList.first(); event; event = mEventList.next() ) { 549 for( event = mEventList.first(); event; event = mEventList.next() ) {
550 if ( event->doesRecur() ) { 550 if ( event->doesRecur() ) {
551 if ( event->isMultiDay() ) { 551 if ( event->isMultiDay() ) {
552 int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); 552 int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() );
553 int i; 553 int i;
554 for ( i = 0; i <= extraDays; i++ ) { 554 for ( i = 0; i <= extraDays; i++ ) {
555 if ( event->recursOn( qd.addDays( -i ) ) ) { 555 if ( event->recursOn( qd.addDays( -i ) ) ) {
556 eventList.append( event ); 556 eventList.append( event );
557 break; 557 break;
558 } 558 }
559 } 559 }
560 } else { 560 } else {
561 if ( event->recursOn( qd ) ) 561 if ( event->recursOn( qd ) )
562 eventList.append( event ); 562 eventList.append( event );
563 } 563 }
564 } else { 564 } else {
565 if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { 565 if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) {
566 eventList.append( event ); 566 eventList.append( event );
567 } 567 }
568 } 568 }
569 } 569 }
570 570
571 if ( !sorted ) { 571 if ( !sorted ) {
572 return eventList; 572 return eventList;
573 } 573 }
574 574
575 // kdDebug(5800) << "Sorting events for date\n" << endl; 575 // kdDebug(5800) << "Sorting events for date\n" << endl;
576 // now, we have to sort it based on dtStart.time() 576 // now, we have to sort it based on dtStart.time()
577 QPtrList<Event> eventListSorted; 577 QPtrList<Event> eventListSorted;
578 Event *sortEvent; 578 Event *sortEvent;
579 for ( event = eventList.first(); event; event = eventList.next() ) { 579 for ( event = eventList.first(); event; event = eventList.next() ) {
580 sortEvent = eventListSorted.first(); 580 sortEvent = eventListSorted.first();
581 int i = 0; 581 int i = 0;
582 while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) 582 while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() )
583 { 583 {
584 i++; 584 i++;
585 sortEvent = eventListSorted.next(); 585 sortEvent = eventListSorted.next();
586 } 586 }
587 eventListSorted.insert( i, event ); 587 eventListSorted.insert( i, event );
588 } 588 }
589 return eventListSorted; 589 return eventListSorted;
590} 590}
591 591
592 592
593QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, 593QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end,
594 bool inclusive ) 594 bool inclusive )
595{ 595{
596 Event *event = 0; 596 Event *event = 0;
597 597
598 QPtrList<Event> eventList; 598 QPtrList<Event> eventList;
599 599
600 // Get non-recurring events 600 // Get non-recurring events
601 for( event = mEventList.first(); event; event = mEventList.next() ) { 601 for( event = mEventList.first(); event; event = mEventList.next() ) {
602 if ( event->doesRecur() ) { 602 if ( event->doesRecur() ) {
603 QDate rStart = event->dtStart().date(); 603 QDate rStart = event->dtStart().date();
604 bool found = false; 604 bool found = false;
605 if ( inclusive ) { 605 if ( inclusive ) {
606 if ( rStart >= start && rStart <= end ) { 606 if ( rStart >= start && rStart <= end ) {
607 // Start date of event is in range. Now check for end date. 607 // Start date of event is in range. Now check for end date.
608 // if duration is negative, event recurs forever, so do not include it. 608 // if duration is negative, event recurs forever, so do not include it.
609 if ( event->recurrence()->duration() == 0 ) { // End date set 609 if ( event->recurrence()->duration() == 0 ) { // End date set
610 QDate rEnd = event->recurrence()->endDate(); 610 QDate rEnd = event->recurrence()->endDate();
611 if ( rEnd >= start && rEnd <= end ) { // End date within range 611 if ( rEnd >= start && rEnd <= end ) { // End date within range
612 found = true; 612 found = true;
613 } 613 }
614 } else if ( event->recurrence()->duration() > 0 ) { // Duration set 614 } else if ( event->recurrence()->duration() > 0 ) { // Duration set
615 // TODO: Calculate end date from duration. Should be done in Event 615 // TODO: Calculate end date from duration. Should be done in Event
616 // For now exclude all events with a duration. 616 // For now exclude all events with a duration.
617 } 617 }
618 } 618 }
619 } else { 619 } else {
620 bool founOne; 620 bool founOne;
621 QDate next = event->getNextOccurence( start, &founOne ).date(); 621 QDate next = event->getNextOccurence( start, &founOne ).date();
622 if ( founOne ) { 622 if ( founOne ) {
623 if ( next <= end ) { 623 if ( next <= end ) {
624 found = true; 624 found = true;
625 } 625 }
626 } 626 }
627 627
628 /* 628 /*
629 // crap !!! 629 // crap !!!
630 if ( rStart <= end ) { // Start date not after range 630 if ( rStart <= end ) { // Start date not after range
631 if ( rStart >= start ) { // Start date within range 631 if ( rStart >= start ) { // Start date within range
632 found = true; 632 found = true;
633 } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever 633 } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever
634 found = true; 634 found = true;
635 } else if ( event->recurrence()->duration() == 0 ) { // End date set 635 } else if ( event->recurrence()->duration() == 0 ) { // End date set
636 QDate rEnd = event->recurrence()->endDate(); 636 QDate rEnd = event->recurrence()->endDate();
637 if ( rEnd >= start && rEnd <= end ) { // End date within range 637 if ( rEnd >= start && rEnd <= end ) { // End date within range
638 found = true; 638 found = true;
639 } 639 }
640 } else { // Duration set 640 } else { // Duration set
641 // TODO: Calculate end date from duration. Should be done in Event 641 // TODO: Calculate end date from duration. Should be done in Event
642 // For now include all events with a duration. 642 // For now include all events with a duration.
643 found = true; 643 found = true;
644 } 644 }
645 } 645 }
646 */ 646 */
647 647
648 } 648 }
649 649
650 if ( found ) eventList.append( event ); 650 if ( found ) eventList.append( event );
651 } else { 651 } else {
652 QDate s = event->dtStart().date(); 652 QDate s = event->dtStart().date();
653 QDate e = event->dtEnd().date(); 653 QDate e = event->dtEnd().date();
654 654
655 if ( inclusive ) { 655 if ( inclusive ) {
656 if ( s >= start && e <= end ) { 656 if ( s >= start && e <= end ) {
657 eventList.append( event ); 657 eventList.append( event );
658 } 658 }
659 } else { 659 } else {
660 if ( ( s >= start && s <= end ) || ( e >= start && e <= end ) ) { 660 if ( ( s >= start && s <= end ) || ( e >= start && e <= end ) ) {
661 eventList.append( event ); 661 eventList.append( event );
662 } 662 }
663 } 663 }
664 } 664 }
665 } 665 }
666 666
667 return eventList; 667 return eventList;
668} 668}
669 669
670QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) 670QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt )
671{ 671{
672 return rawEventsForDate( qdt.date() ); 672 return rawEventsForDate( qdt.date() );
673} 673}
674 674
675QPtrList<Event> CalendarLocal::rawEvents() 675QPtrList<Event> CalendarLocal::rawEvents()
676{ 676{
677 return mEventList; 677 return mEventList;
678} 678}
679 679
680bool CalendarLocal::addJournal(Journal *journal) 680bool CalendarLocal::addJournal(Journal *journal)
681{ 681{
682 if ( journal->dtStart().isValid()) 682 if ( journal->dtStart().isValid())
683 kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl; 683 kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl;
684 else 684 else
685 kdDebug(5800) << "Adding Journal without a DTSTART" << endl; 685 kdDebug(5800) << "Adding Journal without a DTSTART" << endl;
686 686
687 mJournalList.append(journal); 687 mJournalList.append(journal);
688 688
689 journal->registerObserver( this ); 689 journal->registerObserver( this );
690 690
691 setModified( true ); 691 setModified( true );
692 692
693 return true; 693 return true;
694} 694}
695 695
696void CalendarLocal::deleteJournal( Journal *journal ) 696void CalendarLocal::deleteJournal( Journal *journal )
697{ 697{
698 if ( mUndoIncidence ) delete mUndoIncidence; 698 if ( mUndoIncidence ) delete mUndoIncidence;
699 mUndoIncidence = journal->clone(); 699 mUndoIncidence = journal->clone();
700 mUndoIncidence->setSummary( mUndoIncidence->description().left(25)); 700 mUndoIncidence->setSummary( mUndoIncidence->description().left(25));
701 if ( mJournalList.removeRef(journal) ) { 701 if ( mJournalList.removeRef(journal) ) {
702 setModified( true ); 702 setModified( true );
703 } 703 }
704} 704}
705 705
706Journal *CalendarLocal::journal( const QDate &date ) 706Journal *CalendarLocal::journal( const QDate &date )
707{ 707{
708// kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; 708// kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl;
709 709
710 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 710 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
711 if ( it->dtStart().date() == date ) 711 if ( it->dtStart().date() == date )
712 return it; 712 return it;
713 713
714 return 0; 714 return 0;
715} 715}
716 716
717Journal *CalendarLocal::journal( const QString &uid ) 717Journal *CalendarLocal::journal( const QString &uid )
718{ 718{
719 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 719 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
720 if ( it->uid() == uid ) 720 if ( it->uid() == uid )
721 return it; 721 return it;
722 722
723 return 0; 723 return 0;
724} 724}
725 725
726QPtrList<Journal> CalendarLocal::journals() 726QPtrList<Journal> CalendarLocal::journals()
727{ 727{
728 return mJournalList; 728 return mJournalList;
729} 729}
730 730