[Xfce4-commits] <xfdesktop:master> Add xfdesktop_file_utils_trash_files() to move files to the trash.

Jannis Pohlmann noreply at xfce.org
Tue Nov 2 01:14:39 CET 2010


Updating branch refs/heads/master
         to 72ab19e02f85f486ef19fb5f33adc6251921fee6 (commit)
       from 064843c5a293a5dda9093e31bf999921e0f66475 (commit)

commit 72ab19e02f85f486ef19fb5f33adc6251921fee6
Author: Jannis Pohlmann <jannis at xfce.org>
Date:   Tue Oct 26 21:32:18 2010 +0200

    Add xfdesktop_file_utils_trash_files() to move files to the trash.

 src/xfdesktop-file-utils.c |   60 ++++++++++++++++++++++++++++++++++++++++++++
 src/xfdesktop-file-utils.h |    3 ++
 2 files changed, 63 insertions(+), 0 deletions(-)

diff --git a/src/xfdesktop-file-utils.c b/src/xfdesktop-file-utils.c
index cda6178..a3d925f 100644
--- a/src/xfdesktop-file-utils.c
+++ b/src/xfdesktop-file-utils.c
@@ -52,6 +52,7 @@
 #include "xfdesktop-file-icon.h"
 #include "xfdesktop-file-manager-proxy.h"
 #include "xfdesktop-file-utils.h"
+#include "xfdesktop-trash-proxy.h"
 
 ThunarVfsInteractiveJobResponse
 xfdesktop_file_utils_interactive_job_ask(GtkWindow *parent,
@@ -700,6 +701,65 @@ xfdesktop_file_utils_unlink_files(GList *files,
 }
 
 void
+xfdesktop_file_utils_trash_files(GList *files,
+                                 GdkScreen *screen,
+                                 GtkWindow *parent)
+{
+    DBusGProxy *trash_proxy;
+    
+    g_return_if_fail(files != NULL && G_IS_FILE(files->data));
+    g_return_if_fail(GDK_IS_SCREEN(screen) || GTK_IS_WINDOW(parent));
+    
+    if(!screen)
+        screen = gtk_widget_get_screen(GTK_WIDGET(parent));
+    
+    trash_proxy = xfdesktop_file_utils_peek_trash_proxy();
+    if(trash_proxy) {
+        GError *error = NULL;
+        guint nfiles = g_list_length(files);
+        gchar **uris = g_new0(gchar *, nfiles+1);
+        gchar *display_name = gdk_screen_make_display_name(screen);
+        gchar *startup_id = g_strdup_printf("_TIME%d", gtk_get_current_event_time());
+        GList *lp;
+        gint n;
+
+        /* convert GFile list into an array of URIs */
+        for(n = 0, lp = files; lp != NULL; ++n, lp = lp->next)
+            uris[n] = g_file_get_uri(lp->data);
+        uris[n] = NULL;
+
+        xfdesktop_file_utils_set_window_cursor(parent, GDK_WATCH);
+        
+        if(!xfdesktop_trash_proxy_move_to_trash(trash_proxy,
+                                                (const gchar **)uris, 
+                                                display_name, startup_id,
+                                                &error))
+        {
+            xfce_message_dialog(parent,
+                                _("Trash Error"), GTK_STOCK_DIALOG_ERROR,
+                                _("The selected files could not be moved to the trash"),
+                                error->message, GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT, 
+                                NULL);
+
+            g_error_free(error);
+        }
+
+        xfdesktop_file_utils_set_window_cursor(parent, GDK_LEFT_PTR);
+        
+        g_free(startup_id);
+        g_strfreev(uris);
+        g_free(display_name);
+    } else {
+        xfce_message_dialog(parent,
+                            _("Delete Error"), GTK_STOCK_DIALOG_ERROR,
+                            _("The selected files could not be moved to the trash"),
+                            _("This feature requires a trash service to "
+                              "be present (such as the one supplied by Thunar)."),
+                            GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT, NULL);
+    }
+}
+
+void
 xfdesktop_file_utils_create_file(GFile *parent_folder,
                                  const gchar *content_type,
                                  GdkScreen *screen,
diff --git a/src/xfdesktop-file-utils.h b/src/xfdesktop-file-utils.h
index 5f37e95..fa25960 100644
--- a/src/xfdesktop-file-utils.h
+++ b/src/xfdesktop-file-utils.h
@@ -91,6 +91,9 @@ void xfdesktop_file_utils_open_folder(GFile *file,
 void xfdesktop_file_utils_rename_file(GFile *file,
                                       GdkScreen *screen,
                                       GtkWindow *parent);
+void xfdesktop_file_utils_trash_files(GList *files,
+                                       GdkScreen *screen,
+                                       GtkWindow *parent);
 void xfdesktop_file_utils_unlink_files(GList *files,
                                        GdkScreen *screen,
                                        GtkWindow *parent);



More information about the Xfce4-commits mailing list