diff options
author | Daniel Friesel <derf@finalrewind.org> | 2011-04-26 17:02:24 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2011-04-26 17:02:24 +0200 |
commit | b4c95797ed5f88deacbda18d9364fdbeaf2bc100 (patch) | |
tree | 8c022f760658740a1199a08cf08572ab72e1a119 | |
parent | 569c27a1c68cdac24cc603a8a033f90747010c98 (diff) |
Only create caption directory when writing out a caption (closes #42)
-rw-r--r-- | src/feh.h | 2 | ||||
-rw-r--r-- | src/imlib.c | 13 | ||||
-rw-r--r-- | src/keyevents.c | 5 |
3 files changed, 13 insertions, 7 deletions
@@ -143,7 +143,7 @@ void slideshow_save_image(winwidget win); void feh_edit_inplace_orient(winwidget w, int orientation); void feh_edit_inplace_lossless_rotate(winwidget w, int orientation); gib_list *feh_wrap_string(char *text, int wrap_width, Imlib_Font fn, gib_style * style); -char *build_caption_filename(feh_file * file); +char *build_caption_filename(feh_file * file, short create_dir); gib_list *feh_list_jump(gib_list * root, gib_list * l, int direction, int num); /* Imlib stuff */ diff --git a/src/imlib.c b/src/imlib.c index d125286..dcf3c5c 100644 --- a/src/imlib.c +++ b/src/imlib.c @@ -505,7 +505,7 @@ void feh_draw_info(winwidget w) return; } -char *build_caption_filename(feh_file * file) +char *build_caption_filename(feh_file * file, short create_dir) { char *caption_filename; char *s, *dir, *caption_dir; @@ -524,6 +524,8 @@ char *build_caption_filename(feh_file * file) D(("dir %s, cp %s, cdir %s\n", dir, opt.caption_path, caption_dir)) if (stat(caption_dir, &cdir_stat) == -1) { + if (!create_dir) + return NULL; if (mkdir(caption_dir, 0755) == -1) eprintf("Failed to create caption directory %s:", caption_dir); } else if (!S_ISDIR(cdir_stat.st_mode)) @@ -559,9 +561,12 @@ void feh_draw_caption(winwidget w) if (!file->caption) { char *caption_filename; - caption_filename = build_caption_filename(file); - /* read caption from file */ - file->caption = ereadfile(caption_filename); + caption_filename = build_caption_filename(file, 0); + if (caption_filename) + /* read caption from file */ + file->caption = ereadfile(caption_filename); + else + file->caption = estrdup(""); free(caption_filename); } diff --git a/src/keyevents.c b/src/keyevents.c index 896087e..e43ae33 100644 --- a/src/keyevents.c +++ b/src/keyevents.c @@ -377,14 +377,15 @@ void feh_event_handle_keypress(XEvent * ev) /* finish caption entry, write to captions file */ FILE *fp; char *caption_filename; - caption_filename = build_caption_filename(FEH_FILE(winwid->file->data)); + caption_filename = + build_caption_filename(FEH_FILE(winwid->file->data), 1); winwid->caption_entry = 0; winwidget_render_image_cached(winwid); XFreePixmap(disp, winwid->bg_pmap_cache); winwid->bg_pmap_cache = 0; fp = fopen(caption_filename, "w"); if (!fp) { - weprintf("couldn't write to captions file %s:", caption_filename); + eprintf("couldn't write to captions file %s:", caption_filename); return; } fprintf(fp, "%s", FEH_FILE(winwid->file->data)->caption); |