korganizer

koeditorrecurrence.h

00001 /*
00002     This file is part of KOrganizer.
00003     Copyright (c) 2000-2003 Cornelius Schumacher <schumacher@kde.org>
00004     Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019 
00020     As a special exception, permission is given to link this program
00021     with any edition of TQt, and distribute the resulting executable,
00022     without including the source code for TQt in the source distribution.
00023 */
00024 #ifndef _KOEDITORRECURRENCE_H
00025 #define _KOEDITORRECURRENCE_H
00026 
00027 #include <tqdatetime.h>
00028 #include <tqwidget.h>
00029 #include <tqbitarray.h>
00030 
00031 #include <kdialogbase.h>
00032 
00033 #include <libkcal/incidencebase.h>
00034 
00035 class TQWidgetStack;
00036 class TQSpinBox;
00037 class TQRadioButton;
00038 class TQGroupBox;
00039 class TQCheckBox;
00040 
00041 class KDateEdit;
00042 namespace KCal {
00043 class Incidence;
00044 }
00045 using namespace KCal;
00046 
00047 class RecurBase : public TQWidget
00048 {
00049   public:
00050     RecurBase( TQWidget *parent = 0, const char *name = 0 );
00051 
00052     void setFrequency( int );
00053     int frequency();
00054     // FIXME: If we want to adjust the recurrence when the start/due date change,
00055     // we need to reimplement this method in the derived classes!
00056     void setDateTimes( const TQDateTime &/*start*/, const TQDateTime &/*end*/ ) {}
00057 
00058     TQWidget *frequencyEdit();
00059 
00060   protected:
00061     static TQComboBox *createWeekCountCombo( TQWidget *parent=0, const char *name=0 );
00062     static TQComboBox *createWeekdayCombo( TQWidget *parent=0, const char *name=0 );
00063     static TQComboBox *createMonthNameCombo( TQWidget *parent=0, const char *name=0 );
00064     TQBoxLayout *createFrequencySpinBar( TQWidget *parent, TQLayout *layout,
00065     TQString everyText, TQString unitText );
00066 
00067   private:
00068     TQSpinBox *mFrequencyEdit;
00069 };
00070 
00071 class RecurDaily : public RecurBase
00072 {
00073   public:
00074     RecurDaily( TQWidget *parent = 0, const char *name = 0 );
00075 };
00076 
00077 class RecurWeekly : public RecurBase
00078 {
00079   public:
00080     RecurWeekly( TQWidget *parent = 0, const char *name = 0 );
00081 
00082     void setDays( const TQBitArray & );
00083     TQBitArray days();
00084 
00085   private:
00086     TQCheckBox *mDayBoxes[7];
00087 };
00088 
00089 class RecurMonthly : public RecurBase
00090 {
00091   public:
00092     RecurMonthly( TQWidget *parent = 0, const char *name = 0 );
00093 
00094     void setByDay( int day );
00095     void setByPos( int count, int weekday );
00096 
00097     bool byDay();
00098     bool byPos();
00099 
00100     int day();
00101 
00102     int count();
00103     int weekday();
00104 
00105   private:
00106     TQRadioButton *mByDayRadio;
00107     TQComboBox *mByDayCombo;
00108 
00109     TQRadioButton *mByPosRadio;
00110     TQComboBox *mByPosCountCombo;
00111     TQComboBox *mByPosWeekdayCombo;
00112 };
00113 
00114 class RecurYearly : public RecurBase
00115 {
00116   public:
00117     enum YearlyType { byDay, byPos, byMonth };
00118 
00119     RecurYearly( TQWidget *parent = 0, const char *name = 0 );
00120 
00121     void setByDay( int day );
00122     void setByPos( int count, int weekday, int month );
00123     void setByMonth( int day, int month );
00124 
00125     YearlyType getType();
00126 
00127     int day();
00128     int posCount();
00129     int posWeekday();
00130     int posMonth();
00131     int monthDay();
00132     int month();
00133 
00134   private:
00135     TQRadioButton *mByMonthRadio;
00136     TQRadioButton *mByPosRadio;
00137     TQRadioButton *mByDayRadio;
00138 
00139     TQSpinBox *mByMonthSpin;
00140     TQComboBox *mByMonthCombo;
00141 
00142     TQComboBox *mByPosDayCombo;
00143     TQComboBox *mByPosWeekdayCombo;
00144     TQComboBox *mByPosMonthCombo;
00145 
00146     TQSpinBox *mByDaySpin;
00147 };
00148 
00149 class RecurrenceChooser : public TQWidget
00150 {
00151     Q_OBJECT
00152   
00153   public:
00154     RecurrenceChooser( TQWidget *parent = 0, const char *name = 0 );
00155 
00156     enum { Daily, Weekly, Monthly, Yearly };
00157 
00158     void setType( int );
00159     int type();
00160 
00161   signals:
00162     void chosen( int );
00163 
00164   protected slots:
00165     void emitChoice();
00166 
00167   private:
00168     TQComboBox *mTypeCombo;
00169 
00170     TQRadioButton *mDailyButton;
00171     TQRadioButton *mWeeklyButton;
00172     TQRadioButton *mMonthlyButton;
00173     TQRadioButton *mYearlyButton;
00174 };
00175 
00176 class ExceptionsBase
00177 {
00178   public:
00179     virtual void setDates( const DateList & ) = 0;
00180     virtual DateList dates() = 0;
00181 };
00182 
00183 class ExceptionsWidget : public TQWidget, public ExceptionsBase
00184 {
00185     Q_OBJECT
00186   
00187   public:
00188     ExceptionsWidget( TQWidget *parent = 0, const char *name = 0 );
00189 
00190     void setDates( const DateList & );
00191     DateList dates();
00192 
00193   protected slots:
00194     void addException();
00195     void changeException();
00196     void deleteException();
00197 
00198   private:
00199     KDateEdit *mExceptionDateEdit;
00200     TQListBox *mExceptionList;
00201     DateList mExceptionDates;
00202 };
00203 
00204 class ExceptionsDialog : public KDialogBase, public ExceptionsBase
00205 {
00206   public:
00207     ExceptionsDialog( TQWidget *parent, const char *name = 0 );
00208 
00209     void setDates( const DateList & );
00210     DateList dates();
00211 
00212   private:
00213     ExceptionsWidget *mExceptions;
00214 };
00215 
00216 class RecurrenceRangeBase
00217 {
00218   public:
00219     virtual void setDefaults( const TQDateTime &from ) = 0;
00220 
00221     virtual void setDuration( int ) = 0;
00222     virtual int duration() = 0;
00223 
00224     virtual void setEndDate( const TQDate & ) = 0;
00225     virtual TQDate endDate() = 0;
00226 
00227     virtual void setDateTimes( const TQDateTime &start,
00228                                const TQDateTime &end = TQDateTime() ) = 0;
00229 };
00230 
00231 class RecurrenceRangeWidget : public TQWidget, public RecurrenceRangeBase
00232 {
00233     Q_OBJECT
00234   
00235   public:
00236     RecurrenceRangeWidget( TQWidget *parent = 0, const char *name = 0 );
00237 
00238     void setDefaults( const TQDateTime &from );
00239 
00240     void setDuration( int );
00241     int duration();
00242 
00243     void setEndDate( const TQDate & );
00244     TQDate endDate();
00245 
00246     void setDateTimes( const TQDateTime &start,
00247                        const TQDateTime &end = TQDateTime() );
00248 
00249   protected slots:
00250     void showCurrentRange();
00251 
00252   private:
00253     TQGroupBox *mRangeGroupBox;
00254     TQLabel *mStartDateLabel;
00255     TQRadioButton *mNoEndDateButton;
00256     TQRadioButton *mEndDurationButton;
00257     TQSpinBox *mEndDurationEdit;
00258     TQRadioButton *mEndDateButton;
00259     KDateEdit *mEndDateEdit;
00260 };
00261 
00262 class RecurrenceRangeDialog : public KDialogBase, public RecurrenceRangeBase
00263 {
00264   public:
00265     RecurrenceRangeDialog( TQWidget *parent = 0, const char *name = 0 );
00266 
00267     void setDefaults( const TQDateTime &from );
00268 
00269     void setDuration( int );
00270     int duration();
00271 
00272     void setEndDate( const TQDate & );
00273     TQDate endDate();
00274 
00275     void setDateTimes( const TQDateTime &start,
00276                        const TQDateTime &end = TQDateTime() );
00277 
00278   private:
00279     RecurrenceRangeWidget *mRecurrenceRangeWidget;
00280 };
00281 
00282 class KOEditorRecurrence : public TQWidget
00283 {
00284     Q_OBJECT
00285   
00286   public:
00287     KOEditorRecurrence ( TQWidget *parent = 0, const char *name = 0 );
00288     virtual ~KOEditorRecurrence();
00289 
00290     enum { Daily, Weekly, Monthly, Yearly };
00291 
00293     void setDefaults( const TQDateTime &from, const TQDateTime &to, bool allday );
00295     void readIncidence( Incidence * );
00297     void writeIncidence( Incidence * );
00298 
00300     bool validateInput();
00301 
00302     bool doesRecur();
00303 
00304     void saveValues();
00305     void restoreValues();
00306 
00307   public slots:
00308     void setRecurrenceEnabled( bool );
00309     void setDateTimes( const TQDateTime &start, const TQDateTime &end );
00310     void setDateTimeStr( const TQString & );
00311 
00312   signals:
00313     void dateTimesChanged( const TQDateTime &start, const TQDateTime &end );
00314 
00315   protected slots:
00316     void showCurrentRule( int );
00317     void showExceptionsDialog();
00318     void showRecurrenceRangeDialog();
00319 
00320   private:
00321     Recurrence mSaveRec;
00322     TQCheckBox *mEnabledCheck;
00323 
00324     TQGroupBox *mTimeGroupBox;
00325     TQLabel *mDateTimeLabel;
00326 
00327     TQGroupBox *mRuleBox;
00328     TQWidgetStack *mRuleStack;
00329     RecurrenceChooser *mRecurrenceChooser;
00330 
00331     RecurDaily *mDaily;
00332     RecurWeekly *mWeekly;
00333     RecurMonthly *mMonthly;
00334     RecurYearly *mYearly;
00335 
00336     RecurrenceRangeBase *mRecurrenceRange;
00337     RecurrenceRangeWidget *mRecurrenceRangeWidget;
00338     RecurrenceRangeDialog *mRecurrenceRangeDialog;
00339     TQPushButton *mRecurrenceRangeButton;
00340 
00341     ExceptionsBase *mExceptions;
00342     ExceptionsDialog *mExceptionsDialog;
00343     ExceptionsWidget *mExceptionsWidget;
00344     TQPushButton *mExceptionsButton;
00345 
00346     TQDateTime mEventStartDt;
00347 };
00348 
00349 class KOEditorRecurrenceDialog : public KDialogBase
00350 {
00351   Q_OBJECT
00352   
00353   public:
00354     KOEditorRecurrenceDialog( TQWidget *parent );
00355     KOEditorRecurrence* editor() const { return mRecurrence; }
00356 
00357   protected slots:
00358     void slotOk();
00359     void slotCancel();
00360 
00361   private:
00362     KOEditorRecurrence *mRecurrence;
00363     bool mRecurEnabled;
00364 };
00365 
00366 #endif