[banshee/browser-filters] Option to show/hide the genre filter (bgo#538005)



commit 6cea486661716abeff7b025a777de6474f8dcc0e
Author: Alexander Kojevnikov <alexander kojevnikov com>
Date:   Sat May 29 13:15:27 2010 +1000

    Option to show/hide the genre filter (bgo#538005)

 src/Clients/Nereid/Nereid/PlayerInterface.cs       |   19 +++++++++++
 .../Banshee.Library/LibrarySchema.cs               |    7 ++++
 .../Banshee.Library/MusicLibrarySource.cs          |    5 +++
 .../Banshee.Sources/DatabaseSource.cs              |    7 +++-
 .../CompositeTrackSourceContents.cs                |   34 +++++++++++--------
 .../FilteredListSourceContents.cs                  |   25 +++++++++-----
 .../InternetRadioSourceContents.cs                 |    1 +
 .../PodcastSourceContents.cs                       |    3 ++
 8 files changed, 77 insertions(+), 24 deletions(-)
---
diff --git a/src/Clients/Nereid/Nereid/PlayerInterface.cs b/src/Clients/Nereid/Nereid/PlayerInterface.cs
index 31bb762..8f829eb 100644
--- a/src/Clients/Nereid/Nereid/PlayerInterface.cs
+++ b/src/Clients/Nereid/Nereid/PlayerInterface.cs
@@ -44,6 +44,7 @@ using Banshee.Sources;
 using Banshee.Database;
 using Banshee.Collection;
 using Banshee.Collection.Database;
+using Banshee.Library;
 using Banshee.MediaEngine;
 using Banshee.Configuration;
 
@@ -362,6 +363,7 @@ namespace Nereid
 
             // Service events
             ServiceManager.SourceManager.ActiveSourceChanged += OnActiveSourceChanged;
+            ServiceManager.SourceManager.SourceAdded += OnSourceAdded;
             ServiceManager.SourceManager.SourceUpdated += OnSourceUpdated;
 
             ActionService.TrackActions ["SearchForSameArtistAction"].Activated += OnProgrammaticSearch;
@@ -547,6 +549,14 @@ namespace Nereid
             }
         }
 
+        private void OnSourceAdded (SourceEventArgs args)
+        {
+            if (args.Source is MusicLibrarySource) {
+                (args.Source as MusicLibrarySource).FiltersChanged += OnFiltersChanged;
+                OnFiltersChanged (args.Source, EventArgs.Empty);
+            }
+        }
+
         private void OnSourceUpdated (SourceEventArgs args)
         {
             if (args.Source == ServiceManager.SourceManager.ActiveSource) {
@@ -561,6 +571,15 @@ namespace Nereid
 
 #region UI Event Handlers
 
+        private void OnFiltersChanged (object sender, EventArgs e)
+        {
+            if (composite_view != null) {
+                ThreadAssist.ProxyToMain (delegate {
+                    composite_view.ResetViews ();
+                });
+            }
+        }
+
         private void OnSearchEntryChanged (object o, EventArgs args)
         {
             Source source = ServiceManager.SourceManager.ActiveSource;
diff --git a/src/Core/Banshee.Services/Banshee.Library/LibrarySchema.cs b/src/Core/Banshee.Services/Banshee.Library/LibrarySchema.cs
index 22b540a..f69ed73 100644
--- a/src/Core/Banshee.Services/Banshee.Library/LibrarySchema.cs
+++ b/src/Core/Banshee.Services/Banshee.Library/LibrarySchema.cs
@@ -92,5 +92,12 @@ namespace Banshee.Configuration.Schema
             "Sort tracks by album year",
             "If set the tracks will be sorted by album year instead of by album name"
         );
+
+        public static readonly SchemaEntry<bool> ShowGenre = new SchemaEntry<bool>(
+            "library", "show_genre",
+            true,
+            "Show genre in the browser",
+            "If enabled, the genre filter will be shown in the browser."
+        );
     }
 }
diff --git a/src/Core/Banshee.Services/Banshee.Library/MusicLibrarySource.cs b/src/Core/Banshee.Services/Banshee.Library/MusicLibrarySource.cs
index f549c27..ffbb52e 100644
--- a/src/Core/Banshee.Services/Banshee.Library/MusicLibrarySource.cs
+++ b/src/Core/Banshee.Services/Banshee.Library/MusicLibrarySource.cs
@@ -83,6 +83,11 @@ namespace Banshee.Library
                     DatabaseTrackModel.Reload ();
                 }
             ));
