// IfsTelnetPressShow.bcpl -- Executive press-queue subcommands
// Copyright Xerox Corporation 1980, 1981

// Last modified November 14, 1981  10:51 AM by Taft

get "Ifs.decl"
get "IfsFiles.decl"
get "IfsPress.decl"
get "IfsRs.decl"

external
[
// outgoing procedures
ExecShowPress;

// incoming procedures
EnumeratePressQueue; IFSPrintError; TelnetAborting; TelnetConfirm;
FreePointer; GetString; PutTemplate; StringCompare; TruePredicate; Ws; Wss;

// incoming statics
dsp; CtxRunning
]

//----------------------------------------------------------------------------
let ExecShowPress(cs, showOnly) be
//----------------------------------------------------------------------------
// Called with showOnly = true by "Show Print-requests"
// Called with showOnly = false by "Cancel"
[
let userName = nil  // word after showOnly
unless showOnly do Wss(cs, " (printing requests)")
let ui = CtxRunning>>RSCtx.userInfo
userName = ui>>UserInfo.userName
if ui>>UserInfo.capabilities.wheel then
   [
   Wss(cs, " (for user) ")
   userName = GetString(cs, 0, Wss, "user name")
   ]

let capabilities = ui>>UserInfo.capabilities
ui>>UserInfo.capabilities.wheel = true

EnumeratePressQueue(TruePredicate, ShowPQE, lv showOnly)

ui>>UserInfo.capabilities = capabilities
if userName ne ui>>UserInfo.userName then FreePointer(lv userName)
]

//----------------------------------------------------------------------------
and ShowPQE(pqe, serverName, lvShowOnly) = valof
//----------------------------------------------------------------------------
[
let requestorName = pqe + pqe>>PQE.requestorName
if not TelnetAborting() &
 ((lvShowOnly!1)>>String.length eq 0 %
  StringCompare(lvShowOnly!1, requestorName) eq 0) then
   [
   PutTemplate(dsp, "*n$S, $D pages, to $S, for $S, $S-sided",
    pqe+(pqe>>PQE.fileName), (pqe>>PQE.pages)*(pqe>>PQE.copies),
    serverName, requestorName, (pqe>>PQE.duplex? "2","1"))
   if pqe>>PQE.holdPassword ne 0 then
      PutTemplate(dsp, "  Password: $S", pqe+pqe>>PQE.holdPassword);
   test pqe>>PQE.status eq ecPQEPending
      ifso if not @lvShowOnly & TelnetConfirm(". Cancel?") then
         pqe>>PQE.status = ecPQERemoved
      ifnot
         [ Ws("*n --"); IFSPrintError(dsp, pqe>>PQE.status) ]
   ]

// Always rewrite PQE -- so that we will set write date = read date.
// This generates some additional activity for the Press background
// process.  But if we didn't do this, the read date would end up
// later than the write date, and background processing of this file
// might be erroneously delayed.
resultis true
]