Commit a7feea34 authored by Cosimo Cecchi's avatar Cosimo Cecchi

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
parent 04fc9452
......@@ -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);
}
......
......@@ -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__ */
......@@ -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;
......@@ -2005,6 +2009,30 @@ unmount_shortcut_cb (GtkMenuItem *item,
do_unmount_selection (sidebar);
}
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,
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment