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, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 **************************************************************************/
19
25#ifndef _NOTIFICATION_MANAGER_H__
26#define _NOTIFICATION_MANAGER_H__
27
28#include <wx/timer.h>
29#include "notification.h"
30#include "observable_evtvar.h"
31#include "comm_appmsg.h"
32
33class NotificationMsg : public AppMsg {
34public:
35 NotificationMsg() : AppMsg(AppMsg::Type::CustomMsg) {}
36
37 NotificationMsg(const std::string action,
38 std::shared_ptr<Notification> _notification)
39 : AppMsg(AppMsg::Type::CustomMsg),
40 action_verb(action),
41 notification(_notification) {};
42
43 virtual ~NotificationMsg() = default;
44
45 const std::string action_verb;
46 std::shared_ptr<Notification> notification;
47};
48
51public:
52 static NotificationManager& GetInstance();
53
55 NotificationManager& operator=(const NotificationManager&) = delete;
56
57 std::string AddNotification(std::shared_ptr<Notification> _notification);
58
66 std::string AddNotification(NotificationSeverity _severity,
67 const std::string& _message,
68 int timeout_secs = -1);
74 bool AcknowledgeNotification(const std::string& guid);
75
76 bool AcknowledgeAllNotifications();
77
79 NotificationSeverity GetMaxSeverity();
80
82 const std::vector<std::shared_ptr<Notification>>& GetNotifications() const {
83 return active_notifications;
84 }
85
86 size_t GetNotificationCount() const { return active_notifications.size(); }
87 void ScrubNotificationDirectory(int days_to_retain);
88
91
92private:
94 void PersistNotificationAsFile(
95 const std::shared_ptr<Notification> _notification);
96
97 void OnTimer(wxTimerEvent& event);
98
99 std::vector<std::shared_ptr<Notification>> active_notifications;
100 wxTimer m_timeout_timer;
101};
102
103#endif
Generic event handling between MVC Model and Controller based on a shared EventVar variable.
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.
EventVar evt_notificationlist_change
Notified without data when a notification is added or removed.
NotificationSeverity GetMaxSeverity()
Return max severity among current active notifications.
Class Notification.