542461
From bac4bd595c518983571b0fb41fcf5586f27544eb Mon Sep 17 00:00:00 2001
542461
From: Carlos Soriano <csoriano@redhat.com>
542461
Date: Mon, 19 Nov 2018 08:55:22 +0000
542461
Subject: [PATCH] dbus: Implement rename file
542461
542461
So desktop icons extensions can use it.
542461
542461
542461
(cherry picked from commit 42c5ce657e2b24ddf19932e9e3284a045d60ff51)
542461
---
542461
 data/dbus-interfaces.xml    |  4 ++++
542461
 src/nautilus-dbus-manager.c | 33 +++++++++++++++++++++++++++++++++
542461
 2 files changed, 37 insertions(+)
542461
542461
diff --git a/data/dbus-interfaces.xml b/data/dbus-interfaces.xml
542461
index 298871bc4..1827f92ab 100644
542461
--- a/data/dbus-interfaces.xml
542461
+++ b/data/dbus-interfaces.xml
542461
@@ -39,6 +39,10 @@
542461
     <method name='CreateFolder'>
542461
       <arg type='s' name='URI' direction='in'/>
542461
     </method>
542461
+    <method name='RenameFile'>
542461
+      <arg type='s' name='URI' direction='in'/>
542461
+      <arg type='s' name='NewName' direction='in'/>
542461
+    </method>
542461
     <method name='Undo'>
542461
     </method>
542461
     <method name='Redo'>
542461
diff --git a/src/nautilus-dbus-manager.c b/src/nautilus-dbus-manager.c
542461
index 3257c4bd4..43f27e10a 100644
542461
--- a/src/nautilus-dbus-manager.c
542461
+++ b/src/nautilus-dbus-manager.c
542461
@@ -27,6 +27,7 @@
542461
 
542461
 #include "nautilus-file-operations.h"
542461
 #include "nautilus-file-undo-manager.h"
542461
+#include "nautilus-file.h"
542461
 
542461
 #define DEBUG_FLAG NAUTILUS_DEBUG_DBUS
542461
 #include "nautilus-debug.h"
542461
@@ -230,6 +231,34 @@ handle_trash_files (NautilusDBusFileOperations  *object,
542461
     return TRUE; /* invocation was handled */
542461
 }
542461
 
542461
+static void
542461
+rename_file_on_finished (NautilusFile *file,
542461
+                         GFile        *result_location,
542461
+                         GError       *error,
542461
+                         gpointer      callback_data)
542461
+{
542461
+    g_application_release (g_application_get_default ());
542461
+}
542461
+
542461
+static gboolean
542461
+handle_rename_file (NautilusDBusFileOperations *object,
542461
+                    GDBusMethodInvocation      *invocation,
542461
+                    const gchar                *uri,
542461
+                    const gchar                *new_name)
542461
+{
542461
+    NautilusFile *file = NULL;
542461
+
542461
+    file = nautilus_file_get_by_uri (uri);
542461
+
542461
+    g_application_hold (g_application_get_default ());
542461
+    nautilus_file_rename (file, new_name,
542461
+                          rename_file_on_finished, NULL);
542461
+
542461
+    nautilus_dbus_file_operations_complete_rename_file (object, invocation);
542461
+
542461
+    return TRUE; /* invocation was handled */
542461
+}
542461
+
542461
 
542461
 static void
542461
 undo_manager_changed (NautilusDBusManager *self)
542461
@@ -266,6 +295,10 @@ nautilus_dbus_manager_init (NautilusDBusManager *self)
542461
                       "handle-create-folder",
542461
                       G_CALLBACK (handle_create_folder),
542461
                       self);
542461
+    g_signal_connect (self->file_operations,
542461
+                      "handle-rename-file",
542461
+                      G_CALLBACK (handle_rename_file),
542461
+                      self);
542461
     g_signal_connect (self->file_operations,
542461
                       "handle-undo",
542461
                       G_CALLBACK (handle_undo),
542461
-- 
542461
2.18.1
542461