New function to return an icon for a MIME type, using GnomeIconTheme if
* e-gui-utils.c (e_icon_for_mime_type): New function to return an
icon for a MIME type, using GnomeIconTheme if available or
gnome-vfs and gnome-mime-data if not.
svn path=/trunk/; revision=21733
This commit is contained in:
@ -1,3 +1,9 @@
|
||||
2003-07-01 Dan Winship <danw@ximian.com>
|
||||
|
||||
* e-gui-utils.c (e_icon_for_mime_type): New function to return an
|
||||
icon for a MIME type, using GnomeIconTheme if available or
|
||||
gnome-vfs and gnome-mime-data if not.
|
||||
|
||||
2003-06-19 Dan Winship <danw@ximian.com>
|
||||
|
||||
* e-xml-hash-utils.c (e_xml_to_hash): don't leak an extra copy of
|
||||
|
||||
@ -11,6 +11,8 @@
|
||||
*/
|
||||
#include <config.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "e-gui-utils.h"
|
||||
|
||||
#include <glib.h>
|
||||
@ -20,6 +22,14 @@
|
||||
#include <gtk/gtklabel.h>
|
||||
#include <gtk/gtkhbox.h>
|
||||
|
||||
#include <libgnome/gnome-program.h>
|
||||
#ifdef HAVE_LIBGNOMEUI_GNOME_ICON_LOOKUP_H
|
||||
#include <libgnomeui/gnome-icon-lookup.h>
|
||||
#endif
|
||||
#include <libgnomevfs/gnome-vfs-mime-handlers.h>
|
||||
|
||||
#include "art/empty.xpm"
|
||||
|
||||
GtkWidget *e_create_image_widget(gchar *name,
|
||||
gchar *string1, gchar *string2,
|
||||
gint int1, gint int2)
|
||||
@ -77,3 +87,84 @@ e_button_new_with_stock_icon (const char *label_str, const char *stockid)
|
||||
return button;
|
||||
}
|
||||
|
||||
/**
|
||||
* e_icon_for_mime_type:
|
||||
* @mime_type: a MIME type
|
||||
* @size_hint: the size the caller plans to display the icon at
|
||||
*
|
||||
* Tries to find an icon representing @mime_type that will display
|
||||
* nicely at @size_hint by @size_hint pixels. The returned icon
|
||||
* may or may not actually be that size.
|
||||
*
|
||||
* Return value: a pixbuf, which the caller must unref when it is done
|
||||
**/
|
||||
GdkPixbuf *
|
||||
e_icon_for_mime_type (const char *mime_type, int size_hint)
|
||||
{
|
||||
char *icon_name, *icon_path = NULL;
|
||||
GdkPixbuf *pixbuf = NULL;
|
||||
|
||||
#ifdef HAVE_LIBGNOMEUI_GNOME_ICON_LOOKUP_H
|
||||
static GnomeIconTheme *icon_theme = NULL;
|
||||
|
||||
/* Try the icon theme. (GNOME 2.2 or Sun GNOME 2.0).
|
||||
* This will also look in GNOME VFS.
|
||||
*/
|
||||
|
||||
if (!icon_theme)
|
||||
icon_theme = gnome_icon_theme_new ();
|
||||
|
||||
icon_name = gnome_icon_lookup (icon_theme, NULL, NULL, NULL, NULL,
|
||||
mime_type, 0, NULL);
|
||||
if (icon_name) {
|
||||
icon_path = gnome_icon_theme_lookup_icon (
|
||||
icon_theme, icon_name, size_hint, NULL, NULL);
|
||||
g_free (icon_name);
|
||||
}
|
||||
|
||||
#else
|
||||
const char *vfs_icon_name;
|
||||
|
||||
/* Try gnome-vfs. (gnome-vfs.mime itself doesn't offer much,
|
||||
* but other software packages may define icons for
|
||||
* themselves.
|
||||
*/
|
||||
vfs_icon_name = gnome_vfs_mime_get_icon (mime_type);
|
||||
if (vfs_icon_name) {
|
||||
icon_path = gnome_program_locate_file (
|
||||
NULL, GNOME_FILE_DOMAIN_PIXMAP,
|
||||
vfs_icon_name, TRUE, NULL);
|
||||
}
|
||||
|
||||
if (!icon_path) {
|
||||
char *p;
|
||||
|
||||
/* Try gnome-mime-data. */
|
||||
icon_name = g_strdup_printf ("document-icons/gnome-%s.png",
|
||||
mime_type);
|
||||
p = strrchr (icon_name, '/');
|
||||
if (p)
|
||||
*p = '-';
|
||||
|
||||
icon_path = gnome_program_locate_file (
|
||||
NULL, GNOME_FILE_DOMAIN_PIXMAP,
|
||||
icon_name, TRUE, NULL);
|
||||
g_free (icon_name);
|
||||
}
|
||||
|
||||
if (!icon_path) {
|
||||
/* Use the generic document icon. */
|
||||
icon_path = gnome_program_locate_file (NULL, GNOME_FILE_DOMAIN_PIXMAP,
|
||||
"document-icons/i-regular.png", TRUE, NULL);
|
||||
if (!icon_path) {
|
||||
g_warning ("Could not get any icon for %s!",mime_type);
|
||||
return gdk_pixbuf_new_from_xpm_data((const char **)empty_xpm);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
pixbuf = gdk_pixbuf_new_from_file (icon_path, NULL);
|
||||
g_free (icon_path);
|
||||
return pixbuf;
|
||||
}
|
||||
|
||||
|
||||
@ -9,4 +9,6 @@ GtkWidget *e_create_image_widget (gchar *name, gchar *string1, gchar *st
|
||||
|
||||
GtkWidget *e_button_new_with_stock_icon (const char *label_str, const char *stockid);
|
||||
|
||||
GdkPixbuf *e_icon_for_mime_type (const char *mime_type, int size);
|
||||
|
||||
#endif /* E_GUI_UTILS_H */
|
||||
|
||||
Reference in New Issue
Block a user