|
|
#include "ubl-settings-resourcequota.h"
|
|
|
|
|
|
config main_config;
|
|
|
main_window *widgets;
|
|
|
/**on_close_subwindow(GtkWidget *self)
|
|
|
* [EN]
|
|
|
* Closes window in which [self] is contained.
|
|
|
* [RU]
|
|
|
* Закрывает окно, в котором расположен виджет [self].
|
|
|
*/
|
|
|
void on_close_subwindow(GtkWidget *self){
|
|
|
gtk_widget_destroy(gtk_widget_get_toplevel(self));
|
|
|
}
|
|
|
|
|
|
/**yon_open_browser(GtkWidget *self, char *link)
|
|
|
* [EN]
|
|
|
* Opens browser with [link] link.
|
|
|
* [RU]
|
|
|
* Открывает браузер с [link] ссылкой.
|
|
|
*/
|
|
|
void yon_open_browser(GtkWidget *self, char *link){
|
|
|
yon_ubl_browser_window_open(link,TITLE_LABEL);
|
|
|
}
|
|
|
|
|
|
/**on_open_documentation_confirmation(GtkWidget *self, char *link)
|
|
|
* [EN]
|
|
|
* Opens confirmation window for [link] link.
|
|
|
* [RU]
|
|
|
* Открывает окно подтверждение перехода по ссылке [link].
|
|
|
*/
|
|
|
void on_open_documentation_confirmation(GtkWidget *self, char *link){
|
|
|
if (main_config.always_open_documentation==0){
|
|
|
GtkBuilder *builder = gtk_builder_new_from_resource(glade_path);
|
|
|
documentation_confirmation_window *widgets = malloc(sizeof(documentation_confirmation_window));
|
|
|
widgets->Window = yon_gtk_builder_get_widget(builder,"helpConfirmationWindow");
|
|
|
widgets->AcceptButton = yon_gtk_builder_get_widget(builder,"ReadHelpButton");
|
|
|
widgets->CloseButton = yon_gtk_builder_get_widget(builder,"CancelHelpButton");
|
|
|
widgets->HatText = yon_gtk_builder_get_widget(builder,"webHeaderNameLabel");
|
|
|
widgets->HeaderText = yon_gtk_builder_get_widget(builder,"helpHeader");
|
|
|
widgets->InfoText = yon_gtk_builder_get_widget(builder,"helpText");
|
|
|
widgets->AlwaysOpenCheck = yon_gtk_builder_get_widget(builder,"AlwaysOpenDocumentationCheckbox");
|
|
|
gtk_label_set_text(GTK_LABEL(widgets->HatText),TITLE_LABEL);
|
|
|
gtk_label_set_text(GTK_LABEL(widgets->HeaderText),HELP_TITLE_LABEL);
|
|
|
gtk_label_set_text(GTK_LABEL(widgets->InfoText),HELP_INFO_LABEL);
|
|
|
gtk_button_set_label(GTK_BUTTON(widgets->AcceptButton),OPEN_HELP_LABEL);
|
|
|
gtk_button_set_label(GTK_BUTTON(widgets->AlwaysOpenCheck),HELP_ALWAYS_OPEN_LABEL);
|
|
|
gtk_button_set_label(GTK_BUTTON(widgets->CloseButton),CANCEL_LABEL);
|
|
|
gtk_widget_show_all(widgets->Window);
|
|
|
g_signal_connect(G_OBJECT(widgets->CloseButton),"clicked",G_CALLBACK(on_close_subwindow),NULL);
|
|
|
g_signal_connect(G_OBJECT(widgets->AcceptButton),"clicked",G_CALLBACK(yon_open_browser),yon_char_new(link));
|
|
|
g_signal_connect(G_OBJECT(widgets->AcceptButton),"clicked",G_CALLBACK(on_close_subwindow),NULL);
|
|
|
|
|
|
|
|
|
} else {
|
|
|
yon_open_browser(self,link);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**on_link(GtkWidget *self, char* uri, gpointer user_data)
|
|
|
* [EN]
|
|
|
* Signal for hadnling AboutDialog links.
|
|
|
* Connect to "activate-link" signal.
|
|
|
* [self] is AboutDialog window;
|
|
|
* [uri] is activated link;
|
|
|
* [user_data] is pointer for user data, hasn't used in standard handler;
|
|
|
* [RU]
|
|
|
* Функция для обработки сигнала нажатия на ссылку окна AboutDialog.
|
|
|
* Присоединять к сигналу "activate-link".
|
|
|
* [self] - окно AboutDialog;
|
|
|
* [uri] - ссылка, по которой совершается переход;
|
|
|
* [user_data] - указатель на любые другие данные, не используется в стандартном обработчике;
|
|
|
*/
|
|
|
void on_link(GtkWidget *self, char* uri, gpointer user_data){
|
|
|
gtk_widget_destroy(self);
|
|
|
on_open_documentation_confirmation(self,uri);
|
|
|
}
|
|
|
|
|
|
/**on_about()
|
|
|
* [EN]
|
|
|
* Function for setting up and showing AboutDialog.
|
|
|
* Connect it to "activate" signal of Documentation MenuItem.
|
|
|
* [RU]
|
|
|
* Функиця для настройки и показа окна AboutDialog.
|
|
|
* Присоединять к сигналу "activate" кнопки справки типа MenuItem.
|
|
|
*/
|
|
|
void on_about(){
|
|
|
GtkBuilder *builder=gtk_builder_new_from_resource(glade_path);
|
|
|
GtkWidget *window=yon_gtk_builder_get_widget(builder,"AboutWindow");
|
|
|
GtkWidget *title=yon_gtk_builder_get_widget(builder,"headerAboutTopic");
|
|
|
GtkWidget *hideButtonBox=yon_gtk_builder_get_widget(builder,"buttonBoxHide");
|
|
|
gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(window),version_application);
|
|
|
gtk_about_dialog_set_website_label(GTK_ABOUT_DIALOG(window),PROJECT_HOME_LABEL);
|
|
|
gtk_label_set_text(GTK_LABEL(title),TITLE_LABEL);
|
|
|
g_signal_connect(G_OBJECT(window),"activate-link",G_CALLBACK(on_link),NULL);
|
|
|
gtk_widget_set_visible(hideButtonBox,0);
|
|
|
gtk_widget_destroy(hideButtonBox);
|
|
|
gtk_widget_show(window);
|
|
|
}
|
|
|
|
|
|
void config_init(){
|
|
|
main_config.always_open_documentation=0;
|
|
|
main_config.win_height=0;
|
|
|
main_config.win_width=0;
|
|
|
main_config.win_pos_x=0;
|
|
|
main_config.win_pos_y=0;
|
|
|
main_config.socket_id=-1;
|
|
|
main_config.save_socket_id=-1;
|
|
|
main_config.load_socket_id=-1;
|
|
|
main_config.lock_help=0;
|
|
|
main_config.lock_help=0;
|
|
|
main_config.lock_load_global=0;
|
|
|
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_config.flag_set_data = 0;
|
|
|
main_config.i_o_limit_read_size=NULL;
|
|
|
main_config.i_o_limit_write_size=NULL;
|
|
|
main_config.i_o_limit_write=NULL;
|
|
|
main_config.i_o_limit_read=NULL;
|
|
|
}
|
|
|
|
|
|
main_window *setup_window(){
|
|
|
/* Widgets getting | Получение виджетов */
|
|
|
widgets = malloc(sizeof(main_window));
|
|
|
GtkBuilder *builder = gtk_builder_new_from_resource(glade_path);
|
|
|
widgets->Window = yon_gtk_builder_get_widget(builder,"MainWindow");
|
|
|
|
|
|
widgets->btnDelQuotas = yon_gtk_builder_get_widget(builder,"btnDelQuotas");
|
|
|
widgets->treeViewMain = yon_gtk_builder_get_widget(builder,"treeViewMain");
|
|
|
widgets->tvc0 = GTK_TREE_VIEW_COLUMN(gtk_builder_get_object(builder,"tvc0"));
|
|
|
widgets->tvc1 = GTK_TREE_VIEW_COLUMN(gtk_builder_get_object(builder,"tvc1"));
|
|
|
widgets->tvc2 = GTK_TREE_VIEW_COLUMN(gtk_builder_get_object(builder,"tvc2"));
|
|
|
widgets->tvc3 = GTK_TREE_VIEW_COLUMN(gtk_builder_get_object(builder,"tvc3"));
|
|
|
widgets->tvc4 = GTK_TREE_VIEW_COLUMN(gtk_builder_get_object(builder,"tvc4"));
|
|
|
widgets->tvc5 = GTK_TREE_VIEW_COLUMN(gtk_builder_get_object(builder,"tvc5"));
|
|
|
widgets->tvc6 = GTK_TREE_VIEW_COLUMN(gtk_builder_get_object(builder,"tvc6"));
|
|
|
widgets->tvc7 = GTK_TREE_VIEW_COLUMN(gtk_builder_get_object(builder,"tvc7"));
|
|
|
|
|
|
widgets->btnMainShowAllEmpty = yon_gtk_builder_get_widget(builder,"btnMainShowAllEmpty");
|
|
|
widgets->btnMainShowCoreStream = yon_gtk_builder_get_widget(builder,"btnMainShowCoreStream");
|
|
|
|
|
|
main_config.list = GTK_LIST_STORE(gtk_builder_get_object(builder, "liststore"));
|
|
|
widgets->vteInformation = yon_gtk_builder_get_widget(builder,"vteInformation");
|
|
|
widgets->vteDispatcher = yon_gtk_builder_get_widget(builder,"vteDispatcher");
|
|
|
widgets->vteProcesses = yon_gtk_builder_get_widget(builder,"vteProcesses");
|
|
|
widgets->cbtMainInfo = yon_gtk_builder_get_widget(builder,"cbtMainInfo");
|
|
|
widgets->cbtMainInfoLevel2 = yon_gtk_builder_get_widget(builder,"cbtMainInfoLevel2");
|
|
|
widgets->spinUpdateDispatcher = yon_gtk_builder_get_widget(builder,"spinUpdateDispatcher");
|
|
|
widgets->btnUpdateDispatcher = yon_gtk_builder_get_widget(builder,"btnUpdateDispatcher");
|
|
|
widgets->btnSaveCfg = yon_gtk_builder_get_widget(builder,"btnSaveCfg");
|
|
|
widgets->notebookMain = yon_gtk_builder_get_widget(builder,"notebookMain");
|
|
|
|
|
|
widgets->btnEdit = yon_gtk_builder_get_widget(builder,"btnEdit");
|
|
|
widgets->btnAdd = yon_gtk_builder_get_widget(builder,"btnAdd");
|
|
|
widgets->btnInfo = yon_gtk_builder_get_widget(builder,"btnInfo");
|
|
|
widgets->HatLabel = yon_gtk_builder_get_widget(builder,"headerTopic");
|
|
|
widgets->PlugBox = yon_gtk_builder_get_widget(builder,"plugBox");
|
|
|
|
|
|
widgets->HeadOverlay = yon_gtk_builder_get_widget(builder,"HeadOverlay");
|
|
|
widgets->HeadImage = yon_gtk_builder_get_widget(builder,"HeadBackgroundImage");
|
|
|
widgets->HeadBox = yon_gtk_builder_get_widget(builder,"HeaderBox");
|
|
|
widgets->HeadTitleLabel = yon_gtk_builder_get_widget(builder,"HeaderTitleLabel");
|
|
|
widgets->HeadInfoLabel = yon_gtk_builder_get_widget(builder,"HeaderInfoLabel");
|
|
|
|
|
|
widgets->StatusBox = yon_gtk_builder_get_widget(builder,"mainStatusBox");
|
|
|
widgets->StatusIcon = yon_gtk_builder_get_widget(builder,"mainStatusIcon");
|
|
|
widgets->StatusLabel = yon_gtk_builder_get_widget(builder,"mainStatusLabel");
|
|
|
|
|
|
widgets->SaveLabel = yon_gtk_builder_get_widget(builder,"headerSaveConfigLabel");
|
|
|
widgets->SaveMenuItem = yon_gtk_builder_get_widget(builder,"SaveGlobalLocalConfigurationMenuItem");
|
|
|
widgets->SaveGlobalMenuItem = yon_gtk_builder_get_widget(builder,"SaveGlobalConfigurationMenuItem");
|
|
|
widgets->SaveLocalMenuItem = yon_gtk_builder_get_widget(builder,"SaveLocalConfigurationMenuItem");
|
|
|
widgets->RightBox = yon_gtk_builder_get_widget(builder,"HeaderRightBox");
|
|
|
|
|
|
widgets->LoadLabel = yon_gtk_builder_get_widget(builder,"headerLoadConfigLabel");
|
|
|
widgets->LoadGlobalMenuItem = yon_gtk_builder_get_widget(builder,"LoadGlobalConfigurationMenuItem");
|
|
|
widgets->LoadLocalMenuItem = yon_gtk_builder_get_widget(builder,"LoadLocalConfigurationMenuItem");
|
|
|
widgets->LeftBox = yon_gtk_builder_get_widget(builder,"HeaderLeftBox");
|
|
|
|
|
|
widgets->DocumentationMenuItem = yon_gtk_builder_get_widget(builder,"DocumentationMenuItem");
|
|
|
widgets->AboutMenuItem = yon_gtk_builder_get_widget(builder,"AboutMenuItem");
|
|
|
|
|
|
widgets->btnShowFilters = yon_gtk_builder_get_widget(builder,"btnShowFilters");
|
|
|
if (main_config.lock_load_global == 1){
|
|
|
gtk_widget_set_sensitive(widgets->LoadGlobalMenuItem,0);
|
|
|
}
|
|
|
if (main_config.lock_save_global == 1){
|
|
|
gtk_widget_set_sensitive(widgets->SaveGlobalMenuItem,0);
|
|
|
gtk_widget_set_sensitive(widgets->SaveMenuItem,0);
|
|
|
}
|
|
|
if (main_config.lock_save_local == 1){
|
|
|
gtk_widget_set_sensitive(widgets->SaveLocalMenuItem,0);
|
|
|
gtk_widget_set_sensitive(widgets->SaveMenuItem,0);
|
|
|
}
|
|
|
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;
|
|
|
}
|
|
|
|
|
|
void main_update_dispatcher() {
|
|
|
int second = gtk_spin_button_get_value(GTK_SPIN_BUTTON(widgets->spinUpdateDispatcher));
|
|
|
char* str_second = yon_char_from_int(second);
|
|
|
char *cmd = yon_char_get_augumented("systemd-cgtop -d ", str_second);
|
|
|
yon_terminal_integrated_launch(widgets->vteDispatcher, cmd, NULL, NULL);
|
|
|
free(str_second);
|
|
|
free(cmd);
|
|
|
}
|
|
|
|
|
|
void main_update_processes() {
|
|
|
char* cmd = NULL;
|
|
|
gboolean active_all_empty = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->btnMainShowAllEmpty));
|
|
|
gboolean active_core_stream = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->btnMainShowCoreStream));
|
|
|
if (active_core_stream == 1) {
|
|
|
cmd = "systemd-cgls --no-page -l";
|
|
|
}
|
|
|
else if (active_all_empty == 1) {
|
|
|
cmd = "systemd-cgls --no-page -k";
|
|
|
}
|
|
|
else if (active_all_empty == 1 && active_core_stream == 1) {
|
|
|
cmd = "systemd-cgls --no-page -l -k";
|
|
|
}
|
|
|
else {
|
|
|
cmd = "systemd-cgls --no-page";
|
|
|
}
|
|
|
yon_terminal_integrated_launch(widgets->vteProcesses, cmd, NULL, NULL);
|
|
|
}
|
|
|
|
|
|
void main_update_information() {
|
|
|
int menu_id = gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->cbtMainInfo));
|
|
|
char* cmd = NULL;
|
|
|
config_str fill_cmb_2 = NULL;
|
|
|
int size = 0;
|
|
|
if (menu_id == 0) {
|
|
|
fill_cmb_2 = philos_list_user(&size);
|
|
|
|
|
|
}
|
|
|
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) {
|
|
|
fill_cmb_2 = philos_pars_terminal_systemd_cgls(CMD_GET_SLICE_SERVICE, ".service", &size);
|
|
|
philos_array_string_remove_char(&fill_cmb_2, "\n", size);
|
|
|
}
|
|
|
else if (menu_id == 3) {
|
|
|
fill_cmb_2 = philos_pars_terminal_systemd_cgls(CMD_GET_SLICE_SERVICE, ".slice", &size);
|
|
|
philos_array_string_remove_char(&fill_cmb_2, "\n", size);
|
|
|
}
|
|
|
if (menu_id >= 0) {
|
|
|
g_signal_handlers_disconnect_by_func(G_OBJECT(widgets->cbtMainInfoLevel2), main_cbx_2_event, NULL);
|
|
|
gtk_combo_box_text_remove_all(GTK_COMBO_BOX_TEXT(widgets->cbtMainInfoLevel2));
|
|
|
philos_fill_combo_box_text(widgets->cbtMainInfoLevel2, fill_cmb_2, size);
|
|
|
g_signal_connect(G_OBJECT(widgets->cbtMainInfoLevel2),"changed",G_CALLBACK(main_cbx_2_event), NULL);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void load_system_cfg() {
|
|
|
main_config.flag_load = 0;
|
|
|
template_load_cfg(CMD_LOAD_SYSTEM);
|
|
|
yon_ubl_status_box_render(LOCAL_LOAD_SUCCESS, BACKGROUND_IMAGE_SUCCESS_TYPE);
|
|
|
}
|
|
|
|
|
|
void load_global_cfg() {
|
|
|
main_config.flag_load = 1;
|
|
|
template_load_cfg(CMD_LOAD_GLOBAL);
|
|
|
yon_ubl_status_box_render(GLOBAL_LOAD_SUCCESS,BACKGROUND_IMAGE_SUCCESS_TYPE);
|
|
|
}
|
|
|
|
|
|
void clear_array() {
|
|
|
philos_free_string_array(&main_config.type_quota, main_config.size_tree_view);
|
|
|
philos_free_string_array(&main_config.quota_volume , main_config.size_tree_view);
|
|
|
philos_free_int_array(&main_config.soft_raw_limit, main_config.size_tree_view);
|
|
|
philos_free_int_array(&main_config.hard_raw_limit, main_config.size_tree_view);
|
|
|
philos_free_int_array(&main_config.swap , main_config.size_tree_view);
|
|
|
philos_free_int_array(&main_config.cpu_limit, main_config.size_tree_view);
|
|
|
philos_free_int_array_n2(&main_config.i_o_limit_read, main_config.size_tree_view);
|
|
|
philos_free_int_array_n2(&main_config.i_o_limit_write, main_config.size_tree_view);
|
|
|
philos_free_string_array_n3(&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);
|
|
|
philos_free_int_array(&main_config.soft_raw_limit_size, main_config.size_tree_view);
|
|
|
philos_free_int_array(&main_config.hard_raw_limit_size, main_config.size_tree_view);
|
|
|
philos_free_int_array(&main_config.swap_size, main_config.size_tree_view);
|
|
|
philos_free_int_array(&main_config.cpu_limit_size, main_config.size_tree_view);
|
|
|
philos_free_int_array_n2(&main_config.i_o_limit_read_size, main_config.size_tree_view);
|
|
|
philos_free_int_array_n2(&main_config.i_o_limit_write_size, main_config.size_tree_view);
|
|
|
gtk_list_store_clear(main_config.list);
|
|
|
main_config.i_o_limit_read = NULL;
|
|
|
main_config.i_o_limit_read_size = NULL;
|
|
|
main_config.i_o_limit_write = NULL;
|
|
|
main_config.i_o_limit_write_size = NULL;
|
|
|
main_config.disk = NULL;
|
|
|
|
|
|
main_config.size_tree_view = 0;
|
|
|
}
|
|
|
|
|
|
void template_load_cfg(char* cmd) {
|
|
|
clear_array();
|
|
|
int size = 0;
|
|
|
char** cfg = yon_config_load(cmd, &size);
|
|
|
philos_array_string_remove_char(&cfg, "\n", size);
|
|
|
for (int index = 0; index < size; index++) {
|
|
|
char* str_key_value = yon_char_new(cfg[index]);
|
|
|
char* str_key = yon_char_divide_search(str_key_value, "=",-1);
|
|
|
if (yon_char_find_count(str_key, "CGROUP_QUOTA") != 0) {
|
|
|
if (str_key_value[0] == '\"') {
|
|
|
yon_char_divide(str_key_value, 0);
|
|
|
size_t length = strlen(str_key_value);
|
|
|
str_key_value = yon_char_divide(str_key_value, length-1);
|
|
|
}
|
|
|
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++;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
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) {
|
|
|
philos_set_pow_size_memory("-", &main_config.type_quota_size, index, array_size_pow);
|
|
|
philos_set_size_memory_integer_char("-", &main_config.type_quota, index);
|
|
|
|
|
|
philos_set_pow_size_memory("-", &main_config.quota_volume_size, index, array_size_pow);
|
|
|
philos_set_size_memory_integer_char("-", &main_config.quota_volume, index);
|
|
|
|
|
|
philos_set_pow_size_memory("-", &main_config.cpu_limit_size, index, array_size_pow);
|
|
|
set_size_memory_integer("-", &main_config.cpu_limit, index);
|
|
|
|
|
|
philos_set_pow_size_memory("-", &main_config.soft_raw_limit_size, index, array_size_pow);
|
|
|
set_size_memory_integer("-", &main_config.soft_raw_limit, index);
|
|
|
|
|
|
philos_set_pow_size_memory("-", &main_config.hard_raw_limit_size, index, array_size_pow);
|
|
|
set_size_memory_integer("-", &main_config.hard_raw_limit, index);
|
|
|
|
|
|
philos_set_pow_size_memory("-", &main_config.swap_size, index, array_size_pow);
|
|
|
set_size_memory_integer("-",&main_config.swap , index);
|
|
|
|
|
|
int* array_limit = NULL;
|
|
|
char** array_disk = NULL;
|
|
|
int index_n2 = 0;
|
|
|
array_limit = philos_int_append(array_limit, &index_n2, -3);
|
|
|
index_n2--;
|
|
|
array_disk = yon_char_parsed_append(array_disk, &index_n2, "-");
|
|
|
array_limit = philos_int_append(array_limit, &index_n2, -2);
|
|
|
index_n2--;
|
|
|
array_disk = yon_char_parsed_append(array_disk, &index_n2, NULL);
|
|
|
main_config.i_o_limit_read = yon_remalloc(main_config.i_o_limit_read, (index + 1) * sizeof(int*));
|
|
|
main_config.i_o_limit_read_size = yon_remalloc(main_config.i_o_limit_read_size, (index + 1) * sizeof(int*));
|
|
|
main_config.disk = yon_remalloc(main_config.disk, (index + 1) * sizeof(char**));
|
|
|
main_config.i_o_limit_write = yon_remalloc(main_config.i_o_limit_write, (index + 1) * sizeof(int*));
|
|
|
main_config.i_o_limit_write_size = yon_remalloc(main_config.i_o_limit_write_size, (index + 1) * sizeof(int*));
|
|
|
main_config.disk = yon_remalloc(main_config.disk, (index + 1) * sizeof(char**));
|
|
|
|
|
|
philos_array_int_copy(&main_config.i_o_limit_read[index], &array_limit);
|
|
|
philos_array_int_copy(&main_config.i_o_limit_read_size[index], &array_limit);
|
|
|
yon_char_parsed_copy(&main_config.disk[index], &array_disk);
|
|
|
|
|
|
philos_array_int_copy(&main_config.i_o_limit_write[main_config.size_tree_view], &array_limit);
|
|
|
philos_array_int_copy(&main_config.i_o_limit_write_size[main_config.size_tree_view], &array_limit);
|
|
|
yon_char_parsed_copy(&main_config.disk[main_config.size_tree_view], &array_disk);
|
|
|
philos_free_int_array(&array_limit, 1);
|
|
|
philos_free_string_array(&array_disk, 1);
|
|
|
}
|
|
|
|
|
|
void str_split_key(char* source_value, int index) {
|
|
|
char* value = yon_char_new(source_value);
|
|
|
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.type_quota = 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.type_quota = 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 = 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 (strstr(arr_users[user_index], value) != NULL) {
|
|
|
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.type_quota = 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.type_quota = 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;
|
|
|
char* key = NULL;
|
|
|
char* value = NULL;
|
|
|
char** arr_values = philos_str_split(new_value, &size, ",");
|
|
|
if (arr_values == NULL) {
|
|
|
return;
|
|
|
}
|
|
|
init_cfg_array(index);
|
|
|
char* value_i = NULL;
|
|
|
for (int index_1 = 0; index_1 < size; index_1++) {
|
|
|
value = yon_char_new(arr_values[index_1]);
|
|
|
key = yon_char_divide_search(value, "=", -1);
|
|
|
if (yon_char_find_count(key, "IOReadBandwidthMax") != 0) {
|
|
|
get_param_io_limit(arr_values, index_1, size,index, "IOReadBandwidthMax");
|
|
|
}
|
|
|
if (yon_char_find_count(key, "IOWriteBandwidthMax") != 0) {
|
|
|
get_param_io_limit(arr_values, index_1, size,index, "IOWriteBandwidthMax");
|
|
|
}
|
|
|
if (yon_char_find_count(key, "MemoryHigh") != 0) {
|
|
|
philos_set_pow_size_memory(yon_char_new(value), &main_config.soft_raw_limit_size, index, array_size_pow);
|
|
|
set_size_memory_integer(yon_char_new(value), &main_config.soft_raw_limit, index);
|
|
|
}
|
|
|
if (yon_char_find_count(key, "MemoryMax") != 0) {
|
|
|
philos_set_pow_size_memory(yon_char_new(value), &main_config.hard_raw_limit_size, index, array_size_pow);
|
|
|
set_size_memory_integer(yon_char_new(value), &main_config.hard_raw_limit, index);
|
|
|
}
|
|
|
if (yon_char_find_count(key, "MemorySwapMax") != 0) {
|
|
|
philos_set_pow_size_memory(yon_char_new(value), &main_config.swap_size, index, array_size_pow);
|
|
|
set_size_memory_integer(yon_char_new(value), &main_config.swap, index);
|
|
|
}
|
|
|
if (yon_char_find_count(key, "CPUQuota") != 0) {
|
|
|
philos_set_pow_size_memory(yon_char_new(value), &main_config.cpu_limit_size, index, array_size_pow);
|
|
|
set_size_memory_integer(yon_char_new(value), &main_config.cpu_limit, index);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
void get_param_io_limit(char** arr_values, int index_start, int size, int index_n1, char *key_find) {
|
|
|
int* array_limit = NULL;
|
|
|
char** array_disk = NULL;
|
|
|
int* array_limit_size = NULL;
|
|
|
int index_n2 = 0;
|
|
|
int flag_parsed = 0;
|
|
|
int flag_exit = 0;
|
|
|
for (int i = index_start; i < size; i++) {
|
|
|
if (strstr(arr_values[i], "BandwidthMax")!=NULL ) {
|
|
|
char* value = yon_char_new(arr_values[i]);
|
|
|
yon_char_divide_search(value, "=", -1);
|
|
|
if (strstr(arr_values[i], key_find)!=NULL) {
|
|
|
// Найден ключ в массив
|
|
|
char* disk = yon_char_divide_search(yon_char_new(value), " ", -1);
|
|
|
array_disk = yon_char_parsed_append(array_disk, &index_n2, disk);
|
|
|
index_n2--;
|
|
|
philos_set_pow_size_memory(yon_char_new(value), &array_limit_size, index_n2, array_size_pow);
|
|
|
set_size_memory_integer(yon_char_new(value), &array_limit, index_n2);
|
|
|
flag_parsed = 1;
|
|
|
index_n2++;
|
|
|
}
|
|
|
else if (strstr(arr_values[i], "BandwidthMax")!=NULL &&
|
|
|
strstr(arr_values[i], key_find)==NULL && flag_parsed == 1) {
|
|
|
// Найден ключ в массив, но не тот
|
|
|
flag_exit = 1;
|
|
|
}
|
|
|
free(value);
|
|
|
}
|
|
|
else if (flag_parsed == 1) {
|
|
|
char* disk = yon_char_divide_search(yon_char_new(arr_values[i]), " ", -1);
|
|
|
array_disk = yon_char_parsed_append(array_disk, &index_n2, disk);
|
|
|
index_n2--;
|
|
|
philos_set_pow_size_memory(yon_char_new(arr_values[i]), &array_limit_size, index_n2, array_size_pow);
|
|
|
set_size_memory_integer(yon_char_new(arr_values[i]), &array_limit, index_n2);
|
|
|
index_n2++;
|
|
|
}
|
|
|
else if (flag_exit == 1) {
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
if (index_n2 != 0) {
|
|
|
array_limit = philos_int_append(array_limit, &index_n2, -2);
|
|
|
index_n2--;
|
|
|
array_disk = yon_char_parsed_append(array_disk, &index_n2, NULL);
|
|
|
index_n2--;
|
|
|
array_limit_size = philos_int_append(array_limit_size, &index_n2, -2);
|
|
|
if (strstr(key_find, "IOReadBandwidthMax")!=NULL) {
|
|
|
main_config.i_o_limit_read = yon_remalloc(main_config.i_o_limit_read, (index_n1 + 1) * sizeof(int*));
|
|
|
main_config.i_o_limit_read_size = yon_remalloc(main_config.i_o_limit_read_size, (index_n1 + 1) * sizeof(int*));
|
|
|
main_config.disk = yon_remalloc(main_config.disk, (index_n1 + 1) * sizeof(char**));
|
|
|
philos_array_int_copy(&main_config.i_o_limit_read[index_n1], &array_limit);
|
|
|
philos_array_int_copy(&main_config.i_o_limit_read_size[index_n1], &array_limit_size);
|
|
|
yon_char_parsed_copy(&main_config.disk[index_n1], &array_disk);
|
|
|
}
|
|
|
else {
|
|
|
main_config.i_o_limit_write = yon_remalloc(main_config.i_o_limit_write, (index_n1 + 1) * sizeof(int*));
|
|
|
main_config.i_o_limit_write_size = yon_remalloc(main_config.i_o_limit_write_size, (index_n1 + 1) * sizeof(int*));
|
|
|
main_config.disk = yon_remalloc(main_config.disk, (index_n1 + 1) * sizeof(char**));
|
|
|
philos_array_int_copy(&main_config.i_o_limit_write[index_n1], &array_limit);
|
|
|
philos_array_int_copy(&main_config.i_o_limit_write_size[index_n1], &array_limit_size);
|
|
|
yon_char_parsed_copy(&main_config.disk[index_n1], &array_disk);
|
|
|
}
|
|
|
philos_free_int_array(&array_limit, index_n2);
|
|
|
philos_free_string_array(&array_disk, index_n2);
|
|
|
philos_free_int_array(&array_limit_size, index_n2);
|
|
|
}
|
|
|
else {
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void set_size_memory_integer(char* str_find, int** array_data, int index) {
|
|
|
if (strstr(str_find, " ")) {
|
|
|
yon_char_divide_search(str_find, " ", -1);
|
|
|
}
|
|
|
char* simv_del_array[9] = {"K","M","G","T","k","m","g","t","%"};
|
|
|
for (size_t i = 0; i < 9; i++) {
|
|
|
if (strstr(str_find, simv_del_array[i])) {
|
|
|
str_find = yon_char_divide_search(str_find, simv_del_array[i], -1);
|
|
|
}
|
|
|
}
|
|
|
if (strstr(str_find, "-")==NULL) {
|
|
|
*array_data = philos_int_append(*array_data, &index, atoi(str_find));
|
|
|
}
|
|
|
else {
|
|
|
*array_data = philos_int_append(*array_data, &index, -1);
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
void main_cbx_2_event() {
|
|
|
int menu_id = gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->cbtMainInfoLevel2));
|
|
|
char* cmd_text_param = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(widgets->cbtMainInfoLevel2));
|
|
|
char* cmd = NULL;
|
|
|
if (menu_id >= 0) {
|
|
|
cmd = yon_char_unite("systemctl status ", cmd_text_param ," --no-pager", NULL);
|
|
|
yon_terminal_integrated_launch(widgets->vteInformation, cmd, NULL, NULL);
|
|
|
}
|
|
|
if (menu_id >= 0) {
|
|
|
free(cmd_text_param);
|
|
|
}
|
|
|
if (menu_id >= 0) {
|
|
|
free(cmd);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void tree_view_select(GtkWidget *self, main_window *widgets) {
|
|
|
GtkTreeIter iter;
|
|
|
GtkTreeModel *model = GTK_TREE_MODEL(main_config.list);
|
|
|
GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->treeViewMain));
|
|
|
if(gtk_tree_selection_get_selected(selection, &model, &iter)) {
|
|
|
gtk_widget_set_sensitive(widgets->btnAdd,1);
|
|
|
gtk_widget_set_sensitive(widgets->btnDelQuotas,1);
|
|
|
gtk_widget_set_sensitive(widgets->btnEdit,1);
|
|
|
gtk_widget_set_sensitive(widgets->btnInfo,1);
|
|
|
}
|
|
|
else {
|
|
|
gtk_widget_set_sensitive(widgets->btnAdd,1);
|
|
|
gtk_widget_set_sensitive(widgets->btnDelQuotas,0);
|
|
|
gtk_widget_set_sensitive(widgets->btnEdit,0);
|
|
|
gtk_widget_set_sensitive(widgets->btnInfo,0);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void tree_view_add(int index) {
|
|
|
main_config.type_quota = yon_char_parsed_append(main_config.type_quota, &main_config.size_tree_view, add_get_quota_object());
|
|
|
main_config.size_tree_view--;
|
|
|
main_config.quota_volume = yon_char_parsed_append(main_config.quota_volume, &main_config.size_tree_view, add_get_select_device_to_level_2());
|
|
|
main_config.size_tree_view--;
|
|
|
main_config.soft_raw_limit = philos_int_append(main_config.soft_raw_limit, &main_config.size_tree_view, add_get_soft());
|
|
|
main_config.size_tree_view--;
|
|
|
main_config.hard_raw_limit = philos_int_append(main_config.hard_raw_limit, &main_config.size_tree_view, add_get_hard());
|
|
|
main_config.size_tree_view--;
|
|
|
main_config.swap = philos_int_append(main_config.swap, &main_config.size_tree_view, add_get_limit_swap());
|
|
|
main_config.size_tree_view--;
|
|
|
main_config.cpu_limit = philos_int_append(main_config.cpu_limit, &main_config.size_tree_view, add_get_limit_cpu());
|
|
|
main_config.size_tree_view--;
|
|
|
|
|
|
main_config.i_o_limit_read = yon_remalloc(main_config.i_o_limit_read, (main_config.size_tree_view + 1) * sizeof(int*));
|
|
|
main_config.i_o_limit_read_size = yon_remalloc(main_config.i_o_limit_read_size, (main_config.size_tree_view + 1) * sizeof(int*));
|
|
|
main_config.disk = yon_remalloc(main_config.disk, (main_config.size_tree_view + 1) * sizeof(char**));
|
|
|
philos_array_int_copy(&main_config.i_o_limit_read[main_config.size_tree_view], add_get_read_device());
|
|
|
philos_array_int_copy(&main_config.i_o_limit_read_size[main_config.size_tree_view], add_get_read_device_size_pow());
|
|
|
yon_char_parsed_copy(&main_config.disk[main_config.size_tree_view], add_get_select_device());
|
|
|
|
|
|
main_config.i_o_limit_write = yon_remalloc(main_config.i_o_limit_write, (main_config.size_tree_view + 1) * sizeof(int*));
|
|
|
main_config.i_o_limit_write_size = yon_remalloc(main_config.i_o_limit_write_size, (main_config.size_tree_view + 1) * sizeof(int*));
|
|
|
main_config.disk = yon_remalloc(main_config.disk, (main_config.size_tree_view + 1) * sizeof(char**));
|
|
|
philos_array_int_copy(&main_config.i_o_limit_write[main_config.size_tree_view], add_get_write_device());
|
|
|
philos_array_int_copy(&main_config.i_o_limit_write_size[main_config.size_tree_view], add_get_write_device_size_pow());
|
|
|
|
|
|
main_config.type_quota_size = philos_int_append(main_config.type_quota_size, &main_config.size_tree_view, add_get_quota_object_size());
|
|
|
main_config.size_tree_view--;
|
|
|
main_config.quota_volume_size = philos_int_append(main_config.quota_volume_size, &main_config.size_tree_view, -1);
|
|
|
main_config.size_tree_view--;
|
|
|
main_config.soft_raw_limit_size = philos_int_append(main_config.soft_raw_limit_size, &main_config.size_tree_view, add_get_soft_size());
|
|
|
main_config.size_tree_view--;
|
|
|
main_config.hard_raw_limit_size = philos_int_append(main_config.hard_raw_limit_size, &main_config.size_tree_view, add_get_hard_size());
|
|
|
main_config.size_tree_view--;
|
|
|
main_config.swap_size = philos_int_append(main_config.swap_size, &main_config.size_tree_view, add_get_limit_swap_size());
|
|
|
main_config.size_tree_view--;
|
|
|
main_config.cpu_limit_size = philos_int_append(main_config.cpu_limit_size, &main_config.size_tree_view, add_get_limit_cpu_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) {
|
|
|
GtkTreeModel *model = GTK_TREE_MODEL(main_config.list);
|
|
|
if (flag_gui_add == 0) {
|
|
|
g_object_ref(main_config.list);
|
|
|
gtk_list_store_clear(main_config.list);
|
|
|
}
|
|
|
for (int index = start; index < size; index++) {
|
|
|
GtkTreeIter iter;
|
|
|
gtk_list_store_append(main_config.list,&iter);
|
|
|
char* str_io_read = format_io_limit_in_tree_view(main_config.disk, main_config.i_o_limit_read, main_config.i_o_limit_read_size, index);
|
|
|
char* str_io_write = format_io_limit_in_tree_view(main_config.disk, main_config.i_o_limit_write, main_config.i_o_limit_write_size, index);
|
|
|
gtk_list_store_set(main_config.list,&iter,
|
|
|
0,main_config.type_quota[index],
|
|
|
1,main_config.quota_volume[index],
|
|
|
2,philos_format_cfg_str_size_memory("", main_config.soft_raw_limit[index],main_config.soft_raw_limit_size[index]),
|
|
|
3,philos_format_cfg_str_size_memory("", main_config.hard_raw_limit[index],main_config.hard_raw_limit_size[index]),
|
|
|
4,philos_format_cfg_str_size_memory("", main_config.swap[index],main_config.swap_size[index]),
|
|
|
5,philos_format_cfg_str_size_memory("", main_config.cpu_limit[index], -1),
|
|
|
6,str_io_read,
|
|
|
7,str_io_write,-1);
|
|
|
free(str_io_read);
|
|
|
free(str_io_write);
|
|
|
}
|
|
|
if (flag_gui_add != 0) {
|
|
|
gtk_tree_view_set_model(GTK_TREE_VIEW(widgets->treeViewMain), model);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
char* format_io_limit_in_tree_view(config_str* disk, int** i_o_limit, int** i_o_limit_size, int index) {
|
|
|
int index_to_n2 = 0;
|
|
|
char* str = "";
|
|
|
while (1) {
|
|
|
if (i_o_limit == NULL) {break;}
|
|
|
if (i_o_limit[index]!= NULL) {
|
|
|
if (i_o_limit[index][index_to_n2] != -2) {
|
|
|
if (index_to_n2!=0) {
|
|
|
if (!strstr(str, "-")) {
|
|
|
char* num_and_pow_size = philos_format_cfg_str_size_memory(" ", i_o_limit[index][index_to_n2] , i_o_limit_size[index][index_to_n2]);
|
|
|
if (!strstr(num_and_pow_size, "-")) {
|
|
|
str = yon_char_unite(str, ",",
|
|
|
disk[index][index_to_n2], " ",
|
|
|
num_and_pow_size, NULL);
|
|
|
}
|
|
|
free(num_and_pow_size);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
else {
|
|
|
if (!strstr(str, "-")) {
|
|
|
char* num_and_pow_size = philos_format_cfg_str_size_memory(" ", i_o_limit[index][index_to_n2], i_o_limit_size[index][index_to_n2]);
|
|
|
if (!strstr(num_and_pow_size, "-")) {
|
|
|
str = yon_char_unite(str,
|
|
|
disk[index][index_to_n2], " ",
|
|
|
num_and_pow_size, NULL);
|
|
|
}
|
|
|
free(num_and_pow_size);
|
|
|
}
|
|
|
}
|
|
|
index_to_n2++;
|
|
|
}
|
|
|
else {
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
if (strlen(str)==0) {
|
|
|
return yon_char_new("-");
|
|
|
}
|
|
|
return str;
|
|
|
}
|
|
|
|
|
|
int tree_view_edit() {
|
|
|
int index = 0;
|
|
|
GtkTreeIter iter;
|
|
|
GtkTreeModel *model = GTK_TREE_MODEL(main_config.list);
|
|
|
|
|
|
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();
|
|
|
main_config.hard_raw_limit[index] = edit_get_hard();
|
|
|
main_config.swap[index] = edit_get_limit_swap();
|
|
|
main_config.cpu_limit[index] = edit_get_limit_cpu();
|
|
|
|
|
|
philos_array_int_copy(&main_config.i_o_limit_read[index], edit_get_read_device());
|
|
|
philos_array_int_copy(&main_config.i_o_limit_read_size[index], edit_get_read_device_size_pow());
|
|
|
yon_char_parsed_copy(&main_config.disk[index], edit_get_select_device());
|
|
|
|
|
|
philos_array_int_copy(&main_config.i_o_limit_write[index], edit_get_write_device());
|
|
|
philos_array_int_copy(&main_config.i_o_limit_write_size[index], edit_get_write_device_size_pow());
|
|
|
|
|
|
main_config.soft_raw_limit_size[index] = edit_get_soft_size();
|
|
|
main_config.hard_raw_limit_size[index] = edit_get_hard_size();
|
|
|
main_config.swap_size[index] = edit_get_limit_swap_size();
|
|
|
main_config.cpu_limit_size[index] = edit_get_limit_cpu_size();
|
|
|
|
|
|
char* str_io_read = format_io_limit_in_tree_view(main_config.disk, main_config.i_o_limit_read, main_config.i_o_limit_read_size, index);
|
|
|
char* str_io_write = format_io_limit_in_tree_view(main_config.disk, main_config.i_o_limit_write, main_config.i_o_limit_write_size, index);
|
|
|
gtk_list_store_set(main_config.list,&iter,
|
|
|
0,main_config.type_quota[index],
|
|
|
1,main_config.quota_volume[index],
|
|
|
2,philos_format_cfg_str_size_memory("",main_config.soft_raw_limit[index],main_config.soft_raw_limit_size[index]),
|
|
|
3,philos_format_cfg_str_size_memory("",main_config.hard_raw_limit[index],main_config.hard_raw_limit_size[index]),
|
|
|
4,philos_format_cfg_str_size_memory("",main_config.swap[index],main_config.swap_size[index]),
|
|
|
5,philos_format_cfg_str_size_memory("",main_config.cpu_limit[index], -1),
|
|
|
6,str_io_read,
|
|
|
7,str_io_write,-1);
|
|
|
return 1;
|
|
|
}
|
|
|
else {
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
void main_visible_columns(GtkWidget *self) {
|
|
|
gboolean *flags_filters = filters_get_flag();
|
|
|
gtk_tree_view_column_set_visible(widgets->tvc0, flags_filters[0]);
|
|
|
gtk_tree_view_column_set_visible(widgets->tvc1, flags_filters[1]);
|
|
|
gtk_tree_view_column_set_visible(widgets->tvc2, flags_filters[2]);
|
|
|
gtk_tree_view_column_set_visible(widgets->tvc3, flags_filters[3]);
|
|
|
gtk_tree_view_column_set_visible(widgets->tvc4, flags_filters[4]);
|
|
|
gtk_tree_view_column_set_visible(widgets->tvc5, flags_filters[5]);
|
|
|
gtk_tree_view_column_set_visible(widgets->tvc6, flags_filters[6]);
|
|
|
gtk_tree_view_column_set_visible(widgets->tvc7, flags_filters[7]);
|
|
|
filters_on_hide_subwindow(self);
|
|
|
}
|
|
|
|
|
|
void info_show(GtkWidget *self) {
|
|
|
GtkTreeIter iter;
|
|
|
GtkTreeModel *model = GTK_TREE_MODEL(main_config.list);
|
|
|
GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->treeViewMain));
|
|
|
if(gtk_tree_selection_get_selected(selection, &model, &iter)) {
|
|
|
char* str_iter = gtk_tree_model_get_string_from_iter(model, &iter);
|
|
|
int index = atoi(str_iter);
|
|
|
char* t_quota = main_config.type_quota[index];
|
|
|
if (yon_char_find_count(t_quota, "-") == 0) {
|
|
|
}
|
|
|
}
|
|
|
gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->notebookMain), 3);
|
|
|
}
|
|
|
|
|
|
void event_all(main_window *widgets) {
|
|
|
|
|
|
}
|
|
|
|
|
|
void main_event(main_window *widgets) {
|
|
|
/* Signal connection | Присоединение сигналов */
|
|
|
g_signal_connect(G_OBJECT(widgets->Window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
|
|
|
g_signal_connect(G_OBJECT(widgets->DocumentationMenuItem),"activate",G_CALLBACK(on_open_documentation_confirmation),WIKI_LINK);
|
|
|
g_signal_connect(G_OBJECT(widgets->AboutMenuItem),"activate",G_CALLBACK(on_about),NULL);
|
|
|
|
|
|
g_signal_connect(G_OBJECT(widgets->btnShowFilters),"clicked",G_CALLBACK(wrapper_filters_show), NULL);
|
|
|
g_signal_connect(G_OBJECT(widgets->btnAdd),"clicked",G_CALLBACK(wrapper_add_show), glade_path);
|
|
|
g_signal_connect(G_OBJECT(widgets->btnEdit),"clicked",G_CALLBACK(wrapper_edit_show), glade_path);
|
|
|
g_signal_connect(G_OBJECT(widgets->btnInfo),"clicked",G_CALLBACK(info_show), glade_path);
|
|
|
g_signal_connect(G_OBJECT(widgets->btnUpdateDispatcher),"clicked",G_CALLBACK(main_update_dispatcher), NULL);
|
|
|
g_signal_connect(G_OBJECT(widgets->btnMainShowAllEmpty), "toggled", G_CALLBACK(main_update_processes), NULL);
|
|
|
g_signal_connect(G_OBJECT(widgets->btnMainShowCoreStream), "toggled", G_CALLBACK(main_update_processes), NULL);
|
|
|
g_signal_connect(G_OBJECT(widgets->cbtMainInfo),"changed",G_CALLBACK(main_update_information), NULL);
|
|
|
g_signal_connect(G_OBJECT(widgets->btnDelQuotas), "clicked", G_CALLBACK(tree_view_del_line), 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);
|
|
|
}
|
|
|
void wrapper_add_show(GtkWidget *self) {
|
|
|
add_show(NULL, glade_path);
|
|
|
g_signal_connect(G_OBJECT(get_widget_add()->btnSaveTempSave), "clicked", G_CALLBACK(main_add_btn_save), NULL);
|
|
|
}
|
|
|
void main_add_btn_save() {
|
|
|
tree_view_add(main_config.size_tree_view);
|
|
|
add_on_destroy_subwindow(get_widget_add()->Window);
|
|
|
}
|
|
|
|
|
|
void wrapper_filters_show(GtkWidget *self) {
|
|
|
filters_show(self, glade_path);
|
|
|
g_signal_connect(G_OBJECT(get_widget_filters()->btnFiltersSave),"clicked",G_CALLBACK(main_visible_columns), NULL);
|
|
|
}
|
|
|
|
|
|
void wrapper_edit_show() {
|
|
|
GtkTreeIter iter;
|
|
|
GtkTreeModel *model = GTK_TREE_MODEL(main_config.list);
|
|
|
GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->treeViewMain));
|
|
|
if(gtk_tree_selection_get_selected(selection, &model, &iter)) {
|
|
|
char* str_iter = gtk_tree_model_get_string_from_iter(model, &iter);
|
|
|
int index = atoi(str_iter);
|
|
|
size_t size_disk_array = 0;
|
|
|
if (main_config.disk) {
|
|
|
for (size_disk_array; main_config.disk[index][size_disk_array]; size_disk_array++) {
|
|
|
}
|
|
|
}
|
|
|
edit_show(NULL, glade_path);
|
|
|
edit_set_size_arrays(size_disk_array);
|
|
|
edit_set_select_device(&main_config.disk[index]);
|
|
|
edit_set_write_device(main_config.i_o_limit_write[index], main_config.i_o_limit_write_size[index]);
|
|
|
edit_set_read_device(main_config.i_o_limit_read[index], main_config.i_o_limit_read_size[index]);
|
|
|
edit_set_hard(main_config.hard_raw_limit[index], main_config.hard_raw_limit_size[index]);
|
|
|
edit_set_limit_cpu(main_config.cpu_limit[index], main_config.cpu_limit_size[index]);
|
|
|
edit_set_soft(main_config.soft_raw_limit[index], main_config.soft_raw_limit_size[index]);
|
|
|
edit_set_limit_swap(main_config.swap[index], main_config.swap_size[index]);
|
|
|
|
|
|
edit_event(get_widget_edit());
|
|
|
g_signal_connect(G_OBJECT(get_widget_edit()->btnSaveTempSave), "clicked", G_CALLBACK(main_edit_btn_save), NULL);
|
|
|
edit_init_windows();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void main_edit_btn_save() {
|
|
|
if (tree_view_edit(main_config.size_tree_view)) {
|
|
|
edit_init_windows();
|
|
|
add_on_destroy_subwindow(get_widget_edit()->Window);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
void tree_view_del_line() {
|
|
|
int index = 0;
|
|
|
GtkTreeIter iter;
|
|
|
GtkTreeModel *model = GTK_TREE_MODEL(main_config.list);
|
|
|
GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->treeViewMain));
|
|
|
if(gtk_tree_selection_get_selected(selection, &model, &iter)) {
|
|
|
char* str_iter = yon_char_new(gtk_tree_model_get_string_from_iter(model, &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);
|
|
|
char* key_del = save_format_key(index);
|
|
|
if (key_del != NULL) {
|
|
|
main_config.array_del_line = yon_char_parsed_append(main_config.array_del_line, &main_config.size_array_del_line, yon_char_new(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);
|
|
|
main_config.size_tree_view++;
|
|
|
main_config.soft_raw_limit = remove_element_int_array(main_config.soft_raw_limit, &main_config.size_tree_view,index);
|
|
|
main_config.size_tree_view++;
|
|
|
main_config.hard_raw_limit = remove_element_int_array(main_config.hard_raw_limit, &main_config.size_tree_view,index);
|
|
|
main_config.size_tree_view++;
|
|
|
main_config.swap = remove_element_int_array(main_config.swap, &main_config.size_tree_view,index);
|
|
|
main_config.size_tree_view++;
|
|
|
main_config.cpu_limit = remove_element_int_array(main_config.cpu_limit, &main_config.size_tree_view,index);
|
|
|
main_config.size_tree_view++;
|
|
|
main_config.i_o_limit_read = remove_element_int_array_n3(main_config.i_o_limit_read, &main_config.size_tree_view,index);
|
|
|
main_config.size_tree_view++;
|
|
|
main_config.i_o_limit_write = remove_element_int_array_n3(main_config.i_o_limit_write, &main_config.size_tree_view,index);
|
|
|
main_config.size_tree_view++;
|
|
|
main_config.disk = yon_char_parsed_shrink_n3(main_config.disk, &main_config.size_tree_view,index);
|
|
|
main_config.size_tree_view++;
|
|
|
|
|
|
main_config.i_o_limit_read_size = remove_element_int_array_n3(main_config.i_o_limit_read_size, &main_config.size_tree_view,index);
|
|
|
main_config.size_tree_view++;
|
|
|
main_config.i_o_limit_write_size = remove_element_int_array_n3(main_config.i_o_limit_write_size, &main_config.size_tree_view,index);
|
|
|
main_config.size_tree_view++;
|
|
|
main_config.type_quota_size = remove_element_int_array(main_config.type_quota_size, &main_config.size_tree_view,index);
|
|
|
main_config.size_tree_view++;
|
|
|
main_config.quota_volume_size = remove_element_int_array(main_config.quota_volume_size, &main_config.size_tree_view,index);
|
|
|
main_config.size_tree_view++;
|
|
|
main_config.soft_raw_limit_size = remove_element_int_array(main_config.soft_raw_limit_size, &main_config.size_tree_view,index);
|
|
|
main_config.size_tree_view++;
|
|
|
main_config.hard_raw_limit_size = remove_element_int_array(main_config.hard_raw_limit_size, &main_config.size_tree_view,index);
|
|
|
main_config.size_tree_view++;
|
|
|
main_config.swap_size = remove_element_int_array(main_config.swap_size, &main_config.size_tree_view,index);
|
|
|
main_config.size_tree_view++;
|
|
|
main_config.cpu_limit_size = remove_element_int_array(main_config.cpu_limit_size, &main_config.size_tree_view,index);
|
|
|
|
|
|
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() {
|
|
|
int flag_mess_save = 0;
|
|
|
if (main_config.flag_load == 0) {
|
|
|
flag_mess_save = template_format_str_save(CMD_ALL_SAVE, CMD_ALL_REMOVE);
|
|
|
}
|
|
|
else {
|
|
|
flag_mess_save = template_format_str_save(CMD_ALL_SAVE, CMD_ALL_REMOVE);
|
|
|
}
|
|
|
if (flag_mess_save) {
|
|
|
yon_ubl_status_box_render(GLOBAL_LOCAL_SAVE_SUCCESS,BACKGROUND_IMAGE_SUCCESS_TYPE);
|
|
|
}
|
|
|
else {
|
|
|
yon_ubl_status_box_render(MESS_NOTHING_SAVE, BACKGROUND_IMAGE_SUCCESS_TYPE);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
void wrapper_global_save() {
|
|
|
if (template_format_str_save(CMD_SAVE_GLOBAL, CMD_REMOVE_GLOBAL)) {
|
|
|
yon_ubl_status_box_render(GLOBAL_LOAD_SUCCESS,BACKGROUND_IMAGE_SUCCESS_TYPE);
|
|
|
}
|
|
|
else {
|
|
|
yon_ubl_status_box_render(MESS_NOTHING_SAVE, BACKGROUND_IMAGE_SUCCESS_TYPE);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
void wrapper_system_save() {
|
|
|
if (template_format_str_save(CMD_SAVE_SYSTEM, CMD_REMOVE_SYSTEM)) {
|
|
|
yon_ubl_status_box_render(LOCAL_SAVE_SUCCESS,BACKGROUND_IMAGE_SUCCESS_TYPE);
|
|
|
}
|
|
|
else {
|
|
|
yon_ubl_status_box_render(MESS_NOTHING_SAVE, BACKGROUND_IMAGE_SUCCESS_TYPE);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
char* save_format_key(int index) {
|
|
|
char* key = NULL;
|
|
|
if (strstr(main_config.quota_volume[index], "-") == NULL) {
|
|
|
key = yon_char_unite("CGROUP_QUOTA[", main_config.quota_volume[index] , "]", NULL);
|
|
|
}
|
|
|
return key;
|
|
|
}
|
|
|
|
|
|
char* save_format_value(int index) {
|
|
|
char* value = "";
|
|
|
char split_simvol[2] = {0};
|
|
|
split_simvol[0] = 0;
|
|
|
split_simvol[1] = 0;
|
|
|
if (main_config.soft_raw_limit[index]>=0) {
|
|
|
char* value_size = philos_format_cfg_str_size_memory("MemoryHigh=", main_config.soft_raw_limit[index],main_config.soft_raw_limit_size[index]);
|
|
|
if (!strstr(value_size,"-")) {
|
|
|
value = yon_char_unite(value ,split_simvol, value_size, NULL);
|
|
|
split_simvol[0] = ',';
|
|
|
split_simvol[1] = '\0';
|
|
|
}
|
|
|
free(value_size);
|
|
|
}
|
|
|
if (main_config.hard_raw_limit[index]>=0) {
|
|
|
char* value_size = philos_format_cfg_str_size_memory("MemoryMax=", main_config.hard_raw_limit[index],main_config.hard_raw_limit_size[index]);
|
|
|
if (!strstr(value_size,"-")) {
|
|
|
value = yon_char_unite(value ,split_simvol, value_size, NULL);
|
|
|
split_simvol[0] = ',';
|
|
|
split_simvol[1] = '\0';
|
|
|
}
|
|
|
free(value_size);
|
|
|
}
|
|
|
if (main_config.swap[index]>=0) {
|
|
|
char* value_size = philos_format_cfg_str_size_memory("MemorySwapMax=", main_config.swap[index],main_config.swap_size[index]);
|
|
|
if (!strstr(value_size,"-")) {
|
|
|
value = yon_char_unite(value ,split_simvol, value_size, NULL);
|
|
|
split_simvol[0] = ',';
|
|
|
split_simvol[1] = '\0';
|
|
|
}
|
|
|
free(value_size);
|
|
|
}
|
|
|
if (main_config.cpu_limit[index]>=0) {
|
|
|
value = yon_char_unite(value ,split_simvol,"CPUQuota=", yon_char_from_int(main_config.cpu_limit[index]), "%", NULL);
|
|
|
split_simvol[0] = ',';
|
|
|
split_simvol[1] = '\0';
|
|
|
}
|
|
|
value = add_io_str_format_ubconfig(value, "IOReadBandwidthMax", main_config.i_o_limit_read, main_config.i_o_limit_read_size, main_config.disk, index);
|
|
|
value = add_io_str_format_ubconfig(value, "IOWriteBandwidthMax", main_config.i_o_limit_write, main_config.i_o_limit_write_size, main_config.disk, index);
|
|
|
return value;
|
|
|
}
|
|
|
char* add_io_str_format_ubconfig(char* cmd_io, char* key, int** i_o_limit, int** i_o_limit_size, char*** disk, int index) {
|
|
|
char split_simvol[2] = {0};
|
|
|
if (i_o_limit== NULL) {return cmd_io;}
|
|
|
if (i_o_limit_size[index] == NULL) {return cmd_io;}
|
|
|
if (i_o_limit[index] == NULL) {return cmd_io;}
|
|
|
int len_array = 0;
|
|
|
for (int i = 0;i_o_limit[index][i] != -2; i++) {
|
|
|
len_array += 1;
|
|
|
}
|
|
|
for (int i=0; i<len_array; i++) {
|
|
|
if (i==0 && strlen(cmd_io) < 3) {
|
|
|
cmd_io = yon_char_unite(cmd_io, key, "=", NULL);
|
|
|
}
|
|
|
else if (i==0 && strlen(cmd_io) > 3) {
|
|
|
cmd_io = yon_char_unite(cmd_io, ",", key, "=", NULL);
|
|
|
}
|
|
|
int read_limit = i_o_limit[index][i];
|
|
|
char* read_disk = disk[index][i];
|
|
|
int read_limit_size = i_o_limit_size[index][i];
|
|
|
if (read_limit >= 0 && read_disk && read_limit_size >= 0) {
|
|
|
char* num_and_pow_size = philos_format_cfg_str_size_memory("",read_limit, read_limit_size);
|
|
|
cmd_io = yon_char_unite(cmd_io, split_simvol, read_disk, " ",num_and_pow_size, NULL);
|
|
|
split_simvol[0] = ',';
|
|
|
split_simvol[1] = '\0';
|
|
|
free(num_and_pow_size);
|
|
|
}
|
|
|
}
|
|
|
return cmd_io;
|
|
|
}
|
|
|
|
|
|
|
|
|
int check_save() {
|
|
|
if (main_config.flag_set_data == 1) {
|
|
|
return 0;
|
|
|
}
|
|
|
else if (main_config.flag_set_data == 0) {
|
|
|
return 1;
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
int template_format_str_save(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(source_set_cmd);
|
|
|
if (cmd_set != NULL && cmd_remove != NULL) {
|
|
|
philos_config_save(yon_char_unite(cmd_set, "; " , cmd_remove, NULL));
|
|
|
}
|
|
|
else if (cmd_remove != NULL) {
|
|
|
philos_config_save(cmd_remove);
|
|
|
}
|
|
|
else if (cmd_set != NULL) {
|
|
|
philos_config_save(cmd_set);
|
|
|
}
|
|
|
else {
|
|
|
return 0;
|
|
|
}
|
|
|
if (cmd_remove != NULL) {
|
|
|
free(cmd_remove);
|
|
|
}
|
|
|
if (cmd_set != NULL) {
|
|
|
free(cmd_set);
|
|
|
}
|
|
|
|
|
|
|
|
|
main_config.flag_set_data = 0;
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
char* template_format_str_set_save(char* source_set_cmd) {
|
|
|
char* cmd = yon_char_new(source_set_cmd);
|
|
|
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));
|
|
|
if (key != NULL && value != NULL) {
|
|
|
cmd = yon_char_unite(cmd, " " , key, "=\"" , value, "\" ", NULL);
|
|
|
flag_save = 1;
|
|
|
}
|
|
|
if (key != NULL) {
|
|
|
free(key);
|
|
|
}
|
|
|
else if (value != NULL) {
|
|
|
free(value);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (flag_save && check_save()== 0) {
|
|
|
puts(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;
|
|
|
if (main_config.size_array_del_line == 0) {
|
|
|
return NULL;
|
|
|
}
|
|
|
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;
|
|
|
}
|
|
|
}
|
|
|
if (flag_save) {
|
|
|
philos_free_string_array(&main_config.array_del_line, main_config.size_array_del_line);
|
|
|
main_config.size_array_del_line = 0;
|
|
|
return cmd;
|
|
|
}
|
|
|
free(cmd);
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
void main_fill_tree_view_after_remove() {
|
|
|
for (int index= 0; index < main_config.size_tree_view; index++) {
|
|
|
GtkTreeIter iter;
|
|
|
gtk_list_store_append(main_config.list,&iter);
|
|
|
char* str_io_read = format_io_limit_in_tree_view(main_config.disk, main_config.i_o_limit_read, main_config.i_o_limit_read_size, index);
|
|
|
char* str_io_write = format_io_limit_in_tree_view(main_config.disk, main_config.i_o_limit_write, main_config.i_o_limit_write_size, index);
|
|
|
gtk_list_store_set(main_config.list,&iter,
|
|
|
0,main_config.type_quota[index],
|
|
|
1,main_config.quota_volume[index],
|
|
|
2,philos_format_cfg_str_size_memory("",main_config.soft_raw_limit[index],main_config.soft_raw_limit_size[index]),
|
|
|
3,philos_format_cfg_str_size_memory("",main_config.hard_raw_limit[index],main_config.hard_raw_limit_size[index]),
|
|
|
4,philos_format_cfg_str_size_memory("",main_config.swap[index],main_config.swap_size[index]),
|
|
|
5,philos_format_cfg_str_size_memory("",main_config.cpu_limit[index], -1),
|
|
|
6,str_io_read,
|
|
|
7,str_io_write,-1);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void main_localization(main_window *widgets) {
|
|
|
/* Localisation | Локализация */
|
|
|
gtk_label_set_text(GTK_LABEL(widgets->HatLabel),TITLE_LABEL);
|
|
|
gtk_label_set_text(GTK_LABEL(widgets->SaveLabel),SAVE_LABEL);
|
|
|
gtk_menu_item_set_label(GTK_MENU_ITEM(widgets->SaveMenuItem),SAVE_CONFIGURATION_LABEL);
|
|
|
gtk_menu_item_set_label(GTK_MENU_ITEM(widgets->SaveGlobalMenuItem),SAVE_GLOBAL_LABEL);
|
|
|
gtk_menu_item_set_label(GTK_MENU_ITEM(widgets->SaveLocalMenuItem),SAVE_LOCAL_LABEL);
|
|
|
|
|
|
gtk_label_set_text(GTK_LABEL(widgets->LoadLabel),LOAD_LABEL);
|
|
|
gtk_menu_item_set_label(GTK_MENU_ITEM(widgets->LoadGlobalMenuItem),LOAD_GLOBAL_LABEL);
|
|
|
gtk_menu_item_set_label(GTK_MENU_ITEM(widgets->LoadLocalMenuItem),LOAD_LOCAL_LABEL);
|
|
|
|
|
|
gtk_menu_item_set_label(GTK_MENU_ITEM(widgets->DocumentationMenuItem),DOCUMENTATION_LABEL);
|
|
|
gtk_menu_item_set_label(GTK_MENU_ITEM(widgets->AboutMenuItem),ABOUT_LABEL);
|
|
|
}
|
|
|
|
|
|
void yon_load_proceed(char *command){
|
|
|
if (yon_config_load_register(command))
|
|
|
yon_ubl_status_box_render(LOCAL_SAVE_SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
|
|
|
else
|
|
|
yon_ubl_status_box_render(LOAD_FAILED_LABEL,BACKGROUND_IMAGE_FAIL_TYPE);
|
|
|
}
|
|
|
int main(int argc, char *argv[]){
|
|
|
local=setlocale(LC_ALL, "");
|
|
|
textdomain (LocaleName);
|
|
|
config_init();
|
|
|
int size_array_size_pow = 0;
|
|
|
array_size_pow = yon_char_parsed_append(array_size_pow,&size_array_size_pow, STR_KB);
|
|
|
array_size_pow = yon_char_parsed_append(array_size_pow,&size_array_size_pow, STR_MB);
|
|
|
array_size_pow = yon_char_parsed_append(array_size_pow,&size_array_size_pow, STR_GB);
|
|
|
array_size_pow = yon_char_parsed_append(array_size_pow,&size_array_size_pow, STR_TB);
|
|
|
int option_index=0;
|
|
|
int show_help=0;
|
|
|
{
|
|
|
struct option long_options[] = {
|
|
|
{"help", 0, 0, 'h'},
|
|
|
{"version", 0, 0, 'V'},
|
|
|
{"lock-help", 0,0, 1},
|
|
|
{"lock-save", 0,0, 2},
|
|
|
{"lock-save-local", 0,0, 3},
|
|
|
{"lock-save-global", 0,0, 4},
|
|
|
{"lock-load-global", 0,0, 5},
|
|
|
{"socket-id", 1, 0, 's'},
|
|
|
{"socket-ext-id", 1,0, 'e'},
|
|
|
{"socket-trd-id", 1,0, 't'},
|
|
|
{"debug", 0,0, 'd'},
|
|
|
{ NULL, 0, NULL, 0 }
|
|
|
};
|
|
|
for (int i=0;i<argc;i++){
|
|
|
int argument=getopt_long(argc,argv,"hVvs:e:t:d",long_options,&option_index);
|
|
|
switch(argument){
|
|
|
case 'h':
|
|
|
show_help=1;
|
|
|
break;
|
|
|
case 'v':
|
|
|
case 'V':
|
|
|
printf("%s\n",VERSION_LABEL);
|
|
|
exit(0);
|
|
|
break;
|
|
|
case 's':
|
|
|
if(optarg)
|
|
|
main_config.socket_id=atoi(optarg);
|
|
|
break;
|
|
|
case 'e':
|
|
|
if(optarg)
|
|
|
main_config.load_socket_id=atoi(optarg);
|
|
|
break;
|
|
|
case 't':
|
|
|
if(optarg)
|
|
|
main_config.save_socket_id=atoi(optarg);
|
|
|
break;
|
|
|
case 1:
|
|
|
main_config.lock_help=1;
|
|
|
break;
|
|
|
case 2:
|
|
|
main_config.lock_save_local=1;
|
|
|
main_config.lock_save_global=1;
|
|
|
break;
|
|
|
case 3:
|
|
|
main_config.lock_save_local=1;
|
|
|
break;
|
|
|
case 4:
|
|
|
main_config.lock_save_global=1;
|
|
|
break;
|
|
|
case 5:
|
|
|
main_config.lock_load_global=1;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
if (show_help==1&&main_config.lock_help!=1){
|
|
|
printf("%s\n",HELP_LABEL);
|
|
|
exit(0);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (getuid()!=0){
|
|
|
main_config.lock_load_global=1;
|
|
|
main_config.lock_save_global=1;
|
|
|
main_config.lock_save_local=1;
|
|
|
}
|
|
|
gtk_init(&argc,&argv);
|
|
|
|
|
|
add_get_cmd_group(CMD_GET_GROUP);
|
|
|
add_get_systemd_cgls(CMD_GET_SLICE_SERVICE);
|
|
|
gtk_init(&argc,&argv);
|
|
|
device_disk_parsed();
|
|
|
main_window *widgets = setup_window();
|
|
|
main_update_information();
|
|
|
filters_init_flag();
|
|
|
main_localization(widgets);
|
|
|
tree_view_select(NULL, widgets);
|
|
|
|
|
|
yon_ubl_header_setup_resource(widgets->HeadOverlay,widgets->HeadBox,widgets->HeadImage,banner_path);
|
|
|
|
|
|
yon_ubl_status_box_setup(widgets->StatusIcon,widgets->StatusBox,widgets->StatusLabel);
|
|
|
if (getuid()!=0)
|
|
|
yon_ubl_status_box_render(TITLE_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
|
|
|
else
|
|
|
yon_ubl_status_box_render(TITLE_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
|
|
|
yon_ubl_setup_sockets(widgets->PlugBox,widgets->LeftBox,widgets->RightBox,main_config.socket_id,main_config.load_socket_id,main_config.save_socket_id);
|
|
|
yon_window_config_setup(GTK_WINDOW(widgets->Window));
|
|
|
yon_window_config_load(config_path);
|
|
|
GtkCssProvider *css=gtk_css_provider_new();
|
|
|
gtk_css_provider_load_from_resource(css,CssPath);
|
|
|
gtk_style_context_add_provider_for_screen(gdk_screen_get_default(),
|
|
|
GTK_STYLE_PROVIDER(css),
|
|
|
-1);
|
|
|
load_global_cfg();
|
|
|
load_system_cfg();
|
|
|
event_all(widgets);
|
|
|
main_event(widgets);
|
|
|
gtk_main();
|
|
|
philos_free_string_array(&array_size_pow, size_array_size_pow);
|
|
|
} |