Mercurial > geeqie.yaz
annotate src/slideshow.c @ 804:e702eaa6d1df
vficon_sync speed-up
author | nadvornik |
---|---|
date | Sun, 08 Jun 2008 20:24:46 +0000 |
parents | d6a7fb4b8e7c |
children | ad420f2eb789 |
rev | line source |
---|---|
1 | 1 /* |
196 | 2 * Geeqie |
9 | 3 * (C) 2004 John Ellis |
475 | 4 * Copyright (C) 2008 The Geeqie Team |
1 | 5 * |
6 * Author: John Ellis | |
7 * | |
9 | 8 * This software is released under the GNU General Public License (GNU GPL). |
9 * Please read the included file COPYING for more information. | |
10 * This software comes with no warranty of any kind, use at your own risk! | |
1 | 11 */ |
12 | |
9 | 13 |
281 | 14 #include "main.h" |
9 | 15 #include "collect.h" |
16 #include "image.h" | |
17 #include "slideshow.h" | |
586 | 18 #include "filedata.h" |
1 | 19 |
9 | 20 #include "layout.h" |
21 #include "layout_image.h" | |
22 #include "ui_fileops.h" | |
1 | 23 |
9 | 24 |
744
eb7e0d3206a2
Move code from slideshow_timer_reset() to new slideshow_timer_stop() and simplify calls.
zas_
parents:
736
diff
changeset
|
25 static void slideshow_timer_stop(SlideShowData *ss); |
9 | 26 |
1 | 27 |
9 | 28 void slideshow_free(SlideShowData *ss) |
29 { | |
89
b3149a34d0dd
Sat Oct 28 14:41:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
30 if (!ss) return; |
b3149a34d0dd
Sat Oct 28 14:41:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
31 |
744
eb7e0d3206a2
Move code from slideshow_timer_reset() to new slideshow_timer_stop() and simplify calls.
zas_
parents:
736
diff
changeset
|
32 slideshow_timer_stop(ss); |
1 | 33 |
9 | 34 if (ss->stop_func) ss->stop_func(ss, ss->stop_data); |
3 | 35 |
138 | 36 if (ss->filelist) filelist_free(ss->filelist); |
9 | 37 if (ss->cd) collection_unref(ss->cd); |
783 | 38 file_data_unref(ss->dir_fd); |
1 | 39 |
9 | 40 g_list_free(ss->list); |
41 g_list_free(ss->list_done); | |
1 | 42 |
138 | 43 file_data_unref(ss->slide_fd); |
9 | 44 |
45 g_free(ss); | |
1 | 46 } |
47 | |
9 | 48 static GList *generate_list(SlideShowData *ss) |
1 | 49 { |
50 GList *list = NULL; | |
51 | |
9 | 52 if (ss->from_selection) |
53 { | |
54 list = layout_selection_list_by_index(ss->layout); | |
55 } | |
56 else | |
1 | 57 { |
736 | 58 guint i; |
517 | 59 for (i = 0; i < ss->slide_count; i++) |
1 | 60 { |
61 list = g_list_prepend(list, GINT_TO_POINTER(i)); | |
62 } | |
9 | 63 list = g_list_reverse(list); |
1 | 64 } |
65 | |
66 return list; | |
67 } | |
68 | |
9 | 69 static GList *generate_random_list(SlideShowData *ss) |
1 | 70 { |
71 GList *src_list = NULL; | |
72 GList *list = NULL; | |
73 GList *work; | |
74 | |
9 | 75 src_list = generate_list(ss); |
1 | 76 |
516 | 77 while (src_list) |
1 | 78 { |
9 | 79 gint p = (double)rand() / ((double)RAND_MAX + 1.0) * g_list_length(src_list); |
1 | 80 work = g_list_nth(src_list, p); |
81 list = g_list_prepend(list, work->data); | |
82 src_list = g_list_remove(src_list, work->data); | |
83 } | |
84 | |
85 return list; | |
86 } | |
87 | |
9 | 88 static void slideshow_list_init(SlideShowData *ss, gint start_index) |
1 | 89 { |
9 | 90 if (ss->list_done) |
1 | 91 { |
9 | 92 g_list_free(ss->list_done); |
93 ss->list_done = NULL; | |
1 | 94 } |
95 | |
9 | 96 if (ss->list) g_list_free(ss->list); |
3 | 97 |
326 | 98 if (options->slideshow.random) |
1 | 99 { |
9 | 100 ss->list = generate_random_list(ss); |
1 | 101 } |
102 else | |
103 { | |
9 | 104 ss->list = generate_list(ss); |
105 if (start_index >= 0) | |
3 | 106 { |
9 | 107 /* start with specified image by skipping to it */ |
108 gint i = 0; | |
109 | |
516 | 110 while (ss->list && i < start_index) |
9 | 111 { |
513
985fdfebd89e
Remove whitespace between function name and first parenthesis for the sake of consistency. (pass 2)
zas_
parents:
475
diff
changeset
|
112 ss->list_done = g_list_prepend(ss->list_done, ss->list->data); |
9 | 113 ss->list = g_list_remove(ss->list, ss->list->data); |
114 i++; | |
115 } | |
3 | 116 } |
117 } | |
118 } | |
119 | |
9 | 120 gint slideshow_should_continue(SlideShowData *ss) |
1 | 121 { |
138 | 122 FileData *imd_fd; |
783 | 123 FileData *dir_fd; |
9 | 124 |
89
b3149a34d0dd
Sat Oct 28 14:41:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
125 if (!ss) return FALSE; |
b3149a34d0dd
Sat Oct 28 14:41:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
126 |
138 | 127 imd_fd = image_get_fd(ss->imd); |
9 | 128 |
138 | 129 if ( ((imd_fd == NULL) != (ss->slide_fd == NULL)) || |
130 (imd_fd && ss->slide_fd && imd_fd != ss->slide_fd) ) return FALSE; | |
9 | 131 |
138 | 132 if (ss->filelist) return TRUE; |
9 | 133 |
134 if (ss->cd) | |
135 { | |
136 if (g_list_length(ss->cd->list) == ss->slide_count) | |
137 return TRUE; | |
138 else | |
139 return FALSE; | |
140 } | |
141 | |
142 if (!ss->layout) return FALSE; | |
783 | 143 dir_fd = ss->layout->dir_fd; |
9 | 144 |
783 | 145 if (dir_fd && ss->dir_fd && dir_fd == ss->dir_fd) |
9 | 146 { |
147 if (ss->from_selection && ss->slide_count == layout_selection_count(ss->layout, NULL)) return TRUE; | |
148 if (!ss->from_selection && ss->slide_count == layout_list_count(ss->layout, NULL)) return TRUE; | |
149 } | |
150 | |
151 return FALSE; | |
152 } | |
153 | |
745
41dc324ee014
slideshow_next(), slideshow_prev(): move code to common slideshow_move(), reducing code redundancy.
zas_
parents:
744
diff
changeset
|
154 static gint slideshow_step(SlideShowData *ss, gboolean forward) |
9 | 155 { |
156 gint row; | |
157 | |
158 if (!slideshow_should_continue(ss)) | |
1 | 159 { |
160 return FALSE; | |
161 } | |
162 | |
9 | 163 if (forward) |
164 { | |
165 if (!ss->list) return TRUE; | |
1 | 166 |
9 | 167 row = GPOINTER_TO_INT(ss->list->data); |
513
985fdfebd89e
Remove whitespace between function name and first parenthesis for the sake of consistency. (pass 2)
zas_
parents:
475
diff
changeset
|
168 ss->list_done = g_list_prepend(ss->list_done, ss->list->data); |
9 | 169 ss->list = g_list_remove(ss->list, ss->list->data); |
170 } | |
171 else | |
172 { | |
173 if (!ss->list_done || !ss->list_done->next) return TRUE; | |
3 | 174 |
9 | 175 ss->list = g_list_prepend(ss->list, ss->list_done->data); |
176 ss->list_done = g_list_remove(ss->list_done, ss->list_done->data); | |
177 row = GPOINTER_TO_INT(ss->list_done->data); | |
3 | 178 } |
179 | |
138 | 180 file_data_unref(ss->slide_fd); |
181 ss->slide_fd = NULL; | |
3 | 182 |
138 | 183 if (ss->filelist) |
9 | 184 { |
138 | 185 ss->slide_fd = file_data_ref((FileData *)g_list_nth_data(ss->filelist, row)); |
334 | 186 image_change_fd(ss->imd, ss->slide_fd, image_zoom_get_default(ss->imd, options->image.zoom_mode)); |
9 | 187 } |
188 else if (ss->cd) | |
189 { | |
190 CollectInfo *info; | |
3 | 191 |
9 | 192 info = g_list_nth_data(ss->cd->list, row); |
138 | 193 ss->slide_fd = file_data_ref(info->fd); |
9 | 194 |
334 | 195 image_change_from_collection(ss->imd, ss->cd, info, image_zoom_get_default(ss->imd, options->image.zoom_mode)); |
3 | 196 } |
197 else | |
198 { | |
138 | 199 ss->slide_fd = file_data_ref(layout_list_get_fd(ss->layout, row)); |
9 | 200 |
201 if (ss->from_selection) | |
202 { | |
334 | 203 image_change_fd(ss->imd, ss->slide_fd, image_zoom_get_default(ss->imd, options->image.zoom_mode)); |
9 | 204 layout_status_update_info(ss->layout, NULL); |
205 } | |
206 else | |
207 { | |
208 layout_image_set_index(ss->layout, row); | |
209 } | |
3 | 210 } |
211 | |
326 | 212 if (!ss->list && options->slideshow.repeat) |
9 | 213 { |
214 slideshow_list_init(ss, -1); | |
215 } | |
3 | 216 |
9 | 217 if (!ss->list) |
1 | 218 { |
219 return FALSE; | |
220 } | |
221 | |
9 | 222 /* read ahead */ |
1 | 223 |
334 | 224 if (options->image.enable_read_ahead) |
1 | 225 { |
9 | 226 gint r; |
227 if (forward) | |
228 { | |
229 if (!ss->list) return TRUE; | |
230 r = GPOINTER_TO_INT(ss->list->data); | |
231 } | |
232 else | |
233 { | |
234 if (!ss->list_done || !ss->list_done->next) return TRUE; | |
235 r = GPOINTER_TO_INT(ss->list_done->next->data); | |
236 } | |
1 | 237 |
138 | 238 if (ss->filelist) |
9 | 239 { |
138 | 240 image_prebuffer_set(ss->imd, g_list_nth_data(ss->filelist, r)); |
9 | 241 } |
242 else if (ss->cd) | |
243 { | |
244 CollectInfo *info; | |
245 info = g_list_nth_data(ss->cd->list, r); | |
138 | 246 if (info) image_prebuffer_set(ss->imd, info->fd); |
9 | 247 } |
248 else if (ss->from_selection) | |
249 { | |
138 | 250 image_prebuffer_set(ss->imd, layout_list_get_fd(ss->layout, r)); |
9 | 251 } |
1 | 252 } |
253 | |
254 return TRUE; | |
255 } | |
256 | |
3 | 257 static gint slideshow_loop_cb(gpointer data) |
258 { | |
9 | 259 SlideShowData *ss = data; |
1 | 260 |
9 | 261 if (ss->paused) return TRUE; |
1 | 262 |
9 | 263 if (!slideshow_step(ss, TRUE)) |
3 | 264 { |
9 | 265 ss->timeout_id = -1; |
266 slideshow_free(ss); | |
1 | 267 return FALSE; |
268 } | |
269 | |
270 return TRUE; | |
271 } | |
272 | |
744
eb7e0d3206a2
Move code from slideshow_timer_reset() to new slideshow_timer_stop() and simplify calls.
zas_
parents:
736
diff
changeset
|
273 static void slideshow_timer_stop(SlideShowData *ss) |
9 | 274 { |
744
eb7e0d3206a2
Move code from slideshow_timer_reset() to new slideshow_timer_stop() and simplify calls.
zas_
parents:
736
diff
changeset
|
275 if (ss->timeout_id == -1) return; |
eb7e0d3206a2
Move code from slideshow_timer_reset() to new slideshow_timer_stop() and simplify calls.
zas_
parents:
736
diff
changeset
|
276 |
eb7e0d3206a2
Move code from slideshow_timer_reset() to new slideshow_timer_stop() and simplify calls.
zas_
parents:
736
diff
changeset
|
277 g_source_remove(ss->timeout_id); |
eb7e0d3206a2
Move code from slideshow_timer_reset() to new slideshow_timer_stop() and simplify calls.
zas_
parents:
736
diff
changeset
|
278 ss->timeout_id = -1; |
eb7e0d3206a2
Move code from slideshow_timer_reset() to new slideshow_timer_stop() and simplify calls.
zas_
parents:
736
diff
changeset
|
279 } |
9 | 280 |
744
eb7e0d3206a2
Move code from slideshow_timer_reset() to new slideshow_timer_stop() and simplify calls.
zas_
parents:
736
diff
changeset
|
281 static void slideshow_timer_reset(SlideShowData *ss) |
eb7e0d3206a2
Move code from slideshow_timer_reset() to new slideshow_timer_stop() and simplify calls.
zas_
parents:
736
diff
changeset
|
282 { |
eb7e0d3206a2
Move code from slideshow_timer_reset() to new slideshow_timer_stop() and simplify calls.
zas_
parents:
736
diff
changeset
|
283 if (options->slideshow.delay < 1) options->slideshow.delay = 1; |
eb7e0d3206a2
Move code from slideshow_timer_reset() to new slideshow_timer_stop() and simplify calls.
zas_
parents:
736
diff
changeset
|
284 |
eb7e0d3206a2
Move code from slideshow_timer_reset() to new slideshow_timer_stop() and simplify calls.
zas_
parents:
736
diff
changeset
|
285 if (ss->timeout_id != -1) g_source_remove(ss->timeout_id); |
eb7e0d3206a2
Move code from slideshow_timer_reset() to new slideshow_timer_stop() and simplify calls.
zas_
parents:
736
diff
changeset
|
286 ss->timeout_id = g_timeout_add(options->slideshow.delay * 1000 / SLIDESHOW_SUBSECOND_PRECISION, |
eb7e0d3206a2
Move code from slideshow_timer_reset() to new slideshow_timer_stop() and simplify calls.
zas_
parents:
736
diff
changeset
|
287 slideshow_loop_cb, ss); |
9 | 288 } |
289 | |
745
41dc324ee014
slideshow_next(), slideshow_prev(): move code to common slideshow_move(), reducing code redundancy.
zas_
parents:
744
diff
changeset
|
290 static void slideshow_move(SlideShowData *ss, gboolean forward) |
9 | 291 { |
89
b3149a34d0dd
Sat Oct 28 14:41:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
292 if (!ss) return; |
b3149a34d0dd
Sat Oct 28 14:41:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
293 |
745
41dc324ee014
slideshow_next(), slideshow_prev(): move code to common slideshow_move(), reducing code redundancy.
zas_
parents:
744
diff
changeset
|
294 if (!slideshow_step(ss, forward)) |
9 | 295 { |
296 slideshow_free(ss); | |
297 return; | |
298 } | |
299 | |
744
eb7e0d3206a2
Move code from slideshow_timer_reset() to new slideshow_timer_stop() and simplify calls.
zas_
parents:
736
diff
changeset
|
300 slideshow_timer_reset(ss); |
9 | 301 } |
302 | |
745
41dc324ee014
slideshow_next(), slideshow_prev(): move code to common slideshow_move(), reducing code redundancy.
zas_
parents:
744
diff
changeset
|
303 void slideshow_next(SlideShowData *ss) |
41dc324ee014
slideshow_next(), slideshow_prev(): move code to common slideshow_move(), reducing code redundancy.
zas_
parents:
744
diff
changeset
|
304 { |
41dc324ee014
slideshow_next(), slideshow_prev(): move code to common slideshow_move(), reducing code redundancy.
zas_
parents:
744
diff
changeset
|
305 slideshow_move(ss, TRUE); |
41dc324ee014
slideshow_next(), slideshow_prev(): move code to common slideshow_move(), reducing code redundancy.
zas_
parents:
744
diff
changeset
|
306 } |
41dc324ee014
slideshow_next(), slideshow_prev(): move code to common slideshow_move(), reducing code redundancy.
zas_
parents:
744
diff
changeset
|
307 |
9 | 308 void slideshow_prev(SlideShowData *ss) |
309 { | |
745
41dc324ee014
slideshow_next(), slideshow_prev(): move code to common slideshow_move(), reducing code redundancy.
zas_
parents:
744
diff
changeset
|
310 slideshow_move(ss, FALSE); |
9 | 311 } |
312 | |
313 static SlideShowData *real_slideshow_start(ImageWindow *imd, LayoutWindow *lw, | |
138 | 314 GList *filelist, gint start_point, |
9 | 315 CollectionData *cd, CollectInfo *start_info, |
316 void (*stop_func)(SlideShowData *, gpointer), gpointer stop_data) | |
317 { | |
318 SlideShowData *ss; | |
319 gint start_index = -1; | |
320 | |
138 | 321 if (!filelist && !cd && layout_list_count(lw, NULL) < 1) return NULL; |
9 | 322 |
323 ss = g_new0(SlideShowData, 1); | |
324 | |
325 ss->imd = imd; | |
326 | |
138 | 327 ss->filelist = filelist; |
9 | 328 ss->cd = cd; |
329 ss->layout = lw; | |
783 | 330 ss->dir_fd = NULL; |
9 | 331 |
332 ss->list = NULL; | |
333 ss->list_done = NULL; | |
334 | |
335 ss->from_selection = FALSE; | |
336 | |
119
197b8d2e52ce
Thu Nov 30 09:55:42 2006 John Ellis <johne@verizon.net>
gqview
parents:
89
diff
changeset
|
337 ss->stop_func = NULL; |
9 | 338 |
339 ss->timeout_id = -1; | |
340 ss->paused = FALSE; | |
341 | |
138 | 342 if (ss->filelist) |
9 | 343 { |
138 | 344 ss->slide_count = g_list_length(ss->filelist); |
9 | 345 } |
346 else if (ss->cd) | |
347 { | |
348 collection_ref(ss->cd); | |
349 ss->slide_count = g_list_length(ss->cd->list); | |
326 | 350 if (!options->slideshow.random && start_info) |
9 | 351 { |
352 start_index = g_list_index(ss->cd->list, start_info); | |
353 } | |
354 } | |
355 else | |
356 { | |
357 /* layout method */ | |
358 | |
359 ss->slide_count = layout_selection_count(ss->layout, NULL); | |
783 | 360 ss->dir_fd = file_data_ref(ss->layout->dir_fd); |
9 | 361 if (ss->slide_count < 2) |
362 { | |
363 ss->slide_count = layout_list_count(ss->layout, NULL); | |
736 | 364 if (!options->slideshow.random && start_point >= 0 && (guint) start_point < ss->slide_count) |
9 | 365 { |
366 start_index = start_point; | |
367 } | |
368 } | |
369 else | |
370 { | |
371 ss->from_selection = TRUE; | |
372 } | |
373 } | |
374 | |
375 slideshow_list_init(ss, start_index); | |
376 | |
138 | 377 ss->slide_fd = file_data_ref(image_get_fd(ss->imd)); |
9 | 378 if (slideshow_step(ss, TRUE)) |
379 { | |
744
eb7e0d3206a2
Move code from slideshow_timer_reset() to new slideshow_timer_stop() and simplify calls.
zas_
parents:
736
diff
changeset
|
380 slideshow_timer_reset(ss); |
119
197b8d2e52ce
Thu Nov 30 09:55:42 2006 John Ellis <johne@verizon.net>
gqview
parents:
89
diff
changeset
|
381 |
197b8d2e52ce
Thu Nov 30 09:55:42 2006 John Ellis <johne@verizon.net>
gqview
parents:
89
diff
changeset
|
382 ss->stop_func = stop_func; |
197b8d2e52ce
Thu Nov 30 09:55:42 2006 John Ellis <johne@verizon.net>
gqview
parents:
89
diff
changeset
|
383 ss->stop_data = stop_data; |
9 | 384 } |
385 else | |
386 { | |
119
197b8d2e52ce
Thu Nov 30 09:55:42 2006 John Ellis <johne@verizon.net>
gqview
parents:
89
diff
changeset
|
387 slideshow_free(ss); |
9 | 388 ss = NULL; |
389 } | |
390 | |
391 return ss; | |
392 } | |
393 | |
138 | 394 SlideShowData *slideshow_start_from_filelist(ImageWindow *imd, GList *list, |
9 | 395 void (*stop_func)(SlideShowData *, gpointer), gpointer stop_data) |
396 { | |
397 return real_slideshow_start(imd, NULL, list, -1, NULL, NULL, stop_func, stop_data); | |
398 } | |
399 | |
400 SlideShowData *slideshow_start_from_collection(ImageWindow *imd, CollectionData *cd, | |
401 void (*stop_func)(SlideShowData *, gpointer), gpointer stop_data, | |
402 CollectInfo *start_info) | |
403 { | |
404 return real_slideshow_start(imd, NULL, NULL, -1, cd, start_info, stop_func, stop_data); | |
405 } | |
406 | |
407 SlideShowData *slideshow_start(ImageWindow *imd, LayoutWindow *lw, gint start_point, | |
408 void (*stop_func)(SlideShowData *, gpointer), gpointer stop_data) | |
409 { | |
410 return real_slideshow_start(imd, lw, NULL, start_point, NULL, NULL, stop_func, stop_data); | |
411 } | |
412 | |
413 gint slideshow_paused(SlideShowData *ss) | |
414 { | |
415 if (!ss) return FALSE; | |
416 | |
417 return ss->paused; | |
418 } | |
419 | |
420 void slideshow_pause_set(SlideShowData *ss, gint paused) | |
421 { | |
422 if (!ss) return; | |
423 | |
424 ss->paused = paused; | |
425 } | |
426 | |
427 gint slideshow_pause_toggle(SlideShowData *ss) | |
428 { | |
429 slideshow_pause_set(ss, !slideshow_paused(ss)); | |
430 return slideshow_paused(ss); | |
431 } |