[banshee] [Banshee.ThickClient] Move BANSHEE_DISABLE_GRID switch to an option in the preferences



commit 8ba16f8c2c0a9188a2f4ea7cd085a768200b0998
Author: Andrés G. Aragoneses <knocte gmail com>
Date:   Mon May 24 05:36:43 2010 +0200

    [Banshee.ThickClient] Move BANSHEE_DISABLE_GRID switch to an option in the preferences
    
    Disabling the album grid in favour of the classic layout is now
    supported as a main configuration option (BGO#618122)

 .../Banshee.Sources/SourceManager.cs               |   10 +-
 .../Banshee.Collection.Gui/AlbumListView.cs        |  128 +++++++++++++++++---
 2 files changed, 115 insertions(+), 23 deletions(-)
---
diff --git a/src/Core/Banshee.Services/Banshee.Sources/SourceManager.cs b/src/Core/Banshee.Services/Banshee.Sources/SourceManager.cs
index c430b05..6878128 100644
--- a/src/Core/Banshee.Services/Banshee.Sources/SourceManager.cs
+++ b/src/Core/Banshee.Services/Banshee.Sources/SourceManager.cs
@@ -154,17 +154,17 @@ namespace Banshee.Sources
             source.ChildSourceAdded += OnChildSourceAdded;
             source.ChildSourceRemoved += OnChildSourceRemoved;
 
-            SourceAdded.SafeInvoke (new SourceAddedArgs () {
-                Position = position,
-                Source = source
-            });
-
             if (source is MusicLibrarySource) {
                 music_library = source as MusicLibrarySource;
             } else if (source is VideoLibrarySource) {
                 video_library = source as VideoLibrarySource;
             }
 
+            SourceAdded.SafeInvoke (new SourceAddedArgs () {
+                Position = position,
+                Source = source
+            });
+
             IDBusExportable exportable = source as IDBusExportable;
             if (exportable != null) {
                 ServiceManager.DBusServiceManager.RegisterObject (exportable);
diff --git a/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/AlbumListView.cs b/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/AlbumListView.cs
index 058e46a..3ad6e84 100644
--- a/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/AlbumListView.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/AlbumListView.cs
@@ -31,42 +31,134 @@ using System;
 using Hyena.Data;
 using Hyena.Data.Gui;
 
+using Banshee.Preferences;
+using Banshee.Configuration;
+using Banshee.Library;
 using Banshee.Collection;
 using Banshee.ServiceStack;
 using Banshee.MediaEngine;
 using Banshee.Gui;
 
+using Mono.Unix;
+
 namespace Banshee.Collection.Gui
 {
     public class AlbumListView : TrackFilterListView<AlbumInfo>
     {
         private ColumnCellAlbum renderer;
+        private Column classic_layout_column;
+        private DataViewLayoutGrid grid_layout;
+        private bool? album_grid_rendered = null;
 
         public AlbumListView () : base ()
         {
-            if (!String.IsNullOrEmpty (Environment.GetEnvironmentVariable ("BANSHEE_DISABLE_GRID"))) {
-                column_controller.Add (new Column ("Album", renderer = new ColumnCellAlbum (), 1.0));
-                ColumnController = column_controller;
-            } else {
-                var layout = new DataViewLayoutGrid () {
-                    ChildAllocator = () => new DataViewChildAlbum (),
-                    View = this
-                };
-
-                layout.ChildCountChanged += (o, e) => {
-                    var artwork_manager = ServiceManager.Get<ArtworkManager> ();
-                    if (artwork_manager != null && e.Value > 0) {
-                        int size = (int)((DataViewChildAlbum)layout[0]).ImageSize;
-                        artwork_manager.ChangeCacheSize (size, e.Value);
-                    }
-                };
-
-                ViewLayout = layout;
+            renderer = new ColumnCellAlbum ();
+            grid_layout = new DataViewLayoutGrid () {
+                ChildAllocator = () => new DataViewChildAlbum (),
+                View = this
+            };
+            grid_layout.ChildCountChanged += (o, e) => {
+                var artwork_manager = ServiceManager.Get<ArtworkManager> ();
+                if (artwork_manager != null && e.Value > 0) {
+                    int size = (int)((DataViewChildAlbum)grid_layout[0]).ImageSize;
+                    artwork_manager.ChangeCacheSize (size, e.Value);
+                }
+            };
+            ViewLayout = grid_layout;
+
+            ServiceManager.SourceManager.SourceRemoved += UninstallPreferences;
+            ServiceManager.SourceManager.SourceAdded += InstallPreferences;
+            if (ServiceManager.SourceManager.MusicLibrary != null) {
+                InstallPreferences ();
             }
 
+            DisableAlbumGridPref =  new SchemaPreference<bool> (DisableAlbumGrid,
+                    Catalog.GetString ("Disable album grid"),
+                    Catalog.GetString ("Disable album grid and show the classic layout instead"),
+                    ToggleAlbumGrid);
+
             ServiceManager.PlayerEngine.ConnectEvent (OnPlayerEvent, PlayerEvent.TrackInfoUpdated);
         }
 
+        private void ToggleAlbumGrid ()
+        {
+            if (album_grid_rendered.HasValue &&
+                !DisableAlbumGrid.Get ().Equals (album_grid_rendered.Value)) {
+                return;
+            }
+
+            DisabledAlbumGrid = DisableAlbumGrid.Get ();
+        }
+
+        private PreferenceBase disable_album_grid;
+        private MusicLibrarySource music_lib = null;
+
+        private void InstallPreferences (Sources.SourceAddedArgs args)
+        {
+            if (!args.Source.Equals (ServiceManager.SourceManager.MusicLibrary)) {
+                return;
+            }
+
+            InstallPreferences ();
+        }
+
+        private void InstallPreferences ()
+        {
+            music_lib = ServiceManager.SourceManager.MusicLibrary;
+            disable_album_grid = music_lib.PreferencesPage["misc"].Add (DisableAlbumGridPref);
+
+            ServiceManager.SourceManager.SourceAdded -= InstallPreferences;
+        }
+
+        private void UninstallPreferences (Sources.SourceEventArgs args)
+        {
+            if (args.Source.Equals (music_lib)) {
+                return;
+            }
+
+            music_lib.PreferencesPage["misc"].Remove (disable_album_grid);
+            music_lib = null;
+
+            ServiceManager.SourceManager.SourceRemoved -= UninstallPreferences;
+        }
+
+        private bool DisabledAlbumGrid {
+            get { return DisableAlbumGrid.Get (); }
+            set {
+                DisableAlbumGrid.Set (value);
+                if (value) {
+                    ViewLayout = null;
+                    if (classic_layout_column == null)
+                        classic_layout_column = new Column ("Album", renderer, 1.0);
+                    column_controller.Add (classic_layout_column);
+                    ColumnController = column_controller;
+                } else {
+                    if (classic_layout_column != null)
+                        column_controller.Remove (classic_layout_column);
+                    ColumnController = null;
+                    ViewLayout = grid_layout;
+                }
+                album_grid_rendered = !value;
+            }
+        }
+
+        private static SchemaPreference<bool> DisableAlbumGridPref = null;
+
+        private static readonly SchemaEntry<bool> DisableAlbumGrid = new SchemaEntry<bool> (
+            "player_window", "disable_album_grid",
+            false,
+            "Disable album grid",
+            "Disable album grid and show the classic layout instead"
+        );
+
+        protected override bool OnWidgetEvent (Gdk.Event evnt)
+        {
+            if (album_grid_rendered == null && evnt.Type == Gdk.EventType.Expose) {
+                ToggleAlbumGrid ();
+            }
+            return base.OnWidgetEvent (evnt);
+        }
+
         protected override Gdk.Size OnMeasureChild ()
         {
             return ViewLayout != null



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