System for application settings WIP

pull/38/head
Ivan Dmitrievich Yartsev 10 months ago
parent 14b8c32f57
commit cbd3f42bc8

@ -6,6 +6,7 @@
<file>libublsettingsui-gtk3-documentation.glade</file> <file>libublsettingsui-gtk3-documentation.glade</file>
<file>libublsettingsui-gtk3-saving.glade</file> <file>libublsettingsui-gtk3-saving.glade</file>
<file>libublsettingsui-gtk3-debugger.glade</file> <file>libublsettingsui-gtk3-debugger.glade</file>
<file>libublsettingsui-gtk3-config-window.glade</file>
</gresource> </gresource>
<gresource prefix="/com/ublinux/css"> <gresource prefix="/com/ublinux/css">
<file>libublsettingsui-gtk3.css</file> <file>libublsettingsui-gtk3.css</file>

@ -0,0 +1,201 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2 -->
<interface domain="libublsettingsui-gtk3">
<requires lib="gtk+" version="3.24"/>
<!-- interface-css-provider-path libublsettingsui-gtk3.css -->
<object class="GtkImage" id="image1">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="icon-name">com.ublinux.libublsettingsui-gtk3.cancel-symbolic</property>
<style>
<class name="marginright"/>
</style>
</object>
<object class="GtkImage" id="image2">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="icon-name">com.ublinux.libublsettingsui-gtk3.accept-symbolic</property>
<style>
<class name="marginright"/>
</style>
</object>
<object class="GtkWindow" id="Window">
<property name="width-request">450</property>
<property name="height-request">200</property>
<property name="can-focus">False</property>
<property name="modal">True</property>
<property name="icon-name">com.ublinux.libublsettingsui-gtk3</property>
<property name="type-hint">dialog</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">5</property>
<child>
<object class="GtkBox" id="StatusBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-start">5</property>
<property name="margin-end">5</property>
<property name="margin-bottom">5</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="shadow-type">in</property>
<child>
<object class="GtkViewport">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkBox" id="WorkZoneBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">5</property>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
</child>
</object>
</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">True</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
</child>
<child type="titlebar">
<object class="GtkHeaderBar">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child type="title">
<object class="GtkLabel" id="HeaderTopic">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Configuration settings</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
</child>
<child>
<object class="GtkImage" id="HeaderImage">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="pixel-size">32</property>
<property name="icon-name">com.ublinux.libublsettingsui-gtk3</property>
</object>
</child>
<child>
<object class="GtkButton" id="CancelButton">
<property name="label" translatable="yes">Cancel</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="image">image1</property>
<style>
<class name="marginright"/>
</style>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="AcceptButton">
<property name="label" translatable="yes">Apply</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="image">image2</property>
<style>
<class name="marginright"/>
</style>
</object>
<packing>
<property name="pack-type">end</property>
<property name="position">2</property>
</packing>
</child>
<style>
<class name="toolbar"/>
</style>
</object>
</child>
</object>
<object class="GtkListStore" id="liststore1">
<columns>
<!-- column-name Active -->
<column type="gboolean"/>
<!-- column-name Parameter -->
<column type="gchararray"/>
<!-- column-name OldValue -->
<column type="gchararray"/>
<!-- column-name NewValue -->
<column type="gchararray"/>
<!-- column-name CompareString -->
<column type="gchararray"/>
<!-- column-name Color -->
<column type="gchararray"/>
<!-- column-name Show -->
<column type="gboolean"/>
<!-- column-name Section -->
<column type="gchararray"/>
</columns>
</object>
<object class="GtkListStore" id="liststore1fwe">
<columns>
<!-- column-name Active -->
<column type="gboolean"/>
<!-- column-name Parameter -->
<column type="gchararray"/>
<!-- column-name OldValue -->
<column type="gchararray"/>
<!-- column-name NewValue -->
<column type="gchararray"/>
<!-- column-name CompareString -->
<column type="gchararray"/>
<!-- column-name Color -->
<column type="gchararray"/>
<!-- column-name Show -->
<column type="gboolean"/>
<!-- column-name SaveCommand -->
<column type="gchararray"/>
</columns>
</object>
</interface>

