[banshee/gtk3] GSettings: extractor to find internal SchemaEntry instances too



commit 4835694fc7281d40b5d85c97b246f17785220053
Author: Andres G. Aragoneses <knocte gmail com>
Date:   Thu Mar 28 00:29:05 2013 +0000

    GSettings: extractor to find internal SchemaEntry instances too
    
    There were some internal/private SchemaEntry instances in some classes
    that the extractor should be able to inspect.
    
    For this, a new unit test is added, and the following issue is fixed:
    when finding these new set of SchemaEntry instances in the AlbumDialog
    class in Muinshe, a NullReferenceException [1] would be thrown because
    the access to the class via Reflection would trigger the execution of
    its static ctor, which would depend on Banshee running properly to work
    (as it would inspect MusicLibrarySource.CurrentFilters property). To fix
    this, the static ctor is removed, and the usage of the album_model field
    (that was being initialized in this static ctor) is replaced by a property
    which is lazily initialized.
    
    [1] Unhandled Exception:
    System.TypeInitializationException: An exception was thrown by the type initializer for 
Muinshee.AlbumDialog ---> System.NullReferenceException: Object reference not set to an instance of an object
      at Muinshee.BaseDialog.get_Music () [0x00000] in 
/home/andres1210/Code/bansheeGTK3/src/Clients/Muinshee/Muinshee/BaseDialog.cs:154
      at Muinshee.AlbumDialog..cctor () [0x00000] in <filename unknown>:0
      --- End of inner exception stack trace ---
      at (wrapper managed-to-native) System.Reflection.MonoField:GetValueInternal 
(System.Reflection.MonoField,object)
      at System.Reflection.MonoField.GetValue (System.Object obj) [0x0006a] in 
/home/andres1210/Code/system_mono/mono/mcs/class/corlib/System.Reflection/MonoField.cs:125
      at GSettingsSchemaExtractorProgram+GSettingsKey.ExtractFromField (SchemaSet schemaSet, 
System.Reflection.FieldInfo field) [0x00000] in <filename unknown>:0
      at GSettingsSchemaExtractorProgram.Extract (IEnumerable`1 types) [0x00000] in <filename unknown>:0
      at GSettingsSchemaExtractorProgram.Extract (System.IO.DirectoryInfo dir) [0x00000] in <filename 
unknown>:0
      at GSettingsSchemaExtractorProgram.Main (System.String[] args) [0x00000] in <filename unknown>:0

 build/GSettingsSchemaExtractor.cs            |    4 +++-
 build/GSettingsSchemaExtractorTests.cs       |   18 ++++++++++++++++++
 src/Clients/Muinshee/Muinshee/AlbumDialog.cs |   20 ++++++++++++--------
 3 files changed, 33 insertions(+), 9 deletions(-)
---
diff --git a/build/GSettingsSchemaExtractor.cs b/build/GSettingsSchemaExtractor.cs
index cf178dc..e4c2804 100644
--- a/build/GSettingsSchemaExtractor.cs
+++ b/build/GSettingsSchemaExtractor.cs
@@ -65,7 +65,9 @@ public class GSettingsSchemaExtractorProgram
         schema_fields = new HashSet<FieldInfo> ();
 
         foreach (Type type in types) {
-            foreach (FieldInfo field in type.GetFields (BindingFlags.Public | BindingFlags.Static)) {
+            foreach (FieldInfo field in type.GetFields (BindingFlags.Public |
+                                                        BindingFlags.NonPublic |
+                                                        BindingFlags.Static)) {
                 if (CheckForValidEntry (type, field)) {
                     schema_fields.Add (field);
                 }
diff --git a/build/GSettingsSchemaExtractorTests.cs b/build/GSettingsSchemaExtractorTests.cs
index 458821a..3d20c97 100644
--- a/build/GSettingsSchemaExtractorTests.cs
+++ b/build/GSettingsSchemaExtractorTests.cs
@@ -240,6 +240,24 @@ namespace GSettingsSchemaExtractor
                 .Trim ()));
         }
 
+        internal class TypeWithInternalSchema {
+            internal static readonly SchemaEntry<int> VolumeSchema = new SchemaEntry<int> (
+                "player_engine", "volume",
+                80,
+                "Volume",
+                "Volume of playback relative to mixer output"
+            );
+        }
+
+        [Test]
+        public void SchemaNonPublic ()
+        {
+            StringBuilder result = GSettingsSchemaExtractorProgram.Extract (new Type [] { typeof 
(TypeWithInternalSchema) });
+
+            Assert.That (result, Is.Not.Null);
+            Assert.That (result.ToString ().Trim (), Is.StringContaining ("<schema id="));
+        }
+
     }
 }
 
diff --git a/src/Clients/Muinshee/Muinshee/AlbumDialog.cs b/src/Clients/Muinshee/Muinshee/AlbumDialog.cs
index 12c2f1f..8bc80ee 100644
--- a/src/Clients/Muinshee/Muinshee/AlbumDialog.cs
+++ b/src/Clients/Muinshee/Muinshee/AlbumDialog.cs
@@ -71,13 +71,17 @@ namespace Muinshee
         static readonly SchemaEntry<bool> MaximizedSchema = WindowConfiguration.NewMaximizedSchema 
(CONFIG_NAMESPACE);
 
         private static DatabaseAlbumListModel album_model;
-
-        static AlbumDialog () {
-            // TODO set the Album filter as the one/only current filter
-            foreach (IFilterListModel filter in Music.CurrentFilters) {
-                if (filter is DatabaseAlbumListModel) {
-                    album_model = filter as DatabaseAlbumListModel;
+        private static DatabaseAlbumListModel AlbumModel {
+            get {
+                if (album_model == null) {
+                    // TODO set the Album filter as the one/only current filter
+                    foreach (IFilterListModel filter in Music.CurrentFilters) {
+                        if (filter is DatabaseAlbumListModel) {
+                            album_model = filter as DatabaseAlbumListModel;
+                        }
+                    }
                 }
+                return album_model;
             }
         }
 
@@ -90,7 +94,7 @@ namespace Muinshee
         protected override Widget GetItemWidget ()
         {
             AlbumListView album_view = new MuinsheeAlbumView ();
-            album_view.SetModel (album_model);
+            album_view.SetModel (AlbumModel);
 
             album_view.RowActivated += OnRowActivated;
             return album_view;
@@ -107,7 +111,7 @@ namespace Muinshee
 
         public override void Destroy ()
         {
-            album_model.Selection.Clear ();
+            AlbumModel.Selection.Clear ();
             base.Destroy ();
         }
 


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