From 19f2b9477746871c44a7b76b9afe5bf1da1dd912 Mon Sep 17 00:00:00 2001 From: Igor Belitskiy Date: Tue, 30 May 2023 17:20:10 +0600 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=BA=D1=83=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BD=D1=84=D0=B8=D0=B3=D1=83=D1=80=D0=B0=D1=86=D0=B8=D0=B8,?= =?UTF-8?q?=20=D0=BD=D0=B5=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5?= =?UTF-8?q?=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/ubl-settings-resourcequota.c | 89 ++++++++++++++++++++++++----- source/ubl-settings-resourcequota.h | 4 +- source/ubl-strings.h | 4 ++ ubl-settings-resourcequota.glade | 5 +- 4 files changed, 86 insertions(+), 16 deletions(-) diff --git a/source/ubl-settings-resourcequota.c b/source/ubl-settings-resourcequota.c index 32eb766..613dbc6 100644 --- a/source/ubl-settings-resourcequota.c +++ b/source/ubl-settings-resourcequota.c @@ -260,7 +260,7 @@ void load_global_cfg() { void template_cfg(char* cmd) { int size = 0; - int index = 0; + int index_quotas = 0; char** cfg = yon_config_load(cmd, &size); for (int index = 0; index < size; index++) { char* str_key_value = yon_char_new(cfg[index]); @@ -271,12 +271,73 @@ void template_cfg(char* cmd) { size_t length = strlen(str_key_value); str_key_value = yon_char_divide(str_key_value, length-2); } + str_split_key(str_key, index_quotas); str_split_value(str_key_value, index); - index++; + index_quotas++; } } + if (index_quotas != 0) { + fill_tree_view(0, size); + } + + +} +void str_split_key(char* value, int index) { + yon_char_divide_search(value, "[", -1); + value = yon_char_divide_search(value, "]", -1); + if (strstr(value, ".") != NULL) { + if (strstr(value, ".slice") != NULL) { + main_config.quota_volume = yon_char_parsed_append(main_config.quota_volume, &index, value); + index--; + main_config.type_quota_size = philos_int_append(main_config.type_quota_size, &index, 4); + index--; + main_config.quota_volume = yon_char_parsed_append(main_config.type_quota, &index, STR_PROCESS); + index--; + } + else if (strstr(value, ".service") != NULL) { + main_config.quota_volume = yon_char_parsed_append(main_config.quota_volume, &index, value); + index--; + main_config.type_quota_size = philos_int_append(main_config.type_quota_size, &index, 3); + index--; + main_config.quota_volume = yon_char_parsed_append(main_config.type_quota, &index, STR_SLICE); + index--; + } + else { + main_config.quota_volume = yon_char_parsed_append(main_config.quota_volume, &index, value); + index--; + main_config.type_quota_size = philos_int_append(main_config.type_quota_size, &index, -1); + index--; + main_config.quota_volume = yon_char_parsed_append(main_config.type_quota, &index, "-"); + index--; + } + + } + else { + int user_size = 0; + char** arr_users = philos_list_user(&user_size); + for (int user_index = 0; user_index < user_size; user_index++) { + // Пользователь + if (strcmp(arr_users[user_index], value) != 0) { + main_config.type_quota_size = philos_int_append(main_config.type_quota_size, &index, 0); + index--; + main_config.quota_volume = yon_char_parsed_append(main_config.quota_volume, &index, value); + index--; + main_config.quota_volume = yon_char_parsed_append(main_config.type_quota, &index, STR_USER); + index--; + } + // Группа + else { + main_config.type_quota_size = philos_int_append(main_config.type_quota_size, &index, 1); + index--; + main_config.quota_volume = yon_char_parsed_append(main_config.quota_volume, &index, value); + index--; + main_config.quota_volume = yon_char_parsed_append(main_config.type_quota, &index, STR_GROUP); + index--; + } + } + } + } - void str_split_value(char* values, int index) { char* new_value = yon_char_new(values); int size = 0; @@ -358,6 +419,11 @@ void set_pow_size(char* str_find, int* array_size, char** array_data , int index index--; } if (strstr(str_find,"-") == NULL) { + if (str_find[0] == '\"') { + yon_char_divide(str_find, 0); + size_t length = strlen(str_find); + str_find = yon_char_divide(str_find, length-2); + } size_t length = strlen(str_find); str_find = yon_char_divide(str_find, length-2); array_data = yon_char_parsed_append(array_data, &index, str_find); @@ -365,16 +431,6 @@ void set_pow_size(char* str_find, int* array_size, char** array_data , int index else { array_data = yon_char_parsed_append(array_data, &index, "-"); } - GtkTreeIter iter; - gtk_list_store_append(main_config.list,&iter); - gtk_list_store_set(main_config.list,&iter,0,main_config.type_quota[index], - 1,main_config.quota_volume[index], - 2,main_config.soft_raw_limit[index], - 3,main_config.hard_raw_limit[index], - 4,main_config.swap[index], - 5,main_config.cpu_limit[index], - 6,main_config.i_o_limit_read[index], - 7,main_config.i_o_limit_write[index],-1); } @@ -453,6 +509,11 @@ void tree_view_add(int index) { main_config.i_o_limit_read_size = philos_int_append(main_config.i_o_limit_read_size, &main_config.size_tree_view, add_get_read_device_size()); 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); +} + +void fill_tree_view(int start, int size) { + for (int index = start; index < size; index++) { GtkTreeIter iter; gtk_list_store_append(main_config.list,&iter); gtk_list_store_set(main_config.list,&iter,0,main_config.type_quota[index], @@ -463,7 +524,9 @@ void tree_view_add(int index) { 5,main_config.cpu_limit[index], 6,main_config.i_o_limit_read[index], 7,main_config.i_o_limit_write[index],-1); + } } + int tree_view_edit() { int index = 0; GtkTreeIter iter; diff --git a/source/ubl-settings-resourcequota.h b/source/ubl-settings-resourcequota.h index f9e6314..57a56b5 100755 --- a/source/ubl-settings-resourcequota.h +++ b/source/ubl-settings-resourcequota.h @@ -181,4 +181,6 @@ void load_system_cfg(); void load_global_cfg(); void template_cfg(char* cmd); void str_split_value(char* values, int index); -void set_pow_size(char* str_find, int* array_size, char** array_data, int index); \ No newline at end of file +void set_pow_size(char* str_find, int* array_size, char** array_data, int index); +void str_split_key(char* value, int index); +void fill_tree_view(int start, int size); \ No newline at end of file diff --git a/source/ubl-strings.h b/source/ubl-strings.h index 2bc0e69..2d732c4 100644 --- a/source/ubl-strings.h +++ b/source/ubl-strings.h @@ -23,6 +23,10 @@ #define PROJECT_HOME_LABEL _("Project Home Page") #define NOTHING_CHOSEN_LABEL _("Nothing were chosen") +#define STR_USER _("User") +#define STR_GROUP _("Group") +#define STR_PROCESS _("Process") +#define STR_SLICE _("Slice") #define GLOBAL_LOAD_SUCCESS _("Global configuration loading succseeded.") #define LOCAL_LOAD_SUCCESS _("Local configuration loading succseeded.") diff --git a/ubl-settings-resourcequota.glade b/ubl-settings-resourcequota.glade index f16fa4c..c9045b9 100644 --- a/ubl-settings-resourcequota.glade +++ b/ubl-settings-resourcequota.glade @@ -2736,9 +2736,10 @@ translated and supported by community. 640 500 False - 800 - 600 + 700 + 500 com.ublinux.ubl-settings-resourcequota + center True