Include a Other Software section in Help file
[geeqie.git] / src / trash.c
index 6439a20..b3aecfc 100644 (file)
@@ -1,16 +1,24 @@
 /*
- * Geeqie
- * (C) 2006 John Ellis
- * Copyright (C) 2008 The Geeqie Team
+ * Copyright (C) 2006 John Ellis
+ * Copyright (C) 2008 - 2016 The Geeqie Team
  *
  * Author: John Ellis
  *
- * This software is released under the GNU General Public License (GNU GPL).
- * Please read the included file COPYING for more information.
- * This software comes with no warranty of any kind, use at your own risk!
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-
 #include "main.h"
 #include "trash.h"
 #include "utilops.h"
@@ -33,11 +41,11 @@ static gint file_util_safe_number(gint64 free_space)
        gint64 total = 0;
        GList *list;
        GList *work;
-       gint sorted = FALSE;
-       gint warned = FALSE;
+       gboolean sorted = FALSE;
+       gboolean warned = FALSE;
        FileData *dir_fd;
 
-       dir_fd = file_data_new_simple(options->file_ops.safe_delete_path);
+       dir_fd = file_data_new_dir(options->file_ops.safe_delete_path);
        if (!filelist_read(dir_fd, &list, NULL))
                {
                file_data_unref(dir_fd);
@@ -110,75 +118,72 @@ static gchar *file_util_safe_dest(const gchar *path)
        return dest;
 }
 
-static void file_util_safe_del_toggle_cb(GtkWidget *button, gpointer data)
-{
-       options->file_ops.safe_delete_enable = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button));
-}
-
-static void file_util_safe_del_close_cb(GtkWidget *dialog, gpointer data)
-{
-       GenericDialog **gd = data;
-
-       *gd = NULL;
-}
-
-gint file_util_safe_unlink(const gchar *path)
+gboolean file_util_safe_unlink(const gchar *path)
 {
        static GenericDialog *gd = NULL;
        gchar *result = NULL;
-       gint success = TRUE;
+       gboolean success = TRUE;
 
        if (!isfile(path)) return FALSE;
 
-       if (!isdir(options->file_ops.safe_delete_path))
+       if (options->file_ops.no_trash)
                {
-               DEBUG_1("creating trash: %s", options->file_ops.safe_delete_path);
-               if (!options->file_ops.safe_delete_path || !mkdir_utf8(options->file_ops.safe_delete_path, 0755))
+               if (!unlink_file(path))
                        {
-                       result = _("Could not create folder");
+                       file_util_warning_dialog(_("Delete failed"),
+                                                _("Unable to remove file"),
+                                                GTK_STOCK_DIALOG_WARNING, NULL);
                        success = FALSE;
                        }
                }
-
-       if (success)
+       else if (!options->file_ops.use_system_trash)
                {
-               gchar *dest;
-
-               dest = file_util_safe_dest(path);
-               if (dest)
+               if (!isdir(options->file_ops.safe_delete_path))
                        {
-                       DEBUG_1("safe deleting %s to %s", path, dest);
-                       success = move_file(path, dest);
+                       DEBUG_1("creating trash: %s", options->file_ops.safe_delete_path);
+                       if (!options->file_ops.safe_delete_path || !mkdir_utf8(options->file_ops.safe_delete_path, 0755))
+                               {
+                               result = _("Could not create folder");
+                               success = FALSE;
+                               }
                        }
-               else
+
+               if (success)
                        {
-                       success = FALSE;
+                       gchar *dest;
+
+                       dest = file_util_safe_dest(path);
+                       if (dest)
+                               {
+                               DEBUG_1("safe deleting %s to %s", path, dest);
+                               success = move_file(path, dest);
+                               }
+                       else
+                               {
+                               success = FALSE;
+                               }
+
+                       if (!success && !access_file(path, W_OK))
+                               {
+                               result = _("Permission denied");
+                               }
+                       g_free(dest);
                        }
 
-               if (!success && !access_file(path, W_OK))
+               if (result && !gd)
                        {
-                       result = _("Permission denied");
+                       gchar *buf;
+
+                       buf = g_strdup_printf(_("Unable to access or create the trash folder.\n\"%s\""), options->file_ops.safe_delete_path);
+                       gd = file_util_warning_dialog(result, buf, GTK_STOCK_DIALOG_WARNING, NULL);
+                       g_free(buf);
                        }
-               g_free(dest);
                }
-
-       if (result && !gd)
+       else
                {
-               GtkWidget *button;
-               gchar *buf;
-
-               buf = g_strdup_printf(_("Unable to access or create the trash folder.\n\"%s\""), options->file_ops.safe_delete_path);
-               gd = file_util_warning_dialog(result, buf, GTK_STOCK_DIALOG_WARNING, NULL);
-               g_free(buf);
-
-               button = gtk_check_button_new_with_label(_("Turn off safe delete"));
-               g_signal_connect(G_OBJECT(button), "toggled",
-                                G_CALLBACK(file_util_safe_del_toggle_cb), NULL);
-               gtk_box_pack_start(GTK_BOX(gd->vbox), button, FALSE, FALSE, 0);
-               gtk_widget_show(button);
-
-               g_signal_connect(G_OBJECT(gd->dialog), "destroy",
-                                G_CALLBACK(file_util_safe_del_close_cb), &gd);
+               GFile *tmp = g_file_new_for_path (path);
+               g_file_trash(tmp, FALSE, NULL);
+               g_object_unref(tmp);
                }
 
        return success;
@@ -186,31 +191,35 @@ gint file_util_safe_unlink(const gchar *path)
 
 gchar *file_util_safe_delete_status(void)
 {
-       gchar *buf;
+       gchar *buf = NULL;
 
        if (is_valid_editor_command(CMD_DELETE))
                {
                buf = g_strdup(_("Deletion by external command"));
                }
-       else
+       else if (options->file_ops.no_trash)
                {
-               if (options->file_ops.safe_delete_enable)
+               buf = g_strdup(_("Deleting without trash"));
+               }
+       else if (options->file_ops.safe_delete_enable)
+               {
+               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);
+                               buf2 = g_strdup_printf(_(" (max. %d MiB)"), options->file_ops.safe_delete_folder_maxsize);
                        else
                                buf2 = g_strdup("");
 
-                       buf = g_strdup_printf(_("Safe delete: %s%s\nTrash: %s"), _("on"), buf2, options->file_ops.safe_delete_path);
+                       buf = g_strdup_printf(_("Using Geeqie Trash bin\n%s"), buf2);
                        g_free(buf2);
                        }
                else
                        {
-                       buf = g_strdup_printf(_("Safe delete: %s"), _("off"));
+                       buf = g_strdup(_("Using system Trash bin"));
                        }
                }
-               
+
        return buf;
 }
 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */