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