3 * Copyright (C) 2008 The Geeqie Team
5 * Author: Laurent Monin
7 * This software is released under the GNU General Public License (GNU GPL).
8 * Please read the included file COPYING for more information.
9 * This software comes with no warranty of any kind, use at your own risk!
13 #include "view_file.h"
21 #include "view_file_list.h"
22 #include "view_file_icon.h"
25 *-----------------------------------------------------------------------------
27 *-----------------------------------------------------------------------------
30 void vf_send_update(ViewFile *vf)
32 if (vf->func_status) vf->func_status(vf, vf->data_status);
36 *-----------------------------------------------------------------------------
38 *-----------------------------------------------------------------------------
41 void vf_sort_set(ViewFile *vf, SortType type, gint ascend)
45 case FILEVIEW_LIST: vflist_sort_set(vf, type, ascend); break;
46 case FILEVIEW_ICON: vficon_sort_set(vf, type, ascend); break;
51 *-----------------------------------------------------------------------------
53 *-----------------------------------------------------------------------------
56 FileData *vf_index_get_data(ViewFile *vf, gint row)
62 case FILEVIEW_LIST: fd = vflist_index_get_data(vf, row); break;
63 case FILEVIEW_ICON: fd = vficon_index_get_data(vf, row); break;
69 gint vf_index_by_path(ViewFile *vf, const gchar *path)
75 case FILEVIEW_LIST: index = vflist_index_by_path(vf, path); break;
76 case FILEVIEW_ICON: index = vficon_index_by_path(vf, path); break;
82 gint vf_count(ViewFile *vf, gint64 *bytes)
88 case FILEVIEW_LIST: count = vflist_count(vf, bytes); break;
89 case FILEVIEW_ICON: count = vficon_count(vf, bytes); break;
95 GList *vf_get_list(ViewFile *vf)
101 case FILEVIEW_LIST: list = vflist_get_list(vf); break;
102 case FILEVIEW_ICON: list = vficon_get_list(vf); break;
110 *-------------------------------------------------------------------
112 *-------------------------------------------------------------------
115 static gint vf_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
122 case FILEVIEW_LIST: ret = vflist_press_key_cb(widget, event, data); break;
123 case FILEVIEW_ICON: ret = vficon_press_key_cb(widget, event, data); break;
130 *-------------------------------------------------------------------
132 *-------------------------------------------------------------------
135 static gint vf_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
142 case FILEVIEW_LIST: ret = vflist_press_cb(widget, bevent, data); break;
143 case FILEVIEW_ICON: ret = vficon_press_cb(widget, bevent, data); break;
149 static gint vf_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
156 case FILEVIEW_LIST: ret = vflist_release_cb(widget, bevent, data); break;
157 case FILEVIEW_ICON: ret = vficon_release_cb(widget, bevent, data); break;
165 *-----------------------------------------------------------------------------
167 *-----------------------------------------------------------------------------
170 gint vf_selection_count(ViewFile *vf, gint64 *bytes)
176 case FILEVIEW_LIST: count = vflist_selection_count(vf, bytes); break;
177 case FILEVIEW_ICON: count = vficon_selection_count(vf, bytes); break;
183 GList *vf_selection_get_list(ViewFile *vf)
189 case FILEVIEW_LIST: list = vflist_selection_get_list(vf); break;
190 case FILEVIEW_ICON: list = vficon_selection_get_list(vf); break;
196 GList *vf_selection_get_list_by_index(ViewFile *vf)
202 case FILEVIEW_LIST: list = vflist_selection_get_list_by_index(vf); break;
203 case FILEVIEW_ICON: list = vficon_selection_get_list_by_index(vf); break;
209 void vf_select_all(ViewFile *vf)
213 case FILEVIEW_LIST: vflist_select_all(vf); break;
214 case FILEVIEW_ICON: vficon_select_all(vf); break;
218 void vf_select_none(ViewFile *vf)
222 case FILEVIEW_LIST: vflist_select_none(vf); break;
223 case FILEVIEW_ICON: vficon_select_none(vf); break;
227 void vf_select_invert(ViewFile *vf)
231 case FILEVIEW_LIST: vflist_select_invert(vf); break;
232 case FILEVIEW_ICON: vficon_select_invert(vf); break;
236 void vf_select_by_fd(ViewFile *vf, FileData *fd)
240 case FILEVIEW_LIST: vflist_select_by_fd(vf, fd); break;
241 case FILEVIEW_ICON: vficon_select_by_fd(vf, fd); break;
245 void vf_mark_to_selection(ViewFile *vf, gint mark, MarkToSelectionMode mode)
249 case FILEVIEW_LIST: vflist_mark_to_selection(vf, mark, mode); break;
250 case FILEVIEW_ICON: vficon_mark_to_selection(vf, mark, mode); break;
254 void vf_selection_to_mark(ViewFile *vf, gint mark, SelectionToMarkMode mode)
258 case FILEVIEW_LIST: vflist_selection_to_mark(vf, mark, mode); break;
259 case FILEVIEW_ICON: vficon_selection_to_mark(vf, mark, mode); break;
264 *-----------------------------------------------------------------------------
266 *-----------------------------------------------------------------------------
270 static void vf_dnd_init(ViewFile *vf)
274 case FILEVIEW_LIST: vflist_dnd_init(vf); break;
275 case FILEVIEW_ICON: vficon_dnd_init(vf); break;
280 *-----------------------------------------------------------------------------
282 *-----------------------------------------------------------------------------
285 GList *vf_pop_menu_file_list(ViewFile *vf)
291 case FILEVIEW_LIST: ret = vflist_pop_menu_file_list(vf); break;
292 case FILEVIEW_ICON: ret = vficon_pop_menu_file_list(vf); break;
298 void vf_pop_menu_edit_cb(GtkWidget *widget, gpointer data)
304 vf = submenu_item_get_data(widget);
305 n = GPOINTER_TO_INT(data);
309 list = vf_pop_menu_file_list(vf);
310 start_editor_from_filelist(n, list);
314 void vf_pop_menu_info_cb(GtkWidget *widget, gpointer data)
318 info_window_new(NULL, vf_pop_menu_file_list(vf), NULL);
321 void vf_pop_menu_copy_cb(GtkWidget *widget, gpointer data)
325 file_util_copy(NULL, vf_pop_menu_file_list(vf), NULL, vf->listview);
328 void vf_pop_menu_move_cb(GtkWidget *widget, gpointer data)
332 file_util_move(NULL, vf_pop_menu_file_list(vf), NULL, vf->listview);
335 void vf_pop_menu_delete_cb(GtkWidget *widget, gpointer data)
339 file_util_delete(NULL, vf_pop_menu_file_list(vf), vf->listview);
342 void vf_pop_menu_copy_path_cb(GtkWidget *widget, gpointer data)
346 file_util_copy_path_list_to_clipboard(vf_pop_menu_file_list(vf));
349 void vf_pop_menu_sort_cb(GtkWidget *widget, gpointer data)
354 if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))) return;
356 vf = submenu_item_get_data(widget);
359 type = (SortType)GPOINTER_TO_INT(data);
363 layout_sort_set(vf->layout, type, vf->sort_ascend);
367 vf_sort_set(vf, type, vf->sort_ascend);
371 void vf_pop_menu_sort_ascend_cb(GtkWidget *widget, gpointer data)
377 layout_sort_set(vf->layout, vf->sort_method, !vf->sort_ascend);
381 vf_sort_set(vf, vf->sort_method, !vf->sort_ascend);
385 void vf_pop_menu_sel_mark_cb(GtkWidget *widget, gpointer data)
388 vf_mark_to_selection(vf, vf->active_mark, MTS_MODE_SET);
391 void vf_pop_menu_sel_mark_and_cb(GtkWidget *widget, gpointer data)
394 vf_mark_to_selection(vf, vf->active_mark, MTS_MODE_AND);
397 void vf_pop_menu_sel_mark_or_cb(GtkWidget *widget, gpointer data)
400 vf_mark_to_selection(vf, vf->active_mark, MTS_MODE_OR);
403 void vf_pop_menu_sel_mark_minus_cb(GtkWidget *widget, gpointer data)
406 vf_mark_to_selection(vf, vf->active_mark, MTS_MODE_MINUS);
409 void vf_pop_menu_set_mark_sel_cb(GtkWidget *widget, gpointer data)
412 vf_selection_to_mark(vf, vf->active_mark, STM_MODE_SET);
415 void vf_pop_menu_res_mark_sel_cb(GtkWidget *widget, gpointer data)
418 vf_selection_to_mark(vf, vf->active_mark, STM_MODE_RESET);
421 void vf_pop_menu_toggle_mark_sel_cb(GtkWidget *widget, gpointer data)
424 vf_selection_to_mark(vf, vf->active_mark, STM_MODE_TOGGLE);
427 void vf_pop_menu_toggle_view_type_cb(GtkWidget *widget, gpointer data)
431 if (!vf->layout) return;
433 switch(vf->layout->file_view_type)
436 layout_views_set(vf->layout, vf->layout->dir_view_type, FILEVIEW_ICON);
439 layout_views_set(vf->layout, vf->layout->dir_view_type, FILEVIEW_LIST);
447 gint vf_refresh(ViewFile *vf)
453 case FILEVIEW_LIST: ret = vflist_refresh(vf); break;
454 case FILEVIEW_ICON: ret = vficon_refresh(vf); break;
460 gint vf_set_path(ViewFile *vf, const gchar *path)
466 case FILEVIEW_LIST: ret = vflist_set_path(vf, path); break;
467 case FILEVIEW_ICON: ret = vficon_set_path(vf, path); break;
473 static void vf_destroy_cb(GtkWidget *widget, gpointer data)
479 case FILEVIEW_LIST: vflist_destroy_cb(widget, data); break;
480 case FILEVIEW_ICON: vficon_destroy_cb(widget, data); break;
485 g_signal_handlers_disconnect_matched(G_OBJECT(vf->popup), G_SIGNAL_MATCH_DATA,
487 gtk_widget_destroy(vf->popup);
495 ViewFile *vf_new(FileViewType type, const gchar *path)
499 vf = g_new0(ViewFile, 1);
506 vf->sort_method = SORT_NAME;
507 vf->sort_ascend = TRUE;
509 vf->thumbs_running = FALSE;
510 vf->thumbs_count = 0;
511 vf->thumbs_loader = NULL;
512 vf->thumbs_filedata = NULL;
516 vf->widget = gtk_scrolled_window_new(NULL, NULL);
517 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(vf->widget), GTK_SHADOW_IN);
518 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(vf->widget),
519 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
521 g_signal_connect(G_OBJECT(vf->widget), "destroy",
522 G_CALLBACK(vf_destroy_cb), vf);
526 case FILEVIEW_LIST: vf = vflist_new(vf, path); break;
527 case FILEVIEW_ICON: vf = vficon_new(vf, path); break;
532 g_signal_connect(G_OBJECT(vf->listview), "key_press_event",
533 G_CALLBACK(vf_press_key_cb), vf);
534 g_signal_connect(G_OBJECT(vf->listview), "button_press_event",
535 G_CALLBACK(vf_press_cb), vf);
536 g_signal_connect(G_OBJECT(vf->listview), "button_release_event",
537 G_CALLBACK(vf_release_cb), vf);
539 gtk_container_add(GTK_CONTAINER(vf->widget), vf->listview);
540 gtk_widget_show(vf->listview);
542 if (path) vf_set_path(vf, path);
547 void vf_set_status_func(ViewFile *vf, void (*func)(ViewFile *vf, gpointer data), gpointer data)
549 vf->func_status = func;
550 vf->data_status = data;
553 void vf_set_thumb_status_func(ViewFile *vf, void (*func)(ViewFile *vf, gdouble val, const gchar *text, gpointer data), gpointer data)
555 vf->func_thumb_status = func;
556 vf->data_thumb_status = data;
559 void vf_thumb_set(ViewFile *vf, gint enable)
563 case FILEVIEW_LIST: vflist_thumb_set(vf, enable); break;
564 case FILEVIEW_ICON: /*vficon_thumb_set(vf, enable);*/ break;
568 void vf_marks_set(ViewFile *vf, gint enable)
572 case FILEVIEW_LIST: vflist_marks_set(vf, enable); break;
573 case FILEVIEW_ICON: /*vficon_marks_set(vf, enable);*/ break;
577 void vf_set_layout(ViewFile *vf, LayoutWindow *layout)
583 *-----------------------------------------------------------------------------
584 * maintenance (for rename, move, remove)
585 *-----------------------------------------------------------------------------
588 gint vf_maint_renamed(ViewFile *vf, FileData *fd)
594 case FILEVIEW_LIST: ret = vflist_maint_renamed(vf, fd); break;
595 case FILEVIEW_ICON: ret = vficon_maint_renamed(vf, fd); break;
601 gint vf_maint_removed(ViewFile *vf, FileData *fd, GList *ignore_list)
607 case FILEVIEW_LIST: ret = vflist_maint_removed(vf, fd, ignore_list); break;
608 case FILEVIEW_ICON: ret = vficon_maint_removed(vf, fd, ignore_list); break;
614 gint vf_maint_moved(ViewFile *vf, FileData *fd, GList *ignore_list)
620 case FILEVIEW_LIST: ret = vflist_maint_moved(vf, fd, ignore_list); break;
621 case FILEVIEW_ICON: ret = vficon_maint_moved(vf, fd, ignore_list); break;