File hashjob.patch of Package f-spot

From 51a917d7bbba286547ac5be7e54d7d2d4fa55414 Mon Sep 17 00:00:00 2001
From: sdelcroix <sdelcroix@772769d8-d925-0410-89eb-a6ffa0d40526>
Date: Mon, 24 Nov 2008 13:10:54 +0000
Subject: [PATCH] yet another round of fixes for md5

2008-11-24  Lorenzo Milesi  <maxxer@yetopen.it>

	* src/Core/Photo.cs: ensure md5 is hashed when creating new version
	with SaveVersion.


2008-11-24  Lorenzo Milesi  <maxxer@yetopen.it>

	* HashJob/HashJob.cs: check for missing hashes in photo versions, and
	check for empty strings also, not only for null (to work on db 16.3).
	display some feedback when pressing buttons.
	* HashJob/HashJob.addin.xml: bump ver. fix bgo#558671.

git-svn-id: svn+ssh://svn.gnome.org/svn/f-spot/branches/FSPOT_0_5_0_STABLE@4616 772769d8-d925-0410-89eb-a6ffa0d40526
---
 ChangeLog                                  |    5 +++
 extensions/Tools/ChangeLog                 |    7 +++++
 extensions/Tools/HashJob/HashJob.addin.xml |    2 +-
 extensions/Tools/HashJob/HashJob.cs        |   38 +++++++++++++++++++++++++---
 src/Core/Photo.cs                          |   12 +--------
 5 files changed, 48 insertions(+), 16 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 6bb4c95..545004f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2008-11-24  Lorenzo Milesi  <maxxer@yetopen.it>
+
+	* src/Core/Photo.cs: ensure md5 is hashed when creating new version
+	with SaveVersion.
+
 2008-09-25  Stephane Delcroix  <sdelcroix@novell.com>
 
 	* src/PhotoVersionMenu.cs: no longer Ellipsize items
diff --git a/extensions/Tools/ChangeLog b/extensions/Tools/ChangeLog
index 7c92594..a573ef4 100644
--- a/extensions/Tools/ChangeLog
+++ b/extensions/Tools/ChangeLog
@@ -1,3 +1,10 @@
+2008-11-24  Lorenzo Milesi  <maxxer@yetopen.it>
+
+	* HashJob/HashJob.cs: check for missing hashes in photo versions, and
+	check for empty strings also, not only for null (to work on db 16.3).
+	display some feedback when pressing buttons.
+	* HashJob/HashJob.addin.xml: bump ver. fix bgo#558671.
+
 2008-10-17  Stephane Delcroix  <sdelcroix@novell.com>
 
 	* HashJob/: new HashJob extension
diff --git a/extensions/Tools/HashJob/HashJob.addin.xml b/extensions/Tools/HashJob/HashJob.addin.xml
index f70af7a..fa3d865 100644
--- a/extensions/Tools/HashJob/HashJob.addin.xml
+++ b/extensions/Tools/HashJob/HashJob.addin.xml
@@ -1,6 +1,6 @@
 <Addin namespace="FSpot"
 	id="HashJob"
-	version="0.5.0.0"
+	version="0.5.0.1"
 	description="Process your photo collection for duplicate detection"
 	author="Stephane Delcroix"
 	url="http://f-spot.org/Extensions"
diff --git a/extensions/Tools/HashJob/HashJob.cs b/extensions/Tools/HashJob/HashJob.cs
index 7aecd53..696bcb4 100644
--- a/extensions/Tools/HashJob/HashJob.cs
+++ b/extensions/Tools/HashJob/HashJob.cs
@@ -15,7 +15,6 @@ using Mono.Data.SqliteClient;
 using Gtk;
 
 using FSpot;
-using FSpot.UI.Dialog;
 using FSpot.Extensions;
 using FSpot.Jobs;
 
