editdlg.h 10.8 KB
Newer Older
1
/*
2
 *  editdlg.h  -  dialog to create or modify an alarm or alarm template
3
 *  Program:  kalarm
4
 *  Copyright © 2001-2015 by David Jarvie <djarvie@kde.org>
5 6 7 8 9
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
10 11 12 13 14 15
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU General Public License for more details.
 *
David Jarvie's avatar
David Jarvie committed
16 17 18
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 20 21 22 23
 */

#ifndef EDITDLG_H
#define EDITDLG_H

Laurent Montel's avatar
Laurent Montel committed
24 25 26
#include <kalarmcal/alarmtext.h>
#include <kalarmcal/datetime.h>
#include <kalarmcal/kaevent.h>
27

Laurent Montel's avatar
Laurent Montel committed
28
#include <AkonadiCore/collection.h>
29

30 31
#include <QDialog>
#include <QTime>
32

David Jarvie's avatar
David Jarvie committed
33 34 35
class QLabel;
class QShowEvent;
class QResizeEvent;
David Jarvie's avatar
David Jarvie committed
36
class QAbstractButton;
David Jarvie's avatar
David Jarvie committed
37
class QGroupBox;
38
class QFrame;
39
class QVBoxLayout;
Laurent Montel's avatar
Laurent Montel committed
40
class QLineEdit;
Laurent Montel's avatar
Laurent Montel committed
41
class QTabWidget;
42
class ButtonGroup;
43
class TimeEdit;
David Jarvie's avatar
David Jarvie committed
44 45
class RadioButton;
class CheckBox;
46
class LateCancelSelector;
David Jarvie's avatar
David Jarvie committed
47
class AlarmTimeWidget;
48
class RecurrenceEdit;
49
class Reminder;
50
class StackedScrollGroup;
51
class TimeSpinBox;
52
class QDialogButtonBox;
53

54
using namespace KAlarmCal;
55

56

