diff options
Diffstat (limited to 'src/Commands.vala')
-rw-r--r-- | src/Commands.vala | 89 |
1 files changed, 63 insertions, 26 deletions
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<Dateable, Event?> prev_events; // used when photos are batch changed instead of shifted uniformly - private time_t? new_time = null; - private Gee.HashMap<Dateable, time_t?> old_times; + private DateTime? new_time = null; + private Gee.HashMap<Dateable, DateTime?> old_times; private Gee.ArrayList<Dateable> error_list; public AdjustDateTimePhotosCommand(Gee.Iterable<DataView> 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<Dateable, time_t?>(); + old_times = new Gee.HashMap<Dateable, DateTime?>(); + } + + 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<MediaSource, string> 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<FaceID?, FaceLocation>? 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<PhotoID?, string> photo_geometry_map = new Gee.HashMap<PhotoID?, string> ((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<SourceProxy> to_add = new Gee.ArrayList<SourceProxy>(); private Gee.ArrayList<SourceProxy> to_remove = new Gee.ArrayList<SourceProxy>(); - private Gee.Map<SourceProxy, string> to_update = new Gee.HashMap<SourceProxy, string>(); - private Gee.Map<SourceProxy, string> geometries = new Gee.HashMap<SourceProxy, string>(); + private Gee.Map<SourceProxy, FaceLocationData?> to_update = new Gee.HashMap<SourceProxy, FaceLocationData?>(); + private Gee.Map<SourceProxy, FaceLocationData?> geometries = new Gee.HashMap<SourceProxy, FaceLocationData?>(); - public ModifyFacesCommand(MediaSource media, Gee.Map<Face, string> new_face_list) { + public ModifyFacesCommand(MediaSource media, Gee.Map<Face, FaceLocationData?> 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<Face, string> entry in new_face_list.entries) { + foreach (Gee.Map.Entry<Face, FaceLocationData?> 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<SourceProxy, string> entry in to_update.entries) { + foreach (Gee.Map.Entry<SourceProxy, FaceLocationData?> 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); } |