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