[gnome-settings-daemon] housekeeping: use the nautilus DBus API to empty trash



commit fb02e429d7a415482349c0a037e248ae8a880c1a
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Tue Feb 22 23:39:52 2011 -0500

    housekeeping: use the nautilus DBus API to empty trash
    
    https://bugzilla.gnome.org/show_bug.cgi?id=632154

 plugins/housekeeping/Makefile.am            |   14 +-
 plugins/housekeeping/gsd-disk-space.c       |   70 +++++-
 plugins/housekeeping/gsd-disk-space.h       |    3 +
 plugins/housekeeping/gsd-empty-trash-test.c |   45 +++
 plugins/housekeeping/gsd-ldsm-trash-empty.c |  400 ---------------------------
 plugins/housekeeping/gsd-ldsm-trash-empty.h |   27 --
 6 files changed, 124 insertions(+), 435 deletions(-)
---
diff --git a/plugins/housekeeping/Makefile.am b/plugins/housekeeping/Makefile.am
index deed47c..a848658 100644
--- a/plugins/housekeeping/Makefile.am
+++ b/plugins/housekeeping/Makefile.am
@@ -1,12 +1,10 @@
 COMMON_FILES =				\
 	gsd-disk-space.c		\
 	gsd-disk-space.h		\
-	gsd-ldsm-trash-empty.c		\
-	gsd-ldsm-trash-empty.h		\
 	gsd-ldsm-dialog.c		\
 	gsd-ldsm-dialog.h
 
-noinst_PROGRAMS = gsd-disk-space-test
+noinst_PROGRAMS = gsd-disk-space-test gsd-empty-trash-test
 
 gsd_disk_space_test_SOURCES =		\
 	gsd-disk-space-test.c		\
@@ -18,6 +16,16 @@ gsd_disk_space_test_CFLAGS =		\
 	$(LIBNOTIFY_CFLAGS)		\
 	$(AM_CFLAGS)
 
+gsd_empty_trash_test_SOURCES =		\
+	gsd-empty-trash-test.c		\
+	$(COMMON_FILES)
+gsd_empty_trash_test_LDADD = $(SETTINGS_PLUGIN_LIBS) $(GIOUNIX_LIBS) $(LIBNOTIFY_LIBS)
+gsd_empty_trash_test_CFLAGS =		\
+	$(SETTINGS_PLUGIN_CFLAGS)	\
+	$(GIOUNIX_CFLAGS)		\
+	$(LIBNOTIFY_CFLAGS)		\
+	$(AM_CFLAGS)
+
 plugin_LTLIBRARIES = libhousekeeping.la
 
 libhousekeeping_la_SOURCES =		\
diff --git a/plugins/housekeeping/gsd-disk-space.c b/plugins/housekeeping/gsd-disk-space.c
index 5e815f1..7ea45de 100644
--- a/plugins/housekeeping/gsd-disk-space.c
+++ b/plugins/housekeeping/gsd-disk-space.c
@@ -37,8 +37,6 @@
 
 #include "gsd-disk-space.h"
 #include "gsd-ldsm-dialog.h"
-#include "gsd-ldsm-trash-empty.h"
-
 
 #define GIGABYTE                   1024 * 1024 * 1024
 
@@ -217,13 +215,76 @@ examine_callback (NotifyNotification *n,
 }
 
 static void
