diff options
author | Daiki Ueno <ueno@unixuser.org> | 2012-11-17 10:27:12 +0900 |
---|---|---|
committer | Daiki Ueno <ueno@unixuser.org> | 2012-11-22 17:26:02 +0900 |
commit | aac59640e793752d1ae815ffea4d9113f77679e0 (patch) | |
tree | 57417ca570e963f3e26f1ba7857b5b8c14eef7d4 /libcaribou/xml-deserializer.vala | |
parent | 7da19a8125017d81834aed26c60f55db5fea1d51 (diff) | |
download | caribou-aac59640e793752d1ae815ffea4d9113f77679e0.tar.gz |
libcaribou: refactor some code
Use Gee lists and hashtables extensively instead of GLib's;
specify proper cname to libxklavier signals to avoid using
a static signal handler; remove unnecessary "using".
https://bugzilla.gnome.org/show_bug.cgi?id=688517
Diffstat (limited to 'libcaribou/xml-deserializer.vala')
-rw-r--r-- | libcaribou/xml-deserializer.vala | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/libcaribou/xml-deserializer.vala b/libcaribou/xml-deserializer.vala index 4bfc088..8058c0f 100644 --- a/libcaribou/xml-deserializer.vala +++ b/libcaribou/xml-deserializer.vala @@ -1,5 +1,3 @@ -using Xml; - namespace Caribou { private class XmlDeserializer : Object { @@ -22,19 +20,19 @@ namespace Caribou { public static string get_layout_file (string keyboard_type, string group, string variant) throws IOError { - List<string> dirs = new List<string> (); + Gee.ArrayList<string> dirs = new Gee.ArrayList<string> (); string custom_dir = Environment.get_variable("CARIBOU_LAYOUTS_DIR"); if (custom_dir != null) - dirs.append (Path.build_filename (custom_dir, "layouts", - keyboard_type)); + dirs.add (Path.build_filename (custom_dir, "layouts", + keyboard_type)); - dirs.append (Path.build_filename (Environment.get_user_data_dir (), - "caribou", "layouts", keyboard_type)); + dirs.add (Path.build_filename (Environment.get_user_data_dir (), + "caribou", "layouts", keyboard_type)); foreach (string dir in Environment.get_system_data_dirs ()) { - dirs.append (Path.build_filename ( - dir, "caribou", "layouts", keyboard_type)); + dirs.add (Path.build_filename ( + dir, "caribou", "layouts", keyboard_type)); } foreach (string data_dir in dirs) { @@ -57,11 +55,11 @@ namespace Caribou { public static GroupModel? load_group (string keyboard_type, string group, string variant) { - Doc* doc; + Xml.Doc* doc; try { string fn = get_layout_file (keyboard_type, group, variant); - doc = Parser.parse_file (fn); + doc = Xml.Parser.parse_file (fn); if (doc == null) throw new IOError.FAILED ( "Cannot load XML text reader for %s", fn); @@ -76,7 +74,7 @@ namespace Caribou { create_levels_from_xml (grp, node); delete doc; - Parser.cleanup (); + Xml.Parser.cleanup (); return grp; } @@ -85,7 +83,7 @@ namespace Caribou { Xml.Node* node) { assert (node->name == "layout"); for (Xml.Node* iter = node->children; iter != null; iter = iter->next) { - if (iter->type != ElementType.ELEMENT_NODE) + if (iter->type != Xml.ElementType.ELEMENT_NODE) continue; string levelname = iter->get_prop ("name"); @@ -101,14 +99,14 @@ namespace Caribou { public static void load_rows (LevelModel level, Xml.Node* node) { assert (node->name == "level"); for (Xml.Node* i = node->children; i != null; i = i->next) { - if (i->type != ElementType.ELEMENT_NODE) + if (i->type != Xml.ElementType.ELEMENT_NODE) continue; RowModel row = new RowModel (); level.add_row (row); for (Xml.Node* i2 = i->children; i2 != null; i2 = i2->next) { - if (i2->type != ElementType.ELEMENT_NODE) + if (i2->type != Xml.ElementType.ELEMENT_NODE) continue; if (i2->name == "key") { @@ -126,7 +124,7 @@ namespace Caribou { row.add_column (column); for (Xml.Node* i = node->children; i != null; i = i->next) { - if (i->type != ElementType.ELEMENT_NODE) + if (i->type != Xml.ElementType.ELEMENT_NODE) continue; column.add_key (load_key (i, align)); @@ -146,7 +144,7 @@ namespace Caribou { if (align != null) key.align = align; - for (Attr* prop = node->properties; prop != null; prop = prop->next) { + for (Xml.Attr* prop = node->properties; prop != null; prop = prop->next) { if (prop->name == "toggle") key.toggle = prop->children->content; else if (prop->name == "align") @@ -156,7 +154,7 @@ namespace Caribou { } for (Xml.Node* i = node->children; i != null; i = i->next) { - if (i->type != ElementType.ELEMENT_NODE) + if (i->type != Xml.ElementType.ELEMENT_NODE) continue; key.add_subkey (load_key (i, null)); |