static ThunarVfsVolume* thunar_vfs_volume_manager_real_get_volume_by_info (ThunarVfsVolumeManager *manager, const ThunarVfsInfo *info) { ThunarVfsVolume *best_volume = NULL; ThunarVfsPath *best_path = NULL; ThunarVfsPath *info_path; ThunarVfsPath *path; GList *lp; /* translate the info's path to a local path */ info_path = _thunar_vfs_path_translate (info->path, THUNAR_VFS_PATH_SCHEME_FILE, NULL); if (G_LIKELY (info_path != NULL)) { /* otherwise try to find it the hard way */ for (lp = manager->volumes; lp != NULL; lp = lp->next) { /* check if the volume is mounted */ if (!thunar_vfs_volume_is_mounted (lp->data)) continue; /* check if the mount point is an ancestor of the info path */ path = thunar_vfs_volume_get_mount_point (lp->data); if (path == NULL || (!thunar_vfs_path_equal (info_path, path) && !thunar_vfs_path_is_ancestor (info_path, path))) continue; /* possible match, check if better than previous match */ if (best_volume == NULL || thunar_vfs_path_equal (path, best_path) || thunar_vfs_path_is_ancestor (path, best_path)) { best_volume = lp->data; best_path = path; } } /* cleanup */ thunar_vfs_path_unref (info_path); } return best_volume; }
static void thunar_location_entry_item_activated (GtkWidget *item, ThunarLocationEntry *location_entry) { ThunarVfsVolume *volume; ThunarFile *file; GtkWidget *window; GError *error = NULL; _thunar_return_if_fail (GTK_IS_MENU_ITEM (item)); _thunar_return_if_fail (THUNAR_IS_LOCATION_ENTRY (location_entry)); /* determine the toplevel window */ window = gtk_widget_get_toplevel (GTK_WIDGET (location_entry)); /* check if the item corresponds to a volume */ volume = g_object_get_data (G_OBJECT (item), "thunar-vfs-volume"); if (G_UNLIKELY (volume != NULL)) { /* check if the volume isn't already mounted */ if (G_LIKELY (!thunar_vfs_volume_is_mounted (volume))) { /* try to mount the volume */ if (!thunar_vfs_volume_mount (volume, window, &error)) { /* display an error dialog to inform the user */ thunar_dialogs_show_error (window, error, _("Failed to mount \"%s\""), thunar_vfs_volume_get_name (volume)); g_error_free (error); return; } } /* try to determine the mount point of the volume */ file = thunar_file_get_for_path (thunar_vfs_volume_get_mount_point (volume), &error); if (G_UNLIKELY (file == NULL)) { /* display an error dialog to inform the user */ thunar_dialogs_show_error (window, error, _("Failed to determine the mount point for %s"), thunar_vfs_volume_get_name (volume)); g_error_free (error); return; } } else { /* determine the file from the item */ file = g_object_get_data (G_OBJECT (item), "thunar-file"); if (G_LIKELY (file != NULL)) g_object_ref (G_OBJECT (file)); } /* check if we have a file object now */ if (G_LIKELY (file != NULL)) { /* make sure that this is actually a directory */ if (thunar_file_is_directory (file)) { /* open the new directory */ thunar_navigator_change_directory (THUNAR_NAVIGATOR (location_entry), file); } /* cleanup */ g_object_unref (G_OBJECT (file)); } }
static void thunar_vfs_volume_manager_hal_device_condition (LibHalContext *context, const gchar *udi, const gchar *name, const gchar *details) { ThunarVfsVolumeManagerHal *manager_hal = libhal_ctx_get_user_data (context); ThunarVfsVolumeHal *volume_hal; DBusError derror; GList *volumes = NULL; GList *lp; gchar **volume_udis; gint n_volume_udis; gint n; _thunar_vfs_return_if_fail (THUNAR_VFS_IS_VOLUME_MANAGER_HAL (manager_hal)); _thunar_vfs_return_if_fail (manager_hal->context == context); /* check if the device should be ejected */ if (G_LIKELY (strcmp (name, "EjectPressed") == 0)) { /* check if we have a volume for the device */ volume_hal = thunar_vfs_volume_manager_hal_get_volume_by_udi (manager_hal, udi); if (G_LIKELY (volume_hal == NULL)) { /* initialize D-Bus error */ dbus_error_init (&derror); /* the UDI most probably identifies the drive of the volume */ volume_udis = libhal_manager_find_device_string_match (context, "info.parent", udi, &n_volume_udis, &derror); if (G_LIKELY (volume_udis != NULL)) { /* determine the volumes for the UDIs */ for (n = 0; n < n_volume_udis; ++n) { /* check if we have a mounted volume for this UDI */ volume_hal = thunar_vfs_volume_manager_hal_get_volume_by_udi (manager_hal, volume_udis[n]); if (volume_hal != NULL && thunar_vfs_volume_is_mounted (THUNAR_VFS_VOLUME (volume_hal))) volumes = g_list_prepend (volumes, g_object_ref (G_OBJECT (volume_hal))); } libhal_free_string_array (volume_udis); } /* free D-Bus error */ dbus_error_free (&derror); } else if (thunar_vfs_volume_is_mounted (THUNAR_VFS_VOLUME (volume_hal))) { volumes = g_list_prepend (volumes, g_object_ref (G_OBJECT (volume_hal))); } /* check there are any mounted volumes on the device */ if (G_LIKELY (volumes != NULL)) { /* tell everybody, that we're about to unmount those volumes */ for (lp = volumes; lp != NULL; lp = lp->next) { thunar_vfs_volume_pre_unmount (lp->data); g_object_unref (G_OBJECT (lp->data)); } g_list_free (volumes); /* emit the "device-eject" signal and let Thunar eject the device */ g_signal_emit_by_name (G_OBJECT (manager_hal), "device-eject", udi); } } }