home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 May / Chip_2000-05_cd2.bin / suse / inst-sys / lib / YaST2 / clients / printconf_test_page.ycp < prev    next >
Encoding:
Text File  |  2000-03-30  |  4.3 KB  |  135 lines

  1. /* The Printer Configurator
  2.  * Module for testing the printer
  3.  * Jan Holesovsky <kendy@suse.cz>, 2000
  4.  *
  5.  * $Id: printconf_test_page.ycp,v 1.9.4.4 2000/03/23 16:22:10 gs Exp $
  6.  */
  7.  
  8. /* Arguments:
  9.      1st: (map)    printer to be tested
  10.      
  11.    Returns:
  12.      true          everything was successful
  13.      false         otherwise
  14. */
  15.  
  16. {
  17. // Help, 1 of 3
  18.   string help_text = UI(_("<P>You can test the current settings of your printer here.
  19. Your printer should be already connected to
  20. the computer and ready to print.</P>
  21. "));
  22. // Help, 2 of 3
  23.   help_text = help_text + UI(_("<P>To start testing, push the <B>Run test</B> button. If you have
  24. selected the manufacturer and the model correctly, the printer will
  25. print a test page.</P>
  26. "));
  27. // Help, 3 of 3
  28.   help_text = help_text + UI(_("<P>If anything goes wrong, push <B>Stop!</B>.</P>"));
  29.  
  30. // Hint. Before pressing any button.
  31.   string test_message = UI(_("<P>YaST2 is ready to print a sample page.</P>
  32. <P>Please make sure that the printer is turned on and ONLINE,
  33. then press the <B>Run test</B> button.</P>
  34. "));
  35.  
  36. // Hint. After the 'Run test' button.
  37.   string msg_after_test = UI(_("<P>The test page was sent to the printer using the command '%1'.
  38. Printing should start in few seconds.</P>
  39. <P>If the printer is not producing appropriate output,
  40. use the <B>Stop!</B> button.</P>
  41. "));
  42.  
  43. // Hint. After the 'Stop!' button.
  44.   string msg_after_stop = UI(_("<P>Printing was stopped.</P>
  45. <P>If the printer still prints, push the reset button on the printer
  46. or remove all the paper from its tray. After it stops printing,
  47. <B>switch off</B> the printer power, wait 10 seconds and switch it on 
  48. again.</P>
  49. <P>Recheck the manufacturer and printer model entries you made 
  50. previously.</P>
  51. "));
  52.   
  53.   map printer = Args(0);
  54.  
  55.   /* The end of the definitions */
  56.  
  57.   term contents = 
  58.     `VBox(`ReplacePoint(`id(`text_rep), `RichText(test_message)),
  59.           `HBox(`PushButton(`id(`test), _("&Run test")),
  60.             `PushButton(`id(`stop), _("&Stop!"))),
  61.       `Label(_("Is the result as you expected?")));
  62.  
  63.   UI(`SetPrintconfContents(_("Print sample page"),
  64.       contents, help_text, false, _("&Yes")));
  65.   
  66.   list|void names = lookup(printer, "names");
  67.   if (names == nil)
  68.     return false;
  69.   string|void name = select(names, 0);
  70.   if (name == nil)
  71.     return false;//name = "";
  72.  
  73.   /* For now: */
  74.   string print_name = sformat("y2prn_%1.upp--auto-%1", name);
  75.   string upp_name = sformat("/etc/gs.upp/y2prn_%1.upp", name);
  76.   
  77.   any ret = nil;
  78.   do {
  79.     ret = UI(`UserInput());
  80.     
  81.     if (ret == `test) {
  82.       /* For 6.4 */
  83.       if (name == "lp") name = "";
  84.       string switch = "";
  85.       if (name != "")
  86.         switch = "-P";
  87.       //string exec_lpr = 
  88.       Shell(
  89.         sformat("PAP=`cat %1 | \
  90.                       grep -e '-sPAPERSIZE' | \
  91.               sed 's/[^=]*=//'` ; \
  92.                  cat /lib/YaST2/suse_testpg.ps | \
  93.                  sed -e \"s/~the~specified~paper~/$PAP/\" \
  94.                  -e 's/~the~lpr~parameter~/%2%3/' > /tmp/testpg.ps",
  95.          upp_name,
  96.          switch, name));
  97.  
  98.       if (Shell(sformat("lpr -P%1 /tmp/testpg.ps", print_name)) == 0) {
  99.         UI(`ChangeWidget(`id(`test), `Enabled, false));
  100.         string lpr_command = sformat("lpr %1%2 /tmp/testpg.ps", switch, name);
  101.         UI(`ReplaceWidget(`id(`text_rep),
  102.           `RichText(sformat(msg_after_test, lpr_command))));
  103.       } else {
  104.         UI(`ReplaceWidget(`id(`text_rep),
  105.           `RichText(
  106. "<P>I was unable to print the testpage. Check /lib/YaST2/suse_testpg.ps.</P>")));
  107.       }
  108.     }
  109.     if (ret == `stop) {
  110.       Shell("/sbin/init.d/lpd stop");
  111.       
  112.       string|void conn_name = lookup(printer, "connection");
  113.       if (conn_name == "parallel" || conn_name == "serial" || conn_name == "usb") {
  114.         string device = lookup(lookup(printer, conn_name), "device");
  115.  
  116.         Shell(sformat("fuser -k %1", device));   // kill currently printing processes
  117.     
  118.     if (conn_name == "parallel")
  119.           Shell(sformat("reset_parport %1", device)); // reset the parallel port
  120.       }
  121.       
  122.       Shell("rm `find /var/spool/lpd -name \"[cd]f*\" -type f`"); // remove all jobs
  123.       Shell("/sbin/init.d/lpd start"); // restart lpd
  124.  
  125.       UI(`ReplaceWidget(`id(`text_rep), `RichText(msg_after_stop)));
  126.       UI(`ChangeWidget(`id(`test), `Enabled, true));
  127.     }
  128.   } while (ret == `test || ret == `stop);
  129.  
  130.   if (ret == `next)
  131.     return true;
  132.  
  133.   return false;
  134. }
  135.