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