[dconf-editor] Make Schema and SchemaKey structs.



commit f550810ac0873f9f31f05787207b99f0c3f106bb
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Sun Oct 4 21:02:44 2015 +0200

    Make Schema and SchemaKey structs.

 editor/Makefile.am       |    1 -
 editor/dconf-model.vala  |   53 ++++++++++++++++++++++++++++++++++++++----
 editor/dconf-schema.vala |   58 ----------------------------------------------
 po/POTFILES.in           |    1 -
 po/POTFILES.skip         |    1 -
 5 files changed, 48 insertions(+), 66 deletions(-)
---
diff --git a/editor/Makefile.am b/editor/Makefile.am
index aed8195..341f34f 100644
--- a/editor/Makefile.am
+++ b/editor/Makefile.am
@@ -38,7 +38,6 @@ dconf_editor_SOURCES = \
        dconf-editor.vala \
        dconf-window.vala \
        dconf-model.vala \
-       dconf-schema.vala \
        dconf-view.vala
 
 desktopdir = $(datadir)/applications
diff --git a/editor/dconf-model.vala b/editor/dconf-model.vala
index 8b480fd..286d740 100644
--- a/editor/dconf-model.vala
+++ b/editor/dconf-model.vala
@@ -15,6 +15,18 @@
   along with Dconf Editor.  If not, see <http://www.gnu.org/licenses/>.
 */
 
+public struct SchemaKey
+{
+    public string schema_id;
+    public string name;
+    public string? summary;
+    public string? description;
+    public Variant default_value;
+    public string type;
+    public string range_type;
+    public Variant range_content;
+}
+
 public class Key : GLib.Object
 {
     private SettingsModel model;
@@ -212,10 +224,16 @@ public class Directory : GLib.Object
     }
 }
 
+public struct Schema
+{
+    public string path;
+    public GLib.HashTable<string, SchemaKey?> keys;
+}
+
 public class SettingsModel: GLib.Object, Gtk.TreeModel
 {
-    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, 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 DConf.Client client;
     private Directory root;
@@ -254,11 +272,36 @@ public class SettingsModel: GLib.Object, Gtk.TreeModel
     public void create_schema (SettingsSchema settings_schema)
     {
         string schema_id = settings_schema.get_id ();
-        Schema schema = new Schema ();
-        schema.path = settings_schema.get_path ();          // TODO will always returns null for relocatable 
schemas
+        Schema schema = Schema () {
+                path = settings_schema.get_path (),     // TODO will always returns null for relocatable 
schemas
+                keys = new GLib.HashTable<string, SchemaKey?> (str_hash, str_equal)
+            };
+
         foreach (string key_id in settings_schema.list_keys ())
         {
-            SchemaKey key = new SchemaKey (schema_id, settings_schema.get_key (key_id));
+            SettingsSchemaKey settings_schema_key = settings_schema.get_key (key_id);
+
+            string range_type = settings_schema_key.get_range ().get_child_value (0).get_string (); // don’t 
put it in the switch, or it fails
+            string type;
+            switch (range_type)
+            {
+                case "enum":    type = "<enum>"; break;  // <choices> or enum="", and hopefully <aliases>
+                case "flags":   type = "as";     break;  // TODO better
+                default:
+                case "type":    type = (string) settings_schema_key.get_value_type ().peek_string (); break;
+            }
+
+            SchemaKey key = SchemaKey () {
+                    schema_id = schema_id,
+                    name = settings_schema_key.get_name (),
+                    summary = settings_schema_key.get_summary (),
+                    description = settings_schema_key.get_description (),
+                    default_value = settings_schema_key.get_default_value (),
+                    type = type,
+                    range_type = range_type,
+                    range_content = settings_schema_key.get_range ().get_child_value (1).get_child_value (0)
+                };
+
             schema.keys.insert (key.name, key);
             keys.insert (schema.path + key.name, key);
         }
diff --git a/po/POTFILES.in b/po/POTFILES.in
index ca4a43c..6fc96fc 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -5,7 +5,6 @@ editor/ca.desrt.dconf-editor.desktop.in.in
 [type: gettext/glade]editor/dconf-editor.ui
 editor/dconf-editor.vala
 editor/dconf-model.vala
-editor/dconf-schema.vala
 editor/dconf-view.vala
 editor/dconf-window.vala
 [type: gettext/glade]editor/key-editor.ui
diff --git a/po/POTFILES.skip b/po/POTFILES.skip
index 29eb772..02e0154 100644
--- a/po/POTFILES.skip
+++ b/po/POTFILES.skip
@@ -2,7 +2,6 @@ editor/ca.desrt.dconf-editor.desktop.in
 editor/dconf-editor.c
 editor/dconf-window.c
 editor/dconf-model.c
-editor/dconf-schema.c
 editor/dconf-view.c
 # Autotools failure
 sub/editor/ca.desrt.dconf-editor.desktop.in


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