[banshee] [PixbufImageSurface] Add convenience factory func



commit d693c7a0e2fba3c7923d5e447fc8abf33b90dba3
Author: Gabriel Burt <gabriel burt gmail com>
Date:   Mon Jun 8 13:23:59 2009 -0500

    [PixbufImageSurface] Add convenience factory func
    
    There are many places were we create PixbufImageSurface (all touched in
    this patch) where we assume that nothing is thrown, but that null is
    returned if there is an error.  This patch adds a convenience factory
    method (only adding to the API; all ctors are left alone) that makes
    sure the passed in Pixbuf's Handle isn't null, and will catch any errors
    in creating the PixbufImageSurface and return null.
---
 .../Muinshee/Muinshee/MuinsheeTrackInfoDisplay.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 ++++++++++++++++++
 5 files changed, 23 insertions(+), 5 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/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 5e83ba9..46e558a 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..1f13799 100644
--- a/src/Libraries/Hyena.Gui/Hyena.Gui/PixbufImageSurface.cs
+++ b/src/Libraries/Hyena.Gui/Hyena.Gui/PixbufImageSurface.cs
@@ -50,6 +50,24 @@ 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;
+            }
+
+            try {
+                return new PixbufImageSurface (pixbuf, disposePixbuf);
+            } catch {
+                return null;
+            }
+        }
         
         private IntPtr data;
         



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