#!/bin/sh
#8.06.11 rodin.s: i18n

export TEXTDOMAIN=xsaneshell #usr_sbin2
export TEXTDOMAINDIR=/usr/share/locale
export OUTPUT_CHARSET=UTF-8


COMMOUT="`cat /etc/sane.d/dll.conf | grep '^#[a-zA-Z0-9]' | tr '#' ' ' | tr '\n' ' '`"

export Xsane='
<window title="'$(gettext 'Frontend for Xsane')'" icon-name="gtk-preferences">
<vbox space-expand="true" space-fill="true">
  <frame>
    <vbox space-expand="true" space-fill="true">
      '"`/usr/lib/gtkdialog/xml_info scale scanner.svg 60 "$(gettext "<b>When Xsane starts, your scanner (if it is connected and turned on) should be autodetected.</b>")" "$(gettext "However, some entries in the drivers list (/etc/sane.d/dll.conf) are commented-out. These are:")" "<i>$COMMOUT</i>" "$(gettext "If your scanner is one of these, then Xsane will not auto-detect it. - in that case, click 'Quit' button and open 'dll.conf' in a text editor and uncomment the appropriate entry.")"`"'
      <text height-request="5" space-expand="false" space-fill="false"><label>""</label></text>
      <expander>  
        <vbox border-width="10">
          <text xalign="0" use-markup="true"><label>"'$(gettext "Xsane may be a bit 'insane' when detecting a SCSI scanner. There are various things that you may have to do:
1. Run 'sane-find-scanner' in a terminal window.
2. Make sure 'sg' module is loaded.
3. Specify the device on the commandline,
   ex: <b># xsane microtek2:/dev/sg3</b>
4. or maybe a symbolic link,
   ex: <b># ln -s /dev/sg3 /dev/scanner</b>")'"</label></text>
          <hseparator></hseparator>
        </vbox>
      <label>'$(gettext 'About SCSI drives')'</label>
    </expander>
    <text xalign="1" use-markup="true" wrap="false"><label>"'$(gettext "To continue and run Xsane, please choose the scanner type.")'"</label></text>
  </vbox>
  <hbox space-expand="false" space-fill="false">
    <button image-position="2">
      '"`/usr/lib/gtkdialog/xml_button-icon plug_usb.svg huge`"'
      <label>USB</label>
      <action>EXIT:10</action>
    </button>
    <button image-position="2">
      '"`/usr/lib/gtkdialog/xml_button-icon plug_parallel.svg huge`"'
      <label>"'$(gettext 'Parallel')'"</label>
      <action>EXIT:11</action>
    </button>
    <button image-position="2">
      '"`/usr/lib/gtkdialog/xml_button-icon plug_scsi.svg huge`"'
      <label>SCSI</label>
      <action>EXIT:12</action>
    </button>
    </hbox>
  </frame>
  <hbox space-expand="false" space-fill="false">
    <button>
      '"`/usr/lib/gtkdialog/xml_button-icon quit`"'
      <label>"'$(gettext 'Quit')'"</label>
    </button>
  </hbox>
</vbox>
</window>'

. /usr/lib/gtkdialog/xml_info gtk #build bg_pixmap for gtk-theme
RETVAL="`gtkdialog -p Xsane`"
eval "$RETVAL"

case $RETVAL in
 *10*)
  #modprobe scanner
  #2.6 kernel does not have module 'scanner'. instead relies on libusb.
  echo
  ;;
 *11*)
  modprobe parport_pc
  ;;
 *12*)
  modprobe sg
  ;;
 *)
  exit
  ;;
esac

sleep 1
exec xsane
