parent
df34f7f48b
commit
e482336d47
@ -0,0 +1,256 @@
|
||||
#include "ubinstall-gtk.h"
|
||||
|
||||
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));
|
||||
return section;
|
||||
}
|
||||
|
||||
void yon_advanced_section_remove(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;
|
||||
}
|
||||
}
|
||||
|
||||
int yon_advanced_section_get(char *partition){
|
||||
if (yon_char_is_empty(partition)) return -1;
|
||||
if (sections_size>0&&!strcmp(sections[0]->part_label,partition)){
|
||||
return 0;
|
||||
} else if (sections_size>1&&!strcmp(sections[1]->part_label,partition)){
|
||||
return 1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void yon_advanced_partition_set_from_section(advanced_partition *part, advanced_section *section){
|
||||
gtk_label_set_text(GTK_LABEL(part->SectionLabel),section->part_label);
|
||||
if (section->format){
|
||||
gtk_switch_set_active(GTK_SWITCH(part->FormatSwitch),1);
|
||||
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));
|
||||
gtk_entry_set_text(GTK_ENTRY(part->PartLabelEntry),section->part_label);
|
||||
gtk_entry_set_text(GTK_ENTRY(part->FileSystemLabelEntry),section->fs_label);
|
||||
gtk_combo_box_set_active_id(GTK_COMBO_BOX(part->FileSystemTypeCombo),section->fs_type);
|
||||
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){
|
||||
GList *list = gtk_container_get_children(GTK_CONTAINER(widgets->AdvancedPartitionAddBox));
|
||||
GList *iter;
|
||||
for (iter = list; iter; iter=iter->next){
|
||||
gtk_widget_destroy(GTK_WIDGET(iter->data));
|
||||
}
|
||||
for (int i=0;i<sections_size;i++){
|
||||
advanced_partition *part = yon_advanced_partition_new();
|
||||
yon_advanced_partition_set_from_section(part,sections[i]);
|
||||
gtk_box_pack_start(GTK_BOX(widgets->AdvancedPartitionAddBox),part->MainBox,0,0,0);
|
||||
}
|
||||
}
|
||||
|
||||
void on_advanced_partition_create(GtkWidget *, main_window *widgets){
|
||||
GtkTreeIter iter;
|
||||
for_iter(GTK_TREE_MODEL(widgets->DevicesList),&iter){
|
||||
char *target;
|
||||
int active;
|
||||
gtk_tree_model_get(GTK_TREE_MODEL(widgets->DevicesList),&iter,0,&target,3,&active,-1);
|
||||
gtk_list_store_set(widgets->DevicesList,&iter,3,!active,-1);
|
||||
if (!active){
|
||||
if (sections_size==2) return;
|
||||
advanced_section *section = yon_advanced_section_new();
|
||||
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;
|
||||
int status;
|
||||
gtk_tree_model_get(GTK_TREE_MODEL(widgets->PartitionsList),&iter,0,&target,5,&status,-1);
|
||||
gtk_list_store_set(widgets->DevicesList,&iter,3,!status,-1);
|
||||
if (!status){
|
||||
if (sections_size==2) return;
|
||||
advanced_section *section = yon_advanced_section_new();
|
||||
sections[sections_size]=section;
|
||||
sections_size++;
|
||||
} else {
|
||||
yon_advanced_section_remove(target);
|
||||
}
|
||||
}
|
||||
yon_advanced_update(widgets);
|
||||
|
||||
}
|
||||
|
||||
void yon_install_advanced_init(main_window *){
|
||||
}
|
||||
|
||||
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;
|
||||
gtk_tree_model_get(model,&iter,0,&target_part,7,&status,-1);
|
||||
|
||||
if (!status){
|
||||
if (chosen<2){
|
||||
gtk_list_store_set(widgets->PartitionsList,&iter,7,!status,-1);
|
||||
chosen++;
|
||||
advanced_partition *part = yon_advanced_partition_new();
|
||||
part->part_type = ADVANCED_PART_EXISTING;
|
||||
part->order_iter = g_sequence_append(widgets->advanced_partition_order,part);
|
||||
part->part = target_part;
|
||||
gtk_box_pack_start(GTK_BOX(widgets->AdvancedPartitionAddBox),part->MainBox,0,0,0);
|
||||
gtk_widget_show(part->MainBox);
|
||||
yon_advanced_partition_setup(part,widgets);
|
||||
on_advanced_parts_added(NULL,NULL,widgets);
|
||||
}
|
||||
} else {
|
||||
gtk_list_store_set(widgets->PartitionsList,&iter,7,!status,-1);
|
||||
advanced_partition *part = g_object_get_data(G_OBJECT(widgets->AdvancedPartitionAddBox),target_part);
|
||||
if (part){
|
||||
on_advanced_part_remove(part->RemoveButton,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,-1);
|
||||
}
|
||||
yon_char_parsed_free(parsed,parsed_size);
|
||||
}
|
||||
}
|
||||
}
|
||||
yon_char_parsed_free(partitions,size);
|
||||
}
|
||||
|
||||
void on_install_advanced_device_chosen(GtkCellRenderer *, gchar *path, main_window *widgets){
|
||||
gtk_list_store_clear(widgets->PartitionsList);
|
||||
yon_advanced_partition_clear(widgets);
|
||||
GtkTreeIter iter;
|
||||
GtkTreeModel *model = GTK_TREE_MODEL(widgets->DevicesList);
|
||||
|
||||
int chosen = 0;
|
||||
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
|
||||
if (chosen <2){
|
||||
gtk_list_store_set(widgets->DevicesList,&iter,5,!status,-1);
|
||||
chosen++;
|
||||
} else {
|
||||
for_iter (model,&iter){
|
||||
gtk_tree_model_get(model,&iter,5,&status,-1);
|
||||
if (!status){
|
||||
gtk_list_store_set(widgets->DevicesList,&iter,6,0,-1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} else { // unchecks
|
||||
gtk_list_store_set(widgets->DevicesList,&iter,5,!status,-1);
|
||||
if (chosen == 2){
|
||||
for_iter (model,&iter){
|
||||
gtk_list_store_set(widgets->DevicesList,&iter,6,1,-1);
|
||||
}
|
||||
}
|
||||
chosen--;
|
||||
}
|
||||
}
|
||||
|
||||
if (chosen) gtk_widget_set_sensitive(widgets->AdvancedAddButton,1);
|
||||
else gtk_widget_set_sensitive(widgets->AdvancedAddButton,0);
|
||||
yon_advanced_parts_update(widgets);
|
||||
}
|
||||
@ -1,64 +0,0 @@
|
||||
#include "ubinstall-gtk.h"
|
||||
|
||||
typedef struct {
|
||||
char *section;
|
||||
int sys_section;
|
||||
int user_section;
|
||||
int format;
|
||||
int size;
|
||||
char size_letter;
|
||||
char *part_label;
|
||||
char *fs_type;
|
||||
char *fs_label;
|
||||
char *encryption;
|
||||
char *encryption_password;
|
||||
|
||||
} advanced_section;
|
||||
|
||||
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));
|
||||
sections[sections_size] = section;
|
||||
sections_size++;
|
||||
return section;
|
||||
}
|
||||
|
||||
void yon_advanced_section_remove(int pos){
|
||||
switch(pos){
|
||||
case 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// add section from tree view
|
||||
void yon_advanced_add(main_window *widgets){
|
||||
|
||||
}
|
||||
|
||||
//new section from button
|
||||
void yon_advanced_new(main_window *widgets){
|
||||
|
||||
}
|
||||
Loading…
Reference in new issue