#include "ubl-settings-services.h" 
 
config main_config; 
 
//saving & loading

void on_save_done(main_window *, config_str output, int size){
	char *final_output = yon_char_parsed_to_string(output,size,"");
    if (!yon_char_is_empty(final_output)){
        printf("%s\n",final_output);
        free(final_output);
    }
    if (output&&size>0){
        yon_char_parsed_free(output,size);
    }
    textdomain(template_ui_LocaleName);
	switch (main_config.save_config){
		case 0:
			yon_ubl_status_box_render(GLOBAL_SAVE_SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
			break;
		case 1:
			yon_ubl_status_box_render(LOCAL_SAVE_SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
			break;
		case 3:
			yon_ubl_status_box_render(GLOBAL_LOCAL_SAVE_SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
			break;
	}
    textdomain(LocaleName);
}
 
void yon_load_proceed(YON_CONFIG_TYPE type){ 
	if (type!=YON_CONFIG_CUSTOM){
		yon_config_clean();
        if (!yon_char_is_empty(config_get_default_command))
            yon_config_load_config(YON_CONFIG_DEFAULT,config_get_default_command,NULL);
	}
    if (type==YON_CONFIG_GLOBAL){
		yon_config_load_config(type,config_get_global_command,NULL);
	} else if (type==YON_CONFIG_LOCAL){
		yon_config_load_config(type,config_get_local_command,NULL);
    } else if (type==YON_CONFIG_CUSTOM){
		char *path="";
        textdomain(template_ui_LocaleName);
		GtkWidget *dialog = gtk_file_chooser_dialog_new(template_app_information.app_title,NULL,GTK_FILE_CHOOSER_ACTION_SAVE,CANCEL_LABEL,GTK_RESPONSE_CANCEL,OPEN_LABEL,GTK_RESPONSE_ACCEPT,NULL);
        textdomain(LocaleName);
        gtk_window_set_icon_name(GTK_WINDOW(dialog),"com.ublinux.ubl-settings-services");
        gtk_window_set_title(GTK_WINDOW(dialog),TITLE_LABEL);
        GtkFileFilter *filter = gtk_file_filter_new();
		gtk_file_filter_add_pattern(filter,"*.ini");
        gtk_file_filter_set_name(filter, "*.ini");
		gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog),filter);
		gtk_widget_show(dialog);
		int response = gtk_dialog_run(GTK_DIALOG(dialog));
		if (response == GTK_RESPONSE_ACCEPT){
			char *file = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
			if (!yon_char_is_empty(file)){
				path=file;
			}
            yon_config_clean();
            if (!yon_char_is_empty(config_get_default_command))
                yon_config_load_config(YON_CONFIG_DEFAULT,config_get_default_command,NULL);
            char *command = yon_config_get_custom_command(path);
            yon_config_load_config(type,command,NULL);
			gtk_widget_destroy(dialog);
		} else {
			gtk_widget_destroy(dialog);
		}
	}
}

void on_config_local_load(GtkWidget *,main_window *widgets){
    if (!main_config.update_thread_active){
        main_config.update_thread_active=1;
        yon_load_proceed(YON_CONFIG_LOCAL);
        yon_ubl_status_box_render(LIST_LOAD_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
        g_thread_new("update",(GThreadFunc)yon_interface_update,widgets);
        main_config.load_mode=YON_CONFIG_LOCAL;
    }
}

void on_config_global_load(GtkWidget *,main_window *widgets){
    if (!main_config.update_thread_active){
        main_config.update_thread_active=1;
        yon_load_proceed(YON_CONFIG_GLOBAL);
        yon_ubl_status_box_render(LIST_LOAD_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
        g_thread_new("update",(GThreadFunc)yon_interface_update,widgets);
        main_config.load_mode=YON_CONFIG_GLOBAL;
    }
    
}

void on_config_custom_load(GtkWidget *,main_window *widgets){
	yon_load_proceed(YON_CONFIG_CUSTOM);
	textdomain(template_ui_LocaleName);
	yon_ubl_status_box_render(GLOBAL_LOAD_SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
	textdomain(LocaleName);
	main_config.load_mode=YON_CONFIG_CUSTOM;
        g_thread_new("update",(GThreadFunc)yon_interface_update,widgets);
}

void on_service_constant_update(){
    
}

void on_config_global_local_save(){
    main_config.save_config=3;
    yon_save_proceed(NULL,YON_CONFIG_BOTH,config_get_global_command,NULL);
}

void on_config_local_save(){
    main_config.save_config=1;
    yon_save_proceed("system",YON_CONFIG_LOCAL,config_get_local_command,NULL);
    
}

void on_config_global_save(){
    main_config.save_config=0;
    yon_save_proceed("global",YON_CONFIG_GLOBAL,config_get_global_command,NULL);
    
}

void on_config_custom_save(GtkWidget *, main_window *){
    main_config.save_config=1;
	template_saving_window *window = yon_save_proceed(NULL,YON_CONFIG_CUSTOM,yon_config_get_custom_command("system"),NULL);
	if (window){};
}

// functions
enum YON_UNIT_TYPE yon_get_unit_type(char *unit_name);

enum YON_UNIT_TYPE yon_get_unit_type(char *unit_name){
        enum YON_UNIT_TYPE final_type=0;
    char *type = yon_char_new(unit_name);
    int cut = yon_char_find_last(type,'.');
    if (cut>-1){
        free(yon_char_divide(type,cut));
    }
    if (!strcmp(type,"service")){
        final_type = YON_UNIT_SERVICE;
    } else if (!strcmp(type,"swap")){
        final_type = YON_UNIT_SWAP;
    } else if (!strcmp(type,"socket")){
        final_type = YON_UNIT_SOCKET;
    } else if (!strcmp(type,"device")){
        final_type = YON_UNIT_DEVICE;
    } else if (!strcmp(type,"target")){
        final_type = YON_UNIT_TARGET;
    } else if (!strcmp(type,"automount")){
        final_type = YON_UNIT_MOUNT;
    } else if (!strcmp(type,"timer")){
        final_type = YON_UNIT_TIMER;
    } else if (!strcmp(type,"path")){
        final_type = YON_UNIT_PATH;
    } else if (!strcmp(type,"slice")){
        final_type = YON_UNIT_SLICE;
    } else if (!strcmp(type,"scope")){
        final_type = YON_UNIT_SCOPE;
    } else {
        final_type = YON_UNIT_UNRECOGNISED;
    }
    free(type);
    return final_type;
} 

void on_activate(GtkTreeView *self, main_window *widgets){
 if (self&&widgets){};
}

void on_config_autostart_clicked(GtkCellRenderer *, char *path, main_window *widgets){
        GtkTreeIter filter_iter;
        GtkTreeIter iter,itor;
        GtkTreeModel *model;
        GtkTreeModel *filter;
        GtkTreeModel *sort;
        if (gtk_notebook_get_current_page(GTK_NOTEBOOK(widgets->MainNotebook))==0){
            model = GTK_TREE_MODEL(widgets->SystemList);
            filter = GTK_TREE_MODEL(widgets->SystemFilter);
            sort = GTK_TREE_MODEL(widgets->SystemSort);
        } else {
            model = GTK_TREE_MODEL(widgets->UserList);
            filter = GTK_TREE_MODEL(widgets->UserFilter);
            sort = GTK_TREE_MODEL(widgets->UserSort);
        }
        GtkTreePath *path_converted = gtk_tree_path_new_from_string(path);
        gtk_tree_model_get_iter(sort,&filter_iter,path_converted);
        {
        gtk_tree_model_sort_convert_iter_to_child_iter(GTK_TREE_MODEL_SORT(sort),&itor,&filter_iter);
        gtk_tree_model_filter_convert_iter_to_child_iter(GTK_TREE_MODEL_FILTER(filter),&iter,&itor);
        gboolean status = 0,autoblock = 0;
        char *name;
        gtk_tree_model_get(model,&iter,0,&status,1,&autoblock,5,&name,-1);
        char *unit = yon_char_new(name);
        char *parsed_name = yon_char_divide(unit, yon_char_find_last(name,'.'));
        free(unit);
        unit=parsed_name;
        gtk_list_store_set(GTK_LIST_STORE(model),&iter,0,!status,-1);
        if (!status&&autoblock){
            on_config_autostop_clicked(NULL,path,widgets);
        }
        char *config_sting = yon_config_get_by_key("SERVICES_ENABLE");
        int size;
        config_str parsed = yon_char_parse(config_sting,&size,",");
        char *additional_name = NULL;
        if (strstr(name,".service")){
            char *temp = yon_char_new(name);
            additional_name = yon_char_divide_search(temp,".",-1);
            free(temp);
        }
        int place = yon_char_parsed_check_exist(parsed,size,name);
        if (place==-1){
            place = yon_char_parsed_check_exist(parsed,size,additional_name);
        }
        if (status==0){
            if (place ==-1){
                if (yon_char_parsed_check_exist(parsed,size,unit)==-1){
                    if (!yon_config_append_element("SERVICES_ENABLE",name,",")){
                        yon_config_register("SERVICES_ENABLE",SERVICES_ENABLE_get_command,name);
                    }
                } else {
                    parsed = yon_char_parsed_rip(parsed,&size,place);
                    if (parsed)
                        yon_config_register("SERVICES_ENABLE",SERVICES_ENABLE_get_command,yon_char_parsed_to_string(parsed,size,","));
                    else yon_config_remove_by_key("SERVICES_ENABLE");
                }
            }
        } else {
            if (place !=-1){
                parsed = yon_char_parsed_rip(parsed,&size,place);
                if (parsed)
                    yon_config_register("SERVICES_ENABLE",SERVICES_ENABLE_get_command,yon_char_parsed_to_string(parsed,size,","));
                else yon_config_remove_by_key("SERVICES_ENABLE");
            }
        }
        yon_char_parsed_free(parsed,size);
    }
}

void on_config_autostop_clicked(GtkCellRenderer *, char *path, main_window *widgets){
        GtkTreeIter filter_iter;
        GtkTreeIter iter,itor;
        GtkTreeModel *model;
        GtkTreeModel *filter;
        GtkTreeModel *sort;
        if (gtk_notebook_get_current_page(GTK_NOTEBOOK(widgets->MainNotebook))==0){
            model = GTK_TREE_MODEL(widgets->SystemList);
            filter = GTK_TREE_MODEL(widgets->SystemFilter);
            sort = GTK_TREE_MODEL(widgets->SystemSort);
        } else {
            model = GTK_TREE_MODEL(widgets->UserList);
            filter = GTK_TREE_MODEL(widgets->UserFilter);
            sort = GTK_TREE_MODEL(widgets->UserSort);
        }
        GtkTreePath *path_converted = gtk_tree_path_new_from_string(path);
        gtk_tree_model_get_iter(sort,&filter_iter,path_converted);
        {
        gtk_tree_model_sort_convert_iter_to_child_iter(GTK_TREE_MODEL_SORT(sort),&itor,&filter_iter);
        gtk_tree_model_filter_convert_iter_to_child_iter(GTK_TREE_MODEL_FILTER(filter),&iter,&itor);
        gboolean status = 0,autostart=0;
        char *name;
        gtk_tree_model_get(model,&iter,0,&autostart,1,&status,5,&name,-1);
        char *unit = yon_char_new(name);
        char *parsed_name = yon_char_divide(unit, yon_char_find_last(name,'.'));
        free(unit);
        unit=parsed_name;
        gtk_list_store_set(GTK_LIST_STORE(model),&iter,1,!status,-1);
        if (!status&&autostart){
            on_config_autostart_clicked(NULL,path,widgets);
        }
        char *config_sting = yon_config_get_by_key("SERVICES_DISABLE");
        int size;
        config_str parsed = yon_char_parse(config_sting,&size,",");
        char *additional_name = NULL;
        if (strstr(name,".service")){
            char *temp = yon_char_new(name);
            additional_name = yon_char_divide_search(temp,".",-1);
            free(temp);
        }
        int place = yon_char_parsed_check_exist(parsed,size,name);
        if (place==-1){
            place = yon_char_parsed_check_exist(parsed,size,additional_name);
        }
        if (status==0){
            if (place ==-1){
                if (yon_char_parsed_check_exist(parsed,size,unit)==-1){
                    if (!yon_config_append_element("SERVICES_DISABLE",name,",")){
                        yon_config_register("SERVICES_DISABLE",SERVICES_DISABLE_get_command,name);
                    }
                } else {
                    parsed = yon_char_parsed_rip(parsed,&size,place);
                    if (parsed)
                        yon_config_set("SERVICES_DISABLE",yon_char_parsed_to_string(parsed,size,","));
                    else yon_config_remove_by_key("SERVICES_DISABLE");
                }
            }
        } else {
            if (place !=-1){
                parsed = yon_char_parsed_rip(parsed,&size,place);
                if (parsed)
                    yon_config_set("SERVICES_DISABLE",yon_char_parsed_to_string(parsed,size,","));
                else yon_config_remove_by_key("SERVICES_DISABLE");
            }
        }
        yon_char_parsed_free(parsed,size);
    }

}

void on_config_block_clicked(GtkCellRenderer *, char *path, main_window *widgets){
        GtkTreeIter filter_iter;
        GtkTreeIter iter,itor;
        GtkTreeModel *model;
        GtkTreeModel *filter;
        GtkTreeModel *sort;
        if (gtk_notebook_get_current_page(GTK_NOTEBOOK(widgets->MainNotebook))==0){
            model = GTK_TREE_MODEL(widgets->SystemList);
            filter = GTK_TREE_MODEL(widgets->SystemFilter);
            sort = GTK_TREE_MODEL(widgets->SystemSort);
        } else {
            model = GTK_TREE_MODEL(widgets->UserList);
            filter = GTK_TREE_MODEL(widgets->UserFilter);
            sort = GTK_TREE_MODEL(widgets->UserSort);
        }
        GtkTreePath *path_converted = gtk_tree_path_new_from_string(path);
        gtk_tree_model_get_iter(sort,&filter_iter,path_converted);
        {
        gtk_tree_model_sort_convert_iter_to_child_iter(GTK_TREE_MODEL_SORT(sort),&itor,&filter_iter);
        gtk_tree_model_filter_convert_iter_to_child_iter(GTK_TREE_MODEL_FILTER(filter),&iter,&itor);
        gboolean status = 0;
        char *name;
        gtk_tree_model_get(model,&iter,2,&status,5,&name,-1);
        char *unit = yon_char_new(name);
        char *parsed_name = yon_char_divide(unit, yon_char_find_last(name,'.'));
        free(unit);
        unit=parsed_name;
        gtk_list_store_set(GTK_LIST_STORE(model),&iter,2,!status,-1);
        char *config_sting = yon_config_get_by_key(SERVICES_MASK_parameter);
        int size;
        config_str parsed = yon_char_parse(config_sting,&size,",");
        char *additional_name = NULL;
        if (strstr(name,".service")){
            char *temp = yon_char_new(name);
            additional_name = yon_char_divide_search(temp,".",-1);
            free(temp);
        }
        int place = yon_char_parsed_check_exist(parsed,size,name);
        if (place==-1){
            place = yon_char_parsed_check_exist(parsed,size,additional_name);
        }
        if (status==0){
            if (place ==-1){
                if (yon_char_parsed_check_exist(parsed,size,unit)==-1){
                    if (!yon_config_append_element(SERVICES_MASK_parameter,name,",")){
                        yon_config_register(SERVICES_MASK_parameter,SERVICES_MASK_parameter_command,name);
                    }
                } else {
                    parsed = yon_char_parsed_rip(parsed,&size,place);
                    if (parsed)
                        yon_config_set(SERVICES_MASK_parameter,yon_char_parsed_to_string(parsed,size,","));
                    else yon_config_remove_by_key(SERVICES_MASK_parameter);
                }
            }
        } else {
            if (place !=-1){
                parsed = yon_char_parsed_rip(parsed,&size,place);
                if (parsed)
                    yon_config_set(SERVICES_MASK_parameter,yon_char_parsed_to_string(parsed,size,","));
                else yon_config_remove_by_key(SERVICES_MASK_parameter);
            }
        }
        yon_char_parsed_free(parsed,size);
    }

}

void on_system_autostart_confirmed(GtkWidget *,char *service_command){
    yon_launch_app_with_arguments(yon_debug_output("%s\n",service_command),"");
}

void on_system_autostart_clicked(GtkCellRenderer *, char *path, main_window *widgets){
        GtkTreeIter filter_iter;
        GtkTreeIter iter,itor;
        GtkTreeModel *model;
        GtkTreeModel *filter;
        GtkTreeModel *sort;
        if (gtk_notebook_get_current_page(GTK_NOTEBOOK(widgets->MainNotebook))==0){
            model = GTK_TREE_MODEL(widgets->SystemList);
            filter = GTK_TREE_MODEL(widgets->SystemFilter);
            sort = GTK_TREE_MODEL(widgets->SystemSort);
        } else {
            model = GTK_TREE_MODEL(widgets->UserList);
            filter = GTK_TREE_MODEL(widgets->UserFilter);
            sort = GTK_TREE_MODEL(widgets->UserSort);
        }
        GtkTreePath *path_converted = gtk_tree_path_new_from_string(path);
        gtk_tree_model_get_iter(sort,&filter_iter,path_converted);
        {
        gtk_tree_model_sort_convert_iter_to_child_iter(GTK_TREE_MODEL_SORT(sort),&itor,&filter_iter);
        gtk_tree_model_filter_convert_iter_to_child_iter(GTK_TREE_MODEL_FILTER(filter),&iter,&itor);
        gboolean status = 0;
        char *service_name;
        gtk_tree_model_get(model,&iter,3,&status,5,&service_name,-1);
        dialog_confirmation_data *data = yon_confirmation_dialog_data_new();
        data->action_text=(!status)==0 ?SERVICE_DISABLE_WARNING_LABEL(service_name):SERVICE_ENABLE_WARNING_LABEL(service_name);
        data->data=(!status)==1 ? service_enable_command(service_name) : \
         service_disable_command(service_name);
        data->function=(void*)(void*)on_system_autostart_confirmed;
        data->title = status?SERVICE_AUTOSTOP_TITLE_LABEL:SERVICE_AUTOSTART_TITLE_LABEL;
        int responce = yon_confirmation_dialog_call(widgets->Window,data);
        if (responce == GTK_RESPONSE_ACCEPT){
        gtk_list_store_set(GTK_LIST_STORE(model),&iter,3,!status,-1);
        }
    }
}

gboolean sort_bool(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b,gpointer col){
    int val_a,val_b;
    char *name_a="", *name_b="";
    gtk_tree_model_get(model,a,GPOINTER_TO_INT(col),&val_a,6,&name_a,-1);
    gtk_tree_model_get(model,b,GPOINTER_TO_INT(col),&val_b,6,&name_b,-1);
    if (val_a==val_b){
        gchar *key_a = g_utf8_collate_key(name_a, -1);
        gchar *key_b = g_utf8_collate_key(name_b, -1);
        gint result = strcmp(key_a, key_b);
        g_free(key_a);
        g_free(key_b);

        return result;
    }
    return val_a ? -1 : 1;
}

gboolean sort_string(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b,gpointer col){
    char *name_a="", *name_b="";
    gtk_tree_model_get(model,a,GPOINTER_TO_INT(col),&name_a,-1);
    gtk_tree_model_get(model,b,GPOINTER_TO_INT(col),&name_b,-1);
    if (!name_a) name_a="";
    if (!name_b) name_b="";
    gchar *key_a = g_utf8_collate_key(name_a, -1);
    gchar *key_b = g_utf8_collate_key(name_b, -1);
    gint result = strcmp(key_a, key_b);
    g_free(key_a);
    g_free(key_b);

    return result;
}

gboolean yon_filter(GtkTreeModel* model, GtkTreeIter *iter, main_window *widgets){
    gboolean autostart,autostop,masked,type,loaded,active;
    char *name;
    gtk_tree_model_get(model,iter,0,&autostart,1,&autostop,2,&masked,5,&name,7,&type,8,&active,9,&loaded,-1);
    GtkWidget *combo=NULL;
    GtkWidget *loaded_check=NULL;
    GtkWidget *active_check=NULL;
    GtkWidget *name_entry = NULL;
    if (model == GTK_TREE_MODEL(widgets->SystemList)){
        combo = widgets->SystemFiltersCombo;
        loaded_check = widgets->SystemUnloadedShowCheck;
        active_check = widgets->SystemInactiveShowCheck;
        name_entry = widgets->SystemSearchEntry;
    }
    if (model == GTK_TREE_MODEL(widgets->UserList)){
            combo = widgets->UserFiltersCombo;
            loaded_check = widgets->UserUnloadedShowCheck;
            active_check = widgets->UserInactiveShowCheck;
            name_entry = widgets->UserSearchEntry;
    }
    int type_filter = 1;
    int active_filter = 0;
    int loaded_filter = 0;
    int name_filter = 1;

    int filter_active = gtk_combo_box_get_active(GTK_COMBO_BOX(combo));
    if (filter_active>0){
        if (filter_active>3){
        char *text = (char*)gtk_combo_box_get_active_id(GTK_COMBO_BOX(combo));
        if (yon_get_unit_type(text)!=(enum YON_UNIT_TYPE)type) type_filter = 0;
        } else {
            switch (filter_active){
                case 1: if (!autostart) type_filter=0;
                    break;
                case 2: if (!autostop) type_filter=0;
                    break;
                case 3: if (!masked) type_filter=0;
                    break;
            }
        }
    }

    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(active_check))){
        active_filter=1;

        if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(loaded_check)))
            loaded_filter=1;
    }

    char *name_text = (char*)gtk_entry_get_text(GTK_ENTRY(name_entry));
    if (name&&!yon_char_is_empty(name_text)&&!strstr(g_utf8_strdown(name,strlen(name)),g_utf8_strdown(name_text,strlen(name_text))))
        name_filter=0;
    if (type_filter&&(active_filter||active)&&(loaded_filter||loaded)&&name_filter){
        return 1;
    }
    return 0;
}

