Selaa lähdekoodia

Add timestamp to filename

cinaeco 4 kuukautta sitten
vanhempi
commit
cee152f761
1 muutettua tiedostoa jossa 23 lisäystä ja 20 poistoa
  1. 23 20
      scan-dialog

+ 23 - 20
scan-dialog

@@ -24,12 +24,12 @@ function check_filename {
 }
 export -f check_filename # Make available to run_scan's command substitution
 
-# Run scanner. arguments: 1-folder 2-prefix 3-format 4-papersize 5-resolution 6-colormode
+# Run scanner. arguments: 1-folder 2-prefix 3-timestamp 4-format 5-papersize 6-resolution 7-colormode
 function run_scan {
 
   # Paper size.
   landscape=false
-  case $4 in
+  case $5 in
   A4)
     x=210
     y=297
@@ -44,7 +44,7 @@ function run_scan {
     y=210
     ;;
   A5R)
-    if [[ $5 == "150" ]] then
+    if [[ $6 == "150" ]] then
       # Force A4 instead, and cut later.
       # Sane epson backend throws an out of memory error at ~A5R 150DPI.
       x=210
@@ -55,27 +55,28 @@ function run_scan {
     ;;
   esac
 
-  filename=$(check_filename $1/$2.$3)
+  filename=$1/$2-$(date +"%Y-%m-%d-%H%M%S").$4
+  filename=$(check_filename $filename)
 
-  echo "$6 $5 $x $y $filename"
+  echo "$7 $6 $x $y $filename"
 
   tempname="./temp-$(date +%s).png"
-  scanimage --mode=$6 --resolution=$5 -x $x -y $y --format=png --output-file=$tempname | \
+  scanimage --mode=$7 --resolution=$6 -x $x -y $y --format=png --output-file=$tempname | \
   yad --progress --text="Scanning to PNG..." --width=300 --no-buttons --auto-close
   if [[ $landscape == true ]] then
     convert $tempname -rotate 90 $tempname
   fi
 
-  case $3 in
+  case $4 in
     png)
       cp $tempname $filename
       ;;
     jpg)
       convert -quality 85 $tempname $filename | \
-      yad --progress --text="Converting to $3..." --width=300 --no-buttons --auto-close
+      yad --progress --text="Converting to $4..." --width=300 --no-buttons --auto-close
       ;;
     pdf)
-      if [[ $6 != "Lineart" ]] then
+      if [[ $7 != "Lineart" ]] then
         tempname2="${tempname%.png}.jpg"
         convert -quality 85 $tempname $tempname2 | \
         yad --progress --text="Converting to jpg..." --width=300 --no-buttons --auto-close
@@ -83,11 +84,13 @@ function run_scan {
         tempname=$tempname2
       fi
       convert $tempname $filename | \
-      yad --progress --text="Converting to $3..." --width=300 --no-buttons --auto-close
+      yad --progress --text="Converting to $4..." --width=300 --no-buttons --auto-close
       ;;
   esac
 
-  yad --picture --title="Preview" --size=fit --width=750 --height=1000  --filename=$tempname
+  size_raw=$(stat -c%s $filename)
+  size_kb=$((size_raw/1024))
+  yad --picture --title="Filesize: $size_kb KB" --size=fit --width=750 --height=1000  --filename=$tempname
   rm $tempname
 }
 export -f run_scan # Make function available to yad button command.
@@ -97,20 +100,20 @@ yad --form --orient=hor --maximized --width=750 --height=250 --columns=3 \
   --title="Scanning Options" \
   --field="Scan Folder:SFL" /mnt/public/scans \
   --field="Filename Prefix:SFL" scan \
+  --field="Timestamp:CB" Yes\!No \
   --field="File format:CB" jpg\!png\!pdf \
   --field="Paper Size:CB" A4\!A4R\!A5\!A5R \
   --field="Resolution (DPI):CB" 75\!150\!^300\!600\!1200 \
-  --field="...:BTN" "" \
   --field="Scan Buttons:BTN" "" \
-  --field="Colour:FBTN" 'bash -c "run_scan %1 %2 %3 %4 %5 Color"' \
-  --field="Grayscale:FBTN" 'bash -c "run_scan %1 %2 %3 %4 %5 Gray"' \
-  --field="B&W:FBTN" 'bash -c "run_scan %1 %2 %3 %4 %5 Lineart"' \
+  --field="Colour:FBTN" 'bash -c "run_scan %1 %2 %3 %4 %5 %6 Color"' \
+  --field="Grayscale:FBTN" 'bash -c "run_scan %1 %2 %3 %4 %5 %6 Gray"' \
+  --field="B&W:FBTN" 'bash -c "run_scan %1 %2 %3 %4 %5 %6 Lineart"' \
   --field="...:BTN" "" \
   --field="...:BTN" "" \
   --field="Presets:BTN" "" \
-  --field="Art (Colour PNG):FBTN" 'bash -c "run_scan %1 art png %4 %5 Color"' \
-  --field="Art (Colour JPG):FBTN" 'bash -c "run_scan %1 art jpg %4 %5 Color"' \
-  --field="Doc (Colour PDF):FBTN" 'bash -c "run_scan %1 doc pdf %4 %5 Color"' \
-  --field="Doc (Gray PDF):FBTN" 'bash -c "run_scan %1 doc pdf %4 %5 Gray"' \
-  --field="Doc (B&W PDF):FBTN" 'bash -c "run_scan %1 doc pdf %4 %5 Lineart"' \
+  --field="Art (Colour PNG):FBTN" 'bash -c "run_scan %1 art %3 png %5 %6 Color"' \
+  --field="Art (Colour JPG):FBTN" 'bash -c "run_scan %1 art %3 jpg %5 %6 Color"' \
+  --field="Doc (Colour PDF):FBTN" 'bash -c "run_scan %1 doc %3 pdf %5 %6 Color"' \
+  --field="Doc (Gray PDF):FBTN" 'bash -c "run_scan %1 doc %3 pdf %5 %6 Gray"' \
+  --field="Doc (B&W PDF):FBTN" 'bash -c "run_scan %1 doc %3 pdf %5 %6 Lineart"' \
   --no-buttons --buttons-layout=center