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"
25 #include "history-list.h"
29 #include "pixbuf-util.h"
32 #include "ui-fileops.h"
35 #include "view-file/view-file-list.h"
36 #include "view-file/view-file-icon.h"
40 *-----------------------------------------------------------------------------
42 *-----------------------------------------------------------------------------
45 void vf_send_update(ViewFile *vf)
47 if (vf->func_status) vf->func_status(vf, vf->data_status);
51 *-----------------------------------------------------------------------------
53 *-----------------------------------------------------------------------------
56 void vf_sort_set(ViewFile *vf, SortType type, gboolean ascend)
60 case FILEVIEW_LIST: vflist_sort_set(vf, type, ascend); break;
61 case FILEVIEW_ICON: vficon_sort_set(vf, type, ascend); break;
66 *-----------------------------------------------------------------------------
68 *-----------------------------------------------------------------------------
71 FileData *vf_index_get_data(ViewFile *vf, gint row)
73 return static_cast<FileData *>(g_list_nth_data(vf->list, row));
76 gint vf_index_by_fd(ViewFile *vf, FileData *fd)
82 case FILEVIEW_LIST: ret = vflist_index_by_fd(vf, fd); break;
83 case FILEVIEW_ICON: ret = vficon_index_by_fd(vf, fd); break;
90 guint vf_count(ViewFile *vf, gint64 *bytes)
100 FileData *fd = (FileData *)work->data;
109 return g_list_length(vf->list);
112 GList *vf_get_list(ViewFile *vf)
116 for (work = vf->list; work; work = work->next)
118 FileData *fd = (FileData *)work->data;
119 list = g_list_prepend(list, file_data_ref(fd));
122 return g_list_reverse(list);
126 *-------------------------------------------------------------------
128 *-------------------------------------------------------------------
131 static gboolean vf_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
133 ViewFile *vf = (ViewFile *)data;
138 case FILEVIEW_LIST: ret = vflist_press_key_cb(widget, event, data); break;
139 case FILEVIEW_ICON: ret = vficon_press_key_cb(widget, event, data); break;
140 default: ret = FALSE;
147 *-------------------------------------------------------------------
149 *-------------------------------------------------------------------
152 static gboolean vf_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
154 ViewFile *vf = (ViewFile *)data;
159 case FILEVIEW_LIST: ret = vflist_press_cb(widget, bevent, data); break;
160 case FILEVIEW_ICON: ret = vficon_press_cb(widget, bevent, data); break;
161 default: ret = FALSE;
167 static gboolean vf_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
169 ViewFile *vf = (ViewFile *)data;
174 case FILEVIEW_LIST: ret = vflist_release_cb(widget, bevent, data); break;
175 case FILEVIEW_ICON: ret = vficon_release_cb(widget, bevent, data); break;
176 default: ret = FALSE;
184 *-----------------------------------------------------------------------------
186 *-----------------------------------------------------------------------------
189 guint vf_selection_count(ViewFile *vf, gint64 *bytes)
195 case FILEVIEW_LIST: ret = vflist_selection_count(vf, bytes); break;
196 case FILEVIEW_ICON: ret = vficon_selection_count(vf, bytes); break;
203 GList *vf_selection_get_list(ViewFile *vf)
209 case FILEVIEW_LIST: ret = vflist_selection_get_list(vf); break;
210 case FILEVIEW_ICON: ret = vficon_selection_get_list(vf); break;
217 GList *vf_selection_get_list_by_index(ViewFile *vf)
223 case FILEVIEW_LIST: ret = vflist_selection_get_list_by_index(vf); break;
224 case FILEVIEW_ICON: ret = vficon_selection_get_list_by_index(vf); break;
231 void vf_select_all(ViewFile *vf)
235 case FILEVIEW_LIST: vflist_select_all(vf); break;
236 case FILEVIEW_ICON: vficon_select_all(vf); break;
240 void vf_select_none(ViewFile *vf)
244 case FILEVIEW_LIST: vflist_select_none(vf); break;
245 case FILEVIEW_ICON: vficon_select_none(vf); break;
249 void vf_select_invert(ViewFile *vf)
253 case FILEVIEW_LIST: vflist_select_invert(vf); break;
254 case FILEVIEW_ICON: vficon_select_invert(vf); break;
258 void vf_select_by_fd(ViewFile *vf, FileData *fd)
262 case FILEVIEW_LIST: vflist_select_by_fd(vf, fd); break;
263 case FILEVIEW_ICON: vficon_select_by_fd(vf, fd); break;
267 void vf_select_list(ViewFile *vf, GList *list)
271 case FILEVIEW_LIST: vflist_select_list(vf, list); break;
272 case FILEVIEW_ICON: vficon_select_list(vf, list); break;
276 void vf_mark_to_selection(ViewFile *vf, gint mark, MarkToSelectionMode mode)
280 case FILEVIEW_LIST: vflist_mark_to_selection(vf, mark, mode); break;
281 case FILEVIEW_ICON: vficon_mark_to_selection(vf, mark, mode); break;
285 void vf_selection_to_mark(ViewFile *vf, gint mark, SelectionToMarkMode mode)
289 case FILEVIEW_LIST: vflist_selection_to_mark(vf, mark, mode); break;
290 case FILEVIEW_ICON: vficon_selection_to_mark(vf, mark, mode); break;
295 *-----------------------------------------------------------------------------
297 *-----------------------------------------------------------------------------
301 static void vf_dnd_init(ViewFile *vf)
305 case FILEVIEW_LIST: vflist_dnd_init(vf); break;
306 case FILEVIEW_ICON: vficon_dnd_init(vf); break;
311 *-----------------------------------------------------------------------------
313 *-----------------------------------------------------------------------------
316 GList *vf_pop_menu_file_list(ViewFile *vf)
322 case FILEVIEW_LIST: ret = vflist_pop_menu_file_list(vf); break;
323 case FILEVIEW_ICON: ret = vficon_pop_menu_file_list(vf); break;
330 GList *vf_selection_get_one(ViewFile *vf, FileData *fd)
336 case FILEVIEW_LIST: ret = vflist_selection_get_one(vf, fd); break;
337 case FILEVIEW_ICON: ret = vficon_selection_get_one(vf, fd); break;
344 static void vf_pop_menu_edit_cb(GtkWidget *widget, gpointer data)
347 const gchar *key = static_cast<const gchar *>(data);
349 vf = static_cast<ViewFile *>(submenu_item_get_data(widget));
353 file_util_start_editor_from_filelist(key, vf_pop_menu_file_list(vf), vf->dir_fd->path, vf->listview);
356 static void vf_pop_menu_view_cb(GtkWidget *widget, gpointer data)
358 ViewFile *vf = (ViewFile *)data;
362 case FILEVIEW_LIST: vflist_pop_menu_view_cb(widget, data); break;
363 case FILEVIEW_ICON: vficon_pop_menu_view_cb(widget, data); break;
367 static void vf_pop_menu_open_archive_cb(GtkWidget *UNUSED(widget), gpointer data)
369 ViewFile *vf = (ViewFile *)data;
370 LayoutWindow *lw_new;
377 fd = (VFLIST(vf)->click_fd);
380 fd = (VFICON(vf)->click_fd);
384 dest_dir = open_archive(fd);
387 lw_new = layout_new_from_default();
388 layout_set_path(lw_new, dest_dir);
393 warning_dialog(_("Cannot open archive file"), _("See the Log Window"), GTK_STOCK_DIALOG_WARNING, NULL);
397 static void vf_pop_menu_copy_cb(GtkWidget *UNUSED(widget), gpointer data)
399 ViewFile *vf = (ViewFile *)data;
401 file_util_copy(NULL, vf_pop_menu_file_list(vf), NULL, vf->listview);
404 static void vf_pop_menu_move_cb(GtkWidget *UNUSED(widget), gpointer data)
406 ViewFile *vf = (ViewFile *)data;
408 file_util_move(NULL, vf_pop_menu_file_list(vf), NULL, vf->listview);
411 static void vf_pop_menu_rename_cb(GtkWidget *widget, gpointer data)
413 ViewFile *vf = (ViewFile *)data;
417 case FILEVIEW_LIST: vflist_pop_menu_rename_cb(widget, data); break;
418 case FILEVIEW_ICON: vficon_pop_menu_rename_cb(widget, data); break;
422 static void vf_pop_menu_delete_cb(GtkWidget *UNUSED(widget), gpointer data)
424 ViewFile *vf = (ViewFile *)data;
426 options->file_ops.safe_delete_enable = FALSE;
427 file_util_delete(NULL, vf_pop_menu_file_list(vf), vf->listview);
430 static void vf_pop_menu_move_to_trash_cb(GtkWidget *UNUSED(widget), gpointer data)
432 ViewFile *vf = (ViewFile *)data;
434 options->file_ops.safe_delete_enable = TRUE;
435 file_util_delete(NULL, vf_pop_menu_file_list(vf), vf->listview);
438 static void vf_pop_menu_copy_path_cb(GtkWidget *UNUSED(widget), gpointer data)
440 ViewFile *vf = (ViewFile *)data;
442 file_util_copy_path_list_to_clipboard(vf_pop_menu_file_list(vf), TRUE);
445 static void vf_pop_menu_copy_path_unquoted_cb(GtkWidget *UNUSED(widget), gpointer data)
447 ViewFile *vf = (ViewFile *)data;
449 file_util_copy_path_list_to_clipboard(vf_pop_menu_file_list(vf), FALSE);
452 static void vf_pop_menu_enable_grouping_cb(GtkWidget *UNUSED(widget), gpointer data)
454 ViewFile *vf = (ViewFile *)data;
456 file_data_disable_grouping_list(vf_pop_menu_file_list(vf), FALSE);
459 static void vf_pop_menu_duplicates_cb(GtkWidget *UNUSED(widget), gpointer data)
461 ViewFile *vf = (ViewFile *)data;
464 dw = dupe_window_new();
465 dupe_window_add_files(dw, vf_pop_menu_file_list(vf), FALSE);
468 static void vf_pop_menu_disable_grouping_cb(GtkWidget *UNUSED(widget), gpointer data)
470 ViewFile *vf = (ViewFile *)data;
472 file_data_disable_grouping_list(vf_pop_menu_file_list(vf), TRUE);
475 static void vf_pop_menu_sort_cb(GtkWidget *widget, gpointer data)
480 if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))) return;
482 vf = static_cast<ViewFile *>(submenu_item_get_data(widget));
485 type = (SortType)GPOINTER_TO_INT(data);
487 if (type == SORT_EXIFTIME || type == SORT_EXIFTIMEDIGITIZED || type == SORT_RATING)
489 vf_read_metadata_in_idle(vf);
494 layout_sort_set(vf->layout, type, vf->sort_ascend);
498 vf_sort_set(vf, type, vf->sort_ascend);
502 static void vf_pop_menu_sort_ascend_cb(GtkWidget *UNUSED(widget), gpointer data)
504 ViewFile *vf = (ViewFile *)data;
508 layout_sort_set(vf->layout, vf->sort_method, !vf->sort_ascend);
512 vf_sort_set(vf, vf->sort_method, !vf->sort_ascend);
516 static void vf_pop_menu_sel_mark_cb(GtkWidget *UNUSED(widget), gpointer data)
518 ViewFile *vf = (ViewFile *)data;
519 vf_mark_to_selection(vf, vf->active_mark, MTS_MODE_SET);
522 static void vf_pop_menu_sel_mark_and_cb(GtkWidget *UNUSED(widget), gpointer data)
524 ViewFile *vf = (ViewFile *)data;
525 vf_mark_to_selection(vf, vf->active_mark, MTS_MODE_AND);
528 static void vf_pop_menu_sel_mark_or_cb(GtkWidget *UNUSED(widget), gpointer data)
530 ViewFile *vf = (ViewFile *)data;
531 vf_mark_to_selection(vf, vf->active_mark, MTS_MODE_OR);
534 static void vf_pop_menu_sel_mark_minus_cb(GtkWidget *UNUSED(widget), gpointer data)
536 ViewFile *vf = (ViewFile *)data;
537 vf_mark_to_selection(vf, vf->active_mark, MTS_MODE_MINUS);
540 static void vf_pop_menu_set_mark_sel_cb(GtkWidget *UNUSED(widget), gpointer data)
542 ViewFile *vf = (ViewFile *)data;
543 vf_selection_to_mark(vf, vf->active_mark, STM_MODE_SET);
546 static void vf_pop_menu_res_mark_sel_cb(GtkWidget *UNUSED(widget), gpointer data)
548 ViewFile *vf = (ViewFile *)data;
549 vf_selection_to_mark(vf, vf->active_mark, STM_MODE_RESET);
552 static void vf_pop_menu_toggle_mark_sel_cb(GtkWidget *UNUSED(widget), gpointer data)
554 ViewFile *vf = (ViewFile *)data;
555 vf_selection_to_mark(vf, vf->active_mark, STM_MODE_TOGGLE);
558 static void vf_pop_menu_toggle_view_type_cb(GtkWidget *widget, gpointer data)
560 ViewFile *vf = (ViewFile *)data;
561 FileViewType new_type = static_cast<FileViewType>(GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "menu_item_radio_data")));
562 if (!vf->layout) return;
564 layout_views_set(vf->layout, vf->layout->options.dir_view_type, new_type);
567 static void vf_pop_menu_refresh_cb(GtkWidget *widget, gpointer data)
569 ViewFile *vf = (ViewFile *)data;
573 case FILEVIEW_LIST: vflist_pop_menu_refresh_cb(widget, data); break;
574 case FILEVIEW_ICON: vficon_pop_menu_refresh_cb(widget, data); break;
578 static void vf_popup_destroy_cb(GtkWidget *widget, gpointer data)
580 ViewFile *vf = (ViewFile *)data;
584 case FILEVIEW_LIST: vflist_popup_destroy_cb(widget, data); break;
585 case FILEVIEW_ICON: vficon_popup_destroy_cb(widget, data); break;
588 filelist_free(vf->editmenu_fd_list);
589 vf->editmenu_fd_list = NULL;
593 * @brief Add file selection list to a collection
595 * @param[in] data Index to the collection list menu item selected, or -1 for new collection
599 static void vf_pop_menu_collections_cb(GtkWidget *widget, gpointer data)
602 GList *selection_list;
604 vf = static_cast<ViewFile *>(submenu_item_get_data(widget));
605 selection_list = vf_selection_get_list(vf);
606 pop_menu_collections(selection_list, data);
608 filelist_free(selection_list);
611 GtkWidget *vf_pop_menu(ViewFile *vf)
616 gboolean active = FALSE;
617 gboolean class_archive = FALSE;
618 GtkAccelGroup *accel_group;
623 vflist_color_set(vf, VFLIST(vf)->click_fd, TRUE);
624 active = (VFLIST(vf)->click_fd != NULL);
625 class_archive = (VFLIST(vf)->click_fd != NULL && VFLIST(vf)->click_fd->format_class == FORMAT_CLASS_ARCHIVE);
628 active = (VFICON(vf)->click_fd != NULL);
629 class_archive = (VFICON(vf)->click_fd != NULL && VFICON(vf)->click_fd->format_class == FORMAT_CLASS_ARCHIVE);
633 menu = popup_menu_short_lived();
635 accel_group = gtk_accel_group_new();
636 gtk_menu_set_accel_group(GTK_MENU(menu), accel_group);
638 g_object_set_data(G_OBJECT(menu), "window_keys", NULL);
639 g_object_set_data(G_OBJECT(menu), "accel_group", accel_group);
641 g_signal_connect(G_OBJECT(menu), "destroy",
642 G_CALLBACK(vf_popup_destroy_cb), vf);
644 if (vf->clicked_mark > 0)
646 gint mark = vf->clicked_mark;
647 gchar *str_set_mark = g_strdup_printf(_("_Set mark %d"), mark);
648 gchar *str_res_mark = g_strdup_printf(_("_Reset mark %d"), mark);
649 gchar *str_toggle_mark = g_strdup_printf(_("_Toggle mark %d"), mark);
650 gchar *str_sel_mark = g_strdup_printf(_("_Select mark %d"), mark);
651 gchar *str_sel_mark_or = g_strdup_printf(_("_Add mark %d"), mark);
652 gchar *str_sel_mark_and = g_strdup_printf(_("_Intersection with mark %d"), mark);
653 gchar *str_sel_mark_minus = g_strdup_printf(_("_Unselect mark %d"), mark);
655 g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
657 vf->active_mark = mark;
658 vf->clicked_mark = 0;
660 menu_item_add_sensitive(menu, str_set_mark, active,
661 G_CALLBACK(vf_pop_menu_set_mark_sel_cb), vf);
663 menu_item_add_sensitive(menu, str_res_mark, active,
664 G_CALLBACK(vf_pop_menu_res_mark_sel_cb), vf);
666 menu_item_add_sensitive(menu, str_toggle_mark, active,
667 G_CALLBACK(vf_pop_menu_toggle_mark_sel_cb), vf);
669 menu_item_add_divider(menu);
671 menu_item_add_sensitive(menu, str_sel_mark, active,
672 G_CALLBACK(vf_pop_menu_sel_mark_cb), vf);
673 menu_item_add_sensitive(menu, str_sel_mark_or, active,
674 G_CALLBACK(vf_pop_menu_sel_mark_or_cb), vf);
675 menu_item_add_sensitive(menu, str_sel_mark_and, active,
676 G_CALLBACK(vf_pop_menu_sel_mark_and_cb), vf);
677 menu_item_add_sensitive(menu, str_sel_mark_minus, active,
678 G_CALLBACK(vf_pop_menu_sel_mark_minus_cb), vf);
680 menu_item_add_divider(menu);
682 g_free(str_set_mark);
683 g_free(str_res_mark);
684 g_free(str_toggle_mark);
685 g_free(str_sel_mark);
686 g_free(str_sel_mark_and);
687 g_free(str_sel_mark_or);
688 g_free(str_sel_mark_minus);
691 vf->editmenu_fd_list = vf_pop_menu_file_list(vf);
692 submenu_add_edit(menu, &item, G_CALLBACK(vf_pop_menu_edit_cb), vf, vf->editmenu_fd_list);
693 gtk_widget_set_sensitive(item, active);
695 menu_item_add_stock_sensitive(menu, _("View in _new window"), GTK_STOCK_NEW, active,
696 G_CALLBACK(vf_pop_menu_view_cb), vf);
698 menu_item_add_stock_sensitive(menu, _("Open archive"), GTK_STOCK_OPEN, active & class_archive, G_CALLBACK(vf_pop_menu_open_archive_cb), vf);
700 menu_item_add_divider(menu);
701 menu_item_add_stock_sensitive(menu, _("_Copy..."), GTK_STOCK_COPY, active,
702 G_CALLBACK(vf_pop_menu_copy_cb), vf);
703 menu_item_add_sensitive(menu, _("_Move..."), active,
704 G_CALLBACK(vf_pop_menu_move_cb), vf);
705 menu_item_add_sensitive(menu, _("_Rename..."), active,
706 G_CALLBACK(vf_pop_menu_rename_cb), vf);
707 menu_item_add_sensitive(menu, _("_Copy path to clipboard"), active,
708 G_CALLBACK(vf_pop_menu_copy_path_cb), vf);
709 menu_item_add_sensitive(menu, _("_Copy path unquoted to clipboard"), active,
710 G_CALLBACK(vf_pop_menu_copy_path_unquoted_cb), vf);
711 menu_item_add_divider(menu);
712 menu_item_add_stock_sensitive(menu,
713 options->file_ops.confirm_move_to_trash ? _("Move to Trash...") :
714 _("Move to Trash"), PIXBUF_INLINE_ICON_TRASH, active,
715 G_CALLBACK(vf_pop_menu_move_to_trash_cb), vf);
716 menu_item_add_stock_sensitive(menu,
717 options->file_ops.confirm_delete ? _("_Delete...") :
718 _("_Delete"), GTK_STOCK_DELETE, active,
719 G_CALLBACK(vf_pop_menu_delete_cb), vf);
720 menu_item_add_divider(menu);
722 menu_item_add_sensitive(menu, _("Enable file _grouping"), active,
723 G_CALLBACK(vf_pop_menu_enable_grouping_cb), vf);
724 menu_item_add_sensitive(menu, _("Disable file groupi_ng"), active,
725 G_CALLBACK(vf_pop_menu_disable_grouping_cb), vf);
727 menu_item_add_divider(menu);
728 menu_item_add_stock_sensitive(menu, _("_Find duplicates..."), GTK_STOCK_FIND, active,
729 G_CALLBACK(vf_pop_menu_duplicates_cb), vf);
730 menu_item_add_divider(menu);
732 submenu = submenu_add_collections(menu, &item,
733 G_CALLBACK(vf_pop_menu_collections_cb), vf);
734 gtk_widget_set_sensitive(item, active);
735 menu_item_add_divider(menu);
737 submenu = submenu_add_sort(NULL, G_CALLBACK(vf_pop_menu_sort_cb), vf,
738 FALSE, FALSE, TRUE, vf->sort_method);
739 menu_item_add_divider(submenu);
740 menu_item_add_check(submenu, _("Ascending"), vf->sort_ascend,
741 G_CALLBACK(vf_pop_menu_sort_ascend_cb), vf);
743 item = menu_item_add(menu, _("_Sort"), NULL, NULL);
744 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
746 item = menu_item_add_radio(menu, _("Images as List"), GINT_TO_POINTER(FILEVIEW_LIST), vf->type == FILEVIEW_LIST,
747 G_CALLBACK(vf_pop_menu_toggle_view_type_cb), vf);
749 item = menu_item_add_radio(menu, _("Images as Icons"), GINT_TO_POINTER(FILEVIEW_ICON), vf->type == FILEVIEW_ICON,
750 G_CALLBACK(vf_pop_menu_toggle_view_type_cb), vf);
755 menu_item_add_check(menu, _("Show _thumbnails"), VFLIST(vf)->thumbs_enabled,
756 G_CALLBACK(vflist_pop_menu_thumbs_cb), vf);
759 menu_item_add_check(menu, _("Show filename _text"), VFICON(vf)->show_text,
760 G_CALLBACK(vficon_pop_menu_show_names_cb), vf);
767 menu_item_add_check(menu, _("Show star rating"), options->show_star_rating,
768 G_CALLBACK(vflist_pop_menu_show_star_rating_cb), vf);
771 menu_item_add_check(menu, _("Show star rating"), options->show_star_rating,
772 G_CALLBACK(vficon_pop_menu_show_star_rating_cb), vf);
776 menu_item_add_stock(menu, _("Re_fresh"), GTK_STOCK_REFRESH, G_CALLBACK(vf_pop_menu_refresh_cb), vf);
781 gboolean vf_refresh(ViewFile *vf)
787 case FILEVIEW_LIST: ret = vflist_refresh(vf); break;
788 case FILEVIEW_ICON: ret = vficon_refresh(vf); break;
789 default: ret = FALSE;
795 gboolean vf_set_fd(ViewFile *vf, FileData *dir_fd)
801 case FILEVIEW_LIST: ret = vflist_set_fd(vf, dir_fd); break;
802 case FILEVIEW_ICON: ret = vficon_set_fd(vf, dir_fd); break;
803 default: ret = FALSE;
809 static void vf_destroy_cb(GtkWidget *widget, gpointer data)
811 ViewFile *vf = (ViewFile *)data;
815 case FILEVIEW_LIST: vflist_destroy_cb(widget, data); break;
816 case FILEVIEW_ICON: vficon_destroy_cb(widget, data); break;
821 g_signal_handlers_disconnect_matched(G_OBJECT(vf->popup), G_SIGNAL_MATCH_DATA,
823 gtk_widget_destroy(vf->popup);
826 if (vf->read_metadata_in_idle_id)
828 g_idle_remove_by_data(vf);
830 file_data_unref(vf->dir_fd);
835 static void vf_marks_filter_toggle_cb(GtkWidget *UNUSED(widget), gpointer data)
837 ViewFile *vf = (ViewFile *)data;
841 typedef struct _MarksTextEntry MarksTextEntry;
842 struct _MarksTextEntry {
845 GtkWidget *edit_widget;
850 static void vf_marks_tooltip_cancel_cb(GenericDialog *gd, gpointer data)
852 MarksTextEntry *mte = (MarksTextEntry *)data;
854 g_free(mte->text_entry);
855 generic_dialog_close(gd);
858 static void vf_marks_tooltip_ok_cb(GenericDialog *gd, gpointer data)
860 MarksTextEntry *mte = (MarksTextEntry *)data;
862 g_free(options->marks_tooltips[mte->mark_no]);
863 options->marks_tooltips[mte->mark_no] = g_strdup(gtk_entry_get_text(GTK_ENTRY(mte->edit_widget)));
865 gtk_widget_set_tooltip_text(mte->parent, options->marks_tooltips[mte->mark_no]);
867 g_free(mte->text_entry);
868 generic_dialog_close(gd);
871 void vf_marks_filter_on_icon_press(GtkEntry *UNUSED(entry), GtkEntryIconPosition UNUSED(pos),
872 GdkEvent *UNUSED(event), gpointer userdata)
874 MarksTextEntry *mte = static_cast<MarksTextEntry *>(userdata);
876 g_free(mte->text_entry);
877 mte->text_entry = g_strdup("");
878 gtk_entry_set_text(GTK_ENTRY(mte->edit_widget), "");
881 static void vf_marks_tooltip_help_cb(GenericDialog *UNUSED(gd), gpointer UNUSED(data))
883 help_window_show("GuideImageMarks.html");
886 static gboolean vf_marks_tooltip_cb(GtkWidget *widget,
887 GdkEventButton *event,
891 gint i = GPOINTER_TO_INT(user_data);
894 if (event->button == MOUSE_BUTTON_RIGHT)
896 mte = g_new0(MarksTextEntry, 1);
898 mte->text_entry = g_strdup(options->marks_tooltips[i]);
899 mte->parent = widget;
901 mte->gd = generic_dialog_new(_("Mark text"), "mark_text",
903 vf_marks_tooltip_cancel_cb, mte);
904 generic_dialog_add_message(mte->gd, GTK_STOCK_DIALOG_QUESTION, _("Set mark text"),
905 _("This will set or clear the mark text."), FALSE);
906 generic_dialog_add_button(mte->gd, GTK_STOCK_OK, NULL,
907 vf_marks_tooltip_ok_cb, TRUE);
908 generic_dialog_add_button(mte->gd, GTK_STOCK_HELP, NULL,
909 vf_marks_tooltip_help_cb, FALSE);
911 table = pref_table_new(mte->gd->vbox, 3, 1, FALSE, TRUE);
912 pref_table_label(table, 0, 0, g_strdup_printf("%s%d", _("Mark "), mte->mark_no + 1), 1.0);
913 mte->edit_widget = gtk_entry_new();
914 gtk_widget_set_size_request(mte->edit_widget, 300, -1);
917 gtk_entry_set_text(GTK_ENTRY(mte->edit_widget), mte->text_entry);
919 gtk_table_attach_defaults(GTK_TABLE(table), mte->edit_widget, 1, 2, 0, 1);
920 generic_dialog_attach_default(mte->gd, mte->edit_widget);
922 gtk_entry_set_icon_from_stock(GTK_ENTRY(mte->edit_widget),
923 GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CLEAR);
924 gtk_entry_set_icon_tooltip_text (GTK_ENTRY(mte->edit_widget),
925 GTK_ENTRY_ICON_SECONDARY, "Clear");
926 g_signal_connect(GTK_ENTRY(mte->edit_widget), "icon-press",
927 G_CALLBACK(vf_marks_filter_on_icon_press), mte);
929 gtk_widget_show(mte->edit_widget);
930 gtk_widget_grab_focus(mte->edit_widget);
931 gtk_widget_show(GTK_WIDGET(mte->gd->dialog));
939 static void vf_file_filter_save_cb(GtkWidget *UNUSED(widget), gpointer data)
941 ViewFile *vf = (ViewFile *)data;
943 gchar *remove_text = NULL;
944 gchar *index_text = NULL;
945 gboolean text_found = FALSE;
948 entry_text = g_strdup(gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(vf->file_filter.combo)))));
950 if (entry_text[0] == '\0' && vf->file_filter.last_selected >= 0)
952 gtk_combo_box_set_active(GTK_COMBO_BOX(vf->file_filter.combo), vf->file_filter.last_selected);
953 remove_text = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(vf->file_filter.combo));
954 history_list_item_remove("file_filter", remove_text);
955 gtk_combo_box_text_remove(GTK_COMBO_BOX_TEXT(vf->file_filter.combo), vf->file_filter.last_selected);
958 gtk_combo_box_set_active(GTK_COMBO_BOX(vf->file_filter.combo), -1);
959 vf->file_filter.last_selected = - 1;
960 gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(vf->file_filter.combo))), "");
961 vf->file_filter.count--;
965 if (entry_text[0] != '\0')
967 for (i = 0; i < vf->file_filter.count; i++)
973 gtk_combo_box_set_active(GTK_COMBO_BOX(vf->file_filter.combo), i);
974 index_text = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(vf->file_filter.combo));
976 if (g_strcmp0(index_text, entry_text) == 0)
986 history_list_add_to_key("file_filter", entry_text, 10);
987 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(vf->file_filter.combo), entry_text);
988 vf->file_filter.count++;
989 gtk_combo_box_set_active(GTK_COMBO_BOX(vf->file_filter.combo), vf->file_filter.count - 1);
998 static void vf_file_filter_cb(GtkWidget *UNUSED(widget), gpointer data)
1000 ViewFile *vf = (ViewFile *)data;
1005 static gboolean vf_file_filter_press_cb(GtkWidget *widget, GdkEventButton *UNUSED(bevent), gpointer data)
1007 ViewFile *vf = (ViewFile *)data;
1008 vf->file_filter.last_selected = gtk_combo_box_get_active(GTK_COMBO_BOX(vf->file_filter.combo));
1010 gtk_widget_grab_focus(widget);
1015 static GtkWidget *vf_marks_filter_init(ViewFile *vf)
1017 GtkWidget *frame = gtk_frame_new(NULL);
1018 GtkWidget *hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
1022 for (i = 0; i < FILEDATA_MARKS_SIZE ; i++)
1024 GtkWidget *check = gtk_check_button_new();
1025 gtk_box_pack_start(GTK_BOX(hbox), check, FALSE, FALSE, 0);
1026 g_signal_connect(G_OBJECT(check), "toggled",
1027 G_CALLBACK(vf_marks_filter_toggle_cb), vf);
1028 g_signal_connect(G_OBJECT(check), "button_press_event",
1029 G_CALLBACK(vf_marks_tooltip_cb), GINT_TO_POINTER(i));
1030 gtk_widget_set_tooltip_text(check, options->marks_tooltips[i]);
1032 gtk_widget_show(check);
1033 vf->filter_check[i] = check;
1035 gtk_container_add(GTK_CONTAINER(frame), hbox);
1036 gtk_widget_show(hbox);
1040 void vf_file_filter_set(ViewFile *vf, gboolean enable)
1044 gtk_widget_show(vf->file_filter.combo);
1045 gtk_widget_show(vf->file_filter.frame);
1049 gtk_widget_hide(vf->file_filter.combo);
1050 gtk_widget_hide(vf->file_filter.frame);
1056 static gboolean vf_file_filter_class_cb(GtkWidget *widget, gpointer data)
1058 ViewFile *vf = (ViewFile *)data;
1061 gboolean state = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget));
1063 for (i = 0; i < FILE_FORMAT_CLASSES; i++)
1065 if (g_strcmp0(format_class_list[i], gtk_menu_item_get_label(GTK_MENU_ITEM(widget))) == 0)
1067 options->class_filter[i] = state;
1075 static gboolean vf_file_filter_class_set_all_cb(GtkWidget *widget, gpointer data)
1077 ViewFile *vf = (ViewFile *)data;
1084 if (g_strcmp0(_("Select all"), gtk_menu_item_get_label(GTK_MENU_ITEM(widget))) == 0)
1093 for (i = 0; i < FILE_FORMAT_CLASSES; i++)
1095 options->class_filter[i] = state;
1099 parent = gtk_widget_get_parent(widget);
1100 children = gtk_container_get_children(GTK_CONTAINER(parent));
1103 child = static_cast<GtkWidget *>(children->data);
1104 if (i < FILE_FORMAT_CLASSES)
1106 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(child), state);
1109 children = children->next;
1111 g_list_free(children);
1117 static GtkWidget *class_filter_menu (ViewFile *vf)
1120 GtkWidget *menu_item;
1123 menu = gtk_menu_new();
1125 for (i = 0; i < FILE_FORMAT_CLASSES; i++)
1127 menu_item = gtk_check_menu_item_new_with_label(format_class_list[i]);
1128 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu_item), options->class_filter[i]);
1129 g_signal_connect(G_OBJECT(menu_item), "toggled", G_CALLBACK(vf_file_filter_class_cb), vf);
1130 gtk_menu_shell_append(GTK_MENU_SHELL (menu), menu_item);
1131 gtk_widget_show(menu_item);
1134 menu_item = gtk_menu_item_new_with_label(_("Select all"));
1135 gtk_menu_shell_append(GTK_MENU_SHELL (menu), menu_item);
1136 gtk_widget_show(menu_item);
1137 g_signal_connect(G_OBJECT(menu_item), "activate", G_CALLBACK(vf_file_filter_class_set_all_cb), vf);
1139 menu_item = gtk_menu_item_new_with_label(_("Select none"));
1140 gtk_menu_shell_append(GTK_MENU_SHELL (menu), menu_item);
1141 gtk_widget_show(menu_item);
1142 g_signal_connect(G_OBJECT(menu_item), "activate", G_CALLBACK(vf_file_filter_class_set_all_cb), vf);
1147 static void case_sensitive_cb(GtkWidget *widget, gpointer data)
1149 ViewFile *vf = (ViewFile *)data;
1151 vf->file_filter.case_sensitive = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1155 static void file_filter_clear_cb(GtkEntry *UNUSED(entry), GtkEntryIconPosition pos, GdkEvent *UNUSED(event), gpointer userdata)
1157 if (pos == GTK_ENTRY_ICON_SECONDARY)
1159 gtk_entry_set_text(GTK_ENTRY(userdata), "");
1160 gtk_widget_grab_focus(GTK_WIDGET(userdata));
1164 static GtkWidget *vf_file_filter_init(ViewFile *vf)
1166 GtkWidget *frame = gtk_frame_new(NULL);
1167 GtkWidget *hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
1170 GtkWidget *combo_entry;
1172 GtkWidget *menuitem;
1173 GtkWidget *case_sensitive;
1178 vf->file_filter.combo = gtk_combo_box_text_new_with_entry();
1179 combo_entry = gtk_bin_get_child(GTK_BIN(vf->file_filter.combo));
1180 gtk_widget_show(gtk_bin_get_child(GTK_BIN(vf->file_filter.combo)));
1181 gtk_widget_show((GTK_WIDGET(vf->file_filter.combo)));
1182 gtk_widget_set_tooltip_text(GTK_WIDGET(vf->file_filter.combo), _("Use regular expressions"));
1184 gtk_entry_set_icon_from_stock(GTK_ENTRY(combo_entry), GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CLEAR);
1185 gtk_entry_set_icon_tooltip_text (GTK_ENTRY(combo_entry), GTK_ENTRY_ICON_SECONDARY, _("Clear"));
1186 g_signal_connect(GTK_ENTRY(combo_entry), "icon-press", G_CALLBACK(file_filter_clear_cb), combo_entry);
1188 work = history_list_get_by_key("file_filter");
1191 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(vf->file_filter.combo), (gchar *)work->data);
1194 vf->file_filter.count = n;
1196 gtk_combo_box_set_active(GTK_COMBO_BOX(vf->file_filter.combo), 0);
1198 g_signal_connect(G_OBJECT(combo_entry), "activate",
1199 G_CALLBACK(vf_file_filter_save_cb), vf);
1201 g_signal_connect(G_OBJECT(vf->file_filter.combo), "changed",
1202 G_CALLBACK(vf_file_filter_cb), vf);
1204 g_signal_connect(G_OBJECT(combo_entry), "button_press_event",
1205 G_CALLBACK(vf_file_filter_press_cb), vf);
1207 gtk_box_pack_start(GTK_BOX(hbox), vf->file_filter.combo, FALSE, FALSE, 0);
1208 gtk_widget_show(vf->file_filter.combo);
1209 gtk_container_add(GTK_CONTAINER(frame), hbox);
1210 gtk_widget_show(hbox);
1212 case_sensitive = gtk_check_button_new_with_label(_("Case"));
1213 gtk_box_pack_start(GTK_BOX(hbox), case_sensitive, FALSE, FALSE, 0);
1214 gtk_widget_set_tooltip_text(GTK_WIDGET(case_sensitive), _("Case sensitive"));
1215 g_signal_connect(G_OBJECT(case_sensitive), "clicked", G_CALLBACK(case_sensitive_cb), vf);
1216 gtk_widget_show(case_sensitive);
1218 menubar = gtk_menu_bar_new();
1219 gtk_box_pack_start(GTK_BOX(hbox), menubar, FALSE, TRUE, 0);
1220 gtk_widget_show(menubar);
1222 box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, PREF_PAD_GAP);
1223 icon = gtk_image_new_from_icon_name("pan-down", GTK_ICON_SIZE_MENU);
1224 label = gtk_label_new(_("Class"));
1226 gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 0);
1227 gtk_box_pack_end(GTK_BOX(box), icon, FALSE, FALSE, 0);
1229 menuitem = gtk_menu_item_new();
1231 gtk_widget_set_tooltip_text(GTK_WIDGET(menuitem), _("Select Class filter"));
1232 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), class_filter_menu(vf));
1233 gtk_menu_shell_append(GTK_MENU_SHELL(menubar), menuitem);
1234 gtk_container_add(GTK_CONTAINER(menuitem), box);
1235 gtk_widget_show_all(menuitem);
1240 void vf_mark_filter_toggle(ViewFile *vf, gint mark)
1243 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(vf->filter_check[n]),
1244 !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(vf->filter_check[n])));
1247 ViewFile *vf_new(FileViewType type, FileData *dir_fd)
1251 vf = g_new0(ViewFile, 1);
1254 vf->sort_method = SORT_NAME;
1255 vf->sort_ascend = TRUE;
1256 vf->read_metadata_in_idle_id = 0;
1258 vf->scrolled = gtk_scrolled_window_new(NULL, NULL);
1259 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(vf->scrolled), GTK_SHADOW_IN);
1260 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(vf->scrolled),
1261 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1263 vf->filter = vf_marks_filter_init(vf);
1264 vf->file_filter.frame = vf_file_filter_init(vf);
1266 vf->widget = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
1267 gtk_box_pack_start(GTK_BOX(vf->widget), vf->filter, FALSE, FALSE, 0);
1268 gtk_box_pack_start(GTK_BOX(vf->widget), vf->file_filter.frame, FALSE, FALSE, 0);
1269 gtk_box_pack_start(GTK_BOX(vf->widget), vf->scrolled, TRUE, TRUE, 0);
1270 gtk_widget_show(vf->scrolled);
1272 g_signal_connect(G_OBJECT(vf->widget), "destroy",
1273 G_CALLBACK(vf_destroy_cb), vf);
1277 case FILEVIEW_LIST: vf = vflist_new(vf, dir_fd); break;
1278 case FILEVIEW_ICON: vf = vficon_new(vf, dir_fd); break;
1283 g_signal_connect(G_OBJECT(vf->listview), "key_press_event",
1284 G_CALLBACK(vf_press_key_cb), vf);
1285 g_signal_connect(G_OBJECT(vf->listview), "button_press_event",
1286 G_CALLBACK(vf_press_cb), vf);
1287 g_signal_connect(G_OBJECT(vf->listview), "button_release_event",
1288 G_CALLBACK(vf_release_cb), vf);
1290 gtk_container_add(GTK_CONTAINER(vf->scrolled), vf->listview);
1291 gtk_widget_show(vf->listview);
1293 if (dir_fd) vf_set_fd(vf, dir_fd);
1298 void vf_set_status_func(ViewFile *vf, void (*func)(ViewFile *vf, gpointer data), gpointer data)
1300 vf->func_status = func;
1301 vf->data_status = data;
1304 void vf_set_thumb_status_func(ViewFile *vf, void (*func)(ViewFile *vf, gdouble val, const gchar *text, gpointer data), gpointer data)
1306 vf->func_thumb_status = func;
1307 vf->data_thumb_status = data;
1310 void vf_thumb_set(ViewFile *vf, gboolean enable)
1314 case FILEVIEW_LIST: vflist_thumb_set(vf, enable); break;
1315 case FILEVIEW_ICON: /*vficon_thumb_set(vf, enable);*/ break;
1320 static gboolean vf_thumb_next(ViewFile *vf);
1322 static gdouble vf_thumb_progress(ViewFile *vf)
1329 case FILEVIEW_LIST: vflist_thumb_progress_count(vf->list, &count, &done); break;
1330 case FILEVIEW_ICON: vficon_thumb_progress_count(vf->list, &count, &done); break;
1333 DEBUG_1("thumb progress: %d of %d", done, count);
1334 return (gdouble)done / count;
1337 static gdouble vf_read_metadata_in_idle_progress(ViewFile *vf)
1344 case FILEVIEW_LIST: vflist_read_metadata_progress_count(vf->list, &count, &done); break;
1345 case FILEVIEW_ICON: vficon_read_metadata_progress_count(vf->list, &count, &done); break;
1348 return (gdouble)done / count;
1351 static void vf_set_thumb_fd(ViewFile *vf, FileData *fd)
1355 case FILEVIEW_LIST: vflist_set_thumb_fd(vf, fd); break;
1356 case FILEVIEW_ICON: vficon_set_thumb_fd(vf, fd); break;
1360 static void vf_thumb_status(ViewFile *vf, gdouble val, const gchar *text)
1362 if (vf->func_thumb_status)
1364 vf->func_thumb_status(vf, val, text, vf->data_thumb_status);
1368 static void vf_thumb_do(ViewFile *vf, FileData *fd)
1372 vf_set_thumb_fd(vf, fd);
1373 vf_thumb_status(vf, vf_thumb_progress(vf), _("Loading thumbs..."));
1376 void vf_thumb_cleanup(ViewFile *vf)
1378 vf_thumb_status(vf, 0.0, NULL);
1380 vf->thumbs_running = FALSE;
1382 thumb_loader_free(vf->thumbs_loader);
1383 vf->thumbs_loader = NULL;
1385 vf->thumbs_filedata = NULL;
1388 void vf_thumb_stop(ViewFile *vf)
1390 if (vf->thumbs_running) vf_thumb_cleanup(vf);
1393 static void vf_thumb_common_cb(ThumbLoader *tl, gpointer data)
1395 ViewFile *vf = (ViewFile *)data;
1397 if (vf->thumbs_filedata && vf->thumbs_loader == tl)
1399 vf_thumb_do(vf, vf->thumbs_filedata);
1402 while (vf_thumb_next(vf));
1405 static void vf_thumb_error_cb(ThumbLoader *tl, gpointer data)
1407 vf_thumb_common_cb(tl, data);
1410 static void vf_thumb_done_cb(ThumbLoader *tl, gpointer data)
1412 vf_thumb_common_cb(tl, data);
1415 static gboolean vf_thumb_next(ViewFile *vf)
1417 FileData *fd = NULL;
1419 if (!gtk_widget_get_realized(vf->listview))
1421 vf_thumb_status(vf, 0.0, NULL);
1427 case FILEVIEW_LIST: fd = vflist_thumb_next_fd(vf); break;
1428 case FILEVIEW_ICON: fd = vficon_thumb_next_fd(vf); break;
1434 vf_thumb_cleanup(vf);
1438 vf->thumbs_filedata = fd;
1440 thumb_loader_free(vf->thumbs_loader);
1442 vf->thumbs_loader = thumb_loader_new(options->thumbnails.max_width, options->thumbnails.max_height);
1443 thumb_loader_set_callbacks(vf->thumbs_loader,
1449 if (!thumb_loader_start(vf->thumbs_loader, fd))
1451 /* set icon to unknown, continue */
1452 DEBUG_1("thumb loader start failed %s", fd->path);
1453 vf_thumb_do(vf, fd);
1461 static void vf_thumb_reset_all(ViewFile *vf)
1465 for (work = vf->list; work; work = work->next)
1467 FileData *fd = (FileData *)work->data;
1468 if (fd->thumb_pixbuf)
1470 g_object_unref(fd->thumb_pixbuf);
1471 fd->thumb_pixbuf = NULL;
1476 void vf_thumb_update(ViewFile *vf)
1480 if (vf->type == FILEVIEW_LIST && !VFLIST(vf)->thumbs_enabled) return;
1482 vf_thumb_status(vf, 0.0, _("Loading thumbs..."));
1483 vf->thumbs_running = TRUE;
1485 if (thumb_format_changed)
1487 vf_thumb_reset_all(vf);
1488 thumb_format_changed = FALSE;
1491 while (vf_thumb_next(vf));
1494 void vf_star_cleanup(ViewFile *vf)
1496 if (vf->stars_id != 0)
1498 g_source_remove(vf->stars_id);
1502 vf->stars_filedata = NULL;
1505 void vf_star_stop(ViewFile *vf)
1507 vf_star_cleanup(vf);
1510 static void vf_set_star_fd(ViewFile *vf, FileData *fd)
1514 case FILEVIEW_LIST: vflist_set_star_fd(vf, fd); break;
1515 case FILEVIEW_ICON: vficon_set_star_fd(vf, fd); break;
1520 static void vf_star_do(ViewFile *vf, FileData *fd)
1524 vf_set_star_fd(vf, fd);
1527 static gboolean vf_star_next(ViewFile *vf)
1529 FileData *fd = NULL;
1533 case FILEVIEW_LIST: fd = vflist_star_next_fd(vf); break;
1534 case FILEVIEW_ICON: fd = vficon_star_next_fd(vf); break;
1541 vf_star_cleanup(vf);
1548 gboolean vf_stars_cb(gpointer data)
1550 ViewFile *vf = (ViewFile *)data;
1551 FileData *fd = vf->stars_filedata;
1555 read_rating_data(fd);
1559 if (vf_star_next(vf))
1565 vf->stars_filedata = NULL;
1574 void vf_star_update(ViewFile *vf)
1578 if (!options->show_star_rating)
1586 void vf_marks_set(ViewFile *vf, gboolean enable)
1588 if (vf->marks_enabled == enable) return;
1590 vf->marks_enabled = enable;
1594 case FILEVIEW_LIST: vflist_marks_set(vf, enable); break;
1595 case FILEVIEW_ICON: vficon_marks_set(vf, enable); break;
1598 gtk_widget_show(vf->filter);
1600 gtk_widget_hide(vf->filter);
1602 vf_refresh_idle(vf);
1605 //void vf_star_rating_set(ViewFile *vf, gboolean enable)
1607 //if (options->show_star_rating == enable) return;
1608 //options->show_star_rating = enable;
1612 //case FILEVIEW_LIST: vflist_star_rating_set(vf, enable); break;
1613 //case FILEVIEW_ICON: vficon_star_rating_set(vf, enable); break;
1615 //vf_refresh_idle(vf);
1618 guint vf_marks_get_filter(ViewFile *vf)
1622 if (!vf->marks_enabled) return 0;
1624 for (i = 0; i < FILEDATA_MARKS_SIZE ; i++)
1626 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(vf->filter_check[i])))
1634 GRegex *vf_file_filter_get_filter(ViewFile *vf)
1637 GError *error = NULL;
1638 gchar *file_filter_text = NULL;
1640 if (!gtk_widget_get_visible(vf->file_filter.combo))
1642 return g_regex_new("", GRegexCompileFlags(0), GRegexMatchFlags(0), NULL);
1645 file_filter_text = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(vf->file_filter.combo));
1647 if (file_filter_text[0] != '\0')
1649 ret = g_regex_new(file_filter_text, vf->file_filter.case_sensitive ? GRegexCompileFlags(0) : G_REGEX_CASELESS, GRegexMatchFlags(0), &error);
1652 log_printf("Error: could not compile regular expression %s\n%s\n", file_filter_text, error->message);
1653 g_error_free(error);
1655 ret = g_regex_new("", GRegexCompileFlags(0), GRegexMatchFlags(0), NULL);
1657 g_free(file_filter_text);
1661 ret = g_regex_new("", GRegexCompileFlags(0), GRegexMatchFlags(0), NULL);
1667 guint vf_class_get_filter(ViewFile *vf)
1672 if (!gtk_widget_get_visible(vf->file_filter.combo))
1677 for ( i = 0; i < FILE_FORMAT_CLASSES; i++)
1679 if (options->class_filter[i])
1688 void vf_set_layout(ViewFile *vf, LayoutWindow *layout)
1690 vf->layout = layout;
1695 *-----------------------------------------------------------------------------
1696 * maintenance (for rename, move, remove)
1697 *-----------------------------------------------------------------------------
1700 static gboolean vf_refresh_idle_cb(gpointer data)
1702 ViewFile *vf = (ViewFile *)data;
1705 vf->refresh_idle_id = 0;
1709 void vf_refresh_idle_cancel(ViewFile *vf)
1711 if (vf->refresh_idle_id)
1713 g_source_remove(vf->refresh_idle_id);
1714 vf->refresh_idle_id = 0;
1719 void vf_refresh_idle(ViewFile *vf)
1721 if (!vf->refresh_idle_id)
1723 vf->time_refresh_set = time(NULL);
1724 /* file operations run with G_PRIORITY_DEFAULT_IDLE */
1725 vf->refresh_idle_id = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE + 50, vf_refresh_idle_cb, vf, NULL);
1727 else if (time(NULL) - vf->time_refresh_set > 1)
1729 /* more than 1 sec since last update - increase priority */
1730 vf_refresh_idle_cancel(vf);
1731 vf->time_refresh_set = time(NULL);
1732 vf->refresh_idle_id = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE - 50, vf_refresh_idle_cb, vf, NULL);
1736 void vf_notify_cb(FileData *fd, NotifyType type, gpointer data)
1738 ViewFile *vf = (ViewFile *)data;
1741 NotifyType interested = static_cast<NotifyType>(NOTIFY_CHANGE | NOTIFY_REREAD | NOTIFY_GROUPING);
1742 if (vf->marks_enabled) interested = static_cast<NotifyType>(interested | NOTIFY_MARKS | NOTIFY_METADATA);
1743 /** @FIXME NOTIFY_METADATA should be checked by the keyword-to-mark functions and converted to NOTIFY_MARKS only if there was a change */
1745 if (!(type & interested) || vf->refresh_idle_id || !vf->dir_fd) return;
1747 refresh = (fd == vf->dir_fd);
1751 gchar *base = remove_level_from_path(fd->path);
1752 refresh = (g_strcmp0(base, vf->dir_fd->path) == 0);
1756 if ((type & NOTIFY_CHANGE) && fd->change)
1758 if (!refresh && fd->change->dest)
1760 gchar *dest_base = remove_level_from_path(fd->change->dest);
1761 refresh = (g_strcmp0(dest_base, vf->dir_fd->path) == 0);
1765 if (!refresh && fd->change->source)
1767 gchar *source_base = remove_level_from_path(fd->change->source);
1768 refresh = (g_strcmp0(source_base, vf->dir_fd->path) == 0);
1769 g_free(source_base);
1775 DEBUG_1("Notify vf: %s %04x", fd->path, type);
1776 vf_refresh_idle(vf);
1780 static gboolean vf_read_metadata_in_idle_cb(gpointer data)
1783 ViewFile *vf = (ViewFile *)data;
1786 vf_thumb_status(vf, vf_read_metadata_in_idle_progress(vf), _("Loading meta..."));
1792 fd = static_cast<FileData *>(work->data);
1794 if (fd && !fd->metadata_in_idle_loaded)
1798 read_exif_time_data(fd);
1800 if (!fd->exifdate_digitized)
1802 read_exif_time_digitized_data(fd);
1804 if (fd->rating == STAR_RATING_NOT_READ)
1806 read_rating_data(fd);
1808 fd->metadata_in_idle_loaded = TRUE;
1814 vf_thumb_status(vf, 0.0, NULL);
1815 vf->read_metadata_in_idle_id = 0;
1820 static void vf_read_metadata_in_idle_finished_cb(gpointer data)
1822 ViewFile *vf = (ViewFile *)data;
1824 vf_thumb_status(vf, 0.0, "Loading meta...");
1825 vf->read_metadata_in_idle_id = 0;
1828 void vf_read_metadata_in_idle(ViewFile *vf)
1832 if (vf->read_metadata_in_idle_id)
1834 g_idle_remove_by_data(vf);
1836 vf->read_metadata_in_idle_id = 0;
1840 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);
1846 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */