Maki
Formally verfied low-code orchestration
Loading...
Searching...
No Matches
notifications.h
1#pragma once
2
3#include <stdint.h>
4
5#include <QWidget>
6#include <chrono>
7#include <functional>
8#include <string>
9
10#include "logging.h"
11
12namespace notification {
13
17using NotificationBody = std::variant<std::string, QWidget*>;
18
26extern std::function<void(logging::LogLevel level,
27 const std::string& header,
28 const std::string& message)>
29 gNotificationStream;
30
40extern std::function<QString(const QString& id,
41 logging::LogLevel level,
42 const std::string& header,
43 QWidget* body)>
44 gLongNotificationStream;
45
53void Notify(logging::LogLevel level, const std::string& header, const NotificationBody& message);
54
64QString NotifyLongRunning(const QString& id, logging::LogLevel level, const std::string& header, const NotificationBody& body);
65
73template <typename... Args>
74std::string format(std::string_view fmt, Args&&... args)
75{
76 return std::vformat(fmt, std::make_format_args(args...));
77}
78
79} // namespace notification
80
81#define NOTIFY_ERROR(header, s, ...) \
82 notification::Notify(logging::LogLevel::Error, header, notification::format(s, ##__VA_ARGS__))
83#define NOTIFY_WARNING(header, s, ...) \
84 notification::Notify(logging::LogLevel::Warning, header, notification::format(s, ##__VA_ARGS__))
85#define NOTIFY_INFO(header, s, ...) \
86 notification::Notify(logging::LogLevel::Info, header, notification::format(s, ##__VA_ARGS__))
87
88#define NOTIFY_LONG_ERROR(id, header, content) \
89 notification::NotifyLongRunning(id, logging::LogLevel::Error, header, content)
90#define NOTIFY_LONG_WARNING(id, header, content) \
91 notification::NotifyLongRunning(id, logging::LogLevel::Warning, header, content)
92#define NOTIFY_LONG_INFO(id, header, content) \
93 notification::NotifyLongRunning(id, logging::LogLevel::Info, header, content)