home *** CD-ROM | disk | FTP | other *** search
- /* The Printer Configurator
- * Module for testing the printer
- * Jan Holesovsky <kendy@suse.cz>, 2000
- *
- * $Id: printconf_test_page.ycp,v 1.9.4.4 2000/03/23 16:22:10 gs Exp $
- */
-
- /* Arguments:
- 1st: (map) printer to be tested
-
- Returns:
- true everything was successful
- false otherwise
- */
-
- {
- // Help, 1 of 3
- string help_text = UI(_("<P>You can test the current settings of your printer here.
- Your printer should be already connected to
- the computer and ready to print.</P>
- "));
- // Help, 2 of 3
- help_text = help_text + UI(_("<P>To start testing, push the <B>Run test</B> button. If you have
- selected the manufacturer and the model correctly, the printer will
- print a test page.</P>
- "));
- // Help, 3 of 3
- help_text = help_text + UI(_("<P>If anything goes wrong, push <B>Stop!</B>.</P>"));
-
- // Hint. Before pressing any button.
- string test_message = UI(_("<P>YaST2 is ready to print a sample page.</P>
- <P>Please make sure that the printer is turned on and ONLINE,
- then press the <B>Run test</B> button.</P>
- "));
-
- // Hint. After the 'Run test' button.
- string msg_after_test = UI(_("<P>The test page was sent to the printer using the command '%1'.
- Printing should start in few seconds.</P>
- <P>If the printer is not producing appropriate output,
- use the <B>Stop!</B> button.</P>
- "));
-
- // Hint. After the 'Stop!' button.
- string msg_after_stop = UI(_("<P>Printing was stopped.</P>
- <P>If the printer still prints, push the reset button on the printer
- or remove all the paper from its tray. After it stops printing,
- <B>switch off</B> the printer power, wait 10 seconds and switch it on
- again.</P>
- <P>Recheck the manufacturer and printer model entries you made
- previously.</P>
- "));
-
- map printer = Args(0);
-
- /* The end of the definitions */
-
- term contents =
- `VBox(`ReplacePoint(`id(`text_rep), `RichText(test_message)),
- `HBox(`PushButton(`id(`test), _("&Run test")),
- `PushButton(`id(`stop), _("&Stop!"))),
- `Label(_("Is the result as you expected?")));
-
- UI(`SetPrintconfContents(_("Print sample page"),
- contents, help_text, false, _("&Yes")));
-
- list|void names = lookup(printer, "names");
- if (names == nil)
- return false;
- string|void name = select(names, 0);
- if (name == nil)
- return false;//name = "";
-
- /* For now: */
- string print_name = sformat("y2prn_%1.upp--auto-%1", name);
- string upp_name = sformat("/etc/gs.upp/y2prn_%1.upp", name);
-
- any ret = nil;
- do {
- ret = UI(`UserInput());
-
- if (ret == `test) {
- /* For 6.4 */
- if (name == "lp") name = "";
- string switch = "";
- if (name != "")
- switch = "-P";
- //string exec_lpr =
- Shell(
- sformat("PAP=`cat %1 | \
- grep -e '-sPAPERSIZE' | \
- sed 's/[^=]*=//'` ; \
- cat /lib/YaST2/suse_testpg.ps | \
- sed -e \"s/~the~specified~paper~/$PAP/\" \
- -e 's/~the~lpr~parameter~/%2%3/' > /tmp/testpg.ps",
- upp_name,
- switch, name));
-
- if (Shell(sformat("lpr -P%1 /tmp/testpg.ps", print_name)) == 0) {
- UI(`ChangeWidget(`id(`test), `Enabled, false));
- string lpr_command = sformat("lpr %1%2 /tmp/testpg.ps", switch, name);
- UI(`ReplaceWidget(`id(`text_rep),
- `RichText(sformat(msg_after_test, lpr_command))));
- } else {
- UI(`ReplaceWidget(`id(`text_rep),
- `RichText(
- "<P>I was unable to print the testpage. Check /lib/YaST2/suse_testpg.ps.</P>")));
- }
- }
- if (ret == `stop) {
- Shell("/sbin/init.d/lpd stop");
-
- string|void conn_name = lookup(printer, "connection");
- if (conn_name == "parallel" || conn_name == "serial" || conn_name == "usb") {
- string device = lookup(lookup(printer, conn_name), "device");
-
- Shell(sformat("fuser -k %1", device)); // kill currently printing processes
-
- if (conn_name == "parallel")
- Shell(sformat("reset_parport %1", device)); // reset the parallel port
- }
-
- Shell("rm `find /var/spool/lpd -name \"[cd]f*\" -type f`"); // remove all jobs
- Shell("/sbin/init.d/lpd start"); // restart lpd
-
- UI(`ReplaceWidget(`id(`text_rep), `RichText(msg_after_stop)));
- UI(`ChangeWidget(`id(`test), `Enabled, true));
- }
- } while (ret == `test || ret == `stop);
-
- if (ret == `next)
- return true;
-
- return false;
- }
-