Fixes; Added custom callback function to settings window comboboxes

pull/38/head
parent 455dac66e3
commit 2617110609

@ -7,7 +7,6 @@
<property name="width-request">450</property> <property name="width-request">450</property>
<property name="height-request">200</property> <property name="height-request">200</property>
<property name="can-focus">False</property> <property name="can-focus">False</property>
<property name="modal">True</property>
<property name="icon-name">com.ublinux.libublsettingsui-gtk3</property> <property name="icon-name">com.ublinux.libublsettingsui-gtk3</property>
<property name="type-hint">dialog</property> <property name="type-hint">dialog</property>
<child> <child>

@ -36,6 +36,7 @@ typedef struct yon_configuration_parameters {
dictionary_fields(yon_configuration_parameters); dictionary_fields(yon_configuration_parameters);
char *label; char *label;
char *value; char *value;
GCallback func;
enum CONFIGURATION_PARAMETER_TYPE type; enum CONFIGURATION_PARAMETER_TYPE type;
} yon_configuration_parameters; } yon_configuration_parameters;
@ -51,6 +52,8 @@ yon_configuration_entry_parameter *yon_configuration_entry_parameter_new(char *i
return parameter; return parameter;
} }
yon_configuration_parameters *__yon_settings_parameters = NULL;
yon_configuration_combo_parameter *yon_configuration_combo_box_parameter_new(char *id, char *label_text, config_str parameters){ yon_configuration_combo_parameter *yon_configuration_combo_box_parameter_new(char *id, char *label_text, config_str parameters){
yon_configuration_combo_parameter *parameter = malloc(sizeof(yon_configuration_combo_parameter)); yon_configuration_combo_parameter *parameter = malloc(sizeof(yon_configuration_combo_parameter));
parameter->Box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,5); parameter->Box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,5);
@ -70,6 +73,12 @@ yon_configuration_combo_parameter *yon_configuration_combo_box_parameter_new(cha
gtk_combo_box_set_active(GTK_COMBO_BOX(parameter->ComboBox),0); gtk_combo_box_set_active(GTK_COMBO_BOX(parameter->ComboBox),0);
} }
g_signal_connect(G_OBJECT(parameter->ComboBox),"changed",G_CALLBACK(on_confuguration_combo_box_changed),id); g_signal_connect(G_OBJECT(parameter->ComboBox),"changed",G_CALLBACK(on_confuguration_combo_box_changed),id);
yon_configuration_parameters *target = (yon_configuration_parameters*)yon_dictionary_get((dictionary**)&__yon_settings_parameters,id);
if (target){
if (target->func){
g_signal_connect(G_OBJECT(parameter->ComboBox),"changed",G_CALLBACK(target->func),target->value);
}
}
gtk_widget_show_all(parameter->Box); gtk_widget_show_all(parameter->Box);
return parameter; return parameter;
} }
@ -84,8 +93,6 @@ ubl_settings_window *yon_ubl_settings_window_new(){
return window; return window;
} }
yon_configuration_parameters *__yon_settings_parameters = NULL;
yon_configuration_boolean_parameter *__yon_configuration_boolean_parameter_new(char *id, char *label_text){ yon_configuration_boolean_parameter *__yon_configuration_boolean_parameter_new(char *id, char *label_text){
yon_configuration_boolean_parameter *parameter = malloc(sizeof(yon_configuration_boolean_parameter)); yon_configuration_boolean_parameter *parameter = malloc(sizeof(yon_configuration_boolean_parameter));
@ -109,6 +116,7 @@ yon_configuration_parameters *yon_configuration_parameter_new()
dict->prev = NULL; dict->prev = NULL;
dict->data = NULL; dict->data = NULL;
dict->value = NULL; dict->value = NULL;
dict->func = NULL;
dict->first = (struct yon_configuration_parameters*)dict; dict->first = (struct yon_configuration_parameters*)dict;
dict->data_type = DICTIONARY_OTHER_TYPE; dict->data_type = DICTIONARY_OTHER_TYPE;
return dict; return dict;
@ -123,6 +131,7 @@ yon_configuration_parameters *yon_configuration_parameter_append(yon_configurati
targetdict->next->data_type = DICTIONARY_OTHER_TYPE; targetdict->next->data_type = DICTIONARY_OTHER_TYPE;
targetdict->next->data = NULL; targetdict->next->data = NULL;
targetdict->next->value = NULL; targetdict->next->value = NULL;
targetdict->next->func = NULL;
return targetdict->next; return targetdict->next;
} }
@ -202,19 +211,19 @@ void __yon_on_boolean_parameter_toggled(GtkToggleButton *self ,char *id){
void on_confuguration_combo_box_changed(GtkComboBox *self, char *id){ void on_confuguration_combo_box_changed(GtkComboBox *self, char *id){
yon_configuration_parameters *cur = (yon_configuration_parameters*)yon_dictionary_get((dictionary**)&__yon_settings_parameters,id); yon_configuration_parameters *cur = (yon_configuration_parameters*)yon_dictionary_get((dictionary**)&__yon_settings_parameters,id);
if (cur){ if (cur){
cur->value = yon_char_new((char*)gtk_combo_box_get_active_id(self)); char *cur_value = yon_char_new((char*)gtk_combo_box_get_active_id(self));
if (yon_window_config_check_init()){ if (yon_window_config_check_init()){
yon_window_config_add_instant_parameter(id,"settings",cur->value,YON_TYPE_STRING); yon_window_config_add_instant_parameter(id,"settings",cur_value,YON_TYPE_STRING);
} }
} }
} }
//init section //init section
void yon_configuration_window_add_combo_box_parameter(enum CONFIGURATION_PARAMETER_TYPE type, char *id, char *label,...){ void yon_configuration_window_add_combo_box_parameter(enum CONFIGURATION_PARAMETER_TYPE type, char *id, char *label, GCallback func, gpointer data,...){
yon_configuration_parameter_add_or_create_if_exists_with_data(__yon_settings_parameters,id,label); yon_configuration_parameter_add_or_create_if_exists_with_data(__yon_settings_parameters,id,label);
va_list args; va_list args;
va_start(args,label); va_start(args,data);
char *cur=NULL; char *cur=NULL;
int size=0; int size=0;
config_str variants = NULL; config_str variants = NULL;
@ -234,6 +243,8 @@ void yon_configuration_window_add_combo_box_parameter(enum CONFIGURATION_PARAMET
parameter->data = (void*)variants; parameter->data = (void*)variants;
parameter->type = CONFIGURATION_PARAMETER_COMBO_BOX; parameter->type = CONFIGURATION_PARAMETER_COMBO_BOX;
parameter->func = func;
parameter->value = data;
} }
} }

@ -261,7 +261,7 @@ enum CONFIGURATION_PARAMETER_TYPE{
void yon_ubl_settings_window_init(GtkMenu *menu); void yon_ubl_settings_window_init(GtkMenu *menu);
void *yon_ubl_settings_window_get(char *id); void *yon_ubl_settings_window_get(char *id);
void yon_configuration_window_add_boolean_parameter(enum CONFIGURATION_PARAMETER_TYPE type, char *id, char *label); void yon_configuration_window_add_boolean_parameter(enum CONFIGURATION_PARAMETER_TYPE type, char *id, char *label);
void yon_configuration_window_add_combo_box_parameter(enum CONFIGURATION_PARAMETER_TYPE type, char *id, char *label,...); void yon_configuration_window_add_combo_box_parameter(enum CONFIGURATION_PARAMETER_TYPE type, char *id, char *label, GCallback func, gpointer data, ...);
typedef struct { typedef struct {
GtkWidget *window; GtkWidget *window;

Loading…
Cancel
Save