Added new window for saving confirmation

pull/80/head
Ivan Yartsev 2 years ago
parent 7e843455e4
commit 5c808943ad

@ -11,6 +11,7 @@
<file>ubl-settings-logging-filechooser.glade</file>
<file>ubl-settings-logging-logrotate-table.glade</file>
<file>ubl-settings-logging-terminal.glade</file>
<file>ubl-settings-logging-saving.glade</file>
</gresource>
<gresource prefix="/com/ublinux/css">
<file>ubl-settings-logging.css</file>

@ -50,6 +50,7 @@ set(DEPENDFILES
../ubl-settings-logging-logrotate-table.glade
../ubl-settings-logging-filechooser.glade
../ubl-settings-logging-terminal.glade
../ubl-settings-logging-saving.glade
../gresource.xml
../ubl-settings-logging-banner.png
../ubl-settings-logging.css

@ -26,6 +26,207 @@ void yon_open_browser(GtkWidget *self, char *link){
yon_ubl_browser_window_open(link,TITLE_LABEL);
}
void on_save_window_parameter_switched(GtkCellRendererToggle *self, gchar *path, 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, saving_window *window){
char *append_command = yon_char_unite("ubconfig --target ",main_config.load_mode==1?"global":"system"," set ",NULL);
char *remove_command = yon_char_unite("ubconfig --target ",main_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,&parameter,2,&old_value,3,&new_value,5,&can_save,6,&section,-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_close_subwindow(self,"SavingWindow");
}
saving_window *yon_save_proceed(char *path,YON_CONFIG_TYPE type, ...){
if (((type==YON_CONFIG_LOCAL&& main_config.load_mode==1)||(type==YON_CONFIG_GLOBAL&& main_config.load_mode==0))){
yon_config_save_registered(path);
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 (main_config.load_mode==1){
config_to_save="global";
yon_config_save_registered("system");
} else if (main_config.load_mode==0){
config_to_save="system";
yon_config_save_registered("global");
}
}
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(glade_saving_path);
saving_window *window = malloc(sizeof(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_title(GTK_WINDOW(window->Window),TITLE_LABEL);
g_signal_connect(G_OBJECT(window->CancelButton),"clicked",G_CALLBACK(on_close_subwindow),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;
}
}
/**on_open_documentation_confirmation(GtkWidget *self, char *link)
* [EN]
* Opens confirmation window for [link] link.
@ -204,35 +405,35 @@ void on_load_local(){
}
void yon_save_proceed(char *path,YON_CONFIG_TYPE type){
if (((type==YON_CONFIG_LOCAL&& main_config.load_mode==1)||(type==YON_CONFIG_GLOBAL&& main_config.load_mode==0)))
yon_config_save_registered(path);
else{
if (type==YON_CONFIG_BOTH)
yon_launch("ubconfig remove logging LOGROTATE[*] JOURNALD[*]");
else if (type==YON_CONFIG_LOCAL)
yon_launch("ubconfig --target system remove logging LOGROTATE[*] JOURNALD[*]");
else if (type==YON_CONFIG_GLOBAL)
yon_launch("ubconfig --target global remove logging LOGROTATE[*] JOURNALD[*]");
yon_config_force_save_registered(path);
}
// void yon_save_proceed(char *path,YON_CONFIG_TYPE type){
// if (((type==YON_CONFIG_LOCAL&& main_config.load_mode==1)||(type==YON_CONFIG_GLOBAL&& main_config.load_mode==0)))
// yon_config_save_registered(path);
// else{
// if (type==YON_CONFIG_BOTH)
// yon_launch("ubconfig remove logging LOGROTATE[*] JOURNALD[*]");
// else if (type==YON_CONFIG_LOCAL)
// yon_launch("ubconfig --target system remove logging LOGROTATE[*] JOURNALD[*]");
// else if (type==YON_CONFIG_GLOBAL)
// yon_launch("ubconfig --target global remove logging LOGROTATE[*] JOURNALD[*]");
// yon_config_force_save_registered(path);
// }
}
// }
void on_save_global_local(){
yon_save_proceed(NULL,YON_CONFIG_BOTH);
yon_save_proceed(NULL,YON_CONFIG_BOTH,"logging", "JOURNALD[*] LOGROTATE[*]",NULL);
yon_ubl_status_box_render(GLOBAL_LOCAL_SAVE_SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
}
void on_save_global(){
yon_save_proceed("global",YON_CONFIG_GLOBAL);
yon_save_proceed("global",YON_CONFIG_GLOBAL,"logging", "JOURNALD[*] LOGROTATE[*]",NULL);
yon_ubl_status_box_render(LOCAL_SAVE_SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
}
void on_save_local(){
yon_save_proceed("system",YON_CONFIG_LOCAL);
yon_save_proceed("system",YON_CONFIG_LOCAL,"logging", "JOURNALD[*] LOGROTATE[*]",NULL);
yon_ubl_status_box_render(GLOBAL_SAVE_SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
}

@ -33,6 +33,7 @@
#define glade_rules_path "/com/ublinux/ui/ubl-settings-logging-rules.glade"
#define glade_filechooser_path "/com/ublinux/ui/ubl-settings-logging-filechooser.glade"
#define glade_terminal_path "/com/ublinux/ui/ubl-settings-logging-terminal.glade"
#define glade_saving_path "/com/ublinux/ui/ubl-settings-logging-saving.glade"
#define banner_path "/com/ublinux/images/ubl-settings-logging-banner.png"
#define CssPath "/com/ublinux/css/ubl-settings-logging.css"
#define config_path yon_char_unite(yon_ubl_user_get_home_directory(),"/.config/",LocaleName,"/",LocaleName,".conf",NULL)
@ -357,4 +358,17 @@ typedef struct {
char *paths;
} logrotate_configure_window;
typedef struct {
GtkWidget *Window;
GtkWidget *HeaderTopic;
GtkWidget *HeaderImage;
GtkWidget *StatusBox;
GtkWidget *ParametersTree;
GtkCellRenderer *ToggleCell;
GtkWidget *CancelButton;
GtkWidget *SaveButton;
GtkListStore *list;
YON_CONFIG_TYPE type;
} saving_window;
main_window *setup_window();

@ -0,0 +1,216 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2 -->
<interface>
<requires lib="gtk+" version="3.24"/>
<!-- interface-css-provider-path ubl-settings-logging.css -->
<object class="GtkCheckButton" id="ToggleAllCheck">
<property name="label" translatable="yes">Save</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">False</property>
<property name="draw-indicator">True</property>
</object>
<object class="GtkImage" id="image1">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="icon-name">process-stop-symbolic</property>
</object>
<object class="GtkImage" id="image2">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="icon-name">emblem-ok-symbolic</property>
</object>
<object class="GtkListStore" id="liststore1">
<columns>
<!-- column-name Active -->
<column type="gboolean"/>
<!-- column-name Parameter -->
<column type="gchararray"/>
<!-- column-name OldValue -->
<column type="gchararray"/>
<!-- column-name NewValue -->
<column type="gchararray"/>
<!-- column-name Color -->
<column type="gchararray"/>
<!-- column-name Show -->
<column type="gboolean"/>
<!-- column-name Section -->
<column type="gchararray"/>
</columns>
</object>
<object class="GtkDialog" id="Window">
<property name="width-request">450</property>
<property name="height-request">500</property>
<property name="can-focus">False</property>
<property name="modal">True</property>
<property name="icon-name">com.ublinux.ubl-settings-logging</property>
<property name="type-hint">dialog</property>
<child internal-child="vbox">
<object class="GtkBox">
<property name="can-focus">False</property>
<property name="margin-bottom">5</property>
<property name="orientation">vertical</property>
<property name="spacing">5</property>
<child internal-child="action_area">
<object class="GtkButtonBox">
<property name="can-focus">False</property>
<property name="layout-style">end</property>
<child>
<object class="GtkButton" id="CancelButton">
<property name="label" translatable="yes">Cancel</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="image">image1</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="SaveButton">
<property name="label" translatable="yes">Save</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="image">image2</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="pack-type">end</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox" id="StatusBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="shadow-type">in</property>
<child>
<object class="GtkTreeView" id="ParametersTree">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="model">liststore1</property>
<child internal-child="selection">
<object class="GtkTreeSelection">
<property name="mode">none</property>
</object>
</child>
<child>
<object class="GtkTreeViewColumn">
<property name="title" translatable="yes">Save</property>
<child>
<object class="GtkCellRendererToggle" id="ToggleCell"/>
<attributes>
<attribute name="cell-background">4</attribute>
<attribute name="sensitive">5</attribute>
<attribute name="active">0</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn">
<property name="title" translatable="yes">Parameter</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="cell-background">4</attribute>
<attribute name="sensitive">5</attribute>
<attribute name="text">1</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn">
<property name="title" translatable="yes">Old value</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="cell-background">4</attribute>
<attribute name="sensitive">5</attribute>
<attribute name="text">2</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn">
<property name="title" translatable="yes">New value</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="cell-background">4</attribute>
<attribute name="sensitive">5</attribute>
<attribute name="text">3</attribute>
</attributes>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
<child type="titlebar">
<object class="GtkHeaderBar">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="show-close-button">True</property>
<child type="title">
<object class="GtkLabel" id="HeaderTopic">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Logs and events</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
</child>
<child>
<object class="GtkImage" id="HeaderImage">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="pixel-size">32</property>
<property name="icon-name">com.ublinux.ubl-settings-logging</property>
</object>
</child>
<style>
<class name="toolbar"/>
</style>
</object>
</child>
</object>
</interface>
Loading…
Cancel
Save