File indexing completed on 2024-03-24 05:48:43
0001 /* 0002 KT task editor window header 0003 -------------------------------------------------------------------- 0004 SPDX-FileCopyrightText: 1999 Gary Meyer <gary@meyer.net> 0005 -------------------------------------------------------------------- 0006 SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #pragma once 0010 0011 #include <QComboBox> 0012 #include <QDialog> 0013 #include <QGroupBox> 0014 #include <QLabel> 0015 #include <QPushButton> 0016 #include <QStringList> 0017 #include <QTextEdit> 0018 0019 #include <KTitleWidget> 0020 0021 class QCheckBox; 0022 class QGridLayout; 0023 class QHBoxLayout; 0024 0025 class KUrlRequester; 0026 0027 class CTTask; 0028 0029 class CrontabWidget; 0030 0031 class SetOrClearAllButton : public QPushButton 0032 { 0033 public: 0034 enum Status { SET_ALL, CLEAR_ALL }; 0035 0036 SetOrClearAllButton(QWidget *parent, SetOrClearAllButton::Status status); 0037 0038 void setStatus(SetOrClearAllButton::Status status); 0039 0040 bool isSetAll(); 0041 0042 bool isClearAll(); 0043 0044 private: 0045 SetOrClearAllButton::Status currentStatus; 0046 }; 0047 0048 class NumberPushButton : public QPushButton 0049 { 0050 public: 0051 explicit NumberPushButton(QWidget *parent); 0052 NumberPushButton(bool digitMode, QWidget *parent); 0053 0054 void updatePalette(); 0055 0056 bool event(QEvent *e) override; 0057 0058 void paintEvent(QPaintEvent *) override; 0059 0060 bool mIsDirty; 0061 QPalette mPalSelected; 0062 QPalette mPalNormal; 0063 }; 0064 0065 /** 0066 * Task editor window. 0067 */ 0068 class TaskEditorDialog : public QDialog 0069 { 0070 Q_OBJECT 0071 0072 public: 0073 /** 0074 * Initialize from CTTask. 0075 */ 0076 explicit TaskEditorDialog(CTTask *ctTask, const QString &caption, CrontabWidget *crontabWidget); 0077 0078 /** 0079 * Destroy. 0080 */ 0081 ~TaskEditorDialog() override; 0082 0083 private Q_SLOTS: 0084 0085 /** 0086 * Control the task title bar. 0087 */ 0088 void setupTitleWidget(const QString &comment = QLatin1String(""), KTitleWidget::MessageType = KTitleWidget::PlainMessage); 0089 0090 /** 0091 * Enable checkbox has changed 0092 */ 0093 void slotEnabledChanged(); 0094 0095 /** 0096 * Reboot checkbox has changed 0097 */ 0098 void slotRebootChanged(); 0099 0100 /** 0101 * Daily checkbox has been changed. 0102 */ 0103 void slotDailyChanged(); 0104 0105 /** 0106 * Apply changes and close. 0107 */ 0108 void slotOK(); 0109 0110 /** 0111 * Run the wizard. 0112 */ 0113 void slotWizard(); 0114 0115 /** 0116 * Set or clear all month checkboxes 0117 */ 0118 void slotAllMonths(); 0119 0120 /** 0121 * A month checkbox has changed 0122 */ 0123 void slotMonthChanged(); 0124 0125 /** 0126 * Set or clear all day of month checkboxes 0127 */ 0128 void slotAllDaysOfMonth(); 0129 0130 /** 0131 * A day of month checkbox has changed 0132 */ 0133 void slotDayOfMonthChanged(); 0134 0135 /** 0136 * Set or clear all day of week checkboxes 0137 */ 0138 void slotAllDaysOfWeek(); 0139 0140 /** 0141 * A day of week checkbox has changed 0142 */ 0143 void slotDayOfWeekChanged(); 0144 0145 /** 0146 * Set or clear all hour checkboxes 0147 */ 0148 void slotAllHours(); 0149 0150 /** 0151 * An hour checkbox has changed 0152 */ 0153 void slotHourChanged(); 0154 0155 void slotMinutesPreselection(int index); 0156 0157 /** 0158 * A minute checkbox has changed 0159 */ 0160 void slotMinuteChanged(); 0161 0162 private: 0163 NumberPushButton *createHourButton(QGroupBox *hoursGroup, int hour); 0164 QGroupBox *createHoursGroup(QWidget *mainWidget); 0165 0166 NumberPushButton *createMinuteButton(int minuteIndex); 0167 void createMinutesGroup(QWidget *mainWidget); 0168 0169 /** 0170 * Returns true if there is no checked minute in the hidden minuteButton 0171 */ 0172 bool canReduceMinutesGroup(); 0173 void emptyMinutesGroup(); 0174 void reduceMinutesGroup(); 0175 void increaseMinutesGroup(); 0176 0177 QGroupBox *createMonthsGroup(QWidget *mainWidget); 0178 0179 QGroupBox *createDaysOfMonthGroup(QWidget *mainWidget); 0180 QGroupBox *createDaysOfWeekGroup(QWidget *mainWidget); 0181 0182 bool checkCommand(); 0183 0184 void defineCommandIcon(); 0185 0186 bool isEveryDay(); 0187 0188 /** 0189 * Task. 0190 */ 0191 CTTask *mCtTask = nullptr; 0192 0193 CrontabWidget *mCrontabWidget = nullptr; 0194 0195 // Widgets. 0196 0197 KTitleWidget *mTitleWidget = nullptr; 0198 QPushButton *mOkButton = nullptr; 0199 0200 QComboBox *mUserCombo = nullptr; 0201 0202 QTextEdit *mLeComment = nullptr; 0203 0204 QLabel *mCommandIcon = nullptr; 0205 QPixmap mMissingCommandPixmap; 0206 KUrlRequester *mCommand = nullptr; 0207 0208 QCheckBox *mChkEnabled = nullptr; 0209 QCheckBox *mChkReboot = nullptr; 0210 QCheckBox *mCbEveryDay = nullptr; 0211 0212 QGroupBox *mBgMonth = nullptr; 0213 NumberPushButton *mMonthButtons[13]; // The index 0 is not used 0214 SetOrClearAllButton *mAllMonths = nullptr; 0215 0216 QGroupBox *mBgDayOfMonth; 0217 NumberPushButton *mDayOfMonthButtons[32]; // The index 0 is not used 0218 SetOrClearAllButton *mAllDaysOfMonth = nullptr; 0219 0220 QGroupBox *mBgDayOfWeek = nullptr; 0221 NumberPushButton *mDayOfWeekButtons[8]; // The index 0 is not used 0222 SetOrClearAllButton *mAllDaysOfWeek = nullptr; 0223 0224 QGroupBox *mHoursGroup = nullptr; 0225 QLabel *mMorningLabel = nullptr; 0226 QLabel *mAfternoonLabel = nullptr; 0227 QPushButton *mHourButtons[24]; 0228 SetOrClearAllButton *mAllHours = nullptr; 0229 0230 QGroupBox *mMinutesGroup = nullptr; 0231 QGridLayout *mMinutesLayout = nullptr; 0232 QPushButton *mMinuteButtons[60]; 0233 0234 QHBoxLayout *mMinutesPreselectionLayout = nullptr; 0235 QComboBox *mMinutesPreselection = nullptr; 0236 0237 static const int minuteTotal = 59; // or 55 or 59 0238 0239 static const int minutePerColumn = 12; // or 30 or 12 0240 0241 static const int reducedMinuteStep = 5; 0242 0243 QStringList mSpecialValidCommands; 0244 }; 0245