#include "ubl-settings-update.h"

config main_config;

//functions

void on_toggle_button_toggled(GtkWidget *self, main_window *widgets){
    if (self == widgets->AutoUpdateCheck){
        
        if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->AutoUpdateCheck))){
            yon_config_register(AUTOUPDATE,AUTOUPDATE_command,"enable");
            on_toggle_button_toggled(widgets->UpdateIntervalDefaultCheck,widgets); 
            gtk_widget_set_sensitive(widgets->UpdateModeCombo,1);
            on_toggle_button_toggled(widgets->UpdateModeCombo,widgets);
        } else {
            yon_config_remove_by_key(AUTOUPDATE);
            yon_config_remove_by_key(AUTOUPDATE_interval);
            on_toggle_button_toggled(widgets->UpdateIntervalDefaultCheck,widgets); 
            gtk_widget_set_sensitive(widgets->UpdateModeCombo,0);
            gtk_widget_set_sensitive(widgets->UpdateRepoListCheck,0);
        }

    } else if (self == widgets->UpdateModeCombo){
        gtk_widget_set_sensitive(widgets->UpdateRepoListCheck,0);
            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->UpdateRepoListCheck),0);
        int save_mode = gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->UpdateModeCombo));
        switch (save_mode){
            case 0: yon_config_remove_by_key(AUTOUPDATE_mode);
                yon_config_remove_by_key(AUTOUPDATE_repos);
                break;
            case 1:yon_config_register(AUTOUPDATE_mode,AUTOUPDATE_mode_command,"modsys");
                yon_config_remove_by_key(AUTOUPDATE_repos);
                break;
            case 2:yon_config_register(AUTOUPDATE_mode,AUTOUPDATE_mode_command,"modules");
                yon_config_remove_by_key(AUTOUPDATE_repos);
                break;
            case 3:{
                yon_config_register(AUTOUPDATE_mode,AUTOUPDATE_mode_command,"system");
                gtk_widget_set_sensitive(widgets->UpdateRepoListCheck,1);
                yon_config_remove_by_key(AUTOUPDATE_repos);
            }
                break;
        }
        
    } else if (self == widgets->UpdateIntervalDefaultCheck||self == widgets->UpdateIntervalSpin|| self == widgets->UpdateIntervalCombo || self == widgets->BootCheck){
        if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->UpdateIntervalDefaultCheck))){
            yon_config_remove_by_key(AUTOUPDATE_interval);
            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->BootCheck),0);
            gtk_widget_set_sensitive(widgets->BootCheck,0);
            gtk_widget_set_sensitive(widgets->UpdateIntervalSpin,0);
            gtk_widget_set_sensitive(widgets->UpdateIntervalCombo,0);
            return;
        } else {
            if (!gtk_spin_button_get_value(GTK_SPIN_BUTTON(widgets->UpdateIntervalSpin))){
            yon_config_remove_by_key(AUTOUPDATE_interval);
            }
            char *int_str = yon_char_from_long(gtk_spin_button_get_value(GTK_SPIN_BUTTON(widgets->UpdateIntervalSpin)));
            char *interval = "";
            if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->BootCheck))) interval = "boot";
            switch(gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->UpdateIntervalCombo))){
                case 0: interval = yon_char_unite(!yon_char_is_empty(interval)?interval:"",!yon_char_is_empty(interval)?",":"",int_str,"min",NULL);
                    break;
                case 1: interval = yon_char_unite(!yon_char_is_empty(interval)?interval:"",!yon_char_is_empty(interval)?",":"",int_str,"h",NULL);
                    break;
                case 2: interval = yon_char_unite(!yon_char_is_empty(interval)?interval:"",!yon_char_is_empty(interval)?",":"",int_str,"d",NULL);
                    break;
                case 3: interval = yon_char_unite(!yon_char_is_empty(interval)?interval:"",!yon_char_is_empty(interval)?",":"",int_str,"M",NULL);
                    break;
            }
            yon_config_register(AUTOUPDATE_interval,AUTOUPDATE_interval_command,interval);
            gtk_widget_set_sensitive(widgets->BootCheck,1);
            gtk_widget_set_sensitive(widgets->UpdateIntervalSpin,1);
            gtk_widget_set_sensitive(widgets->UpdateIntervalCombo,1);
        }
        
        
    } else if (self == widgets->UpdateRepoListCheck||self == widgets->UpdateRepoTree){
        if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->UpdateRepoListCheck))){
            yon_config_remove_by_key(AUTOUPDATE_repos);
        } else {
            char *repos = "";
            GtkTreeIter iter;
            for_iter(GTK_TREE_MODEL(widgets->ReposList),&iter){
                char *target;
                int status;
                gtk_tree_model_get(GTK_TREE_MODEL(widgets->ReposList),&iter,6,&status,1,&target,-1);
                if (status){
                    char *temp = yon_char_unite(repos,!yon_char_is_empty(repos)?",":"",target,NULL);
                    if (!yon_char_is_empty(repos)) free(repos);
                    repos = temp;
                }
            }
            yon_config_register(AUTOUPDATE_repos,AUTOUPDATE_repos_command,repos);
        }
        
    } else if (self == widgets->RepositoriesRepoListConfigurationCheck||self == widgets->RepositoriesDisableSystemReposCheck){
        if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->RepositoriesRepoListConfigurationCheck))){
            int disable_repo_active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->RepositoriesDisableSystemReposCheck));
                GtkTreeModel *model = GTK_TREE_MODEL(widgets->ReposList);
                GtkTreeIter iter;
                for_iter(model,&iter){
                    char *name;
                    gtk_tree_model_get(model,&iter,1,&name,-1);
                    char *compare_value = REPOSITORY(name);
                    if (!config(compare_value)||yon_config_check_ignore(compare_value)||yon_config_get_status(compare_value)<0){
                            gtk_list_store_set(widgets->ReposList,&iter,5,!disable_repo_active,-1);
                    } else {
                            gtk_list_store_set(widgets->ReposList,&iter,5,1,-1);
                    }
                }
            if (disable_repo_active){
                yon_config_register(REPOSITORY_parameter,REPOSITORY_parameter_command,"only");
            } else {
                yon_config_register(REPOSITORY_parameter,REPOSITORY_parameter_command,"enable");
            }
        } else {
                yon_config_register(REPOSITORY_parameter,REPOSITORY_parameter_command,"disable");
                int size = 0;
                config_str repos = yon_config_get_all_by_key(REPOSITORY_search,&size);
                for (int i=0;i<size;i++){
                    
                    char *key = yon_char_divide_search(repos[i],"=",-1);
                    // yon_config_remove_ignore(key);
                    yon_config_compare_ignore_set(key,0);
                    free(key);
                }
        }
        
    } else if (self == widgets->PublicationConnectPublicCheck||self == widgets->RecieveDBFromNetCheck||self == widgets->PublicationCheck||self == widgets->PublicationTree){
        char *repo_net = "";
        if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->PublicationConnectPublicCheck))){
                repo_net = NULL;
                repo_net = "enable";
            if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->RecieveDBFromNetCheck))){
                if (!repo_net) repo_net = ",db";
                else repo_net = yon_char_unite(repo_net,",","db",NULL);
            }
            char *repos = "";
            GtkTreeIter iter;
            int disabled_count=0;
            for_iter(GTK_TREE_MODEL(widgets->PublicationList),&iter){
                char *target;
                int status;
                gtk_tree_model_get(GTK_TREE_MODEL(widgets->PublicationList),&iter,0,&status,1,&target,-1);
                if (status){
                    char *temp = yon_char_unite(repos,!yon_char_is_empty(repos)?",":"",target,NULL);
                    if (!yon_char_is_empty(repos)) free(repos);
                    repos = temp;
                } else {
                    disabled_count++;
                }
            }
            if (!yon_char_is_empty(repos)&&disabled_count){
                repo_net = yon_char_unite(repo_net,",",repos,NULL);
            }
        } else {
            repo_net = "disable";
            if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->RecieveDBFromNetCheck))){
                if (!repo_net) repo_net = ",db";
                else repo_net = yon_char_unite(repo_net,",","db",NULL);
            } else {
                // repo_net = yon_char_unite(repo_net,",",NULL);
            }
        }
        if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->PublicationCheck))){
            yon_config_remove_by_key(REPOPUBLIC_NET_parameter);
        }
        yon_config_register(REPOPUBLIC_NET_parameter,REPOPUBLIC_NET_parameter_command,repo_net);
        
    } else if (self == widgets->MirrorPublicCheck){
        if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->MirrorPublicCheck))){
            yon_config_register(REPOPUBLIC_CACHE,REPOPUBLIC_CACHE_command,"enable");
        } else {
            yon_config_register(REPOPUBLIC_CACHE,REPOPUBLIC_CACHE_command,"disable");

        }
        
    }
}

void on_update_mode_changed(GtkWidget *, main_window *widgets){
    int active = gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->UpdateModeCombo));
    if (active == 3){
        gtk_widget_set_sensitive(widgets->UpdateRepoListCheck,0);
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->UpdateRepoListCheck),0);
    } else {
        gtk_widget_set_sensitive(widgets->UpdateRepoListCheck,1);
    }
}

void yon_update_toggled(GtkWidget *self, main_window *widgets){
    g_signal_handlers_block_by_func(G_OBJECT(self),G_CALLBACK(yon_update_toggled),widgets);
    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->AutoUpdateCheck))){
        gtk_widget_set_sensitive(widgets->UpdateIntervalDefaultCheck,1);
        int status = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->UpdateIntervalDefaultCheck));
        gtk_widget_set_sensitive(GTK_WIDGET(widgets->BootCheck),!status);
        gtk_widget_set_sensitive(GTK_WIDGET(widgets->UpdateIntervalSpin),!status);
        gtk_widget_set_sensitive(GTK_WIDGET(widgets->UpdateIntervalCombo),!status);
        status = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->BootCheck));
        gtk_widget_set_sensitive(GTK_WIDGET(widgets->UpdateModeCombo),1);

    } else {
        gtk_widget_set_sensitive(GTK_WIDGET(widgets->UpdateIntervalDefaultCheck),0);
        gtk_widget_set_sensitive(GTK_WIDGET(widgets->BootCheck),0);
        gtk_widget_set_sensitive(GTK_WIDGET(widgets->UpdateIntervalSpin),0);
        gtk_widget_set_sensitive(GTK_WIDGET(widgets->UpdateIntervalCombo),0);
        gtk_widget_set_sensitive(GTK_WIDGET(widgets->UpdateModeCombo),0);
        
    }
    g_signal_handlers_unblock_by_func(G_OBJECT(self),G_CALLBACK(yon_update_toggled),widgets);
}

