From 96e8ac3ecd119001dcc8c30887cade789ee4d818 Mon Sep 17 00:00:00 2001 From: Igor Belitskiy Date: Mon, 5 Jun 2023 12:15:31 +0600 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5=D0=BD=D0=B8=D0=B5=20?= =?UTF-8?q?gui=20=D1=81=D0=BF=D0=B8=D1=81=D0=BA=D0=BE=D0=BC=20=D0=B3=D1=80?= =?UTF-8?q?=D1=83=D0=BF=D0=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/ubl-settings-resourcequota.c | 34 ++++++++++++++++++++++------- source/ubl-settings-resourcequota.h | 6 +++++ source/ubl-utils.c | 13 ++++++++--- source/ubl-utils.h | 2 ++ source/view_add.c | 7 +++++- source/view_add.h | 3 +++ 6 files changed, 53 insertions(+), 12 deletions(-) diff --git a/source/ubl-settings-resourcequota.c b/source/ubl-settings-resourcequota.c index 41d4a20..5eebf41 100644 --- a/source/ubl-settings-resourcequota.c +++ b/source/ubl-settings-resourcequota.c @@ -191,8 +191,6 @@ main_window *setup_window(){ if (main_config.lock_save_global == 1 && main_config.lock_save_local == 1) { gtk_widget_set_sensitive(widgets->btnSaveCfg,0); } - - gtk_widget_show_all(widgets->Window); return widgets; } @@ -235,7 +233,8 @@ void main_update_information() { } else if (menu_id == 1) { - + fill_cmb_2 = yon_config_load(CMD_GET_GROUP, &size); + philos_array_string_remove_char(&fill_cmb_2, "\n", size); } else if (menu_id == 2) { @@ -666,6 +665,10 @@ void main_event(main_window *widgets) { g_signal_connect(G_OBJECT(widgets->treeViewMain), "cursor-changed", G_CALLBACK(tree_view_select), widgets); g_signal_connect(G_OBJECT(widgets->LoadGlobalMenuItem), "activate", G_CALLBACK(load_global_cfg), widgets); g_signal_connect(G_OBJECT(widgets->LoadLocalMenuItem), "activate", G_CALLBACK(load_system_cfg), widgets); + + g_signal_connect(G_OBJECT(widgets->SaveGlobalMenuItem), "activate", G_CALLBACK(wrapper_global_save), widgets); + g_signal_connect(G_OBJECT(widgets->SaveLocalMenuItem), "activate", G_CALLBACK(wrapper_system_save), widgets); + g_signal_connect(G_OBJECT(widgets->SaveMenuItem), "activate", G_CALLBACK(wrapper_all_save), widgets); /* g_signal_connect(G_OBJECT(widgets->LoadGlobalMenuItem),"activate",G_CALLBACK(),NULL); g_signal_connect(G_OBJECT(widgets->LoadLocalMenuItem),"activate",G_CALLBACK(),NULL); @@ -676,6 +679,7 @@ void main_event(main_window *widgets) { */ } void wrapper_add_show(GtkWidget *self) { + add_get_cmd_group(CMD_GET_GROUP); add_show(NULL, glade_path); g_signal_connect(G_OBJECT(get_widget_add()->btnSaveAddSave), "clicked", G_CALLBACK(main_add_btn_save), NULL); } @@ -766,11 +770,25 @@ void tree_view_del_line() { main_config.i_o_limit_write_size = remove_element_int_array(main_config.i_o_limit_write_size, &main_config.size_tree_view,index); } } +void wrapper_all_save() { + wrapper_template_save("all"); +} -void template_format_save(dictionary* load_temp_cfg) { - if (load_temp_cfg == NULL) { - return; - } +void wrapper_global_save() { + wrapper_template_save("global"); +} + +void wrapper_system_save() { + wrapper_template_save("system"); +} + +void wrapper_template_save(char* check_flag) { + puts(check_flag); + template_format_str_save(); +} + +void template_format_str_save() { + yon_dictionary_free_all(main_config.save_cfg_gui, NULL); for (size_t i = 0; i < main_config.size_tree_view; i++) { char* key = NULL; char* value = ""; @@ -816,7 +834,6 @@ void template_format_save(dictionary* load_temp_cfg) { main_config.save_cfg_gui = yon_dictionary_create_with_data_connected(main_config.save_cfg_gui, key, yon_char_new(value)); free(key); free(value); - } } @@ -923,6 +940,7 @@ int main(int argc, char *argv[]){ main_window *widgets = setup_window(); main_config.load_global_cfg = yon_dictionary_create_empty(); main_config.load_system_cfg = yon_dictionary_create_empty(); + main_config.save_cfg_gui = yon_dictionary_create_empty(); main_update_information(); filters_init_flag(); filters_setup_window(glade_path); diff --git a/source/ubl-settings-resourcequota.h b/source/ubl-settings-resourcequota.h index da8eae9..6c66328 100755 --- a/source/ubl-settings-resourcequota.h +++ b/source/ubl-settings-resourcequota.h @@ -34,6 +34,7 @@ #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_GET_GROUP "cut -d: -f1 /etc/group" typedef char* string; string version_application = "1.0"; @@ -189,3 +190,8 @@ void str_split_key(char* source_value, int index); void fill_tree_view(int start, int size, int flag_gui_add); void clear_array(); void init_cfg_array(int index); +void wrapper_template_save(char* check_flag); +void wrapper_system_save(); +void wrapper_global_save(); +void wrapper_all_save(); +void template_format_str_save(); diff --git a/source/ubl-utils.c b/source/ubl-utils.c index 0f67570..b4acb04 100644 --- a/source/ubl-utils.c +++ b/source/ubl-utils.c @@ -26,6 +26,13 @@ void yon_dictionary_switch_to_last(dictionary **dict) } } +void philos_array_string_remove_char(char*** array, char* str_remove, int size) { + for (int index = 0; index < size; index++) { + (*array)[index] = yon_char_divide_search((*array)[index], str_remove, -1); + } + +} + dictionary *yon_dictionary_create_conneced(dictionary *targetdict) { targetdict = yon_dictionary_get_last(targetdict); @@ -403,9 +410,9 @@ config_str philos_list_user(int* size) { } break; } - if ((entry->pw_uid >= uid_min && entry->pw_uid < uid_max) || entry->pw_uid == 0) { - str_users = yon_char_parsed_append(str_users, size, entry->pw_name); - } + //if ((entry->pw_uid >= uid_min && entry->pw_uid < uid_max) || entry->pw_uid == 0) { + str_users = yon_char_parsed_append(str_users, size, entry->pw_name); + //} } endpwent(); return str_users; diff --git a/source/ubl-utils.h b/source/ubl-utils.h index b95c808..f8deecd 100644 --- a/source/ubl-utils.h +++ b/source/ubl-utils.h @@ -144,6 +144,8 @@ char **yon_char_parse(char *parameters, int *size, char *divider); char** philos_str_split(char *parameters, int *size, char *divider); +void philos_array_string_remove_char(char*** array, char* str_remove, int size); + char **yon_char_parsed_shrink(char **char_string, int *size, int item_to_delete); int yon_char_parsed_check_exist(char **parameters, int size, char *param); diff --git a/source/view_add.c b/source/view_add.c index c478654..e2dce85 100644 --- a/source/view_add.c +++ b/source/view_add.c @@ -84,6 +84,10 @@ void add_event(add_window *widgets) { } +void add_get_cmd_group(char* cmd_get_group) { + CMD_GET_GROUP = cmd_get_group; +} + void add_destroy(GtkWidget *self) { add_widgets = NULL; } @@ -212,7 +216,8 @@ void add_update_combo_box() { } else if (menu_id == 1) { - + fill_cmb_2 = yon_config_load(CMD_GET_GROUP, &size); + philos_array_string_remove_char(&fill_cmb_2, "\n", size); } else if (menu_id == 2) { diff --git a/source/view_add.h b/source/view_add.h index 261d998..068e5c9 100644 --- a/source/view_add.h +++ b/source/view_add.h @@ -13,8 +13,10 @@ #include #include "my_device.h" +static char* CMD_GET_GROUP; // Переменные typedef struct { + GtkWidget* Window; GtkWidget* btnSaveAddSave; GtkWidget* btnAddCancel; @@ -76,6 +78,7 @@ int add_get_limit_cpu_size(); int add_get_limit_swap_size(); int add_get_quota_object_size(); +void add_get_cmd_group(char* cmd_get_group); char* add_get_select_device_to_level_2(); void add_generate_cmd(); #endif \ No newline at end of file