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