Add gtk_icon_paintable_get_icon_name()

This allows you to see which icon was actually chosen.
This commit is contained in:
Alexander Larsson 2020-02-06 17:28:19 +01:00
parent d45d604df1
commit 57ecb2829a
4 changed files with 29 additions and 1 deletions

View File

@ -5010,6 +5010,7 @@ gtk_icon_theme_lookup_by_gicon
gtk_icon_theme_list_icons
gtk_icon_theme_get_icon_sizes
gtk_icon_paintable_get_filename
gtk_icon_paintable_get_icon_name
gtk_icon_paintable_is_symbolic
<SUBSECTION Standard>
GtkIconClass

View File

@ -261,6 +261,7 @@ struct _GtkIconPaintable
IconKey key;
GtkIconTheme *in_cache; /* Protected by icon_cache lock */
gchar *icon_name;
gchar *filename;
GLoadableIcon *loadable;
@ -1909,6 +1910,7 @@ real_choose_icon (GtkIconTheme *self,
if (icon == NULL)
{
icon = icon_paintable_new (size, scale);
icon->icon_name = g_strdup ("image-missing");
icon->filename = g_strdup (IMAGE_MISSING_RESOURCE_PATH);
icon->is_resource = TRUE;
}
@ -2686,6 +2688,7 @@ theme_lookup_icon (IconTheme *theme,
filename = g_strconcat (icon_name, string_from_suffix (min_suffix), NULL);
icon->filename = g_build_filename (dir->path, filename, NULL);
icon->icon_name = g_strdup (icon_name);
icon->is_svg = min_suffix == ICON_CACHE_FLAG_SVG_SUFFIX;
icon->is_resource = dir->is_resource;
icon->is_symbolic = icon_uri_is_symbolic (filename, -1);
@ -3092,6 +3095,7 @@ gtk_icon_paintable_finalize (GObject *object)
g_strfreev (icon->key.icon_names);
g_free (icon->filename);
g_free (icon->icon_name);
g_clear_object (&icon->loadable);
g_clear_object (&icon->texture);
@ -3129,6 +3133,25 @@ gtk_icon_paintable_get_filename (GtkIconPaintable *icon)
return icon->filename;
}
/**
* gtk_icon_paintable_get_icon_name:
* @self: a #GtkIcon
*
* Gets the icon name being used for the icon. This is only set
* if a themed icon was used, and will show the actual icon-name
* the was chosen.
*
* Returns: (nullable) (type filename): the themed icon-name for the icon, or %NULL
* if its not a themed icon.
*/
const gchar *
gtk_icon_paintable_get_icon_name (GtkIconPaintable *icon)
{
g_return_val_if_fail (icon != NULL, NULL);
return icon->icon_name;
}
/**
* gtk_icon_paintable_is_symbolic:
* @self: a #GtkIcon
@ -3282,6 +3305,7 @@ icon_ensure_texture__locked (GtkIconPaintable *icon,
if (!source_pixbuf)
{
source_pixbuf = _gdk_pixbuf_new_from_resource (IMAGE_MISSING_RESOURCE_PATH, "png", NULL);
icon->icon_name = g_strdup ("image-missing");
icon->is_symbolic = FALSE;
g_assert (source_pixbuf != NULL);
}
@ -3579,6 +3603,7 @@ gtk_icon_theme_lookup_by_gicon (GtkIconTheme *self,
{
g_debug ("Unhandled GIcon type %s", g_type_name_from_instance ((GTypeInstance *)gicon));
icon = icon_paintable_new (size, scale);
icon->icon_name = g_strdup ("image-missing");
icon->filename = g_strdup (IMAGE_MISSING_RESOURCE_PATH);
icon->is_resource = TRUE;
}

View File

@ -139,6 +139,8 @@ GType gtk_icon_paintable_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
const gchar * gtk_icon_paintable_get_filename (GtkIconPaintable *self);
GDK_AVAILABLE_IN_ALL
const gchar * gtk_icon_paintable_get_icon_name (GtkIconPaintable *self);
GDK_AVAILABLE_IN_ALL
gboolean gtk_icon_paintable_is_symbolic (GtkIconPaintable *self);
G_END_DECLS

View File

@ -121,7 +121,7 @@ assert_icon_lookup_fails (const char *icon_name,
/* We never truly *fail*, but check that we got the image-missing fallback */
g_assert (info != NULL);
g_assert (g_str_has_suffix (gtk_icon_paintable_get_filename (info), "image-missing.png"));
g_assert_cmpstr (gtk_icon_paintable_get_icon_name (info), ==, "image-missing");
}
static GList *lookups = NULL;