From 9675d2877559ef6df0ce4c6a4d1fba70f0e5c0b8 Mon Sep 17 00:00:00 2001 From: Ivan Yarcev Date: Mon, 16 Dec 2024 16:45:28 +0600 Subject: [PATCH] Fixed editing for repos and mirrors --- source/ubl-settings-update.c | 71 ++++++++++++++--------- source/ubl-settings-update.h | 8 +-- ubl-settings-update-mirror-path-add.glade | 1 + ubl-settings-update.glade | 15 ----- 4 files changed, 49 insertions(+), 46 deletions(-) diff --git a/source/ubl-settings-update.c b/source/ubl-settings-update.c index 2b341cd..c14bef6 100644 --- a/source/ubl-settings-update.c +++ b/source/ubl-settings-update.c @@ -738,19 +738,31 @@ void on_repo_edit(GtkWidget *,main_window *widgets){ int cur_size; config_str repos = yon_char_parse(parsed[0],&cur_size,","); for (int i=0;iStatusBox),EMPTY_IMPORTANT_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE); - yon_ubl_status_highlight_incorrect(window->RepoSourceEntry); - return; - } - gtk_entry_set_text(GTK_ENTRY(window->RepoSourceEntry),""); - GtkBuilder *builder = gtk_builder_new_from_resource(glade_mirror_path_add_path); - gtk_box_pack_start(GTK_BOX(window->SourceBox),yon_gtk_builder_get_widget(builder,"PathRemovalBox"),0,0,2); - gtk_entry_set_text(GTK_ENTRY(gtk_builder_get_object(builder,"PathEntry")),target); - g_signal_connect(gtk_builder_get_object(builder,"PathEditButton"),"clicked",G_CALLBACK(on_mirror_path_edit),gtk_builder_get_object(builder,"PathRemovalBox")); - g_signal_connect(gtk_builder_get_object(builder,"PathRemoveButton"),"clicked",G_CALLBACK(on_mirror_path_removed),gtk_builder_get_object(builder,"PathRemovalBox")); + 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; + + if (strstr(repos[i],"@")){ + char *type = yon_char_divide_search(repos[i],"@",-1); + gtk_combo_box_set_active_id(GTK_COMBO_BOX(section->TypeCombo),type); + free(type); + + } 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),repos[i]); + gtk_box_pack_start(GTK_BOX(window->SourceBox),section->PathRemovalBox,0,0,2); + 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); } + yon_char_parsed_free(repos,cur_size); } if (size>1&&!yon_char_is_empty(parsed[1])){ //siglevel int cur_size; @@ -908,18 +920,25 @@ void on_mirror_edit(GtkWidget *,main_window *widgets){ config_str parsed = yon_char_parse(parameter,&size,","); for (int i=0;iStatusBox),EMPTY_IMPORTANT_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE); - yon_ubl_status_highlight_incorrect(window->TypeEntry); - return; - } - gtk_entry_set_text(GTK_ENTRY(window->TypeEntry),""); GtkBuilder *builder = gtk_builder_new_from_resource(glade_mirror_path_add_path); - gtk_box_pack_start(GTK_BOX(window->PathBox),yon_gtk_builder_get_widget(builder,"PathRemovalBox"),0,0,2); - gtk_entry_set_text(GTK_ENTRY(gtk_builder_get_object(builder,"PathEntry")),target); - g_signal_connect(gtk_builder_get_object(builder,"PathEditButton"),"clicked",G_CALLBACK(on_mirror_path_edit),gtk_builder_get_object(builder,"PathRemovalBox")); - g_signal_connect(gtk_builder_get_object(builder,"PathRemoveButton"),"clicked",G_CALLBACK(on_mirror_path_removed),gtk_builder_get_object(builder,"PathRemovalBox")); - g_object_unref(G_OBJECT(builder)); + + 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 *type = yon_char_divide_search(parsed[i],"@",-1); + gtk_combo_box_set_active_id(GTK_COMBO_BOX(section->TypeCombo),type); + yon_dictionary_add_or_create_if_exists_with_data(window->sections,(char*)target,section); + + gtk_entry_set_text(GTK_ENTRY(section->PathEntry),parsed[i]); + gtk_box_pack_start(GTK_BOX(window->PathBox),section->PathRemovalBox,0,0,2); + + 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->Window); @@ -998,8 +1017,8 @@ void on_repo_accept_clicked(GtkWidget *, dictionary *dict){ char *sources = ""; dictionary *dact = NULL; for_dictionaries (dact, window->sections){ - - char *cur = yon_char_unite(gtk_combo_box_get_active_id(GTK_COMBO_BOX(((path_section*)dact->data)->TypeCombo)),"@",(char*)gtk_entry_get_text(GTK_ENTRY(((path_section*)dact->data)->PathEntry)),NULL); + char *type = (char*)gtk_combo_box_get_active_id(GTK_COMBO_BOX(((path_section*)dact->data)->TypeCombo)); + char *cur = yon_char_unite(type?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; @@ -1295,14 +1314,12 @@ void on_mirror_path_edit(GtkWidget *self,mirror_add_window *window){ gtk_editable_set_editable(GTK_EDITABLE(((path_section*)dict->data)->PathEntry),0); gtk_widget_set_sensitive(((path_section*)dict->data)->TypeCombo,0); GtkWidget *image = gtk_button_get_image(GTK_BUTTON(((path_section*)dict->data)->PathEditButton)); - gtk_entry_set_has_frame(GTK_ENTRY(((path_section*)dict->data)->PathEntry),0); gtk_image_set_from_icon_name(GTK_IMAGE(image),edit_icon_name,GTK_ICON_SIZE_BUTTON); } else { ((path_section*)dict->data)->edits=0; gtk_widget_set_sensitive(((path_section*)dict->data)->TypeCombo,1); gtk_editable_set_editable(GTK_EDITABLE(((path_section*)dict->data)->PathEntry),1); GtkWidget *image = gtk_button_get_image(GTK_BUTTON(((path_section*)dict->data)->PathEditButton)); - gtk_entry_set_has_frame(GTK_ENTRY(((path_section*)dict->data)->PathEntry),1); gtk_image_set_from_icon_name(GTK_IMAGE(image),accept_icon_name,GTK_ICON_SIZE_BUTTON); } } diff --git a/source/ubl-settings-update.h b/source/ubl-settings-update.h index 3fa2caf..ee5cc72 100644 --- a/source/ubl-settings-update.h +++ b/source/ubl-settings-update.h @@ -146,6 +146,8 @@ typedef struct { typedef struct { dictionary *sections; + GtkWidget *RepoSourceCombo; + GtkWidget *RepoSourceEntry; GtkWidget *Window; GtkWidget *HeadLabel; GtkWidget *StatusBox; @@ -158,8 +160,6 @@ typedef struct { GtkWidget *RepoSignConditionCombo; GtkWidget *RepoSignCheckCombo; GtkWidget *RepoSourceButton; - GtkWidget *RepoSourceEntry; - GtkWidget *RepoSourceCombo; GtkWidget *SourceBox; GtkWidget *RepoSourceAddButton; GtkWidget *RepoNameEntry; @@ -214,6 +214,8 @@ typedef struct { typedef struct { dictionary *sections; + GtkWidget *TypeCombo; + GtkWidget *TypeEntry; GtkWidget *Window; GtkWidget *HeadLabel; GtkWidget *StatusBox; @@ -221,8 +223,6 @@ typedef struct { GtkWidget *AcceptButton; GtkWidget *CancelButton; GtkWidget *NameEntry; - GtkWidget *TypeCombo; - GtkWidget *TypeEntry; GtkWidget *TypeButton; GtkWidget *PathBox; diff --git a/ubl-settings-update-mirror-path-add.glade b/ubl-settings-update-mirror-path-add.glade index 5bc6933..167bd1a 100644 --- a/ubl-settings-update-mirror-path-add.glade +++ b/ubl-settings-update-mirror-path-add.glade @@ -41,6 +41,7 @@ True + False False WEB link diff --git a/ubl-settings-update.glade b/ubl-settings-update.glade index 2a59e9b..476d005 100644 --- a/ubl-settings-update.glade +++ b/ubl-settings-update.glade @@ -1552,21 +1552,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - - True - fixed - Type - - - end - - - 1 - - - - Resource URL