[banshee] Lazily load the GUI for several sources



commit 3dceca235edc22088babf3d7dc3e9f9f934cef4f
Author: Gabriel Burt <gabriel burt gmail com>
Date:   Fri Nov 27 15:56:25 2009 -0800

    Lazily load the GUI for several sources
    
    Don't actually create the Gtk+ widgetry for Last.fm, Internet Archive,
    Now Playing, Podcasts, and Internet Radio sources until necessary.

 .../Banshee.Sources.Gui/LazyLoadSourceContents.cs  |   80 ++++++++++++++++++++
 .../Banshee.ThickClient/Banshee.ThickClient.csproj |    1 +
 src/Core/Banshee.ThickClient/Makefile.am           |    1 +
 .../Banshee.InternetArchive/HomeSource.cs          |    2 +-
 .../Banshee.InternetArchive/SearchSource.cs        |    2 +-
 .../Banshee.InternetRadio/InternetRadioSource.cs   |    4 +-
 .../Banshee.Lastfm.Radio/LastfmSource.cs           |    2 +-
 .../Banshee.NowPlaying/NowPlayingSource.cs         |    8 +-
 .../Banshee.Podcasting.Data/PodcastSource.cs       |    2 +-
 9 files changed, 92 insertions(+), 10 deletions(-)
---
diff --git a/src/Core/Banshee.ThickClient/Banshee.Sources.Gui/LazyLoadSourceContents.cs b/src/Core/Banshee.ThickClient/Banshee.Sources.Gui/LazyLoadSourceContents.cs
new file mode 100644
index 0000000..60245a4
--- /dev/null
+++ b/src/Core/Banshee.ThickClient/Banshee.Sources.Gui/LazyLoadSourceContents.cs
@@ -0,0 +1,80 @@
+//
+// LazyLoadSourceContents.cs
+//
+// Author:
+//   Gabriel Burt <gburt novell com>
+//
+// Copyright (C) 2009 Novell, Inc.
+//
+// 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 Gtk;
+
+using Banshee.Sources;
+
+namespace Banshee.Sources.Gui
+{
+    public class LazyLoadSourceContents<T> : ISourceContents where T : ISourceContents
+    {
+        private object [] args;
+        private ISourceContents actual_contents;
+        private ISourceContents ActualContents {
+            get {
+                if (actual_contents == null) {
+                    lock (this) {
+                        if (actual_contents == null) {
+                            using (new Hyena.Timer (String.Format ("Creating new {0}", typeof(T).Name))) {
+                            actual_contents = (T) Activator.CreateInstance (typeof(T), args);
+                            }
+                        }
+                    }
+                }
+
+                return actual_contents;
+            }
+        }
+
+        public LazyLoadSourceContents (params object [] args)
+        {
+            this.args = args;
+        }
+
+        public bool SetSource (ISource source)
+        {
+            return ActualContents.SetSource (source);
+        }
+
+        public void ResetSource ()
+        {
+            ActualContents.ResetSource ();
+        }
+
+        public ISource Source {
+            get { return ActualContents.Source; }
+        }
+
+        public Widget Widget {
+            get { return ActualContents.Widget; }
+        }
+    }
+}
diff --git a/src/Core/Banshee.ThickClient/Banshee.ThickClient.csproj b/src/Core/Banshee.ThickClient/Banshee.ThickClient.csproj
index 4c8cd3f..a7fb52e 100644
--- a/src/Core/Banshee.ThickClient/Banshee.ThickClient.csproj
+++ b/src/Core/Banshee.ThickClient/Banshee.ThickClient.csproj
@@ -197,6 +197,7 @@
     <Compile Include="Banshee.Sources.Gui\SourceIconResolver.cs" />
     <Compile Include="Banshee.Gui\BaseClientWindow.cs" />
     <Compile Include="Banshee.Sources.Gui\CompositeTrackSourceContents.cs" />
