[banshee/better-now-playing: 32/32] [NowPlaying] Dynamically add all context page sources to now playing toolbar



commit c3180e5ce8f5022489ab3d1423fd1b6891abb366
Author: Alex Launi <alex launi gmail com>
Date:   Thu Jun 3 17:34:45 2010 -0400

    [NowPlaying] Dynamically add all context page sources to now playing toolbar
    
    Instead of hardcoding some PoC sources into the toolbar, actually loop through
    loaded pages and add them to the toolbar. Also make them set the contents of
    the now playing source to that context page.

 .../Banshee.ContextPane/ContextPane.cs             |    6 ++-
 .../Banshee.NowPlaying/Actions.cs                  |   42 +++++++++++++++----
 .../Banshee.NowPlaying/NowPlayingSource.cs         |    6 +-
 3 files changed, 41 insertions(+), 13 deletions(-)
---
diff --git a/src/Core/Banshee.ThickClient/Banshee.ContextPane/ContextPane.cs b/src/Core/Banshee.ThickClient/Banshee.ContextPane/ContextPane.cs
index 88b0a60..5f11b1a 100644
--- a/src/Core/Banshee.ThickClient/Banshee.ContextPane/ContextPane.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.ContextPane/ContextPane.cs
@@ -70,6 +70,10 @@ namespace Banshee.ContextPane
             set { expand_handler = value; }
         }
 
+        public List<BaseContextPage> Pages {
+            get { return pages; }
+        }
+
         public bool Large {
             get { return large; }
         }
@@ -223,7 +227,7 @@ namespace Banshee.ContextPane
             vbox.Visible = true;//enabled && npages > 1;
         }
 
-        private void SetActivePage (BaseContextPage page)
+        public void SetActivePage (BaseContextPage page)
         {
             if (page == null || page == active_page)
                 return;
diff --git a/src/Extensions/Banshee.NowPlaying/Banshee.NowPlaying/Actions.cs b/src/Extensions/Banshee.NowPlaying/Banshee.NowPlaying/Actions.cs
index 770d135..8e8d47e 100644
--- a/src/Extensions/Banshee.NowPlaying/Banshee.NowPlaying/Actions.cs
+++ b/src/Extensions/Banshee.NowPlaying/Banshee.NowPlaying/Actions.cs
@@ -43,25 +43,48 @@ namespace Banshee.NowPlaying
 {
     public class Actions : BansheeActionGroup
     {
+        public const string TrackInfoId = "StandardNpOpen";
+
+        private Dictionary<int, BaseContextPage> pages;
         private NowPlayingSource now_playing_source;
 
         public Actions (NowPlayingSource nowPlayingSource) : base ("NowPlaying")
         {
+            int i = 0;
             now_playing_source = nowPlayingSource;
+            pages = new Dictionary<int, BaseContextPage> ();
+            ContextPane = new ContextPane.ContextPane ();
+            List<RadioActionEntry> actions = new List<RadioActionEntry> ();
 
-            Add (new RadioActionEntry [] {
-                new RadioActionEntry ("StandardNpOpen", null, null, null, "Now Playing", 0),
-                new RadioActionEntry ("LastFmOpen", null, null, null, "Last.fm recommendations", 1),
-                new RadioActionEntry ("WikipediaOpen", null, null, null, "Wikipedia", 2)
-            }, 0, OnChanged);
+            actions.Add (new RadioActionEntry (TrackInfoId, null, null, null, "Track Information", i));
 
-            this["StandardNpOpen"].IconName = "applications-multimedia";
-            this["LastFmOpen"].IconName = "lastfm-audioscrobbler";
-            this["WikipediaOpen"].IconName = "wikipedia";
+            foreach (BaseContextPage page in ContextPane.Pages) {
+                i++;
+                actions.Add (new RadioActionEntry (page.Id, null, null, null, page.Name, i));
+                pages.Add (i, page);
+            }
+
+            Add (actions.ToArray (), 0, OnChanged);
+
+            this[TrackInfoId].IconName = "applications-multimedia";
+            foreach (BaseContextPage page in ContextPane.Pages) {
+                foreach (string icon in page.IconNames) {
+                    if (IconThemeUtils.HasIcon (icon)) {
+                        this[page.Id].IconName = icon;
+                        break;
+                    }
+                }
+            }
 
             Register ();
+        }
 
-            ContextPane = new ContextPane.ContextPane ();
+        // We've got 1 hard coded action available and the rest come from the context pane.
+        // so we loop through our pages and get their ids and return an IEnumerable with them all.
+        public IEnumerable<string> PageIds {
+            get {
+                return new string [] { TrackInfoId }.Concat (pages.Values.Select (p => p.Id));
+            }
         }
 
         public void OnChanged (System.Object o, ChangedArgs args)
@@ -71,6 +94,7 @@ namespace Banshee.NowPlaying
             if (args.Current.CurrentValue == 0) {
                 now_playing_source.SetSubstituteAudioDisplay (null);
             } else {
+                ContextPane.SetActivePage (pages[args.Current.CurrentValue]);
                 now_playing_source.SetSubstituteAudioDisplay (ContextPane);
             }
         }
diff --git a/src/Extensions/Banshee.NowPlaying/Banshee.NowPlaying/NowPlayingSource.cs b/src/Extensions/Banshee.NowPlaying/Banshee.NowPlaying/NowPlayingSource.cs
index fbbd9bc..8b9c2a2 100644
--- a/src/Extensions/Banshee.NowPlaying/Banshee.NowPlaying/NowPlayingSource.cs
+++ b/src/Extensions/Banshee.NowPlaying/Banshee.NowPlaying/NowPlayingSource.cs
@@ -77,9 +77,9 @@ namespace Banshee.NowPlaying
             Actions.Visible = ServiceManager.SourceManager.ActiveSource == this;
 
             ui_manager = ServiceManager.Get<InterfaceActionService> ().UIManager;
-            ui_manager.AddUiFromString (String.Format (button_xml, "StandardNpOpen"));
-            ui_manager.AddUiFromString (String.Format (button_xml, "LastFmOpen"));
-            ui_manager.AddUiFromString (String.Format (button_xml, "WikipediaOpen"));
+            foreach (string pageId in Actions.PageIds) {
+                ui_manager.AddUiFromString (String.Format (button_xml, pageId));
+            }
         }
 
         void OnActiveSourceChanged (SourceEventArgs args)



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