diff --git a/source/ubl-settings-logging.c b/source/ubl-settings-logging.c index 2d3f6c0..a3c4798 100644 --- a/source/ubl-settings-logging.c +++ b/source/ubl-settings-logging.c @@ -363,9 +363,10 @@ void on_logrotate_save(GtkWidget *self, logrotate_configure_window *window){ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->FileAmountCheck))){ long fileamount = gtk_spin_button_get_value(GTK_SPIN_BUTTON(window->FileAmountSpin)); int active = gtk_combo_box_get_active(GTK_COMBO_BOX(window->FileAmountCombo)); + rotate_count = yon_char_append("rotate ",yon_char_from_long(fileamount)); if (active==2){ const char *text = gtk_entry_get_text(GTK_ENTRY(window->FileAmountEntry)); - rotate_count=yon_char_unite("olddir",",",text,NULL); + olddir=yon_char_unite("olddir ",text,NULL); } } @@ -498,12 +499,15 @@ void on_logrotate_save(GtkWidget *self, logrotate_configure_window *window){ free(yon_char_divide_search(commandline," ",-1)); } if(!yon_char_is_empty(paths)){ + GtkTreeIter iter; yon_config_register(LOGROTATE(paths),"logging",commandline); + gtk_list_store_append(main_config.logrotate_list,&iter); + gtk_list_store_set(main_config.logrotate_list,&iter,0,gtk_entry_get_text(GTK_ENTRY(window->LogNameEntry)),1,paths,2,gtk_entry_get_text(GTK_ENTRY(window->LogDescriptionEntry)),-1); on_close_subwindow(window->MainWindow); } } -logrotate_configure_window *yon_logrotate_window_new(){ +logrotate_configure_window *yon_logrotate_window_new(char *paths){ logrotate_configure_window *window = malloc(sizeof(logrotate_configure_window)); GtkBuilder *builder = gtk_builder_new_from_resource(glade_logrotate_path); window->MainWindow=yon_gtk_builder_get_widget(builder,"MainWindow"); @@ -602,14 +606,157 @@ logrotate_configure_window *yon_logrotate_window_new(){ g_signal_connect(G_OBJECT(window->CreateLogCombo),"changed",G_CALLBACK(yon_gtk_widget_set_sensitive_from_combo_box_inversed),window->CreateLogEntry); g_signal_connect(G_OBJECT(window->CreateLogCombo),"changed",G_CALLBACK(yon_gtk_widget_set_sensitive_from_combo_box_inversed),window->CreateLogButton); - + if (paths){ + int size; + GtkTreeIter iter; + config_str parsed = yon_char_parse(paths,&size,","); + for (int i=0; ilist,&iter); + gtk_list_store_set(window->list,&iter,0,parsed[i],-1); + } + yon_char_parsed_free(parsed,size); + char *parameters = yon_config_get_by_key(LOGROTATE(paths)); + if (parameters){ + parameters = yon_char_replace(parameters,",\t",","); + if (parameters[0]==',') yon_char_divide_search(parameters,",",-1); + parsed = yon_char_parse(parameters,&size,","); + for (int i=0;iRotationPeriodMainCombo),0); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->RotationPeriodCheck),1); + } else if (!strcmp(parsed[i],"daily")){ + gtk_combo_box_set_active(GTK_COMBO_BOX(window->RotationPeriodMainCombo),1); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->RotationPeriodCheck),1); + }else if (!strcmp(parsed[i],"weekly")){ + gtk_combo_box_set_active(GTK_COMBO_BOX(window->RotationPeriodMainCombo),2); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->RotationPeriodCheck),1); + gtk_combo_box_set_active(GTK_COMBO_BOX(window->RotationPeriodAdditionalCombo),atoi(parsed[i+1])); + }else if (!strcmp(parsed[i],"monthly")){ + gtk_combo_box_set_active(GTK_COMBO_BOX(window->RotationPeriodMainCombo),3); + }else if (!strcmp(parsed[i],"yearly")){ + gtk_combo_box_set_active(GTK_COMBO_BOX(window->RotationPeriodMainCombo),4); + }else if (!strcmp(parsed[i],"size")){ + int sizemod = yon_size_get_int_from_letter(parsed[i][strlen(parsed[i])-1]); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->JournalMaxSizeSpin),atol(parsed[i])); + gtk_combo_box_set_active(GTK_COMBO_BOX(window->JournalMaxSizeCombo),sizemod); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->JournalMaxSizeCheck),1); + }else if (!strcmp(parsed[i],"rotate")){ + char *value = strstr(parsed[i]," ")+1; + gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->FileAmountSpin),atol(value)); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->FileAmountCheck),1); + }else if (!strcmp(parsed[i],"olddir")){ + char *value = strstr(parsed[i]," ")+1; + gtk_entry_set_text(GTK_ENTRY(window->FileAmountEntry),value); + gtk_combo_box_set_active(GTK_COMBO_BOX(window->FileAmountCombo),1); + }else if (!strcmp(parsed[i],"noolddir")){ + gtk_combo_box_set_active(GTK_COMBO_BOX(window->FileAmountCombo),2); + }else if (!strcmp(parsed[i],"su")){ + char *value = strstr(parsed[i]," ")+1; + char *nvalue = yon_char_divide_search(value," ",-1); + int us = yon_gtk_combo_box_text_find(window->RotationAtUserCombo,nvalue); + int gr = yon_gtk_combo_box_text_find(window->RotationAtGroupCombo,value); + gtk_combo_box_set_active(GTK_COMBO_BOX(window->RotationAtUserCombo),us); + gtk_combo_box_set_active(GTK_COMBO_BOX(window->RotationAtGroupCombo),gr); + }else if (!strcmp(parsed[i],"missingok")){ + gtk_combo_box_set_active(GTK_COMBO_BOX(window->ErrorProcessingCombo),1); + }else if (!strcmp(parsed[i],"nomissingok")){ + gtk_combo_box_set_active(GTK_COMBO_BOX(window->ErrorProcessingCombo),2); + }else if (!strcmp(parsed[i],"ifempty")){ + gtk_combo_box_set_active(GTK_COMBO_BOX(window->JournalEmptyCombo),1); + }else if (!strcmp(parsed[i],"notifempty")){ + gtk_combo_box_set_active(GTK_COMBO_BOX(window->JournalEmptyCombo),2); + }else if (!strcmp(parsed[i],"minage")){ + char *value = strstr(parsed[i]," ")+1; + gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->DoNotRotateYoungerSpin),atol(value)); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->DoNotRotateYoungerCheck),1); + }else if (!strcmp(parsed[i],"maxage")){ + char *value = strstr(parsed[i]," ")+1; + gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->DeleteOlderSpin),atol(value)); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->DeleteOlderCheck),1); + }else if (!strcmp(parsed[i],"minsize")){ + char *value = strstr(parsed[i]," ")+1; + gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->RotateSizeMaxAfterTimeSpin),atol(value)); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->RotateSizeMaxAfterTimeCheck),1); + gtk_combo_box_set_active(GTK_COMBO_BOX(window->RotateSizeMaxAfterTimeCombo),yon_size_get_int_from_letter(value[strlen(value)-1])); + }else if (!strcmp(parsed[i],"maxsize")){ + char *value = strstr(parsed[i]," ")+1; + gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->RotateSizeMaxBeforeTimeSpin),atol(value)); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->RotateSizeMaxBeforeTimeCheck),1); + gtk_combo_box_set_active(GTK_COMBO_BOX(window->RotateSizeMaxBeforeTimeCombo),yon_size_get_int_from_letter(value[strlen(value)-1])); + // }else if (!strcmp(parsed[i],"create")){ + // + // }else if (!strcmp(parsed[i],"nocreate")){ + // + }else if (!strcmp(parsed[i],"copytruncate")){ + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->CutCheck),1); + }else if (!strcmp(parsed[i],"compress")){ + gtk_combo_box_set_active(GTK_COMBO_BOX(window->CompressionCombo),1); + }else if (!strcmp(parsed[i],"nocompress")){ + gtk_combo_box_set_active(GTK_COMBO_BOX(window->CompressionCombo),2); + }else if (!strcmp(parsed[i],"delaycompress")){ + gtk_combo_box_set_active(GTK_COMBO_BOX(window->QueueCombo),1); + + }else if (!strcmp(parsed[i],"nodelaycompress")){ + gtk_combo_box_set_active(GTK_COMBO_BOX(window->QueueCombo),2); + }else if (!strcmp(parsed[i],"extension")){ + char *value = strstr(parsed[i]," ")+1; + gtk_combo_box_set_active(GTK_COMBO_BOX(window->SaveOriginalCombo),1); + gtk_entry_set_text(GTK_ENTRY(window->SaveOriginalEntry),value); + }else if (!strcmp(parsed[i],"dateext")){ + gtk_combo_box_set_active(GTK_COMBO_BOX(window->AddDateCombo),1); + }else if (!strcmp(parsed[i],"start")){ + char *value = strstr(parsed[i]," ")+1; + gtk_combo_box_set_active(GTK_COMBO_BOX(window->OldNumberCombo),1); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->OldNumberEntry),atol(value)); + }else if (!strcmp(parsed[i],"mail")){ + char *value = strstr(parsed[i]," ")+1; + gtk_entry_set_text(GTK_ENTRY(window->EmailEntry),value); + gtk_combo_box_set_active(GTK_COMBO_BOX(window->EmailCombo),1); + }else if (!strcmp(parsed[i],"nomail")){ + gtk_combo_box_set_active(GTK_COMBO_BOX(window->EmailCombo),2); + }else if (!strcmp(parsed[i],"mailfirst")){ + gtk_combo_box_set_active(GTK_COMBO_BOX(window->EmailContentsCombo),1); + }else if (!strcmp(parsed[i],"maillast")){ + gtk_combo_box_set_active(GTK_COMBO_BOX(window->EmailContentsCombo),2); + }else if (!strcmp(parsed[i],"sharedscripts")){ + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->SharedScenariosCheck),1); + }else if (!strcmp(parsed[i],"firstaction")){ + char *value = parsed[i+1]; + gtk_entry_set_text(GTK_ENTRY(window->CommandBeforeOnceEntry),value); + i++; + }else if (!strcmp(parsed[i],"lastaction")){ + char *value = parsed[i+1]; + gtk_entry_set_text(GTK_ENTRY(window->CommandAfterOnceEntry),value); + i++; + }else if (!strcmp(parsed[i],"prerotate")){ + char *value = parsed[i+1]; + gtk_entry_set_text(GTK_ENTRY(window->CommandBeforeEntry),value); + i++; + }else if (!strcmp(parsed[i],"postrotate")){ + char *value = parsed[i+1]; + gtk_entry_set_text(GTK_ENTRY(window->CommandAfterEntry),value); + i++; + // }else if (!strcmp(parsed[i],"preremove")){ + // char *value = parsed[i+1]; + // gtk_entry_set_text(GTK_ENTRY(window->CommandBeforeOnceEntry),value); + // i++; + }else if (!strcmp(parsed[i],"endscript")){ + char *value = parsed[i+1]; + gtk_entry_set_text(GTK_ENTRY(window->EndworkCommandEntry),value); + i++; + } + } + } + } return window; } void on_logrotate_add(GtkWidget *self, main_window *widgets){ - logrotate_configure_window *window = yon_logrotate_window_new(); + logrotate_configure_window *window = yon_logrotate_window_new(NULL); gtk_widget_show(window->MainWindow); + gtk_widget_set_sensitive(window->LogNameEntry,1); + gtk_widget_set_sensitive(window->LogDescriptionEntry,1); gtk_label_set_text(GTK_LABEL(window->LogSizeLabel),""); } @@ -618,8 +765,15 @@ void on_logrotate_edit(GtkWidget *self, logrotate_tab_window *window){ GtkTreeIter iter,itar; if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(window->MainTree)),&model, &iter)){ char *name; + int size=0; char *paths; - logrotate_configure_window *dialog = yon_logrotate_window_new(); + gtk_tree_model_get(gtk_tree_view_get_model(GTK_TREE_VIEW(window->MainTree)),&iter,1,&paths,-1); + config_str path_parsed = yon_char_parse(paths,&size,"\n"); + paths=NULL; + for (int i=0;iMainWindow); gtk_tree_model_get(model,&iter,0,&name,1,&paths,-1); gtk_entry_set_text(GTK_ENTRY(dialog->LogNameEntry),name); @@ -629,12 +783,6 @@ void on_logrotate_edit(GtkWidget *self, logrotate_tab_window *window){ gtk_entry_set_has_frame(GTK_ENTRY(dialog->LogDescriptionEntry),0); gtk_style_context_add_class(gtk_widget_get_style_context(dialog->LogNameEntry),"nobackground"); gtk_style_context_add_class(gtk_widget_get_style_context(dialog->LogDescriptionEntry),"nobackground"); - int size=0; - config_str path_parsed = yon_char_parse(paths,&size,"\n"); - for (int i=0;ilist,&itar); - gtk_list_store_set(dialog->list,&itar,0,path_parsed[i],-1); - } } } @@ -653,8 +801,10 @@ void on_logrotate_apps_configure(GtkWidget *self, logrotate_window *window){ if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(window->AppsMainTree)),&model,&iter)){ char *paths; char *name; + char *settings; gtk_list_store_append(main_config.logrotate_list,&itar); - gtk_tree_model_get(model,&iter,0,&name,1,&paths,-1); + gtk_tree_model_get(model,&iter,0,&name,1,&paths,2,&settings,-1); + yon_config_register(LOGROTATE(yon_char_replace(paths,"\n",",")),"logging",settings); gtk_list_store_set(main_config.logrotate_list,&itar,0,name,1,paths,-1); } } @@ -667,9 +817,15 @@ void on_log_edit_logrotate_settings(GtkWidget *self, dictionary *dict){ if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->MainTree)),&model,&iter)){ char *name; char *description; - logrotate_configure_window *dialog = yon_logrotate_window_new(); - gtk_widget_show(dialog->MainWindow); gtk_tree_model_get(model,&iter,0,&name,2,&description,-1); + GList *list = gtk_container_get_children(GTK_CONTAINER(window->LogPathsBox)); + char *pathse=NULL; + for (int i=0;iMainWindow); gtk_entry_set_text(GTK_ENTRY(dialog->LogNameEntry),name); gtk_entry_set_text(GTK_ENTRY(dialog->LogDescriptionEntry),description); gtk_widget_set_can_focus(dialog->LogNameEntry,0); @@ -678,13 +834,6 @@ void on_log_edit_logrotate_settings(GtkWidget *self, dictionary *dict){ gtk_entry_set_has_frame(GTK_ENTRY(dialog->LogDescriptionEntry),0); gtk_style_context_add_class(gtk_widget_get_style_context(dialog->LogNameEntry),"nobackground"); gtk_style_context_add_class(gtk_widget_get_style_context(dialog->LogDescriptionEntry),"nobackground"); - GList *list = gtk_container_get_children(GTK_CONTAINER(window->LogPathsBox)); - for (int i=0;ilist,&itar); - GList *paths = gtk_container_get_children((GtkContainer*)g_list_nth_data(list,i)); - gtk_list_store_set(dialog->list,&itar,0,gtk_entry_get_text((GtkEntry*)g_list_nth_data(paths,1)),-1); - g_list_free(paths); - } } } diff --git a/source/ubl-utils.c b/source/ubl-utils.c index 3ed0e09..5377bac 100644 --- a/source/ubl-utils.c +++ b/source/ubl-utils.c @@ -645,7 +645,7 @@ char *yon_char_replace(char *source, char *find, char*replace){ memset(temp,0,strlen(source)-strlen(final)+strlen(replace)); memcpy(temp,source,strlen(source)-strlen(final)); temp=yon_char_append(temp,replace); - source=yon_char_append(temp,final+1); + source=yon_char_append(temp,final+strlen(find)); } }