From 9cbb4a816f6bf21c1ae6f5a2627f67cfa17b6d4e Mon Sep 17 00:00:00 2001 From: Mario Zimmermann Date: Fri, 23 Aug 2024 09:45:17 +0200 Subject: [PATCH] preserve original import filename in xmp data --- src/common/exif.cc | 3 ++- src/common/metadata.c | 3 ++- src/common/metadata.h | 1 + src/control/jobs/control_jobs.c | 7 +++++++ src/libs/metadata.c | 13 ++++++++++++- src/libs/metadata_view.c | 2 +- 6 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/common/exif.cc b/src/common/exif.cc index 83dceb93643a..895a49a0a2df 100644 --- a/src/common/exif.cc +++ b/src/common/exif.cc @@ -405,7 +405,8 @@ const char *dt_xmp_keys[] "Xmp.acdsee.notes", "Xmp.dc.creator", "Xmp.dc.publisher", "Xmp.dc.title", "Xmp.dc.description", "Xmp.dc.rights", - "Xmp.dc.format", "Xmp.xmpMM.DerivedFrom" }; + "Xmp.dc.format", "Xmp.xmpMM.DerivedFrom", + "Xmp.xmpMM.PreservedFileName" }; // The number of XmpBag XmpSeq keys that dt uses static const guint dt_xmp_keys_n = G_N_ELEMENTS(dt_xmp_keys); diff --git a/src/common/metadata.c b/src/common/metadata.c index e96822da57f7..8a90f87ab908 100644 --- a/src/common/metadata.c +++ b/src/common/metadata.c @@ -50,7 +50,8 @@ static const struct {"Xmp.dc.rights", N_("rights"), DT_METADATA_TYPE_USER, 4}, {"Xmp.acdsee.notes", N_("notes"), DT_METADATA_TYPE_USER, 5}, {"Xmp.darktable.version_name", N_("version name"), DT_METADATA_TYPE_OPTIONAL, 6}, - {"Xmp.darktable.image_id", N_("image id"), DT_METADATA_TYPE_INTERNAL, 7} + {"Xmp.darktable.image_id", N_("image id"), DT_METADATA_TYPE_INTERNAL, 7}, + {"Xmp.xmpMM.PreservedFileName", N_("preserved filename"), DT_METADATA_TYPE_OPTIONAL, 8} // clang-format on }; diff --git a/src/common/metadata.h b/src/common/metadata.h index 8a457ac5e59e..c8fdbfb04f7a 100644 --- a/src/common/metadata.h +++ b/src/common/metadata.h @@ -36,6 +36,7 @@ typedef enum dt_metadata_t DT_METADATA_XMP_ACDSEE_NOTES, DT_METADATA_XMP_VERSION_NAME, DT_METADATA_XMP_IMAGE_ID, + DT_METADATA_XMP_PRESERVED_FILENAME, DT_METADATA_NUMBER } dt_metadata_t; diff --git a/src/control/jobs/control_jobs.c b/src/control/jobs/control_jobs.c index 596cdc6b1b1c..a363e595b935 100644 --- a/src/control/jobs/control_jobs.c +++ b/src/control/jobs/control_jobs.c @@ -2373,6 +2373,13 @@ static int _control_import_image_copy(const char *filename, dt_datetime_unix_to_exif(dt_txt, sizeof(dt_txt), &datetime); char *id = g_strconcat(fn, "-", dt_txt, NULL); dt_metadata_set(imgid, "Xmp.darktable.image_id", id, FALSE); + gchar *output_basename = g_path_get_basename(output); + if(g_strcmp0(output_basename, fn)) + { + // file renamed during import, preserve the original filename + dt_metadata_set(imgid, "Xmp.xmpMM.PreservedFileName", fn, FALSE); + } + g_free(output_basename); g_free(id); g_object_unref(info); g_object_unref(gfile); diff --git a/src/libs/metadata.c b/src/libs/metadata.c index afbb7307d888..52a3025d4aae 100644 --- a/src/libs/metadata.c +++ b/src/libs/metadata.c @@ -33,7 +33,7 @@ #endif #include -DT_MODULE(3) +DT_MODULE(4) typedef enum dt_metadata_pref_cols_t { @@ -870,6 +870,17 @@ void *legacy_params(dt_lib_module_t *self, *new_version = 3; return new_params; } + else if(old_version == 3) + { + const size_t new_params_size = old_params_size + 1; + char *new_params = calloc(sizeof(char), new_params_size); + + memcpy(new_params, old_params, old_params_size); + + *new_size = new_params_size; + *new_version = 4; + return new_params; + } return NULL; } diff --git a/src/libs/metadata_view.c b/src/libs/metadata_view.c index 4b7d124ebc0d..05cbbfaa16c1 100644 --- a/src/libs/metadata_view.c +++ b/src/libs/metadata_view.c @@ -167,7 +167,7 @@ static const char *_labels[] = { /* xmp */ //FIXME: reserve DT_METADATA_NUMBER places - "","","","","","","","", + "","","","","","","","","", /* geotagging */ N_("latitude"),