void on_filter_changed(GtkWidget *, main_window *widgets){
    int page = gtk_notebook_get_current_page(GTK_NOTEBOOK(widgets->MainNotebook));
    if (page == 0){
        gtk_tree_view_set_model(GTK_TREE_VIEW(widgets->SystemUnitsTree),NULL);
        gtk_tree_model_filter_refilter(widgets->SystemFilter);
        gtk_tree_view_set_model(GTK_TREE_VIEW(widgets->SystemUnitsTree),GTK_TREE_MODEL(widgets->SystemSort));
    } else if (page == 1){
        gtk_tree_view_set_model(GTK_TREE_VIEW(widgets->UserUnitsTree),NULL);
        gtk_tree_model_filter_refilter(widgets->UserFilter);
        gtk_tree_view_set_model(GTK_TREE_VIEW(widgets->UserUnitsTree),GTK_TREE_MODEL(widgets->UserSort));
    }
}

void on_system_kill_confirmed(GtkWidget *,char *service_name){
    yon_launch(yon_debug_output("%s\n",service_name));
}

void on_system_launch_clicked(GtkWidget *, char *path, main_window *widgets){
        GtkTreeIter iter, itor, filter_iter;
        GtkTreeModel *model;
        GtkTreeModel *filter;
        GtkTreeModel *sort;
        if (gtk_notebook_get_current_page(GTK_NOTEBOOK(widgets->MainNotebook))==0){
            model = GTK_TREE_MODEL(widgets->SystemList);
            filter = GTK_TREE_MODEL(widgets->SystemFilter);
            sort = GTK_TREE_MODEL(widgets->SystemSort);
        } else {
            model = GTK_TREE_MODEL(widgets->UserList);
            filter = GTK_TREE_MODEL(widgets->UserFilter);
            sort = GTK_TREE_MODEL(widgets->UserSort);
        }
        GtkTreePath *path_converted = gtk_tree_path_new_from_string(path);
        gtk_tree_model_get_iter(sort,&filter_iter,path_converted);
        {
        gtk_tree_model_sort_convert_iter_to_child_iter(GTK_TREE_MODEL_SORT(sort),&itor,&filter_iter);
        gtk_tree_model_filter_convert_iter_to_child_iter(GTK_TREE_MODEL_FILTER(filter),&iter,&itor);
        gboolean status = 0;
        char *service_name;
        gtk_tree_model_get(model,&iter,4,&status,5,&service_name,-1);
        if (status){
            dialog_confirmation_data *data = yon_confirmation_dialog_data_new();
            data->action_text=SERVICE_STOP_WARNING_LABEL(service_name);
            data->data=service_stop_command(service_name);
            data->title = SERVICE_STOP_TITLE_LABEL;
            int size;
            config_str result = yon_config_load(service_check_active_command(service_name),&size);
            yon_char_remove_last_symbol(result[0],'\n');
            if (size>0&&!strcmp(result[0],"active")){
                int responce = yon_confirmation_dialog_call(widgets->Window,data);
                if (responce == GTK_RESPONSE_ACCEPT){
                    on_system_kill_confirmed(NULL,data->data);
                    result = yon_config_load(service_check_active_command(service_name),&size);
                    yon_char_remove_last_symbol(result[0],'\n');
                    if (strcmp(result[0],"active")){
                        gtk_list_store_set(GTK_LIST_STORE(model),&iter,4,0,-1);
                    } else {
                        yon_ubl_status_box_render(SERVICE_STOP_FAILED_LABEL,BACKGROUND_IMAGE_FAIL_TYPE);
                    }

                }
            } else {
                        gtk_list_store_set(GTK_LIST_STORE(model),&iter,4,0,-1);

            }
            yon_char_parsed_free(result,size);
        } else {
            dialog_confirmation_data *data = yon_confirmation_dialog_data_new();
            data->action_text=SERVICE_START_WARNING_LABEL(service_name);
            data->data=service_start_command(service_name);
            data->function=(void*)(void*)on_system_kill_confirmed;
            data->title = SERVICE_START_TITLE_LABEL;
            int size;
            config_str result = yon_config_load(service_check_active_command(service_name),&size);
            yon_char_remove_last_symbol(result[0],'\n');
            if (size>0&&strcmp(result[0],"active")){
                int responce = yon_confirmation_dialog_call(widgets->Window,data);
                if (responce == GTK_RESPONSE_ACCEPT){
                    gtk_list_store_set(GTK_LIST_STORE(model),&iter,4,1,-1);
                        yon_ubl_status_box_render(SERVICE_START_SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
                }
            }
        }
    }

}

void on_service_restart_confirmed(GtkWidget *self,char *service_name){
    if (self){};
    char *command = restart_command(service_name);
    yon_launch_app_with_arguments(yon_debug_output("%s\n",command),"");
}

void on_system_restart_clicked(GtkWidget *, main_window *widgets){
    GtkWidget *target_tree;
    switch(gtk_notebook_get_current_page(GTK_NOTEBOOK(widgets->MainNotebook))){
        case 0:target_tree=widgets->SystemUnitsTree;
            break;
        case 1: target_tree = widgets->UserUnitsTree;
            break;
        default: return;
    }
    GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(target_tree));
    GtkTreeIter iter;
    if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(target_tree)),&model,&iter)){
        char *target;
        gtk_tree_model_get(model,&iter,5,&target,-1);
        dialog_confirmation_data *data = yon_confirmation_dialog_data_new();
        data->action_text=REEXEC_SERVICE_WARMING_LABEL(target);
        data->data=target;
        data->function=(void*)(void*)on_service_restart_confirmed;
        data->title = RELAUNCH_SERVICE_LABEL;
        int responce = yon_confirmation_dialog_call(widgets->Window,data);
        if (responce == GTK_RESPONSE_ACCEPT){
            yon_ubl_status_box_render(SERVICE_RELOAD_SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
        }
    }
}

void on_configs_selection_changed(GtkWidget *,main_window *widgets){
    GtkTreeIter iter;
    GtkTreeModel *model;
    if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->ConfigMainTree)),&model,&iter)){
        gtk_widget_set_sensitive(widgets->ConfigEditButton,1);
    } else {
        gtk_widget_set_sensitive(widgets->ConfigEditButton,0);
    }
}

void on_sessions_selection_changed(GtkWidget *, main_window *widgets){
    GtkTreeIter iter;
    GtkTreeModel *model;
    if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->SessionMainTree)),&model,&iter)){
        gtk_widget_set_sensitive(widgets->SessionStopButton,1);
        gtk_widget_set_sensitive(widgets->SessionBlockButton,1);
        gtk_widget_set_sensitive(widgets->SessionStartButton,1);
        gtk_widget_set_sensitive(widgets->SessionSwitchButton,1);
    } else {
        gtk_widget_set_sensitive(widgets->SessionStopButton,0);
        gtk_widget_set_sensitive(widgets->SessionBlockButton,0);
        gtk_widget_set_sensitive(widgets->SessionStartButton,0);
        gtk_widget_set_sensitive(widgets->SessionSwitchButton,0);
    }
}

gboolean yon_sessions_update(main_window *widgets){
    gtk_tree_view_set_model(GTK_TREE_VIEW(widgets->SessionMainTree),NULL);
    gtk_list_store_clear(widgets->SessionsList);
    int sessions_size;
    config_str sessions = yon_config_load(list_of_session_command,&sessions_size);
    for (int i=0;i<sessions_size;i++){
        if (sessions[i][strlen(sessions[i])-1]=='\n') sessions[i][strlen(sessions[i])-1] = '\0';
        GtkTreeIter iter;
        int size;
        config_str parsed = yon_char_parse(sessions[i],&size," ");
        if (!strcmp(parsed[1],"\001")) parsed[1]=ACTIVE_LABEL;
        else parsed[1]=INACTIVE_LABEL;
        if (parsed&&size>4){
            gtk_list_store_append(widgets->SessionsList,&iter);
            gtk_list_store_set(widgets->SessionsList,&iter,0,atoi(parsed[0]),1,parsed[1],2,atoi(parsed[2]),3,parsed[3],4,parsed[4],5,parsed[4],6,parsed[5],-1);
        }
    }
    gtk_tree_view_set_model(GTK_TREE_VIEW(widgets->SessionMainTree),GTK_TREE_MODEL(widgets->SessionsList));
    return G_SOURCE_REMOVE;
}

void on_session_activate(GtkWidget *self, main_window *widgets){
    GtkTreeModel *model = GTK_TREE_MODEL(widgets->SessionsList);
    GtkTreeIter iter;
    if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->SessionMainTree)),&model,&iter)){

        int id;
        gtk_tree_model_get(model,&iter,0,&id,-1);
        dialog_confirmation_data *data = yon_confirmation_dialog_data_new();
        char *convert = yon_char_from_int(id);
        data->action_text = SESSION_ACTIVATE_TOOLTIP_LABEL(convert);
        data->title = SESSION_SWITCH_TITLE_LABEL(convert);
        if (yon_confirmation_dialog_call(self,data) == GTK_RESPONSE_ACCEPT){ 
            yon_launch(yon_debug_output("%s\n",session_activate_session(convert)));
            free(convert);
            yon_sessions_update(widgets);
        }
    }
}

