FreeRDP
SDL2/dialogs/sdl_connection_dialog.hpp
1 
20 #pragma once
21 
22 #include <memory>
23 #include <mutex>
24 #include <string>
25 #include <vector>
26 
27 #include <SDL.h>
28 
29 #include <freerdp/freerdp.h>
30 
31 #include "sdl_widget.hpp"
32 #include "sdl_buttons.hpp"
33 
35 {
36  public:
37  explicit SDLConnectionDialog(rdpContext* context);
38  SDLConnectionDialog(const SDLConnectionDialog& other) = delete;
39  SDLConnectionDialog(const SDLConnectionDialog&& other) = delete;
40  virtual ~SDLConnectionDialog();
41 
42  SDLConnectionDialog& operator=(const SDLConnectionDialog& other) = delete;
43  SDLConnectionDialog& operator=(SDLConnectionDialog&& other) = delete;
44 
45  bool visible() const;
46 
47  bool setTitle(const char* fmt, ...);
48  bool showInfo(const char* fmt, ...);
49  bool showWarn(const char* fmt, ...);
50  bool showError(const char* fmt, ...);
51 
52  bool show();
53  bool hide();
54 
55  bool running() const;
56  bool wait(bool ignoreRdpContextQuit = false);
57 
58  bool handle(const SDL_Event& event);
59 
60  private:
61  enum MsgType
62  {
63  MSG_NONE,
64  MSG_INFO,
65  MSG_WARN,
66  MSG_ERROR,
67  MSG_DISCARD
68  };
69 
70  bool createWindow();
71  void destroyWindow();
72 
73  bool update();
74 
75  bool setModal();
76 
77  static bool clearWindow(SDL_Renderer* renderer);
78 
79  bool update(SDL_Renderer* renderer);
80 
81  bool show(MsgType type, const char* fmt, va_list ap);
82  bool show(MsgType type);
83 
84  static std::string print(const char* fmt, va_list ap);
85  bool setTimer(Uint32 timeoutMS = 15000);
86  void resetTimer();
87 
88  static Uint32 timeout(Uint32 intervalMS, void* pvthis);
89 
90  struct widget_cfg_t
91  {
92  SDL_Color fgcolor = {};
93  SDL_Color bgcolor = {};
94  SdlWidget widget;
95  };
96 
97  rdpContext* _context = nullptr;
98  SDL_Window* _window = nullptr;
99  SDL_Renderer* _renderer = nullptr;
100  mutable std::mutex _mux;
101  std::string _title;
102  std::string _msg;
103  MsgType _type = MSG_NONE;
104  MsgType _type_active = MSG_NONE;
105  SDL_TimerID _timer = -1;
106  bool _running = false;
107  std::vector<widget_cfg_t> _list;
108  SdlButtonList _buttons;
109 };
110 
112 {
113  public:
114  explicit SDLConnectionDialogHider(freerdp* instance);
115  explicit SDLConnectionDialogHider(rdpContext* context);
116 
118  SDLConnectionDialogHider(const SDLConnectionDialogHider& other) = delete;
120  SDLConnectionDialogHider& operator=(const SDLConnectionDialogHider& other) = delete;
121  SDLConnectionDialogHider& operator=(SDLConnectionDialogHider& other) = delete;
122 
124 
125  private:
126  SDLConnectionDialog* get(freerdp* instance);
127  static SDLConnectionDialog* get(rdpContext* context);
128 
129  SDLConnectionDialog* _dialog = nullptr;
130  bool _visible = false;
131 };