2 * Copyright (C) 2006 John Ellis
3 * Copyright (C) 2008 - 2016 The Geeqie Team
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.
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.
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.
26 #include "collect-io.h"
30 #include "fullscreen.h"
32 #include "image-load.h"
33 #include "image-overlay.h"
35 #include "layout_image.h"
36 #include "layout_util.h"
39 #include "pixbuf_util.h"
40 #include "pixbuf-renderer.h"
42 #include "slideshow.h"
43 #include "ui_fileops.h"
45 #include "uri_utils.h"
49 #include <gdk/gdkkeysyms.h> /* for keyboard values */
52 typedef struct _ViewWindow ViewWindow;
65 static GList *view_window_list = NULL;
68 static GtkWidget *view_popup_menu(ViewWindow *vw);
69 static void view_fullscreen_toggle(ViewWindow *vw, gboolean force_off);
70 static void view_overlay_toggle(ViewWindow *vw);
72 static void view_slideshow_next(ViewWindow *vw);
73 static void view_slideshow_prev(ViewWindow *vw);
74 static void view_slideshow_start(ViewWindow *vw);
75 static void view_slideshow_stop(ViewWindow *vw);
77 static void view_window_close(ViewWindow *vw);
79 static void view_window_dnd_init(ViewWindow *vw);
81 static void view_window_notify_cb(FileData *fd, NotifyType type, gpointer data);
84 *-----------------------------------------------------------------------------
86 *-----------------------------------------------------------------------------
89 static ImageWindow *view_window_active_image(ViewWindow *vw)
91 if (vw->fs) return vw->fs->imd;
96 static void view_window_set_list(ViewWindow *vw, GList *list)
99 filelist_free(vw->list);
101 vw->list_pointer = NULL;
103 vw->list = filelist_copy(list);
106 static gboolean view_window_contains_collection(ViewWindow *vw)
111 cd = image_get_collection(view_window_active_image(vw), &info);
116 static void view_collection_step(ViewWindow *vw, gboolean next)
118 ImageWindow *imd = view_window_active_image(vw);
121 CollectInfo *read_ahead_info = NULL;
123 cd = image_get_collection(imd, &info);
125 if (!cd || !info) return;
129 info = collection_next_by_info(cd, info);
130 if (options->image.enable_read_ahead)
132 read_ahead_info = collection_next_by_info(cd, info);
133 if (!read_ahead_info) read_ahead_info = collection_prev_by_info(cd, info);
138 info = collection_prev_by_info(cd, info);
139 if (options->image.enable_read_ahead)
141 read_ahead_info = collection_prev_by_info(cd, info);
142 if (!read_ahead_info) read_ahead_info = collection_next_by_info(cd, info);
148 image_change_from_collection(imd, cd, info, image_zoom_get_default(imd));
150 if (read_ahead_info) image_prebuffer_set(imd, read_ahead_info->fd);
155 static void view_collection_step_to_end(ViewWindow *vw, gboolean last)
157 ImageWindow *imd = view_window_active_image(vw);
160 CollectInfo *read_ahead_info = NULL;
162 cd = image_get_collection(imd, &info);
164 if (!cd || !info) return;
168 info = collection_get_last(cd);
169 if (options->image.enable_read_ahead) read_ahead_info = collection_prev_by_info(cd, info);
173 info = collection_get_first(cd);
174 if (options->image.enable_read_ahead) read_ahead_info = collection_next_by_info(cd, info);
179 image_change_from_collection(imd, cd, info, image_zoom_get_default(imd));
180 if (read_ahead_info) image_prebuffer_set(imd, read_ahead_info->fd);
184 static void view_list_step(ViewWindow *vw, gboolean next)
186 ImageWindow *imd = view_window_active_image(vw);
191 if (!vw->list) return;
193 fd = image_get_fd(imd);
196 if (g_list_position(vw->list, vw->list_pointer) >= 0)
198 work = vw->list_pointer;
202 gboolean found = FALSE;
205 while (work && !found)
227 if (work) work_ahead = work->next;
232 if (work) work_ahead = work->prev;
237 vw->list_pointer = work;
239 image_change_fd(imd, fd, image_zoom_get_default(imd));
241 if (options->image.enable_read_ahead && work_ahead)
243 FileData *next_fd = work_ahead->data;
244 image_prebuffer_set(imd, next_fd);
248 static void view_list_step_to_end(ViewWindow *vw, gboolean last)
250 ImageWindow *imd = view_window_active_image(vw);
255 if (!vw->list) return;
259 work = g_list_last(vw->list);
260 work_ahead = work->prev;
265 work_ahead = work->next;
268 vw->list_pointer = work;
270 image_change_fd(imd, fd, image_zoom_get_default(imd));
272 if (options->image.enable_read_ahead && work_ahead)
274 FileData *next_fd = work_ahead->data;
275 image_prebuffer_set(imd, next_fd);
279 static void view_step_next(ViewWindow *vw)
283 view_slideshow_next(vw);
287 view_list_step(vw, TRUE);
291 view_collection_step(vw, TRUE);
295 static void view_step_prev(ViewWindow *vw)
299 view_slideshow_prev(vw);
303 view_list_step(vw, FALSE);
307 view_collection_step(vw, FALSE);
311 static void view_step_to_end(ViewWindow *vw, gboolean last)
315 view_list_step_to_end(vw, last);
319 view_collection_step_to_end(vw, last);
324 *-----------------------------------------------------------------------------
325 * view window keyboard
326 *-----------------------------------------------------------------------------
329 static void view_window_menu_pos_cb(GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer data)
331 ViewWindow *vw = data;
334 imd = view_window_active_image(vw);
335 gdk_window_get_origin(gtk_widget_get_window(imd->pr), x, y);
336 popup_menu_position_clamp(menu, x, y, 0);
339 static gboolean view_window_key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
341 ViewWindow *vw = data;
348 imd = view_window_active_image(vw);
351 switch (event->keyval)
353 case GDK_KEY_Left: case GDK_KEY_KP_Left:
356 case GDK_KEY_Right: case GDK_KEY_KP_Right:
359 case GDK_KEY_Up: case GDK_KEY_KP_Up:
362 case GDK_KEY_Down: case GDK_KEY_KP_Down:
372 if (event->state & GDK_SHIFT_MASK)
378 keyboard_scroll_calc(&x, &y, event);
379 image_scroll(imd, x, y);
382 if (stop_signal) return stop_signal;
384 if (event->state & GDK_CONTROL_MASK)
387 switch (event->keyval)
401 file_util_copy(image_get_fd(imd), NULL, NULL, imd->widget);
404 file_util_move(image_get_fd(imd), NULL, NULL, imd->widget);
407 file_util_rename(image_get_fd(imd), NULL, imd->widget);
410 options->file_ops.safe_delete_enable = TRUE;
411 file_util_delete(image_get_fd(imd), NULL, imd->widget);
414 view_window_close(vw);
421 else if (event->state & GDK_SHIFT_MASK)
424 switch (event->keyval)
427 image_alter_orientation(imd, imd->image_fd, ALTER_ROTATE_180);
430 image_alter_orientation(imd, imd->image_fd, ALTER_MIRROR);
433 image_alter_orientation(imd, imd->image_fd, ALTER_FLIP);
436 image_set_desaturate(imd, !image_get_desaturate(imd));
442 view_fullscreen_toggle(vw, TRUE);
443 imd = view_window_active_image(vw);
444 fd = image_get_fd(imd);
446 fd ? g_list_append(NULL, file_data_ref(fd)) : NULL,
447 filelist_copy(vw->list), vw->window);
450 case GDK_KEY_Delete: case GDK_KEY_KP_Delete:
451 if (options->file_ops.enable_delete_key)
453 options->file_ops.safe_delete_enable = FALSE;
454 file_util_delete(image_get_fd(imd), NULL, imd->widget);
465 switch (event->keyval)
467 case GDK_KEY_Page_Up: case GDK_KEY_KP_Page_Up:
468 case GDK_KEY_BackSpace:
472 case GDK_KEY_Page_Down: case GDK_KEY_KP_Page_Down:
477 case GDK_KEY_Home: case GDK_KEY_KP_Home:
478 view_step_to_end(vw, FALSE);
480 case GDK_KEY_End: case GDK_KEY_KP_End:
481 view_step_to_end(vw, TRUE);
483 case '+': case '=': case GDK_KEY_KP_Add:
484 image_zoom_adjust(imd, get_zoom_increment());
486 case '-': case GDK_KEY_KP_Subtract:
487 image_zoom_adjust(imd, -get_zoom_increment());
489 case 'X': case 'x': case GDK_KEY_KP_Multiply:
490 image_zoom_set(imd, 0.0);
492 case 'Z': case 'z': case GDK_KEY_KP_Divide: case '1':
493 image_zoom_set(imd, 1.0);
496 image_zoom_set(imd, 2.0);
499 image_zoom_set(imd, 3.0);
502 image_zoom_set(imd, 4.0);
505 image_zoom_set(imd, -4.0);
508 image_zoom_set(imd, -3.0);
511 image_zoom_set(imd, -2.0);
514 image_zoom_set_fill_geometry(imd, FALSE);
517 image_zoom_set_fill_geometry(imd, TRUE);
525 view_slideshow_stop(vw);
529 view_slideshow_start(vw);
533 slideshow_pause_toggle(vw->ss);
538 view_fullscreen_toggle(vw, FALSE);
541 view_overlay_toggle(vw);
544 image_alter_orientation(imd, imd->image_fd, ALTER_ROTATE_90);
547 image_alter_orientation(imd, imd->image_fd, ALTER_ROTATE_90_CC);
549 case GDK_KEY_Delete: case GDK_KEY_KP_Delete:
550 if (options->file_ops.enable_delete_key)
552 options->file_ops.safe_delete_enable = TRUE;
553 file_util_delete(image_get_fd(imd), NULL, imd->widget);
559 view_fullscreen_toggle(vw, TRUE);
563 view_window_close(vw);
568 menu = view_popup_menu(vw);
569 gtk_menu_popup(GTK_MENU(menu), NULL, NULL,
570 view_window_menu_pos_cb, vw, 0, GDK_CURRENT_TIME);
577 if (!stop_signal && is_help_key(event))
579 help_window_show("GuideOtherWindowsImageWindow.html");
587 *-----------------------------------------------------------------------------
588 * view window main routines
589 *-----------------------------------------------------------------------------
591 static void button_cb(ImageWindow *imd, GdkEventButton *event, gpointer data)
593 ViewWindow *vw = data;
596 LayoutWindow *lw_new;
598 switch (event->button)
600 case MOUSE_BUTTON_LEFT:
601 if (options->image_l_click_archive && imd->image_fd->format_class == FORMAT_CLASS_ARCHIVE)
603 dest_dir = open_archive(imd->image_fd);
606 lw_new = layout_new_from_default();
607 layout_set_path(lw_new, dest_dir);
612 warning_dialog(_("Cannot open archive file"), _("See the Log Window"), GTK_STOCK_DIALOG_WARNING, NULL);
615 else if (options->image_l_click_video && options->image_l_click_video_editor && imd->image_fd->format_class == FORMAT_CLASS_VIDEO)
617 start_editor_from_file(options->image_l_click_video_editor, imd->image_fd);
619 else if (options->image_lm_click_nav)
622 case MOUSE_BUTTON_MIDDLE:
623 if (options->image_lm_click_nav)
626 case MOUSE_BUTTON_RIGHT:
627 menu = view_popup_menu(vw);
628 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 3, event->time);
635 static void scroll_cb(ImageWindow *imd, GdkEventScroll *event, gpointer data)
637 ViewWindow *vw = data;
639 if ((event->state & GDK_CONTROL_MASK) ||
640 (imd->mouse_wheel_mode && !options->image_lm_click_nav))
642 switch (event->direction)
645 image_zoom_adjust_at_point(imd, get_zoom_increment(), event->x, event->y);
647 case GDK_SCROLL_DOWN:
648 image_zoom_adjust_at_point(imd, -get_zoom_increment(), event->x, event->y);
654 else if ( (event->state & GDK_SHIFT_MASK) != (guint) (options->mousewheel_scrolls))
656 switch (event->direction)
659 image_scroll(imd, 0, -MOUSEWHEEL_SCROLL_SIZE);
661 case GDK_SCROLL_DOWN:
662 image_scroll(imd, 0, MOUSEWHEEL_SCROLL_SIZE);
664 case GDK_SCROLL_LEFT:
665 image_scroll(imd, -MOUSEWHEEL_SCROLL_SIZE, 0);
667 case GDK_SCROLL_RIGHT:
668 image_scroll(imd, MOUSEWHEEL_SCROLL_SIZE, 0);
676 switch (event->direction)
681 case GDK_SCROLL_DOWN:
690 static void view_image_set_buttons(ViewWindow *vw, ImageWindow *imd)
692 image_set_button_func(imd, button_cb, vw);
693 image_set_scroll_func(imd, scroll_cb, vw);
696 static void view_fullscreen_stop_func(FullScreenData *fs, gpointer data)
698 ViewWindow *vw = data;
702 if (vw->ss) vw->ss->imd = vw->imd;
705 static void view_fullscreen_toggle(ViewWindow *vw, gboolean force_off)
707 if (force_off && !vw->fs) return;
711 if (image_osd_get(vw->imd) & OSD_SHOW_INFO)
712 image_osd_set(vw->imd, image_osd_get(vw->fs->imd));
714 fullscreen_stop(vw->fs);
718 vw->fs = fullscreen_start(vw->window, vw->imd, view_fullscreen_stop_func, vw);
720 view_image_set_buttons(vw, vw->fs->imd);
721 g_signal_connect(G_OBJECT(vw->fs->window), "key_press_event",
722 G_CALLBACK(view_window_key_press_cb), vw);
724 if (vw->ss) vw->ss->imd = vw->fs->imd;
726 if (image_osd_get(vw->imd) & OSD_SHOW_INFO)
728 image_osd_set(vw->fs->imd, image_osd_get(vw->imd));
729 image_osd_set(vw->imd, OSD_SHOW_NOTHING);
734 static void view_overlay_toggle(ViewWindow *vw)
738 imd = view_window_active_image(vw);
740 image_osd_toggle(imd);
743 static void view_slideshow_next(ViewWindow *vw)
745 if (vw->ss) slideshow_next(vw->ss);
748 static void view_slideshow_prev(ViewWindow *vw)
750 if (vw->ss) slideshow_prev(vw->ss);
753 static void view_slideshow_stop_func(SlideShowData *fs, gpointer data)
755 ViewWindow *vw = data;
762 fd = image_get_fd(view_window_active_image(vw));
770 vw->list_pointer = work;
780 static void view_slideshow_start(ViewWindow *vw)
789 vw->ss = slideshow_start_from_filelist(NULL, view_window_active_image(vw),
790 filelist_copy(vw->list),
791 view_slideshow_stop_func, vw);
792 vw->list_pointer = NULL;
796 cd = image_get_collection(view_window_active_image(vw), &info);
799 vw->ss = slideshow_start_from_collection(NULL, view_window_active_image(vw), cd,
800 view_slideshow_stop_func, vw, info);
805 static void view_slideshow_stop(ViewWindow *vw)
807 if (vw->ss) slideshow_free(vw->ss);
810 static void view_window_destroy_cb(GtkWidget *widget, gpointer data)
812 ViewWindow *vw = data;
814 view_window_list = g_list_remove(view_window_list, vw);
816 view_slideshow_stop(vw);
817 fullscreen_stop(vw->fs);
819 filelist_free(vw->list);
821 file_data_unregister_notify_func(view_window_notify_cb, vw);
826 static void view_window_close(ViewWindow *vw)
828 view_slideshow_stop(vw);
829 view_fullscreen_toggle(vw, TRUE);
830 gtk_widget_destroy(vw->window);
833 static gboolean view_window_delete_cb(GtkWidget *w, GdkEventAny *event, gpointer data)
835 ViewWindow *vw = data;
837 view_window_close(vw);
841 static ViewWindow *real_view_window_new(FileData *fd, GList *list, CollectionData *cd, CollectInfo *info)
844 GtkAllocation req_size;
845 GdkGeometry geometry;
848 if (!fd && !list && (!cd || !info)) return NULL;
850 vw = g_new0(ViewWindow, 1);
852 vw->window = window_new(GTK_WINDOW_TOPLEVEL, "view", PIXBUF_INLINE_ICON_VIEW, NULL, NULL);
853 DEBUG_NAME(vw->window);
855 geometry.min_width = DEFAULT_MINIMAL_WINDOW_SIZE;
856 geometry.min_height = DEFAULT_MINIMAL_WINDOW_SIZE;
857 gtk_window_set_geometry_hints(GTK_WINDOW(vw->window), NULL, &geometry, GDK_HINT_MIN_SIZE);
859 gtk_window_set_resizable(GTK_WINDOW(vw->window), TRUE);
860 gtk_container_set_border_width(GTK_CONTAINER(vw->window), 0);
862 vw->imd = image_new(FALSE);
863 image_color_profile_set(vw->imd,
864 options->color_profile.input_type,
865 options->color_profile.use_image);
866 image_color_profile_set_use(vw->imd, options->color_profile.enabled);
868 image_background_set_color_from_options(vw->imd, FALSE);
870 image_attach_window(vw->imd, vw->window, NULL, GQ_APPNAME, TRUE);
872 image_auto_refresh_enable(vw->imd, TRUE);
873 image_top_window_set_sync(vw->imd, TRUE);
875 gtk_container_add(GTK_CONTAINER(vw->window), vw->imd->widget);
876 gtk_widget_show(vw->imd->widget);
878 view_window_dnd_init(vw);
880 view_image_set_buttons(vw, vw->imd);
882 g_signal_connect(G_OBJECT(vw->window), "destroy",
883 G_CALLBACK(view_window_destroy_cb), vw);
884 g_signal_connect(G_OBJECT(vw->window), "delete_event",
885 G_CALLBACK(view_window_delete_cb), vw);
886 g_signal_connect(G_OBJECT(vw->window), "key_press_event",
887 G_CALLBACK(view_window_key_press_cb), vw);
890 image_change_from_collection(vw->imd, cd, info, image_zoom_get_default(NULL));
891 /* Grab the fd so we can correctly size the window in
892 the call to image_load_dimensions() below. */
894 if (options->image.enable_read_ahead)
896 CollectInfo * r_info = collection_next_by_info(cd, info);
897 if (!r_info) r_info = collection_prev_by_info(cd, info);
898 if (r_info) image_prebuffer_set(vw->imd, r_info->fd);
903 view_window_set_list(vw, list);
904 vw->list_pointer = vw->list;
905 image_change_fd(vw->imd, (FileData *)vw->list->data, image_zoom_get_default(NULL));
906 /* Set fd to first in list */
909 if (options->image.enable_read_ahead)
911 GList *work = vw->list->next;
912 if (work) image_prebuffer_set(vw->imd, (FileData *)work->data);
917 image_change_fd(vw->imd, fd, image_zoom_get_default(NULL));
920 /* Wait until image is loaded otherwise size is not defined */
921 image_load_dimensions(fd, &w, &h);
923 if (options->image.limit_window_size)
925 gint mw = gdk_screen_width() * options->image.max_window_size / 100;
926 gint mh = gdk_screen_height() * options->image.max_window_size / 100;
932 gtk_window_set_default_size(GTK_WINDOW(vw->window), w, h);
933 req_size.x = req_size.y = 0;
936 gtk_widget_size_allocate(GTK_WIDGET(vw->window), &req_size);
938 #if !GTK_CHECK_VERSION(3,0,0)
939 gtk_widget_set_size_request(vw->imd->pr, w, h);
942 gtk_window_set_focus_on_map(GTK_WINDOW(vw->window), FALSE);
943 gtk_widget_show(vw->window);
945 view_window_list = g_list_append(view_window_list, vw);
947 file_data_register_notify_func(view_window_notify_cb, vw, NOTIFY_PRIORITY_LOW);
952 static void view_window_collection_unref_cb(GtkWidget *widget, gpointer data)
954 CollectionData *cd = data;
956 collection_unref(cd);
959 void view_window_new(FileData *fd)
965 if (file_extension_match(fd->path, GQ_COLLECTION_EXT))
971 cd = collection_new(fd->path);
972 if (collection_load(cd, fd->path, COLLECTION_LOAD_NONE))
974 info = collection_get_first(cd);
978 collection_unref(cd);
982 vw = real_view_window_new(NULL, NULL, cd, info);
985 g_signal_connect(G_OBJECT(vw->window), "destroy",
986 G_CALLBACK(view_window_collection_unref_cb), cd);
989 else if (isdir(fd->path) && filelist_read(fd, &list, NULL))
991 list = filelist_sort_path(list);
992 list = filelist_filter(list, FALSE);
993 real_view_window_new(NULL, list, NULL, NULL);
998 real_view_window_new(fd, NULL, NULL, NULL);
1003 void view_window_new_from_list(GList *list)
1005 real_view_window_new(NULL, list, NULL, NULL);
1008 void view_window_new_from_collection(CollectionData *cd, CollectInfo *info)
1010 real_view_window_new(NULL, NULL, cd, info);
1014 *-----------------------------------------------------------------------------
1016 *-----------------------------------------------------------------------------
1019 void view_window_colors_update(void)
1023 work = view_window_list;
1026 ViewWindow *vw = work->data;
1029 image_background_set_color_from_options(vw->imd, !!vw->fs);
1033 gboolean view_window_find_image(ImageWindow *imd, gint *index, gint *total)
1037 work = view_window_list;
1040 ViewWindow *vw = work->data;
1043 if (vw->imd == imd ||
1044 (vw->fs && vw->fs->imd == imd))
1051 n = g_list_length(vw->ss->list_done);
1052 t = n + g_list_length(vw->ss->list);
1054 if (index) *index = n - 1;
1055 if (total) *total = t;
1059 if (index) *index = g_list_position(vw->list, vw->list_pointer);
1060 if (total) *total = g_list_length(vw->list);
1070 *-----------------------------------------------------------------------------
1071 * view window menu routines and callbacks
1072 *-----------------------------------------------------------------------------
1075 static void view_new_window_cb(GtkWidget *widget, gpointer data)
1077 ViewWindow *vw = data;
1081 cd = image_get_collection(vw->imd, &info);
1085 view_window_new_from_collection(cd, info);
1089 view_window_new(image_get_fd(vw->imd));
1093 static void view_edit_cb(GtkWidget *widget, gpointer data)
1097 const gchar *key = data;
1099 vw = submenu_item_get_data(widget);
1102 if (!editor_window_flag_set(key))
1104 view_fullscreen_toggle(vw, TRUE);
1107 imd = view_window_active_image(vw);
1108 file_util_start_editor_from_file(key, image_get_fd(imd), imd->widget);
1111 static void view_alter_cb(GtkWidget *widget, gpointer data)
1116 vw = submenu_item_get_data(widget);
1117 type = GPOINTER_TO_INT(data);
1120 image_alter_orientation(vw->imd, vw->imd->image_fd, type);
1123 #if !GTK_CHECK_VERSION(3,0,0)
1124 static void view_wallpaper_cb(GtkWidget *widget, gpointer data)
1126 ViewWindow *vw = data;
1129 imd = view_window_active_image(vw);
1130 image_to_root_window(imd, (image_zoom_get(imd) == 0.0));
1134 static void view_zoom_in_cb(GtkWidget *widget, gpointer data)
1136 ViewWindow *vw = data;
1138 image_zoom_adjust(view_window_active_image(vw), get_zoom_increment());
1141 static void view_zoom_out_cb(GtkWidget *widget, gpointer data)
1143 ViewWindow *vw = data;
1145 image_zoom_adjust(view_window_active_image(vw), -get_zoom_increment());
1148 static void view_zoom_1_1_cb(GtkWidget *widget, gpointer data)
1150 ViewWindow *vw = data;
1152 image_zoom_set(view_window_active_image(vw), 1.0);
1155 static void view_zoom_fit_cb(GtkWidget *widget, gpointer data)
1157 ViewWindow *vw = data;
1159 image_zoom_set(view_window_active_image(vw), 0.0);
1162 static void view_copy_cb(GtkWidget *widget, gpointer data)
1164 ViewWindow *vw = data;
1167 imd = view_window_active_image(vw);
1168 file_util_copy(image_get_fd(imd), NULL, NULL, imd->widget);
1171 static void view_move_cb(GtkWidget *widget, gpointer data)
1173 ViewWindow *vw = data;
1176 imd = view_window_active_image(vw);
1177 file_util_move(image_get_fd(imd), NULL, NULL, imd->widget);
1180 static void view_rename_cb(GtkWidget *widget, gpointer data)
1182 ViewWindow *vw = data;
1185 imd = view_window_active_image(vw);
1186 file_util_rename(image_get_fd(imd), NULL, imd->widget);
1189 static void view_delete_cb(GtkWidget *widget, gpointer data)
1191 ViewWindow *vw = data;
1194 imd = view_window_active_image(vw);
1195 options->file_ops.safe_delete_enable = FALSE;
1196 file_util_delete(image_get_fd(imd), NULL, imd->widget);
1199 static void view_move_to_trash_cb(GtkWidget *widget, gpointer data)
1201 ViewWindow *vw = data;
1204 imd = view_window_active_image(vw);
1205 options->file_ops.safe_delete_enable = TRUE;
1206 file_util_delete(image_get_fd(imd), NULL, imd->widget);
1209 static void view_copy_path_cb(GtkWidget *widget, gpointer data)
1211 ViewWindow *vw = data;
1214 imd = view_window_active_image(vw);
1215 file_util_copy_path_to_clipboard(image_get_fd(imd), TRUE);
1218 static void view_copy_path_unquoted_cb(GtkWidget *widget, gpointer data)
1220 ViewWindow *vw = data;
1223 imd = view_window_active_image(vw);
1224 file_util_copy_path_to_clipboard(image_get_fd(imd), FALSE);
1227 static void view_fullscreen_cb(GtkWidget *widget, gpointer data)
1229 ViewWindow *vw = data;
1231 view_fullscreen_toggle(vw, FALSE);
1234 static void view_slideshow_start_cb(GtkWidget *widget, gpointer data)
1236 ViewWindow *vw = data;
1238 view_slideshow_start(vw);
1241 static void view_slideshow_stop_cb(GtkWidget *widget, gpointer data)
1243 ViewWindow *vw = data;
1245 view_slideshow_stop(vw);
1248 static void view_slideshow_pause_cb(GtkWidget *widget, gpointer data)
1250 ViewWindow *vw = data;
1252 slideshow_pause_toggle(vw->ss);
1255 static void view_close_cb(GtkWidget *widget, gpointer data)
1257 ViewWindow *vw = data;
1259 view_window_close(vw);
1262 static LayoutWindow *view_new_layout_with_fd(FileData *fd)
1266 nw = layout_new(NULL, NULL);
1267 layout_sort_set(nw, options->file_sort.method, options->file_sort.ascending);
1268 layout_set_fd(nw, fd);
1273 static void view_set_layout_path_cb(GtkWidget *widget, gpointer data)
1275 ViewWindow *vw = data;
1279 imd = view_window_active_image(vw);
1281 if (!imd || !imd->image_fd) return;
1283 lw = layout_find_by_image_fd(imd);
1285 layout_set_fd(lw, imd->image_fd);
1287 view_new_layout_with_fd(imd->image_fd);
1288 view_window_close(vw);
1291 static void view_popup_menu_destroy_cb(GtkWidget *widget, gpointer data)
1293 GList *editmenu_fd_list = data;
1295 filelist_free(editmenu_fd_list);
1298 static GList *view_window_get_fd_list(ViewWindow *vw)
1301 ImageWindow *imd = view_window_active_image(vw);
1305 FileData *fd = image_get_fd(imd);
1306 if (fd) list = g_list_append(NULL, file_data_ref(fd));
1313 * @brief Add file selection list to a collection
1315 * @param[in] data Index to the collection list menu item selected, or -1 for new collection
1319 static void image_pop_menu_collections_cb(GtkWidget *widget, gpointer data)
1324 GList *selection_list = NULL;
1326 vw = submenu_item_get_data(widget);
1327 imd = view_window_active_image(vw);
1328 fd = image_get_fd(imd);
1329 selection_list = g_list_append(selection_list, fd);
1330 pop_menu_collections(selection_list, data);
1332 filelist_free(selection_list);
1335 static GtkWidget *view_popup_menu(ViewWindow *vw)
1339 GList *editmenu_fd_list;
1341 menu = popup_menu_short_lived();
1344 menu_item_add_stock(menu, _("Zoom _in"), GTK_STOCK_ZOOM_IN, G_CALLBACK(view_zoom_in_cb), vw);
1345 menu_item_add_stock(menu, _("Zoom _out"), GTK_STOCK_ZOOM_OUT, G_CALLBACK(view_zoom_out_cb), vw);
1346 menu_item_add_stock(menu, _("Zoom _1:1"), GTK_STOCK_ZOOM_100, G_CALLBACK(view_zoom_1_1_cb), vw);
1347 menu_item_add_stock(menu, _("Fit image to _window"), GTK_STOCK_ZOOM_FIT, G_CALLBACK(view_zoom_fit_cb), vw);
1348 menu_item_add_divider(menu);
1350 editmenu_fd_list = view_window_get_fd_list(vw);
1351 g_signal_connect(G_OBJECT(menu), "destroy",
1352 G_CALLBACK(view_popup_menu_destroy_cb), editmenu_fd_list);
1353 item = submenu_add_edit(menu, NULL, G_CALLBACK(view_edit_cb), vw, editmenu_fd_list);
1354 menu_item_add_divider(item);
1355 #if !GTK_CHECK_VERSION(3,0,0)
1356 menu_item_add(item, _("Set as _wallpaper"), G_CALLBACK(view_wallpaper_cb), vw);
1358 submenu_add_alter(menu, G_CALLBACK(view_alter_cb), vw);
1360 menu_item_add_stock(menu, _("View in _new window"), GTK_STOCK_NEW, G_CALLBACK(view_new_window_cb), vw);
1361 item = menu_item_add(menu, _("_Go to directory view"), G_CALLBACK(view_set_layout_path_cb), vw);
1363 menu_item_add_divider(menu);
1364 menu_item_add_stock(menu, _("_Copy..."), GTK_STOCK_COPY, G_CALLBACK(view_copy_cb), vw);
1365 menu_item_add(menu, _("_Move..."), G_CALLBACK(view_move_cb), vw);
1366 menu_item_add(menu, _("_Rename..."), G_CALLBACK(view_rename_cb), vw);
1367 menu_item_add(menu, _("_Copy path"), G_CALLBACK(view_copy_path_cb), vw);
1368 menu_item_add(menu, _("_Copy path unquoted"), G_CALLBACK(view_copy_path_unquoted_cb), vw);
1370 menu_item_add_divider(menu);
1371 menu_item_add_stock(menu,
1372 options->file_ops.confirm_move_to_trash ? _("Move to Trash...") :
1373 _("Move to Trash"), PIXBUF_INLINE_ICON_TRASH,
1374 G_CALLBACK(view_move_to_trash_cb), vw);
1375 menu_item_add_stock(menu,
1376 options->file_ops.confirm_delete ? _("_Delete...") :
1377 _("_Delete"), GTK_STOCK_DELETE,
1378 G_CALLBACK(view_delete_cb), vw);
1380 menu_item_add_divider(menu);
1382 submenu_add_collections(menu, &item,
1383 G_CALLBACK(image_pop_menu_collections_cb), vw);
1384 gtk_widget_set_sensitive(item, TRUE);
1385 menu_item_add_divider(menu);
1389 menu_item_add(menu, _("_Stop slideshow"), G_CALLBACK(view_slideshow_stop_cb), vw);
1390 if (slideshow_paused(vw->ss))
1392 item = menu_item_add(menu, _("Continue slides_how"),
1393 G_CALLBACK(view_slideshow_pause_cb), vw);
1397 item = menu_item_add(menu, _("Pause slides_how"),
1398 G_CALLBACK(view_slideshow_pause_cb), vw);
1403 item = menu_item_add(menu, _("_Start slideshow"), G_CALLBACK(view_slideshow_start_cb), vw);
1404 gtk_widget_set_sensitive(item, (vw->list != NULL) || view_window_contains_collection(vw));
1405 item = menu_item_add(menu, _("Pause slides_how"), G_CALLBACK(view_slideshow_pause_cb), vw);
1406 gtk_widget_set_sensitive(item, FALSE);
1411 menu_item_add(menu, _("Exit _full screen"), G_CALLBACK(view_fullscreen_cb), vw);
1415 menu_item_add(menu, _("_Full screen"), G_CALLBACK(view_fullscreen_cb), vw);
1418 menu_item_add_divider(menu);
1419 menu_item_add_stock(menu, _("C_lose window"), GTK_STOCK_CLOSE, G_CALLBACK(view_close_cb), vw);
1425 *-------------------------------------------------------------------
1427 *-------------------------------------------------------------------
1435 static void view_dir_list_cancel(GtkWidget *widget, gpointer data)
1440 static void view_dir_list_do(ViewWindow *vw, GList *list, gboolean skip, gboolean recurse)
1444 view_window_set_list(vw, NULL);
1449 FileData *fd = work->data;
1452 if (isdir(fd->path))
1460 list = filelist_recursive(fd);
1464 filelist_read(fd, &list, NULL);
1465 list = filelist_sort_path(list);
1466 list = filelist_filter(list, FALSE);
1468 if (list) vw->list = g_list_concat(vw->list, list);
1473 /** @FIXME no filtering here */
1474 vw->list = g_list_append(vw->list, file_data_ref(fd));
1482 vw->list_pointer = vw->list;
1483 fd = vw->list->data;
1484 image_change_fd(vw->imd, fd, image_zoom_get_default(vw->imd));
1486 work = vw->list->next;
1487 if (options->image.enable_read_ahead && work)
1490 image_prebuffer_set(vw->imd, fd);
1495 image_change_fd(vw->imd, NULL, image_zoom_get_default(vw->imd));
1499 static void view_dir_list_add(GtkWidget *widget, gpointer data)
1501 CViewConfirmD *d = data;
1502 view_dir_list_do(d->vw, d->list, FALSE, FALSE);
1505 static void view_dir_list_recurse(GtkWidget *widget, gpointer data)
1507 CViewConfirmD *d = data;
1508 view_dir_list_do(d->vw, d->list, FALSE, TRUE);
1511 static void view_dir_list_skip(GtkWidget *widget, gpointer data)
1513 CViewConfirmD *d = data;
1514 view_dir_list_do(d->vw, d->list, TRUE, FALSE);
1517 static void view_dir_list_destroy(GtkWidget *widget, gpointer data)
1519 CViewConfirmD *d = data;
1520 filelist_free(d->list);
1524 static GtkWidget *view_confirm_dir_list(ViewWindow *vw, GList *list)
1529 d = g_new(CViewConfirmD, 1);
1533 menu = popup_menu_short_lived();
1534 g_signal_connect(G_OBJECT(menu), "destroy",
1535 G_CALLBACK(view_dir_list_destroy), d);
1537 menu_item_add_stock(menu, _("Dropped list includes folders."), GTK_STOCK_DND_MULTIPLE, NULL, NULL);
1538 menu_item_add_divider(menu);
1539 menu_item_add_stock(menu, _("_Add contents"), GTK_STOCK_OK, G_CALLBACK(view_dir_list_add), d);
1540 menu_item_add_stock(menu, _("Add contents _recursive"), GTK_STOCK_ADD, G_CALLBACK(view_dir_list_recurse), d);
1541 menu_item_add_stock(menu, _("_Skip folders"), GTK_STOCK_REMOVE, G_CALLBACK(view_dir_list_skip), d);
1542 menu_item_add_divider(menu);
1543 menu_item_add_stock(menu, _("Cancel"), GTK_STOCK_CANCEL, G_CALLBACK(view_dir_list_cancel), d);
1549 *-----------------------------------------------------------------------------
1550 * image drag and drop routines
1551 *-----------------------------------------------------------------------------
1554 static void view_window_get_dnd_data(GtkWidget *widget, GdkDragContext *context,
1556 GtkSelectionData *selection_data, guint info,
1557 guint time, gpointer data)
1559 ViewWindow *vw = data;
1562 if (gtk_drag_get_source_widget(context) == vw->imd->pr) return;
1566 if (info == TARGET_URI_LIST || info == TARGET_APP_COLLECTION_MEMBER)
1568 CollectionData *source;
1572 if (info == TARGET_URI_LIST)
1576 list = uri_filelist_from_gtk_selection_data(selection_data);
1581 FileData *fd = work->data;
1582 if (isdir(fd->path))
1585 menu = view_confirm_dir_list(vw, list);
1586 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 0, time);
1592 list = filelist_filter(list, FALSE);
1599 source = collection_from_dnd_data((gchar *)gtk_selection_data_get_data(selection_data), &list, &info_list);
1607 if (isfile(fd->path))
1609 view_slideshow_stop(vw);
1610 view_window_set_list(vw, NULL);
1612 if (source && info_list)
1614 image_change_from_collection(imd, source, info_list->data, image_zoom_get_default(imd));
1623 vw->list_pointer = vw->list;
1625 image_change_fd(imd, fd, image_zoom_get_default(imd));
1629 filelist_free(list);
1630 g_list_free(info_list);
1634 static void view_window_set_dnd_data(GtkWidget *widget, GdkDragContext *context,
1635 GtkSelectionData *selection_data, guint info,
1636 guint time, gpointer data)
1638 ViewWindow *vw = data;
1641 fd = image_get_fd(vw->imd);
1647 list = g_list_append(NULL, fd);
1648 uri_selection_data_set_uris_from_filelist(selection_data, list);
1653 gtk_selection_data_set(selection_data, gtk_selection_data_get_target(selection_data),
1658 static void view_window_dnd_init(ViewWindow *vw)
1664 gtk_drag_source_set(imd->pr, GDK_BUTTON2_MASK,
1665 dnd_file_drag_types, dnd_file_drag_types_count,
1666 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK);
1667 g_signal_connect(G_OBJECT(imd->pr), "drag_data_get",
1668 G_CALLBACK(view_window_set_dnd_data), vw);
1670 gtk_drag_dest_set(imd->pr,
1671 GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP,
1672 dnd_file_drop_types, dnd_file_drop_types_count,
1673 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK);
1674 g_signal_connect(G_OBJECT(imd->pr), "drag_data_received",
1675 G_CALLBACK(view_window_get_dnd_data), vw);
1679 *-----------------------------------------------------------------------------
1680 * maintenance (for rename, move, remove)
1681 *-----------------------------------------------------------------------------
1684 static void view_real_removed(ViewWindow *vw, FileData *fd)
1689 imd = view_window_active_image(vw);
1690 image_fd = image_get_fd(imd);
1692 if (image_fd && image_fd == fd)
1696 view_list_step(vw, TRUE);
1697 if (image_get_fd(imd) == image_fd)
1699 view_list_step(vw, FALSE);
1702 else if (view_window_contains_collection(vw))
1704 view_collection_step(vw, TRUE);
1705 if (image_get_fd(imd) == image_fd)
1707 view_collection_step(vw, FALSE);
1710 if (image_get_fd(imd) == image_fd)
1712 image_change_fd(imd, NULL, image_zoom_get_default(imd));
1721 old = vw->list_pointer;
1729 chk_fd = work->data;
1735 if (vw->list_pointer == chk_link)
1737 vw->list_pointer = (chk_link->next) ? chk_link->next : chk_link->prev;
1739 vw->list = g_list_remove(vw->list, chk_fd);
1740 file_data_unref(chk_fd);
1744 /* handles stepping correctly when same image is in the list more than once */
1745 if (old && old != vw->list_pointer)
1749 if (vw->list_pointer)
1751 fd = vw->list_pointer->data;
1758 image_change_fd(imd, fd, image_zoom_get_default(imd));
1762 image_osd_update(imd);
1765 static void view_window_notify_cb(FileData *fd, NotifyType type, gpointer data)
1767 ViewWindow *vw = data;
1769 if (!(type & NOTIFY_CHANGE) || !fd->change) return;
1771 DEBUG_1("Notify view_window: %s %04x", fd->path, type);
1773 switch (fd->change->type)
1775 case FILEDATA_CHANGE_MOVE:
1776 case FILEDATA_CHANGE_RENAME:
1778 case FILEDATA_CHANGE_COPY:
1780 case FILEDATA_CHANGE_DELETE:
1781 view_real_removed(vw, fd);
1783 case FILEDATA_CHANGE_UNSPECIFIED:
1784 case FILEDATA_CHANGE_WRITE_METADATA:
1788 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */