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