Исправил вывод в treeView

pull/4/head
Igor Belitskiy 2 years ago
parent 990226175f
commit 2994580efe

@ -251,12 +251,12 @@ void main_update_information() {
} }
void load_system_cfg() { void load_system_cfg() {
template_cfg(CMD_LOAD_SYSTEM); template_cfg(CMD_LOAD_SYSTEM, main_config.load_system_cfg);
yon_ubl_status_box_render(LOCAL_LOAD_SUCCESS, BACKGROUND_IMAGE_SUCCESS_TYPE); yon_ubl_status_box_render(LOCAL_LOAD_SUCCESS, BACKGROUND_IMAGE_SUCCESS_TYPE);
} }
void load_global_cfg() { void load_global_cfg() {
template_cfg(CMD_LOAD_GLOBAL); template_cfg(CMD_LOAD_GLOBAL, main_config.load_global_cfg);
yon_ubl_status_box_render(GLOBAL_LOAD_SUCCESS,BACKGROUND_IMAGE_SUCCESS_TYPE); yon_ubl_status_box_render(GLOBAL_LOAD_SUCCESS,BACKGROUND_IMAGE_SUCCESS_TYPE);
} }
@ -283,7 +283,7 @@ void clear_array() {
main_config.size_tree_view = 0; main_config.size_tree_view = 0;
} }
void template_cfg(char* cmd) { void template_cfg(char* cmd, dictionary* load_cfg) {
clear_array(); clear_array();
int size = 0; int size = 0;
char** cfg = yon_config_load(cmd, &size); char** cfg = yon_config_load(cmd, &size);
@ -296,11 +296,13 @@ void template_cfg(char* cmd) {
size_t length = strlen(str_key_value); size_t length = strlen(str_key_value);
str_key_value = yon_char_divide(str_key_value, length-2); str_key_value = yon_char_divide(str_key_value, length-2);
} }
str_split_key(str_key, main_config.size_tree_view); load_cfg = yon_dictionary_create_with_data_connected(load_cfg, str_key, str_key_value);
str_split_value(str_key_value, main_config.size_tree_view); str_split_value(str_key_value, main_config.size_tree_view);
str_split_key(str_key, main_config.size_tree_view);
main_config.size_tree_view++; main_config.size_tree_view++;
} }
} }
if (main_config.size_tree_view != 0) { if (main_config.size_tree_view != 0) {
fill_tree_view(0, main_config.size_tree_view, 0); fill_tree_view(0, main_config.size_tree_view, 0);
} }
@ -309,6 +311,8 @@ void template_cfg(char* cmd) {
void init_cfg_array(int index) { void init_cfg_array(int index) {
main_config.disk = yon_char_parsed_append(main_config.disk, &index, "-"); main_config.disk = yon_char_parsed_append(main_config.disk, &index, "-");
index--; index--;
set_pow_size("-", &main_config.type_quota_size, &main_config.type_quota, index);
set_pow_size("-", &main_config.quota_volume_size, &main_config.quota_volume, index);
set_pow_size("-", &main_config.cpu_limit_size, &main_config.cpu_limit, index); set_pow_size("-", &main_config.cpu_limit_size, &main_config.cpu_limit, index);
set_pow_size("-", &main_config.cpu_limit_size, &main_config.cpu_limit, index); set_pow_size("-", &main_config.cpu_limit_size, &main_config.cpu_limit, index);
set_pow_size("-", &main_config.soft_raw_limit_size, &main_config.soft_raw_limit, index); set_pow_size("-", &main_config.soft_raw_limit_size, &main_config.soft_raw_limit, index);
@ -317,7 +321,9 @@ void init_cfg_array(int index) {
set_pow_size("-", &main_config.i_o_limit_read_size, &main_config.i_o_limit_read, index); set_pow_size("-", &main_config.i_o_limit_read_size, &main_config.i_o_limit_read, index);
set_pow_size("-", &main_config.i_o_limit_write_size, &main_config.i_o_limit_write, index); set_pow_size("-", &main_config.i_o_limit_write_size, &main_config.i_o_limit_write, index);
} }
void str_split_key(char* value, int index) {
void str_split_key(char* source_value, int index) {
char* value = yon_char_new(source_value);
yon_char_divide_search(value, "[", -1); yon_char_divide_search(value, "[", -1);
value = yon_char_divide_search(value, "]", -1); value = yon_char_divide_search(value, "]", -1);
if (strstr(value, ".") != NULL) { if (strstr(value, ".") != NULL) {
@ -340,8 +346,6 @@ void str_split_key(char* value, int index) {
else { else {
main_config.quota_volume = yon_char_parsed_append(main_config.quota_volume, &index, value); main_config.quota_volume = yon_char_parsed_append(main_config.quota_volume, &index, value);
index--; index--;
main_config.type_quota_size = philos_int_append(main_config.type_quota_size, &index, -1);
index--;
main_config.type_quota = yon_char_parsed_append(main_config.type_quota, &index, "-"); main_config.type_quota = yon_char_parsed_append(main_config.type_quota, &index, "-");
index--; index--;
} }
@ -352,8 +356,8 @@ void str_split_key(char* value, int index) {
char** arr_users = philos_list_user(&user_size); char** arr_users = philos_list_user(&user_size);
for (int user_index = 0; user_index < user_size; user_index++) { for (int user_index = 0; user_index < user_size; user_index++) {
// Пользователь // Пользователь
if (strcmp(arr_users[user_index], value) != 0) { if (strstr(arr_users[user_index], value) != NULL) {
main_config.type_quota_size = philos_int_append(main_config.type_quota_size, &index, 0); main_config.type_quota_size = philos_int_append(main_config.type_quota_size, &index, -1);
index--; index--;
main_config.quota_volume = yon_char_parsed_append(main_config.quota_volume, &index, value); main_config.quota_volume = yon_char_parsed_append(main_config.quota_volume, &index, value);
index--; index--;
@ -371,6 +375,7 @@ void str_split_key(char* value, int index) {
} }
} }
} }
} }
void str_split_value(char* values, int index) { void str_split_value(char* values, int index) {
@ -425,25 +430,25 @@ void set_pow_size(char* str_find, int** array_size, char*** array_data , int ind
if (strstr(str_find,"K") != NULL) { if (strstr(str_find,"K") != NULL) {
*array_size = philos_int_append(*array_size, &index, 0); *array_size = philos_int_append(*array_size, &index, 0);
str_find = yon_char_divide(str_find, length-1); str_find = yon_char_divide(str_find, length-1);
str_find = yon_char_unite(str_find, " ", STR_KB); str_find = yon_char_unite(str_find, " ", STR_KB, NULL);
index--; index--;
} }
else if (strstr(str_find,"M") != NULL) { else if (strstr(str_find,"M") != NULL) {
*array_size = philos_int_append(*array_size, &index, 1); *array_size = philos_int_append(*array_size, &index, 1);
str_find = yon_char_divide(str_find, length-1); str_find = yon_char_divide(str_find, length-1);
str_find = yon_char_unite(str_find," ", STR_MB); str_find = yon_char_unite(str_find," ", STR_MB, NULL);
index--; index--;
} }
else if (strstr(str_find,"G") != NULL) { else if (strstr(str_find,"G") != NULL) {
*array_size = philos_int_append(*array_size, &index, 2); *array_size = philos_int_append(*array_size, &index, 2);
str_find = yon_char_divide(str_find, length-1); str_find = yon_char_divide(str_find, length-1);
str_find = yon_char_unite(str_find," ", STR_GB); str_find = yon_char_unite(str_find," ", STR_GB, NULL);
index--; index--;
} }
else if (strstr(str_find,"T") != NULL) { else if (strstr(str_find,"T") != NULL) {
*array_size = philos_int_append(*array_size, &index, 3); *array_size = philos_int_append(*array_size, &index, 3);
str_find = yon_char_divide(str_find, length-1); str_find = yon_char_divide(str_find, length-1);
str_find = yon_char_unite(str_find," ", STR_TB); str_find = yon_char_unite(str_find," ", STR_TB, NULL);
index--; index--;
} }
else if (strstr(str_find,"\%") != NULL) { else if (strstr(str_find,"\%") != NULL) {
@ -720,8 +725,13 @@ void tree_view_del_line() {
GtkTreeModel *model = GTK_TREE_MODEL(main_config.list); GtkTreeModel *model = GTK_TREE_MODEL(main_config.list);
GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->treeViewMain)); GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->treeViewMain));
if(gtk_tree_selection_get_selected(selection, &model, &iter)) { if(gtk_tree_selection_get_selected(selection, &model, &iter)) {
char* str_iter = gtk_tree_model_get_string_from_iter(model, &iter); char* str_iter = yon_char_new(gtk_tree_model_get_string_from_iter(model, &iter));
index = atoi(str_iter); index = atoi(str_iter);
g_object_ref(main_config.list);
gtk_tree_view_set_model(GTK_TREE_VIEW(widgets->treeViewMain), NULL);
gtk_list_store_clear(main_config.list);
main_fill_tree_view_after_remove();
gtk_tree_view_set_model(GTK_TREE_VIEW(widgets->treeViewMain), model);
main_config.type_quota = yon_char_parsed_shrink(main_config.type_quota, &main_config.size_tree_view,index); 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.size_tree_view++;
main_config.quota_volume = yon_char_parsed_shrink(main_config.quota_volume, &main_config.size_tree_view,index); main_config.quota_volume = yon_char_parsed_shrink(main_config.quota_volume, &main_config.size_tree_view,index);
@ -754,14 +764,59 @@ void tree_view_del_line() {
main_config.i_o_limit_read_size = remove_element_int_array(main_config.i_o_limit_read_size, &main_config.size_tree_view,index); main_config.i_o_limit_read_size = remove_element_int_array(main_config.i_o_limit_read_size, &main_config.size_tree_view,index);
main_config.size_tree_view++; main_config.size_tree_view++;
main_config.i_o_limit_write_size = remove_element_int_array(main_config.i_o_limit_write_size, &main_config.size_tree_view,index); main_config.i_o_limit_write_size = remove_element_int_array(main_config.i_o_limit_write_size, &main_config.size_tree_view,index);
g_object_ref(main_config.list);
gtk_tree_view_set_model(GTK_TREE_VIEW(widgets->treeViewMain), NULL);
gtk_list_store_clear(main_config.list);
main_fill_tree_view_after_remove();
gtk_tree_view_set_model(GTK_TREE_VIEW(widgets->treeViewMain), model);
} }
else { }
void template_format_save(dictionary* load_temp_cfg) {
if (load_temp_cfg == NULL) {
return;
}
for (size_t i = 0; i < main_config.size_tree_view; i++) {
char* key = NULL;
char* value = "";
char split_simvol[2] = {0};
if (strstr(main_config.quota_volume[i], "-") == NULL) {
key = yon_char_unite("CGROUP_QUOTA[", &main_config.type_quota[i] , "]", NULL);
}
else {
key = yon_char_unite("CGROUP_QUOTA[", &main_config.type_quota[i], ".", &main_config.quota_volume[i], "]", NULL);
}
split_simvol[0] = 0;
split_simvol[1] = 0;
if (strstr(main_config.soft_raw_limit[i], "-") != NULL) {
value = yon_char_unite(value, main_config.soft_raw_limit[i], NULL);
split_simvol[0] = ',';
split_simvol[1] = '\0';
}
if (strstr(main_config.hard_raw_limit[i], "-") != NULL) {
value = yon_char_unite(value, split_simvol, main_config.hard_raw_limit[i], NULL);
split_simvol[0] = ',';
split_simvol[1] = '\0';
}
if (strstr(main_config.swap[i], "-") != NULL) {
value = yon_char_unite(value, split_simvol, main_config.swap[i], NULL);
split_simvol[0] = ',';
split_simvol[1] = '\0';
}
if (strstr(main_config.cpu_limit[i], "-") != NULL) {
value = yon_char_unite(value, split_simvol, main_config.cpu_limit[i], NULL);
split_simvol[0] = ',';
split_simvol[1] = '\0';
}
if (strstr(main_config.i_o_limit_read[i], "-") != NULL) {
value = yon_char_unite(value, split_simvol, main_config.i_o_limit_read[i], NULL);
split_simvol[0] = ',';
split_simvol[1] = '\0';
}
if (strstr(main_config.i_o_limit_write[i], "-") != NULL) {
value = yon_char_unite(value, split_simvol, main_config.i_o_limit_write[i], NULL);
split_simvol[0] = ',';
split_simvol[1] = '\0';
}
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);
} }
} }
@ -866,6 +921,8 @@ int main(int argc, char *argv[]){
gtk_init(&argc,&argv); gtk_init(&argc,&argv);
device_disk_parsed(); device_disk_parsed();
main_window *widgets = setup_window(); main_window *widgets = setup_window();
main_config.load_global_cfg = yon_dictionary_create_empty();
main_config.load_system_cfg = yon_dictionary_create_empty();
main_update_information(); main_update_information();
filters_init_flag(); filters_init_flag();
filters_setup_window(glade_path); filters_setup_window(glade_path);

@ -62,7 +62,6 @@ typedef struct {
config_str load_system_key; config_str load_system_key;
config_str load_global_key; config_str load_global_key;
config_str cfg_gui_key;
render_data status_render; render_data status_render;
config_str type_quota; config_str type_quota;
@ -84,6 +83,9 @@ typedef struct {
int* i_o_limit_read_size; int* i_o_limit_read_size;
int* i_o_limit_write_size; int* i_o_limit_write_size;
int size_tree_view; int size_tree_view;
dictionary* load_global_cfg;
dictionary* load_system_cfg;
dictionary* save_cfg_gui;
} config; } config;
typedef struct { typedef struct {
@ -180,10 +182,10 @@ void tree_view_del_line();
void main_fill_tree_view_after_remove(); void main_fill_tree_view_after_remove();
void load_system_cfg(); void load_system_cfg();
void load_global_cfg(); void load_global_cfg();
void template_cfg(char* cmd); void template_cfg(char* cmd, dictionary* load_cfg);
void str_split_value(char* values, int index); void str_split_value(char* values, int index);
void set_pow_size(char* str_find, int** array_size, char*** array_data, int index); void set_pow_size(char* str_find, int** array_size, char*** array_data, int index);
void str_split_key(char* value, int index); void str_split_key(char* source_value, int index);
void fill_tree_view(int start, int size, int flag_gui_add); void fill_tree_view(int start, int size, int flag_gui_add);
void clear_array(); void clear_array();
void init_cfg_array(int index); void init_cfg_array(int index);

@ -568,11 +568,11 @@ char *yon_char_from_int(int int_to_convert)
{ {
int i = 1; int i = 1;
float convert_check = (float)int_to_convert; float convert_check = (float)int_to_convert;
for (i = 1; convert_check > 10; i++) for (i = 1; convert_check >= 10; i++)
{ {
convert_check = convert_check / 10; convert_check = convert_check / 10;
} }
char *ch = malloc(i * sizeof(char) + 1); char *ch = g_malloc0(i * sizeof(char) + 1);
sprintf(ch, "%d", int_to_convert); sprintf(ch, "%d", int_to_convert);
return ch; return ch;
} }
@ -987,16 +987,23 @@ int* philos_int_append(int* array, int* size, int value) {
} }
int* remove_element_int_array(int* array, int* size, int index) { int* remove_element_int_array(int* array, int* size, int item_to_delete) {
int* temp = malloc(((*size) - 1) * sizeof(int)); int *new_int_parsed=NULL;
if (index != 0) new_int_parsed=malloc(sizeof(int*)*((*size)-1));
memcpy(temp, array, index * sizeof(int)); int flag = 0;
for (int i=0;i < (*size);i++){
if (index != ((*size) - 1)) if (i==item_to_delete) {
memcpy(temp+index, array+index+1, ((*size) - index - 1) * sizeof(int)); flag = 1;
}
free (array); if (flag == 0) {
return temp; memcpy(&(new_int_parsed[i]),&(array[i]),sizeof(int));
}
else if (flag == 1 && i!=item_to_delete) {
memcpy(&(new_int_parsed[i]),&(array[i-1]),sizeof(int));
}
}
(*size)=(*size)-1;
return new_int_parsed;
} }
// Gtk functions // Gtk functions

@ -188,7 +188,7 @@ int yon_launch(thread_output *thread);
int* philos_int_append(int* array, int* size, int value); int* philos_int_append(int* array, int* size, int value);
int* remove_element_int_array(int* array, int* size, int index); int* remove_element_int_array(int* array, int* size, int item_to_delete);
// Gtk functions // Gtk functions
#ifdef __GTK_H__ #ifdef __GTK_H__

@ -257,7 +257,7 @@ void edit_generate_cmd() {
split_simvol[1] = '\0'; split_simvol[1] = '\0';
} }
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(edit_widgets->chkCPULimitEdit))) { if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(edit_widgets->chkCPULimitEdit))) {
size_bite = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(edit_widgets->spinCPULimitEdit)); size_bite = (int)gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(edit_widgets->spinCPULimitEdit));
str_cmd = yon_char_unite(str_cmd, split_simvol, str_cmd = yon_char_unite(str_cmd, split_simvol,
"CPUQuota=", "CPUQuota=",
yon_char_from_int(size_bite), yon_char_from_int(size_bite),

Loading…
Cancel
Save