Updating branch refs/heads/nick/new-shortcuts-pane-model to 083417bba6399a44bbb5b5bcabaa3b9721fe2fbe (commit) from a0f743d61115cf90a48d6273f9b569e2b7dad63f (commit)
commit 083417bba6399a44bbb5b5bcabaa3b9721fe2fbe Author: Nick Schermer <n...@xfce.org> Date: Sun Oct 7 00:14:12 2012 +0200 Port the shortcuts pane to ThunarDevice. thunar/thunar-gio-extensions.c | 37 --- thunar/thunar-gio-extensions.h | 2 - thunar/thunar-shortcuts-icon-renderer.c | 39 ++-- thunar/thunar-shortcuts-model.c | 452 ++++++++----------------------- thunar/thunar-shortcuts-model.h | 5 +- thunar/thunar-shortcuts-view.c | 390 ++++++--------------------- 6 files changed, 217 insertions(+), 708 deletions(-) diff --git a/thunar/thunar-gio-extensions.c b/thunar/thunar-gio-extensions.c index 288d936..ae52cda 100644 --- a/thunar/thunar-gio-extensions.c +++ b/thunar/thunar-gio-extensions.c @@ -578,43 +578,6 @@ thunar_g_volume_is_present (GVolume *volume) -/** - * thunar_g_volume_can_eject: - * - * If we should show the eject arrow/menu item - * in the interface. - * - * Check if the mount can eject/unmount or else look at - * the capability of the drive. - **/ -gboolean -thunar_g_volume_can_eject (GVolume *volume) -{ - GMount *mount; - GDrive *drive; - gboolean can_eject; - - mount = g_volume_get_mount (volume); - if (mount != NULL) - { - can_eject = g_mount_can_eject (mount) || g_mount_can_unmount (mount); - g_object_unref (mount); - return can_eject; - } - - drive = g_volume_get_drive (volume); - if (drive != NULL) - { - can_eject = g_drive_can_eject (drive); - g_object_unref (drive); - return can_eject; - } - - return FALSE; -} - - - gboolean thunar_g_app_info_launch (GAppInfo *info, GFile *working_directory, diff --git a/thunar/thunar-gio-extensions.h b/thunar/thunar-gio-extensions.h index c7fde60..7afb1dd 100644 --- a/thunar/thunar-gio-extensions.h +++ b/thunar/thunar-gio-extensions.h @@ -72,8 +72,6 @@ void thunar_g_file_list_free (GList *list); gboolean thunar_g_volume_is_removable (GVolume *volume); gboolean thunar_g_volume_is_mounted (GVolume *volume); gboolean thunar_g_volume_is_present (GVolume *volume); -gboolean -thunar_g_volume_can_eject (GVolume *volume); gboolean thunar_g_app_info_launch (GAppInfo *info, GFile *working_directory, diff --git a/thunar/thunar-shortcuts-icon-renderer.c b/thunar/thunar-shortcuts-icon-renderer.c index a31f553..3797140 100644 --- a/thunar/thunar-shortcuts-icon-renderer.c +++ b/thunar/thunar-shortcuts-icon-renderer.c @@ -28,6 +28,7 @@ #include <thunar/thunar-gobject-extensions.h> #include <thunar/thunar-icon-factory.h> #include <thunar/thunar-shortcuts-icon-renderer.h> +#include <thunar/thunar-device.h> @@ -36,7 +37,7 @@ enum { PROP_0, PROP_VOLUME, - PROP_MOUNT, + PROP_DEVICE, PROP_GICON, }; @@ -71,7 +72,7 @@ struct _ThunarShortcutsIconRenderer ThunarIconRenderer __parent__; GVolume *volume; - GMount *mount; + ThunarDevice *device; GIcon *gicon; }; @@ -108,15 +109,15 @@ thunar_shortcuts_icon_renderer_class_init (ThunarShortcutsIconRendererClass *kla EXO_PARAM_READWRITE)); /** - * ThunarShortcutsIconRenderer:mount: + * ThunarShortcutsIconRenderer:device: * - * The #GMount for which to render an icon or %NULL to fallback + * The #ThunarDevice for which to render an icon or %NULL to fallback * to the default icon renderering (see #ThunarIconRenderer). **/ g_object_class_install_property (gobject_class, - PROP_MOUNT, - g_param_spec_object ("mount", "mount", "mount", - G_TYPE_MOUNT, + PROP_DEVICE, + g_param_spec_object ("device", "device", "device", + THUNAR_TYPE_DEVICE, EXO_PARAM_READWRITE)); /** @@ -152,8 +153,8 @@ thunar_shortcuts_icon_renderer_finalize (GObject *object) if (G_UNLIKELY (renderer->volume != NULL)) g_object_unref (renderer->volume); - if (G_UNLIKELY (renderer->mount != NULL)) - g_object_unref (renderer->mount); + if (G_UNLIKELY (renderer->device != NULL)) + g_object_unref (renderer->device); if (G_UNLIKELY (renderer->gicon != NULL)) g_object_unref (renderer->gicon); @@ -177,8 +178,8 @@ thunar_shortcuts_icon_renderer_get_property (GObject *object, g_value_set_object (value, renderer->volume); break; - case PROP_MOUNT: - g_value_set_object (value, renderer->mount); + case PROP_DEVICE: + g_value_set_object (value, renderer->device); break; case PROP_GICON: @@ -209,10 +210,10 @@ thunar_shortcuts_icon_renderer_set_property (GObject *object, renderer->volume = g_value_dup_object (value); break; - case PROP_MOUNT: - if (G_UNLIKELY (renderer->mount != NULL)) - g_object_unref (renderer->mount); - renderer->mount = g_value_dup_object (value); + case PROP_DEVICE: + if (G_UNLIKELY (renderer->device != NULL)) + g_object_unref (renderer->device); + renderer->device = g_value_dup_object (value); break; case PROP_GICON: @@ -250,7 +251,7 @@ thunar_shortcuts_icon_renderer_render (GtkCellRenderer *renderer, /* check if we have a volume set */ if (G_UNLIKELY (shortcuts_icon_renderer->volume != NULL || shortcuts_icon_renderer->gicon != NULL - || shortcuts_icon_renderer->mount != NULL)) + || shortcuts_icon_renderer->device != NULL)) { /* load the volume icon */ icon_theme = gtk_icon_theme_get_for_screen (gdk_drawable_get_screen (window)); @@ -261,7 +262,7 @@ thunar_shortcuts_icon_renderer_render (GtkCellRenderer *renderer, else if (shortcuts_icon_renderer->volume != NULL) gicon = g_volume_get_icon (shortcuts_icon_renderer->volume); else - gicon = g_mount_get_icon (shortcuts_icon_renderer->mount); + gicon = thunar_device_get_icon (shortcuts_icon_renderer->device); icon_info = gtk_icon_theme_lookup_by_gicon (icon_theme, gicon, cell_area->width, GTK_ICON_LOOKUP_USE_BUILTIN); @@ -294,8 +295,8 @@ thunar_shortcuts_icon_renderer_render (GtkCellRenderer *renderer, icon_area.height = gdk_pixbuf_get_height (icon); } - if (shortcuts_icon_renderer->volume != NULL - && !thunar_g_volume_is_mounted (shortcuts_icon_renderer->volume)) + if (shortcuts_icon_renderer->device != NULL + && !thunar_device_is_mounted (shortcuts_icon_renderer->device)) { /* 50% translucent for unmounted volumes */ temp = exo_gdk_pixbuf_lucent (icon, 50); diff --git a/thunar/thunar-shortcuts-model.c b/thunar/thunar-shortcuts-model.c index 79bd03d..68f6ce7 100644 --- a/thunar/thunar-shortcuts-model.c +++ b/thunar/thunar-shortcuts-model.c @@ -40,6 +40,7 @@ #include <thunar/thunar-file.h> #include <thunar/thunar-shortcuts-model.h> +#include <thunar/thunar-device-monitor.h> #include <thunar/thunar-private.h> @@ -106,23 +107,14 @@ static void thunar_shortcuts_model_file_changed (ThunarFile ThunarShortcutsModel *model); static void thunar_shortcuts_model_file_destroy (ThunarFile *file, ThunarShortcutsModel *model); -static void thunar_shortcuts_model_volume_added (GVolumeMonitor *volume_monitor, - GVolume *volume, +static void thunar_shortcuts_model_device_added (ThunarDeviceMonitor *device_monitor, + ThunarDevice *device, ThunarShortcutsModel *model); -static void thunar_shortcuts_model_volume_removed (GVolumeMonitor *volume_monitor, - GVolume *volume, +static void thunar_shortcuts_model_device_removed (ThunarDeviceMonitor *device_monitor, + ThunarDevice *device, ThunarShortcutsModel *model); -static void thunar_shortcuts_model_volume_changed (GVolumeMonitor *monitor, - GVolume *volume, - ThunarShortcutsModel *model); -static void thunar_shortcuts_model_mount_added (GVolumeMonitor *volume_monitor, - GMount *mount, - ThunarShortcutsModel *model); -static void thunar_shortcuts_model_mount_removed (GVolumeMonitor *volume_monitor, - GMount *mount, - ThunarShortcutsModel *model); -static void thunar_shortcuts_model_mount_changed (GVolumeMonitor *monitor, - GMount *mount, +static void thunar_shortcuts_model_device_changed (ThunarDeviceMonitor *device_monitor, + ThunarDevice *device, ThunarShortcutsModel *model); static void thunar_shortcut_free (ThunarShortcut *shortcut, @@ -144,17 +136,16 @@ struct _ThunarShortcutsModel * generated by another model. */ #ifndef NDEBUG - gint stamp; + gint stamp; #endif - GList *shortcuts; + GList *shortcuts; - GList *hidden_volumes; - GVolumeMonitor *volume_monitor; - guint volume_monitor_idle_id; + ThunarDeviceMonitor *device_monitor; + guint devices_monitor_idle_id; - GFileMonitor *monitor; - guint load_idle_id; + GFileMonitor *monitor; + guint load_idle_id; }; struct _ThunarShortcut @@ -169,8 +160,7 @@ struct _ThunarShortcut GFile *location; ThunarFile *file; - GVolume *volume; - GMount *mount; + ThunarDevice *device; }; @@ -222,13 +212,12 @@ thunar_shortcuts_model_drag_source_init (GtkTreeDragSourceIface *iface) static gboolean -thunar_shortcuts_model_volumes_load (gpointer data) +thunar_shortcuts_model_devices_load (gpointer data) { ThunarShortcutsModel *model = THUNAR_SHORTCUTS_MODEL (data); - ThunarShortcut *shortcut; - GList *volumes; - GList *lp; - GList *mounts; + ThunarShortcut *shortcut; + GList *devices; + GList *lp; GDK_THREADS_ENTER (); @@ -247,38 +236,26 @@ thunar_shortcuts_model_volumes_load (gpointer data) shortcut->gicon = g_themed_icon_new (GTK_STOCK_HARDDISK); thunar_shortcuts_model_add_shortcut (model, shortcut); - /* connect to the volume monitor */ - model->volume_monitor = g_volume_monitor_get (); + /* connect to the device monitor */ + model->device_monitor = thunar_device_monitor_get (); - /* get a list of all volumes available */ - volumes = g_volume_monitor_get_volumes (model->volume_monitor); - for (lp = volumes; lp != NULL; lp = lp->next) + /* get a list of all devices available */ + devices = thunar_device_monitor_get_devices (model->device_monitor); + for (lp = devices; lp != NULL; lp = lp->next) { - thunar_shortcuts_model_volume_added (model->volume_monitor, lp->data, model); + thunar_shortcuts_model_device_added (model->device_monitor, lp->data, model); g_object_unref (G_OBJECT (lp->data)); } - g_list_free (volumes); - - /* get a list of all mounts available */ - mounts = g_volume_monitor_get_mounts (model->volume_monitor); - for (lp = mounts; lp != NULL; lp = lp->next) - { - thunar_shortcuts_model_mount_added (model->volume_monitor, lp->data, model); - g_object_unref (G_OBJECT (lp->data)); - } - g_list_free (mounts); + g_list_free (devices); GDK_THREADS_LEAVE (); /* monitor for changes */ - g_signal_connect (model->volume_monitor, "volume-added", G_CALLBACK (thunar_shortcuts_model_volume_added), model); - g_signal_connect (model->volume_monitor, "volume-removed", G_CALLBACK (thunar_shortcuts_model_volume_removed), model); - g_signal_connect (model->volume_monitor, "volume-changed", G_CALLBACK (thunar_shortcuts_model_volume_changed), model); - g_signal_connect (model->volume_monitor, "mount-added", G_CALLBACK (thunar_shortcuts_model_mount_added), model); - g_signal_connect (model->volume_monitor, "mount-removed", G_CALLBACK (thunar_shortcuts_model_mount_removed), model); - g_signal_connect (model->volume_monitor, "mount-changed", G_CALLBACK (thunar_shortcuts_model_mount_changed), model); + g_signal_connect (model->device_monitor, "device-added", G_CALLBACK (thunar_shortcuts_model_device_added), model); + g_signal_connect (model->device_monitor, "device-removed", G_CALLBACK (thunar_shortcuts_model_device_removed), model); + g_signal_connect (model->device_monitor, "device-changed", G_CALLBACK (thunar_shortcuts_model_device_changed), model); - model->volume_monitor_idle_id = 0; + model->devices_monitor_idle_id = 0; return FALSE; } @@ -397,7 +374,7 @@ thunar_shortcuts_model_init (ThunarShortcutsModel *model) #endif /* load volumes */ - model->volume_monitor_idle_id = g_idle_add_full (G_PRIORITY_LOW, thunar_shortcuts_model_volumes_load, model, NULL); + model->devices_monitor_idle_id = g_idle_add_full (G_PRIORITY_LOW, thunar_shortcuts_model_devices_load, model, NULL); /* add network */ thunar_shortcuts_model_shortcut_network (model); @@ -419,17 +396,14 @@ thunar_shortcuts_model_finalize (GObject *object) if (model->load_idle_id != 0) g_source_remove (model->load_idle_id); - /* stop volume monitor loading */ - if (model->volume_monitor_idle_id != 0) - g_source_remove (model->volume_monitor_idle_id); + /* stop device monitor loading */ + if (model->devices_monitor_idle_id != 0) + g_source_remove (model->devices_monitor_idle_id); /* free all shortcuts */ g_list_foreach (model->shortcuts, (GFunc) thunar_shortcut_free, model); g_list_free (model->shortcuts); - /* free all hidden volumes */ - g_list_free_full (model->hidden_volumes, g_object_unref); - /* detach from the file monitor */ if (model->monitor != NULL) { @@ -437,9 +411,9 @@ thunar_shortcuts_model_finalize (GObject *object) g_object_unref (model->monitor); } - /* unlink 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); + /* unlink from the device 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_shortcuts_model_parent_class)->finalize) (object); } @@ -484,11 +458,8 @@ thunar_shortcuts_model_get_column_type (GtkTreeModel *tree_model, case THUNAR_SHORTCUTS_MODEL_COLUMN_GICON: return G_TYPE_ICON; - case THUNAR_SHORTCUTS_MODEL_COLUMN_VOLUME: - return G_TYPE_VOLUME; - - case THUNAR_SHORTCUTS_MODEL_COLUMN_MOUNT: - return G_TYPE_MOUNT; + case THUNAR_SHORTCUTS_MODEL_COLUMN_DEVICE: + return THUNAR_TYPE_DEVICE; case THUNAR_SHORTCUTS_MODEL_COLUMN_MUTABLE: return G_TYPE_BOOLEAN; @@ -579,10 +550,8 @@ thunar_shortcuts_model_get_value (GtkTreeModel *tree_model, case THUNAR_SHORTCUTS_MODEL_COLUMN_NAME: g_value_init (value, G_TYPE_STRING); - if (G_UNLIKELY (shortcut->volume != NULL)) - g_value_take_string (value, g_volume_get_name (shortcut->volume)); - else if (shortcut->mount != NULL) - g_value_take_string (value, g_mount_get_name (shortcut->mount)); + if (G_UNLIKELY (shortcut->device != NULL)) + g_value_take_string (value, thunar_device_get_name (shortcut->device)); else if (shortcut->name != NULL) g_value_set_static_string (value, shortcut->name); else if (shortcut->file != NULL) @@ -603,14 +572,9 @@ thunar_shortcuts_model_get_value (GtkTreeModel *tree_model, g_value_set_object (value, shortcut->gicon); break; - case THUNAR_SHORTCUTS_MODEL_COLUMN_VOLUME: - g_value_init (value, G_TYPE_VOLUME); - g_value_set_object (value, shortcut->volume); - break; - - case THUNAR_SHORTCUTS_MODEL_COLUMN_MOUNT: - g_value_init (value, G_TYPE_MOUNT); - g_value_set_object (value, shortcut->mount); + case THUNAR_SHORTCUTS_MODEL_COLUMN_DEVICE: + g_value_init (value, THUNAR_TYPE_DEVICE); + g_value_set_object (value, shortcut->device); break; case THUNAR_SHORTCUTS_MODEL_COLUMN_LOCATION: @@ -627,10 +591,8 @@ thunar_shortcuts_model_get_value (GtkTreeModel *tree_model, break; case THUNAR_SHORTCUTS_MODEL_COLUMN_CAN_EJECT: - if (shortcut->volume != NULL) - can_eject = thunar_g_volume_can_eject (shortcut->volume); - else if (shortcut->mount != NULL) - can_eject = g_mount_can_eject (shortcut->mount) || g_mount_can_unmount (shortcut->mount); + if (shortcut->device != NULL) + can_eject = thunar_device_can_eject (shortcut->device); else can_eject = FALSE; @@ -800,15 +762,10 @@ thunar_shortcuts_model_sort_func (gconstpointer shortcut_a, if (a->sort_id != b->sort_id) return a->sort_id > b->sort_id ? 1 : -1; - /* properly sort volumes by timestamp */ - if (a->volume != NULL && b->volume != NULL) - return -g_strcmp0 (g_volume_get_sort_key (a->volume), - g_volume_get_sort_key (b->volume)); - - /* properly sort mounts by timestamp */ - if (a->mount != NULL && b->mount != NULL) - return -g_strcmp0 (g_mount_get_sort_key (a->mount), - g_mount_get_sort_key (b->mount)); + /* properly sort devices by timestamp */ + if (a->device != NULL && b->device != NULL) + return -g_strcmp0 (thunar_device_get_sort_key (a->device), + thunar_device_get_sort_key (b->device)); return g_strcmp0 (a->name, b->name); } @@ -1213,284 +1170,104 @@ thunar_shortcuts_model_file_destroy (ThunarFile *file, static void -thunar_shortcuts_model_volume_changed (GVolumeMonitor *volume_monitor, - GVolume *volume, - ThunarShortcutsModel *model) +thunar_shortcuts_model_device_added (ThunarDeviceMonitor *device_monitor, + ThunarDevice *device, + ThunarShortcutsModel *model) { - ThunarShortcut *shortcut = NULL; - GtkTreeIter iter; - GList *lp; - gint idx; - GtkTreePath *path; + ThunarShortcut *shortcut; - _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_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_SHORTCUTS_MODEL (model)); - /* check if the volume is on the hidden list */ - lp = g_list_find (model->hidden_volumes, volume); - if (lp != NULL) - { - /* check if we need to display the volume now */ - if (thunar_g_volume_is_removable (volume)) - { - /* remove the volume from the list of hidden volumes */ - model->hidden_volumes = g_list_delete_link (model->hidden_volumes, lp); - - /* allocate a new shortcut */ - shortcut = g_slice_new0 (ThunarShortcut); - shortcut->group = THUNAR_SHORTCUT_GROUP_VOLUMES; - shortcut->volume = volume; + /* allocate a new shortcut */ + shortcut = g_slice_new0 (ThunarShortcut); + shortcut->device = g_object_ref (device); - /* the volume is present now, so we have to display it */ - thunar_shortcuts_model_add_shortcut (model, shortcut); - } - } - else + switch (thunar_device_get_kind (device)) { - /* lookup the shortcut that contains the given volume */ - for (idx = 0, lp = model->shortcuts; - shortcut == NULL && lp != NULL; - ++idx, lp = lp->next) - { - if (THUNAR_SHORTCUT (lp->data)->volume == volume) - shortcut = lp->data; - } - - /* verify that we actually found the shortcut */ - _thunar_assert (shortcut != NULL); - _thunar_assert (shortcut->volume == volume); - - /* check if we need to hide the volume now */ - if (!thunar_g_volume_is_removable (volume)) - { - /* move the volume to the hidden list */ - model->hidden_volumes = g_list_prepend (model->hidden_volumes, - g_object_ref (volume)); + case THUNAR_DEVICE_KIND_VOLUME: + shortcut->group = THUNAR_SHORTCUT_GROUP_VOLUMES; + break; - /* remove the shortcut from the user interface */ - thunar_shortcuts_model_remove_shortcut (model, shortcut); - } - else - { - /* generate an iterator for the path */ - GTK_TREE_ITER_INIT (iter, model->stamp, lp); + case THUNAR_DEVICE_KIND_MOUNT_LOCAL: + shortcut->group = THUNAR_SHORTCUT_GROUP_MOUNTS; + break; - /* tell the view that the volume has changed in some way */ - path = gtk_tree_path_new_from_indices (idx, -1); - gtk_tree_model_row_changed (GTK_TREE_MODEL (model), path, &iter); - gtk_tree_path_free (path); - } + case THUNAR_DEVICE_KIND_MOUNT_REMOTE: + shortcut->group = THUNAR_SHORTCUT_GROUP_NETWORK_MOUNTS; + break; } -} - - - -static void -thunar_shortcuts_model_volume_added (GVolumeMonitor *volume_monitor, - GVolume *volume, - ThunarShortcutsModel *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)); - _thunar_return_if_fail (THUNAR_IS_SHORTCUTS_MODEL (model)); - - /* place the volume on the hidden list */ - model->hidden_volumes = g_list_prepend (model->hidden_volumes, g_object_ref (volume)); - /* let the "changed" handler place the volume where appropriate */ - thunar_shortcuts_model_volume_changed (volume_monitor, volume, model); + /* insert in the model */ + thunar_shortcuts_model_add_shortcut (model, shortcut); } static void -thunar_shortcuts_model_volume_removed (GVolumeMonitor *volume_monitor, - GVolume *volume, +thunar_shortcuts_model_device_removed (ThunarDeviceMonitor *device_monitor, + ThunarDevice *device, ThunarShortcutsModel *model) { 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_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_SHORTCUTS_MODEL (model)); - 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 an active shortcut then... */ - for (lp = model->shortcuts; lp != NULL; lp = lp->next) - if (THUNAR_SHORTCUT (lp->data)->volume == volume) - break; - - /* something is broken if we don't have a shortcut here */ - _thunar_assert (lp != NULL); - _thunar_assert (THUNAR_SHORTCUT (lp->data)->volume == volume); - - /* drop the shortcut from the model */ - thunar_shortcuts_model_remove_shortcut (model, lp->data); - } -} - - - -static gboolean -thunar_shortcuts_model_has_location (ThunarShortcutsModel *model, - GFile *location) -{ - GList *lp; - ThunarShortcut *shortcut; - - _thunar_return_val_if_fail (THUNAR_IS_SHORTCUTS_MODEL (model), FALSE); - _thunar_return_val_if_fail (G_IS_FILE (location), FALSE); - + /* find the shortcut */ for (lp = model->shortcuts; lp != NULL; lp = lp->next) - { - shortcut = lp->data; - - /* check if we have a location that matches */ - if (shortcut->location != NULL - && g_file_equal (shortcut->location, location)) - return TRUE; + if (THUNAR_SHORTCUT (lp->data)->device == device) + break; - /* check if we have a file that matches */ - if (shortcut->file != NULL - && g_file_equal (thunar_file_get_file (shortcut->file), location)) - return TRUE; - } + /* something is broken if we don't have a shortcut here */ + _thunar_assert (lp != NULL); + _thunar_assert (THUNAR_SHORTCUT (lp->data)->device == device); - return FALSE; + /* drop the shortcut from the model */ + if (G_LIKELY (lp != NULL)) + thunar_shortcuts_model_remove_shortcut (model, lp->data); } static void -thunar_shortcuts_model_mount_changed (GVolumeMonitor *volume_monitor, - GMount *mount, - ThunarShortcutsModel *model) +thunar_shortcuts_model_device_changed (ThunarDeviceMonitor *device_monitor, + ThunarDevice *device, + ThunarShortcutsModel *model) { - GList *lp; - guint idx; GtkTreeIter iter; + GList *lp; + gint idx; GtkTreePath *path; - _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_MOUNT (mount)); + _thunar_return_if_fail (THUNAR_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_SHORTCUTS_MODEL (model)); - /* find mount */ + /* find the shortcut */ for (lp = model->shortcuts, idx = 0; lp != NULL; lp = lp->next, idx++) - if (THUNAR_SHORTCUT (lp->data)->mount == mount) + if (THUNAR_SHORTCUT (lp->data)->device == device) break; - if (lp == NULL) - return; - /* something is broken if we don't have a shortcut here */ - _thunar_assert (THUNAR_SHORTCUT (lp->data)->mount == mount); - - /* generate an iterator for the path */ - GTK_TREE_ITER_INIT (iter, model->stamp, lp); - - /* tell the view that the volume has changed in some way */ - path = gtk_tree_path_new_from_indices (idx, -1); - gtk_tree_model_row_changed (GTK_TREE_MODEL (model), path, &iter); - gtk_tree_path_free (path); -} - - - -static void -thunar_shortcuts_model_mount_added (GVolumeMonitor *volume_monitor, - GMount *mount, - ThunarShortcutsModel *model) -{ - GVolume *volume; - GFile *location; - ThunarShortcutGroup group; - ThunarShortcut *shortcut; - - _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_MOUNT (mount)); - _thunar_return_if_fail (THUNAR_IS_SHORTCUTS_MODEL (model)); - - /* never show shadowed mounts */ - if (g_mount_is_shadowed (mount)) - return; + _thunar_assert (lp != NULL); + _thunar_assert (THUNAR_SHORTCUT (lp->data)->device == device); - /* skip mounts with a volume */ - volume = g_mount_get_volume (mount); - if (volume != NULL) + if (G_LIKELY (lp != NULL)) { - g_object_unref (volume); - return; - } - - location = g_mount_get_root (mount); + /* generate an iterator for the path */ + GTK_TREE_ITER_INIT (iter, model->stamp, lp); - /* skip ghoto locations, since those also have a mount - * and igore locations already in the model */ - if (g_file_has_uri_scheme (location, "gphoto2") - || thunar_shortcuts_model_has_location (model, location)) - { - g_object_unref (location); - return; + /* tell the view that the volume has changed in some way */ + path = gtk_tree_path_new_from_indices (idx, -1); + gtk_tree_model_row_changed (GTK_TREE_MODEL (model), path, &iter); + gtk_tree_path_free (path); } - - if (g_file_has_uri_scheme (location, "file") - || g_file_has_uri_scheme (location, "archive")) - group = THUNAR_SHORTCUT_GROUP_MOUNTS; - else - group = THUNAR_SHORTCUT_GROUP_NETWORK_MOUNTS; - - /* allocate a new shortcut */ - shortcut = g_slice_new0 (ThunarShortcut); - shortcut->group = group; - shortcut->location = location; - shortcut->mount = g_object_ref (mount); - - /* the mount is present now, so we have to display it */ - thunar_shortcuts_model_add_shortcut (model, shortcut); -} - - - -static void -thunar_shortcuts_model_mount_removed (GVolumeMonitor *volume_monitor, - GMount *mount, - ThunarShortcutsModel *model) -{ - 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_MOUNT (mount)); - _thunar_return_if_fail (THUNAR_IS_SHORTCUTS_MODEL (model)); - - /* find mount */ - for (lp = model->shortcuts; lp != NULL; lp = lp->next) - if (THUNAR_SHORTCUT (lp->data)->mount == mount) - break; - - if (lp == NULL) - return; - - /* something is broken if we don't have a shortcut here */ - _thunar_assert (THUNAR_SHORTCUT (lp->data)->mount == mount); - - /* drop the shortcut from the model */ - thunar_shortcuts_model_remove_shortcut (model, lp->data); } @@ -1511,11 +1288,8 @@ thunar_shortcut_free (ThunarShortcut *shortcut, g_object_unref (shortcut->file); } - if (G_LIKELY (shortcut->volume != NULL)) - g_object_unref (shortcut->volume); - - if (G_LIKELY (shortcut->mount != NULL)) - g_object_unref (shortcut->mount); + if (G_LIKELY (shortcut->device != NULL)) + g_object_unref (shortcut->device); if (G_LIKELY (shortcut->gicon != NULL)) g_object_unref (shortcut->gicon); @@ -1581,7 +1355,6 @@ thunar_shortcuts_model_iter_for_file (ThunarShortcutsModel *model, ThunarFile *file, GtkTreeIter *iter) { - GMount *mount; GFile *mount_point; GList *lp; ThunarShortcut *shortcut; @@ -1602,24 +1375,19 @@ thunar_shortcuts_model_iter_for_file (ThunarShortcutsModel *model, } /* but maybe we have a mounted(!) volume with a matching mount point */ - if (shortcut->volume != NULL) + if (shortcut->device != NULL) { - mount = g_volume_get_mount (shortcut->volume); - - if (G_LIKELY (mount != NULL)) + mount_point = thunar_device_get_root (shortcut->device); + if (mount_point != NULL) { - mount_point = g_mount_get_root (mount); - - if (G_LIKELY (g_file_equal (mount_point, thunar_file_get_file (file)))) + if (g_file_equal (mount_point, thunar_file_get_file (file))) { GTK_TREE_ITER_INIT (*iter, model->stamp, lp); g_object_unref (mount_point); - g_object_unref (mount); return TRUE; } g_object_unref (mount_point); - g_object_unref (mount); } } } diff --git a/thunar/thunar-shortcuts-model.h b/thunar/thunar-shortcuts-model.h index ce5def4..b5d94f6 100644 --- a/thunar/thunar-shortcuts-model.h +++ b/thunar/thunar-shortcuts-model.h @@ -41,7 +41,7 @@ typedef struct _ThunarShortcutsModel ThunarShortcutsModel; * @THUNAR_SHORTCUTS_MODEL_COLUMN_FILE : the index of the file column. * @THUNAR_SHORTCUTS_MODEL_COLUMN_LOCATION : file of the location. * @THUNAR_SHORTCUTS_MODEL_COLUMN_GICON : custom image. - * @THUNAR_SHORTCUTS_MODEL_COLUMN_VOLUME : the index of the volume column. + * @THUNAR_SHORTCUTS_MODEL_COLUMN_DEVICE : the index of the device column. * @THUNAR_SHORTCUTS_MODEL_COLUMN_MUTABLE : tells whether a row is mutable. * @THUNAR_SHORTCUTS_MODEL_COLUMN_EJECT : stock icon name for eject symbol * @THUNAR_SHORTCUTS_MODEL_COLUMN_SEPARATOR : tells whether a row is a separator. @@ -57,8 +57,7 @@ typedef enum THUNAR_SHORTCUTS_MODEL_COLUMN_FILE, THUNAR_SHORTCUTS_MODEL_COLUMN_LOCATION, THUNAR_SHORTCUTS_MODEL_COLUMN_GICON, - THUNAR_SHORTCUTS_MODEL_COLUMN_VOLUME, - THUNAR_SHORTCUTS_MODEL_COLUMN_MOUNT, + THUNAR_SHORTCUTS_MODEL_COLUMN_DEVICE, THUNAR_SHORTCUTS_MODEL_COLUMN_MUTABLE, THUNAR_SHORTCUTS_MODEL_COLUMN_CAN_EJECT, THUNAR_SHORTCUTS_MODEL_COLUMN_GROUP, diff --git a/thunar/thunar-shortcuts-view.c b/thunar/thunar-shortcuts-view.c index 720fb44..19d095b 100644 --- a/thunar/thunar-shortcuts-view.c +++ b/thunar/thunar-shortcuts-view.c @@ -32,9 +32,6 @@ #include <gdk/gdkkeysyms.h> -#ifdef HAVE_LIBNOTIFY -#include <thunar/thunar-notify.h> -#endif #include <thunar/thunar-application.h> #include <thunar/thunar-browser.h> #include <thunar/thunar-dialogs.h> @@ -46,6 +43,7 @@ #include <thunar/thunar-shortcuts-icon-renderer.h> #include <thunar/thunar-shortcuts-model.h> #include <thunar/thunar-shortcuts-view.h> +#include <thunar/thunar-device-monitor.h> @@ -128,7 +126,7 @@ static void thunar_shortcuts_view_open (Thunar gboolean new_window); static void thunar_shortcuts_view_open_in_new_window_clicked (ThunarShortcutsView *view); static void thunar_shortcuts_view_empty_trash (ThunarShortcutsView *view); -static void thunar_shortcuts_view_disconnect (ThunarShortcutsView *view); +static void thunar_shortcuts_view_eject (ThunarShortcutsView *view); static void thunar_shortcuts_view_mount (ThunarShortcutsView *view); static void thunar_shortcuts_view_unmount (ThunarShortcutsView *view); @@ -305,8 +303,7 @@ thunar_shortcuts_view_init (ThunarShortcutsView *view) gtk_tree_view_column_set_attributes (column, view->icon_renderer, "gicon", THUNAR_SHORTCUTS_MODEL_COLUMN_GICON, "file", THUNAR_SHORTCUTS_MODEL_COLUMN_FILE, - "volume", THUNAR_SHORTCUTS_MODEL_COLUMN_VOLUME, - "mount", THUNAR_SHORTCUTS_MODEL_COLUMN_MOUNT, + "device", THUNAR_SHORTCUTS_MODEL_COLUMN_DEVICE, "visible", THUNAR_SHORTCUTS_MODEL_COLUMN_NOT_HEADER, NULL); @@ -466,7 +463,7 @@ thunar_shortcuts_view_button_release_event (GtkWidget *widget, if (G_LIKELY (view->pressed_button == (gint) event->button)) { if (view->pressed_eject_button) - thunar_shortcuts_view_disconnect (view); + thunar_shortcuts_view_eject (view); /* check if we should simply open or open in new window */ if (G_LIKELY (event->button == 1)) @@ -876,9 +873,7 @@ thunar_shortcuts_view_context_menu (ThunarShortcutsView *view, GtkWidget *item; GtkWidget *window; gboolean mutable; - GVolume *volume; - GMount *mount; - GMount *volume_mount; + ThunarDevice *device; GList *providers, *lp; GList *actions = NULL, *tmp; ThunarShortcutGroup group; @@ -891,8 +886,7 @@ thunar_shortcuts_view_context_menu (ThunarShortcutsView *view, /* check whether the shortcut at the given path is mutable */ gtk_tree_model_get (model, iter, THUNAR_SHORTCUTS_MODEL_COLUMN_FILE, &file, - THUNAR_SHORTCUTS_MODEL_COLUMN_VOLUME, &volume, - THUNAR_SHORTCUTS_MODEL_COLUMN_MOUNT, &mount, + THUNAR_SHORTCUTS_MODEL_COLUMN_DEVICE, &device, THUNAR_SHORTCUTS_MODEL_COLUMN_MUTABLE, &mutable, THUNAR_SHORTCUTS_MODEL_COLUMN_GROUP, &group, -1); @@ -916,7 +910,6 @@ thunar_shortcuts_view_context_menu (ThunarShortcutsView *view, gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); gtk_widget_show (item); - /* check if we have a volume here */ switch (group) { case THUNAR_SHORTCUT_GROUP_VOLUMES: @@ -925,28 +918,23 @@ thunar_shortcuts_view_context_menu (ThunarShortcutsView *view, gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); gtk_widget_show (item); - volume_mount = g_volume_get_mount (volume); - /* append the "Mount" item */ item = gtk_image_menu_item_new_with_mnemonic (_("_Mount")); - gtk_widget_set_visible (item, volume_mount == NULL && g_volume_can_mount (volume)); + gtk_widget_set_visible (item, thunar_device_can_mount (device)); g_signal_connect_swapped (G_OBJECT (item), "activate", G_CALLBACK (thunar_shortcuts_view_mount), view); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); /* append the "Unmount" item */ item = gtk_image_menu_item_new_with_mnemonic (_("_Unmount")); - gtk_widget_set_visible (item, volume_mount != NULL && g_mount_can_unmount (volume_mount)); + gtk_widget_set_visible (item, thunar_device_can_unmount (device)); g_signal_connect_swapped (G_OBJECT (item), "activate", G_CALLBACK (thunar_shortcuts_view_unmount), view); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); /* append the "Disconnect" (eject + safely remove drive) item */ item = gtk_image_menu_item_new_with_mnemonic (_("_Eject")); - gtk_widget_set_visible (item, thunar_g_volume_can_eject (volume)); + gtk_widget_set_visible (item, thunar_device_can_eject (device)); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); - g_signal_connect_swapped (G_OBJECT (item), "activate", G_CALLBACK (thunar_shortcuts_view_disconnect), view); - - if (volume_mount != NULL) - g_object_unref (volume_mount); + g_signal_connect_swapped (G_OBJECT (item), "activate", G_CALLBACK (thunar_shortcuts_view_eject), view); break; case THUNAR_SHORTCUT_GROUP_MOUNTS: @@ -958,12 +946,12 @@ thunar_shortcuts_view_context_menu (ThunarShortcutsView *view, /* append the "Disconnect" item */ item = gtk_image_menu_item_new_with_mnemonic (_("Disconn_ect")); - g_signal_connect_swapped (G_OBJECT (item), "activate", G_CALLBACK (thunar_shortcuts_view_disconnect), view); + gtk_widget_set_sensitive (item, thunar_device_can_eject (device)); + g_signal_connect_swapped (G_OBJECT (item), "activate", G_CALLBACK (thunar_shortcuts_view_eject), view); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); gtk_widget_show (item); break; - case THUNAR_SHORTCUT_GROUP_TRASH: /* append a menu separator */ item = gtk_separator_menu_item_new (); @@ -1065,10 +1053,8 @@ thunar_shortcuts_view_context_menu (ThunarShortcutsView *view, /* clean up */ if (G_LIKELY (file != NULL)) g_object_unref (G_OBJECT (file)); - if (G_UNLIKELY (volume != NULL)) - g_object_unref (G_OBJECT (volume)); - if (G_UNLIKELY (mount != NULL)) - g_object_unref (G_OBJECT (mount)); + if (G_UNLIKELY (device != NULL)) + g_object_unref (G_OBJECT (device)); gtk_tree_path_free (path); } @@ -1459,7 +1445,7 @@ thunar_shortcuts_view_open (ThunarShortcutsView *view, GtkTreeModel *model; GtkTreeIter iter; ThunarFile *file; - GVolume *volume; + ThunarDevice *device; GFile *location; _thunar_return_if_fail (THUNAR_IS_SHORTCUTS_VIEW (view)); @@ -1476,13 +1462,13 @@ thunar_shortcuts_view_open (ThunarShortcutsView *view, /* determine the file for the shortcut at the given tree iterator */ gtk_tree_model_get (model, &iter, THUNAR_SHORTCUTS_MODEL_COLUMN_FILE, &file, - THUNAR_SHORTCUTS_MODEL_COLUMN_VOLUME, &volume, + THUNAR_SHORTCUTS_MODEL_COLUMN_DEVICE, &device, THUNAR_SHORTCUTS_MODEL_COLUMN_LOCATION, &location, -1); - if (G_LIKELY (volume != NULL)) - { - thunar_browser_poke_volume (THUNAR_BROWSER (view), volume, view, + if (G_LIKELY (FALSE && device != NULL)) + {/* TODO */ + thunar_browser_poke_volume (THUNAR_BROWSER (view), (GVolume *)device, view, thunar_shortcuts_view_poke_volume_finish, GUINT_TO_POINTER (new_window)); } @@ -1502,8 +1488,8 @@ thunar_shortcuts_view_open (ThunarShortcutsView *view, if (file != NULL) g_object_unref (file); - if (volume != NULL) - g_object_unref (volume); + if (device != NULL) + g_object_unref (device); if (location != NULL) g_object_unref (location); @@ -1537,137 +1523,37 @@ thunar_shortcuts_view_empty_trash (ThunarShortcutsView *view) static void -thunar_shortcuts_view_eject_volume_finish (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - ThunarShortcutsView *view = THUNAR_SHORTCUTS_VIEW (user_data); - GtkWidget *window; - GVolume *volume = G_VOLUME (object); - GError *error = NULL; - gchar *volume_name; - - _thunar_return_if_fail (G_IS_VOLUME (object)); - _thunar_return_if_fail (G_IS_ASYNC_RESULT (result)); - _thunar_return_if_fail (THUNAR_IS_SHORTCUTS_VIEW (view)); - - /* check if there was an error */ - if (!g_volume_eject_with_operation_finish (volume, result, &error)) - { - /* ignore GIO errors already handled */ - if (error->domain != G_IO_ERROR || error->code != G_IO_ERROR_FAILED_HANDLED) - { - window = gtk_widget_get_toplevel (GTK_WIDGET (view)); - - /* display an error dialog to inform the user */ - volume_name = g_volume_get_name (volume); - thunar_dialogs_show_error (window, error, _("Failed to eject \"%s\""), volume_name); - g_free (volume_name); - - g_error_free (error); - } - } - -#ifdef HAVE_LIBNOTIFY - thunar_notify_eject_finish (volume); -#endif - - g_object_unref (view); -} - - - -static void -thunar_shortcuts_view_eject_mount_finish (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - ThunarShortcutsView *view = THUNAR_SHORTCUTS_VIEW (user_data); - GtkWidget *window; - GMount *mount = G_MOUNT (object); - GError *error = NULL; - gchar *mount_name; - - _thunar_return_if_fail (G_IS_MOUNT (object)); - _thunar_return_if_fail (G_IS_ASYNC_RESULT (result)); - _thunar_return_if_fail (THUNAR_IS_SHORTCUTS_VIEW (view)); - - /* check if there was an error */ - if (!g_mount_eject_with_operation_finish (mount, result, &error)) - { - /* ignore GIO errors already handled */ - if (error->domain != G_IO_ERROR || error->code != G_IO_ERROR_FAILED_HANDLED) - { - window = gtk_widget_get_toplevel (GTK_WIDGET (view)); - - /* display an error dialog to inform the user */ - mount_name = g_mount_get_name (mount); - thunar_dialogs_show_error (window, error, _("Failed to eject \"%s\""), mount_name); - g_free (mount_name); - - g_error_free (error); - } - } - -#ifdef HAVE_LIBNOTIFY - thunar_notify_unmount_finish (mount); -#endif - - g_object_unref (view); -} - - - -static void -thunar_shortcuts_view_unmount_finish (GObject *object, - GAsyncResult *result, - gpointer user_data) +thunar_shortcuts_view_eject_finish (ThunarDevice *device, + const GError *error, + gpointer user_data) { ThunarShortcutsView *view = THUNAR_SHORTCUTS_VIEW (user_data); - GtkWidget *window; - GMount *mount = G_MOUNT (object); - GError *error = NULL; - gchar *mount_name; + gchar *device_name; - _thunar_return_if_fail (G_IS_MOUNT (object)); - _thunar_return_if_fail (G_IS_ASYNC_RESULT (result)); + _thunar_return_if_fail (THUNAR_IS_DEVICE (device)); _thunar_return_if_fail (THUNAR_IS_SHORTCUTS_VIEW (view)); /* check if there was an error */ - if (!g_mount_unmount_with_operation_finish (mount, result, &error)) + if (error != NULL) { - /* ignore GIO errors already handled */ - if (error->domain != G_IO_ERROR || error->code != G_IO_ERROR_FAILED_HANDLED) - { - window = gtk_widget_get_toplevel (GTK_WIDGET (view)); - - /* display an error dialog to inform the user */ - mount_name = g_mount_get_name (mount); - thunar_dialogs_show_error (window, error, _("Failed to eject \"%s\""), mount_name); - g_free (mount_name); - - g_error_free (error); - } + /* display an error dialog to inform the user */ + device_name = thunar_device_get_name (device); + thunar_dialogs_show_error (GTK_WIDGET (view), error, _("Failed to eject \"%s\""), device_name); + g_free (device_name); } -#ifdef HAVE_LIBNOTIFY - thunar_notify_unmount_finish (mount); -#endif - g_object_unref (view); } static void -thunar_shortcuts_view_disconnect (ThunarShortcutsView *view) +thunar_shortcuts_view_eject (ThunarShortcutsView *view) { GtkTreeSelection *selection; GtkTreeModel *model; GtkTreeIter iter; - GVolume *volume; - GMount *mount; - GMount *volume_mount; + ThunarDevice *device; GMountOperation *mount_operation; GtkWidget *window; @@ -1675,109 +1561,24 @@ thunar_shortcuts_view_disconnect (ThunarShortcutsView *view) /* determine the selected item */ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view)); - if (!gtk_tree_selection_get_selected (selection, &model, &iter)) - return; - - /* determine the volume/mount for the shortcut at the given tree iterator */ - gtk_tree_model_get (model, &iter, - THUNAR_SHORTCUTS_MODEL_COLUMN_VOLUME, &volume, - THUNAR_SHORTCUTS_MODEL_COLUMN_MOUNT, &mount, -1); - - _thunar_return_if_fail (volume == NULL || G_IS_VOLUME (volume)); - _thunar_return_if_fail (mount == NULL || G_IS_MOUNT (mount)); - - /* prepare a mount operation */ - window = gtk_widget_get_toplevel (GTK_WIDGET (view)); - mount_operation = gtk_mount_operation_new (GTK_WINDOW (window)); - - if (mount != NULL) - { - /* distinguish between ejectable and unmountable mounts */ - if (g_mount_can_eject (mount)) - { -#ifdef HAVE_LIBNOTIFY - thunar_notify_unmount (mount); -#endif - - /* try ejecting the mount */ - g_mount_eject_with_operation (mount, - G_MOUNT_UNMOUNT_NONE, - mount_operation, - NULL, - thunar_shortcuts_view_eject_mount_finish, - g_object_ref (view)); - } - else if (g_mount_can_unmount (mount)) - { -#ifdef HAVE_LIBNOTIFY - thunar_notify_unmount (mount); -#endif - - /* try unmounting the mount */ - g_mount_unmount_with_operation (mount, - G_MOUNT_UNMOUNT_NONE, - mount_operation, - NULL, - thunar_shortcuts_view_unmount_finish, - g_object_ref (view)); - } - - g_object_unref (mount); - } - else if (volume != NULL) + if (gtk_tree_selection_get_selected (selection, &model, &iter)) { - if (g_volume_can_eject (volume)) - { -#ifdef HAVE_LIBNOTIFY - thunar_notify_eject (volume); -#endif - /* try ejecting the volume */ - g_volume_eject_with_operation (volume, - G_MOUNT_UNMOUNT_NONE, - mount_operation, - NULL, - thunar_shortcuts_view_eject_volume_finish, - g_object_ref (view)); - } - else - { - volume_mount = g_volume_get_mount (volume); - if (volume_mount != NULL) - { - /* distinguish between ejectable and unmountable mounts */ - if (g_mount_can_eject (volume_mount)) - { -#ifdef HAVE_LIBNOTIFY - thunar_notify_unmount (volume_mount); -#endif - - g_mount_eject_with_operation (mount, - G_MOUNT_UNMOUNT_NONE, - mount_operation, - NULL, - thunar_shortcuts_view_eject_mount_finish, - g_object_ref (view)); - } - else if (g_mount_can_unmount (volume_mount)) - { -#ifdef HAVE_LIBNOTIFY - thunar_notify_unmount (volume_mount); -#endif + /* determine the volume/mount for the shortcut at the given tree iterator */ + gtk_tree_model_get (model, &iter, THUNAR_SHORTCUTS_MODEL_COLUMN_DEVICE, &device, -1); + _thunar_return_if_fail (THUNAR_IS_DEVICE (device)); - /* try unmounting the mount */ - g_mount_unmount_with_operation (volume_mount, - G_MOUNT_UNMOUNT_NONE, - mount_operation, - NULL, - thunar_shortcuts_view_unmount_finish, - g_object_ref (view)); - } + /* prepare a mount operation */ + window = gtk_widget_get_toplevel (GTK_WIDGET (view)); + mount_operation = gtk_mount_operation_new (GTK_WINDOW (window)); - g_object_unref (volume_mount); - } - } + /* try to unmount */ + thunar_device_eject (device, + mount_operation, + NULL, + thunar_shortcuts_view_eject_finish, + g_object_ref (view)); - g_object_unref (volume); + g_object_unref (G_OBJECT (device)); } } @@ -1806,7 +1607,6 @@ thunar_shortcuts_view_poke_volume_mount_finish (ThunarBrowser *browser, - static void thunar_shortcuts_view_mount (ThunarShortcutsView *view) { @@ -1827,9 +1627,10 @@ thunar_shortcuts_view_mount (ThunarShortcutsView *view) if (gtk_tree_selection_get_selected (selection, &model, &iter)) { /* determine the file for the shortcut at the given tree iterator */ - gtk_tree_model_get (model, &iter, + volume = NULL; + /*gtk_tree_model_get (model, &iter, THUNAR_SHORTCUTS_MODEL_COLUMN_VOLUME, &volume, - -1); + -1);*/ if (G_LIKELY (volume != NULL)) { @@ -1844,14 +1645,37 @@ thunar_shortcuts_view_mount (ThunarShortcutsView *view) static void +thunar_shortcuts_view_unmount_finish (ThunarDevice *device, + const GError *error, + gpointer user_data) +{ + ThunarShortcutsView *view = THUNAR_SHORTCUTS_VIEW (user_data); + gchar *device_name; + + _thunar_return_if_fail (THUNAR_IS_DEVICE (device)); + _thunar_return_if_fail (THUNAR_IS_SHORTCUTS_VIEW (view)); + + /* check if there was an error */ + if (error != NULL) + { + /* display an error dialog to inform the user */ + device_name = thunar_device_get_name (device); + thunar_dialogs_show_error (GTK_WIDGET (view), error, _("Failed to unmount \"%s\""), device_name); + g_free (device_name); + } + + g_object_unref (view); +} + + + +static void thunar_shortcuts_view_unmount (ThunarShortcutsView *view) { GtkTreeSelection *selection; GtkTreeModel *model; GtkTreeIter iter; - GVolume *volume; - GMount *mount; - GMount *volume_mount; + ThunarDevice *device; GMountOperation *mount_operation; GtkWidget *window; @@ -1862,65 +1686,21 @@ thunar_shortcuts_view_unmount (ThunarShortcutsView *view) if (gtk_tree_selection_get_selected (selection, &model, &iter)) { /* determine the volume/mount for the shortcut at the given tree iterator */ - gtk_tree_model_get (model, &iter, - THUNAR_SHORTCUTS_MODEL_COLUMN_VOLUME, &volume, - THUNAR_SHORTCUTS_MODEL_COLUMN_MOUNT, &mount, -1); - - _thunar_return_if_fail (volume == NULL || G_IS_VOLUME (volume)); - _thunar_return_if_fail (mount == NULL || G_IS_MOUNT (mount)); + gtk_tree_model_get (model, &iter, THUNAR_SHORTCUTS_MODEL_COLUMN_DEVICE, &device, -1); + _thunar_return_if_fail (THUNAR_IS_DEVICE (device)); /* prepare a mount operation */ window = gtk_widget_get_toplevel (GTK_WIDGET (view)); mount_operation = gtk_mount_operation_new (GTK_WINDOW (window)); - if (mount != NULL) - { - /* only handle mounts that can be unmounted here */ - if (g_mount_can_unmount (mount)) - { -#ifdef HAVE_LIBNOTIFY - thunar_notify_unmount (mount); -#endif - - /* try unmounting the mount */ - g_mount_unmount_with_operation (mount, - G_MOUNT_UNMOUNT_NONE, - mount_operation, - NULL, - thunar_shortcuts_view_unmount_finish, - g_object_ref (view)); - } - - g_object_unref (mount); - } - else if (volume != NULL) - { - volume_mount = g_volume_get_mount (volume); - if (volume_mount != NULL) - { - /* only handle mounts that can be unmounted here */ - if (g_mount_can_unmount (volume_mount)) - { -#ifdef HAVE_LIBNOTIFY - thunar_notify_unmount (volume_mount); -#endif - - /* try unmounting the mount */ - g_mount_unmount_with_operation (volume_mount, - G_MOUNT_UNMOUNT_NONE, - mount_operation, - NULL, - thunar_shortcuts_view_unmount_finish, - g_object_ref (view)); - } - - g_object_unref (volume_mount); - } - - g_object_unref (volume); - } + /* try to unmount */ + thunar_device_unmount (device, + mount_operation, + NULL, + thunar_shortcuts_view_unmount_finish, + g_object_ref (view)); - g_object_unref (mount_operation); + g_object_unref (G_OBJECT (device)); } } _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org https://mail.xfce.org/mailman/listinfo/xfce4-commits