File indexing completed on 2024-05-12 05:14:53

0001 /*
0002  *  messagewindow.h  -  displays an alarm message in a window
0003  *  Program:  kalarm
0004  *  SPDX-FileCopyrightText: 2001-2020 David Jarvie <djarvie@kde.org>
0005  *
0006  *  SPDX-License-Identifier: GPL-2.0-or-later
0007  */
0008 
0009 #pragma once
0010 
0011 #include "mainwindowbase.h"
0012 #include "messagedisplay.h"
0013 
0014 
0015 class QShowEvent;
0016 class QMoveEvent;
0017 class QResizeEvent;
0018 class QCloseEvent;
0019 class PushButton;
0020 class MessageText;
0021 class QCheckBox;
0022 class QLabel;
0023 
0024 using namespace KAlarmCal;
0025 
0026 /**
0027  * MessageWindow: A window to display an alarm or error message
0028  */
0029 class MessageWindow : public MainWindowBase, public MessageDisplay
0030 {
0031     Q_OBJECT
0032 public:
0033     MessageWindow();     // for session management restoration only
0034     MessageWindow(const KAEvent&, const KAAlarm&, int flags);
0035     MessageWindow(const KAEvent&, const DateTime& alarmDateTime, const QStringList& errmsgs,
0036                   const QString& dontShowAgain);
0037     ~MessageWindow() override;
0038 
0039     QWidget* displayParent() override;
0040     void closeDisplay() override;
0041     void showDisplay() override;
0042     void raiseDisplay() override;
0043 
0044     void                repeat(const KAAlarm&) override;
0045     bool                hasDefer() const override;
0046     void                showDefer() override;
0047     void                showDateTime(const KAEvent&, const KAAlarm&) override;
0048     void                cancelReminder(const KAEvent&, const KAAlarm&) override;
0049 
0050     /** Use display() instead of show() to display a message window.
0051      *  This prevents windows which should be auto-closed from being shown.
0052      */
0053     void                display();
0054 
0055     QSize               sizeHint() const override;
0056     static void         redisplayAlarms();
0057     static int          windowCount(bool excludeAlwaysHidden = false);
0058     static bool         spread(bool scatter);
0059 
0060 protected Q_SLOTS:
0061     void textsChanged(MessageDisplayHelper::DisplayTexts::TextIds ids, const QString& change);
0062 
0063 protected:
0064     /** Called by MessageDisplayHelper to confirm that the alarm message should
0065      *  be acknowledged (closed).
0066      *  @return  true to close the alarm message, false to keep it open.
0067      */
0068     bool confirmAcknowledgement() override;
0069 
0070     void setUpDisplay() override;
0071 
0072     bool isDeferButtonEnabled() const override;
0073     void enableDeferButton(bool enable) override;
0074     void enableEditButton(bool enable) override;
0075 
0076     /** Called when the edit alarm dialog has been cancelled. */
0077     void editDlgCancelled() override;
0078 
0079     void                showEvent(QShowEvent*) override;
0080     void                moveEvent(QMoveEvent*) override;
0081     void                resizeEvent(QResizeEvent*) override;
0082     void                closeEvent(QCloseEvent*) override;
0083     void                saveProperties(KConfigGroup&) override;
0084     void                readProperties(const KConfigGroup&) override;
0085 
0086 private Q_SLOTS:
0087     void                slotOk();
0088     void                slotEdit();
0089     void                slotDefer();
0090     void                activeWindowChanged(WId);
0091     void                displayMainWindow();
0092     void                slotShowKMailMessage();
0093     void                enableButtons();
0094     void                commandCompleted(bool success);
0095     void                frameDrawn();
0096 
0097 private:
0098     void                displayComplete();
0099     void                setButtonsReadOnly(bool);
0100     bool                getWorkAreaAndModal();
0101     static bool         isSpread(const QPoint& topLeft);
0102     void show();   // ensure that display() is called instead of show() on a MessageWindow object
0103 
0104     static QList<MessageWindow*> mWindowList;     // list of message window instances
0105     // Properties needed by readProperties()
0106     int                 mRestoreHeight;
0107     // Miscellaneous
0108     QLabel*             mTimeLabel {nullptr};     // trigger time label
0109     QLabel*             mRemainingText {nullptr}; // the remaining time (for a reminder window)
0110     PushButton*         mOkButton;
0111     PushButton*         mEditButton {nullptr};
0112     PushButton*         mDeferButton {nullptr};
0113     PushButton*         mSilenceButton {nullptr};
0114     PushButton*         mKAlarmButton;
0115     PushButton*         mKMailButton {nullptr};
0116     MessageText*        mCommandText {nullptr};   // shows output from command
0117     QCheckBox*          mDontShowAgainCheck {nullptr};
0118     DeferDlgData*       mDeferData {nullptr};     // defer dialog data
0119     int                 mButtonDelay;             // delay (ms) after window is shown before buttons are enabled
0120     int                 mScreenNumber;            // screen to display on, or -1 for default
0121     bool                mInitialised {false};     // setUpDisplay() has been called to create the window's widgets
0122     bool                mShown {false};           // true once the window has been displayed
0123     bool                mPositioning {false};     // true when the window is being positioned initially
0124 };
0125 
0126 // vim: et sw=4: