diff --git a/source/ubinstall-gtk-source.c b/source/ubinstall-gtk-source.c index dc4119c..e052630 100644 --- a/source/ubinstall-gtk-source.c +++ b/source/ubinstall-gtk-source.c @@ -1,17 +1,37 @@ #include "ubinstall-gtk.h" void on_source_changed(GtkComboBox *self){ - GtkWidget *devices_combo = g_object_get_data(G_OBJECT(self),"target"); - GtkWidget *path_button = g_object_get_data(G_OBJECT(self),"button"); - GtkWidget *path_combo = g_object_get_data(G_OBJECT(self),"combo"); + source_element *element = g_object_get_data(G_OBJECT(self),"source_element"); if (gtk_combo_box_get_active(self)){ - gtk_widget_show(path_button); - gtk_widget_show(path_combo); - gtk_widget_hide(devices_combo); + gtk_widget_show(element->PathButton); + gtk_widget_show(element->PathEntry); + gtk_widget_hide(element->DeviceCombo); } else{ - gtk_widget_hide(path_button); - gtk_widget_hide(path_combo); - gtk_widget_show(devices_combo); + gtk_widget_hide(element->PathButton); + gtk_widget_hide(element->PathEntry); + gtk_widget_show(element->DeviceCombo); + } +} + +void yon_source_update(source_window *window){ + GList *list = gtk_container_get_children(GTK_CONTAINER(window->AddBox)); + GList *iter; + for (iter = list; iter; iter = iter->next){ + source_element *element = (source_element*)g_object_get_data(G_OBJECT(iter->data),"source_element"); + if (!iter->next){ + GtkWidget *button = gtk_button_new_from_icon_name(add_icon_path,GTK_ICON_SIZE_BUTTON); + g_signal_connect(G_OBJECT(button),"clicked",G_CALLBACK(on_source_add),window); + gtk_box_pack_end(GTK_BOX(element->MainBox),button,0,0,0); + element->AddButton = button; + gtk_style_context_add_class(gtk_widget_get_style_context(button),"thin"); + gtk_style_context_add_class(gtk_widget_get_style_context(button),"instant"); + gtk_widget_show(button); + } else { + if (element->AddButton) { + gtk_widget_destroy(element->AddButton); + element->AddButton = NULL; + } + } } } @@ -25,22 +45,21 @@ source_element *yon_source_element_new(){ element->DeviceCombo = yon_gtk_builder_get_widget(builder,"DeviceCombo"); element->PathButton = yon_gtk_builder_get_widget(builder,"PathButton"); element->RemoveButton = yon_gtk_builder_get_widget(builder,"RemoveButton"); + element->AddButton = NULL; + yon_gtk_combo_box_block_scroll(GTK_COMBO_BOX(element->DeviceCombo)); yon_gtk_combo_box_block_scroll(GTK_COMBO_BOX(element->TypeCombo)); + g_signal_connect(G_OBJECT(element->RemoveButton),"clicked",G_CALLBACK(on_source_remove),element); g_signal_connect(G_OBJECT(element->PathButton),"clicked",G_CALLBACK(on_source_choose),element); g_signal_connect(G_OBJECT(element->TypeCombo),"changed",G_CALLBACK(on_source_changed),element); - g_object_set_data(G_OBJECT(element->PathButton),"combo",element->TypeCombo); + + g_object_set_data(G_OBJECT(element->PathButton),"source_element",element); g_object_set_data(G_OBJECT(element->MainBox),"source_element",element); - g_object_set_data(G_OBJECT(element->PathButton),"target_combo",element->TypeCombo); - g_object_set_data(G_OBJECT(element->TypeCombo),"target",element->DeviceCombo); - g_object_set_data(G_OBJECT(element->TypeCombo),"button",element->PathButton); - g_object_set_data(G_OBJECT(element->TypeCombo),"combo",element->PathEntry); - gtk_widget_set_sensitive(element->DeviceCombo,0); - gtk_widget_set_sensitive(element->TypeCombo,0); - gtk_widget_set_sensitive(element->PathEntry,0); - gtk_widget_set_sensitive(element->PathButton,0); + g_object_set_data(G_OBJECT(element->TypeCombo),"source_element",element); + gtk_widget_hide(element->PathButton); + int size; config_str parts = yon_config_load(get_parts_and_devices_command, &size); for (int i=0;iAddBox),element->MainBox,0,0,0); + g_object_set_data(G_OBJECT(element->MainBox),"window",window); + + if (yon_char_is_empty(key)) return; + if (yon_char_check_begins_with(key,"/dev/")){ gtk_combo_box_set_active_id(GTK_COMBO_BOX(element->DeviceCombo),key); gtk_combo_box_set_active(GTK_COMBO_BOX(element->TypeCombo),0); @@ -69,61 +93,27 @@ void yon_source_element_add(char *key,void*,source_window *window){ gtk_entry_set_text(GTK_ENTRY(element->PathEntry),key); gtk_combo_box_set_active(GTK_COMBO_BOX(element->TypeCombo),1); } - gtk_box_pack_start(GTK_BOX(window->AddBox),element->MainBox,0,0,0); - g_object_set_data(G_OBJECT(element->MainBox),"window",window); - g_object_set_data(G_OBJECT(element->PathButton),"target",window->PathEntry); -} - -void yon_source_update(source_window *window){ - GList *list = gtk_container_get_children(GTK_CONTAINER(window->AddBox)); - GList *iter; - for (iter=list;iter;iter=iter->next){ - gtk_widget_destroy(GTK_WIDGET(iter->data)); - } - dictionary *dict; - if (!window->sources) return; - for_dictionaries(dict,window->sources){ - yon_source_element_add(dict->key,NULL,window); - - } } void on_source_add(GtkWidget *,source_window *window){ - const char *path = gtk_widget_get_visible(window->PathEntry)?gtk_entry_get_text(GTK_ENTRY(window->PathEntry)):gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(window->DeviceCombo)); - if (yon_char_is_empty(path)){ - yon_ubl_status_box_spawn(GTK_CONTAINER(window->StatusBox),_EMPTY_IMPORTANT_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE); - yon_ubl_status_highlight_incorrect(gtk_widget_get_visible(window->PathEntry)?window->PathEntry:window->DeviceCombo); - return; - } - if (!yon_dictionary_get(&window->sources,(char*)path)){ - yon_dictionary_add_or_create_if_exists_with_data(window->sources,yon_char_new(path),NULL); - gtk_entry_set_text(GTK_ENTRY(window->PathEntry),""); - gtk_combo_box_set_active(GTK_COMBO_BOX(window->DeviceCombo),0); - yon_source_update(window); - } else { - yon_ubl_status_box_spawn(GTK_CONTAINER(window->StatusBox),VALUE_REPEAT_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE); - } + yon_source_element_add(NULL,NULL,window); + yon_source_update(window); } void on_source_remove(GtkWidget *,source_element *element){ source_window *window = g_object_get_data(G_OBJECT(element->MainBox),"window"); - const char *path = gtk_widget_get_visible(element->PathEntry)?gtk_entry_get_text(GTK_ENTRY(element->PathEntry)):gtk_combo_box_get_active_id(GTK_COMBO_BOX(element->DeviceCombo)); - dictionary *dict = yon_dictionary_get(&window->sources,(char*)path); - if (dict){ - window->sources = yon_dictionary_rip(dict); - yon_source_update(window); - } + gtk_widget_destroy(element->MainBox); + yon_source_update(window); } void on_source_choose(GtkWidget *self){ - GtkWidget *target_entry = g_object_get_data(G_OBJECT(self),"target"); - GtkWidget *target_mode = g_object_get_data(G_OBJECT(self),"combo"); - switch (gtk_combo_box_get_active(GTK_COMBO_BOX(target_mode))){ + source_element *element = g_object_get_data(G_OBJECT(self),"source_element"); + switch (gtk_combo_box_get_active(GTK_COMBO_BOX(element->TypeCombo))){ case 1:{ filechooser_window *dialog = yon_file_chooser_window_new(GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER); - yon_gtk_window_setup(GTK_WINDOW(dialog->Window),GTK_WINDOW(dialog->Window),OPEN_LABEL,icon_path,"filechooser_window"); + yon_gtk_window_setup(GTK_WINDOW(dialog->Window),GTK_WINDOW(dialog->Window),OPEN_LABEL,icon_path,"filechooser_window"); if (yon_file_chooser_start(dialog)==GTK_RESPONSE_ACCEPT){ - gtk_entry_set_text(GTK_ENTRY(target_entry),dialog->last_success_selection); + gtk_entry_set_text(GTK_ENTRY(element->PathEntry),dialog->last_success_selection); free(dialog); } @@ -137,7 +127,7 @@ void on_source_choose(GtkWidget *self){ gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog->MainFileChooser),filter); if (yon_file_chooser_start(dialog)==GTK_RESPONSE_ACCEPT){ - gtk_entry_set_text(GTK_ENTRY(target_entry),dialog->last_success_selection); + gtk_entry_set_text(GTK_ENTRY(element->PathEntry),dialog->last_success_selection); free(dialog); } @@ -151,10 +141,6 @@ void on_source_accept(GtkWidget *,source_window *window){ on_subwindow_close(window->Window); return; } - const char *creation_path = gtk_widget_get_visible(window->PathEntry)? gtk_entry_get_text(GTK_ENTRY(window->PathEntry)):NULL; - if (!yon_char_is_empty(creation_path)){ - yon_ubl_status_box_spawn(GTK_CONTAINER(window->StatusBox),SOURCE_CREATE_ONGOING_ERROR_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE); - } char *sources_list = NULL; GList *list = gtk_container_get_children(GTK_CONTAINER(window->AddBox)); GList *iter; @@ -207,26 +193,6 @@ void on_source_accept(GtkWidget *,source_window *window){ } else { yon_config_remove_by_key(source_parameter); } - int size; - config_str paths = NULL; - dictionary *dict; - if (window->sources){ - for_dictionaries(dict,window->sources){ - if (yon_char_parsed_check_exist(paths,size,dict->key)>-1){ - yon_ubl_status_box_spawn(GTK_CONTAINER(window->StatusBox),VALUE_REPEAT_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE); - return; - } - yon_char_parsed_add_or_create_if_exists(paths,&size,dict->key); - } - if (!size){ - yon_ubl_status_box_spawn(GTK_CONTAINER(window->StatusBox),_EMPTY_IMPORTANT_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE); - yon_ubl_status_highlight_incorrect(window->PathEntry); - return; - } - } - char *parameter_string = yon_char_parsed_to_string(paths,(int)size,","); - if (!yon_char_is_empty(parameter_string)) free(parameter_string); - if (!main_config.configure_mode){ int size; config_str parameters = yon_config_get_save_parameters_by_key(&size,locale_parameter,lang_parameter,zone_parameter,NULL); @@ -238,7 +204,6 @@ void on_source_accept(GtkWidget *,source_window *window){ yon_char_parsed_free(parameters,size); } } - yon_dictionary_free_all(window->sources,NULL); on_subwindow_close(window->Window); free(window); } @@ -252,54 +217,27 @@ source_window *yon_source_window_new(){ window->CancelButton = yon_gtk_builder_get_widget(builder,"CancelButton"); window->AcceptButton = yon_gtk_builder_get_widget(builder,"AcceptButton"); window->AutoSwitch = yon_gtk_builder_get_widget(builder,"AutoSwitch"); - window->TypeCombo = yon_gtk_builder_get_widget(builder,"TypeCombo"); - window->PathEntry = yon_gtk_builder_get_widget(builder,"PathEntry"); - window->DeviceCombo = yon_gtk_builder_get_widget(builder,"DeviceCombo"); - window->PathButton = yon_gtk_builder_get_widget(builder,"PathButton"); - window->AddButton = yon_gtk_builder_get_widget(builder,"AddButton"); window->AddBox = yon_gtk_builder_get_widget(builder,"AddBox"); - window->sources = NULL; g_signal_connect(G_OBJECT(window->CancelButton),"clicked",G_CALLBACK(on_subwindow_close),NULL); g_signal_connect(G_OBJECT(window->AcceptButton),"clicked",G_CALLBACK(on_source_accept),window); - g_signal_connect(G_OBJECT(window->AddButton),"clicked",G_CALLBACK(on_source_add),window); - g_signal_connect(G_OBJECT(window->PathButton),"clicked",G_CALLBACK(on_source_choose),window); - g_signal_connect(G_OBJECT(window->TypeCombo),"changed",G_CALLBACK(on_source_changed),window); g_signal_connect(G_OBJECT(window->AutoSwitch),"state-set",G_CALLBACK(yon_gtk_widget_set_sensitive_from_switch_inversed),gtk_widget_get_parent(gtk_widget_get_parent(window->AddBox))); - g_signal_connect(G_OBJECT(window->AutoSwitch),"state-set",G_CALLBACK(yon_gtk_widget_set_sensitive_from_switch_inversed),window->TypeCombo); - g_signal_connect(G_OBJECT(window->AutoSwitch),"state-set",G_CALLBACK(yon_gtk_widget_set_sensitive_from_switch_inversed),window->DeviceCombo); - g_signal_connect(G_OBJECT(window->AutoSwitch),"state-set",G_CALLBACK(yon_gtk_widget_set_sensitive_from_switch_inversed),window->PathButton); - g_signal_connect(G_OBJECT(window->AutoSwitch),"state-set",G_CALLBACK(yon_gtk_widget_set_sensitive_from_switch_inversed),window->PathEntry); - g_signal_connect(G_OBJECT(window->AutoSwitch),"state-set",G_CALLBACK(yon_gtk_widget_set_sensitive_from_switch_inversed),window->AddButton); - g_object_set_data(G_OBJECT(window->PathButton),"combo",window->TypeCombo); - g_object_set_data(G_OBJECT(window->PathButton),"target",window->PathEntry); - g_object_set_data(G_OBJECT(window->TypeCombo),"target",window->DeviceCombo); - g_object_set_data(G_OBJECT(window->TypeCombo),"button",window->PathButton); - g_object_set_data(G_OBJECT(window->TypeCombo),"combo",window->PathEntry); + { char *config_parameter = config(source_parameter); - if (window->sources){ - yon_dictionary_free_all(window->sources,NULL); - } - int size; - config_str parsed = yon_char_parse(config_parameter,&size,","); - for (int i=0;isources,parsed[i],NULL); - } - yon_char_parsed_free(parsed,size); - } - int size; - config_str parts = yon_config_load(get_parts_and_devices_command, &size); - for (int i=0;iDeviceCombo),parsed[1],parsed[1]); + if (!yon_char_is_empty(config_parameter)){ + gtk_switch_set_active(GTK_SWITCH(window->AutoSwitch),0); + int size; + config_str parsed = yon_char_parse(config_parameter,&size,","); + for (int i=0;iDeviceCombo),0); - yon_char_parsed_free(parts,size); return window; } diff --git a/source/ubinstall-gtk.h b/source/ubinstall-gtk.h index 8f05d2e..f8f53fa 100755 --- a/source/ubinstall-gtk.h +++ b/source/ubinstall-gtk.h @@ -1027,13 +1027,7 @@ typedef struct GtkWidget *CancelButton; GtkWidget *AcceptButton; GtkWidget *AutoSwitch; - GtkWidget *TypeCombo; - GtkWidget *PathEntry; - GtkWidget *DeviceCombo; - GtkWidget *PathButton; - GtkWidget *AddButton; GtkWidget *AddBox; - dictionary *sources; } source_window; typedef struct @@ -1044,6 +1038,7 @@ typedef struct GtkWidget *DeviceCombo; GtkWidget *PathButton; GtkWidget *RemoveButton; + GtkWidget *AddButton; } source_element; @@ -1337,7 +1332,6 @@ void on_source_accept(GtkWidget *, source_window *window); void on_source_choose(GtkWidget *self); void on_source_remove(GtkWidget *, source_element *element); void on_source_add(GtkWidget *, source_window *window); -void yon_source_update(source_window *window); void yon_source_element_add(char *key, void *, source_window *window); source_element *yon_source_element_new(); void on_rdp_toggled(GtkWidget *self, main_window *); @@ -1455,4 +1449,5 @@ void on_menu_chosen(GtkWidget *, GtkListBoxRow* row, yon_menu_window *window); gboolean yon_locale_window_load(language_window *window); void yon_os_password_open(GtkWidget *, main_window *widgets); void yon_userdata_password_open(GtkWidget *, main_window *widgets); -double yon_password_check_func(yon_password_window *window, const char *password_string); \ No newline at end of file +double yon_password_check_func(yon_password_window *window, const char *password_string); +void yon_source_update(source_window *window); \ No newline at end of file diff --git a/ubinstall-gtk-source.glade b/ubinstall-gtk-source.glade index 8c1482d..192097f 100644 --- a/ubinstall-gtk-source.glade +++ b/ubinstall-gtk-source.glade @@ -3,16 +3,6 @@ - - True - False - com.ublinux.libublsettingsui-gtk3.zoom-symbolic - - - True - False - com.ublinux.libublsettingsui-gtk3.increase-symbolic - 400 250 @@ -139,94 +129,6 @@ 0 - - - True - False - 5 - - - True - False - False - 0 - - Device - Folder - ISO-image - - - - False - True - 0 - - - - - False - True - - - True - True - 1 - - - - - True - False - False - 0 - - - True - True - 2 - - - - - False - True - True - image1 - - - - False - True - 3 - - - - - True - False - True - True - image2 - - - - False - True - 4 - - - - - False - True - end - 1 - - True @@ -265,7 +167,7 @@ - False + True True 2 diff --git a/ubinstall-gtk.css b/ubinstall-gtk.css index 97b25fb..ca4778b 100644 --- a/ubinstall-gtk.css +++ b/ubinstall-gtk.css @@ -5,6 +5,9 @@ .noborder { border:none; } +.instant { + transition: 0; +} .borders *{ border-width:0.5px; border-style: solid;