[Xfce4-commits] <thunar:nick/new-shortcuts-pane-model> Emit a device-changed when a mount for a known volume is added.
Nick Schermer
noreply at xfce.org
Sun Oct 7 13:48:01 CEST 2012
Updating branch refs/heads/nick/new-shortcuts-pane-model
to 8f8e4d6d26702b140efd053aebbdfa6bbcb4efc3 (commit)
from 3f1ca47ed23696aa6fe6a3e5d4c1caed45434977 (commit)
commit 8f8e4d6d26702b140efd053aebbdfa6bbcb4efc3
Author: Nick Schermer <nick at xfce.org>
Date: Sun Oct 7 11:11:09 2012 +0200
Emit a device-changed when a mount for a known volume is added.
thunar/thunar-device-monitor.c | 93 ++++++++++++++-------------------------
thunar/thunar-tree-model.c | 14 +++---
thunar/thunar-window.c | 2 +-
3 files changed, 42 insertions(+), 67 deletions(-)
diff --git a/thunar/thunar-device-monitor.c b/thunar/thunar-device-monitor.c
index 284c7f8..a275e92 100644
--- a/thunar/thunar-device-monitor.c
+++ b/thunar/thunar-device-monitor.c
@@ -276,57 +276,6 @@ thunar_device_monitor_mount_is_internal (GMount *mount)
static gboolean
-thunar_device_monitor_has_location (ThunarDeviceMonitor *monitor,
- GFile *location)
-{
-
- _thunar_return_val_if_fail (G_IS_FILE (location), FALSE);
- _thunar_return_val_if_fail (THUNAR_IS_DEVICE_MONITOR (monitor), FALSE);
-
- return FALSE;
-}
-
-
-
-static gboolean
-thunar_device_monitor_mount_is_hidden (GMount *mount,
- ThunarDeviceMonitor *monitor)
-{
- GVolume *volume;
- GFile *location;
-
- _thunar_return_val_if_fail (G_IS_MOUNT (mount), TRUE);
- _thunar_return_val_if_fail (THUNAR_IS_DEVICE_MONITOR (monitor), TRUE);
-
- /* never show shadowed mounts */
- if (g_mount_is_shadowed (mount))
- return TRUE;
-
- /* skip mounts with a volume, we prefer a volume as device */
- volume = g_mount_get_volume (mount);
- if (volume != NULL)
- {
- g_object_unref (volume);
- return TRUE;
- }
-
- location = g_mount_get_root (mount);
-
- /* skip ghoto locations, since those also have a volume
- * and igore locations already in the device list */
- if (g_file_has_uri_scheme (location, "gphoto2")
- || thunar_device_monitor_has_location (monitor, location))
- {
- g_object_unref (location);
- return TRUE;
- }
-
- return FALSE;
-}
-
-
-
-static gboolean
thunar_device_monitor_volume_is_visible (GVolume *volume)
{
gboolean can_eject = FALSE;
@@ -519,26 +468,40 @@ thunar_device_monitor_mount_added (GVolumeMonitor *volume_monitor,
ThunarDevice *device;
GFile *location;
ThunarDeviceKind kind = THUNAR_DEVICE_KIND_MOUNT_LOCAL;
+ GVolume *volume;
_thunar_return_if_fail (G_IS_VOLUME_MONITOR (volume_monitor));
_thunar_return_if_fail (THUNAR_IS_DEVICE_MONITOR (monitor));
_thunar_return_if_fail (monitor->volume_monitor == volume_monitor);
_thunar_return_if_fail (G_IS_MOUNT (mount));
- if (!thunar_device_monitor_mount_is_hidden (mount, monitor))
+ /* never handle shadowed mounts */
+ if (g_mount_is_shadowed (mount))
+ return;
+
+ /* volume for this mount */
+ volume = g_mount_get_volume (mount);
+ if (volume == NULL)
{
location = g_mount_get_root (mount);
- if (G_LIKELY (location != NULL))
- {
- if (g_file_has_uri_scheme (location, "file")
- || g_file_has_uri_scheme (location, "archive"))
- kind = THUNAR_DEVICE_KIND_MOUNT_LOCAL;
- else
- kind = THUNAR_DEVICE_KIND_MOUNT_REMOTE;
+ if (G_UNLIKELY (location == NULL))
+ return;
+ /* skip ghoto locations, since those also have a volume */
+ if (g_file_has_uri_scheme (location, "gphoto2"))
+ {
g_object_unref (location);
+ return;
}
+ if (g_file_has_uri_scheme (location, "file")
+ || g_file_has_uri_scheme (location, "archive"))
+ kind = THUNAR_DEVICE_KIND_MOUNT_LOCAL;
+ else
+ kind = THUNAR_DEVICE_KIND_MOUNT_REMOTE;
+
+ g_object_unref (location);
+
/* create a new device for this mount */
device = g_object_new (THUNAR_TYPE_DEVICE,
"device", mount,
@@ -551,6 +514,18 @@ thunar_device_monitor_mount_added (GVolumeMonitor *volume_monitor,
/* notify */
g_signal_emit (G_OBJECT (monitor), device_monitor_signals[DEVICE_ADDED], 0, device);
}
+ else
+ {
+ /* maybe we mounted a volume */
+ device = g_hash_table_lookup (monitor->devices, volume);
+ if (device != NULL)
+ {
+ /* notify */
+ g_signal_emit (G_OBJECT (monitor), device_monitor_signals[DEVICE_CHANGED], 0, device);
+ }
+
+ g_object_unref (volume);
+ }
}
diff --git a/thunar/thunar-tree-model.c b/thunar/thunar-tree-model.c
index 4c5df5a..913ed23 100644
--- a/thunar/thunar-tree-model.c
+++ b/thunar/thunar-tree-model.c
@@ -853,7 +853,7 @@ thunar_tree_model_sort (ThunarTreeModel *model,
guint n_children;
gint *new_order;
guint n;
-
+
_thunar_return_if_fail (THUNAR_IS_TREE_MODEL (model));
/* determine the number of children of the node */
@@ -970,7 +970,7 @@ thunar_tree_model_device_changed (ThunarDeviceMonitor *device_monitor,
_thunar_return_if_fail (model->device_monitor == device_monitor);
_thunar_return_if_fail (THUNAR_IS_DEVICE (device));
_thunar_return_if_fail (THUNAR_IS_TREE_MODEL (model));
-
+
/* lookup the volume in the item list */
for (node = model->root->children; node != NULL; node = node->next)
{
@@ -982,7 +982,7 @@ thunar_tree_model_device_changed (ThunarDeviceMonitor *device_monitor,
/* verify that we actually found the item */
_thunar_assert (item != NULL);
_thunar_assert (item->device == device);
-
+
/* check if the volume is mounted and we don't have a file yet */
if (thunar_device_is_mounted (device) && item->file == NULL)
{
@@ -1002,15 +1002,15 @@ thunar_tree_model_device_changed (ThunarDeviceMonitor *device_monitor,
{
/* reset the item for the node */
thunar_tree_model_item_reset (item);
-
+
/* release all child nodes */
while (node->children != NULL)
g_node_traverse (node->children, G_POST_ORDER, G_TRAVERSE_ALL, -1, thunar_tree_model_node_traverse_remove, model);
-
+
/* append the dummy node */
thunar_tree_model_node_insert_dummy (node, model);
}
-
+
/* generate an iterator for the item */
GTK_TREE_ITER_INIT (iter, model->stamp, node);
@@ -1065,7 +1065,7 @@ thunar_tree_model_device_added (ThunarDeviceMonitor *device_monitor,
GtkTreePath *path;
GtkTreeIter iter;
GNode *node;
-
+
_thunar_return_if_fail (THUNAR_IS_DEVICE_MONITOR (device_monitor));
_thunar_return_if_fail (model->device_monitor == device_monitor);
_thunar_return_if_fail (THUNAR_IS_DEVICE (device));
diff --git a/thunar/thunar-window.c b/thunar/thunar-window.c
index 53d2457..e6f8536 100644
--- a/thunar/thunar-window.c
+++ b/thunar/thunar-window.c
@@ -2793,7 +2793,7 @@ thunar_window_device_pre_unmount (ThunarDeviceMonitor *device_monitor,
mount_point = thunar_device_get_root (device);
file = thunar_file_cache_lookup (mount_point);
g_object_unref (mount_point);
-g_message ("%p file", file);
+
if (G_UNLIKELY (file == NULL))
return;
More information about the Xfce4-commits
mailing list