Debian Codegraph @

src/main/generic-options.c

raw symbols SCIP
1 /*
2 *
3 * Copyright 2003 Robert Krawitz ([email protected])
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation; either version 2 of the License, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
19 #ifdef HAVE_CONFIG_H
20 #include <config.h>
21 #endif
22 #include <gutenprint/gutenprint.h>
23 #include "gutenprint-internal.h"
24 #include <gutenprint/gutenprint-intl-internal.h>
25 #include "generic-options.h"
26 #include <string.h>
27 #include <limits.h>
28
29 static const stpi_quality_t standard_qualities[] =
30 {
31 { "FastEconomy", N_("Fast Economy"), 0 },
32 { "Economy", N_("Economy"), 1 },
33 { "Draft", N_("Draft"), 3 },
34 { "Standard", N_("Standard"), 5 },
35 { "High", N_("High"), 6 },
36 { "Photo", N_("Photo"), 7 },
37 { "HighPhoto", N_("Super Photo"), 8 },
38 { "UltraPhoto", N_("Ultra Photo"), 9 },
39 { "Best", N_("Best"), 10 },
40 };
41
42 static const stpi_image_type_t standard_image_types[] =
43 {
44 { "Text", N_("Text") },
45 { "Graphics", N_("Graphics") },
46 { "TextGraphics", N_("Mixed Text and Graphics") },
47 { "Photo", N_("Photograph") },
48 { "LineArt", N_("Line Art") },
49 };
50
51 static const stpi_job_mode_t standard_job_modes[] =
52 {
53 { "Page", N_("Page") },
54 { "Job", N_("Job") },
55 };
56
57 static const stp_parameter_t the_parameters[] =
58 {
59 {
60 "Quality", N_("Print Quality"), "Color=Yes,Category=Basic Output Adjustment",
61 N_("Print Quality"),
62 STP_PARAMETER_TYPE_STRING_LIST, STP_PARAMETER_CLASS_FEATURE,
63 STP_PARAMETER_LEVEL_BASIC, 1, 1, STP_CHANNEL_NONE, 0, 0
64 },
65 {
66 "ImageType", N_("Image Type"), "Color=Yes,Category=Basic Image Adjustment",
67 N_("Type of image being printed"),
68 STP_PARAMETER_TYPE_STRING_LIST, STP_PARAMETER_CLASS_OUTPUT,
69 STP_PARAMETER_LEVEL_BASIC, 1, 1, STP_CHANNEL_NONE, 0, 0
70 },
71 {
72 "JobMode", N_("Job Mode"), "Color=No,Category=Job Mode",
73 N_("Job vs. page mode"),
74 STP_PARAMETER_TYPE_STRING_LIST, STP_PARAMETER_CLASS_CORE,
75 STP_PARAMETER_LEVEL_BASIC, 1, 1, STP_CHANNEL_NONE, 0, 0
76 },
77 {
78 "PageNumber", N_("Page Number"), "Color=No,Category=Job Mode",
79 N_("Page number"),
80 STP_PARAMETER_TYPE_INT, STP_PARAMETER_CLASS_CORE,
81 STP_PARAMETER_LEVEL_BASIC, 1, 1, STP_CHANNEL_NONE, 1, 0
82 },
83 {
84 "NumCopies", N_("Number of Copies"), "Color=No,Category=Job Mode",
85 N_("Number of Copies"),
86 STP_PARAMETER_TYPE_INT, STP_PARAMETER_CLASS_CORE,
87 STP_PARAMETER_LEVEL_INTERNAL, 1, 0, STP_CHANNEL_NONE, 1, 0
88 },
89 {
90 "Collate", N_("Collate the Job"), "Color=No,Category=Job Mode",
91 N_("Collate the Job"),
92 STP_PARAMETER_TYPE_BOOLEAN, STP_PARAMETER_CLASS_CORE,
93 STP_PARAMETER_LEVEL_INTERNAL, 1, 0, STP_CHANNEL_NONE, 1, 0
94 },
95 };
96
97 static const int the_parameter_count =
98 sizeof(the_parameters) / sizeof(const stp_parameter_t);
99
100 int
101 stpi_get_qualities_count(void)
102 {
103 return sizeof(standard_qualities) / sizeof(stpi_quality_t);
104 }
105
106 const stpi_quality_t *
107 stpi_get_quality_by_index(int idx)
108 {
109 if (idx < 0 || idx >= stpi_get_qualities_count())
110 return NULL;
111 else
112 return &(standard_qualities[idx]);
113 }
114
115 const stpi_quality_t *
116 stpi_get_quality_by_name(const char *quality)
117 {
118 int i;
119 if (!quality)
120 return NULL;
121 for (i = 0; i < stpi_get_qualities_count(); i++)
122 {
123 const stpi_quality_t *qual = stpi_get_quality_by_index(i);
124 if (strcmp(quality, qual->name) == 0)
125 return qual;
126 }
127 return NULL;
128 }
129
130 int
131 stpi_get_image_types_count(void)
132 {
133 return sizeof(standard_image_types) / sizeof(stpi_image_type_t);
134 }
135
136 const stpi_image_type_t *
137 stpi_get_image_type_by_index(int idx)
138 {
139 if (idx < 0 || idx >= stpi_get_image_types_count())
140 return NULL;
141 else
142 return &(standard_image_types[idx]);
143 }
144
145 const stpi_image_type_t *
146 stpi_get_image_type_by_name(const char *image_type)
147 {
148 int i;
149 if (!image_type)
150 return NULL;
151 for (i = 0; i < stpi_get_image_types_count(); i++)
152 {
153 const stpi_image_type_t *itype = stpi_get_image_type_by_index(i);
154 if (strcmp(image_type, itype->name) == 0)
155 return itype;
156 }
157 return NULL;
158 }
159
160 int
161 stpi_get_job_modes_count(void)
162 {
163 return sizeof(standard_job_modes) / sizeof(stpi_job_mode_t);
164 }
165
166 const stpi_job_mode_t *
167 stpi_get_job_mode_by_index(int idx)
168 {
169 if (idx < 0 || idx >= stpi_get_job_modes_count())
170 return NULL;
171 else
172 return &(standard_job_modes[idx]);
173 }
174
175 const stpi_job_mode_t *
176 stpi_get_job_mode_by_name(const char *job_mode)
177 {
178 int i;
179 if (!job_mode)
180 return NULL;
181 for (i = 0; i < stpi_get_job_modes_count(); i++)
182 {
183 const stpi_job_mode_t *itype = stpi_get_job_mode_by_index(i);
184 if (strcmp(job_mode, itype->name) == 0)
185 return itype;
186 }
187 return NULL;
188 }
189
190 stp_parameter_list_t
191 stp_list_generic_parameters(const stp_vars_t *v)
192 {
193 stp_parameter_list_t *ret = stp_parameter_list_create();
194 int i;
195 (void)v;
196 for (i = 0; i < the_parameter_count; i++)
197 stp_parameter_list_add_param(ret, &(the_parameters[i]));
198 return ret;
199 }
200
201 void
202 stpi_describe_generic_parameter(const stp_vars_t *v, const char *name,
203 stp_parameter_t *description)
204 {
205 int i;
206 (void)v;
207
208 description->p_type = STP_PARAMETER_TYPE_INVALID;
209 if (name == NULL)
210 return;
211
212 for (i = 0; i < the_parameter_count; i++)
213 if (strcmp(name, the_parameters[i].name) == 0)
214 {
215 stp_fill_parameter_settings(description, &(the_parameters[i]));
216 break;
217 }
218
219 description->deflt.str = NULL;
220
221 if (strcmp(name, "Quality") == 0)
222 {
223 #if 0
224 description->bounds.str = stp_string_list_create();
225 stp_string_list_add_string(description->bounds.str, "None",
226 _("Manual Control"));
227 for (i = 0; i < stpi_get_qualities_count(); i++)
228 {
229 const stpi_quality_t *qual = stpi_get_quality_by_index(i);
230 stp_string_list_add_string(description->bounds.str, qual->name,
231 gettext(qual->text));
232 }
233 description->deflt.str = "Standard";
234 #else
235 description->bounds.str = stp_string_list_create();
236 description->is_active = 0;
237 #endif
238 }
239 else if (strcmp(name, "ImageType") == 0)
240 {
241 description->bounds.str = stp_string_list_create();
242 stp_string_list_add_string(description->bounds.str, "None",
243 _("Manual Control"));
244 for (i = 0; i < stpi_get_image_types_count(); i++)
245 {
246 const stpi_image_type_t *itype = stpi_get_image_type_by_index(i);
247 stp_string_list_add_string(description->bounds.str, itype->name,
248 gettext(itype->text));
249 }
250 description->deflt.str = "TextGraphics";
251 }
252 else if (strcmp(name, "JobMode") == 0)
253 {
254 description->bounds.str = stp_string_list_create();
255 for (i = 0; i < stpi_get_job_modes_count(); i++)
256 {
257 const stpi_job_mode_t *itype = stpi_get_job_mode_by_index(i);
258 stp_string_list_add_string(description->bounds.str, itype->name,
259 gettext(itype->text));
260 }
261 description->deflt.str = "Page";
262 }
263 else if (strcmp(name, "PageNumber") == 0)
264 {
265 description->deflt.integer = 0;
266 description->bounds.integer.lower = 0;
267 description->bounds.integer.upper = INT_MAX;
268 }
269 else if (strcmp(name, "NumCopies") == 0)
270 {
271 description->deflt.integer = 1;
272 description->bounds.integer.lower = 1;
273 description->bounds.integer.upper = INT_MAX;
274 }
275 else if (strcmp(name, "Collate") == 0)
276 {
277 description->deflt.boolean = 0;
278 }
279 }