Mercurial > geeqie.yaz
annotate src/bar_info.c @ 204:d662d680250d
improved xmp vs. legacy metadata handling
author | nadvornik |
---|---|
date | Wed, 26 Mar 2008 08:00:46 +0000 |
parents | f6e307c7bad6 |
children | b932b6928e20 |
rev | line source |
---|---|
9 | 1 /* |
196 | 2 * Geeqie |
9 | 3 * (C) 2004 John Ellis |
4 * | |
5 * Author: John Ellis | |
6 * | |
7 * This software is released under the GNU General Public License (GNU GPL). | |
8 * Please read the included file COPYING for more information. | |
9 * This software comes with no warranty of any kind, use at your own risk! | |
10 */ | |
11 | |
12 | |
13 #include "gqview.h" | |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
14 #include "exif.h" |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
15 |
9 | 16 #include "bar_info.h" |
17 | |
18 #include "cache.h" | |
19 #include "filelist.h" | |
20 #include "info.h" | |
21 #include "utilops.h" | |
22 #include "ui_bookmark.h" | |
23 #include "ui_fileops.h" | |
24 #include "ui_misc.h" | |
25 #include "ui_utildlg.h" | |
26 | |
27 | |
28 #define BAR_KEYWORD_AUTOSAVE_TIME 10000 | |
29 | |
30 | |
31 static const gchar *keyword_favorite_defaults[] = { | |
32 N_("Favorite"), | |
33 N_("Todo"), | |
34 N_("People"), | |
35 N_("Places"), | |
36 N_("Art"), | |
37 N_("Nature"), | |
38 N_("Possessions"), | |
39 NULL | |
40 }; | |
41 | |
42 | |
43 static void bar_info_keyword_update_all(void); | |
44 | |
45 | |
46 /* | |
47 *------------------------------------------------------------------- | |
48 * keyword / comment utils | |
49 *------------------------------------------------------------------- | |
50 */ | |
51 | |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
52 static gint comment_file_write(gchar *path, GList *keywords, const gchar *comment) |
9 | 53 { |
54 FILE *f; | |
55 | |
56 f = fopen(path, "w"); | |
57 if (!f) return FALSE; | |
58 | |
196 | 59 fprintf(f, "#Geeqie comment (%s)\n\n", VERSION); |
9 | 60 |
61 fprintf(f, "[keywords]\n"); | |
62 while (keywords) | |
63 { | |
64 const gchar *word = keywords->data; | |
65 keywords = keywords->next; | |
66 | |
67 fprintf(f, "%s\n", word); | |
68 } | |
69 fprintf(f, "\n"); | |
70 | |
71 fprintf(f, "[comment]\n"); | |
72 fprintf(f, "%s\n", (comment) ? comment : ""); | |
73 | |
74 fprintf(f, "#end\n"); | |
75 | |
76 fclose(f); | |
77 | |
78 return TRUE; | |
79 } | |
80 | |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
81 static gint comment_legacy_write(FileData *fd, GList *keywords, const gchar *comment) |
9 | 82 { |
83 gchar *comment_path; | |
84 gint success = FALSE; | |
85 | |
86 /* If an existing metadata file exists, we will try writing to | |
87 * it's location regardless of the user's preference. | |
88 */ | |
138 | 89 comment_path = cache_find_location(CACHE_TYPE_METADATA, fd->path); |
9 | 90 if (comment_path && !access_file(comment_path, W_OK)) |
91 { | |
92 g_free(comment_path); | |
93 comment_path = NULL; | |
94 } | |
95 | |
96 if (!comment_path) | |
97 { | |
98 gchar *comment_dir; | |
99 mode_t mode = 0755; | |
100 | |
138 | 101 comment_dir = cache_get_location(CACHE_TYPE_METADATA, fd->path, FALSE, &mode); |
9 | 102 if (cache_ensure_dir_exists(comment_dir, mode)) |
103 { | |
138 | 104 comment_path = g_strconcat(comment_dir, "/", fd->name, |
9 | 105 GQVIEW_CACHE_EXT_METADATA, NULL); |
106 } | |
107 g_free(comment_dir); | |
108 } | |
109 | |
110 if (comment_path) | |
111 { | |
112 gchar *comment_pathl; | |
113 | |
114 if (debug) printf("Saving comment: %s\n", comment_path); | |
115 | |
116 comment_pathl = path_from_utf8(comment_path); | |
117 | |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
118 success = comment_file_write(comment_pathl, keywords, comment); |
9 | 119 |
120 g_free(comment_pathl); | |
121 g_free(comment_path); | |
122 } | |
123 | |
124 return success; | |
125 } | |
126 | |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
127 static gint comment_file_read(gchar *path, GList **keywords, gchar **comment) |
9 | 128 { |
129 FILE *f; | |
130 gchar s_buf[1024]; | |
131 gchar *key = NULL; | |
132 GList *list = NULL; | |
133 GString *comment_build = NULL; | |
134 | |
135 f = fopen(path, "r"); | |
136 if (!f) return FALSE; | |
137 | |
138 while (fgets(s_buf,sizeof(s_buf), f)) | |
139 { | |
140 if (s_buf[0]=='#') continue; | |
141 if (s_buf[0]=='[') | |
142 { | |
143 gint c = 0; | |
144 gchar *ptr = s_buf + 1; | |
145 | |
146 while(ptr[c] != ']' && ptr[c] != '\n' && ptr[c] != '\0') c++; | |
147 | |
148 g_free(key); | |
149 key = g_strndup(ptr, c); | |
150 } | |
151 else if (key) | |
152 { | |
153 gint newline = FALSE; | |
154 gchar *ptr = s_buf; | |
155 | |
156 while (*ptr != '\n' && *ptr != '\0') ptr++; | |
157 if (*ptr == '\n') | |
158 { | |
159 *ptr = '\0'; | |
160 newline = TRUE; | |
161 } | |
162 | |
163 if (strcasecmp(key, "keywords") == 0) | |
164 { | |
165 if (strlen(s_buf) > 0) list = g_list_prepend(list, g_strdup(s_buf)); | |
166 } | |
167 else if (strcasecmp(key, "comment") == 0) | |
168 { | |
169 if (!comment_build) comment_build = g_string_new(""); | |
170 g_string_append(comment_build, s_buf); | |
171 if (strlen(s_buf) > 0 && newline) g_string_append_c(comment_build, '\n'); | |
172 } | |
173 } | |
174 } | |
175 | |
176 fclose(f); | |
177 g_free(key); | |
178 | |
179 *keywords = g_list_reverse(list); | |
180 if (comment_build) | |
181 { | |
182 if (comment) *comment = g_strdup(comment_build->str); | |
183 g_string_free(comment_build, TRUE); | |
184 } | |
185 | |
186 return TRUE; | |
187 } | |
188 | |
204 | 189 static gint comment_delete_legacy(FileData *fd) |
190 { | |
191 gchar *comment_path; | |
192 gchar *comment_pathl; | |
193 gint success = FALSE; | |
194 if (!fd) return FALSE; | |
195 | |
196 comment_path = cache_find_location(CACHE_TYPE_METADATA, fd->path); | |
197 if (!comment_path) return FALSE; | |
198 | |
199 comment_pathl = path_from_utf8(comment_path); | |
200 | |
201 success = !unlink(comment_pathl); | |
202 | |
203 g_free(comment_pathl); | |
204 g_free(comment_path); | |
205 | |
206 return success; | |
207 } | |
208 | |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
209 static gint comment_legacy_read(FileData *fd, GList **keywords, gchar **comment) |
9 | 210 { |
211 gchar *comment_path; | |
212 gchar *comment_pathl; | |
213 gint success = FALSE; | |
138 | 214 if (!fd) return FALSE; |
9 | 215 |
138 | 216 comment_path = cache_find_location(CACHE_TYPE_METADATA, fd->path); |
9 | 217 if (!comment_path) return FALSE; |
218 | |
219 comment_pathl = path_from_utf8(comment_path); | |
220 | |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
221 success = comment_file_read(comment_pathl, keywords, comment); |
9 | 222 |
223 g_free(comment_pathl); | |
224 g_free(comment_path); | |
225 | |
226 return success; | |
227 } | |
228 | |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
229 gchar *comment_key = "Xmp.dc.description"; |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
230 gchar *keyword_key = "Xmp.dc.subject"; |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
231 |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
232 static gint comment_xmp_read(FileData *fd, GList **keywords, gchar **comment) |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
233 { |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
234 ExifData *exif = exif_read_fd(fd, FALSE); |
204 | 235 gint success; |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
236 if (!exif) return FALSE; |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
237 |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
238 if (comment) |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
239 { |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
240 ExifItem *item = exif_get_item(exif, comment_key); |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
241 *comment = exif_item_get_string(item, 0); |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
242 } |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
243 |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
244 if (keywords) |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
245 { |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
246 ExifItem *item = exif_get_item(exif, keyword_key); |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
247 int count = exif_item_get_elements(item); |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
248 int i = 0; |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
249 GList *work = NULL; |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
250 char *kw = NULL; |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
251 |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
252 while (i < count && (kw = exif_item_get_string(item, i++))) |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
253 { |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
254 work = g_list_append(work, (gpointer) kw); |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
255 } |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
256 |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
257 *keywords = work; |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
258 } |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
259 |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
260 exif_free(exif); |
204 | 261 |
262 success = *comment || *keywords; | |
263 | |
264 return success; | |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
265 } |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
266 |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
267 static gint comment_xmp_write(FileData *fd, GList *keywords, const gchar *comment) |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
268 { |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
269 gint success = FALSE; |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
270 GList *work = keywords; |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
271 ExifData *exif = exif_read_fd(fd, FALSE); |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
272 if (!exif) return FALSE; |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
273 |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
274 ExifItem *item = exif_get_item(exif, comment_key); |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
275 |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
276 if (item && !(comment && comment[0])) |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
277 { |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
278 exif_item_delete(exif, item); |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
279 item = NULL; |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
280 } |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
281 |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
282 if (!item && comment && comment[0]) item = exif_add_item(exif, comment_key); |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
283 if (item) exif_item_set_string(item, comment); |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
284 |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
285 |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
286 |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
287 while ((item = exif_get_item(exif, keyword_key))) |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
288 { |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
289 exif_item_delete(exif, item); |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
290 } |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
291 |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
292 if (work) |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
293 { |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
294 item = exif_add_item(exif, keyword_key); |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
295 |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
296 while (work) |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
297 { |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
298 gchar *kw = (gchar *) work->data; |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
299 work = work->next; |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
300 |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
301 exif_item_set_string(item, kw); |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
302 } |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
303 } |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
304 |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
305 success = exif_write(exif); |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
306 |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
307 exif_free(exif); |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
308 |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
309 return success; |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
310 } |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
311 |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
312 gint comment_write(FileData *fd, GList *keywords, const gchar *comment) |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
313 { |
204 | 314 if (!fd) return FALSE; |
315 | |
316 if (enable_metadata_dirs && /* FIXME - use dedicated option */ | |
317 comment_xmp_write(fd, keywords, comment)) | |
318 { | |
319 comment_delete_legacy(fd); | |
320 return TRUE; | |
321 } | |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
322 |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
323 return comment_legacy_write(fd, keywords, comment); |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
324 } |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
325 |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
326 gint comment_read(FileData *fd, GList **keywords, gchar **comment) |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
327 { |
204 | 328 GList *keywords1, *keywords2; |
329 gchar *comment1, *comment2; | |
330 gint res1, res2; | |
331 | |
332 if (!fd) return FALSE; | |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
333 |
204 | 334 res1 = comment_xmp_read(fd, &keywords1, &comment1); |
335 res2 = comment_legacy_read(fd, &keywords2, &comment2); | |
336 | |
337 if (!res1 && !res2) | |
338 { | |
339 return FALSE; | |
340 } | |
341 | |
342 if (keywords) | |
343 { | |
344 if (res1 && res2) | |
345 *keywords = g_list_concat(keywords1, keywords2); | |
346 else | |
347 *keywords = res1 ? keywords1 : keywords2; | |
348 } | |
349 else | |
350 { | |
351 if (res1) string_list_free(keywords1); | |
352 if (res2) string_list_free(keywords2); | |
353 } | |
354 | |
355 | |
356 if (comment) | |
357 { | |
358 if (res1 && res2 && comment1 && comment2 && comment1[0] && comment2[0]) | |
359 *comment = g_strdup_printf("%s\n%s", comment1, comment2); | |
360 else | |
361 *comment = res1 ? comment1 : comment2; | |
362 } | |
363 if (res1 && (!comment || *comment != comment1)) g_free(comment1); | |
364 if (res2 && (!comment || *comment != comment2)) g_free(comment2); | |
365 | |
366 return TRUE; | |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
367 } |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
368 |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
369 |
9 | 370 static gchar *comment_pull(GtkWidget *textview) |
371 { | |
372 GtkTextBuffer *buffer; | |
373 GtkTextIter start, end; | |
374 | |
375 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview)); | |
376 gtk_text_buffer_get_bounds(buffer, &start, &end); | |
377 | |
378 return gtk_text_buffer_get_text(buffer, &start, &end, FALSE); | |
379 } | |
380 | |
381 GList *keyword_list_pull(GtkWidget *text_widget) | |
382 { | |
383 GList *list = NULL; | |
384 gchar *text; | |
385 gchar *ptr; | |
386 | |
387 if (GTK_IS_TEXT_VIEW(text_widget)) | |
388 { | |
389 text = comment_pull(text_widget); | |
390 } | |
391 else if (GTK_IS_ENTRY(text_widget)) | |
392 { | |
393 text = g_strdup(gtk_entry_get_text(GTK_ENTRY(text_widget))); | |
394 } | |
395 else | |
396 { | |
397 return NULL; | |
398 } | |
399 | |
400 ptr = text; | |
401 while (*ptr != '\0') | |
402 { | |
403 gchar *begin; | |
404 gint l = 0; | |
405 | |
406 while (*ptr == ' ' || *ptr == ',' || *ptr == '\n' || *ptr == '\r' || *ptr == '\b') ptr++; | |
407 begin = ptr; | |
408 if (*ptr != '\0') | |
409 { | |
410 while (*ptr != ' ' && *ptr != ',' && | |
411 *ptr != '\n' && *ptr != '\r' && *ptr != '\b' && | |
412 *ptr != '\0') | |
413 { | |
414 ptr++; | |
415 l++; | |
416 } | |
417 } | |
418 | |
419 if (l > 0) list = g_list_append(list, g_strndup(begin, l)); | |
420 } | |
421 | |
422 g_free(text); | |
423 | |
424 return list; | |
425 } | |
426 | |
427 void keyword_list_push(GtkWidget *textview, GList *list) | |
428 { | |
429 GtkTextBuffer *buffer; | |
430 GtkTextIter start, end; | |
431 | |
432 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview)); | |
433 gtk_text_buffer_get_bounds(buffer, &start, &end); | |
434 gtk_text_buffer_delete (buffer, &start, &end); | |
435 | |
436 while (list) | |
437 { | |
438 const gchar *word = list->data; | |
439 GtkTextIter iter; | |
440 | |
441 gtk_text_buffer_get_end_iter(buffer, &iter); | |
442 if (word) gtk_text_buffer_insert(buffer, &iter, word, -1); | |
443 gtk_text_buffer_get_end_iter(buffer, &iter); | |
444 gtk_text_buffer_insert(buffer, &iter, "\n", -1); | |
445 | |
446 list = list->next; | |
447 } | |
448 } | |
449 | |
138 | 450 static void metadata_set_keywords(FileData *fd, GList *list, gint add) |
9 | 451 { |
452 gchar *comment = NULL; | |
453 GList *keywords = NULL; | |
454 GList *save_list = NULL; | |
455 | |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
456 comment_read(fd, &keywords, &comment); |
9 | 457 |
458 if (add) | |
459 { | |
460 GList *work; | |
461 | |
462 work = list; | |
463 while (work) | |
464 { | |
465 gchar *key; | |
466 GList *p; | |
467 | |
468 key = work->data; | |
469 work = work->next; | |
470 | |
471 p = keywords; | |
472 while (p && key) | |
473 { | |
474 gchar *needle = p->data; | |
475 p = p->next; | |
476 | |
477 if (strcmp(needle, key) == 0) key = NULL; | |
478 } | |
479 | |
480 if (key) keywords = g_list_append(keywords, g_strdup(key)); | |
481 } | |
482 save_list = keywords; | |
483 } | |
484 else | |
485 { | |
486 save_list = list; | |
487 } | |
488 | |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
489 comment_write(fd, save_list, comment); |
9 | 490 |
138 | 491 string_list_free(keywords); |
9 | 492 g_free(comment); |
493 } | |
494 | |
495 /* | |
496 *------------------------------------------------------------------- | |
497 * keyword list dialog | |
498 *------------------------------------------------------------------- | |
499 */ | |
500 | |
501 #define KEYWORD_DIALOG_WIDTH 200 | |
502 #define KEYWORD_DIALOG_HEIGHT 250 | |
503 | |
504 typedef struct _KeywordDlg KeywordDlg; | |
505 struct _KeywordDlg | |
506 { | |
507 GenericDialog *gd; | |
508 GtkWidget *treeview; | |
509 }; | |
510 | |
511 static KeywordDlg *keyword_dialog = NULL; | |
512 | |
513 | |
514 static void keyword_dialog_cancel_cb(GenericDialog *gd, gpointer data) | |
515 { | |
516 g_free(keyword_dialog); | |
517 keyword_dialog = NULL; | |
518 } | |
519 | |
520 static void keyword_dialog_ok_cb(GenericDialog *gd, gpointer data) | |
521 { | |
522 KeywordDlg *kd = data; | |
523 GtkTreeModel *store; | |
524 GtkTreeIter iter; | |
525 gint valid; | |
526 | |
527 history_list_free_key("keywords"); | |
528 | |
529 store = gtk_tree_view_get_model(GTK_TREE_VIEW(kd->treeview)); | |
530 valid = gtk_tree_model_get_iter_first(store, &iter); | |
531 while (valid) | |
532 { | |
533 gchar *key; | |
534 | |
535 gtk_tree_model_get(store, &iter, 0, &key, -1); | |
536 valid = gtk_tree_model_iter_next(store, &iter); | |
537 | |
538 history_list_add_to_key("keywords", key, 0); | |
539 } | |
540 | |
541 keyword_dialog_cancel_cb(gd, data); | |
542 | |
543 bar_info_keyword_update_all(); | |
544 } | |
545 | |
546 static void keyword_dialog_add_cb(GtkWidget *button, gpointer data) | |
547 { | |
548 KeywordDlg *kd = data; | |
549 GtkTreeSelection *selection; | |
550 GtkTreeModel *store; | |
551 GtkTreeIter sibling; | |
552 GtkTreeIter iter; | |
553 GtkTreePath *tpath; | |
554 | |
555 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(kd->treeview)); | |
556 if (gtk_tree_selection_get_selected(selection, &store, &sibling)) | |
557 { | |
558 gtk_list_store_insert_before(GTK_LIST_STORE(store), &iter, &sibling); | |
559 } | |
560 else | |
561 { | |
562 store = gtk_tree_view_get_model(GTK_TREE_VIEW(kd->treeview)); | |
563 gtk_list_store_append(GTK_LIST_STORE(store), &iter); | |
564 } | |
565 | |
566 gtk_list_store_set(GTK_LIST_STORE(store), &iter, 1, TRUE, -1); | |
567 | |
568 tpath = gtk_tree_model_get_path(store, &iter); | |
569 gtk_tree_view_set_cursor(GTK_TREE_VIEW(kd->treeview), tpath, | |
570 gtk_tree_view_get_column(GTK_TREE_VIEW(kd->treeview), 0), TRUE); | |
571 gtk_tree_path_free(tpath); | |
572 } | |
573 | |
574 static void keyword_dialog_remove_cb(GtkWidget *button, gpointer data) | |
575 { | |
576 KeywordDlg *kd = data; | |
577 GtkTreeSelection *selection; | |
578 GtkTreeModel *store; | |
579 GtkTreeIter iter; | |
580 GtkTreeIter next; | |
581 GtkTreePath *tpath; | |
582 | |
583 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(kd->treeview)); | |
584 if (!gtk_tree_selection_get_selected(selection, &store, &iter)) return; | |
585 | |
586 tpath = NULL; | |
587 next = iter; | |
588 if (gtk_tree_model_iter_next(store, &next)) | |
589 { | |
590 tpath = gtk_tree_model_get_path(store, &next); | |
591 } | |
592 else | |
593 { | |
594 tpath = gtk_tree_model_get_path(store, &iter); | |
595 if (!gtk_tree_path_prev(tpath)) | |
596 { | |
597 gtk_tree_path_free(tpath); | |
598 tpath = NULL; | |
599 } | |
600 } | |
601 if (tpath) | |
602 { | |
603 gtk_tree_view_set_cursor(GTK_TREE_VIEW(kd->treeview), tpath, | |
604 gtk_tree_view_get_column(GTK_TREE_VIEW(kd->treeview), 0), FALSE); | |
605 gtk_tree_path_free(tpath); | |
606 } | |
607 | |
608 gtk_list_store_remove(GTK_LIST_STORE(store), &iter); | |
609 } | |
610 | |
611 static void keyword_dialog_edit_cb(GtkCellRendererText *renderer, const gchar *path, | |
612 const gchar *new_text, gpointer data) | |
613 { | |
614 KeywordDlg *kd = data; | |
615 GtkTreeModel *store; | |
616 GtkTreeIter iter; | |
617 GtkTreePath *tpath; | |
618 | |
619 if (!new_text || strlen(new_text) == 0) return; | |
620 | |
621 store = gtk_tree_view_get_model(GTK_TREE_VIEW(kd->treeview)); | |
622 | |
623 tpath = gtk_tree_path_new_from_string(path); | |
624 gtk_tree_model_get_iter(store, &iter, tpath); | |
625 gtk_tree_path_free(tpath); | |
626 | |
627 gtk_list_store_set(GTK_LIST_STORE(store), &iter, 0, new_text, -1); | |
628 } | |
629 | |
630 static void keyword_dialog_populate(KeywordDlg *kd) | |
631 { | |
632 GtkListStore *store; | |
633 GList *list; | |
634 | |
635 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(kd->treeview))); | |
636 gtk_list_store_clear(store); | |
637 | |
638 list = history_list_get_by_key("keywords"); | |
639 list = g_list_last(list); | |
640 while (list) | |
641 { | |
642 GtkTreeIter iter; | |
643 | |
644 gtk_list_store_append(store, &iter); | |
645 gtk_list_store_set(store, &iter, 0, list->data, | |
646 1, TRUE, -1); | |
647 | |
648 list = list->prev; | |
649 } | |
650 } | |
651 | |
652 static void keyword_dialog_show(void) | |
653 { | |
654 GtkWidget *scrolled; | |
655 GtkListStore *store; | |
656 GtkTreeViewColumn *column; | |
657 GtkCellRenderer *renderer; | |
658 GtkWidget *hbox; | |
659 GtkWidget *button; | |
660 | |
661 if (keyword_dialog) | |
662 { | |
663 gtk_window_present(GTK_WINDOW(keyword_dialog->gd->dialog)); | |
664 return; | |
665 } | |
666 | |
667 keyword_dialog = g_new0(KeywordDlg, 1); | |
668 | |
669 keyword_dialog->gd = generic_dialog_new(_("Keyword Presets"), | |
196 | 670 "Geeqie", "keyword_presets", NULL, TRUE, |
9 | 671 keyword_dialog_cancel_cb, keyword_dialog); |
672 generic_dialog_add_message(keyword_dialog->gd, NULL, _("Favorite keywords list"), NULL); | |
673 | |
674 generic_dialog_add_button(keyword_dialog->gd, GTK_STOCK_OK, NULL, | |
675 keyword_dialog_ok_cb, TRUE); | |
676 | |
677 scrolled = gtk_scrolled_window_new(NULL, NULL); | |
678 gtk_widget_set_size_request(scrolled, KEYWORD_DIALOG_WIDTH, KEYWORD_DIALOG_HEIGHT); | |
679 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); | |
680 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), | |
681 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
682 gtk_box_pack_start(GTK_BOX(keyword_dialog->gd->vbox), scrolled, TRUE, TRUE, 5); | |
683 gtk_widget_show(scrolled); | |
684 | |
685 store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_BOOLEAN); | |
686 keyword_dialog->treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); | |
687 g_object_unref(store); | |
688 | |
689 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(keyword_dialog->treeview), FALSE); | |
690 gtk_tree_view_set_search_column(GTK_TREE_VIEW(keyword_dialog->treeview), 0); | |
691 gtk_tree_view_set_reorderable(GTK_TREE_VIEW(keyword_dialog->treeview), TRUE); | |
692 | |
693 column = gtk_tree_view_column_new(); | |
694 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); | |
695 renderer = gtk_cell_renderer_text_new(); | |
696 g_signal_connect(G_OBJECT(renderer), "edited", | |
697 G_CALLBACK(keyword_dialog_edit_cb), keyword_dialog); | |
698 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
699 gtk_tree_view_column_add_attribute(column, renderer, "text", 0); | |
700 gtk_tree_view_column_add_attribute(column, renderer, "editable", 1); | |
701 gtk_tree_view_append_column(GTK_TREE_VIEW(keyword_dialog->treeview), column); | |
702 | |
703 gtk_container_add(GTK_CONTAINER(scrolled), keyword_dialog->treeview); | |
704 gtk_widget_show(keyword_dialog->treeview); | |
705 | |
706 hbox = gtk_hbox_new(FALSE, 5); | |
707 gtk_box_pack_start(GTK_BOX(keyword_dialog->gd->vbox), hbox, FALSE, FALSE, 0); | |
708 gtk_widget_show(hbox); | |
709 | |
710 button = gtk_button_new_from_stock(GTK_STOCK_ADD); | |
711 g_signal_connect(G_OBJECT(button), "clicked", | |
712 G_CALLBACK(keyword_dialog_add_cb), keyword_dialog); | |
713 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
714 gtk_widget_show(button); | |
715 | |
716 button = gtk_button_new_from_stock(GTK_STOCK_REMOVE); | |
717 g_signal_connect(G_OBJECT(button), "clicked", | |
718 G_CALLBACK(keyword_dialog_remove_cb), keyword_dialog); | |
719 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
720 gtk_widget_show(button); | |
721 | |
722 keyword_dialog_populate(keyword_dialog); | |
723 | |
724 gtk_widget_show(keyword_dialog->gd->dialog); | |
725 } | |
726 | |
727 | |
728 static void bar_keyword_edit_cb(GtkWidget *button, gpointer data) | |
729 { | |
730 keyword_dialog_show(); | |
731 } | |
732 | |
733 | |
734 /* | |
735 *------------------------------------------------------------------- | |
736 * info bar | |
737 *------------------------------------------------------------------- | |
738 */ | |
739 | |
740 typedef enum { | |
741 BAR_SORT_COPY, | |
742 BAR_SORT_MOVE, | |
743 BAR_SORT_LINK | |
744 } SortActionType; | |
745 | |
746 enum { | |
747 KEYWORD_COLUMN_TOGGLE = 0, | |
748 KEYWORD_COLUMN_TEXT | |
749 }; | |
750 | |
751 typedef struct _BarInfoData BarInfoData; | |
752 struct _BarInfoData | |
753 { | |
754 GtkWidget *vbox; | |
755 GtkWidget *group_box; | |
756 GtkWidget *label_file_name; | |
757 GtkWidget *label_file_time; | |
758 | |
759 GtkWidget *keyword_view; | |
760 GtkWidget *keyword_treeview; | |
761 | |
762 GtkWidget *comment_view; | |
763 | |
764 GtkWidget *button_save; | |
765 GtkWidget *button_set_add; | |
766 GtkWidget *button_set_replace; | |
767 | |
138 | 768 FileData *fd; |
9 | 769 |
770 gint changed; | |
771 gint save_timeout_id; | |
772 | |
773 GList *(*list_func)(gpointer); | |
774 gpointer list_data; | |
775 }; | |
776 | |
777 | |
778 static GList *bar_list = NULL; | |
779 | |
780 | |
781 static void bar_info_write(BarInfoData *bd) | |
782 { | |
783 GList *list; | |
784 gchar *comment; | |
785 | |
138 | 786 if (!bd->fd) return; |
9 | 787 |
788 list = keyword_list_pull(bd->keyword_view); | |
789 comment = comment_pull(bd->comment_view); | |
790 | |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
791 comment_write(bd->fd, list, comment); |
9 | 792 |
138 | 793 string_list_free(list); |
9 | 794 g_free(comment); |
795 | |
796 bd->changed = FALSE; | |
797 gtk_widget_set_sensitive(bd->button_save, FALSE); | |
798 } | |
799 | |
800 static gint bar_info_autosave(gpointer data) | |
801 { | |
802 BarInfoData *bd = data; | |
803 | |
804 bar_info_write(bd); | |
805 | |
806 bd->save_timeout_id = -1; | |
807 | |
808 return FALSE; | |
809 } | |
810 | |
811 static void bar_info_save_update(BarInfoData *bd, gint enable) | |
812 { | |
813 if (bd->save_timeout_id != -1) | |
814 { | |
815 g_source_remove(bd->save_timeout_id); | |
816 bd->save_timeout_id = -1; | |
817 } | |
818 if (enable) | |
819 { | |
820 bd->save_timeout_id = g_timeout_add(BAR_KEYWORD_AUTOSAVE_TIME, bar_info_autosave, bd); | |
821 } | |
822 } | |
823 | |
824 static gint bar_keyword_list_find(GList *list, const gchar *keyword) | |
825 { | |
826 while (list) | |
827 { | |
828 gchar *haystack = list->data; | |
829 | |
830 if (haystack && keyword && strcmp(haystack, keyword) == 0) return TRUE; | |
831 | |
832 list = list->next; | |
833 } | |
834 | |
835 return FALSE; | |
836 } | |
837 | |
838 static void bar_keyword_list_sync(BarInfoData *bd, GList *keywords) | |
839 { | |
840 GList *list; | |
841 GtkListStore *store; | |
842 GtkTreeIter iter; | |
843 | |
844 list = history_list_get_by_key("keywords"); | |
845 if (!list) | |
846 { | |
847 /* blank? set up a few example defaults */ | |
848 | |
849 gint i = 0; | |
850 | |
851 while (keyword_favorite_defaults[i] != NULL) | |
852 { | |
853 history_list_add_to_key("keywords", _(keyword_favorite_defaults[i]), 0); | |
854 i++; | |
855 } | |
856 | |
857 list = history_list_get_by_key("keywords"); | |
858 } | |
859 | |
860 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(bd->keyword_treeview))); | |
861 | |
862 gtk_list_store_clear(store); | |
863 | |
864 list = g_list_last(list); | |
865 while (list) | |
866 { | |
867 gchar *key = list->data; | |
868 | |
869 gtk_list_store_append(store, &iter); | |
870 gtk_list_store_set(store, &iter, KEYWORD_COLUMN_TOGGLE, bar_keyword_list_find(keywords, key), | |
871 KEYWORD_COLUMN_TEXT, key, -1); | |
872 | |
873 list = list->prev; | |
874 } | |
875 } | |
876 | |
877 static void bar_info_keyword_update_all(void) | |
878 { | |
879 GList *work; | |
880 | |
881 work = bar_list; | |
882 while (work) | |
883 { | |
884 BarInfoData *bd; | |
885 GList *keywords; | |
886 | |
887 bd = work->data; | |
888 work = work->next; | |
889 | |
890 keywords = keyword_list_pull(bd->keyword_view); | |
891 bar_keyword_list_sync(bd, keywords); | |
138 | 892 string_list_free(keywords); |
9 | 893 } |
894 } | |
895 | |
896 static void bar_info_update(BarInfoData *bd) | |
897 { | |
898 GList *keywords = NULL; | |
899 gchar *comment = NULL; | |
900 | |
901 if (bd->label_file_name) | |
902 { | |
138 | 903 gtk_label_set_text(GTK_LABEL(bd->label_file_name), (bd->fd) ? bd->fd->name : ""); |
9 | 904 } |
905 if (bd->label_file_time) | |
906 { | |
138 | 907 gtk_label_set_text(GTK_LABEL(bd->label_file_time), (bd->fd) ? text_from_time(bd->fd->date) : ""); |
9 | 908 } |
909 | |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
910 if (comment_read(bd->fd, &keywords, &comment)) |
9 | 911 { |
912 keyword_list_push(bd->keyword_view, keywords); | |
913 gtk_text_buffer_set_text(gtk_text_view_get_buffer(GTK_TEXT_VIEW(bd->comment_view)), | |
914 (comment) ? comment : "", -1); | |
915 | |
916 bar_keyword_list_sync(bd, keywords); | |
917 | |
138 | 918 string_list_free(keywords); |
9 | 919 g_free(comment); |
920 } | |
921 else | |
922 { | |
923 gtk_text_buffer_set_text(gtk_text_view_get_buffer(GTK_TEXT_VIEW(bd->keyword_view)), "", -1); | |
924 gtk_text_buffer_set_text(gtk_text_view_get_buffer(GTK_TEXT_VIEW(bd->comment_view)), "", -1); | |
925 | |
926 bar_keyword_list_sync(bd, NULL); | |
927 } | |
928 | |
929 bar_info_save_update(bd, FALSE); | |
930 bd->changed = FALSE; | |
931 gtk_widget_set_sensitive(bd->button_save, FALSE); | |
932 | |
138 | 933 gtk_widget_set_sensitive(bd->group_box, (bd->fd != NULL)); |
9 | 934 } |
935 | |
138 | 936 void bar_info_set(GtkWidget *bar, FileData *fd) |
9 | 937 { |
938 BarInfoData *bd; | |
939 | |
940 bd = g_object_get_data(G_OBJECT(bar), "bar_info_data"); | |
941 if (!bd) return; | |
942 | |
943 if (bd->changed) bar_info_write(bd); | |
944 | |
138 | 945 file_data_unref(bd->fd); |
946 bd->fd = file_data_ref(fd); | |
9 | 947 |
948 bar_info_update(bd); | |
949 } | |
950 | |
138 | 951 void bar_info_maint_renamed(GtkWidget *bar, FileData *fd) |
9 | 952 { |
953 BarInfoData *bd; | |
954 | |
955 bd = g_object_get_data(G_OBJECT(bar), "bar_info_data"); | |
956 if (!bd) return; | |
957 | |
138 | 958 file_data_unref(bd->fd); |
959 bd->fd = file_data_ref(fd); | |
9 | 960 |
961 if (bd->label_file_name) | |
962 { | |
138 | 963 gtk_label_set_text(GTK_LABEL(bd->label_file_name), (bd->fd) ? bd->fd->name : ""); |
9 | 964 } |
965 } | |
966 | |
967 gint bar_info_event(GtkWidget *bar, GdkEvent *event) | |
968 { | |
969 BarInfoData *bd; | |
970 | |
971 bd = g_object_get_data(G_OBJECT(bar), "bar_info_data"); | |
972 if (!bd) return FALSE; | |
973 | |
974 if (GTK_WIDGET_HAS_FOCUS(bd->keyword_view)) return gtk_widget_event(bd->keyword_view, event); | |
975 if (GTK_WIDGET_HAS_FOCUS(bd->comment_view)) return gtk_widget_event(bd->comment_view, event); | |
976 | |
977 return FALSE; | |
978 } | |
979 | |
980 static void bar_info_keyword_set(BarInfoData *bd, const gchar *keyword, gint active) | |
981 { | |
982 GList *list; | |
983 gint found; | |
984 | |
985 if (!keyword) return; | |
986 | |
987 list = keyword_list_pull(bd->keyword_view); | |
988 found = bar_keyword_list_find(list, keyword); | |
989 | |
990 if (active != found) | |
991 { | |
992 if (found) | |
993 { | |
994 GList *work = list; | |
995 | |
996 while (work) | |
997 { | |
998 gchar *key = work->data; | |
999 work = work->next; | |
1000 | |
1001 if (key && keyword && strcmp(key, keyword) == 0) | |
1002 { | |
1003 list = g_list_remove(list, key); | |
1004 g_free(key); | |
1005 } | |
1006 } | |
1007 } | |
1008 else | |
1009 { | |
1010 list = g_list_append(list, g_strdup(keyword)); | |
1011 } | |
1012 | |
1013 keyword_list_push(bd->keyword_view, list); | |
1014 } | |
1015 | |
138 | 1016 string_list_free(list); |
9 | 1017 } |
1018 | |
1019 static void bar_info_keyword_toggle(GtkCellRendererToggle *toggle, const gchar *path, gpointer data) | |
1020 { | |
1021 BarInfoData *bd = data; | |
1022 GtkTreeModel *store; | |
1023 GtkTreeIter iter; | |
1024 GtkTreePath *tpath; | |
1025 gchar *key = NULL; | |
1026 gboolean active; | |
1027 | |
1028 store = gtk_tree_view_get_model(GTK_TREE_VIEW(bd->keyword_treeview)); | |
1029 | |
1030 tpath = gtk_tree_path_new_from_string(path); | |
1031 gtk_tree_model_get_iter(store, &iter, tpath); | |
1032 gtk_tree_path_free(tpath); | |
1033 | |
1034 gtk_tree_model_get(store, &iter, KEYWORD_COLUMN_TOGGLE, &active, | |
1035 KEYWORD_COLUMN_TEXT, &key, -1); | |
1036 active = (!active); | |
1037 gtk_list_store_set(GTK_LIST_STORE(store), &iter, KEYWORD_COLUMN_TOGGLE, active, -1); | |
1038 | |
1039 bar_info_keyword_set(bd, key, active); | |
1040 g_free(key); | |
1041 } | |
1042 | |
1043 static void bar_info_save(GtkWidget *button, gpointer data) | |
1044 { | |
1045 BarInfoData *bd = data; | |
1046 | |
1047 bar_info_save_update(bd, FALSE); | |
1048 bar_info_write(bd); | |
1049 } | |
1050 | |
1051 static void bar_info_set_selection(BarInfoData *bd, gint add) | |
1052 { | |
1053 GList *keywords; | |
1054 GList *list = NULL; | |
1055 GList *work; | |
1056 | |
1057 if (!bd->list_func) return; | |
1058 | |
1059 keywords = keyword_list_pull(bd->keyword_view); | |
1060 if (!keywords && add) return; | |
1061 | |
1062 list = bd->list_func(bd->list_data); | |
1063 work = list; | |
1064 while (work) | |
1065 { | |
138 | 1066 FileData *fd = work->data; |
9 | 1067 work = work->next; |
1068 | |
138 | 1069 metadata_set_keywords(fd, keywords, add); |
9 | 1070 } |
1071 | |
138 | 1072 filelist_free(list); |
1073 string_list_free(keywords); | |
9 | 1074 } |
1075 | |
1076 static void bar_info_set_add(GtkWidget *button, gpointer data) | |
1077 { | |
1078 BarInfoData *bd = data; | |
1079 | |
1080 bar_info_set_selection(bd, TRUE); | |
1081 } | |
1082 | |
1083 static void bar_info_set_replace(GtkWidget *button, gpointer data) | |
1084 { | |
1085 BarInfoData *bd = data; | |
1086 | |
1087 bar_info_set_selection(bd, FALSE); | |
1088 } | |
1089 | |
1090 static void bar_info_changed(GtkTextBuffer *buffer, gpointer data) | |
1091 { | |
1092 BarInfoData *bd = data; | |
1093 | |
1094 bd->changed = TRUE; | |
1095 gtk_widget_set_sensitive(bd->button_save, TRUE); | |
1096 | |
1097 bar_info_save_update(bd, TRUE); | |
1098 } | |
1099 | |
1100 void bar_info_close(GtkWidget *bar) | |
1101 { | |
1102 BarInfoData *bd; | |
1103 | |
1104 bd = g_object_get_data(G_OBJECT(bar), "bar_info_data"); | |
1105 if (!bd) return; | |
1106 | |
1107 gtk_widget_destroy(bd->vbox); | |
1108 } | |
1109 | |
1110 static void bar_info_destroy(GtkWidget *widget, gpointer data) | |
1111 { | |
1112 BarInfoData *bd = data; | |
1113 | |
1114 if (bd->changed) bar_info_write(bd); | |
1115 bar_info_save_update(bd, FALSE); | |
1116 | |
1117 bar_list = g_list_remove(bar_list, bd); | |
1118 | |
138 | 1119 file_data_unref(bd->fd); |
9 | 1120 |
1121 g_free(bd); | |
1122 } | |
1123 | |
138 | 1124 GtkWidget *bar_info_new(FileData *fd, gint metadata_only, GtkWidget *bounding_widget) |
9 | 1125 { |
1126 BarInfoData *bd; | |
1127 GtkWidget *box; | |
1128 GtkWidget *hbox; | |
1129 GtkWidget *table; | |
1130 GtkWidget *scrolled; | |
1131 GtkTextBuffer *buffer; | |
1132 GtkWidget *label; | |
1133 GtkWidget *tbar; | |
1134 GtkListStore *store; | |
1135 GtkTreeViewColumn *column; | |
1136 GtkCellRenderer *renderer; | |
1137 | |
1138 bd = g_new0(BarInfoData, 1); | |
1139 | |
1140 bd->list_func = NULL; | |
1141 bd->list_data = NULL; | |
1142 | |
1143 bd->vbox = gtk_vbox_new(FALSE, PREF_PAD_GAP); | |
1144 g_object_set_data(G_OBJECT(bd->vbox), "bar_info_data", bd); | |
1145 g_signal_connect(G_OBJECT(bd->vbox), "destroy", | |
1146 G_CALLBACK(bar_info_destroy), bd); | |
1147 | |
1148 if (!metadata_only) | |
1149 { | |
1150 hbox = pref_box_new(bd->vbox, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_GAP); | |
1151 | |
1152 label = sizer_new(bd->vbox, bounding_widget, SIZER_POS_LEFT); | |
1153 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
1154 gtk_widget_show(label); | |
1155 | |
1156 label = gtk_label_new(_("Keywords")); | |
1157 pref_label_bold(label, TRUE, FALSE); | |
1158 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0); | |
1159 gtk_widget_show(label); | |
1160 } | |
1161 | |
1162 bd->group_box = pref_box_new(bd->vbox, TRUE, GTK_ORIENTATION_VERTICAL, PREF_PAD_GAP); | |
1163 | |
1164 if (!metadata_only) | |
1165 { | |
1166 GtkWidget *table; | |
1167 | |
1168 table = pref_table_new(bd->group_box, 2, 2, FALSE, FALSE); | |
1169 | |
1170 bd->label_file_name = table_add_line(table, 0, 0, _("Filename:"), NULL); | |
1171 bd->label_file_time = table_add_line(table, 0, 1, _("File date:"), NULL); | |
1172 } | |
1173 else | |
1174 { | |
1175 bd->label_file_name = NULL; | |
1176 bd->label_file_time = NULL; | |
1177 } | |
1178 | |
1179 table = gtk_table_new(3, 1, TRUE); | |
1180 gtk_table_set_row_spacings(GTK_TABLE(table), PREF_PAD_GAP); | |
1181 gtk_box_pack_start(GTK_BOX(bd->group_box), table, TRUE, TRUE, 0); | |
1182 gtk_widget_show(table); | |
1183 | |
1184 /* keyword entry */ | |
1185 | |
1186 box = gtk_vbox_new(FALSE, 0); | |
1187 gtk_table_attach(GTK_TABLE(table), box, 0, 1, 0, 2, | |
1188 GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); | |
1189 gtk_widget_show(box); | |
1190 | |
1191 label = pref_label_new(box, _("Keywords:")); | |
1192 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); | |
1193 pref_label_bold(label, TRUE, FALSE); | |
1194 | |
1195 hbox = pref_box_new(box, TRUE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_GAP); | |
1196 | |
1197 scrolled = gtk_scrolled_window_new(NULL, NULL); | |
1198 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); | |
1199 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), | |
1200 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
1201 gtk_box_pack_start(GTK_BOX(hbox), scrolled, TRUE, TRUE, 0); | |
1202 gtk_widget_show(scrolled); | |
1203 | |
1204 bd->keyword_view = gtk_text_view_new(); | |
1205 gtk_container_add(GTK_CONTAINER(scrolled), bd->keyword_view); | |
1206 gtk_widget_show(bd->keyword_view); | |
1207 | |
1208 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(bd->keyword_view)); | |
1209 g_signal_connect(G_OBJECT(buffer), "changed", | |
1210 G_CALLBACK(bar_info_changed), bd); | |
1211 | |
1212 scrolled = gtk_scrolled_window_new(NULL, NULL); | |
1213 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); | |
1214 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), | |
1215 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
1216 gtk_box_pack_start(GTK_BOX(hbox), scrolled, TRUE, TRUE, 0); | |
1217 gtk_widget_show(scrolled); | |
1218 | |
1219 store = gtk_list_store_new(2, G_TYPE_BOOLEAN, G_TYPE_STRING); | |
1220 bd->keyword_treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); | |
1221 g_object_unref(store); | |
1222 | |
1223 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(bd->keyword_treeview), FALSE); | |
1224 | |
1225 if (metadata_only) | |
1226 { | |
1227 gtk_tree_view_set_search_column(GTK_TREE_VIEW(bd->keyword_treeview), KEYWORD_COLUMN_TEXT); | |
1228 } | |
1229 else | |
1230 { | |
1231 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(bd->keyword_treeview), FALSE); | |
1232 } | |
1233 | |
1234 column = gtk_tree_view_column_new(); | |
1235 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); | |
1236 | |
1237 renderer = gtk_cell_renderer_toggle_new(); | |
1238 gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
1239 gtk_tree_view_column_add_attribute(column, renderer, "active", KEYWORD_COLUMN_TOGGLE); | |
1240 g_signal_connect(G_OBJECT(renderer), "toggled", | |
1241 G_CALLBACK(bar_info_keyword_toggle), bd); | |
1242 | |
1243 renderer = gtk_cell_renderer_text_new(); | |
1244 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
1245 gtk_tree_view_column_add_attribute(column, renderer, "text", KEYWORD_COLUMN_TEXT); | |
1246 | |
1247 gtk_tree_view_append_column(GTK_TREE_VIEW(bd->keyword_treeview), column); | |
1248 | |
1249 gtk_container_add(GTK_CONTAINER(scrolled), bd->keyword_treeview); | |
1250 gtk_widget_show(bd->keyword_treeview); | |
1251 | |
1252 /* comment entry */ | |
1253 | |
1254 box = gtk_vbox_new(FALSE, 0); | |
1255 gtk_table_attach(GTK_TABLE(table), box, 0, 1, 2, 3, | |
1256 GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); | |
1257 gtk_widget_show(box); | |
1258 | |
1259 label = pref_label_new(box, _("Comment:")); | |
1260 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); | |
1261 pref_label_bold(label, TRUE, FALSE); | |
1262 | |
1263 scrolled = gtk_scrolled_window_new(NULL, NULL); | |
1264 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); | |
1265 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), | |
1266 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
1267 gtk_box_pack_start(GTK_BOX(box), scrolled, TRUE, TRUE, 0); | |
1268 gtk_widget_show(scrolled); | |
1269 | |
1270 bd->comment_view = gtk_text_view_new(); | |
1271 gtk_container_add(GTK_CONTAINER(scrolled), bd->comment_view); | |
1272 gtk_widget_show(bd->comment_view); | |
1273 | |
1274 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(bd->comment_view)); | |
1275 g_signal_connect(G_OBJECT(buffer), "changed", | |
1276 G_CALLBACK(bar_info_changed), bd); | |
1277 | |
1278 /* toolbar */ | |
1279 | |
1280 tbar = pref_toolbar_new(bd->group_box, GTK_TOOLBAR_ICONS); | |
1281 | |
41
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
1282 pref_toolbar_button(tbar, GTK_STOCK_INDEX, NULL, FALSE, |
9 | 1283 _("Edit favorite keywords list."), |
1284 G_CALLBACK(bar_keyword_edit_cb), bd); | |
1285 pref_toolbar_spacer(tbar); | |
41
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
1286 bd->button_set_add = pref_toolbar_button(tbar, GTK_STOCK_ADD, NULL, FALSE, |
9 | 1287 _("Add keywords to selected files"), |
1288 G_CALLBACK(bar_info_set_add), bd); | |
41
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
1289 bd->button_set_replace = pref_toolbar_button(tbar, GTK_STOCK_CONVERT, NULL, FALSE, |
9 | 1290 _("Add keywords to selected files, replacing the existing ones."), |
1291 G_CALLBACK(bar_info_set_replace), bd); | |
1292 pref_toolbar_spacer(tbar); | |
41
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
1293 bd->button_save = pref_toolbar_button(tbar, GTK_STOCK_SAVE, NULL, FALSE, |
9 | 1294 _("Save comment now"), |
1295 G_CALLBACK(bar_info_save), bd); | |
1296 | |
1297 bd->save_timeout_id = -1; | |
1298 | |
138 | 1299 bd->fd = file_data_ref(fd); |
9 | 1300 bar_info_update(bd); |
1301 | |
1302 bar_info_selection(bd->vbox, 0); | |
1303 | |
1304 bar_list = g_list_append(bar_list, bd); | |
1305 | |
1306 return bd->vbox; | |
1307 } | |
1308 | |
1309 void bar_info_set_selection_func(GtkWidget *bar, GList *(*list_func)(gpointer data), gpointer data) | |
1310 { | |
1311 BarInfoData *bd; | |
1312 | |
1313 bd = g_object_get_data(G_OBJECT(bar), "bar_info_data"); | |
1314 if (!bd) return; | |
1315 | |
1316 bd->list_func = list_func; | |
1317 bd->list_data = data; | |
1318 } | |
1319 | |
1320 void bar_info_selection(GtkWidget *bar, gint count) | |
1321 { | |
1322 BarInfoData *bd; | |
1323 gint enable; | |
1324 | |
1325 bd = g_object_get_data(G_OBJECT(bar), "bar_info_data"); | |
1326 if (!bd) return; | |
1327 | |
1328 enable = (count > 0 && bd->list_func != NULL); | |
1329 | |
1330 gtk_widget_set_sensitive(bd->button_set_add, enable); | |
1331 gtk_widget_set_sensitive(bd->button_set_replace, enable); | |
1332 } | |
1333 | |
1334 void bar_info_size_request(GtkWidget *bar, gint width) | |
1335 { | |
1336 BarInfoData *bd; | |
1337 | |
1338 bd = g_object_get_data(G_OBJECT(bar), "bar_info_data"); | |
1339 if (!bd) return; | |
1340 | |
1341 if (bd->label_file_name) | |
1342 { | |
1343 gtk_widget_set_size_request(bd->vbox, width, -1); | |
1344 } | |
1345 } | |
1346 |