CAPS Universe documentation  1.0.4
All you need to know to be successful
hl-input-tray.h
Go to the documentation of this file.
1/*
2 * SPDX-License-Identifier: GPL-2.0-or-later
3 *
4 * (c) 2020 Juergen Borleis <projects@caps-printing.org>
5 *
6 * This library is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 */
11
20#if 0
21/*
22 * "AUTO" always means autoselect between TRAY1 and MANUAL
23 *
24 * AUTO:
25 * @PJL SET SOURCETRAY = AUTO <-- the printer selects the source from the given info
26 * @PJL SET LPARM:PCL PAPER = <format-name> <-- paper format to print to
27 * @PJL SET TRAY1SIZE = <format-name> <-- paper format loaded in the tray
28 * @PJL SET MANUALFEED = ON <-- printer is allowed to select the manual feed if the format to print to isn't in the tray
29 *
30 * TRAY1:
31 * @PJL SET SOURCETRAY = TRAY1 <-- the printer is forced to use the paper from the tray
32 * @PJL SET LPARM:PCL PAPER = <format-name> <-- paper format to print to
33 * @PJL SET TRAY1SIZE = <format-name> <-- paper format loaded in the tray
34 * @PJL SET MANUALFEED = OFF <-- printer isn't allowed to select the source itself
35 *
36 * MANUAL:
37 * @PJL SET SOURCETRAY = AUTO <-- the printer selects the source from the given info
38 * @PJL SET LPARM:PCL PAPER = <format-name> <-- paper format to print to
39 * @PJL SET TRAY1SIZE = <format-name> <-- paper format loaded in the tray
40 * @PJL SET MANUALFEED = ON <-- printer is allowed to select the manual feed if the format to print to isn't in the tray
41 * FIXME How to force the manual feed if the same paper format is loaded in the tray?
42 *
43 * Ist MANUALFEED nur, um den manuellen Einzug "freizuschalten"? Dann wären es vermutlich nur diese
44 * zwei Kombinationen:
45 *
46 * TRAY1:
47 * @PJL SET SOURCETRAY = TRAY1 <-- the printer is forced to use the paper from the tray
48 * @PJL SET LPARM:PCL PAPER = <format-name> <-- paper format to print to
49 * @PJL SET TRAY1SIZE = <format-name> <-- paper format loaded in the tray
50 * @PJL SET MANUALFEED = OFF <-- printer isn't allowed to select the source itself
51 *
52 * MANUAL:
53 * @PJL SET SOURCETRAY = AUTO <-- the printer selects the source from the given info
54 * @PJL SET LPARM:PCL PAPER = <format-name> <-- paper format to print to
55 * @PJL SET TRAY1SIZE = <format-name> <-- paper format loaded in the tray
56 * @PJL SET MANUALFEED = ON <-- printer is allowed to select the manual feed if the format to print to isn't in the tray
57 *
58 * Es ist natürlich auch möglich, die erste Seite manuell einzuziehen und die weiteren aus dem Papierfach
59 * (das bietet der Windows-Treiber an). -> dann müsste das vor jeder Seite geändert werden.
60 *
61 * Der Treiber hier im Original sendet auch MANUAL als SOURCETRAY. Vielleicht stimmt das ja auch und
62 * die ausgelesenen Daten aus dem Drucker stimmen an der Stelle nicht.
63 */
64static const struct caps_ppd_selection_entry hl20_input_tray_selections[] = {
65 { .option = "Auto", .description = NLS_("Auto Select"), .value = "AUTO", },
66 { .option = "TRAY", .description = NLS_("Tray"), .value = "TRAY1", },
67 { .option = "MANUAL", .description = NLS_("Manual Feed"), .value = "MANUAL", },
68};
69
70static struct caps_ppd_selection hl20_input_tray_selection = {
72 .option = "InputSlot",
73 .description = NLS_("Paper Source"),
74 .entry_count = ARRAY_SIZE(hl20_input_tray_selections),
75 .default_entry = 0,
76 .entries = hl20_input_tray_selections,
77};
78
86static __nonnull() void hl20_adapt_input_tray(struct brother_doc *info)
87{
88 static struct caps_ppd_option one_type_only[] = {
89 { .keyword = "DefaultInputSlot", .value = NULL, },
90 { .keyword = "InputSlot", .name = NULL, .description = NLS_("Paper Source"), .value = NULL, },
91 };
92 const char *input_slot, *default_input_slot;
93 ssize_t idx;
94
95 input_slot = hl_setup_value_get(info->instance, "paper", "type");
96 if (input_slot != NULL) {
97 /* the user has pre-selected one paper type in its INI, use it as the default */
98
99 /* user has selected one, validate it */
100 idx = hl_selection_entry_get(hl20_paper_type_selections, ARRAY_SIZE(hl20_paper_type_selections), paper_type);
101 if (idx < 0) {
102 /* user's selection is invalid, fall back to the default */
105 caps_print_warn(_("Unknown paper type '%s', falling back to '%s'\n"), paper_type, hl20_paper_type_selections[idx].option);
106 } else {
107 /* user's selection is valid, use it */
108 caps_print_noisy(_("Using predefined paper type '%s'\n"), paper_type);
109 }
110 one_type_only[0].value = hl20_paper_type_selections[idx].option;
111 one_type_only[1].name = hl20_paper_type_selections[idx].option;
112 one_type_only[1].value = hl20_paper_type_selections[idx].value;
113
114 /* add (invisible) options instead of the (useless) selection for this case */
115 hl_options_add(&hl20_options, ARRAY_SIZE(one_type_only), one_type_only);
116 return;
117 }
118
119 /* no predefined paper type, thus, we add the full selection to the PPD */
120 hl_feature_selection_add(&hl20_featuresX, &hl20_media_type_selection);
121
122 /* if we have the list of paper types, we need its default as well */
123 default_paper_type = hl_setup_value_get(info->instance, "paper", "default_type");
124 if (default_paper_type == NULL) {
125 idx = 0; /* keep "PLAIN" as the default */
126 goto fallback;
127 }
128
129 /* user has selected one, validate it and get its index */
130 idx = hl_selection_entry_get(hl20_paper_type_selections, ARRAY_SIZE(hl20_paper_type_selections), default_paper_type);
131 if (idx < 0) {
132 caps_print_warn(_("Unknown paper type '%s', falling back to '%s'\n"), default_paper_type, hl20_paper_type_selections[0].option);
133 idx = 0; /* keep "PLAIN" as the default */
134 }
135
136fallback:
137 hl20_media_type_selection.default_entry = (size_t)idx;
138}
139#endif
#define __nonnull(params)
Definition: libcapsbase.h:84
#define caps_print_noisy(fmt,...)
Definition: libcapsbase.h:284
#define caps_print_warn(fmt,...)
Definition: libcapsbase.h:260
#define caps_assert(expr)
Assert the given expression is true, else terminate the program.
Definition: libcapsbase.h:602
@ LIBCAPS_OT_PICKONE
Definition: libcapsppd.h:282
void hl_options_add(struct ppd_option_add *o, size_t entries, struct caps_ppd_option option[entries])
Definition: hl-series.c:44
ssize_t hl_selection_entry_get(size_t selection_cnt, const struct caps_ppd_selection_entry selection_list[selection_cnt], const char *entry)
Definition: hl-series.c:55
void hl_feature_selection_add(struct ppd_feature_add *f, struct caps_ppd_selection *s)
Definition: hl-series.c:36
#define NLS_(string)
National Language Support related.
Definition: libcapsbase-local.h:61
#define ARRAY_SIZE(x)
Definition: libcapsbase-local.h:37
#define _(string)
National Language Support related.
Definition: libcapsbase-local.h:54
static struct caps_ppd_selection drv_spl2_media_type_selection
Definition: samsung-spl2-ml-1640-2240.c:141
Structure to keep the information read-in from an external PPD files.
Definition: libcapsppd-api.h:151
const char * keyword
Definition: libcapsppd-api.h:152
const char * value
Definition: libcapsppd-api.h:158
const char * name
Definition: libcapsppd-api.h:154
Definition of one 'option' entry a PPD selection provides.
Definition: libcapsppd.h:292
const char * option
Definition: libcapsppd.h:293
Description of an OpenUI/CloseUI PPD selection.
Definition: libcapsppd.h:303
enum caps_ppd_option_type option_type
Definition: libcapsppd.h:304
size_t default_entry
Definition: libcapsppd.h:308