author | zautrix <zautrix> | 2005-07-09 10:40:57 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-07-09 10:40:57 (UTC) |
commit | b51db424f4b1e558ab8c7c723859bb564c99d83b (patch) (unidiff) | |
tree | 2de26e6455c6b07b17cb169ef23e4170387a5fcc | |
parent | f731dd9fc5b3f14c44d4de26eb5370a79c63887c (diff) | |
download | kdepimpi-b51db424f4b1e558ab8c7c723859bb564c99d83b.zip kdepimpi-b51db424f4b1e558ab8c7c723859bb564c99d83b.tar.gz kdepimpi-b51db424f4b1e558ab8c7c723859bb564c99d83b.tar.bz2 |
fixxx
-rw-r--r-- | korganizer/calendarview.cpp | 7 | ||||
-rw-r--r-- | libkcal/calendar.h | 1 | ||||
-rw-r--r-- | libkcal/calendarlocal.cpp | 35 | ||||
-rw-r--r-- | libkcal/calendarlocal.h | 2 | ||||
-rw-r--r-- | libkcal/incidencebase.cpp | 8 | ||||
-rw-r--r-- | libkcal/incidencebase.h | 1 |
6 files changed, 41 insertions, 13 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp index ccacc52..a350c3b 100644 --- a/korganizer/calendarview.cpp +++ b/korganizer/calendarview.cpp | |||
@@ -459,1694 +459,1695 @@ void CalendarView::init() | |||
459 | "CalendarView::DateNavigator" ); | 459 | "CalendarView::DateNavigator" ); |
460 | #if 0 | 460 | #if 0 |
461 | // FIXME | 461 | // FIXME |
462 | mDateNavigator = new KDateNavigator(mLeftFrame, mCalendar, TRUE, | 462 | mDateNavigator = new KDateNavigator(mLeftFrame, mCalendar, TRUE, |
463 | "CalendarView::DateNavigator", QDate::currentDate()); | 463 | "CalendarView::DateNavigator", QDate::currentDate()); |
464 | #endif | 464 | #endif |
465 | // mDateNavigator->blockSignals( true ); | 465 | // mDateNavigator->blockSignals( true ); |
466 | //leftFrameLayout->addWidget( mDateNavigator ); | 466 | //leftFrameLayout->addWidget( mDateNavigator ); |
467 | mTodoList = new KOTodoView(mCalendar, mLeftFrame, "todolistsmall"); | 467 | mTodoList = new KOTodoView(mCalendar, mLeftFrame, "todolistsmall"); |
468 | mFilterView = new KOFilterView(&mFilters,mLeftFrame,"CalendarView::FilterView"); | 468 | mFilterView = new KOFilterView(&mFilters,mLeftFrame,"CalendarView::FilterView"); |
469 | mCalEditView = new KOCalEditView(mLeftFrame,"CalendarView::CaleditView"); | 469 | mCalEditView = new KOCalEditView(mLeftFrame,"CalendarView::CaleditView"); |
470 | connect( mCalEditView, SIGNAL( calendarEnabled (int,bool) ),mCalendar, SLOT( setCalendarEnabled(int,bool)) ); | 470 | connect( mCalEditView, SIGNAL( calendarEnabled (int,bool) ),mCalendar, SLOT( setCalendarEnabled(int,bool)) ); |
471 | connect( mCalEditView, SIGNAL( alarmEnabled(int,bool) ),mCalendar, SLOT( setAlarmEnabled(int,bool)) ); | 471 | connect( mCalEditView, SIGNAL( alarmEnabled(int,bool) ),mCalendar, SLOT( setAlarmEnabled(int,bool)) ); |
472 | connect( mCalEditView, SIGNAL( calendarReadonly(int,bool) ),this, SLOT( setCalReadOnly(int,bool)) ); | 472 | connect( mCalEditView, SIGNAL( calendarReadonly(int,bool) ),this, SLOT( setCalReadOnly(int,bool)) ); |
473 | connect( mCalEditView, SIGNAL( setCalendarDefault(int) ),mCalendar, SLOT( setDefaultCalendar(int)) ); | 473 | connect( mCalEditView, SIGNAL( setCalendarDefault(int) ),mCalendar, SLOT( setDefaultCalendar(int)) ); |
474 | connect( mCalEditView, SIGNAL( setCalendarDefault(int) ),mViewManager, SLOT( setDefaultCalendar(int)) ); | 474 | connect( mCalEditView, SIGNAL( setCalendarDefault(int) ),mViewManager, SLOT( setDefaultCalendar(int)) ); |
475 | connect( mCalEditView, SIGNAL( removeCalendar(int) ),mCalendar, SLOT( setCalendarRemove(int)) ); | 475 | connect( mCalEditView, SIGNAL( removeCalendar(int) ),mCalendar, SLOT( setCalendarRemove(int)) ); |
476 | connect( mCalEditView, SIGNAL( calendarAdded(int) ),this, SLOT( addCalendarId(int)) ); | 476 | connect( mCalEditView, SIGNAL( calendarAdded(int) ),this, SLOT( addCalendarId(int)) ); |
477 | connect( mCalEditView, SIGNAL( needsUpdate() ),this, SLOT( updateView()) ); | 477 | connect( mCalEditView, SIGNAL( needsUpdate() ),this, SLOT( updateView()) ); |
478 | connect( mCalEditView, SIGNAL( checkCalendar() ),this, SLOT( checkFiles() )); | 478 | connect( mCalEditView, SIGNAL( checkCalendar() ),this, SLOT( checkFiles() )); |
479 | connect( mCalEditView, SIGNAL( needsUpdate() ),this, SLOT( updateUnmanagedViews()) ); | 479 | connect( mCalEditView, SIGNAL( needsUpdate() ),this, SLOT( updateUnmanagedViews()) ); |
480 | 480 | ||
481 | mTodoList->setNavigator( mNavigator ); | 481 | mTodoList->setNavigator( mNavigator ); |
482 | #if 0 | 482 | #if 0 |
483 | if ( QApplication::desktop()->width() < 480 ) { | 483 | if ( QApplication::desktop()->width() < 480 ) { |
484 | leftFrameLayout->addWidget(mFilterView); | 484 | leftFrameLayout->addWidget(mFilterView); |
485 | leftFrameLayout->addWidget(mTodoList, 2 ); | 485 | leftFrameLayout->addWidget(mTodoList, 2 ); |
486 | 486 | ||
487 | } else { | 487 | } else { |
488 | leftFrameLayout->addWidget(mTodoList,2 ); | 488 | leftFrameLayout->addWidget(mTodoList,2 ); |
489 | leftFrameLayout->addWidget(mFilterView ); | 489 | leftFrameLayout->addWidget(mFilterView ); |
490 | } | 490 | } |
491 | #endif | 491 | #endif |
492 | mFilterView->hide(); | 492 | mFilterView->hide(); |
493 | mCalEditView->hide(); | 493 | mCalEditView->hide(); |
494 | QWidget *rightBox = new QWidget( mMainFrame ); | 494 | QWidget *rightBox = new QWidget( mMainFrame ); |
495 | //mainBoxLayout->addWidget ( rightBox, 10 ); | 495 | //mainBoxLayout->addWidget ( rightBox, 10 ); |
496 | QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); | 496 | QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); |
497 | mRightFrame = new QWidgetStack( rightBox ); | 497 | mRightFrame = new QWidgetStack( rightBox ); |
498 | rightLayout->addWidget( mRightFrame, 10 ); | 498 | rightLayout->addWidget( mRightFrame, 10 ); |
499 | 499 | ||
500 | //mLeftFrame = (QWidget *)leftFrame; | 500 | //mLeftFrame = (QWidget *)leftFrame; |
501 | if ( KOPrefs::instance()->mVerticalScreen ) { | 501 | if ( KOPrefs::instance()->mVerticalScreen ) { |
502 | //mDateNavigator->setFixedHeight( mDateNavigator->sizeHint().height() ); | 502 | //mDateNavigator->setFixedHeight( mDateNavigator->sizeHint().height() ); |
503 | //mDateNavigator->setMinimumWidth( mDateNavigator->sizeHint().width() ); | 503 | //mDateNavigator->setMinimumWidth( mDateNavigator->sizeHint().width() ); |
504 | //mTodoList->setFixedHeight( mDateNavigator->sizeHint().height() ); | 504 | //mTodoList->setFixedHeight( mDateNavigator->sizeHint().height() ); |
505 | //leftFrame->setFixedHeight( mDateNavigator->sizeHint().height() ); | 505 | //leftFrame->setFixedHeight( mDateNavigator->sizeHint().height() ); |
506 | } else { | 506 | } else { |
507 | //mDateNavigator->setFixedWidth( mDateNavigator->sizeHint().width() ); | 507 | //mDateNavigator->setFixedWidth( mDateNavigator->sizeHint().width() ); |
508 | //mTodoList->setFixedWidth( mDateNavigator->sizeHint().width() ); | 508 | //mTodoList->setFixedWidth( mDateNavigator->sizeHint().width() ); |
509 | //leftFrame->setFixedWidth( mDateNavigator->sizeHint().width() ); | 509 | //leftFrame->setFixedWidth( mDateNavigator->sizeHint().width() ); |
510 | } | 510 | } |
511 | if ( !KOPrefs::instance()->mShowDateNavigator) | 511 | if ( !KOPrefs::instance()->mShowDateNavigator) |
512 | mDateNavigator->hide(); | 512 | mDateNavigator->hide(); |
513 | //qDebug("Calendarview Size %d %d ", width(), height()); | 513 | //qDebug("Calendarview Size %d %d ", width(), height()); |
514 | #endif | 514 | #endif |
515 | 515 | ||
516 | connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), | 516 | connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), |
517 | SLOT( showDates( const KCal::DateList & ) ) ); | 517 | SLOT( showDates( const KCal::DateList & ) ) ); |
518 | 518 | ||
519 | connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), | 519 | connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), |
520 | mDateNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); | 520 | mDateNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); |
521 | 521 | ||
522 | 522 | ||
523 | 523 | ||
524 | connect( mDateNavigator, SIGNAL( showMonth( const QDate & ) ), | 524 | connect( mDateNavigator, SIGNAL( showMonth( const QDate & ) ), |
525 | mViewManager, SLOT( showMonth( const QDate & ) ) ); | 525 | mViewManager, SLOT( showMonth( const QDate & ) ) ); |
526 | 526 | ||
527 | connect( mDateNavigator, SIGNAL( weekClicked( const QDate & ) ), | 527 | connect( mDateNavigator, SIGNAL( weekClicked( const QDate & ) ), |
528 | mNavigator, SLOT( selectWeek( const QDate & ) ) ); | 528 | mNavigator, SLOT( selectWeek( const QDate & ) ) ); |
529 | 529 | ||
530 | connect( mDateNavigator, SIGNAL( goPrevYear() ), | 530 | connect( mDateNavigator, SIGNAL( goPrevYear() ), |
531 | mNavigator, SLOT( selectPreviousYear() ) ); | 531 | mNavigator, SLOT( selectPreviousYear() ) ); |
532 | connect( mDateNavigator, SIGNAL( goNextYear() ), | 532 | connect( mDateNavigator, SIGNAL( goNextYear() ), |
533 | mNavigator, SLOT( selectNextYear() ) ); | 533 | mNavigator, SLOT( selectNextYear() ) ); |
534 | connect( mDateNavigator, SIGNAL( goPrevMonth() ), | 534 | connect( mDateNavigator, SIGNAL( goPrevMonth() ), |
535 | mNavigator, SLOT( selectPreviousMonth() ) ); | 535 | mNavigator, SLOT( selectPreviousMonth() ) ); |
536 | connect( mDateNavigator, SIGNAL( goNextMonth() ), | 536 | connect( mDateNavigator, SIGNAL( goNextMonth() ), |
537 | mNavigator, SLOT( selectNextMonth() ) ); | 537 | mNavigator, SLOT( selectNextMonth() ) ); |
538 | 538 | ||
539 | connect( mDateNavigator, SIGNAL( goPrevious() ), | 539 | connect( mDateNavigator, SIGNAL( goPrevious() ), |
540 | mNavigator, SLOT( selectPrevious() ) ); | 540 | mNavigator, SLOT( selectPrevious() ) ); |
541 | connect( mDateNavigator, SIGNAL( goNext() ), | 541 | connect( mDateNavigator, SIGNAL( goNext() ), |
542 | mNavigator, SLOT( selectNext() ) ); | 542 | mNavigator, SLOT( selectNext() ) ); |
543 | connect( mDateNavigator, SIGNAL( monthSelected ( int ) ), | 543 | connect( mDateNavigator, SIGNAL( monthSelected ( int ) ), |
544 | mNavigator, SLOT( slotMonthSelect( int ) ) ); | 544 | mNavigator, SLOT( slotMonthSelect( int ) ) ); |
545 | 545 | ||
546 | connect( mDateNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), | 546 | connect( mDateNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), |
547 | mNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); | 547 | mNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); |
548 | #if 0 | 548 | #if 0 |
549 | connect( mDateNavigator, SIGNAL( incidenceDropped( Incidence * ) ), | 549 | connect( mDateNavigator, SIGNAL( incidenceDropped( Incidence * ) ), |
550 | SLOT( incidenceAdded( Incidence *) ) ); | 550 | SLOT( incidenceAdded( Incidence *) ) ); |
551 | #endif | 551 | #endif |
552 | // connect(mDateNavigator,SIGNAL(dayPassed(QDate)),SLOT(updateView())); | 552 | // connect(mDateNavigator,SIGNAL(dayPassed(QDate)),SLOT(updateView())); |
553 | 553 | ||
554 | connect( this, SIGNAL( configChanged() ), | 554 | connect( this, SIGNAL( configChanged() ), |
555 | mDateNavigator, SLOT( updateConfig() ) ); | 555 | mDateNavigator, SLOT( updateConfig() ) ); |
556 | 556 | ||
557 | connect( mTodoList, SIGNAL( newTodoSignal() ), | 557 | connect( mTodoList, SIGNAL( newTodoSignal() ), |
558 | SLOT( newTodo() ) ); | 558 | SLOT( newTodo() ) ); |
559 | connect( mTodoList, SIGNAL( newSubTodoSignal( Todo *) ), | 559 | connect( mTodoList, SIGNAL( newSubTodoSignal( Todo *) ), |
560 | SLOT( newSubTodo( Todo * ) ) ); | 560 | SLOT( newSubTodo( Todo * ) ) ); |
561 | connect( mTodoList, SIGNAL( editTodoSignal( Todo * ) ), | 561 | connect( mTodoList, SIGNAL( editTodoSignal( Todo * ) ), |
562 | SLOT( editTodo( Todo * ) ) ); | 562 | SLOT( editTodo( Todo * ) ) ); |
563 | connect( mTodoList, SIGNAL( showTodoSignal( Todo * ) ), | 563 | connect( mTodoList, SIGNAL( showTodoSignal( Todo * ) ), |
564 | SLOT( showTodo( Todo *) ) ); | 564 | SLOT( showTodo( Todo *) ) ); |
565 | connect( mTodoList, SIGNAL( deleteTodoSignal( Todo *) ), | 565 | connect( mTodoList, SIGNAL( deleteTodoSignal( Todo *) ), |
566 | SLOT( deleteTodo( Todo *) ) ); | 566 | SLOT( deleteTodo( Todo *) ) ); |
567 | connect( this, SIGNAL( configChanged()), mTodoList, SLOT( updateConfig() ) ); | 567 | connect( this, SIGNAL( configChanged()), mTodoList, SLOT( updateConfig() ) ); |
568 | connect( mTodoList, SIGNAL( purgeCompletedSignal() ), | 568 | connect( mTodoList, SIGNAL( purgeCompletedSignal() ), |
569 | SLOT( purgeCompleted() ) ); | 569 | SLOT( purgeCompleted() ) ); |
570 | connect( mTodoList, SIGNAL( todoModifiedSignal( Todo *, int ) ), | 570 | connect( mTodoList, SIGNAL( todoModifiedSignal( Todo *, int ) ), |
571 | SIGNAL( todoModified( Todo *, int ) ) ); | 571 | SIGNAL( todoModified( Todo *, int ) ) ); |
572 | 572 | ||
573 | connect( mTodoList, SIGNAL( cloneTodoSignal( Incidence * ) ), | 573 | connect( mTodoList, SIGNAL( cloneTodoSignal( Incidence * ) ), |
574 | this, SLOT ( cloneIncidence( Incidence * ) ) ); | 574 | this, SLOT ( cloneIncidence( Incidence * ) ) ); |
575 | connect( mTodoList, SIGNAL( cancelTodoSignal( Incidence * ) ), | 575 | connect( mTodoList, SIGNAL( cancelTodoSignal( Incidence * ) ), |
576 | this, SLOT (cancelIncidence( Incidence * ) ) ); | 576 | this, SLOT (cancelIncidence( Incidence * ) ) ); |
577 | 577 | ||
578 | connect( mTodoList, SIGNAL( moveTodoSignal( Incidence * ) ), | 578 | connect( mTodoList, SIGNAL( moveTodoSignal( Incidence * ) ), |
579 | this, SLOT ( moveIncidence( Incidence * ) ) ); | 579 | this, SLOT ( moveIncidence( Incidence * ) ) ); |
580 | connect( mTodoList, SIGNAL( beamTodoSignal( Incidence * ) ), | 580 | connect( mTodoList, SIGNAL( beamTodoSignal( Incidence * ) ), |
581 | this, SLOT ( beamIncidence( Incidence * ) ) ); | 581 | this, SLOT ( beamIncidence( Incidence * ) ) ); |
582 | 582 | ||
583 | connect( mTodoList, SIGNAL( unparentTodoSignal( Todo * ) ), | 583 | connect( mTodoList, SIGNAL( unparentTodoSignal( Todo * ) ), |
584 | this, SLOT ( todo_unsub( Todo * ) ) ); | 584 | this, SLOT ( todo_unsub( Todo * ) ) ); |
585 | 585 | ||
586 | connect( mTodoList, SIGNAL( reparentTodoSignal( Todo *,Todo * ) ), | 586 | connect( mTodoList, SIGNAL( reparentTodoSignal( Todo *,Todo * ) ), |
587 | this, SLOT ( todo_resub( Todo *,Todo * ) ) ); | 587 | this, SLOT ( todo_resub( Todo *,Todo * ) ) ); |
588 | connect( this, SIGNAL( todoModified( Todo *, int )), mTodoList, | 588 | connect( this, SIGNAL( todoModified( Todo *, int )), mTodoList, |
589 | SLOT( updateTodo( Todo *, int ) ) ); | 589 | SLOT( updateTodo( Todo *, int ) ) ); |
590 | connect( this, SIGNAL( todoModified( Todo *, int )), this, | 590 | connect( this, SIGNAL( todoModified( Todo *, int )), this, |
591 | SLOT( changeTodoDisplay( Todo *, int ) ) ); | 591 | SLOT( changeTodoDisplay( Todo *, int ) ) ); |
592 | 592 | ||
593 | 593 | ||
594 | connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) ); | 594 | connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) ); |
595 | connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) ); | 595 | connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) ); |
596 | connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) ); | 596 | connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) ); |
597 | connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) ); | 597 | connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) ); |
598 | 598 | ||
599 | 599 | ||
600 | 600 | ||
601 | 601 | ||
602 | 602 | ||
603 | connect(QApplication::clipboard(),SIGNAL(dataChanged()), | 603 | connect(QApplication::clipboard(),SIGNAL(dataChanged()), |
604 | SLOT(checkClipboard())); | 604 | SLOT(checkClipboard())); |
605 | connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ), | 605 | connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ), |
606 | SLOT( processTodoListSelection( Incidence * ) ) ); | 606 | SLOT( processTodoListSelection( Incidence * ) ) ); |
607 | connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool))); | 607 | connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool))); |
608 | 608 | ||
609 | // kdDebug() << "CalendarView::CalendarView() done" << endl; | 609 | // kdDebug() << "CalendarView::CalendarView() done" << endl; |
610 | 610 | ||
611 | mDateFrame = new QVBox(0,0,WType_Popup); | 611 | mDateFrame = new QVBox(0,0,WType_Popup); |
612 | //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised); | 612 | //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised); |
613 | mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised ); | 613 | mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised ); |
614 | mDateFrame->setLineWidth(3); | 614 | mDateFrame->setLineWidth(3); |
615 | mDateFrame->hide(); | 615 | mDateFrame->hide(); |
616 | mDateFrame->setCaption( i18n( "Pick a date to display")); | 616 | mDateFrame->setCaption( i18n( "Pick a date to display")); |
617 | mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() ); | 617 | mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() ); |
618 | 618 | ||
619 | connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate))); | 619 | connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate))); |
620 | 620 | ||
621 | mEventEditor = mDialogManager->getEventEditor(); | 621 | mEventEditor = mDialogManager->getEventEditor(); |
622 | mTodoEditor = mDialogManager->getTodoEditor(); | 622 | mTodoEditor = mDialogManager->getTodoEditor(); |
623 | 623 | ||
624 | mFlagEditDescription = false; | 624 | mFlagEditDescription = false; |
625 | 625 | ||
626 | mSuspendTimer = new QTimer( this ); | 626 | mSuspendTimer = new QTimer( this ); |
627 | mAlarmTimer = new QTimer( this ); | 627 | mAlarmTimer = new QTimer( this ); |
628 | mRecheckAlarmTimer = new QTimer( this ); | 628 | mRecheckAlarmTimer = new QTimer( this ); |
629 | connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) ); | 629 | connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) ); |
630 | connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) ); | 630 | connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) ); |
631 | connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) ); | 631 | connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) ); |
632 | mAlarmDialog = new AlarmDialog( this ); | 632 | mAlarmDialog = new AlarmDialog( this ); |
633 | connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) ); | 633 | connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) ); |
634 | mAlarmDialog->setServerNotification( false ); | 634 | mAlarmDialog->setServerNotification( false ); |
635 | mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime ); | 635 | mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime ); |
636 | 636 | ||
637 | 637 | ||
638 | #ifndef DESKTOP_VERSION | 638 | #ifndef DESKTOP_VERSION |
639 | //US listen for arriving address resultsets | 639 | //US listen for arriving address resultsets |
640 | connect(ExternalAppHandler::instance(), SIGNAL(receivedBirthdayListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)), | 640 | connect(ExternalAppHandler::instance(), SIGNAL(receivedBirthdayListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)), |
641 | this, SLOT(insertBirthdays(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&))); | 641 | this, SLOT(insertBirthdays(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&))); |
642 | #endif | 642 | #endif |
643 | mDateNavigator->setCalendar( mCalendar ); | 643 | mDateNavigator->setCalendar( mCalendar ); |
644 | } | 644 | } |
645 | 645 | ||
646 | 646 | ||
647 | CalendarView::~CalendarView() | 647 | CalendarView::~CalendarView() |
648 | { | 648 | { |
649 | // kdDebug() << "~CalendarView()" << endl; | 649 | // kdDebug() << "~CalendarView()" << endl; |
650 | //qDebug("CalendarView::~CalendarView() "); | 650 | //qDebug("CalendarView::~CalendarView() "); |
651 | delete mDialogManager; | 651 | delete mDialogManager; |
652 | delete mViewManager; | 652 | delete mViewManager; |
653 | delete mStorage; | 653 | delete mStorage; |
654 | delete mDateFrame ; | 654 | delete mDateFrame ; |
655 | delete mEventViewerDialog; | 655 | delete mEventViewerDialog; |
656 | //kdDebug() << "~CalendarView() done" << endl; | 656 | //kdDebug() << "~CalendarView() done" << endl; |
657 | } | 657 | } |
658 | void CalendarView::nextConflict( bool all, bool allday ) | 658 | void CalendarView::nextConflict( bool all, bool allday ) |
659 | { | 659 | { |
660 | 660 | ||
661 | QPtrList<Event> testlist = mCalendar->events(); | 661 | QPtrList<Event> testlist = mCalendar->events(); |
662 | Event * test = testlist.first(); | 662 | Event * test = testlist.first(); |
663 | while ( test ) { | 663 | while ( test ) { |
664 | test->setTagged( false ); | 664 | test->setTagged( false ); |
665 | test = testlist.next(); | 665 | test = testlist.next(); |
666 | } | 666 | } |
667 | QTime st ( 0,0,0); | 667 | QTime st ( 0,0,0); |
668 | if ( mViewManager->currentView() == mViewManager->agendaView() ) | 668 | if ( mViewManager->currentView() == mViewManager->agendaView() ) |
669 | st = mViewManager->agendaView()->agenda()->getEndTime(); | 669 | st = mViewManager->agendaView()->agenda()->getEndTime(); |
670 | //qDebug("time %s ", st.toString().latin1()); | 670 | //qDebug("time %s ", st.toString().latin1()); |
671 | QDateTime startDT = QDateTime (mNavigator->selectedDates().first(),st); | 671 | QDateTime startDT = QDateTime (mNavigator->selectedDates().first(),st); |
672 | QDateTime conflict; | 672 | QDateTime conflict; |
673 | QDateTime retVal; | 673 | QDateTime retVal; |
674 | bool found = false; | 674 | bool found = false; |
675 | Event * cE = 0; | 675 | Event * cE = 0; |
676 | Event * cE2 = 0; | 676 | Event * cE2 = 0; |
677 | QPtrList<Event> testlist2 = testlist; | 677 | QPtrList<Event> testlist2 = testlist; |
678 | test = testlist.first(); | 678 | test = testlist.first(); |
679 | bool skip = false; | 679 | bool skip = false; |
680 | while ( test ) { | 680 | while ( test ) { |
681 | skip = false; | 681 | skip = false; |
682 | if ( !all ) skip = ( allday != test->doesFloat() ); | 682 | if ( !all ) skip = ( allday != test->doesFloat() ); |
683 | if ( !skip ) { | 683 | if ( !skip ) { |
684 | Event * test2 = testlist2.first(); | 684 | Event * test2 = testlist2.first(); |
685 | while ( test2 ) { | 685 | while ( test2 ) { |
686 | skip = false; | 686 | skip = false; |
687 | if ( !all ) skip = ( allday != test2->doesFloat() ); | 687 | if ( !all ) skip = ( allday != test2->doesFloat() ); |
688 | if ( !skip ) { | 688 | if ( !skip ) { |
689 | if ( !test2->isTagged() ) { | 689 | if ( !test2->isTagged() ) { |
690 | if ( test->isOverlapping ( test2, &retVal, &startDT ) ) { | 690 | if ( test->isOverlapping ( test2, &retVal, &startDT ) ) { |
691 | //qDebug("overlap "); | 691 | //qDebug("overlap "); |
692 | if ( ! found ) { | 692 | if ( ! found ) { |
693 | if ( retVal >= startDT ) { | 693 | if ( retVal >= startDT ) { |
694 | conflict = retVal; | 694 | conflict = retVal; |
695 | cE = test; | 695 | cE = test; |
696 | cE2 = test2; | 696 | cE2 = test2; |
697 | found = true; | 697 | found = true; |
698 | } | 698 | } |
699 | } else { | 699 | } else { |
700 | if ( retVal >= startDT && retVal < conflict ) { | 700 | if ( retVal >= startDT && retVal < conflict ) { |
701 | conflict = retVal; | 701 | conflict = retVal; |
702 | cE = test; | 702 | cE = test; |
703 | cE2 = test2; | 703 | cE2 = test2; |
704 | } | 704 | } |
705 | } | 705 | } |
706 | } | 706 | } |
707 | } | 707 | } |
708 | } | 708 | } |
709 | test2 = testlist2.next(); | 709 | test2 = testlist2.next(); |
710 | } | 710 | } |
711 | } | 711 | } |
712 | test->setTagged( true ); | 712 | test->setTagged( true ); |
713 | test = testlist.next(); | 713 | test = testlist.next(); |
714 | } | 714 | } |
715 | if ( found ) { | 715 | if ( found ) { |
716 | if ( mViewManager->currentView() != mViewManager->agendaView() || mNavigator->selectedDates().count() > 1 ) | 716 | if ( mViewManager->currentView() != mViewManager->agendaView() || mNavigator->selectedDates().count() > 1 ) |
717 | mViewManager->showDayView(); | 717 | mViewManager->showDayView(); |
718 | mNavigator->slotDaySelect( conflict.date() ); | 718 | mNavigator->slotDaySelect( conflict.date() ); |
719 | int hour = conflict.time().hour(); | 719 | int hour = conflict.time().hour(); |
720 | mViewManager->agendaView()->setStartHour( hour ); | 720 | mViewManager->agendaView()->setStartHour( hour ); |
721 | topLevelWidget()->setCaption( i18n("Conflict %1 <-> %2"). arg( cE->summary().left( 20 ) ).arg( cE2->summary().left( 20 ) ) ); | 721 | topLevelWidget()->setCaption( i18n("Conflict %1 <-> %2"). arg( cE->summary().left( 20 ) ).arg( cE2->summary().left( 20 ) ) ); |
722 | return; | 722 | return; |
723 | } | 723 | } |
724 | 724 | ||
725 | topLevelWidget()->setCaption( i18n("No conflict found") ); | 725 | topLevelWidget()->setCaption( i18n("No conflict found") ); |
726 | qDebug("No conflict found "); | 726 | qDebug("No conflict found "); |
727 | return; | 727 | return; |
728 | } | 728 | } |
729 | 729 | ||
730 | void CalendarView::conflictAll() | 730 | void CalendarView::conflictAll() |
731 | { | 731 | { |
732 | nextConflict ( true, true ); | 732 | nextConflict ( true, true ); |
733 | } | 733 | } |
734 | void CalendarView::conflictAllday() | 734 | void CalendarView::conflictAllday() |
735 | { | 735 | { |
736 | nextConflict ( false, true ); | 736 | nextConflict ( false, true ); |
737 | } | 737 | } |
738 | void CalendarView::conflictNotAll() | 738 | void CalendarView::conflictNotAll() |
739 | { | 739 | { |
740 | nextConflict ( false, false ); | 740 | nextConflict ( false, false ); |
741 | } | 741 | } |
742 | 742 | ||
743 | void CalendarView::setCalReadOnly( int id, bool readO ) | 743 | void CalendarView::setCalReadOnly( int id, bool readO ) |
744 | { | 744 | { |
745 | if ( readO ) { | 745 | if ( readO ) { |
746 | emit save(); | 746 | emit save(); |
747 | } | 747 | } |
748 | mCalendar->setReadOnly( id, readO ); | 748 | mCalendar->setReadOnly( id, readO ); |
749 | } | 749 | } |
750 | void CalendarView::setScrollBarStep(int val ) | 750 | void CalendarView::setScrollBarStep(int val ) |
751 | { | 751 | { |
752 | #ifdef DESKTOP_VERSION | 752 | #ifdef DESKTOP_VERSION |
753 | mDateScrollBar->setLineStep ( val ); | 753 | mDateScrollBar->setLineStep ( val ); |
754 | #endif | 754 | #endif |
755 | } | 755 | } |
756 | void CalendarView::scrollBarValue(int val ) | 756 | void CalendarView::scrollBarValue(int val ) |
757 | { | 757 | { |
758 | #ifdef DESKTOP_VERSION | 758 | #ifdef DESKTOP_VERSION |
759 | if ( QApplication::desktop()->width() < 800 ) return; | 759 | if ( QApplication::desktop()->width() < 800 ) return; |
760 | static bool block = false; | 760 | static bool block = false; |
761 | if ( block ) return; | 761 | if ( block ) return; |
762 | block = true; | 762 | block = true; |
763 | int count = mNavigator->selectedDates().count(); | 763 | int count = mNavigator->selectedDates().count(); |
764 | int day = mNavigator->selectedDates().first().dayOfYear(); | 764 | int day = mNavigator->selectedDates().first().dayOfYear(); |
765 | int stepdays = val; | 765 | int stepdays = val; |
766 | if ( mDateScrollBar->lineStep () <= count ) { | 766 | if ( mDateScrollBar->lineStep () <= count ) { |
767 | //val = val/mDateScrollBar->lineStep ()*mDateScrollBar->lineStep(); | 767 | //val = val/mDateScrollBar->lineStep ()*mDateScrollBar->lineStep(); |
768 | //qDebug("VAL %d ",val ); | 768 | //qDebug("VAL %d ",val ); |
769 | stepdays = (val-day)/mDateScrollBar->lineStep ()*mDateScrollBar->lineStep(); | 769 | stepdays = (val-day)/mDateScrollBar->lineStep ()*mDateScrollBar->lineStep(); |
770 | stepdays = day+stepdays; | 770 | stepdays = day+stepdays; |
771 | if ( stepdays < 0 ) stepdays = 0; | 771 | if ( stepdays < 0 ) stepdays = 0; |
772 | } | 772 | } |
773 | if ( stepdays == day ) { | 773 | if ( stepdays == day ) { |
774 | block = false; | 774 | block = false; |
775 | return; | 775 | return; |
776 | } | 776 | } |
777 | int year = mNavigator->selectedDates().first().year(); | 777 | int year = mNavigator->selectedDates().first().year(); |
778 | QDate d ( year,1,1 ); | 778 | QDate d ( year,1,1 ); |
779 | mNavigator->selectDates( d.addDays( stepdays-1) , count ); | 779 | mNavigator->selectDates( d.addDays( stepdays-1) , count ); |
780 | block = false; | 780 | block = false; |
781 | #endif | 781 | #endif |
782 | 782 | ||
783 | } | 783 | } |
784 | void CalendarView::updateView(const QDate &start, const QDate &end) | 784 | void CalendarView::updateView(const QDate &start, const QDate &end) |
785 | { | 785 | { |
786 | #ifdef DESKTOP_VERSION | 786 | #ifdef DESKTOP_VERSION |
787 | if ( ! mDateScrollBar->draggingSlider () ) { | 787 | if ( ! mDateScrollBar->draggingSlider () ) { |
788 | int dof = start.dayOfYear(); | 788 | int dof = start.dayOfYear(); |
789 | //qDebug("dof %d day %d val %d ", dof, start.dayOfYear(),mDateScrollBar->value() ); | 789 | //qDebug("dof %d day %d val %d ", dof, start.dayOfYear(),mDateScrollBar->value() ); |
790 | if ( dof != mDateScrollBar->value() ) { | 790 | if ( dof != mDateScrollBar->value() ) { |
791 | mDateScrollBar->blockSignals( true ); | 791 | mDateScrollBar->blockSignals( true ); |
792 | mDateScrollBar->setValue( start.dayOfYear()); | 792 | mDateScrollBar->setValue( start.dayOfYear()); |
793 | mDateScrollBar->blockSignals( false ); | 793 | mDateScrollBar->blockSignals( false ); |
794 | } | 794 | } |
795 | } | 795 | } |
796 | #endif | 796 | #endif |
797 | mTodoList->updateView(); | 797 | mTodoList->updateView(); |
798 | mViewManager->updateView(start, end); | 798 | mViewManager->updateView(start, end); |
799 | //mDateNavigator->updateView(); | 799 | //mDateNavigator->updateView(); |
800 | } | 800 | } |
801 | 801 | ||
802 | 802 | ||
803 | 803 | ||
804 | void CalendarView::checkFiles() | 804 | void CalendarView::checkFiles() |
805 | { | 805 | { |
806 | QString message; | 806 | QString message; |
807 | QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; | 807 | QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; |
808 | KopiCalendarFile * cal = calendars.first(); | 808 | KopiCalendarFile * cal = calendars.first(); |
809 | while ( cal ) { | 809 | while ( cal ) { |
810 | if ( cal->mErrorOnLoad ) { | 810 | if ( cal->mErrorOnLoad ) { |
811 | message += cal->mName +"\n"+KGlobal::formatMessage ( "(" +i18n( "Filepath: ")+ cal->mFileName+")" ,0 )+"\n"; | 811 | message += cal->mName +"\n"+KGlobal::formatMessage ( "(" +i18n( "Filepath: ")+ cal->mFileName+")" ,0 )+"\n"; |
812 | } | 812 | } |
813 | cal = calendars.next(); | 813 | cal = calendars.next(); |
814 | } | 814 | } |
815 | if ( !message.isEmpty() ) { | 815 | if ( !message.isEmpty() ) { |
816 | message = KGlobal::formatMessage( i18n("Calendar(s) not loaded:"),0 )+"\n" + message +KGlobal::formatMessage(i18n("You can try to reload the calendar in the Resource View!"),0); | 816 | message = KGlobal::formatMessage( i18n("Calendar(s) not loaded:"),0 )+"\n" + message +KGlobal::formatMessage(i18n("You can try to reload the calendar in the Resource View!"),0); |
817 | KMessageBox::error(this,message, i18n("Loding of calendar(s) failed")); | 817 | KMessageBox::error(this,message, i18n("Loding of calendar(s) failed")); |
818 | } | 818 | } |
819 | QTimer::singleShot( 2000, this, SLOT ( checkAlarms() )); | 819 | QTimer::singleShot( 2000, this, SLOT ( checkAlarms() )); |
820 | } | 820 | } |
821 | void CalendarView::checkAlarms() | 821 | void CalendarView::checkAlarms() |
822 | { | 822 | { |
823 | 823 | ||
824 | 824 | ||
825 | KConfig *config = KOGlobals::config(); | 825 | KConfig *config = KOGlobals::config(); |
826 | config->setGroup( "AppRun" ); | 826 | config->setGroup( "AppRun" ); |
827 | QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) ); | 827 | QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) ); |
828 | int daysto = dt.daysTo( QDate::currentDate() ); | 828 | int daysto = dt.daysTo( QDate::currentDate() ); |
829 | int days = config->readNumEntry( "LatestProgramStopDays" , daysto); | 829 | int days = config->readNumEntry( "LatestProgramStopDays" , daysto); |
830 | dt = dt.addDays( days ); | 830 | dt = dt.addDays( days ); |
831 | int secto = dt.secsTo( QDateTime::currentDateTime() ); | 831 | int secto = dt.secsTo( QDateTime::currentDateTime() ); |
832 | int secs = config->readNumEntry( "LatestProgramStopSecs" , secto) - 30; | 832 | int secs = config->readNumEntry( "LatestProgramStopSecs" , secto) - 30; |
833 | //qDebug("KO: Reading program stop %d ", secs); | 833 | //qDebug("KO: Reading program stop %d ", secs); |
834 | //secs -= ( 3600 * 24*3 ); // debug only | 834 | //secs -= ( 3600 * 24*3 ); // debug only |
835 | QDateTime latest = dt.addSecs ( secs ); | 835 | QDateTime latest = dt.addSecs ( secs ); |
836 | qDebug("KO: Last termination on %s ", latest.toString().latin1()); | 836 | qDebug("KO: Last termination on %s ", latest.toString().latin1()); |
837 | //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() ); | 837 | //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() ); |
838 | QPtrList<Incidence> el = mCalendar->rawIncidences(); | 838 | QPtrList<Incidence> el = mCalendar->rawIncidences(); |
839 | QPtrList<Incidence> al; | 839 | QPtrList<Incidence> al; |
840 | Incidence* inL = el.first(); | 840 | Incidence* inL = el.first(); |
841 | QDateTime cur = QDateTime::currentDateTime().addSecs(-59); | 841 | QDateTime cur = QDateTime::currentDateTime().addSecs(-59); |
842 | qDebug("KO: Checking alarm until %s ", cur.toString().latin1()); | 842 | qDebug("KO: Checking alarm until %s ", cur.toString().latin1()); |
843 | while ( inL ) { | 843 | while ( inL ) { |
844 | bool ok = false; | 844 | bool ok = false; |
845 | int offset = 0; | 845 | int offset = 0; |
846 | QDateTime next = inL->getNextAlarmDateTime(& ok, &offset, latest ) ; | 846 | QDateTime next = inL->getNextAlarmDateTime(& ok, &offset, latest ) ; |
847 | if ( ok ) { | 847 | if ( ok ) { |
848 | //qDebug("OK %s",next.toString().latin1()); | 848 | //qDebug("OK %s",next.toString().latin1()); |
849 | if ( next < cur ) { | 849 | if ( next < cur ) { |
850 | al.append( inL ); | 850 | al.append( inL ); |
851 | //qDebug("found missed alarm: %s ", inL->summary().latin1() ); | 851 | //qDebug("found missed alarm: %s ", inL->summary().latin1() ); |
852 | } | 852 | } |
853 | } | 853 | } |
854 | inL = el.next(); | 854 | inL = el.next(); |
855 | } | 855 | } |
856 | if ( al.count() ) { | 856 | if ( al.count() ) { |
857 | QDialog* dia = new QDialog( this, "huhu", false, WDestructiveClose | WStyle_StaysOnTop ); | 857 | QDialog* dia = new QDialog( this, "huhu", false, WDestructiveClose | WStyle_StaysOnTop ); |
858 | dia->setCaption( i18n("KO/Pi: Missing alarms!") ); | 858 | dia->setCaption( i18n("KO/Pi: Missing alarms!") ); |
859 | QVBoxLayout* lay = new QVBoxLayout( dia ); | 859 | QVBoxLayout* lay = new QVBoxLayout( dia ); |
860 | lay->setSpacing( 0 ); | 860 | lay->setSpacing( 0 ); |
861 | lay->setMargin( 0 ); | 861 | lay->setMargin( 0 ); |
862 | MissedAlarmTextBrowser* matb = new MissedAlarmTextBrowser ( dia, al, latest ); | 862 | MissedAlarmTextBrowser* matb = new MissedAlarmTextBrowser ( dia, al, latest ); |
863 | connect( matb, SIGNAL( showIncidence( QString ) ),SLOT( showIncidence( QString ) )); | 863 | connect( matb, SIGNAL( showIncidence( QString ) ),SLOT( showIncidence( QString ) )); |
864 | lay->addWidget( matb ); | 864 | lay->addWidget( matb ); |
865 | if ( QApplication::desktop()->width() == 480 || QApplication::desktop()->width() == 640 ) { | 865 | if ( QApplication::desktop()->width() == 480 || QApplication::desktop()->width() == 640 ) { |
866 | int wid = 210; | 866 | int wid = 210; |
867 | int x = QApplication::desktop()->width() - wid - 7; | 867 | int x = QApplication::desktop()->width() - wid - 7; |
868 | int y = QApplication::desktop()->height() - wid - 70; | 868 | int y = QApplication::desktop()->height() - wid - 70; |
869 | dia->setGeometry ( x,y,wid,wid); | 869 | dia->setGeometry ( x,y,wid,wid); |
870 | } else { | 870 | } else { |
871 | int si = 220; | 871 | int si = 220; |
872 | if ( QApplication::desktop()->width() > 470 ) | 872 | if ( QApplication::desktop()->width() > 470 ) |
873 | si = 400; | 873 | si = 400; |
874 | dia->resize(si,si/2); | 874 | dia->resize(si,si/2); |
875 | } | 875 | } |
876 | dia->setBackgroundColor( QColor( 255, 255, 255 ) ); | 876 | dia->setBackgroundColor( QColor( 255, 255, 255 ) ); |
877 | dia->show(); | 877 | dia->show(); |
878 | 878 | ||
879 | } | 879 | } |
880 | } | 880 | } |
881 | void CalendarView::showDay( QDate d ) | 881 | void CalendarView::showDay( QDate d ) |
882 | { | 882 | { |
883 | dateNavigator()->blockSignals( true ); | 883 | dateNavigator()->blockSignals( true ); |
884 | dateNavigator()->selectDate( d ); | 884 | dateNavigator()->selectDate( d ); |
885 | dateNavigator()->blockSignals( false ); | 885 | dateNavigator()->blockSignals( false ); |
886 | mViewManager->showDayView(); | 886 | mViewManager->showDayView(); |
887 | //dateNavigator()->selectDate( d ); | 887 | //dateNavigator()->selectDate( d ); |
888 | } | 888 | } |
889 | void CalendarView::timerAlarm() | 889 | void CalendarView::timerAlarm() |
890 | { | 890 | { |
891 | //qDebug("CalendarView::timerAlarm() "); | 891 | //qDebug("CalendarView::timerAlarm() "); |
892 | computeAlarm(mAlarmNotification ); | 892 | computeAlarm(mAlarmNotification ); |
893 | } | 893 | } |
894 | 894 | ||
895 | void CalendarView::suspendAlarm() | 895 | void CalendarView::suspendAlarm() |
896 | { | 896 | { |
897 | //qDebug(" CalendarView::suspendAlarm() "); | 897 | //qDebug(" CalendarView::suspendAlarm() "); |
898 | computeAlarm(mSuspendAlarmNotification ); | 898 | computeAlarm(mSuspendAlarmNotification ); |
899 | 899 | ||
900 | } | 900 | } |
901 | 901 | ||
902 | void CalendarView::startAlarm( QString mess , QString filename) | 902 | void CalendarView::startAlarm( QString mess , QString filename) |
903 | { | 903 | { |
904 | 904 | ||
905 | topLevelWidget()->showNormal(); | 905 | topLevelWidget()->showNormal(); |
906 | topLevelWidget()->setActiveWindow(); | 906 | topLevelWidget()->setActiveWindow(); |
907 | topLevelWidget()->raise(); | 907 | topLevelWidget()->raise(); |
908 | 908 | ||
909 | mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount ); | 909 | mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount ); |
910 | QTimer::singleShot( 2000, this, SLOT( checkNextTimerAlarm() ) ); | 910 | QTimer::singleShot( 2000, this, SLOT( checkNextTimerAlarm() ) ); |
911 | 911 | ||
912 | } | 912 | } |
913 | 913 | ||
914 | void CalendarView::checkNextTimerAlarm() | 914 | void CalendarView::checkNextTimerAlarm() |
915 | { | 915 | { |
916 | mCalendar->checkAlarmForIncidence( 0, true ); | 916 | mCalendar->checkAlarmForIncidence( 0, true ); |
917 | } | 917 | } |
918 | 918 | ||
919 | void CalendarView::computeAlarm( QString msg ) | 919 | void CalendarView::computeAlarm( QString msg ) |
920 | { | 920 | { |
921 | 921 | ||
922 | QString mess = msg; | 922 | QString mess = msg; |
923 | QString mAlarmMessage = mess.mid( 9 ); | 923 | QString mAlarmMessage = mess.mid( 9 ); |
924 | QString filename = MainWindow::resourcePath(); | 924 | QString filename = MainWindow::resourcePath(); |
925 | filename += "koalarm.wav"; | 925 | filename += "koalarm.wav"; |
926 | QString tempfilename; | 926 | QString tempfilename; |
927 | if ( mess.left( 13 ) == "suspend_alarm") { | 927 | if ( mess.left( 13 ) == "suspend_alarm") { |
928 | bool error = false; | 928 | bool error = false; |
929 | int len = mess.mid( 13 ).find("+++"); | 929 | int len = mess.mid( 13 ).find("+++"); |
930 | if ( len < 2 ) | 930 | if ( len < 2 ) |
931 | error = true; | 931 | error = true; |
932 | else { | 932 | else { |
933 | tempfilename = mess.mid( 13, len ); | 933 | tempfilename = mess.mid( 13, len ); |
934 | if ( !QFile::exists( tempfilename ) ) | 934 | if ( !QFile::exists( tempfilename ) ) |
935 | error = true; | 935 | error = true; |
936 | } | 936 | } |
937 | if ( ! error ) { | 937 | if ( ! error ) { |
938 | filename = tempfilename; | 938 | filename = tempfilename; |
939 | } | 939 | } |
940 | mAlarmMessage = mess.mid( 13+len+3 ); | 940 | mAlarmMessage = mess.mid( 13+len+3 ); |
941 | //qDebug("suspend file %s ",tempfilename.latin1() ); | 941 | //qDebug("suspend file %s ",tempfilename.latin1() ); |
942 | startAlarm( mAlarmMessage, filename); | 942 | startAlarm( mAlarmMessage, filename); |
943 | return; | 943 | return; |
944 | } | 944 | } |
945 | if ( mess.left( 11 ) == "timer_alarm") { | 945 | if ( mess.left( 11 ) == "timer_alarm") { |
946 | //mTimerTime = 0; | 946 | //mTimerTime = 0; |
947 | startAlarm( mess.mid( 11 ), filename ); | 947 | startAlarm( mess.mid( 11 ), filename ); |
948 | return; | 948 | return; |
949 | } | 949 | } |
950 | if ( mess.left( 10 ) == "proc_alarm") { | 950 | if ( mess.left( 10 ) == "proc_alarm") { |
951 | bool error = false; | 951 | bool error = false; |
952 | int len = mess.mid( 10 ).find("+++"); | 952 | int len = mess.mid( 10 ).find("+++"); |
953 | if ( len < 2 ) | 953 | if ( len < 2 ) |
954 | error = true; | 954 | error = true; |
955 | else { | 955 | else { |
956 | tempfilename = mess.mid( 10, len ); | 956 | tempfilename = mess.mid( 10, len ); |
957 | if ( !QFile::exists( tempfilename ) ) | 957 | if ( !QFile::exists( tempfilename ) ) |
958 | error = true; | 958 | error = true; |
959 | } | 959 | } |
960 | if ( error ) { | 960 | if ( error ) { |
961 | mAlarmMessage = "Procedure Alarm\nError - File not found\n"; | 961 | mAlarmMessage = "Procedure Alarm\nError - File not found\n"; |
962 | mAlarmMessage += mess.mid( 10+len+3+9 ); | 962 | mAlarmMessage += mess.mid( 10+len+3+9 ); |
963 | } else { | 963 | } else { |
964 | //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent"); | 964 | //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent"); |
965 | //qDebug("-----system command %s ",tempfilename.latin1() ); | 965 | //qDebug("-----system command %s ",tempfilename.latin1() ); |
966 | #ifndef _WIN32_ | 966 | #ifndef _WIN32_ |
967 | if ( vfork () == 0 ) { | 967 | if ( vfork () == 0 ) { |
968 | execl ( tempfilename.latin1(), 0 ); | 968 | execl ( tempfilename.latin1(), 0 ); |
969 | return; | 969 | return; |
970 | } | 970 | } |
971 | #else | 971 | #else |
972 | QProcess* p = new QProcess(); | 972 | QProcess* p = new QProcess(); |
973 | p->addArgument( tempfilename.latin1() ); | 973 | p->addArgument( tempfilename.latin1() ); |
974 | p->start(); | 974 | p->start(); |
975 | return; | 975 | return; |
976 | #endif | 976 | #endif |
977 | 977 | ||
978 | return; | 978 | return; |
979 | } | 979 | } |
980 | 980 | ||
981 | //qDebug("+++++++system command %s ",tempfilename.latin1() ); | 981 | //qDebug("+++++++system command %s ",tempfilename.latin1() ); |
982 | } | 982 | } |
983 | if ( mess.left( 11 ) == "audio_alarm") { | 983 | if ( mess.left( 11 ) == "audio_alarm") { |
984 | bool error = false; | 984 | bool error = false; |
985 | int len = mess.mid( 11 ).find("+++"); | 985 | int len = mess.mid( 11 ).find("+++"); |
986 | if ( len < 2 ) | 986 | if ( len < 2 ) |
987 | error = true; | 987 | error = true; |
988 | else { | 988 | else { |
989 | tempfilename = mess.mid( 11, len ); | 989 | tempfilename = mess.mid( 11, len ); |
990 | if ( !QFile::exists( tempfilename ) ) | 990 | if ( !QFile::exists( tempfilename ) ) |
991 | error = true; | 991 | error = true; |
992 | } | 992 | } |
993 | if ( ! error ) { | 993 | if ( ! error ) { |
994 | filename = tempfilename; | 994 | filename = tempfilename; |
995 | } | 995 | } |
996 | mAlarmMessage = mess.mid( 11+len+3+9 ); | 996 | mAlarmMessage = mess.mid( 11+len+3+9 ); |
997 | //qDebug("audio file command %s ",tempfilename.latin1() ); | 997 | //qDebug("audio file command %s ",tempfilename.latin1() ); |
998 | } | 998 | } |
999 | if ( mess.left( 9 ) == "cal_alarm") { | 999 | if ( mess.left( 9 ) == "cal_alarm") { |
1000 | mAlarmMessage = mess.mid( 9 ) ; | 1000 | mAlarmMessage = mess.mid( 9 ) ; |
1001 | } | 1001 | } |
1002 | 1002 | ||
1003 | startAlarm( mAlarmMessage, filename ); | 1003 | startAlarm( mAlarmMessage, filename ); |
1004 | 1004 | ||
1005 | 1005 | ||
1006 | } | 1006 | } |
1007 | 1007 | ||
1008 | void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString ¬i ) | 1008 | void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString ¬i ) |
1009 | { | 1009 | { |
1010 | //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); | 1010 | //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); |
1011 | 1011 | ||
1012 | mSuspendAlarmNotification = noti; | 1012 | mSuspendAlarmNotification = noti; |
1013 | int ms = QDateTime::currentDateTime().secsTo( qdt )*1000; | 1013 | int ms = QDateTime::currentDateTime().secsTo( qdt )*1000; |
1014 | //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000); | 1014 | //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000); |
1015 | mSuspendTimer->start( ms , true ); | 1015 | mSuspendTimer->start( ms , true ); |
1016 | 1016 | ||
1017 | } | 1017 | } |
1018 | 1018 | ||
1019 | void CalendarView::addAlarm(const QDateTime &qdt, const QString ¬i ) | 1019 | void CalendarView::addAlarm(const QDateTime &qdt, const QString ¬i ) |
1020 | { | 1020 | { |
1021 | mNextAlarmDateTime = qdt; | 1021 | mNextAlarmDateTime = qdt; |
1022 | //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); | 1022 | //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); |
1023 | if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { | 1023 | if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { |
1024 | #ifndef DESKTOP_VERSION | 1024 | #ifndef DESKTOP_VERSION |
1025 | AlarmServer::addAlarm ( qdt,"koalarm", noti.utf8() ); | 1025 | AlarmServer::addAlarm ( qdt,"koalarm", noti.utf8() ); |
1026 | #endif | 1026 | #endif |
1027 | return; | 1027 | return; |
1028 | } | 1028 | } |
1029 | int maxSec; | 1029 | int maxSec; |
1030 | //maxSec = 5; //testing only | 1030 | //maxSec = 5; //testing only |
1031 | maxSec = 86400+3600; // one day+1hour | 1031 | maxSec = 86400+3600; // one day+1hour |
1032 | mAlarmNotification = noti; | 1032 | mAlarmNotification = noti; |
1033 | int sec = QDateTime::currentDateTime().secsTo( qdt ); | 1033 | int sec = QDateTime::currentDateTime().secsTo( qdt ); |
1034 | if ( sec > maxSec ) { | 1034 | if ( sec > maxSec ) { |
1035 | mRecheckAlarmTimer->start( maxSec * 1000 ); | 1035 | mRecheckAlarmTimer->start( maxSec * 1000 ); |
1036 | // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec ); | 1036 | // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec ); |
1037 | return; | 1037 | return; |
1038 | } else { | 1038 | } else { |
1039 | mRecheckAlarmTimer->stop(); | 1039 | mRecheckAlarmTimer->stop(); |
1040 | } | 1040 | } |
1041 | //qDebug("Alarm timer started with secs: %d ", sec); | 1041 | //qDebug("Alarm timer started with secs: %d ", sec); |
1042 | mAlarmTimer->start( sec *1000 , true ); | 1042 | mAlarmTimer->start( sec *1000 , true ); |
1043 | 1043 | ||
1044 | } | 1044 | } |
1045 | // called by mRecheckAlarmTimer to get next alarm | 1045 | // called by mRecheckAlarmTimer to get next alarm |
1046 | // we need this, because a QTimer has only a max range of 25 days | 1046 | // we need this, because a QTimer has only a max range of 25 days |
1047 | void CalendarView::recheckTimerAlarm() | 1047 | void CalendarView::recheckTimerAlarm() |
1048 | { | 1048 | { |
1049 | mAlarmTimer->stop(); | 1049 | mAlarmTimer->stop(); |
1050 | mRecheckAlarmTimer->stop(); | 1050 | mRecheckAlarmTimer->stop(); |
1051 | mCalendar->checkAlarmForIncidence( 0, true ); | 1051 | mCalendar->checkAlarmForIncidence( 0, true ); |
1052 | } | 1052 | } |
1053 | #ifndef DESKTOP_VERSION | 1053 | #ifndef DESKTOP_VERSION |
1054 | void CalendarView::removeAlarm(const QDateTime &qdt, const QString ¬i ) | 1054 | void CalendarView::removeAlarm(const QDateTime &qdt, const QString ¬i ) |
1055 | #else | 1055 | #else |
1056 | void CalendarView::removeAlarm(const QDateTime &, const QString & ) | 1056 | void CalendarView::removeAlarm(const QDateTime &, const QString & ) |
1057 | #endif | 1057 | #endif |
1058 | { | 1058 | { |
1059 | //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); | 1059 | //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); |
1060 | if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { | 1060 | if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { |
1061 | #ifndef DESKTOP_VERSION | 1061 | #ifndef DESKTOP_VERSION |
1062 | AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.utf8() ); | 1062 | AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.utf8() ); |
1063 | #endif | 1063 | #endif |
1064 | return; | 1064 | return; |
1065 | } | 1065 | } |
1066 | mAlarmTimer->stop(); | 1066 | mAlarmTimer->stop(); |
1067 | } | 1067 | } |
1068 | void CalendarView::selectWeekNum ( int num ) | 1068 | void CalendarView::selectWeekNum ( int num ) |
1069 | { | 1069 | { |
1070 | dateNavigator()->blockSignals( true ); | 1070 | dateNavigator()->blockSignals( true ); |
1071 | dateNavigator()->selectWeek( num ); | 1071 | dateNavigator()->selectWeek( num ); |
1072 | dateNavigator()->blockSignals( false ); | 1072 | dateNavigator()->blockSignals( false ); |
1073 | mViewManager->showWeekView(); | 1073 | mViewManager->showWeekView(); |
1074 | } | 1074 | } |
1075 | KOViewManager *CalendarView::viewManager() | 1075 | KOViewManager *CalendarView::viewManager() |
1076 | { | 1076 | { |
1077 | return mViewManager; | 1077 | return mViewManager; |
1078 | } | 1078 | } |
1079 | 1079 | ||
1080 | KODialogManager *CalendarView::dialogManager() | 1080 | KODialogManager *CalendarView::dialogManager() |
1081 | { | 1081 | { |
1082 | return mDialogManager; | 1082 | return mDialogManager; |
1083 | } | 1083 | } |
1084 | 1084 | ||
1085 | QDate CalendarView::startDate() | 1085 | QDate CalendarView::startDate() |
1086 | { | 1086 | { |
1087 | DateList dates = mNavigator->selectedDates(); | 1087 | DateList dates = mNavigator->selectedDates(); |
1088 | 1088 | ||
1089 | return dates.first(); | 1089 | return dates.first(); |
1090 | } | 1090 | } |
1091 | 1091 | ||
1092 | QDate CalendarView::endDate() | 1092 | QDate CalendarView::endDate() |
1093 | { | 1093 | { |
1094 | DateList dates = mNavigator->selectedDates(); | 1094 | DateList dates = mNavigator->selectedDates(); |
1095 | 1095 | ||
1096 | return dates.last(); | 1096 | return dates.last(); |
1097 | } | 1097 | } |
1098 | 1098 | ||
1099 | 1099 | ||
1100 | void CalendarView::createPrinter() | 1100 | void CalendarView::createPrinter() |
1101 | { | 1101 | { |
1102 | #ifndef KORG_NOPRINTER | 1102 | #ifndef KORG_NOPRINTER |
1103 | if (!mCalPrinter) { | 1103 | if (!mCalPrinter) { |
1104 | mCalPrinter = new CalPrinter(this, mCalendar); | 1104 | mCalPrinter = new CalPrinter(this, mCalendar); |
1105 | connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig())); | 1105 | connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig())); |
1106 | } | 1106 | } |
1107 | #endif | 1107 | #endif |
1108 | } | 1108 | } |
1109 | 1109 | ||
1110 | 1110 | ||
1111 | //KOPrefs::instance()->mWriteBackFile | 1111 | //KOPrefs::instance()->mWriteBackFile |
1112 | //KOPrefs::instance()->mWriteBackExistingOnly | 1112 | //KOPrefs::instance()->mWriteBackExistingOnly |
1113 | 1113 | ||
1114 | // 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); | 1114 | // 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); |
1115 | // 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); | 1115 | // 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); |
1116 | // 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); | 1116 | // 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); |
1117 | // 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); | 1117 | // 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); |
1118 | // 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); | 1118 | // 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); |
1119 | // 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); | 1119 | // 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); |
1120 | 1120 | ||
1121 | int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) | 1121 | int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) |
1122 | { | 1122 | { |
1123 | 1123 | ||
1124 | // 0 equal | 1124 | // 0 equal |
1125 | // 1 take local | 1125 | // 1 take local |
1126 | // 2 take remote | 1126 | // 2 take remote |
1127 | // 3 cancel | 1127 | // 3 cancel |
1128 | QDateTime lastSync = mLastCalendarSync; | 1128 | QDateTime lastSync = mLastCalendarSync; |
1129 | QDateTime localMod = local->lastModified(); | 1129 | QDateTime localMod = local->lastModified(); |
1130 | QDateTime remoteMod = remote->lastModified(); | 1130 | QDateTime remoteMod = remote->lastModified(); |
1131 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 1131 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
1132 | bool remCh, locCh; | 1132 | bool remCh, locCh; |
1133 | remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); | 1133 | remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); |
1134 | //if ( remCh ) | 1134 | //if ( remCh ) |
1135 | //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); | 1135 | //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); |
1136 | locCh = ( localMod > mLastCalendarSync ); | 1136 | locCh = ( localMod > mLastCalendarSync ); |
1137 | if ( !remCh && ! locCh ) { | 1137 | if ( !remCh && ! locCh ) { |
1138 | //qDebug("both not changed "); | 1138 | //qDebug("both not changed "); |
1139 | lastSync = localMod.addDays(1); | 1139 | lastSync = localMod.addDays(1); |
1140 | if ( mode <= SYNC_PREF_ASK ) | 1140 | if ( mode <= SYNC_PREF_ASK ) |
1141 | return 0; | 1141 | return 0; |
1142 | } else { | 1142 | } else { |
1143 | if ( locCh ) { | 1143 | if ( locCh ) { |
1144 | //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1()); | 1144 | //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1()); |
1145 | lastSync = localMod.addDays( -1 ); | 1145 | lastSync = localMod.addDays( -1 ); |
1146 | if ( !remCh ) | 1146 | if ( !remCh ) |
1147 | remoteMod = ( lastSync.addDays( -1 ) ); | 1147 | remoteMod = ( lastSync.addDays( -1 ) ); |
1148 | } else { | 1148 | } else { |
1149 | //qDebug(" not loc changed "); | 1149 | //qDebug(" not loc changed "); |
1150 | lastSync = localMod.addDays( 1 ); | 1150 | lastSync = localMod.addDays( 1 ); |
1151 | if ( remCh ) | 1151 | if ( remCh ) |
1152 | remoteMod =( lastSync.addDays( 1 ) ); | 1152 | remoteMod =( lastSync.addDays( 1 ) ); |
1153 | 1153 | ||
1154 | } | 1154 | } |
1155 | } | 1155 | } |
1156 | full = true; | 1156 | full = true; |
1157 | if ( mode < SYNC_PREF_ASK ) | 1157 | if ( mode < SYNC_PREF_ASK ) |
1158 | mode = SYNC_PREF_ASK; | 1158 | mode = SYNC_PREF_ASK; |
1159 | } else { | 1159 | } else { |
1160 | if ( localMod == remoteMod ) | 1160 | if ( localMod == remoteMod ) |
1161 | // if ( local->revision() == remote->revision() ) | 1161 | // if ( local->revision() == remote->revision() ) |
1162 | return 0; | 1162 | return 0; |
1163 | 1163 | ||
1164 | } | 1164 | } |
1165 | // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); | 1165 | // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); |
1166 | 1166 | ||
1167 | //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision()); | 1167 | //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision()); |
1168 | //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() ); | 1168 | //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() ); |
1169 | //full = true; //debug only | 1169 | //full = true; //debug only |
1170 | if ( full ) { | 1170 | if ( full ) { |
1171 | bool equ = false; | 1171 | bool equ = false; |
1172 | if ( local->typeID() == eventID ) { | 1172 | if ( local->typeID() == eventID ) { |
1173 | equ = (*((Event*) local) == *((Event*) remote)); | 1173 | equ = (*((Event*) local) == *((Event*) remote)); |
1174 | } | 1174 | } |
1175 | else if ( local->typeID() == todoID ) | 1175 | else if ( local->typeID() == todoID ) |
1176 | equ = (*((Todo*) local) == (*(Todo*) remote)); | 1176 | equ = (*((Todo*) local) == (*(Todo*) remote)); |
1177 | else if ( local->typeID() == journalID ) | 1177 | else if ( local->typeID() == journalID ) |
1178 | equ = (*((Journal*) local) == *((Journal*) remote)); | 1178 | equ = (*((Journal*) local) == *((Journal*) remote)); |
1179 | if ( equ ) { | 1179 | if ( equ ) { |
1180 | //qDebug("equal "); | 1180 | //qDebug("equal "); |
1181 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 1181 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
1182 | local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); | 1182 | local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); |
1183 | } | 1183 | } |
1184 | if ( mode < SYNC_PREF_FORCE_LOCAL ) | 1184 | if ( mode < SYNC_PREF_FORCE_LOCAL ) |
1185 | return 0; | 1185 | return 0; |
1186 | 1186 | ||
1187 | }//else //debug only | 1187 | }//else //debug only |
1188 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); | 1188 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); |
1189 | } | 1189 | } |
1190 | int result; | 1190 | int result; |
1191 | bool localIsNew; | 1191 | bool localIsNew; |
1192 | //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , localMod.toString().latin1() , remoteMod.toString().latin1() ); | 1192 | //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , localMod.toString().latin1() , remoteMod.toString().latin1() ); |
1193 | 1193 | ||
1194 | 1194 | ||
1195 | // ************************************************ | 1195 | // ************************************************ |
1196 | // ************************************************ | 1196 | // ************************************************ |
1197 | // ************************************************ | 1197 | // ************************************************ |
1198 | // We may have that lastSync > remoteMod AND lastSync > localMod | 1198 | // We may have that lastSync > remoteMod AND lastSync > localMod |
1199 | // BUT remoteMod != localMod | 1199 | // BUT remoteMod != localMod |
1200 | 1200 | ||
1201 | 1201 | ||
1202 | if ( full && mode < SYNC_PREF_NEWEST ) | 1202 | if ( full && mode < SYNC_PREF_NEWEST ) |
1203 | mode = SYNC_PREF_ASK; | 1203 | mode = SYNC_PREF_ASK; |
1204 | 1204 | ||
1205 | switch( mode ) { | 1205 | switch( mode ) { |
1206 | case SYNC_PREF_LOCAL: | 1206 | case SYNC_PREF_LOCAL: |
1207 | if ( lastSync > remoteMod ) | 1207 | if ( lastSync > remoteMod ) |
1208 | return 1; | 1208 | return 1; |
1209 | if ( lastSync > localMod ) | 1209 | if ( lastSync > localMod ) |
1210 | return 2; | 1210 | return 2; |
1211 | return 1; | 1211 | return 1; |
1212 | break; | 1212 | break; |
1213 | case SYNC_PREF_REMOTE: | 1213 | case SYNC_PREF_REMOTE: |
1214 | if ( lastSync > localMod ) | 1214 | if ( lastSync > localMod ) |
1215 | return 2; | 1215 | return 2; |
1216 | if ( lastSync > remoteMod ) | 1216 | if ( lastSync > remoteMod ) |
1217 | return 1; | 1217 | return 1; |
1218 | return 2; | 1218 | return 2; |
1219 | break; | 1219 | break; |
1220 | case SYNC_PREF_NEWEST: | 1220 | case SYNC_PREF_NEWEST: |
1221 | if ( localMod >= remoteMod ) | 1221 | if ( localMod >= remoteMod ) |
1222 | return 1; | 1222 | return 1; |
1223 | else | 1223 | else |
1224 | return 2; | 1224 | return 2; |
1225 | break; | 1225 | break; |
1226 | case SYNC_PREF_ASK: | 1226 | case SYNC_PREF_ASK: |
1227 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); | 1227 | qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); |
1228 | if ( lastSync > remoteMod && lastSync > localMod) | 1228 | if ( lastSync > remoteMod && lastSync > localMod) |
1229 | return 0; | 1229 | return 0; |
1230 | if ( lastSync > remoteMod ) | 1230 | if ( lastSync > remoteMod ) |
1231 | return 1; | 1231 | return 1; |
1232 | if ( lastSync > localMod ) | 1232 | if ( lastSync > localMod ) |
1233 | return 2; | 1233 | return 2; |
1234 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); | 1234 | qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); |
1235 | localIsNew = localMod >= remoteMod; | 1235 | localIsNew = localMod >= remoteMod; |
1236 | if ( localIsNew ) | 1236 | if ( localIsNew ) |
1237 | getEventViewerDialog()->setColorMode( 1 ); | 1237 | getEventViewerDialog()->setColorMode( 1 ); |
1238 | else | 1238 | else |
1239 | getEventViewerDialog()->setColorMode( 2 ); | 1239 | getEventViewerDialog()->setColorMode( 2 ); |
1240 | getEventViewerDialog()->setIncidence(local); | 1240 | getEventViewerDialog()->setIncidence(local); |
1241 | if ( localIsNew ) | 1241 | if ( localIsNew ) |
1242 | getEventViewerDialog()->setColorMode( 2 ); | 1242 | getEventViewerDialog()->setColorMode( 2 ); |
1243 | else | 1243 | else |
1244 | getEventViewerDialog()->setColorMode( 1 ); | 1244 | getEventViewerDialog()->setColorMode( 1 ); |
1245 | getEventViewerDialog()->addIncidence(remote); | 1245 | getEventViewerDialog()->addIncidence(remote); |
1246 | getEventViewerDialog()->setColorMode( 0 ); | 1246 | getEventViewerDialog()->setColorMode( 0 ); |
1247 | //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); | 1247 | //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); |
1248 | getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); | 1248 | getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); |
1249 | getEventViewerDialog()->showMe(); | 1249 | getEventViewerDialog()->showMe(); |
1250 | result = getEventViewerDialog()->executeS( localIsNew ); | 1250 | result = getEventViewerDialog()->executeS( localIsNew ); |
1251 | return result; | 1251 | return result; |
1252 | 1252 | ||
1253 | break; | 1253 | break; |
1254 | case SYNC_PREF_FORCE_LOCAL: | 1254 | case SYNC_PREF_FORCE_LOCAL: |
1255 | return 1; | 1255 | return 1; |
1256 | break; | 1256 | break; |
1257 | case SYNC_PREF_FORCE_REMOTE: | 1257 | case SYNC_PREF_FORCE_REMOTE: |
1258 | return 2; | 1258 | return 2; |
1259 | break; | 1259 | break; |
1260 | 1260 | ||
1261 | default: | 1261 | default: |
1262 | // SYNC_PREF_TAKE_BOTH not implemented | 1262 | // SYNC_PREF_TAKE_BOTH not implemented |
1263 | break; | 1263 | break; |
1264 | } | 1264 | } |
1265 | return 0; | 1265 | return 0; |
1266 | } | 1266 | } |
1267 | Event* CalendarView::getLastSyncEvent() | 1267 | Event* CalendarView::getLastSyncEvent() |
1268 | { | 1268 | { |
1269 | Event* lse; | 1269 | Event* lse; |
1270 | //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); | 1270 | //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); |
1271 | lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); | 1271 | lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); |
1272 | if (!lse) { | 1272 | if (!lse) { |
1273 | lse = new Event(); | 1273 | lse = new Event(); |
1274 | lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); | 1274 | lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); |
1275 | QString sum = ""; | 1275 | QString sum = ""; |
1276 | if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) | 1276 | if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) |
1277 | sum = "E: "; | 1277 | sum = "E: "; |
1278 | lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); | 1278 | lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); |
1279 | lse->setDtStart( mLastCalendarSync ); | 1279 | lse->setDtStart( mLastCalendarSync ); |
1280 | lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); | 1280 | lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); |
1281 | lse->setCategories( i18n("SyncEvent") ); | 1281 | lse->setCategories( i18n("SyncEvent") ); |
1282 | lse->setReadOnly( true ); | 1282 | lse->setReadOnly( true ); |
1283 | mCalendar->addEvent( lse ); | 1283 | mCalendar->addEvent( lse ); |
1284 | } | 1284 | } |
1285 | 1285 | ||
1286 | return lse; | 1286 | return lse; |
1287 | 1287 | ||
1288 | } | 1288 | } |
1289 | 1289 | ||
1290 | // we check, if the to delete event has a id for a profile | 1290 | // we check, if the to delete event has a id for a profile |
1291 | // if yes, we set this id in the profile to delete | 1291 | // if yes, we set this id in the profile to delete |
1292 | void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) | 1292 | void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) |
1293 | { | 1293 | { |
1294 | if ( lastSync.count() == 0 ) { | 1294 | if ( lastSync.count() == 0 ) { |
1295 | //qDebug(" lastSync.count() == 0"); | 1295 | //qDebug(" lastSync.count() == 0"); |
1296 | return; | 1296 | return; |
1297 | } | 1297 | } |
1298 | if ( toDelete->typeID() == journalID ) | 1298 | if ( toDelete->typeID() == journalID ) |
1299 | return; | 1299 | return; |
1300 | 1300 | ||
1301 | Event* eve = lastSync.first(); | 1301 | Event* eve = lastSync.first(); |
1302 | 1302 | ||
1303 | while ( eve ) { | 1303 | while ( eve ) { |
1304 | QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name | 1304 | QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name |
1305 | if ( !id.isEmpty() ) { | 1305 | if ( !id.isEmpty() ) { |
1306 | QString des = eve->description(); | 1306 | QString des = eve->description(); |
1307 | QString pref = "e"; | 1307 | QString pref = "e"; |
1308 | if ( toDelete->typeID() == todoID ) | 1308 | if ( toDelete->typeID() == todoID ) |
1309 | pref = "t"; | 1309 | pref = "t"; |
1310 | des += pref+ id + ","; | 1310 | des += pref+ id + ","; |
1311 | eve->setReadOnly( false ); | 1311 | eve->setReadOnly( false ); |
1312 | eve->setDescription( des ); | 1312 | eve->setDescription( des ); |
1313 | //qDebug("setdes %s ", des.latin1()); | 1313 | //qDebug("setdes %s ", des.latin1()); |
1314 | eve->setReadOnly( true ); | 1314 | eve->setReadOnly( true ); |
1315 | } | 1315 | } |
1316 | eve = lastSync.next(); | 1316 | eve = lastSync.next(); |
1317 | } | 1317 | } |
1318 | 1318 | ||
1319 | } | 1319 | } |
1320 | void CalendarView::checkExternalId( Incidence * inc ) | 1320 | void CalendarView::checkExternalId( Incidence * inc ) |
1321 | { | 1321 | { |
1322 | QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; | 1322 | QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; |
1323 | checkExternSyncEvent( lastSync, inc ); | 1323 | checkExternSyncEvent( lastSync, inc ); |
1324 | 1324 | ||
1325 | } | 1325 | } |
1326 | bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) | 1326 | bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) |
1327 | { | 1327 | { |
1328 | bool syncOK = true; | 1328 | bool syncOK = true; |
1329 | int addedEvent = 0; | 1329 | int addedEvent = 0; |
1330 | int addedEventR = 0; | 1330 | int addedEventR = 0; |
1331 | int deletedEventR = 0; | 1331 | int deletedEventR = 0; |
1332 | int deletedEventL = 0; | 1332 | int deletedEventL = 0; |
1333 | int changedLocal = 0; | 1333 | int changedLocal = 0; |
1334 | int changedRemote = 0; | 1334 | int changedRemote = 0; |
1335 | int filteredIN = 0; | 1335 | int filteredIN = 0; |
1336 | int filteredOUT = 0; | 1336 | int filteredOUT = 0; |
1337 | //QPtrList<Event> el = local->rawEvents(); | 1337 | //QPtrList<Event> el = local->rawEvents(); |
1338 | Event* eventR; | 1338 | Event* eventR; |
1339 | QString uid; | 1339 | QString uid; |
1340 | int take; | 1340 | int take; |
1341 | Event* eventRSync; | 1341 | Event* eventRSync; |
1342 | Event* eventLSync; | 1342 | Event* eventLSync; |
1343 | clearAllViews(); | 1343 | clearAllViews(); |
1344 | QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); | 1344 | QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); |
1345 | QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); | 1345 | QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); |
1346 | bool fullDateRange = false; | 1346 | bool fullDateRange = false; |
1347 | local->resetTempSyncStat(); | 1347 | local->resetTempSyncStat(); |
1348 | mLastCalendarSync = QDateTime::currentDateTime(); | 1348 | mLastCalendarSync = QDateTime::currentDateTime(); |
1349 | if ( mSyncManager->syncWithDesktop() ) { | 1349 | if ( mSyncManager->syncWithDesktop() ) { |
1350 | remote->resetPilotStat(1); | 1350 | remote->resetPilotStat(1); |
1351 | if ( KSyncManager::mRequestedSyncEvent.isValid() ) { | 1351 | if ( KSyncManager::mRequestedSyncEvent.isValid() ) { |
1352 | mLastCalendarSync = KSyncManager::mRequestedSyncEvent; | 1352 | mLastCalendarSync = KSyncManager::mRequestedSyncEvent; |
1353 | qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() ); | 1353 | qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() ); |
1354 | } else { | 1354 | } else { |
1355 | qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); | 1355 | qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); |
1356 | } | 1356 | } |
1357 | } | 1357 | } |
1358 | QDateTime modifiedCalendar = mLastCalendarSync; | 1358 | QDateTime modifiedCalendar = mLastCalendarSync; |
1359 | eventLSync = getLastSyncEvent(); | 1359 | eventLSync = getLastSyncEvent(); |
1360 | eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); | 1360 | eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); |
1361 | if ( eventR ) { | 1361 | if ( eventR ) { |
1362 | qDebug("last-syncEvent on remote found "); | ||
1362 | eventRSync = (Event*) eventR->clone(); | 1363 | eventRSync = (Event*) eventR->clone(); |
1363 | remote->deleteEvent(eventR ); | 1364 | remote->deleteEvent(eventR ); |
1364 | 1365 | ||
1365 | } else { | 1366 | } else { |
1366 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) { | 1367 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) { |
1367 | eventRSync = (Event*)eventLSync->clone(); | 1368 | eventRSync = (Event*)eventLSync->clone(); |
1368 | } else { | 1369 | } else { |
1369 | fullDateRange = true; | 1370 | fullDateRange = true; |
1370 | eventRSync = new Event(); | 1371 | eventRSync = new Event(); |
1371 | eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); | 1372 | eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); |
1372 | eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); | 1373 | eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); |
1373 | eventRSync->setDtStart( mLastCalendarSync ); | 1374 | eventRSync->setDtStart( mLastCalendarSync ); |
1374 | eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); | 1375 | eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); |
1375 | eventRSync->setCategories( i18n("SyncEvent") ); | 1376 | eventRSync->setCategories( i18n("SyncEvent") ); |
1376 | } | 1377 | } |
1377 | } | 1378 | } |
1378 | if ( eventLSync->dtStart() == mLastCalendarSync ) | 1379 | if ( eventLSync->dtStart() == mLastCalendarSync ) |
1379 | fullDateRange = true; | 1380 | fullDateRange = true; |
1380 | 1381 | ||
1381 | if ( ! fullDateRange ) { | 1382 | if ( ! fullDateRange ) { |
1382 | if ( eventLSync->dtStart() != eventRSync->dtStart() ) { | 1383 | if ( eventLSync->dtStart() != eventRSync->dtStart() ) { |
1383 | 1384 | ||
1384 | // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); | 1385 | qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); |
1385 | //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); | 1386 | //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); |
1386 | fullDateRange = true; | 1387 | fullDateRange = true; |
1387 | } | 1388 | } |
1388 | } | 1389 | } |
1389 | if ( mSyncManager->syncWithDesktop() ) { | 1390 | if ( mSyncManager->syncWithDesktop() ) { |
1390 | fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync ); | 1391 | fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync ); |
1391 | } | 1392 | } |
1392 | if ( fullDateRange ) | 1393 | if ( fullDateRange ) |
1393 | mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); | 1394 | mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); |
1394 | else | 1395 | else |
1395 | mLastCalendarSync = eventLSync->dtStart(); | 1396 | mLastCalendarSync = eventLSync->dtStart(); |
1396 | // for resyncing if own file has changed | 1397 | // for resyncing if own file has changed |
1397 | if ( mCurrentSyncDevice == "deleteaftersync" ) { | 1398 | if ( mCurrentSyncDevice == "deleteaftersync" ) { |
1398 | mLastCalendarSync = loadedFileVersion; | 1399 | mLastCalendarSync = loadedFileVersion; |
1399 | //qDebug("setting mLastCalendarSync "); | 1400 | //qDebug("setting mLastCalendarSync "); |
1400 | } | 1401 | } |
1401 | //qDebug("*************************** "); | 1402 | //qDebug("*************************** "); |
1402 | qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange); | 1403 | qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange); |
1403 | QPtrList<Incidence> er = remote->rawIncidences(); | 1404 | QPtrList<Incidence> er = remote->rawIncidences(); |
1404 | Incidence* inR = er.first(); | 1405 | Incidence* inR = er.first(); |
1405 | Incidence* inL; | 1406 | Incidence* inL; |
1406 | QProgressBar bar( er.count(),0 ); | 1407 | QProgressBar bar( er.count(),0 ); |
1407 | bar.setCaption (i18n("Syncing - close to abort!") ); | 1408 | bar.setCaption (i18n("Syncing - close to abort!") ); |
1408 | 1409 | ||
1409 | // ************** setting up filter ************* | 1410 | // ************** setting up filter ************* |
1410 | CalFilter *filterIN = 0; | 1411 | CalFilter *filterIN = 0; |
1411 | CalFilter *filterOUT = 0; | 1412 | CalFilter *filterOUT = 0; |
1412 | CalFilter *filter = mFilters.first(); | 1413 | CalFilter *filter = mFilters.first(); |
1413 | while(filter) { | 1414 | while(filter) { |
1414 | if ( filter->name() == mSyncManager->mFilterInCal ) | 1415 | if ( filter->name() == mSyncManager->mFilterInCal ) |
1415 | filterIN = filter; | 1416 | filterIN = filter; |
1416 | if ( filter->name() == mSyncManager->mFilterOutCal ) | 1417 | if ( filter->name() == mSyncManager->mFilterOutCal ) |
1417 | filterOUT = filter; | 1418 | filterOUT = filter; |
1418 | filter = mFilters.next(); | 1419 | filter = mFilters.next(); |
1419 | } | 1420 | } |
1420 | int w = 300; | 1421 | int w = 300; |
1421 | if ( QApplication::desktop()->width() < 320 ) | 1422 | if ( QApplication::desktop()->width() < 320 ) |
1422 | w = 220; | 1423 | w = 220; |
1423 | int h = bar.sizeHint().height() ; | 1424 | int h = bar.sizeHint().height() ; |
1424 | int dw = QApplication::desktop()->width(); | 1425 | int dw = QApplication::desktop()->width(); |
1425 | int dh = QApplication::desktop()->height(); | 1426 | int dh = QApplication::desktop()->height(); |
1426 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 1427 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
1427 | bar.show(); | 1428 | bar.show(); |
1428 | int modulo = (er.count()/10)+1; | 1429 | int modulo = (er.count()/10)+1; |
1429 | int incCounter = 0; | 1430 | int incCounter = 0; |
1430 | while ( inR ) { | 1431 | while ( inR ) { |
1431 | if ( ! bar.isVisible() ) | 1432 | if ( ! bar.isVisible() ) |
1432 | return false; | 1433 | return false; |
1433 | if ( incCounter % modulo == 0 ) | 1434 | if ( incCounter % modulo == 0 ) |
1434 | bar.setProgress( incCounter ); | 1435 | bar.setProgress( incCounter ); |
1435 | ++incCounter; | 1436 | ++incCounter; |
1436 | uid = inR->uid(); | 1437 | uid = inR->uid(); |
1437 | bool skipIncidence = false; | 1438 | bool skipIncidence = false; |
1438 | if ( uid.left(15) == QString("last-syncEvent-") ) | 1439 | if ( uid.left(15) == QString("last-syncEvent-") ) |
1439 | skipIncidence = true; | 1440 | skipIncidence = true; |
1440 | QString idS; | 1441 | QString idS; |
1441 | qApp->processEvents(); | 1442 | qApp->processEvents(); |
1442 | if ( !skipIncidence ) { | 1443 | if ( !skipIncidence ) { |
1443 | inL = local->incidence( uid ); | 1444 | inL = local->incidence( uid ); |
1444 | if ( inL ) { // maybe conflict - same uid in both calendars | 1445 | if ( inL ) { // maybe conflict - same uid in both calendars |
1445 | if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { | 1446 | if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { |
1446 | //qDebug("take %d %s ", take, inL->summary().latin1()); | 1447 | //qDebug("take %d %s ", take, inL->summary().latin1()); |
1447 | if ( take == 3 ) | 1448 | if ( take == 3 ) |
1448 | return false; | 1449 | return false; |
1449 | if ( take == 1 ) {// take local ********************** | 1450 | if ( take == 1 ) {// take local ********************** |
1450 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) | 1451 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) |
1451 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); | 1452 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); |
1452 | else | 1453 | else |
1453 | idS = inR->IDStr(); | 1454 | idS = inR->IDStr(); |
1454 | int calID = inR->calID(); | 1455 | int calID = inR->calID(); |
1455 | remote->deleteIncidence( inR ); | 1456 | remote->deleteIncidence( inR ); |
1456 | inR = inL->clone(); | 1457 | inR = inL->clone(); |
1457 | inR->setCalID( calID ); | 1458 | inR->setCalID( calID ); |
1458 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 1459 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
1459 | if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) | 1460 | if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) |
1460 | inR->setIDStr( idS ); | 1461 | inR->setIDStr( idS ); |
1461 | remote->addIncidence( inR ); | 1462 | remote->addIncidence( inR ); |
1462 | if ( mSyncManager->syncWithDesktop() ) | 1463 | if ( mSyncManager->syncWithDesktop() ) |
1463 | inR->setPilotId( 2 ); | 1464 | inR->setPilotId( 2 ); |
1464 | ++changedRemote; | 1465 | ++changedRemote; |
1465 | } else {// take remote ********************** | 1466 | } else {// take remote ********************** |
1466 | idS = inL->IDStr(); | 1467 | idS = inL->IDStr(); |
1467 | int pid = inL->pilotId(); | 1468 | int pid = inL->pilotId(); |
1468 | int calID = inL->calID(); | 1469 | int calID = inL->calID(); |
1469 | local->deleteIncidence( inL ); | 1470 | local->deleteIncidence( inL ); |
1470 | inL = inR->clone(); | 1471 | inL = inR->clone(); |
1471 | inL->setCalID( calID ); | 1472 | inL->setCalID( calID ); |
1472 | if ( mSyncManager->syncWithDesktop() ) | 1473 | if ( mSyncManager->syncWithDesktop() ) |
1473 | inL->setPilotId( pid ); | 1474 | inL->setPilotId( pid ); |
1474 | inL->setIDStr( idS ); | 1475 | inL->setIDStr( idS ); |
1475 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 1476 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
1476 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); | 1477 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); |
1477 | inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); | 1478 | inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); |
1478 | } | 1479 | } |
1479 | local->addIncidence( inL ); | 1480 | local->addIncidence( inL ); |
1480 | ++changedLocal; | 1481 | ++changedLocal; |
1481 | } | 1482 | } |
1482 | } | 1483 | } |
1483 | } else { // no conflict ********** add or delete remote | 1484 | } else { // no conflict ********** add or delete remote |
1484 | if ( !filterIN || filterIN->filterCalendarItem( inR ) ){ | 1485 | if ( !filterIN || filterIN->filterCalendarItem( inR ) ){ |
1485 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 1486 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
1486 | QString des = eventLSync->description(); | 1487 | QString des = eventLSync->description(); |
1487 | QString pref = "e"; | 1488 | QString pref = "e"; |
1488 | if ( inR->typeID() == todoID ) | 1489 | if ( inR->typeID() == todoID ) |
1489 | pref = "t"; | 1490 | pref = "t"; |
1490 | if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it | 1491 | if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it |
1491 | inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); | 1492 | inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); |
1492 | //remote->deleteIncidence( inR ); | 1493 | //remote->deleteIncidence( inR ); |
1493 | ++deletedEventR; | 1494 | ++deletedEventR; |
1494 | } else { | 1495 | } else { |
1495 | inR->setLastModified( modifiedCalendar ); | 1496 | inR->setLastModified( modifiedCalendar ); |
1496 | inL = inR->clone(); | 1497 | inL = inR->clone(); |
1497 | inL->setIDStr( ":" ); | 1498 | inL->setIDStr( ":" ); |
1498 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); | 1499 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); |
1499 | inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); | 1500 | inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); |
1500 | 1501 | ||
1501 | inL->setCalID( 0 );// add to default cal | 1502 | inL->setCalID( 0 );// add to default cal |
1502 | local->addIncidence( inL ); | 1503 | local->addIncidence( inL ); |
1503 | ++addedEvent; | 1504 | ++addedEvent; |
1504 | 1505 | ||
1505 | } | 1506 | } |
1506 | } else { | 1507 | } else { |
1507 | if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { | 1508 | if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { |
1508 | inR->setLastModified( modifiedCalendar ); | 1509 | inR->setLastModified( modifiedCalendar ); |
1509 | inL = inR->clone(); | 1510 | inL = inR->clone(); |
1510 | inL->setIDStr( ":" ); | 1511 | inL->setIDStr( ":" ); |
1511 | inL->setCalID( 0 );// add to default cal | 1512 | inL->setCalID( 0 );// add to default cal |
1512 | local->addIncidence( inL ); | 1513 | local->addIncidence( inL ); |
1513 | ++addedEvent; | 1514 | ++addedEvent; |
1514 | 1515 | ||
1515 | } else { | 1516 | } else { |
1516 | checkExternSyncEvent(eventRSyncSharp, inR); | 1517 | checkExternSyncEvent(eventRSyncSharp, inR); |
1517 | remote->deleteIncidence( inR ); | 1518 | remote->deleteIncidence( inR ); |
1518 | ++deletedEventR; | 1519 | ++deletedEventR; |
1519 | } | 1520 | } |
1520 | } | 1521 | } |
1521 | } else { | 1522 | } else { |
1522 | ++filteredIN; | 1523 | ++filteredIN; |
1523 | } | 1524 | } |
1524 | } | 1525 | } |
1525 | } | 1526 | } |
1526 | inR = er.next(); | 1527 | inR = er.next(); |
1527 | } | 1528 | } |
1528 | QPtrList<Incidence> el = local->rawIncidences(); | 1529 | QPtrList<Incidence> el = local->rawIncidences(); |
1529 | inL = el.first(); | 1530 | inL = el.first(); |
1530 | modulo = (el.count()/10)+1; | 1531 | modulo = (el.count()/10)+1; |
1531 | bar.setCaption (i18n("Add / remove events") ); | 1532 | bar.setCaption (i18n("Add / remove events") ); |
1532 | bar.setTotalSteps ( el.count() ) ; | 1533 | bar.setTotalSteps ( el.count() ) ; |
1533 | bar.show(); | 1534 | bar.show(); |
1534 | incCounter = 0; | 1535 | incCounter = 0; |
1535 | 1536 | ||
1536 | while ( inL ) { | 1537 | while ( inL ) { |
1537 | 1538 | ||
1538 | qApp->processEvents(); | 1539 | qApp->processEvents(); |
1539 | if ( ! bar.isVisible() ) | 1540 | if ( ! bar.isVisible() ) |
1540 | return false; | 1541 | return false; |
1541 | if ( incCounter % modulo == 0 ) | 1542 | if ( incCounter % modulo == 0 ) |
1542 | bar.setProgress( incCounter ); | 1543 | bar.setProgress( incCounter ); |
1543 | ++incCounter; | 1544 | ++incCounter; |
1544 | uid = inL->uid(); | 1545 | uid = inL->uid(); |
1545 | bool skipIncidence = false; | 1546 | bool skipIncidence = false; |
1546 | if ( uid.left(15) == QString("last-syncEvent-") ) | 1547 | if ( uid.left(15) == QString("last-syncEvent-") ) |
1547 | skipIncidence = true; | 1548 | skipIncidence = true; |
1548 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->typeID() == journalID ) | 1549 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->typeID() == journalID ) |
1549 | skipIncidence = true; | 1550 | skipIncidence = true; |
1550 | if ( !skipIncidence ) { | 1551 | if ( !skipIncidence ) { |
1551 | inR = remote->incidence( uid ); | 1552 | inR = remote->incidence( uid ); |
1552 | if ( ! inR ) { | 1553 | if ( ! inR ) { |
1553 | if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){ | 1554 | if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){ |
1554 | // no conflict ********** add or delete local | 1555 | // no conflict ********** add or delete local |
1555 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 1556 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
1556 | if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { | 1557 | if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { |
1557 | checkExternSyncEvent(eventLSyncSharp, inL); | 1558 | checkExternSyncEvent(eventLSyncSharp, inL); |
1558 | local->deleteIncidence( inL ); | 1559 | local->deleteIncidence( inL ); |
1559 | ++deletedEventL; | 1560 | ++deletedEventL; |
1560 | } else { | 1561 | } else { |
1561 | if ( ! mSyncManager->mWriteBackExistingOnly ) { | 1562 | if ( ! mSyncManager->mWriteBackExistingOnly ) { |
1562 | inL->removeID(mCurrentSyncDevice ); | 1563 | inL->removeID(mCurrentSyncDevice ); |
1563 | ++addedEventR; | 1564 | ++addedEventR; |
1564 | //qDebug("remote added Incidence %s ", inL->summary().latin1()); | 1565 | //qDebug("remote added Incidence %s ", inL->summary().latin1()); |
1565 | inL->setLastModified( modifiedCalendar ); | 1566 | inL->setLastModified( modifiedCalendar ); |
1566 | inR = inL->clone(); | 1567 | inR = inL->clone(); |
1567 | inR->setIDStr( ":" ); | 1568 | inR->setIDStr( ":" ); |
1568 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 1569 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
1569 | inR->setCalID( 0 );// add to default cal | 1570 | inR->setCalID( 0 );// add to default cal |
1570 | remote->addIncidence( inR ); | 1571 | remote->addIncidence( inR ); |
1571 | } | 1572 | } |
1572 | } | 1573 | } |
1573 | } else { | 1574 | } else { |
1574 | if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { | 1575 | if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { |
1575 | checkExternSyncEvent(eventLSyncSharp, inL); | 1576 | checkExternSyncEvent(eventLSyncSharp, inL); |
1576 | local->deleteIncidence( inL ); | 1577 | local->deleteIncidence( inL ); |
1577 | ++deletedEventL; | 1578 | ++deletedEventL; |
1578 | } else { | 1579 | } else { |
1579 | if ( ! mSyncManager->mWriteBackExistingOnly ) { | 1580 | if ( ! mSyncManager->mWriteBackExistingOnly ) { |
1580 | ++addedEventR; | 1581 | ++addedEventR; |
1581 | inL->setLastModified( modifiedCalendar ); | 1582 | inL->setLastModified( modifiedCalendar ); |
1582 | inR = inL->clone(); | 1583 | inR = inL->clone(); |
1583 | inR->setIDStr( ":" ); | 1584 | inR->setIDStr( ":" ); |
1584 | inR->setCalID( 0 );// add to default cal | 1585 | inR->setCalID( 0 );// add to default cal |
1585 | remote->addIncidence( inR ); | 1586 | remote->addIncidence( inR ); |
1586 | } | 1587 | } |
1587 | } | 1588 | } |
1588 | } | 1589 | } |
1589 | } else { | 1590 | } else { |
1590 | ++filteredOUT; | 1591 | ++filteredOUT; |
1591 | } | 1592 | } |
1592 | } | 1593 | } |
1593 | } | 1594 | } |
1594 | inL = el.next(); | 1595 | inL = el.next(); |
1595 | } | 1596 | } |
1596 | int delFut = 0; | 1597 | int delFut = 0; |
1597 | int remRem = 0; | 1598 | int remRem = 0; |
1598 | if ( mSyncManager->mWriteBackInFuture ) { | 1599 | if ( mSyncManager->mWriteBackInFuture ) { |
1599 | er = remote->rawIncidences(); | 1600 | er = remote->rawIncidences(); |
1600 | remRem = er.count(); | 1601 | remRem = er.count(); |
1601 | inR = er.first(); | 1602 | inR = er.first(); |
1602 | QDateTime dt; | 1603 | QDateTime dt; |
1603 | QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) ); | 1604 | QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) ); |
1604 | QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 ); | 1605 | QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 ); |
1605 | while ( inR ) { | 1606 | while ( inR ) { |
1606 | if ( inR->typeID() == todoID ) { | 1607 | if ( inR->typeID() == todoID ) { |
1607 | Todo * t = (Todo*)inR; | 1608 | Todo * t = (Todo*)inR; |
1608 | if ( t->hasDueDate() ) | 1609 | if ( t->hasDueDate() ) |
1609 | dt = t->dtDue(); | 1610 | dt = t->dtDue(); |
1610 | else | 1611 | else |
1611 | dt = cur.addSecs( 62 ); | 1612 | dt = cur.addSecs( 62 ); |
1612 | } | 1613 | } |
1613 | else if (inR->typeID() == eventID ) { | 1614 | else if (inR->typeID() == eventID ) { |
1614 | bool ok; | 1615 | bool ok; |
1615 | dt = inR->getNextOccurence( cur, &ok ); | 1616 | dt = inR->getNextOccurence( cur, &ok ); |
1616 | if ( !ok ) | 1617 | if ( !ok ) |
1617 | dt = cur.addSecs( -62 ); | 1618 | dt = cur.addSecs( -62 ); |
1618 | } | 1619 | } |
1619 | else | 1620 | else |
1620 | dt = inR->dtStart(); | 1621 | dt = inR->dtStart(); |
1621 | if ( dt < cur || dt > end ) { | 1622 | if ( dt < cur || dt > end ) { |
1622 | remote->deleteIncidence( inR ); | 1623 | remote->deleteIncidence( inR ); |
1623 | ++delFut; | 1624 | ++delFut; |
1624 | } | 1625 | } |
1625 | inR = er.next(); | 1626 | inR = er.next(); |
1626 | } | 1627 | } |
1627 | } | 1628 | } |
1628 | bar.hide(); | 1629 | bar.hide(); |
1629 | mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); | 1630 | mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); |
1630 | eventLSync->setReadOnly( false ); | 1631 | eventLSync->setReadOnly( false ); |
1631 | eventLSync->setDtStart( mLastCalendarSync ); | 1632 | eventLSync->setDtStart( mLastCalendarSync ); |
1632 | eventRSync->setDtStart( mLastCalendarSync ); | 1633 | eventRSync->setDtStart( mLastCalendarSync ); |
1633 | eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); | 1634 | eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); |
1634 | eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); | 1635 | eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); |
1635 | eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; | 1636 | eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; |
1636 | eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); | 1637 | eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); |
1637 | eventLSync->setReadOnly( true ); | 1638 | eventLSync->setReadOnly( true ); |
1638 | qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL ); | 1639 | qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL ); |
1639 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal... | 1640 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal... |
1640 | remote->addEvent( eventRSync ); | 1641 | remote->addEvent( eventRSync ); |
1641 | else | 1642 | else |
1642 | delete eventRSync; | 1643 | delete eventRSync; |
1643 | qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() ); | 1644 | qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() ); |
1644 | QString mes; | 1645 | QString mes; |
1645 | mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n %d incoming filtered out\n %d outgoing filtered out\n"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR, filteredIN, filteredOUT ); | 1646 | mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n %d incoming filtered out\n %d outgoing filtered out\n"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR, filteredIN, filteredOUT ); |
1646 | QString delmess; | 1647 | QString delmess; |
1647 | if ( delFut ) { | 1648 | if ( delFut ) { |
1648 | delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are more\nthan %d weeks in the past or\nmore than %d weeks in the future.\nAfter skipping, remote has\n%d calendar/todo items."), delFut,mSyncManager->mWriteBackInPast,mSyncManager->mWriteBackInFuture, remRem-delFut); | 1649 | delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are more\nthan %d weeks in the past or\nmore than %d weeks in the future.\nAfter skipping, remote has\n%d calendar/todo items."), delFut,mSyncManager->mWriteBackInPast,mSyncManager->mWriteBackInFuture, remRem-delFut); |
1649 | mes += delmess; | 1650 | mes += delmess; |
1650 | } | 1651 | } |
1651 | mes = i18n("Local calendar changed!\n") +mes; | 1652 | mes = i18n("Local calendar changed!\n") +mes; |
1652 | mCalendar->checkAlarmForIncidence( 0, true ); | 1653 | mCalendar->checkAlarmForIncidence( 0, true ); |
1653 | qDebug( mes ); | 1654 | qDebug( mes ); |
1654 | if ( mSyncManager->mShowSyncSummary ) { | 1655 | if ( mSyncManager->mShowSyncSummary ) { |
1655 | if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, | 1656 | if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, |
1656 | i18n("KO/Pi Synchronization"),i18n("Write back"))) { | 1657 | i18n("KO/Pi Synchronization"),i18n("Write back"))) { |
1657 | qDebug("KO: WB cancelled "); | 1658 | qDebug("KO: WB cancelled "); |
1658 | mSyncManager->mWriteBackFile = false; | 1659 | mSyncManager->mWriteBackFile = false; |
1659 | return syncOK; | 1660 | return syncOK; |
1660 | } | 1661 | } |
1661 | } | 1662 | } |
1662 | return syncOK; | 1663 | return syncOK; |
1663 | } | 1664 | } |
1664 | 1665 | ||
1665 | void CalendarView::setSyncDevice( QString s ) | 1666 | void CalendarView::setSyncDevice( QString s ) |
1666 | { | 1667 | { |
1667 | mCurrentSyncDevice= s; | 1668 | mCurrentSyncDevice= s; |
1668 | } | 1669 | } |
1669 | void CalendarView::setSyncName( QString s ) | 1670 | void CalendarView::setSyncName( QString s ) |
1670 | { | 1671 | { |
1671 | mCurrentSyncName= s; | 1672 | mCurrentSyncName= s; |
1672 | } | 1673 | } |
1673 | bool CalendarView::syncCalendar(QString filename, int mode) | 1674 | bool CalendarView::syncCalendar(QString filename, int mode) |
1674 | { | 1675 | { |
1675 | //qDebug("syncCalendar %s ", filename.latin1()); | 1676 | //qDebug("syncCalendar %s ", filename.latin1()); |
1676 | mGlobalSyncMode = SYNC_MODE_NORMAL; | 1677 | mGlobalSyncMode = SYNC_MODE_NORMAL; |
1677 | CalendarLocal* calendar = new CalendarLocal(); | 1678 | CalendarLocal* calendar = new CalendarLocal(); |
1678 | calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); | 1679 | calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); |
1679 | FileStorage* storage = new FileStorage( calendar ); | 1680 | FileStorage* storage = new FileStorage( calendar ); |
1680 | bool syncOK = false; | 1681 | bool syncOK = false; |
1681 | storage->setFileName( filename ); | 1682 | storage->setFileName( filename ); |
1682 | // qDebug("loading ... "); | 1683 | // qDebug("loading ... "); |
1683 | if ( storage->load() ) { | 1684 | if ( storage->load() ) { |
1684 | getEventViewerDialog()->setSyncMode( true ); | 1685 | getEventViewerDialog()->setSyncMode( true ); |
1685 | syncOK = synchronizeCalendar( mCalendar, calendar, mode ); | 1686 | syncOK = synchronizeCalendar( mCalendar, calendar, mode ); |
1686 | getEventViewerDialog()->setSyncMode( false ); | 1687 | getEventViewerDialog()->setSyncMode( false ); |
1687 | if ( syncOK ) { | 1688 | if ( syncOK ) { |
1688 | if ( mSyncManager->mWriteBackFile ) | 1689 | if ( mSyncManager->mWriteBackFile ) |
1689 | { | 1690 | { |
1690 | storage->setSaveFormat( new ICalFormat() ); | 1691 | storage->setSaveFormat( new ICalFormat() ); |
1691 | storage->save(); | 1692 | storage->save(); |
1692 | } | 1693 | } |
1693 | } | 1694 | } |
1694 | setModified( true ); | 1695 | setModified( true ); |
1695 | } | 1696 | } |
1696 | delete storage; | 1697 | delete storage; |
1697 | delete calendar; | 1698 | delete calendar; |
1698 | if ( syncOK ) | 1699 | if ( syncOK ) |
1699 | updateView(); | 1700 | updateView(); |
1700 | return syncOK; | 1701 | return syncOK; |
1701 | } | 1702 | } |
1702 | 1703 | ||
1703 | void CalendarView::syncExternal( int mode ) | 1704 | void CalendarView::syncExternal( int mode ) |
1704 | { | 1705 | { |
1705 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 1706 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
1706 | 1707 | ||
1707 | qApp->processEvents(); | 1708 | qApp->processEvents(); |
1708 | CalendarLocal* calendar = new CalendarLocal(); | 1709 | CalendarLocal* calendar = new CalendarLocal(); |
1709 | calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); | 1710 | calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); |
1710 | bool syncOK = false; | 1711 | bool syncOK = false; |
1711 | bool loadSuccess = false; | 1712 | bool loadSuccess = false; |
1712 | PhoneFormat* phoneFormat = 0; | 1713 | PhoneFormat* phoneFormat = 0; |
1713 | emit tempDisableBR(true); | 1714 | emit tempDisableBR(true); |
1714 | #ifndef DESKTOP_VERSION | 1715 | #ifndef DESKTOP_VERSION |
1715 | SharpFormat* sharpFormat = 0; | 1716 | SharpFormat* sharpFormat = 0; |
1716 | if ( mode == 0 ) { // sharp | 1717 | if ( mode == 0 ) { // sharp |
1717 | sharpFormat = new SharpFormat () ; | 1718 | sharpFormat = new SharpFormat () ; |
1718 | loadSuccess = sharpFormat->load( calendar, mCalendar ); | 1719 | loadSuccess = sharpFormat->load( calendar, mCalendar ); |
1719 | 1720 | ||
1720 | } else | 1721 | } else |
1721 | #endif | 1722 | #endif |
1722 | if ( mode == 1 ) { // phone | 1723 | if ( mode == 1 ) { // phone |
1723 | phoneFormat = new PhoneFormat (mCurrentSyncDevice, | 1724 | phoneFormat = new PhoneFormat (mCurrentSyncDevice, |
1724 | mSyncManager->mPhoneDevice, | 1725 | mSyncManager->mPhoneDevice, |
1725 | mSyncManager->mPhoneConnection, | 1726 | mSyncManager->mPhoneConnection, |
1726 | mSyncManager->mPhoneModel); | 1727 | mSyncManager->mPhoneModel); |
1727 | loadSuccess = phoneFormat->load( calendar,mCalendar); | 1728 | loadSuccess = phoneFormat->load( calendar,mCalendar); |
1728 | 1729 | ||
1729 | } else { | 1730 | } else { |
1730 | emit tempDisableBR(false); | 1731 | emit tempDisableBR(false); |
1731 | return; | 1732 | return; |
1732 | } | 1733 | } |
1733 | if ( loadSuccess ) { | 1734 | if ( loadSuccess ) { |
1734 | getEventViewerDialog()->setSyncMode( true ); | 1735 | getEventViewerDialog()->setSyncMode( true ); |
1735 | syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); | 1736 | syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); |
1736 | getEventViewerDialog()->setSyncMode( false ); | 1737 | getEventViewerDialog()->setSyncMode( false ); |
1737 | qApp->processEvents(); | 1738 | qApp->processEvents(); |
1738 | if ( syncOK ) { | 1739 | if ( syncOK ) { |
1739 | if ( mSyncManager->mWriteBackFile ) | 1740 | if ( mSyncManager->mWriteBackFile ) |
1740 | { | 1741 | { |
1741 | QPtrList<Incidence> iL = mCalendar->rawIncidences(); | 1742 | QPtrList<Incidence> iL = mCalendar->rawIncidences(); |
1742 | Incidence* inc = iL.first(); | 1743 | Incidence* inc = iL.first(); |
1743 | if ( phoneFormat ) { | 1744 | if ( phoneFormat ) { |
1744 | while ( inc ) { | 1745 | while ( inc ) { |
1745 | inc->removeID(mCurrentSyncDevice); | 1746 | inc->removeID(mCurrentSyncDevice); |
1746 | inc = iL.next(); | 1747 | inc = iL.next(); |
1747 | } | 1748 | } |
1748 | } | 1749 | } |
1749 | #ifndef DESKTOP_VERSION | 1750 | #ifndef DESKTOP_VERSION |
1750 | if ( sharpFormat ) | 1751 | if ( sharpFormat ) |
1751 | sharpFormat->save(calendar); | 1752 | sharpFormat->save(calendar); |
1752 | #endif | 1753 | #endif |
1753 | if ( phoneFormat ) | 1754 | if ( phoneFormat ) |
1754 | phoneFormat->save(calendar); | 1755 | phoneFormat->save(calendar); |
1755 | iL = calendar->rawIncidences(); | 1756 | iL = calendar->rawIncidences(); |
1756 | inc = iL.first(); | 1757 | inc = iL.first(); |
1757 | Incidence* loc; | 1758 | Incidence* loc; |
1758 | while ( inc ) { | 1759 | while ( inc ) { |
1759 | if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { | 1760 | if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { |
1760 | loc = mCalendar->incidence(inc->uid() ); | 1761 | loc = mCalendar->incidence(inc->uid() ); |
1761 | if ( loc ) { | 1762 | if ( loc ) { |
1762 | loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); | 1763 | loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); |
1763 | loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); | 1764 | loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); |
1764 | } | 1765 | } |
1765 | } | 1766 | } |
1766 | inc = iL.next(); | 1767 | inc = iL.next(); |
1767 | } | 1768 | } |
1768 | Incidence* lse = getLastSyncEvent(); | 1769 | Incidence* lse = getLastSyncEvent(); |
1769 | if ( lse ) { | 1770 | if ( lse ) { |
1770 | lse->setReadOnly( false ); | 1771 | lse->setReadOnly( false ); |
1771 | lse->setDescription( "" ); | 1772 | lse->setDescription( "" ); |
1772 | lse->setReadOnly( true ); | 1773 | lse->setReadOnly( true ); |
1773 | } | 1774 | } |
1774 | } | 1775 | } |
1775 | } else { | 1776 | } else { |
1776 | topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); | 1777 | topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); |
1777 | } | 1778 | } |
1778 | setModified( true ); | 1779 | setModified( true ); |
1779 | } else { | 1780 | } else { |
1780 | QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; | 1781 | QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; |
1781 | QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), | 1782 | QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), |
1782 | question, i18n("Ok")) ; | 1783 | question, i18n("Ok")) ; |
1783 | 1784 | ||
1784 | } | 1785 | } |
1785 | delete calendar; | 1786 | delete calendar; |
1786 | updateView(); | 1787 | updateView(); |
1787 | emit tempDisableBR(false); | 1788 | emit tempDisableBR(false); |
1788 | return ;//syncOK; | 1789 | return ;//syncOK; |
1789 | 1790 | ||
1790 | } | 1791 | } |
1791 | 1792 | ||
1792 | bool CalendarView::importBday() | 1793 | bool CalendarView::importBday() |
1793 | { | 1794 | { |
1794 | #ifndef KORG_NOKABC | 1795 | #ifndef KORG_NOKABC |
1795 | 1796 | ||
1796 | #ifdef DESKTOP_VERSION | 1797 | #ifdef DESKTOP_VERSION |
1797 | int curCal = mCalendar->defaultCalendar(); | 1798 | int curCal = mCalendar->defaultCalendar(); |
1798 | int bd = mCalEditView->getBirtdayID(); | 1799 | int bd = mCalEditView->getBirtdayID(); |
1799 | if ( bd == 0 ) | 1800 | if ( bd == 0 ) |
1800 | return false; | 1801 | return false; |
1801 | mCalendar->setDefaultCalendar( bd ); | 1802 | mCalendar->setDefaultCalendar( bd ); |
1802 | KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); | 1803 | KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); |
1803 | KABC::AddressBook::Iterator it; | 1804 | KABC::AddressBook::Iterator it; |
1804 | int count = 0; | 1805 | int count = 0; |
1805 | for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { | 1806 | for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { |
1806 | ++count; | 1807 | ++count; |
1807 | } | 1808 | } |
1808 | QProgressBar bar(count,0 ); | 1809 | QProgressBar bar(count,0 ); |
1809 | int w = 300; | 1810 | int w = 300; |
1810 | if ( QApplication::desktop()->width() < 320 ) | 1811 | if ( QApplication::desktop()->width() < 320 ) |
1811 | w = 220; | 1812 | w = 220; |
1812 | int h = bar.sizeHint().height() ; | 1813 | int h = bar.sizeHint().height() ; |
1813 | int dw = QApplication::desktop()->width(); | 1814 | int dw = QApplication::desktop()->width(); |
1814 | int dh = QApplication::desktop()->height(); | 1815 | int dh = QApplication::desktop()->height(); |
1815 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 1816 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
1816 | bar.show(); | 1817 | bar.show(); |
1817 | bar.setCaption (i18n("Reading addressbook - close to abort!") ); | 1818 | bar.setCaption (i18n("Reading addressbook - close to abort!") ); |
1818 | qApp->processEvents(); | 1819 | qApp->processEvents(); |
1819 | count = 0; | 1820 | count = 0; |
1820 | int addCount = 0; | 1821 | int addCount = 0; |
1821 | KCal::Attendee* a = 0; | 1822 | KCal::Attendee* a = 0; |
1822 | for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { | 1823 | for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { |
1823 | if ( ! bar.isVisible() ) | 1824 | if ( ! bar.isVisible() ) |
1824 | return false; | 1825 | return false; |
1825 | bar.setProgress( count++ ); | 1826 | bar.setProgress( count++ ); |
1826 | qApp->processEvents(); | 1827 | qApp->processEvents(); |
1827 | //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); | 1828 | //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); |
1828 | if ( (*it).birthday().date().isValid() ){ | 1829 | if ( (*it).birthday().date().isValid() ){ |
1829 | a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; | 1830 | a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; |
1830 | if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) | 1831 | if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) |
1831 | ++addCount; | 1832 | ++addCount; |
1832 | } | 1833 | } |
1833 | QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); | 1834 | QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); |
1834 | if ( anni.isValid() ){ | 1835 | if ( anni.isValid() ){ |
1835 | a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; | 1836 | a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; |
1836 | if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) | 1837 | if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) |
1837 | ++addCount; | 1838 | ++addCount; |
1838 | } | 1839 | } |
1839 | } | 1840 | } |
1840 | mCalendar->setDefaultCalendar( curCal ); | 1841 | mCalendar->setDefaultCalendar( curCal ); |
1841 | updateView(); | 1842 | updateView(); |
1842 | topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); | 1843 | topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); |
1843 | #else //DESKTOP_VERSION | 1844 | #else //DESKTOP_VERSION |
1844 | 1845 | ||
1845 | ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); | 1846 | ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); |
1846 | // the result should now arrive through method insertBirthdays | 1847 | // the result should now arrive through method insertBirthdays |
1847 | 1848 | ||
1848 | #endif //DESKTOP_VERSION | 1849 | #endif //DESKTOP_VERSION |
1849 | 1850 | ||
1850 | #endif //KORG_NOKABC | 1851 | #endif //KORG_NOKABC |
1851 | 1852 | ||
1852 | 1853 | ||
1853 | return true; | 1854 | return true; |
1854 | } | 1855 | } |
1855 | 1856 | ||
1856 | // This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI | 1857 | // This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI |
1857 | void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, | 1858 | void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, |
1858 | const QStringList& anniversaryList, const QStringList& realNameList, | 1859 | const QStringList& anniversaryList, const QStringList& realNameList, |
1859 | const QStringList& emailList, const QStringList& assembledNameList, | 1860 | const QStringList& emailList, const QStringList& assembledNameList, |
1860 | const QStringList& uidList) | 1861 | const QStringList& uidList) |
1861 | { | 1862 | { |
1862 | 1863 | ||
1863 | //qDebug("KO::CalendarView::insertBirthdays"); | 1864 | //qDebug("KO::CalendarView::insertBirthdays"); |
1864 | if (uid == this->name()) | 1865 | if (uid == this->name()) |
1865 | { | 1866 | { |
1866 | int curCal = mCalendar->defaultCalendar(); | 1867 | int curCal = mCalendar->defaultCalendar(); |
1867 | int bd = mCalEditView->getBirtdayID(); | 1868 | int bd = mCalEditView->getBirtdayID(); |
1868 | if ( bd == 0 ) | 1869 | if ( bd == 0 ) |
1869 | return; | 1870 | return; |
1870 | mCalendar->setDefaultCalendar( bd ); | 1871 | mCalendar->setDefaultCalendar( bd ); |
1871 | 1872 | ||
1872 | 1873 | ||
1873 | int count = birthdayList.count(); | 1874 | int count = birthdayList.count(); |
1874 | int addCount = 0; | 1875 | int addCount = 0; |
1875 | KCal::Attendee* a = 0; | 1876 | KCal::Attendee* a = 0; |
1876 | 1877 | ||
1877 | //qDebug("CalView 1 %i", count); | 1878 | //qDebug("CalView 1 %i", count); |
1878 | 1879 | ||
1879 | QProgressBar bar(count,0 ); | 1880 | QProgressBar bar(count,0 ); |
1880 | int w = 300; | 1881 | int w = 300; |
1881 | if ( QApplication::desktop()->width() < 320 ) | 1882 | if ( QApplication::desktop()->width() < 320 ) |
1882 | w = 220; | 1883 | w = 220; |
1883 | int h = bar.sizeHint().height() ; | 1884 | int h = bar.sizeHint().height() ; |
1884 | int dw = QApplication::desktop()->width(); | 1885 | int dw = QApplication::desktop()->width(); |
1885 | int dh = QApplication::desktop()->height(); | 1886 | int dh = QApplication::desktop()->height(); |
1886 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 1887 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
1887 | bar.show(); | 1888 | bar.show(); |
1888 | bar.setCaption (i18n("inserting birthdays - close to abort!") ); | 1889 | bar.setCaption (i18n("inserting birthdays - close to abort!") ); |
1889 | qApp->processEvents(); | 1890 | qApp->processEvents(); |
1890 | 1891 | ||
1891 | QDate birthday; | 1892 | QDate birthday; |
1892 | QDate anniversary; | 1893 | QDate anniversary; |
1893 | QString realName; | 1894 | QString realName; |
1894 | QString email; | 1895 | QString email; |
1895 | QString assembledName; | 1896 | QString assembledName; |
1896 | QString uid; | 1897 | QString uid; |
1897 | bool ok = true; | 1898 | bool ok = true; |
1898 | for ( int i = 0; i < count; i++) | 1899 | for ( int i = 0; i < count; i++) |
1899 | { | 1900 | { |
1900 | if ( ! bar.isVisible() ) | 1901 | if ( ! bar.isVisible() ) |
1901 | return; | 1902 | return; |
1902 | bar.setProgress( i ); | 1903 | bar.setProgress( i ); |
1903 | qApp->processEvents(); | 1904 | qApp->processEvents(); |
1904 | 1905 | ||
1905 | birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); | 1906 | birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); |
1906 | if (!ok) { | 1907 | if (!ok) { |
1907 | ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); | 1908 | ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); |
1908 | } | 1909 | } |
1909 | 1910 | ||
1910 | anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); | 1911 | anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); |
1911 | if (!ok) { | 1912 | if (!ok) { |
1912 | ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); | 1913 | ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); |
1913 | } | 1914 | } |
1914 | realName = realNameList[i]; | 1915 | realName = realNameList[i]; |
1915 | email = emailList[i]; | 1916 | email = emailList[i]; |
1916 | assembledName = assembledNameList[i]; | 1917 | assembledName = assembledNameList[i]; |
1917 | uid = uidList[i]; | 1918 | uid = uidList[i]; |
1918 | //qDebug("insert birthday in KO/Pi: %s,%s,%s,%s: %s, %s", realName.latin1(), email.latin1(), assembledName.latin1(), uid.latin1(), birthdayList[i].latin1(), anniversaryList[i].latin1() ); | 1919 | //qDebug("insert birthday in KO/Pi: %s,%s,%s,%s: %s, %s", realName.latin1(), email.latin1(), assembledName.latin1(), uid.latin1(), birthdayList[i].latin1(), anniversaryList[i].latin1() ); |
1919 | 1920 | ||
1920 | if ( birthday.isValid() ){ | 1921 | if ( birthday.isValid() ){ |
1921 | a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, | 1922 | a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, |
1922 | KCal::Attendee::ReqParticipant,uid) ; | 1923 | KCal::Attendee::ReqParticipant,uid) ; |
1923 | if ( addAnniversary( birthday, assembledName, a, true ) ) | 1924 | if ( addAnniversary( birthday, assembledName, a, true ) ) |
1924 | ++addCount; | 1925 | ++addCount; |
1925 | } | 1926 | } |
1926 | 1927 | ||
1927 | if ( anniversary.isValid() ){ | 1928 | if ( anniversary.isValid() ){ |
1928 | a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, | 1929 | a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, |
1929 | KCal::Attendee::ReqParticipant,uid) ; | 1930 | KCal::Attendee::ReqParticipant,uid) ; |
1930 | if ( addAnniversary( anniversary, assembledName, a, false ) ) | 1931 | if ( addAnniversary( anniversary, assembledName, a, false ) ) |
1931 | ++addCount; | 1932 | ++addCount; |
1932 | } | 1933 | } |
1933 | } | 1934 | } |
1934 | 1935 | ||
1935 | mCalendar->setDefaultCalendar( curCal ); | 1936 | mCalendar->setDefaultCalendar( curCal ); |
1936 | updateView(); | 1937 | updateView(); |
1937 | topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); | 1938 | topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); |
1938 | 1939 | ||
1939 | } | 1940 | } |
1940 | 1941 | ||
1941 | } | 1942 | } |
1942 | 1943 | ||
1943 | 1944 | ||
1944 | 1945 | ||
1945 | bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) | 1946 | bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) |
1946 | { | 1947 | { |
1947 | //qDebug("addAnni "); | 1948 | //qDebug("addAnni "); |
1948 | Event * ev = new Event(); | 1949 | Event * ev = new Event(); |
1949 | ev->setOrganizer(KOPrefs::instance()->email()); | 1950 | ev->setOrganizer(KOPrefs::instance()->email()); |
1950 | if ( a ) { | 1951 | if ( a ) { |
1951 | ev->addAttendee( a ); | 1952 | ev->addAttendee( a ); |
1952 | } | 1953 | } |
1953 | QString kind; | 1954 | QString kind; |
1954 | if ( birthday ) { | 1955 | if ( birthday ) { |
1955 | kind = i18n( "Birthday" ); | 1956 | kind = i18n( "Birthday" ); |
1956 | ev->setSummary( name + " (" + QString::number(date.year()) +")"); | 1957 | ev->setSummary( name + " (" + QString::number(date.year()) +")"); |
1957 | } | 1958 | } |
1958 | else { | 1959 | else { |
1959 | kind = i18n( "Anniversary" ); | 1960 | kind = i18n( "Anniversary" ); |
1960 | ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind ); | 1961 | ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind ); |
1961 | } | 1962 | } |
1962 | ev->setCategories( kind ); | 1963 | ev->setCategories( kind ); |
1963 | ev->setDtStart( QDateTime(date) ); | 1964 | ev->setDtStart( QDateTime(date) ); |
1964 | ev->setDtEnd( QDateTime(date) ); | 1965 | ev->setDtEnd( QDateTime(date) ); |
1965 | ev->setFloats( true ); | 1966 | ev->setFloats( true ); |
1966 | Recurrence * rec = ev->recurrence(); | 1967 | Recurrence * rec = ev->recurrence(); |
1967 | rec->setYearly(Recurrence::rYearlyMonth,1,-1); | 1968 | rec->setYearly(Recurrence::rYearlyMonth,1,-1); |
1968 | rec->addYearlyNum( date.month() ); | 1969 | rec->addYearlyNum( date.month() ); |
1969 | if ( !mCalendar->addAnniversaryNoDup( ev ) ) { | 1970 | if ( !mCalendar->addAnniversaryNoDup( ev ) ) { |
1970 | delete ev; | 1971 | delete ev; |
1971 | return false; | 1972 | return false; |
1972 | } | 1973 | } |
1973 | return true; | 1974 | return true; |
1974 | 1975 | ||
1975 | } | 1976 | } |
1976 | bool CalendarView::importQtopia( const QString &categories, | 1977 | bool CalendarView::importQtopia( const QString &categories, |
1977 | const QString &datebook, | 1978 | const QString &datebook, |
1978 | const QString &todolist ) | 1979 | const QString &todolist ) |
1979 | { | 1980 | { |
1980 | 1981 | ||
1981 | QtopiaFormat qtopiaFormat; | 1982 | QtopiaFormat qtopiaFormat; |
1982 | qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); | 1983 | qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); |
1983 | if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); | 1984 | if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); |
1984 | if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); | 1985 | if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); |
1985 | if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); | 1986 | if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); |
1986 | 1987 | ||
1987 | updateView(); | 1988 | updateView(); |
1988 | return true; | 1989 | return true; |
1989 | 1990 | ||
1990 | #if 0 | 1991 | #if 0 |
1991 | mGlobalSyncMode = SYNC_MODE_QTOPIA; | 1992 | mGlobalSyncMode = SYNC_MODE_QTOPIA; |
1992 | mCurrentSyncDevice = "qtopia-XML"; | 1993 | mCurrentSyncDevice = "qtopia-XML"; |
1993 | if ( mSyncManager->mAskForPreferences ) | 1994 | if ( mSyncManager->mAskForPreferences ) |
1994 | edit_sync_options(); | 1995 | edit_sync_options(); |
1995 | qApp->processEvents(); | 1996 | qApp->processEvents(); |
1996 | CalendarLocal* calendar = new CalendarLocal(); | 1997 | CalendarLocal* calendar = new CalendarLocal(); |
1997 | calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); | 1998 | calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); |
1998 | bool syncOK = false; | 1999 | bool syncOK = false; |
1999 | QtopiaFormat qtopiaFormat; | 2000 | QtopiaFormat qtopiaFormat; |
2000 | qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); | 2001 | qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); |
2001 | bool loadOk = true; | 2002 | bool loadOk = true; |
2002 | if ( !categories.isEmpty() ) | 2003 | if ( !categories.isEmpty() ) |
2003 | loadOk = qtopiaFormat.load( calendar, categories ); | 2004 | loadOk = qtopiaFormat.load( calendar, categories ); |
2004 | if ( loadOk && !datebook.isEmpty() ) | 2005 | if ( loadOk && !datebook.isEmpty() ) |
2005 | loadOk = qtopiaFormat.load( calendar, datebook ); | 2006 | loadOk = qtopiaFormat.load( calendar, datebook ); |
2006 | if ( loadOk && !todolist.isEmpty() ) | 2007 | if ( loadOk && !todolist.isEmpty() ) |
2007 | loadOk = qtopiaFormat.load( calendar, todolist ); | 2008 | loadOk = qtopiaFormat.load( calendar, todolist ); |
2008 | 2009 | ||
2009 | if ( loadOk ) { | 2010 | if ( loadOk ) { |
2010 | getEventViewerDialog()->setSyncMode( true ); | 2011 | getEventViewerDialog()->setSyncMode( true ); |
2011 | syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); | 2012 | syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); |
2012 | getEventViewerDialog()->setSyncMode( false ); | 2013 | getEventViewerDialog()->setSyncMode( false ); |
2013 | qApp->processEvents(); | 2014 | qApp->processEvents(); |
2014 | if ( syncOK ) { | 2015 | if ( syncOK ) { |
2015 | if ( mSyncManager->mWriteBackFile ) | 2016 | if ( mSyncManager->mWriteBackFile ) |
2016 | { | 2017 | { |
2017 | // write back XML file | 2018 | // write back XML file |
2018 | 2019 | ||
2019 | } | 2020 | } |
2020 | setModified( true ); | 2021 | setModified( true ); |
2021 | } | 2022 | } |
2022 | } else { | 2023 | } else { |
2023 | QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; | 2024 | QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; |
2024 | QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), | 2025 | QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), |
2025 | question, i18n("Ok")) ; | 2026 | question, i18n("Ok")) ; |
2026 | } | 2027 | } |
2027 | delete calendar; | 2028 | delete calendar; |
2028 | updateView(); | 2029 | updateView(); |
2029 | return syncOK; | 2030 | return syncOK; |
2030 | 2031 | ||
2031 | 2032 | ||
2032 | #endif | 2033 | #endif |
2033 | 2034 | ||
2034 | } | 2035 | } |
2035 | 2036 | ||
2036 | void CalendarView::setSyncEventsReadOnly() | 2037 | void CalendarView::setSyncEventsReadOnly() |
2037 | { | 2038 | { |
2038 | mCalendar->setSyncEventsReadOnly(); | 2039 | mCalendar->setSyncEventsReadOnly(); |
2039 | } | 2040 | } |
2040 | 2041 | ||
2041 | bool CalendarView::loadCalendars() | 2042 | bool CalendarView::loadCalendars() |
2042 | { | 2043 | { |
2043 | QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; | 2044 | QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; |
2044 | KopiCalendarFile * cal = calendars.first(); | 2045 | KopiCalendarFile * cal = calendars.first(); |
2045 | mCalendar->setDefaultCalendar( 1 ); | 2046 | mCalendar->setDefaultCalendar( 1 ); |
2046 | openCalendar( MainWindow::defaultFileName(), false ); | 2047 | openCalendar( MainWindow::defaultFileName(), false ); |
2047 | cal = calendars.next(); | 2048 | cal = calendars.next(); |
2048 | while ( cal ) { | 2049 | while ( cal ) { |
2049 | addCalendar( cal ); | 2050 | addCalendar( cal ); |
2050 | cal = calendars.next(); | 2051 | cal = calendars.next(); |
2051 | } | 2052 | } |
2052 | restoreCalendarSettings(); | 2053 | restoreCalendarSettings(); |
2053 | return true; | 2054 | return true; |
2054 | } | 2055 | } |
2055 | bool CalendarView::restoreCalendarSettings() | 2056 | bool CalendarView::restoreCalendarSettings() |
2056 | { | 2057 | { |
2057 | QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; | 2058 | QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; |
2058 | KopiCalendarFile * cal = calendars.first(); | 2059 | KopiCalendarFile * cal = calendars.first(); |
2059 | while ( cal ) { | 2060 | while ( cal ) { |
2060 | mCalendar->setCalendarEnabled( cal->mCalNumber,cal->isEnabled ); | 2061 | mCalendar->setCalendarEnabled( cal->mCalNumber,cal->isEnabled ); |
2061 | mCalendar->setAlarmEnabled( cal->mCalNumber, cal->isAlarmEnabled ); | 2062 | mCalendar->setAlarmEnabled( cal->mCalNumber, cal->isAlarmEnabled ); |
2062 | mCalendar->setReadOnly( cal->mCalNumber, cal->isReadOnly ); | 2063 | mCalendar->setReadOnly( cal->mCalNumber, cal->isReadOnly ); |
2063 | if ( cal->isStandard ) | 2064 | if ( cal->isStandard ) |
2064 | mCalendar->setDefaultCalendar( cal->mCalNumber ); | 2065 | mCalendar->setDefaultCalendar( cal->mCalNumber ); |
2065 | cal = calendars.next(); | 2066 | cal = calendars.next(); |
2066 | } | 2067 | } |
2067 | setSyncEventsReadOnly(); | 2068 | setSyncEventsReadOnly(); |
2068 | mCalendar->reInitAlarmSettings(); | 2069 | mCalendar->reInitAlarmSettings(); |
2069 | updateUnmanagedViews(); | 2070 | updateUnmanagedViews(); |
2070 | updateView(); | 2071 | updateView(); |
2071 | return true; | 2072 | return true; |
2072 | } | 2073 | } |
2073 | void CalendarView::addCalendarId( int id ) | 2074 | void CalendarView::addCalendarId( int id ) |
2074 | { | 2075 | { |
2075 | KopiCalendarFile * cal = KOPrefs::instance()->getCalendar( id ); | 2076 | KopiCalendarFile * cal = KOPrefs::instance()->getCalendar( id ); |
2076 | if ( cal ) | 2077 | if ( cal ) |
2077 | addCalendar( cal ); | 2078 | addCalendar( cal ); |
2078 | } | 2079 | } |
2079 | bool CalendarView::addCalendar( KopiCalendarFile * cal ) | 2080 | bool CalendarView::addCalendar( KopiCalendarFile * cal ) |
2080 | { | 2081 | { |
2081 | cal->mErrorOnLoad = false; | 2082 | cal->mErrorOnLoad = false; |
2082 | if ( mCalendar->addCalendarFile( cal->mFileName, cal->mCalNumber )) { | 2083 | if ( mCalendar->addCalendarFile( cal->mFileName, cal->mCalNumber )) { |
2083 | cal->mLoadDt = QDateTime::currentDateTime(); | 2084 | cal->mLoadDt = QDateTime::currentDateTime(); |
2084 | return true; | 2085 | return true; |
2085 | } | 2086 | } |
2086 | qDebug("KO: Error adding calendar file %s ",cal->mFileName.latin1() ); | 2087 | qDebug("KO: Error adding calendar file %s ",cal->mFileName.latin1() ); |
2087 | cal->mErrorOnLoad = true; | 2088 | cal->mErrorOnLoad = true; |
2088 | return false; | 2089 | return false; |
2089 | } | 2090 | } |
2090 | bool CalendarView::openCalendar(QString filename, bool merge) | 2091 | bool CalendarView::openCalendar(QString filename, bool merge) |
2091 | { | 2092 | { |
2092 | 2093 | ||
2093 | if (filename.isEmpty()) { | 2094 | if (filename.isEmpty()) { |
2094 | return false; | 2095 | return false; |
2095 | } | 2096 | } |
2096 | 2097 | ||
2097 | if (!QFile::exists(filename)) { | 2098 | if (!QFile::exists(filename)) { |
2098 | KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); | 2099 | KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); |
2099 | return false; | 2100 | return false; |
2100 | } | 2101 | } |
2101 | 2102 | ||
2102 | globalFlagBlockAgenda = 1; | 2103 | globalFlagBlockAgenda = 1; |
2103 | clearAllViews(); | 2104 | clearAllViews(); |
2104 | if (!merge) { | 2105 | if (!merge) { |
2105 | mViewManager->setDocumentId( filename ); | 2106 | mViewManager->setDocumentId( filename ); |
2106 | mCalendar->close(); | 2107 | mCalendar->close(); |
2107 | } | 2108 | } |
2108 | mStorage->setFileName( filename ); | 2109 | mStorage->setFileName( filename ); |
2109 | 2110 | ||
2110 | if ( mStorage->load() ) { | 2111 | if ( mStorage->load() ) { |
2111 | if ( merge ) ;//setModified( true ); | 2112 | if ( merge ) ;//setModified( true ); |
2112 | else { | 2113 | else { |
2113 | //setModified( true ); | 2114 | //setModified( true ); |
2114 | mViewManager->setDocumentId( filename ); | 2115 | mViewManager->setDocumentId( filename ); |
2115 | mDialogManager->setDocumentId( filename ); | 2116 | mDialogManager->setDocumentId( filename ); |
2116 | mTodoList->setDocumentId( filename ); | 2117 | mTodoList->setDocumentId( filename ); |
2117 | } | 2118 | } |
2118 | globalFlagBlockAgenda = 2; | 2119 | globalFlagBlockAgenda = 2; |
2119 | // if ( getLastSyncEvent() ) | 2120 | // if ( getLastSyncEvent() ) |
2120 | // getLastSyncEvent()->setReadOnly( true ); | 2121 | // getLastSyncEvent()->setReadOnly( true ); |
2121 | mCalendar->reInitAlarmSettings(); | 2122 | mCalendar->reInitAlarmSettings(); |
2122 | setSyncEventsReadOnly(); | 2123 | setSyncEventsReadOnly(); |
2123 | updateUnmanagedViews(); | 2124 | updateUnmanagedViews(); |
2124 | updateView(); | 2125 | updateView(); |
2125 | if ( filename != MainWindow::defaultFileName() ) { | 2126 | if ( filename != MainWindow::defaultFileName() ) { |
2126 | saveCalendar( MainWindow::defaultFileName() ); | 2127 | saveCalendar( MainWindow::defaultFileName() ); |
2127 | } else { | 2128 | } else { |
2128 | QFileInfo finf ( MainWindow::defaultFileName()); | 2129 | QFileInfo finf ( MainWindow::defaultFileName()); |
2129 | if ( finf.exists() ) { | 2130 | if ( finf.exists() ) { |
2130 | setLoadedFileVersion( finf.lastModified () ); | 2131 | setLoadedFileVersion( finf.lastModified () ); |
2131 | } | 2132 | } |
2132 | } | 2133 | } |
2133 | return true; | 2134 | return true; |
2134 | } else { | 2135 | } else { |
2135 | // while failing to load, the calendar object could | 2136 | // while failing to load, the calendar object could |
2136 | // have become partially populated. Clear it out. | 2137 | // have become partially populated. Clear it out. |
2137 | if ( !merge ) { | 2138 | if ( !merge ) { |
2138 | mCalendar->close(); | 2139 | mCalendar->close(); |
2139 | mViewManager->setDocumentId( filename ); | 2140 | mViewManager->setDocumentId( filename ); |
2140 | mDialogManager->setDocumentId( filename ); | 2141 | mDialogManager->setDocumentId( filename ); |
2141 | mTodoList->setDocumentId( filename ); | 2142 | mTodoList->setDocumentId( filename ); |
2142 | } | 2143 | } |
2143 | 2144 | ||
2144 | //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); | 2145 | //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); |
2145 | 2146 | ||
2146 | QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); | 2147 | QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); |
2147 | globalFlagBlockAgenda = 2; | 2148 | globalFlagBlockAgenda = 2; |
2148 | mCalendar->reInitAlarmSettings(); | 2149 | mCalendar->reInitAlarmSettings(); |
2149 | setSyncEventsReadOnly(); | 2150 | setSyncEventsReadOnly(); |
2150 | updateUnmanagedViews(); | 2151 | updateUnmanagedViews(); |
2151 | updateView(); | 2152 | updateView(); |
2152 | } | 2153 | } |
diff --git a/libkcal/calendar.h b/libkcal/calendar.h index 14a1a45..95477cd 100644 --- a/libkcal/calendar.h +++ b/libkcal/calendar.h | |||
@@ -1,378 +1,379 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 1998 Preston Brown | 3 | Copyright (c) 1998 Preston Brown |
4 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. |
10 | 10 | ||
11 | This library is distributed in the hope that it will be useful, | 11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. | 14 | Library General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU Library General Public License | 16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to | 17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. | 19 | Boston, MA 02111-1307, USA. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #ifndef CALENDAR_H | 22 | #ifndef CALENDAR_H |
23 | #define CALENDAR_H | 23 | #define CALENDAR_H |
24 | 24 | ||
25 | #include <qobject.h> | 25 | #include <qobject.h> |
26 | #include <qstring.h> | 26 | #include <qstring.h> |
27 | #include <qdatetime.h> | 27 | #include <qdatetime.h> |
28 | #include <qptrlist.h> | 28 | #include <qptrlist.h> |
29 | #include <qdict.h> | 29 | #include <qdict.h> |
30 | 30 | ||
31 | #include "customproperties.h" | 31 | #include "customproperties.h" |
32 | #include "event.h" | 32 | #include "event.h" |
33 | #include "todo.h" | 33 | #include "todo.h" |
34 | #include "journal.h" | 34 | #include "journal.h" |
35 | #include "calfilter.h" | 35 | #include "calfilter.h" |
36 | 36 | ||
37 | //#define _TIME_ZONE "-0500" /* hardcoded, overridden in config file. */ | 37 | //#define _TIME_ZONE "-0500" /* hardcoded, overridden in config file. */ |
38 | 38 | ||
39 | class KConfig; | 39 | class KConfig; |
40 | 40 | ||
41 | namespace KCal { | 41 | namespace KCal { |
42 | 42 | ||
43 | 43 | ||
44 | /** | 44 | /** |
45 | This is the main "calendar" object class for KOrganizer. It holds | 45 | This is the main "calendar" object class for KOrganizer. It holds |
46 | information like all appointments/events, user information, etc. etc. | 46 | information like all appointments/events, user information, etc. etc. |
47 | one calendar is associated with each CalendarView (@see calendarview.h). | 47 | one calendar is associated with each CalendarView (@see calendarview.h). |
48 | This is an abstract base class defining the interface to a calendar. It is | 48 | This is an abstract base class defining the interface to a calendar. It is |
49 | implemented by subclasses like @see CalendarLocal, which use different | 49 | implemented by subclasses like @see CalendarLocal, which use different |
50 | methods to store and access the data. | 50 | methods to store and access the data. |
51 | 51 | ||
52 | Ownership of events etc. is handled by the following policy: As soon as an | 52 | Ownership of events etc. is handled by the following policy: As soon as an |
53 | event (or any other subclass of IncidenceBase) object is added to the | 53 | event (or any other subclass of IncidenceBase) object is added to the |
54 | Calendar by addEvent() it is owned by the Calendar object. The Calendar takes | 54 | Calendar by addEvent() it is owned by the Calendar object. The Calendar takes |
55 | care of deleting it. All Events returned by the query functions are returned | 55 | care of deleting it. All Events returned by the query functions are returned |
56 | as pointers, that means all changes to the returned events are immediately | 56 | as pointers, that means all changes to the returned events are immediately |
57 | visible in the Calendar. You shouldn't delete any Event object you get from | 57 | visible in the Calendar. You shouldn't delete any Event object you get from |
58 | Calendar. | 58 | Calendar. |
59 | */ | 59 | */ |
60 | class Calendar : public QObject, public CustomProperties, | 60 | class Calendar : public QObject, public CustomProperties, |
61 | public IncidenceBase::Observer | 61 | public IncidenceBase::Observer |
62 | { | 62 | { |
63 | Q_OBJECT | 63 | Q_OBJECT |
64 | public: | 64 | public: |
65 | Calendar(); | 65 | Calendar(); |
66 | Calendar(const QString &timeZoneId); | 66 | Calendar(const QString &timeZoneId); |
67 | virtual ~Calendar(); | 67 | virtual ~Calendar(); |
68 | Incidence * undoIncidence() { return mUndoIncidence; }; | 68 | Incidence * undoIncidence() { return mUndoIncidence; }; |
69 | bool undoDeleteIncidence(); | 69 | bool undoDeleteIncidence(); |
70 | void deleteIncidence(Incidence *in); | 70 | void deleteIncidence(Incidence *in); |
71 | void resetTempSyncStat(); | 71 | void resetTempSyncStat(); |
72 | void resetPilotStat(int id); | 72 | void resetPilotStat(int id); |
73 | /** | 73 | /** |
74 | Clears out the current calendar, freeing all used memory etc. | 74 | Clears out the current calendar, freeing all used memory etc. |
75 | */ | 75 | */ |
76 | virtual void close() = 0; | 76 | virtual void close() = 0; |
77 | virtual void addCalendar( Calendar* ) = 0; | 77 | virtual void addCalendar( Calendar* ) = 0; |
78 | virtual bool addCalendarFile( QString name, int id ) = 0; | 78 | virtual bool addCalendarFile( QString name, int id ) = 0; |
79 | virtual bool mergeCalendarFile( QString name ) = 0; | 79 | virtual bool mergeCalendarFile( QString name ) = 0; |
80 | virtual Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates ) = 0; | ||
80 | virtual void setSyncEventsReadOnly() = 0; | 81 | virtual void setSyncEventsReadOnly() = 0; |
81 | virtual void stopAllTodos() = 0; | 82 | virtual void stopAllTodos() = 0; |
82 | 83 | ||
83 | /** | 84 | /** |
84 | Sync changes in memory to persistant storage. | 85 | Sync changes in memory to persistant storage. |
85 | */ | 86 | */ |
86 | virtual void save() = 0; | 87 | virtual void save() = 0; |
87 | virtual QPtrList<Event> getExternLastSyncEvents() = 0; | 88 | virtual QPtrList<Event> getExternLastSyncEvents() = 0; |
88 | virtual void removeSyncInfo( QString syncProfile) = 0; | 89 | virtual void removeSyncInfo( QString syncProfile) = 0; |
89 | virtual bool isSaving() { return false; } | 90 | virtual bool isSaving() { return false; } |
90 | 91 | ||
91 | /** | 92 | /** |
92 | Return the owner of the calendar's full name. | 93 | Return the owner of the calendar's full name. |
93 | */ | 94 | */ |
94 | const QString &getOwner() const; | 95 | const QString &getOwner() const; |
95 | /** | 96 | /** |
96 | Set the owner of the calendar. Should be owner's full name. | 97 | Set the owner of the calendar. Should be owner's full name. |
97 | */ | 98 | */ |
98 | void setOwner( const QString &os ); | 99 | void setOwner( const QString &os ); |
99 | /** | 100 | /** |
100 | Return the email address of the calendar owner. | 101 | Return the email address of the calendar owner. |
101 | */ | 102 | */ |
102 | const QString &getEmail(); | 103 | const QString &getEmail(); |
103 | /** | 104 | /** |
104 | Set the email address of the calendar owner. | 105 | Set the email address of the calendar owner. |
105 | */ | 106 | */ |
106 | void setEmail( const QString & ); | 107 | void setEmail( const QString & ); |
107 | 108 | ||
108 | /** | 109 | /** |
109 | Set time zone from a timezone string (e.g. -2:00) | 110 | Set time zone from a timezone string (e.g. -2:00) |
110 | */ | 111 | */ |
111 | void setTimeZone( const QString &tz ); | 112 | void setTimeZone( const QString &tz ); |
112 | /** | 113 | /** |
113 | Set time zone from a minutes value (e.g. -60) | 114 | Set time zone from a minutes value (e.g. -60) |
114 | */ | 115 | */ |
115 | void setTimeZone( int tz ); | 116 | void setTimeZone( int tz ); |
116 | /** | 117 | /** |
117 | Return time zone as offest in minutes. | 118 | Return time zone as offest in minutes. |
118 | */ | 119 | */ |
119 | int getTimeZone() const; | 120 | int getTimeZone() const; |
120 | /** | 121 | /** |
121 | Compute an ISO 8601 format string from the time zone. | 122 | Compute an ISO 8601 format string from the time zone. |
122 | */ | 123 | */ |
123 | QString getTimeZoneStr() const; | 124 | QString getTimeZoneStr() const; |
124 | /** | 125 | /** |
125 | Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal | 126 | Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal |
126 | values). | 127 | values). |
127 | */ | 128 | */ |
128 | void setTimeZoneId( const QString & ); | 129 | void setTimeZoneId( const QString & ); |
129 | /** | 130 | /** |
130 | Return time zone id. | 131 | Return time zone id. |
131 | */ | 132 | */ |
132 | QString timeZoneId() const; | 133 | QString timeZoneId() const; |
133 | /** | 134 | /** |
134 | Use local time, not UTC or a time zone. | 135 | Use local time, not UTC or a time zone. |
135 | */ | 136 | */ |
136 | void setLocalTime(); | 137 | void setLocalTime(); |
137 | /** | 138 | /** |
138 | Return whether local time is being used. | 139 | Return whether local time is being used. |
139 | */ | 140 | */ |
140 | bool isLocalTime() const; | 141 | bool isLocalTime() const; |
141 | 142 | ||
142 | /** | 143 | /** |
143 | Add an incidence to calendar. | 144 | Add an incidence to calendar. |
144 | 145 | ||
145 | @return true on success, false on error. | 146 | @return true on success, false on error. |
146 | */ | 147 | */ |
147 | virtual bool addIncidence( Incidence * ); | 148 | virtual bool addIncidence( Incidence * ); |
148 | 149 | ||
149 | // Adds an incidence and all relatedto incidences to the cal | 150 | // Adds an incidence and all relatedto incidences to the cal |
150 | void addIncidenceBranch( Incidence * ); | 151 | void addIncidenceBranch( Incidence * ); |
151 | /** | 152 | /** |
152 | Return filtered list of all incidences of this calendar. | 153 | Return filtered list of all incidences of this calendar. |
153 | */ | 154 | */ |
154 | virtual QPtrList<Incidence> incidences(); | 155 | virtual QPtrList<Incidence> incidences(); |
155 | 156 | ||
156 | /** | 157 | /** |
157 | Return unfiltered list of all incidences of this calendar. | 158 | Return unfiltered list of all incidences of this calendar. |
158 | */ | 159 | */ |
159 | virtual QPtrList<Incidence> rawIncidences(); | 160 | virtual QPtrList<Incidence> rawIncidences(); |
160 | 161 | ||
161 | /** | 162 | /** |
162 | Adds a Event to this calendar object. | 163 | Adds a Event to this calendar object. |
163 | @param anEvent a pointer to the event to add | 164 | @param anEvent a pointer to the event to add |
164 | 165 | ||
165 | @return true on success, false on error. | 166 | @return true on success, false on error. |
166 | */ | 167 | */ |
167 | virtual bool addEventNoDup( Event *event ) = 0; | 168 | virtual bool addEventNoDup( Event *event ) = 0; |
168 | virtual bool addAnniversaryNoDup( Event *event ) = 0; | 169 | virtual bool addAnniversaryNoDup( Event *event ) = 0; |
169 | virtual bool addEvent( Event *anEvent ) = 0; | 170 | virtual bool addEvent( Event *anEvent ) = 0; |
170 | /** | 171 | /** |
171 | Delete event from calendar. | 172 | Delete event from calendar. |
172 | */ | 173 | */ |
173 | virtual void deleteEvent( Event * ) = 0; | 174 | virtual void deleteEvent( Event * ) = 0; |
174 | /** | 175 | /** |
175 | Retrieves an event on the basis of the unique string ID. | 176 | Retrieves an event on the basis of the unique string ID. |
176 | */ | 177 | */ |
177 | virtual Event *event( const QString &UniqueStr ) = 0; | 178 | virtual Event *event( const QString &UniqueStr ) = 0; |
178 | virtual Event *event( QString, QString ) = 0; | 179 | virtual Event *event( QString, QString ) = 0; |
179 | /** | 180 | /** |
180 | Builds and then returns a list of all events that match for the | 181 | Builds and then returns a list of all events that match for the |
181 | date specified. useful for dayView, etc. etc. | 182 | date specified. useful for dayView, etc. etc. |
182 | The calendar filter is applied. | 183 | The calendar filter is applied. |
183 | */ | 184 | */ |
184 | QPtrList<Event> events( const QDate &date, bool sorted = false); | 185 | QPtrList<Event> events( const QDate &date, bool sorted = false); |
185 | /** | 186 | /** |
186 | Get events, which occur on the given date. | 187 | Get events, which occur on the given date. |
187 | The calendar filter is applied. | 188 | The calendar filter is applied. |
188 | */ | 189 | */ |
189 | QPtrList<Event> events( const QDateTime &qdt ); | 190 | QPtrList<Event> events( const QDateTime &qdt ); |
190 | /** | 191 | /** |
191 | Get events in a range of dates. If inclusive is set to true, only events | 192 | Get events in a range of dates. If inclusive is set to true, only events |
192 | are returned, which are completely included in the range. | 193 | are returned, which are completely included in the range. |
193 | The calendar filter is applied. | 194 | The calendar filter is applied. |
194 | */ | 195 | */ |
195 | QPtrList<Event> events( const QDate &start, const QDate &end, | 196 | QPtrList<Event> events( const QDate &start, const QDate &end, |
196 | bool inclusive = false); | 197 | bool inclusive = false); |
197 | /** | 198 | /** |
198 | Return filtered list of all events in calendar. | 199 | Return filtered list of all events in calendar. |
199 | */ | 200 | */ |
200 | virtual QPtrList<Event> events(); | 201 | virtual QPtrList<Event> events(); |
201 | /** | 202 | /** |
202 | Return unfiltered list of all events in calendar. | 203 | Return unfiltered list of all events in calendar. |
203 | */ | 204 | */ |
204 | virtual QPtrList<Event> rawEvents() = 0; | 205 | virtual QPtrList<Event> rawEvents() = 0; |
205 | 206 | ||
206 | /** | 207 | /** |
207 | Add a todo to the todolist. | 208 | Add a todo to the todolist. |
208 | 209 | ||
209 | @return true on success, false on error. | 210 | @return true on success, false on error. |
210 | */ | 211 | */ |
211 | virtual bool addTodo( Todo *todo ) = 0; | 212 | virtual bool addTodo( Todo *todo ) = 0; |
212 | virtual bool addTodoNoDup( Todo *todo ) = 0; | 213 | virtual bool addTodoNoDup( Todo *todo ) = 0; |
213 | /** | 214 | /** |
214 | Remove a todo from the todolist. | 215 | Remove a todo from the todolist. |
215 | */ | 216 | */ |
216 | virtual void deleteTodo( Todo * ) = 0; | 217 | virtual void deleteTodo( Todo * ) = 0; |
217 | virtual void deleteJournal( Journal * ) = 0; | 218 | virtual void deleteJournal( Journal * ) = 0; |
218 | /** | 219 | /** |
219 | Return filterd list of todos. | 220 | Return filterd list of todos. |
220 | */ | 221 | */ |
221 | virtual QPtrList<Todo> todos(); | 222 | virtual QPtrList<Todo> todos(); |
222 | /** | 223 | /** |
223 | Searches todolist for an event with this unique string identifier, | 224 | Searches todolist for an event with this unique string identifier, |
224 | returns a pointer or null. | 225 | returns a pointer or null. |
225 | */ | 226 | */ |
226 | virtual Todo *todo( const QString &uid ) = 0; | 227 | virtual Todo *todo( const QString &uid ) = 0; |
227 | virtual Todo *todo( QString, QString ) = 0; | 228 | virtual Todo *todo( QString, QString ) = 0; |
228 | /** | 229 | /** |
229 | Returns list of todos due on the specified date. | 230 | Returns list of todos due on the specified date. |
230 | */ | 231 | */ |
231 | virtual QPtrList<Todo> todos( const QDate &date ) = 0; | 232 | virtual QPtrList<Todo> todos( const QDate &date ) = 0; |
232 | /** | 233 | /** |
233 | Return unfiltered list of todos. | 234 | Return unfiltered list of todos. |
234 | */ | 235 | */ |
235 | virtual QPtrList<Todo> rawTodos() = 0; | 236 | virtual QPtrList<Todo> rawTodos() = 0; |
236 | 237 | ||
237 | /** | 238 | /** |
238 | Add a Journal entry to calendar. | 239 | Add a Journal entry to calendar. |
239 | 240 | ||
240 | @return true on success, false on error. | 241 | @return true on success, false on error. |
241 | */ | 242 | */ |
242 | virtual bool addJournal( Journal * ) = 0; | 243 | virtual bool addJournal( Journal * ) = 0; |
243 | /** | 244 | /** |
244 | Return Journal for given date. | 245 | Return Journal for given date. |
245 | */ | 246 | */ |
246 | virtual Journal *journal( const QDate & ) = 0; | 247 | virtual Journal *journal( const QDate & ) = 0; |
247 | virtual QPtrList<Journal> journals4Date( const QDate & ) = 0; | 248 | virtual QPtrList<Journal> journals4Date( const QDate & ) = 0; |
248 | /** | 249 | /** |
249 | Return Journal with given UID. | 250 | Return Journal with given UID. |
250 | */ | 251 | */ |
251 | virtual Journal *journal( const QString &UID ) = 0; | 252 | virtual Journal *journal( const QString &UID ) = 0; |
252 | /** | 253 | /** |
253 | Return list of all Journal entries. | 254 | Return list of all Journal entries. |
254 | */ | 255 | */ |
255 | virtual QPtrList<Journal> journals() = 0; | 256 | virtual QPtrList<Journal> journals() = 0; |
256 | 257 | ||
257 | /** | 258 | /** |
258 | Searches all incidence types for an incidence with this unique | 259 | Searches all incidence types for an incidence with this unique |
259 | string identifier, returns a pointer or null. | 260 | string identifier, returns a pointer or null. |
260 | */ | 261 | */ |
261 | Incidence* incidence( const QString&UID ); | 262 | Incidence* incidence( const QString&UID ); |
262 | 263 | ||
263 | /** | 264 | /** |
264 | Setup relations for an incidence. | 265 | Setup relations for an incidence. |
265 | */ | 266 | */ |
266 | virtual void setupRelations( Incidence * ); | 267 | virtual void setupRelations( Incidence * ); |
267 | /** | 268 | /** |
268 | Remove all relations to an incidence | 269 | Remove all relations to an incidence |
269 | */ | 270 | */ |
270 | virtual void removeRelations( Incidence * ); | 271 | virtual void removeRelations( Incidence * ); |
271 | 272 | ||
272 | /** | 273 | /** |
273 | Set calendar filter, which filters events for the events() functions. | 274 | Set calendar filter, which filters events for the events() functions. |
274 | The Filter object is owned by the caller. | 275 | The Filter object is owned by the caller. |
275 | */ | 276 | */ |
276 | void setFilter( CalFilter * ); | 277 | void setFilter( CalFilter * ); |
277 | /** | 278 | /** |
278 | Return calendar filter. | 279 | Return calendar filter. |
279 | */ | 280 | */ |
280 | CalFilter *filter(); | 281 | CalFilter *filter(); |
281 | virtual QDateTime nextAlarm( int daysTo ) = 0; | 282 | virtual QDateTime nextAlarm( int daysTo ) = 0; |
282 | virtual QString nextSummary( ) const = 0; | 283 | virtual QString nextSummary( ) const = 0; |
283 | virtual void reInitAlarmSettings() = 0; | 284 | virtual void reInitAlarmSettings() = 0; |
284 | virtual QDateTime nextAlarmEventDateTime() const = 0; | 285 | virtual QDateTime nextAlarmEventDateTime() const = 0; |
285 | virtual void checkAlarmForIncidence( Incidence *, bool ) = 0; | 286 | virtual void checkAlarmForIncidence( Incidence *, bool ) = 0; |
286 | /** | 287 | /** |
287 | Return all alarms, which ocur in the given time interval. | 288 | Return all alarms, which ocur in the given time interval. |
288 | */ | 289 | */ |
289 | virtual Alarm::List alarms( const QDateTime &from, | 290 | virtual Alarm::List alarms( const QDateTime &from, |
290 | const QDateTime &to ) = 0; | 291 | const QDateTime &to ) = 0; |
291 | 292 | ||
292 | class Observer { | 293 | class Observer { |
293 | public: | 294 | public: |
294 | virtual void calendarModified( bool, Calendar * ) = 0; | 295 | virtual void calendarModified( bool, Calendar * ) = 0; |
295 | }; | 296 | }; |
296 | 297 | ||
297 | void registerObserver( Observer * ); | 298 | void registerObserver( Observer * ); |
298 | 299 | ||
299 | void setModified( bool ); | 300 | void setModified( bool ); |
300 | 301 | ||
301 | /** | 302 | /** |
302 | Set product id returned by loadedProductId(). This function is only | 303 | Set product id returned by loadedProductId(). This function is only |
303 | useful for the calendar loading code. | 304 | useful for the calendar loading code. |
304 | */ | 305 | */ |
305 | void setLoadedProductId( const QString & ); | 306 | void setLoadedProductId( const QString & ); |
306 | /** | 307 | /** |
307 | Return product id taken from file that has been loaded. Returns | 308 | Return product id taken from file that has been loaded. Returns |
308 | QString::null, if no calendar has been loaded. | 309 | QString::null, if no calendar has been loaded. |
309 | */ | 310 | */ |
310 | QString loadedProductId(); | 311 | QString loadedProductId(); |
311 | int defaultCalendar(); | 312 | int defaultCalendar(); |
312 | void setDontDeleteIncidencesOnClose (); | 313 | void setDontDeleteIncidencesOnClose (); |
313 | public slots: | 314 | public slots: |
314 | void setDefaultCalendar( int ); | 315 | void setDefaultCalendar( int ); |
315 | virtual void setCalendarEnabled( int id, bool enable ) = 0; | 316 | virtual void setCalendarEnabled( int id, bool enable ) = 0; |
316 | virtual void setAlarmEnabled( int id, bool enable ) = 0; | 317 | virtual void setAlarmEnabled( int id, bool enable ) = 0; |
317 | virtual void setReadOnly( int id, bool enable ) = 0; | 318 | virtual void setReadOnly( int id, bool enable ) = 0; |
318 | virtual void setDefaultCalendarEnabledOnly() = 0; | 319 | virtual void setDefaultCalendarEnabledOnly() = 0; |
319 | virtual void setCalendarRemove( int id ) = 0; | 320 | virtual void setCalendarRemove( int id ) = 0; |
320 | signals: | 321 | signals: |
321 | void calendarChanged(); | 322 | void calendarChanged(); |
322 | void calendarSaved(); | 323 | void calendarSaved(); |
323 | void calendarLoaded(); | 324 | void calendarLoaded(); |
324 | void addAlarm(const QDateTime &qdt, const QString ¬i ); | 325 | void addAlarm(const QDateTime &qdt, const QString ¬i ); |
325 | void removeAlarm(const QDateTime &qdt, const QString ¬i ); | 326 | void removeAlarm(const QDateTime &qdt, const QString ¬i ); |
326 | 327 | ||
327 | protected: | 328 | protected: |
328 | /** | 329 | /** |
329 | Get unfiltered events, which occur on the given date. | 330 | Get unfiltered events, which occur on the given date. |
330 | */ | 331 | */ |
331 | virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0; | 332 | virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0; |
332 | /** | 333 | /** |
333 | Get unfiltered events, which occur on the given date. | 334 | Get unfiltered events, which occur on the given date. |
334 | */ | 335 | */ |
335 | virtual QPtrList<Event> rawEventsForDate( const QDate &date, | 336 | virtual QPtrList<Event> rawEventsForDate( const QDate &date, |
336 | bool sorted = false ) = 0; | 337 | bool sorted = false ) = 0; |
337 | /** | 338 | /** |
338 | Get events in a range of dates. If inclusive is set to true, only events | 339 | Get events in a range of dates. If inclusive is set to true, only events |
339 | are returned, which are completely included in the range. | 340 | are returned, which are completely included in the range. |
340 | */ | 341 | */ |
341 | virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end, | 342 | virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end, |
342 | bool inclusive = false ) = 0; | 343 | bool inclusive = false ) = 0; |
343 | 344 | ||
344 | Incidence *mNextAlarmIncidence; | 345 | Incidence *mNextAlarmIncidence; |
345 | Incidence *mUndoIncidence; | 346 | Incidence *mUndoIncidence; |
346 | int mDefaultCalendar; | 347 | int mDefaultCalendar; |
347 | bool mDeleteIncidencesOnClose; | 348 | bool mDeleteIncidencesOnClose; |
348 | 349 | ||
349 | private: | 350 | private: |
350 | void init(); | 351 | void init(); |
351 | 352 | ||
352 | QString mOwner; // who the calendar belongs to | 353 | QString mOwner; // who the calendar belongs to |
353 | QString mOwnerEmail; // email address of the owner | 354 | QString mOwnerEmail; // email address of the owner |
354 | int mTimeZone; // timezone OFFSET from GMT (MINUTES) | 355 | int mTimeZone; // timezone OFFSET from GMT (MINUTES) |
355 | bool mLocalTime; // use local time, not UTC or a time zone | 356 | bool mLocalTime; // use local time, not UTC or a time zone |
356 | 357 | ||
357 | 358 | ||
358 | CalFilter *mFilter; | 359 | CalFilter *mFilter; |
359 | CalFilter *mDefaultFilter; | 360 | CalFilter *mDefaultFilter; |
360 | 361 | ||
361 | 362 | ||
362 | QString mTimeZoneId; | 363 | QString mTimeZoneId; |
363 | 364 | ||
364 | Observer *mObserver; | 365 | Observer *mObserver; |
365 | bool mNewObserver; | 366 | bool mNewObserver; |
366 | 367 | ||
367 | bool mModified; | 368 | bool mModified; |
368 | 369 | ||
369 | QString mLoadedProductId; | 370 | QString mLoadedProductId; |
370 | 371 | ||
371 | // This list is used to put together related todos | 372 | // This list is used to put together related todos |
372 | QDict<Incidence> mOrphans; | 373 | QDict<Incidence> mOrphans; |
373 | QDict<Incidence> mOrphanUids; | 374 | QDict<Incidence> mOrphanUids; |
374 | }; | 375 | }; |
375 | 376 | ||
376 | } | 377 | } |
377 | 378 | ||
378 | #endif | 379 | #endif |
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index 3e42ec0..e37a7ad 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp | |||
@@ -1,913 +1,932 @@ | |||
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 |
46 | using namespace KCal; | 46 | using namespace KCal; |
47 | 47 | ||
48 | CalendarLocal::CalendarLocal() | 48 | CalendarLocal::CalendarLocal() |
49 | : Calendar() | 49 | : Calendar() |
50 | { | 50 | { |
51 | init(); | 51 | init(); |
52 | } | 52 | } |
53 | 53 | ||
54 | CalendarLocal::CalendarLocal(const QString &timeZoneId) | 54 | CalendarLocal::CalendarLocal(const QString &timeZoneId) |
55 | : Calendar(timeZoneId) | 55 | : Calendar(timeZoneId) |
56 | { | 56 | { |
57 | init(); | 57 | init(); |
58 | } | 58 | } |
59 | 59 | ||
60 | void CalendarLocal::init() | 60 | void CalendarLocal::init() |
61 | { | 61 | { |
62 | mNextAlarmIncidence = 0; | 62 | mNextAlarmIncidence = 0; |
63 | } | 63 | } |
64 | 64 | ||
65 | 65 | ||
66 | CalendarLocal::~CalendarLocal() | 66 | CalendarLocal::~CalendarLocal() |
67 | { | 67 | { |
68 | if ( mDeleteIncidencesOnClose ) | 68 | if ( mDeleteIncidencesOnClose ) |
69 | close(); | 69 | close(); |
70 | } | 70 | } |
71 | bool CalendarLocal::mergeCalendarFile( QString name ) | 71 | bool CalendarLocal::mergeCalendarFile( QString name ) |
72 | { | 72 | { |
73 | CalendarLocal calendar( timeZoneId() ); | 73 | CalendarLocal calendar( timeZoneId() ); |
74 | calendar.setDefaultCalendar( 1 ); | 74 | calendar.setDefaultCalendar( 1 ); |
75 | if ( calendar.load( name ) ) { | 75 | if ( calendar.load( name ) ) { |
76 | mergeCalendar( &calendar ); | 76 | mergeCalendar( &calendar ); |
77 | return true; | 77 | return true; |
78 | } | 78 | } |
79 | return false; | 79 | return false; |
80 | } | 80 | } |
81 | 81 | ||
82 | Incidence* CalendarLocal::incidenceForUid( const QString& uid ) | 82 | Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates) |
83 | { | 83 | { |
84 | Todo *todo;; | 84 | Todo *todo;; |
85 | Incidence *retVal = 0; | 85 | Incidence *retVal = 0; |
86 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 86 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
87 | if ( todo->uid() == uid ) { | 87 | if ( todo->uid() == uid ) { |
88 | if ( doNotCheckDuplicates ) return todo; | ||
88 | if ( retVal ) { | 89 | if ( retVal ) { |
89 | if ( retVal->calID() > todo->calID() ) { | 90 | if ( retVal->calID() > todo->calID() ) { |
90 | retVal = todo; | 91 | retVal = todo; |
91 | } | 92 | } |
92 | } else { | 93 | } else { |
93 | retVal = todo; | 94 | retVal = todo; |
94 | } | 95 | } |
95 | } | 96 | } |
96 | } | 97 | } |
97 | if ( retVal ) return retVal; | 98 | if ( retVal ) return retVal; |
98 | Event *event; | 99 | Event *event; |
99 | for ( event = mEventList.first(); event; event = mEventList.next() ) { | 100 | for ( event = mEventList.first(); event; event = mEventList.next() ) { |
100 | if ( event->uid() == uid ) { | 101 | if ( event->uid() == uid ) { |
102 | if ( doNotCheckDuplicates ) return event; | ||
101 | if ( retVal ) { | 103 | if ( retVal ) { |
102 | if ( retVal->calID() > event->calID() ) { | 104 | if ( retVal->calID() > event->calID() ) { |
103 | retVal = event; | 105 | retVal = event; |
104 | } | 106 | } |
105 | } else { | 107 | } else { |
106 | retVal = event; | 108 | retVal = event; |
107 | } | 109 | } |
108 | } | 110 | } |
109 | } | 111 | } |
110 | if ( retVal ) return retVal; | 112 | if ( retVal ) return retVal; |
111 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 113 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
112 | if ( it->uid() == uid ) { | 114 | if ( it->uid() == uid ) { |
115 | if ( doNotCheckDuplicates ) return it; | ||
113 | if ( retVal ) { | 116 | if ( retVal ) { |
114 | if ( retVal->calID() > it->calID() ) { | 117 | if ( retVal->calID() > it->calID() ) { |
115 | retVal = it; | 118 | retVal = it; |
116 | } | 119 | } |
117 | } else { | 120 | } else { |
118 | retVal = it; | 121 | retVal = it; |
119 | } | 122 | } |
120 | } | 123 | } |
121 | return retVal; | 124 | return retVal; |
122 | } | 125 | } |
123 | 126 | ||
124 | bool CalendarLocal::mergeCalendar( Calendar* remote ) | 127 | bool CalendarLocal::mergeCalendar( Calendar* remote ) |
125 | { | 128 | { |
129 | // 1 look for raw inc in local | ||
130 | // if inc not in remote, delete in local | ||
131 | // 2 look for raw inc in remote | ||
132 | // if inc in local, replace it | ||
133 | // if not in local, add it to default calendar | ||
134 | QPtrList<Incidence> localInc = rawIncidences(); | ||
135 | Incidence* inL = localInc.first(); | ||
136 | while ( inL ) { | ||
137 | if ( ! inL->isReadOnly () ) | ||
138 | if ( !remote->incidenceForUid( inL->uid(), true )) | ||
139 | deleteIncidence( inL ); | ||
140 | inL = localInc.next(); | ||
141 | } | ||
126 | QPtrList<Incidence> er = remote->rawIncidences(); | 142 | QPtrList<Incidence> er = remote->rawIncidences(); |
127 | Incidence* inR = er.first(); | 143 | Incidence* inR = er.first(); |
128 | Incidence* inL; | ||
129 | while ( inR ) { | 144 | while ( inR ) { |
130 | inL = incidenceForUid( inR->uid() ); | 145 | inL = incidenceForUid( inR->uid(),false ); |
131 | if ( inL ) { | 146 | if ( inL ) { |
132 | int calID = inL->calID(); | 147 | if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) { |
133 | deleteIncidence( inL ); | 148 | int calID = inL->calID(); |
134 | inL = inR->clone(); | 149 | deleteIncidence( inL ); |
135 | inL->setCalID( calID ); | 150 | inL = inR->clone(); |
136 | addIncidence( inL ); | 151 | inL->setCalID( calID ); |
152 | addIncidence( inL ); | ||
153 | } | ||
137 | } else { | 154 | } else { |
138 | inL = inR->clone(); | 155 | inL = inR->clone(); |
139 | inL->setCalID( 0 );// add to default cal | 156 | inL->setCalID( 0 );// add to default cal |
140 | addIncidence( inL ); | 157 | addIncidence( inL ); |
141 | } | 158 | } |
142 | inR = er.next(); | 159 | inR = er.next(); |
143 | } | 160 | } |
144 | return true; | 161 | return true; |
145 | } | 162 | } |
163 | |||
164 | |||
146 | bool CalendarLocal::addCalendarFile( QString name, int id ) | 165 | bool CalendarLocal::addCalendarFile( QString name, int id ) |
147 | { | 166 | { |
148 | CalendarLocal calendar( timeZoneId() ); | 167 | CalendarLocal calendar( timeZoneId() ); |
149 | calendar.setDefaultCalendar( id ); | 168 | calendar.setDefaultCalendar( id ); |
150 | if ( calendar.load( name ) ) { | 169 | if ( calendar.load( name ) ) { |
151 | addCalendar( &calendar ); | 170 | addCalendar( &calendar ); |
152 | return true; | 171 | return true; |
153 | } | 172 | } |
154 | return false; | 173 | return false; |
155 | } | 174 | } |
156 | void CalendarLocal::setSyncEventsReadOnly() | 175 | void CalendarLocal::setSyncEventsReadOnly() |
157 | { | 176 | { |
158 | Event * ev; | 177 | Event * ev; |
159 | ev = mEventList.first(); | 178 | ev = mEventList.first(); |
160 | while ( ev ) { | 179 | while ( ev ) { |
161 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) | 180 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) |
162 | ev->setReadOnly( true ); | 181 | ev->setReadOnly( true ); |
163 | ev = mEventList.next(); | 182 | ev = mEventList.next(); |
164 | } | 183 | } |
165 | } | 184 | } |
166 | void CalendarLocal::addCalendar( Calendar* cal ) | 185 | void CalendarLocal::addCalendar( Calendar* cal ) |
167 | { | 186 | { |
168 | cal->setDontDeleteIncidencesOnClose(); | 187 | cal->setDontDeleteIncidencesOnClose(); |
169 | { | 188 | { |
170 | QPtrList<Event> EventList = cal->rawEvents(); | 189 | QPtrList<Event> EventList = cal->rawEvents(); |
171 | Event * ev = EventList.first(); | 190 | Event * ev = EventList.first(); |
172 | while ( ev ) { | 191 | while ( ev ) { |
173 | ev->unRegisterObserver( cal ); | 192 | ev->unRegisterObserver( cal ); |
174 | ev->registerObserver( this ); | 193 | ev->registerObserver( this ); |
175 | mEventList.append( ev ); | 194 | mEventList.append( ev ); |
176 | ev = EventList.next(); | 195 | ev = EventList.next(); |
177 | } | 196 | } |
178 | } | 197 | } |
179 | { | 198 | { |
180 | 199 | ||
181 | QPtrList<Todo> TodoList = cal->rawTodos(); | 200 | QPtrList<Todo> TodoList = cal->rawTodos(); |
182 | Todo * ev = TodoList.first(); | 201 | Todo * ev = TodoList.first(); |
183 | while ( ev ) { | 202 | while ( ev ) { |
184 | QString rel = ev->relatedToUid(); | 203 | QString rel = ev->relatedToUid(); |
185 | if ( !rel.isEmpty() ){ | 204 | if ( !rel.isEmpty() ){ |
186 | ev->setRelatedTo ( 0 ); | 205 | ev->setRelatedTo ( 0 ); |
187 | ev->setRelatedToUid( rel ); | 206 | ev->setRelatedToUid( rel ); |
188 | } | 207 | } |
189 | ev = TodoList.next(); | 208 | ev = TodoList.next(); |
190 | } | 209 | } |
191 | //TodoList = cal->rawTodos(); | 210 | //TodoList = cal->rawTodos(); |
192 | ev = TodoList.first(); | 211 | ev = TodoList.first(); |
193 | while ( ev ) { | 212 | while ( ev ) { |
194 | ev->unRegisterObserver( cal ); | 213 | ev->unRegisterObserver( cal ); |
195 | ev->registerObserver( this ); | 214 | ev->registerObserver( this ); |
196 | mTodoList.append( ev ); | 215 | mTodoList.append( ev ); |
197 | setupRelations( ev ); | 216 | setupRelations( ev ); |
198 | ev = TodoList.next(); | 217 | ev = TodoList.next(); |
199 | } | 218 | } |
200 | } | 219 | } |
201 | { | 220 | { |
202 | QPtrList<Journal> JournalList = cal->journals(); | 221 | QPtrList<Journal> JournalList = cal->journals(); |
203 | Journal * ev = JournalList.first(); | 222 | Journal * ev = JournalList.first(); |
204 | while ( ev ) { | 223 | while ( ev ) { |
205 | ev->unRegisterObserver( cal ); | 224 | ev->unRegisterObserver( cal ); |
206 | ev->registerObserver( this ); | 225 | ev->registerObserver( this ); |
207 | mJournalList.append( ev ); | 226 | mJournalList.append( ev ); |
208 | ev = JournalList.next(); | 227 | ev = JournalList.next(); |
209 | } | 228 | } |
210 | } | 229 | } |
211 | setModified( true ); | 230 | setModified( true ); |
212 | } | 231 | } |
213 | bool CalendarLocal::load( const QString &fileName ) | 232 | bool CalendarLocal::load( const QString &fileName ) |
214 | { | 233 | { |
215 | FileStorage storage( this, fileName ); | 234 | FileStorage storage( this, fileName ); |
216 | return storage.load(); | 235 | return storage.load(); |
217 | } | 236 | } |
218 | 237 | ||
219 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) | 238 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) |
220 | { | 239 | { |
221 | FileStorage storage( this, fileName, format ); | 240 | FileStorage storage( this, fileName, format ); |
222 | return storage.save(); | 241 | return storage.save(); |
223 | } | 242 | } |
224 | 243 | ||
225 | void CalendarLocal::stopAllTodos() | 244 | void CalendarLocal::stopAllTodos() |
226 | { | 245 | { |
227 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 246 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
228 | it->setRunning( false ); | 247 | it->setRunning( false ); |
229 | 248 | ||
230 | } | 249 | } |
231 | void CalendarLocal::close() | 250 | void CalendarLocal::close() |
232 | { | 251 | { |
233 | 252 | ||
234 | Todo * i; | 253 | Todo * i; |
235 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); | 254 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); |
236 | 255 | ||
237 | mEventList.setAutoDelete( true ); | 256 | mEventList.setAutoDelete( true ); |
238 | mTodoList.setAutoDelete( true ); | 257 | mTodoList.setAutoDelete( true ); |
239 | mJournalList.setAutoDelete( false ); | 258 | mJournalList.setAutoDelete( false ); |
240 | 259 | ||
241 | mEventList.clear(); | 260 | mEventList.clear(); |
242 | mTodoList.clear(); | 261 | mTodoList.clear(); |
243 | mJournalList.clear(); | 262 | mJournalList.clear(); |
244 | 263 | ||
245 | mEventList.setAutoDelete( false ); | 264 | mEventList.setAutoDelete( false ); |
246 | mTodoList.setAutoDelete( false ); | 265 | mTodoList.setAutoDelete( false ); |
247 | mJournalList.setAutoDelete( false ); | 266 | mJournalList.setAutoDelete( false ); |
248 | 267 | ||
249 | setModified( false ); | 268 | setModified( false ); |
250 | } | 269 | } |
251 | 270 | ||
252 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) | 271 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) |
253 | { | 272 | { |
254 | QString cat; | 273 | QString cat; |
255 | bool isBirthday = true; | 274 | bool isBirthday = true; |
256 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { | 275 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { |
257 | isBirthday = false; | 276 | isBirthday = false; |
258 | cat = i18n( "Anniversary" ); | 277 | cat = i18n( "Anniversary" ); |
259 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { | 278 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { |
260 | isBirthday = true; | 279 | isBirthday = true; |
261 | cat = i18n( "Birthday" ); | 280 | cat = i18n( "Birthday" ); |
262 | } else { | 281 | } else { |
263 | qDebug("addAnniversaryNoDup called without fitting category! "); | 282 | qDebug("addAnniversaryNoDup called without fitting category! "); |
264 | return false; | 283 | return false; |
265 | } | 284 | } |
266 | Event * eve; | 285 | Event * eve; |
267 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 286 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
268 | if ( !(eve->categories().contains( cat ) )) | 287 | if ( !(eve->categories().contains( cat ) )) |
269 | continue; | 288 | continue; |
270 | // now we have an event with fitting category | 289 | // now we have an event with fitting category |
271 | if ( eve->dtStart().date() != event->dtStart().date() ) | 290 | if ( eve->dtStart().date() != event->dtStart().date() ) |
272 | continue; | 291 | continue; |
273 | // now we have an event with fitting category+date | 292 | // now we have an event with fitting category+date |
274 | if ( eve->summary() != event->summary() ) | 293 | if ( eve->summary() != event->summary() ) |
275 | continue; | 294 | continue; |
276 | // now we have an event with fitting category+date+summary | 295 | // now we have an event with fitting category+date+summary |
277 | return false; | 296 | return false; |
278 | } | 297 | } |
279 | return addEvent( event ); | 298 | return addEvent( event ); |
280 | 299 | ||
281 | } | 300 | } |
282 | bool CalendarLocal::addEventNoDup( Event *event ) | 301 | bool CalendarLocal::addEventNoDup( Event *event ) |
283 | { | 302 | { |
284 | Event * eve; | 303 | Event * eve; |
285 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 304 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
286 | if ( *eve == *event ) { | 305 | if ( *eve == *event ) { |
287 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); | 306 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); |
288 | return false; | 307 | return false; |
289 | } | 308 | } |
290 | } | 309 | } |
291 | return addEvent( event ); | 310 | return addEvent( event ); |
292 | } | 311 | } |
293 | 312 | ||
294 | bool CalendarLocal::addEvent( Event *event ) | 313 | bool CalendarLocal::addEvent( Event *event ) |
295 | { | 314 | { |
296 | insertEvent( event ); | 315 | insertEvent( event ); |
297 | 316 | ||
298 | event->registerObserver( this ); | 317 | event->registerObserver( this ); |
299 | 318 | ||
300 | setModified( true ); | 319 | setModified( true ); |
301 | if ( event->calID() == 0 ) | 320 | if ( event->calID() == 0 ) |
302 | event->setCalID( mDefaultCalendar ); | 321 | event->setCalID( mDefaultCalendar ); |
303 | event->setCalEnabled( true ); | 322 | event->setCalEnabled( true ); |
304 | 323 | ||
305 | return true; | 324 | return true; |
306 | } | 325 | } |
307 | 326 | ||
308 | void CalendarLocal::deleteEvent( Event *event ) | 327 | void CalendarLocal::deleteEvent( Event *event ) |
309 | { | 328 | { |
310 | if ( mUndoIncidence ) delete mUndoIncidence; | 329 | if ( mUndoIncidence ) delete mUndoIncidence; |
311 | mUndoIncidence = event->clone(); | 330 | mUndoIncidence = event->clone(); |
312 | if ( mEventList.removeRef( event ) ) { | 331 | if ( mEventList.removeRef( event ) ) { |
313 | setModified( true ); | 332 | setModified( true ); |
314 | } | 333 | } |
315 | } | 334 | } |
316 | 335 | ||
317 | 336 | ||
318 | Event *CalendarLocal::event( const QString &uid ) | 337 | Event *CalendarLocal::event( const QString &uid ) |
319 | { | 338 | { |
320 | Event *event; | 339 | Event *event; |
321 | Event *retVal = 0; | 340 | Event *retVal = 0; |
322 | for ( event = mEventList.first(); event; event = mEventList.next() ) { | 341 | for ( event = mEventList.first(); event; event = mEventList.next() ) { |
323 | if ( event->calEnabled() && event->uid() == uid ) { | 342 | if ( event->calEnabled() && event->uid() == uid ) { |
324 | if ( retVal ) { | 343 | if ( retVal ) { |
325 | if ( retVal->calID() > event->calID() ) { | 344 | if ( retVal->calID() > event->calID() ) { |
326 | retVal = event; | 345 | retVal = event; |
327 | } | 346 | } |
328 | } else { | 347 | } else { |
329 | retVal = event; | 348 | retVal = event; |
330 | } | 349 | } |
331 | } | 350 | } |
332 | } | 351 | } |
333 | return retVal; | 352 | return retVal; |
334 | } | 353 | } |
335 | bool CalendarLocal::addTodoNoDup( Todo *todo ) | 354 | bool CalendarLocal::addTodoNoDup( Todo *todo ) |
336 | { | 355 | { |
337 | Todo * eve; | 356 | Todo * eve; |
338 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { | 357 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { |
339 | if ( *eve == *todo ) { | 358 | if ( *eve == *todo ) { |
340 | //qDebug("duplicate todo found! not inserted! "); | 359 | //qDebug("duplicate todo found! not inserted! "); |
341 | return false; | 360 | return false; |
342 | } | 361 | } |
343 | } | 362 | } |
344 | return addTodo( todo ); | 363 | return addTodo( todo ); |
345 | } | 364 | } |
346 | bool CalendarLocal::addTodo( Todo *todo ) | 365 | bool CalendarLocal::addTodo( Todo *todo ) |
347 | { | 366 | { |
348 | mTodoList.append( todo ); | 367 | mTodoList.append( todo ); |
349 | 368 | ||
350 | todo->registerObserver( this ); | 369 | todo->registerObserver( this ); |
351 | 370 | ||
352 | // Set up subtask relations | 371 | // Set up subtask relations |
353 | setupRelations( todo ); | 372 | setupRelations( todo ); |
354 | 373 | ||
355 | setModified( true ); | 374 | setModified( true ); |
356 | if ( todo->calID() == 0 ) | 375 | if ( todo->calID() == 0 ) |
357 | todo->setCalID( mDefaultCalendar ); | 376 | todo->setCalID( mDefaultCalendar ); |
358 | todo->setCalEnabled( true ); | 377 | todo->setCalEnabled( true ); |
359 | return true; | 378 | return true; |
360 | } | 379 | } |
361 | 380 | ||
362 | void CalendarLocal::deleteTodo( Todo *todo ) | 381 | void CalendarLocal::deleteTodo( Todo *todo ) |
363 | { | 382 | { |
364 | // Handle orphaned children | 383 | // Handle orphaned children |
365 | if ( mUndoIncidence ) delete mUndoIncidence; | 384 | if ( mUndoIncidence ) delete mUndoIncidence; |
366 | removeRelations( todo ); | 385 | removeRelations( todo ); |
367 | mUndoIncidence = todo->clone(); | 386 | mUndoIncidence = todo->clone(); |
368 | 387 | ||
369 | if ( mTodoList.removeRef( todo ) ) { | 388 | if ( mTodoList.removeRef( todo ) ) { |
370 | setModified( true ); | 389 | setModified( true ); |
371 | } | 390 | } |
372 | } | 391 | } |
373 | 392 | ||
374 | QPtrList<Todo> CalendarLocal::rawTodos() | 393 | QPtrList<Todo> CalendarLocal::rawTodos() |
375 | { | 394 | { |
376 | QPtrList<Todo> el; | 395 | QPtrList<Todo> el; |
377 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 396 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
378 | if ( it->calEnabled() ) el.append( it ); | 397 | if ( it->calEnabled() ) el.append( it ); |
379 | return el; | 398 | return el; |
380 | } | 399 | } |
381 | Todo *CalendarLocal::todo( QString syncProf, QString id ) | 400 | Todo *CalendarLocal::todo( QString syncProf, QString id ) |
382 | { | 401 | { |
383 | Todo *todo; | 402 | Todo *todo; |
384 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 403 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
385 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; | 404 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; |
386 | } | 405 | } |
387 | 406 | ||
388 | return 0; | 407 | return 0; |
389 | } | 408 | } |
390 | void CalendarLocal::removeSyncInfo( QString syncProfile) | 409 | void CalendarLocal::removeSyncInfo( QString syncProfile) |
391 | { | 410 | { |
392 | QPtrList<Incidence> all = rawIncidences() ; | 411 | QPtrList<Incidence> all = rawIncidences() ; |
393 | Incidence *inc; | 412 | Incidence *inc; |
394 | for ( inc = all.first(); inc; inc = all.next() ) { | 413 | for ( inc = all.first(); inc; inc = all.next() ) { |
395 | inc->removeID( syncProfile ); | 414 | inc->removeID( syncProfile ); |
396 | } | 415 | } |
397 | if ( syncProfile.isEmpty() ) { | 416 | if ( syncProfile.isEmpty() ) { |
398 | QPtrList<Event> el; | 417 | QPtrList<Event> el; |
399 | Event *todo; | 418 | Event *todo; |
400 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 419 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
401 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 420 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
402 | el.append( todo ); | 421 | el.append( todo ); |
403 | } | 422 | } |
404 | for ( todo = el.first(); todo; todo = el.next() ) { | 423 | for ( todo = el.first(); todo; todo = el.next() ) { |
405 | deleteIncidence ( todo ); | 424 | deleteIncidence ( todo ); |
406 | } | 425 | } |
407 | } else { | 426 | } else { |
408 | Event *lse = event( "last-syncEvent-"+ syncProfile); | 427 | Event *lse = event( "last-syncEvent-"+ syncProfile); |
409 | if ( lse ) | 428 | if ( lse ) |
410 | deleteIncidence ( lse ); | 429 | deleteIncidence ( lse ); |
411 | } | 430 | } |
412 | } | 431 | } |
413 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() | 432 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() |
414 | { | 433 | { |
415 | QPtrList<Event> el; | 434 | QPtrList<Event> el; |
416 | Event *todo; | 435 | Event *todo; |
417 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 436 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
418 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 437 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
419 | if ( todo->summary().left(3) == "E: " ) | 438 | if ( todo->summary().left(3) == "E: " ) |
420 | el.append( todo ); | 439 | el.append( todo ); |
421 | } | 440 | } |
422 | 441 | ||
423 | return el; | 442 | return el; |
424 | 443 | ||
425 | } | 444 | } |
426 | Event *CalendarLocal::event( QString syncProf, QString id ) | 445 | Event *CalendarLocal::event( QString syncProf, QString id ) |
427 | { | 446 | { |
428 | Event *todo; | 447 | Event *todo; |
429 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 448 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
430 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; | 449 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; |
431 | } | 450 | } |
432 | 451 | ||
433 | return 0; | 452 | return 0; |
434 | } | 453 | } |
435 | Todo *CalendarLocal::todo( const QString &uid ) | 454 | Todo *CalendarLocal::todo( const QString &uid ) |
436 | { | 455 | { |
437 | Todo *todo;; | 456 | Todo *todo;; |
438 | Todo *retVal = 0; | 457 | Todo *retVal = 0; |
439 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 458 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
440 | if ( todo->calEnabled() && todo->uid() == uid ) { | 459 | if ( todo->calEnabled() && todo->uid() == uid ) { |
441 | if ( retVal ) { | 460 | if ( retVal ) { |
442 | if ( retVal->calID() > todo->calID() ) { | 461 | if ( retVal->calID() > todo->calID() ) { |
443 | retVal = todo; | 462 | retVal = todo; |
444 | } | 463 | } |
445 | } else { | 464 | } else { |
446 | retVal = todo; | 465 | retVal = todo; |
447 | } | 466 | } |
448 | } | 467 | } |
449 | } | 468 | } |
450 | return retVal; | 469 | return retVal; |
451 | } | 470 | } |
452 | QString CalendarLocal::nextSummary() const | 471 | QString CalendarLocal::nextSummary() const |
453 | { | 472 | { |
454 | return mNextSummary; | 473 | return mNextSummary; |
455 | } | 474 | } |
456 | QDateTime CalendarLocal::nextAlarmEventDateTime() const | 475 | QDateTime CalendarLocal::nextAlarmEventDateTime() const |
457 | { | 476 | { |
458 | return mNextAlarmEventDateTime; | 477 | return mNextAlarmEventDateTime; |
459 | } | 478 | } |
460 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) | 479 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) |
461 | { | 480 | { |
462 | //mNextAlarmIncidence | 481 | //mNextAlarmIncidence |
463 | //mNextAlarmDateTime | 482 | //mNextAlarmDateTime |
464 | //return mNextSummary; | 483 | //return mNextSummary; |
465 | //return mNextAlarmEventDateTime; | 484 | //return mNextAlarmEventDateTime; |
466 | bool newNextAlarm = false; | 485 | bool newNextAlarm = false; |
467 | bool computeNextAlarm = false; | 486 | bool computeNextAlarm = false; |
468 | bool ok; | 487 | bool ok; |
469 | int offset; | 488 | int offset; |
470 | QDateTime nextA; | 489 | QDateTime nextA; |
471 | // QString nextSum; | 490 | // QString nextSum; |
472 | //QDateTime nextEvent; | 491 | //QDateTime nextEvent; |
473 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { | 492 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { |
474 | computeNextAlarm = true; | 493 | computeNextAlarm = true; |
475 | } else { | 494 | } else { |
476 | if ( ! deleted ) { | 495 | if ( ! deleted ) { |
477 | nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; | 496 | nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; |
478 | if ( ok ) { | 497 | if ( ok ) { |
479 | if ( nextA < mNextAlarmDateTime ) { | 498 | if ( nextA < mNextAlarmDateTime ) { |
480 | deRegisterAlarm(); | 499 | deRegisterAlarm(); |
481 | mNextAlarmDateTime = nextA; | 500 | mNextAlarmDateTime = nextA; |
482 | mNextSummary = incidence->summary(); | 501 | mNextSummary = incidence->summary(); |
483 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; | 502 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; |
484 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 503 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
485 | newNextAlarm = true; | 504 | newNextAlarm = true; |
486 | mNextAlarmIncidence = incidence; | 505 | mNextAlarmIncidence = incidence; |
487 | } else { | 506 | } else { |
488 | if ( incidence == mNextAlarmIncidence ) { | 507 | if ( incidence == mNextAlarmIncidence ) { |
489 | computeNextAlarm = true; | 508 | computeNextAlarm = true; |
490 | } | 509 | } |
491 | } | 510 | } |
492 | } else { | 511 | } else { |
493 | if ( mNextAlarmIncidence == incidence ) { | 512 | if ( mNextAlarmIncidence == incidence ) { |
494 | computeNextAlarm = true; | 513 | computeNextAlarm = true; |
495 | } | 514 | } |
496 | } | 515 | } |
497 | } else { // deleted | 516 | } else { // deleted |
498 | if ( incidence == mNextAlarmIncidence ) { | 517 | if ( incidence == mNextAlarmIncidence ) { |
499 | computeNextAlarm = true; | 518 | computeNextAlarm = true; |
500 | } | 519 | } |
501 | } | 520 | } |
502 | } | 521 | } |
503 | if ( computeNextAlarm ) { | 522 | if ( computeNextAlarm ) { |
504 | deRegisterAlarm(); | 523 | deRegisterAlarm(); |
505 | nextA = nextAlarm( 1000 ); | 524 | nextA = nextAlarm( 1000 ); |
506 | if (! mNextAlarmIncidence ) { | 525 | if (! mNextAlarmIncidence ) { |
507 | return; | 526 | return; |
508 | } | 527 | } |
509 | newNextAlarm = true; | 528 | newNextAlarm = true; |
510 | } | 529 | } |
511 | if ( newNextAlarm ) | 530 | if ( newNextAlarm ) |
512 | registerAlarm(); | 531 | registerAlarm(); |
513 | } | 532 | } |
514 | QString CalendarLocal:: getAlarmNotification() | 533 | QString CalendarLocal:: getAlarmNotification() |
515 | { | 534 | { |
516 | QString ret; | 535 | QString ret; |
517 | // this should not happen | 536 | // this should not happen |
518 | if (! mNextAlarmIncidence ) | 537 | if (! mNextAlarmIncidence ) |
519 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; | 538 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; |
520 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); | 539 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); |
521 | if ( alarm->type() == Alarm::Procedure ) { | 540 | if ( alarm->type() == Alarm::Procedure ) { |
522 | ret = "proc_alarm" + alarm->programFile()+"+++"; | 541 | ret = "proc_alarm" + alarm->programFile()+"+++"; |
523 | } else { | 542 | } else { |
524 | ret = "audio_alarm" +alarm->audioFile() +"+++"; | 543 | ret = "audio_alarm" +alarm->audioFile() +"+++"; |
525 | } | 544 | } |
526 | ret += "cal_alarm"+ mNextSummary.left( 25 ); | 545 | ret += "cal_alarm"+ mNextSummary.left( 25 ); |
527 | if ( mNextSummary.length() > 25 ) | 546 | if ( mNextSummary.length() > 25 ) |
528 | ret += "\n" + mNextSummary.mid(25, 25 ); | 547 | ret += "\n" + mNextSummary.mid(25, 25 ); |
529 | ret+= "\n"+mNextAlarmEventDateTimeString; | 548 | ret+= "\n"+mNextAlarmEventDateTimeString; |
530 | return ret; | 549 | return ret; |
531 | } | 550 | } |
532 | void CalendarLocal::registerAlarm() | 551 | void CalendarLocal::registerAlarm() |
533 | { | 552 | { |
534 | mLastAlarmNotificationString = getAlarmNotification(); | 553 | mLastAlarmNotificationString = getAlarmNotification(); |
535 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); | 554 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); |
536 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 555 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
537 | // #ifndef DESKTOP_VERSION | 556 | // #ifndef DESKTOP_VERSION |
538 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); | 557 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); |
539 | // #endif | 558 | // #endif |
540 | } | 559 | } |
541 | void CalendarLocal::deRegisterAlarm() | 560 | void CalendarLocal::deRegisterAlarm() |
542 | { | 561 | { |
543 | if ( mLastAlarmNotificationString.isNull() ) | 562 | if ( mLastAlarmNotificationString.isNull() ) |
544 | return; | 563 | return; |
545 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); | 564 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); |
546 | 565 | ||
547 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 566 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
548 | mNextAlarmEventDateTime = QDateTime(); | 567 | mNextAlarmEventDateTime = QDateTime(); |
549 | // #ifndef DESKTOP_VERSION | 568 | // #ifndef DESKTOP_VERSION |
550 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); | 569 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); |
551 | // #endif | 570 | // #endif |
552 | } | 571 | } |
553 | 572 | ||
554 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) | 573 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) |
555 | { | 574 | { |
556 | QPtrList<Todo> todos; | 575 | QPtrList<Todo> todos; |
557 | 576 | ||
558 | Todo *todo; | 577 | Todo *todo; |
559 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 578 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
560 | if ( !todo->calEnabled() ) continue; | 579 | if ( !todo->calEnabled() ) continue; |
561 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { | 580 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { |
562 | todos.append( todo ); | 581 | todos.append( todo ); |
563 | } | 582 | } |
564 | } | 583 | } |
565 | 584 | ||
566 | filter()->apply( &todos ); | 585 | filter()->apply( &todos ); |
567 | return todos; | 586 | return todos; |
568 | } | 587 | } |
569 | void CalendarLocal::reInitAlarmSettings() | 588 | void CalendarLocal::reInitAlarmSettings() |
570 | { | 589 | { |
571 | if ( !mNextAlarmIncidence ) { | 590 | if ( !mNextAlarmIncidence ) { |
572 | nextAlarm( 1000 ); | 591 | nextAlarm( 1000 ); |
573 | } | 592 | } |
574 | deRegisterAlarm(); | 593 | deRegisterAlarm(); |
575 | mNextAlarmIncidence = 0; | 594 | mNextAlarmIncidence = 0; |
576 | checkAlarmForIncidence( 0, false ); | 595 | checkAlarmForIncidence( 0, false ); |
577 | 596 | ||
578 | } | 597 | } |
579 | 598 | ||
580 | 599 | ||
581 | 600 | ||
582 | QDateTime CalendarLocal::nextAlarm( int daysTo ) | 601 | QDateTime CalendarLocal::nextAlarm( int daysTo ) |
583 | { | 602 | { |
584 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); | 603 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); |
585 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); | 604 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); |
586 | QDateTime next; | 605 | QDateTime next; |
587 | Event *e; | 606 | Event *e; |
588 | bool ok; | 607 | bool ok; |
589 | bool found = false; | 608 | bool found = false; |
590 | int offset; | 609 | int offset; |
591 | mNextAlarmIncidence = 0; | 610 | mNextAlarmIncidence = 0; |
592 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 611 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
593 | if ( !e->calEnabled() ) continue; | 612 | if ( !e->calEnabled() ) continue; |
594 | next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; | 613 | next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; |
595 | if ( ok ) { | 614 | if ( ok ) { |
596 | if ( next < nextA ) { | 615 | if ( next < nextA ) { |
597 | nextA = next; | 616 | nextA = next; |
598 | found = true; | 617 | found = true; |
599 | mNextSummary = e->summary(); | 618 | mNextSummary = e->summary(); |
600 | mNextAlarmEventDateTime = next.addSecs(offset ) ; | 619 | mNextAlarmEventDateTime = next.addSecs(offset ) ; |
601 | mNextAlarmIncidence = (Incidence *) e; | 620 | mNextAlarmIncidence = (Incidence *) e; |
602 | } | 621 | } |
603 | } | 622 | } |
604 | } | 623 | } |
605 | Todo *t; | 624 | Todo *t; |
606 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 625 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
607 | if ( !t->calEnabled() ) continue; | 626 | if ( !t->calEnabled() ) continue; |
608 | next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; | 627 | next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; |
609 | if ( ok ) { | 628 | if ( ok ) { |
610 | if ( next < nextA ) { | 629 | if ( next < nextA ) { |
611 | nextA = next; | 630 | nextA = next; |
612 | found = true; | 631 | found = true; |
613 | mNextSummary = t->summary(); | 632 | mNextSummary = t->summary(); |
614 | mNextAlarmEventDateTime = next.addSecs(offset ); | 633 | mNextAlarmEventDateTime = next.addSecs(offset ); |
615 | mNextAlarmIncidence = (Incidence *) t; | 634 | mNextAlarmIncidence = (Incidence *) t; |
616 | } | 635 | } |
617 | } | 636 | } |
618 | } | 637 | } |
619 | if ( mNextAlarmIncidence ) { | 638 | if ( mNextAlarmIncidence ) { |
620 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 639 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
621 | mNextAlarmDateTime = nextA; | 640 | mNextAlarmDateTime = nextA; |
622 | } | 641 | } |
623 | return nextA; | 642 | return nextA; |
624 | } | 643 | } |
625 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) | 644 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) |
626 | { | 645 | { |
627 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); | 646 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); |
628 | } | 647 | } |
629 | 648 | ||
630 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) | 649 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) |
631 | { | 650 | { |
632 | 651 | ||
633 | Alarm::List alarms; | 652 | Alarm::List alarms; |
634 | 653 | ||
635 | Event *e; | 654 | Event *e; |
636 | 655 | ||
637 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 656 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
638 | if ( !e->calEnabled() ) continue; | 657 | if ( !e->calEnabled() ) continue; |
639 | if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); | 658 | if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); |
640 | else appendAlarms( alarms, e, from, to ); | 659 | else appendAlarms( alarms, e, from, to ); |
641 | } | 660 | } |
642 | 661 | ||
643 | Todo *t; | 662 | Todo *t; |
644 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 663 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
645 | if ( !t->calEnabled() ) continue; | 664 | if ( !t->calEnabled() ) continue; |
646 | appendAlarms( alarms, t, from, to ); | 665 | appendAlarms( alarms, t, from, to ); |
647 | } | 666 | } |
648 | 667 | ||
649 | return alarms; | 668 | return alarms; |
650 | } | 669 | } |
651 | 670 | ||
652 | void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, | 671 | void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, |
653 | const QDateTime &from, const QDateTime &to ) | 672 | const QDateTime &from, const QDateTime &to ) |
654 | { | 673 | { |
655 | QPtrList<Alarm> alarmList = incidence->alarms(); | 674 | QPtrList<Alarm> alarmList = incidence->alarms(); |
656 | Alarm *alarm; | 675 | Alarm *alarm; |
657 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { | 676 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { |
658 | // kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() | 677 | // kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() |
659 | // << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; | 678 | // << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; |
660 | if ( alarm->enabled() ) { | 679 | if ( alarm->enabled() ) { |
661 | if ( alarm->time() >= from && alarm->time() <= to ) { | 680 | if ( alarm->time() >= from && alarm->time() <= to ) { |
662 | alarms.append( alarm ); | 681 | alarms.append( alarm ); |
663 | } | 682 | } |
664 | } | 683 | } |
665 | } | 684 | } |
666 | } | 685 | } |
667 | 686 | ||
668 | void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, | 687 | void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, |
669 | Incidence *incidence, | 688 | Incidence *incidence, |
670 | const QDateTime &from, | 689 | const QDateTime &from, |
671 | const QDateTime &to ) | 690 | const QDateTime &to ) |
672 | { | 691 | { |
673 | 692 | ||
674 | QPtrList<Alarm> alarmList = incidence->alarms(); | 693 | QPtrList<Alarm> alarmList = incidence->alarms(); |
675 | Alarm *alarm; | 694 | Alarm *alarm; |
676 | QDateTime qdt; | 695 | QDateTime qdt; |
677 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { | 696 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { |
678 | if (incidence->recursOn(from.date())) { | 697 | if (incidence->recursOn(from.date())) { |
679 | qdt.setTime(alarm->time().time()); | 698 | qdt.setTime(alarm->time().time()); |
680 | qdt.setDate(from.date()); | 699 | qdt.setDate(from.date()); |
681 | } | 700 | } |
682 | else qdt = alarm->time(); | 701 | else qdt = alarm->time(); |
683 | // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); | 702 | // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); |
684 | if ( alarm->enabled() ) { | 703 | if ( alarm->enabled() ) { |
685 | if ( qdt >= from && qdt <= to ) { | 704 | if ( qdt >= from && qdt <= to ) { |
686 | alarms.append( alarm ); | 705 | alarms.append( alarm ); |
687 | } | 706 | } |
688 | } | 707 | } |
689 | } | 708 | } |
690 | } | 709 | } |
691 | 710 | ||
692 | 711 | ||
693 | /****************************** PROTECTED METHODS ****************************/ | 712 | /****************************** PROTECTED METHODS ****************************/ |
694 | 713 | ||
695 | // after changes are made to an event, this should be called. | 714 | // after changes are made to an event, this should be called. |
696 | void CalendarLocal::update( IncidenceBase *incidence ) | 715 | void CalendarLocal::update( IncidenceBase *incidence ) |
697 | { | 716 | { |
698 | incidence->setSyncStatus( Event::SYNCMOD ); | 717 | incidence->setSyncStatus( Event::SYNCMOD ); |
699 | incidence->setLastModified( QDateTime::currentDateTime() ); | 718 | incidence->setLastModified( QDateTime::currentDateTime() ); |
700 | // we should probably update the revision number here, | 719 | // we should probably update the revision number here, |
701 | // or internally in the Event itself when certain things change. | 720 | // or internally in the Event itself when certain things change. |
702 | // need to verify with ical documentation. | 721 | // need to verify with ical documentation. |
703 | 722 | ||
704 | setModified( true ); | 723 | setModified( true ); |
705 | } | 724 | } |
706 | 725 | ||
707 | void CalendarLocal::insertEvent( Event *event ) | 726 | void CalendarLocal::insertEvent( Event *event ) |
708 | { | 727 | { |
709 | if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); | 728 | if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); |
710 | } | 729 | } |
711 | 730 | ||
712 | 731 | ||
713 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) | 732 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) |
714 | { | 733 | { |
715 | QPtrList<Event> eventList; | 734 | QPtrList<Event> eventList; |
716 | 735 | ||
717 | Event *event; | 736 | Event *event; |
718 | for( event = mEventList.first(); event; event = mEventList.next() ) { | 737 | for( event = mEventList.first(); event; event = mEventList.next() ) { |
719 | if ( !event->calEnabled() ) continue; | 738 | if ( !event->calEnabled() ) continue; |
720 | if ( event->doesRecur() ) { | 739 | if ( event->doesRecur() ) { |
721 | if ( event->isMultiDay() ) { | 740 | if ( event->isMultiDay() ) { |
722 | int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); | 741 | int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); |
723 | int i; | 742 | int i; |
724 | for ( i = 0; i <= extraDays; i++ ) { | 743 | for ( i = 0; i <= extraDays; i++ ) { |
725 | if ( event->recursOn( qd.addDays( -i ) ) ) { | 744 | if ( event->recursOn( qd.addDays( -i ) ) ) { |
726 | eventList.append( event ); | 745 | eventList.append( event ); |
727 | break; | 746 | break; |
728 | } | 747 | } |
729 | } | 748 | } |
730 | } else { | 749 | } else { |
731 | if ( event->recursOn( qd ) ) | 750 | if ( event->recursOn( qd ) ) |
732 | eventList.append( event ); | 751 | eventList.append( event ); |
733 | } | 752 | } |
734 | } else { | 753 | } else { |
735 | if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { | 754 | if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { |
736 | eventList.append( event ); | 755 | eventList.append( event ); |
737 | } | 756 | } |
738 | } | 757 | } |
739 | } | 758 | } |
740 | 759 | ||
741 | if ( !sorted ) { | 760 | if ( !sorted ) { |
742 | return eventList; | 761 | return eventList; |
743 | } | 762 | } |
744 | 763 | ||
745 | // kdDebug(5800) << "Sorting events for date\n" << endl; | 764 | // kdDebug(5800) << "Sorting events for date\n" << endl; |
746 | // now, we have to sort it based on dtStart.time() | 765 | // now, we have to sort it based on dtStart.time() |
747 | QPtrList<Event> eventListSorted; | 766 | QPtrList<Event> eventListSorted; |
748 | Event *sortEvent; | 767 | Event *sortEvent; |
749 | for ( event = eventList.first(); event; event = eventList.next() ) { | 768 | for ( event = eventList.first(); event; event = eventList.next() ) { |
750 | sortEvent = eventListSorted.first(); | 769 | sortEvent = eventListSorted.first(); |
751 | int i = 0; | 770 | int i = 0; |
752 | while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) | 771 | while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) |
753 | { | 772 | { |
754 | i++; | 773 | i++; |
755 | sortEvent = eventListSorted.next(); | 774 | sortEvent = eventListSorted.next(); |
756 | } | 775 | } |
757 | eventListSorted.insert( i, event ); | 776 | eventListSorted.insert( i, event ); |
758 | } | 777 | } |
759 | return eventListSorted; | 778 | return eventListSorted; |
760 | } | 779 | } |
761 | 780 | ||
762 | 781 | ||
763 | QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, | 782 | QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, |
764 | bool inclusive ) | 783 | bool inclusive ) |
765 | { | 784 | { |
766 | Event *event = 0; | 785 | Event *event = 0; |
767 | 786 | ||
768 | QPtrList<Event> eventList; | 787 | QPtrList<Event> eventList; |
769 | 788 | ||
770 | // Get non-recurring events | 789 | // Get non-recurring events |
771 | for( event = mEventList.first(); event; event = mEventList.next() ) { | 790 | for( event = mEventList.first(); event; event = mEventList.next() ) { |
772 | if ( !event->calEnabled() ) continue; | 791 | if ( !event->calEnabled() ) continue; |
773 | if ( event->doesRecur() ) { | 792 | if ( event->doesRecur() ) { |
774 | QDate rStart = event->dtStart().date(); | 793 | QDate rStart = event->dtStart().date(); |
775 | bool found = false; | 794 | bool found = false; |
776 | if ( inclusive ) { | 795 | if ( inclusive ) { |
777 | if ( rStart >= start && rStart <= end ) { | 796 | if ( rStart >= start && rStart <= end ) { |
778 | // Start date of event is in range. Now check for end date. | 797 | // Start date of event is in range. Now check for end date. |
779 | // if duration is negative, event recurs forever, so do not include it. | 798 | // if duration is negative, event recurs forever, so do not include it. |
780 | if ( event->recurrence()->duration() == 0 ) { // End date set | 799 | if ( event->recurrence()->duration() == 0 ) { // End date set |
781 | QDate rEnd = event->recurrence()->endDate(); | 800 | QDate rEnd = event->recurrence()->endDate(); |
782 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 801 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
783 | found = true; | 802 | found = true; |
784 | } | 803 | } |
785 | } else if ( event->recurrence()->duration() > 0 ) { // Duration set | 804 | } else if ( event->recurrence()->duration() > 0 ) { // Duration set |
786 | // TODO: Calculate end date from duration. Should be done in Event | 805 | // TODO: Calculate end date from duration. Should be done in Event |
787 | // For now exclude all events with a duration. | 806 | // For now exclude all events with a duration. |
788 | } | 807 | } |
789 | } | 808 | } |
790 | } else { | 809 | } else { |
791 | bool founOne; | 810 | bool founOne; |
792 | QDate next = event->getNextOccurence( start, &founOne ).date(); | 811 | QDate next = event->getNextOccurence( start, &founOne ).date(); |
793 | if ( founOne ) { | 812 | if ( founOne ) { |
794 | if ( next <= end ) { | 813 | if ( next <= end ) { |
795 | found = true; | 814 | found = true; |
796 | } | 815 | } |
797 | } | 816 | } |
798 | 817 | ||
799 | /* | 818 | /* |
800 | // crap !!! | 819 | // crap !!! |
801 | if ( rStart <= end ) { // Start date not after range | 820 | if ( rStart <= end ) { // Start date not after range |
802 | if ( rStart >= start ) { // Start date within range | 821 | if ( rStart >= start ) { // Start date within range |
803 | found = true; | 822 | found = true; |
804 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever | 823 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever |
805 | found = true; | 824 | found = true; |
806 | } else if ( event->recurrence()->duration() == 0 ) { // End date set | 825 | } else if ( event->recurrence()->duration() == 0 ) { // End date set |
807 | QDate rEnd = event->recurrence()->endDate(); | 826 | QDate rEnd = event->recurrence()->endDate(); |
808 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 827 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
809 | found = true; | 828 | found = true; |
810 | } | 829 | } |
811 | } else { // Duration set | 830 | } else { // Duration set |
812 | // TODO: Calculate end date from duration. Should be done in Event | 831 | // TODO: Calculate end date from duration. Should be done in Event |
813 | // For now include all events with a duration. | 832 | // For now include all events with a duration. |
814 | found = true; | 833 | found = true; |
815 | } | 834 | } |
816 | } | 835 | } |
817 | */ | 836 | */ |
818 | 837 | ||
819 | } | 838 | } |
820 | 839 | ||
821 | if ( found ) eventList.append( event ); | 840 | if ( found ) eventList.append( event ); |
822 | } else { | 841 | } else { |
823 | QDate s = event->dtStart().date(); | 842 | QDate s = event->dtStart().date(); |
824 | QDate e = event->dtEnd().date(); | 843 | QDate e = event->dtEnd().date(); |
825 | 844 | ||
826 | if ( inclusive ) { | 845 | if ( inclusive ) { |
827 | if ( s >= start && e <= end ) { | 846 | if ( s >= start && e <= end ) { |
828 | eventList.append( event ); | 847 | eventList.append( event ); |
829 | } | 848 | } |
830 | } else { | 849 | } else { |
831 | if ( ( e >= start && s <= end ) ) { | 850 | if ( ( e >= start && s <= end ) ) { |
832 | eventList.append( event ); | 851 | eventList.append( event ); |
833 | } | 852 | } |
834 | } | 853 | } |
835 | } | 854 | } |
836 | } | 855 | } |
837 | 856 | ||
838 | return eventList; | 857 | return eventList; |
839 | } | 858 | } |
840 | 859 | ||
841 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) | 860 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) |
842 | { | 861 | { |
843 | return rawEventsForDate( qdt.date() ); | 862 | return rawEventsForDate( qdt.date() ); |
844 | } | 863 | } |
845 | 864 | ||
846 | QPtrList<Event> CalendarLocal::rawEvents() | 865 | QPtrList<Event> CalendarLocal::rawEvents() |
847 | { | 866 | { |
848 | QPtrList<Event> el; | 867 | QPtrList<Event> el; |
849 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 868 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
850 | if ( it->calEnabled() ) el.append( it ); | 869 | if ( it->calEnabled() ) el.append( it ); |
851 | return el; | 870 | return el; |
852 | } | 871 | } |
853 | 872 | ||
854 | bool CalendarLocal::addJournal(Journal *journal) | 873 | bool CalendarLocal::addJournal(Journal *journal) |
855 | { | 874 | { |
856 | mJournalList.append(journal); | 875 | mJournalList.append(journal); |
857 | 876 | ||
858 | journal->registerObserver( this ); | 877 | journal->registerObserver( this ); |
859 | 878 | ||
860 | setModified( true ); | 879 | setModified( true ); |
861 | if ( journal->calID() == 0 ) | 880 | if ( journal->calID() == 0 ) |
862 | journal->setCalID( mDefaultCalendar ); | 881 | journal->setCalID( mDefaultCalendar ); |
863 | journal->setCalEnabled( true ); | 882 | journal->setCalEnabled( true ); |
864 | return true; | 883 | return true; |
865 | } | 884 | } |
866 | 885 | ||
867 | void CalendarLocal::deleteJournal( Journal *journal ) | 886 | void CalendarLocal::deleteJournal( Journal *journal ) |
868 | { | 887 | { |
869 | if ( mUndoIncidence ) delete mUndoIncidence; | 888 | if ( mUndoIncidence ) delete mUndoIncidence; |
870 | mUndoIncidence = journal->clone(); | 889 | mUndoIncidence = journal->clone(); |
871 | mUndoIncidence->setSummary( mUndoIncidence->description().left(25)); | 890 | mUndoIncidence->setSummary( mUndoIncidence->description().left(25)); |
872 | if ( mJournalList.removeRef(journal) ) { | 891 | if ( mJournalList.removeRef(journal) ) { |
873 | setModified( true ); | 892 | setModified( true ); |
874 | } | 893 | } |
875 | } | 894 | } |
876 | 895 | ||
877 | QPtrList<Journal> CalendarLocal::journals4Date( const QDate & date ) | 896 | QPtrList<Journal> CalendarLocal::journals4Date( const QDate & date ) |
878 | { | 897 | { |
879 | QPtrList<Journal> el; | 898 | QPtrList<Journal> el; |
880 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 899 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
881 | if ( it->calEnabled() && it->dtStart().date() == date) el.append( it ); | 900 | if ( it->calEnabled() && it->dtStart().date() == date) el.append( it ); |
882 | return el; | 901 | return el; |
883 | } | 902 | } |
884 | Journal *CalendarLocal::journal( const QDate &date ) | 903 | Journal *CalendarLocal::journal( const QDate &date ) |
885 | { | 904 | { |
886 | // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; | 905 | // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; |
887 | 906 | ||
888 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 907 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
889 | if ( it->calEnabled() && it->dtStart().date() == date ) | 908 | if ( it->calEnabled() && it->dtStart().date() == date ) |
890 | return it; | 909 | return it; |
891 | 910 | ||
892 | return 0; | 911 | return 0; |
893 | } | 912 | } |
894 | 913 | ||
895 | Journal *CalendarLocal::journal( const QString &uid ) | 914 | Journal *CalendarLocal::journal( const QString &uid ) |
896 | { | 915 | { |
897 | Journal * retVal = 0; | 916 | Journal * retVal = 0; |
898 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 917 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
899 | if ( it->calEnabled() && it->uid() == uid ) { | 918 | if ( it->calEnabled() && it->uid() == uid ) { |
900 | if ( retVal ) { | 919 | if ( retVal ) { |
901 | if ( retVal->calID() > it->calID() ) { | 920 | if ( retVal->calID() > it->calID() ) { |
902 | retVal = it; | 921 | retVal = it; |
903 | } | 922 | } |
904 | } else { | 923 | } else { |
905 | retVal = it; | 924 | retVal = it; |
906 | } | 925 | } |
907 | } | 926 | } |
908 | return retVal; | 927 | return retVal; |
909 | } | 928 | } |
910 | 929 | ||
911 | QPtrList<Journal> CalendarLocal::journals() | 930 | QPtrList<Journal> CalendarLocal::journals() |
912 | { | 931 | { |
913 | QPtrList<Journal> el; | 932 | QPtrList<Journal> el; |
diff --git a/libkcal/calendarlocal.h b/libkcal/calendarlocal.h index 23b0542..a7a85c8 100644 --- a/libkcal/calendarlocal.h +++ b/libkcal/calendarlocal.h | |||
@@ -1,230 +1,230 @@ | |||
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 | #ifndef KCAL_CALENDARLOCAL_H | 22 | #ifndef KCAL_CALENDARLOCAL_H |
23 | #define KCAL_CALENDARLOCAL_H | 23 | #define KCAL_CALENDARLOCAL_H |
24 | 24 | ||
25 | #include "calendar.h" | 25 | #include "calendar.h" |
26 | 26 | ||
27 | namespace KCal { | 27 | namespace KCal { |
28 | 28 | ||
29 | class CalFormat; | 29 | class CalFormat; |
30 | 30 | ||
31 | /** | 31 | /** |
32 | This class provides a calendar stored as a local file. | 32 | This class provides a calendar stored as a local file. |
33 | */ | 33 | */ |
34 | class CalendarLocal : public Calendar | 34 | class CalendarLocal : public Calendar |
35 | { | 35 | { |
36 | public: | 36 | public: |
37 | /** | 37 | /** |
38 | Constructs a new calendar, with variables initialized to sane values. | 38 | Constructs a new calendar, with variables initialized to sane values. |
39 | */ | 39 | */ |
40 | CalendarLocal(); | 40 | CalendarLocal(); |
41 | /** | 41 | /** |
42 | Constructs a new calendar, with variables initialized to sane values. | 42 | Constructs a new calendar, with variables initialized to sane values. |
43 | */ | 43 | */ |
44 | CalendarLocal( const QString &timeZoneId ); | 44 | CalendarLocal( const QString &timeZoneId ); |
45 | ~CalendarLocal(); | 45 | ~CalendarLocal(); |
46 | void addCalendar( Calendar* ); | 46 | void addCalendar( Calendar* ); |
47 | bool addCalendarFile( QString name, int id ); | 47 | bool addCalendarFile( QString name, int id ); |
48 | bool mergeCalendarFile( QString name ); | 48 | bool mergeCalendarFile( QString name ); |
49 | bool mergeCalendar( Calendar* cal ); | 49 | bool mergeCalendar( Calendar* cal ); |
50 | Incidence* incidenceForUid( const QString& uid ); | 50 | Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates ); |
51 | void setSyncEventsReadOnly(); | 51 | void setSyncEventsReadOnly(); |
52 | void stopAllTodos(); | 52 | void stopAllTodos(); |
53 | /** | 53 | /** |
54 | Loads a calendar on disk in vCalendar or iCalendar format into the current | 54 | Loads a calendar on disk in vCalendar or iCalendar format into the current |
55 | calendar. Any information already present is lost. | 55 | calendar. Any information already present is lost. |
56 | @return true, if successfull, false on error. | 56 | @return true, if successfull, false on error. |
57 | @param fileName the name of the calendar on disk. | 57 | @param fileName the name of the calendar on disk. |
58 | */ | 58 | */ |
59 | bool load( const QString &fileName ); | 59 | bool load( const QString &fileName ); |
60 | /** | 60 | /** |
61 | Writes out the calendar to disk in the specified \a format. | 61 | Writes out the calendar to disk in the specified \a format. |
62 | CalendarLocal takes ownership of the CalFormat object. | 62 | CalendarLocal takes ownership of the CalFormat object. |
63 | @return true, if successfull, false on error. | 63 | @return true, if successfull, false on error. |
64 | @param fileName the name of the file | 64 | @param fileName the name of the file |
65 | */ | 65 | */ |
66 | bool save( const QString &fileName, CalFormat *format = 0 ); | 66 | bool save( const QString &fileName, CalFormat *format = 0 ); |
67 | 67 | ||
68 | /** | 68 | /** |
69 | Clears out the current calendar, freeing all used memory etc. etc. | 69 | Clears out the current calendar, freeing all used memory etc. etc. |
70 | */ | 70 | */ |
71 | void close(); | 71 | void close(); |
72 | 72 | ||
73 | void save() {} | 73 | void save() {} |
74 | 74 | ||
75 | /** | 75 | /** |
76 | Add Event to calendar. | 76 | Add Event to calendar. |
77 | */ | 77 | */ |
78 | void removeSyncInfo( QString syncProfile); | 78 | void removeSyncInfo( QString syncProfile); |
79 | bool addAnniversaryNoDup( Event *event ); | 79 | bool addAnniversaryNoDup( Event *event ); |
80 | bool addEventNoDup( Event *event ); | 80 | bool addEventNoDup( Event *event ); |
81 | bool addEvent( Event *event ); | 81 | bool addEvent( Event *event ); |
82 | /** | 82 | /** |
83 | Deletes an event from this calendar. | 83 | Deletes an event from this calendar. |
84 | */ | 84 | */ |
85 | void deleteEvent( Event *event ); | 85 | void deleteEvent( Event *event ); |
86 | 86 | ||
87 | /** | 87 | /** |
88 | Retrieves an event on the basis of the unique string ID. | 88 | Retrieves an event on the basis of the unique string ID. |
89 | */ | 89 | */ |
90 | Event *event( const QString &uid ); | 90 | Event *event( const QString &uid ); |
91 | /** | 91 | /** |
92 | Return unfiltered list of all events in calendar. | 92 | Return unfiltered list of all events in calendar. |
93 | */ | 93 | */ |
94 | QPtrList<Event> rawEvents(); | 94 | QPtrList<Event> rawEvents(); |
95 | QPtrList<Event> getExternLastSyncEvents(); | 95 | QPtrList<Event> getExternLastSyncEvents(); |
96 | /** | 96 | /** |
97 | Add a todo to the todolist. | 97 | Add a todo to the todolist. |
98 | */ | 98 | */ |
99 | bool addTodo( Todo *todo ); | 99 | bool addTodo( Todo *todo ); |
100 | bool addTodoNoDup( Todo *todo ); | 100 | bool addTodoNoDup( Todo *todo ); |
101 | /** | 101 | /** |
102 | Remove a todo from the todolist. | 102 | Remove a todo from the todolist. |
103 | */ | 103 | */ |
104 | void deleteTodo( Todo * ); | 104 | void deleteTodo( Todo * ); |
105 | /** | 105 | /** |
106 | Searches todolist for an event with this unique string identifier, | 106 | Searches todolist for an event with this unique string identifier, |
107 | returns a pointer or null. | 107 | returns a pointer or null. |
108 | */ | 108 | */ |
109 | Todo *todo( const QString &uid ); | 109 | Todo *todo( const QString &uid ); |
110 | /** | 110 | /** |
111 | Return list of all todos. | 111 | Return list of all todos. |
112 | */ | 112 | */ |
113 | QPtrList<Todo> rawTodos(); | 113 | QPtrList<Todo> rawTodos(); |
114 | /** | 114 | /** |
115 | Returns list of todos due on the specified date. | 115 | Returns list of todos due on the specified date. |
116 | */ | 116 | */ |
117 | QPtrList<Todo> todos( const QDate &date ); | 117 | QPtrList<Todo> todos( const QDate &date ); |
118 | /** | 118 | /** |
119 | Return list of all todos. | 119 | Return list of all todos. |
120 | 120 | ||
121 | Workaround because compiler does not recognize function of base class. | 121 | Workaround because compiler does not recognize function of base class. |
122 | */ | 122 | */ |
123 | QPtrList<Todo> todos() { return Calendar::todos(); } | 123 | QPtrList<Todo> todos() { return Calendar::todos(); } |
124 | 124 | ||
125 | /** | 125 | /** |
126 | Add a Journal entry to calendar. | 126 | Add a Journal entry to calendar. |
127 | */ | 127 | */ |
128 | bool addJournal( Journal * ); | 128 | bool addJournal( Journal * ); |
129 | /** | 129 | /** |
130 | Remove a Journal from the calendar. | 130 | Remove a Journal from the calendar. |
131 | */ | 131 | */ |
132 | void deleteJournal( Journal * ); | 132 | void deleteJournal( Journal * ); |
133 | /** | 133 | /** |
134 | Return Journal for given date. | 134 | Return Journal for given date. |
135 | */ | 135 | */ |
136 | Journal *journal( const QDate & ); | 136 | Journal *journal( const QDate & ); |
137 | QPtrList<Journal> journals4Date( const QDate & ); | 137 | QPtrList<Journal> journals4Date( const QDate & ); |
138 | /** | 138 | /** |
139 | Return Journal with given UID. | 139 | Return Journal with given UID. |
140 | */ | 140 | */ |
141 | Journal *journal( const QString &uid ); | 141 | Journal *journal( const QString &uid ); |
142 | /** | 142 | /** |
143 | Return list of all Journals stored in calendar. | 143 | Return list of all Journals stored in calendar. |
144 | */ | 144 | */ |
145 | QPtrList<Journal> journals(); | 145 | QPtrList<Journal> journals(); |
146 | 146 | ||
147 | /** | 147 | /** |
148 | Return all alarms, which ocur in the given time interval. | 148 | Return all alarms, which ocur in the given time interval. |
149 | */ | 149 | */ |
150 | Alarm::List alarms( const QDateTime &from, const QDateTime &to ); | 150 | Alarm::List alarms( const QDateTime &from, const QDateTime &to ); |
151 | 151 | ||
152 | /** | 152 | /** |
153 | Return all alarms, which ocur before given date. | 153 | Return all alarms, which ocur before given date. |
154 | */ | 154 | */ |
155 | Alarm::List alarmsTo( const QDateTime &to ); | 155 | Alarm::List alarmsTo( const QDateTime &to ); |
156 | 156 | ||
157 | QDateTime nextAlarm( int daysTo ) ; | 157 | QDateTime nextAlarm( int daysTo ) ; |
158 | QDateTime nextAlarmEventDateTime() const; | 158 | QDateTime nextAlarmEventDateTime() const; |
159 | void checkAlarmForIncidence( Incidence *, bool deleted ) ; | 159 | void checkAlarmForIncidence( Incidence *, bool deleted ) ; |
160 | void registerAlarm(); | 160 | void registerAlarm(); |
161 | void deRegisterAlarm(); | 161 | void deRegisterAlarm(); |
162 | QString getAlarmNotification(); | 162 | QString getAlarmNotification(); |
163 | QString nextSummary() const ; | 163 | QString nextSummary() const ; |
164 | /** | 164 | /** |
165 | This method should be called whenever a Event is modified directly | 165 | This method should be called whenever a Event is modified directly |
166 | via it's pointer. It makes sure that the calendar is internally | 166 | via it's pointer. It makes sure that the calendar is internally |
167 | consistent. | 167 | consistent. |
168 | */ | 168 | */ |
169 | void update( IncidenceBase *incidence ); | 169 | void update( IncidenceBase *incidence ); |
170 | 170 | ||
171 | /** | 171 | /** |
172 | Builds and then returns a list of all events that match for the | 172 | Builds and then returns a list of all events that match for the |
173 | date specified. useful for dayView, etc. etc. | 173 | date specified. useful for dayView, etc. etc. |
174 | */ | 174 | */ |
175 | QPtrList<Event> rawEventsForDate( const QDate &date, bool sorted = false ); | 175 | QPtrList<Event> rawEventsForDate( const QDate &date, bool sorted = false ); |
176 | /** | 176 | /** |
177 | Get unfiltered events for date \a qdt. | 177 | Get unfiltered events for date \a qdt. |
178 | */ | 178 | */ |
179 | QPtrList<Event> rawEventsForDate( const QDateTime &qdt ); | 179 | QPtrList<Event> rawEventsForDate( const QDateTime &qdt ); |
180 | /** | 180 | /** |
181 | Get unfiltered events in a range of dates. If inclusive is set to true, | 181 | Get unfiltered events in a range of dates. If inclusive is set to true, |
182 | only events are returned, which are completely included in the range. | 182 | only events are returned, which are completely included in the range. |
183 | */ | 183 | */ |
184 | QPtrList<Event> rawEvents( const QDate &start, const QDate &end, | 184 | QPtrList<Event> rawEvents( const QDate &start, const QDate &end, |
185 | bool inclusive = false ); | 185 | bool inclusive = false ); |
186 | Todo *todo( QString, QString ); | 186 | Todo *todo( QString, QString ); |
187 | Event *event( QString, QString ); | 187 | Event *event( QString, QString ); |
188 | 188 | ||
189 | public slots: | 189 | public slots: |
190 | void setCalendarEnabled( int id, bool enable ); | 190 | void setCalendarEnabled( int id, bool enable ); |
191 | void setAlarmEnabled( int id, bool enable ); | 191 | void setAlarmEnabled( int id, bool enable ); |
192 | void setReadOnly( int id, bool enable ); | 192 | void setReadOnly( int id, bool enable ); |
193 | void setDefaultCalendarEnabledOnly(); | 193 | void setDefaultCalendarEnabledOnly(); |
194 | void setCalendarRemove( int id ); | 194 | void setCalendarRemove( int id ); |
195 | 195 | ||
196 | protected: | 196 | protected: |
197 | 197 | ||
198 | // Event* mNextAlarmEvent; | 198 | // Event* mNextAlarmEvent; |
199 | QString mNextSummary; | 199 | QString mNextSummary; |
200 | QString mNextAlarmEventDateTimeString; | 200 | QString mNextAlarmEventDateTimeString; |
201 | QString mLastAlarmNotificationString; | 201 | QString mLastAlarmNotificationString; |
202 | QDateTime mNextAlarmEventDateTime; | 202 | QDateTime mNextAlarmEventDateTime; |
203 | QDateTime mNextAlarmDateTime; | 203 | QDateTime mNextAlarmDateTime; |
204 | void reInitAlarmSettings(); | 204 | void reInitAlarmSettings(); |
205 | 205 | ||
206 | /** Notification function of IncidenceBase::Observer. */ | 206 | /** Notification function of IncidenceBase::Observer. */ |
207 | void incidenceUpdated( IncidenceBase *i ) { update( i ); } | 207 | void incidenceUpdated( IncidenceBase *i ) { update( i ); } |
208 | 208 | ||
209 | /** inserts an event into its "proper place" in the calendar. */ | 209 | /** inserts an event into its "proper place" in the calendar. */ |
210 | void insertEvent( Event *event ); | 210 | void insertEvent( Event *event ); |
211 | 211 | ||
212 | /** Append alarms of incidence in interval to list of alarms. */ | 212 | /** Append alarms of incidence in interval to list of alarms. */ |
213 | void appendAlarms( Alarm::List &alarms, Incidence *incidence, | 213 | void appendAlarms( Alarm::List &alarms, Incidence *incidence, |
214 | const QDateTime &from, const QDateTime &to ); | 214 | const QDateTime &from, const QDateTime &to ); |
215 | 215 | ||
216 | /** Append alarms of recurring events in interval to list of alarms. */ | 216 | /** Append alarms of recurring events in interval to list of alarms. */ |
217 | void appendRecurringAlarms( Alarm::List &alarms, Incidence *incidence, | 217 | void appendRecurringAlarms( Alarm::List &alarms, Incidence *incidence, |
218 | const QDateTime &from, const QDateTime &to ); | 218 | const QDateTime &from, const QDateTime &to ); |
219 | 219 | ||
220 | private: | 220 | private: |
221 | void init(); | 221 | void init(); |
222 | 222 | ||
223 | QPtrList<Event> mEventList; | 223 | QPtrList<Event> mEventList; |
224 | QPtrList<Todo> mTodoList; | 224 | QPtrList<Todo> mTodoList; |
225 | QPtrList<Journal> mJournalList; | 225 | QPtrList<Journal> mJournalList; |
226 | }; | 226 | }; |
227 | 227 | ||
228 | } | 228 | } |
229 | 229 | ||
230 | #endif | 230 | #endif |
diff --git a/libkcal/incidencebase.cpp b/libkcal/incidencebase.cpp index dcead02..1a19f3e 100644 --- a/libkcal/incidencebase.cpp +++ b/libkcal/incidencebase.cpp | |||
@@ -1,472 +1,478 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include <kglobal.h> | 21 | #include <kglobal.h> |
22 | #include <klocale.h> | 22 | #include <klocale.h> |
23 | #include <kdebug.h> | 23 | #include <kdebug.h> |
24 | #include <kidmanager.h> | 24 | #include <kidmanager.h> |
25 | 25 | ||
26 | #include "calformat.h" | 26 | #include "calformat.h" |
27 | #include "syncdefines.h" | 27 | #include "syncdefines.h" |
28 | 28 | ||
29 | #include "incidencebase.h" | 29 | #include "incidencebase.h" |
30 | 30 | ||
31 | using namespace KCal; | 31 | using namespace KCal; |
32 | 32 | ||
33 | IncidenceBase::IncidenceBase() : | 33 | IncidenceBase::IncidenceBase() : |
34 | mReadOnly(false), mFloats(true), mDuration(0), mHasDuration(false), | 34 | mReadOnly(false), mFloats(true), mDuration(0), mHasDuration(false), |
35 | mPilotId(0), mSyncStatus(SYNCMOD) | 35 | mPilotId(0), mSyncStatus(SYNCMOD) |
36 | { | 36 | { |
37 | blockLastModified = false; | ||
37 | setUid(CalFormat::createUniqueId()); | 38 | setUid(CalFormat::createUniqueId()); |
38 | mOrganizer = ""; | 39 | mOrganizer = ""; |
39 | mFloats = false; | 40 | mFloats = false; |
40 | mDuration = 0; | 41 | mDuration = 0; |
41 | mHasDuration = false; | 42 | mHasDuration = false; |
42 | mPilotId = 0; | 43 | mPilotId = 0; |
43 | mExternalId = ":"; | 44 | mExternalId = ":"; |
44 | mTempSyncStat = SYNC_TEMPSTATE_INITIAL; | 45 | mTempSyncStat = SYNC_TEMPSTATE_INITIAL; |
45 | mSyncStatus = 0; | 46 | mSyncStatus = 0; |
46 | mAttendees.setAutoDelete( true ); | 47 | mAttendees.setAutoDelete( true ); |
47 | mCalEnabled = true; | 48 | mCalEnabled = true; |
48 | mAlarmEnabled = true; | 49 | mAlarmEnabled = true; |
49 | mCalID = 0; | 50 | mCalID = 0; |
50 | } | 51 | } |
51 | 52 | ||
52 | IncidenceBase::IncidenceBase(const IncidenceBase &i) : | 53 | IncidenceBase::IncidenceBase(const IncidenceBase &i) : |
53 | CustomProperties( i ) | 54 | CustomProperties( i ) |
54 | { | 55 | { |
55 | 56 | ||
57 | blockLastModified = false; | ||
56 | mReadOnly = i.mReadOnly; | 58 | mReadOnly = i.mReadOnly; |
57 | mDtStart = i.mDtStart; | 59 | mDtStart = i.mDtStart; |
58 | mDuration = i.mDuration; | 60 | mDuration = i.mDuration; |
59 | mHasDuration = i.mHasDuration; | 61 | mHasDuration = i.mHasDuration; |
60 | mOrganizer = i.mOrganizer; | 62 | mOrganizer = i.mOrganizer; |
61 | mUid = i.mUid; | 63 | mUid = i.mUid; |
62 | mCalEnabled = i.mCalEnabled; | 64 | mCalEnabled = i.mCalEnabled; |
63 | mAlarmEnabled = i.mAlarmEnabled; | 65 | mAlarmEnabled = i.mAlarmEnabled; |
64 | mCalID = i.mCalID; | 66 | mCalID = i.mCalID; |
65 | QPtrList<Attendee> attendees = i.attendees(); | 67 | QPtrList<Attendee> attendees = i.attendees(); |
66 | for( Attendee *a = attendees.first(); a; a = attendees.next() ) { | 68 | for( Attendee *a = attendees.first(); a; a = attendees.next() ) { |
67 | mAttendees.append( new Attendee( *a ) ); | 69 | mAttendees.append( new Attendee( *a ) ); |
68 | } | 70 | } |
69 | mFloats = i.mFloats; | 71 | mFloats = i.mFloats; |
70 | mLastModified = i.mLastModified; | 72 | mLastModified = i.mLastModified; |
71 | mPilotId = i.mPilotId; | 73 | mPilotId = i.mPilotId; |
72 | mTempSyncStat = i.mTempSyncStat; | 74 | mTempSyncStat = i.mTempSyncStat; |
73 | mSyncStatus = i.mSyncStatus; | 75 | mSyncStatus = i.mSyncStatus; |
74 | mExternalId = i.mExternalId; | 76 | mExternalId = i.mExternalId; |
75 | // The copied object is a new one, so it isn't observed by the observer | 77 | // The copied object is a new one, so it isn't observed by the observer |
76 | // of the original object. | 78 | // of the original object. |
77 | mObservers.clear(); | 79 | mObservers.clear(); |
78 | 80 | ||
79 | mAttendees.setAutoDelete( true ); | 81 | mAttendees.setAutoDelete( true ); |
80 | } | 82 | } |
81 | 83 | ||
82 | IncidenceBase::~IncidenceBase() | 84 | IncidenceBase::~IncidenceBase() |
83 | { | 85 | { |
84 | } | 86 | } |
85 | 87 | ||
86 | 88 | ||
87 | bool KCal::operator==( const IncidenceBase& i1, const IncidenceBase& i2 ) | 89 | bool KCal::operator==( const IncidenceBase& i1, const IncidenceBase& i2 ) |
88 | { | 90 | { |
89 | // do not compare mSyncStatus and mExternalId | 91 | // do not compare mSyncStatus and mExternalId |
90 | if( i1.attendees().count() != i2.attendees().count() ) { | 92 | if( i1.attendees().count() != i2.attendees().count() ) { |
91 | return false; // no need to check further | 93 | return false; // no need to check further |
92 | } | 94 | } |
93 | if ( i1.attendees().count() > 0 ) { | 95 | if ( i1.attendees().count() > 0 ) { |
94 | Attendee * a1 = i1.attendees().first(), *a2 =i2.attendees().first() ; | 96 | Attendee * a1 = i1.attendees().first(), *a2 =i2.attendees().first() ; |
95 | while ( a1 ) { | 97 | while ( a1 ) { |
96 | if ( !( (*a1) == (*a2)) ) | 98 | if ( !( (*a1) == (*a2)) ) |
97 | { | 99 | { |
98 | //qDebug("Attendee not equal "); | 100 | //qDebug("Attendee not equal "); |
99 | return false; | 101 | return false; |
100 | } | 102 | } |
101 | a1 = i1.attendees().next(); | 103 | a1 = i1.attendees().next(); |
102 | a2 = i2.attendees().next(); | 104 | a2 = i2.attendees().next(); |
103 | } | 105 | } |
104 | } | 106 | } |
105 | //if ( i1.dtStart() != i2.dtStart() ) | 107 | //if ( i1.dtStart() != i2.dtStart() ) |
106 | // return false; | 108 | // return false; |
107 | #if 0 | 109 | #if 0 |
108 | qDebug("1 %d ",i1.doesFloat() == i2.doesFloat() ); | 110 | qDebug("1 %d ",i1.doesFloat() == i2.doesFloat() ); |
109 | qDebug("1 %d ",i1.duration() == i2.duration() ); | 111 | qDebug("1 %d ",i1.duration() == i2.duration() ); |
110 | qDebug("3 %d ",i1.hasDuration() == i2.hasDuration() ); | 112 | qDebug("3 %d ",i1.hasDuration() == i2.hasDuration() ); |
111 | qDebug("1 %d ",i1.pilotId() == i2.pilotId() ); | 113 | qDebug("1 %d ",i1.pilotId() == i2.pilotId() ); |
112 | qDebug("1 %d %d %d",i1.syncStatus() == i2.syncStatus() , i1.syncStatus(),i2.syncStatus() ); | 114 | qDebug("1 %d %d %d",i1.syncStatus() == i2.syncStatus() , i1.syncStatus(),i2.syncStatus() ); |
113 | qDebug("6 %d ",i1.organizer() == i2.organizer() ); | 115 | qDebug("6 %d ",i1.organizer() == i2.organizer() ); |
114 | 116 | ||
115 | #endif | 117 | #endif |
116 | if ( i1.hasDuration() == i2.hasDuration() ) { | 118 | if ( i1.hasDuration() == i2.hasDuration() ) { |
117 | if ( i1.hasDuration() ) { | 119 | if ( i1.hasDuration() ) { |
118 | if ( i1.duration() != i2.duration() ) | 120 | if ( i1.duration() != i2.duration() ) |
119 | return false; | 121 | return false; |
120 | } | 122 | } |
121 | } else { | 123 | } else { |
122 | return false; | 124 | return false; |
123 | } | 125 | } |
124 | 126 | ||
125 | return ( i1.organizer() == i2.organizer() && | 127 | return ( i1.organizer() == i2.organizer() && |
126 | // i1.uid() == i2.uid() && | 128 | // i1.uid() == i2.uid() && |
127 | // Don't compare lastModified, otherwise the operator is not | 129 | // Don't compare lastModified, otherwise the operator is not |
128 | // of much use. We are not comparing for identity, after all. | 130 | // of much use. We are not comparing for identity, after all. |
129 | i1.doesFloat() == i2.doesFloat() && | 131 | i1.doesFloat() == i2.doesFloat() && |
130 | i1.pilotId() == i2.pilotId() );// && i1.syncStatus() == i2.syncStatus() ); | 132 | i1.pilotId() == i2.pilotId() );// && i1.syncStatus() == i2.syncStatus() ); |
131 | // no need to compare mObserver | 133 | // no need to compare mObserver |
132 | } | 134 | } |
133 | 135 | ||
134 | 136 | ||
135 | QDateTime IncidenceBase::getEvenTime( QDateTime dt ) | 137 | QDateTime IncidenceBase::getEvenTime( QDateTime dt ) |
136 | { | 138 | { |
137 | QTime t = dt.time(); | 139 | QTime t = dt.time(); |
138 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 140 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
139 | return dt; | 141 | return dt; |
140 | } | 142 | } |
141 | 143 | ||
142 | bool IncidenceBase::isTagged() const | 144 | bool IncidenceBase::isTagged() const |
143 | { | 145 | { |
144 | return mIsTagged; | 146 | return mIsTagged; |
145 | } | 147 | } |
146 | void IncidenceBase::setTagged( bool b) | 148 | void IncidenceBase::setTagged( bool b) |
147 | { | 149 | { |
148 | mIsTagged = b; | 150 | mIsTagged = b; |
149 | } | 151 | } |
150 | void IncidenceBase::setCalID( int id ) | 152 | void IncidenceBase::setCalID( int id ) |
151 | { | 153 | { |
152 | if ( mCalID > 0 ) | 154 | if ( mCalID > 0 ) { |
155 | blockLastModified = true; | ||
153 | updated(); | 156 | updated(); |
157 | blockLastModified = false; | ||
158 | } | ||
154 | mCalID = id; | 159 | mCalID = id; |
155 | } | 160 | } |
156 | int IncidenceBase::calID() const | 161 | int IncidenceBase::calID() const |
157 | { | 162 | { |
158 | return mCalID; | 163 | return mCalID; |
159 | } | 164 | } |
160 | void IncidenceBase::setCalEnabled( bool b ) | 165 | void IncidenceBase::setCalEnabled( bool b ) |
161 | { | 166 | { |
162 | mCalEnabled = b; | 167 | mCalEnabled = b; |
163 | } | 168 | } |
164 | bool IncidenceBase::calEnabled() const | 169 | bool IncidenceBase::calEnabled() const |
165 | { | 170 | { |
166 | return mCalEnabled; | 171 | return mCalEnabled; |
167 | } | 172 | } |
168 | 173 | ||
169 | void IncidenceBase::setAlarmEnabled( bool b ) | 174 | void IncidenceBase::setAlarmEnabled( bool b ) |
170 | { | 175 | { |
171 | mAlarmEnabled = b; | 176 | mAlarmEnabled = b; |
172 | } | 177 | } |
173 | bool IncidenceBase::alarmEnabled() const | 178 | bool IncidenceBase::alarmEnabled() const |
174 | { | 179 | { |
175 | return mAlarmEnabled; | 180 | return mAlarmEnabled; |
176 | } | 181 | } |
177 | 182 | ||
178 | 183 | ||
179 | void IncidenceBase::setUid(const QString &uid) | 184 | void IncidenceBase::setUid(const QString &uid) |
180 | { | 185 | { |
181 | mUid = uid; | 186 | mUid = uid; |
182 | updated(); | 187 | updated(); |
183 | } | 188 | } |
184 | 189 | ||
185 | QString IncidenceBase::uid() const | 190 | QString IncidenceBase::uid() const |
186 | { | 191 | { |
187 | return mUid; | 192 | return mUid; |
188 | } | 193 | } |
189 | 194 | ||
190 | void IncidenceBase::setLastModified(const QDateTime &lm) | 195 | void IncidenceBase::setLastModified(const QDateTime &lm) |
191 | { | 196 | { |
197 | if ( blockLastModified ) return; | ||
192 | // DON'T! updated() because we call this from | 198 | // DON'T! updated() because we call this from |
193 | // Calendar::updateEvent(). | 199 | // Calendar::updateEvent(). |
194 | mLastModified = getEvenTime(lm); | 200 | mLastModified = getEvenTime(lm); |
195 | //qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1()); | 201 | //qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1()); |
196 | } | 202 | } |
197 | 203 | ||
198 | QDateTime IncidenceBase::lastModified() const | 204 | QDateTime IncidenceBase::lastModified() const |
199 | { | 205 | { |
200 | return mLastModified; | 206 | return mLastModified; |
201 | } | 207 | } |
202 | 208 | ||
203 | void IncidenceBase::setOrganizer(const QString &o) | 209 | void IncidenceBase::setOrganizer(const QString &o) |
204 | { | 210 | { |
205 | // we don't check for readonly here, because it is | 211 | // we don't check for readonly here, because it is |
206 | // possible that by setting the organizer we are changing | 212 | // possible that by setting the organizer we are changing |
207 | // the event's readonly status... | 213 | // the event's readonly status... |
208 | mOrganizer = o; | 214 | mOrganizer = o; |
209 | if (mOrganizer.left(7).upper() == "MAILTO:") | 215 | if (mOrganizer.left(7).upper() == "MAILTO:") |
210 | mOrganizer = mOrganizer.remove(0,7); | 216 | mOrganizer = mOrganizer.remove(0,7); |
211 | 217 | ||
212 | updated(); | 218 | updated(); |
213 | } | 219 | } |
214 | 220 | ||
215 | QString IncidenceBase::organizer() const | 221 | QString IncidenceBase::organizer() const |
216 | { | 222 | { |
217 | return mOrganizer; | 223 | return mOrganizer; |
218 | } | 224 | } |
219 | 225 | ||
220 | void IncidenceBase::setReadOnly( bool readOnly ) | 226 | void IncidenceBase::setReadOnly( bool readOnly ) |
221 | { | 227 | { |
222 | mReadOnly = readOnly; | 228 | mReadOnly = readOnly; |
223 | } | 229 | } |
224 | 230 | ||
225 | void IncidenceBase::setDtStart(const QDateTime &dtStart) | 231 | void IncidenceBase::setDtStart(const QDateTime &dtStart) |
226 | { | 232 | { |
227 | // if (mReadOnly) return; | 233 | // if (mReadOnly) return; |
228 | mDtStart = getEvenTime(dtStart); | 234 | mDtStart = getEvenTime(dtStart); |
229 | updated(); | 235 | updated(); |
230 | } | 236 | } |
231 | 237 | ||
232 | 238 | ||
233 | QDateTime IncidenceBase::dtStart() const | 239 | QDateTime IncidenceBase::dtStart() const |
234 | { | 240 | { |
235 | return mDtStart; | 241 | return mDtStart; |
236 | } | 242 | } |
237 | 243 | ||
238 | QString IncidenceBase::dtStartTimeStr() const | 244 | QString IncidenceBase::dtStartTimeStr() const |
239 | { | 245 | { |
240 | return KGlobal::locale()->formatTime(dtStart().time()); | 246 | return KGlobal::locale()->formatTime(dtStart().time()); |
241 | } | 247 | } |
242 | 248 | ||
243 | QString IncidenceBase::dtStartDateStr(bool shortfmt) const | 249 | QString IncidenceBase::dtStartDateStr(bool shortfmt) const |
244 | { | 250 | { |
245 | return KGlobal::locale()->formatDate(dtStart().date(),shortfmt); | 251 | return KGlobal::locale()->formatDate(dtStart().date(),shortfmt); |
246 | } | 252 | } |
247 | 253 | ||
248 | QString IncidenceBase::dtStartStr(bool shortfmt) const | 254 | QString IncidenceBase::dtStartStr(bool shortfmt) const |
249 | { | 255 | { |
250 | if ( doesFloat() ) | 256 | if ( doesFloat() ) |
251 | return KGlobal::locale()->formatDate(dtStart().date(),shortfmt); | 257 | return KGlobal::locale()->formatDate(dtStart().date(),shortfmt); |
252 | return KGlobal::locale()->formatDateTime(dtStart(), shortfmt); | 258 | return KGlobal::locale()->formatDateTime(dtStart(), shortfmt); |
253 | } | 259 | } |
254 | 260 | ||
255 | 261 | ||
256 | bool IncidenceBase::doesFloat() const | 262 | bool IncidenceBase::doesFloat() const |
257 | { | 263 | { |
258 | return mFloats; | 264 | return mFloats; |
259 | } | 265 | } |
260 | 266 | ||
261 | void IncidenceBase::setFloats(bool f) | 267 | void IncidenceBase::setFloats(bool f) |
262 | { | 268 | { |
263 | if (mReadOnly) return; | 269 | if (mReadOnly) return; |
264 | mFloats = f; | 270 | mFloats = f; |
265 | updated(); | 271 | updated(); |
266 | } | 272 | } |
267 | 273 | ||
268 | 274 | ||
269 | bool IncidenceBase::addAttendee(Attendee *a, bool doupdate) | 275 | bool IncidenceBase::addAttendee(Attendee *a, bool doupdate) |
270 | { | 276 | { |
271 | if (mReadOnly) return false; | 277 | if (mReadOnly) return false; |
272 | if (a->name().left(7).upper() == "MAILTO:") | 278 | if (a->name().left(7).upper() == "MAILTO:") |
273 | a->setName(a->name().remove(0,7)); | 279 | a->setName(a->name().remove(0,7)); |
274 | 280 | ||
275 | QPtrListIterator<Attendee> qli(mAttendees); | 281 | QPtrListIterator<Attendee> qli(mAttendees); |
276 | 282 | ||
277 | qli.toFirst(); | 283 | qli.toFirst(); |
278 | while (qli) { | 284 | while (qli) { |
279 | if (*qli.current() == *a) | 285 | if (*qli.current() == *a) |
280 | return false; | 286 | return false; |
281 | ++qli; | 287 | ++qli; |
282 | } | 288 | } |
283 | mAttendees.append(a); | 289 | mAttendees.append(a); |
284 | if (doupdate) updated(); | 290 | if (doupdate) updated(); |
285 | return true; | 291 | return true; |
286 | } | 292 | } |
287 | 293 | ||
288 | #if 0 | 294 | #if 0 |
289 | void IncidenceBase::removeAttendee(Attendee *a) | 295 | void IncidenceBase::removeAttendee(Attendee *a) |
290 | { | 296 | { |
291 | if (mReadOnly) return; | 297 | if (mReadOnly) return; |
292 | mAttendees.removeRef(a); | 298 | mAttendees.removeRef(a); |
293 | updated(); | 299 | updated(); |
294 | } | 300 | } |
295 | 301 | ||
296 | void IncidenceBase::removeAttendee(const char *n) | 302 | void IncidenceBase::removeAttendee(const char *n) |
297 | { | 303 | { |
298 | Attendee *a; | 304 | Attendee *a; |
299 | 305 | ||
300 | if (mReadOnly) return; | 306 | if (mReadOnly) return; |
301 | for (a = mAttendees.first(); a; a = mAttendees.next()) | 307 | for (a = mAttendees.first(); a; a = mAttendees.next()) |
302 | if (a->getName() == n) { | 308 | if (a->getName() == n) { |
303 | mAttendees.remove(); | 309 | mAttendees.remove(); |
304 | break; | 310 | break; |
305 | } | 311 | } |
306 | } | 312 | } |
307 | #endif | 313 | #endif |
308 | 314 | ||
309 | void IncidenceBase::clearAttendees() | 315 | void IncidenceBase::clearAttendees() |
310 | { | 316 | { |
311 | if (mReadOnly) return; | 317 | if (mReadOnly) return; |
312 | mAttendees.clear(); | 318 | mAttendees.clear(); |
313 | } | 319 | } |
314 | 320 | ||
315 | #if 0 | 321 | #if 0 |
316 | Attendee *IncidenceBase::getAttendee(const char *n) const | 322 | Attendee *IncidenceBase::getAttendee(const char *n) const |
317 | { | 323 | { |
318 | QPtrListIterator<Attendee> qli(mAttendees); | 324 | QPtrListIterator<Attendee> qli(mAttendees); |
319 | 325 | ||
320 | qli.toFirst(); | 326 | qli.toFirst(); |
321 | while (qli) { | 327 | while (qli) { |
322 | if (qli.current()->getName() == n) | 328 | if (qli.current()->getName() == n) |
323 | return qli.current(); | 329 | return qli.current(); |
324 | ++qli; | 330 | ++qli; |
325 | } | 331 | } |
326 | return 0L; | 332 | return 0L; |
327 | } | 333 | } |
328 | #endif | 334 | #endif |
329 | 335 | ||
330 | Attendee *IncidenceBase::attendeeByMail(const QString &email) | 336 | Attendee *IncidenceBase::attendeeByMail(const QString &email) |
331 | { | 337 | { |
332 | QPtrListIterator<Attendee> qli(mAttendees); | 338 | QPtrListIterator<Attendee> qli(mAttendees); |
333 | 339 | ||
334 | qli.toFirst(); | 340 | qli.toFirst(); |
335 | while (qli) { | 341 | while (qli) { |
336 | if (qli.current()->email().lower() == email.lower()) | 342 | if (qli.current()->email().lower() == email.lower()) |
337 | return qli.current(); | 343 | return qli.current(); |
338 | ++qli; | 344 | ++qli; |
339 | } | 345 | } |
340 | return 0L; | 346 | return 0L; |
341 | } | 347 | } |
342 | 348 | ||
343 | Attendee *IncidenceBase::attendeeByMails(const QStringList &emails, const QString& email) | 349 | Attendee *IncidenceBase::attendeeByMails(const QStringList &emails, const QString& email) |
344 | { | 350 | { |
345 | QPtrListIterator<Attendee> qli(mAttendees); | 351 | QPtrListIterator<Attendee> qli(mAttendees); |
346 | 352 | ||
347 | QStringList mails = emails; | 353 | QStringList mails = emails; |
348 | if (!email.isEmpty()) { | 354 | if (!email.isEmpty()) { |
349 | mails.append(email); | 355 | mails.append(email); |
350 | } | 356 | } |
351 | qli.toFirst(); | 357 | qli.toFirst(); |
352 | while (qli) { | 358 | while (qli) { |
353 | for ( QStringList::Iterator it = mails.begin(); it != mails.end(); ++it ) { | 359 | for ( QStringList::Iterator it = mails.begin(); it != mails.end(); ++it ) { |
354 | if (qli.current()->email().lower() == (*it).lower()) | 360 | if (qli.current()->email().lower() == (*it).lower()) |
355 | return qli.current(); | 361 | return qli.current(); |
356 | } | 362 | } |
357 | 363 | ||
358 | ++qli; | 364 | ++qli; |
359 | } | 365 | } |
360 | return 0L; | 366 | return 0L; |
361 | } | 367 | } |
362 | 368 | ||
363 | void IncidenceBase::setDuration(int seconds) | 369 | void IncidenceBase::setDuration(int seconds) |
364 | { | 370 | { |
365 | mDuration = seconds; | 371 | mDuration = seconds; |
366 | setHasDuration(true); | 372 | setHasDuration(true); |
367 | } | 373 | } |
368 | 374 | ||
369 | int IncidenceBase::duration() const | 375 | int IncidenceBase::duration() const |
370 | { | 376 | { |
371 | return mDuration; | 377 | return mDuration; |
372 | } | 378 | } |
373 | 379 | ||
374 | void IncidenceBase::setHasDuration(bool b) | 380 | void IncidenceBase::setHasDuration(bool b) |
375 | { | 381 | { |
376 | mHasDuration = b; | 382 | mHasDuration = b; |
377 | } | 383 | } |
378 | 384 | ||
379 | bool IncidenceBase::hasDuration() const | 385 | bool IncidenceBase::hasDuration() const |
380 | { | 386 | { |
381 | return mHasDuration; | 387 | return mHasDuration; |
382 | } | 388 | } |
383 | 389 | ||
384 | void IncidenceBase::setSyncStatus(int stat) | 390 | void IncidenceBase::setSyncStatus(int stat) |
385 | { | 391 | { |
386 | if (mReadOnly) return; | 392 | if (mReadOnly) return; |
387 | mSyncStatus = stat; | 393 | mSyncStatus = stat; |
388 | } | 394 | } |
389 | 395 | ||
390 | int IncidenceBase::syncStatus() const | 396 | int IncidenceBase::syncStatus() const |
391 | { | 397 | { |
392 | return mSyncStatus; | 398 | return mSyncStatus; |
393 | } | 399 | } |
394 | 400 | ||
395 | void IncidenceBase::setPilotId( int id ) | 401 | void IncidenceBase::setPilotId( int id ) |
396 | { | 402 | { |
397 | if (mReadOnly) return; | 403 | if (mReadOnly) return; |
398 | mPilotId = id; | 404 | mPilotId = id; |
399 | } | 405 | } |
400 | 406 | ||
401 | int IncidenceBase::pilotId() const | 407 | int IncidenceBase::pilotId() const |
402 | { | 408 | { |
403 | return mPilotId; | 409 | return mPilotId; |
404 | } | 410 | } |
405 | 411 | ||
406 | int IncidenceBase::tempSyncStat() const | 412 | int IncidenceBase::tempSyncStat() const |
407 | { | 413 | { |
408 | return mTempSyncStat; | 414 | return mTempSyncStat; |
409 | } | 415 | } |
410 | void IncidenceBase::setTempSyncStat( int id ) | 416 | void IncidenceBase::setTempSyncStat( int id ) |
411 | { | 417 | { |
412 | if (mReadOnly) return; | 418 | if (mReadOnly) return; |
413 | mTempSyncStat = id; | 419 | mTempSyncStat = id; |
414 | } | 420 | } |
415 | 421 | ||
416 | void IncidenceBase::removeID(const QString &prof) | 422 | void IncidenceBase::removeID(const QString &prof) |
417 | { | 423 | { |
418 | if ( prof.isEmpty() ) | 424 | if ( prof.isEmpty() ) |
419 | mExternalId = ":"; | 425 | mExternalId = ":"; |
420 | else | 426 | else |
421 | mExternalId = KIdManager::removeId ( mExternalId, prof); | 427 | mExternalId = KIdManager::removeId ( mExternalId, prof); |
422 | 428 | ||
423 | } | 429 | } |
424 | void IncidenceBase::setID( const QString & prof , const QString & id ) | 430 | void IncidenceBase::setID( const QString & prof , const QString & id ) |
425 | { | 431 | { |
426 | mExternalId = KIdManager::setId ( mExternalId, prof, id ); | 432 | mExternalId = KIdManager::setId ( mExternalId, prof, id ); |
427 | } | 433 | } |
428 | QString IncidenceBase::getID( const QString & prof) | 434 | QString IncidenceBase::getID( const QString & prof) |
429 | { | 435 | { |
430 | return KIdManager::getId ( mExternalId, prof ); | 436 | return KIdManager::getId ( mExternalId, prof ); |
431 | } | 437 | } |
432 | 438 | ||
433 | // example :Sharp_DTM;22;23566:TP;-1;8654:TPP;18;0: | 439 | // example :Sharp_DTM;22;23566:TP;-1;8654:TPP;18;0: |
434 | // format name;III;JJJ: III >= 0, may be -1. JJJ always >= 0 | 440 | // format name;III;JJJ: III >= 0, may be -1. JJJ always >= 0 |
435 | void IncidenceBase::setCsum( const QString & prof , const QString & id ) | 441 | void IncidenceBase::setCsum( const QString & prof , const QString & id ) |
436 | { | 442 | { |
437 | mExternalId = KIdManager::setCsum ( mExternalId, prof, id ); | 443 | mExternalId = KIdManager::setCsum ( mExternalId, prof, id ); |
438 | } | 444 | } |
439 | QString IncidenceBase::getCsum( const QString & prof) | 445 | QString IncidenceBase::getCsum( const QString & prof) |
440 | { | 446 | { |
441 | return KIdManager::getCsum ( mExternalId, prof ); | 447 | return KIdManager::getCsum ( mExternalId, prof ); |
442 | } | 448 | } |
443 | 449 | ||
444 | void IncidenceBase::setIDStr( const QString & s ) | 450 | void IncidenceBase::setIDStr( const QString & s ) |
445 | { | 451 | { |
446 | if (mReadOnly) return; | 452 | if (mReadOnly) return; |
447 | mExternalId = s; | 453 | mExternalId = s; |
448 | } | 454 | } |
449 | 455 | ||
450 | QString IncidenceBase::IDStr() const | 456 | QString IncidenceBase::IDStr() const |
451 | { | 457 | { |
452 | return mExternalId ; | 458 | return mExternalId ; |
453 | } | 459 | } |
454 | void IncidenceBase::registerObserver( IncidenceBase::Observer *observer ) | 460 | void IncidenceBase::registerObserver( IncidenceBase::Observer *observer ) |
455 | { | 461 | { |
456 | if( !mObservers.contains(observer) ) mObservers.append( observer ); | 462 | if( !mObservers.contains(observer) ) mObservers.append( observer ); |
457 | } | 463 | } |
458 | 464 | ||
459 | void IncidenceBase::unRegisterObserver( IncidenceBase::Observer *observer ) | 465 | void IncidenceBase::unRegisterObserver( IncidenceBase::Observer *observer ) |
460 | { | 466 | { |
461 | mObservers.remove( observer ); | 467 | mObservers.remove( observer ); |
462 | } | 468 | } |
463 | 469 | ||
464 | void IncidenceBase::updated() | 470 | void IncidenceBase::updated() |
465 | { | 471 | { |
466 | QPtrListIterator<Observer> it(mObservers); | 472 | QPtrListIterator<Observer> it(mObservers); |
467 | while( it.current() ) { | 473 | while( it.current() ) { |
468 | Observer *o = it.current(); | 474 | Observer *o = it.current(); |
469 | ++it; | 475 | ++it; |
470 | o->incidenceUpdated( this ); | 476 | o->incidenceUpdated( this ); |
471 | } | 477 | } |
472 | } | 478 | } |
diff --git a/libkcal/incidencebase.h b/libkcal/incidencebase.h index bccf287..bed73db 100644 --- a/libkcal/incidencebase.h +++ b/libkcal/incidencebase.h | |||
@@ -1,185 +1,186 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | #ifndef KCAL_INCIDENCEBASE_H | 20 | #ifndef KCAL_INCIDENCEBASE_H |
21 | #define KCAL_INCIDENCEBASE_H | 21 | #define KCAL_INCIDENCEBASE_H |
22 | // | 22 | // |
23 | // Incidence - base class of calendaring components | 23 | // Incidence - base class of calendaring components |
24 | // | 24 | // |
25 | 25 | ||
26 | #include <qdatetime.h> | 26 | #include <qdatetime.h> |
27 | #include <qstringlist.h> | 27 | #include <qstringlist.h> |
28 | #include <qvaluelist.h> | 28 | #include <qvaluelist.h> |
29 | #include <qptrlist.h> | 29 | #include <qptrlist.h> |
30 | 30 | ||
31 | #include "customproperties.h" | 31 | #include "customproperties.h" |
32 | #include "attendee.h" | 32 | #include "attendee.h" |
33 | 33 | ||
34 | namespace KCal { | 34 | namespace KCal { |
35 | 35 | ||
36 | typedef QValueList<QDate> DateList; | 36 | typedef QValueList<QDate> DateList; |
37 | enum IncTypeID { eventID,todoID,journalID,freebusyID }; | 37 | enum IncTypeID { eventID,todoID,journalID,freebusyID }; |
38 | 38 | ||
39 | /** | 39 | /** |
40 | This class provides the base class common to all calendar components. | 40 | This class provides the base class common to all calendar components. |
41 | */ | 41 | */ |
42 | class IncidenceBase : public CustomProperties | 42 | class IncidenceBase : public CustomProperties |
43 | { | 43 | { |
44 | public: | 44 | public: |
45 | class Observer { | 45 | class Observer { |
46 | public: | 46 | public: |
47 | virtual void incidenceUpdated( IncidenceBase * ) = 0; | 47 | virtual void incidenceUpdated( IncidenceBase * ) = 0; |
48 | }; | 48 | }; |
49 | 49 | ||
50 | IncidenceBase(); | 50 | IncidenceBase(); |
51 | IncidenceBase(const IncidenceBase &); | 51 | IncidenceBase(const IncidenceBase &); |
52 | virtual ~IncidenceBase(); | 52 | virtual ~IncidenceBase(); |
53 | 53 | ||
54 | virtual QCString type() const = 0; | 54 | virtual QCString type() const = 0; |
55 | virtual IncTypeID typeID() const = 0; | 55 | virtual IncTypeID typeID() const = 0; |
56 | 56 | ||
57 | /** Set the unique id for the event */ | 57 | /** Set the unique id for the event */ |
58 | void setUid(const QString &); | 58 | void setUid(const QString &); |
59 | /** Return the unique id for the event */ | 59 | /** Return the unique id for the event */ |
60 | QString uid() const; | 60 | QString uid() const; |
61 | 61 | ||
62 | /** Sets the time the incidence was last modified. */ | 62 | /** Sets the time the incidence was last modified. */ |
63 | void setLastModified(const QDateTime &lm); | 63 | void setLastModified(const QDateTime &lm); |
64 | /** Return the time the incidence was last modified. */ | 64 | /** Return the time the incidence was last modified. */ |
65 | QDateTime lastModified() const; | 65 | QDateTime lastModified() const; |
66 | 66 | ||
67 | /** sets the organizer for the event */ | 67 | /** sets the organizer for the event */ |
68 | void setOrganizer(const QString &o); | 68 | void setOrganizer(const QString &o); |
69 | QString organizer() const; | 69 | QString organizer() const; |
70 | 70 | ||
71 | /** Set readonly status. */ | 71 | /** Set readonly status. */ |
72 | virtual void setReadOnly( bool ); | 72 | virtual void setReadOnly( bool ); |
73 | /** Return if the object is read-only. */ | 73 | /** Return if the object is read-only. */ |
74 | bool isReadOnly() const { return mReadOnly; } | 74 | bool isReadOnly() const { return mReadOnly; } |
75 | 75 | ||
76 | /** for setting the event's starting date/time with a QDateTime. */ | 76 | /** for setting the event's starting date/time with a QDateTime. */ |
77 | virtual void setDtStart(const QDateTime &dtStart); | 77 | virtual void setDtStart(const QDateTime &dtStart); |
78 | /** returns an event's starting date/time as a QDateTime. */ | 78 | /** returns an event's starting date/time as a QDateTime. */ |
79 | virtual QDateTime dtStart() const; | 79 | virtual QDateTime dtStart() const; |
80 | /** returns an event's starting time as a string formatted according to the | 80 | /** returns an event's starting time as a string formatted according to the |
81 | users locale settings */ | 81 | users locale settings */ |
82 | QString dtStartTimeStr() const; | 82 | QString dtStartTimeStr() const; |
83 | /** returns an event's starting date as a string formatted according to the | 83 | /** returns an event's starting date as a string formatted according to the |
84 | users locale settings */ | 84 | users locale settings */ |
85 | QString dtStartDateStr(bool shortfmt=true) const; | 85 | QString dtStartDateStr(bool shortfmt=true) const; |
86 | /** returns an event's starting date and time as a string formatted according | 86 | /** returns an event's starting date and time as a string formatted according |
87 | to the users locale settings */ | 87 | to the users locale settings */ |
88 | QString dtStartStr(bool shortfmt=true) const; | 88 | QString dtStartStr(bool shortfmt=true) const; |
89 | 89 | ||
90 | virtual void setDuration(int seconds); | 90 | virtual void setDuration(int seconds); |
91 | int duration() const; | 91 | int duration() const; |
92 | void setHasDuration(bool); | 92 | void setHasDuration(bool); |
93 | bool hasDuration() const; | 93 | bool hasDuration() const; |
94 | 94 | ||
95 | /** Return true or false depending on whether the incidence "floats," | 95 | /** Return true or false depending on whether the incidence "floats," |
96 | * i.e. has a date but no time attached to it. */ | 96 | * i.e. has a date but no time attached to it. */ |
97 | bool doesFloat() const; | 97 | bool doesFloat() const; |
98 | /** Set whether the incidence floats, i.e. has a date but no time attached to it. */ | 98 | /** Set whether the incidence floats, i.e. has a date but no time attached to it. */ |
99 | void setFloats(bool f); | 99 | void setFloats(bool f); |
100 | 100 | ||
101 | /** | 101 | /** |
102 | Add Attendee to this incidence. IncidenceBase takes ownership of the | 102 | Add Attendee to this incidence. IncidenceBase takes ownership of the |
103 | Attendee object. | 103 | Attendee object. |
104 | */ | 104 | */ |
105 | bool addAttendee(Attendee *a, bool doupdate=true ); | 105 | bool addAttendee(Attendee *a, bool doupdate=true ); |
106 | // void removeAttendee(Attendee *a); | 106 | // void removeAttendee(Attendee *a); |
107 | // void removeAttendee(const char *n); | 107 | // void removeAttendee(const char *n); |
108 | /** Remove all Attendees. */ | 108 | /** Remove all Attendees. */ |
109 | void clearAttendees(); | 109 | void clearAttendees(); |
110 | /** Return list of attendees. */ | 110 | /** Return list of attendees. */ |
111 | QPtrList<Attendee> attendees() const { return mAttendees; }; | 111 | QPtrList<Attendee> attendees() const { return mAttendees; }; |
112 | /** Return number of attendees. */ | 112 | /** Return number of attendees. */ |
113 | int attendeeCount() const { return mAttendees.count(); }; | 113 | int attendeeCount() const { return mAttendees.count(); }; |
114 | /** Return the Attendee with this email */ | 114 | /** Return the Attendee with this email */ |
115 | Attendee* attendeeByMail(const QString &); | 115 | Attendee* attendeeByMail(const QString &); |
116 | /** Return first Attendee with one of this emails */ | 116 | /** Return first Attendee with one of this emails */ |
117 | Attendee* attendeeByMails(const QStringList &, const QString& email = QString::null); | 117 | Attendee* attendeeByMails(const QStringList &, const QString& email = QString::null); |
118 | 118 | ||
119 | /** pilot syncronization states */ | 119 | /** pilot syncronization states */ |
120 | enum { SYNCNONE = 0, SYNCMOD = 1, SYNCDEL = 3 }; | 120 | enum { SYNCNONE = 0, SYNCMOD = 1, SYNCDEL = 3 }; |
121 | /** Set synchronisation satus. */ | 121 | /** Set synchronisation satus. */ |
122 | void setSyncStatus(int stat); | 122 | void setSyncStatus(int stat); |
123 | /** Return synchronisation status. */ | 123 | /** Return synchronisation status. */ |
124 | int syncStatus() const; | 124 | int syncStatus() const; |
125 | 125 | ||
126 | /** Set Pilot Id. */ | 126 | /** Set Pilot Id. */ |
127 | void setPilotId(int id); | 127 | void setPilotId(int id); |
128 | /** Return Pilot Id. */ | 128 | /** Return Pilot Id. */ |
129 | int pilotId() const; | 129 | int pilotId() const; |
130 | 130 | ||
131 | void setTempSyncStat(int id); | 131 | void setTempSyncStat(int id); |
132 | int tempSyncStat() const; | 132 | int tempSyncStat() const; |
133 | void setIDStr( const QString & ); | 133 | void setIDStr( const QString & ); |
134 | QString IDStr() const; | 134 | QString IDStr() const; |
135 | void setID( const QString &, const QString & ); | 135 | void setID( const QString &, const QString & ); |
136 | QString getID( const QString & ); | 136 | QString getID( const QString & ); |
137 | void setCsum( const QString &, const QString & ); | 137 | void setCsum( const QString &, const QString & ); |
138 | QString getCsum( const QString & ); | 138 | QString getCsum( const QString & ); |
139 | void removeID(const QString &); | 139 | void removeID(const QString &); |
140 | 140 | ||
141 | void registerObserver( Observer * ); | 141 | void registerObserver( Observer * ); |
142 | void unRegisterObserver( Observer * ); | 142 | void unRegisterObserver( Observer * ); |
143 | void updated(); | 143 | void updated(); |
144 | void setCalID( int id ); | 144 | void setCalID( int id ); |
145 | int calID() const; | 145 | int calID() const; |
146 | void setCalEnabled( bool ); | 146 | void setCalEnabled( bool ); |
147 | bool calEnabled() const; | 147 | bool calEnabled() const; |
148 | void setAlarmEnabled( bool ); | 148 | void setAlarmEnabled( bool ); |
149 | bool alarmEnabled() const; | 149 | bool alarmEnabled() const; |
150 | bool isTagged() const; | 150 | bool isTagged() const; |
151 | void setTagged( bool ); | 151 | void setTagged( bool ); |
152 | protected: | 152 | protected: |
153 | bool blockLastModified; | ||
153 | bool mIsTagged; | 154 | bool mIsTagged; |
154 | QDateTime mDtStart; | 155 | QDateTime mDtStart; |
155 | bool mReadOnly; | 156 | bool mReadOnly; |
156 | QDateTime getEvenTime( QDateTime ); | 157 | QDateTime getEvenTime( QDateTime ); |
157 | 158 | ||
158 | private: | 159 | private: |
159 | // base components | 160 | // base components |
160 | QString mOrganizer; | 161 | QString mOrganizer; |
161 | QString mUid; | 162 | QString mUid; |
162 | int mCalID; | 163 | int mCalID; |
163 | bool mCalEnabled; | 164 | bool mCalEnabled; |
164 | bool mAlarmEnabled; | 165 | bool mAlarmEnabled; |
165 | QDateTime mLastModified; | 166 | QDateTime mLastModified; |
166 | QPtrList<Attendee> mAttendees; | 167 | QPtrList<Attendee> mAttendees; |
167 | 168 | ||
168 | bool mFloats; | 169 | bool mFloats; |
169 | 170 | ||
170 | int mDuration; | 171 | int mDuration; |
171 | bool mHasDuration; | 172 | bool mHasDuration; |
172 | QString mExternalId; | 173 | QString mExternalId; |
173 | int mTempSyncStat; | 174 | int mTempSyncStat; |
174 | 175 | ||
175 | // PILOT SYNCHRONIZATION STUFF | 176 | // PILOT SYNCHRONIZATION STUFF |
176 | int mPilotId; // unique id for pilot sync | 177 | int mPilotId; // unique id for pilot sync |
177 | int mSyncStatus; // status (for sync) | 178 | int mSyncStatus; // status (for sync) |
178 | 179 | ||
179 | QPtrList<Observer> mObservers; | 180 | QPtrList<Observer> mObservers; |
180 | }; | 181 | }; |
181 | 182 | ||
182 | bool operator==( const IncidenceBase&, const IncidenceBase& ); | 183 | bool operator==( const IncidenceBase&, const IncidenceBase& ); |
183 | } | 184 | } |
184 | 185 | ||
185 | #endif | 186 | #endif |