author | zautrix <zautrix> | 2005-10-22 16:49:42 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-10-22 16:49:42 (UTC) |
commit | 3ec18dd19fdf4eb7e763b8022f90de83249facfd (patch) (unidiff) | |
tree | abc6c8568c33b70afd8abc46ae9495e5d862cba1 /libkcal/calendarlocal.cpp | |
parent | c643664ae97e757afda1012dc998b49e6cc2d575 (diff) | |
download | kdepimpi-3ec18dd19fdf4eb7e763b8022f90de83249facfd.zip kdepimpi-3ec18dd19fdf4eb7e763b8022f90de83249facfd.tar.gz kdepimpi-3ec18dd19fdf4eb7e763b8022f90de83249facfd.tar.bz2 |
fixxx
-rw-r--r-- | libkcal/calendarlocal.cpp | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index 1a1c6be..0ddfeca 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp | |||
@@ -263,399 +263,423 @@ void CalendarLocal::close() | |||
263 | mJournalList.clear(); | 263 | mJournalList.clear(); |
264 | 264 | ||
265 | mEventList.setAutoDelete( false ); | 265 | mEventList.setAutoDelete( false ); |
266 | mTodoList.setAutoDelete( false ); | 266 | mTodoList.setAutoDelete( false ); |
267 | mJournalList.setAutoDelete( false ); | 267 | mJournalList.setAutoDelete( false ); |
268 | 268 | ||
269 | setModified( false ); | 269 | setModified( false ); |
270 | } | 270 | } |
271 | 271 | ||
272 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) | 272 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) |
273 | { | 273 | { |
274 | QString cat; | 274 | QString cat; |
275 | bool isBirthday = true; | 275 | bool isBirthday = true; |
276 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { | 276 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { |
277 | isBirthday = false; | 277 | isBirthday = false; |
278 | cat = i18n( "Anniversary" ); | 278 | cat = i18n( "Anniversary" ); |
279 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { | 279 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { |
280 | isBirthday = true; | 280 | isBirthday = true; |
281 | cat = i18n( "Birthday" ); | 281 | cat = i18n( "Birthday" ); |
282 | } else { | 282 | } else { |
283 | qDebug("addAnniversaryNoDup called without fitting category! "); | 283 | qDebug("addAnniversaryNoDup called without fitting category! "); |
284 | return false; | 284 | return false; |
285 | } | 285 | } |
286 | Event * eve; | 286 | Event * eve; |
287 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 287 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
288 | if ( !(eve->categories().contains( cat ) )) | 288 | if ( !(eve->categories().contains( cat ) )) |
289 | continue; | 289 | continue; |
290 | // now we have an event with fitting category | 290 | // now we have an event with fitting category |
291 | if ( eve->dtStart().date() != event->dtStart().date() ) | 291 | if ( eve->dtStart().date() != event->dtStart().date() ) |
292 | continue; | 292 | continue; |
293 | // now we have an event with fitting category+date | 293 | // now we have an event with fitting category+date |
294 | if ( eve->summary() != event->summary() ) | 294 | if ( eve->summary() != event->summary() ) |
295 | continue; | 295 | continue; |
296 | // now we have an event with fitting category+date+summary | 296 | // now we have an event with fitting category+date+summary |
297 | return false; | 297 | return false; |
298 | } | 298 | } |
299 | return addEvent( event ); | 299 | return addEvent( event ); |
300 | 300 | ||
301 | } | 301 | } |
302 | bool CalendarLocal::addEventNoDup( Event *event ) | 302 | bool CalendarLocal::addEventNoDup( Event *event ) |
303 | { | 303 | { |
304 | Event * eve; | 304 | Event * eve; |
305 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 305 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
306 | if ( *eve == *event ) { | 306 | if ( *eve == *event ) { |
307 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); | 307 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); |
308 | return false; | 308 | return false; |
309 | } | 309 | } |
310 | } | 310 | } |
311 | return addEvent( event ); | 311 | return addEvent( event ); |
312 | } | 312 | } |
313 | 313 | ||
314 | bool CalendarLocal::addEvent( Event *event ) | 314 | bool CalendarLocal::addEvent( Event *event ) |
315 | { | 315 | { |
316 | insertEvent( event ); | 316 | insertEvent( event ); |
317 | 317 | ||
318 | event->registerObserver( this ); | 318 | event->registerObserver( this ); |
319 | 319 | ||
320 | setModified( true ); | 320 | setModified( true ); |
321 | if ( event->calID() == 0 ) | 321 | if ( event->calID() == 0 ) |
322 | event->setCalID( mDefaultCalendar ); | 322 | event->setCalID( mDefaultCalendar ); |
323 | event->setCalEnabled( true ); | 323 | event->setCalEnabled( true ); |
324 | 324 | ||
325 | return true; | 325 | return true; |
326 | } | 326 | } |
327 | 327 | ||
328 | void CalendarLocal::deleteEvent( Event *event ) | 328 | void CalendarLocal::deleteEvent( Event *event ) |
329 | { | 329 | { |
330 | clearUndo(event); | 330 | clearUndo(event); |
331 | if ( mEventList.removeRef( event ) ) { | 331 | if ( mEventList.removeRef( event ) ) { |
332 | setModified( true ); | 332 | setModified( true ); |
333 | } | 333 | } |
334 | } | 334 | } |
335 | 335 | ||
336 | 336 | ||
337 | Event *CalendarLocal::event( const QString &uid ) | 337 | Event *CalendarLocal::event( const QString &uid ) |
338 | { | 338 | { |
339 | Event *event; | 339 | Event *event; |
340 | Event *retVal = 0; | 340 | Event *retVal = 0; |
341 | for ( event = mEventList.first(); event; event = mEventList.next() ) { | 341 | for ( event = mEventList.first(); event; event = mEventList.next() ) { |
342 | if ( event->calEnabled() && event->uid() == uid ) { | 342 | if ( event->calEnabled() && event->uid() == uid ) { |
343 | if ( retVal ) { | 343 | if ( retVal ) { |
344 | if ( retVal->calID() > event->calID() ) { | 344 | if ( retVal->calID() > event->calID() ) { |
345 | retVal = event; | 345 | retVal = event; |
346 | } | 346 | } |
347 | } else { | 347 | } else { |
348 | retVal = event; | 348 | retVal = event; |
349 | } | 349 | } |
350 | } | 350 | } |
351 | } | 351 | } |
352 | return retVal; | 352 | return retVal; |
353 | } | 353 | } |
354 | bool CalendarLocal::addTodoNoDup( Todo *todo ) | 354 | bool CalendarLocal::addTodoNoDup( Todo *todo ) |
355 | { | 355 | { |
356 | Todo * eve; | 356 | Todo * eve; |
357 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { | 357 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { |
358 | if ( *eve == *todo ) { | 358 | if ( *eve == *todo ) { |
359 | //qDebug("duplicate todo found! not inserted! "); | 359 | //qDebug("duplicate todo found! not inserted! "); |
360 | return false; | 360 | return false; |
361 | } | 361 | } |
362 | } | 362 | } |
363 | return addTodo( todo ); | 363 | return addTodo( todo ); |
364 | } | 364 | } |
365 | bool CalendarLocal::addTodo( Todo *todo ) | 365 | bool CalendarLocal::addTodo( Todo *todo ) |
366 | { | 366 | { |
367 | mTodoList.append( todo ); | 367 | mTodoList.append( todo ); |
368 | 368 | ||
369 | todo->registerObserver( this ); | 369 | todo->registerObserver( this ); |
370 | 370 | ||
371 | // Set up subtask relations | 371 | // Set up subtask relations |
372 | setupRelations( todo ); | 372 | setupRelations( todo ); |
373 | 373 | ||
374 | setModified( true ); | 374 | setModified( true ); |
375 | if ( todo->calID() == 0 ) | 375 | if ( todo->calID() == 0 ) |
376 | todo->setCalID( mDefaultCalendar ); | 376 | todo->setCalID( mDefaultCalendar ); |
377 | todo->setCalEnabled( true ); | 377 | todo->setCalEnabled( true ); |
378 | return true; | 378 | return true; |
379 | } | 379 | } |
380 | 380 | ||
381 | void CalendarLocal::deleteTodo( Todo *todo ) | 381 | void CalendarLocal::deleteTodo( Todo *todo ) |
382 | { | 382 | { |
383 | // Handle orphaned children | 383 | // Handle orphaned children |
384 | removeRelations( todo ); | 384 | removeRelations( todo ); |
385 | clearUndo(todo); | 385 | clearUndo(todo); |
386 | 386 | ||
387 | if ( mTodoList.removeRef( todo ) ) { | 387 | if ( mTodoList.removeRef( todo ) ) { |
388 | setModified( true ); | 388 | setModified( true ); |
389 | } | 389 | } |
390 | } | 390 | } |
391 | 391 | ||
392 | QPtrList<Todo> CalendarLocal::rawTodos() | 392 | QPtrList<Todo> CalendarLocal::rawTodos() |
393 | { | 393 | { |
394 | QPtrList<Todo> el; | 394 | QPtrList<Todo> el; |
395 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 395 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
396 | if ( it->calEnabled() ) el.append( it ); | 396 | if ( it->calEnabled() ) el.append( it ); |
397 | return el; | 397 | return el; |
398 | } | 398 | } |
399 | Todo *CalendarLocal::todo( QString syncProf, QString id ) | 399 | Todo *CalendarLocal::todo( QString syncProf, QString id ) |
400 | { | 400 | { |
401 | Todo *todo; | 401 | Todo *todo; |
402 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 402 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
403 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; | 403 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; |
404 | } | 404 | } |
405 | 405 | ||
406 | return 0; | 406 | return 0; |
407 | } | 407 | } |
408 | void CalendarLocal::removeSyncInfo( QString syncProfile) | 408 | void CalendarLocal::removeSyncInfo( QString syncProfile) |
409 | { | 409 | { |
410 | QPtrList<Incidence> all = rawIncidences() ; | 410 | QPtrList<Incidence> all = rawIncidences() ; |
411 | Incidence *inc; | 411 | Incidence *inc; |
412 | for ( inc = all.first(); inc; inc = all.next() ) { | 412 | for ( inc = all.first(); inc; inc = all.next() ) { |
413 | inc->removeID( syncProfile ); | 413 | inc->removeID( syncProfile ); |
414 | } | 414 | } |
415 | if ( syncProfile.isEmpty() ) { | 415 | if ( syncProfile.isEmpty() ) { |
416 | QPtrList<Event> el; | 416 | QPtrList<Event> el; |
417 | Event *todo; | 417 | Event *todo; |
418 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 418 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
419 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 419 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
420 | el.append( todo ); | 420 | el.append( todo ); |
421 | } | 421 | } |
422 | for ( todo = el.first(); todo; todo = el.next() ) { | 422 | for ( todo = el.first(); todo; todo = el.next() ) { |
423 | deleteIncidence ( todo ); | 423 | deleteIncidence ( todo ); |
424 | } | 424 | } |
425 | } else { | 425 | } else { |
426 | Event *lse = event( "last-syncEvent-"+ syncProfile); | 426 | Event *lse = event( "last-syncEvent-"+ syncProfile); |
427 | if ( lse ) | 427 | if ( lse ) |
428 | deleteIncidence ( lse ); | 428 | deleteIncidence ( lse ); |
429 | } | 429 | } |
430 | } | 430 | } |
431 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() | 431 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() |
432 | { | 432 | { |
433 | QPtrList<Event> el; | 433 | QPtrList<Event> el; |
434 | Event *todo; | 434 | Event *todo; |
435 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 435 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
436 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 436 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
437 | if ( todo->summary().left(3) == "E: " ) | 437 | if ( todo->summary().left(3) == "E: " ) |
438 | el.append( todo ); | 438 | el.append( todo ); |
439 | } | 439 | } |
440 | 440 | ||
441 | return el; | 441 | return el; |
442 | 442 | ||
443 | } | 443 | } |
444 | Event *CalendarLocal::event( QString syncProf, QString id ) | 444 | Event *CalendarLocal::event( QString syncProf, QString id ) |
445 | { | 445 | { |
446 | Event *todo; | 446 | Event *todo; |
447 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 447 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
448 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; | 448 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; |
449 | } | 449 | } |
450 | 450 | ||
451 | return 0; | 451 | return 0; |
452 | } | 452 | } |
453 | Todo *CalendarLocal::todo( const QString &uid ) | 453 | Todo *CalendarLocal::todo( const QString &uid ) |
454 | { | 454 | { |
455 | Todo *todo;; | 455 | Todo *todo; |
456 | Todo *retVal = 0; | 456 | Todo *retVal = 0; |
457 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 457 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
458 | if ( todo->calEnabled() && todo->uid() == uid ) { | 458 | if ( todo->calEnabled() && todo->uid() == uid ) { |
459 | if ( retVal ) { | 459 | if ( retVal ) { |
460 | if ( retVal->calID() > todo->calID() ) { | 460 | if ( retVal->calID() > todo->calID() ) { |
461 | retVal = todo; | 461 | retVal = todo; |
462 | } | 462 | } |
463 | } else { | 463 | } else { |
464 | retVal = todo; | 464 | retVal = todo; |
465 | } | 465 | } |
466 | } | 466 | } |
467 | } | 467 | } |
468 | return retVal; | 468 | return retVal; |
469 | } | 469 | } |
470 | void CalendarLocal::getIncidenceCount( int calId, int& events, int & todos, int & journals) | ||
471 | { | ||
472 | events = 0; | ||
473 | todos = 0; | ||
474 | journals = 0; | ||
475 | { | ||
476 | Todo *todo; | ||
477 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | ||
478 | if ( todo->calID() == calId ) | ||
479 | ++todos; | ||
480 | } | ||
481 | } | ||
482 | { | ||
483 | Event *todo; | ||
484 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | ||
485 | if ( todo->calID() == calId ) | ||
486 | ++events; | ||
487 | |||
488 | } | ||
489 | } | ||
490 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | ||
491 | if ( it->calID() == calId ) ++journals; | ||
492 | |||
493 | } | ||
470 | QString CalendarLocal::nextSummary() const | 494 | QString CalendarLocal::nextSummary() const |
471 | { | 495 | { |
472 | return mNextSummary; | 496 | return mNextSummary; |
473 | } | 497 | } |
474 | QDateTime CalendarLocal::nextAlarmEventDateTime() const | 498 | QDateTime CalendarLocal::nextAlarmEventDateTime() const |
475 | { | 499 | { |
476 | return mNextAlarmEventDateTime; | 500 | return mNextAlarmEventDateTime; |
477 | } | 501 | } |
478 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) | 502 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) |
479 | { | 503 | { |
480 | //mNextAlarmIncidence | 504 | //mNextAlarmIncidence |
481 | //mNextAlarmDateTime | 505 | //mNextAlarmDateTime |
482 | //return mNextSummary; | 506 | //return mNextSummary; |
483 | //return mNextAlarmEventDateTime; | 507 | //return mNextAlarmEventDateTime; |
484 | bool newNextAlarm = false; | 508 | bool newNextAlarm = false; |
485 | bool computeNextAlarm = false; | 509 | bool computeNextAlarm = false; |
486 | bool ok; | 510 | bool ok; |
487 | int offset; | 511 | int offset; |
488 | QDateTime nextA; | 512 | QDateTime nextA; |
489 | // QString nextSum; | 513 | // QString nextSum; |
490 | //QDateTime nextEvent; | 514 | //QDateTime nextEvent; |
491 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { | 515 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { |
492 | computeNextAlarm = true; | 516 | computeNextAlarm = true; |
493 | } else { | 517 | } else { |
494 | if ( ! deleted ) { | 518 | if ( ! deleted ) { |
495 | nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; | 519 | nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; |
496 | if ( ok ) { | 520 | if ( ok ) { |
497 | if ( nextA < mNextAlarmDateTime ) { | 521 | if ( nextA < mNextAlarmDateTime ) { |
498 | deRegisterAlarm(); | 522 | deRegisterAlarm(); |
499 | mNextAlarmDateTime = nextA; | 523 | mNextAlarmDateTime = nextA; |
500 | mNextSummary = incidence->summary(); | 524 | mNextSummary = incidence->summary(); |
501 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; | 525 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; |
502 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 526 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
503 | newNextAlarm = true; | 527 | newNextAlarm = true; |
504 | mNextAlarmIncidence = incidence; | 528 | mNextAlarmIncidence = incidence; |
505 | } else { | 529 | } else { |
506 | if ( incidence == mNextAlarmIncidence ) { | 530 | if ( incidence == mNextAlarmIncidence ) { |
507 | computeNextAlarm = true; | 531 | computeNextAlarm = true; |
508 | } | 532 | } |
509 | } | 533 | } |
510 | } else { | 534 | } else { |
511 | if ( mNextAlarmIncidence == incidence ) { | 535 | if ( mNextAlarmIncidence == incidence ) { |
512 | computeNextAlarm = true; | 536 | computeNextAlarm = true; |
513 | } | 537 | } |
514 | } | 538 | } |
515 | } else { // deleted | 539 | } else { // deleted |
516 | if ( incidence == mNextAlarmIncidence ) { | 540 | if ( incidence == mNextAlarmIncidence ) { |
517 | computeNextAlarm = true; | 541 | computeNextAlarm = true; |
518 | } | 542 | } |
519 | } | 543 | } |
520 | } | 544 | } |
521 | if ( computeNextAlarm ) { | 545 | if ( computeNextAlarm ) { |
522 | deRegisterAlarm(); | 546 | deRegisterAlarm(); |
523 | nextA = nextAlarm( 1000 ); | 547 | nextA = nextAlarm( 1000 ); |
524 | if (! mNextAlarmIncidence ) { | 548 | if (! mNextAlarmIncidence ) { |
525 | return; | 549 | return; |
526 | } | 550 | } |
527 | newNextAlarm = true; | 551 | newNextAlarm = true; |
528 | } | 552 | } |
529 | if ( newNextAlarm ) | 553 | if ( newNextAlarm ) |
530 | registerAlarm(); | 554 | registerAlarm(); |
531 | } | 555 | } |
532 | QString CalendarLocal:: getAlarmNotification() | 556 | QString CalendarLocal:: getAlarmNotification() |
533 | { | 557 | { |
534 | QString ret; | 558 | QString ret; |
535 | // this should not happen | 559 | // this should not happen |
536 | if (! mNextAlarmIncidence ) | 560 | if (! mNextAlarmIncidence ) |
537 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; | 561 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; |
538 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); | 562 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); |
539 | if ( alarm->type() == Alarm::Procedure ) { | 563 | if ( alarm->type() == Alarm::Procedure ) { |
540 | ret = "proc_alarm" + alarm->programFile()+"+++"; | 564 | ret = "proc_alarm" + alarm->programFile()+"+++"; |
541 | } else { | 565 | } else { |
542 | ret = "audio_alarm" +alarm->audioFile() +"+++"; | 566 | ret = "audio_alarm" +alarm->audioFile() +"+++"; |
543 | } | 567 | } |
544 | ret += "cal_alarm"+ mNextSummary.left( 25 ); | 568 | ret += "cal_alarm"+ mNextSummary.left( 25 ); |
545 | if ( mNextSummary.length() > 25 ) | 569 | if ( mNextSummary.length() > 25 ) |
546 | ret += "\n" + mNextSummary.mid(25, 25 ); | 570 | ret += "\n" + mNextSummary.mid(25, 25 ); |
547 | ret+= "\n"+mNextAlarmEventDateTimeString; | 571 | ret+= "\n"+mNextAlarmEventDateTimeString; |
548 | return ret; | 572 | return ret; |
549 | } | 573 | } |
550 | void CalendarLocal::registerAlarm() | 574 | void CalendarLocal::registerAlarm() |
551 | { | 575 | { |
552 | mLastAlarmNotificationString = getAlarmNotification(); | 576 | mLastAlarmNotificationString = getAlarmNotification(); |
553 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); | 577 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); |
554 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 578 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
555 | // #ifndef DESKTOP_VERSION | 579 | // #ifndef DESKTOP_VERSION |
556 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); | 580 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); |
557 | // #endif | 581 | // #endif |
558 | } | 582 | } |
559 | void CalendarLocal::deRegisterAlarm() | 583 | void CalendarLocal::deRegisterAlarm() |
560 | { | 584 | { |
561 | if ( mLastAlarmNotificationString.isNull() ) | 585 | if ( mLastAlarmNotificationString.isNull() ) |
562 | return; | 586 | return; |
563 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); | 587 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); |
564 | 588 | ||
565 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 589 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
566 | mNextAlarmEventDateTime = QDateTime(); | 590 | mNextAlarmEventDateTime = QDateTime(); |
567 | // #ifndef DESKTOP_VERSION | 591 | // #ifndef DESKTOP_VERSION |
568 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); | 592 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); |
569 | // #endif | 593 | // #endif |
570 | } | 594 | } |
571 | 595 | ||
572 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) | 596 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) |
573 | { | 597 | { |
574 | QPtrList<Todo> todos; | 598 | QPtrList<Todo> todos; |
575 | 599 | ||
576 | Todo *todo; | 600 | Todo *todo; |
577 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 601 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
578 | if ( !todo->calEnabled() ) continue; | 602 | if ( !todo->calEnabled() ) continue; |
579 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { | 603 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { |
580 | todos.append( todo ); | 604 | todos.append( todo ); |
581 | } | 605 | } |
582 | } | 606 | } |
583 | 607 | ||
584 | filter()->apply( &todos ); | 608 | filter()->apply( &todos ); |
585 | return todos; | 609 | return todos; |
586 | } | 610 | } |
587 | void CalendarLocal::reInitAlarmSettings() | 611 | void CalendarLocal::reInitAlarmSettings() |
588 | { | 612 | { |
589 | if ( !mNextAlarmIncidence ) { | 613 | if ( !mNextAlarmIncidence ) { |
590 | nextAlarm( 1000 ); | 614 | nextAlarm( 1000 ); |
591 | } | 615 | } |
592 | deRegisterAlarm(); | 616 | deRegisterAlarm(); |
593 | mNextAlarmIncidence = 0; | 617 | mNextAlarmIncidence = 0; |
594 | checkAlarmForIncidence( 0, false ); | 618 | checkAlarmForIncidence( 0, false ); |
595 | 619 | ||
596 | } | 620 | } |
597 | 621 | ||
598 | 622 | ||
599 | 623 | ||
600 | QDateTime CalendarLocal::nextAlarm( int daysTo ) | 624 | QDateTime CalendarLocal::nextAlarm( int daysTo ) |
601 | { | 625 | { |
602 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); | 626 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); |
603 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); | 627 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); |
604 | QDateTime next; | 628 | QDateTime next; |
605 | Event *e; | 629 | Event *e; |
606 | bool ok; | 630 | bool ok; |
607 | bool found = false; | 631 | bool found = false; |
608 | int offset; | 632 | int offset; |
609 | mNextAlarmIncidence = 0; | 633 | mNextAlarmIncidence = 0; |
610 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 634 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
611 | if ( !e->calEnabled() ) continue; | 635 | if ( !e->calEnabled() ) continue; |
612 | next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; | 636 | next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; |
613 | if ( ok ) { | 637 | if ( ok ) { |
614 | if ( next < nextA ) { | 638 | if ( next < nextA ) { |
615 | nextA = next; | 639 | nextA = next; |
616 | found = true; | 640 | found = true; |
617 | mNextSummary = e->summary(); | 641 | mNextSummary = e->summary(); |
618 | mNextAlarmEventDateTime = next.addSecs(offset ) ; | 642 | mNextAlarmEventDateTime = next.addSecs(offset ) ; |
619 | mNextAlarmIncidence = (Incidence *) e; | 643 | mNextAlarmIncidence = (Incidence *) e; |
620 | } | 644 | } |
621 | } | 645 | } |
622 | } | 646 | } |
623 | Todo *t; | 647 | Todo *t; |
624 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 648 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
625 | if ( !t->calEnabled() ) continue; | 649 | if ( !t->calEnabled() ) continue; |
626 | next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; | 650 | next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; |
627 | if ( ok ) { | 651 | if ( ok ) { |
628 | if ( next < nextA ) { | 652 | if ( next < nextA ) { |
629 | nextA = next; | 653 | nextA = next; |
630 | found = true; | 654 | found = true; |
631 | mNextSummary = t->summary(); | 655 | mNextSummary = t->summary(); |
632 | mNextAlarmEventDateTime = next.addSecs(offset ); | 656 | mNextAlarmEventDateTime = next.addSecs(offset ); |
633 | mNextAlarmIncidence = (Incidence *) t; | 657 | mNextAlarmIncidence = (Incidence *) t; |
634 | } | 658 | } |
635 | } | 659 | } |
636 | } | 660 | } |
637 | if ( mNextAlarmIncidence ) { | 661 | if ( mNextAlarmIncidence ) { |
638 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 662 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
639 | mNextAlarmDateTime = nextA; | 663 | mNextAlarmDateTime = nextA; |
640 | } | 664 | } |
641 | return nextA; | 665 | return nextA; |
642 | } | 666 | } |
643 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) | 667 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) |
644 | { | 668 | { |
645 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); | 669 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); |
646 | } | 670 | } |
647 | 671 | ||
648 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) | 672 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) |
649 | { | 673 | { |
650 | 674 | ||
651 | Alarm::List alarms; | 675 | Alarm::List alarms; |
652 | 676 | ||
653 | Event *e; | 677 | Event *e; |
654 | 678 | ||
655 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 679 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
656 | if ( !e->calEnabled() ) continue; | 680 | if ( !e->calEnabled() ) continue; |
657 | if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); | 681 | if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); |
658 | else appendAlarms( alarms, e, from, to ); | 682 | else appendAlarms( alarms, e, from, to ); |
659 | } | 683 | } |
660 | 684 | ||
661 | Todo *t; | 685 | Todo *t; |