home *** CD-ROM | disk | FTP | other *** search
- /* The Printer Configurator
- * Asking the device of a parallel/USB(/TODO serial) printer
- * Jan Holesovsky <kendy@suse.cz>, 2000
- *
- * $Id: printconf_ask_device.ycp,v 1.6.4.3 2000/03/23 16:09:07 gs Exp $
- */
-
- /* Arguments:
- 1st: (string) "parallel" | "usb" (TODO: "serial")
- 2nd: (map) the printer record
- 3rd: (bool) am I the first dialog (when configuring?)
-
- Returns:
- (map) the printer record if successful
- (void) nil otherwise
- */
-
- {
- string type = Args(0);
- map printer = Args(1);
- boolean frst = Args(2);
-
- string help_text = "";
- if (type == "parallel")
- // Help, parallel printer part
- help_text = UI(_("<P>If you have multiple parallel ports, please choose the parallel port to which your printer is attached.</P>"));
-
- if (type == "usb")
- // Help, USB printer part
- help_text = UI(_("<P>Please choose the device for your USB printer.</P>"));
-
- // Help, common part
- 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>
- "));
-
- // Help, the test screen
- string help_text_test = UI(_("<P>Here you can test whether your device is functional and the printer is accessible.</P>
- "));
-
- // Text describing what is happening
- string test_descr = UI(_("<P>I will send the message 'Hello, world' to the previously selected
- device.</P>
- <P>Please connect your printer to the computer,
- switch it on, and make sure that it is ONLINE.</P>
- <P>If the operation fails, it will be timed out in %1 seconds.</P>
- "));
-
- map test_messages = $[
- 0 : _("<P>It seems that there are no problems with the device you chose.
- If your printer has reacted somehow (printed message, formfeed, or at least
- blinking leds), the hardware connection should be functioning correctly.</P>
- "),
- 1 : _("<P>There was a problem while sending the message to the printer--
- The operation has timed out.</P>
- <P>Please verify that your printer is connected to the computer,
- that the printer power is on, and that it is ONLINE.</P>
- <P>It is also possible that you have a cabling problem.</P>
- "),
- 2 : _("<P>There was a problem while printing.</P>
- <P>It seems that the device is not properly configured or you do not have
- permission
- to write to it. Did you run the configuration program as user 'root'?</P>
- "),
- 127 : _("<P>FATAL: I was not able to run the 'test_device' script. I am sorry.</P>
- ")
- ];
-
- map device_names = $[
- "/dev/lp0" : _("First parallel port (/dev/lp0)"),
- "/dev/lp1" : _("Second parallel port (/dev/lp1)"),
- "/dev/lp2" : _("Third parallel port (/dev/lp2)"),
- "/dev/lp3" : _("Fourth parallel port (/dev/lp3)"),
- "/dev/usblp0" : _("First USB printer (/dev/usblp0)"),
- "/dev/usblp1" : _("Second USB printer (/dev/usblp1)"),
- "/dev/usblp2" : _("Third USB printer (/dev/usblp2)"),
- "/dev/usblp3" : _("Fourth USB printer (/dev/usblp3)")
- ];
- integer timeout_sec = 10;
- string test_text = "Hello, world\n\f";
-
- define TestDevice(string dev) ``{
- term contents =
- `VBox(`ReplacePoint(`id(`text_rep), `RichText(sformat(test_descr, timeout_sec))),
- `PushButton(`id(`test), _("&Run test")),
- `Label(_("Is the result as you expected?")));
-
- UI(`SetPrintconfContents(_("Testing the connection of the printer"),
- contents, help_text_test, false, _("&Yes")));
-
- any ret = nil;
- do {
- ret = UI(`UserInput());
-
- if (ret == `test) {
- integer tst = Shell(sformat("test_device '%1' '%2' '%3'",
- test_text, dev, timeout_sec));
-
- UI(`ReplaceWidget(`id(`text_rep), `RichText(lookup(test_messages, tst))));
- }
- } while (ret == `test);
-
- if (ret == `next) return true;
- return false;
- };
- /* The end of the definitions */
-
- term devicesel = `VStretch();
- if (type == "parallel" || type == "usb") {
- list|void devices = nil;
- if (type == "parallel")
- devices = SCR(`Read(.proc.parport.devices));
- if (type == "usb")
- devices = SCR(`Read(.proc.usblp.devices));
-
- if (devices == nil)
- devices = [];
- if (size(devices) == 0 && type == "parallel") {
- // CAUTION: "device" here means /dev/lp0, /dev/lp1, ...
- UI(`DisplayMessage(_("I have not found any parallel devices (/dev/lp?)! It seems\n
- that your parallel port is not properly configured.
- ")));
- devices = add(devices, "/dev/lp0");
- }
- if (size(devices) == 0 && type == "usb") {
- // CAUTION: "device" here means /dev/usblp0, /dev/usblp1, ...
- UI(`DisplayMessage(_("I have not found any USB devices (/dev/usblp?)! It seems\n
- that your USB bus is not properly configured.
- ")));
- devices = add(devices, "/dev/usblp0");
- }
-
- list device_val = [];
- foreach(`dev, devices, ``{
- device_val = add(device_val, `item(`id(dev), lookup(device_names, dev, dev),
- (dev == "/dev/lp0" || dev == "/dev/usblp0")));
- });
- devicesel = `VSquash(`SelectionBox(`id(`devicesel),
- _("Select connection:"), device_val));
- }
- /*if (type == "usb") {
- devicesel = `TextEntry(`id(`usbent), _("Enter USB device (e.g. /dev/usblp0):"));
- }*/
-
- term contents =
- `VBox(devicesel,
- `VStretch(),
- `Right(`PushButton(`id(`test), _("&Test"))));
-
- any ret = nil;
- string|void device = nil;
- do {
- UI(`SetPrintconfContents(_("Printer device"),
- contents, help_text, frst, _("&Next")));
- ret = UI(`UserInput());
-
- if (type == "parallel" || type == "usb")
- device = UI(`QueryWidget(`id(`devicesel), `CurrentItem));
- /*if (type == "usb")
- device = UI(`QueryWidget(`id(`usbent), `Value));*/
-
- if ((ret == `test) && (device != nil) && TestDevice(device))
- ret = `next;
- } while ((ret == `test) || (ret == `next && (device == nil || device == "")));
-
- if (ret == `next && type == "parallel")
- return add(printer, "parallel", $[ "device":device]);
- if (ret == `next && type == "usb")
- return add(printer, "usb", $[ "device":device]);
- /* TODO: if (ret == `next && type == "serial")
- return add(printer, "serial", $[ "device":device, "baudrate": <blah>]);*/
-
- return nil;
- }
-