void yon_interface_update(main_window *widgets){

        g_signal_handlers_block_by_func(G_OBJECT(widgets->BootCheck),G_CALLBACK(on_toggle_button_toggled),widgets);
    g_signal_handlers_block_by_func(G_OBJECT(widgets->PublicationCheck),G_CALLBACK(on_toggle_button_toggled),widgets);
    g_signal_handlers_block_by_func(G_OBJECT(widgets->UpdateIntervalSpin),G_CALLBACK(on_toggle_button_toggled),widgets);
    g_signal_handlers_block_by_func(G_OBJECT(widgets->UpdateIntervalCombo),G_CALLBACK(on_toggle_button_toggled),widgets);
    g_signal_handlers_block_by_func(G_OBJECT(widgets->AutoUpdateCheck),G_CALLBACK(on_toggle_button_toggled),widgets);

    g_signal_handlers_block_by_func(G_OBJECT(widgets->UpdateModeCombo),G_CALLBACK(on_toggle_button_toggled),widgets);
    g_signal_handlers_block_by_func(G_OBJECT(widgets->UpdateIntervalDefaultCheck),G_CALLBACK(on_toggle_button_toggled),widgets);
    g_signal_handlers_block_by_func(G_OBJECT(widgets->UpdateRepoListCheck),G_CALLBACK(on_toggle_button_toggled),widgets);
    g_signal_handlers_block_by_func(G_OBJECT(widgets->RepositoriesRepoListConfigurationCheck),G_CALLBACK(on_toggle_button_toggled),widgets);
    g_signal_handlers_block_by_func(G_OBJECT(widgets->RepositoriesDisableSystemReposCheck),G_CALLBACK(on_toggle_button_toggled),widgets);
    g_signal_handlers_block_by_func(G_OBJECT(widgets->PublicationConnectPublicCheck),G_CALLBACK(on_toggle_button_toggled),widgets);
    g_signal_handlers_block_by_func(G_OBJECT(widgets->RecieveDBFromNetCheck),G_CALLBACK(on_toggle_button_toggled),widgets);
    g_signal_handlers_block_by_func(G_OBJECT(widgets->MirrorPublicCheck),G_CALLBACK(on_toggle_button_toggled),widgets);
    gtk_list_store_clear(widgets->ReposList);
    gtk_list_store_clear(widgets->MirrorList);
    // gtk_list_store_clear(widgets->UpdateRepoList);
    gtk_list_store_clear(widgets->PublicationList);
    gtk_list_store_clear(widgets->WebPublicationList);
    int size;
    GtkTreeIter iter;
    char *last_update_time = config(AUTOUPDATE_timestamp);
    if (!yon_char_is_empty(last_update_time)){
        int datetime_size;
        config_str datetime_parsed = yon_char_parse(last_update_time,&datetime_size," ");
        int year, month, day, hour, minute;
        int date_parsed_size, time_parsed_size;
        config_str date_parsed = yon_char_parse(datetime_parsed[0],&date_parsed_size,"-");
        config_str time_parsed = yon_char_parse(datetime_parsed[1],&time_parsed_size,":");
        year = atoi(date_parsed[0]);
        month = atoi(date_parsed[1]);
        day = atoi(date_parsed[2]);
        hour = atoi(time_parsed[0]);
        minute = atoi(time_parsed[1]);
            GDateTime *datetime = g_date_time_new_utc(year,month,day,hour,minute,0.0);
            if (yon_char_is_empty(main_config.date_format)){
                yon_window_config_get_parameter("settings","date_format",&main_config.date_format,YON_TYPE_STRING);
                if (yon_char_is_empty(main_config.date_format)){
                    main_config.date_format="%d.%m.%Y %H:%M";
                }
            }
            char *time_label = g_date_time_format(datetime,main_config.date_format);
            gtk_entry_set_text(GTK_ENTRY(widgets->DateEntry),time_label);
            g_date_time_unref(datetime);
            free(time_label);
    }
    {
        char *repo_config = config(REPOSITORY_parameter);
                gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->RepositoriesRepoListConfigurationCheck),0);
                gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->RepositoriesDisableSystemReposCheck),0);
        
        config_str repos = yon_config_get_all_by_key(REPOSITORY_search,&size);
            for (int i=0;i<size;i++){
                char *current = yon_char_new(repos[i]);
                char *key = yon_char_divide_search(current,"=",-1);
                free(yon_char_divide_search(key,"[",-1));
                key[strlen(key)-1]='\0';
                int cur_size;
                config_str parsed = yon_char_parse(current,&cur_size,";");
                if (cur_size){
                    gtk_list_store_append(widgets->ReposList,&iter);
                    char *temp = strstr(parsed[0],",")?yon_char_replace(parsed[0],",","\n"):parsed[0];
                    parsed[0] = temp;
                    gtk_list_store_set(widgets->ReposList,&iter,0,(cur_size>3&&!strcmp(parsed[3],""))||cur_size<3?1:0,1,key,2,parsed[0],3,cur_size>1?parsed[1]:"",4,cur_size>2?parsed[2]:"",5,1,-1);

                }
                free(key);
                free(current);
            }
            yon_char_parsed_free(repos,size);
            if (!yon_char_is_empty(repo_config)){
            
            if (!strcmp(repo_config,"disable")){
                gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->RepositoriesRepoListConfigurationCheck),0);
            } else if (!strcmp(repo_config,"enable")){
                gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->RepositoriesRepoListConfigurationCheck),1);
            }else if (!strcmp(repo_config,"only")){
                gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->RepositoriesDisableSystemReposCheck),1);
                gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->RepositoriesRepoListConfigurationCheck),1);
                int disable_repo_active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->RepositoriesDisableSystemReposCheck));
                GtkTreeModel *model = GTK_TREE_MODEL(widgets->ReposList);
                GtkTreeIter iter;
                for_iter(model,&iter){
                    char *name;
                    gtk_tree_model_get(model,&iter,1,&name,-1);
                    char *compare_value = REPOSITORY(name);
                    if (!config(compare_value)||yon_config_check_ignore(compare_value)||yon_config_get_status(compare_value)<0){
                            gtk_list_store_set(widgets->ReposList,&iter,5,!disable_repo_active,-1);
                    } else {
                            gtk_list_store_set(widgets->ReposList,&iter,5,1,-1);
                    }
                }
            }
        }

    }
    {
        int repos_size;
        config_str publish_repos = yon_config_load(get_publication_list_command,&repos_size);
        char *publish = config(REPOPUBLIC_NET_parameter);
        if (publish) {
            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->PublicationCheck),1);
            int cur_size;
            config_str parsed = yon_char_parse(publish,&cur_size,",");
            if (cur_size){
                if (!strcmp(parsed[0],"disable")||!strcmp(parsed[0],"no")||!strcmp(parsed[0],"none")){
                    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->PublicationConnectPublicCheck),0);
                } else if (!strcmp(parsed[0],"enable")||!strcmp(parsed[0],"yes")){
                    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->PublicationConnectPublicCheck),1);
                }
                if (cur_size>1&&!strcmp(parsed[1],"db")){
                    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->RecieveDBFromNetCheck),1);
                } else {
                    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->RecieveDBFromNetCheck),0);
                }
                for (int i=0;i<repos_size;i++){
                    yon_char_remove_last_symbol(publish_repos[i],'\n');
                    gtk_list_store_append(widgets->PublicationList,&iter);
                        gtk_list_store_set(widgets->PublicationList,&iter,1,publish_repos[i],0,!(cur_size-2)||(cur_size-2&&yon_char_parsed_check_exist(parsed,cur_size,publish_repos[i])>-1)?1:0,-1);
                }
                if (cur_size>2){
                    for (int i=2;i<cur_size;i++){
                        if (yon_char_parsed_check_exist(publish_repos,repos_size,parsed[i])==-1){
                            gtk_list_store_append(widgets->PublicationList,&iter);
                            gtk_list_store_set(widgets->PublicationList,&iter,1,parsed[i],-1);
                        }
                    }
                }
                yon_char_parsed_free(parsed,cur_size);
            }
        } else {
                for (int i=0;i<repos_size;i++){
                    yon_char_remove_last_symbol(publish_repos[i],'\n');
                    gtk_list_store_append(widgets->PublicationList,&iter);
                        gtk_list_store_set(widgets->PublicationList,&iter,1,publish_repos[i],0,1,-1);
                }
            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->PublicationCheck),0);
        }
    }
    {
        char *mirror = config(REPOPUBLIC_CACHE);
        if (!yon_char_is_empty(mirror)){
            if (!strcmp(mirror,"enable")||!strcmp(mirror,"yes")){
                gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->MirrorPublicCheck),1);
            } else if (!strcmp(mirror,"disable")||!strcmp(mirror,"no")||!strcmp(mirror,"none")){
                gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->MirrorPublicCheck),0);
            }
        }

        config_str mirror_list = yon_config_get_all_by_key(REPOPUBLIC_CACHE_search,&size);
        if (size){
            for (int i=0;i<size;i++){
                if (yon_char_check_begins_with(mirror_list[i],REPOPUBLIC_CACHE_port)||
                yon_char_check_begins_with(mirror_list[i],REPOPUBLIC_CACHE_cache_dir)||
                yon_char_check_begins_with(mirror_list[i],REPOPUBLIC_CACHE_purge_files_after)||
                yon_char_check_begins_with(mirror_list[i],REPOPUBLIC_CACHE_download_timeout)||
                yon_char_check_begins_with(mirror_list[i],REPOPUBLIC_CACHE_http_proxy)||
                yon_char_check_begins_with(mirror_list[i],REPOPUBLIC_CACHE_user_agent)||
                yon_char_check_begins_with(mirror_list[i],REPOPUBLIC_CACHE_cron)||
                yon_char_check_begins_with(mirror_list[i],REPOPUBLIC_CACHE_ttl_unaccessed_in_days)||
                yon_char_check_begins_with(mirror_list[i],REPOPUBLIC_CACHE_ttl_unupdated_in_days)) continue;
                char *cur = yon_char_new(mirror_list[i]);
                char *key = yon_char_divide_search(cur,"=",-1);
                if (yon_char_is_empty(key)) continue;
                free(yon_char_divide_search(key,"[",-1));
                key[strlen(key)-1]='\0';

                    gtk_list_store_append(widgets->MirrorList,&iter);
                int cur_size;
                config_str parsed = yon_char_parse(cur,&cur_size,",");
                if (cur_size){
                    gtk_list_store_set(widgets->MirrorList,&iter,0,key,2,yon_char_parsed_to_string(parsed,cur_size,"\n"),-1);
                }
            }
        }
    }
    {
        char *autoupdate_config = config(AUTOUPDATE);
        if (!yon_char_is_empty(autoupdate_config)&&!strcmp(autoupdate_config,"enable")){
            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->AutoUpdateCheck),1);
        } else {
            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->AutoUpdateCheck),0);
            }

        autoupdate_config = config(AUTOUPDATE_mode);
        if (!yon_char_is_empty(autoupdate_config)){
            if (!strcmp(autoupdate_config,"modsys")){
                gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->UpdateModeCombo),1);
            } else if (!strcmp(autoupdate_config,"modules")){
                gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->UpdateModeCombo),2);
            } else if (!strcmp(autoupdate_config,"system")){
                gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->UpdateModeCombo),3);
            }
        } else {
            gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->UpdateModeCombo),0);
        }

        char *autoupdate_repos = config(AUTOUPDATE_repos);
        if (autoupdate_repos){
            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->UpdateRepoListCheck),1);
        } else {
            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->UpdateRepoListCheck),0);
        }
            int parsed_size;
            GtkTreeIter iter;
            config_str parsed = yon_char_parse(autoupdate_repos,&parsed_size,",");
            for_iter(GTK_TREE_MODEL(widgets->ReposList),&iter){
                char *target = NULL;
                gtk_tree_model_get(GTK_TREE_MODEL(widgets->ReposList),&iter,1,&target,-1);
                gtk_list_store_set(widgets->ReposList,&iter,6,!parsed_size||(yon_char_is_empty(autoupdate_repos)||(parsed_size&&yon_char_parsed_check_exist(parsed,parsed_size,target)>-1))?1:0,-1);
            }
            yon_char_parsed_free(parsed,parsed_size);
        autoupdate_config = config(AUTOUPDATE_interval);
        if (!yon_char_is_empty(autoupdate_config)){
            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->UpdateIntervalDefaultCheck),0);
                int parsed_size;
                config_str parsed = yon_char_parse(autoupdate_config,&parsed_size,",");
                if (yon_char_parsed_check_exist(parsed,parsed_size,"boot")!=-1){
                    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->BootCheck),1);
                }
                if (strstr(parsed[parsed_size-1],"min")){
                    gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->UpdateIntervalCombo),0);
                } else if (parsed[parsed_size-1][strlen(parsed[parsed_size-1])-1]=='h'){
                    gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->UpdateIntervalCombo),1);
                } else if (parsed[parsed_size-1][strlen(parsed[parsed_size-1])-1]=='d'){
                    gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->UpdateIntervalCombo),2);
                } else if (parsed[parsed_size-1][strlen(parsed[parsed_size-1])-1]=='M'){
                    gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->UpdateIntervalCombo),3);
                } 
                gtk_spin_button_set_value(GTK_SPIN_BUTTON(widgets->UpdateIntervalSpin),atol(parsed[parsed_size-1]));
        } else {
            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->UpdateIntervalDefaultCheck),1);
            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->BootCheck),0);
            gtk_spin_button_set_value(GTK_SPIN_BUTTON(widgets->UpdateIntervalSpin),0);
            gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->UpdateIntervalCombo),0);

        }
    }

    {
        config_str web_publish = yon_config_get_all_by_key(REPOPUBLIC_WEB_search,&size);
        for (int i=0;i<size;i++){
            gtk_list_store_append(widgets->WebPublicationList,&iter);
            char *cur = yon_char_new(web_publish[i]);
            char *key = yon_char_divide_search(cur,"=",-1);
            char *full_key = yon_char_new(key);
            free(yon_char_divide_search(key,"[",-1));
            key[strlen(key)-1]='\0';
            char *path = NULL;
            if (!strstr(key,":")){
                path=key;
                key=NULL;
            } else {
                path = yon_char_divide_search(key,":",-1);
            }
            int repos_size;
            config_str repos = NULL;
            if (!yon_char_is_empty(key)){
                repos = yon_char_parse(key,&repos_size,",");
            } else {
                repos = yon_file_list_dirs(path,&repos_size);
                int pool_pos = yon_char_parsed_check_exist(repos,repos_size,"pool");
                if (pool_pos!=-1){
                    repos = yon_char_parsed_rip(repos,&repos_size,pool_pos);
                }
            }
            if (repos_size){
            char *repos_paths = yon_char_parsed_to_string(repos,repos_size,",");
            if (!yon_char_is_empty(repos_paths)) free(repos_paths);
            if (!repos_size){
                int temp_size;
                config_str contents = yon_file_ls(path,&temp_size);
                for (int k=0;k<temp_size;k++){
                    char *full_content_path = yon_char_unite(path,"/",contents[k],NULL);
                    if (yon_file_is_directory(full_content_path)&&strcmp(contents[k],"pool")&&strcmp(contents[k],".")&&strcmp(contents[k],"..")){
                        yon_char_parsed_add_or_create_if_exists(repos,&repos_size,contents[k]);
                    }
                    free(full_content_path);
                }
                yon_char_parsed_free(contents,temp_size);

            }

            repos_paths = yon_char_parsed_to_string(repos,repos_size,"\n");
            gtk_list_store_set(widgets->WebPublicationList,&iter,2,repos_paths,8,full_key,-1);
            free(repos_paths);
            }

            gtk_list_store_set(widgets->WebPublicationList,&iter,1,path,-1);
            int cur_size;
            config_str parsed = yon_char_parse(cur,&cur_size,":");
            if (cur_size){
                if (!strcmp(parsed[0],"enable")||!strcmp(parsed[0],"yes")){
                    gtk_list_store_set(widgets->WebPublicationList,&iter,0,1,-1);
                } else if (!strcmp(parsed[0],"disable")||!strcmp(parsed[0],"no")||!strcmp(parsed[0],"none")) {
                    gtk_list_store_set(widgets->WebPublicationList,&iter,0,0,-1);
                }
                if (cur_size>1&&!strcmp(parsed[1],"listing")){
                    gtk_list_store_set(widgets->WebPublicationList,&iter,3,1,-1);
                }
                if (cur_size>2&&!yon_char_is_empty(parsed[2])){
                    gtk_list_store_set(widgets->WebPublicationList,&iter,4,parsed[2],-1);
                }
                if (cur_size>3&&!yon_char_is_empty(parsed[3])){
                    gtk_list_store_set(widgets->WebPublicationList,&iter,5,parsed[3],-1);
                }
                if (cur_size>4&&!yon_char_is_empty(parsed[4])){
                    if (!strcmp(parsed[4],"sha256")||!strcmp(parsed[4],"sha512")){
                        gtk_list_store_set(widgets->WebPublicationList,&iter,7,"******",-1);
                        gtk_list_store_set(widgets->WebPublicationList,&iter,6,parsed[4],-1);
                    } else {
                        if (strlen(parsed[4])==128||strlen(parsed[4])==64)
                            gtk_list_store_set(widgets->WebPublicationList,&iter,7,parsed[5],-1);
                        else
                            gtk_list_store_set(widgets->WebPublicationList,&iter,7,"******",-1);
                        if (cur_size>5&&!yon_char_is_empty(parsed[5])){
                            gtk_list_store_set(widgets->WebPublicationList,&iter,6,parsed[4],-1);
                        }
                    }
                }
            }
        }
    }
    {
        gtk_list_store_clear(widgets->FtpList);
        int size;
        config_str ftp_parameters = yon_config_get_all_by_key(REPOPUBLIC_FTP_search,&size);
        for (int i=0;i<size;i++){
            char *parameter_string = yon_char_new(ftp_parameters[i]);
            char *parameter_name = yon_char_divide_search(parameter_string,"=",-1);
            char *key = yon_config_parameter_get_key(parameter_name);
            char *repos = yon_char_replace(key,",","\n");
            char *storage = NULL;
            if (strstr(repos,":")){
                storage = yon_char_divide_search(repos,":",-1);
            } else {
                storage = repos;
                repos = NULL;
            }

            int parsed_size;
            config_str parsed = yon_char_parse(parameter_string,&parsed_size,":");
            int enabled = size>0&&(!strcmp(parsed[0],"enable")||!strcmp(parsed[0],"yes"));
            char *port = NULL;
            if (parsed_size>1&&!yon_char_is_empty(parsed[1])){
                port = parsed[1];
            }
            char *user = NULL;
            if (parsed_size>2&&!yon_char_is_empty(parsed[2])){
                user = parsed[2];
            }
            gtk_list_store_append(widgets->FtpList,&iter);
            gtk_list_store_set(widgets->FtpList,&iter,0,enabled,1,storage,2,repos,3,port,4,user,-1);
            yon_char_parsed_free(parsed,parsed_size);
        }
        yon_char_parsed_free(ftp_parameters,size);
    }

    g_signal_handlers_unblock_by_func(G_OBJECT(widgets->BootCheck),G_CALLBACK(on_toggle_button_toggled),widgets);
    g_signal_handlers_unblock_by_func(G_OBJECT(widgets->PublicationCheck),G_CALLBACK(on_toggle_button_toggled),widgets);
    g_signal_handlers_unblock_by_func(G_OBJECT(widgets->UpdateIntervalSpin),G_CALLBACK(on_toggle_button_toggled),widgets);
    g_signal_handlers_unblock_by_func(G_OBJECT(widgets->UpdateIntervalCombo),G_CALLBACK(on_toggle_button_toggled),widgets);
    g_signal_handlers_unblock_by_func(G_OBJECT(widgets->AutoUpdateCheck),G_CALLBACK(on_toggle_button_toggled),widgets);
    g_signal_handlers_unblock_by_func(G_OBJECT(widgets->UpdateModeCombo),G_CALLBACK(on_toggle_button_toggled),widgets);
    g_signal_handlers_unblock_by_func(G_OBJECT(widgets->UpdateIntervalDefaultCheck),G_CALLBACK(on_toggle_button_toggled),widgets);
    g_signal_handlers_unblock_by_func(G_OBJECT(widgets->UpdateRepoListCheck),G_CALLBACK(on_toggle_button_toggled),widgets);
    g_signal_handlers_unblock_by_func(G_OBJECT(widgets->RepositoriesRepoListConfigurationCheck),G_CALLBACK(on_toggle_button_toggled),widgets);
    g_signal_handlers_unblock_by_func(G_OBJECT(widgets->RepositoriesDisableSystemReposCheck),G_CALLBACK(on_toggle_button_toggled),widgets);
    g_signal_handlers_unblock_by_func(G_OBJECT(widgets->PublicationConnectPublicCheck),G_CALLBACK(on_toggle_button_toggled),widgets);
    g_signal_handlers_unblock_by_func(G_OBJECT(widgets->RecieveDBFromNetCheck),G_CALLBACK(on_toggle_button_toggled),widgets);
    g_signal_handlers_unblock_by_func(G_OBJECT(widgets->MirrorPublicCheck),G_CALLBACK(on_toggle_button_toggled),widgets);
}

