Mercurial > geeqie.yaz
annotate src/bar_exif.c @ 177:0ca3b4c8ffae
started exiv2 integration
author | nadvornik |
---|---|
date | Wed, 13 Feb 2008 14:46:23 +0000 |
parents | 695e1ad3b169 |
children | 37004d5a584a |
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" | |
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[] = { |
9 | 31 "fCamera", |
32 "fDateTime", | |
33 "fShutterSpeed", | |
34 "fAperture", | |
35 "ExposureProgram", | |
36 "fExposureBias", | |
37 "fISOSpeedRating", | |
38 "fFocalLength", | |
39 "fSubjectDistance", | |
40 "MeteringMode", | |
41 "fFlash", | |
42 "LightSource", | |
43 "fResolution", | |
44 "Orientation", | |
45 "ImageDescription", | |
46 "Copyright" | |
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 | |
177 | 175 exif = exif_read(eb->fd->path, 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; | |
243 GList *work; | |
176
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
244 ExifItem *item; |
9 | 245 |
246 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(eb->listview))); | |
247 gtk_list_store_clear(store); | |
248 | |
176
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
249 item = exif_get_first_item(exif); |
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
250 while (item) |
9 | 251 { |
252 gchar *tag; | |
253 const gchar *tag_name; | |
254 gchar *text; | |
255 const gchar *format; | |
256 gchar *elements; | |
257 const gchar *description; | |
258 | |
176
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
259 tag = g_strdup_printf("0x%04x", exif_item_get_tag_id(item)); |
9 | 260 tag_name = exif_item_get_tag_name(item); |
261 format = exif_item_get_format_name(item, TRUE); | |
262 text = exif_item_get_data_as_text(item); | |
263 text = bar_exif_validate_text(text); | |
176
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
264 elements = g_strdup_printf("%d", exif_item_get_elements(item)); |
9 | 265 description = exif_item_get_description(item); |
266 if (!description) description = ""; | |
267 gtk_list_store_append(store, &iter); | |
268 gtk_list_store_set(store, &iter, | |
269 EXIF_ADVCOL_ENABLED, bar_exif_row_enabled(tag_name), | |
270 EXIF_ADVCOL_TAG, tag, | |
271 EXIF_ADVCOL_NAME, tag_name, | |
272 EXIF_ADVCOL_VALUE, text, | |
273 EXIF_ADVCOL_FORMAT, format, | |
274 EXIF_ADVCOL_ELEMENTS, elements, | |
275 EXIF_ADVCOL_DESCRIPTION, description, -1); | |
276 g_free(tag); | |
277 g_free(text); | |
278 g_free(elements); | |
176
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
279 item = exif_get_next_item(exif); |
9 | 280 } |
281 } | |
282 | |
283 exif_free(exif); | |
284 } | |
285 | |
286 static void bar_exif_clear(ExifBar *eb) | |
287 { | |
288 gint len; | |
289 gint i; | |
290 | |
291 if (!GTK_WIDGET_SENSITIVE(eb->labels[0])) return; | |
292 | |
293 len = bar_exif_key_count; | |
294 for (i = 0; i < len; i++) | |
295 { | |
296 gtk_label_set_text(GTK_LABEL(eb->labels[i]), ""); | |
297 } | |
298 for (i = 0; i < EXIF_BAR_CUSTOM_COUNT; i++) | |
299 { | |
300 gtk_label_set_text(GTK_LABEL(eb->custom_value[i]), ""); | |
301 } | |
302 | |
303 if (eb->listview) | |
304 { | |
305 GtkListStore *store; | |
306 | |
307 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(eb->listview))); | |
308 gtk_list_store_clear(store); | |
309 } | |
310 } | |
311 | |
138 | 312 void bar_exif_set(GtkWidget *bar, FileData *fd) |
9 | 313 { |
314 ExifBar *eb; | |
315 | |
316 eb = g_object_get_data(G_OBJECT(bar), "bar_exif_data"); | |
317 if (!eb) return; | |
318 | |
319 /* store this, advanced view toggle needs to reload data */ | |
138 | 320 file_data_unref(eb->fd); |
321 eb->fd = file_data_ref(fd); | |
9 | 322 |
323 bar_exif_clear(eb); | |
324 bar_exif_update(eb); | |
325 } | |
326 | |
327 static void bar_exif_row_toggled_cb(GtkCellRendererToggle *toggle, const gchar *path, gpointer data) | |
328 { | |
329 GtkWidget *listview = data; | |
330 GtkTreeModel *store; | |
331 GtkTreeIter iter; | |
332 GtkTreePath *tpath; | |
333 gchar *name = NULL; | |
334 gboolean active; | |
335 | |
336 store = gtk_tree_view_get_model(GTK_TREE_VIEW(listview)); | |
337 | |
338 tpath = gtk_tree_path_new_from_string(path); | |
339 gtk_tree_model_get_iter(store, &iter, tpath); | |
340 gtk_tree_path_free(tpath); | |
341 | |
342 gtk_tree_model_get(store, &iter, EXIF_ADVCOL_ENABLED, &active, | |
343 EXIF_ADVCOL_NAME, &name, -1); | |
344 active = (!active); | |
345 | |
346 if (active && | |
347 g_list_length(history_list_get_by_key("exif_extras")) >= EXIF_BAR_CUSTOM_COUNT) | |
348 { | |
349 active = FALSE; | |
350 } | |
351 | |
352 gtk_list_store_set(GTK_LIST_STORE(store), &iter, EXIF_ADVCOL_ENABLED, active, -1); | |
353 | |
354 if (active) | |
355 { | |
356 history_list_add_to_key("exif_extras", name, EXIF_BAR_CUSTOM_COUNT); | |
357 } | |
358 else | |
359 { | |
360 history_list_item_change("exif_extras", name, NULL); | |
361 } | |
362 | |
363 g_free(name); | |
364 } | |
365 | |
366 static void bar_exif_add_column_check(GtkWidget *listview, const gchar *title, gint n) | |
367 { | |
368 GtkTreeViewColumn *column; | |
369 GtkCellRenderer *renderer; | |
370 | |
371 column = gtk_tree_view_column_new(); | |
372 gtk_tree_view_column_set_title(column, title); | |
373 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); | |
374 | |
375 renderer = gtk_cell_renderer_toggle_new(); | |
376 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
377 gtk_tree_view_column_add_attribute(column, renderer, "active", n); | |
378 gtk_tree_view_append_column(GTK_TREE_VIEW(listview), column); | |
379 | |
380 g_signal_connect(G_OBJECT(renderer), "toggled", | |
381 G_CALLBACK(bar_exif_row_toggled_cb), listview); | |
382 } | |
383 | |
48
6948407f52a5
Fri Jun 3 18:43:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
384 static void bar_exif_add_column(GtkWidget *listview, const gchar *title, gint n, gint sizable) |
9 | 385 { |
386 GtkTreeViewColumn *column; | |
387 GtkCellRenderer *renderer; | |
388 | |
389 column = gtk_tree_view_column_new(); | |
390 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
|
391 |
6948407f52a5
Fri Jun 3 18:43:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
392 if (sizable) |
6948407f52a5
Fri Jun 3 18:43:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
393 { |
6948407f52a5
Fri Jun 3 18:43:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
394 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
|
395 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
|
396 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
|
397 } |
6948407f52a5
Fri Jun 3 18:43:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
398 else |
6948407f52a5
Fri Jun 3 18:43:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
399 { |
6948407f52a5
Fri Jun 3 18:43:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
400 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
|
401 } |
9 | 402 |
403 renderer = gtk_cell_renderer_text_new(); | |
404 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
405 gtk_tree_view_column_add_attribute(column, renderer, "text", n); | |
406 gtk_tree_view_append_column(GTK_TREE_VIEW(listview), column); | |
407 } | |
408 | |
409 static void bar_exif_advanced_build_view(ExifBar *eb) | |
410 { | |
411 GtkListStore *store; | |
412 | |
413 if (eb->listview) return; | |
414 | |
415 store = gtk_list_store_new(7, G_TYPE_BOOLEAN, | |
416 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, | |
417 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); | |
418 eb->listview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); | |
419 g_object_unref(store); | |
420 | |
421 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(eb->listview), TRUE); | |
422 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(eb->listview), TRUE); | |
423 | |
424 if (eb->allow_search) | |
425 { | |
426 gtk_tree_view_set_search_column(GTK_TREE_VIEW(eb->listview), EXIF_ADVCOL_NAME); | |
427 } | |
428 else | |
429 { | |
430 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(eb->listview), FALSE); | |
431 } | |
432 | |
433 bar_exif_add_column_check(eb->listview, "", EXIF_ADVCOL_ENABLED); | |
434 | |
48
6948407f52a5
Fri Jun 3 18:43:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
435 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
|
436 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
|
437 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
|
438 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
|
439 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
|
440 bar_exif_add_column(eb->listview, _("Description"), EXIF_ADVCOL_DESCRIPTION, FALSE); |
9 | 441 |
442 eb->advanced_scrolled = gtk_scrolled_window_new(NULL, NULL); | |
443 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(eb->advanced_scrolled), GTK_SHADOW_IN); | |
444 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(eb->advanced_scrolled), | |
445 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); | |
446 gtk_box_pack_start(GTK_BOX(eb->vbox), eb->advanced_scrolled, TRUE, TRUE, 0); | |
447 gtk_container_add(GTK_CONTAINER(eb->advanced_scrolled), eb->listview); | |
448 gtk_widget_show(eb->listview); | |
449 } | |
450 | |
451 static void bar_exif_advanced_cb(GtkWidget *widget, gpointer data) | |
452 { | |
453 ExifBar *eb = data; | |
454 gint advanced; | |
455 | |
456 advanced = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); | |
457 | |
458 if (advanced) | |
459 { | |
460 gtk_widget_hide(eb->scrolled); | |
461 bar_exif_advanced_build_view(eb); | |
462 gtk_widget_show(eb->advanced_scrolled); | |
463 } | |
464 else | |
465 { | |
466 gtk_widget_hide(eb->advanced_scrolled); | |
467 gtk_widget_show(eb->scrolled); | |
468 } | |
469 | |
470 bar_exif_update(eb); | |
471 } | |
472 | |
473 gint bar_exif_is_advanced(GtkWidget *bar) | |
474 { | |
475 ExifBar *eb; | |
476 | |
477 eb = g_object_get_data(G_OBJECT(bar), "bar_exif_data"); | |
478 if (!eb) return FALSE; | |
479 | |
480 return (eb->advanced_scrolled && GTK_WIDGET_VISIBLE(eb->advanced_scrolled)); | |
481 } | |
482 | |
483 void bar_exif_close(GtkWidget *bar) | |
484 { | |
485 ExifBar *eb; | |
486 | |
487 eb = g_object_get_data(G_OBJECT(bar), "bar_exif_data"); | |
488 if (!eb) return; | |
489 | |
490 gtk_widget_destroy(eb->vbox); | |
491 } | |
492 | |
493 static void bar_exif_size(ExifBar *eb, gint val) | |
494 { | |
495 gint size; | |
496 | |
497 size = eb->vbox->allocation.width; | |
498 size = CLAMP(size + val, EXIF_BAR_SIZE_INCREMENT * 2, EXIF_BAR_SIZE_INCREMENT * 16); | |
499 | |
500 gtk_widget_set_size_request(eb->vbox, size, -1); | |
501 } | |
502 | |
503 static void bar_exif_larger(GtkWidget *widget, gpointer data) | |
504 { | |
505 ExifBar *eb = data; | |
506 | |
507 bar_exif_size(eb, EXIF_BAR_SIZE_INCREMENT); | |
508 } | |
509 | |
510 static void bar_exif_smaller(GtkWidget *widget, gpointer data) | |
511 { | |
512 ExifBar *eb = data; | |
513 | |
514 bar_exif_size(eb, -EXIF_BAR_SIZE_INCREMENT); | |
515 } | |
516 | |
517 static void bar_exif_destroy(GtkWidget *widget, gpointer data) | |
518 { | |
519 ExifBar *eb = data; | |
520 | |
521 g_free(eb->labels); | |
138 | 522 file_data_unref(eb->fd); |
9 | 523 g_free(eb); |
524 } | |
525 | |
138 | 526 GtkWidget *bar_exif_new(gint show_title, FileData *fd, gint advanced, GtkWidget *bounding_widget) |
9 | 527 { |
528 ExifBar *eb; | |
529 GtkWidget *table; | |
530 GtkWidget *viewport; | |
531 GtkWidget *hbox; | |
532 GtkWidget *button; | |
533 gint len; | |
534 gint i; | |
535 | |
536 eb = g_new0(ExifBar, 1); | |
537 | |
538 eb->labels = g_new0(GtkWidget *, bar_exif_key_count); | |
539 | |
540 eb->vbox = gtk_vbox_new(FALSE, PREF_PAD_GAP); | |
541 g_object_set_data(G_OBJECT(eb->vbox), "bar_exif_data", eb); | |
542 g_signal_connect_after(G_OBJECT(eb->vbox), "destroy", | |
543 G_CALLBACK(bar_exif_destroy), eb); | |
544 | |
545 eb->allow_search = !show_title; | |
546 | |
547 if (show_title) | |
548 { | |
549 GtkWidget *box; | |
550 GtkWidget *label; | |
551 GtkWidget *button; | |
552 GtkWidget *arrow; | |
553 | |
554 box = gtk_hbox_new(FALSE, 0); | |
555 | |
556 label = sizer_new(eb->vbox, bounding_widget, SIZER_POS_LEFT); | |
557 sizer_set_limits(label, EXIF_BAR_SIZE_INCREMENT * 2, -1, -1 , -1); | |
558 gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 0); | |
559 gtk_widget_show(label); | |
560 | |
561 label = gtk_label_new(_("Exif")); | |
562 pref_label_bold(label, TRUE, FALSE); | |
563 gtk_box_pack_start(GTK_BOX(box), label, TRUE, TRUE, 0); | |
564 gtk_widget_show(label); | |
565 | |
566 button = gtk_button_new(); | |
567 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); | |
568 g_signal_connect(G_OBJECT(button), "clicked", | |
569 G_CALLBACK(bar_exif_smaller), eb); | |
570 gtk_box_pack_end(GTK_BOX(box), button, FALSE, FALSE, 0); | |
571 arrow = gtk_arrow_new(GTK_ARROW_RIGHT, GTK_SHADOW_NONE); | |
572 gtk_widget_set_size_request(arrow, EXIF_BAR_ARROW_SIZE, EXIF_BAR_ARROW_SIZE); | |
573 gtk_container_add(GTK_CONTAINER(button), arrow); | |
574 gtk_widget_show(arrow); | |
575 gtk_widget_show(button); | |
576 | |
577 button = gtk_button_new(); | |
578 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); | |
579 g_signal_connect(G_OBJECT(button), "clicked", | |
580 G_CALLBACK(bar_exif_larger), eb); | |
581 gtk_box_pack_end(GTK_BOX(box), button, FALSE, FALSE, 0); | |
582 arrow = gtk_arrow_new(GTK_ARROW_LEFT, GTK_SHADOW_NONE); | |
583 gtk_widget_set_size_request(arrow, EXIF_BAR_ARROW_SIZE, EXIF_BAR_ARROW_SIZE); | |
584 gtk_container_add(GTK_CONTAINER(button), arrow); | |
585 gtk_widget_show(arrow); | |
586 gtk_widget_show(button); | |
587 | |
588 gtk_box_pack_start(GTK_BOX(eb->vbox), box, FALSE, FALSE, 0); | |
589 gtk_widget_show(box); | |
590 } | |
591 | |
592 table = gtk_table_new(2, bar_exif_key_count + 1 + EXIF_BAR_CUSTOM_COUNT, FALSE); | |
593 | |
594 eb->table = table; | |
595 | |
596 len = bar_exif_key_count; | |
597 for (i = 0; i < len; i++) | |
598 { | |
599 const gchar *text; | |
600 | |
601 text = exif_get_description_by_key(bar_exif_key_list[i]); | |
602 eb->labels[i] = table_add_line(table, 0, i, text, NULL); | |
603 } | |
604 | |
605 eb->custom_sep = gtk_hseparator_new(); | |
606 gtk_table_attach(GTK_TABLE(table), eb->custom_sep, 0, 1, | |
607 bar_exif_key_count, bar_exif_key_count + 1, | |
608 GTK_FILL, GTK_FILL, 2, 2); | |
609 | |
610 for (i = 0; i < EXIF_BAR_CUSTOM_COUNT; i++) | |
611 { | |
612 table_add_line_custom(table, 0, bar_exif_key_count + 1 + i, | |
613 "", "", &eb->custom_name[i], &eb->custom_value[i]); | |
614 } | |
615 | |
616 eb->scrolled = gtk_scrolled_window_new(NULL, NULL); | |
617 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(eb->scrolled), | |
618 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
619 | |
620 viewport = gtk_viewport_new(NULL, NULL); | |
621 gtk_viewport_set_shadow_type(GTK_VIEWPORT(viewport), GTK_SHADOW_NONE); | |
622 gtk_container_add(GTK_CONTAINER(eb->scrolled), viewport); | |
623 gtk_widget_show(viewport); | |
624 | |
625 gtk_container_add(GTK_CONTAINER(viewport), table); | |
626 gtk_widget_show(table); | |
627 | |
628 gtk_box_pack_start(GTK_BOX(eb->vbox), eb->scrolled, TRUE, TRUE, 0); | |
629 | |
630 hbox = gtk_hbox_new(FALSE, PREF_PAD_SPACE); | |
631 gtk_box_pack_end(GTK_BOX(eb->vbox), hbox, FALSE, FALSE, 0); | |
632 gtk_widget_show(hbox); | |
633 | |
634 button = gtk_check_button_new_with_label(_("Advanced view")); | |
635 if (advanced) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE); | |
636 g_signal_connect(G_OBJECT(button), "toggled", | |
637 G_CALLBACK(bar_exif_advanced_cb), eb); | |
638 gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
639 gtk_widget_show(button); | |
640 | |
641 eb->advanced_scrolled = NULL; | |
642 eb->listview = NULL; | |
643 | |
644 if (advanced) | |
645 { | |
646 bar_exif_advanced_build_view(eb); | |
647 gtk_widget_show(eb->advanced_scrolled); | |
648 } | |
649 else | |
650 { | |
651 gtk_widget_show(eb->scrolled); | |
652 } | |
653 | |
138 | 654 eb->fd = file_data_ref(fd); |
9 | 655 bar_exif_update(eb); |
656 | |
657 return eb->vbox; | |
658 } | |
659 |