Mercurial > geeqie.yaz
annotate src/bar_info.c @ 646:91dfc98f3ca1
Reading of Iptc.Application2.Keywords should now be fixed.
Use uft8_validate_or_convert() on exif's text data to be safe.
author | zas_ |
---|---|
date | Mon, 12 May 2008 23:26:00 +0000 |
parents | eaf94facc190 |
children | 42d36db921bc |
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'; | |
604
0b203af63dbf
Use g_ascii_strcasecmp() instead of strcasecmp() where ascii-only strings
zas_
parents:
595
diff
changeset
|
160 if (g_ascii_strcasecmp(keystr, "keywords") == 0) |
445
89f8bffbce21
comment_file_read(): rewrite the parser, drop leading and trailing newlines
zas_
parents:
442
diff
changeset
|
161 key = MK_KEYWORDS; |
604
0b203af63dbf
Use g_ascii_strcasecmp() instead of strcasecmp() where ascii-only strings
zas_
parents:
595
diff
changeset
|
162 else if (g_ascii_strcasecmp(keystr, "comment") == 0) |
445
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 | |
642
9c74ff4bf1cd
Extract and append keywords from Iptc.Application2.Keywords tags.
zas_
parents:
604
diff
changeset
|
249 static GList *remove_duplicate_strings_from_list(GList *list) |
9c74ff4bf1cd
Extract and append keywords from Iptc.Application2.Keywords tags.
zas_
parents:
604
diff
changeset
|
250 { |
9c74ff4bf1cd
Extract and append keywords from Iptc.Application2.Keywords tags.
zas_
parents:
604
diff
changeset
|
251 GList *work = list; |
9c74ff4bf1cd
Extract and append keywords from Iptc.Application2.Keywords tags.
zas_
parents:
604
diff
changeset
|
252 GHashTable *hashtable = g_hash_table_new(g_str_hash, g_str_equal); |
9c74ff4bf1cd
Extract and append keywords from Iptc.Application2.Keywords tags.
zas_
parents:
604
diff
changeset
|
253 GList *newlist = NULL; |
9c74ff4bf1cd
Extract and append keywords from Iptc.Application2.Keywords tags.
zas_
parents:
604
diff
changeset
|
254 |
9c74ff4bf1cd
Extract and append keywords from Iptc.Application2.Keywords tags.
zas_
parents:
604
diff
changeset
|
255 while (work) |
9c74ff4bf1cd
Extract and append keywords from Iptc.Application2.Keywords tags.
zas_
parents:
604
diff
changeset
|
256 { |
9c74ff4bf1cd
Extract and append keywords from Iptc.Application2.Keywords tags.
zas_
parents:
604
diff
changeset
|
257 gchar *key = work->data; |
9c74ff4bf1cd
Extract and append keywords from Iptc.Application2.Keywords tags.
zas_
parents:
604
diff
changeset
|
258 |
9c74ff4bf1cd
Extract and append keywords from Iptc.Application2.Keywords tags.
zas_
parents:
604
diff
changeset
|
259 if (g_hash_table_lookup(hashtable, key) == NULL) |
9c74ff4bf1cd
Extract and append keywords from Iptc.Application2.Keywords tags.
zas_
parents:
604
diff
changeset
|
260 { |
9c74ff4bf1cd
Extract and append keywords from Iptc.Application2.Keywords tags.
zas_
parents:
604
diff
changeset
|
261 g_hash_table_insert(hashtable, (gpointer) key, GINT_TO_POINTER(1)); |
9c74ff4bf1cd
Extract and append keywords from Iptc.Application2.Keywords tags.
zas_
parents:
604
diff
changeset
|
262 newlist = g_list_prepend(newlist, key); |
9c74ff4bf1cd
Extract and append keywords from Iptc.Application2.Keywords tags.
zas_
parents:
604
diff
changeset
|
263 } |
9c74ff4bf1cd
Extract and append keywords from Iptc.Application2.Keywords tags.
zas_
parents:
604
diff
changeset
|
264 work = work->next; |
9c74ff4bf1cd
Extract and append keywords from Iptc.Application2.Keywords tags.
zas_
parents:
604
diff
changeset
|
265 } |
9c74ff4bf1cd
Extract and append keywords from Iptc.Application2.Keywords tags.
zas_
parents:
604
diff
changeset
|
266 |
9c74ff4bf1cd
Extract and append keywords from Iptc.Application2.Keywords tags.
zas_
parents:
604
diff
changeset
|
267 g_hash_table_destroy(hashtable); |
9c74ff4bf1cd
Extract and append keywords from Iptc.Application2.Keywords tags.
zas_
parents:
604
diff
changeset
|
268 g_list_free(list); |
9c74ff4bf1cd
Extract and append keywords from Iptc.Application2.Keywords tags.
zas_
parents:
604
diff
changeset
|
269 |
9c74ff4bf1cd
Extract and append keywords from Iptc.Application2.Keywords tags.
zas_
parents:
604
diff
changeset
|
270 return g_list_reverse(newlist); |
9c74ff4bf1cd
Extract and append keywords from Iptc.Application2.Keywords tags.
zas_
parents:
604
diff
changeset
|
271 } |
9c74ff4bf1cd
Extract and append keywords from Iptc.Application2.Keywords tags.
zas_
parents:
604
diff
changeset
|
272 |
593
bb712693cad3
comment_xmp_read(), comment_xmp_write(): cleanup and improve readibility.
zas_
parents:
586
diff
changeset
|
273 #define COMMENT_KEY "Xmp.dc.description" |
bb712693cad3
comment_xmp_read(), comment_xmp_write(): cleanup and improve readibility.
zas_
parents:
586
diff
changeset
|
274 #define KEYWORD_KEY "Xmp.dc.subject" |
188
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 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
|
277 { |
593
bb712693cad3
comment_xmp_read(), comment_xmp_write(): cleanup and improve readibility.
zas_
parents:
586
diff
changeset
|
278 ExifData *exif; |
bb712693cad3
comment_xmp_read(), comment_xmp_write(): cleanup and improve readibility.
zas_
parents:
586
diff
changeset
|
279 |
bb712693cad3
comment_xmp_read(), comment_xmp_write(): cleanup and improve readibility.
zas_
parents:
586
diff
changeset
|
280 exif = exif_read_fd(fd); |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
281 if (!exif) return FALSE; |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
282 |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
283 if (comment) |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
284 { |
593
bb712693cad3
comment_xmp_read(), comment_xmp_write(): cleanup and improve readibility.
zas_
parents:
586
diff
changeset
|
285 ExifItem *item = exif_get_item(exif, COMMENT_KEY); |
646
91dfc98f3ca1
Reading of Iptc.Application2.Keywords should now be fixed.
zas_
parents:
643
diff
changeset
|
286 |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
287 *comment = exif_item_get_string(item, 0); |
646
91dfc98f3ca1
Reading of Iptc.Application2.Keywords should now be fixed.
zas_
parents:
643
diff
changeset
|
288 *comment = utf8_validate_or_convert(*comment); |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
289 } |
442 | 290 |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
291 if (keywords) |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
292 { |
593
bb712693cad3
comment_xmp_read(), comment_xmp_write(): cleanup and improve readibility.
zas_
parents:
586
diff
changeset
|
293 ExifItem *item; |
bb712693cad3
comment_xmp_read(), comment_xmp_write(): cleanup and improve readibility.
zas_
parents:
586
diff
changeset
|
294 gint i; |
bb712693cad3
comment_xmp_read(), comment_xmp_write(): cleanup and improve readibility.
zas_
parents:
586
diff
changeset
|
295 |
bb712693cad3
comment_xmp_read(), comment_xmp_write(): cleanup and improve readibility.
zas_
parents:
586
diff
changeset
|
296 *keywords = NULL; |
bb712693cad3
comment_xmp_read(), comment_xmp_write(): cleanup and improve readibility.
zas_
parents:
586
diff
changeset
|
297 item = exif_get_item(exif, KEYWORD_KEY); |
bb712693cad3
comment_xmp_read(), comment_xmp_write(): cleanup and improve readibility.
zas_
parents:
586
diff
changeset
|
298 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
|
299 { |
bb712693cad3
comment_xmp_read(), comment_xmp_write(): cleanup and improve readibility.
zas_
parents:
586
diff
changeset
|
300 gchar *kw = exif_item_get_string(item, i); |
442 | 301 |
646
91dfc98f3ca1
Reading of Iptc.Application2.Keywords should now be fixed.
zas_
parents:
643
diff
changeset
|
302 kw = utf8_validate_or_convert(kw); |
593
bb712693cad3
comment_xmp_read(), comment_xmp_write(): cleanup and improve readibility.
zas_
parents:
586
diff
changeset
|
303 if (!kw) break; |
bb712693cad3
comment_xmp_read(), comment_xmp_write(): cleanup and improve readibility.
zas_
parents:
586
diff
changeset
|
304 *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
|
305 } |
646
91dfc98f3ca1
Reading of Iptc.Application2.Keywords should now be fixed.
zas_
parents:
643
diff
changeset
|
306 |
643
eaf94facc190
Disable non-working Iptc.Application2.Keywords reading introduced in revision 736.
zas_
parents:
642
diff
changeset
|
307 /* FIXME: |
eaf94facc190
Disable non-working Iptc.Application2.Keywords reading introduced in revision 736.
zas_
parents:
642
diff
changeset
|
308 * Exiv2 handles Iptc keywords as multiple entries with the |
eaf94facc190
Disable non-working Iptc.Application2.Keywords reading introduced in revision 736.
zas_
parents:
642
diff
changeset
|
309 * same key, thus exif_get_item returns only the first keyword |
eaf94facc190
Disable non-working Iptc.Application2.Keywords reading introduced in revision 736.
zas_
parents:
642
diff
changeset
|
310 * and the only way to get all keywords is to iterate through |
eaf94facc190
Disable non-working Iptc.Application2.Keywords reading introduced in revision 736.
zas_
parents:
642
diff
changeset
|
311 * the item list. |
eaf94facc190
Disable non-working Iptc.Application2.Keywords reading introduced in revision 736.
zas_
parents:
642
diff
changeset
|
312 */ |
646
91dfc98f3ca1
Reading of Iptc.Application2.Keywords should now be fixed.
zas_
parents:
643
diff
changeset
|
313 for (item = exif_get_first_item(exif); |
91dfc98f3ca1
Reading of Iptc.Application2.Keywords should now be fixed.
zas_
parents:
643
diff
changeset
|
314 item; |
91dfc98f3ca1
Reading of Iptc.Application2.Keywords should now be fixed.
zas_
parents:
643
diff
changeset
|
315 item = exif_get_next_item(exif)) |
642
9c74ff4bf1cd
Extract and append keywords from Iptc.Application2.Keywords tags.
zas_
parents:
604
diff
changeset
|
316 { |
646
91dfc98f3ca1
Reading of Iptc.Application2.Keywords should now be fixed.
zas_
parents:
643
diff
changeset
|
317 guint tag; |
91dfc98f3ca1
Reading of Iptc.Application2.Keywords should now be fixed.
zas_
parents:
643
diff
changeset
|
318 |
91dfc98f3ca1
Reading of Iptc.Application2.Keywords should now be fixed.
zas_
parents:
643
diff
changeset
|
319 tag = exif_item_get_tag_id(item); |
91dfc98f3ca1
Reading of Iptc.Application2.Keywords should now be fixed.
zas_
parents:
643
diff
changeset
|
320 if (tag == 0x0019) /* Iptc.Application2.Keywords */ |
91dfc98f3ca1
Reading of Iptc.Application2.Keywords should now be fixed.
zas_
parents:
643
diff
changeset
|
321 { |
91dfc98f3ca1
Reading of Iptc.Application2.Keywords should now be fixed.
zas_
parents:
643
diff
changeset
|
322 gchar *kw; |
642
9c74ff4bf1cd
Extract and append keywords from Iptc.Application2.Keywords tags.
zas_
parents:
604
diff
changeset
|
323 |
646
91dfc98f3ca1
Reading of Iptc.Application2.Keywords should now be fixed.
zas_
parents:
643
diff
changeset
|
324 kw = exif_item_get_data_as_text(item); |
91dfc98f3ca1
Reading of Iptc.Application2.Keywords should now be fixed.
zas_
parents:
643
diff
changeset
|
325 kw = utf8_validate_or_convert(kw); |
91dfc98f3ca1
Reading of Iptc.Application2.Keywords should now be fixed.
zas_
parents:
643
diff
changeset
|
326 |
91dfc98f3ca1
Reading of Iptc.Application2.Keywords should now be fixed.
zas_
parents:
643
diff
changeset
|
327 if (!kw) continue; |
91dfc98f3ca1
Reading of Iptc.Application2.Keywords should now be fixed.
zas_
parents:
643
diff
changeset
|
328 *keywords = g_list_append(*keywords, (gpointer) kw); |
91dfc98f3ca1
Reading of Iptc.Application2.Keywords should now be fixed.
zas_
parents:
643
diff
changeset
|
329 } |
642
9c74ff4bf1cd
Extract and append keywords from Iptc.Application2.Keywords tags.
zas_
parents:
604
diff
changeset
|
330 } |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
331 } |
442 | 332 |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
333 exif_free(exif); |
442 | 334 |
593
bb712693cad3
comment_xmp_read(), comment_xmp_write(): cleanup and improve readibility.
zas_
parents:
586
diff
changeset
|
335 return (comment && *comment) || (keywords && *keywords); |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
336 } |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
337 |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
338 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
|
339 { |
593
bb712693cad3
comment_xmp_read(), comment_xmp_write(): cleanup and improve readibility.
zas_
parents:
586
diff
changeset
|
340 gint success; |
bb712693cad3
comment_xmp_read(), comment_xmp_write(): cleanup and improve readibility.
zas_
parents:
586
diff
changeset
|
341 gint write_comment = (comment && comment[0]); |
bb712693cad3
comment_xmp_read(), comment_xmp_write(): cleanup and improve readibility.
zas_
parents:
586
diff
changeset
|
342 ExifData *exif; |
bb712693cad3
comment_xmp_read(), comment_xmp_write(): cleanup and improve readibility.
zas_
parents:
586
diff
changeset
|
343 ExifItem *item; |
bb712693cad3
comment_xmp_read(), comment_xmp_write(): cleanup and improve readibility.
zas_
parents:
586
diff
changeset
|
344 |
bb712693cad3
comment_xmp_read(), comment_xmp_write(): cleanup and improve readibility.
zas_
parents:
586
diff
changeset
|
345 exif = exif_read_fd(fd); |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
346 if (!exif) return FALSE; |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
347 |
593
bb712693cad3
comment_xmp_read(), comment_xmp_write(): cleanup and improve readibility.
zas_
parents:
586
diff
changeset
|
348 item = exif_get_item(exif, COMMENT_KEY); |
bb712693cad3
comment_xmp_read(), comment_xmp_write(): cleanup and improve readibility.
zas_
parents:
586
diff
changeset
|
349 if (item && !write_comment) |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
350 { |
442 | 351 exif_item_delete(exif, item); |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
352 item = NULL; |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
353 } |
442 | 354 |
593
bb712693cad3
comment_xmp_read(), comment_xmp_write(): cleanup and improve readibility.
zas_
parents:
586
diff
changeset
|
355 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
|
356 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
|
357 |
593
bb712693cad3
comment_xmp_read(), comment_xmp_write(): cleanup and improve readibility.
zas_
parents:
586
diff
changeset
|
358 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
|
359 { |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
360 exif_item_delete(exif, item); |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
361 } |
442 | 362 |
593
bb712693cad3
comment_xmp_read(), comment_xmp_write(): cleanup and improve readibility.
zas_
parents:
586
diff
changeset
|
363 if (keywords) |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
364 { |
593
bb712693cad3
comment_xmp_read(), comment_xmp_write(): cleanup and improve readibility.
zas_
parents:
586
diff
changeset
|
365 GList *work; |
442 | 366 |
593
bb712693cad3
comment_xmp_read(), comment_xmp_write(): cleanup and improve readibility.
zas_
parents:
586
diff
changeset
|
367 item = exif_add_item(exif, KEYWORD_KEY); |
bb712693cad3
comment_xmp_read(), comment_xmp_write(): cleanup and improve readibility.
zas_
parents:
586
diff
changeset
|
368 |
bb712693cad3
comment_xmp_read(), comment_xmp_write(): cleanup and improve readibility.
zas_
parents:
586
diff
changeset
|
369 work = keywords; |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
370 while (work) |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
371 { |
593
bb712693cad3
comment_xmp_read(), comment_xmp_write(): cleanup and improve readibility.
zas_
parents:
586
diff
changeset
|
372 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
|
373 work = work->next; |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
374 } |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
375 } |
442 | 376 |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
377 success = exif_write(exif); |
442 | 378 |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
379 exif_free(exif); |
442 | 380 |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
381 return success; |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
382 } |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
383 |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
384 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
|
385 { |
204 | 386 if (!fd) return FALSE; |
387 | |
594
4cfce4ed35e0
Use a dedicated option to enable keywords and comment saving as XMP tags
zas_
parents:
593
diff
changeset
|
388 if (options->save_metadata_in_image_file && |
204 | 389 comment_xmp_write(fd, keywords, comment)) |
390 { | |
391 comment_delete_legacy(fd); | |
392 return TRUE; | |
393 } | |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
394 |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
395 return comment_legacy_write(fd, keywords, comment); |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
396 } |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
397 |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
398 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
|
399 { |
253 | 400 GList *keywords1 = NULL; |
401 GList *keywords2 = NULL; | |
402 gchar *comment1 = NULL; | |
403 gchar *comment2 = NULL; | |
204 | 404 gint res1, res2; |
405 | |
406 if (!fd) return FALSE; | |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
407 |
204 | 408 res1 = comment_xmp_read(fd, &keywords1, &comment1); |
409 res2 = comment_legacy_read(fd, &keywords2, &comment2); | |
442 | 410 |
204 | 411 if (!res1 && !res2) |
412 { | |
413 return FALSE; | |
414 } | |
442 | 415 |
204 | 416 if (keywords) |
417 { | |
418 if (res1 && res2) | |
419 *keywords = g_list_concat(keywords1, keywords2); | |
420 else | |
421 *keywords = res1 ? keywords1 : keywords2; | |
642
9c74ff4bf1cd
Extract and append keywords from Iptc.Application2.Keywords tags.
zas_
parents:
604
diff
changeset
|
422 |
9c74ff4bf1cd
Extract and append keywords from Iptc.Application2.Keywords tags.
zas_
parents:
604
diff
changeset
|
423 *keywords = remove_duplicate_strings_from_list(*keywords); |
204 | 424 } |
425 else | |
426 { | |
427 if (res1) string_list_free(keywords1); | |
428 if (res2) string_list_free(keywords2); | |
429 } | |
442 | 430 |
204 | 431 |
432 if (comment) | |
433 { | |
434 if (res1 && res2 && comment1 && comment2 && comment1[0] && comment2[0]) | |
435 *comment = g_strdup_printf("%s\n%s", comment1, comment2); | |
436 else | |
437 *comment = res1 ? comment1 : comment2; | |
438 } | |
439 if (res1 && (!comment || *comment != comment1)) g_free(comment1); | |
440 if (res2 && (!comment || *comment != comment2)) g_free(comment2); | |
442 | 441 |
204 | 442 return TRUE; |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
443 } |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
444 |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
445 |
9 | 446 static gchar *comment_pull(GtkWidget *textview) |
447 { | |
448 GtkTextBuffer *buffer; | |
449 GtkTextIter start, end; | |
442 | 450 |
9 | 451 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview)); |
452 gtk_text_buffer_get_bounds(buffer, &start, &end); | |
442 | 453 |
9 | 454 return gtk_text_buffer_get_text(buffer, &start, &end, FALSE); |
455 } | |
456 | |
427
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
457 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
|
458 { |
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
459 while (list) |
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
460 { |
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
461 gchar *haystack = list->data; |
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
462 |
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
463 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
|
464 |
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
465 list = list->next; |
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
466 } |
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
467 |
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
468 return FALSE; |
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
469 } |
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
470 |
9 | 471 GList *keyword_list_pull(GtkWidget *text_widget) |
472 { | |
473 GList *list = NULL; | |
474 gchar *text; | |
475 gchar *ptr; | |
476 | |
477 if (GTK_IS_TEXT_VIEW(text_widget)) | |
478 { | |
479 text = comment_pull(text_widget); | |
480 } | |
481 else if (GTK_IS_ENTRY(text_widget)) | |
482 { | |
483 text = g_strdup(gtk_entry_get_text(GTK_ENTRY(text_widget))); | |
484 } | |
485 else | |
486 { | |
487 return NULL; | |
488 } | |
489 | |
490 ptr = text; | |
491 while (*ptr != '\0') | |
492 { | |
493 gchar *begin; | |
494 gint l = 0; | |
495 | |
427
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
496 #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
|
497 while (KEYWORDS_SEPARATOR(*ptr)) ptr++; |
9 | 498 begin = ptr; |
427
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
499 while (*ptr != '\0' && !KEYWORDS_SEPARATOR(*ptr)) |
9 | 500 { |
427
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
501 ptr++; |
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
502 l++; |
9 | 503 } |
442 | 504 |
427
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
505 /* trim starting and ending whitespaces */ |
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
506 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
|
507 while (l > 0 && g_ascii_isspace(begin[l-1])) l--; |
9 | 508 |
427
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
509 if (l > 0) |
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
510 { |
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
511 gchar *keyword = g_strndup(begin, l); |
442 | 512 |
427
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
513 /* 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
|
514 if (keyword_list_find(list, keyword) == FALSE) |
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
515 list = g_list_append(list, keyword); |
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
516 else |
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
517 g_free(keyword); |
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
518 } |
9 | 519 } |
520 | |
521 g_free(text); | |
522 | |
523 return list; | |
524 } | |
525 | |
526 void keyword_list_push(GtkWidget *textview, GList *list) | |
527 { | |
528 GtkTextBuffer *buffer; | |
529 GtkTextIter start, end; | |
530 | |
531 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview)); | |
532 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
|
533 gtk_text_buffer_delete(buffer, &start, &end); |
9 | 534 |
535 while (list) | |
536 { | |
537 const gchar *word = list->data; | |
538 GtkTextIter iter; | |
539 | |
540 gtk_text_buffer_get_end_iter(buffer, &iter); | |
541 if (word) gtk_text_buffer_insert(buffer, &iter, word, -1); | |
542 gtk_text_buffer_get_end_iter(buffer, &iter); | |
543 gtk_text_buffer_insert(buffer, &iter, "\n", -1); | |
544 | |
545 list = list->next; | |
546 } | |
547 } | |
548 | |
595
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
549 static void metadata_set_keywords(FileData *fd, GList *keywords_to_use, gchar *comment_to_use, gint add) |
9 | 550 { |
551 gchar *comment = NULL; | |
552 GList *keywords = NULL; | |
553 GList *save_list = NULL; | |
554 | |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
555 comment_read(fd, &keywords, &comment); |
595
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
556 |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
557 if (comment_to_use) |
9 | 558 { |
595
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
559 if (add && comment && *comment) |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
560 { |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
561 gchar *tmp = comment; |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
562 |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
563 comment = g_strconcat(tmp, comment_to_use, NULL); |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
564 g_free(tmp); |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
565 } |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
566 else |
9 | 567 { |
595
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
568 g_free(comment); |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
569 comment = g_strdup(comment_to_use); |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
570 } |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
571 } |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
572 |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
573 if (keywords_to_use) |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
574 { |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
575 if (add && keywords && g_list_length(keywords) > 0) |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
576 { |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
577 GList *work; |
9 | 578 |
595
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
579 work = keywords_to_use; |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
580 while (work) |
9 | 581 { |
595
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
582 gchar *key; |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
583 GList *p; |
9 | 584 |
595
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
585 key = work->data; |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
586 work = work->next; |
9 | 587 |
595
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
588 p = keywords; |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
589 while (p && key) |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
590 { |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
591 gchar *needle = p->data; |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
592 p = p->next; |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
593 |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
594 if (strcmp(needle, key) == 0) key = NULL; |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
595 } |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
596 |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
597 if (key) keywords = g_list_append(keywords, g_strdup(key)); |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
598 } |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
599 save_list = keywords; |
9 | 600 } |
595
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
601 else |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
602 { |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
603 save_list = keywords_to_use; |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
604 } |
9 | 605 } |
595
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
606 |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
607 comment_write(fd, save_list, comment); |
9 | 608 |
138 | 609 string_list_free(keywords); |
9 | 610 g_free(comment); |
611 } | |
612 | |
613 /* | |
614 *------------------------------------------------------------------- | |
615 * keyword list dialog | |
616 *------------------------------------------------------------------- | |
617 */ | |
618 | |
619 #define KEYWORD_DIALOG_WIDTH 200 | |
620 #define KEYWORD_DIALOG_HEIGHT 250 | |
621 | |
622 typedef struct _KeywordDlg KeywordDlg; | |
623 struct _KeywordDlg | |
624 { | |
625 GenericDialog *gd; | |
626 GtkWidget *treeview; | |
627 }; | |
628 | |
629 static KeywordDlg *keyword_dialog = NULL; | |
630 | |
631 | |
632 static void keyword_dialog_cancel_cb(GenericDialog *gd, gpointer data) | |
633 { | |
634 g_free(keyword_dialog); | |
635 keyword_dialog = NULL; | |
636 } | |
637 | |
638 static void keyword_dialog_ok_cb(GenericDialog *gd, gpointer data) | |
639 { | |
640 KeywordDlg *kd = data; | |
641 GtkTreeModel *store; | |
642 GtkTreeIter iter; | |
643 gint valid; | |
644 | |
645 history_list_free_key("keywords"); | |
646 | |
647 store = gtk_tree_view_get_model(GTK_TREE_VIEW(kd->treeview)); | |
648 valid = gtk_tree_model_get_iter_first(store, &iter); | |
649 while (valid) | |
650 { | |
651 gchar *key; | |
652 | |
653 gtk_tree_model_get(store, &iter, 0, &key, -1); | |
654 valid = gtk_tree_model_iter_next(store, &iter); | |
655 | |
656 history_list_add_to_key("keywords", key, 0); | |
657 } | |
658 | |
659 keyword_dialog_cancel_cb(gd, data); | |
660 | |
661 bar_info_keyword_update_all(); | |
662 } | |
663 | |
664 static void keyword_dialog_add_cb(GtkWidget *button, gpointer data) | |
665 { | |
666 KeywordDlg *kd = data; | |
667 GtkTreeSelection *selection; | |
668 GtkTreeModel *store; | |
669 GtkTreeIter sibling; | |
670 GtkTreeIter iter; | |
671 GtkTreePath *tpath; | |
672 | |
673 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(kd->treeview)); | |
674 if (gtk_tree_selection_get_selected(selection, &store, &sibling)) | |
675 { | |
676 gtk_list_store_insert_before(GTK_LIST_STORE(store), &iter, &sibling); | |
677 } | |
678 else | |
679 { | |
680 store = gtk_tree_view_get_model(GTK_TREE_VIEW(kd->treeview)); | |
681 gtk_list_store_append(GTK_LIST_STORE(store), &iter); | |
682 } | |
683 | |
684 gtk_list_store_set(GTK_LIST_STORE(store), &iter, 1, TRUE, -1); | |
685 | |
686 tpath = gtk_tree_model_get_path(store, &iter); | |
687 gtk_tree_view_set_cursor(GTK_TREE_VIEW(kd->treeview), tpath, | |
688 gtk_tree_view_get_column(GTK_TREE_VIEW(kd->treeview), 0), TRUE); | |
689 gtk_tree_path_free(tpath); | |
690 } | |
691 | |
692 static void keyword_dialog_remove_cb(GtkWidget *button, gpointer data) | |
693 { | |
694 KeywordDlg *kd = data; | |
695 GtkTreeSelection *selection; | |
696 GtkTreeModel *store; | |
697 GtkTreeIter iter; | |
698 GtkTreeIter next; | |
699 GtkTreePath *tpath; | |
700 | |
701 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(kd->treeview)); | |
702 if (!gtk_tree_selection_get_selected(selection, &store, &iter)) return; | |
703 | |
704 tpath = NULL; | |
705 next = iter; | |
706 if (gtk_tree_model_iter_next(store, &next)) | |
707 { | |
708 tpath = gtk_tree_model_get_path(store, &next); | |
709 } | |
710 else | |
711 { | |
712 tpath = gtk_tree_model_get_path(store, &iter); | |
713 if (!gtk_tree_path_prev(tpath)) | |
714 { | |
715 gtk_tree_path_free(tpath); | |
716 tpath = NULL; | |
717 } | |
718 } | |
719 if (tpath) | |
720 { | |
721 gtk_tree_view_set_cursor(GTK_TREE_VIEW(kd->treeview), tpath, | |
722 gtk_tree_view_get_column(GTK_TREE_VIEW(kd->treeview), 0), FALSE); | |
723 gtk_tree_path_free(tpath); | |
724 } | |
725 | |
726 gtk_list_store_remove(GTK_LIST_STORE(store), &iter); | |
727 } | |
728 | |
729 static void keyword_dialog_edit_cb(GtkCellRendererText *renderer, const gchar *path, | |
730 const gchar *new_text, gpointer data) | |
731 { | |
732 KeywordDlg *kd = data; | |
733 GtkTreeModel *store; | |
734 GtkTreeIter iter; | |
735 GtkTreePath *tpath; | |
736 | |
737 if (!new_text || strlen(new_text) == 0) return; | |
738 | |
739 store = gtk_tree_view_get_model(GTK_TREE_VIEW(kd->treeview)); | |
740 | |
741 tpath = gtk_tree_path_new_from_string(path); | |
742 gtk_tree_model_get_iter(store, &iter, tpath); | |
743 gtk_tree_path_free(tpath); | |
744 | |
745 gtk_list_store_set(GTK_LIST_STORE(store), &iter, 0, new_text, -1); | |
746 } | |
747 | |
748 static void keyword_dialog_populate(KeywordDlg *kd) | |
749 { | |
750 GtkListStore *store; | |
751 GList *list; | |
752 | |
753 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(kd->treeview))); | |
754 gtk_list_store_clear(store); | |
755 | |
756 list = history_list_get_by_key("keywords"); | |
757 list = g_list_last(list); | |
758 while (list) | |
759 { | |
760 GtkTreeIter iter; | |
761 | |
762 gtk_list_store_append(store, &iter); | |
763 gtk_list_store_set(store, &iter, 0, list->data, | |
764 1, TRUE, -1); | |
765 | |
766 list = list->prev; | |
767 } | |
768 } | |
769 | |
770 static void keyword_dialog_show(void) | |
771 { | |
772 GtkWidget *scrolled; | |
773 GtkListStore *store; | |
774 GtkTreeViewColumn *column; | |
775 GtkCellRenderer *renderer; | |
776 GtkWidget *hbox; | |
777 GtkWidget *button; | |
778 | |
779 if (keyword_dialog) | |
780 { | |
781 gtk_window_present(GTK_WINDOW(keyword_dialog->gd->dialog)); | |
782 return; | |
783 } | |
784 | |
785 keyword_dialog = g_new0(KeywordDlg, 1); | |
786 | |
787 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
|
788 GQ_WMCLASS, "keyword_presets", NULL, TRUE, |
9 | 789 keyword_dialog_cancel_cb, keyword_dialog); |
790 generic_dialog_add_message(keyword_dialog->gd, NULL, _("Favorite keywords list"), NULL); | |
791 | |
792 generic_dialog_add_button(keyword_dialog->gd, GTK_STOCK_OK, NULL, | |
793 keyword_dialog_ok_cb, TRUE); | |
794 | |
795 scrolled = gtk_scrolled_window_new(NULL, NULL); | |
796 gtk_widget_set_size_request(scrolled, KEYWORD_DIALOG_WIDTH, KEYWORD_DIALOG_HEIGHT); | |
797 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); | |
798 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), | |
799 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
800 gtk_box_pack_start(GTK_BOX(keyword_dialog->gd->vbox), scrolled, TRUE, TRUE, 5); | |
801 gtk_widget_show(scrolled); | |
802 | |
803 store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_BOOLEAN); | |
804 keyword_dialog->treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); | |
805 g_object_unref(store); | |
806 | |
807 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(keyword_dialog->treeview), FALSE); | |
808 gtk_tree_view_set_search_column(GTK_TREE_VIEW(keyword_dialog->treeview), 0); | |
809 gtk_tree_view_set_reorderable(GTK_TREE_VIEW(keyword_dialog->treeview), TRUE); | |
810 | |
811 column = gtk_tree_view_column_new(); | |
812 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); | |
813 renderer = gtk_cell_renderer_text_new(); | |
814 g_signal_connect(G_OBJECT(renderer), "edited", | |
815 G_CALLBACK(keyword_dialog_edit_cb), keyword_dialog); | |
816 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
817 gtk_tree_view_column_add_attribute(column, renderer, "text", 0); | |
818 gtk_tree_view_column_add_attribute(column, renderer, "editable", 1); | |
819 gtk_tree_view_append_column(GTK_TREE_VIEW(keyword_dialog->treeview), column); | |
820 | |
821 gtk_container_add(GTK_CONTAINER(scrolled), keyword_dialog->treeview); | |
822 gtk_widget_show(keyword_dialog->treeview); | |
823 | |
824 hbox = gtk_hbox_new(FALSE, 5); | |
825 gtk_box_pack_start(GTK_BOX(keyword_dialog->gd->vbox), hbox, FALSE, FALSE, 0); | |
826 gtk_widget_show(hbox); | |
827 | |
828 button = gtk_button_new_from_stock(GTK_STOCK_ADD); | |
829 g_signal_connect(G_OBJECT(button), "clicked", | |
830 G_CALLBACK(keyword_dialog_add_cb), keyword_dialog); | |
831 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
832 gtk_widget_show(button); | |
833 | |
834 button = gtk_button_new_from_stock(GTK_STOCK_REMOVE); | |
835 g_signal_connect(G_OBJECT(button), "clicked", | |
836 G_CALLBACK(keyword_dialog_remove_cb), keyword_dialog); | |
837 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
838 gtk_widget_show(button); | |
839 | |
840 keyword_dialog_populate(keyword_dialog); | |
841 | |
842 gtk_widget_show(keyword_dialog->gd->dialog); | |
843 } | |
844 | |
845 | |
846 static void bar_keyword_edit_cb(GtkWidget *button, gpointer data) | |
847 { | |
848 keyword_dialog_show(); | |
849 } | |
850 | |
851 | |
852 /* | |
853 *------------------------------------------------------------------- | |
854 * info bar | |
855 *------------------------------------------------------------------- | |
856 */ | |
857 | |
858 typedef enum { | |
859 BAR_SORT_COPY, | |
860 BAR_SORT_MOVE, | |
861 BAR_SORT_LINK | |
862 } SortActionType; | |
863 | |
864 enum { | |
865 KEYWORD_COLUMN_TOGGLE = 0, | |
866 KEYWORD_COLUMN_TEXT | |
867 }; | |
868 | |
869 typedef struct _BarInfoData BarInfoData; | |
870 struct _BarInfoData | |
871 { | |
872 GtkWidget *vbox; | |
873 GtkWidget *group_box; | |
874 GtkWidget *label_file_name; | |
875 GtkWidget *label_file_time; | |
876 | |
877 GtkWidget *keyword_view; | |
878 GtkWidget *keyword_treeview; | |
879 | |
880 GtkWidget *comment_view; | |
881 | |
882 GtkWidget *button_save; | |
595
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
883 GtkWidget *button_set_keywords_add; |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
884 GtkWidget *button_set_keywords_replace; |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
885 GtkWidget *button_set_comment_add; |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
886 GtkWidget *button_set_comment_replace; |
9 | 887 |
138 | 888 FileData *fd; |
9 | 889 |
890 gint changed; | |
891 gint save_timeout_id; | |
892 | |
893 GList *(*list_func)(gpointer); | |
894 gpointer list_data; | |
895 }; | |
896 | |
897 | |
898 static GList *bar_list = NULL; | |
899 | |
900 | |
901 static void bar_info_write(BarInfoData *bd) | |
902 { | |
903 GList *list; | |
904 gchar *comment; | |
905 | |
138 | 906 if (!bd->fd) return; |
9 | 907 |
908 list = keyword_list_pull(bd->keyword_view); | |
909 comment = comment_pull(bd->comment_view); | |
910 | |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
911 comment_write(bd->fd, list, comment); |
9 | 912 |
138 | 913 string_list_free(list); |
9 | 914 g_free(comment); |
915 | |
916 bd->changed = FALSE; | |
917 gtk_widget_set_sensitive(bd->button_save, FALSE); | |
918 } | |
919 | |
920 static gint bar_info_autosave(gpointer data) | |
921 { | |
922 BarInfoData *bd = data; | |
923 | |
924 bar_info_write(bd); | |
925 | |
926 bd->save_timeout_id = -1; | |
927 | |
928 return FALSE; | |
929 } | |
930 | |
931 static void bar_info_save_update(BarInfoData *bd, gint enable) | |
932 { | |
933 if (bd->save_timeout_id != -1) | |
934 { | |
935 g_source_remove(bd->save_timeout_id); | |
936 bd->save_timeout_id = -1; | |
937 } | |
938 if (enable) | |
939 { | |
940 bd->save_timeout_id = g_timeout_add(BAR_KEYWORD_AUTOSAVE_TIME, bar_info_autosave, bd); | |
941 } | |
942 } | |
943 | |
944 static void bar_keyword_list_sync(BarInfoData *bd, GList *keywords) | |
945 { | |
946 GList *list; | |
947 GtkListStore *store; | |
948 GtkTreeIter iter; | |
949 | |
950 list = history_list_get_by_key("keywords"); | |
951 if (!list) | |
952 { | |
953 /* blank? set up a few example defaults */ | |
954 | |
955 gint i = 0; | |
956 | |
957 while (keyword_favorite_defaults[i] != NULL) | |
958 { | |
959 history_list_add_to_key("keywords", _(keyword_favorite_defaults[i]), 0); | |
960 i++; | |
961 } | |
962 | |
963 list = history_list_get_by_key("keywords"); | |
964 } | |
965 | |
966 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(bd->keyword_treeview))); | |
967 | |
968 gtk_list_store_clear(store); | |
969 | |
970 list = g_list_last(list); | |
971 while (list) | |
972 { | |
973 gchar *key = list->data; | |
974 | |
975 gtk_list_store_append(store, &iter); | |
427
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
976 gtk_list_store_set(store, &iter, KEYWORD_COLUMN_TOGGLE, keyword_list_find(keywords, key), |
9 | 977 KEYWORD_COLUMN_TEXT, key, -1); |
978 | |
979 list = list->prev; | |
980 } | |
981 } | |
982 | |
983 static void bar_info_keyword_update_all(void) | |
984 { | |
985 GList *work; | |
986 | |
987 work = bar_list; | |
988 while (work) | |
989 { | |
990 BarInfoData *bd; | |
991 GList *keywords; | |
992 | |
993 bd = work->data; | |
994 work = work->next; | |
995 | |
996 keywords = keyword_list_pull(bd->keyword_view); | |
997 bar_keyword_list_sync(bd, keywords); | |
138 | 998 string_list_free(keywords); |
9 | 999 } |
1000 } | |
1001 | |
1002 static void bar_info_update(BarInfoData *bd) | |
1003 { | |
1004 GList *keywords = NULL; | |
1005 gchar *comment = NULL; | |
1006 | |
1007 if (bd->label_file_name) | |
1008 { | |
138 | 1009 gtk_label_set_text(GTK_LABEL(bd->label_file_name), (bd->fd) ? bd->fd->name : ""); |
9 | 1010 } |
1011 if (bd->label_file_time) | |
1012 { | |
138 | 1013 gtk_label_set_text(GTK_LABEL(bd->label_file_time), (bd->fd) ? text_from_time(bd->fd->date) : ""); |
9 | 1014 } |
1015 | |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
1016 if (comment_read(bd->fd, &keywords, &comment)) |
9 | 1017 { |
1018 keyword_list_push(bd->keyword_view, keywords); | |
1019 gtk_text_buffer_set_text(gtk_text_view_get_buffer(GTK_TEXT_VIEW(bd->comment_view)), | |
1020 (comment) ? comment : "", -1); | |
1021 | |
1022 bar_keyword_list_sync(bd, keywords); | |
1023 | |
138 | 1024 string_list_free(keywords); |
9 | 1025 g_free(comment); |
1026 } | |
1027 else | |
1028 { | |
1029 gtk_text_buffer_set_text(gtk_text_view_get_buffer(GTK_TEXT_VIEW(bd->keyword_view)), "", -1); | |
1030 gtk_text_buffer_set_text(gtk_text_view_get_buffer(GTK_TEXT_VIEW(bd->comment_view)), "", -1); | |
1031 | |
1032 bar_keyword_list_sync(bd, NULL); | |
1033 } | |
1034 | |
1035 bar_info_save_update(bd, FALSE); | |
1036 bd->changed = FALSE; | |
1037 gtk_widget_set_sensitive(bd->button_save, FALSE); | |
1038 | |
138 | 1039 gtk_widget_set_sensitive(bd->group_box, (bd->fd != NULL)); |
9 | 1040 } |
1041 | |
138 | 1042 void bar_info_set(GtkWidget *bar, FileData *fd) |
9 | 1043 { |
1044 BarInfoData *bd; | |
1045 | |
1046 bd = g_object_get_data(G_OBJECT(bar), "bar_info_data"); | |
1047 if (!bd) return; | |
1048 | |
1049 if (bd->changed) bar_info_write(bd); | |
1050 | |
138 | 1051 file_data_unref(bd->fd); |
1052 bd->fd = file_data_ref(fd); | |
9 | 1053 |
1054 bar_info_update(bd); | |
1055 } | |
1056 | |
138 | 1057 void bar_info_maint_renamed(GtkWidget *bar, FileData *fd) |
9 | 1058 { |
1059 BarInfoData *bd; | |
1060 | |
1061 bd = g_object_get_data(G_OBJECT(bar), "bar_info_data"); | |
1062 if (!bd) return; | |
1063 | |
138 | 1064 file_data_unref(bd->fd); |
1065 bd->fd = file_data_ref(fd); | |
9 | 1066 |
1067 if (bd->label_file_name) | |
1068 { | |
138 | 1069 gtk_label_set_text(GTK_LABEL(bd->label_file_name), (bd->fd) ? bd->fd->name : ""); |
9 | 1070 } |
1071 } | |
1072 | |
1073 gint bar_info_event(GtkWidget *bar, GdkEvent *event) | |
1074 { | |
1075 BarInfoData *bd; | |
1076 | |
1077 bd = g_object_get_data(G_OBJECT(bar), "bar_info_data"); | |
1078 if (!bd) return FALSE; | |
1079 | |
1080 if (GTK_WIDGET_HAS_FOCUS(bd->keyword_view)) return gtk_widget_event(bd->keyword_view, event); | |
1081 if (GTK_WIDGET_HAS_FOCUS(bd->comment_view)) return gtk_widget_event(bd->comment_view, event); | |
1082 | |
1083 return FALSE; | |
1084 } | |
1085 | |
1086 static void bar_info_keyword_set(BarInfoData *bd, const gchar *keyword, gint active) | |
1087 { | |
1088 GList *list; | |
1089 gint found; | |
1090 | |
1091 if (!keyword) return; | |
1092 | |
1093 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
|
1094 found = keyword_list_find(list, keyword); |
9 | 1095 |
1096 if (active != found) | |
1097 { | |
1098 if (found) | |
1099 { | |
1100 GList *work = list; | |
1101 | |
1102 while (work) | |
1103 { | |
1104 gchar *key = work->data; | |
1105 work = work->next; | |
1106 | |
1107 if (key && keyword && strcmp(key, keyword) == 0) | |
1108 { | |
1109 list = g_list_remove(list, key); | |
1110 g_free(key); | |
1111 } | |
1112 } | |
1113 } | |
1114 else | |
1115 { | |
1116 list = g_list_append(list, g_strdup(keyword)); | |
1117 } | |
1118 | |
1119 keyword_list_push(bd->keyword_view, list); | |
1120 } | |
1121 | |
138 | 1122 string_list_free(list); |
9 | 1123 } |
1124 | |
1125 static void bar_info_keyword_toggle(GtkCellRendererToggle *toggle, const gchar *path, gpointer data) | |
1126 { | |
1127 BarInfoData *bd = data; | |
1128 GtkTreeModel *store; | |
1129 GtkTreeIter iter; | |
1130 GtkTreePath *tpath; | |
1131 gchar *key = NULL; | |
1132 gboolean active; | |
1133 | |
1134 store = gtk_tree_view_get_model(GTK_TREE_VIEW(bd->keyword_treeview)); | |
1135 | |
1136 tpath = gtk_tree_path_new_from_string(path); | |
1137 gtk_tree_model_get_iter(store, &iter, tpath); | |
1138 gtk_tree_path_free(tpath); | |
1139 | |
1140 gtk_tree_model_get(store, &iter, KEYWORD_COLUMN_TOGGLE, &active, | |
1141 KEYWORD_COLUMN_TEXT, &key, -1); | |
1142 active = (!active); | |
1143 gtk_list_store_set(GTK_LIST_STORE(store), &iter, KEYWORD_COLUMN_TOGGLE, active, -1); | |
1144 | |
1145 bar_info_keyword_set(bd, key, active); | |
1146 g_free(key); | |
1147 } | |
1148 | |
1149 static void bar_info_save(GtkWidget *button, gpointer data) | |
1150 { | |
1151 BarInfoData *bd = data; | |
1152 | |
1153 bar_info_save_update(bd, FALSE); | |
1154 bar_info_write(bd); | |
1155 } | |
1156 | |
595
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1157 static void bar_info_set_selection(BarInfoData *bd, gint set_keywords, gint set_comment, gint add) |
9 | 1158 { |
595
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1159 GList *keywords = NULL; |
9 | 1160 GList *list = NULL; |
1161 GList *work; | |
595
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1162 gchar *comment = NULL; |
9 | 1163 |
1164 if (!bd->list_func) return; | |
1165 | |
595
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1166 if (set_keywords) |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1167 { |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1168 keywords = keyword_list_pull(bd->keyword_view); |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1169 } |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1170 |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1171 if (set_comment) |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1172 { |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1173 comment = comment_pull(bd->comment_view); |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1174 } |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1175 |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1176 if (add && !keywords && !comment) return; |
9 | 1177 |
1178 list = bd->list_func(bd->list_data); | |
1179 work = list; | |
1180 while (work) | |
1181 { | |
138 | 1182 FileData *fd = work->data; |
9 | 1183 work = work->next; |
1184 | |
595
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1185 metadata_set_keywords(fd, keywords, comment, add); |
9 | 1186 } |
1187 | |
138 | 1188 filelist_free(list); |
1189 string_list_free(keywords); | |
595
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1190 g_free(comment); |
9 | 1191 } |
1192 | |
595
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1193 static void bar_info_set_keywords_add(GtkWidget *button, gpointer data) |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1194 { |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1195 BarInfoData *bd = data; |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1196 |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1197 bar_info_set_selection(bd, TRUE, FALSE, TRUE); |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1198 } |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1199 |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1200 static void bar_info_set_keywords_replace(GtkWidget *button, gpointer data) |
9 | 1201 { |
1202 BarInfoData *bd = data; | |
1203 | |
595
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1204 bar_info_set_selection(bd, TRUE, FALSE, FALSE); |
9 | 1205 } |
1206 | |
595
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1207 static void bar_info_set_comment_add(GtkWidget *button, gpointer data) |
9 | 1208 { |
1209 BarInfoData *bd = data; | |
1210 | |
595
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1211 bar_info_set_selection(bd, FALSE, TRUE, TRUE); |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1212 } |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1213 |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1214 static void bar_info_set_comment_replace(GtkWidget *button, gpointer data) |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1215 { |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1216 BarInfoData *bd = data; |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1217 |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1218 bar_info_set_selection(bd, FALSE, TRUE, FALSE); |
9 | 1219 } |
1220 | |
1221 static void bar_info_changed(GtkTextBuffer *buffer, gpointer data) | |
1222 { | |
1223 BarInfoData *bd = data; | |
1224 | |
1225 bd->changed = TRUE; | |
1226 gtk_widget_set_sensitive(bd->button_save, TRUE); | |
1227 | |
1228 bar_info_save_update(bd, TRUE); | |
1229 } | |
1230 | |
1231 void bar_info_close(GtkWidget *bar) | |
1232 { | |
1233 BarInfoData *bd; | |
1234 | |
1235 bd = g_object_get_data(G_OBJECT(bar), "bar_info_data"); | |
1236 if (!bd) return; | |
1237 | |
1238 gtk_widget_destroy(bd->vbox); | |
1239 } | |
1240 | |
1241 static void bar_info_destroy(GtkWidget *widget, gpointer data) | |
1242 { | |
1243 BarInfoData *bd = data; | |
1244 | |
1245 if (bd->changed) bar_info_write(bd); | |
1246 bar_info_save_update(bd, FALSE); | |
1247 | |
1248 bar_list = g_list_remove(bar_list, bd); | |
1249 | |
138 | 1250 file_data_unref(bd->fd); |
9 | 1251 |
1252 g_free(bd); | |
1253 } | |
1254 | |
138 | 1255 GtkWidget *bar_info_new(FileData *fd, gint metadata_only, GtkWidget *bounding_widget) |
9 | 1256 { |
1257 BarInfoData *bd; | |
1258 GtkWidget *box; | |
1259 GtkWidget *hbox; | |
1260 GtkWidget *table; | |
1261 GtkWidget *scrolled; | |
1262 GtkTextBuffer *buffer; | |
1263 GtkWidget *label; | |
1264 GtkWidget *tbar; | |
1265 GtkListStore *store; | |
1266 GtkTreeViewColumn *column; | |
1267 GtkCellRenderer *renderer; | |
1268 | |
1269 bd = g_new0(BarInfoData, 1); | |
1270 | |
1271 bd->list_func = NULL; | |
1272 bd->list_data = NULL; | |
1273 | |
1274 bd->vbox = gtk_vbox_new(FALSE, PREF_PAD_GAP); | |
1275 g_object_set_data(G_OBJECT(bd->vbox), "bar_info_data", bd); | |
1276 g_signal_connect(G_OBJECT(bd->vbox), "destroy", | |
1277 G_CALLBACK(bar_info_destroy), bd); | |
1278 | |
1279 if (!metadata_only) | |
1280 { | |
1281 hbox = pref_box_new(bd->vbox, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_GAP); | |
1282 | |
1283 label = sizer_new(bd->vbox, bounding_widget, SIZER_POS_LEFT); | |
1284 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
1285 gtk_widget_show(label); | |
1286 | |
1287 label = gtk_label_new(_("Keywords")); | |
1288 pref_label_bold(label, TRUE, FALSE); | |
1289 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0); | |
1290 gtk_widget_show(label); | |
1291 } | |
1292 | |
1293 bd->group_box = pref_box_new(bd->vbox, TRUE, GTK_ORIENTATION_VERTICAL, PREF_PAD_GAP); | |
1294 | |
1295 if (!metadata_only) | |
1296 { | |
1297 GtkWidget *table; | |
1298 | |
1299 table = pref_table_new(bd->group_box, 2, 2, FALSE, FALSE); | |
1300 | |
1301 bd->label_file_name = table_add_line(table, 0, 0, _("Filename:"), NULL); | |
1302 bd->label_file_time = table_add_line(table, 0, 1, _("File date:"), NULL); | |
1303 } | |
1304 else | |
1305 { | |
1306 bd->label_file_name = NULL; | |
1307 bd->label_file_time = NULL; | |
1308 } | |
1309 | |
1310 table = gtk_table_new(3, 1, TRUE); | |
1311 gtk_table_set_row_spacings(GTK_TABLE(table), PREF_PAD_GAP); | |
1312 gtk_box_pack_start(GTK_BOX(bd->group_box), table, TRUE, TRUE, 0); | |
1313 gtk_widget_show(table); | |
1314 | |
1315 /* keyword entry */ | |
1316 | |
1317 box = gtk_vbox_new(FALSE, 0); | |
1318 gtk_table_attach(GTK_TABLE(table), box, 0, 1, 0, 2, | |
1319 GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); | |
1320 gtk_widget_show(box); | |
1321 | |
1322 label = pref_label_new(box, _("Keywords:")); | |
1323 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); | |
1324 pref_label_bold(label, TRUE, FALSE); | |
1325 | |
1326 hbox = pref_box_new(box, TRUE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_GAP); | |
1327 | |
1328 scrolled = gtk_scrolled_window_new(NULL, NULL); | |
1329 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); | |
1330 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), | |
1331 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
1332 gtk_box_pack_start(GTK_BOX(hbox), scrolled, TRUE, TRUE, 0); | |
1333 gtk_widget_show(scrolled); | |
1334 | |
1335 bd->keyword_view = gtk_text_view_new(); | |
1336 gtk_container_add(GTK_CONTAINER(scrolled), bd->keyword_view); | |
1337 gtk_widget_show(bd->keyword_view); | |
1338 | |
1339 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(bd->keyword_view)); | |
1340 g_signal_connect(G_OBJECT(buffer), "changed", | |
1341 G_CALLBACK(bar_info_changed), bd); | |
1342 | |
1343 scrolled = gtk_scrolled_window_new(NULL, NULL); | |
1344 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); | |
1345 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), | |
1346 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
1347 gtk_box_pack_start(GTK_BOX(hbox), scrolled, TRUE, TRUE, 0); | |
1348 gtk_widget_show(scrolled); | |
1349 | |
1350 store = gtk_list_store_new(2, G_TYPE_BOOLEAN, G_TYPE_STRING); | |
1351 bd->keyword_treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); | |
1352 g_object_unref(store); | |
1353 | |
1354 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(bd->keyword_treeview), FALSE); | |
1355 | |
1356 if (metadata_only) | |
1357 { | |
1358 gtk_tree_view_set_search_column(GTK_TREE_VIEW(bd->keyword_treeview), KEYWORD_COLUMN_TEXT); | |
1359 } | |
1360 else | |
1361 { | |
1362 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(bd->keyword_treeview), FALSE); | |
1363 } | |
1364 | |
1365 column = gtk_tree_view_column_new(); | |
1366 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); | |
1367 | |
1368 renderer = gtk_cell_renderer_toggle_new(); | |
1369 gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
1370 gtk_tree_view_column_add_attribute(column, renderer, "active", KEYWORD_COLUMN_TOGGLE); | |
1371 g_signal_connect(G_OBJECT(renderer), "toggled", | |
1372 G_CALLBACK(bar_info_keyword_toggle), bd); | |
1373 | |
1374 renderer = gtk_cell_renderer_text_new(); | |
1375 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
1376 gtk_tree_view_column_add_attribute(column, renderer, "text", KEYWORD_COLUMN_TEXT); | |
1377 | |
1378 gtk_tree_view_append_column(GTK_TREE_VIEW(bd->keyword_treeview), column); | |
1379 | |
1380 gtk_container_add(GTK_CONTAINER(scrolled), bd->keyword_treeview); | |
1381 gtk_widget_show(bd->keyword_treeview); | |
1382 | |
1383 /* comment entry */ | |
1384 | |
1385 box = gtk_vbox_new(FALSE, 0); | |
1386 gtk_table_attach(GTK_TABLE(table), box, 0, 1, 2, 3, | |
1387 GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); | |
1388 gtk_widget_show(box); | |
1389 | |
1390 label = pref_label_new(box, _("Comment:")); | |
1391 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); | |
1392 pref_label_bold(label, TRUE, FALSE); | |
1393 | |
1394 scrolled = gtk_scrolled_window_new(NULL, NULL); | |
1395 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); | |
1396 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), | |
1397 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
1398 gtk_box_pack_start(GTK_BOX(box), scrolled, TRUE, TRUE, 0); | |
1399 gtk_widget_show(scrolled); | |
1400 | |
1401 bd->comment_view = gtk_text_view_new(); | |
1402 gtk_container_add(GTK_CONTAINER(scrolled), bd->comment_view); | |
1403 gtk_widget_show(bd->comment_view); | |
1404 | |
1405 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(bd->comment_view)); | |
1406 g_signal_connect(G_OBJECT(buffer), "changed", | |
1407 G_CALLBACK(bar_info_changed), bd); | |
1408 | |
1409 /* toolbar */ | |
1410 | |
1411 tbar = pref_toolbar_new(bd->group_box, GTK_TOOLBAR_ICONS); | |
1412 | |
41
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
1413 pref_toolbar_button(tbar, GTK_STOCK_INDEX, NULL, FALSE, |
9 | 1414 _("Edit favorite keywords list."), |
1415 G_CALLBACK(bar_keyword_edit_cb), bd); | |
1416 pref_toolbar_spacer(tbar); | |
595
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1417 bd->button_set_keywords_add = pref_toolbar_button(tbar, GTK_STOCK_ADD, NULL, FALSE, |
9 | 1418 _("Add keywords to selected files"), |
595
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1419 G_CALLBACK(bar_info_set_keywords_add), bd); |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1420 bd->button_set_keywords_replace = pref_toolbar_button(tbar, GTK_STOCK_CONVERT, NULL, FALSE, |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1421 _("Add keywords to selected files, replacing existing ones"), |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1422 G_CALLBACK(bar_info_set_keywords_replace), bd); |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1423 bd->button_set_comment_add = pref_toolbar_button(tbar, GTK_STOCK_DND_MULTIPLE, NULL, FALSE, |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1424 _("Add comment to selected files"), |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1425 G_CALLBACK(bar_info_set_comment_add), bd); |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1426 bd->button_set_comment_replace = pref_toolbar_button(tbar, GTK_STOCK_DND, NULL, FALSE, |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1427 _("Add comment to selected files, replacing existing one"), |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1428 G_CALLBACK(bar_info_set_comment_replace), bd); |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1429 |
9 | 1430 pref_toolbar_spacer(tbar); |
41
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
1431 bd->button_save = pref_toolbar_button(tbar, GTK_STOCK_SAVE, NULL, FALSE, |
9 | 1432 _("Save comment now"), |
1433 G_CALLBACK(bar_info_save), bd); | |
1434 | |
1435 bd->save_timeout_id = -1; | |
1436 | |
138 | 1437 bd->fd = file_data_ref(fd); |
9 | 1438 bar_info_update(bd); |
1439 | |
1440 bar_info_selection(bd->vbox, 0); | |
1441 | |
1442 bar_list = g_list_append(bar_list, bd); | |
442 | 1443 |
9 | 1444 return bd->vbox; |
1445 } | |
1446 | |
1447 void bar_info_set_selection_func(GtkWidget *bar, GList *(*list_func)(gpointer data), gpointer data) | |
1448 { | |
1449 BarInfoData *bd; | |
1450 | |
1451 bd = g_object_get_data(G_OBJECT(bar), "bar_info_data"); | |
1452 if (!bd) return; | |
1453 | |
1454 bd->list_func = list_func; | |
1455 bd->list_data = data; | |
1456 } | |
1457 | |
1458 void bar_info_selection(GtkWidget *bar, gint count) | |
1459 { | |
1460 BarInfoData *bd; | |
1461 gint enable; | |
1462 | |
1463 bd = g_object_get_data(G_OBJECT(bar), "bar_info_data"); | |
1464 if (!bd) return; | |
1465 | |
1466 enable = (count > 0 && bd->list_func != NULL); | |
1467 | |
595
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1468 gtk_widget_set_sensitive(bd->button_set_keywords_add, enable); |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1469 gtk_widget_set_sensitive(bd->button_set_keywords_replace, enable); |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1470 gtk_widget_set_sensitive(bd->button_set_comment_add, enable); |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1471 gtk_widget_set_sensitive(bd->button_set_comment_replace, enable); |
15766932414c
Allow the user to append or replace comments for a group of selected files.
zas_
parents:
594
diff
changeset
|
1472 |
9 | 1473 } |