Webdar 1.0.0
Web user interface to libdar
html_select_file.hpp
Go to the documentation of this file.
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_SELECT_FILE_HPP
25#define HTML_SELECT_FILE_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 <map>
36#include <dar/libdar.hpp>
37#include <memory>
38#include <libthreadar/libthreadar.hpp>
39
40 // webdar headers
41#include "events.hpp"
42#include "actor.hpp"
43#include "html_div.hpp"
44#include "html_text.hpp"
45#include "html_form_fieldset.hpp"
46#include "html_button.hpp"
47#include "html_double_button.hpp"
48#include "html_table.hpp"
49#include "html_popup.hpp"
50#include "html_form.hpp"
51#include "html_form_input.hpp"
52#include "html_web_user_interaction.hpp"
53
54
56
57
59
78
109class html_select_file: public html_popup, public events, public actor, public libthreadar::thread_signal
110{
111public:
113 static const std::string entry_selected;
114
116 static const std::string op_cancelled;
117
119 {
123 };
124
126
128 html_select_file(const std::string & message);
129
130 html_select_file(const html_select_file & ref) = delete;
131 html_select_file(html_select_file && ref) noexcept(false) = delete;
132 html_select_file & operator = (const html_select_file & ref) = delete;
133 html_select_file & operator = (html_select_file && ref) noexcept(false) = delete;
134 virtual ~html_select_file() { clear_content(); cancel(); join(); };
135
137
139 void set_select_mode(select_mode val) { if(status != st_init) throw WEBDAR_BUG; cur_select_mode = val; };
140
142
144 void set_can_create_dir(bool val) { if(status != st_init) throw WEBDAR_BUG; btn_createdir.set_visible(val); };
145
149 void set_filter(const std::string & mask) { filter = mask; };
150
152
157 void go_select(const std::shared_ptr<libdar::entrepot> & x_entr,
158 const std::string & start_dir);
159
161 std::string get_selected_path() const { if(status != st_completed) throw WEBDAR_BUG; status = st_init; return fieldset.get_label(); };
162
164 virtual void on_event(const std::string & event_name) override;
165
167 std::string get_message() const { return x_message; };
168
169protected:
170
172 virtual std::string inherited_get_body_part(const chemin & path,
173 const request & req) override;
174
176 virtual void new_css_library_available() override;
177
179 virtual void inherited_run() override;
180
182 virtual void signaled_inherited_cancel() override;
183
184private:
185 // event name for the 'change to parent directory' button (parentdir)
186 static const std::string op_chdir_parent;
187 static const std::string op_createdir;
188 static const std::string op_hide_createdir;
189
190 // internal css class names
191 static const std::string css_sticky_top;
192 static const std::string css_sticky_bot;
193
194 // popup size of browser windows
195 static constexpr const unsigned int width_pct = 80;
196 static constexpr const unsigned int height_pct = 80;
197
198
200 struct item
201 {
202 html_button* btn;
203 libdar::inode_type type;
204 libdar::inode_type target_type;
205 item() { btn = nullptr; type = target_type = libdar::inode_type::unknown; };
206 item(html_button* ptr) { btn = ptr; type = target_type = libdar::inode_type::unknown; };
207 };
208
209
210 // object status
211
212 libthreadar::mutex content_mutex;
213
214 mutable enum
215 {
216 st_init,
217 st_go_select,
218 st_completed
219 } status;
220
221 enum thread_to_run
222 {
223 run_nothing,
224 run_create_dir,
225 run_init_fill,
226 run_fill_only
227 };
228
229 mutable thread_to_run which_thread;
230
231 // status field about html components
232 bool is_loading_mode;
233 bool new_warning;
234 libdar::inode_type fieldset_target_type;
235 libdar::inode_type fieldset_type;
236
237 // settings
238 std::string x_message;
239 select_mode cur_select_mode;
240 std::string filter;
241 bool should_refresh;
242 std::shared_ptr<libdar::entrepot> entr;
243 std::shared_ptr<libdar::user_interaction> mem_ui;
244
245 // html components
246
247 html_text title;
248 html_text entrepot_url;
249 html_text warning;
251 html_div title_box;
252 html_form_fieldset fieldset;
253
254 //
255 std::string path_loaded;
256 std::map<std::string, item> listed;
257 html_double_button parentdir;
258 html_text content_placeholder;
259 bool need_reload_content;
260 html_table content;
261
262 html_div btn_box;
263 html_button btn_cancel;
264 html_button btn_validate;
265 html_button btn_createdir;
266 html_button btn_hide_createdir;
267 html_form createdir_form;
268 html_form_input createdir_input;
269
270
271
272 // internal routines
273
276 bool init_fieldset_target_type();
277
279 void fill_content();
280
282 void create_dir();
283
285 void add_content_entry(const std::string & event_name,
286 libdar::inode_type tp,
287 libdar::inode_type target_tp,
288 const std::string & entry);
289
291
293 void run_thread(thread_to_run val);
294
296 void clear_content();
297
299
302 void loading_mode(bool mode);
303
305 static std::string get_parent_path(const std::string & somepath);
306
308
312 void my_closing();
313
315 bool is_a_valid_dir(const std::string & pathval, const std::string & name) const;
316
318 void update_entrepot_url();
319
320};
321
322#endif
class of object that are pointed/triggered to by others
Definition: actor.hpp:55
void set_visible(bool mode)
ask for the object to become visible in HTML page or temporarily hidden
Definition: body_builder.cpp:211
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_div is the implementation of
Definition: html_div.hpp:46
html_button equivalent with changing path to trigger the button event
Definition: html_double_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 implements HTML form feature
Definition: html_form.hpp:51
class html_popup is the implementation of
Definition: html_popup.hpp:50
class html_select_file
Definition: html_select_file.hpp:110
void go_select(const std::shared_ptr< libdar::entrepot > &x_entr, const std::string &start_dir)
start the user interaction for a path selection
Definition: html_select_file.cpp:158
html_select_file(const std::string &message)
constructor
Definition: html_select_file.cpp:59
std::string get_message() const
returns the message argument passed at construction time
Definition: html_select_file.hpp:167
virtual std::string inherited_get_body_part(const chemin &path, const request &req) override
inherited from body_builder (via html_div)
Definition: html_select_file.cpp:353
static const std::string op_cancelled
event when the user cancelled file selection
Definition: html_select_file.hpp:116
select_mode
Definition: html_select_file.hpp:119
@ sel_file
only non dir and symlinks and non symlink should be selectable
Definition: html_select_file.hpp:120
@ sel_symlinks
only symlinks should be selectable
Definition: html_select_file.hpp:122
@ sel_dir
only directories and symlinks pointing to dir
Definition: html_select_file.hpp:121
virtual void signaled_inherited_cancel() override
inherited from libthreadar::thread
Definition: html_select_file.cpp:720
void set_filter(const std::string &mask)
Definition: html_select_file.hpp:149
std::string get_selected_path() const
obtain the path selected by the user (mandatory after entry_selected event, in order to reuse this ob...
Definition: html_select_file.hpp:161
void set_can_create_dir(bool val)
whether to show the button allowing the user to create a subdirectory
Definition: html_select_file.hpp:144
static const std::string entry_selected
event when user selected a file
Definition: html_select_file.hpp:113
void set_select_mode(select_mode val)
ask the user to select a file path (false) or a directory path (true)
Definition: html_select_file.hpp:139
virtual void on_event(const std::string &event_name) override
action triggered from html_buttons internally used in this class implementation (do not use,...
Definition: html_select_file.cpp:189
virtual void inherited_run() override
inherited from libthreadar::thread
Definition: html_select_file.cpp:447
virtual void new_css_library_available() override
inherited from body_builder (via html_div)
Definition: html_select_file.cpp:405
html component implementing the html table structure
Definition: html_table.hpp:52
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
class holding fields of an HTTP request (method, URI, header, cookies, and so on)
Definition: request.hpp:45
defines the event class