void on_session_end(GtkWidget *self, main_window *widgets){
    GtkTreeModel *model = GTK_TREE_MODEL(widgets->SessionsList);
    GtkTreeIter iter;
    if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->SessionMainTree)),&model,&iter)){
        int id;
        gtk_tree_model_get(model,&iter,0,&id,-1);
        dialog_confirmation_data *data = yon_confirmation_dialog_data_new();
        char *convert = yon_char_from_int(id);
        data->action_text = SESSION_END_TOOLTIP_LABEL(convert);
        data->title = SESSION_TERMINATE_TITLE_LABEL(convert);
        if (yon_confirmation_dialog_call(self,data) == GTK_RESPONSE_ACCEPT){ 
            if (!system(yon_debug_output("%s\n",session_terminate_session(convert)))){
                GtkTreeModel *model;
                GtkTreeIter iter;
                if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->SessionMainTree)),&model, &iter)){
                    gtk_list_store_remove(widgets->SessionsList,&iter);
                    
                }
            }
            free(convert);
        }
    }
}

void on_session_unlock(GtkWidget *self, main_window *widgets){
    GtkTreeModel *model = GTK_TREE_MODEL(widgets->SessionsList);
    GtkTreeIter iter;
    if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->SessionMainTree)),&model,&iter)){
        int id;
        gtk_tree_model_get(model,&iter,0,&id,-1);
        dialog_confirmation_data *data = yon_confirmation_dialog_data_new();
        char *convert = yon_char_from_int(id);
        data->action_text = SESSION_UNLOCK_TOOLTIP_LABEL(convert);
        data->data = NULL;
        data->function = NULL;
        data->title = SESSION_UNLOCK_TITLE_LABEL(convert);
        if (yon_confirmation_dialog_call(self,data) == GTK_RESPONSE_ACCEPT){ 
            yon_launch(yon_debug_output("%s\n",session_unlock_session(convert)));
            free(convert);
            yon_sessions_update(widgets);
        }
    }
}

void on_session_block(GtkWidget *self, main_window *widgets){
    GtkTreeModel *model = GTK_TREE_MODEL(widgets->SessionsList);
    GtkTreeIter iter;
    if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->SessionMainTree)),&model,&iter)){
        int id;
        gtk_tree_model_get(model,&iter,0,&id,-1);
        dialog_confirmation_data *data = yon_confirmation_dialog_data_new();
        char *convert = yon_char_from_int(id);
        data->action_text = SESSION_BLOCK_TOOLTIP_LABEL(convert);
        data->data = NULL;
        data->function = NULL;
        data->title = SESSION_LOCK_TITLE_LABEL(convert);
        if (yon_confirmation_dialog_call(self,data) == GTK_RESPONSE_ACCEPT){ 
            yon_launch(yon_debug_output("%s\n",session_lock_session(convert)));
            free(convert);
            yon_sessions_update(widgets);
        }
    }
}

log_window *yon_log_window_new(){
    log_window *window = malloc(sizeof(log_window));
    GtkBuilder *builder = gtk_builder_new_from_resource(glade_path_log);
    window->Window = yon_gtk_builder_get_widget(builder,"MonitorWindow");
    window->SystemTerminal = yon_gtk_builder_get_widget(builder,"SystemTerminal");
    window->TerminalScroll = yon_gtk_builder_get_widget(builder,"TerminalScroll");
    window->TextEditor = yon_gtk_builder_get_widget(builder,"TextEditor");
    window->webHeaderNameLabel = yon_gtk_builder_get_widget(builder,"webHeaderNameLabel");
    window->UpdateButton = yon_gtk_builder_get_widget(builder,"UpdateButton");
    window->SaveButton = yon_gtk_builder_get_widget(builder,"SaveButton");
    window->StatusBox = yon_gtk_builder_get_widget(builder,"StatusBox");
    window->target=NULL;
    window->adjustment = GTK_ADJUSTMENT(gtk_builder_get_object(builder,"adjustment1"));
    yon_gtk_widget_set_scroll_window_for_scroll(window->Window,GTK_SCROLLBAR(window->TerminalScroll));
    gtk_window_set_icon_name(GTK_WINDOW(window->Window),"com.ublinux.ubl-settings-services");
    GdkRGBA rgba;
    vte_terminal_get_color_background_for_draw(VTE_TERMINAL(window->SystemTerminal),&rgba);
    vte_terminal_set_color_cursor(VTE_TERMINAL(window->SystemTerminal),&rgba);
    yon_window_config_custom_window_setup(GTK_WINDOW(window->Window),"terminal_window");
    g_signal_connect(G_OBJECT(window->UpdateButton),"clicked",G_CALLBACK(on_update_clicked),window);
    return window;
}

void yon_system_systemd_restart(GtkWidget *, main_window *widgets){
    if (widgets){
        if (!getuid()&&gtk_notebook_get_current_page(GTK_NOTEBOOK(widgets->MainNotebook))==0){
            if (system(yon_debug_output("%s\n",reload_systemd_root_command))){
                yon_ubl_status_box_render(SYSTEMD_RELAUNCH_ERROR_LABEL,BACKGROUND_IMAGE_FAIL_TYPE);
            } else {
                yon_ubl_status_box_render(SYSTEMD_RELAUNCH_SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);

            }
        } else {
            if (system(yon_debug_output("%s\n",reload_systemd_user_command))){
                yon_ubl_status_box_render(SYSTEMD_RELAUNCH_ERROR_LABEL,BACKGROUND_IMAGE_FAIL_TYPE);
            } else {
                yon_ubl_status_box_render(SYSTEMD_RELAUNCH_SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);

            }
        }
    }
}

void yon_system_systemd_reexec(GtkWidget *, main_window *widgets){
    if (widgets){
        if (getuid()!=0&&gtk_notebook_get_current_page(GTK_NOTEBOOK(widgets->MainNotebook))==0){
            if (system(yon_debug_output("%s\n",reexec_systemd_root_command))){
                yon_ubl_status_box_render(SYSTEMD_REEXEC_ERROR_LABEL,BACKGROUND_IMAGE_FAIL_TYPE);
            } else {
                yon_ubl_status_box_render(SYSTEMD_REEXEC_SUCCESS_LABEL,BACKGROUND_IMAGE_FAIL_TYPE);

            }
        } else {
            if (system(yon_debug_output("%s\n",reexec_systemd_user_command))){
                yon_ubl_status_box_render(SYSTEMD_REEXEC_ERROR_LABEL,BACKGROUND_IMAGE_FAIL_TYPE);
            } else {
                yon_ubl_status_box_render(SYSTEMD_REEXEC_SUCCESS_LABEL,BACKGROUND_IMAGE_FAIL_TYPE);

            }
        }
    }
}

typedef void (*data_function)(void*,void*);

void on_system_update_hz_clicked(GtkWidget *self, main_window *widgets){
    if (widgets){
        dialog_confirmation_data *data = yon_confirmation_dialog_data_new();
        if (gtk_notebook_get_current_page(GTK_NOTEBOOK(widgets->MainNotebook))==0){
            data->action_text = RELOAD_SYSTEM_SETTINGS_WARNING_LABEL;
        }else if (gtk_notebook_get_current_page(GTK_NOTEBOOK(widgets->MainNotebook))==1){
            data->action_text = RELOAD_USER_SETTINGS_WARNING_LABEL;
        }
        data->data = widgets; 
        data->function = (data_function)yon_system_systemd_restart;
        data->title = RELAUNCH_SYSTEMCTL_LABEL;
        yon_confirmation_dialog_call(self,data);

    }
}

void on_system_update_clicked(GtkWidget *self, main_window *widgets){
 if (widgets){
        dialog_confirmation_data *data = yon_confirmation_dialog_data_new();
        data->action_text = REEXEC_SERVICE_WARMING_LABEL("systemd");
        data->data = widgets; 
        data->function = (data_function)yon_system_systemd_reexec;
        yon_confirmation_dialog_call(self,data);
 }

}

void on_system_info_clicked(GtkWidget *, main_window *widgets){
 if (widgets){
    GtkTreeIter iter;
    GtkTreeModel *model = GTK_TREE_MODEL(widgets->SystemList);
    if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->SystemUnitsTree)),&model,&iter)){
        char *name;
        gtk_tree_model_get(model,&iter,5,&name,-1);
        log_window *window = yon_log_window_new();
        gtk_label_set_text(GTK_LABEL(window->webHeaderNameLabel),SERVICE_STATE_TITLE_LABEL(name));
        gtk_window_set_title(GTK_WINDOW(window->Window),SERVICE_STATE_TITLE_LABEL(name));
        window->target = service_info_command(name);
        yon_terminal_integrated_start_shell(window->SystemTerminal,window->target,NULL,NULL);
        gtk_widget_show(window->Window);
    }
 }

}

void on_system_log_clicked(GtkWidget *, main_window *widgets){
 if (widgets){
    GtkTreeIter iter;
    GtkTreeModel *model = GTK_TREE_MODEL(widgets->SystemList);
    if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->SystemUnitsTree)),&model,&iter)){
        char *name;
        gtk_tree_model_get(model,&iter,5,&name,-1);
        log_window *window = yon_log_window_new();
        gtk_label_set_text(GTK_LABEL(window->webHeaderNameLabel),SERVICE_LOG_TITLE_LABEL(name));
        gtk_window_set_title(GTK_WINDOW(window->Window),SERVICE_LOG_TITLE_LABEL(name));
        window->target = get_log_command(name);
        yon_terminal_integrated_start_shell(window->SystemTerminal,window->target,NULL,NULL);
        gtk_widget_show(window->Window);
    }
 }

}

gboolean on_terminal_relaunch(log_window *window){
    gtk_widget_set_sensitive(window->SystemTerminal,0);
    sleep(1);
    gtk_widget_set_sensitive(window->SystemTerminal,1);
    yon_terminal_integrated_start_shell(window->SystemTerminal,window->target,NULL,NULL);
    return G_SOURCE_REMOVE;
}

void on_save_clicked(GtkWidget *, log_window *window){
    vte_terminal_feed_child(VTE_TERMINAL(window->SystemTerminal),"\30",-1);
    vte_terminal_feed_child(VTE_TERMINAL(window->SystemTerminal),"Y\r",-1);
    gtk_widget_grab_focus(window->SystemTerminal);
    g_idle_add((GSourceFunc)on_terminal_relaunch,window);
}

void on_update_clicked(GtkWidget *, log_window *window){
    yon_terminal_integrated_start_shell(window->SystemTerminal,window->target,NULL,NULL);
}

void on_system_edit_clicked(GtkWidget *, main_window *widgets){
 if (widgets){
    GtkTreeIter iter;
    GtkTreeModel *model = GTK_TREE_MODEL(widgets->SystemList);
    if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->SystemUnitsTree)),&model,&iter)){
        char *name;
        gtk_tree_model_get(model,&iter,5,&name,-1);
        log_window *window = yon_log_window_new();
        gtk_label_set_text(GTK_LABEL(window->webHeaderNameLabel),SERVICE_UNIT_EDIT_TITLE_LABEL);
        gtk_window_set_title(GTK_WINDOW(window->Window),SERVICE_UNIT_EDIT_TITLE_LABEL);
        gtk_widget_show(window->SaveButton);
        window->target=show_source_command(name);
        yon_terminal_integrated_start_shell(window->SystemTerminal,window->target,NULL,NULL);
        GdkRGBA rgba;
        rgba.blue=1;
        rgba.green=1;
        rgba.red=1;
        vte_terminal_set_color_cursor(VTE_TERMINAL(window->SystemTerminal),&rgba);
        gtk_widget_set_sensitive(window->SystemTerminal,1);
        g_signal_connect(G_OBJECT(window->SaveButton),"clicked",G_CALLBACK(on_save_clicked),window);
        gtk_widget_show(window->Window);
    }
 }

}

void on_system_status_clicked(GtkWidget *, main_window *widgets){
 if (widgets){
    GtkTreeIter iter;
    GtkTreeModel *model = GTK_TREE_MODEL(widgets->SystemList);
    if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->SystemUnitsTree)),&model,&iter)){
        char *name;
        gtk_tree_model_get(model,&iter,5,&name,-1);
        log_window *window = yon_log_window_new();
        gtk_label_set_text(GTK_LABEL(window->webHeaderNameLabel),PROPERTIES_LABEL);
        gtk_window_set_title(GTK_WINDOW(window->Window),PROPERTIES_LABEL);
        window->target = properties_command(name);
        yon_terminal_integrated_start_shell(window->SystemTerminal,window->target,NULL,NULL);
        gtk_widget_show(window->Window);
    }
    
 }

}

void on_user_update_hz_clicked(GtkWidget *self, main_window *widgets){
    if (widgets){
        dialog_confirmation_data *data = yon_confirmation_dialog_data_new();
        data->action_text = REEXEC_SERVICE_WARMING_LABEL("systemd");
        data->data = widgets; 
        data->function = (data_function)yon_system_systemd_restart;
        data->title = REEXEC_SYSTEMCTL_LABEL;
        yon_confirmation_dialog_call(self,data);

    }

}

void on_user_update_clicked(GtkWidget *self, main_window *widgets){
 if (widgets){
        dialog_confirmation_data *data = yon_confirmation_dialog_data_new();
        data->action_text = RELOAD_SERVICE_WARMING_LABEL("systemd");
        data->data = widgets; 
        data->function = (data_function)yon_system_systemd_reexec;
        yon_confirmation_dialog_call(self,data);
 }

}

void on_user_info_clicked(GtkWidget *, main_window *widgets){
 if (widgets){
    GtkTreeIter iter;
    GtkTreeModel *model = GTK_TREE_MODEL(widgets->UserList);
    if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->UserUnitsTree)),&model,&iter)){
        char *name;
        gtk_tree_model_get(model,&iter,5,&name,-1);
        log_window *window = yon_log_window_new();
        gtk_label_set_text(GTK_LABEL(window->webHeaderNameLabel),SERVICE_STATE_TITLE_LABEL(name));
        gtk_window_set_title(GTK_WINDOW(window->Window),SERVICE_STATE_TITLE_LABEL(name));
        window->target = user_service_info_command(name);
        yon_terminal_integrated_start_shell(window->SystemTerminal,window->target,NULL,NULL);
        gtk_widget_show(window->Window);
    }
 }

}

void on_user_log_clicked(GtkWidget *, main_window *widgets){
 if (widgets){
    GtkTreeIter iter;
    GtkTreeModel *model = GTK_TREE_MODEL(widgets->UserList);
    if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->UserUnitsTree)),&model,&iter)){
        char *name;
        gtk_tree_model_get(model,&iter,5,&name,-1);
        log_window *window = yon_log_window_new();
        gtk_label_set_text(GTK_LABEL(window->webHeaderNameLabel),SERVICE_LOG_TITLE_LABEL(name));
        gtk_window_set_title(GTK_WINDOW(window->Window),SERVICE_LOG_TITLE_LABEL(name));
        window->target = user_get_log_command(name);
        yon_terminal_integrated_start_shell(window->SystemTerminal,window->target,NULL,NULL);
        gtk_widget_show(window->Window);
    }
 }

}

void on_user_edit_clicked(GtkWidget *, main_window *widgets){
 if (widgets){
    GtkTreeIter iter;
    GtkTreeModel *model = GTK_TREE_MODEL(widgets->UserList);
    if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->UserUnitsTree)),&model,&iter)){
        char *name;
        gtk_tree_model_get(model,&iter,5,&name,-1);
        log_window *window = yon_log_window_new();
        gtk_label_set_text(GTK_LABEL(window->webHeaderNameLabel),SERVICE_UNIT_EDIT_TITLE_LABEL);
        gtk_window_set_title(GTK_WINDOW(window->Window),SERVICE_UNIT_EDIT_TITLE_LABEL);
        gtk_widget_show(window->SaveButton);
        window->target=user_show_source_command(name);
        yon_terminal_integrated_start_shell(window->SystemTerminal,window->target,NULL,NULL);
        GdkRGBA rgba;
        rgba.blue=1;
        rgba.green=1;
        rgba.red=1;
        vte_terminal_set_color_cursor(VTE_TERMINAL(window->SystemTerminal),&rgba);
        gtk_widget_set_sensitive(window->SystemTerminal,1);
        g_signal_connect(G_OBJECT(window->SaveButton),"clicked",G_CALLBACK(on_save_clicked),window);
        gtk_widget_show(window->Window);
    }
 }

}

