From d443a3c2509889533ca812c163056bace396b586 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Wed, 14 Jun 2023 20:35:58 +0200 Subject: New upstream version 0.32.1 --- src/Commands.vala | 89 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 63 insertions(+), 26 deletions(-) (limited to 'src/Commands.vala') diff --git a/src/Commands.vala b/src/Commands.vala index 589ae38..76aecb4 100644 --- a/src/Commands.vala +++ b/src/Commands.vala @@ -1316,8 +1316,17 @@ public class AdjustDateTimePhotoCommand : SingleDataSourceCommand { this.modify_original = modify_original; } + private DateTime get_base_time() { + var exposure_time = dateable.get_exposure_time(); + if (exposure_time == null) { + exposure_time = new DateTime.from_unix_utc(0); + } + + return exposure_time; + } + public override void execute() { - set_time(dateable, dateable.get_exposure_time() + (time_t) time_shift); + set_time(dateable, get_base_time().add_seconds(time_shift)); prev_event = dateable.get_event(); @@ -1333,12 +1342,12 @@ public class AdjustDateTimePhotoCommand : SingleDataSourceCommand { } public override void undo() { - set_time(dateable, dateable.get_exposure_time() - (time_t) time_shift); + set_time(dateable, get_base_time().add_seconds(-1 * time_shift)); dateable.set_event(prev_event); } - private void set_time(Dateable dateable, time_t exposure_time) { + private void set_time(Dateable dateable, DateTime exposure_time) { if (modify_original && dateable is Photo) { try { ((Photo)dateable).set_exposure_time_persistent(exposure_time); @@ -1358,8 +1367,8 @@ public class AdjustDateTimePhotosCommand : MultipleDataSourceCommand { private Gee.Map prev_events; // used when photos are batch changed instead of shifted uniformly - private time_t? new_time = null; - private Gee.HashMap old_times; + private DateTime? new_time = null; + private Gee.HashMap old_times; private Gee.ArrayList error_list; public AdjustDateTimePhotosCommand(Gee.Iterable iter, int64 time_shift, @@ -1377,16 +1386,24 @@ public class AdjustDateTimePhotosCommand : MultipleDataSourceCommand { // this should be replaced by a first function when we migrate to Gee's List foreach (DataView view in iter) { - prev_events.set(view.get_source() as Dateable, (view.get_source() as MediaSource).get_event()); + prev_events.set(view.get_source() as Dateable, ((MediaSource) view.get_source()).get_event()); if (new_time == null) { - new_time = ((Dateable) view.get_source()).get_exposure_time() + - (time_t) time_shift; + new_time = get_base_time((Dateable)view.get_source()).add_seconds(time_shift); break; } } - old_times = new Gee.HashMap(); + old_times = new Gee.HashMap(); + } + + private DateTime get_base_time(Dateable dateable) { + var exposure_time = dateable.get_exposure_time(); + if (exposure_time == null) { + exposure_time = new DateTime.from_unix_utc(0); + } + + return exposure_time; } public override void execute() { @@ -1425,7 +1442,7 @@ public class AdjustDateTimePhotosCommand : MultipleDataSourceCommand { } } - private void set_time(Dateable dateable, time_t exposure_time) { + private void set_time(Dateable dateable, DateTime exposure_time) { // set_exposure_time_persistent wouldn't work on videos, // since we can't actually write them from inside shotwell, // so check whether we're working on a Photo or a Video @@ -1445,8 +1462,8 @@ public class AdjustDateTimePhotosCommand : MultipleDataSourceCommand { public override void execute_on_source(DataSource source) { Dateable dateable = ((Dateable) source); - if (keep_relativity && dateable.get_exposure_time() != 0) { - set_time(dateable, dateable.get_exposure_time() + (time_t) time_shift); + if (keep_relativity && dateable.get_exposure_time() != null) { + set_time(dateable, dateable.get_exposure_time().add_seconds(time_shift)); } else { old_times.set(dateable, dateable.get_exposure_time()); set_time(dateable, new_time); @@ -1470,10 +1487,10 @@ public class AdjustDateTimePhotosCommand : MultipleDataSourceCommand { set_time(photo, old_times.get(photo)); old_times.unset(photo); } else { - set_time(photo, photo.get_exposure_time() - (time_t) time_shift); + set_time(photo, photo.get_exposure_time().add_seconds(-1 * time_shift)); } - (source as MediaSource).set_event(prev_events.get(source as Dateable)); + ((MediaSource) source).set_event(prev_events.get(source as Dateable)); } } @@ -2165,8 +2182,6 @@ public class ModifyTagsCommand : SingleDataSourceCommand { } foreach (string path in new_paths) { - assert(Tag.global.exists(path)); - SourceProxy proxy = Tag.for_path(path).get_proxy(); to_add.add(proxy); proxy.broken.connect(on_proxy_broken); @@ -2541,7 +2556,8 @@ public class RemoveFacesFromPhotosCommand : SimpleProxyableCommand { face.attach_many(map_source_geometry.keys); foreach (Gee.Map.Entry entry in map_source_geometry.entries) - FaceLocation.create(face.get_face_id(), ((Photo) entry.key).get_photo_id(), entry.value); + FaceLocation.create(face.get_face_id(), ((Photo) entry.key).get_photo_id(), + { entry.value, null }); } private void on_source_destroyed(DataSource source) { @@ -2572,6 +2588,26 @@ public class RenameFaceCommand : SimpleProxyableCommand { } } +public class SetFaceRefCommand : SimpleProxyableCommand { + private FaceLocation face_loc; + + public SetFaceRefCommand(Face face, MediaSource source) { + base (face, Resources.set_face_from_photo_label(face.get_name()), face.get_name()); + Gee.Map? face_loc_map = FaceLocation.get_locations_by_photo((Photo)source); + face_loc = face_loc_map.get(face.get_face_id()); + } + + protected override void execute_on_source(DataSource source) { + if (!((Face) source).set_reference(face_loc)) + AppWindow.error_message(Resources.set_face_from_photo_error()); + } + + protected override void undo_on_source(DataSource source) { + //if (!((Face) source).rename(old_name)) + // AppWindow.error_message(Resources.rename_face_exists_message(old_name)); + } +} + public class DeleteFaceCommand : SimpleProxyableCommand { private Gee.Map photo_geometry_map = new Gee.HashMap ((Gee.HashDataFunc)FaceLocation.photo_id_hash, (Gee.EqualDataFunc)FaceLocation.photo_ids_equal); @@ -2607,7 +2643,8 @@ public class DeleteFaceCommand : SimpleProxyableCommand { Face face = (Face) source; face.attach(photo); - FaceLocation.create(face.get_face_id(), entry.key, entry.value); + FaceLocation.create(face.get_face_id(), entry.key, + { entry.value, null }); } } } @@ -2617,10 +2654,10 @@ public class ModifyFacesCommand : SingleDataSourceCommand { private MediaSource media; private Gee.ArrayList to_add = new Gee.ArrayList(); private Gee.ArrayList to_remove = new Gee.ArrayList(); - private Gee.Map to_update = new Gee.HashMap(); - private Gee.Map geometries = new Gee.HashMap(); + private Gee.Map to_update = new Gee.HashMap(); + private Gee.Map geometries = new Gee.HashMap(); - public ModifyFacesCommand(MediaSource media, Gee.Map new_face_list) { + public ModifyFacesCommand(MediaSource media, Gee.Map new_face_list) { base (media, Resources.MODIFY_FACES_LABEL, ""); this.media = media; @@ -2639,13 +2676,13 @@ public class ModifyFacesCommand : SingleDataSourceCommand { FaceLocation.get_face_location(face.get_face_id(), ((Photo) media).get_photo_id()); assert(face_location != null); - geometries.set(proxy, face_location.get_serialized_geometry()); + geometries.set(proxy, face_location.get_face_data()); } } } // Add any face that's in the new list but not the original - foreach (Gee.Map.Entry entry in new_face_list.entries) { + foreach (Gee.Map.Entry entry in new_face_list.entries) { if (original_faces == null || !original_faces.contains(entry.key)) { SourceProxy proxy = entry.key.get_proxy(); @@ -2661,13 +2698,13 @@ public class ModifyFacesCommand : SingleDataSourceCommand { assert(face_location != null); string old_geometry = face_location.get_serialized_geometry(); - if (old_geometry != entry.value) { + if (old_geometry != entry.value.geometry) { SourceProxy proxy = entry.key.get_proxy(); to_update.set(proxy, entry.value); proxy.broken.connect(on_proxy_broken); - geometries.set(proxy, old_geometry); + geometries.set(proxy, face_location.get_face_data()); } } } @@ -2694,7 +2731,7 @@ public class ModifyFacesCommand : SingleDataSourceCommand { foreach (SourceProxy proxy in to_remove) ((Face) proxy.get_source()).detach(media); - foreach (Gee.Map.Entry entry in to_update.entries) { + foreach (Gee.Map.Entry entry in to_update.entries) { Face face = (Face) entry.key.get_source(); FaceLocation.create(face.get_face_id(), ((Photo) media).get_photo_id(), entry.value); } -- cgit v1.2.3