Webdar 1.0.0
Web user interface to libdar
html_form_input_file.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_FORM_INPUT_FILE_HPP
25#define HTML_FORM_INPUT_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 <memory>
36
37 // webdar headers
38#include "html_div.hpp"
39#include "events.hpp"
40#include "jsoner.hpp"
41#include "html_form_input.hpp"
42#include "html_double_button.hpp"
43#include "html_select_file.hpp"
44#include "html_text.hpp"
45
47
55
57 public events,
58 public actor,
59 public jsoner
60{
61public:
62
63 static const std::string changed_event;
64 static const std::string changed_entrepot;
65 static const std::string repo_update_needed;
66 static const std::string repo_updated;
67
68 html_form_input_file(const std::string & label,
69 const std::string & initial_value,
70 const std::string & size,
71 const std::string & css_class,
72 const std::string & popup_message);
73
74 html_form_input_file(const html_form_input_file & ref) = delete;
75 html_form_input_file(html_form_input_file && ref) noexcept = delete;
76 html_form_input_file & operator = (const html_form_input_file & ref) = delete;
77 html_form_input_file & operator = (html_form_input_file && ref) noexcept = delete;
78 ~html_form_input_file() = default;
79
80 // relayed from html_form_input
81
82 void change_label(const std::string & label) { input.change_label(label); };
83 const std::string & get_value() const { return input.get_value(); };
84 void set_value(const std::string & val) { input.set_value(val); };
85
87
92 void set_change_event_name(const std::string & name);
93
94 // relayed from html_select_file
95
96 enum select_mode { select_dir, select_file, select_slice, select_symlink };
97
98 void set_select_mode(select_mode val);
99 void set_can_create_dir(bool val) { user_select.set_can_create_dir(val); };
100
102
104 void set_entrepot(std::shared_ptr<libdar::entrepot> entrepot);
105
107
121
143 void set_entrepot_updater(events* updater);
144
146 std::string get_min_digits() const;
147
148 // inherited from events
149
150 virtual void on_event(const std::string & event_name) override;
151
153 virtual void load_json(const json & source) override { input.load_json(source); };
154
156 virtual json save_json() const override { return input.save_json(); };
157
159 virtual void clear_json() override { input.clear_json(); };
160
162 void set_tooltip(const std::string & val) { input.set_tooltip(val); };
163
164protected:
165
166 // inherited from body_builder
167 virtual void new_css_library_available() override;
168 virtual std::string inherited_get_body_part(const chemin & path,
169 const request & req) override;
170
171
172private:
173 std::string changed_event_name;
174 std::shared_ptr<libdar::entrepot> entrep;
175 bool refresh_get_body;
176 select_mode selmode;
177 std::string min_digits;
178 bool internal_change;
179 events* repo_updater;
180
181 // adoption tree:
182 //
183 // html_div (this)
184 // |
185 // +--- input_div
186 // | |
187 // | +- input
188 // +--- trigger
189 // +--- user_select
190 // +--- empty_text
191 //
192
193 html_form_input input;
194 html_div input_div;
195 html_double_button trigger;
196 html_select_file user_select;
197 html_text empty_text;
198
199
200 std::string slicename_to_basename_update_min_digits(const std::string & val);
201
202 static const std::string triggered_event;
203
204 static const std::string css_input;
205 static const std::string css_button_box;
206};
207
208
209#endif
class of object that are pointed/triggered to by others
Definition: actor.hpp:55
class chemin definition
Definition: chemin.hpp:51
class css_class gather css attributed under a given label
Definition: css_class.hpp:51
class events
Definition: events.hpp:52
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_input_file provides a mean to the user to navigate in a file system to select a file ...
Definition: html_form_input_file.hpp:60
std::string get_min_digits() const
in select_slice mode, obtain the min-digits from the provided filename
Definition: html_form_input_file.cpp:154
virtual void on_event(const std::string &event_name) override
implementation in inherited class of the action triggered by the event given in argument
Definition: html_form_input_file.cpp:162
void set_entrepot(std::shared_ptr< libdar::entrepot > entrepot)
change the entrepot to search into (if not called, local file system is used)
Definition: html_form_input_file.cpp:138
virtual void clear_json() override
inherited from jsoner
Definition: html_form_input_file.hpp:159
void set_change_event_name(const std::string &name)
change the name of the "changed" event
Definition: html_form_input_file.cpp:106
static const std::string changed_entrepot
triggered once the entrepot has been modified by mean of set_entrepot() method
Definition: html_form_input_file.hpp:64
static const std::string repo_updated
triggered by the events object passed to set_entrepot_updater() after calling set_entrepot() method o...
Definition: html_form_input_file.hpp:66
static const std::string repo_update_needed
triggered when user clicked on the '+' button to browse the entrepot if set_entrepot_updater() has be...
Definition: html_form_input_file.hpp:65
static const std::string changed_event
triggered (unless the event name is modified) when the field name is modified
Definition: html_form_input_file.hpp:63
virtual json save_json() const override
inherited from jsoner
Definition: html_form_input_file.hpp:156
virtual void load_json(const json &source) override
inherited from jsoner
Definition: html_form_input_file.hpp:153
virtual std::string inherited_get_body_part(const chemin &path, const request &req) override
inherited from body_builder
Definition: html_form_input_file.cpp:249
void set_entrepot_updater(events *updater)
Definition: html_form_input_file.cpp:146
void set_tooltip(const std::string &val)
tooltip for the component
Definition: html_form_input_file.hpp:162
virtual void new_css_library_available() override
inherited from body_builder
Definition: html_form_input_file.cpp:221
class html_form_input implements HTML input feature
Definition: html_form_input.hpp:57
virtual void clear_json() override
inherited from jsoner
Definition: html_form_input.cpp:217
void set_tooltip(const std::string &msg)
set tooltip for the html label of the input form
Definition: html_form_input.hpp:122
virtual json save_json() const override
inherited from jsoner
Definition: html_form_input.cpp:206
virtual void load_json(const json &source) override
inherited from jsoner
Definition: html_form_input.cpp:179
class html_select_file
Definition: html_select_file.hpp:110
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
class html_text manage text and header in html document
Definition: html_text.hpp:52
class jsoner
Definition: jsoner.hpp:73
unsigned int size() const
the number of peers
Definition: reference.hpp:97
class holding fields of an HTTP request (method, URI, header, cookies, and so on)
Definition: request.hpp:45
defines the event class
defines html_select_file class
defines jsoner class and class exception_json