st/icon: Add API to set the fallback GIcon

Let's support the fallback icon a bit better and allow setting its GIcon
just as we do for the normal icon.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/888
This commit is contained in:
Jonas Dreßler 2019-11-21 17:03:22 +07:00 committed by Florian Müllner
parent 8b8d3e28b2
commit e784afe9ac
2 changed files with 62 additions and 0 deletions

View File

@ -37,6 +37,8 @@ enum
PROP_0, PROP_0,
PROP_GICON, PROP_GICON,
PROP_FALLBACK_GICON,
PROP_ICON_NAME, PROP_ICON_NAME,
PROP_ICON_SIZE, PROP_ICON_SIZE,
PROP_FALLBACK_ICON_NAME, PROP_FALLBACK_ICON_NAME,
@ -86,6 +88,10 @@ st_icon_set_property (GObject *gobject,
st_icon_set_gicon (icon, g_value_get_object (value)); st_icon_set_gicon (icon, g_value_get_object (value));
break; break;
case PROP_FALLBACK_GICON:
st_icon_set_fallback_gicon (icon, g_value_get_object (value));
break;
case PROP_ICON_NAME: case PROP_ICON_NAME:
st_icon_set_icon_name (icon, g_value_get_string (value)); st_icon_set_icon_name (icon, g_value_get_string (value));
break; break;
@ -118,6 +124,10 @@ st_icon_get_property (GObject *gobject,
g_value_set_object (value, st_icon_get_gicon (icon)); g_value_set_object (value, st_icon_get_gicon (icon));
break; break;
case PROP_FALLBACK_GICON:
g_value_set_object (value, st_icon_get_fallback_gicon (icon));
break;
case PROP_ICON_NAME: case PROP_ICON_NAME:
g_value_set_string (value, st_icon_get_icon_name (icon)); g_value_set_string (value, st_icon_get_icon_name (icon));
break; break;
@ -246,6 +256,13 @@ st_icon_class_init (StIconClass *klass)
G_TYPE_ICON, G_TYPE_ICON,
ST_PARAM_READWRITE); 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] = props[PROP_ICON_NAME] =
g_param_spec_string ("icon-name", g_param_spec_string ("icon-name",
"Icon name", "Icon name",
@ -601,6 +618,47 @@ st_icon_set_gicon (StIcon *icon, GIcon *gicon)
st_icon_update (icon); 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: * st_icon_get_icon_size:
* @icon: an #StIcon * @icon: an #StIcon

View File

@ -60,6 +60,10 @@ GIcon *st_icon_get_gicon (StIcon *icon);
void st_icon_set_gicon (StIcon *icon, void st_icon_set_gicon (StIcon *icon,
GIcon *gicon); 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); const gchar *st_icon_get_icon_name (StIcon *icon);
void st_icon_set_icon_name (StIcon *icon, void st_icon_set_icon_name (StIcon *icon,
const gchar *icon_name); const gchar *icon_name);