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