diff options
author | Robert Ancell <robert.ancell@canonical.com> | 2012-10-01 11:08:08 +1300 |
---|---|---|
committer | Robert Ancell <robert.ancell@canonical.com> | 2012-10-01 11:08:08 +1300 |
commit | 2cfa1d503a0a58014778149b6c353ea1d9b446f8 (patch) | |
tree | f8c6b5b112de972d52f3941a2f490007c7e64cc4 /editor | |
parent | 344bdb99b8ef2be5361a4af18d6ab7ace9a07e44 (diff) | |
download | dconf-2cfa1d503a0a58014778149b6c353ea1d9b446f8.tar.gz |
editor: Decode schema overrides
https://bugzilla.gnome.org/show_bug.cgi?id=654812
Diffstat (limited to 'editor')
-rw-r--r-- | editor/dconf-model.vala | 2 | ||||
-rw-r--r-- | editor/dconf-schema.vala | 80 |
2 files changed, 71 insertions, 11 deletions
diff --git a/editor/dconf-model.vala b/editor/dconf-model.vala index ff45a29..fe95ffe 100644 --- a/editor/dconf-model.vala +++ b/editor/dconf-model.vala @@ -601,7 +601,7 @@ public class SettingsModel: GLib.Object, Gtk.TreeModel } /* Add keys for the values in the schemas */ - foreach (var schema in schemas.schemas) + foreach (var schema in schemas.schemas.get_values()) root.load_schema(schema, schema.path[1:schema.path.length]); } diff --git a/editor/dconf-schema.vala b/editor/dconf-schema.vala index 0365603..fd35fb2 100644 --- a/editor/dconf-schema.vala +++ b/editor/dconf-schema.vala @@ -345,7 +345,7 @@ public class Schema public class SchemaList { - public GLib.List<Schema> schemas = new GLib.List<Schema>(); + public GLib.HashTable<string, Schema> schemas = new GLib.HashTable<string, Schema>(str_hash, str_equal); public GLib.HashTable<string, SchemaKey> keys = new GLib.HashTable<string, SchemaKey>(str_hash, str_equal); public GLib.HashTable<string, SchemaEnum> enums = new GLib.HashTable<string, SchemaEnum>(str_hash, str_equal); public GLib.HashTable<string, SchemaFlags> flags = new GLib.HashTable<string, SchemaFlags>(str_hash, str_equal); @@ -385,7 +385,7 @@ public class SchemaList string full_name = schema.path + key.name; keys.insert(full_name, key); } - schemas.append(schema); + schemas.insert(schema.id, schema); } else if (node->name == "enum") { @@ -407,19 +407,79 @@ public class SchemaList delete doc; } + public void parse_override(string path) + { + var keyfile = new KeyFile(); + try + { + keyfile.load_from_file(path, KeyFileFlags.NONE); + } + catch (Error e) + { + warning("Failed to load override file %s: %s", path, e.message); + return; + } + + foreach (var group in keyfile.get_groups()) + { + var schema = schemas.lookup(group); + if (schema == null) + continue; + + string[] keys; + try { keys = keyfile.get_keys(group); } catch (Error e) { continue; } + + foreach (var key_name in keys) + { + string value; + try { value = keyfile.get_value(group, key_name); } catch (Error e) { continue; } + + var key = schema.keys.lookup (key_name); + if (key == null) + continue; + + Variant default_value; + try + { + default_value = Variant.parse(new VariantType(key.type), value); + } + catch (VariantParseError e) + { + // ... + continue; + } + + key.default_value = default_value; + } + } + } + public void load_directory(string dir) throws Error { - File directory = File.new_for_path(dir); + var directory = File.new_for_path(dir); + var i = directory.enumerate_children (FileAttribute.STANDARD_NAME, 0, null); - FileInfo info; - while ((info = i.next_file (null)) != null) { - string name = info.get_name(); + while (true) + { + var info = i.next_file (null); + if (info == null) + break; + var name = info.get_name(); - if (!name.has_suffix(".gschema.xml") && !name.has_suffix(".enums.xml")) - continue; + if (name.has_suffix(".gschema.xml") || name.has_suffix(".enums.xml")) + parse_file(Path.build_filename(dir, name, null)); + } + + i = directory.enumerate_children (FileAttribute.STANDARD_NAME, 0, null); + while (true) + { + var info = i.next_file (null); + if (info == null) + break; + var name = info.get_name(); - string path = Path.build_filename(dir, name, null); - parse_file(path); + if (name.has_suffix(".override")) + parse_override(Path.build_filename(dir, name, null)); } } } |