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