1 /*
2 * Copyright (C) 2006 John Ellis
3 * Copyright (C) 2008 - 2016 The Geeqie Team
4 *
5 * Author: John Ellis
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 */
21
22 #include "pan-view.h"
23
24 #include "bar_exif.h"
25 #include "dnd.h"
26 #include "editors.h"
27 #include "exif.h"
28 #include "fullscreen.h"
29 #include "history_list.h"
30 #include "image.h"
31 #include "img-view.h"
32 #include "layout_util.h"
33 #include "menu.h"
34 #include "metadata.h"
35 #include "misc.h"
36 #include "pan-calendar.h"
37 #include "pan-folder.h"
38 #include "pan-grid.h"
39 #include "pan-item.h"
40 #include "pan-timeline.h"
41 #include "pan-util.h"
42 #include "pan-view-filter.h"
43 #include "pan-view-search.h"
44 #include "pixbuf-renderer.h"
45 #include "pixbuf_util.h"
46 #include "thumb.h"
47 #include "ui_fileops.h"
48 #include "ui_menu.h"
49 #include "ui_misc.h"
50 #include "ui_tabcomp.h"
51 #include "ui_utildlg.h"
52 #include "uri_utils.h"
53 #include "utilops.h"
54 #include "window.h"
55
56 #include <gdk/gdkkeysyms.h> /* for keyboard values */
57
58 #include <math.h>
59
60
61 #define PAN_WINDOW_DEFAULT_WIDTH 720
62 #define PAN_WINDOW_DEFAULT_HEIGHT 500
63
64 #define PAN_TILE_SIZE 512
65
66 #define ZOOM_INCREMENT 1.0
67 #define ZOOM_LABEL_WIDTH 64
68
69
70 #define PAN_PREF_GROUP "pan_view_options"
71 #define PAN_PREF_HIDE_WARNING "hide_performance_warning"
72 #define PAN_PREF_EXIF_PAN_DATE "use_exif_date"
73 #define PAN_PREF_INFO_IMAGE "info_image_size"
74 #define PAN_PREF_INFO_EXIF "info_includes_exif"
75
76
77 static GList *pan_window_list = NULL;
78
79
80 static void pan_layout_update_idle(PanWindow *pw);
81
82 static void pan_fullscreen_toggle(PanWindow *pw, gboolean force_off);
83
84 static void pan_window_close(PanWindow *pw);
85
86 static GtkWidget *pan_popup_menu(PanWindow *pw);
87
88 static void pan_window_dnd_init(PanWindow *pw);
89
90
91 /*
92 *-----------------------------------------------------------------------------
93 * the image/thumb loader queue
94 *-----------------------------------------------------------------------------
95 */
96
97 static gboolean pan_queue_step(PanWindow *pw);
98
99
pan_queue_thumb_done_cb(ThumbLoader * tl,gpointer data)100 static void pan_queue_thumb_done_cb(ThumbLoader *tl, gpointer data)
101 {
102 PanWindow *pw = data;
103
104 if (pw->queue_pi)
105 {
106 PanItem *pi;
107 gint rc;
108
109 pi = pw->queue_pi;
110 pw->queue_pi = NULL;
111
112 pi->queued = FALSE;
113
114 if (pi->pixbuf) g_object_unref(pi->pixbuf);
115 pi->pixbuf = thumb_loader_get_pixbuf(tl);
116
117 rc = pi->refcount;
118 image_area_changed(pw->imd, pi->x, pi->y, pi->width, pi->height);
119 pi->refcount = rc;
120 }
121
122 thumb_loader_free(pw->tl);
123 pw->tl = NULL;
124
125 while (pan_queue_step(pw));
126 }
127
pan_queue_image_done_cb(ImageLoader * il,gpointer data)128 static void pan_queue_image_done_cb(ImageLoader *il, gpointer data)
129 {
130 PanWindow *pw = data;
131
132 if (pw->queue_pi)
133 {
134 PanItem *pi;
135 gint rc;
136
137 pi = pw->queue_pi;
138 pw->queue_pi = NULL;
139
140 pi->queued = FALSE;
141
142 if (pi->pixbuf) g_object_unref(pi->pixbuf);
143 pi->pixbuf = image_loader_get_pixbuf(pw->il);
144 if (pi->pixbuf) g_object_ref(pi->pixbuf);
145
146 if (pi->pixbuf && pw->size != PAN_IMAGE_SIZE_100 &&
147 (gdk_pixbuf_get_width(pi->pixbuf) > pi->width ||
148 gdk_pixbuf_get_height(pi->pixbuf) > pi->height))
149 {
150 GdkPixbuf *tmp;
151
152 tmp = pi->pixbuf;
153 pi->pixbuf = gdk_pixbuf_scale_simple(tmp, pi->width, pi->height,
154 (GdkInterpType)options->image.zoom_quality);
155 g_object_unref(tmp);
156 }
157
158 rc = pi->refcount;
159 image_area_changed(pw->imd, pi->x, pi->y, pi->width, pi->height);
160 pi->refcount = rc;
161 }
162
163 image_loader_free(pw->il);
164 pw->il = NULL;
165
166 while (pan_queue_step(pw));
167 }
168
pan_queue_step(PanWindow * pw)169 static gboolean pan_queue_step(PanWindow *pw)
170 {
171 PanItem *pi;
172
173 if (!pw->queue) return FALSE;
174
175 pi = pw->queue->data;
176 pw->queue = g_list_remove(pw->queue, pi);
177 pw->queue_pi = pi;
178
179 if (!pw->queue_pi->fd)
180 {
181 pw->queue_pi->queued = FALSE;
182 pw->queue_pi = NULL;
183 return TRUE;
184 }
185
186 image_loader_free(pw->il);
187 pw->il = NULL;
188 thumb_loader_free(pw->tl);
189 pw->tl = NULL;
190
191 if (pi->type == PAN_ITEM_IMAGE)
192 {
193 pw->il = image_loader_new(pi->fd);
194
195 if (pw->size != PAN_IMAGE_SIZE_100)
196 {
197 image_loader_set_requested_size(pw->il, pi->width, pi->height);
198 }
199
200 g_signal_connect(G_OBJECT(pw->il), "error", (GCallback)pan_queue_image_done_cb, pw);
201 g_signal_connect(G_OBJECT(pw->il), "done", (GCallback)pan_queue_image_done_cb, pw);
202
203 if (image_loader_start(pw->il)) return FALSE;
204
205 image_loader_free(pw->il);
206 pw->il = NULL;
207 }
208 else if (pi->type == PAN_ITEM_THUMB)
209 {
210 pw->tl = thumb_loader_new(PAN_THUMB_SIZE, PAN_THUMB_SIZE);
211
212 if (!pw->tl->standard_loader)
213 {
214 /* The classic loader will recreate a thumbnail any time we
215 * request a different size than what exists. This view will
216 * almost never use the user configured sizes so disable cache.
217 */
218 thumb_loader_set_cache(pw->tl, FALSE, FALSE, FALSE);
219 }
220
221 thumb_loader_set_callbacks(pw->tl,
222 pan_queue_thumb_done_cb,
223 pan_queue_thumb_done_cb,
224 NULL, pw);
225
226 if (thumb_loader_start(pw->tl, pi->fd)) return FALSE;
227
228 thumb_loader_free(pw->tl);
229 pw->tl = NULL;
230 }
231
232 pw->queue_pi->queued = FALSE;
233 pw->queue_pi = NULL;
234 return TRUE;
235 }
236
pan_queue_add(PanWindow * pw,PanItem * pi)237 static void pan_queue_add(PanWindow *pw, PanItem *pi)
238 {
239 if (!pi || pi->queued || pi->pixbuf) return;
240 if (pw->size <= PAN_IMAGE_SIZE_THUMB_NONE &&
241 (!pi->key || strcmp(pi->key, "info") != 0) )
242 {
243 return;
244 }
245
246 pi->queued = TRUE;
247 pw->queue = g_list_prepend(pw->queue, pi);
248
249 if (!pw->tl && !pw->il) while (pan_queue_step(pw));
250 }
251
252
253 /*
254 *-----------------------------------------------------------------------------
255 * tile request/dispose handlers
256 *-----------------------------------------------------------------------------
257 */
258
pan_window_request_tile_cb(PixbufRenderer * pr,gint x,gint y,gint width,gint height,GdkPixbuf * pixbuf,gpointer data)259 static gboolean pan_window_request_tile_cb(PixbufRenderer *pr, gint x, gint y,
260 gint width, gint height, GdkPixbuf *pixbuf, gpointer data)
261 {
262 PanWindow *pw = data;
263 GList *list;
264 GList *work;
265 gint i;
266
267 pixbuf_set_rect_fill(pixbuf,
268 0, 0, width, height,
269 PAN_BACKGROUND_COLOR, 255);
270
271 for (i = (x / PAN_GRID_SIZE) * PAN_GRID_SIZE; i < x + width; i += PAN_GRID_SIZE)
272 {
273 gint rx, ry, rw, rh;
274
275 if (util_clip_region(x, y, width, height,
276 i, y, 1, height,
277 &rx, &ry, &rw, &rh))
278 {
279 pixbuf_draw_rect_fill(pixbuf,
280 rx - x, ry - y, rw, rh,
281 PAN_GRID_COLOR, PAN_GRID_ALPHA);
282 }
283 }
284 for (i = (y / PAN_GRID_SIZE) * PAN_GRID_SIZE; i < y + height; i += PAN_GRID_SIZE)
285 {
286 gint rx, ry, rw, rh;
287
288 if (util_clip_region(x, y, width, height,
289 x, i, width, 1,
290 &rx, &ry, &rw, &rh))
291 {
292 pixbuf_draw_rect_fill(pixbuf,
293 rx - x, ry - y, rw, rh,
294 PAN_GRID_COLOR, PAN_GRID_ALPHA);
295 }
296 }
297
298 list = pan_layout_intersect(pw, x, y, width, height);
299 work = list;
300 while (work)
301 {
302 PanItem *pi;
303 gboolean queue = FALSE;
304
305 pi = work->data;
306 work = work->next;
307
308 pi->refcount++;
309
310 switch (pi->type)
311 {
312 case PAN_ITEM_BOX:
313 queue = pan_item_box_draw(pw, pi, pixbuf, pr, x, y, width, height);
314 break;
315 case PAN_ITEM_TRIANGLE:
316 queue = pan_item_tri_draw(pw, pi, pixbuf, pr, x, y, width, height);
317 break;
318 case PAN_ITEM_TEXT:
319 queue = pan_item_text_draw(pw, pi, pixbuf, pr, x, y, width, height);
320 break;
321 case PAN_ITEM_THUMB:
322 queue = pan_item_thumb_draw(pw, pi, pixbuf, pr, x, y, width, height);
323 break;
324 case PAN_ITEM_IMAGE:
325 queue = pan_item_image_draw(pw, pi, pixbuf, pr, x, y, width, height);
326 break;
327 case PAN_ITEM_NONE:
328 default:
329 break;
330 }
331
332 if (queue) pan_queue_add(pw, pi);
333 }
334
335 g_list_free(list);
336
337 return TRUE;
338 }
339
pan_window_dispose_tile_cb(PixbufRenderer * pr,gint x,gint y,gint width,gint height,GdkPixbuf * pixbuf,gpointer data)340 static void pan_window_dispose_tile_cb(PixbufRenderer *pr, gint x, gint y,
341 gint width, gint height, GdkPixbuf *pixbuf, gpointer data)
342 {
343 PanWindow *pw = data;
344 GList *list;
345 GList *work;
346
347 list = pan_layout_intersect(pw, x, y, width, height);
348 work = list;
349 while (work)
350 {
351 PanItem *pi;
352
353 pi = work->data;
354 work = work->next;
355
356 if (pi->refcount > 0)
357 {
358 pi->refcount--;
359
360 if (pi->refcount == 0)
361 {
362 if (pi->queued)
363 {
364 pw->queue = g_list_remove(pw->queue, pi);
365 pi->queued = FALSE;
366 }
367 if (pw->queue_pi == pi) pw->queue_pi = NULL;
368 if (pi->pixbuf)
369 {
370 g_object_unref(pi->pixbuf);
371 pi->pixbuf = NULL;
372 }
373 }
374 }
375 }
376
377 g_list_free(list);
378 }
379
380
381 /*
382 *-----------------------------------------------------------------------------
383 * misc
384 *-----------------------------------------------------------------------------
385 */
386
pan_window_message(PanWindow * pw,const gchar * text)387 static void pan_window_message(PanWindow *pw, const gchar *text)
388 {
389 GList *work;
390 gint count = 0;
391 gint64 size = 0;
392 gchar *ss;
393 gchar *buf;
394
395 if (text)
396 {
397 gtk_label_set_text(GTK_LABEL(pw->label_message), text);
398 return;
399 }
400
401 work = pw->list_static;
402 if (pw->layout == PAN_LAYOUT_CALENDAR)
403 {
404 while (work)
405 {
406 PanItem *pi;
407
408 pi = work->data;
409 work = work->next;
410
411 if (pi->fd &&
412 pi->type == PAN_ITEM_BOX &&
413 pi->key && strcmp(pi->key, "dot") == 0)
414 {
415 size += pi->fd->size;
416 count++;
417 }
418 }
419 }
420 else
421 {
422 while (work)
423 {
424 PanItem *pi;
425
426 pi = work->data;
427 work = work->next;
428
429 if (pi->fd &&
430 (pi->type == PAN_ITEM_THUMB || pi->type == PAN_ITEM_IMAGE))
431 {
432 size += pi->fd->size;
433 count++;
434 }
435 }
436 }
437
438 ss = text_from_size_abrev(size);
439 buf = g_strdup_printf(_("%d images, %s"), count, ss);
440 g_free(ss);
441 gtk_label_set_text(GTK_LABEL(pw->label_message), buf);
442 g_free(buf);
443 }
444
pan_warning_folder(const gchar * path,GtkWidget * parent)445 static void pan_warning_folder(const gchar *path, GtkWidget *parent)
446 {
447 gchar *message;
448
449 message = g_strdup_printf(_("The pan view does not support the folder \"%s\"."), path);
450 warning_dialog(_("Folder not supported"), message,
451 GTK_STOCK_DIALOG_INFO, parent);
452 g_free(message);
453 }
454
pan_window_zoom_limit(PanWindow * pw)455 static void pan_window_zoom_limit(PanWindow *pw)
456 {
457 gdouble min;
458
459 switch (pw->size)
460 {
461 case PAN_IMAGE_SIZE_THUMB_DOTS:
462 case PAN_IMAGE_SIZE_THUMB_NONE:
463 case PAN_IMAGE_SIZE_THUMB_SMALL:
464 case PAN_IMAGE_SIZE_THUMB_NORMAL:
465 #if 0
466 /* easily requires > 512mb ram when window size > 1024x768 and zoom is <= -8 */
467 min = -16.0;
468 break;
469 #endif
470 case PAN_IMAGE_SIZE_THUMB_LARGE:
471 min = -6.0;
472 break;
473 case PAN_IMAGE_SIZE_10:
474 case PAN_IMAGE_SIZE_25:
475 min = -4.0;
476 break;
477 case PAN_IMAGE_SIZE_33:
478 case PAN_IMAGE_SIZE_50:
479 case PAN_IMAGE_SIZE_100:
480 default:
481 min = -2.0;
482 break;
483 }
484
485 image_zoom_set_limits(pw->imd, min, 32.0);
486 }
487
488
489 /*
490 *-----------------------------------------------------------------------------
491 * cache
492 *-----------------------------------------------------------------------------
493 */
494
pan_cache_sort_file_cb(gpointer a,gpointer b)495 static gint pan_cache_sort_file_cb(gpointer a, gpointer b)
496 {
497 PanCacheData *pca = a;
498 PanCacheData *pcb = b;
499 return filelist_sort_compare_filedata(pca->fd, pcb->fd);
500 }
pan_cache_sort(GList * list,SortType method,gboolean ascend)501 GList *pan_cache_sort(GList *list, SortType method, gboolean ascend)
502 {
503 return filelist_sort_full(list, method, ascend, (GCompareFunc) pan_cache_sort_file_cb);
504 }
505
506
pan_cache_free(PanWindow * pw)507 static void pan_cache_free(PanWindow *pw)
508 {
509 GList *work;
510
511 work = pw->cache_list;
512 while (work)
513 {
514 PanCacheData *pc;
515
516 pc = work->data;
517 work = work->next;
518
519 cache_sim_data_free(pc->cd);
520 file_data_unref(pc->fd);
521 g_free(pc);
522 }
523
524 g_list_free(pw->cache_list);
525 pw->cache_list = NULL;
526
527 filelist_free(pw->cache_todo);
528 pw->cache_todo = NULL;
529
530 pw->cache_count = 0;
531 pw->cache_total = 0;
532 pw->cache_tick = 0;
533
534 cache_loader_free(pw->cache_cl);
535 pw->cache_cl = NULL;
536 }
537
pan_cache_fill(PanWindow * pw,FileData * dir_fd)538 static void pan_cache_fill(PanWindow *pw, FileData *dir_fd)
539 {
540 GList *list;
541
542 pan_cache_free(pw);
543
544 list = pan_list_tree(dir_fd, SORT_NAME, TRUE, pw->ignore_symlinks);
545 pw->cache_todo = g_list_reverse(list);
546
547 pw->cache_total = g_list_length(pw->cache_todo);
548 }
549
pan_cache_step_done_cb(CacheLoader * cl,gint error,gpointer data)550 static void pan_cache_step_done_cb(CacheLoader *cl, gint error, gpointer data)
551 {
552 PanWindow *pw = data;
553
554 if (pw->cache_list)
555 {
556 PanCacheData *pc;
557 pc = pw->cache_list->data;
558
559 if (!pc->cd)
560 {
561 pc->cd = cl->cd;
562 cl->cd = NULL;
563 }
564 }
565
566 cache_loader_free(cl);
567 pw->cache_cl = NULL;
568
569 pan_layout_update_idle(pw);
570 }
571
pan_cache_step(PanWindow * pw)572 static gboolean pan_cache_step(PanWindow *pw)
573 {
574 FileData *fd;
575 PanCacheData *pc;
576 CacheDataType load_mask;
577
578 if (!pw->cache_todo) return TRUE;
579
580 fd = pw->cache_todo->data;
581 pw->cache_todo = g_list_remove(pw->cache_todo, fd);
582
583 pc = g_new0(PanCacheData, 1);
584 pc->fd = file_data_ref(fd);
585
586 pc->cd = NULL;
587
588 pw->cache_list = g_list_prepend(pw->cache_list, pc);
589
590 cache_loader_free(pw->cache_cl);
591
592 load_mask = CACHE_LOADER_NONE;
593 if (pw->size > PAN_IMAGE_SIZE_THUMB_LARGE) load_mask |= CACHE_LOADER_DIMENSIONS;
594 if (pw->exif_date_enable) load_mask |= CACHE_LOADER_DATE;
595 pw->cache_cl = cache_loader_new(pc->fd, load_mask,
596 pan_cache_step_done_cb, pw);
597 return (pw->cache_cl == NULL);
598 }
599
600 /* This sync date function is optimized for lists with a common sort */
pan_cache_sync_date(PanWindow * pw,GList * list)601 void pan_cache_sync_date(PanWindow *pw, GList *list)
602 {
603 GList *haystack;
604 GList *work;
605
606 haystack = g_list_copy(pw->cache_list);
607
608 work = list;
609 while (work)
610 {
611 FileData *fd;
612 GList *needle;
613
614 fd = work->data;
615 work = work->next;
616
617 needle = haystack;
618 while (needle)
619 {
620 PanCacheData *pc;
621
622 pc = needle->data;
623 if (pc->fd == fd)
624 {
625 if (pc->cd && pc->cd->have_date && pc->cd->date >= 0)
626 {
627 fd->date = pc->cd->date;
628 }
629
630 haystack = g_list_delete_link(haystack, needle);
631 needle = NULL;
632 }
633 else
634 {
635 needle = needle->next;
636 }
637 }
638 }
639
640 g_list_free(haystack);
641 }
642
643 /*
644 *-----------------------------------------------------------------------------
645 * item grid
646 *-----------------------------------------------------------------------------
647 */
648
pan_grid_clear(PanWindow * pw)649 static void pan_grid_clear(PanWindow *pw)
650 {
651 GList *work;
652
653 work = pw->list_grid;
654 while (work)
655 {
656 PanGrid *pg;
657
658 pg = work->data;
659 work = work->next;
660
661 g_list_free(pg->list);
662 g_free(pg);
663 }
664
665 g_list_free(pw->list_grid);
666 pw->list_grid = NULL;
667
668 pw->list = g_list_concat(pw->list, pw->list_static);
669 pw->list_static = NULL;
670 }
671
pan_grid_build(PanWindow * pw,gint width,gint height,gint grid_size)672 static void pan_grid_build(PanWindow *pw, gint width, gint height, gint grid_size)
673 {
674 GList *work;
675 gint col, row;
676 gint cw, ch;
677 gint l;
678 gint i, j;
679
680 pan_grid_clear(pw);
681
682 l = g_list_length(pw->list);
683
684 if (l < 1) return;
685
686 col = (gint)(sqrt((gdouble)l / grid_size) * width / height + 0.999);
687 col = CLAMP(col, 1, l / grid_size + 1);
688 row = (gint)((gdouble)l / grid_size / col);
689 if (row < 1) row = 1;
690
691 /* limit minimum size of grid so that a tile will always fit regardless of position */
692 cw = MAX((gint)ceil((gdouble)width / col), PAN_TILE_SIZE * 2);
693 ch = MAX((gint)ceil((gdouble)height / row), PAN_TILE_SIZE * 2);
694
695 row = row * 2 - 1;
696 col = col * 2 - 1;
697
698 DEBUG_1("intersect speedup grid is %dx%d, based on %d average per grid", col, row, grid_size);
699
700 for (j = 0; j < row; j++)
701 for (i = 0; i < col; i++)
702 {
703 if ((i + 1) * cw / 2 < width && (j + 1) * ch / 2 < height)
704 {
705 PanGrid *pg;
706
707 pg = g_new0(PanGrid, 1);
708 pg->x = i * cw / 2;
709 pg->y = j * ch / 2;
710 pg->w = cw;
711 pg->h = ch;
712
713 pw->list_grid = g_list_prepend(pw->list_grid, pg);
714
715 DEBUG_1("grid section: %d,%d (%dx%d)", pg->x, pg->y, pg->w, pg->h);
716 }
717 }
718
719 work = pw->list;
720 while (work)
721 {
722 PanItem *pi;
723 GList *grid;
724
725 pi = work->data;
726 work = work->next;
727
728 grid = pw->list_grid;
729 while (grid)
730 {
731 PanGrid *pg;
732 gint rx, ry, rw, rh;
733
734 pg = grid->data;
735 grid = grid->next;
736
737 if (util_clip_region(pi->x, pi->y, pi->width, pi->height,
738 pg->x, pg->y, pg->w, pg->h,
739 &rx, &ry, &rw, &rh))
740 {
741 pg->list = g_list_prepend(pg->list, pi);
742 }
743 }
744 }
745
746 work = pw->list_grid;
747 while (work)
748 {
749 PanGrid *pg;
750
751 pg = work->data;
752 work = work->next;
753
754 pg->list = g_list_reverse(pg->list);
755 }
756
757 pw->list_static = pw->list;
758 pw->list = NULL;
759 }
760
761
762 /*
763 *-----------------------------------------------------------------------------
764 * layout state reset
765 *-----------------------------------------------------------------------------
766 */
767
pan_window_items_free(PanWindow * pw)768 static void pan_window_items_free(PanWindow *pw)
769 {
770 GList *work;
771
772 pan_grid_clear(pw);
773
774 work = pw->list;
775 while (work)
776 {
777 PanItem *pi = work->data;
778 work = work->next;
779
780 pan_item_free(pi);
781 }
782
783 g_list_free(pw->list);
784 pw->list = NULL;
785
786 g_list_free(pw->queue);
787 pw->queue = NULL;
788 pw->queue_pi = NULL;
789
790 image_loader_free(pw->il);
791 pw->il = NULL;
792
793 thumb_loader_free(pw->tl);
794 pw->tl = NULL;
795
796 pw->click_pi = NULL;
797 pw->search_pi = NULL;
798 }
799
800
801 /*
802 *-----------------------------------------------------------------------------
803 * layout generation, queries, sizing
804 *-----------------------------------------------------------------------------
805 */
806
pan_layout_compute(PanWindow * pw,FileData * dir_fd,gint * width,gint * height,gint * scroll_x,gint * scroll_y)807 static void pan_layout_compute(PanWindow *pw, FileData *dir_fd,
808 gint *width, gint *height,
809 gint *scroll_x, gint *scroll_y)
810 {
811 pan_window_items_free(pw);
812
813 switch (pw->size)
814 {
815 case PAN_IMAGE_SIZE_THUMB_DOTS:
816 pw->thumb_size = PAN_THUMB_SIZE_DOTS;
817 pw->thumb_gap = PAN_THUMB_GAP_DOTS;
818 break;
819 case PAN_IMAGE_SIZE_THUMB_NONE:
820 pw->thumb_size = PAN_THUMB_SIZE_NONE;
821 pw->thumb_gap = PAN_THUMB_GAP_SMALL;
822 break;
823 case PAN_IMAGE_SIZE_THUMB_SMALL:
824 pw->thumb_size = PAN_THUMB_SIZE_SMALL;
825 pw->thumb_gap = PAN_THUMB_GAP_SMALL;
826 break;
827 case PAN_IMAGE_SIZE_THUMB_NORMAL:
828 default:
829 pw->thumb_size = PAN_THUMB_SIZE_NORMAL;
830 pw->thumb_gap = PAN_THUMB_GAP_NORMAL;
831 break;
832 case PAN_IMAGE_SIZE_THUMB_LARGE:
833 pw->thumb_size = PAN_THUMB_SIZE_LARGE;
834 pw->thumb_gap = PAN_THUMB_GAP_LARGE;
835 break;
836 case PAN_IMAGE_SIZE_10:
837 pw->image_size = 10;
838 pw->thumb_gap = PAN_THUMB_GAP_NORMAL;
839 break;
840 case PAN_IMAGE_SIZE_25:
841 pw->image_size = 25;
842 pw->thumb_gap = PAN_THUMB_GAP_NORMAL;
843 break;
844 case PAN_IMAGE_SIZE_33:
845 pw->image_size = 33;
846 pw->thumb_gap = PAN_THUMB_GAP_LARGE;
847 break;
848 case PAN_IMAGE_SIZE_50:
849 pw->image_size = 50;
850 pw->thumb_gap = PAN_THUMB_GAP_HUGE;
851 break;
852 case PAN_IMAGE_SIZE_100:
853 pw->image_size = 100;
854 pw->thumb_gap = PAN_THUMB_GAP_HUGE;
855 break;
856 }
857
858 *width = 0;
859 *height = 0;
860 *scroll_x = 0;
861 *scroll_y = 0;
862
863 switch (pw->layout)
864 {
865 case PAN_LAYOUT_GRID:
866 default:
867 pan_grid_compute(pw, dir_fd, width, height);
868 break;
869 case PAN_LAYOUT_FOLDERS_LINEAR:
870 pan_folder_tree_compute(pw, dir_fd, width, height);
871 break;
872 case PAN_LAYOUT_FOLDERS_FLOWER:
873 pan_flower_compute(pw, dir_fd, width, height, scroll_x, scroll_y);
874 break;
875 case PAN_LAYOUT_CALENDAR:
876 pan_calendar_compute(pw, dir_fd, width, height);
877 break;
878 case PAN_LAYOUT_TIMELINE:
879 pan_timeline_compute(pw, dir_fd, width, height);
880 break;
881 }
882
883 pan_cache_free(pw);
884
885 DEBUG_1("computed %d objects", g_list_length(pw->list));
886 }
887
pan_layout_intersect_l(GList * list,GList * item_list,gint x,gint y,gint width,gint height)888 static GList *pan_layout_intersect_l(GList *list, GList *item_list,
889 gint x, gint y, gint width, gint height)
890 {
891 GList *work;
892
893 work = item_list;
894 while (work)
895 {
896 PanItem *pi;
897 gint rx, ry, rw, rh;
898
899 pi = work->data;
900 work = work->next;
901
902 if (util_clip_region(x, y, width, height,
903 pi->x, pi->y, pi->width, pi->height,
904 &rx, &ry, &rw, &rh))
905 {
906 list = g_list_prepend(list, pi);
907 }
908 }
909
910 return list;
911 }
912
pan_layout_intersect(PanWindow * pw,gint x,gint y,gint width,gint height)913 GList *pan_layout_intersect(PanWindow *pw, gint x, gint y, gint width, gint height)
914 {
915 GList *list = NULL;
916 GList *grid;
917 PanGrid *pg = NULL;
918
919 grid = pw->list_grid;
920 while (grid && !pg)
921 {
922 pg = grid->data;
923 grid = grid->next;
924
925 if (x < pg->x || x + width > pg->x + pg->w ||
926 y < pg->y || y + height > pg->y + pg->h)
927 {
928 pg = NULL;
929 }
930 }
931
932 list = pan_layout_intersect_l(list, pw->list, x, y, width, height);
933
934 if (pg)
935 {
936 list = pan_layout_intersect_l(list, pg->list, x, y, width, height);
937 }
938 else
939 {
940 list = pan_layout_intersect_l(list, pw->list_static, x, y, width, height);
941 }
942
943 return list;
944 }
945
pan_layout_resize(PanWindow * pw)946 void pan_layout_resize(PanWindow *pw)
947 {
948 gint width = 0;
949 gint height = 0;
950 GList *work;
951 PixbufRenderer *pr;
952
953 work = pw->list;
954 while (work)
955 {
956 PanItem *pi;
957
958 pi = work->data;
959 work = work->next;
960
961 if (width < pi->x + pi->width) width = pi->x + pi->width;
962 if (height < pi->y + pi->height) height = pi->y + pi->height;
963 }
964 work = pw->list_static;
965 while (work)
966 {
967 PanItem *pi;
968
969 pi = work->data;
970 work = work->next;
971
972 if (width < pi->x + pi->width) width = pi->x + pi->width;
973 if (height < pi->y + pi->height) height = pi->y + pi->height;
974 }
975
976 width += PAN_BOX_BORDER * 2;
977 height += PAN_BOX_BORDER * 2;
978
979 pr = PIXBUF_RENDERER(pw->imd->pr);
980 if (width < pr->window_width) width = pr->window_width;
981 if (height < pr->window_width) height = pr->window_height;
982
983 pixbuf_renderer_set_tiles_size(PIXBUF_RENDERER(pw->imd->pr), width, height);
984 }
985
pan_layout_update_idle_cb(gpointer data)986 static gint pan_layout_update_idle_cb(gpointer data)
987 {
988 PanWindow *pw = data;
989 gint width;
990 gint height;
991 gint scroll_x;
992 gint scroll_y;
993
994 if (pw->size > PAN_IMAGE_SIZE_THUMB_LARGE ||
995 (pw->exif_date_enable && (pw->layout == PAN_LAYOUT_TIMELINE || pw->layout == PAN_LAYOUT_CALENDAR)))
996 {
997 if (!pw->cache_list && !pw->cache_todo)
998 {
999 pan_cache_fill(pw, pw->dir_fd);
1000 if (pw->cache_todo)
1001 {
1002 pan_window_message(pw, _("Reading image data..."));
1003 return TRUE;
1004 }
1005 }
1006 if (pw->cache_todo)
1007 {
1008 pw->cache_count++;
1009 pw->cache_tick++;
1010 if (pw->cache_count == pw->cache_total)
1011 {
1012 pan_window_message(pw, _("Sorting..."));
1013 }
1014 else if (pw->cache_tick > 9)
1015 {
1016 gchar *buf;
1017
1018 buf = g_strdup_printf("%s %d / %d", _("Reading image data..."),
1019 pw->cache_count, pw->cache_total);
1020 pan_window_message(pw, buf);
1021 g_free(buf);
1022
1023 pw->cache_tick = 0;
1024 }
1025
1026 if (pan_cache_step(pw)) return TRUE;
1027
1028 pw->idle_id = 0;
1029 return FALSE;
1030 }
1031 }
1032
1033 pan_layout_compute(pw, pw->dir_fd, &width, &height, &scroll_x, &scroll_y);
1034
1035 pan_window_zoom_limit(pw);
1036
1037 if (width > 0 && height > 0)
1038 {
1039 gdouble align;
1040
1041 DEBUG_1("Canvas size is %d x %d", width, height);
1042
1043 pan_grid_build(pw, width, height, 1000);
1044
1045 pixbuf_renderer_set_tiles(PIXBUF_RENDERER(pw->imd->pr), width, height,
1046 PAN_TILE_SIZE, PAN_TILE_SIZE, 10,
1047 pan_window_request_tile_cb,
1048 pan_window_dispose_tile_cb, pw, 1.0);
1049
1050 if (scroll_x == 0 && scroll_y == 0)
1051 {
1052 align = 0.0;
1053 }
1054 else
1055 {
1056 align = 0.5;
1057 }
1058 pixbuf_renderer_scroll_to_point(PIXBUF_RENDERER(pw->imd->pr), scroll_x, scroll_y, align, align);
1059 }
1060
1061 pan_window_message(pw, NULL);
1062
1063 pw->idle_id = 0;
1064 return FALSE;
1065 }
1066
pan_layout_update_idle(PanWindow * pw)1067 static void pan_layout_update_idle(PanWindow *pw)
1068 {
1069 if (!pw->idle_id)
1070 {
1071 pw->idle_id = g_idle_add(pan_layout_update_idle_cb, pw);
1072 }
1073 }
1074
pan_layout_update(PanWindow * pw)1075 void pan_layout_update(PanWindow *pw)
1076 {
1077 pan_window_message(pw, _("Sorting images..."));
1078 pan_layout_update_idle(pw);
1079 }
1080
pan_layout_set_fd(PanWindow * pw,FileData * dir_fd)1081 static void pan_layout_set_fd(PanWindow *pw, FileData *dir_fd)
1082 {
1083 if (!dir_fd) return;
1084
1085 if (strcmp(dir_fd->path, G_DIR_SEPARATOR_S) == 0)
1086 {
1087 pan_warning_folder(dir_fd->path, pw->window);
1088 return;
1089 }
1090
1091 file_data_unref(pw->dir_fd);
1092 pw->dir_fd = file_data_ref(dir_fd);
1093
1094 pan_layout_update(pw);
1095 }
1096
1097
1098 /*
1099 *-----------------------------------------------------------------------------
1100 * keyboard handlers
1101 *-----------------------------------------------------------------------------
1102 */
1103
pan_menu_click_fd(PanWindow * pw)1104 FileData *pan_menu_click_fd(PanWindow *pw)
1105 {
1106 if (pw->click_pi && pw->click_pi->fd) return pw->click_pi->fd;
1107 return NULL;
1108 }
1109
pan_window_menu_pos_cb(GtkMenu * menu,gint * x,gint * y,gboolean * push_in,gpointer data)1110 static void pan_window_menu_pos_cb(GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer data)
1111 {
1112 PanWindow *pw = data;
1113
1114 gdk_window_get_origin(gtk_widget_get_window(pw->imd->pr), x, y);
1115 popup_menu_position_clamp(menu, x, y, 0);
1116 }
1117
pan_window_key_press_cb(GtkWidget * widget,GdkEventKey * event,gpointer data)1118 static gboolean pan_window_key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
1119 {
1120 PanWindow *pw = data;
1121 PixbufRenderer *pr;
1122 FileData *fd;
1123 gboolean stop_signal = FALSE;
1124 GtkWidget *menu;
1125 GtkWidget *imd_widget;
1126 gint x = 0;
1127 gint y = 0;
1128 gint focused;
1129 gint on_entry;
1130
1131 pr = PIXBUF_RENDERER(pw->imd->pr);
1132 fd = pan_menu_click_fd(pw);
1133
1134 imd_widget = gtk_container_get_focus_child(GTK_CONTAINER(pw->imd->widget));
1135 focused = (pw->fs || (imd_widget && gtk_widget_has_focus(imd_widget)));
1136 on_entry = (gtk_widget_has_focus(pw->path_entry) ||
1137 gtk_widget_has_focus(pw->search_ui->search_entry) ||
1138 gtk_widget_has_focus(pw->filter_ui->filter_entry));
1139
1140 if (focused)
1141 {
1142 stop_signal = TRUE;
1143 switch (event->keyval)
1144 {
1145 case GDK_KEY_Left: case GDK_KEY_KP_Left:
1146 x -= 1;
1147 break;
1148 case GDK_KEY_Right: case GDK_KEY_KP_Right:
1149 x += 1;
1150 break;
1151 case GDK_KEY_Up: case GDK_KEY_KP_Up:
1152 y -= 1;
1153 break;
1154 case GDK_KEY_Down: case GDK_KEY_KP_Down:
1155 y += 1;
1156 break;
1157 case GDK_KEY_Page_Up: case GDK_KEY_KP_Page_Up:
1158 pixbuf_renderer_scroll(pr, 0, 0 - pr->vis_height / 2);
1159 break;
1160 case GDK_KEY_Page_Down: case GDK_KEY_KP_Page_Down:
1161 pixbuf_renderer_scroll(pr, 0, pr->vis_height / 2);
1162 break;
1163 case GDK_KEY_Home: case GDK_KEY_KP_Home:
1164 pixbuf_renderer_scroll(pr, 0 - pr->vis_width / 2, 0);
1165 break;
1166 case GDK_KEY_End: case GDK_KEY_KP_End:
1167 pixbuf_renderer_scroll(pr, pr->vis_width / 2, 0);
1168 break;
1169 default:
1170 stop_signal = FALSE;
1171 break;
1172 }
1173
1174 if (x != 0 || y!= 0)
1175 {
1176 if (event->state & GDK_SHIFT_MASK)
1177 {
1178 x *= 3;
1179 y *= 3;
1180 }
1181 keyboard_scroll_calc(&x, &y, event);
1182 pixbuf_renderer_scroll(pr, x, y);
1183 }
1184 }
1185
1186 if (stop_signal) return stop_signal;
1187
1188 if (event->state & GDK_CONTROL_MASK)
1189 {
1190 stop_signal = TRUE;
1191 switch (event->keyval)
1192 {
1193 case '1':
1194 case '2':
1195 case '3':
1196 case '4':
1197 case '5':
1198 case '6':
1199 case '7':
1200 case '8':
1201 case '9':
1202 case '0':
1203 break;
1204 case 'C': case 'c':
1205 if (fd) file_util_copy(fd, NULL, NULL, GTK_WIDGET(pr));
1206 break;
1207 case 'M': case 'm':
1208 if (fd) file_util_move(fd, NULL, NULL, GTK_WIDGET(pr));
1209 break;
1210 case 'R': case 'r':
1211 if (fd) file_util_rename(fd, NULL, GTK_WIDGET(pr));
1212 break;
1213 case 'D': case 'd':
1214 if (fd)
1215 {
1216 options->file_ops.safe_delete_enable = TRUE;
1217 file_util_delete(fd, NULL, GTK_WIDGET(pr));
1218 }
1219 break;
1220 case 'F': case 'f':
1221 pan_search_toggle_visible(pw, TRUE);
1222 break;
1223 case 'G': case 'g':
1224 pan_search_activate(pw);
1225 break;
1226 case 'W': case 'w':
1227 pan_window_close(pw);
1228 break;
1229 default:
1230 stop_signal = FALSE;
1231 break;
1232 }
1233 }
1234 else
1235 {
1236 stop_signal = TRUE;
1237 switch (event->keyval)
1238 {
1239 case GDK_KEY_Escape:
1240 if (pw->fs)
1241 {
1242 pan_fullscreen_toggle(pw, TRUE);
1243 }
1244 else
1245 {
1246 pan_search_toggle_visible(pw, FALSE);
1247 }
1248 break;
1249 default:
1250 stop_signal = FALSE;
1251 break;
1252 }
1253
1254 if (stop_signal) return stop_signal;
1255
1256 // Don't steal characters from entry boxes.
1257 if (!on_entry)
1258 {
1259 stop_signal = TRUE;
1260 switch (event->keyval)
1261 {
1262 case '+': case '=': case GDK_KEY_KP_Add:
1263 pixbuf_renderer_zoom_adjust(pr, ZOOM_INCREMENT);
1264 break;
1265 case '-': case GDK_KEY_KP_Subtract:
1266 pixbuf_renderer_zoom_adjust(pr, -ZOOM_INCREMENT);
1267 break;
1268 case 'Z': case 'z': case GDK_KEY_KP_Divide: case '1':
1269 pixbuf_renderer_zoom_set(pr, 1.0);
1270 break;
1271 case '2':
1272 pixbuf_renderer_zoom_set(pr, 2.0);
1273 break;
1274 case '3':
1275 pixbuf_renderer_zoom_set(pr, 3.0);
1276 break;
1277 case '4':
1278 pixbuf_renderer_zoom_set(pr, 4.0);
1279 break;
1280 case '7':
1281 pixbuf_renderer_zoom_set(pr, -4.0);
1282 break;
1283 case '8':
1284 pixbuf_renderer_zoom_set(pr, -3.0);
1285 break;
1286 case '9':
1287 pixbuf_renderer_zoom_set(pr, -2.0);
1288 break;
1289 case 'F': case 'f':
1290 case 'V': case 'v':
1291 case GDK_KEY_F11:
1292 pan_fullscreen_toggle(pw, FALSE);
1293 break;
1294 case 'I': case 'i':
1295 break;
1296 case GDK_KEY_Delete: case GDK_KEY_KP_Delete:
1297 break;
1298 case GDK_KEY_Menu:
1299 case GDK_KEY_F10:
1300 menu = pan_popup_menu(pw);
1301 gtk_menu_popup(GTK_MENU(menu), NULL, NULL,
1302 pan_window_menu_pos_cb, pw, 0, GDK_CURRENT_TIME);
1303 break;
1304 case '/':
1305 pan_search_toggle_visible(pw, TRUE);
1306 break;
1307 stop_signal = FALSE;
1308 break;
1309 }
1310 }
1311 }
1312 if (!stop_signal && is_help_key(event))
1313 {
1314 help_window_show("GuideOtherWindowsPanView.html");
1315 stop_signal = TRUE;
1316 }
1317
1318 return stop_signal;
1319 }
1320
1321 /*
1322 *-----------------------------------------------------------------------------
1323 * info popup
1324 *-----------------------------------------------------------------------------
1325 */
1326
pan_info_add_exif(PanTextAlignment * ta,FileData * fd)1327 static void pan_info_add_exif(PanTextAlignment *ta, FileData *fd)
1328 {
1329 GList *exif_list;
1330 gchar *text;
1331 gchar *title;
1332 gchar *key;
1333
1334 if (!fd) return;
1335
1336 exif_list = bar_pane_exif_list();
1337 while (exif_list)
1338 {
1339 title = exif_list->data;
1340 exif_list = exif_list->next;
1341 key = exif_list->data;
1342 exif_list = exif_list->next;
1343
1344 text = metadata_read_string(fd, key, METADATA_FORMATTED);
1345 if (text && text[0] != '\0')
1346 {
1347 pan_text_alignment_add(ta, title, text);
1348 }
1349
1350 g_free(text);
1351 }
1352
1353 string_list_free(exif_list);
1354 }
1355
1356
pan_info_update(PanWindow * pw,PanItem * pi)1357 void pan_info_update(PanWindow *pw, PanItem *pi)
1358 {
1359 PanTextAlignment *ta;
1360 PanItem *pbox;
1361 PanItem *p;
1362 gchar *buf;
1363 gint x1, y1, x2, y2, x3, y3;
1364 gint x, y, w, h;
1365
1366 if (pw->click_pi == pi) return;
1367 if (pi && !pi->fd) pi = NULL;
1368
1369 while ((p = pan_item_find_by_key(pw, PAN_ITEM_NONE, "info"))) pan_item_remove(pw, p);
1370 pw->click_pi = pi;
1371
1372 if (!pi) return;
1373
1374 DEBUG_1("info set to %s", pi->fd->path);
1375
1376 pbox = pan_item_box_new(pw, NULL, pi->x + pi->width + 4, pi->y, 10, 10,
1377 PAN_POPUP_BORDER,
1378 PAN_POPUP_COLOR, PAN_POPUP_ALPHA,
1379 PAN_POPUP_BORDER_COLOR, PAN_POPUP_ALPHA);
1380 pan_item_set_key(pbox, "info");
1381
1382 if (pi->type == PAN_ITEM_THUMB && pi->pixbuf)
1383 {
1384 w = gdk_pixbuf_get_width(pi->pixbuf);
1385 h = gdk_pixbuf_get_height(pi->pixbuf);
1386
1387 x1 = pi->x + pi->width - (pi->width - w) / 2 - 8;
1388 y1 = pi->y + (pi->height - h) / 2 + 8;
1389 }
1390 else
1391 {
1392 x1 = pi->x + pi->width - 8;
1393 y1 = pi->y + 8;
1394 }
1395
1396 x2 = pbox->x + 1;
1397 y2 = pbox->y + 36;
1398 x3 = pbox->x + 1;
1399 y3 = pbox->y + 12;
1400 util_clip_triangle(x1, y1, x2, y2, x3, y3,
1401 &x, &y, &w, &h);
1402
1403 p = pan_item_tri_new(pw, NULL, x, y, w, h,
1404 x1, y1, x2, y2, x3, y3,
1405 PAN_POPUP_COLOR, PAN_POPUP_ALPHA);
1406 pan_item_tri_border(p, PAN_BORDER_1 | PAN_BORDER_3, PAN_POPUP_BORDER_COLOR, PAN_POPUP_ALPHA);
1407 pan_item_set_key(p, "info");
1408 pan_item_added(pw, p);
1409
1410 ta = pan_text_alignment_new(pw, pbox->x + PREF_PAD_BORDER, pbox->y + PREF_PAD_BORDER, "info");
1411
1412 pan_text_alignment_add(ta, _("Filename:"), pi->fd->name);
1413 buf = remove_level_from_path(pi->fd->path);
1414 pan_text_alignment_add(ta, _("Location:"), buf);
1415 g_free(buf);
1416 pan_text_alignment_add(ta, _("Date:"), text_from_time(pi->fd->date));
1417 buf = text_from_size(pi->fd->size);
1418 pan_text_alignment_add(ta, _("Size:"), buf);
1419 g_free(buf);
1420
1421 if (pw->info_includes_exif)
1422 {
1423 pan_info_add_exif(ta, pi->fd);
1424 }
1425
1426 pan_text_alignment_calc(ta, pbox);
1427 pan_text_alignment_free(ta);
1428
1429 pan_item_box_shadow(pbox, PAN_SHADOW_OFFSET * 2, PAN_SHADOW_FADE * 2);
1430 pan_item_added(pw, pbox);
1431
1432 if (pw->info_image_size > PAN_IMAGE_SIZE_THUMB_NONE)
1433 {
1434 gint iw, ih;
1435 if (image_load_dimensions(pi->fd, &iw, &ih))
1436 {
1437 gint scale = 25;
1438
1439 switch (pw->info_image_size)
1440 {
1441 case PAN_IMAGE_SIZE_10:
1442 scale = 10;
1443 break;
1444 case PAN_IMAGE_SIZE_25:
1445 scale = 25;
1446 break;
1447 case PAN_IMAGE_SIZE_33:
1448 scale = 33;
1449 break;
1450 case PAN_IMAGE_SIZE_50:
1451 scale = 50;
1452 break;
1453 case PAN_IMAGE_SIZE_100:
1454 scale = 100;
1455 break;
1456 }
1457
1458 iw = MAX(1, iw * scale / 100);
1459 ih = MAX(1, ih * scale / 100);
1460
1461 pbox = pan_item_box_new(pw, NULL, pbox->x, pbox->y + pbox->height + 8, 10, 10,
1462 PAN_POPUP_BORDER,
1463 PAN_POPUP_COLOR, PAN_POPUP_ALPHA,
1464 PAN_POPUP_BORDER_COLOR, PAN_POPUP_ALPHA);
1465 pan_item_set_key(pbox, "info");
1466
1467 p = pan_item_image_new(pw, file_data_new_group(pi->fd->path),
1468 pbox->x + PREF_PAD_BORDER, pbox->y + PREF_PAD_BORDER, iw, ih);
1469 pan_item_set_key(p, "info");
1470 pan_item_size_by_item(pbox, p, PREF_PAD_BORDER);
1471
1472 pan_item_box_shadow(pbox, PAN_SHADOW_OFFSET * 2, PAN_SHADOW_FADE * 2);
1473 pan_item_added(pw, pbox);
1474 }
1475 }
1476
1477 pan_layout_resize(pw);
1478 }
1479
1480
1481 /*
1482 *-----------------------------------------------------------------------------
1483 * main window
1484 *-----------------------------------------------------------------------------
1485 */
1486
button_cb(PixbufRenderer * pr,GdkEventButton * event,gpointer data)1487 static void button_cb(PixbufRenderer *pr, GdkEventButton *event, gpointer data)
1488 {
1489 PanWindow *pw = data;
1490 PanItem *pi = NULL;
1491 GtkWidget *menu;
1492 gint rx, ry;
1493
1494 rx = ry = 0;
1495 if (pr->scale)
1496 {
1497 rx = (gdouble)(pr->x_scroll + event->x - pr->x_offset) / pr->scale;
1498 ry = (gdouble)(pr->y_scroll + event->y - pr->y_offset) / pr->scale;
1499 }
1500
1501 pi = pan_item_find_by_coord(pw, PAN_ITEM_BOX, rx, ry, "info");
1502 if (pi && event->button == MOUSE_BUTTON_LEFT)
1503 {
1504 pan_info_update(pw, NULL);
1505 return;
1506 }
1507
1508 pi = pan_item_find_by_coord(pw, (pw->size > PAN_IMAGE_SIZE_THUMB_LARGE) ? PAN_ITEM_IMAGE : PAN_ITEM_THUMB,
1509 rx, ry, NULL);
1510
1511 switch (event->button)
1512 {
1513 case MOUSE_BUTTON_LEFT:
1514 pan_info_update(pw, pi);
1515
1516 if (!pi && pw->layout == PAN_LAYOUT_CALENDAR)
1517 {
1518 pi = pan_item_find_by_coord(pw, PAN_ITEM_BOX, rx, ry, "day");
1519 pan_calendar_update(pw, pi);
1520 }
1521 break;
1522 case MOUSE_BUTTON_MIDDLE:
1523 break;
1524 case MOUSE_BUTTON_RIGHT:
1525 pan_info_update(pw, pi);
1526 menu = pan_popup_menu(pw);
1527 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 3, event->time);
1528 break;
1529 default:
1530 break;
1531 }
1532 }
1533
scroll_cb(PixbufRenderer * pr,GdkEventScroll * event,gpointer data)1534 static void scroll_cb(PixbufRenderer *pr, GdkEventScroll *event, gpointer data)
1535 {
1536 gint w, h;
1537
1538 w = pr->vis_width;
1539 h = pr->vis_height;
1540
1541 if (!(event->state & GDK_SHIFT_MASK))
1542 {
1543 w /= 3;
1544 h /= 3;
1545 }
1546
1547 if (event->state & GDK_CONTROL_MASK)
1548 {
1549 switch (event->direction)
1550 {
1551 case GDK_SCROLL_UP:
1552 pixbuf_renderer_zoom_adjust_at_point(pr, ZOOM_INCREMENT,
1553 (gint)event->x, (gint)event->y);
1554 break;
1555 case GDK_SCROLL_DOWN:
1556 pixbuf_renderer_zoom_adjust_at_point(pr, -ZOOM_INCREMENT,
1557 (gint)event->x, (gint)event->y);
1558 break;
1559 default:
1560 break;
1561 }
1562 }
1563 else
1564 {
1565 switch (event->direction)
1566 {
1567 case GDK_SCROLL_UP:
1568 pixbuf_renderer_scroll(pr, 0, -h);
1569 break;
1570 case GDK_SCROLL_DOWN:
1571 pixbuf_renderer_scroll(pr, 0, h);
1572 break;
1573 case GDK_SCROLL_LEFT:
1574 pixbuf_renderer_scroll(pr, -w, 0);
1575 break;
1576 case GDK_SCROLL_RIGHT:
1577 pixbuf_renderer_scroll(pr, w, 0);
1578 break;
1579 default:
1580 break;
1581 }
1582 }
1583 }
1584
pan_image_set_buttons(PanWindow * pw,ImageWindow * imd)1585 static void pan_image_set_buttons(PanWindow *pw, ImageWindow *imd)
1586 {
1587 g_signal_connect(G_OBJECT(imd->pr), "clicked",
1588 G_CALLBACK(button_cb), pw);
1589 g_signal_connect(G_OBJECT(imd->pr), "scroll_event",
1590 G_CALLBACK(scroll_cb), pw);
1591 }
1592
pan_fullscreen_stop_func(FullScreenData * fs,gpointer data)1593 static void pan_fullscreen_stop_func(FullScreenData *fs, gpointer data)
1594 {
1595 PanWindow *pw = data;
1596
1597 pw->fs = NULL;
1598 pw->imd = pw->imd_normal;
1599 }
1600
pan_fullscreen_toggle(PanWindow * pw,gboolean force_off)1601 static void pan_fullscreen_toggle(PanWindow *pw, gboolean force_off)
1602 {
1603 if (force_off && !pw->fs) return;
1604
1605 if (pw->fs)
1606 {
1607 fullscreen_stop(pw->fs);
1608 }
1609 else
1610 {
1611 pw->fs = fullscreen_start(pw->window, pw->imd, pan_fullscreen_stop_func, pw);
1612 pan_image_set_buttons(pw, pw->fs->imd);
1613 g_signal_connect(G_OBJECT(pw->fs->window), "key_press_event",
1614 G_CALLBACK(pan_window_key_press_cb), pw);
1615
1616 pw->imd = pw->fs->imd;
1617 }
1618 }
1619
pan_window_image_zoom_cb(PixbufRenderer * pr,gdouble zoom,gpointer data)1620 static void pan_window_image_zoom_cb(PixbufRenderer *pr, gdouble zoom, gpointer data)
1621 {
1622 PanWindow *pw = data;
1623 gchar *text;
1624
1625 text = image_zoom_get_as_text(pw->imd);
1626 gtk_label_set_text(GTK_LABEL(pw->label_zoom), text);
1627 g_free(text);
1628 }
1629
pan_window_image_scroll_notify_cb(PixbufRenderer * pr,gpointer data)1630 static void pan_window_image_scroll_notify_cb(PixbufRenderer *pr, gpointer data)
1631 {
1632 PanWindow *pw = data;
1633 GtkAdjustment *adj;
1634 GdkRectangle rect;
1635 gint width, height;
1636
1637 if (pr->scale == 0.0) return;
1638
1639 pixbuf_renderer_get_visible_rect(pr, &rect);
1640 pixbuf_renderer_get_image_size(pr, &width, &height);
1641
1642 adj = gtk_range_get_adjustment(GTK_RANGE(pw->scrollbar_h));
1643 gtk_adjustment_set_page_size(adj, rect.width);
1644 gtk_adjustment_set_page_increment(adj, gtk_adjustment_get_page_size(adj) / 2.0);
1645 gtk_adjustment_set_step_increment(adj, 48.0 / pr->scale);
1646 gtk_adjustment_set_lower(adj, 0.0);
1647 gtk_adjustment_set_upper(adj, MAX((gdouble)width, 1.0));
1648 gtk_adjustment_set_value(adj, (gdouble)rect.x);
1649
1650 pref_signal_block_data(pw->scrollbar_h, pw);
1651 gtk_adjustment_changed(adj);
1652 gtk_adjustment_value_changed(adj);
1653 pref_signal_unblock_data(pw->scrollbar_h, pw);
1654
1655 adj = gtk_range_get_adjustment(GTK_RANGE(pw->scrollbar_v));
1656 gtk_adjustment_set_page_size(adj, rect.height);
1657 gtk_adjustment_set_page_increment(adj, gtk_adjustment_get_page_size(adj) / 2.0);
1658 gtk_adjustment_set_step_increment(adj, 48.0 / pr->scale);
1659 gtk_adjustment_set_lower(adj, 0.0);
1660 gtk_adjustment_set_upper(adj, MAX((gdouble)height, 1.0));
1661 gtk_adjustment_set_value(adj, (gdouble)rect.y);
1662
1663 pref_signal_block_data(pw->scrollbar_v, pw);
1664 gtk_adjustment_changed(adj);
1665 gtk_adjustment_value_changed(adj);
1666 pref_signal_unblock_data(pw->scrollbar_v, pw);
1667 }
1668
pan_window_scrollbar_h_value_cb(GtkRange * range,gpointer data)1669 static void pan_window_scrollbar_h_value_cb(GtkRange *range, gpointer data)
1670 {
1671 PanWindow *pw = data;
1672 PixbufRenderer *pr;
1673 gint x;
1674
1675 pr = PIXBUF_RENDERER(pw->imd_normal->pr);
1676
1677 if (!pr->scale) return;
1678
1679 x = (gint)gtk_range_get_value(range);
1680
1681 pixbuf_renderer_scroll_to_point(pr, x, (gint)((gdouble)pr->y_scroll / pr->scale), 0.0, 0.0);
1682 }
1683
pan_window_scrollbar_v_value_cb(GtkRange * range,gpointer data)1684 static void pan_window_scrollbar_v_value_cb(GtkRange *range, gpointer data)
1685 {
1686 PanWindow *pw = data;
1687 PixbufRenderer *pr;
1688 gint y;
1689
1690 pr = PIXBUF_RENDERER(pw->imd_normal->pr);
1691
1692 if (!pr->scale) return;
1693
1694 y = (gint)gtk_range_get_value(range);
1695
1696 pixbuf_renderer_scroll_to_point(pr, (gint)((gdouble)pr->x_scroll / pr->scale), y, 0.0, 0.0);
1697 }
1698
pan_window_layout_change_cb(GtkWidget * combo,gpointer data)1699 static void pan_window_layout_change_cb(GtkWidget *combo, gpointer data)
1700 {
1701 PanWindow *pw = data;
1702
1703 pw->layout = gtk_combo_box_get_active(GTK_COMBO_BOX(combo));
1704 pan_layout_update(pw);
1705 }
1706
pan_window_layout_size_cb(GtkWidget * combo,gpointer data)1707 static void pan_window_layout_size_cb(GtkWidget *combo, gpointer data)
1708 {
1709 PanWindow *pw = data;
1710
1711 pw->size = gtk_combo_box_get_active(GTK_COMBO_BOX(combo));
1712 pan_layout_update(pw);
1713 }
1714
pan_window_entry_activate_cb(const gchar * new_text,gpointer data)1715 static void pan_window_entry_activate_cb(const gchar *new_text, gpointer data)
1716 {
1717 PanWindow *pw = data;
1718 gchar *path;
1719
1720 path = remove_trailing_slash(new_text);
1721 parse_out_relatives(path);
1722
1723 if (!isdir(path))
1724 {
1725 warning_dialog(_("Folder not found"),
1726 _("The entered path is not a folder"),
1727 GTK_STOCK_DIALOG_WARNING, pw->path_entry);
1728 }
1729 else
1730 {
1731 FileData *dir_fd = file_data_new_dir(path);
1732 tab_completion_append_to_history(pw->path_entry, path);
1733
1734 pan_layout_set_fd(pw, dir_fd);
1735 file_data_unref(dir_fd);
1736 }
1737
1738 g_free(path);
1739 }
1740
pan_window_close(PanWindow * pw)1741 static void pan_window_close(PanWindow *pw)
1742 {
1743 pan_window_list = g_list_remove(pan_window_list, pw);
1744
1745 pref_list_int_set(PAN_PREF_GROUP, PAN_PREF_EXIF_PAN_DATE, pw->exif_date_enable);
1746 pref_list_int_set(PAN_PREF_GROUP, PAN_PREF_INFO_IMAGE, pw->info_image_size);
1747 pref_list_int_set(PAN_PREF_GROUP, PAN_PREF_INFO_EXIF, pw->info_includes_exif);
1748
1749 if (pw->idle_id)
1750 {
1751 g_source_remove(pw->idle_id);
1752 }
1753
1754 pan_fullscreen_toggle(pw, TRUE);
1755 pan_search_ui_destroy(&pw->search_ui);
1756 pan_filter_ui_destroy(&pw->filter_ui);
1757 gtk_widget_destroy(pw->window);
1758
1759 pan_window_items_free(pw);
1760 pan_cache_free(pw);
1761
1762 file_data_unref(pw->dir_fd);
1763
1764 g_free(pw);
1765 }
1766
pan_window_delete_cb(GtkWidget * w,GdkEventAny * event,gpointer data)1767 static gboolean pan_window_delete_cb(GtkWidget *w, GdkEventAny *event, gpointer data)
1768 {
1769 PanWindow *pw = data;
1770
1771 pan_window_close(pw);
1772 return TRUE;
1773 }
1774
pan_window_new_real(FileData * dir_fd)1775 static void pan_window_new_real(FileData *dir_fd)
1776 {
1777 PanWindow *pw;
1778 GtkWidget *vbox;
1779 GtkWidget *box;
1780 GtkWidget *combo;
1781 GtkWidget *hbox;
1782 GtkWidget *frame;
1783 GtkWidget *table;
1784 GdkGeometry geometry;
1785
1786 pw = g_new0(PanWindow, 1);
1787
1788 pw->dir_fd = file_data_ref(dir_fd);
1789 pw->layout = PAN_LAYOUT_TIMELINE;
1790 pw->size = PAN_IMAGE_SIZE_THUMB_NORMAL;
1791 pw->thumb_size = PAN_THUMB_SIZE_NORMAL;
1792 pw->thumb_gap = PAN_THUMB_GAP_NORMAL;
1793
1794 if (!pref_list_int_get(PAN_PREF_GROUP, PAN_PREF_EXIF_PAN_DATE, &pw->exif_date_enable))
1795 {
1796 pw->exif_date_enable = FALSE;
1797 }
1798 if (!pref_list_int_get(PAN_PREF_GROUP, PAN_PREF_INFO_IMAGE, &pw->info_image_size))
1799 {
1800 pw->info_image_size = PAN_IMAGE_SIZE_THUMB_NONE;
1801 }
1802 if (!pref_list_int_get(PAN_PREF_GROUP, PAN_PREF_INFO_EXIF, &pw->info_includes_exif))
1803 {
1804 pw->info_includes_exif = TRUE;
1805 }
1806
1807 pw->ignore_symlinks = TRUE;
1808
1809 pw->idle_id = 0;
1810
1811 pw->window = window_new(GTK_WINDOW_TOPLEVEL, "panview", NULL, NULL, _("Pan View"));
1812 DEBUG_NAME(pw->window);
1813
1814 geometry.min_width = DEFAULT_MINIMAL_WINDOW_SIZE;
1815 geometry.min_height = DEFAULT_MINIMAL_WINDOW_SIZE;
1816 gtk_window_set_geometry_hints(GTK_WINDOW(pw->window), NULL, &geometry, GDK_HINT_MIN_SIZE);
1817
1818 gtk_window_set_resizable(GTK_WINDOW(pw->window), TRUE);
1819 gtk_container_set_border_width(GTK_CONTAINER(pw->window), 0);
1820
1821 vbox = gtk_vbox_new(FALSE, 0);
1822 DEBUG_NAME(vbox);
1823 gtk_container_add(GTK_CONTAINER(pw->window), vbox);
1824 gtk_widget_show(vbox);
1825
1826 box = pref_box_new(vbox, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_SPACE);
1827
1828 pref_spacer(box, 0);
1829 pref_label_new(box, _("Location:"));
1830 combo = tab_completion_new_with_history(&pw->path_entry, dir_fd->path, "pan_view_path", -1,
1831 pan_window_entry_activate_cb, pw);
1832 gtk_box_pack_start(GTK_BOX(box), combo, TRUE, TRUE, 0);
1833 gtk_widget_show(combo);
1834
1835 combo = gtk_combo_box_text_new();
1836 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), _("Timeline"));
1837 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), _("Calendar"));
1838 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), _("Folders"));
1839 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), _("Folders (flower)"));
1840 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), _("Grid"));
1841
1842 gtk_combo_box_set_active(GTK_COMBO_BOX(combo), pw->layout);
1843 g_signal_connect(G_OBJECT(combo), "changed",
1844 G_CALLBACK(pan_window_layout_change_cb), pw);
1845 gtk_box_pack_start(GTK_BOX(box), combo, FALSE, FALSE, 0);
1846 gtk_widget_show(combo);
1847
1848 combo = gtk_combo_box_text_new();
1849 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), _("Dots"));
1850 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), _("No Images"));
1851 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), _("Small Thumbnails"));
1852 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), _("Normal Thumbnails"));
1853 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), _("Large Thumbnails"));
1854 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), _("1:10 (10%)"));
1855 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), _("1:4 (25%)"));
1856 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), _("1:3 (33%)"));
1857 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), _("1:2 (50%)"));
1858 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), _("1:1 (100%)"));
1859
1860 gtk_combo_box_set_active(GTK_COMBO_BOX(combo), pw->size);
1861 g_signal_connect(G_OBJECT(combo), "changed",
1862 G_CALLBACK(pan_window_layout_size_cb), pw);
1863 gtk_box_pack_start(GTK_BOX(box), combo, FALSE, FALSE, 0);
1864 gtk_widget_show(combo);
1865
1866 table = pref_table_new(vbox, 2, 2, FALSE, TRUE);
1867 gtk_table_set_row_spacings(GTK_TABLE(table), 2);
1868 gtk_table_set_col_spacings(GTK_TABLE(table), 2);
1869
1870 /* FIXME: pan view does not work correctly when renderer-clutter()
1871 * is used.
1872 */
1873 gint temp = options->image.use_clutter_renderer;
1874 options->image.use_clutter_renderer = FALSE;
1875 pw->imd = image_new(TRUE);
1876 options->image.use_clutter_renderer = temp;
1877
1878 pw->imd_normal = pw->imd;
1879
1880 g_signal_connect(G_OBJECT(pw->imd->pr), "zoom",
1881 G_CALLBACK(pan_window_image_zoom_cb), pw);
1882 g_signal_connect(G_OBJECT(pw->imd->pr), "scroll_notify",
1883 G_CALLBACK(pan_window_image_scroll_notify_cb), pw);
1884
1885 gtk_table_attach(GTK_TABLE(table), pw->imd->widget, 0, 1, 0, 1,
1886 GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 0, 0);
1887 gtk_widget_show(GTK_WIDGET(pw->imd->widget));
1888
1889 pan_window_dnd_init(pw);
1890
1891 pan_image_set_buttons(pw, pw->imd);
1892
1893 pw->scrollbar_h = gtk_hscrollbar_new(NULL);
1894 g_signal_connect(G_OBJECT(pw->scrollbar_h), "value_changed",
1895 G_CALLBACK(pan_window_scrollbar_h_value_cb), pw);
1896 gtk_table_attach(GTK_TABLE(table), pw->scrollbar_h, 0, 1, 1, 2,
1897 GTK_FILL | GTK_EXPAND, 0, 0, 0);
1898 gtk_widget_show(pw->scrollbar_h);
1899
1900 pw->scrollbar_v = gtk_vscrollbar_new(NULL);
1901 g_signal_connect(G_OBJECT(pw->scrollbar_v), "value_changed",
1902 G_CALLBACK(pan_window_scrollbar_v_value_cb), pw);
1903 gtk_table_attach(GTK_TABLE(table), pw->scrollbar_v, 1, 2, 0, 1,
1904 0, GTK_FILL | GTK_EXPAND, 0, 0);
1905 gtk_widget_show(pw->scrollbar_v);
1906
1907 /* find bar */
1908
1909 pw->search_ui = pan_search_ui_new(pw);
1910 gtk_box_pack_start(GTK_BOX(vbox), pw->search_ui->search_box, FALSE, FALSE, 2);
1911
1912 /* filter bar */
1913 pw->filter_ui = pan_filter_ui_new(pw);
1914 gtk_box_pack_start(GTK_BOX(vbox), pw->filter_ui->filter_box, FALSE, FALSE, 2);
1915
1916 /* status bar */
1917
1918 box = pref_box_new(vbox, FALSE, GTK_ORIENTATION_HORIZONTAL, 0);
1919
1920 frame = gtk_frame_new(NULL);
1921 DEBUG_NAME(frame);
1922 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN);
1923 gtk_widget_set_size_request(frame, ZOOM_LABEL_WIDTH, -1);
1924 gtk_box_pack_start(GTK_BOX(box), frame, TRUE, TRUE, 0);
1925 gtk_widget_show(frame);
1926
1927 hbox = gtk_hbox_new(FALSE, PREF_PAD_SPACE);
1928 gtk_container_add(GTK_CONTAINER(frame), hbox);
1929 gtk_widget_show(hbox);
1930
1931 pref_spacer(hbox, 0);
1932 pw->label_message = pref_label_new(hbox, "");
1933
1934 frame = gtk_frame_new(NULL);
1935 DEBUG_NAME(frame);
1936 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN);
1937 gtk_widget_set_size_request(frame, ZOOM_LABEL_WIDTH, -1);
1938 gtk_box_pack_end(GTK_BOX(box), frame, FALSE, FALSE, 0);
1939 gtk_widget_show(frame);
1940
1941 pw->label_zoom = gtk_label_new("");
1942 gtk_container_add(GTK_CONTAINER(frame), pw->label_zoom);
1943 gtk_widget_show(pw->label_zoom);
1944
1945 // Add the "Find" button to the status bar area.
1946 gtk_box_pack_end(GTK_BOX(box), pw->search_ui->search_button, FALSE, FALSE, 0);
1947 gtk_widget_show(pw->search_ui->search_button);
1948
1949 // Add the "Filter" button to the status bar area.
1950 gtk_box_pack_end(GTK_BOX(box), pw->filter_ui->filter_button, FALSE, FALSE, 0);
1951 gtk_widget_show(pw->filter_ui->filter_button);
1952
1953 g_signal_connect(G_OBJECT(pw->window), "delete_event",
1954 G_CALLBACK(pan_window_delete_cb), pw);
1955 g_signal_connect(G_OBJECT(pw->window), "key_press_event",
1956 G_CALLBACK(pan_window_key_press_cb), pw);
1957
1958 gtk_window_set_default_size(GTK_WINDOW(pw->window), PAN_WINDOW_DEFAULT_WIDTH, PAN_WINDOW_DEFAULT_HEIGHT);
1959
1960 pan_layout_update(pw);
1961
1962 gtk_widget_grab_focus(GTK_WIDGET(pw->imd->widget));
1963 gtk_widget_show(pw->window);
1964
1965 pan_window_list = g_list_append(pan_window_list, pw);
1966 }
1967
1968 /*
1969 *-----------------------------------------------------------------------------
1970 * peformance warnings
1971 *-----------------------------------------------------------------------------
1972 */
1973
pan_warning_ok_cb(GenericDialog * gd,gpointer data)1974 static void pan_warning_ok_cb(GenericDialog *gd, gpointer data)
1975 {
1976 FileData *dir_fd = data;
1977
1978 generic_dialog_close(gd);
1979
1980 pan_window_new_real(dir_fd);
1981 file_data_unref(dir_fd);
1982 }
1983
pan_warning_hide_cb(GtkWidget * button,gpointer data)1984 static void pan_warning_hide_cb(GtkWidget *button, gpointer data)
1985 {
1986 gboolean hide_dlg;
1987
1988 hide_dlg = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button));
1989 pref_list_int_set(PAN_PREF_GROUP, PAN_PREF_HIDE_WARNING, hide_dlg);
1990 }
1991
pan_warning(FileData * dir_fd)1992 static gboolean pan_warning(FileData *dir_fd)
1993 {
1994 GenericDialog *gd;
1995 GtkWidget *box;
1996 GtkWidget *group;
1997 GtkWidget *button;
1998 GtkWidget *ct_button;
1999 gboolean hide_dlg;
2000
2001 if (dir_fd && strcmp(dir_fd->path, G_DIR_SEPARATOR_S) == 0)
2002 {
2003 pan_warning_folder(dir_fd->path, NULL);
2004 return TRUE;
2005 }
2006
2007 if (options->thumbnails.enable_caching &&
2008 options->thumbnails.spec_standard) return FALSE;
2009
2010 if (!pref_list_int_get(PAN_PREF_GROUP, PAN_PREF_HIDE_WARNING, &hide_dlg)) hide_dlg = FALSE;
2011 if (hide_dlg) return FALSE;
2012
2013 gd = generic_dialog_new(_("Pan View Performance"), "pan_view_warning", NULL, FALSE,
2014 NULL, NULL);
2015 gd->data = file_data_ref(dir_fd);
2016 generic_dialog_add_button(gd, GTK_STOCK_OK, NULL,
2017 pan_warning_ok_cb, TRUE);
2018
2019 box = generic_dialog_add_message(gd, GTK_STOCK_DIALOG_INFO,
2020 _("Pan view performance may be poor."),
2021 _("To improve the performance of thumbnails in\npan view the following options can be enabled.\n\nNote that both options must be enabled to\nnotice a change in performance."), TRUE);
2022
2023 group = pref_box_new(box, FALSE, GTK_ORIENTATION_HORIZONTAL, 0);
2024 pref_spacer(group, PREF_PAD_INDENT);
2025 group = pref_box_new(group, TRUE, GTK_ORIENTATION_VERTICAL, PREF_PAD_GAP);
2026
2027 ct_button = pref_checkbox_new_int(group, _("Cache thumbnails"),
2028 options->thumbnails.enable_caching, &options->thumbnails.enable_caching);
2029 button = pref_checkbox_new_int(group, _("Use shared thumbnail cache"),
2030 options->thumbnails.spec_standard, &options->thumbnails.spec_standard);
2031 pref_checkbox_link_sensitivity(ct_button, button);
2032
2033 pref_line(box, 0);
2034
2035 pref_checkbox_new(box, _("Do not show this dialog again"), hide_dlg,
2036 G_CALLBACK(pan_warning_hide_cb), NULL);
2037
2038 gtk_widget_show(gd->dialog);
2039
2040 return TRUE;
2041 }
2042
2043
2044 /*
2045 *-----------------------------------------------------------------------------
2046 * entry point
2047 *-----------------------------------------------------------------------------
2048 */
2049
pan_window_new(FileData * dir_fd)2050 void pan_window_new(FileData *dir_fd)
2051 {
2052 if (pan_warning(dir_fd)) return;
2053
2054 pan_window_new_real(dir_fd);
2055 }
2056
2057
2058 /*
2059 *-----------------------------------------------------------------------------
2060 * menus
2061 *-----------------------------------------------------------------------------
2062 */
2063
2064 #define INFO_IMAGE_SIZE_KEY "image_size_data"
2065
2066
pan_new_window_cb(GtkWidget * widget,gpointer data)2067 static void pan_new_window_cb(GtkWidget *widget, gpointer data)
2068 {
2069 PanWindow *pw = data;
2070 FileData *fd;
2071
2072 fd = pan_menu_click_fd(pw);
2073 if (fd)
2074 {
2075 pan_fullscreen_toggle(pw, TRUE);
2076 view_window_new(fd);
2077 }
2078 }
2079
pan_go_to_original_cb(GtkWidget * widget,gpointer data)2080 static void pan_go_to_original_cb(GtkWidget *widget, gpointer data)
2081 {
2082 LayoutWindow *lw = NULL;
2083 PanWindow *pw = data;
2084 FileData *fd;
2085
2086 if (!layout_valid(&lw)) return;
2087
2088 fd = pan_menu_click_fd(pw);
2089 if (fd)
2090 {
2091 layout_set_fd(lw, fd);
2092 }
2093 }
2094
pan_edit_cb(GtkWidget * widget,gpointer data)2095 static void pan_edit_cb(GtkWidget *widget, gpointer data)
2096 {
2097 PanWindow *pw;
2098 FileData *fd;
2099 const gchar *key = data;
2100
2101 pw = submenu_item_get_data(widget);
2102 if (!pw) return;
2103
2104 fd = pan_menu_click_fd(pw);
2105 if (fd)
2106 {
2107 if (!editor_window_flag_set(key))
2108 {
2109 pan_fullscreen_toggle(pw, TRUE);
2110 }
2111 file_util_start_editor_from_file(key, fd, pw->imd->widget);
2112 }
2113 }
2114
pan_zoom_in_cb(GtkWidget * widget,gpointer data)2115 static void pan_zoom_in_cb(GtkWidget *widget, gpointer data)
2116 {
2117 PanWindow *pw = data;
2118
2119 image_zoom_adjust(pw->imd, ZOOM_INCREMENT);
2120 }
2121
pan_zoom_out_cb(GtkWidget * widget,gpointer data)2122 static void pan_zoom_out_cb(GtkWidget *widget, gpointer data)
2123 {
2124 PanWindow *pw = data;
2125
2126 image_zoom_adjust(pw->imd, -ZOOM_INCREMENT);
2127 }
2128
pan_zoom_1_1_cb(GtkWidget * widget,gpointer data)2129 static void pan_zoom_1_1_cb(GtkWidget *widget, gpointer data)
2130 {
2131 PanWindow *pw = data;
2132
2133 image_zoom_set(pw->imd, 1.0);
2134 }
2135
pan_copy_cb(GtkWidget * widget,gpointer data)2136 static void pan_copy_cb(GtkWidget *widget, gpointer data)
2137 {
2138 PanWindow *pw = data;
2139 FileData *fd;
2140
2141 fd = pan_menu_click_fd(pw);
2142 if (fd) file_util_copy(fd, NULL, NULL, pw->imd->widget);
2143 }
2144
pan_move_cb(GtkWidget * widget,gpointer data)2145 static void pan_move_cb(GtkWidget *widget, gpointer data)
2146 {
2147 PanWindow *pw = data;
2148 FileData *fd;
2149
2150 fd = pan_menu_click_fd(pw);
2151 if (fd) file_util_move(fd, NULL, NULL, pw->imd->widget);
2152 }
2153
pan_rename_cb(GtkWidget * widget,gpointer data)2154 static void pan_rename_cb(GtkWidget *widget, gpointer data)
2155 {
2156 PanWindow *pw = data;
2157 FileData *fd;
2158
2159 fd = pan_menu_click_fd(pw);
2160 if (fd) file_util_rename(fd, NULL, pw->imd->widget);
2161 }
2162
pan_delete_cb(GtkWidget * widget,gpointer data)2163 static void pan_delete_cb(GtkWidget *widget, gpointer data)
2164 {
2165 PanWindow *pw = data;
2166 FileData *fd;
2167
2168 fd = pan_menu_click_fd(pw);
2169 if (fd)
2170 {
2171 options->file_ops.safe_delete_enable = FALSE;
2172 file_util_delete(fd, NULL, pw->imd->widget);
2173 }
2174 }
2175
pan_move_to_trash_cb(GtkWidget * widget,gpointer data)2176 static void pan_move_to_trash_cb(GtkWidget *widget, gpointer data)
2177 {
2178 PanWindow *pw = data;
2179 FileData *fd;
2180
2181 fd = pan_menu_click_fd(pw);
2182 if (fd)
2183 {
2184 options->file_ops.safe_delete_enable = TRUE;
2185 file_util_delete(fd, NULL, pw->imd->widget);
2186 }
2187 }
2188
pan_copy_path_cb(GtkWidget * widget,gpointer data)2189 static void pan_copy_path_cb(GtkWidget *widget, gpointer data)
2190 {
2191 PanWindow *pw = data;
2192 FileData *fd;
2193
2194 fd = pan_menu_click_fd(pw);
2195 if (fd) file_util_copy_path_to_clipboard(fd, TRUE);
2196 }
2197
pan_copy_path_unquoted_cb(GtkWidget * widget,gpointer data)2198 static void pan_copy_path_unquoted_cb(GtkWidget *widget, gpointer data)
2199 {
2200 PanWindow *pw = data;
2201 FileData *fd;
2202
2203 fd = pan_menu_click_fd(pw);
2204 if (fd) file_util_copy_path_to_clipboard(fd, FALSE);
2205 }
2206
pan_exif_date_toggle_cb(GtkWidget * widget,gpointer data)2207 static void pan_exif_date_toggle_cb(GtkWidget *widget, gpointer data)
2208 {
2209 PanWindow *pw = data;
2210
2211 pw->exif_date_enable = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget));
2212 pan_layout_update(pw);
2213 }
2214
pan_info_toggle_exif_cb(GtkWidget * widget,gpointer data)2215 static void pan_info_toggle_exif_cb(GtkWidget *widget, gpointer data)
2216 {
2217 PanWindow *pw = data;
2218
2219 pw->info_includes_exif = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget));
2220 /* fixme: sync info now */
2221 }
2222
pan_info_toggle_image_cb(GtkWidget * widget,gpointer data)2223 static void pan_info_toggle_image_cb(GtkWidget *widget, gpointer data)
2224 {
2225 PanWindow *pw = data;
2226
2227 pw->info_image_size = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), INFO_IMAGE_SIZE_KEY));
2228 /* fixme: sync info now */
2229 }
2230
pan_fullscreen_cb(GtkWidget * widget,gpointer data)2231 static void pan_fullscreen_cb(GtkWidget *widget, gpointer data)
2232 {
2233 PanWindow *pw = data;
2234
2235 pan_fullscreen_toggle(pw, FALSE);
2236 }
2237
pan_close_cb(GtkWidget * widget,gpointer data)2238 static void pan_close_cb(GtkWidget *widget, gpointer data)
2239 {
2240 PanWindow *pw = data;
2241
2242 pan_window_close(pw);
2243 }
2244
pan_popup_menu_destroy_cb(GtkWidget * widget,gpointer data)2245 static void pan_popup_menu_destroy_cb(GtkWidget *widget, gpointer data)
2246 {
2247 GList *editmenu_fd_list = data;
2248
2249 filelist_free(editmenu_fd_list);
2250 }
2251
pan_play_cb(GtkWidget * widget,gpointer data)2252 static void pan_play_cb(GtkWidget *widget, gpointer data)
2253 {
2254 PanWindow *pw = data;
2255
2256 start_editor_from_file(options->image_l_click_video_editor, pw->click_pi->fd);
2257 }
2258
pan_view_get_fd_list(PanWindow * pw)2259 static GList *pan_view_get_fd_list(PanWindow *pw)
2260 {
2261 GList *list = NULL;
2262 FileData *fd = pan_menu_click_fd(pw);
2263
2264 if (fd) list = g_list_prepend(filelist_copy(fd->sidecar_files), file_data_ref(fd));
2265
2266 return list;
2267 }
2268
2269 /**
2270 * @brief Add file selection list to a collection
2271 * @param[in] widget
2272 * @param[in] data Index to the collection list menu item selected, or -1 for new collection
2273 *
2274 *
2275 */
pan_pop_menu_collections_cb(GtkWidget * widget,gpointer data)2276 static void pan_pop_menu_collections_cb(GtkWidget *widget, gpointer data)
2277 {
2278 PanWindow *pw;
2279 GList *selection_list = NULL;
2280
2281 pw = submenu_item_get_data(widget);
2282 selection_list = g_list_append(selection_list, pan_menu_click_fd(pw));
2283 pop_menu_collections(selection_list, data);
2284
2285 filelist_free(selection_list);
2286 }
2287
pan_popup_menu(PanWindow * pw)2288 static GtkWidget *pan_popup_menu(PanWindow *pw)
2289 {
2290 GtkWidget *menu;
2291 GtkWidget *submenu;
2292 GtkWidget *item;
2293 gboolean active, video;
2294 GList *editmenu_fd_list;
2295
2296 active = (pw->click_pi != NULL);
2297 video = (active && pw->click_pi->fd && pw->click_pi->fd->format_class == FORMAT_CLASS_VIDEO);
2298
2299 menu = popup_menu_short_lived();
2300
2301 menu_item_add_stock_sensitive(menu, _("_Play"), GTK_STOCK_MEDIA_PLAY, video,
2302 G_CALLBACK(pan_play_cb), pw);
2303 menu_item_add_divider(menu);
2304
2305 menu_item_add_stock(menu, _("Zoom _in"), GTK_STOCK_ZOOM_IN,
2306 G_CALLBACK(pan_zoom_in_cb), pw);
2307 menu_item_add_stock(menu, _("Zoom _out"), GTK_STOCK_ZOOM_OUT,
2308 G_CALLBACK(pan_zoom_out_cb), pw);
2309 menu_item_add_stock(menu, _("Zoom _1:1"), GTK_STOCK_ZOOM_100,
2310 G_CALLBACK(pan_zoom_1_1_cb), pw);
2311 menu_item_add_divider(menu);
2312
2313 editmenu_fd_list = pan_view_get_fd_list(pw);
2314 g_signal_connect(G_OBJECT(menu), "destroy",
2315 G_CALLBACK(pan_popup_menu_destroy_cb), editmenu_fd_list);
2316
2317 submenu_add_edit(menu, &item, G_CALLBACK(pan_edit_cb), pw, editmenu_fd_list);
2318 gtk_widget_set_sensitive(item, active);
2319
2320 menu_item_add_stock_sensitive(menu, _("View in _new window"), GTK_STOCK_NEW, active,
2321 G_CALLBACK(pan_new_window_cb), pw);
2322 menu_item_add_stock(menu, _("Go to original"), GTK_STOCK_FIND,
2323 G_CALLBACK(pan_go_to_original_cb), pw);
2324
2325 menu_item_add_divider(menu);
2326 menu_item_add_stock_sensitive(menu, _("_Copy..."), GTK_STOCK_COPY, active,
2327 G_CALLBACK(pan_copy_cb), pw);
2328 menu_item_add_sensitive(menu, _("_Move..."), active,
2329 G_CALLBACK(pan_move_cb), pw);
2330 menu_item_add_sensitive(menu, _("_Rename..."), active,
2331 G_CALLBACK(pan_rename_cb), pw);
2332 menu_item_add_sensitive(menu, _("_Copy path"), active,
2333 G_CALLBACK(pan_copy_path_cb), pw);
2334 menu_item_add_sensitive(menu, _("_Copy path unquoted"), active,
2335 G_CALLBACK(pan_copy_path_unquoted_cb), pw);
2336
2337 menu_item_add_divider(menu);
2338 menu_item_add_stock_sensitive(menu,
2339 options->file_ops.confirm_move_to_trash ? _("Move to Trash...") :
2340 _("Move to Trash"), PIXBUF_INLINE_ICON_TRASH, active,
2341 G_CALLBACK(pan_move_to_trash_cb), pw);
2342 menu_item_add_stock_sensitive(menu,
2343 options->file_ops.confirm_delete ? _("_Delete...") :
2344 _("_Delete"), GTK_STOCK_DELETE, active,
2345 G_CALLBACK(pan_delete_cb), pw);
2346
2347 menu_item_add_divider(menu);
2348
2349 submenu = submenu_add_collections(menu, &item,
2350 G_CALLBACK(pan_pop_menu_collections_cb), pw);
2351 gtk_widget_set_sensitive(item, TRUE);
2352 menu_item_add_divider(menu);
2353
2354
2355 item = menu_item_add_check(menu, _("Sort by E_xif date"), pw->exif_date_enable,
2356 G_CALLBACK(pan_exif_date_toggle_cb), pw);
2357 gtk_widget_set_sensitive(item, (pw->layout == PAN_LAYOUT_TIMELINE || pw->layout == PAN_LAYOUT_CALENDAR));
2358
2359 menu_item_add_divider(menu);
2360
2361 menu_item_add_check(menu, _("_Show Exif information"), pw->info_includes_exif,
2362 G_CALLBACK(pan_info_toggle_exif_cb), pw);
2363 item = menu_item_add(menu, _("Show im_age"), NULL, NULL);
2364 submenu = gtk_menu_new();
2365 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
2366
2367 item = menu_item_add_check(submenu, _("_None"), (pw->info_image_size == PAN_IMAGE_SIZE_THUMB_NONE),
2368 G_CALLBACK(pan_info_toggle_image_cb), pw);
2369 g_object_set_data(G_OBJECT(item), INFO_IMAGE_SIZE_KEY, GINT_TO_POINTER(PAN_IMAGE_SIZE_THUMB_NONE));
2370
2371 item = menu_item_add_check(submenu, _("_Full size"), (pw->info_image_size == PAN_IMAGE_SIZE_100),
2372 G_CALLBACK(pan_info_toggle_image_cb), pw);
2373 g_object_set_data(G_OBJECT(item), INFO_IMAGE_SIZE_KEY, GINT_TO_POINTER(PAN_IMAGE_SIZE_100));
2374
2375 item = menu_item_add_check(submenu, _("1:2 (50%)"), (pw->info_image_size == PAN_IMAGE_SIZE_50),
2376 G_CALLBACK(pan_info_toggle_image_cb), pw);
2377 g_object_set_data(G_OBJECT(item), INFO_IMAGE_SIZE_KEY, GINT_TO_POINTER(PAN_IMAGE_SIZE_50));
2378
2379 item = menu_item_add_check(submenu, _("1:3 (33%)"), (pw->info_image_size == PAN_IMAGE_SIZE_33),
2380 G_CALLBACK(pan_info_toggle_image_cb), pw);
2381 g_object_set_data(G_OBJECT(item), INFO_IMAGE_SIZE_KEY, GINT_TO_POINTER(PAN_IMAGE_SIZE_33));
2382
2383 item = menu_item_add_check(submenu, _("1:4 (25%)"), (pw->info_image_size == PAN_IMAGE_SIZE_25),
2384 G_CALLBACK(pan_info_toggle_image_cb), pw);
2385 g_object_set_data(G_OBJECT(item), INFO_IMAGE_SIZE_KEY, GINT_TO_POINTER(PAN_IMAGE_SIZE_25));
2386
2387 item = menu_item_add_check(submenu, _("1:10 (10%)"), (pw->info_image_size == PAN_IMAGE_SIZE_10),
2388 G_CALLBACK(pan_info_toggle_image_cb), pw);
2389 g_object_set_data(G_OBJECT(item), INFO_IMAGE_SIZE_KEY, GINT_TO_POINTER(PAN_IMAGE_SIZE_10));
2390
2391
2392
2393 menu_item_add_divider(menu);
2394
2395 if (pw->fs)
2396 {
2397 menu_item_add(menu, _("Exit _full screen"), G_CALLBACK(pan_fullscreen_cb), pw);
2398 }
2399 else
2400 {
2401 menu_item_add(menu, _("_Full screen"), G_CALLBACK(pan_fullscreen_cb), pw);
2402 }
2403
2404 menu_item_add_divider(menu);
2405 menu_item_add_stock(menu, _("C_lose window"), GTK_STOCK_CLOSE, G_CALLBACK(pan_close_cb), pw);
2406
2407 return menu;
2408 }
2409
2410
2411 /*
2412 *-----------------------------------------------------------------------------
2413 * drag and drop
2414 *-----------------------------------------------------------------------------
2415 */
2416
pan_window_get_dnd_data(GtkWidget * widget,GdkDragContext * context,gint x,gint y,GtkSelectionData * selection_data,guint info,guint time,gpointer data)2417 static void pan_window_get_dnd_data(GtkWidget *widget, GdkDragContext *context,
2418 gint x, gint y,
2419 GtkSelectionData *selection_data, guint info,
2420 guint time, gpointer data)
2421 {
2422 PanWindow *pw = data;
2423
2424 if (gtk_drag_get_source_widget(context) == pw->imd->pr) return;
2425
2426 if (info == TARGET_URI_LIST)
2427 {
2428 GList *list;
2429
2430 list = uri_filelist_from_gtk_selection_data(selection_data);
2431 if (list && isdir(((FileData *)list->data)->path))
2432 {
2433 FileData *fd = list->data;
2434
2435 pan_layout_set_fd(pw, fd);
2436 }
2437
2438 filelist_free(list);
2439 }
2440 }
2441
pan_window_set_dnd_data(GtkWidget * widget,GdkDragContext * context,GtkSelectionData * selection_data,guint info,guint time,gpointer data)2442 static void pan_window_set_dnd_data(GtkWidget *widget, GdkDragContext *context,
2443 GtkSelectionData *selection_data, guint info,
2444 guint time, gpointer data)
2445 {
2446 PanWindow *pw = data;
2447 FileData *fd;
2448
2449 fd = pan_menu_click_fd(pw);
2450 if (fd)
2451 {
2452 GList *list;
2453
2454 list = g_list_append(NULL, fd);
2455 uri_selection_data_set_uris_from_filelist(selection_data, list);
2456 g_list_free(list);
2457 }
2458 else
2459 {
2460 gtk_selection_data_set(selection_data, gtk_selection_data_get_target(selection_data),
2461 8, NULL, 0);
2462 }
2463 }
2464
pan_window_dnd_init(PanWindow * pw)2465 static void pan_window_dnd_init(PanWindow *pw)
2466 {
2467 GtkWidget *widget;
2468
2469 widget = pw->imd->pr;
2470
2471 gtk_drag_source_set(widget, GDK_BUTTON2_MASK,
2472 dnd_file_drag_types, dnd_file_drag_types_count,
2473 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK);
2474 g_signal_connect(G_OBJECT(widget), "drag_data_get",
2475 G_CALLBACK(pan_window_set_dnd_data), pw);
2476
2477 gtk_drag_dest_set(widget,
2478 GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP,
2479 dnd_file_drop_types, dnd_file_drop_types_count,
2480 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK);
2481 g_signal_connect(G_OBJECT(widget), "drag_data_received",
2482 G_CALLBACK(pan_window_get_dnd_data), pw);
2483 }
2484
2485 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
2486