2 * messagewin.h - displays an alarm message
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.
24 /** @file messagewin.h - displays an alarm message */
26 #include "autoqpointer.h"
30 #include "mainwindowbase.h"
32 #include <kalarmcal/kaevent.h>
35 #include <akonadi/collection.h>
36 #include <akonadi/item.h>
56 using namespace KAlarmCal
;
59 * MessageWin: A window to display an alarm or error message
61 class MessageWin
: public MainWindowBase
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
);
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;
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
; }
86 virtual QSize
sizeHint() const;
87 static int instanceCount(bool excludeAlwaysHidden
= false);
89 static MessageWin
* findEvent(const EventId
& eventId
);
91 static MessageWin
* findEvent(const QString
& eventId
);
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
);
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
&);
113 void editCloseCancel();
114 void activeWindowChanged(WId
);
115 void checkDeferralLimit();
116 void displayMainWindow();
117 #ifdef KMAIL_SUPPORTED
118 void slotShowKMailMessage();
121 void audioTerminating();
125 void enableButtons();
126 void setRemainingTextDay();
127 void setRemainingTextMinute();
129 void readProcessOutput(ShellProcess
*);
132 MessageWin(const KAEvent
*, const DateTime
& alarmDateTime
, const QStringList
& errmsgs
,
133 const QString
& dontShowAgain
);
135 QString
dateTimeToDisplay();
136 void displayComplete();
137 void setButtonsReadOnly(bool);
138 bool getWorkAreaAndModal();
140 void setDeferralLimit(const KAEvent
&);
141 void alarmShowing(KAEvent
&);
143 bool retrieveEvent(KAEvent
&, Akonadi::Collection
&, bool& showEdit
, bool& showDefer
);
145 bool retrieveEvent(KAEvent
&, AlarmResource
*&, bool& showEdit
, bool& showDefer
);
147 bool haveErrorMessage(unsigned msg
) const;
148 void clearErrorMessage(unsigned msg
) const;
150 static bool reinstateFromDisplaying(const KCalCore::Event::Ptr
&, KAEvent
&, Akonadi::Collection
&, bool& showEdit
, bool& showDefer
);
152 static bool reinstateFromDisplaying(const KCal::Event
*, KAEvent
&, AlarmResource
*&, bool& showEdit
, bool& showDefer
);
154 static bool isSpread(const QPoint
& topLeft
);
156 static QList
<MessageWin
*> mWindowList
; // list of existing message windows
158 static QMap
<EventId
, unsigned> mErrorMessages
; // error messages currently displayed, by event ID
160 static QMap
<QString
, unsigned> mErrorMessages
; // error messages currently displayed, by event ID
162 // Sound file playing
163 static QPointer
<AudioThread
> mAudioThread
; // thread to play audio file
164 // Properties needed by readProperties()
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
171 Akonadi::Item::Id mEventItemId
;
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
188 int mAudioRepeatPause
;
190 bool mShowEdit
; // display the Edit button
191 bool mNoDefer
; // don't display a Defer option
192 bool mInvalid
; // restored window is invalid
194 KAEvent mEvent
; // the whole event, for updating the calendar file
195 KAEvent mOriginalEvent
; // the original event supplied to the constructor
197 Akonadi::Collection mCollection
; // collection which the event comes/came from
199 AlarmResource
* mResource
; // resource which the event comes/came from
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
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