[banshee/gtk3] ThickClient: adapt classes to have static SchemaEntries (GSettings friendly)



commit de6cf60f3b924ca77aee8e9fe647c551cb245172
Author: Andres G. Aragoneses <knocte gmail com>
Date:   Thu Dec 20 21:40:45 2012 +0000

    ThickClient: adapt classes to have static SchemaEntries (GSettings friendly)
    
    PersistentWindowController class had schema entries created at runtime
    which meant that the classes dependent on this GUI logic could not be
    inspected by GSettingsSchemaExtractor (static analysis) to find their
    configuration properly.
    
    With this change, we abstract this set of SchemaEntry instances related to
    window configuration (posizion, size, maximized|minimized) into a new class
    called WindowConfiguration, which has also some static helpers to avoid
    repeating the summary, description and default values of all the schema
    entries that have the same info.

 src/Clients/Muinshee/Muinshee/AlbumDialog.cs       |   11 ++-
 src/Clients/Muinshee/Muinshee/BaseDialog.cs        |    8 +-
 src/Clients/Muinshee/Muinshee/PlayerInterface.cs   |   13 +++-
 src/Clients/Muinshee/Muinshee/SongDialog.cs        |   11 ++-
 src/Clients/Nereid/Nereid/PlayerInterface.cs       |   11 ++-
 .../Banshee.Gui/BaseClientWindow.cs                |    4 +-
 .../Banshee.Gui/PersistentWindowController.cs      |   66 +++----------
 .../Banshee.Gui/WindowConfiguration.cs             |  104 ++++++++++++++++++++
 src/Core/Banshee.ThickClient/Makefile.am           |    1 +
 9 files changed, 169 insertions(+), 60 deletions(-)
---
diff --git a/src/Clients/Muinshee/Muinshee/AlbumDialog.cs b/src/Clients/Muinshee/Muinshee/AlbumDialog.cs
index b29ea75..7a75cf6 100644
--- a/src/Clients/Muinshee/Muinshee/AlbumDialog.cs
+++ b/src/Clients/Muinshee/Muinshee/AlbumDialog.cs
@@ -63,6 +63,13 @@ namespace Muinshee
 
     public class AlbumDialog : BaseDialog
     {
+        const string config_namespace = BaseDialog.ConfigNamespacePrefix + ".album";
+        static readonly SchemaEntry<int> WidthSchema = WindowConfiguration.NewWidthSchema (config_namespace, BaseDialog.DEFAULT_WIDTH);
+        static readonly SchemaEntry<int> HeightSchema = WindowConfiguration.NewHeightSchema (config_namespace, BaseDialog.DEFAULT_HEIGHT);
+        static readonly SchemaEntry<int> XPosSchema = WindowConfiguration.NewXPosSchema (config_namespace);
+        static readonly SchemaEntry<int> YPosSchema = WindowConfiguration.NewYPosSchema (config_namespace);
+        static readonly SchemaEntry<bool> MaximizedSchema = WindowConfiguration.NewMaximizedSchema (config_namespace);
+
         private static DatabaseAlbumListModel album_model;
 
         static AlbumDialog () {
@@ -74,7 +81,9 @@ namespace Muinshee
             }
         }
 
-        public AlbumDialog (PlaylistSource queue) : base (queue, Catalog.GetString ("Play Album"), "album")
+        public AlbumDialog (PlaylistSource queue) :
+            base (queue, Catalog.GetString ("Play Album"),
+                  new WindowConfiguration (WidthSchema, HeightSchema, XPosSchema, YPosSchema, MaximizedSchema))
         {
         }
 
