From a5b5f12832ebc3530f37880d48c224981bbd649e Mon Sep 17 00:00:00 2001 From: Mario Zimmermann Date: Tue, 13 Jan 2026 19:23:04 +0100 Subject: [PATCH] restrict metadata tag list in metadata editor The metadata editor should only allow to edit tags which are supposed to be user-editable. --- src/gui/metadata_tags.c | 31 +++++++++++++++++++++++++++++-- src/gui/metadata_tags.h | 4 ++-- src/libs/export_metadata.c | 4 ++-- src/libs/metadata.c | 4 ++-- 4 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/gui/metadata_tags.c b/src/gui/metadata_tags.c index 86d711ea93c9..9b280ee34d5e 100644 --- a/src/gui/metadata_tags.c +++ b/src/gui/metadata_tags.c @@ -1,6 +1,6 @@ /* This file is part of darktable, - Copyright (C) 2025 darktable developers. + Copyright (C) 2026 darktable developers. darktable is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -85,7 +85,10 @@ static void _tree_selection_change(GtkTreeSelection *selection, gpointer user_da gtk_widget_set_sensitive(add_button, nb > 0); } -GtkWidget *dt_metadata_tags_dialog(GtkWidget *parent, gpointer metadata_activated_callback, gpointer user_data) +GtkWidget *dt_metadata_tags_dialog(GtkWidget *parent, + const gboolean user_editable_only, + gpointer metadata_activated_callback, + gpointer user_data) { GtkWidget *dialog = gtk_dialog_new_with_buttons(_("select tag"), GTK_WINDOW(parent), GTK_DIALOG_DESTROY_WITH_PARENT, @@ -124,9 +127,33 @@ GtkWidget *dt_metadata_tags_dialog(GtkWidget *parent, gpointer metadata_activate if(!taglist) taglist = (GList *) dt_exif_get_exiv2_taglist(); + // list of user-editable tagnames for the metadata editor + const char *allowed_tag_names[] = + { + "Xmp.dc.", + "Xmp.acdsee.", + "Xmp.iptc.", + "Iptc." + }; + for(GList *tag = taglist; tag; tag = g_list_next(tag)) { const char *tagname = tag->data; + + if(user_editable_only) + { + // for the metadata editor we only want to expose user-editable fields + gboolean allowed = FALSE; + for(int i = 0; (i < sizeof(allowed_tag_names) / sizeof(allowed_tag_names[0])) && !allowed; i++) + { + if(g_strstr_len(tagname, -1, allowed_tag_names[i]) == tagname) + allowed = TRUE; + } + + if(!allowed) + continue; + } + char *type = g_strstr_len(tagname, -1, ","); if(type) { diff --git a/src/gui/metadata_tags.h b/src/gui/metadata_tags.h index e0f22682c7d3..5cce9e1d21d8 100644 --- a/src/gui/metadata_tags.h +++ b/src/gui/metadata_tags.h @@ -1,6 +1,6 @@ /* This file is part of darktable, - Copyright (C) 2025 darktable developers. + Copyright (C) 2026 darktable developers. darktable is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,7 +17,7 @@ */ gchar *dt_metadata_tags_get_selected(); -GtkWidget *dt_metadata_tags_dialog(GtkWidget *parent, gpointer metadata_activated_callback, gpointer user_data); +GtkWidget *dt_metadata_tags_dialog(GtkWidget *parent, const gboolean user_editable_only, gpointer metadata_activated_callback, gpointer user_data); // clang-format off // modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py diff --git a/src/libs/export_metadata.c b/src/libs/export_metadata.c index be126b1129e4..a8d0e80ba329 100644 --- a/src/libs/export_metadata.c +++ b/src/libs/export_metadata.c @@ -1,6 +1,6 @@ /* This file is part of darktable, - Copyright (C) 2019-2025 darktable developers. + Copyright (C) 2019-2026 darktable developers. darktable is free software: you can redistribute it and/or modify @@ -98,7 +98,7 @@ static void _metadata_activated(GtkTreeView *tree_view, // dialog to add metadata tag into the formula list static void _add_tag_button_clicked(GtkButton *button, dt_lib_export_metadata_t *d) { - GtkWidget *dialog = dt_metadata_tags_dialog(d->dialog, _metadata_activated, d); + GtkWidget *dialog = dt_metadata_tags_dialog(d->dialog, FALSE, _metadata_activated, d); #ifdef GDK_WINDOWING_QUARTZ dt_osx_disallow_fullscreen(dialog); diff --git a/src/libs/metadata.c b/src/libs/metadata.c index 066e5bb140bd..4e322988ae9a 100644 --- a/src/libs/metadata.c +++ b/src/libs/metadata.c @@ -1,6 +1,6 @@ /* This file is part of darktable, - Copyright (C) 2010-2025 darktable developers. + Copyright (C) 2010-2026 darktable developers. darktable is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -743,7 +743,7 @@ static void _metadata_activated(GtkTreeView *tree_view, // dialog to add metadata tag into the formula list static void _add_tag_button_clicked(GtkButton *button, dt_lib_metadata_t *d) { - GtkWidget *dialog = dt_metadata_tags_dialog(d->dialog, _metadata_activated, d); + GtkWidget *dialog = dt_metadata_tags_dialog(d->dialog, TRUE, _metadata_activated, d); #ifdef GDK_WINDOWING_QUARTZ dt_osx_disallow_fullscreen(dialog);