summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorguns <self@sungpae.com>2016-05-28 00:29:28 -0500
committerguns <self@sungpae.com>2016-05-28 00:29:28 -0500
commit7db8895f8cfb3d58b8e9b4c7a5a64a4df9bb1af0 (patch)
tree4dca4d3ad40931efb1012aaf866929f1a5287c33 /src
parent5df711cbae423ed2b51b84d12a1e92f07de50de3 (diff)
New sort option: dirname
Sort filelist by dirname, then by name. This results in file entries sorting before subdirectory entries. Useful in conjunction with upcoming prev_dir and next_dir navigation actions.
Diffstat (limited to 'src')
-rw-r--r--src/filelist.c28
-rw-r--r--src/filelist.h14
-rw-r--r--src/menu.c8
-rw-r--r--src/options.c2
4 files changed, 50 insertions, 2 deletions
diff --git a/src/filelist.c b/src/filelist.c
index 7e9dcbe..8956238 100644
--- a/src/filelist.c
+++ b/src/filelist.c
@@ -383,6 +383,20 @@ int feh_file_info_load(feh_file * file, Imlib_Image im)
return(0);
}
+void feh_file_dirname(char *dst, feh_file * f, int maxlen)
+{
+ int n = strlen(f->filename) - strlen(f->name);
+
+ /* Give up on long dirnames */
+ if (n <= 0 || n >= maxlen) {
+ dst[0] = '\0';
+ return;
+ }
+
+ strncpy(dst, f->filename, n);
+ dst[n] = '\0';
+}
+
int feh_cmp_filename(void *file1, void *file2)
{
return(strcmp(FEH_FILE(file1)->filename, FEH_FILE(file2)->filename));
@@ -393,6 +407,17 @@ int feh_cmp_name(void *file1, void *file2)
return(strcmp(FEH_FILE(file1)->name, FEH_FILE(file2)->name));
}
+int feh_cmp_dirname(void *file1, void *file2)
+{
+ char dir1[FEH_MAX_DIRNAME_LEN], dir2[FEH_MAX_DIRNAME_LEN];
+ int cmp;
+ feh_file_dirname(dir1, FEH_FILE(file1), FEH_MAX_DIRNAME_LEN);
+ feh_file_dirname(dir2, FEH_FILE(file2), FEH_MAX_DIRNAME_LEN);
+ if ((cmp = strcmp(dir1, dir2)) != 0)
+ return(cmp);
+ return(feh_cmp_name(file1, file2));
+}
+
/* Return -1 if file1 is _newer_ than file2 */
int feh_cmp_mtime(void *file1, void *file2)
{
@@ -465,6 +490,9 @@ void feh_prepare_filelist(void)
case SORT_FILENAME:
filelist = gib_list_sort(filelist, feh_cmp_filename);
break;
+ case SORT_DIRNAME:
+ filelist = gib_list_sort(filelist, feh_cmp_dirname);
+ break;
case SORT_MTIME:
filelist = gib_list_sort(filelist, feh_cmp_mtime);
break;
diff --git a/src/filelist.h b/src/filelist.h
index 7bfd518..79d1e62 100644
--- a/src/filelist.h
+++ b/src/filelist.h
@@ -53,13 +53,21 @@ struct __feh_file_info {
};
#define FEH_FILE(l) ((feh_file *) l)
+#define FEH_MAX_DIRNAME_LEN 4096
enum filelist_recurse { FILELIST_FIRST, FILELIST_CONTINUE, FILELIST_LAST };
-enum sort_type { SORT_NONE, SORT_NAME, SORT_FILENAME, SORT_MTIME, SORT_WIDTH,
+enum sort_type {
+ SORT_NONE,
+ SORT_NAME,
+ SORT_FILENAME,
+ SORT_DIRNAME,
+ SORT_MTIME,
+ SORT_WIDTH,
SORT_HEIGHT,
SORT_PIXELS,
- SORT_SIZE, SORT_FORMAT
+ SORT_SIZE,
+ SORT_FORMAT
};
feh_file *feh_file_new(char *filename);
@@ -73,6 +81,7 @@ void add_file_to_rm_filelist(char *file);
void delete_rm_files(void);
gib_list *feh_file_info_preload(gib_list * list);
int feh_file_info_load(feh_file * file, Imlib_Image im);
+void feh_file_dirname(char *dst, feh_file * f, int maxlen);
void feh_prepare_filelist(void);
int feh_write_filelist(gib_list * list, char *filename);
gib_list *feh_read_filelist(char *filename);
@@ -81,6 +90,7 @@ gib_list *feh_file_remove_from_list(gib_list * list, gib_list * l);
void feh_save_filelist();
int feh_cmp_name(void *file1, void *file2);
+int feh_cmp_dirname(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);
diff --git a/src/menu.c b/src/menu.c
index f315093..ddb2db1 100644
--- a/src/menu.c
+++ b/src/menu.c
@@ -67,6 +67,7 @@ enum {
CB_BG_FILLED_NOFILE,
CB_SORT_FILENAME,
CB_SORT_IMAGENAME,
+ CB_SORT_DIRNAME,
CB_SORT_MTIME,
CB_SORT_FILESIZE,
CB_SORT_RANDOMIZE,
@@ -947,6 +948,7 @@ void feh_menu_init_common()
feh_menu_add_entry(m, "By File Name", NULL, CB_SORT_FILENAME, 0, NULL);
feh_menu_add_entry(m, "By Image Name", NULL, CB_SORT_IMAGENAME, 0, NULL);
+ feh_menu_add_entry(m, "By Directory Name", NULL, CB_SORT_DIRNAME, 0, NULL);
feh_menu_add_entry(m, "By Modification Date", NULL, CB_SORT_MTIME, 0, NULL);
if (opt.preload || (opt.sort > SORT_MTIME))
feh_menu_add_entry(m, "By File Size", NULL, CB_SORT_FILESIZE, 0, NULL);
@@ -1277,6 +1279,12 @@ void feh_menu_cb(feh_menu * m, feh_menu_item * i, int action, unsigned short dat
slideshow_change_image(m->fehwin, SLIDE_FIRST, 1);
}
break;
+ case CB_SORT_DIRNAME:
+ filelist = gib_list_sort(filelist, feh_cmp_dirname);
+ if (opt.jump_on_resort) {
+ slideshow_change_image(m->fehwin, SLIDE_FIRST, 1);
+ }
+ break;
case CB_SORT_MTIME:
filelist = gib_list_sort(filelist, feh_cmp_mtime);
if (opt.jump_on_resort) {
diff --git a/src/options.c b/src/options.c
index b43db91..9e2ff5a 100644
--- a/src/options.c
+++ b/src/options.c
@@ -514,6 +514,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, "dirname"))
+ opt.sort = SORT_DIRNAME;
else if (!strcasecmp(optarg, "mtime"))
opt.sort = SORT_MTIME;
else if (!strcasecmp(optarg, "width"))