Path adding at logrotate has been reworked

pull/80/head
Ivan Yartsev 2 years ago
parent edc6a68289
commit 68af724788

@ -484,6 +484,85 @@ void on_inspector_open(GtkWidget *self, main_window *widgets){
// Logrotate window
void on_logrotate_configuration_path_filechooser_save_edit(GtkWidget *self, dictionary *dict){
logrotate_configure_window *window = yon_dictionary_get_data(dict->first,logrotate_configure_window*);
logrotate_filechooser_window *dialog = yon_dictionary_get_data(dict->first->next,logrotate_filechooser_window*);
GtkTreeIter iter, itar;
GtkTreeModel *model = GTK_TREE_MODEL(window->list);
if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(window->LogPathsTree)),&model,&iter)){
char *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog->FileChooser));
int valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(window->list),&itar);
int deleted=0;
for (;valid;valid=gtk_tree_model_iter_next(GTK_TREE_MODEL(window->list),&itar)){
char *path;
gtk_tree_model_get(GTK_TREE_MODEL(window->list),&itar,0,&path,-1);
if (path&&filename)
if (!strcmp(path,filename)&&gtk_tree_path_compare(gtk_tree_model_get_path(GTK_TREE_MODEL(window->list),&itar),gtk_tree_model_get_path(GTK_TREE_MODEL(window->list),&iter))){
yon_ubl_status_list_store_highlight_incorrect(window->list,gtk_tree_iter_copy(&itar));
yon_ubl_status_box_spawn(GTK_CONTAINER(dialog->StatusBox),REPEAT_PATHS_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE);
deleted=1;
}
}
if(!deleted){
gtk_list_store_set(window->list,&iter,0,filename,-1);
on_close_subwindow(dialog->FileChooser,"FileDialog");
}
}
}
void on_logrotate_configuration_path_filechooser_save(GtkWidget *self, dictionary *dict){
logrotate_configure_window *window = yon_dictionary_get_data(dict->first,logrotate_configure_window*);
logrotate_filechooser_window *dialog = yon_dictionary_get_data(dict->first->next,logrotate_filechooser_window*);
char *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog->FileChooser));
GtkTreeIter iter, itar;
int valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(window->list),&itar);
int deleted=0;
for (;valid;valid=gtk_tree_model_iter_next(GTK_TREE_MODEL(window->list),&itar)){
char *path;
gtk_tree_model_get(GTK_TREE_MODEL(window->list),&itar,0,&path,-1);
if (path&&filename)
if (!strcmp(path,filename)){
yon_ubl_status_list_store_highlight_incorrect(window->list,gtk_tree_iter_copy(&itar));
yon_ubl_status_box_spawn(GTK_CONTAINER(dialog->StatusBox),REPEAT_PATHS_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE);
deleted=1;
}
}
if(!deleted){
gtk_list_store_append(window->list,&iter);
gtk_list_store_set(window->list,&iter,0,filename,-1);
on_close_subwindow(dialog->FileChooser,"FileDialog");
}
}
void on_logrotate_configuration_path_filechooser_open(GtkWidget *self, logrotate_configure_window *window){
GtkTreeIter iter;
GtkTreeModel *model = GTK_TREE_MODEL(window->list);
if (self==window->LogPathEditButton){
if (!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(window->LogPathsTree)),&model,&iter))
return;
}
GtkBuilder *builder = gtk_builder_new_from_resource(glade_filechooser_path);
logrotate_filechooser_window *dialog = malloc(sizeof(logrotate_filechooser_window));
dialog->FileChooser = yon_gtk_builder_get_widget(builder,"FileChooser");
dialog->FileOrDirCheck = yon_gtk_builder_get_widget(builder,"FileOrDirCheck");
dialog->CancelButton = yon_gtk_builder_get_widget(builder,"CancelButton");
dialog->AcceptButton = yon_gtk_builder_get_widget(builder,"AcceptButton");
dialog->StatusBox = yon_gtk_builder_get_widget(builder,"StatusBox");
yon_window_config_custom_window_set(GTK_WINDOW(dialog->FileChooser),"FileDialog");
gtk_window_set_transient_for(GTK_WINDOW(window->MainWindow),GTK_WINDOW(window->MainWindow));
dictionary *dict = NULL;
gtk_window_set_title(GTK_WINDOW(dialog->FileChooser),TITLE_LABEL);
yon_dictionary_add_or_create_if_exists_with_data(dict,"window",window);
yon_dictionary_add_or_create_if_exists_with_data(dict,"dialog",dialog);
g_signal_connect(G_OBJECT(dialog->CancelButton),"clicked",G_CALLBACK(on_close_subwindow),"FileDialog");
if (self==window->LogPathAddButton)
g_signal_connect(G_OBJECT(dialog->AcceptButton),"clicked",G_CALLBACK(on_logrotate_configuration_path_filechooser_save),dict);
else if (self==window->LogPathEditButton)
g_signal_connect(G_OBJECT(dialog->AcceptButton),"clicked",G_CALLBACK(on_logrotate_configuration_path_filechooser_save_edit),dict);
gtk_widget_show(dialog->FileChooser);
}
void on_logrotate_configuration_path_add(GtkWidget *self, logrotate_configure_window *window){
GtkTreeModel *model = GTK_TREE_MODEL(window->list);
GtkTreeIter iter;
@ -518,13 +597,8 @@ void on_path_editing_done(GtkCellRendererText* self,gchar* gtkpath,gchar* new_te
yon_ubl_status_list_store_highlight_incorrect(window->list,gtk_tree_iter_copy(&itar));
yon_ubl_status_list_store_highlight_incorrect(window->list,gtk_tree_iter_copy(&iter));
yon_ubl_status_box_spawn(GTK_CONTAINER(window->StatusBox),REPEAT_PATHS_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE);
new_text[strlen(new_text)-1]='\0';
gtk_list_store_set(window->list,&iter,0,new_text,-1);
deleted=1;
}
}
if (!deleted)
gtk_list_store_set(window->list,&iter,0,new_text,-1);
}
@ -1150,8 +1224,8 @@ logrotate_configure_window *yon_logrotate_window_new(char *paths, logrotate_wind
g_signal_connect(G_OBJECT(window->SaveButton),"clicked",G_CALLBACK(on_logrotate_save),dict);
g_signal_connect(G_OBJECT(window->PathCell),"edited",G_CALLBACK(on_path_editing_done),window);
g_signal_connect(G_OBJECT(window->PathCell),"editing-canceled",G_CALLBACK(on_path_editing_cancel),window);
g_signal_connect(G_OBJECT(window->LogPathAddButton),"clicked",G_CALLBACK(on_logrotate_configuration_path_add),window);
g_signal_connect(G_OBJECT(window->LogPathEditButton),"clicked",G_CALLBACK(on_logrotate_configuration_path_edit),window);
g_signal_connect(G_OBJECT(window->LogPathAddButton),"clicked",G_CALLBACK(on_logrotate_configuration_path_filechooser_open),window);
g_signal_connect(G_OBJECT(window->LogPathEditButton),"clicked",G_CALLBACK(on_logrotate_configuration_path_filechooser_open),window);
g_signal_connect(G_OBJECT(window->LogPathRemoveButton),"clicked",G_CALLBACK(on_logrotate_configuration_path_remove),window);
g_signal_connect(G_OBJECT(window->RotationPeriodCheck),"toggled",G_CALLBACK(on_logrotate_period_check_toggled),window);

@ -236,6 +236,7 @@ typedef struct {
GtkWidget *FileOrDirCheck;
GtkWidget *CancelButton;
GtkWidget *AcceptButton;
GtkWidget *StatusBox;
} logrotate_filechooser_window;
typedef struct {

@ -78,6 +78,21 @@
<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">1</property>
</packing>
</child>
</object>
</child>
<child type="titlebar">

Loading…
Cancel
Save