+    <Compile Include="Banshee.Sources.Gui\LazyLoadSourceContents.cs" />
     <Compile Include="Banshee.Sources.Gui\ISourceContents.cs" />
     <Compile Include="Banshee.Sources.Gui\ObjectListSourceContents.cs" />
     <Compile Include="Banshee.Playlist.Gui\PlaylistExportDialog.cs" />
diff --git a/src/Core/Banshee.ThickClient/Makefile.am b/src/Core/Banshee.ThickClient/Makefile.am
index 3569988..f2b709c 100644
--- a/src/Core/Banshee.ThickClient/Makefile.am
+++ b/src/Core/Banshee.ThickClient/Makefile.am
@@ -145,6 +145,7 @@ SOURCES =  \
 	Banshee.Sources.Gui/FilteredListSourceContents.cs \
 	Banshee.Sources.Gui/ISourceContents.cs \
 	Banshee.Sources.Gui/ITrackModelSourceContents.cs \
+	Banshee.Sources.Gui/LazyLoadSourceContents.cs \
 	Banshee.Sources.Gui/ObjectListSourceContents.cs \
 	Banshee.Sources.Gui/SourceComboBox.cs \
 	Banshee.Sources.Gui/SourceIconResolver.cs \
diff --git a/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/HomeSource.cs b/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/HomeSource.cs
index 1a4c43e..842d503 100644
--- a/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/HomeSource.cs
+++ b/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/HomeSource.cs
@@ -70,7 +70,7 @@ namespace Banshee.InternetArchive
             //Properties.SetStringList ("Icon.Name", "video-x-generic", "video", "source-library");
             Properties.SetString ("ActiveSourceUIResource", "HomeSourceActiveUI.xml");
             Properties.SetString ("GtkActionPath", "/IaHomeSourcePopup");
-            Properties.Set<Gtk.Widget> ("Nereid.SourceContents", new HomeView (this));
+            Properties.Set<Banshee.Sources.Gui.ISourceContents> ("Nereid.SourceContents", new Banshee.Sources.Gui.LazyLoadSourceContents<HomeView> (this));
 
             actions = new Actions (this);
 
diff --git a/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/SearchSource.cs b/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/SearchSource.cs
index ec0195f..51c7104 100644
--- a/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/SearchSource.cs
+++ b/src/Extensions/Banshee.InternetArchive/Banshee.InternetArchive/SearchSource.cs
@@ -98,7 +98,7 @@ namespace Banshee.InternetArchive
                 Properties.Set<Gtk.Widget> ("Nereid.SourceContents.HeaderWidget", header_widget);
             }
 
-            Properties.Set<Gtk.Widget> ("Nereid.SourceContents", new SearchView (this));
+            Properties.Set<Banshee.Sources.Gui.ISourceContents> ("Nereid.SourceContents", new Banshee.Sources.Gui.LazyLoadSourceContents<SearchView> (this));
         }
 
         public void SetSearch (SearchDescription settings)
