File dconf-use-g_settings_get_default_value.patch of Package dconf

From b25b57872daa036adbafeddb6aaf1236407bed1b Mon Sep 17 00:00:00 2001
From: Mike Gorse <mgorse@suse.com>
Date: Thu, 1 May 2014 12:56:11 -0500
Subject: [PATCH] Use g_settings_get_default_value() to retrieve default values

GSettings now has an API to retrieve a default value, and using it is
more reliable than parsing the schema ourselves.

https://bugzilla.gnome.org/show_bug.cgi?id=668234
---
 editor/dconf-editor.vala |  5 +++-
 editor/dconf-model.vala  |  7 ++++-
 editor/dconf-schema.vala | 76 +-----------------------------------------------
 3 files changed, 11 insertions(+), 77 deletions(-)

diff --git a/editor/dconf-editor.vala b/editor/dconf-editor.vala
index 8174218..692c57e 100644
--- a/editor/dconf-editor.vala
+++ b/editor/dconf-editor.vala
@@ -235,7 +235,10 @@ class ConfigurationEditor : Gtk.Application
             if (selected_key.schema != null)
             {
                 var gettext_domain = selected_key.schema.gettext_domain;
+                Settings settings;
+
                 schema_name = selected_key.schema.schema.id;
+                settings = new Settings (schema_name);
                 if (selected_key.schema.summary != null)
                     summary = selected_key.schema.summary;
                 if (gettext_domain != null && summary != "")
@@ -245,7 +248,7 @@ class ConfigurationEditor : Gtk.Application
                 if (gettext_domain != null && description != "")
                     description = dgettext(gettext_domain, description);
                 type = key_to_description(selected_key);
-                default_value = selected_key.schema.default_value.print(false);
+                default_value = settings.get_default_value (((Key)(iter.user_data)).name).print(false);
             }
             else
             {
diff --git a/editor/dconf-model.vala b/editor/dconf-model.vala
index 8b43d60..ae25f86 100644
--- a/editor/dconf-model.vala
+++ b/editor/dconf-model.vala
@@ -37,6 +37,7 @@ public class Key : GLib.Object
     }
 
     private Variant? _value;
+    private Variant? _default_value;
     public Variant value
     {
         get
@@ -45,7 +46,11 @@ public class Key : GLib.Object
             if (_value != null)
                 return _value;
             else
-                return schema.default_value;
+            {
+                var settings = new Settings (schema.schema.id);
+                _default_value = settings.get_default_value (name);
+                return _default_value;
+            }
         }
         set
         {
diff --git a/editor/dconf-schema.vala b/editor/dconf-schema.vala
index fd35fb2..37c6571 100644
--- a/editor/dconf-schema.vala
+++ b/editor/dconf-schema.vala
@@ -3,7 +3,6 @@ public class SchemaKey
     public Schema schema;
     public string name;
     public string type;
-    public Variant default_value;
     public SchemaValueRange? range;
     public SchemaValueRange type_range;
     public List<SchemaChoice> choices;
@@ -42,15 +41,8 @@ public class SchemaKey
         {
             if (child->name == "default")
             {
-                try
-                {
-                    default_value = Variant.parse(new VariantType(type), child->get_content());
-                }
-                catch (VariantParseError e)
-                {
-                    // ...
+                // we use get_default_value(), so ignore this
                 }
-            }
             else if (child->name == "summary")
                 summary = child->get_content();
             else if (child->name == "description")
@@ -129,9 +121,6 @@ public class SchemaKey
             else if (child->type != Xml.ElementType.TEXT_NODE && child->type != Xml.ElementType.COMMENT_NODE)
                 warning ("Unknown child tag in <key>, <%s>", child->name);
         }
-
-        //if (default_value == null)
-        //    ?
     }
 }
 
@@ -248,9 +237,6 @@ public class SchemaEnum
             else if (child->type != Xml.ElementType.TEXT_NODE && child->type != Xml.ElementType.COMMENT_NODE)
                 warning ("Unknown tag in <enum>, <%s>", child->name);
         }
-        
-        //if (default_value == null)
-        //    ?
     }
 }
 
@@ -301,9 +287,6 @@ public class SchemaFlags
             else if (child->type != Xml.ElementType.TEXT_NODE && child->type != Xml.ElementType.COMMENT_NODE)
                 warning ("Unknown tag in <flags>, <%s>", child->name);
         }
-        
-        //if (default_value == null)
-        //    ?
     }
 }
 
@@ -407,53 +390,6 @@ 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
     {
         var directory = File.new_for_path(dir);
@@ -471,15 +407,5 @@ public class SchemaList
         }
 
         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();
-
-            if (name.has_suffix(".override"))
-                parse_override(Path.build_filename(dir, name, null));
-        }
     }
 }
-- 
1.8.4