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.
21 #include "view-file.h"
24 #include <glib-object.h>
31 #include "history-list.h"
34 #include "main-defines.h"
40 #include "ui-fileops.h"
43 #include "ui-utildlg.h"
45 #include "view-file/view-file-icon.h"
46 #include "view-file/view-file-list.h"
50 *-----------------------------------------------------------------------------
52 *-----------------------------------------------------------------------------
55 void vf_send_update(ViewFile *vf)
57 if (vf->func_status) vf->func_status(vf, vf->data_status);
61 *-----------------------------------------------------------------------------
63 *-----------------------------------------------------------------------------
66 void vf_sort_set(ViewFile *vf, SortType type, gboolean ascend, gboolean case_sensitive)
70 case FILEVIEW_LIST: vflist_sort_set(vf, type, ascend, case_sensitive); break;
71 case FILEVIEW_ICON: vficon_sort_set(vf, type, ascend, case_sensitive); break;
76 *-----------------------------------------------------------------------------
78 *-----------------------------------------------------------------------------
81 FileData *vf_index_get_data(ViewFile *vf, gint row)
83 return static_cast<FileData *>(g_list_nth_data(vf->list, row));
86 gint vf_index_by_fd(ViewFile *vf, FileData *fd)
92 case FILEVIEW_LIST: ret = vflist_index_by_fd(vf, fd); break;
93 case FILEVIEW_ICON: ret = vficon_index_by_fd(vf, fd); break;
100 guint vf_count(ViewFile *vf, gint64 *bytes)
110 auto fd = static_cast<FileData *>(work->data);
119 return g_list_length(vf->list);
122 GList *vf_get_list(ViewFile *vf)
124 return filelist_copy(vf->list);
128 *-------------------------------------------------------------------
130 *-------------------------------------------------------------------
133 static gboolean vf_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
135 auto vf = static_cast<ViewFile *>(data);
140 case FILEVIEW_LIST: ret = vflist_press_key_cb(vf, widget, event); break;
141 case FILEVIEW_ICON: ret = vficon_press_key_cb(vf, widget, event); break;
142 default: ret = FALSE;
149 *-------------------------------------------------------------------
151 *-------------------------------------------------------------------
154 static gboolean vf_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
156 auto vf = static_cast<ViewFile *>(data);
161 case FILEVIEW_LIST: ret = vflist_press_cb(vf, widget, bevent); break;
162 case FILEVIEW_ICON: ret = vficon_press_cb(vf, widget, bevent); break;
163 default: ret = FALSE;
169 static gboolean vf_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
171 auto vf = static_cast<ViewFile *>(data);
176 case FILEVIEW_LIST: ret = vflist_release_cb(vf, widget, bevent); break;
177 case FILEVIEW_ICON: ret = vficon_release_cb(vf, widget, bevent); break;
178 default: ret = FALSE;
186 *-----------------------------------------------------------------------------
188 *-----------------------------------------------------------------------------
191 guint vf_selection_count(ViewFile *vf, gint64 *bytes)
197 case FILEVIEW_LIST: ret = vflist_selection_count(vf, bytes); break;
198 case FILEVIEW_ICON: ret = vficon_selection_count(vf, bytes); break;
205 GList *vf_selection_get_list(ViewFile *vf)
211 case FILEVIEW_LIST: ret = vflist_selection_get_list(vf); break;
212 case FILEVIEW_ICON: ret = vficon_selection_get_list(vf); break;
213 default: ret = nullptr;
219 GList *vf_selection_get_list_by_index(ViewFile *vf)
225 case FILEVIEW_LIST: ret = vflist_selection_get_list_by_index(vf); break;
226 case FILEVIEW_ICON: ret = vficon_selection_get_list_by_index(vf); break;
227 default: ret = nullptr;
233 void vf_selection_foreach(ViewFile *vf, const ViewFile::SelectionCallback &func)
239 case FILEVIEW_LIST: vflist_selection_foreach(vf, func); break;
240 case FILEVIEW_ICON: vficon_selection_foreach(vf, func); break;
244 void vf_select_all(ViewFile *vf)
248 case FILEVIEW_LIST: vflist_select_all(vf); break;
249 case FILEVIEW_ICON: vficon_select_all(vf); break;
253 void vf_select_none(ViewFile *vf)
257 case FILEVIEW_LIST: vflist_select_none(vf); break;
258 case FILEVIEW_ICON: vficon_select_none(vf); break;
262 void vf_select_invert(ViewFile *vf)
266 case FILEVIEW_LIST: vflist_select_invert(vf); break;
267 case FILEVIEW_ICON: vficon_select_invert(vf); break;
271 void vf_select_by_fd(ViewFile *vf, FileData *fd)
275 case FILEVIEW_LIST: vflist_select_by_fd(vf, fd); break;
276 case FILEVIEW_ICON: vficon_select_by_fd(vf, fd); break;
280 void vf_select_list(ViewFile *vf, GList *list)
284 case FILEVIEW_LIST: vflist_select_list(vf, list); break;
285 case FILEVIEW_ICON: vficon_select_list(vf, list); break;
289 void vf_mark_to_selection(ViewFile *vf, gint mark, MarkToSelectionMode mode)
293 case FILEVIEW_LIST: vflist_mark_to_selection(vf, mark, mode); break;
294 case FILEVIEW_ICON: vficon_mark_to_selection(vf, mark, mode); break;
298 void vf_selection_to_mark(ViewFile *vf, gint mark, SelectionToMarkMode mode)
302 case FILEVIEW_LIST: vflist_selection_to_mark(vf, mark, mode); break;
303 case FILEVIEW_ICON: vficon_selection_to_mark(vf, mark, mode); break;
308 *-----------------------------------------------------------------------------
310 *-----------------------------------------------------------------------------
314 static void vf_dnd_init(ViewFile *vf)
318 case FILEVIEW_LIST: vflist_dnd_init(vf); break;
319 case FILEVIEW_ICON: vficon_dnd_init(vf); break;
324 *-----------------------------------------------------------------------------
326 *-----------------------------------------------------------------------------
329 GList *vf_pop_menu_file_list(ViewFile *vf)
335 case FILEVIEW_LIST: ret = vflist_pop_menu_file_list(vf); break;
336 case FILEVIEW_ICON: ret = vficon_pop_menu_file_list(vf); break;
337 default: ret = nullptr;
343 GList *vf_selection_get_one(ViewFile *vf, FileData *fd)
349 case FILEVIEW_LIST: ret = vflist_selection_get_one(vf, fd); break;
350 case FILEVIEW_ICON: ret = vficon_selection_get_one(vf, fd); break;
351 default: ret = nullptr;
357 static void vf_pop_menu_edit_cb(GtkWidget *widget, gpointer data)
360 auto key = static_cast<const gchar *>(data);
362 vf = static_cast<ViewFile *>(submenu_item_get_data(widget));
366 file_util_start_editor_from_filelist(key, vf_pop_menu_file_list(vf), vf->dir_fd->path, vf->listview);
369 static void vf_pop_menu_view_cb(GtkWidget *, gpointer data)
371 auto vf = static_cast<ViewFile *>(data);
375 case FILEVIEW_LIST: vflist_pop_menu_view_cb(vf); break;
376 case FILEVIEW_ICON: vficon_pop_menu_view_cb(vf); break;
380 static void vf_pop_menu_open_archive_cb(GtkWidget *, gpointer data)
382 auto vf = static_cast<ViewFile *>(data);
383 LayoutWindow *lw_new;
386 dest_dir = open_archive(vf->click_fd);
389 lw_new = layout_new_from_default();
390 layout_set_path(lw_new, dest_dir);
395 warning_dialog(_("Cannot open archive file"), _("See the Log Window"), GQ_ICON_DIALOG_WARNING, nullptr);
399 static void vf_pop_menu_copy_cb(GtkWidget *, gpointer data)
401 auto vf = static_cast<ViewFile *>(data);
403 file_util_copy(nullptr, vf_pop_menu_file_list(vf), nullptr, vf->listview);
406 static void vf_pop_menu_move_cb(GtkWidget *, gpointer data)
408 auto vf = static_cast<ViewFile *>(data);
410 file_util_move(nullptr, vf_pop_menu_file_list(vf), nullptr, vf->listview);
413 static void vf_pop_menu_rename_cb(GtkWidget *, gpointer data)
415 auto vf = static_cast<ViewFile *>(data);
419 case FILEVIEW_LIST: vflist_pop_menu_rename_cb(vf); break;
420 case FILEVIEW_ICON: vficon_pop_menu_rename_cb(vf); break;
424 static void vf_pop_menu_delete_cb(GtkWidget *, gpointer data)
426 auto vf = static_cast<ViewFile *>(data);
428 options->file_ops.safe_delete_enable = FALSE;
429 file_util_delete(nullptr, vf_pop_menu_file_list(vf), vf->listview);
432 static void vf_pop_menu_move_to_trash_cb(GtkWidget *, gpointer data)
434 auto vf = static_cast<ViewFile *>(data);
436 options->file_ops.safe_delete_enable = TRUE;
437 file_util_delete(nullptr, vf_pop_menu_file_list(vf), vf->listview);
440 static void vf_pop_menu_copy_path_cb(GtkWidget *, gpointer data)
442 auto vf = static_cast<ViewFile *>(data);
444 file_util_path_list_to_clipboard(vf_pop_menu_file_list(vf), TRUE, TRUE);
447 static void vf_pop_menu_copy_path_unquoted_cb(GtkWidget *, gpointer data)
449 auto vf = static_cast<ViewFile *>(data);
451 file_util_path_list_to_clipboard(vf_pop_menu_file_list(vf), FALSE, TRUE);
454 static void vf_pop_menu_cut_path_cb(GtkWidget *, gpointer data)
456 auto vf = static_cast<ViewFile *>(data);
458 file_util_path_list_to_clipboard(vf_pop_menu_file_list(vf), FALSE, FALSE);
461 static void vf_pop_menu_enable_grouping_cb(GtkWidget *, gpointer data)
463 auto vf = static_cast<ViewFile *>(data);
465 file_data_disable_grouping_list(vf_pop_menu_file_list(vf), FALSE);
468 static void vf_pop_menu_duplicates_cb(GtkWidget *, gpointer data)
470 auto vf = static_cast<ViewFile *>(data);
473 dw = dupe_window_new();
474 dupe_window_add_files(dw, vf_pop_menu_file_list(vf), FALSE);
477 static void vf_pop_menu_disable_grouping_cb(GtkWidget *, gpointer data)
479 auto vf = static_cast<ViewFile *>(data);
481 file_data_disable_grouping_list(vf_pop_menu_file_list(vf), TRUE);
484 static void vf_pop_menu_sort_cb(GtkWidget *widget, gpointer data)
489 if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))) return;
491 vf = static_cast<ViewFile *>(submenu_item_get_data(widget));
494 type = static_cast<SortType>GPOINTER_TO_INT(data);
496 if (type == SORT_EXIFTIME || type == SORT_EXIFTIMEDIGITIZED || type == SORT_RATING)
498 vf_read_metadata_in_idle(vf);
503 layout_sort_set_files(vf->layout, type, vf->sort_ascend, vf->sort_case);
507 vf_sort_set(vf, type, vf->sort_ascend, vf->sort_case);
511 static void vf_pop_menu_sort_ascend_cb(GtkWidget *, gpointer data)
513 auto vf = static_cast<ViewFile *>(data);
517 layout_sort_set_files(vf->layout, vf->sort_method, !vf->sort_ascend, vf->sort_case);
521 vf_sort_set(vf, vf->sort_method, !vf->sort_ascend, vf->sort_case);
525 static void vf_pop_menu_sort_case_cb(GtkWidget *, gpointer data)
527 auto vf = static_cast<ViewFile *>(data);
531 layout_sort_set_files(vf->layout, vf->sort_method, vf->sort_ascend, !vf->sort_case);
535 vf_sort_set(vf, vf->sort_method, vf->sort_ascend, !vf->sort_case);
539 static void vf_pop_menu_sel_mark_cb(GtkWidget *, gpointer data)
541 auto vf = static_cast<ViewFile *>(data);
542 vf_mark_to_selection(vf, vf->active_mark, MTS_MODE_SET);
545 static void vf_pop_menu_sel_mark_and_cb(GtkWidget *, gpointer data)
547 auto vf = static_cast<ViewFile *>(data);
548 vf_mark_to_selection(vf, vf->active_mark, MTS_MODE_AND);
551 static void vf_pop_menu_sel_mark_or_cb(GtkWidget *, gpointer data)
553 auto vf = static_cast<ViewFile *>(data);
554 vf_mark_to_selection(vf, vf->active_mark, MTS_MODE_OR);
557 static void vf_pop_menu_sel_mark_minus_cb(GtkWidget *, gpointer data)
559 auto vf = static_cast<ViewFile *>(data);
560 vf_mark_to_selection(vf, vf->active_mark, MTS_MODE_MINUS);
563 static void vf_pop_menu_set_mark_sel_cb(GtkWidget *, gpointer data)
565 auto vf = static_cast<ViewFile *>(data);
566 vf_selection_to_mark(vf, vf->active_mark, STM_MODE_SET);
569 static void vf_pop_menu_res_mark_sel_cb(GtkWidget *, gpointer data)
571 auto vf = static_cast<ViewFile *>(data);
572 vf_selection_to_mark(vf, vf->active_mark, STM_MODE_RESET);
575 static void vf_pop_menu_toggle_mark_sel_cb(GtkWidget *, gpointer data)
577 auto vf = static_cast<ViewFile *>(data);
578 vf_selection_to_mark(vf, vf->active_mark, STM_MODE_TOGGLE);
581 static void vf_pop_menu_toggle_view_type_cb(GtkWidget *widget, gpointer data)
583 auto vf = static_cast<ViewFile *>(data);
584 auto new_type = static_cast<FileViewType>(GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "menu_item_radio_data")));
585 if (!vf->layout) return;
587 layout_views_set(vf->layout, vf->layout->options.dir_view_type, new_type);
590 static void vf_pop_menu_refresh_cb(GtkWidget *, gpointer data)
592 auto vf = static_cast<ViewFile *>(data);
596 case FILEVIEW_LIST: vflist_pop_menu_refresh_cb(vf); break;
597 case FILEVIEW_ICON: vficon_pop_menu_refresh_cb(vf); break;
601 static void vf_popup_destroy_cb(GtkWidget *, gpointer data)
603 auto vf = static_cast<ViewFile *>(data);
607 case FILEVIEW_LIST: vflist_popup_destroy_cb(vf); break;
608 case FILEVIEW_ICON: vficon_popup_destroy_cb(vf); break;
611 vf->click_fd = nullptr;
614 filelist_free(vf->editmenu_fd_list);
615 vf->editmenu_fd_list = nullptr;
619 * @brief Add file selection list to a collection
621 * @param[in] data Index to the collection list menu item selected, or -1 for new collection
625 static void vf_pop_menu_collections_cb(GtkWidget *widget, gpointer data)
628 GList *selection_list;
630 vf = static_cast<ViewFile *>(submenu_item_get_data(widget));
631 selection_list = vf_selection_get_list(vf);
632 pop_menu_collections(selection_list, data);
634 filelist_free(selection_list);
637 static void vf_pop_menu_show_star_rating_cb(GtkWidget *, gpointer data)
639 auto *vf = static_cast<ViewFile *>(data);
641 options->show_star_rating = !options->show_star_rating;
645 case FILEVIEW_LIST: vflist_pop_menu_show_star_rating_cb(vf); break;
646 case FILEVIEW_ICON: vficon_pop_menu_show_star_rating_cb(vf); break;
650 GtkWidget *vf_pop_menu(ViewFile *vf)
655 gboolean active = FALSE;
656 gboolean class_archive = FALSE;
657 GtkAccelGroup *accel_group;
659 if (vf->type == FILEVIEW_LIST)
661 vflist_color_set(vf, vf->click_fd, TRUE);
664 active = (vf->click_fd != nullptr);
665 class_archive = (vf->click_fd != nullptr && vf->click_fd->format_class == FORMAT_CLASS_ARCHIVE);
667 menu = popup_menu_short_lived();
669 accel_group = gtk_accel_group_new();
670 gtk_menu_set_accel_group(GTK_MENU(menu), accel_group);
672 g_object_set_data(G_OBJECT(menu), "window_keys", nullptr);
673 g_object_set_data(G_OBJECT(menu), "accel_group", accel_group);
675 g_signal_connect(G_OBJECT(menu), "destroy",
676 G_CALLBACK(vf_popup_destroy_cb), vf);
678 if (vf->clicked_mark > 0)
680 gint mark = vf->clicked_mark;
681 gchar *str_set_mark = g_strdup_printf(_("_Set mark %d"), mark);
682 gchar *str_res_mark = g_strdup_printf(_("_Reset mark %d"), mark);
683 gchar *str_toggle_mark = g_strdup_printf(_("_Toggle mark %d"), mark);
684 gchar *str_sel_mark = g_strdup_printf(_("_Select mark %d"), mark);
685 gchar *str_sel_mark_or = g_strdup_printf(_("_Add mark %d"), mark);
686 gchar *str_sel_mark_and = g_strdup_printf(_("_Intersection with mark %d"), mark);
687 gchar *str_sel_mark_minus = g_strdup_printf(_("_Unselect mark %d"), mark);
689 g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
691 vf->active_mark = mark;
692 vf->clicked_mark = 0;
694 menu_item_add_sensitive(menu, str_set_mark, active,
695 G_CALLBACK(vf_pop_menu_set_mark_sel_cb), vf);
697 menu_item_add_sensitive(menu, str_res_mark, active,
698 G_CALLBACK(vf_pop_menu_res_mark_sel_cb), vf);
700 menu_item_add_sensitive(menu, str_toggle_mark, active,
701 G_CALLBACK(vf_pop_menu_toggle_mark_sel_cb), vf);
703 menu_item_add_divider(menu);
705 menu_item_add_sensitive(menu, str_sel_mark, active,
706 G_CALLBACK(vf_pop_menu_sel_mark_cb), vf);
707 menu_item_add_sensitive(menu, str_sel_mark_or, active,
708 G_CALLBACK(vf_pop_menu_sel_mark_or_cb), vf);
709 menu_item_add_sensitive(menu, str_sel_mark_and, active,
710 G_CALLBACK(vf_pop_menu_sel_mark_and_cb), vf);
711 menu_item_add_sensitive(menu, str_sel_mark_minus, active,
712 G_CALLBACK(vf_pop_menu_sel_mark_minus_cb), vf);
714 menu_item_add_divider(menu);
716 g_free(str_set_mark);
717 g_free(str_res_mark);
718 g_free(str_toggle_mark);
719 g_free(str_sel_mark);
720 g_free(str_sel_mark_and);
721 g_free(str_sel_mark_or);
722 g_free(str_sel_mark_minus);
725 vf->editmenu_fd_list = vf_pop_menu_file_list(vf);
726 submenu_add_edit(menu, &item, G_CALLBACK(vf_pop_menu_edit_cb), vf, vf->editmenu_fd_list);
727 gtk_widget_set_sensitive(item, active);
729 menu_item_add_icon_sensitive(menu, _("View in _new window"), GQ_ICON_NEW, active,
730 G_CALLBACK(vf_pop_menu_view_cb), vf);
732 menu_item_add_icon_sensitive(menu, _("Open archive"), GQ_ICON_OPEN, active & class_archive, G_CALLBACK(vf_pop_menu_open_archive_cb), vf);
734 menu_item_add_divider(menu);
735 menu_item_add_icon_sensitive(menu, _("_Copy..."), GQ_ICON_COPY, active,
736 G_CALLBACK(vf_pop_menu_copy_cb), vf);
737 menu_item_add_sensitive(menu, _("_Move..."), active,
738 G_CALLBACK(vf_pop_menu_move_cb), vf);
739 menu_item_add_sensitive(menu, _("_Rename..."), active,
740 G_CALLBACK(vf_pop_menu_rename_cb), vf);
741 menu_item_add_sensitive(menu, _("_Copy to clipboard"), active,
742 G_CALLBACK(vf_pop_menu_copy_path_cb), vf);
743 menu_item_add_sensitive(menu, _("_Copy to clipboard (unquoted)"), active,
744 G_CALLBACK(vf_pop_menu_copy_path_unquoted_cb), vf);
745 menu_item_add_sensitive(menu, _("_Cut to clipboard"), active,
746 G_CALLBACK(vf_pop_menu_cut_path_cb), vf);
747 menu_item_add_divider(menu);
748 menu_item_add_icon_sensitive(menu,
749 options->file_ops.confirm_move_to_trash ? _("Move to Trash...") :
750 _("Move to Trash"), GQ_ICON_DELETE, active,
751 G_CALLBACK(vf_pop_menu_move_to_trash_cb), vf);
752 menu_item_add_icon_sensitive(menu,
753 options->file_ops.confirm_delete ? _("_Delete...") :
754 _("_Delete"), GQ_ICON_DELETE_SHRED, active,
755 G_CALLBACK(vf_pop_menu_delete_cb), vf);
756 menu_item_add_divider(menu);
758 menu_item_add_sensitive(menu, _("Enable file _grouping"), active,
759 G_CALLBACK(vf_pop_menu_enable_grouping_cb), vf);
760 menu_item_add_sensitive(menu, _("Disable file groupi_ng"), active,
761 G_CALLBACK(vf_pop_menu_disable_grouping_cb), vf);
763 menu_item_add_divider(menu);
764 menu_item_add_icon_sensitive(menu, _("_Find duplicates..."), GQ_ICON_FIND, active,
765 G_CALLBACK(vf_pop_menu_duplicates_cb), vf);
766 menu_item_add_divider(menu);
768 submenu = submenu_add_collections(menu, &item,
769 G_CALLBACK(vf_pop_menu_collections_cb), vf);
770 gtk_widget_set_sensitive(item, active);
771 menu_item_add_divider(menu);
773 submenu = submenu_add_sort(nullptr, G_CALLBACK(vf_pop_menu_sort_cb), vf,
774 FALSE, FALSE, TRUE, vf->sort_method);
775 menu_item_add_divider(submenu);
776 menu_item_add_check(submenu, _("Ascending"), vf->sort_ascend,
777 G_CALLBACK(vf_pop_menu_sort_ascend_cb), vf);
778 menu_item_add_check(submenu, _("Case"), vf->sort_ascend,
779 G_CALLBACK(vf_pop_menu_sort_case_cb), vf);
781 item = menu_item_add(menu, _("_Sort"), nullptr, nullptr);
782 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
784 item = menu_item_add_radio(menu, _("Images as List"), GINT_TO_POINTER(FILEVIEW_LIST), vf->type == FILEVIEW_LIST,
785 G_CALLBACK(vf_pop_menu_toggle_view_type_cb), vf);
787 item = menu_item_add_radio(menu, _("Images as Icons"), GINT_TO_POINTER(FILEVIEW_ICON), vf->type == FILEVIEW_ICON,
788 G_CALLBACK(vf_pop_menu_toggle_view_type_cb), vf);
792 case FILEVIEW_LIST: vflist_pop_menu_add_items(vf, menu); break;
793 case FILEVIEW_ICON: vficon_pop_menu_add_items(vf, menu); break;
796 menu_item_add_check(menu, _("Show star rating"), options->show_star_rating,
797 G_CALLBACK(vf_pop_menu_show_star_rating_cb), vf);
799 menu_item_add_icon(menu, _("Re_fresh"), GQ_ICON_REFRESH, G_CALLBACK(vf_pop_menu_refresh_cb), vf);
804 gboolean vf_refresh(ViewFile *vf)
810 case FILEVIEW_LIST: ret = vflist_refresh(vf); break;
811 case FILEVIEW_ICON: ret = vficon_refresh(vf); break;
812 default: ret = FALSE;
818 gboolean vf_set_fd(ViewFile *vf, FileData *dir_fd)
824 case FILEVIEW_LIST: ret = vflist_set_fd(vf, dir_fd); break;
825 case FILEVIEW_ICON: ret = vficon_set_fd(vf, dir_fd); break;
826 default: ret = FALSE;
832 static void vf_destroy_cb(GtkWidget *, gpointer data)
834 auto vf = static_cast<ViewFile *>(data);
838 case FILEVIEW_LIST: vflist_destroy_cb(vf); break;
839 case FILEVIEW_ICON: vficon_destroy_cb(vf); break;
844 g_signal_handlers_disconnect_matched(G_OBJECT(vf->popup), G_SIGNAL_MATCH_DATA,
845 0, 0, nullptr, nullptr, vf);
846 gq_gtk_widget_destroy(vf->popup);
849 if (vf->read_metadata_in_idle_id)
851 g_idle_remove_by_data(vf);
853 file_data_unref(vf->dir_fd);
858 static void vf_marks_filter_toggle_cb(GtkWidget *, gpointer data)
860 auto vf = static_cast<ViewFile *>(data);
864 struct MarksTextEntry {
867 GtkWidget *edit_widget;
872 static void vf_marks_tooltip_cancel_cb(GenericDialog *gd, gpointer data)
874 auto mte = static_cast<MarksTextEntry *>(data);
876 g_free(mte->text_entry);
877 generic_dialog_close(gd);
880 static void vf_marks_tooltip_ok_cb(GenericDialog *gd, gpointer data)
882 auto mte = static_cast<MarksTextEntry *>(data);
884 g_free(options->marks_tooltips[mte->mark_no]);
885 options->marks_tooltips[mte->mark_no] = g_strdup(gq_gtk_entry_get_text(GTK_ENTRY(mte->edit_widget)));
887 gtk_widget_set_tooltip_text(mte->parent, options->marks_tooltips[mte->mark_no]);
889 g_free(mte->text_entry);
890 generic_dialog_close(gd);
893 void vf_marks_filter_on_icon_press(GtkEntry *, GtkEntryIconPosition, GdkEvent *, gpointer userdata)
895 auto mte = static_cast<MarksTextEntry *>(userdata);
897 g_free(mte->text_entry);
898 mte->text_entry = g_strdup("");
899 gq_gtk_entry_set_text(GTK_ENTRY(mte->edit_widget), "");
902 static void vf_marks_tooltip_help_cb(GenericDialog *, gpointer)
904 help_window_show("GuideImageMarks.html");
907 static gboolean vf_marks_tooltip_cb(GtkWidget *widget,
908 GdkEventButton *event,
912 gint i = GPOINTER_TO_INT(user_data);
914 if (event->button != MOUSE_BUTTON_RIGHT)
917 auto mte = g_new0(MarksTextEntry, 1);
919 mte->text_entry = g_strdup(options->marks_tooltips[i]);
920 mte->parent = widget;
922 mte->gd = generic_dialog_new(_("Mark text"), "mark_text",
924 vf_marks_tooltip_cancel_cb, mte);
925 generic_dialog_add_message(mte->gd, GQ_ICON_DIALOG_QUESTION, _("Set mark text"),
926 _("This will set or clear the mark text."), FALSE);
927 generic_dialog_add_button(mte->gd, GQ_ICON_OK, "OK",
928 vf_marks_tooltip_ok_cb, TRUE);
929 generic_dialog_add_button(mte->gd, GQ_ICON_HELP, _("Help"),
930 vf_marks_tooltip_help_cb, FALSE);
932 table = pref_table_new(mte->gd->vbox, 3, 1, FALSE, TRUE);
933 pref_table_label(table, 0, 0, g_strdup_printf("%s%d", _("Mark "), mte->mark_no + 1), GTK_ALIGN_END);
934 mte->edit_widget = gtk_entry_new();
935 gtk_widget_set_size_request(mte->edit_widget, 300, -1);
938 gq_gtk_entry_set_text(GTK_ENTRY(mte->edit_widget), mte->text_entry);
940 gq_gtk_grid_attach_default(GTK_GRID(table), mte->edit_widget, 1, 2, 0, 1);
941 generic_dialog_attach_default(mte->gd, mte->edit_widget);
943 gtk_entry_set_icon_from_icon_name(GTK_ENTRY(mte->edit_widget),
944 GTK_ENTRY_ICON_SECONDARY, GQ_ICON_CLEAR);
945 gtk_entry_set_icon_tooltip_text(GTK_ENTRY(mte->edit_widget),
946 GTK_ENTRY_ICON_SECONDARY, _("Clear"));
947 g_signal_connect(GTK_ENTRY(mte->edit_widget), "icon-press",
948 G_CALLBACK(vf_marks_filter_on_icon_press), mte);
950 gtk_widget_show(mte->edit_widget);
951 gtk_widget_grab_focus(mte->edit_widget);
952 gtk_widget_show(GTK_WIDGET(mte->gd->dialog));
957 static void vf_file_filter_save_cb(GtkWidget *, gpointer data)
959 auto vf = static_cast<ViewFile *>(data);
961 gchar *remove_text = nullptr;
962 gchar *index_text = nullptr;
963 gboolean text_found = FALSE;
966 entry_text = g_strdup(gq_gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(vf->file_filter.combo)))));
968 if (entry_text[0] == '\0' && vf->file_filter.last_selected >= 0)
970 gtk_combo_box_set_active(GTK_COMBO_BOX(vf->file_filter.combo), vf->file_filter.last_selected);
971 remove_text = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(vf->file_filter.combo));
972 history_list_item_remove("file_filter", remove_text);
973 gtk_combo_box_text_remove(GTK_COMBO_BOX_TEXT(vf->file_filter.combo), vf->file_filter.last_selected);
976 gtk_combo_box_set_active(GTK_COMBO_BOX(vf->file_filter.combo), -1);
977 vf->file_filter.last_selected = - 1;
978 gq_gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(vf->file_filter.combo))), "");
979 vf->file_filter.count--;
983 if (entry_text[0] != '\0')
985 for (i = 0; i < vf->file_filter.count; i++)
991 gtk_combo_box_set_active(GTK_COMBO_BOX(vf->file_filter.combo), i);
992 index_text = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(vf->file_filter.combo));
994 if (g_strcmp0(index_text, entry_text) == 0)
1004 history_list_add_to_key("file_filter", entry_text, 10);
1005 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(vf->file_filter.combo), entry_text);
1006 vf->file_filter.count++;
1007 gtk_combo_box_set_active(GTK_COMBO_BOX(vf->file_filter.combo), vf->file_filter.count - 1);
1016 static void vf_file_filter_cb(GtkWidget *, gpointer data)
1018 auto vf = static_cast<ViewFile *>(data);
1023 static gboolean vf_file_filter_press_cb(GtkWidget *widget, GdkEventButton *, gpointer data)
1025 auto vf = static_cast<ViewFile *>(data);
1026 vf->file_filter.last_selected = gtk_combo_box_get_active(GTK_COMBO_BOX(vf->file_filter.combo));
1028 gtk_widget_grab_focus(widget);
1033 static GtkWidget *vf_marks_filter_init(ViewFile *vf)
1035 GtkWidget *frame = gtk_frame_new(nullptr);
1036 GtkWidget *hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
1040 for (i = 0; i < FILEDATA_MARKS_SIZE ; i++)
1042 GtkWidget *check = gtk_check_button_new();
1043 gq_gtk_box_pack_start(GTK_BOX(hbox), check, FALSE, FALSE, 0);
1044 g_signal_connect(G_OBJECT(check), "toggled",
1045 G_CALLBACK(vf_marks_filter_toggle_cb), vf);
1046 g_signal_connect(G_OBJECT(check), "button_press_event",
1047 G_CALLBACK(vf_marks_tooltip_cb), GINT_TO_POINTER(i));
1048 gtk_widget_set_tooltip_text(check, options->marks_tooltips[i]);
1050 gtk_widget_show(check);
1051 vf->filter_check[i] = check;
1053 gq_gtk_container_add(GTK_WIDGET(frame), hbox);
1054 gtk_widget_show(hbox);
1058 void vf_file_filter_set(ViewFile *vf, gboolean enable)
1062 gtk_widget_show(vf->file_filter.combo);
1063 gtk_widget_show(vf->file_filter.frame);
1067 gtk_widget_hide(vf->file_filter.combo);
1068 gtk_widget_hide(vf->file_filter.frame);
1074 static gboolean vf_file_filter_class_cb(GtkWidget *widget, gpointer data)
1076 auto vf = static_cast<ViewFile *>(data);
1079 gboolean state = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget));
1081 for (i = 0; i < FILE_FORMAT_CLASSES; i++)
1083 if (g_strcmp0(format_class_list[i], gtk_menu_item_get_label(GTK_MENU_ITEM(widget))) == 0)
1085 options->class_filter[i] = state;
1093 static gboolean vf_file_filter_class_set_all_cb(GtkWidget *widget, gpointer data)
1095 auto vf = static_cast<ViewFile *>(data);
1102 if (g_strcmp0(_("Select all"), gtk_menu_item_get_label(GTK_MENU_ITEM(widget))) == 0)
1111 for (i = 0; i < FILE_FORMAT_CLASSES; i++)
1113 options->class_filter[i] = state;
1117 parent = gtk_widget_get_parent(widget);
1118 children = gtk_container_get_children(GTK_CONTAINER(parent));
1121 child = static_cast<GtkWidget *>(children->data);
1122 if (i < FILE_FORMAT_CLASSES)
1124 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(child), state);
1127 children = children->next;
1129 g_list_free(children);
1135 static GtkWidget *class_filter_menu (ViewFile *vf)
1138 GtkWidget *menu_item;
1141 menu = gtk_menu_new();
1143 for (i = 0; i < FILE_FORMAT_CLASSES; i++)
1145 menu_item = gtk_check_menu_item_new_with_label(format_class_list[i]);
1146 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu_item), options->class_filter[i]);
1147 g_signal_connect(G_OBJECT(menu_item), "toggled", G_CALLBACK(vf_file_filter_class_cb), vf);
1148 gtk_menu_shell_append(GTK_MENU_SHELL (menu), menu_item);
1149 gtk_widget_show(menu_item);
1152 menu_item = gtk_menu_item_new_with_label(_("Select all"));
1153 gtk_menu_shell_append(GTK_MENU_SHELL (menu), menu_item);
1154 gtk_widget_show(menu_item);
1155 g_signal_connect(G_OBJECT(menu_item), "activate", G_CALLBACK(vf_file_filter_class_set_all_cb), vf);
1157 menu_item = gtk_menu_item_new_with_label(_("Select none"));
1158 gtk_menu_shell_append(GTK_MENU_SHELL (menu), menu_item);
1159 gtk_widget_show(menu_item);
1160 g_signal_connect(G_OBJECT(menu_item), "activate", G_CALLBACK(vf_file_filter_class_set_all_cb), vf);
1165 static void case_sensitive_cb(GtkWidget *widget, gpointer data)
1167 auto vf = static_cast<ViewFile *>(data);
1169 vf->file_filter.case_sensitive = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1173 static void file_filter_clear_cb(GtkEntry *, GtkEntryIconPosition pos, GdkEvent *, gpointer userdata)
1175 if (pos == GTK_ENTRY_ICON_SECONDARY)
1177 gq_gtk_entry_set_text(GTK_ENTRY(userdata), "");
1178 gtk_widget_grab_focus(GTK_WIDGET(userdata));
1182 static GtkWidget *vf_file_filter_init(ViewFile *vf)
1184 GtkWidget *frame = gtk_frame_new(nullptr);
1185 GtkWidget *hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
1188 GtkWidget *combo_entry;
1190 GtkWidget *menuitem;
1191 GtkWidget *case_sensitive;
1196 vf->file_filter.combo = gtk_combo_box_text_new_with_entry();
1197 combo_entry = gtk_bin_get_child(GTK_BIN(vf->file_filter.combo));
1198 gtk_widget_show(gtk_bin_get_child(GTK_BIN(vf->file_filter.combo)));
1199 gtk_widget_show((GTK_WIDGET(vf->file_filter.combo)));
1200 gtk_widget_set_tooltip_text(GTK_WIDGET(vf->file_filter.combo), _("Use regular expressions"));
1202 gtk_entry_set_icon_from_icon_name(GTK_ENTRY(combo_entry), GTK_ENTRY_ICON_SECONDARY, GQ_ICON_CLEAR);
1203 gtk_entry_set_icon_tooltip_text (GTK_ENTRY(combo_entry), GTK_ENTRY_ICON_SECONDARY, _("Clear"));
1204 g_signal_connect(GTK_ENTRY(combo_entry), "icon-press", G_CALLBACK(file_filter_clear_cb), combo_entry);
1206 work = history_list_get_by_key("file_filter");
1209 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(vf->file_filter.combo), static_cast<gchar *>(work->data));
1212 vf->file_filter.count = n;
1214 gtk_combo_box_set_active(GTK_COMBO_BOX(vf->file_filter.combo), 0);
1216 g_signal_connect(G_OBJECT(combo_entry), "activate",
1217 G_CALLBACK(vf_file_filter_save_cb), vf);
1219 g_signal_connect(G_OBJECT(vf->file_filter.combo), "changed",
1220 G_CALLBACK(vf_file_filter_cb), vf);
1222 g_signal_connect(G_OBJECT(combo_entry), "button_press_event",
1223 G_CALLBACK(vf_file_filter_press_cb), vf);
1225 gq_gtk_box_pack_start(GTK_BOX(hbox), vf->file_filter.combo, FALSE, FALSE, 0);
1226 gtk_widget_show(vf->file_filter.combo);
1227 gq_gtk_container_add(GTK_WIDGET(frame), hbox);
1228 gtk_widget_show(hbox);
1230 case_sensitive = gtk_check_button_new_with_label(_("Case"));
1231 gq_gtk_box_pack_start(GTK_BOX(hbox), case_sensitive, FALSE, FALSE, 0);
1232 gtk_widget_set_tooltip_text(GTK_WIDGET(case_sensitive), _("Case sensitive"));
1233 g_signal_connect(G_OBJECT(case_sensitive), "clicked", G_CALLBACK(case_sensitive_cb), vf);
1234 gtk_widget_show(case_sensitive);
1236 menubar = gtk_menu_bar_new();
1237 gq_gtk_box_pack_start(GTK_BOX(hbox), menubar, FALSE, TRUE, 0);
1238 gtk_widget_show(menubar);
1240 box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, PREF_PAD_GAP);
1241 icon = gtk_image_new_from_icon_name(GQ_ICON_PAN_DOWN, GTK_ICON_SIZE_MENU);
1242 label = gtk_label_new(_("Class"));
1244 gq_gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 0);
1245 gq_gtk_box_pack_end(GTK_BOX(box), icon, FALSE, FALSE, 0);
1247 menuitem = gtk_menu_item_new();
1249 gtk_widget_set_tooltip_text(GTK_WIDGET(menuitem), _("Select Class filter"));
1250 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), class_filter_menu(vf));
1251 gtk_menu_shell_append(GTK_MENU_SHELL(menubar), menuitem);
1252 gq_gtk_container_add(GTK_WIDGET(menuitem), box);
1253 gq_gtk_widget_show_all(menuitem);
1258 void vf_mark_filter_toggle(ViewFile *vf, gint mark)
1261 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(vf->filter_check[n]),
1262 !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(vf->filter_check[n])));
1265 ViewFile *vf_new(FileViewType type, FileData *dir_fd)
1269 vf = g_new0(ViewFile, 1);
1272 vf->sort_method = SORT_NAME;
1273 vf->sort_ascend = TRUE;
1274 vf->read_metadata_in_idle_id = 0;
1276 vf->scrolled = gq_gtk_scrolled_window_new(nullptr, nullptr);
1277 gq_gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(vf->scrolled), GTK_SHADOW_IN);
1278 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(vf->scrolled),
1279 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1281 vf->filter = vf_marks_filter_init(vf);
1282 vf->file_filter.frame = vf_file_filter_init(vf);
1284 vf->widget = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
1285 gq_gtk_box_pack_start(GTK_BOX(vf->widget), vf->filter, FALSE, FALSE, 0);
1286 gq_gtk_box_pack_start(GTK_BOX(vf->widget), vf->file_filter.frame, FALSE, FALSE, 0);
1287 gq_gtk_box_pack_start(GTK_BOX(vf->widget), vf->scrolled, TRUE, TRUE, 0);
1288 gtk_widget_show(vf->scrolled);
1290 g_signal_connect(G_OBJECT(vf->widget), "destroy",
1291 G_CALLBACK(vf_destroy_cb), vf);
1295 case FILEVIEW_LIST: vf = vflist_new(vf); break;
1296 case FILEVIEW_ICON: vf = vficon_new(vf); break;
1301 g_signal_connect(G_OBJECT(vf->listview), "key_press_event",
1302 G_CALLBACK(vf_press_key_cb), vf);
1303 g_signal_connect(G_OBJECT(vf->listview), "button_press_event",
1304 G_CALLBACK(vf_press_cb), vf);
1305 g_signal_connect(G_OBJECT(vf->listview), "button_release_event",
1306 G_CALLBACK(vf_release_cb), vf);
1308 gq_gtk_container_add(GTK_WIDGET(vf->scrolled), vf->listview);
1309 gtk_widget_show(vf->listview);
1311 if (dir_fd) vf_set_fd(vf, dir_fd);
1316 void vf_set_status_func(ViewFile *vf, void (*func)(ViewFile *vf, gpointer data), gpointer data)
1318 vf->func_status = func;
1319 vf->data_status = data;
1322 void vf_set_thumb_status_func(ViewFile *vf, void (*func)(ViewFile *vf, gdouble val, const gchar *text, gpointer data), gpointer data)
1324 vf->func_thumb_status = func;
1325 vf->data_thumb_status = data;
1328 void vf_thumb_set(ViewFile *vf, gboolean enable)
1332 case FILEVIEW_LIST: vflist_thumb_set(vf, enable); break;
1333 case FILEVIEW_ICON: /*vficon_thumb_set(vf, enable);*/ break;
1338 static gboolean vf_thumb_next(ViewFile *vf);
1340 static gdouble vf_thumb_progress(ViewFile *vf)
1347 case FILEVIEW_LIST: vflist_thumb_progress_count(vf->list, count, done); break;
1348 case FILEVIEW_ICON: vficon_thumb_progress_count(vf->list, count, done); break;
1351 DEBUG_1("thumb progress: %d of %d", done, count);
1352 return static_cast<gdouble>(done) / count;
1355 static gdouble vf_read_metadata_in_idle_progress(ViewFile *vf)
1362 case FILEVIEW_LIST: vflist_read_metadata_progress_count(vf->list, count, done); break;
1363 case FILEVIEW_ICON: vficon_read_metadata_progress_count(vf->list, count, done); break;
1366 return static_cast<gdouble>(done) / count;
1369 static void vf_set_thumb_fd(ViewFile *vf, FileData *fd)
1373 case FILEVIEW_LIST: vflist_set_thumb_fd(vf, fd); break;
1374 case FILEVIEW_ICON: vficon_set_thumb_fd(vf, fd); break;
1378 static void vf_thumb_status(ViewFile *vf, gdouble val, const gchar *text)
1380 if (vf->func_thumb_status)
1382 vf->func_thumb_status(vf, val, text, vf->data_thumb_status);
1386 static void vf_thumb_do(ViewFile *vf, FileData *fd)
1390 vf_set_thumb_fd(vf, fd);
1391 vf_thumb_status(vf, vf_thumb_progress(vf), _("Loading thumbs..."));
1394 void vf_thumb_cleanup(ViewFile *vf)
1396 vf_thumb_status(vf, 0.0, nullptr);
1398 vf->thumbs_running = FALSE;
1400 thumb_loader_free(vf->thumbs_loader);
1401 vf->thumbs_loader = nullptr;
1403 vf->thumbs_filedata = nullptr;
1406 void vf_thumb_stop(ViewFile *vf)
1408 if (vf->thumbs_running) vf_thumb_cleanup(vf);
1411 static void vf_thumb_common_cb(ThumbLoader *tl, gpointer data)
1413 auto vf = static_cast<ViewFile *>(data);
1415 if (vf->thumbs_filedata && vf->thumbs_loader == tl)
1417 vf_thumb_do(vf, vf->thumbs_filedata);
1420 while (vf_thumb_next(vf));
1423 static void vf_thumb_error_cb(ThumbLoader *tl, gpointer data)
1425 vf_thumb_common_cb(tl, data);
1428 static void vf_thumb_done_cb(ThumbLoader *tl, gpointer data)
1430 vf_thumb_common_cb(tl, data);
1433 static gboolean vf_thumb_next(ViewFile *vf)
1435 FileData *fd = nullptr;
1437 if (!gtk_widget_get_realized(vf->listview))
1439 vf_thumb_status(vf, 0.0, nullptr);
1445 case FILEVIEW_LIST: fd = vflist_thumb_next_fd(vf); break;
1446 case FILEVIEW_ICON: fd = vficon_thumb_next_fd(vf); break;
1452 vf_thumb_cleanup(vf);
1456 vf->thumbs_filedata = fd;
1458 thumb_loader_free(vf->thumbs_loader);
1460 vf->thumbs_loader = thumb_loader_new(options->thumbnails.max_width, options->thumbnails.max_height);
1461 thumb_loader_set_callbacks(vf->thumbs_loader,
1467 if (!thumb_loader_start(vf->thumbs_loader, fd))
1469 /* set icon to unknown, continue */
1470 DEBUG_1("thumb loader start failed %s", fd->path);
1471 vf_thumb_do(vf, fd);
1479 static void vf_thumb_reset_all(ViewFile *vf)
1483 for (work = vf->list; work; work = work->next)
1485 auto fd = static_cast<FileData *>(work->data);
1486 if (fd->thumb_pixbuf)
1488 g_object_unref(fd->thumb_pixbuf);
1489 fd->thumb_pixbuf = nullptr;
1494 void vf_thumb_update(ViewFile *vf)
1498 if (vf->type == FILEVIEW_LIST && !VFLIST(vf)->thumbs_enabled) return;
1500 vf_thumb_status(vf, 0.0, _("Loading thumbs..."));
1501 vf->thumbs_running = TRUE;
1503 if (thumb_format_changed)
1505 vf_thumb_reset_all(vf);
1506 thumb_format_changed = FALSE;
1509 while (vf_thumb_next(vf));
1512 void vf_star_cleanup(ViewFile *vf)
1514 if (vf->stars_id != 0)
1516 g_source_remove(vf->stars_id);
1520 vf->stars_filedata = nullptr;
1523 void vf_star_stop(ViewFile *vf)
1525 vf_star_cleanup(vf);
1528 static void vf_set_star_fd(ViewFile *vf, FileData *fd)
1532 case FILEVIEW_LIST: vflist_set_star_fd(vf, fd); break;
1533 case FILEVIEW_ICON: vficon_set_star_fd(vf, fd); break;
1538 static void vf_star_do(ViewFile *vf, FileData *fd)
1542 vf_set_star_fd(vf, fd);
1545 static gboolean vf_star_next(ViewFile *vf)
1547 FileData *fd = nullptr;
1551 case FILEVIEW_LIST: fd = vflist_star_next_fd(vf); break;
1552 case FILEVIEW_ICON: fd = vficon_star_next_fd(vf); break;
1559 vf_star_cleanup(vf);
1566 gboolean vf_stars_cb(gpointer data)
1568 auto vf = static_cast<ViewFile *>(data);
1569 FileData *fd = vf->stars_filedata;
1573 read_rating_data(fd);
1577 if (vf_star_next(vf))
1579 return G_SOURCE_CONTINUE;
1582 vf->stars_filedata = nullptr;
1584 return G_SOURCE_REMOVE;
1587 return G_SOURCE_REMOVE;
1590 void vf_star_update(ViewFile *vf)
1594 if (!options->show_star_rating)
1602 void vf_marks_set(ViewFile *vf, gboolean enable)
1604 if (vf->marks_enabled == enable) return;
1606 vf->marks_enabled = enable;
1610 case FILEVIEW_LIST: vflist_marks_set(vf, enable); break;
1611 case FILEVIEW_ICON: vficon_marks_set(vf, enable); break;
1614 gtk_widget_show(vf->filter);
1616 gtk_widget_hide(vf->filter);
1618 vf_refresh_idle(vf);
1620 #pragma GCC diagnostic push
1621 #pragma GCC diagnostic ignored "-Wunused-function"
1622 void vf_star_rating_set_unused(ViewFile *vf, gboolean enable)
1624 if (options->show_star_rating == enable) return;
1625 options->show_star_rating = enable;
1629 case FILEVIEW_LIST: vflist_star_rating_set(vf, enable); break;
1630 case FILEVIEW_ICON: vficon_star_rating_set(vf, enable); break;
1632 vf_refresh_idle(vf);
1634 #pragma GCC diagnostic pop
1636 guint vf_marks_get_filter(ViewFile *vf)
1640 if (!vf->marks_enabled) return 0;
1642 for (i = 0; i < FILEDATA_MARKS_SIZE ; i++)
1644 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(vf->filter_check[i])))
1652 GRegex *vf_file_filter_get_filter(ViewFile *vf)
1654 GRegex *ret = nullptr;
1655 GError *error = nullptr;
1656 gchar *file_filter_text = nullptr;
1658 if (!gtk_widget_get_visible(vf->file_filter.combo))
1660 return g_regex_new("", static_cast<GRegexCompileFlags>(0), static_cast<GRegexMatchFlags>(0), nullptr);
1663 file_filter_text = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(vf->file_filter.combo));
1665 if (file_filter_text[0] != '\0')
1667 ret = g_regex_new(file_filter_text, vf->file_filter.case_sensitive ? static_cast<GRegexCompileFlags>(0) : G_REGEX_CASELESS, static_cast<GRegexMatchFlags>(0), &error);
1670 log_printf("Error: could not compile regular expression %s\n%s\n", file_filter_text, error->message);
1671 g_error_free(error);
1673 ret = g_regex_new("", static_cast<GRegexCompileFlags>(0), static_cast<GRegexMatchFlags>(0), nullptr);
1675 g_free(file_filter_text);
1679 ret = g_regex_new("", static_cast<GRegexCompileFlags>(0), static_cast<GRegexMatchFlags>(0), nullptr);
1685 guint vf_class_get_filter(ViewFile *vf)
1690 if (!gtk_widget_get_visible(vf->file_filter.combo))
1695 for ( i = 0; i < FILE_FORMAT_CLASSES; i++)
1697 if (options->class_filter[i])
1706 void vf_set_layout(ViewFile *vf, LayoutWindow *layout)
1708 vf->layout = layout;
1713 *-----------------------------------------------------------------------------
1714 * maintenance (for rename, move, remove)
1715 *-----------------------------------------------------------------------------
1718 static gboolean vf_refresh_idle_cb(gpointer data)
1720 auto vf = static_cast<ViewFile *>(data);
1723 vf->refresh_idle_id = 0;
1724 return G_SOURCE_REMOVE;
1727 void vf_refresh_idle_cancel(ViewFile *vf)
1729 if (vf->refresh_idle_id)
1731 g_source_remove(vf->refresh_idle_id);
1732 vf->refresh_idle_id = 0;
1737 void vf_refresh_idle(ViewFile *vf)
1739 if (!vf->refresh_idle_id)
1741 vf->time_refresh_set = time(nullptr);
1742 /* file operations run with G_PRIORITY_DEFAULT_IDLE */
1743 vf->refresh_idle_id = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE + 50, vf_refresh_idle_cb, vf, nullptr);
1745 else if (time(nullptr) - vf->time_refresh_set > 1)
1747 /* more than 1 sec since last update - increase priority */
1748 vf_refresh_idle_cancel(vf);
1749 vf->time_refresh_set = time(nullptr);
1750 vf->refresh_idle_id = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE - 50, vf_refresh_idle_cb, vf, nullptr);
1754 void vf_notify_cb(FileData *fd, NotifyType type, gpointer data)
1756 auto vf = static_cast<ViewFile *>(data);
1759 auto interested = static_cast<NotifyType>(NOTIFY_CHANGE | NOTIFY_REREAD | NOTIFY_GROUPING);
1760 if (vf->marks_enabled) interested = static_cast<NotifyType>(interested | NOTIFY_MARKS | NOTIFY_METADATA);
1761 /** @FIXME NOTIFY_METADATA should be checked by the keyword-to-mark functions and converted to NOTIFY_MARKS only if there was a change */
1763 if (!(type & interested) || vf->refresh_idle_id || !vf->dir_fd) return;
1765 refresh = (fd == vf->dir_fd);
1769 gchar *base = remove_level_from_path(fd->path);
1770 refresh = (g_strcmp0(base, vf->dir_fd->path) == 0);
1774 if ((type & NOTIFY_CHANGE) && fd->change)
1776 if (!refresh && fd->change->dest)
1778 gchar *dest_base = remove_level_from_path(fd->change->dest);
1779 refresh = (g_strcmp0(dest_base, vf->dir_fd->path) == 0);
1783 if (!refresh && fd->change->source)
1785 gchar *source_base = remove_level_from_path(fd->change->source);
1786 refresh = (g_strcmp0(source_base, vf->dir_fd->path) == 0);
1787 g_free(source_base);
1793 DEBUG_1("Notify vf: %s %04x", fd->path, type);
1794 vf_refresh_idle(vf);
1798 static gboolean vf_read_metadata_in_idle_cb(gpointer data)
1801 auto vf = static_cast<ViewFile *>(data);
1804 vf_thumb_status(vf, vf_read_metadata_in_idle_progress(vf), _("Loading meta..."));
1810 fd = static_cast<FileData *>(work->data);
1812 if (fd && !fd->metadata_in_idle_loaded)
1816 read_exif_time_data(fd);
1818 if (!fd->exifdate_digitized)
1820 read_exif_time_digitized_data(fd);
1822 if (fd->rating == STAR_RATING_NOT_READ)
1824 read_rating_data(fd);
1826 fd->metadata_in_idle_loaded = TRUE;
1827 return G_SOURCE_CONTINUE;
1832 vf_thumb_status(vf, 0.0, nullptr);
1833 vf->read_metadata_in_idle_id = 0;
1835 return G_SOURCE_REMOVE;
1838 static void vf_read_metadata_in_idle_finished_cb(gpointer data)
1840 auto vf = static_cast<ViewFile *>(data);
1842 vf_thumb_status(vf, 0.0, _("Loading meta..."));
1843 vf->read_metadata_in_idle_id = 0;
1846 void vf_read_metadata_in_idle(ViewFile *vf)
1850 if (vf->read_metadata_in_idle_id)
1852 g_idle_remove_by_data(vf);
1854 vf->read_metadata_in_idle_id = 0;
1858 vf->read_metadata_in_idle_id = g_idle_add_full(G_PRIORITY_LOW, vf_read_metadata_in_idle_cb, vf, vf_read_metadata_in_idle_finished_cb);
1862 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */