diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 6449680..1223788 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -28,6 +28,8 @@ set(SOURCE_FILES my_process.cc util.h util.cc + my_plug.h + my_plug.cc ubl-util-standard.h ubl-util-standard.c main.cc) diff --git a/source/main.cc b/source/main.cc index a0ef5e8..3426bf9 100644 --- a/source/main.cc +++ b/source/main.cc @@ -1,5 +1,5 @@ #include "ubl-settings-quotas.h" - +#include "my_plug.h" void pars_flag(int index_start, int argc, char* argv[]); diff --git a/source/my_plug.cc b/source/my_plug.cc new file mode 100644 index 0000000..db266d9 --- /dev/null +++ b/source/my_plug.cc @@ -0,0 +1,41 @@ +#ifndef MY_PLUG_H +#define MY_PLUG_H + +#include "my_plug.h" +#include "ubl-settings-quotas.h" + + + + +CmdArgParser::CmdArgParser(const std::string& p_name, const std::string& p_description, const std::string& p_help) +: Glib::OptionGroup{p_name, p_description, p_help} { + Glib::OptionEntry socketIDArg; + socketIDArg.set_long_name("socket-id"); + socketIDArg.set_flags(Glib::OptionEntry::FLAG_IN_MAIN); + socketIDArg.set_description("Settings manager socket"); + Glib::OptionEntry socketExtId; + socketExtId.set_long_name("socket-ext-id"); + socketExtId.set_flags(Glib::OptionEntry::FLAG_IN_MAIN); + socketExtId.set_description("Settings manager secondary socket"); + Glib::OptionEntry socketTrdId; + socketTrdId.set_long_name("socket-trd-id"); + socketTrdId.set_flags(Glib::OptionEntry::FLAG_IN_MAIN); + socketTrdId.set_description("Settings manager secondary socket"); + add_entry(socketIDArg, m_socketID); + add_entry(socketExtId, socket_ext_id_I); + add_entry(socketTrdId, socket_trd_id_I); +} +::Window CmdArgParser::GetSocketID() const{ + return m_socketID; +} + +SettingsPlug::SettingsPlug(::Window p_socketID, Glib::RefPtr builder) + :Gtk::Plug{p_socketID} { + MainWindow* wnd = nullptr; + builder->get_widget_derived("window", wnd); + builder->get_widget("plugBox", plugBox); + plugBox->get_parent()->remove(*plugBox); + add(*plugBox); + show_all_children(); +} +#endif \ No newline at end of file diff --git a/source/my_plug.h b/source/my_plug.h new file mode 100644 index 0000000..7b98857 --- /dev/null +++ b/source/my_plug.h @@ -0,0 +1,20 @@ +#include "project_lib.h" + + +class CmdArgParser : public Glib::OptionGroup { +public: + CmdArgParser(const std::string& p_name, const std::string& p_description, const std::string& p_help); + ::Window GetSocketID() const; +private: + int m_socketID = 0; + +}; +class SettingsPlug : public Gtk::Plug{ +public: + Gtk::Window *window; + SettingsPlug(::Window p_socketID, Glib::RefPtr builder); + +private: + Gtk::Widget *plugBox; + Gtk::Widget *parent; +}; \ No newline at end of file diff --git a/source/my_type.h b/source/my_type.h index 7431181..f92948e 100644 --- a/source/my_type.h +++ b/source/my_type.h @@ -1,11 +1,28 @@ #ifndef MY_TYPE_H #define MY_TYPE_H -#include -#include +#include "project_lib.h" + +using namespace std; + typedef unsigned long max_num_T; -tuple tuple_user_grups; +struct users_grups{ + string name; + bool state; + max_num_T size_data; + max_num_T soft_limit_size; + max_num_T severe_restriction_size; + max_num_T postponement_size_brat; + max_num_T hard_limit_activation_time_size; + max_num_T file; + max_num_T soft_file_limitation; + max_num_T hard_file_restriction; + max_num_T postponement_hard_file_restriction; + max_num_T hard_limit_activation_time; + }; +typedef struct users_grups USER_GRUPS; +typedef map map_str_str; +typedef map * map_s_s_ptr; #endif \ No newline at end of file diff --git a/source/project_lib.h b/source/project_lib.h index 907db55..da1025e 100644 --- a/source/project_lib.h +++ b/source/project_lib.h @@ -2,38 +2,23 @@ #define PROJECT_LIB_H #include -#include #include -#include #include #include #include #include -#include -#include #include #include #include -#include -#include -#include -#include #include #include -#include -#include #include #include -#include #include -#include -#include -#include #include #include #include #include -#include #include #include #include diff --git a/source/ubl-settings-quotas.cc b/source/ubl-settings-quotas.cc index 665d2ae..4e869d8 100755 --- a/source/ubl-settings-quotas.cc +++ b/source/ubl-settings-quotas.cc @@ -11,29 +11,8 @@ const string path_img_head_background = "/usr/share/ubl-settings-quotas/images/l int socket_ext_id_I = 0; int socket_trd_id_I = 0; -string version_application = "1.0"; -CmdArgParser::CmdArgParser(const std::string& p_name, const std::string& p_description, const std::string& p_help) -: Glib::OptionGroup{p_name, p_description, p_help} { - Glib::OptionEntry socketIDArg; - socketIDArg.set_long_name("socket-id"); - socketIDArg.set_flags(Glib::OptionEntry::FLAG_IN_MAIN); - socketIDArg.set_description("Settings manager socket"); - Glib::OptionEntry socketExtId; - socketExtId.set_long_name("socket-ext-id"); - socketExtId.set_flags(Glib::OptionEntry::FLAG_IN_MAIN); - socketExtId.set_description("Settings manager secondary socket"); - Glib::OptionEntry socketTrdId; - socketTrdId.set_long_name("socket-trd-id"); - socketTrdId.set_flags(Glib::OptionEntry::FLAG_IN_MAIN); - socketTrdId.set_description("Settings manager secondary socket"); - add_entry(socketIDArg, m_socketID); - add_entry(socketExtId, socket_ext_id_I); - add_entry(socketTrdId, socket_trd_id_I); -} -::Window CmdArgParser::GetSocketID() const{ - return m_socketID; -} +string version_application = "1.0"; MainWindow::MainWindow(BaseObjectType* obj, Glib::RefPtr const& builder) : Gtk::ApplicationWindow(obj), builder{builder} { @@ -89,10 +68,10 @@ void MainWindow::lacalization() { UsersTabLabel->set_text(_("Users")); generalDeviceLabel->set_text(_("Device:")); generalFileSystemLabel->set_text(_("File system:")); - generalGroupsFrameLabel->set_text(_("quotas for groups")); + generalGroupsFrameLabel->set_text(_("Quotas for groups")); generalGroupsEnableCheck->set_label(_("Enable")); generalUsersEnableCheck->set_label(_("Enable")); - generalUsersFrameLabel->set_label(_("quotas for users")); + generalUsersFrameLabel->set_label(_("Quotas for users")); generalGroupsSizeLabel->set_text(_("Excess size delay period")); generalGroupsFilesLabel->set_text(_("Excess files delay period")); generalUsersSizeLabel->set_text(_("Excess size delay period")); @@ -346,14 +325,144 @@ void MainWindow::info_status_app(string stule) { boxInfo->add_class(stule); } -SettingsPlug::SettingsPlug(::Window p_socketID, Glib::RefPtr builder) - :Gtk::Plug{p_socketID} { - MainWindow* wnd = nullptr; - builder->get_widget_derived("window", wnd); - builder->get_widget("plugBox", plugBox); - plugBox->get_parent()->remove(*plugBox); - add(*plugBox); - show_all_children(); +void MainWindow::init_dict(string flag_load) { + std::map map_gui_cfg_n; + map_gui_cfg_n[""] = ""; + + map_gui_cfg = map_gui_cfg_n; + if (flag_load == "global") { + map_global_cfg = map_gui_cfg_n; + } + else if (flag_load == "system") { + map_system_cfg = map_gui_cfg_n; + } +} + +bool MainWindow::save_template(string section, string flag_save) { + bool flag_no_save = true; + obj_save.set_data_local(map_system_cfg); + obj_save.set_data_global(map_global_cfg); + obj_save.set_data_gui(map_gui_cfg); + obj_save.set_vec_params(vec_param_names); + obj_save.save(section, flag_save); + vector obj_vec_error = obj_save.get_error(); + flag_no_save = obj_save.get_state_save(); + return flag_no_save; +} + +void MainWindow::wrapper_save_all_cfg() { + this->set_data_cfg(); + bool _flag_save_global = this->save_template("boot", "global");; + bool _flag_save_local = this->save_template("boot", "system"); + if (_flag_save_global && _flag_save_local) { + this->info_warning_error(5); + } + else { + info_warning_error(4); + } + map_global_cfg = map_gui_cfg; + map_system_cfg = map_gui_cfg; + +} + +void MainWindow::load_global_cfg() { + this->load_template(&map_global_cfg, "global"); + info_warning_error(1); + map_gui_cfg = map_global_cfg; +} + +void MainWindow::load_system_cfg() { + this->load_template(&map_system_cfg, "system"); + info_warning_error(0); + map_gui_cfg = map_system_cfg; +} + +void MainWindow::set_data_cfg() { + // TODO: + // Написать функцию +} +void MainWindow::wrapper_save_global_cfg() { + this->set_data_cfg(); + if (this->save_template("boot", "global")) { + this->info_warning_error(5); + } + else { + info_warning_error(3); + } + map_global_cfg = map_gui_cfg; + +} + +void MainWindow::wrapper_save_local_cfg() { + this->set_data_cfg(); + if (this->save_template("boot", "system")) { + this->info_warning_error(5); + } + else { + info_warning_error(2); + } + map_system_cfg = map_gui_cfg; +} + +void MainWindow::load_template(map_str_str* map_temp, string str_load) { + this->init_dict(str_load); + string sections; + sections = "boot"; + obj_load.set_sections(sections); + *map_temp = obj_load.get_load_data(*map_temp, str_load); +} + +void MainWindow::info_warning_error(int mess) { + if (obj_load.get_count_error() > 0 || obj_save.get_count_error() > 0) { + info_status_app("boxInfoMessError"); + imgInfo->set_from_icon_name("com.ublinux.ubl-settings-bootloader.warning", Gtk::ICON_SIZE_MENU); + string mess_error = ""; + if (mess == 0) { + mess_error = string(_("Local configuration reading error")) + str_cmd_error; + lblWarning->set_text(mess_error); + } + else if (mess == 1) { + mess_error = string(_("Global configuration read error")) + str_cmd_error; + lblWarning->set_text(mess_error); + } + else if (mess == 2) { + mess_error = string(_("Local configuration write error")) + str_cmd_error; + lblWarning->set_text(mess_error); + } + else if (mess == 3) { + mess_error = string(_("Global configuration write error")) + str_cmd_error; + lblWarning->set_text(mess_error); + } + else if (mess == 4) { + mess_error = string(_("Error saved local and global configuration")) + str_cmd_error; + lblWarning->set_text(mess_error); + } + str_cmd_error = ""; + obj_load.set_count_error(0); + obj_save.set_count_error(0); + } + else { + info_status_app("boxInfoMessOK"); + imgInfo->set_from_icon_name("com.ublinux.ubl-settings-bootloader.checked", Gtk::ICON_SIZE_MENU); + if (mess == 0) { + lblWarning->set_text(_("Local configuration downloaded successfully")); + } + else if (mess == 1) { + lblWarning->set_text(_("Global configuration downloaded successfully")); + } + else if (mess == 2) { + lblWarning->set_text(_("Local configuration successfully written")); + } + else if (mess == 3) { + lblWarning->set_text(_("Global configuration successfully written")); + } + else if (mess == 4) { + lblWarning->set_text(_("Successfully saved local and global configuration")); + } + else if (mess == 5) { + lblWarning->set_text(_("Nothing to save!")); + } + } } void help() { diff --git a/source/ubl-settings-quotas.h b/source/ubl-settings-quotas.h index b953ff4..b3ba81a 100644 --- a/source/ubl-settings-quotas.h +++ b/source/ubl-settings-quotas.h @@ -2,8 +2,15 @@ #define UBL_SETTINGS_QUOTAS_H #include "util.h" +#include "load.h" +#include "save.h" +#include "my_process.h" +#include "my_type.h" +extern int socket_ext_id_I; +extern int socket_trd_id_I; + using namespace std; extern const string path_app; @@ -12,17 +19,10 @@ extern const string app_name; extern const string path_locale; extern const string path_css; extern const string path_img_head_background; -extern int socket_ext_id_I; -extern int socket_trd_id_I; + extern string version_application; -class CmdArgParser : public Glib::OptionGroup { -public: - CmdArgParser(const std::string& p_name, const std::string& p_description, const std::string& p_help); - ::Window GetSocketID() const; -private: - int m_socketID = 0; -}; + class MainWindow : public Gtk::ApplicationWindow { public: @@ -155,7 +155,20 @@ class MainWindow : public Gtk::ApplicationWindow { Gtk::Label *quotegroupSizeSoftLimitLabel; Gtk::Label *quoteuserFilesSoftLimitlabel; Gtk::Window *QuotasUserEditWindow; - Gtk::Window *QuotasEditWindow; + Gtk::Window *QuotasEditWindow; + + public: + Lib_save::Save obj_save = Lib_save::Save(); + Lib_Load::Load obj_load = Lib_Load::Load(); + vector vec_param_names; + My_Process::My_Process_system obj_process_system = My_Process::My_Process_system(); + My_Process::My_Process_call obj_process_call = My_Process::My_Process_call(); + map_str_str map_gui_cfg; + map_str_str map_global_cfg; + map_str_str map_system_cfg; + + string str_cmd_error; + public: MainWindow(BaseObjectType* obj, Glib::RefPtr const& builder); MainWindow(Glib::RefPtr const& builder); @@ -167,19 +180,20 @@ class MainWindow : public Gtk::ApplicationWindow { void info_status_app(string stule); void groupsFilters_show(); void init_tree_view(); + void load_template(map_str_str* map_temp, string str_load); + void info_warning_error(int mess); + void wrapper_save_local_cfg(); + void wrapper_save_global_cfg(); + void wrapper_save_all_cfg(); + void init_dict(string flag_load); + void set_data_cfg(); + void load_global_cfg(); + void load_system_cfg(); + bool save_template(string section, string flag_save); void view_add_columns(Gtk::TreeView &treeView); }; -class SettingsPlug : public Gtk::Plug{ -public: - Gtk::Window *window; - SettingsPlug(::Window p_socketID, Glib::RefPtr builder); - -private: - Gtk::Widget *plugBox; - Gtk::Widget *parent; -}; void help(); #endif diff --git a/ubl-settings-quotas.glade b/ubl-settings-quotas.glade index 7e731f6..56c9797 100644 --- a/ubl-settings-quotas.glade +++ b/ubl-settings-quotas.glade @@ -742,7 +742,7 @@ - 135 + 0 True False 5 @@ -756,6 +756,24 @@ 2 + + + True + False + 5 + 5 + 5 + 5 + 6 + 6 + **** + + + False + True + 3 + + False @@ -1205,7 +1223,7 @@ True False - quotas for groups + Quotas for groups 0 @@ -1659,7 +1677,7 @@ True False - quotas for users + Quotas for users 0 @@ -1733,6 +1751,24 @@ 2 + + + True + False + 5 + 5 + 5 + 5 + 6 + 6 + **** + + + False + True + 3 + + Filters @@ -1743,7 +1779,7 @@ False True - 3 + 4 @@ -1835,6 +1871,24 @@ 2 + + + True + False + 5 + 5 + 5 + 5 + 6 + 6 + **** + + + False + True + 3 + + Filters @@ -1845,7 +1899,7 @@ False True - 3 + 4 @@ -2157,8 +2211,8 @@ False - UBConfig - Quotas - com.ublinux.ubl-settings-quotas + start + False True @@ -2698,6 +2752,22 @@ + + + True + False + UBConfig - Quotas + + + True + False + 32 + com.ublinux.ubl-settings-quotas + 5 + + + + 1000000 @@ -2721,8 +2791,8 @@ False - UBConfig - Quotas - com.ublinux.ubl-settings-quotas + start + False True @@ -3268,5 +3338,21 @@ + + + True + False + UBConfig - Quotas + + + True + False + 32 + com.ublinux.ubl-settings-quotas + 5 + + + + diff --git a/ubl-settings-quotas_ru.po b/ubl-settings-quotas_ru.po index e2975c4..92410aa 100644 --- a/ubl-settings-quotas_ru.po +++ b/ubl-settings-quotas_ru.po @@ -368,13 +368,13 @@ msgstr "имя" #: source/ubl-settings-quotas.cc:92 source/ubl-settings-quotas.cc:89 #: source/ubl-settings-quotas.cc:86 source/ubl-settings-quotas.cc:85 -msgid "quotas for groups" -msgstr "квоты для групп" +msgid "Quotas for groups" +msgstr "Квоты для групп" #: source/ubl-settings-quotas.cc:95 source/ubl-settings-quotas.cc:92 #: source/ubl-settings-quotas.cc:89 source/ubl-settings-quotas.cc:88 -msgid "quotas for users" -msgstr "квоты для пользователей" +msgid "Quotas for users" +msgstr "Квоты для пользователей" #: source/ubl-settings-quotas.cc:350 source/ubl-settings-quotas.cc:371 #: source/ubl-settings-quotas.cc:318 source/ubl-settings-quotas.cc:267