[Nautilus-list] John's .desktop icon patch



Hi,

Has this patch been merged into mainstream Nautilus? If not what
changes do I need to make to get it ready?

This is John Harper's patch to dig icons out of .desktop files (if
those files are coming over VFS).

Havoc

Index: libnautilus-extensions/nautilus-icon-factory.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-extensions/nautilus-icon-factory.c,v
retrieving revision 1.194
diff -u -r1.194 nautilus-icon-factory.c
--- libnautilus-extensions/nautilus-icon-factory.c	2001/02/15 15:45:41	1.194
+++ libnautilus-extensions/nautilus-icon-factory.c	2001/02/18 02:11:35
@@ -55,6 +55,7 @@
 #include <libgnomevfs/gnome-vfs-mime-info.h>
 #include <libgnomevfs/gnome-vfs-mime-handlers.h>
 #include <libgnomevfs/gnome-vfs-mime-monitor.h>
+#include <libgnomevfs/gnome-vfs-ops.h>
 #include <libgnomevfs/gnome-vfs-types.h>
 #include <libnautilus-extensions/nautilus-gdk-pixbuf-extensions.h>
 #include <librsvg/rsvg.h>
@@ -1343,6 +1344,55 @@
 	return nautilus_file_is_local (file);
 }
 
+static char *
+get_icon_name_from_desktop_file_uri (const char *file_uri)
+{
+	GnomeVFSResult result;
+	GnomeVFSHandle *handle;
+	GnomeVFSFileInfo info;
+	char *buffer;
+	GnomeVFSFileSize bytes_read;
+	char *ptr, *next;
+	char *icon_name;
+
+	icon_name = NULL;
+
+	result = gnome_vfs_get_file_info (file_uri, &info, GNOME_VFS_FILE_INFO_DEFAULT);
+	if (result != GNOME_VFS_OK) {
+		return NULL;
+	}
+
+	result = gnome_vfs_open (&handle, file_uri, GNOME_VFS_OPEN_READ);
+	if (result != GNOME_VFS_OK) {
+		return NULL;
+	}
+
+	buffer = g_malloc (info.size + 1);
+	result = gnome_vfs_read (handle, buffer, info.size, &bytes_read);
+	if (result == GNOME_VFS_OK) {
+		buffer[bytes_read] = 0;
+		ptr = buffer;
+		while (ptr != NULL) {
+			next = strchr (ptr, '\n');
+			if (strncmp ("Icon=", ptr, 5) == 0) {
+				if (next != NULL) {
+					*next = 0;
+				}
+				if (ptr[5] != 0) {
+					icon_name = g_strdup (ptr + 5);
+				}
+				break;
+			}
+			ptr = next ? next + 1 : NULL;
+		}
+	}
+
+	g_free (buffer);
+	gnome_vfs_close (handle);
+
+	return icon_name;
+}
+
 /* return TRUE if the passed-in mime-type is one that we can thumbnail.  It's
  * used to exclude ones that we know will generate errors if we tried them.
  */
@@ -1424,7 +1474,14 @@
 			g_free (file_path);
 		}
 	}
-	
+
+	/* Handle .desktop files */
+	if (uri == NULL
+	    && (nautilus_file_is_mime_type (file, "application/x-gnome-app-info")
+		|| nautilus_file_is_mime_type (file, "application/x-gnome-control-center-applet"))) {
+		icon_name = get_icon_name_from_desktop_file_uri (file_uri);
+	}
+
 	/* handle SVG files */
 	if (uri == NULL && nautilus_file_is_mime_type (file, "image/svg")) {
 		uri = g_strdup (file_uri);




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