[nautilus] places-sidebar: add a notification while ejecting volumes



commit a7feea344d68c653317d5beebc420035e2145081
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Tue May 15 16:12:37 2012 -0400

    places-sidebar: add a notification while ejecting volumes
    
    Using the show-unmount-progress signal on GMountOperation
    Based on an initial patch by TomÃÅ BÅatek <tbzatek redhat com>
    
    https://bugzilla.gnome.org/show_bug.cgi?id=619665
    
    See also:
    https://bugzilla.gnome.org/show_bug.cgi?id=676111
    https://bugzilla.redhat.com/show_bug.cgi?id=819492

 src/nautilus-application.c    |   55 +++++++++++++++++++++++++++++++++++++++++
 src/nautilus-application.h    |    6 ++++
 src/nautilus-places-sidebar.c |   34 +++++++++++++++++++++++++
 3 files changed, 95 insertions(+), 0 deletions(-)
---
diff --git a/src/nautilus-application.c b/src/nautilus-application.c
index a3142a7..2d13d4b 100644
--- a/src/nautilus-application.c
+++ b/src/nautilus-application.c
@@ -108,8 +108,61 @@ struct _NautilusApplicationPriv {
 
 	gboolean no_desktop;
 	gchar *geometry;
+
+	NotifyNotification *unmount_notify;
 };
 
+
+void
+nautilus_application_notify_unmount_done (NautilusApplication *application,
+					  const gchar *message)
+{
+	if (application->priv->unmount_notify) {
+		notify_notification_close (application->priv->unmount_notify, NULL);
+		g_clear_object (&application->priv->unmount_notify);
+	}
+
+	if (message != NULL) {
+		NotifyNotification *unplug;
+		gchar **strings;
+
+		strings = g_strsplit (message, "\n", 0);
+		unplug = notify_notification_new (strings[0], strings[1],
+						  "media-removable");
+
+		notify_notification_show (unplug, NULL);
+		g_object_unref (unplug);
+		g_strfreev (strings);
+	}
+}
+
+void
+nautilus_application_notify_unmount_show (NautilusApplication *application,
+					  const gchar *message)
+{
+	gchar **strings;
+
+	strings = g_strsplit (message, "\n", 0);
+
+	if (!application->priv->unmount_notify) {
+		application->priv->unmount_notify =
+			notify_notification_new (strings[0], strings[1],
+						 "media-removable");
+
+		notify_notification_set_hint (application->priv->unmount_notify,
+					      "transient", g_variant_new_boolean (TRUE));
+		notify_notification_set_urgency (application->priv->unmount_notify,
+						 NOTIFY_URGENCY_CRITICAL);
+	} else {
+		notify_notification_update (application->priv->unmount_notify,
+					    strings[0], strings[1],
+					    "media-removable");
+	}
+
+	notify_notification_show (application->priv->unmount_notify, NULL);
+	g_strfreev (strings);
+}
+
 static gboolean
 check_required_directories (NautilusApplication *application)
 {
@@ -1320,6 +1373,8 @@ nautilus_application_quit_mainloop (GApplication *app)
 	nautilus_icon_info_clear_caches ();
  	nautilus_application_save_accel_map (NULL);
 
+	nautilus_application_notify_unmount_done (NAUTILUS_APPLICATION (app), NULL);
+
 	G_APPLICATION_CLASS (nautilus_application_parent_class)->quit_mainloop (app);
 }
 
diff --git a/src/nautilus-application.h b/src/nautilus-application.h
index 12846e4..48a1c94 100644
--- a/src/nautilus-application.h
+++ b/src/nautilus-application.h
@@ -71,4 +71,10 @@ void nautilus_application_open_location (NautilusApplication *application,
 					 GFile *selection,
 					 const char *startup_id);
 
+void nautilus_application_notify_unmount_show (NautilusApplication *application,
+					       const gchar *message);
+
+void nautilus_application_notify_unmount_done (NautilusApplication *application,
+					       const gchar *message);
+
 #endif /* __NAUTILUS_APPLICATION_H__ */
diff --git a/src/nautilus-places-sidebar.c b/src/nautilus-places-sidebar.c
index e6ee652..0d90161 100644
--- a/src/nautilus-places-sidebar.c
+++ b/src/nautilus-places-sidebar.c
@@ -52,6 +52,8 @@
 #include "nautilus-window.h"
 #include "nautilus-window-slot.h"
 
+#include <libnotify/notify.h>
+
 #define DEBUG_FLAG NAUTILUS_DEBUG_PLACES
 #include <libnautilus-private/nautilus-debug.h>
 
@@ -98,6 +100,8 @@ typedef struct {
 	NautilusWindowSlot *go_to_after_mount_slot;
 	NautilusWindowOpenFlags go_to_after_mount_flags;
 
+	NotifyNotification *unmount_notify;
+
 	GtkTreePath *eject_highlight_path;
 
 	GDBusProxy *hostnamed_proxy;
@@ -2006,6 +2010,30 @@ unmount_shortcut_cb (GtkMenuItem           *item,
 }
 
 static void
+show_unmount_progress_cb (GMountOperation *op,
+			  const gchar *message,
+			  gint64 time_left,
+			  gint64 bytes_left,
+			  gpointer user_data)
+{
+	NautilusApplication *app = NAUTILUS_APPLICATION (g_application_get_default ());
+
+	if (bytes_left == 0) {
+		nautilus_application_notify_unmount_done (app, message);
+	} else {
+		nautilus_application_notify_unmount_show (app, message);
+	}
+}
+
+static void
+show_unmount_progress_aborted_cb (GMountOperation *op,
+				  gpointer user_data)
+{
+	NautilusApplication *app = NAUTILUS_APPLICATION (g_application_get_default ());
+	nautilus_application_notify_unmount_done (app, NULL);
+}
+
+static void
 drive_eject_cb (GObject *source_object,
 		GAsyncResult *res,
 		gpointer user_data)
@@ -2108,6 +2136,11 @@ do_eject (GMount *mount,
 		g_drive_eject_with_operation (drive, 0, mount_op, NULL, drive_eject_cb,
 					      g_object_ref (sidebar->window));
 	}
+
+	g_signal_connect (mount_op, "show-unmount-progress",
+			  G_CALLBACK (show_unmount_progress_cb), sidebar);
+	g_signal_connect (mount_op, "aborted",
+			  G_CALLBACK (show_unmount_progress_aborted_cb), sidebar);
 	g_object_unref (mount_op);
 }
 
@@ -3318,6 +3351,7 @@ nautilus_places_sidebar_dispose (GObject *object)
 	sidebar->uri = NULL;
 
 	free_drag_data (sidebar);
+	g_clear_object (&sidebar->unmount_notify);
 
 	if (sidebar->eject_highlight_path != NULL) {
 		gtk_tree_path_free (sidebar->eject_highlight_path);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]