mirror of https://github.com/djcb/mu.git
* mu-widget-util.c: improve error reporting
This commit is contained in:
parent
51f5f5ed5d
commit
f460d7c241
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** Copyright (C) 2011 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
** Copyright (C) 2011-2012 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||||
**
|
**
|
||||||
** This program is free software; you can redistribute it and/or modify it
|
** This program is free software; you can redistribute it and/or modify it
|
||||||
** under the terms of the GNU General Public License as published by the
|
** under the terms of the GNU General Public License as published by the
|
||||||
|
@ -30,7 +30,7 @@ second_guess_content_type (const char *ctype)
|
||||||
const char *orig, *subst;
|
const char *orig, *subst;
|
||||||
} substtable [] = {
|
} substtable [] = {
|
||||||
{"text", "text/plain"},
|
{"text", "text/plain"},
|
||||||
{"image/pjpeg", "image/jpeg" }
|
{"image/pjpeg", "image/jpeg" }
|
||||||
};
|
};
|
||||||
|
|
||||||
for (i = 0; i != G_N_ELEMENTS(substtable); ++i)
|
for (i = 0; i != G_N_ELEMENTS(substtable); ++i)
|
||||||
|
@ -45,27 +45,34 @@ get_icon_pixbuf_for_content_type (const char *ctype, size_t size)
|
||||||
{
|
{
|
||||||
GIcon *icon;
|
GIcon *icon;
|
||||||
GdkPixbuf *pixbuf;
|
GdkPixbuf *pixbuf;
|
||||||
|
GError *err;
|
||||||
|
|
||||||
icon = g_content_type_get_icon (ctype);
|
icon = g_content_type_get_icon (ctype);
|
||||||
pixbuf = NULL;
|
pixbuf = NULL;
|
||||||
|
err = NULL;
|
||||||
|
|
||||||
/* based on a snippet from http://www.gtkforums.com/about4721.html */
|
/* based on a snippet from http://www.gtkforums.com/about4721.html */
|
||||||
if (G_IS_THEMED_ICON(icon)) {
|
if (G_IS_THEMED_ICON(icon)) {
|
||||||
gchar const * const *names;
|
gchar const * const *names;
|
||||||
names = g_themed_icon_get_names (G_THEMED_ICON(icon));
|
names = g_themed_icon_get_names (G_THEMED_ICON(icon));
|
||||||
pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default(),
|
pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default(),
|
||||||
*names, size, 0, NULL);
|
*names, size, 0, &err);
|
||||||
} else if (G_IS_FILE_ICON(icon)) {
|
} else if (G_IS_FILE_ICON(icon)) {
|
||||||
GFile *icon_file;
|
GFile *icon_file;
|
||||||
gchar *path;
|
gchar *path;
|
||||||
icon_file = g_file_icon_get_file (G_FILE_ICON(icon));
|
icon_file = g_file_icon_get_file (G_FILE_ICON(icon));
|
||||||
path = g_file_get_path (icon_file);
|
path = g_file_get_path (icon_file);
|
||||||
pixbuf = gdk_pixbuf_new_from_file_at_size (path, size, size, NULL);
|
pixbuf = gdk_pixbuf_new_from_file_at_size (path, size, size, &err);
|
||||||
g_free (path);
|
g_free (path);
|
||||||
g_object_unref(icon_file);
|
g_object_unref(icon_file);
|
||||||
}
|
}
|
||||||
g_object_unref(icon);
|
g_object_unref(icon);
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
g_warning ("error: %s\n", err->message);
|
||||||
|
g_clear_error (&err);
|
||||||
|
}
|
||||||
|
|
||||||
return pixbuf;
|
return pixbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,11 +86,9 @@ mu_widget_util_get_icon_pixbuf_for_content_type (const char *ctype, size_t size)
|
||||||
g_return_val_if_fail (size > 0, NULL);
|
g_return_val_if_fail (size > 0, NULL);
|
||||||
|
|
||||||
pixbuf = get_icon_pixbuf_for_content_type (ctype, size);
|
pixbuf = get_icon_pixbuf_for_content_type (ctype, size);
|
||||||
if (!pixbuf)
|
if (!pixbuf)
|
||||||
pixbuf = get_icon_pixbuf_for_content_type
|
pixbuf = get_icon_pixbuf_for_content_type
|
||||||
(second_guess_content_type (ctype), size);
|
(second_guess_content_type (ctype), size);
|
||||||
|
|
||||||
return pixbuf;
|
return pixbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue