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