diff -Naur shotwell-0.7.2-orig/src/PhotoExporter.vala shotwell-0.7.2-new/src/PhotoExporter.vala --- shotwell-0.7.2-orig/src/PhotoExporter.vala 2010-09-10 19:55:55.000000000 -0300 +++ shotwell-0.7.2-new/src/PhotoExporter.vala 2010-10-10 17:53:07.000000000 -0300 @@ -1,9 +1,21 @@ -/* Copyright 2010 Yorba Foundation + /* Copyright 2010 Yorba Foundation * * This software is licensed under the GNU Lesser General Public License * (version 2.1 or later). See the COPYING file in this distribution. */ + +// This is used to enumerate the photos with same timestamp +class DateTimePhotoItem { + public int next; + public Photo? orig; + + public DateTimePhotoItem(int next, Photo? p) { + this.next = next; + this.orig = p; + } +} + public class PhotoExporter : Object { public enum Overwrite { YES, @@ -120,12 +132,61 @@ export_completed(); } + + + private bool process_queue() { int submitted = 0; + ///* + //These are used to check if a basename has already been used and to + //map a photo to a new basename on the expor folder + var datetimes = new Gee.HashMap (); + var name_map = new Gee.HashMap (); + + // First Pass -- Maps photos to names + // I1'm mapping from name -> YYYY:MM:DD HH:MM:SS(-seq)?.jpeg + // That's arbitrary, but is there any sense in exporting a selection + // and keeping the original names that make no sense in the exported + // directory? + + AppWindow.get_instance().set_busy_cursor(); + + int seq_digits = (int)(GLib.Math.log10(photos.size)) + 1; + foreach (Photo photo in photos) { - string basename = photo.get_export_basename(file_format); + string datetime = + photo.get_metadata().get_digitized_date_time().get_exif_label(); + string destname; + + if (datetime in datetimes) { + DateTimePhotoItem d = datetimes[datetime]; + + if (d.next == 2) { + // First duplicate + // Needs to rename the original file, to keep consistency + string destname_orig = "%s-%0*d".printf(datetime,seq_digits,1); + name_map[d.orig] = destname_orig; + } + + destname = "%s-%0*d".printf(datetime,seq_digits,d.next); + datetimes[datetime].next = d.next++; + + } else { + destname = "%s".printf(datetime); + // store the next sequence number: this is 1, next is 2 + DateTimePhotoItem d = new DateTimePhotoItem(2,photo); + datetimes[datetime] = d; + } + + name_map[photo] = destname; + + } + + //*/ + foreach (Photo photo in photos) { + string basename = file_format.get_default_basename(name_map[photo]); File dest = dir.get_child(basename); - + if (!replace_all && dest.query_exists(null)) { switch (overwrite_callback(this, dest)) { case Overwrite.YES: @@ -220,6 +281,8 @@ } private bool on_export_failed(PhotoExporter exporter, File file, int remaining, Error err) { + stdout.printf("Exception on export: %d, %s\n",err.code, + err.message); return export_error_dialog(file, remaining > 0) != Gtk.ResponseType.CANCEL; } }