From f119eca62e620bdd23c7042abe5e8b7331f5c0c6 Mon Sep 17 00:00:00 2001 From: Igor Belitskiy Date: Fri, 9 Jun 2023 11:21:41 +0600 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BD=D0=BE=20?= =?UTF-8?q?=D0=BB=D0=BE=D0=B3=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D1=81=D0=BE=D1=85=D1=80=D0=B0=D0=BD=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/ubl-settings-resourcequota.c | 54 ++++++++--------------------- source/ubl-settings-resourcequota.h | 4 ++- source/ubl-utils.c | 25 +++++++++++-- source/ubl-utils.h | 4 +++ source/view_edit.c | 5 --- 5 files changed, 45 insertions(+), 47 deletions(-) diff --git a/source/ubl-settings-resourcequota.c b/source/ubl-settings-resourcequota.c index ae3a0d4..87a24a6 100644 --- a/source/ubl-settings-resourcequota.c +++ b/source/ubl-settings-resourcequota.c @@ -115,6 +115,7 @@ void config_init(){ main_config.size_tree_view = 0; main_config.flag_load = 0; main_config.size_array_del_line = 0; + main_config.flag_set_data = 0; } main_window *setup_window(){ @@ -257,13 +258,13 @@ void main_update_information() { void load_system_cfg() { main_config.flag_load = 0; - template_cfg(CMD_LOAD_SYSTEM, main_config.load_system_cfg); + template_load_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); + template_load_cfg(CMD_LOAD_GLOBAL, main_config.load_global_cfg); yon_ubl_status_box_render(GLOBAL_LOAD_SUCCESS,BACKGROUND_IMAGE_SUCCESS_TYPE); } @@ -293,7 +294,7 @@ void clear_array() { main_config.size_tree_view = 0; } -void template_cfg(char* cmd, dictionary* load_cfg) { +void template_load_cfg(char* cmd, dictionary* load_cfg) { clear_array(); int size = 0; char** cfg = yon_config_load(cmd, &size); @@ -316,7 +317,8 @@ void template_cfg(char* cmd, dictionary* load_cfg) { if (main_config.size_tree_view != 0) { fill_tree_view(0, main_config.size_tree_view, 0); - } + } + main_config.flag_set_data = 0; } void init_cfg_array(int index) { @@ -573,6 +575,7 @@ void tree_view_add(int index) { main_config.size_tree_view--; main_config.i_o_limit_write_size = philos_int_append(main_config.i_o_limit_write_size, &main_config.size_tree_view, add_get_write_device_size()); fill_tree_view(main_config.size_tree_view-1, main_config.size_tree_view, 1); + main_config.flag_set_data = 1; } void fill_tree_view(int start, int size, int flag_gui_add) { @@ -605,6 +608,7 @@ int tree_view_edit() { GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->treeViewMain)); if(gtk_tree_selection_get_selected(selection, &model, &iter)) { + main_config.flag_set_data = 1; char* str_iter = gtk_tree_model_get_string_from_iter(model, &iter); index = atoi(str_iter); main_config.soft_raw_limit[index] = edit_get_soft(); @@ -793,6 +797,7 @@ void tree_view_del_line() { main_fill_tree_view_after_remove(); gtk_tree_view_set_model(GTK_TREE_VIEW(widgets->treeViewMain), model); free(str_iter); + main_config.flag_set_data = 1; } } void wrapper_all_save() { @@ -879,39 +884,11 @@ char* save_format_value(int index) { int check_save(dictionary* load_cfg) { - dictionary* ptr_dict_gui = NULL; - dictionary* ptr_dict_load = NULL; - char* key_gui = NULL; - char* value_gui = NULL; - char* key_load = NULL; - char* value_load = NULL; - int flag_check_key = 0; - int flag_check_value = 0; - size_t size_cfg_gui = yon_dict_len(main_config.save_cfg_gui); - size_t size_cfg_load = yon_dict_len(load_cfg); - if (size_cfg_gui!=size_cfg_load) { + if (main_config.flag_set_data == 1) { return 0; } - 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; - value_load = (char*)ptr_dict_load->data; - - if (key_gui == key_load) { - flag_check_key = 1; - return 1; - } - if (value_gui == value_load) { - // TODO: check - flag_check_value = 1; - return 1; - } - } - if (flag_check_key == 0 || flag_check_value == 0) { - return 0; - } + else if (main_config.flag_set_data == 0) { + return 1; } return 0; } @@ -936,20 +913,20 @@ int template_format_str_save(dictionary* load_cfg, char* source_set_cmd, char* s if (cmd_set != NULL) { free(cmd_set); } + + + main_config.flag_set_data = 0; return 1; } 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_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++) { char* key = NULL; char* value = NULL; key = yon_char_new(save_format_key(index)); value = yon_char_new(save_format_value(index)); - main_config.save_cfg_gui = yon_dictionary_create_with_data_connected(main_config.save_cfg_gui, key, yon_char_new(value)); if (key != NULL && value != NULL) { cmd = yon_char_unite(cmd, " " , key, "=" , value, NULL); flag_save = 1; @@ -1098,7 +1075,6 @@ 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 a9a0e21..f84ced5 100755 --- a/source/ubl-settings-resourcequota.h +++ b/source/ubl-settings-resourcequota.h @@ -98,6 +98,8 @@ typedef struct dictionary *load_global_cfg; dictionary *load_system_cfg; dictionary *save_cfg_gui; + + int flag_set_data; // flag_load | 0 system // flag_load | 1 global int flag_load; @@ -198,7 +200,7 @@ void tree_view_del_line(); void main_fill_tree_view_after_remove(); void load_system_cfg(); void load_global_cfg(); -void template_cfg(char *cmd, dictionary *load_cfg); +void template_load_cfg(char *cmd, dictionary *load_cfg); void str_split_value(char *values, int index); void set_pow_size(char *str_find, int **array_size, char ***array_data, int index); void str_split_key(char *source_value, int index); diff --git a/source/ubl-utils.c b/source/ubl-utils.c index c84a862..a1205d2 100644 --- a/source/ubl-utils.c +++ b/source/ubl-utils.c @@ -17,12 +17,33 @@ dictionary *yon_dictionary_create_empty() dict->data_type = DICTIONARY_OTHER_TYPE; return dict; } +dictionary *yon_dictionary_copy(dictionary *dict){ + dictionary *dct = yon_dictionary_create_with_data(dict->key,dict->data); + dct->data_type= dict->data_type; +} +/**yon_dictionary_copy_deep(dictionary *dict) + * [EN] + * + * [RU] + * Создаёт полную копию словаря [dict] и возвращает первый элемент +*/ +dictionary *yon_dictionary_copy_deep(dictionary *dict){ + dictionary *dct = NULL; + dictionary *newone=NULL; + for_dictionaries(dct,dict){ + yon_dictionary_add_or_create_if_exists_with_data(newone,dct->key,dct->data); + newone->data_type=dct->data_type; + } + return newone->first; +} size_t yon_dict_len(dictionary *dict) { dictionary* ptr_dict = NULL; size_t size = 0; - for_dictionaries(ptr_dict, dict) { - size+=1; + if (dict != NULL) { + for_dictionaries(ptr_dict, dict) { + size+=1; + } } return size; } diff --git a/source/ubl-utils.h b/source/ubl-utils.h index 63389e4..d8fe781 100644 --- a/source/ubl-utils.h +++ b/source/ubl-utils.h @@ -92,6 +92,10 @@ typedef char** config_str; dictionary *yon_dictionary_create_empty(); +dictionary *yon_dictionary_copy(dictionary *dict); + +dictionary *yon_dictionary_copy_deep(dictionary *dict); + size_t yon_dict_len(dictionary *dict); dictionary *yon_dictionary_create_conneced(dictionary *targetdict); diff --git a/source/view_edit.c b/source/view_edit.c index b9a018f..e8a288b 100644 --- a/source/view_edit.c +++ b/source/view_edit.c @@ -110,11 +110,6 @@ void edit_init_windows() { edit_generate_cmd(); } - - - - - char* edit_get_select_device() { char* text = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(edit_widgets->cbtEditDevice)); if (text != NULL) {