57
class EditAlarmDlg : public QDialog
58
{
59 60 61 62 63 64 65 66 67
        Q_OBJECT
    public:
        enum Type { NO_TYPE, DISPLAY, COMMAND, EMAIL, AUDIO };
        enum GetResourceType {
            RES_PROMPT,        // prompt for resource
            RES_USE_EVENT_ID,  // use resource containing event, or prompt if not found
            RES_IGNORE         // don't get resource
        };

Laurent Montel's avatar
Laurent Montel committed
68
        static EditAlarmDlg* create(bool Template, Type, QWidget* parent = nullptr,
69
                                    GetResourceType = RES_PROMPT);
Laurent Montel's avatar
Laurent Montel committed
70
        static EditAlarmDlg* create(bool Template, const KAEvent*, bool newAlarm, QWidget* parent = nullptr,
71 72 73
                                    GetResourceType = RES_PROMPT, bool readOnly = false);
        virtual ~EditAlarmDlg();
        bool            getEvent(KAEvent&, Akonadi::Collection&);
74

75 76 77
        // Methods to initialise values in the New Alarm dialogue.
        // N.B. setTime() must be called first to set the date-only characteristic,
        //      followed by setRecurrence() if applicable.
78
        void            setTime(const DateTime&);    // must be called first to set date-only value
79
        void            setRecurrence(const KARecurrence&, const KCalCore::Duration& subRepeatInterval, int subRepeatCount);
80
        void            setRepeatAtLogin();
81
        virtual void    setAction(KAEvent::SubAction, const AlarmText& = AlarmText()) = 0;
82 83 84
        void            setLateCancel(int minutes);
        void            setShowInKOrganizer(bool);

85
        QSize           sizeHint() const override    { return minimumSizeHint(); }
86

87
        static int      instanceCount();
88 89 90
        static QString  i18n_chk_ShowInKOrganizer();   // text of 'Show in KOrganizer' checkbox

    protected:
Laurent Montel's avatar
Laurent Montel committed
91
        EditAlarmDlg(bool Template, KAEvent::SubAction, QWidget* parent = nullptr,
92
                     GetResourceType = RES_PROMPT);
Laurent Montel's avatar
Laurent Montel committed
93
        EditAlarmDlg(bool Template, const KAEvent*, bool newAlarm, QWidget* parent = nullptr,
94 95
                     GetResourceType = RES_PROMPT, bool readOnly = false);
        void            init(const KAEvent* event);
96 97 98 99
        void            resizeEvent(QResizeEvent*) override;
        void            showEvent(QShowEvent*) override;
        void            closeEvent(QCloseEvent*) override;
        bool            eventFilter(QObject*, QEvent*) override;
100 101 102 103 104 105 106 107
        virtual QString type_caption() const = 0;
        virtual void    type_init(QWidget* parent, QVBoxLayout* frameLayout) = 0;
        virtual void    type_initValues(const KAEvent*) = 0;
        virtual void    type_showOptions(bool more) = 0;
        virtual void    setReadOnly(bool readOnly) = 0;
        virtual void    saveState(const KAEvent*) = 0;
        virtual bool    type_stateChanged() const = 0;
        virtual void    type_setEvent(KAEvent&, const KDateTime&, const QString& text, int lateCancel, bool trial) = 0;
108
        virtual KAEvent::Flags getAlarmFlags() const;
109
        virtual bool    type_validate(bool trial) = 0;
110 111
        virtual void    type_aboutToTry() {}
        virtual void    type_executedTry(const QString& text, void* obj) { Q_UNUSED(text); Q_UNUSED(obj); }
Laurent Montel's avatar
Laurent Montel committed
112 113
        virtual Reminder* createReminder(QWidget* parent)  { Q_UNUSED(parent); return nullptr; }
        virtual CheckBox* type_createConfirmAckCheckbox(QWidget* parent)  { Q_UNUSED(parent); return nullptr; }
114 115 116 117 118 119 120 121 122 123 124
        virtual bool    checkText(QString& result, bool showErrorMessage = true) const = 0;

        void            showMainPage();
        bool            isTemplate() const         { return mTemplate; }
        bool            isNewAlarm() const         { return mNewAlarm; }
        bool            dateOnly() const;
        bool            isTimedRecurrence() const;
        bool            showingMore() const        { return mShowingMore; }
        Reminder*       reminder() const           { return mReminder; }
        LateCancelSelector* lateCancel() const     { return mLateCancel; }

Laurent Montel's avatar
Laurent Montel committed
125
    protected Q_SLOTS:
126 127 128
        virtual void    slotTry();
        virtual void    slotHelp();      // Load Template
        virtual void    slotDefault();   // More/Less Options
129
        void            slotButtonClicked(QAbstractButton *button);
130 131
        void            contentsChanged();

Laurent Montel's avatar
Laurent Montel committed
132
    private Q_SLOTS:
133 134 135 136 137 138 139 140 141
        void            slotRecurTypeChange(int repeatType);
        void            slotRecurFrequencyChange();
        void            slotEditDeferral();
        void            slotShowMainPage();
        void            slotShowRecurrenceEdit();
        void            slotAnyTimeToggled(bool anyTime);
        void            slotTemplateTimeType(QAbstractButton*);
        void            slotSetSubRepetition();
        void            slotResize();
142
        void            focusFixTimer();
143 144 145 146 147 148

    private:
        void            init(const KAEvent* event, GetResourceType getResource);
        void            initValues(const KAEvent*);
        void            setEvent(KAEvent&, const QString& text, bool trial);
        bool            validate();
Laurent Montel's avatar
Laurent Montel committed
149
        void            setRecurTabTitle(const KAEvent* = nullptr);
150 151 152 153
        virtual bool    stateChanged() const;
        void            showOptions(bool more);

    protected:
154
        KAEvent::SubAction  mAlarmType;           // actual alarm type
155 156 157 158 159 160

        QDialogButtonBox*   mButtonBox;
        QAbstractButton*    mTryButton;
        QAbstractButton*    mLoadTemplateButton;
        QAbstractButton*    mMoreLessButton;

161
    private:
162
        static QList<EditAlarmDlg*> mWindowList;  // list of instances
Laurent Montel's avatar
Laurent Montel committed
163
        QTabWidget*         mTabs;                // the tabs in the dialog
164 165 166 167 168 169 170 171
        StackedScrollGroup* mTabScrollGroup;
        int                 mMainPageIndex;
        int                 mRecurPageIndex;
        bool                mMainPageShown;            // true once the main tab has been displayed
        bool                mRecurPageShown;           // true once the recurrence tab has been displayed
        bool                mRecurSetDefaultEndDate;   // adjust default end date/time when recurrence tab is displayed

        // Templates
Laurent Montel's avatar
Laurent Montel committed
172
        QLineEdit*          mTemplateName;
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
        ButtonGroup*        mTemplateTimeGroup;
        RadioButton*        mTemplateDefaultTime; // no alarm time is specified
        RadioButton*        mTemplateUseTimeAfter;// alarm time is specified as an offset from current
        RadioButton*        mTemplateAnyTime;     // alarms have date only, no time
        RadioButton*        mTemplateUseTime;     // an alarm time is specified
        TimeSpinBox*        mTemplateTimeAfter;   // the specified offset from the current time
        TimeEdit*           mTemplateTime;        // the alarm time which is specified 
        QGroupBox*          mDeferGroup;
        QLabel*             mDeferTimeLabel;
        QPushButton*        mDeferChangeButton;

        AlarmTimeWidget*    mTimeWidget;
        LateCancelSelector* mLateCancel;
        Reminder*           mReminder;           // null except for display alarms
        CheckBox*           mShowInKorganizer;

        QFrame*             mMoreOptions;        // contains options hidden by default

        RecurrenceEdit*     mRecurrenceEdit;

        QString             mAlarmMessage;       // message text/file name/command/email message
194 195
        DateTime            mAlarmDateTime;
        DateTime            mDeferDateTime;
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
        Akonadi::Item::Id   mCollectionItemId;   // if >=0, save alarm in collection containing this item ID
        Akonadi::Collection mCollection;         // collection to save event into, or null
        int                 mDeferGroupHeight;   // height added by deferred time widget
        int                 mDesktop;            // desktop to display the dialog in
        QString             mEventId;            // UID of event being edited, or blank for new event
        bool                mTemplate;           // editing an alarm template
        bool                mNewAlarm;           // editing a new alarm
        bool                mExpiredRecurrence;  // initially a recurrence which has expired
        mutable bool        mChanged;            // controls other than deferral have changed since dialog was displayed
        mutable bool        mOnlyDeferred;       // the only change made in the dialog was to the existing deferral
        bool                mDesiredReadOnly;    // the specified read-only status of the dialog
        bool                mReadOnly;           // the actual read-only status of the dialog
        bool                mShowingMore;        // the More Options button has been clicked

        // Initial state of all controls
        KAEvent*            mSavedEvent;
        QString             mSavedTemplateName;     // mTemplateName value
        QAbstractButton*    mSavedTemplateTimeType; // selected button in mTemplateTimeGroup
        QTime               mSavedTemplateTime;     // mTemplateTime value
        int                 mSavedTemplateAfterTime;// mTemplateAfterTime value
        QString             mSavedTextFileCommandMessage;  // mTextMessageEdit/mFileMessageEdit/mCmdCommandEdit/mEmailMessageEdit value
        KDateTime           mSavedDateTime;         // mTimeWidget value
        KDateTime           mSavedDeferTime;        // mDeferDateTime value
        int                 mSavedRecurrenceType;   // RecurrenceEdit::RepeatType value
        int                 mSavedLateCancel;       // mLateCancel value
        bool                mSavedShowInKorganizer; // mShowInKorganizer status
222 223 224
};

#endif // EDITDLG_H
225 226

// vim: et sw=4: