[Nautilus-list] Those pesky stats of .directory



The following patch reduces stat()s of ".directory" files from 1005 to
186 for me. When starting up nautilus and exiting. It's clear that
still more improvement is possible because only 28 unique .directory
files get statted. Red Hat guys, should I check this in now or wait
until after you ship? I think this is critical to get in before
landing patches on the mainline. I also have further improvements in
mind which should fix the icon factory case and improve this even
more.

Regards,

Maciej


Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/nautilus/ChangeLog,v
retrieving revision 1.4691.2.32
diff -u -r1.4691.2.32 ChangeLog
--- ChangeLog	2001/08/18 00:14:42	1.4691.2.32
+++ ChangeLog	2001/08/18 01:43:07
@@ -1,3 +1,65 @@
+2001-08-17  Maciej Stachowiak  <mjs noisehavoc org>
+
+	* libnautilus-private/nautilus-file-attributes.h: Add
+	NAUTILUS_FILE_CUSTOM_NAME attribute.
+
+	* libnautilus-private/nautilus-directory-private.h,
+	libnautilus-private/nautilus-directory-async.c:
+	(custom_name_cancel), (nautilus_directory_set_up_request),
+	(nautilus_async_destroying_file), (lacks_custom_name),
+	(wants_custom_name), (request_is_satisfied), (custom_name_done),
+	(custom_name_read_done),
+	(custom_name_nautilus_link_read_callback),
+	(get_custom_name_for_gmc_link), (make_dot_directory_uri),
+	(custom_name_start), (start_or_stop_io),
+	(nautilus_directory_cancel), (cancel_custom_name_for_file),
+	(cancel_loading_attributes),
+	(nautilus_directory_cancel_loading_file_attributes): Changes to
+	get the custom name out of a .desktop style link asynchronously
+	and with caching.
+
+	* libnautilus-private/nautilus-file-private.h,
+	libnautilus-private/nautilus-file.c: (destroy),
+	(nautilus_file_get_name), (invalidate_custom_name),
+	(nautilus_file_invalidate_attributes_internal),
+	(nautilus_file_get_all_attributes): Handle new custom_name
+	attribute properly.
+
+	* libnautilus-private/nautilus-link.h,
+	libnautilus-private/nautilus-link.c:
+	(nautilus_link_get_link_uri_given_file_contents): Fix to work for
+	classic nautilus links.
+	(nautilus_link_get_link_name_given_file_contents): New call to get
+	a custom name given link contents. (Actually does nothing for
+	old-style nautilus links).
+	* libnautilus-private/nautilus-link-impl-desktop.h,
+	libnautilus-private/nautilus-link-impl-desktop.c:
+	(nautilus_link_impl_desktop_get_link_name_from_desktop,
+	nautilus_link_impl_desktop_get_link_name_given_file_contents):
+	Implement the above for .desktop files.
+
+	* components/tree/nautilus-tree-model.c:
+	(nautilus_tree_model_monitor_add,
+	nautilus_tree_model_node_begin_monitoring_no_connect): Monitor
+	custom_name and attributes required by icon factory.
+	
+	* src/file-manager/fm-directory-view.c (finish_loading): Monitor
+	custom name attribute.
+
+	* src/file-manager/fm-properties-window.c
+	(create_properties_window): Monitor custom name attribute.
+	
+	* src/file-manager/fm-search-list-view.c (real_adding_file):
+	Monitor custom name attribute.
+
+	* src/nautilus-window-manage-views.c
+	(viewed_file_changed_callback): Always update title even if URI
+	did not change because custom name may have changed or just been
+	retrieved.
+
+	* src/nautilus-window.c: (nautilus_window_set_viewed_file):
+	Monitor custom name attribute,
+
 2001-08-17  Alex Larsson  <alexl redhat com>
 
 	* libnautilus-private/nautilus-file.c (prepend_automatic_emblem_names):
Index: components/tree/nautilus-tree-model.c
===================================================================
RCS file: /cvs/gnome/nautilus/components/tree/nautilus-tree-model.c,v
retrieving revision 1.49
diff -u -r1.49 nautilus-tree-model.c
--- components/tree/nautilus-tree-model.c	2001/07/05 23:16:52	1.49
+++ components/tree/nautilus-tree-model.c	2001/08/18 01:43:08
@@ -30,6 +30,7 @@
 #include <gtk/gtksignal.h>
 #include <libgnomevfs/gnome-vfs.h>
 #include <libnautilus-private/nautilus-file-attributes.h>
+#include <libnautilus-private/nautilus-icon-factory.h>
 #include <eel/eel-glib-extensions.h>
 #include <eel/eel-gtk-macros.h>
 #include <stdio.h>
@@ -327,8 +328,10 @@
 			 "changed",
 			 nautilus_tree_model_root_node_file_monitor,
 			 model);