diff --git a/src/Extensions/Banshee.InternetRadio/Banshee.InternetRadio/InternetRadioSource.cs b/src/Extensions/Banshee.InternetRadio/Banshee.InternetRadio/InternetRadioSource.cs
index 7447515..8581772 100644
--- a/src/Extensions/Banshee.InternetRadio/Banshee.InternetRadio/InternetRadioSource.cs
+++ b/src/Extensions/Banshee.InternetRadio/Banshee.InternetRadio/InternetRadioSource.cs
@@ -49,7 +49,6 @@ namespace Banshee.InternetRadio
 {
     public class InternetRadioSource : PrimarySource, IDisposable, IBasicPlaybackController
     {
-        private InternetRadioSourceContents source_contents;
         private uint ui_id;
 
         public InternetRadioSource () : base (Catalog.GetString ("Radio"), Catalog.GetString ("Radio"), "internet-radio", 220)
@@ -76,9 +75,8 @@ namespace Banshee.InternetRadio
 
             Properties.SetString ("GtkActionPath", "/InternetRadioContextMenu");
 
-            source_contents = new InternetRadioSourceContents ();
             Properties.Set<bool> ("Nereid.SourceContentsPropagate", true);
-            Properties.Set<ISourceContents> ("Nereid.SourceContents", source_contents);
+            Properties.Set<ISourceContents> ("Nereid.SourceContents", new LazyLoadSourceContents<InternetRadioSourceContents> ());
 
             Properties.SetString ("TrackEditorActionLabel", Catalog.GetString ("Edit Station"));
             Properties.Set<InvokeHandler> ("TrackEditorActionHandler", delegate {
diff --git a/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/LastfmSource.cs b/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/LastfmSource.cs
index 4d8e038..06546f9 100644
--- a/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/LastfmSource.cs
+++ b/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/LastfmSource.cs
@@ -106,7 +106,7 @@ namespace Banshee.Lastfm.Radio
             Properties.Set<LastfmColumnController> ("TrackView.ColumnController", new LastfmColumnController ());
 
             // FIXME this is temporary until we split the GUI part from the non-GUI part
-            Properties.Set<ISourceContents> ("Nereid.SourceContents", new LastfmSourceContents ());
+            Properties.Set<ISourceContents> ("Nereid.SourceContents", new LazyLoadSourceContents<LastfmSourceContents> ());
             Properties.Set<bool> ("Nereid.SourceContents.HeaderVisible", false);
 
             actions = new LastfmActions (this);
diff --git a/src/Extensions/Banshee.NowPlaying/Banshee.NowPlaying/NowPlayingSource.cs b/src/Extensions/Banshee.NowPlaying/Banshee.NowPlaying/NowPlayingSource.cs
index d95eb81..415919f 100644
--- a/src/Extensions/Banshee.NowPlaying/Banshee.NowPlaying/NowPlayingSource.cs
+++ b/src/Extensions/Banshee.NowPlaying/Banshee.NowPlaying/NowPlayingSource.cs
@@ -47,10 +47,7 @@ namespace Banshee.NowPlaying
 
         public NowPlayingSource () : base ("now-playing", Catalog.GetString ("Now Playing"), 10, "now-playing")
         {
-            now_playing_interface = new NowPlayingInterface ();
-
             Properties.SetString ("Icon.Name", "applications-multimedia");
-            Properties.Set<ISourceContents> ("Nereid.SourceContents", now_playing_interface);
             Properties.Set<bool> ("Nereid.SourceContents.HeaderVisible", false);
             Properties.SetString ("ActiveSourceUIResource", "ActiveSourceUI.xml");
 
@@ -104,6 +101,11 @@ namespace Banshee.NowPlaying
 
         public override void Activate ()
         {
+            if (now_playing_interface == null) {
+                now_playing_interface = new NowPlayingInterface ();
+                Properties.Set<ISourceContents> ("Nereid.SourceContents", now_playing_interface);
+            }
+
             if (now_playing_interface != null) {
                 now_playing_interface.OverrideFullscreen ();
             }
diff --git a/src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Data/PodcastSource.cs b/src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Data/PodcastSource.cs
index 8d754e6..787c762 100644
--- a/src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Data/PodcastSource.cs
+++ b/src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Data/PodcastSource.cs
@@ -112,7 +112,7 @@ namespace Banshee.Podcasting.Gui
 
             Properties.SetString ("GtkActionPath", "/PodcastSourcePopup");
 
-            Properties.Set<ISourceContents> ("Nereid.SourceContents", new PodcastSourceContents ());
+            Properties.Set<ISourceContents> ("Nereid.SourceContents", new LazyLoadSourceContents<PodcastSourceContents> ());
             Properties.Set<bool> ("Nereid.SourceContentsPropagate", true);
 
             Properties.SetString ("TrackView.ColumnControllerXml", String.Format (@"



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