f-spot r3614 - in trunk: Tests/src src src/Core



Author: sdelcroix
Date: Wed Jan 30 12:30:12 2008
New Revision: 3614
URL: http://svn.gnome.org/viewvc/f-spot?rev=3614&view=rev

Log:
more code cleaning, more refacactoring

Added:
   trunk/Tests/src/ThumbnailGenerator.cs
Modified:
   trunk/Tests/src/Makefile
   trunk/Tests/src/PhotoStore.cs
   trunk/src/Core/DbItem.cs
   trunk/src/Core/Photo.cs
   trunk/src/FileImportBackend.cs
   trunk/src/PhotoVersionCommands.cs
   trunk/src/PhotoVersionMenu.cs
   trunk/src/RotateCommand.cs
   trunk/src/ThumbnailGenerator.cs

Modified: trunk/Tests/src/Makefile
==============================================================================
--- trunk/Tests/src/Makefile	(original)
+++ trunk/Tests/src/Makefile	Wed Jan 30 12:30:12 2008
@@ -6,23 +6,29 @@
 	IBrowsableItem.cs		\
 	PhotoStore.cs			\
 	TagStore.cs			\
+	ThumbnailGenerator.cs		\
 	Query/LogicalTerm.cs		
 
 PKGS = 					\
 	-pkg:mono-nunit			\
 	-pkg:gnome-vfs-sharp-2.0	\
+	-pkg:gnome-sharp-2.0		\
 	-pkg:gtk-sharp-2.0
 
 REFS =					\
 	-r:../../src/f-spot.exe		\
 	-r:../../src/FSpot.Core.dll	\
+	-r:../../src/FSpot.Utils.dll	\
 	-r:../../semweb/SemWeb.dll
 
+RESOURCES =							\
+	-resource:../../icons/f-spot-32.png,f-spot-32.png
+
 
 MCSFLAGS = -t:library -d:ENABLE_NUNIT
 
 $(TESTASSEMBLY): $(SOURCES)
-	gmcs $(MCSFLAGS) $(PKGS) $(REFS) $(SOURCES) -out:$(TESTASSEMBLY)
+	gmcs $(MCSFLAGS) $(PKGS) $(REFS) $(SOURCES) $(RESOURCES) -out:$(TESTASSEMBLY)
 
 test: $(TESTASSEMBLY)
 	export MONO_PATH=../../src:../../semweb; nunit-console2 $(TESTASSEMBLY)

Modified: trunk/Tests/src/PhotoStore.cs
==============================================================================
--- trunk/Tests/src/PhotoStore.cs	(original)
+++ trunk/Tests/src/PhotoStore.cs	Wed Jan 30 12:30:12 2008
@@ -29,7 +29,7 @@
 			db.Init (path, true);
 
 			foreach (string image in images) {
-				File.Copy ("../images/" + image, "./" + image);
+				File.Copy ("../images/" + image, "./" + image, true);
 			}
 
 		}

