[banshee/gtk3] build: properly join keys belonging to same GSettings schema



commit 4c6c034158771e5659cef82dc842a7a033f5a725
Author: Andres G. Aragoneses <knocte gmail com>
Date:   Tue Dec 18 21:14:09 2012 +0000

    build: properly join keys belonging to same GSettings schema
    
    In GConf, every key would be embedded in its own <schema> tag, as the
    test included in this commit demonstrates.
    
    However, in GSettings, keys belonging to the same schema must be included
    within the same <schema> tag. This commits introduces a test for this, and
    the solution.

 build/GConfSchemaExtractorTests.cs     |   50 ++++++++++++++++++++++++++++++++
 build/GSettingsSchemaExtractor.cs      |   25 +++++++++------
 build/GSettingsSchemaExtractorTests.cs |   33 +++++++++++++++++++++
 3 files changed, 98 insertions(+), 10 deletions(-)
---
diff --git a/build/GConfSchemaExtractorTests.cs b/build/GConfSchemaExtractorTests.cs
index a47ba44..da39fd5 100644
--- a/build/GConfSchemaExtractorTests.cs
+++ b/build/GConfSchemaExtractorTests.cs
@@ -213,6 +213,56 @@ namespace GConfSchemaExtractor
 </gconfschemafile>"
                 .Trim ()));
         }
+
+        [Test]
+        public void SchemaWithMoreThanOneKey ()
+        {
+            StringBuilder result = GConfSchemaExtractorProgram.Extract (
+                new Type [] { typeof (IntegerType), typeof (DoubleType), typeof (StringType) });
+
+            Assert.That (result, Is.Not.Null);
+            Assert.That (result.ToString ().Trim (), Is.EqualTo (@"
+<?xml version=""1.0""?>
+<gconfschemafile>
+  <schemalist>
+    <schema>
+      <key>/schemas/apps/banshee/player_engine/volume</key>
+      <applyto>/apps/banshee/player_engine/volume</applyto>
+      <owner>banshee</owner>
+      <type>int</type>
+      <default>80</default>
+      <locale name=""C"">
+        <short>Volume</short>
+        <long>Volume of playback relative to mixer output</long>
+      </locale>
+    </schema>
+    <schema>
+      <key>/schemas/apps/banshee/player_window/cover_art_size</key>
+      <applyto>/apps/banshee/player_window/cover_art_size</applyto>
+      <owner>banshee</owner>
+      <type>float</type>
+      <default>20.5</default>
+      <locale name=""C"">
+        <short>Cover art size</short>
+        <long>Surface size of cover art in the album grid</long>
+      </locale>
+    </schema>
+    <schema>
+      <key>/schemas/apps/banshee/player_window/default_export_format</key>
+      <applyto>/apps/banshee/player_window/default_export_format</applyto>
+      <owner>banshee</owner>
+      <type>string</type>
+      <default>m3u</default>
+      <locale name=""C"">
+        <short>Export Format</short>
+        <long>The default playlist export format</long>
+      </locale>
+    </schema>
+  </schemalist>
+</gconfschemafile>
+"
+                .Trim ()));
+        }
     }
 }
 
