|
|
|
|
@ -69,20 +69,207 @@ void on_about(GtkWidget *self, char *version_application){
|
|
|
|
|
|
|
|
|
|
//functions
|
|
|
|
|
|
|
|
|
|
int yon_load_proceed(YON_CONFIG_TYPE type){
|
|
|
|
|
// if (yon_config_load_register(type,"logging",,"logging",JOURNALD("*"),NULL)){
|
|
|
|
|
// update_loaded_logrotate();
|
|
|
|
|
// return 1;
|
|
|
|
|
// }
|
|
|
|
|
void on_save_window_parameter_switched(GtkCellRendererToggle *self, gchar *path, template_saving_window *window){
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
if (gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(window->list),&iter,path)){
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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,"\"",NULL));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
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);
|
|
|
|
|
system(final_command);
|
|
|
|
|
free(final_command);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
on_subwindow_close(self);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void 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)))
|
|
|
|
|
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);
|
|
|
|
|
else{
|
|
|
|
|
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";
|
|
|
|
|
yon_config_save_registered("system");
|
|
|
|
|
} else if (template_config->load_mode==0){
|
|
|
|
|
config_to_save="system";
|
|
|
|
|
yon_config_save_registered("global");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
yon_config_set_status(0);
|
|
|
|
|
config_str 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);
|
|
|
|
|
if (final_str[strlen(final_str)-1]=='\n')final_str[strlen(final_str)-1]='\0';
|
|
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
GtkBuilder *builder = gtk_builder_new_from_resource(ui_glade_path_saving);
|
|
|
|
|
GtkWidget *window = yon_gtk_builder_get_widget(builder,"MainWindow");
|
|
|
|
|
gtk_widget_show(window);
|
|
|
|
|
template_saving_window *window = malloc(sizeof(template_saving_window));
|
|
|
|
|
window->Window = yon_gtk_builder_get_widget(builder,"Window");
|
|
|
|
|
window->HeaderImage = yon_gtk_builder_get_widget(builder,"HeaderImage");
|
|
|
|
|
window->HeaderTopic = yon_gtk_builder_get_widget(builder,"HeaderTopic");
|
|
|
|
|
window->StatusBox = yon_gtk_builder_get_widget(builder,"StatusBox");
|
|
|
|
|
window->ParametersTree = yon_gtk_builder_get_widget(builder,"ParametersTree");
|
|
|
|
|
window->SaveButton = yon_gtk_builder_get_widget(builder,"SaveButton");
|
|
|
|
|
window->CancelButton = yon_gtk_builder_get_widget(builder,"CancelButton");
|
|
|
|
|
window->ToggleCell = GTK_CELL_RENDERER(gtk_builder_get_object(builder,"ToggleCell"));
|
|
|
|
|
window->list = GTK_LIST_STORE(gtk_builder_get_object(builder,"liststore1"));
|
|
|
|
|
window->type=type;
|
|
|
|
|
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){
|
|
|
|
|
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;i<compare_keys_size;i++){
|
|
|
|
|
gtk_list_store_append(window->list,&iter);
|
|
|
|
|
gtk_list_store_set(window->list,&iter,0,1,1,compare_keys[i],5,1,-1);
|
|
|
|
|
for (int j=0;j<compare_size;j++){
|
|
|
|
|
if(config_compare[j][strlen(config_compare[j])-1]=='\n') config_compare[j][strlen(config_compare[j])-1]='\0';
|
|
|
|
|
char *compare_value = yon_char_new(config_compare[j]);
|
|
|
|
|
char *compare_name = yon_char_divide_search(compare_value,"=",-1);
|
|
|
|
|
if (!strcmp(compare_name,compare_keys[i])){
|
|
|
|
|
char *cur_section = (char*)yon_dictionary_get(&loaded.dict->first,compare_keys[i])->prev->data;
|
|
|
|
|
gtk_list_store_set(window->list,&iter,2,compare_value,4,rgba_string,6,cur_section,-1);
|
|
|
|
|
}
|
|
|
|
|
free(compare_value);
|
|
|
|
|
free(compare_name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
char *name,*value;
|
|
|
|
|
for (int i=0;i<config_keys_size;i++){
|
|
|
|
|
int found=0;
|
|
|
|
|
char *compare_value = yon_char_new(config_strings[i]);
|
|
|
|
|
char *compare_name = yon_char_divide_search(compare_value,"=",-1);
|
|
|
|
|
char *section = yon_config_get_section_for_key(compare_name);
|
|
|
|
|
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)){
|
|
|
|
|
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])){
|
|
|
|
|
gtk_list_store_set(window->list,&iter,3,compare_value,4,NULL,6,section,-1);
|
|
|
|
|
if (!strcmp(value,compare_value)){
|
|
|
|
|
gtk_list_store_set(window->list,&iter,0,0,5,0,-1);
|
|
|
|
|
}
|
|
|
|
|
found=1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!found){
|
|
|
|
|
GtkTreeIter itar;
|
|
|
|
|
gtk_list_store_append(window->list,&itar);
|
|
|
|
|
gtk_list_store_set(window->list,&itar,0,1,1,compare_name,3,compare_value,5,1,6,section,-1);
|
|
|
|
|
}
|
|
|
|
|
free(compare_value);
|
|
|
|
|
free(compare_name);
|
|
|
|
|
}
|
|
|
|
|
free(rgba_string);
|
|
|
|
|
|
|
|
|
|
gtk_tree_view_set_model(GTK_TREE_VIEW(window->ParametersTree),GTK_TREE_MODEL(window->list));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gtk_widget_show(window->Window);
|
|
|
|
|
return window;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
@ -183,6 +370,7 @@ template_main_window *yon_ubl_window_setup(){
|
|
|
|
|
else
|
|
|
|
|
yon_ubl_status_box_render(LOCAL_LOAD_SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
|
|
|
|
|
}
|
|
|
|
|
template_config->load_mode=1;
|
|
|
|
|
if(template_config)
|
|
|
|
|
yon_ubl_setup_sockets(widgets->PlugBox,widgets->LeftBox,widgets->RightBox,template_config->socket_id,template_config->load_socket_id,template_config->save_socket_id);
|
|
|
|
|
yon_window_config_setup(GTK_WINDOW(widgets->Window));
|
|
|
|
|
|