[gnome-flashback/nautilus-file-operations2: 3/4] desktop: add support for org.gnome.Nautilus.FileOperations2
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-flashback/nautilus-file-operations2: 3/4] desktop: add support for org.gnome.Nautilus.FileOperations2
- Date: Fri, 31 Jan 2020 15:38:15 +0000 (UTC)
commit 289ac82ed43466015008f054979171dcf20dd025
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Fri Jan 31 17:30:00 2020 +0200
desktop: add support for org.gnome.Nautilus.FileOperations2
gnome-flashback/libdesktop/gf-icon-view.c | 479 +++++++++++++++++++++++----
gnome-flashback/libdesktop/gf-icon-view.h | 15 +-
gnome-flashback/libdesktop/gf-icon.c | 11 +-
gnome-flashback/libdesktop/gf-monitor-view.c | 20 +-
4 files changed, 447 insertions(+), 78 deletions(-)
---
diff --git a/gnome-flashback/libdesktop/gf-icon-view.c b/gnome-flashback/libdesktop/gf-icon-view.c
index 11f4749..3462897 100644
--- a/gnome-flashback/libdesktop/gf-icon-view.c
+++ b/gnome-flashback/libdesktop/gf-icon-view.c
@@ -18,10 +18,13 @@
#include "config.h"
#include "gf-icon-view.h"
+#include <gdk/gdkx.h>
#include <glib/gi18n.h>
+#include "dbus/gf-fd-dbus-introspectable-gen.h"
#include "dbus/gf-file-manager-gen.h"
#include "dbus/gf-nautilus-gen.h"
+#include "dbus/gf-nautilus2-gen.h"
#include "gf-create-folder-dialog.h"
#include "gf-desktop-enum-types.h"
#include "gf-desktop-enums.h"
@@ -78,6 +81,7 @@ struct _GfIconView
GList *rubberband_icons;
GfNautilusGen *nautilus;
+ GfNautilus2Gen *nautilus2;
GfFileManagerGen *file_manager;
GtkWidget *create_folder_dialog;
@@ -109,6 +113,39 @@ static guint view_signals[LAST_SIGNAL] = { 0 };
G_DEFINE_TYPE (GfIconView, gf_icon_view, GTK_TYPE_EVENT_BOX)
+static GVariant *
+get_platform_data (GfIconView *self,
+ guint32 timestamp)
+{
+ GVariantBuilder builder;
+ GtkWidget *toplevel;
+ GdkWindow *window;
+ char *parent_handle;
+
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
+
+ toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self));
+ window = gtk_widget_get_window (toplevel);
+ parent_handle = g_strdup_printf ("x11:%lx", gdk_x11_window_get_xid (window));
+
+ g_variant_builder_add (&builder,
+ "{sv}",
+ "parent-handle",
+ g_variant_new_take_string (parent_handle));
+
+ g_variant_builder_add (&builder,
+ "{sv}",
+ "timestamp",
+ g_variant_new_uint32 (timestamp));
+
+ g_variant_builder_add (&builder,
+ "{sv}",
+ "window-position",
+ g_variant_new_string ("center"));
+
+ return g_variant_builder_end (&builder);
+}
+
static char *
build_attributes_list (const char *first,
...)
@@ -516,7 +553,26 @@ empty_trash_cb (GObject *object,
if (error != NULL)
{
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
- g_warning ("Error creating new folder: %s", error->message);
+ g_warning ("Error emptying trash: %s", error->message);
+ g_error_free (error);
+ }
+}
+
+static void
+empty_trash2_cb (GObject *object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ GError *error;
+
+ error = NULL;
+ gf_nautilus2_gen_call_empty_trash_finish (GF_NAUTILUS2_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);
}
}
@@ -540,6 +596,25 @@ trash_files_cb (GObject *object,
}
}
+static void
+trash_files2_cb (GObject *object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ GError *error;
+
+ error = NULL;
+ gf_nautilus2_gen_call_trash_files_finish (GF_NAUTILUS2_GEN (object),
+ res, &error);
+
+ if (error != NULL)
+ {
+ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ g_warning ("Error moving files to trash: %s", error->message);
+ g_error_free (error);
+ }
+}
+
static void
rename_file_cb (GObject *object,
GAsyncResult *res,
@@ -559,6 +634,25 @@ rename_file_cb (GObject *object,
}
}
+static void
+rename_file2_cb (GObject *object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ GError *error;
+
+ error = NULL;
+ gf_nautilus2_gen_call_rename_file_finish (GF_NAUTILUS2_GEN (object),
+ res, &error);
+
+ if (error != NULL)
+ {
+ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ g_warning ("Error renaming file: %s", error->message);
+ g_error_free (error);
+ }
+}
+
static void
copy_uris_cb (GObject *object,
GAsyncResult *res,
@@ -578,6 +672,25 @@ copy_uris_cb (GObject *object,
}
}
+static void
+copy_uris2_cb (GObject *object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ GError *error;
+
+ error = NULL;
+ gf_nautilus2_gen_call_copy_uris_finish (GF_NAUTILUS2_GEN (object),
+ res, &error);
+
+ if (error != NULL)
+ {
+ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ g_warning ("Error copying uris: %s", error->message);
+ g_error_free (error);
+ }
+}
+
static void
move_uris_cb (GObject *object,
GAsyncResult *res,
@@ -597,6 +710,25 @@ move_uris_cb (GObject *object,
}
}
+static void
+move_uris2_cb (GObject *object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ GError *error;
+
+ error = NULL;
+ gf_nautilus2_gen_call_move_uris_finish (GF_NAUTILUS2_GEN (object),
+ res, &error);
+
+ if (error != NULL)
+ {
+ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ g_warning ("Error moving uris: %s", error->message);
+ g_error_free (error);
+ }
+}
+
static GfIconInfo *
create_icon_info (GfIconView *self,
GtkWidget *icon)
@@ -852,6 +984,25 @@ create_folder_cb (GObject *object,
}
}
+static void
+create_folder2_cb (GObject *object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ GError *error;
+
+ error = NULL;
+ gf_nautilus2_gen_call_create_folder_finish (GF_NAUTILUS2_GEN (object),
+ res, &error);
+
+ if (error != NULL)
+ {
+ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ g_warning ("Error creating new folder: %s", error->message);
+ g_error_free (error);
+ }
+}
+
static void
create_folder_dialog_response_cb (GtkDialog *dialog,
gint response_id,
@@ -874,10 +1025,31 @@ create_folder_dialog_response_cb (GtkDialog *dialog,
uri = g_file_get_uri (new_file);
g_object_unref (new_file);
- gf_nautilus_gen_call_create_folder (self->nautilus, uri,
- self->cancellable,
- create_folder_cb,
- NULL);
+ if (self->nautilus2 != NULL)
+ {
+ guint32 timestamp;
+
+ timestamp = gtk_get_current_event_time ();
+
+ gf_nautilus2_gen_call_create_folder (self->nautilus2,
+ uri,
+ get_platform_data (self, timestamp),
+ self->cancellable,
+ create_folder2_cb,
+ NULL);
+ }
+ else if (self->nautilus != NULL)
+ {
+ gf_nautilus_gen_call_create_folder (self->nautilus,
+ uri,
+ self->cancellable,
+ create_folder_cb,
+ NULL);
+ }
+ else
+ {
+ g_assert_not_reached ();
+ }
gtk_widget_destroy (GTK_WIDGET (dialog));
g_free (uri);
@@ -896,7 +1068,8 @@ new_folder_cb (GtkMenuItem *item,
{
GtkWidget *dialog;
- if (self->nautilus == NULL)
+ if (self->nautilus2 == NULL &&
+ self->nautilus == NULL)
return;
if (self->create_folder_dialog != NULL)
@@ -1648,7 +1821,7 @@ enumerate_desktop (GfIconView *self)
}
static void
-nautilus_ready_cb (GObject *object,
+nautilus_ready_cb (GObject *object,
GAsyncResult *res,
gpointer user_data)
@@ -1673,6 +1846,133 @@ nautilus_ready_cb (GObject *object,
self->nautilus = nautilus;
}
+static void
+nautilus2_ready_cb (GObject *object,
+ GAsyncResult *res,
+ gpointer user_data)
+
+{
+ GError *error;
+ GfNautilus2Gen *nautilus2;
+ GfIconView *self;
+
+ error = NULL;
+ nautilus2 = gf_nautilus2_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 = GF_ICON_VIEW (user_data);
+ self->nautilus2 = nautilus2;
+}
+
+static void
+introspect_cb (GObject *object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ GError *error;
+ char *xml_data;
+ GfIconView *self;
+ GDBusNodeInfo *info;
+ gboolean file_operations2;
+ int i;
+
+ xml_data = NULL;
+ error = NULL;
+
+ gf_fd_dbus_introspectable_gen_call_introspect_finish (GF_FD_DBUS_INTROSPECTABLE_GEN (object),
+ &xml_data,
+ 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 = GF_ICON_VIEW (user_data);
+
+ info = g_dbus_node_info_new_for_xml (xml_data, NULL);
+ g_free (xml_data);
+
+ file_operations2 = FALSE;
+ for (i = 0; info->interfaces[i] != NULL; i++)
+ {
+ if (g_strcmp0 (info->interfaces[i]->name, "org.gnome.Nautilus.FileOperations2") == 0)
+ {
+ file_operations2 = TRUE;
+ break;
+ }
+ }
+
+ if (file_operations2)
+ {
+ gf_nautilus2_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",
+ self->cancellable,
+ nautilus2_ready_cb,
+ self);
+ }
+ else
+ {
+ gf_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",
+ self->cancellable,
+ nautilus_ready_cb,
+ self);
+ }
+
+ g_dbus_node_info_unref (info);
+}
+
+static void
+introspectable_ready_cb (GObject *object,
+ GAsyncResult *res,
+ gpointer user_data)
+
+{
+ GError *error;
+ GfFdDBusIntrospectableGen *introspectable;
+ GfIconView *self;
+
+ error = NULL;
+ introspectable = gf_fd_dbus_introspectable_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 = GF_ICON_VIEW (user_data);
+
+ gf_fd_dbus_introspectable_gen_call_introspect (introspectable,
+ self->cancellable,
+ introspect_cb,
+ self);
+
+ g_object_unref (introspectable);
+}
+
static void
file_manager_ready_cb (GObject *object,
GAsyncResult *res,
@@ -2017,7 +2317,9 @@ trash_cb (GfIconView *self,
if (uris == NULL)
return;
- gf_icon_view_move_to_trash (self, (const char * const *) uris);
+ gf_icon_view_move_to_trash (self,
+ (const char * const *) uris,
+ gtk_get_current_event_time ());
g_strfreev (uris);
}
@@ -2388,6 +2690,7 @@ gf_icon_view_dispose (GObject *object)
g_clear_pointer (&self->rubberband_icons, g_list_free);
g_clear_object (&self->nautilus);
+ g_clear_object (&self->nautilus2);
g_clear_object (&self->file_manager);
g_clear_pointer (&self->create_folder_dialog, gtk_widget_destroy);
@@ -2833,13 +3136,13 @@ gf_icon_view_init (GfIconView *self)
self->cancellable = g_cancellable_new ();
- gf_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",
- self->cancellable,
- nautilus_ready_cb,
- self);
+ gf_fd_dbus_introspectable_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",
+ self->cancellable,
+ introspectable_ready_cb,
+ self);
gf_file_manager_gen_proxy_new_for_bus (G_BUS_TYPE_SESSION,
G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START_AT_CONSTRUCTION,
@@ -2988,15 +3291,24 @@ gf_icon_view_show_item_properties (GfIconView *self,
}
void
-gf_icon_view_empty_trash (GfIconView *self)
+gf_icon_view_empty_trash (GfIconView *self,
+ guint32 timestamp)
{
- if (self->nautilus == NULL)
- return;
-
- gf_nautilus_gen_call_empty_trash (self->nautilus,
- self->cancellable,
- empty_trash_cb,
- NULL);
+ if (self->nautilus2 != NULL)
+ {
+ gf_nautilus2_gen_call_empty_trash (self->nautilus2,
+ get_platform_data (self, timestamp),
+ self->cancellable,
+ empty_trash2_cb,
+ NULL);
+ }
+ else if (self->nautilus != NULL)
+ {
+ gf_nautilus_gen_call_empty_trash (self->nautilus,
+ self->cancellable,
+ empty_trash_cb,
+ NULL);
+ }
}
gboolean
@@ -3084,62 +3396,105 @@ gf_icon_view_validate_new_name (GfIconView *self,
void
gf_icon_view_move_to_trash (GfIconView *self,
- const char * const *uris)
+ const char * const *uris,
+ guint32 timestamp)
{
- if (self->nautilus == NULL)
- return;
-
- gf_nautilus_gen_call_trash_files (self->nautilus,
- uris,
- self->cancellable,
- trash_files_cb,
- NULL);
+ if (self->nautilus2 != NULL)
+ {
+ gf_nautilus2_gen_call_trash_files (self->nautilus2,
+ uris,
+ get_platform_data (self, timestamp),
+ self->cancellable,
+ trash_files2_cb,
+ NULL);
+ }
+ else if (self->nautilus != NULL)
+ {
+ gf_nautilus_gen_call_trash_files (self->nautilus,
+ uris,
+ self->cancellable,
+ trash_files_cb,
+ NULL);
+ }
}
void
gf_icon_view_rename_file (GfIconView *self,
const char *uri,
- const char *new_name)
+ const char *new_name,
+ guint32 timestamp)
{
- if (self->nautilus == NULL)
- return;
-
- gf_nautilus_gen_call_rename_file (self->nautilus,
- uri,
- new_name,
- self->cancellable,
- rename_file_cb,
- NULL);
+ if (self->nautilus2 != NULL)
+ {
+ gf_nautilus2_gen_call_rename_file (self->nautilus2,
+ uri,
+ new_name,
+ get_platform_data (self, timestamp),
+ self->cancellable,
+ rename_file2_cb,
+ NULL);
+ }
+ else if (self->nautilus != NULL)
+ {
+ gf_nautilus_gen_call_rename_file (self->nautilus,
+ uri,
+ new_name,
+ self->cancellable,
+ rename_file_cb,
+ NULL);
+ }
}
void
gf_icon_view_copy_uris (GfIconView *self,
const char * const *uris,
- const char *destination)
+ const char *destination,
+ guint32 timestamp)
{
- if (self->nautilus == NULL)
- return;
-
- gf_nautilus_gen_call_copy_uris (self->nautilus,
- uris,
- destination,
- self->cancellable,
- copy_uris_cb,
- NULL);
+ if (self->nautilus2 != NULL)
+ {
+ gf_nautilus2_gen_call_copy_uris (self->nautilus2,
+ uris,
+ destination,
+ get_platform_data (self, timestamp),
+ self->cancellable,
+ copy_uris2_cb,
+ NULL);
+ }
+ else if (self->nautilus != NULL)
+ {
+ gf_nautilus_gen_call_copy_uris (self->nautilus,
+ uris,
+ destination,
+ self->cancellable,
+ copy_uris_cb,
+ NULL);
+ }
}
void
gf_icon_view_move_uris (GfIconView *self,
const char * const *uris,
- const char *destination)
+ const char *destination,
+ guint32 timestamp)
{
- if (self->nautilus == NULL)
- return;
-
- gf_nautilus_gen_call_move_uris (self->nautilus,
- uris,
- destination,
- self->cancellable,
- move_uris_cb,
- NULL);
+ if (self->nautilus2 != NULL)
+ {
+ gf_nautilus2_gen_call_move_uris (self->nautilus2,
+ uris,
+ destination,
+ get_platform_data (self, timestamp),
+ self->cancellable,
+ move_uris2_cb,
+ NULL);
+ }
+ else if (self->nautilus != NULL)
+ {
+ gf_nautilus_gen_call_move_uris (self->nautilus,
+ uris,
+ destination,
+ self->cancellable,
+ move_uris_cb,
+ NULL);
+ }
}
diff --git a/gnome-flashback/libdesktop/gf-icon-view.h b/gnome-flashback/libdesktop/gf-icon-view.h
index 8d3be92..697ee00 100644
--- a/gnome-flashback/libdesktop/gf-icon-view.h
+++ b/gnome-flashback/libdesktop/gf-icon-view.h
@@ -47,7 +47,8 @@ GList *gf_icon_view_get_selected_icons (GfIconView *
void gf_icon_view_show_item_properties (GfIconView *self,
const char * const *uris);
-void gf_icon_view_empty_trash (GfIconView *self);
+void gf_icon_view_empty_trash (GfIconView *self,
+ guint32 timestamp);
gboolean gf_icon_view_validate_new_name (GfIconView *self,
GFileType file_type,
@@ -55,19 +56,23 @@ gboolean gf_icon_view_validate_new_name (GfIconView *
char **message);
void gf_icon_view_move_to_trash (GfIconView *self,
- const char * const *uris);
+ const char * const *uris,
+ guint32 timestamp);
void gf_icon_view_rename_file (GfIconView *self,
const char *uri,
- const char *new_name);
+ const char *new_name,
+ guint32 timestamp);
void gf_icon_view_copy_uris (GfIconView *self,
const char * const *uris,
- const char *destination);
+ const char *destination,
+ guint32 timestamp);
void gf_icon_view_move_uris (GfIconView *self,
const char * const *uris,
- const char *destination);
+ const char *destination,
+ guint32 timestamp);
G_END_DECLS
diff --git a/gnome-flashback/libdesktop/gf-icon.c b/gnome-flashback/libdesktop/gf-icon.c
index c081307..77c6fcc 100644
--- a/gnome-flashback/libdesktop/gf-icon.c
+++ b/gnome-flashback/libdesktop/gf-icon.c
@@ -385,7 +385,10 @@ rename_do_rename_cb (GfRenamePopover *popover,
char *uri;
uri = g_file_get_uri (priv->file);
- gf_icon_view_rename_file (priv->icon_view, uri, new_name);
+ gf_icon_view_rename_file (priv->icon_view,
+ uri,
+ new_name,
+ gtk_get_current_event_time ());
g_free (uri);
}
@@ -431,7 +434,9 @@ move_to_trash_cb (GtkMenuItem *item,
if (uris == NULL)
return;
- gf_icon_view_move_to_trash (priv->icon_view, (const char * const *) uris);
+ gf_icon_view_move_to_trash (priv->icon_view,
+ (const char * const *) uris,
+ gtk_get_current_event_time ());
g_strfreev (uris);
}
@@ -475,7 +480,7 @@ empty_trash_cb (GtkMenuItem *item,
priv = gf_icon_get_instance_private (self);
- gf_icon_view_empty_trash (priv->icon_view);
+ gf_icon_view_empty_trash (priv->icon_view, gtk_get_current_event_time ());
}
static void
diff --git a/gnome-flashback/libdesktop/gf-monitor-view.c b/gnome-flashback/libdesktop/gf-monitor-view.c
index c9e3d87..bdf76a1 100644
--- a/gnome-flashback/libdesktop/gf-monitor-view.c
+++ b/gnome-flashback/libdesktop/gf-monitor-view.c
@@ -456,7 +456,8 @@ get_uris_from_gnome_icon_list (GfMonitorView *self,
static void
copy_to_desktop (GfMonitorView *self,
- char **uris)
+ char **uris,
+ guint time)
{
char *desktop_uri;
@@ -464,14 +465,16 @@ copy_to_desktop (GfMonitorView *self,
gf_icon_view_copy_uris (self->icon_view,
(const char * const *) uris,
- desktop_uri);
+ desktop_uri,
+ time);
g_free (desktop_uri);
}
static void
move_to_desktop (GfMonitorView *self,
- char **uris)
+ char **uris,
+ guint time)
{
char *desktop_uri;
@@ -479,7 +482,8 @@ move_to_desktop (GfMonitorView *self,
gf_icon_view_move_uris (self->icon_view,
(const char * const *) uris,
- desktop_uri);
+ desktop_uri,
+ time);
g_free (desktop_uri);
}
@@ -582,7 +586,7 @@ drag_data_received_cb (GtkWidget *widget,
uris = get_uris_from_icon_list (self, icon);
- copy_to_desktop (self, uris);
+ copy_to_desktop (self, uris, time);
g_strfreev (uris);
success = TRUE;
@@ -603,7 +607,7 @@ drag_data_received_cb (GtkWidget *widget,
uris = get_uris_from_gnome_icon_list (self, selection_data);
- move_to_desktop (self, uris);
+ move_to_desktop (self, uris, time);
g_strfreev (uris);
success = TRUE;
@@ -618,7 +622,7 @@ drag_data_received_cb (GtkWidget *widget,
uris = get_uris_from_gnome_icon_list (self, selection_data);
- copy_to_desktop (self, uris);
+ copy_to_desktop (self, uris, time);
g_strfreev (uris);
success = TRUE;
@@ -635,7 +639,7 @@ drag_data_received_cb (GtkWidget *widget,
uris = gtk_selection_data_get_uris (data);
- copy_to_desktop (self, uris);
+ copy_to_desktop (self, uris, time);
g_strfreev (uris);
success = TRUE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]