29#include "model/navutil_base.h"
38NotificationManager::NotificationManager() {
39 m_timeout_timer.Bind(wxEVT_TIMER, &NotificationManager::OnTimer,
this,
40 m_timeout_timer.GetId());
41 m_timeout_timer.Start(1000, wxTIMER_CONTINUOUS);
44void NotificationManager::OnTimer(wxTimerEvent& event) {
45 for (
auto note : active_notifications) {
46 if (note->GetTimeoutCount() > 0) {
47 note->DecrementTimoutCount();
50 for (
auto note : active_notifications) {
51 if (note->GetTimeoutCount() == 0) {
53 note->DecrementTimoutCount();
61 for (
auto note : active_notifications) {
62 int severity =
static_cast<int>(note->GetSeverity());
63 if (severity > rv) rv = severity;
65 return static_cast<NotificationSeverity
>(rv);
68std::string NotificationManager::AddNotification(
69 std::shared_ptr<Notification> _notification) {
70 active_notifications.push_back(_notification);
72 return _notification->GetGuid();
75std::string NotificationManager::AddNotification(NotificationSeverity _severity,
76 const std::string& _message,
79 std::make_shared<Notification>(_severity, _message, _timeout_secs);
80 active_notifications.push_back(notification);
82 return notification->GetGuid();
86 if (!GUID.length())
return false;
88 size_t target_message_hash = 0;
89 for (
auto it = active_notifications.begin();
90 it != active_notifications.end();) {
91 if ((*it)->GetGuid() == GUID) {
92 target_message_hash = (*it)->GetStringHash();
97 if (!target_message_hash)
return false;
102 while (!done && active_notifications.size()) {
103 for (
auto it = active_notifications.begin();
104 it != active_notifications.end();) {
105 if ((*it)->GetStringHash() == target_message_hash) {
106 active_notifications.erase(it);
111 if (it == active_notifications.end()) done =
true;
const void Notify()
Notify all listeners, no data supplied.
The global list of user notifications, a singleton.
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 NotificationManager.