From b7a6df75d387760cc159d225a1d8d40a785ddd74 Mon Sep 17 00:00:00 2001 From: Benedikt Meurer <benny@xfce.org> Date: Tue, 14 Feb 2006 11:45:28 +0000 Subject: [PATCH] 2006-02-14 Benedikt Meurer <benny@xfce.org> * thunar/thunar-shortcuts-model.c: Include non-removable volumes in the list of hidden volumes. * thunar-vfs/thunar-vfs-volume-hal.c: Determine the volumes from the drives on startup, instead of FindDeviceByCapability(volume), as that seems to be what GNOME does. Maybe one day, there'll be a usable HAL documentation, and hardware will really just work. (Old svn revision: 19864) --- ChangeLog | 9 +++++ thunar-vfs/thunar-vfs-volume-hal.c | 47 +++++++++++++++++------ thunar/thunar-shortcuts-model.c | 60 +++++++++++++++--------------- 3 files changed, 75 insertions(+), 41 deletions(-) diff --git a/ChangeLog b/ChangeLog index b9253d309..c56320907 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2006-02-14 Benedikt Meurer <benny@xfce.org> + + * thunar/thunar-shortcuts-model.c: Include non-removable volumes in + the list of hidden volumes. + * thunar-vfs/thunar-vfs-volume-hal.c: Determine the volumes from the + drives on startup, instead of FindDeviceByCapability(volume), as + that seems to be what GNOME does. Maybe one day, there'll be a + usable HAL documentation, and hardware will really just work. + 2006-02-13 Benedikt Meurer <benny@xfce.org> * acinclude.m4, configure.in.in, thunar-vfs/Makefile.am, diff --git a/thunar-vfs/thunar-vfs-volume-hal.c b/thunar-vfs/thunar-vfs-volume-hal.c index a18597a72..527147531 100644 --- a/thunar-vfs/thunar-vfs-volume-hal.c +++ b/thunar-vfs/thunar-vfs-volume-hal.c @@ -720,10 +720,13 @@ thunar_vfs_volume_manager_hal_manager_init (ThunarVfsVolumeManagerIface *iface) static void thunar_vfs_volume_manager_hal_init (ThunarVfsVolumeManagerHal *manager_hal) { - DBusError error; - gchar **udis; - gint n_udis; - gint n; + LibHalDrive *hd; + DBusError error; + gchar **drive_udis; + gchar **udis; + gint n_drive_udis; + gint n_udis; + gint n, m; /* initialize the D-BUS error */ dbus_error_init (&error); @@ -758,16 +761,36 @@ thunar_vfs_volume_manager_hal_init (ThunarVfsVolumeManagerHal *manager_hal) /* setup the D-BUS connection with the GLib main loop */ dbus_connection_setup_with_g_main (manager_hal->dbus_connection, NULL); - /* lookup all volumes currently known to HAL */ - udis = libhal_find_device_by_capability (manager_hal->context, "volume", &n_udis, NULL); - if (G_LIKELY (udis != NULL)) + /* lookup all drives currently known to HAL */ + drive_udis = libhal_find_device_by_capability (manager_hal->context, "storage", &n_drive_udis, &error); + if (G_LIKELY (drive_udis != NULL)) { - /* add volumes for all given UDIs */ - for (n = 0; n < n_udis; ++n) - thunar_vfs_volume_manager_hal_device_added (manager_hal->context, udis[n]); + /* process all drives UDIs */ + for (m = 0; m < n_drive_udis; ++m) + { + /* determine the LibHalDrive for the drive UDI */ + hd = libhal_drive_from_udi (manager_hal->context, drive_udis[m]); + if (G_UNLIKELY (hd == NULL)) + continue; + + /* determine all volumes for the given drive */ + udis = libhal_drive_find_all_volumes (manager_hal->context, hd, &n_udis); + if (G_LIKELY (udis != NULL)) + { + /* add volumes for all given UDIs */ + for (n = 0; n < n_udis; ++n) + thunar_vfs_volume_manager_hal_device_added (manager_hal->context, udis[n]); + + /* release the UDIs */ + libhal_free_string_array (udis); + } + + /* release the hal drive */ + libhal_drive_free (hd); + } - /* release the UDIs */ - libhal_free_string_array (udis); + /* release the drive UDIs */ + libhal_free_string_array (drive_udis); } /* watch all devices for changes */ diff --git a/thunar/thunar-shortcuts-model.c b/thunar/thunar-shortcuts-model.c index ef0844ebd..3d4e37968 100644 --- a/thunar/thunar-shortcuts-model.c +++ b/thunar/thunar-shortcuts-model.c @@ -302,35 +302,32 @@ thunar_shortcuts_model_init (ThunarShortcutsModel *model) volumes = thunar_vfs_volume_manager_get_volumes (model->volume_manager); for (lp = volumes; lp != NULL; lp = lp->next) { - /* we list only removable devices here */ + /* monitor the volume for changes */ volume = THUNAR_VFS_VOLUME (lp->data); - if (thunar_vfs_volume_is_removable (volume)) + g_object_ref (G_OBJECT (volume)); + g_signal_connect (G_OBJECT (volume), "changed", + G_CALLBACK (thunar_shortcuts_model_volume_changed), model); + + /* we list only present, removable devices here */ + if (thunar_vfs_volume_is_removable (volume) && thunar_vfs_volume_is_present (volume)) { - /* monitor the volume for changes */ - g_object_ref (G_OBJECT (volume)); - g_signal_connect (G_OBJECT (volume), "changed", - G_CALLBACK (thunar_shortcuts_model_volume_changed), model); + /* generate the shortcut (w/o a file, else we might + * prevent the volume from being unmounted) + */ + shortcut = g_new (ThunarShortcut, 1); + shortcut->type = THUNAR_SHORTCUT_REMOVABLE_MEDIA; + shortcut->file = NULL; + shortcut->name = NULL; + shortcut->volume = volume; - if (thunar_vfs_volume_is_present (volume)) - { - /* generate the shortcut (w/o a file, else we might - * prevent the volume from being unmounted) - */ - shortcut = g_new (ThunarShortcut, 1); - shortcut->type = THUNAR_SHORTCUT_REMOVABLE_MEDIA; - shortcut->file = NULL; - shortcut->name = NULL; - shortcut->volume = volume; - - /* link the shortcut to the list */ - thunar_shortcuts_model_add_shortcut (model, shortcut, path); - gtk_tree_path_next (path); - } - else - { - /* schedule the volume for later checking, there's no medium present */ - model->hidden_volumes = g_list_prepend (model->hidden_volumes, volume); - } + /* link the shortcut to the list */ + thunar_shortcuts_model_add_shortcut (model, shortcut, path); + gtk_tree_path_next (path); + } + else + { + /* schedule the volume for later checking, not removable or there's no medium present */ + model->hidden_volumes = g_list_prepend (model->hidden_volumes, volume); } } @@ -365,6 +362,7 @@ static void thunar_shortcuts_model_finalize (GObject *object) { ThunarShortcutsModel *model = THUNAR_SHORTCUTS_MODEL (object); + GList *lp; g_return_if_fail (THUNAR_IS_SHORTCUTS_MODEL (model)); @@ -373,7 +371,11 @@ thunar_shortcuts_model_finalize (GObject *object) g_list_free (model->shortcuts); /* free all hidden volumes */ - g_list_foreach (model->hidden_volumes, (GFunc) g_object_unref, NULL); + for (lp = model->hidden_volumes; lp != NULL; lp = lp->next) + { + g_signal_handlers_disconnect_by_func (G_OBJECT (lp->data), thunar_shortcuts_model_volume_changed, model); + g_object_unref (G_OBJECT (lp->data)); + } g_list_free (model->hidden_volumes); /* detach from the VFS monitor */ @@ -1021,7 +1023,7 @@ thunar_shortcuts_model_volume_changed (ThunarVfsVolume *volume, if (lp != NULL) { /* check if we need to display the volume now */ - if (thunar_vfs_volume_is_present (volume)) + if (thunar_vfs_volume_is_present (volume) && thunar_vfs_volume_is_removable (volume)) { /* remove the volume from the list of hidden volumes */ model->hidden_volumes = g_list_delete_link (model->hidden_volumes, lp); @@ -1063,7 +1065,7 @@ thunar_shortcuts_model_volume_changed (ThunarVfsVolume *volume, g_assert (shortcut->volume == volume); /* check if we need to hide the volume now */ - if (!thunar_vfs_volume_is_present (volume)) + if (!thunar_vfs_volume_is_present (volume) || !thunar_vfs_volume_is_removable (volume)) { /* need to ref here, because the file_destroy() handler will drop the refcount. */ g_object_ref (G_OBJECT (volume)); -- GitLab