[f-spot/taglib-metadata: 18/20] Move FileBrowsableItem into Core.



commit fd12263a74bfa46f4c2ee613d60460da4d8f206a
Author: Ruben Vermeersch <ruben savanne be>
Date:   Sat Jun 26 20:23:55 2010 +0200

    Move FileBrowsableItem into Core.

 extensions/Tools/MergeDb/MergeDb.cs |    2 +-
 src/Core/FileBrowsableItem.cs       |  110 +++++++++++++++++++++++++++++++++++
 src/Core/Makefile.am                |    1 +
 src/Core/Photo.cs                   |   11 +---
 src/FileBrowsableItem.cs            |  109 ----------------------------------
 src/Import/ImportSource.cs          |    2 +-
 src/Makefile.am                     |    1 -
 src/PhotoStore.cs                   |    2 +-
 src/Utils/HashUtils.cs              |   15 +++++
 src/Utils/Makefile.am               |    1 +
 10 files changed, 131 insertions(+), 123 deletions(-)
---
diff --git a/extensions/Tools/MergeDb/MergeDb.cs b/extensions/Tools/MergeDb/MergeDb.cs
index 4b2589d..6e0dfbc 100644
--- a/extensions/Tools/MergeDb/MergeDb.cs
+++ b/extensions/Tools/MergeDb/MergeDb.cs
@@ -241,7 +241,7 @@ namespace MergeDbExtension
 			photo.DefaultVersion.Uri = dest_uri;
 
 			if (photo.DefaultVersion.ImportMD5 == String.Empty) {
-				(photo.DefaultVersion as PhotoVersion).ImportMD5 = Photo.GenerateMD5 (photo.DefaultVersion.Uri);
+				(photo.DefaultVersion as PhotoVersion).ImportMD5 = HashUtils.GenerateMD5 (photo.DefaultVersion.Uri);
 			}
 
 			if (photo_path != destination) {
diff --git a/src/Core/FileBrowsableItem.cs b/src/Core/FileBrowsableItem.cs
new file mode 100644
index 0000000..708f0fe
--- /dev/null
+++ b/src/Core/FileBrowsableItem.cs
@@ -0,0 +1,110 @@
+/*
+ * FileBrowsableItem.cs
+ *
+ * Author(s):
+ *	Larry Ewing  (lewing novell com)
+ *	Stephane Delcroix  (stephane delcroix org)
+ *
+ * This is free software. See COPYING for details
+ */
+
+
+using System;
+using System.IO;
+using System.Collections;
+using System.Xml;
+
+using Hyena;
+using FSpot.Utils;
+
+using Mono.Unix.Native;
+
+namespace FSpot {
+    public class FileBrowsableItem : IBrowsableItem
+    {
+        bool metadata_parsed = false;
+
+        public FileBrowsableItem (SafeUri uri)
+        {
+            DefaultVersion = new FileBrowsableItemVersion () {
+                Uri = uri
+            };
+        }
+
+        private void EnsureMetadataParsed ()
+        {
+            if (metadata_parsed)
+                return;
+
+            var res = new GIOTagLibFileAbstraction () { Uri = DefaultVersion.Uri };
+            using (var metadata = TagLib.File.Create (res) as TagLib.Image.File) {
+                var date = metadata.ImageTag.DateTime;
+                time = date.HasValue ? date.Value : CreateDate;
+                description = metadata.ImageTag.Comment;
+            }
+
+            metadata_parsed = true;
+        }
+
+        private DateTime CreateDate {
+            get {
+                var info = GLib.FileFactory.NewForUri (DefaultVersion.Uri).QueryInfo ("time::created", GLib.FileQueryInfoFlags.None, null);
+                return NativeConvert.ToDateTime ((long)info.GetAttributeULong ("time::created"));
+            }
+        }
+
+        public Tag [] Tags {
+            get {
+                return null;
+            }
+        }
+
+        private DateTime time;
+        public DateTime Time {
+            get {
+                EnsureMetadataParsed ();
+                return time;
+            }
+        }
+
+        public IBrowsableItemVersion DefaultVersion { get; private set; }
+
+        private string description;
+        public string Description {
+            get {
+                EnsureMetadataParsed ();
+                return description;
+            }
+        }
+
+        public string Name {
+            get {
+                return DefaultVersion.Uri.GetFilename ();
+            }
+        }
+
+        public uint Rating {
+            get {
+                return 0; //FIXME ndMaxxer: correct?
+            }
+        }
+
+        private class FileBrowsableItemVersion : IBrowsableItemVersion {
+            public string Name { get { return String.Empty; } }
+            public bool IsProtected { get { return true; } }
+
+            public SafeUri BaseUri { get { return Uri.GetBaseUri (); } }
+            public string Filename { get { return Uri.GetFilename (); } }
+            public SafeUri Uri { get; set; }
+
+            private string import_md5 = String.Empty;
+            public string ImportMD5 {
+                get {
+                    if (import_md5 == String.Empty)
+                        import_md5 = HashUtils.GenerateMD5 (Uri);
+                    return import_md5;
+                }
+            }
+        }
+    }
+}
diff --git a/src/Core/Makefile.am b/src/Core/Makefile.am
index c5aafe2..1409421 100644
--- a/src/Core/Makefile.am
+++ b/src/Core/Makefile.am
@@ -11,6 +11,7 @@ SOURCES = \
 	Delay.cs \
 	Tag.cs \
 	Global.cs \
+	FileBrowsableItem.cs \
 	IBrowsableItem.cs \
 	IBrowsableItemChanges.cs \
 	IBrowsableItemComparer.cs \
diff --git a/src/Core/Photo.cs b/src/Core/Photo.cs
index b5e72c2..8605852 100644
--- a/src/Core/Photo.cs
+++ b/src/Core/Photo.cs
@@ -233,7 +233,7 @@ namespace FSpot
 					using (Stream stream = System.IO.File.OpenWrite (versionUri.LocalPath)) {
 						img.Save (buffer, stream);
 					}
-					(GetVersion (version) as PhotoVersion).ImportMD5 = GenerateMD5 (VersionUri (version));
+					(GetVersion (version) as PhotoVersion).ImportMD5 = HashUtils.GenerateMD5 (VersionUri (version));
 					DefaultVersionId = version;
 				} catch (System.Exception e) {
 					Log.Exception (e);
@@ -501,15 +501,6 @@ namespace FSpot
 				md5_cache.Clear (); 
 		}
 
-		public static string GenerateMD5 (SafeUri uri)
-		{
-			var file = GLib.FileFactory.NewForUri (uri);
-			var stream = new GLib.GioStream (file.Read (null));
-			var hash = CryptoUtil.Md5EncodeStream (stream);
-			stream.Close ();
-			return hash;
-		}
-
 		// Constructor
 		public Photo (uint id, long unix_time)
 			: base (id)
diff --git a/src/Import/ImportSource.cs b/src/Import/ImportSource.cs
index fd2e3b9..ec496d3 100644
--- a/src/Import/ImportSource.cs
+++ b/src/Import/ImportSource.cs
@@ -29,7 +29,7 @@ namespace FSpot.Import
         public string ImportMD5 {
             get {
                 if (import_md5 == String.Empty)
-                    import_md5 = Photo.GenerateMD5 (Uri);
+                    import_md5 = HashUtils.GenerateMD5 (Uri);
                 return import_md5;
             }
         }
diff --git a/src/Makefile.am b/src/Makefile.am
index 3368baf..665add9 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -55,7 +55,6 @@ SOURCES = \
 	Extensions/TransitionNode.cs \
 	Extensions/ViewModeCondition.cs \
 	Fader.cs \
-	FileBrowsableItem.cs \
 	Filters/ChmodFilter.cs \
 	Filters/FilterRequest.cs \
 	Filters/FilterSet.cs \
diff --git a/src/PhotoStore.cs b/src/PhotoStore.cs
index f44d26d..8a1045a 100644
--- a/src/PhotoStore.cs
+++ b/src/PhotoStore.cs
@@ -501,7 +501,7 @@ public class PhotoStore : DbStore<Photo> {
 			if (version.ImportMD5 != String.Empty && version.ImportMD5 != null)
 				continue;
 
-			string version_md5_sum = Photo.GenerateMD5 (version.Uri);
+			string version_md5_sum = HashUtils.GenerateMD5 (version.Uri);
 			version.ImportMD5 = version_md5_sum;
 			photo.Changes.ChangeVersion (version_id);
 		}
diff --git a/src/Utils/HashUtils.cs b/src/Utils/HashUtils.cs
new file mode 100644
index 0000000..7b6a5a3
--- /dev/null
+++ b/src/Utils/HashUtils.cs
@@ -0,0 +1,15 @@
+using Hyena;
+
+namespace FSpot
+{
+	public class HashUtils {
+		public static string GenerateMD5 (SafeUri uri)
+		{
+			var file = GLib.FileFactory.NewForUri (uri);
+			var stream = new GLib.GioStream (file.Read (null));
+			var hash = CryptoUtil.Md5EncodeStream (stream);
+			stream.Close ();
+			return hash;
+		}
+	}
+}
diff --git a/src/Utils/Makefile.am b/src/Utils/Makefile.am
index 8f4d0fb..3b15fcf 100644
--- a/src/Utils/Makefile.am
+++ b/src/Utils/Makefile.am
@@ -11,6 +11,7 @@ SOURCES = \
 	GdkUtils.cs \
     GIOTagLibFileAbstraction.cs \
 	GtkUtil.cs \
+	HashUtils.cs \
 	PixbufUtils.cs \
 	RecursiveFileEnumerator.cs \
 	SafeUri.cs \



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