FreeRDP
Loading...
Searching...
No Matches
sdl_connection_dialog_wrapper.hpp
1
21#pragma once
22
23#include <mutex>
24#include <memory>
25#include <string>
26#include <queue>
27
28#include <winpr/wlog.h>
29#include <winpr/platform.h>
30#include <freerdp/types.h>
31
32#include <SDL3/SDL.h>
33
35
37{
38 public:
39 enum MsgType
40 {
41 MSG_NONE,
42 MSG_INFO,
43 MSG_WARN,
44 MSG_ERROR,
45 MSG_DISCARD
46 };
47
48 explicit SdlConnectionDialogWrapper(wLog* log);
50
53
54 SdlConnectionDialogWrapper& operator=(const SdlConnectionDialogWrapper& other) = delete;
55 SdlConnectionDialogWrapper& operator=(SdlConnectionDialogWrapper&& other) = delete;
56
57 void create(rdpContext* context);
58 void destroy();
59
60 bool isRunning() const;
61 bool isVisible() const;
62
63 bool handleEvent(const SDL_Event& event);
64
65 WINPR_ATTR_FORMAT_ARG(2, 3)
66 void setTitle(WINPR_FORMAT_ARG const char* fmt, ...);
67 void setTitle(const std::string& title);
68
69 WINPR_ATTR_FORMAT_ARG(2, 3)
70 void showInfo(WINPR_FORMAT_ARG const char* fmt, ...);
71 void showInfo(const std::string& info);
72
73 WINPR_ATTR_FORMAT_ARG(2, 3)
74 void showWarn(WINPR_FORMAT_ARG const char* fmt, ...);
75 void showWarn(const std::string& info);
76
77 WINPR_ATTR_FORMAT_ARG(2, 3)
78 void showError(WINPR_FORMAT_ARG const char* fmt, ...);
79 void showError(const std::string& error);
80
81 void show(SdlConnectionDialogWrapper::MsgType type, const std::string& msg);
82
83 void show(bool visible = true);
84
85 void handleShow();
86
87 private:
88 class EventArg
89 {
90 public:
91 explicit EventArg(bool visible);
92 explicit EventArg(const std::string& title);
93 EventArg(SdlConnectionDialogWrapper::MsgType type, const std::string& msg, bool visible);
94
95 [[nodiscard]] bool hasTitle() const;
96 [[nodiscard]] const std::string& title() const;
97
98 [[nodiscard]] bool hasMessage() const;
99 [[nodiscard]] const std::string& message() const;
100
101 [[nodiscard]] bool hasType() const;
102 [[nodiscard]] SdlConnectionDialogWrapper::MsgType type() const;
103
104 [[nodiscard]] bool hasVisibility() const;
105 [[nodiscard]] bool visible() const;
106
107 [[nodiscard]] std::string str() const;
108
109 private:
110 std::string _title;
111 std::string _message;
112 SdlConnectionDialogWrapper::MsgType _type = MSG_NONE;
113 bool _visible = false;
114 uint32_t _mask = 0;
115 };
116 void push(EventArg&& arg);
117
118 mutable std::mutex _mux;
119 std::unique_ptr<SDLConnectionDialog> _connection_dialog{};
120 std::queue<EventArg> _queue{};
121 wLog* _log = nullptr;
122};