File indexing completed on 2025-04-20 07:58:48
0001 /* 0002 * SPDX-FileCopyrightText: 2019 Dimitris Kardarakos <dimkard@posteo.net> 0003 * 0004 * SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 0007 #ifndef NOTIFICATIONHANDLER_H 0008 #define NOTIFICATIONHANDLER_H 0009 0010 #include "alarmsmodel.h" 0011 #include <QVariantMap> 0012 0013 class AlarmNotification; 0014 /** 0015 * @brief Manages the creation and triggering of event alarm notifications 0016 * 0017 */ 0018 class NotificationHandler : public QObject 0019 { 0020 Q_OBJECT 0021 public: 0022 explicit NotificationHandler(QObject *parent); 0023 ~NotificationHandler() override; 0024 0025 /** 0026 * @brief Parses the internal list of active and suspended notifications and triggers their sending 0027 */ 0028 void sendNotifications(); 0029 0030 /** 0031 * @brief Creates an alarm notification object for the Incidence with \p uid. It sets the text to be displayed according to \p text. It adds this alarm notification to the internal list of active notifications (the list of notifications that should be sent at the next check). 0032 */ 0033 void addActiveNotification(const QString &uid, const QString &text); 0034 0035 /** 0036 * @brief Creates an alarm notification object for the Incidence with \p uid. It sets the text to be displayed according to \p text. It adds this alarm notification to the internal list of suspended notifications. 0037 */ 0038 void addSuspendedNotification(const QString &uid, const QString &text, const QDateTime &remindTime); 0039 0040 /** 0041 * @return The time period to check for alarms 0042 */ 0043 FilterPeriod period() const; 0044 0045 /** 0046 * @brief Sets the time period to check for alarms 0047 */ 0048 void setPeriod(const FilterPeriod &checkPeriod); 0049 0050 /** 0051 * @return The list of active notifications. It is the set of notification that should be sent at the next check 0052 */ 0053 QHash<QString, AlarmNotification *> activeNotifications() const; 0054 0055 /** 0056 * @return The list of suspended notifications 0057 */ 0058 QHash<QString, AlarmNotification *> suspendedNotifications() const; 0059 0060 /** 0061 * @brief The date time of the first suspended alarm scheduled. If no suspended notifications exist, an invalid datetime is returned. 0062 */ 0063 QDateTime firstSuspended() const; 0064 0065 Q_SIGNAL void scheduleAlarmCheck(); 0066 0067 public Q_SLOTS: 0068 /** 0069 * @brief Dismisses any further notification display for the alarm \p notification. 0070 * 0071 */ 0072 void dismiss(AlarmNotification *const notification); 0073 0074 /** 0075 * @brief Suspends the display of the alarm \p notification, by removing it from the list of active and putting it to the list of suspended notifications. Remind time is set according to configuration. 0076 */ 0077 void suspend(AlarmNotification *const notification); 0078 0079 private: 0080 void sendActiveNotifications(); 0081 void sendSuspendedNotifications(); 0082 0083 QHash<QString, AlarmNotification *> m_active_notifications; 0084 QHash<QString, AlarmNotification *> m_suspended_notifications; 0085 FilterPeriod m_period; 0086 int m_suspend_seconds; 0087 }; 0088 #endif