diff options
author | Nick Schermer <nick@xfce.org> | 2012-10-07 01:16:53 +0200 |
---|---|---|
committer | Nick Schermer <nick@xfce.org> | 2012-10-13 16:10:35 +0200 |
commit | 3dee1594752e97e7958abbfb029ce59ce026fe8f (patch) | |
tree | 674227a69f1908592600b4ef76a406edb0eae73e /thunar/thunar-tree-model.c | |
parent | 24a3e95c1c840c5104f9918d413002737489c9ef (diff) | |
download | thunar-3dee1594752e97e7958abbfb029ce59ce026fe8f.tar.gz |
Use ThunarDevice in the tree side pane.
Diffstat (limited to 'thunar/thunar-tree-model.c')
-rw-r--r-- | thunar/thunar-tree-model.c | 336 |
1 files changed, 133 insertions, 203 deletions
diff --git a/thunar/thunar-tree-model.c b/thunar/thunar-tree-model.c index df7c34d2..4cbf0e59 100644 --- a/thunar/thunar-tree-model.c +++ b/thunar/thunar-tree-model.c @@ -36,6 +36,7 @@ #include <thunar/thunar-preferences.h> #include <thunar/thunar-private.h> #include <thunar/thunar-tree-model.h> +#include <thunar/thunar-device-monitor.h> @@ -114,22 +115,19 @@ static void thunar_tree_model_cleanup_idle_destroy (gpointer static void thunar_tree_model_file_changed (ThunarFileMonitor *file_monitor, ThunarFile *file, ThunarTreeModel *model); -static void thunar_tree_model_mount_pre_unmount (GVolumeMonitor *volume_monitor, - GMount *mount, +static void thunar_tree_model_device_added (ThunarDeviceMonitor *device_monitor, + ThunarDevice *device, ThunarTreeModel *model); -static void thunar_tree_model_volume_added (GVolumeMonitor *volume_monitor, - GVolume *volume, +static void thunar_tree_model_device_removed (ThunarDeviceMonitor *device_monitor, + ThunarDevice *device, ThunarTreeModel *model); -static void thunar_tree_model_volume_removed (GVolumeMonitor *volume_monitor, - GVolume *volume, - ThunarTreeModel *model); -static void thunar_tree_model_volume_changed (GVolumeMonitor *volume_monitor, - GVolume *volume, +static void thunar_tree_model_device_changed (ThunarDeviceMonitor *device_monitor, + ThunarDevice *device, ThunarTreeModel *model); static ThunarTreeModelItem *thunar_tree_model_item_new_with_file (ThunarTreeModel *model, ThunarFile *file) G_GNUC_MALLOC; -static ThunarTreeModelItem *thunar_tree_model_item_new_with_volume (ThunarTreeModel *model, - GVolume *volume) G_GNUC_MALLOC; +static ThunarTreeModelItem *thunar_tree_model_item_new_with_device (ThunarTreeModel *model, + ThunarDevice *device) G_GNUC_MALLOC; static void thunar_tree_model_item_free (ThunarTreeModelItem *item); static void thunar_tree_model_item_reset (ThunarTreeModelItem *item); static void thunar_tree_model_item_load_folder (ThunarTreeModelItem *item); @@ -183,9 +181,8 @@ struct _ThunarTreeModel gint stamp; #endif - /* removable volumes */ - GVolumeMonitor *volume_monitor; - GList *hidden_volumes; + /* removable devices */ + ThunarDeviceMonitor *device_monitor; ThunarFileMonitor *file_monitor; @@ -205,7 +202,7 @@ struct _ThunarTreeModelItem guint load_idle_id; ThunarFile *file; ThunarFolder *folder; - GVolume *volume; + ThunarDevice *device; ThunarTreeModel *model; /* list of children of this node that are @@ -282,7 +279,7 @@ thunar_tree_model_init (ThunarTreeModel *model) GFile *desktop; GFile *home; GList *system_paths = NULL; - GList *volumes; + GList *devices; GList *lp; GNode *node; @@ -305,11 +302,10 @@ thunar_tree_model_init (ThunarTreeModel *model) model->root = g_node_new (NULL); /* connect to the volume monitor */ - model->volume_monitor = g_volume_monitor_get (); - g_signal_connect (model->volume_monitor, "mount-pre-unmount", G_CALLBACK (thunar_tree_model_mount_pre_unmount), model); - g_signal_connect (model->volume_monitor, "volume-added", G_CALLBACK (thunar_tree_model_volume_added), model); - g_signal_connect (model->volume_monitor, "volume-removed", G_CALLBACK (thunar_tree_model_volume_removed), model); - g_signal_connect (model->volume_monitor, "volume-changed", G_CALLBACK (thunar_tree_model_volume_changed), model); + model->device_monitor = thunar_device_monitor_get (); + g_signal_connect (model->device_monitor, "device-added", G_CALLBACK (thunar_tree_model_device_added), model); + g_signal_connect (model->device_monitor, "device-removed", G_CALLBACK (thunar_tree_model_device_removed), model); + g_signal_connect (model->device_monitor, "device-changed", G_CALLBACK (thunar_tree_model_device_changed), model); /* add the home folder to the system paths */ home = thunar_g_file_new_for_home (); @@ -360,14 +356,14 @@ thunar_tree_model_init (ThunarTreeModel *model) g_list_free (system_paths); g_object_unref (home); - /* setup the initial volumes */ - volumes = g_volume_monitor_get_volumes (model->volume_monitor); - for (lp = volumes; lp != NULL; lp = lp->next) + /* setup the initial devices */ + devices = thunar_device_monitor_get_devices (model->device_monitor); + for (lp = devices; lp != NULL; lp = lp->next) { - thunar_tree_model_volume_added (model->volume_monitor, lp->data, model); + thunar_tree_model_device_added (model->device_monitor, lp->data, model); g_object_unref (lp->data); } - g_list_free (volumes); + g_list_free (devices); } @@ -385,16 +381,13 @@ thunar_tree_model_finalize (GObject *object) g_signal_handlers_disconnect_by_func (model->file_monitor, thunar_tree_model_file_changed, model); g_object_unref (model->file_monitor); - /* release all hidden volumes */ - g_list_free_full (model->hidden_volumes, g_object_unref); - /* release all resources allocated to the model */ g_node_traverse (model->root, G_POST_ORDER, G_TRAVERSE_ALL, -1, thunar_tree_model_node_traverse_free, NULL); g_node_destroy (model->root); /* disconnect from the volume monitor */ - g_signal_handlers_disconnect_matched (model->volume_monitor, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, model); - g_object_unref (model->volume_monitor); + g_signal_handlers_disconnect_matched (model->device_monitor, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, model); + g_object_unref (model->device_monitor); (*G_OBJECT_CLASS (thunar_tree_model_parent_class)->finalize) (object); } @@ -476,8 +469,8 @@ thunar_tree_model_get_column_type (GtkTreeModel *tree_model, case THUNAR_TREE_MODEL_COLUMN_ATTR: return PANGO_TYPE_ATTR_LIST; - case THUNAR_TREE_MODEL_COLUMN_VOLUME: - return G_TYPE_VOLUME; + case THUNAR_TREE_MODEL_COLUMN_DEVICE: + return THUNAR_TYPE_DEVICE; default: _thunar_assert_not_reached (); @@ -613,8 +606,8 @@ thunar_tree_model_get_value (GtkTreeModel *tree_model, case THUNAR_TREE_MODEL_COLUMN_NAME: g_value_init (value, G_TYPE_STRING); - if (G_LIKELY (item != NULL && item->volume != NULL)) - g_value_take_string (value, g_volume_get_name (item->volume)); + if (G_LIKELY (item != NULL && item->device != NULL)) + g_value_take_string (value, thunar_device_get_name (item->device)); else if (G_LIKELY (item != NULL && item->file != NULL)) g_value_set_static_string (value, thunar_file_get_display_name (item->file)); else @@ -629,9 +622,9 @@ thunar_tree_model_get_value (GtkTreeModel *tree_model, g_value_set_boxed (value, thunar_pango_attr_list_italic ()); break; - case THUNAR_TREE_MODEL_COLUMN_VOLUME: - g_value_init (value, G_TYPE_VOLUME); - g_value_set_object (value, (item != NULL) ? item->volume : NULL); + case THUNAR_TREE_MODEL_COLUMN_DEVICE: + g_value_init (value, THUNAR_TYPE_DEVICE); + g_value_set_object (value, (item != NULL) ? item->device : NULL); break; default: @@ -959,128 +952,72 @@ thunar_tree_model_file_changed (ThunarFileMonitor *file_monitor, static void -thunar_tree_model_volume_changed (GVolumeMonitor *volume_monitor, - GVolume *volume, - ThunarTreeModel *model) +thunar_tree_model_device_changed (ThunarDeviceMonitor *device_monitor, + ThunarDevice *device, + ThunarTreeModel *model) { ThunarTreeModelItem *item = NULL; GtkTreePath *path; GtkTreeIter iter; - GMount *mount; GFile *mount_point; GNode *node; - GList *lp; - _thunar_return_if_fail (G_IS_VOLUME_MONITOR (volume_monitor)); - _thunar_return_if_fail (model->volume_monitor == volume_monitor); - _thunar_return_if_fail (G_IS_VOLUME (volume)); + _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)); _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) + { + item = THUNAR_TREE_MODEL_ITEM (node->data); + if (item->device == device) + break; + } - /* check if the volume is on the hidden list */ - lp = g_list_find (model->hidden_volumes, volume); - if (G_LIKELY (lp != NULL)) + /* 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) { - /* check if we need to display the volume now */ - if (thunar_g_volume_is_removable (volume) && thunar_g_volume_is_present (volume)) + mount_point = thunar_device_get_root (device); + if (mount_point != NULL) { - /* remove the volume from the list of hidden volumes */ - model->hidden_volumes = g_list_delete_link (model->hidden_volumes, lp); - - /* allocate a new item for the volume */ - item = thunar_tree_model_item_new_with_volume (model, volume); - - /* insert before the last child of the root (the "File System" node) */ - node = g_node_last_child (model->root); - node = g_node_insert_data_before (model->root, node, item); - - /* determine the iterator for the new node */ - GTK_TREE_ITER_INIT (iter, model->stamp, node); - - /* tell the view about the new node */ - path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), &iter); - gtk_tree_model_row_inserted (GTK_TREE_MODEL (model), path, &iter); - gtk_tree_path_free (path); + /* try to determine the file for the mount point */ + item->file = thunar_file_get (mount_point, NULL); - /* add the dummy node */ - thunar_tree_model_node_insert_dummy (node, model); + /* because the volume node is already reffed, we need to load the folder manually here */ + thunar_tree_model_item_load_folder (item); - /* drop our reference on the volume */ - g_object_unref (volume); + g_object_unref (mount_point); } } - else + else if (!thunar_device_is_mounted (device) && item->file != NULL) { - /* lookup the volume in the item list */ - for (node = model->root->children; node != NULL; node = node->next) - { - item = THUNAR_TREE_MODEL_ITEM (node->data); - if (item->volume == volume) - break; - } - - /* verify that we actually found the item */ - _thunar_assert (item != NULL); - _thunar_assert (item->volume == volume); - - /* check if we need to hide the volume now */ - if (!thunar_g_volume_is_removable (volume) || !thunar_g_volume_is_present (volume)) - { - /* need to ref here, because the volumes_removed() handler will drop the reference */ - g_object_ref (volume); - - /* use "volume-removed" handler to hide the volume */ - thunar_tree_model_volume_removed (model->volume_monitor, volume, model); - - /* move the volume to the hidden list */ - model->hidden_volumes = g_list_prepend (model->hidden_volumes, volume); - } - else - { - /* check if the volume is mounted and we don't have a file yet */ - if (thunar_g_volume_is_mounted (volume) && item->file == NULL) - { - mount = g_volume_get_mount (volume); - - if (G_LIKELY (mount != NULL)) - { - mount_point = g_mount_get_root (mount); - - /* try to determine the file for the mount point */ - item->file = thunar_file_get (mount_point, NULL); - - /* because the volume node is already reffed, we need to load the folder manually here */ - thunar_tree_model_item_load_folder (item); - - g_object_unref (mount_point); - g_object_unref (mount); - } - } - else if (!thunar_g_volume_is_mounted (volume) && item->file != NULL) - { - /* 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); - - /* tell the view that the volume has changed in some way */ - path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), &iter); - gtk_tree_model_row_changed (GTK_TREE_MODEL (model), path, &iter); - gtk_tree_path_free (path); - } + /* 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); + /* tell the view that the volume has changed in some way */ + path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), &iter); + gtk_tree_model_row_changed (GTK_TREE_MODEL (model), path, &iter); + gtk_tree_path_free (path); +} +#if 0 static void thunar_tree_model_mount_pre_unmount (GVolumeMonitor *volume_monitor, GMount *mount, @@ -1121,63 +1058,68 @@ thunar_tree_model_mount_pre_unmount (GVolumeMonitor *volume_monitor, /* add the dummy node */ thunar_tree_model_node_insert_dummy (node, model); } - +#endif static void -thunar_tree_model_volume_added (GVolumeMonitor *volume_monitor, - GVolume *volume, - ThunarTreeModel *model) +thunar_tree_model_device_added (ThunarDeviceMonitor *device_monitor, + ThunarDevice *device, + ThunarTreeModel *model) { - _thunar_return_if_fail (G_IS_VOLUME_MONITOR (volume_monitor)); - _thunar_return_if_fail (model->volume_monitor == volume_monitor); - _thunar_return_if_fail (G_IS_VOLUME (volume)); + ThunarTreeModelItem *item; + 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)); _thunar_return_if_fail (THUNAR_IS_TREE_MODEL (model)); - /* place the volume on the hidden list */ - model->hidden_volumes = g_list_prepend (model->hidden_volumes, g_object_ref (volume)); + /* allocate a new item for the volume */ + item = thunar_tree_model_item_new_with_device (model, device); - /* and let the "volume-changed" handler place the volume where appropriate */ - thunar_tree_model_volume_changed (volume_monitor, volume, model); + /* insert before the last child of the root (the "File System" node) */ + node = g_node_last_child (model->root); + node = g_node_insert_data_before (model->root, node, item); + + /* determine the iterator for the new node */ + GTK_TREE_ITER_INIT (iter, model->stamp, node); + + /* tell the view about the new node */ + path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), &iter); + gtk_tree_model_row_inserted (GTK_TREE_MODEL (model), path, &iter); + gtk_tree_path_free (path); + + /* add the dummy node */ + thunar_tree_model_node_insert_dummy (node, model); } static void -thunar_tree_model_volume_removed (GVolumeMonitor *volume_monitor, - GVolume *volume, - ThunarTreeModel *model) +thunar_tree_model_device_removed (ThunarDeviceMonitor *device_monitor, + ThunarDevice *device, + ThunarTreeModel *model) { GNode *node; - GList *lp; - _thunar_return_if_fail (G_IS_VOLUME_MONITOR (volume_monitor)); - _thunar_return_if_fail (model->volume_monitor == volume_monitor); - _thunar_return_if_fail (G_IS_VOLUME (volume)); + _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)); _thunar_return_if_fail (THUNAR_IS_TREE_MODEL (model)); - /* check if the volume is on the hidden list */ - lp = g_list_find (model->hidden_volumes, volume); - if (G_LIKELY (lp != NULL)) - { - /* remove the volume from the hidden list and drop our reference */ - model->hidden_volumes = g_list_delete_link (model->hidden_volumes, lp); - g_object_unref (volume); - } - else - { - /* must be a visible volume then... */ - for (node = model->root->children; node != NULL; node = node->next) - if (THUNAR_TREE_MODEL_ITEM (node->data)->volume == volume) - break; + /* find the device */ + for (node = model->root->children; node != NULL; node = node->next) + if (THUNAR_TREE_MODEL_ITEM (node->data)->device == device) + break; - /* something is broken if we don't have an item here */ - _thunar_assert (node != NULL); - _thunar_assert (THUNAR_TREE_MODEL_ITEM (node->data)->volume == volume); + /* something is broken if we don't have an item here */ + _thunar_assert (node != NULL); + _thunar_assert (THUNAR_TREE_MODEL_ITEM (node->data)->device == device); - /* drop the node from the model */ - g_node_traverse (node, G_POST_ORDER, G_TRAVERSE_ALL, -1, thunar_tree_model_node_traverse_remove, model); - } + /* drop the node from the model */ + g_node_traverse (node, G_POST_ORDER, G_TRAVERSE_ALL, -1, thunar_tree_model_node_traverse_remove, model); } @@ -1198,31 +1140,25 @@ thunar_tree_model_item_new_with_file (ThunarTreeModel *model, static ThunarTreeModelItem* -thunar_tree_model_item_new_with_volume (ThunarTreeModel *model, - GVolume *volume) +thunar_tree_model_item_new_with_device (ThunarTreeModel *model, + ThunarDevice *device) { ThunarTreeModelItem *item; - GMount *mount; GFile *mount_point; item = g_slice_new0 (ThunarTreeModelItem); - item->volume = g_object_ref (G_OBJECT (volume)); + item->device = g_object_ref (G_OBJECT (device)); item->model = model; /* check if the volume is mounted */ - if (thunar_g_volume_is_mounted (volume)) + if (thunar_device_is_mounted (device)) { - mount = g_volume_get_mount (volume); - - if (G_LIKELY (mount != NULL)) + mount_point = thunar_device_get_root (device); + if (G_LIKELY (mount_point != NULL)) { - mount_point = g_mount_get_root (mount); - /* try to determine the file for the mount point */ item->file = thunar_file_get (mount_point, NULL); - g_object_unref (mount_point); - g_object_unref (mount); } } @@ -1235,8 +1171,8 @@ static void thunar_tree_model_item_free (ThunarTreeModelItem *item) { /* disconnect from the volume */ - if (G_UNLIKELY (item->volume != NULL)) - g_object_unref (item->volume); + if (G_UNLIKELY (item->device != NULL)) + g_object_unref (item->device); /* reset the remaining resources */ thunar_tree_model_item_reset (item); @@ -1287,10 +1223,10 @@ thunar_tree_model_item_reset (ThunarTreeModelItem *item) static void thunar_tree_model_item_load_folder (ThunarTreeModelItem *item) { - _thunar_return_if_fail (item->file != NULL || item->volume != NULL); + _thunar_return_if_fail (item->file != NULL || item->device != NULL); /* schedule the "load" idle source (if not already done) */ - if (G_LIKELY (item->load_idle_id == 0 && item->folder == NULL)) + if (G_LIKELY (item->load_idle_id == 0 && item->device == NULL)) { item->load_idle_id = g_idle_add_full (G_PRIORITY_HIGH, thunar_tree_model_item_load_idle, item, thunar_tree_model_item_load_idle_destroy); @@ -1482,7 +1418,6 @@ static gboolean thunar_tree_model_item_load_idle (gpointer user_data) { ThunarTreeModelItem *item = user_data; - GMount *mount; GFile *mount_point; GList *files; #ifndef NDEBUG @@ -1504,19 +1439,14 @@ thunar_tree_model_item_load_idle (gpointer user_data) GDK_THREADS_ENTER (); /* check if we don't have a file yet and this is a mounted volume */ - if (item->file == NULL && item->volume != NULL && thunar_g_volume_is_mounted (item->volume)) + if (item->file == NULL && item->device != NULL && thunar_device_is_mounted (item->device)) { - mount = g_volume_get_mount (item->volume); - - if (G_LIKELY (mount != NULL)) + mount_point = thunar_device_get_root (item->device); + if (G_LIKELY (mount_point != NULL)) { - mount_point = g_mount_get_root (mount); - /* try to determine the file for the mount point */ item->file = thunar_file_get (mount_point, NULL); - g_object_unref (mount_point); - g_object_unref (mount); } } |