-		
-		monitor_attributes = g_list_prepend (NULL, NAUTILUS_FILE_ATTRIBUTE_IS_DIRECTORY);
+
+		monitor_attributes = nautilus_icon_factory_get_required_file_attributes ();
+		monitor_attributes = g_list_prepend (monitor_attributes, NAUTILUS_FILE_ATTRIBUTE_IS_DIRECTORY);
+		monitor_attributes = g_list_prepend (monitor_attributes, NAUTILUS_FILE_ATTRIBUTE_CUSTOM_NAME);
 		nautilus_file_monitor_add (nautilus_tree_node_get_file (model->details->root_node),
 					   model,
 					   monitor_attributes);
@@ -411,8 +414,10 @@
 	if (force_reload) {
 		nautilus_directory_force_reload (directory);
 	}
-
-	monitor_attributes = g_list_prepend (NULL, NAUTILUS_FILE_ATTRIBUTE_IS_DIRECTORY);
+	
+	monitor_attributes = nautilus_icon_factory_get_required_file_attributes ();
+	monitor_attributes = g_list_prepend (monitor_attributes, NAUTILUS_FILE_ATTRIBUTE_IS_DIRECTORY);
+	monitor_attributes = g_list_prepend (monitor_attributes, NAUTILUS_FILE_ATTRIBUTE_CUSTOM_NAME);
 	nautilus_directory_file_monitor_add (directory,
 					     model,
 					     TRUE, TRUE,
Index: libnautilus-private/nautilus-directory-async.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-directory-async.c,v
retrieving revision 1.158
diff -u -r1.158 nautilus-directory-async.c
--- libnautilus-private/nautilus-directory-async.c	2001/07/05 23:16:53	1.158
+++ libnautilus-private/nautilus-directory-async.c	2001/08/18 01:43:08
@@ -38,6 +38,8 @@
 #include <ctype.h>
 #include <gnome-xml/parser.h>
 #include <gnome-xml/xmlmemory.h>
+#include <libgnome/gnome-metadata.h>
+#include <libgnome/gnome-mime-info.h>
 #include <gtk/gtkmain.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -73,6 +75,11 @@
 	EelReadFileHandle *handle;
 };
 
+struct CustomNameReadState {
+	NautilusFile *file;
+	EelReadFileHandle *handle;
+};
+
 typedef struct {
 	NautilusFile *file; /* Which file, NULL means all. */
 	union {
@@ -388,6 +395,19 @@
 }
 
 static void
+custom_name_cancel (NautilusDirectory *directory)
+{
+	if (directory->details->custom_name_read_state != NULL) {
+		eel_read_file_cancel (directory->details->custom_name_read_state->handle);
+		g_free (directory->details->custom_name_read_state);
+		directory->details->custom_name_read_state = NULL;
+
+		async_job_end (directory, "custom name");
+	}
+}
+
+
+static void
 file_info_cancel (NautilusDirectory *directory)
 {
 	if (directory->details->get_info_in_progress != NULL) {
@@ -538,6 +558,13 @@
 		request->file_info = TRUE;
 		request->activation_uri = TRUE;
 	}
+
+	if (g_list_find_custom (file_attributes,
+				NAUTILUS_FILE_ATTRIBUTE_CUSTOM_NAME,
+				eel_strcmp_compare_func) != NULL) {
+		request->file_info = TRUE;
+		request->custom_name = TRUE;
+	}
 	
 	request->metafile |= g_list_find_custom
 		(file_attributes,
@@ -1489,6 +1516,11 @@
 		directory->details->activation_uri_read_state->file = NULL;
 		changed = TRUE;
 	}
+	if (directory->details->custom_name_read_state != NULL
+	    && directory->details->custom_name_read_state->file == file) {
+		directory->details->custom_name_read_state->file = NULL;
+		changed = TRUE;
+	}
 
 	/* Let the directory take care of the rest. */
 	if (changed) {
@@ -1590,7 +1622,22 @@
 	return request->activation_uri;
 }
 
+static gboolean
+lacks_custom_name (NautilusFile *file)
+{
+	return file->details->info != NULL
+		&& !file->details->custom_name_is_up_to_date
+		&& nautilus_file_is_local (file);
+}
+
+static gboolean
+wants_custom_name (const Request *request)
+{
+	return request->custom_name;
+}
+
 
+
 static gboolean
 has_problem (NautilusDirectory *directory, NautilusFile *file, FileCheck problem)
 {
@@ -1659,6 +1706,12 @@
 		}
 	}
 
+	if (request->custom_name) {
+		if (has_problem (directory, file, lacks_custom_name)) {
+			return FALSE;
+		}
+	}
+
 	return TRUE;
 }
 
@@ -2867,7 +2920,198 @@
 	}
 }
 