// standard functions

char *on_save_repos(main_window *widgets){
    GtkTreeIter iter;
    int size=0;
    config_str queue = NULL;
    for_iter(GTK_TREE_MODEL(widgets->ReposList),&iter){
        char *target;
        gtk_tree_model_get(GTK_TREE_MODEL(widgets->ReposList),&iter,1,&target,-1);
        yon_char_parsed_add_or_create_if_exists(queue,&size,REPOSITORY(target));
    }
    int param_size;
    config_str parameters = yon_config_get_save_parameters_by_list(&param_size,queue,size);
    return yon_char_parsed_to_string(parameters,param_size," ");
}



void on_toggle_cell_toggled(GtkCellRenderer *self,char *path, main_window *widgets){
    GtkListStore *target = NULL;
    GtkWidget *table = NULL;
    GtkTreeIter iter;
    int status;
    if (self == widgets->UpdateToggleCell){
        target = widgets->ReposList;
        table = widgets->UpdateRepoTree;
        gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(target),&iter,path);
        gtk_tree_model_get(GTK_TREE_MODEL(target),&iter,6,&status,-1);
        gtk_list_store_set(GTK_LIST_STORE(target),&iter,6,!status,-1);
    } else if (self == widgets->PublicationToggleCell){
        target = widgets->PublicationList;
        table = widgets->PublicationTree;
        gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(target),&iter,path);
        gtk_tree_model_get(GTK_TREE_MODEL(target),&iter,0,&status,-1);
        gtk_list_store_set(GTK_LIST_STORE(target),&iter,0,!status,-1);

    }
    
    on_toggle_button_toggled(table,widgets);
}

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

}

