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 "system/macros.h"
24#include "system/mem_alloc.h"
25#include "common/utility.h"
26#include "common/conf.h"
28
34
35const char flags_keyword[] = "plugins/lighttable/export/metadata_flags";
36const char formula_keyword[] = "plugins/lighttable/export/metadata_formula";
37
39{
40 const char *metadata_flags = dt_conf_get_string_const(flags_keyword);
41 const int32_t flags = strtol(metadata_flags, NULL, 16);
42 return flags;
43}
44
46{
47 char *metadata_presets = NULL;
49 {
50 metadata_presets = dt_conf_get_string(flags_keyword);
51 int i = 0;
52 char *conf_keyword = g_strdup_printf("%s%d", formula_keyword, i);
53 while (dt_conf_key_exists(conf_keyword))
54 {
55 gchar *nameformula = dt_conf_get_string(conf_keyword);
56 dt_free(conf_keyword);
57 if(nameformula[0])
58 {
59 char *formula = g_strstr_len(nameformula, strlen(nameformula), ";");
60 if(formula)
61 {
62 formula[0] = '\0';
63 formula ++;
64 metadata_presets = dt_util_dstrcat(metadata_presets,"\1%s\1%s", nameformula, formula);
65 }
66 }
67 dt_free(nameformula);
68 i++;
69 conf_keyword = g_strdup_printf("%s%d", formula_keyword, i);
70 }
71 dt_free(conf_keyword);
72 }
73 else
74 {
75 metadata_presets = g_strdup_printf("%x", dt_lib_export_metadata_default_flags());
76 }
77 return metadata_presets;
78}
79
80void dt_lib_export_metadata_set_conf(const char *metadata_presets)
81{
82 GList *list = dt_util_str_to_glist("\1", metadata_presets);
83 int i = 0;
84 char *conf_keyword = NULL;
85 char *nameformula = NULL;
86 if (list)
87 {
88 char *flags_hexa = list->data;
90 list = g_list_remove(list, flags_hexa);
91 dt_free(flags_hexa);
92 if (list)
93 {
94 for (GList *tags = list; tags; tags = g_list_next(tags))
95 {
96 const char *tagname = (char *)tags->data;
97 tags = g_list_next(tags);
98 if (IS_NULL_PTR(tags)) break;
99 const char *formula = (char *)tags->data;
100 nameformula = g_strdup_printf("%s;%s", tagname, formula);
101 conf_keyword = g_strdup_printf("%s%d", formula_keyword, i);
102 dt_conf_set_string(conf_keyword, nameformula);
103 dt_free(nameformula);
104 dt_free(conf_keyword);
105 i++;
106 }
107 }
108 }
110 g_list_free_full(list, dt_free_gpointer);
111 list = NULL;
112
113 // clean up deprecated formulas
114 conf_keyword = g_strdup_printf("%s%d", formula_keyword, i);
115 while (dt_conf_key_exists(conf_keyword))
116 {
117 dt_conf_set_string(conf_keyword, "");
118 dt_free(conf_keyword);
119 i++;
120 conf_keyword = g_strdup_printf("%s%d", formula_keyword, i);
121 }
122 dt_free(conf_keyword);
123}
124
125// clang-format off
126// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
127// vim: shiftwidth=2 expandtab tabstop=2 cindent
128// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
129// clang-format on
int dt_conf_key_exists(const char *key)
Does key have a value?
gchar * dt_conf_get_string(const char *name)
Read the stored string for name as a private copy.
void dt_conf_set_string(const char *name, const char *val)
const char * dt_conf_get_string_const(const char *name)
Borrow the stored string for name without copying it.
#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 macros.h:96
static void dt_free_gpointer(gpointer ptr)
g_free() one pointer, with the signature GDestroyNotify wants.
Definition mem_alloc.h:184
#define dt_free(ptr)
g_free() ptr and set it to NULL, skipping both if it is already NULL.
Definition mem_alloc.h:171
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:833
gchar * dt_util_dstrcat(gchar *str, const gchar *format,...)
Definition utility.c:99