[gnome-shell] theme-node: Add lookup_url/get_url() methods
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell] theme-node: Add lookup_url/get_url() methods
- Date: Tue, 16 Apr 2013 17:27:50 +0000 (UTC)
commit 2b439ef2096aaeaf66ff8508df8b4ed16fe48c46
Author: Florian Müllner <fmuellner gnome org>
Date: Tue Apr 16 14:43:51 2013 +0200
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
src/st/st-theme-node.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++
src/st/st-theme-node.h | 6 ++++
2 files changed, 101 insertions(+)
---
diff --git a/src/st/st-theme-node.c b/src/st/st-theme-node.c
index 8e2e7b7..db6b023 100644
--- a/src/st/st-theme-node.c
+++ b/src/st/st-theme-node.c
@@ -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)
{
diff --git a/src/st/st-theme-node.h b/src/st/st-theme-node.h
index 98da358..4a5f58c 100644
--- a/src/st/st-theme-node.h
+++ b/src/st/st-theme-node.h
@@ -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
*/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]