You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
828 lines
35 KiB
828 lines
35 KiB
#include "ubinstall-gtk.h"
|
|
|
|
#define toggled_icon_name "com.ublinux.libublsettingsui-gtk3.toggled-symbolic"
|
|
#define untoggled_icon_name "com.ublinux.libublsettingsui-gtk3.untoggled-symbolic"
|
|
|
|
advanced_section *yon_advanced_section_new();
|
|
void yon_advanced_section_remove();
|
|
|
|
int sections_size=0;
|
|
advanced_section *sections[2] = {NULL};
|
|
|
|
advanced_section *yon_advanced_section_new(){
|
|
if (sections_size>=2) return NULL;
|
|
advanced_section *section = malloc(sizeof(advanced_section));
|
|
memset(section,0,sizeof(advanced_section));
|
|
if (!sections_size){
|
|
section->sys_section=1;
|
|
section->user_section=1;
|
|
} else {
|
|
section->sys_section=0;
|
|
section->user_section=1;
|
|
sections[0]->sys_section=1;
|
|
sections[0]->user_section=0;
|
|
}
|
|
return section;
|
|
}
|
|
|
|
void yon_advanced_section_remove_all(){
|
|
if (sections[0]){
|
|
free(sections[0]);
|
|
sections[0]=NULL;
|
|
}
|
|
if (sections[1]){
|
|
free(sections[1]);
|
|
sections[1]=NULL;
|
|
}
|
|
sections_size=0;
|
|
}
|
|
|
|
void yon_advanced_section_remove_by_name(char *part){
|
|
int pos = yon_advanced_section_get(part);
|
|
switch(pos){
|
|
case 0:
|
|
if (sections[0]){
|
|
free(sections[0]);
|
|
if (sections[1]){
|
|
sections[0]=sections[1];
|
|
sections[1]=NULL;
|
|
} else {
|
|
sections[0]=NULL;
|
|
}
|
|
sections_size--;
|
|
}
|
|
break;
|
|
case 1:
|
|
if (sections[1]){
|
|
free(sections[1]);
|
|
sections[1]=NULL;
|
|
sections_size--;
|
|
}
|
|
break;
|
|
default: return;
|
|
}
|
|
}
|
|
void yon_advanced_section_remove(advanced_partition *part){
|
|
int pos = yon_advanced_section_get_by_part(part);
|
|
switch(pos){
|
|
case 0:
|
|
if (sections[0]){
|
|
free(sections[0]);
|
|
if (sections[1]){
|
|
sections[0]=sections[1];
|
|
sections[1]=NULL;
|
|
} else {
|
|
sections[0]=NULL;
|
|
}
|
|
sections_size--;
|
|
}
|
|
break;
|
|
case 1:
|
|
if (sections[1]){
|
|
free(sections[1]);
|
|
sections[1]=NULL;
|
|
sections_size--;
|
|
}
|
|
break;
|
|
default:return;
|
|
}
|
|
}
|
|
|
|
int yon_advanced_section_get_by_part(advanced_partition *part){
|
|
if (!part) return -1;
|
|
if (sections_size>0&§ions[0]->partition_widgets==part){
|
|
return 0;
|
|
} else if (sections_size>1&§ions[1]->partition_widgets==part){
|
|
return 1;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
int yon_advanced_section_get(char *partition){
|
|
if (yon_char_is_empty(partition)) return -1;
|
|
if (sections_size>0&&!strcmp(sections[0]->part_source==PART_SOURCE_PART?sections[0]->partition:sections[0]->device,partition)){
|
|
return 0;
|
|
} else if (sections_size>1&&!strcmp(sections[1]->part_source==PART_SOURCE_PART?sections[1]->partition:sections[1]->device,partition)){
|
|
return 1;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
void yon_advanced_partition_set_from_section(advanced_partition *part, advanced_section *section){
|
|
if (part&§ion){
|
|
gtk_label_set_text(GTK_LABEL(part->SectionLabel),section->part_source==PART_SOURCE_PART?section->partition:section->device);
|
|
part->part = yon_char_new(section->partition);
|
|
part->device = yon_char_new(section->device);
|
|
if (!yon_char_is_empty(part->part)) part->part_type = ADVANCED_PART_NEW;
|
|
else part->part_type = ADVANCED_PART_EXISTING;
|
|
if (section->format){
|
|
gtk_switch_set_active(GTK_SWITCH(part->FormatSwitch),1);
|
|
if (section->size){
|
|
gtk_spin_button_set_value(GTK_SPIN_BUTTON(part->SizeSpin),section->size);
|
|
gtk_combo_box_set_active(GTK_COMBO_BOX(part->SizeCombo),yon_get_size_get_from_letter(section->size_letter));
|
|
}
|
|
if (section->part_label){
|
|
gtk_entry_set_text(GTK_ENTRY(part->PartLabelEntry),section->part_label);
|
|
}
|
|
if (section->fs_label)
|
|
gtk_entry_set_text(GTK_ENTRY(part->FileSystemLabelEntry),section->fs_label);
|
|
if (!yon_char_is_empty(section->fs_type)){
|
|
gtk_combo_box_set_active_id(GTK_COMBO_BOX(part->FileSystemTypeCombo),section->fs_type);
|
|
}
|
|
if (!yon_char_is_empty(section->encryption)){
|
|
gtk_combo_box_set_active_id(GTK_COMBO_BOX(part->EncryptionCombo),section->encryption);
|
|
gtk_entry_set_text(GTK_ENTRY(part->EncryptionEntry),section->encryption_password);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void yon_advanced_update(main_window *widgets){
|
|
yon_advanced_partition_clear(widgets);
|
|
int virtual_found = 0;
|
|
for (int i=0;i<sections_size;i++){
|
|
advanced_partition *part = yon_advanced_partition_new();
|
|
if (sections[i]->partition_widgets) sections[i]->partition_widgets = NULL;
|
|
sections[i]->partition_widgets = part;
|
|
g_signal_connect(G_OBJECT(part->RemoveButton),"clicked",G_CALLBACK(on_advanced_part_remove),widgets);
|
|
g_signal_connect(G_OBJECT(part->SystemSectionToggle),"clicked",G_CALLBACK(on_advanced_section_toggled),widgets);
|
|
g_signal_connect(G_OBJECT(part->UserDataSectionToggle),"clicked",G_CALLBACK(on_advanced_section_toggled),widgets);
|
|
g_signal_connect(G_OBJECT(part->SizeCombo),"changed",G_CALLBACK(on_advanced_size_changed),widgets);
|
|
if (i==0){
|
|
gtk_widget_set_sensitive(part->SystemSectionToggle,0);
|
|
gtk_widget_set_sensitive(part->UserDataSectionToggle,0);
|
|
GtkWidget *SystemImage = gtk_button_get_image(GTK_BUTTON(part->SystemSectionToggle));
|
|
GtkWidget *UserImage = gtk_button_get_image(GTK_BUTTON(part->UserDataSectionToggle));
|
|
gtk_image_set_from_icon_name(GTK_IMAGE(SystemImage),toggled_icon_name,GTK_ICON_SIZE_BUTTON);
|
|
gtk_image_set_from_icon_name(GTK_IMAGE(UserImage),toggled_icon_name,GTK_ICON_SIZE_BUTTON);
|
|
}
|
|
yon_advanced_partition_set_from_section(part,sections[i]);
|
|
yon_advanced_set_max_size_from_partition(part,widgets);
|
|
gtk_box_pack_start(GTK_BOX(widgets->AdvancedPartitionAddBox),part->MainBox,0,0,0);
|
|
g_signal_handlers_block_by_func(G_OBJECT(widgets->AdvancedVirtualDeviceCombo),G_CALLBACK(on_advanced_virtual_device_changed),widgets);
|
|
if (!virtual_found&>k_combo_box_set_active_id(GTK_COMBO_BOX(widgets->AdvancedVirtualDeviceCombo),sections[i]->part_source==PART_SOURCE_PART?sections[i]->partition:sections[i]->device)){
|
|
virtual_found=1;
|
|
}
|
|
g_signal_handlers_unblock_by_func(G_OBJECT(widgets->AdvancedVirtualDeviceCombo),G_CALLBACK(on_advanced_virtual_device_changed),widgets);
|
|
|
|
part->part_type = ADVANCED_PART_EXISTING;
|
|
}
|
|
if (!virtual_found||!sections_size) {
|
|
g_signal_handlers_block_by_func(G_OBJECT(widgets->AdvancedVirtualDeviceCombo),G_CALLBACK(on_advanced_virtual_device_changed),widgets);
|
|
gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->AdvancedVirtualDeviceCombo),0);
|
|
g_signal_handlers_unblock_by_func(G_OBJECT(widgets->AdvancedVirtualDeviceCombo),G_CALLBACK(on_advanced_virtual_device_changed),widgets);
|
|
}
|
|
yon_advanced_section_update(widgets);
|
|
GtkTreeIter itar;
|
|
for_iter(GTK_TREE_MODEL(widgets->PartitionsList),&itar){
|
|
int status;
|
|
char *target;
|
|
gtk_tree_model_get(GTK_TREE_MODEL(widgets->PartitionsList),&itar,0,&target,7,&status,-1);
|
|
if (!((sections_size>0&&!strcmp(target,sections[0]->part_source==PART_SOURCE_PART?sections[0]->partition:sections[0]->device))||(sections_size>1&&!strcmp(target,sections[1]->part_source==PART_SOURCE_PART?sections[1]->partition:sections[1]->device)))){
|
|
gtk_list_store_set(widgets->PartitionsList,&itar,7,0,-1);
|
|
}
|
|
}
|
|
if (sections_size>=2){
|
|
gtk_widget_hide(widgets->AdvancedAddButton);
|
|
} else {
|
|
gtk_widget_show(widgets->AdvancedAddButton);
|
|
|
|
}
|
|
}
|
|
|
|
void on_advanced_partition_create(GtkWidget *, main_window *widgets){
|
|
GtkTreeIter iter, *last_unvalid = NULL;
|
|
int found = 0;
|
|
for_iter(GTK_TREE_MODEL(widgets->DevicesList),&iter){
|
|
char *target;
|
|
int active;
|
|
gtk_tree_model_get(GTK_TREE_MODEL(widgets->DevicesList),&iter,0,&target,5,&active,-1);
|
|
if (active){
|
|
if (!yon_advanced_section_get(target)){
|
|
last_unvalid = gtk_tree_iter_copy(&iter);
|
|
} else {
|
|
found=1;
|
|
if (sections_size==2) break;
|
|
advanced_section *section = yon_advanced_section_new();
|
|
section->part_source = PART_SOURCE_DEVICE;
|
|
section->device = target;
|
|
section->partition = NULL;
|
|
sections[sections_size]=section;
|
|
sections_size++;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if (!found&&last_unvalid){
|
|
char *target;
|
|
int active;
|
|
gtk_tree_model_get(GTK_TREE_MODEL(widgets->DevicesList),last_unvalid,0,&target,5,&active,-1);
|
|
|
|
if (sections_size==2) return;
|
|
advanced_section *section = yon_advanced_section_new();
|
|
section->part_source = PART_SOURCE_DEVICE;
|
|
section->device = target;
|
|
section->partition = NULL;
|
|
sections[sections_size]=section;
|
|
sections_size++;
|
|
}
|
|
yon_advanced_update(widgets);
|
|
}
|
|
|
|
void on_advanced_partition_add(GtkWidget *, char *path, main_window *widgets){
|
|
GtkTreeIter iter;
|
|
if (gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(widgets->PartitionsList),&iter,path)){
|
|
char *target, *device;
|
|
int status;
|
|
gtk_tree_model_get(GTK_TREE_MODEL(widgets->PartitionsList),&iter,0,&target,7,&status,9,&device,-1);
|
|
gtk_list_store_set(widgets->DevicesList,&iter,7,!status,-1);
|
|
if (!status){
|
|
if (sections_size==2) return;
|
|
advanced_section *section = yon_advanced_section_new();
|
|
section->part_source = PART_SOURCE_PART;
|
|
section->device = NULL;
|
|
section->partition = target = device;
|
|
sections[sections_size]=section;
|
|
sections_size++;
|
|
} else {
|
|
yon_advanced_section_remove_by_name(target);
|
|
}
|
|
}
|
|
yon_advanced_update(widgets);
|
|
|
|
}
|
|
|
|
void yon_install_advanced_init(main_window *widgets){
|
|
gtk_combo_box_text_remove_all(GTK_COMBO_BOX_TEXT(widgets->AdvancedVirtualDeviceCombo));
|
|
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(widgets->AdvancedVirtualDeviceCombo),NO_LABEL);
|
|
gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->AdvancedVirtualDeviceCombo),0);
|
|
int size;
|
|
config_str vmf_file = yon_resource_open_file(vfs_list_path,&size);
|
|
for (int i=1;i<size;i++){
|
|
int parsed_size;
|
|
config_str parsed = yon_char_parse(vmf_file[i],&parsed_size,";");
|
|
gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(widgets->AdvancedVirtualDeviceCombo),parsed[2],parsed[0]);
|
|
yon_char_parsed_free(parsed,parsed_size);
|
|
}
|
|
yon_char_parsed_free(vmf_file,size);
|
|
}
|
|
|
|
void on_install_advanced_partition_chosen(GtkCellRenderer*, gchar *path, main_window *widgets){
|
|
GtkTreeIter iter;
|
|
GtkTreeModel *model = GTK_TREE_MODEL(widgets->PartitionsList);
|
|
|
|
int chosen = 0;
|
|
chosen = yon_advanced_get_part_size(widgets);
|
|
|
|
gtk_tree_model_get_iter_from_string(model,&iter,path);
|
|
int status;
|
|
char *target_part, *device;
|
|
gtk_tree_model_get(model,&iter,0,&target_part,7,&status,9,&device,-1);
|
|
|
|
if (!status){
|
|
if (chosen<2){
|
|
gtk_list_store_set(widgets->PartitionsList,&iter,7,!status,-1);
|
|
chosen++;
|
|
advanced_section *section = yon_advanced_section_new();
|
|
section->part_source = PART_SOURCE_PART;
|
|
section->partition = target_part;
|
|
section->device = NULL;
|
|
sections[sections_size]=section;
|
|
sections_size++;
|
|
}
|
|
} else {
|
|
gtk_list_store_set(widgets->PartitionsList,&iter,7,!status,-1);
|
|
yon_advanced_section_remove_by_name(target_part);
|
|
}
|
|
yon_advanced_update(widgets);
|
|
}
|
|
|
|
void yon_advanced_parts_update(main_window *widgets){
|
|
int size;
|
|
config_str partitions;
|
|
partitions = yon_config_load(yon_debug_output("%s\n",get_parts_and_devices_command),&size);
|
|
for (int i=0;i<size;i++){
|
|
yon_char_remove_last_symbol(partitions[i],'\n');
|
|
}
|
|
|
|
GtkTreeModel *model = GTK_TREE_MODEL(widgets->DevicesList);
|
|
GtkTreeIter iter;
|
|
for_iter (model,&iter){
|
|
char *disk_path;
|
|
int status;
|
|
gtk_tree_model_get(model,&iter,0,&disk_path,5,&status,-1);
|
|
if (!status) continue;
|
|
|
|
for (int i=0;i<size;i++){
|
|
int parsed_size;
|
|
config_str parsed = yon_char_parse(partitions[i],&parsed_size,";");
|
|
if (!strcmp(parsed[0],"part")){
|
|
char *name = parsed[1];
|
|
if (strstr(name,disk_path)){
|
|
char *capacity = NULL;
|
|
long capacity_long = 0;
|
|
char *free_space = NULL;
|
|
long free_space_long = 0;
|
|
char *fs_type = NULL;
|
|
char *label = NULL;
|
|
|
|
if (parsed_size>2){
|
|
char sizemod='\0';
|
|
capacity_long = atol(parsed[2]);
|
|
|
|
char *temp = yon_char_from_double(yon_size_long_convert_automatic(capacity_long,&sizemod));
|
|
capacity = yon_char_append_c(temp,sizemod);
|
|
free(temp);
|
|
}
|
|
if (parsed_size>7&&!yon_char_is_empty(parsed[7])){
|
|
char sizemod='\0';
|
|
free_space_long = capacity_long-atol(parsed[7]);
|
|
char *temp = yon_char_from_double(yon_size_long_convert_automatic(free_space_long,&sizemod));
|
|
free_space = yon_char_append_c(temp,sizemod);
|
|
free(temp);
|
|
}
|
|
if (parsed_size>3){
|
|
fs_type = parsed[3];
|
|
}
|
|
if (parsed_size>4){
|
|
label = parsed[4];
|
|
}
|
|
|
|
GtkTreeIter itar;
|
|
gtk_list_store_append(widgets->PartitionsList,&itar);
|
|
gtk_list_store_set(widgets->PartitionsList,&itar,0,name,1,capacity,2,free_space,3,fs_type,4,label,5,capacity_long,6,free_space_long,8,1,9,disk_path,-1);
|
|
}
|
|
yon_char_parsed_free(parsed,parsed_size);
|
|
}
|
|
}
|
|
}
|
|
yon_char_parsed_free(partitions,size);
|
|
}
|
|
|
|
void yon_advanced_set_max_size_from_partition(advanced_partition *part, main_window *widgets){
|
|
char *cur_name = part->part_type == ADVANCED_PART_EXISTING?part->device:part->part;
|
|
GtkTreeModel *model = GTK_TREE_MODEL(widgets->PartitionsList);
|
|
GtkTreeIter iter;
|
|
long selected_size;
|
|
|
|
for_iter(model,&iter){
|
|
char *target;
|
|
gtk_tree_model_get(model,&iter,part->part_type == ADVANCED_PART_EXISTING?9:0,&target,-1);
|
|
if (!strcmp(target,cur_name)){
|
|
gtk_tree_model_get(model,&iter,6,&selected_size,-1);
|
|
if (!selected_size){
|
|
gtk_tree_model_get(model,&iter,5,&selected_size,-1);
|
|
}
|
|
if (selected_size){
|
|
GtkAdjustment *adj = gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(part->SizeSpin));
|
|
const char *sizemod = gtk_combo_box_get_active_id(GTK_COMBO_BOX(part->SizeCombo));
|
|
double new_size = yon_size_long_convert_to_mod(selected_size,sizemod[0]);
|
|
gtk_adjustment_set_upper(adj,new_size);
|
|
gdouble old_value = gtk_adjustment_get_value(adj);
|
|
if (old_value>new_size){
|
|
gtk_adjustment_set_value(adj,new_size);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void on_advanced_size_changed(GtkWidget *self,main_window *widgets){
|
|
advanced_partition *part = g_object_get_data(G_OBJECT(self),"advanced_partition");
|
|
yon_advanced_set_max_size_from_partition(part,widgets);
|
|
}
|
|
|
|
void on_install_advanced_device_chosen(GtkCellRenderer *, gchar *path, main_window *widgets){
|
|
gtk_list_store_clear(widgets->PartitionsList);
|
|
yon_advanced_section_remove_all();
|
|
GtkTreeIter iter;
|
|
GtkTreeModel *model = GTK_TREE_MODEL(widgets->DevicesList);
|
|
// chosen = yon_advanced_get_part_size(widgets);
|
|
|
|
if (gtk_tree_model_get_iter_from_string(model,&iter,path)){
|
|
int status;
|
|
char *target;
|
|
gtk_tree_model_get(model,&iter,0,&target,5,&status,-1);
|
|
if (!status){ // checks
|
|
gtk_list_store_set(widgets->DevicesList,&iter,5,!status,-1);
|
|
|
|
} else { // unchecks
|
|
gtk_list_store_set(widgets->DevicesList,&iter,5,!status,-1);
|
|
for_iter (model,&iter){
|
|
gtk_list_store_set(widgets->DevicesList,&iter,6,1,-1);
|
|
}
|
|
}
|
|
}
|
|
int chosen_amount = 0;
|
|
for_iter(model,&iter){
|
|
int status;
|
|
gtk_tree_model_get(model,&iter,5,&status,-1);
|
|
if (status)chosen_amount++;
|
|
}
|
|
gtk_widget_set_sensitive(widgets->AdvancedVirtualDeviceCombo,chosen_amount>=2);
|
|
// if (chosen) gtk_widget_set_sensitive(widgets->AdvancedAddButton,1);
|
|
// else gtk_widget_set_sensitive(widgets->AdvancedAddButton,0);
|
|
yon_advanced_parts_update(widgets);
|
|
yon_advanced_update(widgets);
|
|
}
|
|
|
|
void on_advanced_password_clicked(GtkWidget *, advanced_partition *part){
|
|
yon_password_window *window = yon_password_open(GTK_ENTRY(part->EncryptionEntry));
|
|
gtk_widget_hide(gtk_widget_get_parent(window->EncryptionCombo));
|
|
gtk_widget_hide(window->HashBox);
|
|
gtk_widget_hide(window->NoEncriptionCheck);
|
|
}
|
|
|
|
void yon_advanced_partition_clear(main_window *widgets){
|
|
GList *list = gtk_container_get_children(GTK_CONTAINER(widgets->AdvancedPartitionAddBox));
|
|
GList *iter;
|
|
for (iter=list;iter;iter=iter->next){
|
|
advanced_partition *part = g_object_get_data(G_OBJECT(iter->data),"advanced_partition");
|
|
gtk_widget_destroy(GTK_WIDGET(iter->data));
|
|
free(part);
|
|
}
|
|
}
|
|
|
|
int yon_advanced_get_part_size(main_window *widgets){
|
|
int size = 0;
|
|
GList *list = gtk_container_get_children(GTK_CONTAINER(widgets->AdvancedPartitionAddBox));
|
|
size = g_list_length(list);
|
|
g_list_free(list);
|
|
return size;
|
|
}
|
|
|
|
void yon_advanced_section_update_section(advanced_partition *part,GtkWidget *cur_toggle,main_window *widgets){
|
|
int systoggle = cur_toggle == part->SystemSectionToggle;
|
|
advanced_section *section = sections[yon_advanced_section_get_by_part(part)];
|
|
g_signal_handlers_block_by_func(G_OBJECT(cur_toggle),G_CALLBACK(on_advanced_section_toggled),widgets);
|
|
gboolean active = systoggle?section->sys_section:section->user_section;
|
|
gtk_widget_set_sensitive(cur_toggle,!active);
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cur_toggle),active);
|
|
g_signal_handlers_unblock_by_func(G_OBJECT(cur_toggle),G_CALLBACK(on_advanced_section_toggled),widgets);
|
|
GtkWidget *compare_image = gtk_button_get_image(GTK_BUTTON(cur_toggle));
|
|
gtk_image_set_from_icon_name(GTK_IMAGE(compare_image),!active?untoggled_icon_name:toggled_icon_name,GTK_ICON_SIZE_BUTTON);
|
|
}
|
|
|
|
void yon_advanced_section_update(main_window *widgets){
|
|
GList *list = gtk_container_get_children(GTK_CONTAINER(widgets->AdvancedPartitionAddBox));
|
|
GList *iter;
|
|
for (iter=list;iter;iter=iter->next){
|
|
advanced_partition *compare_part = g_object_get_data(G_OBJECT(iter->data),"advanced_partition");
|
|
GtkWidget *cur_toggle = compare_part->SystemSectionToggle;
|
|
yon_advanced_section_update_section(compare_part,cur_toggle,widgets);
|
|
cur_toggle = compare_part->UserDataSectionToggle;
|
|
yon_advanced_section_update_section(compare_part,cur_toggle,widgets);
|
|
}
|
|
}
|
|
|
|
void on_advanced_section_toggled(GtkWidget *self, main_window *widgets){
|
|
advanced_partition *part = g_object_get_data(G_OBJECT(self),"advanced_partition");
|
|
int pos = yon_advanced_section_get_by_part(part);
|
|
if (self == part->SystemSectionToggle){
|
|
sections[pos]->sys_section = 1;
|
|
if (sections[!pos]&§ions[pos]->user_section){
|
|
sections[pos]->user_section=0;
|
|
sections[!pos]->user_section=1;
|
|
}
|
|
} else {
|
|
sections[pos]->user_section = 1;
|
|
if (sections[!pos]&§ions[pos]->sys_section){
|
|
sections[pos]->sys_section=0;
|
|
sections[!pos]->sys_section=1;
|
|
}
|
|
}
|
|
GList *list = gtk_container_get_children(GTK_CONTAINER(widgets->AdvancedPartitionAddBox));
|
|
GList *iter;
|
|
for (iter=list;iter;iter=iter->next){
|
|
advanced_partition *compare_part = g_object_get_data(G_OBJECT(iter->data),"advanced_partition");
|
|
if (part != compare_part) {
|
|
if (self == part->SystemSectionToggle){
|
|
sections[yon_advanced_section_get_by_part(compare_part)]->sys_section = 0;
|
|
} else {
|
|
sections[yon_advanced_section_get_by_part(compare_part)]->user_section = 0;
|
|
}
|
|
}
|
|
}
|
|
yon_advanced_section_update(widgets);
|
|
}
|
|
|
|
int yon_advanced_save(main_window *widgets){
|
|
yon_config_register(AUTOINSTALL_TYPE_INSTALL,AUTOINSTALL_TYPE_INSTALL_command,"custom");
|
|
char *devices[2] = {NULL};
|
|
char *parts[2] = {NULL};
|
|
char *part_size[2] = {NULL};
|
|
char *part_label[2] = {NULL};
|
|
char *fs_type[2] = {NULL};
|
|
char *fs_label[2] = {NULL};
|
|
char *encryption[2] = {NULL};
|
|
char *format[2] = {NULL};
|
|
if (!sections_size){
|
|
return 0;
|
|
}
|
|
advanced_section *cur_section = sections[0]->sys_section?sections[0]:sections[1];
|
|
if (!yon_char_is_empty(cur_section->partition)){
|
|
if (!yon_char_is_empty(cur_section->partition)){
|
|
parts[0]=cur_section->partition;
|
|
} else {
|
|
parts[0]="";
|
|
}
|
|
} else {
|
|
devices[0]=cur_section->device;
|
|
}
|
|
if (cur_section->user_section){
|
|
if (!yon_char_is_empty(cur_section->device)){
|
|
if (!yon_char_is_empty(cur_section->partition)){
|
|
parts[1]=cur_section->partition;
|
|
} else {
|
|
parts[1]="";
|
|
}
|
|
} else {
|
|
devices[1]=cur_section->device;
|
|
}
|
|
}
|
|
if (cur_section->size){
|
|
char *size_str = yon_char_from_long(cur_section->size);
|
|
char *sz_str = yon_char_append_c(size_str,cur_section->size_letter);
|
|
part_size[0]=sz_str;
|
|
}
|
|
if (!yon_char_is_empty(cur_section->part_label)){
|
|
part_label[0]=cur_section->part_label;
|
|
}
|
|
if (!yon_char_is_empty(cur_section->fs_type)){
|
|
fs_type[0]=cur_section->fs_type;
|
|
}
|
|
if (!yon_char_is_empty(cur_section->fs_label)){
|
|
fs_label[0]=cur_section->fs_label;
|
|
}
|
|
if (cur_section->format){
|
|
format[0]="yes";
|
|
} else {
|
|
format[0]="no";
|
|
}
|
|
if (!yon_char_is_empty(cur_section->encryption)){
|
|
char *encrypt_str = yon_char_unite(cur_section->encryption,":",cur_section->encryption_password,NULL);
|
|
encryption[0]=encrypt_str;
|
|
}
|
|
if (sections_size>1){
|
|
cur_section = sections[0]->sys_section?sections[1]:sections[0];
|
|
|
|
devices[1]=cur_section->device;
|
|
if (!yon_char_is_empty(cur_section->partition)){
|
|
parts[1]=cur_section->partition;
|
|
} else {
|
|
parts[1]="";
|
|
}
|
|
if (cur_section->size){
|
|
char *size_str = yon_char_from_long(cur_section->size);
|
|
char *sz_str = yon_char_append_c(size_str,cur_section->size_letter);
|
|
part_size[1]=sz_str;
|
|
}
|
|
if (!yon_char_is_empty(cur_section->part_label)){
|
|
part_label[1]=cur_section->part_label;
|
|
}
|
|
if (!yon_char_is_empty(cur_section->fs_type)){
|
|
fs_type[1]=cur_section->fs_type;
|
|
}
|
|
if (!yon_char_is_empty(cur_section->fs_label)){
|
|
fs_label[1]=cur_section->fs_label;
|
|
}
|
|
if (cur_section->format){
|
|
format[1]="yes";
|
|
} else {
|
|
format[1]="no";
|
|
}
|
|
if (!yon_char_is_empty(cur_section->encryption)){
|
|
char *encrypt_str = yon_char_unite(cur_section->encryption,":",cur_section->encryption_password,NULL);
|
|
encryption[1]=encrypt_str;
|
|
}
|
|
}
|
|
|
|
if (devices[0]||devices[1]){
|
|
char *devices_str = yon_char_parsed_to_string_full(devices,2,",");
|
|
yon_config_register(AUTOINSTALL_DEVICE,AUTOINSTALL_DEVICE_command,devices_str);
|
|
}
|
|
if (!yon_char_is_empty(parts[0])||!yon_char_is_empty(parts[1])){
|
|
char *parts_str = yon_char_parsed_to_string_full(parts,2,",");
|
|
yon_config_register(part_parameter,part_parameter_command,parts_str);
|
|
}
|
|
if (part_size[0]||part_size[1]){
|
|
char *part_size_str = yon_char_parsed_to_string_full(part_size,2,",");
|
|
yon_config_register(part_size_parameter,part_size_parameter_command,part_size_str);
|
|
}
|
|
if (part_label[0]||part_label[1]){
|
|
char *part_label_str = yon_char_parsed_to_string_full(part_label,2,",");
|
|
yon_config_register(part_label_parameter,part_label_parameter_command,part_label_str);
|
|
|
|
}
|
|
if (fs_type[0]||fs_type[1]){
|
|
char *fs_type_str = yon_char_parsed_to_string_full(fs_type,2,",");
|
|
yon_config_register(part_fs_type_parameter,part_fs_type_parameter_command,fs_type_str);
|
|
|
|
}
|
|
if (fs_label[0]||fs_label[1]){
|
|
char *fs_label_str = yon_char_parsed_to_string_full(fs_label,2,",");
|
|
yon_config_register(part_fs_label_parameter,part_fs_label_parameter_command,fs_label_str);
|
|
|
|
}
|
|
if (encryption[0]||encryption[1]){
|
|
char *encryption_str = yon_char_parsed_to_string_full(encryption,2,",");
|
|
yon_config_register(part_crypt_parameter,part_crypt_parameter_command,encryption_str);
|
|
|
|
}
|
|
if (format[0]||format[1]){
|
|
char *format_str = yon_char_parsed_to_string_full(format,2,",");
|
|
yon_config_register(part_format_parameter,part_format_parameter_command,format_str);
|
|
|
|
}
|
|
if (gtk_switch_get_active(GTK_SWITCH(widgets->AdvancedLoadTypeSwitch))){
|
|
char *boot = NULL;
|
|
if (gtk_switch_get_active(GTK_SWITCH(widgets->AdvancedBiosSectorSwitch))){
|
|
yon_char_append_element(boot,"bios","+");
|
|
}
|
|
if (gtk_switch_get_active(GTK_SWITCH(widgets->AdvancedEFISwitch))){
|
|
yon_char_append_element(boot,"efi","+");
|
|
|
|
}
|
|
if (!yon_char_is_empty(boot)){
|
|
yon_config_register(boot_parameter,boot_parameter_command,boot);
|
|
} else {
|
|
yon_config_remove_by_key(boot_parameter);
|
|
}
|
|
} else {
|
|
yon_config_remove_by_key(boot_parameter);
|
|
}
|
|
if (gtk_switch_get_active(GTK_SWITCH(widgets->AdvancedSwapSwitch))){
|
|
if (gtk_switch_get_active(GTK_SWITCH(widgets->AdvancedSwapAutoSwitch))){
|
|
yon_config_register(swap_parameter,swap_parameter_command,"auto");
|
|
|
|
} else if (gtk_switch_get_active(GTK_SWITCH(widgets->AdvancedSwapRamSwitch))){
|
|
yon_config_register(swap_parameter,swap_parameter_command,"yes");
|
|
yon_config_register(swap_size_parameter,swap_parameter_command,"ram");
|
|
|
|
} else if (gtk_switch_get_active(GTK_SWITCH(widgets->AdvancedSwapFixedSwitch))){
|
|
yon_config_register(swap_parameter,swap_parameter_command,"yes");
|
|
long swap_size = gtk_spin_button_get_value(GTK_SPIN_BUTTON(widgets->AdvancedSwapFixedSpin));
|
|
int size_letter = gtk_switch_get_active(GTK_SWITCH(widgets->AdvancedSwapFixedSizeSwitch));
|
|
char *swap_str = yon_char_from_long(swap_size);
|
|
char *size_final = yon_char_unite(swap_str,size_letter?"G":"M",NULL);
|
|
yon_config_register(swap_size_parameter,swap_parameter_command,size_final);
|
|
} else {
|
|
yon_config_remove_by_key(swap_parameter);
|
|
yon_config_remove_by_key(swap_size_parameter);
|
|
}
|
|
}
|
|
char *parameters = yon_config_get_all_info();
|
|
yon_debug_output("%s\n",parameters);
|
|
return 1;
|
|
}
|
|
|
|
|
|
void yon_advanced_part_parameter_changed(GtkWidget *self, advanced_partition *part){
|
|
advanced_section *section = sections[yon_advanced_section_get_by_part(part)];
|
|
if (self == part->SizeCombo||self == part->SizeSpin){
|
|
section->size = gtk_spin_button_get_value(GTK_SPIN_BUTTON(part->SizeSpin));
|
|
int size_id = gtk_combo_box_get_active(GTK_COMBO_BOX(part->SizeCombo));
|
|
section->size_letter = *yon_size_get_mod(size_id>-1?size_id:0);
|
|
} else if (self == part->PartLabelEntry){
|
|
section->part_label = yon_char_new(gtk_entry_get_text(GTK_ENTRY(part->PartLabelEntry)));
|
|
} else if (self == part->FileSystemTypeCombo){
|
|
section->fs_type = yon_char_new(gtk_combo_box_get_active_id(GTK_COMBO_BOX(part->FileSystemTypeCombo)));
|
|
} else if (self == part->FileSystemLabelEntry){
|
|
section->fs_label = yon_char_new(gtk_entry_get_text(GTK_ENTRY(part->FileSystemLabelEntry)));
|
|
} else if (self == part->EncryptionCombo||self == part->EncryptionEntry){
|
|
section->encryption = yon_char_new(gtk_combo_box_get_active_id(GTK_COMBO_BOX(part->EncryptionCombo)));
|
|
section->encryption_password = yon_char_new(gtk_entry_get_text(GTK_ENTRY(part->EncryptionEntry)));
|
|
} else if (self == part->FormatSwitch){
|
|
if (gtk_switch_get_active(GTK_SWITCH(part->FormatSwitch))){
|
|
section->format=1;
|
|
} else {
|
|
section->format=0;
|
|
}
|
|
}
|
|
}
|
|
|
|
gboolean on_format_changed(GtkWidget *self, gboolean , advanced_partition *part){
|
|
yon_advanced_part_parameter_changed(self, part);
|
|
return 0;
|
|
}
|
|
|
|
advanced_partition *yon_advanced_partition_new(){
|
|
advanced_partition *part = new(advanced_partition);
|
|
GtkBuilder *builder = gtk_builder_new_from_resource(glade_path_advanced_part);
|
|
part->MainBox = yon_gtk_builder_get_widget(builder,"MainBox");
|
|
part->SectionLabel = yon_gtk_builder_get_widget(builder,"SectionLabel");
|
|
part->SystemSectionToggle = yon_gtk_builder_get_widget(builder,"SystemSectionToggle");
|
|
part->UserDataSectionToggle = yon_gtk_builder_get_widget(builder,"UserDataSectionToggle");
|
|
part->RemoveButton = yon_gtk_builder_get_widget(builder,"RemoveButton");
|
|
part->FormatSwitch = yon_gtk_builder_get_widget(builder,"FormatSwitch");
|
|
part->SizeSpin = yon_gtk_builder_get_widget(builder,"SizeSpin");
|
|
part->SizeCombo = yon_gtk_builder_get_widget(builder,"SizeCombo");
|
|
part->PartLabelEntry = yon_gtk_builder_get_widget(builder,"PartLabelEntry");
|
|
part->FileSystemTypeCombo = yon_gtk_builder_get_widget(builder,"FileSystemTypeCombo");
|
|
part->FileSystemLabelEntry = yon_gtk_builder_get_widget(builder,"FileSystemLabelEntry");
|
|
part->EncryptionCombo = yon_gtk_builder_get_widget(builder,"EncryptionCombo");
|
|
part->EncryptionEntry = yon_gtk_builder_get_widget(builder,"EncryptionEntry");
|
|
part->EncryptionButton = yon_gtk_builder_get_widget(builder,"EncryptionButton");
|
|
part->FormatRevealer = yon_gtk_builder_get_widget(builder,"FormatRevealer");
|
|
part->order_iter = NULL;
|
|
part->part = NULL;
|
|
part->device = NULL;
|
|
|
|
yon_gtk_revealer_set_from_switch(GTK_REVEALER(part->FormatRevealer),GTK_SWITCH(part->FormatSwitch));
|
|
g_signal_connect(G_OBJECT(part->EncryptionButton),"clicked",G_CALLBACK(on_advanced_password_clicked),part);
|
|
g_signal_connect(G_OBJECT(part->EncryptionCombo),"changed",G_CALLBACK(yon_gtk_widget_set_sensitive_from_combo_box),part->EncryptionButton);
|
|
g_signal_connect(G_OBJECT(part->EncryptionCombo),"changed",G_CALLBACK(yon_gtk_widget_set_sensitive_from_combo_box),part->EncryptionEntry);
|
|
g_signal_connect(G_OBJECT(part->EncryptionEntry),"changed",G_CALLBACK(yon_advanced_part_parameter_changed),part);
|
|
g_signal_connect(G_OBJECT(part->FormatSwitch),"state-set",G_CALLBACK(on_format_changed),part);
|
|
g_signal_connect(G_OBJECT(part->SizeCombo),"changed",G_CALLBACK(yon_advanced_part_parameter_changed),part);
|
|
g_signal_connect(G_OBJECT(part->SizeSpin),"changed",G_CALLBACK(yon_advanced_part_parameter_changed),part);
|
|
g_signal_connect(G_OBJECT(part->PartLabelEntry),"changed",G_CALLBACK(yon_advanced_part_parameter_changed),part);
|
|
g_signal_connect(G_OBJECT(part->FileSystemTypeCombo),"changed",G_CALLBACK(yon_advanced_part_parameter_changed),part);
|
|
g_signal_connect(G_OBJECT(part->FileSystemLabelEntry),"changed",G_CALLBACK(yon_advanced_part_parameter_changed),part);
|
|
g_signal_connect(G_OBJECT(part->EncryptionCombo),"changed",G_CALLBACK(yon_advanced_part_parameter_changed),part);
|
|
|
|
|
|
yon_fs_type_setup(GTK_COMBO_BOX_TEXT(part->FileSystemTypeCombo));
|
|
|
|
g_object_set_data(G_OBJECT(part->MainBox),"advanced_partition",part);
|
|
g_object_set_data(G_OBJECT(part->SizeCombo),"advanced_partition",part);
|
|
g_object_set_data(G_OBJECT(part->RemoveButton),"advanced_partition",part);
|
|
g_object_set_data(G_OBJECT(part->SystemSectionToggle),"advanced_partition",part);
|
|
g_object_set_data(G_OBJECT(part->UserDataSectionToggle),"advanced_partition",part);
|
|
|
|
int size;
|
|
config_str encryptions = yon_char_parsed_new(&size,encryptions_list,NULL);
|
|
for (int i=0;i<size;i++){
|
|
gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(part->EncryptionCombo),encryptions[i],encryptions[i]);
|
|
}
|
|
yon_char_parsed_free(encryptions,size);
|
|
return part;
|
|
}
|
|
|
|
void on_advanced_part_remove(GtkWidget *self, main_window *widgets){
|
|
advanced_partition *part = g_object_get_data(G_OBJECT(self),"advanced_partition");
|
|
yon_advanced_section_remove(part);
|
|
if (sections_size){
|
|
sections[0]->sys_section=1;
|
|
sections[0]->user_section=1;
|
|
}
|
|
yon_advanced_update(widgets);
|
|
|
|
}
|
|
|
|
int yon_advanced_section_append(advanced_section *section){
|
|
if (sections_size==2) return -1;
|
|
sections[sections_size] = section;
|
|
sections_size++;
|
|
return sections_size-1;
|
|
}
|
|
|
|
void on_advanced_virtual_device_changed(GtkWidget *, main_window *widgets){
|
|
yon_advanced_section_remove_all();
|
|
char *device = (char*)gtk_combo_box_get_active_id(GTK_COMBO_BOX(widgets->AdvancedVirtualDeviceCombo));
|
|
int size;
|
|
config_str vfs_file = yon_resource_open_file(vfs_list_path,&size);
|
|
config_str cur_device = NULL;
|
|
for (int i=0;i<size;i++){
|
|
int parsed_size;
|
|
config_str parsed = yon_char_parse(vfs_file[i],&parsed_size,";");
|
|
if (!yon_char_is_empty(device)&&!yon_char_is_empty(parsed[2])&!strcmp(parsed[2],device)){
|
|
cur_device = parsed;
|
|
gtk_label_set_text(GTK_LABEL(widgets->AdvancedVirtualDeviceLabel),parsed[1]);
|
|
} else {
|
|
yon_char_parsed_free(parsed,parsed_size);
|
|
}
|
|
}
|
|
if (!yon_char_is_empty(device)){
|
|
GtkTreeIter iter;
|
|
GtkTreeModel *model = GTK_TREE_MODEL(widgets->DevicesList);
|
|
int active_devices=0;
|
|
for_iter(model,&iter){
|
|
int status;
|
|
gtk_tree_model_get(model,&iter,5,&status,-1);
|
|
if (status) active_devices++;
|
|
}
|
|
if (atoi(cur_device[3])>active_devices){
|
|
yon_ubl_status_box_spawn(GTK_CONTAINER(widgets->StatusBox),COUNT_INVALID_LABEL(cur_device[3]),5,BACKGROUND_IMAGE_INFO_TYPE);
|
|
yon_ubl_status_highlight_incorrect(widgets->AdvancedVirtualDeviceCombo);
|
|
yon_char_parsed_free(cur_device,4);
|
|
return;
|
|
}
|
|
|
|
if (atoi(cur_device[4])%active_devices!=0){
|
|
yon_ubl_status_box_spawn(GTK_CONTAINER(widgets->StatusBox),PARITY_INVALID_LABEL(cur_device[4]),5,BACKGROUND_IMAGE_INFO_TYPE);
|
|
yon_ubl_status_highlight_incorrect(widgets->AdvancedVirtualDeviceCombo);
|
|
yon_char_parsed_free(cur_device,4);
|
|
return;
|
|
}
|
|
|
|
advanced_section *section = yon_advanced_section_new();
|
|
section->part_source = PART_SOURCE_VIRTUAL;
|
|
section->partition = device;
|
|
section->device = device;
|
|
yon_advanced_section_append(section);
|
|
|
|
}
|
|
yon_char_parsed_free(vfs_file,size);
|
|
yon_advanced_update(widgets);
|
|
} |