+
+static void
+custom_name_done (NautilusDirectory *directory,
+		     NautilusFile *file,
+		     const char *name)
+{
+	file->details->custom_name_is_up_to_date = TRUE;
+
+	file->details->got_custom_name = TRUE;
+	g_free (file->details->custom_name);
+	file->details->custom_name = g_strdup (name);
+
+	nautilus_file_changed (file);
+
+	async_job_end (directory, "custom name");
+	nautilus_directory_async_state_changed (directory);
+}
+
+static void
+custom_name_read_done (NautilusDirectory *directory,
+		       const char *name)
+{
+	NautilusFile *file;
+
+	file = directory->details->custom_name_read_state->file;
+	g_free (directory->details->custom_name_read_state);
+	directory->details->custom_name_read_state = NULL;
+
+	custom_name_done (directory, file, name);
+}
+
+static void
+custom_name_nautilus_link_read_callback (GnomeVFSResult result,
+					GnomeVFSFileSize bytes_read,
+					char *file_contents,
+					gpointer callback_data)
+{
+	NautilusDirectory *directory;
+	char *buffer, *name;
+
+	directory = NAUTILUS_DIRECTORY (callback_data);
+
+	nautilus_directory_ref (directory);
+
+	/* Handle the case where we read the Nautilus link. */
+	if (result != GNOME_VFS_OK) {
+		/* FIXME bugzilla.eazel.com 2433: We should report this error to the user. */
+		g_free (file_contents);
+		name = NULL;
+	} else {
+		/* The gnome-xml parser requires a zero-terminated array. */
+		buffer = g_realloc (file_contents, bytes_read + 1);
+		buffer[bytes_read] = '\0';
+                name = nautilus_link_get_link_name_given_file_contents (buffer, bytes_read);
+		g_free (buffer);
+	}
+
+	custom_name_read_done (directory, name);
+	g_free (name);
+
+	nautilus_directory_unref (directory);
+}
+
+
 static void
+get_custom_name_for_gmc_link (NautilusDirectory *directory,
+			      NautilusFile *file,
+			      const char *uri)
+{
+	char *caption;
+	int size, res;
+	char *path; 
+	
+	path = gnome_vfs_get_local_path_from_uri (uri);
+	
+	if (path != NULL) {
+		/* FIXME: this gnome_metata_get call is synchronous, but better to
+		 * have it here where the results will at least be cached than in
+		 * nautilus_file_get_name. 
+		 */
+		res = gnome_metadata_get (path, "icon-caption", &size, &caption);
+	} else {
+		res = -1;
+	}
+	
+	g_free (path);
+	
+	if (res == 0) {
+		custom_name_done (directory, file, caption);
+	} else {
+		custom_name_done (directory, file, NULL);
+	}
+}
+
+
+static char *
+make_dot_directory_uri (const char *uri)
+{
+	char *dot_directory_uri;
+	GnomeVFSURI *vfs_uri;
+	GnomeVFSURI *dot_dir_vfs_uri;
+	
+	/* FIXME: what we really need is a uri_append_file_name call
+	 * that works on strings, so we can avoid the VFS parsing step.
+	 */
+
+	vfs_uri = gnome_vfs_uri_new (uri);
+	dot_dir_vfs_uri = gnome_vfs_uri_append_file_name (vfs_uri, ".directory");
+	dot_directory_uri = gnome_vfs_uri_to_string (dot_dir_vfs_uri, GNOME_VFS_URI_HIDE_NONE);
+	
+	gnome_vfs_uri_unref (vfs_uri);
+	gnome_vfs_uri_unref (dot_dir_vfs_uri);
+
+	return dot_directory_uri;
+}
+
+static void
+custom_name_start (NautilusDirectory *directory)
+{
+	NautilusFile *file;
+	char *mime_type, *uri, *dot_directory_uri;
+	gboolean gmc_style_link, nautilus_style_link, is_directory;
+
+	/* If there's already a custom name read in progress, check
+	 * to be sure it's still wanted.  */
+	if (directory->details->custom_name_read_state != NULL) {
+		file = directory->details->custom_name_read_state->file;
+		if (file != NULL) {
+			g_assert (NAUTILUS_IS_FILE (file));
+			g_assert (file->details->directory == directory);
+			if (is_needy (file,
+				      lacks_custom_name,
+				      wants_custom_name)) {
+				return;
+			}
+		}
+
+		/* The count is not wanted, so stop it. */
+		custom_name_cancel (directory);
+	}
+
+	/* Figure out which file to get custom_name for. */
+	file = select_needy_file (directory,
+				  lacks_custom_name,
+				  wants_custom_name);
+	if (file == NULL) {
+		return;
+	}
+
+	if (!async_job_start (directory, "custom name")) {
+		return;
+	}
+
+	/* Figure out if it is a link. */
+	mime_type = nautilus_file_get_mime_type (file);
+	gmc_style_link = eel_strcasecmp (mime_type, "application/x-gmc-link") == 0
+		&& nautilus_file_is_in_desktop (file);
+	g_free (mime_type);
+	nautilus_style_link = nautilus_file_is_nautilus_link (file);
+        is_directory = nautilus_file_is_directory (file);
+	
+	/* If it's not a link we are done. If it is, we need to read it. */
+	if (!(gmc_style_link || nautilus_style_link || is_directory)) {
+		custom_name_done (directory, file, NULL);
+	} else {
+		directory->details->custom_name_read_state = g_new0 (CustomNameReadState, 1);
+		directory->details->custom_name_read_state->file = file;
+		uri = nautilus_file_get_uri (file);
+		if (gmc_style_link) {
+		        get_custom_name_for_gmc_link (directory, file, uri);
+			g_free (uri);
+		} else if (is_directory) {
+			dot_directory_uri = make_dot_directory_uri (uri);
+
+			directory->details->custom_name_read_state->handle = eel_read_entire_file_async
+				(dot_directory_uri,
+				 custom_name_nautilus_link_read_callback,
+				 directory);
+			
+			g_free (dot_directory_uri);
+		} else {
+			directory->details->custom_name_read_state->handle = eel_read_entire_file_async
+				(uri,
+				 custom_name_nautilus_link_read_callback,
+				 directory);
+		}
+		g_free (uri);
+	}
+}
+
+
+static void
 start_or_stop_io (NautilusDirectory *directory)
 {
 	/* Start or stop getting file info. */
@@ -2890,6 +3134,11 @@
 	 * reading the contents of Nautilus and GMC link files.
 	 */
 	activation_uri_start (directory);
+
+	/* Start or stop getting custom names, which includes
+	 * reading the contents of .desktop and .directory files
+	 */
+	custom_name_start (directory);
 }
 
 /* Call this when the monitor or call when ready list changes,
@@ -2940,6 +3189,7 @@
 	file_list_cancel (directory);
 	mime_list_cancel (directory);
 	top_left_cancel (directory);
+	custom_name_cancel (directory);
 
 	/* We aren't waiting for anything any more. */
 	if (waiting_directories != NULL) {
@@ -3007,6 +3257,16 @@
 }
 
 static void
