[f-spot/taglib-metadata: 8/10] Pull date handling out of Imaging.
- From: Ruben Vermeersch <rubenv src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [f-spot/taglib-metadata: 8/10] Pull date handling out of Imaging.
- Date: Sat, 12 Jun 2010 15:57:21 +0000 (UTC)
commit f4b5b25ae54664178d4c2c8093c945269d760f65
Author: Ruben Vermeersch <ruben savanne be>
Date: Sat Jun 12 13:52:49 2010 +0200
Pull date handling out of Imaging.
Also move PhotoStore creating to a model that uses IBrowsableItem.
extensions/Tools/MergeDb/MergeDb.cs | 25 +++++++--------
extensions/Tools/MergeDb/MergeDbDialog.cs | 1 -
src/Core/IBrowsableItem.cs | 2 -
src/Core/IBrowsableItemVersion.cs | 2 +-
src/Core/PhotoVersion.cs | 46 ++++++++++++++++------------
src/FileBrowsableItem.cs | 34 +++++++++++++++++----
src/Imaging/Ciff.cs | 14 ---------
src/Imaging/ImageFile.cs | 18 -----------
src/Imaging/JpegFile.cs | 7 ----
src/Imaging/MrwFile.cs | 12 -------
src/Imaging/PngFile.cs | 15 ---------
src/Imaging/Tiff.cs | 21 -------------
src/Import/ImportController.cs | 9 ++----
src/Import/ImportSource.cs | 17 +++++++++-
src/PhotoStore.cs | 29 ++++++------------
src/PhotoVersionCommands.cs | 2 +-
16 files changed, 96 insertions(+), 158 deletions(-)
---
diff --git a/extensions/Tools/MergeDb/MergeDb.cs b/extensions/Tools/MergeDb/MergeDb.cs
index 85effb6..b1a4c66 100644
--- a/extensions/Tools/MergeDb/MergeDb.cs
+++ b/extensions/Tools/MergeDb/MergeDb.cs
@@ -188,7 +188,6 @@ namespace MergeDbExtension
void ImportPhoto (Photo photo, bool copy)
{
Log.WarningFormat ("Importing {0}", photo.Name);
- PhotoStore from_store = from_db.Photos;
PhotoStore to_store = to_db.Photos;
string photo_path = photo.VersionUri (Photo.OriginalVersionId).AbsolutePath;
@@ -232,19 +231,21 @@ namespace MergeDbExtension
Photo newp;
if (copy)
- destination = FindImportDestination (new SafeUri (photo_path)).AbsolutePath;
+ destination = FindImportDestination (new SafeUri (photo_path), photo.Time).AbsolutePath;
else
destination = photo_path;
+ var dest_uri = new SafeUri (photo_path);
- var hash = Photo.GenerateMD5 (new SafeUri (photo_path));
+ photo.DefaultVersionId = 1;
+ photo.DefaultVersion.Uri = dest_uri;
- // Don't copy if we are already home
- if (photo_path == destination)
- newp = to_store.Create (new SafeUri (destination), roll_map [photo.RollId], hash);
- else {
+ if (photo.DefaultVersion.ImportMD5 == String.Empty) {
+ (photo.DefaultVersion as PhotoVersion).ImportMD5 = Photo.GenerateMD5 (photo.DefaultVersion.Uri);
+ }
+
+ if (photo_path != destination) {
System.IO.File.Copy (photo_path, destination);
- newp = to_store.Create (new SafeUri (destination), new SafeUri (photo_path), roll_map [photo.RollId], hash);
try {
File.SetAttributes (destination, File.GetAttributes (destination) & ~FileAttributes.ReadOnly);
DateTime create = File.GetCreationTime (photo_path);
@@ -256,6 +257,8 @@ namespace MergeDbExtension
}
}
+ newp = to_store.CreateFrom (photo, roll_map [photo.RollId]);
+
if (newp == null)
return;
@@ -280,14 +283,10 @@ namespace MergeDbExtension
to_store.Commit (newp);
}
- SafeUri FindImportDestination (SafeUri uri)
+ SafeUri FindImportDestination (SafeUri uri, DateTime time)
{
// 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;
- }
var dest_uri = FSpot.Global.PhotoUri.Append (time.Year.ToString ())
.Append (String.Format ("{0:D2}", time.Month))
diff --git a/extensions/Tools/MergeDb/MergeDbDialog.cs b/extensions/Tools/MergeDb/MergeDbDialog.cs
index 7efbf2d..e2bcf0b 100644
--- a/extensions/Tools/MergeDb/MergeDbDialog.cs
+++ b/extensions/Tools/MergeDb/MergeDbDialog.cs
@@ -17,7 +17,6 @@ namespace MergeDbExtension
{
[Glade.Widget] Gtk.Dialog mergedb_dialog;
[Glade.Widget] Gtk.Button apply_button;
- [Glade.Widget] Gtk.Button cancel_button;
[Glade.Widget] Gtk.FileChooserButton db_filechooser;
[Glade.Widget] Gtk.RadioButton newrolls_radio;
[Glade.Widget] Gtk.RadioButton allrolls_radio;
diff --git a/src/Core/IBrowsableItem.cs b/src/Core/IBrowsableItem.cs
index 72ce751..ab9ecfc 100644
--- a/src/Core/IBrowsableItem.cs
+++ b/src/Core/IBrowsableItem.cs
@@ -34,6 +34,4 @@ namespace FSpot
get;
}
}
-
-
}
diff --git a/src/Core/IBrowsableItemVersion.cs b/src/Core/IBrowsableItemVersion.cs
index 366716f..345172a 100644
--- a/src/Core/IBrowsableItemVersion.cs
+++ b/src/Core/IBrowsableItemVersion.cs
@@ -9,7 +9,7 @@ namespace FSpot
string Filename { get; }
// For convenience
- SafeUri Uri { get; }
+ SafeUri Uri { get; set; }
string ImportMD5 { get; }
}
diff --git a/src/Core/PhotoVersion.cs b/src/Core/PhotoVersion.cs
index 683a3a9..4957673 100644
--- a/src/Core/PhotoVersion.cs
+++ b/src/Core/PhotoVersion.cs
@@ -14,26 +14,32 @@ using Hyena;
namespace FSpot
{
- public class PhotoVersion : IBrowsableItemVersion
- {
- public string Name { get; set; }
- public IBrowsableItem Photo { get; private set; }
- public SafeUri BaseUri { get; set; }
+ public class PhotoVersion : IBrowsableItemVersion
+ {
+ public string Name { get; set; }
+ public IBrowsableItem Photo { get; private set; }
+ public SafeUri BaseUri { get; set; }
public string Filename { get; set; }
- public SafeUri Uri { get { return BaseUri.Append (Filename); } }
- public string ImportMD5 { get; internal set; }
- public uint VersionId { get; private set; }
- public bool IsProtected { get; private set; }
-
- public PhotoVersion (IBrowsableItem photo, uint version_id, SafeUri base_uri, string filename, string md5_sum, string name, bool is_protected)
- {
- Photo = photo;
- VersionId = version_id;
- BaseUri = base_uri;
+ public SafeUri Uri {
+ get { return BaseUri.Append (Filename); }
+ set {
+ BaseUri = value.GetBaseUri ();
+ Filename = value.GetFilename ();
+ }
+ }
+ public string ImportMD5 { get; set; }
+ public uint VersionId { get; private set; }
+ public bool IsProtected { get; private set; }
+
+ public PhotoVersion (IBrowsableItem photo, uint version_id, SafeUri base_uri, string filename, string md5_sum, string name, bool is_protected)
+ {
+ Photo = photo;
+ VersionId = version_id;
+ BaseUri = base_uri;
Filename = filename;
- ImportMD5 = md5_sum;
- Name = name;
- IsProtected = is_protected;
- }
- }
+ ImportMD5 = md5_sum;
+ Name = name;
+ IsProtected = is_protected;
+ }
+ }
}
diff --git a/src/FileBrowsableItem.cs b/src/FileBrowsableItem.cs
index d69bed7..89529fb 100644
--- a/src/FileBrowsableItem.cs
+++ b/src/FileBrowsableItem.cs
@@ -16,6 +16,7 @@ using System.Xml;
using Hyena;
using FSpot.Utils;
+using Mono.Unix.Native;
namespace FSpot {
public class FileBrowsableItem : IBrowsableItem, IDisposable
@@ -47,11 +48,25 @@ namespace FSpot {
}
}
- public DateTime Time {
- get {
- return Image.Date;
- }
- }
+ private DateTime? time = null;
+ public System.DateTime Time {
+ get {
+ if (!time.HasValue) {
+ 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 IBrowsableItemVersion DefaultVersion { get; private set; }
@@ -95,7 +110,14 @@ namespace FSpot {
public string Filename { get { return Uri.GetFilename (); } }
public SafeUri Uri { get; set; }
- public string ImportMD5 { get { return String.Empty; } }
+ private string import_md5 = String.Empty;
+ public string ImportMD5 {
+ get {
+ if (import_md5 == String.Empty)
+ import_md5 = Photo.GenerateMD5 (Uri);
+ return import_md5;
+ }
+ }
}
}
}
diff --git a/src/Imaging/Ciff.cs b/src/Imaging/Ciff.cs
index 66425f6..97994ba 100644
--- a/src/Imaging/Ciff.cs
+++ b/src/Imaging/Ciff.cs
@@ -432,20 +432,6 @@ namespace FSpot.Ciff {
return orientation;
}
- public override System.DateTime Date {
- get {
- ImageDirectory props = Root.ReadDirectory (Tag.ImageProps);
- byte [] date = props.ReadEntry (Tag.TimeStamp);
-
- if (date == null) {
- Log.Debug ("NO DATE");
- return base.Date;
- }
-
- return new CaptureTime (date, little).LocalTime;
- }
- }
-
public override System.IO.Stream PixbufStream ()
{
byte [] data = GetEmbeddedJpeg ();
diff --git a/src/Imaging/ImageFile.cs b/src/Imaging/ImageFile.cs
index 6c51631..ef58dc6 100644
--- a/src/Imaging/ImageFile.cs
+++ b/src/Imaging/ImageFile.cs
@@ -37,8 +37,6 @@ namespace FSpot {
protected Stream Open ()
{
Log.DebugFormat ("open uri = {0}", uri.ToString ());
-// if (uri.IsFile)
-// return new FileStream (uri.LocalPath, FileMode.Open);
return new GLib.GioStream (GLib.FileFactory.NewForUri (uri).Read (null));
}
@@ -166,22 +164,6 @@ namespace FSpot {
return null;
}
- public virtual System.DateTime Date
- {
- get {
- // FIXME mono uses the file change time (ctime) incorrectly
- // as the creation time so we try to work around that slightly
- GFileInfo info = GLib.FileFactory.NewForUri (uri).QueryInfo ("time::modified,time::created", GLib.FileQueryInfoFlags.None, null);
- DateTime write = NativeConvert.ToDateTime ((long)info.GetAttributeULong ("time::modified"));
- DateTime create = NativeConvert.ToDateTime ((long)info.GetAttributeULong ("time::created"));
-
- if (create < write)
- return create;
- else
- return write;
- }
- }
-
public static bool HasLoader (SafeUri uri)
{
return GetLoaderType (uri) != null;
diff --git a/src/Imaging/JpegFile.cs b/src/Imaging/JpegFile.cs
index b821b8a..3a568e6 100644
--- a/src/Imaging/JpegFile.cs
+++ b/src/Imaging/JpegFile.cs
@@ -184,12 +184,5 @@ namespace FSpot {
metadata_file.ImageTag.DateTime = time;
}
- public override System.DateTime Date {
- get {
- var date = metadata_file.ImageTag.DateTime;
- return date.HasValue ? date.Value : base.Date;
- }
- }
-
}
}
diff --git a/src/Imaging/MrwFile.cs b/src/Imaging/MrwFile.cs
index df334aa..edc71d5 100644
--- a/src/Imaging/MrwFile.cs
+++ b/src/Imaging/MrwFile.cs
@@ -192,18 +192,6 @@ namespace FSpot.Mrw {
}
}
- public override System.DateTime Date
- {
- get {
- DirectoryEntry e = this.Header.Directory.Lookup (TagId.DateTime);
-
- if (e != null)
- return DirectoryEntry.DateTimeFromString (e.StringValue);
- else
- return base.Date;
- }
- }
-
public void Select (SemWeb.StatementSink sink)
{
this.Header.Select (sink);
diff --git a/src/Imaging/PngFile.cs b/src/Imaging/PngFile.cs
index cc64eec..be87c09 100644
--- a/src/Imaging/PngFile.cs
+++ b/src/Imaging/PngFile.cs
@@ -1375,20 +1375,5 @@ namespace FSpot.Png {
}
Header.Insert (itext);
}
-
- public override System.DateTime Date {
- get {
- // FIXME: we should first try parsing the
- // LookupText ("Creation Time") as a valid date
-
- foreach (Chunk chunk in Chunks) {
- TimeChunk time = chunk as TimeChunk;
- if (time != null)
- return time.Time;
- }
- return base.Date;
- }
- }
-
}
}
diff --git a/src/Imaging/Tiff.cs b/src/Imaging/Tiff.cs
index 2d8e22e..e7df951 100644
--- a/src/Imaging/Tiff.cs
+++ b/src/Imaging/Tiff.cs
@@ -2035,27 +2035,6 @@ namespace FSpot.Tiff {
Header.SelectDirectory (Header.Directory, sink);
}
- public override System.DateTime Date {
- get {
- SubdirectoryEntry sub = (SubdirectoryEntry) this.Header.Directory.Lookup (TagId.ExifIfdPointer);
- DirectoryEntry e;
-
- if (sub != null) {
- e = sub.Directory [0].Lookup (TagId.DateTimeOriginal);
-
- if (e != null)
- return DirectoryEntry.DateTimeFromString (e.StringValue);
- }
-
- e = this.Header.Directory.Lookup (TagId.DateTime);
-
- if (e != null)
- return DirectoryEntry.DateTimeFromString (e.StringValue);
- else
- return base.Date;
- }
- }
-
public override PixbufOrientation GetOrientation ()
{
ShortEntry e = (ShortEntry)(this.Header.Directory.Lookup (TagId.Orientation));
diff --git a/src/Import/ImportController.cs b/src/Import/ImportController.cs
index 71bb30a..73e9b53 100644
--- a/src/Import/ImportController.cs
+++ b/src/Import/ImportController.cs
@@ -292,10 +292,9 @@ namespace FSpot.Import
void ImportPhoto (IBrowsableItem item, Roll roll)
{
var destination = FindImportDestination (item);
- string hash = String.Empty;
// Do duplicate detection
- if (DuplicateDetect && store.HasDuplicate (item.DefaultVersion.Uri, out hash)) {
+ if (DuplicateDetect && store.HasDuplicate (item)) {
return;
}
@@ -305,13 +304,11 @@ namespace FSpot.Import
var new_file = GLib.FileFactory.NewForUri (destination);
file.Copy (new_file, GLib.FileCopyFlags.AllMetadata, null, null);
copied_files.Add (destination);
+ item.DefaultVersion.Uri = destination;
}
// Import photo
- var photo = store.Create (destination,
- item.DefaultVersion.Uri,
- roll.Id,
- hash);
+ var photo = store.CreateFrom (item, roll.Id);
bool needs_commit = false;
diff --git a/src/Import/ImportSource.cs b/src/Import/ImportSource.cs
index ba27d96..fd2e3b9 100644
--- a/src/Import/ImportSource.cs
+++ b/src/Import/ImportSource.cs
@@ -17,8 +17,21 @@ namespace FSpot.Import
public SafeUri BaseUri { get; set; }
public string Filename { get; set; }
- public SafeUri Uri { get { return BaseUri.Append (Filename); } }
+ public SafeUri Uri {
+ get { return BaseUri.Append (Filename); }
+ set {
+ BaseUri = value.GetBaseUri ();
+ Filename = value.GetFilename ();
+ }
+ }
- public string ImportMD5 { get { return String.Empty; } }
+ private string import_md5 = String.Empty;
+ public string ImportMD5 {
+ get {
+ if (import_md5 == String.Empty)
+ import_md5 = Photo.GenerateMD5 (Uri);
+ return import_md5;
+ }
+ }
}
}
diff --git a/src/PhotoStore.cs b/src/PhotoStore.cs
index 98ad319..2248750 100644
--- a/src/PhotoStore.cs
+++ b/src/PhotoStore.cs
@@ -100,8 +100,9 @@ public class PhotoStore : DbStore<Photo> {
Database.ExecuteNonQuery ("CREATE INDEX idx_photos_roll_id ON photos(roll_id)");
}
- public bool HasDuplicate (SafeUri uri, out string hash) {
- hash = Photo.GenerateMD5 (uri);
+ public bool HasDuplicate (IBrowsableItem item) {
+ var uri = item.DefaultVersion.Uri;
+ string hash = item.DefaultVersion.ImportMD5;
var condition = new ConditionWrapper (String.Format ("import_md5 = \"{0}\"", hash));
var dupes_by_hash = Count ("photo_versions", condition);
if (dupes_by_hash > 0)
@@ -122,9 +123,7 @@ public class PhotoStore : DbStore<Photo> {
Log.DebugFormat ("Found one possible duplicate for {0}", reader["filename"].ToString ());
if (!time.HasValue) {
// Only read time when needed
- using (FSpot.ImageFile img = FSpot.ImageFile.Create (uri)) {
- time = img.Date;
- }
+ time = item.Time;
}
if (reader["time"].ToString () == DbUtils.UnixTimeFromDateTime (time.Value).ToString ()) {
@@ -142,20 +141,12 @@ public class PhotoStore : DbStore<Photo> {
return false;
}
- public Photo Create (SafeUri uri, uint roll_id, string import_md5)
- {
- return Create (uri, uri, roll_id, import_md5);
- }
-
- public Photo Create (SafeUri new_uri, SafeUri orig_uri, uint roll_id, string import_md5)
+ public Photo CreateFrom (IBrowsableItem item, uint roll_id)
{
Photo photo;
- var new_base_uri = new_uri.GetBaseUri ();
- var filename = new_uri.GetFilename ();
-
- using (FSpot.ImageFile img = FSpot.ImageFile.Create (orig_uri)) {
- long unix_time = DbUtils.UnixTimeFromDateTime (img.Date);
+ using (FSpot.ImageFile img = FSpot.ImageFile.Create (item.DefaultVersion.Uri)) {
+ long unix_time = DbUtils.UnixTimeFromDateTime (item.Time);
string description = img.Description != null ? img.Description.Split ('\0') [0] : String.Empty;
uint id = (uint) Database.Execute (
@@ -163,8 +154,8 @@ public class PhotoStore : DbStore<Photo> {
"INSERT INTO photos (time, base_uri, filename, description, roll_id, default_version_id, rating) " +
"VALUES (:time, :base_uri, :filename, :description, :roll_id, :default_version_id, :rating)",
"time", unix_time,
- "base_uri", new_base_uri.ToString (),
- "filename", filename,
+ "base_uri", item.DefaultVersion.BaseUri.ToString (),
+ "filename", item.DefaultVersion.Filename,
"description", description,
"roll_id", roll_id,
"default_version_id", Photo.OriginalVersionId,
@@ -173,7 +164,7 @@ public class PhotoStore : DbStore<Photo> {
);
photo = new Photo (id, unix_time);
- photo.AddVersionUnsafely (Photo.OriginalVersionId, new_base_uri, filename, import_md5, Catalog.GetString ("Original"), true);
+ photo.AddVersionUnsafely (Photo.OriginalVersionId, item.DefaultVersion.BaseUri, item.DefaultVersion.Filename, item.DefaultVersion.ImportMD5, Catalog.GetString ("Original"), true);
photo.Loaded = true;
InsertVersion (photo, photo.DefaultVersion as PhotoVersion);
diff --git a/src/PhotoVersionCommands.cs b/src/PhotoVersionCommands.cs
index bae1fae..d2e3eda 100644
--- a/src/PhotoVersionCommands.cs
+++ b/src/PhotoVersionCommands.cs
@@ -173,7 +173,7 @@ public class PhotoVersionCommands
try {
if (ResponseType.Ok == HigMessageDialog.RunHigConfirmation(parent_window, DialogFlags.DestroyWithParent,
MessageType.Warning, msg, desc, ok_caption)) {
- Photo new_photo = store.Create (photo.DefaultVersion.Uri, photo.RollId, photo.DefaultVersion.ImportMD5);
+ Photo new_photo = store.CreateFrom (photo, photo.RollId);
new_photo.CopyAttributesFrom (photo);
photo.DeleteVersion (photo.DefaultVersionId, false, true);
store.Commit (new Photo[] {new_photo, photo});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]