home *** CD-ROM | disk | FTP | other *** search
- /* The Printer Configurator
- * Printer's names
- * Jan Holesovsky <kendy@suse.cz>, 2000
- *
- * $Id: printconf_spool_info.ycp,v 1.11.4.4 2000/03/23 16:22:10 gs Exp $
- */
-
- /* Arguments:
- 1st: (int) number of the printer
- 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 3
- string help_text = UI(_("<P>A printer name is required for printing.</P>"));
- // Help, 2 of 3
- help_text = help_text + UI(_("<P>Your first (default) printer will be called 'lp'.
- You must provide a unique name for each additional printer. The
- configuration program will assign additional names to each printer. Please
- refer to the manual for more information.</P>
- "));
-
- list forbidden_names = Args(0);
- map printer = Args(1);
- boolean frst = Args(2);
-
- if (contains(forbidden_names, "lp"))
- // Help, 3 of 3
- help_text = help_text + UI(_("<P>If you don't like the default name, you can change it using
- the <B>Change</B> button.</P>
- "));
-
- define NoviceContents(list names) ``{
- string names_str = "";
- string names_mono = "";
- string names_raw = "";
- string names_ascii = "";
- foreach(`nam, names, ``{
- if (names_str == "") {
- names_str = nam;
- if (nam == "lp") names_mono = "mono";
- else names_mono = nam+"-mono";
- if (nam == "lp") names_raw = "raw";
- else names_raw = nam+"-raw";
- if (nam == "lp") names_ascii = "ascii";
- else names_ascii = nam+"-ascii";
- } else {
- // How to separete names? Let's have names x, y and z (in this order)
- // %1, %2 will write x, y, z
- // %2 - %1 will write z - y - x
- names_str = sformat(UI(_("%1, %2")), names_str, nam);
- names_mono = sformat(UI(_("%1, %2")), names_mono, nam+"-mono");
- names_raw = sformat(UI(_("%1, %2")), names_raw, nam+"-raw");
- names_ascii = sformat(UI(_("%1, %2")), names_ascii, nam+"-ascii");
- }
- });
-
- term has_button = `VStretch();
- if (select(names, 0) != "lp")
- // Button that switches between showing and changing the name
- has_button = `Right(`PushButton(`id(`expert), _("&Change")));
-
- return
- `VBox(
- // This name the user should use when printing PostScript (and some
- // other things - pictures, dvi). This is the usual use.
- `Left(`Label(_("Name for normal printing:"))),
- `Label(names_str),
- /*`Left(`Label(sformat(msage, UI(_("raw")), ""))),
- `Label(names_raw),*/
- // This name can be used when printing ascii files. It is faster.
- `Left(`Label(_("Name for ascii printing:"))),
- `Label(names_ascii),
- /*`Left(`Label(sformat(msage, UI(_("mono")), UI(_(" (color printers only!)"))))),
- `Label(names_mono),*/
- `VStretch(),
- has_button
- );
- };
- /* The end of the definitions */
-
- list|void names = lookup(printer, "names");
- if ((names == nil) || (size(names) == 0)) {
- if (!contains(forbidden_names, "lp"))
- names = [ "lp" ];
- else {
- integer no = 1;
- while (contains(forbidden_names, sformat("printer%1", no)))
- no = no+1;
- names = [ sformat("printer%1", no) ];
- }
- }
-
- UI(`SetPrintconfContents(_("Printer's name"),
- NoviceContents(names),
- help_text, frst, _("&Next")));
-
- any ret = nil;
- boolean expert = false;
- repeat {
- ret = UI(`UserInput());
-
- if (expert) {
- string name = UI(`QueryWidget(`id(`pr_name), `Value));
- if (size(name) > 0 &&
- size(name) < 20 &&
- ! contains(union(forbidden_names, [ "lp", "ascii", "raw", "remote" ]), name) &&
- name == filterchars(name,
- "_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")) {
- names = [ name ];
- } else {
- UI(`DisplayMessage(sformat(UI(_("Invalid name! The name can be up to 20 characters long and you can only use \n
- the characters 0..9, A..Z, a..z and _. Additionally, you cannot use\n
- the names 'lp', 'ascii', 'raw' and 'remote' because of their special
- function.\n
- The name must not be used for another printer.
- ")))));
- ret = nil;
- }
- }
-
- if (ret == `expert) {
- /* Not for 6.4. Dimensed for 7.0...
- term expert_contents =
- `VBox(`VSquash(`HBox(`TextEntry(`id(`pr_name), _("Name:")),
- `Bottom(`PushButton(`id(`new_one), _("&Add"))))),
- `HBox(`ReplacePoint(`id(`namessel_rep),
- `SelectionBox(`id(`names_sel), `opt(`notify),
- _("Names of this printer:"), names)),
- `PushButton(`id(`delete), _("&Delete"))),
- `Right(`PushButton(`id(`novice), _("&Show")))
- );
- */
- expert = true;
- term expert_contents =
- `HBox(`TextEntry(`id(`pr_name),
- _("Name, you want to use for your printer:"), select(names, 0)),
- // Button that switches between showing and changing the name
- `Bottom(`PushButton(`id(`novice), _("&Show")))
- );
-
- // Name of the whole dialog.
- UI(`SetPrintconfContents(_("Printer's name"),
- expert_contents, help_text, frst, _("&Next")));
- }
- if (ret == `novice) {
- expert = false;
-
- UI(`SetPrintconfContents(_("Printer's name"),
- NoviceContents(names),
- help_text, frst, _("&Next")));
- }
-
- /* Not for 6.4. Dimensed for 7.0...
- if (ret == `names_sel) {
- string|void nam = UI(`QueryWidget(`id(`names_sel), `CurrentItem));
- if (nam != nil)
- UI(`ChangeWidget(`id(`pr_name), `Value, nam));
- }
- if (ret == `new_one) {
- string name = UI(`QueryWidget(`id(`pr_name), `Value));
- name = filterchars(name, "_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
- if ((size(name) > 0) && !contains(names, name)) {
- if (size(names) > 0)
- UI(`DisplayMessage(sformat(UI(_("I am sorry. For now you can use just one name for a printer.
- Please, delete the previously entered name (%1) first.")), select(names, 0))));
- else if (contains(forbidden_names, name))
- UI(`DisplayMessage(sformat(UI(_("Name '%1' is already used by another
- printer. Please, enter some other one.")), name)));
- else {
- names = add(names, name);
- UI(`ReplaceWidget(`id(`namessel_rep),
- `SelectionBox(`id(`names_sel), `opt(`notify), _("Names of this printer:"), names)));
- }
- }
- }
- if (ret == `delete) {
- string|void del_name = UI(`QueryWidget(`id(`names_sel), `CurrentItem));
- if (del_name != nil) {
- names = filter(`name, names, ``(name != del_name));
- UI(`ReplaceWidget(`id(`namessel_rep),
- `SelectionBox(`id(`names_sel), `opt(`notify), _("Names of this printer:"), names)));
- }
- }*/
- } until ((ret == `back) || ((ret == `next) && (size(names) > 0)));
-
- if (ret == `next) {
- return add(printer, "names", names);
- }
- return nil;
- }
-