Allow to disable trash completely
authorKlaus Ethgen <Klaus@Ethgen.de>
Fri, 24 May 2019 07:38:54 +0000 (08:38 +0100)
committerKlaus Ethgen <Klaus@Ethgen.de>
Fri, 24 May 2019 07:38:54 +0000 (08:38 +0100)
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
src/options.h
src/preferences.c
src/rcfile.c
src/trash.c

index 4502d68..dd83f29 100644 (file)
@@ -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;
index e4da085..65e8b74 100644 (file)
@@ -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 */
index 2f35b54..6bcbed4 100644 (file)
@@ -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);
index 99794d5..ae838a1 100644 (file)
@@ -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;
index b6a8343..b53404e 100644 (file)
@@ -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"));
                        }
                }