summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Ancell <robert.ancell@canonical.com>2011-03-10 16:28:33 +1100
committerRobert Ancell <robert.ancell@canonical.com>2011-03-10 16:28:33 +1100
commita48204f8582e0d039c68ea2fdeb65f56660530a8 (patch)
tree48d7a43c73a1702b0c1fe384bb29a7de9f107b0d
parent9ad8fec5ff0e6790286b624f98c0b2926ccb5eb9 (diff)
downloaddconf-a48204f8582e0d039c68ea2fdeb65f56660530a8.tar.gz
editor: Decode choices and aliases
-rw-r--r--editor/dconf-schema.vala95
1 files changed, 84 insertions, 11 deletions
diff --git a/editor/dconf-schema.vala b/editor/dconf-schema.vala
index c67759b..3520d60 100644
--- a/editor/dconf-schema.vala
+++ b/editor/dconf-schema.vala
@@ -6,6 +6,7 @@ public class SchemaKey
public Variant default_value;
public SchemaValueRange? range;
public SchemaValueRange type_range;
+ public List<Variant> choices;
public string? enum_name;
public string? summary;
public string? description;
@@ -38,21 +39,93 @@ public class SchemaKey
{
if (child->name == "default")
{
- try
- {
- default_value = Variant.parse(new VariantType(type), child->children->content);
- }
- catch (VariantParseError e)
- {
- // ...
- }
+ try
+ {
+ default_value = Variant.parse(new VariantType(type), child->children->content);
+ }
+ catch (VariantParseError e)
+ {
+ // ...
+ }
}
else if (child->name == "summary")
- summary = child->children->content;
+ summary = child->children->content;
else if (child->name == "description")
- description = child->children->content;
+ description = child->children->content;
else if (child->name == "range")
- range = new SchemaValueRange.from_xml(type, child);
+ range = new SchemaValueRange.from_xml(type, child);
+ else if (child->name == "choices")
+ {
+ for (var n = child->children; n != null; n = n->next)
+ {
+ if (n->name != "choice")
+ {
+ warning ("Unknown child tag in <choices>, <%s>", n->name);
+ continue;
+ }
+
+ string? value = null;
+ for (var prop = n->properties; prop != null; prop = prop->next)
+ {
+ if (prop->name == "value")
+ value = prop->children->content;
+ else
+ warning ("Unknown property on <choice>, %s", prop->name);
+ }
+
+ if (value == null)
+ {
+ warning ("Ignoring <choice> with no value");
+ continue;
+ }
+
+ Variant v;
+ try
+ {
+ v = Variant.parse(new VariantType(type), value);
+ choices.append (v);
+ }
+ catch (VariantParseError e)
+ {
+ warning ("Invalid choice value '%s'", value);
+ }
+ }
+ }
+ else if (child->name == "aliases")
+ {
+ for (var n = child->children; n != null; n = n->next)
+ {
+ if (n->name != "alias")
+ {
+ warning ("Unknown child tag in <aliases>, <%s>", n->name);
+ continue;
+ }
+
+ string? value = null, target = null;
+ for (var prop = n->properties; prop != null; prop = prop->next)
+ {
+ if (prop->name == "value")
+ value = prop->children->content;
+ else if (prop->name == "target")
+ target = prop->children->content;
+ else
+ warning ("Unknown property on <alias>, %s", prop->name);
+ }
+
+ if (value == null)
+ {
+ warning ("Ignoring <alias> with no value");
+ continue;
+ }
+ if (target == null)
+ {
+ warning ("Ignoring <alias> with no target");
+ continue;
+ }
+
+ // FIXME: Use it
+ }
+ }
else if (child->type != Xml.ElementType.TEXT_NODE && child->type != Xml.ElementType.COMMENT_NODE)
warning ("Unknown child tag in <key>, <%s>", child->name);
}