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