From ca78ff6851ef6b61b1ec7aff43a3537188e5340d Mon Sep 17 00:00:00 2001 From: Klaus Ethgen Date: Fri, 24 May 2019 08:38:54 +0100 Subject: [PATCH] Allow to disable trash completely The posibilito to not use trash at all was lost with implementation of system trash. However, usually one does not want the system to keep megabytes of trash lying around. That option allows to switch trash of completely. The implementation, however, is a bit dirty, maybe someone else has a better Idea to do it. --- src/options.c | 1 + src/options.h | 1 + src/preferences.c | 19 +++++++++++++++++-- src/rcfile.c | 2 ++ src/trash.c | 45 ++++++++++++++++++++++++++++----------------- 5 files changed, 49 insertions(+), 19 deletions(-) diff --git a/src/options.c b/src/options.c index 4502d689..dd83f297 100644 --- a/src/options.c +++ b/src/options.c @@ -72,6 +72,7 @@ ConfOptions *init_options(ConfOptions *options) options->file_ops.safe_delete_enable = TRUE; options->file_ops.safe_delete_folder_maxsize = 128; options->file_ops.safe_delete_path = NULL; + options->file_ops.no_trash = FALSE; options->file_sort.ascending = TRUE; options->file_sort.case_sensitive = FALSE; diff --git a/src/options.h b/src/options.h index e4da0858..65e8b748 100644 --- a/src/options.h +++ b/src/options.h @@ -101,6 +101,7 @@ struct _ConfOptions gboolean use_system_trash; gchar *safe_delete_path; gint safe_delete_folder_maxsize; + gboolean no_trash; } file_ops; /* image */ diff --git a/src/preferences.c b/src/preferences.c index 2f35b54c..6bcbed47 100644 --- a/src/preferences.c +++ b/src/preferences.c @@ -262,6 +262,7 @@ static void config_window_apply(void) options->file_ops.enable_delete_key = c_options->file_ops.enable_delete_key; options->file_ops.confirm_move_to_trash = c_options->file_ops.confirm_move_to_trash; options->file_ops.use_system_trash = c_options->file_ops.use_system_trash; + options->file_ops.no_trash = c_options->file_ops.no_trash; options->file_ops.safe_delete_folder_maxsize = c_options->file_ops.safe_delete_folder_maxsize; options->tools_restore_state = c_options->tools_restore_state; options->save_window_positions = c_options->save_window_positions; @@ -2951,6 +2952,7 @@ static void use_geeqie_trash_cb(GtkWidget *widget, gpointer data) if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) { c_options->file_ops.use_system_trash = FALSE; + c_options->file_ops.no_trash = FALSE; } } @@ -2959,6 +2961,15 @@ static void use_system_trash_cb(GtkWidget *widget, gpointer data) if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) { c_options->file_ops.use_system_trash = TRUE; + c_options->file_ops.no_trash = FALSE; + } +} + +static void use_no_cache_cb(GtkWidget *widget, gpointer data) +{ + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) + { + c_options->file_ops.no_trash = TRUE; } } @@ -2988,7 +2999,7 @@ static void config_tab_behavior(GtkWidget *notebook) options->file_ops.enable_delete_key, &c_options->file_ops.enable_delete_key); ct_button = pref_radiobutton_new(group, NULL, _("Use Geeqie trash location"), - !options->file_ops.use_system_trash, G_CALLBACK(use_geeqie_trash_cb),NULL); + !options->file_ops.use_system_trash && !options->file_ops.no_trash, G_CALLBACK(use_geeqie_trash_cb),NULL); hbox = pref_box_new(group, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_SPACE); pref_checkbox_link_sensitivity(ct_button, hbox); @@ -3017,7 +3028,11 @@ static void config_tab_behavior(GtkWidget *notebook) G_CALLBACK(safe_delete_clear_cb), NULL); gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0); pref_radiobutton_new(group, ct_button, _("Use system Trash bin"), - options->file_ops.use_system_trash, G_CALLBACK(use_system_trash_cb), NULL); + options->file_ops.use_system_trash && !options->file_ops.no_trash, G_CALLBACK(use_system_trash_cb), NULL); + + pref_radiobutton_new(group, ct_button, _("Use no trash at all"), + options->file_ops.no_trash, G_CALLBACK(use_no_cache_cb), NULL); + gtk_widget_show(button); pref_spacer(group, PREF_PAD_GROUP); diff --git a/src/rcfile.c b/src/rcfile.c index 99794d52..ae838a1d 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -361,6 +361,7 @@ static void write_global_attributes(GString *outstr, gint indent) WRITE_NL(); WRITE_BOOL(*options, file_ops.safe_delete_enable); WRITE_NL(); WRITE_CHAR(*options, file_ops.safe_delete_path); WRITE_NL(); WRITE_INT(*options, file_ops.safe_delete_folder_maxsize); + WRITE_NL(); WRITE_BOOL(*options, file_ops.no_trash); /* Properties dialog Options */ WRITE_NL(); WRITE_CHAR(*options, properties.tabs_order); @@ -797,6 +798,7 @@ static gboolean load_global_params(const gchar **attribute_names, const gchar ** if (READ_BOOL(*options, file_ops.safe_delete_enable)) continue; if (READ_CHAR(*options, file_ops.safe_delete_path)) continue; if (READ_INT(*options, file_ops.safe_delete_folder_maxsize)) continue; + if (READ_BOOL(*options, file_ops.no_trash)) continue; /* Fullscreen options */ if (READ_INT(*options, fullscreen.screen)) continue; diff --git a/src/trash.c b/src/trash.c index b6a83432..b53404e2 100644 --- a/src/trash.c +++ b/src/trash.c @@ -133,7 +133,17 @@ gboolean file_util_safe_unlink(const gchar *path) if (!isfile(path)) return FALSE; - if (!options->file_ops.use_system_trash) + if (options->file_ops.no_trash) + { + if (!unlink_file(path)) + { + file_util_warning_dialog(_("Delete failed"), + _("Unable to remove file"), + GTK_STOCK_DIALOG_WARNING, NULL); + success = FALSE; + } + } + else if (!options->file_ops.use_system_trash) { if (!isdir(options->file_ops.safe_delete_path)) { @@ -195,25 +205,26 @@ gchar *file_util_safe_delete_status(void) { buf = g_strdup(_("Deletion by external command")); } - else + else if (options->file_ops.no_trash) + { + buf = g_strdup(_("Deleting without trash")); + } + else if (options->file_ops.safe_delete_enable) { - if (options->file_ops.safe_delete_enable) + if (!options->file_ops.use_system_trash) { - if (!options->file_ops.use_system_trash) - { - gchar *buf2; - if (options->file_ops.safe_delete_folder_maxsize > 0) - buf2 = g_strdup_printf(_(" (max. %d MB)"), options->file_ops.safe_delete_folder_maxsize); - else - buf2 = g_strdup(""); - - buf = g_strdup_printf(_("Using Geeqie Trash bin\n%s"), buf2); - g_free(buf2); - } + gchar *buf2; + if (options->file_ops.safe_delete_folder_maxsize > 0) + buf2 = g_strdup_printf(_(" (max. %d MB)"), options->file_ops.safe_delete_folder_maxsize); else - { - buf = g_strdup(_("Using system Trash bin")); - } + buf2 = g_strdup(""); + + buf = g_strdup_printf(_("Using Geeqie Trash bin\n%s"), buf2); + g_free(buf2); + } + else + { + buf = g_strdup(_("Using system Trash bin")); } } -- 2.20.1