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