void on_selection_changed(GtkWidget *self, main_window *widgets){
    GtkTreeModel *model;
    GtkTreeIter iter;
    if (self == widgets->RepositoriesTree){
        if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->RepositoriesTree)),&model,&iter)){
            gtk_widget_set_sensitive(widgets->RepositoriesMoveUpButton,1);
            gtk_widget_set_sensitive(widgets->RepositoriesMoveDownButton,1);
            gtk_widget_set_sensitive(widgets->RepositoriesEditButton,1);
            gtk_widget_set_sensitive(widgets->RepositoriesDeleteButton,1);
        } else {
            gtk_widget_set_sensitive(widgets->RepositoriesMoveUpButton,0);
            gtk_widget_set_sensitive(widgets->RepositoriesMoveDownButton,0);
            gtk_widget_set_sensitive(widgets->RepositoriesEditButton,0);
            gtk_widget_set_sensitive(widgets->RepositoriesDeleteButton,0);
        }
    } else if (self == widgets->WebPublicationTree){
        if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->WebPublicationTree)),&model,&iter)){
            gtk_widget_set_sensitive(widgets->WebPublicationEditButton,1);
            gtk_widget_set_sensitive(widgets->WebPublicationRemoveButton,1);
        } else {
            gtk_widget_set_sensitive(widgets->WebPublicationEditButton,0);
            gtk_widget_set_sensitive(widgets->WebPublicationRemoveButton,0);
        }
    } else if (self == widgets->MirrorTree){
        if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->MirrorTree)),&model,&iter)){
            gtk_widget_set_sensitive(widgets->MirrorEditButton,1);
            gtk_widget_set_sensitive(widgets->MirrorRemoveButton,1);
        } else {
            gtk_widget_set_sensitive(widgets->MirrorEditButton,0);
            gtk_widget_set_sensitive(widgets->MirrorRemoveButton,0);
        }
    } else if (self == widgets->FtpTree){
        if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->FtpTree)),&model,&iter)){
            gtk_widget_set_sensitive(widgets->FtpEditButton,1);
            gtk_widget_set_sensitive(widgets->FtpRemoveButton,1);
        } else {
            gtk_widget_set_sensitive(widgets->FtpEditButton,0);
            gtk_widget_set_sensitive(widgets->FtpRemoveButton,0);
        }
    }
}



void on_scrolled_window_size_allocate(GtkWidget *, GdkRectangle *allocation, repo_add_window *window){
    if (allocation->height<100){
        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(gtk_widget_get_parent(gtk_widget_get_parent(window->SourceListBox))),GTK_POLICY_NEVER,GTK_POLICY_NEVER);
        gtk_widget_set_size_request(gtk_widget_get_parent(gtk_widget_get_parent(window->SourceListBox)),-1,allocation->height);
    } else {
        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(gtk_widget_get_parent(gtk_widget_get_parent(window->SourceListBox))),GTK_POLICY_NEVER,GTK_POLICY_ALWAYS);
        gtk_widget_set_size_request(gtk_widget_get_parent(gtk_widget_get_parent(window->SourceListBox)),-1,100);
    }
}

void on_repo_add(GtkWidget *, main_window *widgets){
    gtk_tree_selection_unselect_all(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->MirrorTree)));
    repo_add_window *window = yon_repo_add_window_new();
    yon_gtk_window_setup(GTK_WINDOW(window->Window),GTK_WINDOW(widgets->Window),ADD_REPO_LABEL,icon_path,"add_repo_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->AcceptButton),"clicked",G_CALLBACK(on_repo_accept_clicked),dict);

}


void on_password_encryption_changed(GtkComboBox *self, password_window *dialog){
    int active = gtk_combo_box_get_active(self);
        gtk_widget_set_sensitive(dialog->NoEncriptionCheck,!!active);
        if (!active)
            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->NoEncriptionCheck),0);
}

void yon_hash_entry_sensitiveness_update(GtkWidget *, password_window *dialog){
    int hash_type_sensitive = gtk_combo_box_get_active(GTK_COMBO_BOX(dialog->EncryptionCombo));
    int encrypt_sensitive = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->NoEncriptionCheck));
    if (!encrypt_sensitive&&hash_type_sensitive) gtk_widget_set_sensitive(dialog->PasswordHashEntry,1);
    else gtk_widget_set_sensitive(dialog->PasswordHashEntry,0);
}

void on_password_open(GtkWidget *, web_publication_add_window *window){
    password_window *dialog = yon_password_window_new();
    g_signal_connect(G_OBJECT(dialog->NoEncriptionCheck),"toggled",G_CALLBACK(yon_hash_entry_sensitiveness_update),dialog);
    g_signal_connect(G_OBJECT(dialog->EncryptionCombo),"changed",G_CALLBACK(yon_hash_entry_sensitiveness_update),dialog);
    yon_gtk_entry_set_password_visibility_icon(GTK_ENTRY(dialog->PasswordEntry));
    yon_gtk_entry_set_password_visibility_icon(GTK_ENTRY(dialog->PasswordHashEntry));
    yon_gtk_entry_set_password_visibility_icon(GTK_ENTRY(dialog->RepeatPasswordEntry));
    char *old_password = yon_char_new(gtk_entry_get_text(GTK_ENTRY(window->UserPasswordEntry)));
    char *hash_type = NULL;
    if (!yon_char_is_empty(old_password)&&strstr(old_password,"|")){
        hash_type = yon_char_divide(old_password,6);
        gtk_combo_box_set_active_id(GTK_COMBO_BOX(dialog->EncryptionCombo),hash_type);
    }
    if (!yon_char_is_empty(old_password)&&(strlen(old_password)==128||strlen(old_password)==64)){
        dialog->old_password = old_password;
        gtk_entry_set_text(GTK_ENTRY(dialog->PasswordHashEntry),old_password);
    } else if (!yon_char_is_empty(old_password)){
        dialog->old_password = old_password;
        gtk_entry_set_text(GTK_ENTRY(dialog->PasswordEntry),old_password);
        gtk_entry_set_text(GTK_ENTRY(dialog->RepeatPasswordEntry),old_password);
    }
    dictionary *dict = NULL;
    yon_dictionary_add_or_create_if_exists_with_data(dict,"window",dialog);
    yon_dictionary_add_or_create_if_exists_with_data(dict,"target",window->UserPasswordEntry);
    g_signal_connect(G_OBJECT(dialog->AcceptButton),"clicked",G_CALLBACK(on_password_accept),dict);
    g_signal_connect(G_OBJECT(dialog->EncryptionCombo),"changed",G_CALLBACK(on_password_encryption_changed),dialog);
    yon_gtk_window_setup(GTK_WINDOW(dialog->Window),GTK_WINDOW(window->Window),PASSWORD_INPUT_LABEL,icon_path,"password_window");
}



void on_repo_remove(GtkWidget *self, main_window *widgets){
    dialog_confirmation_data *data = yon_confirmation_dialog_data_new();
    data->action_text=REMOVE_REPO_WARNING_LABEL;
    data->function=(void(*)(void*,void*))on_repositories_remove_accept;
    data->data = widgets;
    yon_confirmation_dialog_call(self,data);
}



void on_repositories_remove_accept(GtkWidget *, main_window *widgets){
    GtkTreeModel *model=NULL;
    GtkTreeIter iter;
    if (!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->RepositoriesTree)),&model,&iter)) {
        return;
    }
    char *repo;
    gtk_tree_model_get(model,&iter,1,&repo,-1);
    yon_config_remove_by_key(REPOSITORY(repo));
    yon_interface_update(widgets);
}