Added: trunk/Tests/src/ThumbnailGenerator.cs
==============================================================================
--- (empty file)
+++ trunk/Tests/src/ThumbnailGenerator.cs	Wed Jan 30 12:30:12 2008
@@ -0,0 +1,130 @@
+#if ENABLE_NUNIT
+using NUnit.Framework;
+using System;
+using System.IO;
+
+using FSpot.Utils;
+
+namespace FSpot.Tests
+{
+	[TestFixture]
+	public class ThumbnailGeneratorTests {
+		string [] Names = new string [] { 
+			"\x00a9F-SpotUnit\x00b5Test.png",
+			"img(\x00a9F-SpotUnit\x00b5Test).png",
+			"img\u00ff.png",
+			"img\u0100.png",
+			"imgÎ.png",
+			"img(Î).png",
+			"img(ÏÏÎÏÎÏÎÎÎÎÎÎÎ).png",
+		};
+
+		public ThumbnailGeneratorTests ()
+		{
+			Gnome.Vfs.Vfs.Initialize ();
+		}
+
+		public string CreateFile (string name, int size)
+		{
+			using (Gdk.Pixbuf test = new Gdk.Pixbuf (null, "f-spot-32.png")) {
+				using (Gdk.Pixbuf tmp = test.ScaleSimple (size, size, Gdk.InterpType.Nearest)) {
+					string path = System.IO.Path.GetTempPath ();
+					path = System.IO.Path.Combine (path, name);
+					Console.WriteLine (path);
+					tmp.Save (path, Path.GetExtension (path).TrimStart (new char [] { '.' }));
+					return path;
+				}
+			}
+		}
+		
+		[Test]
+		public void BadNames ()
+		{
+			foreach (string name in Names) {
+				BadNames (name);
+			}
+		}
+
+		public void BadNames (string name)
+		{
+			string path = CreateFile (name, 512);
+			System.Uri uri = UriUtils.PathToFileUri (path);
+
+			Gnome.ThumbnailFactory factory = new Gnome.ThumbnailFactory (Gnome.ThumbnailSize.Large);
+			string escaped = UriUtils.PathToFileUriEscaped (path);
+			string large_path = Gnome.Thumbnail.PathForUri (escaped,
+									Gnome.ThumbnailSize.Large);
+
+			using (Gdk.Pixbuf pixbuf = new Gdk.Pixbuf (uri.LocalPath)) {
+				factory.SaveThumbnail (pixbuf, escaped, System.DateTime.Now);
+				
+				Assert.IsTrue (File.Exists (large_path), String.Format ("Missing: {0} created from {1} as {2}", large_path, path, escaped));
+				Gdk.Pixbuf thumb = new Gdk.Pixbuf (large_path);
+				Assert.IsNotNull (thumb);
+			}
+
+			File.Delete (path);
+			File.Delete (large_path);
+		}
+
+		[Test]
+		public void StringNames ()
+		{
+			foreach (string name in Names) {
+				StringNames (name);
+			}
+		}
+		
+		public void StringNames (string name)
+		{
+			string path = CreateFile (name, 1024);
+			string thumb_path = ThumbnailGenerator.ThumbnailPath (path);
+			
+			ThumbnailGenerator.Create (path);
+
+			Assert.IsTrue (File.Exists (thumb_path), String.Format ("Missing: {0} created from {1}", thumb_path, path));
+			using (Gdk.Pixbuf thumb = new Gdk.Pixbuf (thumb_path)) {
+				Assert.IsNotNull (thumb);
+				Assert.AreEqual (thumb.GetOption (ThumbnailGenerator.ThumbUri), UriUtils.PathToFileUriEscaped (path));
+				Assert.AreEqual (new Uri (thumb.GetOption (ThumbnailGenerator.ThumbUri)), UriUtils.PathToFileUri (path));
+				Assert.IsTrue (ThumbnailGenerator.ThumbnailIsValid (thumb, UriUtils.PathToFileUri (path)));
+			}
+			
+			File.Delete (path);
+			File.Delete (thumb_path);
+		}
+
+		[Test]
+		public void UriNames ()
+		{
+			foreach (string name in Names) {
+				UriNames (name);
+			}
+		}
+
+		public void UriNames (string name)
+		{
+			string path = CreateFile (name, 768);
+			Uri uri = new Uri (Gnome.Vfs.Uri.GetUriFromLocalPath (path));
+
+			string string_path = ThumbnailGenerator.ThumbnailPath (path);
+			string thumb_path = ThumbnailGenerator.ThumbnailPath (uri);
+			Assert.AreEqual (thumb_path, string_path);
+
+			ThumbnailGenerator.Create (uri);
+
+			Assert.IsTrue (File.Exists (thumb_path), String.Format ("Missing: {0} created from {1}", thumb_path, uri));
+			using (Gdk.Pixbuf thumb = new Gdk.Pixbuf (thumb_path)) {
+				Assert.IsNotNull (thumb);
+				Assert.AreEqual (thumb.GetOption (ThumbnailGenerator.ThumbUri), UriUtils.UriToStringEscaped (uri));
+				Assert.AreEqual (new Uri (thumb.GetOption (ThumbnailGenerator.ThumbUri)), uri);
+				Assert.IsTrue (ThumbnailGenerator.ThumbnailIsValid (thumb, uri));
+			}
+
+			File.Delete (thumb_path);
+			File.Delete (path);
+		}
+	}
+}
+#endif 
+

