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