void on_repo_edit(GtkWidget *,main_window *widgets){
    repo_add_window *window = yon_repo_add_window_new();
    yon_gtk_window_setup(GTK_WINDOW(window->Window),GTK_WINDOW(widgets->Window),EDIT_REPO_LABEL,icon_path,"add_repo_window");
    gtk_label_set_text(GTK_LABEL(window->HeadLabel),EDIT_REPO_LABEL);
    GtkTreeIter iter;
    char *target;
    gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->RepositoriesTree)),NULL,&iter);
    gtk_tree_model_get(GTK_TREE_MODEL(widgets->ReposList),&iter,1,&target,-1);
    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->AcceptButton),"clicked",G_CALLBACK(on_repo_accept_clicked),dict);
    gtk_entry_set_text(GTK_ENTRY(window->RepoNameEntry),target);
    window->name = yon_char_new(target);
    int size;
    config_str parsed = yon_char_parse(config(REPOSITORY(target)),&size,";");
    if (size){
        {
            int cur_size;
            config_str repos = yon_char_parse(parsed[0],&cur_size,",");
            for (int i=0;i<cur_size;i++){
                GtkBuilder *builder = gtk_builder_new_from_resource(glade_repo_path_add_path);

                path_section *section = malloc(sizeof(path_section));
                section->PathRemovalBox = yon_gtk_builder_get_widget(builder,"PathRemovalBox");
                section->PathEditButton = yon_gtk_builder_get_widget(builder,"PathEditButton");
                section->PathEntry = yon_gtk_builder_get_widget(builder,"PathEntry");
                section->PathRemoveButton = yon_gtk_builder_get_widget(builder,"PathRemoveButton");
                section->TypeCombo = yon_gtk_builder_get_widget(builder,"TypeCombo");
                section->edits=0;

                    char *path = yon_char_new(repos[i]);
                if (strstr(repos[i],"file://")){
                    gtk_combo_box_set_active(GTK_COMBO_BOX(section->TypeCombo),0);
                    free(yon_char_divide(path,6));

                } else if (strstr(repos[i],"ftp://")){
                    gtk_combo_box_set_active(GTK_COMBO_BOX(section->TypeCombo),1);
                    free(yon_char_divide(path,5));

                } else if (strstr(repos[i],"http://")){
                    gtk_combo_box_set_active(GTK_COMBO_BOX(section->TypeCombo),2);
                    free(yon_char_divide(path,6));

                } else if (strstr(repos[i],"https://")){
                    gtk_combo_box_set_active(GTK_COMBO_BOX(section->TypeCombo),3);
                    free(yon_char_divide(path,7));

                } else {
                    gtk_combo_box_set_active(GTK_COMBO_BOX(section->TypeCombo),4);

                }
                    gtk_entry_set_text(GTK_ENTRY(section->PathEntry),path);
                    free(path);
                yon_dictionary_add_or_create_if_exists_with_data(window->sections,(char*)target,section);

                gtk_box_pack_start(GTK_BOX(window->SourceBox),section->PathRemovalBox,0,0,0);
                g_signal_connect(gtk_builder_get_object(builder,"PathEditButton"),"clicked",G_CALLBACK(on_mirror_path_edit),window);
                g_signal_connect(gtk_builder_get_object(builder,"PathRemoveButton"),"clicked",G_CALLBACK(on_mirror_path_removed),window);
            }
            gtk_widget_show(window->SourceListBox);
            yon_char_parsed_free(repos,cur_size);
        }
        if (size>1&&!yon_char_is_empty(parsed[1])){ //siglevel
            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->SignDefaultCheck),0);
            int cur_size;
            config_str siglevel = yon_char_parse(parsed[1],&cur_size,",");
            
            GtkTreeModel *model = GTK_TREE_MODEL(window->SignList);
            GtkTreeIter iter;
            for_iter (model,&iter){
                char *target;
                gtk_tree_model_get(model,&iter,1,&target,-1);
                if (yon_char_parsed_check_exist(siglevel,cur_size,target)>-1){
                    gtk_list_store_set(window->SignList,&iter,0,1,-1);
                } else {
                    gtk_list_store_set(window->SignList,&iter,0,0,-1);

                }
            }
            gtk_entry_set_text(GTK_ENTRY(window->SignLevelCheckEntry),parsed[1]);
        }
        if (size>2&&!yon_char_is_empty(parsed[2])){ //usage
            int usage_size;
            config_str usage = yon_char_parse(parsed[2],&usage_size,",");
            for (int i=0;i<usage_size;i++){
                if (!strcmp(usage[i],"All")){
                    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->UsageDefaultCheck),1);
                } else {
                    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->UsageDefaultCheck),0);
                    if (!strcmp(usage[i],"Sync")){
                        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->UsageEnableUpdateCheck),1);
                    }
                    if (!strcmp(usage[i],"Search")){
                        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->UsageEnableSearchCheck),1);
                    }
                    if (!strcmp(usage[i],"Install")){
                        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->UsageEnableInsallCheck),1);
                    }
                    if (!strcmp(usage[i],"Upgrade")){
                        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->UsageSysupgradeCheck),1);
                    }
                }
            }
            if (usage_size) yon_char_parsed_free(usage,usage_size);
        }
        if (size<3||yon_char_is_empty(parsed[3])||strcmp(parsed[3],"disable")){ //disable
            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->EnabledCheck),1);
        }
    }
    gtk_widget_show(window->Window);
}


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

    if (!window->sections&&yon_char_is_empty(gtk_entry_get_text(GTK_ENTRY(window->RepoSourceEntry)))) {
        yon_ubl_status_box_spawn(GTK_CONTAINER(window->StatusBox),EMPTY_IMPORTANT_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE);
        yon_ubl_status_highlight_incorrect(window->RepoSourceEntry);
        return;
    }
    const char *repo_name = gtk_entry_get_text(GTK_ENTRY(window->RepoNameEntry));
    if (yon_char_is_empty(repo_name)){
        yon_ubl_status_box_spawn(GTK_CONTAINER(window->StatusBox),EMPTY_IMPORTANT_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE);
        yon_ubl_status_highlight_incorrect(window->RepoNameEntry);
        return;
    }
    int enabled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->EnabledCheck));
    char *sources = "";
    dictionary *dact = NULL;
    if (window->sections){
        for_dictionaries (dact, window->sections){
            char *type = (char*)gtk_combo_box_get_active_id(GTK_COMBO_BOX(((path_section*)dact->data)->TypeCombo));
            char *cur = yon_char_unite(type?type:"",(char*)gtk_entry_get_text(GTK_ENTRY(((path_section*)dact->data)->PathEntry)),NULL);
            char *temp = yon_char_unite(sources,!yon_char_is_empty(sources)?",":"",cur,NULL);
            if (!yon_char_is_empty(sources)) free(sources);
            sources = temp;
        }
    }
    char *source_main = (char*)gtk_entry_get_text(GTK_ENTRY(window->RepoSourceEntry));
    if (!yon_char_is_empty(source_main)) {
        char *type = (char*)gtk_combo_box_get_active_id(GTK_COMBO_BOX(window->RepoSourceCombo));
        source_main = yon_char_unite(type?type:"",source_main,NULL);
        char *temp = yon_char_unite(sources,!yon_char_is_empty(sources)?",":"",source_main,NULL);
        if (!yon_char_is_empty(sources)) free(sources);
        sources = temp;
    }
    if (yon_char_is_empty(sources)){
        yon_ubl_status_box_spawn(GTK_CONTAINER(window->StatusBox),EMPTY_IMPORTANT_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE);
        yon_ubl_status_highlight_incorrect(window->RepoSourceEntry);
        return;
    }

    char *sign_level= "";
    if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->SignDefaultCheck))){
        sign_level = (char*)gtk_entry_get_text(GTK_ENTRY(window->SignLevelCheckEntry));
    }
        char *usage = "";
    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->UsageDefaultCheck))){
        usage = "All";
    } else {
         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->UsageEnableUpdateCheck))){
            usage = yon_char_new("Sync");
        }
        if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->UsageEnableSearchCheck))){
            char *temp = yon_char_unite(usage,!yon_char_is_empty(usage)?",":"","Search",NULL);
            if (!yon_char_is_empty(usage)) free(usage);
            usage=temp;
        }
        if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->UsageEnableInsallCheck))){
            char *temp = yon_char_unite(usage,!yon_char_is_empty(usage)?",":"","Install",NULL);
            if (!yon_char_is_empty(usage)) free(usage);
            usage=temp;
        }
        if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->UsageSysupgradeCheck))){
            char *temp = yon_char_unite(usage,!yon_char_is_empty(usage)?",":"","Upgrade",NULL);
            if (!yon_char_is_empty(usage)) free(usage);
            usage=temp;
        }
    }

    char *final = yon_char_unite(sources,";",sign_level,";",usage,";",enabled?"":"disable",NULL);

    if (!yon_char_is_empty(window->name)&&strcmp(repo_name,window->name)){
        yon_config_remove_by_key(REPOSITORY(window->name));
    }
    yon_config_register(REPOSITORY(repo_name),REOSITORY_command(repo_name),final);
    yon_interface_update(widgets);
    gtk_widget_destroy(window->Window);
    free(window);

}



char *yon_password_unencrypted_password_get(password_window *window){
    const char *password = gtk_entry_get_text(GTK_ENTRY(window->PasswordEntry));
    const char *password_repeat = gtk_entry_get_text(GTK_ENTRY(window->RepeatPasswordEntry));
    if (strpbrk(password,"!@#%^&*\'")){
        yon_ubl_status_box_spawn(GTK_CONTAINER(window->StatusBox),PASSWORD_RESTRICTED_SYMBOL_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE);
        yon_ubl_status_highlight_incorrect(window->PasswordEntry);
        return NULL;
    }
    if (strcmp(password,password_repeat)){
        yon_ubl_status_box_spawn(GTK_CONTAINER(window->StatusBox),PASSWORD_MISMATCH_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE);
        yon_ubl_status_highlight_incorrect(window->PasswordEntry);
        yon_ubl_status_highlight_incorrect(window->RepeatPasswordEntry);
        return NULL;
    }
    if (yon_char_is_empty(password)){
        yon_ubl_status_box_spawn(GTK_CONTAINER(window->StatusBox),EMPTY_IMPORTANT_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE);
        yon_ubl_status_highlight_incorrect(window->PasswordEntry);
        return NULL;
    }

    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->NoEncriptionCheck))){
        const char *encryption = gtk_combo_box_get_active_id(GTK_COMBO_BOX(window->EncryptionCombo));
        char *final = yon_char_unite(encryption,"|",password,NULL);
        return final;
    } else {
        return yon_char_new(password);
    }
}

char *yon_password_hash_get(password_window *window){
    int encription_active = gtk_combo_box_get_active(GTK_COMBO_BOX(window->EncryptionCombo));
    const char *encription = gtk_combo_box_get_active_id(GTK_COMBO_BOX(window->EncryptionCombo));
    const char *hash = gtk_entry_get_text(GTK_ENTRY(window->PasswordHashEntry));
    if (!yon_char_is_empty(hash)){
        // if (!yon_char_is_empty(window->old_password)&&strcmp(hash,window->old_password)){
            switch(encription_active){
                case 1:{
                    if (strlen(hash)!=128){
                yon_ubl_status_box_spawn(GTK_CONTAINER(window->StatusBox),INCORRECT_HASH_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE);
                yon_ubl_status_highlight_incorrect(window->PasswordHashEntry);
                return NULL;
            }
                }
                    break;
                case 2:{
                    if (strlen(hash)!=64){
                yon_ubl_status_box_spawn(GTK_CONTAINER(window->StatusBox),INCORRECT_HASH_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE);
                yon_ubl_status_highlight_incorrect(window->PasswordHashEntry);
                return NULL;
            }
                }
                    break;
            }
        // }
        char *final = yon_char_unite(encription,"|",hash,NULL);
        return final;
    } else {
        const char *password = gtk_entry_get_text(GTK_ENTRY(window->PasswordEntry));
        const char *password_repeat = gtk_entry_get_text(GTK_ENTRY(window->RepeatPasswordEntry));
        if (strpbrk(password,"!@#%^&*\'")){
            yon_ubl_status_box_spawn(GTK_CONTAINER(window->StatusBox),PASSWORD_RESTRICTED_SYMBOL_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE);
            yon_ubl_status_highlight_incorrect(window->PasswordEntry);
            return NULL;
        }
        if (yon_char_is_empty(password_repeat)){
            yon_ubl_status_box_spawn(GTK_CONTAINER(window->StatusBox),EMPTY_IMPORTANT_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE);
            yon_ubl_status_highlight_incorrect(window->RepeatPasswordEntry);
            return NULL;
        }
        if (strcmp(password,password_repeat)){
            yon_ubl_status_box_spawn(GTK_CONTAINER(window->StatusBox),PASSWORD_MISMATCH_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE);
            yon_ubl_status_highlight_incorrect(window->PasswordEntry);
            yon_ubl_status_highlight_incorrect(window->RepeatPasswordEntry);
            return NULL;
        }

        int size;
        config_str hash = yon_config_load(yon_debug_output("%s\n",encription_active==1?sha512_encrypt_command(password):sha256_encrypt_command(password)),&size);
            yon_char_remove_last_symbol(hash[0],'\n');

        char *final = yon_char_unite(encription,"|",hash[0],NULL);
        return final;
    }
    return NULL;
}

void on_password_accept(GtkWidget *,dictionary *dict){
    password_window *window = yon_dictionary_get_data(dict->first,password_window*);
    GtkWidget *target = yon_dictionary_get_data(dict->first->next,GtkWidget*);

    int encription_active = gtk_combo_box_get_active(GTK_COMBO_BOX(window->EncryptionCombo));
    char *final = NULL;
    if (encription_active == 0||gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->NoEncriptionCheck))){
        final = yon_password_unencrypted_password_get(window);
        if (!final) return;
    } else {
        final = yon_password_hash_get(window);
        if (!final) return;
    }
    gtk_entry_set_text(GTK_ENTRY(target),final);
    gtk_widget_destroy(window->Window);
}




 

