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