summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-09-14 01:03:08 (UTC)
committer zautrix <zautrix>2004-09-14 01:03:08 (UTC)
commit30762fe125216362e1a6c1d5ec5d22d9525aa336 (patch) (unidiff)
tree4ff0fbf43efa921c86d64ff3f50baa9e59d207d9
parent8ce7eae438dcd20f9c79fc0a36dfef0a6d3931eb (diff)
downloadkdepimpi-30762fe125216362e1a6c1d5ec5d22d9525aa336.zip
kdepimpi-30762fe125216362e1a6c1d5ec5d22d9525aa336.tar.gz
kdepimpi-30762fe125216362e1a6c1d5ec5d22d9525aa336.tar.bz2
Many bugfixes
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp16
-rw-r--r--libkcal/alarm.cpp36
-rw-r--r--libkcal/recurrence.cpp56
-rw-r--r--libkcal/sharpformat.cpp7
4 files changed, 94 insertions, 21 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index 258bd43..94cc97d 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -613,623 +613,629 @@ void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti )
613 //maxSec = 5; //testing only 613 //maxSec = 5; //testing only
614 maxSec = 86400+3600; // one day+1hour 614 maxSec = 86400+3600; // one day+1hour
615 mAlarmNotification = noti; 615 mAlarmNotification = noti;
616 int sec = QDateTime::currentDateTime().secsTo( qdt ); 616 int sec = QDateTime::currentDateTime().secsTo( qdt );
617 if ( sec > maxSec ) { 617 if ( sec > maxSec ) {
618 mRecheckAlarmTimer->start( maxSec * 1000 ); 618 mRecheckAlarmTimer->start( maxSec * 1000 );
619 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec ); 619 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec );
620 return; 620 return;
621 } else { 621 } else {
622 mRecheckAlarmTimer->stop(); 622 mRecheckAlarmTimer->stop();
623 } 623 }
624 //qDebug("Alarm timer started with secs: %d ", sec); 624 //qDebug("Alarm timer started with secs: %d ", sec);
625 mAlarmTimer->start( sec *1000 , true ); 625 mAlarmTimer->start( sec *1000 , true );
626 626
627} 627}
628// called by mRecheckAlarmTimer to get next alarm 628// called by mRecheckAlarmTimer to get next alarm
629// we need this, because a QTimer has only a max range of 25 days 629// we need this, because a QTimer has only a max range of 25 days
630void CalendarView::recheckTimerAlarm() 630void CalendarView::recheckTimerAlarm()
631{ 631{
632 mAlarmTimer->stop(); 632 mAlarmTimer->stop();
633 mRecheckAlarmTimer->stop(); 633 mRecheckAlarmTimer->stop();
634 mCalendar->checkAlarmForIncidence( 0, true ); 634 mCalendar->checkAlarmForIncidence( 0, true );
635} 635}
636void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti ) 636void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti )
637{ 637{
638 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 638 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
639 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 639 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
640#ifndef DESKTOP_VERSION 640#ifndef DESKTOP_VERSION
641 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() ); 641 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() );
642#endif 642#endif
643 return; 643 return;
644 } 644 }
645 mAlarmTimer->stop(); 645 mAlarmTimer->stop();
646} 646}
647void CalendarView::selectWeekNum ( int num ) 647void CalendarView::selectWeekNum ( int num )
648{ 648{
649 dateNavigator()->selectWeek( num ); 649 dateNavigator()->selectWeek( num );
650 mViewManager->showWeekView(); 650 mViewManager->showWeekView();
651} 651}
652KOViewManager *CalendarView::viewManager() 652KOViewManager *CalendarView::viewManager()
653{ 653{
654 return mViewManager; 654 return mViewManager;
655} 655}
656 656
657KODialogManager *CalendarView::dialogManager() 657KODialogManager *CalendarView::dialogManager()
658{ 658{
659 return mDialogManager; 659 return mDialogManager;
660} 660}
661 661
662QDate CalendarView::startDate() 662QDate CalendarView::startDate()
663{ 663{
664 DateList dates = mNavigator->selectedDates(); 664 DateList dates = mNavigator->selectedDates();
665 665
666 return dates.first(); 666 return dates.first();
667} 667}
668 668
669QDate CalendarView::endDate() 669QDate CalendarView::endDate()
670{ 670{
671 DateList dates = mNavigator->selectedDates(); 671 DateList dates = mNavigator->selectedDates();
672 672
673 return dates.last(); 673 return dates.last();
674} 674}
675 675
676 676
677void CalendarView::createPrinter() 677void CalendarView::createPrinter()
678{ 678{
679#ifndef KORG_NOPRINTER 679#ifndef KORG_NOPRINTER
680 if (!mCalPrinter) { 680 if (!mCalPrinter) {
681 mCalPrinter = new CalPrinter(this, mCalendar); 681 mCalPrinter = new CalPrinter(this, mCalendar);
682 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig())); 682 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig()));
683 } 683 }
684#endif 684#endif
685} 685}
686 686
687void CalendarView::confSync() 687void CalendarView::confSync()
688{ 688{
689 static KSyncPrefsDialog* sp = 0; 689 static KSyncPrefsDialog* sp = 0;
690 if ( ! sp ) { 690 if ( ! sp ) {
691 sp = new KSyncPrefsDialog( this, "syncprefs", true ); 691 sp = new KSyncPrefsDialog( this, "syncprefs", true );
692 } 692 }
693 sp->usrReadConfig(); 693 sp->usrReadConfig();
694#ifndef DESKTOP_VERSION 694#ifndef DESKTOP_VERSION
695 sp->showMaximized(); 695 sp->showMaximized();
696#else 696#else
697 sp->show(); 697 sp->show();
698#endif 698#endif
699 sp->exec(); 699 sp->exec();
700 KOPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames(); 700 KOPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames();
701 KOPrefs::instance()->mLocalMachineName = sp->getLocalMachineName (); 701 KOPrefs::instance()->mLocalMachineName = sp->getLocalMachineName ();
702} 702}
703 703
704 704
705//KOPrefs::instance()->mWriteBackFile 705//KOPrefs::instance()->mWriteBackFile
706//KOPrefs::instance()->mWriteBackExistingOnly 706//KOPrefs::instance()->mWriteBackExistingOnly
707 707
708// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); 708// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict"));
709// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); 709// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict"));
710// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); 710// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict"));
711// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); 711// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict"));
712// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); 712// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always"));
713// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); 713// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always"));
714 714
715int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) 715int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full )
716{ 716{
717 717
718 //void setZaurusId(int id); 718 //void setZaurusId(int id);
719 // int zaurusId() const; 719 // int zaurusId() const;
720 // void setZaurusUid(int id); 720 // void setZaurusUid(int id);
721 // int zaurusUid() const; 721 // int zaurusUid() const;
722 // void setZaurusStat(int id); 722 // void setZaurusStat(int id);
723 // int zaurusStat() const; 723 // int zaurusStat() const;
724 // 0 equal 724 // 0 equal
725 // 1 take local 725 // 1 take local
726 // 2 take remote 726 // 2 take remote
727 // 3 cancel 727 // 3 cancel
728 QDateTime lastSync = mLastCalendarSync; 728 QDateTime lastSync = mLastCalendarSync;
729 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 729 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
730 bool remCh, locCh; 730 bool remCh, locCh;
731 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 731 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
732 if ( remCh ) 732 if ( remCh )
733 qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 733 qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
734 locCh = ( local->lastModified() > mLastCalendarSync ); 734 locCh = ( local->lastModified() > mLastCalendarSync );
735 //qDebug("locCh %d remCh %d locuid %d remuid %d", locCh, remCh,local->zaurusUid(), remote->zaurusUid() ); 735 //qDebug("locCh %d remCh %d locuid %d remuid %d", locCh, remCh,local->zaurusUid(), remote->zaurusUid() );
736 if ( !remCh && ! locCh ) { 736 if ( !remCh && ! locCh ) {
737 qDebug("both not changed "); 737 qDebug("both not changed ");
738 lastSync = local->lastModified().addDays(1); 738 lastSync = local->lastModified().addDays(1);
739 } else { 739 } else {
740 if ( locCh ) { 740 if ( locCh ) {
741 qDebug("loc changed %d", local->revision() ); 741 qDebug("loc changed %d %s %s", local->revision() , local->lastModified().toString().latin1(), mLastCalendarSync.toString().latin1());
742 lastSync = local->lastModified().addDays( -1 ); 742 lastSync = local->lastModified().addDays( -1 );
743 if ( !remCh ) 743 if ( !remCh )
744 remote->setLastModified( lastSync.addDays( -1 ) ); 744 remote->setLastModified( lastSync.addDays( -1 ) );
745 } else { 745 } else {
746 qDebug(" not loc changed "); 746 qDebug(" not loc changed ");
747 lastSync = local->lastModified().addDays( 1 ); 747 lastSync = local->lastModified().addDays( 1 );
748 if ( remCh ) 748 if ( remCh )
749 remote->setLastModified( lastSync.addDays( 1 ) ); 749 remote->setLastModified( lastSync.addDays( 1 ) );
750 750
751 } 751 }
752 } 752 }
753 full = true; 753 full = true;
754 if ( mode < SYNC_PREF_ASK ) 754 if ( mode < SYNC_PREF_ASK )
755 mode = SYNC_PREF_ASK; 755 mode = SYNC_PREF_ASK;
756 } else { 756 } else {
757 if ( local->lastModified() == remote->lastModified() ) 757 if ( local->lastModified() == remote->lastModified() )
758 if ( local->revision() == remote->revision() ) 758 if ( local->revision() == remote->revision() )
759 return 0; 759 return 0;
760 760
761 } 761 }
762 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 762 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
763 763
764 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , local->revision(), remote->lastModified().toString().latin1(), remote->revision()); 764 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , local->revision(), remote->lastModified().toString().latin1(), remote->revision());
765 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); 765 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() );
766 //full = true; //debug only 766 //full = true; //debug only
767 if ( full ) { 767 if ( full ) {
768 bool equ = false; 768 bool equ = false;
769 if ( local->type() == "Event" ) { 769 if ( local->type() == "Event" ) {
770 equ = (*((Event*) local) == *((Event*) remote)); 770 equ = (*((Event*) local) == *((Event*) remote));
771 } 771 }
772 else if ( local->type() =="Todo" ) 772 else if ( local->type() =="Todo" )
773 equ = (*((Todo*) local) == (*(Todo*) remote)); 773 equ = (*((Todo*) local) == (*(Todo*) remote));
774 else if ( local->type() =="Journal" ) 774 else if ( local->type() =="Journal" )
775 equ = (*((Journal*) local) == *((Journal*) remote)); 775 equ = (*((Journal*) local) == *((Journal*) remote));
776 if ( equ ) { 776 if ( equ ) {
777 //qDebug("equal "); 777 //qDebug("equal ");
778 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 778 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
779 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 779 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
780 } 780 }
781 if ( mode < SYNC_PREF_FORCE_LOCAL ) 781 if ( mode < SYNC_PREF_FORCE_LOCAL )
782 return 0; 782 return 0;
783 783
784 }//else //debug only 784 }//else //debug only
785 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 785 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
786 } 786 }
787 int result; 787 int result;
788 bool localIsNew; 788 bool localIsNew;
789 qDebug("mLastCalendarSync %s lastsync %s --- local %s remote %s ",mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); 789 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() );
790 790
791 if ( full && mode < SYNC_PREF_NEWEST ) 791 if ( full && mode < SYNC_PREF_NEWEST )
792 mode = SYNC_PREF_ASK; 792 mode = SYNC_PREF_ASK;
793 793
794 switch( mode ) { 794 switch( mode ) {
795 case SYNC_PREF_LOCAL: 795 case SYNC_PREF_LOCAL:
796 if ( lastSync > remote->lastModified() ) 796 if ( lastSync > remote->lastModified() )
797 return 1; 797 return 1;
798 if ( lastSync > local->lastModified() ) 798 if ( lastSync > local->lastModified() )
799 return 2; 799 return 2;
800 return 1; 800 return 1;
801 break; 801 break;
802 case SYNC_PREF_REMOTE: 802 case SYNC_PREF_REMOTE:
803 if ( lastSync > remote->lastModified() ) 803 if ( lastSync > remote->lastModified() )
804 return 1; 804 return 1;
805 if ( lastSync > local->lastModified() ) 805 if ( lastSync > local->lastModified() )
806 return 2; 806 return 2;
807 return 2; 807 return 2;
808 break; 808 break;
809 case SYNC_PREF_NEWEST: 809 case SYNC_PREF_NEWEST:
810 if ( local->lastModified() > remote->lastModified() ) 810 if ( local->lastModified() > remote->lastModified() )
811 return 1; 811 return 1;
812 else 812 else
813 return 2; 813 return 2;
814 break; 814 break;
815 case SYNC_PREF_ASK: 815 case SYNC_PREF_ASK:
816 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() ); 816 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() );
817 if ( lastSync > remote->lastModified() ) 817 if ( lastSync > remote->lastModified() )
818 return 1; 818 return 1;
819 if ( lastSync > local->lastModified() ) 819 if ( lastSync > local->lastModified() )
820 return 2; 820 return 2;
821 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() ); 821 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() );
822 localIsNew = local->lastModified() >= remote->lastModified(); 822 localIsNew = local->lastModified() >= remote->lastModified();
823 if ( localIsNew ) 823 if ( localIsNew )
824 getEventViewerDialog()->setColorMode( 1 ); 824 getEventViewerDialog()->setColorMode( 1 );
825 else 825 else
826 getEventViewerDialog()->setColorMode( 2 ); 826 getEventViewerDialog()->setColorMode( 2 );
827 getEventViewerDialog()->setIncidence(local); 827 getEventViewerDialog()->setIncidence(local);
828 if ( localIsNew ) 828 if ( localIsNew )
829 getEventViewerDialog()->setColorMode( 2 ); 829 getEventViewerDialog()->setColorMode( 2 );
830 else 830 else
831 getEventViewerDialog()->setColorMode( 1 ); 831 getEventViewerDialog()->setColorMode( 1 );
832 getEventViewerDialog()->addIncidence(remote); 832 getEventViewerDialog()->addIncidence(remote);
833 getEventViewerDialog()->setColorMode( 0 ); 833 getEventViewerDialog()->setColorMode( 0 );
834 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); 834 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() );
835 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); 835 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!"));
836 getEventViewerDialog()->showMe(); 836 getEventViewerDialog()->showMe();
837 result = getEventViewerDialog()->executeS( localIsNew ); 837 result = getEventViewerDialog()->executeS( localIsNew );
838 return result; 838 return result;
839 839
840 break; 840 break;
841 case SYNC_PREF_FORCE_LOCAL: 841 case SYNC_PREF_FORCE_LOCAL:
842 return 1; 842 return 1;
843 break; 843 break;
844 case SYNC_PREF_FORCE_REMOTE: 844 case SYNC_PREF_FORCE_REMOTE:
845 return 2; 845 return 2;
846 break; 846 break;
847 847
848 default: 848 default:
849 // SYNC_PREF_TAKE_BOTH not implemented 849 // SYNC_PREF_TAKE_BOTH not implemented
850 break; 850 break;
851 } 851 }
852 return 0; 852 return 0;
853} 853}
854Event* CalendarView::getLastSyncEvent() 854Event* CalendarView::getLastSyncEvent()
855{ 855{
856 Event* lse; 856 Event* lse;
857 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 857 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
858 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); 858 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice );
859 if (!lse) { 859 if (!lse) {
860 lse = new Event(); 860 lse = new Event();
861 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); 861 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice );
862 QString sum = ""; 862 QString sum = "";
863 if ( KOPrefs::instance()->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) 863 if ( KOPrefs::instance()->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
864 sum = "E: "; 864 sum = "E: ";
865 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); 865 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event"));
866 lse->setDtStart( mLastCalendarSync ); 866 lse->setDtStart( mLastCalendarSync );
867 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 867 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
868 lse->setCategories( i18n("SyncEvent") ); 868 lse->setCategories( i18n("SyncEvent") );
869 lse->setReadOnly( true ); 869 lse->setReadOnly( true );
870 mCalendar->addEvent( lse ); 870 mCalendar->addEvent( lse );
871 } 871 }
872 872
873 return lse; 873 return lse;
874 874
875} 875}
876// probaly useless 876// probaly useless
877void CalendarView::setupExternSyncProfiles() 877void CalendarView::setupExternSyncProfiles()
878{ 878{
879 Event* lse; 879 Event* lse;
880 mExternLastSyncEvent.clear(); 880 mExternLastSyncEvent.clear();
881 int i; 881 int i;
882 for ( i = 0; i < KOPrefs::instance()->mExternSyncProfiles.count(); ++i ) { 882 for ( i = 0; i < KOPrefs::instance()->mExternSyncProfiles.count(); ++i ) {
883 lse = mCalendar->event( "last-syncEvent-"+ KOPrefs::instance()->mExternSyncProfiles[i] ); 883 lse = mCalendar->event( "last-syncEvent-"+ KOPrefs::instance()->mExternSyncProfiles[i] );
884 if ( lse ) 884 if ( lse )
885 mExternLastSyncEvent.append( lse ); 885 mExternLastSyncEvent.append( lse );
886 else 886 else
887 qDebug("Last Sync event not found for %s ", KOPrefs::instance()->mExternSyncProfiles[i].latin1()); 887 qDebug("Last Sync event not found for %s ", KOPrefs::instance()->mExternSyncProfiles[i].latin1());
888 } 888 }
889 889
890} 890}
891// we check, if the to delete event has a id for a profile 891// we check, if the to delete event has a id for a profile
892// if yes, we set this id in the profile to delete 892// if yes, we set this id in the profile to delete
893void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) 893void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete )
894{ 894{
895 if ( lastSync.count() == 0 ) { 895 if ( lastSync.count() == 0 ) {
896 //qDebug(" lastSync.count() == 0"); 896 //qDebug(" lastSync.count() == 0");
897 return; 897 return;
898 } 898 }
899 if ( toDelete->type() == "Journal" ) 899 if ( toDelete->type() == "Journal" )
900 return; 900 return;
901 901
902 Event* eve = lastSync.first(); 902 Event* eve = lastSync.first();
903 903
904 while ( eve ) { 904 while ( eve ) {
905 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name 905 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name
906 if ( !id.isEmpty() ) { 906 if ( !id.isEmpty() ) {
907 QString des = eve->description(); 907 QString des = eve->description();
908 QString pref = "e"; 908 QString pref = "e";
909 if ( toDelete->type() == "Todo" ) 909 if ( toDelete->type() == "Todo" )
910 pref = "t"; 910 pref = "t";
911 des += pref+ id + ","; 911 des += pref+ id + ",";
912 eve->setReadOnly( false ); 912 eve->setReadOnly( false );
913 eve->setDescription( des ); 913 eve->setDescription( des );
914 //qDebug("setdes %s ", des.latin1()); 914 //qDebug("setdes %s ", des.latin1());
915 eve->setReadOnly( true ); 915 eve->setReadOnly( true );
916 } 916 }
917 eve = lastSync.next(); 917 eve = lastSync.next();
918 } 918 }
919 919
920} 920}
921void CalendarView::checkExternalId( Incidence * inc ) 921void CalendarView::checkExternalId( Incidence * inc )
922{ 922{
923 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; 923 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ;
924 checkExternSyncEvent( lastSync, inc ); 924 checkExternSyncEvent( lastSync, inc );
925 925
926} 926}
927bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) 927bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode )
928{ 928{
929 bool syncOK = true; 929 bool syncOK = true;
930 int addedEvent = 0; 930 int addedEvent = 0;
931 int addedEventR = 0; 931 int addedEventR = 0;
932 int deletedEventR = 0; 932 int deletedEventR = 0;
933 int deletedEventL = 0; 933 int deletedEventL = 0;
934 int changedLocal = 0; 934 int changedLocal = 0;
935 int changedRemote = 0; 935 int changedRemote = 0;
936 //QPtrList<Event> el = local->rawEvents(); 936 //QPtrList<Event> el = local->rawEvents();
937 Event* eventR; 937 Event* eventR;
938 QString uid; 938 QString uid;
939 int take; 939 int take;
940 Event* eventL; 940 Event* eventL;
941 Event* eventRSync; 941 Event* eventRSync;
942 Event* eventLSync; 942 Event* eventLSync;
943 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); 943 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents();
944 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); 944 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents();
945 bool fullDateRange = false; 945 bool fullDateRange = false;
946 local->resetTempSyncStat(); 946 local->resetTempSyncStat();
947 mLastCalendarSync = QDateTime::currentDateTime(); 947 mLastCalendarSync = QDateTime::currentDateTime();
948 QDateTime modifiedCalendar = mLastCalendarSync;; 948 QDateTime modifiedCalendar = mLastCalendarSync;;
949 eventLSync = getLastSyncEvent(); 949 eventLSync = getLastSyncEvent();
950 eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); 950 eventR = remote->event("last-syncEvent-"+mCurrentSyncName );
951 if ( eventR ) { 951 if ( eventR ) {
952 eventRSync = (Event*) eventR->clone(); 952 eventRSync = (Event*) eventR->clone();
953 remote->deleteEvent(eventR ); 953 remote->deleteEvent(eventR );
954 954
955 } else { 955 } else {
956 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 956 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
957 eventRSync = (Event*)eventLSync->clone(); 957 eventRSync = (Event*)eventLSync->clone();
958 } else { 958 } else {
959 fullDateRange = true; 959 fullDateRange = true;
960 eventRSync = new Event(); 960 eventRSync = new Event();
961 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); 961 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event"));
962 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); 962 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName );
963 eventRSync->setDtStart( mLastCalendarSync ); 963 eventRSync->setDtStart( mLastCalendarSync );
964 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 964 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
965 eventRSync->setCategories( i18n("SyncEvent") ); 965 eventRSync->setCategories( i18n("SyncEvent") );
966 } 966 }
967 } 967 }
968 if ( eventLSync->dtStart() == mLastCalendarSync ) 968 if ( eventLSync->dtStart() == mLastCalendarSync )
969 fullDateRange = true; 969 fullDateRange = true;
970 970
971 if ( ! fullDateRange ) { 971 if ( ! fullDateRange ) {
972 if ( eventLSync->dtStart() != eventRSync->dtStart() ) { 972 if ( eventLSync->dtStart() != eventRSync->dtStart() ) {
973 973
974 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); 974 // 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()); 975 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec());
976 fullDateRange = true; 976 fullDateRange = true;
977 } 977 }
978 } 978 }
979 if ( fullDateRange ) 979 if ( fullDateRange )
980 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 980 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
981 else 981 else
982 mLastCalendarSync = eventLSync->dtStart(); 982 mLastCalendarSync = eventLSync->dtStart();
983 // for resyncing if own file has changed 983 // for resyncing if own file has changed
984 if ( mCurrentSyncDevice == "deleteaftersync" ) { 984 if ( mCurrentSyncDevice == "deleteaftersync" ) {
985 mLastCalendarSync = loadedFileVersion; 985 mLastCalendarSync = loadedFileVersion;
986 qDebug("setting mLastCalendarSync "); 986 qDebug("setting mLastCalendarSync ");
987 } 987 }
988 //qDebug("*************************** "); 988 //qDebug("*************************** ");
989 qDebug("mLastCalendarSync %s ",mLastCalendarSync.toString().latin1() ); 989 qDebug("mLastCalendarSync %s ",mLastCalendarSync.toString().latin1() );
990 QPtrList<Incidence> er = remote->rawIncidences(); 990 QPtrList<Incidence> er = remote->rawIncidences();
991 Incidence* inR = er.first(); 991 Incidence* inR = er.first();
992 Incidence* inL; 992 Incidence* inL;
993 QProgressBar bar( er.count(),0 ); 993 QProgressBar bar( er.count(),0 );
994 bar.setCaption (i18n("Syncing - close to abort!") ); 994 bar.setCaption (i18n("Syncing - close to abort!") );
995 995
996 int w = 300; 996 int w = 300;
997 if ( QApplication::desktop()->width() < 320 ) 997 if ( QApplication::desktop()->width() < 320 )
998 w = 220; 998 w = 220;
999 int h = bar.sizeHint().height() ; 999 int h = bar.sizeHint().height() ;
1000 int dw = QApplication::desktop()->width(); 1000 int dw = QApplication::desktop()->width();
1001 int dh = QApplication::desktop()->height(); 1001 int dh = QApplication::desktop()->height();
1002 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1002 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1003 bar.show(); 1003 bar.show();
1004 int modulo = (er.count()/10)+1; 1004 int modulo = (er.count()/10)+1;
1005 int incCounter = 0; 1005 int incCounter = 0;
1006 while ( inR ) { 1006 while ( inR ) {
1007 if ( ! bar.isVisible() ) 1007 if ( ! bar.isVisible() )
1008 return false; 1008 return false;
1009 if ( incCounter % modulo == 0 ) 1009 if ( incCounter % modulo == 0 )
1010 bar.setProgress( incCounter ); 1010 bar.setProgress( incCounter );
1011 ++incCounter; 1011 ++incCounter;
1012 uid = inR->uid(); 1012 uid = inR->uid();
1013 bool skipIncidence = false; 1013 bool skipIncidence = false;
1014 if ( uid.left(15) == QString("last-syncEvent-") ) 1014 if ( uid.left(15) == QString("last-syncEvent-") )
1015 skipIncidence = true; 1015 skipIncidence = true;
1016 1016
1017 qApp->processEvents(); 1017 qApp->processEvents();
1018 if ( !skipIncidence ) { 1018 if ( !skipIncidence ) {
1019 inL = local->incidence( uid ); 1019 inL = local->incidence( uid );
1020 if ( inL ) { // maybe conflict - same uid in both calendars 1020 if ( inL ) { // maybe conflict - same uid in both calendars
1021 int maxrev = inL->revision(); 1021 int maxrev = inL->revision();
1022 if ( maxrev < inR->revision() ) 1022 if ( maxrev < inR->revision() )
1023 maxrev = inR->revision(); 1023 maxrev = inR->revision();
1024 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1024 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1025 //qDebug("take %d %s ", take, inL->summary().latin1()); 1025 //qDebug("take %d %s ", take, inL->summary().latin1());
1026 if ( take == 3 ) 1026 if ( take == 3 )
1027 return false; 1027 return false;
1028 if ( take == 1 ) {// take local 1028 if ( take == 1 ) {// take local
1029 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1029 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1030 remote->deleteIncidence( inR ); 1030 remote->deleteIncidence( inR );
1031 if ( inL->revision() < maxrev ) 1031 if ( inL->revision() < maxrev )
1032 inL->setRevision( maxrev ); 1032 inL->setRevision( maxrev );
1033 remote->addIncidence( inL->clone() ); 1033 inR = inL->clone();
1034 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1035 remote->addIncidence( inR );
1034 ++changedRemote; 1036 ++changedRemote;
1035 } else { 1037 } else {
1036 if ( inR->revision() < maxrev ) 1038 if ( inR->revision() < maxrev )
1037 inR->setRevision( maxrev ); 1039 inR->setRevision( maxrev );
1038 local->deleteIncidence( inL ); 1040 local->deleteIncidence( inL );
1039 local->addIncidence( inR->clone() ); 1041 local->addIncidence( inR->clone() );
1040 ++changedLocal; 1042 ++changedLocal;
1041 } 1043 }
1042 } 1044 }
1043 } else { // no conflict 1045 } else { // no conflict
1044 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1046 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1045 QString des = eventLSync->description(); 1047 QString des = eventLSync->description();
1046 QString pref = "e"; 1048 QString pref = "e";
1047 if ( inR->type() == "Todo" ) 1049 if ( inR->type() == "Todo" )
1048 pref = "t"; 1050 pref = "t";
1049 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 1051 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1050 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1052 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1051 //remote->deleteIncidence( inR ); 1053 //remote->deleteIncidence( inR );
1052 ++deletedEventR; 1054 ++deletedEventR;
1053 } else { 1055 } else {
1054 inR->setLastModified( modifiedCalendar ); 1056 inR->setLastModified( modifiedCalendar );
1055 local->addIncidence( inR->clone() ); 1057 inL = inR->clone();
1058 local->addIncidence( inL );
1056 ++addedEvent; 1059 ++addedEvent;
1057 } 1060 }
1058 } else { 1061 } else {
1059 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 1062 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1060 inR->setLastModified( modifiedCalendar ); 1063 inR->setLastModified( modifiedCalendar );
1061 local->addIncidence( inR->clone() ); 1064 local->addIncidence( inR->clone() );
1062 ++addedEvent; 1065 ++addedEvent;
1063 } else { 1066 } else {
1064 checkExternSyncEvent(eventRSyncSharp, inR); 1067 checkExternSyncEvent(eventRSyncSharp, inR);
1065 remote->deleteIncidence( inR ); 1068 remote->deleteIncidence( inR );
1066 ++deletedEventR; 1069 ++deletedEventR;
1067 } 1070 }
1068 } 1071 }
1069 } 1072 }
1070 } 1073 }
1071 inR = er.next(); 1074 inR = er.next();
1072 } 1075 }
1073 QPtrList<Incidence> el = local->rawIncidences(); 1076 QPtrList<Incidence> el = local->rawIncidences();
1074 inL = el.first(); 1077 inL = el.first();
1075 modulo = (el.count()/10)+1; 1078 modulo = (el.count()/10)+1;
1076 bar.setCaption (i18n("Add / remove events") ); 1079 bar.setCaption (i18n("Add / remove events") );
1077 bar.setTotalSteps ( el.count() ) ; 1080 bar.setTotalSteps ( el.count() ) ;
1078 bar.show(); 1081 bar.show();
1079 incCounter = 0; 1082 incCounter = 0;
1080 1083
1081 while ( inL ) { 1084 while ( inL ) {
1082 1085
1083 qApp->processEvents(); 1086 qApp->processEvents();
1084 if ( ! bar.isVisible() ) 1087 if ( ! bar.isVisible() )
1085 return false; 1088 return false;
1086 if ( incCounter % modulo == 0 ) 1089 if ( incCounter % modulo == 0 )
1087 bar.setProgress( incCounter ); 1090 bar.setProgress( incCounter );
1088 ++incCounter; 1091 ++incCounter;
1089 uid = inL->uid(); 1092 uid = inL->uid();
1090 bool skipIncidence = false; 1093 bool skipIncidence = false;
1091 if ( uid.left(15) == QString("last-syncEvent-") ) 1094 if ( uid.left(15) == QString("last-syncEvent-") )
1092 skipIncidence = true; 1095 skipIncidence = true;
1093 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) 1096 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" )
1094 skipIncidence = true; 1097 skipIncidence = true;
1095 if ( !skipIncidence ) { 1098 if ( !skipIncidence ) {
1096 inR = remote->incidence( uid ); 1099 inR = remote->incidence( uid );
1097 if ( ! inR ) { 1100 if ( ! inR ) {
1098 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1101 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1099 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1102 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1100 local->deleteIncidence( inL ); 1103 local->deleteIncidence( inL );
1101 ++deletedEventL; 1104 ++deletedEventL;
1102 } else { 1105 } else {
1103 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { 1106 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) {
1104 inL->removeID(mCurrentSyncDevice ); 1107 inL->removeID(mCurrentSyncDevice );
1105 ++addedEventR; 1108 ++addedEventR;
1109 qDebug("remote added Incidence %s ", inL->summary().latin1());
1106 inL->setLastModified( modifiedCalendar ); 1110 inL->setLastModified( modifiedCalendar );
1107 remote->addIncidence( inL->clone() ); 1111 inR = inL->clone();
1112 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1113 remote->addIncidence( inR );
1108 } 1114 }
1109 } 1115 }
1110 } else { 1116 } else {
1111 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1117 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1112 checkExternSyncEvent(eventLSyncSharp, inL); 1118 checkExternSyncEvent(eventLSyncSharp, inL);
1113 local->deleteIncidence( inL ); 1119 local->deleteIncidence( inL );
1114 ++deletedEventL; 1120 ++deletedEventL;
1115 } else { 1121 } else {
1116 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { 1122 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) {
1117 ++addedEventR; 1123 ++addedEventR;
1118 inL->setLastModified( modifiedCalendar ); 1124 inL->setLastModified( modifiedCalendar );
1119 remote->addIncidence( inL->clone() ); 1125 remote->addIncidence( inL->clone() );
1120 } 1126 }
1121 } 1127 }
1122 } 1128 }
1123 } 1129 }
1124 } 1130 }
1125 inL = el.next(); 1131 inL = el.next();
1126 } 1132 }
1127 int delFut = 0; 1133 int delFut = 0;
1128 if ( KOPrefs::instance()->mWriteBackInFuture ) { 1134 if ( KOPrefs::instance()->mWriteBackInFuture ) {
1129 er = remote->rawIncidences(); 1135 er = remote->rawIncidences();
1130 inR = er.first(); 1136 inR = er.first();
1131 QDateTime dt; 1137 QDateTime dt;
1132 QDateTime cur = QDateTime::currentDateTime(); 1138 QDateTime cur = QDateTime::currentDateTime();
1133 QDateTime end = cur.addSecs( KOPrefs::instance()->mWriteBackInFuture * 3600 *24 *7 ); 1139 QDateTime end = cur.addSecs( KOPrefs::instance()->mWriteBackInFuture * 3600 *24 *7 );
1134 while ( inR ) { 1140 while ( inR ) {
1135 if ( inR->type() == "Todo" ) { 1141 if ( inR->type() == "Todo" ) {
1136 Todo * t = (Todo*)inR; 1142 Todo * t = (Todo*)inR;
1137 if ( t->hasDueDate() ) 1143 if ( t->hasDueDate() )
1138 dt = t->dtDue(); 1144 dt = t->dtDue();
1139 else 1145 else
1140 dt = cur.addSecs( 62 ); 1146 dt = cur.addSecs( 62 );
1141 } 1147 }
1142 else if (inR->type() == "Event" ) { 1148 else if (inR->type() == "Event" ) {
1143 bool ok; 1149 bool ok;
1144 dt = inR->getNextOccurence( cur, &ok ); 1150 dt = inR->getNextOccurence( cur, &ok );
1145 if ( !ok ) 1151 if ( !ok )
1146 dt = cur.addSecs( -62 ); 1152 dt = cur.addSecs( -62 );
1147 } 1153 }
1148 else 1154 else
1149 dt = inR->dtStart(); 1155 dt = inR->dtStart();
1150 if ( dt < cur || dt > end ) { 1156 if ( dt < cur || dt > end ) {
1151 remote->deleteIncidence( inR ); 1157 remote->deleteIncidence( inR );
1152 ++delFut; 1158 ++delFut;
1153 } 1159 }
1154 inR = er.next(); 1160 inR = er.next();
1155 } 1161 }
1156 } 1162 }
1157 bar.hide(); 1163 bar.hide();
1158 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1164 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1159 eventLSync->setReadOnly( false ); 1165 eventLSync->setReadOnly( false );
1160 eventLSync->setDtStart( mLastCalendarSync ); 1166 eventLSync->setDtStart( mLastCalendarSync );
1161 eventRSync->setDtStart( mLastCalendarSync ); 1167 eventRSync->setDtStart( mLastCalendarSync );
1162 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1168 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1163 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1169 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1164 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1170 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1165 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1171 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1166 eventLSync->setReadOnly( true ); 1172 eventLSync->setReadOnly( true );
1167 if ( mGlobalSyncMode == SYNC_MODE_NORMAL) 1173 if ( mGlobalSyncMode == SYNC_MODE_NORMAL)
1168 remote->addEvent( eventRSync ); 1174 remote->addEvent( eventRSync );
1169 QString mes; 1175 QString mes;
1170 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 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 );
1171 QString delmess; 1177 QString delmess;
1172 if ( delFut ) { 1178 if ( delFut ) {
1173 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\n"),delFut, KOPrefs::instance()->mWriteBackInFuture ); 1179 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\n"),delFut, KOPrefs::instance()->mWriteBackInFuture );
1174 mes += delmess; 1180 mes += delmess;
1175 } 1181 }
1176 if ( KOPrefs::instance()->mShowSyncSummary ) { 1182 if ( KOPrefs::instance()->mShowSyncSummary ) {
1177 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") ); 1183 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") );
1178 } 1184 }
1179 qDebug( mes ); 1185 qDebug( mes );
1180 mCalendar->checkAlarmForIncidence( 0, true ); 1186 mCalendar->checkAlarmForIncidence( 0, true );
1181 return syncOK; 1187 return syncOK;
1182} 1188}
1183 1189
1184void CalendarView::setSyncDevice( QString s ) 1190void CalendarView::setSyncDevice( QString s )
1185{ 1191{
1186 mCurrentSyncDevice= s; 1192 mCurrentSyncDevice= s;
1187} 1193}
1188void CalendarView::setSyncName( QString s ) 1194void CalendarView::setSyncName( QString s )
1189{ 1195{
1190 mCurrentSyncName= s; 1196 mCurrentSyncName= s;
1191} 1197}
1192bool CalendarView::syncCalendar(QString filename, int mode) 1198bool CalendarView::syncCalendar(QString filename, int mode)
1193{ 1199{
1194 mGlobalSyncMode = SYNC_MODE_NORMAL; 1200 mGlobalSyncMode = SYNC_MODE_NORMAL;
1195 CalendarLocal* calendar = new CalendarLocal(); 1201 CalendarLocal* calendar = new CalendarLocal();
1196 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1202 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1197 FileStorage* storage = new FileStorage( calendar ); 1203 FileStorage* storage = new FileStorage( calendar );
1198 bool syncOK = false; 1204 bool syncOK = false;
1199 storage->setFileName( filename ); 1205 storage->setFileName( filename );
1200 // qDebug("loading ... "); 1206 // qDebug("loading ... ");
1201 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { 1207 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) {
1202 getEventViewerDialog()->setSyncMode( true ); 1208 getEventViewerDialog()->setSyncMode( true );
1203 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1209 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1204 getEventViewerDialog()->setSyncMode( false ); 1210 getEventViewerDialog()->setSyncMode( false );
1205 if ( syncOK ) { 1211 if ( syncOK ) {
1206 if ( KOPrefs::instance()->mWriteBackFile ) 1212 if ( KOPrefs::instance()->mWriteBackFile )
1207 { 1213 {
1208 storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); 1214 storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) );
1209 storage->save(); 1215 storage->save();
1210 } 1216 }
1211 } 1217 }
1212 setModified( true ); 1218 setModified( true );
1213 } 1219 }
1214 delete storage; 1220 delete storage;
1215 delete calendar; 1221 delete calendar;
1216 if ( syncOK ) 1222 if ( syncOK )
1217 updateView(); 1223 updateView();
1218 return syncOK; 1224 return syncOK;
1219} 1225}
1220void CalendarView::syncPhone() 1226void CalendarView::syncPhone()
1221{ 1227{
1222 syncExternal( 1 ); 1228 syncExternal( 1 );
1223} 1229}
1224void CalendarView::syncExternal( int mode ) 1230void CalendarView::syncExternal( int mode )
1225{ 1231{
1226 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1232 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1227 //mCurrentSyncDevice = "sharp-DTM"; 1233 //mCurrentSyncDevice = "sharp-DTM";
1228 if ( KOPrefs::instance()->mAskForPreferences ) 1234 if ( KOPrefs::instance()->mAskForPreferences )
1229 edit_sync_options(); 1235 edit_sync_options();
1230 qApp->processEvents(); 1236 qApp->processEvents();
1231 CalendarLocal* calendar = new CalendarLocal(); 1237 CalendarLocal* calendar = new CalendarLocal();
1232 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1238 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1233 bool syncOK = false; 1239 bool syncOK = false;
1234 bool loadSuccess = false; 1240 bool loadSuccess = false;
1235 PhoneFormat* phoneFormat = 0; 1241 PhoneFormat* phoneFormat = 0;
diff --git a/libkcal/alarm.cpp b/libkcal/alarm.cpp
index 29e6205..1fc7169 100644
--- a/libkcal/alarm.cpp
+++ b/libkcal/alarm.cpp
@@ -1,195 +1,229 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 1998 Preston Brown 3 Copyright (c) 1998 Preston Brown
4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5 5
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version. 9 version 2 of the License, or (at your option) any later version.
10 10
11 This library is distributed in the hope that it will be useful, 11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 14 Library General Public License for more details.
15 15
16 You should have received a copy of the GNU Library General Public License 16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to 17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21 21
22#include <kdebug.h> 22#include <kdebug.h>
23 23
24#include "incidence.h" 24#include "incidence.h"
25#include "todo.h" 25#include "todo.h"
26 26
27#include "alarm.h" 27#include "alarm.h"
28 28
29using namespace KCal; 29using namespace KCal;
30#include <qwidget.h> 30#include <qwidget.h>
31Alarm::Alarm(Incidence *parent) 31Alarm::Alarm(Incidence *parent)
32 : mParent(parent), 32 : mParent(parent),
33 mType(Audio), 33 mType(Audio),
34 mDescription(""), // to make operator==() not fail 34 mDescription(""), // to make operator==() not fail
35 mFile(""), // to make operator==() not fail 35 mFile(""), // to make operator==() not fail
36 mMailSubject(""), // to make operator==() not fail 36 mMailSubject(""), // to make operator==() not fail
37 mAlarmSnoozeTime(5), 37 mAlarmSnoozeTime(5),
38 mAlarmRepeatCount(0), 38 mAlarmRepeatCount(0),
39 mEndOffset(false), 39 mEndOffset(false),
40 mHasTime(false), 40 mHasTime(false),
41 mAlarmEnabled(false) 41 mAlarmEnabled(false)
42{ 42{
43 43
44} 44}
45 45
46Alarm::~Alarm() 46Alarm::~Alarm()
47{ 47{
48} 48}
49 49
50bool Alarm::operator==( const Alarm& rhs ) const 50bool Alarm::operator==( const Alarm& rhs ) const
51{ 51{
52
52 if ( mType != rhs.mType || 53 if ( mType != rhs.mType ||
53 mAlarmSnoozeTime != rhs.mAlarmSnoozeTime || 54 mAlarmSnoozeTime != rhs.mAlarmSnoozeTime ||
54 mAlarmRepeatCount != rhs.mAlarmRepeatCount || 55 mAlarmRepeatCount != rhs.mAlarmRepeatCount ||
55 mAlarmEnabled != rhs.mAlarmEnabled || 56 mAlarmEnabled != rhs.mAlarmEnabled ||
56 mHasTime != rhs.mHasTime) 57 mHasTime != rhs.mHasTime)
57 return false; 58 return false;
58 59
60#if 0
61 if ( mType != rhs.mType ) {
62
63 qDebug("aaa1 ");
64 return false;
65 }
66
67 if ( mAlarmSnoozeTime != rhs.mAlarmSnoozeTime ) {
68
69 qDebug("aaa2 ");
70 return false;
71 }
72
73
74 if ( mAlarmRepeatCount != rhs.mAlarmRepeatCount ) {
75
76 qDebug("aaa3 ");
77 return false;
78 }
79
80 if ( mAlarmEnabled != rhs.mAlarmEnabled ) {
81
82 qDebug("aaa4 ");
83 return false;
84 }
85
86 if ( mHasTime != rhs.mHasTime ) {
87
88 qDebug("aaa5 ");
89 return false;
90 }
91#endif
92
93
59 if (mHasTime) { 94 if (mHasTime) {
60 if (mAlarmTime != rhs.mAlarmTime) 95 if (mAlarmTime != rhs.mAlarmTime)
61 return false; 96 return false;
62 } else { 97 } else {
63 if (mOffset != rhs.mOffset || 98 if (mOffset != rhs.mOffset ||
64 mEndOffset != rhs.mEndOffset) 99 mEndOffset != rhs.mEndOffset)
65 return false; 100 return false;
66 } 101 }
67
68 switch (mType) { 102 switch (mType) {
69 case Display: 103 case Display:
70 return mDescription == rhs.mDescription; 104 return mDescription == rhs.mDescription;
71 105
72 case Email: 106 case Email:
73 return mDescription == rhs.mDescription && 107 return mDescription == rhs.mDescription &&
74 mMailAttachFiles == rhs.mMailAttachFiles && 108 mMailAttachFiles == rhs.mMailAttachFiles &&
75 mMailAddresses == rhs.mMailAddresses && 109 mMailAddresses == rhs.mMailAddresses &&
76 mMailSubject == rhs.mMailSubject; 110 mMailSubject == rhs.mMailSubject;
77 111
78 case Procedure: 112 case Procedure:
79 return mFile == rhs.mFile && 113 return mFile == rhs.mFile &&
80 mDescription == rhs.mDescription; 114 mDescription == rhs.mDescription;
81 115
82 case Audio: 116 case Audio:
83 return mFile == rhs.mFile; 117 return mFile == rhs.mFile;
84 118
85 case Invalid: 119 case Invalid:
86 break; 120 break;
87 } 121 }
88 return false; 122 return false;
89} 123}
90 124
91void Alarm::setType(Alarm::Type type) 125void Alarm::setType(Alarm::Type type)
92{ 126{
93 if (type == mType) 127 if (type == mType)
94 return; 128 return;
95 129
96 switch (type) { 130 switch (type) {
97 case Display: 131 case Display:
98 mDescription = ""; 132 mDescription = "";
99 break; 133 break;
100 case Procedure: 134 case Procedure:
101 mFile = mDescription = ""; 135 mFile = mDescription = "";
102 break; 136 break;
103 case Audio: 137 case Audio:
104 mFile = ""; 138 mFile = "";
105 break; 139 break;
106 case Email: 140 case Email:
107 mMailSubject = mDescription = ""; 141 mMailSubject = mDescription = "";
108 mMailAddresses.clear(); 142 mMailAddresses.clear();
109 mMailAttachFiles.clear(); 143 mMailAttachFiles.clear();
110 break; 144 break;
111 case Invalid: 145 case Invalid:
112 break; 146 break;
113 default: 147 default:
114 return; 148 return;
115 } 149 }
116 mType = type; 150 mType = type;
117 mParent->updated(); 151 mParent->updated();
118} 152}
119 153
120Alarm::Type Alarm::type() const 154Alarm::Type Alarm::type() const
121{ 155{
122 return mType; 156 return mType;
123} 157}
124 158
125void Alarm::setAudioAlarm(const QString &audioFile) 159void Alarm::setAudioAlarm(const QString &audioFile)
126{ 160{
127 mType = Audio; 161 mType = Audio;
128 mFile = audioFile; 162 mFile = audioFile;
129 mParent->updated(); 163 mParent->updated();
130} 164}
131 165
132void Alarm::setAudioFile(const QString &audioFile) 166void Alarm::setAudioFile(const QString &audioFile)
133{ 167{
134 if (mType == Audio) { 168 if (mType == Audio) {
135 mFile = audioFile; 169 mFile = audioFile;
136 mParent->updated(); 170 mParent->updated();
137 } 171 }
138} 172}
139 173
140QString Alarm::audioFile() const 174QString Alarm::audioFile() const
141{ 175{
142 return (mType == Audio) ? mFile : QString::null; 176 return (mType == Audio) ? mFile : QString::null;
143} 177}
144 178
145void Alarm::setProcedureAlarm(const QString &programFile, const QString &arguments) 179void Alarm::setProcedureAlarm(const QString &programFile, const QString &arguments)
146{ 180{
147 mType = Procedure; 181 mType = Procedure;
148 mFile = programFile; 182 mFile = programFile;
149 mDescription = arguments; 183 mDescription = arguments;
150 mParent->updated(); 184 mParent->updated();
151} 185}
152 186
153void Alarm::setProgramFile(const QString &programFile) 187void Alarm::setProgramFile(const QString &programFile)
154{ 188{
155 if (mType == Procedure) { 189 if (mType == Procedure) {
156 mFile = programFile; 190 mFile = programFile;
157 mParent->updated(); 191 mParent->updated();
158 } 192 }
159} 193}
160 194
161QString Alarm::programFile() const 195QString Alarm::programFile() const
162{ 196{
163 return (mType == Procedure) ? mFile : QString::null; 197 return (mType == Procedure) ? mFile : QString::null;
164} 198}
165 199
166void Alarm::setProgramArguments(const QString &arguments) 200void Alarm::setProgramArguments(const QString &arguments)
167{ 201{
168 if (mType == Procedure) { 202 if (mType == Procedure) {
169 mDescription = arguments; 203 mDescription = arguments;
170 mParent->updated(); 204 mParent->updated();
171 } 205 }
172} 206}
173 207
174QString Alarm::programArguments() const 208QString Alarm::programArguments() const
175{ 209{
176 return (mType == Procedure) ? mDescription : QString::null; 210 return (mType == Procedure) ? mDescription : QString::null;
177} 211}
178 212
179void Alarm::setEmailAlarm(const QString &subject, const QString &text, 213void Alarm::setEmailAlarm(const QString &subject, const QString &text,
180 const QValueList<Person> &addressees, const QStringList &attachments) 214 const QValueList<Person> &addressees, const QStringList &attachments)
181{ 215{
182 mType = Email; 216 mType = Email;
183 mMailSubject = subject; 217 mMailSubject = subject;
184 mDescription = text; 218 mDescription = text;
185 mMailAddresses = addressees; 219 mMailAddresses = addressees;
186 mMailAttachFiles = attachments; 220 mMailAttachFiles = attachments;
187 mParent->updated(); 221 mParent->updated();
188} 222}
189 223
190void Alarm::setMailAddress(const Person &mailAddress) 224void Alarm::setMailAddress(const Person &mailAddress)
191{ 225{
192 if (mType == Email) { 226 if (mType == Email) {
193 mMailAddresses.clear(); 227 mMailAddresses.clear();
194 mMailAddresses += mailAddress; 228 mMailAddresses += mailAddress;
195 mParent->updated(); 229 mParent->updated();
diff --git a/libkcal/recurrence.cpp b/libkcal/recurrence.cpp
index dd74e10..e84f672 100644
--- a/libkcal/recurrence.cpp
+++ b/libkcal/recurrence.cpp
@@ -1,264 +1,296 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 1998 Preston Brown 3 Copyright (c) 1998 Preston Brown
4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5 Copyright (c) 2002 David Jarvie <software@astrojar.org.uk> 5 Copyright (c) 2002 David Jarvie <software@astrojar.org.uk>
6 6
7 This library is free software; you can redistribute it and/or 7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public 8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either 9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version. 10 version 2 of the License, or (at your option) any later version.
11 11
12 This library is distributed in the hope that it will be useful, 12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details. 15 Library General Public License for more details.
16 16
17 You should have received a copy of the GNU Library General Public License 17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to 18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. 20 Boston, MA 02111-1307, USA.
21*/ 21*/
22 22
23#include <limits.h> 23#include <limits.h>
24 24
25#include <kdebug.h> 25#include <kdebug.h>
26#include <kglobal.h> 26#include <kglobal.h>
27#include <klocale.h> 27#include <klocale.h>
28 28
29#include "incidence.h" 29#include "incidence.h"
30 30
31#include "recurrence.h" 31#include "recurrence.h"
32 32
33using namespace KCal; 33using namespace KCal;
34 34
35Recurrence::Feb29Type Recurrence::mFeb29YearlyDefaultType = Recurrence::rMar1; 35Recurrence::Feb29Type Recurrence::mFeb29YearlyDefaultType = Recurrence::rMar1;
36 36
37 37
38Recurrence::Recurrence(Incidence *parent, int compatVersion) 38Recurrence::Recurrence(Incidence *parent, int compatVersion)
39: recurs(rNone), // by default, it's not a recurring event 39: recurs(rNone), // by default, it's not a recurring event
40 rWeekStart(1), // default is Monday 40 rWeekStart(1), // default is Monday
41 rDays(7), 41 rDays(7),
42 mFloats(parent ? parent->doesFloat() : false), 42 mFloats(parent ? parent->doesFloat() : false),
43 mRecurReadOnly(false), 43 mRecurReadOnly(false),
44 mRecurExDatesCount(0), 44 mRecurExDatesCount(0),
45 mFeb29YearlyType(mFeb29YearlyDefaultType), 45 mFeb29YearlyType(mFeb29YearlyDefaultType),
46 mCompatVersion(compatVersion ? compatVersion : INT_MAX), 46 mCompatVersion(compatVersion ? compatVersion : INT_MAX),
47 mCompatRecurs(rNone), 47 mCompatRecurs(rNone),
48 mCompatDuration(0), 48 mCompatDuration(0),
49 mParent(parent) 49 mParent(parent)
50{ 50{
51 rMonthDays.setAutoDelete( true ); 51 rMonthDays.setAutoDelete( true );
52 rMonthPositions.setAutoDelete( true ); 52 rMonthPositions.setAutoDelete( true );
53 rYearNums.setAutoDelete( true ); 53 rYearNums.setAutoDelete( true );
54} 54}
55 55
56Recurrence::Recurrence(const Recurrence &r, Incidence *parent) 56Recurrence::Recurrence(const Recurrence &r, Incidence *parent)
57: recurs(r.recurs), 57: recurs(r.recurs),
58 rWeekStart(r.rWeekStart), 58 rWeekStart(r.rWeekStart),
59 rDays(r.rDays.copy()), 59 rDays(r.rDays.copy()),
60 rFreq(r.rFreq), 60 rFreq(r.rFreq),
61 rDuration(r.rDuration), 61 rDuration(r.rDuration),
62 rEndDateTime(r.rEndDateTime), 62 rEndDateTime(r.rEndDateTime),
63 mRecurStart(r.mRecurStart), 63 mRecurStart(r.mRecurStart),
64 mFloats(r.mFloats), 64 mFloats(r.mFloats),
65 mRecurReadOnly(r.mRecurReadOnly), 65 mRecurReadOnly(r.mRecurReadOnly),
66 mRecurExDatesCount(r.mRecurExDatesCount), 66 mRecurExDatesCount(r.mRecurExDatesCount),
67 mFeb29YearlyType(r.mFeb29YearlyType), 67 mFeb29YearlyType(r.mFeb29YearlyType),
68 mCompatVersion(r.mCompatVersion), 68 mCompatVersion(r.mCompatVersion),
69 mCompatRecurs(r.mCompatRecurs), 69 mCompatRecurs(r.mCompatRecurs),
70 mCompatDuration(r.mCompatDuration), 70 mCompatDuration(r.mCompatDuration),
71 mParent(parent) 71 mParent(parent)
72{ 72{
73 for (QPtrListIterator<rMonthPos> mp(r.rMonthPositions); mp.current(); ++mp) { 73 for (QPtrListIterator<rMonthPos> mp(r.rMonthPositions); mp.current(); ++mp) {
74 rMonthPos *tmp = new rMonthPos; 74 rMonthPos *tmp = new rMonthPos;
75 tmp->rPos = mp.current()->rPos; 75 tmp->rPos = mp.current()->rPos;
76 tmp->negative = mp.current()->negative; 76 tmp->negative = mp.current()->negative;
77 tmp->rDays = mp.current()->rDays.copy(); 77 tmp->rDays = mp.current()->rDays.copy();
78 rMonthPositions.append(tmp); 78 rMonthPositions.append(tmp);
79 } 79 }
80 for (QPtrListIterator<int> md(r.rMonthDays); md.current(); ++md) { 80 for (QPtrListIterator<int> md(r.rMonthDays); md.current(); ++md) {
81 int *tmp = new int; 81 int *tmp = new int;
82 *tmp = *md.current(); 82 *tmp = *md.current();
83 rMonthDays.append(tmp); 83 rMonthDays.append(tmp);
84 } 84 }
85 for (QPtrListIterator<int> yn(r.rYearNums); yn.current(); ++yn) { 85 for (QPtrListIterator<int> yn(r.rYearNums); yn.current(); ++yn) {
86 int *tmp = new int; 86 int *tmp = new int;
87 *tmp = *yn.current(); 87 *tmp = *yn.current();
88 rYearNums.append(tmp); 88 rYearNums.append(tmp);
89 } 89 }
90 rMonthDays.setAutoDelete( true ); 90 rMonthDays.setAutoDelete( true );
91 rMonthPositions.setAutoDelete( true ); 91 rMonthPositions.setAutoDelete( true );
92 rYearNums.setAutoDelete( true ); 92 rYearNums.setAutoDelete( true );
93} 93}
94 94
95Recurrence::~Recurrence() 95Recurrence::~Recurrence()
96{ 96{
97} 97}
98 98
99 99
100bool Recurrence::operator==( const Recurrence& r2 ) const 100bool Recurrence::operator==( const Recurrence& r2 ) const
101{ 101{
102 102
103 // the following line is obvious 103 // the following line is obvious
104 if ( recurs == rNone && r2.recurs == rNone ) 104 if ( recurs == rNone && r2.recurs == rNone )
105 return true; 105 return true;
106 // we need the above line, because two non recurring events may 106 // we need the above line, because two non recurring events may
107 // differ in the other settings, because one (or both) 107 // differ in the other settings, because one (or both)
108 // may be not initialized properly 108 // may be not initialized properly
109
109 if ( recurs != r2.recurs 110 if ( recurs != r2.recurs
110 || rFreq != r2.rFreq 111 || rFreq != r2.rFreq
111 || rDuration != r2.rDuration 112 || rDuration != r2.rDuration
112 || !rDuration && rEndDateTime != r2.rEndDateTime 113 || !rDuration && rEndDateTime != r2.rEndDateTime
113 || mRecurStart != r2.mRecurStart 114 || mRecurStart != r2.mRecurStart
114 || mFloats != r2.mFloats 115 || mFloats != r2.mFloats
115 || mRecurReadOnly != r2.mRecurReadOnly 116 || mRecurReadOnly != r2.mRecurReadOnly
116 || mRecurExDatesCount != r2.mRecurExDatesCount ) 117 || mRecurExDatesCount != r2.mRecurExDatesCount )
117 return false; 118 return false;
118 // no need to compare mCompat* and mParent 119 // no need to compare mCompat* and mParent
119 // OK to compare the pointers 120 // OK to compare the pointers
120 switch ( recurs ) 121 switch ( recurs )
121 { 122 {
122 case rWeekly: 123 case rWeekly:
123 return rDays == r2.rDays 124 return rDays == r2.rDays
124 && rWeekStart == r2.rWeekStart; 125 && rWeekStart == r2.rWeekStart;
125 case rMonthlyPos: 126 case rMonthlyPos: {
126 return rMonthPositions.count() == r2.rMonthPositions.count(); 127 QPtrList<rMonthPos> MonthPositions = rMonthPositions;
127 case rMonthlyDay: 128 QPtrList<rMonthPos> MonthPositions2 = r2.rMonthPositions;
128 return rMonthDays.count() == r2.rMonthDays.count(); 129 if ( !MonthPositions.count() )
129 case rYearlyPos: 130 return false;
130 return rYearNums.count() == r2.rYearNums.count() 131 if ( !MonthPositions2.count() )
131 && rMonthPositions.count() == r2.rMonthPositions.count(); 132 return false;
132 case rYearlyMonth: 133 return MonthPositions.first()->rPos == MonthPositions2.first()->rPos;
133 return rYearNums.count() == r2.rYearNums.count() 134 }
134 && mFeb29YearlyType == r2.mFeb29YearlyType; 135 case rMonthlyDay: {
135 case rYearlyDay: 136 QPtrList<int> MonthDays = rMonthDays ;
136 return rYearNums == r2.rYearNums; 137 QPtrList<int> MonthDays2 = r2.rMonthDays ;
138 if ( !MonthDays.count() )
139 return false;
140 if ( !MonthDays2.count() )
141 return false;
142 return *MonthDays.first() == *MonthDays2.first() ;
143 }
144 case rYearlyPos: {
145
146 QPtrList<int> YearNums = rYearNums;
147 QPtrList<int> YearNums2 = r2.rYearNums;
148 if ( *YearNums.first() != *YearNums2.first() )
149 return false;
150 QPtrList<rMonthPos> MonthPositions = rMonthPositions;
151 QPtrList<rMonthPos> MonthPositions2 = r2.rMonthPositions;
152 if ( !MonthPositions.count() )
153 return false;
154 if ( !MonthPositions2.count() )
155 return false;
156 return MonthPositions.first()->rPos == MonthPositions2.first()->rPos;
157
158 }
159 case rYearlyMonth: {
160 QPtrList<int> YearNums = rYearNums;
161 QPtrList<int> YearNums2 = r2.rYearNums;
162 return ( *YearNums.first() == *YearNums2.first() && mFeb29YearlyType == r2.mFeb29YearlyType);
163 }
164 case rYearlyDay: {
165 QPtrList<int> YearNums = rYearNums;
166 QPtrList<int> YearNums2 = r2.rYearNums;
167 return ( *YearNums.first() == *YearNums2.first() );
168 }
137 case rNone: 169 case rNone:
138 case rMinutely: 170 case rMinutely:
139 case rHourly: 171 case rHourly:
140 case rDaily: 172 case rDaily:
141 default: 173 default:
142 return true; 174 return true;
143 } 175 }
144} 176}
145/* 177/*
146bool Recurrence::compareLists( const QPtrList<int> &l1 ,const QPtrList<int> &l2) 178bool Recurrence::compareLists( const QPtrList<int> &l1 ,const QPtrList<int> &l2)
147{ 179{
148 if ( l1.count() != l2.count() ) 180 if ( l1.count() != l2.count() )
149 return false; 181 return false;
150 int count = l1.count(); 182 int count = l1.count();
151 int i; 183 int i;
152 for ( i = 0; i < count ; ++i ) { 184 for ( i = 0; i < count ; ++i ) {
153 // if ( l1.at(i) != l2.at(i) ) 185 // if ( l1.at(i) != l2.at(i) )
154 return false; 186 return false;
155 qDebug("compüare "); 187 qDebug("compüare ");
156 } 188 }
157 return true; 189 return true;
158} 190}
159*/ 191*/
160QString Recurrence::recurrenceText() const 192QString Recurrence::recurrenceText() const
161{ 193{
162 QString recurText = i18n("No"); 194 QString recurText = i18n("No");
163 if ( recurs == Recurrence::rMinutely ) 195 if ( recurs == Recurrence::rMinutely )
164 recurText = i18n("minutely"); 196 recurText = i18n("minutely");
165 else if ( recurs == Recurrence::rHourly ) 197 else if ( recurs == Recurrence::rHourly )
166 recurText = i18n("hourly"); 198 recurText = i18n("hourly");
167 else if ( recurs == Recurrence::rDaily ) 199 else if ( recurs == Recurrence::rDaily )
168 recurText = i18n("daily"); 200 recurText = i18n("daily");
169 else if ( recurs == Recurrence::rWeekly ) 201 else if ( recurs == Recurrence::rWeekly )
170 recurText = i18n("weekly"); 202 recurText = i18n("weekly");
171 else if ( recurs == Recurrence::rMonthlyPos ) 203 else if ( recurs == Recurrence::rMonthlyPos )
172 recurText = i18n("monthly"); 204 recurText = i18n("monthly");
173 else if ( recurs == Recurrence::rMonthlyDay ) 205 else if ( recurs == Recurrence::rMonthlyDay )
174 recurText = i18n("day-monthly"); 206 recurText = i18n("day-monthly");
175 else if ( recurs == Recurrence::rYearlyMonth ) 207 else if ( recurs == Recurrence::rYearlyMonth )
176 recurText = i18n("month-yearly"); 208 recurText = i18n("month-yearly");
177 else if ( recurs == Recurrence::rYearlyDay ) 209 else if ( recurs == Recurrence::rYearlyDay )
178 recurText = i18n("day-yearly"); 210 recurText = i18n("day-yearly");
179 else if ( recurs == Recurrence::rYearlyPos ) 211 else if ( recurs == Recurrence::rYearlyPos )
180 recurText = i18n("position-yearly"); 212 recurText = i18n("position-yearly");
181 return recurText; 213 return recurText;
182} 214}
183 215
184void Recurrence::setCompatVersion(int version) 216void Recurrence::setCompatVersion(int version)
185{ 217{
186 mCompatVersion = version ? version : INT_MAX; 218 mCompatVersion = version ? version : INT_MAX;
187} 219}
188 220
189ushort Recurrence::doesRecur() const 221ushort Recurrence::doesRecur() const
190{ 222{
191 return recurs; 223 return recurs;
192} 224}
193 225
194bool Recurrence::recursOnPure(const QDate &qd) const 226bool Recurrence::recursOnPure(const QDate &qd) const
195{ 227{
196 switch(recurs) { 228 switch(recurs) {
197 case rMinutely: 229 case rMinutely:
198 return recursSecondly(qd, rFreq*60); 230 return recursSecondly(qd, rFreq*60);
199 case rHourly: 231 case rHourly:
200 return recursSecondly(qd, rFreq*3600); 232 return recursSecondly(qd, rFreq*3600);
201 case rDaily: 233 case rDaily:
202 return recursDaily(qd); 234 return recursDaily(qd);
203 case rWeekly: 235 case rWeekly:
204 return recursWeekly(qd); 236 return recursWeekly(qd);
205 case rMonthlyPos: 237 case rMonthlyPos:
206 case rMonthlyDay: 238 case rMonthlyDay:
207 return recursMonthly(qd); 239 return recursMonthly(qd);
208 case rYearlyMonth: 240 case rYearlyMonth:
209 return recursYearlyByMonth(qd); 241 return recursYearlyByMonth(qd);
210 case rYearlyDay: 242 case rYearlyDay:
211 return recursYearlyByDay(qd); 243 return recursYearlyByDay(qd);
212 case rYearlyPos: 244 case rYearlyPos:
213 return recursYearlyByPos(qd); 245 return recursYearlyByPos(qd);
214 default: 246 default:
215 return false; 247 return false;
216 case rNone: 248 case rNone:
217 return false; 249 return false;
218 } // case 250 } // case
219 return false; 251 return false;
220} 252}
221 253
222bool Recurrence::recursAtPure(const QDateTime &dt) const 254bool Recurrence::recursAtPure(const QDateTime &dt) const
223{ 255{
224 switch(recurs) { 256 switch(recurs) {
225 case rMinutely: 257 case rMinutely:
226 return recursMinutelyAt(dt, rFreq); 258 return recursMinutelyAt(dt, rFreq);
227 case rHourly: 259 case rHourly:
228 return recursMinutelyAt(dt, rFreq*60); 260 return recursMinutelyAt(dt, rFreq*60);
229 default: 261 default:
230 if (dt.time() != mRecurStart.time()) 262 if (dt.time() != mRecurStart.time())
231 return false; 263 return false;
232 switch(recurs) { 264 switch(recurs) {
233 case rDaily: 265 case rDaily:
234 return recursDaily(dt.date()); 266 return recursDaily(dt.date());
235 case rWeekly: 267 case rWeekly:
236 return recursWeekly(dt.date()); 268 return recursWeekly(dt.date());
237 case rMonthlyPos: 269 case rMonthlyPos:
238 case rMonthlyDay: 270 case rMonthlyDay:
239 return recursMonthly(dt.date()); 271 return recursMonthly(dt.date());
240 case rYearlyMonth: 272 case rYearlyMonth:
241 return recursYearlyByMonth(dt.date()); 273 return recursYearlyByMonth(dt.date());
242 case rYearlyDay: 274 case rYearlyDay:
243 return recursYearlyByDay(dt.date()); 275 return recursYearlyByDay(dt.date());
244 case rYearlyPos: 276 case rYearlyPos:
245 return recursYearlyByPos(dt.date()); 277 return recursYearlyByPos(dt.date());
246 default: 278 default:
247 return false; 279 return false;
248 case rNone: 280 case rNone:
249 return false; 281 return false;
250 } 282 }
251 } // case 283 } // case
252 return false; 284 return false;
253} 285}
254 286
255QDate Recurrence::endDate() const 287QDate Recurrence::endDate() const
256{ 288{
257 int count = 0; 289 int count = 0;
258 QDate end; 290 QDate end;
259 if (recurs != rNone) { 291 if (recurs != rNone) {
260 if (rDuration < 0) 292 if (rDuration < 0)
261 return QDate(); // infinite recurrence 293 return QDate(); // infinite recurrence
262 if (rDuration == 0) 294 if (rDuration == 0)
263 return rEndDateTime.date(); 295 return rEndDateTime.date();
264 296
diff --git a/libkcal/sharpformat.cpp b/libkcal/sharpformat.cpp
index defdb09..89eb72f 100644
--- a/libkcal/sharpformat.cpp
+++ b/libkcal/sharpformat.cpp
@@ -55,451 +55,452 @@ using namespace KCal;
55// 13 RPOS pos = 4. monday in month 55// 13 RPOS pos = 4. monday in month
56// 14 RDYS days: 1 mon/ 2 tue .. 64 sun 56// 14 RDYS days: 1 mon/ 2 tue .. 64 sun
57// 15 REND 0 = no end/ 1 = end 57// 15 REND 0 = no end/ 1 = end
58// 16 REDT rec end dt 58// 16 REDT rec end dt
59//ALSD 59//ALSD
60//ALED 60//ALED
61//MDAY 61//MDAY
62 62
63class SharpParser : public QObject 63class SharpParser : public QObject
64{ 64{
65 public: 65 public:
66 SharpParser( Calendar *calendar ) : mCalendar( calendar ) { 66 SharpParser( Calendar *calendar ) : mCalendar( calendar ) {
67 oldCategories = 0; 67 oldCategories = 0;
68 } 68 }
69 69
70 bool startElement( Calendar *existingCalendar, const QStringList & attList, QString qName ) 70 bool startElement( Calendar *existingCalendar, const QStringList & attList, QString qName )
71 { 71 {
72 int i = 1; 72 int i = 1;
73 bool skip = true; 73 bool skip = true;
74 int max = attList.count() -2; 74 int max = attList.count() -2;
75 while ( i < max ) { 75 while ( i < max ) {
76 if ( !attList[i].isEmpty() ) { 76 if ( !attList[i].isEmpty() ) {
77 skip = false; 77 skip = false;
78 break; 78 break;
79 } 79 }
80 ++i ; 80 ++i ;
81 } 81 }
82 if ( skip ) 82 if ( skip )
83 return false; 83 return false;
84 ulong cSum = SharpFormat::getCsum(attList ); 84 ulong cSum = SharpFormat::getCsum(attList );
85 85
86 if ( qName == "Event" ) { 86 if ( qName == "Event" ) {
87 Event *event; 87 Event *event;
88 event = existingCalendar->event( "Sharp_DTM",attList[0] ); 88 event = existingCalendar->event( "Sharp_DTM",attList[0] );
89 if ( event ) 89 if ( event )
90 event = (Event*)event->clone(); 90 event = (Event*)event->clone();
91 else 91 else
92 event = new Event; 92 event = new Event;
93 event->setID("Sharp_DTM", attList[0] ); 93 event->setID("Sharp_DTM", attList[0] );
94 event->setCsum( "Sharp_DTM", QString::number( cSum )); 94 event->setCsum( "Sharp_DTM", QString::number( cSum ));
95 event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); 95 event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL );
96 96
97 event->setSummary( attList[2] ); 97 event->setSummary( attList[2] );
98 event->setLocation( attList[3] ); 98 event->setLocation( attList[3] );
99 event->setDescription( attList[4] ); 99 event->setDescription( attList[4] );
100 if ( attList[7] == "1" ) { 100 if ( attList[7] == "1" ) {
101 event->setDtStart( QDateTime(fromString( attList[17]+"T000000", false ).date(),QTime(0,0,0 ) )); 101 event->setDtStart( QDateTime(fromString( attList[17]+"T000000", false ).date(),QTime(0,0,0 ) ));
102 event->setDtEnd( QDateTime(fromString( attList[18]+"T000000", false ).date(),QTime(0,0,0 ))); 102 event->setDtEnd( QDateTime(fromString( attList[18]+"T000000", false ).date(),QTime(0,0,0 )));
103 event->setFloats( true ); 103 event->setFloats( true );
104 } else { 104 } else {
105 event->setFloats( false ); 105 event->setFloats( false );
106 event->setDtStart( fromString( attList[5] ) ); 106 event->setDtStart( fromString( attList[5] ) );
107 event->setDtEnd( fromString( attList[6] )); 107 event->setDtEnd( fromString( attList[6] ));
108 } 108 }
109 109
110 QString rtype = attList[11]; 110 QString rtype = attList[11];
111 if ( rtype != "255" ) { 111 if ( rtype != "255" ) {
112 // qDebug("recurs "); 112 // qDebug("recurs ");
113 QDate startDate = event->dtStart().date(); 113 QDate startDate = event->dtStart().date();
114 114
115 QString freqStr = attList[12]; 115 QString freqStr = attList[12];
116 int freq = freqStr.toInt(); 116 int freq = freqStr.toInt();
117 117
118 QString hasEndDateStr = attList[15] ; 118 QString hasEndDateStr = attList[15] ;
119 bool hasEndDate = hasEndDateStr == "1"; 119 bool hasEndDate = hasEndDateStr == "1";
120 120
121 QString endDateStr = attList[16]; 121 QString endDateStr = attList[16];
122 QDate endDate = fromString( endDateStr ).date(); 122 QDate endDate = fromString( endDateStr ).date();
123 123
124 QString weekDaysStr = attList[14]; 124 QString weekDaysStr = attList[14];
125 uint weekDaysNum = weekDaysStr.toInt(); 125 uint weekDaysNum = weekDaysStr.toInt();
126 126
127 QBitArray weekDays( 7 ); 127 QBitArray weekDays( 7 );
128 int i; 128 int i;
129 int bb = 1; 129 int bb = 1;
130 for( i = 1; i <= 7; ++i ) { 130 for( i = 1; i <= 7; ++i ) {
131 weekDays.setBit( i - 1, ( bb & weekDaysNum )); 131 weekDays.setBit( i - 1, ( bb & weekDaysNum ));
132 bb = 2 << (i-1); 132 bb = 2 << (i-1);
133 //qDebug(" %d bit %d ",i-1,weekDays.at(i-1) ); 133 //qDebug(" %d bit %d ",i-1,weekDays.at(i-1) );
134 } 134 }
135 // qDebug("next "); 135 // qDebug("next ");
136 QString posStr = attList[13]; 136 QString posStr = attList[13];
137 int pos = posStr.toInt(); 137 int pos = posStr.toInt();
138 Recurrence *r = event->recurrence(); 138 Recurrence *r = event->recurrence();
139 139
140 if ( rtype == "0" ) { 140 if ( rtype == "0" ) {
141 if ( hasEndDate ) r->setDaily( freq, endDate ); 141 if ( hasEndDate ) r->setDaily( freq, endDate );
142 else r->setDaily( freq, -1 ); 142 else r->setDaily( freq, -1 );
143 } else if ( rtype == "1" ) { 143 } else if ( rtype == "1" ) {
144 if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate ); 144 if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate );
145 else r->setWeekly( freq, weekDays, -1 ); 145 else r->setWeekly( freq, weekDays, -1 );
146 } else if ( rtype == "3" ) { 146 } else if ( rtype == "3" ) {
147 if ( hasEndDate ) 147 if ( hasEndDate )
148 r->setMonthly( Recurrence::rMonthlyDay, freq, endDate ); 148 r->setMonthly( Recurrence::rMonthlyDay, freq, endDate );
149 else 149 else
150 r->setMonthly( Recurrence::rMonthlyDay, freq, -1 ); 150 r->setMonthly( Recurrence::rMonthlyDay, freq, -1 );
151 r->addMonthlyDay( startDate.day() ); 151 r->addMonthlyDay( startDate.day() );
152 } else if ( rtype == "2" ) { 152 } else if ( rtype == "2" ) {
153 if ( hasEndDate ) 153 if ( hasEndDate )
154 r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); 154 r->setMonthly( Recurrence::rMonthlyPos, freq, endDate );
155 else 155 else
156 r->setMonthly( Recurrence::rMonthlyPos, freq, -1 ); 156 r->setMonthly( Recurrence::rMonthlyPos, freq, -1 );
157 QBitArray days( 7 ); 157 QBitArray days( 7 );
158 days.fill( false ); 158 days.fill( false );
159 days.setBit( startDate.dayOfWeek() - 1 ); 159 days.setBit( startDate.dayOfWeek() - 1 );
160 r->addMonthlyPos( pos, days ); 160 r->addMonthlyPos( pos, days );
161 } else if ( rtype == "4" ) { 161 } else if ( rtype == "4" ) {
162 if ( hasEndDate ) 162 if ( hasEndDate )
163 r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); 163 r->setYearly( Recurrence::rYearlyMonth, freq, endDate );
164 else 164 else
165 r->setYearly( Recurrence::rYearlyMonth, freq, -1 ); 165 r->setYearly( Recurrence::rYearlyMonth, freq, -1 );
166 r->addYearlyNum( startDate.month() ); 166 r->addYearlyNum( startDate.month() );
167 } 167 }
168 } else { 168 } else {
169 event->recurrence()->unsetRecurs(); 169 event->recurrence()->unsetRecurs();
170 } 170 }
171 171
172 QString categoryList = attList[1] ; 172 QString categoryList = attList[1] ;
173 event->setCategories( lookupCategories( categoryList ) ); 173 event->setCategories( lookupCategories( categoryList ) );
174 174
175 // strange 0 semms to mean: alarm enabled 175 // strange 0 semms to mean: alarm enabled
176 if ( attList[8] == "0" ) { 176 if ( attList[8] == "0" ) {
177 Alarm *alarm; 177 Alarm *alarm;
178 if ( event->alarms().count() > 0 ) 178 if ( event->alarms().count() > 0 )
179 alarm = event->alarms().first(); 179 alarm = event->alarms().first();
180 else { 180 else {
181 alarm = new Alarm( event ); 181 alarm = new Alarm( event );
182 event->addAlarm( alarm ); 182 event->addAlarm( alarm );
183 alarm->setType( Alarm::Audio );
183 } 184 }
184 alarm->setType( Alarm::Audio ); 185 //alarm->setType( Alarm::Audio );
185 alarm->setEnabled( true ); 186 alarm->setEnabled( true );
186 int alarmOffset = attList[9].toInt(); 187 int alarmOffset = attList[9].toInt();
187 alarm->setStartOffset( alarmOffset * -60 ); 188 alarm->setStartOffset( alarmOffset * -60 );
188 } else { 189 } else {
189 Alarm *alarm; 190 Alarm *alarm;
190 if ( event->alarms().count() > 0 ) { 191 if ( event->alarms().count() > 0 ) {
191 alarm = event->alarms().first(); 192 alarm = event->alarms().first();
192 alarm->setType( Alarm::Audio ); 193 alarm->setType( Alarm::Audio );
193 alarm->setStartOffset( -60*15 ); 194 alarm->setStartOffset( -60*15 );
194 alarm->setEnabled( false ); 195 alarm->setEnabled( false );
195 } 196 }
196 } 197 }
197 198
198 mCalendar->addEvent( event); 199 mCalendar->addEvent( event);
199 } else if ( qName == "Todo" ) { 200 } else if ( qName == "Todo" ) {
200 Todo *todo; 201 Todo *todo;
201 202
202 todo = existingCalendar->todo( "Sharp_DTM", attList[0] ); 203 todo = existingCalendar->todo( "Sharp_DTM", attList[0] );
203 if (todo ) 204 if (todo )
204 todo = (Todo*)todo->clone(); 205 todo = (Todo*)todo->clone();
205 else 206 else
206 todo = new Todo; 207 todo = new Todo;
207 208
208//CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1 209//CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1
209// 0 1 2 3 4 5 6 7 8 210// 0 1 2 3 4 5 6 7 8
210//1,,,,,1,4,Loch zumachen,"" 211//1,,,,,1,4,Loch zumachen,""
211//3,Privat,20040317T000000,20040318T000000,20040319T000000,0,5,Call bbb,"notes123 bbb gggg ""bb "" " 212//3,Privat,20040317T000000,20040318T000000,20040319T000000,0,5,Call bbb,"notes123 bbb gggg ""bb "" "
212//2,"Familie,Freunde,Holiday",20040318T000000,20040324T000000,20040317T000000,1,2,tod2,notes 213//2,"Familie,Freunde,Holiday",20040318T000000,20040324T000000,20040317T000000,1,2,tod2,notes
213 214
214 todo->setID( "Sharp_DTM", attList[0]); 215 todo->setID( "Sharp_DTM", attList[0]);
215 todo->setCsum( "Sharp_DTM", QString::number( cSum )); 216 todo->setCsum( "Sharp_DTM", QString::number( cSum ));
216 todo->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); 217 todo->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
217 218
218 todo->setSummary( attList[7] ); 219 todo->setSummary( attList[7] );
219 todo->setDescription( attList[8]); 220 todo->setDescription( attList[8]);
220 221
221 int priority = attList[6].toInt(); 222 int priority = attList[6].toInt();
222 if ( priority == 0 ) priority = 3; 223 if ( priority == 0 ) priority = 3;
223 todo->setPriority( priority ); 224 todo->setPriority( priority );
224 225
225 QString categoryList = attList[1]; 226 QString categoryList = attList[1];
226 todo->setCategories( lookupCategories( categoryList ) ); 227 todo->setCategories( lookupCategories( categoryList ) );
227 228
228 229
229 230
230 QString hasDateStr = attList[3]; // due 231 QString hasDateStr = attList[3]; // due
231 if ( !hasDateStr.isEmpty() ) { 232 if ( !hasDateStr.isEmpty() ) {
232 if ( hasDateStr.right(6) == "000000" ) { 233 if ( hasDateStr.right(6) == "000000" ) {
233 todo->setDtDue( QDateTime(fromString( hasDateStr, false ).date(), QTime(0,0,0 )) ); 234 todo->setDtDue( QDateTime(fromString( hasDateStr, false ).date(), QTime(0,0,0 )) );
234 todo->setFloats( true ); 235 todo->setFloats( true );
235 } 236 }
236 else { 237 else {
237 todo->setDtDue( fromString( hasDateStr ) ); 238 todo->setDtDue( fromString( hasDateStr ) );
238 todo->setFloats( false ); 239 todo->setFloats( false );
239 } 240 }
240 241
241 todo->setHasDueDate( true ); 242 todo->setHasDueDate( true );
242 } 243 }
243 hasDateStr = attList[2];//start 244 hasDateStr = attList[2];//start
244 if ( !hasDateStr.isEmpty() ) { 245 if ( !hasDateStr.isEmpty() ) {
245 246
246 todo->setDtStart( fromString( hasDateStr ) ); 247 todo->setDtStart( fromString( hasDateStr ) );
247 todo->setHasStartDate( true); 248 todo->setHasStartDate( true);
248 } else 249 } else
249 todo->setHasStartDate( false ); 250 todo->setHasStartDate( false );
250 hasDateStr = attList[4];//completed 251 hasDateStr = attList[4];//completed
251 if ( !hasDateStr.isEmpty() ) { 252 if ( !hasDateStr.isEmpty() ) {
252 todo->setCompleted(fromString( hasDateStr ) ); 253 todo->setCompleted(fromString( hasDateStr ) );
253 } 254 }
254 QString completedStr = attList[5]; 255 QString completedStr = attList[5];
255 if ( completedStr == "0" ) 256 if ( completedStr == "0" )
256 todo->setCompleted( true ); 257 todo->setCompleted( true );
257 else 258 else
258 todo->setCompleted( false ); 259 todo->setCompleted( false );
259 mCalendar->addTodo( todo ); 260 mCalendar->addTodo( todo );
260 261
261 } else if ( qName == "Category" ) { 262 } else if ( qName == "Category" ) {
262 /* 263 /*
263 QString id = attributes.value( "id" ); 264 QString id = attributes.value( "id" );
264 QString name = attributes.value( "name" ); 265 QString name = attributes.value( "name" );
265 setCategory( id, name ); 266 setCategory( id, name );
266 */ 267 */
267 } 268 }
268 //qDebug("end "); 269 //qDebug("end ");
269 return true; 270 return true;
270 } 271 }
271 272
272 273
273 void setCategoriesList ( QStringList * c ) 274 void setCategoriesList ( QStringList * c )
274 { 275 {
275 oldCategories = c; 276 oldCategories = c;
276 } 277 }
277 278
278 QDateTime fromString ( QString s, bool useTz = true ) { 279 QDateTime fromString ( QString s, bool useTz = true ) {
279 QDateTime dt; 280 QDateTime dt;
280 int y,m,t,h,min,sec; 281 int y,m,t,h,min,sec;
281 y = s.mid(0,4).toInt(); 282 y = s.mid(0,4).toInt();
282 m = s.mid(4,2).toInt(); 283 m = s.mid(4,2).toInt();
283 t = s.mid(6,2).toInt(); 284 t = s.mid(6,2).toInt();
284 h = s.mid(9,2).toInt(); 285 h = s.mid(9,2).toInt();
285 min = s.mid(11,2).toInt(); 286 min = s.mid(11,2).toInt();
286 sec = s.mid(13,2).toInt(); 287 sec = s.mid(13,2).toInt();
287 dt = QDateTime(QDate(y,m,t), QTime(h,min,sec)); 288 dt = QDateTime(QDate(y,m,t), QTime(h,min,sec));
288 int offset = KGlobal::locale()->localTimeOffset( dt ); 289 int offset = KGlobal::locale()->localTimeOffset( dt );
289 if ( useTz ) 290 if ( useTz )
290 dt = dt.addSecs ( offset*60); 291 dt = dt.addSecs ( offset*60);
291 return dt; 292 return dt;
292 293
293 } 294 }
294 protected: 295 protected:
295 QDateTime toDateTime( const QString &value ) 296 QDateTime toDateTime( const QString &value )
296 { 297 {
297 QDateTime dt; 298 QDateTime dt;
298 dt.setTime_t( value.toUInt() ); 299 dt.setTime_t( value.toUInt() );
299 300
300 return dt; 301 return dt;
301 } 302 }
302 303
303 QStringList lookupCategories( const QString &categoryList ) 304 QStringList lookupCategories( const QString &categoryList )
304 { 305 {
305 QStringList categoryIds = QStringList::split( ";", categoryList ); 306 QStringList categoryIds = QStringList::split( ";", categoryList );
306 QStringList categories; 307 QStringList categories;
307 QStringList::ConstIterator it; 308 QStringList::ConstIterator it;
308 for( it = categoryIds.begin(); it != categoryIds.end(); ++it ) { 309 for( it = categoryIds.begin(); it != categoryIds.end(); ++it ) {
309 QString cate = category( *it ); 310 QString cate = category( *it );
310 if ( oldCategories ) { 311 if ( oldCategories ) {
311 if ( ! oldCategories->contains( cate ) ) 312 if ( ! oldCategories->contains( cate ) )
312 oldCategories->append( cate ); 313 oldCategories->append( cate );
313 } 314 }
314 categories.append(cate ); 315 categories.append(cate );
315 } 316 }
316 return categories; 317 return categories;
317 } 318 }
318 319
319 private: 320 private:
320 Calendar *mCalendar; 321 Calendar *mCalendar;
321 QStringList * oldCategories; 322 QStringList * oldCategories;
322 static QString category( const QString &id ) 323 static QString category( const QString &id )
323 { 324 {
324 QMap<QString,QString>::ConstIterator it = mCategoriesMap.find( id ); 325 QMap<QString,QString>::ConstIterator it = mCategoriesMap.find( id );
325 if ( it == mCategoriesMap.end() ) return id; 326 if ( it == mCategoriesMap.end() ) return id;
326 else return *it; 327 else return *it;
327 } 328 }
328 329
329 static void setCategory( const QString &id, const QString &name ) 330 static void setCategory( const QString &id, const QString &name )
330 { 331 {
331 mCategoriesMap.insert( id, name ); 332 mCategoriesMap.insert( id, name );
332 } 333 }
333 334
334 static QMap<QString,QString> mCategoriesMap; 335 static QMap<QString,QString> mCategoriesMap;
335}; 336};
336 337
337QMap<QString,QString> SharpParser::mCategoriesMap; 338QMap<QString,QString> SharpParser::mCategoriesMap;
338 339
339SharpFormat::SharpFormat() 340SharpFormat::SharpFormat()
340{ 341{
341 mCategories = 0; 342 mCategories = 0;
342} 343}
343 344
344SharpFormat::~SharpFormat() 345SharpFormat::~SharpFormat()
345{ 346{
346} 347}
347ulong SharpFormat::getCsum( const QStringList & attList) 348ulong SharpFormat::getCsum( const QStringList & attList)
348{ 349{
349 int max = attList.count() -1; 350 int max = attList.count() -1;
350 ulong cSum = 0; 351 ulong cSum = 0;
351 int j,k,i; 352 int j,k,i;
352 int add; 353 int add;
353 for ( i = 1; i < max ; ++i ) { 354 for ( i = 1; i < max ; ++i ) {
354 QString s = attList[i]; 355 QString s = attList[i];
355 if ( ! s.isEmpty() ){ 356 if ( ! s.isEmpty() ){
356 j = s.length(); 357 j = s.length();
357 for ( k = 0; k < j; ++k ) { 358 for ( k = 0; k < j; ++k ) {
358 int mul = k +1; 359 int mul = k +1;
359 add = s[k].unicode (); 360 add = s[k].unicode ();
360 if ( k < 16 ) 361 if ( k < 16 )
361 mul = mul * mul; 362 mul = mul * mul;
362 add = add * mul *i*i*i; 363 add = add * mul *i*i*i;
363 cSum += add; 364 cSum += add;
364 } 365 }
365 } 366 }
366 } 367 }
367 return cSum; 368 return cSum;
368 369
369} 370}
370#include <stdlib.h> 371#include <stdlib.h>
371#define DEBUGMODE false 372//#define DEBUGMODE false
373#define DEBUGMODE true
372bool SharpFormat::load( Calendar *calendar, Calendar *existngCal ) 374bool SharpFormat::load( Calendar *calendar, Calendar *existngCal )
373{ 375{
374 376
375 377
376 bool debug = DEBUGMODE; 378 bool debug = DEBUGMODE;
377 //debug = true;
378 QString text; 379 QString text;
379 QString codec = "utf8"; 380 QString codec = "utf8";
380 QLabel status ( i18n("Reading events ..."), 0 ); 381 QLabel status ( i18n("Reading events ..."), 0 );
381 382
382 int w = status.sizeHint().width()+20 ; 383 int w = status.sizeHint().width()+20 ;
383 if ( w < 200 ) w = 200; 384 if ( w < 200 ) w = 200;
384 int h = status.sizeHint().height()+20 ; 385 int h = status.sizeHint().height()+20 ;
385 int dw = QApplication::desktop()->width(); 386 int dw = QApplication::desktop()->width();
386 int dh = QApplication::desktop()->height(); 387 int dh = QApplication::desktop()->height();
387 status.setCaption(i18n("Reading DTM Data") ); 388 status.setCaption(i18n("Reading DTM Data") );
388 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 389 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
389 status.show(); 390 status.show();
390 status.raise(); 391 status.raise();
391 qApp->processEvents(); 392 qApp->processEvents();
392 QString fileName; 393 QString fileName;
393 if ( ! debug ) { 394 if ( ! debug ) {
394 fileName = "/tmp/kopitempout"; 395 fileName = "/tmp/kopitempout";
395 QString command ="db2file datebook -r -c "+ codec + " > " + fileName; 396 QString command ="db2file datebook -r -c "+ codec + " > " + fileName;
396 system ( command.latin1() ); 397 system ( command.latin1() );
397 } else { 398 } else {
398 fileName = "/tmp/events.txt"; 399 fileName = "/tmp/events.txt";
399 400
400 } 401 }
401 QFile file( fileName ); 402 QFile file( fileName );
402 if (!file.open( IO_ReadOnly ) ) { 403 if (!file.open( IO_ReadOnly ) ) {
403 return false; 404 return false;
404 405
405 } 406 }
406 QTextStream ts( &file ); 407 QTextStream ts( &file );
407 ts.setCodec( QTextCodec::codecForName("utf8") ); 408 ts.setCodec( QTextCodec::codecForName("utf8") );
408 text = ts.read(); 409 text = ts.read();
409 file.close(); 410 file.close();
410 status.setText( i18n("Processing events ...") ); 411 status.setText( i18n("Processing events ...") );
411 status.raise(); 412 status.raise();
412 qApp->processEvents(); 413 qApp->processEvents();
413 fromString2Cal( calendar, existngCal, text, "Event" ); 414 fromString2Cal( calendar, existngCal, text, "Event" );
414 status.setText( i18n("Reading todos ...") ); 415 status.setText( i18n("Reading todos ...") );
415 qApp->processEvents(); 416 qApp->processEvents();
416 if ( ! debug ) { 417 if ( ! debug ) {
417 fileName = "/tmp/kopitempout"; 418 fileName = "/tmp/kopitempout";
418 QString command = "db2file todo -r -c " + codec+ " > " + fileName; 419 QString command = "db2file todo -r -c " + codec+ " > " + fileName;
419 system ( command.latin1() ); 420 system ( command.latin1() );
420 } else { 421 } else {
421 fileName = "/tmp/todo.txt"; 422 fileName = "/tmp/todo.txt";
422 } 423 }
423 file.setName( fileName ); 424 file.setName( fileName );
424 if (!file.open( IO_ReadOnly ) ) { 425 if (!file.open( IO_ReadOnly ) ) {
425 return false; 426 return false;
426 427
427 } 428 }
428 ts.setDevice( &file ); 429 ts.setDevice( &file );
429 text = ts.read(); 430 text = ts.read();
430 file.close(); 431 file.close();
431 432
432 status.setText( i18n("Processing todos ...") ); 433 status.setText( i18n("Processing todos ...") );
433 status.raise(); 434 status.raise();
434 qApp->processEvents(); 435 qApp->processEvents();
435 fromString2Cal( calendar, existngCal, text, "Todo" ); 436 fromString2Cal( calendar, existngCal, text, "Todo" );
436 return true; 437 return true;
437} 438}
438int SharpFormat::getNumFromRecord( QString answer, Incidence* inc ) 439int SharpFormat::getNumFromRecord( QString answer, Incidence* inc )
439{ 440{
440 int retval = -1; 441 int retval = -1;
441 QStringList templist; 442 QStringList templist;
442 QString tempString; 443 QString tempString;
443 int start = 0; 444 int start = 0;
444 int len = answer.length(); 445 int len = answer.length();
445 int end = answer.find ("\n",start)+1; 446 int end = answer.find ("\n",start)+1;
446 bool ok = true; 447 bool ok = true;
447 start = end; 448 start = end;
448 int ccc = 0; 449 int ccc = 0;
449 while ( start > 0 ) { 450 while ( start > 0 ) {
450 templist.clear(); 451 templist.clear();
451 ok = true; 452 ok = true;
452 int loopCount = 0; 453 int loopCount = 0;
453 while ( ok ) { 454 while ( ok ) {
454 ++loopCount; 455 ++loopCount;
455 if ( loopCount > 25 ) { 456 if ( loopCount > 25 ) {
456 qDebug("KO: Error in while loop"); 457 qDebug("KO: Error in while loop");
457 ok = false; 458 ok = false;
458 start = 0; 459 start = 0;
459 break; 460 break;
460 } 461 }
461 if ( ok ) 462 if ( ok )
462 tempString = getPart( answer, ok, start ); 463 tempString = getPart( answer, ok, start );
463 if ( start >= len || start == 0 ) { 464 if ( start >= len || start == 0 ) {
464 start = 0; 465 start = 0;
465 ok = false; 466 ok = false;
466 } 467 }
467 if ( tempString.right(1) =="\n" ) 468 if ( tempString.right(1) =="\n" )
468 tempString = tempString.left( tempString.length()-1); 469 tempString = tempString.left( tempString.length()-1);
469 470
470 templist.append( tempString ); 471 templist.append( tempString );
471 } 472 }
472 ++ccc; 473 ++ccc;
473 if ( ccc == 2 && loopCount < 25 ) { 474 if ( ccc == 2 && loopCount < 25 ) {
474 start = 0; 475 start = 0;
475 bool ok; 476 bool ok;
476 int newnum = templist[0].toInt( &ok ); 477 int newnum = templist[0].toInt( &ok );
477 if ( ok && newnum > 0) { 478 if ( ok && newnum > 0) {
478 retval = newnum; 479 retval = newnum;
479 inc->setID( "Sharp_DTM",templist[0] ); 480 inc->setID( "Sharp_DTM",templist[0] );
480 inc->setCsum( "Sharp_DTM", QString::number( getCsum( templist ) )); 481 inc->setCsum( "Sharp_DTM", QString::number( getCsum( templist ) ));
481 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 482 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
482 } 483 }
483 } 484 }
484 } 485 }
485 //qDebug("getNumFromRecord returning : %d ", retval); 486 //qDebug("getNumFromRecord returning : %d ", retval);
486 return retval; 487 return retval;
487} 488}
488bool SharpFormat::save( Calendar *calendar) 489bool SharpFormat::save( Calendar *calendar)
489{ 490{
490 491
491 QLabel status ( i18n("Processing/adding events ..."), 0 ); 492 QLabel status ( i18n("Processing/adding events ..."), 0 );
492 int w = status.sizeHint().width()+20 ; 493 int w = status.sizeHint().width()+20 ;
493 if ( w < 200 ) w = 200; 494 if ( w < 200 ) w = 200;
494 int h = status.sizeHint().height()+20 ; 495 int h = status.sizeHint().height()+20 ;
495 int dw = QApplication::desktop()->width(); 496 int dw = QApplication::desktop()->width();
496 int dh = QApplication::desktop()->height(); 497 int dh = QApplication::desktop()->height();
497 status.setCaption(i18n("Writing DTM Data") ); 498 status.setCaption(i18n("Writing DTM Data") );
498 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 499 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
499 status.show(); 500 status.show();
500 status.raise(); 501 status.raise();
501 qApp->processEvents(); 502 qApp->processEvents();
502 bool debug = DEBUGMODE; 503 bool debug = DEBUGMODE;
503 QString codec = "utf8"; 504 QString codec = "utf8";
504 QString answer; 505 QString answer;
505 QString ePrefix = "CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY\n"; 506 QString ePrefix = "CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY\n";