Patch title: Release 94 bulk changes
Abstract:
File: /pliant/protocol/lpr/spooler.page
Key:
    Removed line
    Added line
module "/pliant/language/unsafe.pli"
module "/pliant/language/stream.pli"
module "/pliant/admin/file.pli"
module "/pliant/appli/database.pli"
module "/pliant/storage/database.pli"
module "/pliant/language/context.pli"
module "/pliant/fullpliant/this_computer.pli"
module "database.pli"
module "embedded.pli"
module "/pliant/graphic/color/gamut.pli"
module "/pliant/graphic/color/database.pli"
module "device.pli"
module "spool.pli"


title "Print queues configuration and administration"

requires "spooler"
lpr_embedded_migrate "embedded:/"


if allowed:"administrator"
  para
    table columns 3 border 0
      cell [LPR service:]
      cell
        var Str lpr := this_computer "pliant" "lpr" "service"
        select "" lpr
          option "" ""
          option "Yes" "true"
          option "No" "false"
      cell [Should we run the LPR server on this computer, allowing other computers on the network to access printers connected through this computer ?]
    button "Update"
      this_computer "pliant" "lpr" "service" := lpr
      reload_page

para
  [Print queues:] ; eol
  table columns 3
    cell header [Queue ID]
    cell header [Label]
    cell header [Administration]
    each printer this_computer:env:"printer"
      var Str queue := keyof:printer
      var Str queue := keyof printer
      var Str label := printer "label"
      if printer:"status"="S"
        cell color (color hsl 30 50 60)
          if printer:"default"="true"
            bold text:queue
          else
            text queue
      else
        cell
          if printer:"default"="true"
            bold text:queue
          else
            text queue
      cell
        text label
      cell
        if allowed:"administrator"
          page button "configure" noeol
            var (Data Set:Str) p :> this_computer:env:"printer" queue
            title "Print queue '"+keyof:p+"'"
    
            box color (color hsl 60 50 75) header "Expression configuration" round 5
              para
                [1. ]
                select "Select a profile: " (var Str cdevice)
                  option "" ""
                  each cdev color_database:data:device
                    if cdev:printer:driver<>"" and cdev:label<>""
                      option cdev:label keyof:cdev
              para
                [2. ]
                select "How is the printer connected:" (var Str pdevice) noeol
                  if os_api="win32"
                    option "parallel port" "device:LPT1"
                    option "a print server" "lpr"
                  else
                    option "parallel port" "device:/lp0"
                    option "usb port" "device:/usb/lp0"
                    option "a print server" "lpr"
                input "IP:" (var Str ip) length 15 noeol
                var Str queue := "lp"
                input "queue:" queue length 10
                italic [You need to fill 'IP' and 'queue' only if the printer is connected through a print server.]
              para
                [3. Press ]
                button "configure all at once" noeol
                  var Data:ColorDevice prof :> color_database:data:device:cdevice
                  this_computer "printer" keyof:p "printer" := "the_printer"
                  this_computer "printer" keyof:p "device" := (shunt pdevice="lpr" "lprng://"+ip+"/"+queue pdevice)
                  this_computer "printer" keyof:p "label" := prof label
                  this_computer "printer" keyof:p "once" := "true"
                  this_computer "printer" keyof:p "timeout" := shunt os_api="linux" and not (pdevice parse "device:/usb/" any) "120" ""
                  this_computer "printer" keyof:p "export" := "127.0.0.1"
                  each f (prof:printer pmap "" Set:Str)
                    this_computer "printer" keyof:p keyof:f := f
                  reload_page
                [ button.]
    
            header "Description"
              table columns 3 border 0
                cell [Queue label:]
                cell
                  var Str label := p "label"
                  input "" label length 40
                cell
                  void
            header "Driver (most of it should be automatically field from the profile selected in express configuration)"
              table columns 3 border 0
                cell [Driver:]
                cell
                  var Str driver := p "driver"
                  input "" driver length 10
                cell
                  [The filter is the Pliant driver.] ; eol
                  [Most common filter are] ; fixed [ escp2 ] ; [for Epson stylus line,]
                  fixed [ pcl ] ; [for HP Designjet (does not work on HP Desktop inkjet printers), ]
                  [and ] ; fixed [ gimpprint ] ; [if the printer will be driver using Gimp-print free software.]
                cell [Model:]
                cell
                  var Str model := p "model"
                  input "" model length 10
                cell
                  [Must be one of the models the driver is awared of.]
                cell [Extra options:]
                cell
                  var Str options := p "options"
                  input "" options length 40
                cell
                  [As an example, the] ; fixed [ escp2 ] ; [driver recognizes] ; fixed [ unidirectional ] ; [option.]
                cell [Paper name:]
                cell
                  var Str paper := p "paper"
                  input "" paper length 30 noeol
                cell
                  [This is informative only.]
                cell [Paper size:]
                cell
                  var Str size_x := p "size_x"
                  input "" size_x length 4 noeol
                  var Str size_y := p "size_y"
                  input " x " size_y length 4 noeol
                  [ mm]
                cell
                  void
                cell [Margins:]
                cell
                  var Str margin_left := p "margin_left"
                  var Str margin_top := p "margin_top"
                  var Str margin_right := p "margin_right"
                  var Str margin_bottom := p "margin_bottom"
                  input "L" margin_left length 3 noeol
                  input "T" margin_top length 3 noeol
                  input "R" margin_right length 3 noeol
                  input "B" margin_bottom length 3 noeol
                  [ mm]
                cell
                  void
                cell [R鳯lution:]
                cell
                  var Str resolution_x := p "resolution_x"
                  input "" resolution_x length 4 noeol
                  var Str resolution_y := p "resolution_y"
                  input " x " resolution_y length 4 noeol
                  [ dpi]
                cell
                  void
                cell [Antialiasing:]
                cell
                  var Str antialiasing_x := p "antialiasing_x"
                  input "" antialiasing_x length 1 noeol
                  var Str antialiasing_y := p "antialiasing_y"
                  input " x " antialiasing_y length 1
                cell
                  [Use no antialiasing if your computer is slow, 2 or even 4 if your computer is faster than the printer.] 
                cell [Sharpening:]
                cell
                  var Str sharpening := p "sharpening"
                  input "" sharpening length 5
                cell
                  [Leave it blank unless you want to experiment.]
                cell [Gamut:]
                cell
                  var Str gamut := p "gamut"
                  input "" gamut length 40
                cell
                  var Float ctimeout := 86400
                  button "Compute calibration grid" noeol
                    color_gamut_compute "rgb" this_computer:env:"printer":(keyof p):"gamut" "grid_steps "+this_computer:env:"printer":(keyof p):"grid_steps" ctimeout
                    reload_page
                  input " no more than " ctimeout length 6 noeol
                  [seconds] ; eol
                  link "edit color profiles" "/pliant/graphic/color/editor.html"
                cell [Calibration steps:]
                cell
                  var Str grid_steps := p "grid_steps"
                  input "" grid_steps length 2 noeol
                cell
                  [How many steps do we compute on the calibration grid in each dimension. ]
                  [33 is perfect but will require several hours of calibration on a fast computer, 17 is high quality, and 9 is correct.]
            header "Connection"
              table columns 3 border 0
                cell [Printer ID:]
                cell
                  var Str printer_id := p "printer"
                  input "" printer_id length 16
                cell
                  [If several queues connect to the same physical printer, they should have the same printer ID in order to avoid to send several jobs all at once.]
                cell [Device:]
                cell
                  var Str device := p "device"
                  input "" device length 40
                cell
                  [Probably] ; fixed [ device:/lp0 ] ; [if you are using the so called parallel interface,]
                  fixed [ device:/usb/lp0 ] ; [if the printer is connected to an USB port, ]
                  [or something like] ; fixed [ lpr://server_name/queue_name ] ; [ is the printer is connected to another server or a print server. ]
                  note "more details"
                    title "Remote printers"
                    para
                      [If the printer is connected to an LPRng compatible server (accepting send on the fly feature), then you can try something like] ; fixed [ lprng://server_name/queue_name ] ; eol
                    para
                      [If the printer is connected to a print server it may accept FTP connections through something like] ; fixed [ ftp://server_name/client/queue_name ] ; [where 'client' is an identifier that you must not change.]
                cell [Timemout:]
                cell
                  var Str timeout := p "timeout"
                  input "" timeout length 4 noeol ; [ seconds]
                cell
                  highlight "warning: " ; [Don't set a timeout if the printer is connected through USB on Linux because it would raise a Linux kernel bug.]
                cell [Print on the fly:]
                cell
                  var Str once := p "once"
                  select "" once
                    option "" ""
                    option "yes" "true"
                    option "no" "false"
                cell
                  [Should print while receiving or ripping, or store then print. ]
                  [In case of troubles, just say 'no'.] ; eol
                  [If you want to print on the fly to a printer connecter through a print server, you have to replace 'lpr:' with 'lprng:' in the device field, and the remote print server implementation must be correct (as an example, LPRng is, but basic LPD daemon is not).]
                cell [Export:]
                cell
                  var Str export := p "export"
                  input "" export length 40
                cell
                  [Specify here the IP addresses that are allowed to print on the printer.] ; eol
                  [An example could be:]
                  fixed [ 127.0.0.1 10.0.0.0/255.0.0.0]
                cell [Default:]
                cell
                  var Str default := p "default"
                  select "" default
                    option "" ""
                    option "yes" "true"
                    option "no" "false"
                cell
                  [Is this the default queue usually named 'lp' in Unix world ?]
            para
              button "Update printer queue settings"
                this_computer "printer" keyof:p "label" := label
                this_computer "printer" keyof:p "driver" := driver
                this_computer "printer" keyof:p "model" := model
                this_computer "printer" keyof:p "options" := options
                this_computer "printer" keyof:p "sharpening" := sharpening
                this_computer "printer" keyof:p "paper" := paper
                this_computer "printer" keyof:p "size_x" := size_x
                this_computer "printer" keyof:p "size_y" := size_y
                this_computer "printer" keyof:p "margin_left" := margin_left
                this_computer "printer" keyof:p "margin_top" := margin_top
                this_computer "printer" keyof:p "margin_right" := margin_right
                this_computer "printer" keyof:p "margin_bottom" := margin_bottom
                this_computer "printer" keyof:p "resolution_x" := resolution_x
                this_computer "printer" keyof:p "resolution_y" := resolution_y
                this_computer "printer" keyof:p "antialiasing_x" := antialiasing_x
                this_computer "printer" keyof:p "antialiasing_y" := antialiasing_y
                this_computer "printer" keyof:p "gamut" := gamut
                this_computer "printer" keyof:p "grid_steps" := grid_steps
                this_computer "printer" keyof:p "printer" := printer_id
                this_computer "printer" keyof:p "device" := device
                this_computer "printer" keyof:p "timeout" := timeout
                this_computer "printer" keyof:p "once" := once
                this_computer "printer" keyof:p "export" := export
                this_computer "printer" keyof:p "default" := default
                each v (this_computer:env:"printer" keyof:p)
                  if v=""
                   (this_computer:env:"printer" keyof:p) delete keyof:v
                lpr_embedded_configure "embedded:/"
                goto_backward
            para
              note "display raw print queue settings (usefull only for debugging)"
                var (Data Set:Str) p :> this_computer:env:"printer" keyof:p
                title "Print queue '"+keyof:p+"'"
                table columns 2
                  cell header [Variable]
                  cell header [Value]
                  each v p
                    cell (text keyof:v)
                    cell text:v
        if printer:"status"="S"
          button "start" noeol
            lpr_restart queue
            reload_page
        else
          button "stop" noeol
            lpr_stop queue
            reload_page
  
  if allowed:"administrator"
    input "Queue name: " (var Str qname) noeol
    page button "Create new printer queue" noeol
      this_computer "printer" qname "printer" := "the_printer"
      reload_page
    page button "Delete the printer queue" noeol
      this_computer:env:"printer" delete qname
      reload_page


if os_api="linux"
  para
    [Auto detected USB printers:] ; eol
    table columns 2
      cell header [USB printer model]
      cell header [Serial number]
      for (var Int i) 0 15
        var Str dev := "device:/usb/lp"+string:i
        if lpr_device_model:dev<>"" or lpr_device_sn:dev<>""
          cell
            text lpr_device_model:dev
          cell
            text lpr_device_sn:dev


para
  text "Print jobs (current time is "+string:datetime+") :[lf]"
  table columns 6
    cell header [Queue]
    cell header [Label]
    cell header [Size]
    cell header [Queued on[lf]Started on]
    cell header [Status]
    cell void
    each job lpr_database:data:job
      cell
        text job:queue
      cell
        text job:label
      cell
        if job:format=""
          var FileInfo info := file_query (lpr_filename job "lpr") standard
          text (string info:size)
        else
          var FileInfo info := file_query (lpr_filename job job:format) standard
          text (string info:size)+" "+job:format
          if job:format<>"prn"
            var FileInfo info := file_query (lpr_filename job "prn") standard
            if info=defined
              eol ; text (string info:size)
      cell
        text (string job:s_startup)
        if job:p_startup=defined
          eol ; text (string job:p_startup)
      if job:error<>""
        cell color (color hsl 0 50 70)
          text job:error
      else
        cell
          if job:s_status="R"
            text "spooling "+job:s_comment+"[lf]"
          if job:r_status="R"
            text "ripping "+job:r_comment+"[lf]"
          if job:p_status="S"
            text "suspended[lf]"
          if job:p_status="R"
            text "printing "+job:p_comment+"[lf]"
      cell
        page button "Edit"
          title "Job '"+keyof:job+"' on queue '"+queue+"'"
        page button "edit" noeol
          title "Job '"+keyof:job+"' on queue '"+job:queue+"'"
          [Raw settings:]
          table columns 2
            cell header [ID]
            cell header [Value]
            each v (job pmap "" Set:Str)
              cell
                text keyof:v
              cell
                text v
          page button "Discard"
            job error := ""
            lpr_cancel job (var Stream no_data)
            goto_backward
        if job:p_status="W"
          page button "suspend" noeol
            if job:p_status="W"
              job p_status := "S"
            reload_page
        eif job:p_status="S"
          page button "restart" noeol
            if job:p_status="S"
              job p_status := "W"
            reload_page
        page button "cancel" noeol
          job error := ""
          lpr_cancel job (var Stream no_data)
          reload_page
  button "Discard all jobs at once"
    title "Cancel all jobs"
    [Do you really want to cancel all jobs on all queues at once ? ]
    button "yes" noeol
      each job lpr_database:data:job
        job error := ""
        lpr_cancel job (var Stream no_data)
      goto_backward
    button "no"
      goto_backward