From 6f0b88564da9006b128c457d06971359f771b0f4 Mon Sep 17 00:00:00 2001 From: Ivan Yarcev Date: Thu, 7 Mar 2024 10:36:52 +0600 Subject: [PATCH 01/10] Library saving API and functions update --- libublsettingsui-gtk3-saving.glade | 45 ++- source/libublsettingsui-gtk3.c | 443 +++++++++++------------------ source/libublsettingsui-gtk3.h | 2 + 3 files changed, 193 insertions(+), 297 deletions(-) diff --git a/libublsettingsui-gtk3-saving.glade b/libublsettingsui-gtk3-saving.glade index b1b7b1e..1514e56 100644 --- a/libublsettingsui-gtk3-saving.glade +++ b/libublsettingsui-gtk3-saving.glade @@ -36,14 +36,14 @@ + + - - @@ -105,8 +105,8 @@ - 4 - 5 + 5 + 6 0 @@ -121,8 +121,8 @@ 150 - 4 - 5 + 5 + 6 1 @@ -139,8 +139,8 @@ 250 - 4 - 5 + 5 + 6 2 @@ -156,8 +156,8 @@ 250 - 4 - 5 + 5 + 6 3 @@ -170,7 +170,9 @@ - 7 + 5 + 6 + 4 @@ -252,7 +254,24 @@ - - liststore1 + + + + + + + + + + + + + + + + + + + diff --git a/source/libublsettingsui-gtk3.c b/source/libublsettingsui-gtk3.c index e939bff..8426de4 100644 --- a/source/libublsettingsui-gtk3.c +++ b/source/libublsettingsui-gtk3.c @@ -113,7 +113,7 @@ void on_about(GtkWidget *self, char *version_application){ } //functions -void (*save_success_function)(void*)=NULL; +void (*save_success_function)(void*,config_str,int)=NULL; void *save_success_argument=NULL; void yon_save_window_set_postsave_function(void *function, void *data){ @@ -124,20 +124,11 @@ void yon_save_window_set_postsave_function(void *function, void *data){ void on_save_window_parameter_switched(GtkCellRendererToggle *self, gchar *path, template_saving_window *window){ GtkTreeIter iter,itar; if (path){ - if (gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(window->filteredModel),&itar,path)){ - char *seek_name; - gtk_tree_model_get(window->filteredModel,&itar,1,&seek_name,-1); - int valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(window->list),&iter); - for (;valid;valid=gtk_tree_model_iter_next(GTK_TREE_MODEL(window->list),&iter)){ - char *name; - gtk_tree_model_get(GTK_TREE_MODEL(window->list),&iter,1,&name,-1); - if (!strcmp(seek_name,name)){ - gboolean is_active; - gtk_tree_model_get(GTK_TREE_MODEL(window->list),&iter,0,&is_active,-1); - gtk_list_store_set(window->list,&iter,0,!is_active,-1); - } - } - } + if (gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(window->list),&itar,path)){ + gboolean is_active; + gtk_tree_model_get(GTK_TREE_MODEL(window->list),&itar,0,&is_active,-1); + gtk_list_store_set(window->list,&itar,0,!is_active,-1); + } } int once_active=0; int valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(window->list),&iter); @@ -151,7 +142,6 @@ void on_save_window_parameter_switched(GtkCellRendererToggle *self, gchar *path, } if (!once_active) gtk_widget_set_sensitive(window->SaveButton,0); else gtk_widget_set_sensitive(window->SaveButton,1); - gtk_tree_model_filter_refilter(GTK_TREE_MODEL_FILTER(window->filteredModel)); } @@ -173,189 +163,113 @@ template_debug_window *template_debugger_window_new(){ } void on_save_parameters(GtkWidget *self, template_saving_window *window){ - char *append_command = yon_char_unite("ubconfig --target ",template_config->load_mode==1?"global":"system"," set ",NULL); - char *remove_command = yon_char_unite("ubconfig --target ",template_config->load_mode==1?"global":"system"," remove ",NULL); - dictionary *final_append=NULL; - dictionary *final_remove=NULL; GtkTreeIter iter; - int valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(window->list),&iter); - for (;valid;valid=gtk_tree_model_iter_next(GTK_TREE_MODEL(window->list),&iter)){ - gboolean is_active,can_save; - char *parameter,*old_value,*new_value,*section; - gtk_tree_model_get(GTK_TREE_MODEL(window->list),&iter,0,&is_active,1,¶meter,2,&old_value,3,&new_value,5,&can_save,6,§ion,-1); - if (is_active&&can_save){ - if(!yon_char_is_empty(parameter)){ - if (yon_char_is_empty(new_value)){ // empty new value - delete - if (yon_dictionary_get(&final_remove,section)){ - final_remove->data = yon_char_unite((char*)final_remove->data," ",parameter,NULL); - } else { - yon_dictionary_add_or_create_if_exists_with_data(final_remove,section, parameter); - } - } else { // non-empty new value - add - if (yon_dictionary_get(&final_append,section)){ - final_append->data=yon_char_unite((char*)final_append->data," ",yon_char_unite(parameter,"=\'",new_value,"\'",NULL),NULL); - } else { - yon_dictionary_add_or_create_if_exists_with_data(final_append,section, yon_char_unite(parameter,"=",new_value[0]!='\''?"\'":"",new_value,new_value[strlen(new_value)-1]!='\''?"\'":"",NULL)); - } - } - } + GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(window->ParametersTree)); + int valid = gtk_tree_model_get_iter_first(model,&iter); + int saved_size=0; + config_str saved_parameters=NULL; + for (;valid;valid = gtk_tree_model_iter_next(model,&iter)){ + char *parameter; + int is_active; + gtk_tree_model_get(model,&iter,0,&is_active,1,¶meter,-1); + if (is_active){ + yon_char_parsed_add_or_create_if_exists(saved_parameters,&saved_size,parameter); } + } - // if (debug_output==1){ - // template_debug_window *debug_window = template_debugger_window_new(); - // gtk_widget_show(debug_window->Window); - // dictionary *dict = NULL; - // char *final_command_line = ""; - // if (final_remove){ - // for_dictionaries(dict,final_remove){ - // char *final_command = yon_char_unite(remove_command," ",dict->key," ",(char*)dict->data,NULL); - // char *temp = yon_char_unite(final_command_line,!yon_char_is_empty(final_command_line)?";echo \"":"echo \"",final_command,"\";",final_command,NULL); - // if (!yon_char_is_empty(final_command_line)) - // free(final_command_line); - // final_command_line=temp; - // free(final_command); - // } - // } - // if (final_append){ - // for_dictionaries(dict,final_append){ - // char *final_command = yon_char_unite(append_command," ",dict->key," ",(char*)dict->data,NULL); - // char *temp = yon_char_unite(final_command_line,!yon_char_is_empty(final_command_line)?";echo \"":"echo \"",final_command,"\";",final_command,NULL); - // if (!yon_char_is_empty(final_command_line)) - // free(final_command_line); - // final_command_line=temp; - // free(final_command); - // } - // } - // if (window->type==YON_CONFIG_BOTH) { - // if (template_config->load_mode==1){ - // yon_config_save_registered("system"); - // } else if (template_config->load_mode==0){ - // yon_config_save_registered("global"); - // } - // } - // if (!yon_char_is_empty(final_command_line)){ - // if (debug_output) - // printf("%s\n",final_command_line); - // yon_terminal_integrated_start(debug_window->Vte,final_command_line,NULL,NULL); - // } - // } else - { - dictionary *dict = NULL; - if (final_remove){ - for_dictionaries(dict,final_remove){ - char *final_command = yon_char_unite(remove_command," ",dict->key," ",(char*)dict->data,NULL); - system(final_command); - printf("%s\n",final_command); - free(final_command); - } + int size=0; + config_str commands = yon_config_get_save_parameters_by_list(&size,saved_parameters,saved_size); + char *target = yon_config_get_type_path(window->type); + if (target){ + if (yon_char_is_empty(target)){ + yon_char_parsed_prepend_strings(commands,size,ubconfig_dull_command); } - if (final_append){ - for_dictionaries(dict,final_append){ - char *final_command = yon_char_unite(append_command," ",dict->key," ",(char*)dict->data,NULL); - system(final_command); - printf("%s\n",final_command); - free(final_command); - } + yon_char_parsed_prepend_strings(commands,size,ubconfig_set_command(target)); + } else return; + char *final_command = yon_char_parsed_to_string(commands,size,";"); + FILE *file = popen(final_command,"r"); + int file_save; + config_str file_return = yon_config_load_file(file,&file_save); + if (save_success_function) + { + save_success_function(save_success_argument,file_return,file_save); + } + + yon_window_config_custom_window_set(GTK_WINDOW(window->Window),"SaveWindow"); + on_subwindow_close(self); +} + +struct loaded_config { + dictionary_fields(loaded_config); + char *section; +}; + +struct loaded_config *yon_config_convert_parameter(config_str parsed, int size){ + struct loaded_config *loaded=NULL; + for (int i=0;ikey=key; + loaded->first=loaded; + loaded->next=NULL; + loaded->prev=NULL; + loaded->section=NULL; + loaded->data=value; + } else { + loaded->next = (struct loaded_config*)malloc(sizeof(struct loaded_config)); + struct loaded_config *next=loaded->next; + next->first=loaded->first; + next->prev=loaded; + next->key=key; + next->first=loaded->first; + next->next=NULL; + next->section=NULL; + next->data=value; + loaded=next; } - if (window->type==YON_CONFIG_BOTH) { - if (template_config->load_mode==1){ - yon_config_save_registered("system"); - } else if (template_config->load_mode==0){ - yon_config_save_registered("global"); + } + return loaded; +} + +struct loaded_config *yon_config_get_compared(char *command, int *final_size){ + if (command){ + *final_size=0; + int size; + config_str config = yon_config_load(command,&size); + config_str temporary = NULL; + int temp_size; + if (config&&size>0){ + for (int i=0;itype == YON_CONFIG_GLOBAL) - yon_ubl_status_box_render(GLOBAL_SAVE_SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE); - else if (window->type == YON_CONFIG_LOCAL) - yon_ubl_status_box_render(LOCAL_SAVE_SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE); - else if (window->type == YON_CONFIG_BOTH) - yon_ubl_status_box_render(GLOBAL_LOCAL_SAVE_SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE); - textdomain(template_app_information.app_locale); - yon_window_config_custom_window_set(GTK_WINDOW(window->Window),"SaveWindow"); - on_subwindow_close(self); } template_saving_window *yon_save_proceed(char *path,YON_CONFIG_TYPE type, ...){ - if (((type==YON_CONFIG_LOCAL&& template_config->load_mode==1)||(type==YON_CONFIG_GLOBAL&& template_config->load_mode==0))){ - yon_config_save_registered(path); - textdomain(template_ui_LocaleName); - if (type == YON_CONFIG_GLOBAL) - yon_ubl_status_box_render(GLOBAL_SAVE_SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE); - else if (type == YON_CONFIG_LOCAL) - yon_ubl_status_box_render(LOCAL_SAVE_SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE); - else if (type == YON_CONFIG_BOTH) - yon_ubl_status_box_render(GLOBAL_LOCAL_SAVE_SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE); - textdomain(template_app_information.app_locale); - return NULL; - } else { char *config_to_save = NULL; - if (type==YON_CONFIG_GLOBAL) config_to_save="global"; - else if (type==YON_CONFIG_LOCAL) config_to_save="system"; - else if (type==YON_CONFIG_BOTH) { - if (template_config->load_mode==1){ - config_to_save="global"; - } else if (template_config->load_mode==0){ - config_to_save="system"; - } - } - config_str config_compare=NULL; + config_to_save = yon_config_get_type_path(type); + struct loaded_config *config_compare=NULL; int compare_size=0; va_list args; va_start(args,type); - char *cur_section = NULL; - dictionary *section_commands=NULL; - while ((cur_section=va_arg(args,char*))){ - char *cur_parameter = va_arg(args,char*); - yon_dictionary_add_or_create_if_exists_with_data(section_commands,cur_section,cur_parameter); - } - struct loaded_config { - dictionary *dict; - char *section; - }; - - struct loaded_config loaded; - loaded.dict = yon_dictionary_new(); - dictionary *dct; - for_dictionaries(dct,section_commands){ - char *command = yon_char_unite(ubconfig_load_command," ", config_to_save," get ", dct->key," ", yon_dictionary_get_data(dct,char*),NULL); - FILE *output = popen(command, "r"); - char **output_strings = NULL; - output_strings = malloc(sizeof(char*)); - int i = 0; - char str[4096]; - memset(str, 0, 4096); - while (fgets(str, 4096, output)) - { - if (!yon_char_is_empty(str)&& strcmp(str,"(null)\n")!=0) - { - char *final_str = yon_char_new(str); - char *key = yon_char_divide_search(final_str,"=",-1); - final_str=yon_char_divide_search(final_str,"\n",-1); - if ((final_str[0]=='\''&&final_str[strlen(final_str)-1]=='\'')||(final_str[0]=='\"'&&final_str[strlen(final_str)-1]=='\"')){ - final_str[strlen(final_str)-1] = '\0'; - free(yon_char_divide(final_str,0)); - } - char *str_copy = yon_char_unite(key,"=",final_str,NULL); - dictionary *found=NULL; - if (!(found=yon_dictionary_get(&loaded.dict,key))){ - yon_dictionary_add_or_create_if_exists_with_data(loaded.dict,NULL,yon_char_new(dct->key)); - yon_dictionary_add_or_create_if_exists_with_data(loaded.dict,key,yon_char_new(final_str)); - yon_char_parsed_add_or_create_if_exists(config_compare,&compare_size,yon_char_new(str_copy)); - } else{ - int element = yon_char_parsed_check_exist(config_compare,compare_size,(char*)loaded.dict->data); - if (element>-1){ - free(config_compare[element]); - config_compare[element]=yon_char_new(str_copy); - loaded.dict->data = yon_char_new(final_str); - } - } - } - } + char *compare_command=""; + char *cur_command; + while ((cur_command=va_arg(args,char*))){ + compare_command = yon_char_unite(compare_command,!yon_char_is_empty(compare_command)?";":"",cur_command,NULL); } + config_compare = yon_config_get_compared(compare_command,&compare_size); /////////////////////////////////////////////// + GtkBuilder *builder = gtk_builder_new_from_resource(ui_glade_path_saving); template_saving_window *window = malloc(sizeof(template_saving_window)); window->Window = yon_gtk_builder_get_widget(builder,"Window"); @@ -371,6 +285,16 @@ template_saving_window *yon_save_proceed(char *path,YON_CONFIG_TYPE type, ...){ window->OldValueCell = GTK_CELL_RENDERER(gtk_builder_get_object(builder,"OldValueCell")); window->NewValueColumn = GTK_TREE_VIEW_COLUMN(gtk_builder_get_object(builder,"NewValueColumn")); window->NewValueCell = GTK_CELL_RENDERER(gtk_builder_get_object(builder,"NewValueCell")); + window->type=type; + window->filteredModel = GTK_TREE_MODEL(gtk_builder_get_object(builder,"listfilter1")); + yon_window_config_custom_window_setup(GTK_WINDOW(window->Window),"SaveWindow"); + gtk_window_set_icon_name(GTK_WINDOW(window->Window),yon_char_append("com.ublinux.",template_app_information.app_tech_name)); + gtk_window_set_title(GTK_WINDOW(window->Window),template_app_information.app_title); + gtk_label_set_text(GTK_LABEL(window->HeaderTopic),template_app_information.app_title); + gtk_image_set_from_pixbuf(GTK_IMAGE(window->HeaderImage),gtk_icon_theme_load_icon_for_scale(gtk_icon_theme_get_default(),yon_char_append("com.ublinux.",template_app_information.app_tech_name),32,1,GTK_ICON_LOOKUP_FORCE_SIZE,NULL)); + g_signal_connect(G_OBJECT(window->CancelButton),"clicked",G_CALLBACK(on_subwindow_close),NULL); + g_signal_connect(G_OBJECT(window->SaveButton),"clicked", G_CALLBACK(on_save_parameters),window); + g_signal_connect(G_OBJECT(window->ToggleCell),"toggled", G_CALLBACK(on_save_window_parameter_switched),window); textdomain(template_ui_LocaleName); if (type==YON_CONFIG_BOTH){ yon_ubl_status_box_spawn_infinite(GTK_CONTAINER(window->StatusBox),"savingTarget",SAVING_GLOBAL_LOCAL_STATE_LABEL,BACKGROUND_IMAGE_INFO_TYPE); @@ -382,115 +306,66 @@ template_saving_window *yon_save_proceed(char *path,YON_CONFIG_TYPE type, ...){ } textdomain(template_app_information.app_locale); - window->type=type; - window->filteredModel = GTK_TREE_MODEL(gtk_builder_get_object(builder,"listfilter1")); - gtk_tree_model_filter_set_visible_column(GTK_TREE_MODEL_FILTER(window->filteredModel),5); - yon_window_config_custom_window_setup(GTK_WINDOW(window->Window),"SaveWindow"); - gtk_window_set_icon_name(GTK_WINDOW(window->Window),yon_char_append("com.ublinux.",template_app_information.app_tech_name)); - gtk_window_set_title(GTK_WINDOW(window->Window),template_app_information.app_title); - gtk_label_set_text(GTK_LABEL(window->HeaderTopic),template_app_information.app_title); - gtk_image_set_from_pixbuf(GTK_IMAGE(window->HeaderImage),gtk_icon_theme_load_icon_for_scale(gtk_icon_theme_get_default(),yon_char_append("com.ublinux.",template_app_information.app_tech_name),32,1,GTK_ICON_LOOKUP_FORCE_SIZE,NULL)); - g_signal_connect(G_OBJECT(window->CancelButton),"clicked",G_CALLBACK(on_subwindow_close),NULL); - g_signal_connect(G_OBJECT(window->SaveButton),"clicked", G_CALLBACK(on_save_parameters),window); - g_signal_connect(G_OBJECT(window->ToggleCell),"toggled", G_CALLBACK(on_save_window_parameter_switched),window); - int config_size=0; - config_str config_strings = yon_config_get_all(&config_size); - if (config_strings){ //untracked parameters - GtkTreeIter iter; - gtk_tree_view_set_model(GTK_TREE_VIEW(window->ParametersTree),NULL); - config_str compare_keys = NULL; - compare_keys = yon_char_parsed_copy(config_compare,compare_size); - int compare_keys_size=compare_size; - yon_char_parsed_divide_search_full(compare_keys,compare_keys_size,"=",-1); - int config_keys_size=0; - config_str config_keys = yon_config_get_all_keys(&config_keys_size); - int final_size=0; - GdkRGBA rgba; - rgba.alpha=0.8; - rgba.red=1; - rgba.blue=0.3; - rgba.green=0.65; - char *rgba_string = gdk_rgba_to_string(&rgba); - for (int i=0;ikey); + gboolean status=0; + status = yon_config_get_status(current->key); + if (dict&&!yon_char_is_empty((char*)dict->data)&&status!=-2){ + if (strcmp((char*)dict->data,(char*)current->data)){ + GtkTreeIter iter; + if (status==0||status==-2) status = 0; + else status=1; + char *compare_string = yon_char_unite("",(char*)dict->data,"\n",(char*)current->data,NULL); gtk_list_store_append(window->list,&iter); - gtk_list_store_set(window->list,&iter,0,0,1,compare_keys[i],5,1,-1); - for (int j=0;jfirst,compare_keys[i])->prev->data; - char *combined = yon_char_unite("",compare_value,"\n",NULL); - gtk_list_store_set(window->list,&iter,2,compare_value,4,rgba_string,6,cur_section,7,combined,-1); - free(combined); - } - free(compare_value); - free(compare_name); - } - if (yon_config_check_ignore(compare_keys[i])){ - gtk_list_store_set(window->list,&iter,0,0,1,compare_keys[i],4,NULL,5,0,-1); - - } - - } - char *name,*value; - for (int i=0;ilist),&iter); - for (;valid;valid=gtk_tree_model_iter_next(GTK_TREE_MODEL(window->list),&iter)){ // found parameter - gtk_tree_model_get(GTK_TREE_MODEL(window->list),&iter,1,&name,2,&value,-1); - if (!yon_char_is_empty(name)&&!strcmp(name,config_keys[i])){ - if (!yon_config_check_ignore(name)){ - char *combined = yon_char_unite("",value,"\n",compare_value,NULL); - gtk_list_store_set(window->list,&iter,3,compare_value,4,NULL,6,section,7,combined,-1); - free(combined); - if ((value&&!strcmp(value,compare_value))){ - gtk_list_store_set(window->list,&iter,0,0,3,value,5,0,-1); - } else { - if (yon_config_get_status(name)!=0){ - gtk_list_store_set(window->list,&iter,0,1,5,1,-1); - } - }; - }; - found=1; - break; - } - } - if (!found){ // new parameter - if (!yon_config_check_ignore(compare_name)&&!yon_char_is_empty(compare_value)){ - GtkTreeIter itar; - gtk_list_store_append(window->list,&itar); - char *combined = yon_char_append("\n",compare_value); - gtk_list_store_set(window->list,&itar,0,0,1,compare_name,3,compare_value,5,1,6,section,7,combined,-1); - if (yon_config_get_status(compare_name)==1){ - gtk_list_store_set(window->list,&itar,0,1,-1); - } - free(combined); - } - } - free(compare_value); - free(compare_name); + gtk_list_store_set(window->list,&iter,0,status,1,current->key,2,(char*)dict->data,3,(char*)current->data,4,compare_string,6,1,-1); + free(compare_string); + } + } else if ((strcmp((char*)current->data,""))&&status!=-2){ + GtkTreeIter iter; + if (status==0||status==-2) status = 0; + else status=1; + char *compare_string = yon_char_unite("\n",(char*)current->data,NULL); + gtk_list_store_append(window->list,&iter); + gtk_list_store_set(window->list,&iter,0,status,1,current->key,3,(char*)current->data,4,compare_string,6,1,-1); + free(compare_string); } - free(rgba_string); - if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(window->filteredModel),&iter)){ - gtk_widget_destroy(window->Window); - textdomain(template_ui_LocaleName); - yon_ubl_status_box_render(NOTHING_TO_SAVE_LABEL,BACKGROUND_IMAGE_FAIL_TYPE); - textdomain(template_app_information.app_locale); - return NULL; + } + for_dictionaries(current,config_compare){ + GtkTreeIter iter; + dictionary *dict = yon_dictionary_get((dictionary**)¤t_loaded,current->key); + if (!dict){ + GdkRGBA rgba; + rgba.alpha=0.8; + rgba.red=1; + rgba.blue=0.3; + rgba.green=0.65; + char *rgba_string = gdk_rgba_to_string(&rgba); + int status=0; + char *compare_string = yon_char_unite((char*)current->data,"\n",NULL); + gtk_list_store_append(window->list,&iter); + gtk_list_store_set(window->list,&iter,0,0,1,current->key,3,(char*)current->data,4,compare_string,5,rgba_string,6,1,-1); + free(compare_string); } - gtk_tree_view_set_model(GTK_TREE_VIEW(window->ParametersTree),window->filteredModel); } - + GtkTreeIter iter; + if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(window->list),&iter)){ + gtk_widget_destroy(window->Window); + textdomain(template_ui_LocaleName); + yon_ubl_status_box_render(NOTHING_TO_SAVE_LABEL,BACKGROUND_IMAGE_FAIL_TYPE); + textdomain(template_app_information.app_locale); + return NULL; + } + gtk_tree_view_set_model(GTK_TREE_VIEW(window->ParametersTree),GTK_TREE_MODEL(window->list)); gtk_widget_show(window->Window); on_save_window_parameter_switched(NULL,NULL,window); return window; - - } - } int yon_confirmation_dialog_call(GtkWidget *self,dialog_confirmation_data *data){ diff --git a/source/libublsettingsui-gtk3.h b/source/libublsettingsui-gtk3.h index a8acc81..cbfdd7b 100644 --- a/source/libublsettingsui-gtk3.h +++ b/source/libublsettingsui-gtk3.h @@ -93,6 +93,8 @@ #define SAVE_MODE_HDD_HOME_LABEL _("HDD sandbox with profile saving") #endif +#define dull_parameter_get_command "ubconfig --source global get users PARAMETER" + #define SAVE_MODE_GET_COMMAND "ubconfig --raw --source system get [config] SYSTEMBOOT_STATEMODE" typedef enum SAVE_MODE_TYPE { From 114cd74f7ac3c6374cabf0e131bbf2140b9fd4d5 Mon Sep 17 00:00:00 2001 From: Ivan Yarcev Date: Mon, 11 Mar 2024 17:44:59 +0600 Subject: [PATCH 02/10] Added saving and loading from specific file --- libublsettingsui-gtk3-filechooser.glade | 142 +++++++++++++++++++++++ libublsettingsui-gtk3.glade | 22 ++++ libublsettingsui-gtk3.pot | 144 +++++++++++++++++------- libublsettingsui-gtk3_ru.po | 144 +++++++++++++++++------- source/libublsettingsui-gtk3.c | 71 +++++++++--- source/libublsettingsui-gtk3.h | 91 ++++++++------- 6 files changed, 478 insertions(+), 136 deletions(-) create mode 100644 libublsettingsui-gtk3-filechooser.glade diff --git a/libublsettingsui-gtk3-filechooser.glade b/libublsettingsui-gtk3-filechooser.glade new file mode 100644 index 0000000..c1ebeea --- /dev/null +++ b/libublsettingsui-gtk3-filechooser.glade @@ -0,0 +1,142 @@ + + + + + + 450 + 500 + False + True + com.ublinux.libublsettingsui-gtk3 + dialog + + + True + False + vertical + 5 + + + True + False + vertical + + + + + + False + True + 0 + + + + + True + False + 5 + 5 + 5 + 5 + 5 + vertical + 5 + + + True + False + False + True + + + True + True + 0 + + + + + True + True + 2 + + + + + + + True + False + True + + + True + False + TEMPLATE Manager + + + + + + + + True + False + 32 + com.ublinux.libublsettingsui-gtk3 + + + + + Cancel + True + True + True + image1 + + + + 1 + + + + + Save + True + True + True + image2 + + + + end + 2 + + + + + + + + True + False + com.ublinux.libublsettingsui-gtk3.cancel-symbolic + + + + True + False + com.ublinux.libublsettingsui-gtk3.accept-symbolic + + + diff --git a/libublsettingsui-gtk3.glade b/libublsettingsui-gtk3.glade index 83bdb4f..4eff111 100644 --- a/libublsettingsui-gtk3.glade +++ b/libublsettingsui-gtk3.glade @@ -148,6 +148,17 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. True False Load local configuration + + + + + + True + False + Load from specific file + True @@ -195,6 +206,17 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. True False Save to local configuration + + + + + + True + False + Save to specific file + True diff --git a/libublsettingsui-gtk3.pot b/libublsettingsui-gtk3.pot index fbdcbf5..e36ad95 100644 --- a/libublsettingsui-gtk3.pot +++ b/libublsettingsui-gtk3.pot @@ -17,168 +17,232 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -#: source/libublsettingsui-gtk3.h:31 +#: source/libublsettingsui-gtk3.h:34 +msgid "Version:" +msgstr "" + +#: source/libublsettingsui-gtk3.h:35 +msgid " version:" +msgstr "" + +#: source/libublsettingsui-gtk3.h:35 +msgid "Usage:" +msgstr "" + +#: source/libublsettingsui-gtk3.h:35 +msgid "[OPTIONS]" +msgstr "" + +#: source/libublsettingsui-gtk3.h:35 +msgid "Options:" +msgstr "" + +#: source/libublsettingsui-gtk3.h:35 +msgid "Show this help" +msgstr "" + +#: source/libublsettingsui-gtk3.h:35 +msgid "Show package version" +msgstr "" + +#: source/libublsettingsui-gtk3.h:35 +msgid "Lock this help menu" +msgstr "" + +#: source/libublsettingsui-gtk3.h:35 +msgid "Lock configuration saving" +msgstr "" + +#: source/libublsettingsui-gtk3.h:35 +msgid "Lock local configration saving" +msgstr "" + +#: source/libublsettingsui-gtk3.h:35 +msgid "Lock global configration saving" +msgstr "" + +#: source/libublsettingsui-gtk3.h:35 +msgid "Lock global configration loading" +msgstr "" + +#: source/libublsettingsui-gtk3.h:35 +msgid "Reset application settings" +msgstr "" + +#: source/libublsettingsui-gtk3.h:40 msgid "Operation succeeded" msgstr "" -#: source/libublsettingsui-gtk3.h:32 +#: source/libublsettingsui-gtk3.h:41 msgid "" "Warning! Application was launched without root - root-dependent actions are " "locked" msgstr "" -#: source/libublsettingsui-gtk3.h:34 +#: source/libublsettingsui-gtk3.h:43 msgid "About" msgstr "" -#: source/libublsettingsui-gtk3.h:35 +#: source/libublsettingsui-gtk3.h:44 msgid "Documentation" msgstr "" -#: source/libublsettingsui-gtk3.h:37 +#: source/libublsettingsui-gtk3.h:46 +msgid "Save to specific file" +msgstr "" + +#: source/libublsettingsui-gtk3.h:47 msgid "Save to local configuration" msgstr "" -#: source/libublsettingsui-gtk3.h:38 +#: source/libublsettingsui-gtk3.h:48 msgid "Save to global configuration" msgstr "" -#: source/libublsettingsui-gtk3.h:39 +#: source/libublsettingsui-gtk3.h:49 msgid "Save configuration" msgstr "" -#: source/libublsettingsui-gtk3.h:40 +#: source/libublsettingsui-gtk3.h:50 msgid "Save" msgstr "" -#: source/libublsettingsui-gtk3.h:42 +#: source/libublsettingsui-gtk3.h:52 +msgid "Load from specific file" +msgstr "" + +#: source/libublsettingsui-gtk3.h:53 msgid "Load local configuration" msgstr "" -#: source/libublsettingsui-gtk3.h:43 +#: source/libublsettingsui-gtk3.h:54 msgid "Load global configuration" msgstr "" -#: source/libublsettingsui-gtk3.h:44 +#: source/libublsettingsui-gtk3.h:55 msgid "Load" msgstr "" -#: source/libublsettingsui-gtk3.h:46 +#: source/libublsettingsui-gtk3.h:57 msgid "Cancel" msgstr "" -#: source/libublsettingsui-gtk3.h:47 +#: source/libublsettingsui-gtk3.h:58 msgid "Accept" msgstr "" -#: source/libublsettingsui-gtk3.h:49 +#: source/libublsettingsui-gtk3.h:59 +msgid "Open" +msgstr "" + +#: source/libublsettingsui-gtk3.h:61 msgid "Would you like to read documentation in the Web?" msgstr "" -#: source/libublsettingsui-gtk3.h:50 +#: source/libublsettingsui-gtk3.h:62 msgid "" "You will be redirected to documentation website where documentation is\n" "translated and supported by community." msgstr "" -#: source/libublsettingsui-gtk3.h:51 +#: source/libublsettingsui-gtk3.h:63 msgid "Always redirect to online documentation" msgstr "" -#: source/libublsettingsui-gtk3.h:52 +#: source/libublsettingsui-gtk3.h:64 msgid "Open documentation" msgstr "" -#: source/libublsettingsui-gtk3.h:53 +#: source/libublsettingsui-gtk3.h:65 msgid "Project Home Page" msgstr "" -#: source/libublsettingsui-gtk3.h:54 +#: source/libublsettingsui-gtk3.h:66 msgid "Nothing were chosen" msgstr "" -#: source/libublsettingsui-gtk3.h:55 +#: source/libublsettingsui-gtk3.h:67 msgid "Copyright © 2022 - 2023, UBSoft LLC" msgstr "" -#: source/libublsettingsui-gtk3.h:58 +#: source/libublsettingsui-gtk3.h:70 msgid "Global configuration loading succeeded." msgstr "" -#: source/libublsettingsui-gtk3.h:59 +#: source/libublsettingsui-gtk3.h:71 msgid "Local configuration loading succeeded." msgstr "" -#: source/libublsettingsui-gtk3.h:60 +#: source/libublsettingsui-gtk3.h:72 msgid "Config loading failed" msgstr "" -#: source/libublsettingsui-gtk3.h:62 +#: source/libublsettingsui-gtk3.h:74 msgid "Local and global configuration saving succeeded." msgstr "" -#: source/libublsettingsui-gtk3.h:63 +#: source/libublsettingsui-gtk3.h:75 msgid "Global configuration saving succeeded." msgstr "" -#: source/libublsettingsui-gtk3.h:64 +#: source/libublsettingsui-gtk3.h:76 msgid "Local configuration saving succeeded." msgstr "" -#: source/libublsettingsui-gtk3.h:66 +#: source/libublsettingsui-gtk3.h:78 msgid "Parameter" msgstr "" -#: source/libublsettingsui-gtk3.h:67 +#: source/libublsettingsui-gtk3.h:79 msgid "Old value" msgstr "" -#: source/libublsettingsui-gtk3.h:68 +#: source/libublsettingsui-gtk3.h:80 msgid "New value" msgstr "" -#: source/libublsettingsui-gtk3.h:69 +#: source/libublsettingsui-gtk3.h:81 msgid "" "Value\n" "(Old/New)" msgstr "" -#: source/libublsettingsui-gtk3.h:71 +#: source/libublsettingsui-gtk3.h:83 msgid "Nothing to save" msgstr "" -#: source/libublsettingsui-gtk3.h:72 +#: source/libublsettingsui-gtk3.h:84 msgid "Saving into local configuration" msgstr "" -#: source/libublsettingsui-gtk3.h:73 +#: source/libublsettingsui-gtk3.h:85 msgid "Saving into global configuration" msgstr "" -#: source/libublsettingsui-gtk3.h:74 +#: source/libublsettingsui-gtk3.h:86 msgid "Saving into global and local configuration" msgstr "" -#: source/libublsettingsui-gtk3.h:79 +#: source/libublsettingsui-gtk3.h:91 msgid "Full saving mode" msgstr "" -#: source/libublsettingsui-gtk3.h:80 +#: source/libublsettingsui-gtk3.h:92 msgid "Saving into module" msgstr "" -#: source/libublsettingsui-gtk3.h:81 +#: source/libublsettingsui-gtk3.h:93 msgid "Sandbox mode" msgstr "" -#: source/libublsettingsui-gtk3.h:82 +#: source/libublsettingsui-gtk3.h:94 msgid "Sandbox with profile saving" msgstr "" -#: source/libublsettingsui-gtk3.h:83 +#: source/libublsettingsui-gtk3.h:95 msgid "HDD sandbox" msgstr "" -#: source/libublsettingsui-gtk3.h:84 +#: source/libublsettingsui-gtk3.h:96 msgid "HDD sandbox with profile saving" msgstr "" diff --git a/libublsettingsui-gtk3_ru.po b/libublsettingsui-gtk3_ru.po index c469ce4..7d37bc0 100644 --- a/libublsettingsui-gtk3_ru.po +++ b/libublsettingsui-gtk3_ru.po @@ -17,11 +17,63 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -#: source/libublsettingsui-gtk3.h:31 +#: source/libublsettingsui-gtk3.h:34 +msgid "Version:" +msgstr "Версия:" + +#: source/libublsettingsui-gtk3.h:35 +msgid " version:" +msgstr " версия:" + +#: source/libublsettingsui-gtk3.h:35 +msgid "Usage:" +msgstr "Использование:" + +#: source/libublsettingsui-gtk3.h:35 +msgid "[OPTIONS]" +msgstr "[АРГУМЕНТЫ]" + +#: source/libublsettingsui-gtk3.h:35 +msgid "Options:" +msgstr "Аргументы:" + +#: source/libublsettingsui-gtk3.h:35 +msgid "Show this help" +msgstr "Показать эту подсказку" + +#: source/libublsettingsui-gtk3.h:35 +msgid "Show package version" +msgstr "Показать версию пакета" + +#: source/libublsettingsui-gtk3.h:35 +msgid "Lock this help menu" +msgstr "Заблокировать это меню помощи" + +#: source/libublsettingsui-gtk3.h:35 +msgid "Lock configuration saving" +msgstr "Успешно записана локальная конфигурация" + +#: source/libublsettingsui-gtk3.h:35 +msgid "Lock local configration saving" +msgstr "Заблокировать сохранение локальной конфигурации" + +#: source/libublsettingsui-gtk3.h:35 +msgid "Lock global configration saving" +msgstr "Заблокировать сохранение глобальной конфигурации" + +#: source/libublsettingsui-gtk3.h:35 +msgid "Lock global configration loading" +msgstr "Заблокировать загрузку глобальную конфигурацию" + +#: source/libublsettingsui-gtk3.h:35 +msgid "Reset application settings" +msgstr "Сбросить настройки программы" + +#: source/libublsettingsui-gtk3.h:40 msgid "Operation succeeded" msgstr "Операция завершена" -#: source/libublsettingsui-gtk3.h:32 +#: source/libublsettingsui-gtk3.h:41 msgid "" "Warning! Application was launched without root - root-dependent actions are " "locked" @@ -29,55 +81,67 @@ msgstr "" "Внимание! Приложение было запущено без прав суперпользователя - действия, " "требующие их наличия заблокированы" -#: source/libublsettingsui-gtk3.h:34 +#: source/libublsettingsui-gtk3.h:43 msgid "About" msgstr "О программе" -#: source/libublsettingsui-gtk3.h:35 +#: source/libublsettingsui-gtk3.h:44 msgid "Documentation" msgstr "Справка" -#: source/libublsettingsui-gtk3.h:37 +#: source/libublsettingsui-gtk3.h:46 +msgid "Save to specific file" +msgstr "Сохранить в файл" + +#: source/libublsettingsui-gtk3.h:47 msgid "Save to local configuration" msgstr "Сохранить в локальную конфигурацию" -#: source/libublsettingsui-gtk3.h:38 +#: source/libublsettingsui-gtk3.h:48 msgid "Save to global configuration" msgstr "Сохранить в глобальную конфигурацию" -#: source/libublsettingsui-gtk3.h:39 +#: source/libublsettingsui-gtk3.h:49 msgid "Save configuration" msgstr "Сохранить конфигурацию" -#: source/libublsettingsui-gtk3.h:40 +#: source/libublsettingsui-gtk3.h:50 msgid "Save" msgstr "Сохранить" -#: source/libublsettingsui-gtk3.h:42 +#: source/libublsettingsui-gtk3.h:52 +msgid "Load from specific file" +msgstr "Загрузить из файла" + +#: source/libublsettingsui-gtk3.h:53 msgid "Load local configuration" msgstr "Загрузить локальную конфигурацию" -#: source/libublsettingsui-gtk3.h:43 +#: source/libublsettingsui-gtk3.h:54 msgid "Load global configuration" msgstr "Загрузить глобальную конфигурацию" -#: source/libublsettingsui-gtk3.h:44 +#: source/libublsettingsui-gtk3.h:55 msgid "Load" msgstr "Загрузить" -#: source/libublsettingsui-gtk3.h:46 +#: source/libublsettingsui-gtk3.h:57 msgid "Cancel" msgstr "Отмена" -#: source/libublsettingsui-gtk3.h:47 +#: source/libublsettingsui-gtk3.h:58 msgid "Accept" msgstr "Принять" -#: source/libublsettingsui-gtk3.h:49 +#: source/libublsettingsui-gtk3.h:59 +msgid "Open" +msgstr "Открыть" + +#: source/libublsettingsui-gtk3.h:61 msgid "Would you like to read documentation in the Web?" msgstr "Вы хотите прочитать справку в Сети?" -#: source/libublsettingsui-gtk3.h:50 +#: source/libublsettingsui-gtk3.h:62 msgid "" "You will be redirected to documentation website where documentation is\n" "translated and supported by community." @@ -85,63 +149,63 @@ msgstr "" "Вы будете перенаправлены на сайт с документацией, где страницы помощи\n" "переводятся и поддерживаются сообществом." -#: source/libublsettingsui-gtk3.h:51 +#: source/libublsettingsui-gtk3.h:63 msgid "Always redirect to online documentation" msgstr "Всегда перенаправлять" -#: source/libublsettingsui-gtk3.h:52 +#: source/libublsettingsui-gtk3.h:64 msgid "Open documentation" msgstr "Прочитать справку" -#: source/libublsettingsui-gtk3.h:53 +#: source/libublsettingsui-gtk3.h:65 msgid "Project Home Page" msgstr "Домашняя страница проекта" -#: source/libublsettingsui-gtk3.h:54 +#: source/libublsettingsui-gtk3.h:66 msgid "Nothing were chosen" msgstr "Ничего не было выбрано" -#: source/libublsettingsui-gtk3.h:55 +#: source/libublsettingsui-gtk3.h:67 msgid "Copyright © 2022 - 2023, UBSoft LLC" msgstr "Copyright © 2022 - 2023, ООО «Юбисофт»" -#: source/libublsettingsui-gtk3.h:58 +#: source/libublsettingsui-gtk3.h:70 msgid "Global configuration loading succeeded." msgstr "Успешно загружена глобальная конфигурация" -#: source/libublsettingsui-gtk3.h:59 +#: source/libublsettingsui-gtk3.h:71 msgid "Local configuration loading succeeded." msgstr "Успешно загружена локальная конфигурация" -#: source/libublsettingsui-gtk3.h:60 +#: source/libublsettingsui-gtk3.h:72 msgid "Config loading failed" msgstr "Ошибка загрузки конфига" -#: source/libublsettingsui-gtk3.h:62 +#: source/libublsettingsui-gtk3.h:74 msgid "Local and global configuration saving succeeded." msgstr "Успешно записаны локальная и глобальная конфигурация" -#: source/libublsettingsui-gtk3.h:63 +#: source/libublsettingsui-gtk3.h:75 msgid "Global configuration saving succeeded." msgstr "Успешно записана глобальная конфигурация" -#: source/libublsettingsui-gtk3.h:64 +#: source/libublsettingsui-gtk3.h:76 msgid "Local configuration saving succeeded." msgstr "Успешно записана локальная конфигурация" -#: source/libublsettingsui-gtk3.h:66 +#: source/libublsettingsui-gtk3.h:78 msgid "Parameter" msgstr "Параметр" -#: source/libublsettingsui-gtk3.h:67 +#: source/libublsettingsui-gtk3.h:79 msgid "Old value" msgstr "Старое значение" -#: source/libublsettingsui-gtk3.h:68 +#: source/libublsettingsui-gtk3.h:80 msgid "New value" msgstr "Новое значение" -#: source/libublsettingsui-gtk3.h:69 +#: source/libublsettingsui-gtk3.h:81 msgid "" "Value\n" "(Old/New)" @@ -149,42 +213,42 @@ msgstr "" "Значение\n" "(Старое/Новое)" -#: source/libublsettingsui-gtk3.h:71 +#: source/libublsettingsui-gtk3.h:83 msgid "Nothing to save" msgstr "Нечего сохранять" -#: source/libublsettingsui-gtk3.h:72 +#: source/libublsettingsui-gtk3.h:84 msgid "Saving into local configuration" msgstr "Сохранение в локальный конфигурационный файл" -#: source/libublsettingsui-gtk3.h:73 +#: source/libublsettingsui-gtk3.h:85 msgid "Saving into global configuration" msgstr "Сохранение в глобальный конфигурационный файл" -#: source/libublsettingsui-gtk3.h:74 +#: source/libublsettingsui-gtk3.h:86 msgid "Saving into global and local configuration" msgstr "Сохранение в глобальный и локальный конфигурационный файл" -#: source/libublsettingsui-gtk3.h:79 +#: source/libublsettingsui-gtk3.h:91 msgid "Full saving mode" msgstr "Полное сохранение" -#: source/libublsettingsui-gtk3.h:80 +#: source/libublsettingsui-gtk3.h:92 msgid "Saving into module" msgstr "Сохранение в модуль" -#: source/libublsettingsui-gtk3.h:81 +#: source/libublsettingsui-gtk3.h:93 msgid "Sandbox mode" msgstr "Полная песочница в ОЗУ" -#: source/libublsettingsui-gtk3.h:82 +#: source/libublsettingsui-gtk3.h:94 msgid "Sandbox with profile saving" msgstr "Песочница с сохранением профиля пользователя" -#: source/libublsettingsui-gtk3.h:83 +#: source/libublsettingsui-gtk3.h:95 msgid "HDD sandbox" msgstr "Полная песочница на HDD" -#: source/libublsettingsui-gtk3.h:84 +#: source/libublsettingsui-gtk3.h:96 msgid "HDD sandbox with profile saving" msgstr "Полная песочница на HDD с сохранением профиля пользователя" diff --git a/source/libublsettingsui-gtk3.c b/source/libublsettingsui-gtk3.c index 8426de4..1e4b239 100644 --- a/source/libublsettingsui-gtk3.c +++ b/source/libublsettingsui-gtk3.c @@ -185,7 +185,9 @@ void on_save_parameters(GtkWidget *self, template_saving_window *window){ yon_char_parsed_prepend_strings(commands,size,ubconfig_dull_command); } yon_char_parsed_prepend_strings(commands,size,ubconfig_set_command(target)); - } else return; + } else { + yon_char_parsed_prepend_strings(commands,size,ubconfig_set_command(window->custom_save_path)); + } char *final_command = yon_char_parsed_to_string(commands,size,";"); FILE *file = popen(final_command,"r"); int file_save; @@ -265,10 +267,40 @@ template_saving_window *yon_save_proceed(char *path,YON_CONFIG_TYPE type, ...){ va_start(args,type); char *compare_command=""; char *cur_command; + if (!path&&type == YON_CONFIG_CUSTOM){ + GtkWidget *dialog = gtk_file_chooser_dialog_new(template_app_information.app_title,NULL,GTK_FILE_CHOOSER_ACTION_SAVE,CANCEL_LABEL,GTK_RESPONSE_CANCEL,SAVE_LABEL,GTK_RESPONSE_ACCEPT,NULL); + GtkFileFilter *filter = gtk_file_filter_new(); + gtk_file_filter_add_pattern(filter,"*.ini"); + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog),filter); + int response = gtk_dialog_run(GTK_DIALOG(dialog)); + if (response == GTK_RESPONSE_ACCEPT){ + char *file = yon_file_path_proceed_spaces(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog))); + char *directory = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(dialog)); + if (!yon_char_is_empty(file)){ + if (!strstr(file,".ini")) file = yon_char_append(file,".ini"); + if (access(file,0)!=F_OK){ + FILE *source_file = fopen("/lib/ublinux/templates/ublinux-data.ini","r"); + FILE *dest_file = fopen(file,"w"); + int ch; + while ((ch = fgetc(source_file)) != EOF) { + fputc(ch, dest_file); + } + } + } + path = file; + gtk_widget_destroy(dialog); + } else { + gtk_widget_destroy(dialog); + return NULL; + } + } while ((cur_command=va_arg(args,char*))){ + char *temp=cur_command; + cur_command = yon_config_parameter_prepare_command(cur_command,type!=YON_CONFIG_CUSTOM?yon_config_get_type_path(type):path,NULL,NULL); compare_command = yon_char_unite(compare_command,!yon_char_is_empty(compare_command)?";":"",cur_command,NULL); + free(temp); } - config_compare = yon_config_get_compared(compare_command,&compare_size); /////////////////////////////////////////////// + config_compare = yon_config_get_compared(compare_command,&compare_size); GtkBuilder *builder = gtk_builder_new_from_resource(ui_glade_path_saving); template_saving_window *window = malloc(sizeof(template_saving_window)); @@ -287,6 +319,7 @@ template_saving_window *yon_save_proceed(char *path,YON_CONFIG_TYPE type, ...){ window->NewValueCell = GTK_CELL_RENDERER(gtk_builder_get_object(builder,"NewValueCell")); window->type=type; window->filteredModel = GTK_TREE_MODEL(gtk_builder_get_object(builder,"listfilter1")); + window->custom_save_path=path; yon_window_config_custom_window_setup(GTK_WINDOW(window->Window),"SaveWindow"); gtk_window_set_icon_name(GTK_WINDOW(window->Window),yon_char_append("com.ublinux.",template_app_information.app_tech_name)); gtk_window_set_title(GTK_WINDOW(window->Window),template_app_information.app_title); @@ -337,21 +370,23 @@ template_saving_window *yon_save_proceed(char *path,YON_CONFIG_TYPE type, ...){ free(compare_string); } } - for_dictionaries(current,config_compare){ - GtkTreeIter iter; - dictionary *dict = yon_dictionary_get((dictionary**)¤t_loaded,current->key); - if (!dict){ - GdkRGBA rgba; - rgba.alpha=0.8; - rgba.red=1; - rgba.blue=0.3; - rgba.green=0.65; - char *rgba_string = gdk_rgba_to_string(&rgba); - int status=0; - char *compare_string = yon_char_unite((char*)current->data,"\n",NULL); - gtk_list_store_append(window->list,&iter); - gtk_list_store_set(window->list,&iter,0,0,1,current->key,3,(char*)current->data,4,compare_string,5,rgba_string,6,1,-1); - free(compare_string); + if (config_compare){ + for_dictionaries(current,config_compare){ + GtkTreeIter iter; + dictionary *dict = yon_dictionary_get((dictionary**)¤t_loaded,current->key); + if (!dict){ + GdkRGBA rgba; + rgba.alpha=0.8; + rgba.red=1; + rgba.blue=0.3; + rgba.green=0.65; + char *rgba_string = gdk_rgba_to_string(&rgba); + int status=0; + char *compare_string = yon_char_unite((char*)current->data,"\n",NULL); + gtk_list_store_append(window->list,&iter); + gtk_list_store_set(window->list,&iter,0,0,1,current->key,3,(char*)current->data,4,compare_string,5,rgba_string,6,1,-1); + free(compare_string); + } } } GtkTreeIter iter; @@ -454,10 +489,12 @@ template_main_window *setup_window(){ widgets->SaveMenuItem = yon_gtk_builder_get_widget(builder,"SaveGlobalLocalConfigurationMenuItem"); widgets->SaveGlobalMenuItem = yon_gtk_builder_get_widget(builder,"SaveGlobalConfigurationMenuItem"); widgets->SaveLocalMenuItem = yon_gtk_builder_get_widget(builder,"SaveLocalConfigurationMenuItem"); + widgets->SaveCustomMenuItem = yon_gtk_builder_get_widget(builder,"SaveExternalConfigurationMenuItem"); widgets->RightBox = yon_gtk_builder_get_widget(builder,"HeaderRightBox"); widgets->LoadGlobalMenuItem = yon_gtk_builder_get_widget(builder,"LoadGlobalConfigurationMenuItem"); widgets->LoadLocalMenuItem = yon_gtk_builder_get_widget(builder,"LoadLocalConfigurationMenuItem"); + widgets->LoadCustomMenuItem = yon_gtk_builder_get_widget(builder,"LoadExternalConfigurationMenuItem"); widgets->LeftBox = yon_gtk_builder_get_widget(builder,"HeaderLeftBox"); widgets->InterfaceBox = yon_gtk_builder_get_widget(builder,"InterfaceBox"); diff --git a/source/libublsettingsui-gtk3.h b/source/libublsettingsui-gtk3.h index cbfdd7b..bcb82b0 100644 --- a/source/libublsettingsui-gtk3.h +++ b/source/libublsettingsui-gtk3.h @@ -43,17 +43,20 @@ #define ABOUT_LABEL _("About") #define DOCUMENTATION_LABEL _("Documentation") + #define SAVE_CUSTOM_LABEL _("Save to specific file") #define SAVE_LOCAL_LABEL _("Save to local configuration") #define SAVE_GLOBAL_LABEL _("Save to global configuration") #define SAVE_CONFIGURATION_LABEL _("Save configuration") #define SAVE_LABEL _("Save") + #define LOAD_CUSTOM_LABEL _("Load from specific file") #define LOAD_LOCAL_LABEL _("Load local configuration") #define LOAD_GLOBAL_LABEL _("Load global configuration") #define LOAD_LABEL _("Load") #define CANCEL_LABEL _("Cancel") #define ACCEPT_LABEL _("Accept") + #define OPEN_LABEL _("Open") #define HELP_TITLE_LABEL _("Would you like to read documentation in the Web?") #define HELP_INFO_LABEL _("You will be redirected to documentation website where documentation is\ntranslated and supported by community.") @@ -127,51 +130,60 @@ typedef struct { } template_app_info; static template_app_info template_app_information; -typedef struct { - int socket_id; - int load_socket_id; - int save_socket_id; - - int lock_help; - int lock_save_local; - int lock_save_global; - int lock_load_global; - int lock_load_system; - int load_mode; +#define template_config_fields\ + int socket_id;\ + int load_socket_id;\ + int save_socket_id;\ + \ + int lock_help;\ + int lock_save_local;\ + int lock_save_global;\ + int lock_load_global;\ + int lock_load_system;\ +\ + int load_mode;\ +\ + int always_open_documentation;\ - int always_open_documentation; +typedef struct { + template_config_fields } _template_config; static _template_config *template_config; +#define template_window_fields\ + GtkWidget *Window;\ + GtkWidget *HeadLabel;\ + GtkWidget *PlugBox;\ +\ + GtkWidget *HeadOverlay;\ + GtkWidget *HeadImage;\ + GtkWidget *HeadBox;\ + GtkWidget *HeadTitleLabel;\ + GtkWidget *HeadInfoLabel;\ +\ + GtkWidget *StatusBox;\ + GtkWidget *StatusIcon;\ + GtkWidget *StatusLabel;\ +\ + GtkWidget *SaveMenuItem;\ + GtkWidget *SaveGlobalMenuItem;\ + GtkWidget *SaveLocalMenuItem;\ + GtkWidget *SaveCustomMenuItem;\ + GtkWidget *RightBox;\ +\ + GtkWidget *LoadGlobalMenuItem;\ + GtkWidget *LoadLocalMenuItem;\ + GtkWidget *LoadCustomMenuItem;\ + GtkWidget *LeftBox;\ +\ + GtkWidget *DocumentationMenuItem;\ + GtkWidget *AboutMenuItem;\ +\ + GtkWidget *InterfaceBox;\ + //} typedef struct { - GtkWidget *Window; - GtkWidget *HeadLabel; - GtkWidget *PlugBox; - - GtkWidget *HeadOverlay; - GtkWidget *HeadImage; - GtkWidget *HeadBox; - GtkWidget *HeadTitleLabel; - GtkWidget *HeadInfoLabel; - - GtkWidget *StatusBox; - GtkWidget *StatusIcon; - GtkWidget *StatusLabel; - - GtkWidget *SaveMenuItem; - GtkWidget *SaveGlobalMenuItem; - GtkWidget *SaveLocalMenuItem; - GtkWidget *RightBox; - - GtkWidget *LoadGlobalMenuItem; - GtkWidget *LoadLocalMenuItem; - GtkWidget *LeftBox; - - GtkWidget *DocumentationMenuItem; - GtkWidget *AboutMenuItem; - - GtkWidget *InterfaceBox; + template_window_fields } template_main_window; @@ -201,6 +213,7 @@ typedef struct { GtkTreeViewColumn *NewValueColumn; GtkCellRenderer *NewValueCell; YON_CONFIG_TYPE type; + char *custom_save_path; } template_saving_window; typedef struct { From 3896355b7a44a04806fa4d98d5c14cf490b8ecc5 Mon Sep 17 00:00:00 2001 From: Ivan Yarcev Date: Mon, 11 Mar 2024 17:58:57 +0600 Subject: [PATCH 03/10] Changed homepage on about menu --- libublsettingsui-gtk3-about.glade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libublsettingsui-gtk3-about.glade b/libublsettingsui-gtk3-about.glade index d7bf64d..b220563 100644 --- a/libublsettingsui-gtk3-about.glade +++ b/libublsettingsui-gtk3-about.glade @@ -14,7 +14,7 @@ 1.1 Copyright © 2022 - 2023, UBSoft LLC TEMPLATE Manager - https://wiki.ublinux.ru/ru/Программное_обеспечение/Программы_и_утилиты/Все/libublsettingsui-gtk3 + https://wiki.ublinux.ru/ Project Home Page Это приложение распространяется без каких-либо гарантий. Подробнее в <a href="https://www.gnu.org/licenses/old-licenses/gpl-2.0.html">GNU General Public License, версии 2 или позднее</a>. From bc2e0990d42bd75726d85f77391015ca6c289515 Mon Sep 17 00:00:00 2001 From: Ivan Yarcev Date: Tue, 12 Mar 2024 10:15:09 +0600 Subject: [PATCH 04/10] Fixed about window link --- libublsettingsui-gtk3-about.glade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libublsettingsui-gtk3-about.glade b/libublsettingsui-gtk3-about.glade index b220563..b2e2765 100644 --- a/libublsettingsui-gtk3-about.glade +++ b/libublsettingsui-gtk3-about.glade @@ -14,7 +14,7 @@ 1.1 Copyright © 2022 - 2023, UBSoft LLC TEMPLATE Manager - https://wiki.ublinux.ru/ + https://ublinux.ru/ Project Home Page Это приложение распространяется без каких-либо гарантий. Подробнее в <a href="https://www.gnu.org/licenses/old-licenses/gpl-2.0.html">GNU General Public License, версии 2 или позднее</a>. From 2666ab1c1fa26525be938e1274525ae8c7ee1b32 Mon Sep 17 00:00:00 2001 From: Ivan Yarcev Date: Tue, 12 Mar 2024 11:28:00 +0600 Subject: [PATCH 05/10] Added icon name for web window; Fixed saving for both configs --- source/libublsettingsui-gtk3.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/source/libublsettingsui-gtk3.c b/source/libublsettingsui-gtk3.c index 1e4b239..b27e591 100644 --- a/source/libublsettingsui-gtk3.c +++ b/source/libublsettingsui-gtk3.c @@ -53,7 +53,9 @@ void on_subwindow_close(GtkWidget *self){ } void yon_open_browser(GtkWidget *self, char *link){ - yon_ubl_browser_window_open(link,template_app_information.app_title); + GtkWidget *window = yon_ubl_browser_window_open(link,template_app_information.app_title); + if (window) + gtk_window_set_icon_name(GTK_WINDOW(window),yon_char_append("com.ublinux.",template_app_information.app_tech_name)); } void on_open_documentation_confirmation(GtkWidget *self, char *link){ @@ -184,7 +186,9 @@ void on_save_parameters(GtkWidget *self, template_saving_window *window){ if (yon_char_is_empty(target)){ yon_char_parsed_prepend_strings(commands,size,ubconfig_dull_command); } - yon_char_parsed_prepend_strings(commands,size,ubconfig_set_command(target)); + else { + yon_char_parsed_prepend_strings(commands,size,ubconfig_set_command(target)); + } } else { yon_char_parsed_prepend_strings(commands,size,ubconfig_set_command(window->custom_save_path)); } From 3c7bed07046267f875d20a20a4d6dba11e2adb9a Mon Sep 17 00:00:00 2001 From: Ivan Yarcev Date: Tue, 12 Mar 2024 15:13:00 +0600 Subject: [PATCH 06/10] Fixed about window icon --- source/libublsettingsui-gtk3.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source/libublsettingsui-gtk3.c b/source/libublsettingsui-gtk3.c index b27e591..e427795 100644 --- a/source/libublsettingsui-gtk3.c +++ b/source/libublsettingsui-gtk3.c @@ -106,6 +106,7 @@ void on_about(GtkWidget *self, char *version_application){ gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(window),version_application); gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(window),template_app_information.app_title); gtk_about_dialog_set_logo_icon_name(GTK_ABOUT_DIALOG(window),yon_char_append("com.ublinux.",template_app_information.app_tech_name)); + gtk_window_set_icon_name(GTK_WINDOW(window),yon_char_append("com.ublinux.",template_app_information.app_tech_name)); gtk_about_dialog_set_program_name(GTK_ABOUT_DIALOG(window),template_app_information.app_tech_name); gtk_label_set_text(GTK_LABEL(title),template_app_information.app_title); g_signal_connect(G_OBJECT(window),"activate-link",G_CALLBACK(on_link),NULL); From d1b6fef0f9010b15a4e00bd1b8e1f4e34ffdcea0 Mon Sep 17 00:00:00 2001 From: Ivan Yarcev Date: Tue, 12 Mar 2024 15:25:55 +0600 Subject: [PATCH 07/10] Added command output --- source/libublsettingsui-gtk3.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source/libublsettingsui-gtk3.c b/source/libublsettingsui-gtk3.c index e427795..e2ce782 100644 --- a/source/libublsettingsui-gtk3.c +++ b/source/libublsettingsui-gtk3.c @@ -197,6 +197,7 @@ void on_save_parameters(GtkWidget *self, template_saving_window *window){ FILE *file = popen(final_command,"r"); int file_save; config_str file_return = yon_config_load_file(file,&file_save); + yon_char_parsed_append(file_return,&file_save,final_command); if (save_success_function) { save_success_function(save_success_argument,file_return,file_save); From 6ea66195680b2f9864dd301316ecba369c860ed8 Mon Sep 17 00:00:00 2001 From: Ivan Yarcev Date: Tue, 12 Mar 2024 16:48:00 +0600 Subject: [PATCH 08/10] Fixed crash at saving --- source/libublsettingsui-gtk3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libublsettingsui-gtk3.c b/source/libublsettingsui-gtk3.c index e2ce782..5c4b088 100644 --- a/source/libublsettingsui-gtk3.c +++ b/source/libublsettingsui-gtk3.c @@ -197,7 +197,7 @@ void on_save_parameters(GtkWidget *self, template_saving_window *window){ FILE *file = popen(final_command,"r"); int file_save; config_str file_return = yon_config_load_file(file,&file_save); - yon_char_parsed_append(file_return,&file_save,final_command); + file_return = yon_char_parsed_append(file_return,&file_save,final_command); if (save_success_function) { save_success_function(save_success_argument,file_return,file_save); From f2bfcfa5ba55e6dd0b38f032a1affbcf65835f8d Mon Sep 17 00:00:00 2001 From: Ivan Yarcev Date: Wed, 13 Mar 2024 12:20:41 +0600 Subject: [PATCH 09/10] Changed new config file creation method --- source/libublsettingsui-gtk3.c | 10 +++++----- source/libublsettingsui-gtk3.h | 3 +++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/source/libublsettingsui-gtk3.c b/source/libublsettingsui-gtk3.c index 5c4b088..4ee9e2d 100644 --- a/source/libublsettingsui-gtk3.c +++ b/source/libublsettingsui-gtk3.c @@ -285,11 +285,11 @@ template_saving_window *yon_save_proceed(char *path,YON_CONFIG_TYPE type, ...){ if (!yon_char_is_empty(file)){ if (!strstr(file,".ini")) file = yon_char_append(file,".ini"); if (access(file,0)!=F_OK){ - FILE *source_file = fopen("/lib/ublinux/templates/ublinux-data.ini","r"); - FILE *dest_file = fopen(file,"w"); - int ch; - while ((ch = fgetc(source_file)) != EOF) { - fputc(ch, dest_file); + char *command_creation = ubconfig_file_create(file); + system(command_creation); + if (access(file,0)!=F_OK){ + yon_ubl_status_box_render(CUSTOM_CONFIG_CREATION_ERROR_LABEL,BACKGROUND_IMAGE_FAIL_TYPE); + return NULL; } } } diff --git a/source/libublsettingsui-gtk3.h b/source/libublsettingsui-gtk3.h index bcb82b0..f41eb58 100644 --- a/source/libublsettingsui-gtk3.h +++ b/source/libublsettingsui-gtk3.h @@ -94,12 +94,15 @@ #define SAVE_MODE_RAM_HOME_LABEL _("Sandbox with profile saving") #define SAVE_MODE_HDD_LABEL _("HDD sandbox") #define SAVE_MODE_HDD_HOME_LABEL _("HDD sandbox with profile saving") + #define CUSTOM_CONFIG_CREATION_ERROR_LABEL _("New configuration file creation failed") #endif #define dull_parameter_get_command "ubconfig --source global get users PARAMETER" #define SAVE_MODE_GET_COMMAND "ubconfig --raw --source system get [config] SYSTEMBOOT_STATEMODE" +#define ubconfig_file_create(target) yon_char_unite("ubconfig --target \"",target,"\" create",NULL) + typedef enum SAVE_MODE_TYPE { SAVE_MODE_FULL, SAVE_MODE_MODULE, From c65d78a1381c9f4d10463c543c4411c25b98e164 Mon Sep 17 00:00:00 2001 From: Ivan Yarcev Date: Thu, 14 Mar 2024 14:34:03 +0600 Subject: [PATCH 10/10] Fixed rendering of missing saving parameters --- source/libublsettingsui-gtk3.c | 92 +++++++++++++++++----------------- 1 file changed, 47 insertions(+), 45 deletions(-) diff --git a/source/libublsettingsui-gtk3.c b/source/libublsettingsui-gtk3.c index 4ee9e2d..c16c2c4 100644 --- a/source/libublsettingsui-gtk3.c +++ b/source/libublsettingsui-gtk3.c @@ -352,61 +352,63 @@ template_saving_window *yon_save_proceed(char *path,YON_CONFIG_TYPE type, ...){ struct loaded_config *current_loaded = yon_config_convert_parameter(current_config,current_size); struct loaded_config *current = NULL; - for_dictionaries(current,current_loaded){ - dictionary *dict = yon_dictionary_get((dictionary**)&config_compare,current->key); - gboolean status=0; - status = yon_config_get_status(current->key); - if (dict&&!yon_char_is_empty((char*)dict->data)&&status!=-2){ - if (strcmp((char*)dict->data,(char*)current->data)){ + if (current_loaded){ + for_dictionaries(current,current_loaded){ + dictionary *dict = yon_dictionary_get((dictionary**)&config_compare,current->key); + gboolean status=0; + status = yon_config_get_status(current->key); + if (dict&&!yon_char_is_empty((char*)dict->data)&&status!=-2){ + if (strcmp((char*)dict->data,(char*)current->data)){ + GtkTreeIter iter; + if (status==0||status==-2) status = 0; + else status=1; + char *compare_string = yon_char_unite("",(char*)dict->data,"\n",(char*)current->data,NULL); + gtk_list_store_append(window->list,&iter); + gtk_list_store_set(window->list,&iter,0,status,1,current->key,2,(char*)dict->data,3,(char*)current->data,4,compare_string,6,1,-1); + free(compare_string); + } + } else if ((strcmp((char*)current->data,""))&&status!=-2){ GtkTreeIter iter; if (status==0||status==-2) status = 0; else status=1; - char *compare_string = yon_char_unite("",(char*)dict->data,"\n",(char*)current->data,NULL); + char *compare_string = yon_char_unite("\n",(char*)current->data,NULL); gtk_list_store_append(window->list,&iter); - gtk_list_store_set(window->list,&iter,0,status,1,current->key,2,(char*)dict->data,3,(char*)current->data,4,compare_string,6,1,-1); + gtk_list_store_set(window->list,&iter,0,status,1,current->key,3,(char*)current->data,4,compare_string,6,1,-1); free(compare_string); } - } else if ((strcmp((char*)current->data,""))&&status!=-2){ - GtkTreeIter iter; - if (status==0||status==-2) status = 0; - else status=1; - char *compare_string = yon_char_unite("\n",(char*)current->data,NULL); - gtk_list_store_append(window->list,&iter); - gtk_list_store_set(window->list,&iter,0,status,1,current->key,3,(char*)current->data,4,compare_string,6,1,-1); - free(compare_string); } - } - if (config_compare){ - for_dictionaries(current,config_compare){ - GtkTreeIter iter; - dictionary *dict = yon_dictionary_get((dictionary**)¤t_loaded,current->key); - if (!dict){ - GdkRGBA rgba; - rgba.alpha=0.8; - rgba.red=1; - rgba.blue=0.3; - rgba.green=0.65; - char *rgba_string = gdk_rgba_to_string(&rgba); - int status=0; - char *compare_string = yon_char_unite((char*)current->data,"\n",NULL); - gtk_list_store_append(window->list,&iter); - gtk_list_store_set(window->list,&iter,0,0,1,current->key,3,(char*)current->data,4,compare_string,5,rgba_string,6,1,-1); - free(compare_string); + if (config_compare){ + for_dictionaries(current,config_compare){ + GtkTreeIter iter; + dictionary *dict = yon_dictionary_get((dictionary**)¤t_loaded,current->key); + if (!dict){ + GdkRGBA rgba; + rgba.alpha=0.8; + rgba.red=1; + rgba.blue=0.3; + rgba.green=0.65; + char *rgba_string = gdk_rgba_to_string(&rgba); + int status=0; + char *compare_string = yon_char_unite((char*)current->data,"\n",NULL); + gtk_list_store_append(window->list,&iter); + gtk_list_store_set(window->list,&iter,0,0,1,current->key,2,(char*)current->data,4,compare_string,5,rgba_string,6,1,-1); + free(compare_string); + } } } } - GtkTreeIter iter; - if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(window->list),&iter)){ - gtk_widget_destroy(window->Window); - textdomain(template_ui_LocaleName); - yon_ubl_status_box_render(NOTHING_TO_SAVE_LABEL,BACKGROUND_IMAGE_FAIL_TYPE); - textdomain(template_app_information.app_locale); - return NULL; - } - gtk_tree_view_set_model(GTK_TREE_VIEW(window->ParametersTree),GTK_TREE_MODEL(window->list)); - gtk_widget_show(window->Window); - on_save_window_parameter_switched(NULL,NULL,window); - return window; + GtkTreeIter iter; + if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(window->list),&iter)){ + gtk_widget_destroy(window->Window); + textdomain(template_ui_LocaleName); + yon_ubl_status_box_render(NOTHING_TO_SAVE_LABEL,BACKGROUND_IMAGE_FAIL_TYPE); + textdomain(template_app_information.app_locale); + return NULL; + } + gtk_tree_view_set_model(GTK_TREE_VIEW(window->ParametersTree),GTK_TREE_MODEL(window->list)); + gtk_widget_show(window->Window); + on_save_window_parameter_switched(NULL,NULL,window); + return window; } int yon_confirmation_dialog_call(GtkWidget *self,dialog_confirmation_data *data){