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