void on_user_status_clicked(GtkWidget *, main_window *widgets){
 if (widgets){
    GtkTreeIter iter;
    GtkTreeModel *model = GTK_TREE_MODEL(widgets->UserList);
    if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->UserUnitsTree)),&model,&iter)){
        char *name;
        gtk_tree_model_get(model,&iter,5,&name,-1);
        log_window *window = yon_log_window_new();
        gtk_label_set_text(GTK_LABEL(window->webHeaderNameLabel),PROPERTIES_LABEL);
        gtk_window_set_title(GTK_WINDOW(window->Window),PROPERTIES_LABEL);
        window->target = user_properties_command(name);
        yon_terminal_integrated_start_shell(window->SystemTerminal,window->target,NULL,NULL);
        gtk_widget_show(window->Window);
    }
    
 }

}

void on_config_log_save(GtkWidget *, log_window *window){
    GtkTextIter start, end;
    GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(window->TextEditor));
    gtk_text_buffer_get_end_iter(buffer,&end);
    gtk_text_buffer_get_start_iter(buffer,&start);
    char *text = gtk_text_buffer_get_text(buffer,&start,&end,1);
    if (text){
        if (yon_file_save(window->target,text)){
            yon_ubl_status_box_spawn(GTK_CONTAINER(window->StatusBox),SAVED_LABEL,5,BACKGROUND_IMAGE_SUCCESS_TYPE);
        } else {
            yon_ubl_status_box_spawn(GTK_CONTAINER(window->StatusBox),ERROR_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE);
        }
    }
}

void on_config_edit_clicked(GtkWidget *, main_window *widgets){
 if (widgets){
    GtkTreeIter iter;
    GtkTreeModel *model = GTK_TREE_MODEL(widgets->ConfigList);
    if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->ConfigMainTree)),&model,&iter)){
        log_window *window = yon_log_window_new();
        if (getuid())
            gtk_widget_set_sensitive(window->SaveButton,0);
        gtk_label_set_text(GTK_LABEL(window->webHeaderNameLabel),EDIT_CONFIG_LABEL);
        gtk_window_set_title(GTK_WINDOW(window->Window),EDIT_CONFIG_LABEL);
        gtk_widget_hide(gtk_widget_get_parent(window->SystemTerminal));
        gtk_widget_show(gtk_widget_get_parent(window->TextEditor));
        gtk_widget_show(window->SaveButton);
        char *name;
        gtk_tree_model_get(model,&iter,0,&name,-1);
        int size;
        window->target = name;
        config_str parsed = yon_config_load(config_get_command(name),&size);
        char *text = yon_char_parsed_to_string(parsed,size,"");
        gtk_text_buffer_set_text(gtk_text_view_get_buffer(GTK_TEXT_VIEW(window->TextEditor)),text,-1);
        g_signal_connect(G_OBJECT(window->SaveButton),"clicked",G_CALLBACK(on_config_log_save),window);
        gtk_widget_show(window->Window);
    }
    
 }

}

void on_system_services_status(GtkWidget *, main_window *widgets){
 if (widgets){
        log_window *window = yon_log_window_new();
        gtk_label_set_text(GTK_LABEL(window->webHeaderNameLabel),SYSTEM_STATUS_LABEL);
        gtk_window_set_title(GTK_WINDOW(window->Window),SYSTEM_STATUS_LABEL);
        window->target = system_services_status_command;
        yon_terminal_integrated_start_shell(window->SystemTerminal,window->target,NULL,NULL);
        gtk_widget_show(window->Window);
    
 }
    
}

void on_user_services_status(GtkWidget *, main_window *widgets){
 if (widgets){
        log_window *window = yon_log_window_new();
        gtk_label_set_text(GTK_LABEL(window->webHeaderNameLabel),USER_STATUS_LABEL);
        gtk_window_set_title(GTK_WINDOW(window->Window),USER_STATUS_LABEL);
        window->target = user_services_status_command;
        yon_terminal_integrated_start_shell(window->SystemTerminal,window->target,NULL,NULL);
        gtk_widget_show(window->Window);
    
 }
    
}

void on_units_status(GtkWidget *, main_window *widgets){
 if (widgets){
        log_window *window = yon_log_window_new();
        gtk_label_set_text(GTK_LABEL(window->webHeaderNameLabel),INSTALLED_UNIT_LABEL);
        gtk_window_set_title(GTK_WINDOW(window->Window),INSTALLED_UNIT_LABEL);
        window->target = !gtk_notebook_get_current_page(GTK_NOTEBOOK(widgets->MainNotebook))?installed_units_states_command:user_installed_units_states_command;
        yon_terminal_integrated_start_shell(window->SystemTerminal,window->target,NULL,NULL);
        gtk_widget_show(window->Window);
    
 }
    
}

void on_units_list_status(GtkWidget *, main_window *widgets){
 if (widgets){
        log_window *window = yon_log_window_new();
        gtk_label_set_text(GTK_LABEL(window->webHeaderNameLabel),UNITS_LIST_LABEL);
        gtk_window_set_title(GTK_WINDOW(window->Window),UNITS_LIST_LABEL);
        window->target = !gtk_notebook_get_current_page(GTK_NOTEBOOK(widgets->MainNotebook))?list_of_units_states_command:user_list_of_units_states_command;
        yon_terminal_integrated_start_shell(window->SystemTerminal,window->target,NULL,NULL);
        gtk_widget_show(window->Window);
    
 }
    
}

void on_sockets_list_status(GtkWidget *, main_window *widgets){
 if (widgets){
        log_window *window = yon_log_window_new();
        gtk_label_set_text(GTK_LABEL(window->webHeaderNameLabel),SOCKETS_LIST_LABEL);
        gtk_window_set_title(GTK_WINDOW(window->Window),SOCKETS_LIST_LABEL);
        window->target = !gtk_notebook_get_current_page(GTK_NOTEBOOK(widgets->MainNotebook))?list_of_sockets_states_command:user_list_of_sockets_states_command;
        yon_terminal_integrated_start_shell(window->SystemTerminal,window->target,NULL,NULL);
        gtk_widget_show(window->Window);
    
 }
    
}

void on_timers_list_status(GtkWidget *, main_window *widgets){
 if (widgets){
        log_window *window = yon_log_window_new();
        gtk_label_set_text(GTK_LABEL(window->webHeaderNameLabel),TIMERS_LIST_LABEL);
        gtk_window_set_title(GTK_WINDOW(window->Window),TIMERS_LIST_LABEL);
        window->target = !gtk_notebook_get_current_page(GTK_NOTEBOOK(widgets->MainNotebook))?list_of_timers_states_command:user_list_of_timers_states_command;
        yon_terminal_integrated_start_shell(window->SystemTerminal,window->target,NULL,NULL);
        gtk_widget_show(window->Window);
    
 }
    
}

gboolean yon_interface_list_models_disconnect(main_window *widgets){

        gtk_tree_view_set_model(GTK_TREE_VIEW(widgets->SystemUnitsTree),NULL);
        gtk_tree_view_set_model(GTK_TREE_VIEW(widgets->UserUnitsTree),NULL);
        gtk_tree_view_set_model(GTK_TREE_VIEW(widgets->ConfigMainTree),NULL);
        gtk_tree_view_set_model(GTK_TREE_VIEW(widgets->TimersMainTree),NULL);
        gtk_list_store_clear(widgets->SystemList);
        gtk_list_store_clear(widgets->UserList);
        gtk_list_store_clear(widgets->ConfigList);
        gtk_list_store_clear(widgets->TimersList);
        gtk_spinner_start(GTK_SPINNER(widgets->SystemLoadingSpinner));
        gtk_spinner_start(GTK_SPINNER(widgets->UserLoadingSpinner));
        gtk_spinner_start(GTK_SPINNER(widgets->ConfigLoadingSpinner));
        gtk_spinner_start(GTK_SPINNER(widgets->SessionsLoadingSpinner));
        gtk_spinner_start(GTK_SPINNER(widgets->TimersLoadingSpinner));
        gtk_widget_show(widgets->SystemLoadingSpinner);
        gtk_widget_show(widgets->UserLoadingSpinner);
        gtk_widget_show(widgets->ConfigLoadingSpinner);
        gtk_widget_show(widgets->SessionsLoadingSpinner);
        gtk_widget_show(widgets->TimersLoadingSpinner);
        gtk_widget_set_sensitive(widgets->UserInactiveShowCheck,0);
        gtk_widget_set_sensitive(widgets->UserUnloadedShowCheck,0);
        gtk_widget_set_sensitive(widgets->SystemInactiveShowCheck,0);
        gtk_widget_set_sensitive(widgets->SystemUnloadedShowCheck,0);
        gtk_widget_set_sensitive(widgets->UserSearchEntry,0);
        gtk_widget_set_sensitive(widgets->SystemSearchEntry,0);
        gtk_widget_set_sensitive(widgets->UserFiltersCombo,0);
        gtk_widget_set_sensitive(widgets->SystemFiltersCombo,0);

    g_signal_handlers_block_by_func(G_OBJECT(widgets->UserFiltersCombo),G_CALLBACK(on_filter_changed),widgets);
    g_signal_handlers_block_by_func(G_OBJECT(widgets->UserSearchEntry),G_CALLBACK(on_filter_changed),widgets);
    g_signal_handlers_block_by_func(G_OBJECT(widgets->UserInactiveShowCheck),G_CALLBACK(on_filter_changed),widgets);
    g_signal_handlers_block_by_func(G_OBJECT(widgets->UserUnloadedShowCheck),G_CALLBACK(on_filter_changed),widgets);
        return G_SOURCE_REMOVE;
}

void on_sort_activate(GtkTreeViewColumn *self, main_window *widgets){
    if (self == gtk_tree_view_get_column(GTK_TREE_VIEW(widgets->SystemUpperTree),2)){
        gtk_tree_view_column_clicked(gtk_tree_view_get_column(GTK_TREE_VIEW(widgets->SystemUnitsTree),6));
    } else {
        gtk_tree_view_column_clicked(gtk_tree_view_get_column(GTK_TREE_VIEW(widgets->UserUnitsTree),6));
    }
}

gboolean yon_interface_list_models_connect(main_window *widgets){
        gtk_tree_view_set_model(GTK_TREE_VIEW(widgets->SystemUnitsTree),GTK_TREE_MODEL(widgets->SystemSort));
        gtk_tree_view_set_model(GTK_TREE_VIEW(widgets->UserUnitsTree),GTK_TREE_MODEL(widgets->UserSort));
        gtk_tree_view_set_model(GTK_TREE_VIEW(widgets->ConfigMainTree),GTK_TREE_MODEL(widgets->ConfigList));
        gtk_tree_view_set_model(GTK_TREE_VIEW(widgets->TimersMainTree),GTK_TREE_MODEL(widgets->TimersList));
        gtk_spinner_stop(GTK_SPINNER(widgets->SystemLoadingSpinner));
        gtk_spinner_stop(GTK_SPINNER(widgets->UserLoadingSpinner));
        gtk_spinner_stop(GTK_SPINNER(widgets->ConfigLoadingSpinner));
        gtk_spinner_stop(GTK_SPINNER(widgets->SessionsLoadingSpinner));
        gtk_spinner_stop(GTK_SPINNER(widgets->TimersLoadingSpinner));
        gtk_widget_hide(widgets->SystemLoadingSpinner);
        gtk_widget_hide(widgets->UserLoadingSpinner);
        gtk_widget_hide(widgets->ConfigLoadingSpinner);
        gtk_widget_hide(widgets->SessionsLoadingSpinner);
        gtk_widget_hide(widgets->TimersLoadingSpinner);

        gtk_widget_set_sensitive(widgets->UserInactiveShowCheck,1);
        gtk_widget_set_sensitive(widgets->SystemInactiveShowCheck,1);
        if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->UserInactiveShowCheck))){
            gtk_widget_set_sensitive(widgets->UserUnloadedShowCheck,1);
        } else {
            gtk_widget_set_sensitive(widgets->UserUnloadedShowCheck,0);
        }
        if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->SystemInactiveShowCheck))){
            gtk_widget_set_sensitive(widgets->SystemUnloadedShowCheck,1);
        } else {
            gtk_widget_set_sensitive(widgets->SystemUnloadedShowCheck,0);
        }
        gtk_widget_set_sensitive(widgets->UserSearchEntry,1);
        gtk_widget_set_sensitive(widgets->SystemSearchEntry,1);
        gtk_widget_set_sensitive(widgets->UserFiltersCombo,1);
        gtk_widget_set_sensitive(widgets->SystemFiltersCombo,1);

    g_signal_handlers_unblock_by_func(G_OBJECT(widgets->UserFiltersCombo),G_CALLBACK(on_filter_changed),widgets);
    g_signal_handlers_unblock_by_func(G_OBJECT(widgets->UserSearchEntry),G_CALLBACK(on_filter_changed),widgets);
    g_signal_handlers_unblock_by_func(G_OBJECT(widgets->UserInactiveShowCheck),G_CALLBACK(on_filter_changed),widgets);
    g_signal_handlers_unblock_by_func(G_OBJECT(widgets->UserUnloadedShowCheck),G_CALLBACK(on_filter_changed),widgets);
        return G_SOURCE_REMOVE;
}

gboolean yon_system_set(struct system_services_data *data){
    GtkTreeIter iter;
    gtk_list_store_append(data->widgets->SystemList,&iter);
    gtk_list_store_set(data->widgets->SystemList,&iter,3,data->SystemAutostart,4,data->SystemLaunched,5,data->Name,6,data->Descr,7,data->Type,8,data->Loaded,9,data->Active,11,_(data->State),13,data->State,-1);
    return G_SOURCE_REMOVE;
}

gboolean yon_user_set(struct system_user_data *data){
    GtkTreeIter iter;
    gtk_list_store_append(data->widgets->UserList,&iter);
    gtk_list_store_set(data->widgets->UserList,&iter,3,data->SystemAutostart,4,data->SystemLaunched,5,data->Name,6,data->Descr,5,data->Name,6,data->Descr,7,data->Type,8,data->Loaded,9,data->Active,11,_(data->State),13,data->State,-1);
    return G_SOURCE_REMOVE;
}

gboolean yon_system_config_set(struct system_config_data *data){
    GtkTreeIter iter;
    gtk_list_store_append(data->widgets->ConfigList,&iter);
    gtk_list_store_set(data->widgets->ConfigList,&iter,0,data->Name,1,data->Descr,2,data->Date,-1);
    return G_SOURCE_REMOVE;
}

gboolean yon_timers_set(struct system_timers_data *data){
    GtkTreeIter iter;
    gtk_list_store_append(data->widgets->TimersList,&iter);
    gtk_list_store_set(data->widgets->TimersList,&iter,0,data->unit,1,data->next,2,data->left,3,data->last,4,data->passed,5,data->activates,-1);
    return G_SOURCE_REMOVE;
}

gboolean yon_interface_update_finish(main_window *widgets){
    {
        int parsed_size;
        char *enabled = yon_config_get_by_key(SERVICES_ENABLE_PARAMETER);
        config_str parsed = yon_char_parse(enabled,&parsed_size,",");
        GtkTreeIter iter;
        GtkTreeModel *model = GTK_TREE_MODEL(widgets->SystemList);

        int valid = gtk_tree_model_get_iter_first(model,&iter);
        for (;valid;valid=gtk_tree_model_iter_next(model,&iter))
        {
            gtk_list_store_set(widgets->SystemList,&iter,0,0,-1);
        }
        valid = gtk_tree_model_get_iter_first(model,&iter);
        for (;valid;valid=gtk_tree_model_iter_next(model,&iter))
        {
            char *name;
            gtk_tree_model_get(model,&iter,5,&name,-1);
            for (int i=0;i<parsed_size;i++){
                if (yon_char_find_last(parsed[i],'.')==-1) {
                    char *temp = yon_char_append(parsed[i],".service");
                    free(parsed[i]);
                    parsed[i]=temp;
                }
                if (!strcmp(name,parsed[i])) 
                    gtk_list_store_set(widgets->SystemList,&iter,0,1,-1);
            }
        }
        yon_char_parsed_free(parsed,parsed_size);
        
        while(gtk_events_pending()) gtk_main_iteration();
        char *disabled = yon_config_get_by_key(SERVICES_DISABLE_PARAMETER);
        parsed = yon_char_parse(disabled,&parsed_size,",");
        valid = gtk_tree_model_get_iter_first(model,&iter);
        for (;valid;valid=gtk_tree_model_iter_next(model,&iter))
        {
            gtk_list_store_set(widgets->SystemList,&iter,1,0,-1);
        }
        valid = gtk_tree_model_get_iter_first(model,&iter);
        for (;valid;valid=gtk_tree_model_iter_next(model,&iter))
        {
            char *name;
            gtk_tree_model_get(model,&iter,5,&name,-1);
            for (int i=0;i<parsed_size;i++){
                if (strstr(name,parsed[i])) gtk_list_store_set(widgets->SystemList,&iter,1,1,-1);
            }
        }
        yon_char_parsed_free(parsed,parsed_size);
        
        while(gtk_events_pending()) gtk_main_iteration();
        char *masked = yon_config_get_by_key(SERVICES_MASK_parameter);
        parsed = yon_char_parse(masked,&parsed_size,",");
        valid = gtk_tree_model_get_iter_first(model,&iter);
        for (;valid;valid=gtk_tree_model_iter_next(model,&iter))
        {
            gtk_list_store_set(widgets->SystemList,&iter,2,0,-1);
        }
        valid = gtk_tree_model_get_iter_first(model,&iter);
        for (;valid;valid=gtk_tree_model_iter_next(model,&iter))
        {
            char *name;
            gtk_tree_model_get(model,&iter,5,&name,-1);
            for (int i=0;i<parsed_size;i++){
                if (strstr(name,parsed[i])) gtk_list_store_set(widgets->SystemList,&iter,2,1,-1);
            }
        }
    }
        while(gtk_events_pending()) gtk_main_iteration();
    {

        int parsed_size;
        char *enabled = yon_config_get_by_key(SERVICES_ENABLE_PARAMETER);
        config_str parsed = yon_char_parse(enabled,&parsed_size,",");
        GtkTreeIter iter;
        GtkTreeModel *model = GTK_TREE_MODEL(widgets->UserList);

        int valid = gtk_tree_model_get_iter_first(model,&iter);
        for (;valid;valid=gtk_tree_model_iter_next(model,&iter))
        {
            gtk_list_store_set(widgets->UserList,&iter,0,0,-1);
        }
        valid = gtk_tree_model_get_iter_first(model,&iter);
        for (;valid;valid=gtk_tree_model_iter_next(model,&iter))
        {
            char *name;
            gtk_tree_model_get(model,&iter,5,&name,-1);
            for (int i=0;i<parsed_size;i++){
                if (strstr(name,parsed[i])) gtk_list_store_set(widgets->UserList,&iter,0,1,-1);
            }
        }
        yon_char_parsed_free(parsed,parsed_size);
        
        while(gtk_events_pending()) gtk_main_iteration();
        char *disabled = yon_config_get_by_key(SERVICES_DISABLE_PARAMETER);
        parsed = yon_char_parse(disabled,&parsed_size,",");
        valid = gtk_tree_model_get_iter_first(model,&iter);
        for (;valid;valid=gtk_tree_model_iter_next(model,&iter))
        {
            gtk_list_store_set(widgets->UserList,&iter,1,0,-1);
        }
        valid = gtk_tree_model_get_iter_first(model,&iter);
        for (;valid;valid=gtk_tree_model_iter_next(model,&iter))
        {
            char *name;
            gtk_tree_model_get(model,&iter,5,&name,-1);
            for (int i=0;i<parsed_size;i++){
                if (strstr(name,parsed[i])) gtk_list_store_set(widgets->UserList,&iter,1,1,-1);
            }
        }
        yon_char_parsed_free(parsed,parsed_size);
        
        while(gtk_events_pending()) gtk_main_iteration();
        char *masked = yon_config_get_by_key(SERVICES_MASK_parameter);
        parsed = yon_char_parse(masked,&parsed_size,",");
        valid = gtk_tree_model_get_iter_first(model,&iter);
        for (;valid;valid=gtk_tree_model_iter_next(model,&iter))
        {
            gtk_list_store_set(widgets->UserList,&iter,2,0,-1);
        }
        valid = gtk_tree_model_get_iter_first(model,&iter);
        for (;valid;valid=gtk_tree_model_iter_next(model,&iter))
        {
            char *name;
            gtk_tree_model_get(model,&iter,5,&name,-1);
            for (int i=0;i<parsed_size;i++){
                if (strstr(name,parsed[i])) gtk_list_store_set(widgets->UserList,&iter,2,1,-1);
            }
        }
    }
    main_config.update_thread_active=0;
    if (!getuid()){
        char *final = yon_char_unite(yon_char_get_localised_from_lib(SUCCESS_LABEL),". ",main_config.load_mode==YON_CONFIG_GLOBAL?yon_char_get_localised_from_lib(GLOBAL_LOAD_SUCCESS_LABEL):yon_char_get_localised_from_lib(LOCAL_LOAD_SUCCESS_LABEL),NULL);
        yon_ubl_status_box_render(final,BACKGROUND_IMAGE_SUCCESS_TYPE);
        free(final);
    } else {
        textdomain(template_ui_LocaleName);
        yon_ubl_status_box_render(ROOT_WARNING_LABEL,BACKGROUND_IMAGE_FAIL_TYPE);
        textdomain(LocaleName);
    }
    return G_SOURCE_REMOVE;
}

void yon_service_update(main_window *widgets){
    int active_page = gtk_notebook_get_current_page(GTK_NOTEBOOK(widgets->MainNotebook));
    switch (active_page)
    {
    case 0:{
        GtkTreeModel *model;
        GtkTreeIter iter;
        gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->SystemUnitsTree)),&model,&iter);
        char *target;
        gtk_tree_model_get(model,&iter,5,&target,-1);
        int size;
        config_str new_info = yon_config_load(load_system_service_single(target),&size);
        int parsed_size;
        config_str parsed = yon_char_parse(new_info[0],&parsed_size,";");
            char *name_temp = yon_char_replace(parsed[0],"\\","\18");
            if (name_temp!=parsed[0]) free(parsed[0]);
            parsed[0]=yon_char_replace(name_temp,"\18","\\\\");
            if (name_temp!=parsed[0]) free(name_temp);
            if (parsed){
                int enabled = !strcmp(parsed[5],"enabled");
                int loaded = !strcmp(parsed[1],"loaded");
                int active = !strcmp(parsed[2],"active");
                enum YON_UNIT_TYPE type = yon_get_unit_type(parsed[0]);
                gtk_list_store_append(widgets->SystemList,&iter);
                gtk_list_store_set(widgets->SystemList,&iter,3,enabled,4,active,5,parsed[0],6,parsed[4],7,type,8,active,9,loaded,11,_(parsed[3]),13,parsed[3],-1);
            }

        } break;
    case 1:{
        GtkTreeModel *model;
        GtkTreeIter iter;
        gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->UserUnitsTree)),&model,&iter);
        char *target;
        gtk_tree_model_get(model,&iter,5,&target,-1);
        int size;
        config_str new_info = yon_config_load(load_user_service_single(target),&size);
        int parsed_size;
        config_str parsed = yon_char_parse(new_info[0],&parsed_size,";");
            char *name_temp = yon_char_replace(parsed[0],"\\","\18");
            if (name_temp!=parsed[0]) free(parsed[0]);
            parsed[0]=yon_char_replace(name_temp,"\18","\\\\");
            if (name_temp!=parsed[0]) free(name_temp);
            if (parsed){
                int enabled = !strcmp(parsed[5],"enabled");
                int loaded = !strcmp(parsed[1],"loaded");
                int active = !strcmp(parsed[2],"active");
                enum YON_UNIT_TYPE type = yon_get_unit_type(parsed[0]);
                gtk_list_store_append(widgets->SystemList,&iter);
                gtk_list_store_set(widgets->SystemList,&iter,3,enabled,4,active,5,parsed[0],6,parsed[4],7,type,8,active,9,loaded,11,_(parsed[3]),13,parsed[3],-1);
            }
        } break;
    default:
        break;
    }
}

void* yon_interface_update(main_window *widgets){
    if (widgets){
        g_idle_add((GSourceFunc)yon_interface_list_models_disconnect,widgets);
        int system_size;
        config_str system_services = yon_config_load(load_services_command,&system_size);
        int user_size;
        config_str user_services = yon_config_load(load_user_units_command,&user_size);
        int config_size;
        config_str config_files = yon_config_load(get_config_files_command,&config_size);
        int timers_size;
        config_str timers = yon_config_load(get_timers_command,&timers_size);
        struct json_object *jsobject = json_tokener_parse(timers[0]);
        for (int i=0; i<system_size;i++){
            system_services[i] = yon_char_replace(system_services[i],"\\x2d","");
            GtkTreeIter iter;
            if (system_services[i][strlen(system_services[i])-1]=='\n') system_services[i][strlen(system_services[i])-1] = '\0';
            int size;
            config_str parsed = yon_char_parse(system_services[i],&size,";");
            char *name_temp = yon_char_replace(parsed[0],"\\","\18");
            if (name_temp!=parsed[0]) free(parsed[0]);
            parsed[0]=yon_char_replace(name_temp,"\18","\\\\");
            if (name_temp!=parsed[0]) free(name_temp);
            if (parsed){
                int names_size;
                config_str names_parsed = yon_char_parse(parsed[0],&names_size," ");
                for (int j=0;j<names_size;j++){
                    int found=0;
                    for_iter(widgets->SystemList,&iter){
                        char *target;
                        gtk_tree_model_get(GTK_TREE_MODEL(widgets->SystemList),&iter,5,&target,-1);
                        if (!strcmp(target,names_parsed[j])){
                            found = 1;
                            break;
                        }
                    }
                    if (!found) {
                        int enabled = !strcmp(parsed[5],"enabled");
                        int loaded = !strcmp(parsed[1],"loaded");
                        int active = !strcmp(parsed[2],"active");
                        enum YON_UNIT_TYPE type = yon_get_unit_type(names_parsed[j]);
                        gtk_list_store_append(widgets->SystemList,&iter);
                        gtk_list_store_set(widgets->SystemList,&iter,3,enabled,4,active,5,names_parsed[j],6,parsed[4],7,type,8,active,9,loaded,11,_(parsed[3]),13,parsed[3],14,parsed[1],15,parsed[2],16,parsed[8],-1);
                    }
                }
                yon_char_parsed_free(names_parsed,names_size);
            }

        }
        yon_char_parsed_free(system_services,system_size);
        for (int i=0; i<user_size;i++){
            GtkTreeIter iter;
            if (user_services[i][strlen(user_services[i])-1]=='\n') user_services[i][strlen(user_services[i])-1] = '\0';
            int size;
            config_str parsed = yon_char_parse(user_services[i],&size,";");
            if (parsed){
                int names_size;
                config_str names_parsed = yon_char_parse(parsed[0],&names_size," ");
                for (int j=0;j<names_size;j++){
                    int found=0;
                    for_iter(widgets->UserList,&iter){
                        char *target;
                        gtk_tree_model_get(GTK_TREE_MODEL(widgets->UserList),&iter,5,&target,-1);
                        if (!strcmp(target,names_parsed[j])){
                            found = 1;
                            break;
                        }
                    }
                    if (!found) {
                        int enabled = !strcmp(parsed[5],"enabled");
                        int loaded = !strcmp(parsed[1],"loaded");
                        int active = !strcmp(parsed[2],"active");
                        enum YON_UNIT_TYPE type = yon_get_unit_type(names_parsed[j]);
                        gtk_list_store_append(widgets->UserList,&iter);
                        gtk_list_store_set(widgets->UserList,&iter,3,enabled,4,active,5,names_parsed[j],6,parsed[4],7,type,8,active,9,loaded,11,_(parsed[3]),13,parsed[3],14,parsed[1],15,parsed[2],16,parsed[8],-1);
                    }
                }
                yon_char_parsed_free(names_parsed,names_size);
            }

        }
        yon_char_parsed_free(user_services,user_size);
        int descr_size;
        config_str config_descr = yon_resource_open_file(systemd_config_path,&descr_size);
        for (int i=0; i<config_size;i++){
            int size;
            if (config_files[i][strlen(config_files[i])-1]=='\n') config_files[i][strlen(config_files[i])-1] = '\0';
            config_str parsed = yon_char_parse(config_files[i],&size,";");
            if (parsed&&size>2){
                char *description = "";
                {
                    for (int k=0;k<descr_size;k++){
                        int parsed_size;
                        config_str parsed_descr = yon_char_parse(config_descr[k],&parsed_size,";");
                        if (parsed_size){
                            for (int j=1;j<parsed_size;j++){
                                GRegex *regex = g_regex_new(parsed_descr[0],0,0,NULL);
                                
                                GMatchInfo *match = NULL;
                                g_regex_match(regex,parsed[2],0,&match);
                                g_regex_unref(regex);
                                if (g_match_info_matches(match)){
                                    yon_char_remove_last_symbol(parsed_descr[1],'\n');
                                    description = yon_char_new(parsed_descr[1]);
                                    break;
                                }
                                g_match_info_unref(match);
                            }
                            yon_char_parsed_free(parsed_descr,parsed_size);
                        }
                    }
                }
                struct system_config_data *data = malloc(sizeof(struct system_config_data));
                {
                    data->widgets=widgets;
                    data->Name=yon_char_new(parsed[2]);
                    data->Descr=yon_char_new(parsed[1]);
                    data->Date = _(description);
                }
                g_idle_add((GSourceFunc)yon_system_config_set,data);
            }
        }
        g_idle_add((GSourceFunc)yon_sessions_update,widgets);
        yon_char_parsed_free(config_files,config_size);
        
        for (size_t i=0;i<json_object_array_length(jsobject);i++){
            struct json_object *item_obj = json_object_array_get_idx(jsobject, i);
            const char *unit="",*next="",*left="",*last="",*passed="",*activates="";
            // Получение значений по ключам
            struct json_object *unit_obj;
            if (json_object_object_get_ex(item_obj, "unit", &unit_obj)) {
                unit = json_object_get_string(unit_obj);
            }

            struct json_object *next_obj;
            if (json_object_object_get_ex(item_obj, "next", &next_obj)) {
                next = json_object_get_string(next_obj);
            }

            struct json_object *left_obj;
            if (json_object_object_get_ex(item_obj, "left", &left_obj)) {
                left = json_object_get_string(left_obj);
            }

            struct json_object *last_obj;
            if (json_object_object_get_ex(item_obj, "last", &last_obj)) {
                last = json_object_get_string(last_obj);
            }

            struct json_object *passed_obj;
            if (json_object_object_get_ex(item_obj, "passed", &passed_obj)) {
                passed = json_object_get_string(passed_obj);
            }

            struct json_object *activates_obj;
            if (json_object_object_get_ex(item_obj, "activates", &activates_obj)) {
                activates = json_object_get_string(activates_obj);
            }
                GDateTime *datetime=NULL;
                if (!yon_char_is_empty(next)&&atol(next)!=0){
                    datetime = g_date_time_new_from_unix_local(atol(next)/1000000);
                    next = g_date_time_format(datetime,"%Y.%m.%d %H:%M:%S");
                    g_date_time_unref(datetime);
                } else {
                    next="";
                }
                if (!yon_char_is_empty(left)&&atol(left)!=0){
                datetime = g_date_time_new_from_unix_local(atol(left)/1000000);
                GDateTime *now = g_date_time_new_now_local();
                left = g_date_time_format(datetime,"%Y.%m.%d %H:%M:%S");
                gint64 left_microseconds = 0;
                left_microseconds = g_date_time_difference(datetime,now);
                left_microseconds/=1000000;
                long days = (long)((left_microseconds/60)/60)/24;
                long hours = (long)(left_microseconds/60)/60%60;
                long minutes = (long)left_microseconds/60%60;
                long seconds = (long)left_microseconds%60;
                g_date_time_unref(datetime);
                left = yon_char_unite(days?yon_char_from_long(days):"",days?" ":"",days?DAYS_LABEL:"",days?" ":"",hours?yon_char_from_long(hours):"",hours?" ":"",hours?HOURS_LABEL:"",hours?" ":"",minutes?yon_char_from_long(minutes):"",minutes?" ":"",minutes?MINUTES_LABEL:"",minutes?" ":"",seconds?yon_char_from_long(seconds):"",seconds?" ":"",seconds?SECONDS_LABEL:"",NULL);
                } else {
                    left="";
                }
                if (!yon_char_is_empty(last)&&atol(last)!=0){
                    datetime = g_date_time_new_from_unix_local(atol(last)/1000000);
                    last = g_date_time_format(datetime,"%Y.%m.%d %H:%M:%S");
                    g_date_time_unref(datetime);
                } else {
                    last="";
                }
                if (!yon_char_is_empty(passed)&&atol(passed)!=0){
                    datetime = g_date_time_new_from_unix_local(atol(passed)/1000000);
                    passed = g_date_time_format(datetime,"%Y.%m.%d %H:%M:%S");
                    g_date_time_unref(datetime);
                } else {
                    passed="";
                }
                struct system_timers_data *data = malloc(sizeof(struct system_timers_data));
                {
                    data->widgets=widgets;
                    data->unit=unit;
                    data->next=next;
                    data->left=left;
                    data->last=last;
                    data->passed=passed;
                    data->activates=activates;
                }
                g_idle_add((GSourceFunc)yon_timers_set,data);
        }
    }
        
        g_idle_add((GSourceFunc)yon_interface_update_finish,widgets);
        g_idle_add((GSourceFunc)yon_interface_list_models_connect,widgets);
        return NULL;
}

