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