+cancel_custom_name_for_file (NautilusDirectory *directory,
+			     NautilusFile      *file)
+{
+	if (directory->details->custom_name_read_state != NULL &&
+	    directory->details->custom_name_read_state->file == file) {
+		custom_name_cancel (directory);
+	}
+}
+
+static void
 cancel_loading_attributes (NautilusDirectory *directory,
 			   GList *file_attributes)
 {
@@ -3031,8 +3291,11 @@
 		file_info_cancel (directory);
 	}
 	if (request.activation_uri) {
-		file_info_cancel (directory);
+		activation_uri_cancel (directory);
 	}
+	if (request.custom_name) {
+		custom_name_cancel (directory);
+	}
 	
 	/* FIXME bugzilla.eazel.com 5064: implement cancelling metadata when we
 	   implement invalidating metadata */
@@ -3067,6 +3330,9 @@
 	}
 	if (request.activation_uri) {
 		cancel_activation_uri_for_file (directory, file);
+	}
+	if (request.custom_name) {
+		cancel_custom_name_for_file (directory, file);
 	}
 
 	/* FIXME bugzilla.eazel.com 5064: implement cancelling metadata when we
Index: libnautilus-private/nautilus-directory-private.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-directory-private.h,v
retrieving revision 1.82
diff -u -r1.82 nautilus-directory-private.h
--- libnautilus-private/nautilus-directory-private.h	2001/07/07 09:19:14	1.82
+++ libnautilus-private/nautilus-directory-private.h	2001/08/18 01:43:08
@@ -37,6 +37,7 @@
 
 typedef struct ActivationURIReadState ActivationURIReadState;
 typedef struct TopLeftTextReadState TopLeftTextReadState;
+typedef struct CustomNameReadState CustomNameReadState;
 typedef struct FileMonitors FileMonitors;
 
 struct NautilusDirectoryDetails
@@ -98,6 +99,7 @@
 
 	TopLeftTextReadState *top_left_read_state;
 	ActivationURIReadState *activation_uri_read_state;
+	CustomNameReadState *custom_name_read_state;
 
 	GList *file_operations_in_progress; /* list of FileOperation * */
 };
@@ -112,6 +114,7 @@
 	gboolean metafile;
 	gboolean mime_list;
 	gboolean top_left_text;
+	gboolean custom_name;
 } Request;
 
 NautilusDirectory *nautilus_directory_get_existing                    (const char                *uri);
Index: libnautilus-private/nautilus-file-attributes.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-file-attributes.h,v
retrieving revision 1.15
diff -u -r1.15 nautilus-file-attributes.h
--- libnautilus-private/nautilus-file-attributes.h	2000/12/07 01:55:37	1.15
+++ libnautilus-private/nautilus-file-attributes.h	2001/08/18 01:43:08
@@ -29,16 +29,17 @@
  * interest in changes to the attributes or when waiting for them.
  */
 
