Add missing space between switch and first parenthesis.
[geeqie.git] / src / view_file.c
1 /*
2  * Geeqie
3  * Copyright (C) 2008 - 2009 The Geeqie Team
4  *
5  * Author: Laurent Monin
6  *
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!
10  */
11
12 #include "main.h"
13 #include "view_file.h"
14
15 #include "editors.h"
16 #include "layout.h"
17 #include "menu.h"
18 #include "ui_menu.h"
19 #include "ui_fileops.h"
20 #include "utilops.h"
21 #include "view_file_list.h"
22 #include "view_file_icon.h"
23
24 /*
25  *-----------------------------------------------------------------------------
26  * signals
27  *-----------------------------------------------------------------------------
28  */
29
30 void vf_send_update(ViewFile *vf)
31 {
32         if (vf->func_status) vf->func_status(vf, vf->data_status);
33 }
34
35 /*
36  *-----------------------------------------------------------------------------
37  * misc
38  *-----------------------------------------------------------------------------
39  */
40
41 void vf_sort_set(ViewFile *vf, SortType type, gint ascend)
42 {
43         switch (vf->type)
44         {
45         case FILEVIEW_LIST: vflist_sort_set(vf, type, ascend); break;
46         case FILEVIEW_ICON: vficon_sort_set(vf, type, ascend); break;
47         }
48 }
49
50 /*
51  *-----------------------------------------------------------------------------
52  * row stuff
53  *-----------------------------------------------------------------------------
54  */
55
56 FileData *vf_index_get_data(ViewFile *vf, gint row)
57 {
58         FileData *fd = NULL;
59
60         switch (vf->type)
61         {
62         case FILEVIEW_LIST: fd = vflist_index_get_data(vf, row); break;
63         case FILEVIEW_ICON: fd = vficon_index_get_data(vf, row); break;
64         }
65
66         return fd;
67 }
68
69 gint vf_index_by_path(ViewFile *vf, const gchar *path)
70 {
71         gint index = -1;
72
73         switch (vf->type)
74         {
75         case FILEVIEW_LIST: index = vflist_index_by_path(vf, path); break;
76         case FILEVIEW_ICON: index = vficon_index_by_path(vf, path); break;
77         }
78
79         return index;
80 }
81
82 guint vf_count(ViewFile *vf, gint64 *bytes)
83 {
84         guint count = 0;
85
86         switch (vf->type)
87         {
88         case FILEVIEW_LIST: count = vflist_count(vf, bytes); break;
89         case FILEVIEW_ICON: count = vficon_count(vf, bytes); break;
90         }
91
92         return count;
93 }
94
95 GList *vf_get_list(ViewFile *vf)
96 {
97         GList *list = NULL;
98
99         switch (vf->type)
100         {
101         case FILEVIEW_LIST: list = vflist_get_list(vf); break;
102         case FILEVIEW_ICON: list = vficon_get_list(vf); break;
103         }
104
105         return list;
106 }
107
108
109 /*
110  *-------------------------------------------------------------------
111  * keyboard
112  *-------------------------------------------------------------------
113  */
114
115 static gint vf_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
116 {
117         ViewFile *vf = data;
118         gint ret = FALSE;
119
120         switch (vf->type)
121         {
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;
124         }
125
126         return ret;
127 }
128
129 /*
130  *-------------------------------------------------------------------
131  * mouse
132  *-------------------------------------------------------------------
133  */
134
135 static gint vf_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
136 {
137         ViewFile *vf = data;
138         gint ret = FALSE;
139
140         switch (vf->type)
141         {
142         case FILEVIEW_LIST: ret = vflist_press_cb(widget, bevent, data); break;
143         case FILEVIEW_ICON: ret = vficon_press_cb(widget, bevent, data); break;
144         }
145
146         return ret;
147 }
148
149 static gint vf_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
150 {
151         ViewFile *vf = data;
152         gint ret = FALSE;
153
154         switch (vf->type)
155         {
156         case FILEVIEW_LIST: ret = vflist_release_cb(widget, bevent, data); break;
157         case FILEVIEW_ICON: ret = vficon_release_cb(widget, bevent, data); break;
158         }
159
160         return ret;
161 }
162
163
164 /*
165  *-----------------------------------------------------------------------------
166  * selections
167  *-----------------------------------------------------------------------------
168  */
169
170 guint vf_selection_count(ViewFile *vf, gint64 *bytes)
171 {
172         guint count = 0;
173
174         switch (vf->type)
175         {
176         case FILEVIEW_LIST: count = vflist_selection_count(vf, bytes); break;
177         case FILEVIEW_ICON: count = vficon_selection_count(vf, bytes); break;
178         }
179
180         return count;
181 }
182
183 GList *vf_selection_get_list(ViewFile *vf)
184 {
185         GList *list = NULL;
186
187         switch (vf->type)
188         {
189         case FILEVIEW_LIST: list = vflist_selection_get_list(vf); break;
190         case FILEVIEW_ICON: list = vficon_selection_get_list(vf); break;
191         }
192
193         return list;
194 }
195
196 GList *vf_selection_get_list_by_index(ViewFile *vf)
197 {
198         GList *list = NULL;
199
200         switch (vf->type)
201         {
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;
204         }
205
206         return list;
207 }
208
209 void vf_select_all(ViewFile *vf)
210 {
211         switch (vf->type)
212         {
213         case FILEVIEW_LIST: vflist_select_all(vf); break;
214         case FILEVIEW_ICON: vficon_select_all(vf); break;
215         }
216 }
217
218 void vf_select_none(ViewFile *vf)
219 {
220         switch (vf->type)
221         {
222         case FILEVIEW_LIST: vflist_select_none(vf); break;
223         case FILEVIEW_ICON: vficon_select_none(vf); break;
224         }
225 }
226
227 void vf_select_invert(ViewFile *vf)
228 {
229         switch (vf->type)
230         {
231         case FILEVIEW_LIST: vflist_select_invert(vf); break;
232         case FILEVIEW_ICON: vficon_select_invert(vf); break;
233         }
234 }
235
236 void vf_select_by_fd(ViewFile *vf, FileData *fd)
237 {
238         switch (vf->type)
239         {
240         case FILEVIEW_LIST: vflist_select_by_fd(vf, fd); break;
241         case FILEVIEW_ICON: vficon_select_by_fd(vf, fd); break;
242         }
243 }
244
245 void vf_mark_to_selection(ViewFile *vf, gint mark, MarkToSelectionMode mode)
246 {
247         switch (vf->type)
248         {
249         case FILEVIEW_LIST: vflist_mark_to_selection(vf, mark, mode); break;
250         case FILEVIEW_ICON: vficon_mark_to_selection(vf, mark, mode); break;
251         }
252 }
253
254 void vf_selection_to_mark(ViewFile *vf, gint mark, SelectionToMarkMode mode)
255 {
256         switch (vf->type)
257         {
258         case FILEVIEW_LIST: vflist_selection_to_mark(vf, mark, mode); break;
259         case FILEVIEW_ICON: vficon_selection_to_mark(vf, mark, mode); break;
260         }
261 }
262
263 /*
264  *-----------------------------------------------------------------------------
265  * dnd
266  *-----------------------------------------------------------------------------
267  */
268
269
270 static void vf_dnd_init(ViewFile *vf)
271 {
272         switch (vf->type)
273         {
274         case FILEVIEW_LIST: vflist_dnd_init(vf); break;
275         case FILEVIEW_ICON: vficon_dnd_init(vf); break;
276         }
277 }
278
279 /*
280  *-----------------------------------------------------------------------------
281  * pop-up menu
282  *-----------------------------------------------------------------------------
283  */
284
285 GList *vf_pop_menu_file_list(ViewFile *vf)
286 {
287         GList *ret = NULL;
288
289         switch (vf->type)
290         {
291         case FILEVIEW_LIST: ret = vflist_pop_menu_file_list(vf); break;
292         case FILEVIEW_ICON: ret = vficon_pop_menu_file_list(vf); break;
293         }
294
295         return ret;
296 }
297
298 static void vf_pop_menu_edit_cb(GtkWidget *widget, gpointer data)
299 {
300         ViewFile *vf;
301         const gchar *key = data;
302         GList *list;
303
304         vf = submenu_item_get_data(widget);
305
306         if (!vf) return;
307
308         list = vf_pop_menu_file_list(vf);
309         file_util_start_editor_from_filelist(key, list, vf->listview);
310         filelist_free(list);
311 }
312
313 static void vf_pop_menu_view_cb(GtkWidget *widget, gpointer data)
314 {
315         ViewFile *vf = data;
316
317         switch (vf->type)
318         {
319         case FILEVIEW_LIST: vflist_pop_menu_view_cb(widget, data); break;
320         case FILEVIEW_ICON: vficon_pop_menu_view_cb(widget, data); break;
321         }
322 }
323
324 static void vf_pop_menu_copy_cb(GtkWidget *widget, gpointer data)
325 {
326         ViewFile *vf = data;
327
328         file_util_copy(NULL, vf_pop_menu_file_list(vf), NULL, vf->listview);
329 }
330
331 static void vf_pop_menu_move_cb(GtkWidget *widget, gpointer data)
332 {
333         ViewFile *vf = data;
334
335         file_util_move(NULL, vf_pop_menu_file_list(vf), NULL, vf->listview);
336 }
337
338 static void vf_pop_menu_rename_cb(GtkWidget *widget, gpointer data)
339 {
340         ViewFile *vf = data;
341
342         switch (vf->type)
343         {
344         case FILEVIEW_LIST: vflist_pop_menu_rename_cb(widget, data); break;
345         case FILEVIEW_ICON: vficon_pop_menu_rename_cb(widget, data); break;
346         }
347 }
348
349 static void vf_pop_menu_delete_cb(GtkWidget *widget, gpointer data)
350 {
351         ViewFile *vf = data;
352
353         file_util_delete(NULL, vf_pop_menu_file_list(vf), vf->listview);
354 }
355
356 static void vf_pop_menu_copy_path_cb(GtkWidget *widget, gpointer data)
357 {
358         ViewFile *vf = data;
359
360         file_util_copy_path_list_to_clipboard(vf_pop_menu_file_list(vf));
361 }
362
363 static void vf_pop_menu_sort_cb(GtkWidget *widget, gpointer data)
364 {
365         ViewFile *vf;
366         SortType type;
367
368         if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))) return;
369
370         vf = submenu_item_get_data(widget);
371         if (!vf) return;
372
373         type = (SortType)GPOINTER_TO_INT(data);
374
375         if (vf->layout)
376                 {
377                 layout_sort_set(vf->layout, type, vf->sort_ascend);
378                 }
379         else
380                 {
381                 vf_sort_set(vf, type, vf->sort_ascend);
382                 }
383 }
384
385 static void vf_pop_menu_sort_ascend_cb(GtkWidget *widget, gpointer data)
386 {
387         ViewFile *vf = data;
388
389         if (vf->layout)
390                 {
391                 layout_sort_set(vf->layout, vf->sort_method, !vf->sort_ascend);
392                 }
393         else
394                 {
395                 vf_sort_set(vf, vf->sort_method, !vf->sort_ascend);
396                 }
397 }
398
399 static void vf_pop_menu_sel_mark_cb(GtkWidget *widget, gpointer data)
400 {
401         ViewFile *vf = data;
402         vf_mark_to_selection(vf, vf->active_mark, MTS_MODE_SET);
403 }
404
405 static void vf_pop_menu_sel_mark_and_cb(GtkWidget *widget, gpointer data)
406 {
407         ViewFile *vf = data;
408         vf_mark_to_selection(vf, vf->active_mark, MTS_MODE_AND);
409 }
410
411 static void vf_pop_menu_sel_mark_or_cb(GtkWidget *widget, gpointer data)
412 {
413         ViewFile *vf = data;
414         vf_mark_to_selection(vf, vf->active_mark, MTS_MODE_OR);
415 }
416
417 static void vf_pop_menu_sel_mark_minus_cb(GtkWidget *widget, gpointer data)
418 {
419         ViewFile *vf = data;
420         vf_mark_to_selection(vf, vf->active_mark, MTS_MODE_MINUS);
421 }
422
423 static void vf_pop_menu_set_mark_sel_cb(GtkWidget *widget, gpointer data)
424 {
425         ViewFile *vf = data;
426         vf_selection_to_mark(vf, vf->active_mark, STM_MODE_SET);
427 }
428
429 static void vf_pop_menu_res_mark_sel_cb(GtkWidget *widget, gpointer data)
430 {
431         ViewFile *vf = data;
432         vf_selection_to_mark(vf, vf->active_mark, STM_MODE_RESET);
433 }
434
435 static void vf_pop_menu_toggle_mark_sel_cb(GtkWidget *widget, gpointer data)
436 {
437         ViewFile *vf = data;
438         vf_selection_to_mark(vf, vf->active_mark, STM_MODE_TOGGLE);
439 }
440
441 static void vf_pop_menu_toggle_view_type_cb(GtkWidget *widget, gpointer data)
442 {
443         ViewFile *vf = data;
444         
445         if (!vf->layout) return;
446
447         switch (vf->layout->file_view_type)
448         {
449         case FILEVIEW_LIST:
450                 layout_views_set(vf->layout, vf->layout->options.dir_view_type, FILEVIEW_ICON);
451                 break;
452         case FILEVIEW_ICON:
453                 layout_views_set(vf->layout, vf->layout->options.dir_view_type, FILEVIEW_LIST);
454                 break;
455         }
456 }
457
458 static void vf_pop_menu_refresh_cb(GtkWidget *widget, gpointer data)
459 {
460         ViewFile *vf = data;
461
462         switch (vf->type)
463         {
464         case FILEVIEW_LIST: vflist_pop_menu_refresh_cb(widget, data); break;
465         case FILEVIEW_ICON: vficon_pop_menu_refresh_cb(widget, data); break;
466         }
467 }
468
469 static void vf_popup_destroy_cb(GtkWidget *widget, gpointer data)
470 {
471         ViewFile *vf = data;
472
473         switch (vf->type)
474         {
475         case FILEVIEW_LIST: vflist_popup_destroy_cb(widget, data); break;
476         case FILEVIEW_ICON: vficon_popup_destroy_cb(widget, data); break;
477         }
478 }
479
480 GtkWidget *vf_pop_menu(ViewFile *vf)
481 {
482         GtkWidget *menu;
483         GtkWidget *item;
484         GtkWidget *submenu;
485         gint active = 0;
486
487         switch (vf->type)
488         {
489         case FILEVIEW_LIST:
490                 vflist_color_set(vf, VFLIST(vf)->click_fd, TRUE);
491                 active = (VFLIST(vf)->click_fd != NULL);
492                 break;
493         case FILEVIEW_ICON:
494                 active = (VFICON(vf)->click_id != NULL);
495                 break;
496         }
497
498         menu = popup_menu_short_lived();
499
500         g_signal_connect(G_OBJECT(menu), "destroy",
501                          G_CALLBACK(vf_popup_destroy_cb), vf);
502
503         if (vf->clicked_mark > 0)
504                 {
505                 gint mark = vf->clicked_mark;
506                 gchar *str_set_mark = g_strdup_printf(_("_Set mark %d"), mark);
507                 gchar *str_res_mark = g_strdup_printf(_("_Reset mark %d"), mark);
508                 gchar *str_toggle_mark = g_strdup_printf(_("_Toggle mark %d"), mark);
509                 gchar *str_sel_mark = g_strdup_printf(_("_Select mark %d"), mark);
510                 gchar *str_sel_mark_or = g_strdup_printf(_("_Add mark %d"), mark);
511                 gchar *str_sel_mark_and = g_strdup_printf(_("_Intersection with mark %d"), mark);
512                 gchar *str_sel_mark_minus = g_strdup_printf(_("_Unselect mark %d"), mark);
513
514                 g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
515
516                 vf->active_mark = mark;
517                 vf->clicked_mark = 0;
518
519                 menu_item_add_sensitive(menu, str_set_mark, active,
520                                         G_CALLBACK(vf_pop_menu_set_mark_sel_cb), vf);
521
522                 menu_item_add_sensitive(menu, str_res_mark, active,
523                                         G_CALLBACK(vf_pop_menu_res_mark_sel_cb), vf);
524
525                 menu_item_add_sensitive(menu, str_toggle_mark, active,
526                                         G_CALLBACK(vf_pop_menu_toggle_mark_sel_cb), vf);
527
528                 menu_item_add_divider(menu);
529
530                 menu_item_add_sensitive(menu, str_sel_mark, active,
531                                         G_CALLBACK(vf_pop_menu_sel_mark_cb), vf);
532                 menu_item_add_sensitive(menu, str_sel_mark_or, active,
533                                         G_CALLBACK(vf_pop_menu_sel_mark_or_cb), vf);
534                 menu_item_add_sensitive(menu, str_sel_mark_and, active,
535                                         G_CALLBACK(vf_pop_menu_sel_mark_and_cb), vf);
536                 menu_item_add_sensitive(menu, str_sel_mark_minus, active,
537                                         G_CALLBACK(vf_pop_menu_sel_mark_minus_cb), vf);
538
539                 menu_item_add_divider(menu);
540
541                 g_free(str_set_mark);
542                 g_free(str_res_mark);
543                 g_free(str_toggle_mark);
544                 g_free(str_sel_mark);
545                 g_free(str_sel_mark_and);
546                 g_free(str_sel_mark_or);
547                 g_free(str_sel_mark_minus);
548                 }
549
550         submenu_add_edit(menu, &item, G_CALLBACK(vf_pop_menu_edit_cb), vf);
551         gtk_widget_set_sensitive(item, active);
552
553         menu_item_add_stock_sensitive(menu, _("View in _new window"), GTK_STOCK_NEW, active,
554                                       G_CALLBACK(vf_pop_menu_view_cb), vf);
555
556         menu_item_add_divider(menu);
557         menu_item_add_stock_sensitive(menu, _("_Copy..."), GTK_STOCK_COPY, active,
558                                       G_CALLBACK(vf_pop_menu_copy_cb), vf);
559         menu_item_add_sensitive(menu, _("_Move..."), active,
560                                 G_CALLBACK(vf_pop_menu_move_cb), vf);
561         menu_item_add_sensitive(menu, _("_Rename..."), active,
562                                 G_CALLBACK(vf_pop_menu_rename_cb), vf);
563         menu_item_add_stock_sensitive(menu, _("_Delete..."), GTK_STOCK_DELETE, active,
564                                       G_CALLBACK(vf_pop_menu_delete_cb), vf);
565         if (options->show_copy_path)
566                 menu_item_add_sensitive(menu, _("_Copy path"), active,
567                                         G_CALLBACK(vf_pop_menu_copy_path_cb), vf);
568
569         menu_item_add_divider(menu);
570
571         submenu = submenu_add_sort(NULL, G_CALLBACK(vf_pop_menu_sort_cb), vf,
572                                    FALSE, FALSE, TRUE, vf->sort_method);
573         menu_item_add_divider(submenu);
574         menu_item_add_check(submenu, _("Ascending"), vf->sort_ascend,
575                             G_CALLBACK(vf_pop_menu_sort_ascend_cb), vf);
576
577         item = menu_item_add(menu, _("_Sort"), NULL, NULL);
578         gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
579
580         menu_item_add_check(menu, _("View as _icons"), (vf->type == FILEVIEW_ICON),
581                             G_CALLBACK(vf_pop_menu_toggle_view_type_cb), vf);
582
583         switch (vf->type)
584         {
585         case FILEVIEW_LIST:
586                 menu_item_add_check(menu, _("Show _thumbnails"), VFLIST(vf)->thumbs_enabled,
587                                     G_CALLBACK(vflist_pop_menu_thumbs_cb), vf);
588                 break;
589         case FILEVIEW_ICON:
590                 menu_item_add_check(menu, _("Show filename _text"), VFICON(vf)->show_text,
591                                     G_CALLBACK(vficon_pop_menu_show_names_cb), vf);
592                 break;
593         }
594         
595         menu_item_add_stock(menu, _("Re_fresh"), GTK_STOCK_REFRESH, G_CALLBACK(vf_pop_menu_refresh_cb), vf);
596
597         return menu;
598 }
599
600 gint vf_refresh(ViewFile *vf)
601 {
602         gint ret = FALSE;
603
604         switch (vf->type)
605         {
606         case FILEVIEW_LIST: ret = vflist_refresh(vf); break;
607         case FILEVIEW_ICON: ret = vficon_refresh(vf); break;
608         }
609
610         return ret;
611 }
612
613 gint vf_set_fd(ViewFile *vf, FileData *dir_fd)
614 {
615         gint ret = FALSE;
616
617         switch (vf->type)
618         {
619         case FILEVIEW_LIST: ret = vflist_set_fd(vf, dir_fd); break;
620         case FILEVIEW_ICON: ret = vficon_set_fd(vf, dir_fd); break;
621         }
622         
623         return ret;
624 }
625
626 static void vf_destroy_cb(GtkWidget *widget, gpointer data)
627 {
628         ViewFile *vf = data;
629
630         switch (vf->type)
631         {
632         case FILEVIEW_LIST: vflist_destroy_cb(widget, data); break;
633         case FILEVIEW_ICON: vficon_destroy_cb(widget, data); break;
634         }
635
636         if (vf->popup)
637                 {
638                 g_signal_handlers_disconnect_matched(G_OBJECT(vf->popup), G_SIGNAL_MATCH_DATA,
639                                                      0, 0, 0, NULL, vf);
640                 gtk_widget_destroy(vf->popup);
641                 }
642
643         file_data_unref(vf->dir_fd);
644         g_free(vf->info);
645         g_free(vf);
646 }
647
648 static void vf_marks_filter_toggle_cb(GtkWidget *widget, gpointer data)
649 {
650         ViewFile *vf = data;
651         vf_refresh_idle(vf);
652 }
653
654
655 static GtkWidget *vf_marks_filter_init(ViewFile *vf)
656 {
657         GtkWidget *frame = gtk_frame_new(NULL);
658         GtkWidget *hbox = gtk_hbox_new(FALSE, 0);
659         
660         gint i;
661         
662         for (i = 0; i < FILEDATA_MARKS_SIZE ; i++)
663                 {
664                 GtkWidget *check = gtk_check_button_new();
665                 gtk_box_pack_start(GTK_BOX(hbox), check, FALSE, FALSE, 0);
666                 g_signal_connect(G_OBJECT(check), "toggled",
667                          G_CALLBACK(vf_marks_filter_toggle_cb), vf);
668
669                 gtk_widget_show(check);
670                 vf->filter_check[i] = check;
671                 }
672         gtk_container_add(GTK_CONTAINER(frame), hbox);
673         gtk_widget_show(hbox);
674         return frame;
675 }
676
677 ViewFile *vf_new(FileViewType type, FileData *dir_fd)
678 {
679         ViewFile *vf;
680
681         vf = g_new0(ViewFile, 1);
682         vf->type = type;
683
684         vf->info = NULL;
685         vf->dir_fd = NULL;
686         vf->list = NULL;
687
688         vf->sort_method = SORT_NAME;
689         vf->sort_ascend = TRUE;
690         
691         vf->thumbs_running = FALSE;
692         vf->thumbs_loader = NULL;
693         vf->thumbs_filedata = NULL;
694
695         vf->popup = NULL;
696
697         vf->refresh_idle_id = -1;
698
699         vf->scrolled = gtk_scrolled_window_new(NULL, NULL);
700         gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(vf->scrolled), GTK_SHADOW_IN);
701         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(vf->scrolled),
702                                        GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
703         
704         vf->filter = vf_marks_filter_init(vf);
705
706         vf->widget = gtk_vbox_new(FALSE, 0);
707         gtk_box_pack_start(GTK_BOX(vf->widget), vf->filter, FALSE, FALSE, 0);
708         gtk_box_pack_start(GTK_BOX(vf->widget), vf->scrolled, TRUE, TRUE, 0);
709         gtk_widget_show(vf->scrolled);
710         
711         g_signal_connect(G_OBJECT(vf->widget), "destroy",
712                          G_CALLBACK(vf_destroy_cb), vf);
713
714         switch (type)
715         {
716         case FILEVIEW_LIST: vf = vflist_new(vf, dir_fd); break;
717         case FILEVIEW_ICON: vf = vficon_new(vf, dir_fd); break;
718         }
719
720         vf_dnd_init(vf);
721
722         g_signal_connect(G_OBJECT(vf->listview), "key_press_event",
723                          G_CALLBACK(vf_press_key_cb), vf);
724         g_signal_connect(G_OBJECT(vf->listview), "button_press_event",
725                          G_CALLBACK(vf_press_cb), vf);
726         g_signal_connect(G_OBJECT(vf->listview), "button_release_event",
727                          G_CALLBACK(vf_release_cb), vf);
728
729         gtk_container_add(GTK_CONTAINER(vf->scrolled), vf->listview);
730         gtk_widget_show(vf->listview);
731
732         if (dir_fd) vf_set_fd(vf, dir_fd);
733
734         return vf;
735 }
736
737 void vf_set_status_func(ViewFile *vf, void (*func)(ViewFile *vf, gpointer data), gpointer data)
738 {
739         vf->func_status = func;
740         vf->data_status = data;
741 }
742
743 void vf_set_thumb_status_func(ViewFile *vf, void (*func)(ViewFile *vf, gdouble val, const gchar *text, gpointer data), gpointer data)
744 {
745         vf->func_thumb_status = func;
746         vf->data_thumb_status = data;
747 }
748
749 void vf_thumb_set(ViewFile *vf, gint enable)
750 {
751         switch (vf->type)
752         {
753         case FILEVIEW_LIST: vflist_thumb_set(vf, enable); break;
754         case FILEVIEW_ICON: /*vficon_thumb_set(vf, enable);*/ break;
755         }
756 }
757
758 void vf_marks_set(ViewFile *vf, gint enable)
759 {
760         if (vf->marks_enabled == enable) return;
761
762         vf->marks_enabled = enable;
763
764         switch (vf->type)
765         {
766         case FILEVIEW_LIST: vflist_marks_set(vf, enable); break;
767         case FILEVIEW_ICON: vficon_marks_set(vf, enable); break;
768         }
769         if (enable)
770                 gtk_widget_show(vf->filter);
771         else
772                 gtk_widget_hide(vf->filter);
773
774         vf_refresh_idle(vf);
775 }
776
777 guint vf_marks_get_filter(ViewFile *vf)
778 {
779         guint ret = 0;
780         gint i;
781         if (!vf->marks_enabled) return 0;
782         
783         for (i = 0; i < FILEDATA_MARKS_SIZE ; i++)
784                 {
785                 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(vf->filter_check[i])))
786                         {
787                         ret |= 1 << i;
788                         }
789                 }
790         return ret;
791 }
792
793 void vf_set_layout(ViewFile *vf, LayoutWindow *layout)
794 {
795         vf->layout = layout;
796 }
797
798
799 /*
800  *-----------------------------------------------------------------------------
801  * maintenance (for rename, move, remove)
802  *-----------------------------------------------------------------------------
803  */
804
805 static gint vf_refresh_idle_cb(gpointer data)
806 {
807         ViewFile *vf = data;
808
809         vf_refresh(vf);
810         vf->refresh_idle_id = -1;
811         return FALSE;
812 }
813
814 void vf_refresh_idle_cancel(ViewFile *vf)
815 {
816         if (vf->refresh_idle_id != -1) g_source_remove(vf->refresh_idle_id);
817         vf->refresh_idle_id = -1;
818 }
819
820
821 void vf_refresh_idle(ViewFile *vf)
822 {
823         if (vf->refresh_idle_id == -1)
824                 {
825                 vf->refresh_idle_id = g_idle_add(vf_refresh_idle_cb, vf);
826                 }
827 }
828
829 void vf_notify_cb(FileData *fd, NotifyType type, gpointer data)
830 {
831         ViewFile *vf = data;
832         gboolean refresh;
833
834         if (vf->refresh_idle_id != -1) return;
835
836         if (!vf->dir_fd) return;
837
838         refresh = (fd == vf->dir_fd);
839
840         if (!refresh)
841                 {
842                 gchar *base = remove_level_from_path(fd->path);
843                 refresh = (strcmp(base, vf->dir_fd->path) == 0);
844                 g_free(base);
845                 }
846
847         if (type == NOTIFY_TYPE_CHANGE && fd->change)
848                 {
849                 if (!refresh && fd->change->dest)
850                         {
851                         gchar *dest_base = remove_level_from_path(fd->change->dest);
852                         refresh = (strcmp(dest_base, vf->dir_fd->path) == 0);
853                         g_free(dest_base);
854                         }
855
856                 if (!refresh && fd->change->source)
857                         {
858                         gchar *source_base = remove_level_from_path(fd->change->source);
859                         refresh = (strcmp(source_base, vf->dir_fd->path) == 0);
860                         g_free(source_base);
861                         }
862                 }
863         
864         if (refresh)
865                 {
866                 vf_refresh_idle(vf);
867                 }
868 }
869
870 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */