#include "ubinstall-gtk.h" 
 
config main_config; 
 
//functions 

void on_toggle_button_switch_on(GtkWidget *, GtkToggleButton *toggle){
    gtk_toggle_button_set_active(toggle,1);
}

void on_autohostname_check(GtkWidget *, main_window *widgets){
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->HostnameSensitiveCheck),1);
    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->AutoHostnameCheck))){
        gtk_widget_set_sensitive(widgets->HotnameEntry,0);
        gtk_entry_set_placeholder_text(GTK_ENTRY(widgets->HotnameEntry),"auto");
    }else{
        gtk_widget_set_sensitive(widgets->HotnameEntry,1);
        gtk_entry_set_placeholder_text(GTK_ENTRY(widgets->HotnameEntry),"ublinux-install");
    }
}

void yon_password_set_sensitive_from_toggle(GtkWidget *self, main_window *widgets);
void yon_password_set_sensitive_from_toggle(GtkWidget *self, main_window *widgets){
    GtkWidget *combo = NULL;
    GtkWidget *entry = NULL;
    if (self == widgets->PasswordSensitiveCheck){
        combo = widgets->PasswordCombo;
        entry = widgets->PasswordEntry;
    } else {
        combo = widgets->AdminPasswordCombo;
        entry = widgets->AdminPasswordEntry;
    }
    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(self))){
        gtk_widget_set_sensitive(combo,1);
        if (gtk_combo_box_get_active(GTK_COMBO_BOX(combo))){
            gtk_widget_set_sensitive(entry,1);
        } else {
            gtk_widget_set_sensitive(entry,0);
        }
    } else {
        gtk_widget_set_sensitive(combo,0);
        gtk_widget_set_sensitive(entry,0);
        
    }
}

void yon_password_combo_set_sensitive(GtkWidget *self, main_window *widgets);
void yon_password_combo_set_sensitive(GtkWidget *self, main_window *widgets){
    GtkWidget *entry = NULL;
    GtkWidget *toggle = NULL; 
    if (self == widgets->PasswordCombo){
        entry = widgets->PasswordEntry;
        toggle = widgets->PasswordSensitiveCheck;
    } else if (self == widgets->AdminPasswordCombo){
        entry = widgets->AdminPasswordEntry;
        toggle = widgets->RootPasswordSensitiveCheck;
    }
    if (gtk_combo_box_get_active(GTK_COMBO_BOX(self))&&gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toggle))){
        gtk_widget_set_sensitive(entry,1);
    } else {
        gtk_widget_set_sensitive(entry,0);

    }
}

void on_autohostname_sensitiveness_check(GtkWidget *, main_window *widgets){
    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->HostnameSensitiveCheck))){
        gtk_widget_set_sensitive(widgets->AutoHostnameCheck,1);
        if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->AutoHostnameCheck))){
            gtk_widget_set_sensitive(widgets->HotnameEntry,0);
        } else 
            gtk_widget_set_sensitive(widgets->HotnameEntry,1);
    } else {
            gtk_widget_set_sensitive(widgets->HotnameEntry,0);
            gtk_widget_set_sensitive(widgets->AutoHostnameCheck,0);
    }
}

void on_hostname_entry_changed (GtkWidget *, main_window *widgets){
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->HostnameSensitiveCheck),1);
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->AutoHostnameCheck),0);
} 

void _yon_saving_threaded(char *final_command);
void _yon_saving_threaded(char *final_command){
    FILE *file = popen(final_command,"r");
    int file_save;
    config_str file_return = yon_config_load_file(file,&file_save);
    pclose(file);
    file_return = yon_char_parsed_append(file_return,&file_save,final_command);
    char *result = yon_char_parsed_to_string(file_return,file_save,"");
    yon_debug_output("%s\n",result);
    yon_char_parsed_free(file_return,file_save);
    free(result);
}

char *yon_save_command_prepare(char *command, char *target){
    int size;
    config_str parsed = yon_char_parse(command,&size," ");
    free(parsed[2]);
    parsed[2]=yon_char_new(target);
    free(parsed[3]);
    parsed[3]=yon_char_new("set");
    for (int i=5;i<size;i++){
        char * cur = yon_config_get_by_key(parsed[i]);
        char *full_value = yon_char_unite(parsed[i],"='",cur,"'",NULL);
        free(parsed[i]);
        parsed[i]=full_value;
    }
    char *final = yon_char_parsed_to_string(parsed,size," ");
    yon_char_parsed_free(parsed,size);
    return final;

}

void yon_save_proceed(char *path, YON_CONFIG_TYPE type);
void yon_save_proceed(char *path, YON_CONFIG_TYPE type){
        yon_debug_output("%s\n",yon_config_save_simple(type,path));
}
 
void yon_load_proceed(YON_CONFIG_TYPE type);
void yon_load_proceed(YON_CONFIG_TYPE type){ 
    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="";
		GtkWidget *dialog = gtk_file_chooser_dialog_new(TITLE_LABEL,NULL,GTK_FILE_CHOOSER_ACTION_SAVE,CANCEL_LABEL,GTK_RESPONSE_CANCEL,OPEN_LABEL,GTK_RESPONSE_ACCEPT,NULL);
        yon_gtk_window_setup(GTK_WINDOW(dialog),NULL,TITLE_LABEL,icon_path,"FileChooserWindow");
        textdomain(LocaleName);
        gtk_window_set_icon_name(GTK_WINDOW(dialog),"com.ublinux.ubinstall");
        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=yon_char_unite("'",file,"'",NULL);
                free(file);
			}
			gtk_widget_destroy(dialog);
		} else {
			gtk_widget_destroy(dialog);
		}
		yon_config_load_config(type,yon_config_get_custom_command(path),NULL);
        if (path) free(path);
	}
}

void yon_interface_update(main_window *widgets){
    // gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->RegionSensitiveCheck),0);
    // gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->LanguagesSensitiveCheck),0);
    // gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->MainLanguageSensitiveCheck),0);
    // gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->KeyboardModelSensitiveCheck),0);
    // gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->OptionsSensitiveCheck),0);
    // gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->LayoutSensitiveCheck),0);
    // gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->UsernameSensitiveCheck),0);
    // gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->LoginSensitiveCheck),0);
    // gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->PasswordSensitiveCheck),0);
    // gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->AutologinSensitiveCheck),0);
    // gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->RootPasswordSensitiveCheck),0);
    // gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->HostnameSensitiveCheck),0);
    // gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->CommonFilesystemSensitiveCheck),0);
    // gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->CommonSectionSensitiveCheck),0);
    // gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->NextSizeSensitiveCheck),0);
    // gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->NextFSTypeSensitiveCheck),0);
    // gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->NextLabelSensitiveCheck),0);
    // gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->SameFSTypeSensitiveCheck),0);
    // gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->SameLabelSensitiveCheck),0);
    if (widgets){};
    enum YON_PAGES page=YON_PAGE_COMPLETED;
    char *type = config(AUTOINSTALL_TYPE_INSTALL);
    if (!yon_char_is_empty(type)){
        if (!strcmp(type,"fast")){
            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->InstallationRadio),1);
            page = YON_PAGE_INSTALL_COMMON;
        } else if (!strcmp(type,"next")){
            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->InstallationNearRadio),1);
            page = YON_PAGE_INSTALL_SEPARATE;
        } else if (!strcmp(type,"part")){
            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->InstallationLinuxRadio),1);
            page = YON_PAGE_INSTALL_SAME_PARTITION;
        } else if (!strcmp(type,"grub_install")){
            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->InstallationWindowsRadio),1);
            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->GrubInstallRadio),1);
            page = YON_PAGE_OPTIONS_GRUB_INSTALL;
        } else if (!strcmp(type,"grub_update")){
            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->InstallationWindowsRadio),1);
            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->GrubUpdateRadio),1);
            page = YON_PAGE_OPTIONS_GRUB_UPDATE;
        } else if (!strcmp(type,"system_only")){
            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->InstallationWindowsRadio),1);
            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->OSRadio),1);
            page = YON_PAGE_OPTIONS_OS_ONLY;
        } else if (!strcmp(type,"data_only")){
            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->InstallationWindowsRadio),1);
            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->UserDataOnlyRadio),1);
            page = YON_PAGE_OPTIONS_USRDATA_ONLY;
        } else if (!strcmp(type,"custom")){
            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->InstallationWindowsRadio),1);
            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->SeparateRadio),1);
            page = YON_PAGE_OPTIONS_SEPARATE;
        }
    }

    char *device = config(AUTOINSTALL_DEVICE);
    char *part = NULL;
    if (page!=YON_PAGE_INSTALL_COMMON)
    part = config(part_parameter);

    char *fs_type = config(part_type_parameter);
    char *device_label = config(device_label_parameter);
    char *format = config(device_format_parameter);
    char *part_size = config(part_size_parameter);

    GtkListStore *device_list = widgets->DevicesList;
    GtkListStore *part_list=widgets->PartitionsList;
    GtkWidget *device_tree=NULL;
    GtkWidget *part_tree=NULL;
    switch (page){
        case YON_PAGE_INSTALL_COMMON:{
            device_tree = widgets->CommonInstallationDevicesTree;
        } break;
        case YON_PAGE_INSTALL_SEPARATE:{
            device_tree = widgets->InstallationNearSysDevicesTree;
            part_tree = widgets->InstallationNearSysSectionTree;
            if (!yon_char_is_empty(part_size)){
                gtk_spin_button_set_value(GTK_SPIN_BUTTON(widgets->InstallationNearSizeSpin),atof(part_size));
                if (part_size[strlen(part_size)-1]=='M') gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->InstallationNearSizeTypeSpin),0);
                if (part_size[strlen(part_size)-1]=='G') gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->InstallationNearSizeTypeSpin),1);
                if (part_size[strlen(part_size)-1]=='T') gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->InstallationNearSizeTypeSpin),2);
            }
            if (format&&!strcmp(format,"yes")) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->NextInstallationFormatCheck),1);
            else  gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->NextInstallationFormatCheck),main_config.format_default);
            if (!yon_char_is_empty(fs_type))
            gtk_combo_box_set_active_id(GTK_COMBO_BOX(widgets->NextInstallationFilesystemTypeCombo),fs_type);
            if (device_label)
            gtk_entry_set_text(GTK_ENTRY(widgets->NextInstallationSectionNameEntry),device_label);
            else 
            gtk_entry_set_text(GTK_ENTRY(widgets->NextInstallationSectionNameEntry),"");

        } break;
        case YON_PAGE_INSTALL_SAME_PARTITION:{
            device_tree = widgets->SamePlaceDeviceTree;
            part_tree = widgets->SamePlacePartTree;
            if (!yon_char_is_empty(fs_type))
                gtk_combo_box_set_active_id(GTK_COMBO_BOX(widgets->SameInstallationFilesystemTypeCombo),fs_type);
            if (format&&!strcmp(format,"yes")) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->SameInstallationFormatCheck),1);
            else  gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->SameInstallationFormatCheck),main_config.format_default);
            if (device_label)
                gtk_entry_set_text(GTK_ENTRY(widgets->SameInstallationSectionNameEntry),device_label);
                else 
                gtk_entry_set_text(GTK_ENTRY(widgets->SameInstallationSectionNameEntry),"");

        } break;
        case YON_PAGE_OPTIONS_GRUB_INSTALL:{
            device_tree = widgets->GrubInstallDevicesTree;
        } break;
        case YON_PAGE_OPTIONS_GRUB_UPDATE:{
            device_tree = widgets->GrubUpdateDevicesTree;
        } break;
        case YON_PAGE_OPTIONS_SEPARATE:{
            GtkTreeIter iter;
            device_tree = widgets->SeparateDevicesTree;
            part_tree = widgets->SeparateSysSectionTree;
            for_iter(GTK_TREE_MODEL(device_list),&iter){
                char *cur_device;
                gtk_tree_model_get(GTK_TREE_MODEL(device_list),&iter, 0,&cur_device,-1);
                if (!strcmp(cur_device,device)){
                    gtk_tree_selection_select_iter(gtk_tree_view_get_selection(GTK_TREE_VIEW(device_tree)),&iter);
                    break;
                }
            }
            on_near_installation_device_changed(device_tree,widgets);
            for_iter(GTK_TREE_MODEL(part_list),&iter){
                char *cur_part;
                gtk_tree_model_get(GTK_TREE_MODEL(device_list),&iter, 0,&cur_part,-1);
                if (!strcmp(cur_part,part)){
                    gtk_tree_selection_select_iter(gtk_tree_view_get_selection(GTK_TREE_VIEW(part_tree)),&iter);
                }
            }
        } break;
        case YON_PAGE_OPTIONS_OS_ONLY:{
            device_tree = widgets->OSDevicesTree;
            part_tree = widgets->OSSysSectionTree;
        } break;
        case YON_PAGE_OPTIONS_USRDATA_ONLY:{
            device_tree = widgets->UserdataDevicesTree;
            part_tree = widgets->UserdataSysSectionTree;
        } break;
        default:{}break;
    }





    GtkTreeIter iter;
    char *cur_device="";
    if (page!=YON_PAGE_OPTIONS_SEPARATE && !yon_char_is_empty(device)){
        for_iter (widgets->DevicesList,&iter){
            gtk_tree_model_get(GTK_TREE_MODEL(widgets->DevicesList),&iter,0,&cur_device,-1);
            if (!strcmp(device,cur_device)){
                gtk_tree_selection_select_iter(gtk_tree_view_get_selection(GTK_TREE_VIEW(device_tree)),&iter);
                break;
            }
        }
        on_near_installation_device_changed(device_tree,widgets);
        if (!yon_char_is_empty(part)){
            for_iter (widgets->PartitionsList,&iter){
                gtk_tree_model_get(GTK_TREE_MODEL(widgets->PartitionsList),&iter,0,&part,-1);
                if (!strcmp(device,cur_device)){
                    gtk_tree_selection_select_iter(gtk_tree_view_get_selection(GTK_TREE_VIEW(part_tree)),&iter);
                    break;
                }
            }
        }
    }


    char *system_locale = config(locale_parameter);
    if (!yon_char_is_empty(system_locale)){
        char *chosen_langs = "";
    for_iter(widgets->LanguagesList,&iter){
        char *cur=NULL, *render = NULL;
        gtk_tree_model_get(GTK_TREE_MODEL(widgets->LanguagesList),&iter,1,&render,2,&cur,-1);
        if (strstr(system_locale,cur)){
            gtk_list_store_set((widgets->LanguagesList),&iter,0,1,-1);
            chosen_langs = yon_char_unite(chosen_langs,!yon_char_is_empty(chosen_langs)?";":"",render,NULL);
        } else {
            gtk_list_store_set((widgets->LanguagesList),&iter,0,0,-1);
        }
    }
    if (!yon_char_is_empty(chosen_langs)){
        gtk_entry_set_text(GTK_ENTRY(widgets->AvailableLanguagesEntry),chosen_langs);
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->LanguagesSensitiveCheck),1);
        free(chosen_langs);
    } else {
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->LanguagesSensitiveCheck),0);
        gtk_entry_set_text(GTK_ENTRY(widgets->AvailableLanguagesEntry),"");
    }
    // gtk_tree_model_filter_refilter(GTK_TREE_MODEL_FILTER(widgets->LanguagesFilter));
    } else {
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->LanguagesSensitiveCheck),0);
        gtk_entry_set_text(GTK_ENTRY(widgets->AvailableLanguagesEntry),"");
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->LanguagesSensitiveCheck),0);
        for_iter(widgets->LanguagesList,&iter){
                gtk_list_store_set((widgets->LanguagesList),&iter,0,0,-1);
        }
        // gtk_tree_model_filter_refilter(GTK_TREE_MODEL_FILTER(widgets->LanguagesFilter));
    }



    char *zone = config(zone_parameter);
    char *region = NULL;
    
    if (!yon_char_is_empty(zone)) region = yon_char_divide_search(zone,"/",-1); else {gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->RegionSensitiveCheck),0);}
    if (!yon_char_is_empty(region)){
        gtk_combo_box_set_active_id(GTK_COMBO_BOX(widgets->RegionCombo),region);
    } else {
        gtk_combo_box_set_active_id(GTK_COMBO_BOX(widgets->RegionCombo),"Europe");
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->RegionSensitiveCheck),0);
    }

    if (!yon_char_is_empty(zone)){
        gtk_combo_box_set_active_id(GTK_COMBO_BOX(widgets->ZoneCombo),zone);
    } else {
        gtk_combo_box_set_active_id(GTK_COMBO_BOX(widgets->ZoneCombo),"Moscow");
    }

    char *language = config(lang_parameter);
    if (!yon_char_is_empty(language)){
        gtk_combo_box_set_active_id(GTK_COMBO_BOX(widgets->LanguageCombo),language);
    } else {
        gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->LanguageCombo),0);
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->MainLanguageSensitiveCheck),0);
    }


    char *kbmodel = config (xkbmodel_parameter);
    char *optinos = config(xkboptions_parameter);
    char *layout = config(xkblayout_parameter);

    if (!yon_char_is_empty(kbmodel)){
        gtk_combo_box_set_active_id(GTK_COMBO_BOX(widgets->KeyboardModelCombo),kbmodel);
    } else {
        gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->KeyboardModelCombo),0);
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->KeyboardModelSensitiveCheck),0);
    
    }

    if (!yon_char_is_empty(optinos)){
        gtk_combo_box_set_active_id(GTK_COMBO_BOX(widgets->LayoutBindingCombo),optinos);
    } else {
        gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->LayoutBindingCombo),0);
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->OptionsSensitiveCheck),0);
    }

    if (!yon_char_is_empty(layout)){
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->ManualLayoutRadio),1);
    for_iter(widgets->LayoutList,&iter){
        char *cur=NULL;
        gtk_tree_model_get(GTK_TREE_MODEL(widgets->LayoutList),&iter,0,&cur,-1);
        if (strstr(layout,cur)){
            gtk_tree_store_set(widgets->LayoutList,&iter,3,1,-1);
        } else {
            gtk_tree_store_set(widgets->LayoutList,&iter,3,0,-1);
        }
    }
    } else {
        for_iter(widgets->LayoutList,&iter){
            char *id;
            gtk_tree_model_get(GTK_TREE_MODEL(widgets->LayoutList),&iter,0,&id,-1);
            if (!strcmp(id,"ru")||!strcmp(id,"us")){
                gtk_tree_store_set(widgets->LayoutList,&iter,3,1,-1);
            } else {
                gtk_tree_store_set((widgets->LayoutList),&iter,3,0,-1);
            }
        }
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->LayoutSensitiveCheck),0);
    }

    char *user_name = config(user_name_parameter);
    char *user_gecos = config(user_gecos_parameter);
    char *user_password = config(user_password_parameter);
    char *root_password = config(root_password_parameter);
    char *autologin = config(autologin_parameter);
    char *hostname = config(hostname_parameter);

    if (!yon_char_is_empty(user_name)){
        gtk_entry_set_text(GTK_ENTRY(widgets->LoginEntry),user_name);
    } else {
        gtk_entry_set_text(GTK_ENTRY(widgets->LoginEntry),"");
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->LoginSensitiveCheck),0);
    }

    if (!yon_char_is_empty(user_gecos)){
        gtk_entry_set_text(GTK_ENTRY(widgets->UserNameEntry),user_gecos);
    } else {
        gtk_entry_set_text(GTK_ENTRY(widgets->UserNameEntry),"");
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->UsernameSensitiveCheck),0);
    }

    if (!yon_char_is_empty(user_password)){
        gtk_entry_set_text(GTK_ENTRY(widgets->PasswordEntry),user_password);
        gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->PasswordCombo),1);
    } else {
        gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->PasswordCombo),0);
        gtk_entry_set_text(GTK_ENTRY(widgets->PasswordEntry),"");
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->PasswordSensitiveCheck),0);
        
    }

    if (!yon_char_is_empty(root_password)){
        gtk_entry_set_text(GTK_ENTRY(widgets->AdminPasswordEntry),root_password);
        gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->AdminPasswordCombo),1);
    } else {
        gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->AdminPasswordCombo),0);
        gtk_entry_set_text(GTK_ENTRY(widgets->AdminPasswordEntry),"");
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->RootPasswordSensitiveCheck),0);
    }
    
    if (!yon_char_is_empty(autologin)){
        if (!strcmp(autologin,"yes"))
            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->AutologinCheck),1);
        else 
            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->AutologinCheck),0);
    } else {
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->AutologinCheck),main_config.autologin_default);
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->AutologinSensitiveCheck),0);
    }

    if (!yon_char_is_empty(hostname)){
        if (strcmp(hostname,"auto")){
            gtk_entry_set_text(GTK_ENTRY(widgets->HotnameEntry),hostname);
            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->AutoHostnameCheck),0);
            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->HostnameSensitiveCheck),1);
        } else{
            gtk_entry_set_text(GTK_ENTRY(widgets->HotnameEntry),"");
            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->AutoHostnameCheck),1);
        }
    } else {
        gtk_entry_set_text(GTK_ENTRY(widgets->HotnameEntry),"");
        g_signal_handlers_block_by_func(G_OBJECT(widgets->AutoHostnameCheck),on_autohostname_check,widgets);
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->AutoHostnameCheck),1);
        g_signal_handlers_unblock_by_func(G_OBJECT(widgets->AutoHostnameCheck),on_autohostname_check,widgets);
            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->HostnameSensitiveCheck),0);
    }

    // if (fs_type) free(fs_type);
    // if (device_label) free(device_label);
    // if (format) free(format);
    // if (part_size) free(part_size);
    // if (user_name) free(user_name);
    // if (user_gecos) free(user_gecos);
    // if (user_password) free(user_password);
    // if (root_password) free(root_password);
    // if (autologin) free(autologin);
    // if (hostname) free(hostname);
    // if (kbmodel) free(kbmodel);
    // if (optinos) free(optinos);
    // if (layout) free(layout);
    // if (language) free(language);
    // if (zone) free(zone);
    // if (system_locale) free(system_locale);
    // if (region) free(region);
    // if (device) free(device);
    // if (part) free(part);
}

void on_config_local_load(GtkWidget *,main_window *widgets);
void on_config_local_load(GtkWidget *,main_window *widgets){
        yon_load_proceed(YON_CONFIG_LOCAL);
        yon_interface_update(widgets);
        main_config.load_mode=1;
}

void on_config_global_load(GtkWidget *,main_window *);
void on_config_global_load(GtkWidget *,main_window *widgets){
        yon_load_proceed(YON_CONFIG_GLOBAL);
        yon_interface_update(widgets);
        main_config.load_mode=0;
}

void on_config_custom_load(GtkWidget *,main_window *);
void on_config_custom_load(GtkWidget *,main_window *widgets){
	yon_load_proceed(YON_CONFIG_CUSTOM);
        yon_interface_update(widgets);
	main_config.load_mode=3;
}

void on_config_global_local_save(GtkWidget *,main_window *widgets);
void on_config_global_local_save(GtkWidget *,main_window *widgets){
    yon_save_proceed(NULL,YON_CONFIG_BOTH);
    gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->Notebook),YON_PAGE_COMPLETED);
}

void on_config_local_save(GtkWidget *,main_window *widgets);
void on_config_local_save(GtkWidget *,main_window *widgets){
    yon_save_proceed("system",YON_CONFIG_LOCAL);
    gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->Notebook),YON_PAGE_COMPLETED);
    
}

void on_config_global_save(GtkWidget *,main_window *widgets);
void on_config_global_save(GtkWidget *,main_window *widgets){
    yon_save_proceed("global",YON_CONFIG_GLOBAL);
    gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->Notebook),YON_PAGE_COMPLETED);
    
}

void on_config_custom_save(GtkWidget *, main_window *widgets);
void on_config_custom_save(GtkWidget *, main_window *widgets){
    char *path = NULL;
    // YON_CONFIG_TYPE type = YON_CONFIG_CUSTOM;
            GtkWidget *dialog = gtk_file_chooser_dialog_new(TITLE_LABEL,NULL,GTK_FILE_CHOOSER_ACTION_SAVE,CANCEL_LABEL,GTK_RESPONSE_CANCEL,SAVE_LABEL,GTK_RESPONSE_ACCEPT,NULL);
            textdomain(TITLE_LABEL);
            GtkFileFilter *filter = gtk_file_filter_new();
            gtk_window_set_icon_name(GTK_WINDOW(dialog),yon_char_append("com.ublinux.",LocaleName));
            gtk_file_filter_add_pattern(filter,"*.ini");
            gtk_file_filter_set_name(filter, "*.ini");
            gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog),filter);
            int response = gtk_dialog_run(GTK_DIALOG(dialog));
            if (response == GTK_RESPONSE_ACCEPT){
                char *file = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
                // char *directory = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(dialog));
                if (!yon_char_is_empty(file)){
                    if (!strstr(file,".ini")) file = yon_char_append(file,".ini");
                    if (access(file,0)!=F_OK){
                        char *command_creation = ubconfig_file_create(file);
                        int a = system(yon_debug_output("%s\n",command_creation));
                        if (access(file,0)!=F_OK||a){
                            yon_ubl_status_box_render(CUSTOM_CONFIG_CREATION_ERROR_LABEL,BACKGROUND_IMAGE_FAIL_TYPE);
                            return;
                        }
                    }
                }
                path = yon_char_unite("'",file,"'",NULL);
                free(file);
                gtk_widget_destroy(dialog);
            } else {
                gtk_widget_destroy(dialog);
                return;
            }
	yon_save_proceed(path,YON_CONFIG_CUSTOM);
    if (path) free(path);
    gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->Notebook),YON_PAGE_COMPLETED);
}

void yon_open_browser(GtkWidget *, char *link);
void yon_open_browser(GtkWidget *, char *link){
    GtkWidget *window = yon_ubl_browser_window_open(link,TITLE_LABEL);
    if (window)
    gtk_window_set_icon_name(GTK_WINDOW(window),yon_char_append("com.ublinux.",LocaleName));
}

void on_open_documentation_confirmation(GtkWidget *self, char *link);
void on_open_documentation_confirmation(GtkWidget *self, char *link){
    if (main_config.always_open_documentation==0){
        GtkBuilder *builder = gtk_builder_new_from_resource(ui_glade_path_documentation);
        documentation_confirmation_window *window = malloc(sizeof(documentation_confirmation_window));
        window->Window = yon_gtk_builder_get_widget(builder,"helpConfirmationWindow");
        window->AcceptButton = yon_gtk_builder_get_widget(builder,"ReadHelpButton");
        window->CloseButton = yon_gtk_builder_get_widget(builder,"CancelHelpButton");
        window->HeaderLabel = yon_gtk_builder_get_widget(builder,"webHeaderNameLabel");
        window->AlwaysOpenCheck = yon_gtk_builder_get_widget(builder,"AlwaysOpenDocumentationCheckbox");
        gtk_label_set_text(GTK_LABEL(window->HeaderLabel),TITLE_LABEL);
        gtk_widget_show_all(window->Window);
        g_signal_connect(G_OBJECT(window->CloseButton),"clicked",G_CALLBACK(on_subwindow_close),NULL);
        g_signal_connect(G_OBJECT(window->AcceptButton),"clicked",G_CALLBACK(yon_open_browser),yon_char_new(link));
        g_signal_connect(G_OBJECT(window->AcceptButton),"clicked",G_CALLBACK(on_subwindow_close),NULL);
        
        
    } else {
        yon_open_browser(self,link);
    }
}

void on_link(GtkWidget *self, char* uri);
void on_link(GtkWidget *self, char* uri){
    gtk_widget_destroy(self);
    on_open_documentation_confirmation(self,uri);
}

void on_about(GtkWidget *);
void on_about(GtkWidget *){
    GtkBuilder *builder=gtk_builder_new_from_resource(ui_glade_path_about);
    GtkWidget *window=yon_gtk_builder_get_widget(builder,"AboutWindow");
    GtkWidget *title=yon_gtk_builder_get_widget(builder,"headerAboutTopic");
    GtkWidget *hideButtonBox=yon_gtk_builder_get_widget(builder,"buttonBoxHide");
    gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(window),version_application);
    gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(window),TITLE_LABEL);
    gtk_about_dialog_set_logo_icon_name(GTK_ABOUT_DIALOG(window),yon_char_append("com.ublinux.",LocaleName));
    gtk_window_set_icon_name(GTK_WINDOW(window),yon_char_append("com.ublinux.",LocaleName));
    gtk_about_dialog_set_program_name(GTK_ABOUT_DIALOG(window),LocaleName);
    gtk_label_set_text(GTK_LABEL(title),TITLE_LABEL);
    g_signal_connect(G_OBJECT(window),"activate-link",G_CALLBACK(on_link),WIKI_LINK);
    gtk_widget_set_visible(hideButtonBox,0);
    gtk_widget_destroy(hideButtonBox);
    gtk_widget_show(window);
}

double yon_size_long_convert_automatic(unsigned long bytes, char *size);
double yon_size_long_convert_automatic(unsigned long bytes, char *size){
    int repeats;
    double byte_float=bytes;
    for (repeats=-1;byte_float>1024;repeats++){
        byte_float=byte_float/1024;
    }
    if (repeats==-1) {
        repeats=0;
        byte_float=byte_float/1024;
    }
    switch(repeats){
        case 0: (*size)='K';
        break;
        case 1: (*size)='M';
        break;
        case 2: (*size)='G';
        break;
        case 3: (*size)='T';
        break; 
    }
    return byte_float;
}

// standard functions 
 
void on_keyboard_accept(GtkWidget *self,main_window *widgets);
void on_keyboard_accept(GtkWidget *self,main_window *widgets){
    gtk_tree_model_filter_refilter(GTK_TREE_MODEL_FILTER(widgets->LayoutsFilter));
    on_subwindow_close(self);
}

void on_layout_toggle(GtkCellRendererToggle*,  gchar* path, ubinstall_keyboard_window *window);
void on_layout_toggle(GtkCellRendererToggle*,  gchar* path, ubinstall_keyboard_window *window){
    GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(window->LayoutsTree));
    GtkTreeIter iter;
    if (gtk_tree_model_get_iter_from_string(model,&iter,path)){
        int status=0;
        gtk_tree_model_get(model,&iter,3,&status,-1);
        gtk_tree_store_set(GTK_TREE_STORE(model),&iter,3,!status,-1);
    }
}

ubinstall_keyboard_window *yon_ubinstall_keyboard_new(){
	ubinstall_keyboard_window *window = malloc(sizeof(ubinstall_keyboard_window));
	GtkBuilder *builder = gtk_builder_new_from_resource(glade_path_ubinstall_keyboard);
	window->MainWindow=yon_gtk_builder_get_widget(builder,"MainWindow");
	window->StatusBox=yon_gtk_builder_get_widget(builder,"StatusBox");
	window->headerBar=yon_gtk_builder_get_widget(builder,"headerBar");
	window->CancelButton=yon_gtk_builder_get_widget(builder,"CancelButton");
	window->SaveButton=yon_gtk_builder_get_widget(builder,"SaveButton");
	window->LayoutsTree=yon_gtk_builder_get_widget(builder,"LayoutsTree");
    window->ActiveToggle = GTK_CELL_RENDERER(gtk_builder_get_object(builder,"ActiveToggle"));

    g_signal_connect(G_OBJECT(window->CancelButton),"clicked",G_CALLBACK(on_subwindow_close),NULL);

return window;
}

void on_keyboard_clicked (GtkWidget *, main_window *widgets);
void on_keyboard_clicked (GtkWidget *, main_window *widgets){
    ubinstall_keyboard_window *window = yon_ubinstall_keyboard_new();
    yon_gtk_window_setup(GTK_WINDOW(window->MainWindow),GTK_WINDOW(widgets->MainWindow),KEYBOARD_TITLE_LABEL,icon_path,"keyboard-window");
    gtk_tree_view_set_model(GTK_TREE_VIEW(window->LayoutsTree),GTK_TREE_MODEL(widgets->LayoutList));

    g_signal_connect(G_OBJECT(window->ActiveToggle),"toggled",G_CALLBACK(on_layout_toggle),window);
    g_signal_connect(G_OBJECT(window->SaveButton),"clicked",G_CALLBACK(on_keyboard_accept),widgets);
    gtk_widget_show(window->MainWindow);
}

void yon_language_selection_changed(GtkCellRenderer *, char *path, ubinstall_language_window *window);
void yon_language_selection_changed(GtkCellRenderer *, char *path, ubinstall_language_window *window){
    GtkTreeIter iter;
    int state;

    if (gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(window->liststore1),&iter,path)){
        gtk_tree_model_get(GTK_TREE_MODEL(window->liststore1),&iter,0,&state,-1);
        gtk_list_store_set(window->liststore1,&iter,0,!state,-1);
    }
}

