diff --git a/src/st/st-icon.c b/src/st/st-icon.c index 6cc7e4dba..13f7dd54f 100644 --- a/src/st/st-icon.c +++ b/src/st/st-icon.c @@ -37,6 +37,8 @@ enum PROP_0, PROP_GICON, + PROP_FALLBACK_GICON, + PROP_ICON_NAME, PROP_ICON_SIZE, PROP_FALLBACK_ICON_NAME, @@ -86,6 +88,10 @@ st_icon_set_property (GObject *gobject, st_icon_set_gicon (icon, g_value_get_object (value)); break; + case PROP_FALLBACK_GICON: + st_icon_set_fallback_gicon (icon, g_value_get_object (value)); + break; + case PROP_ICON_NAME: st_icon_set_icon_name (icon, g_value_get_string (value)); break; @@ -118,6 +124,10 @@ st_icon_get_property (GObject *gobject, g_value_set_object (value, st_icon_get_gicon (icon)); break; + case PROP_FALLBACK_GICON: + g_value_set_object (value, st_icon_get_fallback_gicon (icon)); + break; + case PROP_ICON_NAME: g_value_set_string (value, st_icon_get_icon_name (icon)); break; @@ -246,6 +256,13 @@ st_icon_class_init (StIconClass *klass) G_TYPE_ICON, ST_PARAM_READWRITE); + props[PROP_FALLBACK_GICON] = + g_param_spec_object ("fallback-gicon", + "Fallback GIcon", + "The fallback GIcon shown if the normal icon fails to load", + G_TYPE_ICON, + ST_PARAM_READWRITE); + props[PROP_ICON_NAME] = g_param_spec_string ("icon-name", "Icon name", @@ -601,6 +618,47 @@ st_icon_set_gicon (StIcon *icon, GIcon *gicon) st_icon_update (icon); } +/** + * st_icon_get_fallback_gicon: + * @icon: a #StIcon + * + * Gets the currently set fallback #GIcon. + * + * Returns: (transfer none): The fallback #GIcon, if set, otherwise %NULL + */ +GIcon * +st_icon_get_fallback_gicon (StIcon *icon) +{ + g_return_val_if_fail (ST_IS_ICON (icon), NULL); + + return icon->priv->fallback_gicon; +} + +/** + * st_icon_set_fallback_gicon: + * @icon: a #StIcon + * @fallback_gicon: (nullable): the fallback #GIcon + * + * Sets a fallback #GIcon to show if the normal icon fails to load. + * If @fallback_gicon is %NULL or fails to load, the icon is unset and no + * texture will be visible for the fallback icon. + */ +void +st_icon_set_fallback_gicon (StIcon *icon, + GIcon *fallback_gicon) +{ + g_return_if_fail (ST_IS_ICON (icon)); + g_return_if_fail (fallback_gicon == NULL || G_IS_ICON (fallback_gicon)); + + if (g_icon_equal (icon->priv->fallback_gicon, fallback_gicon)) + return; + + g_set_object (&icon->priv->fallback_gicon, fallback_gicon); + g_object_notify_by_pspec (G_OBJECT (icon), props[PROP_FALLBACK_GICON]); + + st_icon_update (icon); +} + /** * st_icon_get_icon_size: * @icon: an #StIcon diff --git a/src/st/st-icon.h b/src/st/st-icon.h index f510520dc..8714ef931 100644 --- a/src/st/st-icon.h +++ b/src/st/st-icon.h @@ -60,6 +60,10 @@ GIcon *st_icon_get_gicon (StIcon *icon); void st_icon_set_gicon (StIcon *icon, GIcon *gicon); +GIcon *st_icon_get_fallback_gicon (StIcon *icon); +void st_icon_set_fallback_gicon (StIcon *icon, + GIcon *fallback_gicon); + const gchar *st_icon_get_icon_name (StIcon *icon); void st_icon_set_icon_name (StIcon *icon, const gchar *icon_name);