From ec529e70c20c4164fe34179fc1956676bd10e665 Mon Sep 17 00:00:00 2001 From: lukefromdc Date: Sat, 22 Oct 2016 23:14:31 -0400 Subject: GtkApplication: Notify when ejected volumes safe to unplug Notify users when an external drive is still writing data on attempt to eject, and again when drive is safe to unmount. Notifications behave as they do in Nemo when ejecting/unmounting a flash drive. Tested with GTK 3.22 and a known slow flash drive. This is in GtkApplication builds only, code is from Nemo. FIXME: build system does not limit libnotify dependency to GtkApplication builds and is rather improvised. Adding libnotify to CORE_MODULES via configure.ac did not work, and using Nemo's changes put -lnotify into CORE rather than ALL libs and that caused build failures on failure to link. --- src/caja-application.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'src/caja-application.c') diff --git a/src/caja-application.c b/src/caja-application.c index 23a4ec56..e1d8a892 100644 --- a/src/caja-application.c +++ b/src/caja-application.c @@ -90,6 +90,7 @@ #include #include #include +#include #else enum { COMMAND_0, /* unused: 0 is an invalid command */ @@ -158,8 +159,36 @@ struct _CajaApplicationPriv { gboolean force_desktop; gboolean autostart; gchar *geometry; + NotifyNotification *unmount_notify; }; +void +caja_application_notify_unmount_show (CajaApplication *application, + const gchar *message) +{ + gchar **strings; + + strings = g_strsplit (message, "\n", 0); + + if (application->priv->unmount_notify == NULL) { + 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); +} + #else G_DEFINE_TYPE (CajaApplication, caja_application, G_TYPE_OBJECT); @@ -597,6 +626,7 @@ caja_application_finalize (GObject *object) } g_free (application->priv->geometry); + #else if (application->volume_monitor) { @@ -634,7 +664,9 @@ caja_application_finalize (GObject *object) g_object_unref (application->ss_proxy); application->ss_proxy = NULL; } - +#if ENABLE_LIBUNIQUE == (FALSE) + notify_uninit (); +#endif G_OBJECT_CLASS (caja_application_parent_class)->finalize (object); } @@ -3204,7 +3236,7 @@ caja_application_startup (GApplication *app) menu_provider_init_callback (); /* Initialize the UI handler singleton for file operations */ - /*notify_init (GETTEXT_PACKAGE); */ + notify_init (GETTEXT_PACKAGE); /* Watch for unmounts so we can close open windows */ /* TODO-gio: This should be using the UNMOUNTED feature of GFileMonitor instead */ -- cgit v1.2.1