Add --no_error_purge flag to not remove errored images from image list #1

Open
spacelama wants to merge 2 commits from spacelama/qiv:master into master
  1. 43
      image.c
  2. 2
      main.h
  3. 5
      options.c
  4. 3
      qiv.1
  5. 2
      qiv.h
  6. 5
      utils.c

43
image.c

@ -665,27 +665,42 @@ void update_image(qiv_image *q, int mode)
gdk_beep();
/* take this image out of the file list */
--images;
for(i=image_idx;i<images;++i) {
image_names[i] = image_names[i+1];
}
if (! keep_error_images) {
--images;
for(i=image_idx;i<images;++i) {
image_names[i] = image_names[i+1];
}
/* If deleting the last file out of x */
if(images == image_idx)
image_idx = 0;
/* If deleting the last file out of x */
if(images == image_idx)
image_idx = 0;
Review

This is no real change but just different whitespacing, right?

This is no real change but just different whitespacing, right?
Review

No, it's indented with the:

if (! keep_error_images) {
No, it's indented with the: if (! keep_error_images) {
/* If deleting the only file left */
if(!images) {
/* If deleting the only file left */
if(!images) {
Review

This is no real change but just different whitespacing, right?

This is no real change but just different whitespacing, right?
Review

Same as above. The diff appears quite awkward because of the its refused to treat the newline separated sections as one single change.

Same as above. The diff appears quite awkward because of the its refused to treat the newline separated sections as one single change.
#ifdef DEBUG
g_print("*** deleted last file in list. Exiting.\n");
g_print("*** deleted last file in list. Exiting.\n");
#endif
exit(0);
exit(0);
}
/* else load the next image */
qiv_load_image(q);
return;
} else if (command_run_on_image) {
command_run_on_image = 0;
image_idx++;
/* If was already viewing the last image, go back to the start
* (which might be the same image if there's only one, but we've
* already cleared command_run_on_image, so we break loop) */
if(images == image_idx)
image_idx = 0;
/* else load the next image */
qiv_load_image(q);
return;
}
/* else load the next image */
qiv_load_image(q);
return;
} else {
command_run_on_image = 0;
if (mode == REDRAW || mode == FULL_REDRAW)
setup_imlib_color_modifier(q->mod);

2
main.h

@ -72,6 +72,8 @@ int autorotate = 1; /* autorotate JPEGs according to EXIF tag */
int rotation = 0; /* rotation x degrees clockwise, 1=90degrees 2=180degrees 3=270degrees */
int vikeys = 0; /* option to give us some vi-like keys (for movement) */
int trashbin = 0; /* option to use users trash bin instead of local .qiv_trash when deleting image */
int keep_error_images = 0; /* Whether to keep images that fail to load, in the list */
int command_run_on_image = 0; /* Whether a command has just been run on an image, so we can skip this image if it has disappeared by the time we reload it */
#ifdef SUPPORT_LCMS
const char* source_profile = NULL;

5
options.c

@ -27,7 +27,7 @@ extern int optind, opterr, optopt;
#define LONGOPT_VIKEYS 256
#define LONGOPT_TRASHBIN 257
static char *short_options = "ab:c:Cd:efg:hilLmno:pq:rstuvw:xyzA:BDF:GIJKMNPRSTW:X:Y:Z:";
static char *short_options = "ab:c:Cd:Eefg:hilLmno:pq:rstuvw:xyzA:BDF:GIJKMNPRSTW:X:Y:Z:";
static struct option long_options[] =
{
{"do_grab", 0, NULL, 'a'},
@ -61,6 +61,7 @@ static struct option long_options[] =
{"browse", 0, NULL, 'B'},
{"cycle", 0, NULL, 'C'},
{"no_sort", 0, NULL, 'D'},
{"no_error_purge", 0, NULL, 'E'},
Review

The name of the option makes it sound as if loading errors were always ignored.
But I interpreted your code such that only errors after a command-run are ignored.

Uhm, what about taking away this condition and actually ignore all loading errors?

The name of the option makes it sound as if loading errors were always ignored. But I interpreted your code such that only errors after a command-run are ignored. Uhm, what about taking away this condition and actually ignore all loading errors?
Review

It does two things - it doesn't remove the errored image from the image list (so at all times, regardless of whether you just ran a command). But it still advances one image if the error is the result of a command returning (you can get back to that errored image by pressing backspace to go back one image). I debated with myself over the flag: --keep_error_images would also work.

Where I use this is when cataloging a massive run of photos from a holiday (I come away with 2000 photos sometimes). When working on a scene, I use qiv-command [0-9] to move an image quickly into a directory called "qiv-0" to "qiv-9". Just a single keypress to categorise an image, then immediately advance to the next image. But if I realise I made a mistake, I just backspace one spot, press [0-9] again, and it moves the image back to the original location, and loads correctly again. I also have other keybindings - "0" followed by "K" tells qiv-command to move the file to qiv-0 (a special directory), and "K" tells the qiv-command to run exiftran on the image to rotate it losslessly. If I didn't move it into qiv-0 first, then it just runs jpegtran to do a lossy conversion (and "O" restores an erroneously rotated image). I wouldn't be able to do these exceptions if the image was removed from the list the moment the file was removed from the image list when it appeared in qiv-0.

It does two things - it doesn't remove the errored image from the image list (so at all times, regardless of whether you just ran a command). But it still advances one image if the error is the result of a command returning (you can get back to that errored image by pressing backspace to go back one image). I debated with myself over the flag: --keep_error_images would also work. Where I use this is when cataloging a massive run of photos from a holiday (I come away with 2000 photos sometimes). When working on a scene, I use qiv-command [0-9] to move an image quickly into a directory called "qiv-0" to "qiv-9". Just a single keypress to categorise an image, then immediately advance to the next image. But if I realise I made a mistake, I just backspace one spot, press [0-9] again, and it moves the image back to the original location, and loads correctly again. I also have other keybindings - "0" followed by "K" tells qiv-command to move the file to qiv-0 (a special directory), and "K" tells the qiv-command to run exiftran on the image to rotate it losslessly. If I didn't move it into qiv-0 first, then it just runs jpegtran to do a lossy conversion (and "O" restores an erroneously rotated image). I wouldn't be able to do these exceptions if the image was removed from the list the moment the file was removed from the image list when it appeared in qiv-0.
{"file", 1, NULL, 'F'},
{"disable_grab", 0, NULL, 'G'},
{"statusbar", 0, NULL, 'I'},
@ -313,6 +314,8 @@ void options_read(int argc, char **argv, qiv_image *q)
break;
case 'D': need_sort = 0;
break;
case 'E': keep_error_images = 1;
break;
case 'F': if(rreadfile(optarg) < 0) {
g_print("Error: %s could not be opened: %s.\n",optarg, strerror(errno));
gdk_exit(1);

3
qiv.1

@ -92,6 +92,9 @@ Disable filtering of images by extension. Normally, qiv
will only load images with an image extension such as .jpg, .png, .gif ...
This option lets you load any file as an image.
.TP
.B \-E, \-\-no_error_purge
Ignore errors loading images - do not remove them from the list of files
.TP
.B \-i, \-\-no_statusbar
Disable statusbar.
.TP

2
qiv.h

@ -162,6 +162,8 @@ extern int autorotate;
extern int rotation;
extern int vikeys;
extern int trashbin;
extern int keep_error_images;
extern int command_run_on_image;
extern const char *helpstrs[], **helpkeys, *image_extensions[];

5
utils.c

@ -289,7 +289,9 @@ void run_command(qiv_image *q, char *n, char *filename, int *numlines, const cha
int i;
struct stat before, after;
stat(filename, &before);
if (stat(filename, &before) != -1) {
command_run_on_image = 1;
}
if (!buffer)
buffer = xmalloc(MAXOUTPUTBUFFER + 1);
@ -527,6 +529,7 @@ void show_help(char *name, int exit_status)
" --merged_case_sort, -M Sort filenames with AaBbCc... alpha order\n"
" --mtime_sort, -K Sort files by their modification time\n"
" --no_filter, -n Do not filter images by extension\n"
" --no_error_purge, -E Do not remove images with loading error\n"
" --no_statusbar, -i Disable statusbar\n"
" --statusbar, -I Enable statusbar\n"
" --no_sort, -D Do not apply any sorting to the list of files\n"

Loading…
Cancel
Save