From 567bd8688408d569037b0a934845f5c4b8635ae1 Mon Sep 17 00:00:00 2001
From: Xiaoguang Wang <xwang@suse.com>
Date: Thu, 26 Apr 2018 10:47:20 +0800
Subject: [PATCH] file-view: Add unmount notification

Unmounting disk from file view context menu shows notification same as
unmounting from sidebar.

https://gitlab.gnome.org/GNOME/nautilus/issues/379
---
 src/nautilus-file-operations.c |  6 +++
 src/nautilus-ui-utilities.c    | 84 ++++++++++++++++++++++++++++++++++++++++++
 src/nautilus-ui-utilities.h    | 10 ++++-
 src/nautilus-window.c          | 83 -----------------------------------------
 4 files changed, 99 insertions(+), 84 deletions(-)

Index: nautilus-3.26.2/src/nautilus-file-operations.c
===================================================================
--- nautilus-3.26.2.orig/src/nautilus-file-operations.c
+++ nautilus-3.26.2/src/nautilus-file-operations.c
@@ -2617,6 +2617,12 @@ do_unmount (UnmountData *data)
     {
         mount_op = gtk_mount_operation_new (data->parent_window);
     }
+
+    g_signal_connect (mount_op, "show-unmount-progress",
+                      G_CALLBACK (show_unmount_progress_cb), NULL);
+    g_signal_connect (mount_op, "aborted",
+                      G_CALLBACK (show_unmount_progress_aborted_cb), NULL);
+
     if (data->eject)
     {
         g_mount_eject_with_operation (data->mount,
Index: nautilus-3.26.2/src/nautilus-ui-utilities.c
===================================================================
--- nautilus-3.26.2.orig/src/nautilus-ui-utilities.c
+++ nautilus-3.26.2/src/nautilus-ui-utilities.c
@@ -23,6 +23,7 @@
 
 #include "nautilus-ui-utilities.h"
 #include "nautilus-icon-info.h"
+#include "nautilus-application.h"
 #include <eel/eel-graphic-effects.h>
 
 #include <gio/gio.h>
@@ -490,3 +491,86 @@ show_error_dialog (const gchar *primary_
 
     return GTK_DIALOG (dialog);
 }
+
+static void
+notify_unmount_done (GMountOperation *op,
+                     const gchar     *message)
+{
+    NautilusApplication *application;
+    gchar *notification_id;
+
+    application = nautilus_application_get_default ();
+    notification_id = g_strdup_printf ("nautilus-mount-operation-%p", op);
+    nautilus_application_withdraw_notification (application, notification_id);
+
+    if (message != NULL)
+    {
+        GNotification *unplug;
+        GIcon *icon;
+        gchar **strings;
+
+        strings = g_strsplit (message, "\n", 0);
+        icon = g_themed_icon_new ("media-removable-symbolic");
+        unplug = g_notification_new (strings[0]);
+        g_notification_set_body (unplug, strings[1]);
+        g_notification_set_icon (unplug, icon);
+
+        nautilus_application_send_notification (application, notification_id, unplug);
+        g_object_unref (unplug);
+        g_object_unref (icon);
+        g_strfreev (strings);
+    }
+
+    g_free (notification_id);
+}
+
+static void
+notify_unmount_show (GMountOperation *op,
+                     const gchar     *message)
+{
+    NautilusApplication *application;
+    GNotification *unmount;
+    gchar *notification_id;
+    GIcon *icon;
+    gchar **strings;
+
+    application = nautilus_application_get_default ();
+    strings = g_strsplit (message, "\n", 0);
+    icon = g_themed_icon_new ("media-removable");
+
+    unmount = g_notification_new (strings[0]);
+    g_notification_set_body (unmount, strings[1]);
+    g_notification_set_icon (unmount, icon);
+    g_notification_set_priority (unmount, G_NOTIFICATION_PRIORITY_URGENT);
+
+    notification_id = g_strdup_printf ("nautilus-mount-operation-%p", op);
+    nautilus_application_send_notification (application, notification_id, unmount);
+    g_object_unref (unmount);
+    g_object_unref (icon);
+    g_strfreev (strings);
+    g_free (notification_id);
+}
+
+void
+show_unmount_progress_cb (GMountOperation *op,
+                          const gchar     *message,
+                          gint64           time_left,
+                          gint64           bytes_left,
+                          gpointer         user_data)
+{
+    if (bytes_left == 0)
+    {
+        notify_unmount_done (op, message);
+    }
+    else
+    {
+        notify_unmount_show (op, message);
+    }
+}
+
+void
+show_unmount_progress_aborted_cb (GMountOperation *op,
+                                  gpointer         user_data)
+{
+    notify_unmount_done (op, NULL);
+}
Index: nautilus-3.26.2/src/nautilus-ui-utilities.h
===================================================================
--- nautilus-3.26.2.orig/src/nautilus-ui-utilities.h
+++ nautilus-3.26.2/src/nautilus-ui-utilities.h
@@ -53,4 +53,12 @@ GtkDialog *    show_error_dialog
                                                     const gchar *secondary_text,
                                                     GtkWindow   *parent);
 
+void       show_unmount_progress_cb                (GMountOperation   *op,
+                                                    const gchar       *message,
+                                                    gint64             time_left,
+                                                    gint64             bytes_left,
+                                                    gpointer           user_data);
+void       show_unmount_progress_aborted_cb        (GMountOperation   *op,
+                                                     gpointer           user_data);
+
 #endif /* NAUTILUS_UI_UTILITIES_H */
Index: nautilus-3.26.2/src/nautilus-window.c
===================================================================
--- nautilus-3.26.2.orig/src/nautilus-window.c
+++ nautilus-3.26.2/src/nautilus-window.c
@@ -1023,89 +1023,6 @@ open_location_cb (NautilusWindow     *wi
 }
 
 static void
-notify_unmount_done (GMountOperation *op,
-                     const gchar     *message)
-{
-    NautilusApplication *application;
-    gchar *notification_id;
-
-    application = nautilus_application_get_default ();
-    notification_id = g_strdup_printf ("nautilus-mount-operation-%p", op);
-    nautilus_application_withdraw_notification (application, notification_id);
-
-    if (message != NULL)
-    {
-        GNotification *unplug;
-        GIcon *icon;
-        gchar **strings;
-
-        strings = g_strsplit (message, "\n", 0);
-        icon = g_themed_icon_new ("media-removable-symbolic");
-        unplug = g_notification_new (strings[0]);
-        g_notification_set_body (unplug, strings[1]);
-        g_notification_set_icon (unplug, icon);
-
-        nautilus_application_send_notification (application, notification_id, unplug);
-        g_object_unref (unplug);
-        g_object_unref (icon);
-        g_strfreev (strings);
-    }
-
-    g_free (notification_id);
-}
-
-static void
-notify_unmount_show (GMountOperation *op,
-                     const gchar     *message)
-{
-    NautilusApplication *application;
-    GNotification *unmount;
-    gchar *notification_id;
-    GIcon *icon;
-    gchar **strings;
-
-    application = nautilus_application_get_default ();
-    strings = g_strsplit (message, "\n", 0);
-    icon = g_themed_icon_new ("media-removable");
-
-    unmount = g_notification_new (strings[0]);
-    g_notification_set_body (unmount, strings[1]);
-    g_notification_set_icon (unmount, icon);
-    g_notification_set_priority (unmount, G_NOTIFICATION_PRIORITY_URGENT);
-
-    notification_id = g_strdup_printf ("nautilus-mount-operation-%p", op);
-    nautilus_application_send_notification (application, notification_id, unmount);
-    g_object_unref (unmount);
-    g_object_unref (icon);
-    g_strfreev (strings);
-    g_free (notification_id);
-}
-
-static void
-show_unmount_progress_cb (GMountOperation *op,
-                          const gchar     *message,
-                          gint64           time_left,
-                          gint64           bytes_left,
-                          gpointer         user_data)
-{
-    if (bytes_left == 0)
-    {
-        notify_unmount_done (op, message);
-    }
-    else
-    {
-        notify_unmount_show (op, message);
-    }
-}
-
-static void
-show_unmount_progress_aborted_cb (GMountOperation *op,
-                                  gpointer         user_data)
-{
-    notify_unmount_done (op, NULL);
-}
-
-static void
 places_sidebar_unmount_operation_cb (NautilusWindow  *window,
                                      GMountOperation *mount_operation)
 {
