summaryrefslogtreecommitdiff
path: root/libcaribou
diff options
context:
space:
mode:
authorEitan Isaacson <eitan@monotonous.org>2011-05-31 11:33:38 -0700
committerEitan Isaacson <eitan@monotonous.org>2011-06-01 12:47:01 -0700
commit22ed36c74597159cf4866abee35bb898127dea5a (patch)
tree8d69b0934a709fdc033fc0e91212866c2b2ec254 /libcaribou
parent6e333d1e0ac6bf25b70b16341bf70d3adc17137d (diff)
downloadcaribou-22ed36c74597159cf4866abee35bb898127dea5a.tar.gz
Have UI choose keyboard type.
Diffstat (limited to 'libcaribou')
-rw-r--r--libcaribou/json-deserializer.vala24
-rw-r--r--libcaribou/keyboard-model.vala10
2 files changed, 20 insertions, 14 deletions
diff --git a/libcaribou/json-deserializer.vala b/libcaribou/json-deserializer.vala
index 818655c..ea448a4 100644
--- a/libcaribou/json-deserializer.vala
+++ b/libcaribou/json-deserializer.vala
@@ -18,23 +18,22 @@ namespace Caribou {
return false;
}
- public static GLib.File get_layout_file (string group,
+ public static GLib.File get_layout_file (string keyboard_type, string group,
string variant) throws IOError {
- Settings caribou_settings = new Settings ("org.gnome.caribou");
- string kb_type = caribou_settings.get_string("keyboard-type");
List<string> dirs = new List<string> ();
string custom_dir = Environment.get_variable("CARIBOU_LAYOUTS_DIR");
if (custom_dir != null)
- dirs.append (Path.build_filename (custom_dir, "layouts", kb_type));
+ dirs.append (Path.build_filename (custom_dir, "layouts",
+ keyboard_type));
dirs.append (Path.build_filename (Environment.get_user_data_dir (),
- "caribou", "layouts", kb_type));
+ "caribou", "layouts", keyboard_type));
foreach (string data_dir in Environment.get_system_data_dirs ()) {
dirs.append (Path.build_filename (
- data_dir, "caribou", "layouts", kb_type));
+ data_dir, "caribou", "layouts", keyboard_type));
}
foreach (string data_dir in dirs) {
@@ -46,19 +45,22 @@ namespace Caribou {
throw new IOError.NOT_FOUND (
"Could not find layout file for %s %s", group, variant); }
- public static bool load_group (GroupModel group) {
+ public static GroupModel? load_group (string keyboard_type,
+ string group, string variant) {
Json.Parser parser = new Json.Parser ();
try {
- GLib.File f = get_layout_file (group.group, group.variant);
+ GLib.File f = get_layout_file (keyboard_type, group, variant);
parser.load_from_stream (f.read (), (Cancellable) null);
- create_levels_from_json (group, parser.get_root ());
} catch (GLib.Error e) {
stdout.printf ("Failed to load JSON: %s\n", e.message);
- return false;
+ return null;
}
- return true;
+ GroupModel grp = new GroupModel (group, variant);
+ create_levels_from_json (grp, parser.get_root ());
+
+ return grp;
}
public static void create_levels_from_json (GroupModel group,
diff --git a/libcaribou/keyboard-model.vala b/libcaribou/keyboard-model.vala
index a1fa2fc..3b06c9f 100644
--- a/libcaribou/keyboard-model.vala
+++ b/libcaribou/keyboard-model.vala
@@ -3,6 +3,7 @@ using Bus;
namespace Caribou {
public class KeyboardModel : Object {
public string active_group { get; private set; default = ""; }
+ public string keyboard_type { get; construct; }
XAdapter xadapter;
HashTable<string, GroupModel> groups;
@@ -13,13 +14,15 @@ namespace Caribou {
string[] grps, variants;
int i;
- groups = new HashTable<string, GroupModel> (str_hash, str_equal);
+ assert (keyboard_type != null);
xadapter = XAdapter.get_default ();
xadapter.group_changed.connect (on_group_changed);
xadapter.get_groups (out grps, out variants);
+ groups = new HashTable<string, GroupModel> (str_hash, str_equal);
+
for (i=0;i<grps.length;i++)
populate_group (grps[i], variants[i]);
@@ -28,8 +31,9 @@ namespace Caribou {
}
private void populate_group (string group, string variant) {
- GroupModel grp = new GroupModel (group, variant);
- if (JsonDeserializer.load_group (grp))
+ GroupModel grp = JsonDeserializer.load_group (keyboard_type,
+ group, variant);
+ if (grp != null)
groups.insert (GroupModel.create_group_name (group, variant), grp);
}