#include "ubl-settings-usergroups.h"

void on_additional_settings_changed(GtkWidget *self, ubl_settings_usergroups_additional_settings_window *window){
    if (self == window->DefaultUserNameEntry){
        window->default_user_name = gtk_entry_get_text(GTK_ENTRY(window->DefaultUserNameEntry));

    } else if (self == window->DefaultPasswordEntry){
        window->default_password = gtk_entry_get_text(GTK_ENTRY(window->DefaultPasswordEntry));

    } else if (self == window->RootPasswordEntry){
        window->default_root_password = gtk_entry_get_text(GTK_ENTRY(window->RootPasswordEntry));

    } else if (self == window->PasswordHashCombo){
        window->password_hash = "";

    } else if (self == window->DefaultUserAdministratorCheck){
        window->user_1000_admin = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->DefaultUserAdministratorCheck));

    } else if (self == window->UsersBootCheck){
        window->user_boot = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->UsersBootCheck));

    // } else if (self == window->UsersShutdownCheck){
    //     window->user_shutdown = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->UsersShutdownCheck));
    }
}

 void on_additional_settings_save(GtkWidget *, ubl_settings_usergroups_additional_settings_window *window){
	const char *default_user = (char*)gtk_entry_get_text(GTK_ENTRY(window->DefaultUserNameEntry));
	if (!yon_char_is_empty(default_user)){
        if (window->default_user_name)
            yon_config_register(DEFAULTUSER_parameter,DEFAULTUSER_parameter_command,yon_char_new((char*)default_user));
	} else {
        if (window->default_user_name)
            yon_config_remove_by_key(DEFAULTUSER_parameter);
	}
	char *default_password = NULL;
	int user_password_active = gtk_combo_box_get_active(GTK_COMBO_BOX(window->DefaultPasswordCombo));
	if (user_password_active==1)
		default_password=(char*)gtk_entry_get_text(GTK_ENTRY(window->DefaultPasswordEntry));
	else if (user_password_active==2)
		default_password=" ";
	else if (user_password_active==3){
		default_password="!*";
	}
	if (!yon_char_is_empty(default_password)){
        // if (window->default_password)
		yon_config_register(DEFAULTPASSWD_parameter,DEFAULTPASSWD_parameter_command,default_password);
	} else {
        // if (window->default_password)
            yon_config_remove_by_key(DEFAULTPASSWD_parameter);
	}
	char *root_password = NULL;
	int root_password_active = gtk_combo_box_get_active(GTK_COMBO_BOX(window->RootPasswordCombo));
	if (root_password_active==1)
		root_password=(char*)gtk_entry_get_text(GTK_ENTRY(window->RootPasswordEntry));
	else if (root_password_active==2)
		root_password=" ";
	if (!yon_char_is_empty(root_password)){
        // if (window->default_root_password)
		yon_config_register(DEFAULTROOTPASSWD_parameter,DEFAULTROOTPASSWD_parameter_command,root_password);
	} else {
        // if (window->default_root_password)
            yon_config_remove_by_key(DEFAULTROOTPASSWD_parameter);
	}
	int user_k_admin = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->DefaultUserAdministratorCheck));
        if (user_k_admin){
            if (window->user_1000_admin)
                yon_config_register(ADDADM_parameter,ADDADM_parameter_command,"yes");
        } else {
            if (window->user_1000_admin)
                yon_config_register(ADDADM_parameter,ADDADM_parameter_command,"no");
        }
	if (gtk_combo_box_get_active(GTK_COMBO_BOX(window->PasswordHashCombo))!=0){
		char *hash = (char*)gtk_combo_box_get_active_id(GTK_COMBO_BOX(window->PasswordHashCombo));
		if (!yon_char_is_empty(hash)){
            if (window->password_hash)
                yon_config_register(HASHPASSWD_parameter,HASHPASSWD_parameter_command,hash);
		}
	}else {
        if (window->password_hash)
            yon_config_remove_by_key(HASHPASSWD_parameter);
	}
	// char *sync = "";
	// int boot_active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->UsersBootCheck));
	// int shutdown_active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->UsersShutdownCheck));
	// if (!boot_active&&!shutdown_active){
    //     if (window->user_boot>-1||window->user_boot>-1)
    //         yon_config_remove_by_key(USERADD_SYNC_parameter);
	// } else {
	// 	if (boot_active){
    //         if (window->user_boot>-1)
    //             sync = "boot";
	// 	}
	// 	if (shutdown_active){
    //         if (window->user_shutdown>-1)
    //             sync = yon_char_unite(sync,yon_char_is_empty(sync)?"":",","shutdown",NULL);
	// 	}
    //     if (window->user_boot>-1||window->user_boot>-1)
	// 	yon_config_register(USERADD_SYNC_parameter,USERADD_SYNC_parameter_command,sync);
	// }
	on_useradd_sync_changed(window);
 }

 void on_additional_settings_user_sync_add(GtkWidget *self, ubl_settings_usergroups_additional_settings_window *window){
	GtkTreeModel *model;
	GtkTreeIter iter;
	GtkWidget *tree;
	if (self == window->UserAddButton){
		tree = window->UsersTree;
	} else {
		tree = window->GroupsTree;
	}
	if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(tree)),&model,&iter)){
		char *name;
		char *parameter;
		int min_sensitive;
		int max_sensitive;
		gtk_tree_model_get(model,&iter,1,&name,7,&min_sensitive,8,&max_sensitive,9,&parameter,-1);

		gtk_list_store_append(GTK_LIST_STORE(model),&iter);
		gtk_list_store_set(GTK_LIST_STORE(model),&iter,0,1,1,name,5,1,6,1,7,min_sensitive,8,max_sensitive,9,parameter,10,1,11,1,-1);

	}
 }

 void on_additional_settings_user_sync_remove(GtkWidget *, ubl_settings_usergroups_additional_settings_window *window){
	GtkTreeModel *model;
	GtkTreeIter iter;
	if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(window->UsersTree)),&model,&iter)){
		gboolean is_indeletable;
		gtk_tree_model_get(model,&iter,4,&is_indeletable,-1);
		if (!is_indeletable){
			gtk_list_store_remove(window->UsersShutdownList,&iter);
		}
	}
 }

 void on_additional_settings_group_sync_remove(GtkWidget *, ubl_settings_usergroups_additional_settings_window *window){
	GtkTreeModel *model;
	GtkTreeIter iter;
	if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(window->GroupsTree)),&model,&iter)){
		gboolean is_indeletable;
		gtk_tree_model_get(model,&iter,4,&is_indeletable,-1);
		if (!is_indeletable){
			gtk_list_store_remove(window->GroupsShutdownList,&iter);
		}
	}
	// on_useradd_sync_changed(window);
 }

