Beispiel #1
0
gib_list *feh_file_info_preload(gib_list * list)
{
	gib_list *l;
	feh_file *file = NULL;
	gib_list *remove_list = NULL;

	if (opt.verbose)
		fprintf(stdout, PACKAGE " - preloading...\n");

	for (l = list; l; l = l->next) {
		file = FEH_FILE(l->data);
		D(5, ("file %p, file->next %p, file->name %s\n", l, l->next, file->name));
		if (feh_file_info_load(file, NULL)) {
			D(3, ("Failed to load file %p\n", file));
			remove_list = gib_list_add_front(remove_list, l);
			if (opt.verbose)
				feh_display_status('x');
		} else if (opt.verbose)
			feh_display_status('.');
	}
	if (opt.verbose)
		fprintf(stdout, "\n");

	if (remove_list) {
		for (l = remove_list; l; l = l->next)
			filelist = list = gib_list_remove(list, (gib_list *) l->data);

		gib_list_free(remove_list);
	}

	return(list);
}
Beispiel #2
0
gib_list *feh_read_filelist(char *filename)
{
	FILE *fp;
	gib_list *list = NULL;
	char s[1024], s1[1024];
	Imlib_Image im1;

	if (!filename)
		return(NULL);

	/* try and load the given filelist as an image, cowardly refuse to
	 * overwrite an image with a filelist. (requested by user who did feh -df *
	 * when he meant feh -dF *, as it overwrote the first image with the
	 * filelist).
	 */
	if (feh_load_image_char(&im1, filename)) {
		weprintf(
				"The file you specified as a filelist to read - %s - appears to be an image. Ignoring it (this is a common mistake).\n",
				filename);
		opt.filelistfile = NULL;
		return(NULL);
	}

	errno = 0;
	if ((fp = fopen(filename, "r")) == NULL) {
		/* return quietly, as it's okay to specify a filelist file that doesn't
		   exist. In that case we create it on exit. */
		return(NULL);
	}

	for (; fgets(s, sizeof(s), fp);) {
		D(5, ("Got line '%s'\n", s));
		s1[0] = '\0';
		sscanf(s, "%[^\n]", (char *) &s1);
		if (!(*s1) || (*s1 == '\n'))
			continue;
		D(5, ("Got filename %s from filelist file\n", s1));
		/* Add it to the new list */
		list = gib_list_add_front(list, feh_file_new(s1));
	}
	fclose(fp);

	return(list);
}
Beispiel #3
0
/* TODO s/bit/lot */
void init_thumbnail_mode(void)
{
	/* moved to thumbnail_data:
	   Imlib_Image im_main;
	   Imlib_Image bg_im = NULL;
	   Imlib_Font fn = NULL;
	   Imlib_Font title_fn = NULL;

	   int w = 800, h = 600;
	   int bg_w = 0, bg_h = 0;

	   int text_area_w, text_area_h;
	   int max_column_w = 0;
	 */

	Imlib_Image im_temp;
	int ww = 0, hh = 0, www, hhh, xxx, yyy;
	int x = 0, y = 0;
	winwidget winwid = NULL;
	Imlib_Image im_thumb = NULL;
	unsigned char trans_bg = 0;
	int title_area_h = 0;
	int tw = 0, th = 0;
	int fw_name, fw_size, fw_dim, fh;
	int thumbnailcount = 0;
	feh_file *file = NULL;
	gib_list *l, *last = NULL;
	int lines;
	int index_image_width, index_image_height;
	int x_offset_name = 0, x_offset_dim = 0, x_offset_size = 0;
	char *s;
	unsigned int thumb_counter = 0;

	/* initialize thumbnail mode data */
	td.im_main = NULL;
	td.im_bg = NULL;
	td.font_main = NULL;
	td.font_title = NULL;

	td.w = 640;
	td.h = 480;
	td.bg_w = 0;
	td.bg_h = 0;
	td.thumb_tot_h = 0;
	td.text_area_w = 0;
	td.text_area_h = 0;

	td.vertical = 0;
	td.max_column_w = 0;

	mode = "thumbnail";

	if (opt.font)
		td.font_main = gib_imlib_load_font(opt.font);

	if (!td.font_main)
		td.font_main = gib_imlib_load_font(DEFAULT_FONT);

	if (opt.title_font) {
		int fh, fw;

		td.font_title = gib_imlib_load_font(opt.title_font);
		gib_imlib_get_text_size(td.font_title, "W", NULL, &fw, &fh,
				IMLIB_TEXT_TO_RIGHT);
		title_area_h = fh + 4;
	} else
		td.font_title = imlib_load_font(DEFAULT_FONT_TITLE);

	if ((!td.font_main) || (!td.font_title))
		eprintf("Error loading fonts");

	/* Work out how tall the font is */
	gib_imlib_get_text_size(td.font_main, "W", NULL, &tw, &th,
			IMLIB_TEXT_TO_RIGHT);
	/* For now, allow room for the right number of lines with small gaps */
	td.text_area_h = ((th + 2) * (opt.index_show_name + opt.index_show_size +
				opt.index_show_dim)) + 5;

	/* This includes the text area for index data */
	td.thumb_tot_h = opt.thumb_h + td.text_area_h;

	/* Use bg image dimensions for default size */
	if (opt.bg && opt.bg_file) {
		if (!strcmp(opt.bg_file, "trans"))
			trans_bg = 1;
		else {

			D(3, ("Time to apply a background to blend onto\n"));
			if (feh_load_image_char(&td.im_bg, opt.bg_file) != 0) {
				td.bg_w = gib_imlib_image_get_width(td.im_bg);
				td.bg_h = gib_imlib_image_get_height(td.im_bg);
			}
		}
	}

	/* figure out geometry for the main window and entries */
	feh_thumbnail_calculate_geometry();

	index_image_width = td.w;
	index_image_height = td.h + title_area_h;
	td.im_main = imlib_create_image(index_image_width, index_image_height);
	gib_imlib_image_set_has_alpha(td.im_main, 1);

	if (!td.im_main)
		eprintf("Imlib error creating index image, are you low on RAM?");

	if (td.im_bg)
		gib_imlib_blend_image_onto_image(td.im_main, td.im_bg,
						 gib_imlib_image_has_alpha
						 (td.im_bg), 0, 0, td.bg_w, td.bg_h, 0, 0,
						 td.w, td.h, 1, 0, 0);
	else if (trans_bg) {
		gib_imlib_image_fill_rectangle(td.im_main, 0, 0, td.w,
				td.h + title_area_h, 0, 0, 0, 0);
		gib_imlib_image_set_has_alpha(td.im_main, 1);
	} else {
		/* Colour the background */
		gib_imlib_image_fill_rectangle(td.im_main, 0, 0, td.w,
				td.h + title_area_h, 0, 0, 0, 255);
	}

	/* Create title now */

	if (!opt.title)
		s = estrdup(PACKAGE " [thumbnail mode]");
	else
		s = estrdup(feh_printf(opt.title, NULL));

	if (opt.display) {
		winwid = winwidget_create_from_image(td.im_main, s, WIN_TYPE_THUMBNAIL);
		winwidget_show(winwid);
	}

	/* make sure we have an ~/.thumbnails/normal directory for storing
	   permanent thumbnails */
	td.cache_thumbnails = opt.cache_thumbnails;

	if (td.cache_thumbnails) {
		if (opt.thumb_w > opt.thumb_h)
			td.cache_dim = opt.thumb_w;
		else
			td.cache_dim = opt.thumb_h;

		if (td.cache_dim > 256) {
			/* No caching as specified by standard. Sort of. */
			td.cache_thumbnails = 0;
		} else if (td.cache_dim > 128) {
			td.cache_dim = 256;
			td.cache_dir = estrdup("large");
		} else {
			td.cache_dim = 128;
			td.cache_dir = estrdup("normal");
		}
		feh_thumbnail_setup_thumbnail_dir();
	}

	for (l = filelist; l; l = l->next) {
		file = FEH_FILE(l->data);
		if (last) {
			filelist = feh_file_remove_from_list(filelist, last);
			last = NULL;
		}
		D(4, ("About to load image %s\n", file->filename));
		/*      if (feh_load_image(&im_temp, file) != 0) */
		if (feh_thumbnail_get_thumbnail(&im_temp, file) != 0) {
			if (opt.verbose)
				feh_display_status('.');
			D(4, ("Successfully loaded %s\n", file->filename));
			www = opt.thumb_w;
			hhh = opt.thumb_h;
			ww = gib_imlib_image_get_width(im_temp);
			hh = gib_imlib_image_get_height(im_temp);
			thumbnailcount++;
			if (gib_imlib_image_has_alpha(im_temp))
				imlib_context_set_blend(1);
			else
				imlib_context_set_blend(0);

			if (opt.aspect) {
				double ratio = 0.0;

				/* Keep the aspect ratio for the thumbnail */
				ratio = ((double) ww / hh) / ((double) www / hhh);

				if (ratio > 1.0)
					hhh = opt.thumb_h / ratio;
				else if (ratio != 1.0)
					www = opt.thumb_w * ratio;
			}

			if ((!opt.stretch) && ((www > ww) || (hhh > hh))) {
				/* Don't make the image larger unless stretch is specified */
				www = ww;
				hhh = hh;
			}

			im_thumb = gib_imlib_create_cropped_scaled_image(im_temp, 0, 0,
					ww, hh, www, hhh, 1);
			gib_imlib_free_image_and_decache(im_temp);

			if (opt.alpha) {
				DATA8 atab[256];

				D(3, ("Applying alpha options\n"));
				gib_imlib_image_set_has_alpha(im_thumb, 1);
				memset(atab, opt.alpha_level, sizeof(atab));
				gib_imlib_apply_color_modifier_to_rectangle
				    (im_thumb, 0, 0, www, hhh, NULL, NULL, NULL, atab);
			}

			td.text_area_w = opt.thumb_w;
			/* Now draw on the info text */
			if (opt.index_show_name) {
				gib_imlib_get_text_size(td.font_main, file->name, NULL,
						&fw_name, &fh, IMLIB_TEXT_TO_RIGHT);
				if (fw_name > td.text_area_w)
					td.text_area_w = fw_name;
			}
			if (opt.index_show_dim) {
				gib_imlib_get_text_size(td.font_main,
							create_index_dimension_string(ww, hh),
							NULL, &fw_dim, &fh, IMLIB_TEXT_TO_RIGHT);
				if (fw_dim > td.text_area_w)
					td.text_area_w = fw_dim;
			}
			if (opt.index_show_size) {
				gib_imlib_get_text_size(td.font_main,
							create_index_size_string(file->filename),
							NULL, &fw_size, &fh, IMLIB_TEXT_TO_RIGHT);
				if (fw_size > td.text_area_w)
					td.text_area_w = fw_size;
			}
			if (td.text_area_w > opt.thumb_w)
				td.text_area_w += 5;

			/* offsets for centering text */
			x_offset_name = (td.text_area_w - fw_name) / 2;
			x_offset_dim = (td.text_area_w - fw_dim) / 2;
			x_offset_size = (td.text_area_w - fw_size) / 2;

			if (td.vertical) {
				if (td.text_area_w > td.max_column_w)
					td.max_column_w = td.text_area_w;
				if (y > td.h - td.thumb_tot_h) {
					y = 0;
					x += td.max_column_w;
					td.max_column_w = 0;
				}
				if (x > td.w - td.text_area_w)
					break;
			} else {
				if (x > td.w - td.text_area_w) {
					x = 0;
					y += td.thumb_tot_h;
				}
				if (y > td.h - td.thumb_tot_h)
					break;
			}

			/* center image relative to the text below it (if any) */
			xxx = x + ((td.text_area_w - www) / 2);
			yyy = y;

			if (opt.aspect)
				yyy += (opt.thumb_h - hhh) / 2;

			/* Draw now */
			gib_imlib_blend_image_onto_image(td.im_main,
							 im_thumb,
							 gib_imlib_image_has_alpha
							 (im_thumb), 0, 0,
							 www, hhh, xxx,
							 yyy, www, hhh, 1,
							 gib_imlib_image_has_alpha(im_thumb), 0);

			thumbnails = gib_list_add_front(thumbnails,
					feh_thumbnail_new(file, xxx, yyy, www, hhh));

			gib_imlib_free_image_and_decache(im_thumb);

			lines = 0;
			if (opt.index_show_name)
				gib_imlib_text_draw(td.im_main,
						td.font_main, NULL,
						x + x_offset_name,
						y + opt.thumb_h + (lines++ * (th + 2)) + 2,
						file->name, IMLIB_TEXT_TO_RIGHT,
						255, 255, 255, 255);
			if (opt.index_show_dim)
				gib_imlib_text_draw(td.im_main,
						td.font_main, NULL,
						x + x_offset_dim,
						y + opt.thumb_h + (lines++ * (th + 2)) + 2,
						create_index_dimension_string(ww, hh),
						IMLIB_TEXT_TO_RIGHT, 255, 255, 255, 255);
			if (opt.index_show_size)
				gib_imlib_text_draw(td.im_main,
						td.font_main, NULL,
						x + x_offset_size,
						y + opt.thumb_h + (lines++ * (th + 2)) + 2,
						create_index_size_string(file->filename),
						IMLIB_TEXT_TO_RIGHT, 255, 255, 255, 255);

			if (td.vertical)
				y += td.thumb_tot_h;
			else
				x += td.text_area_w;
		} else {
			if (opt.verbose)
				feh_display_status('x');
			last = l;
		}
		if (opt.display) {
			/* thumb_counter is unsigned, so no need to catch overflows */
			if (++thumb_counter == opt.thumb_redraw) {
				winwidget_render_image(winwid, 0, 0);
				thumb_counter = 0;
			}
			if (!feh_main_iteration(0))
				exit(0);
		}
	}

	if (thumb_counter != 0)
		winwidget_render_image(winwid, 0, 0);

	if (opt.verbose)
		fprintf(stdout, "\n");

	if (opt.title_font) {
		int fw, fh, fx, fy;
		char *s;

		s = create_index_title_string(thumbnailcount, td.w, td.h);
		gib_imlib_get_text_size(td.font_title, s, NULL, &fw, &fh,
				IMLIB_TEXT_TO_RIGHT);
		fx = (index_image_width - fw) >> 1;
		fy = index_image_height - fh - 2;
		gib_imlib_text_draw(td.im_main, td.font_title, NULL, fx,
				fy, s, IMLIB_TEXT_TO_RIGHT, 255, 255, 255, 255);
	}
Beispiel #4
0
void feh_draw_caption(winwidget w)
{
	static Imlib_Font fn = NULL;
	int tw = 0, th = 0, ww, hh;
	int x, y;
	Imlib_Image im = NULL;
	char *p;
	gib_list *lines, *l;
	static gib_style *caption_style = NULL;
	feh_file *file;

	if (!w->file) {
		return;
	}
	file = FEH_FILE(w->file->data);
	if (!file->filename) {
		return;
	}

	if (!file->caption) {
		char *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);
	}

	if (file->caption == NULL) {
		/* caption file is not there, we want to cache that, otherwise we'll stat
		 * the damn file every time we render the image. Reloading an image will
		 * always cause the caption to be reread though so we're safe to do so.
		 * (Before this bit was added, when zooming a captionless image with
		 * captions enabled, the captions file would be stat()d like 30 times a
		 * second) - don't forget this function is called from
		 * winwidget_render_image().
		 */
		file->caption = estrdup("");
	}

	if (*(file->caption) == '\0' && !w->caption_entry)
		return;

	caption_style = gib_style_new("caption");
	caption_style->bits = gib_list_add_front(caption_style->bits,
		gib_style_bit_new(0, 0, 0, 0, 0, 0));
	caption_style->bits = gib_list_add_front(caption_style->bits,
		gib_style_bit_new(1, 1, 0, 0, 0, 255));

	fn = feh_load_font(w);

	if (*(file->caption) == '\0') {
		p = estrdup("Caption entry mode - Hit ESC to cancel");
		lines = feh_wrap_string(p, w->w, fn, NULL);
		free(p);
	} else
		lines = feh_wrap_string(file->caption, w->w, fn, NULL);

	if (!lines)
		return;

	/* Work out how high/wide the caption is */
	l = lines;
	while (l) {
		p = (char *) l->data;
		gib_imlib_get_text_size(fn, p, caption_style, &ww, &hh, IMLIB_TEXT_TO_RIGHT);
		if (ww > tw)
			tw = ww;
		th += hh;
		if (l->next)
			th += 1;	/* line spacing */
		l = l->next;
	}

	/* we don't want the caption overlay larger than our window */
	if (th > w->h)
		th = w->h;
	if (tw > w->w)
		tw = w->w;

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

	feh_imlib_image_fill_text_bg(im, tw, th);

	l = lines;
	x = 0;
	y = 0;
	while (l) {
		p = (char *) l->data;
		gib_imlib_get_text_size(fn, p, caption_style, &ww, &hh, IMLIB_TEXT_TO_RIGHT);
		x = (tw - ww) / 2;
		if (w->caption_entry && (*(file->caption) == '\0'))
			gib_imlib_text_draw(im, fn, caption_style, x, y, p,
				IMLIB_TEXT_TO_RIGHT, 255, 255, 127, 255);
		else if (w->caption_entry)
			gib_imlib_text_draw(im, fn, caption_style, x, y, p,
				IMLIB_TEXT_TO_RIGHT, 255, 255, 0, 255);
		else
			gib_imlib_text_draw(im, fn, caption_style, x, y, p,
				IMLIB_TEXT_TO_RIGHT, 255, 255, 255, 255);

		y += hh + 1;	/* line spacing */
		l = l->next;
	}

	gib_imlib_render_image_on_drawable(w->bg_pmap, im, (w->w - tw) / 2, w->h - th, 1, 1, 0);
	gib_imlib_free_image_and_decache(im);
	gib_list_free_and_data(lines);
	return;
}
Beispiel #5
0
void feh_menu_cb(feh_menu * m, feh_menu_item * i, int action, void *data)
{
	char *path;
	Imlib_Image im;
	winwidget winwid;

	switch (action) {
		case CB_BG_TILED:
			path = feh_absolute_path(FEH_FILE(m->fehwin->file->data)->filename);
			feh_wm_set_bg(path, m->fehwin->im, 0, 0, 0, (int) data, 1);
			free(path);
			break;
		case CB_BG_SCALED:
			path = feh_absolute_path(FEH_FILE(m->fehwin->file->data)->filename);
			feh_wm_set_bg(path, m->fehwin->im, 0, 1, 0, (int) data, 1);
			free(path);
			break;
		case CB_BG_CENTERED:
			path = feh_absolute_path(FEH_FILE(m->fehwin->file->data)->filename);
			feh_wm_set_bg(path, m->fehwin->im, 1, 0, 0, (int) data, 1);
			free(path);
			break;
		case CB_BG_FILLED:
			path = feh_absolute_path(FEH_FILE(m->fehwin->file->data)->filename);
			feh_wm_set_bg(path, m->fehwin->im, 0, 0, 1, (int) data, 1);
			free(path);
			break;
		case CB_BG_TILED_NOFILE:
			feh_wm_set_bg(NULL, m->fehwin->im, 0, 0, 0, (int) data, 1);
			break;
		case CB_BG_SCALED_NOFILE:
			feh_wm_set_bg(NULL, m->fehwin->im, 0, 1, 0, (int) data, 1);
			break;
		case CB_BG_CENTERED_NOFILE:
			feh_wm_set_bg(NULL, m->fehwin->im, 1, 0, 0, (int) data, 1);
			break;
		case CB_BG_FILLED_NOFILE:
			feh_wm_set_bg(NULL, m->fehwin->im, 0, 0, 1, (int) data, 1);
			break;
		case CB_ABOUT:
			if (feh_load_image_char(&im, PREFIX "/share/feh/images/about.png")
					!= 0) {
				winwid = winwidget_create_from_image(im, "About " PACKAGE,
						WIN_TYPE_ABOUT);
				winwid->file = gib_list_add_front(NULL,
						feh_file_new(PREFIX "/share/feh/images/about.png"));
				winwidget_show(winwid);
			}
			break;
		case CB_CLOSE:
			winwidget_destroy(m->fehwin);
			break;
		case CB_EXIT:
			winwidget_destroy_all();
			break;
		case CB_RESET:
			if (m->fehwin->has_rotated) {
				m->fehwin->im_w = gib_imlib_image_get_width(m->fehwin->im);
				m->fehwin->im_h = gib_imlib_image_get_height(m->fehwin->im);
				winwidget_resize(m->fehwin, m->fehwin->im_w, m->fehwin->im_h);
			}
			winwidget_reset_image(m->fehwin);
			winwidget_render_image(m->fehwin, 1, 1);
			break;
		case CB_RELOAD:
			feh_reload_image(m->fehwin, 0, 0);
			break;
		case CB_REMOVE:
			feh_filelist_image_remove(m->fehwin, 0);
			break;
		case CB_DELETE:
			feh_filelist_image_remove(m->fehwin, 1);
			break;
		case CB_REMOVE_THUMB:
			feh_thumbnail_mark_removed(FEH_FILE(m->fehwin->file->data), 0);
			feh_filelist_image_remove(m->fehwin, 0);
			break;
		case CB_DELETE_THUMB:
			feh_thumbnail_mark_removed(FEH_FILE(m->fehwin->file->data), 1);
			feh_filelist_image_remove(m->fehwin, 1);
			break;
		case CB_SORT_FILENAME:
			filelist = gib_list_sort(filelist, feh_cmp_filename);
			if (opt.jump_on_resort) {
				slideshow_change_image(m->fehwin, SLIDE_FIRST);
			}
			break;
		case CB_SORT_IMAGENAME:
			filelist = gib_list_sort(filelist, feh_cmp_name);
			if (opt.jump_on_resort) {
				slideshow_change_image(m->fehwin, SLIDE_FIRST);
			}
			break;
		case CB_SORT_FILESIZE:
			filelist = gib_list_sort(filelist, feh_cmp_size);
			if (opt.jump_on_resort) {
				slideshow_change_image(m->fehwin, SLIDE_FIRST);
			}
			break;
		case CB_SORT_RANDOMIZE:
			filelist = gib_list_randomize(filelist);
			if (opt.jump_on_resort) {
				slideshow_change_image(m->fehwin, SLIDE_FIRST);
			}
			break;
		case CB_FIT:
			winwidget_size_to_image(m->fehwin);
			break;
		case CB_EDIT_ROTATE:
			feh_edit_inplace_orient(m->fehwin, (int) data);
			break;
		case CB_SAVE_IMAGE:
			slideshow_save_image(m->fehwin);
			break;
		case CB_SAVE_FILELIST:
			feh_save_filelist();
			break;
		case CB_OPT_DRAW_FILENAME:
			MENU_ITEM_TOGGLE(i);
			if (MENU_ITEM_IS_ON(i))
				opt.draw_filename = TRUE;
			else
				opt.draw_filename = FALSE;
			winwidget_rerender_all(0, 1);
			break;
		case CB_OPT_DRAW_ACTIONS:
			MENU_ITEM_TOGGLE(i);
			if (MENU_ITEM_IS_ON(i))
				opt.draw_actions = TRUE;
			else
				opt.draw_actions = FALSE;
			winwidget_rerender_all(0, 1);
			break;
		case CB_OPT_KEEP_HTTP:
			MENU_ITEM_TOGGLE(i);
			if (MENU_ITEM_IS_ON(i))
				opt.keep_http = TRUE;
			else
				opt.keep_http = FALSE;
			break;
		case CB_OPT_FREEZE_WINDOW:
			MENU_ITEM_TOGGLE(i);
			if (MENU_ITEM_IS_ON(i)) {
				opt.geom_flags = (WidthValue | HeightValue);
				opt.geom_w = m->fehwin->w;
				opt.geom_h = m->fehwin->h;
			} else {
				opt.geom_flags = 0;
			}
			break;
		case CB_OPT_FULLSCREEN:
			feh_menu_cb_opt_fullscreen(m, i);
			break;
		case CB_OPT_AUTO_ZOOM:
			MENU_ITEM_TOGGLE(i);
			if (MENU_ITEM_IS_ON(i))
				opt.zoom_mode = ZOOM_MODE_FILL;
			else
				opt.zoom_mode = 0;
			winwidget_rerender_all(1, 1);
			break;
	}
	return;
}
Beispiel #6
0
void add_file_to_rm_filelist(char *file)
{
	rm_filelist = gib_list_add_front(rm_filelist, feh_file_new(file));
	return;
}
Beispiel #7
0
/* Recursive */
void add_file_to_filelist_recursively(char *origpath, unsigned char level)
{
	struct stat st;
	char *path;

	if (!origpath)
		return;

	path = estrdup(origpath);
	D(4, ("file is %s\n", path));

	if (level == FILELIST_FIRST) {
		/* First time through, sort out pathname */
		int len = 0;

		len = strlen(path);
		if (path[len - 1] == '/')
			path[len - 1] = '\0';

		if ((!strncmp(path, "http://", 7))
				|| (!strncmp(path, "https://", 8))
				|| (!strncmp(path, "ftp://", 6))) {
			/* Its a url */
			D(3, ("Adding url %s to filelist\n", path));
			filelist = gib_list_add_front(filelist, feh_file_new(path));
			/* We'll download it later... */
			free(path);
			return;
		} else if (opt.filelistfile) {
			char *newpath = feh_absolute_path(path);

			free(path);
			path = newpath;
		}
	}

	errno = 0;
	if (stat(path, &st)) {
		/* Display useful error message */
		switch (errno) {
		case ENOENT:
		case ENOTDIR:
			if (!opt.quiet)
				weprintf("%s does not exist - skipping", path);
			break;
		case ELOOP:
			if (!opt.quiet)
				weprintf("%s - too many levels of symbolic links - skipping", path);
			break;
		case EACCES:
			if (!opt.quiet)
				weprintf("you don't have permission to open %s - skipping", path);
			break;
		default:
			if (!opt.quiet)
				weprintf("couldn't open %s", path);
			break;
		}
		free(path);
		return;
	}

	if ((S_ISDIR(st.st_mode)) && (level != FILELIST_LAST)) {
		struct dirent *de;
		DIR *dir;

		D(4, ("It is a directory\n"));

		if ((dir = opendir(path)) == NULL) {
			if (!opt.quiet)
				weprintf("couldn't open directory %s:", path);
			free(path);
			return;
		}
		de = readdir(dir);
		while (de != NULL) {
			if (strcmp(de->d_name, ".")
					&& strcmp(de->d_name, "..")) {
				char *newfile;

				newfile = estrjoin("", path, "/", de->d_name, NULL);

				/* This ensures we go down one level even if not fully recursive
				   - this way "feh some_dir" expands to some_dir's contents */
				if (opt.recursive)
					add_file_to_filelist_recursively(newfile, FILELIST_CONTINUE);
				else
					add_file_to_filelist_recursively(newfile, FILELIST_LAST);

				free(newfile);
			}
			de = readdir(dir);
		}
		closedir(dir);
	} else if (S_ISREG(st.st_mode)) {
		D(5, ("Adding regular file %s to filelist\n", path));
		filelist = gib_list_add_front(filelist, feh_file_new(path));
	}
	free(path);
	return;
}
Beispiel #8
0
static void feh_parse_option_array(int argc, char **argv, int finalrun)
{
	int discard;
	static char stropts[] =
		"a:A:b:B:cC:dD:e:E:f:Fg:GhH:iIj:J:kK:lL:mM:nNo:O:pPqrR:sS:tT:uUvVwW:xXy:YzZ"
		".@:^:~:):|:+:<:>:";

	/* (*name, has_arg, *flag, val) See: struct option in getopts.h */
	static struct option lopts[] = {
		{"menu-bg"       , 1, 0, ')'},
		{"debug"         , 0, 0, '+'},
		{"scale-down"    , 0, 0, '.'},
		{"max-dimension" , 1, 0, '<'},
		{"min-dimension" , 1, 0, '>'},
		{"title-font"    , 1, 0, '@'},
		{"action"        , 1, 0, 'A'},
		{"image-bg"      , 1, 0, 'B'},
		{"fontpath"      , 1, 0, 'C'},
		{"slideshow-delay",1, 0, 'D'},
		{"thumb-height"  , 1, 0, 'E'},
		{"full-screen"   , 0, 0, 'F'}, /* deprecated */
		{"fullscreen"    , 0, 0, 'F'},
		{"draw-actions"  , 0, 0, 'G'},
		{"limit-height"  , 1, 0, 'H'},
		{"fullindex"     , 0, 0, 'I'},
		{"thumb-redraw"  , 1, 0, 'J'},
		{"caption-path"  , 1, 0, 'K'},
		{"customlist"    , 1, 0, 'L'},
		{"menu-font"     , 1, 0, 'M'},
		{"no-menus"      , 0, 0, 'N'},
		{"output-only"   , 1, 0, 'O'},
		{"cache-thumbnails", 0, 0, 'P'},
		{"reload"        , 1, 0, 'R'},
		{"sort"          , 1, 0, 'S'},
		{"theme"         , 1, 0, 'T'},
		{"loadable"      , 0, 0, 'U'},
		{"verbose"       , 0, 0, 'V'},
		{"limit-width"   , 1, 0, 'W'},
		{"ignore-aspect" , 0, 0, 'X'},
		{"hide-pointer"  , 0, 0, 'Y'},
		{"auto-zoom"     , 0, 0, 'Z'},
		{"title"         , 1, 0, '^'},
		{"alpha"         , 1, 0, 'a'},
		{"bg"            , 1, 0, 'b'},
		{"collage"       , 0, 0, 'c'},
		{"draw-filename" , 0, 0, 'd'},
		{"font"          , 1, 0, 'e'},
		{"filelist"      , 1, 0, 'f'},
		{"geometry"      , 1, 0, 'g'},
		{"help"          , 0, 0, 'h'},
		{"index"         , 0, 0, 'i'},
		{"output-dir"    , 1, 0, 'j'},
		{"keep-http"     , 0, 0, 'k'},
		{"list"          , 0, 0, 'l'},
		{"montage"       , 0, 0, 'm'},
		{"reverse"       , 0, 0, 'n'},
		{"output"        , 1, 0, 'o'},
		{"preload"       , 0, 0, 'p'},
		{"quiet"         , 0, 0, 'q'},
		{"recursive"     , 0, 0, 'r'},
		{"stretch"       , 0, 0, 's'},
		{"thumbnails"    , 0, 0, 't'},
		{"unloadable"    , 0, 0, 'u'},
		{"version"       , 0, 0, 'v'},
		{"multiwindow"   , 0, 0, 'w'},
		{"borderless"    , 0, 0, 'x'},
		{"thumb-width"   , 1, 0, 'y'},
		{"randomize"     , 0, 0, 'z'},
		{"start-at"      , 1, 0, '|'},
		{"thumb-title"   , 1, 0, '~'},
		{"bg-tile"       , 0, 0, 200},
		{"bg-center"     , 0, 0, 201},
		{"bg-scale"      , 0, 0, 202},
		{"zoom"          , 1, 0, 205},
		{"no-screen-clip", 0, 0, 206},
		{"index-info"    , 1, 0, 207},
		{"magick-timeout", 1, 0, 208},
		{"action1"       , 1, 0, 209},
		{"action2"       , 1, 0, 210},
		{"action3"       , 1, 0, 211},
		{"action4"       , 1, 0, 212},
		{"action5"       , 1, 0, 213},
		{"action6"       , 1, 0, 214},
		{"action7"       , 1, 0, 215},
		{"action8"       , 1, 0, 216},
		{"action9"       , 1, 0, 217},
		{"bg-fill"       , 0, 0, 218},
		{"bg-max"        , 0, 0, 219},
		{"no-jump-on-resort", 0, 0, 220},
#ifdef HAVE_LIBEXIF
		{"draw-exif"     , 0, 0, 223},
#endif
		{"cycle-once"    , 0, 0, 224},
		{"no-xinerama"   , 0, 0, 225},
		{"draw-tinted"   , 0, 0, 229},
		{"info"          , 1, 0, 234},
		{"force-aliasing", 0, 0, 235},
		{"no-fehbg"      , 0, 0, 236},
		{"keep-zoom-vp"  , 0, 0, 237},
		{"scroll-step"   , 1, 0, 238},
		{"xinerama-index", 1, 0, 239},

		{0, 0, 0, 0}
	};
	int optch = 0, cmdx = 0;

	while ((optch = getopt_long(argc, argv, stropts, lopts, &cmdx)) != EOF) {
		D(("Got option, getopt calls it %d, or %c\n", optch, optch));
		switch (optch) {
		case 0:
			break;
		case ')':
			free(opt.menu_bg);
			opt.menu_bg = estrdup(optarg);
			weprintf("The --menu-bg option is deprecated and will be removed by 2012");
			break;
		case '+':
			opt.debug = 1;
			break;
		case '<':
			XParseGeometry(optarg, &discard, &discard, &opt.max_width, &opt.max_height);
			if (opt.max_width == 0)
				opt.max_width = UINT_MAX;
			if (opt.max_height == 0)
				opt.max_height = UINT_MAX;
			break;
		case '>':
			XParseGeometry(optarg, &discard, &discard, &opt.min_width, &opt.min_height);
			break;
		case '.':
			opt.scale_down = 1;
			break;
		case '@':
			opt.title_font = estrdup(optarg);
			break;
		case 'A':
			opt.actions[0] = estrdup(optarg);
			break;
		case 'B':
			if (!strcmp(optarg, "checks"))
				opt.image_bg = IMAGE_BG_CHECKS;
			else if (!strcmp(optarg, "white"))
				opt.image_bg = IMAGE_BG_WHITE;
			else if (!strcmp(optarg, "black"))
				opt.image_bg = IMAGE_BG_BLACK;
			else
				weprintf("Unknown argument to --image-bg: %s", optarg);
			break;
		case 'C':
			D(("adding fontpath %s\n", optarg));
			imlib_add_path_to_font_path(optarg);
			break;
		case 'D':
			opt.slideshow_delay = atof(optarg);
			if (opt.slideshow_delay < 0.0) {
				opt.slideshow_delay *= (-1);
				opt.paused = 1;
			}
			break;
		case 'E':
			opt.thumb_h = atoi(optarg);
			break;
		case 'F':
			opt.full_screen = 1;
			break;
		case 'G':
			opt.draw_actions = 1;
			break;
		case 'H':
			opt.limit_h = atoi(optarg);
			break;
		case 'I':
			opt.index = 1;
			opt.index_info = estrdup("%n\n%S\n%wx%h");
			break;
		case 'J':
			opt.thumb_redraw = atoi(optarg);
			break;
		case 'K':
			opt.caption_path = estrdup(optarg);
			break;
		case 'L':
			opt.customlist = estrdup(optarg);
			opt.display = 0;
			break;
		case 'M':
			free(opt.menu_font);
			opt.menu_font = estrdup(optarg);
			break;
		case 'N':
			opt.no_menus = 1;
			break;
		case 'O':
			opt.output = 1;
			opt.output_file = estrdup(optarg);
			opt.display = 0;
			break;
		case 'P':
			opt.cache_thumbnails = 1;
			break;
		case 'R':
			opt.reload = atof(optarg);
			break;
		case 'S':
			if (!strcasecmp(optarg, "name"))
				opt.sort = SORT_NAME;
			else if (!strcasecmp(optarg, "filename"))
				opt.sort = SORT_FILENAME;
			else if (!strcasecmp(optarg, "mtime"))
				opt.sort = SORT_MTIME;
			else if (!strcasecmp(optarg, "width"))
				opt.sort = SORT_WIDTH;
			else if (!strcasecmp(optarg, "height"))
				opt.sort = SORT_HEIGHT;
			else if (!strcasecmp(optarg, "pixels"))
				opt.sort = SORT_PIXELS;
			else if (!strcasecmp(optarg, "size"))
				opt.sort = SORT_SIZE;
			else if (!strcasecmp(optarg, "format"))
				opt.sort = SORT_FORMAT;
			else {
				weprintf("Unrecognised sort mode \"%s\". Defaulting to "
						"sort by filename", optarg);
				opt.sort = SORT_FILENAME;
			}
			if (opt.randomize) {
				weprintf("commandline contains --randomize and --sort. "
						"--randomize has been unset");
				opt.randomize = 0;
			}
			break;
		case 'T':
			theme = estrdup(optarg);
			break;
		case 'U':
			opt.loadables = 1;
			opt.display = 0;
			break;
		case 'V':
			opt.verbose = 1;
			break;
		case 'W':
			opt.limit_w = atoi(optarg);
			break;
		case 'X':
			opt.aspect = 0;
			break;
		case 'Y':
			opt.hide_pointer = 1;
			break;
		case 'Z':
			opt.zoom_mode = ZOOM_MODE_MAX;
			break;
		case '^':
			opt.title = estrdup(optarg);
			break;
		case 'a':
			opt.alpha = 1;
			opt.alpha_level = 255 - atoi(optarg);
			break;
		case 'b':
			opt.bg = 1;
			opt.bg_file = estrdup(optarg);
			break;
		case 'c':
			opt.collage = 1;
			break;
		case 'd':
			opt.draw_filename = 1;
			break;
		case 'e':
			opt.font = estrdup(optarg);
			break;
		case 'f':
			if (!strcmp(optarg, "-"))
				opt.filelistfile = estrdup("/dev/stdin");
			else
				opt.filelistfile = estrdup(optarg);
			break;
		case 'g':
			opt.geom_flags = XParseGeometry(optarg, &opt.geom_x,
					&opt.geom_y, &opt.geom_w, &opt.geom_h);
			break;
		case 'h':
			show_usage();
			break;
		case 'i':
			opt.index = 1;
			opt.index_info = estrdup("%n");
			break;
		case 'j':
			opt.output_dir = estrdup(optarg);
			break;
		case 'k':
			opt.keep_http = 1;
			break;
		case 'l':
			opt.list = 1;
			opt.display = 0;
			break;
		case 'm':
			opt.index = 1;
			break;
		case 'n':
			opt.reverse = 1;
			break;
		case 'o':
			opt.output = 1;
			opt.output_file = estrdup(optarg);
			break;
		case 'p':
			opt.preload = 1;
			break;
		case 'q':
			opt.quiet = 1;
			break;
		case 'r':
			opt.recursive = 1;
			break;
		case 's':
			opt.stretch = 1;
			break;
		case 't':
			opt.thumbs = 1;
			opt.index_info = estrdup("%n");
			break;
		case 'u':
			opt.unloadables = 1;
			opt.display = 0;
			break;
		case 'v':
			show_version();
			break;
		case 'w':
			opt.multiwindow = 1;
			break;
		case 'x':
			opt.borderless = 1;
			break;
		case 'y':
			opt.thumb_w = atoi(optarg);
			break;
		case 'z':
			opt.randomize = 1;
			if (opt.sort != SORT_NONE) {
				weprintf("commandline contains --sort and --randomize. "
						"--sort has been unset");
				opt.sort = SORT_NONE;
			}
			break;
		case '|':
			opt.start_list_at = estrdup(optarg);
			break;
		case '~':
			opt.thumb_title = estrdup(optarg);
			break;
		case 200:
			opt.bgmode = BG_MODE_TILE;
			break;
		case 201:
			opt.bgmode = BG_MODE_CENTER;
			break;
		case 202:
			opt.bgmode = BG_MODE_SCALE;
			break;
		case 205:
			if (!strcmp("fill", optarg))
				opt.zoom_mode = ZOOM_MODE_FILL;
			else if (!strcmp("max", optarg))
				opt.zoom_mode = ZOOM_MODE_MAX;
			else
				opt.default_zoom = atoi(optarg);
			break;
		case 206:
			opt.screen_clip = 0;
			break;
		case 207:
			opt.index_info = estrdup(optarg);
			break;
		case 208:
			opt.magick_timeout = atoi(optarg);
			break;
		case 209:
			opt.actions[1] = estrdup(optarg);
			break;
		case 210:
			opt.actions[2] = estrdup(optarg);
			break;
		case 211:
			opt.actions[3] = estrdup(optarg);
			break;
		case 212:
			opt.actions[4] = estrdup(optarg);
			break;
		case 213:
			opt.actions[5] = estrdup(optarg);
			break;
		case 214:
			opt.actions[6] = estrdup(optarg);
			break;
		case 215:
			opt.actions[7] = estrdup(optarg);
			break;
		case 216:
			opt.actions[8] = estrdup(optarg);
			break;
		case 217:
			opt.actions[9] = estrdup(optarg);
			break;
		case 218:
			opt.bgmode = BG_MODE_FILL;
			break;
		case 219:
			opt.bgmode = BG_MODE_MAX;
			break;
		case 220:
			opt.jump_on_resort = 0;
			break;
#ifdef HAVE_LIBEXIF
		case 223:
			opt.draw_exif = 1;
			break;
#endif
		case 224:
			opt.cycle_once = 1;
			break;
		case 225:
			opt.xinerama = 0;
			break;
		case 229:
			opt.text_bg = TEXT_BG_TINTED;
			break;
		case 234:
			opt.info_cmd = estrdup(optarg);
			if (opt.info_cmd[0] == ';')
				opt.info_cmd++;
			else
				opt.draw_info = 1;
			break;
		case 235:
			opt.force_aliasing = 1;
			break;
		case 236:
			opt.no_fehbg = 1;
			break;
		case 237:
			opt.keep_zoom_vp = 1;
			break;
		case 238:
			opt.scroll_step = atoi(optarg);
			break;
		case 239:
			opt.xinerama_index = atoi(optarg);
			break;
		default:
			break;
		}
	}

	/* Now the leftovers, which must be files */
	if (optind < argc) {
		while (optind < argc) {
			if (opt.reload)
				original_file_items = gib_list_add_front(original_file_items, estrdup(argv[optind]));
			/* If recursive is NOT set, but the only argument is a directory
			   name, we grab all the files in there, but not subdirs */
			add_file_to_filelist_recursively(argv[optind++], FILELIST_FIRST);
		}
	}
	else if (finalrun && !opt.filelistfile && !opt.bgmode)
		add_file_to_filelist_recursively(".", FILELIST_FIRST);

	/* So that we can safely be called again */
	optind = 0;
	return;
}