summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Soriano <csoriano@gnome.org>2016-02-17 20:22:24 +0100
committerCarlos Soriano <csoriano@gnome.org>2016-02-17 20:56:39 +0100
commit24450454c126113ca9e9824510737b6e61e170a0 (patch)
tree164cf1cc94cf1335debcc15c0c17a1e01858f3f9
parenta467868557c678619037c4d351b4acb8ef6c54f1 (diff)
downloadnautilus-24450454c126113ca9e9824510737b6e61e170a0.tar.gz
window: add notifications for sidebar operations
Recently we removed gtk+ notifications from mount operations in the gtk+ sidebar in order to move the handling of those to Nautilus. Now that that is done, implement notifications handling for unmount sidebar operations. The mount operations notifications are still handled by gnome-shell, we will see if that continues making sense or not.
-rw-r--r--src/nautilus-window.c91
1 files changed, 91 insertions, 0 deletions
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index 5e79d39c0..ca565f8a4 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -932,6 +932,95 @@ open_location_cb (NautilusWindow *window,
location, flags, NULL, window, NULL);
}
+static void
+notify_unmount_done (GMountOperation *op,
+ const gchar *message)
+{
+ GApplication *application;
+ gchar *notification_id;
+
+ application = g_application_get_default ();
+ notification_id = g_strdup_printf ("nautilus-mount-operation-%p", op);
+ g_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");
+ unplug = g_notification_new (strings[0]);
+ g_notification_set_body (unplug, strings[1]);
+ g_notification_set_icon (unplug, icon);
+
+ g_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)
+{
+ GApplication *application;
+ GNotification *unmount;
+ gchar *notification_id;
+ GIcon *icon;
+ gchar **strings;
+
+ application = g_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);
+ g_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)
+{
+ g_signal_connect (mount_operation, "show-unmount-progress",
+ G_CALLBACK (show_unmount_progress_cb), NULL);
+ g_signal_connect (mount_operation, "aborted",
+ G_CALLBACK (show_unmount_progress_aborted_cb), NULL);
+}
+
/* Callback used when the places sidebar needs us to present an error message */
static void
places_sidebar_show_error_message_cb (GtkPlacesSidebar *sidebar,
@@ -1275,6 +1364,8 @@ nautilus_window_set_up_sidebar (NautilusWindow *window)
G_CALLBACK (places_sidebar_drag_perform_drop_cb), window);
g_signal_connect (window->priv->places_sidebar, "populate-popup",
G_CALLBACK (places_sidebar_populate_popup_cb), window);
+ g_signal_connect (window->priv->places_sidebar, "unmount",
+ G_CALLBACK (places_sidebar_unmount_operation_cb), window);
}
void