void on_additional_settings_cell_toggled(GtkCellRenderer *self, char *path, ubl_settings_usergroups_additional_settings_window *window){
	GtkTreeIter iter;
	GtkTreeModel *model = NULL;
	if (self == window->UserActiveCell){
		model = GTK_TREE_MODEL(window->UsersShutdownList);
	}  else {
		model = GTK_TREE_MODEL(window->GroupsShutdownList);
	}
	int status;
	gtk_tree_model_get_iter_from_string(model,&iter,path);
	gtk_tree_model_get(model,&iter,0,&status,-1);
	gtk_list_store_set(GTK_LIST_STORE(model),&iter,0,!status,6,!status,-1);
	if (path[0]=='0'&&!!status){
		for_iter(model,&iter){
			gtk_list_store_set(GTK_LIST_STORE(model),&iter,5,1,-1);
		}
	} else if (path[0] == '0'&&!status) {
		int i=0;
		for_iter(model,&iter){
			if (i){
				gtk_list_store_set(GTK_LIST_STORE(model),&iter,5,0,-1);
			}
			i++;
		}
	}
	// on_useradd_sync_changed(window);
}

void on_additional_settings_cell_edited(GtkCellRenderer *self, char *path, char *new_text, ubl_settings_usergroups_additional_settings_window *window){
	for (size_t i=0;i<strlen(new_text);i++){
		if (!g_ascii_isdigit(new_text[i])) return;
	}
GtkTreeIter iter;
	GtkTreeModel *model = NULL;
	int place_to_set = -1;
	if (self == window->UserMinCell){
		model = GTK_TREE_MODEL(window->UsersShutdownList);
		place_to_set=2;
	} else  if (self == window->UserMaxCell) {
		model = GTK_TREE_MODEL(window->UsersShutdownList);
		place_to_set=3;
	} else  if (self == window->GroupMinCell) {
		model = GTK_TREE_MODEL(window->GroupsShutdownList);
		place_to_set=2;
	} else  if (self == window->GroupMaxCell) {
		model = GTK_TREE_MODEL(window->GroupsShutdownList);
		place_to_set=3;
	}
	gtk_tree_model_get_iter_from_string(model,&iter,path);
	char *old_val;
	gtk_tree_model_get(model,&iter,place_to_set==2?3:2,&old_val,-1);
	if (yon_char_is_empty(old_val)) old_val = "";
	if (!yon_char_is_empty(old_val)){
		if (place_to_set==2){
			if (atoi(new_text)>atoi(old_val)){
				new_text=old_val;
			}
		} else {
			if (atoi(old_val)>atoi(new_text)){
				new_text = old_val;
			}
		}
	}
		gtk_list_store_set(GTK_LIST_STORE(model),&iter,place_to_set,new_text,place_to_set==2?3:2,old_val,-1);
	// on_useradd_sync_changed(window);
}

void yon_shutdown_toggled(GtkWidget *self,ubl_settings_usergroups_additional_settings_window *window){
	if (self == window->UsersShutdownCheck){
		int active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(self));
		gtk_widget_set_sensitive(window->UserAddButton,!active);
		gtk_widget_set_sensitive(window->UsersTree,!active);
		gtk_widget_set_sensitive(window->UserRemoveButton,!active);
		if (active){
			GtkTreeIter iter;
			for_iter(GTK_TREE_MODEL(window->UsersShutdownList),&iter){
				gtk_list_store_set(window->UsersShutdownList,&iter,0,0,-1);
			}
			gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(window->UsersShutdownList),&iter,"1");
			gtk_list_store_set(window->UsersShutdownList,&iter,0,1,-1);
			gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(window->UsersShutdownList),&iter,"2");
			gtk_list_store_set(window->UsersShutdownList,&iter,0,1,-1);
		}
	} else {
		int active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(self));
		gtk_widget_set_sensitive(window->GroupAddButton,!active);
		gtk_widget_set_sensitive(window->GroupsTree,!active);
		gtk_widget_set_sensitive(window->GroupRemoveButton,!active);
		if (active){
			GtkTreeIter iter;
			for_iter(GTK_TREE_MODEL(window->GroupsShutdownList),&iter){
				gtk_list_store_set(window->GroupsShutdownList,&iter,0,0,-1);
			}
			gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(window->GroupsShutdownList),&iter,"1");
			gtk_list_store_set(window->GroupsShutdownList,&iter,0,1,-1);
			gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(window->GroupsShutdownList),&iter,"2");
			gtk_list_store_set(window->GroupsShutdownList,&iter,0,1,-1);
		}
	}
}

void on_adiitional_settings_tree_selection_changed(GtkWidget *self, ubl_settings_usergroups_additional_settings_window *window){
	GtkTreeModel *model;
	GtkTreeIter iter;
	GtkWidget *tree;
	GtkWidget *add_button;
	GtkWidget *remove_button;
	if (self == window->UsersTree){
		tree = window->UsersTree;
		add_button = window->UserAddButton;
		remove_button = window->UserRemoveButton;
	} else {
		tree = window->GroupsTree;
		add_button = window->GroupAddButton;
		remove_button = window->GroupRemoveButton;
	}
	if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(tree)),&model,&iter)){
		int deletable;
		int creatable;
		char *parameter;
		gtk_tree_model_get(model,&iter,9,&parameter,10,&creatable,11,&deletable,-1);
		if (creatable) gtk_widget_set_sensitive(add_button,1); else gtk_widget_set_sensitive(add_button,0);
		if (deletable) gtk_widget_set_sensitive(remove_button,1); else gtk_widget_set_sensitive(remove_button,0);
	}
}