diff --git a/src/Clients/Muinshee/Muinshee/BaseDialog.cs b/src/Clients/Muinshee/Muinshee/BaseDialog.cs
index 261ae86..8dededf 100644
--- a/src/Clients/Muinshee/Muinshee/BaseDialog.cs
+++ b/src/Clients/Muinshee/Muinshee/BaseDialog.cs
@@ -63,11 +63,15 @@ namespace Muinshee
 
     public abstract class BaseDialog : BansheeDialog
     {
+        protected const string CONFIG_NAMESPACE_PREFIX = "muinshee";
+        protected const int DEFAULT_WIDTH = 500;
+        protected const int DEFAULT_HEIGHT = 475;
+
         private SearchEntry search_entry;
         private PlaylistSource queue;
         private PersistentWindowController window_controller;
 
-        public BaseDialog (PlaylistSource queue, string title, string addType) : base (title)
+        public BaseDialog (PlaylistSource queue, string title, WindowConfiguration windowConfig) : base (title)
         {
             this.queue = queue;
             VBox.Spacing = 6;
@@ -99,7 +103,7 @@ namespace Muinshee
             Button play_button = new ImageButton (Catalog.GetString ("_Play"), "media-playback-start");
             AddButton (play_button, Gtk.ResponseType.Ok, true);
 
-            window_controller = new PersistentWindowController (this, String.Format ("muinshee.{0}", addType), 500, 475, WindowPersistOptions.Size);
+            window_controller = new PersistentWindowController (this, windowConfig, WindowPersistOptions.Size);
             window_controller.Restore ();
             ShowAll ();
 
diff --git a/src/Clients/Muinshee/Muinshee/PlayerInterface.cs b/src/Clients/Muinshee/Muinshee/PlayerInterface.cs
index b937573..f911a6f 100644
--- a/src/Clients/Muinshee/Muinshee/PlayerInterface.cs
+++ b/src/Clients/Muinshee/Muinshee/PlayerInterface.cs
@@ -59,6 +59,15 @@ namespace Muinshee
 {
     public class PlayerInterface : BaseClientWindow, IClientWindow, IDBusObjectName, IService, IDisposable
     {
+        const string CONFIG_NAMESPACE = "muinshee";
+        const int DEFAULT_WIDTH = -1;
+        const int DEFAULT_HEIGHT = 450;
+        static readonly SchemaEntry<int> WidthSchema = WindowConfiguration.NewWidthSchema (CONFIG_NAMESPACE, DEFAULT_WIDTH);
+        static readonly SchemaEntry<int> HeightSchema = WindowConfiguration.NewHeightSchema (CONFIG_NAMESPACE, DEFAULT_HEIGHT);
+        static readonly SchemaEntry<int> XPosSchema = WindowConfiguration.NewXPosSchema (CONFIG_NAMESPACE);
+        static readonly SchemaEntry<int> YPosSchema = WindowConfiguration.NewYPosSchema (CONFIG_NAMESPACE);
+        static readonly SchemaEntry<bool> MaximizedSchema = WindowConfiguration.NewMaximizedSchema (CONFIG_NAMESPACE);
+
         // Major Layout Components
         private VBox content_vbox;
         private VBox main_vbox;
@@ -73,7 +82,9 @@ namespace Muinshee
         private int played_songs_number = -1;
         private SchemaPreference<int> played_songs_number_pref;
 
-        public PlayerInterface () : base (Catalog.GetString ("Banshee Media Player"), "muinshee", -1, 450)
+        public PlayerInterface () :
+            base (Catalog.GetString ("Banshee Media Player"),
+                  new WindowConfiguration (WidthSchema, HeightSchema, XPosSchema, YPosSchema, MaximizedSchema))
         {
         }
 
diff --git a/src/Clients/Muinshee/Muinshee/SongDialog.cs b/src/Clients/Muinshee/Muinshee/SongDialog.cs
index 92da9b8..f9c9f41 100644
--- a/src/Clients/Muinshee/Muinshee/SongDialog.cs
+++ b/src/Clients/Muinshee/Muinshee/SongDialog.cs
@@ -50,7 +50,16 @@ namespace Muinshee
 {
     public class SongDialog : BaseDialog
     {
-        public SongDialog (PlaylistSource queue) : base (queue, Catalog.GetString ("Play Song"), "song")
+        const string CONFIG_NAMESPACE = BaseDialog.CONFIG_NAMESPACE_PREFIX + ".song";
+        static readonly SchemaEntry<int> WidthSchema = WindowConfiguration.NewWidthSchema (CONFIG_NAMESPACE, BaseDialog.DEFAULT_WIDTH);
+        static readonly SchemaEntry<int> HeightSchema = WindowConfiguration.NewHeightSchema (CONFIG_NAMESPACE, BaseDialog.DEFAULT_HEIGHT);
+        static readonly SchemaEntry<int> XPosSchema = WindowConfiguration.NewXPosSchema (CONFIG_NAMESPACE);
+        static readonly SchemaEntry<int> YPosSchema = WindowConfiguration.NewYPosSchema (CONFIG_NAMESPACE);
+        static readonly SchemaEntry<bool> MaximizedSchema = WindowConfiguration.NewMaximizedSchema (CONFIG_NAMESPACE);
+
+        public SongDialog (PlaylistSource queue) :
+            base (queue, Catalog.GetString ("Play Song"),
+                  new WindowConfiguration (WidthSchema, HeightSchema, XPosSchema, YPosSchema, MaximizedSchema))
         {
         }
 
diff --git a/src/Clients/Nereid/Nereid/PlayerInterface.cs b/src/Clients/Nereid/Nereid/PlayerInterface.cs
index ea4414f..45dadd7 100644
--- a/src/Clients/Nereid/Nereid/PlayerInterface.cs
+++ b/src/Clients/Nereid/Nereid/PlayerInterface.cs
@@ -58,6 +58,13 @@ namespace Nereid
 {
     public class PlayerInterface : BaseClientWindow, IClientWindow, IDBusObjectName, IService, IDisposable, IHasSourceView
     {
+        const string CONFIG_NAMESPACE = "player_window";
+        static readonly SchemaEntry<int> WidthSchema = WindowConfiguration.NewWidthSchema (CONFIG_NAMESPACE, 1024);
+        static readonly SchemaEntry<int> HeightSchema = WindowConfiguration.NewHeightSchema (CONFIG_NAMESPACE, 700);
+        static readonly SchemaEntry<int> XPosSchema = WindowConfiguration.NewXPosSchema (CONFIG_NAMESPACE);
+        static readonly SchemaEntry<int> YPosSchema = WindowConfiguration.NewYPosSchema (CONFIG_NAMESPACE);
+        static readonly SchemaEntry<bool> MaximizedSchema = WindowConfiguration.NewMaximizedSchema (CONFIG_NAMESPACE);
+
         // Major Layout Components
         private VBox primary_vbox;
         private Table header_table;
@@ -104,7 +111,9 @@ namespace Nereid
             }
         }
 
-        public PlayerInterface () : base (Catalog.GetString ("Banshee Media Player"), "player_window", 1024, 700)
+        public PlayerInterface () :
+            base (Catalog.GetString ("Banshee Media Player"),
+                  new WindowConfiguration (WidthSchema, HeightSchema, XPosSchema, YPosSchema, MaximizedSchema))
         {
             // if (PlatformDetection.IsMeeGo) {
             //     Gdk.Window.AddFilterForAll (OnGdkEventFilter);
diff --git a/src/Core/Banshee.ThickClient/Banshee.Gui/BaseClientWindow.cs b/src/Core/Banshee.ThickClient/Banshee.Gui/BaseClientWindow.cs
index 6eadb5b..14eac49 100644
--- a/src/Core/Banshee.ThickClient/Banshee.Gui/BaseClientWindow.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.Gui/BaseClientWindow.cs
@@ -61,14 +61,14 @@ namespace Banshee.Gui
         {
         }
 
-        public BaseClientWindow (string title, string configNameSpace, int defaultWidth, int defaultHeight) : base (title)
+        public BaseClientWindow (string title, WindowConfiguration windowConfiguration) : base (title)
         {
             elements_service = ServiceManager.Get<GtkElementsService> ();
             action_service = ServiceManager.Get<InterfaceActionService> ();
 
             ConfigureWindow ();
 
-            window_controller = new PersistentWindowController (this, configNameSpace, defaultWidth, defaultHeight, WindowPersistOptions.All);
+            window_controller = new PersistentWindowController (this, windowConfiguration, WindowPersistOptions.All);
             window_controller.Restore ();
 
             elements_service.PrimaryWindow = this;
diff --git a/src/Core/Banshee.ThickClient/Banshee.Gui/PersistentWindowController.cs b/src/Core/Banshee.ThickClient/Banshee.Gui/PersistentWindowController.cs
index 9018672..07e73cb 100644
--- a/src/Core/Banshee.ThickClient/Banshee.Gui/PersistentWindowController.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.Gui/PersistentWindowController.cs
@@ -47,45 +47,11 @@ namespace Banshee.Gui
         private uint timer_id = 0;
         private bool pending_changes;
 
-        public PersistentWindowController (Gtk.Window window, string configNameSpace, int defaultWidth, int defaultHeight, WindowPersistOptions options)
+        public PersistentWindowController (Gtk.Window window, WindowConfiguration windowConfig, WindowPersistOptions options)
         {
             this.window = window;
             this.options = options;
-
-            WidthSchema = new SchemaEntry<int>(
-                configNameSpace, "width",
-                defaultWidth,
-                "Window Width",
-                "Width of the main interface window."
-            );
-
-            HeightSchema = new SchemaEntry<int>(
-                configNameSpace, "height",
-                defaultHeight,
-                "Window Height",
-                "Height of the main interface window."
-            );
-
-            XPosSchema = new SchemaEntry<int>(
-                configNameSpace, "x_pos",
-                0,
-                "Window Position X",
-                "Pixel position of Main Player Window on the X Axis"
-            );
-
-            YPosSchema = new SchemaEntry<int>(
-                configNameSpace, "y_pos",
-                0,
-                "Window Position Y",
-                "Pixel position of Main Player Window on the Y Axis"
-            );
-
-            MaximizedSchema = new SchemaEntry<bool>(
-                configNameSpace, "maximized",
-                false,
-                "Window Maximized",
-                "True if main window is to be maximized, false if it is not."
-            );
+            this.window_config = windowConfig;
 
             window.ConfigureEvent += OnChanged;
             window.WindowStateEvent += OnChanged;
@@ -108,8 +74,8 @@ namespace Banshee.Gui
         public void Restore ()
         {
             if ((options & WindowPersistOptions.Size) != 0) {
-                int width = WidthSchema.Get ();
-                int height = HeightSchema.Get ();
+                int width = window_config.WidthSchema.Get ();
+                int height = window_config.HeightSchema.Get ();
 
                 if (width != 0 && height != 0) {
                     window.Resize (width, height);
@@ -117,8 +83,8 @@ namespace Banshee.Gui
             }
 
             if ((options & WindowPersistOptions.Position) != 0) {
-                int x = XPosSchema.Get ();
-                int y = YPosSchema.Get ();
+                int x = window_config.XPosSchema.Get ();
+                int y = window_config.YPosSchema.Get ();
 
                 if (x == 0 && y == 0) {
                     window.SetPosition (Gtk.WindowPosition.Center);
@@ -128,7 +94,7 @@ namespace Banshee.Gui
             }
 
             if ((options & WindowPersistOptions.Size) != 0) {
-                if (MaximizedSchema.Get ()) {
+                if (window_config.MaximizedSchema.Get ()) {
                     window.Maximize ();
                 } else {
                     window.Unmaximize ();
@@ -172,7 +138,7 @@ namespace Banshee.Gui
         private void InnerSave ()
         {
             if (maximized) {
-                MaximizedSchema.Set (true);
+                window_config.MaximizedSchema.Set (true);
                 return;
             }
 
@@ -180,17 +146,13 @@ namespace Banshee.Gui
                  return;
             }
 
-            MaximizedSchema.Set (false);
-            XPosSchema.Set (x);
-            YPosSchema.Set (y);
-            WidthSchema.Set (width);
-            HeightSchema.Set (height);
+            window_config.MaximizedSchema.Set (false);
+            window_config.XPosSchema.Set (x);
+            window_config.YPosSchema.Set (y);
+            window_config.WidthSchema.Set (width);
+            window_config.HeightSchema.Set (height);
         }
 
-        private SchemaEntry<int> WidthSchema;
-        private SchemaEntry<int> HeightSchema;
-        private SchemaEntry<int> XPosSchema;
-        private SchemaEntry<int> YPosSchema;
-        private SchemaEntry<bool> MaximizedSchema;
+        private WindowConfiguration window_config;
     }
 }
diff --git a/src/Core/Banshee.ThickClient/Banshee.Gui/WindowConfiguration.cs b/src/Core/Banshee.ThickClient/Banshee.Gui/WindowConfiguration.cs
new file mode 100644
index 0000000..73481af
--- /dev/null
+++ b/src/Core/Banshee.ThickClient/Banshee.Gui/WindowConfiguration.cs
@@ -0,0 +1,104 @@
+//
+// WindowConfiguration.cs
+//
+// Author:
+//   Andres G. Aragoneses <knocte gmail com>
+//
+// Copyright 2012 Andres G. Aragoneses
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+using System;
+using Banshee.Configuration;
+
+namespace Banshee.Gui
+{
+    public class WindowConfiguration
+    {
+        public SchemaEntry<int> WidthSchema { get; private set; }
+        public SchemaEntry<int> HeightSchema { get; private set; }
+        public SchemaEntry<int> XPosSchema { get; private set; }
+        public SchemaEntry<int> YPosSchema { get; private set; }
+        public SchemaEntry<bool> MaximizedSchema { get; private set; }
+
+        public WindowConfiguration (SchemaEntry<int> widthSchema,
+                                    SchemaEntry<int> heightSchema,
+                                    SchemaEntry<int> xPosSchema,
+                                    SchemaEntry<int> yPosSchema,
+                                    SchemaEntry<bool> maximizedSchema)
+        {
+            WidthSchema = widthSchema;
+            HeightSchema = heightSchema;
+            XPosSchema = xPosSchema;
+            YPosSchema = yPosSchema;
+            MaximizedSchema = maximizedSchema;
+        }
+
+        public static SchemaEntry<int> NewWidthSchema (string configNamespace, int defaultWidth)
+        {
+            return new SchemaEntry <int> (
+                configNamespace, "width",
+                defaultWidth,
+                "Window Width",
+                "Width of the main interface window."
+            );
+        }
+
+        public static SchemaEntry<int> NewHeightSchema (string configNamespace, int defaultHeight)
+        {
+            return new SchemaEntry <int> (
+                configNamespace, "height",
+                defaultHeight,
+                "Window Height",
+                "Height of the main interface window."
+            );
+        }
+
+        public static SchemaEntry<int> NewXPosSchema (string configNamespace)
+        {
+            return new SchemaEntry <int> (
+                configNamespace, "x_pos",
+                0,
+                "Window Position X",
+                "Pixel position of Main Player Window on the X Axis"
+            );
+        }
+
+        public static SchemaEntry<int> NewYPosSchema (string configNamespace)
+        {
+            return new SchemaEntry <int> (
+                configNamespace, "y_pos",
+                0,
+                "Window Position Y",
+                "Pixel position of Main Player Window on the Y Axis"
+            );
+        }
+
+        public static SchemaEntry<bool> NewMaximizedSchema (string configNamespace)
+        {
+            return new SchemaEntry <bool> (
+                configNamespace, "maximized",
+                false,
+                "Window Maximized",
+                "True if main window is to be maximized, false if it is not."
+            );
+        }
+    }
+}
+
diff --git a/src/Core/Banshee.ThickClient/Makefile.am b/src/Core/Banshee.ThickClient/Makefile.am
index 5eeaff2..6e54ae7 100644
--- a/src/Core/Banshee.ThickClient/Makefile.am
+++ b/src/Core/Banshee.ThickClient/Makefile.am
@@ -126,6 +126,7 @@ SOURCES =  \
 	Banshee.Gui/SourceActions.cs \
 	Banshee.Gui/TrackActions.cs \
 	Banshee.Gui/ViewActions.cs \
+	Banshee.Gui/WindowConfiguration.cs \
 	Banshee.Library.Gui/FileImportSource.cs \
 	Banshee.Library.Gui/FolderImportSource.cs \
 	Banshee.Library.Gui/ImportDialog.cs \



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