Sophie

Sophie

distrib > Mandriva > 2007.1 > x86_64 > by-pkgid > 72682f97789893cb05925a6c35ec9c08 > files > 4

gnome-panel-2.18.0-5mdv2007.1.src.rpm

--- gnome-panel-2.18.0/gnome-panel/panel-menu-items.c.desktopitem	2007-03-17 11:52:41.000000000 +0100
+++ gnome-panel-2.18.0/gnome-panel/panel-menu-items.c	2007-03-17 11:59:40.000000000 +0100
@@ -38,6 +38,7 @@
 #include <string.h>
 #include <glib/gi18n.h>
 
+#include <libgnome/gnome-desktop-item.h>
 #include <libgnomevfs/gnome-vfs.h>
 #include <libgnome/gnome-url.h>
 #include <libgnomeui/gnome-url.h>
@@ -296,6 +297,7 @@
 	typedef struct {
 		GnomeVFSURI *uri;
 		char        *label;
+		char        *icon;
 	} PanelBookmark;
 
 	GtkWidget   *add_menu;
@@ -306,6 +308,9 @@
 	int          i;
 	GSList      *add_bookmarks, *l;
 	PanelBookmark *bookmark;
+	GnomeVFSFileInfo *vfs_info;
+
+	vfs_info = gnome_vfs_file_info_new ();
 
 	filename = g_build_filename (g_get_home_dir (),
 				     BOOKMARKS_FILENAME, NULL);
@@ -328,6 +333,9 @@
 			GnomeVFSURI *uri;
 			char        *space;
 			char        *label;
+			GnomeDesktopItem *desktop_entry;
+			char	    *icon;
+
 
 			g_hash_table_insert (table, lines[i], lines[i]);
 
@@ -341,6 +349,8 @@
 
 			uri = gnome_vfs_uri_new (lines[i]);
 
+			icon = NULL;
+
 			if (!uri ||
 			    (!strcmp (gnome_vfs_uri_get_scheme (uri), "file") &&
 			     !gnome_vfs_uri_exists (uri))) {
@@ -351,15 +361,57 @@
 				continue;
 			}
 
+			if (!strcmp (gnome_vfs_uri_get_scheme (uri), "file")) {
+				if (gnome_vfs_get_file_info_uri (uri, vfs_info, GNOME_VFS_FILE_INFO_GET_MIME_TYPE|GNOME_VFS_FILE_INFO_FOLLOW_LINKS) == GNOME_VFS_OK && (vfs_info->type != GNOME_VFS_FILE_TYPE_SYMBOLIC_LINK )) {
+				  if  ((vfs_info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_MIME_TYPE) != 0
+				  && strcmp (gnome_vfs_file_info_get_mime_type (vfs_info), "application/x-desktop") == 0) {
+					char        *unescaped_uri;
+
+					unescaped_uri = gnome_vfs_uri_to_string (uri, GNOME_VFS_URI_HIDE_NONE);
+					desktop_entry = gnome_desktop_item_new_from_uri (unescaped_uri, 0, NULL);
+					g_free (unescaped_uri);
+					if (desktop_entry && (gnome_desktop_item_get_entry_type (desktop_entry) == GNOME_DESKTOP_ITEM_TYPE_LINK)) {
+						unescaped_uri = g_filename_from_utf8(gnome_desktop_item_get_string (desktop_entry, GNOME_DESKTOP_ITEM_URL), -1, NULL, NULL, NULL);
+						if (label)
+							g_free (label);
+						if (uri)
+							gnome_vfs_uri_unref (uri);
+						if (!unescaped_uri) {
+							continue;
+						}
+
+						if (!panel_uri_exists (unescaped_uri)) {
+							gnome_desktop_item_unref (desktop_entry);
+							g_free (unescaped_uri);
+							continue;
+						}
+						uri = gnome_vfs_uri_new (unescaped_uri);
+						g_free (unescaped_uri);
+						label = g_strdup (gnome_desktop_item_get_localestring (desktop_entry, GNOME_DESKTOP_ITEM_NAME));
+						icon = g_strdup(gnome_desktop_item_get_string (desktop_entry, GNOME_DESKTOP_ITEM_ICON));
+					}
+					gnome_desktop_item_unref (desktop_entry);
+				    }
+				} else {
+					if (label)
+						g_free (label);
+					if (uri)
+						gnome_vfs_uri_unref (uri);
+					continue;
+				}
+			}
+
 			bookmark = g_malloc (sizeof (PanelBookmark));
 			bookmark->uri = uri;
 			bookmark->label = label;
+			bookmark->icon = icon;
 			add_bookmarks = g_slist_prepend (add_bookmarks, bookmark);
 		}
 	}
 
 	g_hash_table_destroy (table);
 	g_strfreev (lines);
+	gnome_vfs_file_info_unref (vfs_info);
 
 	add_bookmarks = g_slist_reverse (add_bookmarks);
 
@@ -452,7 +504,7 @@
 			}
 		}
 
-		panel_menu_items_append_place_item ("gnome-fs-directory",
+		panel_menu_items_append_place_item (bookmark->icon? bookmark->icon :"gnome-fs-directory",
 						    label,
 						    tooltip,
 						    add_menu,
@@ -462,8 +514,8 @@
 		g_free (tooltip);
 		g_free (full_uri);
 		g_free (label);
-		if (bookmark->label)
-			g_free (bookmark->label);
+		g_free (bookmark->label);
+		g_free (bookmark->icon);
 		gnome_vfs_uri_unref (bookmark->uri);
 		g_free (bookmark);
 	}