void on_repo_source_add(GtkWidget *, repo_add_window *window){
    char *target = (char*)gtk_entry_get_text(GTK_ENTRY(window->RepoSourceEntry));
    if (yon_char_is_empty(target)){
        yon_ubl_status_box_spawn(GTK_CONTAINER(window->StatusBox),EMPTY_IMPORTANT_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE);
        yon_ubl_status_highlight_incorrect(window->RepoSourceEntry);
        return;
    }

    GtkBuilder *builder = gtk_builder_new_from_resource(glade_repo_path_add_path);

    path_section *section = malloc(sizeof(path_section));
    section->PathRemovalBox = yon_gtk_builder_get_widget(builder,"PathRemovalBox");
    section->PathEditButton = yon_gtk_builder_get_widget(builder,"PathEditButton");
    section->PathEntry = yon_gtk_builder_get_widget(builder,"PathEntry");
    section->PathRemoveButton = yon_gtk_builder_get_widget(builder,"PathRemoveButton");
    section->TypeCombo = yon_gtk_builder_get_widget(builder,"TypeCombo");
    section->edits=0;

    const char *id = gtk_combo_box_get_active_id(GTK_COMBO_BOX(window->RepoSourceCombo));
    if (!yon_char_is_empty(id))
        gtk_combo_box_set_active_id(GTK_COMBO_BOX(section->TypeCombo),id);
    else
        gtk_combo_box_set_active(GTK_COMBO_BOX(section->TypeCombo),4);
    yon_dictionary_add_or_create_if_exists_with_data(window->sections,(char*)target,section);

    gtk_entry_set_text(GTK_ENTRY(section->PathEntry),target);
    gtk_entry_set_text(GTK_ENTRY(window->RepoSourceEntry),"");
    gtk_box_pack_start(GTK_BOX(window->SourceBox),section->PathRemovalBox,0,0,0);
    gtk_widget_show(window->SourceListBox);
    g_signal_connect(gtk_builder_get_object(builder,"PathEditButton"),"clicked",G_CALLBACK(on_mirror_path_edit),window);
    g_signal_connect(gtk_builder_get_object(builder,"PathRemoveButton"),"clicked",G_CALLBACK(on_mirror_path_removed),window);
}

void on_file_chooser_open(GtkWidget *self, GtkEntry *target){
    filechooser_window *window = yon_file_chooser_window_new(GTK_FILE_CHOOSER_ACTION_OPEN);
        yon_gtk_window_setup(GTK_WINDOW(window->Window),GTK_WINDOW(gtk_widget_get_toplevel(self)),yon_char_get_localised_from_lib(CHOOSE_FILE_LABEL),icon_path,"file_chooser");
    if (yon_file_chooser_start(window)){
        char *file = window->last_any_selection;
        if (!yon_char_is_empty(file)){
            gtk_entry_set_text(target,file);
        }
    }
    free(window);
}

void on_repo_file_chooser_open(GtkWidget *, repo_add_window *window){
    filechooser_window *fchwindow = NULL;
    const char *source_type = gtk_combo_box_get_active_id(GTK_COMBO_BOX(window->RepoSourceCombo));
    if (yon_char_is_empty(source_type)){
        GtkFileFilter *filter = gtk_file_filter_new();
        fchwindow = yon_file_chooser_window_new(GTK_FILE_CHOOSER_ACTION_OPEN);
        yon_gtk_window_setup(GTK_WINDOW(fchwindow->Window),GTK_WINDOW(window->Window),yon_char_get_localised_from_lib(CHOOSE_FILE_LABEL),icon_path,"file_chooser");
        gtk_file_filter_set_name(filter,"*ini");
        gtk_file_filter_add_pattern(filter,"*ini");
        gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(fchwindow->MainFileChooser),filter);
    } else if (!strcmp(source_type,"file://")){
        fchwindow = yon_file_chooser_window_new(GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
        yon_gtk_window_setup(GTK_WINDOW(fchwindow->Window),GTK_WINDOW(window->Window),yon_char_get_localised_from_lib(CHOOSE_FILE_LABEL),icon_path,"file_chooser");
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(fchwindow->ChooseFolderCheck),1);
    } else return;

    yon_gtk_window_setup(GTK_WINDOW(fchwindow->Window),GTK_WINDOW(window->Window),yon_char_get_localised_from_lib(CHOOSE_FILE_LABEL),icon_path,"file_chooser");
    if (yon_file_chooser_start(fchwindow)){
        char *file = fchwindow->last_success_selection;
        if (!yon_char_is_empty(file)){
            gtk_entry_set_text(GTK_ENTRY(window->RepoSourceEntry),file);
        }
    }
    free(fchwindow);
}

void on_password_hash_sensitiveness(GtkWidget *,password_window *window){
    const char *password = gtk_entry_get_text(GTK_ENTRY(window->PasswordEntry));
    const char *repeat_password = gtk_entry_get_text(GTK_ENTRY(window->RepeatPasswordEntry));
    const char *hash = gtk_entry_get_text(GTK_ENTRY(window->PasswordHashEntry));
	if (!yon_char_is_empty(password)||!yon_char_is_empty(repeat_password)){
		gtk_widget_set_sensitive(window->HashBox,0);
		gtk_widget_set_sensitive(window->PasswordBox,1);
    } else if (yon_char_is_empty(password)&&yon_char_is_empty(repeat_password)&&
                gtk_combo_box_get_active(GTK_COMBO_BOX(window->EncryptionCombo))>0&&
                yon_char_is_empty(hash)){
		gtk_widget_set_sensitive(window->HashBox,1);
		gtk_widget_set_sensitive(window->PasswordBox,1);
		gtk_widget_set_sensitive(window->NoEncriptionCheck,1);
	} else if (!yon_char_is_empty(hash)) {
		gtk_widget_set_sensitive(window->HashBox,1);
		gtk_widget_set_sensitive(window->PasswordBox,0);
		gtk_widget_set_sensitive(window->NoEncriptionCheck,0);
	} else {
		gtk_widget_set_sensitive(window->HashBox,0);
		gtk_widget_set_sensitive(window->PasswordBox,1);
	}
}

password_window *yon_password_window_new(){
    GtkBuilder *builder = gtk_builder_new_from_resource(glade_password_path);
    password_window *window = malloc(sizeof(password_window));
    window->Window = yon_gtk_builder_get_widget(builder,"PasswordWindow");
    window->HeadLabel = yon_gtk_builder_get_widget(builder,"userTitleNameLabel");
    window->StatusBox = yon_gtk_builder_get_widget(builder,"StatusBox");
    window->PasswordEntry = yon_gtk_builder_get_widget(builder,"PasswordEntry");
    window->RepeatPasswordEntry = yon_gtk_builder_get_widget(builder,"RepeatPasswordEntry");
    window->EncryptionCombo = yon_gtk_builder_get_widget(builder,"EncryptionCombo");
    window->NoEncriptionCheck = yon_gtk_builder_get_widget(builder,"NoEncriptionCheck");
    window->PasswordHashEntry = yon_gtk_builder_get_widget(builder,"PasswordHashEntry");
    window->UserCancelButton = yon_gtk_builder_get_widget(builder,"UserCancelButton");
    window->AcceptButton = yon_gtk_builder_get_widget(builder,"UserOkButton");
    window->PasswordBox = yon_gtk_builder_get_widget(builder,"PasswordBox");
    window->HashBox = yon_gtk_builder_get_widget(builder,"HashBox");

    window->old_password=NULL;
    g_signal_connect(G_OBJECT(window->UserCancelButton),"clicked",G_CALLBACK(on_subwindow_close),NULL);
    g_signal_connect(G_OBJECT(window->EncryptionCombo),"changed",G_CALLBACK(on_password_hash_sensitiveness),window);
    g_signal_connect(G_OBJECT(window->NoEncriptionCheck),"toggled",G_CALLBACK(on_password_hash_sensitiveness),window);
    g_signal_connect(G_OBJECT(window->PasswordHashEntry),"changed",G_CALLBACK(on_password_hash_sensitiveness),window);
    g_signal_connect(G_OBJECT(window->PasswordEntry),"changed",G_CALLBACK(on_password_hash_sensitiveness),window);
    g_signal_connect(G_OBJECT(window->RepeatPasswordEntry),"changed",G_CALLBACK(on_password_hash_sensitiveness),window);
    gtk_widget_show(window->Window);
    return window;
}

void on_sign_cell_toggled(GtkWidget *, char *path, repo_add_window *window){
    GtkTreeModel *model = GTK_TREE_MODEL(window->SignList);
    GtkTreeIter check_iter;
    if (gtk_tree_model_get_iter_from_string(model,&check_iter,path)){
        int check_status;
        char *target;
        gtk_tree_model_get(model,&check_iter,0,&check_status,1,&target,-1);
        gtk_list_store_set(window->SignList,&check_iter,0,!check_status,-1);
        char *active_signs = yon_char_new((char*)gtk_entry_get_text(GTK_ENTRY(window->SignLevelCheckEntry)));
        if (!check_status){
            char *temp = yon_char_unite(active_signs,!yon_char_is_empty(active_signs)?",":"",target,NULL);
                gtk_entry_set_text(GTK_ENTRY(window->SignLevelCheckEntry),temp);
        } else {
            int parsed_size;
            config_str parsed = yon_char_parse(active_signs,&parsed_size,",");
            if (parsed_size){
                int found = yon_char_parsed_check_exist(parsed,parsed_size,target);
                if (found>-1){
                    parsed = yon_char_parsed_rip(parsed,&parsed_size,found);
                }
                char *temp = yon_char_parsed_to_string(parsed,parsed_size,",");
                gtk_entry_set_text(GTK_ENTRY(window->SignLevelCheckEntry),temp);
            }
        }
    }
}

void on_sign_check_toggled(GtkToggleButton *self, repo_add_window *window){
    int status = gtk_toggle_button_get_active(self);
    gtk_widget_set_sensitive(window->SignTree,!status);
    
}

void on_repo_source_changed(GtkComboBox *self, repo_add_window *window){
    int active = gtk_combo_box_get_active(self);
    gtk_entry_set_text(GTK_ENTRY(window->RepoSourceEntry),"");
    if (active ==0 || active == 4){
        gtk_widget_set_sensitive(window->RepoSourceButton,1);
    } else {
        gtk_widget_set_sensitive(window->RepoSourceButton,0);
    }
}

