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