[PATH] nautilus places sidebar



Hi,

Following what I said in gnomevfs ML[1] here is a patch for the places
sidebar. It now list all unmounted and user-visible drives followed by
user-visible volumes. It is simpler since gnomevfs removed drive for
mounted partitons (/dev/hdX doesn't have a drive anymore).

[1]
http://mail.gnome.org/archives/gnome-vfs-list/2006-July/msg00045.html

Xavier Claessens.
Index: src/nautilus-places-sidebar.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-places-sidebar.c,v
retrieving revision 1.24
diff -u -p -r1.24 nautilus-places-sidebar.c
--- src/nautilus-places-sidebar.c	24 Jul 2006 22:45:37 -0000	1.24
+++ src/nautilus-places-sidebar.c	1 Aug 2006 19:15:21 -0000
@@ -113,6 +113,7 @@ enum {
 typedef enum {
 	PLACES_BUILT_IN,
 	PLACES_MOUNTED_VOLUME,
+	PLACES_DRIVE,
 	PLACES_BOOKMARK,
 	PLACES_SEPARATOR
 } PlaceType;
@@ -215,9 +216,8 @@ update_places (NautilusPlacesSidebar *si
 	GtkTreeSelection      *selection;
 	GtkTreeIter           iter, last_iter;
 	GnomeVFSVolumeMonitor *volume_monitor;
-	GList 		      *volumes, *l, *ll;
+	GList 		      *volumes, *drives, *l;
 	GnomeVFSVolume	      *volume;
-	GList		      *drives;
 	GnomeVFSDrive	      *drive;
 	int 		      bookmark_count, index;
 	char 		      *location, *icon, *mount_uri, *name, *desktop_path;
@@ -262,80 +262,53 @@ update_places (NautilusPlacesSidebar *si
 		gtk_tree_selection_select_iter (selection, &last_iter);
 	}
 
-	/* for all drives add all its volumes */
+	/* add user_visible unmouted drives */
 
 	volume_monitor = gnome_vfs_get_volume_monitor ();
 	drives = gnome_vfs_volume_monitor_get_connected_drives (volume_monitor);
 	drives = g_list_sort (drives, (GCompareFunc)gnome_vfs_drive_compare);
 	for (l = drives; l != NULL; l = l->next) {
 		drive = l->data;
-		if (!gnome_vfs_drive_is_user_visible (drive)) {
+		if (!gnome_vfs_drive_is_user_visible (drive) ||
+		    gnome_vfs_drive_is_mounted (drive)) {
 			gnome_vfs_drive_unref (drive);
 			continue;
 		}
-		if (gnome_vfs_drive_is_mounted (drive)) {
-			/* The drive is mounted, add all its volumes */
-			volumes = gnome_vfs_drive_get_mounted_volumes (drive);
-			volumes = g_list_sort (volumes, (GCompareFunc)gnome_vfs_volume_compare);
-			for (ll = volumes; ll != NULL; ll = ll->next) {
-				volume = ll->data;
-				if (!gnome_vfs_volume_is_user_visible (volume)) {
-					gnome_vfs_volume_unref (volume);
-					continue;
-				}
-				icon = gnome_vfs_volume_get_icon (volume);
-				mount_uri = gnome_vfs_volume_get_activation_uri (volume);
-				name = gnome_vfs_volume_get_display_name (volume);
-				last_iter = add_place (sidebar, PLACES_MOUNTED_VOLUME,
-						       name, icon, mount_uri,
-						       drive, volume, 0);
-				if (strcmp (location, mount_uri) == 0) {
-					gtk_tree_selection_select_iter (selection, &last_iter);
-				}
-				gnome_vfs_volume_unref (volume);
-				g_free (icon);
-				g_free (name);
-				g_free (mount_uri);
-			}
-			g_list_free (volumes);
-		} else {
-			/* The drive is unmounted but visible, add it.
-			 * This is for drives like floppy that can't be
-			 * auto-mounted */
-			icon = gnome_vfs_drive_get_icon (drive);
-			name = gnome_vfs_drive_get_display_name (drive);
-			last_iter = add_place (sidebar, PLACES_BUILT_IN,
-					       name, icon, NULL,
-					       drive, NULL, 0);
-			g_free (icon);
-			g_free (name);
-		}		
+		icon = gnome_vfs_drive_get_icon (drive);
+		mount_uri = gnome_vfs_drive_get_activation_uri (drive);
+		name = gnome_vfs_drive_get_display_name (drive);
+		last_iter = add_place (sidebar, PLACES_DRIVE,
+				       name, icon, mount_uri,
+				       drive, NULL, 0);
+		g_free (icon);
+		g_free (name);
+		g_free (mount_uri);
 		gnome_vfs_drive_unref (drive);
 	}
 	g_list_free (drives);
 
-	/* add mounted volumes that has no drive (ftp, sftp,...) */
+	/* add user_visible volumes */
 
 	volumes = gnome_vfs_volume_monitor_get_mounted_volumes (volume_monitor);
 	volumes = g_list_sort (volumes, (GCompareFunc)gnome_vfs_volume_compare);
 	for (l = volumes; l != NULL; l = l->next) {
 		volume = l->data;
-		drive = gnome_vfs_volume_get_drive (volume);
-		if (!gnome_vfs_volume_is_user_visible (volume) || drive != NULL) {
-		    	gnome_vfs_drive_unref (drive);
+		if (!gnome_vfs_volume_is_user_visible (volume)) {
 			gnome_vfs_volume_unref (volume);
 			continue;
 		}
+		drive = gnome_vfs_volume_get_drive (volume);
 		icon = gnome_vfs_volume_get_icon (volume);
 		mount_uri = gnome_vfs_volume_get_activation_uri (volume);
 		name = gnome_vfs_volume_get_display_name (volume);
 		last_iter = add_place (sidebar, PLACES_MOUNTED_VOLUME,
 				       name, icon, mount_uri,
-				       NULL, volume, 0);
+				       drive, volume, 0);
 		if (strcmp (location, mount_uri) == 0) {
 			gtk_tree_selection_select_iter (selection, &last_iter);
 		}
 		gnome_vfs_volume_unref (volume);
+		gnome_vfs_drive_unref (drive);
 		g_free (icon);
 		g_free (name);
 		g_free (mount_uri);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]