+nautilus_empty_trash_cb (GObject *object,
+                         GAsyncResult *res,
+                         gpointer _unused)
+{
+        GDBusProxy *proxy = G_DBUS_PROXY (object);
+        GError *error = NULL;
+
+        g_dbus_proxy_call_finish (proxy, res, &error);
+
+        if (error != NULL) {
+                g_warning ("Unable to call EmptyTrash() on the Nautilus DBus interface: %s",
+                           error->message);
+                g_error_free (error);
+        }
+
+        /* clean up the proxy object */
+        g_object_unref (proxy);
+}
+
+static void
+nautilus_proxy_ready_cb (GObject *object,
+                         GAsyncResult *res,
+                         gpointer _unused)
+{
+        GDBusProxy *proxy = NULL;
+        GError *error = NULL;
+
+        proxy = g_dbus_proxy_new_for_bus_finish (res, &error);
+
+        if (proxy == NULL) {
+                g_warning ("Unable to create a proxy object for the Nautilus DBus interface: %s",
+                           error->message);
+                g_error_free (error);
+
+                return;
+        }
+
+        g_dbus_proxy_call (proxy,
+                           "EmptyTrash",
+                           NULL,
+                           G_DBUS_CALL_FLAGS_NONE,
+                           -1,
+                           NULL,
+                           nautilus_empty_trash_cb,
+                           NULL);
+}
+
+void
+gsd_ldsm_show_empty_trash (void)
+{
+        /* prepare the Nautilus proxy object */
+        g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION,
+                                  G_DBUS_PROXY_FLAGS_NONE,
+                                  NULL,
+                                  "org.gnome.Nautilus",
+                                  "/org/gnome/Nautilus",
+                                  "org.gnome.Nautilus.FileOperations",
+                                  NULL,
+                                  nautilus_proxy_ready_cb,
+                                  NULL);
+}
+
+static void
 empty_trash_callback (NotifyNotification *n,
                       const char         *action)
 {
         g_assert (action != NULL);
         g_assert (strcmp (action, "empty-trash") == 0);
 
-        gsd_ldsm_trash_empty ();
+        gsd_ldsm_show_empty_trash ();
 
         notify_notification_close (n, NULL);
 }
@@ -355,7 +416,7 @@ ldsm_notify_for_mount (LdsmMountInfo *mount,
                         break;
                 case GSD_LDSM_DIALOG_RESPONSE_EMPTY_TRASH:
                         retval = TRUE;
-                        gsd_ldsm_trash_empty ();
+                        gsd_ldsm_show_empty_trash ();
                         break;
                 case GTK_RESPONSE_NONE:
                 case GTK_RESPONSE_DELETE_EVENT:
@@ -798,7 +859,6 @@ gsd_ldsm_setup (gboolean check_now)
 
         ldsm_timeout_id = g_timeout_add_seconds (CHECK_EVERY_X_SECONDS,
                                                  ldsm_check_all_mounts, NULL);
-
 }
 
 void
diff --git a/plugins/housekeeping/gsd-disk-space.h b/plugins/housekeeping/gsd-disk-space.h
index cb458ca..363b73a 100644
--- a/plugins/housekeeping/gsd-disk-space.h
+++ b/plugins/housekeeping/gsd-disk-space.h
@@ -31,6 +31,9 @@ G_BEGIN_DECLS
 void gsd_ldsm_setup (gboolean check_now);
 void gsd_ldsm_clean (void);
 
+/* for the test */
+void gsd_ldsm_show_empty_trash (void);
+
 G_END_DECLS
 
 #endif /* __GSD_DISK_SPACE_H */
diff --git a/plugins/housekeeping/gsd-empty-trash-test.c b/plugins/housekeeping/gsd-empty-trash-test.c
new file mode 100644
index 0000000..6abf29f
--- /dev/null
+++ b/plugins/housekeeping/gsd-empty-trash-test.c
@@ -0,0 +1,45 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ * vim: set et sw=8 ts=8:
+ *
+ * Copyright (c) 2011, Red Hat, Inc.
+ *
+ * Authors: Cosimo Cecchi <cosimoc redhat com>
+ *
+ * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#include "config.h"
+#include <gtk/gtk.h>
+#include "gsd-disk-space.h"
+
+int
+main (int    argc,
+      char **argv)
+{
+        GMainLoop *loop;
+
+        gtk_init (&argc, &argv);
+
+        loop = g_main_loop_new (NULL, FALSE);
+
+        gsd_ldsm_show_empty_trash ();
+        g_main_loop_run (loop);
+
+        g_main_loop_unref (loop);
+
+        return 0;
+}
+



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]