[f-spot/taglib-metadata] Slightly decouple from ImageFile.



commit 3c95f2a20501874cbdddfa98ecbf9677c2a4251d
Author: Ruben Vermeersch <ruben savanne be>
Date:   Sat Jun 12 00:47:56 2010 +0200

    Slightly decouple from ImageFile.

 src/Imaging/ImageFile.cs       |    6 ++++++
 src/Import/FileImportSource.cs |   19 ++++++++++++-------
 src/Import/ImportController.cs |   11 +++++------
 3 files changed, 23 insertions(+), 13 deletions(-)
---
diff --git a/src/Imaging/ImageFile.cs b/src/Imaging/ImageFile.cs
index c770c00..079d5c3 100644
--- a/src/Imaging/ImageFile.cs
+++ b/src/Imaging/ImageFile.cs
@@ -190,6 +190,12 @@ namespace FSpot {
 		static Type GetLoaderType (SafeUri uri)
 		{
 			string extension = uri.GetExtension ().ToLower ();
+			if (extension == ".thm") {
+				// Ignore video thumbnails
+				return null;
+			}
+
+
 			Type t = (Type) name_table [extension];
 
 			if (t == null) {
diff --git a/src/Import/FileImportSource.cs b/src/Import/FileImportSource.cs
index 4ee1942..663b110 100644
--- a/src/Import/FileImportSource.cs
+++ b/src/Import/FileImportSource.cs
@@ -4,6 +4,7 @@ using System.Threading;
 using System.Collections.Generic;
 using FSpot.Utils;
 using Gtk;
+using Mono.Unix.Native;
 
 namespace FSpot.Import
 {
@@ -154,18 +155,22 @@ namespace FSpot.Import
         public System.DateTime Time {
             get {
                 if (!time.HasValue) {
-                    try {
-                        using (FSpot.ImageFile img = FSpot.ImageFile.Create (DefaultVersion.Uri)) {
-                            time = img.Date;
-                        }
-                    } catch (Exception) {
-                        time = DateTime.Now;
-                    }
+                    var res = new GIOTagLibFileAbstraction () { Uri = DefaultVersion.Uri };
+                    var metadata_file = TagLib.File.Create (res) as TagLib.Image.File;
+                    var date = metadata_file.ImageTag.DateTime;
+                    time = date.HasValue ? date.Value : CreateDate;
                 }
                 return time.Value;
             }
         }
 
+        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 { throw new NotImplementedException (); } }
         public string Description { get { throw new NotImplementedException (); } }
         public string Name { get { throw new NotImplementedException (); } }
diff --git a/src/Import/ImportController.cs b/src/Import/ImportController.cs
index 875e49b..71bb30a 100644
--- a/src/Import/ImportController.cs
+++ b/src/Import/ImportController.cs
@@ -291,7 +291,7 @@ namespace FSpot.Import
 
         void ImportPhoto (IBrowsableItem item, Roll roll)
         {
-            var destination = FindImportDestination (item.DefaultVersion.Uri);
+            var destination = FindImportDestination (item);
             string hash = String.Empty;
 
             // Do duplicate detection
@@ -334,17 +334,16 @@ namespace FSpot.Import
             imported_photos.Add (photo.Id);
         }
 
-        SafeUri FindImportDestination (SafeUri uri)
+        SafeUri FindImportDestination (IBrowsableItem item)
         {
+            var uri = item.DefaultVersion.Uri;
+
             if (!CopyFiles)
                 return uri; // Keep it at the same place
 
             // Find a new unique location inside the photo folder
             string name = uri.GetFilename ();
-            DateTime time;
-            using (FSpot.ImageFile img = FSpot.ImageFile.Create (uri)) {
-                time = img.Date;
-            }
+            DateTime time = item.Time;
 
             var dest_uri = Global.PhotoUri.Append (time.Year.ToString ())
                                           .Append (String.Format ("{0:D2}", time.Month))



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