Blame SOURCES/0007-dbus-manager-Keep-application-alive-for-operations.patch

af40a0
From 80b807d9e52fdc3e5e0af5a2d4dd61fdb0a39bc8 Mon Sep 17 00:00:00 2001
af40a0
From: Carlos Soriano <csoriano@redhat.com>
af40a0
Date: Tue, 7 Aug 2018 21:08:21 +0200
af40a0
Subject: [PATCH 07/11] dbus-manager: Keep application alive for operations
af40a0
af40a0
Operations started from Nautilus windows have the persistence handler,
af40a0
however, when not using windows like when invoked through DBus the
af40a0
application could die after a timeout.
af40a0
af40a0
This would stop the operation in the middle of its process, with
af40a0
possible data loss.
af40a0
af40a0
Make sure we keep the application alive while this is happening.
af40a0
---
af40a0
 src/nautilus-dbus-manager.c | 55 +++++++++++++++++++++++++++++++++++--
af40a0
 1 file changed, 52 insertions(+), 3 deletions(-)
af40a0
af40a0
diff --git a/src/nautilus-dbus-manager.c b/src/nautilus-dbus-manager.c
af40a0
index 8135c9650..0d5137292 100644
af40a0
--- a/src/nautilus-dbus-manager.c
af40a0
+++ b/src/nautilus-dbus-manager.c
af40a0
@@ -95,13 +95,29 @@ handle_copy_file (NautilusDBusFileOperations *object,
af40a0
     return TRUE; /* invocation was handled */
af40a0
 }
af40a0
 
af40a0
+static void
af40a0
+undo_redo_on_finished (gpointer user_data)
af40a0
+{
af40a0
+    g_autoptr (NautilusFileUndoManager) undo_manager = NULL;
af40a0
+    int *handler_id = (int *) user_data;
af40a0
+
af40a0
+    undo_manager = nautilus_file_undo_manager_get ();
af40a0
+    g_signal_handler_disconnect (undo_manager, *handler_id);
af40a0
+    g_application_release (g_application_get_default ());
af40a0
+    g_free (handler_id);
af40a0
+}
af40a0
+
af40a0
 static gboolean
af40a0
 handle_redo (NautilusDBusFileOperations *object,
af40a0
              GDBusMethodInvocation      *invocation)
