[banshee/better-now-playing] [ContextPane] Hide ContextPages when they are irrelevant to the currently playing track.
- From: Alex Launi <alexlauni src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [banshee/better-now-playing] [ContextPane] Hide ContextPages when they are irrelevant to the currently playing track.
- Date: Fri, 18 Jun 2010 00:25:49 +0000 (UTC)
commit 7e9937d9e49aa962e629d0719828469435080450
Author: Alex Launi <alex launi gmail com>
Date: Thu Jun 17 19:43:25 2010 -0400
[ContextPane] Hide ContextPages when they are irrelevant to the currently playing track.
Add API to BaseContextPage so that pages can declare what types of media they support
displaying context for. In ContextPageManager we check the pages and update the list
of pages to only show the pages which are relevant to the playing track.
.../Banshee.ContextPane/BaseContextPage.cs | 5 ++
.../Banshee.ContextPane/BaseContextView.cs | 1 +
.../Banshee.ContextPane/ContextPageManager.cs | 49 +++++++++++++++++++-
3 files changed, 53 insertions(+), 2 deletions(-)
---
diff --git a/src/Core/Banshee.ThickClient/Banshee.ContextPane/BaseContextPage.cs b/src/Core/Banshee.ThickClient/Banshee.ContextPane/BaseContextPage.cs
index f13d25d..3190ba9 100644
--- a/src/Core/Banshee.ThickClient/Banshee.ContextPane/BaseContextPage.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.ContextPane/BaseContextPage.cs
@@ -61,9 +61,14 @@ namespace Banshee.ContextPane
}
}
+
+ public bool Hidden { get; set; }
public string Id { get; protected set; }
public string Name { get; protected set;}
public string [] IconNames { get; protected set;}
+ public virtual TrackMediaAttributes SupportedMediaAttributes {
+ get { return TrackMediaAttributes.Default; }
+ }
public abstract Widget Widget { get; }
public abstract void SetTrack (TrackInfo track);
diff --git a/src/Core/Banshee.ThickClient/Banshee.ContextPane/BaseContextView.cs b/src/Core/Banshee.ThickClient/Banshee.ContextPane/BaseContextView.cs
index f5fd642..3446592 100644
--- a/src/Core/Banshee.ThickClient/Banshee.ContextPane/BaseContextView.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.ContextPane/BaseContextView.cs
@@ -124,6 +124,7 @@ namespace Banshee.ContextPane
if (Enabled) {
SetCurrentTrackForActivePage ();
}
+
}
protected void SetCurrentTrackForActivePage ()
diff --git a/src/Core/Banshee.ThickClient/Banshee.ContextPane/ContextPageManager.cs b/src/Core/Banshee.ThickClient/Banshee.ContextPane/ContextPageManager.cs
index f0e5207..78b60db 100644
--- a/src/Core/Banshee.ThickClient/Banshee.ContextPane/ContextPageManager.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.ContextPane/ContextPageManager.cs
@@ -28,9 +28,15 @@
using System;
using System.Collections.Generic;
-using Mono.Addins;
+using System.Linq;
+
using Gtk;
+using Mono.Addins;
+
+using Banshee.Collection;
using Banshee.Gui;
+using Banshee.MediaEngine;
+using Banshee.ServiceStack;
namespace Banshee.ContextPane
{
@@ -48,20 +54,54 @@ namespace Banshee.ContextPane
public void Init ()
{
Mono.Addins.AddinManager.AddExtensionNodeHandler ("/Banshee/ThickClient/ContextPane", OnExtensionChanged);
+ ServiceManager.PlayerEngine.ConnectEvent (OnPlayerEvent, PlayerEvent.StartOfStream | PlayerEvent.TrackInfoUpdated);
}
public IEnumerable<BaseContextPage> Pages {
get {
- return pages.Values;
+ return pages.Values.Where (p => !p.Hidden);
+ }
+ }
+
+ private void UpdateAvailablePages ()
+ {
+ foreach (BaseContextPage page in Pages) {
+ bool hidden = page.Hidden;
+ SetPageVisibilityForTrack (page);
+
+ // If the visibility of the page changes we fire this signal
+ if (hidden != page.Hidden && !page.Hidden) {
+ var handler = PageAdded;
+ if (handler != null) {
+ handler (page);
+ }
+ } else if (hidden != page.Hidden && page.Hidden) {
+ var handler = PageRemoved;
+ if (handler != null) {
+ handler (page);
+ }
+ }
}
}
+ private void SetPageVisibilityForTrack (BaseContextPage page)
+ {
+ TrackInfo track = ServiceManager.PlayerEngine.CurrentTrack;
+ if (track == null) {
+ page.Hidden = false;
+ return;
+ }
+
+ page.Hidden = !track.HasAttribute (page.SupportedMediaAttributes);
+ }
+
private void OnExtensionChanged (object o, ExtensionNodeEventArgs args)
{
TypeExtensionNode node = (TypeExtensionNode) args.ExtensionNode;
if (args.Change == ExtensionChange.Add) {
var page = (BaseContextPage) node.CreateInstance ();
+ SetPageVisibilityForTrack (page);
pages.Add (node.Id, page);
var handler = PageAdded;
if (handler != null) {
@@ -84,5 +124,10 @@ namespace Banshee.ContextPane
page.Dispose ();
}
}
+
+ private void OnPlayerEvent (PlayerEventArgs args)
+ {
+ UpdateAvailablePages ();
+ }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]