Mercurial > geeqie.yaz
annotate src/metadata.c @ 1691:db9a5d850c03
updated links
author | nadvornik |
---|---|
date | Mon, 03 Aug 2009 20:47:14 +0000 |
parents | 2ec2f6827127 |
children | 9efd43f52b5b |
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 |
1284 | 4 * Copyright (C) 2008 - 2009 The Geeqie Team |
1178
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" |
1404 | 27 #include "rcfile.h" |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
28 |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
29 typedef enum { |
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
30 MK_NONE, |
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
31 MK_KEYWORDS, |
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
32 MK_COMMENT |
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
33 } MetadataKey; |
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
34 |
1598 | 35 static const gchar *group_keys[] = { /* tags that will be written to all files in a group, options->metadata.sync_grouped_files */ |
36 "Xmp.dc.title", | |
37 "Xmp.photoshop.Urgency", | |
38 "Xmp.photoshop.Category", | |
39 "Xmp.photoshop.SupplementalCategory", | |
40 "Xmp.dc.subject", | |
41 "Xmp.iptc.Location", | |
42 "Xmp.photoshop.Instruction", | |
43 "Xmp.photoshop.DateCreated", | |
44 "Xmp.dc.creator", | |
45 "Xmp.photoshop.AuthorsPosition", | |
46 "Xmp.photoshop.City", | |
47 "Xmp.photoshop.State", | |
48 "Xmp.iptc.CountryCode", | |
49 "Xmp.photoshop.Country", | |
50 "Xmp.photoshop.TransmissionReference", | |
51 "Xmp.photoshop.Headline", | |
52 "Xmp.photoshop.Credit", | |
53 "Xmp.photoshop.Source", | |
54 "Xmp.dc.rights", | |
55 "Xmp.dc.description", | |
56 "Xmp.photoshop.CaptionWriter", | |
57 NULL}; | |
1204
fa91098e4949
queue metadata and write them in an idle callback
nadvornik
parents:
1203
diff
changeset
|
58 |
fa91098e4949
queue metadata and write them in an idle callback
nadvornik
parents:
1203
diff
changeset
|
59 static gboolean metadata_write_queue_idle_cb(gpointer data); |
1434 | 60 static gboolean metadata_legacy_write(FileData *fd); |
1224 | 61 static void metadata_legacy_delete(FileData *fd, const gchar *except); |
1665 | 62 static gboolean metadata_file_read(gchar *path, GList **keywords, gchar **comment); |
1211 | 63 |
64 | |
65 | |
1204
fa91098e4949
queue metadata and write them in an idle callback
nadvornik
parents:
1203
diff
changeset
|
66 /* |
fa91098e4949
queue metadata and write them in an idle callback
nadvornik
parents:
1203
diff
changeset
|
67 *------------------------------------------------------------------- |
fa91098e4949
queue metadata and write them in an idle callback
nadvornik
parents:
1203
diff
changeset
|
68 * write queue |
fa91098e4949
queue metadata and write them in an idle callback
nadvornik
parents:
1203
diff
changeset
|
69 *------------------------------------------------------------------- |
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 static GList *metadata_write_queue = NULL; |
1523 | 73 static guint metadata_write_idle_id = 0; /* event source id */ |
1204
fa91098e4949
queue metadata and write them in an idle callback
nadvornik
parents:
1203
diff
changeset
|
74 |
fa91098e4949
queue metadata and write them in an idle callback
nadvornik
parents:
1203
diff
changeset
|
75 static void metadata_write_queue_add(FileData *fd) |
fa91098e4949
queue metadata and write them in an idle callback
nadvornik
parents:
1203
diff
changeset
|
76 { |
1218 | 77 if (!g_list_find(metadata_write_queue, fd)) |
78 { | |
79 metadata_write_queue = g_list_prepend(metadata_write_queue, fd); | |
80 file_data_ref(fd); | |
1240
30e207ac22e4
added a status bar button for writting metadata immediately
nadvornik
parents:
1238
diff
changeset
|
81 |
30e207ac22e4
added a status bar button for writting metadata immediately
nadvornik
parents:
1238
diff
changeset
|
82 layout_status_update_write_all(); |
1218 | 83 } |
1204
fa91098e4949
queue metadata and write them in an idle callback
nadvornik
parents:
1203
diff
changeset
|
84 |
1523 | 85 if (metadata_write_idle_id) |
1214
31402ecb2aed
write metadata after timeout, image change or dir change
nadvornik
parents:
1211
diff
changeset
|
86 { |
31402ecb2aed
write metadata after timeout, image change or dir change
nadvornik
parents:
1211
diff
changeset
|
87 g_source_remove(metadata_write_idle_id); |
1523 | 88 metadata_write_idle_id = 0; |
1214
31402ecb2aed
write metadata after timeout, image change or dir change
nadvornik
parents:
1211
diff
changeset
|
89 } |
31402ecb2aed
write metadata after timeout, image change or dir change
nadvornik
parents:
1211
diff
changeset
|
90 |
1244 | 91 if (options->metadata.confirm_after_timeout) |
1214
31402ecb2aed
write metadata after timeout, image change or dir change
nadvornik
parents:
1211
diff
changeset
|
92 { |
31402ecb2aed
write metadata after timeout, image change or dir change
nadvornik
parents:
1211
diff
changeset
|
93 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
|
94 } |
1204
fa91098e4949
queue metadata and write them in an idle callback
nadvornik
parents:
1203
diff
changeset
|
95 } |
fa91098e4949
queue metadata and write them in an idle callback
nadvornik
parents:
1203
diff
changeset
|
96 |
fa91098e4949
queue metadata and write them in an idle callback
nadvornik
parents:
1203
diff
changeset
|
97 |
1205
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1204
diff
changeset
|
98 gboolean metadata_write_queue_remove(FileData *fd) |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1204
diff
changeset
|
99 { |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1204
diff
changeset
|
100 g_hash_table_destroy(fd->modified_xmp); |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1204
diff
changeset
|
101 fd->modified_xmp = NULL; |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1204
diff
changeset
|
102 |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1204
diff
changeset
|
103 metadata_write_queue = g_list_remove(metadata_write_queue, fd); |
1211 | 104 |
105 file_data_increment_version(fd); | |
1432 | 106 file_data_send_notification(fd, NOTIFY_REREAD); |
1211 | 107 |
1205
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1204
diff
changeset
|
108 file_data_unref(fd); |
1240
30e207ac22e4
added a status bar button for writting metadata immediately
nadvornik
parents:
1238
diff
changeset
|
109 |
30e207ac22e4
added a status bar button for writting metadata immediately
nadvornik
parents:
1238
diff
changeset
|
110 layout_status_update_write_all(); |
1205
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1204
diff
changeset
|
111 return TRUE; |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1204
diff
changeset
|
112 } |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1204
diff
changeset
|
113 |
1211 | 114 gboolean metadata_write_queue_remove_list(GList *list) |
115 { | |
116 GList *work; | |
117 gboolean ret = TRUE; | |
118 | |
119 work = list; | |
120 while (work) | |
121 { | |
122 FileData *fd = work->data; | |
123 work = work->next; | |
124 ret = ret && metadata_write_queue_remove(fd); | |
125 } | |
126 return ret; | |
127 } | |
128 | |
1205
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1204
diff
changeset
|
129 |
1231 | 130 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
|
131 { |
1211 | 132 GList *work; |
133 GList *to_approve = NULL; | |
1205
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1204
diff
changeset
|
134 |
1211 | 135 work = metadata_write_queue; |
136 while (work) | |
137 { | |
138 FileData *fd = work->data; | |
139 work = work->next; | |
140 | |
141 if (fd->change) continue; /* another operation in progress, skip this file for now */ | |
142 | |
1225 | 143 to_approve = g_list_prepend(to_approve, file_data_ref(fd)); |
1211 | 144 } |
1205
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1204
diff
changeset
|
145 |
1231 | 146 file_util_write_metadata(NULL, to_approve, NULL, done_func, done_data); |
1211 | 147 |
148 filelist_free(to_approve); | |
1214
31402ecb2aed
write metadata after timeout, image change or dir change
nadvornik
parents:
1211
diff
changeset
|
149 |
31402ecb2aed
write metadata after timeout, image change or dir change
nadvornik
parents:
1211
diff
changeset
|
150 return (metadata_write_queue != NULL); |
31402ecb2aed
write metadata after timeout, image change or dir change
nadvornik
parents:
1211
diff
changeset
|
151 } |
1205
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1204
diff
changeset
|
152 |
1214
31402ecb2aed
write metadata after timeout, image change or dir change
nadvornik
parents:
1211
diff
changeset
|
153 static gboolean metadata_write_queue_idle_cb(gpointer data) |
31402ecb2aed
write metadata after timeout, image change or dir change
nadvornik
parents:
1211
diff
changeset
|
154 { |
1231 | 155 metadata_write_queue_confirm(NULL, NULL); |
1523 | 156 metadata_write_idle_id = 0; |
1205
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1204
diff
changeset
|
157 return FALSE; |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1204
diff
changeset
|
158 } |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1204
diff
changeset
|
159 |
1224 | 160 gboolean metadata_write_perform(FileData *fd) |
1211 | 161 { |
162 gboolean success; | |
163 ExifData *exif; | |
164 | |
1224 | 165 g_assert(fd->change); |
166 | |
167 if (fd->change->dest && | |
1228 | 168 strcmp(extension_from_path(fd->change->dest), GQ_CACHE_EXT_METADATA) == 0) |
1224 | 169 { |
170 success = metadata_legacy_write(fd); | |
171 if (success) metadata_legacy_delete(fd, fd->change->dest); | |
172 return success; | |
173 } | |
174 | |
175 /* write via exiv2 */ | |
1211 | 176 /* we can either use cached metadata which have fd->modified_xmp already applied |
177 or read metadata from file and apply fd->modified_xmp | |
178 metadata are read also if the file was modified meanwhile */ | |
179 exif = exif_read_fd(fd); | |
180 if (!exif) return FALSE; | |
181 | |
1224 | 182 success = (fd->change->dest) ? exif_write_sidecar(exif, fd->change->dest) : exif_write(exif); /* write modified metadata */ |
183 exif_free_fd(fd, exif); | |
1211 | 184 |
1255 | 185 if (fd->change->dest) |
186 /* this will create a FileData for the sidecar and link it to the main file | |
187 (we can't wait until the sidecar is discovered by directory scanning because | |
188 exif_read_fd is called before that and it would read the main file only and | |
189 store the metadata in the cache) | |
190 FIXME: this does not catch new sidecars created by independent external programs | |
191 */ | |
192 file_data_unref(file_data_new_simple(fd->change->dest)); | |
193 | |
1224 | 194 if (success) metadata_legacy_delete(fd, fd->change->dest); |
195 return success; | |
1204
fa91098e4949
queue metadata and write them in an idle callback
nadvornik
parents:
1203
diff
changeset
|
196 } |
fa91098e4949
queue metadata and write them in an idle callback
nadvornik
parents:
1203
diff
changeset
|
197 |
1240
30e207ac22e4
added a status bar button for writting metadata immediately
nadvornik
parents:
1238
diff
changeset
|
198 gint metadata_queue_length(void) |
30e207ac22e4
added a status bar button for writting metadata immediately
nadvornik
parents:
1238
diff
changeset
|
199 { |
30e207ac22e4
added a status bar button for writting metadata immediately
nadvornik
parents:
1238
diff
changeset
|
200 return g_list_length(metadata_write_queue); |
30e207ac22e4
added a status bar button for writting metadata immediately
nadvornik
parents:
1238
diff
changeset
|
201 } |
30e207ac22e4
added a status bar button for writting metadata immediately
nadvornik
parents:
1238
diff
changeset
|
202 |
1234
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
203 static gboolean metadata_check_key(const gchar *keys[], const gchar *key) |
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 const gchar **k = keys; |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
206 |
1243 | 207 while (*k) |
1234
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 if (strcmp(key, *k) == 0) return TRUE; |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
210 k++; |
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 return FALSE; |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
213 } |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
214 |
1567
c776b1310ca6
added an option to write image orientation to the metadata
nadvornik
parents:
1542
diff
changeset
|
215 gboolean metadata_write_revert(FileData *fd, const gchar *key) |
c776b1310ca6
added an option to write image orientation to the metadata
nadvornik
parents:
1542
diff
changeset
|
216 { |
c776b1310ca6
added an option to write image orientation to the metadata
nadvornik
parents:
1542
diff
changeset
|
217 if (!fd->modified_xmp) return FALSE; |
c776b1310ca6
added an option to write image orientation to the metadata
nadvornik
parents:
1542
diff
changeset
|
218 |
c776b1310ca6
added an option to write image orientation to the metadata
nadvornik
parents:
1542
diff
changeset
|
219 g_hash_table_remove(fd->modified_xmp, key); |
c776b1310ca6
added an option to write image orientation to the metadata
nadvornik
parents:
1542
diff
changeset
|
220 |
c776b1310ca6
added an option to write image orientation to the metadata
nadvornik
parents:
1542
diff
changeset
|
221 if (g_hash_table_size(fd->modified_xmp) == 0) |
c776b1310ca6
added an option to write image orientation to the metadata
nadvornik
parents:
1542
diff
changeset
|
222 { |
c776b1310ca6
added an option to write image orientation to the metadata
nadvornik
parents:
1542
diff
changeset
|
223 metadata_write_queue_remove(fd); |
c776b1310ca6
added an option to write image orientation to the metadata
nadvornik
parents:
1542
diff
changeset
|
224 } |
c776b1310ca6
added an option to write image orientation to the metadata
nadvornik
parents:
1542
diff
changeset
|
225 else |
c776b1310ca6
added an option to write image orientation to the metadata
nadvornik
parents:
1542
diff
changeset
|
226 { |
c776b1310ca6
added an option to write image orientation to the metadata
nadvornik
parents:
1542
diff
changeset
|
227 /* reread the metadata to restore the original value */ |
c776b1310ca6
added an option to write image orientation to the metadata
nadvornik
parents:
1542
diff
changeset
|
228 file_data_increment_version(fd); |
c776b1310ca6
added an option to write image orientation to the metadata
nadvornik
parents:
1542
diff
changeset
|
229 file_data_send_notification(fd, NOTIFY_REREAD); |
c776b1310ca6
added an option to write image orientation to the metadata
nadvornik
parents:
1542
diff
changeset
|
230 } |
1568 | 231 return TRUE; |
1567
c776b1310ca6
added an option to write image orientation to the metadata
nadvornik
parents:
1542
diff
changeset
|
232 } |
c776b1310ca6
added an option to write image orientation to the metadata
nadvornik
parents:
1542
diff
changeset
|
233 |
1234
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
234 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
|
235 { |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
236 if (!fd->modified_xmp) |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
237 { |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
238 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
|
239 } |
1234
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
240 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
|
241 if (fd->exif) |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
242 { |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
243 exif_update_metadata(fd->exif, key, values); |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
244 } |
1204
fa91098e4949
queue metadata and write them in an idle callback
nadvornik
parents:
1203
diff
changeset
|
245 metadata_write_queue_add(fd); |
1218 | 246 file_data_increment_version(fd); |
1432 | 247 file_data_send_notification(fd, NOTIFY_METADATA); |
1218 | 248 |
1234
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
249 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
|
250 { |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
251 GList *work = fd->sidecar_files; |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
252 |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
253 while (work) |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
254 { |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
255 FileData *sfd = work->data; |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
256 work = work->next; |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
257 |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
258 if (filter_file_class(sfd->extension, FORMAT_CLASS_META)) continue; |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
259 |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
260 metadata_write_list(sfd, key, values); |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
261 } |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
262 } |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
263 |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
264 |
1203
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
265 return TRUE; |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
266 } |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
267 |
1234
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
268 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
|
269 { |
1234
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
270 GList *list = g_list_append(NULL, g_strdup(value)); |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
271 gboolean ret = metadata_write_list(fd, key, list); |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
272 string_list_free(list); |
31f50c1b6a9a
write keywords and comments with separate functions
nadvornik
parents:
1231
diff
changeset
|
273 return ret; |
1203
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
274 } |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
275 |
1567
c776b1310ca6
added an option to write image orientation to the metadata
nadvornik
parents:
1542
diff
changeset
|
276 gboolean metadata_write_int(FileData *fd, const gchar *key, guint64 value) |
c776b1310ca6
added an option to write image orientation to the metadata
nadvornik
parents:
1542
diff
changeset
|
277 { |
c776b1310ca6
added an option to write image orientation to the metadata
nadvornik
parents:
1542
diff
changeset
|
278 gchar string[50]; |
c776b1310ca6
added an option to write image orientation to the metadata
nadvornik
parents:
1542
diff
changeset
|
279 |
c776b1310ca6
added an option to write image orientation to the metadata
nadvornik
parents:
1542
diff
changeset
|
280 g_snprintf(string, sizeof(string), "%ld", value); |
c776b1310ca6
added an option to write image orientation to the metadata
nadvornik
parents:
1542
diff
changeset
|
281 return metadata_write_string(fd, key, string); |
c776b1310ca6
added an option to write image orientation to the metadata
nadvornik
parents:
1542
diff
changeset
|
282 } |
1203
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1194
diff
changeset
|
283 |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
284 /* |
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 * keyword / comment read/write |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
287 *------------------------------------------------------------------- |
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 |
1665 | 290 static gboolean metadata_file_write(gchar *path, const GList *keywords, const gchar *comment) |
1178
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 SecureSaveInfo *ssi; |
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 ssi = secure_open(path); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
295 if (!ssi) return FALSE; |
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 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
|
298 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
299 secure_fprintf(ssi, "[keywords]\n"); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
300 while (keywords && secsave_errno == SS_ERR_NONE) |
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 const gchar *word = keywords->data; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
303 keywords = keywords->next; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
304 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
305 secure_fprintf(ssi, "%s\n", word); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
306 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
307 secure_fputc(ssi, '\n'); |
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 secure_fprintf(ssi, "[comment]\n"); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
310 secure_fprintf(ssi, "%s\n", (comment) ? comment : ""); |
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 secure_fprintf(ssi, "#end\n"); |
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 return (secure_close(ssi) == 0); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
315 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
316 |
1434 | 317 static gboolean metadata_legacy_write(FileData *fd) |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
318 { |
1434 | 319 gboolean success = FALSE; |
320 gchar *metadata_pathl; | |
1665 | 321 gpointer keywords; |
322 gpointer comment_l; | |
323 gboolean have_keywords; | |
324 gboolean have_comment; | |
325 const gchar *comment; | |
326 GList *orig_keywords = NULL; | |
327 gchar *orig_comment = NULL; | |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
328 |
1224 | 329 g_assert(fd->change && fd->change->dest); |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
330 |
1224 | 331 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
|
332 |
1665 | 333 if (!fd->modified_xmp) return TRUE; |
334 | |
1224 | 335 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
|
336 |
1665 | 337 have_keywords = g_hash_table_lookup_extended(fd->modified_xmp, KEYWORD_KEY, NULL, &keywords); |
338 have_comment = g_hash_table_lookup_extended(fd->modified_xmp, COMMENT_KEY, NULL, &comment_l); | |
1668 | 339 comment = (have_comment && comment_l) ? ((GList *)comment_l)->data : NULL; |
1665 | 340 |
341 if (!have_keywords || !have_comment) metadata_file_read(metadata_pathl, &orig_keywords, &orig_comment); | |
342 | |
343 success = metadata_file_write(metadata_pathl, | |
344 have_keywords ? (GList *)keywords : orig_keywords, | |
345 have_comment ? comment : orig_comment); | |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
346 |
1224 | 347 g_free(metadata_pathl); |
1665 | 348 g_free(orig_comment); |
349 string_list_free(orig_keywords); | |
350 | |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
351 return success; |
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 |
1434 | 354 static gboolean 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
|
355 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
356 FILE *f; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
357 gchar s_buf[1024]; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
358 MetadataKey key = MK_NONE; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
359 GList *list = NULL; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
360 GString *comment_build = NULL; |
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 f = fopen(path, "r"); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
363 if (!f) return FALSE; |
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 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
|
366 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
367 gchar *ptr = s_buf; |
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 if (*ptr == '#') continue; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
370 if (*ptr == '[' && key != MK_COMMENT) |
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 gchar *keystr = ++ptr; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
373 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
374 key = MK_NONE; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
375 while (*ptr != ']' && *ptr != '\n' && *ptr != '\0') ptr++; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
376 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
377 if (*ptr == ']') |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
378 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
379 *ptr = '\0'; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
380 if (g_ascii_strcasecmp(keystr, "keywords") == 0) |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
381 key = MK_KEYWORDS; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
382 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
|
383 key = MK_COMMENT; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
384 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
385 continue; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
386 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
387 |
1347
79937bc55f3a
Add missing space between switch and first parenthesis.
zas_
parents:
1340
diff
changeset
|
388 switch (key) |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
389 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
390 case MK_NONE: |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
391 break; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
392 case MK_KEYWORDS: |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
393 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
394 while (*ptr != '\n' && *ptr != '\0') ptr++; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
395 *ptr = '\0'; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
396 if (strlen(s_buf) > 0) |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
397 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
398 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
|
399 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
400 list = g_list_prepend(list, kw); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
401 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
402 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
403 break; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
404 case MK_COMMENT: |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
405 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
|
406 g_string_append(comment_build, s_buf); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
407 break; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
408 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
409 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
410 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
411 fclose(f); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
412 |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
413 if (keywords) |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
414 { |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
415 *keywords = g_list_reverse(list); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
416 } |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
417 else |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
418 { |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
419 string_list_free(list); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
420 } |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
421 |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
422 if (comment_build) |
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 if (comment) |
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 gint len; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
427 gchar *ptr = comment_build->str; |
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 /* strip leading and trailing newlines */ |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
430 while (*ptr == '\n') ptr++; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
431 len = strlen(ptr); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
432 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
|
433 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
|
434 if (len > 0) |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
435 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
436 gchar *text = g_strndup(ptr, len); |
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 *comment = utf8_validate_or_convert(text); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
439 g_free(text); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
440 } |
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 g_string_free(comment_build, TRUE); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
443 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
444 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
445 return TRUE; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
446 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
447 |
1224 | 448 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
|
449 { |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
450 gchar *metadata_path; |
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
451 gchar *metadata_pathl; |
1224 | 452 if (!fd) return; |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
453 |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
454 metadata_path = cache_find_location(CACHE_TYPE_METADATA, fd->path); |
1224 | 455 if (metadata_path && (!except || strcmp(metadata_path, except) != 0)) |
456 { | |
457 metadata_pathl = path_from_utf8(metadata_path); | |
458 unlink(metadata_pathl); | |
459 g_free(metadata_pathl); | |
460 g_free(metadata_path); | |
461 } | |
1667 | 462 |
463 #ifdef HAVE_EXIV2 | |
464 /* without exiv2: do not delete xmp metadata because we are not able to convert it, | |
465 just ignore it */ | |
1224 | 466 metadata_path = cache_find_location(CACHE_TYPE_XMP_METADATA, fd->path); |
467 if (metadata_path && (!except || strcmp(metadata_path, except) != 0)) | |
468 { | |
469 metadata_pathl = path_from_utf8(metadata_path); | |
470 unlink(metadata_pathl); | |
471 g_free(metadata_pathl); | |
472 g_free(metadata_path); | |
473 } | |
1667 | 474 #endif |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
475 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
476 |
1434 | 477 static gboolean 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
|
478 { |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
479 gchar *metadata_path; |
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
480 gchar *metadata_pathl; |
1434 | 481 gboolean success = FALSE; |
482 | |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
483 if (!fd) return FALSE; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
484 |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
485 metadata_path = cache_find_location(CACHE_TYPE_METADATA, fd->path); |
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
486 if (!metadata_path) return FALSE; |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
487 |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
488 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
|
489 |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
490 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
|
491 |
1191
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
492 g_free(metadata_pathl); |
bb02d0e2a573
Rename most comment_*() functions to more appropriate metadata_*().
zas_
parents:
1178
diff
changeset
|
493 g_free(metadata_path); |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
494 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
495 return success; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
496 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
497 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
498 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
|
499 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
500 GList *work = list; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
501 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
|
502 GList *newlist = NULL; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
503 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
504 while (work) |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
505 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
506 gchar *key = work->data; |
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 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
|
509 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
510 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
|
511 newlist = g_list_prepend(newlist, key); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
512 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
513 work = work->next; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
514 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
515 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
516 g_hash_table_destroy(hashtable); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
517 g_list_free(list); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
518 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
519 return g_list_reverse(newlist); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
520 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
521 |
1288 | 522 GList *metadata_read_list(FileData *fd, const gchar *key, MetadataFormat format) |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
523 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
524 ExifData *exif; |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
525 GList *list = NULL; |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
526 if (!fd) return NULL; |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
527 |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
528 /* unwritten data overide everything */ |
1288 | 529 if (fd->modified_xmp && format == METADATA_PLAIN) |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
530 { |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
531 list = g_hash_table_lookup(fd->modified_xmp, key); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
532 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
|
533 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
534 |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
535 /* |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
536 Legacy metadata file is the primary source if it exists. |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
537 Merging the lists does not make much sense, because the existence of |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
538 legacy metadata file indicates that the other metadata sources are not |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
539 writable and thus it would not be possible to delete the keywords |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
540 that comes from the image file. |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
541 */ |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
542 if (strcmp(key, KEYWORD_KEY) == 0) |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
543 { |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
544 if (metadata_legacy_read(fd, &list, NULL)) return list; |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
545 } |
1504 | 546 else if (strcmp(key, COMMENT_KEY) == 0) |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
547 { |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
548 gchar *comment = NULL; |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
549 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
|
550 } |
1504 | 551 else if (strncmp(key, "file.", 5) == 0) |
1483
7cb24fdf07c0
re-added possibility to display basic file info (size, mode, date)
nadvornik
parents:
1465
diff
changeset
|
552 { |
7cb24fdf07c0
re-added possibility to display basic file info (size, mode, date)
nadvornik
parents:
1465
diff
changeset
|
553 return g_list_append(NULL, metadata_file_info(fd, key, format)); |
7cb24fdf07c0
re-added possibility to display basic file info (size, mode, date)
nadvornik
parents:
1465
diff
changeset
|
554 } |
7cb24fdf07c0
re-added possibility to display basic file info (size, mode, date)
nadvornik
parents:
1465
diff
changeset
|
555 |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
556 exif = exif_read_fd(fd); /* this is cached, thus inexpensive */ |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
557 if (!exif) return NULL; |
1288 | 558 list = exif_get_metadata(exif, key, format); |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
559 exif_free_fd(fd, exif); |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
560 return list; |
1178
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 |
1288 | 563 gchar *metadata_read_string(FileData *fd, const gchar *key, MetadataFormat format) |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
564 { |
1288 | 565 GList *string_list = metadata_read_list(fd, key, format); |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
566 if (string_list) |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
567 { |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
568 gchar *str = string_list->data; |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
569 string_list->data = NULL; |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
570 string_list_free(string_list); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
571 return str; |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
572 } |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
573 return NULL; |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
574 } |
1288 | 575 |
576 guint64 metadata_read_int(FileData *fd, const gchar *key, guint64 fallback) | |
577 { | |
578 guint64 ret; | |
579 gchar *endptr; | |
580 gchar *string = metadata_read_string(fd, key, METADATA_PLAIN); | |
581 if (!string) return fallback; | |
582 | |
583 ret = g_ascii_strtoull(string, &endptr, 10); | |
584 if (string == endptr) ret = fallback; | |
585 g_free(string); | |
586 return ret; | |
587 } | |
1509 | 588 |
589 gdouble metadata_read_GPS_coord(FileData *fd, const gchar *key, gdouble fallback) | |
590 { | |
591 gdouble coord; | |
592 gchar *endptr; | |
593 gdouble deg, min, sec; | |
594 gboolean ok = FALSE; | |
595 gchar *string = metadata_read_string(fd, key, METADATA_PLAIN); | |
596 if (!string) return fallback; | |
597 | |
598 deg = g_ascii_strtod(string, &endptr); | |
599 if (*endptr == ',') | |
600 { | |
601 min = g_ascii_strtod(endptr + 1, &endptr); | |
602 if (*endptr == ',') | |
603 sec = g_ascii_strtod(endptr + 1, &endptr); | |
604 else | |
605 sec = 0.0; | |
606 | |
607 | |
608 if (*endptr == 'S' || *endptr == 'W' || *endptr == 'N' || *endptr == 'E') | |
609 { | |
610 coord = deg + min /60.0 + sec / 3600.0; | |
611 ok = TRUE; | |
612 if (*endptr == 'S' || *endptr == 'W') coord = -coord; | |
613 } | |
614 } | |
615 | |
616 if (!ok) | |
617 { | |
618 coord = fallback; | |
619 log_printf("unable to parse GPS coordinate '%s'\n", string); | |
620 } | |
621 | |
622 g_free(string); | |
623 return coord; | |
624 } | |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
625 |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
626 gboolean metadata_append_string(FileData *fd, const gchar *key, const char *value) |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
627 { |
1288 | 628 gchar *str = metadata_read_string(fd, key, METADATA_PLAIN); |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
629 |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
630 if (!str) |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
631 { |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
632 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
|
633 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
634 else |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
635 { |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
636 gchar *new_string = g_strconcat(str, value, NULL); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
637 gboolean ret = metadata_write_string(fd, key, new_string); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
638 g_free(str); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
639 g_free(new_string); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
640 return ret; |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
641 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
642 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
643 |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
644 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
|
645 { |
1288 | 646 GList *list = metadata_read_list(fd, key, METADATA_PLAIN); |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
647 |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
648 if (!list) |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
649 { |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
650 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
|
651 } |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
652 else |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
653 { |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
654 gboolean ret; |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
655 list = g_list_concat(list, string_list_copy(values)); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
656 list = remove_duplicate_strings_from_list(list); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
657 |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
658 ret = metadata_write_list(fd, key, list); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
659 string_list_free(list); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
660 return ret; |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
661 } |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
662 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
663 |
1689 | 664 /** |
665 * \see find_string_in_list | |
666 */ | |
1340
361120a66609
Use g_utf8_casefold() to compare keywords, uppercased/lowercased keywords are now matched against predefined list.
zas_
parents:
1288
diff
changeset
|
667 gchar *find_string_in_list_utf8nocase(GList *list, const gchar *string) |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
668 { |
1340
361120a66609
Use g_utf8_casefold() to compare keywords, uppercased/lowercased keywords are now matched against predefined list.
zas_
parents:
1288
diff
changeset
|
669 gchar *string_casefold = g_utf8_casefold(string, -1); |
361120a66609
Use g_utf8_casefold() to compare keywords, uppercased/lowercased keywords are now matched against predefined list.
zas_
parents:
1288
diff
changeset
|
670 |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
671 while (list) |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
672 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
673 gchar *haystack = list->data; |
1689 | 674 |
1340
361120a66609
Use g_utf8_casefold() to compare keywords, uppercased/lowercased keywords are now matched against predefined list.
zas_
parents:
1288
diff
changeset
|
675 if (haystack) |
361120a66609
Use g_utf8_casefold() to compare keywords, uppercased/lowercased keywords are now matched against predefined list.
zas_
parents:
1288
diff
changeset
|
676 { |
361120a66609
Use g_utf8_casefold() to compare keywords, uppercased/lowercased keywords are now matched against predefined list.
zas_
parents:
1288
diff
changeset
|
677 gboolean equal; |
361120a66609
Use g_utf8_casefold() to compare keywords, uppercased/lowercased keywords are now matched against predefined list.
zas_
parents:
1288
diff
changeset
|
678 gchar *haystack_casefold = g_utf8_casefold(haystack, -1); |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
679 |
1340
361120a66609
Use g_utf8_casefold() to compare keywords, uppercased/lowercased keywords are now matched against predefined list.
zas_
parents:
1288
diff
changeset
|
680 equal = (strcmp(haystack_casefold, string_casefold) == 0); |
361120a66609
Use g_utf8_casefold() to compare keywords, uppercased/lowercased keywords are now matched against predefined list.
zas_
parents:
1288
diff
changeset
|
681 g_free(haystack_casefold); |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
682 |
1340
361120a66609
Use g_utf8_casefold() to compare keywords, uppercased/lowercased keywords are now matched against predefined list.
zas_
parents:
1288
diff
changeset
|
683 if (equal) |
361120a66609
Use g_utf8_casefold() to compare keywords, uppercased/lowercased keywords are now matched against predefined list.
zas_
parents:
1288
diff
changeset
|
684 { |
361120a66609
Use g_utf8_casefold() to compare keywords, uppercased/lowercased keywords are now matched against predefined list.
zas_
parents:
1288
diff
changeset
|
685 g_free(string_casefold); |
361120a66609
Use g_utf8_casefold() to compare keywords, uppercased/lowercased keywords are now matched against predefined list.
zas_
parents:
1288
diff
changeset
|
686 return haystack; |
361120a66609
Use g_utf8_casefold() to compare keywords, uppercased/lowercased keywords are now matched against predefined list.
zas_
parents:
1288
diff
changeset
|
687 } |
361120a66609
Use g_utf8_casefold() to compare keywords, uppercased/lowercased keywords are now matched against predefined list.
zas_
parents:
1288
diff
changeset
|
688 } |
1689 | 689 |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
690 list = list->next; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
691 } |
1689 | 692 |
1340
361120a66609
Use g_utf8_casefold() to compare keywords, uppercased/lowercased keywords are now matched against predefined list.
zas_
parents:
1288
diff
changeset
|
693 g_free(string_casefold); |
361120a66609
Use g_utf8_casefold() to compare keywords, uppercased/lowercased keywords are now matched against predefined list.
zas_
parents:
1288
diff
changeset
|
694 return NULL; |
361120a66609
Use g_utf8_casefold() to compare keywords, uppercased/lowercased keywords are now matched against predefined list.
zas_
parents:
1288
diff
changeset
|
695 } |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
696 |
1689 | 697 /** |
698 * \see find_string_in_list | |
699 */ | |
700 gchar *find_string_in_list_utf8case(GList *list, const gchar *string) | |
701 { | |
702 while (list) | |
703 { | |
704 gchar *haystack = list->data; | |
705 | |
706 if (haystack && strcmp(haystack, string) == 0) | |
707 return haystack; | |
708 | |
709 list = list->next; | |
710 } // while (list) | |
711 | |
712 return NULL; | |
713 } // gchar *find_string_in_list_utf... | |
714 | |
715 /** | |
716 * \brief Find a existent string in a list. | |
717 * | |
718 * This is a switch between find_string_in_list_utf8case and | |
719 * find_string_in_list_utf8nocase to search with or without case for the | |
720 * existence of a string. | |
721 * | |
722 * \param list The list to search in | |
723 * \param string The string to search for | |
724 * \return The string or NULL | |
725 * | |
726 * \see find_string_in_list_utf8case | |
727 * \see find_string_in_list_utf8nocase | |
728 */ | |
729 gchar *find_string_in_list(GList *list, const gchar *string) | |
730 { | |
731 if (options->metadata.keywords_case_sensitive) | |
732 return find_string_in_list_utf8case(list, string); | |
733 else | |
734 return find_string_in_list_utf8nocase(list, string); | |
735 } | |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
736 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
737 #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
|
738 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
739 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
|
740 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
741 GList *list = NULL; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
742 const gchar *ptr = text; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
743 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
744 while (*ptr != '\0') |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
745 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
746 const gchar *begin; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
747 gint l = 0; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
748 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
749 while (KEYWORDS_SEPARATOR(*ptr)) ptr++; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
750 begin = ptr; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
751 while (*ptr != '\0' && !KEYWORDS_SEPARATOR(*ptr)) |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
752 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
753 ptr++; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
754 l++; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
755 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
756 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
757 /* trim starting and ending whitespaces */ |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
758 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
|
759 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
|
760 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
761 if (l > 0) |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
762 { |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
763 gchar *keyword = g_strndup(begin, l); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
764 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
765 /* only add if not already in the list */ |
1689 | 766 if (!find_string_in_list(list, keyword)) |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
767 list = g_list_append(list, keyword); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
768 else |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
769 g_free(keyword); |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
770 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
771 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
772 |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
773 return list; |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
774 } |
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
775 |
1222 | 776 /* |
777 * keywords to marks | |
778 */ | |
779 | |
780 | |
781 gboolean meta_data_get_keyword_mark(FileData *fd, gint n, gpointer data) | |
782 { | |
1425 | 783 /* FIXME: do not use global keyword_tree */ |
784 GList *path = data; | |
1222 | 785 GList *keywords; |
786 gboolean found = FALSE; | |
1288 | 787 keywords = metadata_read_list(fd, KEYWORD_KEY, METADATA_PLAIN); |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1234
diff
changeset
|
788 if (keywords) |
1222 | 789 { |
1425 | 790 GtkTreeIter iter; |
791 if (keyword_tree_get_iter(GTK_TREE_MODEL(keyword_tree), &iter, path) && | |
792 keyword_tree_is_set(GTK_TREE_MODEL(keyword_tree), &iter, keywords)) | |
793 found = TRUE; | |
1222 | 794 |
795 } | |
796 return found; | |
797 } | |
798 | |
799 gboolean meta_data_set_keyword_mark(FileData *fd, gint n, gboolean value, gpointer data) | |
800 { | |
1425 | 801 GList *path = data; |
1222 | 802 GList *keywords = NULL; |
1425 | 803 GtkTreeIter iter; |
804 | |
805 if (!keyword_tree_get_iter(GTK_TREE_MODEL(keyword_tree), &iter, path)) return FALSE; | |
806 | |
1288 | 807 keywords = metadata_read_list(fd, KEYWORD_KEY, METADATA_PLAIN); |
1222 | 808 |
1425 | 809 if (!!keyword_tree_is_set(GTK_TREE_MODEL(keyword_tree), &iter, keywords) != !!value) |
1222 | 810 { |
1425 | 811 if (value) |
1222 | 812 { |
1425 | 813 keyword_tree_set(GTK_TREE_MODEL(keyword_tree), &iter, &keywords); |
1222 | 814 } |
1425 | 815 else |
816 { | |
817 keyword_tree_reset(GTK_TREE_MODEL(keyword_tree), &iter, &keywords); | |
818 } | |
819 metadata_write_list(fd, KEYWORD_KEY, keywords); | |
1222 | 820 } |
821 | |
822 string_list_free(keywords); | |
823 return TRUE; | |
824 } | |
825 | |
1425 | 826 |
827 | |
828 void meta_data_connect_mark_with_keyword(GtkTreeModel *keyword_tree, GtkTreeIter *kw_iter, gint mark) | |
829 { | |
830 | |
831 FileDataGetMarkFunc get_mark_func; | |
832 FileDataSetMarkFunc set_mark_func; | |
833 gpointer mark_func_data; | |
834 | |
835 gint i; | |
836 | |
837 for (i = 0; i < FILEDATA_MARKS_SIZE; i++) | |
838 { | |
839 file_data_get_registered_mark_func(i, &get_mark_func, &set_mark_func, &mark_func_data); | |
840 if (get_mark_func == meta_data_get_keyword_mark) | |
841 { | |
842 GtkTreeIter old_kw_iter; | |
843 GList *old_path = mark_func_data; | |
844 | |
845 if (keyword_tree_get_iter(keyword_tree, &old_kw_iter, old_path) && | |
846 (i == mark || /* release any previous connection of given mark */ | |
847 keyword_compare(keyword_tree, &old_kw_iter, kw_iter) == 0)) /* or given keyword */ | |
848 { | |
849 file_data_register_mark_func(i, NULL, NULL, NULL, NULL); | |
850 gtk_tree_store_set(GTK_TREE_STORE(keyword_tree), &old_kw_iter, KEYWORD_COLUMN_MARK, "", -1); | |
851 } | |
852 } | |
853 } | |
854 | |
855 | |
856 if (mark >= 0 && mark < FILEDATA_MARKS_SIZE) | |
857 { | |
858 GList *path; | |
859 gchar *mark_str; | |
860 path = keyword_tree_get_path(keyword_tree, kw_iter); | |
861 file_data_register_mark_func(mark, meta_data_get_keyword_mark, meta_data_set_keyword_mark, path, (GDestroyNotify)string_list_free); | |
862 | |
863 mark_str = g_strdup_printf("%d", mark + 1); | |
864 gtk_tree_store_set(GTK_TREE_STORE(keyword_tree), kw_iter, KEYWORD_COLUMN_MARK, mark_str, -1); | |
865 g_free(mark_str); | |
866 } | |
867 } | |
868 | |
869 | |
1391 | 870 /* |
871 *------------------------------------------------------------------- | |
872 * keyword tree | |
873 *------------------------------------------------------------------- | |
874 */ | |
875 | |
876 | |
877 | |
878 GtkTreeStore *keyword_tree; | |
879 | |
880 gchar *keyword_get_name(GtkTreeModel *keyword_tree, GtkTreeIter *iter) | |
881 { | |
882 gchar *name; | |
883 gtk_tree_model_get(keyword_tree, iter, KEYWORD_COLUMN_NAME, &name, -1); | |
884 return name; | |
885 } | |
886 | |
887 gchar *keyword_get_casefold(GtkTreeModel *keyword_tree, GtkTreeIter *iter) | |
888 { | |
889 gchar *casefold; | |
890 gtk_tree_model_get(keyword_tree, iter, KEYWORD_COLUMN_CASEFOLD, &casefold, -1); | |
891 return casefold; | |
892 } | |
893 | |
894 gboolean keyword_get_is_keyword(GtkTreeModel *keyword_tree, GtkTreeIter *iter) | |
895 { | |
896 gboolean is_keyword; | |
897 gtk_tree_model_get(keyword_tree, iter, KEYWORD_COLUMN_IS_KEYWORD, &is_keyword, -1); | |
898 return is_keyword; | |
899 } | |
900 | |
901 void keyword_set(GtkTreeStore *keyword_tree, GtkTreeIter *iter, const gchar *name, gboolean is_keyword) | |
902 { | |
903 gchar *casefold = g_utf8_casefold(name, -1); | |
904 gtk_tree_store_set(keyword_tree, iter, KEYWORD_COLUMN_MARK, "", | |
905 KEYWORD_COLUMN_NAME, name, | |
906 KEYWORD_COLUMN_CASEFOLD, casefold, | |
907 KEYWORD_COLUMN_IS_KEYWORD, is_keyword, -1); | |
908 g_free(casefold); | |
909 } | |
910 | |
1396 | 911 gboolean keyword_compare(GtkTreeModel *keyword_tree, GtkTreeIter *a, GtkTreeIter *b) |
912 { | |
913 GtkTreePath *pa = gtk_tree_model_get_path(keyword_tree, a); | |
914 GtkTreePath *pb = gtk_tree_model_get_path(keyword_tree, b); | |
915 gint ret = gtk_tree_path_compare(pa, pb); | |
916 gtk_tree_path_free(pa); | |
917 gtk_tree_path_free(pb); | |
918 return ret; | |
919 } | |
920 | |
1429
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
921 gboolean keyword_same_parent(GtkTreeModel *keyword_tree, GtkTreeIter *a, GtkTreeIter *b) |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
922 { |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
923 GtkTreeIter parent_a; |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
924 GtkTreeIter parent_b; |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
925 |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
926 gboolean valid_pa = gtk_tree_model_iter_parent(keyword_tree, &parent_a, a); |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
927 gboolean valid_pb = gtk_tree_model_iter_parent(keyword_tree, &parent_b, b); |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
928 |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
929 if (valid_pa && valid_pb) |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
930 { |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
931 return keyword_compare(keyword_tree, &parent_a, &parent_b) == 0; |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
932 } |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
933 else |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
934 { |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
935 return (!valid_pa && !valid_pb); /* both are toplevel */ |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
936 } |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
937 } |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
938 |
1465 | 939 gboolean keyword_exists(GtkTreeModel *keyword_tree, GtkTreeIter *parent_ptr, GtkTreeIter *sibling, const gchar *name, gboolean exclude_sibling, GtkTreeIter *result) |
1429
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
940 { |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
941 GtkTreeIter parent; |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
942 GtkTreeIter iter; |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
943 gboolean toplevel = FALSE; |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
944 gboolean ret; |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
945 gchar *casefold; |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
946 |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
947 if (parent_ptr) |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
948 { |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
949 parent = *parent_ptr; |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
950 } |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
951 else if (sibling) |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
952 { |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
953 toplevel = !gtk_tree_model_iter_parent(keyword_tree, &parent, sibling); |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
954 } |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
955 else |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
956 { |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
957 toplevel = TRUE; |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
958 } |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
959 |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
960 if (!gtk_tree_model_iter_children(GTK_TREE_MODEL(keyword_tree), &iter, toplevel ? NULL : &parent)) return FALSE; |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
961 |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
962 casefold = g_utf8_casefold(name, -1); |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
963 ret = FALSE; |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
964 |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
965 while (TRUE) |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
966 { |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
967 if (!(exclude_sibling && sibling && keyword_compare(keyword_tree, &iter, sibling) == 0)) |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
968 { |
1592
69abb57139f0
use "keywords" instead of "tags" in option name, it is more consistent
nadvornik
parents:
1568
diff
changeset
|
969 if (options->metadata.keywords_case_sensitive) |
1540 | 970 { |
971 gchar *iter_name = keyword_get_name(keyword_tree, &iter); | |
972 ret = strcmp(name, iter_name) == 0; | |
973 g_free(iter_name); | |
974 } | |
975 else | |
976 { | |
977 gchar *iter_casefold = keyword_get_casefold(keyword_tree, &iter); | |
978 ret = strcmp(casefold, iter_casefold) == 0; | |
979 g_free(iter_casefold); | |
980 } // if (options->metadata.tags_cas... | |
1429
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
981 } |
1465 | 982 if (ret) |
983 { | |
984 if (result) *result = iter; | |
985 break; | |
986 } | |
1429
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
987 if (!gtk_tree_model_iter_next(keyword_tree, &iter)) break; |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
988 } |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
989 g_free(casefold); |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
990 return ret; |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
991 } |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
992 |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
993 |
1392 | 994 void keyword_copy(GtkTreeStore *keyword_tree, GtkTreeIter *to, GtkTreeIter *from) |
995 { | |
996 | |
997 gchar *mark, *name, *casefold; | |
998 gboolean is_keyword; | |
999 | |
1428 | 1000 /* do not copy KEYWORD_COLUMN_HIDE_IN, it fully shows the new subtree */ |
1392 | 1001 gtk_tree_model_get(GTK_TREE_MODEL(keyword_tree), from, KEYWORD_COLUMN_MARK, &mark, |
1002 KEYWORD_COLUMN_NAME, &name, | |
1003 KEYWORD_COLUMN_CASEFOLD, &casefold, | |
1004 KEYWORD_COLUMN_IS_KEYWORD, &is_keyword, -1); | |
1005 | |
1006 gtk_tree_store_set(keyword_tree, to, KEYWORD_COLUMN_MARK, mark, | |
1007 KEYWORD_COLUMN_NAME, name, | |
1008 KEYWORD_COLUMN_CASEFOLD, casefold, | |
1009 KEYWORD_COLUMN_IS_KEYWORD, is_keyword, -1); | |
1010 g_free(mark); | |
1011 g_free(name); | |
1012 g_free(casefold); | |
1013 } | |
1014 | |
1015 void keyword_copy_recursive(GtkTreeStore *keyword_tree, GtkTreeIter *to, GtkTreeIter *from) | |
1016 { | |
1017 GtkTreeIter from_child; | |
1018 | |
1019 keyword_copy(keyword_tree, to, from); | |
1020 | |
1021 if (!gtk_tree_model_iter_children(GTK_TREE_MODEL(keyword_tree), &from_child, from)) return; | |
1022 | |
1023 while (TRUE) | |
1024 { | |
1025 GtkTreeIter to_child; | |
1026 gtk_tree_store_append(keyword_tree, &to_child, to); | |
1027 keyword_copy_recursive(keyword_tree, &to_child, &from_child); | |
1028 if (!gtk_tree_model_iter_next(GTK_TREE_MODEL(keyword_tree), &from_child)) return; | |
1029 } | |
1030 } | |
1031 | |
1032 void keyword_move_recursive(GtkTreeStore *keyword_tree, GtkTreeIter *to, GtkTreeIter *from) | |
1033 { | |
1034 keyword_copy_recursive(keyword_tree, to, from); | |
1428 | 1035 keyword_delete(keyword_tree, from); |
1392 | 1036 } |
1037 | |
1038 GList *keyword_tree_get_path(GtkTreeModel *keyword_tree, GtkTreeIter *iter_ptr) | |
1039 { | |
1040 GList *path = NULL; | |
1041 GtkTreeIter iter = *iter_ptr; | |
1042 | |
1043 while (TRUE) | |
1044 { | |
1045 GtkTreeIter parent; | |
1046 path = g_list_prepend(path, keyword_get_name(keyword_tree, &iter)); | |
1047 if (!gtk_tree_model_iter_parent(keyword_tree, &parent, &iter)) break; | |
1048 iter = parent; | |
1049 } | |
1050 return path; | |
1051 } | |
1052 | |
1053 gboolean keyword_tree_get_iter(GtkTreeModel *keyword_tree, GtkTreeIter *iter_ptr, GList *path) | |
1054 { | |
1055 GtkTreeIter iter; | |
1056 | |
1057 if (!gtk_tree_model_get_iter_first(keyword_tree, &iter)) return FALSE; | |
1058 | |
1059 while (TRUE) | |
1060 { | |
1061 GtkTreeIter children; | |
1062 while (TRUE) | |
1063 { | |
1064 gchar *name = keyword_get_name(keyword_tree, &iter); | |
1065 if (strcmp(name, path->data) == 0) break; | |
1066 g_free(name); | |
1067 if (!gtk_tree_model_iter_next(keyword_tree, &iter)) return FALSE; | |
1068 } | |
1069 path = path->next; | |
1070 if (!path) | |
1071 { | |
1072 *iter_ptr = iter; | |
1073 return TRUE; | |
1074 } | |
1075 | |
1076 if (!gtk_tree_model_iter_children(keyword_tree, &children, &iter)) return FALSE; | |
1077 iter = children; | |
1078 } | |
1079 } | |
1080 | |
1081 | |
1391 | 1082 static gboolean keyword_tree_is_set_casefold(GtkTreeModel *keyword_tree, GtkTreeIter iter, GList *casefold_list) |
1083 { | |
1084 if (!casefold_list) return FALSE; | |
1456
b24391991f7f
improved expanding and hiding of helper keywords
nadvornik
parents:
1434
diff
changeset
|
1085 |
b24391991f7f
improved expanding and hiding of helper keywords
nadvornik
parents:
1434
diff
changeset
|
1086 if (!keyword_get_is_keyword(keyword_tree, &iter)) |
b24391991f7f
improved expanding and hiding of helper keywords
nadvornik
parents:
1434
diff
changeset
|
1087 { |
b24391991f7f
improved expanding and hiding of helper keywords
nadvornik
parents:
1434
diff
changeset
|
1088 /* for the purpose of expanding and hiding, a helper is set if it has any children set */ |
b24391991f7f
improved expanding and hiding of helper keywords
nadvornik
parents:
1434
diff
changeset
|
1089 GtkTreeIter child; |
b24391991f7f
improved expanding and hiding of helper keywords
nadvornik
parents:
1434
diff
changeset
|
1090 if (!gtk_tree_model_iter_children(keyword_tree, &child, &iter)) |
b24391991f7f
improved expanding and hiding of helper keywords
nadvornik
parents:
1434
diff
changeset
|
1091 return FALSE; /* this should happen only on empty helpers */ |
b24391991f7f
improved expanding and hiding of helper keywords
nadvornik
parents:
1434
diff
changeset
|
1092 |
b24391991f7f
improved expanding and hiding of helper keywords
nadvornik
parents:
1434
diff
changeset
|
1093 while (TRUE) |
b24391991f7f
improved expanding and hiding of helper keywords
nadvornik
parents:
1434
diff
changeset
|
1094 { |
b24391991f7f
improved expanding and hiding of helper keywords
nadvornik
parents:
1434
diff
changeset
|
1095 if (keyword_tree_is_set_casefold(keyword_tree, child, casefold_list)) return TRUE; |
b24391991f7f
improved expanding and hiding of helper keywords
nadvornik
parents:
1434
diff
changeset
|
1096 if (!gtk_tree_model_iter_next(keyword_tree, &child)) return FALSE; |
b24391991f7f
improved expanding and hiding of helper keywords
nadvornik
parents:
1434
diff
changeset
|
1097 } |
b24391991f7f
improved expanding and hiding of helper keywords
nadvornik
parents:
1434
diff
changeset
|
1098 } |
1391 | 1099 |
1100 while (TRUE) | |
1101 { | |
1102 GtkTreeIter parent; | |
1103 | |
1104 if (keyword_get_is_keyword(keyword_tree, &iter)) | |
1105 { | |
1106 GList *work = casefold_list; | |
1107 gboolean found = FALSE; | |
1108 gchar *iter_casefold = keyword_get_casefold(keyword_tree, &iter); | |
1109 while (work) | |
1110 { | |
1111 const gchar *casefold = work->data; | |
1112 work = work->next; | |
1113 | |
1114 if (strcmp(iter_casefold, casefold) == 0) | |
1115 { | |
1116 found = TRUE; | |
1117 break; | |
1118 } | |
1119 } | |
1120 g_free(iter_casefold); | |
1121 if (!found) return FALSE; | |
1122 } | |
1123 | |
1124 if (!gtk_tree_model_iter_parent(keyword_tree, &parent, &iter)) return TRUE; | |
1125 iter = parent; | |
1126 } | |
1127 } | |
1128 | |
1540 | 1129 static gboolean keyword_tree_is_set_casefull(GtkTreeModel *keyword_tree, GtkTreeIter iter, GList *kw_list) |
1130 { | |
1131 if (!kw_list) return FALSE; | |
1132 | |
1133 if (!keyword_get_is_keyword(keyword_tree, &iter)) | |
1134 { | |
1135 /* for the purpose of expanding and hiding, a helper is set if it has any children set */ | |
1136 GtkTreeIter child; | |
1137 if (!gtk_tree_model_iter_children(keyword_tree, &child, &iter)) | |
1138 return FALSE; /* this should happen only on empty helpers */ | |
1139 | |
1140 while (TRUE) | |
1141 { | |
1142 if (keyword_tree_is_set_casefull(keyword_tree, child, kw_list)) return TRUE; | |
1143 if (!gtk_tree_model_iter_next(keyword_tree, &child)) return FALSE; | |
1144 } | |
1145 } | |
1146 | |
1147 while (TRUE) | |
1148 { | |
1149 GtkTreeIter parent; | |
1150 | |
1151 if (keyword_get_is_keyword(keyword_tree, &iter)) | |
1152 { | |
1153 GList *work = kw_list; | |
1154 gboolean found = FALSE; | |
1155 gchar *iter_name = keyword_get_name(keyword_tree, &iter); | |
1156 while (work) | |
1157 { | |
1158 const gchar *name = work->data; | |
1159 work = work->next; | |
1160 | |
1161 if (strcmp(iter_name, name) == 0) | |
1162 { | |
1163 found = TRUE; | |
1164 break; | |
1165 } | |
1166 } | |
1167 g_free(iter_name); | |
1168 if (!found) return FALSE; | |
1169 } | |
1170 | |
1171 if (!gtk_tree_model_iter_parent(keyword_tree, &parent, &iter)) return TRUE; | |
1172 iter = parent; | |
1173 } | |
1174 } | |
1175 | |
1391 | 1176 gboolean keyword_tree_is_set(GtkTreeModel *keyword_tree, GtkTreeIter *iter, GList *kw_list) |
1177 { | |
1178 gboolean ret; | |
1179 GList *casefold_list = NULL; | |
1180 GList *work; | |
1181 | |
1592
69abb57139f0
use "keywords" instead of "tags" in option name, it is more consistent
nadvornik
parents:
1568
diff
changeset
|
1182 if (options->metadata.keywords_case_sensitive) |
1540 | 1183 { |
1184 ret = keyword_tree_is_set_casefull(keyword_tree, *iter, kw_list); | |
1185 } | |
1186 else | |
1391 | 1187 { |
1540 | 1188 work = kw_list; |
1189 while (work) | |
1190 { | |
1191 const gchar *kw = work->data; | |
1192 work = work->next; | |
1428 | 1193 |
1540 | 1194 casefold_list = g_list_prepend(casefold_list, g_utf8_casefold(kw, -1)); |
1195 } | |
1196 | |
1197 ret = keyword_tree_is_set_casefold(keyword_tree, *iter, casefold_list); | |
1198 | |
1199 string_list_free(casefold_list); | |
1391 | 1200 } |
1540 | 1201 |
1391 | 1202 return ret; |
1203 } | |
1204 | |
1205 void keyword_tree_set(GtkTreeModel *keyword_tree, GtkTreeIter *iter_ptr, GList **kw_list) | |
1206 { | |
1207 GtkTreeIter iter = *iter_ptr; | |
1208 while (TRUE) | |
1209 { | |
1210 GtkTreeIter parent; | |
1211 | |
1212 if (keyword_get_is_keyword(keyword_tree, &iter)) | |
1213 { | |
1214 gchar *name = keyword_get_name(keyword_tree, &iter); | |
1689 | 1215 if (!find_string_in_list(*kw_list, name)) |
1391 | 1216 { |
1217 *kw_list = g_list_append(*kw_list, name); | |
1218 } | |
1219 else | |
1220 { | |
1221 g_free(name); | |
1222 } | |
1223 } | |
1224 | |
1225 if (!gtk_tree_model_iter_parent(keyword_tree, &parent, &iter)) return; | |
1226 iter = parent; | |
1227 } | |
1228 } | |
1229 | |
1230 static void keyword_tree_reset1(GtkTreeModel *keyword_tree, GtkTreeIter *iter, GList **kw_list) | |
1231 { | |
1232 gchar *found; | |
1233 gchar *name; | |
1234 if (!keyword_get_is_keyword(keyword_tree, iter)) return; | |
1235 | |
1236 name = keyword_get_name(keyword_tree, iter); | |
1689 | 1237 found = find_string_in_list(*kw_list, name); |
1391 | 1238 |
1239 if (found) | |
1240 { | |
1241 *kw_list = g_list_remove(*kw_list, found); | |
1242 g_free(found); | |
1243 } | |
1244 g_free(name); | |
1245 } | |
1246 | |
1247 static void keyword_tree_reset_recursive(GtkTreeModel *keyword_tree, GtkTreeIter *iter, GList **kw_list) | |
1248 { | |
1249 GtkTreeIter child; | |
1250 keyword_tree_reset1(keyword_tree, iter, kw_list); | |
1251 | |
1252 if (!gtk_tree_model_iter_children(keyword_tree, &child, iter)) return; | |
1253 | |
1254 while (TRUE) | |
1255 { | |
1256 keyword_tree_reset_recursive(keyword_tree, &child, kw_list); | |
1257 if (!gtk_tree_model_iter_next(keyword_tree, &child)) return; | |
1258 } | |
1259 } | |
1260 | |
1261 static gboolean keyword_tree_check_empty_children(GtkTreeModel *keyword_tree, GtkTreeIter *parent, GList *kw_list) | |
1262 { | |
1263 GtkTreeIter iter; | |
1264 | |
1265 if (!gtk_tree_model_iter_children(keyword_tree, &iter, parent)) | |
1266 return TRUE; /* this should happen only on empty helpers */ | |
1267 | |
1268 while (TRUE) | |
1269 { | |
1457 | 1270 if (keyword_tree_is_set(keyword_tree, &iter, kw_list)) return FALSE; |
1271 if (!gtk_tree_model_iter_next(keyword_tree, &iter)) return TRUE; | |
1391 | 1272 } |
1273 } | |
1274 | |
1275 void keyword_tree_reset(GtkTreeModel *keyword_tree, GtkTreeIter *iter_ptr, GList **kw_list) | |
1276 { | |
1277 GtkTreeIter iter = *iter_ptr; | |
1278 GtkTreeIter parent; | |
1279 keyword_tree_reset_recursive(keyword_tree, &iter, kw_list); | |
1280 | |
1281 if (!gtk_tree_model_iter_parent(keyword_tree, &parent, &iter)) return; | |
1282 iter = parent; | |
1283 | |
1284 while (keyword_tree_check_empty_children(keyword_tree, &iter, *kw_list)) | |
1285 { | |
1286 GtkTreeIter parent; | |
1287 keyword_tree_reset1(keyword_tree, &iter, kw_list); | |
1288 if (!gtk_tree_model_iter_parent(keyword_tree, &parent, &iter)) return; | |
1289 iter = parent; | |
1290 } | |
1291 } | |
1292 | |
1414 | 1293 void keyword_delete(GtkTreeStore *keyword_tree, GtkTreeIter *iter_ptr) |
1294 { | |
1428 | 1295 GList *list; |
1296 GtkTreeIter child; | |
1297 while (gtk_tree_model_iter_children(GTK_TREE_MODEL(keyword_tree), &child, iter_ptr)) | |
1298 { | |
1299 keyword_delete(keyword_tree, &child); | |
1300 } | |
1301 | |
1302 meta_data_connect_mark_with_keyword(GTK_TREE_MODEL(keyword_tree), iter_ptr, -1); | |
1303 | |
1304 gtk_tree_model_get(GTK_TREE_MODEL(keyword_tree), iter_ptr, KEYWORD_COLUMN_HIDE_IN, &list, -1); | |
1305 g_list_free(list); | |
1306 | |
1414 | 1307 gtk_tree_store_remove(keyword_tree, iter_ptr); |
1308 } | |
1309 | |
1310 | |
1428 | 1311 void keyword_hide_in(GtkTreeStore *keyword_tree, GtkTreeIter *iter, gpointer id) |
1312 { | |
1313 GList *list; | |
1314 gtk_tree_model_get(GTK_TREE_MODEL(keyword_tree), iter, KEYWORD_COLUMN_HIDE_IN, &list, -1); | |
1315 if (!g_list_find(list, id)) | |
1316 { | |
1317 list = g_list_prepend(list, id); | |
1318 gtk_tree_store_set(keyword_tree, iter, KEYWORD_COLUMN_HIDE_IN, list, -1); | |
1319 } | |
1320 } | |
1321 | |
1322 void keyword_show_in(GtkTreeStore *keyword_tree, GtkTreeIter *iter, gpointer id) | |
1323 { | |
1324 GList *list; | |
1325 gtk_tree_model_get(GTK_TREE_MODEL(keyword_tree), iter, KEYWORD_COLUMN_HIDE_IN, &list, -1); | |
1326 list = g_list_remove(list, id); | |
1327 gtk_tree_store_set(keyword_tree, iter, KEYWORD_COLUMN_HIDE_IN, list, -1); | |
1328 } | |
1329 | |
1330 gboolean keyword_is_hidden_in(GtkTreeModel *keyword_tree, GtkTreeIter *iter, gpointer id) | |
1331 { | |
1332 GList *list; | |
1333 gtk_tree_model_get(keyword_tree, iter, KEYWORD_COLUMN_HIDE_IN, &list, -1); | |
1334 return !!g_list_find(list, id); | |
1335 } | |
1336 | |
1337 static gboolean keyword_show_all_in_cb(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data) | |
1338 { | |
1339 keyword_show_in(GTK_TREE_STORE(model), iter, data); | |
1340 return FALSE; | |
1341 } | |
1342 | |
1343 void keyword_show_all_in(GtkTreeStore *keyword_tree, gpointer id) | |
1344 { | |
1345 gtk_tree_model_foreach(GTK_TREE_MODEL(keyword_tree), keyword_show_all_in_cb, id); | |
1346 } | |
1347 | |
1348 static void keyword_hide_unset_in_recursive(GtkTreeStore *keyword_tree, GtkTreeIter *iter_ptr, gpointer id, GList *keywords) | |
1349 { | |
1350 GtkTreeIter iter = *iter_ptr; | |
1351 while (TRUE) | |
1352 { | |
1456
b24391991f7f
improved expanding and hiding of helper keywords
nadvornik
parents:
1434
diff
changeset
|
1353 if (!keyword_tree_is_set(GTK_TREE_MODEL(keyword_tree), &iter, keywords)) |
1428 | 1354 { |
1355 keyword_hide_in(keyword_tree, &iter, id); | |
1356 /* no need to check children of hidden node */ | |
1357 } | |
1358 else | |
1359 { | |
1360 GtkTreeIter child; | |
1361 if (gtk_tree_model_iter_children(GTK_TREE_MODEL(keyword_tree), &child, &iter)) | |
1362 { | |
1363 keyword_hide_unset_in_recursive(keyword_tree, &child, id, keywords); | |
1364 } | |
1365 } | |
1366 if (!gtk_tree_model_iter_next(GTK_TREE_MODEL(keyword_tree), &iter)) return; | |
1367 } | |
1368 } | |
1369 | |
1370 void keyword_hide_unset_in(GtkTreeStore *keyword_tree, gpointer id, GList *keywords) | |
1371 { | |
1372 GtkTreeIter iter; | |
1487 | 1373 if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(keyword_tree), &iter)) return; |
1428 | 1374 keyword_hide_unset_in_recursive(keyword_tree, &iter, id, keywords); |
1375 } | |
1376 | |
1377 static gboolean keyword_show_set_in_cb(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter_ptr, gpointer data) | |
1378 { | |
1379 GtkTreeIter iter = *iter_ptr; | |
1380 GList *keywords = data; | |
1381 gpointer id = keywords->data; | |
1382 keywords = keywords->next; /* hack */ | |
1383 if (keyword_tree_is_set(model, &iter, keywords)) | |
1384 { | |
1385 while (TRUE) | |
1386 { | |
1387 GtkTreeIter parent; | |
1388 keyword_show_in(GTK_TREE_STORE(model), &iter, id); | |
1389 if (!gtk_tree_model_iter_parent(GTK_TREE_MODEL(keyword_tree), &parent, &iter)) break; | |
1390 iter = parent; | |
1391 } | |
1392 } | |
1393 return FALSE; | |
1394 } | |
1395 | |
1396 void keyword_show_set_in(GtkTreeStore *keyword_tree, gpointer id, GList *keywords) | |
1397 { | |
1398 /* hack: pass id to keyword_hide_unset_in_cb in the list */ | |
1399 keywords = g_list_prepend(keywords, id); | |
1400 gtk_tree_model_foreach(GTK_TREE_MODEL(keyword_tree), keyword_show_set_in_cb, keywords); | |
1401 keywords = g_list_delete_link(keywords, keywords); | |
1402 } | |
1403 | |
1404 | |
1404 | 1405 void keyword_tree_new(void) |
1406 { | |
1407 if (keyword_tree) return; | |
1408 | |
1428 | 1409 keyword_tree = gtk_tree_store_new(KEYWORD_COLUMN_COUNT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_POINTER); |
1404 | 1410 } |
1411 | |
1542 | 1412 static GtkTreeIter keyword_tree_default_append(GtkTreeStore *keyword_tree, GtkTreeIter *parent, const gchar *name, gboolean is_keyword) |
1413 { | |
1414 GtkTreeIter iter; | |
1415 gtk_tree_store_append(keyword_tree, &iter, parent); | |
1416 keyword_set(keyword_tree, &iter, name, is_keyword); | |
1417 return iter; | |
1418 } | |
1391 | 1419 |
1420 void keyword_tree_new_default(void) | |
1421 { | |
1595 | 1422 GtkTreeIter i1, i2, i3; |
1391 | 1423 |
1595 | 1424 if (!keyword_tree) keyword_tree_new(); |
1391 | 1425 |
1542 | 1426 i1 = keyword_tree_default_append(keyword_tree, NULL, _("People"), TRUE); |
1427 i2 = keyword_tree_default_append(keyword_tree, &i1, _("Family"), TRUE); | |
1428 i2 = keyword_tree_default_append(keyword_tree, &i1, _("Free time"), TRUE); | |
1429 i2 = keyword_tree_default_append(keyword_tree, &i1, _("Children"), TRUE); | |
1430 i2 = keyword_tree_default_append(keyword_tree, &i1, _("Sport"), TRUE); | |
1431 i2 = keyword_tree_default_append(keyword_tree, &i1, _("Culture"), TRUE); | |
1432 i3 = keyword_tree_default_append(keyword_tree, &i2, _("Festival"), TRUE); | |
1433 i1 = keyword_tree_default_append(keyword_tree, NULL, _("Nature"), TRUE); | |
1434 i2 = keyword_tree_default_append(keyword_tree, &i1, _("Animal"), TRUE); | |
1435 i3 = keyword_tree_default_append(keyword_tree, &i2, _("Bird"), TRUE); | |
1436 i3 = keyword_tree_default_append(keyword_tree, &i2, _("Insect"), TRUE); | |
1437 i3 = keyword_tree_default_append(keyword_tree, &i2, _("Pets"), TRUE); | |
1438 i3 = keyword_tree_default_append(keyword_tree, &i2, _("Wildlife"), TRUE); | |
1439 i3 = keyword_tree_default_append(keyword_tree, &i2, _("Zoo"), TRUE); | |
1440 i2 = keyword_tree_default_append(keyword_tree, &i1, _("Plant"), TRUE); | |
1441 i3 = keyword_tree_default_append(keyword_tree, &i2, _("Tree"), TRUE); | |
1442 i3 = keyword_tree_default_append(keyword_tree, &i2, _("Flower"), TRUE); | |
1443 i2 = keyword_tree_default_append(keyword_tree, &i1, _("Water"), TRUE); | |
1444 i3 = keyword_tree_default_append(keyword_tree, &i2, _("River"), TRUE); | |
1445 i3 = keyword_tree_default_append(keyword_tree, &i2, _("Lake"), TRUE); | |
1446 i3 = keyword_tree_default_append(keyword_tree, &i2, _("Sea"), TRUE); | |
1447 i2 = keyword_tree_default_append(keyword_tree, &i1, _("Landscape"), TRUE); | |
1448 i1 = keyword_tree_default_append(keyword_tree, NULL, _("Art"), TRUE); | |
1449 i2 = keyword_tree_default_append(keyword_tree, &i1, _("Statue"), TRUE); | |
1450 i2 = keyword_tree_default_append(keyword_tree, &i1, _("Painting"), TRUE); | |
1451 i2 = keyword_tree_default_append(keyword_tree, &i1, _("Historic"), TRUE); | |
1452 i2 = keyword_tree_default_append(keyword_tree, &i1, _("Modern"), TRUE); | |
1453 i1 = keyword_tree_default_append(keyword_tree, NULL, _("City"), TRUE); | |
1454 i2 = keyword_tree_default_append(keyword_tree, &i1, _("Park"), TRUE); | |
1455 i2 = keyword_tree_default_append(keyword_tree, &i1, _("Street"), TRUE); | |
1456 i2 = keyword_tree_default_append(keyword_tree, &i1, _("Square"), TRUE); | |
1457 i1 = keyword_tree_default_append(keyword_tree, NULL, _("Architecture"), TRUE); | |
1458 i2 = keyword_tree_default_append(keyword_tree, &i1, _("Buildings"), FALSE); | |
1459 i3 = keyword_tree_default_append(keyword_tree, &i2, _("House"), TRUE); | |
1460 i3 = keyword_tree_default_append(keyword_tree, &i2, _("Cathedral"), TRUE); | |
1461 i3 = keyword_tree_default_append(keyword_tree, &i2, _("Palace"), TRUE); | |
1462 i3 = keyword_tree_default_append(keyword_tree, &i2, _("Castle"), TRUE); | |
1463 i3 = keyword_tree_default_append(keyword_tree, &i2, _("Bridge"), TRUE); | |
1464 i2 = keyword_tree_default_append(keyword_tree, &i1, _("Interior"), TRUE); | |
1465 i2 = keyword_tree_default_append(keyword_tree, &i1, _("Historic"), TRUE); | |
1466 i2 = keyword_tree_default_append(keyword_tree, &i1, _("Modern"), TRUE); | |
1467 i1 = keyword_tree_default_append(keyword_tree, NULL, _("Places"), FALSE); | |
1468 i1 = keyword_tree_default_append(keyword_tree, NULL, _("Conditions"), FALSE); | |
1469 i2 = keyword_tree_default_append(keyword_tree, &i1, _("Night"), TRUE); | |
1470 i3 = keyword_tree_default_append(keyword_tree, &i2, _("Lights"), TRUE); | |
1471 i2 = keyword_tree_default_append(keyword_tree, &i1, _("Reflections"), TRUE); | |
1472 i2 = keyword_tree_default_append(keyword_tree, &i1, _("Sun"), TRUE); | |
1473 i2 = keyword_tree_default_append(keyword_tree, &i1, _("Weather"), FALSE); | |
1474 i3 = keyword_tree_default_append(keyword_tree, &i2, _("Fog"), TRUE); | |
1475 i3 = keyword_tree_default_append(keyword_tree, &i2, _("Rain"), TRUE); | |
1476 i3 = keyword_tree_default_append(keyword_tree, &i2, _("Clouds"), TRUE); | |
1477 i3 = keyword_tree_default_append(keyword_tree, &i2, _("Snow"), TRUE); | |
1478 i3 = keyword_tree_default_append(keyword_tree, &i2, _("Sunny weather"), TRUE); | |
1479 i1 = keyword_tree_default_append(keyword_tree, NULL, _("Photo"), FALSE); | |
1480 i2 = keyword_tree_default_append(keyword_tree, &i1, _("Edited"), TRUE); | |
1481 i2 = keyword_tree_default_append(keyword_tree, &i1, _("Detail"), TRUE); | |
1482 i2 = keyword_tree_default_append(keyword_tree, &i1, _("Macro"), TRUE); | |
1483 i2 = keyword_tree_default_append(keyword_tree, &i1, _("Portrait"), TRUE); | |
1484 i2 = keyword_tree_default_append(keyword_tree, &i1, _("Black and White"), TRUE); | |
1485 i2 = keyword_tree_default_append(keyword_tree, &i1, _("Perspective"), TRUE); | |
1391 | 1486 } |
1487 | |
1222 | 1488 |
1404 | 1489 static void keyword_tree_node_write_config(GtkTreeModel *keyword_tree, GtkTreeIter *iter_ptr, GString *outstr, gint indent) |
1490 { | |
1491 GtkTreeIter iter = *iter_ptr; | |
1492 while (TRUE) | |
1493 { | |
1494 GtkTreeIter children; | |
1495 gchar *name; | |
1496 | |
1461 | 1497 WRITE_NL(); WRITE_STRING("<keyword "); |
1404 | 1498 name = keyword_get_name(keyword_tree, &iter); |
1499 write_char_option(outstr, indent, "name", name); | |
1500 g_free(name); | |
1501 write_bool_option(outstr, indent, "kw", keyword_get_is_keyword(keyword_tree, &iter)); | |
1502 if (gtk_tree_model_iter_children(keyword_tree, &children, &iter)) | |
1503 { | |
1461 | 1504 WRITE_STRING(">"); |
1505 indent++; | |
1404 | 1506 keyword_tree_node_write_config(keyword_tree, &children, outstr, indent); |
1461 | 1507 indent--; |
1508 WRITE_NL(); WRITE_STRING("</keyword>"); | |
1404 | 1509 } |
1461 | 1510 else |
1511 { | |
1512 WRITE_STRING("/>"); | |
1513 } | |
1404 | 1514 if (!gtk_tree_model_iter_next(keyword_tree, &iter)) return; |
1515 } | |
1516 } | |
1517 | |
1518 void keyword_tree_write_config(GString *outstr, gint indent) | |
1519 { | |
1520 GtkTreeIter iter; | |
1461 | 1521 WRITE_NL(); WRITE_STRING("<keyword_tree>"); |
1404 | 1522 indent++; |
1523 | |
1524 if (keyword_tree && gtk_tree_model_get_iter_first(GTK_TREE_MODEL(keyword_tree), &iter)) | |
1525 { | |
1526 keyword_tree_node_write_config(GTK_TREE_MODEL(keyword_tree), &iter, outstr, indent); | |
1527 } | |
1528 indent--; | |
1461 | 1529 WRITE_NL(); WRITE_STRING("</keyword_tree>"); |
1404 | 1530 } |
1531 | |
1532 GtkTreeIter *keyword_add_from_config(GtkTreeStore *keyword_tree, GtkTreeIter *parent, const gchar **attribute_names, const gchar **attribute_values) | |
1533 { | |
1534 gchar *name = NULL; | |
1535 gboolean is_kw = TRUE; | |
1536 | |
1537 while (*attribute_names) | |
1538 { | |
1539 const gchar *option = *attribute_names++; | |
1540 const gchar *value = *attribute_values++; | |
1541 | |
1542 if (READ_CHAR_FULL("name", name)) continue; | |
1543 if (READ_BOOL_FULL("kw", is_kw)) continue; | |
1544 | |
1464 | 1545 log_printf("unknown attribute %s = %s\n", option, value); |
1404 | 1546 } |
1547 if (name && name[0]) | |
1548 { | |
1549 GtkTreeIter iter; | |
1465 | 1550 /* re-use existing keyword if any */ |
1551 if (!keyword_exists(GTK_TREE_MODEL(keyword_tree), parent, NULL, name, FALSE, &iter)) | |
1552 { | |
1553 gtk_tree_store_append(keyword_tree, &iter, parent); | |
1554 } | |
1404 | 1555 keyword_set(keyword_tree, &iter, name, is_kw); |
1556 g_free(name); | |
1557 return gtk_tree_iter_copy(&iter); | |
1558 } | |
1559 g_free(name); | |
1560 return NULL; | |
1561 } | |
1562 | |
1178
f6449c17306b
Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff
changeset
|
1563 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |