f-spot r3966 - in trunk/src: Core Query



Author: sdelcroix
Date: Wed May 21 10:26:52 2008
New Revision: 3966
URL: http://svn.gnome.org/viewvc/f-spot?rev=3966&view=rev

Log:
make Tag and TagTerm IDisposable

Modified:
   trunk/src/Core/Category.cs
   trunk/src/Core/Global.cs
   trunk/src/Core/IPreferenceBackend.cs
   trunk/src/Core/Tag.cs
   trunk/src/Query/LogicalTerm.cs

Modified: trunk/src/Core/Category.cs
==============================================================================
--- trunk/src/Core/Category.cs	(original)
+++ trunk/src/Core/Category.cs	Wed May 21 10:26:52 2008
@@ -1,5 +1,5 @@
 /*
- * FSpot.Tag
+ * FSpot.Category.cs
  * 
  * Author(s):
  *	Larry Ewing  <lewing novell com>

Modified: trunk/src/Core/Global.cs
==============================================================================
--- trunk/src/Core/Global.cs	(original)
+++ trunk/src/Core/Global.cs	Wed May 21 10:26:52 2008
@@ -6,7 +6,7 @@
  */
 
 namespace FSpot {
-	public class Global {
+	public static class Global {
 		public static string HomeDirectory {
 			get { return System.IO.Path.Combine (System.Environment.GetEnvironmentVariable ("HOME"), System.String.Empty); }
 		}

Modified: trunk/src/Core/IPreferenceBackend.cs
==============================================================================
--- trunk/src/Core/IPreferenceBackend.cs	(original)
+++ trunk/src/Core/IPreferenceBackend.cs	Wed May 21 10:26:52 2008
@@ -7,6 +7,9 @@
  * This is free software. See COPYING for details.
  */
 
+using System;
+using System.Runtime.Serialization;
+
 namespace FSpot
 {
 	public class NotifyEventArgs : System.EventArgs
@@ -28,7 +31,7 @@
 		}
 	}
 
-	public class NoSuchKeyException : System.Exception
+	public class NoSuchKeyException : Exception
 	{
 		public NoSuchKeyException () : base ()
 		{
@@ -37,6 +40,14 @@
 		public NoSuchKeyException (string key) : base (key)
 		{
 		}
+
+		public NoSuchKeyException (string key, Exception e) : base (key, e)
+		{
+		}
+
+		protected NoSuchKeyException (SerializationInfo info, StreamingContext context) : base (info, context)
+		{
+		}
 	}
 
 	public delegate void NotifyChangedHandler (object sender, NotifyEventArgs args);

Modified: trunk/src/Core/Tag.cs
==============================================================================
--- trunk/src/Core/Tag.cs	(original)
+++ trunk/src/Core/Tag.cs	Wed May 21 10:26:52 2008
@@ -14,7 +14,7 @@
 
 namespace FSpot
 {
-	public class Tag : DbItem, IComparable {
+	public class Tag : DbItem, IComparable, IDisposable {
 		private string name;
 		public string Name {
 			set {
@@ -154,5 +154,27 @@
 	
 			return false;
 		}
+
+		public void Dispose ()
+		{
+			if (icon != null)
+				icon.Dispose ();
+			if (cached_icon != null)
+				cached_icon.Dispose ();
+			if (category != null)
+				category.Dispose ();
+			System.GC.SuppressFinalize (this);
+		}
+
+		~Tag ()
+		{
+			Log.DebugFormat ("Finalizer called on {0}. Should be Disposed", GetType ());		
+			if (icon != null)
+				icon.Dispose ();
+			if (cached_icon != null)
+				cached_icon.Dispose ();
+			if (category != null)
+				category.Dispose ();
+		}
 	}
 }

Modified: trunk/src/Query/LogicalTerm.cs
==============================================================================
--- trunk/src/Query/LogicalTerm.cs	(original)
+++ trunk/src/Query/LogicalTerm.cs	Wed May 21 10:26:52 2008
@@ -9,6 +9,7 @@
 
 using System;
 using System.Collections.Generic;
+using FSpot.Utils;
 
 namespace FSpot.Query
 {
@@ -17,7 +18,7 @@
 		public abstract string SqlClause ();
 	}
 
-	public class TagTerm : LogicalTerm
+	public class TagTerm : LogicalTerm, IDisposable
 	{
 		Tag tag;
 		public Tag Tag {
@@ -51,6 +52,20 @@
 			else
 				return String.Format (" (photos.id IN (SELECT photo_id FROM photo_tags WHERE tag_id IN ({0}))) ", String.Join (", ", tagids));
 		}
+
+		public void Dispose ()
+		{
+			if (tag != null)
+				tag.Dispose ();
+			System.GC.SuppressFinalize (this);
+		}
+
+		~TagTerm ()
+		{
+			Log.DebugFormat ("Finalizer called on {0}. Should be Disposed", GetType ());
+			if (tag != null)
+				tag.Dispose ();
+		}
 	}
 
 	public class TextTerm : LogicalTerm
@@ -118,7 +133,7 @@
 			return ls.ToArray ();
 		}
 
-		public string SqlClause (string op, string[] items)
+		public static string SqlClause (string op, string[] items)
 		{
 			if (items.Length == 1)
 				return items [0];



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