diff options
author | Carlos Soriano <csoriano@gnome.org> | 2016-02-15 19:23:15 +0100 |
---|---|---|
committer | Carlos Soriano <csoriano@gnome.org> | 2016-02-15 19:23:15 +0100 |
commit | c361ab235a36dfa2525f1ee600de660b7e01e290 (patch) | |
tree | a9bf20c18d548a41e17467a2895d32431f96b0cf | |
parent | c22170b37224e6cfed44621c7c816adaffa121d2 (diff) | |
download | nautilus-c361ab235a36dfa2525f1ee600de660b7e01e290.tar.gz |
window: add notifications for sidebar operations
Recently we removed gtk+ notifications from mount operations in the
sidebar in order to move the handling of those to Nautilus.
Now that that is done, implement notifications handling for sidebar
operations.
-rw-r--r-- | src/nautilus-window.c | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/src/nautilus-window.c b/src/nautilus-window.c index 5e79d39c0..5bd4c4650 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_mount_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, "mount-operation", + G_CALLBACK (places_sidebar_mount_operation_cb), window); } void |