[gtk+] icontheme: Don't force missing icon
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] icontheme: Don't force missing icon
- Date: Wed, 14 May 2014 02:58:44 +0000 (UTC)
commit 5d1b5c13fb4771c1d3de2deafedd0cd678c4cd35
Author: Benjamin Otte <otte redhat com>
Date: Sun May 11 02:30:50 2014 +0200
icontheme: Don't force missing icon
When forcing regular or symbolic icons, fall back to the default
specified icons. This ensures that when no symbolic icon is present, an
icon will still appear - the regular one.
gtk/gtkicontheme.c | 57 ++++++++++++++++++++++++++++++++++++---------------
gtk/gtkicontheme.h | 8 +++---
2 files changed, 44 insertions(+), 21 deletions(-)
---
diff --git a/gtk/gtkicontheme.c b/gtk/gtkicontheme.c
index 8bf1062..b06d0fb 100644
--- a/gtk/gtkicontheme.c
+++ b/gtk/gtkicontheme.c
@@ -1803,7 +1803,7 @@ choose_icon (GtkIconTheme *icon_theme,
{
gboolean has_regular = FALSE, has_symbolic = FALSE;
GtkIconInfo *icon_info;
- gchar **new_names;
+ GPtrArray *new_names;
guint i;
for (i = 0; icon_names[i]; i++)
@@ -1816,40 +1816,63 @@ choose_icon (GtkIconTheme *icon_theme,
if ((flags & GTK_ICON_LOOKUP_FORCE_REGULAR) && has_symbolic)
{
- new_names = g_new0 (gchar *, i + 1);
+ new_names = g_ptr_array_new_with_free_func (g_free);
for (i = 0; icon_names[i]; i++)
{
if (g_str_has_suffix (icon_names[i], "-symbolic"))
- new_names[i] = g_strndup (icon_names[i], strlen (icon_names[i]) - strlen ("-symbolic"));
+ g_ptr_array_add (new_names, g_strndup (icon_names[i], strlen (icon_names[i]) - strlen
("-symbolic")));
else
- new_names[i] = g_strdup (icon_names[i]);
+ g_ptr_array_add (new_names, g_strdup (icon_names[i]));
}
+ for (i = 0; icon_names[i]; i++)
+ {
+ if (g_str_has_suffix (icon_names[i], "-symbolic"))
+ g_ptr_array_add (new_names, g_strdup (icon_names[i]));
+ }
+ g_ptr_array_add (new_names, NULL);
+
+ icon_info = real_choose_icon (icon_theme,
+ (const gchar **) new_names->pdata,
+ size,
+ scale,
+ flags & ~(GTK_ICON_LOOKUP_FORCE_REGULAR |
GTK_ICON_LOOKUP_FORCE_SYMBOLIC));
+
+ g_ptr_array_free (new_names, TRUE);
}
else if ((flags & GTK_ICON_LOOKUP_FORCE_SYMBOLIC) && has_regular)
{
- new_names = g_new0 (gchar *, i + 1);
+ new_names = g_ptr_array_new_with_free_func (g_free);
for (i = 0; icon_names[i]; i++)
{
if (!g_str_has_suffix (icon_names[i], "-symbolic"))
- new_names[i] = g_strconcat (icon_names[i], "-symbolic", NULL);
+ g_ptr_array_add (new_names, g_strconcat (icon_names[i], "-symbolic", NULL));
else
- new_names[i] = g_strdup (icon_names[i]);
+ g_ptr_array_add (new_names, g_strdup (icon_names[i]));
+ }
+ for (i = 0; icon_names[i]; i++)
+ {
+ if (!g_str_has_suffix (icon_names[i], "-symbolic"))
+ g_ptr_array_add (new_names, g_strdup (icon_names[i]));
}
+ g_ptr_array_add (new_names, NULL);
+
+ icon_info = real_choose_icon (icon_theme,
+ (const gchar **) new_names->pdata,
+ size,
+ scale,
+ flags & ~(GTK_ICON_LOOKUP_FORCE_REGULAR |
GTK_ICON_LOOKUP_FORCE_SYMBOLIC));
+
+ g_ptr_array_free (new_names, TRUE);
}
else
{
- new_names = NULL;
+ icon_info = real_choose_icon (icon_theme,
+ icon_names,
+ size,
+ scale,
+ flags & ~(GTK_ICON_LOOKUP_FORCE_REGULAR |
GTK_ICON_LOOKUP_FORCE_SYMBOLIC));
}
- icon_info = real_choose_icon (icon_theme,
- new_names ? (const gchar **) new_names : icon_names,
- size,
- scale,
- flags & ~(GTK_ICON_LOOKUP_FORCE_REGULAR | GTK_ICON_LOOKUP_FORCE_SYMBOLIC));
-
- if (new_names)
- g_strfreev (new_names);
-
return icon_info;
}
diff --git a/gtk/gtkicontheme.h b/gtk/gtkicontheme.h
index bdbaafe..c11cfab 100644
--- a/gtk/gtkicontheme.h
+++ b/gtk/gtkicontheme.h
@@ -113,10 +113,10 @@ struct _GtkIconThemeClass
* fallback, see gtk_icon_theme_choose_icon(). Since 2.12.
* @GTK_ICON_LOOKUP_FORCE_SIZE: Always get the icon scaled to the
* requested size. Since 2.14.
- * @GTK_ICON_LOOKUP_FORCE_REGULAR: Always load regular icons, even when
- * symbolic icon names are given. Since 3.14.
- * @GTK_ICON_LOOKUP_FORCE_SYMBOLIC: Always load symbolic icons, even when
- * regular icon names are given. Since 3.14.
+ * @GTK_ICON_LOOKUP_FORCE_REGULAR: Try to always load regular icons, even
+ * when symbolic icon names are given. Since 3.14.
+ * @GTK_ICON_LOOKUP_FORCE_SYMBOLIC: Try to always load symbolic icons, even
+ * when regular icon names are given. Since 3.14.
*
* Used to specify options for gtk_icon_theme_lookup_icon()
*/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]