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

  1. /* The Printer Configurator
  2.  * Asking the manufacuturer and the model of the printer
  3.  * Jan Holesovsky <kendy@suse.cz>, 2000
  4.  *
  5.  * $Id: printconf_manuf_model.ycp,v 1.2.4.3 2000/03/23 16:22:10 gs Exp $
  6.  */
  7.  
  8. /* Arguments:
  9.      1st: (list) the printer database
  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. // Help, 1 of 2
  20.   string help_text = UI(_("<P>Please choose the manufacturer and model of your printer.</P>"));
  21. // Help, 2 of 2
  22.   help_text = help_text + UI(_("<P>If you cannot find your printer in this database, see the <B>Generic
  23. printers</B> section. There you can select from a list of common printing
  24. protocols. If you do not know which protocol your printer uses,
  25. consult the printer's manual or contact the manufacturer's technical 
  26. support.</P>
  27. "));
  28.  
  29.   list pr_database = Args(0);
  30.   map printer      = Args(1);
  31.   boolean frst     = Args(2);
  32.   boolean reverse  = Args(3);
  33.  
  34.   /* Skip this dialog if everything was autodetected */
  35.   if (!reverse &&
  36.       lookup(printer, "autodetected") == true &&
  37.       size(lookup(printer, "manufacturer")) > 0 &&
  38.       size(lookup(printer, "model")) > 0 &&
  39.       lookup(printer, "ps2printer") != nil)
  40.     return printer;
  41.   
  42.   define ModelValues(map manuf_rec, string|void model) ``{
  43.     /*list val = [];
  44.     list prns = lookup(manuf_rec, "printers");
  45.     foreach(`prn, prns, ``{
  46.       string model_nam = lookup(prn, "name");
  47.       val = add(val, `item(`id(prn), model_nam, model_nam == model));
  48.     }); 
  49.     return val;*/
  50.     list prns = lookup(manuf_rec, "printers");
  51.     return
  52.       maplist(`prn, prns, ``{
  53.         string model_nam = lookup(prn, "name");
  54.         return `item(`id(prn), model_nam, model_nam == model);
  55.       }); 
  56.   };
  57.   /* The end of the definitions */
  58.  
  59.   string|void manuf = lookup(printer, "manufacturer");
  60.   string|void model = lookup(printer, "model");
  61.   map|void manuf_rec = nil;
  62.   map|void ps2printer = nil;
  63.   
  64.   /*list manuf_val = [];
  65.   foreach(`man, pr_database, ``{
  66.     string manuf_nam = lookup(man, "name");
  67.     if (manuf_nam == manuf)
  68.       manuf_rec = man;
  69.     manuf_val = add(manuf_val, `item(`id(man), manuf_nam, manuf_nam == manuf));
  70.   });*/
  71.   list manuf_val = 
  72.     maplist(`man, pr_database, ``{
  73.       string manuf_nam = lookup(man, "name");
  74.       if (manuf_nam == manuf)
  75.         manuf_rec = man;
  76.       return `item(`id(man), manuf_nam, manuf_nam == manuf);
  77.     });
  78.   
  79.   term manufsel = `SelectionBox(`id(`manufsel), `opt(`notify),
  80.     _("Select manufacturer:"), manuf_val);
  81.   
  82.   list model_val = [];
  83.   if (manuf_rec != nil)
  84.     model_val = ModelValues(manuf_rec, model);
  85.   term modelsel = `SelectionBox(`id(`modelsel),
  86.     _("Select model:"), model_val);
  87.     
  88.   term contents = 
  89.     `HBox(manufsel,
  90.           `ReplacePoint(`id(`modelsel_rep), modelsel));
  91.  
  92.   UI(`SetPrintconfContents(_("Manufacturer and model of the printer"),
  93.       contents, help_text, frst, _("&Next")));
  94.  
  95.   any ret = nil;
  96.   repeat {
  97.     ret = UI(`UserInput());
  98.  
  99.     if (ret == `manufsel) {
  100.       manuf_rec = UI(`QueryWidget(`id(`manufsel), `CurrentItem));
  101.       if (manuf_rec != nil) {
  102.         model = nil;
  103.         manuf = lookup(manuf_rec, "name");
  104.         list prns = lookup(manuf_rec, "printers");
  105.         
  106.         model_val = ModelValues(manuf_rec, nil);
  107.         modelsel = `SelectionBox(`id(`modelsel),
  108.           _("Select model:"), model_val);
  109.         
  110.         UI(`ReplaceWidget(`id(`modelsel_rep), modelsel));
  111.       }
  112.     } else {
  113.       map|void model_rec = UI(`QueryWidget(`id(`modelsel), `CurrentItem));
  114.       if (model_rec != nil) {
  115.         model = lookup(model_rec, "name");
  116.         ps2printer = lookup(model_rec, "ps2printer");
  117.       }
  118.     }
  119.   } until ((ret == `back) || ((ret == `next) && (manuf != nil) && (model != nil)));
  120.   
  121.   if (ret == `next)
  122.     return add(add(add(printer, "manufacturer", manuf),
  123.                                 "model", model),
  124.                           "ps2printer", ps2printer);
  125.   return nil;
  126. }
  127.