[gtk: 17/31] Add gtk_icon_paintable_get_icon_name()
- From: Alexander Larsson <alexl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk: 17/31] Add gtk_icon_paintable_get_icon_name()
- Date: Mon, 10 Feb 2020 12:48:12 +0000 (UTC)
commit 57ecb2829a725b8ece788e70cd68c228cbe455b7
Author: Alexander Larsson <alexl redhat com>
Date: Thu Feb 6 17:28:19 2020 +0100
Add gtk_icon_paintable_get_icon_name()
This allows you to see which icon was actually chosen.
docs/reference/gtk/gtk4-sections.txt | 1 +
gtk/gtkicontheme.c | 25 +++++++++++++++++++++++++
gtk/gtkicontheme.h | 2 ++
testsuite/gtk/icontheme.c | 2 +-
4 files changed, 29 insertions(+), 1 deletion(-)
---
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index fa4001a1f6..3316829a80 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -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
diff --git a/gtk/gtkicontheme.c b/gtk/gtkicontheme.c
index 2b94a87339..65459be8e3 100644
--- a/gtk/gtkicontheme.c
+++ b/gtk/gtkicontheme.c
@@ -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;
}
diff --git a/gtk/gtkicontheme.h b/gtk/gtkicontheme.h
index efacc13c50..2a3366b7d5 100644
--- a/gtk/gtkicontheme.h
+++ b/gtk/gtkicontheme.h
@@ -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
diff --git a/testsuite/gtk/icontheme.c b/testsuite/gtk/icontheme.c
index 5c3b6cd008..6d84adc5d8 100644
--- a/testsuite/gtk/icontheme.c
+++ b/testsuite/gtk/icontheme.c
@@ -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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]