home *** CD-ROM | disk | FTP | other *** search
- /* The Printer Configurator
- * Asking the manufacuturer and the model of the printer
- * Jan Holesovsky <kendy@suse.cz>, 2000
- *
- * $Id: printconf_manuf_model.ycp,v 1.2.4.3 2000/03/23 16:22:10 gs Exp $
- */
-
- /* Arguments:
- 1st: (list) the printer database
- 2nd: (map) the printer record
- 3rd: (bool) am I the first dialog (when configuring?)
-
- Returns:
- (map) the printer record if successful
- (void) nil otherwise
- */
-
- {
- // Help, 1 of 2
- string help_text = UI(_("<P>Please choose the manufacturer and model of your printer.</P>"));
- // Help, 2 of 2
- help_text = help_text + UI(_("<P>If you cannot find your printer in this database, see the <B>Generic
- printers</B> section. There you can select from a list of common printing
- protocols. If you do not know which protocol your printer uses,
- consult the printer's manual or contact the manufacturer's technical
- support.</P>
- "));
-
- list pr_database = Args(0);
- map printer = Args(1);
- boolean frst = Args(2);
- boolean reverse = Args(3);
-
- /* Skip this dialog if everything was autodetected */
- if (!reverse &&
- lookup(printer, "autodetected") == true &&
- size(lookup(printer, "manufacturer")) > 0 &&
- size(lookup(printer, "model")) > 0 &&
- lookup(printer, "ps2printer") != nil)
- return printer;
-
- define ModelValues(map manuf_rec, string|void model) ``{
- /*list val = [];
- list prns = lookup(manuf_rec, "printers");
- foreach(`prn, prns, ``{
- string model_nam = lookup(prn, "name");
- val = add(val, `item(`id(prn), model_nam, model_nam == model));
- });
- return val;*/
- list prns = lookup(manuf_rec, "printers");
- return
- maplist(`prn, prns, ``{
- string model_nam = lookup(prn, "name");
- return `item(`id(prn), model_nam, model_nam == model);
- });
- };
- /* The end of the definitions */
-
- string|void manuf = lookup(printer, "manufacturer");
- string|void model = lookup(printer, "model");
- map|void manuf_rec = nil;
- map|void ps2printer = nil;
-
- /*list manuf_val = [];
- foreach(`man, pr_database, ``{
- string manuf_nam = lookup(man, "name");
- if (manuf_nam == manuf)
- manuf_rec = man;
- manuf_val = add(manuf_val, `item(`id(man), manuf_nam, manuf_nam == manuf));
- });*/
- list manuf_val =
- maplist(`man, pr_database, ``{
- string manuf_nam = lookup(man, "name");
- if (manuf_nam == manuf)
- manuf_rec = man;
- return `item(`id(man), manuf_nam, manuf_nam == manuf);
- });
-
- term manufsel = `SelectionBox(`id(`manufsel), `opt(`notify),
- _("Select manufacturer:"), manuf_val);
-
- list model_val = [];
- if (manuf_rec != nil)
- model_val = ModelValues(manuf_rec, model);
- term modelsel = `SelectionBox(`id(`modelsel),
- _("Select model:"), model_val);
-
- term contents =
- `HBox(manufsel,
- `ReplacePoint(`id(`modelsel_rep), modelsel));
-
- UI(`SetPrintconfContents(_("Manufacturer and model of the printer"),
- contents, help_text, frst, _("&Next")));
-
- any ret = nil;
- repeat {
- ret = UI(`UserInput());
-
- if (ret == `manufsel) {
- manuf_rec = UI(`QueryWidget(`id(`manufsel), `CurrentItem));
- if (manuf_rec != nil) {
- model = nil;
- manuf = lookup(manuf_rec, "name");
- list prns = lookup(manuf_rec, "printers");
-
- model_val = ModelValues(manuf_rec, nil);
- modelsel = `SelectionBox(`id(`modelsel),
- _("Select model:"), model_val);
-
- UI(`ReplaceWidget(`id(`modelsel_rep), modelsel));
- }
- } else {
- map|void model_rec = UI(`QueryWidget(`id(`modelsel), `CurrentItem));
- if (model_rec != nil) {
- model = lookup(model_rec, "name");
- ps2printer = lookup(model_rec, "ps2printer");
- }
- }
- } until ((ret == `back) || ((ret == `next) && (manuf != nil) && (model != nil)));
-
- if (ret == `next)
- return add(add(add(printer, "manufacturer", manuf),
- "model", model),
- "ps2printer", ps2printer);
- return nil;
- }
-