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