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