[nautilus] slot: use the default mount location when switching to a mount root



commit 3d3382add4ad387bb05425ba09d9dcbf5ee5314b
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Fri Oct 26 14:26:04 2012 -0400

    slot: use the default mount location when switching to a mount root
    
    Add a new flag to signal that we really want the default mount location
    to be loaded if possible. This way we can still get to the mount root
    e.g. by going up or typing it directly in the location bar, but the
    default location between sidebar mounts and using Connect to Server will
    be the same.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=522917

 src/nautilus-application.c |   13 ++++++-------
 src/nautilus-window-slot.c |   43 +++++++++++++++++++++++++++++++++++++++----
 src/nautilus-window.h      |    4 +++-
 3 files changed, 48 insertions(+), 12 deletions(-)
---
diff --git a/src/nautilus-application.c b/src/nautilus-application.c
index faa403b..b84c437 100644
--- a/src/nautilus-application.c
+++ b/src/nautilus-application.c
@@ -705,10 +705,10 @@ action_new_window (GSimpleAction *action,
 
 static gboolean
 go_to_server_cb (NautilusWindow *window,
+		 GFile          *location,
 		 GError         *error,
 		 gpointer        user_data)
 {
-	GFile *location = user_data;
 	gboolean retval;
 
 	if (error == NULL) {
@@ -760,8 +760,6 @@ go_to_server_cb (NautilusWindow *window,
 		retval = FALSE;
 	}
 
-	g_object_unref (location);
-
 	return retval;
 }
 
@@ -772,13 +770,14 @@ on_connect_server_response (GtkDialog      *dialog,
 {
 	if (response == GTK_RESPONSE_OK) {
 		GFile *location;
+		NautilusWindow *window = NAUTILUS_WINDOW (get_focus_window (application));
 
 		location = nautilus_connect_server_dialog_get_location (NAUTILUS_CONNECT_SERVER_DIALOG (dialog));
 		if (location != NULL) {
-			nautilus_window_go_to_full (NAUTILUS_WINDOW (get_focus_window (application)),
-						    location,
-						    go_to_server_cb,
-						    location);
+			nautilus_window_slot_open_location_full (nautilus_window_get_active_slot (window),
+								 location,
+								 NAUTILUS_WINDOW_OPEN_FLAG_USE_DEFAULT_LOCATION,
+								 NULL, go_to_server_cb, application);
 		}
 	}
 
diff --git a/src/nautilus-window-slot.c b/src/nautilus-window-slot.c
index 8b32be9..0e6321e 100644
--- a/src/nautilus-window-slot.c
+++ b/src/nautilus-window-slot.c
@@ -120,6 +120,7 @@ struct NautilusWindowSlotDetails {
 	guint location_change_distance;
 	char *pending_scroll_to;
 	GList *pending_selection;
+	gboolean pending_use_default_location;
 	NautilusFile *determine_view_file;
 	GCancellable *mount_cancellable;
 	GError *mount_error;
@@ -768,12 +769,13 @@ nautilus_window_slot_open_location_full (NautilusWindowSlot *slot,
 	    !is_desktop) {
 
 		if (callback != NULL) {
-			callback (window, NULL, user_data);
+			callback (window, location, NULL, user_data);
 		}
 
 		goto done;
         }
 
+	slot->details->pending_use_default_location = ((flags & NAUTILUS_WINDOW_OPEN_FLAG_USE_DEFAULT_LOCATION) != 0);
         begin_location_change (target_slot, location, old_location, new_selection,
 			       NAUTILUS_LOCATION_CHANGE_STANDARD, 0, NULL, callback, user_data);
 
@@ -788,6 +790,7 @@ report_callback (NautilusWindowSlot *slot,
 	if (slot->details->open_callback != NULL) {
 		gboolean res;
 		res = slot->details->open_callback (nautilus_window_slot_get_window (slot),
+						    slot->details->pending_location,
 						    error, slot->details->open_callback_user_data);
 		slot->details->open_callback = NULL;
 		slot->details->open_callback_user_data = NULL;
@@ -1083,7 +1086,8 @@ mount_not_mounted_callback (GObject *source_object,
 	} else {
 		nautilus_file_invalidate_all_attributes (slot->details->determine_view_file);
 		nautilus_file_call_when_ready (slot->details->determine_view_file,
-					       NAUTILUS_FILE_ATTRIBUTE_INFO,
+					       NAUTILUS_FILE_ATTRIBUTE_INFO |
+					       NAUTILUS_FILE_ATTRIBUTE_MOUNT,
 					       got_file_info_for_view_selection_callback,
 					       slot);
 	}
@@ -1101,10 +1105,11 @@ got_file_info_for_view_selection_callback (NautilusFile *file,
 	NautilusWindow *window;
 	NautilusWindowSlot *slot;
 	NautilusFile *viewed_file, *parent_file;
-	GFile *location;
+	GFile *location, *default_location;
 	GMountOperation *mount_op;
 	MountNotMountedData *data;
 	GtkApplication *app;
+	GMount *mount;
 
 	slot = callback_data;
 	window = nautilus_window_slot_get_window (slot);
@@ -1139,6 +1144,35 @@ got_file_info_for_view_selection_callback (NautilusFile *file,
 		goto done;
 	}
 
+	mount = NULL;
+	default_location = NULL;
+
+	if (slot->details->pending_use_default_location) {
+		mount = nautilus_file_get_mount (file);
+		slot->details->pending_use_default_location = FALSE;
+	}
+
+	if (mount != NULL) {
+		default_location = g_mount_get_default_location (mount);
+		g_object_unref (mount);
+	}
+
+	if (default_location != NULL &&
+	    !g_file_equal (slot->details->pending_location, default_location)) {
+		g_clear_object (&slot->details->pending_location);
+		slot->details->pending_location = default_location;
+		slot->details->determine_view_file = nautilus_file_get (default_location);
+
+		nautilus_file_invalidate_all_attributes (slot->details->determine_view_file);
+		nautilus_file_call_when_ready (slot->details->determine_view_file,
+					       NAUTILUS_FILE_ATTRIBUTE_INFO |
+					       NAUTILUS_FILE_ATTRIBUTE_MOUNT,
+					       got_file_info_for_view_selection_callback,
+					       slot);
+
+		goto done;
+	}
+
 	parent_file = nautilus_file_get_parent (file);
 	if ((parent_file != NULL) &&
 	    nautilus_file_get_file_type (file) == G_FILE_TYPE_REGULAR) {
@@ -1156,7 +1190,8 @@ got_file_info_for_view_selection_callback (NautilusFile *file,
 
 		nautilus_file_invalidate_all_attributes (slot->details->determine_view_file);
 		nautilus_file_call_when_ready (slot->details->determine_view_file,
-					       NAUTILUS_FILE_ATTRIBUTE_INFO,
+					       NAUTILUS_FILE_ATTRIBUTE_INFO |
+					       NAUTILUS_FILE_ATTRIBUTE_MOUNT,
 					       got_file_info_for_view_selection_callback,
 					       slot);
 
diff --git a/src/nautilus-window.h b/src/nautilus-window.h
index 3dc343f..2472998 100644
--- a/src/nautilus-window.h
+++ b/src/nautilus-window.h
@@ -41,7 +41,8 @@ typedef struct NautilusWindowDetails NautilusWindowDetails;
 typedef enum {
         NAUTILUS_WINDOW_OPEN_FLAG_CLOSE_BEHIND = 1 << 0,
         NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW = 1 << 1,
-        NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB = 1 << 2
+        NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB = 1 << 2,
+        NAUTILUS_WINDOW_OPEN_FLAG_USE_DEFAULT_LOCATION = 1 << 3
 } NautilusWindowOpenFlags;
 
 typedef enum {
@@ -50,6 +51,7 @@ typedef enum {
 }  NautilusWindowOpenSlotFlags;
 
 typedef gboolean (* NautilusWindowGoToCallback) (NautilusWindow *window,
+                                                 GFile *location,
                                                  GError *error,
                                                  gpointer user_data);
 



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