2 * Copyright (C) 2008 - 2016 The Geeqie Team
4 * Author: Laurent Monin
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "view_file.h"
30 #include "ui_fileops.h"
32 #include "view_file_list.h"
33 #include "view_file_icon.h"
36 *-----------------------------------------------------------------------------
38 *-----------------------------------------------------------------------------
41 void vf_send_update(ViewFile *vf)
43 if (vf->func_status) vf->func_status(vf, vf->data_status);
47 *-----------------------------------------------------------------------------
49 *-----------------------------------------------------------------------------
52 void vf_sort_set(ViewFile *vf, SortType type, gboolean ascend)
56 case FILEVIEW_LIST: vflist_sort_set(vf, type, ascend); break;
57 case FILEVIEW_ICON: vficon_sort_set(vf, type, ascend); break;
62 *-----------------------------------------------------------------------------
64 *-----------------------------------------------------------------------------
67 FileData *vf_index_get_data(ViewFile *vf, gint row)
73 case FILEVIEW_LIST: fd = vflist_index_get_data(vf, row); break;
74 case FILEVIEW_ICON: fd = vficon_index_get_data(vf, row); break;
80 gint vf_index_by_fd(ViewFile *vf, FileData *fd)
86 case FILEVIEW_LIST: index = vflist_index_by_fd(vf, fd); break;
87 case FILEVIEW_ICON: index = vficon_index_by_fd(vf, fd); break;
93 guint vf_count(ViewFile *vf, gint64 *bytes)
99 case FILEVIEW_LIST: count = vflist_count(vf, bytes); break;
100 case FILEVIEW_ICON: count = vficon_count(vf, bytes); break;
106 GList *vf_get_list(ViewFile *vf)
112 case FILEVIEW_LIST: list = vflist_get_list(vf); break;
113 case FILEVIEW_ICON: list = vficon_get_list(vf); break;
121 *-------------------------------------------------------------------
123 *-------------------------------------------------------------------
126 static gboolean vf_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
129 gboolean ret = FALSE;
133 case FILEVIEW_LIST: ret = vflist_press_key_cb(widget, event, data); break;
134 case FILEVIEW_ICON: ret = vficon_press_key_cb(widget, event, data); break;
141 *-------------------------------------------------------------------
143 *-------------------------------------------------------------------
146 static gboolean vf_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
149 gboolean ret = FALSE;
153 case FILEVIEW_LIST: ret = vflist_press_cb(widget, bevent, data); break;
154 case FILEVIEW_ICON: ret = vficon_press_cb(widget, bevent, data); break;
160 static gboolean vf_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
163 gboolean ret = FALSE;
167 case FILEVIEW_LIST: ret = vflist_release_cb(widget, bevent, data); break;
168 case FILEVIEW_ICON: ret = vficon_release_cb(widget, bevent, data); break;
176 *-----------------------------------------------------------------------------
178 *-----------------------------------------------------------------------------
181 gboolean vf_index_is_selected(ViewFile *vf, gint row)
183 gboolean ret = FALSE;
187 case FILEVIEW_LIST: ret = vflist_index_is_selected(vf, row); break;
188 case FILEVIEW_ICON: ret = vficon_index_is_selected(vf, row); break;
195 guint vf_selection_count(ViewFile *vf, gint64 *bytes)
201 case FILEVIEW_LIST: count = vflist_selection_count(vf, bytes); break;
202 case FILEVIEW_ICON: count = vficon_selection_count(vf, bytes); break;
208 GList *vf_selection_get_list(ViewFile *vf)
214 case FILEVIEW_LIST: list = vflist_selection_get_list(vf); break;
215 case FILEVIEW_ICON: list = vficon_selection_get_list(vf); break;
221 GList *vf_selection_get_list_by_index(ViewFile *vf)
227 case FILEVIEW_LIST: list = vflist_selection_get_list_by_index(vf); break;
228 case FILEVIEW_ICON: list = vficon_selection_get_list_by_index(vf); break;
234 void vf_select_all(ViewFile *vf)
238 case FILEVIEW_LIST: vflist_select_all(vf); break;
239 case FILEVIEW_ICON: vficon_select_all(vf); break;
243 void vf_select_none(ViewFile *vf)
247 case FILEVIEW_LIST: vflist_select_none(vf); break;
248 case FILEVIEW_ICON: vficon_select_none(vf); break;
252 void vf_select_invert(ViewFile *vf)
256 case FILEVIEW_LIST: vflist_select_invert(vf); break;
257 case FILEVIEW_ICON: vficon_select_invert(vf); break;
261 void vf_select_by_fd(ViewFile *vf, FileData *fd)
265 case FILEVIEW_LIST: vflist_select_by_fd(vf, fd); break;
266 case FILEVIEW_ICON: vficon_select_by_fd(vf, fd); break;
270 void vf_mark_to_selection(ViewFile *vf, gint mark, MarkToSelectionMode mode)
274 case FILEVIEW_LIST: vflist_mark_to_selection(vf, mark, mode); break;
275 case FILEVIEW_ICON: vficon_mark_to_selection(vf, mark, mode); break;
279 void vf_selection_to_mark(ViewFile *vf, gint mark, SelectionToMarkMode mode)
283 case FILEVIEW_LIST: vflist_selection_to_mark(vf, mark, mode); break;
284 case FILEVIEW_ICON: vficon_selection_to_mark(vf, mark, mode); break;
289 *-----------------------------------------------------------------------------
291 *-----------------------------------------------------------------------------
295 static void vf_dnd_init(ViewFile *vf)
299 case FILEVIEW_LIST: vflist_dnd_init(vf); break;
300 case FILEVIEW_ICON: vficon_dnd_init(vf); break;
305 *-----------------------------------------------------------------------------
307 *-----------------------------------------------------------------------------
310 GList *vf_pop_menu_file_list(ViewFile *vf)
316 case FILEVIEW_LIST: ret = vflist_pop_menu_file_list(vf); break;
317 case FILEVIEW_ICON: ret = vficon_pop_menu_file_list(vf); break;
323 GList *vf_selection_get_one(ViewFile *vf, FileData *fd)
329 case FILEVIEW_LIST: ret = vflist_selection_get_one(vf, fd); break;
330 case FILEVIEW_ICON: ret = vficon_selection_get_one(vf, fd); break;
336 static void vf_pop_menu_edit_cb(GtkWidget *widget, gpointer data)
339 const gchar *key = data;
341 vf = submenu_item_get_data(widget);
345 file_util_start_editor_from_filelist(key, vf_pop_menu_file_list(vf), vf->dir_fd->path, vf->listview);
348 static void vf_pop_menu_view_cb(GtkWidget *widget, gpointer data)
354 case FILEVIEW_LIST: vflist_pop_menu_view_cb(widget, data); break;
355 case FILEVIEW_ICON: vficon_pop_menu_view_cb(widget, data); break;
359 static void vf_pop_menu_copy_cb(GtkWidget *widget, gpointer data)
363 file_util_copy(NULL, vf_pop_menu_file_list(vf), NULL, vf->listview);
366 static void vf_pop_menu_move_cb(GtkWidget *widget, gpointer data)
370 file_util_move(NULL, vf_pop_menu_file_list(vf), NULL, vf->listview);
373 static void vf_pop_menu_rename_cb(GtkWidget *widget, gpointer data)
379 case FILEVIEW_LIST: vflist_pop_menu_rename_cb(widget, data); break;
380 case FILEVIEW_ICON: vficon_pop_menu_rename_cb(widget, data); break;
384 static void vf_pop_menu_delete_cb(GtkWidget *widget, gpointer data)
388 file_util_delete(NULL, vf_pop_menu_file_list(vf), vf->listview);
391 static void vf_pop_menu_copy_path_cb(GtkWidget *widget, gpointer data)
395 file_util_copy_path_list_to_clipboard(vf_pop_menu_file_list(vf));
398 static void vf_pop_menu_enable_grouping_cb(GtkWidget *widget, gpointer data)
402 file_data_disable_grouping_list(vf_pop_menu_file_list(vf), FALSE);
405 static void vf_pop_menu_duplicates_cb(GtkWidget *widget, gpointer data)
410 dw = dupe_window_new(DUPE_MATCH_NAME);
411 dupe_window_add_files(dw, vf_pop_menu_file_list(vf), FALSE);
414 static void vf_pop_menu_disable_grouping_cb(GtkWidget *widget, gpointer data)
418 file_data_disable_grouping_list(vf_pop_menu_file_list(vf), TRUE);
421 static void vf_pop_menu_sort_cb(GtkWidget *widget, gpointer data)
426 if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))) return;
428 vf = submenu_item_get_data(widget);
431 type = (SortType)GPOINTER_TO_INT(data);
435 layout_sort_set(vf->layout, type, vf->sort_ascend);
439 vf_sort_set(vf, type, vf->sort_ascend);
443 static void vf_pop_menu_sort_ascend_cb(GtkWidget *widget, gpointer data)
449 layout_sort_set(vf->layout, vf->sort_method, !vf->sort_ascend);
453 vf_sort_set(vf, vf->sort_method, !vf->sort_ascend);
457 static void vf_pop_menu_sel_mark_cb(GtkWidget *widget, gpointer data)
460 vf_mark_to_selection(vf, vf->active_mark, MTS_MODE_SET);
463 static void vf_pop_menu_sel_mark_and_cb(GtkWidget *widget, gpointer data)
466 vf_mark_to_selection(vf, vf->active_mark, MTS_MODE_AND);
469 static void vf_pop_menu_sel_mark_or_cb(GtkWidget *widget, gpointer data)
472 vf_mark_to_selection(vf, vf->active_mark, MTS_MODE_OR);
475 static void vf_pop_menu_sel_mark_minus_cb(GtkWidget *widget, gpointer data)
478 vf_mark_to_selection(vf, vf->active_mark, MTS_MODE_MINUS);
481 static void vf_pop_menu_set_mark_sel_cb(GtkWidget *widget, gpointer data)
484 vf_selection_to_mark(vf, vf->active_mark, STM_MODE_SET);
487 static void vf_pop_menu_res_mark_sel_cb(GtkWidget *widget, gpointer data)
490 vf_selection_to_mark(vf, vf->active_mark, STM_MODE_RESET);
493 static void vf_pop_menu_toggle_mark_sel_cb(GtkWidget *widget, gpointer data)
496 vf_selection_to_mark(vf, vf->active_mark, STM_MODE_TOGGLE);
499 static void vf_pop_menu_toggle_view_type_cb(GtkWidget *widget, gpointer data)
502 FileViewType new_type = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "menu_item_radio_data"));
503 if (!vf->layout) return;
505 layout_views_set(vf->layout, vf->layout->options.dir_view_type, new_type);
508 static void vf_pop_menu_refresh_cb(GtkWidget *widget, gpointer data)
514 case FILEVIEW_LIST: vflist_pop_menu_refresh_cb(widget, data); break;
515 case FILEVIEW_ICON: vficon_pop_menu_refresh_cb(widget, data); break;
519 static void vf_popup_destroy_cb(GtkWidget *widget, gpointer data)
525 case FILEVIEW_LIST: vflist_popup_destroy_cb(widget, data); break;
526 case FILEVIEW_ICON: vficon_popup_destroy_cb(widget, data); break;
529 filelist_free(vf->editmenu_fd_list);
530 vf->editmenu_fd_list = NULL;
533 GtkWidget *vf_pop_menu(ViewFile *vf)
538 gboolean active = FALSE;
543 vflist_color_set(vf, VFLIST(vf)->click_fd, TRUE);
544 active = (VFLIST(vf)->click_fd != NULL);
547 active = (VFICON(vf)->click_id != NULL);
551 menu = popup_menu_short_lived();
553 g_signal_connect(G_OBJECT(menu), "destroy",
554 G_CALLBACK(vf_popup_destroy_cb), vf);
556 if (vf->clicked_mark > 0)
558 gint mark = vf->clicked_mark;
559 gchar *str_set_mark = g_strdup_printf(_("_Set mark %d"), mark);
560 gchar *str_res_mark = g_strdup_printf(_("_Reset mark %d"), mark);
561 gchar *str_toggle_mark = g_strdup_printf(_("_Toggle mark %d"), mark);
562 gchar *str_sel_mark = g_strdup_printf(_("_Select mark %d"), mark);
563 gchar *str_sel_mark_or = g_strdup_printf(_("_Add mark %d"), mark);
564 gchar *str_sel_mark_and = g_strdup_printf(_("_Intersection with mark %d"), mark);
565 gchar *str_sel_mark_minus = g_strdup_printf(_("_Unselect mark %d"), mark);
567 g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
569 vf->active_mark = mark;
570 vf->clicked_mark = 0;
572 menu_item_add_sensitive(menu, str_set_mark, active,
573 G_CALLBACK(vf_pop_menu_set_mark_sel_cb), vf);
575 menu_item_add_sensitive(menu, str_res_mark, active,
576 G_CALLBACK(vf_pop_menu_res_mark_sel_cb), vf);
578 menu_item_add_sensitive(menu, str_toggle_mark, active,
579 G_CALLBACK(vf_pop_menu_toggle_mark_sel_cb), vf);
581 menu_item_add_divider(menu);
583 menu_item_add_sensitive(menu, str_sel_mark, active,
584 G_CALLBACK(vf_pop_menu_sel_mark_cb), vf);
585 menu_item_add_sensitive(menu, str_sel_mark_or, active,
586 G_CALLBACK(vf_pop_menu_sel_mark_or_cb), vf);
587 menu_item_add_sensitive(menu, str_sel_mark_and, active,
588 G_CALLBACK(vf_pop_menu_sel_mark_and_cb), vf);
589 menu_item_add_sensitive(menu, str_sel_mark_minus, active,
590 G_CALLBACK(vf_pop_menu_sel_mark_minus_cb), vf);
592 menu_item_add_divider(menu);
594 g_free(str_set_mark);
595 g_free(str_res_mark);
596 g_free(str_toggle_mark);
597 g_free(str_sel_mark);
598 g_free(str_sel_mark_and);
599 g_free(str_sel_mark_or);
600 g_free(str_sel_mark_minus);
603 vf->editmenu_fd_list = vf_pop_menu_file_list(vf);
604 submenu_add_edit(menu, &item, G_CALLBACK(vf_pop_menu_edit_cb), vf, vf->editmenu_fd_list);
605 gtk_widget_set_sensitive(item, active);
607 menu_item_add_stock_sensitive(menu, _("View in _new window"), GTK_STOCK_NEW, active,
608 G_CALLBACK(vf_pop_menu_view_cb), vf);
610 menu_item_add_divider(menu);
611 menu_item_add_stock_sensitive(menu, _("_Copy..."), GTK_STOCK_COPY, active,
612 G_CALLBACK(vf_pop_menu_copy_cb), vf);
613 menu_item_add_sensitive(menu, _("_Move..."), active,
614 G_CALLBACK(vf_pop_menu_move_cb), vf);
615 menu_item_add_sensitive(menu, _("_Rename..."), active,
616 G_CALLBACK(vf_pop_menu_rename_cb), vf);
617 menu_item_add_stock_sensitive(menu, _("_Delete..."), GTK_STOCK_DELETE, active,
618 G_CALLBACK(vf_pop_menu_delete_cb), vf);
619 menu_item_add_sensitive(menu, _("_Copy path"), active,
620 G_CALLBACK(vf_pop_menu_copy_path_cb), vf);
622 menu_item_add_sensitive(menu, _("Enable file _grouping"), active,
623 G_CALLBACK(vf_pop_menu_enable_grouping_cb), vf);
624 menu_item_add_sensitive(menu, _("Disable file groupi_ng"), active,
625 G_CALLBACK(vf_pop_menu_disable_grouping_cb), vf);
627 menu_item_add_divider(menu);
628 menu_item_add_stock_sensitive(menu, _("_Find duplicates..."), GTK_STOCK_FIND, active,
629 G_CALLBACK(vf_pop_menu_duplicates_cb), vf);
630 menu_item_add_divider(menu);
632 submenu = submenu_add_sort(NULL, G_CALLBACK(vf_pop_menu_sort_cb), vf,
633 FALSE, FALSE, TRUE, vf->sort_method);
634 menu_item_add_divider(submenu);
635 menu_item_add_check(submenu, _("Ascending"), vf->sort_ascend,
636 G_CALLBACK(vf_pop_menu_sort_ascend_cb), vf);
638 item = menu_item_add(menu, _("_Sort"), NULL, NULL);
639 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
641 item = menu_item_add_radio(menu, _("View as _List"), GINT_TO_POINTER(FILEVIEW_LIST), vf->type == FILEVIEW_LIST,
642 G_CALLBACK(vf_pop_menu_toggle_view_type_cb), vf);
644 item = menu_item_add_radio(menu, _("View as _Icons"), GINT_TO_POINTER(FILEVIEW_ICON), vf->type == FILEVIEW_ICON,
645 G_CALLBACK(vf_pop_menu_toggle_view_type_cb), vf);
650 menu_item_add_check(menu, _("Show _thumbnails"), VFLIST(vf)->thumbs_enabled,
651 G_CALLBACK(vflist_pop_menu_thumbs_cb), vf);
654 menu_item_add_check(menu, _("Show filename _text"), VFICON(vf)->show_text,
655 G_CALLBACK(vficon_pop_menu_show_names_cb), vf);
659 menu_item_add_stock(menu, _("Re_fresh"), GTK_STOCK_REFRESH, G_CALLBACK(vf_pop_menu_refresh_cb), vf);
664 gboolean vf_refresh(ViewFile *vf)
666 gboolean ret = FALSE;
670 case FILEVIEW_LIST: ret = vflist_refresh(vf); break;
671 case FILEVIEW_ICON: ret = vficon_refresh(vf); break;
677 gboolean vf_set_fd(ViewFile *vf, FileData *dir_fd)
679 gboolean ret = FALSE;
683 case FILEVIEW_LIST: ret = vflist_set_fd(vf, dir_fd); break;
684 case FILEVIEW_ICON: ret = vficon_set_fd(vf, dir_fd); break;
690 static void vf_destroy_cb(GtkWidget *widget, gpointer data)
696 case FILEVIEW_LIST: vflist_destroy_cb(widget, data); break;
697 case FILEVIEW_ICON: vficon_destroy_cb(widget, data); break;
702 g_signal_handlers_disconnect_matched(G_OBJECT(vf->popup), G_SIGNAL_MATCH_DATA,
704 gtk_widget_destroy(vf->popup);
707 file_data_unref(vf->dir_fd);
712 static void vf_marks_filter_toggle_cb(GtkWidget *widget, gpointer data)
719 static GtkWidget *vf_marks_filter_init(ViewFile *vf)
721 GtkWidget *frame = gtk_frame_new(NULL);
722 GtkWidget *hbox = gtk_hbox_new(FALSE, 0);
726 for (i = 0; i < FILEDATA_MARKS_SIZE ; i++)
728 GtkWidget *check = gtk_check_button_new();
729 gtk_box_pack_start(GTK_BOX(hbox), check, FALSE, FALSE, 0);
730 g_signal_connect(G_OBJECT(check), "toggled",
731 G_CALLBACK(vf_marks_filter_toggle_cb), vf);
733 gtk_widget_show(check);
734 vf->filter_check[i] = check;
736 gtk_container_add(GTK_CONTAINER(frame), hbox);
737 gtk_widget_show(hbox);
741 void vf_mark_filter_toggle(ViewFile *vf, gint mark)
744 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(vf->filter_check[n]),
745 !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(vf->filter_check[n])));
748 ViewFile *vf_new(FileViewType type, FileData *dir_fd)
752 vf = g_new0(ViewFile, 1);
755 vf->sort_method = SORT_NAME;
756 vf->sort_ascend = TRUE;
758 vf->scrolled = gtk_scrolled_window_new(NULL, NULL);
759 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(vf->scrolled), GTK_SHADOW_IN);
760 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(vf->scrolled),
761 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
763 vf->filter = vf_marks_filter_init(vf);
765 vf->widget = gtk_vbox_new(FALSE, 0);
766 gtk_box_pack_start(GTK_BOX(vf->widget), vf->filter, FALSE, FALSE, 0);
767 gtk_box_pack_start(GTK_BOX(vf->widget), vf->scrolled, TRUE, TRUE, 0);
768 gtk_widget_show(vf->scrolled);
770 g_signal_connect(G_OBJECT(vf->widget), "destroy",
771 G_CALLBACK(vf_destroy_cb), vf);
775 case FILEVIEW_LIST: vf = vflist_new(vf, dir_fd); break;
776 case FILEVIEW_ICON: vf = vficon_new(vf, dir_fd); break;
781 g_signal_connect(G_OBJECT(vf->listview), "key_press_event",
782 G_CALLBACK(vf_press_key_cb), vf);
783 g_signal_connect(G_OBJECT(vf->listview), "button_press_event",
784 G_CALLBACK(vf_press_cb), vf);
785 g_signal_connect(G_OBJECT(vf->listview), "button_release_event",
786 G_CALLBACK(vf_release_cb), vf);
788 gtk_container_add(GTK_CONTAINER(vf->scrolled), vf->listview);
789 gtk_widget_show(vf->listview);
791 if (dir_fd) vf_set_fd(vf, dir_fd);
796 void vf_set_status_func(ViewFile *vf, void (*func)(ViewFile *vf, gpointer data), gpointer data)
798 vf->func_status = func;
799 vf->data_status = data;
802 void vf_set_thumb_status_func(ViewFile *vf, void (*func)(ViewFile *vf, gdouble val, const gchar *text, gpointer data), gpointer data)
804 vf->func_thumb_status = func;
805 vf->data_thumb_status = data;
808 void vf_thumb_set(ViewFile *vf, gboolean enable)
812 case FILEVIEW_LIST: vflist_thumb_set(vf, enable); break;
813 case FILEVIEW_ICON: /*vficon_thumb_set(vf, enable);*/ break;
818 static gboolean vf_thumb_next(ViewFile *vf);
820 static gdouble vf_thumb_progress(ViewFile *vf)
827 case FILEVIEW_LIST: vflist_thumb_progress_count(vf->list, &count, &done); break;
828 case FILEVIEW_ICON: vficon_thumb_progress_count(vf->list, &count, &done); break;
831 DEBUG_1("thumb progress: %d of %d", done, count);
832 return (gdouble)done / count;
835 static void vf_set_thumb_fd(ViewFile *vf, FileData *fd)
839 case FILEVIEW_LIST: vflist_set_thumb_fd(vf, fd); break;
840 case FILEVIEW_ICON: vficon_set_thumb_fd(vf, fd); break;
844 static void vf_thumb_status(ViewFile *vf, gdouble val, const gchar *text)
846 if (vf->func_thumb_status)
848 vf->func_thumb_status(vf, val, text, vf->data_thumb_status);
852 static void vf_thumb_do(ViewFile *vf, FileData *fd)
856 vf_set_thumb_fd(vf, fd);
857 vf_thumb_status(vf, vf_thumb_progress(vf), _("Loading thumbs..."));
860 void vf_thumb_cleanup(ViewFile *vf)
862 vf_thumb_status(vf, 0.0, NULL);
864 vf->thumbs_running = FALSE;
866 thumb_loader_free(vf->thumbs_loader);
867 vf->thumbs_loader = NULL;
869 vf->thumbs_filedata = NULL;
872 void vf_thumb_stop(ViewFile *vf)
874 if (vf->thumbs_running) vf_thumb_cleanup(vf);
877 static void vf_thumb_common_cb(ThumbLoader *tl, gpointer data)
881 if (vf->thumbs_filedata && vf->thumbs_loader == tl)
883 vf_thumb_do(vf, vf->thumbs_filedata);
886 while (vf_thumb_next(vf));
889 static void vf_thumb_error_cb(ThumbLoader *tl, gpointer data)
891 vf_thumb_common_cb(tl, data);
894 static void vf_thumb_done_cb(ThumbLoader *tl, gpointer data)
896 vf_thumb_common_cb(tl, data);
899 static gboolean vf_thumb_next(ViewFile *vf)
903 if (!gtk_widget_get_realized(vf->listview))
905 vf_thumb_status(vf, 0.0, NULL);
911 case FILEVIEW_LIST: fd = vflist_thumb_next_fd(vf); break;
912 case FILEVIEW_ICON: fd = vficon_thumb_next_fd(vf); break;
918 vf_thumb_cleanup(vf);
922 vf->thumbs_filedata = fd;
924 thumb_loader_free(vf->thumbs_loader);
926 vf->thumbs_loader = thumb_loader_new(options->thumbnails.max_width, options->thumbnails.max_height);
927 thumb_loader_set_callbacks(vf->thumbs_loader,
933 if (!thumb_loader_start(vf->thumbs_loader, fd))
935 /* set icon to unknown, continue */
936 DEBUG_1("thumb loader start failed %s", fd->path);
945 static void vf_thumb_reset_all(ViewFile *vf)
949 case FILEVIEW_LIST: vflist_thumb_reset_all(vf); break;
950 case FILEVIEW_ICON: vficon_thumb_reset_all(vf); break;
954 void vf_thumb_update(ViewFile *vf)
958 if (vf->type == FILEVIEW_LIST && !VFLIST(vf)->thumbs_enabled) return;
960 vf_thumb_status(vf, 0.0, _("Loading thumbs..."));
961 vf->thumbs_running = TRUE;
963 if (thumb_format_changed)
965 vf_thumb_reset_all(vf);
966 thumb_format_changed = FALSE;
969 while (vf_thumb_next(vf));
973 void vf_marks_set(ViewFile *vf, gboolean enable)
975 if (vf->marks_enabled == enable) return;
977 vf->marks_enabled = enable;
981 case FILEVIEW_LIST: vflist_marks_set(vf, enable); break;
982 case FILEVIEW_ICON: vficon_marks_set(vf, enable); break;
985 gtk_widget_show(vf->filter);
987 gtk_widget_hide(vf->filter);
992 guint vf_marks_get_filter(ViewFile *vf)
996 if (!vf->marks_enabled) return 0;
998 for (i = 0; i < FILEDATA_MARKS_SIZE ; i++)
1000 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(vf->filter_check[i])))
1008 void vf_set_layout(ViewFile *vf, LayoutWindow *layout)
1010 vf->layout = layout;
1015 *-----------------------------------------------------------------------------
1016 * maintenance (for rename, move, remove)
1017 *-----------------------------------------------------------------------------
1020 static gboolean vf_refresh_idle_cb(gpointer data)
1022 ViewFile *vf = data;
1025 vf->refresh_idle_id = 0;
1029 void vf_refresh_idle_cancel(ViewFile *vf)
1031 if (vf->refresh_idle_id)
1033 g_source_remove(vf->refresh_idle_id);
1034 vf->refresh_idle_id = 0;
1039 void vf_refresh_idle(ViewFile *vf)
1041 if (!vf->refresh_idle_id)
1043 vf->time_refresh_set = time(NULL);
1044 /* file operations run with G_PRIORITY_DEFAULT_IDLE */
1045 vf->refresh_idle_id = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE + 50, vf_refresh_idle_cb, vf, NULL);
1047 else if (time(NULL) - vf->time_refresh_set > 1)
1049 /* more than 1 sec since last update - increase priority */
1050 vf_refresh_idle_cancel(vf);
1051 vf->time_refresh_set = time(NULL);
1052 vf->refresh_idle_id = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE - 50, vf_refresh_idle_cb, vf, NULL);
1056 void vf_notify_cb(FileData *fd, NotifyType type, gpointer data)
1058 ViewFile *vf = data;
1061 NotifyType interested = NOTIFY_CHANGE | NOTIFY_REREAD | NOTIFY_GROUPING;
1062 if (vf->marks_enabled) interested |= NOTIFY_MARKS | NOTIFY_METADATA;
1063 /* FIXME: NOTIFY_METADATA should be checked by the keyword-to-mark functions and converted to NOTIFY_MARKS only if there was a change */
1065 if (!(type & interested) || vf->refresh_idle_id || !vf->dir_fd) return;
1067 refresh = (fd == vf->dir_fd);
1071 gchar *base = remove_level_from_path(fd->path);
1072 refresh = (strcmp(base, vf->dir_fd->path) == 0);
1076 if ((type & NOTIFY_CHANGE) && fd->change)
1078 if (!refresh && fd->change->dest)
1080 gchar *dest_base = remove_level_from_path(fd->change->dest);
1081 refresh = (strcmp(dest_base, vf->dir_fd->path) == 0);
1085 if (!refresh && fd->change->source)
1087 gchar *source_base = remove_level_from_path(fd->change->source);
1088 refresh = (strcmp(source_base, vf->dir_fd->path) == 0);
1089 g_free(source_base);
1095 DEBUG_1("Notify vf: %s %04x", fd->path, type);
1096 vf_refresh_idle(vf);
1100 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */