Description: QR Code Scan from File
 QR Code Scan from File with CLI and GUI. 
 .
Forwarded: not-needed

--- wifi-qr-0.2.orig/wifi-qr
+++ wifi-qr-0.2/wifi-qr
@@ -30,8 +30,8 @@ VERSION=0.2
 
 #RAW DATA SAMPLE
 #"WIFI:S:$SSID;P:$PASSWORD;T:$KEY_TYPE;H:$true;"
-#qrencode -o - -t UTF8 
-#qrencode -l h -s 14 -o 
+#qrencode -o - -t UTF8
+#qrencode -l h -s 14 -o
 
 #GUI Mainmenu
 main_menu() {
@@ -43,6 +43,7 @@ main_menu() {
     --width=300 --height=320 \
     --column="Check" --column="Option" \
     TRUE "Scan and connect" \
+    FALSE "Scan Image and connect" \
     FALSE "Share current WiFi" \
     FALSE "Share saved WiFi" \
     FALSE "See license" \
@@ -54,9 +55,12 @@ main_menu() {
 
   elif [[ "$CHOICE" =~ "Share current WiFi" ]]; then
     call_current_wifi_gui
-  
+
   elif [[ "$CHOICE" =~ "Scan and connect" ]]; then
-    call_wifi_scan_gui
+    call_wifi_scan_gui "cam"
+
+  elif [[ "$CHOICE" =~ "Scan Image and connect" ]]; then
+    call_file_select_and_scan_gui
 
   elif [[ "$CHOICE" =~ "See license" ]]; then
     zenity --text-info --title="WiFi QR Copyright" --filename=/usr/share/doc/wifi-qr/copyright --width=528 --height=780
@@ -139,7 +143,7 @@ call_wifi_terminal() {
 terminal_qr() {
   call_wifi_pass
   qrencode -o - -t UTF8 "WIFI:S:$WIFIS;P:$KEEY;$PSSK$H;"
-  echo 
+  echo
 }
 
 current_wifi_ssid() {
@@ -179,26 +183,50 @@ call_wifi_pass() {
   echo -e "${RESET}"
 }
 
-call_wifi_scan() {
-  wifiqrdata=''
-  # tmp data-matrix holder
-  cwd="/tmp/"
-  qr_data="$cwd/wifi-qr-scan"
-  zbarcam --raw --prescale=320x240 /dev/video0 >$qr_data &
+call_zbar_cam_scan() {
+  qr_data=$1
+  zbarcam --raw --prescale=320x240 /dev/video0 >"$qr_data" &
 
   # Last job running in background eg. zbarcam
   pid=$!
-
   # Sleep loop until $qr_data file has content
+  local i=0
+  local chars="/-\|"
+  echo -en "  Scanning QR Code" "\r"
   while [[ ! -s $qr_data ]]; do
-    sleep 1
-    pgrep -x zbarcam >/dev/null && echo "Still Scanning" || exit 0
+    sleep 0.5
+    pgrep -x zbarcam >/dev/null && echo -en "${chars:$i:1}" "\r" || exit 0
+    i=$(((i+1)%${#chars}))
     # cleanup - add a trap that will remove $qr_data and kill zbarcam
     # if any of the signals - SIGHUP SIGINT SIGTERM it received.
     trap 'rm -f "$qr_data" ; kill -s 9 "$pid"; exit' SIGHUP SIGINT SIGTERM
   done
 
   kill -s 9 $pid
+  # to supress the kill message
+  # https://stackoverflow.com/a/5722874/11910267
+  wait $pid 2>/dev/null
+}
+
+call_zbar_img_scan() {
+  qr_data=$1
+  img_path=$2
+  zbarimg --raw "$img_path" >"$qr_data" 2>/dev/null
+}
+
+call_wifi_scan() {
+  mode=$1
+  wifiqrdata=''
+  # tmp data-matrix holder
+  cwd="/tmp/"
+  qr_data="$cwd/wifi-qr-scan"
+
+  if [[ $mode == "cam" ]]; then
+    call_zbar_cam_scan "$qr_data"
+  else
+    call_zbar_img_scan "$qr_data" "$mode" # mode stores the image path
+  fi
+
   wifiqrdata=$(cat $qr_data)
   rm -f $qr_data
 
@@ -207,7 +235,7 @@ call_wifi_scan() {
     ## Go Go GUI and CLI Mod
     # ssid & key are not always in the same sequence - fix by using a dict and cut identifier for first key
     if echo "$wifiqrdata" | grep --quiet "H:true;"; then
-    	QHIDE=true 
+    	QHIDE=true
     fi
     declare -A wifiqrcred
     wifiqrcred+=([$(echo "$wifiqrdata" | cut -b 6- | awk -F';' '{print $1}' | cut -d":" -f1)]=$(echo "$wifiqrdata" | cut -b 6- | awk -F';' '{print $1}' | cut -d":" -f2))
@@ -268,7 +296,7 @@ call_wifi_scan() {
 
 
 call_wifi_scan_terminal() {
-  call_wifi_scan
+  call_wifi_scan "$1"
      if [[ "$QSSIDO" == "NOWIFI" ]]; then
 	exit 0
      elif [[ "$QHIDE" == "true" ]]; then
@@ -282,10 +310,10 @@ call_wifi_scan_terminal() {
 }
 
 call_wifi_scan_gui() {
-  call_wifi_scan
+  call_wifi_scan "$1"
   # Function with QR data
   if [[ "$QSSIDO" =~ "ON" ]]; then
-    zenity --question --title="Connect to WiFi" --text="Connect to '$QSSID'?" --width=200 --height=120 --icon-name=network-wireless 2>/dev/null 
+    zenity --question --title="Connect to WiFi" --text="Connect to '$QSSID'?" --width=200 --height=120 --icon-name=network-wireless 2>/dev/null
     connectn=$?
     if [ $connectn == 0 ]; then \
       scan_connect
@@ -314,7 +342,11 @@ call_wifi_scan_gui() {
         exit
       fi
     elif [[ "$CHOICE" =~ "Retry submitting another QR Code" ]]; then
-      call_wifi_scan_gui
+      if [[ $1 == "cam" ]]; then
+        call_wifi_gui "cam"
+      else
+        call_file_select_and_scan_gui
+      fi
     else
       exit
     fi
@@ -328,6 +360,15 @@ call_wifi_scan_gui() {
   fi
 }
 
+call_file_select_and_scan_gui () {
+  img_path=$(zenity --file-selection)
+  if [ -z "$img_path" ]; then
+    echo "No file selected"
+    exit
+  fi
+  call_wifi_scan_gui "$img_path"
+}
+
 scan_connect() {
   nmcli radio wifi on
   nmcli dev wifi rescan >/dev/null 2>&1
@@ -360,11 +401,24 @@ case $1 in
   ;;
 [Ss])
   echo "qr scan"
-  call_wifi_scan_terminal
+  call_wifi_scan_terminal "cam"
+  ;;
+[Ff])
+  if [ -f "$2" ]; then
+    echo "qr scan from file $2"
+    call_wifi_scan_terminal "$2"
+  else
+    echo "File not found"
+    exit
+  fi
+  ;;
+[Pp])
+  echo "qr scan from file with gui"
+  call_file_select_and_scan_gui
   ;;
 [Qq])
   echo "qr scan with gui"
-  call_wifi_scan_gui
+  call_wifi_scan_gui "cam"
   ;;
 [Vv])
    echo -e "${GREEN}==================${RESET}"
@@ -373,10 +427,12 @@ case $1 in
   ;;
 *)
   echo -e "\nInvalid input\n
-	Please use	g for GUI Main Menu 
+	Please use	g for GUI Main Menu
 			c for WiFi QR Create GUI
 			t for WiFi QR Create Terminal
 			s for QR Scan and Auto Connect WiFi
+			f Terminal [file] for QR Scan and Auto Connect WiFi from file
+			p With GUI [file] for QR Scan and Auto Connect WiFi from file
 			q for QR Scan and Connect WiFi GUI
 			v for WiFi-QR Version is $VERSION
 		"
--- wifi-qr-0.2.orig/wifi-qr.1
+++ wifi-qr-0.2/wifi-qr.1
@@ -3,7 +3,7 @@
 wifi-qr \-  WiFi Share and Connect with QR
 .SH SYNOPSIS
 .B wifi-qr
-.RI [ Gg | Cc | Tt | Ss | Qq | Vv ]  
+.RI [ Gg | Cc | Tt | Ss | Ff | Pp | Qq | Vv ]  
 .br
 .SH DESCRIPTION
  PC to Android Network SSID Password share with QR code.
@@ -29,6 +29,12 @@ wifi-qr option
 .B s 	QR Scan and Auto Connect WiFi
 .br
 .TP
+.B f 	Terminal - QR File Scan and Auto Connect WiFi
+.br
+.TP
+.B p 	With Gui - QR File Scan and Auto Connect WiFi
+.br
+.TP
 .B q 	QR Scan and Connect WiFi GUI
 .br
 .TP
--- wifi-qr-0.2.orig/wifi-qr.desktop
+++ wifi-qr-0.2/wifi-qr.desktop
@@ -8,13 +8,18 @@ Icon=wifi-qr.svg
 Keywords="QR; WiFi; Password; Share;"
 Terminal=false
 Categories=GNOME;Utility;
-Actions=ScanQR;CreateQR;
+Actions=ScanQR;ScanFileQR;CreateQR;
 
 [Desktop Action ScanQR]
 Name=Scan WiFi QR Code
 Exec=sh -c 'wifi-qr q'
 Terminal=false
 
+[Desktop Action ScanFileQR]
+Name=Scan WiFi QR Code File
+Exec=sh -c 'wifi-qr p'
+Terminal=false
+
 [Desktop Action CreateQR]
 Name=Create WiFi QR Code
 Exec=sh -c 'wifi-qr c'
