Merge pull request 'master' (#21) from YanTheKaller/libublsettings-gtk3:master into master

Reviewed-on: #21
master v1.19
Dmitry Razumov 1 year ago
commit 89d91f7516

@ -148,7 +148,7 @@ void yon_terminal_integrated_start_shell(GtkWidget *terminal, char* command, voi
// Window config section // Window config section
#define check_window_config_setup if(__yon_window_config_target_window) #define check_window_config_setup if(__yon_window_config_target_window&&__yon_window_config_path)
typedef struct { typedef struct {
char *parameter_name; char *parameter_name;
@ -180,54 +180,57 @@ void yon_terminal_integrated_start_shell(GtkWidget *terminal, char* command, voi
static char *__yon_window_config_path = NULL; static char *__yon_window_config_path = NULL;
void yon_window_config_save(){ void yon_window_config_save(){
check_window_config_setup {
g_key_file_set_integer(__yon_window_config_file,"window","WindowPosX",__yon_main_window_config.x); g_key_file_set_integer(__yon_window_config_file,"window","WindowPosX",__yon_main_window_config.x);
g_key_file_set_integer(__yon_window_config_file,"window","WindowPosY",__yon_main_window_config.y); g_key_file_set_integer(__yon_window_config_file,"window","WindowPosY",__yon_main_window_config.y);
g_key_file_set_integer(__yon_window_config_file,"window","WindowWidth",__yon_main_window_config.width); g_key_file_set_integer(__yon_window_config_file,"window","WindowWidth",__yon_main_window_config.width);
g_key_file_set_integer(__yon_window_config_file,"window","WindowHeight",__yon_main_window_config.height); g_key_file_set_integer(__yon_window_config_file,"window","WindowHeight",__yon_main_window_config.height);
g_key_file_set_integer(__yon_window_config_file,"window","fullscreen",__yon_main_window_config.fullscreen); g_key_file_set_integer(__yon_window_config_file,"window","fullscreen",__yon_main_window_config.fullscreen);
dictionary *dict=NULL; dictionary *dict=NULL;
if (__yon_main_window_config.deleted_parameters) if (__yon_main_window_config.deleted_parameters)
for_dictionaries(dict,__yon_main_window_config.deleted_parameters){ for_dictionaries(dict,__yon_main_window_config.deleted_parameters){
__yon_custom_parameter *param = yon_dictionary_get_data(dict,__yon_custom_parameter*); __yon_custom_parameter *param = yon_dictionary_get_data(dict,__yon_custom_parameter*);
g_key_file_remove_key(__yon_window_config_file,param->section,param->parameter_name,NULL); g_key_file_remove_key(__yon_window_config_file,param->section,param->parameter_name,NULL);
}
if (__yon_main_window_config.custom_listeners)
for_dictionaries(dict,__yon_main_window_config.custom_listeners){
__yon_listener_parameter *param = yon_dictionary_get_data(dict,__yon_listener_parameter*);
GValue *val = g_malloc0(sizeof(GValue));
g_object_get_property(G_OBJECT(param->track_widget),param->property_name,val);
switch(param->containing_type){
case YON_TYPE_STRING:
g_key_file_set_string(__yon_window_config_file,"window",param->parameter_name, g_value_get_string(val));
break;
case YON_TYPE_INT:
g_key_file_set_integer(__yon_window_config_file,"window",param->parameter_name, g_value_get_int(val));
break;
case YON_TYPE_BOOLEAN:
g_key_file_set_boolean(__yon_window_config_file,"window",param->parameter_name, g_value_get_boolean(val));
break;
case YON_TYPE_OTHER:printf("\033[0;31mCannot save %s property with %s key\033[0m\n",param->property_name,param->parameter_name);break;
} }
} if (__yon_main_window_config.custom_listeners)
if (__yon_main_window_config.custom_parameters) for_dictionaries(dict,__yon_main_window_config.custom_listeners){
for_dictionaries(dict,__yon_main_window_config.custom_parameters){ __yon_listener_parameter *param = yon_dictionary_get_data(dict,__yon_listener_parameter*);
__yon_custom_parameter *param = yon_dictionary_get_data(dict,__yon_custom_parameter*); GValue *val = g_malloc0(sizeof(GValue));
switch (param->containing_type){ g_object_get_property(G_OBJECT(param->track_widget),param->property_name,val);
case YON_TYPE_STRING: switch(param->containing_type){
g_key_file_set_string(__yon_window_config_file,param->section,param->parameter_name, (char*)param->property); case YON_TYPE_STRING:
break; g_key_file_set_string(__yon_window_config_file,"window",param->parameter_name, g_value_get_string(val));
case YON_TYPE_INT: break;
g_key_file_set_integer(__yon_window_config_file,param->section,param->parameter_name, *(int*)param->property); case YON_TYPE_INT:
break; g_key_file_set_integer(__yon_window_config_file,"window",param->parameter_name, g_value_get_int(val));
case YON_TYPE_BOOLEAN: break;
g_key_file_set_boolean(__yon_window_config_file,param->section,param->parameter_name, *(gboolean*)param->property); case YON_TYPE_BOOLEAN:
break; g_key_file_set_boolean(__yon_window_config_file,"window",param->parameter_name, g_value_get_boolean(val));
default: break;
break; case YON_TYPE_OTHER:printf("\033[0;31mCannot save %s property with %s key\033[0m\n",param->property_name,param->parameter_name);break;
}
}
if (__yon_main_window_config.custom_parameters)
for_dictionaries(dict,__yon_main_window_config.custom_parameters){
__yon_custom_parameter *param = yon_dictionary_get_data(dict,__yon_custom_parameter*);
switch (param->containing_type){
case YON_TYPE_STRING:
g_key_file_set_string(__yon_window_config_file,param->section,param->parameter_name, (char*)param->property);
break;
case YON_TYPE_INT:
g_key_file_set_integer(__yon_window_config_file,param->section,param->parameter_name, *(int*)param->property);
break;
case YON_TYPE_BOOLEAN:
g_key_file_set_boolean(__yon_window_config_file,param->section,param->parameter_name, *(gboolean*)param->property);
break;
default:
break;
}
} }
g_key_file_save_to_file(__yon_window_config_file,__yon_window_config_path,NULL);
} }
g_key_file_save_to_file(__yon_window_config_file,__yon_window_config_path,NULL);
} }
void yon_get_is_fullscreen(){ void yon_get_is_fullscreen(){
@ -282,61 +285,62 @@ void yon_terminal_integrated_start_shell(GtkWidget *terminal, char* command, voi
} }
int yon_window_config_load(char *path){ int yon_window_config_load(char *path){
check_window_config_setup{
if (!access(path,0)){ if (!access(path,0)){
__yon_window_config_file = g_key_file_new(); __yon_window_config_file = g_key_file_new();
__yon_window_config_path=yon_char_new(path); __yon_window_config_path=yon_char_new(path);
if (!g_key_file_load_from_file(__yon_window_config_file,__yon_window_config_path,G_KEY_FILE_NONE,NULL)){ if (!g_key_file_load_from_file(__yon_window_config_file,__yon_window_config_path,G_KEY_FILE_NONE,NULL)){
struct stat st; struct stat st;
int size; int size;
config_str conf = yon_char_parse(yon_char_new(__yon_window_config_path),&size,"/"); config_str conf = yon_char_parse(yon_char_new(__yon_window_config_path),&size,"/");
char *path = yon_char_unite(conf[0],"/",conf[1],"/",conf[2],"/",conf[3],"/",conf[4],"/",NULL); char *path = yon_char_unite(conf[0],"/",conf[1],"/",conf[2],"/",conf[3],"/",conf[4],"/",NULL);
if (stat(path, &st) == -1) { if (stat(path, &st) == -1) {
mkdir(path, 0777); mkdir(path, 0777);
}
FILE *fp;
fp=fopen(__yon_window_config_path,"w");
chmod(__yon_window_config_path,0777);
fclose(fp);
g_key_file_load_from_file(__yon_window_config_file,__yon_window_config_path,G_KEY_FILE_NONE,NULL);
} }
FILE *fp; __yon_main_window_config.x = g_key_file_get_integer(__yon_window_config_file,"window","WindowPosX",NULL);
fp=fopen(__yon_window_config_path,"w"); __yon_main_window_config.y = g_key_file_get_integer(__yon_window_config_file,"window","WindowPosY",NULL);
chmod(__yon_window_config_path,0777); __yon_main_window_config.width = g_key_file_get_integer(__yon_window_config_file,"window","WindowWidth",NULL);
fclose(fp); __yon_main_window_config.height = g_key_file_get_integer(__yon_window_config_file,"window","WindowHeight",NULL);
g_key_file_load_from_file(__yon_window_config_file,__yon_window_config_path,G_KEY_FILE_NONE,NULL); __yon_main_window_config.fullscreen = g_key_file_get_integer(__yon_window_config_file,"window","fullscreen",NULL);
} dictionary *dict=NULL;
__yon_main_window_config.x = g_key_file_get_integer(__yon_window_config_file,"window","WindowPosX",NULL); if (__yon_main_window_config.custom_listeners)
__yon_main_window_config.y = g_key_file_get_integer(__yon_window_config_file,"window","WindowPosY",NULL); for_dictionaries(dict,__yon_main_window_config.custom_listeners){
__yon_main_window_config.width = g_key_file_get_integer(__yon_window_config_file,"window","WindowWidth",NULL); __yon_listener_parameter *param = yon_dictionary_get_data(dict,__yon_listener_parameter*);
__yon_main_window_config.height = g_key_file_get_integer(__yon_window_config_file,"window","WindowHeight",NULL); GValue *val = g_malloc0(sizeof(GValue));
__yon_main_window_config.fullscreen = g_key_file_get_integer(__yon_window_config_file,"window","fullscreen",NULL); g_object_get_property(G_OBJECT(param->track_widget),param->property_name,val);
dictionary *dict=NULL; switch(param->containing_type){
if (__yon_main_window_config.custom_listeners) case YON_TYPE_STRING:
for_dictionaries(dict,__yon_main_window_config.custom_listeners){ g_value_set_string(val,g_key_file_get_string(__yon_window_config_file,"window",param->parameter_name, NULL));
__yon_listener_parameter *param = yon_dictionary_get_data(dict,__yon_listener_parameter*); break;
GValue *val = g_malloc0(sizeof(GValue)); case YON_TYPE_INT:
g_object_get_property(G_OBJECT(param->track_widget),param->property_name,val); int output = g_key_file_get_integer(__yon_window_config_file,"window",param->parameter_name, NULL);
switch(param->containing_type){ if (!output) output=-1;
case YON_TYPE_STRING: g_value_set_int(val,output);
g_value_set_string(val,g_key_file_get_string(__yon_window_config_file,"window",param->parameter_name, NULL)); break;
break; case YON_TYPE_BOOLEAN:
case YON_TYPE_INT: gboolean res = g_key_file_get_boolean(__yon_window_config_file,"window",param->parameter_name, NULL);
int output = g_key_file_get_integer(__yon_window_config_file,"window",param->parameter_name, NULL); g_value_set_boolean(val,res);
if (!output) output=-1; break;
g_value_set_int(val,output); default:printf("\033[0;31mCannot load %s property with %s key\033[0m\n",param->property_name,param->parameter_name);break;
break; }
case YON_TYPE_BOOLEAN: g_object_set_property(G_OBJECT(param->track_widget),param->property_name,val);
gboolean res = g_key_file_get_boolean(__yon_window_config_file,"window",param->parameter_name, NULL); }
g_value_set_boolean(val,res); if (__yon_main_window_config.width==0) __yon_main_window_config.width=800;
break; if (__yon_main_window_config.height==0) __yon_main_window_config.height=600;
default:printf("\033[0;31mCannot load %s property with %s key\033[0m\n",param->property_name,param->parameter_name);break; gtk_window_resize(__yon_window_config_target_window,__yon_main_window_config.width,__yon_main_window_config.height);
gtk_window_move(__yon_window_config_target_window,__yon_main_window_config.x,__yon_main_window_config.y);
pthread_t tid;
pthread_create(&tid,NULL,(void *)_yon_maximize,NULL);
return 1;
} }
g_object_set_property(G_OBJECT(param->track_widget),param->property_name,val);
}
if (__yon_main_window_config.width==0) __yon_main_window_config.width=800;
if (__yon_main_window_config.height==0) __yon_main_window_config.height=600;
gtk_window_resize(__yon_window_config_target_window,__yon_main_window_config.width,__yon_main_window_config.height);
gtk_window_move(__yon_window_config_target_window,__yon_main_window_config.x,__yon_main_window_config.y);
pthread_t tid;
pthread_create(&tid,NULL,(void *)_yon_maximize,NULL);
return 1;
} else {
return 0;
} }
return 0;
} }
void yon_window_config_apply(){ void yon_window_config_apply(){
@ -377,13 +381,15 @@ void yon_terminal_integrated_start_shell(GtkWidget *terminal, char* command, voi
} }
void yon_window_config_add_instant_parameter(char *param_name, char *section, void *tracked_value, enum YON_TYPE val_type){ void yon_window_config_add_instant_parameter(char *param_name, char *section, void *tracked_value, enum YON_TYPE val_type){
switch (val_type){ check_window_config_setup {
case YON_TYPE_BOOLEAN: g_key_file_set_boolean(__yon_window_config_file,section,param_name,*((gboolean*)tracked_value)); switch (val_type){
break; case YON_TYPE_BOOLEAN: g_key_file_set_boolean(__yon_window_config_file,section,param_name,*((gboolean*)tracked_value));
case YON_TYPE_INT: g_key_file_set_integer(__yon_window_config_file,section,param_name,*((int*)tracked_value)); break;
break; case YON_TYPE_INT: g_key_file_set_integer(__yon_window_config_file,section,param_name,*((int*)tracked_value));
case YON_TYPE_STRING: g_key_file_set_string(__yon_window_config_file,section,param_name,(char*)tracked_value); break;
break; case YON_TYPE_STRING: g_key_file_set_string(__yon_window_config_file,section,param_name,(char*)tracked_value);
break;
}
} }
} }
@ -401,27 +407,29 @@ void yon_terminal_integrated_start_shell(GtkWidget *terminal, char* command, voi
int yon_window_config_get_parameter(char *section, char *config_parameter, void *return_value, enum YON_TYPE type){ int yon_window_config_get_parameter(char *section, char *config_parameter, void *return_value, enum YON_TYPE type){
GError *err=NULL; check_window_config_setup{
switch (type){ GError *err=NULL;
case YON_TYPE_BOOLEAN: switch (type){
*((int*)return_value) = g_key_file_get_boolean(__yon_window_config_file,section,config_parameter,&err); case YON_TYPE_BOOLEAN:
if (err) return 0; else return 1; *((int*)return_value) = g_key_file_get_boolean(__yon_window_config_file,section,config_parameter,&err);
break; if (err) return 0; else return 1;
case YON_TYPE_INT: break;
*((int*)return_value) = g_key_file_get_integer(__yon_window_config_file,section,config_parameter,&err); case YON_TYPE_INT:
if (err) return 0; else return 1; *((int*)return_value) = g_key_file_get_integer(__yon_window_config_file,section,config_parameter,&err);
break; if (err) return 0; else return 1;
case YON_TYPE_STRING: break;
*((char**)return_value) = g_key_file_get_string(__yon_window_config_file,section,config_parameter,&err); case YON_TYPE_STRING:
if (err) return 0; else return 1; *((char**)return_value) = g_key_file_get_string(__yon_window_config_file,section,config_parameter,&err);
break; if (err) return 0; else return 1;
case YON_TYPE_STRING_LIST: break;
gsize size=0; case YON_TYPE_STRING_LIST:
*((char***)return_value) = g_key_file_get_string_list(__yon_window_config_file,section,config_parameter,&size,&err); gsize size=0;
*((char***)return_value)=yon_remalloc(return_value,size+1); *((char***)return_value) = g_key_file_get_string_list(__yon_window_config_file,section,config_parameter,&size,&err);
*((char***)return_value)[size]=NULL; *((char***)return_value)=yon_remalloc(return_value,size+1);
if (err) return 0; else return 1; *((char***)return_value)[size]=NULL;
break; if (err) return 0; else return 1;
break;
}
} }
} }
@ -680,6 +688,30 @@ int yon_gtk_list_store_find_text(GtkListStore *list, GtkTreeIter *iter, int seek
return 0; return 0;
} }
void yon_gtk_toggle_button_set_inactive_from_toggle(GtkToggleButton *self, GtkToggleButton *target){
if (gtk_toggle_button_get_active(self)){
gtk_toggle_button_set_active(target,1);
} else {
gtk_toggle_button_set_active(target,0);
}
}
void yon_gtk_toggle_button_set_inactive_from_entry(GtkEntry *self, GtkToggleButton *target){
if (strlen(gtk_entry_get_text(self))>0){
gtk_toggle_button_set_active(target,1);
} else {
gtk_toggle_button_set_active(target,0);
}
}
void yon_gtk_toggle_button_set_inactive_from_combo_box(GtkComboBox *self, GtkToggleButton *target){
if (gtk_combo_box_get_active(self)>0){
gtk_toggle_button_set_active(target,1);
} else {
gtk_toggle_button_set_active(target,0);
}
}
void yon_gtk_widget_set_sensitive_from_toggle_button(GtkToggleButton *toggle, GtkWidget *target){ void yon_gtk_widget_set_sensitive_from_toggle_button(GtkToggleButton *toggle, GtkWidget *target){
gtk_widget_set_sensitive(target,gtk_toggle_button_get_active(toggle)); gtk_widget_set_sensitive(target,gtk_toggle_button_get_active(toggle));
} }

@ -252,6 +252,12 @@ int yon_dictionary_gtk_pack_end_multiple_widgets(GtkBox *destination, gboolean e
int yon_gtk_list_store_find_text(GtkListStore *list, GtkTreeIter *iter, int seek_column, char *value); int yon_gtk_list_store_find_text(GtkListStore *list, GtkTreeIter *iter, int seek_column, char *value);
void yon_gtk_toggle_button_set_inactive_from_toggle(GtkToggleButton *self, GtkToggleButton *target);
void yon_gtk_toggle_button_set_inactive_from_entry(GtkEntry *self, GtkToggleButton *target);
void yon_gtk_toggle_button_set_inactive_from_combo_box(GtkComboBox *self, GtkToggleButton *target);
/**yon_gtk_widget_set_sensitive_from_toggle_button(GtkToggleButton *toggle, GtkWidget *target) /**yon_gtk_widget_set_sensitive_from_toggle_button(GtkToggleButton *toggle, GtkWidget *target)
* [EN] * [EN]
* *

Loading…
Cancel
Save