[f-spot/taglib-metadata: 26/29] Remove more unused code.



commit 747f8ba4cab545f587632d2f66874a45b4363d0c
Author: Ruben Vermeersch <ruben savanne be>
Date:   Fri Jul 2 11:04:35 2010 +0200

    Remove more unused code.

 src/ImageLoaderThread.cs    |    6 ++-
 src/PixbufCache.cs          |    2 +-
 src/PixbufUtils.cs          |  147 +------------------------------------------
 src/ThumbnailCache.cs       |    5 +-
 src/Utils/PixbufUtils.cs    |    2 +-
 src/Widgets/Filmstrip.cs    |    6 +-
 src/Widgets/IconView.cs     |    3 +-
 src/Widgets/PreviewPopup.cs |    2 +-
 8 files changed, 19 insertions(+), 154 deletions(-)
---
diff --git a/src/ImageLoaderThread.cs b/src/ImageLoaderThread.cs
index d0ea239..4e30cd6 100644
--- a/src/ImageLoaderThread.cs
+++ b/src/ImageLoaderThread.cs
@@ -16,6 +16,7 @@ using System;
 
 using Hyena;
 
+using FSpot.Utils;
 using FSpot.Imaging;
 
 public class ImageLoaderThread {
@@ -32,7 +33,10 @@ public class ImageLoaderThread {
 		/* The pixbuf obtained from the operation.  */
         private Pixbuf result;
 		public Pixbuf Result {
-            get { return PixbufUtils.ShallowCopy (result); }
+            get {
+				if (result == null) return null;
+				return result.ShallowCopy ();
+			}
             set { result = value; }
         }
 
diff --git a/src/PixbufCache.cs b/src/PixbufCache.cs
index 402feeb..38d9e20 100644
--- a/src/PixbufCache.cs
+++ b/src/PixbufCache.cs
@@ -354,7 +354,7 @@ namespace FSpot {
 					if (pixbuf == null)
 						return null;
 					
-					return PixbufUtils.ShallowCopy (pixbuf);
+					return pixbuf.ShallowCopy ();
 				}
 			}
 			
diff --git a/src/PixbufUtils.cs b/src/PixbufUtils.cs
index 1d3dc62..b460a41 100644
--- a/src/PixbufUtils.cs
+++ b/src/PixbufUtils.cs
@@ -144,14 +144,6 @@ public static class PixbufUtils {
 		}
 	}
 
