1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
|
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* metadata-editor.c
* Copyright (C) 2016, 2017 Ben Touchette
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <stdlib.h>
#include <ctype.h>
#include <gegl.h>
#include <gtk/gtk.h>
#include <gexiv2/gexiv2.h>
#include <glib.h>
#include <glib/gstdio.h>
#include <libgimp/gimp.h>
#include <libgimp/gimpui.h>
#include "libgimp/stdplugins-intl.h"
#include "metadata-xml.h"
#include "metadata-misc.h"
#include "metadata-tags.h"
#include "metadata-impexp.h"
#include "metadata-editor.h"
extern gboolean gimpmetadata;
extern gboolean xmptag;
extern gboolean iptctag;
extern gboolean tagvalue;
extern gboolean tagname;
extern gboolean force_write;
extern gchar *str_tag_value;
extern gchar *str_tag_name;
const GMarkupParser xml_markup_parser =
{
xml_parser_start_element,
xml_parser_end_element,
xml_parser_data,
NULL, /* passthrough */
NULL /* error */
};
/* ============================================================================
* ==[ METADATA IMPORT TEMPLATE ]==============================================
* ============================================================================
*/
void
import_file_metadata(metadata_editor *args)
{
GimpXmlParser *xml_parser;
GError *error = NULL;
FILE *file;
gchar *xmldata;
gimpmetadata = FALSE;
xmptag = FALSE;
iptctag = FALSE;
tagvalue = FALSE;
tagname = FALSE;
file = g_fopen (args->filename, "r");
if (file != NULL)
{
/* get xml data from file */
g_file_get_contents (args->filename, &xmldata, NULL, &error);
/* parse xml data fetched from file */
xml_parser = xml_parser_new (&xml_markup_parser, args);
xml_parser_parse_file (xml_parser, args->filename, &error);
xml_parser_free (xml_parser);
fclose (file);
}
}
/* ============================================================================
* ==[ METADATA EXPORT TEMPLATE ]==============================================
* ============================================================================
*/
void
export_file_metadata (metadata_editor *args)
{
GError *error = NULL;
FILE *file;
gchar *value;
gchar *value_utf;
gchar *xmldata;
gint i, size;
if (force_write == TRUE)
{
/* Save fields in case of updates */
metadata_editor_write_callback (args->dialog, args->builder, args->image_id);
/* Fetch a fresh copy of the metadata */
args->metadata = GEXIV2_METADATA (gimp_image_get_metadata (args->image_id));
}
xmldata = g_strconcat ("<?xml version=“1.0” encoding=“utf-8”?>\n",
"<gimp-metadata>\n", NULL);
/* HANDLE IPTC */
for (i = 0; i < n_equivalent_metadata_tags; i++)
{
int index = equivalent_metadata_tags[i].other_tag_index;
xmldata = g_strconcat (xmldata, "\t<iptc-tag>\n", NULL);
xmldata = g_strconcat (xmldata, "\t\t<tag-name>", NULL);
xmldata = g_strconcat (xmldata, equivalent_metadata_tags[i].tag, NULL);
xmldata = g_strconcat (xmldata, "</tag-name>\n", NULL);
xmldata = g_strconcat (xmldata, "\t\t<tag-mode>", NULL);
xmldata = g_strconcat (xmldata, equivalent_metadata_tags[i].mode, NULL);
xmldata = g_strconcat (xmldata, "</tag-mode>\n", NULL);
xmldata = g_strconcat (xmldata, "\t\t<tag-value>", NULL);
if (!strcmp("single", default_metadata_tags[index].mode) ||
!strcmp("multi", default_metadata_tags[index].mode))
{
const gchar *value;
value = get_tag_ui_text (args, default_metadata_tags[index].tag,
default_metadata_tags[index].mode);
if (value)
{
value_utf = g_locale_to_utf8 (value, -1, NULL, NULL, NULL);
xmldata = g_strconcat (xmldata, value_utf, NULL);
}
}
else if (!strcmp("combo", default_metadata_tags[index].mode))
{
gint data = get_tag_ui_combo (args, default_metadata_tags[index].tag,
default_metadata_tags[index].mode);
value = g_malloc(1024);
g_sprintf(value, "%d", data);
xmldata = g_strconcat (xmldata, value, NULL);
g_free(value);
}
else if (!strcmp("list", default_metadata_tags[i].mode))
{
/* No IPTC lists elements at this point */
}
xmldata = g_strconcat (xmldata, "</tag-value>\n", NULL);
xmldata = g_strconcat (xmldata, "\t</iptc-tag>\n", NULL);
}
/* HANDLE XMP */
for (i = 0; i < n_default_metadata_tags; i++)
{
xmldata = g_strconcat (xmldata, "\t<xmp-tag>\n", NULL);
xmldata = g_strconcat (xmldata, "\t\t<tag-name>", NULL);
xmldata = g_strconcat (xmldata, default_metadata_tags[i].tag, NULL);
xmldata = g_strconcat (xmldata, "</tag-name>\n", NULL);
xmldata = g_strconcat (xmldata, "\t\t<tag-mode>", NULL);
xmldata = g_strconcat (xmldata, default_metadata_tags[i].mode, NULL);
xmldata = g_strconcat (xmldata, "</tag-mode>\n", NULL);
if (!strcmp("single", default_metadata_tags[i].mode) ||
!strcmp("multi", default_metadata_tags[i].mode))
{
const gchar *value;
xmldata = g_strconcat (xmldata, "\t\t<tag-value>", NULL);
value = get_tag_ui_text (args, default_metadata_tags[i].tag,
default_metadata_tags[i].mode);
if (value)
{
value_utf = g_locale_to_utf8 (value, -1, NULL, NULL, NULL);
xmldata = g_strconcat (xmldata, value_utf, NULL);
}
xmldata = g_strconcat (xmldata, "</tag-value>\n", NULL);
}
else if (!strcmp("combo", default_metadata_tags[i].mode))
{
gint data;
xmldata = g_strconcat (xmldata, "\t\t<tag-value>", NULL);
data = get_tag_ui_combo (args, default_metadata_tags[i].tag,
default_metadata_tags[i].mode);
value = g_malloc(1024);
g_sprintf(value, "%d", data);
xmldata = g_strconcat (xmldata, value, NULL);
g_free(value);
xmldata = g_strconcat (xmldata, "</tag-value>\n", NULL);
}
else if (!strcmp("list", default_metadata_tags[i].mode))
{
gchar *data;
xmldata = g_strconcat (xmldata, "\t\t<tag-list-value>\n", NULL);
data = get_tag_ui_list (args, default_metadata_tags[i].tag,
default_metadata_tags[i].mode);
xmldata = g_strconcat (xmldata, data, NULL);
if (data)
g_free(data);
xmldata = g_strconcat (xmldata, "\t\t</tag-list-value>\n", NULL);
}
xmldata = g_strconcat (xmldata, "\t</xmp-tag>\n", NULL);
}
xmldata = g_strconcat(xmldata, "</gimp-metadata>\n", NULL);
size = strlen (xmldata);
file = g_fopen (args->filename, "w");
if (file != NULL)
{
g_file_set_contents (args->filename, xmldata, size, &error);
fclose (file);
}
if (xmldata)
{
g_free (xmldata);
}
}
|