test fix for g_key_file error

pull/21/head
parent c5d850447e
commit 74acaae673

@ -285,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(){
@ -406,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;
}
} }
} }

Loading…
Cancel
Save