1 /*
2  *  messagenotification.h  -  displays an alarm message in a system notification
3  *  Program:  kalarm
4  *  SPDX-FileCopyrightText: 2020 David Jarvie <djarvie@kde.org>
5  *
6  *  SPDX-License-Identifier: GPL-2.0-or-later
7  */
8 
9 #pragma once
10 
11 #include "messagedisplay.h"
12 #include <KNotification>
13 
14 using namespace KAlarmCal;
15 
16 /**
17  * MessageNotification: A window to display an alarm or error message
18  */
19 class MessageNotification : public KNotification, public MessageDisplay
20 {
21     Q_OBJECT
22 public:
23     MessageNotification(const KAEvent&, const KAAlarm&, int flags);
24     MessageNotification(const KAEvent&, const DateTime& alarmDateTime, const QStringList& errmsgs,
25                   const QString& dontShowAgain);
26     ~MessageNotification() override;
27 
28     /** Restore MessageNotification instances saved at session shutdown. */
29     static void sessionRestore();
30 
31     QWidget* displayParent() override;
32     void closeDisplay() override;
33     void showDisplay() override;
34     void raiseDisplay() override;
35 
36     void                repeat(const KAAlarm&) override;
37     bool                hasDefer() const override;
38     void                showDefer() override;
39     void                showDateTime(const KAEvent&, const KAAlarm&) override;
40     void                cancelReminder(const KAEvent&, const KAAlarm&) override;
41     static int          notificationCount();
42 
43 protected Q_SLOTS:
44     void textsChanged(MessageDisplayHelper::DisplayTexts::TextIds ids, const QString& change);
45 
46 protected:
47     void setUpDisplay() override;
48     bool isDeferButtonEnabled() const override;
49     void enableDeferButton(bool enable) override;
50     void enableEditButton(bool enable) override;
51     void saveProperties(KConfigGroup&);
52 
53 private Q_SLOTS:
54     void buttonActivated(unsigned int index);
55     void commandCompleted(bool success);
56     void slotClosed();
57 
58 private:
59     MessageNotification(const QString& eventId, MessageDisplayHelper* helper);
60     void                setNotificationTitle(const QString&);
61     void                setNotificationText();
62     void                setNotificationButtons();
63 
64     static QVector<MessageNotification*> mNotificationList;   // list of notification instances
65     // Miscellaneous
66     QString             mTimeText;                // trigger time text
67     QString             mMessageText;             // alarm message text
68     QString             mRemainingText;           // remaining time text
69     int                 mEditButtonIndex {-1};    // edit button's action index
70     int                 mDeferButtonIndex {-1};   // defer button's action index
71     bool                mEnableDefer {false};     // whether to show a Defer button
72     bool                mEnableEdit {false};      // whether to show an Edit button
73     bool                mInitialised {false};     // setUpDisplay() has been called to create the window's widgets
74     bool                mDisplayComplete {false}; // true once displayComplete() has been called
75     bool                mShown {false};           // true once the notification has been displayed
76     bool                mCommandInhibit {false};  // true to prevent display until command exits
77 
78 friend class MNSessionManager;
79 };
80 
81 
82 // vim: et sw=4:
83