Source window changes

pull/113/head
parent 58755b9fda
commit 497e810bd9
No known key found for this signature in database
GPG Key ID: FF1D842BF4DDE92B

@ -308,7 +308,16 @@ source_element *yon_source_element_new(){
void yon_source_element_add(char *key,void*,source_window *window){ void yon_source_element_add(char *key,void*,source_window *window){
source_element *element = yon_source_element_new(); source_element *element = yon_source_element_new();
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_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); 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->MainBox),"window",window);
g_object_set_data(G_OBJECT(element->PathButton),"target",window->PathEntry); 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){ for (iter=list;iter;iter=iter->next){
gtk_widget_destroy(GTK_WIDGET(iter->data)); 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){ 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)); 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)){ if (!yon_dictionary_get(&window->sources,(char*)path)){
g_hash_table_add(window->sources,yon_char_new(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); 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){ void on_source_remove(GtkWidget *,source_element *element){
source_window *window = g_object_get_data(G_OBJECT(element->MainBox),"window"); source_window *window = g_object_get_data(G_OBJECT(element->MainBox),"window");
const char *path = gtk_entry_get_text(GTK_ENTRY(window->PathEntry)); 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));
if (g_hash_table_contains(window->sources,path)){ dictionary *dict = yon_dictionary_get(&window->sources,(char*)path);
g_hash_table_remove(window->sources,path); if (dict){
window->sources = yon_dictionary_rip(dict);
yon_source_update(window); yon_source_update(window);
} }
} }
@ -376,8 +395,21 @@ void on_source_accept(GtkWidget *,source_window *window){
on_subwindow_close(window->Window); on_subwindow_close(window->Window);
return; return;
} }
guint size; const char *creation_path = gtk_widget_get_visible(window->PathEntry)? gtk_entry_get_text(GTK_ENTRY(window->PathEntry)):NULL;
config_str paths = (config_str)g_hash_table_get_keys_as_array(window->sources,&size); 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){ if (!size){
yon_ubl_status_box_spawn(GTK_CONTAINER(window->StatusBox),EMPTY_IMPORTANT_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE); yon_ubl_status_box_spawn(GTK_CONTAINER(window->StatusBox),EMPTY_IMPORTANT_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE);
yon_ubl_status_highlight_incorrect(window->PathEntry); 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_char_parsed_free(parameters,size);
} }
} }
yon_dictionary_free_all(window->sources,NULL);
free(window);
} }
source_window *yon_source_window_new(){ 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->PathButton = yon_gtk_builder_get_widget(builder,"PathButton");
window->AddButton = yon_gtk_builder_get_widget(builder,"AddButton"); window->AddButton = yon_gtk_builder_get_widget(builder,"AddButton");
window->AddBox = yon_gtk_builder_get_widget(builder,"AddBox"); 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->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->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->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->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->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),"combo",window->TypeCombo);
g_object_set_data(G_OBJECT(window->PathButton),"target",window->PathEntry); 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),"target",window->DeviceCombo);
@ -446,7 +480,18 @@ source_window *yon_source_window_new(){
void on_source_clicked(GtkWidget *,main_window *widgets){ void on_source_clicked(GtkWidget *,main_window *widgets){
source_window *window = yon_source_window_new(); 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;i<size;i++){
yon_dictionary_add_or_create_if_exists_with_data(window->sources,parsed[i],NULL);
}
yon_char_parsed_free(parsed,size);
}
g_object_set_data(G_OBJECT(window->Window),"widgets",widgets); g_object_set_data(G_OBJECT(window->Window),"widgets",widgets);
yon_source_update(window);
gtk_widget_show(window->Window); gtk_widget_show(window->Window);
} }

@ -927,9 +927,10 @@ typedef struct {
GtkWidget *PathButton; GtkWidget *PathButton;
GtkWidget *AddButton; GtkWidget *AddButton;
GtkWidget *AddBox; GtkWidget *AddBox;
GHashTable *sources; dictionary *sources;
} source_window; } source_window;
typedef struct { typedef struct {
GtkWidget *MainBox; GtkWidget *MainBox;
GtkWidget *TypeCombo; GtkWidget *TypeCombo;

@ -223,6 +223,8 @@ NULL)
#define COUNT_INVALID_LABEL(target) yon_char_unite(_("Cues"),target,NULL) #define COUNT_INVALID_LABEL(target) yon_char_unite(_("Cues"),target,NULL)
#define ABOUT_TITLE_LABEL _("About UBLinux installation") #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 _("New section at")
// #define _LABEL _("\"/ublinux-data/\" user data section") // #define _LABEL _("\"/ublinux-data/\" user data section")
// #define _LABEL _("\"/ublinux/\" system section") // #define _LABEL _("\"/ublinux/\" system section")

@ -49,6 +49,12 @@
<property name="margin-end">5</property> <property name="margin-end">5</property>
<property name="margin-top">15</property> <property name="margin-top">15</property>
<property name="margin-bottom">15</property> <property name="margin-bottom">15</property>
<property name="orientation">vertical</property>
<property name="spacing">5</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="spacing">15</property> <property name="spacing">15</property>
<child> <child>
<object class="GtkImage"> <object class="GtkImage">
@ -119,11 +125,26 @@
<property name="position">1</property> <property name="position">1</property>
</packing> </packing>
</child> </child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child> <child>
<object class="GtkScrolledWindow"> <object class="GtkScrolledWindow">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">True</property> <property name="can-focus">True</property>
<property name="hscrollbar-policy">never</property> <property name="hscrollbar-policy">never</property>
<property name="shadow-type">in</property>
<child> <child>
<object class="GtkViewport"> <object class="GtkViewport">
<property name="visible">True</property> <property name="visible">True</property>
@ -133,6 +154,16 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="sensitive">False</property> <property name="sensitive">False</property>
<property name="can-focus">False</property> <property name="can-focus">False</property>
<property name="margin-start">5</property>
<property name="margin-end">5</property>
<property name="margin-top">5</property>
<property name="margin-bottom">5</property>
<property name="orientation">vertical</property>
<property name="spacing">5</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<property name="spacing">5</property> <property name="spacing">5</property>
<child> <child>
@ -214,6 +245,7 @@
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">True</property> <property name="fill">True</property>
<property name="pack-type">end</property>
<property name="position">0</property> <property name="position">0</property>
</packing> </packing>
</child> </child>
@ -230,25 +262,25 @@
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">True</property> <property name="fill">True</property>
<property name="position">1</property> <property name="position">2</property>
</packing> </packing>
</child> </child>
</object> </object>
</child>
</object>
</child>
</object>
<packing> <packing>
<property name="expand">True</property> <property name="expand">True</property>
<property name="fill">True</property> <property name="fill">True</property>
<property name="position">2</property> <property name="position">0</property>
</packing> </packing>
</child> </child>
</object> </object>
</child>
</object>
</child>
</object>
<packing> <packing>
<property name="expand">True</property> <property name="expand">True</property>
<property name="fill">True</property> <property name="fill">True</property>
<property name="position">1</property> <property name="position">2</property>
</packing> </packing>
</child> </child>
</object> </object>

Loading…
Cancel
Save