File nautilus-219439-update-links-upon-unmount.diff of Package nautilus

2006-11-08  Federico Mena Quintero  <federico@novell.com>

	Fix https://bugzilla.novell.com/show_bug.cgi?id=219439
	(original bug: https://bugzilla.novell.com/show_bug.cgi?id=215351),
	the icon for a floppy drive disappears after unmounting the floppy.
	Also, unmounting an NFS volume makes the icon disappear.

	Fix the little bug where a recently-unmounted drive still
	shows an "Unmount Volume" menu item.

	* libnautilus-private/nautilus-desktop-link-monitor.c
	(drive_has_volumes_apart_from): New function; checks whether a
	drive has any mounted volumes apart from a given one.  We need
	this to check that corresponds to a volume that is being
	unmounted, since within the volume_unmounted callback, the drive
	still thinks it is mounted (as the volume in question has not been
	removed from it yet).
	(should_show_drive): Check whether the drive has any volumes left
	over aside from the volume being unmounted.
	(volume_unmounted_callback): Pass the volume to should_show_drive().

	* libnautilus-private/nautilus-desktop-icon-file.c
	(update_info_from_link): If the link acquires a volume, remove the
	drive from the corresponding NautilusFile.  And the converse: if
	the link acquires a drive, remove the volume from the
	corresponding NautilusFile.  Files can have volumes XOR drives, or
	none.  This fixes the bug where you mount a drive, then umount the
	corresponding volume, and the menu on the drive icon still shows
	"unmount volume".

	* libnautilus-private/nautilus-desktop-link.c
	(nautilus_desktop_link_update_from_volume): Removed spurious
	comment.

	* src/file-manager/fm-directory-view.c
	(activation_file_changed_after_drive_mounted): Don't check the
	file's drive; it doesn't have one because it got replaced with a
	volume.

--- nautilus/libnautilus-private/nautilus-desktop-link-monitor.c	2006-12-18 15:06:46.000000000 -0600
+++ nautilus/libnautilus-private/nautilus-desktop-link-monitor.c	2006-11-23 10:03:25.000000000 -0600
@@ -207,10 +207,43 @@ nautilus_desktop_link_monitor_make_filen
 }
 
 static gboolean
-should_show_drive (GnomeVFSDrive *drive)
+drive_has_volumes_apart_from (GnomeVFSDrive *drive, GnomeVFSVolume *possibly_last_volume)
 {
+	GList *volumes;
+	GList *l;
+	gboolean has_other_volumes;
+
+	has_other_volumes = FALSE;
+
+	volumes = gnome_vfs_drive_get_mounted_volumes (drive);
+
+	for (l = volumes; l; l = l->next) {
+		GnomeVFSVolume *volume;
+
+		volume = GNOME_VFS_VOLUME (l->data);
+		if (volume != possibly_last_volume)
+			has_other_volumes = TRUE;
+
+		gnome_vfs_volume_unref (volume);
+	}
+
+	g_list_free (volumes);
+
+	return has_other_volumes;
+}
+
+static gboolean
+should_show_drive (GnomeVFSDrive *drive, GnomeVFSVolume *possibly_last_volume)
+{
+	gboolean should_show;
+
+	if (possibly_last_volume)
+		should_show = !drive_has_volumes_apart_from (drive, possibly_last_volume);
+	else
+		should_show = !gnome_vfs_drive_is_mounted (drive);
+
 	return (gnome_vfs_drive_is_user_visible (drive)
-		&& !gnome_vfs_drive_is_mounted (drive)
+		&& should_show
 		&& eel_preferences_get_boolean (NAUTILUS_PREFERENCES_DESKTOP_VOLUMES_VISIBLE));
 }
 
@@ -227,7 +260,7 @@ create_drive_link (NautilusDesktopLinkMo
 {
 	NautilusDesktopLink *link;
 
-	if (!should_show_drive (drive))
+	if (!should_show_drive (drive, NULL))
 		return;
 
 	link = nautilus_desktop_link_new_from_drive_or_volume (G_OBJECT (drive));
@@ -457,7 +490,7 @@ volume_unmounted_callback (GnomeVFSVolum
 
 	drive = gnome_vfs_volume_get_drive (volume);
 	if (drive) {
-		if (should_show_drive (drive)) {
+		if (should_show_drive (drive, volume)) {
 			nautilus_desktop_link_update_from_volume (link, volume);
 		} else {
 			remove_link = TRUE;
--- nautilus/libnautilus-private/nautilus-desktop-icon-file.c	2006-12-18 15:06:46.000000000 -0600
+++ nautilus/libnautilus-private/nautilus-desktop-icon-file.c	2006-11-23 10:03:25.000000000 -0600
@@ -220,12 +224,16 @@ update_info_from_link (NautilusDesktopIc
 		volume = GNOME_VFS_VOLUME (drive_or_volume);
 		nautilus_file_set_volume (file, volume);
 		gnome_vfs_volume_unref (volume);
+
+		nautilus_file_set_drive (file, NULL);
 	} else {
 		GnomeVFSDrive *drive;
 
 		drive = GNOME_VFS_DRIVE (drive_or_volume);
 		nautilus_file_set_drive (file, drive);
 		gnome_vfs_drive_unref (drive);
+
+		nautilus_file_set_volume (file, NULL);
 	}
 	
 	file->details->file_info_is_up_to_date = TRUE;
--- nautilus/libnautilus-private/nautilus-desktop-link.c	2006-12-18 15:06:46.000000000 -0600
+++ nautilus/libnautilus-private/nautilus-desktop-link.c	2006-11-23 10:03:25.000000000 -0600
@@ -485,7 +485,6 @@ nautilus_desktop_link_update_from_volume
 
 		drive = gnome_vfs_volume_get_drive (volume);
 
-		/* Do we need to use gnome_vfs_drive_compare()? */
 		g_assert (G_OBJECT (drive) == G_OBJECT (link->details->drive_or_volume));
 		gnome_vfs_drive_unref (drive);
 
@@ -505,8 +504,6 @@ nautilus_desktop_link_update_from_volume
 		/* The link will get updated below */
 	} else {
 		g_assert (GNOME_IS_VFS_VOLUME (link->details->drive_or_volume));
-
-		/* Do we need to use gnome_vfs_volume_compare()? */
 		g_assert (GNOME_VFS_VOLUME (link->details->drive_or_volume) == volume);
 
 		/* If the volume got unmounted, restore the link's object to the
--- nautilus/src/file-manager/fm-directory-view.c	2006-12-18 15:06:46.000000000 -0600
+++ nautilus/src/file-manager/fm-directory-view.c	2006-12-18 16:47:28.000000000 -0600
@@ -7456,14 +7456,9 @@ activation_file_changed_after_drive_moun
 					     gpointer data)
 {
 	ActivateParameters *parameters;
-	GnomeVFSDrive *drive;
 
 	parameters = data;
 
-	drive = nautilus_file_get_drive (parameters->file); /* we don't own this reference */
-	g_assert (drive != NULL);
-	g_assert (gnome_vfs_drive_is_mounted (drive));
-
 	g_signal_handler_disconnect (parameters->file, parameters->file_changed_id);
 	parameters->file_changed_id = 0;
 
openSUSE Build Service is sponsored by