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