public override bool Step(out StepStatusInfo status_info) { Photo photo = null; Pixbuf thumbnail = null; bool is_duplicate = false; if (import_info == null) throw new ImportException ("Prepare() was not called"); if (this.count == import_info.Count) throw new ImportException ("Already finished"); // FIXME Need to get the EXIF info etc. ImportInfo info = (ImportInfo)import_info [this.count]; bool needs_commit = false; bool abort = false; try { string destination = info.OriginalPath; if (copy) destination = ChooseLocation (info.OriginalPath, directories); // Don't copy if we are already home if (info.OriginalPath == destination) { info.DestinationPath = destination; if (detect_duplicates) photo = store.CheckForDuplicate (UriUtils.PathToFileUri (destination)); if (photo == null) photo = store.Create (UriUtils.PathToFileUri (info.DestinationPath), roll.Id, out thumbnail); else is_duplicate = true; } else { System.IO.File.Copy (info.OriginalPath, destination); System.IO.File.SetAttributes (destination, System.IO.FileAttributes.Normal); info.DestinationPath = destination; if (detect_duplicates) photo = store.CheckForDuplicate (UriUtils.PathToFileUri (destination)); if (photo == null) { photo = store.Create (UriUtils.PathToFileUri (info.DestinationPath), UriUtils.PathToFileUri (info.OriginalPath), roll.Id, out thumbnail); try { File.SetAttributes (destination, File.GetAttributes (info.DestinationPath) & ~FileAttributes.ReadOnly); DateTime create = File.GetCreationTime (info.OriginalPath); File.SetCreationTime (info.DestinationPath, create); DateTime mod = File.GetLastWriteTime (info.OriginalPath); File.SetLastWriteTime (info.DestinationPath, mod); } catch (IOException) { // we don't want an exception here to be fatal. } } else { is_duplicate = true; System.IO.File.Delete (destination); } } if (!is_duplicate) { if (tags != null) { foreach (Tag t in tags) { photo.AddTag (t); } needs_commit = true; } needs_commit |= xmptags.Import (photo, info.DestinationPath, info.OriginalPath); if (needs_commit) store.Commit(photo); info.Photo = photo; } } catch (System.Exception e) { System.Console.WriteLine ("Error importing {0}{2}{1}", info.OriginalPath, e.ToString (), Environment.NewLine); if (thumbnail != null) thumbnail.Dispose (); thumbnail = null; photo = null; HigMessageDialog errordialog = new HigMessageDialog (parent, Gtk.DialogFlags.Modal | Gtk.DialogFlags.DestroyWithParent, Gtk.MessageType.Error, Gtk.ButtonsType.Cancel, Catalog.GetString ("Import error"), String.Format(Catalog.GetString ("Error importing {0}{2}{2}{1}"), info.OriginalPath, e.Message, Environment.NewLine )); errordialog.AddButton (Catalog.GetString ("Skip"), Gtk.ResponseType.Reject, false); ResponseType response = (ResponseType) errordialog.Run (); errordialog.Destroy (); if (response == ResponseType.Cancel) abort = true; } this.count ++; if (is_duplicate) this.duplicate_count ++; status_info = new StepStatusInfo (photo, thumbnail, this.count, is_duplicate); return (!abort && count != import_info.Count); }
// Import one picture. Returns false when done; then you have to call Finish(). public abstract bool Step(out StepStatusInfo import_info);
// Import one picture. Returns false when done; then you have to call Finish(). public abstract bool Step (out StepStatusInfo import_info);
public override bool Step(out StepStatusInfo status_info) { Photo photo = null; Pixbuf thumbnail = null; bool is_duplicate = false; if (import_info == null) { throw new ImportException("Prepare() was not called"); } if (this.count == import_info.Count) { throw new ImportException("Already finished"); } // FIXME Need to get the EXIF info etc. ImportInfo info = (ImportInfo)import_info [this.count]; bool needs_commit = false; bool abort = false; try { string destination = info.OriginalPath; if (copy) { destination = ChooseLocation(info.OriginalPath, directories); } // Don't copy if we are already home if (info.OriginalPath == destination) { info.DestinationPath = destination; if (detect_duplicates) { photo = store.CheckForDuplicate(UriUtils.PathToFileUri(destination)); } if (photo == null) { photo = store.Create(info.DestinationPath, roll.Id, out thumbnail); } else { is_duplicate = true; } } else { System.IO.File.Copy(info.OriginalPath, destination); info.DestinationPath = destination; if (detect_duplicates) { photo = store.CheckForDuplicate(UriUtils.PathToFileUri(destination)); } if (photo == null) { photo = store.Create(info.DestinationPath, info.OriginalPath, roll.Id, out thumbnail); try { File.SetAttributes(destination, File.GetAttributes(info.DestinationPath) & ~FileAttributes.ReadOnly); DateTime create = File.GetCreationTime(info.OriginalPath); File.SetCreationTime(info.DestinationPath, create); DateTime mod = File.GetLastWriteTime(info.OriginalPath); File.SetLastWriteTime(info.DestinationPath, mod); } catch (IOException) { // we don't want an exception here to be fatal. } } else { is_duplicate = true; System.IO.File.Delete(destination); } } if (!is_duplicate) { if (tags != null) { foreach (Tag t in tags) { photo.AddTag(t); } needs_commit = true; } needs_commit |= xmptags.Import(photo, info.DestinationPath, info.OriginalPath); if (needs_commit) { store.Commit(photo); } info.Photo = photo; } } catch (System.Exception e) { System.Console.WriteLine("Error importing {0}{2}{1}", info.OriginalPath, e.ToString(), Environment.NewLine); if (thumbnail != null) { thumbnail.Dispose(); } thumbnail = null; photo = null; HigMessageDialog errordialog = new HigMessageDialog(parent, Gtk.DialogFlags.Modal | Gtk.DialogFlags.DestroyWithParent, Gtk.MessageType.Error, Gtk.ButtonsType.Cancel, Catalog.GetString("Import error"), String.Format(Catalog.GetString("Error importing {0}{2}{2}{1}"), info.OriginalPath, e.Message, Environment.NewLine)); errordialog.AddButton(Catalog.GetString("Skip"), Gtk.ResponseType.Reject, false); ResponseType response = (ResponseType)errordialog.Run(); errordialog.Destroy(); if (response == ResponseType.Cancel) { abort = true; } } this.count++; if (is_duplicate) { this.duplicate_count++; } status_info = new StepStatusInfo(photo, thumbnail, this.count, is_duplicate); return(!abort && count != import_info.Count); }