Nautilus hard code freeze break request



The attached patch causes Nautilus to close open navigation windows when
a mount point is unmounted, if they only displayed locations on the
mount (i.e. if they were opened as automount, or opened manually for the
specific locations). It also ensures that we never auto-close the very
last navigation window when no desktop is drawn.

It's supposed to fix bug 318094 [1].

If it's rejected due to its complexity, we should at least get in the

-               if (NAUTILUS_IS_SPATIAL_WINDOW (window)) {
+               if (NAUTILUS_IS_SPATIAL_WINDOW (slot->window)) {

bits because that's definitly a bug. Note how “window” points to a
random window, rather than the slot's window.


best regards,
 Christian Neumair

[1] http://bugzilla.gnome.org/show_bug.cgi?id=318094

-- 
Christian Neumair <cneumair gnome org>
Index: src/nautilus-application.c
===================================================================
--- src/nautilus-application.c	(Revision 14599)
+++ src/nautilus-application.c	(Arbeitskopie)
@@ -50,6 +50,8 @@
 #include "nautilus-main.h"
 #include "nautilus-spatial-window.h"
 #include "nautilus-navigation-window.h"
+#include "nautilus-window-slot.h"
+#include "nautilus-navigation-window-slot.h"
 #include "nautilus-shell-interface.h"
 #include "nautilus-shell.h"
 #include "nautilus-window-bookmarks.h"
@@ -1446,6 +1448,40 @@ mount_added_callback (GVolumeMonitor *mo
 	nautilus_autorun (mount, autorun_show_window, application);
 }
 
+static inline int
+count_slots_for_windows (GList *window_list)
+{
+	NautilusWindow *window;
+	GList *slots, *l;
+	int count;
+
+	count = 0;
+
+	for (l = window_list; l != NULL; l = l->next) {
+		window = NAUTILUS_WINDOW (l->data);
+
+		slots = nautilus_window_get_slots (window);
+		count += g_list_length (slots);
+		g_list_free (slots);
+	}
+
+	return count;
+}
+
+static NautilusWindowSlot *
+get_first_navigation_slot (GList *slot_list)
+{
+	GList *l;
+
+	for (l = slot_list; l != NULL; l = l->next) {
+		if (NAUTILUS_IS_NAVIGATION_WINDOW_SLOT (l->data)) {
+			return l->data;
+		}
+	}
+
+	return NULL;
+}
+
 /* Called whenever a mount is unmounted. Check and see if there are
  * any windows open displaying contents on the mount. If there are,
  * close them.  It would also be cool to save open window and position
@@ -1461,9 +1497,11 @@ mount_removed_callback (GVolumeMonitor *
 	GList *window_list, *node, *close_list;
 	NautilusWindow *window;
 	NautilusWindowSlot *slot;
+	NautilusWindowSlot *force_no_close_slot;
 	GFile *root;
 
 	close_list = NULL;
+	force_no_close_slot = NULL;
 	
 	/* Check and see if any of the open windows are displaying contents from the unmounted mount */
 	window_list = nautilus_application_get_window_list ();
@@ -1486,13 +1524,24 @@ mount_removed_callback (GVolumeMonitor *
 		}
 	}
 
+	if (nautilus_application_desktop_windows == NULL &&
+	    g_list_length (close_list) != 0 &&
+	    g_list_length (close_list) == count_slots_for_windows (window_list)) {
+		/* We are trying to close all open slots. Keep one navigation slot open. */
+		force_no_close_slot = get_first_navigation_slot (close_list);
+	}
+
 	/* Handle the windows in the close list. */
 	for (node = close_list; node != NULL; node = node->next) {
 		slot = node->data;
-		if (NAUTILUS_IS_SPATIAL_WINDOW (window)) {
+		window = slot->window;
+
+		if (NAUTILUS_IS_SPATIAL_WINDOW (window) ||
+		    (nautilus_navigation_window_slot_should_close_with_mount (NAUTILUS_NAVIGATION_WINDOW_SLOT (slot), mount) &&
+		     slot != force_no_close_slot)) {
 			nautilus_window_slot_close (slot);
 		} else {
-			nautilus_window_go_home (slot->window);
+			nautilus_window_slot_go_home (slot, FALSE);
 		}
 	}
 
Index: src/nautilus-navigation-window-slot.c
===================================================================
--- src/nautilus-navigation-window-slot.c	(Revision 14599)
+++ src/nautilus-navigation-window-slot.c	(Arbeitskopie)
@@ -36,6 +36,43 @@ static void nautilus_navigation_window_s
 G_DEFINE_TYPE (NautilusNavigationWindowSlot, nautilus_navigation_window_slot, NAUTILUS_TYPE_WINDOW_SLOT)
 #define parent_class nautilus_navigation_window_slot_parent_class
 
+gboolean
+nautilus_navigation_window_slot_should_close_with_mount (NautilusNavigationWindowSlot *slot,
+							 GMount *mount)
+{
+	NautilusBookmark *bookmark;
+	GFile *mount_location, *bookmark_location;
+	GList *l;
+	gboolean close_with_mount;
+
+	mount_location = g_mount_get_root (mount);
+
+	close_with_mount = TRUE;
+
+	for (l = slot->back_list; l != NULL; l = l->next) {
+		bookmark = NAUTILUS_BOOKMARK (l->data);
+
+		bookmark_location = nautilus_bookmark_get_location (bookmark);
+		close_with_mount &= g_file_has_prefix (bookmark_location, mount_location);
+		g_object_unref (bookmark_location);
+
+		if (!close_with_mount) {
+			break;
+		}
+	}
+
+	close_with_mount &= g_file_has_prefix (NAUTILUS_WINDOW_SLOT (slot)->location, mount_location);
+
+	/* we could also consider the forward list here, but since the “go home” request
+	 * in nautilus-window-manager-views.c:mount_removed_callback() would discard those
+	 * anyway, we don't consider them.
+	 */
+
+	g_object_unref (mount_location);
+
+	return close_with_mount;
+}
+
 void
 nautilus_navigation_window_slot_clear_forward_list (NautilusNavigationWindowSlot *slot)
 {
Index: src/nautilus-navigation-window-slot.h
===================================================================
--- src/nautilus-navigation-window-slot.h	(Revision 14599)
+++ src/nautilus-navigation-window-slot.h	(Arbeitskopie)
@@ -66,6 +66,9 @@ struct NautilusNavigationWindowSlotClass
 
 GType nautilus_navigation_window_slot_get_type (void);
 
+gboolean nautilus_navigation_window_slot_should_close_with_mount (NautilusNavigationWindowSlot *slot,
+								  GMount *mount);
+
 void nautilus_navigation_window_slot_clear_forward_list (NautilusNavigationWindowSlot *slot);
 void nautilus_navigation_window_slot_clear_back_list    (NautilusNavigationWindowSlot *slot);
 


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