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