Commit f104f321 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

Merge pull request #119 from guns/sort-mtime

New sort option: mtime
parents 71c7ff9f 4fae6007
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -532,10 +532,15 @@ in paused mode.
.It Cm -S , --sort Ar sort_type
.
The file list may be sorted according to image parameters.  Allowed sort
types are: name, filename, width, height, pixels, size, format.  For sort
modes other than name or filename, a preload run will be necessary,
types are: name, filename, mtime, width, height, pixels, size, format.  For sort
modes other than name, filename, or mtime, a preload run will be necessary,
causing a delay proportional to the number of images in the list.
.
.Pp
.
The mtime sort mode sorts images by most recently modified. To sort by oldest
first, reverse the filelist with --reverse.
.
.It Cm -| , --start-at Ar filename
.
Start the filelist at
+23 −1
Original line number Diff line number Diff line
@@ -354,6 +354,25 @@ int feh_cmp_name(void *file1, void *file2)
	return(strcmp(FEH_FILE(file1)->name, FEH_FILE(file2)->name));
}

/* Return -1 if file1 is _newer_ than file2 */
int feh_cmp_mtime(void *file1, void *file2)
{
	struct stat s1, s2;

	if (stat(FEH_FILE(file1)->filename, &s1)) {
		feh_print_stat_error(FEH_FILE(file1)->filename);
		return(-1);
	}

	if (stat(FEH_FILE(file2)->filename, &s2)) {
		feh_print_stat_error(FEH_FILE(file2)->filename);
		return(-1);
	}

	/* gib_list_sort is not stable, so explicitly return 0 as -1 */
	return(s1.st_mtime >= s2.st_mtime ? -1 : 1);
}

int feh_cmp_width(void *file1, void *file2)
{
	return((FEH_FILE(file1)->info->width - FEH_FILE(file2)->info->width));
@@ -381,7 +400,7 @@ int feh_cmp_format(void *file1, void *file2)

void feh_prepare_filelist(void)
{
	if (opt.list || opt.customlist || (opt.sort > SORT_FILENAME)
	if (opt.list || opt.customlist || (opt.sort > SORT_MTIME)
			|| opt.preload || opt.min_width || opt.min_height
			|| (opt.max_width != UINT_MAX) || (opt.max_height != UINT_MAX)) {
		/* For these sort options, we have to preload images */
@@ -407,6 +426,9 @@ void feh_prepare_filelist(void)
	case SORT_FILENAME:
		filelist = gib_list_sort(filelist, feh_cmp_filename);
		break;
	case SORT_MTIME:
		filelist = gib_list_sort(filelist, feh_cmp_mtime);
		break;
	case SORT_WIDTH:
		filelist = gib_list_sort(filelist, feh_cmp_width);
		break;
+2 −1
Original line number Diff line number Diff line
@@ -56,7 +56,7 @@ struct __feh_file_info {

enum filelist_recurse { FILELIST_FIRST, FILELIST_CONTINUE, FILELIST_LAST };

enum sort_type { SORT_NONE, SORT_NAME, SORT_FILENAME, SORT_WIDTH,
enum sort_type { SORT_NONE, SORT_NAME, SORT_FILENAME, SORT_MTIME, SORT_WIDTH,
	SORT_HEIGHT,
	SORT_PIXELS,
	SORT_SIZE, SORT_FORMAT
@@ -82,6 +82,7 @@ void feh_save_filelist();

int feh_cmp_name(void *file1, void *file2);
int feh_cmp_filename(void *file1, void *file2);
int feh_cmp_mtime(void *file1, void *file2);
int feh_cmp_width(void *file1, void *file2);
int feh_cmp_height(void *file1, void *file2);
int feh_cmp_pixels(void *file1, void *file2);
+2 −1
Original line number Diff line number Diff line
@@ -46,7 +46,8 @@ OPTIONS
 -U, --loadable            List all loadable files. No image display
 -u, --unloadable          List all unloadable files. No image display
 -S, --sort SORT_TYPE      Sort files by:
                           name, filename, width, height, pixels, size or format
                           name, filename, mtime, width, height, pixels, size,
                           or format
 -n, --reverse             Reverse sort order
 -A, --action ACTION       Specify action to perform when pressing <return>.
                           Executed by /bin/sh, may contain FORMAT SPECIFIERS
+2 −0
Original line number Diff line number Diff line
@@ -501,6 +501,8 @@ static void feh_parse_option_array(int argc, char **argv, int finalrun)
				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"))