Commit 3fa39154 authored by Yu-Jie Lin's avatar Yu-Jie Lin
Browse files

Add reload functionality for directories (derf#14)

parent 083a71e9
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "options.h"

gib_list *filelist = NULL;
gib_list *original_file_items = NULL; // original file items from argv
int filelist_len = 0;
gib_list *current_file = NULL;
extern int errno;
+1 −0
Original line number Diff line number Diff line
@@ -82,6 +82,7 @@ int feh_cmp_size(void *file1, void *file2);
int feh_cmp_format(void *file1, void *file2);

extern gib_list *filelist;
extern gib_list *original_file_items;
extern int filelist_len;
extern gib_list *current_file;

+2 −0
Original line number Diff line number Diff line
@@ -784,6 +784,8 @@ static void feh_parse_option_array(int argc, char **argv, int finalrun)
	/* 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);
+43 −0
Original line number Diff line number Diff line
@@ -89,8 +89,51 @@ void cb_slide_timer(void *data)

void cb_reload_timer(void *data)
{
	gib_list *l;
	char *current_filename;

	winwidget w = (winwidget) data;

	// save the current filename for refinding it in new list
	current_filename = estrdup(FEH_FILE(current_file->data)->filename);
	gib_list_free_and_data(filelist);
	filelist = NULL;
	filelist_len = 0;
	current_file = NULL;

	// rebuild filelist from original_file_items
	if (gib_list_length(original_file_items) > 0)
		for (l = gib_list_last(original_file_items); l; l = l->prev)
			add_file_to_filelist_recursively(l->data, FILELIST_FIRST);
	else if (!opt.filelistfile && !opt.bgmode)
		add_file_to_filelist_recursively(".", FILELIST_FIRST);
	
	if (!(filelist_len = gib_list_length(filelist))) {
		fprintf(stderr, "No files found to reload.\n");
		exit(1);
	}

	// find the previously current file
	for (l = filelist; l; l = l->next)
		if (strcmp(FEH_FILE(l->data)->filename, current_filename) == 0) {
			current_file = l;
			break;
		}

	free(current_filename);

	filelist = gib_list_first(gib_list_reverse(filelist));

	if (!current_file)
		current_file = filelist;
	w->file = current_file;

	// reset window name in case of current file order,
	// filename, or filelist_length has changed.
	current_filename = slideshow_create_name(FEH_FILE(current_file->data));
	winwidget_rename(w, current_filename);
	free(current_filename);

	feh_reload_image(w, 0, 0);
	feh_add_unique_timer(cb_reload_timer, w, opt.reload);
	return;