OpenCPN Partial API docs
Loading...
Searching...
No Matches
notification_manager.h
Go to the documentation of this file.
1/**************************************************************************
2 * Copyright (C) 2025 by David S. Register *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, see <https://www.gnu.org/licenses/>. *
16 **************************************************************************/
17
24#ifndef NOTIFICATION_MANAGER_H_
25#define NOTIFICATION_MANAGER_H_
26
27#include <wx/timer.h>
28
29#include "observable/evtvar.h"
30
31#include "notification.h"
32#include "comm_appmsg.h"
33
34class NotificationMsg : public AppMsg {
35public:
36 NotificationMsg() : AppMsg(AppMsg::Type::CustomMsg) {}
37
38 NotificationMsg(const std::string action,
39 std::shared_ptr<Notification> _notification)
40 : AppMsg(AppMsg::Type::CustomMsg),
41 action_verb(action),
42 notification(_notification) {};
43
44 virtual ~NotificationMsg() = default;
45
46 const std::string action_verb;
47 std::shared_ptr<Notification> notification;
48};
49
52public:
53 static NotificationManager& GetInstance();
54
56 NotificationManager& operator=(const NotificationManager&) = delete;
57
58 std::string AddNotification(std::shared_ptr<Notification> _notification);
59
67 std::string AddNotification(NotificationSeverity _severity,
68 const std::string& _message,
69 int timeout_secs = -1);
75 bool AcknowledgeNotification(const std::string& guid);
76
77 bool AcknowledgeAllNotifications();
78
80 NotificationSeverity GetMaxSeverity();
81
83 const std::vector<std::shared_ptr<Notification>>& GetNotifications() const {
84 return active_notifications;
85 }
86
87 size_t GetNotificationCount() const { return active_notifications.size(); }
88 void ScrubNotificationDirectory(int days_to_retain);
89
92
93private:
95 void PersistNotificationAsFile(
96 const std::shared_ptr<Notification> _notification);
97
98 void OnTimer(wxTimerEvent& event);
99
100 std::vector<std::shared_ptr<Notification>> active_notifications;
101 wxTimer m_timeout_timer;
102};
103
104#endif
The global list of user notifications, a singleton.
const std::vector< std::shared_ptr< Notification > > & GetNotifications() const
Return current active notifications.
bool AcknowledgeNotification(const std::string &guid)
User ack on a notification which eventually will remove it.
obs::EventVar evt_notificationlist_change
Notified without data when a notification is added or removed.
NotificationSeverity GetMaxSeverity()
Return max severity among current active notifications.
Decoded messages definitions.
User notification container.