diff --git a/source/ubl-settings-resourcequota.c b/source/ubl-settings-resourcequota.c index 54fbd83..22b1dfd 100644 --- a/source/ubl-settings-resourcequota.c +++ b/source/ubl-settings-resourcequota.c @@ -113,6 +113,8 @@ void config_init(){ main_config.lock_save_global=0; main_config.lock_save_local=0; main_config.size_tree_view = 0; + main_config.flag_load = 0; + main_config.size_array_del_line = 0; } main_window *setup_window(){ @@ -254,11 +256,13 @@ void main_update_information() { } void load_system_cfg() { + main_config.flag_load = 0; template_cfg(CMD_LOAD_SYSTEM, main_config.load_system_cfg); yon_ubl_status_box_render(LOCAL_LOAD_SUCCESS, BACKGROUND_IMAGE_SUCCESS_TYPE); } void load_global_cfg() { + main_config.flag_load = 1; template_cfg(CMD_LOAD_GLOBAL, main_config.load_global_cfg); yon_ubl_status_box_render(GLOBAL_LOAD_SUCCESS,BACKGROUND_IMAGE_SUCCESS_TYPE); } @@ -273,6 +277,8 @@ void clear_array() { philos_free_string_array(&main_config.i_o_limit_read , main_config.size_tree_view); philos_free_string_array(&main_config.i_o_limit_write , main_config.size_tree_view); philos_free_string_array(&main_config.disk, main_config.size_tree_view); + philos_free_string_array(&main_config.array_del_line, main_config.size_array_del_line); + main_config.size_array_del_line = 0; philos_free_int_array(&main_config.type_quota_size, main_config.size_tree_view); philos_free_int_array(&main_config.quota_volume_size, main_config.size_tree_view); @@ -731,6 +737,11 @@ void tree_view_del_line() { g_object_ref(main_config.list); gtk_tree_view_set_model(GTK_TREE_VIEW(widgets->treeViewMain), NULL); gtk_list_store_clear(main_config.list); + char* key_del = save_format_key(main_config.size_tree_view-1); + if (key_del != NULL) { + main_config.array_del_line = yon_char_parsed_append(main_config.array_del_line, &main_config.size_array_del_line, key_del); + free(key_del); + } main_config.type_quota = yon_char_parsed_shrink(main_config.type_quota, &main_config.size_tree_view,index); main_config.size_tree_view++; main_config.quota_volume = yon_char_parsed_shrink(main_config.quota_volume, &main_config.size_tree_view,index); @@ -768,15 +779,23 @@ void tree_view_del_line() { } } void wrapper_all_save() { - // template_format_str_save(main_config.load_global_cfg, CMD_LOAD_GLOBAL); + if (main_config.flag_load == 0) { + template_format_str_save(main_config.load_system_cfg, CMD_ALL_SAVE, CMD_ALL_REMOVE); + } + else { + template_format_str_save(main_config.load_global_cfg, CMD_ALL_SAVE, CMD_ALL_REMOVE); + } + yon_ubl_status_box_render(GLOBAL_LOCAL_SAVE_SUCCESS,BACKGROUND_IMAGE_SUCCESS_TYPE); } void wrapper_global_save() { - template_format_str_save(main_config.load_global_cfg, CMD_SAVE_GLOBAL); + template_format_str_save(main_config.load_global_cfg, CMD_SAVE_GLOBAL, CMD_REMOVE_GLOBAL); + yon_ubl_status_box_render(GLOBAL_LOAD_SUCCESS,BACKGROUND_IMAGE_SUCCESS_TYPE); } void wrapper_system_save() { - template_format_str_save(main_config.load_system_cfg, CMD_SAVE_SYSTEM); + template_format_str_save(main_config.load_system_cfg, CMD_SAVE_SYSTEM, CMD_REMOVE_SYSTEM); + yon_ubl_status_box_render(LOCAL_SAVE_SUCCESS,BACKGROUND_IMAGE_SUCCESS_TYPE); } @@ -794,6 +813,8 @@ char* save_format_value(int index) { split_simvol[0] = 0; split_simvol[1] = 0; if (strstr(main_config.soft_raw_limit[index], "-") == NULL) { + puts(main_config.soft_raw_limit[index]); + printf("%d\n", main_config.soft_raw_limit_size[index]); value = yon_char_unite(philos_format_cfg_str_size_memory("MemoryHigh", main_config.soft_raw_limit[index],main_config.soft_raw_limit_size[index]),NULL); split_simvol[0] = ','; split_simvol[1] = '\0'; @@ -824,6 +845,7 @@ char* save_format_value(int index) { return value; } + int check_save(dictionary* load_cfg) { dictionary* ptr_dict_gui = NULL; dictionary* ptr_dict_load = NULL; @@ -840,6 +862,7 @@ int check_save(dictionary* load_cfg) { } for_dictionaries(ptr_dict_gui, main_config.save_cfg_gui) { for_dictionaries(ptr_dict_load, load_cfg) { + key_gui = ptr_dict_gui->key; value_gui = (char*)ptr_dict_gui->data; key_load = ptr_dict_load->key; @@ -859,12 +882,32 @@ int check_save(dictionary* load_cfg) { return 1; } } + return 0; +} +int template_format_str_save(dictionary* load_cfg, char* source_set_cmd, char* source_remove_cmd) { + char* cmd_remove = template_format_str_remove_save(source_remove_cmd); + char* cmd_set = template_format_str_set_save(load_cfg, source_set_cmd); + if (cmd_set != NULL && cmd_remove != NULL) { + yon_config_save(yon_char_unite(cmd_set, "; " , cmd_remove, NULL)); + } + else if (cmd_remove != NULL) { + yon_config_save(cmd_remove); + puts(cmd_remove); + } + else if (cmd_set != NULL) { + yon_config_save(cmd_set); + puts(cmd_remove); + } + else { + return 0; + } + return 1; + } - -void template_format_str_save(dictionary* load_cfg, char* source_cmd) { +char* template_format_str_set_save(dictionary* load_cfg, char* source_set_cmd) { yon_dictionary_free_all(main_config.save_cfg_gui, NULL); - char* cmd = yon_char_new(source_cmd); + char* cmd = yon_char_new(source_set_cmd); main_config.save_cfg_gui = yon_dictionary_create_empty(); int flag_save = 0; for (size_t index = 0; index < main_config.size_tree_view; index++) { @@ -872,23 +915,45 @@ void template_format_str_save(dictionary* load_cfg, char* source_cmd) { char* value = NULL; key = save_format_key(index); value = save_format_value(index); - puts(value); main_config.save_cfg_gui = yon_dictionary_create_with_data_connected(main_config.save_cfg_gui, key, yon_char_new(value)); - check_save(load_cfg); if (key != NULL && value != NULL) { - cmd = yon_char_unite(cmd, " " , key, "=" , value, " ", NULL); - flag_save = 1; + if (check_save(load_cfg) == 1) { + cmd = yon_char_unite(cmd, " " , key, "=" , value, " ", NULL); + flag_save = 1; + } + } + if (key != NULL) { + free(key); + } + if (value != NULL) { + free(value); } - // puts(key); - free(key); - free(value); } if (flag_save) { - yon_config_save(cmd); + return cmd; } free(cmd); + return NULL; + } +char* template_format_str_remove_save(char* source_remove_cmd) { + char* cmd = yon_char_new(source_remove_cmd); + int flag_save = 0; + for (size_t index = 0; index < main_config.size_array_del_line; index++) { + char* key = main_config.array_del_line[index]; + if (key != NULL) { + cmd = yon_char_unite(cmd, " " , key, " ", NULL); + flag_save = 1; + free(key); + } + } + if (flag_save) { + return cmd; + } + free(cmd); + return NULL; +} void main_fill_tree_view_after_remove() { for (int index= 0; index < main_config.size_tree_view; index++) { @@ -1005,7 +1070,6 @@ int main(int argc, char *argv[]){ event_all(widgets); main_event(widgets); - yon_ubl_header_setup(widgets->HeadOverlay,widgets->HeadBox,widgets->HeadImage,banner_path); if (yon_ubl_status_box_setup(widgets->StatusIcon,widgets->StatusBox,widgets->StatusLabel)) @@ -1017,6 +1081,8 @@ int main(int argc, char *argv[]){ gtk_style_context_add_provider_for_screen(gdk_screen_get_default(), GTK_STYLE_PROVIDER(css), -1); + load_global_cfg(); + load_system_cfg(); gtk_main(); } diff --git a/source/ubl-settings-resourcequota.h b/source/ubl-settings-resourcequota.h index ebfef2b..3fecee3 100755 --- a/source/ubl-settings-resourcequota.h +++ b/source/ubl-settings-resourcequota.h @@ -30,11 +30,17 @@ #define LocalePath "/usr/share/locale" #define LocaleName "ubl-settings-resourcequota" -#define CMD_LOAD_GLOBAL "ubconfig --default --source global get security" -#define CMD_LOAD_SYSTEM "ubconfig --default --source system get security" + +#define CMD_LOAD_GLOBAL "ubconfig --default --source global get security CGROUP_QUOTA[*]" +#define CMD_LOAD_SYSTEM "ubconfig --default --source system get security CGROUP_QUOTA[*]" #define CMD_SAVE_GLOBAL "ubconfig --default --source global set security" #define CMD_SAVE_SYSTEM "ubconfig --default --source system set security" +#define CMD_ALL_SAVE "ubconfig set security " +#define CMD_ALL_REMOVE "ubconfig remove security " +#define CMD_REMOVE_GLOBAL "ubconfig --target global --noexecute remove security " +#define CMD_REMOVE_SYSTEM "ubconfig --target system remove security " #define CMD_GET_SLICE_SERVICE "systemd-cgls --no-page" + #define CMD_GET_GROUP "cut -d: -f1 /etc/group" typedef char *string; string version_application = ""; @@ -76,6 +82,8 @@ typedef struct config_str i_o_limit_read; config_str i_o_limit_write; config_str disk; + config_str array_del_line; + int size_array_del_line; int *type_quota_size; int *quota_volume_size; @@ -89,6 +97,9 @@ typedef struct dictionary *load_global_cfg; dictionary *load_system_cfg; dictionary *save_cfg_gui; + // flag_load | 0 system + // flag_load | 1 global + int flag_load; } config; typedef struct @@ -197,4 +208,7 @@ void wrapper_template_save(char *check_flag); void wrapper_system_save(); void wrapper_global_save(); void wrapper_all_save(); -void template_format_str_save(dictionary *load_cfg, char *source_cmd); +int template_format_str_save(dictionary *load_cfg, char *source_cmd, char* source_remove_cmd); +char* template_format_str_remove_save(char* source_remove_cmd); +char* template_format_str_set_save(dictionary* load_cfg, char* source_set_cmd); +char* save_format_key(int index); \ No newline at end of file diff --git a/source/ubl-strings.h b/source/ubl-strings.h index b5cca97..6a1079c 100644 --- a/source/ubl-strings.h +++ b/source/ubl-strings.h @@ -41,4 +41,5 @@ #define LOCAL_SAVE_SUCCESS _("Local configuration saving succseeded.") #define STR_DEL_TABLE _("Quota deleted") #define STR_NO_SELECT_TABLE _("Quota deleted") -#define STR_QUOTAS_ADD _("Quota deleted") \ No newline at end of file +#define STR_QUOTAS_ADD _("Quota deleted") +#define ALL_SAVE_SUCCESS _("Save configuration") \ No newline at end of file diff --git a/source/view_edit.c b/source/view_edit.c index 475e216..adf23d1 100644 --- a/source/view_edit.c +++ b/source/view_edit.c @@ -38,6 +38,7 @@ edit_window *edit_setup_window(char* glade_path){ device_fill_disk(edit_widgets->cbtEditDevice); // edit_event(edit_widgets); edit_localization(edit_widgets); + edit_init_windows(); } return edit_widgets; } @@ -95,13 +96,13 @@ void edit_show(GtkWidget *self, char* glade_path) { } void edit_init_windows() { - edit_generate_cmd(); edit_set_active_widgets(edit_widgets->chkSoftRestrictionEdit, edit_widgets->spiSevereRestrictionEdit, edit_widgets->cmSevereRestrictionEdit); edit_set_active_widgets(edit_widgets->chkSevereRestrictionEdit, edit_widgets->spinSevereRestrictionEdit, edit_widgets->cmbSevereRestrictionEdit); edit_set_active_widgets(edit_widgets->chkPaddingFLEdit, edit_widgets->spinPaddingFLEdit, edit_widgets->cmbPaddingFLEdit); edit_set_active_widgets(edit_widgets->chkCPULimitEdit, edit_widgets->spinCPULimitEdit, edit_widgets->lblCPULimitEdit); edit_set_active_widgets_device_io(edit_widgets->chbEditWrite, edit_widgets->spinEditWrite, edit_widgets->cbtEditWrite); edit_set_active_widgets_device_io(edit_widgets->chbEditRead, edit_widgets->spinEditRead, edit_widgets->cbtEditRead); + edit_generate_cmd(); } void edit_set_active_widgets(GtkWidget *self, GtkWidget *entry, GtkWidget *label) { diff --git a/ubl-settings-resourcequota.glade b/ubl-settings-resourcequota.glade index 1107ca6..b50039b 100644 --- a/ubl-settings-resourcequota.glade +++ b/ubl-settings-resourcequota.glade @@ -307,7 +307,7 @@ - + True False vertical