diff --git a/source/ubinstall-gtk.c b/source/ubinstall-gtk.c index 0594050..69f30ec 100644 --- a/source/ubinstall-gtk.c +++ b/source/ubinstall-gtk.c @@ -308,7 +308,16 @@ source_element *yon_source_element_new(){ void yon_source_element_add(char *key,void*,source_window *window){ source_element *element = yon_source_element_new(); - gtk_entry_set_text(GTK_ENTRY(element->PathEntry),key); + 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); + } else if (g_regex_match_simple(".*\\.iso",key,G_REGEX_DEFAULT,G_REGEX_MATCH_DEFAULT)){ + gtk_entry_set_text(GTK_ENTRY(element->PathEntry),key); + gtk_combo_box_set_active(GTK_COMBO_BOX(element->TypeCombo),2); + } else { + 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); @@ -320,22 +329,32 @@ void yon_source_update(source_window *window){ for (iter=list;iter;iter=iter->next){ gtk_widget_destroy(GTK_WIDGET(iter->data)); } - g_hash_table_foreach(window->sources,(GHFunc)yon_source_element_add,window); + 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 (!g_hash_table_contains(window->sources,path)){ - g_hash_table_add(window->sources,yon_char_new(path)); + 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); } } void on_source_remove(GtkWidget *,source_element *element){ source_window *window = g_object_get_data(G_OBJECT(element->MainBox),"window"); - const char *path = gtk_entry_get_text(GTK_ENTRY(window->PathEntry)); - if (g_hash_table_contains(window->sources,path)){ - g_hash_table_remove(window->sources,path); + 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); } } @@ -376,8 +395,21 @@ void on_source_accept(GtkWidget *,source_window *window){ on_subwindow_close(window->Window); return; } - guint size; - config_str paths = (config_str)g_hash_table_get_keys_as_array(window->sources,&size); + 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); + } + int size; + config_str paths = NULL; + dictionary *dict; + if (!window->sources) return; + 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); @@ -399,6 +431,8 @@ void on_source_accept(GtkWidget *,source_window *window){ yon_char_parsed_free(parameters,size); } } + yon_dictionary_free_all(window->sources,NULL); + free(window); } source_window *yon_source_window_new(){ @@ -416,14 +450,14 @@ source_window *yon_source_window_new(){ 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 = g_hash_table_new(g_str_hash,g_str_equal); + 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(window->AddBox)); + 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_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); @@ -446,7 +480,18 @@ source_window *yon_source_window_new(){ void on_source_clicked(GtkWidget *,main_window *widgets){ source_window *window = yon_source_window_new(); + char *sources = config(source_parameter); + if (!yon_char_is_empty(sources)&&strcmp(sources,"auto")){ + gtk_switch_set_active(GTK_SWITCH(window->AutoSwitch),0); + int size; + config_str parsed = yon_char_parse(sources,&size,","); + for (int i=0;isources,parsed[i],NULL); + } + yon_char_parsed_free(parsed,size); + } g_object_set_data(G_OBJECT(window->Window),"widgets",widgets); + yon_source_update(window); gtk_widget_show(window->Window); } diff --git a/source/ubinstall-gtk.h b/source/ubinstall-gtk.h index 0279f03..02e1875 100755 --- a/source/ubinstall-gtk.h +++ b/source/ubinstall-gtk.h @@ -927,9 +927,10 @@ typedef struct { GtkWidget *PathButton; GtkWidget *AddButton; GtkWidget *AddBox; - GHashTable *sources; + dictionary *sources; } source_window; + typedef struct { GtkWidget *MainBox; GtkWidget *TypeCombo; diff --git a/source/ubl-strings.h b/source/ubl-strings.h index 96d92f5..afc8c9e 100644 --- a/source/ubl-strings.h +++ b/source/ubl-strings.h @@ -223,6 +223,8 @@ NULL) #define COUNT_INVALID_LABEL(target) yon_char_unite(_("Cues"),target,NULL) #define ABOUT_TITLE_LABEL _("About UBLinux installation") +#define VALUE_REPEAT_LABEL _("Repeating values") +#define SOURCE_CREATE_ONGOING_ERROR_LABEL _("Source creation were not done") // #define _LABEL _("New section at") // #define _LABEL _("\"/ublinux-data/\" user data section") // #define _LABEL _("\"/ublinux/\" system section") diff --git a/ubinstall-gtk-source.glade b/ubinstall-gtk-source.glade index dfc5a72..1a3e61e 100644 --- a/ubinstall-gtk-source.glade +++ b/ubinstall-gtk-source.glade @@ -49,33 +49,20 @@ 5 15 15 - 15 - - - True - False - start - com.ublinux.ubinstall-gtk - 6 - - - False - True - 0 - - + vertical + 5 True False - vertical - 5 + 15 - + True False - Choose a path for configuration file - 0 + start + com.ublinux.ubinstall-gtk + 6 False @@ -87,12 +74,14 @@ True False + vertical 5 - + True - True - True + False + Choose a path for configuration file + 0 False @@ -101,10 +90,34 @@ - + True False - Automatically + 5 + + + True + True + True + + + False + True + 0 + + + + + True + False + Automatically + + + False + True + 1 + + False @@ -114,24 +127,42 @@ - False + True True 1 + + + False + True + 0 + + + + + True + True + never + in - + True - True - never + False - + True + False False + 5 + 5 + 5 + 5 + vertical + 5 True - False False vertical 5 @@ -214,6 +245,7 @@ False True + end 0 @@ -230,25 +262,25 @@ False True - 1 + 2 + + True + True + 0 + - - True - True - 2 - True True - 1 + 2