void on_interface_update(GtkWidget *, main_window *widgets){
    if (!main_config.update_thread_active){
        gtk_tree_selection_unselect_all(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->SystemUnitsTree)));
        gtk_tree_selection_unselect_all(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->UserUnitsTree)));
        yon_ubl_status_box_render(LIST_LOAD_LABEL,BACKGROUND_IMAGE_INFO_TYPE);
        main_config.update_thread_active=1;
        g_thread_new("update",(GThreadFunc)yon_interface_update,widgets);
    }
}

void on_column_resize(GtkTreeViewColumn *,GParamSpec *,main_window *widgets){
    GList *list = gtk_tree_view_get_columns(GTK_TREE_VIEW(widgets->SystemUnitsTree));
    int width_configuration = gtk_tree_view_column_get_width(g_list_nth_data(list,0))+gtk_tree_view_column_get_width(g_list_nth_data(list,1))+gtk_tree_view_column_get_width(g_list_nth_data(list,2));
    int width_system = gtk_tree_view_column_get_width(g_list_nth_data(list,3))+gtk_tree_view_column_get_width(g_list_nth_data(list,4))+gtk_tree_view_column_get_width(g_list_nth_data(list,5));
    g_list_free(list);
    gtk_tree_view_column_set_fixed_width(gtk_tree_view_get_column(GTK_TREE_VIEW(widgets->SystemUpperTree),0),width_configuration);
    gtk_tree_view_column_set_fixed_width(gtk_tree_view_get_column(GTK_TREE_VIEW(widgets->SystemUpperTree),1),width_system);

    list = gtk_tree_view_get_columns(GTK_TREE_VIEW(widgets->UserUnitsTree));
    width_configuration = gtk_tree_view_column_get_width(g_list_nth_data(list,0))+gtk_tree_view_column_get_width(g_list_nth_data(list,1))+gtk_tree_view_column_get_width(g_list_nth_data(list,2));
    width_system = gtk_tree_view_column_get_width(g_list_nth_data(list,3))+gtk_tree_view_column_get_width(g_list_nth_data(list,4))+gtk_tree_view_column_get_width(g_list_nth_data(list,5));
    g_list_free(list);
    gtk_tree_view_column_set_fixed_width(gtk_tree_view_get_column(GTK_TREE_VIEW(widgets->UsersUpperTree),0),width_configuration);
    gtk_tree_view_column_set_fixed_width(gtk_tree_view_get_column(GTK_TREE_VIEW(widgets->UsersUpperTree),1),width_system);
}

/**config_init() 
 * [EN] 
 *  
 * [RU] 
 * Функция инициализации всех параметров конфигурации 
*/ 
void config_init(){ 
    main_config.always_open_documentation=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.load_mode=YON_CONFIG_LOCAL;
    main_config.update_thread_active=0;
    main_config.launch_arguments=NULL;
    main_config.launch_size=0;
}

void on_tree_selection_changed(GtkWidget *, main_window *widgets){
    GtkTreeModel *model;
    GtkWidget *Tree;
    GtkTreeIter iter;
    int page = gtk_notebook_get_current_page(GTK_NOTEBOOK(widgets->MainNotebook));
    if (page==0){
        model = GTK_TREE_MODEL(widgets->SystemList);
        Tree = widgets->SystemUnitsTree;
        if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(Tree)),&model,&iter)){
            char *name, *descr;
            gtk_tree_model_get(model,&iter,5,&name,6,&descr,-1);
            gtk_label_set_text(GTK_LABEL(widgets->SystemServiceLabel),name);
            gtk_label_set_text(GTK_LABEL(widgets->SystemDescriptionLabel),descr);
            gtk_widget_set_sensitive(widgets->SystemStatusButton,1);
            gtk_widget_set_sensitive(widgets->SystemInfoButton,1);
            if (getuid()==0){
            gtk_widget_set_sensitive(widgets->SystemEditButton,1);
            gtk_widget_set_sensitive(widgets->SystemLogButton,1);
            gtk_widget_set_sensitive(widgets->SystemUpdateServiceButton,1);

            }
        } else {
            gtk_label_set_text(GTK_LABEL(widgets->SystemServiceLabel),"");
            gtk_label_set_text(GTK_LABEL(widgets->SystemDescriptionLabel),"");
            gtk_widget_set_sensitive(widgets->SystemStatusButton,0);
            gtk_widget_set_sensitive(widgets->SystemInfoButton,0);
            if (getuid()==0){
            gtk_widget_set_sensitive(widgets->SystemEditButton,0);
            gtk_widget_set_sensitive(widgets->SystemLogButton,0);
            gtk_widget_set_sensitive(widgets->SystemUpdateServiceButton,0);
            }
        }
    } else if (page==1){
        model = GTK_TREE_MODEL(widgets->UserList);
        Tree = widgets->UserUnitsTree;
        if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(Tree)),&model,&iter)){
            char *name, *descr;
            gtk_tree_model_get(model,&iter,5,&name,6,&descr,-1);
            gtk_label_set_text(GTK_LABEL(widgets->UserServiceLabel),name);
            gtk_label_set_text(GTK_LABEL(widgets->UserDescriptionLabel),descr);
            gtk_widget_set_sensitive(widgets->UserStatusButton,1);
            gtk_widget_set_sensitive(widgets->UserInfoButton,1);
            if (getuid()==0){
            gtk_widget_set_sensitive(widgets->UserEditButton,1);
            gtk_widget_set_sensitive(widgets->UserLogButton,1);
            gtk_widget_set_sensitive(widgets->UserUpdateServiceButton,1);
            }
        } else {
            gtk_label_set_text(GTK_LABEL(widgets->UserServiceLabel),"");
            gtk_label_set_text(GTK_LABEL(widgets->UserDescriptionLabel),"");
            gtk_widget_set_sensitive(widgets->UserStatusButton,0);
            gtk_widget_set_sensitive(widgets->UserInfoButton,0);
            if (getuid()==0){
            gtk_widget_set_sensitive(widgets->UserEditButton,0);
            gtk_widget_set_sensitive(widgets->UserLogButton,0);
            gtk_widget_set_sensitive(widgets->UserUpdateServiceButton,0);
                
            }
        }

    }
    if (getuid()==0){
    }
}

gboolean on_tooltip_show(GtkWidget*, gint x, gint y, gboolean, GtkTooltip* tooltip, main_window *widgets) {
    gtk_tooltip_set_custom(tooltip,widgets->TooltipBox);
    GtkWidget *tree = NULL;
    GtkTreeModel *model = NULL;
    if (gtk_notebook_get_current_page(GTK_NOTEBOOK(widgets->MainNotebook)) == 0) {
        tree = widgets->SystemUnitsTree;
        model = gtk_tree_view_get_model(GTK_TREE_VIEW(widgets->SystemUnitsTree));
    } else {
        tree = widgets->UserUnitsTree;
        model = gtk_tree_view_get_model(GTK_TREE_VIEW(widgets->UserUnitsTree));
    }

    gint tree_x, tree_y;
    gtk_tree_view_convert_widget_to_bin_window_coords(GTK_TREE_VIEW(tree), x, y, &tree_x, &tree_y);

    GtkTreePath *path;
    if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tree), tree_x, tree_y, &path, NULL, NULL, NULL)) {
        GtkTreeIter iter;
        if (gtk_tree_model_get_iter(model, &iter, path)) {
            gchar *name, *description, *state, *name_target, *load_status, *active_status,*unit_path,*activate_time,*deactivate_time;
            int size;
            gtk_tree_model_get(model, &iter, 5, &name, 6, &description, 13, &state, 14,&load_status,15,&active_status,16,&unit_path,17,&activate_time,18,&deactivate_time, -1);
            name_target = yon_char_new(name);
            if (name[0]=='-'){
                name_target = yon_char_append("-- ",name_target);
            }

                
                state[0]=g_ascii_toupper(state[0]);
                load_status[0]=g_ascii_toupper(load_status[0]);
                active_status[0]=g_ascii_toupper(active_status[0]);
                gtk_label_set_text(GTK_LABEL(widgets->UnitLabel), unit_path);
                gtk_label_set_markup(GTK_LABEL(widgets->NameLabel), yon_char_unite("<b>",name,"</b>",NULL));
                gtk_label_set_text(GTK_LABEL(widgets->DescriptionLabel), description);
                gtk_label_set_text(GTK_LABEL(widgets->StatusQueryLabel), _(state));
                gtk_label_set_text(GTK_LABEL(widgets->AutostartLabel), _(load_status));
                gtk_label_set_text(GTK_LABEL(widgets->TooltipStatusLabel), _(active_status));
                

                free(name);
                free(description);
                free(state);


            if (yon_char_is_empty(activate_time)||yon_char_is_empty(deactivate_time)){
                config_str target = yon_config_load(yon_debug_output("%s\n",get_activate_deactivate_times(name_target)), &size);
                free(name_target);
                if (target){
                    free(yon_char_divide_search(target[0], "=", -1));
                    yon_char_remove_last_symbol(target[0], '\n');
                    free(yon_char_divide_search(target[1], "=", -1));
                    yon_char_remove_last_symbol(target[1], '\n');
                    free(yon_char_divide_search(target[2], "=", -1));
                    yon_char_remove_last_symbol(target[2], '\n');
                }
                if (target){
                    gchar *formatted_activa = g_strdup(NULL_LABEL);//!yon_char_is_empty(target[1])&&strcmp(target[1],"0")?target[1]:g_strdup(NULL_LABEL);
                    gchar *formatted_deactiva = g_strdup(NULL_LABEL);//!yon_char_is_empty(target[2])&&strcmp(target[2],"0")?target[2]:g_strdup(NULL_LABEL);
                    if (!yon_char_is_empty(target[1])&&strcmp(target[1],"0")){
                        int activated_size;
                        config_str activated_parsed = yon_char_parse(target[1],&activated_size," ");
                        int date_size;
                        config_str date_parsed = yon_char_parse(activated_parsed[1],&date_size,"-");
                        if (date_size>2){
                            char *temp = date_parsed[0];
                            date_parsed[0]=date_parsed[2];
                            date_parsed[2]=temp;
                            formatted_activa = yon_char_unite(date_parsed?yon_char_parsed_to_string(date_parsed,date_size,"."):""," ",activated_parsed[2],NULL);
                            if (date_size) yon_char_parsed_free(date_parsed,date_size);
                        }
                        if (activated_size) yon_char_parsed_free(activated_parsed,activated_size);
                    }
                    if (!yon_char_is_empty(target[2])&&strcmp(target[2],"0")){
                        int deactivated_size;
                        config_str deactivated_parsed = yon_char_parse(target[2],&deactivated_size," ");
                        int date_size;
                        config_str date_parsed = yon_char_parse(deactivated_parsed[1],&date_size,"-");
                        if (date_size>=2){
                            char *temp = date_parsed[0];
                            date_parsed[0]=date_parsed[2];
                            date_parsed[2]=temp;
                            formatted_deactiva = yon_char_unite(date_parsed?yon_char_parsed_to_string(date_parsed,date_size,"."):""," ",deactivated_parsed[2],NULL);
                            if (date_size) yon_char_parsed_free(date_parsed,date_size);
                        }
                        if (deactivated_size) yon_char_parsed_free(deactivated_parsed,deactivated_size);
                    }
                    GtkTreeIter itar;
                    yon_tree_model_sort_filter_get_model_iter(GTK_TREE_MODEL_SORT(model),&iter,&itar);
                    GtkTreeModel *filter_model = gtk_tree_model_sort_get_model(GTK_TREE_MODEL_SORT(model));
                    GtkTreeModel *list = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(filter_model));


                    gtk_list_store_set(GTK_LIST_STORE(list),&itar,17,formatted_activa,18,formatted_deactiva,-1);

                    activate_time = yon_char_new(formatted_activa);
                    deactivate_time = yon_char_new(formatted_deactiva);

                    g_free(formatted_activa);
                    g_free(formatted_deactiva);
                }
                    gtk_label_set_text(GTK_LABEL(widgets->ActivateLabel), activate_time);
                    gtk_label_set_text(GTK_LABEL(widgets->DeactivateLabel), deactivate_time);
            }
            gtk_tree_path_free(path);
            return TRUE;
        }
        gtk_tree_path_free(path);
    }
    return FALSE;
}


