Diffstat (limited to 'korganizer/koeditorrecurrence.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | korganizer/koeditorrecurrence.cpp | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/korganizer/koeditorrecurrence.cpp b/korganizer/koeditorrecurrence.cpp index dea8981..de4e4f7 100644 --- a/korganizer/koeditorrecurrence.cpp +++ b/korganizer/koeditorrecurrence.cpp | |||
@@ -646,463 +646,475 @@ void RecurrenceRangeDialog::setEndDate( const QDate &date ) | |||
646 | 646 | ||
647 | QDate RecurrenceRangeDialog::endDate() | 647 | QDate RecurrenceRangeDialog::endDate() |
648 | { | 648 | { |
649 | return mRecurrenceRangeWidget->endDate(); | 649 | return mRecurrenceRangeWidget->endDate(); |
650 | } | 650 | } |
651 | 651 | ||
652 | void RecurrenceRangeDialog::setDateTimes( const QDateTime &start, | 652 | void RecurrenceRangeDialog::setDateTimes( const QDateTime &start, |
653 | const QDateTime &end ) | 653 | const QDateTime &end ) |
654 | { | 654 | { |
655 | mRecurrenceRangeWidget->setDateTimes( start, end ); | 655 | mRecurrenceRangeWidget->setDateTimes( start, end ); |
656 | } | 656 | } |
657 | 657 | ||
658 | //////////////////////////// RecurrenceChooser //////////////////////// | 658 | //////////////////////////// RecurrenceChooser //////////////////////// |
659 | 659 | ||
660 | RecurrenceChooser::RecurrenceChooser( QWidget *parent, const char *name ) : | 660 | RecurrenceChooser::RecurrenceChooser( QWidget *parent, const char *name ) : |
661 | QWidget( parent, name ) | 661 | QWidget( parent, name ) |
662 | { | 662 | { |
663 | QBoxLayout *topLayout = new QVBoxLayout( this ); | 663 | QBoxLayout *topLayout = new QVBoxLayout( this ); |
664 | 664 | ||
665 | mTypeCombo = new QComboBox( this ); | 665 | mTypeCombo = new QComboBox( this ); |
666 | mTypeCombo->insertItem( i18n("Daily") ); | 666 | mTypeCombo->insertItem( i18n("Daily") ); |
667 | mTypeCombo->insertItem( i18n("Weekly") ); | 667 | mTypeCombo->insertItem( i18n("Weekly") ); |
668 | mTypeCombo->insertItem( i18n("Monthly") ); | 668 | mTypeCombo->insertItem( i18n("Monthly") ); |
669 | mTypeCombo->insertItem( i18n("Yearly") ); | 669 | mTypeCombo->insertItem( i18n("Yearly") ); |
670 | 670 | ||
671 | topLayout->addWidget( mTypeCombo ); | 671 | topLayout->addWidget( mTypeCombo ); |
672 | 672 | ||
673 | connect( mTypeCombo, SIGNAL( activated( int ) ), SLOT( emitChoice() ) ); | 673 | connect( mTypeCombo, SIGNAL( activated( int ) ), SLOT( emitChoice() ) ); |
674 | 674 | ||
675 | } | 675 | } |
676 | 676 | ||
677 | int RecurrenceChooser::type() | 677 | int RecurrenceChooser::type() |
678 | { | 678 | { |
679 | if ( mTypeCombo ) { | 679 | if ( mTypeCombo ) { |
680 | return mTypeCombo->currentItem(); | 680 | return mTypeCombo->currentItem(); |
681 | } else { | 681 | } else { |
682 | if ( mDailyButton->isChecked() ) return Daily; | 682 | if ( mDailyButton->isChecked() ) return Daily; |
683 | else if ( mWeeklyButton->isChecked() ) return Weekly; | 683 | else if ( mWeeklyButton->isChecked() ) return Weekly; |
684 | else if ( mMonthlyButton->isChecked() ) return Monthly; | 684 | else if ( mMonthlyButton->isChecked() ) return Monthly; |
685 | else return Yearly; | 685 | else return Yearly; |
686 | } | 686 | } |
687 | } | 687 | } |
688 | 688 | ||
689 | void RecurrenceChooser::setType( int type ) | 689 | void RecurrenceChooser::setType( int type ) |
690 | { | 690 | { |
691 | if ( mTypeCombo ) { | 691 | if ( mTypeCombo ) { |
692 | mTypeCombo->setCurrentItem( type ); | 692 | mTypeCombo->setCurrentItem( type ); |
693 | } else { | 693 | } else { |
694 | switch ( type ) { | 694 | switch ( type ) { |
695 | case Daily: | 695 | case Daily: |
696 | mDailyButton->setChecked( true ); | 696 | mDailyButton->setChecked( true ); |
697 | break; | 697 | break; |
698 | case Weekly: | 698 | case Weekly: |
699 | mWeeklyButton->setChecked( true ); | 699 | mWeeklyButton->setChecked( true ); |
700 | break; | 700 | break; |
701 | case Monthly: | 701 | case Monthly: |
702 | mMonthlyButton->setChecked( true ); | 702 | mMonthlyButton->setChecked( true ); |
703 | break; | 703 | break; |
704 | case Yearly: | 704 | case Yearly: |
705 | default: | 705 | default: |
706 | mYearlyButton->setChecked( true ); | 706 | mYearlyButton->setChecked( true ); |
707 | break; | 707 | break; |
708 | } | 708 | } |
709 | } | 709 | } |
710 | } | 710 | } |
711 | 711 | ||
712 | void RecurrenceChooser::emitChoice() | 712 | void RecurrenceChooser::emitChoice() |
713 | { | 713 | { |
714 | emit chosen ( type() ); | 714 | emit chosen ( type() ); |
715 | } | 715 | } |
716 | 716 | ||
717 | /////////////////////////////// Main Widget ///////////////////////////// | 717 | /////////////////////////////// Main Widget ///////////////////////////// |
718 | 718 | ||
719 | KOEditorRecurrence::KOEditorRecurrence( QWidget* parent, const char *name ) : | 719 | KOEditorRecurrence::KOEditorRecurrence( QWidget* parent, const char *name ) : |
720 | QWidget( parent, name ) | 720 | QWidget( parent, name ) |
721 | { | 721 | { |
722 | QGridLayout *topLayout = new QGridLayout( this, 2,2 ); | 722 | QGridLayout *topLayout = new QGridLayout( this, 2,2 ); |
723 | topLayout->setSpacing( KDialog::spacingHint() ); | 723 | topLayout->setSpacing( KDialog::spacingHint() ); |
724 | topLayout->setMargin( KDialog::marginHintSmall() ); | 724 | topLayout->setMargin( KDialog::marginHintSmall() ); |
725 | 725 | ||
726 | mEnabledCheck = new QCheckBox( i18n("Enable Recurrence"), this ); | 726 | mEnabledCheck = new QCheckBox( i18n("Enable Recurrence"), this ); |
727 | connect( mEnabledCheck, SIGNAL( toggled( bool ) ), | 727 | connect( mEnabledCheck, SIGNAL( toggled( bool ) ), |
728 | SLOT( setEnabled( bool ) ) ); | 728 | SLOT( setEnabled( bool ) ) ); |
729 | topLayout->addMultiCellWidget( mEnabledCheck, 0, 0, 0, 1 ); | 729 | topLayout->addMultiCellWidget( mEnabledCheck, 0, 0, 0, 1 ); |
730 | 730 | ||
731 | 731 | ||
732 | mTimeGroupBox = new QGroupBox( 1, Horizontal, i18n("Time"), | 732 | mTimeGroupBox = new QGroupBox( 1, Horizontal, i18n("Time"), |
733 | this ); | 733 | this ); |
734 | topLayout->addMultiCellWidget( mTimeGroupBox, 1, 1 , 0 , 1 ); | 734 | topLayout->addMultiCellWidget( mTimeGroupBox, 1, 1 , 0 , 1 ); |
735 | 735 | ||
736 | if ( QApplication::desktop()->width() <= 640 ) { | 736 | if ( QApplication::desktop()->width() <= 640 ) { |
737 | mTimeGroupBox->hide(); | 737 | mTimeGroupBox->hide(); |
738 | } | 738 | } |
739 | 739 | ||
740 | // QFrame *timeFrame = new QFrame( mTimeGroupBox ); | 740 | // QFrame *timeFrame = new QFrame( mTimeGroupBox ); |
741 | // QBoxLayout *layoutTimeFrame = new QHBoxLayout( timeFrame ); | 741 | // QBoxLayout *layoutTimeFrame = new QHBoxLayout( timeFrame ); |
742 | // layoutTimeFrame->setSpacing( KDialog::spacingHint() ); | 742 | // layoutTimeFrame->setSpacing( KDialog::spacingHint() ); |
743 | 743 | ||
744 | mDateTimeLabel = new QLabel( mTimeGroupBox ); | 744 | mDateTimeLabel = new QLabel( mTimeGroupBox ); |
745 | // mDateTimeLabel = new QLabel( timeFrame ); | 745 | // mDateTimeLabel = new QLabel( timeFrame ); |
746 | // layoutTimeFrame->addWidget( mDateTimeLabel ); | 746 | // layoutTimeFrame->addWidget( mDateTimeLabel ); |
747 | //mTimeGroupBox->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum ) ); | 747 | //mTimeGroupBox->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum ) ); |
748 | //mDateTimeLabel->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum) ); | 748 | //mDateTimeLabel->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum) ); |
749 | mRuleBox = new QGroupBox( 1, Horizontal, i18n("Recurrence Rule"), this ); | 749 | mRuleBox = new QGroupBox( 1, Horizontal, i18n("Recurrence Rule"), this ); |
750 | topLayout->addMultiCellWidget( mRuleBox, 2, 2, 0, 1 ); | 750 | topLayout->addMultiCellWidget( mRuleBox, 2, 2, 0, 1 ); |
751 | mRecurrenceChooser = new RecurrenceChooser( mRuleBox ); | 751 | mRecurrenceChooser = new RecurrenceChooser( mRuleBox ); |
752 | connect( mRecurrenceChooser, SIGNAL( chosen( int ) ), | 752 | connect( mRecurrenceChooser, SIGNAL( chosen( int ) ), |
753 | SLOT( showCurrentRule( int ) ) ); | 753 | SLOT( showCurrentRule( int ) ) ); |
754 | 754 | ||
755 | 755 | ||
756 | mRuleStack = new QWidgetStack( mRuleBox ); | 756 | mRuleStack = new QWidgetStack( mRuleBox ); |
757 | 757 | ||
758 | mDaily = new RecurDaily( mRuleStack ); | 758 | mDaily = new RecurDaily( mRuleStack ); |
759 | mRuleStack->addWidget( mDaily, 0 ); | 759 | mRuleStack->addWidget( mDaily, 0 ); |
760 | 760 | ||
761 | mWeekly = new RecurWeekly( mRuleStack ); | 761 | mWeekly = new RecurWeekly( mRuleStack ); |
762 | mRuleStack->addWidget( mWeekly, 0 ); | 762 | mRuleStack->addWidget( mWeekly, 0 ); |
763 | 763 | ||
764 | mMonthly = new RecurMonthly( mRuleStack ); | 764 | mMonthly = new RecurMonthly( mRuleStack ); |
765 | mRuleStack->addWidget( mMonthly, 0 ); | 765 | mRuleStack->addWidget( mMonthly, 0 ); |
766 | 766 | ||
767 | mYearly = new RecurYearly( mRuleStack ); | 767 | mYearly = new RecurYearly( mRuleStack ); |
768 | mRuleStack->addWidget( mYearly, 0 ); | 768 | mRuleStack->addWidget( mYearly, 0 ); |
769 | 769 | ||
770 | showCurrentRule( mRecurrenceChooser->type() ); | 770 | showCurrentRule( mRecurrenceChooser->type() ); |
771 | mRecurrenceRangeWidget = 0; | 771 | mRecurrenceRangeWidget = 0; |
772 | mRecurrenceRangeDialog = new RecurrenceRangeDialog( this ); | 772 | mRecurrenceRangeDialog = new RecurrenceRangeDialog( this ); |
773 | mRecurrenceRange = mRecurrenceRangeDialog; | 773 | mRecurrenceRange = mRecurrenceRangeDialog; |
774 | mRecurrenceRangeButton = new QPushButton( i18n("Recurrence Range..."), | 774 | mRecurrenceRangeButton = new QPushButton( i18n("Recurrence Range..."), |
775 | this ); | 775 | this ); |
776 | 776 | ||
777 | connect( mRecurrenceRangeButton, SIGNAL( clicked() ), | 777 | connect( mRecurrenceRangeButton, SIGNAL( clicked() ), |
778 | SLOT( showRecurrenceRangeDialog() ) ); | 778 | SLOT( showRecurrenceRangeDialog() ) ); |
779 | 779 | ||
780 | mExceptionsWidget = 0; | 780 | mExceptionsWidget = 0; |
781 | mExceptionsDialog = new ExceptionsDialog( this ); | 781 | mExceptionsDialog = new ExceptionsDialog( this ); |
782 | mExceptions = mExceptionsDialog; | 782 | mExceptions = mExceptionsDialog; |
783 | mExceptionsButton = new QPushButton( i18n("Exceptions..."), this ); | 783 | mExceptionsButton = new QPushButton( i18n("Exceptions..."), this ); |
784 | if ( QApplication::desktop()->width() < 320 ) { | 784 | if ( QApplication::desktop()->width() < 320 ) { |
785 | topLayout->addMultiCellWidget( mRecurrenceRangeButton, 3, 3, 0, 1 ); | 785 | topLayout->addMultiCellWidget( mRecurrenceRangeButton, 3, 3, 0, 1 ); |
786 | topLayout->addMultiCellWidget( mExceptionsButton, 4, 4, 0, 1 ); | 786 | topLayout->addMultiCellWidget( mExceptionsButton, 4, 4, 0, 1 ); |
787 | } else { | 787 | } else { |
788 | topLayout->addWidget( mRecurrenceRangeButton, 3, 0 ); | 788 | topLayout->addWidget( mRecurrenceRangeButton, 3, 0 ); |
789 | topLayout->addWidget( mExceptionsButton, 3, 1 ); | 789 | topLayout->addWidget( mExceptionsButton, 3, 1 ); |
790 | } | 790 | } |
791 | connect( mExceptionsButton, SIGNAL( clicked() ), | 791 | connect( mExceptionsButton, SIGNAL( clicked() ), |
792 | SLOT( showExceptionsDialog() ) ); | 792 | SLOT( showExceptionsDialog() ) ); |
793 | } | 793 | } |
794 | 794 | ||
795 | KOEditorRecurrence::~KOEditorRecurrence() | 795 | KOEditorRecurrence::~KOEditorRecurrence() |
796 | { | 796 | { |
797 | } | 797 | } |
798 | 798 | ||
799 | void KOEditorRecurrence::setEnabled( bool enabled ) | 799 | void KOEditorRecurrence::setEnabled( bool enabled ) |
800 | { | 800 | { |
801 | // kdDebug() << "KOEditorRecurrence::setEnabled(): " << (enabled ? "on" : "off") << endl; | 801 | // kdDebug() << "KOEditorRecurrence::setEnabled(): " << (enabled ? "on" : "off") << endl; |
802 | 802 | ||
803 | mTimeGroupBox->setEnabled( enabled ); | 803 | mTimeGroupBox->setEnabled( enabled ); |
804 | if ( mRecurrenceRangeWidget ) mRecurrenceRangeWidget->setEnabled( enabled ); | 804 | if ( mRecurrenceRangeWidget ) mRecurrenceRangeWidget->setEnabled( enabled ); |
805 | if ( mRecurrenceRangeButton ) mRecurrenceRangeButton->setEnabled( enabled ); | 805 | if ( mRecurrenceRangeButton ) mRecurrenceRangeButton->setEnabled( enabled ); |
806 | if ( mExceptionsWidget ) mExceptionsWidget->setEnabled( enabled ); | 806 | if ( mExceptionsWidget ) mExceptionsWidget->setEnabled( enabled ); |
807 | if ( mExceptionsButton ) mExceptionsButton->setEnabled( enabled ); | 807 | if ( mExceptionsButton ) mExceptionsButton->setEnabled( enabled ); |
808 | mRuleBox->setEnabled( enabled ); | 808 | mRuleBox->setEnabled( enabled ); |
809 | } | 809 | } |
810 | 810 | ||
811 | void KOEditorRecurrence::showCurrentRule( int current ) | 811 | void KOEditorRecurrence::showCurrentRule( int current ) |
812 | { | 812 | { |
813 | switch ( current ) { | 813 | switch ( current ) { |
814 | case Daily: | 814 | case Daily: |
815 | mRuleStack->raiseWidget( mDaily ); | 815 | mRuleStack->raiseWidget( mDaily ); |
816 | break; | 816 | break; |
817 | case Weekly: | 817 | case Weekly: |
818 | mRuleStack->raiseWidget( mWeekly ); | 818 | mRuleStack->raiseWidget( mWeekly ); |
819 | break; | 819 | break; |
820 | case Monthly: | 820 | case Monthly: |
821 | mRuleStack->raiseWidget( mMonthly ); | 821 | mRuleStack->raiseWidget( mMonthly ); |
822 | break; | 822 | break; |
823 | default: | 823 | default: |
824 | case Yearly: | 824 | case Yearly: |
825 | mRuleStack->raiseWidget( mYearly ); | 825 | mRuleStack->raiseWidget( mYearly ); |
826 | break; | 826 | break; |
827 | } | 827 | } |
828 | } | 828 | } |
829 | 829 | ||
830 | void KOEditorRecurrence::setDateTimes( QDateTime start, QDateTime end ) | 830 | void KOEditorRecurrence::setDateTimes( QDateTime start, QDateTime end ) |
831 | { | 831 | { |
832 | // kdDebug() << "KOEditorRecurrence::setDateTimes" << endl; | 832 | // kdDebug() << "KOEditorRecurrence::setDateTimes" << endl; |
833 | 833 | ||
834 | mRecurrenceRange->setDateTimes( start, end ); | 834 | mRecurrenceRange->setDateTimes( start, end ); |
835 | mExceptions->setDefaults( end ); | 835 | mExceptions->setDefaults( end ); |
836 | 836 | ||
837 | } | 837 | } |
838 | void KOEditorRecurrence::setDefaultsDates( QDateTime from, QDateTime to ) | ||
839 | { | ||
840 | setDateTimes( from, to ); | ||
841 | QBitArray days( 7 ); | ||
842 | days.fill( 0 ); | ||
843 | days.setBit( from.date().dayOfWeek()- 1); | ||
844 | mWeekly->setDays( days ); | ||
845 | bool byPos = mMonthly->byPos(); | ||
846 | if ( byPos ) | ||
847 | mMonthly->setByDay( from.date().day()-1 ); | ||
848 | mMonthly->setByPos((from.date().day()/7), from.date().dayOfWeek()-1 ); | ||
849 | if ( ! byPos) | ||
850 | mMonthly->setByDay( from.date().day()-1 ); | ||
838 | 851 | ||
839 | void KOEditorRecurrence::setDefaults( QDateTime from, QDateTime to, bool ) | 852 | bool byDay = mYearly->byDay(); |
853 | if ( ! byDay ) | ||
854 | mYearly->setByDay( from.date().dayOfYear() ); | ||
855 | mYearly->setByMonth( from.date().month(), from.date().day() ); | ||
856 | if ( byDay ) | ||
857 | mYearly->setByDay( from.date().dayOfYear() ); | ||
858 | } | ||
859 | void KOEditorRecurrence::setDefaults( QDateTime from, QDateTime to ) | ||
840 | { | 860 | { |
841 | 861 | ||
842 | // qDebug("KOEditorRecurrence::setDefaults %s %s ",from.toString().latin1(),to.toString().latin1() ); | 862 | // qDebug("KOEditorRecurrence::setDefaults %s %s ",from.toString().latin1(),to.toString().latin1() ); |
843 | setDateTimes( from, to ); | 863 | //setDateTimes( from, to ); |
844 | 864 | ||
845 | bool enabled = false; | 865 | bool enabled = false; |
846 | mEnabledCheck->setChecked( enabled ); | 866 | mEnabledCheck->setChecked( enabled ); |
847 | setEnabled( enabled ); | 867 | setEnabled( enabled ); |
848 | 868 | ||
849 | mExceptions->setDefaults( to ); | 869 | mExceptions->setDefaults( to ); |
850 | mRecurrenceRange->setDefaults( to ); | 870 | mRecurrenceRange->setDefaults( to ); |
851 | 871 | ||
852 | mRecurrenceChooser->setType( RecurrenceChooser::Weekly ); | 872 | mRecurrenceChooser->setType( RecurrenceChooser::Weekly ); |
853 | showCurrentRule( mRecurrenceChooser->type() ); | 873 | showCurrentRule( mRecurrenceChooser->type() ); |
854 | 874 | ||
855 | mDaily->setFrequency( 1 ); | 875 | mDaily->setFrequency( 1 ); |
856 | |||
857 | mWeekly->setFrequency( 1 ); | 876 | mWeekly->setFrequency( 1 ); |
858 | QBitArray days( 7 ); | ||
859 | days.fill( 0 ); | ||
860 | days.setBit( from.date().dayOfWeek()- 1); | ||
861 | mWeekly->setDays( days ); | ||
862 | mMonthly->setFrequency( 1 ); | 877 | mMonthly->setFrequency( 1 ); |
863 | mMonthly->setByPos((from.date().day()/7), from.date().dayOfWeek()-1 ); | ||
864 | mMonthly->setByDay( from.date().day()-1 ); | ||
865 | mYearly->setFrequency( 1 ); | 878 | mYearly->setFrequency( 1 ); |
866 | mYearly->setByDay( from.date().dayOfYear() ); | 879 | setDefaultsDates( from, to ); |
867 | mYearly->setByMonth( from.date().month(), from.date().day() ); | ||
868 | } | 880 | } |
869 | 881 | ||
870 | void KOEditorRecurrence::readEvent(Incidence *event) | 882 | void KOEditorRecurrence::readEvent(Incidence *event) |
871 | { | 883 | { |
872 | 884 | ||
873 | QDateTime dtEnd; | 885 | QDateTime dtEnd; |
874 | if ( event->typeID() == eventID ) | 886 | if ( event->typeID() == eventID ) |
875 | dtEnd = ((Event*)event)->dtEnd(); | 887 | dtEnd = ((Event*)event)->dtEnd(); |
876 | else | 888 | else |
877 | dtEnd = ((Todo*)event)->dtDue(); | 889 | dtEnd = ((Todo*)event)->dtDue(); |
878 | 890 | ||
879 | setDefaults( event->dtStart(), dtEnd, true ); | 891 | setDefaults( event->dtStart(), dtEnd ); |
880 | QBitArray rDays( 7 ); | 892 | QBitArray rDays( 7 ); |
881 | QPtrList<Recurrence::rMonthPos> rmp; | 893 | QPtrList<Recurrence::rMonthPos> rmp; |
882 | QPtrList<int> rmd; | 894 | QPtrList<int> rmd; |
883 | int day = 0; | 895 | int day = 0; |
884 | int count = 0; | 896 | int count = 0; |
885 | int month = 0; | 897 | int month = 0; |
886 | setDateTimes( event->dtStart(), dtEnd ); | 898 | setDateTimes( event->dtStart(), dtEnd ); |
887 | 899 | ||
888 | Recurrence *r = event->recurrence(); | 900 | Recurrence *r = event->recurrence(); |
889 | int f = r->frequency(); | 901 | int f = r->frequency(); |
890 | 902 | ||
891 | int recurs = r->doesRecur(); | 903 | int recurs = r->doesRecur(); |
892 | 904 | ||
893 | mEnabledCheck->setChecked( recurs ); | 905 | mEnabledCheck->setChecked( recurs ); |
894 | setEnabled( recurs ); | 906 | setEnabled( recurs ); |
895 | 907 | ||
896 | int recurrenceType = RecurrenceChooser::Weekly; | 908 | int recurrenceType = RecurrenceChooser::Weekly; |
897 | 909 | ||
898 | switch ( recurs ) { | 910 | switch ( recurs ) { |
899 | case Recurrence::rNone: | 911 | case Recurrence::rNone: |
900 | setDefaults( event->dtStart(), dtEnd, true ); | 912 | setDefaults( event->dtStart(), dtEnd ); |
901 | break; | 913 | break; |
902 | case Recurrence::rDaily: | 914 | case Recurrence::rDaily: |
903 | recurrenceType = RecurrenceChooser::Daily; | 915 | recurrenceType = RecurrenceChooser::Daily; |
904 | mDaily->setFrequency( f ); | 916 | mDaily->setFrequency( f ); |
905 | break; | 917 | break; |
906 | case Recurrence::rWeekly: | 918 | case Recurrence::rWeekly: |
907 | recurrenceType = RecurrenceChooser::Weekly; | 919 | recurrenceType = RecurrenceChooser::Weekly; |
908 | mWeekly->setFrequency( f ); | 920 | mWeekly->setFrequency( f ); |
909 | mWeekly->setDays( r->days() ); | 921 | mWeekly->setDays( r->days() ); |
910 | break; | 922 | break; |
911 | case Recurrence::rMonthlyPos: | 923 | case Recurrence::rMonthlyPos: |
912 | // we only handle one possibility in the list right now, | 924 | // we only handle one possibility in the list right now, |
913 | // so I have hardcoded calls with first(). If we make the GUI | 925 | // so I have hardcoded calls with first(). If we make the GUI |
914 | // more extended, this can be changed. | 926 | // more extended, this can be changed. |
915 | recurrenceType = RecurrenceChooser::Monthly; | 927 | recurrenceType = RecurrenceChooser::Monthly; |
916 | 928 | ||
917 | rmp = r->monthPositions(); | 929 | rmp = r->monthPositions(); |
918 | if ( rmp.first()->negative ) | 930 | if ( rmp.first()->negative ) |
919 | count = 5 - rmp.first()->rPos - 1; | 931 | count = 5 - rmp.first()->rPos - 1; |
920 | else | 932 | else |
921 | count = rmp.first()->rPos - 1; | 933 | count = rmp.first()->rPos - 1; |
922 | day = 0; | 934 | day = 0; |
923 | while ( !rmp.first()->rDays.testBit( day ) ) ++day; | 935 | while ( !rmp.first()->rDays.testBit( day ) ) ++day; |
924 | mMonthly->setByPos( count, day ); | 936 | mMonthly->setByPos( count, day ); |
925 | 937 | ||
926 | mMonthly->setFrequency( f ); | 938 | mMonthly->setFrequency( f ); |
927 | 939 | ||
928 | break; | 940 | break; |
929 | case Recurrence::rMonthlyDay: | 941 | case Recurrence::rMonthlyDay: |
930 | recurrenceType = RecurrenceChooser::Monthly; | 942 | recurrenceType = RecurrenceChooser::Monthly; |
931 | 943 | ||
932 | rmd = r->monthDays(); | 944 | rmd = r->monthDays(); |
933 | day = *rmd.first() - 1; | 945 | day = *rmd.first() - 1; |
934 | mMonthly->setByDay( day ); | 946 | mMonthly->setByDay( day ); |
935 | 947 | ||
936 | mMonthly->setFrequency( f ); | 948 | mMonthly->setFrequency( f ); |
937 | 949 | ||
938 | break; | 950 | break; |
939 | case Recurrence::rYearlyMonth: | 951 | case Recurrence::rYearlyMonth: |
940 | { | 952 | { |
941 | recurrenceType = RecurrenceChooser::Yearly; | 953 | recurrenceType = RecurrenceChooser::Yearly; |
942 | //qDebug("Recurrence::rYearlyMonth: "); | 954 | //qDebug("Recurrence::rYearlyMonth: "); |
943 | day = event->dtStart().date().day(); | 955 | day = event->dtStart().date().day(); |
944 | rmd = r->yearNums(); | 956 | rmd = r->yearNums(); |
945 | if ( rmd.count() > 0 ) | 957 | if ( rmd.count() > 0 ) |
946 | month = *rmd.first(); | 958 | month = *rmd.first(); |
947 | else | 959 | else |
948 | month = event->dtStart().date().month() ; | 960 | month = event->dtStart().date().month() ; |
949 | mYearly->setByMonth( month, day ); | 961 | mYearly->setByMonth( month, day ); |
950 | #if 0 | 962 | #if 0 |
951 | //qDebug("2day = %d ",day ); | 963 | //qDebug("2day = %d ",day ); |
952 | QPtrList<Recurrence::rMonthPos> monthlist = r->yearMonthPositions(); | 964 | QPtrList<Recurrence::rMonthPos> monthlist = r->yearMonthPositions(); |
953 | int month; | 965 | int month; |
954 | if ( !monthlist.isEmpty() ) { | 966 | if ( !monthlist.isEmpty() ) { |
955 | month = monthlist.first()->rPos ; | 967 | month = monthlist.first()->rPos ; |
956 | } else { | 968 | } else { |
957 | month = event->dtStart().date().month() ; | 969 | month = event->dtStart().date().month() ; |
958 | } | 970 | } |
959 | mYearly->setByMonth( day, month ); | 971 | mYearly->setByMonth( day, month ); |
960 | #endif | 972 | #endif |
961 | mYearly->setFrequency( f ); | 973 | mYearly->setFrequency( f ); |
962 | } | 974 | } |
963 | 975 | ||
964 | break; | 976 | break; |
965 | case Recurrence::rYearlyDay: | 977 | case Recurrence::rYearlyDay: |
966 | //qDebug("Recurrence::rYearlyDay: "); | 978 | //qDebug("Recurrence::rYearlyDay: "); |
967 | recurrenceType = RecurrenceChooser::Yearly; | 979 | recurrenceType = RecurrenceChooser::Yearly; |
968 | mYearly->setByDay( event->dtStart().date().dayOfYear() ); | 980 | mYearly->setByDay( event->dtStart().date().dayOfYear() ); |
969 | mYearly->setFrequency( f ); | 981 | mYearly->setFrequency( f ); |
970 | break; | 982 | break; |
971 | default: | 983 | default: |
972 | setDefaults( event->dtStart(), dtEnd, true ); | 984 | setDefaults( event->dtStart(), dtEnd ); |
973 | break; | 985 | break; |
974 | } | 986 | } |
975 | 987 | ||
976 | mRecurrenceChooser->setType( recurrenceType ); | 988 | mRecurrenceChooser->setType( recurrenceType ); |
977 | showCurrentRule( recurrenceType ); | 989 | showCurrentRule( recurrenceType ); |
978 | 990 | ||
979 | mRecurrenceRange->setDateTimes( event->dtStart() ); | 991 | mRecurrenceRange->setDateTimes( event->dtStart() ); |
980 | 992 | ||
981 | if ( r->doesRecur() ) { | 993 | if ( r->doesRecur() ) { |
982 | mRecurrenceRange->setDuration( r->duration() ); | 994 | mRecurrenceRange->setDuration( r->duration() ); |
983 | if ( r->duration() == 0 ) | 995 | if ( r->duration() == 0 ) |
984 | { | 996 | { |
985 | if ( r->endDate() < event->dtStart().date() ) | 997 | if ( r->endDate() < event->dtStart().date() ) |
986 | mRecurrenceRange->setEndDate( event->dtStart().date() ); | 998 | mRecurrenceRange->setEndDate( event->dtStart().date() ); |
987 | else | 999 | else |
988 | mRecurrenceRange->setEndDate( r->endDate() ); | 1000 | mRecurrenceRange->setEndDate( r->endDate() ); |
989 | } else | 1001 | } else |
990 | mRecurrenceRange->setEndDate( event->dtStart().date() ); | 1002 | mRecurrenceRange->setEndDate( event->dtStart().date() ); |
991 | } | 1003 | } |
992 | 1004 | ||
993 | mExceptions->setDates( event->exDates() ); | 1005 | mExceptions->setDates( event->exDates() ); |
994 | } | 1006 | } |
995 | 1007 | ||
996 | void KOEditorRecurrence::writeEvent( Incidence *event ) | 1008 | void KOEditorRecurrence::writeEvent( Incidence *event ) |
997 | { | 1009 | { |
998 | Recurrence *r = event->recurrence(); | 1010 | Recurrence *r = event->recurrence(); |
999 | 1011 | ||
1000 | // clear out any old settings; | 1012 | // clear out any old settings; |
1001 | r->unsetRecurs(); | 1013 | r->unsetRecurs(); |
1002 | 1014 | ||
1003 | if ( mEnabledCheck->isChecked() ) { | 1015 | if ( mEnabledCheck->isChecked() ) { |
1004 | int duration = mRecurrenceRange->duration(); | 1016 | int duration = mRecurrenceRange->duration(); |
1005 | QDate endDate; | 1017 | QDate endDate; |
1006 | if ( duration == 0 ) endDate = mRecurrenceRange->endDate(); | 1018 | if ( duration == 0 ) endDate = mRecurrenceRange->endDate(); |
1007 | 1019 | ||
1008 | int recurrenceType = mRecurrenceChooser->type(); | 1020 | int recurrenceType = mRecurrenceChooser->type(); |
1009 | 1021 | ||
1010 | if ( recurrenceType == RecurrenceChooser::Daily ) { | 1022 | if ( recurrenceType == RecurrenceChooser::Daily ) { |
1011 | int freq = mDaily->frequency(); | 1023 | int freq = mDaily->frequency(); |
1012 | if ( duration != 0 ) r->setDaily( freq, duration ); | 1024 | if ( duration != 0 ) r->setDaily( freq, duration ); |
1013 | else r->setDaily( freq, endDate ); | 1025 | else r->setDaily( freq, endDate ); |
1014 | } else if ( recurrenceType == RecurrenceChooser::Weekly ) { | 1026 | } else if ( recurrenceType == RecurrenceChooser::Weekly ) { |
1015 | int freq = mWeekly->frequency(); | 1027 | int freq = mWeekly->frequency(); |
1016 | QBitArray days = mWeekly->days(); | 1028 | QBitArray days = mWeekly->days(); |
1017 | int j; | 1029 | int j; |
1018 | bool found = false; | 1030 | bool found = false; |
1019 | for (j = 0; j < 7 ; ++j ) { | 1031 | for (j = 0; j < 7 ; ++j ) { |
1020 | found |=days.at(j); | 1032 | found |=days.at(j); |
1021 | } | 1033 | } |
1022 | if ( !found ) { | 1034 | if ( !found ) { |
1023 | days.setBit( event->dtStart().date().dayOfWeek()-1); | 1035 | days.setBit( event->dtStart().date().dayOfWeek()-1); |
1024 | //qDebug("bit set %d ", event->dtStart().date().dayOfWeek()-1); | 1036 | //qDebug("bit set %d ", event->dtStart().date().dayOfWeek()-1); |
1025 | } | 1037 | } |
1026 | if ( duration != 0 ) r->setWeekly( freq, days, duration ); | 1038 | if ( duration != 0 ) r->setWeekly( freq, days, duration ); |
1027 | else r->setWeekly( freq, days, endDate ); | 1039 | else r->setWeekly( freq, days, endDate ); |
1028 | } else if ( recurrenceType == RecurrenceChooser::Monthly ) { | 1040 | } else if ( recurrenceType == RecurrenceChooser::Monthly ) { |
1029 | int freq = mMonthly->frequency(); | 1041 | int freq = mMonthly->frequency(); |
1030 | if ( mMonthly->byPos() ) { | 1042 | if ( mMonthly->byPos() ) { |
1031 | int pos = mMonthly->count(); | 1043 | int pos = mMonthly->count(); |
1032 | 1044 | ||
1033 | QBitArray days( 7 ); | 1045 | QBitArray days( 7 ); |
1034 | days.fill( false ); | 1046 | days.fill( false ); |
1035 | 1047 | ||
1036 | days.setBit( mMonthly->weekday() ); | 1048 | days.setBit( mMonthly->weekday() ); |
1037 | if ( duration != 0 ) | 1049 | if ( duration != 0 ) |
1038 | r->setMonthly( Recurrence::rMonthlyPos, freq, duration ); | 1050 | r->setMonthly( Recurrence::rMonthlyPos, freq, duration ); |
1039 | else | 1051 | else |
1040 | r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); | 1052 | r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); |
1041 | r->addMonthlyPos( pos, days ); | 1053 | r->addMonthlyPos( pos, days ); |
1042 | } else { | 1054 | } else { |
1043 | // it's by day | 1055 | // it's by day |
1044 | int day = mMonthly->day(); | 1056 | int day = mMonthly->day(); |
1045 | 1057 | ||
1046 | if ( duration != 0 ) { | 1058 | if ( duration != 0 ) { |
1047 | r->setMonthly( Recurrence::rMonthlyDay, freq, duration ); | 1059 | r->setMonthly( Recurrence::rMonthlyDay, freq, duration ); |
1048 | } else { | 1060 | } else { |
1049 | r->setMonthly( Recurrence::rMonthlyDay, freq, endDate ); | 1061 | r->setMonthly( Recurrence::rMonthlyDay, freq, endDate ); |
1050 | } | 1062 | } |
1051 | r->addMonthlyDay( day ); | 1063 | r->addMonthlyDay( day ); |
1052 | } | 1064 | } |
1053 | } else if ( recurrenceType == RecurrenceChooser::Yearly ) { | 1065 | } else if ( recurrenceType == RecurrenceChooser::Yearly ) { |
1054 | //qDebug("RecurrenceChooser::Yearly "); | 1066 | //qDebug("RecurrenceChooser::Yearly "); |
1055 | int freq = mYearly->frequency(); | 1067 | int freq = mYearly->frequency(); |
1056 | if ( mYearly->byDay() ) { | 1068 | if ( mYearly->byDay() ) { |
1057 | if ( duration != 0 ) { | 1069 | if ( duration != 0 ) { |
1058 | r->setYearly( Recurrence::rYearlyDay, freq, duration ); | 1070 | r->setYearly( Recurrence::rYearlyDay, freq, duration ); |
1059 | } else { | 1071 | } else { |
1060 | r->setYearly( Recurrence::rYearlyDay, freq, endDate ); | 1072 | r->setYearly( Recurrence::rYearlyDay, freq, endDate ); |
1061 | } | 1073 | } |
1062 | r->addYearlyNum( event->dtStart().date().dayOfYear() ); | 1074 | r->addYearlyNum( event->dtStart().date().dayOfYear() ); |
1063 | } else { | 1075 | } else { |
1064 | if ( duration != 0 ) { | 1076 | if ( duration != 0 ) { |
1065 | r->setYearly( Recurrence::rYearlyMonth, freq, duration ); | 1077 | r->setYearly( Recurrence::rYearlyMonth, freq, duration ); |
1066 | } else { | 1078 | } else { |
1067 | r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); | 1079 | r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); |
1068 | } | 1080 | } |
1069 | r->addYearlyNum( mYearly->month() ); | 1081 | r->addYearlyNum( mYearly->month() ); |
1070 | } | 1082 | } |
1071 | 1083 | ||
1072 | } | 1084 | } |
1073 | 1085 | ||
1074 | event->setExDates( mExceptions->dates() ); | 1086 | event->setExDates( mExceptions->dates() ); |
1075 | } | 1087 | } |
1076 | } | 1088 | } |
1077 | 1089 | ||
1078 | void KOEditorRecurrence::setDateTimeStr( const QString &str ) | 1090 | void KOEditorRecurrence::setDateTimeStr( const QString &str ) |
1079 | { | 1091 | { |
1080 | mDateTimeLabel->setText( str ); | 1092 | mDateTimeLabel->setText( str ); |
1081 | } | 1093 | } |
1082 | 1094 | ||
1083 | bool KOEditorRecurrence::validateInput() | 1095 | bool KOEditorRecurrence::validateInput() |
1084 | { | 1096 | { |
1085 | // Check input here | 1097 | // Check input here |
1086 | 1098 | ||
1087 | return true; | 1099 | return true; |
1088 | } | 1100 | } |
1089 | 1101 | ||
1090 | void KOEditorRecurrence::showExceptionsDialog() | 1102 | void KOEditorRecurrence::showExceptionsDialog() |
1091 | { | 1103 | { |
1092 | DateList dates = mExceptions->dates(); | 1104 | DateList dates = mExceptions->dates(); |
1093 | int result = mExceptionsDialog->exec(); | 1105 | int result = mExceptionsDialog->exec(); |
1094 | if ( result == QDialog::Rejected ) mExceptions->setDates( dates ); | 1106 | if ( result == QDialog::Rejected ) mExceptions->setDates( dates ); |
1095 | } | 1107 | } |
1096 | 1108 | ||
1097 | void KOEditorRecurrence::showRecurrenceRangeDialog() | 1109 | void KOEditorRecurrence::showRecurrenceRangeDialog() |
1098 | { | 1110 | { |
1099 | int duration = mRecurrenceRange->duration(); | 1111 | int duration = mRecurrenceRange->duration(); |
1100 | QDate endDate = mRecurrenceRange->endDate(); | 1112 | QDate endDate = mRecurrenceRange->endDate(); |
1101 | 1113 | ||
1102 | int result = mRecurrenceRangeDialog->exec(); | 1114 | int result = mRecurrenceRangeDialog->exec(); |
1103 | if ( result == QDialog::Rejected ) { | 1115 | if ( result == QDialog::Rejected ) { |
1104 | mRecurrenceRange->setDuration( duration ); | 1116 | mRecurrenceRange->setDuration( duration ); |
1105 | mRecurrenceRange->setEndDate( endDate ); | 1117 | mRecurrenceRange->setEndDate( endDate ); |
1106 | } | 1118 | } |
1107 | 1119 | ||
1108 | } | 1120 | } |