Mercurial > geeqie.yaz
annotate src/slideshow.c @ 1284:8b89e3ff286b
Add year 2009 to copyright info everywhere.
author | zas_ |
---|---|
date | Wed, 04 Feb 2009 17:15:30 +0000 |
parents | f539958d7bd8 |
children | 249bf204004a |
rev | line source |
---|---|
1 | 1 /* |
196 | 2 * Geeqie |
9 | 3 * (C) 2004 John Ellis |
1284 | 4 * Copyright (C) 2008 - 2009 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 | |
1281
f539958d7bd8
Speed up random slideshow, startup time decreases from minutes to seconds when amount of images is big. Patch by Kjell Morgenstern.
zas_
parents:
1055
diff
changeset
|
69 static void ptr_array_add(gpointer data, GPtrArray *array) |
f539958d7bd8
Speed up random slideshow, startup time decreases from minutes to seconds when amount of images is big. Patch by Kjell Morgenstern.
zas_
parents:
1055
diff
changeset
|
70 { |
f539958d7bd8
Speed up random slideshow, startup time decreases from minutes to seconds when amount of images is big. Patch by Kjell Morgenstern.
zas_
parents:
1055
diff
changeset
|
71 g_ptr_array_add(array, data); |
f539958d7bd8
Speed up random slideshow, startup time decreases from minutes to seconds when amount of images is big. Patch by Kjell Morgenstern.
zas_
parents:
1055
diff
changeset
|
72 } |
f539958d7bd8
Speed up random slideshow, startup time decreases from minutes to seconds when amount of images is big. Patch by Kjell Morgenstern.
zas_
parents:
1055
diff
changeset
|
73 |
f539958d7bd8
Speed up random slideshow, startup time decreases from minutes to seconds when amount of images is big. Patch by Kjell Morgenstern.
zas_
parents:
1055
diff
changeset
|
74 static void list_prepend(gpointer data, GList **list) |
f539958d7bd8
Speed up random slideshow, startup time decreases from minutes to seconds when amount of images is big. Patch by Kjell Morgenstern.
zas_
parents:
1055
diff
changeset
|
75 { |
f539958d7bd8
Speed up random slideshow, startup time decreases from minutes to seconds when amount of images is big. Patch by Kjell Morgenstern.
zas_
parents:
1055
diff
changeset
|
76 *list = g_list_prepend(*list, data); |
f539958d7bd8
Speed up random slideshow, startup time decreases from minutes to seconds when amount of images is big. Patch by Kjell Morgenstern.
zas_
parents:
1055
diff
changeset
|
77 } |
f539958d7bd8
Speed up random slideshow, startup time decreases from minutes to seconds when amount of images is big. Patch by Kjell Morgenstern.
zas_
parents:
1055
diff
changeset
|
78 |
f539958d7bd8
Speed up random slideshow, startup time decreases from minutes to seconds when amount of images is big. Patch by Kjell Morgenstern.
zas_
parents:
1055
diff
changeset
|
79 static GPtrArray *generate_ptr_array_from_list(GList *src_list) |
f539958d7bd8
Speed up random slideshow, startup time decreases from minutes to seconds when amount of images is big. Patch by Kjell Morgenstern.
zas_
parents:
1055
diff
changeset
|
80 { |
f539958d7bd8
Speed up random slideshow, startup time decreases from minutes to seconds when amount of images is big. Patch by Kjell Morgenstern.
zas_
parents:
1055
diff
changeset
|
81 GPtrArray *arr = g_ptr_array_sized_new(g_list_length(src_list)); |
f539958d7bd8
Speed up random slideshow, startup time decreases from minutes to seconds when amount of images is big. Patch by Kjell Morgenstern.
zas_
parents:
1055
diff
changeset
|
82 |
f539958d7bd8
Speed up random slideshow, startup time decreases from minutes to seconds when amount of images is big. Patch by Kjell Morgenstern.
zas_
parents:
1055
diff
changeset
|
83 g_list_foreach(src_list, (GFunc) ptr_array_add, arr); |
f539958d7bd8
Speed up random slideshow, startup time decreases from minutes to seconds when amount of images is big. Patch by Kjell Morgenstern.
zas_
parents:
1055
diff
changeset
|
84 |
f539958d7bd8
Speed up random slideshow, startup time decreases from minutes to seconds when amount of images is big. Patch by Kjell Morgenstern.
zas_
parents:
1055
diff
changeset
|
85 return arr; |
f539958d7bd8
Speed up random slideshow, startup time decreases from minutes to seconds when amount of images is big. Patch by Kjell Morgenstern.
zas_
parents:
1055
diff
changeset
|
86 } |
f539958d7bd8
Speed up random slideshow, startup time decreases from minutes to seconds when amount of images is big. Patch by Kjell Morgenstern.
zas_
parents:
1055
diff
changeset
|
87 |
f539958d7bd8
Speed up random slideshow, startup time decreases from minutes to seconds when amount of images is big. Patch by Kjell Morgenstern.
zas_
parents:
1055
diff
changeset
|
88 static void swap(GPtrArray *array, guint index1, guint index2) |
f539958d7bd8
Speed up random slideshow, startup time decreases from minutes to seconds when amount of images is big. Patch by Kjell Morgenstern.
zas_
parents:
1055
diff
changeset
|
89 { |
f539958d7bd8
Speed up random slideshow, startup time decreases from minutes to seconds when amount of images is big. Patch by Kjell Morgenstern.
zas_
parents:
1055
diff
changeset
|
90 gpointer temp = g_ptr_array_index(array, index1); |
f539958d7bd8
Speed up random slideshow, startup time decreases from minutes to seconds when amount of images is big. Patch by Kjell Morgenstern.
zas_
parents:
1055
diff
changeset
|
91 |
f539958d7bd8
Speed up random slideshow, startup time decreases from minutes to seconds when amount of images is big. Patch by Kjell Morgenstern.
zas_
parents:
1055
diff
changeset
|
92 g_ptr_array_index(array, index1) = g_ptr_array_index(array, index2); |
f539958d7bd8
Speed up random slideshow, startup time decreases from minutes to seconds when amount of images is big. Patch by Kjell Morgenstern.
zas_
parents:
1055
diff
changeset
|
93 g_ptr_array_index(array, index2) = temp; |
f539958d7bd8
Speed up random slideshow, startup time decreases from minutes to seconds when amount of images is big. Patch by Kjell Morgenstern.
zas_
parents:
1055
diff
changeset
|
94 } |
f539958d7bd8
Speed up random slideshow, startup time decreases from minutes to seconds when amount of images is big. Patch by Kjell Morgenstern.
zas_
parents:
1055
diff
changeset
|
95 |
f539958d7bd8
Speed up random slideshow, startup time decreases from minutes to seconds when amount of images is big. Patch by Kjell Morgenstern.
zas_
parents:
1055
diff
changeset
|
96 static void ptr_array_random_shuffle(GPtrArray *array) |
f539958d7bd8
Speed up random slideshow, startup time decreases from minutes to seconds when amount of images is big. Patch by Kjell Morgenstern.
zas_
parents:
1055
diff
changeset
|
97 { |
f539958d7bd8
Speed up random slideshow, startup time decreases from minutes to seconds when amount of images is big. Patch by Kjell Morgenstern.
zas_
parents:
1055
diff
changeset
|
98 guint i; |
f539958d7bd8
Speed up random slideshow, startup time decreases from minutes to seconds when amount of images is big. Patch by Kjell Morgenstern.
zas_
parents:
1055
diff
changeset
|
99 for (i = 0; i < array->len; ++i) |
f539958d7bd8
Speed up random slideshow, startup time decreases from minutes to seconds when amount of images is big. Patch by Kjell Morgenstern.
zas_
parents:
1055
diff
changeset
|
100 { |
f539958d7bd8
Speed up random slideshow, startup time decreases from minutes to seconds when amount of images is big. Patch by Kjell Morgenstern.
zas_
parents:
1055
diff
changeset
|
101 guint p = (double)rand() / ((double)RAND_MAX + 1.0) * array->len; |
f539958d7bd8
Speed up random slideshow, startup time decreases from minutes to seconds when amount of images is big. Patch by Kjell Morgenstern.
zas_
parents:
1055
diff
changeset
|
102 swap(array, i, p); |
f539958d7bd8
Speed up random slideshow, startup time decreases from minutes to seconds when amount of images is big. Patch by Kjell Morgenstern.
zas_
parents:
1055
diff
changeset
|
103 } |
f539958d7bd8
Speed up random slideshow, startup time decreases from minutes to seconds when amount of images is big. Patch by Kjell Morgenstern.
zas_
parents:
1055
diff
changeset
|
104 } |
f539958d7bd8
Speed up random slideshow, startup time decreases from minutes to seconds when amount of images is big. Patch by Kjell Morgenstern.
zas_
parents:
1055
diff
changeset
|
105 |
9 | 106 static GList *generate_random_list(SlideShowData *ss) |
1 | 107 { |
1281
f539958d7bd8
Speed up random slideshow, startup time decreases from minutes to seconds when amount of images is big. Patch by Kjell Morgenstern.
zas_
parents:
1055
diff
changeset
|
108 GList *src_list; |
f539958d7bd8
Speed up random slideshow, startup time decreases from minutes to seconds when amount of images is big. Patch by Kjell Morgenstern.
zas_
parents:
1055
diff
changeset
|
109 GPtrArray *src_array; |
1 | 110 GList *list = NULL; |
111 | |
9 | 112 src_list = generate_list(ss); |
1281
f539958d7bd8
Speed up random slideshow, startup time decreases from minutes to seconds when amount of images is big. Patch by Kjell Morgenstern.
zas_
parents:
1055
diff
changeset
|
113 src_array = generate_ptr_array_from_list(src_list); |
f539958d7bd8
Speed up random slideshow, startup time decreases from minutes to seconds when amount of images is big. Patch by Kjell Morgenstern.
zas_
parents:
1055
diff
changeset
|
114 g_list_free(src_list); |
1 | 115 |
1281
f539958d7bd8
Speed up random slideshow, startup time decreases from minutes to seconds when amount of images is big. Patch by Kjell Morgenstern.
zas_
parents:
1055
diff
changeset
|
116 ptr_array_random_shuffle(src_array); |
f539958d7bd8
Speed up random slideshow, startup time decreases from minutes to seconds when amount of images is big. Patch by Kjell Morgenstern.
zas_
parents:
1055
diff
changeset
|
117 g_ptr_array_foreach(src_array, (GFunc) list_prepend, &list); |
f539958d7bd8
Speed up random slideshow, startup time decreases from minutes to seconds when amount of images is big. Patch by Kjell Morgenstern.
zas_
parents:
1055
diff
changeset
|
118 g_ptr_array_free(src_array, TRUE); |
f539958d7bd8
Speed up random slideshow, startup time decreases from minutes to seconds when amount of images is big. Patch by Kjell Morgenstern.
zas_
parents:
1055
diff
changeset
|
119 |
1 | 120 return list; |
121 } | |
122 | |
9 | 123 static void slideshow_list_init(SlideShowData *ss, gint start_index) |
1 | 124 { |
9 | 125 if (ss->list_done) |
1 | 126 { |
9 | 127 g_list_free(ss->list_done); |
128 ss->list_done = NULL; | |
1 | 129 } |
130 | |
9 | 131 if (ss->list) g_list_free(ss->list); |
3 | 132 |
326 | 133 if (options->slideshow.random) |
1 | 134 { |
9 | 135 ss->list = generate_random_list(ss); |
1 | 136 } |
137 else | |
138 { | |
9 | 139 ss->list = generate_list(ss); |
140 if (start_index >= 0) | |
3 | 141 { |
9 | 142 /* start with specified image by skipping to it */ |
143 gint i = 0; | |
144 | |
516 | 145 while (ss->list && i < start_index) |
9 | 146 { |
513
985fdfebd89e
Remove whitespace between function name and first parenthesis for the sake of consistency. (pass 2)
zas_
parents:
475
diff
changeset
|
147 ss->list_done = g_list_prepend(ss->list_done, ss->list->data); |
9 | 148 ss->list = g_list_remove(ss->list, ss->list->data); |
149 i++; | |
150 } | |
3 | 151 } |
152 } | |
153 } | |
154 | |
9 | 155 gint slideshow_should_continue(SlideShowData *ss) |
1 | 156 { |
138 | 157 FileData *imd_fd; |
783 | 158 FileData *dir_fd; |
9 | 159 |
89
b3149a34d0dd
Sat Oct 28 14:41:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
160 if (!ss) return FALSE; |
b3149a34d0dd
Sat Oct 28 14:41:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
161 |
138 | 162 imd_fd = image_get_fd(ss->imd); |
9 | 163 |
138 | 164 if ( ((imd_fd == NULL) != (ss->slide_fd == NULL)) || |
165 (imd_fd && ss->slide_fd && imd_fd != ss->slide_fd) ) return FALSE; | |
9 | 166 |
138 | 167 if (ss->filelist) return TRUE; |
9 | 168 |
169 if (ss->cd) | |
170 { | |
171 if (g_list_length(ss->cd->list) == ss->slide_count) | |
172 return TRUE; | |
173 else | |
174 return FALSE; | |
175 } | |
176 | |
177 if (!ss->layout) return FALSE; | |
783 | 178 dir_fd = ss->layout->dir_fd; |
9 | 179 |
783 | 180 if (dir_fd && ss->dir_fd && dir_fd == ss->dir_fd) |
9 | 181 { |
182 if (ss->from_selection && ss->slide_count == layout_selection_count(ss->layout, NULL)) return TRUE; | |
183 if (!ss->from_selection && ss->slide_count == layout_list_count(ss->layout, NULL)) return TRUE; | |
184 } | |
185 | |
186 return FALSE; | |
187 } | |
188 | |
745
41dc324ee014
slideshow_next(), slideshow_prev(): move code to common slideshow_move(), reducing code redundancy.
zas_
parents:
744
diff
changeset
|
189 static gint slideshow_step(SlideShowData *ss, gboolean forward) |
9 | 190 { |
191 gint row; | |
192 | |
193 if (!slideshow_should_continue(ss)) | |
1 | 194 { |
195 return FALSE; | |
196 } | |
197 | |
9 | 198 if (forward) |
199 { | |
200 if (!ss->list) return TRUE; | |
1 | 201 |
9 | 202 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
|
203 ss->list_done = g_list_prepend(ss->list_done, ss->list->data); |
9 | 204 ss->list = g_list_remove(ss->list, ss->list->data); |
205 } | |
206 else | |
207 { | |
208 if (!ss->list_done || !ss->list_done->next) return TRUE; | |
3 | 209 |
9 | 210 ss->list = g_list_prepend(ss->list, ss->list_done->data); |
211 ss->list_done = g_list_remove(ss->list_done, ss->list_done->data); | |
212 row = GPOINTER_TO_INT(ss->list_done->data); | |
3 | 213 } |
214 | |
138 | 215 file_data_unref(ss->slide_fd); |
216 ss->slide_fd = NULL; | |
3 | 217 |
138 | 218 if (ss->filelist) |
9 | 219 { |
138 | 220 ss->slide_fd = file_data_ref((FileData *)g_list_nth_data(ss->filelist, row)); |
885
ad420f2eb789
Use a specific enum for image.zoom_mode values (ZoomMode) and
zas_
parents:
783
diff
changeset
|
221 image_change_fd(ss->imd, ss->slide_fd, image_zoom_get_default(ss->imd)); |
9 | 222 } |
223 else if (ss->cd) | |
224 { | |
225 CollectInfo *info; | |
3 | 226 |
9 | 227 info = g_list_nth_data(ss->cd->list, row); |
138 | 228 ss->slide_fd = file_data_ref(info->fd); |
9 | 229 |
885
ad420f2eb789
Use a specific enum for image.zoom_mode values (ZoomMode) and
zas_
parents:
783
diff
changeset
|
230 image_change_from_collection(ss->imd, ss->cd, info, image_zoom_get_default(ss->imd)); |
3 | 231 } |
232 else | |
233 { | |
138 | 234 ss->slide_fd = file_data_ref(layout_list_get_fd(ss->layout, row)); |
9 | 235 |
236 if (ss->from_selection) | |
237 { | |
885
ad420f2eb789
Use a specific enum for image.zoom_mode values (ZoomMode) and
zas_
parents:
783
diff
changeset
|
238 image_change_fd(ss->imd, ss->slide_fd, image_zoom_get_default(ss->imd)); |
9 | 239 layout_status_update_info(ss->layout, NULL); |
240 } | |
241 else | |
242 { | |
243 layout_image_set_index(ss->layout, row); | |
244 } | |
3 | 245 } |
246 | |
326 | 247 if (!ss->list && options->slideshow.repeat) |
9 | 248 { |
249 slideshow_list_init(ss, -1); | |
250 } | |
3 | 251 |
9 | 252 if (!ss->list) |
1 | 253 { |
254 return FALSE; | |
255 } | |
256 | |
9 | 257 /* read ahead */ |
1 | 258 |
334 | 259 if (options->image.enable_read_ahead) |
1 | 260 { |
9 | 261 gint r; |
262 if (forward) | |
263 { | |
264 if (!ss->list) return TRUE; | |
265 r = GPOINTER_TO_INT(ss->list->data); | |
266 } | |
267 else | |
268 { | |
269 if (!ss->list_done || !ss->list_done->next) return TRUE; | |
270 r = GPOINTER_TO_INT(ss->list_done->next->data); | |
271 } | |
1 | 272 |
138 | 273 if (ss->filelist) |
9 | 274 { |
138 | 275 image_prebuffer_set(ss->imd, g_list_nth_data(ss->filelist, r)); |
9 | 276 } |
277 else if (ss->cd) | |
278 { | |
279 CollectInfo *info; | |
280 info = g_list_nth_data(ss->cd->list, r); | |
138 | 281 if (info) image_prebuffer_set(ss->imd, info->fd); |
9 | 282 } |
283 else if (ss->from_selection) | |
284 { | |
138 | 285 image_prebuffer_set(ss->imd, layout_list_get_fd(ss->layout, r)); |
9 | 286 } |
1 | 287 } |
288 | |
289 return TRUE; | |
290 } | |
291 | |
3 | 292 static gint slideshow_loop_cb(gpointer data) |
293 { | |
9 | 294 SlideShowData *ss = data; |
1 | 295 |
9 | 296 if (ss->paused) return TRUE; |
1 | 297 |
9 | 298 if (!slideshow_step(ss, TRUE)) |
3 | 299 { |
9 | 300 ss->timeout_id = -1; |
301 slideshow_free(ss); | |
1 | 302 return FALSE; |
303 } | |
304 | |
305 return TRUE; | |
306 } | |
307 | |
744
eb7e0d3206a2
Move code from slideshow_timer_reset() to new slideshow_timer_stop() and simplify calls.
zas_
parents:
736
diff
changeset
|
308 static void slideshow_timer_stop(SlideShowData *ss) |
9 | 309 { |
744
eb7e0d3206a2
Move code from slideshow_timer_reset() to new slideshow_timer_stop() and simplify calls.
zas_
parents:
736
diff
changeset
|
310 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
|
311 |
eb7e0d3206a2
Move code from slideshow_timer_reset() to new slideshow_timer_stop() and simplify calls.
zas_
parents:
736
diff
changeset
|
312 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
|
313 ss->timeout_id = -1; |
eb7e0d3206a2
Move code from slideshow_timer_reset() to new slideshow_timer_stop() and simplify calls.
zas_
parents:
736
diff
changeset
|
314 } |
9 | 315 |
744
eb7e0d3206a2
Move code from slideshow_timer_reset() to new slideshow_timer_stop() and simplify calls.
zas_
parents:
736
diff
changeset
|
316 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
|
317 { |
eb7e0d3206a2
Move code from slideshow_timer_reset() to new slideshow_timer_stop() and simplify calls.
zas_
parents:
736
diff
changeset
|
318 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
|
319 |
eb7e0d3206a2
Move code from slideshow_timer_reset() to new slideshow_timer_stop() and simplify calls.
zas_
parents:
736
diff
changeset
|
320 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
|
321 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
|
322 slideshow_loop_cb, ss); |
9 | 323 } |
324 | |
745
41dc324ee014
slideshow_next(), slideshow_prev(): move code to common slideshow_move(), reducing code redundancy.
zas_
parents:
744
diff
changeset
|
325 static void slideshow_move(SlideShowData *ss, gboolean forward) |
9 | 326 { |
89
b3149a34d0dd
Sat Oct 28 14:41:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
327 if (!ss) return; |
b3149a34d0dd
Sat Oct 28 14:41:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
328 |
745
41dc324ee014
slideshow_next(), slideshow_prev(): move code to common slideshow_move(), reducing code redundancy.
zas_
parents:
744
diff
changeset
|
329 if (!slideshow_step(ss, forward)) |
9 | 330 { |
331 slideshow_free(ss); | |
332 return; | |
333 } | |
334 | |
744
eb7e0d3206a2
Move code from slideshow_timer_reset() to new slideshow_timer_stop() and simplify calls.
zas_
parents:
736
diff
changeset
|
335 slideshow_timer_reset(ss); |
9 | 336 } |
337 | |
745
41dc324ee014
slideshow_next(), slideshow_prev(): move code to common slideshow_move(), reducing code redundancy.
zas_
parents:
744
diff
changeset
|
338 void slideshow_next(SlideShowData *ss) |
41dc324ee014
slideshow_next(), slideshow_prev(): move code to common slideshow_move(), reducing code redundancy.
zas_
parents:
744
diff
changeset
|
339 { |
41dc324ee014
slideshow_next(), slideshow_prev(): move code to common slideshow_move(), reducing code redundancy.
zas_
parents:
744
diff
changeset
|
340 slideshow_move(ss, TRUE); |
41dc324ee014
slideshow_next(), slideshow_prev(): move code to common slideshow_move(), reducing code redundancy.
zas_
parents:
744
diff
changeset
|
341 } |
41dc324ee014
slideshow_next(), slideshow_prev(): move code to common slideshow_move(), reducing code redundancy.
zas_
parents:
744
diff
changeset
|
342 |
9 | 343 void slideshow_prev(SlideShowData *ss) |
344 { | |
745
41dc324ee014
slideshow_next(), slideshow_prev(): move code to common slideshow_move(), reducing code redundancy.
zas_
parents:
744
diff
changeset
|
345 slideshow_move(ss, FALSE); |
9 | 346 } |
347 | |
348 static SlideShowData *real_slideshow_start(ImageWindow *imd, LayoutWindow *lw, | |
138 | 349 GList *filelist, gint start_point, |
9 | 350 CollectionData *cd, CollectInfo *start_info, |
351 void (*stop_func)(SlideShowData *, gpointer), gpointer stop_data) | |
352 { | |
353 SlideShowData *ss; | |
354 gint start_index = -1; | |
355 | |
138 | 356 if (!filelist && !cd && layout_list_count(lw, NULL) < 1) return NULL; |
9 | 357 |
358 ss = g_new0(SlideShowData, 1); | |
359 | |
360 ss->imd = imd; | |
361 | |
138 | 362 ss->filelist = filelist; |
9 | 363 ss->cd = cd; |
364 ss->layout = lw; | |
783 | 365 ss->dir_fd = NULL; |
9 | 366 |
367 ss->list = NULL; | |
368 ss->list_done = NULL; | |
369 | |
370 ss->from_selection = FALSE; | |
371 | |
119
197b8d2e52ce
Thu Nov 30 09:55:42 2006 John Ellis <johne@verizon.net>
gqview
parents:
89
diff
changeset
|
372 ss->stop_func = NULL; |
9 | 373 |
374 ss->timeout_id = -1; | |
375 ss->paused = FALSE; | |
376 | |
138 | 377 if (ss->filelist) |
9 | 378 { |
138 | 379 ss->slide_count = g_list_length(ss->filelist); |
9 | 380 } |
381 else if (ss->cd) | |
382 { | |
383 collection_ref(ss->cd); | |
384 ss->slide_count = g_list_length(ss->cd->list); | |
326 | 385 if (!options->slideshow.random && start_info) |
9 | 386 { |
387 start_index = g_list_index(ss->cd->list, start_info); | |
388 } | |
389 } | |
390 else | |
391 { | |
392 /* layout method */ | |
393 | |
394 ss->slide_count = layout_selection_count(ss->layout, NULL); | |
783 | 395 ss->dir_fd = file_data_ref(ss->layout->dir_fd); |
9 | 396 if (ss->slide_count < 2) |
397 { | |
398 ss->slide_count = layout_list_count(ss->layout, NULL); | |
736 | 399 if (!options->slideshow.random && start_point >= 0 && (guint) start_point < ss->slide_count) |
9 | 400 { |
401 start_index = start_point; | |
402 } | |
403 } | |
404 else | |
405 { | |
406 ss->from_selection = TRUE; | |
407 } | |
408 } | |
409 | |
410 slideshow_list_init(ss, start_index); | |
411 | |
138 | 412 ss->slide_fd = file_data_ref(image_get_fd(ss->imd)); |
9 | 413 if (slideshow_step(ss, TRUE)) |
414 { | |
744
eb7e0d3206a2
Move code from slideshow_timer_reset() to new slideshow_timer_stop() and simplify calls.
zas_
parents:
736
diff
changeset
|
415 slideshow_timer_reset(ss); |
119
197b8d2e52ce
Thu Nov 30 09:55:42 2006 John Ellis <johne@verizon.net>
gqview
parents:
89
diff
changeset
|
416 |
197b8d2e52ce
Thu Nov 30 09:55:42 2006 John Ellis <johne@verizon.net>
gqview
parents:
89
diff
changeset
|
417 ss->stop_func = stop_func; |
197b8d2e52ce
Thu Nov 30 09:55:42 2006 John Ellis <johne@verizon.net>
gqview
parents:
89
diff
changeset
|
418 ss->stop_data = stop_data; |
9 | 419 } |
420 else | |
421 { | |
119
197b8d2e52ce
Thu Nov 30 09:55:42 2006 John Ellis <johne@verizon.net>
gqview
parents:
89
diff
changeset
|
422 slideshow_free(ss); |
9 | 423 ss = NULL; |
424 } | |
425 | |
426 return ss; | |
427 } | |
428 | |
138 | 429 SlideShowData *slideshow_start_from_filelist(ImageWindow *imd, GList *list, |
9 | 430 void (*stop_func)(SlideShowData *, gpointer), gpointer stop_data) |
431 { | |
432 return real_slideshow_start(imd, NULL, list, -1, NULL, NULL, stop_func, stop_data); | |
433 } | |
434 | |
435 SlideShowData *slideshow_start_from_collection(ImageWindow *imd, CollectionData *cd, | |
436 void (*stop_func)(SlideShowData *, gpointer), gpointer stop_data, | |
437 CollectInfo *start_info) | |
438 { | |
439 return real_slideshow_start(imd, NULL, NULL, -1, cd, start_info, stop_func, stop_data); | |
440 } | |
441 | |
442 SlideShowData *slideshow_start(ImageWindow *imd, LayoutWindow *lw, gint start_point, | |
443 void (*stop_func)(SlideShowData *, gpointer), gpointer stop_data) | |
444 { | |
445 return real_slideshow_start(imd, lw, NULL, start_point, NULL, NULL, stop_func, stop_data); | |
446 } | |
447 | |
448 gint slideshow_paused(SlideShowData *ss) | |
449 { | |
450 if (!ss) return FALSE; | |
451 | |
452 return ss->paused; | |
453 } | |
454 | |
455 void slideshow_pause_set(SlideShowData *ss, gint paused) | |
456 { | |
457 if (!ss) return; | |
458 | |
459 ss->paused = paused; | |
460 } | |
461 | |
462 gint slideshow_pause_toggle(SlideShowData *ss) | |
463 { | |
464 slideshow_pause_set(ss, !slideshow_paused(ss)); | |
465 return slideshow_paused(ss); | |
466 } | |
1055
1646720364cf
Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents:
1000
diff
changeset
|
467 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |