Webdar 1.0.0
Web user interface to libdar
html_web_user_interaction.hpp
1/*********************************************************************/
2// webdar - a web server and interface program to libdar
3// Copyright (C) 2013-2025 Denis Corbin
4//
5// This file is part of Webdar
6//
7// Webdar is free software: you can redistribute it and/or modify
8// it under the terms of the GNU General Public License as published by
9// the Free Software Foundation, either version 3 of the License, or
10// (at your option) any later version.
11//
12// Webdar is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with Webdar. If not, see <http://www.gnu.org/licenses/>
19//
20//----
21// to contact the author: dar.linux@free.fr
22/*********************************************************************/
23
24#ifndef HTML_WEB_USER_INTERACTION_HPP
25#define HTML_WEB_USER_INTERACTION_HPP
26
27 // C system header files
28#include "my_config.h"
29extern "C"
30{
31
32}
33
34 // C++ system header files
35#include <libthreadar/libthreadar.hpp>
36#include <memory>
37#include <list>
38
39 // webdar headers
40#include "body_builder.hpp"
41#include "events.hpp"
42#include "actor.hpp"
43#include "html_form_input.hpp"
44#include "html_form.hpp"
45#include "html_form_radio.hpp"
46#include "html_form_fieldset.hpp"
47#include "html_text.hpp"
48#include "html_button.hpp"
49#include "html_statistics.hpp"
50#include "web_user_interaction.hpp"
51
52
54
57
117
119{
120public:
121 // this class generates the following events:
122 static const std::string display_started;
123 static const std::string can_refresh;
124 static const std::string dont_refresh;
125 static const std::string libdar_has_finished;
126
127 // class constructor assignment ops and destructors
128 html_web_user_interaction(unsigned int x_warn_size = 25);
131 html_web_user_interaction & operator = (const html_web_user_interaction & ref) = delete;
132 html_web_user_interaction & operator = (html_web_user_interaction && ref) noexcept = delete;
134
136 void set_warning_list_size(unsigned int size) { check_libdata(); lib_data->set_warning_list_size(size); };
137
139 virtual void on_event(const std::string & event_name) override;
140
142
147 void auto_hide(bool mode, bool unless_interrupted) { autohide = mode; hide_unless_interrupted = unless_interrupted; };
148
150
154 void clear();
155
157 std::shared_ptr<web_user_interaction> get_user_interaction() { check_libdata(); return lib_data; };
158
160 html_statistics & get_statistics() { stats.set_visible(true); return stats; };
161
163
165 void hide_statistics() { stats.set_visible(false); };
166
168
194 void run_and_control_thread(libthreadar::thread* arg);
195
197
206
208 bool is_libdar_running() const;
209
211 bool has_libdar_been_aborted() const { return was_interrupted; };
212
213
214protected:
216 virtual std::string inherited_get_body_part(const chemin & path,
217 const request & req) override;
218 // inherited from body_builder
219 virtual void new_css_library_available() override;
220
221 // inherited from body_builder
222 virtual void my_visibility_has_changed() override;
223
224
225private:
226 static const std::string class_button;
227 static const std::string class_web;
228 static const std::string class_inter;
229
230 // internal event names (assigned to control buttons and on which we registered)
231 static const std::string ask_end_libdar;
232 static const std::string force_end_libdar;
233 static const std::string close_libdar_screen;
234
235 enum mode_type
236 {
237 normal,
238 end_asked,
239 end_forced,
240 finished,
241 closed
242 };
243
244
245 // fields for exchange with libdar thread
246 std::shared_ptr<web_user_interaction> lib_data;
247
248 // current display mode
249 mode_type mode;
250 bool autohide;
251 bool hide_unless_interrupted;
252 bool was_interrupted;
253
254 bool ignore_event;
255
256 libthreadar::thread* managed_thread; // the thread object we manage (or nullptr if none is managed)
257 mutable libthreadar::condition all_threads_pending;
258
259 // body_builder fields
260 html_form_radio h_pause;
261 html_form_fieldset h_inter;
262 html_text h_inter_text;
263 html_form_fieldset h_gtstr_fs;
264 html_form_input h_get_string;
265 html_form h_form;
266 html_text h_warnings;
267 html_form_fieldset h_logs;
268 html_form_fieldset h_global;
269
270 html_statistics stats;
271 html_button ask_close;
272 html_button force_close;
273 html_text helper_text;
274 html_button finish;
275
276 void adjust_visibility();
277 void check_libdata() { if(!lib_data) throw WEBDAR_BUG; };
278 void set_mode(mode_type m);
279 void update_html_from_libdar_status();
280 void update_controlled_thread_status();
281 void clean_threads_termination(bool force);
282 void trigger_refresh();
283 void check_clean_status();
284};
285
286
287#endif
class of object that are pointed/triggered to by others
Definition: actor.hpp:55
class body_builder is the root class of object generating HTML body
Definition: body_builder.hpp:99
void set_visible(bool mode)
ask for the object to become visible in HTML page or temporarily hidden
Definition: body_builder.cpp:211
unsigned int size() const
access to adopted childs
Definition: body_builder.hpp:395
class chemin definition
Definition: chemin.hpp:51
class events
Definition: events.hpp:52
simple html component providing the usual button feature of GUIs, better using html_double_button ins...
Definition: html_button.hpp:48
class html_form_fieldset implements HTML fieldset feature
Definition: html_form_fieldset.hpp:51
class html_form_input implements HTML input feature
Definition: html_form_input.hpp:57
class html_form_radio implements HTML "input" of type "radio"
Definition: html_form_radio.hpp:53
class html_form implements HTML form feature
Definition: html_form.hpp:51
html component to display libdar returned statistics object
Definition: html_statistics.hpp:47
class html_text manage text and header in html document
Definition: html_text.hpp:52
body_builder component, providing an html interface to libdar::user_interaction
Definition: html_web_user_interaction.hpp:119
static const std::string dont_refresh
last changes forbid html refresh
Definition: html_web_user_interaction.hpp:124
bool has_libdar_been_aborted() const
whether libdar thread has been aborted (to be checked by the caller upon libdar_has_finished event)
Definition: html_web_user_interaction.hpp:211
void clear()
clear counters, logs and reset html interface and make the component become visible if it was not alr...
Definition: html_web_user_interaction.cpp:364
virtual void my_visibility_has_changed() override
available for inherited class to be informed when their visibility changes
Definition: html_web_user_interaction.cpp:424
virtual std::string inherited_get_body_part(const chemin &path, const request &req) override
inherited from body_builder, called by the webdar thread
Definition: html_web_user_interaction.cpp:256
static const std::string can_refresh
last changes makes the object html refreshable
Definition: html_web_user_interaction.hpp:123
void run_and_control_thread(libthreadar::thread *arg)
provide a libdar thread to be managed by this html_web_component (stop actions)
Definition: html_web_user_interaction.cpp:161
virtual void new_css_library_available() override
Definition: html_web_user_interaction.cpp:390
void hide_statistics()
hide statistics fields in the web interface
Definition: html_web_user_interaction.hpp:165
bool is_libdar_running() const
whether a libdar thread is running under "this" management
Definition: html_web_user_interaction.cpp:234
static const std::string display_started
when the object has been set visible
Definition: html_web_user_interaction.hpp:122
static const std::string libdar_has_finished
inform the caller that libdar has finished and user asked to close the "window" (or autohide was set)
Definition: html_web_user_interaction.hpp:125
virtual void on_event(const std::string &event_name) override
inherited from actor
Definition: html_web_user_interaction.cpp:291
void auto_hide(bool mode, bool unless_interrupted)
when the control thread has finished, this html_web_user_interaction object becomes invisible
Definition: html_web_user_interaction.hpp:147
void join_controlled_thread()
let the calling thread suspended until the controlled thread ends (the one passed to run_and_control_...
Definition: html_web_user_interaction.cpp:207
html_statistics & get_statistics()
libdar structure provided for user information
Definition: html_web_user_interaction.hpp:160
void set_warning_list_size(unsigned int size)
change the number of last warnings to display
Definition: html_web_user_interaction.hpp:136
std::shared_ptr< web_user_interaction > get_user_interaction()
libdar strcture provided for user interaction
Definition: html_web_user_interaction.hpp:157
class holding fields of an HTTP request (method, URI, header, cookies, and so on)
Definition: request.hpp:45
defines the event class