#include "ubinstall-gtk.h"

int 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)){
        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(device_tree));
        return 0;
    }
    if (!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(part_tree)),&model2,&itar)){
        yon_ubl_status_box_spawn(GTK_CONTAINER(widgets->StatusBox),NO_PART_CHOSEN_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE);
        yon_ubl_status_highlight_incorrect(gtk_widget_get_parent(part_tree));
        return 0;
    }
    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(device_parameter,device_parameter_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){
        yon_debug_output("%s\n",yon_config_save_args_simple(main_config.config_load_path,device_parameter,AUTOINSTALL_TYPE_INSTALL,part_parameter,NULL));
    }
    return 1;
}