Commit 5301e29f authored by Christian Neumair's avatar Christian Neumair Committed by Christian Neumair

When unmounting, close all slots that only displayed locations on the

2008-09-24  Christian Neumair  <cneumair@gnome.org>

	* src/nautilus-application.c (count_slots_of_windows),
	(get_first_navigation_slot), (mount_removed_callback):
	* src/nautilus-navigation-window-slot.c
	(nautilus_navigation_window_slot_should_close_with_mount):
	* src/nautilus-navigation-window-slot.h:
	When unmounting, close all slots that only displayed locations on the
	mount. Never close all open slots, though. 

svn path=/trunk/; revision=14663
parent a76c9bc3
2008-09-24 Christian Neumair <cneumair@gnome.org>
* src/nautilus-application.c (count_slots_of_windows),
(get_first_navigation_slot), (mount_removed_callback):
* src/nautilus-navigation-window-slot.c
(nautilus_navigation_window_slot_should_close_with_mount):
* src/nautilus-navigation-window-slot.h:
When unmounting, close all slots that only displayed locations on the
mount. Never close all open slots, though.
2008-09-24 Cosimo Cecchi <cosimoc@gnome.org>
* configure.in:
......
......@@ -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 *monitor,
nautilus_autorun (mount, autorun_show_window, application);
}
static inline int
count_slots_of_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 *monitor,
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,11 +1524,21 @@ mount_removed_callback (GVolumeMonitor *monitor,
}
}
if (nautilus_application_desktop_windows == NULL &&
g_list_length (close_list) != 0 &&
g_list_length (close_list) == count_slots_of_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;
window = slot->window;
if (NAUTILUS_IS_SPATIAL_WINDOW (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_slot_go_home (slot, FALSE);
......
......@@ -36,6 +36,43 @@ static void nautilus_navigation_window_slot_class_init (NautilusNavigationWindow
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)
{
......
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment