aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ephy-gui.c
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@gnome.org>2003-09-27 18:17:12 +0800
committerMarco Pesenti Gritti <marco@src.gnome.org>2003-09-27 18:17:12 +0800
commiteed2331e611eb281440c1bcb5f76b2e547f1e0a7 (patch)
tree5b19372449ec82830ffb679293de05d498e6232f /lib/ephy-gui.c
parent66a44625b35868a79da71ec78de700d9b8ff7619 (diff)
downloadgsoc2013-epiphany-eed2331e611eb281440c1bcb5f76b2e547f1e0a7.tar
gsoc2013-epiphany-eed2331e611eb281440c1bcb5f76b2e547f1e0a7.tar.gz
gsoc2013-epiphany-eed2331e611eb281440c1bcb5f76b2e547f1e0a7.tar.bz2
gsoc2013-epiphany-eed2331e611eb281440c1bcb5f76b2e547f1e0a7.tar.lz
gsoc2013-epiphany-eed2331e611eb281440c1bcb5f76b2e547f1e0a7.tar.xz
gsoc2013-epiphany-eed2331e611eb281440c1bcb5f76b2e547f1e0a7.tar.zst
gsoc2013-epiphany-eed2331e611eb281440c1bcb5f76b2e547f1e0a7.zip
Use gtkicontheme, and use it also for mime icons.
2003-09-27 Marco Pesenti Gritti <marco@gnome.org> * embed/mozilla/ContentHandler.cpp: * lib/ephy-gui.c: (make_mime_name), (ephy_gui_get_pixbuf_from_mime_type): * lib/ephy-gui.h: * lib/widgets/ephy-spinner.c: (ephy_spinner_init), (ephy_spinner_theme_changed), (ephy_spinner_load_images), (ephy_spinner_finalize): * src/ephy-shell.c: (ephy_shell_init): Use gtkicontheme, and use it also for mime icons.
Diffstat (limited to 'lib/ephy-gui.c')
-rw-r--r--lib/ephy-gui.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/lib/ephy-gui.c b/lib/ephy-gui.c
index 81077d140..af959b5aa 100644
--- a/lib/ephy-gui.c
+++ b/lib/ephy-gui.c
@@ -113,3 +113,75 @@ ephy_gui_help (GtkWindow *parent,
g_error_free (err);
}
}
+
+#define ICON_NAME_MIME_PREFIX "gnome-mime-"
+
+static char *
+make_mime_name (const char *mime_type)
+{
+ char *mime_type_without_slashes, *icon_name;
+ char *p;
+
+ if (mime_type == NULL)
+ {
+ return NULL;
+ }
+
+ mime_type_without_slashes = g_strdup (mime_type);
+
+ while ((p = strchr(mime_type_without_slashes, '/')) != NULL)
+ *p = '-';
+
+ icon_name = g_strconcat (ICON_NAME_MIME_PREFIX, mime_type_without_slashes, NULL);
+ g_free (mime_type_without_slashes);
+
+ return icon_name;
+}
+
+GdkPixbuf *
+ephy_gui_get_pixbuf_from_mime_type (const char *mime_type,
+ int size)
+{
+ GdkPixbuf *pixbuf;
+ GtkIconInfo *icon_info;
+ GtkIconTheme *icon_theme;
+ const char *icon;
+ char *icon_name;
+
+ icon_name = make_mime_name (mime_type);
+
+ icon_theme = gtk_icon_theme_get_default ();
+ g_return_val_if_fail (icon_theme != NULL, NULL);
+
+ icon_info = gtk_icon_theme_lookup_icon
+ (icon_theme, icon_name, size, -1);
+ g_free (icon_name);
+
+ /* try without specific size */
+ if (icon_info == NULL)
+ {
+ icon_info = gtk_icon_theme_lookup_icon
+ (icon_theme, icon_name, -1, -1);
+ }
+
+ /* no icon found */
+ if (icon_info == NULL) return NULL;
+
+ icon = gtk_icon_info_get_filename (icon_info);
+ pixbuf = gdk_pixbuf_new_from_file (icon, NULL);
+ g_return_val_if_fail (pixbuf != NULL, NULL);
+
+ if (size != gtk_icon_info_get_base_size (icon_info))
+ {
+ GdkPixbuf *tmp;
+
+ tmp = gdk_pixbuf_scale_simple (pixbuf, size, size,
+ GDK_INTERP_BILINEAR);
+ g_object_unref (pixbuf);
+ pixbuf = tmp;
+ }
+
+ gtk_icon_info_free (icon_info);
+
+ return pixbuf;
+}