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_add_collection_cb(GtkWidget *widget, gpointer data)
419 w = collection_window_new(NULL);
420 collection_table_add_filelist(w->table, vf_pop_menu_file_list(vf));
423 static void vf_pop_menu_disable_grouping_cb(GtkWidget *widget, gpointer data)
427 file_data_disable_grouping_list(vf_pop_menu_file_list(vf), TRUE);
430 static void vf_pop_menu_sort_cb(GtkWidget *widget, gpointer data)
435 if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))) return;
437 vf = submenu_item_get_data(widget);
440 type = (SortType)GPOINTER_TO_INT(data);
444 layout_sort_set(vf->layout, type, vf->sort_ascend);
448 vf_sort_set(vf, type, vf->sort_ascend);
452 static void vf_pop_menu_sort_ascend_cb(GtkWidget *widget, gpointer data)
458 layout_sort_set(vf->layout, vf->sort_method, !vf->sort_ascend);
462 vf_sort_set(vf, vf->sort_method, !vf->sort_ascend);
466 static void vf_pop_menu_sel_mark_cb(GtkWidget *widget, gpointer data)
469 vf_mark_to_selection(vf, vf->active_mark, MTS_MODE_SET);
472 static void vf_pop_menu_sel_mark_and_cb(GtkWidget *widget, gpointer data)
475 vf_mark_to_selection(vf, vf->active_mark, MTS_MODE_AND);
478 static void vf_pop_menu_sel_mark_or_cb(GtkWidget *widget, gpointer data)
481 vf_mark_to_selection(vf, vf->active_mark, MTS_MODE_OR);
484 static void vf_pop_menu_sel_mark_minus_cb(GtkWidget *widget, gpointer data)
487 vf_mark_to_selection(vf, vf->active_mark, MTS_MODE_MINUS);
490 static void vf_pop_menu_set_mark_sel_cb(GtkWidget *widget, gpointer data)
493 vf_selection_to_mark(vf, vf->active_mark, STM_MODE_SET);
496 static void vf_pop_menu_res_mark_sel_cb(GtkWidget *widget, gpointer data)
499 vf_selection_to_mark(vf, vf->active_mark, STM_MODE_RESET);
502 static void vf_pop_menu_toggle_mark_sel_cb(GtkWidget *widget, gpointer data)
505 vf_selection_to_mark(vf, vf->active_mark, STM_MODE_TOGGLE);
508 static void vf_pop_menu_toggle_view_type_cb(GtkWidget *widget, gpointer data)
511 FileViewType new_type = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "menu_item_radio_data"));
512 if (!vf->layout) return;
514 layout_views_set(vf->layout, vf->layout->options.dir_view_type, new_type);
517 static void vf_pop_menu_refresh_cb(GtkWidget *widget, gpointer data)
523 case FILEVIEW_LIST: vflist_pop_menu_refresh_cb(widget, data); break;
524 case FILEVIEW_ICON: vficon_pop_menu_refresh_cb(widget, data); break;
528 static void vf_popup_destroy_cb(GtkWidget *widget, gpointer data)
534 case FILEVIEW_LIST: vflist_popup_destroy_cb(widget, data); break;
535 case FILEVIEW_ICON: vficon_popup_destroy_cb(widget, data); break;
538 filelist_free(vf->editmenu_fd_list);
539 vf->editmenu_fd_list = NULL;
542 GtkWidget *vf_pop_menu(ViewFile *vf)
547 gboolean active = FALSE;
552 vflist_color_set(vf, VFLIST(vf)->click_fd, TRUE);
553 active = (VFLIST(vf)->click_fd != NULL);
556 active = (VFICON(vf)->click_id != NULL);
560 menu = popup_menu_short_lived();
562 g_signal_connect(G_OBJECT(menu), "destroy",
563 G_CALLBACK(vf_popup_destroy_cb), vf);
565 if (vf->clicked_mark > 0)
567 gint mark = vf->clicked_mark;
568 gchar *str_set_mark = g_strdup_printf(_("_Set mark %d"), mark);
569 gchar *str_res_mark = g_strdup_printf(_("_Reset mark %d"), mark);
570 gchar *str_toggle_mark = g_strdup_printf(_("_Toggle mark %d"), mark);
571 gchar *str_sel_mark = g_strdup_printf(_("_Select mark %d"), mark);
572 gchar *str_sel_mark_or = g_strdup_printf(_("_Add mark %d"), mark);
573 gchar *str_sel_mark_and = g_strdup_printf(_("_Intersection with mark %d"), mark);
574 gchar *str_sel_mark_minus = g_strdup_printf(_("_Unselect mark %d"), mark);
576 g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
578 vf->active_mark = mark;
579 vf->clicked_mark = 0;
581 menu_item_add_sensitive(menu, str_set_mark, active,
582 G_CALLBACK(vf_pop_menu_set_mark_sel_cb), vf);
584 menu_item_add_sensitive(menu, str_res_mark, active,
585 G_CALLBACK(vf_pop_menu_res_mark_sel_cb), vf);
587 menu_item_add_sensitive(menu, str_toggle_mark, active,
588 G_CALLBACK(vf_pop_menu_toggle_mark_sel_cb), vf);
590 menu_item_add_divider(menu);
592 menu_item_add_sensitive(menu, str_sel_mark, active,
593 G_CALLBACK(vf_pop_menu_sel_mark_cb), vf);
594 menu_item_add_sensitive(menu, str_sel_mark_or, active,
595 G_CALLBACK(vf_pop_menu_sel_mark_or_cb), vf);
596 menu_item_add_sensitive(menu, str_sel_mark_and, active,
597 G_CALLBACK(vf_pop_menu_sel_mark_and_cb), vf);
598 menu_item_add_sensitive(menu, str_sel_mark_minus, active,
599 G_CALLBACK(vf_pop_menu_sel_mark_minus_cb), vf);
601 menu_item_add_divider(menu);
603 g_free(str_set_mark);
604 g_free(str_res_mark);
605 g_free(str_toggle_mark);
606 g_free(str_sel_mark);
607 g_free(str_sel_mark_and);
608 g_free(str_sel_mark_or);
609 g_free(str_sel_mark_minus);
612 vf->editmenu_fd_list = vf_pop_menu_file_list(vf);
613 submenu_add_edit(menu, &item, G_CALLBACK(vf_pop_menu_edit_cb), vf, vf->editmenu_fd_list);
614 gtk_widget_set_sensitive(item, active);
616 menu_item_add_stock_sensitive(menu, _("View in _new window"), GTK_STOCK_NEW, active,
617 G_CALLBACK(vf_pop_menu_view_cb), vf);
619 menu_item_add_divider(menu);
620 menu_item_add_stock_sensitive(menu, _("_Copy..."), GTK_STOCK_COPY, active,
621 G_CALLBACK(vf_pop_menu_copy_cb), vf);
622 menu_item_add_sensitive(menu, _("_Move..."), active,
623 G_CALLBACK(vf_pop_menu_move_cb), vf);
624 menu_item_add_sensitive(menu, _("_Rename..."), active,
625 G_CALLBACK(vf_pop_menu_rename_cb), vf);
626 menu_item_add_stock_sensitive(menu, _("_Delete..."), GTK_STOCK_DELETE, active,
627 G_CALLBACK(vf_pop_menu_delete_cb), vf);
628 menu_item_add_sensitive(menu, _("_Copy path"), active,
629 G_CALLBACK(vf_pop_menu_copy_path_cb), vf);
631 menu_item_add_sensitive(menu, _("Enable file _grouping"), active,
632 G_CALLBACK(vf_pop_menu_enable_grouping_cb), vf);
633 menu_item_add_sensitive(menu, _("Disable file groupi_ng"), active,
634 G_CALLBACK(vf_pop_menu_disable_grouping_cb), vf);
636 menu_item_add_divider(menu);
637 menu_item_add_stock_sensitive(menu, _("_Find duplicates..."), GTK_STOCK_FIND, active,
638 G_CALLBACK(vf_pop_menu_duplicates_cb), vf);
639 menu_item_add_divider(menu);
640 menu_item_add_stock_sensitive(menu, _("Add to new collection"), GTK_STOCK_INDEX, active,
641 G_CALLBACK(vf_pop_menu_add_collection_cb), vf);
642 menu_item_add_divider(menu);
644 submenu = submenu_add_sort(NULL, G_CALLBACK(vf_pop_menu_sort_cb), vf,
645 FALSE, FALSE, TRUE, vf->sort_method);
646 menu_item_add_divider(submenu);
647 menu_item_add_check(submenu, _("Ascending"), vf->sort_ascend,
648 G_CALLBACK(vf_pop_menu_sort_ascend_cb), vf);
650 item = menu_item_add(menu, _("_Sort"), NULL, NULL);
651 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
653 item = menu_item_add_radio(menu, _("View as _List"), GINT_TO_POINTER(FILEVIEW_LIST), vf->type == FILEVIEW_LIST,
654 G_CALLBACK(vf_pop_menu_toggle_view_type_cb), vf);
656 item = menu_item_add_radio(menu, _("View as _Icons"), GINT_TO_POINTER(FILEVIEW_ICON), vf->type == FILEVIEW_ICON,
657 G_CALLBACK(vf_pop_menu_toggle_view_type_cb), vf);
662 menu_item_add_check(menu, _("Show _thumbnails"), VFLIST(vf)->thumbs_enabled,
663 G_CALLBACK(vflist_pop_menu_thumbs_cb), vf);
666 menu_item_add_check(menu, _("Show filename _text"), VFICON(vf)->show_text,
667 G_CALLBACK(vficon_pop_menu_show_names_cb), vf);
671 menu_item_add_stock(menu, _("Re_fresh"), GTK_STOCK_REFRESH, G_CALLBACK(vf_pop_menu_refresh_cb), vf);
676 gboolean vf_refresh(ViewFile *vf)
678 gboolean ret = FALSE;
682 case FILEVIEW_LIST: ret = vflist_refresh(vf); break;
683 case FILEVIEW_ICON: ret = vficon_refresh(vf); break;
689 gboolean vf_set_fd(ViewFile *vf, FileData *dir_fd)
691 gboolean ret = FALSE;
695 case FILEVIEW_LIST: ret = vflist_set_fd(vf, dir_fd); break;
696 case FILEVIEW_ICON: ret = vficon_set_fd(vf, dir_fd); break;
702 static void vf_destroy_cb(GtkWidget *widget, gpointer data)
708 case FILEVIEW_LIST: vflist_destroy_cb(widget, data); break;
709 case FILEVIEW_ICON: vficon_destroy_cb(widget, data); break;
714 g_signal_handlers_disconnect_matched(G_OBJECT(vf->popup), G_SIGNAL_MATCH_DATA,
716 gtk_widget_destroy(vf->popup);
719 file_data_unref(vf->dir_fd);
724 static void vf_marks_filter_toggle_cb(GtkWidget *widget, gpointer data)
731 static GtkWidget *vf_marks_filter_init(ViewFile *vf)
733 GtkWidget *frame = gtk_frame_new(NULL);
734 GtkWidget *hbox = gtk_hbox_new(FALSE, 0);
738 for (i = 0; i < FILEDATA_MARKS_SIZE ; i++)
740 GtkWidget *check = gtk_check_button_new();
741 gtk_box_pack_start(GTK_BOX(hbox), check, FALSE, FALSE, 0);
742 g_signal_connect(G_OBJECT(check), "toggled",
743 G_CALLBACK(vf_marks_filter_toggle_cb), vf);
745 gtk_widget_show(check);
746 vf->filter_check[i] = check;
748 gtk_container_add(GTK_CONTAINER(frame), hbox);
749 gtk_widget_show(hbox);
753 void vf_mark_filter_toggle(ViewFile *vf, gint mark)
756 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(vf->filter_check[n]),
757 !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(vf->filter_check[n])));
760 ViewFile *vf_new(FileViewType type, FileData *dir_fd)
764 vf = g_new0(ViewFile, 1);
767 vf->sort_method = SORT_NAME;
768 vf->sort_ascend = TRUE;
770 vf->scrolled = gtk_scrolled_window_new(NULL, NULL);
771 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(vf->scrolled), GTK_SHADOW_IN);
772 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(vf->scrolled),
773 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
775 vf->filter = vf_marks_filter_init(vf);
777 vf->widget = gtk_vbox_new(FALSE, 0);
778 gtk_box_pack_start(GTK_BOX(vf->widget), vf->filter, FALSE, FALSE, 0);
779 gtk_box_pack_start(GTK_BOX(vf->widget), vf->scrolled, TRUE, TRUE, 0);
780 gtk_widget_show(vf->scrolled);
782 g_signal_connect(G_OBJECT(vf->widget), "destroy",
783 G_CALLBACK(vf_destroy_cb), vf);
787 case FILEVIEW_LIST: vf = vflist_new(vf, dir_fd); break;
788 case FILEVIEW_ICON: vf = vficon_new(vf, dir_fd); break;
793 g_signal_connect(G_OBJECT(vf->listview), "key_press_event",
794 G_CALLBACK(vf_press_key_cb), vf);
795 g_signal_connect(G_OBJECT(vf->listview), "button_press_event",
796 G_CALLBACK(vf_press_cb), vf);
797 g_signal_connect(G_OBJECT(vf->listview), "button_release_event",
798 G_CALLBACK(vf_release_cb), vf);
800 gtk_container_add(GTK_CONTAINER(vf->scrolled), vf->listview);
801 gtk_widget_show(vf->listview);
803 if (dir_fd) vf_set_fd(vf, dir_fd);
808 void vf_set_status_func(ViewFile *vf, void (*func)(ViewFile *vf, gpointer data), gpointer data)
810 vf->func_status = func;
811 vf->data_status = data;
814 void vf_set_thumb_status_func(ViewFile *vf, void (*func)(ViewFile *vf, gdouble val, const gchar *text, gpointer data), gpointer data)
816 vf->func_thumb_status = func;
817 vf->data_thumb_status = data;
820 void vf_thumb_set(ViewFile *vf, gboolean enable)
824 case FILEVIEW_LIST: vflist_thumb_set(vf, enable); break;
825 case FILEVIEW_ICON: /*vficon_thumb_set(vf, enable);*/ break;
830 static gboolean vf_thumb_next(ViewFile *vf);
832 static gdouble vf_thumb_progress(ViewFile *vf)
839 case FILEVIEW_LIST: vflist_thumb_progress_count(vf->list, &count, &done); break;
840 case FILEVIEW_ICON: vficon_thumb_progress_count(vf->list, &count, &done); break;
843 DEBUG_1("thumb progress: %d of %d", done, count);
844 return (gdouble)done / count;
847 static void vf_set_thumb_fd(ViewFile *vf, FileData *fd)
851 case FILEVIEW_LIST: vflist_set_thumb_fd(vf, fd); break;
852 case FILEVIEW_ICON: vficon_set_thumb_fd(vf, fd); break;
856 static void vf_thumb_status(ViewFile *vf, gdouble val, const gchar *text)
858 if (vf->func_thumb_status)
860 vf->func_thumb_status(vf, val, text, vf->data_thumb_status);
864 static void vf_thumb_do(ViewFile *vf, FileData *fd)
868 vf_set_thumb_fd(vf, fd);
869 vf_thumb_status(vf, vf_thumb_progress(vf), _("Loading thumbs..."));
872 void vf_thumb_cleanup(ViewFile *vf)
874 vf_thumb_status(vf, 0.0, NULL);
876 vf->thumbs_running = FALSE;
878 thumb_loader_free(vf->thumbs_loader);
879 vf->thumbs_loader = NULL;
881 vf->thumbs_filedata = NULL;
884 void vf_thumb_stop(ViewFile *vf)
886 if (vf->thumbs_running) vf_thumb_cleanup(vf);
889 static void vf_thumb_common_cb(ThumbLoader *tl, gpointer data)
893 if (vf->thumbs_filedata && vf->thumbs_loader == tl)
895 vf_thumb_do(vf, vf->thumbs_filedata);
898 while (vf_thumb_next(vf));
901 static void vf_thumb_error_cb(ThumbLoader *tl, gpointer data)
903 vf_thumb_common_cb(tl, data);
906 static void vf_thumb_done_cb(ThumbLoader *tl, gpointer data)
908 vf_thumb_common_cb(tl, data);
911 static gboolean vf_thumb_next(ViewFile *vf)
915 if (!gtk_widget_get_realized(vf->listview))
917 vf_thumb_status(vf, 0.0, NULL);
923 case FILEVIEW_LIST: fd = vflist_thumb_next_fd(vf); break;
924 case FILEVIEW_ICON: fd = vficon_thumb_next_fd(vf); break;
930 vf_thumb_cleanup(vf);
934 vf->thumbs_filedata = fd;
936 thumb_loader_free(vf->thumbs_loader);
938 vf->thumbs_loader = thumb_loader_new(options->thumbnails.max_width, options->thumbnails.max_height);
939 thumb_loader_set_callbacks(vf->thumbs_loader,
945 if (!thumb_loader_start(vf->thumbs_loader, fd))
947 /* set icon to unknown, continue */
948 DEBUG_1("thumb loader start failed %s", fd->path);
957 static void vf_thumb_reset_all(ViewFile *vf)
961 case FILEVIEW_LIST: vflist_thumb_reset_all(vf); break;
962 case FILEVIEW_ICON: vficon_thumb_reset_all(vf); break;
966 void vf_thumb_update(ViewFile *vf)
970 if (vf->type == FILEVIEW_LIST && !VFLIST(vf)->thumbs_enabled) return;
972 vf_thumb_status(vf, 0.0, _("Loading thumbs..."));
973 vf->thumbs_running = TRUE;
975 if (thumb_format_changed)
977 vf_thumb_reset_all(vf);
978 thumb_format_changed = FALSE;
981 while (vf_thumb_next(vf));
985 void vf_marks_set(ViewFile *vf, gboolean enable)
987 if (vf->marks_enabled == enable) return;
989 vf->marks_enabled = enable;
993 case FILEVIEW_LIST: vflist_marks_set(vf, enable); break;
994 case FILEVIEW_ICON: vficon_marks_set(vf, enable); break;
997 gtk_widget_show(vf->filter);
999 gtk_widget_hide(vf->filter);
1001 vf_refresh_idle(vf);
1004 guint vf_marks_get_filter(ViewFile *vf)
1008 if (!vf->marks_enabled) return 0;
1010 for (i = 0; i < FILEDATA_MARKS_SIZE ; i++)
1012 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(vf->filter_check[i])))
1020 void vf_set_layout(ViewFile *vf, LayoutWindow *layout)
1022 vf->layout = layout;
1027 *-----------------------------------------------------------------------------
1028 * maintenance (for rename, move, remove)
1029 *-----------------------------------------------------------------------------
1032 static gboolean vf_refresh_idle_cb(gpointer data)
1034 ViewFile *vf = data;
1037 vf->refresh_idle_id = 0;
1041 void vf_refresh_idle_cancel(ViewFile *vf)
1043 if (vf->refresh_idle_id)
1045 g_source_remove(vf->refresh_idle_id);
1046 vf->refresh_idle_id = 0;
1051 void vf_refresh_idle(ViewFile *vf)
1053 if (!vf->refresh_idle_id)
1055 vf->time_refresh_set = time(NULL);
1056 /* file operations run with G_PRIORITY_DEFAULT_IDLE */
1057 vf->refresh_idle_id = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE + 50, vf_refresh_idle_cb, vf, NULL);
1059 else if (time(NULL) - vf->time_refresh_set > 1)
1061 /* more than 1 sec since last update - increase priority */
1062 vf_refresh_idle_cancel(vf);
1063 vf->time_refresh_set = time(NULL);
1064 vf->refresh_idle_id = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE - 50, vf_refresh_idle_cb, vf, NULL);
1068 void vf_notify_cb(FileData *fd, NotifyType type, gpointer data)
1070 ViewFile *vf = data;
1073 NotifyType interested = NOTIFY_CHANGE | NOTIFY_REREAD | NOTIFY_GROUPING;
1074 if (vf->marks_enabled) interested |= NOTIFY_MARKS | NOTIFY_METADATA;
1075 /* FIXME: NOTIFY_METADATA should be checked by the keyword-to-mark functions and converted to NOTIFY_MARKS only if there was a change */
1077 if (!(type & interested) || vf->refresh_idle_id || !vf->dir_fd) return;
1079 refresh = (fd == vf->dir_fd);
1083 gchar *base = remove_level_from_path(fd->path);
1084 refresh = (strcmp(base, vf->dir_fd->path) == 0);
1088 if ((type & NOTIFY_CHANGE) && fd->change)
1090 if (!refresh && fd->change->dest)
1092 gchar *dest_base = remove_level_from_path(fd->change->dest);
1093 refresh = (strcmp(dest_base, vf->dir_fd->path) == 0);
1097 if (!refresh && fd->change->source)
1099 gchar *source_base = remove_level_from_path(fd->change->source);
1100 refresh = (strcmp(source_base, vf->dir_fd->path) == 0);
1101 g_free(source_base);
1107 DEBUG_1("Notify vf: %s %04x", fd->path, type);
1108 vf_refresh_idle(vf);
1112 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */