summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2021-03-26 13:15:54 -0400
committerMatthias Clasen <mclasen@redhat.com>2021-03-26 13:17:51 -0400
commit5940de98dda76d25eed71ed088e107838224a576 (patch)
tree517efa5da73c282fe892ea7d9902874515270ece
parent4028bd5bce0c93b21b738f7ec6972858b6e8bede (diff)
downloadgtk+-5940de98dda76d25eed71ed088e107838224a576.tar.gz
icontheme: Add gtk_icon_theme_has_gicon
Add a utility function to check whether the icontheme will produce something better than missing-image for a GIcon. Obviously, we can only answer this question if the GIcon is a themed icon the begin with.
-rw-r--r--gtk/gtkicontheme.c44
-rw-r--r--gtk/gtkicontheme.h3
2 files changed, 47 insertions, 0 deletions
diff --git a/gtk/gtkicontheme.c b/gtk/gtkicontheme.c
index 7486457e17..45623c44d4 100644
--- a/gtk/gtkicontheme.c
+++ b/gtk/gtkicontheme.c
@@ -2615,6 +2615,50 @@ gtk_icon_theme_has_icon (GtkIconTheme *self,
return res;
}
+/**
+ * gtk_icon_theme_has_gicon:
+ * @self: a `GtkIconTheme`
+ * @gicon: a `GIcon`
+ *
+ * Checks whether an icon theme includes an icon
+ * for a particular `GIcon`.
+ *
+ * Returns: %TRUE if @self includes an icon for @gicon
+ */
+gboolean
+gtk_icon_theme_has_gicon (GtkIconTheme *self,
+ GIcon *gicon)
+{
+ const char * const *names;
+ gboolean res = FALSE;
+
+ if (!G_IS_THEMED_ICON (gicon))
+ return TRUE;
+
+ names = g_themed_icon_get_names (G_THEMED_ICON (gicon));
+
+ gtk_icon_theme_lock (self);
+
+ ensure_valid_themes (self, FALSE);
+
+ for (int i = 0; names[i]; i++)
+ {
+ for (GList *l = self->themes; l; l = l->next)
+ {
+ if (theme_has_icon (l->data, names[i]))
+ {
+ res = TRUE;
+ goto out;
+ }
+ }
+ }
+
+ out:
+ gtk_icon_theme_unlock (self);
+
+ return res;
+}
+
static void
add_size (gpointer key,
gpointer value,
diff --git a/gtk/gtkicontheme.h b/gtk/gtkicontheme.h
index 1db2d1766f..183c7249aa 100644
--- a/gtk/gtkicontheme.h
+++ b/gtk/gtkicontheme.h
@@ -116,6 +116,9 @@ char * gtk_icon_theme_get_theme_name (GtkIconTheme
GDK_AVAILABLE_IN_ALL
gboolean gtk_icon_theme_has_icon (GtkIconTheme *self,
const char *icon_name);
+GDK_AVAILABLE_IN_4_2
+gboolean gtk_icon_theme_has_gicon (GtkIconTheme *self,
+ GIcon *gicon);
GDK_AVAILABLE_IN_ALL
int *gtk_icon_theme_get_icon_sizes (GtkIconTheme *self,
const char *icon_name);