Mercurial > geeqie.yaz
annotate src/info.c @ 583:de3e2bc22336
Revert patch 675, and correctly fix gtk assertion failure.
author | zas_ |
---|---|
date | Mon, 05 May 2008 08:32:18 +0000 |
parents | 9dc0513837b5 |
children | 905688aa2317 |
rev | line source |
---|---|
9 | 1 /* |
196 | 2 * Geeqie |
9 | 3 * (C) 2004 John Ellis |
475 | 4 * Copyright (C) 2008 The Geeqie Team |
9 | 5 * |
6 * Author: John Ellis | |
7 * | |
8 * This software is released under the GNU General Public License (GNU GPL). | |
9 * Please read the included file COPYING for more information. | |
10 * This software comes with no warranty of any kind, use at your own risk! | |
11 */ | |
12 | |
13 | |
281 | 14 #include "main.h" |
9 | 15 #include "info.h" |
16 | |
17 #include "bar_info.h" | |
18 #include "bar_exif.h" | |
19 #include "dnd.h" | |
20 #include "filelist.h" | |
21 #include "image.h" | |
22 #include "image-load.h" | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
15
diff
changeset
|
23 #include "pixbuf-renderer.h" |
9 | 24 #include "ui_bookmark.h" |
25 #include "ui_fileops.h" | |
26 #include "ui_misc.h" | |
27 | |
28 #include <pwd.h> | |
29 #include <grp.h> | |
30 | |
31 | |
32 #define IMAGE_SIZE_W 200 | |
33 #define IMAGE_SIZE_H 200 | |
34 | |
90
dc3c77d027e6
Tue Oct 31 18:06:42 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
35 #define DEF_PROPERTY_WIDTH 600 |
dc3c77d027e6
Tue Oct 31 18:06:42 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
36 #define DEF_PROPERTY_HEIGHT 400 |
9 | 37 |
38 typedef struct _TabData TabData; | |
39 struct _TabData | |
40 { | |
41 void (*func_free)(gpointer data); | |
42 void (*func_sync)(InfoData *id, gpointer data); | |
43 void (*func_image)(InfoData *id, gpointer data); | |
44 gpointer data; | |
221 | 45 TabData *(*func_new)(InfoData *id); |
46 GtkWidget *child; | |
9 | 47 }; |
48 | |
221 | 49 typedef struct _InfoTabsPos InfoTabsPos; |
50 struct _InfoTabsPos | |
51 { | |
52 TabData *(*func)(InfoData *id); | |
53 gint pos; | |
54 }; | |
55 | |
56 static GList *info_tabs_pos_list = NULL; | |
9 | 57 |
271
35f9083c6b95
gtk_notebook_set_tab_reorderable() is only available sinc gtk+ 2.10.
zas_
parents:
254
diff
changeset
|
58 static void notebook_set_tab_reorderable(GtkNotebook *notebook, GtkWidget *child, gboolean reorderable) |
35f9083c6b95
gtk_notebook_set_tab_reorderable() is only available sinc gtk+ 2.10.
zas_
parents:
254
diff
changeset
|
59 { |
35f9083c6b95
gtk_notebook_set_tab_reorderable() is only available sinc gtk+ 2.10.
zas_
parents:
254
diff
changeset
|
60 #if GTK_CHECK_VERSION(2,10,0) |
35f9083c6b95
gtk_notebook_set_tab_reorderable() is only available sinc gtk+ 2.10.
zas_
parents:
254
diff
changeset
|
61 gtk_notebook_set_tab_reorderable(notebook, child, reorderable); |
35f9083c6b95
gtk_notebook_set_tab_reorderable() is only available sinc gtk+ 2.10.
zas_
parents:
254
diff
changeset
|
62 #endif |
35f9083c6b95
gtk_notebook_set_tab_reorderable() is only available sinc gtk+ 2.10.
zas_
parents:
254
diff
changeset
|
63 } |
35f9083c6b95
gtk_notebook_set_tab_reorderable() is only available sinc gtk+ 2.10.
zas_
parents:
254
diff
changeset
|
64 |
9 | 65 /* |
66 *------------------------------------------------------------------- | |
67 * table utils | |
68 *------------------------------------------------------------------- | |
69 */ | |
70 | |
71 GtkWidget *table_add_line(GtkWidget *table, gint x, gint y, | |
72 const gchar *description, const gchar *text) | |
73 { | |
74 GtkWidget *label; | |
75 | |
76 if (!text) text = ""; | |
77 | |
78 label = pref_table_label(table, x, y, description, 1.0); | |
79 pref_label_bold(label, TRUE, FALSE); | |
80 | |
81 label = pref_table_label(table, x + 1, y, text, 0.0); | |
82 return label; | |
83 } | |
84 | |
85 /* | |
86 *------------------------------------------------------------------- | |
87 * EXIF tab | |
88 *------------------------------------------------------------------- | |
89 */ | |
90 | |
91 static void info_tab_exif_image(InfoData *id, gpointer data) | |
92 { | |
93 GtkWidget *bar = data; | |
138 | 94 FileData *fd; |
9 | 95 |
96 if (id->image->unknown) | |
97 { | |
138 | 98 fd = NULL; |
9 | 99 } |
100 else | |
101 { | |
138 | 102 fd = id->image->image_fd; |
9 | 103 } |
104 | |
138 | 105 bar_exif_set(bar, fd); |
9 | 106 } |
107 | |
108 static void info_tab_exif_sync(InfoData *id, gpointer data) | |
109 { | |
110 GtkWidget *bar = data; | |
111 | |
112 bar_exif_set(bar, NULL); | |
113 } | |
114 | |
115 static TabData *info_tab_exif_new(InfoData *id) | |
116 { | |
117 TabData *td; | |
118 GtkWidget *bar; | |
119 GtkWidget *label; | |
120 | |
121 bar = bar_exif_new(FALSE, NULL, FALSE, NULL); | |
122 gtk_container_set_border_width(GTK_CONTAINER(bar), PREF_PAD_BORDER); | |
123 | |
124 label = gtk_label_new(_("Exif")); | |
125 gtk_notebook_append_page(GTK_NOTEBOOK(id->notebook), bar, label); | |
271
35f9083c6b95
gtk_notebook_set_tab_reorderable() is only available sinc gtk+ 2.10.
zas_
parents:
254
diff
changeset
|
126 notebook_set_tab_reorderable(GTK_NOTEBOOK(id->notebook), bar, TRUE); |
9 | 127 gtk_widget_show(bar); |
128 | |
129 /* register */ | |
130 td = g_new0(TabData, 1); | |
131 td->func_free = NULL; | |
132 td->func_sync = info_tab_exif_sync; | |
133 td->func_image = info_tab_exif_image; | |
134 td->data = bar; | |
221 | 135 td->func_new = info_tab_exif_new; |
136 td->child = bar; | |
9 | 137 |
138 return td; | |
139 } | |
140 | |
141 /* | |
142 *------------------------------------------------------------------- | |
143 * file attributes tab | |
144 *------------------------------------------------------------------- | |
145 */ | |
146 | |
147 typedef struct _InfoTabMeta InfoTabMeta; | |
148 struct _InfoTabMeta | |
149 { | |
150 GtkWidget *bar_info; | |
151 }; | |
152 | |
153 static void info_tab_meta_free(gpointer data) | |
154 { | |
155 InfoTabMeta *tab = data; | |
156 | |
157 g_free(tab); | |
158 } | |
159 | |
160 static void info_tab_meta_sync(InfoData *id, gpointer data) | |
161 { | |
162 InfoTabMeta *tab = data; | |
163 | |
138 | 164 bar_info_set(tab->bar_info, id->fd); |
9 | 165 } |
166 | |
167 static GList *info_tab_meta_list_cb(gpointer data) | |
168 { | |
169 InfoData *id = data; | |
170 | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
551
diff
changeset
|
171 return filelist_copy(id->list); |
9 | 172 } |
173 | |
174 static TabData *info_tab_meta_new(InfoData *id) | |
175 { | |
176 TabData *td; | |
177 InfoTabMeta *tab; | |
178 GtkWidget *label; | |
179 | |
180 tab = g_new0(InfoTabMeta, 1); | |
181 | |
182 tab->bar_info = bar_info_new(NULL, TRUE, NULL); | |
183 bar_info_set_selection_func(tab->bar_info, info_tab_meta_list_cb, id); | |
184 bar_info_selection(tab->bar_info, g_list_length(id->list) - 1); | |
185 | |
186 gtk_container_set_border_width(GTK_CONTAINER(tab->bar_info), PREF_PAD_BORDER); | |
187 | |
188 label = gtk_label_new(_("Keywords")); | |
189 gtk_notebook_append_page(GTK_NOTEBOOK(id->notebook), tab->bar_info, label); | |
271
35f9083c6b95
gtk_notebook_set_tab_reorderable() is only available sinc gtk+ 2.10.
zas_
parents:
254
diff
changeset
|
190 notebook_set_tab_reorderable(GTK_NOTEBOOK(id->notebook), tab->bar_info, TRUE); |
9 | 191 gtk_widget_show(tab->bar_info); |
192 | |
193 /* register */ | |
194 td = g_new0(TabData, 1); | |
195 td->func_free = info_tab_meta_free; | |
196 td->func_sync = info_tab_meta_sync; | |
197 td->func_image = NULL; | |
198 td->data = tab; | |
221 | 199 td->func_new = info_tab_meta_new; |
200 td->child = tab->bar_info; | |
9 | 201 |
202 return td; | |
203 } | |
204 | |
205 /* | |
206 *------------------------------------------------------------------- | |
207 * general tab | |
208 *------------------------------------------------------------------- | |
209 */ | |
210 | |
211 typedef struct _InfoTabGeneral InfoTabGeneral; | |
212 struct _InfoTabGeneral | |
213 { | |
214 GtkWidget *label_file_time; | |
215 GtkWidget *label_file_size; | |
216 GtkWidget *label_dimensions; | |
217 GtkWidget *label_transparent; | |
218 GtkWidget *label_image_size; | |
219 GtkWidget *label_compression; | |
220 GtkWidget *label_mime_type; | |
221 | |
222 GtkWidget *label_user; | |
223 GtkWidget *label_group; | |
224 GtkWidget *label_perms; | |
225 | |
226 gint compression_done; | |
227 gint64 byte_size; | |
228 }; | |
229 | |
230 static void info_tab_general_image(InfoData *id, gpointer data) | |
231 { | |
232 InfoTabGeneral *tab = data; | |
233 gchar *buf; | |
234 guint mem_size; | |
235 gint has_alpha; | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
15
diff
changeset
|
236 GdkPixbuf *pixbuf; |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
15
diff
changeset
|
237 gint width, height; |
9 | 238 |
239 if (id->image->unknown) return; | |
240 | |
531 | 241 image_get_image_size(id->image, &width, &height); |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
15
diff
changeset
|
242 |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
15
diff
changeset
|
243 buf = g_strdup_printf("%d x %d", width, height); |
9 | 244 gtk_label_set_text(GTK_LABEL(tab->label_dimensions), buf); |
245 g_free(buf); | |
246 | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
15
diff
changeset
|
247 pixbuf = image_get_pixbuf(id->image); |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
15
diff
changeset
|
248 if (pixbuf) |
9 | 249 { |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
15
diff
changeset
|
250 has_alpha = gdk_pixbuf_get_has_alpha(pixbuf); |
9 | 251 } |
252 else | |
253 { | |
254 has_alpha = FALSE; | |
255 } | |
256 gtk_label_set_text(GTK_LABEL(tab->label_transparent), has_alpha ? _("yes") : _("no")); | |
257 | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
15
diff
changeset
|
258 mem_size = width * height * ((has_alpha) ? 4 : 3); |
9 | 259 buf = text_from_size_abrev(mem_size); |
260 gtk_label_set_text(GTK_LABEL(tab->label_image_size), buf); | |
261 g_free(buf); | |
262 | |
263 if (!tab->compression_done && mem_size > 0) | |
264 { | |
15
3263965d5f9e
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
265 buf = g_strdup_printf("%.1f%%", (double)tab->byte_size / mem_size * 100.0); |
9 | 266 gtk_label_set_text(GTK_LABEL(tab->label_compression), buf); |
267 g_free(buf); | |
268 | |
269 tab->compression_done = TRUE; | |
270 } | |
271 | |
272 buf = image_loader_get_format(id->image->il); | |
273 if (buf) | |
274 gtk_label_set_text(GTK_LABEL(tab->label_mime_type), buf); | |
275 g_free(buf); | |
276 } | |
277 | |
278 static gchar *mode_number(mode_t m) | |
279 { | |
280 int mb, mu, mg, mo; | |
281 | |
282 mb = mu = mg = mo = 0; | |
283 | |
284 if (m & S_ISUID) mb |= 4; | |
285 if (m & S_ISGID) mb |= 2; | |
286 if (m & S_ISVTX) mb |= 1; | |
287 | |
288 if (m & S_IRUSR) mu |= 4; | |
289 if (m & S_IWUSR) mu |= 2; | |
290 if (m & S_IXUSR) mu |= 1; | |
291 | |
292 if (m & S_IRGRP) mg |= 4; | |
293 if (m & S_IWGRP) mg |= 2; | |
294 if (m & S_IXGRP) mg |= 1; | |
295 | |
296 if (m & S_IROTH) mo |= 4; | |
297 if (m & S_IWOTH) mo |= 2; | |
298 if (m & S_IXOTH) mo |= 1; | |
299 | |
300 return g_strdup_printf("%d%d%d%d", mb, mu, mg, mo); | |
301 } | |
302 | |
303 static void info_tab_general_sync_perm(InfoTabGeneral *tab, InfoData *id) | |
304 { | |
305 struct stat st; | |
306 | |
138 | 307 if (!stat_utf8(id->fd->path, &st)) |
9 | 308 { |
309 gtk_label_set_text(GTK_LABEL(tab->label_user), ""); | |
310 gtk_label_set_text(GTK_LABEL(tab->label_group), ""); | |
311 gtk_label_set_text(GTK_LABEL(tab->label_perms), ""); | |
312 } | |
313 else | |
314 { | |
315 struct passwd *user; | |
316 struct group *grp; | |
317 gchar pbuf[12]; | |
318 gchar *pmod; | |
319 gchar *buf; | |
320 | |
321 user = getpwuid(st.st_uid); | |
322 gtk_label_set_text(GTK_LABEL(tab->label_user), (user) ? user->pw_name : ""); | |
323 | |
324 grp = getgrgid(st.st_gid); | |
325 gtk_label_set_text(GTK_LABEL(tab->label_group), (grp) ? grp->gr_name : ""); | |
326 | |
327 pbuf[0] = (st.st_mode & S_IRUSR) ? 'r' : '-'; | |
328 pbuf[1] = (st.st_mode & S_IWUSR) ? 'w' : '-'; | |
329 pbuf[2] = (st.st_mode & S_IXUSR) ? 'x' : '-'; | |
330 pbuf[3] = (st.st_mode & S_IRGRP) ? 'r' : '-'; | |
331 pbuf[4] = (st.st_mode & S_IWGRP) ? 'w' : '-'; | |
332 pbuf[5] = (st.st_mode & S_IXGRP) ? 'x' : '-'; | |
333 pbuf[6] = (st.st_mode & S_IROTH) ? 'r' : '-'; | |
334 pbuf[7] = (st.st_mode & S_IWOTH) ? 'w' : '-'; | |
335 pbuf[8] = (st.st_mode & S_IXOTH) ? 'x' : '-'; | |
336 pbuf[9] = '\0'; | |
337 | |
338 pmod = mode_number(st.st_mode); | |
339 buf = g_strdup_printf("%s (%s)", pbuf, pmod); | |
340 gtk_label_set_text(GTK_LABEL(tab->label_perms), buf); | |
341 g_free(buf); | |
342 g_free(pmod); | |
343 } | |
344 } | |
345 | |
346 static void info_tab_general_sync(InfoData *id, gpointer data) | |
347 { | |
348 InfoTabGeneral *tab = data; | |
349 gchar *buf; | |
350 | |
138 | 351 gtk_label_set_text(GTK_LABEL(tab->label_file_time), text_from_time(id->fd->date)); |
9 | 352 |
138 | 353 tab->byte_size = id->fd->size; |
9 | 354 |
355 buf = text_from_size(tab->byte_size); | |
356 gtk_label_set_text(GTK_LABEL(tab->label_file_size), buf); | |
357 g_free(buf); | |
358 | |
359 gtk_label_set_text(GTK_LABEL(tab->label_dimensions), ""); | |
360 gtk_label_set_text(GTK_LABEL(tab->label_transparent), ""); | |
361 gtk_label_set_text(GTK_LABEL(tab->label_image_size), ""); | |
362 | |
363 gtk_label_set_text(GTK_LABEL(tab->label_compression), ""); | |
364 gtk_label_set_text(GTK_LABEL(tab->label_mime_type), ""); | |
365 | |
366 info_tab_general_sync_perm(tab, id); | |
367 | |
368 tab->compression_done = FALSE; | |
369 } | |
370 | |
371 static void info_tab_general_free(gpointer data) | |
372 { | |
373 InfoTabGeneral *tab = data; | |
374 | |
375 g_free(tab); | |
376 } | |
377 | |
378 static TabData *info_tab_general_new(InfoData *id) | |
379 { | |
380 TabData *td; | |
381 InfoTabGeneral *tab; | |
382 GtkWidget *table; | |
383 GtkWidget *label; | |
384 | |
385 tab = g_new0(InfoTabGeneral, 1); | |
386 | |
387 table = pref_table_new(NULL, 2, 11, FALSE, FALSE); | |
388 gtk_container_set_border_width(GTK_CONTAINER(table), PREF_PAD_BORDER); | |
389 | |
390 tab->label_file_time = table_add_line(table, 0, 0, _("File date:"), NULL); | |
391 tab->label_file_size = table_add_line(table, 0, 1, _("File size:"), NULL); | |
392 | |
393 tab->label_dimensions = table_add_line(table, 0, 2, _("Dimensions:"), NULL); | |
394 tab->label_transparent = table_add_line(table, 0, 3, _("Transparent:"), NULL); | |
395 tab->label_image_size = table_add_line(table, 0, 4, _("Image size:"), NULL); | |
396 | |
397 tab->label_compression = table_add_line(table, 0, 5, _("Compress ratio:"), NULL); | |
398 tab->label_mime_type = table_add_line(table, 0, 6, _("File type:"), NULL); | |
399 | |
400 tab->label_user = table_add_line(table, 0, 7, _("Owner:"), NULL); | |
401 tab->label_group = table_add_line(table, 0, 8, _("Group:"), NULL); | |
402 tab->label_perms = table_add_line(table, 0, 9, "", NULL); | |
403 | |
404 label = gtk_label_new(_("General")); | |
405 gtk_notebook_append_page(GTK_NOTEBOOK(id->notebook), table, label); | |
271
35f9083c6b95
gtk_notebook_set_tab_reorderable() is only available sinc gtk+ 2.10.
zas_
parents:
254
diff
changeset
|
406 notebook_set_tab_reorderable(GTK_NOTEBOOK(id->notebook), table, TRUE); |
9 | 407 gtk_widget_show(table); |
408 | |
409 /* register */ | |
410 td = g_new0(TabData, 1); | |
411 td->func_free = info_tab_general_free; | |
412 td->func_sync = info_tab_general_sync; | |
413 td->func_image = info_tab_general_image; | |
414 td->data = tab; | |
221 | 415 td->func_new = info_tab_general_new; |
416 td->child = table; | |
9 | 417 |
418 return td; | |
419 } | |
420 | |
421 /* | |
422 *------------------------------------------------------------------- | |
423 * tabs | |
424 *------------------------------------------------------------------- | |
425 */ | |
426 | |
427 static void info_tabs_sync(InfoData *id, gint image) | |
428 { | |
429 GList *work; | |
430 | |
431 work = id->tab_list; | |
432 while (work) | |
433 { | |
434 TabData *td = work->data; | |
435 work = work->next; | |
436 | |
437 if (image) | |
438 { | |
439 if (td->func_image) td->func_image(id, td->data); | |
440 } | |
441 else | |
442 { | |
443 if (td->func_sync) td->func_sync(id, td->data); | |
444 } | |
445 } | |
446 } | |
447 | |
448 static void info_tabs_free(InfoData *id) | |
449 { | |
450 GList *work; | |
451 | |
452 work = id->tab_list; | |
453 while (work) | |
454 { | |
455 TabData *td = work->data; | |
456 work = work->next; | |
457 | |
458 if (td->func_free) td->func_free(td->data); | |
459 g_free(td); | |
460 } | |
461 g_list_free(id->tab_list); | |
462 id->tab_list = NULL; | |
463 } | |
464 | |
221 | 465 static InfoTabsPos *info_tabs_pos_new(gpointer func, gint pos) |
466 { | |
467 InfoTabsPos *t = g_new0(InfoTabsPos, 1); | |
468 t->func = func; | |
469 t->pos = pos; | |
470 | |
471 return t; | |
472 } | |
473 | |
474 static void info_tabs_pos_list_append(gpointer func) | |
475 { | |
476 static gint pos = 0; | |
477 | |
478 info_tabs_pos_list = g_list_append(info_tabs_pos_list, info_tabs_pos_new(func, pos++)); | |
479 } | |
480 | |
481 static gint compare_info_tabs_pos(gconstpointer a, gconstpointer b) | |
482 { | |
483 InfoTabsPos *ta = (InfoTabsPos *) a; | |
484 InfoTabsPos *tb = (InfoTabsPos *) b; | |
485 | |
486 if (ta->pos > tb->pos) return 1; | |
487 return -1; | |
488 } | |
489 | |
9 | 490 static void info_tabs_init(InfoData *id) |
491 { | |
221 | 492 GList *work; |
493 | |
494 if (!info_tabs_pos_list) | |
495 { | |
496 /* First run, default tabs order is defined here. */ | |
497 info_tabs_pos_list_append(info_tab_general_new); | |
498 info_tabs_pos_list_append(info_tab_meta_new); | |
499 info_tabs_pos_list_append(info_tab_exif_new); | |
500 } | |
501 else | |
502 info_tabs_pos_list = g_list_sort(info_tabs_pos_list, compare_info_tabs_pos); | |
503 | |
504 work = info_tabs_pos_list; | |
505 while (work) | |
506 { | |
507 InfoTabsPos *t = work->data; | |
508 work = work->next; | |
509 | |
510 id->tab_list = g_list_append(id->tab_list, t->func(id)); | |
511 } | |
9 | 512 } |
513 | |
514 /* | |
515 *------------------------------------------------------------------- | |
516 * sync | |
517 *------------------------------------------------------------------- | |
518 */ | |
519 | |
138 | 520 static void info_window_sync(InfoData *id, FileData *fd) |
9 | 521 { |
522 | |
138 | 523 if (!fd) return; |
9 | 524 |
138 | 525 gtk_entry_set_text(GTK_ENTRY(id->name_entry), fd->name); |
9 | 526 |
527 if (id->label_count) | |
528 { | |
529 gchar *buf; | |
530 buf = g_strdup_printf(_("Image %d of %d"), | |
219
92d2444893b8
Fix display of image number in properties dialog when more than one image is selected.
zas_
parents:
196
diff
changeset
|
531 g_list_index(id->list, (gpointer)fd) + 1, |
9 | 532 g_list_length(id->list)); |
533 gtk_label_set_text(GTK_LABEL(id->label_count), buf); | |
534 g_free(buf); | |
535 } | |
536 | |
537 info_tabs_sync(id, FALSE); | |
538 | |
539 id->updated = FALSE; | |
138 | 540 image_change_fd(id->image, fd, 0.0); |
9 | 541 } |
542 | |
221 | 543 static void info_notebook_reordered_cb(GtkNotebook *notebook, GtkWidget *child, guint page_num, gpointer data) |
544 { | |
545 InfoData *id = data; | |
546 GList *work; | |
547 | |
548 /* Save current tabs position to be able to restore them later. */ | |
549 work = id->tab_list; | |
550 while (work) | |
551 { | |
552 GList *tabpos; | |
553 TabData *td = work->data; | |
554 gint pos = gtk_notebook_page_num(GTK_NOTEBOOK(id->notebook), GTK_WIDGET(td->child)); | |
555 work = work->next; | |
556 | |
557 tabpos = info_tabs_pos_list; | |
558 while (tabpos) | |
559 { | |
560 InfoTabsPos *t = tabpos->data; | |
561 tabpos = tabpos->next; | |
562 | |
563 if (t->func == td->func_new) | |
564 { | |
565 t->pos = pos; | |
566 break; | |
567 } | |
442 | 568 } |
551
5b127951daa1
info_notebook_reordered_cb(): do not call info_tabs_sync(), it causes exif
zas_
parents:
531
diff
changeset
|
569 } |
221 | 570 } |
571 | |
9 | 572 /* |
573 *------------------------------------------------------------------- | |
574 * drag n drop (dropping not supported!) | |
575 *------------------------------------------------------------------- | |
576 */ | |
577 | |
578 static void info_window_dnd_data_set(GtkWidget *widget, GdkDragContext *context, | |
579 GtkSelectionData *selection_data, guint info, | |
580 guint time, gpointer data) | |
581 { | |
582 InfoData *id = data; | |
138 | 583 FileData *fd; |
9 | 584 |
138 | 585 fd = image_get_fd(id->image); |
586 if (fd) | |
9 | 587 { |
588 gchar *text; | |
589 gint len; | |
590 GList *list; | |
591 gint plain_text; | |
592 | |
593 switch (info) | |
594 { | |
595 case TARGET_URI_LIST: | |
596 plain_text = FALSE; | |
597 break; | |
598 case TARGET_TEXT_PLAIN: | |
599 default: | |
600 plain_text = TRUE; | |
601 break; | |
602 } | |
138 | 603 list = g_list_append(NULL, fd); |
604 text = uri_text_from_filelist(list, &len, plain_text); | |
9 | 605 g_list_free(list); |
606 | |
607 gtk_selection_data_set(selection_data, selection_data->target, | |
64
04ff0df3ad2f
Mon Aug 15 17:13:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
23
diff
changeset
|
608 8, (guchar *)text, len); |
9 | 609 g_free(text); |
610 } | |
611 } | |
612 | |
613 static void info_window_dnd_init(InfoData *id) | |
614 { | |
615 ImageWindow *imd; | |
616 | |
617 imd = id->image; | |
618 | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
15
diff
changeset
|
619 gtk_drag_source_set(imd->pr, GDK_BUTTON2_MASK, |
9 | 620 dnd_file_drag_types, dnd_file_drag_types_count, |
621 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK); | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
15
diff
changeset
|
622 g_signal_connect(G_OBJECT(imd->pr), "drag_data_get", |
9 | 623 G_CALLBACK(info_window_dnd_data_set), id); |
624 | |
625 #if 0 | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
15
diff
changeset
|
626 gtk_drag_dest_set(imd->pr, |
9 | 627 GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP, |
628 dnd_file_drop_types, dnd_file_drop_types_count, | |
629 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK); | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
15
diff
changeset
|
630 g_signal_connect(G_OBJECT(imd->pr), "drag_data_received", |
9 | 631 G_CALLBACK(info_window_dnd_data_get), id); |
632 #endif | |
633 } | |
634 | |
635 /* | |
636 *------------------------------------------------------------------- | |
637 * base window | |
638 *------------------------------------------------------------------- | |
639 */ | |
640 | |
641 static gint info_window_last_width = DEF_PROPERTY_WIDTH; | |
642 static gint info_window_last_height = DEF_PROPERTY_HEIGHT; | |
643 | |
644 static void info_window_image_update_cb(ImageWindow *imd, gpointer data) | |
645 { | |
646 InfoData *id = data; | |
647 | |
648 /* only do this once after when loading a new image, | |
649 * for tabs that depend on image data (exif) | |
650 * Subsequent updates are ignored, as the image | |
651 * should not really changed if id->updated is TRUE. | |
652 */ | |
653 | |
654 if (id->updated) return; | |
655 if (imd->unknown) return; | |
656 | |
657 info_tabs_sync(id, TRUE); | |
658 id->updated = TRUE; | |
659 } | |
660 | |
661 static void info_window_back_cb(GtkWidget *widget, gpointer data) | |
662 { | |
663 InfoData *id = data; | |
664 GList *work; | |
665 | |
138 | 666 work = g_list_find(id->list, (gpointer)id->fd); |
9 | 667 if (!work || !work->prev) return; |
668 | |
669 work = work->prev; | |
138 | 670 id->fd = work->data; |
9 | 671 |
138 | 672 info_window_sync(id, id->fd); |
9 | 673 |
674 gtk_widget_set_sensitive(id->button_back, (work->prev != NULL)); | |
675 gtk_widget_set_sensitive(id->button_next, TRUE); | |
676 } | |
677 | |
678 static void info_window_next_cb(GtkWidget *widget, gpointer data) | |
679 { | |
680 InfoData *id = data; | |
681 GList *work; | |
682 | |
138 | 683 work = g_list_find(id->list, (gpointer)id->fd); |
9 | 684 if (!work || !work->next) return; |
685 | |
686 work = work->next; | |
138 | 687 id->fd = work->data; |
9 | 688 |
138 | 689 info_window_sync(id, id->fd); |
9 | 690 |
691 gtk_widget_set_sensitive(id->button_next, (work->next != NULL)); | |
692 gtk_widget_set_sensitive(id->button_back, TRUE); | |
693 } | |
694 | |
695 static void info_window_image_button_cb(ImageWindow *imd, gint button, guint32 time, | |
696 gdouble x, gdouble y, guint state, gpointer data) | |
697 { | |
448
a73cc0fa14d0
Use explicit names for mouse buttons instead of numbers.
zas_
parents:
446
diff
changeset
|
698 if (button == MOUSE_BUTTON_LEFT) |
9 | 699 { |
700 info_window_next_cb(NULL, data); | |
701 } | |
448
a73cc0fa14d0
Use explicit names for mouse buttons instead of numbers.
zas_
parents:
446
diff
changeset
|
702 else if (button == MOUSE_BUTTON_MIDDLE || button == MOUSE_BUTTON_RIGHT) |
9 | 703 { |
704 info_window_back_cb(NULL, data); | |
705 } | |
706 } | |
707 | |
708 static void info_window_image_scroll_cb(ImageWindow *imd, GdkScrollDirection direction, guint32 time, | |
709 gdouble x, gdouble y, guint state, gpointer data) | |
710 { | |
711 if (direction == GDK_SCROLL_UP) | |
712 { | |
713 info_window_back_cb(NULL, data); | |
714 } | |
715 else if (direction == GDK_SCROLL_DOWN) | |
716 { | |
717 info_window_next_cb(NULL, data); | |
718 } | |
719 } | |
720 | |
721 static void info_window_close(InfoData *id) | |
722 { | |
723 gdk_drawable_get_size(id->window->window, &info_window_last_width, &info_window_last_height); | |
724 info_window_last_width = MAX(info_window_last_width, DEF_PROPERTY_WIDTH); | |
725 info_window_last_height = MAX(info_window_last_height, DEF_PROPERTY_HEIGHT); | |
726 | |
727 gtk_widget_destroy(id->window); | |
728 } | |
729 | |
730 static void info_window_close_cb(GtkWidget *widget, gpointer data) | |
731 { | |
732 InfoData *id = data; | |
733 | |
734 info_window_close(id); | |
735 } | |
736 | |
737 static gint info_window_delete_cb(GtkWidget *widget, GdkEventAny *event, gpointer data) | |
738 { | |
739 InfoData *id = data; | |
740 | |
741 info_window_close(id); | |
742 return TRUE; | |
743 } | |
744 | |
745 static void info_window_destroy_cb(GtkWidget *widget, gpointer data) | |
746 { | |
747 InfoData *id = data; | |
748 | |
749 info_tabs_free(id); | |
138 | 750 filelist_free(id->list); |
9 | 751 g_free(id); |
752 } | |
753 | |
479
5212d4fed37f
Ensure Properties dialog is displayed above fullscreen window.
zas_
parents:
475
diff
changeset
|
754 void info_window_new(FileData *fd, GList *list, GtkWidget *parent) |
9 | 755 { |
756 InfoData *id; | |
757 GtkWidget *main_vbox; | |
758 GtkWidget *paned; | |
759 GtkWidget *hbox; | |
760 GtkWidget *button; | |
761 GtkWidget *label; | |
762 GdkGeometry geometry; | |
763 | |
138 | 764 if (!fd && !list) return; |
9 | 765 |
766 if (!list) | |
767 { | |
138 | 768 list = g_list_append(NULL, file_data_ref(fd)); |
9 | 769 } |
770 | |
771 id = g_new0(InfoData, 1); | |
772 | |
773 id->list = list; | |
138 | 774 id->fd = (FileData *)id->list->data; |
9 | 775 id->updated = FALSE; |
776 | |
289
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
777 id->window = window_new(GTK_WINDOW_TOPLEVEL, "properties", NULL, NULL, _("Image properties")); |
9 | 778 gtk_window_set_type_hint(GTK_WINDOW(id->window), GDK_WINDOW_TYPE_HINT_DIALOG); |
479
5212d4fed37f
Ensure Properties dialog is displayed above fullscreen window.
zas_
parents:
475
diff
changeset
|
779 id->parent = parent; |
5212d4fed37f
Ensure Properties dialog is displayed above fullscreen window.
zas_
parents:
475
diff
changeset
|
780 if (GTK_IS_WINDOW(id->parent)) { |
5212d4fed37f
Ensure Properties dialog is displayed above fullscreen window.
zas_
parents:
475
diff
changeset
|
781 gtk_window_set_keep_above(GTK_WINDOW(id->window), TRUE); |
5212d4fed37f
Ensure Properties dialog is displayed above fullscreen window.
zas_
parents:
475
diff
changeset
|
782 #if 0 |
5212d4fed37f
Ensure Properties dialog is displayed above fullscreen window.
zas_
parents:
475
diff
changeset
|
783 /* work, but behavior is not that great */ |
5212d4fed37f
Ensure Properties dialog is displayed above fullscreen window.
zas_
parents:
475
diff
changeset
|
784 gtk_window_set_transient_for(GTK_WINDOW(id->window), GTK_WINDOW(id->parent)); |
5212d4fed37f
Ensure Properties dialog is displayed above fullscreen window.
zas_
parents:
475
diff
changeset
|
785 #endif |
5212d4fed37f
Ensure Properties dialog is displayed above fullscreen window.
zas_
parents:
475
diff
changeset
|
786 } |
9 | 787 gtk_window_set_resizable(GTK_WINDOW(id->window), TRUE); |
788 | |
789 geometry.min_width = 32; | |
790 geometry.min_height = 32; | |
791 geometry.base_width = DEF_PROPERTY_WIDTH; | |
792 geometry.base_height = DEF_PROPERTY_HEIGHT; | |
793 gtk_window_set_geometry_hints(GTK_WINDOW(id->window), NULL, &geometry, | |
794 GDK_HINT_MIN_SIZE | GDK_HINT_BASE_SIZE); | |
795 | |
796 | |
797 gtk_window_set_default_size(GTK_WINDOW(id->window), info_window_last_width, info_window_last_height); | |
798 gtk_container_set_border_width(GTK_CONTAINER(id->window), PREF_PAD_BORDER); | |
799 | |
800 g_signal_connect(G_OBJECT(id->window), "delete_event", | |
801 G_CALLBACK(info_window_delete_cb), id); | |
802 g_signal_connect(G_OBJECT(id->window), "destroy", | |
803 G_CALLBACK(info_window_destroy_cb), id); | |
804 | |
805 paned = gtk_hpaned_new(); | |
806 gtk_container_add(GTK_CONTAINER(id->window), paned); | |
807 gtk_widget_show(paned); | |
808 | |
809 id->image = image_new(FALSE); | |
810 image_set_update_func(id->image, info_window_image_update_cb, id); | |
811 | |
812 image_set_button_func(id->image, info_window_image_button_cb, id); | |
813 image_set_scroll_func(id->image, info_window_image_scroll_cb, id); | |
814 | |
815 gtk_widget_set_size_request(id->image->widget, IMAGE_SIZE_W, IMAGE_SIZE_H); | |
816 gtk_paned_pack1(GTK_PANED(paned), id->image->widget, FALSE, TRUE); | |
817 gtk_widget_show(id->image->widget); | |
818 | |
819 main_vbox = gtk_vbox_new(FALSE, 0); | |
820 gtk_paned_pack2(GTK_PANED(paned), main_vbox, TRUE, TRUE); | |
821 gtk_widget_show(main_vbox); | |
822 | |
823 hbox = pref_box_new(main_vbox, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_SPACE); | |
824 label = pref_label_new(hbox, _("Filename:")); | |
825 pref_label_bold(label, TRUE, FALSE); | |
826 | |
827 id->name_entry = gtk_entry_new(); | |
828 gtk_editable_set_editable(GTK_EDITABLE(id->name_entry), FALSE); | |
829 gtk_box_pack_start(GTK_BOX(hbox), id->name_entry, TRUE, TRUE, 0); | |
830 gtk_widget_show(id->name_entry); | |
831 | |
832 id->notebook = gtk_notebook_new(); | |
833 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(id->notebook), GTK_POS_TOP); | |
834 gtk_box_pack_start(GTK_BOX(main_vbox), id->notebook, TRUE, TRUE, 5); | |
221 | 835 g_signal_connect(G_OBJECT(id->notebook), "page-reordered", |
836 G_CALLBACK(info_notebook_reordered_cb), id); | |
837 | |
9 | 838 gtk_widget_show(id->notebook); |
839 | |
840 pref_spacer(main_vbox, PREF_PAD_GAP); | |
841 | |
842 hbox = pref_box_new(main_vbox, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_GAP); | |
843 | |
844 id->button_back = pref_button_new(hbox, GTK_STOCK_GO_BACK, NULL, TRUE, | |
845 G_CALLBACK(info_window_back_cb), id); | |
846 gtk_widget_set_sensitive(id->button_back, FALSE); | |
847 | |
848 id->button_next = pref_button_new(hbox, GTK_STOCK_GO_FORWARD, NULL, TRUE, | |
849 G_CALLBACK(info_window_next_cb), id); | |
850 gtk_widget_set_sensitive(id->button_next, (id->list->next != NULL)); | |
851 | |
852 if (id->list->next) | |
853 { | |
854 id->label_count = pref_label_new(hbox, ""); | |
855 } | |
856 | |
857 button = pref_button_new(NULL, GTK_STOCK_CLOSE, NULL, FALSE, | |
858 G_CALLBACK(info_window_close_cb), id); | |
859 gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
860 gtk_widget_show(button); | |
861 | |
862 /* set up tabs */ | |
863 | |
864 info_tabs_init(id); | |
865 | |
866 /* fill it */ | |
867 | |
138 | 868 info_window_sync(id, id->fd); |
9 | 869 |
870 /* finish */ | |
871 | |
872 info_window_dnd_init(id); | |
873 | |
874 gtk_widget_show(id->window); | |
875 } |