Mercurial > geeqie
annotate src/bar_exif.c @ 211:d43153435be4
Make the zoom increment spinner more precise, step is now 0.1 instead of 1.
author | zas_ |
---|---|
date | Sun, 30 Mar 2008 07:14:37 +0000 |
parents | d662d680250d |
children | 77f1bcc6c161 |
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 | |
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 */ | |
138 | 321 file_data_unref(eb->fd); |
322 eb->fd = file_data_ref(fd); | |
9 | 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); | |
138 | 523 file_data_unref(eb->fd); |
9 | 524 g_free(eb); |
525 } | |
526 | |
138 | 527 GtkWidget *bar_exif_new(gint show_title, FileData *fd, gint advanced, GtkWidget *bounding_widget) |
9 | 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 | |
138 | 655 eb->fd = file_data_ref(fd); |
9 | 656 bar_exif_update(eb); |
657 | |
658 return eb->vbox; | |
659 } | |
660 |