-#define NAUTILUS_FILE_ATTRIBUTE_ACTIVATION_URI             "activation URI"
-#define NAUTILUS_FILE_ATTRIBUTE_CAPABILITIES               "capabilities"
-#define NAUTILUS_FILE_ATTRIBUTE_CUSTOM_ICON                "custom icon"
-#define NAUTILUS_FILE_ATTRIBUTE_DEEP_COUNTS                "deep counts"
-#define NAUTILUS_FILE_ATTRIBUTE_DIRECTORY_ITEM_COUNT       "directory item count"
-#define NAUTILUS_FILE_ATTRIBUTE_DIRECTORY_ITEM_MIME_TYPES  "directory item MIME types"
-#define NAUTILUS_FILE_ATTRIBUTE_FILE_TYPE                  "file type"
-#define NAUTILUS_FILE_ATTRIBUTE_IS_DIRECTORY               "is directory"
-#define NAUTILUS_FILE_ATTRIBUTE_METADATA                   "metadata"
-#define NAUTILUS_FILE_ATTRIBUTE_MIME_TYPE                  "MIME type"
-#define NAUTILUS_FILE_ATTRIBUTE_TOP_LEFT_TEXT              "top left text"
+#define NAUTILUS_FILE_ATTRIBUTE_ACTIVATION_URI              "activation URI"
+#define NAUTILUS_FILE_ATTRIBUTE_CAPABILITIES                "capabilities"
+#define NAUTILUS_FILE_ATTRIBUTE_CUSTOM_ICON                 "custom icon"
+#define NAUTILUS_FILE_ATTRIBUTE_DEEP_COUNTS                 "deep counts"
+#define NAUTILUS_FILE_ATTRIBUTE_DIRECTORY_ITEM_COUNT        "directory item count"
+#define NAUTILUS_FILE_ATTRIBUTE_DIRECTORY_ITEM_MIME_TYPES   "directory item MIME types"
+#define NAUTILUS_FILE_ATTRIBUTE_FILE_TYPE                   "file type"
+#define NAUTILUS_FILE_ATTRIBUTE_IS_DIRECTORY                "is directory"
+#define NAUTILUS_FILE_ATTRIBUTE_METADATA                    "metadata"
+#define NAUTILUS_FILE_ATTRIBUTE_MIME_TYPE                   "MIME type"
+#define NAUTILUS_FILE_ATTRIBUTE_TOP_LEFT_TEXT               "top left text"
+#define NAUTILUS_FILE_ATTRIBUTE_CUSTOM_NAME                 "custom name"
 
 #endif /* NAUTILUS_FILE_ATTRIBUTES_H */
Index: libnautilus-private/nautilus-file-private.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-file-private.h,v
retrieving revision 1.36
diff -u -r1.36 nautilus-file-private.h
--- libnautilus-private/nautilus-file-private.h	2001/04/16 23:02:23	1.36
+++ libnautilus-private/nautilus-file-private.h	2001/08/18 01:43:08
@@ -49,6 +49,7 @@
 {
 	NautilusDirectory *directory;
 	char *relative_uri;
+	char *custom_name;
 
 	GnomeVFSFileInfo *info;
 	GnomeVFSResult get_info_error;
@@ -108,6 +109,9 @@
 
 	eel_boolean_bit got_activation_uri            : 1;
 	eel_boolean_bit activation_uri_is_up_to_date  : 1;
+
+	eel_boolean_bit got_custom_name               : 1;
+	eel_boolean_bit custom_name_is_up_to_date     : 1;
 };
 
 NautilusFile *nautilus_file_new_from_info                  (NautilusDirectory      *directory,
Index: libnautilus-private/nautilus-file.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-file.c,v
retrieving revision 1.249.2.6
diff -u -r1.249.2.6 nautilus-file.c
--- libnautilus-private/nautilus-file.c	2001/08/15 19:05:27	1.249.2.6
+++ libnautilus-private/nautilus-file.c	2001/08/18 01:43:09
@@ -51,7 +51,6 @@
 #include <libgnome/gnome-dentry.h>
 #include <libgnome/gnome-i18n.h>
 #include <libgnome/gnome-metadata.h>
-#include <libgnome/gnome-mime-info.h>
 #include <libgnome/gnome-mime.h>
 #include <libgnomevfs/gnome-vfs-file-info.h>
 #include <libgnomevfs/gnome-vfs-mime-handlers.h>
@@ -449,6 +448,7 @@
 		gnome_vfs_file_info_unref (file->details->info);
 	}
 	g_free (file->details->top_left_text);
+	g_free (file->details->custom_name);
 	g_free (file->details->activation_uri);
 	g_free (file->details->compare_by_emblem_cache);
 	
@@ -2254,77 +2254,20 @@
 }
 
 
-
-
 char *
 nautilus_file_get_name (NautilusFile *file)
 {
 	char *name;
-	char *path, *uri;
-	char *caption;
-	int size, res;
 
 	if (file == NULL) {
 		return NULL;
 	}
 	g_return_val_if_fail (NAUTILUS_IS_FILE (file), NULL);
-
-	 
-	/* handle .desktop files */
-	if (nautilus_file_is_mime_type (file, "application/x-gnome-app-info")) {
-		uri = nautilus_file_get_uri (file);
 
-		name = NULL;
-		if (nautilus_file_is_local (file)) {
-			name = nautilus_link_impl_desktop_local_get_text (uri);
-		}
-		
-		g_free (uri);
-		uri = NULL;
-		
-		if (name != NULL) {
-			return name;
-		}
-	}
-
-	/* honor .directory found inside a directory */
-	if (nautilus_file_is_directory (file) &&
-	    nautilus_file_is_local (file)) {
-		char *dot_dir_uri;
-		char *file_uri;
-		
-		file_uri = nautilus_file_get_uri (file);
-		dot_dir_uri = nautilus_make_path (file_uri, ".directory");
-		g_free (file_uri);
-		
-		name = nautilus_link_impl_desktop_local_get_text (dot_dir_uri);
-		g_free (dot_dir_uri);
-
-		if (name != NULL)
-			return name;
+	if (file->details->got_custom_name && file->details->custom_name != NULL) {
+		return g_strdup (file->details->custom_name);
 	}
 	
-	/* Desktop directories contain special "URL" files, handle
-	 * those by using the gnome metadata caption.
-	 */
-	if (nautilus_file_is_gmc_url (file)) {
-		uri = nautilus_file_get_uri (file);
-		path = gnome_vfs_get_local_path_from_uri (uri);
-
-		if (path != NULL) {
-			res = gnome_metadata_get (path, "icon-caption", &size, &caption);
-		} else {
-			res = -1;
-		}
-		
-		g_free (path);
-		g_free (uri);
-
-		if (res == 0 && caption != NULL) {
-			return caption;
-		}
-	}
-
 	name = gnome_vfs_unescape_string (file->details->relative_uri, "/");
 	if (name != NULL) {
 		return name;
@@ -4877,6 +4820,11 @@
 	file->details->activation_uri_is_up_to_date = FALSE;
 }
 
+static void
+invalidate_custom_name (NautilusFile *file)
+{
+	file->details->custom_name_is_up_to_date = FALSE;
+}
 
 void
 nautilus_file_invalidate_attributes_internal (NautilusFile *file,
@@ -4908,6 +4856,9 @@
 	if (request.activation_uri) {
 		invalidate_activation_uri (file);
 	}
+	if (request.custom_name) {
+		invalidate_custom_name (file);
+	}
 
 	/* FIXME bugzilla.eazel.com 5075: implement invalidating metadata */
 }
@@ -4955,6 +4906,7 @@
         attributes = g_list_prepend (attributes, NAUTILUS_FILE_ATTRIBUTE_METADATA);
         attributes = g_list_prepend (attributes, NAUTILUS_FILE_ATTRIBUTE_MIME_TYPE);
         attributes = g_list_prepend (attributes, NAUTILUS_FILE_ATTRIBUTE_TOP_LEFT_TEXT);
+        attributes = g_list_prepend (attributes, NAUTILUS_FILE_ATTRIBUTE_CUSTOM_NAME);
 
 	return attributes;
 }
Index: libnautilus-private/nautilus-link-impl-desktop.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/Attic/nautilus-link-impl-desktop.c,v
retrieving revision 1.1.2.8
diff -u -r1.1.2.8 nautilus-link-impl-desktop.c
--- libnautilus-private/nautilus-link-impl-desktop.c	2001/08/09 01:06:59	1.1.2.8
+++ libnautilus-private/nautilus-link-impl-desktop.c	2001/08/18 01:43:09
@@ -1,3 +1,4 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
 #include <config.h>
 #include "nautilus-link.h"
 #include "nautilus-link-impl-desktop.h"
@@ -185,8 +186,9 @@
 
 	contents = slurp_uri_contents (path);
 
-	if (contents == NULL)
+	if (contents == NULL) {
 		return NULL;
+	}
 	desktop_file = desktop_file_from_string (contents);
 	g_free (contents);
 
@@ -498,6 +500,23 @@
 	return retval;
 }
 
+static gchar *
+nautilus_link_impl_desktop_get_link_name_from_desktop (DesktopFile *desktop_file)
+{
+	gchar *name;
+
+	name = NULL;
+
+	if (desktop_file_get_string (desktop_file,
+				     "Desktop Entry",
+				     "Name",
+				     &name)) {
+	         return name;
+	} else {
+	         return NULL;
+	}
+}
+
 
 char *
 nautilus_link_impl_desktop_local_get_link_uri (const char *path)
@@ -537,8 +556,28 @@
 
 	desktop_file_free (desktop_file);
 	return retval;
-	
 }
