summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libnautilus-private/nautilus-file-utilities.c42
-rw-r--r--libnautilus-private/nautilus-file-utilities.h1
-rw-r--r--libnautilus-private/nautilus-monitor.c8
-rw-r--r--src/nautilus-application.c77
-rw-r--r--src/nautilus-pathbar.c44
-rw-r--r--src/nautilus-window-manage-views.c25
-rw-r--r--src/nautilus-window-slot.c17
-rw-r--r--src/nautilus-window-slot.h3
8 files changed, 62 insertions, 155 deletions
diff --git a/libnautilus-private/nautilus-file-utilities.c b/libnautilus-private/nautilus-file-utilities.c
index 35a43d66c..b526a42b7 100644
--- a/libnautilus-private/nautilus-file-utilities.c
+++ b/libnautilus-private/nautilus-file-utilities.c
@@ -882,6 +882,48 @@ nautilus_is_desktop_directory (GFile *dir)
return g_file_equal (dir, desktop_dir);
}
+GMount *
+nautilus_get_mounted_mount_for_root (GFile *location)
+{
+ GVolumeMonitor *volume_monitor;
+ GList *mounts;
+ GList *l;
+ GMount *mount;
+ GMount *result = NULL;
+ GFile *root = NULL;
+ GFile *default_location = NULL;
+
+ volume_monitor = g_volume_monitor_get ();
+ mounts = g_volume_monitor_get_mounts (volume_monitor);
+
+ for (l = mounts; l != NULL; l = l->next) {
+ mount = l->data;
+
+ if (g_mount_is_shadowed (mount)) {
+ continue;
+ }
+
+ root = g_mount_get_root (mount);
+ if (g_file_equal (location, root)) {
+ result = g_object_ref (mount);
+ break;
+ }
+
+ default_location = g_mount_get_default_location (mount);
+ if (!g_file_equal (default_location, root) &&
+ g_file_equal (location, default_location)) {
+ result = g_object_ref (mount);
+ break;
+ }
+ }
+
+ g_clear_object (&root);
+ g_clear_object (&default_location);
+ g_list_free_full (mounts, g_object_unref);
+
+ return result;
+}
+
char *
nautilus_ensure_unique_file_name (const char *directory_uri,
const char *base_name,
diff --git a/libnautilus-private/nautilus-file-utilities.h b/libnautilus-private/nautilus-file-utilities.h
index 009fc3dcf..5ff4811d3 100644
--- a/libnautilus-private/nautilus-file-utilities.h
+++ b/libnautilus-private/nautilus-file-utilities.h
@@ -48,6 +48,7 @@ gboolean nautilus_is_home_directory (GFile *dir);
gboolean nautilus_is_home_directory_file (GFile *dir,
const char *filename);
gboolean nautilus_is_in_system_dir (GFile *location);
+GMount * nautilus_get_mounted_mount_for_root (GFile *location);
gboolean nautilus_should_use_templates_directory (void);
char * nautilus_get_templates_directory (void);
diff --git a/libnautilus-private/nautilus-monitor.c b/libnautilus-private/nautilus-monitor.c
index 906d73c47..feeeb9b75 100644
--- a/libnautilus-private/nautilus-monitor.c
+++ b/libnautilus-private/nautilus-monitor.c
@@ -93,19 +93,13 @@ dir_changed (GFileMonitor* monitor,
case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
nautilus_file_changes_queue_file_changed (child);
break;
+ case G_FILE_MONITOR_EVENT_UNMOUNTED:
case G_FILE_MONITOR_EVENT_DELETED:
nautilus_file_changes_queue_file_removed (child);
break;
case G_FILE_MONITOR_EVENT_CREATED:
nautilus_file_changes_queue_file_added (child);
break;
-
- case G_FILE_MONITOR_EVENT_PRE_UNMOUNT:
- /* TODO: Do something */
- break;
- case G_FILE_MONITOR_EVENT_UNMOUNTED:
- /* TODO: Do something */
- break;
}
g_free (uri);
diff --git a/src/nautilus-application.c b/src/nautilus-application.c
index fa1f4f454..5bab06884 100644
--- a/src/nautilus-application.c
+++ b/src/nautilus-application.c
@@ -94,9 +94,6 @@ static GList *nautilus_application_desktop_windows;
static gboolean save_of_accel_map_requested = FALSE;
static void desktop_changed_callback (gpointer user_data);
-static void mount_removed_callback (GVolumeMonitor *monitor,
- GMount *mount,
- NautilusApplication *application);
static void mount_added_callback (GVolumeMonitor *monitor,
GMount *mount,
NautilusApplication *application);
@@ -577,76 +574,6 @@ mount_added_callback (GVolumeMonitor *monitor,
}
}
-/* 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
- * info.
- */
-static void
-mount_removed_callback (GVolumeMonitor *monitor,
- GMount *mount,
- NautilusApplication *application)
-{
- GList *window_list, *node, *close_list;
- NautilusWindow *window;
- NautilusWindowSlot *slot;
- NautilusWindowSlot *force_no_close_slot;
- GFile *root, *computer;
- gchar *uri;
- gint n_slots;
-
- close_list = NULL;
- force_no_close_slot = NULL;
- n_slots = 0;
-
- /* Check and see if any of the open windows are displaying contents from the unmounted mount */
- window_list = gtk_application_get_windows (GTK_APPLICATION (application));
-
- root = g_mount_get_root (mount);
- uri = g_file_get_uri (root);
-
- DEBUG ("Removed mount at uri %s", uri);
- g_free (uri);
-
- /* Construct a list of windows to be closed. Do not add the non-closable windows to the list. */
- for (node = window_list; node != NULL; node = node->next) {
- window = NAUTILUS_WINDOW (node->data);
- if (window != NULL && !NAUTILUS_IS_DESKTOP_WINDOW (window)) {
- GList *l;
-
- for (l = window->details->slots; l != NULL; l = l->next) {
- slot = l->data;
- n_slots++;
- if (nautilus_window_slot_should_close_with_mount (slot, mount)) {
- close_list = g_list_prepend (close_list, slot);
- }
- } /* for all slots */
- }
- }
-
- if ((nautilus_application_desktop_windows == NULL) &&
- (close_list != NULL) &&
- (g_list_length (close_list) == n_slots)) {
- /* We are trying to close all open slots. Keep one navigation slot open. */
- force_no_close_slot = close_list->data;
- }
-
- /* Handle the windows in the close list. */
- for (node = close_list; node != NULL; node = node->next) {
- slot = node->data;
-
- if (slot != force_no_close_slot) {
- nautilus_window_slot_close (slot->window, slot);
- } else {
- computer = g_file_new_for_path (g_get_home_dir ());
- nautilus_window_slot_open_location (slot, computer, 0);
- g_object_unref (computer);
- }
- }
-
- g_list_free (close_list);
-}
-
static void
open_window (NautilusApplication *application,
GFile *location, GdkScreen *screen, const char *geometry)
@@ -1424,11 +1351,7 @@ nautilus_application_startup (GApplication *app)
notify_init (GETTEXT_PACKAGE);
self->priv->progress_handler = nautilus_progress_ui_handler_new ();
- /* Watch for unmounts so we can close open windows */
- /* TODO-gio: This should be using the UNMOUNTED feature of GFileMonitor instead */
self->priv->volume_monitor = g_volume_monitor_get ();
- g_signal_connect_object (self->priv->volume_monitor, "mount_removed",
- G_CALLBACK (mount_removed_callback), self, 0);
g_signal_connect_object (self->priv->volume_monitor, "mount_added",
G_CALLBACK (mount_added_callback), self, 0);
diff --git a/src/nautilus-pathbar.c b/src/nautilus-pathbar.c
index c6d3e7df5..29eaf2d9e 100644
--- a/src/nautilus-pathbar.c
+++ b/src/nautilus-pathbar.c
@@ -1385,55 +1385,15 @@ nautilus_path_bar_update_button_state (ButtonData *button_data,
}
}
-static GMount *
-get_location_is_mounted_mount (GFile *location)
-{
- GVolumeMonitor *volume_monitor;
- GList *mounts, *l;
- GMount *mount, *result = NULL;
- GFile *root = NULL, *default_location = NULL;
-
- volume_monitor = g_volume_monitor_get ();
- mounts = g_volume_monitor_get_mounts (volume_monitor);
-
- for (l = mounts; l != NULL; l = l->next) {
- mount = l->data;
-
- if (g_mount_is_shadowed (mount)) {
- continue;
- }
-
- root = g_mount_get_root (mount);
- if (g_file_equal (location, root)) {
- result = g_object_ref (mount);
- break;
- }
-
- default_location = g_mount_get_default_location (mount);
- if (!g_file_equal (default_location, root) &&
- g_file_equal (location, default_location)) {
- result = g_object_ref (mount);
- break;
- }
- }
-
- g_clear_object (&root);
- g_clear_object (&default_location);
- g_list_free_full (mounts, g_object_unref);
-
- return result;
-}
-
static gboolean
setup_file_path_mounted_mount (GFile *location,
ButtonData *button_data)
{
NautilusIconInfo *info;
GIcon *icon;
- GMount *mount = NULL;
-
- mount = get_location_is_mounted_mount (location);
+ GMount *mount;
+ mount = nautilus_get_mounted_mount_for_root (location);
if (mount == NULL) {
return FALSE;
}
diff --git a/src/nautilus-window-manage-views.c b/src/nautilus-window-manage-views.c
index 1a19b797f..3f8b2f089 100644
--- a/src/nautilus-window-manage-views.c
+++ b/src/nautilus-window-manage-views.c
@@ -292,14 +292,14 @@ viewed_file_changed_callback (NautilusFile *file,
slot->viewed_file_in_trash = is_in_trash = nautilus_file_is_in_trash (file);
- /* Close window if the file it's viewing has been deleted or moved to trash. */
if (nautilus_file_is_gone (file) || (is_in_trash && !was_in_trash)) {
- /* Don't close the window in the case where the
- * file was never seen in the first place.
- */
+
if (slot->viewed_file_seen) {
/* auto-show existing parent. */
- GFile *go_to_file, *parent, *location;
+ GFile *go_to_file;
+ GFile *parent;
+ GFile *location;
+ GMount *mount;
/* Detecting a file is gone may happen in the
* middle of a pending location change, we
@@ -317,14 +317,21 @@ viewed_file_changed_callback (NautilusFile *file,
end_location_change (slot);
go_to_file = NULL;
- location = nautilus_file_get_location (file);
- parent = g_file_get_parent (location);
+ parent = NULL;
+
+ location = nautilus_file_get_location (file);
+ mount = nautilus_get_mounted_mount_for_root (location);
+ if (mount != NULL) {
+ parent = g_file_get_parent (location);
+ g_object_unref (mount);
+ }
g_object_unref (location);
- if (parent) {
+
+ if (parent != NULL) {
go_to_file = nautilus_find_existing_uri_in_hierarchy (parent);
g_object_unref (parent);
}
-
+
if (go_to_file != NULL) {
/* the path bar URI will be set to go_to_uri immediately
* in begin_location_change, but we don't want the
diff --git a/src/nautilus-window-slot.c b/src/nautilus-window-slot.c
index 7ff816a3c..bd8bc6dc6 100644
--- a/src/nautilus-window-slot.c
+++ b/src/nautilus-window-slot.c
@@ -826,23 +826,6 @@ nautilus_window_slot_clear_back_list (NautilusWindowSlot *slot)
slot->back_list = NULL;
}
-gboolean
-nautilus_window_slot_should_close_with_mount (NautilusWindowSlot *slot,
- GMount *mount)
-{
- GFile *mount_location;
- gboolean close_with_mount;
-
- mount_location = g_mount_get_root (mount);
- close_with_mount =
- g_file_has_prefix (NAUTILUS_WINDOW_SLOT (slot)->location, mount_location) ||
- g_file_equal (NAUTILUS_WINDOW_SLOT (slot)->location, mount_location);
-
- g_object_unref (mount_location);
-
- return close_with_mount;
-}
-
NautilusWindowSlot *
nautilus_window_slot_new (NautilusWindow *window)
{
diff --git a/src/nautilus-window-slot.h b/src/nautilus-window-slot.h
index ea91752eb..e7bd64d81 100644
--- a/src/nautilus-window-slot.h
+++ b/src/nautilus-window-slot.h
@@ -175,9 +175,6 @@ char * nautilus_window_slot_get_current_uri (NautilusWindowSlot *
NautilusWindow * nautilus_window_slot_get_window (NautilusWindowSlot *slot);
void nautilus_window_slot_make_hosting_window_active (NautilusWindowSlot *slot);
-gboolean nautilus_window_slot_should_close_with_mount (NautilusWindowSlot *slot,
- GMount *mount);
-
void nautilus_window_slot_clear_forward_list (NautilusWindowSlot *slot);
void nautilus_window_slot_clear_back_list (NautilusWindowSlot *slot);