Mercurial > geeqie.yaz
annotate src/bar_exif.c @ 196:f6e307c7bad6
rename GQview -> Geeqie over the code
author | nadvornik |
---|---|
date | Sun, 23 Mar 2008 20:38:54 +0000 |
parents | 0584cb78aa14 |
children | d662d680250d |
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 | |
13 #include "gqview.h" | |
14 #include "bar_exif.h" | |
15 | |
16 #include "exif.h" | |
17 #include "ui_bookmark.h" | |
18 #include "ui_misc.h" | |
138 | 19 #include "filelist.h" |
9 | 20 |
21 #include <math.h> | |
22 | |
23 #define EXIF_BAR_SIZE_INCREMENT 48 | |
24 #define EXIF_BAR_ARROW_SIZE 7 | |
25 | |
26 #define EXIF_BAR_CUSTOM_COUNT 20 | |
27 | |
48
6948407f52a5
Fri Jun 3 18:43:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
28 #define BAR_EXIF_DATA_COLUMN_WIDTH 250 |
6948407f52a5
Fri Jun 3 18:43:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
29 |
95
eb9bb29cbd65
Fri Nov 3 11:40:48 2006 John Ellis <johne@verizon.net>
gqview
parents:
48
diff
changeset
|
30 static const gchar *bar_exif_key_list_real[] = { |
182 | 31 "fCamera", |
9 | 32 "fDateTime", |
33 "fShutterSpeed", | |
34 "fAperture", | |
181
c01dd7c9c7dc
unified tag names between exiv2 and internal rxif parser
nadvornik
parents:
179
diff
changeset
|
35 "Exif.Photo.ExposureProgram", |
9 | 36 "fExposureBias", |
37 "fISOSpeedRating", | |
38 "fFocalLength", | |
39 "fSubjectDistance", | |
181
c01dd7c9c7dc
unified tag names between exiv2 and internal rxif parser
nadvornik
parents:
179
diff
changeset
|
40 "Exif.Photo.MeteringMode", |
9 | 41 "fFlash", |
181
c01dd7c9c7dc
unified tag names between exiv2 and internal rxif parser
nadvornik
parents:
179
diff
changeset
|
42 "Exif.Photo.LightSource", |
9 | 43 "fResolution", |
181
c01dd7c9c7dc
unified tag names between exiv2 and internal rxif parser
nadvornik
parents:
179
diff
changeset
|
44 "Exif.Image.Orientation", |
c01dd7c9c7dc
unified tag names between exiv2 and internal rxif parser
nadvornik
parents:
179
diff
changeset
|
45 "Exif.Image.ImageDescription", |
182 | 46 "Exif.Image.Copyright" |
9 | 47 }; |
48 | |
95
eb9bb29cbd65
Fri Nov 3 11:40:48 2006 John Ellis <johne@verizon.net>
gqview
parents:
48
diff
changeset
|
49 const gchar **bar_exif_key_list = bar_exif_key_list_real; |
eb9bb29cbd65
Fri Nov 3 11:40:48 2006 John Ellis <johne@verizon.net>
gqview
parents:
48
diff
changeset
|
50 const gint bar_exif_key_count = (sizeof(bar_exif_key_list_real) / sizeof(gchar *)); |
9 | 51 |
52 | |
53 /* | |
54 *------------------------------------------------------------------- | |
55 * table util | |
56 *------------------------------------------------------------------- | |
57 */ | |
58 | |
59 static void table_add_line_custom(GtkWidget *table, gint x, gint y, | |
60 const gchar *text1, const gchar *text2, | |
61 GtkWidget **label1, GtkWidget **label2) | |
62 { | |
63 GtkWidget *label; | |
64 gchar *buf; | |
65 | |
66 buf = g_strconcat((text1) ? text1 : "fixme", ":", NULL); | |
67 if (!text2) text2 = ""; | |
68 | |
69 label = gtk_label_new(buf); | |
70 gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.0); | |
71 pref_label_bold(label, TRUE, FALSE); | |
72 gtk_table_attach(GTK_TABLE(table), label, | |
73 x, x + 1, y, y + 1, | |
74 GTK_FILL, GTK_FILL, | |
75 2, 2); | |
76 *label1 = label; | |
77 | |
78 label = gtk_label_new(text2); | |
79 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0); | |
80 gtk_table_attach(GTK_TABLE(table), label, | |
81 x + 1, x + 2, y, y + 1, | |
82 GTK_FILL, GTK_FILL, | |
83 2, 2); | |
84 *label2 = label; | |
85 | |
86 g_free(buf); | |
87 } | |
88 | |
89 static GtkWidget *table_add_line(GtkWidget *table, gint x, gint y, | |
90 const gchar *description, const gchar *text) | |
91 { | |
92 GtkWidget *key; | |
93 GtkWidget *label; | |
94 | |
95 table_add_line_custom(table, x, y, description, text, &key, &label); | |
96 gtk_widget_show(key); | |
97 gtk_widget_show(label); | |
98 | |
99 return label; | |
100 } | |
101 | |
102 | |
103 /* | |
104 *------------------------------------------------------------------- | |
105 * EXIF bar | |
106 *------------------------------------------------------------------- | |
107 */ | |
108 | |
109 typedef struct _ExifBar ExifBar; | |
110 struct _ExifBar | |
111 { | |
112 GtkWidget *vbox; | |
113 GtkWidget *scrolled; | |
114 GtkWidget *table; | |
115 GtkWidget *advanced_scrolled; | |
116 GtkWidget *listview; | |
117 GtkWidget **labels; | |
118 | |
119 GtkWidget *custom_sep; | |
120 GtkWidget *custom_name[EXIF_BAR_CUSTOM_COUNT]; | |
121 GtkWidget *custom_value[EXIF_BAR_CUSTOM_COUNT]; | |
122 | |
138 | 123 FileData *fd; |
9 | 124 |
125 gint allow_search; | |
126 }; | |
127 | |
128 enum { | |
129 EXIF_ADVCOL_ENABLED = 0, | |
130 EXIF_ADVCOL_TAG, | |
131 EXIF_ADVCOL_NAME, | |
132 EXIF_ADVCOL_VALUE, | |
133 EXIF_ADVCOL_FORMAT, | |
134 EXIF_ADVCOL_ELEMENTS, | |
135 EXIF_ADVCOL_DESCRIPTION, | |
136 EXIF_ADVCOL_COUNT | |
137 }; | |
138 | |
95
eb9bb29cbd65
Fri Nov 3 11:40:48 2006 John Ellis <johne@verizon.net>
gqview
parents:
48
diff
changeset
|
139 gchar *bar_exif_validate_text(gchar *text) |
9 | 140 { |
141 if (text && !g_utf8_validate(text, strlen(text), NULL)) | |
142 { | |
143 gchar *tmp = text; | |
144 text = g_convert(tmp, strlen(tmp), "UTF-8", "ISO-8859-1", NULL, NULL, NULL); | |
145 g_free(tmp); | |
146 } | |
147 return text; | |
148 } | |
149 | |
150 static void bar_exif_sensitive(ExifBar *eb, gint enable) | |
151 { | |
152 gtk_widget_set_sensitive(eb->table, enable); | |
153 if (eb->advanced_scrolled) gtk_widget_set_sensitive(eb->advanced_scrolled, enable); | |
154 } | |
155 | |
156 static gint bar_exif_row_enabled(const gchar *name) | |
157 { | |
158 GList *list; | |
159 | |
160 list = history_list_get_by_key("exif_extras"); | |
161 while (list) | |
162 { | |
163 if (name && strcmp(name, (gchar *)(list->data)) == 0) return TRUE; | |
164 list = list->next; | |
165 } | |
166 | |
167 return FALSE; | |
168 } | |
169 | |
170 static void bar_exif_update(ExifBar *eb) | |
171 { | |
172 ExifData *exif; | |
173 gint len, i; | |
174 | |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
185
diff
changeset
|
175 exif = exif_read_fd(eb->fd, FALSE); |
9 | 176 |
177 if (!exif) | |
178 { | |
179 bar_exif_sensitive(eb, FALSE); | |
180 return; | |
181 } | |
182 | |
183 bar_exif_sensitive(eb, TRUE); | |
184 | |
185 if (GTK_WIDGET_VISIBLE(eb->scrolled)) | |
186 { | |
187 GList *list; | |
188 len = bar_exif_key_count; | |
189 for (i = 0; i < len; i++) | |
190 { | |
191 gchar *text; | |
192 text = exif_get_data_as_text(exif, bar_exif_key_list[i]); | |
193 text = bar_exif_validate_text(text); | |
194 gtk_label_set_text(GTK_LABEL(eb->labels[i]), text); | |
195 g_free(text); | |
196 } | |
197 | |
198 list = g_list_last(history_list_get_by_key("exif_extras")); | |
199 if (list) | |
200 { | |
201 gtk_widget_show(eb->custom_sep); | |
202 } | |
203 else | |
204 { | |
205 gtk_widget_hide(eb->custom_sep); | |
206 } | |
207 i = 0; | |
208 while (list && i < EXIF_BAR_CUSTOM_COUNT) | |
209 { | |
210 gchar *text; | |
211 gchar *name; | |
212 gchar *buf; | |
213 | |
214 name = list->data; | |
215 list = list->prev; | |
216 | |
217 text = exif_get_data_as_text(exif, name); | |
218 text = bar_exif_validate_text(text); | |
219 | |
220 buf = g_strconcat(name, ":", NULL); | |
221 gtk_label_set_text(GTK_LABEL(eb->custom_name[i]), buf); | |
222 g_free(buf); | |
223 gtk_label_set_text(GTK_LABEL(eb->custom_value[i]), text); | |
224 g_free(text); | |
225 | |
226 gtk_widget_show(eb->custom_name[i]); | |
227 gtk_widget_show(eb->custom_value[i]); | |
228 | |
229 i++; | |
230 } | |
231 while (i < EXIF_BAR_CUSTOM_COUNT) | |
232 { | |
233 gtk_widget_hide(eb->custom_name[i]); | |
234 gtk_widget_hide(eb->custom_value[i]); | |
235 i++; | |
236 } | |
237 } | |
238 | |
239 if (eb->advanced_scrolled && GTK_WIDGET_VISIBLE(eb->advanced_scrolled)) | |
240 { | |
241 GtkListStore *store; | |
242 GtkTreeIter iter; | |
176
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
243 ExifItem *item; |
9 | 244 |
245 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(eb->listview))); | |
246 gtk_list_store_clear(store); | |
247 | |
176
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
248 item = exif_get_first_item(exif); |
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
249 while (item) |
9 | 250 { |
251 gchar *tag; | |
185 | 252 gchar *tag_name; |
9 | 253 gchar *text; |
254 const gchar *format; | |
255 gchar *elements; | |
185 | 256 gchar *description; |
9 | 257 |
176
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
258 tag = g_strdup_printf("0x%04x", exif_item_get_tag_id(item)); |
9 | 259 tag_name = exif_item_get_tag_name(item); |
260 format = exif_item_get_format_name(item, TRUE); | |
261 text = exif_item_get_data_as_text(item); | |
262 text = bar_exif_validate_text(text); | |
176
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
263 elements = g_strdup_printf("%d", exif_item_get_elements(item)); |
9 | 264 description = exif_item_get_description(item); |
182 | 265 if (!description) description = g_strdup(""); |
9 | 266 gtk_list_store_append(store, &iter); |
267 gtk_list_store_set(store, &iter, | |
268 EXIF_ADVCOL_ENABLED, bar_exif_row_enabled(tag_name), | |
269 EXIF_ADVCOL_TAG, tag, | |
270 EXIF_ADVCOL_NAME, tag_name, | |
271 EXIF_ADVCOL_VALUE, text, | |
272 EXIF_ADVCOL_FORMAT, format, | |
273 EXIF_ADVCOL_ELEMENTS, elements, | |
274 EXIF_ADVCOL_DESCRIPTION, description, -1); | |
275 g_free(tag); | |
276 g_free(text); | |
277 g_free(elements); | |
182 | 278 g_free(description); |
185 | 279 g_free(tag_name); |
176
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
280 item = exif_get_next_item(exif); |
9 | 281 } |
282 } | |
283 | |
284 exif_free(exif); | |
285 } | |
286 | |
287 static void bar_exif_clear(ExifBar *eb) | |
288 { | |
289 gint len; | |
290 gint i; | |
291 | |
292 if (!GTK_WIDGET_SENSITIVE(eb->labels[0])) return; | |
293 | |
294 len = bar_exif_key_count; | |
295 for (i = 0; i < len; i++) | |
296 { | |
297 gtk_label_set_text(GTK_LABEL(eb->labels[i]), ""); | |
298 } | |
299 for (i = 0; i < EXIF_BAR_CUSTOM_COUNT; i++) | |
300 { | |
301 gtk_label_set_text(GTK_LABEL(eb->custom_value[i]), ""); | |
302 } | |
303 | |
304 if (eb->listview) | |
305 { | |
306 GtkListStore *store; | |
307 | |
308 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(eb->listview))); | |
309 gtk_list_store_clear(store); | |
310 } | |
311 } | |
312 | |
138 | 313 void bar_exif_set(GtkWidget *bar, FileData *fd) |
9 | 314 { |
315 ExifBar *eb; | |
316 | |
182 | 317 g_assert(fd); |
318 | |
9 | 319 eb = g_object_get_data(G_OBJECT(bar), "bar_exif_data"); |
320 if (!eb) return; | |
321 | |
322 /* store this, advanced view toggle needs to reload data */ | |
138 | 323 file_data_unref(eb->fd); |
324 eb->fd = file_data_ref(fd); | |
9 | 325 |
326 bar_exif_clear(eb); | |
327 bar_exif_update(eb); | |
328 } | |
329 | |
330 static void bar_exif_row_toggled_cb(GtkCellRendererToggle *toggle, const gchar *path, gpointer data) | |
331 { | |
332 GtkWidget *listview = data; | |
333 GtkTreeModel *store; | |
334 GtkTreeIter iter; | |
335 GtkTreePath *tpath; | |
336 gchar *name = NULL; | |
337 gboolean active; | |
338 | |
339 store = gtk_tree_view_get_model(GTK_TREE_VIEW(listview)); | |
340 | |
341 tpath = gtk_tree_path_new_from_string(path); | |
342 gtk_tree_model_get_iter(store, &iter, tpath); | |
343 gtk_tree_path_free(tpath); | |
344 | |
345 gtk_tree_model_get(store, &iter, EXIF_ADVCOL_ENABLED, &active, | |
346 EXIF_ADVCOL_NAME, &name, -1); | |
347 active = (!active); | |
348 | |
349 if (active && | |
350 g_list_length(history_list_get_by_key("exif_extras")) >= EXIF_BAR_CUSTOM_COUNT) | |
351 { | |
352 active = FALSE; | |
353 } | |
354 | |
355 gtk_list_store_set(GTK_LIST_STORE(store), &iter, EXIF_ADVCOL_ENABLED, active, -1); | |
356 | |
357 if (active) | |
358 { | |
359 history_list_add_to_key("exif_extras", name, EXIF_BAR_CUSTOM_COUNT); | |
360 } | |
361 else | |
362 { | |
363 history_list_item_change("exif_extras", name, NULL); | |
364 } | |
365 | |
366 g_free(name); | |
367 } | |
368 | |
369 static void bar_exif_add_column_check(GtkWidget *listview, const gchar *title, gint n) | |
370 { | |
371 GtkTreeViewColumn *column; | |
372 GtkCellRenderer *renderer; | |
373 | |
374 column = gtk_tree_view_column_new(); | |
375 gtk_tree_view_column_set_title(column, title); | |
376 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); | |
377 | |
378 renderer = gtk_cell_renderer_toggle_new(); | |
379 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
380 gtk_tree_view_column_add_attribute(column, renderer, "active", n); | |
381 gtk_tree_view_append_column(GTK_TREE_VIEW(listview), column); | |
382 | |
383 g_signal_connect(G_OBJECT(renderer), "toggled", | |
384 G_CALLBACK(bar_exif_row_toggled_cb), listview); | |
385 } | |
386 | |
48
6948407f52a5
Fri Jun 3 18:43:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
387 static void bar_exif_add_column(GtkWidget *listview, const gchar *title, gint n, gint sizable) |
9 | 388 { |
389 GtkTreeViewColumn *column; | |
390 GtkCellRenderer *renderer; | |
391 | |
392 column = gtk_tree_view_column_new(); | |
393 gtk_tree_view_column_set_title(column, title); | |
48
6948407f52a5
Fri Jun 3 18:43:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
394 |
6948407f52a5
Fri Jun 3 18:43:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
395 if (sizable) |
6948407f52a5
Fri Jun 3 18:43:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
396 { |
6948407f52a5
Fri Jun 3 18:43:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
397 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED); |
6948407f52a5
Fri Jun 3 18:43:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
398 gtk_tree_view_column_set_fixed_width(column, BAR_EXIF_DATA_COLUMN_WIDTH); |
6948407f52a5
Fri Jun 3 18:43:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
399 gtk_tree_view_column_set_resizable(column, TRUE); |
6948407f52a5
Fri Jun 3 18:43:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
400 } |
6948407f52a5
Fri Jun 3 18:43:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
401 else |
6948407f52a5
Fri Jun 3 18:43:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
402 { |
6948407f52a5
Fri Jun 3 18:43:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
403 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); |
6948407f52a5
Fri Jun 3 18:43:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
404 } |
9 | 405 |
406 renderer = gtk_cell_renderer_text_new(); | |
407 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
408 gtk_tree_view_column_add_attribute(column, renderer, "text", n); | |
409 gtk_tree_view_append_column(GTK_TREE_VIEW(listview), column); | |
410 } | |
411 | |
412 static void bar_exif_advanced_build_view(ExifBar *eb) | |
413 { | |
414 GtkListStore *store; | |
415 | |
416 if (eb->listview) return; | |
417 | |
418 store = gtk_list_store_new(7, G_TYPE_BOOLEAN, | |
419 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, | |
420 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); | |
421 eb->listview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); | |
422 g_object_unref(store); | |
423 | |
424 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(eb->listview), TRUE); | |
425 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(eb->listview), TRUE); | |
426 | |
427 if (eb->allow_search) | |
428 { | |
429 gtk_tree_view_set_search_column(GTK_TREE_VIEW(eb->listview), EXIF_ADVCOL_NAME); | |
430 } | |
431 else | |
432 { | |
433 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(eb->listview), FALSE); | |
434 } | |
435 | |
436 bar_exif_add_column_check(eb->listview, "", EXIF_ADVCOL_ENABLED); | |
437 | |
48
6948407f52a5
Fri Jun 3 18:43:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
438 bar_exif_add_column(eb->listview, _("Tag"), EXIF_ADVCOL_TAG, FALSE); |
6948407f52a5
Fri Jun 3 18:43:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
439 bar_exif_add_column(eb->listview, _("Name"), EXIF_ADVCOL_NAME, FALSE); |
6948407f52a5
Fri Jun 3 18:43:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
440 bar_exif_add_column(eb->listview, _("Value"), EXIF_ADVCOL_VALUE, TRUE); |
6948407f52a5
Fri Jun 3 18:43:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
441 bar_exif_add_column(eb->listview, _("Format"), EXIF_ADVCOL_FORMAT, FALSE); |
6948407f52a5
Fri Jun 3 18:43:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
442 bar_exif_add_column(eb->listview, _("Elements"), EXIF_ADVCOL_ELEMENTS, FALSE); |
6948407f52a5
Fri Jun 3 18:43:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
443 bar_exif_add_column(eb->listview, _("Description"), EXIF_ADVCOL_DESCRIPTION, FALSE); |
9 | 444 |
445 eb->advanced_scrolled = gtk_scrolled_window_new(NULL, NULL); | |
446 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(eb->advanced_scrolled), GTK_SHADOW_IN); | |
447 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(eb->advanced_scrolled), | |
448 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); | |
449 gtk_box_pack_start(GTK_BOX(eb->vbox), eb->advanced_scrolled, TRUE, TRUE, 0); | |
450 gtk_container_add(GTK_CONTAINER(eb->advanced_scrolled), eb->listview); | |
451 gtk_widget_show(eb->listview); | |
452 } | |
453 | |
454 static void bar_exif_advanced_cb(GtkWidget *widget, gpointer data) | |
455 { | |
456 ExifBar *eb = data; | |
457 gint advanced; | |
458 | |
459 advanced = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); | |
460 | |
461 if (advanced) | |
462 { | |
463 gtk_widget_hide(eb->scrolled); | |
464 bar_exif_advanced_build_view(eb); | |
465 gtk_widget_show(eb->advanced_scrolled); | |
466 } | |
467 else | |
468 { | |
469 gtk_widget_hide(eb->advanced_scrolled); | |
470 gtk_widget_show(eb->scrolled); | |
471 } | |
472 | |
473 bar_exif_update(eb); | |
474 } | |
475 | |
476 gint bar_exif_is_advanced(GtkWidget *bar) | |
477 { | |
478 ExifBar *eb; | |
479 | |
480 eb = g_object_get_data(G_OBJECT(bar), "bar_exif_data"); | |
481 if (!eb) return FALSE; | |
482 | |
483 return (eb->advanced_scrolled && GTK_WIDGET_VISIBLE(eb->advanced_scrolled)); | |
484 } | |
485 | |
486 void bar_exif_close(GtkWidget *bar) | |
487 { | |
488 ExifBar *eb; | |
489 | |
490 eb = g_object_get_data(G_OBJECT(bar), "bar_exif_data"); | |
491 if (!eb) return; | |
492 | |
493 gtk_widget_destroy(eb->vbox); | |
494 } | |
495 | |
496 static void bar_exif_size(ExifBar *eb, gint val) | |
497 { | |
498 gint size; | |
499 | |
500 size = eb->vbox->allocation.width; | |
501 size = CLAMP(size + val, EXIF_BAR_SIZE_INCREMENT * 2, EXIF_BAR_SIZE_INCREMENT * 16); | |
502 | |
503 gtk_widget_set_size_request(eb->vbox, size, -1); | |
504 } | |
505 | |
506 static void bar_exif_larger(GtkWidget *widget, gpointer data) | |
507 { | |
508 ExifBar *eb = data; | |
509 | |
510 bar_exif_size(eb, EXIF_BAR_SIZE_INCREMENT); | |
511 } | |
512 | |
513 static void bar_exif_smaller(GtkWidget *widget, gpointer data) | |
514 { | |
515 ExifBar *eb = data; | |
516 | |
517 bar_exif_size(eb, -EXIF_BAR_SIZE_INCREMENT); | |
518 } | |
519 | |
520 static void bar_exif_destroy(GtkWidget *widget, gpointer data) | |
521 { | |
522 ExifBar *eb = data; | |
523 | |
524 g_free(eb->labels); | |
138 | 525 file_data_unref(eb->fd); |
9 | 526 g_free(eb); |
527 } | |
528 | |
138 | 529 GtkWidget *bar_exif_new(gint show_title, FileData *fd, gint advanced, GtkWidget *bounding_widget) |
9 | 530 { |
531 ExifBar *eb; | |
532 GtkWidget *table; | |
533 GtkWidget *viewport; | |
534 GtkWidget *hbox; | |
535 GtkWidget *button; | |
536 gint len; | |
537 gint i; | |
538 | |
539 eb = g_new0(ExifBar, 1); | |
540 | |
541 eb->labels = g_new0(GtkWidget *, bar_exif_key_count); | |
542 | |
543 eb->vbox = gtk_vbox_new(FALSE, PREF_PAD_GAP); | |
544 g_object_set_data(G_OBJECT(eb->vbox), "bar_exif_data", eb); | |
545 g_signal_connect_after(G_OBJECT(eb->vbox), "destroy", | |
546 G_CALLBACK(bar_exif_destroy), eb); | |
547 | |
548 eb->allow_search = !show_title; | |
549 | |
550 if (show_title) | |
551 { | |
552 GtkWidget *box; | |
553 GtkWidget *label; | |
554 GtkWidget *button; | |
555 GtkWidget *arrow; | |
556 | |
557 box = gtk_hbox_new(FALSE, 0); | |
558 | |
559 label = sizer_new(eb->vbox, bounding_widget, SIZER_POS_LEFT); | |
560 sizer_set_limits(label, EXIF_BAR_SIZE_INCREMENT * 2, -1, -1 , -1); | |
561 gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 0); | |
562 gtk_widget_show(label); | |
563 | |
564 label = gtk_label_new(_("Exif")); | |
565 pref_label_bold(label, TRUE, FALSE); | |
566 gtk_box_pack_start(GTK_BOX(box), label, TRUE, TRUE, 0); | |
567 gtk_widget_show(label); | |
568 | |
569 button = gtk_button_new(); | |
570 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); | |
571 g_signal_connect(G_OBJECT(button), "clicked", | |
572 G_CALLBACK(bar_exif_smaller), eb); | |
573 gtk_box_pack_end(GTK_BOX(box), button, FALSE, FALSE, 0); | |
574 arrow = gtk_arrow_new(GTK_ARROW_RIGHT, GTK_SHADOW_NONE); | |
575 gtk_widget_set_size_request(arrow, EXIF_BAR_ARROW_SIZE, EXIF_BAR_ARROW_SIZE); | |
576 gtk_container_add(GTK_CONTAINER(button), arrow); | |
577 gtk_widget_show(arrow); | |
578 gtk_widget_show(button); | |
579 | |
580 button = gtk_button_new(); | |
581 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); | |
582 g_signal_connect(G_OBJECT(button), "clicked", | |
583 G_CALLBACK(bar_exif_larger), eb); | |
584 gtk_box_pack_end(GTK_BOX(box), button, FALSE, FALSE, 0); | |
585 arrow = gtk_arrow_new(GTK_ARROW_LEFT, GTK_SHADOW_NONE); | |
586 gtk_widget_set_size_request(arrow, EXIF_BAR_ARROW_SIZE, EXIF_BAR_ARROW_SIZE); | |
587 gtk_container_add(GTK_CONTAINER(button), arrow); | |
588 gtk_widget_show(arrow); | |
589 gtk_widget_show(button); | |
590 | |
591 gtk_box_pack_start(GTK_BOX(eb->vbox), box, FALSE, FALSE, 0); | |
592 gtk_widget_show(box); | |
593 } | |
594 | |
595 table = gtk_table_new(2, bar_exif_key_count + 1 + EXIF_BAR_CUSTOM_COUNT, FALSE); | |
596 | |
597 eb->table = table; | |
598 | |
599 len = bar_exif_key_count; | |
600 for (i = 0; i < len; i++) | |
601 { | |
602 const gchar *text; | |
603 | |
604 text = exif_get_description_by_key(bar_exif_key_list[i]); | |
605 eb->labels[i] = table_add_line(table, 0, i, text, NULL); | |
606 } | |
607 | |
608 eb->custom_sep = gtk_hseparator_new(); | |
609 gtk_table_attach(GTK_TABLE(table), eb->custom_sep, 0, 1, | |
610 bar_exif_key_count, bar_exif_key_count + 1, | |
611 GTK_FILL, GTK_FILL, 2, 2); | |
612 | |
613 for (i = 0; i < EXIF_BAR_CUSTOM_COUNT; i++) | |
614 { | |
615 table_add_line_custom(table, 0, bar_exif_key_count + 1 + i, | |
616 "", "", &eb->custom_name[i], &eb->custom_value[i]); | |
617 } | |
618 | |
619 eb->scrolled = gtk_scrolled_window_new(NULL, NULL); | |
620 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(eb->scrolled), | |
621 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
622 | |
623 viewport = gtk_viewport_new(NULL, NULL); | |
624 gtk_viewport_set_shadow_type(GTK_VIEWPORT(viewport), GTK_SHADOW_NONE); | |
625 gtk_container_add(GTK_CONTAINER(eb->scrolled), viewport); | |
626 gtk_widget_show(viewport); | |
627 | |
628 gtk_container_add(GTK_CONTAINER(viewport), table); | |
629 gtk_widget_show(table); | |
630 | |
631 gtk_box_pack_start(GTK_BOX(eb->vbox), eb->scrolled, TRUE, TRUE, 0); | |
632 | |
633 hbox = gtk_hbox_new(FALSE, PREF_PAD_SPACE); | |
634 gtk_box_pack_end(GTK_BOX(eb->vbox), hbox, FALSE, FALSE, 0); | |
635 gtk_widget_show(hbox); | |
636 | |
637 button = gtk_check_button_new_with_label(_("Advanced view")); | |
638 if (advanced) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE); | |
639 g_signal_connect(G_OBJECT(button), "toggled", | |
640 G_CALLBACK(bar_exif_advanced_cb), eb); | |
641 gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
642 gtk_widget_show(button); | |
643 | |
644 eb->advanced_scrolled = NULL; | |
645 eb->listview = NULL; | |
646 | |
647 if (advanced) | |
648 { | |
649 bar_exif_advanced_build_view(eb); | |
650 gtk_widget_show(eb->advanced_scrolled); | |
651 } | |
652 else | |
653 { | |
654 gtk_widget_show(eb->scrolled); | |
655 } | |
656 | |
138 | 657 eb->fd = file_data_ref(fd); |
9 | 658 bar_exif_update(eb); |
659 | |
660 return eb->vbox; | |
661 } | |
662 |