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