theme-node: Add lookup_url/get_url() methods

Similar to the existing generic getter methods, add lookup functions
for URL properties like the standard background-image/border-image
properties.

https://bugzilla.gnome.org/show_bug.cgi?id=693688
This commit is contained in:
Florian Müllner 2013-04-16 14:43:51 +02:00
parent 2fc76e6d9e
commit 2b439ef209
2 changed files with 101 additions and 0 deletions

View File

@ -879,6 +879,101 @@ st_theme_node_get_double (StThemeNode *node,
}
}
/**
* st_theme_node_lookup_url:
* @node: a #StThemeNode
* @property_name: The name of the string property
* @inherit: if %TRUE, if a value is not found for the property on the
* node, then it will be looked up on the parent node, and then on the
* parent's parent, and so forth. Note that if the property has a
* value of 'inherit' it will be inherited even if %FALSE is passed
* in for @inherit; this only affects the default behavior for inheritance.
* @value: (out): location to store the newly allocated value that was
* determined. If the property is not found, the value in this location
* will not be changed.
*
* Looks up a property containing a single URL value.
*
* See also st_theme_node_get_url(), which provides a simpler API.
*
* Return value: %TRUE if the property was found in the properties for this
* theme node (or in the properties of parent nodes when inheriting.)
*/
gboolean
st_theme_node_lookup_url (StThemeNode *node,
const char *property_name,
gboolean inherit,
char **value)
{
gboolean result = FALSE;
int i;
ensure_properties (node);
for (i = node->n_properties - 1; i >= 0; i--)
{
CRDeclaration *decl = node->properties[i];
if (strcmp (decl->property->stryng->str, property_name) == 0)
{
CRTerm *term = decl->value;
CRStyleSheet *base_stylesheet;
GFile *file;
if (term->type != TERM_URI && term->type != TERM_STRING)
continue;
if (decl->parent_statement != NULL)
base_stylesheet = decl->parent_statement->parent_sheet;
else
base_stylesheet = NULL;
file = _st_theme_resolve_url (node->theme,
base_stylesheet,
decl->value->content.str->stryng->str);
*value = g_file_get_path (file);
g_object_unref (file);
result = TRUE;
break;
}
}
if (!result && inherit && node->parent_node)
result = st_theme_node_lookup_url (node->parent_node, property_name, inherit, value);
return result;
}
/*
* st_theme_node_get_url:
* @node: a #StThemeNode
* @property_name: The name of the string property
*
* Looks up a property containing a single URL value.
*
* See also st_theme_node_lookup_url(), which provides more options,
* and lets you handle the case where the theme does not specify the
* indicated value.
*
* Return value: the newly allocated value if found.
* If @property_name is not found, a warning will be logged and %NULL
* will be returned.
*/
char *
st_theme_node_get_url (StThemeNode *node,
const char *property_name)
{
char *value;
if (st_theme_node_lookup_url (node, property_name, FALSE, &value))
return value;
else
{
g_warning ("Did not find string property '%s'", property_name);
return NULL;
}
}
static const PangoFontDescription *
get_parent_font (StThemeNode *node)
{

View File

@ -142,6 +142,10 @@ gboolean st_theme_node_lookup_shadow (StThemeNode *node,
const char *property_name,
gboolean inherit,
StShadow **shadow);
gboolean st_theme_node_lookup_url (StThemeNode *node,
const char *property_name,
gboolean inherit,
char **value);
/* Easier-to-use variants of the above, for application-level use */
void st_theme_node_get_color (StThemeNode *node,
@ -153,6 +157,8 @@ gdouble st_theme_node_get_length (StThemeNode *node,
const char *property_name);
StShadow *st_theme_node_get_shadow (StThemeNode *node,
const char *property_name);
char *st_theme_node_get_url (StThemeNode *node,
const char *property_name);
/* Specific getters for particular properties: cached
*/