[Xfce4-commits] <thunar:jannis/port-to-udev> Re-implement mount/eject notifications based on libnotify.
Jannis Pohlmann
noreply at xfce.org
Fri Jul 23 10:04:01 CEST 2010
Updating branch refs/heads/jannis/port-to-udev
to 66f84710e8cc3e44f944d6c8ecc6b4a708f2b4c2 (commit)
from 9b9ae1e53d751733a095c13c9bab047f2d189acb (commit)
commit 66f84710e8cc3e44f944d6c8ecc6b4a708f2b4c2
Author: Jannis Pohlmann <jannis at xfce.org>
Date: Fri Jul 23 10:01:07 2010 +0200
Re-implement mount/eject notifications based on libnotify.
Notifications are shown before the calls to g_volume_eject() and
g_mount_unmount(). They are closed in the finish callbacks.
Makefile.am | 5 -
configure.in.in | 1 -
thunar-mount-notify/Makefile.am | 46 -----
thunar-mount-notify/main.c | 270 -----------------------------
thunar/Makefile.am | 15 ++-
thunar/main.c | 23 +++
thunar/thunar-notify.c | 236 +++++++++++++++++++++++++
thunar/{thunar-exec.h => thunar-notify.h} | 31 ++--
thunar/thunar-shortcuts-view.c | 49 ++++--
thunar/thunar-tree-view.c | 52 ++++--
10 files changed, 353 insertions(+), 375 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index 64a54ed..85226d5 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -17,10 +17,6 @@
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.
-if HAVE_LIBNOTIFY
-THUNAR_MOUNT_NOTIFY_SUBDIR=thunar-mount-notify
-endif
-
SUBDIRS = \
icons \
pixmaps \
@@ -29,7 +25,6 @@ SUBDIRS = \
tdb \
thunarx \
thunar \
- $(THUNAR_MOUNT_NOTIFY_SUBDIR) \
docs \
examples \
plugins
diff --git a/configure.in.in b/configure.in.in
index f7ae8d6..640b75d 100644
--- a/configure.in.in
+++ b/configure.in.in
@@ -295,7 +295,6 @@ thunar/Makefile
thunarx/Makefile
thunarx/thunarx-2.pc
thunarx/thunarx-config.h
-thunar-mount-notify/Makefile
])
dnl ***************************
diff --git a/thunar-mount-notify/Makefile.am b/thunar-mount-notify/Makefile.am
deleted file mode 100644
index 1e72f22..0000000
--- a/thunar-mount-notify/Makefile.am
+++ /dev/null
@@ -1,46 +0,0 @@
-# vi:set ts=8 sw=8 noet ai nocindent syntax=automake:
-# -
-# Copyright (c) 2010 Jannis Pohlmann <jannis at xfce.org>
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; either version 2 of
-# the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public
-# License along with this program; if not, write to the Free
-# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-# Boston, MA 02110-1301, USA.
-
-INCLUDES = \
- -I$(top_builddir) \
- -I$(top_srcdir) \
- -DG_LOG_DOMAIN=\"thunar-mount-notify\" \
- -DPACKAGE_LOCALE_DIR=\"$(localedir)\" \
- $(PLATFORM_CPPFLAGS)
-
-libexec_PROGRAMS = \
- thunar-mount-notify-1
-
-thunar_mount_notify_1_SOURCES = \
- main.c
-
-thunar_mount_notify_1_CFLAGS = \
- $(GTK_CFLAGS) \
- $(LIBNOTIFY_CFLAGS) \
- $(LIBXFCE4UTIL_CFLAGS) \
- $(PLATFORM_CFLAGS)
-
-thunar_mount_notify_1_LDFLAGS = \
- -no-undefined \
- $(PLATFORM_LDFLAGS)
-
-thunar_mount_notify_1_LDADD = \
- $(GTK_LIBS) \
- $(LIBNOTIFY_LIBS) \
- $(LIBXFCE4UTIL_LIBS)
diff --git a/thunar-mount-notify/main.c b/thunar-mount-notify/main.c
deleted file mode 100644
index a39e994..0000000
--- a/thunar-mount-notify/main.c
+++ /dev/null
@@ -1,270 +0,0 @@
-/* vi:set et ai sw=2 sts=2 ts=2: */
-/*-
- * Copyright (c) 2006-2007 Benedikt Meurer <benny at xfce.org>
- * Copyright (c) 2010 Jannis Pohlmann <jannis at xfce.org>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this program; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-
-#ifdef HAVE_ERRNO_H
-#include <errno.h>
-#endif
-#ifdef HAVE_SIGNAL_H
-#include <signal.h>
-#endif
-#ifdef HAVE_STDLIB_H
-#include <stdlib.h>
-#endif
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-#include <glib/gstdio.h>
-
-#include <gtk/gtk.h>
-
-#include <libnotify/notify.h>
-
-#include <libxfce4util/libxfce4util.h>
-
-
-
-/* make sure all defines are present */
-#ifndef NOTIFY_EXPIRES_NEVER
-#define NOTIFY_EXPIRES_NEVER 0
-#endif
-#ifndef NOTIFY_EXPIRES_DEFAULT
-#define NOTIFY_EXPIRES_DEFAULT -1
-#endif
-
-
-
-/* --- globals --- */
-static gboolean opt_eject = FALSE;
-static gchar *opt_icon = NULL;
-static gchar *opt_name = NULL;
-static gboolean opt_readonly = FALSE;
-static gboolean opt_version = FALSE;
-static gint signal_fds[2];
-static NotifyNotification *notification = NULL;
-
-
-
-/* --- command line options --- */
-static GOptionEntry entries[] =
-{
- { "eject", 'e', 0, G_OPTION_ARG_NONE, &opt_eject, NULL, NULL, },
- { "icon", 'i', 0, G_OPTION_ARG_STRING, &opt_icon, NULL, NULL, },
- { "name", 'n', 0, G_OPTION_ARG_STRING, &opt_name, NULL, NULL, },
- { "readonly", 'r', 0, G_OPTION_ARG_NONE, &opt_readonly, NULL, NULL, },
- { "version", 'V', 0, G_OPTION_ARG_NONE, &opt_version, N_ ("Print version information and exit"), NULL, },
- { NULL, },
-};
-
-
-
-static void
-signal_func (int signo)
-{
- gint ignore;
-
- /* SIGUSR1 means success */
- ignore = write (signal_fds[1], (signo == SIGUSR1) ? "U" : "K", 1);
-}
-
-
-
-static gboolean
-signal_io_func (GIOChannel *channel,
- GIOCondition condition,
- gpointer user_data)
-{
- gchar *message;
- gchar c;
-
- /* read the first character from signal pipe */
- if (read (signal_fds[0], &c, 1) < 1)
- return TRUE;
-
- /* perform the appropriate operation */
- if (c == 'U') /* SIGUSR1 */
- {
- /* the operation succeed */
- if (G_LIKELY (!opt_eject))
- {
- /* tell the user that the device can be removed now */
- message = g_strdup_printf (_("The device \"%s\" is now safe to remove."), opt_name);
- notify_notification_update (notification, _("Device is now safe to remove"), message, opt_icon);
- notify_notification_set_timeout (notification, NOTIFY_EXPIRES_DEFAULT);
- notify_notification_set_urgency (notification, NOTIFY_URGENCY_LOW);
- notify_notification_show (notification, NULL);
- g_free (message);
-
- /* release the notification, so it stays active even
- * after the process exits, otherwise we'll block
- * Thunar's unmount operations...
- */
- g_object_unref (G_OBJECT (notification));
- }
- }
-
- /* terminate the process */
- gtk_main_quit ();
-
- return TRUE;
-}
-
-
-
-int
-main (int argc, char **argv)
-{
- const gchar *summary;
- GIOChannel *channel;
- GError *err = NULL;
- gchar *message;
- const gchar *display_name;
-
- /* initialize the i18n support */
- xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
-
- /* initialize GTK+ */
- if (!gtk_init_with_args (&argc, &argv, "Xfce Mount Notify", entries, GETTEXT_PACKAGE, &err))
- {
- /* check if we have an error message */
- if (G_LIKELY (err == NULL))
- {
- /* no error message, the GUI initialization failed */
- display_name = gdk_get_display_arg_name ();
- g_fprintf (stderr, "thunar-mount-notify: %s: %s\n", _("Failed to open display"), (display_name != NULL) ? display_name : " ");
- }
- else
- {
- /* yep, there's an error, so print it */
- g_fprintf (stderr, "thunar-mount-notify: %s\n", err->message);
- }
- return EXIT_FAILURE;
- }
-
- /* check if we should print version */
- if (G_UNLIKELY (opt_version))
- {
- g_print ("%s %s\n\n", g_get_prgname (), PACKAGE_VERSION);
- g_print (_("Copyright (c) %s\n"
- " os-cillation e.K. All rights reserved.\n\n"
- "Written by Benedikt Meurer <benny at xfce.org>.\n\n"),
- "2006-2007");
- g_print (_("%s comes with ABSOLUTELY NO WARRANTY,\n"
- "You may redistribute copies of %s under the terms of\n"
- "the GNU Lesser General Public License which can be found in the\n"
- "%s source package.\n\n"), g_get_prgname (), g_get_prgname (), PACKAGE_TARNAME);
- g_print (_("Please report bugs to <%s>.\n"), PACKAGE_BUGREPORT);
- return EXIT_SUCCESS;
- }
-
- /* icon defaults to "gnome-dev-harddisk" */
- if (G_UNLIKELY (opt_icon == NULL || *opt_icon == '\0'))
- opt_icon = "gnome-dev-harddisk";
-
- /* make sure that a device name was specified */
- if (G_UNLIKELY (opt_name == NULL || *opt_icon == '\0'))
- {
- /* the caller must specify a usable device name */
- g_printerr ("%s: %s.\n", g_get_prgname (), "Must specify a device name");
- return EXIT_FAILURE;
- }
-
- /* try to initialize libnotify */
- if (!notify_init ("thunar-mount-notify"))
- {
- /* it doesn't make sense to continue from here on */
- g_printerr ("%s: %s.\n", g_get_prgname (), "Failed to initialize libnotify");
- return EXIT_FAILURE;
- }
-
- /* setup the signal pipe */
- if (pipe (signal_fds) < 0)
- {
- g_printerr ("%s: Failed to setup signal pipe: %s.\n", g_get_prgname (), g_strerror (errno));
- return EXIT_FAILURE;
- }
-
- /* register the appropriate signal handlers */
- signal (SIGTERM, signal_func);
- signal (SIGHUP, signal_func);
- signal (SIGINT, signal_func);
- signal (SIGUSR1, signal_func);
-
- /* watch the read side of the signal pipe */
- channel = g_io_channel_unix_new (signal_fds[0]);
- g_io_add_watch (channel, G_IO_IN, signal_io_func, NULL);
- g_io_channel_unref (channel);
-
- /* different summary/message based on whether it's readonly */
- if (G_UNLIKELY (opt_readonly))
- {
- /* check if we eject */
- if (G_LIKELY (opt_eject))
- {
- /* read-only, just ejecting */
- summary = _("Ejecting device");
- message = g_strdup_printf (_("The device \"%s\" is being ejected. This may take some time."), opt_name);
- }
- else
- {
- /* read-only, just unmounting */
- summary = _("Unmounting device");
- message = g_strdup_printf (_("The device \"%s\" is being unmounted by the system. Please do "
- "not remove the media or disconnect the drive."), opt_name);
- }
- }
- else
- {
- /* not read-only, writing back data */
- summary = _("Writing data to device");
- message = g_strdup_printf (_("There is data that needs to be written to the device \"%s\" before it can be "
- "removed. Please do not remove the media or disconnect the drive."), opt_name);
- }
-
- /* setup the notification */
- notification = notify_notification_new (summary, message, opt_icon, NULL);
- g_signal_connect (G_OBJECT (notification), "closed", G_CALLBACK (gtk_main_quit), NULL);
- g_object_add_weak_pointer (G_OBJECT (notification), (gpointer) ¬ification);
- notify_notification_set_urgency (notification, NOTIFY_URGENCY_CRITICAL);
- notify_notification_set_timeout (notification, NOTIFY_EXPIRES_NEVER);
- notify_notification_show (notification, NULL);
- g_free (message);
-
- /* enter the main loop */
- gtk_main ();
-
- /* release the notification */
- if (G_LIKELY (notification != NULL))
- {
- notify_notification_close (notification, NULL);
- g_object_unref (G_OBJECT (notification));
- }
-
- return EXIT_SUCCESS;
-}
diff --git a/thunar/Makefile.am b/thunar/Makefile.am
index 436933d..29923e5 100644
--- a/thunar/Makefile.am
+++ b/thunar/Makefile.am
@@ -1,4 +1,4 @@
-# $Id$
+# vi:set ts=8 sw=8 noet ai nocindent syntax=automake:
INCLUDES = \
-I$(top_builddir) \
@@ -21,6 +21,12 @@ bin_SCRIPTS = \
bin_PROGRAMS = \
Thunar
+if HAVE_LIBNOTIFY
+thunar_notify_sources = \
+ thunar-notify.c \
+ thunar-notify.h
+endif
+
thunar_built_sources = \
thunar-marshal.c \
thunar-marshal.h
@@ -29,6 +35,7 @@ Thunar_SOURCES = \
$(thunar_include_HEADERS) \
$(thunar_built_sources) \
$(thunar_dbus_sources) \
+ $(thunar_notify_sources) \
main.c \
sexy-url-label.c \
sexy-url-label.h \
@@ -223,6 +230,7 @@ Thunar_CFLAGS = \
$(GIO_CFLAGS) \
$(GTHREAD_CFLAGS) \
$(GUDEV_CFLAGS) \
+ $(LIBNOTIFY_CFLAGS) \
$(LIBSM_CFLAGS) \
$(LIBSTARTUP_NOTIFICATION_CFLAGS) \
$(LIBXFCE4UI_CFLAGS) \
@@ -240,8 +248,9 @@ Thunar_LDADD = \
$(GIO_LIBS) \
$(GTHREAD_LIBS) \
$(GUDEV_LIBS) \
- $(LIBSTARTUP_NOTIFICATION_LIBS) \
+ $(LIBNOTIFY_LIBS) \
$(LIBSM_LIBS) \
+ $(LIBSTARTUP_NOTIFICATION_LIBS) \
$(LIBXFCE4UI_LIBS)
Thunar_DEPENDENCIES = \
@@ -409,5 +418,3 @@ EXTRA_DIST = \
thunar-window-ui.xml \
thunar-settings \
$(desktop_in_files)
-
-# vi:set ts=8 sw=8 noet ai nocindent syntax=automake:
diff --git a/thunar/main.c b/thunar/main.c
index 6bec9bf..11ff335 100644
--- a/thunar/main.c
+++ b/thunar/main.c
@@ -33,6 +33,10 @@
#include <gio/gdesktopappinfo.h>
#endif
+#ifdef HAVE_LIBNOTIFY
+#include <libnotify/notify.h>
+#endif
+
#include <thunar/thunar-application.h>
#include <thunar/thunar-dbus-client.h>
#include <thunar/thunar-dbus-service.h>
@@ -133,6 +137,20 @@ main (int argc, char **argv)
/* initialize the GThread system */
if (!g_thread_supported ())
g_thread_init (NULL);
+
+#ifdef HAVE_LIBNOTIFY
+ if (notify_init (PACKAGE_NAME))
+ {
+ /* we do this to work around bugs in libnotify < 0.6.0. Older
+ * versions crash in notify_uninit() when no notifications are
+ * displayed before. These versions also segfault when the
+ * ret_spec_version parameter of notify_get_server_info is
+ * NULL... */
+ gchar *spec_version = NULL;
+ notify_get_server_info (NULL, NULL, NULL, &spec_version);
+ g_free (spec_version);
+ }
+#endif
/* get the startup notification id */
startup_id = g_getenv ("DESKTOP_STARTUP_ID");
@@ -300,5 +318,10 @@ error0:
/* release the application reference */
g_object_unref (G_OBJECT (application));
+#ifdef HAVE_LIBNOTIFY
+ if (notify_is_initted ())
+ notify_uninit ();
+#endif
+
return EXIT_SUCCESS;
}
diff --git a/thunar/thunar-notify.c b/thunar/thunar-notify.c
new file mode 100644
index 0000000..7a5ecc8
--- /dev/null
+++ b/thunar/thunar-notify.c
@@ -0,0 +1,236 @@
+/* vi:set et ai sw=2 sts=2 ts=2: */
+/*-
+ * Copyright (c) 2010 Jannis Pohlmann <jannis at xfce.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#include <libnotify/notify.h>
+
+#include <libxfce4util/libxfce4util.h>
+
+#include <thunar/thunar-notify.h>
+
+
+
+void
+thunar_notify_unmount (GMount *mount)
+{
+ const gchar * const *icon_names;
+ NotifyNotification *notification = NULL;
+ const gchar *summary;
+ GFileInfo *info;
+ gboolean read_only = FALSE;
+ GFile *icon_file;
+ GFile *mount_point;
+ GIcon *icon;
+ gchar *icon_name;
+ gchar *message;
+ gchar *name;
+
+ g_return_if_fail (G_IS_MOUNT (mount));
+
+ mount_point = g_mount_get_root (mount);
+
+ info = g_file_query_info (mount_point, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE,
+ G_FILE_QUERY_INFO_NONE, NULL, NULL);
+
+ if (info != NULL)
+ {
+ read_only = !g_file_info_get_attribute_boolean (info,
+ G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE);
+
+ g_object_unref (info);
+ }
+
+ g_object_unref (mount_point);
+
+ name = g_mount_get_name (mount);
+
+ icon = g_mount_get_icon (mount);
+ if (G_IS_THEMED_ICON (icon))
+ {
+ icon_names = g_themed_icon_get_names (G_THEMED_ICON (icon));
+ if (icon_names != NULL)
+ icon_name = g_strdup (icon_names[0]);
+ }
+ else if (G_IS_FILE_ICON (icon))
+ {
+ icon_file = g_file_icon_get_file (G_FILE_ICON (icon));
+ if (icon_file != NULL)
+ {
+ icon_name = g_file_get_path (icon_file);
+ g_object_unref (icon_file);
+ }
+ }
+ g_object_unref (icon);
+
+ if (read_only)
+ {
+ summary = _("Unmounting device");
+ message = g_strdup_printf (_("The device \"%s\" is being unmounted by the system. "
+ "Please do not remove the media or disconnect the "
+ "drive"), name);
+ }
+ else
+ {
+ summary = _("Writing data to device");
+ message = g_strdup_printf (_("There is data that needs to be written to the "
+ "device \"%s\" before it can be removed. Please "
+ "do not remove the meida or disconnect the drive"),
+ name);
+ }
+
+ notification = notify_notification_new (summary, message, icon_name, NULL);
+ notify_notification_set_urgency (notification, NOTIFY_URGENCY_CRITICAL);
+ notify_notification_set_timeout (notification, NOTIFY_EXPIRES_NEVER);
+ notify_notification_show (notification, NULL);
+
+ g_object_set_data_full (G_OBJECT (mount), "thunar-notification", notification,
+ g_object_unref);
+
+ g_free (message);
+ g_free (icon_name);
+ g_free (name);
+}
+
+
+
+void
+thunar_notify_unmount_finish (GMount *mount)
+{
+ NotifyNotification *notification;
+
+ g_return_if_fail (G_IS_MOUNT (mount));
+
+ notification = g_object_get_data (G_OBJECT (mount), "thunar-notification");
+ if (notification != NULL)
+ {
+ notify_notification_close (notification, NULL);
+ g_object_set_data (G_OBJECT (mount), "thunar-notification", NULL);
+ }
+}
+
+
+
+void
+thunar_notify_eject (GVolume *volume)
+{
+ const gchar * const *icon_names;
+ NotifyNotification *notification = NULL;
+ const gchar *summary;
+ GFileInfo *info;
+ gboolean read_only = FALSE;
+ GMount *mount;
+ GFile *icon_file;
+ GFile *mount_point;
+ GIcon *icon;
+ gchar *icon_name;
+ gchar *message;
+ gchar *name;
+
+ g_return_if_fail (G_IS_VOLUME (volume));
+
+ mount = g_volume_get_mount (volume);
+ if (mount != NULL)
+ {
+ mount_point = g_mount_get_root (mount);
+
+ info = g_file_query_info (mount_point, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE,
+ G_FILE_QUERY_INFO_NONE, NULL, NULL);
+
+ if (info != NULL)
+ {
+ read_only =
+ !g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE);
+
+ g_object_unref (info);
+ }
+
+ g_object_unref (mount_point);
+ }
+
+ name = g_volume_get_name (volume);
+
+ icon = g_volume_get_icon (volume);
+ if (G_IS_THEMED_ICON (icon))
+ {
+ icon_names = g_themed_icon_get_names (G_THEMED_ICON (icon));
+ if (icon_names != NULL)
+ icon_name = g_strdup (icon_names[0]);
+ }
+ else if (G_IS_FILE_ICON (icon))
+ {
+ icon_file = g_file_icon_get_file (G_FILE_ICON (icon));
+ if (icon_file != NULL)
+ {
+ icon_name = g_file_get_path (icon_file);
+ g_object_unref (icon_file);
+ }
+ }
+ g_object_unref (icon);
+
+ if (read_only)
+ {
+ summary = _("Ejecting device");
+ message = g_strdup_printf (_("The device \"%s\" is being ejected. "
+ "This may take some time"), name);
+ }
+ else
+ {
+ summary = _("Writing data to device");
+ message = g_strdup_printf (_("There is data that needs to be written to the "
+ "device \"%s\" before it can be removed. Please "
+ "do not remove the meida or disconnect the drive"),
+ name);
+ }
+
+ notification = notify_notification_new (summary, message, icon_name, NULL);
+ notify_notification_set_urgency (notification, NOTIFY_URGENCY_CRITICAL);
+ notify_notification_set_timeout (notification, NOTIFY_EXPIRES_NEVER);
+ notify_notification_show (notification, NULL);
+
+ g_object_set_data_full (G_OBJECT (volume), "thunar-notification", notification,
+ g_object_unref);
+
+ g_free (message);
+ g_free (icon_name);
+ g_free (name);
+}
+
+
+
+void
+thunar_notify_eject_finish (GVolume *volume)
+{
+ NotifyNotification *notification;
+
+ g_return_if_fail (G_IS_VOLUME (volume));
+
+ notification = g_object_get_data (G_OBJECT (volume), "thunar-notification");
+ if (notification != NULL)
+ {
+ notify_notification_close (notification, NULL);
+ g_object_set_data (G_OBJECT (volume), "thunar-notification", NULL);
+ }
+}
diff --git a/thunar/thunar-exec.h b/thunar/thunar-notify.h
similarity index 51%
copy from thunar/thunar-exec.h
copy to thunar/thunar-notify.h
index 32b5b3c..47696ee 100644
--- a/thunar/thunar-exec.h
+++ b/thunar/thunar-notify.h
@@ -1,7 +1,6 @@
/* vi:set et ai sw=2 sts=2 ts=2: */
/*-
- * Copyright (c) 2005-2007 Benedikt Meurer <benny at xfce.org>
- * Copyright (c) 2009 Jannis Pohlmann <jannis at xfce.org>
+ * Copyright (c) 2010 Jannis Pohlmann <jannis at xfce.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -19,23 +18,21 @@
* Boston, MA 02110-1301, USA.
*/
-#ifndef __THUNAR_EXEC_H__
-#define __THUNAR_EXEC_H__
+#ifndef __THUNAR_NOTIFY_H__
+#define __THUNAR_NOTIFY_H__
-#include <gdk/gdk.h>
+#include <glib.h>
+#include <gio/gio.h>
-G_BEGIN_DECLS;
+#include <libnotify/notify.h>
-gboolean thunar_exec_parse (const gchar *exec,
- GList *path_list,
- const gchar *icon,
- const gchar *name,
- const gchar *path,
- gboolean terminal,
- gint *argc,
- gchar ***argv,
- GError **error);
+G_BEGIN_DECLS
-G_END_DECLS;
+void thunar_notify_unmount (GMount *mount);
+void thunar_notify_unmount_finish (GMount *mount);
+void thunar_notify_eject (GVolume *volume);
+void thunar_notify_eject_finish (GVolume *volume);
-#endif /* !__THUNAR_EXEC_H__ */
+G_END_DECLS
+
+#endif /* !__THUNAR_NOTIFY_H__ */
diff --git a/thunar/thunar-shortcuts-view.c b/thunar/thunar-shortcuts-view.c
index c7df182..58f291e 100644
--- a/thunar/thunar-shortcuts-view.c
+++ b/thunar/thunar-shortcuts-view.c
@@ -1,24 +1,22 @@
-/* $Id$ */
+/* vi:set et ai sw=2 sts=2 ts=2: */
/*-
* Copyright (c) 2005-2007 Benedikt Meurer <benny at xfce.org>
- * Copyright (c) 2009 Jannis Pohlmann <jannis at xfce.org>
+ * Copyright (c) 2009-2010 Jannis Pohlmann <jannis at xfce.org>
*
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
*
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Inspired by the shortcuts list as found in the GtkFileChooser, which was
- * developed for Gtk+ by Red Hat, Inc.
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
@@ -32,6 +30,9 @@
#include <string.h>
#endif
+#ifdef HAVE_LIBNOTIFY
+#include <thunar/thunar-notify.h>
+#endif
#include <thunar/thunar-application.h>
#include <thunar/thunar-browser.h>
#include <thunar/thunar-dialogs.h>
@@ -1376,6 +1377,10 @@ thunar_shortcuts_view_eject_finish (GObject *object,
}
}
+#ifdef HAVE_LIBNOTIFY
+ thunar_notify_eject_finish (volume);
+#endif
+
g_object_unref (view);
}
@@ -1413,6 +1418,10 @@ thunar_shortcuts_view_unmount_finish (GObject *object,
}
}
+#ifdef HAVE_LIBNOTIFY
+ thunar_notify_unmount_finish (mount);
+#endif
+
g_object_unref (view);
}
@@ -1440,6 +1449,10 @@ thunar_shortcuts_view_eject (ThunarShortcutsView *view)
/* determine what the appropriate method is: eject or unmount */
if (g_volume_can_eject (volume))
{
+#ifdef HAVE_LIBNOTIFY
+ thunar_notify_eject (volume);
+#endif
+
/* try to to eject the volume asynchronously */
g_volume_eject (volume, G_MOUNT_UNMOUNT_NONE, NULL,
thunar_shortcuts_view_eject_finish,
@@ -1451,6 +1464,10 @@ thunar_shortcuts_view_eject (ThunarShortcutsView *view)
mount = g_volume_get_mount (volume);
if (G_LIKELY (mount != NULL))
{
+#ifdef HAVE_LIBNOTIFY
+ thunar_notify_unmount (mount);
+#endif
+
/* the volume is mounted, try to unmount the mount */
g_mount_unmount (mount, G_MOUNT_UNMOUNT_NONE, NULL,
thunar_shortcuts_view_unmount_finish,
diff --git a/thunar/thunar-tree-view.c b/thunar/thunar-tree-view.c
index d5c05c9..1bee4bb 100644
--- a/thunar/thunar-tree-view.c
+++ b/thunar/thunar-tree-view.c
@@ -1,21 +1,22 @@
-/* $Id$ */
+/* vi:set et ai sw=2 sts=2 ts=2: */
/*-
- * Copyright (c) 2006 Benedikt Meurer <benny at xfce.org>
- * Copyright (c) 2009 Jannis Pohlmann <jannis at xfce.org>
+ * Copyright (c) 2006 Benedikt Meurer <benny at xfce.org>
+ * Copyright (c) 2009-2010 Jannis Pohlmann <jannis at xfce.org>
*
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
*
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place, Suite 330, Boston, MA 02111-1307 USA
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
@@ -24,6 +25,9 @@
#include <gdk/gdkkeysyms.h>
+#ifdef HAVE_LIBNOTIFY
+#include <thunar/thunar-notify.h>
+#endif
#include <thunar/thunar-application.h>
#include <thunar/thunar-clipboard-manager.h>
#include <thunar/thunar-create-dialog.h>
@@ -1748,6 +1752,10 @@ thunar_tree_view_action_eject_finish (GObject *object,
}
}
+#ifdef HAVE_LIBNOTIFY
+ thunar_notify_eject_finish (volume);
+#endif
+
g_object_unref (view);
}
@@ -1785,6 +1793,10 @@ thunar_tree_view_action_unmount_finish (GObject *object,
}
}
+#ifdef HAVE_LIBNOTIFY
+ thunar_notify_unmount_finish (mount);
+#endif
+
g_object_unref (view);
}
@@ -1793,8 +1805,8 @@ thunar_tree_view_action_unmount_finish (GObject *object,
static void
thunar_tree_view_action_eject (ThunarTreeView *view)
{
- GVolume *volume;
- GMount *mount;
+ GVolume *volume;
+ GMount *mount;
_thunar_return_if_fail (THUNAR_IS_TREE_VIEW (view));
@@ -1805,6 +1817,10 @@ thunar_tree_view_action_eject (ThunarTreeView *view)
/* determine what the appropriate method is: eject or unmount */
if (g_volume_can_eject (volume))
{
+#ifdef HAVE_LIBNOTIFY
+ thunar_notify_eject (volume);
+#endif
+
/* try to to eject the volume asynchronously */
g_volume_eject (volume, G_MOUNT_UNMOUNT_NONE, NULL,
thunar_tree_view_action_eject_finish,
@@ -1816,6 +1832,10 @@ thunar_tree_view_action_eject (ThunarTreeView *view)
mount = g_volume_get_mount (volume);
if (G_LIKELY (mount != NULL))
{
+#ifdef HAVE_LIBNOTIFY
+ thunar_notify_unmount (mount);
+#endif
+
/* the volume is mounted, try to unmount the mount */
g_mount_unmount (mount, G_MOUNT_UNMOUNT_NONE, NULL,
thunar_tree_view_action_unmount_finish,
More information about the Xfce4-commits
mailing list