[caribou] Use Gee.HashMap and not GLib.HashTable.



commit d004beab98726b95e844212479cb541d4461efc6
Author: Eitan Isaacson <eitan monotonous org>
Date:   Tue May 31 12:15:34 2011 -0700

    Use Gee.HashMap and not GLib.HashTable.

 libcaribou/Makefile.am         |    1 -
 libcaribou/group-model.vala    |   19 ++++++-------------
 libcaribou/keyboard-model.vala |   21 +++++++--------------
 libcaribou/util.vala           |   13 -------------
 4 files changed, 13 insertions(+), 41 deletions(-)
---
diff --git a/libcaribou/Makefile.am b/libcaribou/Makefile.am
index a329030..e879eb3 100644
--- a/libcaribou/Makefile.am
+++ b/libcaribou/Makefile.am
@@ -39,7 +39,6 @@ libcaribou_la_SOURCES = \
 	key-model.vala \
 	column-model.vala \
 	scanner.vala \
-	util.vala \
 	json-deserializer.vala \
 	iscannable-item.vala \
 	iscannable-group.vala \
diff --git a/libcaribou/group-model.vala b/libcaribou/group-model.vala
index 1a111ae..279e9a3 100644
--- a/libcaribou/group-model.vala
+++ b/libcaribou/group-model.vala
@@ -7,12 +7,12 @@ namespace Caribou {
         public string group;
         public string variant;
         private string default_level;
-        private HashTable<string, LevelModel> levels;
+        private Gee.HashMap<string, LevelModel> levels;
 
         public GroupModel (string group, string variant) {
             this.group = group;
             this.variant = variant;
-            levels = new HashTable<string, LevelModel> (str_hash, str_equal);
+            levels = new Gee.HashMap<string, LevelModel> (str_hash, str_equal);
             active_level = default_level;
         }
 
@@ -24,7 +24,7 @@ namespace Caribou {
         }
 
         internal void add_level (string lname, LevelModel level) {
-            levels.insert (lname, level);
+            levels.set (lname, level);
             level.level_toggled.connect(on_level_toggled);
             if (level.mode == "default") {
                 default_level = lname;
@@ -33,11 +33,11 @@ namespace Caribou {
         }
 
         public string[] get_levels () {
-            return Util.list_to_array (levels.get_keys ());
+            return (string[]) levels.keys.to_array ();
         }
 
         public LevelModel get_level (string level_name) {
-            return levels.lookup(level_name);
+            return levels.get (level_name);
         }
 
         private void on_level_toggled (string new_level) {
@@ -48,14 +48,7 @@ namespace Caribou {
         }
 
         public IKeyboardObject[] get_children () {
-            IKeyboardObject[] children = new IKeyboardObject[levels.size ()];
-            uint i = 0;
-
-            foreach (LevelModel obj in levels.get_values ()) {
-                children[i++] = (IKeyboardObject) obj;
-            }
-
-            return children;
+            return (IKeyboardObject[]) levels.values.to_array ();
         }
 
     }
diff --git a/libcaribou/keyboard-model.vala b/libcaribou/keyboard-model.vala
index 64813f2..99c3b6e 100644
--- a/libcaribou/keyboard-model.vala
+++ b/libcaribou/keyboard-model.vala
@@ -6,7 +6,7 @@ namespace Caribou {
         public string keyboard_type { get; construct; }
 
         XAdapter xadapter;
-        HashTable<string, GroupModel> groups;
+        Gee.HashMap<string, GroupModel> groups;
 
         construct {
             uint grpid;
@@ -21,7 +21,7 @@ namespace Caribou {
 
             xadapter.get_groups (out grps, out variants);
 
-            groups = new HashTable<string, GroupModel> (str_hash, str_equal);
+            groups = new Gee.HashMap<string, GroupModel> (str_hash, str_equal);
 
             for (i=0;i<grps.length;i++)
                 populate_group (grps[i], variants[i]);
@@ -34,20 +34,20 @@ namespace Caribou {
             GroupModel grp = JsonDeserializer.load_group (keyboard_type,
                                                           group, variant);
             if (grp != null)
-                groups.insert (GroupModel.create_group_name (group, variant), grp);
+                groups.set (GroupModel.create_group_name (group, variant), grp);
         }
 
         public string[] get_groups () {
-            return Util.list_to_array (groups.get_keys ());
+            return (string[]) groups.keys.to_array ();
         }
 
         public GroupModel get_group (string group_name) {
-            return groups.lookup (group_name);
+            return groups.get (group_name);
         }
 
         private void on_group_changed (uint grpid, string group, string variant) {
             string group_name = GroupModel.create_group_name (group, variant);
-            if (groups.lookup (group_name) != null) {
+            if (groups.get (group_name) != null) {
                 active_group = group_name;
             } else {
                 active_group = get_groups ()[0];
@@ -55,14 +55,7 @@ namespace Caribou {
         }
 
         public IKeyboardObject[] get_children () {
-            IKeyboardObject[] children = new IKeyboardObject[groups.size ()];
-            uint i = 0;
-
-            foreach (GroupModel obj in groups.get_values ()) {
-                children[i++] = (IKeyboardObject) obj;
-            }
-
-            return children;
+            return (IKeyboardObject[]) groups.values.to_array ();
         }
     }
 }
\ No newline at end of file



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]