-rw-r--r-- | korganizer/calendarview.cpp | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp index 547d02b..7eca69d 100644 --- a/korganizer/calendarview.cpp +++ b/korganizer/calendarview.cpp | |||
@@ -558,768 +558,769 @@ void CalendarView::computeAlarm( QString msg ) | |||
558 | p->start(); | 558 | p->start(); |
559 | return; | 559 | return; |
560 | #endif | 560 | #endif |
561 | 561 | ||
562 | return; | 562 | return; |
563 | } | 563 | } |
564 | 564 | ||
565 | //qDebug("+++++++system command %s ",tempfilename.latin1() ); | 565 | //qDebug("+++++++system command %s ",tempfilename.latin1() ); |
566 | } | 566 | } |
567 | if ( mess.left( 11 ) == "audio_alarm") { | 567 | if ( mess.left( 11 ) == "audio_alarm") { |
568 | bool error = false; | 568 | bool error = false; |
569 | int len = mess.mid( 11 ).find("+++"); | 569 | int len = mess.mid( 11 ).find("+++"); |
570 | if ( len < 2 ) | 570 | if ( len < 2 ) |
571 | error = true; | 571 | error = true; |
572 | else { | 572 | else { |
573 | tempfilename = mess.mid( 11, len ); | 573 | tempfilename = mess.mid( 11, len ); |
574 | if ( !QFile::exists( tempfilename ) ) | 574 | if ( !QFile::exists( tempfilename ) ) |
575 | error = true; | 575 | error = true; |
576 | } | 576 | } |
577 | if ( ! error ) { | 577 | if ( ! error ) { |
578 | filename = tempfilename; | 578 | filename = tempfilename; |
579 | } | 579 | } |
580 | mAlarmMessage = mess.mid( 11+len+3+9 ); | 580 | mAlarmMessage = mess.mid( 11+len+3+9 ); |
581 | //qDebug("audio file command %s ",tempfilename.latin1() ); | 581 | //qDebug("audio file command %s ",tempfilename.latin1() ); |
582 | } | 582 | } |
583 | if ( mess.left( 9 ) == "cal_alarm") { | 583 | if ( mess.left( 9 ) == "cal_alarm") { |
584 | mAlarmMessage = mess.mid( 9 ) ; | 584 | mAlarmMessage = mess.mid( 9 ) ; |
585 | } | 585 | } |
586 | 586 | ||
587 | startAlarm( mAlarmMessage, filename ); | 587 | startAlarm( mAlarmMessage, filename ); |
588 | 588 | ||
589 | 589 | ||
590 | } | 590 | } |
591 | 591 | ||
592 | void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString ¬i ) | 592 | void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString ¬i ) |
593 | { | 593 | { |
594 | //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); | 594 | //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); |
595 | 595 | ||
596 | mSuspendAlarmNotification = noti; | 596 | mSuspendAlarmNotification = noti; |
597 | int ms = QDateTime::currentDateTime().secsTo( qdt )*1000; | 597 | int ms = QDateTime::currentDateTime().secsTo( qdt )*1000; |
598 | //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000); | 598 | //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000); |
599 | mSuspendTimer->start( ms , true ); | 599 | mSuspendTimer->start( ms , true ); |
600 | 600 | ||
601 | } | 601 | } |
602 | 602 | ||
603 | void CalendarView::addAlarm(const QDateTime &qdt, const QString ¬i ) | 603 | void CalendarView::addAlarm(const QDateTime &qdt, const QString ¬i ) |
604 | { | 604 | { |
605 | //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); | 605 | //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); |
606 | if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { | 606 | if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { |
607 | #ifndef DESKTOP_VERSION | 607 | #ifndef DESKTOP_VERSION |
608 | AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() ); | 608 | AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() ); |
609 | #endif | 609 | #endif |
610 | return; | 610 | return; |
611 | } | 611 | } |
612 | int maxSec; | 612 | int maxSec; |
613 | //maxSec = 5; //testing only | 613 | //maxSec = 5; //testing only |
614 | maxSec = 86400+3600; // one day+1hour | 614 | maxSec = 86400+3600; // one day+1hour |
615 | mAlarmNotification = noti; | 615 | mAlarmNotification = noti; |
616 | int sec = QDateTime::currentDateTime().secsTo( qdt ); | 616 | int sec = QDateTime::currentDateTime().secsTo( qdt ); |
617 | if ( sec > maxSec ) { | 617 | if ( sec > maxSec ) { |
618 | mRecheckAlarmTimer->start( maxSec * 1000 ); | 618 | mRecheckAlarmTimer->start( maxSec * 1000 ); |
619 | // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec ); | 619 | // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec ); |
620 | return; | 620 | return; |
621 | } else { | 621 | } else { |
622 | mRecheckAlarmTimer->stop(); | 622 | mRecheckAlarmTimer->stop(); |
623 | } | 623 | } |
624 | //qDebug("Alarm timer started with secs: %d ", sec); | 624 | //qDebug("Alarm timer started with secs: %d ", sec); |
625 | mAlarmTimer->start( sec *1000 , true ); | 625 | mAlarmTimer->start( sec *1000 , true ); |
626 | 626 | ||
627 | } | 627 | } |
628 | // called by mRecheckAlarmTimer to get next alarm | 628 | // called by mRecheckAlarmTimer to get next alarm |
629 | // we need this, because a QTimer has only a max range of 25 days | 629 | // we need this, because a QTimer has only a max range of 25 days |
630 | void CalendarView::recheckTimerAlarm() | 630 | void CalendarView::recheckTimerAlarm() |
631 | { | 631 | { |
632 | mAlarmTimer->stop(); | 632 | mAlarmTimer->stop(); |
633 | mRecheckAlarmTimer->stop(); | 633 | mRecheckAlarmTimer->stop(); |
634 | mCalendar->checkAlarmForIncidence( 0, true ); | 634 | mCalendar->checkAlarmForIncidence( 0, true ); |
635 | } | 635 | } |
636 | void CalendarView::removeAlarm(const QDateTime &qdt, const QString ¬i ) | 636 | void CalendarView::removeAlarm(const QDateTime &qdt, const QString ¬i ) |
637 | { | 637 | { |
638 | //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); | 638 | //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); |
639 | if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { | 639 | if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { |
640 | #ifndef DESKTOP_VERSION | 640 | #ifndef DESKTOP_VERSION |
641 | AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() ); | 641 | AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() ); |
642 | #endif | 642 | #endif |
643 | return; | 643 | return; |
644 | } | 644 | } |
645 | mAlarmTimer->stop(); | 645 | mAlarmTimer->stop(); |
646 | } | 646 | } |
647 | void CalendarView::selectWeekNum ( int num ) | 647 | void CalendarView::selectWeekNum ( int num ) |
648 | { | 648 | { |
649 | dateNavigator()->selectWeek( num ); | 649 | dateNavigator()->selectWeek( num ); |
650 | mViewManager->showWeekView(); | 650 | mViewManager->showWeekView(); |
651 | } | 651 | } |
652 | KOViewManager *CalendarView::viewManager() | 652 | KOViewManager *CalendarView::viewManager() |
653 | { | 653 | { |
654 | return mViewManager; | 654 | return mViewManager; |
655 | } | 655 | } |
656 | 656 | ||
657 | KODialogManager *CalendarView::dialogManager() | 657 | KODialogManager *CalendarView::dialogManager() |
658 | { | 658 | { |
659 | return mDialogManager; | 659 | return mDialogManager; |
660 | } | 660 | } |
661 | 661 | ||
662 | QDate CalendarView::startDate() | 662 | QDate CalendarView::startDate() |
663 | { | 663 | { |
664 | DateList dates = mNavigator->selectedDates(); | 664 | DateList dates = mNavigator->selectedDates(); |
665 | 665 | ||
666 | return dates.first(); | 666 | return dates.first(); |
667 | } | 667 | } |
668 | 668 | ||
669 | QDate CalendarView::endDate() | 669 | QDate CalendarView::endDate() |
670 | { | 670 | { |
671 | DateList dates = mNavigator->selectedDates(); | 671 | DateList dates = mNavigator->selectedDates(); |
672 | 672 | ||
673 | return dates.last(); | 673 | return dates.last(); |
674 | } | 674 | } |
675 | 675 | ||
676 | 676 | ||
677 | void CalendarView::createPrinter() | 677 | void CalendarView::createPrinter() |
678 | { | 678 | { |
679 | #ifndef KORG_NOPRINTER | 679 | #ifndef KORG_NOPRINTER |
680 | if (!mCalPrinter) { | 680 | if (!mCalPrinter) { |
681 | mCalPrinter = new CalPrinter(this, mCalendar); | 681 | mCalPrinter = new CalPrinter(this, mCalendar); |
682 | connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig())); | 682 | connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig())); |
683 | } | 683 | } |
684 | #endif | 684 | #endif |
685 | } | 685 | } |
686 | 686 | ||
687 | void CalendarView::confSync() | 687 | void CalendarView::confSync() |
688 | { | 688 | { |
689 | static KSyncPrefsDialog* sp = 0; | 689 | static KSyncPrefsDialog* sp = 0; |
690 | if ( ! sp ) { | 690 | if ( ! sp ) { |
691 | sp = new KSyncPrefsDialog( this, "syncprefs", true ); | 691 | sp = new KSyncPrefsDialog( this, "syncprefs", true ); |
692 | } | 692 | } |
693 | sp->usrReadConfig(); | 693 | sp->usrReadConfig(); |
694 | #ifndef DESKTOP_VERSION | 694 | #ifndef DESKTOP_VERSION |
695 | sp->showMaximized(); | 695 | sp->showMaximized(); |
696 | #else | 696 | #else |
697 | sp->show(); | 697 | sp->show(); |
698 | #endif | 698 | #endif |
699 | sp->exec(); | 699 | sp->exec(); |
700 | KOPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames(); | 700 | KOPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames(); |
701 | KOPrefs::instance()->mLocalMachineName = sp->getLocalMachineName (); | 701 | KOPrefs::instance()->mLocalMachineName = sp->getLocalMachineName (); |
702 | } | 702 | } |
703 | 703 | ||
704 | 704 | ||
705 | //KOPrefs::instance()->mWriteBackFile | 705 | //KOPrefs::instance()->mWriteBackFile |
706 | //KOPrefs::instance()->mWriteBackExistingOnly | 706 | //KOPrefs::instance()->mWriteBackExistingOnly |
707 | 707 | ||
708 | // 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); | 708 | // 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); |
709 | // 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); | 709 | // 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); |
710 | // 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); | 710 | // 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); |
711 | // 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); | 711 | // 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); |
712 | // 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); | 712 | // 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); |
713 | // 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); | 713 | // 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); |
714 | 714 | ||
715 | int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) | 715 | int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) |
716 | { | 716 | { |
717 | 717 | ||
718 | //void setZaurusId(int id); | 718 | //void setZaurusId(int id); |
719 | // int zaurusId() const; | 719 | // int zaurusId() const; |
720 | // void setZaurusUid(int id); | 720 | // void setZaurusUid(int id); |
721 | // int zaurusUid() const; | 721 | // int zaurusUid() const; |
722 | // void setZaurusStat(int id); | 722 | // void setZaurusStat(int id); |
723 | // int zaurusStat() const; | 723 | // int zaurusStat() const; |
724 | // 0 equal | 724 | // 0 equal |
725 | // 1 take local | 725 | // 1 take local |
726 | // 2 take remote | 726 | // 2 take remote |
727 | // 3 cancel | 727 | // 3 cancel |
728 | QDateTime lastSync = mLastCalendarSync; | 728 | QDateTime lastSync = mLastCalendarSync; |
729 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 729 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
730 | bool remCh, locCh; | 730 | bool remCh, locCh; |
731 | remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); | 731 | remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); |
732 | locCh = ( local->lastModified() > mLastCalendarSync ); | 732 | locCh = ( local->lastModified() > mLastCalendarSync ); |
733 | //qDebug("locCh %d remCh %d locuid %d remuid %d", locCh, remCh,local->zaurusUid(), remote->zaurusUid() ); | 733 | //qDebug("locCh %d remCh %d locuid %d remuid %d", locCh, remCh,local->zaurusUid(), remote->zaurusUid() ); |
734 | if ( !remCh && ! locCh ) { | 734 | if ( !remCh && ! locCh ) { |
735 | //qDebug("both not changed "); | 735 | //qDebug("both not changed "); |
736 | lastSync = local->lastModified().addDays(1); | 736 | lastSync = local->lastModified().addDays(1); |
737 | } else { | 737 | } else { |
738 | if ( locCh ) { | 738 | if ( locCh ) { |
739 | //qDebug("loc changed %d %d", local->zaurusStat(), local->revision() ); | 739 | //qDebug("loc changed %d %d", local->zaurusStat(), local->revision() ); |
740 | lastSync = local->lastModified().addDays( -1 ); | 740 | lastSync = local->lastModified().addDays( -1 ); |
741 | if ( !remCh ) | 741 | if ( !remCh ) |
742 | remote->setLastModified( lastSync.addDays( -1 ) ); | 742 | remote->setLastModified( lastSync.addDays( -1 ) ); |
743 | } else { | 743 | } else { |
744 | //qDebug(" not loc changed "); | 744 | //qDebug(" not loc changed "); |
745 | lastSync = local->lastModified().addDays( 1 ); | 745 | lastSync = local->lastModified().addDays( 1 ); |
746 | if ( remCh ) | 746 | if ( remCh ) |
747 | remote->setLastModified( lastSync.addDays( 1 ) ); | 747 | remote->setLastModified( lastSync.addDays( 1 ) ); |
748 | 748 | ||
749 | } | 749 | } |
750 | } | 750 | } |
751 | full = true; | 751 | full = true; |
752 | if ( mode < SYNC_PREF_ASK ) | 752 | if ( mode < SYNC_PREF_ASK ) |
753 | mode = SYNC_PREF_ASK; | 753 | mode = SYNC_PREF_ASK; |
754 | } else { | 754 | } else { |
755 | if ( local->lastModified() == remote->lastModified() ) | 755 | if ( local->lastModified() == remote->lastModified() ) |
756 | if ( local->revision() == remote->revision() ) | 756 | if ( local->revision() == remote->revision() ) |
757 | return 0; | 757 | return 0; |
758 | 758 | ||
759 | } | 759 | } |
760 | // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); | 760 | // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); |
761 | 761 | ||
762 | //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , local->revision(), remote->lastModified().toString().latin1(), remote->revision()); | 762 | //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , local->revision(), remote->lastModified().toString().latin1(), remote->revision()); |
763 | //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); | 763 | //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); |
764 | //full = true; //debug only | 764 | //full = true; //debug only |
765 | if ( full ) { | 765 | if ( full ) { |
766 | bool equ = false; | 766 | bool equ = false; |
767 | if ( local->type() == "Event" ) { | 767 | if ( local->type() == "Event" ) { |
768 | equ = (*((Event*) local) == *((Event*) remote)); | 768 | equ = (*((Event*) local) == *((Event*) remote)); |
769 | } | 769 | } |
770 | else if ( local->type() =="Todo" ) | 770 | else if ( local->type() =="Todo" ) |
771 | equ = (*((Todo*) local) == (*(Todo*) remote)); | 771 | equ = (*((Todo*) local) == (*(Todo*) remote)); |
772 | else if ( local->type() =="Journal" ) | 772 | else if ( local->type() =="Journal" ) |
773 | equ = (*((Journal*) local) == *((Journal*) remote)); | 773 | equ = (*((Journal*) local) == *((Journal*) remote)); |
774 | if ( equ ) { | 774 | if ( equ ) { |
775 | //qDebug("equal "); | 775 | //qDebug("equal "); |
776 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 776 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
777 | local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); | 777 | local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); |
778 | } | 778 | } |
779 | if ( mode < SYNC_PREF_FORCE_LOCAL ) | 779 | if ( mode < SYNC_PREF_FORCE_LOCAL ) |
780 | return 0; | 780 | return 0; |
781 | 781 | ||
782 | }//else //debug only | 782 | }//else //debug only |
783 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); | 783 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); |
784 | } | 784 | } |
785 | int result; | 785 | int result; |
786 | bool localIsNew; | 786 | bool localIsNew; |
787 | if ( full && mode < SYNC_PREF_NEWEST ) | 787 | if ( full && mode < SYNC_PREF_NEWEST ) |
788 | mode = SYNC_PREF_ASK; | 788 | mode = SYNC_PREF_ASK; |
789 | 789 | ||
790 | switch( mode ) { | 790 | switch( mode ) { |
791 | case SYNC_PREF_LOCAL: | 791 | case SYNC_PREF_LOCAL: |
792 | if ( lastSync > remote->lastModified() ) | 792 | if ( lastSync > remote->lastModified() ) |
793 | return 1; | 793 | return 1; |
794 | if ( lastSync > local->lastModified() ) | 794 | if ( lastSync > local->lastModified() ) |
795 | return 2; | 795 | return 2; |
796 | return 1; | 796 | return 1; |
797 | break; | 797 | break; |
798 | case SYNC_PREF_REMOTE: | 798 | case SYNC_PREF_REMOTE: |
799 | if ( lastSync > remote->lastModified() ) | 799 | if ( lastSync > remote->lastModified() ) |
800 | return 1; | 800 | return 1; |
801 | if ( lastSync > local->lastModified() ) | 801 | if ( lastSync > local->lastModified() ) |
802 | return 2; | 802 | return 2; |
803 | return 2; | 803 | return 2; |
804 | break; | 804 | break; |
805 | case SYNC_PREF_NEWEST: | 805 | case SYNC_PREF_NEWEST: |
806 | if ( local->lastModified() > remote->lastModified() ) | 806 | if ( local->lastModified() > remote->lastModified() ) |
807 | return 1; | 807 | return 1; |
808 | else | 808 | else |
809 | return 2; | 809 | return 2; |
810 | break; | 810 | break; |
811 | case SYNC_PREF_ASK: | 811 | case SYNC_PREF_ASK: |
812 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() ); | 812 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() ); |
813 | if ( lastSync > remote->lastModified() ) | 813 | if ( lastSync > remote->lastModified() ) |
814 | return 1; | 814 | return 1; |
815 | if ( lastSync > local->lastModified() ) | 815 | if ( lastSync > local->lastModified() ) |
816 | return 2; | 816 | return 2; |
817 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() ); | 817 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() ); |
818 | localIsNew = local->lastModified() > remote->lastModified(); | 818 | localIsNew = local->lastModified() > remote->lastModified(); |
819 | if ( localIsNew ) | 819 | if ( localIsNew ) |
820 | getEventViewerDialog()->setColorMode( 1 ); | 820 | getEventViewerDialog()->setColorMode( 1 ); |
821 | else | 821 | else |
822 | getEventViewerDialog()->setColorMode( 2 ); | 822 | getEventViewerDialog()->setColorMode( 2 ); |
823 | getEventViewerDialog()->setIncidence(local); | 823 | getEventViewerDialog()->setIncidence(local); |
824 | if ( localIsNew ) | 824 | if ( localIsNew ) |
825 | getEventViewerDialog()->setColorMode( 2 ); | 825 | getEventViewerDialog()->setColorMode( 2 ); |
826 | else | 826 | else |
827 | getEventViewerDialog()->setColorMode( 1 ); | 827 | getEventViewerDialog()->setColorMode( 1 ); |
828 | getEventViewerDialog()->addIncidence(remote); | 828 | getEventViewerDialog()->addIncidence(remote); |
829 | getEventViewerDialog()->setColorMode( 0 ); | 829 | getEventViewerDialog()->setColorMode( 0 ); |
830 | //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); | 830 | //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); |
831 | getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); | 831 | getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); |
832 | getEventViewerDialog()->showMe(); | 832 | getEventViewerDialog()->showMe(); |
833 | result = getEventViewerDialog()->executeS( localIsNew ); | 833 | result = getEventViewerDialog()->executeS( localIsNew ); |
834 | return result; | 834 | return result; |
835 | 835 | ||
836 | break; | 836 | break; |
837 | case SYNC_PREF_FORCE_LOCAL: | 837 | case SYNC_PREF_FORCE_LOCAL: |
838 | return 1; | 838 | return 1; |
839 | break; | 839 | break; |
840 | case SYNC_PREF_FORCE_REMOTE: | 840 | case SYNC_PREF_FORCE_REMOTE: |
841 | return 2; | 841 | return 2; |
842 | break; | 842 | break; |
843 | 843 | ||
844 | default: | 844 | default: |
845 | // SYNC_PREF_TAKE_BOTH not implemented | 845 | // SYNC_PREF_TAKE_BOTH not implemented |
846 | break; | 846 | break; |
847 | } | 847 | } |
848 | return 0; | 848 | return 0; |
849 | } | 849 | } |
850 | Event* CalendarView::getLastSyncEvent() | 850 | Event* CalendarView::getLastSyncEvent() |
851 | { | 851 | { |
852 | Event* lse; | 852 | Event* lse; |
853 | //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); | 853 | //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); |
854 | lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); | 854 | lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); |
855 | if (!lse) { | 855 | if (!lse) { |
856 | lse = new Event(); | 856 | lse = new Event(); |
857 | lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); | 857 | lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); |
858 | QString sum = ""; | 858 | QString sum = ""; |
859 | if ( KOPrefs::instance()->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) | 859 | if ( KOPrefs::instance()->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) |
860 | sum = "E: "; | 860 | sum = "E: "; |
861 | lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); | 861 | lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); |
862 | lse->setDtStart( mLastCalendarSync ); | 862 | lse->setDtStart( mLastCalendarSync ); |
863 | lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); | 863 | lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); |
864 | lse->setCategories( i18n("SyncEvent") ); | 864 | lse->setCategories( i18n("SyncEvent") ); |
865 | lse->setReadOnly( true ); | 865 | lse->setReadOnly( true ); |
866 | mCalendar->addEvent( lse ); | 866 | mCalendar->addEvent( lse ); |
867 | } | 867 | } |
868 | 868 | ||
869 | return lse; | 869 | return lse; |
870 | 870 | ||
871 | } | 871 | } |
872 | // probaly useless | 872 | // probaly useless |
873 | void CalendarView::setupExternSyncProfiles() | 873 | void CalendarView::setupExternSyncProfiles() |
874 | { | 874 | { |
875 | Event* lse; | 875 | Event* lse; |
876 | mExternLastSyncEvent.clear(); | 876 | mExternLastSyncEvent.clear(); |
877 | int i; | 877 | int i; |
878 | for ( i = 0; i < KOPrefs::instance()->mExternSyncProfiles.count(); ++i ) { | 878 | for ( i = 0; i < KOPrefs::instance()->mExternSyncProfiles.count(); ++i ) { |
879 | lse = mCalendar->event( "last-syncEvent-"+ KOPrefs::instance()->mExternSyncProfiles[i] ); | 879 | lse = mCalendar->event( "last-syncEvent-"+ KOPrefs::instance()->mExternSyncProfiles[i] ); |
880 | if ( lse ) | 880 | if ( lse ) |
881 | mExternLastSyncEvent.append( lse ); | 881 | mExternLastSyncEvent.append( lse ); |
882 | else | 882 | else |
883 | qDebug("Last Sync event not found for %s ", KOPrefs::instance()->mExternSyncProfiles[i].latin1()); | 883 | qDebug("Last Sync event not found for %s ", KOPrefs::instance()->mExternSyncProfiles[i].latin1()); |
884 | } | 884 | } |
885 | 885 | ||
886 | } | 886 | } |
887 | // we check, if the to delete event has a id for a profile | 887 | // we check, if the to delete event has a id for a profile |
888 | // if yes, we set this id in the profile to delete | 888 | // if yes, we set this id in the profile to delete |
889 | void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) | 889 | void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) |
890 | { | 890 | { |
891 | if ( lastSync.count() == 0 ) { | 891 | if ( lastSync.count() == 0 ) { |
892 | //qDebug(" lastSync.count() == 0"); | 892 | //qDebug(" lastSync.count() == 0"); |
893 | return; | 893 | return; |
894 | } | 894 | } |
895 | if ( toDelete->type() == "Journal" ) | 895 | if ( toDelete->type() == "Journal" ) |
896 | return; | 896 | return; |
897 | 897 | ||
898 | Event* eve = lastSync.first(); | 898 | Event* eve = lastSync.first(); |
899 | 899 | ||
900 | while ( eve ) { | 900 | while ( eve ) { |
901 | QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name | 901 | QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name |
902 | if ( !id.isEmpty() ) { | 902 | if ( !id.isEmpty() ) { |
903 | QString des = eve->description(); | 903 | QString des = eve->description(); |
904 | QString pref = "e"; | 904 | QString pref = "e"; |
905 | if ( toDelete->type() == "Todo" ) | 905 | if ( toDelete->type() == "Todo" ) |
906 | pref = "t"; | 906 | pref = "t"; |
907 | des += pref+ id + ","; | 907 | des += pref+ id + ","; |
908 | eve->setReadOnly( false ); | 908 | eve->setReadOnly( false ); |
909 | eve->setDescription( des ); | 909 | eve->setDescription( des ); |
910 | //qDebug("setdes %s ", des.latin1()); | 910 | //qDebug("setdes %s ", des.latin1()); |
911 | eve->setReadOnly( true ); | 911 | eve->setReadOnly( true ); |
912 | } | 912 | } |
913 | eve = lastSync.next(); | 913 | eve = lastSync.next(); |
914 | } | 914 | } |
915 | 915 | ||
916 | } | 916 | } |
917 | void CalendarView::checkExternalId( Incidence * inc ) | 917 | void CalendarView::checkExternalId( Incidence * inc ) |
918 | { | 918 | { |
919 | QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; | 919 | QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; |
920 | checkExternSyncEvent( lastSync, inc ); | 920 | checkExternSyncEvent( lastSync, inc ); |
921 | 921 | ||
922 | } | 922 | } |
923 | bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) | 923 | bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) |
924 | { | 924 | { |
925 | bool syncOK = true; | 925 | bool syncOK = true; |
926 | int addedEvent = 0; | 926 | int addedEvent = 0; |
927 | int addedEventR = 0; | 927 | int addedEventR = 0; |
928 | int deletedEventR = 0; | 928 | int deletedEventR = 0; |
929 | int deletedEventL = 0; | 929 | int deletedEventL = 0; |
930 | int changedLocal = 0; | 930 | int changedLocal = 0; |
931 | int changedRemote = 0; | 931 | int changedRemote = 0; |
932 | //QPtrList<Event> el = local->rawEvents(); | 932 | //QPtrList<Event> el = local->rawEvents(); |
933 | Event* eventR; | 933 | Event* eventR; |
934 | QString uid; | 934 | QString uid; |
935 | int take; | 935 | int take; |
936 | Event* eventL; | 936 | Event* eventL; |
937 | Event* eventRSync; | 937 | Event* eventRSync; |
938 | Event* eventLSync; | 938 | Event* eventLSync; |
939 | QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); | 939 | QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); |
940 | QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); | 940 | QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); |
941 | bool fullDateRange = false; | 941 | bool fullDateRange = false; |
942 | local->resetTempSyncStat(); | ||
942 | mLastCalendarSync = QDateTime::currentDateTime(); | 943 | mLastCalendarSync = QDateTime::currentDateTime(); |
943 | QDateTime modifiedCalendar = mLastCalendarSync;; | 944 | QDateTime modifiedCalendar = mLastCalendarSync;; |
944 | eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); | 945 | eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); |
945 | if ( eventR ) { | 946 | if ( eventR ) { |
946 | eventRSync = (Event*) eventR->clone(); | 947 | eventRSync = (Event*) eventR->clone(); |
947 | remote->deleteEvent(eventR ); | 948 | remote->deleteEvent(eventR ); |
948 | 949 | ||
949 | } else { | 950 | } else { |
950 | fullDateRange = true; | 951 | fullDateRange = true; |
951 | eventRSync = new Event(); | 952 | eventRSync = new Event(); |
952 | eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); | 953 | eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); |
953 | eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); | 954 | eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); |
954 | eventRSync->setDtStart( mLastCalendarSync ); | 955 | eventRSync->setDtStart( mLastCalendarSync ); |
955 | eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); | 956 | eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); |
956 | eventRSync->setCategories( i18n("SyncEvent") ); | 957 | eventRSync->setCategories( i18n("SyncEvent") ); |
957 | } | 958 | } |
958 | eventLSync = getLastSyncEvent(); | 959 | eventLSync = getLastSyncEvent(); |
959 | if ( eventLSync->dtStart() == mLastCalendarSync ) | 960 | if ( eventLSync->dtStart() == mLastCalendarSync ) |
960 | fullDateRange = true; | 961 | fullDateRange = true; |
961 | 962 | ||
962 | if ( ! fullDateRange ) { | 963 | if ( ! fullDateRange ) { |
963 | if ( eventLSync->dtStart() != eventRSync->dtStart() ) { | 964 | if ( eventLSync->dtStart() != eventRSync->dtStart() ) { |
964 | 965 | ||
965 | // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); | 966 | // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); |
966 | //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); | 967 | //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); |
967 | fullDateRange = true; | 968 | fullDateRange = true; |
968 | } | 969 | } |
969 | } | 970 | } |
970 | if ( fullDateRange ) | 971 | if ( fullDateRange ) |
971 | mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); | 972 | mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); |
972 | else | 973 | else |
973 | mLastCalendarSync = eventLSync->dtStart(); | 974 | mLastCalendarSync = eventLSync->dtStart(); |
974 | // for resyncing if own file has changed | 975 | // for resyncing if own file has changed |
975 | if ( mCurrentSyncDevice == "deleteaftersync" ) { | 976 | if ( mCurrentSyncDevice == "deleteaftersync" ) { |
976 | mLastCalendarSync = loadedFileVersion; | 977 | mLastCalendarSync = loadedFileVersion; |
977 | qDebug("setting mLastCalendarSync "); | 978 | qDebug("setting mLastCalendarSync "); |
978 | } | 979 | } |
979 | //qDebug("*************************** "); | 980 | //qDebug("*************************** "); |
980 | qDebug("mLastCalendarSync %s ",mLastCalendarSync.toString().latin1() ); | 981 | qDebug("mLastCalendarSync %s ",mLastCalendarSync.toString().latin1() ); |
981 | QPtrList<Incidence> er = remote->rawIncidences(); | 982 | QPtrList<Incidence> er = remote->rawIncidences(); |
982 | Incidence* inR = er.first(); | 983 | Incidence* inR = er.first(); |
983 | Incidence* inL; | 984 | Incidence* inL; |
984 | QProgressBar bar( er.count(),0 ); | 985 | QProgressBar bar( er.count(),0 ); |
985 | bar.setCaption (i18n("Syncing - close to abort!") ); | 986 | bar.setCaption (i18n("Syncing - close to abort!") ); |
986 | 987 | ||
987 | int w = 300; | 988 | int w = 300; |
988 | if ( QApplication::desktop()->width() < 320 ) | 989 | if ( QApplication::desktop()->width() < 320 ) |
989 | w = 220; | 990 | w = 220; |
990 | int h = bar.sizeHint().height() ; | 991 | int h = bar.sizeHint().height() ; |
991 | int dw = QApplication::desktop()->width(); | 992 | int dw = QApplication::desktop()->width(); |
992 | int dh = QApplication::desktop()->height(); | 993 | int dh = QApplication::desktop()->height(); |
993 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 994 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
994 | bar.show(); | 995 | bar.show(); |
995 | int modulo = (er.count()/10)+1; | 996 | int modulo = (er.count()/10)+1; |
996 | int incCounter = 0; | 997 | int incCounter = 0; |
997 | while ( inR ) { | 998 | while ( inR ) { |
998 | if ( ! bar.isVisible() ) | 999 | if ( ! bar.isVisible() ) |
999 | return false; | 1000 | return false; |
1000 | if ( incCounter % modulo == 0 ) | 1001 | if ( incCounter % modulo == 0 ) |
1001 | bar.setProgress( incCounter ); | 1002 | bar.setProgress( incCounter ); |
1002 | ++incCounter; | 1003 | ++incCounter; |
1003 | uid = inR->uid(); | 1004 | uid = inR->uid(); |
1004 | bool skipIncidence = false; | 1005 | bool skipIncidence = false; |
1005 | if ( uid.left(15) == QString("last-syncEvent-") ) | 1006 | if ( uid.left(15) == QString("last-syncEvent-") ) |
1006 | skipIncidence = true; | 1007 | skipIncidence = true; |
1007 | 1008 | ||
1008 | qApp->processEvents(); | 1009 | qApp->processEvents(); |
1009 | if ( !skipIncidence ) { | 1010 | if ( !skipIncidence ) { |
1010 | inL = local->incidence( uid ); | 1011 | inL = local->incidence( uid ); |
1011 | if ( inL ) { // maybe conflict - same uid in both calendars | 1012 | if ( inL ) { // maybe conflict - same uid in both calendars |
1012 | int maxrev = inL->revision(); | 1013 | int maxrev = inL->revision(); |
1013 | if ( maxrev < inR->revision() ) | 1014 | if ( maxrev < inR->revision() ) |
1014 | maxrev = inR->revision(); | 1015 | maxrev = inR->revision(); |
1015 | if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { | 1016 | if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { |
1016 | //qDebug("take %d %s ", take, inL->summary().latin1()); | 1017 | //qDebug("take %d %s ", take, inL->summary().latin1()); |
1017 | if ( take == 3 ) | 1018 | if ( take == 3 ) |
1018 | return false; | 1019 | return false; |
1019 | if ( take == 1 ) {// take local | 1020 | if ( take == 1 ) {// take local |
1020 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); | 1021 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); |
1021 | remote->deleteIncidence( inR ); | 1022 | remote->deleteIncidence( inR ); |
1022 | if ( inL->revision() < maxrev ) | 1023 | if ( inL->revision() < maxrev ) |
1023 | inL->setRevision( maxrev ); | 1024 | inL->setRevision( maxrev ); |
1024 | remote->addIncidence( inL->clone() ); | 1025 | remote->addIncidence( inL->clone() ); |
1025 | ++changedRemote; | 1026 | ++changedRemote; |
1026 | } else { | 1027 | } else { |
1027 | if ( inR->revision() < maxrev ) | 1028 | if ( inR->revision() < maxrev ) |
1028 | inR->setRevision( maxrev ); | 1029 | inR->setRevision( maxrev ); |
1029 | local->deleteIncidence( inL ); | 1030 | local->deleteIncidence( inL ); |
1030 | local->addIncidence( inR->clone() ); | 1031 | local->addIncidence( inR->clone() ); |
1031 | ++changedLocal; | 1032 | ++changedLocal; |
1032 | } | 1033 | } |
1033 | } | 1034 | } |
1034 | } else { // no conflict | 1035 | } else { // no conflict |
1035 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 1036 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
1036 | QString des = eventLSync->description(); | 1037 | QString des = eventLSync->description(); |
1037 | QString pref = "e"; | 1038 | QString pref = "e"; |
1038 | if ( inR->type() == "Todo" ) | 1039 | if ( inR->type() == "Todo" ) |
1039 | pref = "t"; | 1040 | pref = "t"; |
1040 | if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it | 1041 | if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it |
1041 | inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); | 1042 | inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); |
1042 | //remote->deleteIncidence( inR ); | 1043 | //remote->deleteIncidence( inR ); |
1043 | ++deletedEventR; | 1044 | ++deletedEventR; |
1044 | } else { | 1045 | } else { |
1045 | inR->setLastModified( modifiedCalendar ); | 1046 | inR->setLastModified( modifiedCalendar ); |
1046 | local->addIncidence( inR->clone() ); | 1047 | local->addIncidence( inR->clone() ); |
1047 | ++addedEvent; | 1048 | ++addedEvent; |
1048 | } | 1049 | } |
1049 | } else { | 1050 | } else { |
1050 | if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { | 1051 | if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { |
1051 | inR->setLastModified( modifiedCalendar ); | 1052 | inR->setLastModified( modifiedCalendar ); |
1052 | local->addIncidence( inR->clone() ); | 1053 | local->addIncidence( inR->clone() ); |
1053 | ++addedEvent; | 1054 | ++addedEvent; |
1054 | } else { | 1055 | } else { |
1055 | checkExternSyncEvent(eventRSyncSharp, inR); | 1056 | checkExternSyncEvent(eventRSyncSharp, inR); |
1056 | remote->deleteIncidence( inR ); | 1057 | remote->deleteIncidence( inR ); |
1057 | ++deletedEventR; | 1058 | ++deletedEventR; |
1058 | } | 1059 | } |
1059 | } | 1060 | } |
1060 | } | 1061 | } |
1061 | } | 1062 | } |
1062 | inR = er.next(); | 1063 | inR = er.next(); |
1063 | } | 1064 | } |
1064 | QPtrList<Incidence> el = local->rawIncidences(); | 1065 | QPtrList<Incidence> el = local->rawIncidences(); |
1065 | inL = el.first(); | 1066 | inL = el.first(); |
1066 | modulo = (el.count()/10)+1; | 1067 | modulo = (el.count()/10)+1; |
1067 | bar.setCaption (i18n("Add / remove events") ); | 1068 | bar.setCaption (i18n("Add / remove events") ); |
1068 | bar.setTotalSteps ( el.count() ) ; | 1069 | bar.setTotalSteps ( el.count() ) ; |
1069 | bar.show(); | 1070 | bar.show(); |
1070 | incCounter = 0; | 1071 | incCounter = 0; |
1071 | 1072 | ||
1072 | while ( inL ) { | 1073 | while ( inL ) { |
1073 | 1074 | ||
1074 | qApp->processEvents(); | 1075 | qApp->processEvents(); |
1075 | if ( ! bar.isVisible() ) | 1076 | if ( ! bar.isVisible() ) |
1076 | return false; | 1077 | return false; |
1077 | if ( incCounter % modulo == 0 ) | 1078 | if ( incCounter % modulo == 0 ) |
1078 | bar.setProgress( incCounter ); | 1079 | bar.setProgress( incCounter ); |
1079 | ++incCounter; | 1080 | ++incCounter; |
1080 | uid = inL->uid(); | 1081 | uid = inL->uid(); |
1081 | bool skipIncidence = false; | 1082 | bool skipIncidence = false; |
1082 | if ( uid.left(15) == QString("last-syncEvent-") ) | 1083 | if ( uid.left(15) == QString("last-syncEvent-") ) |
1083 | skipIncidence = true; | 1084 | skipIncidence = true; |
1084 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) | 1085 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) |
1085 | skipIncidence = true; | 1086 | skipIncidence = true; |
1086 | if ( !skipIncidence ) { | 1087 | if ( !skipIncidence ) { |
1087 | inR = remote->incidence( uid ); | 1088 | inR = remote->incidence( uid ); |
1088 | if ( ! inR ) { | 1089 | if ( ! inR ) { |
1089 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 1090 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
1090 | if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { | 1091 | if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { |
1091 | local->deleteIncidence( inL ); | 1092 | local->deleteIncidence( inL ); |
1092 | ++deletedEventL; | 1093 | ++deletedEventL; |
1093 | } else { | 1094 | } else { |
1094 | if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { | 1095 | if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { |
1095 | inL->removeID(mCurrentSyncDevice ); | 1096 | inL->removeID(mCurrentSyncDevice ); |
1096 | ++addedEventR; | 1097 | ++addedEventR; |
1097 | inL->setLastModified( modifiedCalendar ); | 1098 | inL->setLastModified( modifiedCalendar ); |
1098 | remote->addIncidence( inL->clone() ); | 1099 | remote->addIncidence( inL->clone() ); |
1099 | } | 1100 | } |
1100 | } | 1101 | } |
1101 | } else { | 1102 | } else { |
1102 | if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { | 1103 | if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { |
1103 | checkExternSyncEvent(eventLSyncSharp, inL); | 1104 | checkExternSyncEvent(eventLSyncSharp, inL); |
1104 | local->deleteIncidence( inL ); | 1105 | local->deleteIncidence( inL ); |
1105 | ++deletedEventL; | 1106 | ++deletedEventL; |
1106 | } else { | 1107 | } else { |
1107 | if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { | 1108 | if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { |
1108 | ++addedEventR; | 1109 | ++addedEventR; |
1109 | inL->setLastModified( modifiedCalendar ); | 1110 | inL->setLastModified( modifiedCalendar ); |
1110 | remote->addIncidence( inL->clone() ); | 1111 | remote->addIncidence( inL->clone() ); |
1111 | } | 1112 | } |
1112 | } | 1113 | } |
1113 | } | 1114 | } |
1114 | } | 1115 | } |
1115 | } | 1116 | } |
1116 | inL = el.next(); | 1117 | inL = el.next(); |
1117 | } | 1118 | } |
1118 | 1119 | ||
1119 | bar.hide(); | 1120 | bar.hide(); |
1120 | mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); | 1121 | mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); |
1121 | eventLSync->setReadOnly( false ); | 1122 | eventLSync->setReadOnly( false ); |
1122 | eventLSync->setDtStart( mLastCalendarSync ); | 1123 | eventLSync->setDtStart( mLastCalendarSync ); |
1123 | eventRSync->setDtStart( mLastCalendarSync ); | 1124 | eventRSync->setDtStart( mLastCalendarSync ); |
1124 | eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); | 1125 | eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); |
1125 | eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); | 1126 | eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); |
1126 | eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; | 1127 | eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; |
1127 | eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); | 1128 | eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); |
1128 | eventLSync->setReadOnly( true ); | 1129 | eventLSync->setReadOnly( true ); |
1129 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL) | 1130 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL) |
1130 | remote->addEvent( eventRSync ); | 1131 | remote->addEvent( eventRSync ); |
1131 | QString mes; | 1132 | QString mes; |
1132 | 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"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR ); | 1133 | 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"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR ); |
1133 | if ( KOPrefs::instance()->mShowSyncSummary ) { | 1134 | if ( KOPrefs::instance()->mShowSyncSummary ) { |
1134 | KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") ); | 1135 | KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") ); |
1135 | } | 1136 | } |
1136 | qDebug( mes ); | 1137 | qDebug( mes ); |
1137 | mCalendar->checkAlarmForIncidence( 0, true ); | 1138 | mCalendar->checkAlarmForIncidence( 0, true ); |
1138 | return syncOK; | 1139 | return syncOK; |
1139 | } | 1140 | } |
1140 | 1141 | ||
1141 | void CalendarView::setSyncDevice( QString s ) | 1142 | void CalendarView::setSyncDevice( QString s ) |
1142 | { | 1143 | { |
1143 | mCurrentSyncDevice= s; | 1144 | mCurrentSyncDevice= s; |
1144 | } | 1145 | } |
1145 | void CalendarView::setSyncName( QString s ) | 1146 | void CalendarView::setSyncName( QString s ) |
1146 | { | 1147 | { |
1147 | mCurrentSyncName= s; | 1148 | mCurrentSyncName= s; |
1148 | } | 1149 | } |
1149 | bool CalendarView::syncCalendar(QString filename, int mode) | 1150 | bool CalendarView::syncCalendar(QString filename, int mode) |
1150 | { | 1151 | { |
1151 | mGlobalSyncMode = SYNC_MODE_NORMAL; | 1152 | mGlobalSyncMode = SYNC_MODE_NORMAL; |
1152 | CalendarLocal* calendar = new CalendarLocal(); | 1153 | CalendarLocal* calendar = new CalendarLocal(); |
1153 | calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); | 1154 | calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); |
1154 | FileStorage* storage = new FileStorage( calendar ); | 1155 | FileStorage* storage = new FileStorage( calendar ); |
1155 | bool syncOK = false; | 1156 | bool syncOK = false; |
1156 | storage->setFileName( filename ); | 1157 | storage->setFileName( filename ); |
1157 | // qDebug("loading ... "); | 1158 | // qDebug("loading ... "); |
1158 | if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { | 1159 | if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { |
1159 | getEventViewerDialog()->setSyncMode( true ); | 1160 | getEventViewerDialog()->setSyncMode( true ); |
1160 | syncOK = synchronizeCalendar( mCalendar, calendar, mode ); | 1161 | syncOK = synchronizeCalendar( mCalendar, calendar, mode ); |
1161 | getEventViewerDialog()->setSyncMode( false ); | 1162 | getEventViewerDialog()->setSyncMode( false ); |
1162 | if ( syncOK ) { | 1163 | if ( syncOK ) { |
1163 | if ( KOPrefs::instance()->mWriteBackFile ) | 1164 | if ( KOPrefs::instance()->mWriteBackFile ) |
1164 | { | 1165 | { |
1165 | storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); | 1166 | storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); |
1166 | storage->save(); | 1167 | storage->save(); |
1167 | } | 1168 | } |
1168 | } | 1169 | } |
1169 | setModified( true ); | 1170 | setModified( true ); |
1170 | } | 1171 | } |
1171 | delete storage; | 1172 | delete storage; |
1172 | delete calendar; | 1173 | delete calendar; |
1173 | if ( syncOK ) | 1174 | if ( syncOK ) |
1174 | updateView(); | 1175 | updateView(); |
1175 | return syncOK; | 1176 | return syncOK; |
1176 | } | 1177 | } |
1177 | void CalendarView::syncPhone() | 1178 | void CalendarView::syncPhone() |
1178 | { | 1179 | { |
1179 | syncExternal( 1 ); | 1180 | syncExternal( 1 ); |
1180 | } | 1181 | } |
1181 | void CalendarView::syncExternal( int mode ) | 1182 | void CalendarView::syncExternal( int mode ) |
1182 | { | 1183 | { |
1183 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 1184 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
1184 | //mCurrentSyncDevice = "sharp-DTM"; | 1185 | //mCurrentSyncDevice = "sharp-DTM"; |
1185 | if ( KOPrefs::instance()->mAskForPreferences ) | 1186 | if ( KOPrefs::instance()->mAskForPreferences ) |
1186 | edit_sync_options(); | 1187 | edit_sync_options(); |
1187 | qApp->processEvents(); | 1188 | qApp->processEvents(); |
1188 | CalendarLocal* calendar = new CalendarLocal(); | 1189 | CalendarLocal* calendar = new CalendarLocal(); |
1189 | calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); | 1190 | calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); |
1190 | bool syncOK = false; | 1191 | bool syncOK = false; |
1191 | bool loadSuccess = false; | 1192 | bool loadSuccess = false; |
1192 | PhoneFormat* phoneFormat = 0; | 1193 | PhoneFormat* phoneFormat = 0; |
1193 | #ifndef DESKTOP_VERSION | 1194 | #ifndef DESKTOP_VERSION |
1194 | SharpFormat* sharpFormat = 0; | 1195 | SharpFormat* sharpFormat = 0; |
1195 | if ( mode == 0 ) { // sharp | 1196 | if ( mode == 0 ) { // sharp |
1196 | sharpFormat = new SharpFormat () ; | 1197 | sharpFormat = new SharpFormat () ; |
1197 | loadSuccess = sharpFormat->load( calendar, mCalendar ); | 1198 | loadSuccess = sharpFormat->load( calendar, mCalendar ); |
1198 | 1199 | ||
1199 | } else | 1200 | } else |
1200 | #endif | 1201 | #endif |
1201 | if ( mode == 1 ) { // phone | 1202 | if ( mode == 1 ) { // phone |
1202 | phoneFormat = new PhoneFormat (mCurrentSyncDevice, | 1203 | phoneFormat = new PhoneFormat (mCurrentSyncDevice, |
1203 | KOPrefs::instance()->mPhoneDevice, | 1204 | KOPrefs::instance()->mPhoneDevice, |
1204 | KOPrefs::instance()->mPhoneConnection, | 1205 | KOPrefs::instance()->mPhoneConnection, |
1205 | KOPrefs::instance()->mPhoneModel); | 1206 | KOPrefs::instance()->mPhoneModel); |
1206 | loadSuccess = phoneFormat->load( calendar,mCalendar); | 1207 | loadSuccess = phoneFormat->load( calendar,mCalendar); |
1207 | 1208 | ||
1208 | } else | 1209 | } else |
1209 | return; | 1210 | return; |
1210 | if ( loadSuccess ) { | 1211 | if ( loadSuccess ) { |
1211 | getEventViewerDialog()->setSyncMode( true ); | 1212 | getEventViewerDialog()->setSyncMode( true ); |
1212 | syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs ); | 1213 | syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs ); |
1213 | getEventViewerDialog()->setSyncMode( false ); | 1214 | getEventViewerDialog()->setSyncMode( false ); |
1214 | qApp->processEvents(); | 1215 | qApp->processEvents(); |
1215 | if ( syncOK ) { | 1216 | if ( syncOK ) { |
1216 | if ( KOPrefs::instance()->mWriteBackFile ) | 1217 | if ( KOPrefs::instance()->mWriteBackFile ) |
1217 | { | 1218 | { |
1218 | QPtrList<Incidence> iL = mCalendar->rawIncidences(); | 1219 | QPtrList<Incidence> iL = mCalendar->rawIncidences(); |
1219 | Incidence* inc = iL.first(); | 1220 | Incidence* inc = iL.first(); |
1220 | /* obsolete | 1221 | /* obsolete |
1221 | while ( inc ) { | 1222 | while ( inc ) { |
1222 | inc->setZaurusStat( inc->revision () ); | 1223 | inc->setZaurusStat( inc->revision () ); |
1223 | inc = iL.next(); | 1224 | inc = iL.next(); |
1224 | } | 1225 | } |
1225 | */ | 1226 | */ |
1226 | #ifndef DESKTOP_VERSION | 1227 | #ifndef DESKTOP_VERSION |
1227 | if ( sharpFormat ) | 1228 | if ( sharpFormat ) |
1228 | sharpFormat->save(calendar); | 1229 | sharpFormat->save(calendar); |
1229 | #endif | 1230 | #endif |
1230 | if ( phoneFormat ) | 1231 | if ( phoneFormat ) |
1231 | phoneFormat->save(calendar); | 1232 | phoneFormat->save(calendar); |
1232 | iL = calendar->rawIncidences(); | 1233 | iL = calendar->rawIncidences(); |
1233 | inc = iL.first(); | 1234 | inc = iL.first(); |
1234 | Incidence* loc; | 1235 | Incidence* loc; |
1235 | while ( inc ) { | 1236 | while ( inc ) { |
1236 | if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { | 1237 | if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { |
1237 | loc = mCalendar->incidence(inc->uid() ); | 1238 | loc = mCalendar->incidence(inc->uid() ); |
1238 | if ( loc ) { | 1239 | if ( loc ) { |
1239 | loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); | 1240 | loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); |
1240 | loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); | 1241 | loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); |
1241 | } | 1242 | } |
1242 | } | 1243 | } |
1243 | inc = iL.next(); | 1244 | inc = iL.next(); |
1244 | } | 1245 | } |
1245 | Incidence* lse = getLastSyncEvent(); | 1246 | Incidence* lse = getLastSyncEvent(); |
1246 | if ( lse ) { | 1247 | if ( lse ) { |
1247 | lse->setReadOnly( false ); | 1248 | lse->setReadOnly( false ); |
1248 | lse->setDescription( "" ); | 1249 | lse->setDescription( "" ); |
1249 | lse->setReadOnly( true ); | 1250 | lse->setReadOnly( true ); |
1250 | } | 1251 | } |
1251 | } | 1252 | } |
1252 | } | 1253 | } |
1253 | setModified( true ); | 1254 | setModified( true ); |
1254 | } else { | 1255 | } else { |
1255 | QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; | 1256 | QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; |
1256 | QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), | 1257 | QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), |
1257 | question, i18n("Ok")) ; | 1258 | question, i18n("Ok")) ; |
1258 | 1259 | ||
1259 | } | 1260 | } |
1260 | delete calendar; | 1261 | delete calendar; |
1261 | updateView(); | 1262 | updateView(); |
1262 | return ;//syncOK; | 1263 | return ;//syncOK; |
1263 | 1264 | ||
1264 | } | 1265 | } |
1265 | void CalendarView::syncSharp() | 1266 | void CalendarView::syncSharp() |
1266 | { | 1267 | { |
1267 | syncExternal( 0 ); | 1268 | syncExternal( 0 ); |
1268 | 1269 | ||
1269 | } | 1270 | } |
1270 | 1271 | ||
1271 | 1272 | ||
1272 | #include <kabc/stdaddressbook.h> | 1273 | #include <kabc/stdaddressbook.h> |
1273 | bool CalendarView::importBday() | 1274 | bool CalendarView::importBday() |
1274 | { | 1275 | { |
1275 | KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); | 1276 | KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); |
1276 | KABC::AddressBook::Iterator it; | 1277 | KABC::AddressBook::Iterator it; |
1277 | int count = 0; | 1278 | int count = 0; |
1278 | for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { | 1279 | for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { |
1279 | ++count; | 1280 | ++count; |
1280 | } | 1281 | } |
1281 | QProgressBar bar(count,0 ); | 1282 | QProgressBar bar(count,0 ); |
1282 | int w = 300; | 1283 | int w = 300; |
1283 | if ( QApplication::desktop()->width() < 320 ) | 1284 | if ( QApplication::desktop()->width() < 320 ) |
1284 | w = 220; | 1285 | w = 220; |
1285 | int h = bar.sizeHint().height() ; | 1286 | int h = bar.sizeHint().height() ; |
1286 | int dw = QApplication::desktop()->width(); | 1287 | int dw = QApplication::desktop()->width(); |
1287 | int dh = QApplication::desktop()->height(); | 1288 | int dh = QApplication::desktop()->height(); |
1288 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 1289 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
1289 | bar.show(); | 1290 | bar.show(); |
1290 | bar.setCaption (i18n("Reading addressbook - close to abort!") ); | 1291 | bar.setCaption (i18n("Reading addressbook - close to abort!") ); |
1291 | qApp->processEvents(); | 1292 | qApp->processEvents(); |
1292 | count = 0; | 1293 | count = 0; |
1293 | int addCount = 0; | 1294 | int addCount = 0; |
1294 | KCal::Attendee* a = 0; | 1295 | KCal::Attendee* a = 0; |
1295 | for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { | 1296 | for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { |
1296 | if ( ! bar.isVisible() ) | 1297 | if ( ! bar.isVisible() ) |
1297 | return false; | 1298 | return false; |
1298 | bar.setProgress( count++ ); | 1299 | bar.setProgress( count++ ); |
1299 | qApp->processEvents(); | 1300 | qApp->processEvents(); |
1300 | //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); | 1301 | //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); |
1301 | if ( (*it).birthday().date().isValid() ){ | 1302 | if ( (*it).birthday().date().isValid() ){ |
1302 | a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; | 1303 | a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; |
1303 | if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) | 1304 | if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) |
1304 | ++addCount; | 1305 | ++addCount; |
1305 | } | 1306 | } |
1306 | QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); | 1307 | QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); |
1307 | if ( anni.isValid() ){ | 1308 | if ( anni.isValid() ){ |
1308 | a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; | 1309 | a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; |
1309 | if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) | 1310 | if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) |
1310 | ++addCount; | 1311 | ++addCount; |
1311 | } | 1312 | } |
1312 | } | 1313 | } |
1313 | updateView(); | 1314 | updateView(); |
1314 | topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); | 1315 | topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); |
1315 | return true; | 1316 | return true; |
1316 | } | 1317 | } |
1317 | 1318 | ||
1318 | bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) | 1319 | bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) |
1319 | { | 1320 | { |
1320 | //qDebug("addAnni "); | 1321 | //qDebug("addAnni "); |
1321 | Event * ev = new Event(); | 1322 | Event * ev = new Event(); |
1322 | if ( a ) { | 1323 | if ( a ) { |
1323 | ev->addAttendee( a ); | 1324 | ev->addAttendee( a ); |
1324 | } | 1325 | } |
1325 | QString kind; | 1326 | QString kind; |