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