diff options
author | Daniel Friesel <ghub@derf.homelinux.org> | 2011-08-15 00:48:59 -0700 |
---|---|---|
committer | Daniel Friesel <ghub@derf.homelinux.org> | 2011-08-15 00:48:59 -0700 |
commit | 803a889d92cd884a074dca33fada560f8aefaf15 (patch) | |
tree | 549733793f3e8196c1170641ab60e1aad65db4a2 | |
parent | 083a71e948290894e70708b93c453e97619876b2 (diff) | |
parent | 3fa39154f089a6fadc1a14eb6b206e2d2875be71 (diff) |
Merge pull request #56 from livibetter/reload-dir
Add reload functionality for directories
-rw-r--r-- | src/filelist.c | 1 | ||||
-rw-r--r-- | src/filelist.h | 1 | ||||
-rw-r--r-- | src/options.c | 2 | ||||
-rw-r--r-- | src/slideshow.c | 43 |
4 files changed, 47 insertions, 0 deletions
diff --git a/src/filelist.c b/src/filelist.c index e55e80a..3279bce 100644 --- a/src/filelist.c +++ b/src/filelist.c @@ -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; diff --git a/src/filelist.h b/src/filelist.h index 617236f..9ec302c 100644 --- a/src/filelist.h +++ b/src/filelist.h @@ -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; diff --git a/src/options.c b/src/options.c index c29f057..70eb9d5 100644 --- a/src/options.c +++ b/src/options.c @@ -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); diff --git a/src/slideshow.c b/src/slideshow.c index f33ae9e..b30602b 100644 --- a/src/slideshow.c +++ b/src/slideshow.c @@ -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; |