void on_language_window_accept(GtkWidget *,dictionary *dict);
void on_language_window_accept(GtkWidget *,dictionary *dict){
    main_window *widgets= yon_dictionary_get_data(dict->first,main_window*);
    ubinstall_language_window *window = yon_dictionary_get_data(dict->first->next,ubinstall_language_window*);
    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->DefaultCheck))){
        gtk_entry_set_text(GTK_ENTRY(widgets->AvailableLanguagesEntry),"");
    } else {
        yon_gtk_list_store_copy_full(widgets->LanguagesList,window->liststore1);
        gtk_tree_model_filter_refilter(GTK_TREE_MODEL_FILTER(widgets->LanguagesFilter));
        config_str parsed = NULL;
        int size;
        GtkTreeIter iter;
        for_iter(GTK_TREE_MODEL(window->liststore1),&iter){
            char *current;
            int status;
            gtk_tree_model_get(GTK_TREE_MODEL(window->liststore1),&iter,0,&status,1,&current,-1);
            if (status)
                yon_char_parsed_add_or_create_if_exists(parsed,&size,current);
        }
        char *final = yon_char_parsed_to_string(parsed,size,"; ");
        gtk_entry_set_text(GTK_ENTRY(widgets->AvailableLanguagesEntry),final);
        free(final);
        yon_char_parsed_free(parsed,size);
    }
    on_subwindow_close(window->MainWindow);
    free(window);
}

ubinstall_language_window *yon_ubinstall_language_new(){
	ubinstall_language_window *window = malloc(sizeof(ubinstall_language_window));
	GtkBuilder *builder = gtk_builder_new_from_resource(glade_path_ubinstall_language);
	window->liststore1=GTK_LIST_STORE(gtk_builder_get_object(builder,"liststore1"));
	window->MainWindow=yon_gtk_builder_get_widget(builder,"MainWindow");
	window->StatusBox=yon_gtk_builder_get_widget(builder,"StatusBox");
	window->DefaultCheck=yon_gtk_builder_get_widget(builder,"DefaultCheck");
	window->LanguagesTree=yon_gtk_builder_get_widget(builder,"LanguagesTree");
	window->headerBar=yon_gtk_builder_get_widget(builder,"headerBar");
	window->CancelButton=yon_gtk_builder_get_widget(builder,"CancelButton");
	window->SaveButton=yon_gtk_builder_get_widget(builder,"SaveButton");
	window->ToggleRenderer=GTK_CELL_RENDERER(gtk_builder_get_object(builder,"ToggleRenderer"));

    g_signal_connect(G_OBJECT(window->DefaultCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button_inversed),window->LanguagesTree);
    g_signal_connect(G_OBJECT(window->ToggleRenderer),"toggled",G_CALLBACK(yon_language_selection_changed),window);
    g_signal_connect(G_OBJECT(window->CancelButton),"clicked",G_CALLBACK(on_subwindow_close),NULL);
return window;
}

void on_language_clicked(GtkWidget *, main_window *widgets);
void on_language_clicked(GtkWidget *, main_window *widgets){
    ubinstall_language_window *window = yon_ubinstall_language_new();
    g_object_ref(G_OBJECT(window->liststore1));
    gtk_tree_view_set_model(GTK_TREE_VIEW(window->LanguagesTree),NULL);
    yon_gtk_list_store_copy_full(window->liststore1,widgets->LanguagesList);
    gtk_tree_view_set_model(GTK_TREE_VIEW(window->LanguagesTree),GTK_TREE_MODEL(window->liststore1));
    yon_gtk_window_setup(GTK_WINDOW(window->MainWindow),GTK_WINDOW(widgets->MainWindow),TITLE_LABEL,icon_path,"language-chooser-window");

    dictionary *dict=NULL;
    yon_dictionary_add_or_create_if_exists_with_data(dict,"widgets",widgets);
    yon_dictionary_add_or_create_if_exists_with_data(dict,"window",window);
    g_signal_connect(G_OBJECT(window->SaveButton),"clicked",G_CALLBACK(on_language_window_accept),dict);
    gtk_widget_show(window->MainWindow);
}
 
/**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.debug_mode=0;
    main_config.slider_thread=0;
    main_config.config_save_thread=NULL;
    main_config.install_thread=0;
    main_config.progress_thread=0;
    main_config.install_complete=0;
    main_config.save_done=0;
    main_config.configure_mode=0;
    main_config.load_mode=-1;
    main_config.log_progress_buzy=0;
    main_config.log_end=0;
    main_config.exit_accepted=0;
}

void on_configuration_mode_switch(GtkWidget *self);
void on_configuration_mode_switch(GtkWidget *self){
    main_config.configure_mode = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(self));
}

int cur_slide=0;

int yon_image_resize_from_container(GtkImage *target, GdkPixbuf *pixbuf_unscaled);
int yon_image_resize_from_container(GtkImage *target, GdkPixbuf *pixbuf_unscaled) {
    int width = gtk_widget_get_allocated_width(gtk_widget_get_parent(gtk_widget_get_parent(GTK_WIDGET(target))));
    int height = gtk_widget_get_allocated_height(gtk_widget_get_parent(gtk_widget_get_parent(GTK_WIDGET(target))));
    
    int newImgWidthDef = (width <= 217) ? width : width - 30;
    int newImgHeightDef = (height <= 120) ? height : height - 217;

    int originalWidth = gdk_pixbuf_get_width(pixbuf_unscaled);
    int originalHeight = gdk_pixbuf_get_height(pixbuf_unscaled);
    int newImgHeight = (int)(originalHeight / ((double) originalWidth / newImgWidthDef));
    
    if (newImgHeight > newImgHeightDef) {
        newImgHeight = newImgHeightDef;
        newImgWidthDef = (int)(originalWidth / ((double) originalHeight / newImgHeight));
    }
    int newImageWidth = (int)(originalWidth / ((double) originalHeight / newImgHeight));

    GdkPixbuf *scaledPixBuf = gdk_pixbuf_scale_simple(pixbuf_unscaled, newImageWidth, newImgHeight, GDK_INTERP_BILINEAR);
    gtk_image_set_from_pixbuf(target, scaledPixBuf);

    g_object_unref(scaledPixBuf); // Освобождаем память, занятую скалированным изображением

    return 1;
}

void on_region_resized(GtkWidget *,main_window *widgets);
void on_region_resized(GtkWidget *,main_window *widgets){
            yon_image_resize_from_container(GTK_IMAGE(widgets->SlidesImage), widgets->slides_original[cur_slide]);
            yon_image_resize_from_container(GTK_IMAGE(widgets->RegionImage), widgets->regions_original);
            yon_image_resize_from_container(GTK_IMAGE(widgets->KeyboardImage), widgets->keyboard_original);
}

void on_toggle_block(GtkToggleButton *self);
void on_toggle_block(GtkToggleButton *self){
    int state = gtk_toggle_button_get_active(self);
    g_signal_handlers_block_by_func(G_OBJECT(self),on_toggle_block,NULL);
    gtk_toggle_button_set_active(self,!state);
    g_signal_handlers_unblock_by_func(G_OBJECT(self),on_toggle_block,NULL);
}

void yon_switch_page_render(main_window *widgets, int page);
void yon_switch_page_render(main_window *widgets, int page){
    GtkContainer *parent = GTK_CONTAINER(gtk_widget_get_parent(widgets->UsersToggle));
    GList *list = gtk_container_get_children(parent);
    for (guint i=0;i<g_list_length(list);i++){
        if (i!=(guint)page){
            g_signal_handlers_block_by_func(G_OBJECT(g_list_nth_data(list,i)),on_toggle_block,NULL);
                    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g_list_nth_data(list,i)),0);
            g_signal_handlers_unblock_by_func(G_OBJECT(g_list_nth_data(list,i)),on_toggle_block,NULL);
                } else { 
            g_signal_handlers_block_by_func(G_OBJECT(g_list_nth_data(list,i)),on_toggle_block,NULL);
                    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g_list_nth_data(list,i)),1);
            g_signal_handlers_unblock_by_func(G_OBJECT(g_list_nth_data(list,i)),on_toggle_block,NULL);
                
        }
    }
    g_list_free(list);
}

gboolean on_image_slide(void *data);
gboolean on_image_slide(void *data){
    main_window *widgets = (main_window*)data;
    int size;
    config_str target = yon_char_parsed_new(&size,slide_repeat_path);
    if (size)
        yon_char_parsed_free(target,size);
    gtk_image_set_from_pixbuf(GTK_IMAGE(widgets->SlidesImage),widgets->slides_original[cur_slide]);
    gtk_widget_queue_draw(widgets->SlidesImage);
    if (cur_slide<size-1) cur_slide++; else cur_slide=1;
    return 1;
}

char* yon_debug_output(char *pattern,char*text){
    if (main_config.debug_mode){
        printf(pattern,text);
    }
    return text;
}

void *on_config_save(void *data);
void *on_config_save(void *data){
    main_window *widgets = (main_window*)data;

        int size=0;
        config_str parameters = yon_config_get_all(&size);
        // main_config.install_thread=(GThread*)0x1;
        FILE *file = fopen(progress_path,"w");
        if (file)
            fclose(file);
        char *command = save_config_command(yon_char_parsed_to_string(parameters,size," "));
        yon_char_parsed_free(parameters,size);
        if (system(yon_debug_output("%s\n",command))){
            gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->Notebook),YON_PAGE_INSTALL_ERROR);
        };
        free(command);
        main_config.install_thread=0;
        main_config.install_complete=1;
        yon_debug_output("Install set to: %s\n",yon_char_from_int(main_config.install_complete));
        yon_debug_output("Save state: %s\n",yon_char_from_int(main_config.save_done));
            if (main_config.save_done){
                gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->Notebook),YON_PAGE_COMPLETION);
            }
        main_config.config_save_thread=NULL;
    pthread_exit(NULL);
}

gboolean yon_installation_progress_update(void *data);
gboolean yon_installation_progress_update(void *data) {
    main_window *widgets = (main_window*)data;
    int size;

    while (main_config.log_progress_buzy) {
        while (gtk_events_pending()) gtk_main_iteration();
    }
    main_config.log_progress_buzy = 1;
    config_str text = yon_file_open(progress_path, &size);
    main_config.log_progress_buzy = 0;

    if (size) {
        if (!yon_char_is_empty(text[size-1]) && text[size-1][0] == '(') {
            char *current_copy = yon_char_new(text[size-1]);
            char *percentage = yon_char_divide_search(current_copy, ")", -1);
            yon_char_parsed_free(text, size);

            if (!strstr(percentage, "#pb")) {
                double fraction = atof(percentage+1);
                gtk_label_set_text(GTK_LABEL(widgets->InstallationLabel), current_copy);
                gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(widgets->InstallationProgress), fraction / 100);
                gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(widgets->PackageInstallationProgress), 0);
                gtk_label_set_text(GTK_LABEL(widgets->PackageInstallationLabel), "");
            } else {
                gtk_widget_show(gtk_widget_get_parent(widgets->PackageInstallationProgress));

                config_str parsed = yon_char_parse(current_copy, &size, " ");
                if (size >= 3) {
                    double fraction = atof(parsed[2]) / 100;
                    gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(widgets->PackageInstallationProgress), fraction);
                    gtk_label_set_text(GTK_LABEL(widgets->PackageInstallationLabel), yon_char_parsed_to_string(parsed, size, " "));
                }
                yon_char_parsed_free(parsed, size);
            }

            free(current_copy);
            free(percentage);
        }
    }

    if (main_config.install_thread) {
        return 1;
    } else {
        gtk_label_set_text(GTK_LABEL(widgets->PackageInstallationLabel), "");
        return 0;
    }
}

void on_page_changed(GtkWidget *,GtkWidget *,int page, main_window *widgets);
void on_page_changed(GtkWidget *,GtkWidget *,int page, main_window *widgets){
    switch(page){
        case YON_PAGE_WELCOME: {
            gtk_widget_hide(widgets->SaveButton);
            gtk_widget_set_sensitive(widgets->CancelInstallButton,0);
            gtk_widget_set_sensitive(widgets->BackButton,0);
            gtk_widget_set_sensitive(widgets->NextButton,1);
            gtk_button_set_label(GTK_BUTTON(widgets->NextButton),NEXT_LABEL);
            gtk_button_set_label(GTK_BUTTON(widgets->CancelInstallButton),CANCEL_LABEL);
            gtk_image_set_from_icon_name(GTK_IMAGE(gtk_button_get_image(GTK_BUTTON(widgets->NextButton))),"com.ublinux.ubinstall-gtk.arrow-right-symbolic",GTK_ICON_SIZE_BUTTON);
            gtk_image_set_from_icon_name(GTK_IMAGE(gtk_button_get_image(GTK_BUTTON(widgets->CancelInstallButton))),"com.ublinux.ubinstall-gtk.circle-exit-symbolic",GTK_ICON_SIZE_BUTTON);
            gtk_widget_set_sensitive(widgets->ConfigurationModeMenuItem,1);
            yon_switch_page_render(widgets,0);
        } break;

        case YON_PAGE_LICENCE:{
            gtk_widget_set_sensitive(widgets->CancelInstallButton,1);
            gtk_widget_set_sensitive(widgets->BackButton,1);
            yon_switch_page_render(widgets,1);
        } break;

        case YON_PAGE_REGION: {
                yon_image_resize_from_container(GTK_IMAGE(widgets->RegionImage), widgets->regions_original);
                yon_switch_page_render(widgets,4);
        } break;

        case YON_PAGE_KEYBOARD: {

            yon_switch_page_render(widgets,5);
            yon_image_resize_from_container(GTK_IMAGE(widgets->KeyboardImage), widgets->keyboard_original);
        } break;

        case YON_PAGE_OS_COMPONENTS:
        case YON_PAGE_SOFTWARE:
        case YON_PAGE_INSTALLATION_BEGIN:
            yon_switch_page_render(widgets,3);

        break;
        case YON_PAGE_INSTALLATION:{
            yon_switch_page_render(widgets,3);
            gtk_widget_set_sensitive(widgets->BackButton,0);
            if ((!main_config.configure_mode))
                gtk_widget_set_sensitive(widgets->CancelInstallButton,0);
            if (main_config.config_save_thread&&!main_config.configure_mode)
                g_thread_join(main_config.config_save_thread);
            if (!main_config.progress_thread&&!main_config.configure_mode)
                main_config.progress_thread = gdk_threads_add_timeout(500,(GSourceFunc)yon_installation_progress_update,widgets);
            
            if (!main_config.slider_thread&&!main_config.configure_mode)
            main_config.slider_thread = g_timeout_add(5000,(GSourceFunc)on_image_slide,widgets);
            gtk_widget_show(gtk_widget_get_parent(widgets->InstallationProgress));
        } break;

        case YON_PAGE_USERS:
            yon_switch_page_render(widgets,6);
            gtk_widget_set_sensitive(widgets->NextButton,1);
            gtk_widget_hide(widgets->SaveButton);
            break;

        case YON_PAGE_INSTALL_ERROR:{
            on_summary_log_view((GtkWidget*)NULL,widgets);
            
            yon_switch_page_render(widgets,7);
            gtk_widget_set_sensitive(widgets->BackButton,0);
            gtk_widget_hide(gtk_widget_get_parent(widgets->PackageInstallationProgress));
            gtk_widget_hide(widgets->InstallationLabel);
            gtk_widget_hide(widgets->PackageInstallationLabel);
            gtk_widget_set_sensitive(widgets->NextButton,1);
            gtk_widget_set_sensitive(widgets->CancelInstallButton,1);
            main_config.install_complete=0;
            main_config.save_done=0;
            gtk_button_set_label(GTK_BUTTON(widgets->NextButton),RESTART_LABEL);
            gtk_button_set_label(GTK_BUTTON(widgets->CancelInstallButton),EXIT_LABEL);
            gtk_image_set_from_icon_name(GTK_IMAGE(gtk_button_get_image(GTK_BUTTON(widgets->NextButton))),
            "com.ublinux.ubinstall-gtk.sync-symbolic",GTK_ICON_SIZE_BUTTON);

        } break;
        case YON_PAGE_COMPLETION:{
            yon_switch_page_render(widgets,7);
            gtk_widget_set_sensitive(widgets->BackButton,0);
            gtk_widget_hide(gtk_widget_get_parent(widgets->PackageInstallationProgress));
            gtk_widget_hide(widgets->InstallationLabel);
            gtk_widget_hide(widgets->PackageInstallationLabel);
            gtk_widget_set_sensitive(widgets->NextButton,1);
            gtk_widget_set_sensitive(widgets->CancelInstallButton,1);
            main_config.install_complete=0;
            main_config.save_done=0;
            gtk_button_set_label(GTK_BUTTON(widgets->NextButton),RESTART_LABEL);
            gtk_button_set_label(GTK_BUTTON(widgets->CancelInstallButton),EXIT_LABEL);
            gtk_image_set_from_icon_name(GTK_IMAGE(gtk_button_get_image(GTK_BUTTON(widgets->NextButton))),
            "com.ublinux.ubinstall-gtk.sync-symbolic",GTK_ICON_SIZE_BUTTON);
            }
            break;

            case YON_PAGE_COMPLETED:{
            yon_switch_page_render(widgets,7);
            gtk_widget_set_sensitive(widgets->BackButton,1);
            gtk_widget_hide(gtk_widget_get_parent(widgets->PackageInstallationProgress));
            gtk_widget_hide(widgets->InstallationLabel);
            gtk_widget_hide(widgets->PackageInstallationLabel);
            gtk_widget_set_sensitive(widgets->NextButton,0);
            gtk_widget_set_sensitive(widgets->CancelInstallButton,1);
            main_config.install_complete=0;
            main_config.save_done=0;
            gtk_button_set_label(GTK_BUTTON(widgets->CancelInstallButton),EXIT_LABEL);
            gtk_image_set_from_icon_name(GTK_IMAGE(gtk_button_get_image(GTK_BUTTON(widgets->NextButton))),
            "com.ublinux.ubinstall-gtk.sync-symbolic",GTK_ICON_SIZE_BUTTON);

            }break;

        case YON_PAGE_SECTIONS:
        case YON_PAGE_INSTALL_COMMON:
        case YON_PAGE_INSTALL_SEPARATE:
        case YON_PAGE_INSTALL_SAME_PARTITION:
        case YON_PAGE_INSTALL_OPTIONS:
        case YON_PAGE_OPTIONS_GRUB_INSTALL:
        case YON_PAGE_OPTIONS_GRUB_UPDATE:
        case YON_PAGE_OPTIONS_SEPARATE:
        case YON_PAGE_OPTIONS_SEPARATE_USRDATA:
        case YON_PAGE_OPTIONS_OS_ONLY:
        case YON_PAGE_OPTIONS_USRDATA_ONLY: {
            yon_switch_page_render(widgets,2);
        } break;
        case YON_PAGE_CONFIGURE_END: {
            gtk_widget_set_sensitive(widgets->BackButton,1);
            gtk_widget_set_sensitive(widgets->NextButton,0);
            gtk_widget_set_sensitive(widgets->CancelInstallButton,1);
            gtk_widget_show(widgets->SaveButton);
        }
    }
}

void *on_setup_system_configuration(void *data);
void *on_setup_system_configuration(void * data){
    main_window *widgets = (main_window*)data;
    if (widgets){};
    int size;
    config_str all_parameters = yon_config_get_selection_by_key(&size,
    user_name_parameter,
    user_gecos_parameter,
    user_password_parameter,
    root_password_parameter,
    autologin_parameter,
    xkbmodel_parameter,
    xkblayout_parameter,
    xkbvariant_parameter,
    xkboptions_parameter,
    hostname_parameter,
    zone_parameter,
    lang_parameter,
    locale_parameter,
    NULL);
    if (all_parameters){
        char *parameter_string = yon_char_parsed_to_string(all_parameters,size," ");
        char *command = set_user_config_command(parameter_string);
        if (system(yon_debug_output("$s\n",command))){};
        yon_char_parsed_free(all_parameters,size);
        free(command);
        if (parameter_string) free(parameter_string);
    }
    return NULL;
}

void on_log_closed(GtkWidget *, dictionary *dict);
void on_log_closed(GtkWidget *, dictionary *dict){
    main_window *widgets = yon_dictionary_get_data(dict->first,main_window*);
    log_window *window = yon_dictionary_get_data(dict->first->next,log_window*);

    gtk_widget_set_sensitive(widgets->ReadFullLogButton,1);
    gtk_widget_set_sensitive(widgets->ReadShortLogButton,1);

    free(window->command);
    window->Window=NULL;
}

void *on_save_system_configuration(void *data);
void *on_save_system_configuration(void * data){
    main_window *widgets = (main_window*)data;
    if (widgets){};
    int size;
    config_str all_parameters = yon_config_get_selection_by_key(&size,
    user_name_parameter,
    user_gecos_parameter,
    user_password_parameter,
    root_password_parameter,
    autologin_parameter,
    xkbmodel_parameter,
    xkblayout_parameter,
    xkbvariant_parameter,
    xkboptions_parameter,
    hostname_parameter,
    zone_parameter,
    lang_parameter,
    locale_parameter,
    NULL);
    if (all_parameters){
        char *parameter_string = yon_char_parsed_to_string(all_parameters,size," ");
        char *command = save_additional_config_command(parameter_string);
        if (system(yon_debug_output("%s\n",command))){};
        yon_char_parsed_free(all_parameters,size);
        free(command);
        if (parameter_string) free(parameter_string);
    }
    return NULL;
}

log_window *yon_log_window_new();
log_window *yon_log_window_new(){
    log_window *window = malloc(sizeof(log_window));
    GtkBuilder *builder = gtk_builder_new_from_resource(glade_path_log_view);
    window->Window = yon_gtk_builder_get_widget(builder,"MainWindow");
    window->ScrollWindow = yon_gtk_builder_get_widget(builder,"ScrollWindow");
    window->HeadLabel = yon_gtk_builder_get_widget(builder,"headerTopic");
    window->LogLabel = yon_gtk_builder_get_widget(builder,"LogLabel");
    window->StatusBox = yon_gtk_builder_get_widget(builder,"StatusBox");
    window->ScrollToEndCheck = yon_gtk_builder_get_widget(builder,"ScrollToEndCheck");
    gtk_widget_show(window->Window);
    return window;
}

gboolean yon_read_log(void *data);
gboolean yon_read_log(void *data){
log_window *window = (log_window*)data;
if (window->Window){
    int size;
    while (!main_config.install_complete&&main_config.log_progress_buzy){};
    main_config.log_progress_buzy=1;
    config_str parsed = yon_file_open(window->command,&size);
    main_config.log_progress_buzy=0;
    if (size){
        char *final = yon_char_parsed_to_string(parsed,size,"");
        gtk_label_set_text(GTK_LABEL(window->LogLabel),final);
        if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->ScrollToEndCheck))){
            gtk_adjustment_set_value(gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(window->ScrollWindow)),gtk_adjustment_get_upper(gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(window->ScrollWindow))));
        }
        free(final);
        yon_char_parsed_free(parsed,size);
    }
    return 1;
}
return 0;
}

void on_process_log_view(GtkWidget *,main_window *widgets);
void on_process_log_view(GtkWidget *,main_window *widgets){
    log_window *window = yon_log_window_new();
    dictionary *dict=NULL;
    yon_dictionary_add_or_create_if_exists_with_data(dict,"widgets",widgets);
    yon_dictionary_add_or_create_if_exists_with_data(dict,"window",window);
    g_signal_connect(G_OBJECT(window->Window),"destroy",G_CALLBACK(on_log_closed),dict);
    gtk_widget_set_sensitive(widgets->ReadFullLogButton,0);
    gtk_widget_set_sensitive(widgets->ReadShortLogButton,0);
    yon_gtk_window_setup(GTK_WINDOW(window->Window),NULL,INSTALL_LOG_LABEL,icon_path,"log_viewer");
    window->command = yon_char_new(short_log_path);
    gdk_threads_add_timeout(500,(GSourceFunc)yon_read_log,window);
}

void on_summary_log_view(GtkWidget *,main_window *widgets){
    log_window *window = yon_log_window_new();
    dictionary *dict=NULL;
    yon_dictionary_add_or_create_if_exists_with_data(dict,"widgets",widgets);
    yon_dictionary_add_or_create_if_exists_with_data(dict,"window",window);
    g_signal_connect(G_OBJECT(window->Window),"destroy",G_CALLBACK(on_log_closed),dict);
    gtk_widget_set_sensitive(widgets->ReadFullLogButton,0);
    gtk_widget_set_sensitive(widgets->ReadShortLogButton,0);
    yon_gtk_window_setup(GTK_WINDOW(window->Window),NULL,PROGRESS_LOG_LABEL,icon_path,"log_viewer");
    window->command = yon_char_new(full_log_path);
    gdk_threads_add_timeout(500,(GSourceFunc)yon_read_log,window);

}

void yon_install_options_save(GtkWidget *device_tree, GtkWidget *part_tree,char *mode,main_window *widgets);
void yon_install_options_save(GtkWidget *device_tree, GtkWidget *part_tree,char *mode,main_window *widgets){
    GtkTreeIter iter,itar;
    GtkTreeModel *model,*model2;
    if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(device_tree)),&model,&iter)){
        if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(part_tree)),&model2,&itar)){
            char *cur_device, *cur_section;
            gtk_tree_model_get(model,&iter,0,&cur_device,-1);
            gtk_tree_model_get(model2,&itar,0,&cur_section,-1);
            yon_config_register(AUTOINSTALL_DEVICE,AUTOINSTALL_DEVICE_command,cur_device);
            yon_config_register(AUTOINSTALL_TYPE_INSTALL,AUTOINSTALL_TYPE_INSTALL_command,mode);
            yon_config_register(part_parameter,part_parameter_command,cur_section);

            if(cur_section) free(cur_section); 
            if(cur_device) free(cur_device); 
            if (!main_config.configure_mode)
                gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->Notebook),YON_PAGE_INSTALLATION_BEGIN);
            else 
                gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->Notebook),YON_PAGE_REGION);
        } else {
            yon_ubl_status_box_spawn(GTK_CONTAINER(widgets->StatusBox),NO_DEVICE_CHOSEN_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE);
            yon_ubl_status_highlight_incorrect(part_tree);
        }
    } else {
        yon_ubl_status_box_spawn(GTK_CONTAINER(widgets->StatusBox),NO_DEVICE_CHOSEN_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE);
        yon_ubl_status_highlight_incorrect(device_tree);
    }
}

void on_page_navigation_clicked(GtkWidget *self, main_window *widgets);
void on_page_navigation_clicked(GtkWidget *self, main_window *widgets){
    int mode = self==widgets->NextButton ? 1 : self == widgets->BackButton ? -1 : self==widgets->CancelInstallButton?-2:0;
    int page = gtk_notebook_get_current_page(GTK_NOTEBOOK(widgets->Notebook));
    switch (mode){
        case 1: { // Next
            switch (page){
                case YON_PAGE_WELCOME:{
                    gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->Notebook),YON_PAGE_LICENCE);
                    gtk_widget_set_sensitive(widgets->ConfigurationModeMenuItem,0);
                } break;

                case YON_PAGE_SECTIONS:{ //sections
                    int active_id=-1;
                    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->InstallationRadio)))
                        active_id=0;
                    else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->InstallationNearRadio)))
                        active_id=1;
                    else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->InstallationLinuxRadio)))
                        active_id=2;
                    else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->InstallationWindowsRadio)))
                        active_id=3;
                    // else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->InstallationRadio)))
                    //     active_id=4;
                    main_config.install_mode=active_id;
                    switch (active_id){
                        case 0:{ // normal installation
                            gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->Notebook),YON_PAGE_INSTALL_COMMON);
                        } break;
                        case 1:
                            gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->Notebook),YON_PAGE_INSTALL_SEPARATE);
                            break;
                        case 2:
                            gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->Notebook),YON_PAGE_INSTALL_SAME_PARTITION);
                            break;
                        case 3:
                            gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->Notebook),YON_PAGE_INSTALL_OPTIONS);
                    }
                }break;
                case YON_PAGE_REGION:{ //region
                    gtk_widget_set_sensitive(widgets->BackButton,1);
                    if (gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->RegionCombo))==-1){
                        yon_ubl_status_box_spawn(GTK_CONTAINER(widgets->StatusBox),REGION_EMPTY_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE);
                        yon_ubl_status_highlight_incorrect(widgets->RegionCombo);
                        return;
                    } else if (gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->ZoneCombo))==-1){
                        yon_ubl_status_box_spawn(GTK_CONTAINER(widgets->StatusBox),ZONE_EMPTY_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE);
                        yon_ubl_status_highlight_incorrect(widgets->ZoneCombo);
                        return;
                    } 
                    char *languages = "";
                    GtkTreeIter iter;
                    GtkTreeModel *model = GTK_TREE_MODEL(widgets->LanguagesFilter);
                    char *lang_code=NULL;
                    for_iter(model,&iter){
                        gtk_tree_model_get(model,&iter,2,&lang_code,-1);
                        languages = yon_char_unite(languages,!yon_char_is_empty(languages)?",":"",lang_code,NULL);
                    }
                    if (yon_char_is_empty(languages)||!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->MainLanguageSensitiveCheck))){
                        yon_config_remove_by_key(locale_parameter);
                    } else {
                        yon_config_register(locale_parameter,locale_parameter_command,languages);
                        free(languages);
                    }
                    if (gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->LanguagesCombo))==-1||!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->LanguagesSensitiveCheck))){
                        yon_config_remove_by_key(lang_parameter);
                    } else {
                        char *language = (char*)gtk_combo_box_get_active_id(GTK_COMBO_BOX(widgets->LanguagesCombo));
                        yon_config_register(lang_parameter,lang_parameter_command,language);
                    }
                    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->RegionSensitiveCheck))){
                        char *region = (char*)gtk_combo_box_get_active_id(GTK_COMBO_BOX(widgets->RegionCombo));
                        char *zone = (char*)gtk_combo_box_get_active_id(GTK_COMBO_BOX(widgets->ZoneCombo));
                        yon_debug_output("%s",region);
                        yon_debug_output("/%s\n\n",zone);
                        yon_config_register(zone_parameter,zone_parameter_command,yon_char_unite(region,"/",zone,NULL));
                    } else {
                        yon_config_remove_by_key(zone_parameter);
                    }
                    gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->Notebook),page+1);
                }break;

                case YON_PAGE_KEYBOARD: { //keyboard
                    gtk_widget_set_sensitive(widgets->BackButton,1);
                    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->ManualLayoutRadio))){
                        GtkTreeIter iter;
                        if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(widgets->LayoutList),&iter)){
                            yon_ubl_status_box_spawn(GTK_CONTAINER(widgets->StatusBox),LAYOUTS_CHOSEN_BUT_EMPTY_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE);
                            yon_ubl_status_highlight_incorrect(widgets->ManualLayoutRadio);
                            yon_ubl_status_highlight_incorrect(gtk_widget_get_parent(widgets->LayoutTree));
                        }
                    }
                    char *layouts_list="";
                    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->ManualLayoutRadio))&&gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->LayoutSensitiveCheck))){
                        GtkTreeModel *layouts_model=GTK_TREE_MODEL(widgets->LayoutList);
                        GtkTreeIter iter;
                        char *cur_layout=NULL;
                        for_iter(layouts_model,&iter){
                            int chosen=0;
                            gtk_tree_model_get(layouts_model,&iter,0,&cur_layout,3,&chosen,-1);
                            if (chosen)
                                layouts_list = yon_char_unite(layouts_list,yon_char_is_empty(layouts_list)?"":",",cur_layout,NULL);
                        }
                    } else {
                        yon_config_remove_by_key(xkblayout_parameter);
                    }
                    if (gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->KeyboardModelCombo))&&gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->KeyboardModelSensitiveCheck))){
                        char *model = (char*)gtk_combo_box_get_active_id(GTK_COMBO_BOX(widgets->KeyboardModelCombo));
                        // char *layout_switch;
                        if (!yon_char_is_empty(model))
                            yon_config_register(xkbmodel_parameter,xkbmodel_parameter_command,model);
                    } else{
                        yon_config_remove_by_key(xkbmodel_parameter);
                    }
                    if (yon_char_is_empty(layouts_list)&&gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->LayoutSensitiveCheck)))
                        yon_config_register(xkblayout_parameter,xkblayout_parameter_command,layouts_list);
                    else
                        yon_config_remove_by_key(xkblayout_parameter);

                    gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->Notebook),page+1);
                } break;

                default:{ // all other pages
                    gtk_widget_set_sensitive(widgets->BackButton,1);
                    gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->Notebook),page+1);
                }break;

                case YON_PAGE_INSTALL_COMMON: {
                    GtkTreeModel *model;
                    GtkTreeIter iter;
                    if (!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->CommonInstallationDevicesTree)),&model,&iter)){
                        yon_ubl_status_box_spawn(GTK_CONTAINER(widgets->StatusBox),NO_DEVICE_CHOSEN_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE);
                        yon_ubl_status_highlight_incorrect(gtk_widget_get_parent(widgets->CommonInstallationDevicesTree));
                        return;
                    }
                    char *file_system_type = (char*)gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(widgets->CommonInstallationFilesystemTypeCombo));
                    char *device_name = (char*)gtk_entry_get_text(GTK_ENTRY(widgets->CommonInstallationSectionNameEntry));
                    char *device;
                    yon_config_remove_by_key(part_parameter);
                    gtk_tree_model_get(model,&iter,0,&device,-1);
                    yon_config_register(AUTOINSTALL_TYPE_INSTALL,AUTOINSTALL_TYPE_INSTALL_command,"fast");
                    yon_config_register(AUTOINSTALL_DEVICE,AUTOINSTALL_DEVICE_command,device);
                    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->CommonSectionSensitiveCheck))){
                        yon_config_register(device_label_parameter,device_label_parameter_command,device_name);
                    } else {
                        yon_config_remove_by_key(device_label_parameter);
                    }
                    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->CommonFilesystemSensitiveCheck))){
                        yon_config_register(part_type_parameter,part_type_parameter_command,file_system_type);
                    } else {
                        yon_config_remove_by_key(part_type_parameter);
                    }
                    
                    if (!main_config.configure_mode)
                    gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->Notebook),YON_PAGE_INSTALLATION_BEGIN);
                    else
                        gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->Notebook),YON_PAGE_REGION);
                }break;

                case YON_PAGE_INSTALL_SEPARATE:
                    {
                    GtkTreeModel *model;
                    GtkTreeIter iter;
                    if (!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->InstallationNearSysDevicesTree)),&model,&iter)){
                        yon_ubl_status_box_spawn(GTK_CONTAINER(widgets->StatusBox),NO_DEVICE_CHOSEN_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE);
                        yon_ubl_status_highlight_incorrect(gtk_widget_get_parent(widgets->CommonInstallationDevicesTree));
                        return;
                    }
                    char *device;
                    gtk_tree_model_get(model,&iter,0,&device,-1);
                    if (!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->InstallationNearSysSectionTree)),&model,&iter)){
                        yon_ubl_status_box_spawn(GTK_CONTAINER(widgets->StatusBox),NO_DEVICE_CHOSEN_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE);
                        yon_ubl_status_highlight_incorrect(gtk_widget_get_parent(widgets->CommonInstallationDevicesTree));
                        return;
                    }
                    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->NextSizeSensitiveCheck))){
                        double part_size = gtk_spin_button_get_value(GTK_SPIN_BUTTON(widgets->InstallationNearSizeSpin));
                        if (part_size){
                            char *size_letter = (char*)gtk_combo_box_get_active_id(GTK_COMBO_BOX(widgets->InstallationNearSizeTypeSpin));
                            char *size_final = yon_char_append(yon_char_from_long((long)part_size),size_letter);
                            yon_config_register(part_size_parameter,part_size_parameter_command,size_final);
                        } else yon_config_remove_by_key(part_size_parameter);
                    } else yon_config_remove_by_key(part_size_parameter);
                    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->NextLabelSensitiveCheck))){
                    char *device_name = (char*)gtk_entry_get_text(GTK_ENTRY(widgets->NextInstallationSectionNameEntry));
                    yon_config_register(device_label_parameter,device_label_parameter_command,device_name);
                    } else {
                        yon_config_remove_by_key(device_label_parameter);
                    }
                    char *part;
                    gtk_tree_model_get(model,&iter,0,&part,-1);
                    yon_config_register(AUTOINSTALL_TYPE_INSTALL,AUTOINSTALL_TYPE_INSTALL_command,"next");
                    yon_config_register(AUTOINSTALL_DEVICE,AUTOINSTALL_DEVICE_command,device);
                    yon_config_register(part_parameter,part_parameter_command,part);
                    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->NextFSTypeSensitiveCheck))){
                        if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->NextInstallationFormatCheck))){
                            yon_config_register(device_format_parameter,device_format_parameter_command,"no");
                            yon_config_remove_by_key(part_type_parameter);
                        } else { 
                            char *file_system_type = (char*)gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(widgets->NextInstallationFilesystemTypeCombo));
                            yon_config_register(part_type_parameter,part_type_parameter_command,file_system_type);
                            yon_config_remove_by_key(device_format_parameter);
                        }
                        if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->NextInstallationFormatCheck)))
                            yon_config_register(device_format_parameter,device_format_parameter_command,"no");
                    } else {
                            yon_config_remove_by_key(part_type_parameter);
                            yon_config_remove_by_key(device_format_parameter);
                    }
                    if (!main_config.configure_mode)
                    gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->Notebook),YON_PAGE_INSTALLATION_BEGIN);
                    else
                        gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->Notebook),YON_PAGE_REGION);
                    }
                    break;

                case YON_PAGE_INSTALL_SAME_PARTITION:
                {
                    GtkTreeModel *model;
                    GtkTreeIter iter;
                    if (!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->SamePlaceDeviceTree)),&model,&iter)){
                        yon_ubl_status_box_spawn(GTK_CONTAINER(widgets->StatusBox),NO_DEVICE_CHOSEN_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE);
                        yon_ubl_status_highlight_incorrect(gtk_widget_get_parent(widgets->CommonInstallationDevicesTree));
                        return;
                    }
                    char *device;
                    gtk_tree_model_get(model,&iter,0,&device,-1);
                    if (!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->SamePlacePartTree)),&model,&iter)){
                        yon_ubl_status_box_spawn(GTK_CONTAINER(widgets->StatusBox),NO_DEVICE_CHOSEN_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE);
                        yon_ubl_status_highlight_incorrect(gtk_widget_get_parent(widgets->CommonInstallationDevicesTree));
                        return;
                    }
                    yon_config_remove_by_key(part_size_parameter);
                    char *part;
                    gtk_tree_model_get(model,&iter,0,&part,-1);
                        yon_config_register(AUTOINSTALL_TYPE_INSTALL,AUTOINSTALL_TYPE_INSTALL_command,"part");
                        yon_config_register(AUTOINSTALL_DEVICE,AUTOINSTALL_DEVICE_command,device);
                        yon_config_register(part_parameter,part_parameter_command,part);
                        
                    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->SameLabelSensitiveCheck))){
                        char *device_name = (char*)gtk_entry_get_text(GTK_ENTRY(widgets->SameInstallationSectionNameEntry));
                        yon_config_register(device_label_parameter,device_label_parameter_command,device_name);
                    } else {
                        yon_config_remove_by_key(device_label_parameter);
                    }

                    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->SameFSTypeSensitiveCheck))){
                        if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->SameInstallationFormatCheck))){
                            yon_config_register(device_format_parameter,device_format_parameter_command,"no");
                            yon_config_remove_by_key(part_type_parameter);
                        } else { 
                            char *file_system_type = (char*)gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(widgets->SameInstallationFilesystemTypeCombo));
                            yon_config_register(part_type_parameter,part_type_parameter_command,file_system_type);
                            yon_config_remove_by_key(device_format_parameter);
                        }
                    } else {
                            yon_config_remove_by_key(device_format_parameter);
                            yon_config_remove_by_key(part_type_parameter);

                    }
                    
                    if (!main_config.configure_mode)
                    gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->Notebook),YON_PAGE_INSTALLATION_BEGIN);
                    else
                        gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->Notebook),YON_PAGE_REGION);
                }break;

                case YON_PAGE_USERS:{ //users

                    if (yon_char_is_empty(gtk_entry_get_text(GTK_ENTRY(widgets->UserNameEntry)))||!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->UsernameSensitiveCheck))){
                        yon_config_remove_by_key(user_gecos_parameter);
                    } else {
                        char *username = (char*)gtk_entry_get_text(GTK_ENTRY(widgets->UserNameEntry));
                        yon_config_register(user_gecos_parameter,user_gecos_parameter_command,username);
                    }

                    if (yon_char_is_empty(gtk_entry_get_text(GTK_ENTRY(widgets->LoginEntry)))||!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->LoginSensitiveCheck))){
                        yon_config_remove_by_key(user_name_parameter);
                    } else {
                        char *login = (char*)gtk_entry_get_text(GTK_ENTRY(widgets->LoginEntry));
                        yon_config_register(user_name_parameter,user_name_parameter_command,login);

                    }

                    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->PasswordSensitiveCheck))){
                        if (gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->PasswordCombo))==1){
                            if (yon_char_is_empty(gtk_entry_get_text(GTK_ENTRY(widgets->PasswordEntry)))){
                                yon_ubl_status_box_spawn(GTK_CONTAINER(widgets->StatusBox),EMPTY_IMPORTANT_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE);
                                yon_ubl_status_highlight_incorrect(widgets->PasswordEntry);
                                return;
                            } else {
                                char *password = (char*)gtk_entry_get_text(GTK_ENTRY(widgets->PasswordEntry));
                                
                                yon_config_register(user_password_parameter,user_password_parameter_command,password);
                                
                            }
                        } else {
                            yon_config_remove_by_key(user_password_parameter);
                        }
                    }else {
                        yon_config_remove_by_key(user_password_parameter);

                    }

                    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->RootPasswordSensitiveCheck))){
                        if (gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->AdminPasswordCombo))==1){
                            if (yon_char_is_empty(gtk_entry_get_text(GTK_ENTRY(widgets->AdminPasswordEntry)))){
                                yon_ubl_status_box_spawn(GTK_CONTAINER(widgets->StatusBox),EMPTY_IMPORTANT_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE);
                                yon_ubl_status_highlight_incorrect(widgets->AdminPasswordEntry);
                                return;
                            } else {
                                char *root_password = (char*)gtk_entry_get_text(GTK_ENTRY(widgets->AdminPasswordEntry));
                                yon_config_register(root_password_parameter,root_password_parameter_command,root_password);
                                
                            }
                        } else {
                            yon_config_remove_by_key(root_password_parameter);
                        }
                    } else {
                        yon_config_remove_by_key(root_password_parameter);
                    }

                    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->HostnameSensitiveCheck))){
                        if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->AutoHostnameCheck))){
                                yon_config_register(hostname_parameter,hostname_parameter_command,"auto");
                        } else {
                            if (!yon_char_is_empty(gtk_entry_get_text(GTK_ENTRY(widgets->HotnameEntry)))){
                                    char *hostname = (char*)gtk_entry_get_text(GTK_ENTRY(widgets->HotnameEntry));
                                    yon_config_register(hostname_parameter,hostname_parameter_command,hostname);

                            } else {
                                yon_config_remove_by_key(hostname_parameter);
                                
                            }
                        }
                    } else {
                        yon_config_remove_by_key(hostname_parameter);
                    }
                    
                    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->AutologinSensitiveCheck))){
                        char *autologin = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->AutologinCheck))?"yes":"no";
                        yon_config_register(autologin_parameter,autologin_parameter_command,autologin);
                    } else {
                        yon_config_remove_by_key(autologin_parameter);
                    }

                    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->LayoutSensitiveCheck))){
                        GtkTreeIter iter;
                        if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(widgets->LayoutsFilter),&iter)){
                            char *locales="";
                            for_iter (GTK_TREE_MODEL(widgets->LayoutsFilter),&iter){
                                char *id;
                                int status;
                                gtk_tree_model_get(GTK_TREE_MODEL(widgets->LayoutsFilter),&iter,0,&id,3,&status,-1);
                                if (status){
                                    char *temp = yon_char_unite(locales,!yon_char_is_empty(locales)?",":"",id,NULL);
                                    locales=temp;
                                }
                            }
                            if (!yon_char_is_empty(locales)){
                                yon_config_register(xkblayout_parameter,xkblayout_parameter_command,locales);
                            } else {
                                yon_config_remove_by_key(xkblayout_parameter);
                            }
                        }
                    } else {
                        yon_config_remove_by_key(xkblayout_parameter);
                    }

                    if (gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->LayoutBindingCombo))&&gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->OptionsSensitiveCheck))){
                        char *options = (char*)gtk_combo_box_get_active_id(GTK_COMBO_BOX(widgets->LayoutBindingCombo));
                        yon_config_register(xkboptions_parameter,xkboptions_parameter_command,options);
                    } else {
                        yon_config_remove_by_key(xkboptions_parameter);
                    }
                    
                    if (!main_config.configure_mode){
                        if (!main_config.install_complete){
                            gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->Notebook),YON_PAGE_INSTALLATION);
                        } 
                        if (gtk_progress_bar_get_fraction(GTK_PROGRESS_BAR(widgets->InstallationProgress))>0.9){
                            pthread_t tid;
                            pthread_create(&tid,NULL,on_setup_system_configuration,widgets);
                            yon_debug_output("%s\n","installation ending configuration startup");
                        } else {
                            pthread_t tid;
                            pthread_create(&tid,NULL,on_save_system_configuration,widgets);
                            yon_debug_output("%s\n","installation process configuration startup");
                        }
                        main_config.save_done=1;
                            yon_debug_output("Save changed to: %s\n",yon_char_from_int(main_config.save_done));

                            yon_debug_output("Install state: %s\n",yon_char_from_int(main_config.install_complete));
                        if (main_config.install_complete){
                            gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->Notebook),YON_PAGE_COMPLETION);
                        } else {
                            printf("still deactivated\n");
                            gtk_widget_set_sensitive(widgets->CancelInstallButton,0);
                            gtk_widget_set_sensitive(widgets->NextButton,0);
                            gtk_widget_set_sensitive(widgets->BackButton,0);
                        }
                    } else {
                        gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->Notebook),YON_PAGE_CONFIGURE_END);
                    }
                }break;

                case YON_PAGE_INSTALLATION_BEGIN:{
                    if (!main_config.install_thread){
                        pthread_attr_t attr;
                        pthread_attr_init(&attr);
                        pthread_t tid;

                        pthread_create(&tid,&attr,on_config_save,widgets);
                        memcpy(&main_config.install_thread,&tid,sizeof(pthread_t));
                    }
                    gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->Notebook),YON_PAGE_INSTALLATION);
                } break;

                case YON_PAGE_INSTALL_ERROR:
                case YON_PAGE_COMPLETION:
                    if (!system("reboot"))
                    return;
                break;

                case YON_PAGE_INSTALL_OPTIONS: {
                    int mode = -1;
                    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->GrubInstallRadio))){
                        mode = 0;
                    } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->GrubUpdateRadio))){
                        mode = 1;
                    } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->SeparateRadio))){
                        mode = 2;
                    } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->OSRadio))){
                        mode = 3;
                    } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->UserDataOnlyRadio))){
                        mode = 4;
                    }
                    switch(mode){
                        case 0: gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->Notebook),YON_PAGE_OPTIONS_GRUB_INSTALL);
                            break;
                        case 1: gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->Notebook),YON_PAGE_OPTIONS_GRUB_UPDATE);
                            break;
                        case 2: gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->Notebook),YON_PAGE_OPTIONS_SEPARATE);
                            break;
                        case 3: gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->Notebook),YON_PAGE_OPTIONS_OS_ONLY);
                            break;
                        case 4: gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->Notebook),YON_PAGE_OPTIONS_USRDATA_ONLY);
                            break;
                    }
                } break;

                case YON_PAGE_OPTIONS_GRUB_INSTALL:{
                    GtkTreeIter iter;
                    GtkTreeModel *model;
                    if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->GrubInstallDevicesTree)),&model,&iter)){
                        char *cur_device;
                        gtk_tree_model_get(model,&iter,0,&cur_device,-1);
                        yon_config_register(AUTOINSTALL_DEVICE,AUTOINSTALL_DEVICE_command,cur_device);
                        yon_config_register(AUTOINSTALL_TYPE_INSTALL,AUTOINSTALL_TYPE_INSTALL_command,"grub_install");
                        yon_config_remove_by_key(part_parameter);
                        if (!main_config.configure_mode)
                            gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->Notebook),YON_PAGE_INSTALLATION_BEGIN);
                        else
                            gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->Notebook),YON_PAGE_REGION);
                    } else {
                        yon_ubl_status_box_spawn(GTK_CONTAINER(widgets->StatusBox),NO_DEVICE_CHOSEN_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE);
                        yon_ubl_status_highlight_incorrect(widgets->GrubInstallDevicesTree);
                    }
                } break;

                case YON_PAGE_OPTIONS_GRUB_UPDATE:{
                    GtkTreeIter iter;
                    GtkTreeModel *model;
                    if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->GrubUpdateDevicesTree)),&model,&iter)){
                        char *cur_device;
                        gtk_tree_model_get(model,&iter,0,&cur_device,-1);
                        yon_config_register(AUTOINSTALL_DEVICE,AUTOINSTALL_DEVICE_command,cur_device);
                        yon_config_register(AUTOINSTALL_TYPE_INSTALL,AUTOINSTALL_TYPE_INSTALL_command,"grub_update");
                        yon_config_remove_by_key(part_parameter);
                    if (!main_config.configure_mode)
                        gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->Notebook),YON_PAGE_INSTALLATION_BEGIN);
                    else
                        gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->Notebook),YON_PAGE_REGION);
                    } else {
                        yon_ubl_status_box_spawn(GTK_CONTAINER(widgets->StatusBox),NO_DEVICE_CHOSEN_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE);
                        yon_ubl_status_highlight_incorrect(widgets->GrubUpdateDevicesTree);
                    }
                    }break;

                case YON_PAGE_OPTIONS_SEPARATE:{
                    GtkTreeModel *model;
                    GtkTreeIter iter;
                    if (!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->SeparateSysSectionTree)),&model,&iter)){
                        yon_ubl_status_box_spawn(GTK_CONTAINER(widgets->StatusBox),NO_DEVICE_CHOSEN_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE);
                        yon_ubl_status_highlight_incorrect(gtk_widget_get_parent(widgets->SeparateSysSectionTree));
                        return;
                    }
                    gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->Notebook),YON_PAGE_OPTIONS_SEPARATE_USRDATA);
                    }break;

                case YON_PAGE_OPTIONS_SEPARATE_USRDATA:{
                    GtkTreeIter iter,itar;
                    GtkTreeModel *model,*model2;
                    if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->SeparateDevicesTree)),&model,&iter)){
                        if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->SeparateSysSectionTree)),&model2,&itar)){
                            char *cur_device, *system_section, *user_section;
                            gtk_tree_model_get(model,&iter,0,&cur_device,-1);
                            gtk_tree_model_get(model2,&itar,0,&system_section,-1);
                            if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->SeparateUserSysSectionTree)),&model2,&itar)){
                                gtk_tree_model_get(model2,&itar,0,&user_section,-1);
                                yon_config_register(AUTOINSTALL_DEVICE,AUTOINSTALL_DEVICE_command,cur_device);
                                yon_config_register(part_parameter,part_parameter_command,yon_char_unite(system_section,",",user_section,NULL));
                                yon_config_register(AUTOINSTALL_TYPE_INSTALL,AUTOINSTALL_TYPE_INSTALL_command,"custom");
                                gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->Notebook),YON_PAGE_INSTALLATION_BEGIN);
                                return;
                            } else {

                            }
                        } else {

                        }
                    } else {

                    }
                    
                } break;

                case YON_PAGE_OPTIONS_OS_ONLY:{
                    yon_install_options_save(widgets->OSDevicesTree,widgets->OSSysSectionTree,"system_only",widgets);
                } break;

                case YON_PAGE_OPTIONS_USRDATA_ONLY:{
                    yon_install_options_save(widgets->UserdataDevicesTree,widgets->UserdataSysSectionTree,"data_only",widgets);
                } break;
            }
        } break;
        case -1: { // Previous
            switch (page){
                case YON_PAGE_REGION: {
                    if (!main_config.configure_mode){
                        gtk_widget_set_sensitive(widgets->BackButton,0);
                        gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->Notebook),page-1);
                    } else {
                        gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->Notebook),YON_PAGE_SECTIONS);
                    }
                }break;

                case YON_PAGE_INSTALL_COMMON:
                case YON_PAGE_INSTALL_SEPARATE:
                case YON_PAGE_INSTALL_SAME_PARTITION:
                case YON_PAGE_INSTALL_OPTIONS:
                    {
                        gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->Notebook),YON_PAGE_SECTIONS);
                    } break;

                case YON_PAGE_OPTIONS_GRUB_INSTALL:
                case YON_PAGE_OPTIONS_GRUB_UPDATE:
                case YON_PAGE_OPTIONS_SEPARATE:
                case YON_PAGE_OPTIONS_OS_ONLY:
                case YON_PAGE_OPTIONS_USRDATA_ONLY:
                    gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->Notebook),YON_PAGE_INSTALL_OPTIONS);
                    break;

                case YON_PAGE_INSTALLATION_BEGIN:
                    gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->Notebook),YON_PAGE_SECTIONS);
                break; 

                case YON_PAGE_CONFIGURE_END:{
                    gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->Notebook),YON_PAGE_USERS);
                } break;
                
                case YON_PAGE_COMPLETED:{
                    gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->Notebook),YON_PAGE_USERS);
                } break;

                default:{
                    gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->Notebook),page-1);
                }
            }

        } break;
        case -2: { // Cancel/repeat
            switch (page){
                case YON_PAGE_COMPLETION:
                case YON_PAGE_INSTALL_ERROR:{
                    // GtkWidget *dialog = gtk_dialog_new();
                    gtk_main_quit();
                    }break;
                default:{
                    gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->Notebook),0);
                }
            }
        }break;
    }
}

void on_region_changed(GtkComboBox *self, main_window *widgets);
void on_region_changed(GtkComboBox *self, main_window *widgets){
    char *active = (char*)gtk_combo_box_get_active_id(self);
    active = yon_char_append("/usr/share/zoneinfo/",active);
    int size;
    gtk_combo_box_text_remove_all(GTK_COMBO_BOX_TEXT(widgets->ZoneCombo));
    if (yon_file_is_directory(active)){
        config_str parsed = yon_file_ls(active,&size);
        for (int i=0;i<size;i++){
            gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(widgets->ZoneCombo),parsed[i],_(parsed[i]));
        }
        gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->ZoneCombo),0);
    }
}

void on_locale_changed(GtkWidget *,main_window *);
void on_locale_changed(GtkWidget *,main_window *){

}

void on_additional_software_toggled();
void on_additional_software_toggled(){

}

void yon_set_max_size_from_partition(GtkTreeView *table, GtkSpinButton *spin_size, GtkComboBox *size_type);
void yon_set_max_size_from_partition(GtkTreeView *table, GtkSpinButton *spin_size, GtkComboBox *size_type){
    GtkTreeModel *model;
    GtkTreeIter iter;
    char *selected_size=NULL;
    if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(table),&model,&iter)){
        gtk_tree_model_get(model,&iter,1,&selected_size,-1);
        if (!yon_char_is_empty(selected_size)){
            int size = gtk_combo_box_get_active(size_type);
            double cur_size = atof(selected_size);
            char cur_size_letter = selected_size[strlen(selected_size)-1];
            int cur_size_type=0;
            switch (cur_size_letter){
                case 'M':
                    cur_size_type=0;
                    break;
                case 'G':
                    cur_size_type=1;
                    break;
                case 'T':
                    cur_size_type=2;
                    break;
            }
            if (size-cur_size_type>0){
                for (int i=0;i<size-cur_size_type;i++){
                    cur_size/=1024;
                }
            } else if (size-cur_size_type<0){
                for (int i=0;i<cur_size_type-size;i++){
                    cur_size*=1024;
                }
            }
            gtk_adjustment_set_upper(gtk_spin_button_get_adjustment(spin_size),cur_size);
        }
    }
}

void on_partition_changed(GtkWidget *self, main_window *widgets);
void on_partition_changed(GtkWidget *self, main_window *widgets){
    if (self==widgets->InstallationNearSysSectionTree)
        yon_set_max_size_from_partition(GTK_TREE_VIEW(widgets->InstallationNearSysSectionTree),GTK_SPIN_BUTTON(widgets->InstallationNearSizeSpin),GTK_COMBO_BOX(widgets->InstallationNearSizeTypeSpin));
    
}

void on_separate_installation_changed(GtkWidget *self, main_window *widgets);
void on_separate_installation_changed(GtkWidget *self, main_window *widgets){

    gtk_list_store_clear(widgets->PartitionsList);
    GtkTreeIter iter;
    GtkTreeModel *model;
    if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(self)),&model,&iter)){
        gtk_tree_selection_select_iter(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->SeparateUserDevicesTree)),&iter);
        char *disk_path="";
        gtk_tree_model_get(model,&iter,0,&disk_path,-1);
        int size;
        config_str parsed;
        parsed = yon_config_load(get_parts_and_devices_command,&size);
        char *string = yon_char_parsed_to_string(parsed,size,"");
        struct json_object *root;
        struct json_object *blockdevices;
        root = json_tokener_parse(string);
        json_object_object_get_ex(root, "blockdevices", &blockdevices);
        for (long unsigned int i = 0; i < json_object_array_length(blockdevices); i++) {
            struct json_object *device = json_object_array_get_idx(blockdevices, i);
            struct json_object *type, *path, *size, *model, *fstype, *fsused;

            json_object_object_get_ex(device, "type", &type);
            if (strcmp("part",json_object_get_string(type)))
                continue;
            json_object_object_get_ex(device, "path", &path);
            if (!strstr(json_object_get_string(path),disk_path)){
                continue;
            }
            json_object_object_get_ex(device, "size", &size);
            json_object_object_get_ex(device, "model", &model);
            json_object_object_get_ex(device, "fstype", &fstype);
            json_object_object_get_ex(device, "fsused", &fsused);

            float free_space=0;
            char *free_space_string="";
            if (size&&fsused){
                free_space = atof(json_object_get_string(size))-atof(json_object_get_string(fsused));
                free_space_string = yon_char_append(yon_char_from_float(free_space)," ");
                free_space_string[strlen(free_space_string)-1]=json_object_get_string(size)[strlen(json_object_get_string(size))-1]; 
            }
            // gtk_spin_button_set_value(GTK_SPIN_BUTTON(widgets->InstallationNearSizeSpin),0.0);
            gtk_adjustment_set_upper(gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(widgets->InstallationNearSizeSpin)),0.0);
            gtk_list_store_append(widgets->PartitionsList,&iter);
            gtk_list_store_set(widgets->PartitionsList,&iter,0,json_object_get_string(path),1,json_object_get_string(size),2,free_space_string,3,json_object_get_string(fstype),-1);
        }
        yon_char_parsed_free(parsed,size);
    }
}

void on_near_installation_device_changed(GtkWidget *self, main_window *widgets){
    gtk_list_store_clear(widgets->PartitionsList);
    GtkTreeIter iter;
    GtkTreeModel *model;
    if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(self)),&model,&iter)){
        char *disk_path="";
        gtk_tree_model_get(model,&iter,0,&disk_path,-1);
        int size;
        config_str parsed;
        parsed = yon_config_load(get_parts_and_devices_command,&size);
        char *string = yon_char_parsed_to_string(parsed,size,"");
        struct json_object *root;
        struct json_object *blockdevices;
        root = json_tokener_parse(string);
        json_object_object_get_ex(root, "blockdevices", &blockdevices);
        for (long unsigned int i = 0; i < json_object_array_length(blockdevices); i++) {
            struct json_object *device = json_object_array_get_idx(blockdevices, i);
            struct json_object *type, *path, *size, *model, *fstype, *fsused;

            json_object_object_get_ex(device, "type", &type);
            if (strcmp("part",json_object_get_string(type)))
                continue;
            json_object_object_get_ex(device, "path", &path);
            if (!strstr(json_object_get_string(path),disk_path)){
                continue;
            }
            json_object_object_get_ex(device, "size", &size);
            json_object_object_get_ex(device, "model", &model);
            json_object_object_get_ex(device, "fstype", &fstype);
            json_object_object_get_ex(device, "fsused", &fsused);

            float free_space=0;
            char *free_space_string="";
            if (size&&fsused){
                free_space = atof(json_object_get_string(size))-atof(json_object_get_string(fsused));
                free_space_string = yon_char_append(yon_char_from_float(free_space)," ");
                free_space_string[strlen(free_space_string)-1]=json_object_get_string(size)[strlen(json_object_get_string(size))-1]; 
            }
            // gtk_spin_button_set_value(GTK_SPIN_BUTTON(widgets->InstallationNearSizeSpin),0.0);
            gtk_adjustment_set_upper(gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(widgets->InstallationNearSizeSpin)),0.0);
            gtk_list_store_append(widgets->PartitionsList,&iter);
            gtk_list_store_set(widgets->PartitionsList,&iter,0,json_object_get_string(path),1,json_object_get_string(size),2,free_space_string,3,json_object_get_string(fstype),-1);
        }
        yon_char_parsed_free(parsed,size);
    }
}

void on_same_installation_device_changed(GtkWidget *, main_window *widgets);
void on_same_installation_device_changed(GtkWidget *, main_window *widgets){
    gtk_list_store_clear(widgets->PartitionsList);
    GtkTreeIter iter;
    GtkTreeModel *model;
    if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->SamePlaceDeviceTree)),&model,&iter)){
        char *disk_path="";
        gtk_tree_model_get(model,&iter,0,&disk_path,-1);
        int size;
        config_str parsed;
        parsed = yon_config_load(get_parts_and_devices_command,&size);
        char *string = yon_char_parsed_to_string(parsed,size,"");
        struct json_object *root;
        struct json_object *blockdevices;
        root = json_tokener_parse(string);
        json_object_object_get_ex(root, "blockdevices", &blockdevices);
        for (long unsigned int i = 0; i < json_object_array_length(blockdevices); i++) {
            struct json_object *device = json_object_array_get_idx(blockdevices, i);
            struct json_object *type, *path, *size, *model, *vendor, *serial;

            json_object_object_get_ex(device, "type", &type);
            if (strcmp("part",json_object_get_string(type)))
                continue;
            json_object_object_get_ex(device, "path", &path);
            if (!strstr(json_object_get_string(path),disk_path)){
                continue;
            }
            json_object_object_get_ex(device, "size", &size);
            json_object_object_get_ex(device, "model", &model);
            json_object_object_get_ex(device, "vendor", &vendor);
            json_object_object_get_ex(device, "serial", &serial);

            gtk_list_store_append(widgets->PartitionsList,&iter);
            gtk_list_store_set(widgets->PartitionsList,&iter,0,json_object_get_string(path),1,json_object_get_string(model),2,json_object_get_string(serial),3,json_object_get_string(size),4,json_object_get_string(vendor),-1);
            }
        yon_char_parsed_free(parsed,size);
    }
}

void on_gparted_open();
void on_gparted_open(){
    yon_launch_app_with_arguments(open_gparted_command,NULL);
}

// gboolean on_yon_exit(GtkWidget *,GdkEvent*, main_window *widgets);
// void on_exit_accepted(GtkWidget *,main_window *widgets);
// void on_exit_accepted(GtkWidget *,main_window *widgets){
//     if (main_config.install_thread){
//         pthread_cancel((pthread_t)main_config.install_thread);
//     }
//     main_config.exit_accepted=1;
//     g_signal_emit_by_name(G_OBJECT(widgets->MainWindow),"destroy",widgets->MainWindow,NULL);
// }

// gboolean on_yon_exit(GtkWidget *,GdkEvent*, main_window *widgets){
//     if (!main_config.exit_accepted){
//         if (widgets){};
//         confirmation_window *window = malloc(sizeof(confirmation_window));
//         GtkBuilder *builder = gtk_builder_new_from_resource(glade_path_confirmation);
//         window->Window = yon_gtk_builder_get_widget(builder,"MainWindow");
//         window->AcceptButton = yon_gtk_builder_get_widget(builder,"AcceptButton");
//         window->CancelButton = yon_gtk_builder_get_widget(builder,"CancelButton");
//         g_signal_connect(G_OBJECT(window->AcceptButton),"clicked",G_CALLBACK(on_exit_accepted),widgets);
//         g_signal_connect(G_OBJECT(window->AcceptButton),"clicked",G_CALLBACK(on_subwindow_close),NULL);
//         gtk_window_set_transient_for(GTK_WINDOW(window->Window),GTK_WINDOW(widgets->MainWindow));
//         gtk_window_set_title(GTK_WINDOW(window->Window),TITLE_LABEL);
//         gtk_window_set_icon_name(GTK_WINDOW(window->Window),icon_path);
//         gtk_widget_show(window->Window);

//         return 1;
//     }

//     return 0;
// }

/**yon_main_window_complete(main_window *widgets) 
 * [EN] 
 *  
 * [RU] 
 * Функция настройки основного окна приложения. [widgets] - структура со стандартным интерфейсом. 
*/ 
main_window *yon_main_window_complete(){ 
    main_window *widgets=NULL;
    widgets = yon_remalloc(widgets,sizeof(main_window)); 
    GtkBuilder *builder = gtk_builder_new_from_resource(glade_path); 
    gtk_builder_add_callback_symbol(builder,"yon_gtk_widget_set_sensitive_from_toggle_button",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button));
    gtk_builder_add_callback_symbol(builder,"on_toggle_button_switch_on",G_CALLBACK(on_toggle_button_switch_on));
    // Custom widgets configuration 
    widgets->builder = builder;

    widgets->DevicesList=GTK_LIST_STORE(gtk_builder_get_object(builder,"DevicesList"));
	widgets->LanguagesList=GTK_LIST_STORE(gtk_builder_get_object(builder,"LanguagesList"));
	widgets->MainWindow=yon_gtk_builder_get_widget(builder,"MainWindow");
	widgets->WelcomeToggle=yon_gtk_builder_get_widget(builder,"WelcomeToggle");
	widgets->LicenceToggle=yon_gtk_builder_get_widget(builder,"LicenceToggle");
	widgets->LocationToggle=yon_gtk_builder_get_widget(builder,"LocationToggle");
	widgets->KeyboardToggle=yon_gtk_builder_get_widget(builder,"KeyboardToggle");
	widgets->SectionsToggle=yon_gtk_builder_get_widget(builder,"SectionsToggle");
	widgets->UsersToggle=yon_gtk_builder_get_widget(builder,"USersToggle");
	widgets->SummaryToggle=yon_gtk_builder_get_widget(builder,"SummaryToggle");
	widgets->CompletionToggle=yon_gtk_builder_get_widget(builder,"CompletionToggle");
	widgets->InstallationToggle=yon_gtk_builder_get_widget(builder,"InstallationToggle");
	widgets->LanguageCombo=yon_gtk_builder_get_widget(builder,"LanguageCombo");
	widgets->RegionCombo=yon_gtk_builder_get_widget(builder,"RegionCombo");
	widgets->ZoneCombo=yon_gtk_builder_get_widget(builder,"ZoneCombo");
	widgets->AvailableLanguagesEntry=yon_gtk_builder_get_widget(builder,"AvailableLanguagesEntry");
	widgets->AvailableLanguagesButton=yon_gtk_builder_get_widget(builder,"AvailableLanguagesButton");
	widgets->LanguagesCombo=yon_gtk_builder_get_widget(builder,"LanguagesCombo");
	widgets->KeyboardModelCombo=yon_gtk_builder_get_widget(builder,"KeyboardModelCombo");
	widgets->LayoutBindingCombo=yon_gtk_builder_get_widget(builder,"LayoutBindingCombo");
	widgets->DefaultLayoutRadio=yon_gtk_builder_get_widget(builder,"DefaultLayoutRadio");
	widgets->ManualLayoutRadio=yon_gtk_builder_get_widget(builder,"ManualLayoutRadio");
	widgets->LayoutTree=yon_gtk_builder_get_widget(builder,"LayoutTree");
	widgets->AddButton=yon_gtk_builder_get_widget(builder,"AddButton");
	widgets->RemoveButton=yon_gtk_builder_get_widget(builder,"RemoveButton");
	widgets->InstallationRadio=yon_gtk_builder_get_widget(builder,"InstallationRadio");
	widgets->InstallationNearRadio=yon_gtk_builder_get_widget(builder,"InstallationNearRadio");
	widgets->InstallationLinuxRadio=yon_gtk_builder_get_widget(builder,"InstallationLinuxRadio");
	widgets->InstallationWindowsRadio=yon_gtk_builder_get_widget(builder,"InstallationWindowsRadio");
	widgets->InstallationOptionsRadio=yon_gtk_builder_get_widget(builder,"InstallationOptionsRadio");
	widgets->UserNameEntry=yon_gtk_builder_get_widget(builder,"UserNameEntry");
	widgets->LoginEntry=yon_gtk_builder_get_widget(builder,"LoginEntry");
	widgets->PasswordCombo=yon_gtk_builder_get_widget(builder,"PasswordCombo");
	widgets->PasswordEntry=yon_gtk_builder_get_widget(builder,"PasswordEntry");
	widgets->PasswordButton=yon_gtk_builder_get_widget(builder,"PasswordButton");
	widgets->AutologinCheck=yon_gtk_builder_get_widget(builder,"AutologinCheck");
	widgets->AdminPasswordCombo=yon_gtk_builder_get_widget(builder,"AdminPasswordCombo");
	widgets->AdminPasswordEntry=yon_gtk_builder_get_widget(builder,"AdminPasswordEntry");
	widgets->AdminPasswordButton=yon_gtk_builder_get_widget(builder,"AdminPasswordButton");
	widgets->HotnameEntry=yon_gtk_builder_get_widget(builder,"HotnameEntry");
	widgets->AutoHostnameCheck=yon_gtk_builder_get_widget(builder,"AutoHostnameCheck");
	widgets->CancelInstallButton=yon_gtk_builder_get_widget(builder,"CancelInstallButton");
	widgets->BackButton=yon_gtk_builder_get_widget(builder,"BackButton");
	widgets->NextButton=yon_gtk_builder_get_widget(builder,"NextButton");
	widgets->mainSettingsButton=yon_gtk_builder_get_widget(builder,"mainSettingsButton");
	widgets->menu1=yon_gtk_builder_get_widget(builder,"menu1");
	widgets->menu2=yon_gtk_builder_get_widget(builder,"menu2");
    widgets->RegionImage = yon_gtk_builder_get_widget(builder,"RegionImage");
    widgets->RegionBox = yon_gtk_builder_get_widget(builder,"RegionBox");
    widgets->RegionAspect = yon_gtk_builder_get_widget(builder,"RegionAspect");
    widgets->KeyboardImage = yon_gtk_builder_get_widget(builder,"KeyboardImage");
    widgets->KeyboardBox = yon_gtk_builder_get_widget(builder,"KeyboardBox");
    widgets->Notebook = yon_gtk_builder_get_widget(builder,"Notebook");
    widgets->LicenceLabel = yon_gtk_builder_get_widget(builder,"LicenceLabel");
    widgets->SlidesImage = yon_gtk_builder_get_widget(builder,"SlidesImage");
    widgets->CommonInstallationDevicesTree = yon_gtk_builder_get_widget(builder,"CommonInstallationDevicesTree");
    widgets->AdditionalSoftwareTree = yon_gtk_builder_get_widget(builder,"AdditionalSoftwareTree");

    widgets->SamePlaceDeviceTree = yon_gtk_builder_get_widget(builder,"SamePlaceDeviceTree");
    widgets->SamePlacePartTree = yon_gtk_builder_get_widget(builder,"SamePlacePartTree");

    widgets->InstallationNearSysDevicesTree = yon_gtk_builder_get_widget(builder,"InstallationNearSysDevicesTree");
    widgets->InstallationNearSysSectionTree = yon_gtk_builder_get_widget(builder,"InstallationNearSysSectionTree");
    widgets->InstallationNearSizeSpin = yon_gtk_builder_get_widget(builder,"InstallationNearSizeSpin");
    widgets->InstallationNearSizeTypeSpin = yon_gtk_builder_get_widget(builder,"InstallationNearSizeTypeSpin");

    widgets->InstallationProgress = yon_gtk_builder_get_widget(builder,"InstallationProgress");
    widgets->InstallationLabel = yon_gtk_builder_get_widget(builder,"InstallationLabel");
    widgets->ReadShortLogButton = yon_gtk_builder_get_widget(builder,"ReadShortLogButton");
    widgets->PackageInstallationProgress = yon_gtk_builder_get_widget(builder,"PackageInstallationProgress");
    widgets->PackageInstallationLabel = yon_gtk_builder_get_widget(builder,"PackageInstallationLabel");
    widgets->ReadFullLogButton = yon_gtk_builder_get_widget(builder,"ReadFullLogButton");

    widgets->SameInstallationFilesystemTypeCombo = yon_gtk_builder_get_widget(builder,"SameInstallationFilesystemTypeCombo");
    widgets->SameInstallationFormatCheck = yon_gtk_builder_get_widget(builder,"SameInstallationFormatCheck");
    widgets->SameInstallationSectionNameEntry = yon_gtk_builder_get_widget(builder,"SameInstallationSectionNameEntry");
    widgets->NextInstallationFilesystemTypeCombo = yon_gtk_builder_get_widget(builder,"NextInstallationFilesystemTypeCombo");
    widgets->NextInstallationFormatCheck = yon_gtk_builder_get_widget(builder,"NextInstallationFormatCheck");
    widgets->NextInstallationSectionNameEntry = yon_gtk_builder_get_widget(builder,"NextInstallationSectionNameEntry");
    widgets->CommonInstallationFilesystemTypeCombo = yon_gtk_builder_get_widget(builder,"CommonInstallationFilesystemTypeCombo");
    widgets->CommonInstallationSectionNameEntry = yon_gtk_builder_get_widget(builder,"CommonInstallationSectionNameEntry");

    widgets->GpartedCommonButton = yon_gtk_builder_get_widget(builder,"GpartedCommonButton");
    widgets->GpartedNearButton = yon_gtk_builder_get_widget(builder,"GpartedNearButton");
    widgets->GpartedSameButton = yon_gtk_builder_get_widget(builder,"GpartedSameButton");

    widgets->ConfigurationModeMenuItem = yon_gtk_builder_get_widget(builder,"ConfigurationModeMenuItem");
    widgets->DocumentationMenuItem = yon_ubl_menu_item_documentation_new(DOCUMENTATION_LABEL);
    widgets->AboutMenuItem = yon_ubl_menu_item_about_new(ABOUT_LABEL);

    widgets->StatusBox = yon_gtk_builder_get_widget(builder,"StatusBox");
    widgets->AdditionalSoftwareCell = GTK_CELL_RENDERER(gtk_builder_get_object(builder,"AdditionalSoftwareCell"));

    widgets->GrubInstallRadio = yon_gtk_builder_get_widget(builder,"GrubInstallRadio");
    widgets->GrubUpdateRadio = yon_gtk_builder_get_widget(builder,"GrubUpdateRadio");
    widgets->SeparateRadio = yon_gtk_builder_get_widget(builder,"SeparateRadio");
    widgets->OSRadio = yon_gtk_builder_get_widget(builder,"OSRadio");
    widgets->UserDataOnlyRadio = yon_gtk_builder_get_widget(builder,"UserDataOnlyRadio");

    widgets->GpartedGrubInstallButton = yon_gtk_builder_get_widget(builder,"GpartedGrubInstallButton");
    widgets->GrubInstallDevicesTree = yon_gtk_builder_get_widget(builder,"GrubInstallDevicesTree");

    widgets->GpartedGrubUpdateButton = yon_gtk_builder_get_widget(builder,"GpartedGrubUpdateButton");
    widgets->GrubUpdateDevicesTree = yon_gtk_builder_get_widget(builder,"GrubUpdateDevicesTree");

    widgets->GpartedSeparateButton = yon_gtk_builder_get_widget(builder,"GpartedSeparateButton");
    widgets->SeparateDevicesTree = yon_gtk_builder_get_widget(builder,"SeparateDevicesTree");
    widgets->SeparateSysSectionTree = yon_gtk_builder_get_widget(builder,"SeparateSysSectionTree");
    widgets->GpartedSeparateUserButton = yon_gtk_builder_get_widget(builder,"GpartedSeparateUserButton");
    widgets->SeparateUserDevicesTree = yon_gtk_builder_get_widget(builder,"SeparateUserDevicesTree");
    widgets->SeparateUserSysSectionTree = yon_gtk_builder_get_widget(builder,"SeparateUserSysSectionTree");

    widgets->GpartedOSButton = yon_gtk_builder_get_widget(builder,"GpartedOSButton");
    widgets->OSDevicesTree = yon_gtk_builder_get_widget(builder,"OSDevicesTree");
    widgets->OSSysSectionTree = yon_gtk_builder_get_widget(builder,"OSSysSectionTree");

    widgets->GpartedUserdataButton = yon_gtk_builder_get_widget(builder,"GpartedUserdataButton");
    widgets->UserdataDevicesTree = yon_gtk_builder_get_widget(builder,"UserdataDevicesTree");
    widgets->UserdataSysSectionTree = yon_gtk_builder_get_widget(builder,"UserdataSysSectionTree");

    widgets->SaveButton = yon_gtk_builder_get_widget(builder,"SaveButton");

    widgets->LoadGlobalConfigurationMenuItem = yon_gtk_builder_get_widget(builder,"LoadGlobalConfigurationMenuItem");
    widgets->LoadLocalConfigurationMenuItem = yon_gtk_builder_get_widget(builder,"LoadLocalConfigurationMenuItem");
    widgets->LoadExternalConfigurationMenuItem = yon_gtk_builder_get_widget(builder,"LoadExternalConfigurationMenuItem");

    widgets->SaveGlobalLocalConfigurationMenuItem = yon_gtk_builder_get_widget(builder,"SaveGlobalLocalConfigurationMenuItem");
    widgets->SaveGlobalConfigurationMenuItem = yon_gtk_builder_get_widget(builder,"SaveGlobalConfigurationMenuItem");
    widgets->SaveLocalConfigurationMenuItem = yon_gtk_builder_get_widget(builder,"SaveLocalConfigurationMenuItem");
    widgets->SaveExternalConfigurationMenuItem = yon_gtk_builder_get_widget(builder,"SaveExternalConfigurationMenuItem");

    widgets->LanguagesList = GTK_LIST_STORE(gtk_builder_get_object(builder,"LanguagesList"));
    widgets->LanguagesFilter = GTK_TREE_MODEL(gtk_builder_get_object(builder,"LanguagesFilter"));
    widgets->LayoutsFilter = GTK_TREE_MODEL(gtk_builder_get_object(builder,"LayoutsFilter"));
    widgets->LayoutList = GTK_TREE_STORE(gtk_builder_get_object(builder,"LayoutList"));
    widgets->AdditionalSoftwareList = GTK_LIST_STORE(gtk_builder_get_object(builder,"AdditionalSoftwareList"));
    widgets->PartitionsList = GTK_LIST_STORE(gtk_builder_get_object(builder,"PartitionsList"));

    widgets->RegionSensitiveCheck = yon_gtk_builder_get_widget(builder,"RegionSensitiveCheck");
    widgets->LanguagesSensitiveCheck = yon_gtk_builder_get_widget(builder,"LanguagesSensitiveCheck");
    widgets->MainLanguageSensitiveCheck = yon_gtk_builder_get_widget(builder,"MainLanguageSensitiveCheck");
    widgets->KeyboardModelSensitiveCheck = yon_gtk_builder_get_widget(builder,"KeyboardModelSensitiveCheck");
    widgets->OptionsSensitiveCheck = yon_gtk_builder_get_widget(builder,"OptionsSensitiveCheck");
    widgets->LayoutSensitiveCheck = yon_gtk_builder_get_widget(builder,"LayoutSensitiveCheck");
    widgets->UsernameSensitiveCheck = yon_gtk_builder_get_widget(builder,"UsernameSensitiveCheck");
    widgets->LoginSensitiveCheck = yon_gtk_builder_get_widget(builder,"LoginSensitiveCheck");
    widgets->PasswordSensitiveCheck = yon_gtk_builder_get_widget(builder,"PasswordSensitiveCheck");
    widgets->AutologinSensitiveCheck = yon_gtk_builder_get_widget(builder,"AutologinSensitiveCheck");
    widgets->RootPasswordSensitiveCheck = yon_gtk_builder_get_widget(builder,"RootPasswordSensitiveCheck");
    widgets->HostnameSensitiveCheck = yon_gtk_builder_get_widget(builder,"HostnameSensitiveCheck");
    widgets->CommonFilesystemSensitiveCheck = yon_gtk_builder_get_widget(builder,"CommonFilesystemSensitiveCheck");
    widgets->CommonSectionSensitiveCheck = yon_gtk_builder_get_widget(builder,"CommonSectionSensitiveCheck");
    widgets->NextSizeSensitiveCheck = yon_gtk_builder_get_widget(builder,"NextSizeSensitiveCheck");
    widgets->NextFSTypeSensitiveCheck = yon_gtk_builder_get_widget(builder,"NextFSTypeSensitiveCheck");
    widgets->NextLabelSensitiveCheck = yon_gtk_builder_get_widget(builder,"NextLabelSensitiveCheck");
    widgets->SameFSTypeSensitiveCheck = yon_gtk_builder_get_widget(builder,"SameFSTypeSensitiveCheck");
    widgets->SameLabelSensitiveCheck = yon_gtk_builder_get_widget(builder,"SameLabelSensitiveCheck");

    // g_signal_connect(G_OBJECT(widgets->MainWindow),"delete-event",G_CALLBACK(on_yon_exit),widgets);
    GtkWidget *menu = yon_gtk_builder_get_widget(builder,"menu2");
    gtk_style_context_add_class(gtk_widget_get_style_context(widgets->DocumentationMenuItem),"menuitemmiddle");
    gtk_style_context_remove_class(gtk_widget_get_style_context(widgets->DocumentationMenuItem),"menuitemtop");
    gtk_menu_shell_append(GTK_MENU_SHELL(menu),widgets->DocumentationMenuItem);
    gtk_menu_shell_append(GTK_MENU_SHELL(menu),widgets->AboutMenuItem);

    g_signal_connect(G_OBJECT(widgets->LoadGlobalConfigurationMenuItem),"activate",G_CALLBACK(on_config_global_load),widgets);
    g_signal_connect(G_OBJECT(widgets->LoadLocalConfigurationMenuItem),"activate",G_CALLBACK(on_config_local_load),widgets);
    g_signal_connect(G_OBJECT(widgets->LoadExternalConfigurationMenuItem),"activate",G_CALLBACK(on_config_custom_load),widgets);

    g_signal_connect(G_OBJECT(widgets->SaveGlobalLocalConfigurationMenuItem),"activate",G_CALLBACK(on_config_global_local_save),widgets);
    g_signal_connect(G_OBJECT(widgets->SaveGlobalConfigurationMenuItem),"activate",G_CALLBACK(on_config_global_save),widgets);
    g_signal_connect(G_OBJECT(widgets->SaveLocalConfigurationMenuItem),"activate",G_CALLBACK(on_config_local_save),widgets);
    g_signal_connect(G_OBJECT(widgets->SaveExternalConfigurationMenuItem),"activate",G_CALLBACK(on_config_custom_save),widgets); 

    g_signal_connect(G_OBJECT(widgets->ReadFullLogButton),"clicked",G_CALLBACK(on_process_log_view),widgets);
    g_signal_connect(G_OBJECT(widgets->ReadShortLogButton),"clicked",G_CALLBACK(on_summary_log_view),widgets);

    g_signal_connect(G_OBJECT(widgets->GpartedCommonButton),"clicked",G_CALLBACK(on_gparted_open),NULL);
    g_signal_connect(G_OBJECT(widgets->GpartedSameButton),"clicked",G_CALLBACK(on_gparted_open),NULL);
    g_signal_connect(G_OBJECT(widgets->GpartedNearButton),"clicked",G_CALLBACK(on_gparted_open),NULL);

    g_signal_connect(G_OBJECT(widgets->Notebook),"switch-page",G_CALLBACK(on_page_changed),widgets);
    g_signal_connect(G_OBJECT(widgets->MainWindow),"check-resize",G_CALLBACK(on_region_resized),widgets);
    g_signal_connect(G_OBJECT(widgets->BackButton),"clicked",G_CALLBACK(on_page_navigation_clicked),widgets);
    g_signal_connect(G_OBJECT(widgets->NextButton),"clicked",G_CALLBACK(on_page_navigation_clicked),widgets);
    g_signal_connect(G_OBJECT(widgets->CancelInstallButton),"clicked",G_CALLBACK(on_page_navigation_clicked),widgets);
    g_signal_connect(G_OBJECT(widgets->AvailableLanguagesButton),"clicked",G_CALLBACK(on_language_clicked),widgets);
    g_signal_connect(G_OBJECT(widgets->RegionCombo),"changed",G_CALLBACK(on_region_changed),widgets);
    g_signal_connect(G_OBJECT(widgets->AddButton),"clicked",G_CALLBACK(on_keyboard_clicked),widgets);

    g_signal_connect(G_OBJECT(widgets->UsersToggle),"toggled",G_CALLBACK(on_toggle_block),NULL);
    g_signal_connect(G_OBJECT(widgets->LicenceToggle),"toggled",G_CALLBACK(on_toggle_block),NULL);
    g_signal_connect(G_OBJECT(widgets->WelcomeToggle),"toggled",G_CALLBACK(on_toggle_block),NULL);
    g_signal_connect(G_OBJECT(widgets->KeyboardToggle),"toggled",G_CALLBACK(on_toggle_block),NULL);
    g_signal_connect(G_OBJECT(widgets->LocationToggle),"toggled",G_CALLBACK(on_toggle_block),NULL);
    g_signal_connect(G_OBJECT(widgets->SectionsToggle),"toggled",G_CALLBACK(on_toggle_block),NULL);
    g_signal_connect(G_OBJECT(widgets->InstallationToggle),"toggled",G_CALLBACK(on_toggle_block),NULL);
    g_signal_connect(G_OBJECT(widgets->CompletionToggle),"toggled",G_CALLBACK(on_toggle_block),NULL);
    g_signal_connect(G_OBJECT(widgets->InstallationNearSysDevicesTree),"cursor-changed",G_CALLBACK(on_near_installation_device_changed),widgets);
    g_signal_connect(G_OBJECT(widgets->SamePlaceDeviceTree),"cursor-changed",G_CALLBACK(on_near_installation_device_changed),widgets);
    g_signal_connect(G_OBJECT(widgets->UserdataDevicesTree),"cursor-changed",G_CALLBACK(on_near_installation_device_changed),widgets);
    g_signal_connect(G_OBJECT(widgets->OSDevicesTree),"cursor-changed",G_CALLBACK(on_near_installation_device_changed),widgets);
    g_signal_connect(G_OBJECT(widgets->SeparateDevicesTree),"cursor-changed",G_CALLBACK(on_separate_installation_changed),widgets);

    g_signal_connect(G_OBJECT(widgets->ConfigurationModeMenuItem),"toggled",G_CALLBACK(on_configuration_mode_switch),widgets);
    g_signal_connect(G_OBJECT(widgets->DocumentationMenuItem),"activate",G_CALLBACK(on_open_documentation_confirmation),widgets);
    g_signal_connect(G_OBJECT(widgets->AboutMenuItem),"activate",G_CALLBACK(on_about),widgets);

    g_signal_connect(G_OBJECT(widgets->SamePlacePartTree),"cursor-changed",G_CALLBACK(on_partition_changed),widgets);
    g_signal_connect(G_OBJECT(widgets->InstallationNearSysSectionTree),"cursor-changed",G_CALLBACK(on_partition_changed),widgets);
    gtk_tree_model_filter_set_visible_column(GTK_TREE_MODEL_FILTER(widgets->LayoutsFilter),3);

    g_signal_connect(G_OBJECT(widgets->LanguageCombo),"changed",G_CALLBACK(on_locale_changed),widgets);
    g_signal_connect(G_OBJECT(widgets->AdditionalSoftwareCell),"toggled",G_CALLBACK(on_additional_software_toggled),widgets);

    g_signal_connect(G_OBJECT(widgets->ManualLayoutRadio),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),gtk_widget_get_parent(gtk_widget_get_parent(widgets->AddButton)));
    
    g_signal_connect(G_OBJECT(widgets->AutoHostnameCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button_inversed),widgets->HotnameEntry);

    g_signal_connect(G_OBJECT(widgets->NextInstallationFormatCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),widgets->NextInstallationFilesystemTypeCombo);
    g_signal_connect(G_OBJECT(widgets->SameInstallationFormatCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),widgets->SameInstallationFilesystemTypeCombo);
    g_signal_connect(G_OBJECT(widgets->HostnameSensitiveCheck),"toggled",G_CALLBACK(on_autohostname_sensitiveness_check),widgets);
    g_signal_connect(G_OBJECT(widgets->AutoHostnameCheck),"toggled",G_CALLBACK(on_autohostname_check),widgets);
    g_signal_connect(G_OBJECT(widgets->HotnameEntry),"changed",G_CALLBACK(on_hostname_entry_changed),widgets);

    g_signal_connect(G_OBJECT(widgets->PasswordCombo),"changed",G_CALLBACK(yon_password_combo_set_sensitive),widgets);
    g_signal_connect(G_OBJECT(widgets->AdminPasswordCombo),"changed",G_CALLBACK(yon_password_combo_set_sensitive),widgets);
    g_signal_connect(G_OBJECT(widgets->RootPasswordSensitiveCheck),"toggled",G_CALLBACK(yon_password_set_sensitive_from_toggle),widgets);
    g_signal_connect(G_OBJECT(widgets->PasswordSensitiveCheck),"toggled",G_CALLBACK(yon_password_set_sensitive_from_toggle),widgets);

    gtk_tree_model_filter_set_visible_column(GTK_TREE_MODEL_FILTER(widgets->LanguagesFilter),0);
    gtk_tree_model_filter_refilter(GTK_TREE_MODEL_FILTER(widgets->LanguagesFilter));

    gtk_window_set_title(GTK_WINDOW(widgets->MainWindow),TITLE_LABEL);
    gtk_window_set_icon_name(GTK_WINDOW(widgets->MainWindow),icon_path);

    int size;
    config_str parsed = yon_file_open(licence_path,&size);
    if (size){
        char *licence = yon_char_parsed_to_string(parsed,size,"");
        gtk_label_set_text(GTK_LABEL(widgets->LicenceLabel),licence);
        free(licence);
        yon_char_parsed_free(parsed,size);
    }

    config_str slides = yon_char_parsed_new(&size,slide_repeat_path);
    widgets->regions_original = gdk_pixbuf_new_from_resource(regions_path,NULL);
    widgets->keyboard_original = gdk_pixbuf_new_from_resource(keyboard_path,NULL);
    widgets->slides_original = malloc(sizeof(GdkPixbuf*)*size);
    widgets->slides_original[0] = gdk_pixbuf_new_from_resource(slide_0_path,NULL);
    for (int i=1;i<size;i++){
        widgets->slides_original[i] = gdk_pixbuf_new_from_resource(slides[i-1],NULL);
    }
    yon_char_parsed_free(slides,size);
    int width = gdk_pixbuf_get_width(widgets->regions_original);
    int height = gdk_pixbuf_get_height(widgets->regions_original);
    widgets->region_height_mult = (float)height/width; 
    gtk_image_set_from_pixbuf(GTK_IMAGE(widgets->RegionImage),gdk_pixbuf_scale_simple(widgets->regions_original,600,400,GDK_INTERP_BILINEAR));
    gtk_image_set_from_pixbuf(GTK_IMAGE(widgets->KeyboardImage),gdk_pixbuf_scale_simple(widgets->keyboard_original,600,400,GDK_INTERP_BILINEAR));
    gtk_image_set_from_pixbuf(GTK_IMAGE(widgets->SlidesImage),gdk_pixbuf_scale_simple(widgets->slides_original[0],600,400,GDK_INTERP_BILINEAR));

    GtkTreeIter iter;
    gtk_list_store_clear(widgets->LanguagesList);
    parsed = yon_file_open(languages_path,&size);
    for (int i=0;i<size;i++){
        int cur_size;
        yon_char_remove_last_symbol(parsed[i],'\n')
        config_str cur = yon_char_parse(parsed[i],&cur_size,";");
        if (cur_size){
            gtk_list_store_append(widgets->LanguagesList,&iter);
            gtk_list_store_set(widgets->LanguagesList,&iter,0,0,1,_(cur[1]),2,cur[0],-1);
        }
        yon_char_parsed_free(cur,cur_size);
    }
    yon_char_parsed_free(parsed,size);

    parsed = yon_dir_get_contents(zone_path,&size);
    for (int i=0;i<size;i++){
        if (!strstr(parsed[i],".")&&strcmp(parsed[i],"posix")&&strcmp(parsed[i],"right")){
            char *path = yon_char_append(zone_path,parsed[i]);
            if (yon_file_is_directory(path)){
                gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(widgets->RegionCombo),parsed[i],_(parsed[i]));
            }
            free(path);
        }
    }
    gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->RegionCombo),0);
    yon_char_parsed_free(parsed,size);
    parsed = yon_config_load(get_layouts_command,&size);
    GtkTreeIter itar;
    for (int i=0;i<size;i++){
        yon_char_remove_last_symbol(parsed[i],'\n');
        int layout_size;
        config_str layout = yon_char_parse(parsed[i],&layout_size,"|");
        if (layout_size){
            char *layout_id = yon_char_new(layout[0]);
            gtk_tree_store_append(widgets->LayoutList,&iter,NULL);
            gtk_tree_store_set(widgets->LayoutList,&iter,0,layout[0],1,_(layout[1]),2,1,-1);
            yon_char_parsed_free(layout,layout_size);
            layout = yon_config_load(get_layouts_local_command(layout_id),&layout_size);
            for (int j=0;j<layout_size;j++){
                yon_char_remove_last_symbol(layout[j],'\n');
                int parsed_size;
                config_str layouts_parsed = yon_char_parse(layout[j],&parsed_size,"|");
                if (parsed_size){
                    gtk_tree_store_append(widgets->LayoutList,&itar,&iter);
                    gtk_tree_store_set(widgets->LayoutList,&itar,0,layouts_parsed[0],1,_(layouts_parsed[1]),2,1,3,0,-1);
                    yon_char_parsed_free(layouts_parsed,parsed_size);
                }
            }
            if (layout_size==-1) {
                gtk_tree_store_set(widgets->LayoutList,&iter,2,1,-1);
            }
            yon_char_parsed_free(layout,layout_size);
        }
    }
    yon_char_parsed_free(parsed,size);
    {
        parsed = yon_config_load(get_devices_command,&size);
        char *string = yon_char_parsed_to_string(parsed,size,"");
        struct json_object *root;
        struct json_object *blockdevices;
        root = json_tokener_parse(string);
        json_object_object_get_ex(root, "blockdevices", &blockdevices);
        for (long unsigned int i = 0; i < json_object_array_length(blockdevices); i++) {
            struct json_object *device = json_object_array_get_idx(blockdevices, i);
            struct json_object *path, *size, *model, *vendor, *serial;

            json_object_object_get_ex(device, "path", &path);
            json_object_object_get_ex(device, "size", &size);
            json_object_object_get_ex(device, "model", &model);
            json_object_object_get_ex(device, "vendor", &vendor);
            json_object_object_get_ex(device, "serial", &serial);

            gtk_list_store_append(widgets->DevicesList,&iter);
            gtk_list_store_set(widgets->DevicesList,&iter,0,json_object_get_string(path),1,json_object_get_string(model),2,json_object_get_string(serial),3,json_object_get_string(size),4,json_object_get_string(vendor),-1);
        }
        yon_char_parsed_free(parsed,size);
    }
    
    parsed = yon_resource_open_file(additional_software_path,&size);
    for (int i=1;i<size;i++){
        int module_size;
        config_str module_parsed = yon_char_parse(parsed[i],&module_size,"|");
        if (module_size){
            gtk_list_store_append(widgets->AdditionalSoftwareList,&iter);
            gtk_list_store_set(widgets->AdditionalSoftwareList,&iter,0,1,1,module_parsed[0],3,module_parsed[1],-1); //2,module_parsed[2]
        }
    }

    config_str models = yon_config_load(get_models_command,&size);
    for (int i=0;i<size;i+=2){
        models[i] = yon_char_divide_search(models[i],"\n",-1);
        models[i+1] = yon_char_divide_search(models[i+1],"\n",-1);
        gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(widgets->KeyboardModelCombo),models[i],_(models[i+1]));
    }
    gtk_builder_connect_signals(builder,NULL);
    yon_load_proceed(YON_CONFIG_DEFAULT);
    yon_interface_update(widgets);
    return widgets;
}
 