af40a0
 {
af40a0
     g_autoptr (NautilusFileUndoManager) undo_manager = NULL;
af40a0
+    gint *handler_id = g_new0(int, 1);
af40a0
 
af40a0
     undo_manager = nautilus_file_undo_manager_get ();
af40a0
+    *handler_id = g_signal_connect_swapped (undo_manager, "undo-changed",
af40a0
+                                            G_CALLBACK (undo_redo_on_finished),
af40a0
+                                            handler_id);
af40a0
     nautilus_file_undo_manager_redo (NULL);
af40a0
 
af40a0
     nautilus_dbus_file_operations_complete_redo (object, invocation);
af40a0
@@ -113,14 +129,26 @@ handle_undo (NautilusDBusFileOperations *object,
af40a0
              GDBusMethodInvocation      *invocation)
af40a0
 {
af40a0
     g_autoptr (NautilusFileUndoManager) undo_manager = NULL;
af40a0
+    gint *handler_id = g_new0(int, 1);
af40a0
 
af40a0
     undo_manager = nautilus_file_undo_manager_get ();
af40a0
+    *handler_id = g_signal_connect_swapped (undo_manager, "undo-changed",
af40a0
+                                            G_CALLBACK (undo_redo_on_finished),
af40a0
+                                            handler_id);
af40a0
     nautilus_file_undo_manager_undo (NULL);
af40a0
 
af40a0
     nautilus_dbus_file_operations_complete_undo (object, invocation);
af40a0
     return TRUE; /* invocation was handled */
af40a0
 }
af40a0
 
af40a0
+static void
af40a0
+create_folder_on_finished (GFile    *new_file,
af40a0
+                           gboolean  success,
af40a0
+                           gpointer  callback_data)
af40a0
+{
af40a0
+    g_application_release (g_application_get_default ());
af40a0
+}
af40a0
+
af40a0
 static gboolean
af40a0
 handle_create_folder (NautilusDBusFileOperations *object,
af40a0
                       GDBusMethodInvocation      *invocation,
af40a0
@@ -136,13 +164,22 @@ handle_create_folder (NautilusDBusFileOperations *object,
af40a0
     parent_file = g_file_get_parent (file);
af40a0
     parent_file_uri = g_file_get_uri (parent_file);
af40a0
 
af40a0
+    g_application_hold (g_application_get_default ());
af40a0
     nautilus_file_operations_new_folder (NULL, parent_file_uri, basename,
af40a0
-                                         NULL, NULL);
af40a0
+                                         create_folder_on_finished, NULL);
af40a0
 
af40a0
     nautilus_dbus_file_operations_complete_create_folder (object, invocation);
af40a0
     return TRUE; /* invocation was handled */
af40a0
 }
af40a0
 
af40a0
+static void
af40a0
+copy_on_finished (GHashTable *debutting_uris,
af40a0
+                  gboolean    success,
af40a0
+                  gpointer    callback_data)
af40a0
+{
af40a0
+    g_application_release (g_application_get_default ());
af40a0
+}
af40a0
+
af40a0
 static gboolean
af40a0
 handle_copy_uris (NautilusDBusFileOperations  *object,
af40a0
                   GDBusMethodInvocation       *invocation,
af40a0
@@ -157,14 +194,16 @@ handle_copy_uris (NautilusDBusFileOperations  *object,
af40a0
         source_files = g_list_prepend (source_files, g_strdup (sources[idx]));
af40a0
     }
af40a0
 
af40a0
+    g_application_hold (g_application_get_default ());
af40a0
     nautilus_file_operations_copy_move (source_files, destination,
af40a0
-                                        GDK_ACTION_COPY, NULL, NULL, NULL);
af40a0
+                                        GDK_ACTION_COPY, NULL, copy_on_finished, NULL);
af40a0
 
af40a0
     g_list_free_full (source_files, g_free);
af40a0
     nautilus_dbus_file_operations_complete_copy_uris (object, invocation);
af40a0
     return TRUE; /* invocation was handled */
af40a0
 }
af40a0
 
af40a0
+/* FIXME: Needs a callback for maintaining alive the application */
af40a0
 static gboolean
af40a0
 handle_empty_trash (NautilusDBusFileOperations *object,
af40a0
                     GDBusMethodInvocation      *invocation)
af40a0
@@ -175,6 +214,14 @@ handle_empty_trash (NautilusDBusFileOperations *object,
af40a0
     return TRUE; /* invocation was handled */
af40a0
 }
af40a0
 
af40a0
+static void
af40a0
+trash_on_finished (GHashTable *debutting_uris,
af40a0
+                   gboolean    user_cancel,
af40a0
+                   gpointer    callback_data)
af40a0
+{
af40a0
+    g_application_release (g_application_get_default ());
af40a0
+}
af40a0
+
af40a0
 static gboolean
af40a0
 handle_trash_files (NautilusDBusFileOperations  *object,
af40a0
                     GDBusMethodInvocation       *invocation,
af40a0
@@ -189,7 +236,9 @@ handle_trash_files (NautilusDBusFileOperations  *object,
af40a0
                                        g_file_new_for_uri (sources[idx]));
af40a0
     }
af40a0
 
af40a0
-    nautilus_file_operations_trash_or_delete (source_files, NULL, NULL, NULL);
af40a0
+    g_application_hold (g_application_get_default ());
af40a0
+    nautilus_file_operations_trash_or_delete (source_files, NULL,
af40a0
+                                              trash_on_finished, NULL);
af40a0
 
af40a0
     nautilus_dbus_file_operations_complete_trash_files (object, invocation);
af40a0
     return TRUE; /* invocation was handled */
af40a0
-- 
af40a0
2.17.1
af40a0