[Xfce4-commits] <xfdesktop:xfce-4.8> Implement open and empty actions for the trash.

Jannis Pohlmann noreply at xfce.org
Sat Jan 29 18:22:04 CET 2011


Updating branch refs/heads/xfce-4.8
         to d15eebaab48e640990205eafcaf10c71bd599b88 (commit)
       from 54cf26045b928b8b0c0e10fdb88ff6f6a82f8441 (commit)

commit d15eebaab48e640990205eafcaf10c71bd599b88
Author: Jannis Pohlmann <jannis at xfce.org>
Date:   Sat Jan 29 18:17:55 2011 +0100

    Implement open and empty actions for the trash.
    
    This makes the trash fully functional again. Unfortunately, it also
    required a new string to be added ("Could not empty the trash").

 NEWS                              |    1 +
 src/xfdesktop-file-utils.c        |   46 ++++++++++++++
 src/xfdesktop-file-utils.h        |    2 +
 src/xfdesktop-special-file-icon.c |  119 ++++--------------------------------
 4 files changed, 63 insertions(+), 105 deletions(-)

diff --git a/NEWS b/NEWS
index 07d7bb4..f8ada79 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,7 @@ Xfdesktop 4.x.y
   * Scroll to the selected background in the settings (bug #7087).
   * Handle volume changes in a timeout (bug #7025).
   * Implement monitoring for special file icons (bug #6986).
+  * Implement open and empty actions for the trash.
 
 
 Xfdesktop 4.8.0
diff --git a/src/xfdesktop-file-utils.c b/src/xfdesktop-file-utils.c
index c3c3e3b..33ffe64 100644
--- a/src/xfdesktop-file-utils.c
+++ b/src/xfdesktop-file-utils.c
@@ -900,6 +900,52 @@ xfdesktop_file_utils_trash_files(GList *files,
 }
 
 void
+xfdesktop_file_utils_empty_trash(GdkScreen *screen,
+                                 GtkWindow *parent)
+{
+    DBusGProxy *trash_proxy;
+    
+    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;
+        gchar *display_name = gdk_screen_make_display_name(screen);
+        gchar *startup_id = g_strdup_printf("_TIME%d", gtk_get_current_event_time());
+
+        xfdesktop_file_utils_set_window_cursor(parent, GDK_WATCH);
+        
+        if(!xfdesktop_trash_proxy_empty_trash(trash_proxy,
+                                              display_name, startup_id,
+                                              &error))
+        {
+            xfce_message_dialog(parent,
+                                _("Trash Error"), GTK_STOCK_DIALOG_ERROR,
+                                _("Could not empty 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_free(display_name);
+    } else {
+        xfce_message_dialog(parent,
+                            _("Trash Error"), GTK_STOCK_DIALOG_ERROR,
+                            _("Could not empty 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 73891d1..a44e53f 100644
--- a/src/xfdesktop-file-utils.h
+++ b/src/xfdesktop-file-utils.h
@@ -74,6 +74,8 @@ void xfdesktop_file_utils_rename_file(GFile *file,
 void xfdesktop_file_utils_trash_files(GList *files,
                                        GdkScreen *screen,
                                        GtkWindow *parent);
+void xfdesktop_file_utils_empty_trash(GdkScreen *screen,
+                                      GtkWindow *parent);
 void xfdesktop_file_utils_unlink_files(GList *files,
                                        GdkScreen *screen,
                                        GtkWindow *parent);
diff --git a/src/xfdesktop-special-file-icon.c b/src/xfdesktop-special-file-icon.c
index 7e0264c..8f0990c 100644
--- a/src/xfdesktop-special-file-icon.c
+++ b/src/xfdesktop-special-file-icon.c
@@ -44,8 +44,6 @@
 
 #include <libxfce4ui/libxfce4ui.h>
 
-#include <dbus/dbus-glib.h>
-
 #ifdef HAVE_THUNARX
 #include <thunarx/thunarx.h>
 #endif
@@ -53,7 +51,6 @@
 #include "xfdesktop-common.h"
 #include "xfdesktop-file-utils.h"
 #include "xfdesktop-special-file-icon.h"
-#include "xfdesktop-trash-proxy.h"
 
 struct _XfdesktopSpecialFileIconPrivate
 {
@@ -68,7 +65,6 @@ struct _XfdesktopSpecialFileIconPrivate
     GdkScreen *gscreen;
     
     /* only needed for trash */
-    DBusGProxy *dbus_proxy;
     gboolean trash_item_count;
 };
 
@@ -447,93 +443,18 @@ xfdesktop_special_file_icon_peek_tooltip(XfdesktopIcon *icon)
 }
 
 static void
-xfdesktop_special_file_icon_trash_handle_error(XfdesktopSpecialFileIcon *icon,
-                                               const gchar *method,
-                                               const gchar *message)
-{
-    GtkWidget *icon_view = xfdesktop_icon_peek_icon_view(XFDESKTOP_ICON(icon));
-    GtkWidget *toplevel = gtk_widget_get_toplevel(icon_view);
-    GtkWidget *dlg = xfce_message_dialog_new(GTK_WINDOW(toplevel),
-                                             _("Trash Error"),
-                                             GTK_STOCK_DIALOG_WARNING,
-                                             _("Unable to contact the Xfce Trash service."),
-                                             _("Make sure you have a file manager installed that supports the Xfce Trash service, such as Thunar."),
-                                             GTK_STOCK_CLOSE,
-                                             GTK_RESPONSE_ACCEPT, NULL);
-    gtk_dialog_run(GTK_DIALOG(dlg));
-    gtk_widget_destroy(dlg);
-    
-    g_warning("org.xfce.Trash.%s failed: %s", method ? method : "??",
-              message ? message : "??");
-}
-
-static void
-xfdesktop_special_file_icon_trash_open_cb(DBusGProxy *proxy,
-                                          GError *error,
-                                          gpointer user_data)
-{
-    GtkWidget *icon_view, *toplevel;
-    
-    icon_view = xfdesktop_icon_peek_icon_view(XFDESKTOP_ICON(user_data));
-    toplevel = gtk_widget_get_toplevel(icon_view);
-    xfdesktop_file_utils_set_window_cursor(GTK_WINDOW(toplevel),
-                                           GDK_LEFT_PTR);
-    
-    if(error) {
-        xfdesktop_special_file_icon_trash_handle_error(XFDESKTOP_SPECIAL_FILE_ICON(user_data),
-                                                       "DisplayTrash",
-                                                        error->message);
-    }
-    
-    g_object_unref(G_OBJECT(user_data));
-}
-
-static void
-xfdesktop_special_file_icon_trash_empty_cb(DBusGProxy *proxy,
-                                           GError *error,
-                                           gpointer user_data)
-{
-    if(error) {
-        xfdesktop_special_file_icon_trash_handle_error(XFDESKTOP_SPECIAL_FILE_ICON(user_data),
-                                                       "EmptyTrash",
-                                                        error->message);
-    }
-    
-    g_object_unref(G_OBJECT(user_data));
-}
-
-static void
 xfdesktop_special_file_icon_trash_open(GtkWidget *w,
                                        gpointer user_data)
 {
     XfdesktopSpecialFileIcon *file_icon = XFDESKTOP_SPECIAL_FILE_ICON(user_data);
+    GtkWidget *icon_view, *toplevel;
+
+    icon_view = xfdesktop_icon_peek_icon_view(XFDESKTOP_ICON(file_icon));
+    toplevel = gtk_widget_get_toplevel(icon_view);
     
-    if(G_LIKELY(file_icon->priv->dbus_proxy)) {
-        gchar *display_name = gdk_screen_make_display_name(file_icon->priv->gscreen);
-        gchar *startup_id = g_strdup_printf("_TIME%d", gtk_get_current_event_time());
-        
-        if(!xfdesktop_trash_proxy_display_trash_async(file_icon->priv->dbus_proxy,
-                                                      display_name, startup_id,
-                                                      xfdesktop_special_file_icon_trash_open_cb,
-                                                      file_icon))
-        {
-            xfdesktop_special_file_icon_trash_handle_error(file_icon,
-                                                           "DisplayTrash",
-                                                            NULL);
-        } else {
-            GtkWidget *icon_view, *toplevel;
-            
-            g_object_ref(G_OBJECT(file_icon));
-            
-            icon_view = xfdesktop_icon_peek_icon_view(XFDESKTOP_ICON(file_icon));
-            toplevel = gtk_widget_get_toplevel(icon_view);
-            xfdesktop_file_utils_set_window_cursor(GTK_WINDOW(toplevel),
-                                                   GDK_WATCH);
-        }
-            
-        g_free(startup_id);
-        g_free(display_name);
-    }
+    xfdesktop_file_utils_open_folder(file_icon->priv->file,
+                                     file_icon->priv->gscreen,
+                                     GTK_WINDOW(toplevel));
 }
 
 static void
@@ -541,25 +462,13 @@ xfdesktop_special_file_icon_trash_empty(GtkWidget *w,
                                         gpointer user_data)
 {
     XfdesktopSpecialFileIcon *file_icon = XFDESKTOP_SPECIAL_FILE_ICON(user_data);
-    
-    if(G_LIKELY(file_icon->priv->dbus_proxy)) {
-        gchar *display_name = gdk_screen_make_display_name(file_icon->priv->gscreen);
-        gchar *startup_id = g_strdup_printf("_TIME%d", gtk_get_current_event_time());
-        
-        if(!xfdesktop_trash_proxy_empty_trash_async(file_icon->priv->dbus_proxy,
-                                                    display_name, startup_id,
-                                                    xfdesktop_special_file_icon_trash_empty_cb,
-                                                    file_icon))
-        {
-            xfdesktop_special_file_icon_trash_handle_error(file_icon,
-                                                           "EmptyTrash",
-                                                            NULL);
-        } else
-            g_object_ref(G_OBJECT(file_icon));
-
-        g_free(startup_id);
-        g_free(display_name);
-    }
+    GtkWidget *icon_view, *toplevel;
+
+    icon_view = xfdesktop_icon_peek_icon_view(XFDESKTOP_ICON(file_icon));
+    toplevel = gtk_widget_get_toplevel(icon_view);
+
+    xfdesktop_file_utils_empty_trash(file_icon->priv->gscreen,
+                                     GTK_WINDOW(toplevel));
 }
 
 static gboolean



More information about the Xfce4-commits mailing list