You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
268 lines
12 KiB
268 lines
12 KiB
#include "libublsettingsui-gtk3.h"
|
|
|
|
void on_confuguration_combo_box_changed(GtkComboBox *self, char *id);
|
|
void __yon_on_boolean_parameter_toggled(GtkToggleButton *self ,char *id);
|
|
|
|
typedef struct {
|
|
char *id;
|
|
GtkWidget *Box;
|
|
GtkWidget *CheckButton;
|
|
} yon_configuration_boolean_parameter;
|
|
|
|
typedef struct {
|
|
char *id;
|
|
GtkWidget *Box;
|
|
GtkWidget *Label;
|
|
GtkWidget *Entry;
|
|
} yon_configuration_entry_parameter;
|
|
|
|
typedef struct {
|
|
char *id;
|
|
GtkWidget *Box;
|
|
GtkWidget *Label;
|
|
GtkWidget *ComboBox;
|
|
} yon_configuration_combo_parameter;
|
|
|
|
// typedef struct {
|
|
// char *id;
|
|
// GtkWidget *Label;
|
|
// GtkWidget *GtkTreeView;
|
|
// GtkListStore *list;
|
|
// } yon_configuration_list_parameter;
|
|
|
|
|
|
|
|
typedef struct yon_configuration_parameters {
|
|
dictionary_fields(yon_configuration_parameters);
|
|
char *label;
|
|
char *value;
|
|
GCallback func;
|
|
enum CONFIGURATION_PARAMETER_TYPE type;
|
|
} yon_configuration_parameters;
|
|
|
|
yon_configuration_entry_parameter *yon_configuration_entry_parameter_new(char *id, char *label_text){
|
|
yon_configuration_entry_parameter *parameter = malloc(sizeof(yon_configuration_entry_parameter));
|
|
parameter->Box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,5);
|
|
parameter->Label = gtk_label_new(label_text);
|
|
parameter->Entry = gtk_entry_new();
|
|
parameter->id = yon_char_new(id);
|
|
gtk_box_pack_start(GTK_BOX(parameter->Box),parameter->Label,1,1,0);
|
|
gtk_box_pack_start(GTK_BOX(parameter->Box),parameter->Entry,1,1,0);
|
|
gtk_widget_show_all(parameter->Box);
|
|
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 *parameter = malloc(sizeof(yon_configuration_combo_parameter));
|
|
parameter->Box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,5);
|
|
parameter->Label = gtk_label_new(label_text);
|
|
parameter->ComboBox = gtk_combo_box_text_new();
|
|
parameter->id = yon_char_new(id);
|
|
gtk_box_pack_start(GTK_BOX(parameter->Box),parameter->Label,0,0,0);
|
|
gtk_box_pack_start(GTK_BOX(parameter->Box),parameter->ComboBox,0,0,0);
|
|
for (int i=0;parameters[i]&¶meters[i+1];i+=2){
|
|
gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(parameter->ComboBox),parameters[i],parameters[i+1]);
|
|
}
|
|
char *value = NULL;
|
|
yon_window_config_get_parameter("settings",id,&value,YON_TYPE_STRING);
|
|
if (!yon_char_is_empty(value)){
|
|
gtk_combo_box_set_active_id(GTK_COMBO_BOX(parameter->ComboBox),value);
|
|
} else {
|
|
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);
|
|
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);
|
|
return parameter;
|
|
}
|
|
|
|
ubl_settings_window *yon_ubl_settings_window_new(){
|
|
ubl_settings_window *window = malloc(sizeof(ubl_settings_window));
|
|
GtkBuilder *builder = gtk_builder_new_from_resource("/com/ublinux/ui/libublsettingsui-gtk3-config-window.glade");
|
|
window->window = yon_gtk_builder_get_widget(builder,"Window");
|
|
window->WorkZoneBox = yon_gtk_builder_get_widget(builder,"WorkZoneBox");
|
|
window->AcceptButton = yon_gtk_builder_get_widget(builder,"AcceptButton");
|
|
window->CancelButton = yon_gtk_builder_get_widget(builder,"CancelButton");
|
|
gtk_window_set_title(GTK_WINDOW(window->window),template_app_information.app_title);
|
|
gtk_window_set_icon_name(GTK_WINDOW(window->window),yon_char_append("com.ublinux.",template_app_information.app_tech_name));
|
|
return window;
|
|
}
|
|
|
|
|
|
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));
|
|
parameter->Box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,5);
|
|
parameter->CheckButton = gtk_check_button_new_with_label(label_text);
|
|
parameter->id = yon_char_new(id);
|
|
|
|
g_signal_connect(G_OBJECT(parameter->CheckButton),"toggled",G_CALLBACK(__yon_on_boolean_parameter_toggled),parameter->id);
|
|
gtk_box_pack_start(GTK_BOX(parameter->Box),parameter->CheckButton,0,0,0);
|
|
return parameter;
|
|
}
|
|
|
|
//parameter section
|
|
|
|
yon_configuration_parameters *yon_configuration_parameter_new()
|
|
{
|
|
yon_configuration_parameters *dict = malloc(sizeof(yon_configuration_parameters));
|
|
dict->data = NULL;
|
|
dict->key = NULL;
|
|
dict->next = NULL;
|
|
dict->prev = NULL;
|
|
dict->data = NULL;
|
|
dict->value = NULL;
|
|
dict->func = NULL;
|
|
dict->first = (struct yon_configuration_parameters*)dict;
|
|
dict->data_type = DICTIONARY_OTHER_TYPE;
|
|
return dict;
|
|
}
|
|
|
|
yon_configuration_parameters *yon_configuration_parameter_append(yon_configuration_parameters *targetdict)
|
|
{
|
|
targetdict = (yon_configuration_parameters*)yon_dictionary_get_last((dictionary*)targetdict);
|
|
targetdict->next = (struct yon_configuration_parameters*)yon_configuration_parameter_new();
|
|
targetdict->next->prev = (struct yon_configuration_parameters*)targetdict;
|
|
targetdict->next->first = targetdict->first;
|
|
targetdict->next->data_type = DICTIONARY_OTHER_TYPE;
|
|
targetdict->next->data = NULL;
|
|
targetdict->next->value = NULL;
|
|
targetdict->next->func = NULL;
|
|
return targetdict->next;
|
|
}
|
|
|
|
yon_configuration_parameters *yon_configuration_parameter_new_with_label(char *key, void *data)
|
|
{
|
|
yon_configuration_parameters *dct = yon_configuration_parameter_new();
|
|
dct->key = yon_char_new(key);
|
|
dct->label = data;
|
|
dct->data_type = DICTIONARY_OTHER_TYPE;
|
|
return dct;
|
|
}
|
|
|
|
yon_configuration_parameters *yon_configuration_parameter_append_with_label(yon_configuration_parameters *dict, char *key, void *data)
|
|
{
|
|
yon_configuration_parameters *dct = yon_configuration_parameter_append(dict);
|
|
dct->key = yon_char_new(key);
|
|
dct->label = data;
|
|
dct->data_type = DICTIONARY_OTHER_TYPE;
|
|
return dct;
|
|
}
|
|
|
|
#define yon_configuration_parameter_add_or_create_if_exists_with_data(dict,key,data) {if (!dict) dict=yon_configuration_parameter_new_with_label(key,data); \
|
|
else dict=yon_configuration_parameter_append_with_label(dict,key,data);}
|
|
|
|
void yon_configuration_window_add_boolean_parameter(enum CONFIGURATION_PARAMETER_TYPE type, char *id, char *label){
|
|
yon_configuration_parameter_add_or_create_if_exists_with_data(__yon_settings_parameters,id,label);
|
|
yon_configuration_parameters *parameter = (yon_configuration_parameters*)yon_dictionary_get_last((dictionary*)__yon_settings_parameters);
|
|
if (parameter){
|
|
parameter->type = CONFIGURATION_PARAMETER_BOOL;
|
|
}
|
|
}
|
|
|
|
char *yon_settings_configuration_get(char *id){
|
|
char *return_val = NULL;
|
|
yon_window_config_get_parameter("settings",id,&return_val,YON_TYPE_STRING);
|
|
return return_val;
|
|
}
|
|
|
|
//signnals section
|
|
|
|
void __yon_on_boolean_parameter_toggled(GtkToggleButton *self ,char *id){
|
|
yon_configuration_parameters *current = (yon_configuration_parameters*)yon_dictionary_get((dictionary**)&__yon_settings_parameters,id);
|
|
if (current){
|
|
current->data= gtk_toggle_button_get_active(self)?(void*)1:(void*)0;
|
|
}
|
|
}
|
|
|
|
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);
|
|
if (cur){
|
|
char *cur_value = yon_char_new((char*)gtk_combo_box_get_active_id(self));
|
|
if (yon_window_config_check_init()){
|
|
yon_window_config_add_instant_parameter(id,"settings",cur_value,YON_TYPE_STRING);
|
|
}
|
|
}
|
|
}
|
|
|
|
void __yon_on_ubl_settings_window_open(){
|
|
if (!__yon_settings_parameters) return;
|
|
ubl_settings_window *window = yon_ubl_settings_window_new();
|
|
dictionary *current = NULL;
|
|
for_dictionaries(current,(dictionary*)__yon_settings_parameters){
|
|
switch(((yon_configuration_parameters*)current)->type){
|
|
case CONFIGURATION_PARAMETER_BOOL:{
|
|
yon_configuration_boolean_parameter *cur = __yon_configuration_boolean_parameter_new(((yon_configuration_parameters*)current)->key,((yon_configuration_parameters*)current)->label);
|
|
gtk_box_pack_start(GTK_BOX(window->WorkZoneBox),cur->Box,0,0,0);
|
|
gtk_widget_show_all(window->WorkZoneBox);
|
|
|
|
} break;
|
|
case CONFIGURATION_PARAMETER_ENTRY:{
|
|
// yon_configuration_entry_parameter *cur = __yon_configuration_entry_parameter_new(current->key,current->label);
|
|
// gtk_box_pack_start(GTK_BOX(window->WorkZoneBox),cur->Box,0,0,0);
|
|
|
|
} break;
|
|
case CONFIGURATION_PARAMETER_COMBO_BOX:{
|
|
yon_configuration_combo_parameter *cur = yon_configuration_combo_box_parameter_new(((yon_configuration_parameters*)current)->key,((yon_configuration_parameters*)current)->label,(config_str)((yon_configuration_parameters*)current)->data);
|
|
gtk_box_pack_start(GTK_BOX(window->WorkZoneBox),cur->Box,0,0,0);
|
|
gtk_widget_show_all(window->WorkZoneBox);
|
|
} break;
|
|
case CONFIGURATION_PARAMETER_LIST_MULTIPLE:{
|
|
} break;
|
|
}
|
|
}
|
|
gtk_widget_show(window->window);
|
|
}
|
|
|
|
//init section
|
|
|
|
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);
|
|
va_list args;
|
|
va_start(args,data);
|
|
char *cur=NULL;
|
|
int size=0;
|
|
config_str variants = NULL;
|
|
while ((cur=va_arg(args,char*))){
|
|
yon_char_parsed_add_or_create_if_exists(variants,&size,cur);
|
|
}
|
|
{
|
|
char *target=NULL;
|
|
yon_window_config_get_parameter("settings",id,&target,YON_TYPE_STRING);
|
|
if (yon_char_is_empty(target)){
|
|
yon_window_config_add_instant_parameter(id,"settings",variants[0],YON_TYPE_STRING);
|
|
}
|
|
}
|
|
yon_char_parsed_add_or_create_if_exists(variants,&size,NULL);
|
|
yon_configuration_parameters *parameter = (yon_configuration_parameters*)yon_dictionary_get_last((dictionary*)__yon_settings_parameters);
|
|
if (parameter){
|
|
|
|
parameter->data = (void*)variants;
|
|
parameter->type = CONFIGURATION_PARAMETER_COMBO_BOX;
|
|
parameter->func = func;
|
|
parameter->value = data;
|
|
}
|
|
|
|
}
|
|
|
|
void yon_ubl_settings_window_init(GtkMenu *menu){
|
|
GtkWidget *menu_item = gtk_menu_item_new();
|
|
GtkWidget *box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,0);
|
|
textdomain(template_ui_LocaleName);
|
|
GtkWidget *label = gtk_label_new(CONFIG_WINDOW_MENU_LABEL);
|
|
textdomain(template_app_information.app_locale);
|
|
gtk_style_context_add_class(gtk_widget_get_style_context(menu_item),"menuitemtop");
|
|
GtkWidget *image = gtk_image_new_from_icon_name("com.ublinux.libublsettingsui-gtk3.settings-symbolic",GTK_ICON_SIZE_BUTTON);
|
|
gtk_menu_shell_prepend(GTK_MENU_SHELL(menu),menu_item);
|
|
gtk_container_add(GTK_CONTAINER(menu_item),box);
|
|
gtk_box_pack_start(GTK_BOX(box),image,0,0,5);
|
|
gtk_box_pack_start(GTK_BOX(box),label,0,0,5);
|
|
gtk_widget_show_all(menu_item);
|
|
g_signal_connect(G_OBJECT(menu_item),"activate",G_CALLBACK(__yon_on_ubl_settings_window_open),NULL);
|
|
} |