Saving and loading

pull/2/head
Ivan Yartsev 2 years ago
parent 186de985ef
commit 1706867e51

@ -125,11 +125,58 @@ int yon_size_get_int_from_letter(char size){
//functions
void yon_load_proceed(char *command){
yon_ubl_status_box_render(LOCAL_SAVE_SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
int yon_load_proceed(YON_CONFIG_TYPE type){
if (yon_config_load_register(type,"logging",LOGROTATE("*"),JOURNALD("*"),NULL))
return 1;
}
void on_load_global(){
yon_load_proceed(YON_CONFIG_GLOBAL);
main_config.load_mode=0;
yon_ubl_status_box_render(GLOBAL_LOAD_SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
}
void on_load_local(){
yon_load_proceed(YON_CONFIG_LOCAL);
main_config.load_mode=1;
yon_ubl_status_box_render(LOCAL_LOAD_SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
}
void yon_save_proceed(char *path,YON_CONFIG_TYPE type){
if (!path||((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 system LOGROTATE[*] JOURNALD[*]");
else if (type==YON_CONFIG_LOCAL)
yon_launch("ubconfig --target system remove system LOGROTATE[*] JOURNALD[*]");
else if (type==YON_CONFIG_GLOBAL)
yon_launch("ubconfig --target global remove system LOGROTATE[*] JOURNALD[*]");
yon_config_force_save_registered(path);
}
}
void on_save_global_local(){
yon_save_proceed(NULL,YON_CONFIG_BOTH);
yon_ubl_status_box_render(GLOBAL_LOCAL_SAVE_SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
}
void on_save_global(){
yon_save_proceed("system",YON_CONFIG_LOCAL);
yon_ubl_status_box_render(LOCAL_SAVE_SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
}
void on_save_local(){
yon_save_proceed("global",YON_CONFIG_GLOBAL);
yon_ubl_status_box_render(GLOBAL_SAVE_SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
}
// Inspector functions
void on_inspector_update(GtkWidget *self, inspector_window *window){
@ -1562,6 +1609,7 @@ int main(int argc, char *argv[]){
yon_ubl_status_box_render(LOCAL_LOAD_SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
yon_ubl_setup_sockets(widgets->PlugBox,widgets->LeftBox,widgets->RightBox,main_config.socket_id,main_config.load_socket_id,main_config.save_socket_id);
yon_window_config_setup(GTK_WINDOW(widgets->Window));
yon_load_proceed(YON_CONFIG_LOCAL);
yon_window_config_load(config_path);
GtkCssProvider *css=gtk_css_provider_new();
gtk_css_provider_load_from_resource(css,CssPath);

@ -67,6 +67,8 @@ typedef struct {
int lock_save_global;
int lock_load_global;
int load_mode;
GtkListStore *logrotate_list;
GtkListStore *logrotate_apps_list;
} config;
@ -107,6 +109,7 @@ typedef struct {
GtkWidget *AddButton;
GtkWidget *RemoveButton;
GtkWidget *Notebook;
GtkWidget *ServicesTree;
GtkWidget *ServicesEditButton;

@ -83,11 +83,26 @@
#define LOWER_SIZE_LABEL _("Lower size to:")
#define APPLY_LABEL _("Apply")
#define STATISTICS_LABEL _("Statistics")
#define DEFAULT_LABEL _("Default")
#define RAM_LABEL _("RAM")
#define DRIVE_LABEL _("Drive")
#define AUTO_LABEL _("Auto")
#define NONE_LABEL _("None")
#define YES_LABEL _("Yes")
#define NO_LABEL _("No")
#define AFTER_LABEL _("After")
#define KB_LABEL _("Kb")
#define MB_LABEL _("Mb")
#define GB_LABEL _("Gb")
#define MINUTES_LABEL _("Minutes")
#define HOURS_LABEL _("Hours")
#define DAYS_LABEL _("Days")
#define WEEKS_LABEL _("Weeks")
#define YEARS_LABEL _("Years")
//ubl-settings-logging-logrotate.glade
#define LOGROTATE_LOG_JOURNAL_TAB_LABEL _("Log/Journal:")
#define PATHS_LABEL _("Paths to log and journals files")
#define DEFAULT_LABEL _("Default")
#define ON_LABEL _("On")
#define OFF_LABEL _("Off")
#define SCENARIOS_LABEL _("Scenarios")
@ -107,7 +122,7 @@
#define ERROR_LABEL _("Error processing:")
#define ROTATION_EMPTY_LABEL _("Rotation of jurnal even when it is empty:")
#define DONT_ROTATE_YOUNGER_LABEL _("Do not rotate journal younger than")
#define DAYS_LABEL _("days")
#define DAYS_text_LABEL _("days")
#define DELETE_ROTATED_LABEL _("Delete rotated journals older than")
#define ROTATE_SIZE_LABEL _("Rotate journals if size more than")
#define ROTATE_TIME_LABEL _("but not earlier than the specified time interval")
@ -131,6 +146,32 @@
#define MESSAGE_CONFIGURATION_LABEL _("Message configuration")
#define MANUAL_LABEL _("Manual input:")
#define LOG_SIZE_LABEL _("Log (-s) size:")
#define SAME_DIR_LABEL _("Same directory")
#define SEPARATE_DIR_LABEL _("Separate directory")
#define OUTPUT_ERRORS_LABEL _("Output errors if log file does not exist*")
#define NO_OUTPUT_ERRORS_LABEL _("Do not output errors if log file does not exist")
#define NO_OUTPUT_LABEL _("Do not output")
#define OURPUT_LABEL _("Output errors")
#define SEND_EMAIL_LABEL _("Send Email")
#define NO_SEND_EMAIL_LABEL _("Don't send Email")
#define FIRST_ROTATED_LABEL _("First rotated copy")
#define LAST_ROTATED_LABEL _("Last rotated copy")
#define MESSAGE_CONFIGURATION_LABEL _("Message configuration")
#define ENDWORK_LABEL _("Endwork command:")
#define SCENARIOS_ROTATE_LABEL _("Scenarios are running for each rotated journal")
#define SCENARIOS_LABEL _("Scenarios")
#define HOURLY_LABEL _("Hourly")
#define DAILY_LABEL _("Daily")
#define WEEKLY_LABEL _("Weekly*")
#define MONTHLY_LABEL _("Monthly")
#define YEARLY_LABEL _("Yearly")
#define MONDAY_LABEL _("Monday")
#define TUESDAY_LABEL _("Tuesday")
#define WEDNESDAY_LABEL _("Wednesday")
#define THURSDAY_LABEL _("Thursday")
#define FRIDAY_LABEL _("Friday")
#define SATURDAY_LABEL _("Saturday")
#define SUNDAY_LABEL _("Sunday*")
//ubl-settings-logging-logrotate-table.glade
#define SYSTEM_CONFIGURATION_LABEL _("System configuration")

@ -455,9 +455,9 @@ char *yon_char_append(char *source, char *append)
int size = strlen(source) + strlen(append) + 1;
char *final = malloc(size);
memset(final, 0, size);
if (strstr(source, "%%"))
sprintf(final, source, append);
else
// if (strstr(source, "%%"))
// sprintf(final, source, append);
// else
sprintf(final, "%s%s", source, append);
return final;
}
@ -666,10 +666,10 @@ char **yon_char_parse(char *parameters, int *size, char *divider){
char *paramline=yon_char_new(parameters);
char *param;
while ((param=yon_char_divide_search(paramline,divider,1))){
if (strcmp(param,paramline)==0) break;
string=realloc(string,sizeof(char*)*i);
string[i-1]=yon_char_new(param);
i++;
if (strcmp(param,paramline)==0) break;
}
string=realloc(string,sizeof(char*)*i);
string[i-1]=yon_char_new(paramline);
@ -785,7 +785,7 @@ void yon_char_parsed_free(config_str source, int size){
* Копирует массив строк [to_copy] в [source]
*/
void yon_char_parsed_copy(config_str *source, config_str *to_copy){
if (source&&!*source&&to_copy&&*to_copy){
if (source&&!*source&&to_copy){
int size=0;
config_str new_char = yon_char_parsed_new(&size,(*to_copy)[0]);
for (int i=0;(*to_copy)[i];i++){
@ -802,7 +802,7 @@ void yon_char_parsed_copy(config_str *source, config_str *to_copy){
* Добавляет строку [string] в конец массива строк [parsed] с длинной [size].
*/
config_str yon_char_parsed_append(config_str parsed, int *size, char *string){
config_str new_parsed=realloc(parsed,((*size)+2)*sizeof(char*));
config_str new_parsed=realloc(parsed,(*size+1)*sizeof(char*));
new_parsed[(*size)]=yon_char_new(string);
(*size)++;
return new_parsed;
@ -969,18 +969,6 @@ apps *yon_apps_get_by_name(apps *applist, char *name, int size)
return NULL;
};
config_str yon_file_open(char *file_path, int *size){
*size=0;
FILE *file = fopen(file_path,"r");
if (file){
char *str_loaded=malloc(4098);
config_str final_string = NULL;
while (fgets(str_loaded,4098,file)){
final_string = final_string ? yon_char_parsed_append(final_string,size,str_loaded) : yon_char_parsed_new(size,str_loaded,NULL);
}
return final_string;
}
}
/**
* yon_dir_get_contents(char *dir_path, int *size)
@ -1116,26 +1104,6 @@ int yon_config_remove_by_key(char *key){
return 0;
}
/**yon_config_remove_by_data(void *data)
* [EN]
*
* [RU]
* Производит поиск по конфигу на наличие параметра со значением [data] и удаляет найденное значение из конфига.
*/
int yon_config_remove_by_data(void *data){
check_config{
dictionary *dict = NULL;
for_dictionaries(dict,(dictionary*)__yon__config__strings){
if (dict->data==data){
yon_dictionary_rip(dict);
return 1;
}
}
return 0;
}
return 0;
}
/**yon_config_remove_element(char *key, char *deleted)
* [EN]
*
@ -1331,12 +1299,50 @@ int yon_config_save_registered(char *path){
if (dct->data&&strcmp(yon_dictionary_get_data(dct,char*),"")!=0){
if (((yon_config_parameter*)dct)->flag1==1){
((yon_config_parameter*)dct)->flag1=0;
if (sections_add&&yon_dictionary_get(&sections_add,((yon_config_parameter*)dct)->section)) sections_add->data=(void*)yon_char_unite(yon_dictionary_get_data(sections_add,char*)," ",dct->key,"=\"",yon_dictionary_get_data(dct,char*),"\"",NULL);
else yon_dictionary_add_or_create_if_exists_with_data(sections_add,((yon_config_parameter*)dct)->section,yon_char_unite (ubconfig_save_command,path ? yon_char_append(" --target ",path):"", " set ", ((yon_config_parameter*)dct)->section," ", dct->key,"=\"",yon_dictionary_get_data(dct,char*),"\"",NULL));
if (sections_add&&yon_dictionary_get(&sections_add,((yon_config_parameter*)dct)->section)) sections_add->data=(void*)yon_char_unite(yon_dictionary_get_data(sections_add,char*)," ",dct->key,"=",yon_dictionary_get_data(dct,char*),NULL);
else yon_dictionary_add_or_create_if_exists_with_data(sections_add,((yon_config_parameter*)dct)->section,yon_char_unite (ubconfig_save_command,path ? yon_char_append(" --target ",path):"", " set ", ((yon_config_parameter*)dct)->section, " ",dct->key,"=",yon_dictionary_get_data(dct,char*),NULL));
} else if (((yon_config_parameter*)dct)->flag1==-1){
((yon_config_parameter*)dct)->flag1=0;
if (sections_remove&&yon_dictionary_get(&sections_remove,((yon_config_parameter*)dct)->section)) sections_remove->data=(void*)yon_char_unite(yon_dictionary_get_data(sections_remove,char*)," ",dct->key,NULL);
else yon_dictionary_add_or_create_if_exists_with_data(sections_remove,((yon_config_parameter*)dct)->section,yon_char_unite (ubconfig_save_command,path ? yon_char_append(" --target ",path):"", " remove ", ((yon_config_parameter*)dct)->section, " ",dct->key,NULL));
yon_dictionary_rip(dct);
}
}
}
if (sections_add)
for_dictionaries(dct,sections_add){
char *command = yon_dictionary_get_data(dct,char*);
yon_launch(command);
}
if (sections_remove)
for_dictionaries(dct,sections_remove){
char *command = yon_dictionary_get_data(dct,char*);
yon_launch(command);
}
return 1;
} else return 1;
}
/**int yon_config_force_save_registered(char *path, char *section)
* [EN]
* Saves config with [command]
* [RU]
* Выполняет команду [command], добавляя в конец все записи конфига в таком виде:
* [ПАРАМЕТР1]="[значения1]" [ПАРАМЕТР2]="[значения2]"
*/
int yon_config_force_save_registered(char *path){
check_config{
dictionary *dct;
dictionary *sections_add=NULL;
dictionary *sections_remove=NULL;
for_dictionaries(dct,(dictionary*)__yon__config__strings){
if (dct->data&&strcmp(yon_dictionary_get_data(dct,char*),"")!=0){
if (((yon_config_parameter*)dct)->flag1==1||((yon_config_parameter*)dct)->flag1==0){
if (sections_add&&yon_dictionary_get(&sections_add,((yon_config_parameter*)dct)->section)) sections_add->data=(void*)yon_char_unite(yon_dictionary_get_data(sections_add,char*)," ",dct->key,"=",yon_dictionary_get_data(dct,char*),NULL);
else yon_dictionary_add_or_create_if_exists_with_data(sections_add,((yon_config_parameter*)dct)->section,yon_char_unite (ubconfig_save_command,path ? yon_char_append(" --target ",path):"", " set ", ((yon_config_parameter*)dct)->section, " ",dct->key,"=",yon_dictionary_get_data(dct,char*),NULL));
} else if (((yon_config_parameter*)dct)->flag1==-1){
if (sections_remove&&yon_dictionary_get(&sections_remove,((yon_config_parameter*)dct)->section)) sections_remove->data=(void*)yon_char_unite(yon_dictionary_get_data(sections_remove,char*)," ",dct->key,NULL);
else yon_dictionary_add_or_create_if_exists_with_data(sections_remove,((yon_config_parameter*)dct)->section,yon_char_unite (ubconfig_save_command,path ? yon_char_append(" --target ",path):"", " remove ", ((yon_config_parameter*)dct)->section, " ",dct->key,NULL));
}
}
}
@ -1352,24 +1358,6 @@ int yon_config_save_registered(char *path){
}
// char *command = yon_char_unite(ubconfig_save_command,path ? yon_char_append(" --target ",path):"", " set ", section, " ", yon_dictionary_get_data(dct,char*),NULL);
// char *remove_command = yon_char_unite(ubconfig_save_command, path ? yon_char_append(" --target ",path):"", " remove "," ", yon_dictionary_get_data(dct,char*), section,NULL);
// dictionary *dict = NULL;
// int any_add = 0;
// int any_remove = 0;
// for_dictionaries(dict,(dictionary*)__yon__config__strings){
// char *data = yon_dictionary_get_data(dict,char*);
// if (((yon_config_parameter*)dict)->flag1==1&&strcmp(data,"")!=0){
// command = yon_char_unite(command, " ", dict->key,"=\"", yon_dictionary_get_data(dict,char*),"\"", NULL);
// any_add=1;
// }
// if (strcmp(data,"")==0){
// remove_command = yon_char_unite(remove_command, " ", dict->key, NULL);
// any_remove=1;
// }
// }
// if (any_add) yon_launch(command);
// if (any_remove) yon_launch(remove_command);
return 1;
} else return 1;
}
@ -1393,6 +1381,7 @@ config_str yon_config_get_all(int *size){
}
conf = yon_remalloc(conf,sizeof(char*)*(*size));
conf[*size-1] = NULL;
(*size)=(*size)-1;
return conf;
} else return NULL;
}
@ -1430,7 +1419,18 @@ char *yon_config_get_parameter(config_str parameters, int size, char *param)
return NULL;
}
config_str yon_file_open(char *file_path, int *size){
*size=0;
FILE *file = fopen(file_path,"r");
if (file){
char str_loaded[4098];
config_str final_string = NULL;
while (fgets(str_loaded,4098,file)){
final_string = final_string ? yon_char_parsed_append(final_string,size,str_loaded) : yon_char_parsed_new(size,str_loaded,NULL);
}
return final_string;
}
}
// terminal-using functions
@ -1818,7 +1818,7 @@ void yon_terminal_integrated_start(GtkWidget *terminal, char* command, void *end
param->section=section;
yon_dictionary_add_or_create_if_exists_with_data(__yon_main_window_config.deleted_parameters,param->parameter_name,param);
}
int yon_window_config_get_parameter(char *section, char *config_parameter, void *return_value, enum YON_TYPE type){
GError *err=NULL;
switch (type){
@ -1860,7 +1860,7 @@ GtkWidget *yon_ubl_menu_item_about_new(char *buttonname){
GtkWidget *yon_ubl_menu_item_documentation_new(char *buttonname){
GtkWidget *menu_item = gtk_menu_item_new();
gtk_style_context_add_class(gtk_widget_get_style_context(menu_item),"menuitemtop");
gtk_style_context_add_class(gtk_widget_get_style_context(menu_item),"menuitemmiddle");
GtkWidget *box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,0);
GtkWidget *label = gtk_label_new(buttonname);
GtkWidget *image = gtk_image_new_from_icon_name("dialog-question-symbolic",GTK_ICON_SIZE_BUTTON);

@ -198,6 +198,8 @@ config_str yon_config_load(char *command, int *str_len);
int yon_config_save_registered(char *path);
int yon_config_force_save_registered(char *path);
char *yon_config_get_parameter(config_str parameters, int size, char *param);
int yon_config_load_register(YON_CONFIG_TYPE config_type,char *section,char *parameter, ...);

@ -450,9 +450,9 @@
<property name="can-focus">False</property>
<property name="active">0</property>
<items>
<item translatable="yes">Hourly</item>
<item id="&lt;Введите ID&gt;" translatable="yes">Hourly</item>
<item translatable="yes">Daily</item>
<item translatable="yes">Weekly</item>
<item translatable="yes">Weekly*</item>
<item translatable="yes">Monthly</item>
<item translatable="yes">Yearly</item>
</items>
@ -476,7 +476,7 @@
<item translatable="yes">Thursday</item>
<item translatable="yes">Friday</item>
<item translatable="yes">Saturday</item>
<item translatable="yes">Sunday</item>
<item translatable="yes">Sunday*</item>
</items>
</object>
<packing>

@ -475,11 +475,11 @@ msgstr "Обработка ошибок:"
#: source/ubl-strings.h:123
msgid "Rotation of jurnal even when it is empty:"
msgstr "ротация файла журнала даже если он пуст:"
msgstr "Ротация файла журнала даже если он пуст:"
#: source/ubl-strings.h:124
msgid "Do not rotate journal younger than"
msgstr "Не ратировать журналы, возраст которых меньше"
msgstr "Не ротировать журналы, возраст которых меньше"
#: source/ubl-strings.h:125
msgid "days"

Loading…
Cancel
Save