Introduce vf_pop_menu_file_list() as a wrapper to
[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 "debug.h"
16 #include "view_file_list.h"
17 #include "view_file_icon.h"
18
19 /*
20  *-----------------------------------------------------------------------------
21  * signals
22  *-----------------------------------------------------------------------------
23  */
24
25 void vf_send_update(ViewFile *vf)
26 {
27         if (vf->func_status) vf->func_status(vf, vf->data_status);
28 }
29
30 /*
31  *-----------------------------------------------------------------------------
32  * misc
33  *-----------------------------------------------------------------------------
34  */
35
36 void vf_sort_set(ViewFile *vf, SortType type, gint ascend)
37 {
38         switch(vf->type)
39         {
40         case FILEVIEW_LIST: vflist_sort_set(vf, type, ascend); break;
41         case FILEVIEW_ICON: vficon_sort_set(vf, type, ascend); break;
42         }
43 }
44
45 /*
46  *-----------------------------------------------------------------------------
47  * row stuff
48  *-----------------------------------------------------------------------------
49  */
50
51 FileData *vf_index_get_data(ViewFile *vf, gint row)
52 {
53         FileData *fd = NULL;
54
55         switch(vf->type)
56         {
57         case FILEVIEW_LIST: fd = vflist_index_get_data(vf, row); break;
58         case FILEVIEW_ICON: fd = vficon_index_get_data(vf, row); break;
59         }
60
61         return fd;
62 }
63
64 gint vf_index_by_path(ViewFile *vf, const gchar *path)
65 {
66         gint index = -1;
67
68         switch(vf->type)
69         {
70         case FILEVIEW_LIST: index = vflist_index_by_path(vf, path); break;
71         case FILEVIEW_ICON: index = vficon_index_by_path(vf, path); break;
72         }
73
74         return index;
75 }
76
77 gint vf_count(ViewFile *vf, gint64 *bytes)
78 {
79         gint count = 0;
80
81         switch(vf->type)
82         {
83         case FILEVIEW_LIST: count = vflist_count(vf, bytes); break;
84         case FILEVIEW_ICON: count = vficon_count(vf, bytes); break;
85         }
86
87         return count;
88 }
89
90 GList *vf_get_list(ViewFile *vf)
91 {
92         GList *list = NULL;
93
94         switch(vf->type)
95         {
96         case FILEVIEW_LIST: list = vflist_get_list(vf); break;
97         case FILEVIEW_ICON: list = vficon_get_list(vf); break;
98         }
99
100         return list;
101 }
102
103
104 /*
105  *-------------------------------------------------------------------
106  * keyboard
107  *-------------------------------------------------------------------
108  */
109
110 static gint vf_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
111 {
112         ViewFile *vf = data;
113         gint ret = FALSE;
114
115         switch(vf->type)
116         {
117         case FILEVIEW_LIST: ret = vflist_press_key_cb(widget, event, data); break;
118         case FILEVIEW_ICON: ret = vficon_press_key_cb(widget, event, data); break;
119         }
120
121         return ret;
122 }
123
124 /*
125  *-------------------------------------------------------------------
126  * mouse
127  *-------------------------------------------------------------------
128  */
129
130 static gint vf_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
131 {
132         ViewFile *vf = data;
133         gint ret = FALSE;
134
135         switch(vf->type)
136         {
137         case FILEVIEW_LIST: ret = vflist_press_cb(widget, bevent, data); break;
138         case FILEVIEW_ICON: ret = vficon_press_cb(widget, bevent, data); break;
139         }
140
141         return ret;
142 }
143
144 static gint vf_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
145 {
146         ViewFile *vf = data;
147         gint ret = FALSE;
148
149         switch(vf->type)
150         {
151         case FILEVIEW_LIST: ret = vflist_release_cb(widget, bevent, data); break;
152         case FILEVIEW_ICON: ret = vficon_release_cb(widget, bevent, data); break;
153         }
154
155         return ret;
156 }
157
158
159 /*
160  *-----------------------------------------------------------------------------
161  * selections
162  *-----------------------------------------------------------------------------
163  */
164
165 gint vf_selection_count(ViewFile *vf, gint64 *bytes)
166 {
167         gint count = 0;
168
169         switch(vf->type)
170         {
171         case FILEVIEW_LIST: count = vflist_selection_count(vf, bytes); break;
172         case FILEVIEW_ICON: count = vficon_selection_count(vf, bytes); break;
173         }
174
175         return count;
176 }
177
178 GList *vf_selection_get_list(ViewFile *vf)
179 {
180         GList *list = NULL;
181
182         switch(vf->type)
183         {
184         case FILEVIEW_LIST: list = vflist_selection_get_list(vf); break;
185         case FILEVIEW_ICON: list = vficon_selection_get_list(vf); break;
186         }
187
188         return list;
189 }
190
191 GList *vf_selection_get_list_by_index(ViewFile *vf)
192 {
193         GList *list = NULL;
194
195         switch(vf->type)
196         {
197         case FILEVIEW_LIST: list = vflist_selection_get_list_by_index(vf); break;
198         case FILEVIEW_ICON: list = vficon_selection_get_list_by_index(vf); break;
199         }
200
201         return list;
202 }
203
204 void vf_select_all(ViewFile *vf)
205 {
206         switch(vf->type)
207         {
208         case FILEVIEW_LIST: vflist_select_all(vf); break;
209         case FILEVIEW_ICON: vficon_select_all(vf); break;
210         }
211 }
212
213 void vf_select_none(ViewFile *vf)
214 {
215         switch(vf->type)
216         {
217         case FILEVIEW_LIST: vflist_select_none(vf); break;
218         case FILEVIEW_ICON: vficon_select_none(vf); break;
219         }
220 }
221
222 void vf_select_invert(ViewFile *vf)
223 {
224         switch(vf->type)
225         {
226         case FILEVIEW_LIST: vflist_select_invert(vf); break;
227         case FILEVIEW_ICON: vficon_select_invert(vf); break;
228         }
229 }
230
231 void vf_select_by_fd(ViewFile *vf, FileData *fd)
232 {
233         switch(vf->type)
234         {
235         case FILEVIEW_LIST: vflist_select_by_fd(vf, fd); break;
236         case FILEVIEW_ICON: vficon_select_by_fd(vf, fd); break;
237         }
238 }
239
240 void vf_mark_to_selection(ViewFile *vf, gint mark, MarkToSelectionMode mode)
241 {
242         switch(vf->type)
243         {
244         case FILEVIEW_LIST: vflist_mark_to_selection(vf, mark, mode); break;
245         case FILEVIEW_ICON: vficon_mark_to_selection(vf, mark, mode); break;
246         }
247 }
248
249 void vf_selection_to_mark(ViewFile *vf, gint mark, SelectionToMarkMode mode)
250 {
251         switch(vf->type)
252         {
253         case FILEVIEW_LIST: vflist_selection_to_mark(vf, mark, mode); break;
254         case FILEVIEW_ICON: vficon_selection_to_mark(vf, mark, mode); break;
255         }
256 }
257
258 /*
259  *-----------------------------------------------------------------------------
260  * dnd
261  *-----------------------------------------------------------------------------
262  */
263
264
265 static void vf_dnd_init(ViewFile *vf)
266 {
267         switch(vf->type)
268         {
269         case FILEVIEW_LIST: vflist_dnd_init(vf); break;
270         case FILEVIEW_ICON: vficon_dnd_init(vf); break;
271         }
272 }
273
274 /*
275  *-----------------------------------------------------------------------------
276  * pop-up menu
277  *-----------------------------------------------------------------------------
278  */
279
280 GList *vf_pop_menu_file_list(ViewFile *vf)
281 {
282         GList *ret = NULL;
283
284         switch(vf->type)
285         {
286         case FILEVIEW_LIST: ret = vflist_pop_menu_file_list(vf); break;
287         case FILEVIEW_ICON: ret = vficon_pop_menu_file_list(vf); break;
288         }
289
290         return ret;
291 }
292
293
294
295
296 gint vf_refresh(ViewFile *vf)
297 {
298         gint ret = FALSE;
299
300         switch(vf->type)
301         {
302         case FILEVIEW_LIST: ret = vflist_refresh(vf); break;
303         case FILEVIEW_ICON: ret = vficon_refresh(vf); break;
304         }
305
306         return ret;
307 }
308
309 gint vf_set_path(ViewFile *vf, const gchar *path)
310 {
311         gint ret = FALSE;
312
313         switch(vf->type)
314         {
315         case FILEVIEW_LIST: ret = vflist_set_path(vf, path); break;
316         case FILEVIEW_ICON: ret = vficon_set_path(vf, path); break;
317         }
318         
319         return ret;
320 }
321
322 static void vf_destroy_cb(GtkWidget *widget, gpointer data)
323 {
324         ViewFile *vf = data;
325
326         switch(vf->type)
327         {
328         case FILEVIEW_LIST: vflist_destroy_cb(widget, data); break;
329         case FILEVIEW_ICON: vficon_destroy_cb(widget, data); break;
330         }
331
332         if (vf->popup)
333                 {
334                 g_signal_handlers_disconnect_matched(G_OBJECT(vf->popup), G_SIGNAL_MATCH_DATA,
335                                                      0, 0, 0, NULL, vf);
336                 gtk_widget_destroy(vf->popup);
337                 }
338
339         g_free(vf->path);
340         g_free(vf->info);
341         g_free(vf);
342 }
343
344 ViewFile *vf_new(FileViewType type, const gchar *path)
345 {
346         ViewFile *vf;
347
348         vf = g_new0(ViewFile, 1);
349         vf->type = type;
350
351         vf->info = NULL;
352         vf->path = NULL;
353         vf->list = NULL;
354
355         vf->sort_method = SORT_NAME;
356         vf->sort_ascend = TRUE;
357         
358         vf->thumbs_running = FALSE;
359         vf->thumbs_count = 0;
360         vf->thumbs_loader = NULL;
361         vf->thumbs_filedata = NULL;
362
363         vf->popup = NULL;
364
365         vf->widget = gtk_scrolled_window_new(NULL, NULL);
366         gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(vf->widget), GTK_SHADOW_IN);
367         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(vf->widget),
368                                        GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
369         
370         g_signal_connect(G_OBJECT(vf->widget), "destroy",
371                          G_CALLBACK(vf_destroy_cb), vf);
372
373         switch(type)
374         {
375         case FILEVIEW_LIST: vf = vflist_new(vf, path); break;
376         case FILEVIEW_ICON: vf = vficon_new(vf, path); break;
377         }
378
379         vf_dnd_init(vf);
380
381         g_signal_connect(G_OBJECT(vf->listview), "key_press_event",
382                          G_CALLBACK(vf_press_key_cb), vf);
383         g_signal_connect(G_OBJECT(vf->listview), "button_press_event",
384                          G_CALLBACK(vf_press_cb), vf);
385         g_signal_connect(G_OBJECT(vf->listview), "button_release_event",
386                          G_CALLBACK(vf_release_cb), vf);
387
388         gtk_container_add(GTK_CONTAINER(vf->widget), vf->listview);
389         gtk_widget_show(vf->listview);
390
391         if (path) vf_set_path(vf, path);
392
393         return vf;
394 }
395
396 void vf_set_status_func(ViewFile *vf, void (*func)(ViewFile *vf, gpointer data), gpointer data)
397 {
398         vf->func_status = func;
399         vf->data_status = data;
400 }
401
402 void vf_set_thumb_status_func(ViewFile *vf, void (*func)(ViewFile *vf, gdouble val, const gchar *text, gpointer data), gpointer data)
403 {
404         vf->func_thumb_status = func;
405         vf->data_thumb_status = data;
406 }
407
408 void vf_thumb_set(ViewFile *vf, gint enable)
409 {
410         switch(vf->type)
411         {
412         case FILEVIEW_LIST: vflist_thumb_set(vf, enable); break;
413         case FILEVIEW_ICON: /*vficon_thumb_set(vf, enable);*/ break;
414         }
415 }
416
417 void vf_marks_set(ViewFile *vf, gint enable)
418 {
419         switch(vf->type)
420         {
421         case FILEVIEW_LIST: vflist_marks_set(vf, enable); break;
422         case FILEVIEW_ICON: /*vficon_marks_set(vf, enable);*/ break;
423         }
424 }
425
426 void vf_set_layout(ViewFile *vf, LayoutWindow *layout)
427 {
428         vf->layout = layout;
429 }
430
431 /*
432  *-----------------------------------------------------------------------------
433  * maintenance (for rename, move, remove)
434  *-----------------------------------------------------------------------------
435  */
436
437 gint vf_maint_renamed(ViewFile *vf, FileData *fd)
438 {
439         gint ret = FALSE;
440
441         switch(vf->type)
442         {
443         case FILEVIEW_LIST: ret = vflist_maint_renamed(vf, fd); break;
444         case FILEVIEW_ICON: ret = vficon_maint_renamed(vf, fd); break;
445         }
446
447         return ret;
448 }
449
450 gint vf_maint_removed(ViewFile *vf, FileData *fd, GList *ignore_list)
451 {
452         gint ret = FALSE;
453
454         switch(vf->type)
455         {
456         case FILEVIEW_LIST: ret = vflist_maint_removed(vf, fd, ignore_list); break;
457         case FILEVIEW_ICON: ret = vficon_maint_removed(vf, fd, ignore_list); break;
458         }
459
460         return ret;
461 }
462
463 gint vf_maint_moved(ViewFile *vf, FileData *fd, GList *ignore_list)
464 {
465         gint ret = FALSE;
466
467         switch(vf->type)
468         {
469         case FILEVIEW_LIST: ret = vflist_maint_moved(vf, fd, ignore_list); break;
470         case FILEVIEW_ICON: ret = vficon_maint_moved(vf, fd, ignore_list); break;
471         }
472
473         return ret;
474 }