int main(int argc, char *argv[]){ 
    local=setlocale(LC_ALL, ""); 
    textdomain (LocaleName); 
    config_init(); 
    int option_index=0; 
    int show_help=0; 
    { 
        struct option long_options[] = { 
                {"help", 0, 0, 'h'}, 
                {"version", 0, 0, 'V'}, 
                {"lock-help", 0,0, 1}, 
                {"lock-save", 0,0, 2}, 
                {"lock-save-local", 0,0, 3}, 
                {"lock-save-global", 0,0, 4}, 
                {"lock-load-global", 0,0, 5}, 
                {"socket-id", 1, 0, 's'}, 
                {"socket-ext-id", 1,0, 'e'}, 
                {"socket-trd-id", 1,0, 't'}, 
                {"clear-config", 0,0, 'c'}, 
                {"debug", 0,0, 'd'}, 
                { NULL, 0, NULL, 0 } 
        }; 
        for (int i=0;i<argc;i++){ 
            int argument=getopt_long(argc,argv,"hVvs:e:t:cd",long_options,&option_index); 
            switch(argument){ 
                case 'h': 
                    show_help=1; 
                    break; 
                case 'v': 
                case 'V': 
                    printf("%s\n",VERSION_LABEL); 
                    exit(0); 
                    break; 
                case 's': 
                    if(optarg) 
                        main_config.socket_id=atoi(optarg); 
                    break; 
                case 'e': 
                    if(optarg) 
                        main_config.save_socket_id=atoi(optarg); 
                    break; 
                case 't': 
                    if(optarg) 
                        main_config.load_socket_id=atoi(optarg); 
                    break; 
                case 'c': if (system(yon_char_unite("rm -rfd ", yon_ubl_user_get_home_directory(),"/.config/",LocaleName,"/",NULL))){}; 
                    break; 
                case 'd': main_config.debug_mode=1; 
                    break;
                case 1: 
                    main_config.lock_help=1; 
                    break; 
                case 2: 
                    main_config.lock_save_local=1; 
                    main_config.lock_save_global=1; 
                    break; 
                case 3: 
                    main_config.lock_save_local=1; 
                    break; 
                case 4: 
                    main_config.lock_save_global=1; 
                    break; 
                case 5: 
                    main_config.lock_load_global=1; 
                    break;
            } 
        } 
        if (show_help==1&&main_config.lock_help!=1){ 
            printf("%s\n",HELP_LABEL(NULL)); 
            exit(0); 
            } 
    } 
 
    if (getuid()!=0){ 
        main_config.lock_load_global=1; 
        main_config.lock_save_global=1; 
        main_config.lock_save_local=1; 
    } 
    gtk_init(&argc,&argv); 
    main_window *widgets = NULL;
    widgets = yon_main_window_complete(); 
    yon_window_config_setup(GTK_WINDOW(widgets->MainWindow));

    yon_window_config_load(config_path);
    GtkCssProvider *css=gtk_css_provider_new();
    gtk_css_provider_load_from_resource(css,CssPath);
    gtk_style_context_add_provider_for_screen(gdk_screen_get_default(),
                            GTK_STYLE_PROVIDER(css),
                            -1);
    gtk_main(); 
}