void on_useradd_sync_changed(ubl_settings_usergroups_additional_settings_window *window){
	char *useradd_sync = "";
	if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->UsersBootCheck))){
		useradd_sync = yon_char_new("boot");
	}
	if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->UsersShutdownCheck))){
		char *temp = yon_char_unite(useradd_sync,!yon_char_is_empty(useradd_sync)?",":"","shutdown",NULL);
		if(!yon_char_is_empty(useradd_sync)) free(useradd_sync);
		useradd_sync = temp;
		
	}
		
		GtkTreeIter iter;
		for_iter(window->UsersShutdownList,&iter){
			int active;
			char *min_str, *max_str;
			int sensitive;
			char *parameter;

			gtk_tree_model_get(GTK_TREE_MODEL(window->UsersShutdownList),&iter,0,&active,2,&min_str,3,&max_str,6,&sensitive,9,&parameter,-1);

			if (active&&sensitive){
				if (!strcmp(parameter,"shutdown@all")){
					char *temp = yon_char_unite(useradd_sync,!yon_char_is_empty(useradd_sync)?",":"",parameter,NULL);
					if(!yon_char_is_empty(useradd_sync)) free(useradd_sync);
					useradd_sync = temp;
				} else if (!strcmp(parameter,"shutdown@users")){
					char *temp = yon_char_unite(useradd_sync,!yon_char_is_empty(useradd_sync)?",":"",parameter,NULL);
					if(!yon_char_is_empty(useradd_sync)) free(useradd_sync);
					useradd_sync = temp;

				} else if (!strcmp(parameter,"shutdown@systems")){
					char *temp = yon_char_unite(useradd_sync,!yon_char_is_empty(useradd_sync)?",":"",parameter,NULL);
					if(!yon_char_is_empty(useradd_sync)) free(useradd_sync);
					useradd_sync = temp;

				} else if (!strcmp(parameter,"shutdown@min-max")){
					if (yon_char_is_empty(min_str)||yon_char_is_empty(max_str)){
						yon_ubl_status_box_spawn(GTK_CONTAINER(window->StatusBox),EMPTY_IMPORTANT_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE);
						return;
					}
					char *temp = yon_char_unite(useradd_sync,!yon_char_is_empty(useradd_sync)?",":"","shutdown@",min_str,"-",max_str,NULL);
					if(!yon_char_is_empty(useradd_sync)) free(useradd_sync);
					useradd_sync = temp;

				} else if (!strcmp(parameter,"shutdown@uid")){
					if (yon_char_is_empty(min_str)){
						yon_ubl_status_box_spawn(GTK_CONTAINER(window->StatusBox),EMPTY_IMPORTANT_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE);
						return;
					}
					char *temp = yon_char_unite(useradd_sync,!yon_char_is_empty(useradd_sync)?",":"","shutdown@",min_str,NULL);
					if(!yon_char_is_empty(useradd_sync)) free(useradd_sync);
					useradd_sync = temp;

				}
			}
		}
	if (!yon_char_is_empty(useradd_sync)){
		yon_config_register(USERADD_SYNC_parameter,USERADD_SYNC_get_command,useradd_sync);
	} else {
		yon_config_remove_by_key(USERADD_SYNC_parameter);
	}

	char *groupadd_sync = "";
	if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->GroupsBootCheck))){
		groupadd_sync = yon_char_new("boot");
	}
	if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->GroupsShutdownCheck))){
		char *temp = yon_char_unite(groupadd_sync,!yon_char_is_empty(groupadd_sync)?",":"","shutdown",NULL);
		if(!yon_char_is_empty(groupadd_sync)) free(groupadd_sync);
		groupadd_sync = temp;
	}
		for_iter(window->GroupsShutdownList,&iter){
			int active;
			char *min_str, *max_str;
			int sensitive;
			char *parameter;

			gtk_tree_model_get(GTK_TREE_MODEL(window->GroupsShutdownList),&iter,0,&active,2,&min_str,3,&max_str,6,&sensitive,9,&parameter,-1);
			if (active&&sensitive){
				if (!strcmp(parameter,"shutdown@all")){
					char *temp = yon_char_unite(groupadd_sync,!yon_char_is_empty(groupadd_sync)?",":"",parameter,NULL);
					if(!yon_char_is_empty(groupadd_sync)) free(groupadd_sync);
					groupadd_sync = temp;
				} else if (!strcmp(parameter,"shutdown@users")){
					char *temp = yon_char_unite(groupadd_sync,!yon_char_is_empty(groupadd_sync)?",":"",parameter,NULL);
					if(!yon_char_is_empty(groupadd_sync)) free(groupadd_sync);
					groupadd_sync = temp;

				} else if (!strcmp(parameter,"shutdown@systems")){
					char *temp = yon_char_unite(groupadd_sync,!yon_char_is_empty(groupadd_sync)?",":"",parameter,NULL);
					if(!yon_char_is_empty(groupadd_sync)) free(groupadd_sync);
					groupadd_sync = temp;

				} else if (!strcmp(parameter,"shutdown@min-max")){
					if (yon_char_is_empty(min_str)||yon_char_is_empty(max_str)){
						yon_ubl_status_box_spawn(GTK_CONTAINER(window->StatusBox),EMPTY_IMPORTANT_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE);
						return;
					}
					char *temp = yon_char_unite(groupadd_sync,!yon_char_is_empty(groupadd_sync)?",":"","shutdown@",min_str,"-",max_str,NULL);
					if(!yon_char_is_empty(groupadd_sync)) free(groupadd_sync);
					groupadd_sync = temp;

				} else if (!strcmp(parameter,"shutdown@gid")){
					if (yon_char_is_empty(min_str)){
						yon_ubl_status_box_spawn(GTK_CONTAINER(window->StatusBox),EMPTY_IMPORTANT_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE);
						return;
					}
					char *temp = yon_char_unite(groupadd_sync,!yon_char_is_empty(groupadd_sync)?",":"","shutdown@",min_str,NULL);
					if(!yon_char_is_empty(groupadd_sync)) free(groupadd_sync);
					groupadd_sync = temp;

				}
			}
		}
	if (!yon_char_is_empty(groupadd_sync)){
	yon_config_register(GROUPADD_SYNC_parameter,GROUPADD_SYNC_parameter_command,groupadd_sync);
	} else {
		yon_config_remove_by_key(GROUPADD_SYNC_parameter);
	}
		on_subwindow_close(window->Window);
}

