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