[banshee/better-now-playing] [NowPlaying] Implement a BaseContextView for Now Playing source.



commit 5a04311fdafaba32397cf11ac538d49ebebe7f20
Author: Alex Launi <alex launi gmail com>
Date:   Thu Jun 3 22:19:42 2010 -0400

    [NowPlaying] Implement a BaseContextView for Now Playing source.
    
    Use the abstracted now playing logic to get the context view into
    now playing contents.

 .../Banshee.ContextPane/BaseContextView.cs         |   78 ++++++++++++++------
 .../Banshee.ContextPane/ContextPane.cs             |   25 +-----
 .../Banshee.NowPlaying/Banshee.NowPlaying.csproj   |    1 +
 .../Banshee.NowPlaying/Actions.cs                  |   23 ++----
 .../Banshee.NowPlaying/ContextView.cs              |   46 ++++++++++++
 src/Extensions/Banshee.NowPlaying/Makefile.am      |    1 +
 6 files changed, 115 insertions(+), 59 deletions(-)
---
diff --git a/src/Core/Banshee.ThickClient/Banshee.ContextPane/BaseContextView.cs b/src/Core/Banshee.ThickClient/Banshee.ContextPane/BaseContextView.cs
index b9be806..f5fd642 100644
--- a/src/Core/Banshee.ThickClient/Banshee.ContextPane/BaseContextView.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.ContextPane/BaseContextView.cs
@@ -53,35 +53,17 @@ namespace Banshee.ContextPane
         public BaseContextView ()
         {
             pane_pages = new Dictionary<BaseContextPage, Widget> ();
+            CreateContextNotebook ();
+
+            Manager = new ContextPageManager ();
+            Manager.PageAdded += OnPageAdded;
+            Manager.PageRemoved += OnPageRemoved;
+
             ServiceManager.PlayerEngine.ConnectEvent (OnPlayerEvent, PlayerEvent.StartOfStream | PlayerEvent.TrackInfoUpdated);
         }
 
         public ContextPageManager Manager { get; protected set; }
 
-        protected void CreateContextNotebook ()
-        {
-            notebook = new Notebook () {
-                ShowBorder = false,
-                ShowTabs = false
-            };
-
-            // 'No active track' and 'Loading' widgets
-            no_active = new RoundedFrame ();
-            no_active.Add (new Label () {
-                Markup = String.Format ("<b>{0}</b>", Catalog.GetString ("Waiting for playback to begin..."))
-            });
-            no_active.ShowAll ();
-            notebook.Add (no_active);
-
-            loading = new RoundedFrame ();
-            loading.Add (new Label () { Markup = String.Format ("<b>{0}</b>", Catalog.GetString ("Loading...")) });
-            loading.ShowAll ();
-            notebook.Add (loading);
-
-            PackStart (notebook, true, true, 0);
-            notebook.Show ();
-        }
-
         public virtual void SetActivePage (BaseContextPage page)
         {
             if (page == null || page == active_page) {
@@ -100,6 +82,29 @@ namespace Banshee.ContextPane
 
         protected abstract bool Enabled { get; set; }
 
+        protected virtual void OnPageAdded (BaseContextPage page)
+        {
+            Hyena.Log.DebugFormat ("Adding context page {0}", page.Id);
+
+            // TODO delay adding the page.Widget until the page is first activated,
+            // that way we don't even create those objects unless used
+            var frame = new Hyena.Widgets.RoundedFrame ();
+            frame.Add (page.Widget);
+            frame.Show ();
+
+            page.Widget.Show ();
+            notebook.AppendPage (frame, null);
+            pane_pages[page] = frame;
+        }
+
+        protected virtual void OnPageRemoved (BaseContextPage page)
+        {
+            Hyena.Log.DebugFormat ("Removing context page {0}", page.Id);
+            // Remove the notebook page
+            notebook.RemovePage (notebook.PageNum (pane_pages[page]));
+            pane_pages.Remove (page);
+        }
+
         protected virtual void OnActivePageStateChanged (ContextState state)
         {
             if (active_page == null) {
@@ -128,5 +133,30 @@ namespace Banshee.ContextPane
                 active_page.SetTrack (track);
             }
         }
+
+        private void CreateContextNotebook ()
+        {
+            notebook = new Notebook () {
+                ShowBorder = false,
+                ShowTabs = false
+            };
+
+            // 'No active track' and 'Loading' widgets
+            no_active = new RoundedFrame ();
+            no_active.Add (new Label () {
+                Markup = String.Format ("<b>{0}</b>", Catalog.GetString ("Waiting for playback to begin..."))
+            });
+            no_active.ShowAll ();
+            notebook.Add (no_active);
+
+            loading = new RoundedFrame ();
+            loading.Add (new Label () { Markup = String.Format ("<b>{0}</b>", Catalog.GetString ("Loading...")) });
+            loading.ShowAll ();
+            notebook.Add (loading);
+
+            PackStart (notebook, true, true, 0);
+            notebook.Show ();
+        }
+
     }
 }
diff --git a/src/Core/Banshee.ThickClient/Banshee.ContextPane/ContextPane.cs b/src/Core/Banshee.ThickClient/Banshee.ContextPane/ContextPane.cs
index dfc30b9..ec88ae8 100644
--- a/src/Core/Banshee.ThickClient/Banshee.ContextPane/ContextPane.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.ContextPane/ContextPane.cs
@@ -71,12 +71,8 @@ namespace Banshee.ContextPane
         {
             HeightRequest = 200;
 
-            CreateContextNotebook ();
             CreateTabButtonBox ();
 
-            Manager = new ContextPageManager ();
-            Manager.PageAdded += OnPageAdded;
-            Manager.PageRemoved += OnPageRemoved;
             Manager.Init ();
 
             initialized = true;
@@ -173,15 +169,9 @@ namespace Banshee.ContextPane
             vbox.Visible = true;//enabled && npages > 1;
         }
 
-        private void OnPageAdded (BaseContextPage page)
+        protected override void OnPageAdded (BaseContextPage page)
         {
-            Hyena.Log.DebugFormat ("Adding context page {0}", page.Id);
-
-            // TODO delay adding the page.Widget until the page is first activated,
-            // that way we don't even create those objects unless used
-            var frame = new Hyena.Widgets.RoundedFrame ();
-            frame.Add (page.Widget);
-            frame.Show ();
+            base.OnPageAdded (page);
 
             // TODO implement DnD?
             /*if (page is ITrackContextPage) {
@@ -192,10 +182,6 @@ namespace Banshee.ContextPane
                 };
             }*/
 
-            page.Widget.Show ();
-            notebook.AppendPage (frame, null);
-            pane_pages[page] = frame;
-
             // Setup the tab-like button that switches the notebook to this page
             var tab_image = new Image (IconThemeUtils.LoadIcon (22, page.IconNames));
             var toggle_button = new RadioButton (radio_group) {
@@ -224,12 +210,9 @@ namespace Banshee.ContextPane
             UpdateVisibility ();
         }
 
-        private void OnPageRemoved (BaseContextPage page)
+        protected override void OnPageRemoved (BaseContextPage page)
         {
-            Hyena.Log.DebugFormat ("Removing context page {0}", page.Id);
-            // Remove the notebook page
-            notebook.RemovePage (notebook.PageNum (pane_pages[page]));
-            pane_pages.Remove (page);
+            base.OnPageRemoved (page);
 
             // Remove the tab button
             bool was_active = pane_tabs[page].Active;
diff --git a/src/Extensions/Banshee.NowPlaying/Banshee.NowPlaying.csproj b/src/Extensions/Banshee.NowPlaying/Banshee.NowPlaying.csproj
index 46b47e8..79a3d42 100644
--- a/src/Extensions/Banshee.NowPlaying/Banshee.NowPlaying.csproj
+++ b/src/Extensions/Banshee.NowPlaying/Banshee.NowPlaying.csproj
@@ -116,6 +116,7 @@
     <Compile Include="Banshee.NowPlaying\NowPlayingTrackInfoDisplay.cs" />
     <Compile Include="Banshee.NowPlaying\IVideoDisplay.cs" />
     <Compile Include="Banshee.NowPlaying\Actions.cs" />
+    <Compile Include="Banshee.NowPlaying\ContextView.cs" />
   </ItemGroup>
   <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
   <ProjectExtensions>
diff --git a/src/Extensions/Banshee.NowPlaying/Banshee.NowPlaying/Actions.cs b/src/Extensions/Banshee.NowPlaying/Banshee.NowPlaying/Actions.cs
index 336e630..6f10261 100644
--- a/src/Extensions/Banshee.NowPlaying/Banshee.NowPlaying/Actions.cs
+++ b/src/Extensions/Banshee.NowPlaying/Banshee.NowPlaying/Actions.cs
@@ -53,13 +53,9 @@ namespace Banshee.NowPlaying
             now_playing_source = nowPlayingSource;
             pages = new Dictionary<int, BaseContextPage> ();
 
-            Manager = new ContextPageManager ();
-            Manager.Init ();
-            Manager.PageAdded += OnContextPagesChanged;
-            Manager.PageRemoved += OnContextPagesChanged;
+            ContextView = new ContextView ();
 
             LoadActions ();
-
             Register ();
         }
 
@@ -71,7 +67,12 @@ namespace Banshee.NowPlaying
             }
         }
 
