Commit 65b5d9c1 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

Initial support for in-image warning display (closes #43)

parent f1f2df16
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -8,6 +8,8 @@ git HEAD
    * read directory contents sorted by filename instead of 'randomly'
      (as returned by readdir) by default. Thanks talisein!
      <https://github.com/derf/feh/pull/20>
    * Show certain warnings in the image window as well as on the commandline
      <http://github.com/derf/feh/issues/43>

Sat, 23 Apr 2011 22:00:27 +0200  Daniel Friesel <derf@finalrewind.org>

+2 −0
Original line number Diff line number Diff line
@@ -125,6 +125,7 @@ void init_keyevents(void);
void feh_event_handle_keypress(XEvent * ev);
void feh_action_run(feh_file * file, char *action);
char *feh_printf(char *str, feh_file * file);
void im_weprintf(winwidget w, char *fmt, ...);
void feh_draw_zoom(winwidget w);
void feh_draw_checks(winwidget win);
void cb_slide_timer(void *data);
@@ -135,6 +136,7 @@ void feh_draw_filename(winwidget w);
void feh_draw_actions(winwidget w);
void feh_draw_caption(winwidget w);
void feh_draw_info(winwidget w);
void feh_draw_errstr(winwidget w);
void feh_display_status(char stat);
void real_loadables_mode(int loadable);
void feh_reload_image(winwidget w, int resize, int force_new);
+75 −9
Original line number Diff line number Diff line
@@ -364,6 +364,70 @@ void feh_draw_zoom(winwidget w)
	return;
}

void im_weprintf(winwidget w, char *fmt, ...)
{
	va_list args;
	char *errstr = emalloc(1024);

	fflush(stdout);
	fputs(PACKAGE " WARNING: ", stderr);

	va_start(args, fmt);
	vsnprintf(errstr, 1024, fmt, args);
	va_end(args);

	if (w)
		w->errstr = errstr;

	fputs(errstr, stderr);
	if (fmt[0] != '\0' && fmt[strlen(fmt) - 1] == ':')
		fprintf(stderr, " %s", strerror(errno));
	fputs("\n", stderr);
}


void feh_draw_errstr(winwidget w)
{
	static Imlib_Font fn = NULL;
	int tw = 0, th = 0;
	Imlib_Image im = NULL;
	static DATA8 atab[256];

	if (!w->im)
		return;

	if (opt.font)
		fn = gib_imlib_load_font(opt.font);

	if (!fn)
		fn = gib_imlib_load_font(DEFAULT_FONT);

	if (!fn)
		eprintf("Unable to draw error message. Dying to be safe.");

	memset(atab, 0, sizeof(atab));

	/* Work out how high the font is */
	gib_imlib_get_text_size(fn, w->errstr, NULL, &tw, &th, IMLIB_TEXT_TO_RIGHT);

	tw += 3;
	th += 3;
	im = imlib_create_image(tw, th);
	if (!im)
		eprintf("Couldn't create errstr image. Out of memory?");

	gib_imlib_image_set_has_alpha(im, 1);
	gib_imlib_apply_color_modifier_to_rectangle(im, 0, 0, tw, th, NULL, NULL, NULL, atab);
	gib_imlib_image_fill_rectangle(im, 0, 0, tw, th, 0, 0, 0, 0);

	gib_imlib_text_draw(im, fn, NULL, 2, 2, w->errstr, IMLIB_TEXT_TO_RIGHT, 0, 0, 0, 255);
	gib_imlib_text_draw(im, fn, NULL, 1, 1, w->errstr, IMLIB_TEXT_TO_RIGHT, 255, 0, 0, 255);
	free(w->errstr);
	w->errstr = NULL;
	gib_imlib_render_image_on_drawable(w->bg_pmap, im, 0, w->h - th, 1, 1, 0);
	gib_imlib_free_image_and_decache(im);
}

void feh_draw_filename(winwidget w)
{
	static Imlib_Font fn = NULL;
@@ -388,7 +452,7 @@ void feh_draw_filename(winwidget w)
	}

	if (!fn) {
		weprintf("Couldn't load font for filename printing");
		eprintf("Couldn't load font for filename printing");
		return;
	}