repo_add_window *yon_repo_add_window_new(){
    GtkBuilder *builder = gtk_builder_new_from_resource(glade_repo_add_path);
    repo_add_window *window = malloc(sizeof(repo_add_window));
    window->Window = yon_gtk_builder_get_widget(builder,"MainWindow");
    window->StatusBox = yon_gtk_builder_get_widget(builder,"StatusBox");
    window->EnabledCheck = yon_gtk_builder_get_widget(builder,"EnabledCheck");
    window->RepoNameEntry = yon_gtk_builder_get_widget(builder,"RepoNameEntry");
    window->RepoSourceCombo = yon_gtk_builder_get_widget(builder,"RepoSourceCombo");
    window->RepoSourceEntry = yon_gtk_builder_get_widget(builder,"RepoSourceEntry");
    window->RepoSourceButton = yon_gtk_builder_get_widget(builder,"RepoSourceButton");
    window->RepoSignCheckCombo = yon_gtk_builder_get_widget(builder,"RepoSignCheckCombo");
    window->RepoSignConditionCombo = yon_gtk_builder_get_widget(builder,"RepoSignConditionCombo");
    window->UsageDefaultCheck = yon_gtk_builder_get_widget(builder,"UsageDefaultCheck");
    window->UsageEnableUpdateCheck = yon_gtk_builder_get_widget(builder,"UsageEnableUpdateCheck");
    window->UsageEnableSearchCheck = yon_gtk_builder_get_widget(builder,"UsageEnableSearchCheck");
    window->UsageEnableInsallCheck = yon_gtk_builder_get_widget(builder,"UsageEnableInsallCheck");
    window->UsageSysupgradeCheck = yon_gtk_builder_get_widget(builder,"UsageSysupgradeCheck");
    window->AcceptButton = yon_gtk_builder_get_widget(builder,"AcceptButton");
    window->CancelButton = yon_gtk_builder_get_widget(builder,"CancelButton");
    window->HeadLabel = yon_gtk_builder_get_widget(builder,"HeadLabel");
    window->SignLevelLabel = yon_gtk_builder_get_widget(builder,"SignLevelLabel");
    window->SourceBox = yon_gtk_builder_get_widget(builder,"SourceBox");
    window->SourceListBox = yon_gtk_builder_get_widget(builder,"SourceListBox");
    window->RepoSourceAddButton = yon_gtk_builder_get_widget(builder,"RepoSourceAddButton");
    window->SignDefaultCheck = yon_gtk_builder_get_widget(builder,"SignDefaultCheck");
    window->SignTree = yon_gtk_builder_get_widget(builder,"SignTree");
    window->SignLevelCheckEntry = yon_gtk_builder_get_widget(builder,"SignLevelCheckEntry");
    window->SignCell = GTK_CELL_RENDERER(gtk_builder_get_object(builder,"SignCell"));
    window->SignList = GTK_LIST_STORE(gtk_builder_get_object(builder,"liststore1"));

    window->sections = NULL;
    window->name=NULL;
    g_signal_connect(G_OBJECT(window->RepoSourceButton),"clicked",G_CALLBACK(on_repo_file_chooser_open),window);
    g_signal_connect(G_OBJECT(window->RepoSourceAddButton),"clicked",G_CALLBACK(on_repo_source_add),window);
    g_signal_connect(G_OBJECT(window->CancelButton),"clicked",G_CALLBACK(on_subwindow_close),NULL);
    g_signal_connect(G_OBJECT(window->UsageDefaultCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button_inversed),window->UsageEnableInsallCheck);
    g_signal_connect(G_OBJECT(window->UsageDefaultCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button_inversed),window->UsageEnableSearchCheck);
    g_signal_connect(G_OBJECT(window->UsageDefaultCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button_inversed),window->UsageEnableUpdateCheck);
    g_signal_connect(G_OBJECT(window->UsageDefaultCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button_inversed),window->UsageSysupgradeCheck);
    yon_on_entry_set_allowed_symbols(GTK_ENTRY(window->RepoSourceEntry),"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/1234567890!$.#-_()~$&;{}[]|<>^:?+\\,'*`%");
    yon_on_entry_set_allowed_symbols(GTK_ENTRY(window->RepoNameEntry),"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/1234567890.-_");
    g_signal_connect(G_OBJECT(window->SignDefaultCheck),"toggled",G_CALLBACK(on_sign_check_toggled),window);
    g_signal_connect(G_OBJECT(window->SignCell),"toggled",G_CALLBACK(on_sign_cell_toggled),window);
    g_signal_connect(G_OBJECT(window->RepoSourceCombo),"changed",G_CALLBACK(on_repo_source_changed),window);
    // g_signal_connect(G_OBJECT(window->SourceListBox),"size-allocate",G_CALLBACK(on_scrolled_window_size_allocate),window);
    gtk_widget_show(window->Window);
    
    return window;
}



void on_cell_renderer_toggle_toggled(GtkWidget *, gchar* path, GtkWidget *table){
    GtkTreeIter iter;
    GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(table));
    if (gtk_tree_model_get_iter_from_string(model,&iter,path)){
        int status;
        gtk_tree_model_get(model,&iter,0,&status,-1);
        gtk_list_store_set(GTK_LIST_STORE(model),&iter,0,!status,-1);
    }
}

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

}

void on_update_clicked(GtkWidget *, main_window *widgets){
    switch(main_config.load_mode){
        case YON_CONFIG_LOCAL:
            on_config_local_load(NULL,widgets);
            break;
        case YON_CONFIG_GLOBAL:
            on_config_global_load(NULL,widgets);
            break;
        case YON_CONFIG_CUSTOM:
            on_config_custom_load(NULL,widgets);
            break;
    }
}

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

    {
        gtk_builder_add_callback_symbol(builder,"yon_gtk_widget_set_sensitive_from_toggle_button_inversed",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button_inversed));
        
    }
    // Custom widgets configuration 
    {
        widgets->AutoUpdateCheck = yon_gtk_builder_get_widget(builder,"AutoUpdateCheck");
        widgets->UpdateModeCombo = yon_gtk_builder_get_widget(builder,"UpdateModeCombo");
        widgets->UpdateIntervalDefaultCheck = yon_gtk_builder_get_widget(builder,"UpdateIntervalDefaultCheck");
        widgets->UpdateIntervalSpin = yon_gtk_builder_get_widget(builder,"UpdateIntervalSpin");
        widgets->UpdateToggleCell = GTK_CELL_RENDERER(gtk_builder_get_object(builder,"UpdateToggleCell"));
        widgets->UpdateIntervalCombo = yon_gtk_builder_get_widget(builder,"UpdateIntervalCombo");
        widgets->UpdateRepoListCheck = yon_gtk_builder_get_widget(builder,"UpdateRepoListCheck");
        widgets->UpdateRepoTree = yon_gtk_builder_get_widget(builder,"UpdateRepoTree");
        widgets->RepositoriesRepoListConfigurationCheck = yon_gtk_builder_get_widget(builder,"RepositoriesRepoListConfigurationCheck");
        widgets->RepositoriesDisableSystemReposCheck = yon_gtk_builder_get_widget(builder,"RepositoriesDisableSystemReposCheck");
        widgets->RepositoriesTree = yon_gtk_builder_get_widget(builder,"RepositoriesTree");
        widgets->RepositoriesUpdateButton = yon_gtk_builder_get_widget(builder,"RepositoriesUpdateButton");
        widgets->RepositoriesMoveUpButton = yon_gtk_builder_get_widget(builder,"RepositoriesMoveUpButton");
        widgets->RepositoriesMoveDownButton = yon_gtk_builder_get_widget(builder,"RepositoriesMoveDownButton");
        widgets->RepositoriesCreateButton = yon_gtk_builder_get_widget(builder,"RepositoriesCreateButton");
        widgets->RepositoriesEditButton = yon_gtk_builder_get_widget(builder,"RepositoriesEditButton");
        widgets->RepositoriesDeleteButton = yon_gtk_builder_get_widget(builder,"RepositoriesDeleteButton");
        widgets->PublicationConnectPublicCheck = yon_gtk_builder_get_widget(builder,"PublicationConnectPublicCheck");
        widgets->RecieveDBFromNetCheck = yon_gtk_builder_get_widget(builder,"RecieveDBFromNetCheck");
        widgets->PublicationTree = yon_gtk_builder_get_widget(builder,"PublicationTree");
        widgets->PublicationUpdateButton = yon_gtk_builder_get_widget(builder,"PublicationUpdateButton");
        widgets->PublicationToggleCell = GTK_CELL_RENDERER(gtk_builder_get_object(builder,"PublicationToggleCell"));
        widgets->PublicationCheck = yon_gtk_builder_get_widget(builder,"PublicationCheck");
        widgets->WebPublicationUpdateButton = yon_gtk_builder_get_widget(builder,"WebPublicationUpdateButton");
        widgets->WebPublicationAddButton = yon_gtk_builder_get_widget(builder,"WebPublicationAddButton");
        widgets->WebPublicationEditButton = yon_gtk_builder_get_widget(builder,"WebPublicationEditButton");
        widgets->WebPublicationRemoveButton = yon_gtk_builder_get_widget(builder,"WebPublicationRemoveButton");
        widgets->WebPublicationTree = yon_gtk_builder_get_widget(builder,"WebPublicationTree");
        widgets->FtpUpdateButton = yon_gtk_builder_get_widget(builder,"FtpUpdateButton");
        widgets->FtpAddButton = yon_gtk_builder_get_widget(builder,"FtpAddButton");
        widgets->FtpRemoveButton = yon_gtk_builder_get_widget(builder,"FtpRemoveButton");
        widgets->FtpEditButton = yon_gtk_builder_get_widget(builder,"FtpEditButton");
        widgets->FtpTree = yon_gtk_builder_get_widget(builder,"FtpTree");
        widgets->MirrorPublicCheck = yon_gtk_builder_get_widget(builder,"MirrorPublicCheck");
        widgets->MirrorTree = yon_gtk_builder_get_widget(builder,"MirrorTree");
        widgets->MirrorUpdateButton = yon_gtk_builder_get_widget(builder,"MirrorUpdateButton");
        widgets->MirrorAddButton = yon_gtk_builder_get_widget(builder,"MirrorAddButton");
        widgets->MirrorEditButton = yon_gtk_builder_get_widget(builder,"MirrorEditButton");
        widgets->MirrorRemoveButton = yon_gtk_builder_get_widget(builder,"MirrorRemoveButton");
        widgets->MirrorConfigureButton = yon_gtk_builder_get_widget(builder,"MirrorConfigureButton");
        widgets->BootCheck = yon_gtk_builder_get_widget(builder,"BootCheck");
        widgets->DateEntry = yon_gtk_builder_get_widget(builder,"DateEntry");
        widgets->WebPublicationUpperTree = yon_gtk_builder_get_widget(builder,"WebPublicationUpperTree");
        widgets->ReposList = GTK_LIST_STORE(gtk_builder_get_object(builder,"ReposList"));
        widgets->PublicationList = GTK_LIST_STORE(gtk_builder_get_object(builder,"PublicationList"));
        widgets->WebPublicationList = GTK_LIST_STORE(gtk_builder_get_object(builder,"WebPublicationList"));
        widgets->FtpList = GTK_LIST_STORE(gtk_builder_get_object(builder,"FtpList"));
        widgets->MirrorList = GTK_LIST_STORE(gtk_builder_get_object(builder,"MirrorList"));
    }
    {
        g_signal_connect(G_OBJECT(widgets->RepositoriesMoveUpButton),"clicked",G_CALLBACK(on_repo_move_up),widgets);
        g_signal_connect(G_OBJECT(widgets->RepositoriesMoveDownButton),"clicked",G_CALLBACK(on_repo_move_down),widgets);
        g_signal_connect(G_OBJECT(widgets->RepositoriesCreateButton),"clicked",G_CALLBACK(on_repo_add),widgets);
        g_signal_connect(G_OBJECT(widgets->WebPublicationAddButton),"clicked",G_CALLBACK(on_web_publish_add),widgets);
        g_signal_connect(G_OBJECT(widgets->FtpAddButton),"clicked",G_CALLBACK(yon_ftp_window_add),widgets);
        g_signal_connect(G_OBJECT(widgets->MirrorAddButton),"clicked",G_CALLBACK(on_mirror_add),widgets);
        g_signal_connect(G_OBJECT(widgets->RepositoriesDeleteButton),"clicked",G_CALLBACK(on_repo_remove),widgets);
        g_signal_connect(G_OBJECT(widgets->WebPublicationRemoveButton),"clicked",G_CALLBACK(on_web_publish_remove),widgets);
        g_signal_connect(G_OBJECT(widgets->FtpRemoveButton),"clicked",G_CALLBACK(on_ftp_remove),widgets);
        g_signal_connect(G_OBJECT(widgets->MirrorRemoveButton),"clicked",G_CALLBACK(on_mirror_remove),widgets);
        g_signal_connect(G_OBJECT(widgets->RepositoriesTree),"cursor-changed",G_CALLBACK(on_selection_changed),widgets);
        g_signal_connect(G_OBJECT(widgets->PublicationTree),"cursor-changed",G_CALLBACK(on_selection_changed),widgets);
        g_signal_connect(G_OBJECT(widgets->WebPublicationTree),"cursor-changed",G_CALLBACK(on_selection_changed),widgets);
        g_signal_connect(G_OBJECT(widgets->FtpTree),"cursor-changed",G_CALLBACK(on_selection_changed),widgets);
        g_signal_connect(G_OBJECT(widgets->MirrorTree),"cursor-changed",G_CALLBACK(on_selection_changed),widgets);

        g_signal_connect(G_OBJECT(widgets->MirrorEditButton),"clicked",G_CALLBACK(on_mirror_edit),widgets);
        g_signal_connect(G_OBJECT(widgets->WebPublicationEditButton),"clicked",G_CALLBACK(on_web_publish_edit),widgets);
        g_signal_connect(G_OBJECT(widgets->FtpEditButton),"clicked",G_CALLBACK(yon_ftp_window_edit),widgets);
        g_signal_connect(G_OBJECT(widgets->RepositoriesEditButton),"clicked",G_CALLBACK(on_repo_edit),widgets);

        g_signal_connect(G_OBJECT(widgets->MirrorConfigureButton),"clicked",G_CALLBACK(on_mirror_configure),widgets);
        
        g_signal_connect(G_OBJECT(widgets->SaveMenuItem),"activate",G_CALLBACK(on_config_save),widgets);
        g_signal_connect(G_OBJECT(widgets->SaveGlobalMenuItem),"activate",G_CALLBACK(on_config_global_save),widgets);
        g_signal_connect(G_OBJECT(widgets->SaveLocalMenuItem),"activate",G_CALLBACK(on_config_local_save),widgets);
        g_signal_connect(G_OBJECT(widgets->SaveCustomMenuItem),"activate",G_CALLBACK(on_config_custom_save),widgets);

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

        g_signal_connect(G_OBJECT(widgets->UpdateRepoListCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),widgets->UpdateRepoTree);
        g_signal_connect(G_OBJECT(widgets->PublicationCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),widgets->PublicationTree);
        g_signal_connect(G_OBJECT(widgets->PublicationCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),widgets->PublicationUpdateButton);
        g_signal_connect(G_OBJECT(widgets->RepositoriesUpdateButton),"clicked",G_CALLBACK(on_update_clicked),widgets);
        g_signal_connect(G_OBJECT(widgets->PublicationUpdateButton),"clicked",G_CALLBACK(on_update_clicked),widgets);
        g_signal_connect(G_OBJECT(widgets->WebPublicationUpdateButton),"clicked",G_CALLBACK(on_update_clicked),widgets);
        g_signal_connect(G_OBJECT(widgets->FtpUpdateButton),"clicked",G_CALLBACK(on_update_clicked),widgets);
        g_signal_connect(G_OBJECT(widgets->MirrorUpdateButton),"clicked",G_CALLBACK(on_update_clicked),widgets);
        // g_signal_connect(G_OBJECT(widgets->RepositoriesDisableSystemReposCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),widgets->RepositoriesTree);

        GList *list = gtk_tree_view_get_columns(GTK_TREE_VIEW(widgets->WebPublicationTree));
        for (unsigned int i=0;i<g_list_length(list);i++){
            g_signal_connect_after(G_OBJECT(g_list_nth_data(list,i)),"notify::width",G_CALLBACK(on_column_resize),widgets);
            yon_window_config_add_listener(g_list_nth_data(list,i),yon_char_append("UserUnitsColumn",yon_char_from_int(i)),"fixed-width",YON_TYPE_INT);
        }
    
    }
    
	GList *list = gtk_tree_view_get_columns(GTK_TREE_VIEW(widgets->MirrorTree));
	for (guint i=0;i<g_list_length(list);i++){
		yon_window_config_add_listener((GtkWidget*)g_list_nth_data(list,i),yon_char_append("MirrorColumn",yon_char_from_int(i)),"fixed-width",YON_TYPE_INT);
	}
    g_list_free(list);
	list = gtk_tree_view_get_columns(GTK_TREE_VIEW(widgets->PublicationTree));
	for (guint i=0;i<g_list_length(list);i++){
		yon_window_config_add_listener((GtkWidget*)g_list_nth_data(list,i),yon_char_append("PublishColumn",yon_char_from_int(i)),"fixed-width",YON_TYPE_INT);
	}
	g_list_free(list);
	list = gtk_tree_view_get_columns(GTK_TREE_VIEW(widgets->WebPublicationTree));
	for (guint i=0;i<g_list_length(list);i++){
		yon_window_config_add_listener((GtkWidget*)g_list_nth_data(list,i),yon_char_append("WebColumn",yon_char_from_int(i)),"fixed-width",YON_TYPE_INT);
	}
	g_list_free(list);
	list = gtk_tree_view_get_columns(GTK_TREE_VIEW(widgets->RepositoriesTree));
	for (guint i=0;i<g_list_length(list);i++){
		yon_window_config_add_listener((GtkWidget*)g_list_nth_data(list,i),yon_char_append("RepoColumn",yon_char_from_int(i)),"fixed-width",YON_TYPE_INT);
	}
	g_list_free(list);
    yon_load_proceed(YON_CONFIG_LOCAL);
	list = gtk_tree_view_get_columns(GTK_TREE_VIEW(widgets->UpdateRepoTree));
	for (guint i=0;i<g_list_length(list);i++){
		yon_window_config_add_listener((GtkWidget*)g_list_nth_data(list,i),yon_char_append("UpdateColumn",yon_char_from_int(i)),"fixed-width",YON_TYPE_INT);
	}
	g_list_free(list);
    {
        int size;
        config_str parsed = yon_config_load(yon_config_parameter_prepare_command(AUTOUPDATE_mode_command,"default",NULL,NULL),&size);
        if (size){
            yon_char_remove_last_symbol(parsed[0],'\n');
            free(yon_char_divide_search(parsed[0],"=",-1));
            char *mode = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(widgets->UpdateModeCombo));
            if (!strcmp(parsed[0],"modsys")){
                mode = yon_char_unite(mode," (",MODSYS_UPDATE_MODE_LABEL,")",NULL);
            } else if (!strcmp(parsed[0],"modules")){
                mode = yon_char_unite(mode," (",MODULES_UPDATE_MODE_LABEL,")",NULL);
            } else if (!strcmp(parsed[0],"system")){
                mode = yon_char_unite(mode," (",SYSTEM_UPDATE_MODE_LABEL,")",NULL);
            }
            gtk_combo_box_text_remove(GTK_COMBO_BOX_TEXT(widgets->UpdateModeCombo),0);
            gtk_combo_box_text_prepend_text(GTK_COMBO_BOX_TEXT(widgets->UpdateModeCombo),mode);
            gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->UpdateModeCombo),0);
        }
    }
    
        g_signal_connect(G_OBJECT(widgets->BootCheck),"toggled",G_CALLBACK(on_toggle_button_toggled),widgets);
        g_signal_connect(G_OBJECT(widgets->PublicationCheck),"toggled",G_CALLBACK(on_toggle_button_toggled),widgets);
        g_signal_connect(G_OBJECT(widgets->UpdateIntervalSpin),"changed",G_CALLBACK(on_toggle_button_toggled),widgets);
        g_signal_connect(G_OBJECT(widgets->UpdateIntervalCombo),"changed",G_CALLBACK(on_toggle_button_toggled),widgets);
        g_signal_connect(G_OBJECT(widgets->AutoUpdateCheck),"toggled",G_CALLBACK(on_toggle_button_toggled),widgets);
        g_signal_connect(G_OBJECT(widgets->AutoUpdateCheck),"toggled",G_CALLBACK(yon_update_toggled),widgets);
        // g_signal_connect(G_OBJECT(widgets->AutoUpdateCheck),"toggled",G_CALLBACK(yon_update_toggled),widgets);
        // g_signal_connect(G_OBJECT(widgets->AutoUpdateCheck),"toggled",G_CALLBACK(yon_update_toggled),widgets);
        // g_signal_connect(G_OBJECT(widgets->AutoUpdateCheck),"toggled",G_CALLBACK(yon_update_toggled),widgets);
        g_signal_connect(G_OBJECT(widgets->UpdateModeCombo),"changed",G_CALLBACK(on_toggle_button_toggled),widgets);
        // g_signal_connect(G_OBJECT(widgets->UpdateModeCombo),"changed",G_CALLBACK(on_update_mode_changed),widgets);
        g_signal_connect(G_OBJECT(widgets->UpdateIntervalDefaultCheck),"toggled",G_CALLBACK(on_toggle_button_toggled),widgets);
        g_signal_connect(G_OBJECT(widgets->UpdateRepoListCheck),"toggled",G_CALLBACK(on_toggle_button_toggled),widgets);
        g_signal_connect(G_OBJECT(widgets->RepositoriesRepoListConfigurationCheck),"toggled",G_CALLBACK(on_toggle_button_toggled),widgets);
        g_signal_connect(G_OBJECT(widgets->RepositoriesDisableSystemReposCheck),"toggled",G_CALLBACK(on_toggle_button_toggled),widgets);
        g_signal_connect(G_OBJECT(widgets->PublicationConnectPublicCheck),"toggled",G_CALLBACK(on_toggle_button_toggled),widgets);
        g_signal_connect(G_OBJECT(widgets->RecieveDBFromNetCheck),"toggled",G_CALLBACK(on_toggle_button_toggled),widgets);
        g_signal_connect(G_OBJECT(widgets->MirrorPublicCheck),"toggled",G_CALLBACK(on_toggle_button_toggled),widgets);
        yon_interface_update(widgets);

    {
        yon_gtk_tree_view_minimal_fixed_size_set_full(GTK_TREE_VIEW(widgets->MirrorTree));
        yon_gtk_tree_view_minimal_fixed_size_set_full(GTK_TREE_VIEW(widgets->UpdateRepoTree));
        yon_gtk_tree_view_minimal_fixed_size_set_full(GTK_TREE_VIEW(widgets->PublicationTree));
        yon_gtk_tree_view_minimal_fixed_size_set_full(GTK_TREE_VIEW(widgets->RepositoriesTree));
        yon_gtk_tree_view_minimal_fixed_size_set_full(GTK_TREE_VIEW(widgets->WebPublicationTree));
    }
    yon_root_button_setup((template_main_window*)widgets,main_config.launch_arguments,main_config.launch_size);
    yon_save_window_set_postsave_function(on_save_done,widgets);
    yon_save_window_set_presave_function(on_save_start,widgets);
}

int main(int argc, char *argv[]){ 
    setlocale(LC_ALL, "");
    g_setenv("GDK_BACKEND","x11",1);
    textdomain (LocaleName);
    config_init();

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