-	public static Pixbuf ShallowCopy (Pixbuf pixbuf)
-	{
-		if (pixbuf == null)
-			return null;
-		Pixbuf result = new Pixbuf (pixbuf, 0, 0, pixbuf.Width, pixbuf.Height);
-		return result;
-	}
-
 	public static Pixbuf ScaleToMaxSize (Pixbuf pixbuf, int width, int height)
 	{
 		return ScaleToMaxSize (pixbuf, width, height, true);
@@ -174,51 +166,16 @@ public static class PixbufUtils {
 		
 	static public void GetSize (string path, out int width, out int height)
 	{
-#if true
 		using (Gdk.Pixbuf pixbuf = new Gdk.Pixbuf (path)) {
 			width = pixbuf.Width;
 			height = pixbuf.Height;
 		}
-#else //yes, the pixbuf loader hack is smarter, but it leaks like an old women
-		Gdk.PixbufLoader loader = new Gdk.PixbufLoader ();
-		int orig_width = 0;
-		int orig_height = 0;
-		bool done = false;
-
-		loader.SizePrepared += delegate (object obj, SizePreparedArgs args) {
-			orig_width = args.Width;
-			orig_height = args.Height;
-			done = true;
-		};
-		
-		using (Stream stream = File.OpenRead (path)) {
-			byte [] data = new byte [4096];
-			int count;
-
-			while (((count = stream.Read (data, 0, data.Length)) > 0) && loader.Write (data, (ulong)count)) {
-				if (done)
-					break;
-			}
-		}
-		
-		width = orig_width;
-		height = orig_height;
-#endif
 	}
 
 	static public Pixbuf LoadAtMaxSize (string path, int max_width, int max_height)
 	{
-#if true
 		PixbufUtils.AspectLoader loader = new AspectLoader (max_width, max_height);
 		return loader.LoadFromFile (path);
-#else
-		int width, height;
-		JpegUtils.GetSize (path, out width, out height);
-		PixbufUtils.Fit (width, height, max_width, max_height, false, out width, out height);
-		Gdk.Pixbuf image = JpegUtils.LoadScaled (path, width, height);
-		
-		return image;
-#endif
 	}
 
 	static public Pixbuf LoadFromStream (System.IO.Stream input)
@@ -235,62 +192,7 @@ public static class PixbufUtils {
 		return loader.Pixbuf;
 		
 	}
-	
-
-	public static void Save (Gdk.Pixbuf pixbuf, System.IO.Stream stream, string type, string [] options, string [] values)
-	{
-		byte [] data;
-
-		data = PixbufUtils.Save (pixbuf, type, options, values);
-		stream.Write (data, 0, data.Length);
-	}
-
-	static string [] NullTerminateArray (string [] options)
-	{
-		string [] terminated_options = options;
-
-		if (options != null && options [ options.Length - 1 ] != null) {
-			terminated_options = new string [options.Length + 1];
-			Array.Copy (options, terminated_options, options.Length);
-		}
-		
-		return terminated_options;
-	}
 
-	[DllImport("libgdk_pixbuf-2.0-0.dll")]
-	static extern bool gdk_pixbuf_save_to_bufferv (IntPtr raw, out IntPtr data, out IntPtr length, 
-						       string type, 
-						       string [] keys, string [] values, out IntPtr error);
-
-					
-	public static byte [] Save (Gdk.Pixbuf pixbuf, string type, string [] options, string [] values)
-	{
-		IntPtr error = IntPtr.Zero;
-		IntPtr data;
-		IntPtr length;
-
-		bool success = gdk_pixbuf_save_to_bufferv (pixbuf.Handle, 
-							   out data, 
-							   out length, 
-							   type,
-							   NullTerminateArray (options),
-							   NullTerminateArray (values),
-							   out error);
-		
-		if (error != IntPtr.Zero) 
-			throw new GLib.GException (error);
-
-		if (!success)
-			throw new ApplicationException ("Unknown error while saving file");
-
-		byte [] content = new byte [(int)length];
-		Marshal.Copy (data, content, 0, (int)length);
-
-		GLib.Marshaller.Free (data);
-
-		return content;
-	}
-	
 	public static Pixbuf TagIconFromPixbuf (Pixbuf source)
 	{
 		return IconFromPixbuf (source, (int) FSpot.Tag.IconSize.Large);
@@ -316,44 +218,8 @@ public static class PixbufUtils {
 		
 		return icon;
 	}
-		
-	static public Pixbuf LoadFromScreen (Gdk.Window win) {
-		Gdk.Screen screen = win.Screen;
-		Drawable d = screen.RootWindow;
-		int monitor = screen.GetMonitorAtWindow (win);
-		Gdk.Rectangle geom = screen.GetMonitorGeometry (monitor);
-		
-		//
-		// We use the screen width and height because that reflects
-		// the current resolution, the RootWindow can actually be different.
-		//
 
-		Pixbuf buf = new Pixbuf (Colorspace.Rgb, false, 8, geom.Width, geom.Height);
-		
-		return buf.GetFromDrawable (d,
-					    d.Colormap, geom.X, geom.Y, 0, 0, 
-					    geom.Width, geom.Height);
-	}
-
-	static public Pixbuf LoadFromScreen () {
-		Screen screen = Display.Default.GetScreen (0);
-		Drawable d = screen.RootWindow;
-		int width = screen.Width;
-		int height = screen.Height;
-		
-		//
-		// We use the screen width and height because that reflects
-		// the current resolution, the RootWindow can actually be different.
-		//
-
-		Pixbuf buf = new Pixbuf (Colorspace.Rgb, false, 8, width, height);
-		
-		return buf.GetFromDrawable (d,
-					    d.Colormap, 0, 0, 0, 0, 
-					    width, height);
-	}
-
-	static public Pixbuf LoadFromAssembly (string resource)
+	static Pixbuf LoadFromAssembly (string resource)
 	{
 		try {
 			return new Pixbuf (System.Reflection.Assembly.GetEntryAssembly (), resource);
@@ -362,17 +228,6 @@ public static class PixbufUtils {
 		}
 	}
 
-	[DllImport ("libc")]
-	static extern int rename (string oldpath, string newpath);
-
-	public static void SaveAtomic (Gdk.Pixbuf src, string filename, string type, string [] keys, string [] values)
-	{
-			string tmpname = filename + ".tmp";
-			src.Savev (tmpname, type, NullTerminateArray (keys), NullTerminateArray (values));
-			if (rename (tmpname, filename) < 0)
-				throw new Exception ("Error renaming file");
-	}
-
 	public static Gdk.Pixbuf ScaleToAspect (Gdk.Pixbuf orig, int width, int height)
 	{
 		Gdk.Rectangle pos;
diff --git a/src/ThumbnailCache.cs b/src/ThumbnailCache.cs
index 17e7552..0b1be21 100644
--- a/src/ThumbnailCache.cs
+++ b/src/ThumbnailCache.cs
@@ -14,6 +14,7 @@ using System.Collections;
 using Gdk;
 
 using Hyena;
+using FSpot.Utils;
 
 namespace FSpot
 {
@@ -80,7 +81,9 @@ public class ThumbnailCache : IDisposable {
 		pixbuf_mru.Remove (item);
 		pixbuf_mru.Insert (0, item);
 
-		return PixbufUtils.ShallowCopy (item.pixbuf);
+        if (item.pixbuf == null)
+            return null;
+        return item.pixbuf.ShallowCopy ();
 	}
 
 	public void RemoveThumbnailForUri (SafeUri uri)
diff --git a/src/Utils/PixbufUtils.cs b/src/Utils/PixbufUtils.cs
index 933769b..4964a85 100644
--- a/src/Utils/PixbufUtils.cs
+++ b/src/Utils/PixbufUtils.cs
@@ -191,7 +191,7 @@ namespace FSpot.Utils
 			return dest;
 		}
 
-		public static Pixbuf ShallowCopy (Pixbuf pixbuf)
+		public static Pixbuf ShallowCopy (this Pixbuf pixbuf)
 		{
 			if (pixbuf == null)
 				return null;
diff --git a/src/Widgets/Filmstrip.cs b/src/Widgets/Filmstrip.cs
index dbe6c0b..c3fc8c9 100644
--- a/src/Widgets/Filmstrip.cs
+++ b/src/Widgets/Filmstrip.cs
@@ -612,10 +612,12 @@ namespace FSpot.Widgets
 
  		protected virtual Pixbuf GetPixbuf (int i, bool highlighted)
 		{
-			Pixbuf current;
+			Pixbuf current = null;
 			SafeUri uri = (selection.Collection [i]).DefaultVersion.Uri;
 			try {
-				current = PixbufUtils.ShallowCopy (thumb_cache.Get (uri));
+				var pixbuf = thumb_cache.Get (uri);
+				if (pixbuf != null)
+					current = pixbuf.ShallowCopy ();
 			} catch (IndexOutOfRangeException) {
 				current = null;
 			}
diff --git a/src/Widgets/IconView.cs b/src/Widgets/IconView.cs
index e2d49a9..fa92e69 100644
--- a/src/Widgets/IconView.cs
+++ b/src/Widgets/IconView.cs
@@ -15,6 +15,7 @@ using System;
 using System.Reflection;
 using System.Collections;
 using System.IO;
+using FSpot.Utils;
 using FSpot.Platform;
 
 namespace FSpot.Widgets
@@ -913,7 +914,7 @@ namespace FSpot.Widgets
 
 						lock (entry) {
 							if (entry.Reload && expansion == 0 && !entry.IsDisposed) {
-								entry.SetPixbufExtended (PixbufUtils.ShallowCopy (temp_thumbnail), false);
+								entry.SetPixbufExtended (temp_thumbnail.ShallowCopy (), false);
 								entry.Reload = true;
 							}
 						}
diff --git a/src/Widgets/PreviewPopup.cs b/src/Widgets/PreviewPopup.cs
index 8c94eb1..1fa7b57 100644
--- a/src/Widgets/PreviewPopup.cs
+++ b/src/Widgets/PreviewPopup.cs
@@ -107,7 +107,7 @@ namespace FSpot {
 			
 			string orig_path = item.DefaultVersion.Uri.LocalPath;
 
-			Gdk.Pixbuf pixbuf = PixbufUtils.ShallowCopy (preview_cache.Get (orig_path + show_histogram.ToString ()));
+			Gdk.Pixbuf pixbuf = FSpot.Utils.PixbufUtils.ShallowCopy (preview_cache.Get (orig_path + show_histogram.ToString ()));
 			if (pixbuf == null) {
 				// A bizarre pixbuf = hack to try to deal with cinematic displays, etc.
 				int preview_size = ((this.Screen.Width + this.Screen.Height)/2)/3;



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