[gimp] app: reorganize a bit gimp_widget_load_icon().
- From: Jehan <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: reorganize a bit gimp_widget_load_icon().
- Date: Mon, 25 Jun 2018 14:07:24 +0000 (UTC)
commit 80d2a02b58264338cc7e41f117c6d0d9d2e23f47
Author: Jehan <jehan girinstud io>
Date: Mon Jun 25 15:32:24 2018 +0200
app: reorganize a bit gimp_widget_load_icon().
Massimo spotted some warning with clang in #1608 about pixbuf being used
initialized. Rather than just initializing it, I am actually
reorganizing a bit more the function because there was a bit of a logics
bug. In some weird case, it would have still been possible for this
function to return NULL instead of a magenta square (the case was: the
icon was not present in the icon theme; then wilber-eek was either not
present or failed to load).
This new code organization is more clearer, as a step by step, should
better identify the various failure cases and always return an allocated
GdkPixbuf.
app/widgets/gimpwidgets-utils.c | 106 +++++++++++++++++++---------------------
1 file changed, 50 insertions(+), 56 deletions(-)
---
diff --git a/app/widgets/gimpwidgets-utils.c b/app/widgets/gimpwidgets-utils.c
index cadb7a194b..ccc15d98ba 100644
--- a/app/widgets/gimpwidgets-utils.c
+++ b/app/widgets/gimpwidgets-utils.c
@@ -345,7 +345,7 @@ gimp_widget_load_icon (GtkWidget *widget,
const gchar *icon_name,
gint size)
{
- GdkPixbuf *pixbuf;
+ GdkPixbuf *pixbuf = NULL;
GtkIconTheme *icon_theme;
GtkIconInfo *icon_info;
gchar *name;
@@ -365,76 +365,70 @@ gimp_widget_load_icon (GtkWidget *widget,
GTK_ICON_LOOKUP_GENERIC_FALLBACK);
g_free (name);
- if (! icon_info)
+ if (icon_info)
+ {
+ pixbuf = gtk_icon_info_load_symbolic_for_context (icon_info,
+ gtk_widget_get_style_context (widget),
+ NULL, NULL);
+ g_object_unref (icon_info);
+ if (! pixbuf)
+ /* The icon was seemingly present in the current icon theme, yet
+ * it failed to load. Maybe the file is broken?
+ * As last resort, try to load "gimp-wilber-eek" as fallback.
+ * Note that we are not making more checks, so if the fallback
+ * icon fails to load as well, the function may still return NULL.
+ */
+ g_printerr ("WARNING: icon '%s' failed to load. Check the files "
+ "in your icon theme.\n", icon_name);
+ }
+ else
+ g_printerr ("WARNING: icon theme has no icon '%s'.\n", icon_name);
+
+ /* First fallback: gimp-wilber-eek */
+ if (! pixbuf)
{
- g_printerr ("WARNING: icon theme has no icon '%s'.\n", icon_name);
icon_info = gtk_icon_theme_lookup_icon_for_scale (icon_theme,
GIMP_ICON_WILBER_EEK "-symbolic",
size, scale_factor,
GTK_ICON_LOOKUP_GENERIC_FALLBACK);
-
if (icon_info)
- pixbuf = gtk_icon_info_load_symbolic_for_context (icon_info,
- gtk_widget_get_style_context (widget),
- NULL, NULL);
- }
- else
- {
- pixbuf = gtk_icon_info_load_symbolic_for_context (icon_info,
- gtk_widget_get_style_context (widget),
- NULL, NULL);
- if (! pixbuf)
{
- /* The icon was seemingly present in the current icon theme, yet
- * it failed to load. Maybe the file is broken?
- * As last resort, try to load "gimp-wilber-eek" as fallback.
- * Note that we are not making more checks, so if the fallback
- * icon fails to load as well, the function may still return NULL.
- */
- g_printerr ("WARNING: icon '%s' failed to load. Check the files "
- "in your icon theme.\n", icon_name);
-
+ pixbuf = gtk_icon_info_load_symbolic_for_context (icon_info,
+ gtk_widget_get_style_context (widget),
+ NULL, NULL);
g_object_unref (icon_info);
- icon_info = gtk_icon_theme_lookup_icon_for_scale (icon_theme,
- GIMP_ICON_WILBER_EEK "-symbolic",
- size, scale_factor,
- GTK_ICON_LOOKUP_GENERIC_FALLBACK);
-
- if (icon_info)
- pixbuf = gtk_icon_info_load_symbolic_for_context (icon_info,
- gtk_widget_get_style_context (widget),
- NULL, NULL);
if (! pixbuf)
- {
- /* As last resort, just draw an ugly magenta square. */
- guchar *data;
- gint rowstride = 3 * size;
- gint i, j;
+ g_printerr ("WARNING: icon '%s' failed to load. Check the files "
+ "in your icon theme.\n", GIMP_ICON_WILBER_EEK);
+ }
+ else
+ g_printerr ("WARNING: icon theme has no icon '%s'.\n", GIMP_ICON_WILBER_EEK);
+ }
- g_printerr ("WARNING: icon '%s' failed to load. Check the files "
- "in your icon theme.\n", GIMP_ICON_WILBER_EEK);
+ /* Last fallback: just a magenta square. */
+ if (! pixbuf)
+ {
+ /* As last resort, just draw an ugly magenta square. */
+ guchar *data;
+ gint rowstride = 3 * size;
+ gint i, j;
- data = g_new (guchar, rowstride * size);
- for (i = 0; i < size; i++)
- {
- for (j = 0; j < size; j++)
- {
- data[i * rowstride + j * 3] = 255;
- data[i * rowstride + j * 3 + 1] = 0;
- data[i * rowstride + j * 3 + 2] = 255;
- }
- }
- pixbuf = gdk_pixbuf_new_from_data (data, GDK_COLORSPACE_RGB, FALSE,
- 8, size, size, rowstride,
- (GdkPixbufDestroyNotify) g_free,
- NULL);
+ data = g_new (guchar, rowstride * size);
+ for (i = 0; i < size; i++)
+ {
+ for (j = 0; j < size; j++)
+ {
+ data[i * rowstride + j * 3] = 255;
+ data[i * rowstride + j * 3 + 1] = 0;
+ data[i * rowstride + j * 3 + 2] = 255;
}
}
+ pixbuf = gdk_pixbuf_new_from_data (data, GDK_COLORSPACE_RGB, FALSE,
+ 8, size, size, rowstride,
+ (GdkPixbufDestroyNotify) g_free,
+ NULL);
}
- if (icon_info)
- g_object_unref (icon_info);
-
return pixbuf;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]