@@ -31,14 +30,37 @@ namespace HashJobExtension {
 
 	public class HashJobDialog : Dialog 
 	{
+		private Gtk.Label status_label;
 
 		public void ShowDialog ()
 		{ 			
+			// This query is not very fast, but it's a 'one-time' so don't care much...
+			SqliteDataReader reader = FSpot.Core.Database.Database.Query (
+				"SELECT COUNT(*) FROM photos p WHERE md5_sum IS NULL OR md5_sum = '' OR EXISTS " +
+					"(SELECT * FROM photo_versions pv WHERE p.id=pv.photo_id AND version_id <> '1' AND " +
+					"(pv.md5_sum IS NULL OR pv.md5_sum = ''))");
+			reader.Read ();
+			uint missing_md5 = Convert.ToUInt32 (reader[0]);
+			reader.Close ();
+
+			reader = FSpot.Core.Database.Database.Query (String.Format (
+				"SELECT COUNT(*) FROM jobs WHERE job_type = '{0}' ", typeof(FSpot.Jobs.CalculateHashJob).ToString ()));
+			reader.Read ();
+			uint active_jobs = Convert.ToUInt32 (reader[0]);
+			reader.Close ();
+
 			VBox.Spacing = 6;
-			Label l = new Label ("In order to detect duplicates on pictures you imported before f-spot 0.5.0, f-spot need to analyze your image collection. This is is not done by default as it's time consuming. You can Start or Pause this update process using this dialog."); 
+			Label l = new Label (Catalog.GetString ("In order to detect duplicates on pictures you imported before 0.5.0, " +
+					"F-Spot needs to analyze your image collection. This is is not done by default as it's time consuming. " +
+					"You can Start or Pause this update process using this dialog."));
 			l.LineWrap = true;
 			VBox.PackStart (l);
 
+			Label l2 = new Label (Catalog.GetString (String.Format ("You currently have {0} photos needing md5 calculation, and {1} pending jobs",
+				missing_md5, active_jobs)));
+			l2.LineWrap = true;
+			VBox.PackStart (l2);
+
 			Button execute = new Button (Stock.Execute);
 			execute.Clicked += HandleExecuteClicked;
 			VBox.PackStart (execute);
@@ -47,11 +69,13 @@ namespace HashJobExtension {
 			stop.Clicked += HandleStopClicked;
 			VBox.PackStart (stop);
 
+			status_label = new Label ();
+			VBox.PackStart (status_label);
+
 			this.AddButton ("_Close", ResponseType.Close);
 			this.Response += HandleResponse;
 
 			ShowAll ();
-
 		}
 
 		void HandleResponse (object obj, ResponseArgs args)
@@ -66,18 +90,24 @@ namespace HashJobExtension {
 
 		void HandleExecuteClicked (object o, EventArgs e)
 		{
-			SqliteDataReader reader = FSpot.Core.Database.Database.Query ("SELECT id from photos WHERE md5_sum IS NULL");
+			SqliteDataReader reader = FSpot.Core.Database.Database.Query (
+				"SELECT id FROM photos p WHERE md5_sum IS NULL OR md5_sum = '' OR EXISTS " +
+					"(SELECT * FROM photo_versions pv WHERE p.id=pv.photo_id AND version_id <> '1' AND " +
+					"(pv.md5_sum IS NULL OR pv.md5_sum = '') )");
 			FSpot.Core.Database.Database.BeginTransaction ();
 			while (reader.Read ())
 				FSpot.Jobs.CalculateHashJob.Create (FSpot.Core.Database.Jobs, Convert.ToUInt32 (reader[0]));
 			reader.Close ();
 			FSpot.Core.Database.Database.CommitTransaction ();
+			status_label.Text = Catalog.GetString ("Processing images...");
 		}
 
 		void HandleStopClicked (object o, EventArgs e)
 		{
 			FSpot.Core.Database.Database.ExecuteNonQuery (String.Format ("DELETE FROM jobs WHERE job_type = '{0}'", typeof(FSpot.Jobs.CalculateHashJob).ToString ()));
+			status_label.Text = Catalog.GetString ("Stopped");
 		}
+
 	}
 
 }
diff --git a/src/Core/Photo.cs b/src/Core/Photo.cs
index 0fdfd6b..9493bb5 100644
--- a/src/Core/Photo.cs
+++ b/src/Core/Photo.cs
@@ -359,6 +359,7 @@ namespace FSpot
 					using (Stream stream = System.IO.File.OpenWrite (version_path)) {
 						img.Save (buffer, stream);
 					}
+					(GetVersion (version) as PhotoVersion).MD5Sum = GenerateMD5 (VersionUri (version));
 					FSpot.ThumbnailGenerator.Create (version_path).Dispose ();
 					DefaultVersionId = version;
 				} catch (System.Exception e) {
@@ -446,18 +447,7 @@ namespace FSpot
 					XferOverwriteMode.Abort, 
 					delegate (Gnome.Vfs.XferProgressInfo info) {return 1;});
 	
-	//			Mono.Unix.Native.Stat stat;
-	//			int stat_err = Mono.Unix.Native.Syscall.stat (original_path, out stat);
-	//			File.Copy (original_path, new_path);
 				FSpot.ThumbnailGenerator.Create (new_uri).Dispose ();
-	//			
-	//			if (stat_err == 0) 
-	//				try {
-	//					Mono.Unix.Native.Syscall.chown(new_path, Mono.Unix.Native.Syscall.getuid (), stat.st_gid);
-	//				} catch (Exception) {}
-	//
-			} else {
-				md5_sum = Photo.GenerateMD5 (new_uri);
 			}
 			highest_version_id ++;
 
-- 
1.6.0.2

openSUSE Build Service is sponsored by