Modified: trunk/src/Core/DbItem.cs
==============================================================================
--- trunk/src/Core/DbItem.cs	(original)
+++ trunk/src/Core/DbItem.cs	Wed Jan 30 12:30:12 2008
@@ -17,5 +17,3 @@
 		this.id = id;
 	}
 }
-
-

Modified: trunk/src/Core/Photo.cs
==============================================================================
--- trunk/src/Core/Photo.cs	(original)
+++ trunk/src/Core/Photo.cs	Wed Jan 30 12:30:12 2008
@@ -27,13 +27,10 @@
 		{}
 	}
 
-	public partial class Photo : DbItem, IComparable, FSpot.IBrowsableItem {
+	public class Photo : DbItem, IComparable, IBrowsableItem {
 		// IComparable 
 		public int CompareTo (object obj) {
 			if (this.GetType () == obj.GetType ()) {
-				// FIXME this is way under powered for a real compare in the
-				// equal case but for now it should do.
-	
 				return Compare (this, (Photo)obj);
 			} else if (obj is DateTime) {
 				return this.time.CompareTo ((DateTime)obj);
@@ -277,22 +274,7 @@
 	
 			return false;
 		}
-	
-		[Obsolete ("use GetVersion (uint).Name")]
-		public string GetVersionName (uint version_id)
-		{
-			PhotoVersion v = GetVersion (version_id) as PhotoVersion;
-			if (v != null)
-				return v.Name;
-			return null;
-		}
-	
-		[Obsolete ("Use VersionUri (uint) instead")]
-	        public string GetVersionPath (uint version_id)
-		{
-			return VersionUri (version_id).LocalPath;
-		}
-	
+
 		public System.Uri VersionUri (uint version_id)
 		{
 			if (!Versions.ContainsKey (version_id))
@@ -332,7 +314,7 @@
 					version = CreateDefaultModifiedVersion (DefaultVersionId, false);
 	
 				try {
-					string version_path = GetVersionPath (version);
+					string version_path = VersionUri (version).LocalPath;
 				
 					using (Stream stream = System.IO.File.OpenWrite (version_path)) {
 						img.Save (buffer, stream);
@@ -577,7 +559,6 @@
 		}
 	
 
-
 		// Constructor
 		public Photo (uint id, long unix_time, System.Uri uri)
 			: base (id)
@@ -594,19 +575,5 @@
 			// database.
 			AddVersionUnsafely (OriginalVersionId, uri, Catalog.GetString ("Original"), true);
 		}
-	
-		[Obsolete ("Use Photo (uint, long, Uri) instead")]
-		public Photo (uint id, long unix_time, string directory_path, string name)
-			: this (id, unix_time, System.IO.Path.Combine (directory_path, name))
-		{
-		}
-	
-		[Obsolete ("Use Photo (uint, long, Uri) instead")]
-		public Photo (uint id, long unix_time, string path)
-			: this (id, unix_time, UriUtils.PathToFileUri (path))
-		{
-		}
-	
 	}
-	
 }

Modified: trunk/src/FileImportBackend.cs
==============================================================================
--- trunk/src/FileImportBackend.cs	(original)
+++ trunk/src/FileImportBackend.cs	Wed Jan 30 12:30:12 2008
@@ -82,7 +82,7 @@
 				if (id == Photo.OriginalVersionId)
 				        name = p.Name;
 				else 
-					name = (new System.IO.FileInfo (p.GetVersionPath (id))).Name;
+					name = (new System.IO.FileInfo (p.VersionUri (id).LocalPath)).Name;
 
 				exiting_entries [name] = p;
 			}

Modified: trunk/src/PhotoVersionCommands.cs
==============================================================================
--- trunk/src/PhotoVersionCommands.cs	(original)
+++ trunk/src/PhotoVersionCommands.cs	Wed Jan 30 12:30:12 2008
@@ -28,7 +28,7 @@
 
 			if (photo.VersionNameExists (new_name)
 			    && ! (request_type == RequestType.Rename
-				  && new_name == photo.GetVersionName (photo.DefaultVersionId))) {
+				  && new_name == photo.GetVersion (photo.DefaultVersionId).Name)) {
 				already_in_use_label.Markup = "<small>This name is already in use</small>";
 				ok_button.Sensitive = false;
 				return;
@@ -61,7 +61,7 @@
 			case RequestType.Rename:
 				this.Dialog.Title = Catalog.GetString ("Rename Version");
 				prompt_label.Text = Catalog.GetString ("New name:");
-				version_name_entry.Text = photo.GetVersionName (photo.DefaultVersionId);
+				version_name_entry.Text = photo.GetVersion (photo.DefaultVersionId).Name;
 				version_name_entry.SelectRegion (0, -1);
 				break;
 			}
