Re: Patch for fixing MIME icons in download dialog

Tommi Komulainen <[email protected]>
Newsgroups gmane.comp.web.galeon.devel
Message-ID <[email protected]>
On Tue, 2003-09-23 at 21:06, Hongli Lai wrote:
> When I click on a zipfile (or other file that has "Save" as default 
> action), Galeon usually displays a "broken file"-icon as the file's MIME 
> icon.
> I took a look at the source code and it seems Galeon uses the result of 
> gnome_vfs_mime_get_icon() directly. That is not the correct way. This 
> patch fixes that problem by using GNOME's icon theme functions.

Thanks for the hint!  However the patch you provided is leaking memory,
and generally I got the feeling it depends quite a lot on gnome icon
theme internal details (gnome-mime-* and such) something that IMHO
shouldn't be exposed to applications.

Please see the attached patch, it should have the intended result as
well.  The main difference is letting gnome_icon_lookup() handle the
icon theme details.  Strangely enough it also means we don't need the
gnome_vfs_mime_get_icon() anymore, I don't if that's a good thing, or
bad.


-- 
Tommi Komulainen                                 [email protected]
GPG 1024D/68388EE6    6FD6 DD79 EB38 BF6F 3533  09C0 04A8 9871 6838 8EE6
galeon-mime-icon.diff (text/x-patch, 3.8 KB)
? .bb.swp
? .snprj
? aa
? asdf
? build
? cookie1.png
? cookie2.png
? cvs.proj
? default-prefs.diff
? foo.diff
? links.diff
? prefs.txt
? release.diff
? bookmarks/bookmarks.h.porig
? bookmarks/xbel.c.porig
? src/galeon-link-button.c
? src/galeon-link-button.h
Index: mozilla/ContentHandler.cpp
===================================================================
RCS file: /cvs/gnome/galeon/mozilla/ContentHandler.cpp,v
retrieving revision 1.50
diff -u -p -r1.50 ContentHandler.cpp
--- mozilla/ContentHandler.cpp	30 Aug 2003 18:44:50 -0000	1.50
+++ mozilla/ContentHandler.cpp	24 Sep 2003 12:40:12 -0000
@@ -726,8 +726,8 @@ MimeAskActionDialog::MimeAskActionDialog
 
 	GtkWidget *mimeIcon = glade_xml_get_widget(mGXml,
 						   "mime_ask_action_icon");
-	gtk_image_set_from_file(GTK_IMAGE(mimeIcon),
-				gnome_vfs_mime_get_icon(aMimeType));						     
+	gul_gui_image_set_from_mime_type (mimeIcon, 
+			                  aMimeType, GTK_ICON_SIZE_DIALOG);
 
 	description = gnome_vfs_mime_get_description(aMimeType);
 	if (!description) description = aMimeType;
Index: utils/gul-gui.c
===================================================================
RCS file: /cvs/gnome/galeon/utils/gul-gui.c,v
retrieving revision 1.12
diff -u -p -r1.12 gul-gui.c
--- utils/gul-gui.c	30 Aug 2003 18:46:50 -0000	1.12
+++ utils/gul-gui.c	24 Sep 2003 12:40:13 -0000
@@ -35,9 +35,13 @@
 #include <gtk/gtkwindow.h>
 #include <gtk/gtkdialog.h>
 #include <gtk/gtkmenuitem.h>
+#include <gtk/gtkiconfactory.h>
 #include <gtk/gtkimagemenuitem.h>
 #include <gtk/gtkcheckmenuitem.h>
 #include <gtk/gtkmessagedialog.h>
+#include <gtk/gtkstock.h>
+#include <libgnomeui/gnome-icon-lookup.h>
+#include <libgnomeui/gnome-icon-theme.h>
 
 static void
 make_selection_list (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter,
@@ -332,4 +336,46 @@ gul_gui_widget_hide_now (GtkWidget *widg
 	gtk_widget_hide (widget);
 	while (gtk_events_pending ()) gtk_main_iteration ();
 	return FALSE;
+}
+
+void
+gul_gui_image_set_from_mime_type (GtkWidget  *image,
+		                  const char *mime_type,
+				  GtkIconSize icon_size)
+{
+	int width, height;
+	GnomeIconTheme *theme;
+	char *icon, *path;
+
+	g_return_if_fail (GTK_IS_IMAGE(image));
+	g_return_if_fail (mime_type != NULL);
+
+	if (!gtk_icon_size_lookup_for_settings 
+		(gtk_widget_get_settings (GTK_WIDGET(image)),
+		 icon_size, &width, &height))
+	{
+		width = height = -1;
+	}
+
+	theme = gnome_icon_theme_new ();
+	gnome_icon_theme_set_allow_svg (theme, TRUE);
+
+	icon = gnome_icon_lookup (theme, NULL, NULL, NULL, NULL,
+				  mime_type,
+				  GNOME_ICON_LOOKUP_FLAGS_NONE, NULL);
+
+	path = gnome_icon_theme_lookup_icon (theme, icon, height, NULL, NULL);
+	g_object_unref (theme);
+	g_free (icon);
+
+	if (path)
+	{
+		gtk_image_set_from_file (GTK_IMAGE(image), path);
+		g_free (path);
+	}
+	else
+	{
+		gtk_image_set_from_stock (GTK_IMAGE(image),
+				          GTK_STOCK_NEW, icon_size);
+	}
 }
Index: utils/gul-gui.h
===================================================================
RCS file: /cvs/gnome/galeon/utils/gul-gui.h,v
retrieving revision 1.9
diff -u -p -r1.9 gul-gui.h
--- utils/gul-gui.h	30 Aug 2003 18:46:50 -0000	1.9
+++ utils/gul-gui.h	24 Sep 2003 12:40:13 -0000
@@ -20,7 +20,6 @@
 #define GUL_GUI_H
 
 /* system includes */
-#include <glib.h>
 #include <gtk/gtkmenu.h>
 #include <gtk/gtktreeview.h>
 #include <gtk/gtkradiobutton.h>
@@ -71,6 +70,10 @@ gboolean	gul_gui_confirm_overwrite_file	
 							const char *filename);
 
 gboolean	gul_gui_widget_hide_now		       (GtkWidget *widget);
+
+void            gul_gui_image_set_from_mime_type       (GtkWidget  *image,
+		                                        const char *mime_type,
+							GtkIconSize icon_size);
 
 G_END_DECLS
signature.asc (application/pgp-signature, 189 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQA/cZUIBKiYcWg4juYRAncTAJwOkbl2LSLVknD7GoE5b66HqoZcGQCdGaan
r5G16V8rzFPv5t1X5KND5AM=
=r6ZG
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.