ubl_settings_usergroups_additional_settings_window *yon_ubl_settings_usergroups_additional_settings_new(){
	ubl_settings_usergroups_additional_settings_window *window = malloc(sizeof(ubl_settings_usergroups_additional_settings_window));
	GtkBuilder *builder = gtk_builder_new_from_resource(glade_path_ubl_settings_usergroups_additional_settings);
	window->Window=yon_gtk_builder_get_widget(builder,"Window");
	window->StatusBox=yon_gtk_builder_get_widget(builder,"StatusBox");
	window->DefaultUserNameEntry=yon_gtk_builder_get_widget(builder,"DefaultUserNameEntry");
	window->DefaultUserAdministratorCheck=yon_gtk_builder_get_widget(builder,"DefaultUserAdministratorCheck");
	window->DefaultPasswordCombo=yon_gtk_builder_get_widget(builder,"DefaultPasswordCombo");
	window->DefaultPasswordEntry=yon_gtk_builder_get_widget(builder,"DefaultPasswordEntry");
	window->DefaultPasswordButton=yon_gtk_builder_get_widget(builder,"DefaultPasswordButton");
	window->RootPasswordCombo=yon_gtk_builder_get_widget(builder,"RootPasswordCombo");
	window->RootPasswordEntry=yon_gtk_builder_get_widget(builder,"RootPasswordEntry");
	window->RootPasswordButton=yon_gtk_builder_get_widget(builder,"RootPasswordButton");
	window->PasswordHashCombo=yon_gtk_builder_get_widget(builder,"PasswordHashCombo");
	window->EncryptAllPasswordsButton=yon_gtk_builder_get_widget(builder,"EncryptAllPasswordsButton");
	window->CancelButton=yon_gtk_builder_get_widget(builder,"CancelButton");
	window->AcceptButton=yon_gtk_builder_get_widget(builder,"AcceptButton");
	window->UsersBootCheck=yon_gtk_builder_get_widget(builder,"UsersBootCheck");
	window->UsersShutdownCheck=yon_gtk_builder_get_widget(builder,"UsersShutdownCheck");
	window->UsersShutdownExpander=yon_gtk_builder_get_widget(builder,"UsersShutdownExpander");
	window->UserShutdownRevealer=yon_gtk_builder_get_widget(builder,"UserShutdownRevealer");
	window->UsersTree=yon_gtk_builder_get_widget(builder,"UsersTree");
	window->UserAddButton=yon_gtk_builder_get_widget(builder,"UserAddButton");
	window->UserRemoveButton=yon_gtk_builder_get_widget(builder,"UserRemoveButton");
	window->GroupsBootCheck=yon_gtk_builder_get_widget(builder,"GroupsBootCheck");
	window->GroupsShutdownCheck=yon_gtk_builder_get_widget(builder,"GroupsShutdownCheck");
	window->GroupsShutdownExpander=yon_gtk_builder_get_widget(builder,"GroupShutdownExpander");
	window->GroupShutdownRevealer=yon_gtk_builder_get_widget(builder,"GroupShutdownRevealer");
	window->GroupsTree=yon_gtk_builder_get_widget(builder,"GroupsTree");
	window->GroupAddButton=yon_gtk_builder_get_widget(builder,"GroupAddButton");
	window->GroupRemoveButton=yon_gtk_builder_get_widget(builder,"GroupRemoveButton");
	window->UsersShutdownList=GTK_LIST_STORE(gtk_builder_get_object(builder,"UsersShutdownList"));
	window->GroupsShutdownList=GTK_LIST_STORE(gtk_builder_get_object(builder,"GroupsShutdownList"));
	window->UserActiveCell=GTK_CELL_RENDERER(gtk_builder_get_object(builder,"UserActiveCell"));
	window->UserMinCell=GTK_CELL_RENDERER(gtk_builder_get_object(builder,"UserMinCell"));
	window->UserMaxCell=GTK_CELL_RENDERER(gtk_builder_get_object(builder,"UserMaxCell"));
	window->GroupActiveCell=GTK_CELL_RENDERER(gtk_builder_get_object(builder,"GroupActiveCell"));
	window->GroupMinCell=GTK_CELL_RENDERER(gtk_builder_get_object(builder,"GroupMinCell"));
	window->GroupMaxCell=GTK_CELL_RENDERER(gtk_builder_get_object(builder,"GroupMaxCell"));

	yon_gtk_login_block_symbols(GTK_ENTRY(window->DefaultUserNameEntry));

	gtk_widget_set_tooltip_markup(window->DefaultUserNameEntry,DEFAULT_USER_TOOLTIP_LABEL);

	yon_gtk_revealer_set_from_expander(GTK_REVEALER(window->UserShutdownRevealer),GTK_EXPANDER(window->UsersShutdownExpander));
	yon_gtk_revealer_set_from_expander(GTK_REVEALER(window->GroupShutdownRevealer),GTK_EXPANDER(window->GroupsShutdownExpander));

    window->default_password=NULL;
    window->default_root_password=NULL;
    window->default_user_name=NULL;
    window->user_1000_admin=-1;
    window->user_shutdown=-1;
    window->user_boot=-1;
    window->password_hash=NULL;

	char *useradd_sync = yon_config_get_by_key(USERADD_SYNC_parameter);
	char *groupadd_sync = yon_config_get_by_key(GROUPADD_SYNC_parameter);

	if (!yon_char_is_empty(useradd_sync)){
		GtkTreeModel *model = GTK_TREE_MODEL(window->UsersShutdownList);
		GtkTreeIter iter;
		int useradd_sync_size;
		config_str parsed = yon_char_parse(useradd_sync,&useradd_sync_size,",");
		if (yon_char_parsed_check_exist(parsed,useradd_sync_size,"shutdown@all")){
			int a=0;
			for_iter(model,&iter){
				if (!a){
					gtk_list_store_set(window->UsersShutdownList,&iter,6,0,-1);
					a++;
				} else {
					gtk_list_store_set(window->UsersShutdownList,&iter,5,1,-1);
				}
			}
		}
		int uid_set=0, maxmin_set=0;
		for (int i=0;i<useradd_sync_size;i++){
				gtk_expander_set_expanded(GTK_EXPANDER(window->UsersShutdownExpander),1);
				gtk_revealer_set_reveal_child(GTK_REVEALER(window->UserShutdownRevealer),1);
			if (!strcmp(parsed[i],"boot")){
				gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->UsersBootCheck),1);
			} else if (!strcmp(parsed[i],"shutdown@all")){
				gtk_tree_model_get_iter_first(model,&iter);
				gtk_list_store_set(window->UsersShutdownList,&iter,0,1,7,0,8,0,-1);
			} else if (!strcmp(parsed[i],"shutdown@users")){
				gtk_tree_model_get_iter_first(model,&iter);
				gtk_list_store_set(window->UsersShutdownList,&iter,0,0,5,0,6,0,-1);
				gtk_tree_model_get_iter_from_string(model,&iter,"1");
				gtk_list_store_set(window->UsersShutdownList,&iter,0,1,5,1,6,1,7,0,8,0,-1);

			} else if (!strcmp(parsed[i],"shutdown@systems")){
				gtk_tree_model_get_iter_first(model,&iter);
				gtk_list_store_set(window->UsersShutdownList,&iter,0,0,5,0,6,0,-1);
				gtk_tree_model_get_iter_from_string(model,&iter,"2");
				gtk_list_store_set(window->UsersShutdownList,&iter,0,1,5,1,6,1,7,0,8,0,-1);

			} else if (strstr(parsed[i],"-")){
				gtk_tree_model_get_iter_first(model,&iter);
				gtk_list_store_set(window->UsersShutdownList,&iter,0,0,5,0,6,0,-1);
				if (!maxmin_set){
					gtk_tree_model_get_iter_from_string(model,&iter,"3");
					maxmin_set++;
				} else {
					gtk_list_store_append(window->UsersShutdownList,&iter);
					gtk_list_store_set(window->UsersShutdownList,&iter,1,SHUTDOWN_UID_RANGE_LABEL,5,1,6,1,7,1,8,1,9,"shutdown@uid",10,1,11,1,-1);
				}

				char *temp = yon_char_new(parsed[i]);
				free(yon_char_divide_search(temp,"@",-1));
				char *min = yon_char_divide_search(temp,"-",-1);

				gtk_list_store_set(window->UsersShutdownList,&iter,0,1,2,min,3,temp,6,1,7,1,8,1,-1);

			} else if (strstr(parsed[i],"shutdown@")) {
				gtk_tree_model_get_iter_first(model,&iter);
				gtk_list_store_set(window->UsersShutdownList,&iter,0,0,5,0,6,0,-1);

				if (!uid_set){
					gtk_tree_model_get_iter_from_string(model,&iter,"4");
					uid_set++;
				} else {
					gtk_list_store_append(window->UsersShutdownList,&iter);
					gtk_list_store_set(window->UsersShutdownList,&iter,1,SHUTDOWN_UID_LABEL,5,1,6,1,7,1,8,0,9,"shutdown@uid",10,1,11,1,-1);
				}
				char *temp = yon_char_new(parsed[i]);
				free(yon_char_divide_search(temp,"@",-1));
				gtk_list_store_set(window->UsersShutdownList,&iter,0,1,2,temp,6,1,7,1,8,1,-1);
			} else if (!strcmp(parsed[i],"shutdown")){
				gtk_tree_model_get_iter_first(model,&iter);
				gtk_list_store_set(window->UsersShutdownList,&iter,0,0,-1);
				gtk_tree_model_get_iter_from_string(model,&iter,"1");
				gtk_list_store_set(window->UsersShutdownList,&iter,0,1,5,1,6,1,-1);
				gtk_tree_model_get_iter_from_string(model,&iter,"2");
				gtk_list_store_set(window->UsersShutdownList,&iter,0,1,5,1,6,1,-1);

			}
		}
	}
	
	if (!yon_char_is_empty(groupadd_sync)){
		GtkTreeModel *model = GTK_TREE_MODEL(window->GroupsShutdownList);
		GtkTreeIter iter;
		int useradd_sync_size;
		config_str parsed = yon_char_parse(groupadd_sync,&useradd_sync_size,",");
		if (yon_char_parsed_check_exist(parsed,useradd_sync_size,"shutdown@all")){
			int a=0;
			for_iter(model,&iter){
				if (!a){
					gtk_list_store_set(window->GroupsShutdownList,&iter,6,0,-1);
					a++;
				} else {
					gtk_list_store_set(window->GroupsShutdownList,&iter,5,1,-1);
				}
			}
		}
				gtk_expander_set_expanded(GTK_EXPANDER(window->GroupsShutdownExpander),1);
				gtk_revealer_set_reveal_child(GTK_REVEALER(window->GroupShutdownRevealer),1);
		int uid_set=0, maxmin_set=0;
		for (int i=0;i<useradd_sync_size;i++){
			if (!strcmp(parsed[i],"boot")){
				gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->GroupsBootCheck),1);
			} else if (!strcmp(parsed[i],"shutdown@all")){
				gtk_tree_model_get_iter_first(model,&iter);
				gtk_list_store_set(window->GroupsShutdownList,&iter,0,1,-1);
			} else if (!strcmp(parsed[i],"shutdown@users")){
				gtk_tree_model_get_iter_first(model,&iter);
				gtk_list_store_set(window->GroupsShutdownList,&iter,0,0,-1);
				gtk_tree_model_get_iter_from_string(model,&iter,"1");
				gtk_list_store_set(window->GroupsShutdownList,&iter,0,1,5,1,6,1,-1);

			} else if (!strcmp(parsed[i],"shutdown@systems")){
				gtk_tree_model_get_iter_first(model,&iter);
				gtk_list_store_set(window->GroupsShutdownList,&iter,0,0,-1);
				gtk_tree_model_get_iter_from_string(model,&iter,"2");
				gtk_list_store_set(window->GroupsShutdownList,&iter,0,1,5,1,6,1,-1);

			} else if (strstr(parsed[i],"-")){
				gtk_tree_model_get_iter_first(model,&iter);
				gtk_list_store_set(window->GroupsShutdownList,&iter,0,0,-1);
				if (!maxmin_set){
					gtk_tree_model_get_iter_from_string(model,&iter,"3");
					maxmin_set++;
				} else {
					gtk_list_store_append(window->GroupsShutdownList,&iter);
					gtk_list_store_set(window->GroupsShutdownList,&iter,1,SHUTDOWN_GID_RANGE_LABEL,5,1,6,1,9,"shutdown@uid",10,1,11,1,-1);
				}

				char *temp = yon_char_new(parsed[i]);
				free(yon_char_divide_search(temp,"@",-1));
				char *min = yon_char_divide_search(temp,"-",-1);

				gtk_list_store_set(window->GroupsShutdownList,&iter,0,1,2,min,3,temp,6,1,7,1,8,1,-1);

			} else if (strstr(parsed[i],"shutdown@")){
				gtk_tree_model_get_iter_first(model,&iter);
				gtk_list_store_set(window->GroupsShutdownList,&iter,0,0,-1);

				if (!uid_set){
					gtk_tree_model_get_iter_from_string(model,&iter,"4");
					uid_set++;
				} else {
					gtk_list_store_append(window->GroupsShutdownList,&iter);
					gtk_list_store_set(window->GroupsShutdownList,&iter,1,SHUTDOWN_GID_LABEL,5,1,6,1,7,1,8,1,9,"shutdown@uid",10,1,11,1,-1);
				}
				char *temp = yon_char_new(parsed[i]);
				free(yon_char_divide_search(temp,"@",-1));
				gtk_list_store_set(window->GroupsShutdownList,&iter,0,1,2,temp,5,1,6,1,-1);
			} else if (!strcmp(parsed[i],"shutdown")){
				gtk_tree_model_get_iter_first(model,&iter);
				gtk_list_store_set(window->GroupsShutdownList,&iter,0,0,-1);
				gtk_tree_model_get_iter_from_string(model,&iter,"1");
				gtk_list_store_set(window->GroupsShutdownList,&iter,0,1,6,1,-1);
				gtk_tree_model_get_iter_from_string(model,&iter,"2");
				gtk_list_store_set(window->GroupsShutdownList,&iter,0,1,6,1,-1);

			}
		}
	}
	
    g_signal_connect(G_OBJECT(window->UserAddButton),"clicked",G_CALLBACK(on_additional_settings_user_sync_add),window);
    g_signal_connect(G_OBJECT(window->UserRemoveButton),"clicked",G_CALLBACK(on_additional_settings_user_sync_remove),window);
    g_signal_connect(G_OBJECT(window->GroupAddButton),"clicked",G_CALLBACK(on_additional_settings_user_sync_add),window);
    g_signal_connect(G_OBJECT(window->GroupRemoveButton),"clicked",G_CALLBACK(on_additional_settings_group_sync_remove),window);
	
    g_signal_connect(G_OBJECT(window->UserActiveCell),"toggled",G_CALLBACK(on_additional_settings_cell_toggled),window);
    g_signal_connect(G_OBJECT(window->GroupActiveCell),"toggled",G_CALLBACK(on_additional_settings_cell_toggled),window);
    g_signal_connect(G_OBJECT(window->UserMinCell),"edited",G_CALLBACK(on_additional_settings_cell_edited),window);
    g_signal_connect(G_OBJECT(window->UserMaxCell),"edited",G_CALLBACK(on_additional_settings_cell_edited),window);
    g_signal_connect(G_OBJECT(window->GroupMinCell),"edited",G_CALLBACK(on_additional_settings_cell_edited),window);
    g_signal_connect(G_OBJECT(window->GroupMaxCell),"edited",G_CALLBACK(on_additional_settings_cell_edited),window);
	
    g_signal_connect(G_OBJECT(window->UsersShutdownExpander),"activate",G_CALLBACK(on_additional_settings_changed),window);
    g_signal_connect(G_OBJECT(window->GroupsShutdownExpander),"activate",G_CALLBACK(on_additional_settings_changed),window);
	
    g_signal_connect(G_OBJECT(window->UsersShutdownCheck),"toggled",G_CALLBACK(on_additional_settings_changed),window);
    g_signal_connect(G_OBJECT(window->GroupsShutdownCheck),"toggled",G_CALLBACK(on_additional_settings_changed),window);

	g_signal_connect(G_OBJECT(window->UsersTree),"cursor-changed",G_CALLBACK(on_adiitional_settings_tree_selection_changed),window);
	g_signal_connect(G_OBJECT(window->GroupsTree),"cursor-changed",G_CALLBACK(on_adiitional_settings_tree_selection_changed),window);

	g_signal_connect(G_OBJECT(window->UsersShutdownCheck),"toggled",G_CALLBACK(yon_shutdown_toggled),window);
	g_signal_connect(G_OBJECT(window->GroupsShutdownCheck),"toggled",G_CALLBACK(yon_shutdown_toggled),window);
	yon_window_config_custom_window_setup(GTK_WINDOW(window->Window),"AdditionalSettingsWindow");
	gtk_window_set_title(GTK_WINDOW(window->Window),ADDITIONAL_SETTINGS_TITLE_LABEL);
	{
		char *sync_parameters = yon_config_get_by_key(USERADD_SYNC_parameter);
		int size;
		config_str parsed = yon_char_parse(sync_parameters,&size,",");
		if (sync_parameters){
			if (strstr(sync_parameters,"boot")){
				gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->UsersBootCheck),1);
			}
			if (yon_char_parsed_check_exist(parsed,size,"shutdown")!=-1){
				gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->UsersShutdownCheck),1);
			}
		}
	}
	{
		char *sync_parameters = yon_config_get_by_key(GROUPADD_SYNC_parameter);
		int size;
		config_str parsed = yon_char_parse(sync_parameters,&size,",");
		if (sync_parameters){
			if (strstr(sync_parameters,"boot")){
				gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->GroupsBootCheck),1);
			}
			if (yon_char_parsed_check_exist(parsed,size,"shutdown")!=-1){
				gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->GroupsShutdownCheck),1);
			}
		}
	}
	int hash_size=0;
	config_str hash_algos = yon_resource_open_file(hash_list_path,&hash_size);
	if (main_config.hash_default_id==-1){
		int size;
		config_str ret = yon_config_load(get_default_hash_command,&size);
		if (size>0){
			char *hash = ret[0];
			if (hash[strlen(hash)-1]=='\n') hash[strlen(hash)-1]='\0';
			for (int i=0;i<hash_size;i++){
				if (hash_algos[i][0]!='!'){
					if (hash_algos[i][strlen(hash_algos[i])-1]=='\n') hash_algos[i][strlen(hash_algos[i])-1]='\0';
					int parsed_size;
					config_str parsed = yon_char_parse(hash_algos[i],&parsed_size,";");
					if (!strcmp(hash,parsed[0])){
						char *def_settings = yon_char_new(parsed[1]);
						char *def = yon_char_divide_search(def_settings," ",-1);
						free(def_settings);
						gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(window->PasswordHashCombo),yon_char_unite(DEFAULT_USER_LABEL," (",def,")",NULL));
					}
				}
			}
		}
	}
	for (int i=1;i<hash_size;i++){
		if (hash_algos[i][0]!='!'){
			if (hash_algos[i][strlen(hash_algos[i])-1]=='\n') hash_algos[i][strlen(hash_algos[i])-1]='\0';
			int parsed_size;
			config_str parsed = yon_char_parse(hash_algos[i],&parsed_size,";");
			gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(window->PasswordHashCombo),parsed[0],_(parsed[1]));
			gtk_widget_set_tooltip_text(window->PasswordHashCombo,parsed[1]);
			yon_char_parsed_free(parsed,parsed_size);
		}
	}
	yon_char_parsed_free(hash_algos,hash_size);
	gtk_combo_box_set_active(GTK_COMBO_BOX(window->PasswordHashCombo),0);
	char *default_user = yon_config_get_by_key(DEFAULTUSER_parameter);
	if (!yon_char_is_empty(default_user))
		gtk_entry_set_text(GTK_ENTRY(window->DefaultUserNameEntry),default_user);


	g_signal_connect(G_OBJECT(window->RootPasswordCombo),"changed",G_CALLBACK(on_password_combo_changed),window->RootPasswordButton);
	g_signal_connect(G_OBJECT(window->DefaultPasswordCombo),"changed",G_CALLBACK(on_password_combo_changed),window->DefaultPasswordButton);
	if (!yon_config_check_default(DEFAULTPASSWD_parameter)){
		char *default_password = yon_config_get_by_key(DEFAULTPASSWD_parameter);
		if (!yon_char_is_empty(default_password)){
			if (!strcmp(default_password," ")){
				gtk_combo_box_set_active(GTK_COMBO_BOX(window->DefaultPasswordCombo),2);
			} else if (!strcmp(default_password,"!*")){
				gtk_combo_box_set_active(GTK_COMBO_BOX(window->DefaultPasswordCombo),3);

			} else {
				gtk_combo_box_set_active(GTK_COMBO_BOX(window->DefaultPasswordCombo),1);
				gtk_entry_set_text(GTK_ENTRY(window->DefaultPasswordEntry),default_password);
			}
		}
	}
	if (!yon_config_check_default(DEFAULTROOTPASSWD_parameter)){
	char *root_password = yon_config_get_by_key(DEFAULTROOTPASSWD_parameter);
		if (!yon_char_is_empty(root_password)){
			if (!strcmp(root_password," ")){
				gtk_combo_box_set_active(GTK_COMBO_BOX(window->RootPasswordCombo),2);
			} else {
				gtk_combo_box_set_active(GTK_COMBO_BOX(window->RootPasswordCombo),1);
				gtk_entry_set_text(GTK_ENTRY(window->RootPasswordEntry),root_password);
			}
		}
	}
	char *is_k_admin = yon_config_get_by_key(ADDADM_parameter);
	if (!yon_char_is_empty(is_k_admin))
		if (!strcmp(is_k_admin,"yes"))
			gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->DefaultUserAdministratorCheck),1);
	char *hash = yon_config_get_by_key(HASHPASSWD_parameter);
	if (!yon_char_is_empty(hash)){
		gtk_combo_box_set_active_id(GTK_COMBO_BOX(window->PasswordHashCombo),hash);
	}

	// char *parameter = config(USERADD_SYNC_parameter);
	// {
	// 	int size;
	// 	config_str parsed = yon_char_parse(parameter,&size,",");
	// 	int sync_parameters_size;
	// 	config_str sync_parameters = yon_resource_open_file(sync_parameters_path,&sync_parameters_size);
	// 	for(int i=0;i<size;i++){
	// 		for (int j=1;j<sync_parameters_size;j++){
	// 			int sync_parsed_size;
	// 			config_str sync_parsed = yon_char_parse(sync_parameters[j],&sync_parsed_size,":");
	// 			int cur_size;
	// 			int sync_check = yon_parameter_check_tag(parsed[i],sync_parsed[0]);
	// 			if (sync_check) {
	// 				config_str cur = yon_parameter_get_by_template(parsed[i],sync_parsed[0],&cur_size);
	// 				if (cur){
	// 					GtkTreeIter iter;
	// 					gtk_list_store_append(window->UsersShutdownList,&iter);
	// 					gtk_list_store_set(window->UsersShutdownList,&iter,1,sync_parsed[0],2,cur[0],3,cur_size>1?cur[1]:"",-1);
	// 				};
	// 			}
	// 			yon_char_parsed_free(sync_parsed,sync_parsed_size);
	// 		}
			
	// 	}

	// }

	g_signal_connect(G_OBJECT(window->CancelButton),"clicked",G_CALLBACK(on_subwindow_close),NULL);
	g_signal_connect(G_OBJECT(window->AcceptButton),"clicked",G_CALLBACK(on_additional_settings_save),window);
	dictionary *default_dict=NULL;
	yon_dictionary_add_or_create_if_exists_with_data(default_dict,"combo",window->DefaultPasswordCombo);
	yon_dictionary_add_or_create_if_exists_with_data(default_dict,"entry",window->DefaultPasswordEntry);

	dictionary *root_dict=NULL;
	yon_dictionary_add_or_create_if_exists_with_data(root_dict,"combo",window->RootPasswordCombo);
	yon_dictionary_add_or_create_if_exists_with_data(root_dict,"entry",window->RootPasswordEntry);
	g_signal_connect(G_OBJECT(window->DefaultPasswordButton),"clicked",G_CALLBACK(on_password_change),default_dict);
	g_signal_connect(G_OBJECT(window->RootPasswordButton),"clicked",G_CALLBACK(on_password_change),root_dict);

	g_signal_connect(G_OBJECT(window->PasswordHashCombo),"changed",G_CALLBACK(on_hash_changed),window);

    g_signal_connect(G_OBJECT(window->DefaultUserNameEntry),"changed",G_CALLBACK(on_additional_settings_changed),window);
    g_signal_connect(G_OBJECT(window->DefaultPasswordEntry),"changed",G_CALLBACK(on_additional_settings_changed),window);
    g_signal_connect(G_OBJECT(window->RootPasswordEntry),"changed",G_CALLBACK(on_additional_settings_changed),window);
    g_signal_connect(G_OBJECT(window->PasswordHashCombo),"changed",G_CALLBACK(on_additional_settings_changed),window);
    g_signal_connect(G_OBJECT(window->DefaultUserAdministratorCheck),"toggled",G_CALLBACK(on_additional_settings_changed),window);
    g_signal_connect(G_OBJECT(window->UsersBootCheck),"toggled",G_CALLBACK(on_additional_settings_changed),window);
    g_signal_connect(G_OBJECT(window->GroupsBootCheck),"toggled",G_CALLBACK(on_additional_settings_changed),window);

	// g_signal_connect(G_OBJECT(window->UsersBootCheck),"toggled",G_CALLBACK(on_users_boot_toggled),NULL);
	// g_signal_connect(G_OBJECT(window->UsersShutdownCheck),"toggled",G_CALLBACK(on_users_shutdown_toggled),NULL);

