[gtk/icon-fallback] icontheme: Add gtk_icon_theme_has_gicon
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/icon-fallback] icontheme: Add gtk_icon_theme_has_gicon
- Date: Fri, 26 Mar 2021 17:18:08 +0000 (UTC)
commit 5940de98dda76d25eed71ed088e107838224a576
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Mar 26 13:15:54 2021 -0400
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.
gtk/gtkicontheme.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
gtk/gtkicontheme.h | 3 +++
2 files changed, 47 insertions(+)
---
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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]