@@ -79,7 +79,7 @@
 			ResponseType response = (ResponseType) this.Dialog.Run ();
 
 			name = version_name_entry.Text;
-			if (request_type == RequestType.Rename && name == photo.GetVersionName (photo.DefaultVersionId))
+			if (request_type == RequestType.Rename && name == photo.GetVersion (photo.DefaultVersionId).Name)
 				response = ResponseType.Cancel;
 
 			this.Dialog.Destroy ();
@@ -139,7 +139,7 @@
 			dialog.AddButton (Catalog.GetString ("Delete"), (int) ResponseType.Ok);
 			dialog.DefaultResponse = ResponseType.Ok;
 
-			string version_name = photo.GetVersionName (photo.DefaultVersionId);
+			string version_name = photo.GetVersion (photo.DefaultVersionId).Name;
 			Label label = new Label (String.Format (Catalog.GetString ("Really delete version \"{0}\"?"), version_name));
 			label.Show ();
 			dialog.VBox.PackStart (label, false, true, 6);;

Modified: trunk/src/PhotoVersionMenu.cs
==============================================================================
--- trunk/src/PhotoVersionMenu.cs	(original)
+++ trunk/src/PhotoVersionMenu.cs	Wed Jan 30 12:30:12 2008
@@ -52,7 +52,7 @@
 
 		int i = 0;
 		foreach (uint id in version_ids) {
-			MenuItem menu_item = new MenuItem (photo.GetVersionName (id));
+			MenuItem menu_item = new MenuItem (photo.GetVersion (id).Name);
 			menu_item.Show ();
 			menu_item.Sensitive = true;
 			menu_item.Activated += new EventHandler (HandleMenuItemActivated);

Modified: trunk/src/RotateCommand.cs
==============================================================================
--- trunk/src/RotateCommand.cs	(original)
+++ trunk/src/RotateCommand.cs	Wed Jan 30 12:30:12 2008
@@ -127,7 +127,7 @@
 			if (item is Photo) {
 				Photo p = (Photo) item;
 
-				original_path = p.GetVersionPath (p.VersionIds [version_index++]);
+				original_path = p.VersionUri (p.VersionIds [version_index++]).LocalPath;
 				done = (version_index >= p.VersionIds.Length);
 			} else {
 				original_path = item.DefaultVersionUri.LocalPath;

Modified: trunk/src/ThumbnailGenerator.cs
==============================================================================
--- trunk/src/ThumbnailGenerator.cs	(original)
+++ trunk/src/ThumbnailGenerator.cs	Wed Jan 30 12:30:12 2008
@@ -2,10 +2,6 @@
 using System.IO;
 using FSpot.Utils;
 
-#if ENABLE_NUNIT
-using NUnit.Framework;
-#endif
-
 namespace FSpot {
 	public class ThumbnailGenerator : PixbufLoader {
 		private static Gnome.ThumbnailFactory factory = new Gnome.ThumbnailFactory (Gnome.ThumbnailSize.Large);
@@ -128,125 +124,5 @@
 			}
 		}
 
-#if ENABLE_NUNIT
-		[TestFixture]
-		public class Tests {
-			string [] Names = new string [] { 
-				"\x00a9F-SpotUnit\x00b5Test.png",
-				"img(\x00a9F-SpotUnit\x00b5Test).png",
-				"img\u00ff.png",
-				"img\u0100.png",
-				"imgÎ.png",
-				"img(Î).png",
-				"img(ÏÏÎÏÎÏÎÎÎÎÎÎÎ).png",
-			};
-
-			public Tests ()
-			{
-				Gnome.Vfs.Vfs.Initialize ();
-			}
-
-			public string CreateFile (string name, int size)
-			{
-				using (Gdk.Pixbuf test = new Gdk.Pixbuf (null, "f-spot-32.png")) {
-					using (Gdk.Pixbuf tmp = test.ScaleSimple (size, size, Gdk.InterpType.Nearest)) {
-						string path = System.IO.Path.GetTempPath ();
-						path = System.IO.Path.Combine (path, name);
-						Console.WriteLine (path);
-						tmp.Save (path, Path.GetExtension (path).TrimStart (new char [] { '.' }));
-						return path;
-					}
-				}
-			}
-			
-			[Test]
-			public void BadNames ()
-			{
-				foreach (string name in Names) {
-					BadNames (name);
-				}
-			}
-
-			public void BadNames (string name)
-			{
-				string path = CreateFile (name, 512);
-				System.Uri uri = UriUtils.PathToFileUri (path);
-	
-				Gnome.ThumbnailFactory factory = new Gnome.ThumbnailFactory (Gnome.ThumbnailSize.Large);
-				string escaped = UriUtils.PathToFileUriEscaped (path);
-				string large_path = Gnome.Thumbnail.PathForUri (escaped,
-										Gnome.ThumbnailSize.Large);
-
-				using (Gdk.Pixbuf pixbuf = new Gdk.Pixbuf (uri.LocalPath)) {
-					factory.SaveThumbnail (pixbuf, escaped, System.DateTime.Now);
-					
-					Assert.IsTrue (File.Exists (large_path), String.Format ("Missing: {0} created from {1} as {2}", large_path, path, escaped));
-					Gdk.Pixbuf thumb = new Gdk.Pixbuf (large_path);
-					Assert.IsNotNull (thumb);
-				}
-
-				File.Delete (path);
-				File.Delete (large_path);
-			}
-
-			[Test]
-			public void StringNames ()
-			{
-				foreach (string name in Names) {
-					StringNames (name);
-				}
-			}
-			
-			public void StringNames (string name)
-			{
-				string path = CreateFile (name, 1024);
-				string thumb_path = ThumbnailGenerator.ThumbnailPath (path);
-				
-				ThumbnailGenerator.Create (path);
-
-				Assert.IsTrue (File.Exists (thumb_path), String.Format ("Missing: {0} created from {1}", thumb_path, path));
-				using (Gdk.Pixbuf thumb = new Gdk.Pixbuf (thumb_path)) {
-					Assert.IsNotNull (thumb);
-					Assert.AreEqual (thumb.GetOption (ThumbUri), UriUtils.PathToFileUriEscaped (path));
-					Assert.AreEqual (new Uri (thumb.GetOption (ThumbUri)), UriUtils.PathToFileUri (path));
-					Assert.IsTrue (ThumbnailGenerator.ThumbnailIsValid (thumb, UriUtils.PathToFileUri (path)));
-				}
-				
-				File.Delete (path);
-				File.Delete (thumb_path);
-			}
-
-			[Test]
-			public void UriNames ()
-			{
-				foreach (string name in Names) {
-					UriNames (name);
-				}
-			}
-
-			public void UriNames (string name)
-			{
-				string path = CreateFile (name, 768);
-				Uri uri = new Uri (Gnome.Vfs.Uri.GetUriFromLocalPath (path));
-
-				string string_path = ThumbnailGenerator.ThumbnailPath (path);
-				string thumb_path = ThumbnailGenerator.ThumbnailPath (uri);
-				Assert.AreEqual (thumb_path, string_path);
-
-				ThumbnailGenerator.Create (uri);
-
-				Assert.IsTrue (File.Exists (thumb_path), String.Format ("Missing: {0} created from {1}", thumb_path, uri));
-				using (Gdk.Pixbuf thumb = new Gdk.Pixbuf (thumb_path)) {
-					Assert.IsNotNull (thumb);
-					Assert.AreEqual (thumb.GetOption (ThumbUri), UriUtils.UriToStringEscaped (uri));
-					Assert.AreEqual (new Uri (thumb.GetOption (ThumbUri)), uri);
-					Assert.IsTrue (ThumbnailGenerator.ThumbnailIsValid (thumb, uri));
-				}
-
-				File.Delete (thumb_path);
-				File.Delete (path);
-			}
-		}
-#endif 
 	}
 }



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