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