+
+char *
+nautilus_link_impl_desktop_get_link_name_given_file_contents (const char *link_file_contents,
+							      int         link_file_size)
+{
+	DesktopFile *desktop_file;
+	gchar *slurp;
+	gchar *retval;
+
+	slurp = g_strndup (link_file_contents, link_file_size);
+	desktop_file = desktop_file_from_string (slurp);
+	g_free (slurp);
+	if (desktop_file == NULL) {
+		return NULL; 
+	}
+	retval = nautilus_link_impl_desktop_get_link_name_from_desktop (desktop_file);
+
+	desktop_file_free (desktop_file);
+	return retval;
+}
+
 
 void
 nautilus_link_impl_desktop_local_create_from_gnome_entry    (GnomeDesktopEntry *entry,
Index: libnautilus-private/nautilus-link-impl-desktop.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/Attic/nautilus-link-impl-desktop.h,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 nautilus-link-impl-desktop.h
--- libnautilus-private/nautilus-link-impl-desktop.h	2001/07/24 18:57:12	1.1.2.1
+++ libnautilus-private/nautilus-link-impl-desktop.h	2001/08/18 01:43:09
@@ -53,6 +53,8 @@
 char *           nautilus_link_impl_desktop_local_get_link_uri               (const char        *path);
 char *           nautilus_link_impl_desktop_get_link_uri_given_file_contents (const char        *link_file_contents,
 									      int                link_file_size);
+char *           nautilus_link_impl_desktop_get_link_name_given_file_contents (const char        *link_file_contents,
+									       int                link_file_size);
 void             nautilus_link_impl_desktop_local_create_from_gnome_entry    (GnomeDesktopEntry *entry,
 									      const char        *dest_path,
 									      const GdkPoint    *position);
Index: libnautilus-private/nautilus-link.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-link.c,v
retrieving revision 1.57.2.4
diff -u -r1.57.2.4 nautilus-link.c
--- libnautilus-private/nautilus-link.c	2001/08/01 09:24:37	1.57.2.4
+++ libnautilus-private/nautilus-link.c	2001/08/18 01:43:09
@@ -235,17 +235,36 @@
 nautilus_link_get_link_uri_given_file_contents (const char *file_contents,
 						int file_size)
 {
-	//	const gchar *mime_type;
+	const gchar *mime_type;
 	gchar *retval;
 
-//	mime_type = get_uri_mime_type_full (file_contents);
+	mime_type = gnome_vfs_get_mime_type_for_data (file_contents, file_size);
 	retval = NULL;
 
-//	if (strcmp (mime_type, "application/x-nautilus-link") == 0) {
-//		retval = nautilus_link_impl_get_link_uri_given_file_contents (file_contents, file_size);
-//	} else if (strcmp (mime_type, "application/x-gnome-app-info") == 0) {
+	if (strcmp (mime_type, "application/x-nautilus-link") == 0) {
+		retval = nautilus_link_impl_get_link_uri_given_file_contents (file_contents, file_size);
+	} else if (strcmp (mime_type, "application/x-gnome-app-info") == 0) {
 		retval = nautilus_link_impl_desktop_get_link_uri_given_file_contents (file_contents, file_size);
-//	}
+	}
+
+	return retval;
+}
+
+char *
+nautilus_link_get_link_name_given_file_contents (const char *file_contents,
+						int file_size)
+{
+	const gchar *mime_type;
+	gchar *retval;
+
+	mime_type = gnome_vfs_get_mime_type_for_data (file_contents, file_size);
+	retval = NULL;
+
+	if (strcmp (mime_type, "application/x-nautilus-link") == 0) {
+		retval = NULL;
+	} else if (strcmp (mime_type, "application/x-gnome-app-info") == 0) {
+		retval = nautilus_link_impl_desktop_get_link_uri_given_file_contents (file_contents, file_size);
+	}
 
 	return retval;
 }
Index: libnautilus-private/nautilus-link.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-link.h,v
retrieving revision 1.19
diff -u -r1.19 nautilus-link.h
--- libnautilus-private/nautilus-link.h	2001/02/01 08:36:13	1.19
+++ libnautilus-private/nautilus-link.h	2001/08/18 01:43:09
@@ -115,7 +115,8 @@
 char *           nautilus_link_local_get_link_uri               (const char       *path);
 char *           nautilus_link_get_link_uri_given_file_contents (const char       *link_file_contents,
 								 int               link_file_size);
-
+char *           nautilus_link_get_link_name_given_file_contents (const char *file_contents,
+								  int file_size);
 void		nautilus_link_local_create_from_gnome_entry 	(GnomeDesktopEntry *entry,
 								 const char 	   *dest_path,
 								 const GdkPoint    *position);
Index: src/nautilus-window-manage-views.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-window-manage-views.c,v
retrieving revision 1.267
diff -u -r1.267 nautilus-window-manage-views.c
--- src/nautilus-window-manage-views.c	2001/06/26 23:51:52	1.267
+++ src/nautilus-window-manage-views.c	2001/08/18 01:43:09
@@ -523,10 +523,11 @@
                                 (NAUTILUS_NAVIGATION_BAR (window->navigation_bar),
                                  window->details->location);
 
-                        update_title (window);
                 } else {
                         g_free (new_location);
                 }
+
+                update_title (window);
         }
 }
 
