#include "ubl-settings-usergroups.h"


 
 void on_hash_changed(GtkWidget *, ubl_settings_usergroups_additional_settings_window *window){

	int hash_size=0;
	config_str hash_algos = yon_file_open(hash_list_path,&hash_size);
	for (int i=1;i<hash_size;i++){
			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_widget_set_tooltip_text(window->PasswordHashCombo,parsed[1]);
			yon_char_parsed_free(parsed,parsed_size);
	}
	yon_char_parsed_free(hash_algos,hash_size);
 }

void on_additional_settings_clicked(GtkWidget *, GtkEntry *){
	ubl_settings_usergroups_additional_settings_window *window = yon_ubl_settings_usergroups_additional_settings_new();
    g_signal_connect(G_OBJECT(window->AcceptButton),"clicked",G_CALLBACK(on_subwindow_close),NULL);
    gtk_widget_show(window->Window);

}

gboolean on_encrypt_update(dictionary *dict){
	main_window *widgets = yon_dictionary_get_data(dict->first,main_window*);
	ubl_settings_usergroups_additional_settings_window *window = yon_dictionary_get_data(dict->first->next,ubl_settings_usergroups_additional_settings_window*);
	gtk_widget_destroy(window->Window);
	yon_load_proceed((YON_CONFIG_TYPE)main_config.load_mode);
	yon_interface_update(widgets);
	return G_SOURCE_REMOVE;
}

void *yon_passwords_encrypt(dictionary *dict){
	int exitstatus = system(encrypt_passwords_command);
	if (!exitstatus){
		yon_ubl_status_box_render_thread(yon_char_get_localised_from_lib(SUCCESS_LABEL),BACKGROUND_IMAGE_SUCCESS_TYPE);
		g_idle_add((GSourceFunc)on_encrypt_update,dict);

	} else {
		yon_ubl_status_box_render_thread(yon_char_get_localised_from_lib(FAIL_LABEL),BACKGROUND_IMAGE_SUCCESS_TYPE);

	}
	g_thread_exit(NULL);
}

void on_passwords_encrypt(GtkWidget*,dictionary *dict){
	g_thread_new("encrypt_all_passwords_thread",(GThreadFunc)yon_passwords_encrypt,dict);
}