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



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

    Slightly decouple from ImageFile.

 src/Import/FileImportSource.cs |   19 ++++++++++++-------
 src/Import/ImportController.cs |   11 +++++------
 2 files changed, 17 insertions(+), 13 deletions(-)
---
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]