return window;
}

void on_ubl_settings_usergroups_additional_settings_open(GtkWidget *, main_window *widgets){
    ubl_settings_usergroups_additional_settings_window *window = yon_ubl_settings_usergroups_additional_settings_new();

	dictionary *encrypt_data = NULL;
	yon_dictionary_add_or_create_if_exists_with_data(encrypt_data,"widgets",widgets);
	yon_dictionary_add_or_create_if_exists_with_data(encrypt_data,"window",window);
	dialog_confirmation_data *data=yon_confirmation_dialog_data_new();
	data->function=on_passwords_encrypt;
	data->action_text = ENCRYPT_SURE_LABEL;
	data->data=encrypt_data;
	data->title = ENCRYPT_TITLE_LABEL;

	g_signal_connect(G_OBJECT(window->EncryptAllPasswordsButton),"clicked",G_CALLBACK(yon_confirmation_dialog_call),data);
    
    gtk_window_set_transient_for(GTK_WINDOW(window->Window),GTK_WINDOW(widgets->Window));
    gtk_widget_show(window->Window);

}

config_str yon_parameter_parse(char *parameter, int *size){
	if (yon_char_is_empty(parameter)) return NULL;
	char *cur;
	(*size)=0;
	if ((cur = strstr(parameter,"<"))){
		config_str parsed = yon_char_parse(parameter,size,">");
		for (int i=0;i<(*size);i++){
			char *tag = strstr(parsed[i],">");
			int length = strlen(parsed[i])-strlen(tag+1);
			free(yon_char_divide(parsed[i],length));
		}
		return parsed;
	} else {
		config_str parsed = yon_char_parsed_new(size,parameter,NULL);
		return parsed;
	}
}

