[Xfce4-commits] <thunar:master> Improvements in device handling.
Nick Schermer
noreply at xfce.org
Tue Oct 23 20:24:01 CEST 2012
Updating branch refs/heads/master
to b63fd6bcc745744ff2f3d89f5da9ee820b0b3111 (commit)
from ab899bff9bd91d2e0e514502cbaed8ad8d433c8a (commit)
commit b63fd6bcc745744ff2f3d89f5da9ee820b0b3111
Author: Nick Schermer <nick at xfce.org>
Date: Tue Oct 23 20:09:12 2012 +0200
Improvements in device handling.
Supprt GDrive stopping, improve notification code and
also condense the device_finish functions.
thunar/Makefile.am | 9 +-
thunar/main.c | 5 +-
thunar/thunar-device.c | 347 ++++++++++++++++++++------------------------
thunar/thunar-notify.c | 275 +++++++++++++++---------------------
thunar/thunar-notify.h | 22 ++--
thunar/thunar-tree-view.c | 3 -
6 files changed, 289 insertions(+), 372 deletions(-)
diff --git a/thunar/Makefile.am b/thunar/Makefile.am
index bc12573..f0a4042 100644
--- a/thunar/Makefile.am
+++ b/thunar/Makefile.am
@@ -21,12 +21,6 @@ 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
@@ -35,7 +29,6 @@ thunar_SOURCES = \
$(thunar_include_HEADERS) \
$(thunar_built_sources) \
$(thunar_dbus_sources) \
- $(thunar_notify_sources) \
main.c \
thunar-abstract-dialog.c \
thunar-abstract-dialog.h \
@@ -137,6 +130,8 @@ thunar_SOURCES = \
thunar-location-entry.h \
thunar-misc-jobs.c \
thunar-misc-jobs.h \
+ thunar-notify.c \
+ thunar-notify.h \
thunar-navigator.c \
thunar-navigator.h \
thunar-pango-extensions.c \
diff --git a/thunar/main.c b/thunar/main.c
index ea94e00..6386b46 100644
--- a/thunar/main.c
+++ b/thunar/main.c
@@ -35,15 +35,12 @@
#include <xfconf/xfconf.h>
-#ifdef HAVE_LIBNOTIFY
-#include <thunar/thunar-notify.h>
-#endif
-
#include <thunar/thunar-application.h>
#include <thunar/thunar-dbus-client.h>
#include <thunar/thunar-dbus-service.h>
#include <thunar/thunar-gobject-extensions.h>
#include <thunar/thunar-private.h>
+#include <thunar/thunar-notify.h>
#include <thunar/thunar-session-client.h>
#include <thunar/thunar-stock.h>
diff --git a/thunar/thunar-device.c b/thunar/thunar-device.c
index c0f6bbf..5692b09 100644
--- a/thunar/thunar-device.c
+++ b/thunar/thunar-device.c
@@ -20,13 +20,17 @@
#include <config.h>
#endif
-#ifdef HAVE_LIBNOTIFY
-#include <thunar/thunar-notify.h>
-#endif
#include <thunar/thunar-device.h>
#include <thunar/thunar-device-monitor.h>
#include <thunar/thunar-private.h>
#include <thunar/thunar-file.h>
+#include <thunar/thunar-notify.h>
+
+
+
+typedef gboolean (*AsyncCallbackFinish) (GObject *object,
+ GAsyncResult *result,
+ GError **error);
@@ -75,10 +79,15 @@ struct _ThunarDevice
typedef struct
{
+ /* the device the operation is working on */
ThunarDevice *device;
+
+ /* finish function for the async callback */
+ AsyncCallbackFinish callback_finish;
+
+ /* callback for the user */
ThunarDeviceCallback callback;
gpointer user_data;
- GFile *root_file;
}
ThunarDeviceOperation;
@@ -212,184 +221,83 @@ thunar_device_set_property (GObject *object,
-
static ThunarDeviceOperation *
thunar_device_operation_new (ThunarDevice *device,
ThunarDeviceCallback callback,
- gpointer user_data)
+ gpointer user_data,
+ gpointer callback_finish)
{
- ThunarDeviceOperation *operation;
-
- operation = g_slice_new0 (ThunarDeviceOperation);
- operation->device = g_object_ref (device);
- operation->callback = callback;
- operation->user_data = user_data;
- operation->root_file = thunar_device_get_root (device);
-
- return operation;
-}
-
+ ThunarDeviceOperation *op;
+ op = g_slice_new0 (ThunarDeviceOperation);
+ op->device = g_object_ref (device);
+ op->callback = callback;
+ op->callback_finish = callback_finish;
+ op->user_data = user_data;
-static void
-thunar_device_operation_free (ThunarDeviceOperation *operation)
-{
- g_object_unref (operation->device);
- if (operation->root_file != NULL)
- g_object_unref (operation->root_file);
- g_slice_free (ThunarDeviceOperation, operation);
-}
-
-
-
-static void
-thunar_device_operation_emit_pre_unmount (ThunarDeviceOperation *operation)
-{
- ThunarDeviceMonitor *monitor;
-
- if (operation->root_file != NULL)
- {
- /* make sure the pre-unmount event is emitted, this is important
- * for the interface */
- monitor = thunar_device_monitor_get ();
- g_signal_emit_by_name (monitor, "device-pre-unmount",
- operation->device, operation->root_file);
- g_object_unref (monitor);
- }
-}
-
-
-
-static void
-thunar_device_mount_unmount_finish (GObject *object,
- GAsyncResult *result,
- gpointer user_data)
-{
- ThunarDeviceOperation *operation = user_data;
- GError *error = NULL;
-
- _thunar_return_if_fail (G_IS_MOUNT (object));
- _thunar_return_if_fail (G_IS_ASYNC_RESULT (result));
-
-#ifdef HAVE_LIBNOTIFY
- thunar_notify_unmount_finish (G_MOUNT (object));
-#endif
-
- /* finish the unmount */
- if (!g_mount_unmount_with_operation_finish (G_MOUNT (object), result, &error))
- {
- /* unset the error if a helper program has already interacted with the user */
- if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_FAILED_HANDLED))
- g_clear_error (&error);
- }
-
- /* callback */
- (operation->callback) (operation->device, error, operation->user_data);
-
- /* cleanup */
- if (error != NULL)
- g_error_free (error);
- thunar_device_operation_free (operation);
+ return op;
}
static void
-thunar_device_mount_eject_finish (GObject *object,
- GAsyncResult *result,
- gpointer user_data)
+thunar_device_operation_finish (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
{
- ThunarDeviceOperation *operation = user_data;
+ ThunarDeviceOperation *op = user_data;
GError *error = NULL;
-
- _thunar_return_if_fail (G_IS_MOUNT (object));
+
+ _thunar_return_if_fail (G_IS_OBJECT (object));
_thunar_return_if_fail (G_IS_ASYNC_RESULT (result));
-#ifdef HAVE_LIBNOTIFY
- thunar_notify_unmount_finish (G_MOUNT (object));
-#endif
+ /* remove notification */
+ thunar_notify_finish (op->device);
- /* finish the eject */
- if (!g_mount_eject_with_operation_finish (G_MOUNT (object), result, &error))
+ /* finish the operation */
+ if (!(op->callback_finish) (object, result, &error))
{
/* unset the error if a helper program has already interacted with the user */
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_FAILED_HANDLED))
g_clear_error (&error);
- }
-
- /* callback */
- (operation->callback) (operation->device, error, operation->user_data);
-
- /* cleanup */
- if (error != NULL)
- g_error_free (error);
- thunar_device_operation_free (operation);
-}
-
-
-
-static void
-thunar_device_volume_mount_finished (GObject *object,
- GAsyncResult *result,
- gpointer user_data)
-{
- ThunarDeviceOperation *operation = user_data;
- GError *error = NULL;
- _thunar_return_if_fail (G_IS_VOLUME (object));
- _thunar_return_if_fail (G_IS_ASYNC_RESULT (result));
-
- /* finish the eject */
- if (!g_volume_mount_finish (G_VOLUME (object), result, &error))
- {
- /* unset the error if a helper program has already interacted with the user */
- if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_FAILED_HANDLED)
- || g_error_matches (error, G_IO_ERROR, G_IO_ERROR_ALREADY_MOUNTED)
- || g_error_matches (error, G_IO_ERROR, G_IO_ERROR_PENDING))
- g_clear_error (&error);
+ if (op->callback_finish == (AsyncCallbackFinish) g_volume_mount_finish)
+ {
+ /* special handling for mount operation */
+ if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_ALREADY_MOUNTED)
+ || g_error_matches (error, G_IO_ERROR, G_IO_ERROR_PENDING))
+ g_clear_error (&error);
+ }
}
- /* callback */
- (operation->callback) (operation->device, error, operation->user_data);
+ /* user callback */
+ (op->callback) (op->device, error, op->user_data);
/* cleanup */
- if (error != NULL)
- g_error_free (error);
- thunar_device_operation_free (operation);
+ g_clear_error (&error);
+ g_object_unref (G_OBJECT (op->device));
+ g_slice_free (ThunarDeviceOperation, op);
}
static void
-thunar_device_volume_eject_finish (GObject *object,
- GAsyncResult *result,
- gpointer user_data)
+thunar_device_emit_pre_unmount (ThunarDevice *device,
+ gboolean all_volumes)
{
- ThunarDeviceOperation *operation = user_data;
- GError *error = NULL;
-
- _thunar_return_if_fail (G_IS_VOLUME (object));
- _thunar_return_if_fail (G_IS_ASYNC_RESULT (result));
-
-#ifdef HAVE_LIBNOTIFY
- thunar_notify_eject_finish (G_VOLUME (object));
-#endif
+ ThunarDeviceMonitor *monitor;
+ GFile *root_file;
- /* finish the eject */
- if (!g_volume_eject_with_operation_finish (G_VOLUME (object), result, &error))
+ root_file = thunar_device_get_root (device);
+ if (root_file != NULL)
{
- /* unset the error if a helper program has already interacted with the user */
- if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_FAILED_HANDLED))
- g_clear_error (&error);
+ /* make sure the pre-unmount event is emitted, this is important
+ * for the interface */
+ monitor = thunar_device_monitor_get ();
+ g_signal_emit_by_name (monitor, "device-pre-unmount", device, root_file);
+ g_object_unref (monitor);
+ g_object_unref (root_file);
}
-
- /* callback */
- (operation->callback) (operation->device, error, operation->user_data);
-
- /* cleanup */
- if (error != NULL)
- g_error_free (error);
- thunar_device_operation_free (operation);
}
@@ -503,21 +411,32 @@ thunar_device_can_eject (const ThunarDevice *device)
{
gboolean can_eject = FALSE;
GMount *volume_mount;
+ GDrive *drive;
_thunar_return_val_if_fail (THUNAR_IS_DEVICE (device), FALSE);
if (G_IS_VOLUME (device->device))
{
- can_eject = g_volume_can_eject (device->device);
+ drive = g_volume_get_drive (device->device);
+ if (drive != NULL)
+ {
+ can_eject = g_drive_can_eject (drive) || g_drive_can_stop (drive);
+ g_object_unref (drive);
+ }
if (!can_eject)
{
- /* check if the mount can eject/unmount */
- volume_mount = g_volume_get_mount (device->device);
- if (volume_mount != NULL)
+ /* check if the volume can eject */
+ can_eject = g_volume_can_eject (device->device);
+ if (!can_eject)
{
- can_eject = g_mount_can_eject (volume_mount) || g_mount_can_unmount (volume_mount);
- g_object_unref (volume_mount);
+ /* check if the mount can eject/unmount */
+ volume_mount = g_volume_get_mount (device->device);
+ if (volume_mount != NULL)
+ {
+ can_eject = g_mount_can_eject (volume_mount) || g_mount_can_unmount (volume_mount);
+ g_object_unref (volume_mount);
+ }
}
}
}
@@ -693,7 +612,7 @@ thunar_device_mount (ThunarDevice *device,
ThunarDeviceCallback callback,
gpointer user_data)
{
- ThunarDeviceOperation *operation;
+ ThunarDeviceOperation *op;
_thunar_return_if_fail (THUNAR_IS_DEVICE (device));
_thunar_return_if_fail (G_IS_MOUNT_OPERATION (mount_operation));
@@ -702,13 +621,14 @@ thunar_device_mount (ThunarDevice *device,
if (G_IS_VOLUME (device->device))
{
- operation = thunar_device_operation_new (device, callback, user_data);
+ op = thunar_device_operation_new (device, callback, user_data,
+ g_volume_mount_finish);
g_volume_mount (G_VOLUME (device->device),
G_MOUNT_MOUNT_NONE,
mount_operation,
cancellable,
- thunar_device_volume_mount_finished,
- operation);
+ thunar_device_operation_finish,
+ op);
}
}
@@ -726,7 +646,7 @@ thunar_device_unmount (ThunarDevice *device,
ThunarDeviceCallback callback,
gpointer user_data)
{
- ThunarDeviceOperation *operation;
+ ThunarDeviceOperation *op;
GMount *mount;
_thunar_return_if_fail (THUNAR_IS_DEVICE (device));
@@ -747,19 +667,19 @@ thunar_device_unmount (ThunarDevice *device,
/* only handle mounts that can be unmounted here */
if (g_mount_can_unmount (mount))
{
-#ifdef HAVE_LIBNOTIFY
- thunar_notify_unmount (mount);
-#endif
+ /* inform user */
+ thunar_notify_unmount (device);
/* try unmounting the mount */
- operation = thunar_device_operation_new (device, callback, user_data);
- thunar_device_operation_emit_pre_unmount (operation);
+ thunar_device_emit_pre_unmount (device, FALSE);
+ op = thunar_device_operation_new (device, callback, user_data,
+ g_mount_unmount_with_operation_finish);
g_mount_unmount_with_operation (mount,
G_MOUNT_UNMOUNT_NONE,
mount_operation,
cancellable,
- thunar_device_mount_unmount_finish,
- operation);
+ thunar_device_operation_finish,
+ op);
}
g_object_unref (G_OBJECT (mount));
@@ -780,35 +700,84 @@ thunar_device_eject (ThunarDevice *device,
ThunarDeviceCallback callback,
gpointer user_data)
{
- ThunarDeviceOperation *operation;
+ ThunarDeviceOperation *op;
GMount *mount = NULL;
GVolume *volume;
+ GDrive *drive;
_thunar_return_if_fail (THUNAR_IS_DEVICE (device));
_thunar_return_if_fail (G_IS_MOUNT_OPERATION (mount_operation));
_thunar_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
_thunar_return_if_fail (callback != NULL);
-
if (G_IS_VOLUME (device->device))
{
volume = device->device;
+ drive = g_volume_get_drive (volume);
+
+ if (drive != NULL)
+ {
+ if (g_drive_can_stop (drive))
+ {g_message ("stop drive");
+ /* inform user */
+ thunar_notify_eject (device);
+
+ /* try to stop the drive */
+ thunar_device_emit_pre_unmount (device, TRUE);
+ op = thunar_device_operation_new (device, callback, user_data,
+ g_drive_stop_finish);
+ g_drive_stop (drive,
+ G_MOUNT_UNMOUNT_NONE,
+ mount_operation,
+ cancellable,
+ thunar_device_operation_finish,
+ op);
+
+ g_object_unref (drive);
+
+ /* done */
+ return;
+ }
+ else if (g_drive_can_eject (drive))
+ {g_message ("eject drive");
+ /* inform user */
+ thunar_notify_eject (device);
+
+ /* try to stop the drive */
+ thunar_device_emit_pre_unmount (device, TRUE);
+ op = thunar_device_operation_new (device, callback, user_data,
+ g_drive_eject_with_operation_finish);
+ g_drive_eject_with_operation (drive,
+ G_MOUNT_UNMOUNT_NONE,
+ mount_operation,
+ cancellable,
+ thunar_device_operation_finish,
+ op);
+
+ g_object_unref (drive);
+
+ /* done */
+ return;
+ }
+
+ g_object_unref (drive);
+ }
if (g_volume_can_eject (volume))
{
-#ifdef HAVE_LIBNOTIFY
- thunar_notify_eject (volume);
-#endif
+ /* inform user */
+ thunar_notify_eject (device);
/* try ejecting the volume */
- operation = thunar_device_operation_new (device, callback, user_data);
- thunar_device_operation_emit_pre_unmount (operation);
+ thunar_device_emit_pre_unmount (device, TRUE);
+ op = thunar_device_operation_new (device, callback, user_data,
+ g_volume_eject_with_operation_finish);
g_volume_eject_with_operation (volume,
G_MOUNT_UNMOUNT_NONE,
mount_operation,
cancellable,
- thunar_device_volume_eject_finish,
- operation);
+ thunar_device_operation_finish,
+ op);
/* done */
return;
@@ -831,35 +800,35 @@ thunar_device_eject (ThunarDevice *device,
/* distinguish between ejectable and unmountable mounts */
if (g_mount_can_eject (mount))
{
-#ifdef HAVE_LIBNOTIFY
- thunar_notify_unmount (mount);
-#endif
+ /* inform user */
+ thunar_notify_eject (device);
/* try ejecting the mount */
- operation = thunar_device_operation_new (device, callback, user_data);
- thunar_device_operation_emit_pre_unmount (operation);
+ thunar_device_emit_pre_unmount (device, FALSE);
+ op = thunar_device_operation_new (device, callback, user_data,
+ g_mount_eject_with_operation_finish);
g_mount_eject_with_operation (mount,
G_MOUNT_UNMOUNT_NONE,
mount_operation,
cancellable,
- thunar_device_mount_eject_finish,
- operation);
+ thunar_device_operation_finish,
+ op);
}
else if (g_mount_can_unmount (mount))
{
-#ifdef HAVE_LIBNOTIFY
- thunar_notify_unmount (mount);
-#endif
+ /* inform user */
+ thunar_notify_unmount (device);
/* try unmounting the mount */
- operation = thunar_device_operation_new (device, callback, user_data);
- thunar_device_operation_emit_pre_unmount (operation);
+ thunar_device_emit_pre_unmount (device, FALSE);
+ op = thunar_device_operation_new (device, callback, user_data,
+ g_mount_unmount_with_operation_finish);
g_mount_unmount_with_operation (mount,
G_MOUNT_UNMOUNT_NONE,
mount_operation,
cancellable,
- thunar_device_mount_unmount_finish,
- operation);
+ thunar_device_operation_finish,
+ op);
}
g_object_unref (G_OBJECT (mount));
diff --git a/thunar/thunar-notify.c b/thunar/thunar-notify.c
index 34bd046..b7c647f 100644
--- a/thunar/thunar-notify.c
+++ b/thunar/thunar-notify.c
@@ -2,18 +2,18 @@
/*-
* Copyright (c) 2010 Jannis Pohlmann <jannis at xfce.org>
*
- * This program is free software; you can redistribute it and/or
+ * 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
+ * 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
+ * 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
+ * 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.
*/
@@ -22,16 +22,16 @@
#include <config.h>
#endif
-#include <glib.h>
-#include <gio/gio.h>
-
#include <libnotify/notify.h>
-#include <libxfce4util/libxfce4util.h>
-
#include <thunar/thunar-notify.h>
+#include <thunar/thunar-device.h>
+#include <thunar/thunar-private.h>
+
+
+#ifdef HAVE_LIBNOTIFY
static gboolean thunar_notify_initted = FALSE;
@@ -60,80 +60,43 @@ thunar_notify_init (void)
-void
-thunar_notify_unmount (GMount *mount)
+static void
+thunar_notify_show (ThunarDevice *device,
+ const gchar *summary,
+ const gchar *message)
{
- 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 = NULL;
- gchar *message;
- gchar *name;
-
- g_return_if_fail (G_IS_MOUNT (mount));
-
- if (!thunar_notify_init ())
- return;
-
- 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))
+ NotifyNotification *notification;
+ GIcon *icon;
+ gchar *icon_name = NULL;
+ GFile *icon_file;
+ const gchar* const *icon_names;
+
+ /* get suitable icon for the device */
+ icon = thunar_device_get_icon (device);
+ if (icon != NULL)
{
- icon_file = g_file_icon_get_file (G_FILE_ICON (icon));
- if (icon_file != NULL)
+ if (G_IS_THEMED_ICON (icon))
{
- icon_name = g_file_get_path (icon_file);
- g_object_unref (icon_file);
+ 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);
}
- g_object_unref (icon);
if (icon_name == NULL)
icon_name = g_strdup ("drive-removable-media");
- 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 media or disconnect the drive"),
- name);
- }
-
+ /* create notification */
#ifdef NOTIFY_CHECK_VERSION
#if NOTIFY_CHECK_VERSION (0, 7, 0)
notification = notify_notification_new (summary, message, icon_name);
@@ -143,101 +106,105 @@ thunar_notify_unmount (GMount *mount)
#else
notification = notify_notification_new (summary, message, icon_name, NULL);
#endif
+
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);
+ /* attach to object for finalize */
+ g_object_set_data_full (G_OBJECT (device), I_("thunar-notification"),
+ notification, g_object_unref);
- g_free (message);
g_free (icon_name);
- g_free (name);
}
-void
-thunar_notify_unmount_finish (GMount *mount)
+static gboolean
+thunar_notify_device_readonly (ThunarDevice *device)
{
- NotifyNotification *notification;
-
- g_return_if_fail (G_IS_MOUNT (mount));
+ GFile *mount_point;
+ gboolean readonly = TRUE;
+ GFileInfo *info;
- notification = g_object_get_data (G_OBJECT (mount), "thunar-notification");
- if (notification != NULL)
+ mount_point = thunar_device_get_root (device);
+ if (mount_point != NULL)
{
- notify_notification_close (notification, NULL);
- g_object_set_data (G_OBJECT (mount), "thunar-notification", NULL);
+ info = g_file_query_info (mount_point, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE,
+ G_FILE_QUERY_INFO_NONE, NULL, NULL);
+
+ if (info != NULL)
+ {
+ if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE))
+ readonly = !g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE);
+ g_object_unref (info);
+ }
+
+ g_object_unref (mount_point);
}
+
+ return readonly;
}
+#endif
void
-thunar_notify_eject (GVolume *volume)
+thunar_notify_unmount (ThunarDevice *device)
{
- 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 = NULL;
- gchar *message;
- gchar *name;
-
- g_return_if_fail (G_IS_VOLUME (volume));
+#ifdef HAVE_LIBNOTIFY
+ gchar *name;
+ const gchar *summary;
+ gchar *message;
+
+ _thunar_return_if_fail (THUNAR_IS_DEVICE (device));
if (!thunar_notify_init ())
return;
- mount = g_volume_get_mount (volume);
- if (mount != NULL)
+ name = thunar_device_get_name (device);
+
+ if (thunar_notify_device_readonly (device))
{
- 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);
+ 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 media or disconnect the drive"),
+ name);
+ }
- if (info != NULL)
- {
- read_only =
- !g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE);
+ thunar_notify_show (device, summary, message);
- g_object_unref (info);
- }
+ g_free (name);
+ g_free (message);
+#endif
+}
- 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);
+void
+thunar_notify_eject (ThunarDevice *device)
+{
+#ifdef HAVE_LIBNOTIFY
+ gchar *name;
+ const gchar *summary;
+ gchar *message;
- if (icon_name == NULL)
- icon_name = g_strdup ("drive-removable-media");
+ _thunar_return_if_fail (THUNAR_IS_DEVICE (device));
+
+ if (!thunar_notify_init ())
+ return;
+
+ name = thunar_device_get_name (device);
- if (read_only)
+ if (thunar_notify_device_readonly (device))
{
summary = _("Ejecting device");
message = g_strdup_printf (_("The device \"%s\" is being ejected. "
@@ -252,42 +219,30 @@ thunar_notify_eject (GVolume *volume)
name);
}
-#ifdef NOTIFY_CHECK_VERSION
-#if NOTIFY_CHECK_VERSION (0, 7, 0)
- notification = notify_notification_new (summary, message, icon_name);
-#else
- notification = notify_notification_new (summary, message, icon_name, NULL);
-#endif
-#else
- notification = notify_notification_new (summary, message, icon_name, NULL);
-#endif
- 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);
+ thunar_notify_show (device, summary, message);
- g_free (message);
- g_free (icon_name);
g_free (name);
+ g_free (message);
+#endif
}
void
-thunar_notify_eject_finish (GVolume *volume)
+thunar_notify_finish (ThunarDevice *device)
{
+#ifdef HAVE_LIBNOTIFY
NotifyNotification *notification;
- g_return_if_fail (G_IS_VOLUME (volume));
+ _thunar_return_if_fail (THUNAR_IS_DEVICE (device));
- notification = g_object_get_data (G_OBJECT (volume), "thunar-notification");
+ notification = g_object_get_data (G_OBJECT (device), I_("thunar-notification"));
if (notification != NULL)
{
notify_notification_close (notification, NULL);
- g_object_set_data (G_OBJECT (volume), "thunar-notification", NULL);
+ g_object_set_data (G_OBJECT (device), I_("thunar-notification"), NULL);
}
+#endif
}
@@ -295,7 +250,9 @@ thunar_notify_eject_finish (GVolume *volume)
void
thunar_notify_uninit (void)
{
+#ifdef HAVE_LIBNOTIFY
if (thunar_notify_initted
&& notify_is_initted ())
notify_uninit ();
+#endif
}
diff --git a/thunar/thunar-notify.h b/thunar/thunar-notify.h
index 596ffa7..af17c87 100644
--- a/thunar/thunar-notify.h
+++ b/thunar/thunar-notify.h
@@ -2,18 +2,18 @@
/*-
* Copyright (c) 2010 Jannis Pohlmann <jannis at xfce.org>
*
- * This program is free software; you can redistribute it and/or
+ * 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
+ * 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
+ * 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
+ * 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.
*/
@@ -22,14 +22,16 @@
#define __THUNAR_NOTIFY_H__
#include <glib.h>
-#include <gio/gio.h>
+#include <thunar/thunar-device.h>
G_BEGIN_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);
+void thunar_notify_unmount (ThunarDevice *device);
+
+void thunar_notify_eject (ThunarDevice *device);
+
+void thunar_notify_finish (ThunarDevice *device);
+
void thunar_notify_uninit (void);
G_END_DECLS
diff --git a/thunar/thunar-tree-view.c b/thunar/thunar-tree-view.c
index 09c996d..e5f8c57 100644
--- a/thunar/thunar-tree-view.c
+++ b/thunar/thunar-tree-view.c
@@ -25,9 +25,6 @@
#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>
More information about the Xfce4-commits
mailing list