Updated the Tools menu to reflect current build.
[kdepim.git] / kalarm / messagewin.h
blobd4f619e64329614586516b935f5fb46581d8de78
1 /*
2 * messagewin.h - displays an alarm message
3 * Program: kalarm
4 * Copyright © 2001-2013 by David Jarvie <djarvie@kde.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #ifndef MESSAGEWIN_H
22 #define MESSAGEWIN_H
24 /** @file messagewin.h - displays an alarm message */
26 #include "autoqpointer.h"
27 #ifdef USE_AKONADI
28 #include "eventid.h"
29 #endif
30 #include "mainwindowbase.h"
32 #include <kalarmcal/kaevent.h>
34 #ifdef USE_AKONADI
35 #include <akonadi/collection.h>
36 #include <akonadi/item.h>
37 #endif
39 #include <QList>
40 #include <QMap>
41 #include <QPointer>
43 class QShowEvent;
44 class QMoveEvent;
45 class QResizeEvent;
46 class QCloseEvent;
47 class PushButton;
48 class MessageText;
49 class QCheckBox;
50 class QLabel;
51 class DeferAlarmDlg;
52 class EditAlarmDlg;
53 class ShellProcess;
54 class AudioThread;
56 using namespace KAlarmCal;
58 /**
59 * MessageWin: A window to display an alarm or error message
61 class MessageWin : public MainWindowBase
63 Q_OBJECT
64 public:
65 enum { // flags for constructor
66 NO_RESCHEDULE = 0x01, // don't reschedule the event once it has displayed
67 NO_DEFER = 0x02, // don't display the Defer button
68 ALWAYS_HIDE = 0x04, // never show the window (e.g. for audio-only alarms)
69 NO_INIT_VIEW = 0x08 // for internal MessageWin use only
72 MessageWin(); // for session management restoration only
73 MessageWin(const KAEvent*, const KAAlarm&, int flags);
74 ~MessageWin();
75 void repeat(const KAAlarm&);
76 void setRecreating() { mRecreating = true; }
77 const DateTime& dateTime() { return mDateTime; }
78 KAAlarm::Type alarmType() const { return mAlarmType; }
79 bool hasDefer() const;
80 void showDefer();
81 void cancelReminder(const KAEvent&, const KAAlarm&);
82 void showDateTime(const KAEvent&, const KAAlarm&);
83 bool isValid() const { return !mInvalid; }
84 bool alwaysHidden() const { return mAlwaysHide; }
85 virtual void show();
86 virtual QSize sizeHint() const;
87 static int instanceCount(bool excludeAlwaysHidden = false);
88 #ifdef USE_AKONADI
89 static MessageWin* findEvent(const EventId& eventId);
90 #else
91 static MessageWin* findEvent(const QString& eventId);
92 #endif
93 static void redisplayAlarms();
94 static void stopAudio(bool wait = false);
95 static bool isAudioPlaying();
96 static void showError(const KAEvent&, const DateTime& alarmDateTime, const QStringList& errmsgs,
97 const QString& dontShowAgain = QString());
98 static bool spread(bool scatter);
100 protected:
101 virtual void showEvent(QShowEvent*);
102 virtual void moveEvent(QMoveEvent*);
103 virtual void resizeEvent(QResizeEvent*);
104 virtual void closeEvent(QCloseEvent*);
105 virtual void saveProperties(KConfigGroup&);
106 virtual void readProperties(const KConfigGroup&);
108 private slots:
109 void slotOk();
110 void slotEdit();
111 void slotDefer();
112 void editCloseOk();
113 void editCloseCancel();
114 void activeWindowChanged(WId);
115 void checkDeferralLimit();
116 void displayMainWindow();
117 #ifdef KMAIL_SUPPORTED
118 void slotShowKMailMessage();
119 #endif
120 void slotSpeak();
121 void audioTerminating();
122 void startAudio();
123 void playReady();
124 void playFinished();
125 void enableButtons();
126 void setRemainingTextDay();
127 void setRemainingTextMinute();
128 void frameDrawn();
129 void readProcessOutput(ShellProcess*);
131 private:
132 MessageWin(const KAEvent*, const DateTime& alarmDateTime, const QStringList& errmsgs,
133 const QString& dontShowAgain);
134 void initView();
135 QString dateTimeToDisplay();
136 void displayComplete();
137 void setButtonsReadOnly(bool);
138 bool getWorkAreaAndModal();
139 void playAudio();
140 void setDeferralLimit(const KAEvent&);
141 void alarmShowing(KAEvent&);
142 #ifdef USE_AKONADI
143 bool retrieveEvent(KAEvent&, Akonadi::Collection&, bool& showEdit, bool& showDefer);
144 #else
145 bool retrieveEvent(KAEvent&, AlarmResource*&, bool& showEdit, bool& showDefer);
146 #endif
147 bool haveErrorMessage(unsigned msg) const;
148 void clearErrorMessage(unsigned msg) const;
149 #ifdef USE_AKONADI
150 static bool reinstateFromDisplaying(const KCalCore::Event::Ptr&, KAEvent&, Akonadi::Collection&, bool& showEdit, bool& showDefer);
151 #else
152 static bool reinstateFromDisplaying(const KCal::Event*, KAEvent&, AlarmResource*&, bool& showEdit, bool& showDefer);
153 #endif
154 static bool isSpread(const QPoint& topLeft);
156 static QList<MessageWin*> mWindowList; // list of existing message windows
157 #ifdef USE_AKONADI
158 static QMap<EventId, unsigned> mErrorMessages; // error messages currently displayed, by event ID
159 #else
160 static QMap<QString, unsigned> mErrorMessages; // error messages currently displayed, by event ID
161 #endif
162 // Sound file playing
163 static QPointer<AudioThread> mAudioThread; // thread to play audio file
164 // Properties needed by readProperties()
165 QString mMessage;
166 QFont mFont;
167 QColor mBgColour, mFgColour;
168 DateTime mDateTime; // date/time displayed in the message window
169 QDateTime mCloseTime; // UTC time at which window should be auto-closed
170 #ifdef USE_AKONADI
171 Akonadi::Item::Id mEventItemId;
172 EventId mEventId;
173 #else
174 QString mEventId;
175 #endif
176 QString mAudioFile;
177 float mVolume;
178 float mFadeVolume;
179 int mFadeSeconds;
180 int mDefaultDeferMinutes;
181 KAAlarm::Type mAlarmType;
182 KAEvent::SubAction mAction;
183 unsigned long mKMailSerialNumber; // if email text, message's KMail serial number, else 0
184 KAEvent::CmdErrType mCommandError;
185 QStringList mErrorMsgs;
186 QString mDontShowAgain; // non-null for don't-show-again option with error message
187 int mRestoreHeight;
188 int mAudioRepeatPause;
189 bool mConfirmAck;
190 bool mShowEdit; // display the Edit button
191 bool mNoDefer; // don't display a Defer option
192 bool mInvalid; // restored window is invalid
193 // Miscellaneous
194 KAEvent mEvent; // the whole event, for updating the calendar file
195 KAEvent mOriginalEvent; // the original event supplied to the constructor
196 #ifdef USE_AKONADI
197 Akonadi::Collection mCollection; // collection which the event comes/came from
198 #else
199 AlarmResource* mResource; // resource which the event comes/came from
200 #endif
201 QLabel* mTimeLabel; // trigger time label
202 QLabel* mRemainingText; // the remaining time (for a reminder window)
203 PushButton* mOkButton;
204 PushButton* mEditButton;
205 PushButton* mDeferButton;
206 PushButton* mSilenceButton;
207 PushButton* mKAlarmButton;
208 PushButton* mKMailButton;
209 MessageText* mCommandText; // shows output from command
210 QCheckBox* mDontShowAgainCheck;
211 EditAlarmDlg* mEditDlg; // alarm edit dialog invoked by Edit button
212 DeferAlarmDlg* mDeferDlg;
213 QDateTime mDeferLimit; // last UTC time to which the message can currently be deferred
214 int mButtonDelay; // delay (ms) after window is shown before buttons are enabled
215 int mScreenNumber; // screen to display on, or -1 for default
216 bool mAlwaysHide; // the window should never be displayed
217 bool mErrorWindow; // the window is simply an error message
218 bool mInitialised; // initView() has been called to create the window's widgets
219 bool mNoPostAction; // don't execute any post-alarm action
220 bool mRecreating; // window is about to be deleted and immediately recreated
221 bool mBeep;
222 bool mSpeak; // the message should be spoken via kttsd
223 bool mRescheduleEvent; // true to delete event after message has been displayed
224 bool mShown; // true once the window has been displayed
225 bool mPositioning; // true when the window is being positioned initially
226 bool mNoCloseConfirm; // the Defer or Edit button is closing the dialog
227 bool mDisableDeferral; // true if past deferral limit, so don't enable Defer button
230 #endif // MESSAGEWIN_H
232 // vim: et sw=4: