public void Merge() { Log.DebugFormat("Merging {0} and {1}", raw.VersionUri(Photo.OriginalVersionId), jpeg.VersionUri(Photo.OriginalVersionId)); foreach (uint version_id in jpeg.VersionIds) { string name = jpeg.GetVersion(version_id).Name; try { raw.DefaultVersionId = raw.CreateReparentedVersion(jpeg.GetVersion(version_id) as PhotoVersion, version_id == Photo.OriginalVersionId); if (version_id == Photo.OriginalVersionId) { raw.RenameVersion(raw.DefaultVersionId, "Jpeg"); } else { raw.RenameVersion(raw.DefaultVersionId, name); } } catch (Exception e) { Log.Exception(e); } } raw.AddTag(jpeg.Tags); uint [] version_ids = jpeg.VersionIds; Array.Reverse(version_ids); foreach (uint version_id in version_ids) { try { jpeg.DeleteVersion(version_id, true, true); } catch (Exception e) { Log.Exception(e); } } raw.Changes.DataChanged = true; App.Instance.Database.Photos.Commit(raw); App.Instance.Database.Photos.Remove(jpeg); }
public bool Execute(PhotoStore store, Photo [] photos, Photo new_parent, Gtk.Window parent_window) { foreach (Photo photo in photos) { new_parent.AddTag(photo.Tags); foreach (uint version_id in photo.VersionIds) { try { new_parent.DefaultVersionId = new_parent.CreateReparentedVersion(photo.GetVersion(version_id) as PhotoVersion); store.Commit(new_parent); } catch (Exception e) { Console.WriteLine(e); } } uint [] version_ids = photo.VersionIds; Array.Reverse(version_ids); foreach (uint version_id in version_ids) { try { photo.DeleteVersion(version_id, true, true); } catch (Exception e) { Console.WriteLine(e); } } store.Commit(photo); MainWindow.Toplevel.Database.Photos.Remove(photo); } return(true); }
public void Merge() { photos.Sort(new CompareNameWithRaw()); Console.WriteLine("Maybe merging these photos:"); foreach (Photo photo in this.photos) { Console.WriteLine(photo.Name); } Photo raw = (Photo)this.photos[0]; foreach (Photo jpeg in this.photos.GetRange(1, this.photos.Count - 1)) { Console.WriteLine("...merging {0} into {1}...", jpeg.Name, raw.Name); Console.WriteLine("Merging {0} and {1}", raw.VersionUri(Photo.OriginalVersionId), jpeg.VersionUri(Photo.OriginalVersionId)); foreach (uint version_id in jpeg.VersionIds) { string name = jpeg.GetVersion(version_id).Name; try { raw.DefaultVersionId = raw.CreateReparentedVersion(jpeg.GetVersion(version_id) as PhotoVersion, version_id == Photo.OriginalVersionId); if (version_id == Photo.OriginalVersionId) { // Just the filename part that follows the last "-", e.g. "xy100.jpg". raw.RenameVersion(raw.DefaultVersionId, jpeg.Name.Substring(jpeg.Name.LastIndexOf('-') + 1)); } else { raw.RenameVersion(raw.DefaultVersionId, name); } } catch (Exception e) { Console.WriteLine(e); } } raw.AddTag(jpeg.Tags); uint [] version_ids = jpeg.VersionIds; Array.Reverse(version_ids); foreach (uint version_id in version_ids) { try { jpeg.DeleteVersion(version_id, true, true); } catch (Exception e) { Console.WriteLine(e); } } raw.Changes.DataChanged = true; App.Instance.Database.Photos.Commit(raw); App.Instance.Database.Photos.Remove(jpeg); } }
public bool Execute(PhotoStore store, Photo[] photos, Photo new_parent, Gtk.Window parent_window) { string ok_caption = Strings.ReparentButton; string msg = Catalog.GetPluralString( Strings.ReallyReparentXAsVersionOfYQuestion(new_parent.Name.Replace("_", "__"), photos[0].Name.Replace("_", "__")), Strings.ReallyReparentXPhotosAsVersionOfYQuestion(new_parent.Name.Replace("_", "__"), photos[0].Name.Replace("_", "__")), photos.Length); string desc = Strings.ThisMakesThePhotosAppearAsASingleOneInTheLibraryTheVersionsCanBeDetachedUsingThePhotoMenu; try { if (ResponseType.Ok == HigMessageDialog.RunHigConfirmation(parent_window, DialogFlags.DestroyWithParent, MessageType.Warning, msg, desc, ok_caption)) { uint highest_rating = new_parent.Rating; string new_description = new_parent.Description; foreach (var photo in photos) { highest_rating = Math.Max(photo.Rating, highest_rating); if (string.IsNullOrEmpty(new_description)) { new_description = photo.Description; } new_parent.AddTag(photo.Tags); foreach (uint version_id in photo.VersionIds) { new_parent.DefaultVersionId = new_parent.CreateReparentedVersion(photo.GetVersion(version_id) as PhotoVersion); store.Commit(new_parent); } uint[] version_ids = photo.VersionIds; Array.Reverse(version_ids); foreach (uint version_id in version_ids) { photo.DeleteVersion(version_id, true, true); } store.Remove(photo); } new_parent.Rating = highest_rating; new_parent.Description = new_description; store.Commit(new_parent); return(true); } } catch (Exception e) { HandleException("Could not reparent photos", e, parent_window); } return(false); }
public bool Execute(PhotoStore store, Photo [] photos, Photo new_parent, Gtk.Window parent_window) { string ok_caption = Catalog.GetString("Re_parent"); string msg = String.Format(Catalog.GetPluralString("Really reparent \"{0}\" as version of \"{1}\"?", "Really reparent {2} photos as versions of \"{1}\"?", photos.Length), new_parent.Name.Replace("_", "__"), photos[0].Name.Replace("_", "__"), photos.Length); string desc = Catalog.GetString("This makes the photos appear as a single one in the library. The versions can be detached using the Photo menu."); try { if (ResponseType.Ok == HigMessageDialog.RunHigConfirmation(parent_window, DialogFlags.DestroyWithParent, MessageType.Warning, msg, desc, ok_caption)) { uint highest_rating = new_parent.Rating; string new_description = new_parent.Description; foreach (Photo photo in photos) { highest_rating = Math.Max(photo.Rating, highest_rating); if (string.IsNullOrEmpty(new_description)) { new_description = photo.Description; } new_parent.AddTag(photo.Tags); foreach (uint version_id in photo.VersionIds) { new_parent.DefaultVersionId = new_parent.CreateReparentedVersion(photo.GetVersion(version_id) as PhotoVersion); store.Commit(new_parent); } uint [] version_ids = photo.VersionIds; Array.Reverse(version_ids); foreach (uint version_id in version_ids) { photo.DeleteVersion(version_id, true, true); } store.Remove(photo); } new_parent.Rating = highest_rating; new_parent.Description = new_description; store.Commit(new_parent); return(true); } } catch (Exception e) { HandleException("Could not reparent photos", e, parent_window); } return(false); }