Mercurial > geeqie
annotate src/metadata.c @ 1241:8cb82b33cab8
fixed includes
author | nadvornik |
---|---|
date | Sun, 11 Jan 2009 21:24:58 +0000 |
parents | 30e207ac22e4 |
children | 5106f40597a3 |
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" |
1211 | 25 #include "filefilter.h" |
1241 | 26 #include "layout.h" |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
27 |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
28 typedef enum { |
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
29 MK_NONE, |
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
30 MK_KEYWORDS, |
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
31 MK_COMMENT |
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
32 } MetadataKey; |
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
33 |
1234
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
34 static const gchar *group_keys[] = {KEYWORD_KEY, COMMENT_KEY, NULL}; /* tags that will be written to all files in a group */ |
1204
fa91098e4949
queue metadata and write them in an idle callback
nadvornik
parents:
1203
diff
changeset
|
35 |
fa91098e4949
queue metadata and write them in an idle callback
nadvornik
parents:
1203
diff
changeset
|
36 static gboolean metadata_write_queue_idle_cb(gpointer data); |
fa91098e4949
queue metadata and write them in an idle callback
nadvornik
parents:
1203
diff
changeset
|
37 static gint metadata_legacy_write(FileData *fd); |
1224 | 38 static void metadata_legacy_delete(FileData *fd, const gchar *except); |
1211 | 39 |
40 | |
41 | |
1204
fa91098e4949
queue metadata and write them in an idle callback
nadvornik
parents:
1203
diff
changeset
|
42 /* |
fa91098e4949
queue metadata and write them in an idle callback
nadvornik
parents:
1203
diff
changeset
|
43 *------------------------------------------------------------------- |
fa91098e4949
queue metadata and write them in an idle callback
nadvornik
parents:
1203
diff
changeset
|
44 * write queue |
fa91098e4949
queue metadata and write them in an idle callback
nadvornik
parents:
1203
diff
changeset
|
45 *------------------------------------------------------------------- |
fa91098e4949
queue metadata and write them in an idle callback
nadvornik
parents:
1203
diff
changeset
|
46 */ |
fa91098e4949
queue metadata and write them in an idle callback
nadvornik
parents:
1203
diff
changeset
|
47 |
fa91098e4949
queue metadata and write them in an idle callback
nadvornik
parents:
1203
diff
changeset
|
48 static GList *metadata_write_queue = NULL; |
fa91098e4949
queue metadata and write them in an idle callback
nadvornik
parents:
1203
diff
changeset
|
49 static gint metadata_write_idle_id = -1; |
fa91098e4949
queue metadata and write them in an idle callback
nadvornik
parents:
1203
diff
changeset
|
50 |
fa91098e4949
queue metadata and write them in an idle callback
nadvornik
parents:
1203
diff
changeset
|
51 static void metadata_write_queue_add(FileData *fd) |
fa91098e4949
queue metadata and write them in an idle callback
nadvornik
parents:
1203
diff
changeset
|
52 { |
1218 | 53 if (!g_list_find(metadata_write_queue, fd)) |
54 { | |
55 metadata_write_queue = g_list_prepend(metadata_write_queue, fd); | |
56 file_data_ref(fd); | |
1240
30e207ac22e4
added a status bar button for writting metadata immediately
nadvornik
parents:
1238
diff
changeset
|
57 |
30e207ac22e4
added a status bar button for writting metadata immediately
nadvornik
parents:
1238
diff
changeset
|
58 layout_status_update_write_all(); |
1218 | 59 } |
1204
fa91098e4949
queue metadata and write them in an idle callback
nadvornik
parents:
1203
diff
changeset
|
60 |
1214
31402ecb2aed
write metadata after timeout, image change or dir change
nadvornik
parents:
1211
diff
changeset
|
61 if (metadata_write_idle_id != -1) |
31402ecb2aed
write metadata after timeout, image change or dir change
nadvornik
parents:
1211
diff
changeset
|
62 { |
31402ecb2aed
write metadata after timeout, image change or dir change
nadvornik
parents:
1211
diff
changeset
|
63 g_source_remove(metadata_write_idle_id); |
31402ecb2aed
write metadata after timeout, image change or dir change
nadvornik
parents:
1211
diff
changeset
|
64 metadata_write_idle_id = -1; |
31402ecb2aed
write metadata after timeout, image change or dir change
nadvornik
parents:
1211
diff
changeset
|
65 } |
31402ecb2aed
write metadata after timeout, image change or dir change
nadvornik
parents:
1211
diff
changeset
|
66 |
31402ecb2aed
write metadata after timeout, image change or dir change
nadvornik
parents:
1211
diff
changeset
|
67 if (options->metadata.confirm_timeout > 0) |
31402ecb2aed
write metadata after timeout, image change or dir change
nadvornik
parents:
1211
diff
changeset
|
68 { |
31402ecb2aed
write metadata after timeout, image change or dir change
nadvornik
parents:
1211
diff
changeset
|
69 metadata_write_idle_id = g_timeout_add(options->metadata.confirm_timeout * 1000, metadata_write_queue_idle_cb, NULL); |
31402ecb2aed
write metadata after timeout, image change or dir change
nadvornik
parents:
1211
diff
changeset
|
70 } |
1204
fa91098e4949
queue metadata and write them in an idle callback
nadvornik
parents:
1203
diff
changeset
|
71 } |
fa91098e4949
queue metadata and write them in an idle callback
nadvornik
parents:
1203
diff
changeset
|
72 |
fa91098e4949
queue metadata and write them in an idle callback
nadvornik
parents:
1203
diff
changeset
|
73 |
1205
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1204
diff
changeset
|
74 gboolean metadata_write_queue_remove(FileData *fd) |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1204
diff
changeset
|
75 { |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1204
diff
changeset
|
76 g_hash_table_destroy(fd->modified_xmp); |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1204
diff
changeset
|
77 fd->modified_xmp = NULL; |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1204
diff
changeset
|
78 |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1204
diff
changeset
|
79 metadata_write_queue = g_list_remove(metadata_write_queue, fd); |
1211 | 80 |
81 file_data_increment_version(fd); | |
82 file_data_send_notification(fd, NOTIFY_TYPE_REREAD); | |
83 | |
1205
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1204
diff
changeset
|
84 file_data_unref(fd); |
1240
30e207ac22e4
added a status bar button for writting metadata immediately
nadvornik
parents:
1238
diff
changeset
|
85 |
30e207ac22e4
added a status bar button for writting metadata immediately
nadvornik
parents:
1238
diff
changeset
|
86 layout_status_update_write_all(); |
1205
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1204
diff
changeset
|
87 return TRUE; |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1204
diff
changeset
|
88 } |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1204
diff
changeset
|
89 |
1211 | 90 gboolean metadata_write_queue_remove_list(GList *list) |
91 { | |
92 GList *work; | |
93 gboolean ret = TRUE; | |
94 | |
95 work = list; | |
96 while (work) | |
97 { | |
98 FileData *fd = work->data; | |
99 work = work->next; | |
100 ret = ret && metadata_write_queue_remove(fd); | |
101 } | |
102 return ret; | |
103 } | |
104 | |
1205
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1204
diff
changeset
|
105 |
1231 | 106 gboolean metadata_write_queue_confirm(FileUtilDoneFunc done_func, gpointer done_data) |
1205
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1204
diff
changeset
|
107 { |
1211 | 108 GList *work; |
109 GList *to_approve = NULL; | |
1205
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1204
diff
changeset
|
110 |
1211 | 111 work = metadata_write_queue; |
112 while (work) | |
113 { | |
114 FileData *fd = work->data; | |
115 work = work->next; | |
116 | |
117 if (fd->change) continue; /* another operation in progress, skip this file for now */ | |
118 | |
1225 | 119 to_approve = g_list_prepend(to_approve, file_data_ref(fd)); |
1211 | 120 } |
1205
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1204
diff
changeset
|
121 |
1231 | 122 file_util_write_metadata(NULL, to_approve, NULL, done_func, done_data); |
1211 | 123 |
124 filelist_free(to_approve); | |
1214
31402ecb2aed
write metadata after timeout, image change or dir change
nadvornik
parents:
1211
diff
changeset
|
125 |
31402ecb2aed
write metadata after timeout, image change or dir change
nadvornik
parents:
1211
diff
changeset
|
126 return (metadata_write_queue != NULL); |
31402ecb2aed
write metadata after timeout, image change or dir change
nadvornik
parents:
1211
diff
changeset
|
127 } |
1205
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1204
diff
changeset
|
128 |
1214
31402ecb2aed
write metadata after timeout, image change or dir change
nadvornik
parents:
1211
diff
changeset
|
129 static gboolean metadata_write_queue_idle_cb(gpointer data) |
31402ecb2aed
write metadata after timeout, image change or dir change
nadvornik
parents:
1211
diff
changeset
|
130 { |
1231 | 131 metadata_write_queue_confirm(NULL, NULL); |
1205
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1204
diff
changeset
|
132 metadata_write_idle_id = -1; |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1204
diff
changeset
|
133 return FALSE; |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1204
diff
changeset
|
134 } |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1204
diff
changeset
|
135 |
1224 | 136 gboolean metadata_write_perform(FileData *fd) |
1211 | 137 { |
138 gboolean success; | |
139 ExifData *exif; | |
140 | |
1224 | 141 g_assert(fd->change); |
142 | |
143 if (fd->change->dest && | |
1228 | 144 strcmp(extension_from_path(fd->change->dest), GQ_CACHE_EXT_METADATA) == 0) |
1224 | 145 { |
146 success = metadata_legacy_write(fd); | |
147 if (success) metadata_legacy_delete(fd, fd->change->dest); | |
148 return success; | |
149 } | |
150 | |
151 /* write via exiv2 */ | |
1211 | 152 /* we can either use cached metadata which have fd->modified_xmp already applied |
153 or read metadata from file and apply fd->modified_xmp | |
154 metadata are read also if the file was modified meanwhile */ | |
155 exif = exif_read_fd(fd); | |
156 if (!exif) return FALSE; | |
157 | |
1224 | 158 success = (fd->change->dest) ? exif_write_sidecar(exif, fd->change->dest) : exif_write(exif); /* write modified metadata */ |
159 exif_free_fd(fd, exif); | |
1211 | 160 |
1224 | 161 if (success) metadata_legacy_delete(fd, fd->change->dest); |
162 return success; | |
1204
fa91098e4949
queue metadata and write them in an idle callback
nadvornik
parents:
1203
diff
changeset
|
163 } |
fa91098e4949
queue metadata and write them in an idle callback
nadvornik
parents:
1203
diff
changeset
|
164 |
1240
30e207ac22e4
added a status bar button for writting metadata immediately
nadvornik
parents:
1238
diff
changeset
|
165 gint metadata_queue_length(void) |
30e207ac22e4
added a status bar button for writting metadata immediately
nadvornik
parents:
1238
diff
changeset
|
166 { |
30e207ac22e4
added a status bar button for writting metadata immediately
nadvornik
parents:
1238
diff
changeset
|
167 return g_list_length(metadata_write_queue); |
30e207ac22e4
added a status bar button for writting metadata immediately
nadvornik
parents:
1238
diff
changeset
|
168 } |
30e207ac22e4
added a status bar button for writting metadata immediately
nadvornik
parents:
1238
diff
changeset
|
169 |
1234
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
170 static gboolean metadata_check_key(const gchar *keys[], const gchar *key) |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
171 { |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
172 const gchar **k = keys; |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
173 |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
174 while (k) |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
175 { |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
176 if (strcmp(key, *k) == 0) return TRUE; |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
177 k++; |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
178 } |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
179 return FALSE; |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
180 } |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
181 |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
182 gboolean metadata_write_list(FileData *fd, const gchar *key, const GList *values) |
1203
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
183 { |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
184 if (!fd->modified_xmp) |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
185 { |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
186 fd->modified_xmp = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)string_list_free); |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
187 } |
1234
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
188 g_hash_table_insert(fd->modified_xmp, g_strdup(key), string_list_copy((GList *)values)); |
1203
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
189 if (fd->exif) |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
190 { |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
191 exif_update_metadata(fd->exif, key, values); |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
192 } |
1204
fa91098e4949
queue metadata and write them in an idle callback
nadvornik
parents:
1203
diff
changeset
|
193 metadata_write_queue_add(fd); |
1218 | 194 file_data_increment_version(fd); |
195 file_data_send_notification(fd, NOTIFY_TYPE_INTERNAL); | |
196 | |
1234
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
197 if (options->metadata.sync_grouped_files && metadata_check_key(group_keys, key)) |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
198 { |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
199 GList *work = fd->sidecar_files; |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
200 |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
201 while (work) |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
202 { |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
203 FileData *sfd = work->data; |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
204 work = work->next; |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
205 |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
206 if (filter_file_class(sfd->extension, FORMAT_CLASS_META)) continue; |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
207 |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
208 metadata_write_list(sfd, key, values); |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
209 } |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
210 } |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
211 |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
212 |
1203
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
213 return TRUE; |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
214 } |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
215 |
1234
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
216 gboolean metadata_write_string(FileData *fd, const gchar *key, const char *value) |
1203
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
217 { |
1234
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
218 GList *list = g_list_append(NULL, g_strdup(value)); |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
219 gboolean ret = metadata_write_list(fd, key, list); |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
220 string_list_free(list); |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
221 return ret; |
1203
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
222 } |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
223 |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
224 |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
225 /* |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
226 *------------------------------------------------------------------- |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
227 * keyword / comment read/write |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
228 *------------------------------------------------------------------- |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
229 */ |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
230 |
1204
fa91098e4949
queue metadata and write them in an idle callback
nadvornik
parents:
1203
diff
changeset
|
231 static gint metadata_file_write(gchar *path, GHashTable *modified_xmp) |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
232 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
233 SecureSaveInfo *ssi; |
1204
fa91098e4949
queue metadata and write them in an idle callback
nadvornik
parents:
1203
diff
changeset
|
234 GList *keywords = g_hash_table_lookup(modified_xmp, KEYWORD_KEY); |
fa91098e4949
queue metadata and write them in an idle callback
nadvornik
parents:
1203
diff
changeset
|
235 GList *comment_l = g_hash_table_lookup(modified_xmp, COMMENT_KEY); |
fa91098e4949
queue metadata and write them in an idle callback
nadvornik
parents:
1203
diff
changeset
|
236 gchar *comment = comment_l ? comment_l->data : NULL; |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
237 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
238 ssi = secure_open(path); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
239 if (!ssi) return FALSE; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
240 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
241 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
|
242 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
243 secure_fprintf(ssi, "[keywords]\n"); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
244 while (keywords && secsave_errno == SS_ERR_NONE) |
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 const gchar *word = keywords->data; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
247 keywords = keywords->next; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
248 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
249 secure_fprintf(ssi, "%s\n", word); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
250 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
251 secure_fputc(ssi, '\n'); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
252 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
253 secure_fprintf(ssi, "[comment]\n"); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
254 secure_fprintf(ssi, "%s\n", (comment) ? comment : ""); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
255 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
256 secure_fprintf(ssi, "#end\n"); |
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 return (secure_close(ssi) == 0); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
259 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
260 |
1204
fa91098e4949
queue metadata and write them in an idle callback
nadvornik
parents:
1203
diff
changeset
|
261 static gint metadata_legacy_write(FileData *fd) |
1178
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 gint success = FALSE; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
264 |
1224 | 265 g_assert(fd->change && fd->change->dest); |
266 gchar *metadata_pathl; | |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
267 |
1224 | 268 DEBUG_1("Saving comment: %s", fd->change->dest); |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
269 |
1224 | 270 metadata_pathl = path_from_utf8(fd->change->dest); |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
271 |
1224 | 272 success = metadata_file_write(metadata_pathl, fd->modified_xmp); |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
273 |
1224 | 274 g_free(metadata_pathl); |
1178
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 return success; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
277 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
278 |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
279 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
|
280 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
281 FILE *f; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
282 gchar s_buf[1024]; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
283 MetadataKey key = MK_NONE; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
284 GList *list = NULL; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
285 GString *comment_build = NULL; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
286 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
287 f = fopen(path, "r"); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
288 if (!f) return FALSE; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
289 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
290 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
|
291 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
292 gchar *ptr = s_buf; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
293 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
294 if (*ptr == '#') continue; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
295 if (*ptr == '[' && key != MK_COMMENT) |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
296 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
297 gchar *keystr = ++ptr; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
298 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
299 key = MK_NONE; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
300 while (*ptr != ']' && *ptr != '\n' && *ptr != '\0') ptr++; |
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 if (*ptr == ']') |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
303 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
304 *ptr = '\0'; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
305 if (g_ascii_strcasecmp(keystr, "keywords") == 0) |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
306 key = MK_KEYWORDS; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
307 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
|
308 key = MK_COMMENT; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
309 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
310 continue; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
311 } |
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 switch(key) |
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 case MK_NONE: |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
316 break; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
317 case MK_KEYWORDS: |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
318 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
319 while (*ptr != '\n' && *ptr != '\0') ptr++; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
320 *ptr = '\0'; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
321 if (strlen(s_buf) > 0) |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
322 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
323 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
|
324 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
325 list = g_list_prepend(list, kw); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
326 } |
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 break; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
329 case MK_COMMENT: |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
330 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
|
331 g_string_append(comment_build, s_buf); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
332 break; |
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 fclose(f); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
337 |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
338 if (keywords) |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
339 { |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
340 *keywords = g_list_reverse(list); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
341 } |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
342 else |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
343 { |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
344 string_list_free(list); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
345 } |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
346 |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
347 if (comment_build) |
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 if (comment) |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
350 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
351 gint len; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
352 gchar *ptr = comment_build->str; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
353 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
354 /* strip leading and trailing newlines */ |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
355 while (*ptr == '\n') ptr++; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
356 len = strlen(ptr); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
357 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
|
358 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
|
359 if (len > 0) |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
360 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
361 gchar *text = g_strndup(ptr, len); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
362 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
363 *comment = utf8_validate_or_convert(text); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
364 g_free(text); |
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 g_string_free(comment_build, TRUE); |
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 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
370 return TRUE; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
371 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
372 |
1224 | 373 static void metadata_legacy_delete(FileData *fd, const gchar *except) |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
374 { |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
375 gchar *metadata_path; |
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
376 gchar *metadata_pathl; |
1224 | 377 if (!fd) return; |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
378 |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
379 metadata_path = cache_find_location(CACHE_TYPE_METADATA, fd->path); |
1224 | 380 if (metadata_path && (!except || strcmp(metadata_path, except) != 0)) |
381 { | |
382 metadata_pathl = path_from_utf8(metadata_path); | |
383 unlink(metadata_pathl); | |
384 g_free(metadata_pathl); | |
385 g_free(metadata_path); | |
386 } | |
387 metadata_path = cache_find_location(CACHE_TYPE_XMP_METADATA, fd->path); | |
388 if (metadata_path && (!except || strcmp(metadata_path, except) != 0)) | |
389 { | |
390 metadata_pathl = path_from_utf8(metadata_path); | |
391 unlink(metadata_pathl); | |
392 g_free(metadata_pathl); | |
393 g_free(metadata_path); | |
394 } | |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
395 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
396 |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
397 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
|
398 { |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
399 gchar *metadata_path; |
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
400 gchar *metadata_pathl; |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
401 gint success = FALSE; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
402 if (!fd) return FALSE; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
403 |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
404 metadata_path = cache_find_location(CACHE_TYPE_METADATA, fd->path); |
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
405 if (!metadata_path) return FALSE; |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
406 |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
407 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
|
408 |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
409 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
|
410 |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
411 g_free(metadata_pathl); |
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
412 g_free(metadata_path); |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
413 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
414 return success; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
415 } |
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 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
|
418 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
419 GList *work = list; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
420 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
|
421 GList *newlist = NULL; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
422 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
423 while (work) |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
424 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
425 gchar *key = work->data; |
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 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
|
428 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
429 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
|
430 newlist = g_list_prepend(newlist, key); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
431 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
432 work = work->next; |
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 g_hash_table_destroy(hashtable); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
436 g_list_free(list); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
437 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
438 return g_list_reverse(newlist); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
439 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
440 |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
441 GList *metadata_read_list(FileData *fd, const gchar *key) |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
442 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
443 ExifData *exif; |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
444 GList *list = NULL; |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
445 if (!fd) return NULL; |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
446 |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
447 /* unwritten data overide everything */ |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
448 if (fd->modified_xmp) |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
449 { |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
450 list = g_hash_table_lookup(fd->modified_xmp, key); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
451 if (list) return string_list_copy(list); |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
452 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
453 |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
454 /* |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
455 Legacy metadata file is the primary source if it exists. |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
456 Merging the lists does not make much sense, because the existence of |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
457 legacy metadata file indicates that the other metadata sources are not |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
458 writable and thus it would not be possible to delete the keywords |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
459 that comes from the image file. |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
460 */ |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
461 if (strcmp(key, KEYWORD_KEY) == 0) |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
462 { |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
463 if (metadata_legacy_read(fd, &list, NULL)) return list; |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
464 } |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
465 |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
466 if (strcmp(key, COMMENT_KEY) == 0) |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
467 { |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
468 gchar *comment = NULL; |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
469 if (metadata_legacy_read(fd, NULL, &comment)) return g_list_append(NULL, comment); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
470 } |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
471 |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
472 exif = exif_read_fd(fd); /* this is cached, thus inexpensive */ |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
473 if (!exif) return NULL; |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
474 list = exif_get_metadata(exif, key); |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
475 exif_free_fd(fd, exif); |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
476 return list; |
1178
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 |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
479 gchar *metadata_read_string(FileData *fd, const gchar *key) |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
480 { |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
481 GList *string_list = metadata_read_list(fd, key); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
482 if (string_list) |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
483 { |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
484 gchar *str = string_list->data; |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
485 string_list->data = NULL; |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
486 string_list_free(string_list); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
487 return str; |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
488 } |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
489 return NULL; |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
490 } |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
491 |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
492 gboolean metadata_append_string(FileData *fd, const gchar *key, const char *value) |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
493 { |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
494 gchar *str = metadata_read_string(fd, key); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
495 |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
496 if (!str) |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
497 { |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
498 return metadata_write_string(fd, key, value); |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
499 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
500 else |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
501 { |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
502 gchar *new_string = g_strconcat(str, value, NULL); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
503 gboolean ret = metadata_write_string(fd, key, new_string); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
504 g_free(str); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
505 g_free(new_string); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
506 return ret; |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
507 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
508 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
509 |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
510 gboolean metadata_append_list(FileData *fd, const gchar *key, const GList *values) |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
511 { |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
512 GList *list = metadata_read_list(fd, key); |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
513 |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
514 if (!list) |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
515 { |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
516 return metadata_write_list(fd, key, values); |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
517 } |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
518 else |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
519 { |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
520 gboolean ret; |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
521 list = g_list_concat(list, string_list_copy(values)); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
522 list = remove_duplicate_strings_from_list(list); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
523 |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
524 ret = metadata_write_list(fd, key, list); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
525 string_list_free(list); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
526 return ret; |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
527 } |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
528 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
529 |
1193
aed0e28b2744
keyword_list_find() -> find_string_in_list(), return gboolean.
zas_
parents:
1192
diff
changeset
|
530 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
|
531 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
532 while (list) |
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 gchar *haystack = list->data; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
535 |
1193
aed0e28b2744
keyword_list_find() -> find_string_in_list(), return gboolean.
zas_
parents:
1192
diff
changeset
|
536 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
|
537 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
538 list = list->next; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
539 } |
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 return FALSE; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
542 } |
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 #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
|
545 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
546 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
|
547 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
548 GList *list = NULL; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
549 const gchar *ptr = text; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
550 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
551 while (*ptr != '\0') |
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 const gchar *begin; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
554 gint l = 0; |
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 while (KEYWORDS_SEPARATOR(*ptr)) ptr++; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
557 begin = ptr; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
558 while (*ptr != '\0' && !KEYWORDS_SEPARATOR(*ptr)) |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
559 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
560 ptr++; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
561 l++; |
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 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
564 /* trim starting and ending whitespaces */ |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
565 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
|
566 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
|
567 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
568 if (l > 0) |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
569 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
570 gchar *keyword = g_strndup(begin, l); |
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 /* only add if not already in the list */ |
1193
aed0e28b2744
keyword_list_find() -> find_string_in_list(), return gboolean.
zas_
parents:
1192
diff
changeset
|
573 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
|
574 list = g_list_append(list, keyword); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
575 else |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
576 g_free(keyword); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
577 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
578 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
579 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
580 return list; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
581 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
582 |
1222 | 583 /* |
584 * keywords to marks | |
585 */ | |
586 | |
587 | |
588 gboolean meta_data_get_keyword_mark(FileData *fd, gint n, gpointer data) | |
589 { | |
590 GList *keywords; | |
591 gboolean found = FALSE; | |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
592 keywords = metadata_read_list(fd, KEYWORD_KEY); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
593 if (keywords) |
1222 | 594 { |
595 GList *work = keywords; | |
596 | |
597 while (work) | |
598 { | |
599 gchar *kw = work->data; | |
600 work = work->next; | |
601 | |
602 if (strcmp(kw, data) == 0) | |
603 { | |
604 found = TRUE; | |
605 break; | |
606 } | |
607 } | |
608 string_list_free(keywords); | |
609 } | |
610 return found; | |
611 } | |
612 | |
613 gboolean meta_data_set_keyword_mark(FileData *fd, gint n, gboolean value, gpointer data) | |
614 { | |
615 GList *keywords = NULL; | |
616 gboolean found = FALSE; | |
617 gboolean changed = FALSE; | |
618 GList *work; | |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
619 keywords = metadata_read_list(fd, KEYWORD_KEY); |
1222 | 620 |
621 work = keywords; | |
622 | |
623 while (work) | |
624 { | |
625 gchar *kw = work->data; | |
626 | |
627 if (strcmp(kw, data) == 0) | |
628 { | |
629 found = TRUE; | |
630 if (!value) | |
631 { | |
632 changed = TRUE; | |
633 keywords = g_list_delete_link(keywords, work); | |
634 g_free(kw); | |
635 } | |
636 break; | |
637 } | |
638 work = work->next; | |
639 } | |
640 if (value && !found) | |
641 { | |
642 changed = TRUE; | |
643 keywords = g_list_append(keywords, g_strdup(data)); | |
644 } | |
645 | |
1234
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
646 if (changed) metadata_write_list(fd, KEYWORD_KEY, keywords); |
1222 | 647 |
648 string_list_free(keywords); | |
649 return TRUE; | |
650 } | |
651 | |
652 | |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
653 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |