annotate src/metadata.c @ 1194:ef7530186597

Rename few variables to make the code more readable.
author zas_
date Tue, 02 Dec 2008 19:34:53 +0000
parents aed0e28b2744
children 43bfcbb62cd6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
1 /*
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
2 * Geeqie
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
3 * (C) 2004 John Ellis
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
4 * Copyright (C) 2008 The Geeqie Team
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
5 *
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
6 * Author: John Ellis, Laurent Monin
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
7 *
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
8 * This software is released under the GNU General Public License (GNU GPL).
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
9 * Please read the included file COPYING for more information.
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
10 * This software comes with no warranty of any kind, use at your own risk!
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
11 */
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
12
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
13
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
14 #include "main.h"
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
15 #include "metadata.h"
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
16
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
17 #include "cache.h"
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
18 #include "exif.h"
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
19 #include "filedata.h"
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
20 #include "misc.h"
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
21 #include "secure_save.h"
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
22 #include "ui_fileops.h"
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
23 #include "ui_misc.h"
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
24 #include "utilops.h"
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
25
1191
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
26 typedef enum {
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
27 MK_NONE,
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
28 MK_KEYWORDS,
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
29 MK_COMMENT
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
30 } MetadataKey;
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
31
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
32
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
33 /*
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
34 *-------------------------------------------------------------------
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
35 * keyword / comment read/write
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
36 *-------------------------------------------------------------------
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
37 */
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
38
1191
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
39 static gint metadata_file_write(gchar *path, GList *keywords, const gchar *comment)
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
40 {
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
41 SecureSaveInfo *ssi;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
42
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
43 ssi = secure_open(path);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
44 if (!ssi) return FALSE;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
45
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
46 secure_fprintf(ssi, "#%s comment (%s)\n\n", GQ_APPNAME, VERSION);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
47
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
48 secure_fprintf(ssi, "[keywords]\n");
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
49 while (keywords && secsave_errno == SS_ERR_NONE)
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
50 {
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
51 const gchar *word = keywords->data;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
52 keywords = keywords->next;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
53
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
54 secure_fprintf(ssi, "%s\n", word);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
55 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
56 secure_fputc(ssi, '\n');
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
57
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
58 secure_fprintf(ssi, "[comment]\n");
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
59 secure_fprintf(ssi, "%s\n", (comment) ? comment : "");
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
60
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
61 secure_fprintf(ssi, "#end\n");
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
62
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
63 return (secure_close(ssi) == 0);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
64 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
65
1191
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
66 static gint metadata_legacy_write(FileData *fd, GList *keywords, const gchar *comment)
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
67 {
1191
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
68 gchar *metadata_path;
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
69 gint success = FALSE;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
70
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
71 /* If an existing metadata file exists, we will try writing to
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
72 * it's location regardless of the user's preference.
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
73 */
1191
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
74 metadata_path = cache_find_location(CACHE_TYPE_METADATA, fd->path);
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
75 if (metadata_path && !access_file(metadata_path, W_OK))
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
76 {
1191
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
77 g_free(metadata_path);
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
78 metadata_path = NULL;
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
79 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
80
1191
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
81 if (!metadata_path)
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
82 {
1191
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
83 gchar *metadata_dir;
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
84 mode_t mode = 0755;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
85
1191
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
86 metadata_dir = cache_get_location(CACHE_TYPE_METADATA, fd->path, FALSE, &mode);
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
87 if (recursive_mkdir_if_not_exists(metadata_dir, mode))
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
88 {
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
89 gchar *filename = g_strconcat(fd->name, GQ_CACHE_EXT_METADATA, NULL);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
90
1191
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
91 metadata_path = g_build_filename(metadata_dir, filename, NULL);
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
92 g_free(filename);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
93 }
1191
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
94 g_free(metadata_dir);
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
95 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
96
1191
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
97 if (metadata_path)
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
98 {
1191
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
99 gchar *metadata_pathl;
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
100
1191
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
101 DEBUG_1("Saving comment: %s", metadata_path);
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
102
1191
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
103 metadata_pathl = path_from_utf8(metadata_path);
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
104
1191
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
105 success = metadata_file_write(metadata_pathl, keywords, comment);
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
106
1191
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
107 g_free(metadata_pathl);
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
108 g_free(metadata_path);
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
109 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
110
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
111 return success;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
112 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
113
1191
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
114 static gint metadata_file_read(gchar *path, GList **keywords, gchar **comment)
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
115 {
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
116 FILE *f;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
117 gchar s_buf[1024];
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
118 MetadataKey key = MK_NONE;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
119 GList *list = NULL;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
120 GString *comment_build = NULL;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
121
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
122 f = fopen(path, "r");
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
123 if (!f) return FALSE;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
124
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
125 while (fgets(s_buf, sizeof(s_buf), f))
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
126 {
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
127 gchar *ptr = s_buf;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
128
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
129 if (*ptr == '#') continue;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
130 if (*ptr == '[' && key != MK_COMMENT)
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
131 {
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
132 gchar *keystr = ++ptr;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
133
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
134 key = MK_NONE;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
135 while (*ptr != ']' && *ptr != '\n' && *ptr != '\0') ptr++;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
136
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
137 if (*ptr == ']')
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
138 {
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
139 *ptr = '\0';
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
140 if (g_ascii_strcasecmp(keystr, "keywords") == 0)
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
141 key = MK_KEYWORDS;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
142 else if (g_ascii_strcasecmp(keystr, "comment") == 0)
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
143 key = MK_COMMENT;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
144 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
145 continue;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
146 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
147
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
148 switch(key)
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
149 {
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
150 case MK_NONE:
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
151 break;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
152 case MK_KEYWORDS:
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
153 {
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
154 while (*ptr != '\n' && *ptr != '\0') ptr++;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
155 *ptr = '\0';
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
156 if (strlen(s_buf) > 0)
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
157 {
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
158 gchar *kw = utf8_validate_or_convert(s_buf);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
159
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
160 list = g_list_prepend(list, kw);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
161 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
162 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
163 break;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
164 case MK_COMMENT:
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
165 if (!comment_build) comment_build = g_string_new("");
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
166 g_string_append(comment_build, s_buf);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
167 break;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
168 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
169 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
170
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
171 fclose(f);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
172
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
173 *keywords = g_list_reverse(list);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
174 if (comment_build)
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
175 {
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
176 if (comment)
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
177 {
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
178 gint len;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
179 gchar *ptr = comment_build->str;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
180
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
181 /* strip leading and trailing newlines */
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
182 while (*ptr == '\n') ptr++;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
183 len = strlen(ptr);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
184 while (len > 0 && ptr[len - 1] == '\n') len--;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
185 if (ptr[len] == '\n') len++; /* keep the last one */
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
186 if (len > 0)
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
187 {
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
188 gchar *text = g_strndup(ptr, len);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
189
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
190 *comment = utf8_validate_or_convert(text);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
191 g_free(text);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
192 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
193 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
194 g_string_free(comment_build, TRUE);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
195 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
196
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
197 return TRUE;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
198 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
199
1191
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
200 static gint metadata_legacy_delete(FileData *fd)
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
201 {
1191
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
202 gchar *metadata_path;
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
203 gchar *metadata_pathl;
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
204 gint success = FALSE;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
205 if (!fd) return FALSE;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
206
1191
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
207 metadata_path = cache_find_location(CACHE_TYPE_METADATA, fd->path);
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
208 if (!metadata_path) return FALSE;
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
209
1191
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
210 metadata_pathl = path_from_utf8(metadata_path);
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
211
1191
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
212 success = !unlink(metadata_pathl);
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
213
1191
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
214 g_free(metadata_pathl);
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
215 g_free(metadata_path);
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
216
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
217 return success;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
218 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
219
1191
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
220 static gint metadata_legacy_read(FileData *fd, GList **keywords, gchar **comment)
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
221 {
1191
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
222 gchar *metadata_path;
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
223 gchar *metadata_pathl;
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
224 gint success = FALSE;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
225 if (!fd) return FALSE;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
226
1191
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
227 metadata_path = cache_find_location(CACHE_TYPE_METADATA, fd->path);
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
228 if (!metadata_path) return FALSE;
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
229
1191
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
230 metadata_pathl = path_from_utf8(metadata_path);
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
231
1191
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
232 success = metadata_file_read(metadata_pathl, keywords, comment);
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
233
1191
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
234 g_free(metadata_pathl);
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
235 g_free(metadata_path);
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
236
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
237 return success;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
238 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
239
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
240 static GList *remove_duplicate_strings_from_list(GList *list)
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
241 {
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
242 GList *work = list;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
243 GHashTable *hashtable = g_hash_table_new(g_str_hash, g_str_equal);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
244 GList *newlist = NULL;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
245
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
246 while (work)
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
247 {
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
248 gchar *key = work->data;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
249
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
250 if (g_hash_table_lookup(hashtable, key) == NULL)
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
251 {
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
252 g_hash_table_insert(hashtable, (gpointer) key, GINT_TO_POINTER(1));
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
253 newlist = g_list_prepend(newlist, key);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
254 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
255 work = work->next;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
256 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
257
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
258 g_hash_table_destroy(hashtable);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
259 g_list_free(list);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
260
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
261 return g_list_reverse(newlist);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
262 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
263
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
264 #define COMMENT_KEY "Xmp.dc.description"
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
265 #define KEYWORD_KEY "Xmp.dc.subject"
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
266
1191
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
267 static gint metadata_xmp_read(FileData *fd, GList **keywords, gchar **comment)
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
268 {
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
269 ExifData *exif;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
270
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
271 exif = exif_read_fd(fd);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
272 if (!exif) return FALSE;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
273
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
274 if (comment)
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
275 {
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
276 gchar *text;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
277 ExifItem *item = exif_get_item(exif, COMMENT_KEY);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
278
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
279 text = exif_item_get_string(item, 0);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
280 *comment = utf8_validate_or_convert(text);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
281 g_free(text);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
282 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
283
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
284 if (keywords)
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
285 {
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
286 ExifItem *item;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
287 guint i;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
288
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
289 *keywords = NULL;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
290 item = exif_get_item(exif, KEYWORD_KEY);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
291 for (i = 0; i < exif_item_get_elements(item); i++)
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
292 {
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
293 gchar *kw = exif_item_get_string(item, i);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
294 gchar *utf8_kw;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
295
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
296 if (!kw) break;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
297
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
298 utf8_kw = utf8_validate_or_convert(kw);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
299 *keywords = g_list_append(*keywords, (gpointer) utf8_kw);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
300 g_free(kw);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
301 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
302
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
303 /* FIXME:
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
304 * Exiv2 handles Iptc keywords as multiple entries with the
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
305 * same key, thus exif_get_item returns only the first keyword
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
306 * and the only way to get all keywords is to iterate through
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
307 * the item list.
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
308 */
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
309 for (item = exif_get_first_item(exif);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
310 item;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
311 item = exif_get_next_item(exif))
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
312 {
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
313 guint tag;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
314
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
315 tag = exif_item_get_tag_id(item);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
316 if (tag == 0x0019)
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
317 {
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
318 gchar *tag_name = exif_item_get_tag_name(item);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
319
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
320 if (strcmp(tag_name, "Iptc.Application2.Keywords") == 0)
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
321 {
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
322 gchar *kw;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
323 gchar *utf8_kw;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
324
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
325 kw = exif_item_get_data_as_text(item);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
326 if (!kw) continue;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
327
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
328 utf8_kw = utf8_validate_or_convert(kw);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
329 *keywords = g_list_append(*keywords, (gpointer) utf8_kw);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
330 g_free(kw);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
331 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
332 g_free(tag_name);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
333 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
334 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
335 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
336
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
337 exif_free_fd(fd, exif);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
338
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
339 return (comment && *comment) || (keywords && *keywords);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
340 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
341
1191
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
342 static gint metadata_xmp_write(FileData *fd, GList *keywords, const gchar *comment)
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
343 {
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
344 gint success;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
345 gint write_comment = (comment && comment[0]);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
346 ExifData *exif;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
347 ExifItem *item;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
348
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
349 exif = exif_read_fd(fd);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
350 if (!exif) return FALSE;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
351
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
352 item = exif_get_item(exif, COMMENT_KEY);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
353 if (item && !write_comment)
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
354 {
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
355 exif_item_delete(exif, item);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
356 item = NULL;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
357 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
358
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
359 if (!item && write_comment) item = exif_add_item(exif, COMMENT_KEY);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
360 if (item) exif_item_set_string(item, comment);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
361
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
362 while ((item = exif_get_item(exif, KEYWORD_KEY)))
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
363 {
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
364 exif_item_delete(exif, item);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
365 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
366
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
367 if (keywords)
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
368 {
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
369 GList *work;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
370
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
371 item = exif_add_item(exif, KEYWORD_KEY);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
372
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
373 work = keywords;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
374 while (work)
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
375 {
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
376 exif_item_set_string(item, (gchar *) work->data);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
377 work = work->next;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
378 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
379 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
380
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
381 success = exif_write(exif);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
382
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
383 exif_free_fd(fd, exif);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
384
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
385 return success;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
386 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
387
1191
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
388 gint metadata_write(FileData *fd, GList *keywords, const gchar *comment)
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
389 {
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
390 if (!fd) return FALSE;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
391
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
392 if (options->save_metadata_in_image_file &&
1191
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
393 metadata_xmp_write(fd, keywords, comment))
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
394 {
1191
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
395 metadata_legacy_delete(fd);
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
396 return TRUE;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
397 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
398
1191
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
399 return metadata_legacy_write(fd, keywords, comment);
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
400 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
401
1191
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
402 gint metadata_read(FileData *fd, GList **keywords, gchar **comment)
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
403 {
1194
ef7530186597 Rename few variables to make the code more readable.
zas_
parents: 1193
diff changeset
404 GList *keywords_xmp = NULL;
ef7530186597 Rename few variables to make the code more readable.
zas_
parents: 1193
diff changeset
405 GList *keywords_legacy = NULL;
ef7530186597 Rename few variables to make the code more readable.
zas_
parents: 1193
diff changeset
406 gchar *comment_xmp = NULL;
ef7530186597 Rename few variables to make the code more readable.
zas_
parents: 1193
diff changeset
407 gchar *comment_legacy = NULL;
ef7530186597 Rename few variables to make the code more readable.
zas_
parents: 1193
diff changeset
408 gint result_xmp, result_legacy;
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
409
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
410 if (!fd) return FALSE;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
411
1194
ef7530186597 Rename few variables to make the code more readable.
zas_
parents: 1193
diff changeset
412 result_xmp = metadata_xmp_read(fd, &keywords_xmp, &comment_xmp);
ef7530186597 Rename few variables to make the code more readable.
zas_
parents: 1193
diff changeset
413 result_legacy = metadata_legacy_read(fd, &keywords_legacy, &comment_legacy);
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
414
1194
ef7530186597 Rename few variables to make the code more readable.
zas_
parents: 1193
diff changeset
415 if (!result_xmp && !result_legacy)
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
416 {
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
417 return FALSE;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
418 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
419
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
420 if (keywords)
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
421 {
1194
ef7530186597 Rename few variables to make the code more readable.
zas_
parents: 1193
diff changeset
422 if (result_xmp && result_legacy)
ef7530186597 Rename few variables to make the code more readable.
zas_
parents: 1193
diff changeset
423 *keywords = g_list_concat(keywords_xmp, keywords_legacy);
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
424 else
1194
ef7530186597 Rename few variables to make the code more readable.
zas_
parents: 1193
diff changeset
425 *keywords = result_xmp ? keywords_xmp : keywords_legacy;
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
426
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
427 *keywords = remove_duplicate_strings_from_list(*keywords);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
428 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
429 else
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
430 {
1194
ef7530186597 Rename few variables to make the code more readable.
zas_
parents: 1193
diff changeset
431 if (result_xmp) string_list_free(keywords_xmp);
ef7530186597 Rename few variables to make the code more readable.
zas_
parents: 1193
diff changeset
432 if (result_legacy) string_list_free(keywords_legacy);
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
433 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
434
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
435
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
436 if (comment)
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
437 {
1194
ef7530186597 Rename few variables to make the code more readable.
zas_
parents: 1193
diff changeset
438 if (result_xmp && result_legacy && comment_xmp && comment_legacy && *comment_xmp && *comment_legacy)
ef7530186597 Rename few variables to make the code more readable.
zas_
parents: 1193
diff changeset
439 *comment = g_strdup_printf("%s\n%s", comment_xmp, comment_legacy);
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
440 else
1194
ef7530186597 Rename few variables to make the code more readable.
zas_
parents: 1193
diff changeset
441 *comment = result_xmp ? comment_xmp : comment_legacy;
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
442 }
1194
ef7530186597 Rename few variables to make the code more readable.
zas_
parents: 1193
diff changeset
443
ef7530186597 Rename few variables to make the code more readable.
zas_
parents: 1193
diff changeset
444 if (result_xmp && (!comment || *comment != comment_xmp)) g_free(comment_xmp);
ef7530186597 Rename few variables to make the code more readable.
zas_
parents: 1193
diff changeset
445 if (result_legacy && (!comment || *comment != comment_legacy)) g_free(comment_legacy);
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
446
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
447 // return FALSE in the following cases:
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
448 // - only looking for a comment and didn't find one
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
449 // - only looking for keywords and didn't find any
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
450 // - looking for either a comment or keywords, but found nothing
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
451 if ((!keywords && comment && !*comment) ||
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
452 (!comment && keywords && !*keywords) ||
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
453 ( comment && !*comment && keywords && !*keywords))
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
454 return FALSE;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
455
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
456 return TRUE;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
457 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
458
1194
ef7530186597 Rename few variables to make the code more readable.
zas_
parents: 1193
diff changeset
459 void metadata_set(FileData *fd, GList *new_keywords, gchar *new_comment, gboolean append)
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
460 {
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
461 gchar *comment = NULL;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
462 GList *keywords = NULL;
1194
ef7530186597 Rename few variables to make the code more readable.
zas_
parents: 1193
diff changeset
463 GList *keywords_list = NULL;
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
464
1191
bb02d0e2a573 Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents: 1178
diff changeset
465 metadata_read(fd, &keywords, &comment);
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
466
1194
ef7530186597 Rename few variables to make the code more readable.
zas_
parents: 1193
diff changeset
467 if (new_comment)
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
468 {
1192
48d62a7e3c33 metadata_set_keywords() -> metadata_set(). Use gboolean type for boolean parameters.
zas_
parents: 1191
diff changeset
469 if (append && comment && *comment)
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
470 {
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
471 gchar *tmp = comment;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
472
1194
ef7530186597 Rename few variables to make the code more readable.
zas_
parents: 1193
diff changeset
473 comment = g_strconcat(tmp, new_comment, NULL);
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
474 g_free(tmp);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
475 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
476 else
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
477 {
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
478 g_free(comment);
1194
ef7530186597 Rename few variables to make the code more readable.
zas_
parents: 1193
diff changeset
479 comment = g_strdup(new_comment);
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
480 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
481 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
482
1194
ef7530186597 Rename few variables to make the code more readable.
zas_
parents: 1193
diff changeset
483 if (new_keywords)
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
484 {
1192
48d62a7e3c33 metadata_set_keywords() -> metadata_set(). Use gboolean type for boolean parameters.
zas_
parents: 1191
diff changeset
485 if (append && keywords && g_list_length(keywords) > 0)
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
486 {
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
487 GList *work;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
488
1194
ef7530186597 Rename few variables to make the code more readable.
zas_
parents: 1193
diff changeset
489 work = new_keywords;
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
490 while (work)
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
491 {
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
492 gchar *key;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
493 GList *p;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
494
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
495 key = work->data;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
496 work = work->next;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
497
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
498 p = keywords;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
499 while (p && key)
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
500 {
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
501 gchar *needle = p->data;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
502 p = p->next;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
503
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
504 if (strcmp(needle, key) == 0) key = NULL;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
505 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
506
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
507 if (key) keywords = g_list_append(keywords, g_strdup(key));
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
508 }
1194
ef7530186597 Rename few variables to make the code more readable.
zas_
parents: 1193
diff changeset
509 keywords_list = keywords;
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
510 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
511 else
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
512 {
1194
ef7530186597 Rename few variables to make the code more readable.
zas_
parents: 1193
diff changeset
513 keywords_list = new_keywords;
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
514 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
515 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
516
1194
ef7530186597 Rename few variables to make the code more readable.
zas_
parents: 1193
diff changeset
517 metadata_write(fd, keywords_list, comment);
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
518
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
519 string_list_free(keywords);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
520 g_free(comment);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
521 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
522
1193
aed0e28b2744 keyword_list_find() -> find_string_in_list(), return gboolean.
zas_
parents: 1192
diff changeset
523 gboolean find_string_in_list(GList *list, const gchar *string)
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
524 {
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
525 while (list)
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
526 {
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
527 gchar *haystack = list->data;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
528
1193
aed0e28b2744 keyword_list_find() -> find_string_in_list(), return gboolean.
zas_
parents: 1192
diff changeset
529 if (haystack && string && strcmp(haystack, string) == 0) return TRUE;
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
530
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
531 list = list->next;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
532 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
533
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
534 return FALSE;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
535 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
536
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
537 #define KEYWORDS_SEPARATOR(c) ((c) == ',' || (c) == ';' || (c) == '\n' || (c) == '\r' || (c) == '\b')
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
538
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
539 GList *string_to_keywords_list(const gchar *text)
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
540 {
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
541 GList *list = NULL;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
542 const gchar *ptr = text;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
543
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
544 while (*ptr != '\0')
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
545 {
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
546 const gchar *begin;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
547 gint l = 0;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
548
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
549 while (KEYWORDS_SEPARATOR(*ptr)) ptr++;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
550 begin = ptr;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
551 while (*ptr != '\0' && !KEYWORDS_SEPARATOR(*ptr))
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
552 {
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
553 ptr++;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
554 l++;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
555 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
556
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
557 /* trim starting and ending whitespaces */
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
558 while (l > 0 && g_ascii_isspace(*begin)) begin++, l--;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
559 while (l > 0 && g_ascii_isspace(begin[l-1])) l--;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
560
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
561 if (l > 0)
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
562 {
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
563 gchar *keyword = g_strndup(begin, l);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
564
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
565 /* only add if not already in the list */
1193
aed0e28b2744 keyword_list_find() -> find_string_in_list(), return gboolean.
zas_
parents: 1192
diff changeset
566 if (find_string_in_list(list, keyword) == FALSE)
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
567 list = g_list_append(list, keyword);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
568 else
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
569 g_free(keyword);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
570 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
571 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
572
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
573 return list;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
574 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
575
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
576 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */