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

  1. /* The Printer Configurator
  2.  * Printer's names
  3.  * Jan Holesovsky <kendy@suse.cz>, 2000
  4.  *
  5.  * $Id: printconf_spool_info.ycp,v 1.11.4.4 2000/03/23 16:22:10 gs Exp $
  6.  */
  7.  
  8. /* Arguments:
  9.      1st: (int)  number of the printer
  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 3
  20.   string help_text = UI(_("<P>A printer name is required for printing.</P>"));
  21. // Help, 2 of 3
  22.   help_text = help_text + UI(_("<P>Your first (default) printer will be called 'lp'. 
  23. You must provide a unique name for each additional printer. The 
  24. configuration program will assign additional names to each printer. Please 
  25. refer to the manual for more information.</P>
  26. "));
  27.  
  28.   list forbidden_names = Args(0);
  29.   map printer          = Args(1);
  30.   boolean frst         = Args(2);
  31.   
  32.   if (contains(forbidden_names, "lp"))
  33. // Help, 3 of 3
  34.       help_text = help_text + UI(_("<P>If you don't like the default name, you can change it using
  35. the <B>Change</B> button.</P>
  36. "));
  37.   
  38.   define NoviceContents(list names) ``{
  39.     string names_str = "";
  40.     string names_mono = "";
  41.     string names_raw = "";
  42.     string names_ascii = "";
  43.     foreach(`nam, names, ``{
  44.       if (names_str == "") {
  45.         names_str = nam;
  46.         if (nam == "lp") names_mono = "mono";
  47.         else names_mono = nam+"-mono";
  48.         if (nam == "lp") names_raw = "raw";
  49.         else names_raw = nam+"-raw";
  50.         if (nam == "lp") names_ascii = "ascii";
  51.         else names_ascii = nam+"-ascii";
  52.       } else {
  53.         // How to separete names? Let's have names x, y and z (in this order)
  54.     // %1, %2 will write x, y, z
  55.     // %2 - %1 will write z - y - x
  56.         names_str = sformat(UI(_("%1, %2")), names_str, nam);
  57.         names_mono = sformat(UI(_("%1, %2")), names_mono, nam+"-mono");
  58.         names_raw = sformat(UI(_("%1, %2")), names_raw, nam+"-raw");
  59.         names_ascii = sformat(UI(_("%1, %2")), names_ascii, nam+"-ascii");
  60.       }
  61.     });
  62.  
  63.     term has_button = `VStretch();
  64.     if (select(names, 0) != "lp")
  65.       // Button that switches between showing and changing the name
  66.       has_button = `Right(`PushButton(`id(`expert), _("&Change")));
  67.  
  68.     return
  69.       `VBox(
  70.         // This name the user should use when printing PostScript (and some 
  71.     // other things - pictures, dvi). This is the usual use.
  72.     `Left(`Label(_("Name for normal printing:"))),
  73.     `Label(names_str),
  74.     /*`Left(`Label(sformat(msage, UI(_("raw")), ""))),
  75.     `Label(names_raw),*/
  76.     // This name can be used when printing ascii files. It is faster.
  77.     `Left(`Label(_("Name for ascii printing:"))),
  78.     `Label(names_ascii),
  79.     /*`Left(`Label(sformat(msage, UI(_("mono")), UI(_(" (color printers only!)"))))),
  80.     `Label(names_mono),*/
  81.     `VStretch(),
  82.         has_button
  83.       );
  84.   };
  85.   /* The end of the definitions */
  86.   
  87.   list|void names = lookup(printer, "names");
  88.   if ((names == nil) || (size(names) == 0)) {
  89.     if (!contains(forbidden_names, "lp"))
  90.       names = [ "lp" ];
  91.     else {
  92.       integer no = 1;
  93.       while (contains(forbidden_names, sformat("printer%1", no)))
  94.         no = no+1;
  95.       names = [ sformat("printer%1", no) ];
  96.     }
  97.   }
  98.   
  99.   UI(`SetPrintconfContents(_("Printer's name"),
  100.       NoviceContents(names),
  101.       help_text, frst, _("&Next")));
  102.   
  103.   any ret = nil;
  104.   boolean expert = false;
  105.   repeat {
  106.     ret = UI(`UserInput());
  107.     
  108.     if (expert) {
  109.       string name = UI(`QueryWidget(`id(`pr_name), `Value));
  110.       if (size(name) > 0 && 
  111.         size(name) < 20 &&
  112.     ! contains(union(forbidden_names, [ "lp", "ascii", "raw", "remote" ]), name) &&
  113.         name == filterchars(name,
  114.                 "_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")) {
  115.         names = [ name ];
  116.       } else {
  117.         UI(`DisplayMessage(sformat(UI(_("Invalid name! The name can be up to 20 characters long and you can only use \n
  118. the characters 0..9, A..Z, a..z and _. Additionally, you cannot use\n
  119. the names 'lp', 'ascii', 'raw' and 'remote' because of their special 
  120. function.\n
  121. The name must not be used for another printer.
  122. ")))));
  123.         ret = nil;
  124.       }
  125.     }
  126.     
  127.     if (ret == `expert) {
  128.       /* Not for 6.4. Dimensed for 7.0...
  129.       term expert_contents =
  130.         `VBox(`VSquash(`HBox(`TextEntry(`id(`pr_name), _("Name:")),
  131.                              `Bottom(`PushButton(`id(`new_one), _("&Add"))))),
  132.               `HBox(`ReplacePoint(`id(`namessel_rep),
  133.                       `SelectionBox(`id(`names_sel), `opt(`notify),
  134.                     _("Names of this printer:"), names)),
  135.                     `PushButton(`id(`delete), _("&Delete"))),
  136.           `Right(`PushButton(`id(`novice), _("&Show")))
  137.         );
  138.       */
  139.       expert = true;
  140.       term expert_contents =
  141.         `HBox(`TextEntry(`id(`pr_name),
  142.             _("Name, you want to use for your printer:"), select(names, 0)),
  143.               // Button that switches between showing and changing the name
  144.           `Bottom(`PushButton(`id(`novice), _("&Show")))
  145.         );
  146.     
  147.       // Name of the whole dialog.
  148.       UI(`SetPrintconfContents(_("Printer's name"),
  149.           expert_contents, help_text, frst, _("&Next")));
  150.     }
  151.     if (ret == `novice) {
  152.       expert = false;
  153.       
  154.       UI(`SetPrintconfContents(_("Printer's name"),
  155.           NoviceContents(names),
  156.           help_text, frst, _("&Next")));
  157.     }
  158.  
  159.     /* Not for 6.4. Dimensed for 7.0...
  160.     if (ret == `names_sel) {
  161.       string|void nam = UI(`QueryWidget(`id(`names_sel), `CurrentItem));  
  162.       if (nam != nil)
  163.         UI(`ChangeWidget(`id(`pr_name), `Value, nam));
  164.     }
  165.     if (ret == `new_one) {
  166.       string name = UI(`QueryWidget(`id(`pr_name), `Value));
  167.       name = filterchars(name, "_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
  168.       if ((size(name) > 0) && !contains(names, name)) {
  169.         if (size(names) > 0)
  170.           UI(`DisplayMessage(sformat(UI(_("I am sorry. For now you can use just one name for a printer.
  171. Please, delete the previously entered name (%1) first.")), select(names, 0))));
  172.     else if (contains(forbidden_names, name))
  173.           UI(`DisplayMessage(sformat(UI(_("Name '%1' is already used by another
  174. printer. Please, enter some other one.")), name)));
  175.     else {
  176.           names = add(names, name);
  177.           UI(`ReplaceWidget(`id(`namessel_rep),
  178.             `SelectionBox(`id(`names_sel), `opt(`notify), _("Names of this printer:"), names)));
  179.     }
  180.       }
  181.     }
  182.     if (ret == `delete) {
  183.       string|void del_name = UI(`QueryWidget(`id(`names_sel), `CurrentItem));  
  184.       if (del_name != nil) {
  185.         names = filter(`name, names, ``(name != del_name));
  186.         UI(`ReplaceWidget(`id(`namessel_rep),
  187.           `SelectionBox(`id(`names_sel), `opt(`notify), _("Names of this printer:"), names)));
  188.       }
  189.     }*/
  190.   } until ((ret == `back) || ((ret == `next) && (size(names) > 0)));
  191.   
  192.   if (ret == `next) {
  193.     return add(printer, "names", names);
  194.   }
  195.   return nil;
  196. }
  197.