annotate src/metadata.c @ 1763:140b73f094c5

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