annotate src/metadata.c @ 1504:1e2737565cb7

Cleanup.
author zas_
date Tue, 31 Mar 2009 22:23:33 +0000
parents d6061c019ceb
children e70bbc97acc5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
8b89e3ff286b Add year 2009 to copyright info everywhere.
zas_
parents: 1255
diff changeset
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
e2bbe90b0dcd most of the metadata options now works
nadvornik
parents: 1208
diff changeset
25 #include "filefilter.h"
1241
8cb82b33cab8 fixed includes
nadvornik
parents: 1240
diff changeset
26 #include "layout.h"
1404
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
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
b106af9689db More gboolean.
zas_
parents: 1432
diff changeset
38 static gboolean metadata_legacy_write(FileData *fd);
1224
ebfd305d902e improved sidecar writting
nadvornik
parents: 1222
diff changeset
39 static void metadata_legacy_delete(FileData *fd, const gchar *except);
1211
e2bbe90b0dcd most of the metadata options now works
nadvornik
parents: 1208
diff changeset
40
e2bbe90b0dcd most of the metadata options now works
nadvornik
parents: 1208
diff changeset
41
e2bbe90b0dcd most of the metadata options now works
nadvornik
parents: 1208
diff changeset
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;
fa91098e4949 queue metadata and write them in an idle callback
nadvornik
parents: 1203
diff changeset
50 static gint metadata_write_idle_id = -1;
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
46e4fda574dd improved buffering and notifications
nadvornik
parents: 1214
diff changeset
54 if (!g_list_find(metadata_write_queue, fd))
46e4fda574dd improved buffering and notifications
nadvornik
parents: 1214
diff changeset
55 {
46e4fda574dd improved buffering and notifications
nadvornik
parents: 1214
diff changeset
56 metadata_write_queue = g_list_prepend(metadata_write_queue, fd);
46e4fda574dd improved buffering and notifications
nadvornik
parents: 1214
diff changeset
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
46e4fda574dd improved buffering and notifications
nadvornik
parents: 1214
diff changeset
60 }
1204
fa91098e4949 queue metadata and write them in an idle callback
nadvornik
parents: 1203
diff changeset
61
1214
31402ecb2aed write metadata after timeout, image change or dir change
nadvornik
parents: 1211
diff changeset
62 if (metadata_write_idle_id != -1)
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);
31402ecb2aed write metadata after timeout, image change or dir change
nadvornik
parents: 1211
diff changeset
65 metadata_write_idle_id = -1;
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
b2d98b7c26c1 improved metadata preferences
nadvornik
parents: 1243
diff changeset
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
e2bbe90b0dcd most of the metadata options now works
nadvornik
parents: 1208
diff changeset
81
e2bbe90b0dcd most of the metadata options now works
nadvornik
parents: 1208
diff changeset
82 file_data_increment_version(fd);
1432
cf4029d10d38 improved notification system
nadvornik
parents: 1429
diff changeset
83 file_data_send_notification(fd, NOTIFY_REREAD);
1211
e2bbe90b0dcd most of the metadata options now works
nadvornik
parents: 1208
diff changeset
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
e2bbe90b0dcd most of the metadata options now works
nadvornik
parents: 1208
diff changeset
91 gboolean metadata_write_queue_remove_list(GList *list)
e2bbe90b0dcd most of the metadata options now works
nadvornik
parents: 1208
diff changeset
92 {
e2bbe90b0dcd most of the metadata options now works
nadvornik
parents: 1208
diff changeset
93 GList *work;
e2bbe90b0dcd most of the metadata options now works
nadvornik
parents: 1208
diff changeset
94 gboolean ret = TRUE;
e2bbe90b0dcd most of the metadata options now works
nadvornik
parents: 1208
diff changeset
95
e2bbe90b0dcd most of the metadata options now works
nadvornik
parents: 1208
diff changeset
96 work = list;
e2bbe90b0dcd most of the metadata options now works
nadvornik
parents: 1208
diff changeset
97 while (work)
e2bbe90b0dcd most of the metadata options now works
nadvornik
parents: 1208
diff changeset
98 {
e2bbe90b0dcd most of the metadata options now works
nadvornik
parents: 1208
diff changeset
99 FileData *fd = work->data;
e2bbe90b0dcd most of the metadata options now works
nadvornik
parents: 1208
diff changeset
100 work = work->next;
e2bbe90b0dcd most of the metadata options now works
nadvornik
parents: 1208
diff changeset
101 ret = ret && metadata_write_queue_remove(fd);
e2bbe90b0dcd most of the metadata options now works
nadvornik
parents: 1208
diff changeset
102 }
e2bbe90b0dcd most of the metadata options now works
nadvornik
parents: 1208
diff changeset
103 return ret;
e2bbe90b0dcd most of the metadata options now works
nadvornik
parents: 1208
diff changeset
104 }
e2bbe90b0dcd most of the metadata options now works
nadvornik
parents: 1208
diff changeset
105
1205
3ff2aa99108b use the workflow in utilops.c for metadata approving and writting
nadvornik
parents: 1204
diff changeset
106
1231
ca8ccf0c3e81 added done callback to utilops
nadvornik
parents: 1228
diff changeset
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
e2bbe90b0dcd most of the metadata options now works
nadvornik
parents: 1208
diff changeset
109 GList *work;
e2bbe90b0dcd most of the metadata options now works
nadvornik
parents: 1208
diff changeset
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
e2bbe90b0dcd most of the metadata options now works
nadvornik
parents: 1208
diff changeset
112 work = metadata_write_queue;
e2bbe90b0dcd most of the metadata options now works
nadvornik
parents: 1208
diff changeset
113 while (work)
e2bbe90b0dcd most of the metadata options now works
nadvornik
parents: 1208
diff changeset
114 {
e2bbe90b0dcd most of the metadata options now works
nadvornik
parents: 1208
diff changeset
115 FileData *fd = work->data;
e2bbe90b0dcd most of the metadata options now works
nadvornik
parents: 1208
diff changeset
116 work = work->next;
e2bbe90b0dcd most of the metadata options now works
nadvornik
parents: 1208
diff changeset
117
e2bbe90b0dcd most of the metadata options now works
nadvornik
parents: 1208
diff changeset
118 if (fd->change) continue; /* another operation in progress, skip this file for now */
e2bbe90b0dcd most of the metadata options now works
nadvornik
parents: 1208
diff changeset
119
1225
3e5f52382573 fixed previous change
nadvornik
parents: 1224
diff changeset
120 to_approve = g_list_prepend(to_approve, file_data_ref(fd));
1211
e2bbe90b0dcd most of the metadata options now works
nadvornik
parents: 1208
diff changeset
121 }
1205
3ff2aa99108b use the workflow in utilops.c for metadata approving and writting
nadvornik
parents: 1204
diff changeset
122
1231
ca8ccf0c3e81 added done callback to utilops
nadvornik
parents: 1228
diff changeset
123 file_util_write_metadata(NULL, to_approve, NULL, done_func, done_data);
1211
e2bbe90b0dcd most of the metadata options now works
nadvornik
parents: 1208
diff changeset
124
e2bbe90b0dcd most of the metadata options now works
nadvornik
parents: 1208
diff changeset
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
ca8ccf0c3e81 added done callback to utilops
nadvornik
parents: 1228
diff changeset
132 metadata_write_queue_confirm(NULL, NULL);
1205
3ff2aa99108b use the workflow in utilops.c for metadata approving and writting
nadvornik
parents: 1204
diff changeset
133 metadata_write_idle_id = -1;
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
ebfd305d902e improved sidecar writting
nadvornik
parents: 1222
diff changeset
137 gboolean metadata_write_perform(FileData *fd)
1211
e2bbe90b0dcd most of the metadata options now works
nadvornik
parents: 1208
diff changeset
138 {
e2bbe90b0dcd most of the metadata options now works
nadvornik
parents: 1208
diff changeset
139 gboolean success;
e2bbe90b0dcd most of the metadata options now works
nadvornik
parents: 1208
diff changeset
140 ExifData *exif;
e2bbe90b0dcd most of the metadata options now works
nadvornik
parents: 1208
diff changeset
141
1224
ebfd305d902e improved sidecar writting
nadvornik
parents: 1222
diff changeset
142 g_assert(fd->change);
ebfd305d902e improved sidecar writting
nadvornik
parents: 1222
diff changeset
143
ebfd305d902e improved sidecar writting
nadvornik
parents: 1222
diff changeset
144 if (fd->change->dest &&
1228
4d5587c4bf56 fixed writting of legacy metadata
nadvornik
parents: 1225
diff changeset
145 strcmp(extension_from_path(fd->change->dest), GQ_CACHE_EXT_METADATA) == 0)
1224
ebfd305d902e improved sidecar writting
nadvornik
parents: 1222
diff changeset
146 {
ebfd305d902e improved sidecar writting
nadvornik
parents: 1222
diff changeset
147 success = metadata_legacy_write(fd);
ebfd305d902e improved sidecar writting
nadvornik
parents: 1222
diff changeset
148 if (success) metadata_legacy_delete(fd, fd->change->dest);
ebfd305d902e improved sidecar writting
nadvornik
parents: 1222
diff changeset
149 return success;
ebfd305d902e improved sidecar writting
nadvornik
parents: 1222
diff changeset
150 }
ebfd305d902e improved sidecar writting
nadvornik
parents: 1222
diff changeset
151
ebfd305d902e improved sidecar writting
nadvornik
parents: 1222
diff changeset
152 /* write via exiv2 */
1211
e2bbe90b0dcd most of the metadata options now works
nadvornik
parents: 1208
diff changeset
153 /* we can either use cached metadata which have fd->modified_xmp already applied
e2bbe90b0dcd most of the metadata options now works
nadvornik
parents: 1208
diff changeset
154 or read metadata from file and apply fd->modified_xmp
e2bbe90b0dcd most of the metadata options now works
nadvornik
parents: 1208
diff changeset
155 metadata are read also if the file was modified meanwhile */
e2bbe90b0dcd most of the metadata options now works
nadvornik
parents: 1208
diff changeset
156 exif = exif_read_fd(fd);
e2bbe90b0dcd most of the metadata options now works
nadvornik
parents: 1208
diff changeset
157 if (!exif) return FALSE;
e2bbe90b0dcd most of the metadata options now works
nadvornik
parents: 1208
diff changeset
158
1224
ebfd305d902e improved sidecar writting
nadvornik
parents: 1222
diff changeset
159 success = (fd->change->dest) ? exif_write_sidecar(exif, fd->change->dest) : exif_write(exif); /* write modified metadata */
ebfd305d902e improved sidecar writting
nadvornik
parents: 1222
diff changeset
160 exif_free_fd(fd, exif);
1211
e2bbe90b0dcd most of the metadata options now works
nadvornik
parents: 1208
diff changeset
161
1255
71a75a53dde7 do not ignore newly created sidecars
nadvornik
parents: 1244
diff changeset
162 if (fd->change->dest)
71a75a53dde7 do not ignore newly created sidecars
nadvornik
parents: 1244
diff changeset
163 /* this will create a FileData for the sidecar and link it to the main file
71a75a53dde7 do not ignore newly created sidecars
nadvornik
parents: 1244
diff changeset
164 (we can't wait until the sidecar is discovered by directory scanning because
71a75a53dde7 do not ignore newly created sidecars
nadvornik
parents: 1244
diff changeset
165 exif_read_fd is called before that and it would read the main file only and
71a75a53dde7 do not ignore newly created sidecars
nadvornik
parents: 1244
diff changeset
166 store the metadata in the cache)
71a75a53dde7 do not ignore newly created sidecars
nadvornik
parents: 1244
diff changeset
167 FIXME: this does not catch new sidecars created by independent external programs
71a75a53dde7 do not ignore newly created sidecars
nadvornik
parents: 1244
diff changeset
168 */
71a75a53dde7 do not ignore newly created sidecars
nadvornik
parents: 1244
diff changeset
169 file_data_unref(file_data_new_simple(fd->change->dest));
71a75a53dde7 do not ignore newly created sidecars
nadvornik
parents: 1244
diff changeset
170
1224
ebfd305d902e improved sidecar writting
nadvornik
parents: 1222
diff changeset
171 if (success) metadata_legacy_delete(fd, fd->change->dest);
ebfd305d902e improved sidecar writting
nadvornik
parents: 1222
diff changeset
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
5106f40597a3 fixed possible segfault
nadvornik
parents: 1241
diff changeset
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
46e4fda574dd improved buffering and notifications
nadvornik
parents: 1214
diff changeset
204 file_data_increment_version(fd);
1432
cf4029d10d38 improved notification system
nadvornik
parents: 1429
diff changeset
205 file_data_send_notification(fd, NOTIFY_METADATA);
1218
46e4fda574dd improved buffering and notifications
nadvornik
parents: 1214
diff changeset
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
b106af9689db More gboolean.
zas_
parents: 1432
diff changeset
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
b106af9689db More gboolean.
zas_
parents: 1432
diff changeset
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
b106af9689db More gboolean.
zas_
parents: 1432
diff changeset
273 gboolean success = FALSE;
b106af9689db More gboolean.
zas_
parents: 1432
diff changeset
274 gchar *metadata_pathl;
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
275
1224
ebfd305d902e improved sidecar writting
nadvornik
parents: 1222
diff changeset
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
ebfd305d902e improved sidecar writting
nadvornik
parents: 1222
diff changeset
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
ebfd305d902e improved sidecar writting
nadvornik
parents: 1222
diff changeset
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
ebfd305d902e improved sidecar writting
nadvornik
parents: 1222
diff changeset
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
ebfd305d902e improved sidecar writting
nadvornik
parents: 1222
diff changeset
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
b106af9689db More gboolean.
zas_
parents: 1432
diff changeset
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
ebfd305d902e improved sidecar writting
nadvornik
parents: 1222
diff changeset
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
ebfd305d902e improved sidecar writting
nadvornik
parents: 1222
diff changeset
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
ebfd305d902e improved sidecar writting
nadvornik
parents: 1222
diff changeset
390 if (metadata_path && (!except || strcmp(metadata_path, except) != 0))
ebfd305d902e improved sidecar writting
nadvornik
parents: 1222
diff changeset
391 {
ebfd305d902e improved sidecar writting
nadvornik
parents: 1222
diff changeset
392 metadata_pathl = path_from_utf8(metadata_path);
ebfd305d902e improved sidecar writting
nadvornik
parents: 1222
diff changeset
393 unlink(metadata_pathl);
ebfd305d902e improved sidecar writting
nadvornik
parents: 1222
diff changeset
394 g_free(metadata_pathl);
ebfd305d902e improved sidecar writting
nadvornik
parents: 1222
diff changeset
395 g_free(metadata_path);
ebfd305d902e improved sidecar writting
nadvornik
parents: 1222
diff changeset
396 }
ebfd305d902e improved sidecar writting
nadvornik
parents: 1222
diff changeset
397 metadata_path = cache_find_location(CACHE_TYPE_XMP_METADATA, fd->path);
ebfd305d902e improved sidecar writting
nadvornik
parents: 1222
diff changeset
398 if (metadata_path && (!except || strcmp(metadata_path, except) != 0))
ebfd305d902e improved sidecar writting
nadvornik
parents: 1222
diff changeset
399 {
ebfd305d902e improved sidecar writting
nadvornik
parents: 1222
diff changeset
400 metadata_pathl = path_from_utf8(metadata_path);
ebfd305d902e improved sidecar writting
nadvornik
parents: 1222
diff changeset
401 unlink(metadata_pathl);
ebfd305d902e improved sidecar writting
nadvornik
parents: 1222
diff changeset
402 g_free(metadata_pathl);
ebfd305d902e improved sidecar writting
nadvornik
parents: 1222
diff changeset
403 g_free(metadata_path);
ebfd305d902e improved sidecar writting
nadvornik
parents: 1222
diff changeset
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
b106af9689db More gboolean.
zas_
parents: 1432
diff changeset
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
b106af9689db More gboolean.
zas_
parents: 1432
diff changeset
411 gboolean success = FALSE;
b106af9689db More gboolean.
zas_
parents: 1432
diff changeset
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
10073464e6aa use metadata_read_* functions where possible
nadvornik
parents: 1284
diff changeset
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
10073464e6aa use metadata_read_* functions where possible
nadvornik
parents: 1284
diff changeset
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
1e2737565cb7 Cleanup.
zas_
parents: 1487
diff changeset
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
1e2737565cb7 Cleanup.
zas_
parents: 1487
diff changeset
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
10073464e6aa use metadata_read_* functions where possible
nadvornik
parents: 1284
diff changeset
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
10073464e6aa use metadata_read_* functions where possible
nadvornik
parents: 1284
diff changeset
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
10073464e6aa use metadata_read_* functions where possible
nadvornik
parents: 1284
diff changeset
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
10073464e6aa use metadata_read_* functions where possible
nadvornik
parents: 1284
diff changeset
505
10073464e6aa use metadata_read_* functions where possible
nadvornik
parents: 1284
diff changeset
506 guint64 metadata_read_int(FileData *fd, const gchar *key, guint64 fallback)
10073464e6aa use metadata_read_* functions where possible
nadvornik
parents: 1284
diff changeset
507 {
10073464e6aa use metadata_read_* functions where possible
nadvornik
parents: 1284
diff changeset
508 guint64 ret;
10073464e6aa use metadata_read_* functions where possible
nadvornik
parents: 1284
diff changeset
509 gchar *endptr;
10073464e6aa use metadata_read_* functions where possible
nadvornik
parents: 1284
diff changeset
510 gchar *string = metadata_read_string(fd, key, METADATA_PLAIN);
10073464e6aa use metadata_read_* functions where possible
nadvornik
parents: 1284
diff changeset
511 if (!string) return fallback;
10073464e6aa use metadata_read_* functions where possible
nadvornik
parents: 1284
diff changeset
512
10073464e6aa use metadata_read_* functions where possible
nadvornik
parents: 1284
diff changeset
513 ret = g_ascii_strtoull(string, &endptr, 10);
10073464e6aa use metadata_read_* functions where possible
nadvornik
parents: 1284
diff changeset
514 if (string == endptr) ret = fallback;
10073464e6aa use metadata_read_* functions where possible
nadvornik
parents: 1284
diff changeset
515 g_free(string);
10073464e6aa use metadata_read_* functions where possible
nadvornik
parents: 1284
diff changeset
516 return ret;
10073464e6aa use metadata_read_* functions where possible
nadvornik
parents: 1284
diff changeset
517 }
1238
947e603a52c6 simplified metadata interface, dropped metadata_read,
nadvornik
parents: 1234
diff changeset
518
947e603a52c6 simplified metadata interface, dropped metadata_read,
nadvornik
parents: 1234
diff changeset
519 gboolean metadata_append_string(FileData *fd, const gchar *key, const char *value)
947e603a52c6 simplified metadata interface, dropped metadata_read,
nadvornik
parents: 1234
diff changeset
520 {
1288
10073464e6aa use metadata_read_* functions where possible
nadvornik
parents: 1284
diff changeset
521 gchar *str = metadata_read_string(fd, key, METADATA_PLAIN);
1238
947e603a52c6 simplified metadata interface, dropped metadata_read,
nadvornik
parents: 1234
diff changeset
522
947e603a52c6 simplified metadata interface, dropped metadata_read,
nadvornik
parents: 1234
diff changeset
523 if (!str)
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
524 {
1238
947e603a52c6 simplified metadata interface, dropped metadata_read,
nadvornik
parents: 1234
diff changeset
525 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
526 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
527 else
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
528 {
1238
947e603a52c6 simplified metadata interface, dropped metadata_read,
nadvornik
parents: 1234
diff changeset
529 gchar *new_string = g_strconcat(str, value, NULL);
947e603a52c6 simplified metadata interface, dropped metadata_read,
nadvornik
parents: 1234
diff changeset
530 gboolean ret = metadata_write_string(fd, key, new_string);
947e603a52c6 simplified metadata interface, dropped metadata_read,
nadvornik
parents: 1234
diff changeset
531 g_free(str);
947e603a52c6 simplified metadata interface, dropped metadata_read,
nadvornik
parents: 1234
diff changeset
532 g_free(new_string);
947e603a52c6 simplified metadata interface, dropped metadata_read,
nadvornik
parents: 1234
diff changeset
533 return ret;
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
534 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
535 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
536
1238
947e603a52c6 simplified metadata interface, dropped metadata_read,
nadvornik
parents: 1234
diff changeset
537 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
538 {
1288
10073464e6aa use metadata_read_* functions where possible
nadvornik
parents: 1284
diff changeset
539 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
540
1238
947e603a52c6 simplified metadata interface, dropped metadata_read,
nadvornik
parents: 1234
diff changeset
541 if (!list)
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
542 {
1238
947e603a52c6 simplified metadata interface, dropped metadata_read,
nadvornik
parents: 1234
diff changeset
543 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
544 }
1238
947e603a52c6 simplified metadata interface, dropped metadata_read,
nadvornik
parents: 1234
diff changeset
545 else
947e603a52c6 simplified metadata interface, dropped metadata_read,
nadvornik
parents: 1234
diff changeset
546 {
947e603a52c6 simplified metadata interface, dropped metadata_read,
nadvornik
parents: 1234
diff changeset
547 gboolean ret;
947e603a52c6 simplified metadata interface, dropped metadata_read,
nadvornik
parents: 1234
diff changeset
548 list = g_list_concat(list, string_list_copy(values));
947e603a52c6 simplified metadata interface, dropped metadata_read,
nadvornik
parents: 1234
diff changeset
549 list = remove_duplicate_strings_from_list(list);
947e603a52c6 simplified metadata interface, dropped metadata_read,
nadvornik
parents: 1234
diff changeset
550
947e603a52c6 simplified metadata interface, dropped metadata_read,
nadvornik
parents: 1234
diff changeset
551 ret = metadata_write_list(fd, key, list);
947e603a52c6 simplified metadata interface, dropped metadata_read,
nadvornik
parents: 1234
diff changeset
552 string_list_free(list);
947e603a52c6 simplified metadata interface, dropped metadata_read,
nadvornik
parents: 1234
diff changeset
553 return ret;
947e603a52c6 simplified metadata interface, dropped metadata_read,
nadvornik
parents: 1234
diff changeset
554 }
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
555 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
556
1340
361120a66609 Use g_utf8_casefold() to compare keywords, uppercased/lowercased keywords are now matched against predefined list.
zas_
parents: 1288
diff changeset
557 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
558 {
1340
361120a66609 Use g_utf8_casefold() to compare keywords, uppercased/lowercased keywords are now matched against predefined list.
zas_
parents: 1288
diff changeset
559 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
560
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
561 while (list)
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
562 {
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
563 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
564
361120a66609 Use g_utf8_casefold() to compare keywords, uppercased/lowercased keywords are now matched against predefined list.
zas_
parents: 1288
diff changeset
565 if (haystack)
361120a66609 Use g_utf8_casefold() to compare keywords, uppercased/lowercased keywords are now matched against predefined list.
zas_
parents: 1288
diff changeset
566 {
361120a66609 Use g_utf8_casefold() to compare keywords, uppercased/lowercased keywords are now matched against predefined list.
zas_
parents: 1288
diff changeset
567 gboolean equal;
361120a66609 Use g_utf8_casefold() to compare keywords, uppercased/lowercased keywords are now matched against predefined list.
zas_
parents: 1288
diff changeset
568 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
569
1340
361120a66609 Use g_utf8_casefold() to compare keywords, uppercased/lowercased keywords are now matched against predefined list.
zas_
parents: 1288
diff changeset
570 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
571 g_free(haystack_casefold);
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
572
1340
361120a66609 Use g_utf8_casefold() to compare keywords, uppercased/lowercased keywords are now matched against predefined list.
zas_
parents: 1288
diff changeset
573 if (equal)
361120a66609 Use g_utf8_casefold() to compare keywords, uppercased/lowercased keywords are now matched against predefined list.
zas_
parents: 1288
diff changeset
574 {
361120a66609 Use g_utf8_casefold() to compare keywords, uppercased/lowercased keywords are now matched against predefined list.
zas_
parents: 1288
diff changeset
575 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
576 return haystack;
361120a66609 Use g_utf8_casefold() to compare keywords, uppercased/lowercased keywords are now matched against predefined list.
zas_
parents: 1288
diff changeset
577 }
361120a66609 Use g_utf8_casefold() to compare keywords, uppercased/lowercased keywords are now matched against predefined list.
zas_
parents: 1288
diff changeset
578 }
361120a66609 Use g_utf8_casefold() to compare keywords, uppercased/lowercased keywords are now matched against predefined list.
zas_
parents: 1288
diff changeset
579
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
580 list = list->next;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
581 }
1340
361120a66609 Use g_utf8_casefold() to compare keywords, uppercased/lowercased keywords are now matched against predefined list.
zas_
parents: 1288
diff changeset
582
361120a66609 Use g_utf8_casefold() to compare keywords, uppercased/lowercased keywords are now matched against predefined list.
zas_
parents: 1288
diff changeset
583 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
584 return NULL;
361120a66609 Use g_utf8_casefold() to compare keywords, uppercased/lowercased keywords are now matched against predefined list.
zas_
parents: 1288
diff changeset
585 }
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
586
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
587
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
588 #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
589
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
590 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
591 {
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
592 GList *list = NULL;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
593 const gchar *ptr = text;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
594
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
595 while (*ptr != '\0')
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
596 {
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
597 const gchar *begin;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
598 gint l = 0;
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 while (KEYWORDS_SEPARATOR(*ptr)) ptr++;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
601 begin = ptr;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
602 while (*ptr != '\0' && !KEYWORDS_SEPARATOR(*ptr))
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
603 {
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
604 ptr++;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
605 l++;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
606 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
607
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
608 /* trim starting and ending whitespaces */
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
609 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
610 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
611
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
612 if (l > 0)
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
613 {
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
614 gchar *keyword = g_strndup(begin, l);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
615
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
616 /* 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
617 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
618 list = g_list_append(list, keyword);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
619 else
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
620 g_free(keyword);
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
621 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
622 }
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 return list;
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
625 }
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
626
1222
31dc2f240afb low-level keyword-to-mark functionality
nadvornik
parents: 1220
diff changeset
627 /*
31dc2f240afb low-level keyword-to-mark functionality
nadvornik
parents: 1220
diff changeset
628 * keywords to marks
31dc2f240afb low-level keyword-to-mark functionality
nadvornik
parents: 1220
diff changeset
629 */
31dc2f240afb low-level keyword-to-mark functionality
nadvornik
parents: 1220
diff changeset
630
31dc2f240afb low-level keyword-to-mark functionality
nadvornik
parents: 1220
diff changeset
631
31dc2f240afb low-level keyword-to-mark functionality
nadvornik
parents: 1220
diff changeset
632 gboolean meta_data_get_keyword_mark(FileData *fd, gint n, gpointer data)
31dc2f240afb low-level keyword-to-mark functionality
nadvornik
parents: 1220
diff changeset
633 {
1425
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
634 /* FIXME: do not use global keyword_tree */
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
635 GList *path = data;
1222
31dc2f240afb low-level keyword-to-mark functionality
nadvornik
parents: 1220
diff changeset
636 GList *keywords;
31dc2f240afb low-level keyword-to-mark functionality
nadvornik
parents: 1220
diff changeset
637 gboolean found = FALSE;
1288
10073464e6aa use metadata_read_* functions where possible
nadvornik
parents: 1284
diff changeset
638 keywords = metadata_read_list(fd, KEYWORD_KEY, METADATA_PLAIN);
1238
947e603a52c6 simplified metadata interface, dropped metadata_read,
nadvornik
parents: 1234
diff changeset
639 if (keywords)
1222
31dc2f240afb low-level keyword-to-mark functionality
nadvornik
parents: 1220
diff changeset
640 {
1425
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
641 GtkTreeIter iter;
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
642 if (keyword_tree_get_iter(GTK_TREE_MODEL(keyword_tree), &iter, path) &&
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
643 keyword_tree_is_set(GTK_TREE_MODEL(keyword_tree), &iter, keywords))
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
644 found = TRUE;
1222
31dc2f240afb low-level keyword-to-mark functionality
nadvornik
parents: 1220
diff changeset
645
31dc2f240afb low-level keyword-to-mark functionality
nadvornik
parents: 1220
diff changeset
646 }
31dc2f240afb low-level keyword-to-mark functionality
nadvornik
parents: 1220
diff changeset
647 return found;
31dc2f240afb low-level keyword-to-mark functionality
nadvornik
parents: 1220
diff changeset
648 }
31dc2f240afb low-level keyword-to-mark functionality
nadvornik
parents: 1220
diff changeset
649
31dc2f240afb low-level keyword-to-mark functionality
nadvornik
parents: 1220
diff changeset
650 gboolean meta_data_set_keyword_mark(FileData *fd, gint n, gboolean value, gpointer data)
31dc2f240afb low-level keyword-to-mark functionality
nadvornik
parents: 1220
diff changeset
651 {
1425
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
652 GList *path = data;
1222
31dc2f240afb low-level keyword-to-mark functionality
nadvornik
parents: 1220
diff changeset
653 GList *keywords = NULL;
1425
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
654 GtkTreeIter iter;
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
655
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
656 if (!keyword_tree_get_iter(GTK_TREE_MODEL(keyword_tree), &iter, path)) return FALSE;
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
657
1288
10073464e6aa use metadata_read_* functions where possible
nadvornik
parents: 1284
diff changeset
658 keywords = metadata_read_list(fd, KEYWORD_KEY, METADATA_PLAIN);
1222
31dc2f240afb low-level keyword-to-mark functionality
nadvornik
parents: 1220
diff changeset
659
1425
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
660 if (!!keyword_tree_is_set(GTK_TREE_MODEL(keyword_tree), &iter, keywords) != !!value)
1222
31dc2f240afb low-level keyword-to-mark functionality
nadvornik
parents: 1220
diff changeset
661 {
1425
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
662 if (value)
1222
31dc2f240afb low-level keyword-to-mark functionality
nadvornik
parents: 1220
diff changeset
663 {
1425
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
664 keyword_tree_set(GTK_TREE_MODEL(keyword_tree), &iter, &keywords);
1222
31dc2f240afb low-level keyword-to-mark functionality
nadvornik
parents: 1220
diff changeset
665 }
1425
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
666 else
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
667 {
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
668 keyword_tree_reset(GTK_TREE_MODEL(keyword_tree), &iter, &keywords);
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
669 }
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
670 metadata_write_list(fd, KEYWORD_KEY, keywords);
1222
31dc2f240afb low-level keyword-to-mark functionality
nadvornik
parents: 1220
diff changeset
671 }
31dc2f240afb low-level keyword-to-mark functionality
nadvornik
parents: 1220
diff changeset
672
31dc2f240afb low-level keyword-to-mark functionality
nadvornik
parents: 1220
diff changeset
673 string_list_free(keywords);
31dc2f240afb low-level keyword-to-mark functionality
nadvornik
parents: 1220
diff changeset
674 return TRUE;
31dc2f240afb low-level keyword-to-mark functionality
nadvornik
parents: 1220
diff changeset
675 }
31dc2f240afb low-level keyword-to-mark functionality
nadvornik
parents: 1220
diff changeset
676
1425
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
677
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
678
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
679 void meta_data_connect_mark_with_keyword(GtkTreeModel *keyword_tree, GtkTreeIter *kw_iter, gint mark)
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
680 {
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
681
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
682 FileDataGetMarkFunc get_mark_func;
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
683 FileDataSetMarkFunc set_mark_func;
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
684 gpointer mark_func_data;
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
685
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
686 gint i;
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
687
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
688 for (i = 0; i < FILEDATA_MARKS_SIZE; i++)
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
689 {
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
690 file_data_get_registered_mark_func(i, &get_mark_func, &set_mark_func, &mark_func_data);
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
691 if (get_mark_func == meta_data_get_keyword_mark)
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
692 {
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
693 GtkTreeIter old_kw_iter;
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
694 GList *old_path = mark_func_data;
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
695
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
696 if (keyword_tree_get_iter(keyword_tree, &old_kw_iter, old_path) &&
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
697 (i == mark || /* release any previous connection of given mark */
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
698 keyword_compare(keyword_tree, &old_kw_iter, kw_iter) == 0)) /* or given keyword */
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
699 {
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
700 file_data_register_mark_func(i, NULL, NULL, NULL, NULL);
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
701 gtk_tree_store_set(GTK_TREE_STORE(keyword_tree), &old_kw_iter, KEYWORD_COLUMN_MARK, "", -1);
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
702 }
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
703 }
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
704 }
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
705
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
706
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
707 if (mark >= 0 && mark < FILEDATA_MARKS_SIZE)
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
708 {
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
709 GList *path;
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
710 gchar *mark_str;
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
711 path = keyword_tree_get_path(keyword_tree, kw_iter);
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
712 file_data_register_mark_func(mark, meta_data_get_keyword_mark, meta_data_set_keyword_mark, path, (GDestroyNotify)string_list_free);
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
713
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
714 mark_str = g_strdup_printf("%d", mark + 1);
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
715 gtk_tree_store_set(GTK_TREE_STORE(keyword_tree), kw_iter, KEYWORD_COLUMN_MARK, mark_str, -1);
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
716 g_free(mark_str);
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
717 }
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
718 }
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
719
80462be81410 fixed keyword to mark connection
nadvornik
parents: 1414
diff changeset
720
1391
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
721 /*
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
722 *-------------------------------------------------------------------
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
723 * keyword tree
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
724 *-------------------------------------------------------------------
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
725 */
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
726
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
727
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
728
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
729 GtkTreeStore *keyword_tree;
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
730
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
731 gchar *keyword_get_name(GtkTreeModel *keyword_tree, GtkTreeIter *iter)
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
732 {
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
733 gchar *name;
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
734 gtk_tree_model_get(keyword_tree, iter, KEYWORD_COLUMN_NAME, &name, -1);
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
735 return name;
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
736 }
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
737
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
738 gchar *keyword_get_casefold(GtkTreeModel *keyword_tree, GtkTreeIter *iter)
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
739 {
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
740 gchar *casefold;
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
741 gtk_tree_model_get(keyword_tree, iter, KEYWORD_COLUMN_CASEFOLD, &casefold, -1);
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
742 return casefold;
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
743 }
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
744
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
745 gboolean keyword_get_is_keyword(GtkTreeModel *keyword_tree, GtkTreeIter *iter)
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
746 {
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
747 gboolean is_keyword;
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
748 gtk_tree_model_get(keyword_tree, iter, KEYWORD_COLUMN_IS_KEYWORD, &is_keyword, -1);
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
749 return is_keyword;
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
750 }
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
751
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
752 void keyword_set(GtkTreeStore *keyword_tree, GtkTreeIter *iter, const gchar *name, gboolean is_keyword)
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
753 {
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
754 gchar *casefold = g_utf8_casefold(name, -1);
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
755 gtk_tree_store_set(keyword_tree, iter, KEYWORD_COLUMN_MARK, "",
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
756 KEYWORD_COLUMN_NAME, name,
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
757 KEYWORD_COLUMN_CASEFOLD, casefold,
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
758 KEYWORD_COLUMN_IS_KEYWORD, is_keyword, -1);
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
759 g_free(casefold);
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
760 }
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
761
1396
58f0b4586c8c dnd fixes
nadvornik
parents: 1392
diff changeset
762 gboolean keyword_compare(GtkTreeModel *keyword_tree, GtkTreeIter *a, GtkTreeIter *b)
58f0b4586c8c dnd fixes
nadvornik
parents: 1392
diff changeset
763 {
58f0b4586c8c dnd fixes
nadvornik
parents: 1392
diff changeset
764 GtkTreePath *pa = gtk_tree_model_get_path(keyword_tree, a);
58f0b4586c8c dnd fixes
nadvornik
parents: 1392
diff changeset
765 GtkTreePath *pb = gtk_tree_model_get_path(keyword_tree, b);
58f0b4586c8c dnd fixes
nadvornik
parents: 1392
diff changeset
766 gint ret = gtk_tree_path_compare(pa, pb);
58f0b4586c8c dnd fixes
nadvornik
parents: 1392
diff changeset
767 gtk_tree_path_free(pa);
58f0b4586c8c dnd fixes
nadvornik
parents: 1392
diff changeset
768 gtk_tree_path_free(pb);
58f0b4586c8c dnd fixes
nadvornik
parents: 1392
diff changeset
769 return ret;
58f0b4586c8c dnd fixes
nadvornik
parents: 1392
diff changeset
770 }
58f0b4586c8c dnd fixes
nadvornik
parents: 1392
diff changeset
771
1429
985366bccfb8 do not allow to add keywords with the same name as siblings
nadvornik
parents: 1428
diff changeset
772 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
773 {
985366bccfb8 do not allow to add keywords with the same name as siblings
nadvornik
parents: 1428
diff changeset
774 GtkTreeIter parent_a;
985366bccfb8 do not allow to add keywords with the same name as siblings
nadvornik
parents: 1428
diff changeset
775 GtkTreeIter parent_b;
985366bccfb8 do not allow to add keywords with the same name as siblings
nadvornik
parents: 1428
diff changeset
776
985366bccfb8 do not allow to add keywords with the same name as siblings
nadvornik
parents: 1428
diff changeset
777 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
778 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
779
985366bccfb8 do not allow to add keywords with the same name as siblings
nadvornik
parents: 1428
diff changeset
780 if (valid_pa && valid_pb)
985366bccfb8 do not allow to add keywords with the same name as siblings
nadvornik
parents: 1428
diff changeset
781 {
985366bccfb8 do not allow to add keywords with the same name as siblings
nadvornik
parents: 1428
diff changeset
782 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
783 }
985366bccfb8 do not allow to add keywords with the same name as siblings
nadvornik
parents: 1428
diff changeset
784 else
985366bccfb8 do not allow to add keywords with the same name as siblings
nadvornik
parents: 1428
diff changeset
785 {
985366bccfb8 do not allow to add keywords with the same name as siblings
nadvornik
parents: 1428
diff changeset
786 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
787 }
985366bccfb8 do not allow to add keywords with the same name as siblings
nadvornik
parents: 1428
diff changeset
788 }
985366bccfb8 do not allow to add keywords with the same name as siblings
nadvornik
parents: 1428
diff changeset
789
1465
400ecfc3d8b1 do not add duplicate keywords from config file
nadvornik
parents: 1464
diff changeset
790 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
791 {
985366bccfb8 do not allow to add keywords with the same name as siblings
nadvornik
parents: 1428
diff changeset
792 GtkTreeIter parent;
985366bccfb8 do not allow to add keywords with the same name as siblings
nadvornik
parents: 1428
diff changeset
793 GtkTreeIter iter;
985366bccfb8 do not allow to add keywords with the same name as siblings
nadvornik
parents: 1428
diff changeset
794 gboolean toplevel = FALSE;
985366bccfb8 do not allow to add keywords with the same name as siblings
nadvornik
parents: 1428
diff changeset
795 gboolean ret;
985366bccfb8 do not allow to add keywords with the same name as siblings
nadvornik
parents: 1428
diff changeset
796 gchar *casefold;
985366bccfb8 do not allow to add keywords with the same name as siblings
nadvornik
parents: 1428
diff changeset
797
985366bccfb8 do not allow to add keywords with the same name as siblings
nadvornik
parents: 1428
diff changeset
798 if (parent_ptr)
985366bccfb8 do not allow to add keywords with the same name as siblings
nadvornik
parents: 1428
diff changeset
799 {
985366bccfb8 do not allow to add keywords with the same name as siblings
nadvornik
parents: 1428
diff changeset
800 parent = *parent_ptr;
985366bccfb8 do not allow to add keywords with the same name as siblings
nadvornik
parents: 1428
diff changeset
801 }
985366bccfb8 do not allow to add keywords with the same name as siblings
nadvornik
parents: 1428
diff changeset
802 else if (sibling)
985366bccfb8 do not allow to add keywords with the same name as siblings
nadvornik
parents: 1428
diff changeset
803 {
985366bccfb8 do not allow to add keywords with the same name as siblings
nadvornik
parents: 1428
diff changeset
804 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
805 }
985366bccfb8 do not allow to add keywords with the same name as siblings
nadvornik
parents: 1428
diff changeset
806 else
985366bccfb8 do not allow to add keywords with the same name as siblings
nadvornik
parents: 1428
diff changeset
807 {
985366bccfb8 do not allow to add keywords with the same name as siblings
nadvornik
parents: 1428
diff changeset
808 toplevel = TRUE;
985366bccfb8 do not allow to add keywords with the same name as siblings
nadvornik
parents: 1428
diff changeset
809 }
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 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
812
985366bccfb8 do not allow to add keywords with the same name as siblings
nadvornik
parents: 1428
diff changeset
813 casefold = g_utf8_casefold(name, -1);
985366bccfb8 do not allow to add keywords with the same name as siblings
nadvornik
parents: 1428
diff changeset
814 ret = FALSE;
985366bccfb8 do not allow to add keywords with the same name as siblings
nadvornik
parents: 1428
diff changeset
815
985366bccfb8 do not allow to add keywords with the same name as siblings
nadvornik
parents: 1428
diff changeset
816 while (TRUE)
985366bccfb8 do not allow to add keywords with the same name as siblings
nadvornik
parents: 1428
diff changeset
817 {
985366bccfb8 do not allow to add keywords with the same name as siblings
nadvornik
parents: 1428
diff changeset
818 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
819 {
985366bccfb8 do not allow to add keywords with the same name as siblings
nadvornik
parents: 1428
diff changeset
820 gchar *iter_casefold = keyword_get_casefold(keyword_tree, &iter);
985366bccfb8 do not allow to add keywords with the same name as siblings
nadvornik
parents: 1428
diff changeset
821 ret = strcmp(casefold, iter_casefold) == 0;
985366bccfb8 do not allow to add keywords with the same name as siblings
nadvornik
parents: 1428
diff changeset
822 g_free(iter_casefold);
985366bccfb8 do not allow to add keywords with the same name as siblings
nadvornik
parents: 1428
diff changeset
823 }
1465
400ecfc3d8b1 do not add duplicate keywords from config file
nadvornik
parents: 1464
diff changeset
824 if (ret)
400ecfc3d8b1 do not add duplicate keywords from config file
nadvornik
parents: 1464
diff changeset
825 {
400ecfc3d8b1 do not add duplicate keywords from config file
nadvornik
parents: 1464
diff changeset
826 if (result) *result = iter;
400ecfc3d8b1 do not add duplicate keywords from config file
nadvornik
parents: 1464
diff changeset
827 break;
400ecfc3d8b1 do not add duplicate keywords from config file
nadvornik
parents: 1464
diff changeset
828 }
1429
985366bccfb8 do not allow to add keywords with the same name as siblings
nadvornik
parents: 1428
diff changeset
829 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
830 }
985366bccfb8 do not allow to add keywords with the same name as siblings
nadvornik
parents: 1428
diff changeset
831 g_free(casefold);
985366bccfb8 do not allow to add keywords with the same name as siblings
nadvornik
parents: 1428
diff changeset
832 return ret;
985366bccfb8 do not allow to add keywords with the same name as siblings
nadvornik
parents: 1428
diff changeset
833 }
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
1392
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
836 void keyword_copy(GtkTreeStore *keyword_tree, GtkTreeIter *to, GtkTreeIter *from)
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
837 {
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
838
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
839 gchar *mark, *name, *casefold;
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
840 gboolean is_keyword;
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
841
1428
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
842 /* do not copy KEYWORD_COLUMN_HIDE_IN, it fully shows the new subtree */
1392
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
843 gtk_tree_model_get(GTK_TREE_MODEL(keyword_tree), from, KEYWORD_COLUMN_MARK, &mark,
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
844 KEYWORD_COLUMN_NAME, &name,
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
845 KEYWORD_COLUMN_CASEFOLD, &casefold,
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
846 KEYWORD_COLUMN_IS_KEYWORD, &is_keyword, -1);
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
847
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
848 gtk_tree_store_set(keyword_tree, to, KEYWORD_COLUMN_MARK, mark,
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
849 KEYWORD_COLUMN_NAME, name,
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
850 KEYWORD_COLUMN_CASEFOLD, casefold,
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
851 KEYWORD_COLUMN_IS_KEYWORD, is_keyword, -1);
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
852 g_free(mark);
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
853 g_free(name);
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
854 g_free(casefold);
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
855 }
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
856
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
857 void keyword_copy_recursive(GtkTreeStore *keyword_tree, GtkTreeIter *to, GtkTreeIter *from)
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
858 {
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
859 GtkTreeIter from_child;
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
860
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
861 keyword_copy(keyword_tree, to, from);
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
862
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
863 if (!gtk_tree_model_iter_children(GTK_TREE_MODEL(keyword_tree), &from_child, from)) return;
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
864
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
865 while (TRUE)
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
866 {
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
867 GtkTreeIter to_child;
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
868 gtk_tree_store_append(keyword_tree, &to_child, to);
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
869 keyword_copy_recursive(keyword_tree, &to_child, &from_child);
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
870 if (!gtk_tree_model_iter_next(GTK_TREE_MODEL(keyword_tree), &from_child)) return;
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
871 }
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
872 }
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
873
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
874 void keyword_move_recursive(GtkTreeStore *keyword_tree, GtkTreeIter *to, GtkTreeIter *from)
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
875 {
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
876 keyword_copy_recursive(keyword_tree, to, from);
1428
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
877 keyword_delete(keyword_tree, from);
1392
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
878 }
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
879
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
880 GList *keyword_tree_get_path(GtkTreeModel *keyword_tree, GtkTreeIter *iter_ptr)
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
881 {
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
882 GList *path = NULL;
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
883 GtkTreeIter iter = *iter_ptr;
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
884
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
885 while (TRUE)
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
886 {
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
887 GtkTreeIter parent;
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
888 path = g_list_prepend(path, keyword_get_name(keyword_tree, &iter));
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
889 if (!gtk_tree_model_iter_parent(keyword_tree, &parent, &iter)) break;
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
890 iter = parent;
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
891 }
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
892 return path;
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
893 }
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
894
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
895 gboolean keyword_tree_get_iter(GtkTreeModel *keyword_tree, GtkTreeIter *iter_ptr, GList *path)
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
896 {
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
897 GtkTreeIter iter;
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
898
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
899 if (!gtk_tree_model_get_iter_first(keyword_tree, &iter)) return FALSE;
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
900
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
901 while (TRUE)
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
902 {
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
903 GtkTreeIter children;
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
904 while (TRUE)
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
905 {
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
906 gchar *name = keyword_get_name(keyword_tree, &iter);
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
907 if (strcmp(name, path->data) == 0) break;
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
908 g_free(name);
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
909 if (!gtk_tree_model_iter_next(keyword_tree, &iter)) return FALSE;
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
910 }
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
911 path = path->next;
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
912 if (!path)
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
913 {
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
914 *iter_ptr = iter;
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
915 return TRUE;
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
916 }
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
917
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
918 if (!gtk_tree_model_iter_children(keyword_tree, &children, &iter)) return FALSE;
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
919 iter = children;
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
920 }
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
921 }
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
922
d1b32a69b40a dnd in keywords tree
nadvornik
parents: 1391
diff changeset
923
1391
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
924 static gboolean keyword_tree_is_set_casefold(GtkTreeModel *keyword_tree, GtkTreeIter iter, GList *casefold_list)
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
925 {
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
926 if (!casefold_list) return FALSE;
1456
b24391991f7f improved expanding and hiding of helper keywords
nadvornik
parents: 1434
diff changeset
927
b24391991f7f improved expanding and hiding of helper keywords
nadvornik
parents: 1434
diff changeset
928 if (!keyword_get_is_keyword(keyword_tree, &iter))
b24391991f7f improved expanding and hiding of helper keywords
nadvornik
parents: 1434
diff changeset
929 {
b24391991f7f improved expanding and hiding of helper keywords
nadvornik
parents: 1434
diff changeset
930 /* 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
931 GtkTreeIter child;
b24391991f7f improved expanding and hiding of helper keywords
nadvornik
parents: 1434
diff changeset
932 if (!gtk_tree_model_iter_children(keyword_tree, &child, &iter))
b24391991f7f improved expanding and hiding of helper keywords
nadvornik
parents: 1434
diff changeset
933 return FALSE; /* this should happen only on empty helpers */
b24391991f7f improved expanding and hiding of helper keywords
nadvornik
parents: 1434
diff changeset
934
b24391991f7f improved expanding and hiding of helper keywords
nadvornik
parents: 1434
diff changeset
935 while (TRUE)
b24391991f7f improved expanding and hiding of helper keywords
nadvornik
parents: 1434
diff changeset
936 {
b24391991f7f improved expanding and hiding of helper keywords
nadvornik
parents: 1434
diff changeset
937 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
938 if (!gtk_tree_model_iter_next(keyword_tree, &child)) return FALSE;
b24391991f7f improved expanding and hiding of helper keywords
nadvornik
parents: 1434
diff changeset
939 }
b24391991f7f improved expanding and hiding of helper keywords
nadvornik
parents: 1434
diff changeset
940 }
1391
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
941
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
942 while (TRUE)
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
943 {
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
944 GtkTreeIter parent;
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
945
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
946 if (keyword_get_is_keyword(keyword_tree, &iter))
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
947 {
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
948 GList *work = casefold_list;
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
949 gboolean found = FALSE;
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
950 gchar *iter_casefold = keyword_get_casefold(keyword_tree, &iter);
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
951 while (work)
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
952 {
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
953 const gchar *casefold = work->data;
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
954 work = work->next;
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
955
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
956 if (strcmp(iter_casefold, casefold) == 0)
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
957 {
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
958 found = TRUE;
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
959 break;
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
960 }
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
961 }
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
962 g_free(iter_casefold);
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
963 if (!found) return FALSE;
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
964 }
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
965
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
966 if (!gtk_tree_model_iter_parent(keyword_tree, &parent, &iter)) return TRUE;
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
967 iter = parent;
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
968 }
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
969 }
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
970
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
971 gboolean keyword_tree_is_set(GtkTreeModel *keyword_tree, GtkTreeIter *iter, GList *kw_list)
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
972 {
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
973 gboolean ret;
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
974 GList *casefold_list = NULL;
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
975 GList *work;
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
976
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
977 work = kw_list;
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
978 while (work)
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
979 {
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
980 const gchar *kw = work->data;
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
981 work = work->next;
1428
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
982
1391
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
983 casefold_list = g_list_prepend(casefold_list, g_utf8_casefold(kw, -1));
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
984 }
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
985
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
986 ret = keyword_tree_is_set_casefold(keyword_tree, *iter, casefold_list);
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
987
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
988 string_list_free(casefold_list);
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
989 return ret;
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
990 }
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
991
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
992 void keyword_tree_set(GtkTreeModel *keyword_tree, GtkTreeIter *iter_ptr, GList **kw_list)
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
993 {
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
994 GtkTreeIter iter = *iter_ptr;
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
995 while (TRUE)
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
996 {
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
997 GtkTreeIter parent;
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
998
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
999 if (keyword_get_is_keyword(keyword_tree, &iter))
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1000 {
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1001 gchar *name = keyword_get_name(keyword_tree, &iter);
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1002 if (!find_string_in_list_utf8nocase(*kw_list, name))
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1003 {
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1004 *kw_list = g_list_append(*kw_list, name);
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1005 }
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1006 else
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1007 {
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1008 g_free(name);
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1009 }
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1010 }
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1011
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1012 if (!gtk_tree_model_iter_parent(keyword_tree, &parent, &iter)) return;
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1013 iter = parent;
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1014 }
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1015 }
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1016
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1017 static void keyword_tree_reset1(GtkTreeModel *keyword_tree, GtkTreeIter *iter, GList **kw_list)
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1018 {
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1019 gchar *found;
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1020 gchar *name;
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1021 if (!keyword_get_is_keyword(keyword_tree, iter)) return;
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1022
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1023 name = keyword_get_name(keyword_tree, iter);
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1024 found = find_string_in_list_utf8nocase(*kw_list, name);
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1025
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1026 if (found)
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1027 {
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1028 *kw_list = g_list_remove(*kw_list, found);
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1029 g_free(found);
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1030 }
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1031 g_free(name);
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1032 }
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1033
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1034 static void keyword_tree_reset_recursive(GtkTreeModel *keyword_tree, GtkTreeIter *iter, GList **kw_list)
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1035 {
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1036 GtkTreeIter child;
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1037 keyword_tree_reset1(keyword_tree, iter, kw_list);
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1038
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1039 if (!gtk_tree_model_iter_children(keyword_tree, &child, iter)) return;
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1040
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1041 while (TRUE)
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1042 {
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1043 keyword_tree_reset_recursive(keyword_tree, &child, kw_list);
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1044 if (!gtk_tree_model_iter_next(keyword_tree, &child)) return;
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1045 }
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1046 }
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1047
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1048 static gboolean keyword_tree_check_empty_children(GtkTreeModel *keyword_tree, GtkTreeIter *parent, GList *kw_list)
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1049 {
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1050 GtkTreeIter iter;
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1051
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1052 if (!gtk_tree_model_iter_children(keyword_tree, &iter, parent))
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1053 return TRUE; /* this should happen only on empty helpers */
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1054
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1055 while (TRUE)
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1056 {
1457
5c0ecb2ebbc5 simplified code
nadvornik
parents: 1456
diff changeset
1057 if (keyword_tree_is_set(keyword_tree, &iter, kw_list)) return FALSE;
5c0ecb2ebbc5 simplified code
nadvornik
parents: 1456
diff changeset
1058 if (!gtk_tree_model_iter_next(keyword_tree, &iter)) return TRUE;
1391
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1059 }
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1060 }
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1061
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1062 void keyword_tree_reset(GtkTreeModel *keyword_tree, GtkTreeIter *iter_ptr, GList **kw_list)
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1063 {
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1064 GtkTreeIter iter = *iter_ptr;
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1065 GtkTreeIter parent;
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1066 keyword_tree_reset_recursive(keyword_tree, &iter, kw_list);
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1067
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1068 if (!gtk_tree_model_iter_parent(keyword_tree, &parent, &iter)) return;
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1069 iter = parent;
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1070
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1071 while (keyword_tree_check_empty_children(keyword_tree, &iter, *kw_list))
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1072 {
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1073 GtkTreeIter parent;
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1074 keyword_tree_reset1(keyword_tree, &iter, kw_list);
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1075 if (!gtk_tree_model_iter_parent(keyword_tree, &parent, &iter)) return;
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1076 iter = parent;
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1077 }
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1078 }
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1079
1414
6ce1f7171d48 added a popup menu in keyword tree
nadvornik
parents: 1404
diff changeset
1080 void keyword_delete(GtkTreeStore *keyword_tree, GtkTreeIter *iter_ptr)
6ce1f7171d48 added a popup menu in keyword tree
nadvornik
parents: 1404
diff changeset
1081 {
1428
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1082 GList *list;
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1083 GtkTreeIter child;
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1084 while (gtk_tree_model_iter_children(GTK_TREE_MODEL(keyword_tree), &child, iter_ptr))
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1085 {
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1086 keyword_delete(keyword_tree, &child);
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1087 }
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1088
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1089 meta_data_connect_mark_with_keyword(GTK_TREE_MODEL(keyword_tree), iter_ptr, -1);
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1090
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1091 gtk_tree_model_get(GTK_TREE_MODEL(keyword_tree), iter_ptr, KEYWORD_COLUMN_HIDE_IN, &list, -1);
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1092 g_list_free(list);
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1093
1414
6ce1f7171d48 added a popup menu in keyword tree
nadvornik
parents: 1404
diff changeset
1094 gtk_tree_store_remove(keyword_tree, iter_ptr);
6ce1f7171d48 added a popup menu in keyword tree
nadvornik
parents: 1404
diff changeset
1095 }
6ce1f7171d48 added a popup menu in keyword tree
nadvornik
parents: 1404
diff changeset
1096
6ce1f7171d48 added a popup menu in keyword tree
nadvornik
parents: 1404
diff changeset
1097
1428
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1098 void keyword_hide_in(GtkTreeStore *keyword_tree, GtkTreeIter *iter, gpointer id)
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1099 {
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1100 GList *list;
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1101 gtk_tree_model_get(GTK_TREE_MODEL(keyword_tree), iter, KEYWORD_COLUMN_HIDE_IN, &list, -1);
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1102 if (!g_list_find(list, id))
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1103 {
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1104 list = g_list_prepend(list, id);
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1105 gtk_tree_store_set(keyword_tree, iter, KEYWORD_COLUMN_HIDE_IN, list, -1);
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1106 }
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1107 }
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1108
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1109 void keyword_show_in(GtkTreeStore *keyword_tree, GtkTreeIter *iter, gpointer id)
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1110 {
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1111 GList *list;
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1112 gtk_tree_model_get(GTK_TREE_MODEL(keyword_tree), iter, KEYWORD_COLUMN_HIDE_IN, &list, -1);
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1113 list = g_list_remove(list, id);
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1114 gtk_tree_store_set(keyword_tree, iter, KEYWORD_COLUMN_HIDE_IN, list, -1);
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1115 }
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1116
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1117 gboolean keyword_is_hidden_in(GtkTreeModel *keyword_tree, GtkTreeIter *iter, gpointer id)
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1118 {
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1119 GList *list;
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1120 gtk_tree_model_get(keyword_tree, iter, KEYWORD_COLUMN_HIDE_IN, &list, -1);
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1121 return !!g_list_find(list, id);
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1122 }
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1123
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1124 static gboolean keyword_show_all_in_cb(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1125 {
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1126 keyword_show_in(GTK_TREE_STORE(model), iter, data);
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1127 return FALSE;
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1128 }
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1129
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1130 void keyword_show_all_in(GtkTreeStore *keyword_tree, gpointer id)
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1131 {
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1132 gtk_tree_model_foreach(GTK_TREE_MODEL(keyword_tree), keyword_show_all_in_cb, id);
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1133 }
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1134
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1135 static void keyword_hide_unset_in_recursive(GtkTreeStore *keyword_tree, GtkTreeIter *iter_ptr, gpointer id, GList *keywords)
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1136 {
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1137 GtkTreeIter iter = *iter_ptr;
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1138 while (TRUE)
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1139 {
1456
b24391991f7f improved expanding and hiding of helper keywords
nadvornik
parents: 1434
diff changeset
1140 if (!keyword_tree_is_set(GTK_TREE_MODEL(keyword_tree), &iter, keywords))
1428
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1141 {
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1142 keyword_hide_in(keyword_tree, &iter, id);
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1143 /* no need to check children of hidden node */
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1144 }
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1145 else
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1146 {
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1147 GtkTreeIter child;
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1148 if (gtk_tree_model_iter_children(GTK_TREE_MODEL(keyword_tree), &child, &iter))
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1149 {
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1150 keyword_hide_unset_in_recursive(keyword_tree, &child, id, keywords);
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1151 }
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1152 }
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1153 if (!gtk_tree_model_iter_next(GTK_TREE_MODEL(keyword_tree), &iter)) return;
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1154 }
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1155 }
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1156
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1157 void keyword_hide_unset_in(GtkTreeStore *keyword_tree, gpointer id, GList *keywords)
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1158 {
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1159 GtkTreeIter iter;
1487
d6061c019ceb fixed possible crash
nadvornik
parents: 1483
diff changeset
1160 if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(keyword_tree), &iter)) return;
1428
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1161 keyword_hide_unset_in_recursive(keyword_tree, &iter, id, keywords);
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1162 }
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1163
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1164 static gboolean keyword_show_set_in_cb(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter_ptr, gpointer data)
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1165 {
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1166 GtkTreeIter iter = *iter_ptr;
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1167 GList *keywords = data;
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1168 gpointer id = keywords->data;
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1169 keywords = keywords->next; /* hack */
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1170 if (keyword_tree_is_set(model, &iter, keywords))
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1171 {
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1172 while (TRUE)
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1173 {
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1174 GtkTreeIter parent;
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1175 keyword_show_in(GTK_TREE_STORE(model), &iter, id);
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1176 if (!gtk_tree_model_iter_parent(GTK_TREE_MODEL(keyword_tree), &parent, &iter)) break;
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1177 iter = parent;
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1178 }
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1179 }
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1180 return FALSE;
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1181 }
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1182
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1183 void keyword_show_set_in(GtkTreeStore *keyword_tree, gpointer id, GList *keywords)
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1184 {
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1185 /* hack: pass id to keyword_hide_unset_in_cb in the list */
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1186 keywords = g_list_prepend(keywords, id);
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1187 gtk_tree_model_foreach(GTK_TREE_MODEL(keyword_tree), keyword_show_set_in_cb, keywords);
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1188 keywords = g_list_delete_link(keywords, keywords);
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1189 }
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1190
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1191
1404
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1192 void keyword_tree_new(void)
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1193 {
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1194 if (keyword_tree) return;
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1195
1428
3019f5d3a3c7 added keyword tree filtering
nadvornik
parents: 1425
diff changeset
1196 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
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1197 }
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1198
1391
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1199
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1200 void keyword_tree_new_default(void)
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1201 {
1404
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1202 if (keyword_tree) return;
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1203
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1204 keyword_tree_new();
1391
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1205
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1206 GtkTreeIter i1, i2, i3;
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1207
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1208 gtk_tree_store_append(keyword_tree, &i1, NULL);
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1209 keyword_set(keyword_tree, &i1, "animal", TRUE);
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1210
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1211 gtk_tree_store_append(keyword_tree, &i2, &i1);
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1212 keyword_set(keyword_tree, &i2, "mammal", TRUE);
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1213
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1214 gtk_tree_store_append(keyword_tree, &i3, &i2);
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1215 keyword_set(keyword_tree, &i3, "dog", TRUE);
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1216
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1217 gtk_tree_store_append(keyword_tree, &i3, &i2);
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1218 keyword_set(keyword_tree, &i3, "cat", TRUE);
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1219
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1220 gtk_tree_store_append(keyword_tree, &i2, &i1);
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1221 keyword_set(keyword_tree, &i2, "insect", TRUE);
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1222
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1223 gtk_tree_store_append(keyword_tree, &i3, &i2);
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1224 keyword_set(keyword_tree, &i3, "fly", TRUE);
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1225
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1226 gtk_tree_store_append(keyword_tree, &i3, &i2);
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1227 keyword_set(keyword_tree, &i3, "dragonfly", TRUE);
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1228
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1229 gtk_tree_store_append(keyword_tree, &i1, NULL);
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1230 keyword_set(keyword_tree, &i1, "daytime", FALSE);
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1231
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1232 gtk_tree_store_append(keyword_tree, &i2, &i1);
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1233 keyword_set(keyword_tree, &i2, "morning", TRUE);
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1234
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1235 gtk_tree_store_append(keyword_tree, &i2, &i1);
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1236 keyword_set(keyword_tree, &i2, "noon", TRUE);
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1237
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1238 }
9e0df7903581 implemented keywords editor as described at
nadvornik
parents: 1347
diff changeset
1239
1222
31dc2f240afb low-level keyword-to-mark functionality
nadvornik
parents: 1220
diff changeset
1240
1404
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1241 static void keyword_tree_node_write_config(GtkTreeModel *keyword_tree, GtkTreeIter *iter_ptr, GString *outstr, gint indent)
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1242 {
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1243 GtkTreeIter iter = *iter_ptr;
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1244 while (TRUE)
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1245 {
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1246 GtkTreeIter children;
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1247 gchar *name;
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1248
1461
e015b6573d36 improved config file formatting
nadvornik
parents: 1457
diff changeset
1249 WRITE_NL(); WRITE_STRING("<keyword ");
1404
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1250 name = keyword_get_name(keyword_tree, &iter);
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1251 write_char_option(outstr, indent, "name", name);
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1252 g_free(name);
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1253 write_bool_option(outstr, indent, "kw", keyword_get_is_keyword(keyword_tree, &iter));
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1254 if (gtk_tree_model_iter_children(keyword_tree, &children, &iter))
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1255 {
1461
e015b6573d36 improved config file formatting
nadvornik
parents: 1457
diff changeset
1256 WRITE_STRING(">");
e015b6573d36 improved config file formatting
nadvornik
parents: 1457
diff changeset
1257 indent++;
1404
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1258 keyword_tree_node_write_config(keyword_tree, &children, outstr, indent);
1461
e015b6573d36 improved config file formatting
nadvornik
parents: 1457
diff changeset
1259 indent--;
e015b6573d36 improved config file formatting
nadvornik
parents: 1457
diff changeset
1260 WRITE_NL(); WRITE_STRING("</keyword>");
1404
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1261 }
1461
e015b6573d36 improved config file formatting
nadvornik
parents: 1457
diff changeset
1262 else
e015b6573d36 improved config file formatting
nadvornik
parents: 1457
diff changeset
1263 {
e015b6573d36 improved config file formatting
nadvornik
parents: 1457
diff changeset
1264 WRITE_STRING("/>");
e015b6573d36 improved config file formatting
nadvornik
parents: 1457
diff changeset
1265 }
1404
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1266 if (!gtk_tree_model_iter_next(keyword_tree, &iter)) return;
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1267 }
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1268 }
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1269
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1270 void keyword_tree_write_config(GString *outstr, gint indent)
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1271 {
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1272 GtkTreeIter iter;
1461
e015b6573d36 improved config file formatting
nadvornik
parents: 1457
diff changeset
1273 WRITE_NL(); WRITE_STRING("<keyword_tree>");
1404
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1274 indent++;
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1275
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1276 if (keyword_tree && gtk_tree_model_get_iter_first(GTK_TREE_MODEL(keyword_tree), &iter))
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1277 {
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1278 keyword_tree_node_write_config(GTK_TREE_MODEL(keyword_tree), &iter, outstr, indent);
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1279 }
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1280 indent--;
1461
e015b6573d36 improved config file formatting
nadvornik
parents: 1457
diff changeset
1281 WRITE_NL(); WRITE_STRING("</keyword_tree>");
1404
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1282 }
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1283
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1284 GtkTreeIter *keyword_add_from_config(GtkTreeStore *keyword_tree, GtkTreeIter *parent, const gchar **attribute_names, const gchar **attribute_values)
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1285 {
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1286 gchar *name = NULL;
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1287 gboolean is_kw = TRUE;
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1288
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1289 while (*attribute_names)
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1290 {
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1291 const gchar *option = *attribute_names++;
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1292 const gchar *value = *attribute_values++;
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1293
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1294 if (READ_CHAR_FULL("name", name)) continue;
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1295 if (READ_BOOL_FULL("kw", is_kw)) continue;
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1296
1464
1b3751ac4743 be more verbose on parse errors
nadvornik
parents: 1461
diff changeset
1297 log_printf("unknown attribute %s = %s\n", option, value);
1404
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1298 }
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1299 if (name && name[0])
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1300 {
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1301 GtkTreeIter iter;
1465
400ecfc3d8b1 do not add duplicate keywords from config file
nadvornik
parents: 1464
diff changeset
1302 /* re-use existing keyword if any */
400ecfc3d8b1 do not add duplicate keywords from config file
nadvornik
parents: 1464
diff changeset
1303 if (!keyword_exists(GTK_TREE_MODEL(keyword_tree), parent, NULL, name, FALSE, &iter))
400ecfc3d8b1 do not add duplicate keywords from config file
nadvornik
parents: 1464
diff changeset
1304 {
400ecfc3d8b1 do not add duplicate keywords from config file
nadvornik
parents: 1464
diff changeset
1305 gtk_tree_store_append(keyword_tree, &iter, parent);
400ecfc3d8b1 do not add duplicate keywords from config file
nadvornik
parents: 1464
diff changeset
1306 }
1404
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1307 keyword_set(keyword_tree, &iter, name, is_kw);
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1308 g_free(name);
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1309 return gtk_tree_iter_copy(&iter);
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1310 }
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1311 g_free(name);
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1312 return NULL;
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1313 }
de06d83e1adc save and restore the keyword tree
nadvornik
parents: 1396
diff changeset
1314
1178
f6449c17306b Move comments/keywords read and write stuff to new metadata.{c,h}.
zas_
parents:
diff changeset
1315 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */