Mercurial > geeqie.yaz
annotate src/slideshow.c @ 1753:c4d37e0fc841 default tip
installation fix
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Fri, 29 Jan 2010 19:22:50 +0900 |
parents | 66d4bd637fd7 |
children |
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 { | |
1623
66d4bd637fd7
use layout_set_fd() for changing images from a slideshow
nadvornik
parents:
1523
diff
changeset
|
54 list = layout_selection_list_by_index(ss->lw); |
9 | 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 | |
1446 | 155 gboolean 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 |
1623
66d4bd637fd7
use layout_set_fd() for changing images from a slideshow
nadvornik
parents:
1523
diff
changeset
|
162 if (ss->lw) |
66d4bd637fd7
use layout_set_fd() for changing images from a slideshow
nadvornik
parents:
1523
diff
changeset
|
163 imd_fd = layout_image_get_fd(ss->lw); |
66d4bd637fd7
use layout_set_fd() for changing images from a slideshow
nadvornik
parents:
1523
diff
changeset
|
164 else |
66d4bd637fd7
use layout_set_fd() for changing images from a slideshow
nadvornik
parents:
1523
diff
changeset
|
165 imd_fd = image_get_fd(ss->imd); |
9 | 166 |
138 | 167 if ( ((imd_fd == NULL) != (ss->slide_fd == NULL)) || |
168 (imd_fd && ss->slide_fd && imd_fd != ss->slide_fd) ) return FALSE; | |
9 | 169 |
138 | 170 if (ss->filelist) return TRUE; |
9 | 171 |
172 if (ss->cd) | |
173 { | |
174 if (g_list_length(ss->cd->list) == ss->slide_count) | |
175 return TRUE; | |
176 else | |
177 return FALSE; | |
178 } | |
179 | |
1623
66d4bd637fd7
use layout_set_fd() for changing images from a slideshow
nadvornik
parents:
1523
diff
changeset
|
180 dir_fd = ss->lw->dir_fd; |
9 | 181 |
783 | 182 if (dir_fd && ss->dir_fd && dir_fd == ss->dir_fd) |
9 | 183 { |
1623
66d4bd637fd7
use layout_set_fd() for changing images from a slideshow
nadvornik
parents:
1523
diff
changeset
|
184 if (ss->from_selection && ss->slide_count == layout_selection_count(ss->lw, NULL)) return TRUE; |
66d4bd637fd7
use layout_set_fd() for changing images from a slideshow
nadvornik
parents:
1523
diff
changeset
|
185 if (!ss->from_selection && ss->slide_count == layout_list_count(ss->lw, NULL)) return TRUE; |
9 | 186 } |
187 | |
188 return FALSE; | |
189 } | |
190 | |
1446 | 191 static gboolean slideshow_step(SlideShowData *ss, gboolean forward) |
9 | 192 { |
193 gint row; | |
194 | |
195 if (!slideshow_should_continue(ss)) | |
1 | 196 { |
197 return FALSE; | |
198 } | |
199 | |
9 | 200 if (forward) |
201 { | |
202 if (!ss->list) return TRUE; | |
1 | 203 |
9 | 204 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
|
205 ss->list_done = g_list_prepend(ss->list_done, ss->list->data); |
9 | 206 ss->list = g_list_remove(ss->list, ss->list->data); |
207 } | |
208 else | |
209 { | |
210 if (!ss->list_done || !ss->list_done->next) return TRUE; | |
3 | 211 |
9 | 212 ss->list = g_list_prepend(ss->list, ss->list_done->data); |
213 ss->list_done = g_list_remove(ss->list_done, ss->list_done->data); | |
214 row = GPOINTER_TO_INT(ss->list_done->data); | |
3 | 215 } |
216 | |
138 | 217 file_data_unref(ss->slide_fd); |
218 ss->slide_fd = NULL; | |
3 | 219 |
138 | 220 if (ss->filelist) |
9 | 221 { |
138 | 222 ss->slide_fd = file_data_ref((FileData *)g_list_nth_data(ss->filelist, row)); |
1623
66d4bd637fd7
use layout_set_fd() for changing images from a slideshow
nadvornik
parents:
1523
diff
changeset
|
223 if (ss->lw) |
66d4bd637fd7
use layout_set_fd() for changing images from a slideshow
nadvornik
parents:
1523
diff
changeset
|
224 layout_set_fd(ss->lw, ss->slide_fd); |
66d4bd637fd7
use layout_set_fd() for changing images from a slideshow
nadvornik
parents:
1523
diff
changeset
|
225 else |
66d4bd637fd7
use layout_set_fd() for changing images from a slideshow
nadvornik
parents:
1523
diff
changeset
|
226 image_change_fd(ss->imd, ss->slide_fd, image_zoom_get_default(ss->imd)); |
9 | 227 } |
228 else if (ss->cd) | |
229 { | |
230 CollectInfo *info; | |
3 | 231 |
9 | 232 info = g_list_nth_data(ss->cd->list, row); |
138 | 233 ss->slide_fd = file_data_ref(info->fd); |
9 | 234 |
1623
66d4bd637fd7
use layout_set_fd() for changing images from a slideshow
nadvornik
parents:
1523
diff
changeset
|
235 if (ss->lw) |
66d4bd637fd7
use layout_set_fd() for changing images from a slideshow
nadvornik
parents:
1523
diff
changeset
|
236 image_change_from_collection(ss->lw->image, ss->cd, info, image_zoom_get_default(ss->lw->image)); |
66d4bd637fd7
use layout_set_fd() for changing images from a slideshow
nadvornik
parents:
1523
diff
changeset
|
237 else |
66d4bd637fd7
use layout_set_fd() for changing images from a slideshow
nadvornik
parents:
1523
diff
changeset
|
238 image_change_from_collection(ss->imd, ss->cd, info, image_zoom_get_default(ss->imd)); |
3 | 239 } |
240 else | |
241 { | |
1623
66d4bd637fd7
use layout_set_fd() for changing images from a slideshow
nadvornik
parents:
1523
diff
changeset
|
242 ss->slide_fd = file_data_ref(layout_list_get_fd(ss->lw, row)); |
9 | 243 |
244 if (ss->from_selection) | |
245 { | |
1623
66d4bd637fd7
use layout_set_fd() for changing images from a slideshow
nadvornik
parents:
1523
diff
changeset
|
246 layout_set_fd(ss->lw, ss->slide_fd); |
66d4bd637fd7
use layout_set_fd() for changing images from a slideshow
nadvornik
parents:
1523
diff
changeset
|
247 layout_status_update_info(ss->lw, NULL); |
9 | 248 } |
249 else | |
250 { | |
1623
66d4bd637fd7
use layout_set_fd() for changing images from a slideshow
nadvornik
parents:
1523
diff
changeset
|
251 layout_image_set_index(ss->lw, row); |
9 | 252 } |
3 | 253 } |
254 | |
326 | 255 if (!ss->list && options->slideshow.repeat) |
9 | 256 { |
257 slideshow_list_init(ss, -1); | |
258 } | |
3 | 259 |
9 | 260 if (!ss->list) |
1 | 261 { |
262 return FALSE; | |
263 } | |
264 | |
9 | 265 /* read ahead */ |
1623
66d4bd637fd7
use layout_set_fd() for changing images from a slideshow
nadvornik
parents:
1523
diff
changeset
|
266 if (options->image.enable_read_ahead && (!ss->lw || ss->from_selection)) |
1 | 267 { |
9 | 268 gint r; |
269 if (forward) | |
270 { | |
271 if (!ss->list) return TRUE; | |
272 r = GPOINTER_TO_INT(ss->list->data); | |
273 } | |
274 else | |
275 { | |
276 if (!ss->list_done || !ss->list_done->next) return TRUE; | |
277 r = GPOINTER_TO_INT(ss->list_done->next->data); | |
278 } | |
1 | 279 |
138 | 280 if (ss->filelist) |
9 | 281 { |
138 | 282 image_prebuffer_set(ss->imd, g_list_nth_data(ss->filelist, r)); |
9 | 283 } |
284 else if (ss->cd) | |
285 { | |
286 CollectInfo *info; | |
287 info = g_list_nth_data(ss->cd->list, r); | |
138 | 288 if (info) image_prebuffer_set(ss->imd, info->fd); |
9 | 289 } |
290 else if (ss->from_selection) | |
291 { | |
1623
66d4bd637fd7
use layout_set_fd() for changing images from a slideshow
nadvornik
parents:
1523
diff
changeset
|
292 image_prebuffer_set(ss->lw->image, layout_list_get_fd(ss->lw, r)); |
9 | 293 } |
1 | 294 } |
295 | |
296 return TRUE; | |
297 } | |
298 | |
1446 | 299 static gboolean slideshow_loop_cb(gpointer data) |
3 | 300 { |
9 | 301 SlideShowData *ss = data; |
1 | 302 |
9 | 303 if (ss->paused) return TRUE; |
1 | 304 |
9 | 305 if (!slideshow_step(ss, TRUE)) |
3 | 306 { |
1523 | 307 ss->timeout_id = 0; |
9 | 308 slideshow_free(ss); |
1 | 309 return FALSE; |
310 } | |
311 | |
312 return TRUE; | |
313 } | |
314 | |
744
eb7e0d3206a2
Move code from slideshow_timer_reset() to new slideshow_timer_stop() and simplify calls.
zas_
parents:
736
diff
changeset
|
315 static void slideshow_timer_stop(SlideShowData *ss) |
9 | 316 { |
1523 | 317 if (!ss->timeout_id) return; |
744
eb7e0d3206a2
Move code from slideshow_timer_reset() to new slideshow_timer_stop() and simplify calls.
zas_
parents:
736
diff
changeset
|
318 |
eb7e0d3206a2
Move code from slideshow_timer_reset() to new slideshow_timer_stop() and simplify calls.
zas_
parents:
736
diff
changeset
|
319 g_source_remove(ss->timeout_id); |
1523 | 320 ss->timeout_id = 0; |
744
eb7e0d3206a2
Move code from slideshow_timer_reset() to new slideshow_timer_stop() and simplify calls.
zas_
parents:
736
diff
changeset
|
321 } |
9 | 322 |
744
eb7e0d3206a2
Move code from slideshow_timer_reset() to new slideshow_timer_stop() and simplify calls.
zas_
parents:
736
diff
changeset
|
323 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
|
324 { |
eb7e0d3206a2
Move code from slideshow_timer_reset() to new slideshow_timer_stop() and simplify calls.
zas_
parents:
736
diff
changeset
|
325 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
|
326 |
1523 | 327 if (ss->timeout_id) g_source_remove(ss->timeout_id); |
744
eb7e0d3206a2
Move code from slideshow_timer_reset() to new slideshow_timer_stop() and simplify calls.
zas_
parents:
736
diff
changeset
|
328 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
|
329 slideshow_loop_cb, ss); |
9 | 330 } |
331 | |
745
41dc324ee014
slideshow_next(), slideshow_prev(): move code to common slideshow_move(), reducing code redundancy.
zas_
parents:
744
diff
changeset
|
332 static void slideshow_move(SlideShowData *ss, gboolean forward) |
9 | 333 { |
89
b3149a34d0dd
Sat Oct 28 14:41:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
334 if (!ss) return; |
b3149a34d0dd
Sat Oct 28 14:41:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
335 |
745
41dc324ee014
slideshow_next(), slideshow_prev(): move code to common slideshow_move(), reducing code redundancy.
zas_
parents:
744
diff
changeset
|
336 if (!slideshow_step(ss, forward)) |
9 | 337 { |
338 slideshow_free(ss); | |
339 return; | |
340 } | |
341 | |
744
eb7e0d3206a2
Move code from slideshow_timer_reset() to new slideshow_timer_stop() and simplify calls.
zas_
parents:
736
diff
changeset
|
342 slideshow_timer_reset(ss); |
9 | 343 } |
344 | |
745
41dc324ee014
slideshow_next(), slideshow_prev(): move code to common slideshow_move(), reducing code redundancy.
zas_
parents:
744
diff
changeset
|
345 void slideshow_next(SlideShowData *ss) |
41dc324ee014
slideshow_next(), slideshow_prev(): move code to common slideshow_move(), reducing code redundancy.
zas_
parents:
744
diff
changeset
|
346 { |
41dc324ee014
slideshow_next(), slideshow_prev(): move code to common slideshow_move(), reducing code redundancy.
zas_
parents:
744
diff
changeset
|
347 slideshow_move(ss, TRUE); |
41dc324ee014
slideshow_next(), slideshow_prev(): move code to common slideshow_move(), reducing code redundancy.
zas_
parents:
744
diff
changeset
|
348 } |
41dc324ee014
slideshow_next(), slideshow_prev(): move code to common slideshow_move(), reducing code redundancy.
zas_
parents:
744
diff
changeset
|
349 |
9 | 350 void slideshow_prev(SlideShowData *ss) |
351 { | |
745
41dc324ee014
slideshow_next(), slideshow_prev(): move code to common slideshow_move(), reducing code redundancy.
zas_
parents:
744
diff
changeset
|
352 slideshow_move(ss, FALSE); |
9 | 353 } |
354 | |
1623
66d4bd637fd7
use layout_set_fd() for changing images from a slideshow
nadvornik
parents:
1523
diff
changeset
|
355 static SlideShowData *real_slideshow_start(LayoutWindow *target_lw, ImageWindow *imd, |
138 | 356 GList *filelist, gint start_point, |
9 | 357 CollectionData *cd, CollectInfo *start_info, |
358 void (*stop_func)(SlideShowData *, gpointer), gpointer stop_data) | |
359 { | |
360 SlideShowData *ss; | |
361 gint start_index = -1; | |
362 | |
1623
66d4bd637fd7
use layout_set_fd() for changing images from a slideshow
nadvornik
parents:
1523
diff
changeset
|
363 if (!filelist && !cd && layout_list_count(target_lw, NULL) < 1) return NULL; |
9 | 364 |
365 ss = g_new0(SlideShowData, 1); | |
366 | |
1623
66d4bd637fd7
use layout_set_fd() for changing images from a slideshow
nadvornik
parents:
1523
diff
changeset
|
367 ss->lw = target_lw; |
66d4bd637fd7
use layout_set_fd() for changing images from a slideshow
nadvornik
parents:
1523
diff
changeset
|
368 ss->imd = imd; /* FIXME: ss->imd is used only for img-view.c and can be dropped with it */ |
138 | 369 ss->filelist = filelist; |
9 | 370 ss->cd = cd; |
371 | |
138 | 372 if (ss->filelist) |
9 | 373 { |
138 | 374 ss->slide_count = g_list_length(ss->filelist); |
9 | 375 } |
376 else if (ss->cd) | |
377 { | |
378 collection_ref(ss->cd); | |
379 ss->slide_count = g_list_length(ss->cd->list); | |
326 | 380 if (!options->slideshow.random && start_info) |
9 | 381 { |
382 start_index = g_list_index(ss->cd->list, start_info); | |
383 } | |
384 } | |
385 else | |
386 { | |
387 /* layout method */ | |
388 | |
1623
66d4bd637fd7
use layout_set_fd() for changing images from a slideshow
nadvornik
parents:
1523
diff
changeset
|
389 ss->slide_count = layout_selection_count(ss->lw, NULL); |
66d4bd637fd7
use layout_set_fd() for changing images from a slideshow
nadvornik
parents:
1523
diff
changeset
|
390 ss->dir_fd = file_data_ref(ss->lw->dir_fd); |
9 | 391 if (ss->slide_count < 2) |
392 { | |
1623
66d4bd637fd7
use layout_set_fd() for changing images from a slideshow
nadvornik
parents:
1523
diff
changeset
|
393 ss->slide_count = layout_list_count(ss->lw, NULL); |
736 | 394 if (!options->slideshow.random && start_point >= 0 && (guint) start_point < ss->slide_count) |
9 | 395 { |
396 start_index = start_point; | |
397 } | |
398 } | |
399 else | |
400 { | |
401 ss->from_selection = TRUE; | |
402 } | |
403 } | |
404 | |
405 slideshow_list_init(ss, start_index); | |
1623
66d4bd637fd7
use layout_set_fd() for changing images from a slideshow
nadvornik
parents:
1523
diff
changeset
|
406 |
66d4bd637fd7
use layout_set_fd() for changing images from a slideshow
nadvornik
parents:
1523
diff
changeset
|
407 if (ss->lw) |
66d4bd637fd7
use layout_set_fd() for changing images from a slideshow
nadvornik
parents:
1523
diff
changeset
|
408 ss->slide_fd = file_data_ref(layout_image_get_fd(ss->lw)); |
66d4bd637fd7
use layout_set_fd() for changing images from a slideshow
nadvornik
parents:
1523
diff
changeset
|
409 else |
66d4bd637fd7
use layout_set_fd() for changing images from a slideshow
nadvornik
parents:
1523
diff
changeset
|
410 ss->slide_fd = file_data_ref(image_get_fd(ss->imd)); |
9 | 411 |
412 if (slideshow_step(ss, TRUE)) | |
413 { | |
744
eb7e0d3206a2
Move code from slideshow_timer_reset() to new slideshow_timer_stop() and simplify calls.
zas_
parents:
736
diff
changeset
|
414 slideshow_timer_reset(ss); |
119
197b8d2e52ce
Thu Nov 30 09:55:42 2006 John Ellis <johne@verizon.net>
gqview
parents:
89
diff
changeset
|
415 |
197b8d2e52ce
Thu Nov 30 09:55:42 2006 John Ellis <johne@verizon.net>
gqview
parents:
89
diff
changeset
|
416 ss->stop_func = stop_func; |
197b8d2e52ce
Thu Nov 30 09:55:42 2006 John Ellis <johne@verizon.net>
gqview
parents:
89
diff
changeset
|
417 ss->stop_data = stop_data; |
9 | 418 } |
419 else | |
420 { | |
119
197b8d2e52ce
Thu Nov 30 09:55:42 2006 John Ellis <johne@verizon.net>
gqview
parents:
89
diff
changeset
|
421 slideshow_free(ss); |
9 | 422 ss = NULL; |
423 } | |
424 | |
425 return ss; | |
426 } | |
427 | |
1623
66d4bd637fd7
use layout_set_fd() for changing images from a slideshow
nadvornik
parents:
1523
diff
changeset
|
428 SlideShowData *slideshow_start_from_filelist(LayoutWindow *target_lw, ImageWindow *imd, GList *list, |
9 | 429 void (*stop_func)(SlideShowData *, gpointer), gpointer stop_data) |
430 { | |
1623
66d4bd637fd7
use layout_set_fd() for changing images from a slideshow
nadvornik
parents:
1523
diff
changeset
|
431 return real_slideshow_start(target_lw, imd, list, -1, NULL, NULL, stop_func, stop_data); |
9 | 432 } |
433 | |
1623
66d4bd637fd7
use layout_set_fd() for changing images from a slideshow
nadvornik
parents:
1523
diff
changeset
|
434 SlideShowData *slideshow_start_from_collection(LayoutWindow *target_lw, ImageWindow *imd, CollectionData *cd, |
9 | 435 void (*stop_func)(SlideShowData *, gpointer), gpointer stop_data, |
436 CollectInfo *start_info) | |
437 { | |
1623
66d4bd637fd7
use layout_set_fd() for changing images from a slideshow
nadvornik
parents:
1523
diff
changeset
|
438 return real_slideshow_start(target_lw, imd, NULL, -1, cd, start_info, stop_func, stop_data); |
9 | 439 } |
440 | |
1623
66d4bd637fd7
use layout_set_fd() for changing images from a slideshow
nadvornik
parents:
1523
diff
changeset
|
441 SlideShowData *slideshow_start(LayoutWindow *lw, gint start_point, |
9 | 442 void (*stop_func)(SlideShowData *, gpointer), gpointer stop_data) |
443 { | |
1623
66d4bd637fd7
use layout_set_fd() for changing images from a slideshow
nadvornik
parents:
1523
diff
changeset
|
444 return real_slideshow_start(lw, NULL, NULL, start_point, NULL, NULL, stop_func, stop_data); |
9 | 445 } |
446 | |
1433
b4ad1d201279
Use gboolean where applicable, minor cleanup and indentations fixes.
zas_
parents:
1365
diff
changeset
|
447 gboolean slideshow_paused(SlideShowData *ss) |
9 | 448 { |
449 if (!ss) return FALSE; | |
450 | |
451 return ss->paused; | |
452 } | |
453 | |
1433
b4ad1d201279
Use gboolean where applicable, minor cleanup and indentations fixes.
zas_
parents:
1365
diff
changeset
|
454 void slideshow_pause_set(SlideShowData *ss, gboolean paused) |
9 | 455 { |
456 if (!ss) return; | |
457 | |
458 ss->paused = paused; | |
459 } | |
460 | |
1433
b4ad1d201279
Use gboolean where applicable, minor cleanup and indentations fixes.
zas_
parents:
1365
diff
changeset
|
461 gboolean slideshow_pause_toggle(SlideShowData *ss) |
9 | 462 { |
463 slideshow_pause_set(ss, !slideshow_paused(ss)); | |
464 return slideshow_paused(ss); | |
465 } | |
1055
1646720364cf
Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents:
1000
diff
changeset
|
466 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |