Skip to content
Newer
Older
100644 566 lines (495 sloc) 13.7 KB
21c4996 Initial commit (upstream 1.3.4)
Daniel Friesel authored
1 /* slideshow.c
2
3 Copyright (C) 1999-2003 Tom Gilbert.
0320dfb @derf Copyright Foo
authored
4 Copyright (C) 2010-2011 Daniel Friesel.
21c4996 Initial commit (upstream 1.3.4)
Daniel Friesel authored
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies of the Software and its documentation and acknowledgment shall be
15 given in the documentation and software packages that this Software was
16 used.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
22 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
25 */
26
27 #include "feh.h"
28 #include "filelist.h"
29 #include "timers.h"
30 #include "winwidget.h"
31 #include "options.h"
78a066b Use SIGUSR1/SIGUSR2 in slideshow mode to change images
Daniel Friesel authored
32 #include "signals.h"
21c4996 Initial commit (upstream 1.3.4)
Daniel Friesel authored
33
8ded860 Change source code indentation (indent -kr -i8 -hnl, mainly)
Daniel Friesel authored
34 void init_slideshow_mode(void)
21c4996 Initial commit (upstream 1.3.4)
Daniel Friesel authored
35 {
8ded860 Change source code indentation (indent -kr -i8 -hnl, mainly)
Daniel Friesel authored
36 winwidget w = NULL;
37 int success = 0;
38 char *s = NULL;
51802b3 Make --start-at work with filenames instead of list positions
Daniel Friesel authored
39 gib_list *l = filelist, *last = NULL;
8ded860 Change source code indentation (indent -kr -i8 -hnl, mainly)
Daniel Friesel authored
40 feh_file *file = NULL;
41
51802b3 Make --start-at work with filenames instead of list positions
Daniel Friesel authored
42 for (l = filelist; l && opt.start_list_at; l = l->next) {
43 if (!strcmp(opt.start_list_at, FEH_FILE(l->data)->filename)) {
44 opt.start_list_at = NULL;
45 break;
46 }
8ded860 Change source code indentation (indent -kr -i8 -hnl, mainly)
Daniel Friesel authored
47 }
51802b3 Make --start-at work with filenames instead of list positions
Daniel Friesel authored
48
49 if (opt.start_list_at)
50 eprintf("--start-at %s: File not found in filelist",
51 opt.start_list_at);
52
53 mode = "slideshow";
8ded860 Change source code indentation (indent -kr -i8 -hnl, mainly)
Daniel Friesel authored
54 for (; l; l = l->next) {
55 file = FEH_FILE(l->data);
56 if (last) {
57 filelist = feh_file_remove_from_list(filelist, last);
58 last = NULL;
59 }
60 current_file = l;
61 s = slideshow_create_name(file);
62 if ((w = winwidget_create_from_file(l, s, WIN_TYPE_SLIDESHOW)) != NULL) {
63 free(s);
64 success = 1;
65 winwidget_show(w);
9087479 Allow specifying slideshow-delay while starting the slideshow in paus…
Daniel Friesel authored
66 if (opt.slideshow_delay > 0.0)
8ded860 Change source code indentation (indent -kr -i8 -hnl, mainly)
Daniel Friesel authored
67 feh_add_timer(cb_slide_timer, w, opt.slideshow_delay, "SLIDE_CHANGE");
68 else if (opt.reload > 0)
69 feh_add_unique_timer(cb_reload_timer, w, opt.reload);
70 break;
71 } else {
72 free(s);
73 last = l;
74 }
75 }
76 if (!success)
77 show_mini_usage();
78a066b Use SIGUSR1/SIGUSR2 in slideshow mode to change images
Daniel Friesel authored
78
79 setup_signal_handlers();
80
a12feb1 Remove D_ENTER/D_RETURN, use gdb tracepoints + readelf/awk magic instead
Daniel Friesel authored
81 return;
21c4996 Initial commit (upstream 1.3.4)
Daniel Friesel authored
82 }
83
8ded860 Change source code indentation (indent -kr -i8 -hnl, mainly)
Daniel Friesel authored
84 void cb_slide_timer(void *data)
21c4996 Initial commit (upstream 1.3.4)
Daniel Friesel authored
85 {
64e9c95 @derf Show correct file number after deleting image
authored
86 slideshow_change_image((winwidget) data, SLIDE_NEXT, 1);
a12feb1 Remove D_ENTER/D_RETURN, use gdb tracepoints + readelf/awk magic instead
Daniel Friesel authored
87 return;
21c4996 Initial commit (upstream 1.3.4)
Daniel Friesel authored
88 }
89
8ded860 Change source code indentation (indent -kr -i8 -hnl, mainly)
Daniel Friesel authored
90 void cb_reload_timer(void *data)
21c4996 Initial commit (upstream 1.3.4)
Daniel Friesel authored
91 {
3fa3915 @livibetter Add reload functionality for directories (derf#14)
livibetter authored
92 gib_list *l;
93 char *current_filename;
94
8ded860 Change source code indentation (indent -kr -i8 -hnl, mainly)
Daniel Friesel authored
95 winwidget w = (winwidget) data;
21c4996 Initial commit (upstream 1.3.4)
Daniel Friesel authored
96
1d8d374 @derf Convert C++ style comments to /* */
authored
97 /* save the current filename for refinding it in new list */
3fa3915 @livibetter Add reload functionality for directories (derf#14)
livibetter authored
98 current_filename = estrdup(FEH_FILE(current_file->data)->filename);
99 gib_list_free_and_data(filelist);
100 filelist = NULL;
101 filelist_len = 0;
102 current_file = NULL;
103
1d8d374 @derf Convert C++ style comments to /* */
authored
104 /* rebuild filelist from original_file_items */
3fa3915 @livibetter Add reload functionality for directories (derf#14)
livibetter authored
105 if (gib_list_length(original_file_items) > 0)
106 for (l = gib_list_last(original_file_items); l; l = l->prev)
107 add_file_to_filelist_recursively(l->data, FILELIST_FIRST);
108 else if (!opt.filelistfile && !opt.bgmode)
109 add_file_to_filelist_recursively(".", FILELIST_FIRST);
110
111 if (!(filelist_len = gib_list_length(filelist))) {
112 fprintf(stderr, "No files found to reload.\n");
113 exit(1);
114 }
115
1d8d374 @derf Convert C++ style comments to /* */
authored
116 /* find the previously current file */
3fa3915 @livibetter Add reload functionality for directories (derf#14)
livibetter authored
117 for (l = filelist; l; l = l->next)
118 if (strcmp(FEH_FILE(l->data)->filename, current_filename) == 0) {
119 current_file = l;
120 break;
121 }
122
123 free(current_filename);
124
125 filelist = gib_list_first(gib_list_reverse(filelist));
126
127 if (!current_file)
128 current_file = filelist;
129 w->file = current_file;
130
1d8d374 @derf Convert C++ style comments to /* */
authored
131 /* reset window name in case of current file order,
132 * filename, or filelist_length has changed.
133 */
3fa3915 @livibetter Add reload functionality for directories (derf#14)
livibetter authored
134 current_filename = slideshow_create_name(FEH_FILE(current_file->data));
135 winwidget_rename(w, current_filename);
136 free(current_filename);
137
910e2e3 @derf Revert "feh_reload_image: Always die if reload failed"
authored
138 feh_reload_image(w, 1, 0);
8ded860 Change source code indentation (indent -kr -i8 -hnl, mainly)
Daniel Friesel authored
139 feh_add_unique_timer(cb_reload_timer, w, opt.reload);
a12feb1 Remove D_ENTER/D_RETURN, use gdb tracepoints + readelf/awk magic instead
Daniel Friesel authored
140 return;
21c4996 Initial commit (upstream 1.3.4)
Daniel Friesel authored
141 }
142
910e2e3 @derf Revert "feh_reload_image: Always die if reload failed"
authored
143 void feh_reload_image(winwidget w, int resize, int force_new)
21c4996 Initial commit (upstream 1.3.4)
Daniel Friesel authored
144 {
8ded860 Change source code indentation (indent -kr -i8 -hnl, mainly)
Daniel Friesel authored
145 char *title, *new_title;
146 int len;
147 Imlib_Image tmp;
44987e9 @derf feh_reload_image: Work around broken Imlib2 caching (closes #39)
authored
148 int old_w, old_h;
8ded860 Change source code indentation (indent -kr -i8 -hnl, mainly)
Daniel Friesel authored
149
150 if (!w->file) {
65b5d9c @derf Initial support for in-image warning display (closes #43)
authored
151 im_weprintf(w, "couldn't reload, this image has no file associated with it.");
ed5f55e @derf feh_reload_image: Try to reload unloadable (still existing) images ad…
authored
152 winwidget_render_image(w, 0, 0);
a12feb1 Remove D_ENTER/D_RETURN, use gdb tracepoints + readelf/awk magic instead
Daniel Friesel authored
153 return;
8ded860 Change source code indentation (indent -kr -i8 -hnl, mainly)
Daniel Friesel authored
154 }
155
910e2e3 @derf Revert "feh_reload_image: Always die if reload failed"
authored
156 D(("resize %d, force_new %d\n", resize, force_new));
44987e9 @derf feh_reload_image: Work around broken Imlib2 caching (closes #39)
authored
157
8ded860 Change source code indentation (indent -kr -i8 -hnl, mainly)
Daniel Friesel authored
158 free(FEH_FILE(w->file->data)->caption);
159 FEH_FILE(w->file->data)->caption = NULL;
160
161 len = strlen(w->name) + sizeof("Reloading: ") + 1;
162 new_title = emalloc(len);
163 snprintf(new_title, len, "Reloading: %s", w->name);
164 title = estrdup(w->name);
165 winwidget_rename(w, new_title);
166
44987e9 @derf feh_reload_image: Work around broken Imlib2 caching (closes #39)
authored
167 old_w = gib_imlib_image_get_width(w->im);
168 old_h = gib_imlib_image_get_height(w->im);
169
8b79bc3 @derf feh_reload_image: Always die if reload failed
authored
170 /* if the image has changed in dimensions - we gotta resize */
910e2e3 @derf Revert "feh_reload_image: Always die if reload failed"
authored
171 if ((feh_load_image(&tmp, FEH_FILE(w->file->data))) == 0) {
172 if (force_new) {
173 eprintf("failed to reload image\n");
174 } else {
175 im_weprintf(w, "Couldn't reload image. Is it still there?");
ed5f55e @derf feh_reload_image: Try to reload unloadable (still existing) images ad…
authored
176 winwidget_render_image(w, 0, 0);
910e2e3 @derf Revert "feh_reload_image: Always die if reload failed"
authored
177 }
178 winwidget_rename(w, title);
179 free(title);
180 free(new_title);
181 return;
182 }
183
44987e9 @derf feh_reload_image: Work around broken Imlib2 caching (closes #39)
authored
184 if (!resize && ((old_w != gib_imlib_image_get_width(tmp)) ||
185 (old_h != gib_imlib_image_get_height(tmp))))
8ded860 Change source code indentation (indent -kr -i8 -hnl, mainly)
Daniel Friesel authored
186 resize = 1;
44987e9 @derf feh_reload_image: Work around broken Imlib2 caching (closes #39)
authored
187
ed5f55e @derf feh_reload_image: Try to reload unloadable (still existing) images ad…
authored
188 /* force imlib2 not to cache */
189 winwidget_free_image(w);
190
44987e9 @derf feh_reload_image: Work around broken Imlib2 caching (closes #39)
authored
191 w->im = tmp;
192 winwidget_reset_image(w);
8ded860 Change source code indentation (indent -kr -i8 -hnl, mainly)
Daniel Friesel authored
193
194 w->mode = MODE_NORMAL;
195 if ((w->im_w != gib_imlib_image_get_width(w->im))
196 || (w->im_h != gib_imlib_image_get_height(w->im)))
197 w->had_resize = 1;
198 if (w->has_rotated) {
199 Imlib_Image temp;
200
201 temp = gib_imlib_create_rotated_image(w->im, 0.0);
202 w->im_w = gib_imlib_image_get_width(temp);
203 w->im_h = gib_imlib_image_get_height(temp);
204 gib_imlib_free_image_and_decache(temp);
205 } else {
206 w->im_w = gib_imlib_image_get_width(w->im);
207 w->im_h = gib_imlib_image_get_height(w->im);
208 }
56dec87 @derf Add method to forcefully disable antialiasing (closes GH-17)
authored
209 winwidget_render_image(w, resize, 0);
8ded860 Change source code indentation (indent -kr -i8 -hnl, mainly)
Daniel Friesel authored
210
211 winwidget_rename(w, title);
212 free(title);
213 free(new_title);
214
a12feb1 Remove D_ENTER/D_RETURN, use gdb tracepoints + readelf/awk magic instead
Daniel Friesel authored
215 return;
21c4996 Initial commit (upstream 1.3.4)
Daniel Friesel authored
216 }
217
64e9c95 @derf Show correct file number after deleting image
authored
218 void slideshow_change_image(winwidget winwid, int change, int render)
21c4996 Initial commit (upstream 1.3.4)
Daniel Friesel authored
219 {
8ded860 Change source code indentation (indent -kr -i8 -hnl, mainly)
Daniel Friesel authored
220 gib_list *last = NULL;
221 int i = 0;
222 int jmp = 1;
9b5fac8 @derf slideshow.c: Fix segfault after encountering multiple invalid images …
authored
223 /* We can't use filelist_len in the for loop, since that changes when we
224 * encounter invalid images.
225 */
226 int our_filelist_len = filelist_len;
8ded860 Change source code indentation (indent -kr -i8 -hnl, mainly)
Daniel Friesel authored
227 char *s;
228
229 /* Without this, clicking a one-image slideshow reloads it. Not very *
230 intelligent behaviour :-) */
231 if (filelist_len < 2 && opt.cycle_once == 0)
a12feb1 Remove D_ENTER/D_RETURN, use gdb tracepoints + readelf/awk magic instead
Daniel Friesel authored
232 return;
8ded860 Change source code indentation (indent -kr -i8 -hnl, mainly)
Daniel Friesel authored
233
234 /* Ok. I do this in such an odd way to ensure that if the last or first *
235 image is not loadable, it will go through in the right direction to *
236 find the correct one. Otherwise SLIDE_LAST would try the last file, *
237 then loop forward to find a loadable one. */
238 if (change == SLIDE_FIRST) {
239 current_file = gib_list_last(filelist);
240 change = SLIDE_NEXT;
241 } else if (change == SLIDE_LAST) {
242 current_file = filelist;
243 change = SLIDE_PREV;
244 }
245
246 /* The for loop prevents us looping infinitely */
9b5fac8 @derf slideshow.c: Fix segfault after encountering multiple invalid images …
authored
247 for (i = 0; i < our_filelist_len; i++) {
8ded860 Change source code indentation (indent -kr -i8 -hnl, mainly)
Daniel Friesel authored
248 winwidget_free_image(winwid);
249 switch (change) {
250 case SLIDE_NEXT:
251 current_file = feh_list_jump(filelist, current_file, FORWARD, 1);
252 break;
253 case SLIDE_PREV:
254 current_file = feh_list_jump(filelist, current_file, BACK, 1);
255 break;
7c12650 @decklin Implement random slideshow jump ('z')
decklin authored
256 case SLIDE_RAND:
257 current_file = feh_list_jump(filelist, current_file, FORWARD, rand() % filelist_len);
3f7ffcb Fix segfault related to the random slideshow jump feature
Daniel Friesel authored
258 change = SLIDE_NEXT;
7c12650 @decklin Implement random slideshow jump ('z')
decklin authored
259 break;
8ded860 Change source code indentation (indent -kr -i8 -hnl, mainly)
Daniel Friesel authored
260 case SLIDE_JUMP_FWD:
261 if (filelist_len < 5)
262 jmp = 1;
263 else if (filelist_len < 40)
264 jmp = 2;
265 else
266 jmp = filelist_len / 20;
267 if (!jmp)
268 jmp = 2;
269 current_file = feh_list_jump(filelist, current_file, FORWARD, jmp);
270 /* important. if the load fails, we only want to step on ONCE to
271 try the next file, not another jmp */
272 change = SLIDE_NEXT;
273 break;
274 case SLIDE_JUMP_BACK:
275 if (filelist_len < 5)
276 jmp = 1;
277 else if (filelist_len < 40)
278 jmp = 2;
279 else
280 jmp = filelist_len / 20;
281 if (!jmp)
282 jmp = 2;
283 current_file = feh_list_jump(filelist, current_file, BACK, jmp);
284 /* important. if the load fails, we only want to step back ONCE to
285 try the previous file, not another jmp */
286 change = SLIDE_NEXT;
287 break;
288 default:
289 eprintf("BUG!\n");
290 break;
291 }
292
293 if (last) {
294 filelist = feh_file_remove_from_list(filelist, last);
295 last = NULL;
296 }
297
298 if ((winwidget_loadimage(winwid, FEH_FILE(current_file->data)))
299 != 0) {
300 winwid->mode = MODE_NORMAL;
301 winwid->file = current_file;
302 if ((winwid->im_w != gib_imlib_image_get_width(winwid->im))
303 || (winwid->im_h != gib_imlib_image_get_height(winwid->im)))
304 winwid->had_resize = 1;
305 winwidget_reset_image(winwid);
306 winwid->im_w = gib_imlib_image_get_width(winwid->im);
307 winwid->im_h = gib_imlib_image_get_height(winwid->im);
64e9c95 @derf Show correct file number after deleting image
authored
308 if (render)
309 winwidget_render_image(winwid, 1, 0);
fc9b1de @derf Fix segfault upon unloadable image with --title %h/%w/... (closes GH-35)
authored
310
311 s = slideshow_create_name(FEH_FILE(current_file->data));
312 winwidget_rename(winwid, s);
313 free(s);
314
8ded860 Change source code indentation (indent -kr -i8 -hnl, mainly)
Daniel Friesel authored
315 break;
316 } else
317 last = current_file;
318 }
4e84bc4 Actually detect an empty filelist
Daniel Friesel authored
319 if (last)
320 filelist = feh_file_remove_from_list(filelist, last);
321
322 if (filelist_len == 0)
323 eprintf("No more slides in show");
324
9087479 Allow specifying slideshow-delay while starting the slideshow in paus…
Daniel Friesel authored
325 if (opt.slideshow_delay > 0.0)
8ded860 Change source code indentation (indent -kr -i8 -hnl, mainly)
Daniel Friesel authored
326 feh_add_timer(cb_slide_timer, winwid, opt.slideshow_delay, "SLIDE_CHANGE");
a12feb1 Remove D_ENTER/D_RETURN, use gdb tracepoints + readelf/awk magic instead
Daniel Friesel authored
327 return;
21c4996 Initial commit (upstream 1.3.4)
Daniel Friesel authored
328 }
329
8ded860 Change source code indentation (indent -kr -i8 -hnl, mainly)
Daniel Friesel authored
330 void slideshow_pause_toggle(winwidget w)
21c4996 Initial commit (upstream 1.3.4)
Daniel Friesel authored
331 {
8ded860 Change source code indentation (indent -kr -i8 -hnl, mainly)
Daniel Friesel authored
332 if (!opt.paused) {
333 opt.paused = 1;
334 } else {
335 opt.paused = 0;
336 }
69d69f1 Patch by muennich: Correctly set [Paused] window title
Daniel Friesel authored
337
338 winwidget_rename(w, NULL);
21c4996 Initial commit (upstream 1.3.4)
Daniel Friesel authored
339 }
340
8ded860 Change source code indentation (indent -kr -i8 -hnl, mainly)
Daniel Friesel authored
341 char *slideshow_create_name(feh_file * file)
21c4996 Initial commit (upstream 1.3.4)
Daniel Friesel authored
342 {
8ded860 Change source code indentation (indent -kr -i8 -hnl, mainly)
Daniel Friesel authored
343 char *s = NULL;
344 int len = 0;
345
346 if (!opt.title) {
347 len = strlen(PACKAGE " [slideshow mode] - ") + strlen(file->filename) + 1;
348 s = emalloc(len);
349 snprintf(s, len, PACKAGE " [%d of %d] - %s",
3f7ffcb Fix segfault related to the random slideshow jump feature
Daniel Friesel authored
350 gib_list_num(filelist, current_file) + 1, gib_list_length(filelist), file->filename);
8ded860 Change source code indentation (indent -kr -i8 -hnl, mainly)
Daniel Friesel authored
351 } else {
352 s = estrdup(feh_printf(opt.title, file));
353 }
354
a12feb1 Remove D_ENTER/D_RETURN, use gdb tracepoints + readelf/awk magic instead
Daniel Friesel authored
355 return(s);
21c4996 Initial commit (upstream 1.3.4)
Daniel Friesel authored
356 }
357
8ded860 Change source code indentation (indent -kr -i8 -hnl, mainly)
Daniel Friesel authored
358 void feh_action_run(feh_file * file, char *action)
21c4996 Initial commit (upstream 1.3.4)
Daniel Friesel authored
359 {
8ded860 Change source code indentation (indent -kr -i8 -hnl, mainly)
Daniel Friesel authored
360 if (action) {
361 char *sys;
ae46674 --debug-level → --debug
Daniel Friesel authored
362 D(("Running action %s\n", action));
8ded860 Change source code indentation (indent -kr -i8 -hnl, mainly)
Daniel Friesel authored
363 sys = feh_printf(action, file);
364
365 if (opt.verbose && !opt.list && !opt.customlist)
366 fprintf(stderr, "Running action -->%s<--\n", sys);
367 system(sys);
368 }
a12feb1 Remove D_ENTER/D_RETURN, use gdb tracepoints + readelf/awk magic instead
Daniel Friesel authored
369 return;
21c4996 Initial commit (upstream 1.3.4)
Daniel Friesel authored
370 }
371
8ded860 Change source code indentation (indent -kr -i8 -hnl, mainly)
Daniel Friesel authored
372 char *feh_printf(char *str, feh_file * file)
21c4996 Initial commit (upstream 1.3.4)
Daniel Friesel authored
373 {
8ded860 Change source code indentation (indent -kr -i8 -hnl, mainly)
Daniel Friesel authored
374 char *c;
375 char buf[20];
376 static char ret[4096];
377
378 ret[0] = '\0';
379
380 for (c = str; *c != '\0'; c++) {
381 if (*c == '%') {
382 c++;
383 switch (*c) {
384 case 'f':
385 if (file)
386 strcat(ret, file->filename);
387 break;
388 case 'n':
389 if (file)
390 strcat(ret, file->name);
391 break;
392 case 'w':
393 if (file) {
394 if (!file->info)
395 feh_file_info_load(file, NULL);
396 snprintf(buf, sizeof(buf), "%d", file->info->width);
397 strcat(ret, buf);
398 }
399 break;
400 case 'h':
401 if (file) {
402 if (!file->info)
403 feh_file_info_load(file, NULL);
404 snprintf(buf, sizeof(buf), "%d", file->info->height);
405 strcat(ret, buf);
406 }
407 break;
408 case 's':
409 if (file) {
410 if (!file->info)
411 feh_file_info_load(file, NULL);
412 snprintf(buf, sizeof(buf), "%d", file->info->size);
413 strcat(ret, buf);
414 }
415 break;
416 case 'p':
417 if (file) {
418 if (!file->info)
419 feh_file_info_load(file, NULL);
420 snprintf(buf, sizeof(buf), "%d", file->info->pixels);
421 strcat(ret, buf);
422 }
423 break;
424 case 't':
425 if (file) {
426 if (!file->info)
427 feh_file_info_load(file, NULL);
428 strcat(ret, file->info->format);
429 }
430 break;
431 case 'P':
432 strcat(ret, PACKAGE);
433 break;
434 case 'v':
435 strcat(ret, VERSION);
436 break;
437 case 'm':
438 strcat(ret, mode);
439 break;
440 case 'l':
441 snprintf(buf, sizeof(buf), "%d", gib_list_length(filelist));
442 strcat(ret, buf);
443 break;
444 case 'u':
445 snprintf(buf, sizeof(buf), "%d",
446 current_file != NULL ? gib_list_num(filelist, current_file)
447 + 1 : 0);
448 strcat(ret, buf);
449 break;
450 default:
451 strncat(ret, c, 1);
452 break;
453 }
454 } else if (*c == '\\') {
455 c++;
456 switch (*c) {
457 case 'n':
458 strcat(ret, "\n");
459 break;
460 default:
461 strncat(ret, c, 1);
462 break;
463 }
464 } else
465 strncat(ret, c, 1);
466 }
a12feb1 Remove D_ENTER/D_RETURN, use gdb tracepoints + readelf/awk magic instead
Daniel Friesel authored
467 return(ret);
21c4996 Initial commit (upstream 1.3.4)
Daniel Friesel authored
468 }
469
8ded860 Change source code indentation (indent -kr -i8 -hnl, mainly)
Daniel Friesel authored
470 void feh_filelist_image_remove(winwidget winwid, char do_delete)
21c4996 Initial commit (upstream 1.3.4)
Daniel Friesel authored
471 {
8ded860 Change source code indentation (indent -kr -i8 -hnl, mainly)
Daniel Friesel authored
472 if (winwid->type == WIN_TYPE_SLIDESHOW) {
473 char *s;
474 gib_list *doomed;
475
476 doomed = current_file;
64e9c95 @derf Show correct file number after deleting image
authored
477 slideshow_change_image(winwid, SLIDE_NEXT, 0);
8ded860 Change source code indentation (indent -kr -i8 -hnl, mainly)
Daniel Friesel authored
478 if (do_delete)
479 filelist = feh_file_rm_and_free(filelist, doomed);
480 else
481 filelist = feh_file_remove_from_list(filelist, doomed);
482 if (!filelist) {
483 /* No more images. Game over ;-) */
484 winwidget_destroy(winwid);
485 return;
486 }
487 s = slideshow_create_name(FEH_FILE(winwid->file->data));
488 winwidget_rename(winwid, s);
489 free(s);
64e9c95 @derf Show correct file number after deleting image
authored
490 winwidget_render_image(winwid, 1, 0);
8ded860 Change source code indentation (indent -kr -i8 -hnl, mainly)
Daniel Friesel authored
491 } else if ((winwid->type == WIN_TYPE_SINGLE)
492 || (winwid->type == WIN_TYPE_THUMBNAIL_VIEWER)) {
493 if (do_delete)
494 filelist = feh_file_rm_and_free(filelist, winwid->file);
495 else
496 filelist = feh_file_remove_from_list(filelist, winwid->file);
497 winwidget_destroy(winwid);
498 }
21c4996 Initial commit (upstream 1.3.4)
Daniel Friesel authored
499 }
500
501 void slideshow_save_image(winwidget win)
502 {
8ded860 Change source code indentation (indent -kr -i8 -hnl, mainly)
Daniel Friesel authored
503 char *tmpname;
ff2cb2b Print an error if 's' button (slidehsow_save_image) fails
Daniel Friesel authored
504 Imlib_Load_Error err;
8ded860 Change source code indentation (indent -kr -i8 -hnl, mainly)
Daniel Friesel authored
505
506 if (win->file) {
507 tmpname = feh_unique_filename("", FEH_FILE(win->file->data)->name);
508 } else if (mode) {
509 char *tmp;
510 tmp = estrjoin(".", mode, "png", NULL);
511 tmpname = feh_unique_filename("", tmp);
512 free(tmp);
513 } else {
514 tmpname = feh_unique_filename("", "noname.png");
515 }
516
517 if (!opt.quiet)
518 printf("saving image to filename '%s'\n", tmpname);
519
ae1de0d @derf slideshow.c: save_image: Fix handling of capital file endings (closes #…
authored
520 /* XXX gib_imlib_save_image_with_error_return breaks with *.XXX and
521 * similar because it tries to set the image format, which only works
522 * with .xxx .
523 * So we leave that part out.
524 */
525 imlib_context_set_image(win->im);
526 imlib_save_image_with_error_return(tmpname, &err);
527
ff2cb2b Print an error if 's' button (slidehsow_save_image) fails
Daniel Friesel authored
528 if (err)
65b5d9c @derf Initial support for in-image warning display (closes #43)
authored
529 im_weprintf(win, "Can't save image %s:", tmpname);
ff2cb2b Print an error if 's' button (slidehsow_save_image) fails
Daniel Friesel authored
530
8ded860 Change source code indentation (indent -kr -i8 -hnl, mainly)
Daniel Friesel authored
531 free(tmpname);
a12feb1 Remove D_ENTER/D_RETURN, use gdb tracepoints + readelf/awk magic instead
Daniel Friesel authored
532 return;
21c4996 Initial commit (upstream 1.3.4)
Daniel Friesel authored
533 }
534
8ded860 Change source code indentation (indent -kr -i8 -hnl, mainly)
Daniel Friesel authored
535 gib_list *feh_list_jump(gib_list * root, gib_list * l, int direction, int num)
21c4996 Initial commit (upstream 1.3.4)
Daniel Friesel authored
536 {
8ded860 Change source code indentation (indent -kr -i8 -hnl, mainly)
Daniel Friesel authored
537 int i;
538 gib_list *ret = NULL;
539
540 if (!root)
541 return (NULL);
542 if (!l)
543 return (root);
544
545 ret = l;
546
547 for (i = 0; i < num; i++) {
548 if (direction == FORWARD) {
549 if (ret->next) {
550 ret = ret->next;
551 } else {
552 if (opt.cycle_once) {
553 exit(0);
554 }
555 ret = root;
556 }
557 } else {
558 if (ret->prev)
559 ret = ret->prev;
560 else
561 ret = gib_list_last(ret);
562 }
563 }
564 return (ret);
21c4996 Initial commit (upstream 1.3.4)
Daniel Friesel authored
565 }
Something went wrong with that request. Please try again.