-        private ContextPageManager Manager { get; set; }
+        private ContextView ContextView { get; set; }
+        private ContextPageManager Manager {
+            get {
+                return ContextView.Manager;
+            }
+        }
 
         private void LoadActions ()
         {
@@ -109,15 +110,9 @@ namespace Banshee.NowPlaying
             if (args.Current.CurrentValue == 0) {
                 now_playing_source.SetSubstituteAudioDisplay (null);
             } else {
-                Widget widget = pages[args.Current.CurrentValue].Widget;
-                now_playing_source.SetSubstituteAudioDisplay (widget);
-                widget.Show ();
+                ContextView.SetActivePage (pages[args.Current.CurrentValue]);
+                now_playing_source.SetSubstituteAudioDisplay (ContextView);
             }
         }
-
-        private void OnContextPagesChanged (BaseContextPage page)
-        {
-            LoadActions ();
-        }
     }
 }
diff --git a/src/Extensions/Banshee.NowPlaying/Banshee.NowPlaying/ContextView.cs b/src/Extensions/Banshee.NowPlaying/Banshee.NowPlaying/ContextView.cs
new file mode 100644
index 0000000..a90aaac
--- /dev/null
+++ b/src/Extensions/Banshee.NowPlaying/Banshee.NowPlaying/ContextView.cs
@@ -0,0 +1,46 @@
+// 
+// ContextView.cs
+// 
+// Author:
+//   Alex Launi <alex launi gmail com>
+// 
+// Copyright (c) 2010 Alex Launi
+// 
+// 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.ContextPane;
+
+namespace Banshee.NowPlaying
+{
+    public class ContextView : BaseContextView
+    {
+
+        public ContextView () : base ()
+        {
+            Manager.Init ();
+            Enabled = true;
+        }
+
+        protected override bool Enabled {
+            get ; set;
+        }
+    }
+}
diff --git a/src/Extensions/Banshee.NowPlaying/Makefile.am b/src/Extensions/Banshee.NowPlaying/Makefile.am
index dca604b..a2dad1f 100644
--- a/src/Extensions/Banshee.NowPlaying/Makefile.am
+++ b/src/Extensions/Banshee.NowPlaying/Makefile.am
@@ -5,6 +5,7 @@ INSTALL_DIR = $(EXTENSIONS_INSTALL_DIR)
 
 SOURCES =  \
 	Banshee.NowPlaying/Actions.cs \
+	Banshee.NowPlaying/ContextView.cs \
 	Banshee.NowPlaying/FullscreenAdapter.cs \
 	Banshee.NowPlaying/FullscreenControls.cs \
 	Banshee.NowPlaying/FullscreenWindow.cs \



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