-rw-r--r-- | libkcal/calendarlocal.cpp | 55 |
1 files changed, 37 insertions, 18 deletions
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index 749d9f6..336c3e8 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp | |||
@@ -132,310 +132,322 @@ bool CalendarLocal::load( const QString &fileName ) | |||
132 | } | 132 | } |
133 | 133 | ||
134 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) | 134 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) |
135 | { | 135 | { |
136 | FileStorage storage( this, fileName, format ); | 136 | FileStorage storage( this, fileName, format ); |
137 | return storage.save(); | 137 | return storage.save(); |
138 | } | 138 | } |
139 | 139 | ||
140 | void CalendarLocal::close() | 140 | void CalendarLocal::close() |
141 | { | 141 | { |
142 | 142 | ||
143 | Todo * i; | 143 | Todo * i; |
144 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); | 144 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); |
145 | 145 | ||
146 | mEventList.setAutoDelete( true ); | 146 | mEventList.setAutoDelete( true ); |
147 | mTodoList.setAutoDelete( true ); | 147 | mTodoList.setAutoDelete( true ); |
148 | mJournalList.setAutoDelete( false ); | 148 | mJournalList.setAutoDelete( false ); |
149 | 149 | ||
150 | mEventList.clear(); | 150 | mEventList.clear(); |
151 | mTodoList.clear(); | 151 | mTodoList.clear(); |
152 | mJournalList.clear(); | 152 | mJournalList.clear(); |
153 | 153 | ||
154 | mEventList.setAutoDelete( false ); | 154 | mEventList.setAutoDelete( false ); |
155 | mTodoList.setAutoDelete( false ); | 155 | mTodoList.setAutoDelete( false ); |
156 | mJournalList.setAutoDelete( false ); | 156 | mJournalList.setAutoDelete( false ); |
157 | 157 | ||
158 | setModified( false ); | 158 | setModified( false ); |
159 | } | 159 | } |
160 | 160 | ||
161 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) | 161 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) |
162 | { | 162 | { |
163 | QString cat; | 163 | QString cat; |
164 | bool isBirthday = true; | 164 | bool isBirthday = true; |
165 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { | 165 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { |
166 | isBirthday = false; | 166 | isBirthday = false; |
167 | cat = i18n( "Anniversary" ); | 167 | cat = i18n( "Anniversary" ); |
168 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { | 168 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { |
169 | isBirthday = true; | 169 | isBirthday = true; |
170 | cat = i18n( "Birthday" ); | 170 | cat = i18n( "Birthday" ); |
171 | } else { | 171 | } else { |
172 | qDebug("addAnniversaryNoDup called without fitting category! "); | 172 | qDebug("addAnniversaryNoDup called without fitting category! "); |
173 | return false; | 173 | return false; |
174 | } | 174 | } |
175 | Event * eve; | 175 | Event * eve; |
176 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 176 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
177 | if ( !(eve->categories().contains( cat ) )) | 177 | if ( !(eve->categories().contains( cat ) )) |
178 | continue; | 178 | continue; |
179 | // now we have an event with fitting category | 179 | // now we have an event with fitting category |
180 | if ( eve->dtStart().date() != event->dtStart().date() ) | 180 | if ( eve->dtStart().date() != event->dtStart().date() ) |
181 | continue; | 181 | continue; |
182 | // now we have an event with fitting category+date | 182 | // now we have an event with fitting category+date |
183 | if ( eve->summary() != event->summary() ) | 183 | if ( eve->summary() != event->summary() ) |
184 | continue; | 184 | continue; |
185 | // now we have an event with fitting category+date+summary | 185 | // now we have an event with fitting category+date+summary |
186 | return false; | 186 | return false; |
187 | } | 187 | } |
188 | return addEvent( event ); | 188 | return addEvent( event ); |
189 | 189 | ||
190 | } | 190 | } |
191 | bool CalendarLocal::addEventNoDup( Event *event ) | 191 | bool CalendarLocal::addEventNoDup( Event *event ) |
192 | { | 192 | { |
193 | Event * eve; | 193 | Event * eve; |
194 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 194 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
195 | if ( *eve == *event ) { | 195 | if ( *eve == *event ) { |
196 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); | 196 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); |
197 | return false; | 197 | return false; |
198 | } | 198 | } |
199 | } | 199 | } |
200 | return addEvent( event ); | 200 | return addEvent( event ); |
201 | } | 201 | } |
202 | 202 | ||
203 | bool CalendarLocal::addEvent( Event *event ) | 203 | bool CalendarLocal::addEvent( Event *event ) |
204 | { | 204 | { |
205 | insertEvent( event ); | 205 | insertEvent( event ); |
206 | 206 | ||
207 | event->registerObserver( this ); | 207 | event->registerObserver( this ); |
208 | 208 | ||
209 | setModified( true ); | 209 | setModified( true ); |
210 | event->setCalID( mDefaultCalendar ); | 210 | event->setCalID( mDefaultCalendar ); |
211 | event->setCalEnabled( true ); | 211 | event->setCalEnabled( true ); |
212 | 212 | ||
213 | return true; | 213 | return true; |
214 | } | 214 | } |
215 | 215 | ||
216 | void CalendarLocal::deleteEvent( Event *event ) | 216 | void CalendarLocal::deleteEvent( Event *event ) |
217 | { | 217 | { |
218 | if ( mUndoIncidence ) delete mUndoIncidence; | 218 | if ( mUndoIncidence ) delete mUndoIncidence; |
219 | mUndoIncidence = event->clone(); | 219 | mUndoIncidence = event->clone(); |
220 | if ( mEventList.removeRef( event ) ) { | 220 | if ( mEventList.removeRef( event ) ) { |
221 | setModified( true ); | 221 | setModified( true ); |
222 | } | 222 | } |
223 | } | 223 | } |
224 | 224 | ||
225 | 225 | ||
226 | Event *CalendarLocal::event( const QString &uid ) | 226 | Event *CalendarLocal::event( const QString &uid ) |
227 | { | 227 | { |
228 | 228 | Event *event; | |
229 | Event *event; | 229 | Event *retVal = 0; |
230 | 230 | for ( event = mEventList.first(); event; event = mEventList.next() ) { | |
231 | for ( event = mEventList.first(); event; event = mEventList.next() ) { | 231 | if ( event->calEnabled() && event->uid() == uid ) { |
232 | if ( event->uid() == uid && event->calEnabled() ) { | 232 | if ( retVal ) { |
233 | return event; | 233 | if ( retVal->calID() > event->calID() ) { |
234 | retVal = event; | ||
235 | } | ||
236 | } else { | ||
237 | retVal = event; | ||
238 | } | ||
239 | } | ||
234 | } | 240 | } |
235 | } | 241 | return retVal; |
236 | |||
237 | return 0; | ||
238 | } | 242 | } |
239 | bool CalendarLocal::addTodoNoDup( Todo *todo ) | 243 | bool CalendarLocal::addTodoNoDup( Todo *todo ) |
240 | { | 244 | { |
241 | Todo * eve; | 245 | Todo * eve; |
242 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { | 246 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { |
243 | if ( *eve == *todo ) { | 247 | if ( *eve == *todo ) { |
244 | //qDebug("duplicate todo found! not inserted! "); | 248 | //qDebug("duplicate todo found! not inserted! "); |
245 | return false; | 249 | return false; |
246 | } | 250 | } |
247 | } | 251 | } |
248 | return addTodo( todo ); | 252 | return addTodo( todo ); |
249 | } | 253 | } |
250 | bool CalendarLocal::addTodo( Todo *todo ) | 254 | bool CalendarLocal::addTodo( Todo *todo ) |
251 | { | 255 | { |
252 | mTodoList.append( todo ); | 256 | mTodoList.append( todo ); |
253 | 257 | ||
254 | todo->registerObserver( this ); | 258 | todo->registerObserver( this ); |
255 | 259 | ||
256 | // Set up subtask relations | 260 | // Set up subtask relations |
257 | setupRelations( todo ); | 261 | setupRelations( todo ); |
258 | 262 | ||
259 | setModified( true ); | 263 | setModified( true ); |
260 | todo->setCalID( mDefaultCalendar ); | 264 | todo->setCalID( mDefaultCalendar ); |
261 | todo->setCalEnabled( true ); | 265 | todo->setCalEnabled( true ); |
262 | return true; | 266 | return true; |
263 | } | 267 | } |
264 | 268 | ||
265 | void CalendarLocal::deleteTodo( Todo *todo ) | 269 | void CalendarLocal::deleteTodo( Todo *todo ) |
266 | { | 270 | { |
267 | // Handle orphaned children | 271 | // Handle orphaned children |
268 | if ( mUndoIncidence ) delete mUndoIncidence; | 272 | if ( mUndoIncidence ) delete mUndoIncidence; |
269 | removeRelations( todo ); | 273 | removeRelations( todo ); |
270 | mUndoIncidence = todo->clone(); | 274 | mUndoIncidence = todo->clone(); |
271 | 275 | ||
272 | if ( mTodoList.removeRef( todo ) ) { | 276 | if ( mTodoList.removeRef( todo ) ) { |
273 | setModified( true ); | 277 | setModified( true ); |
274 | } | 278 | } |
275 | } | 279 | } |
276 | 280 | ||
277 | QPtrList<Todo> CalendarLocal::rawTodos() | 281 | QPtrList<Todo> CalendarLocal::rawTodos() |
278 | { | 282 | { |
279 | QPtrList<Todo> el; | 283 | QPtrList<Todo> el; |
280 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 284 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
281 | if ( it->calEnabled() ) el.append( it ); | 285 | if ( it->calEnabled() ) el.append( it ); |
282 | return el; | 286 | return el; |
283 | } | 287 | } |
284 | Todo *CalendarLocal::todo( QString syncProf, QString id ) | 288 | Todo *CalendarLocal::todo( QString syncProf, QString id ) |
285 | { | 289 | { |
286 | Todo *todo; | 290 | Todo *todo; |
287 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 291 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
288 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; | 292 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; |
289 | } | 293 | } |
290 | 294 | ||
291 | return 0; | 295 | return 0; |
292 | } | 296 | } |
293 | void CalendarLocal::removeSyncInfo( QString syncProfile) | 297 | void CalendarLocal::removeSyncInfo( QString syncProfile) |
294 | { | 298 | { |
295 | QPtrList<Incidence> all = rawIncidences() ; | 299 | QPtrList<Incidence> all = rawIncidences() ; |
296 | Incidence *inc; | 300 | Incidence *inc; |
297 | for ( inc = all.first(); inc; inc = all.next() ) { | 301 | for ( inc = all.first(); inc; inc = all.next() ) { |
298 | inc->removeID( syncProfile ); | 302 | inc->removeID( syncProfile ); |
299 | } | 303 | } |
300 | if ( syncProfile.isEmpty() ) { | 304 | if ( syncProfile.isEmpty() ) { |
301 | QPtrList<Event> el; | 305 | QPtrList<Event> el; |
302 | Event *todo; | 306 | Event *todo; |
303 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 307 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
304 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 308 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
305 | el.append( todo ); | 309 | el.append( todo ); |
306 | } | 310 | } |
307 | for ( todo = el.first(); todo; todo = el.next() ) { | 311 | for ( todo = el.first(); todo; todo = el.next() ) { |
308 | deleteIncidence ( todo ); | 312 | deleteIncidence ( todo ); |
309 | } | 313 | } |
310 | } else { | 314 | } else { |
311 | Event *lse = event( "last-syncEvent-"+ syncProfile); | 315 | Event *lse = event( "last-syncEvent-"+ syncProfile); |
312 | if ( lse ) | 316 | if ( lse ) |
313 | deleteIncidence ( lse ); | 317 | deleteIncidence ( lse ); |
314 | } | 318 | } |
315 | } | 319 | } |
316 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() | 320 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() |
317 | { | 321 | { |
318 | QPtrList<Event> el; | 322 | QPtrList<Event> el; |
319 | Event *todo; | 323 | Event *todo; |
320 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 324 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
321 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 325 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
322 | if ( todo->summary().left(3) == "E: " ) | 326 | if ( todo->summary().left(3) == "E: " ) |
323 | el.append( todo ); | 327 | el.append( todo ); |
324 | } | 328 | } |
325 | 329 | ||
326 | return el; | 330 | return el; |
327 | 331 | ||
328 | } | 332 | } |
329 | Event *CalendarLocal::event( QString syncProf, QString id ) | 333 | Event *CalendarLocal::event( QString syncProf, QString id ) |
330 | { | 334 | { |
331 | Event *todo; | 335 | Event *todo; |
332 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 336 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
333 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; | 337 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; |
334 | } | 338 | } |
335 | 339 | ||
336 | return 0; | 340 | return 0; |
337 | } | 341 | } |
338 | Todo *CalendarLocal::todo( const QString &uid ) | 342 | Todo *CalendarLocal::todo( const QString &uid ) |
339 | { | 343 | { |
340 | Todo *todo; | 344 | Todo *todo;; |
345 | Todo *retVal = 0; | ||
341 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 346 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
342 | if ( todo->calEnabled() && todo->uid() == uid ) return todo; | 347 | if ( todo->calEnabled() && todo->uid() == uid ) { |
348 | if ( retVal ) { | ||
349 | if ( retVal->calID() > todo->calID() ) { | ||
350 | retVal = todo; | ||
351 | } | ||
352 | } else { | ||
353 | retVal = todo; | ||
354 | } | ||
355 | } | ||
343 | } | 356 | } |
344 | 357 | return retVal; | |
345 | return 0; | ||
346 | } | 358 | } |
347 | QString CalendarLocal::nextSummary() const | 359 | QString CalendarLocal::nextSummary() const |
348 | { | 360 | { |
349 | return mNextSummary; | 361 | return mNextSummary; |
350 | } | 362 | } |
351 | QDateTime CalendarLocal::nextAlarmEventDateTime() const | 363 | QDateTime CalendarLocal::nextAlarmEventDateTime() const |
352 | { | 364 | { |
353 | return mNextAlarmEventDateTime; | 365 | return mNextAlarmEventDateTime; |
354 | } | 366 | } |
355 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) | 367 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) |
356 | { | 368 | { |
357 | //mNextAlarmIncidence | 369 | //mNextAlarmIncidence |
358 | //mNextAlarmDateTime | 370 | //mNextAlarmDateTime |
359 | //return mNextSummary; | 371 | //return mNextSummary; |
360 | //return mNextAlarmEventDateTime; | 372 | //return mNextAlarmEventDateTime; |
361 | bool newNextAlarm = false; | 373 | bool newNextAlarm = false; |
362 | bool computeNextAlarm = false; | 374 | bool computeNextAlarm = false; |
363 | bool ok; | 375 | bool ok; |
364 | int offset; | 376 | int offset; |
365 | QDateTime nextA; | 377 | QDateTime nextA; |
366 | // QString nextSum; | 378 | // QString nextSum; |
367 | //QDateTime nextEvent; | 379 | //QDateTime nextEvent; |
368 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { | 380 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { |
369 | computeNextAlarm = true; | 381 | computeNextAlarm = true; |
370 | } else { | 382 | } else { |
371 | if ( ! deleted ) { | 383 | if ( ! deleted ) { |
372 | nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; | 384 | nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; |
373 | if ( ok ) { | 385 | if ( ok ) { |
374 | if ( nextA < mNextAlarmDateTime ) { | 386 | if ( nextA < mNextAlarmDateTime ) { |
375 | deRegisterAlarm(); | 387 | deRegisterAlarm(); |
376 | mNextAlarmDateTime = nextA; | 388 | mNextAlarmDateTime = nextA; |
377 | mNextSummary = incidence->summary(); | 389 | mNextSummary = incidence->summary(); |
378 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; | 390 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; |
379 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 391 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
380 | newNextAlarm = true; | 392 | newNextAlarm = true; |
381 | mNextAlarmIncidence = incidence; | 393 | mNextAlarmIncidence = incidence; |
382 | } else { | 394 | } else { |
383 | if ( incidence == mNextAlarmIncidence ) { | 395 | if ( incidence == mNextAlarmIncidence ) { |
384 | computeNextAlarm = true; | 396 | computeNextAlarm = true; |
385 | } | 397 | } |
386 | } | 398 | } |
387 | } else { | 399 | } else { |
388 | if ( mNextAlarmIncidence == incidence ) { | 400 | if ( mNextAlarmIncidence == incidence ) { |
389 | computeNextAlarm = true; | 401 | computeNextAlarm = true; |
390 | } | 402 | } |
391 | } | 403 | } |
392 | } else { // deleted | 404 | } else { // deleted |
393 | if ( incidence == mNextAlarmIncidence ) { | 405 | if ( incidence == mNextAlarmIncidence ) { |
394 | computeNextAlarm = true; | 406 | computeNextAlarm = true; |
395 | } | 407 | } |
396 | } | 408 | } |
397 | } | 409 | } |
398 | if ( computeNextAlarm ) { | 410 | if ( computeNextAlarm ) { |
399 | deRegisterAlarm(); | 411 | deRegisterAlarm(); |
400 | nextA = nextAlarm( 1000 ); | 412 | nextA = nextAlarm( 1000 ); |
401 | if (! mNextAlarmIncidence ) { | 413 | if (! mNextAlarmIncidence ) { |
402 | return; | 414 | return; |
403 | } | 415 | } |
404 | newNextAlarm = true; | 416 | newNextAlarm = true; |
405 | } | 417 | } |
406 | if ( newNextAlarm ) | 418 | if ( newNextAlarm ) |
407 | registerAlarm(); | 419 | registerAlarm(); |
408 | } | 420 | } |
409 | QString CalendarLocal:: getAlarmNotification() | 421 | QString CalendarLocal:: getAlarmNotification() |
410 | { | 422 | { |
411 | QString ret; | 423 | QString ret; |
412 | // this should not happen | 424 | // this should not happen |
413 | if (! mNextAlarmIncidence ) | 425 | if (! mNextAlarmIncidence ) |
414 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; | 426 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; |
415 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); | 427 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); |
416 | if ( alarm->type() == Alarm::Procedure ) { | 428 | if ( alarm->type() == Alarm::Procedure ) { |
417 | ret = "proc_alarm" + alarm->programFile()+"+++"; | 429 | ret = "proc_alarm" + alarm->programFile()+"+++"; |
418 | } else { | 430 | } else { |
419 | ret = "audio_alarm" +alarm->audioFile() +"+++"; | 431 | ret = "audio_alarm" +alarm->audioFile() +"+++"; |
420 | } | 432 | } |
421 | ret += "cal_alarm"+ mNextSummary.left( 25 ); | 433 | ret += "cal_alarm"+ mNextSummary.left( 25 ); |
422 | if ( mNextSummary.length() > 25 ) | 434 | if ( mNextSummary.length() > 25 ) |
423 | ret += "\n" + mNextSummary.mid(25, 25 ); | 435 | ret += "\n" + mNextSummary.mid(25, 25 ); |
424 | ret+= "\n"+mNextAlarmEventDateTimeString; | 436 | ret+= "\n"+mNextAlarmEventDateTimeString; |
425 | return ret; | 437 | return ret; |
426 | } | 438 | } |
427 | void CalendarLocal::registerAlarm() | 439 | void CalendarLocal::registerAlarm() |
428 | { | 440 | { |
429 | mLastAlarmNotificationString = getAlarmNotification(); | 441 | mLastAlarmNotificationString = getAlarmNotification(); |
430 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); | 442 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); |
431 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 443 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
432 | // #ifndef DESKTOP_VERSION | 444 | // #ifndef DESKTOP_VERSION |
433 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); | 445 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); |
434 | // #endif | 446 | // #endif |
435 | } | 447 | } |
436 | void CalendarLocal::deRegisterAlarm() | 448 | void CalendarLocal::deRegisterAlarm() |
437 | { | 449 | { |
438 | if ( mLastAlarmNotificationString.isNull() ) | 450 | if ( mLastAlarmNotificationString.isNull() ) |
439 | return; | 451 | return; |
440 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); | 452 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); |
441 | 453 | ||
@@ -693,197 +705,204 @@ QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, | |||
693 | 705 | ||
694 | /* | 706 | /* |
695 | // crap !!! | 707 | // crap !!! |
696 | if ( rStart <= end ) { // Start date not after range | 708 | if ( rStart <= end ) { // Start date not after range |
697 | if ( rStart >= start ) { // Start date within range | 709 | if ( rStart >= start ) { // Start date within range |
698 | found = true; | 710 | found = true; |
699 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever | 711 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever |
700 | found = true; | 712 | found = true; |
701 | } else if ( event->recurrence()->duration() == 0 ) { // End date set | 713 | } else if ( event->recurrence()->duration() == 0 ) { // End date set |
702 | QDate rEnd = event->recurrence()->endDate(); | 714 | QDate rEnd = event->recurrence()->endDate(); |
703 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 715 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
704 | found = true; | 716 | found = true; |
705 | } | 717 | } |
706 | } else { // Duration set | 718 | } else { // Duration set |
707 | // TODO: Calculate end date from duration. Should be done in Event | 719 | // TODO: Calculate end date from duration. Should be done in Event |
708 | // For now include all events with a duration. | 720 | // For now include all events with a duration. |
709 | found = true; | 721 | found = true; |
710 | } | 722 | } |
711 | } | 723 | } |
712 | */ | 724 | */ |
713 | 725 | ||
714 | } | 726 | } |
715 | 727 | ||
716 | if ( found ) eventList.append( event ); | 728 | if ( found ) eventList.append( event ); |
717 | } else { | 729 | } else { |
718 | QDate s = event->dtStart().date(); | 730 | QDate s = event->dtStart().date(); |
719 | QDate e = event->dtEnd().date(); | 731 | QDate e = event->dtEnd().date(); |
720 | 732 | ||
721 | if ( inclusive ) { | 733 | if ( inclusive ) { |
722 | if ( s >= start && e <= end ) { | 734 | if ( s >= start && e <= end ) { |
723 | eventList.append( event ); | 735 | eventList.append( event ); |
724 | } | 736 | } |
725 | } else { | 737 | } else { |
726 | if ( ( s >= start && s <= end ) || ( e >= start && e <= end ) ) { | 738 | if ( ( s >= start && s <= end ) || ( e >= start && e <= end ) ) { |
727 | eventList.append( event ); | 739 | eventList.append( event ); |
728 | } | 740 | } |
729 | } | 741 | } |
730 | } | 742 | } |
731 | } | 743 | } |
732 | 744 | ||
733 | return eventList; | 745 | return eventList; |
734 | } | 746 | } |
735 | 747 | ||
736 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) | 748 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) |
737 | { | 749 | { |
738 | return rawEventsForDate( qdt.date() ); | 750 | return rawEventsForDate( qdt.date() ); |
739 | } | 751 | } |
740 | 752 | ||
741 | QPtrList<Event> CalendarLocal::rawEvents() | 753 | QPtrList<Event> CalendarLocal::rawEvents() |
742 | { | 754 | { |
743 | QPtrList<Event> el; | 755 | QPtrList<Event> el; |
744 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 756 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
745 | if ( it->calEnabled() ) el.append( it ); | 757 | if ( it->calEnabled() ) el.append( it ); |
746 | return el; | 758 | return el; |
747 | } | 759 | } |
748 | 760 | ||
749 | bool CalendarLocal::addJournal(Journal *journal) | 761 | bool CalendarLocal::addJournal(Journal *journal) |
750 | { | 762 | { |
751 | if ( journal->dtStart().isValid()) | 763 | if ( journal->dtStart().isValid()) |
752 | kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl; | 764 | kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl; |
753 | else | 765 | else |
754 | kdDebug(5800) << "Adding Journal without a DTSTART" << endl; | 766 | kdDebug(5800) << "Adding Journal without a DTSTART" << endl; |
755 | 767 | ||
756 | mJournalList.append(journal); | 768 | mJournalList.append(journal); |
757 | 769 | ||
758 | journal->registerObserver( this ); | 770 | journal->registerObserver( this ); |
759 | 771 | ||
760 | setModified( true ); | 772 | setModified( true ); |
761 | journal->setCalID( mDefaultCalendar ); | 773 | journal->setCalID( mDefaultCalendar ); |
762 | journal->setCalEnabled( true ); | 774 | journal->setCalEnabled( true ); |
763 | return true; | 775 | return true; |
764 | } | 776 | } |
765 | 777 | ||
766 | void CalendarLocal::deleteJournal( Journal *journal ) | 778 | void CalendarLocal::deleteJournal( Journal *journal ) |
767 | { | 779 | { |
768 | if ( mUndoIncidence ) delete mUndoIncidence; | 780 | if ( mUndoIncidence ) delete mUndoIncidence; |
769 | mUndoIncidence = journal->clone(); | 781 | mUndoIncidence = journal->clone(); |
770 | mUndoIncidence->setSummary( mUndoIncidence->description().left(25)); | 782 | mUndoIncidence->setSummary( mUndoIncidence->description().left(25)); |
771 | if ( mJournalList.removeRef(journal) ) { | 783 | if ( mJournalList.removeRef(journal) ) { |
772 | setModified( true ); | 784 | setModified( true ); |
773 | } | 785 | } |
774 | } | 786 | } |
775 | 787 | ||
776 | Journal *CalendarLocal::journal( const QDate &date ) | 788 | Journal *CalendarLocal::journal( const QDate &date ) |
777 | { | 789 | { |
778 | // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; | 790 | // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; |
779 | 791 | ||
780 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 792 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
781 | if ( it->calEnabled() && it->dtStart().date() == date ) | 793 | if ( it->calEnabled() && it->dtStart().date() == date ) |
782 | return it; | 794 | return it; |
783 | 795 | ||
784 | return 0; | 796 | return 0; |
785 | } | 797 | } |
786 | 798 | ||
787 | Journal *CalendarLocal::journal( const QString &uid ) | 799 | Journal *CalendarLocal::journal( const QString &uid ) |
788 | { | 800 | { |
789 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 801 | Journal * retVal = 0; |
790 | if ( it->calEnabled() && it->uid() == uid ) | 802 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
791 | return it; | 803 | if ( it->calEnabled() && it->uid() == uid ) { |
792 | 804 | if ( retVal ) { | |
793 | return 0; | 805 | if ( retVal->calID() > it->calID() ) { |
806 | retVal = it; | ||
807 | } | ||
808 | } else { | ||
809 | retVal = it; | ||
810 | } | ||
811 | } | ||
812 | return retVal; | ||
794 | } | 813 | } |
795 | 814 | ||
796 | QPtrList<Journal> CalendarLocal::journals() | 815 | QPtrList<Journal> CalendarLocal::journals() |
797 | { | 816 | { |
798 | QPtrList<Journal> el; | 817 | QPtrList<Journal> el; |
799 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 818 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
800 | if ( it->calEnabled() ) el.append( it ); | 819 | if ( it->calEnabled() ) el.append( it ); |
801 | return el; | 820 | return el; |
802 | } | 821 | } |
803 | void CalendarLocal::setCalendarRemove( int id ) | 822 | void CalendarLocal::setCalendarRemove( int id ) |
804 | { | 823 | { |
805 | 824 | ||
806 | { | 825 | { |
807 | QPtrList<Event> EventList = mEventList; | 826 | QPtrList<Event> EventList = mEventList; |
808 | Event * ev = EventList.first(); | 827 | Event * ev = EventList.first(); |
809 | while ( ev ) { | 828 | while ( ev ) { |
810 | if ( ev->calID() == id ) | 829 | if ( ev->calID() == id ) |
811 | deleteEvent( ev ); | 830 | deleteEvent( ev ); |
812 | ev = EventList.next(); | 831 | ev = EventList.next(); |
813 | } | 832 | } |
814 | } | 833 | } |
815 | { | 834 | { |
816 | 835 | ||
817 | QPtrList<Todo> TodoList = mTodoList; | 836 | QPtrList<Todo> TodoList = mTodoList; |
818 | Todo * ev = TodoList.first(); | 837 | Todo * ev = TodoList.first(); |
819 | while ( ev ) { | 838 | while ( ev ) { |
820 | if ( ev->calID() == id ) | 839 | if ( ev->calID() == id ) |
821 | deleteTodo( ev ); | 840 | deleteTodo( ev ); |
822 | ev = TodoList.next(); | 841 | ev = TodoList.next(); |
823 | } | 842 | } |
824 | } | 843 | } |
825 | { | 844 | { |
826 | QPtrList<Journal> JournalList = mJournalList; | 845 | QPtrList<Journal> JournalList = mJournalList; |
827 | Journal * ev = JournalList.first(); | 846 | Journal * ev = JournalList.first(); |
828 | while ( ev ) { | 847 | while ( ev ) { |
829 | if ( ev->calID() == id ) | 848 | if ( ev->calID() == id ) |
830 | deleteJournal( ev ); | 849 | deleteJournal( ev ); |
831 | ev = JournalList.next(); | 850 | ev = JournalList.next(); |
832 | } | 851 | } |
833 | } | 852 | } |
834 | 853 | ||
835 | if ( mUndoIncidence ) delete mUndoIncidence; | 854 | if ( mUndoIncidence ) delete mUndoIncidence; |
836 | mUndoIncidence = 0; | 855 | mUndoIncidence = 0; |
837 | 856 | ||
838 | } | 857 | } |
839 | 858 | ||
840 | void CalendarLocal::setCalendarEnabled( int id, bool enable ) | 859 | void CalendarLocal::setCalendarEnabled( int id, bool enable ) |
841 | { | 860 | { |
842 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 861 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
843 | if ( it->calID() == id ) it->setCalEnabled( enable ); | 862 | if ( it->calID() == id ) it->setCalEnabled( enable ); |
844 | 863 | ||
845 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 864 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
846 | if ( it->calID() == id ) it->setCalEnabled( enable ); | 865 | if ( it->calID() == id ) it->setCalEnabled( enable ); |
847 | 866 | ||
848 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 867 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
849 | if ( it->calID() == id ) it->setCalEnabled( enable ); | 868 | if ( it->calID() == id ) it->setCalEnabled( enable ); |
850 | 869 | ||
851 | } | 870 | } |
852 | 871 | ||
853 | void CalendarLocal::setReadOnly( int id, bool enable ) | 872 | void CalendarLocal::setReadOnly( int id, bool enable ) |
854 | { | 873 | { |
855 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 874 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
856 | if ( it->calID() == id ) it->setReadOnly( enable ); | 875 | if ( it->calID() == id ) it->setReadOnly( enable ); |
857 | 876 | ||
858 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 877 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
859 | if ( it->calID() == id ) it->setReadOnly( enable ); | 878 | if ( it->calID() == id ) it->setReadOnly( enable ); |
860 | 879 | ||
861 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 880 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
862 | if ( it->calID() == id ) it->setReadOnly( enable ); | 881 | if ( it->calID() == id ) it->setReadOnly( enable ); |
863 | 882 | ||
864 | } | 883 | } |
865 | 884 | ||
866 | void CalendarLocal::setAlarmEnabled( int id, bool enable ) | 885 | void CalendarLocal::setAlarmEnabled( int id, bool enable ) |
867 | { | 886 | { |
868 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 887 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
869 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); | 888 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); |
870 | 889 | ||
871 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 890 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
872 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); | 891 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); |
873 | 892 | ||
874 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 893 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
875 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); | 894 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); |
876 | reInitAlarmSettings(); | 895 | reInitAlarmSettings(); |
877 | 896 | ||
878 | } | 897 | } |
879 | void CalendarLocal::setDefaultCalendarEnabledOnly() | 898 | void CalendarLocal::setDefaultCalendarEnabledOnly() |
880 | { | 899 | { |
881 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 900 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
882 | it->setCalEnabled( it->calID() == mDefaultCalendar ); | 901 | it->setCalEnabled( it->calID() == mDefaultCalendar ); |
883 | 902 | ||
884 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 903 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
885 | it->setCalEnabled( it->calID() == mDefaultCalendar); | 904 | it->setCalEnabled( it->calID() == mDefaultCalendar); |
886 | 905 | ||
887 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 906 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
888 | it->setCalEnabled( it->calID() == mDefaultCalendar); | 907 | it->setCalEnabled( it->calID() == mDefaultCalendar); |
889 | 908 | ||