+
+            misc.Add (new SchemaPreference<bool> (LibrarySchema.ShowGenre,
+                Catalog.GetString ("Show the list of genres"), null, delegate {
+                    OnFiltersChanged ();
+                }));
         }
 
         public static string GetDefaultBaseDirectory ()
diff --git a/src/Core/Banshee.Services/Banshee.Sources/DatabaseSource.cs b/src/Core/Banshee.Services/Banshee.Sources/DatabaseSource.cs
index 08ea6aa..2b652d4 100644
--- a/src/Core/Banshee.Services/Banshee.Sources/DatabaseSource.cs
+++ b/src/Core/Banshee.Services/Banshee.Sources/DatabaseSource.cs
@@ -152,9 +152,9 @@ namespace Banshee.Sources
                 this.genre_model = genre_model;
             }
 
+            yield return genre_model;
             yield return artist_model;
             yield return album_model;
-            yield return genre_model;
         }
 
         protected virtual void AfterInitialized ()
@@ -388,6 +388,11 @@ namespace Banshee.Sources
                 current_filters_schema.Set (filters);
             }
 
+            OnFiltersChanged ();
+        }
+
+        protected void OnFiltersChanged ()
+        {
             EventHandler handler = FiltersChanged;
             if (handler != null) {
                 handler (this, EventArgs.Empty);
diff --git a/src/Core/Banshee.ThickClient/Banshee.Sources.Gui/CompositeTrackSourceContents.cs b/src/Core/Banshee.ThickClient/Banshee.Sources.Gui/CompositeTrackSourceContents.cs
index 366cbe1..918b6ad 100644
--- a/src/Core/Banshee.ThickClient/Banshee.Sources.Gui/CompositeTrackSourceContents.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.Sources.Gui/CompositeTrackSourceContents.cs
@@ -43,6 +43,7 @@ using Banshee.ServiceStack;
 using Banshee.Collection;
 using Banshee.Collection.Database;
 using Banshee.Configuration;
+using Banshee.Configuration.Schema;
 using Banshee.Gui;
 using Banshee.Collection.Gui;
 
@@ -50,7 +51,7 @@ namespace Banshee.Sources.Gui
 {
     public class CompositeTrackSourceContents : FilteredListSourceContents, ITrackModelSourceContents
     {
-        // private QueryFilterView<string> genre_view;
+        private QueryFilterView<string> genre_view;
         private ArtistListView artist_view;
         private AlbumListView album_view;
         private TrackListView track_view;
@@ -62,16 +63,19 @@ namespace Banshee.Sources.Gui
         protected override void InitializeViews ()
         {
             SetupMainView (track_view = new TrackListView ());
-            // SetupFilterView (genre_view = new QueryFilterView<string> (Catalog.GetString ("Not Set")));
+            SetupFilterView (genre_view = new QueryFilterView<string> (Catalog.GetString ("Not Set")));
             SetupFilterView (artist_view = new ArtistListView ());
             SetupFilterView (album_view = new AlbumListView ());
+            genre_view.Visible = LibrarySchema.ShowGenre.Get ();
+            artist_view.Visible = true;
+            album_view.Visible = true;
         }
 
         protected override void ClearFilterSelections ()
         {
-            // if (genre_view.Model != null) {
-            //     genre_view.Selection.Clear ();
-            // }
+            if (genre_view.Model != null) {
+                genre_view.Selection.Clear ();
+            }
 
             if (artist_view.Model != null) {
                 artist_view.Selection.Clear ();
@@ -82,12 +86,14 @@ namespace Banshee.Sources.Gui
             }
         }
 
-        public void SetModels (TrackListModel track, IListModel<ArtistInfo> artist, IListModel<AlbumInfo> album, IListModel<QueryFilterInfo<string>> genre)
+        public void ResetViews ()
         {
-            SetModel (track);
-            SetModel (artist);
-            SetModel (album);
-            // SetModel (genre);
+            bool show_genre = LibrarySchema.ShowGenre.Get ();
+            if (!show_genre && genre_view.Model != null) {
+                genre_view.Selection.Clear ();
+            }
+            genre_view.Visible = show_genre;
+            Layout ();
         }
 
         IListView<TrackInfo> ITrackModelSourceContents.TrackView {
@@ -132,10 +138,10 @@ namespace Banshee.Sources.Gui
                         SetModel (artist_view, (model as IListModel<ArtistInfo>));
                     else if (model is IListModel<AlbumInfo>)
                         SetModel (album_view, (model as IListModel<AlbumInfo>));
-                    // else if (model is IListModel<QueryFilterInfo<string>>)
-                    //    SetModel (genre_view, (model as IListModel<QueryFilterInfo<string>>));
+                    else if (model is IListModel<QueryFilterInfo<string>>)
+                       SetModel (genre_view, (model as IListModel<QueryFilterInfo<string>>));
                     // else
-                    //    Hyena.Log.DebugFormat ("CompositeTrackSourceContents got non-album/artist filter model: {0}", model);
+                    //    Hyena.Log.DebugFormat ("CompositeTrackSourceContents got non-genre/artist/album filter model: {0}", model);
                 }
             }
 
@@ -149,7 +155,7 @@ namespace Banshee.Sources.Gui
             SetModel (track_view, null);
             SetModel (artist_view, null);
             SetModel (album_view, null);
-            // SetModel (genre_view, null);
+            SetModel (genre_view, null);
             track_view.HeaderVisible = false;
         }
 
diff --git a/src/Core/Banshee.ThickClient/Banshee.Sources.Gui/FilteredListSourceContents.cs b/src/Core/Banshee.ThickClient/Banshee.Sources.Gui/FilteredListSourceContents.cs
index f4e32d2..f0b8958 100644
--- a/src/Core/Banshee.ThickClient/Banshee.Sources.Gui/FilteredListSourceContents.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.Sources.Gui/FilteredListSourceContents.cs
@@ -88,12 +88,7 @@ namespace Banshee.Sources.Gui
             this.name = name;
             InitializeViews ();
 
-            string position = ForcePosition == null ? BrowserPosition.Get () : ForcePosition;
-            if (position == "top") {
-                LayoutTop ();
-            } else {
-                LayoutLeft ();
-            }
+            string position = Layout ();
 
             if (ForcePosition != null) {
                 return;
@@ -206,6 +201,17 @@ namespace Banshee.Sources.Gui
             Layout (true);
         }
 
+        protected string Layout ()
+        {
+            string position = ForcePosition == null ? BrowserPosition.Get () : ForcePosition;
+            if (position == "top") {
+                LayoutTop ();
+            } else {
+                LayoutLeft ();
+            }
+            return position;
+        }
+
         private void Layout (bool top)
         {
             //Hyena.Log.Information ("ListBrowser LayoutLeft");
@@ -216,9 +222,10 @@ namespace Banshee.Sources.Gui
             filter_box.PositionSet = true;
             Paned current_pane = filter_box;
 
-            for (int i = 0; i < filter_scrolled_windows.Count; i++) {
-                ScrolledWindow window = filter_scrolled_windows[i];
-                bool last_even_filter = (i == filter_scrolled_windows.Count - 1 && filter_scrolled_windows.Count % 2 == 0);
+            var visible_windows = filter_scrolled_windows.FindAll (window => window.Child.Visible);
+            for (int i = 0; i < visible_windows.Count; i++) {
+                ScrolledWindow window = visible_windows[i];
+                bool last_even_filter = (i == visible_windows.Count - 1 && visible_windows.Count % 2 == 0);
                 if (i > 0 && !last_even_filter) {
                     Paned new_pane = GetPane (top);
                     current_pane.Pack2 (new_pane, true, false);
diff --git a/src/Extensions/Banshee.InternetRadio/Banshee.InternetRadio/InternetRadioSourceContents.cs b/src/Extensions/Banshee.InternetRadio/Banshee.InternetRadio/InternetRadioSourceContents.cs
index d25c6b5..27eec5d 100644
--- a/src/Extensions/Banshee.InternetRadio/Banshee.InternetRadio/InternetRadioSourceContents.cs
+++ b/src/Extensions/Banshee.InternetRadio/Banshee.InternetRadio/InternetRadioSourceContents.cs
@@ -60,6 +60,7 @@ namespace Banshee.InternetRadio
         {
             SetupMainView (track_view = new TrackListView ());
             SetupFilterView (genre_view = new QueryFilterView<string> (Catalog.GetString ("Not Set")));
+            genre_view.Visible = true;
         }
 
         protected override void ClearFilterSelections ()
diff --git a/src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Gui/PodcastSourceContents.cs b/src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Gui/PodcastSourceContents.cs
index 813b44d..3ae6c6e 100644
--- a/src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Gui/PodcastSourceContents.cs
+++ b/src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Gui/PodcastSourceContents.cs
@@ -68,6 +68,9 @@ namespace Banshee.Podcasting.Gui
             SetupFilterView (unheard_view = new PodcastUnheardFilterView ());
             SetupFilterView (download_view = new DownloadStatusFilterView ());
             SetupFilterView (feed_view = new PodcastFeedView ());
+            unheard_view.Visible = true;
+            download_view.Visible = true;
+            feed_view.Visible = true;
         }
 
         protected override void ClearFilterSelections ()



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