/**yon_main_window_complete(main_window *widgets) 
 * [EN] 
 *  
 * [RU] 
 * Функция настройки основного окна приложения. [widgets] - структура со стандартным интерфейсом. 
*/ 
void yon_main_window_complete(main_window *widgets){ 
    widgets = yon_remalloc(widgets,sizeof(main_window)); 
    GtkBuilder *builder = gtk_builder_new_from_resource(glade_path); 
    gtk_box_pack_start(GTK_BOX(widgets->InterfaceBox),yon_gtk_builder_get_widget(builder,"BoxMain"),1,1,0); 
    // Custom widgets configuration 
    {
	widgets->UserList=GTK_LIST_STORE(gtk_builder_get_object(builder,"UserList"));
	widgets->TimersList =GTK_LIST_STORE(gtk_builder_get_object(builder,"TimersList"));
	widgets->SessionsList=GTK_LIST_STORE(gtk_builder_get_object(builder,"SessionsList"));
	widgets->ConfigList=GTK_LIST_STORE(gtk_builder_get_object(builder,"ConfigList"));
	widgets->SystemList=GTK_LIST_STORE(gtk_builder_get_object(builder,"SystemList"));
	widgets->BoxMain=yon_gtk_builder_get_widget(builder,"BoxMain");
	widgets->SystemSearchEntry=yon_gtk_builder_get_widget(builder,"SystemSearchEntry");
	widgets->SystemUpperTree=yon_gtk_builder_get_widget(builder,"SystemUpperTree");
	widgets->SystemUnitsTree=yon_gtk_builder_get_widget(builder,"SystemUnitsTree");
	widgets->MainNotebook=yon_gtk_builder_get_widget(builder,"MainNotebook");

	widgets->SystemLoadingOverlay=yon_gtk_builder_get_widget(builder,"SystemLoadingOverlay");
	widgets->SystemLoadingSpinner=yon_gtk_builder_get_widget(builder,"SystemLoadingSpinner");
	widgets->UserLoadingOverlay=yon_gtk_builder_get_widget(builder,"UserLoadingOverlay");
	widgets->UserLoadingSpinner=yon_gtk_builder_get_widget(builder,"UserLoadingSpinner");
	widgets->ConfigLoadingOverlay=yon_gtk_builder_get_widget(builder,"ConfigLoadingOverlay");
	widgets->ConfigLoadingSpinner=yon_gtk_builder_get_widget(builder,"ConfigLoadingSpinner");
	widgets->SessionsLoadingOverlay=yon_gtk_builder_get_widget(builder,"SessionsLoadingOverlay");
	widgets->SessionsLoadingSpinner=yon_gtk_builder_get_widget(builder,"SessionsLoadingSpinner");
	widgets->TimersLoadingOverlay=yon_gtk_builder_get_widget(builder,"TimersLoadingOverlay");
	widgets->TimersLoadingSpinner=yon_gtk_builder_get_widget(builder,"TimersLoadingSpinner");

	widgets->TooltipBox=yon_gtk_builder_get_widget(builder,"TooltipBox");
	widgets->NameLabel=yon_gtk_builder_get_widget(builder,"NameLabel");
	widgets->DescriptionLabel=yon_gtk_builder_get_widget(builder,"DescriptionLabel");
	widgets->UnitLabel=yon_gtk_builder_get_widget(builder,"UnitLabel");
	widgets->StatusQueryLabel=yon_gtk_builder_get_widget(builder,"StatusQueryLabel");
	widgets->ActivateLabel=yon_gtk_builder_get_widget(builder,"ActivateLabel");
	widgets->DeactivateLabel=yon_gtk_builder_get_widget(builder,"DeactivateLabel");
	widgets->AutostartLabel=yon_gtk_builder_get_widget(builder,"AutostartLabel");
	widgets->TooltipStatusLabel=yon_gtk_builder_get_widget(builder,"StatusLabel");

	widgets->SystemServicesStatusMenuItem=yon_gtk_builder_get_widget(builder,"SystemServicesStatusMenuItem");
	widgets->InstalledUnitsStatusMenuItem=yon_gtk_builder_get_widget(builder,"InstalledUnitsStatusMenuItem");
	widgets->UnitsStatusListMenuItem=yon_gtk_builder_get_widget(builder,"UnitsStatusListMenuItem");
	widgets->SocketsStatusListMenuItem=yon_gtk_builder_get_widget(builder,"SocketsStatusListMenuItem");
	widgets->TimersStatusListMenuItem=yon_gtk_builder_get_widget(builder,"TimersStatusListMenuItem");

	widgets->UserServicesStatusMenuItem=yon_gtk_builder_get_widget(builder,"UserServicesStatusMenuItem");
	widgets->UserInstalledUnitsStatusMenuItem=yon_gtk_builder_get_widget(builder,"UserInstalledUnitsStatusMenuItem");
	widgets->UserUnitsStatusListMenuItem=yon_gtk_builder_get_widget(builder,"UserUnitsStatusListMenuItem");
	widgets->UserSocketsStatusListMenuItem=yon_gtk_builder_get_widget(builder,"UserSocketsStatusListMenuItem");
	widgets->UserTimersStatusListMenuItem=yon_gtk_builder_get_widget(builder,"UserTimersStatusListMenuItem");

	widgets->SystemSearchEntry=yon_gtk_builder_get_widget(builder,"SystemSearchEntry");
	widgets->SystemFiltersCombo=yon_gtk_builder_get_widget(builder,"SystemFiltersCombo");
	widgets->SystemInactiveShowCheck=yon_gtk_builder_get_widget(builder,"SystemInactiveShowCheck");
	widgets->SystemUnloadedShowCheck=yon_gtk_builder_get_widget(builder,"SystemUnloadedShowCheck");
	widgets->SystemUpperTree=yon_gtk_builder_get_widget(builder,"SystemUpperTree");
	widgets->SystemUnitsTree=yon_gtk_builder_get_widget(builder,"SystemUnitsTree");
	widgets->SystemPrevButton=yon_gtk_builder_get_widget(builder,"SystemPrevButton");
	widgets->SystemUpdateButton=yon_gtk_builder_get_widget(builder,"SystemUpdateButton");
	widgets->SystemServiceUpdateButton=yon_gtk_builder_get_widget(builder,"SystemServiceUpdateButton");
	widgets->SystemUpdateServiceButton=yon_gtk_builder_get_widget(builder,"SystemUpdateServiceButton");
	widgets->SystemInfoButton=yon_gtk_builder_get_widget(builder,"SystemInfoButton");
	widgets->SystemLogButton=yon_gtk_builder_get_widget(builder,"SystemLogButton");
	widgets->SystemEditButton=yon_gtk_builder_get_widget(builder,"SystemEditButton");
	widgets->SystemPropertiesButton=yon_gtk_builder_get_widget(builder,"SystemPropertiesButton");
    widgets->SystemFilter = GTK_TREE_MODEL_FILTER(gtk_builder_get_object(builder,"SystemFilter"));
    widgets->SystemSort = GTK_TREE_MODEL_SORT(gtk_builder_get_object(builder,"SystemSort"));
    widgets->UserFilter = GTK_TREE_MODEL_FILTER(gtk_builder_get_object(builder,"UserFilter"));
    widgets->UserSort = GTK_TREE_MODEL_SORT(gtk_builder_get_object(builder,"UserSort"));
	widgets->SystemStatusButton=yon_gtk_builder_get_widget(builder,"SystemStatusButton");
    widgets->ConfigAutostartCell = GTK_CELL_RENDERER(gtk_builder_get_object(builder,"ConfigAutostartCell"));
    widgets->ConfigAutostopCell = GTK_CELL_RENDERER(gtk_builder_get_object(builder,"ConfigAutostopCell"));
    widgets->ConfigBlockCell = GTK_CELL_RENDERER(gtk_builder_get_object(builder,"ConfigBlockCell"));
    widgets->SystemAutostartCell = GTK_CELL_RENDERER(gtk_builder_get_object(builder,"SystemAutostartCell"));
    widgets->SystemLaunchedCell = GTK_CELL_RENDERER(gtk_builder_get_object(builder,"SystemLaunchedCell"));

    widgets->UserConfigAutostartCell = GTK_CELL_RENDERER(gtk_builder_get_object(builder,"UserConfigAutostartCell"));
    widgets->UserConfigAutostopCell = GTK_CELL_RENDERER(gtk_builder_get_object(builder,"UserConfigAutostopCell"));
    widgets->UserConfigBlockCell = GTK_CELL_RENDERER(gtk_builder_get_object(builder,"UserConfigBlockCell"));
    widgets->UserSystemAutostartCell = GTK_CELL_RENDERER(gtk_builder_get_object(builder,"UserSystemAutostartCell"));
    widgets->UserSystemLaunchedCell = GTK_CELL_RENDERER(gtk_builder_get_object(builder,"UserSystemLaunchedCell"));
    widgets->SystemMenu = yon_rmb_menu_setup(widgets->SystemUnitsTree,NULL,NULL,
        RESTART_LABEL,update_icon_path,G_CALLBACK(on_system_restart_clicked),widgets,
        RELAUNCH_SYSTEMCTL_LABEL,relaunch_icon_path,G_CALLBACK(yon_system_systemd_restart),widgets,
        STATUS_LABEL,status_icon_path,on_system_info_clicked,widgets,
        SHOW_LOG_LABEL,log_icon_path,on_system_log_clicked,widgets,
        SHOW_SOURCE_LABEL,source_icon_path,on_system_edit_clicked,widgets,
        PROPERTIES_LABEL,properties_icon_path,on_system_status_clicked,widgets,
    NULL);

	widgets->UserSearchEntry=yon_gtk_builder_get_widget(builder,"UserSearchEntry");
	widgets->UserFiltersCombo=yon_gtk_builder_get_widget(builder,"UserFiltersCombo");
	widgets->UserInactiveShowCheck=yon_gtk_builder_get_widget(builder,"UserInactiveShowCheck");
	widgets->UserUnloadedShowCheck=yon_gtk_builder_get_widget(builder,"UserUnloadedShowCheck");
	widgets->UsersUpperTree=yon_gtk_builder_get_widget(builder,"UsersUpperTree");
	widgets->UserUnitsTree=yon_gtk_builder_get_widget(builder,"UserUnitsTree");
	widgets->UserPrevButton=yon_gtk_builder_get_widget(builder,"UserPrevButton");
	widgets->UserUpdateButton=yon_gtk_builder_get_widget(builder,"UserUpdateButton");
	widgets->UserServiceUpdateButton=yon_gtk_builder_get_widget(builder,"UserServiceUpdateButton");
	widgets->UserUpdateServiceButton=yon_gtk_builder_get_widget(builder,"UserUpdateServiceButton");
	widgets->UserInfoButton=yon_gtk_builder_get_widget(builder,"UserInfoButton");
	widgets->UserLogButton=yon_gtk_builder_get_widget(builder,"UserLogButton");
	widgets->UserEditButton=yon_gtk_builder_get_widget(builder,"UserEditButton");
	widgets->UserStatusButton=yon_gtk_builder_get_widget(builder,"UserStatusButton");
	widgets->UserServiceLabel=yon_gtk_builder_get_widget(builder,"UserServiceLabel");
	widgets->UserDescriptionLabel=yon_gtk_builder_get_widget(builder,"UserDescriptionLabel");
    widgets->UserMenu = yon_rmb_menu_setup(widgets->UserUnitsTree,NULL,NULL,
        RESTART_LABEL,update_icon_path,G_CALLBACK(on_system_restart_clicked),widgets,
        RELAUNCH_SYSTEMCTL_LABEL,relaunch_icon_path,G_CALLBACK(yon_system_systemd_restart),widgets,
        STATUS_LABEL,status_icon_path,on_user_info_clicked,widgets,
        SHOW_LOG_LABEL,log_icon_path,on_user_log_clicked,widgets,
        SHOW_SOURCE_LABEL,source_icon_path,on_user_edit_clicked,widgets,
        PROPERTIES_LABEL,properties_icon_path,on_user_status_clicked,widgets,
    NULL);

	widgets->ConfigUpdateButton=yon_gtk_builder_get_widget(builder,"ConfigUpdateButton");
	widgets->ConfigEditButton=yon_gtk_builder_get_widget(builder,"ConfigEditButton");
	widgets->ConfigMainTree=yon_gtk_builder_get_widget(builder,"ConfigMainTree");

	widgets->SessionRestartButton=yon_gtk_builder_get_widget(builder,"SessionRestartButton");
	widgets->SessionMainTree=yon_gtk_builder_get_widget(builder,"SessionMainTree");
	widgets->SessionSwitchButton=yon_gtk_builder_get_widget(builder,"SessionSwitchButton");
	widgets->SessionStartButton=yon_gtk_builder_get_widget(builder,"SessionStartButton");
	widgets->SessionStopButton=yon_gtk_builder_get_widget(builder,"SessionStopButton");
	widgets->SessionBlockButton=yon_gtk_builder_get_widget(builder,"SessionBlockButton");
    widgets->SessionMenu = yon_rmb_menu_setup(widgets->SessionMainTree,NULL,NULL,
        UPDATE_LABEL,update_icon_path,G_CALLBACK(on_interface_update),widgets,
        ACTIVATE_SESSION_LABEL,switch_icon_path,G_CALLBACK(on_session_activate),widgets,
        BLOCK_SESSION_LABEL,block_icon_path,G_CALLBACK(on_session_block),widgets,
        UNLOCK_SESSION_LABEL,unlock_icon_path,G_CALLBACK(on_session_unlock),widgets,
        END_SESSION_LABEL,end_icon_path,G_CALLBACK(on_session_end),widgets,
    NULL);
    gtk_style_context_add_class(gtk_widget_get_style_context(((GtkWidget*)widgets->SessionMenu->buttons->first->data)),"separatorBottom");
    {
        GList *list = gtk_container_get_children(GTK_CONTAINER(widgets->SystemMenu->menu));
        gtk_style_context_add_class(gtk_widget_get_style_context(g_list_nth_data(list,1)),"separatorTop");
        gtk_style_context_add_class(gtk_widget_get_style_context(g_list_nth_data(list,1)),"separatorBottom");
        g_list_free(list);
    }
    {
        GList *list = gtk_container_get_children(GTK_CONTAINER(widgets->UserMenu->menu));
        gtk_style_context_add_class(gtk_widget_get_style_context(g_list_nth_data(list,1)),"separatorTop");
        gtk_style_context_add_class(gtk_widget_get_style_context(g_list_nth_data(list,1)),"separatorBottom");
        g_list_free(list);
    }
    widgets->SystemServiceLabel=yon_gtk_builder_get_widget(builder,"SystemServiceLabel");
	widgets->SystemDescriptionLabel=yon_gtk_builder_get_widget(builder,"SystemDescriptionLabel");
    }
	widgets->TimersMainTree=yon_gtk_builder_get_widget(builder,"TimersMainTree");
	widgets->TimersUpdateButton=yon_gtk_builder_get_widget(builder,"TimersUpdateButton");
    // yon_gtk_tree_view_minimal_fixed_size_set_full(GTK_TREE_VIEW(widgets->SystemUnitsTree));

    g_signal_connect(G_OBJECT(widgets->UserUnitsTree),"query-tooltip",G_CALLBACK(on_tooltip_show),widgets);
    g_signal_connect(G_OBJECT(widgets->SystemUnitsTree),"query-tooltip",G_CALLBACK(on_tooltip_show),widgets);

    g_signal_connect(G_OBJECT(widgets->SystemPrevButton),"clicked",G_CALLBACK(on_system_update_hz_clicked),widgets);
    g_signal_connect(G_OBJECT(widgets->SystemUpdateButton),"clicked",G_CALLBACK(on_interface_update),widgets);
    g_signal_connect(G_OBJECT(widgets->SystemServiceUpdateButton),"clicked",G_CALLBACK(on_system_update_clicked),widgets);
    g_signal_connect(G_OBJECT(widgets->SystemUpdateServiceButton),"clicked",G_CALLBACK(on_system_restart_clicked),widgets);
    g_signal_connect(G_OBJECT(widgets->SystemInfoButton),"clicked",G_CALLBACK(on_system_info_clicked),widgets);
    g_signal_connect(G_OBJECT(widgets->SystemLogButton),"clicked",G_CALLBACK(on_system_log_clicked),widgets);
    g_signal_connect(G_OBJECT(widgets->SystemEditButton),"clicked",G_CALLBACK(on_system_edit_clicked),widgets);
    g_signal_connect(G_OBJECT(widgets->SystemStatusButton),"clicked",G_CALLBACK(on_system_status_clicked),widgets);
    g_signal_connect(G_OBJECT(widgets->SystemFiltersCombo),"changed",G_CALLBACK(on_filter_changed),widgets);
    g_signal_connect(G_OBJECT(widgets->SystemSearchEntry),"changed",G_CALLBACK(on_filter_changed),widgets);
    g_signal_connect(G_OBJECT(widgets->SystemInactiveShowCheck),"toggled",G_CALLBACK(on_filter_changed),widgets);
    g_signal_connect(G_OBJECT(widgets->SystemUnloadedShowCheck),"toggled",G_CALLBACK(on_filter_changed),widgets);

    g_signal_connect(G_OBJECT(widgets->UserPrevButton),"clicked",G_CALLBACK(on_user_update_hz_clicked),widgets);
    g_signal_connect(G_OBJECT(widgets->UserUpdateButton),"clicked",G_CALLBACK(on_interface_update),widgets);
    g_signal_connect(G_OBJECT(widgets->UserServiceUpdateButton),"clicked",G_CALLBACK(on_user_update_clicked),widgets);
    g_signal_connect(G_OBJECT(widgets->UserUpdateServiceButton),"clicked",G_CALLBACK(on_system_restart_clicked),widgets);
    g_signal_connect(G_OBJECT(widgets->UserInfoButton),"clicked",G_CALLBACK(on_user_info_clicked),widgets);
    g_signal_connect(G_OBJECT(widgets->UserLogButton),"clicked",G_CALLBACK(on_user_log_clicked),widgets);
    g_signal_connect(G_OBJECT(widgets->UserEditButton),"clicked",G_CALLBACK(on_user_edit_clicked),widgets);
    g_signal_connect(G_OBJECT(widgets->UserStatusButton),"clicked",G_CALLBACK(on_user_status_clicked),widgets);
    g_signal_connect(G_OBJECT(widgets->UserFiltersCombo),"changed",G_CALLBACK(on_filter_changed),widgets);
    g_signal_connect(G_OBJECT(widgets->UserSearchEntry),"changed",G_CALLBACK(on_filter_changed),widgets);
    g_signal_connect(G_OBJECT(widgets->UserInactiveShowCheck),"toggled",G_CALLBACK(on_filter_changed),widgets);
    g_signal_connect(G_OBJECT(widgets->UserUnloadedShowCheck),"toggled",G_CALLBACK(on_filter_changed),widgets);

    g_signal_connect(G_OBJECT(widgets->ConfigEditButton),"clicked",G_CALLBACK(on_config_edit_clicked),widgets);
    g_signal_connect(G_OBJECT(widgets->ConfigUpdateButton),"clicked",G_CALLBACK(on_interface_update),widgets);

    g_signal_connect(G_OBJECT(widgets->SessionRestartButton),"clicked",G_CALLBACK(on_interface_update),widgets);
    g_signal_connect(G_OBJECT(widgets->SessionSwitchButton),"clicked",G_CALLBACK(on_session_activate),widgets);
    g_signal_connect(G_OBJECT(widgets->SessionStartButton),"clicked",G_CALLBACK(on_session_unlock),widgets);
    g_signal_connect(G_OBJECT(widgets->SessionStopButton),"clicked",G_CALLBACK(on_session_end),widgets);
    g_signal_connect(G_OBJECT(widgets->SessionBlockButton),"clicked",G_CALLBACK(on_session_block),widgets);
    g_signal_connect(G_OBJECT(widgets->SessionMainTree),"cursor-changed",G_CALLBACK(on_sessions_selection_changed),widgets);
    g_signal_connect(G_OBJECT(widgets->ConfigMainTree),"cursor-changed",G_CALLBACK(on_configs_selection_changed),widgets);

    g_signal_connect(G_OBJECT(widgets->SystemServicesStatusMenuItem),"activate",G_CALLBACK(on_system_services_status),widgets);
    g_signal_connect(G_OBJECT(widgets->InstalledUnitsStatusMenuItem),"activate",G_CALLBACK(on_units_status),widgets);
    g_signal_connect(G_OBJECT(widgets->UnitsStatusListMenuItem),"activate",G_CALLBACK(on_units_list_status),widgets);
    g_signal_connect(G_OBJECT(widgets->SocketsStatusListMenuItem),"activate",G_CALLBACK(on_sockets_list_status),widgets);
    g_signal_connect(G_OBJECT(widgets->TimersStatusListMenuItem),"activate",G_CALLBACK(on_timers_list_status),widgets);

    g_signal_connect(G_OBJECT(widgets->UserServicesStatusMenuItem),"activate",G_CALLBACK(on_user_services_status),widgets);
    g_signal_connect(G_OBJECT(widgets->UserInstalledUnitsStatusMenuItem),"activate",G_CALLBACK(on_units_status),widgets);
    g_signal_connect(G_OBJECT(widgets->UserUnitsStatusListMenuItem),"activate",G_CALLBACK(on_units_list_status),widgets);
    g_signal_connect(G_OBJECT(widgets->UserSocketsStatusListMenuItem),"activate",G_CALLBACK(on_sockets_list_status),widgets);
    g_signal_connect(G_OBJECT(widgets->UserTimersStatusListMenuItem),"activate",G_CALLBACK(on_timers_list_status),widgets);

    g_signal_connect(G_OBJECT(widgets->ConfigAutostartCell),"toggled",G_CALLBACK(on_config_autostart_clicked),widgets);
    g_signal_connect(G_OBJECT(widgets->ConfigAutostopCell),"toggled",G_CALLBACK(on_config_autostop_clicked),widgets);
    g_signal_connect(G_OBJECT(widgets->ConfigBlockCell),"toggled",G_CALLBACK(on_config_block_clicked),widgets);

    g_signal_connect(G_OBJECT(widgets->UserConfigAutostartCell),"toggled",G_CALLBACK(on_config_autostart_clicked),widgets);
    g_signal_connect(G_OBJECT(widgets->UserConfigAutostopCell),"toggled",G_CALLBACK(on_config_autostop_clicked),widgets);
    g_signal_connect(G_OBJECT(widgets->UserConfigBlockCell),"toggled",G_CALLBACK(on_config_block_clicked),widgets);

    g_signal_connect(G_OBJECT(widgets->TimersUpdateButton),"clicked",G_CALLBACK(on_interface_update),widgets);
    
    g_signal_connect(G_OBJECT(gtk_tree_view_get_column(GTK_TREE_VIEW(widgets->SystemUpperTree),2)),"clicked",G_CALLBACK(on_sort_activate),widgets);
    g_signal_connect(G_OBJECT(gtk_tree_view_get_column(GTK_TREE_VIEW(widgets->UsersUpperTree),2)),"clicked",G_CALLBACK(on_sort_activate),widgets);

    if (getuid()==0){
        gtk_widget_set_sensitive(widgets->UserServiceUpdateButton,0);
        gtk_widget_set_sensitive(widgets->UserPrevButton,0);
        g_signal_connect(G_OBJECT(widgets->SystemAutostartCell),"toggled",G_CALLBACK(on_system_autostart_clicked),widgets);
        g_signal_connect(G_OBJECT(widgets->SystemLaunchedCell),"toggled",G_CALLBACK(on_system_launch_clicked),widgets);

        g_signal_connect(G_OBJECT(widgets->UserSystemAutostartCell),"toggled",G_CALLBACK(on_system_autostart_clicked),widgets);
        g_signal_connect(G_OBJECT(widgets->UserSystemLaunchedCell),"toggled",G_CALLBACK(on_system_launch_clicked),widgets);
    } else {
        gtk_widget_set_sensitive(widgets->SystemUpdateButton,0);
        gtk_widget_set_sensitive(widgets->SystemPrevButton,0);
    }
    gtk_overlay_add_overlay(GTK_OVERLAY(widgets->SystemLoadingOverlay),widgets->SystemLoadingSpinner);
    gtk_overlay_add_overlay(GTK_OVERLAY(widgets->UserLoadingOverlay),widgets->UserLoadingSpinner);
    gtk_overlay_add_overlay(GTK_OVERLAY(widgets->ConfigLoadingOverlay),widgets->ConfigLoadingSpinner);
    gtk_overlay_add_overlay(GTK_OVERLAY(widgets->SessionsLoadingOverlay),widgets->SessionsLoadingSpinner);
    gtk_overlay_add_overlay(GTK_OVERLAY(widgets->TimersLoadingOverlay),widgets->TimersLoadingSpinner);
    yon_gtk_tree_view_minimal_fixed_size_set_full(GTK_TREE_VIEW(widgets->UserUnitsTree));
    yon_gtk_tree_view_minimal_fixed_size_set_full(GTK_TREE_VIEW(widgets->SystemUnitsTree));
    yon_gtk_tree_view_minimal_fixed_size_set_full(GTK_TREE_VIEW(widgets->ConfigMainTree));
    yon_gtk_tree_view_minimal_fixed_size_set_full(GTK_TREE_VIEW(widgets->SessionMainTree));
    yon_gtk_tree_view_minimal_fixed_size_set_full(GTK_TREE_VIEW(widgets->TimersMainTree));
    g_signal_connect(G_OBJECT(widgets->SystemInactiveShowCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),widgets->SystemUnloadedShowCheck);
    g_signal_connect(G_OBJECT(widgets->UserInactiveShowCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),widgets->UserUnloadedShowCheck);
    GList *list = gtk_tree_view_get_columns(GTK_TREE_VIEW(widgets->SystemUnitsTree));
    for (unsigned int i=5;i<g_list_length(list);i++){
    g_signal_connect_after(G_OBJECT(g_list_nth_data(list,i)),"notify::width",G_CALLBACK(on_column_resize),widgets);
        yon_window_config_add_listener(g_list_nth_data(list,i),yon_char_append("SystemUnitsColumn",yon_char_from_int(i)),"fixed-width",YON_TYPE_INT);
    }
    g_list_free(list);
    
    list = gtk_tree_view_get_columns(GTK_TREE_VIEW(widgets->UserUnitsTree));
    for (unsigned int i=5;i<g_list_length(list);i++){
    g_signal_connect_after(G_OBJECT(g_list_nth_data(list,i)),"notify::width",G_CALLBACK(on_column_resize),widgets);
        yon_window_config_add_listener(g_list_nth_data(list,i),yon_char_append("UserUnitsColumn",yon_char_from_int(i)),"fixed-width",YON_TYPE_INT);
    }
    g_list_free(list);
    
    list = gtk_tree_view_get_columns(GTK_TREE_VIEW(widgets->ConfigMainTree));
    for (unsigned int i=0;i<g_list_length(list);i++){
    g_signal_connect_after(G_OBJECT(g_list_nth_data(list,i)),"notify::width",G_CALLBACK(on_column_resize),widgets);
        yon_window_config_add_listener(g_list_nth_data(list,i),yon_char_append("ConfigUnitsColumn",yon_char_from_int(i)),"fixed-width",YON_TYPE_INT);
    }
    g_list_free(list);
    
    list = gtk_tree_view_get_columns(GTK_TREE_VIEW(widgets->SessionMainTree));
    for (unsigned int i=0;i<g_list_length(list);i++){
    g_signal_connect_after(G_OBJECT(g_list_nth_data(list,i)),"notify::width",G_CALLBACK(on_column_resize),widgets);
        yon_window_config_add_listener(g_list_nth_data(list,i),yon_char_append("SessionsUnitsColumn",yon_char_from_int(i)),"fixed-width",YON_TYPE_INT);
    }
    g_list_free(list);
    
    list = gtk_tree_view_get_columns(GTK_TREE_VIEW(widgets->TimersMainTree));
    for (unsigned int i=0;i<g_list_length(list);i++){
    g_signal_connect_after(G_OBJECT(g_list_nth_data(list,i)),"notify::width",G_CALLBACK(on_column_resize),widgets);
        yon_window_config_add_listener(g_list_nth_data(list,i),yon_char_append("TimersUnitsColumn",yon_char_from_int(i)),"fixed-width",YON_TYPE_INT);
    }
    g_list_free(list);
    on_column_resize(NULL,NULL,widgets);

    g_signal_connect(G_OBJECT(widgets->LoadLocalMenuItem),"activate",G_CALLBACK(on_config_local_load),widgets);
    g_signal_connect(G_OBJECT(widgets->LoadGlobalMenuItem),"activate",G_CALLBACK(on_config_global_load),widgets);
    g_signal_connect(G_OBJECT(widgets->LoadCustomMenuItem),"activate",G_CALLBACK(on_config_custom_load),widgets);

    g_signal_connect(G_OBJECT(widgets->SaveMenuItem),"activate",G_CALLBACK(on_config_global_local_save),NULL);
    g_signal_connect(G_OBJECT(widgets->SaveLocalMenuItem),"activate",G_CALLBACK(on_config_local_save),NULL);
    g_signal_connect(G_OBJECT(widgets->SaveGlobalMenuItem),"activate",G_CALLBACK(on_config_global_save),NULL);
    g_signal_connect(G_OBJECT(widgets->SaveCustomMenuItem),"activate",G_CALLBACK(on_config_custom_save),NULL);
    g_signal_connect(G_OBJECT(widgets->SystemUnitsTree),"cursor-changed",G_CALLBACK(on_tree_selection_changed),widgets);
    g_signal_connect(G_OBJECT(widgets->UserUnitsTree),"cursor-changed",G_CALLBACK(on_tree_selection_changed),widgets);
    yon_root_button_setup((template_main_window*)widgets,main_config.launch_arguments,main_config.launch_size);
    gtk_tree_model_filter_set_visible_func(widgets->UserFilter,(GtkTreeModelFilterVisibleFunc)yon_filter,widgets,NULL);
    gtk_tree_model_filter_set_visible_func(widgets->SystemFilter,(GtkTreeModelFilterVisibleFunc)yon_filter,widgets,NULL);
    for (int i=0;i<5;i++){
        gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(widgets->SystemSort),i,(GtkTreeIterCompareFunc)sort_bool,GINT_TO_POINTER(i),NULL);
        gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(widgets->UserSort),i,(GtkTreeIterCompareFunc)sort_bool,GINT_TO_POINTER(i),NULL);
    }
    gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(widgets->SystemSort),5,(GtkTreeIterCompareFunc)sort_string,GINT_TO_POINTER(13),NULL);
    gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(widgets->SystemSort),6,(GtkTreeIterCompareFunc)sort_string,GINT_TO_POINTER(5),NULL);
    gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(widgets->UserSort),5,(GtkTreeIterCompareFunc)sort_string,GINT_TO_POINTER(13),NULL);
    gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(widgets->UserSort),6,(GtkTreeIterCompareFunc)sort_string,GINT_TO_POINTER(5),NULL);
    gtk_tree_view_set_search_column(GTK_TREE_VIEW(widgets->UserUnitsTree),5);
    yon_load_proceed(YON_CONFIG_LOCAL);
    yon_ubl_status_box_render(LIST_LOAD_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
    if (!main_config.update_thread_active){
        main_config.update_thread_active=1;
        g_thread_new("update",(GThreadFunc)yon_interface_update,widgets);
        
    }
    yon_save_window_set_postsave_function(on_save_done,widgets);
}

int main(int argc, char *argv[]){
    setlocale(LC_ALL, "");
    textdomain (LocaleName);
    config_init();
    
    yon_ubl_connect_config((_template_config*)&main_config); 
    yon_ubl_window_init(TITLE_LABEL,TITLE_INFO_LABEL,LocaleName,CssPath,LocaleName,version_application,WIKI_LINK);
	config_str unfound = NULL;
	int size=0;
	yon_ubl_setup_arguments(argc,argv,&unfound,&size,NULL);
    gtk_init(&argc,&argv);
    template_main_window *widgets = yon_ubl_window_setup(); 
    main_config.launch_arguments=yon_char_parsed_copy(argv,argc);
    main_config.launch_size=argc;
    yon_main_window_complete((main_window*)widgets);
    char *path = yon_char_unite(yon_ubl_user_get_home_directory(),"/.config/",LocaleName,"/",LocaleName,".conf",NULL);
    yon_window_config_load(path);
    if (getuid()!=0){
        textdomain(template_ui_LocaleName);
        yon_ubl_status_box_render(ROOT_WARNING_LABEL,BACKGROUND_IMAGE_FAIL_TYPE);
        textdomain(LocaleName);
    }
    gtk_main();
    return 0;
}