@ -42,6 +42,7 @@ set(DEPENDFILES
../libublsettingsui-gtk3-documentation.glade ../libublsettingsui-gtk3-documentation.glade
../libublsettingsui-gtk3-saving.glade ../libublsettingsui-gtk3-saving.glade
../libublsettingsui-gtk3-debugger.glade ../libublsettingsui-gtk3-debugger.glade
../libublsettingsui-gtk3-config-window.glade
../gresource.xml ../gresource.xml
../libublsettingsui-gtk3-banner.png ../libublsettingsui-gtk3-banner.png
../libublsettingsui-gtk3.css ../libublsettingsui-gtk3.css
@ -77,6 +78,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra -Werror -Wmissin
add_library(${PROJECT_NAME} SHARED add_library(${PROJECT_NAME} SHARED
libublsettingsui-gtk3.c libublsettingsui-gtk3.c
libublsettingsui-gtk3-save.c libublsettingsui-gtk3-save.c
libublsettingsui-gtk3-config-window.c
libublsettingsui-gtk3.h libublsettingsui-gtk3.h
${CMAKE_CURRENT_BINARY_DIR}/${GRESOURCE_C}) ${CMAKE_CURRENT_BINARY_DIR}/${GRESOURCE_C})

@ -1,32 +1,215 @@
#include "libublsettingsui-gtk3.h" #include "libublsettingsui-gtk3.h"
typedef struct { typedef struct {
dictionary_fields 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;
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_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]&&parameters[i+1];i+=2){
gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(parameter->ComboBox),parameters[i],parameters[i+1]);
}
gtk_combo_box_set_active(GTK_COMBO_BOX(parameter->ComboBox),0);
gtk_widget_show_all(parameter->Box);
return parameter;
}
typedef struct yon_configuration_parameters {
dictionary_fields(yon_configuration_parameters);
char *label;
enum CONFIGURATION_PARAMETER_TYPE type;
} yon_configuration_parameters; } yon_configuration_parameters;
ubl_settings_window *yon_ubl_settings_window_new(){ ubl_settings_window *yon_ubl_settings_window_new(){
ubl_settings_window *window = malloc(sizeof(ubl_settings_window)); ubl_settings_window *window = malloc(sizeof(ubl_settings_window));
GtkBuilder *builder = gtk_builder_new_from_resource("/com/ublinux/libublsettingsui-gtk3-config-window.glade"); 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->window = yon_gtk_builder_get_widget(builder,"Window");
window->WorkZoneBox = yon_gtk_builder_get_widget(builder,"WorkZoneBox"); 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");
g_signal_connect(G_OBJECT(window->CancelButton),"clicked",G_CALLBACK(on_subwindow_close),NULL);
return window; return window;
} }
yon_configuration_parameters *__yon_settings_parameters = NULL; yon_configuration_parameters *__yon_settings_parameters = NULL;
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;
}
}
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;
}
void __yon_on_ubl_settings_window_open(){ 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);
} }
void yon_ubl_settings_window_init(){ void yon_ubl_settings_window_init(GtkMenu *menu){
GtkMenuItem *menu_item = gtk_menu_item_new(); GtkWidget *menu_item = gtk_menu_item_new();
GtkWidget *box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,5); GtkWidget *box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,5);
GtkWidget *label = gtk_label_new(CONFIG_WINDOW_MENU_LABEL); GtkWidget *label = gtk_label_new(CONFIG_WINDOW_MENU_LABEL);
GtkWidget *image = gtk_image_new_from_icon_name("com.ublinux.libublsettingsui-gtk3.settings-symbolic",GTK_ICON_SIZE_BUTTON); 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_container_add(GTK_CONTAINER(menu_item),box);
gtk_box_pack_start(GTK_BOX(box),image,0,0,0); gtk_box_pack_start(GTK_BOX(box),image,0,0,0);
gtk_box_pack_start(GTK_BOX(box),label,0,0,0); gtk_box_pack_start(GTK_BOX(box),label,0,0,0);
gtk_widget_show_all(menu_item); gtk_widget_show_all(menu_item);
g_signal_connect(G_OBJECT(menu_item),"activate",G_CALLBACK(__yon_on_ubl_settings_window_open),NULL); g_signal_connect(G_OBJECT(menu_item),"activate",G_CALLBACK(__yon_on_ubl_settings_window_open),NULL);
}
void *yon_ubl_settings_window_get(char *id){
yon_configuration_parameters *current = (yon_configuration_parameters*)yon_dictionary_get((dictionary**)&__yon_settings_parameters,id);
if (current){
return current->data;
} else {
return NULL;
}
}
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->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;
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;
}
}
void yon_configuration_window_add_combo_box_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);
va_list args;
va_start(args,label);
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);
}
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;
}
} }

@ -250,9 +250,23 @@ char *yon_get_default_label_with_parameter(char *section, char *parameter);
template_saving_window *yon_save_proceed(char *path,YON_CONFIG_TYPE type, ...); template_saving_window *yon_save_proceed(char *path,YON_CONFIG_TYPE type, ...);
enum CONFIGURATION_PARAMETER_TYPE{
CONFIGURATION_PARAMETER_BOOL,
CONFIGURATION_PARAMETER_ENTRY,
CONFIGURATION_PARAMETER_COMBO_BOX,
CONFIGURATION_PARAMETER_LIST_MULTIPLE
};
void yon_ubl_settings_window_init(GtkMenu *menu);
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_combo_box_parameter(enum CONFIGURATION_PARAMETER_TYPE type, char *id, char *label,...);
typedef struct { typedef struct {
GtkWidget *window; GtkWidget *window;
GtkWidget *WorkZoneBox; GtkWidget *WorkZoneBox;
GtkWidget *AcceptButton;
GtkWidget *CancelButton;
} ubl_settings_window; } ubl_settings_window;
#define VERSION_LABEL yon_char_unite(_("Version:")," ",!yon_char_is_empty(template_app_information.app_version)?template_app_information.app_version:"","\n",NULL) #define VERSION_LABEL yon_char_unite(_("Version:")," ",!yon_char_is_empty(template_app_information.app_version)?template_app_information.app_version:"","\n",NULL)

Loading…
Cancel
Save