-rw-r--r-- | korganizer/calendarview.cpp | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp index bf98ad4..c3c3d47 100644 --- a/korganizer/calendarview.cpp +++ b/korganizer/calendarview.cpp | |||
@@ -446,24 +446,26 @@ void CalendarView::init() | |||
446 | mDateFrame->setCaption( i18n( "Pick a date to display")); | 446 | mDateFrame->setCaption( i18n( "Pick a date to display")); |
447 | mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() ); | 447 | mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() ); |
448 | 448 | ||
449 | connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate))); | 449 | connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate))); |
450 | 450 | ||
451 | mEventEditor = mDialogManager->getEventEditor(); | 451 | mEventEditor = mDialogManager->getEventEditor(); |
452 | mTodoEditor = mDialogManager->getTodoEditor(); | 452 | mTodoEditor = mDialogManager->getTodoEditor(); |
453 | 453 | ||
454 | mFlagEditDescription = false; | 454 | mFlagEditDescription = false; |
455 | 455 | ||
456 | mSuspendTimer = new QTimer( this ); | 456 | mSuspendTimer = new QTimer( this ); |
457 | mAlarmTimer = new QTimer( this ); | 457 | mAlarmTimer = new QTimer( this ); |
458 | mRecheckAlarmTimer = new QTimer( this ); | ||
459 | connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) ); | ||
458 | connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) ); | 460 | connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) ); |
459 | connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) ); | 461 | connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) ); |
460 | mAlarmDialog = new AlarmDialog( this ); | 462 | mAlarmDialog = new AlarmDialog( this ); |
461 | connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) ); | 463 | connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) ); |
462 | mAlarmDialog->setServerNotification( false ); | 464 | mAlarmDialog->setServerNotification( false ); |
463 | mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime ); | 465 | mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime ); |
464 | } | 466 | } |
465 | 467 | ||
466 | 468 | ||
467 | CalendarView::~CalendarView() | 469 | CalendarView::~CalendarView() |
468 | { | 470 | { |
469 | // kdDebug() << "~CalendarView()" << endl; | 471 | // kdDebug() << "~CalendarView()" << endl; |
@@ -482,27 +484,32 @@ void CalendarView::timerAlarm() | |||
482 | } | 484 | } |
483 | 485 | ||
484 | void CalendarView::suspendAlarm() | 486 | void CalendarView::suspendAlarm() |
485 | { | 487 | { |
486 | //qDebug(" CalendarView::suspendAlarm() "); | 488 | //qDebug(" CalendarView::suspendAlarm() "); |
487 | computeAlarm(mSuspendAlarmNotification ); | 489 | computeAlarm(mSuspendAlarmNotification ); |
488 | 490 | ||
489 | } | 491 | } |
490 | 492 | ||
491 | void CalendarView::startAlarm( QString mess , QString filename) | 493 | void CalendarView::startAlarm( QString mess , QString filename) |
492 | { | 494 | { |
493 | mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount ); | 495 | mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount ); |
496 | QTimer::singleShot( 3000, this, SLOT( checkNextTimerAlarm() ) ); | ||
494 | 497 | ||
495 | } | 498 | } |
496 | 499 | ||
500 | void CalendarView::checkNextTimerAlarm() | ||
501 | { | ||
502 | mCalendar->checkAlarmForIncidence( 0, true ); | ||
503 | } | ||
497 | 504 | ||
498 | void CalendarView::computeAlarm( QString msg ) | 505 | void CalendarView::computeAlarm( QString msg ) |
499 | { | 506 | { |
500 | 507 | ||
501 | QString mess = msg; | 508 | QString mess = msg; |
502 | QString mAlarmMessage = mess.mid( 9 ); | 509 | QString mAlarmMessage = mess.mid( 9 ); |
503 | QString filename = MainWindow::resourcePath(); | 510 | QString filename = MainWindow::resourcePath(); |
504 | filename += "koalarm.wav"; | 511 | filename += "koalarm.wav"; |
505 | QString tempfilename; | 512 | QString tempfilename; |
506 | if ( mess.left( 13 ) == "suspend_alarm") { | 513 | if ( mess.left( 13 ) == "suspend_alarm") { |
507 | bool error = false; | 514 | bool error = false; |
508 | int len = mess.mid( 13 ).find("+++"); | 515 | int len = mess.mid( 13 ).find("+++"); |
@@ -595,30 +602,48 @@ void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString ¬i ) | |||
595 | 602 | ||
596 | } | 603 | } |
597 | 604 | ||
598 | void CalendarView::addAlarm(const QDateTime &qdt, const QString ¬i ) | 605 | void CalendarView::addAlarm(const QDateTime &qdt, const QString ¬i ) |
599 | { | 606 | { |
600 | //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); | 607 | //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); |
601 | if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { | 608 | if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { |
602 | #ifndef DESKTOP_VERSION | 609 | #ifndef DESKTOP_VERSION |
603 | AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() ); | 610 | AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() ); |
604 | #endif | 611 | #endif |
605 | return; | 612 | return; |
606 | } | 613 | } |
614 | int maxSec; | ||
615 | //maxSec = 5; //testing only | ||
616 | maxSec = 86400+3600; // one day+1hour | ||
607 | mAlarmNotification = noti; | 617 | mAlarmNotification = noti; |
608 | int ms = QDateTime::currentDateTime().secsTo( qdt )*1000; | 618 | int sec = QDateTime::currentDateTime().secsTo( qdt ); |
609 | //qDebug("Alarm timer started with secs: %d ", ms/1000); | 619 | if ( sec > maxSec ) { |
610 | mAlarmTimer->start( ms , true ); | 620 | mRecheckAlarmTimer->start( maxSec * 1000 ); |
621 | // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec ); | ||
622 | return; | ||
623 | } else { | ||
624 | mRecheckAlarmTimer->stop(); | ||
625 | } | ||
626 | //qDebug("Alarm timer started with secs: %d ", sec); | ||
627 | mAlarmTimer->start( sec *1000 , true ); | ||
611 | 628 | ||
612 | } | 629 | } |
630 | // called by mRecheckAlarmTimer to get next alarm | ||
631 | // we need this, because a QTimer has only a max range of 25 days | ||
632 | void CalendarView::recheckTimerAlarm() | ||
633 | { | ||
634 | mAlarmTimer->stop(); | ||
635 | mRecheckAlarmTimer->stop(); | ||
636 | mCalendar->checkAlarmForIncidence( 0, true ); | ||
637 | } | ||
613 | void CalendarView::removeAlarm(const QDateTime &qdt, const QString ¬i ) | 638 | void CalendarView::removeAlarm(const QDateTime &qdt, const QString ¬i ) |
614 | { | 639 | { |
615 | //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); | 640 | //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); |
616 | if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { | 641 | if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { |
617 | #ifndef DESKTOP_VERSION | 642 | #ifndef DESKTOP_VERSION |
618 | AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() ); | 643 | AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() ); |
619 | #endif | 644 | #endif |
620 | return; | 645 | return; |
621 | } | 646 | } |
622 | mAlarmTimer->stop(); | 647 | mAlarmTimer->stop(); |
623 | } | 648 | } |
624 | void CalendarView::selectWeekNum ( int num ) | 649 | void CalendarView::selectWeekNum ( int num ) |