summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2005-01-17 12:47:46 (UTC)
committer zautrix <zautrix>2005-01-17 12:47:46 (UTC)
commit214b82c86bd5365d7a5fc786c8c9c7231ec6dc77 (patch) (unidiff)
tree9b6052411933ccd1a15428c8f747f0143db4690d
parentba5e5a22ad492f798b2626026cc1838b731e055b (diff)
downloadkdepimpi-214b82c86bd5365d7a5fc786c8c9c7231ec6dc77.zip
kdepimpi-214b82c86bd5365d7a5fc786c8c9c7231ec6dc77.tar.gz
kdepimpi-214b82c86bd5365d7a5fc786c8c9c7231ec6dc77.tar.bz2
small cal fix
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp70
1 files changed, 38 insertions, 32 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index 685bb60..da1edea 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -543,1063 +543,1069 @@ void CalendarView::computeAlarm( QString msg )
543 if ( !QFile::exists( tempfilename ) ) 543 if ( !QFile::exists( tempfilename ) )
544 error = true; 544 error = true;
545 } 545 }
546 if ( ! error ) { 546 if ( ! error ) {
547 filename = tempfilename; 547 filename = tempfilename;
548 } 548 }
549 mAlarmMessage = mess.mid( 13+len+3 ); 549 mAlarmMessage = mess.mid( 13+len+3 );
550 //qDebug("suspend file %s ",tempfilename.latin1() ); 550 //qDebug("suspend file %s ",tempfilename.latin1() );
551 startAlarm( mAlarmMessage, filename); 551 startAlarm( mAlarmMessage, filename);
552 return; 552 return;
553 } 553 }
554 if ( mess.left( 11 ) == "timer_alarm") { 554 if ( mess.left( 11 ) == "timer_alarm") {
555 //mTimerTime = 0; 555 //mTimerTime = 0;
556 startAlarm( mess.mid( 11 ), filename ); 556 startAlarm( mess.mid( 11 ), filename );
557 return; 557 return;
558 } 558 }
559 if ( mess.left( 10 ) == "proc_alarm") { 559 if ( mess.left( 10 ) == "proc_alarm") {
560 bool error = false; 560 bool error = false;
561 int len = mess.mid( 10 ).find("+++"); 561 int len = mess.mid( 10 ).find("+++");
562 if ( len < 2 ) 562 if ( len < 2 )
563 error = true; 563 error = true;
564 else { 564 else {
565 tempfilename = mess.mid( 10, len ); 565 tempfilename = mess.mid( 10, len );
566 if ( !QFile::exists( tempfilename ) ) 566 if ( !QFile::exists( tempfilename ) )
567 error = true; 567 error = true;
568 } 568 }
569 if ( error ) { 569 if ( error ) {
570 mAlarmMessage = "Procedure Alarm\nError - File not found\n"; 570 mAlarmMessage = "Procedure Alarm\nError - File not found\n";
571 mAlarmMessage += mess.mid( 10+len+3+9 ); 571 mAlarmMessage += mess.mid( 10+len+3+9 );
572 } else { 572 } else {
573 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent"); 573 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent");
574 //qDebug("-----system command %s ",tempfilename.latin1() ); 574 //qDebug("-----system command %s ",tempfilename.latin1() );
575#ifndef _WIN32_ 575#ifndef _WIN32_
576 if ( vfork () == 0 ) { 576 if ( vfork () == 0 ) {
577 execl ( tempfilename.latin1(), 0 ); 577 execl ( tempfilename.latin1(), 0 );
578 return; 578 return;
579 } 579 }
580#else 580#else
581 QProcess* p = new QProcess(); 581 QProcess* p = new QProcess();
582 p->addArgument( tempfilename.latin1() ); 582 p->addArgument( tempfilename.latin1() );
583 p->start(); 583 p->start();
584 return; 584 return;
585#endif 585#endif
586 586
587 return; 587 return;
588 } 588 }
589 589
590 //qDebug("+++++++system command %s ",tempfilename.latin1() ); 590 //qDebug("+++++++system command %s ",tempfilename.latin1() );
591 } 591 }
592 if ( mess.left( 11 ) == "audio_alarm") { 592 if ( mess.left( 11 ) == "audio_alarm") {
593 bool error = false; 593 bool error = false;
594 int len = mess.mid( 11 ).find("+++"); 594 int len = mess.mid( 11 ).find("+++");
595 if ( len < 2 ) 595 if ( len < 2 )
596 error = true; 596 error = true;
597 else { 597 else {
598 tempfilename = mess.mid( 11, len ); 598 tempfilename = mess.mid( 11, len );
599 if ( !QFile::exists( tempfilename ) ) 599 if ( !QFile::exists( tempfilename ) )
600 error = true; 600 error = true;
601 } 601 }
602 if ( ! error ) { 602 if ( ! error ) {
603 filename = tempfilename; 603 filename = tempfilename;
604 } 604 }
605 mAlarmMessage = mess.mid( 11+len+3+9 ); 605 mAlarmMessage = mess.mid( 11+len+3+9 );
606 //qDebug("audio file command %s ",tempfilename.latin1() ); 606 //qDebug("audio file command %s ",tempfilename.latin1() );
607 } 607 }
608 if ( mess.left( 9 ) == "cal_alarm") { 608 if ( mess.left( 9 ) == "cal_alarm") {
609 mAlarmMessage = mess.mid( 9 ) ; 609 mAlarmMessage = mess.mid( 9 ) ;
610 } 610 }
611 611
612 startAlarm( mAlarmMessage, filename ); 612 startAlarm( mAlarmMessage, filename );
613 613
614 614
615} 615}
616 616
617void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti ) 617void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti )
618{ 618{
619 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 619 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
620 620
621 mSuspendAlarmNotification = noti; 621 mSuspendAlarmNotification = noti;
622 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000; 622 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000;
623 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000); 623 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000);
624 mSuspendTimer->start( ms , true ); 624 mSuspendTimer->start( ms , true );
625 625
626} 626}
627 627
628void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti ) 628void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti )
629{ 629{
630 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 630 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
631 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 631 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
632#ifndef DESKTOP_VERSION 632#ifndef DESKTOP_VERSION
633 AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() ); 633 AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() );
634#endif 634#endif
635 return; 635 return;
636 } 636 }
637 int maxSec; 637 int maxSec;
638 //maxSec = 5; //testing only 638 //maxSec = 5; //testing only
639 maxSec = 86400+3600; // one day+1hour 639 maxSec = 86400+3600; // one day+1hour
640 mAlarmNotification = noti; 640 mAlarmNotification = noti;
641 int sec = QDateTime::currentDateTime().secsTo( qdt ); 641 int sec = QDateTime::currentDateTime().secsTo( qdt );
642 if ( sec > maxSec ) { 642 if ( sec > maxSec ) {
643 mRecheckAlarmTimer->start( maxSec * 1000 ); 643 mRecheckAlarmTimer->start( maxSec * 1000 );
644 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec ); 644 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec );
645 return; 645 return;
646 } else { 646 } else {
647 mRecheckAlarmTimer->stop(); 647 mRecheckAlarmTimer->stop();
648 } 648 }
649 //qDebug("Alarm timer started with secs: %d ", sec); 649 //qDebug("Alarm timer started with secs: %d ", sec);
650 mAlarmTimer->start( sec *1000 , true ); 650 mAlarmTimer->start( sec *1000 , true );
651 651
652} 652}
653// called by mRecheckAlarmTimer to get next alarm 653// called by mRecheckAlarmTimer to get next alarm
654// we need this, because a QTimer has only a max range of 25 days 654// we need this, because a QTimer has only a max range of 25 days
655void CalendarView::recheckTimerAlarm() 655void CalendarView::recheckTimerAlarm()
656{ 656{
657 mAlarmTimer->stop(); 657 mAlarmTimer->stop();
658 mRecheckAlarmTimer->stop(); 658 mRecheckAlarmTimer->stop();
659 mCalendar->checkAlarmForIncidence( 0, true ); 659 mCalendar->checkAlarmForIncidence( 0, true );
660} 660}
661void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti ) 661void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti )
662{ 662{
663 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 663 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
664 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 664 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
665#ifndef DESKTOP_VERSION 665#ifndef DESKTOP_VERSION
666 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() ); 666 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() );
667#endif 667#endif
668 return; 668 return;
669 } 669 }
670 mAlarmTimer->stop(); 670 mAlarmTimer->stop();
671} 671}
672void CalendarView::selectWeekNum ( int num ) 672void CalendarView::selectWeekNum ( int num )
673{ 673{
674 dateNavigator()->selectWeek( num ); 674 dateNavigator()->selectWeek( num );
675 mViewManager->showWeekView(); 675 mViewManager->showWeekView();
676} 676}
677KOViewManager *CalendarView::viewManager() 677KOViewManager *CalendarView::viewManager()
678{ 678{
679 return mViewManager; 679 return mViewManager;
680} 680}
681 681
682KODialogManager *CalendarView::dialogManager() 682KODialogManager *CalendarView::dialogManager()
683{ 683{
684 return mDialogManager; 684 return mDialogManager;
685} 685}
686 686
687QDate CalendarView::startDate() 687QDate CalendarView::startDate()
688{ 688{
689 DateList dates = mNavigator->selectedDates(); 689 DateList dates = mNavigator->selectedDates();
690 690
691 return dates.first(); 691 return dates.first();
692} 692}
693 693
694QDate CalendarView::endDate() 694QDate CalendarView::endDate()
695{ 695{
696 DateList dates = mNavigator->selectedDates(); 696 DateList dates = mNavigator->selectedDates();
697 697
698 return dates.last(); 698 return dates.last();
699} 699}
700 700
701 701
702void CalendarView::createPrinter() 702void CalendarView::createPrinter()
703{ 703{
704#ifndef KORG_NOPRINTER 704#ifndef KORG_NOPRINTER
705 if (!mCalPrinter) { 705 if (!mCalPrinter) {
706 mCalPrinter = new CalPrinter(this, mCalendar); 706 mCalPrinter = new CalPrinter(this, mCalendar);
707 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig())); 707 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig()));
708 } 708 }
709#endif 709#endif
710} 710}
711 711
712 712
713//KOPrefs::instance()->mWriteBackFile 713//KOPrefs::instance()->mWriteBackFile
714//KOPrefs::instance()->mWriteBackExistingOnly 714//KOPrefs::instance()->mWriteBackExistingOnly
715 715
716// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); 716// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict"));
717// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); 717// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict"));
718// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); 718// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict"));
719// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); 719// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict"));
720// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); 720// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always"));
721// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); 721// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always"));
722 722
723int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) 723int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full )
724{ 724{
725 725
726 // 0 equal 726 // 0 equal
727 // 1 take local 727 // 1 take local
728 // 2 take remote 728 // 2 take remote
729 // 3 cancel 729 // 3 cancel
730 QDateTime lastSync = mLastCalendarSync; 730 QDateTime lastSync = mLastCalendarSync;
731 QDateTime localMod = local->lastModified(); 731 QDateTime localMod = local->lastModified();
732 QDateTime remoteMod = remote->lastModified(); 732 QDateTime remoteMod = remote->lastModified();
733 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 733 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
734 bool remCh, locCh; 734 bool remCh, locCh;
735 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 735 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
736 //if ( remCh ) 736 //if ( remCh )
737 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 737 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
738 locCh = ( localMod > mLastCalendarSync ); 738 locCh = ( localMod > mLastCalendarSync );
739 if ( !remCh && ! locCh ) { 739 if ( !remCh && ! locCh ) {
740 //qDebug("both not changed "); 740 //qDebug("both not changed ");
741 lastSync = localMod.addDays(1); 741 lastSync = localMod.addDays(1);
742 if ( mode <= SYNC_PREF_ASK ) 742 if ( mode <= SYNC_PREF_ASK )
743 return 0; 743 return 0;
744 } else { 744 } else {
745 if ( locCh ) { 745 if ( locCh ) {
746 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1()); 746 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1());
747 lastSync = localMod.addDays( -1 ); 747 lastSync = localMod.addDays( -1 );
748 if ( !remCh ) 748 if ( !remCh )
749 remoteMod = ( lastSync.addDays( -1 ) ); 749 remoteMod = ( lastSync.addDays( -1 ) );
750 } else { 750 } else {
751 //qDebug(" not loc changed "); 751 //qDebug(" not loc changed ");
752 lastSync = localMod.addDays( 1 ); 752 lastSync = localMod.addDays( 1 );
753 if ( remCh ) 753 if ( remCh )
754 remoteMod =( lastSync.addDays( 1 ) ); 754 remoteMod =( lastSync.addDays( 1 ) );
755 755
756 } 756 }
757 } 757 }
758 full = true; 758 full = true;
759 if ( mode < SYNC_PREF_ASK ) 759 if ( mode < SYNC_PREF_ASK )
760 mode = SYNC_PREF_ASK; 760 mode = SYNC_PREF_ASK;
761 } else { 761 } else {
762 if ( localMod == remoteMod ) 762 if ( localMod == remoteMod )
763 // if ( local->revision() == remote->revision() ) 763 // if ( local->revision() == remote->revision() )
764 return 0; 764 return 0;
765 765
766 } 766 }
767 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 767 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
768 768
769 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision()); 769 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision());
770 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() ); 770 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() );
771 //full = true; //debug only 771 //full = true; //debug only
772 if ( full ) { 772 if ( full ) {
773 bool equ = false; 773 bool equ = false;
774 if ( local->type() == "Event" ) { 774 if ( local->type() == "Event" ) {
775 equ = (*((Event*) local) == *((Event*) remote)); 775 equ = (*((Event*) local) == *((Event*) remote));
776 } 776 }
777 else if ( local->type() =="Todo" ) 777 else if ( local->type() =="Todo" )
778 equ = (*((Todo*) local) == (*(Todo*) remote)); 778 equ = (*((Todo*) local) == (*(Todo*) remote));
779 else if ( local->type() =="Journal" ) 779 else if ( local->type() =="Journal" )
780 equ = (*((Journal*) local) == *((Journal*) remote)); 780 equ = (*((Journal*) local) == *((Journal*) remote));
781 if ( equ ) { 781 if ( equ ) {
782 //qDebug("equal "); 782 //qDebug("equal ");
783 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 783 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
784 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 784 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
785 } 785 }
786 if ( mode < SYNC_PREF_FORCE_LOCAL ) 786 if ( mode < SYNC_PREF_FORCE_LOCAL )
787 return 0; 787 return 0;
788 788
789 }//else //debug only 789 }//else //debug only
790 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 790 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
791 } 791 }
792 int result; 792 int result;
793 bool localIsNew; 793 bool localIsNew;
794 //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() ); 794 //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() );
795 795
796 if ( full && mode < SYNC_PREF_NEWEST ) 796 if ( full && mode < SYNC_PREF_NEWEST )
797 mode = SYNC_PREF_ASK; 797 mode = SYNC_PREF_ASK;
798 798
799 switch( mode ) { 799 switch( mode ) {
800 case SYNC_PREF_LOCAL: 800 case SYNC_PREF_LOCAL:
801 if ( lastSync > remoteMod ) 801 if ( lastSync > remoteMod )
802 return 1; 802 return 1;
803 if ( lastSync > localMod ) 803 if ( lastSync > localMod )
804 return 2; 804 return 2;
805 return 1; 805 return 1;
806 break; 806 break;
807 case SYNC_PREF_REMOTE: 807 case SYNC_PREF_REMOTE:
808 if ( lastSync > remoteMod ) 808 if ( lastSync > remoteMod )
809 return 1; 809 return 1;
810 if ( lastSync > localMod ) 810 if ( lastSync > localMod )
811 return 2; 811 return 2;
812 return 2; 812 return 2;
813 break; 813 break;
814 case SYNC_PREF_NEWEST: 814 case SYNC_PREF_NEWEST:
815 if ( localMod > remoteMod ) 815 if ( localMod > remoteMod )
816 return 1; 816 return 1;
817 else 817 else
818 return 2; 818 return 2;
819 break; 819 break;
820 case SYNC_PREF_ASK: 820 case SYNC_PREF_ASK:
821 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 821 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
822 if ( lastSync > remoteMod ) 822 if ( lastSync > remoteMod )
823 return 1; 823 return 1;
824 if ( lastSync > localMod ) 824 if ( lastSync > localMod )
825 return 2; 825 return 2;
826 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 826 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
827 localIsNew = localMod >= remoteMod; 827 localIsNew = localMod >= remoteMod;
828 if ( localIsNew ) 828 if ( localIsNew )
829 getEventViewerDialog()->setColorMode( 1 ); 829 getEventViewerDialog()->setColorMode( 1 );
830 else 830 else
831 getEventViewerDialog()->setColorMode( 2 ); 831 getEventViewerDialog()->setColorMode( 2 );
832 getEventViewerDialog()->setIncidence(local); 832 getEventViewerDialog()->setIncidence(local);
833 if ( localIsNew ) 833 if ( localIsNew )
834 getEventViewerDialog()->setColorMode( 2 ); 834 getEventViewerDialog()->setColorMode( 2 );
835 else 835 else
836 getEventViewerDialog()->setColorMode( 1 ); 836 getEventViewerDialog()->setColorMode( 1 );
837 getEventViewerDialog()->addIncidence(remote); 837 getEventViewerDialog()->addIncidence(remote);
838 getEventViewerDialog()->setColorMode( 0 ); 838 getEventViewerDialog()->setColorMode( 0 );
839 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); 839 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() );
840 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); 840 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!"));
841 getEventViewerDialog()->showMe(); 841 getEventViewerDialog()->showMe();
842 result = getEventViewerDialog()->executeS( localIsNew ); 842 result = getEventViewerDialog()->executeS( localIsNew );
843 return result; 843 return result;
844 844
845 break; 845 break;
846 case SYNC_PREF_FORCE_LOCAL: 846 case SYNC_PREF_FORCE_LOCAL:
847 return 1; 847 return 1;
848 break; 848 break;
849 case SYNC_PREF_FORCE_REMOTE: 849 case SYNC_PREF_FORCE_REMOTE:
850 return 2; 850 return 2;
851 break; 851 break;
852 852
853 default: 853 default:
854 // SYNC_PREF_TAKE_BOTH not implemented 854 // SYNC_PREF_TAKE_BOTH not implemented
855 break; 855 break;
856 } 856 }
857 return 0; 857 return 0;
858} 858}
859Event* CalendarView::getLastSyncEvent() 859Event* CalendarView::getLastSyncEvent()
860{ 860{
861 Event* lse; 861 Event* lse;
862 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 862 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
863 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); 863 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice );
864 if (!lse) { 864 if (!lse) {
865 lse = new Event(); 865 lse = new Event();
866 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); 866 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice );
867 QString sum = ""; 867 QString sum = "";
868 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) 868 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
869 sum = "E: "; 869 sum = "E: ";
870 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); 870 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event"));
871 lse->setDtStart( mLastCalendarSync ); 871 lse->setDtStart( mLastCalendarSync );
872 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 872 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
873 lse->setCategories( i18n("SyncEvent") ); 873 lse->setCategories( i18n("SyncEvent") );
874 lse->setReadOnly( true ); 874 lse->setReadOnly( true );
875 mCalendar->addEvent( lse ); 875 mCalendar->addEvent( lse );
876 } 876 }
877 877
878 return lse; 878 return lse;
879 879
880} 880}
881 881
882// we check, if the to delete event has a id for a profile 882// we check, if the to delete event has a id for a profile
883// if yes, we set this id in the profile to delete 883// if yes, we set this id in the profile to delete
884void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) 884void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete )
885{ 885{
886 if ( lastSync.count() == 0 ) { 886 if ( lastSync.count() == 0 ) {
887 //qDebug(" lastSync.count() == 0"); 887 //qDebug(" lastSync.count() == 0");
888 return; 888 return;
889 } 889 }
890 if ( toDelete->type() == "Journal" ) 890 if ( toDelete->type() == "Journal" )
891 return; 891 return;
892 892
893 Event* eve = lastSync.first(); 893 Event* eve = lastSync.first();
894 894
895 while ( eve ) { 895 while ( eve ) {
896 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name 896 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name
897 if ( !id.isEmpty() ) { 897 if ( !id.isEmpty() ) {
898 QString des = eve->description(); 898 QString des = eve->description();
899 QString pref = "e"; 899 QString pref = "e";
900 if ( toDelete->type() == "Todo" ) 900 if ( toDelete->type() == "Todo" )
901 pref = "t"; 901 pref = "t";
902 des += pref+ id + ","; 902 des += pref+ id + ",";
903 eve->setReadOnly( false ); 903 eve->setReadOnly( false );
904 eve->setDescription( des ); 904 eve->setDescription( des );
905 //qDebug("setdes %s ", des.latin1()); 905 //qDebug("setdes %s ", des.latin1());
906 eve->setReadOnly( true ); 906 eve->setReadOnly( true );
907 } 907 }
908 eve = lastSync.next(); 908 eve = lastSync.next();
909 } 909 }
910 910
911} 911}
912void CalendarView::checkExternalId( Incidence * inc ) 912void CalendarView::checkExternalId( Incidence * inc )
913{ 913{
914 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; 914 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ;
915 checkExternSyncEvent( lastSync, inc ); 915 checkExternSyncEvent( lastSync, inc );
916 916
917} 917}
918bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) 918bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode )
919{ 919{
920 bool syncOK = true; 920 bool syncOK = true;
921 int addedEvent = 0; 921 int addedEvent = 0;
922 int addedEventR = 0; 922 int addedEventR = 0;
923 int deletedEventR = 0; 923 int deletedEventR = 0;
924 int deletedEventL = 0; 924 int deletedEventL = 0;
925 int changedLocal = 0; 925 int changedLocal = 0;
926 int changedRemote = 0; 926 int changedRemote = 0;
927 int filteredIN = 0;
928 int filteredOUT = 0;
927 //QPtrList<Event> el = local->rawEvents(); 929 //QPtrList<Event> el = local->rawEvents();
928 Event* eventR; 930 Event* eventR;
929 QString uid; 931 QString uid;
930 int take; 932 int take;
931 Event* eventL; 933 Event* eventL;
932 Event* eventRSync; 934 Event* eventRSync;
933 Event* eventLSync; 935 Event* eventLSync;
934 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); 936 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents();
935 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); 937 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents();
936 bool fullDateRange = false; 938 bool fullDateRange = false;
937 local->resetTempSyncStat(); 939 local->resetTempSyncStat();
938 mLastCalendarSync = QDateTime::currentDateTime(); 940 mLastCalendarSync = QDateTime::currentDateTime();
939 if ( mSyncManager->syncWithDesktop() ) { 941 if ( mSyncManager->syncWithDesktop() ) {
940 remote->resetPilotStat(1); 942 remote->resetPilotStat(1);
941 if ( KSyncManager::mRequestedSyncEvent.isValid() ) { 943 if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
942 mLastCalendarSync = KSyncManager::mRequestedSyncEvent; 944 mLastCalendarSync = KSyncManager::mRequestedSyncEvent;
943 qDebug("using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() ); 945 qDebug("using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() );
944 } else { 946 } else {
945 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); 947 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime ");
946 } 948 }
947 } 949 }
948 QDateTime modifiedCalendar = mLastCalendarSync; 950 QDateTime modifiedCalendar = mLastCalendarSync;
949 eventLSync = getLastSyncEvent(); 951 eventLSync = getLastSyncEvent();
950 eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); 952 eventR = remote->event("last-syncEvent-"+mCurrentSyncName );
951 if ( eventR ) { 953 if ( eventR ) {
952 eventRSync = (Event*) eventR->clone(); 954 eventRSync = (Event*) eventR->clone();
953 remote->deleteEvent(eventR ); 955 remote->deleteEvent(eventR );
954 956
955 } else { 957 } else {
956 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) { 958 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) {
957 eventRSync = (Event*)eventLSync->clone(); 959 eventRSync = (Event*)eventLSync->clone();
958 } else { 960 } else {
959 fullDateRange = true; 961 fullDateRange = true;
960 eventRSync = new Event(); 962 eventRSync = new Event();
961 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); 963 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event"));
962 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); 964 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName );
963 eventRSync->setDtStart( mLastCalendarSync ); 965 eventRSync->setDtStart( mLastCalendarSync );
964 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 966 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
965 eventRSync->setCategories( i18n("SyncEvent") ); 967 eventRSync->setCategories( i18n("SyncEvent") );
966 } 968 }
967 } 969 }
968 if ( eventLSync->dtStart() == mLastCalendarSync ) 970 if ( eventLSync->dtStart() == mLastCalendarSync )
969 fullDateRange = true; 971 fullDateRange = true;
970 972
971 if ( ! fullDateRange ) { 973 if ( ! fullDateRange ) {
972 if ( eventLSync->dtStart() != eventRSync->dtStart() ) { 974 if ( eventLSync->dtStart() != eventRSync->dtStart() ) {
973 975
974 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); 976 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() );
975 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); 977 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec());
976 fullDateRange = true; 978 fullDateRange = true;
977 } 979 }
978 } 980 }
979 if ( mSyncManager->syncWithDesktop() ) { 981 if ( mSyncManager->syncWithDesktop() ) {
980 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync ); 982 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync );
981 } 983 }
982 if ( fullDateRange ) 984 if ( fullDateRange )
983 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 985 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
984 else 986 else
985 mLastCalendarSync = eventLSync->dtStart(); 987 mLastCalendarSync = eventLSync->dtStart();
986 // for resyncing if own file has changed 988 // for resyncing if own file has changed
987 if ( mCurrentSyncDevice == "deleteaftersync" ) { 989 if ( mCurrentSyncDevice == "deleteaftersync" ) {
988 mLastCalendarSync = loadedFileVersion; 990 mLastCalendarSync = loadedFileVersion;
989 //qDebug("setting mLastCalendarSync "); 991 //qDebug("setting mLastCalendarSync ");
990 } 992 }
991 //qDebug("*************************** "); 993 //qDebug("*************************** ");
992 qDebug("mLastCalendarSync %s full: %d",mLastCalendarSync.toString().latin1(), fullDateRange); 994 qDebug("mLastCalendarSync %s full: %d",mLastCalendarSync.toString().latin1(), fullDateRange);
993 QPtrList<Incidence> er = remote->rawIncidences(); 995 QPtrList<Incidence> er = remote->rawIncidences();
994 Incidence* inR = er.first(); 996 Incidence* inR = er.first();
995 Incidence* inL; 997 Incidence* inL;
996 QProgressBar bar( er.count(),0 ); 998 QProgressBar bar( er.count(),0 );
997 bar.setCaption (i18n("Syncing - close to abort!") ); 999 bar.setCaption (i18n("Syncing - close to abort!") );
998 1000
999 // ************** setting up filter ************* 1001 // ************** setting up filter *************
1000 CalFilter *filterIN = 0; 1002 CalFilter *filterIN = 0;
1001 CalFilter *filterOUT = 0; 1003 CalFilter *filterOUT = 0;
1002 CalFilter *filter = mFilters.first(); 1004 CalFilter *filter = mFilters.first();
1003 while(filter) { 1005 while(filter) {
1004 if ( filter->name() == mSyncManager->mFilterInCal ) 1006 if ( filter->name() == mSyncManager->mFilterInCal )
1005 filterIN = filter; 1007 filterIN = filter;
1006 if ( filter->name() == mSyncManager->mFilterOutCal ) 1008 if ( filter->name() == mSyncManager->mFilterOutCal )
1007 filterOUT = filter; 1009 filterOUT = filter;
1008 filter = mFilters.next(); 1010 filter = mFilters.next();
1009 } 1011 }
1010 int w = 300; 1012 int w = 300;
1011 if ( QApplication::desktop()->width() < 320 ) 1013 if ( QApplication::desktop()->width() < 320 )
1012 w = 220; 1014 w = 220;
1013 int h = bar.sizeHint().height() ; 1015 int h = bar.sizeHint().height() ;
1014 int dw = QApplication::desktop()->width(); 1016 int dw = QApplication::desktop()->width();
1015 int dh = QApplication::desktop()->height(); 1017 int dh = QApplication::desktop()->height();
1016 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1018 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1017 bar.show(); 1019 bar.show();
1018 int modulo = (er.count()/10)+1; 1020 int modulo = (er.count()/10)+1;
1019 int incCounter = 0; 1021 int incCounter = 0;
1020 while ( inR ) { 1022 while ( inR ) {
1021 if ( ! bar.isVisible() ) 1023 if ( ! bar.isVisible() )
1022 return false; 1024 return false;
1023 if ( incCounter % modulo == 0 ) 1025 if ( incCounter % modulo == 0 )
1024 bar.setProgress( incCounter ); 1026 bar.setProgress( incCounter );
1025 ++incCounter; 1027 ++incCounter;
1026 uid = inR->uid(); 1028 uid = inR->uid();
1027 bool skipIncidence = false; 1029 bool skipIncidence = false;
1028 if ( uid.left(15) == QString("last-syncEvent-") ) 1030 if ( uid.left(15) == QString("last-syncEvent-") )
1029 skipIncidence = true; 1031 skipIncidence = true;
1030 QString idS; 1032 QString idS;
1031 qApp->processEvents(); 1033 qApp->processEvents();
1032 if ( !skipIncidence ) { 1034 if ( !skipIncidence ) {
1033 inL = local->incidence( uid ); 1035 inL = local->incidence( uid );
1034 if ( inL ) { // maybe conflict - same uid in both calendars 1036 if ( inL ) { // maybe conflict - same uid in both calendars
1035 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1037 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1036 //qDebug("take %d %s ", take, inL->summary().latin1()); 1038 //qDebug("take %d %s ", take, inL->summary().latin1());
1037 if ( take == 3 ) 1039 if ( take == 3 )
1038 return false; 1040 return false;
1039 if ( take == 1 ) {// take local ********************** 1041 if ( take == 1 ) {// take local **********************
1040 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 1042 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
1041 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1043 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1042 else 1044 else
1043 idS = inR->IDStr(); 1045 idS = inR->IDStr();
1044 remote->deleteIncidence( inR ); 1046 remote->deleteIncidence( inR );
1045 inR = inL->clone(); 1047 inR = inL->clone();
1046 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1048 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1047 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 1049 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
1048 inR->setIDStr( idS ); 1050 inR->setIDStr( idS );
1049 remote->addIncidence( inR ); 1051 remote->addIncidence( inR );
1050 if ( mSyncManager->syncWithDesktop() ) 1052 if ( mSyncManager->syncWithDesktop() )
1051 inR->setPilotId( 2 ); 1053 inR->setPilotId( 2 );
1052 ++changedRemote; 1054 ++changedRemote;
1053 } else {// take remote ********************** 1055 } else {// take remote **********************
1054 idS = inL->IDStr(); 1056 idS = inL->IDStr();
1055 int pid = inL->pilotId(); 1057 int pid = inL->pilotId();
1056 local->deleteIncidence( inL ); 1058 local->deleteIncidence( inL );
1057 inL = inR->clone(); 1059 inL = inR->clone();
1058 if ( mSyncManager->syncWithDesktop() ) 1060 if ( mSyncManager->syncWithDesktop() )
1059 inL->setPilotId( pid ); 1061 inL->setPilotId( pid );
1060 inL->setIDStr( idS ); 1062 inL->setIDStr( idS );
1061 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1063 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1062 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1064 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1063 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1065 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1064 } 1066 }
1065 local->addIncidence( inL ); 1067 local->addIncidence( inL );
1066 ++changedLocal; 1068 ++changedLocal;
1067 } 1069 }
1068 } 1070 }
1069 } else { // no conflict ********** add or delete remote 1071 } else { // no conflict ********** add or delete remote
1070 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){ 1072 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){
1071 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1073 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1072 QString des = eventLSync->description(); 1074 QString des = eventLSync->description();
1073 QString pref = "e"; 1075 QString pref = "e";
1074 if ( inR->type() == "Todo" ) 1076 if ( inR->type() == "Todo" )
1075 pref = "t"; 1077 pref = "t";
1076 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 1078 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1077 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1079 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1078 //remote->deleteIncidence( inR ); 1080 //remote->deleteIncidence( inR );
1079 ++deletedEventR; 1081 ++deletedEventR;
1080 } else { 1082 } else {
1081 inR->setLastModified( modifiedCalendar ); 1083 inR->setLastModified( modifiedCalendar );
1082 inL = inR->clone(); 1084 inL = inR->clone();
1083 inL->setIDStr( ":" ); 1085 inL->setIDStr( ":" );
1084 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1086 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1085 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1087 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1086 local->addIncidence( inL ); 1088 local->addIncidence( inL );
1087 ++addedEvent; 1089 ++addedEvent;
1088 1090
1089 } 1091 }
1090 } else { 1092 } else {
1091 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 1093 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1092 inR->setLastModified( modifiedCalendar ); 1094 inR->setLastModified( modifiedCalendar );
1093 inL = inR->clone(); 1095 inL = inR->clone();
1094 inL->setIDStr( ":" ); 1096 inL->setIDStr( ":" );
1095 local->addIncidence( inL ); 1097 local->addIncidence( inL );
1096 ++addedEvent; 1098 ++addedEvent;
1097 1099
1098 } else { 1100 } else {
1099 checkExternSyncEvent(eventRSyncSharp, inR); 1101 checkExternSyncEvent(eventRSyncSharp, inR);
1100 remote->deleteIncidence( inR ); 1102 remote->deleteIncidence( inR );
1101 ++deletedEventR; 1103 ++deletedEventR;
1102 } 1104 }
1103 } 1105 }
1106 } else {
1107 ++filteredIN;
1104 } 1108 }
1105 } 1109 }
1106 } 1110 }
1107 inR = er.next(); 1111 inR = er.next();
1108 } 1112 }
1109 QPtrList<Incidence> el = local->rawIncidences(); 1113 QPtrList<Incidence> el = local->rawIncidences();
1110 inL = el.first(); 1114 inL = el.first();
1111 modulo = (el.count()/10)+1; 1115 modulo = (el.count()/10)+1;
1112 bar.setCaption (i18n("Add / remove events") ); 1116 bar.setCaption (i18n("Add / remove events") );
1113 bar.setTotalSteps ( el.count() ) ; 1117 bar.setTotalSteps ( el.count() ) ;
1114 bar.show(); 1118 bar.show();
1115 incCounter = 0; 1119 incCounter = 0;
1116 1120
1117 while ( inL ) { 1121 while ( inL ) {
1118 1122
1119 qApp->processEvents(); 1123 qApp->processEvents();
1120 if ( ! bar.isVisible() ) 1124 if ( ! bar.isVisible() )
1121 return false; 1125 return false;
1122 if ( incCounter % modulo == 0 ) 1126 if ( incCounter % modulo == 0 )
1123 bar.setProgress( incCounter ); 1127 bar.setProgress( incCounter );
1124 ++incCounter; 1128 ++incCounter;
1125 uid = inL->uid(); 1129 uid = inL->uid();
1126 bool skipIncidence = false; 1130 bool skipIncidence = false;
1127 if ( uid.left(15) == QString("last-syncEvent-") ) 1131 if ( uid.left(15) == QString("last-syncEvent-") )
1128 skipIncidence = true; 1132 skipIncidence = true;
1129 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) 1133 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" )
1130 skipIncidence = true; 1134 skipIncidence = true;
1131 if ( filterOUT && ! filterOUT->filterCalendarItem( inL ) ){
1132 skipIncidence = true;
1133 }
1134 if ( !skipIncidence ) { 1135 if ( !skipIncidence ) {
1135 inR = remote->incidence( uid ); 1136 inR = remote->incidence( uid );
1136 if ( ! inR ) { // no conflict ********** add or delete local 1137 if ( ! inR ) {
1137 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1138 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){
1138 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1139 // no conflict ********** add or delete local
1139 checkExternSyncEvent(eventLSyncSharp, inL); 1140 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1140 local->deleteIncidence( inL ); 1141 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1141 ++deletedEventL; 1142 checkExternSyncEvent(eventLSyncSharp, inL);
1142 } else { 1143 local->deleteIncidence( inL );
1143 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1144 ++deletedEventL;
1144 inL->removeID(mCurrentSyncDevice ); 1145 } else {
1145 ++addedEventR; 1146 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1146 //qDebug("remote added Incidence %s ", inL->summary().latin1()); 1147 inL->removeID(mCurrentSyncDevice );
1147 inL->setLastModified( modifiedCalendar ); 1148 ++addedEventR;
1148 inR = inL->clone(); 1149 //qDebug("remote added Incidence %s ", inL->summary().latin1());
1149 inR->setIDStr( ":" ); 1150 inL->setLastModified( modifiedCalendar );
1150 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1151 inR = inL->clone();
1151 remote->addIncidence( inR ); 1152 inR->setIDStr( ":" );
1153 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1154 remote->addIncidence( inR );
1155 }
1152 } 1156 }
1153 }
1154 } else {
1155 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1156 checkExternSyncEvent(eventLSyncSharp, inL);
1157 local->deleteIncidence( inL );
1158 ++deletedEventL;
1159 } else { 1157 } else {
1160 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1158 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1161 ++addedEventR; 1159 checkExternSyncEvent(eventLSyncSharp, inL);
1162 inL->setLastModified( modifiedCalendar ); 1160 local->deleteIncidence( inL );
1163 inR = inL->clone(); 1161 ++deletedEventL;
1164 inR->setIDStr( ":" ); 1162 } else {
1165 remote->addIncidence( inR ); 1163 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1164 ++addedEventR;
1165 inL->setLastModified( modifiedCalendar );
1166 inR = inL->clone();
1167 inR->setIDStr( ":" );
1168 remote->addIncidence( inR );
1169 }
1166 } 1170 }
1167 } 1171 }
1172 } else {
1173 ++filteredOUT;
1168 } 1174 }
1169 } 1175 }
1170 } 1176 }
1171 inL = el.next(); 1177 inL = el.next();
1172 } 1178 }
1173 int delFut = 0; 1179 int delFut = 0;
1174 int remRem = 0; 1180 int remRem = 0;
1175 if ( mSyncManager->mWriteBackInFuture ) { 1181 if ( mSyncManager->mWriteBackInFuture ) {
1176 er = remote->rawIncidences(); 1182 er = remote->rawIncidences();
1177 remRem = er.count(); 1183 remRem = er.count();
1178 inR = er.first(); 1184 inR = er.first();
1179 QDateTime dt; 1185 QDateTime dt;
1180 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) ); 1186 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) );
1181 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 ); 1187 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 );
1182 while ( inR ) { 1188 while ( inR ) {
1183 if ( inR->type() == "Todo" ) { 1189 if ( inR->type() == "Todo" ) {
1184 Todo * t = (Todo*)inR; 1190 Todo * t = (Todo*)inR;
1185 if ( t->hasDueDate() ) 1191 if ( t->hasDueDate() )
1186 dt = t->dtDue(); 1192 dt = t->dtDue();
1187 else 1193 else
1188 dt = cur.addSecs( 62 ); 1194 dt = cur.addSecs( 62 );
1189 } 1195 }
1190 else if (inR->type() == "Event" ) { 1196 else if (inR->type() == "Event" ) {
1191 bool ok; 1197 bool ok;
1192 dt = inR->getNextOccurence( cur, &ok ); 1198 dt = inR->getNextOccurence( cur, &ok );
1193 if ( !ok ) 1199 if ( !ok )
1194 dt = cur.addSecs( -62 ); 1200 dt = cur.addSecs( -62 );
1195 } 1201 }
1196 else 1202 else
1197 dt = inR->dtStart(); 1203 dt = inR->dtStart();
1198 if ( dt < cur || dt > end ) { 1204 if ( dt < cur || dt > end ) {
1199 remote->deleteIncidence( inR ); 1205 remote->deleteIncidence( inR );
1200 ++delFut; 1206 ++delFut;
1201 } 1207 }
1202 inR = er.next(); 1208 inR = er.next();
1203 } 1209 }
1204 } 1210 }
1205 bar.hide(); 1211 bar.hide();
1206 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1212 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1207 eventLSync->setReadOnly( false ); 1213 eventLSync->setReadOnly( false );
1208 eventLSync->setDtStart( mLastCalendarSync ); 1214 eventLSync->setDtStart( mLastCalendarSync );
1209 eventRSync->setDtStart( mLastCalendarSync ); 1215 eventRSync->setDtStart( mLastCalendarSync );
1210 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1216 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1211 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1217 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1212 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1218 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1213 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1219 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1214 eventLSync->setReadOnly( true ); 1220 eventLSync->setReadOnly( true );
1215 qDebug("********** %d %d ", mGlobalSyncMode == SYNC_MODE_NORMAL, mSyncManager->syncWithDesktop() ); 1221 qDebug("********** %d %d ", mGlobalSyncMode == SYNC_MODE_NORMAL, mSyncManager->syncWithDesktop() );
1216 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal... 1222 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal...
1217 remote->addEvent( eventRSync ); 1223 remote->addEvent( eventRSync );
1218 else 1224 else
1219 delete eventRSync; 1225 delete eventRSync;
1220 QString mes; 1226 QString mes;
1221 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 ); 1227 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 );
1222 QString delmess; 1228 QString delmess;
1223 if ( delFut ) { 1229 if ( delFut ) {
1224 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); 1230 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);
1225 mes += delmess; 1231 mes += delmess;
1226 } 1232 }
1227 mes = i18n("Local calendar changed!\n") +mes; 1233 mes = i18n("Local calendar changed!\n") +mes;
1228 mCalendar->checkAlarmForIncidence( 0, true ); 1234 mCalendar->checkAlarmForIncidence( 0, true );
1229 qDebug( mes ); 1235 qDebug( mes );
1230 if ( mSyncManager->mShowSyncSummary ) { 1236 if ( mSyncManager->mShowSyncSummary ) {
1231 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, 1237 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes,
1232 i18n("KO/Pi Synchronization"),i18n("Write back"))) { 1238 i18n("KO/Pi Synchronization"),i18n("Write back"))) {
1233 qDebug("cancelled "); 1239 qDebug("cancelled ");
1234 return false; 1240 return false;
1235 } 1241 }
1236 } 1242 }
1237 return syncOK; 1243 return syncOK;
1238} 1244}
1239 1245
1240void CalendarView::setSyncDevice( QString s ) 1246void CalendarView::setSyncDevice( QString s )
1241{ 1247{
1242 mCurrentSyncDevice= s; 1248 mCurrentSyncDevice= s;
1243} 1249}
1244void CalendarView::setSyncName( QString s ) 1250void CalendarView::setSyncName( QString s )
1245{ 1251{
1246 mCurrentSyncName= s; 1252 mCurrentSyncName= s;
1247} 1253}
1248bool CalendarView::syncCalendar(QString filename, int mode) 1254bool CalendarView::syncCalendar(QString filename, int mode)
1249{ 1255{
1250 //qDebug("syncCalendar %s ", filename.latin1()); 1256 //qDebug("syncCalendar %s ", filename.latin1());
1251 mGlobalSyncMode = SYNC_MODE_NORMAL; 1257 mGlobalSyncMode = SYNC_MODE_NORMAL;
1252 CalendarLocal* calendar = new CalendarLocal(); 1258 CalendarLocal* calendar = new CalendarLocal();
1253 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1259 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1254 FileStorage* storage = new FileStorage( calendar ); 1260 FileStorage* storage = new FileStorage( calendar );
1255 bool syncOK = false; 1261 bool syncOK = false;
1256 storage->setFileName( filename ); 1262 storage->setFileName( filename );
1257 // qDebug("loading ... "); 1263 // qDebug("loading ... ");
1258 if ( storage->load() ) { 1264 if ( storage->load() ) {
1259 getEventViewerDialog()->setSyncMode( true ); 1265 getEventViewerDialog()->setSyncMode( true );
1260 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1266 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1261 getEventViewerDialog()->setSyncMode( false ); 1267 getEventViewerDialog()->setSyncMode( false );
1262 if ( syncOK ) { 1268 if ( syncOK ) {
1263 if ( mSyncManager->mWriteBackFile ) 1269 if ( mSyncManager->mWriteBackFile )
1264 { 1270 {
1265 storage->setSaveFormat( new ICalFormat() ); 1271 storage->setSaveFormat( new ICalFormat() );
1266 storage->save(); 1272 storage->save();
1267 } 1273 }
1268 } 1274 }
1269 setModified( true ); 1275 setModified( true );
1270 } 1276 }
1271 delete storage; 1277 delete storage;
1272 delete calendar; 1278 delete calendar;
1273 if ( syncOK ) 1279 if ( syncOK )
1274 updateView(); 1280 updateView();
1275 return syncOK; 1281 return syncOK;
1276} 1282}
1277 1283
1278void CalendarView::syncExternal( int mode ) 1284void CalendarView::syncExternal( int mode )
1279{ 1285{
1280 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1286 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1281 1287
1282 qApp->processEvents(); 1288 qApp->processEvents();
1283 CalendarLocal* calendar = new CalendarLocal(); 1289 CalendarLocal* calendar = new CalendarLocal();
1284 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1290 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1285 bool syncOK = false; 1291 bool syncOK = false;
1286 bool loadSuccess = false; 1292 bool loadSuccess = false;
1287 PhoneFormat* phoneFormat = 0; 1293 PhoneFormat* phoneFormat = 0;
1288 emit tempDisableBR(true); 1294 emit tempDisableBR(true);
1289#ifndef DESKTOP_VERSION 1295#ifndef DESKTOP_VERSION
1290 SharpFormat* sharpFormat = 0; 1296 SharpFormat* sharpFormat = 0;
1291 if ( mode == 0 ) { // sharp 1297 if ( mode == 0 ) { // sharp
1292 sharpFormat = new SharpFormat () ; 1298 sharpFormat = new SharpFormat () ;
1293 loadSuccess = sharpFormat->load( calendar, mCalendar ); 1299 loadSuccess = sharpFormat->load( calendar, mCalendar );
1294 1300
1295 } else 1301 } else
1296#endif 1302#endif
1297 if ( mode == 1 ) { // phone 1303 if ( mode == 1 ) { // phone
1298 phoneFormat = new PhoneFormat (mCurrentSyncDevice, 1304 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
1299 mSyncManager->mPhoneDevice, 1305 mSyncManager->mPhoneDevice,
1300 mSyncManager->mPhoneConnection, 1306 mSyncManager->mPhoneConnection,
1301 mSyncManager->mPhoneModel); 1307 mSyncManager->mPhoneModel);
1302 loadSuccess = phoneFormat->load( calendar,mCalendar); 1308 loadSuccess = phoneFormat->load( calendar,mCalendar);
1303 1309
1304 } else { 1310 } else {
1305 emit tempDisableBR(false); 1311 emit tempDisableBR(false);
1306 return; 1312 return;
1307 } 1313 }
1308 if ( loadSuccess ) { 1314 if ( loadSuccess ) {
1309 getEventViewerDialog()->setSyncMode( true ); 1315 getEventViewerDialog()->setSyncMode( true );
1310 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1316 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1311 getEventViewerDialog()->setSyncMode( false ); 1317 getEventViewerDialog()->setSyncMode( false );
1312 qApp->processEvents(); 1318 qApp->processEvents();
1313 if ( syncOK ) { 1319 if ( syncOK ) {
1314 if ( mSyncManager->mWriteBackFile ) 1320 if ( mSyncManager->mWriteBackFile )
1315 { 1321 {
1316 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1322 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1317 Incidence* inc = iL.first(); 1323 Incidence* inc = iL.first();
1318 if ( phoneFormat ) { 1324 if ( phoneFormat ) {
1319 while ( inc ) { 1325 while ( inc ) {
1320 inc->removeID(mCurrentSyncDevice); 1326 inc->removeID(mCurrentSyncDevice);
1321 inc = iL.next(); 1327 inc = iL.next();
1322 } 1328 }
1323 } 1329 }
1324#ifndef DESKTOP_VERSION 1330#ifndef DESKTOP_VERSION
1325 if ( sharpFormat ) 1331 if ( sharpFormat )
1326 sharpFormat->save(calendar); 1332 sharpFormat->save(calendar);
1327#endif 1333#endif
1328 if ( phoneFormat ) 1334 if ( phoneFormat )
1329 phoneFormat->save(calendar); 1335 phoneFormat->save(calendar);
1330 iL = calendar->rawIncidences(); 1336 iL = calendar->rawIncidences();
1331 inc = iL.first(); 1337 inc = iL.first();
1332 Incidence* loc; 1338 Incidence* loc;
1333 while ( inc ) { 1339 while ( inc ) {
1334 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 1340 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
1335 loc = mCalendar->incidence(inc->uid() ); 1341 loc = mCalendar->incidence(inc->uid() );
1336 if ( loc ) { 1342 if ( loc ) {
1337 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 1343 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
1338 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); 1344 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
1339 } 1345 }
1340 } 1346 }
1341 inc = iL.next(); 1347 inc = iL.next();
1342 } 1348 }
1343 Incidence* lse = getLastSyncEvent(); 1349 Incidence* lse = getLastSyncEvent();
1344 if ( lse ) { 1350 if ( lse ) {
1345 lse->setReadOnly( false ); 1351 lse->setReadOnly( false );
1346 lse->setDescription( "" ); 1352 lse->setDescription( "" );
1347 lse->setReadOnly( true ); 1353 lse->setReadOnly( true );
1348 } 1354 }
1349 } 1355 }
1350 } else { 1356 } else {
1351 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); 1357 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") );
1352 } 1358 }
1353 setModified( true ); 1359 setModified( true );
1354 } else { 1360 } else {
1355 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 1361 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
1356 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 1362 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
1357 question, i18n("Ok")) ; 1363 question, i18n("Ok")) ;
1358 1364
1359 } 1365 }
1360 delete calendar; 1366 delete calendar;
1361 updateView(); 1367 updateView();
1362 emit tempDisableBR(false); 1368 emit tempDisableBR(false);
1363 return ;//syncOK; 1369 return ;//syncOK;
1364 1370
1365} 1371}
1366 1372
1367bool CalendarView::importBday() 1373bool CalendarView::importBday()
1368{ 1374{
1369#ifndef KORG_NOKABC 1375#ifndef KORG_NOKABC
1370 1376
1371#ifdef DESKTOP_VERSION 1377#ifdef DESKTOP_VERSION
1372 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 1378 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
1373 KABC::AddressBook::Iterator it; 1379 KABC::AddressBook::Iterator it;
1374 int count = 0; 1380 int count = 0;
1375 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1381 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1376 ++count; 1382 ++count;
1377 } 1383 }
1378 QProgressBar bar(count,0 ); 1384 QProgressBar bar(count,0 );
1379 int w = 300; 1385 int w = 300;
1380 if ( QApplication::desktop()->width() < 320 ) 1386 if ( QApplication::desktop()->width() < 320 )
1381 w = 220; 1387 w = 220;
1382 int h = bar.sizeHint().height() ; 1388 int h = bar.sizeHint().height() ;
1383 int dw = QApplication::desktop()->width(); 1389 int dw = QApplication::desktop()->width();
1384 int dh = QApplication::desktop()->height(); 1390 int dh = QApplication::desktop()->height();
1385 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1391 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1386 bar.show(); 1392 bar.show();
1387 bar.setCaption (i18n("Reading addressbook - close to abort!") ); 1393 bar.setCaption (i18n("Reading addressbook - close to abort!") );
1388 qApp->processEvents(); 1394 qApp->processEvents();
1389 count = 0; 1395 count = 0;
1390 int addCount = 0; 1396 int addCount = 0;
1391 KCal::Attendee* a = 0; 1397 KCal::Attendee* a = 0;
1392 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1398 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1393 if ( ! bar.isVisible() ) 1399 if ( ! bar.isVisible() )
1394 return false; 1400 return false;
1395 bar.setProgress( count++ ); 1401 bar.setProgress( count++ );
1396 qApp->processEvents(); 1402 qApp->processEvents();
1397 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); 1403 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() );
1398 if ( (*it).birthday().date().isValid() ){ 1404 if ( (*it).birthday().date().isValid() ){
1399 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1405 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1400 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) 1406 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) )
1401 ++addCount; 1407 ++addCount;
1402 } 1408 }
1403 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); 1409 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d");
1404 if ( anni.isValid() ){ 1410 if ( anni.isValid() ){
1405 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1411 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1406 if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) 1412 if ( addAnniversary( anni, (*it).assembledName(), a, false ) )
1407 ++addCount; 1413 ++addCount;
1408 } 1414 }
1409 } 1415 }
1410 updateView(); 1416 updateView();
1411 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1417 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1412#else //DESKTOP_VERSION 1418#else //DESKTOP_VERSION
1413 1419
1414 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); 1420 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/);
1415 // the result should now arrive through method insertBirthdays 1421 // the result should now arrive through method insertBirthdays
1416 1422
1417#endif //DESKTOP_VERSION 1423#endif //DESKTOP_VERSION
1418 1424
1419#endif //KORG_NOKABC 1425#endif //KORG_NOKABC
1420 1426
1421 1427
1422 return true; 1428 return true;
1423} 1429}
1424 1430
1425// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI 1431// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI
1426void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, 1432void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList,
1427 const QStringList& anniversaryList, const QStringList& realNameList, 1433 const QStringList& anniversaryList, const QStringList& realNameList,
1428 const QStringList& emailList, const QStringList& assembledNameList, 1434 const QStringList& emailList, const QStringList& assembledNameList,
1429 const QStringList& uidList) 1435 const QStringList& uidList)
1430{ 1436{
1431 qDebug("CalendarView::insertBirthdays"); 1437 qDebug("CalendarView::insertBirthdays");
1432 if (uid == this->name()) 1438 if (uid == this->name())
1433 { 1439 {
1434 int count = birthdayList.count(); 1440 int count = birthdayList.count();
1435 int addCount = 0; 1441 int addCount = 0;
1436 KCal::Attendee* a = 0; 1442 KCal::Attendee* a = 0;
1437 1443
1438 qDebug("CalView 1 %i", count); 1444 qDebug("CalView 1 %i", count);
1439 1445
1440 QProgressBar bar(count,0 ); 1446 QProgressBar bar(count,0 );
1441 int w = 300; 1447 int w = 300;
1442 if ( QApplication::desktop()->width() < 320 ) 1448 if ( QApplication::desktop()->width() < 320 )
1443 w = 220; 1449 w = 220;
1444 int h = bar.sizeHint().height() ; 1450 int h = bar.sizeHint().height() ;
1445 int dw = QApplication::desktop()->width(); 1451 int dw = QApplication::desktop()->width();
1446 int dh = QApplication::desktop()->height(); 1452 int dh = QApplication::desktop()->height();
1447 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1453 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1448 bar.show(); 1454 bar.show();
1449 bar.setCaption (i18n("inserting birthdays - close to abort!") ); 1455 bar.setCaption (i18n("inserting birthdays - close to abort!") );
1450 qApp->processEvents(); 1456 qApp->processEvents();
1451 1457
1452 QDate birthday; 1458 QDate birthday;
1453 QDate anniversary; 1459 QDate anniversary;
1454 QString realName; 1460 QString realName;
1455 QString email; 1461 QString email;
1456 QString assembledName; 1462 QString assembledName;
1457 QString uid; 1463 QString uid;
1458 bool ok = true; 1464 bool ok = true;
1459 for ( int i = 0; i < count; i++) 1465 for ( int i = 0; i < count; i++)
1460 { 1466 {
1461 if ( ! bar.isVisible() ) 1467 if ( ! bar.isVisible() )
1462 return; 1468 return;
1463 bar.setProgress( i ); 1469 bar.setProgress( i );
1464 qApp->processEvents(); 1470 qApp->processEvents();
1465 1471
1466 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); 1472 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok);
1467 if (!ok) { 1473 if (!ok) {
1468 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); 1474 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1());
1469 } 1475 }
1470 1476
1471 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); 1477 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok);
1472 if (!ok) { 1478 if (!ok) {
1473 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); 1479 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1());
1474 } 1480 }
1475 realName = realNameList[i]; 1481 realName = realNameList[i];
1476 email = emailList[i]; 1482 email = emailList[i];
1477 assembledName = assembledNameList[i]; 1483 assembledName = assembledNameList[i];
1478 uid = uidList[i]; 1484 uid = uidList[i];
1479 //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() ); 1485 //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() );
1480 1486
1481 if ( birthday.isValid() ){ 1487 if ( birthday.isValid() ){
1482 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1488 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1483 KCal::Attendee::ReqParticipant,uid) ; 1489 KCal::Attendee::ReqParticipant,uid) ;
1484 if ( addAnniversary( birthday, assembledName, a, true ) ) 1490 if ( addAnniversary( birthday, assembledName, a, true ) )
1485 ++addCount; 1491 ++addCount;
1486 } 1492 }
1487 1493
1488 if ( anniversary.isValid() ){ 1494 if ( anniversary.isValid() ){
1489 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1495 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1490 KCal::Attendee::ReqParticipant,uid) ; 1496 KCal::Attendee::ReqParticipant,uid) ;
1491 if ( addAnniversary( anniversary, assembledName, a, false ) ) 1497 if ( addAnniversary( anniversary, assembledName, a, false ) )
1492 ++addCount; 1498 ++addCount;
1493 } 1499 }
1494 } 1500 }
1495 1501
1496 updateView(); 1502 updateView();
1497 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1503 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1498 1504
1499 } 1505 }
1500 1506
1501} 1507}
1502 1508
1503 1509
1504 1510
1505bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) 1511bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday)
1506{ 1512{
1507 //qDebug("addAnni "); 1513 //qDebug("addAnni ");
1508 Event * ev = new Event(); 1514 Event * ev = new Event();
1509 if ( a ) { 1515 if ( a ) {
1510 ev->addAttendee( a ); 1516 ev->addAttendee( a );
1511 } 1517 }
1512 QString kind; 1518 QString kind;
1513 if ( birthday ) 1519 if ( birthday )
1514 kind = i18n( "Birthday" ); 1520 kind = i18n( "Birthday" );
1515 else 1521 else
1516 kind = i18n( "Anniversary" ); 1522 kind = i18n( "Anniversary" );
1517 ev->setSummary( name + " - " + kind ); 1523 ev->setSummary( name + " - " + kind );
1518 ev->setOrganizer(a->email()); 1524 ev->setOrganizer(a->email());
1519 ev->setCategories( kind ); 1525 ev->setCategories( kind );
1520 ev->setDtStart( QDateTime(date) ); 1526 ev->setDtStart( QDateTime(date) );
1521 ev->setDtEnd( QDateTime(date) ); 1527 ev->setDtEnd( QDateTime(date) );
1522 ev->setFloats( true ); 1528 ev->setFloats( true );
1523 Recurrence * rec = ev->recurrence(); 1529 Recurrence * rec = ev->recurrence();
1524 rec->setYearly(Recurrence::rYearlyMonth,1,-1); 1530 rec->setYearly(Recurrence::rYearlyMonth,1,-1);
1525 rec->addYearlyNum( date.month() ); 1531 rec->addYearlyNum( date.month() );
1526 if ( !mCalendar->addAnniversaryNoDup( ev ) ) { 1532 if ( !mCalendar->addAnniversaryNoDup( ev ) ) {
1527 delete ev; 1533 delete ev;
1528 return false; 1534 return false;
1529 } 1535 }
1530 return true; 1536 return true;
1531 1537
1532} 1538}
1533bool CalendarView::importQtopia( const QString &categories, 1539bool CalendarView::importQtopia( const QString &categories,
1534 const QString &datebook, 1540 const QString &datebook,
1535 const QString &todolist ) 1541 const QString &todolist )
1536{ 1542{
1537 1543
1538 QtopiaFormat qtopiaFormat; 1544 QtopiaFormat qtopiaFormat;
1539 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1545 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1540 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); 1546 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories );
1541 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); 1547 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook );
1542 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); 1548 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist );
1543 1549
1544 updateView(); 1550 updateView();
1545 return true; 1551 return true;
1546 1552
1547#if 0 1553#if 0
1548 mGlobalSyncMode = SYNC_MODE_QTOPIA; 1554 mGlobalSyncMode = SYNC_MODE_QTOPIA;
1549 mCurrentSyncDevice = "qtopia-XML"; 1555 mCurrentSyncDevice = "qtopia-XML";
1550 if ( mSyncManager->mAskForPreferences ) 1556 if ( mSyncManager->mAskForPreferences )
1551 edit_sync_options(); 1557 edit_sync_options();
1552 qApp->processEvents(); 1558 qApp->processEvents();
1553 CalendarLocal* calendar = new CalendarLocal(); 1559 CalendarLocal* calendar = new CalendarLocal();
1554 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1560 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1555 bool syncOK = false; 1561 bool syncOK = false;
1556 QtopiaFormat qtopiaFormat; 1562 QtopiaFormat qtopiaFormat;
1557 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1563 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1558 bool loadOk = true; 1564 bool loadOk = true;
1559 if ( !categories.isEmpty() ) 1565 if ( !categories.isEmpty() )
1560 loadOk = qtopiaFormat.load( calendar, categories ); 1566 loadOk = qtopiaFormat.load( calendar, categories );
1561 if ( loadOk && !datebook.isEmpty() ) 1567 if ( loadOk && !datebook.isEmpty() )
1562 loadOk = qtopiaFormat.load( calendar, datebook ); 1568 loadOk = qtopiaFormat.load( calendar, datebook );
1563 if ( loadOk && !todolist.isEmpty() ) 1569 if ( loadOk && !todolist.isEmpty() )
1564 loadOk = qtopiaFormat.load( calendar, todolist ); 1570 loadOk = qtopiaFormat.load( calendar, todolist );
1565 1571
1566 if ( loadOk ) { 1572 if ( loadOk ) {
1567 getEventViewerDialog()->setSyncMode( true ); 1573 getEventViewerDialog()->setSyncMode( true );
1568 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1574 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1569 getEventViewerDialog()->setSyncMode( false ); 1575 getEventViewerDialog()->setSyncMode( false );
1570 qApp->processEvents(); 1576 qApp->processEvents();
1571 if ( syncOK ) { 1577 if ( syncOK ) {
1572 if ( mSyncManager->mWriteBackFile ) 1578 if ( mSyncManager->mWriteBackFile )
1573 { 1579 {
1574 // write back XML file 1580 // write back XML file
1575 1581
1576 } 1582 }
1577 setModified( true ); 1583 setModified( true );
1578 } 1584 }
1579 } else { 1585 } else {
1580 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; 1586 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ;
1581 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), 1587 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"),
1582 question, i18n("Ok")) ; 1588 question, i18n("Ok")) ;
1583 } 1589 }
1584 delete calendar; 1590 delete calendar;
1585 updateView(); 1591 updateView();
1586 return syncOK; 1592 return syncOK;
1587 1593
1588 1594
1589#endif 1595#endif
1590 1596
1591} 1597}
1592 1598
1593void CalendarView::setSyncEventsReadOnly() 1599void CalendarView::setSyncEventsReadOnly()
1594{ 1600{
1595 Event * ev; 1601 Event * ev;
1596 QPtrList<Event> eL = mCalendar->rawEvents(); 1602 QPtrList<Event> eL = mCalendar->rawEvents();
1597 ev = eL.first(); 1603 ev = eL.first();
1598 while ( ev ) { 1604 while ( ev ) {
1599 if ( ev->uid().left(15) == QString("last-syncEvent-") ) 1605 if ( ev->uid().left(15) == QString("last-syncEvent-") )
1600 ev->setReadOnly( true ); 1606 ev->setReadOnly( true );
1601 ev = eL.next(); 1607 ev = eL.next();
1602 } 1608 }
1603} 1609}
1604bool CalendarView::openCalendar(QString filename, bool merge) 1610bool CalendarView::openCalendar(QString filename, bool merge)
1605{ 1611{