Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
metadata_export.c
Go to the documentation of this file.
1/*
2 This file is part of darktable,
3 Copyright (C) 2019-2020 Pascal Obry.
4 Copyright (C) 2019 Philippe Weyland.
5 Copyright (C) 2021 Ralf Brown.
6 Copyright (C) 2022 Martin Bařinka.
7 Copyright (C) 2025 Aurélien PIERRE.
8
9 darktable is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 darktable is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with darktable. If not, see <http://www.gnu.org/licenses/>.
21*/
22
23#include "common/darktable.h"
24#include "control/conf.h"
26
32
33const char flags_keyword[] = "plugins/lighttable/export/metadata_flags";
34const char formula_keyword[] = "plugins/lighttable/export/metadata_formula";
35
37{
38 const char *metadata_flags = dt_conf_get_string_const(flags_keyword);
39 const int32_t flags = strtol(metadata_flags, NULL, 16);
40 return flags;
41}
42
44{
45 char *metadata_presets = NULL;
47 {
48 metadata_presets = dt_conf_get_string(flags_keyword);
49 int i = 0;
50 char *conf_keyword = g_strdup_printf("%s%d", formula_keyword, i);
51 while (dt_conf_key_exists(conf_keyword))
52 {
53 gchar *nameformula = dt_conf_get_string(conf_keyword);
54 dt_free(conf_keyword);
55 if(nameformula[0])
56 {
57 char *formula = g_strstr_len(nameformula, strlen(nameformula), ";");
58 if(formula)
59 {
60 formula[0] = '\0';
61 formula ++;
62 metadata_presets = dt_util_dstrcat(metadata_presets,"\1%s\1%s", nameformula, formula);
63 }
64 }
65 dt_free(nameformula);
66 i++;
67 conf_keyword = g_strdup_printf("%s%d", formula_keyword, i);
68 }
69 dt_free(conf_keyword);
70 }
71 else
72 {
73 metadata_presets = g_strdup_printf("%x", dt_lib_export_metadata_default_flags());
74 }
75 return metadata_presets;
76}
77
78void dt_lib_export_metadata_set_conf(const char *metadata_presets)
79{
80 GList *list = dt_util_str_to_glist("\1", metadata_presets);
81 int i = 0;
82 char *conf_keyword = NULL;
83 char *nameformula = NULL;
84 if (list)
85 {
86 char *flags_hexa = list->data;
88 list = g_list_remove(list, flags_hexa);
89 dt_free(flags_hexa);
90 if (list)
91 {
92 for (GList *tags = list; tags; tags = g_list_next(tags))
93 {
94 const char *tagname = (char *)tags->data;
95 tags = g_list_next(tags);
96 if (IS_NULL_PTR(tags)) break;
97 const char *formula = (char *)tags->data;
98 nameformula = g_strdup_printf("%s;%s", tagname, formula);
99 conf_keyword = g_strdup_printf("%s%d", formula_keyword, i);
100 dt_conf_set_string(conf_keyword, nameformula);
101 dt_free(nameformula);
102 dt_free(conf_keyword);
103 i++;
104 }
105 }
106 }
108 g_list_free_full(list, dt_free_gpointer);
109 list = NULL;
110
111 // clean up deprecated formulas
112 conf_keyword = g_strdup_printf("%s%d", formula_keyword, i);
113 while (dt_conf_key_exists(conf_keyword))
114 {
115 dt_conf_set_string(conf_keyword, "");
116 dt_free(conf_keyword);
117 i++;
118 conf_keyword = g_strdup_printf("%s%d", formula_keyword, i);
119 }
120 dt_free(conf_keyword);
121}
122
123// clang-format off
124// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
125// vim: shiftwidth=2 expandtab tabstop=2 cindent
126// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
127// clang-format on
int dt_conf_key_exists(const char *key)
gchar * dt_conf_get_string(const char *name)
void dt_conf_set_string(const char *name, const char *val)
const char * dt_conf_get_string_const(const char *name)
static void dt_free_gpointer(gpointer ptr)
Definition darktable.h:463
#define dt_free(ptr)
Definition darktable.h:456
#define IS_NULL_PTR(p)
C is way too permissive with !=, == and if(var) checks, which can mean too many things depending on w...
Definition darktable.h:281
uint32_t dt_lib_export_metadata_get_conf_flags(void)
char * dt_lib_export_metadata_get_conf(void)
const char formula_keyword[]
uint32_t dt_lib_export_metadata_default_flags(void)
void dt_lib_export_metadata_set_conf(const char *metadata_presets)
const char flags_keyword[]
@ DT_META_TAG
@ DT_META_EXIF
@ DT_META_METADATA
@ DT_META_DT_HISTORY
dt_mipmap_buffer_dsc_flags flags
Definition mipmap_cache.c:4
GList * dt_util_str_to_glist(const gchar *separator, const gchar *text)
Definition utility.c:830
gchar * dt_util_dstrcat(gchar *str, const gchar *format,...)
Definition utility.c:95