@@ -457,7 +521,7 @@ void feh_draw_info(winwidget w)
	}

	if (!fn) {
		weprintf("Couldn't load font for filename printing");
		eprintf("Couldn't load font for filename printing");
		return;
	}

@@ -602,7 +666,7 @@ void feh_draw_caption(winwidget w)
	}

	if (!fn) {
		weprintf("Couldn't load font for caption printing");
		eprintf("Couldn't load font for caption printing");
		return;
	}

@@ -731,7 +795,7 @@ void feh_edit_inplace_orient(winwidget w, int orientation)
		gib_imlib_free_image(old);
		feh_reload_image(w, 1, 1);
	} else {
		weprintf("failed to load image from disk to edit it in place\n");
		weprintf("failed to load image from disk to edit it in place");
	}

	return;
@@ -855,14 +919,16 @@ void feh_edit_inplace_lossless_rotate(winwidget w, int orientation)
		execlp("jpegtran", "jpegtran", "-copy", "all", "-rotate",
				rotate_str, "-outfile", file_str, file_str, NULL);

		eprintf("lossless rotate: Is 'jpegtran' installed? Failed to exec:");
		weprintf("lossless rotate: Is 'jpegtran' installed? Failed to exec:");
		return;
	} else {
		waitpid(pid, &status, 0);

		if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
			weprintf("lossless rotate: Got exitcode %d from jpegtran."
					" Commandline was:\n"
					"jpegtran -copy all -rotate %s -outfile %s %s\n",
			im_weprintf(w,
					"lossless rotate: Got exitcode %d from jpegtran."
					" Commandline was: "
					"jpegtran -copy all -rotate %s -outfile %s %s",
					status >> 8, rotate_str, file_str, file_str);
			return;
		}
@@ -911,7 +977,7 @@ void feh_draw_actions(winwidget w)
	}

	if (!fn) {
		weprintf("Couldn't load font for actions printing");
		eprintf("Couldn't load font for actions printing");
		return;
	}

+3 −3
Original line number Diff line number Diff line
@@ -104,7 +104,7 @@ void feh_reload_image(winwidget w, int resize, int force_new)
	int old_w, old_h;

	if (!w->file) {
		weprintf("couldn't reload, this image has no file associated with it.");
		im_weprintf(w, "couldn't reload, this image has no file associated with it.");
		return;
	}

@@ -130,7 +130,7 @@ void feh_reload_image(winwidget w, int resize, int force_new)
		if (force_new) {
			eprintf("failed to reload image\n");
		} else {
			weprintf("Couldn't reload image. Is it still there?");
			im_weprintf(w, "Couldn't reload image. Is it still there?");
		}
		winwidget_rename(w, title);
		free(title);
@@ -474,7 +474,7 @@ void slideshow_save_image(winwidget win)

	gib_imlib_save_image_with_error_return(win->im, tmpname, &err);
	if (err)
		weprintf("Can't save image %s:", tmpname);
		im_weprintf(win, "Can't save image %s:", tmpname);

	free(tmpname);
	return;
+4 −4
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ void eprintf(char *fmt, ...)
	va_list args;

	fflush(stdout);
	fprintf(stderr, "%s ERROR: ", PACKAGE);
	fputs(PACKAGE " ERROR: ", stderr);

	va_start(args, fmt);
	vfprintf(stderr, fmt, args);
@@ -44,7 +44,7 @@ void eprintf(char *fmt, ...)

	if (fmt[0] != '\0' && fmt[strlen(fmt) - 1] == ':')
		fprintf(stderr, " %s", strerror(errno));
	fprintf(stderr, "\n");
	fputs("\n", stderr);
	exit(2);
}

@@ -54,7 +54,7 @@ void weprintf(char *fmt, ...)
	va_list args;

	fflush(stdout);
	fprintf(stderr, "%s WARNING: ", PACKAGE);
	fputs(PACKAGE " WARNING: ", stderr);

	va_start(args, fmt);
	vfprintf(stderr, fmt, args);
@@ -62,7 +62,7 @@ void weprintf(char *fmt, ...)

	if (fmt[0] != '\0' && fmt[strlen(fmt) - 1] == ':')
		fprintf(stderr, " %s", strerror(errno));
	fprintf(stderr, "\n");
	fputs("\n", stderr);
}

/* estrdup: duplicate a string, report if error */
Loading