nautilus r13619 - in trunk: . libnautilus-private



Author: alexl
Date: Fri Jan 18 11:31:28 2008
New Revision: 13619
URL: http://svn.gnome.org/viewvc/nautilus?rev=13619&view=rev

Log:
2008-01-18  Alexander Larsson  <alexl redhat com>

        * libnautilus-private/nautilus-file.[ch]:
        Add nautilus_file_get_activation_location.
	
        * libnautilus-private/nautilus-directory-async.c:
	Get mounts from mountable files too.
	



Modified:
   trunk/ChangeLog
   trunk/libnautilus-private/nautilus-directory-async.c
   trunk/libnautilus-private/nautilus-file.c
   trunk/libnautilus-private/nautilus-file.h

Modified: trunk/libnautilus-private/nautilus-directory-async.c
==============================================================================
--- trunk/libnautilus-private/nautilus-directory-async.c	(original)
+++ trunk/libnautilus-private/nautilus-directory-async.c	Fri Jan 18 11:31:28 2008
@@ -1730,9 +1730,21 @@
 static gboolean
 lacks_mount (NautilusFile *file)
 {
-	return (file->details->is_mountpoint ||
-		file->details->type == G_FILE_TYPE_MOUNTABLE) &&
-		!file->details->mount_is_up_to_date;
+	return (!file->details->mount_is_up_to_date &&
+		(
+		 /* Unix mountpoint, could be a GMount */
+		 file->details->is_mountpoint ||
+		 
+		 /* The toplevel directory of something */
+		 (file->details->type == G_FILE_TYPE_DIRECTORY &&
+		  nautilus_file_is_self_owned (file)) ||
+		 
+		 /* Mountable with a target_uri, could be a mountpoint */
+		 (file->details->type == G_FILE_TYPE_MOUNTABLE &&
+		  file->details->activation_location != NULL)
+
+		 )
+		);
 }
 
 static gboolean
@@ -3883,38 +3895,27 @@
 }
 
 static void
-find_enclosing_mount_callback (GObject *source_object,
-			       GAsyncResult *res,
-			       gpointer user_data)
+got_mount (MountState *state, GMount *mount)
 {
-	GMount *mount;
 	NautilusDirectory *directory;
-	MountState *state;
 	NautilusFile *file;
-
-	state = user_data;
-	if (state->directory == NULL) {
-		/* Operation was cancelled. Bail out */
-		mount_state_free (state);
-		return;
-	}
-
-	directory = nautilus_directory_ref (state->directory);
 	
-	mount = g_file_find_enclosing_mount_finish (G_FILE (source_object),
-						    res, NULL);
-
+	directory = nautilus_directory_ref (state->directory);
 
 	state->directory->details->mount_state = NULL;
 	async_job_end (state->directory, "mount");
 	
 	file = nautilus_file_ref (state->file);
-	
-	file->details->mount_is_up_to_date = TRUE;
+
 	if (file->details->mount) {
 		g_object_unref (file->details->mount);
+		file->details->mount = NULL;
+	}
+	
+	file->details->mount_is_up_to_date = TRUE;
+	if (mount) {
+		file->details->mount = g_object_ref (mount);
 	}
-	file->details->mount = mount;
 	
 	nautilus_directory_async_state_changed (directory);
 	nautilus_file_changed (file);
@@ -3928,6 +3929,73 @@
 }
 
 static void
+find_enclosing_mount_callback (GObject *source_object,
+			       GAsyncResult *res,
+			       gpointer user_data)
+{
+	GMount *mount;
+	MountState *state;
+	GFile *location, *root;
+
+	state = user_data;
+	if (state->directory == NULL) {
+		/* Operation was cancelled. Bail out */
+		mount_state_free (state);
+		return;
+	}
+
+	mount = g_file_find_enclosing_mount_finish (G_FILE (source_object),
+						    res, NULL);
+
+	if (mount) {
+		root = g_mount_get_root (mount);
+		location = nautilus_file_get_location (state->file);
+		if (!g_file_equal (location, root)) {
+			g_object_unref (mount);
+			mount = NULL;
+		}
+		g_object_unref (root);
+		g_object_unref (location);
+	}
+
+	got_mount (state, mount);
+
+	if (mount) {
+		g_object_unref (mount);
+	}
+}
+
+static GMount *
+get_mount_at (GFile *target)
+{
+	GVolumeMonitor *monitor;
+	GFile *root;
+	GList *mounts, *l;
+	GMount *found;
+	
+	monitor = g_volume_monitor_get ();
+	mounts = g_volume_monitor_get_mounts (monitor);
+
+	found = NULL;
+	for (l = mounts; l != NULL; l = l->next) {
+		root = g_mount_get_root (l->data);
+
+		if (g_file_equal (target, root)) {
+			found = g_object_ref (l->data);
+			break;
+		}
+		
+		g_object_unref (root);
+	}
+
+	eel_g_object_list_free (mounts);
+	
+	g_object_unref (monitor);
+
+	return found;
+}
+
+static void
 mount_start (NautilusDirectory *directory,
 	     NautilusFile *file,
 	     gboolean *doing_io)
@@ -3959,12 +4027,30 @@
 	location = nautilus_file_get_location (file);
 	
 	directory->details->mount_state = state;
-	
-	g_file_find_enclosing_mount_async (location,
-					   G_PRIORITY_DEFAULT,
-					   state->cancellable,
-					   find_enclosing_mount_callback,
-					   state);
+
+	if (file->details->type == G_FILE_TYPE_MOUNTABLE) {
+		GFile *target;
+		GMount *mount;
+
+		mount = NULL;
+		target = nautilus_file_get_activation_location (file);
+		if (target != NULL) {
+			mount = get_mount_at (target);
+			g_object_unref (target);
+		}
+
+		got_mount (state, mount);
+
+		if (mount) {
+			g_object_unref (mount);
+		}
+	} else {
+		g_file_find_enclosing_mount_async (location,
+						   G_PRIORITY_DEFAULT,
+						   state->cancellable,
+						   find_enclosing_mount_callback,
+						   state);
+	}
 	g_object_unref (location);
 }
 

Modified: trunk/libnautilus-private/nautilus-file.c
==============================================================================
--- trunk/libnautilus-private/nautilus-file.c	(original)
+++ trunk/libnautilus-private/nautilus-file.c	Fri Jan 18 11:31:28 2008
@@ -2996,6 +2996,18 @@
 	return nautilus_file_get_uri (file);
 }
 
+GFile *
+nautilus_file_get_activation_location (NautilusFile *file)
+{
+	g_return_val_if_fail (NAUTILUS_IS_FILE (file), NULL);
+
+	if (file->details->activation_location != NULL) {
+		return g_object_ref (file->details->activation_location);
+	}
+	
+	return nautilus_file_get_location (file);
+}
+
 
 char *
 nautilus_file_get_drop_target_uri (NautilusFile *file)

Modified: trunk/libnautilus-private/nautilus-file.h
==============================================================================
--- trunk/libnautilus-private/nautilus-file.h	(original)
+++ trunk/libnautilus-private/nautilus-file.h	Fri Jan 18 11:31:28 2008
@@ -369,6 +369,7 @@
  */
 gboolean                nautilus_file_has_activation_uri                (NautilusFile                   *file);
 char *                  nautilus_file_get_activation_uri                (NautilusFile                   *file);
+GFile *                 nautilus_file_get_activation_location           (NautilusFile                   *file);
 
 char *                  nautilus_file_get_drop_target_uri               (NautilusFile                   *file);
 



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