[banshee] [PixbufImageSurface] Use factory to handle null pb



commit 07edaeff263b2c74d38758d48ac0102e987c1f1b
Author: Gabriel Burt <gabriel burt gmail com>
Date:   Fri May 29 13:55:08 2009 -0500

    [PixbufImageSurface] Use factory to handle null pb
---
 .../Muinshee/Muinshee/MuinsheeTrackInfoDisplay.cs  |    2 +-
 .../Banshee.Collection.Gui/ArtworkManager.cs       |    2 +-
 .../Banshee.Collection.Gui/ColumnCellAlbum.cs      |    2 +-
 .../Banshee.Gui.Widgets/TrackInfoDisplay.cs        |    4 ++--
 .../Banshee.Podcasting.Gui/ColumnCellPodcast.cs    |    2 +-
 .../Hyena.Gui/Hyena.Gui/PixbufImageSurface.cs      |   18 ++++++++++++++++--
 6 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/src/Clients/Muinshee/Muinshee/MuinsheeTrackInfoDisplay.cs b/src/Clients/Muinshee/Muinshee/MuinsheeTrackInfoDisplay.cs
index 7b1034d..42286bc 100644
--- a/src/Clients/Muinshee/Muinshee/MuinsheeTrackInfoDisplay.cs
+++ b/src/Clients/Muinshee/Muinshee/MuinsheeTrackInfoDisplay.cs
@@ -48,7 +48,7 @@ namespace Muinshee
 
         protected override void RenderIdle (Cairo.Context cr)
         {
-            idle_album = idle_album ?? new PixbufImageSurface (Banshee.Gui.IconThemeUtils.LoadIcon (
+            idle_album = idle_album ?? PixbufImageSurface.Create (Banshee.Gui.IconThemeUtils.LoadIcon (
                 ArtworkSizeRequest, "media-optical"), true);
             
             ArtworkRenderer.RenderThumbnail (cr, idle_album, false, Allocation.X, Allocation.Y, 
diff --git a/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/ArtworkManager.cs b/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/ArtworkManager.cs
index 0c2941a..9bd828e 100644
--- a/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/ArtworkManager.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/ArtworkManager.cs
@@ -125,7 +125,7 @@ namespace Banshee.Collection.Gui
             }
             
             try {
-                surface = new PixbufImageSurface (pixbuf);
+                surface = PixbufImageSurface.Create (pixbuf);
                 if (surface == null) {
                     return null;
                 }
diff --git a/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/ColumnCellAlbum.cs b/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/ColumnCellAlbum.cs
index 99186a3..f8d43ca 100644
--- a/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/ColumnCellAlbum.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/ColumnCellAlbum.cs
@@ -45,7 +45,7 @@ namespace Banshee.Collection.Gui
         private static int image_size = 48;
         
         private static ImageSurface default_cover_image 
-            = new PixbufImageSurface (IconThemeUtils.LoadIcon (image_size, "media-optical", "browser-album-cover"));
+            = PixbufImageSurface.Create (IconThemeUtils.LoadIcon (image_size, "media-optical", "browser-album-cover"));
         
         private ArtworkManager artwork_manager;
 
diff --git a/src/Core/Banshee.ThickClient/Banshee.Gui.Widgets/TrackInfoDisplay.cs b/src/Core/Banshee.ThickClient/Banshee.Gui.Widgets/TrackInfoDisplay.cs
index 4633a19..555c7ae 100644
--- a/src/Core/Banshee.ThickClient/Banshee.Gui.Widgets/TrackInfoDisplay.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.Gui.Widgets/TrackInfoDisplay.cs
@@ -66,13 +66,13 @@ namespace Banshee.Gui.Widgets
         private ImageSurface missing_audio_image;
         protected ImageSurface MissingAudioImage {
             get { return missing_audio_image ?? (missing_audio_image 
-                = new PixbufImageSurface (IconThemeUtils.LoadIcon (MissingIconSizeRequest, "audio-x-generic"), true)); }
+                = PixbufImageSurface.Create (IconThemeUtils.LoadIcon (MissingIconSizeRequest, "audio-x-generic"), true)); }
         }
         
         private ImageSurface missing_video_image;
         protected ImageSurface MissingVideoImage {
             get { return missing_video_image ?? (missing_video_image 
-                = new PixbufImageSurface (IconThemeUtils.LoadIcon (MissingIconSizeRequest, "video-x-generic"), true)); }
+                = PixbufImageSurface.Create (IconThemeUtils.LoadIcon (MissingIconSizeRequest, "video-x-generic"), true)); }
         }
         
         private Cairo.Color background_color;
diff --git a/src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Gui/ColumnCellPodcast.cs b/src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Gui/ColumnCellPodcast.cs
index a3bcd45..af13ce2 100644
--- a/src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Gui/ColumnCellPodcast.cs
+++ b/src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Gui/ColumnCellPodcast.cs
@@ -51,7 +51,7 @@ namespace Banshee.Podcasting.Gui
         
         // TODO replace this w/ new icon installation etc
         private static ImageSurface default_cover_image 
-            = new PixbufImageSurface (IconThemeUtils.LoadIcon (image_size, "podcast"));
+            = PixbufImageSurface.Create (IconThemeUtils.LoadIcon (image_size, "podcast"));
         
         private ArtworkManager artwork_manager;
 
diff --git a/src/Libraries/Hyena.Gui/Hyena.Gui/PixbufImageSurface.cs b/src/Libraries/Hyena.Gui/Hyena.Gui/PixbufImageSurface.cs
index a8895df..6aead35 100644
--- a/src/Libraries/Hyena.Gui/Hyena.Gui/PixbufImageSurface.cs
+++ b/src/Libraries/Hyena.Gui/Hyena.Gui/PixbufImageSurface.cs
@@ -50,14 +50,28 @@ namespace Hyena.Gui
         {
             destroy_func = new cairo_destroy_func_t (DestroyPixelData);
         }
+
+        public static PixbufImageSurface Create (Gdk.Pixbuf pixbuf)
+        {
+            return Create (pixbuf, false);
+        }
+
+        public static PixbufImageSurface Create (Gdk.Pixbuf pixbuf, bool disposePixbuf)
+        {
+            if (pixbuf == null || pixbuf.Handle == IntPtr.Zero) {
+                return null;
+            }
+
+            return new PixbufImageSurface (pixbuf, disposePixbuf);
+        }
         
         private IntPtr data;
         
-        public PixbufImageSurface (Gdk.Pixbuf pixbuf) : this (pixbuf, false)
+        private PixbufImageSurface (Gdk.Pixbuf pixbuf) : this (pixbuf, false)
         {
         }
         
-        public PixbufImageSurface (Gdk.Pixbuf pixbuf, bool disposePixbuf) : this (disposePixbuf ? pixbuf : null, 
+        private PixbufImageSurface (Gdk.Pixbuf pixbuf, bool disposePixbuf) : this (disposePixbuf ? pixbuf : null, 
             pixbuf.Width, pixbuf.Height, pixbuf.NChannels, pixbuf.Rowstride, pixbuf.Pixels)
         {
         }



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