diff --git a/build/GSettingsSchemaExtractor.cs b/build/GSettingsSchemaExtractor.cs
index 33aea86..10eb544 100644
--- a/build/GSettingsSchemaExtractor.cs
+++ b/build/GSettingsSchemaExtractor.cs
@@ -7,7 +7,7 @@ using System.Reflection;
 
 public class GSettingsSchemaExtractorProgram
 {
-    private static Dictionary<string, StringBuilder> entries;
+    private static Dictionary<string, List<StringBuilder>> entries;
     private static int schema_count;
 
     public static void Main(string [] args)
@@ -34,7 +34,7 @@ public class GSettingsSchemaExtractorProgram
     internal static StringBuilder Extract (IEnumerable<Type> types)
     {
         schema_count = 0;
-        entries = new Dictionary<string, StringBuilder> ();
+        entries = new Dictionary<string, List<StringBuilder>> ();
 
         foreach (Type type in types) {
             foreach (FieldInfo field in type.GetFields ()) {
@@ -61,11 +61,15 @@ public class GSettingsSchemaExtractorProgram
             StringBuilder final = new StringBuilder ();
             final.Append ("<schemalist>\n");
 
-            List<string> keys = new List<string> (entries.Keys);
-            keys.Sort ();
+            List<string> schemas = new List<string> (entries.Keys);
+            schemas.Sort ();
 
-            foreach(string key in keys) {
-                final.Append (entries [key]);
+            foreach (string id in schemas) {
+                final.AppendFormat ("  <schema id=\"{0}\" path=\"{1}\" gettext-domain=\"banshee\">\n", id, GetPath (id));
+                foreach (StringBuilder sb in entries [id]) {
+                    final.Append (sb);
+                }
+                final.Append ("  </schema>\n");
             }
 
             final.Append ("</schemalist>\n");
@@ -108,7 +112,6 @@ public class GSettingsSchemaExtractorProgram
         schema_count++;
 
         string id = CreateId (namespce);
-        string path = GetPath (id);
         
         bool list = value.GetType ().IsArray;
         Type type = list ? Type.GetTypeArray ((object [])value) [0] : value.GetType ();
@@ -140,14 +143,16 @@ public class GSettingsSchemaExtractorProgram
         }
 
         StringBuilder builder = new StringBuilder ();
-        builder.AppendFormat ("  <schema id=\"{0}\" path=\"{1}\" gettext-domain=\"banshee\">\n", id, path);
         builder.AppendFormat ("    <key name=\"{0}\" type=\"{1}\">\n", key, type_attrib);
         builder.AppendFormat ("      <default>{0}</default>\n", str_val);
         builder.AppendFormat ("      <_summary>{0}</_summary>\n", summary);
         builder.AppendFormat ("      <_description>{0}</_description>\n", description);
         builder.AppendFormat ("    </key>\n");
-        builder.AppendFormat ("  </schema>\n");
-        entries.Add (id + key, builder);
+        if (entries.ContainsKey (id)) {
+            entries [id].Add (builder);
+        } else {
+            entries [id] = new List<StringBuilder> { builder };
+        }
     }
         
     private static string CamelCaseToUnderCase (string s)
diff --git a/build/GSettingsSchemaExtractorTests.cs b/build/GSettingsSchemaExtractorTests.cs
index 1c5aadd..6181787 100644
--- a/build/GSettingsSchemaExtractorTests.cs
+++ b/build/GSettingsSchemaExtractorTests.cs
@@ -177,6 +177,39 @@ namespace GSettingsSchemaExtractor
 </schemalist>"
                 .Trim ()));
         }
+
+        [Test]
+        public void SchemaWithMoreThanOneKey ()
+        {
+            StringBuilder result = GSettingsSchemaExtractorProgram.Extract (
+                new Type [] { typeof (IntegerType), typeof (DoubleType), typeof (StringType) });
+
+            Assert.That (result, Is.Not.Null);
+            Assert.That (result.ToString ().Trim (), Is.EqualTo (@"
+<schemalist>
+  <schema id=""org.gnome.banshee.player_engine"" path=""/apps/banshee/player_engine/"" gettext-domain=""banshee"">
+    <key name=""volume"" type=""i"">
+      <default>80</default>
+      <_summary>Volume</_summary>
+      <_description>Volume of playback relative to mixer output</_description>
+    </key>
+  </schema>
+  <schema id=""org.gnome.banshee.player_window"" path=""/apps/banshee/player_window/"" gettext-domain=""banshee"">
+    <key name=""cover_art_size"" type=""d"">
+      <default>20.5</default>
+      <_summary>Cover art size</_summary>
+      <_description>Surface size of cover art in the album grid</_description>
+    </key>
+    <key name=""default_export_format"" type=""s"">
+      <default>'m3u'</default>
+      <_summary>Export Format</_summary>
+      <_description>The default playlist export format</_description>
+    </key>
+  </schema>
+</schemalist>"
+                .Trim ()));
+        }
+
     }
 }
 



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