[gnome-applets/wip/muktupavels/empty-trash] trash: use Nautilus to empty trash
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-applets/wip/muktupavels/empty-trash] trash: use Nautilus to empty trash
- Date: Tue, 7 Apr 2020 10:32:57 +0000 (UTC)
commit 0771a8b0bbdcb6d3ff66c18c857e877b724c04f7
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Tue Apr 7 13:07:18 2020 +0300
trash: use Nautilus to empty trash
gnome-applets/Makefile.am | 1 -
gnome-applets/trash/Makefile.am | 22 +-
.../trash/org.gnome.Nautilus.FileOperations2.xml | 14 +
gnome-applets/trash/trash-applet.c | 108 +++++-
gnome-applets/trash/trash-empty.c | 369 ---------------------
gnome-applets/trash/trash-empty.h | 27 --
gnome-applets/trash/trash-empty.ui | 123 -------
po/POTFILES.in | 2 -
8 files changed, 139 insertions(+), 527 deletions(-)
---
diff --git a/gnome-applets/Makefile.am b/gnome-applets/Makefile.am
index 8c7811814..7459ce1b9 100644
--- a/gnome-applets/Makefile.am
+++ b/gnome-applets/Makefile.am
@@ -168,7 +168,6 @@ ui_files = \
sticky-notes/ui/sticky-notes-preferences.ui \
sticky-notes/ui/sticky-notes-properties.ui \
timer/timer-applet-menu.ui \
- trash/trash-empty.ui \
trash/trash-menu.ui \
window-buttons/window-buttons.ui \
window-buttons/window-buttons-menu.ui \
diff --git a/gnome-applets/trash/Makefile.am b/gnome-applets/trash/Makefile.am
index 5983605bf..fcc40c463 100644
--- a/gnome-applets/trash/Makefile.am
+++ b/gnome-applets/trash/Makefile.am
@@ -31,8 +31,26 @@ libtrash_applet_la_LIBADD = \
libtrash_applet_la_SOURCES = \
trash-applet.c \
trash-applet.h \
- trash-empty.h \
- trash-empty.c \
+ $(BUILT_SOURCES) \
+ $(NULL)
+
+ta-nautilus-gen.h:
+ta-nautilus-gen.c: org.gnome.Nautilus.FileOperations2.xml
+ $(AM_V_GEN) $(GDBUS_CODEGEN) --c-namespace Ta \
+ --generate-c-code ta-nautilus-gen \
+ $(srcdir)/org.gnome.Nautilus.FileOperations2.xml
+
+BUILT_SOURCES = \
+ ta-nautilus-gen.c \
+ ta-nautilus-gen.h \
+ $(NULL)
+
+CLEANFILES = \
+ $(BUILT_SOURCES) \
+ $(NULL)
+
+EXTRA_DIST = \
+ org.gnome.Nautilus.FileOperations2.xml \
$(NULL)
-include $(top_srcdir)/git.mk
diff --git a/gnome-applets/trash/org.gnome.Nautilus.FileOperations2.xml
b/gnome-applets/trash/org.gnome.Nautilus.FileOperations2.xml
new file mode 100644
index 000000000..e048d3c7d
--- /dev/null
+++ b/gnome-applets/trash/org.gnome.Nautilus.FileOperations2.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
+"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
+<node>
+ <interface name="org.gnome.Nautilus.FileOperations2">
+ <annotation name="org.gtk.GDBus.C.Name" value="NautilusGen" />
+
+ <method name='EmptyTrash'>
+ <arg type="b" name="ask_confirmation" direction='in'/>
+ <arg type='a{sv}' name='platform_data' direction='in'/>
+ </method>
+
+ </interface>
+</node>
diff --git a/gnome-applets/trash/trash-applet.c b/gnome-applets/trash/trash-applet.c
index 243963f86..6c2082b4c 100644
--- a/gnome-applets/trash/trash-applet.c
+++ b/gnome-applets/trash/trash-applet.c
@@ -28,12 +28,16 @@
#include <gdk/gdkkeysyms.h>
#include <gio/gio.h>
-#include "trash-empty.h"
+#include "ta-nautilus-gen.h"
struct _TrashApplet
{
GpApplet parent;
+ GCancellable *cancellable;
+
+ TaNautilusGen *nautilus;
+
GFileMonitor *trash_monitor;
GFile *trash;
@@ -75,6 +79,32 @@ static const GActionEntry trash_applet_menu_actions [] = {
{ NULL }
};
+static void
+nautilus_ready_cb (GObject *object,
+ GAsyncResult *res,
+ gpointer user_data)
+
+{
+ GError *error;
+ TaNautilusGen *nautilus;
+ TrashApplet *self;
+
+ error = NULL;
+ nautilus = ta_nautilus_gen_proxy_new_for_bus_finish (res, &error);
+
+ if (error != NULL)
+ {
+ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ g_warning ("%s", error->message);
+
+ g_error_free (error);
+ return;
+ }
+
+ self = TRASH_APPLET (user_data);
+ self->nautilus = nautilus;
+}
+
static void
trash_applet_monitor_changed (TrashApplet *applet)
{
@@ -181,11 +211,36 @@ trash_applet_size_allocate (GtkWidget *widget,
->size_allocate (widget, allocation);
}
+static void
+trash_applet_constructed (GObject *object)
+{
+ TrashApplet *self;
+
+ self = TRASH_APPLET (object);
+
+ G_OBJECT_CLASS (trash_applet_parent_class)->constructed (object);
+
+ self->cancellable = g_cancellable_new ();
+
+ ta_nautilus_gen_proxy_new_for_bus (G_BUS_TYPE_SESSION,
+ G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START_AT_CONSTRUCTION,
+ "org.gnome.Nautilus",
+ "/org/gnome/Nautilus/FileOperations2",
+ self->cancellable,
+ nautilus_ready_cb,
+ self);
+}
+
static void
trash_applet_dispose (GObject *object)
{
TrashApplet *applet = TRASH_APPLET (object);
+ g_cancellable_cancel (applet->cancellable);
+ g_clear_object (&applet->cancellable);
+
+ g_clear_object (&applet->nautilus);
+
if (applet->trash_monitor)
g_object_unref (applet->trash_monitor);
applet->trash_monitor = NULL;
@@ -313,13 +368,59 @@ error_dialog (TrashApplet *applet, const gchar *error, ...)
g_free (error_string);
}
+static GVariant *
+get_platform_data (guint32 timestamp)
+{
+ GVariantBuilder builder;
+
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
+
+ g_variant_builder_add (&builder,
+ "{sv}",
+ "timestamp",
+ g_variant_new_uint32 (timestamp));
+
+ return g_variant_builder_end (&builder);
+}
+
+static void
+empty_trash_cb (GObject *object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ GError *error;
+
+ error = NULL;
+ ta_nautilus_gen_call_empty_trash_finish (TA_NAUTILUS_GEN (object),
+ res,
+ &error);
+
+ if (error != NULL)
+ {
+ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ g_warning ("Error emptying trash: %s", error->message);
+ g_error_free (error);
+ }
+}
+
static void
trash_applet_do_empty (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
- TrashApplet *applet = (TrashApplet *) user_data;
- trash_empty (GTK_WIDGET (applet));
+ TrashApplet *self;
+ guint32 timestamp;
+
+ self = TRASH_APPLET (user_data);
+
+ timestamp = gtk_get_current_event_time ();
+
+ ta_nautilus_gen_call_empty_trash (self->nautilus,
+ TRUE,
+ get_platform_data (timestamp),
+ self->cancellable,
+ empty_trash_cb,
+ self);
}
static void
@@ -507,6 +608,7 @@ trash_applet_class_init (TrashAppletClass *self_class)
object_class = G_OBJECT_CLASS (self_class);
widget_class = GTK_WIDGET_CLASS (self_class);
+ object_class->constructed = trash_applet_constructed;
object_class->dispose = trash_applet_dispose;
widget_class->size_allocate = trash_applet_size_allocate;
diff --git a/po/POTFILES.in b/po/POTFILES.in
index c7e71ec60..903fef828 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -73,8 +73,6 @@ gnome-applets/tracker-search-bar/tracker-applet.c
gnome-applets/tracker-search-bar/tracker-results-window.c
gnome-applets/tracker-search-bar/tracker-search-bar-menu.ui
gnome-applets/trash/trash-applet.c
-gnome-applets/trash/trash-empty.c
-gnome-applets/trash/trash-empty.ui
gnome-applets/trash/trash-menu.ui
gnome-applets/window-buttons/window-buttons.c
gnome-applets/window-buttons/window-buttons.ui
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]