kalarm

recurrenceedit.h

00001 /*
00002  *  recurrenceedit.h  -  widget to edit the event's recurrence definition
00003  *  Program:  kalarm
00004  *  Copyright © 2002-2005,2008 by David Jarvie <djarvie@kde.org>
00005  *
00006  *  Based originally on KOrganizer module koeditorrecurrence.h,
00007  *  Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>
00008  *
00009  *  This program is free software; you can redistribute it and/or modify
00010  *  it under the terms of the GNU General Public License as published by
00011  *  the Free Software Foundation; either version 2 of the License, or
00012  *  (at your option) any later version.
00013  *
00014  *  This program is distributed in the hope that it will be useful,
00015  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00017  *  GNU General Public License for more details.
00018  *
00019  *  You should have received a copy of the GNU General Public License along
00020  *  with this program; if not, write to the Free Software Foundation, Inc.,
00021  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00022  */
00023 
00024 #ifndef RECURRENCEEDIT_H
00025 #define RECURRENCEEDIT_H
00026 
00027 #include <tqframe.h>
00028 #include <tqdatetime.h>
00029 #include <tqvaluelist.h>
00030 
00031 #include "datetime.h"
00032 class TQWidgetStack;
00033 class TQGroupBox;
00034 class TQLabel;
00035 class TQListBox;
00036 class TQButton;
00037 class TQPushButton;
00038 class TQBoxLayout;
00039 class SpinBox;
00040 class CheckBox;
00041 class RadioButton;
00042 class DateEdit;
00043 class TimeEdit;
00044 class ButtonGroup;
00045 class RepetitionButton;
00046 class KAEvent;
00047 class Rule;
00048 class NoRule;
00049 class SubDailyRule;
00050 class DailyRule;
00051 class WeeklyRule;
00052 class MonthlyRule;
00053 class YearlyRule;
00054 
00055 
00056 class RecurrenceEdit : public TQFrame
00057 {
00058         Q_OBJECT
00059   TQ_OBJECT
00060     public:
00061         // Don't alter the order of these recurrence types
00062         enum RepeatType { INVALID_RECUR = -1, NO_RECUR, AT_LOGIN, SUBDAILY, DAILY, WEEKLY, MONTHLY, ANNUAL };
00063 
00064         RecurrenceEdit(bool readOnly, TQWidget* parent, const char* name = 0);
00065         virtual ~RecurrenceEdit()  { }
00066 
00068         void          setDefaults(const TQDateTime& from);
00070         void          set(const KAEvent&, bool keepDuration);
00072         void          updateEvent(KAEvent&, bool adjustStart);
00073         TQWidget*      checkData(const TQDateTime& startDateTime, TQString& errorMessage) const;
00074         RepeatType    repeatType() const                    { return mRuleButtonType; }
00075         bool          isTimedRepeatType() const             { return mRuleButtonType >= SUBDAILY; }
00076         int           subRepeatCount(int* subRepeatInterval = 0) const;
00077         void          setSubRepetition(int reminderMinutes, bool dateOnly);
00078         void          setStartDate(const TQDate&, const TQDate& today);
00079         void          setDefaultEndDate(const TQDate&);
00080         void          setEndDateTime(const DateTime&);
00081         DateTime      endDateTime() const;
00082         bool          stateChanged() const;
00083         void          activateSubRepetition();
00084 
00085         static TQString i18n_Norecur();           // text of 'No recurrence' selection, lower case
00086         static TQString i18n_NoRecur();           // text of 'No Recurrence' selection, initial capitals
00087         static TQString i18n_AtLogin();           // text of 'At Login' selection
00088         static TQString i18n_l_Atlogin();         // text of 'At &login' selection, with 'L' shortcut
00089         static TQString i18n_HourlyMinutely();    // text of 'Hourly/Minutely'
00090         static TQString i18n_u_HourlyMinutely();  // text of 'Ho&urly/Minutely' selection, with 'U' shortcut
00091         static TQString i18n_Daily();             // text of 'Daily' selection
00092         static TQString i18n_d_Daily();           // text of '&Daily' selection, with 'D' shortcut
00093         static TQString i18n_Weekly();            // text of 'Weekly' selection
00094         static TQString i18n_w_Weekly();          // text of '&Weekly' selection, with 'W' shortcut
00095         static TQString i18n_Monthly();           // text of 'Monthly' selection
00096         static TQString i18n_m_Monthly();         // text of '&Monthly' selection, with 'M' shortcut
00097         static TQString i18n_Yearly();            // text of 'Yearly' selection
00098         static TQString i18n_y_Yearly();          // text of '&Yearly' selection, with 'Y' shortcut
00099 
00100     public slots:
00101         void          setDateTime(const TQDateTime& start)   { mCurrStartDateTime = start; }
00102 
00103     signals:
00104         void          shown();
00105         void          typeChanged(int recurType);   // returns a RepeatType value
00106         void          frequencyChanged();
00107         void          repeatNeedsInitialisation();
00108 
00109     protected:
00110         virtual void  showEvent(TQShowEvent*);
00111 
00112     private slots:
00113         void          periodClicked(int);
00114         void          rangeTypeClicked();
00115         void          repeatCountChanged(int value);
00116         void          slotAnyTimeToggled(bool);
00117         void          addException();
00118         void          changeException();
00119         void          deleteException();
00120         void          enableExceptionButtons();
00121 
00122     private:
00123         void          setRuleDefaults(const TQDate& start);
00124         void          saveState();
00125 
00126         // Main rule box and choices
00127         TQWidgetStack*     mRuleStack;
00128         Rule*             mRule;         // current rule widget, or 0 if NoRule
00129         NoRule*           mNoRule;
00130         SubDailyRule*     mSubDailyRule;
00131         DailyRule*        mDailyRule;
00132         WeeklyRule*       mWeeklyRule;
00133         MonthlyRule*      mMonthlyRule;
00134         YearlyRule*       mYearlyRule;
00135 
00136         ButtonGroup*      mRuleButtonGroup;
00137         RadioButton*      mNoneButton;
00138         RadioButton*      mAtLoginButton;
00139         RadioButton*      mSubDailyButton;
00140         RadioButton*      mDailyButton;
00141         RadioButton*      mWeeklyButton;
00142         RadioButton*      mMonthlyButton;
00143         RadioButton*      mYearlyButton;
00144         int               mNoneButtonId;
00145         int               mAtLoginButtonId;
00146         int               mSubDailyButtonId;
00147         int               mDailyButtonId;
00148         int               mWeeklyButtonId;
00149         int               mMonthlyButtonId;
00150         int               mYearlyButtonId;
00151         RepeatType        mRuleButtonType;
00152         bool              mDailyShown;       // daily rule has been displayed at some time or other
00153         bool              mWeeklyShown;      // weekly rule has been displayed at some time or other
00154         bool              mMonthlyShown;     // monthly rule has been displayed at some time or other
00155         bool              mYearlyShown;      // yearly rule has been displayed at some time or other
00156 
00157         // Range
00158         ButtonGroup*      mRangeButtonGroup;
00159         RadioButton*      mNoEndDateButton;
00160         RadioButton*      mRepeatCountButton;
00161         SpinBox*          mRepeatCountEntry;
00162         TQLabel*           mRepeatCountLabel;
00163         RadioButton*      mEndDateButton;
00164         DateEdit*         mEndDateEdit;
00165         TimeEdit*         mEndTimeEdit;
00166         CheckBox*         mEndAnyTimeCheckBox;
00167 
00168         // Exceptions
00169         TQGroupBox*        mExceptionGroup;
00170         TQListBox*         mExceptionDateList;
00171         DateEdit*         mExceptionDateEdit;
00172         TQPushButton*      mChangeExceptionButton;
00173         TQPushButton*      mDeleteExceptionButton;
00174         TQValueList<TQDate> mExceptionDates;
00175 
00176         // Current start date and time
00177         TQDateTime         mCurrStartDateTime;
00178         RepetitionButton* mSubRepetition;
00179         bool              mNoEmitTypeChanged;        // suppress typeChanged() signal
00180         bool              mReadOnly;
00181 
00182         // Initial state of non-rule controls
00183         TQButton*          mSavedRuleButton;          // which rule button was selected
00184         TQButton*          mSavedRangeButton;         // which range button was selected
00185         int               mSavedRecurCount;          // recurrence repeat count
00186         DateTime          mSavedEndDateTime;         // end date/time
00187         TQValueList<TQDate> mSavedExceptionDates;      // exception dates
00188         int               mSavedRepeatInterval;      // sub-repetition interval (via mSubRepetition button)
00189         int               mSavedRepeatCount;         // sub-repetition count (via mSubRepetition button)
00190 };
00191 
00192 #endif // RECURRENCEEDIT_H