You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ubl-settings-diskquota/source/ubl-settings-diskquota.h

448 lines
21 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#ifndef UBL_SETTINGS_QUOTAS_H
#define UBL_SETTINGS_QUOTAS_H
#include "util.h"
#include "load.h"
#include "save.h"
#include "my_process.h"
#include "my_type.h"
#include "my_device.h"
#include "system_quotas.h"
#include "ubconfig_quotas.h"
#include <dlfcn.h>
#include "ubl-settings-diskquota-cm.h"
#ifdef WEBKIT_FOUND
#include <webkit2/webkit2.h>
#endif
#define copyright _("Copyright © UBSoft LLC, 2022 - ")
#define name_app _("ubl-settings-diskquota")
#define website _("https://wiki.ublinux.com")
#define project_Home_page _("Project Home Page")
#define configuring_system_boot _("Configuring system boot parameters")
#define system_boot _("System boot")
#define str_about _("About ubl-settings-diskquota")
#define command_line_parameters _("Command line parameters:")
#define load_default _("Load default:")
#define seconds _("seconds")
#define download_menu _("Download menu")
#define terminal_for_input _("Terminal for input")
#define terminal_for_output _("Terminal for output")
#define boot_selection_menu_timer _("Boot selection menu timer")
#define str_help _("Help")
#define str_about_1 _("About")
#define str_save_local _("Save")
#define str_load_local _("Load")
#define save_all _("Save in global and local configuration")
#define save_local _("Save in local configuration")
#define save_global _("Save in global configuration")
#define load_global _("Load global configuration")
#define load_local _("Load local configuration")
#define read_online _("Read online")
#define cancel _("Cancel")
#define always_redirect _("Always redirect")
#define boot_screen_display_mode _("Boot screen display mode:")
#define no_loading_animation _("No loading animation, full log")
#define boot_menu_user_name _("Boot menu user name:")
#define boot_menu_user_password _("Boot menu user password:")
#define last_successful_upload _("Last successful upload")
#define read_documentation_web _("Would you like to read documentation in the Web?")
#define redirected_documentation _("You will be redirected to documentation site, where user help pages are ""translated and supported by community.")
#define local_read_error _("Local configuration reading error")
#define global_read_error _("Global configuration read error")
#define local_write_error _("Local configuration write error")
#define global_write_error _("Global configuration write error")
#define error_save_all _("Error saved local and global configuration")
#define local_load_ok _("Local configuration downloaded successfully")
#define global_load_ok _("Global configuration downloaded successfully")
#define local_ok_written _("Local configuration successfully written")
#define global_ok_written _("Global configuration successfully written")
#define successfully_save_all _("Successfully saved local and global configuration")
#define nothing_save _("Nothing to save!")
#define program_as_root _("The program must be run as root")
#define str_weeks _("weeks")
#define str_days _("days")
#define str_hours _("hours")
#define str_minutes _("minutes")
#define str_device _("Device:")
#define str_setting_user _("Setting user quotas")
#define str_users _("Users")
#define str_groups _("Groups")
#define str_files _("files")
#define str_hard_limit _("Hard limit")
#define str_file_system _("File system:")
#define str_name _("Name")
#define str_size _("Size")
#define str_quotas_mode _("Direct control of the file system")
#define str_lb_head _("Configuration of disk quotas parameters for system groups and users")
#define str_soft_limit _("Soft limit")
#define str_currently_using _("Currently using:")
#define str_currently_using_space _("Currently using: ")
#define str_filters _("Filters")
#define str_quotas _("Quotas")
#define str_help_h _("GTK settings disk quota for UBLinux\n" \
"\n" \
"Usage: ubl-settings-diskquota [OPTIONS...]\n" \
"Options:\n" \
" -h, --help\t Show this help\n" \
" -V, --version\t Show package version\n" \
" --lock-help Lock utility help\n" \
" --lock-save Lock saving local and global configuration\n" \
" --lock-save-local Lock save global configuration\n" \
" --lock-save-global Lock load global configuration\n" \
" --lock-load-global Lock load global configuration\n")
#define str_version _("ubl-settings-diskquota version: ")
#define str_user _("User")
#define str_group _("Group")
#define str_projects _("Projects")
#define str_user_1 _("User:")
#define str_group_1 _("Group:")
#define str_project_1 _("Projects:")
#define str_device_project _("Device\nProject")
#define str_quota _("Quota type")
#define str_status _("Status")
#define str_excess_size_delay _("Excess size delay period")
#define str_excess_files_delay _("Excess files delay period")
#define str_disk_quotas_device _("Disk quotas for this device:")
#define str_user_quotas_device _("User quotas for this device: ")
#define str_soft_limit_size _("Soft limit (size)")
#define str_tw_soft_limit _("Soft limit\n(size)")
#define str_hard_limit_size _("Hard limit (size)")
#define str_deferring_hard_limit_size _("Deferring a hard limit (size)")
#define str_hard_activation_size _("Hard limit activation time (size)")
#define str_hard_limit_time _("Hard limit (file) activation time")
#define str_group_quotas_device _("Group quotas for this device:")
#define str_general_settings _("General settings")
#define str_tw_severe_limitation _("Severe\nlimitation\n(size)")
#define str_tw_general_deferring_size _("Deferring\n(size)")
#define str_tw_general_deferring_files _("Deferring\n(files)")
#define str_tw_deferring_size _("Deferring\na hard\nlimit\n(files)")
#define str_tw_deferring_files _("Deferring\na hard\nlimit\n(files)")
#define str_tw_soft_limit_files _("Soft limit\n(files)")
#define str_tw_severe_limitation_files _("Severe\nlimitation\n(files)")
#define str_soft_restriction_files _("Soft Restriction (files)")
#define str_severe_limitation_files _("Severe limitation (files)")
#define str_deferring_limit_files _("Deferring a hard limit (files)")
#define info_box_ok_css "boxInfoMessOK"
#define info_box_error_css "boxInfoMessError"
#define icon_checked "com.ublinux.ubl-settings-diskquota.checked"
#define icon_warning "com.ublinux.ubl-settings-diskquota.warning"
#define link_doc "https://wiki.ublinux.com/ru/Программное_обеспечениерограммы_и_утилиты/Все/ubl-settings-diskquota"
#define cmd_xdg "xdg-open "
#define cmd_execute "su -l %s -c \" DISPLAY=$DISPLAY %s \""
#define path_app "/usr/bin/"
#define path_glade "/usr/share/ubl-settings-diskquota/ui/ubl-settings-diskquota.glade"
#define path_css "/usr/share/ubl-settings-diskquota/css/ubl-settings-diskquota.css"
#define app_name "ubl-settings-diskquota"
#define path_resources "/usr/share/ubl-settings-diskquota"
#define path_img_head_background "/usr/share/ubl-settings-diskquota/images/logo-background.png"
#define no_recognized _("Argument not recognized\n")
#define global_load "ubconfig --default --source global --noexecute get boot"
#define system_load "ubconfig --default --source system --noexecute get boot"
#define global_save "ubconfig --target global --noexecute set boot "
#define system_save "ubconfig --target system --noexecute set boot "
#define global_remove "ubconfig --target global --noexecute set/remove boot "
#define system_remove "ubconfig --target system --noexecute set/remove boot "
#define str_quota_status "Quota use status:"
#define str_prefix_KB _("Kb")
#define str_prefix_MB _("Mb")
#define str_prefix_GB _("Gb")
#define str_prefix_TB _("Tb")
using namespace std;
extern string version_application;
extern bool flag_save;
extern bool flag_save_local;
extern bool flag_save_global;
extern bool flag_load_global;
extern bool flag_lock_help;
extern int socket_ext_id_I;
extern int socket_trd_id_I;
class MainWindow : public Gtk::ApplicationWindow {
public:
class ModelColumns : public Gtk::TreeModel::ColumnRecord {
public:
ModelColumns() {add(name), add(quotas); add(size),
add(soft_limit_size), add(hard_limit_size); add(deferring_size),
add(files); add(soft_limit_files),
add(hard_limit_delay), add(deferring_files); }
Gtk::TreeModelColumn<Glib::ustring> name;
Gtk::TreeModelColumn<Glib::ustring> quotas;
Gtk::TreeModelColumn<Glib::ustring> size;
Gtk::TreeModelColumn<Glib::ustring> soft_limit_size;
Gtk::TreeModelColumn<Glib::ustring> hard_limit_size;
Gtk::TreeModelColumn<Glib::ustring> deferring_size;
Gtk::TreeModelColumn<Glib::ustring> files;
Gtk::TreeModelColumn<Glib::ustring> soft_limit_files;
Gtk::TreeModelColumn<Glib::ustring> hard_limit_delay;
Gtk::TreeModelColumn<Glib::ustring> deferring_files;
};
class ModelColumnsGeneral : public Gtk::TreeModel::ColumnRecord {
public:
ModelColumnsGeneral() {add(status), add(type_quotas); add(device),
add(user), add(group), add(projects); add(soft_limit_size),
add(hard_limit_size); add(soft_limit_files), add(hard_limit_files), add(deferring_size),
add(deferring_files); }
Gtk::TreeModelColumn<bool> status;
Gtk::TreeModelColumn<Glib::ustring> type_quotas;
Gtk::TreeModelColumn<Glib::ustring> device;
Gtk::TreeModelColumn<Glib::ustring> user;
Gtk::TreeModelColumn<Glib::ustring> group;
Gtk::TreeModelColumn<Glib::ustring> projects;
Gtk::TreeModelColumn<Glib::ustring> soft_limit_size;
Gtk::TreeModelColumn<Glib::ustring> hard_limit_size;
Gtk::TreeModelColumn<Glib::ustring> soft_limit_files;
Gtk::TreeModelColumn<Glib::ustring> hard_limit_files;
Gtk::TreeModelColumn<Glib::ustring> deferring_size;
Gtk::TreeModelColumn<Glib::ustring> deferring_files;
};
ModelColumns m_columns;
ModelColumnsGeneral m_columnsGeneral;
Glib::RefPtr<Gtk::Builder> builder;
template<typename Type>
struct Result{
Type response;
int error;
};
Gtk::Label *headerTopic;
Gtk::AboutDialog *aboutWindows;
Gtk::Overlay *HeadOverlay;
Gtk::HeaderBar *headerBar;
Gtk::Box *boxSave;
Gtk::Box *boxButton;
Gtk::Box *boxFuncs;
Gtk::MenuButton *btnSave;
Gtk::MenuButton *btnLoad;
Gtk::MenuButton *btnSettings;
Gtk::ButtonBox *btnBoxAboutDialog;
Gtk::Image *HeadBackgroundImage;
Gtk::Image *imgInfo;
Gtk::Box *boxInfoError;
Gtk::Label *lblWarning;
Gtk::Label *generalTabLabel;
Gtk::Label *UsersTabLabel;
Gtk::Label *GroupsTabLabel;
Gtk::Label *generalGroupsFilesLabel;
Gtk::Label *generalUsersSizeLabel;
Gtk::Label *generalUsersFilesLabel;
Gtk::Label *generalGroupsSizeWeeksLabel;
Gtk::Label *generalGroupsFilesWeeksLabel;
Gtk::Label *generalUsersSizeWeeksLabel;
Gtk::Label *generalUsersFilesWeeksLabel;
Gtk::Label *generalGroupsSizeDaysLabel;
Gtk::Label *generalGroupsFilesDaysLabel;
Gtk::Label *generalUsersSizeDaysLabel;
Gtk::Label *generalUsersFilesDaysLabel;
Gtk::Label *generalGroupsSizeHoursLabel;
Gtk::Label *generalGroupsFilesHoursLabel;
Gtk::Label *generalUsersSizeHoursLabel;
Gtk::Label *generalUsersFilesHoursLabel;
Gtk::Label *generalGroupsSizeMinutesLabel;
Gtk::Label *generalGroupsFilesMinutesLabel;
Gtk::Label *generalUsersSizeMinutesLabel;
Gtk::Label *generalUsersFilesMinutesLabel;
Gtk::Label *ProjectTabLabel;
Gtk::Label *usersProjectLabel;
Gtk::Label *lblLoad;
Gtk::Label *lblSave;
Gtk::MenuItem *btnLoadGlob;
Gtk::MenuItem *btnLoadLocal;
Gtk::MenuItem *btnSynopsis;
Gtk::MenuItem *btnAbout;
Gtk::MenuItem *btnSaveLocalGlob;
Gtk::MenuItem *btnSaveGlob;
Gtk::MenuItem *btnSaveLocal;
Gtk::Label *groupsDeviceLabel;
Gtk::Label *usersDeviceLabel;
Gtk::Label *headLabel;
Gtk::Window *wndFilters;
Gtk::CheckButton *chbFilterName;
Gtk::CheckButton *chbFilterQuotas;
Gtk::CheckButton *chbFilterSize;
Gtk::CheckButton *chbFilterSoftLimitSize;
Gtk::CheckButton *chbFilterHardLimitSize;
Gtk::CheckButton *chbFilterHardLimitSizeDelay;
Gtk::CheckButton *filtersHardSizeActivationFilterCheckbox;
Gtk::CheckButton *chbFilterFiles;
Gtk::CheckButton *chbFilterSoftLimitFile;
Gtk::CheckButton *chbFilterHardLimitFile;
Gtk::CheckButton *chbFilterHardLimitFileDelay;
Gtk::TreeView *groupsQuotasTree;
Gtk::TreeView *usersQuotasTree;
Gtk::TreeView *ProjectQuotasTree;
Gtk::TreeView *GeneralQuotasTree;
Gtk::Label *quotegroupGroupQuotasLabel;
Gtk::Label *quotegroupSizeFrameLabel;
Gtk::Label *quotegroupSizeCurrentlyLabel;
Gtk::Label *quoteSizeHardLimitLabel;
Gtk::Label *quotegroupFilesFrameLabel;
Gtk::Label *quotegroupFilesCurrentlyLabel;
Gtk::Label *quotegroupFilesSoftLimitLabel;
Gtk::Label *quoteFilesHardLimitLabel;
Gtk::Label *quotegroupFilesHarLimitLabel;
Gtk::Label *quotegroupSizeSoftLimitLabel;
Gtk::Window *QuotasEditWindow;
Gtk::Label *headerAboutTopic;
Gtk::Label *lblHeadQuotasEditWindow;
Gtk::Label *lblFiltersHead;
Gtk::ComboBoxText *usersDeviceCombo;
Gtk::ComboBoxText *groupsDeviceCombo;
Gtk::ComboBoxText *generalDeviceCombo;
Gtk::ComboBoxText *usersProjectCombo;
Gtk::Label *lblFstypeGroups;
Gtk::SpinButton *generalGroupsSizeWeeksSpi;
Gtk::SpinButton *generalGroupsFileWeeksSpin;
Gtk::SpinButton *generalGroupsSizeDaySpin;
Gtk::SpinButton *generalGroupsFilesDaySpin;
Gtk::SpinButton *generalGroupsSizeHourSpin;
Gtk::SpinButton *generalGroupsFilesHourSpin;
Gtk::SpinButton *generalGroupsSizeMinuteSpin;
Gtk::SpinButton *generalGroupsFilesMinuteSpin;
Gtk::SpinButton *generalUsersSizWeeksSpin;
Gtk::SpinButton *generalUsersFileWeeksSpin;
Gtk::SpinButton *generalUsersSizeDaySpin;
Gtk::SpinButton *generalUsersFilesDaySpin;
Gtk::SpinButton *generalUsersSizeHourSpin;
Gtk::SpinButton *generalUsersFilesHoursSpin;
Gtk::SpinButton *generalUsersSizeMinuteSpin;
Gtk::SpinButton *generalUsersFilesMinutesSpin;
Gtk::CheckButton *quotegroupSizeSoftLimitCheck;
Gtk::CheckButton *quotegroupSizeHardLimitCheck;
Gtk::CheckButton *quotegroupFilesSoftLimitCheck;
Gtk::CheckButton *quotegroupFilesHardLimitCheck;
Gtk::SpinButton *quotegroupSizeSoftLimitSpin;
Gtk::SpinButton *quotegroupSizeHardLimitSpin;
Gtk::SpinButton *quotegroupFilesSoftLimitSpin;
Gtk::SpinButton *quotegroupFilesHardLimitSpin;
Gtk::Label *quotegroupFilesSoftLimitlabel;
Gtk::ComboBoxText *quotegroupSizeSoftLimitCombo;
Gtk::ComboBoxText *quotegroupSizeHardLimitCombo;
Gtk::Button *quotegroupCancelButton;
Gtk::Button *quotegroupSaveButton;
Gtk::Button *btnFilterGroups;
Gtk::Button *btnFilterUsers;
Gtk::Button *btnFilterProject;
Gtk::Label *lblHeadeWndWeb;
Gtk::Label *lblwebHeaderName;
Gtk::Label *lblhelpText;
Gtk::Label *lblhelpHeader;
Gtk::CheckButton *chkAlwaysOpenHelp;
Gtk::Button *btnReadHelp;
Gtk::Button *btnCancelHelp;
Gtk::Window *wndShowWeb;
Gtk::CheckMenuItem *chbMangSystemFile;
Gtk::Button* btnDelGroups;
Gtk::Button* btnDelProject;
Gtk::Button* btnDelUsers;
Gtk::Button* btnAddGroups;
Gtk::Button* btnAddUsers;
Gtk::Button* btnAddProject;
Gtk::Button* btnEditProject;
Gtk::Button* btnEditUsers;
Gtk::Button* btnEditGroups;
Gtk::Label* lblSetDevice;
Gtk::Label* lblQuotasStatus;
Gtk::Label* lblSetUGP;
Gtk::Label* lblSetNameDevice;
Gtk::Label* lblSetQuotasStatus;
Gtk::ComboBoxText* cmbSetNameUGP;
#ifdef WEBKIT_FOUND
Gtk::Window *wndWeb;
Gtk::Widget *three;
WebKitWebView *one;
#endif
public:
Lib_save::Save obj_save = Lib_save::Save();
Lib_Load::Load obj_load = Lib_Load::Load();
Devices::Parted obj_device = Devices::Parted();
Quotas_sys::Quotas_sys obj_quotas_sys = Quotas_sys::Quotas_sys();
Quotas_ubconfig::Quotas_ubconfig obj_quotas_ubconfig = Quotas_ubconfig::Quotas_ubconfig();
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;
vector<string> vec_param_names;
map_str_str map_device;
string str_cmd_error;
string save_user_or_group;
string sys_or_ubconfig;
string hw_or_sw = "";
bool flag_open_browser = false;
string mode_quota = "ubconfig";
Glib::RefPtr<Gtk::ListStore> list_store_groups;
Glib::RefPtr<Gtk::ListStore> list_store_users;
Glib::RefPtr<Gtk::ListStore> list_store_project;
Gtk::TreeModel::iterator iter_groups;
Gtk::TreeModel::iterator iter_users;
Gtk::TreeModel::iterator iter_project;
bool flag_validate_del_groups = false;
bool flag_validate_del_users = false;
bool flag_validate_del_project = false;
Gtk::TreeModel::Row row;
const struct tv_g_u_p obj_tv_g_u_p {"", "", "", "", "", "", "", "", "",""};
public:
MainWindow(BaseObjectType* obj, Glib::RefPtr<Gtk::Builder> const& builder);
MainWindow(Glib::RefPtr<Gtk::Builder> const& builder);
~MainWindow();
void settings();
void flag_block_gui();
void lacalization();
void add_CSS();
void get_builder();
void event();
void init_work_tv_g_u_p();
void remove_line_template(const Gtk::TreeModel::Path&, const Gtk::TreeModel::iterator& iter, Gtk::TreeModel::iterator& iter_del, bool& flag_del);
void remove_template(Glib::RefPtr<Gtk::ListStore>* list_store, const Gtk::TreeModel::iterator* iter, bool& flag_validate_del);
void init_tree_view_general();
void entry_combo_box_temp(Gtk::ComboBoxText *combo_box, Gtk::Label *label);
void synopsis_show();
void fill_in_pow_memory(Gtk::ComboBoxText *cb_text);
void info_status_app(string stule);
void filters_show();
void init_tree_view();
void template_open_browser();
void open_browser();
void del_columns();
void set_add_tv_g_u_p(Gtk::TreeModel::Row &row, Glib::RefPtr<Gtk::ListStore> list_store, struct tv_g_u_p obj_tv_g_u_p);
void load_template(map_str_str* map_temp, string cmd);
void info_warning_error(int mess);
void off_quota_system(Gtk::ComboBoxText* combo_box, string quota_type);
void wrapper_save_system_cfg();
void wrapper_save_global_cfg();
void wrapper_save_all_cfg();
void init_dict(string flag_load);
void set_data_cfg();
void set_change_gui(Glib::RefPtr<Gtk::ListStore>* list_store, const Gtk::TreeModel::iterator* iter, bool& flag_validate, Gtk::ComboBoxText *combo_box);
void mode_switch_quota();
void save_quotegroupSaveButton();
void wrapper_settings_quotas_temp(string save_user_or_group);
void off_quota_ubconfig(Gtk::ComboBoxText* combo_box, string quota_type);
void init_spin_all();
void edit_tree_view_U(Glib::RefPtr<Gtk::ListStore>* list_store, const Gtk::TreeModel::iterator* iter, bool& flag_validate);
void edit_tree_view_G(Glib::RefPtr<Gtk::ListStore>* list_store, const Gtk::TreeModel::iterator* iter, bool& flag_validate);
void edit_tree_view_P(Glib::RefPtr<Gtk::ListStore>* list_store, const Gtk::TreeModel::iterator* iter, bool& flag_validate);
void format_cmd_quotas_system(struct struct_quotas& _struct_quota);
void format_cmd_quotas_ubconfig(struct struct_quotas& _struct_quota);
void load_global_cfg();
void load_system_cfg();
struct partition_cmd wrapper_settings_quotas();
void filling_device_combo_box_template(Gtk::ComboBoxText *combo_box, map_str_str &map_device);
bool save_template(string section, string flag_save);
void view_add_columns(Gtk::TreeView &treeView);
void check_limit(Gtk::CheckButton *check_button, Gtk::SpinButton *spin, Gtk::ComboBoxText *combo_box);
void check_limit(Gtk::CheckButton *check_button, Gtk::SpinButton *spin, Gtk::Label *combo_box);
};
void help();
#endif