Index: src/nautilus-window.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-window.c,v
retrieving revision 1.335
diff -u -r1.335 nautilus-window.c
--- src/nautilus-window.c	2001/06/01 16:27:19	1.335
+++ src/nautilus-window.c	2001/08/18 01:43:09
@@ -69,6 +69,7 @@
 #include <libnautilus-private/nautilus-bonobo-extensions.h>
 #include <libnautilus-private/nautilus-drag-window.h>
 #include <libnautilus-private/nautilus-file-utilities.h>
+#include <libnautilus-private/nautilus-file-attributes.h>
 #include <libnautilus-private/nautilus-global-preferences.h>
 #include <libnautilus-private/nautilus-horizontal-splitter.h>
 #include <libnautilus-private/nautilus-icon-factory.h>
@@ -2272,11 +2273,23 @@
 nautilus_window_set_viewed_file (NautilusWindow *window,
 				 NautilusFile *file)
 {
+	GList *attributes;
+
 	if (window->details->viewed_file == file) {
 		return;
 	}
 
+	if (window->details->viewed_file != NULL) {
+		nautilus_file_monitor_remove (window->details->viewed_file,
+					      window);
+	}
+
 	nautilus_file_ref (file);
+
+	attributes = g_list_prepend (NULL, NAUTILUS_FILE_ATTRIBUTE_CUSTOM_NAME);
+	nautilus_file_monitor_add (file, window, attributes);
+	g_list_free (attributes);
+
 	cancel_view_as_callback (window);
 	cancel_chose_component_callback (window);
 	nautilus_file_unref (window->details->viewed_file);
Index: src/file-manager/fm-directory-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-directory-view.c,v
retrieving revision 1.463.2.3
diff -u -r1.463.2.3 fm-directory-view.c
--- src/file-manager/fm-directory-view.c	2001/07/24 18:57:14	1.463.2.3
+++ src/file-manager/fm-directory-view.c	2001/08/18 01:43:10
@@ -4736,7 +4736,8 @@
 
 	/* Monitor the things needed to get the right icon. Also
 	 * monitor a directory's item count because the "size"
-	 * attribute is based on that, and the file's metadata.
+	 * attribute is based on that, and the file's metadata
+	 * and possible custom name.
 	 */
 	attributes = nautilus_icon_factory_get_required_file_attributes ();
 	attributes = g_list_prepend (attributes,
@@ -4745,6 +4746,8 @@
 				     NAUTILUS_FILE_ATTRIBUTE_METADATA);
 	attributes = g_list_prepend (attributes, 
 				     NAUTILUS_FILE_ATTRIBUTE_MIME_TYPE);
+	attributes = g_list_prepend (attributes, 
+				     NAUTILUS_FILE_ATTRIBUTE_CUSTOM_NAME);
 
 	nautilus_directory_file_monitor_add (view->details->model,
 					     &view->details->model,
Index: src/file-manager/fm-properties-window.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-properties-window.c,v
retrieving revision 1.121
diff -u -r1.121 fm-properties-window.c
--- src/file-manager/fm-properties-window.c	2001/05/11 01:30:33	1.121
+++ src/file-manager/fm-properties-window.c	2001/08/18 01:43:10
@@ -2132,6 +2132,8 @@
 	 * target file.
 	 */
 	attributes = nautilus_icon_factory_get_required_file_attributes ();
+	attributes = g_list_prepend (attributes,
+				     NAUTILUS_FILE_ATTRIBUTE_CUSTOM_NAME);
 	nautilus_file_monitor_add (window->details->original_file, window, attributes);
 	g_list_free (attributes);
 
Index: src/file-manager/fm-search-list-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-search-list-view.c,v
retrieving revision 1.76
diff -u -r1.76 fm-search-list-view.c
--- src/file-manager/fm-search-list-view.c	2001/05/04 03:14:42	1.76
+++ src/file-manager/fm-search-list-view.c	2001/08/18 01:43:10
@@ -632,7 +632,9 @@
 				   GTK_OBJECT (view));
 	/* Monitor the things needed to get the right
 	 * icon. Also monitor a directory's item count because
-	 * the "size" attribute is based on that, and the file's metadata.  */
+	 * the "size" attribute is based on that, and the file's metadata, and
+	 * possible custom icon.  
+	 */
 	attributes = nautilus_icon_factory_get_required_file_attributes ();		
 	attributes = g_list_prepend (attributes,
 				     NAUTILUS_FILE_ATTRIBUTE_DIRECTORY_ITEM_COUNT);
@@ -640,6 +642,8 @@
 				     NAUTILUS_FILE_ATTRIBUTE_METADATA);
 	attributes = g_list_prepend (attributes, 
 				     NAUTILUS_FILE_ATTRIBUTE_MIME_TYPE);
+	attributes = g_list_prepend (attributes, 
+				     NAUTILUS_FILE_ATTRIBUTE_CUSTOM_NAME);
 	nautilus_file_monitor_add (file, view, attributes);
 	g_list_free (attributes);
 }




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