int yon_parameter_check_tag(char *parameter, char *pattern){
	char *tag_template = "[0-9]{1,}";
	char *converted = "";
	char *current = pattern;
	while (!yon_char_is_empty(current)){
		if ((*current)=='<'){
			char *end = strchr(current,'>');
			if (end){
				converted = yon_char_append(converted,tag_template);
				current = end+1;
			} else {
				// закрытие тэга не найдено
			}
		} else {
			char *temp = yon_char_append_c(converted,*current);
			if (!yon_char_is_empty(converted)) free(converted);
			converted = temp;
			current++;
		}
	}

	GRegex *regex = g_regex_new(converted,G_REGEX_EXTENDED,0,NULL);
	if (regex){
		GMatchInfo *match;
		if (g_regex_match(regex,parameter,0,&match)){
            char *value = g_match_info_fetch(match, 0);
			if (!strcmp(parameter,value))
				return 1;
		}
	}
	
	
	return 0;
}

config_str yon_parameter_get_by_template(char *parameter, char *pattern, int *size){
	config_str final = NULL;
	char *tag_template = "[0-9]{1,}";
	char *converted = "";
	char *current = pattern;
	while (!yon_char_is_empty(current)){
		if ((*current)=='<'){
			char *end = strchr(current,'>');
			if (end){
				converted = yon_char_append(converted,tag_template);
				current = end+1;
			} else {
				// закрытие тэга не найдено
			}
		} else {
			char *temp = yon_char_append_c(converted,*current);
			if (!yon_char_is_empty(converted)) free(converted);
			converted=temp;
			current++;
		}
	}
	GRegex *regex = g_regex_new("[0-9]{1,}",G_REGEX_EXTENDED,0,NULL);
	if (regex){
		GMatchInfo *match;
		 if (g_regex_match(regex, parameter, 0, &match)) {
        while (g_match_info_matches(match)) {
            char *value = g_match_info_fetch(match, 0);
            yon_char_parsed_add_or_create_if_exists(final, size, value);
            g_free(value);
            g_match_info_next(match, NULL);
        }
    }
		g_match_info_free(match);
	}
    g_regex_unref(regex);
	return final;
}