Mercurial > geeqie.yaz
annotate src/bar_info.c @ 431:d7272434b8c2
Sort options.
author | zas_ |
---|---|
date | Sat, 19 Apr 2008 21:18:24 +0000 |
parents | 134beb10d916 |
children | 4b2d7f9af171 |
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 | |
427
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
228 const gchar *comment_key = "Xmp.dc.description"; |
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
229 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
|
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 | |
427
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
382 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
|
383 { |
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
384 while (list) |
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
385 { |
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
386 gchar *haystack = list->data; |
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
387 |
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
388 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
|
389 |
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
390 list = list->next; |
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
391 } |
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
392 |
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
393 return FALSE; |
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
394 } |
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
395 |
9 | 396 GList *keyword_list_pull(GtkWidget *text_widget) |
397 { | |
398 GList *list = NULL; | |
399 gchar *text; | |
400 gchar *ptr; | |
401 | |
402 if (GTK_IS_TEXT_VIEW(text_widget)) | |
403 { | |
404 text = comment_pull(text_widget); | |
405 } | |
406 else if (GTK_IS_ENTRY(text_widget)) | |
407 { | |
408 text = g_strdup(gtk_entry_get_text(GTK_ENTRY(text_widget))); | |
409 } | |
410 else | |
411 { | |
412 return NULL; | |
413 } | |
414 | |
415 ptr = text; | |
416 while (*ptr != '\0') | |
417 { | |
418 gchar *begin; | |
419 gint l = 0; | |
420 | |
427
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
421 #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
|
422 while (KEYWORDS_SEPARATOR(*ptr)) ptr++; |
9 | 423 begin = ptr; |
427
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
424 while (*ptr != '\0' && !KEYWORDS_SEPARATOR(*ptr)) |
9 | 425 { |
427
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
426 ptr++; |
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
427 l++; |
9 | 428 } |
427
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
429 |
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
430 /* trim starting and ending whitespaces */ |
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
431 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
|
432 while (l > 0 && g_ascii_isspace(begin[l-1])) l--; |
9 | 433 |
427
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
434 if (l > 0) |
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
435 { |
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
436 gchar *keyword = g_strndup(begin, l); |
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
437 |
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
438 /* 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
|
439 if (keyword_list_find(list, keyword) == FALSE) |
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
440 list = g_list_append(list, keyword); |
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
441 else |
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
442 g_free(keyword); |
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
443 } |
9 | 444 } |
445 | |
446 g_free(text); | |
447 | |
448 return list; | |
449 } | |
450 | |
451 void keyword_list_push(GtkWidget *textview, GList *list) | |
452 { | |
453 GtkTextBuffer *buffer; | |
454 GtkTextIter start, end; | |
455 | |
456 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview)); | |
457 gtk_text_buffer_get_bounds(buffer, &start, &end); | |
458 gtk_text_buffer_delete (buffer, &start, &end); | |
459 | |
460 while (list) | |
461 { | |
462 const gchar *word = list->data; | |
463 GtkTextIter iter; | |
464 | |
465 gtk_text_buffer_get_end_iter(buffer, &iter); | |
466 if (word) gtk_text_buffer_insert(buffer, &iter, word, -1); | |
467 gtk_text_buffer_get_end_iter(buffer, &iter); | |
468 gtk_text_buffer_insert(buffer, &iter, "\n", -1); | |
469 | |
470 list = list->next; | |
471 } | |
472 } | |
473 | |
138 | 474 static void metadata_set_keywords(FileData *fd, GList *list, gint add) |
9 | 475 { |
476 gchar *comment = NULL; | |
477 GList *keywords = NULL; | |
478 GList *save_list = NULL; | |
479 | |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
480 comment_read(fd, &keywords, &comment); |
9 | 481 |
482 if (add) | |
483 { | |
484 GList *work; | |
485 | |
486 work = list; | |
487 while (work) | |
488 { | |
489 gchar *key; | |
490 GList *p; | |
491 | |
492 key = work->data; | |
493 work = work->next; | |
494 | |
495 p = keywords; | |
496 while (p && key) | |
497 { | |
498 gchar *needle = p->data; | |
499 p = p->next; | |
500 | |
501 if (strcmp(needle, key) == 0) key = NULL; | |
502 } | |
503 | |
504 if (key) keywords = g_list_append(keywords, g_strdup(key)); | |
505 } | |
506 save_list = keywords; | |
507 } | |
508 else | |
509 { | |
510 save_list = list; | |
511 } | |
512 | |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
513 comment_write(fd, save_list, comment); |
9 | 514 |
138 | 515 string_list_free(keywords); |
9 | 516 g_free(comment); |
517 } | |
518 | |
519 /* | |
520 *------------------------------------------------------------------- | |
521 * keyword list dialog | |
522 *------------------------------------------------------------------- | |
523 */ | |
524 | |
525 #define KEYWORD_DIALOG_WIDTH 200 | |
526 #define KEYWORD_DIALOG_HEIGHT 250 | |
527 | |
528 typedef struct _KeywordDlg KeywordDlg; | |
529 struct _KeywordDlg | |
530 { | |
531 GenericDialog *gd; | |
532 GtkWidget *treeview; | |
533 }; | |
534 | |
535 static KeywordDlg *keyword_dialog = NULL; | |
536 | |
537 | |
538 static void keyword_dialog_cancel_cb(GenericDialog *gd, gpointer data) | |
539 { | |
540 g_free(keyword_dialog); | |
541 keyword_dialog = NULL; | |
542 } | |
543 | |
544 static void keyword_dialog_ok_cb(GenericDialog *gd, gpointer data) | |
545 { | |
546 KeywordDlg *kd = data; | |
547 GtkTreeModel *store; | |
548 GtkTreeIter iter; | |
549 gint valid; | |
550 | |
551 history_list_free_key("keywords"); | |
552 | |
553 store = gtk_tree_view_get_model(GTK_TREE_VIEW(kd->treeview)); | |
554 valid = gtk_tree_model_get_iter_first(store, &iter); | |
555 while (valid) | |
556 { | |
557 gchar *key; | |
558 | |
559 gtk_tree_model_get(store, &iter, 0, &key, -1); | |
560 valid = gtk_tree_model_iter_next(store, &iter); | |
561 | |
562 history_list_add_to_key("keywords", key, 0); | |
563 } | |
564 | |
565 keyword_dialog_cancel_cb(gd, data); | |
566 | |
567 bar_info_keyword_update_all(); | |
568 } | |
569 | |
570 static void keyword_dialog_add_cb(GtkWidget *button, gpointer data) | |
571 { | |
572 KeywordDlg *kd = data; | |
573 GtkTreeSelection *selection; | |
574 GtkTreeModel *store; | |
575 GtkTreeIter sibling; | |
576 GtkTreeIter iter; | |
577 GtkTreePath *tpath; | |
578 | |
579 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(kd->treeview)); | |
580 if (gtk_tree_selection_get_selected(selection, &store, &sibling)) | |
581 { | |
582 gtk_list_store_insert_before(GTK_LIST_STORE(store), &iter, &sibling); | |
583 } | |
584 else | |
585 { | |
586 store = gtk_tree_view_get_model(GTK_TREE_VIEW(kd->treeview)); | |
587 gtk_list_store_append(GTK_LIST_STORE(store), &iter); | |
588 } | |
589 | |
590 gtk_list_store_set(GTK_LIST_STORE(store), &iter, 1, TRUE, -1); | |
591 | |
592 tpath = gtk_tree_model_get_path(store, &iter); | |
593 gtk_tree_view_set_cursor(GTK_TREE_VIEW(kd->treeview), tpath, | |
594 gtk_tree_view_get_column(GTK_TREE_VIEW(kd->treeview), 0), TRUE); | |
595 gtk_tree_path_free(tpath); | |
596 } | |
597 | |
598 static void keyword_dialog_remove_cb(GtkWidget *button, gpointer data) | |
599 { | |
600 KeywordDlg *kd = data; | |
601 GtkTreeSelection *selection; | |
602 GtkTreeModel *store; | |
603 GtkTreeIter iter; | |
604 GtkTreeIter next; | |
605 GtkTreePath *tpath; | |
606 | |
607 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(kd->treeview)); | |
608 if (!gtk_tree_selection_get_selected(selection, &store, &iter)) return; | |
609 | |
610 tpath = NULL; | |
611 next = iter; | |
612 if (gtk_tree_model_iter_next(store, &next)) | |
613 { | |
614 tpath = gtk_tree_model_get_path(store, &next); | |
615 } | |
616 else | |
617 { | |
618 tpath = gtk_tree_model_get_path(store, &iter); | |
619 if (!gtk_tree_path_prev(tpath)) | |
620 { | |
621 gtk_tree_path_free(tpath); | |
622 tpath = NULL; | |
623 } | |
624 } | |
625 if (tpath) | |
626 { | |
627 gtk_tree_view_set_cursor(GTK_TREE_VIEW(kd->treeview), tpath, | |
628 gtk_tree_view_get_column(GTK_TREE_VIEW(kd->treeview), 0), FALSE); | |
629 gtk_tree_path_free(tpath); | |
630 } | |
631 | |
632 gtk_list_store_remove(GTK_LIST_STORE(store), &iter); | |
633 } | |
634 | |
635 static void keyword_dialog_edit_cb(GtkCellRendererText *renderer, const gchar *path, | |
636 const gchar *new_text, gpointer data) | |
637 { | |
638 KeywordDlg *kd = data; | |
639 GtkTreeModel *store; | |
640 GtkTreeIter iter; | |
641 GtkTreePath *tpath; | |
642 | |
643 if (!new_text || strlen(new_text) == 0) return; | |
644 | |
645 store = gtk_tree_view_get_model(GTK_TREE_VIEW(kd->treeview)); | |
646 | |
647 tpath = gtk_tree_path_new_from_string(path); | |
648 gtk_tree_model_get_iter(store, &iter, tpath); | |
649 gtk_tree_path_free(tpath); | |
650 | |
651 gtk_list_store_set(GTK_LIST_STORE(store), &iter, 0, new_text, -1); | |
652 } | |
653 | |
654 static void keyword_dialog_populate(KeywordDlg *kd) | |
655 { | |
656 GtkListStore *store; | |
657 GList *list; | |
658 | |
659 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(kd->treeview))); | |
660 gtk_list_store_clear(store); | |
661 | |
662 list = history_list_get_by_key("keywords"); | |
663 list = g_list_last(list); | |
664 while (list) | |
665 { | |
666 GtkTreeIter iter; | |
667 | |
668 gtk_list_store_append(store, &iter); | |
669 gtk_list_store_set(store, &iter, 0, list->data, | |
670 1, TRUE, -1); | |
671 | |
672 list = list->prev; | |
673 } | |
674 } | |
675 | |
676 static void keyword_dialog_show(void) | |
677 { | |
678 GtkWidget *scrolled; | |
679 GtkListStore *store; | |
680 GtkTreeViewColumn *column; | |
681 GtkCellRenderer *renderer; | |
682 GtkWidget *hbox; | |
683 GtkWidget *button; | |
684 | |
685 if (keyword_dialog) | |
686 { | |
687 gtk_window_present(GTK_WINDOW(keyword_dialog->gd->dialog)); | |
688 return; | |
689 } | |
690 | |
691 keyword_dialog = g_new0(KeywordDlg, 1); | |
692 | |
693 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
|
694 GQ_WMCLASS, "keyword_presets", NULL, TRUE, |
9 | 695 keyword_dialog_cancel_cb, keyword_dialog); |
696 generic_dialog_add_message(keyword_dialog->gd, NULL, _("Favorite keywords list"), NULL); | |
697 | |
698 generic_dialog_add_button(keyword_dialog->gd, GTK_STOCK_OK, NULL, | |
699 keyword_dialog_ok_cb, TRUE); | |
700 | |
701 scrolled = gtk_scrolled_window_new(NULL, NULL); | |
702 gtk_widget_set_size_request(scrolled, KEYWORD_DIALOG_WIDTH, KEYWORD_DIALOG_HEIGHT); | |
703 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); | |
704 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), | |
705 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
706 gtk_box_pack_start(GTK_BOX(keyword_dialog->gd->vbox), scrolled, TRUE, TRUE, 5); | |
707 gtk_widget_show(scrolled); | |
708 | |
709 store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_BOOLEAN); | |
710 keyword_dialog->treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); | |
711 g_object_unref(store); | |
712 | |
713 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(keyword_dialog->treeview), FALSE); | |
714 gtk_tree_view_set_search_column(GTK_TREE_VIEW(keyword_dialog->treeview), 0); | |
715 gtk_tree_view_set_reorderable(GTK_TREE_VIEW(keyword_dialog->treeview), TRUE); | |
716 | |
717 column = gtk_tree_view_column_new(); | |
718 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); | |
719 renderer = gtk_cell_renderer_text_new(); | |
720 g_signal_connect(G_OBJECT(renderer), "edited", | |
721 G_CALLBACK(keyword_dialog_edit_cb), keyword_dialog); | |
722 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
723 gtk_tree_view_column_add_attribute(column, renderer, "text", 0); | |
724 gtk_tree_view_column_add_attribute(column, renderer, "editable", 1); | |
725 gtk_tree_view_append_column(GTK_TREE_VIEW(keyword_dialog->treeview), column); | |
726 | |
727 gtk_container_add(GTK_CONTAINER(scrolled), keyword_dialog->treeview); | |
728 gtk_widget_show(keyword_dialog->treeview); | |
729 | |
730 hbox = gtk_hbox_new(FALSE, 5); | |
731 gtk_box_pack_start(GTK_BOX(keyword_dialog->gd->vbox), hbox, FALSE, FALSE, 0); | |
732 gtk_widget_show(hbox); | |
733 | |
734 button = gtk_button_new_from_stock(GTK_STOCK_ADD); | |
735 g_signal_connect(G_OBJECT(button), "clicked", | |
736 G_CALLBACK(keyword_dialog_add_cb), keyword_dialog); | |
737 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
738 gtk_widget_show(button); | |
739 | |
740 button = gtk_button_new_from_stock(GTK_STOCK_REMOVE); | |
741 g_signal_connect(G_OBJECT(button), "clicked", | |
742 G_CALLBACK(keyword_dialog_remove_cb), keyword_dialog); | |
743 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
744 gtk_widget_show(button); | |
745 | |
746 keyword_dialog_populate(keyword_dialog); | |
747 | |
748 gtk_widget_show(keyword_dialog->gd->dialog); | |
749 } | |
750 | |
751 | |
752 static void bar_keyword_edit_cb(GtkWidget *button, gpointer data) | |
753 { | |
754 keyword_dialog_show(); | |
755 } | |
756 | |
757 | |
758 /* | |
759 *------------------------------------------------------------------- | |
760 * info bar | |
761 *------------------------------------------------------------------- | |
762 */ | |
763 | |
764 typedef enum { | |
765 BAR_SORT_COPY, | |
766 BAR_SORT_MOVE, | |
767 BAR_SORT_LINK | |
768 } SortActionType; | |
769 | |
770 enum { | |
771 KEYWORD_COLUMN_TOGGLE = 0, | |
772 KEYWORD_COLUMN_TEXT | |
773 }; | |
774 | |
775 typedef struct _BarInfoData BarInfoData; | |
776 struct _BarInfoData | |
777 { | |
778 GtkWidget *vbox; | |
779 GtkWidget *group_box; | |
780 GtkWidget *label_file_name; | |
781 GtkWidget *label_file_time; | |
782 | |
783 GtkWidget *keyword_view; | |
784 GtkWidget *keyword_treeview; | |
785 | |
786 GtkWidget *comment_view; | |
787 | |
788 GtkWidget *button_save; | |
789 GtkWidget *button_set_add; | |
790 GtkWidget *button_set_replace; | |
791 | |
138 | 792 FileData *fd; |
9 | 793 |
794 gint changed; | |
795 gint save_timeout_id; | |
796 | |
797 GList *(*list_func)(gpointer); | |
798 gpointer list_data; | |
799 }; | |
800 | |
801 | |
802 static GList *bar_list = NULL; | |
803 | |
804 | |
805 static void bar_info_write(BarInfoData *bd) | |
806 { | |
807 GList *list; | |
808 gchar *comment; | |
809 | |
138 | 810 if (!bd->fd) return; |
9 | 811 |
812 list = keyword_list_pull(bd->keyword_view); | |
813 comment = comment_pull(bd->comment_view); | |
814 | |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
815 comment_write(bd->fd, list, comment); |
9 | 816 |
138 | 817 string_list_free(list); |
9 | 818 g_free(comment); |
819 | |
820 bd->changed = FALSE; | |
821 gtk_widget_set_sensitive(bd->button_save, FALSE); | |
822 } | |
823 | |
824 static gint bar_info_autosave(gpointer data) | |
825 { | |
826 BarInfoData *bd = data; | |
827 | |
828 bar_info_write(bd); | |
829 | |
830 bd->save_timeout_id = -1; | |
831 | |
832 return FALSE; | |
833 } | |
834 | |
835 static void bar_info_save_update(BarInfoData *bd, gint enable) | |
836 { | |
837 if (bd->save_timeout_id != -1) | |
838 { | |
839 g_source_remove(bd->save_timeout_id); | |
840 bd->save_timeout_id = -1; | |
841 } | |
842 if (enable) | |
843 { | |
844 bd->save_timeout_id = g_timeout_add(BAR_KEYWORD_AUTOSAVE_TIME, bar_info_autosave, bd); | |
845 } | |
846 } | |
847 | |
848 static void bar_keyword_list_sync(BarInfoData *bd, GList *keywords) | |
849 { | |
850 GList *list; | |
851 GtkListStore *store; | |
852 GtkTreeIter iter; | |
853 | |
854 list = history_list_get_by_key("keywords"); | |
855 if (!list) | |
856 { | |
857 /* blank? set up a few example defaults */ | |
858 | |
859 gint i = 0; | |
860 | |
861 while (keyword_favorite_defaults[i] != NULL) | |
862 { | |
863 history_list_add_to_key("keywords", _(keyword_favorite_defaults[i]), 0); | |
864 i++; | |
865 } | |
866 | |
867 list = history_list_get_by_key("keywords"); | |
868 } | |
869 | |
870 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(bd->keyword_treeview))); | |
871 | |
872 gtk_list_store_clear(store); | |
873 | |
874 list = g_list_last(list); | |
875 while (list) | |
876 { | |
877 gchar *key = list->data; | |
878 | |
879 gtk_list_store_append(store, &iter); | |
427
134beb10d916
Accept keywords composed by two words ("Todo" = "A faire" in french).
zas_
parents:
318
diff
changeset
|
880 gtk_list_store_set(store, &iter, KEYWORD_COLUMN_TOGGLE, keyword_list_find(keywords, key), |
9 | 881 KEYWORD_COLUMN_TEXT, key, -1); |
882 | |
883 list = list->prev; | |
884 } | |
885 } | |
886 | |
887 static void bar_info_keyword_update_all(void) | |
888 { | |
889 GList *work; | |
890 | |
891 work = bar_list; | |
892 while (work) | |
893 { | |
894 BarInfoData *bd; | |
895 GList *keywords; | |
896 | |
897 bd = work->data; | |
898 work = work->next; | |
899 | |
900 keywords = keyword_list_pull(bd->keyword_view); | |
901 bar_keyword_list_sync(bd, keywords); | |
138 | 902 string_list_free(keywords); |
9 | 903 } |
904 } | |
905 | |
906 static void bar_info_update(BarInfoData *bd) | |
907 { | |
908 GList *keywords = NULL; | |
909 gchar *comment = NULL; | |
910 | |
911 if (bd->label_file_name) | |
912 { | |
138 | 913 gtk_label_set_text(GTK_LABEL(bd->label_file_name), (bd->fd) ? bd->fd->name : ""); |
9 | 914 } |
915 if (bd->label_file_time) | |
916 { | |
138 | 917 gtk_label_set_text(GTK_LABEL(bd->label_file_time), (bd->fd) ? text_from_time(bd->fd->date) : ""); |
9 | 918 } |
919 | |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
920 if (comment_read(bd->fd, &keywords, &comment)) |
9 | 921 { |
922 keyword_list_push(bd->keyword_view, keywords); | |
923 gtk_text_buffer_set_text(gtk_text_view_get_buffer(GTK_TEXT_VIEW(bd->comment_view)), | |
924 (comment) ? comment : "", -1); | |
925 | |
926 bar_keyword_list_sync(bd, keywords); | |
927 | |
138 | 928 string_list_free(keywords); |
9 | 929 g_free(comment); |
930 } | |
931 else | |
932 { | |
933 gtk_text_buffer_set_text(gtk_text_view_get_buffer(GTK_TEXT_VIEW(bd->keyword_view)), "", -1); | |
934 gtk_text_buffer_set_text(gtk_text_view_get_buffer(GTK_TEXT_VIEW(bd->comment_view)), "", -1); | |
935 | |
936 bar_keyword_list_sync(bd, NULL); | |
937 } | |
938 | |
939 bar_info_save_update(bd, FALSE); | |
940 bd->changed = FALSE; | |
941 gtk_widget_set_sensitive(bd->button_save, FALSE); | |
942 | |
138 | 943 gtk_widget_set_sensitive(bd->group_box, (bd->fd != NULL)); |
9 | 944 } |
945 | |
138 | 946 void bar_info_set(GtkWidget *bar, FileData *fd) |
9 | 947 { |
948 BarInfoData *bd; | |
949 | |
950 bd = g_object_get_data(G_OBJECT(bar), "bar_info_data"); | |
951 if (!bd) return; | |
952 | |
953 if (bd->changed) bar_info_write(bd); | |
954 | |
138 | 955 file_data_unref(bd->fd); |
956 bd->fd = file_data_ref(fd); | |
9 | 957 |
958 bar_info_update(bd); | |
959 } | |
960 | |
138 | 961 void bar_info_maint_renamed(GtkWidget *bar, FileData *fd) |
9 | 962 { |
963 BarInfoData *bd; | |
964 | |
965 bd = g_object_get_data(G_OBJECT(bar), "bar_info_data"); | |
966 if (!bd) return; | |
967 | |
138 | 968 file_data_unref(bd->fd); |
969 bd->fd = file_data_ref(fd); | |
9 | 970 |
971 if (bd->label_file_name) | |
972 { | |
138 | 973 gtk_label_set_text(GTK_LABEL(bd->label_file_name), (bd->fd) ? bd->fd->name : ""); |
9 | 974 } |
975 } | |
976 | |
977 gint bar_info_event(GtkWidget *bar, GdkEvent *event) | |
978 { | |
979 BarInfoData *bd; | |
980 | |
981 bd = g_object_get_data(G_OBJECT(bar), "bar_info_data"); | |
982 if (!bd) return FALSE; | |
983 | |
984 if (GTK_WIDGET_HAS_FOCUS(bd->keyword_view)) return gtk_widget_event(bd->keyword_view, event); | |
985 if (GTK_WIDGET_HAS_FOCUS(bd->comment_view)) return gtk_widget_event(bd->comment_view, event); | |
986 | |
987 return FALSE; | |
988 } | |
989 | |
990 static void bar_info_keyword_set(BarInfoData *bd, const gchar *keyword, gint active) | |
991 { | |
992 GList *list; | |
993 gint found; | |
994 | |
995 if (!keyword) return; | |
996 | |
997 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
|
998 found = keyword_list_find(list, keyword); |
9 | 999 |
1000 if (active != found) | |
1001 { | |
1002 if (found) | |
1003 { | |
1004 GList *work = list; | |
1005 | |
1006 while (work) | |
1007 { | |
1008 gchar *key = work->data; | |
1009 work = work->next; | |
1010 | |
1011 if (key && keyword && strcmp(key, keyword) == 0) | |
1012 { | |
1013 list = g_list_remove(list, key); | |
1014 g_free(key); | |
1015 } | |
1016 } | |
1017 } | |
1018 else | |
1019 { | |
1020 list = g_list_append(list, g_strdup(keyword)); | |
1021 } | |
1022 | |
1023 keyword_list_push(bd->keyword_view, list); | |
1024 } | |
1025 | |
138 | 1026 string_list_free(list); |
9 | 1027 } |
1028 | |
1029 static void bar_info_keyword_toggle(GtkCellRendererToggle *toggle, const gchar *path, gpointer data) | |
1030 { | |
1031 BarInfoData *bd = data; | |
1032 GtkTreeModel *store; | |
1033 GtkTreeIter iter; | |
1034 GtkTreePath *tpath; | |
1035 gchar *key = NULL; | |
1036 gboolean active; | |
1037 | |
1038 store = gtk_tree_view_get_model(GTK_TREE_VIEW(bd->keyword_treeview)); | |
1039 | |
1040 tpath = gtk_tree_path_new_from_string(path); | |
1041 gtk_tree_model_get_iter(store, &iter, tpath); | |
1042 gtk_tree_path_free(tpath); | |
1043 | |
1044 gtk_tree_model_get(store, &iter, KEYWORD_COLUMN_TOGGLE, &active, | |
1045 KEYWORD_COLUMN_TEXT, &key, -1); | |
1046 active = (!active); | |
1047 gtk_list_store_set(GTK_LIST_STORE(store), &iter, KEYWORD_COLUMN_TOGGLE, active, -1); | |
1048 | |
1049 bar_info_keyword_set(bd, key, active); | |
1050 g_free(key); | |
1051 } | |
1052 | |
1053 static void bar_info_save(GtkWidget *button, gpointer data) | |
1054 { | |
1055 BarInfoData *bd = data; | |
1056 | |
1057 bar_info_save_update(bd, FALSE); | |
1058 bar_info_write(bd); | |
1059 } | |
1060 | |
1061 static void bar_info_set_selection(BarInfoData *bd, gint add) | |
1062 { | |
1063 GList *keywords; | |
1064 GList *list = NULL; | |
1065 GList *work; | |
1066 | |
1067 if (!bd->list_func) return; | |
1068 | |
1069 keywords = keyword_list_pull(bd->keyword_view); | |
1070 if (!keywords && add) return; | |
1071 | |
1072 list = bd->list_func(bd->list_data); | |
1073 work = list; | |
1074 while (work) | |
1075 { | |
138 | 1076 FileData *fd = work->data; |
9 | 1077 work = work->next; |
1078 | |
138 | 1079 metadata_set_keywords(fd, keywords, add); |
9 | 1080 } |
1081 | |
138 | 1082 filelist_free(list); |
1083 string_list_free(keywords); | |
9 | 1084 } |
1085 | |
1086 static void bar_info_set_add(GtkWidget *button, gpointer data) | |
1087 { | |
1088 BarInfoData *bd = data; | |
1089 | |
1090 bar_info_set_selection(bd, TRUE); | |
1091 } | |
1092 | |
1093 static void bar_info_set_replace(GtkWidget *button, gpointer data) | |
1094 { | |
1095 BarInfoData *bd = data; | |
1096 | |
1097 bar_info_set_selection(bd, FALSE); | |
1098 } | |
1099 | |
1100 static void bar_info_changed(GtkTextBuffer *buffer, gpointer data) | |
1101 { | |
1102 BarInfoData *bd = data; | |
1103 | |
1104 bd->changed = TRUE; | |
1105 gtk_widget_set_sensitive(bd->button_save, TRUE); | |
1106 | |
1107 bar_info_save_update(bd, TRUE); | |
1108 } | |
1109 | |
1110 void bar_info_close(GtkWidget *bar) | |
1111 { | |
1112 BarInfoData *bd; | |
1113 | |
1114 bd = g_object_get_data(G_OBJECT(bar), "bar_info_data"); | |
1115 if (!bd) return; | |
1116 | |
1117 gtk_widget_destroy(bd->vbox); | |
1118 } | |
1119 | |
1120 static void bar_info_destroy(GtkWidget *widget, gpointer data) | |
1121 { | |
1122 BarInfoData *bd = data; | |
1123 | |
1124 if (bd->changed) bar_info_write(bd); | |
1125 bar_info_save_update(bd, FALSE); | |
1126 | |
1127 bar_list = g_list_remove(bar_list, bd); | |
1128 | |
138 | 1129 file_data_unref(bd->fd); |
9 | 1130 |
1131 g_free(bd); | |
1132 } | |
1133 | |
138 | 1134 GtkWidget *bar_info_new(FileData *fd, gint metadata_only, GtkWidget *bounding_widget) |
9 | 1135 { |
1136 BarInfoData *bd; | |
1137 GtkWidget *box; | |
1138 GtkWidget *hbox; | |
1139 GtkWidget *table; | |
1140 GtkWidget *scrolled; | |
1141 GtkTextBuffer *buffer; | |
1142 GtkWidget *label; | |
1143 GtkWidget *tbar; | |
1144 GtkListStore *store; | |
1145 GtkTreeViewColumn *column; | |
1146 GtkCellRenderer *renderer; | |
1147 | |
1148 bd = g_new0(BarInfoData, 1); | |
1149 | |
1150 bd->list_func = NULL; | |
1151 bd->list_data = NULL; | |
1152 | |
1153 bd->vbox = gtk_vbox_new(FALSE, PREF_PAD_GAP); | |
1154 g_object_set_data(G_OBJECT(bd->vbox), "bar_info_data", bd); | |
1155 g_signal_connect(G_OBJECT(bd->vbox), "destroy", | |
1156 G_CALLBACK(bar_info_destroy), bd); | |
1157 | |
1158 if (!metadata_only) | |
1159 { | |
1160 hbox = pref_box_new(bd->vbox, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_GAP); | |
1161 | |
1162 label = sizer_new(bd->vbox, bounding_widget, SIZER_POS_LEFT); | |
1163 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
1164 gtk_widget_show(label); | |
1165 | |
1166 label = gtk_label_new(_("Keywords")); | |
1167 pref_label_bold(label, TRUE, FALSE); | |
1168 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0); | |
1169 gtk_widget_show(label); | |
1170 } | |
1171 | |
1172 bd->group_box = pref_box_new(bd->vbox, TRUE, GTK_ORIENTATION_VERTICAL, PREF_PAD_GAP); | |
1173 | |
1174 if (!metadata_only) | |
1175 { | |
1176 GtkWidget *table; | |
1177 | |
1178 table = pref_table_new(bd->group_box, 2, 2, FALSE, FALSE); | |
1179 | |
1180 bd->label_file_name = table_add_line(table, 0, 0, _("Filename:"), NULL); | |
1181 bd->label_file_time = table_add_line(table, 0, 1, _("File date:"), NULL); | |
1182 } | |
1183 else | |
1184 { | |
1185 bd->label_file_name = NULL; | |
1186 bd->label_file_time = NULL; | |
1187 } | |
1188 | |
1189 table = gtk_table_new(3, 1, TRUE); | |
1190 gtk_table_set_row_spacings(GTK_TABLE(table), PREF_PAD_GAP); | |
1191 gtk_box_pack_start(GTK_BOX(bd->group_box), table, TRUE, TRUE, 0); | |
1192 gtk_widget_show(table); | |
1193 | |
1194 /* keyword entry */ | |
1195 | |
1196 box = gtk_vbox_new(FALSE, 0); | |
1197 gtk_table_attach(GTK_TABLE(table), box, 0, 1, 0, 2, | |
1198 GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); | |
1199 gtk_widget_show(box); | |
1200 | |
1201 label = pref_label_new(box, _("Keywords:")); | |
1202 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); | |
1203 pref_label_bold(label, TRUE, FALSE); | |
1204 | |
1205 hbox = pref_box_new(box, TRUE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_GAP); | |
1206 | |
1207 scrolled = gtk_scrolled_window_new(NULL, NULL); | |
1208 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); | |
1209 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), | |
1210 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
1211 gtk_box_pack_start(GTK_BOX(hbox), scrolled, TRUE, TRUE, 0); | |
1212 gtk_widget_show(scrolled); | |
1213 | |
1214 bd->keyword_view = gtk_text_view_new(); | |
1215 gtk_container_add(GTK_CONTAINER(scrolled), bd->keyword_view); | |
1216 gtk_widget_show(bd->keyword_view); | |
1217 | |
1218 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(bd->keyword_view)); | |
1219 g_signal_connect(G_OBJECT(buffer), "changed", | |
1220 G_CALLBACK(bar_info_changed), bd); | |
1221 | |
1222 scrolled = gtk_scrolled_window_new(NULL, NULL); | |
1223 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); | |
1224 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), | |
1225 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
1226 gtk_box_pack_start(GTK_BOX(hbox), scrolled, TRUE, TRUE, 0); | |
1227 gtk_widget_show(scrolled); | |
1228 | |
1229 store = gtk_list_store_new(2, G_TYPE_BOOLEAN, G_TYPE_STRING); | |
1230 bd->keyword_treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); | |
1231 g_object_unref(store); | |
1232 | |
1233 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(bd->keyword_treeview), FALSE); | |
1234 | |
1235 if (metadata_only) | |
1236 { | |
1237 gtk_tree_view_set_search_column(GTK_TREE_VIEW(bd->keyword_treeview), KEYWORD_COLUMN_TEXT); | |
1238 } | |
1239 else | |
1240 { | |
1241 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(bd->keyword_treeview), FALSE); | |
1242 } | |
1243 | |
1244 column = gtk_tree_view_column_new(); | |
1245 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); | |
1246 | |
1247 renderer = gtk_cell_renderer_toggle_new(); | |
1248 gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
1249 gtk_tree_view_column_add_attribute(column, renderer, "active", KEYWORD_COLUMN_TOGGLE); | |
1250 g_signal_connect(G_OBJECT(renderer), "toggled", | |
1251 G_CALLBACK(bar_info_keyword_toggle), bd); | |
1252 | |
1253 renderer = gtk_cell_renderer_text_new(); | |
1254 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
1255 gtk_tree_view_column_add_attribute(column, renderer, "text", KEYWORD_COLUMN_TEXT); | |
1256 | |
1257 gtk_tree_view_append_column(GTK_TREE_VIEW(bd->keyword_treeview), column); | |
1258 | |
1259 gtk_container_add(GTK_CONTAINER(scrolled), bd->keyword_treeview); | |
1260 gtk_widget_show(bd->keyword_treeview); | |
1261 | |
1262 /* comment entry */ | |
1263 | |
1264 box = gtk_vbox_new(FALSE, 0); | |
1265 gtk_table_attach(GTK_TABLE(table), box, 0, 1, 2, 3, | |
1266 GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); | |
1267 gtk_widget_show(box); | |
1268 | |
1269 label = pref_label_new(box, _("Comment:")); | |
1270 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); | |
1271 pref_label_bold(label, TRUE, FALSE); | |
1272 | |
1273 scrolled = gtk_scrolled_window_new(NULL, NULL); | |
1274 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); | |
1275 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), | |
1276 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
1277 gtk_box_pack_start(GTK_BOX(box), scrolled, TRUE, TRUE, 0); | |
1278 gtk_widget_show(scrolled); | |
1279 | |
1280 bd->comment_view = gtk_text_view_new(); | |
1281 gtk_container_add(GTK_CONTAINER(scrolled), bd->comment_view); | |
1282 gtk_widget_show(bd->comment_view); | |
1283 | |
1284 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(bd->comment_view)); | |
1285 g_signal_connect(G_OBJECT(buffer), "changed", | |
1286 G_CALLBACK(bar_info_changed), bd); | |
1287 | |
1288 /* toolbar */ | |
1289 | |
1290 tbar = pref_toolbar_new(bd->group_box, GTK_TOOLBAR_ICONS); | |
1291 | |
41
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
1292 pref_toolbar_button(tbar, GTK_STOCK_INDEX, NULL, FALSE, |
9 | 1293 _("Edit favorite keywords list."), |
1294 G_CALLBACK(bar_keyword_edit_cb), bd); | |
1295 pref_toolbar_spacer(tbar); | |
41
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
1296 bd->button_set_add = pref_toolbar_button(tbar, GTK_STOCK_ADD, NULL, FALSE, |
9 | 1297 _("Add keywords to selected files"), |
1298 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
|
1299 bd->button_set_replace = pref_toolbar_button(tbar, GTK_STOCK_CONVERT, NULL, FALSE, |
9 | 1300 _("Add keywords to selected files, replacing the existing ones."), |
1301 G_CALLBACK(bar_info_set_replace), bd); | |
1302 pref_toolbar_spacer(tbar); | |
41
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
1303 bd->button_save = pref_toolbar_button(tbar, GTK_STOCK_SAVE, NULL, FALSE, |
9 | 1304 _("Save comment now"), |
1305 G_CALLBACK(bar_info_save), bd); | |
1306 | |
1307 bd->save_timeout_id = -1; | |
1308 | |
138 | 1309 bd->fd = file_data_ref(fd); |
9 | 1310 bar_info_update(bd); |
1311 | |
1312 bar_info_selection(bd->vbox, 0); | |
1313 | |
1314 bar_list = g_list_append(bar_list, bd); | |
1315 | |
1316 return bd->vbox; | |
1317 } | |
1318 | |
1319 void bar_info_set_selection_func(GtkWidget *bar, GList *(*list_func)(gpointer data), gpointer data) | |
1320 { | |
1321 BarInfoData *bd; | |
1322 | |
1323 bd = g_object_get_data(G_OBJECT(bar), "bar_info_data"); | |
1324 if (!bd) return; | |
1325 | |
1326 bd->list_func = list_func; | |
1327 bd->list_data = data; | |
1328 } | |
1329 | |
1330 void bar_info_selection(GtkWidget *bar, gint count) | |
1331 { | |
1332 BarInfoData *bd; | |
1333 gint enable; | |
1334 | |
1335 bd = g_object_get_data(G_OBJECT(bar), "bar_info_data"); | |
1336 if (!bd) return; | |
1337 | |
1338 enable = (count > 0 && bd->list_func != NULL); | |
1339 | |
1340 gtk_widget_set_sensitive(bd->button_set_add, enable); | |
1341 gtk_widget_set_sensitive(bd->button_set_replace, enable); | |
1342 } | |
1343 | |
1344 void bar_info_size_request(GtkWidget *bar, gint width) | |
1345 { | |
1346 BarInfoData *bd; | |
1347 | |
1348 bd = g_object_get_data(G_OBJECT(bar), "bar_info_data"); | |
1349 if (!bd) return; | |
1350 | |
1351 if (bd->label_file_name) | |
1352 { | |
1353 gtk_widget_set_size_request(bd->vbox, width, -1); | |
1354 } | |
1355 } | |
1356 |