summaryrefslogtreecommitdiff
path: root/src/filelist.c
diff options
context:
space:
mode:
authorDaniel Friesel <ghub@derf.homelinux.org>2013-01-30 22:28:47 -0800
committerDaniel Friesel <ghub@derf.homelinux.org>2013-01-30 22:28:47 -0800
commitf104f321475d0828a5d7600919d32635b0f77a68 (patch)
tree8f0ad713451491efed75d5d16cfb2771fb17c249 /src/filelist.c
parent71c7ff9ff8eca3008f4b08ef1c4a670b9eb7c7fa (diff)
parent4fae6007dd64d223cdae3f977003f38e3036bada (diff)
Merge pull request #119 from guns/sort-mtime
New sort option: mtime
Diffstat (limited to 'src/filelist.c')
-rw-r--r--src/filelist.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/filelist.c b/src/filelist.c
index 542dbdf..8f3bfe9 100644
--- a/src/filelist.c
+++ b/src/filelist.c
@@ -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;