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.
This commit is contained in:
Matthias Clasen 2021-03-26 13:15:54 -04:00
parent 4028bd5bce
commit 5940de98dd
2 changed files with 47 additions and 0 deletions

View File

@ -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,

View File

@ -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);