diff --git a/man/feh.pre b/man/feh.pre index 0ec26131..76c569cf 100644 --- a/man/feh.pre +++ b/man/feh.pre @@ -1327,6 +1327,10 @@ Human-readable image size . Image format . +.It \&%T +. +Temporary output filename +. .It %u . Number of current file diff --git a/src/filelist.c b/src/filelist.c index 0aeaa022..4969ca3d 100644 --- a/src/filelist.c +++ b/src/filelist.c @@ -49,6 +49,7 @@ feh_file *feh_file_new(char *filename) newfile = (feh_file *) emalloc(sizeof(feh_file)); newfile->caption = NULL; newfile->filename = estrdup(filename); + newfile->tempname = NULL; s = strrchr(filename, '/'); if (s) newfile->name = estrdup(s + 1); @@ -67,6 +68,10 @@ void feh_file_free(feh_file * file) return; if (file->filename) free(file->filename); + if (file->tempname) { + unlink(file->tempname); + free(file->tempname); + } if (file->name) free(file->name); if (file->caption) diff --git a/src/filelist.h b/src/filelist.h index ff0645e1..608bbd2c 100644 --- a/src/filelist.h +++ b/src/filelist.h @@ -32,6 +32,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. struct __feh_file { char *filename; + char *tempname; char *caption; char *name; diff --git a/src/help.raw b/src/help.raw index 3c65fcc5..f7bea069 100644 --- a/src/help.raw +++ b/src/help.raw @@ -144,6 +144,7 @@ FORMAT SPECIFIERS %s image size in bytes %S image size with appropriate unit (kB/MB) %t image format + %T temporary output filename %u current file number %w image width %v " PACKAGE " version diff --git a/src/imlib.c b/src/imlib.c index add88d60..c6ccacba 100644 --- a/src/imlib.c +++ b/src/imlib.c @@ -249,7 +249,9 @@ void feh_print_load_error(char *file, winwidget w, Imlib_Load_Error err, enum fe int feh_is_image(feh_file * file) { unsigned char buf[16]; - FILE *fh = fopen(file->filename, "r"); + char *filename = file->tempname ? file->tempname : file->filename; + + FILE *fh = fopen(filename, "r"); if (!fh) { return 0; } @@ -297,7 +299,7 @@ int feh_is_image(feh_file * file) // PNM et al. return 1; } - if (strstr(file->filename, ".tga")) { + if (strstr(filename, ".tga")) { // TGA return 1; } @@ -324,7 +326,7 @@ int feh_is_image(feh_file * file) // XPM return 1; } - if (strstr(file->filename, ".bz2") || strstr(file->filename, ".gz")) { + if (strstr(filename, ".bz2") || strstr(filename, ".gz")) { // Imlib2 supports compressed images. It relies on the filename to // determine the appropriate loader and does not use magic bytes here. return 1; @@ -343,42 +345,42 @@ int feh_load_image(Imlib_Image * im, feh_file * file) enum { SRC_IMLIB, SRC_HTTP, SRC_MAGICK, SRC_DCRAW } image_source = SRC_IMLIB; char *tmpname = NULL; char *real_filename = NULL; + char *filename; D(("filename is %s, image is %p\n", file->filename, im)); if (!file || !file->filename) return 0; - - if (path_is_url(file->filename)) { + filename = file->tempname ? file->tempname : file->filename; + if (path_is_url(filename)) { image_source = SRC_HTTP; - if ((tmpname = feh_http_load_image(file->filename)) == NULL) { + if ((tmpname = feh_http_load_image(filename)) == NULL) { feh_err = LOAD_ERROR_CURL; err = IMLIB_LOAD_ERROR_FILE_DOES_NOT_EXIST; } } else { if (feh_is_image(file)) { - *im = imlib_load_image_with_error_return(file->filename, &err); + *im = imlib_load_image_with_error_return(filename, &err); } else { feh_err = LOAD_ERROR_MAGICBYTES; err = IMLIB_LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT; } } - if (opt.conversion_timeout >= 0 && ( (err == IMLIB_LOAD_ERROR_UNKNOWN) || (err == IMLIB_LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT))) { - if (feh_file_is_raw(file->filename)) { + if (feh_file_is_raw(filename)) { image_source = SRC_DCRAW; - tmpname = feh_dcraw_load_image(file->filename); + tmpname = feh_dcraw_load_image(filename); if (!tmpname) { feh_err = LOAD_ERROR_DCRAW; } } else { image_source = SRC_MAGICK; feh_err = LOAD_ERROR_IMLIB; - tmpname = feh_magick_load_image(file->filename); + tmpname = feh_magick_load_image(filename); if (!tmpname) { feh_err = LOAD_ERROR_IMAGEMAGICK; } @@ -388,7 +390,7 @@ int feh_load_image(Imlib_Image * im, feh_file * file) if (tmpname) { *im = imlib_load_image_with_error_return(tmpname, &err); if (!err && im) { - real_filename = file->filename; + real_filename = filename; file->filename = tmpname; /* diff --git a/src/slideshow.c b/src/slideshow.c index 87ec4cb6..298835e3 100644 --- a/src/slideshow.c +++ b/src/slideshow.c @@ -511,6 +511,14 @@ char *feh_printf(char *str, feh_file * file, winwidget winwid) strncat(ret, file->info->format, sizeof(ret) - strlen(ret) - 1); } break; + case 'T': + if (file) { + if (file->tempname == NULL) { + file->tempname = feh_unique_filename("/tmp/","feh_tempname"); + } + strncat(ret, file->tempname, sizeof(ret) - strlen(ret) - 1); + } + break; case 'u': f = current_file ? current_file : gib_list_find_by_data(filelist, file); snprintf(buf, sizeof(buf), "%d", f ? gib_list_num(filelist, f) + 1 : 0);