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

  1. /* The Printer Configurator
  2.  * Asking the device of a parallel/USB(/TODO serial) printer
  3.  * Jan Holesovsky <kendy@suse.cz>, 2000
  4.  *
  5.  * $Id: printconf_ask_device.ycp,v 1.6.4.3 2000/03/23 16:09:07 gs Exp $
  6.  */
  7.  
  8. /* Arguments:
  9.      1st: (string) "parallel" | "usb" (TODO: "serial")
  10.      2nd: (map)    the printer record
  11.      3rd: (bool)   am I the first dialog (when configuring?)
  12.  
  13.    Returns:
  14.      (map)         the printer record if successful
  15.      (void)        nil otherwise
  16. */
  17.  
  18. {
  19.   string type  = Args(0);
  20.   map printer  = Args(1);
  21.   boolean frst = Args(2);
  22.  
  23.   string help_text = "";
  24.   if (type == "parallel")
  25. // Help, parallel printer part
  26.       help_text = UI(_("<P>If you have multiple parallel ports, please choose the parallel port to which your printer is attached.</P>"));
  27.  
  28.   if (type == "usb")
  29. // Help, USB printer part
  30.       help_text = UI(_("<P>Please choose the device for your USB printer.</P>"));
  31.  
  32. // Help, common part
  33.   help_text = help_text + UI(_("<P>If you want to be sure that the printer is properly connected, try the <B>Test</B> button.</P>
  34. "));
  35.  
  36. // Help, the test screen
  37.   string help_text_test = UI(_("<P>Here you can test whether your device is functional and the printer is accessible.</P>
  38. "));
  39.   
  40. // Text describing what is happening
  41.   string test_descr = UI(_("<P>I will send the message 'Hello, world' to the previously selected 
  42. device.</P>
  43. <P>Please connect your printer to the computer,
  44. switch it on, and make sure that it is ONLINE.</P>
  45. <P>If the operation fails, it will be timed out in %1 seconds.</P>
  46. "));
  47.  
  48.   map test_messages = $[
  49.     0 : _("<P>It seems that there are no problems with the device you chose.
  50. If your printer has reacted somehow (printed message, formfeed, or at least
  51. blinking leds), the hardware connection should be functioning correctly.</P>
  52. "),
  53.     1 : _("<P>There was a problem while sending the message to the printer--
  54. The operation has timed out.</P>
  55. <P>Please verify that your printer is connected to the computer,
  56.  that the printer power is on, and that it is ONLINE.</P>
  57. <P>It is also possible that you have a cabling problem.</P>
  58. "),
  59.     2 : _("<P>There was a problem while printing.</P>
  60. <P>It seems that the device is not properly configured or you do not have 
  61. permission
  62. to write to it. Did you run the configuration program as user 'root'?</P>
  63. "),
  64.     127 : _("<P>FATAL: I was not able to run the 'test_device' script. I am sorry.</P>
  65. ")
  66.   ];
  67.  
  68.   map device_names = $[
  69.     "/dev/lp0" : _("First parallel port (/dev/lp0)"),
  70.     "/dev/lp1" : _("Second parallel port (/dev/lp1)"),
  71.     "/dev/lp2" : _("Third parallel port (/dev/lp2)"),
  72.     "/dev/lp3" : _("Fourth parallel port (/dev/lp3)"),
  73.     "/dev/usblp0" : _("First USB printer (/dev/usblp0)"),
  74.     "/dev/usblp1" : _("Second USB printer (/dev/usblp1)"),
  75.     "/dev/usblp2" : _("Third USB printer (/dev/usblp2)"),
  76.     "/dev/usblp3" : _("Fourth USB printer (/dev/usblp3)")
  77.   ];
  78.   integer timeout_sec = 10;
  79.   string test_text = "Hello, world\n\f";
  80.  
  81.   define TestDevice(string dev) ``{
  82.     term contents = 
  83.       `VBox(`ReplacePoint(`id(`text_rep), `RichText(sformat(test_descr, timeout_sec))),
  84.             `PushButton(`id(`test), _("&Run test")),
  85.         `Label(_("Is the result as you expected?")));
  86.  
  87.     UI(`SetPrintconfContents(_("Testing the connection of the printer"),
  88.         contents, help_text_test, false, _("&Yes")));
  89.     
  90.     any ret = nil;
  91.     do {
  92.       ret = UI(`UserInput());
  93.       
  94.       if (ret == `test) {
  95.         integer tst = Shell(sformat("test_device '%1' '%2' '%3'",
  96.         test_text, dev, timeout_sec));
  97.  
  98.     UI(`ReplaceWidget(`id(`text_rep), `RichText(lookup(test_messages, tst))));
  99.       }
  100.     } while (ret == `test);
  101.  
  102.     if (ret == `next) return true;
  103.     return false;
  104.   };
  105.   /* The end of the definitions */
  106.  
  107.   term devicesel = `VStretch();
  108.   if (type == "parallel" || type == "usb") {
  109.     list|void devices = nil;
  110.     if (type == "parallel")
  111.       devices = SCR(`Read(.proc.parport.devices));
  112.     if (type == "usb")
  113.       devices = SCR(`Read(.proc.usblp.devices));
  114.       
  115.     if (devices == nil)
  116.       devices = [];
  117.     if (size(devices) == 0 && type == "parallel") {
  118.       // CAUTION: "device" here means /dev/lp0, /dev/lp1, ...
  119.       UI(`DisplayMessage(_("I have not found any parallel devices (/dev/lp?)! It seems\n
  120. that your parallel port is not properly configured.
  121. ")));
  122.       devices = add(devices, "/dev/lp0");
  123.     }
  124.     if (size(devices) == 0 && type == "usb") {
  125.       // CAUTION: "device" here means /dev/usblp0, /dev/usblp1, ...
  126.       UI(`DisplayMessage(_("I have not found any USB devices (/dev/usblp?)! It seems\n
  127. that your USB bus is not properly configured.
  128. ")));
  129.       devices = add(devices, "/dev/usblp0");
  130.     }
  131.  
  132.     list device_val = [];
  133.     foreach(`dev, devices, ``{
  134.       device_val = add(device_val, `item(`id(dev), lookup(device_names, dev, dev),
  135.         (dev == "/dev/lp0" || dev == "/dev/usblp0")));
  136.     });
  137.     devicesel = `VSquash(`SelectionBox(`id(`devicesel),
  138.       _("Select connection:"), device_val));
  139.   }
  140.   /*if (type == "usb") {
  141.     devicesel = `TextEntry(`id(`usbent), _("Enter USB device (e.g. /dev/usblp0):"));
  142.   }*/
  143.   
  144.   term contents =
  145.     `VBox(devicesel,
  146.           `VStretch(),
  147.           `Right(`PushButton(`id(`test), _("&Test"))));
  148.       
  149.   any ret = nil;
  150.   string|void device = nil;
  151.   do {
  152.     UI(`SetPrintconfContents(_("Printer device"),
  153.       contents, help_text, frst, _("&Next")));
  154.     ret = UI(`UserInput());
  155.  
  156.     if (type == "parallel" || type == "usb")
  157.       device = UI(`QueryWidget(`id(`devicesel), `CurrentItem));
  158.     /*if (type == "usb")
  159.       device = UI(`QueryWidget(`id(`usbent), `Value));*/
  160.  
  161.     if ((ret == `test) && (device != nil) && TestDevice(device))
  162.       ret = `next;
  163.   } while ((ret == `test) || (ret == `next && (device == nil || device == "")));
  164.   
  165.   if (ret == `next && type == "parallel")
  166.     return add(printer, "parallel", $[ "device":device]);
  167.   if (ret == `next && type == "usb")
  168.     return add(printer, "usb", $[ "device":device]);
  169.   /* TODO: if (ret == `next && type == "serial")
  170.     return add(printer, "serial", $[ "device":device, "baudrate": <blah>]);*/
  171.  
  172.   return nil;
  173. }
  174.