Webdar 1.0.0
Web user interface to libdar
html_size_unit.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_SIZE_UNIT_HPP
25#define HTML_SIZE_UNIT_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 <dar/libdar.hpp>
36
37 // webdar headers
38#include "html_form_select.hpp"
39#include "html_div.hpp"
40
42
43class html_size_unit : public html_div, public actor, public events
44{
45public:
46 static const std::string changed;
47
49 html_size_unit(const html_size_unit & ref) = delete;
50 html_size_unit(html_size_unit && ref) noexcept = delete;
51 html_size_unit & operator = (const html_size_unit & ref) = delete;
52 html_size_unit & operator = (html_size_unit && ref) noexcept = delete;
53 ~html_size_unit() = default;
54
56 libdar::infinint get_value() const;
57
59 std::string get_string() const { return unit.get_selected_id(); };
60
62 unsigned int get_max_base_unit_index() const { return SI_mode.num_choices() - 1; };
63
65 unsigned int get_current_base_index() const { return SI_mode.get_selected_num(); };
66
68
70 libdar::infinint get_base_unit_value(unsigned int index) const;
71
73
75 unsigned int get_max_power_for_base_unit(unsigned int index) const;
76
78 unsigned int get_current_power_for_base_unit() const { return unit.get_selected_num(); };
79
80
82 void set_unit_and_ratio_indexes(unsigned int base_index, unsigned int power_index);
83
85 void set_enabled(bool val) { unit.set_enabled(val); SI_mode.set_enabled(val); };
86
87
89 virtual void on_event(const std::string & event_name) override;
90
91
92private:
93 static constexpr const char* mode_changed = "SI_mode changed";
94
95 bool manual_change;
97 html_form_select SI_mode;
98
99 void set_fields();
100};
101
102#endif
class of object that are pointed/triggered to by others
Definition: actor.hpp:55
class events
Definition: events.hpp:52
class html_div is the implementation of
Definition: html_div.hpp:46
const std::string & get_selected_id() const
obtain the id of the selected radio button
Definition: html_form_radio.cpp:122
const unsigned int num_choices() const
the number of currently available options
Definition: html_form_radio.hpp:108
unsigned int get_selected_num() const
obtain the index (starts at zero) of the selected radio button
Definition: html_form_radio.hpp:93
class html_form_select implements HTML input of type "select"
Definition: html_form_select.hpp:53
void set_enabled(bool val)
set whether the HTML control is enable or disabled
Definition: html_form_select.cpp:68
html component in a form a couple of dropdown list for user to define a size in byte or larger units
Definition: html_size_unit.hpp:44
libdar::infinint get_value() const
return the unit factor as integer
Definition: html_size_unit.cpp:67
unsigned int get_max_base_unit_index() const
get the max base unit index (index starts at zero)
Definition: html_size_unit.hpp:62
unsigned int get_current_base_index() const
get current base index
Definition: html_size_unit.hpp:65
void set_unit_and_ratio_indexes(unsigned int base_index, unsigned int power_index)
change the selected base unit and factor programmatically
Definition: html_size_unit.cpp:117
std::string get_string() const
return the unit label
Definition: html_size_unit.hpp:59
virtual void on_event(const std::string &event_name) override
actor inheritance
Definition: html_size_unit.cpp:162
libdar::infinint get_base_unit_value(unsigned int index) const
get value of the base unit of given index
Definition: html_size_unit.cpp:84
unsigned int get_max_power_for_base_unit(unsigned int index) const
get the max power available for the base unit of given index
Definition: html_size_unit.cpp:103
void set_enabled(bool val)
whether the HTML control is enable or disabled
Definition: html_size_unit.hpp:85
unsigned int get_current_power_for_base_unit() const
get the current power selected
Definition: html_size_unit.hpp:78