| Line | Source Code | Coverage |
|---|
| 1 | | - |
| 2 | | - |
| 3 | | - |
| 4 | | - |
| 5 | | - |
| 6 | | - |
| 7 | | - |
| 8 | | - |
| 9 | | - |
| 10 | typedef int (*CupsGetDests)(cups_dest_t **dests); | - |
| 11 | typedef void (*CupsFreeDests)(int num_dests, cups_dest_t *dests); | - |
| 12 | typedef const char* (*CupsGetPPD)(const char *printer); | - |
| 13 | typedef int (*CupsMarkOptions)(ppd_file_t *ppd, int num_options, cups_option_t *options); | - |
| 14 | typedef ppd_file_t* (*PPDOpenFile)(const char *filename); | - |
| 15 | typedef void (*PPDMarkDefaults)(ppd_file_t *ppd); | - |
| 16 | typedef int (*PPDMarkOption)(ppd_file_t *ppd, const char *keyword, const char *option); | - |
| 17 | typedef void (*PPDClose)(ppd_file_t *ppd); | - |
| 18 | typedef int (*PPDMarkOption)(ppd_file_t *ppd, const char *keyword, const char *option); | - |
| 19 | typedef void (*CupsFreeOptions)(int num_options, cups_option_t *options); | - |
| 20 | typedef void (*CupsSetDests)(int num_dests, cups_dest_t *dests); | - |
| 21 | typedef cups_lang_t* (*CupsLangGet)(const char *language); | - |
| 22 | typedef const char* (*CupsLangEncoding)(cups_lang_t *language); | - |
| 23 | typedef int (*CupsAddOption)(const char *name, const char *value, int num_options, cups_option_t **options); | - |
| 24 | typedef int (*CupsTempFd)(char *name, int len); | - |
| 25 | typedef int (*CupsPrintFile)(const char * name, const char * filename, const char * title, int num_options, cups_option_t * options); | - |
| 26 | | - |
| 27 | static bool cupsLoaded = false; | - |
| 28 | static int qt_cups_num_printers = 0; | - |
| 29 | static CupsGetDests _cupsGetDests = 0; | - |
| 30 | static CupsFreeDests _cupsFreeDests = 0; | - |
| 31 | static CupsGetPPD _cupsGetPPD = 0; | - |
| 32 | static PPDOpenFile _ppdOpenFile = 0; | - |
| 33 | static PPDMarkDefaults _ppdMarkDefaults = 0; | - |
| 34 | static PPDClose _ppdClose = 0; | - |
| 35 | static CupsMarkOptions _cupsMarkOptions = 0; | - |
| 36 | static PPDMarkOption _ppdMarkOption = 0; | - |
| 37 | static CupsFreeOptions _cupsFreeOptions = 0; | - |
| 38 | static CupsSetDests _cupsSetDests = 0; | - |
| 39 | static CupsLangGet _cupsLangGet = 0; | - |
| 40 | static CupsLangEncoding _cupsLangEncoding = 0; | - |
| 41 | static CupsAddOption _cupsAddOption = 0; | - |
| 42 | static CupsTempFd _cupsTempFd = 0; | - |
| 43 | static CupsPrintFile _cupsPrintFile = 0; | - |
| 44 | | - |
| 45 | static void resolveCups() | - |
| 46 | { | - |
| 47 | QLibrary cupsLib(QLatin1String("cups"), 2); | - |
| 48 | if(cupsLib.load()) { partially evaluated: cupsLib.load()| yes Evaluation Count:2 | no Evaluation Count:0 |
| 0-2 |
| 49 | _cupsGetDests = (CupsGetDests) cupsLib.resolve("cupsGetDests"); | - |
| 50 | _cupsFreeDests = (CupsFreeDests) cupsLib.resolve("cupsFreeDests"); | - |
| 51 | _cupsGetPPD = (CupsGetPPD) cupsLib.resolve("cupsGetPPD"); | - |
| 52 | _cupsLangGet = (CupsLangGet) cupsLib.resolve("cupsLangGet"); | - |
| 53 | _cupsLangEncoding = (CupsLangEncoding) cupsLib.resolve("cupsLangEncoding"); | - |
| 54 | _ppdOpenFile = (PPDOpenFile) cupsLib.resolve("ppdOpenFile"); | - |
| 55 | _ppdMarkDefaults = (PPDMarkDefaults) cupsLib.resolve("ppdMarkDefaults"); | - |
| 56 | _ppdClose = (PPDClose) cupsLib.resolve("ppdClose"); | - |
| 57 | _cupsMarkOptions = (CupsMarkOptions) cupsLib.resolve("cupsMarkOptions"); | - |
| 58 | _ppdMarkOption = (PPDMarkOption) cupsLib.resolve("ppdMarkOption"); | - |
| 59 | _cupsFreeOptions = (CupsFreeOptions) cupsLib.resolve("cupsFreeOptions"); | - |
| 60 | _cupsSetDests = (CupsSetDests) cupsLib.resolve("cupsSetDests"); | - |
| 61 | _cupsAddOption = (CupsAddOption) cupsLib.resolve("cupsAddOption"); | - |
| 62 | _cupsTempFd = (CupsTempFd) cupsLib.resolve("cupsTempFd"); | - |
| 63 | _cupsPrintFile = (CupsPrintFile) cupsLib.resolve("cupsPrintFile"); | - |
| 64 | | - |
| 65 | if (_cupsGetDests && _cupsFreeDests) { partially evaluated: _cupsGetDests| yes Evaluation Count:2 | no Evaluation Count:0 |
partially evaluated: _cupsFreeDests| yes Evaluation Count:2 | no Evaluation Count:0 |
| 0-2 |
| 66 | cups_dest_t *printers; | - |
| 67 | int num_printers = _cupsGetDests(&printers); | - |
| 68 | if (num_printers) partially evaluated: num_printers| no Evaluation Count:0 | yes Evaluation Count:2 |
| 0-2 |
| 69 | _cupsFreeDests(num_printers, printers); never executed: _cupsFreeDests(num_printers, printers); | 0 |
| 70 | qt_cups_num_printers = num_printers; | - |
| 71 | } executed: }Execution Count:2 | 2 |
| 72 | } executed: }Execution Count:2 | 2 |
| 73 | cupsLoaded = true; | - |
| 74 | } executed: }Execution Count:2 | 2 |
| 75 | | - |
| 76 | | - |
| 77 | | - |
| 78 | QCUPSSupport::QCUPSSupport() | - |
| 79 | : | - |
| 80 | prnCount(0), | - |
| 81 | printers(0), | - |
| 82 | page_sizes(0), | - |
| 83 | currPrinterIndex(0), | - |
| 84 | currPPD(0) | - |
| 85 | { | - |
| 86 | if (!cupsLoaded) never evaluated: !cupsLoaded | 0 |
| 87 | resolveCups(); never executed: resolveCups(); | 0 |
| 88 | | - |
| 89 | | - |
| 90 | if (!isAvailable()) never evaluated: !isAvailable() | 0 |
| 91 | return; | 0 |
| 92 | | - |
| 93 | qt_cups_num_printers = prnCount = _cupsGetDests(&printers); | - |
| 94 | | - |
| 95 | for (int i = 0; i < prnCount; ++i) { never evaluated: i < prnCount | 0 |
| 96 | if (printers[i].is_default) { never evaluated: printers[i].is_default | 0 |
| 97 | currPrinterIndex = i; | - |
| 98 | setCurrentPrinter(i); | - |
| 99 | break; | 0 |
| 100 | } | - |
| 101 | } | 0 |
| 102 | | - |
| 103 | | - |
| 104 | cups_lang_t *cupsLang = _cupsLangGet(0); | - |
| 105 | codec = QTextCodec::codecForName(_cupsLangEncoding(cupsLang)); | - |
| 106 | if (!codec) | 0 |
| 107 | codec = QTextCodec::codecForLocale(); never executed: codec = QTextCodec::codecForLocale(); | 0 |
| 108 | | - |
| 109 | } | 0 |
| 110 | | - |
| 111 | QCUPSSupport::~QCUPSSupport() | - |
| 112 | { | - |
| 113 | if (currPPD) | 0 |
| 114 | _ppdClose(currPPD); never executed: _ppdClose(currPPD); | 0 |
| 115 | if (prnCount) never evaluated: prnCount | 0 |
| 116 | _cupsFreeDests(prnCount, printers); never executed: _cupsFreeDests(prnCount, printers); | 0 |
| 117 | } | 0 |
| 118 | | - |
| 119 | int QCUPSSupport::availablePrintersCount() const | - |
| 120 | { | - |
| 121 | return prnCount; never executed: return prnCount; | 0 |
| 122 | } | - |
| 123 | | - |
| 124 | const cups_dest_t* QCUPSSupport::availablePrinters() const | - |
| 125 | { | - |
| 126 | return printers; never executed: return printers; | 0 |
| 127 | } | - |
| 128 | | - |
| 129 | const ppd_file_t* QCUPSSupport::currentPPD() const | - |
| 130 | { | - |
| 131 | return currPPD; never executed: return currPPD; | 0 |
| 132 | } | - |
| 133 | | - |
| 134 | const ppd_file_t* QCUPSSupport::setCurrentPrinter(int index) | - |
| 135 | { | - |
| 136 | qt_noop(); | - |
| 137 | if (index == prnCount) never evaluated: index == prnCount | 0 |
| 138 | return 0; never executed: return 0; | 0 |
| 139 | | - |
| 140 | currPrinterIndex = index; | - |
| 141 | | - |
| 142 | if (currPPD) | 0 |
| 143 | _ppdClose(currPPD); never executed: _ppdClose(currPPD); | 0 |
| 144 | currPPD = 0; | - |
| 145 | page_sizes = 0; | - |
| 146 | | - |
| 147 | const char *ppdFile = _cupsGetPPD(printers[index].name); | - |
| 148 | | - |
| 149 | if (!ppdFile) never evaluated: !ppdFile | 0 |
| 150 | return 0; never executed: return 0; | 0 |
| 151 | | - |
| 152 | currPPD = _ppdOpenFile(ppdFile); | - |
| 153 | unlink(ppdFile); | - |
| 154 | | - |
| 155 | | - |
| 156 | _ppdMarkDefaults(currPPD); | - |
| 157 | | - |
| 158 | | - |
| 159 | _cupsMarkOptions(currPPD, printers[currPrinterIndex].num_options, printers[currPrinterIndex].options); | - |
| 160 | | - |
| 161 | | - |
| 162 | page_sizes = ppdOption("PageSize"); | - |
| 163 | | - |
| 164 | return currPPD; never executed: return currPPD; | 0 |
| 165 | } | - |
| 166 | | - |
| 167 | int QCUPSSupport::currentPrinterIndex() const | - |
| 168 | { | - |
| 169 | return currPrinterIndex; never executed: return currPrinterIndex; | 0 |
| 170 | } | - |
| 171 | | - |
| 172 | bool QCUPSSupport::isAvailable() | - |
| 173 | { | - |
| 174 | if(!cupsLoaded) evaluated: !cupsLoaded| yes Evaluation Count:2 | yes Evaluation Count:117 |
| 2-117 |
| 175 | resolveCups(); executed: resolveCups();Execution Count:2 | 2 |
| 176 | | - |
| 177 | return _cupsGetDests && | 119 |
| 178 | _cupsFreeDests && | 119 |
| 179 | _cupsGetPPD && | 119 |
| 180 | _ppdOpenFile && | 119 |
| 181 | _ppdMarkDefaults && | 119 |
| 182 | _ppdClose && | 119 |
| 183 | _cupsMarkOptions && | 119 |
| 184 | _ppdMarkOption && | 119 |
| 185 | _cupsFreeOptions && | 119 |
| 186 | _cupsSetDests && | 119 |
| 187 | _cupsLangGet && | 119 |
| 188 | _cupsLangEncoding && | 119 |
| 189 | _cupsAddOption && | 119 |
| 190 | (qt_cups_num_printers > 0); executed: return _cupsGetDests && _cupsFreeDests && _cupsGetPPD && _ppdOpenFile && _ppdMarkDefaults && _ppdClose && _cupsMarkOptions && _ppdMarkOption && _cupsFreeOptions && _cupsSetDests && _cupsLangGet && _cupsLangEncoding && _cupsAddOption && (qt_cups_num_printers > 0);Execution Count:119 | 119 |
| 191 | } | - |
| 192 | | - |
| 193 | const ppd_option_t* QCUPSSupport::ppdOption(const char *key) const | - |
| 194 | { | - |
| 195 | if (currPPD) { | 0 |
| 196 | for (int gr = 0; gr < currPPD->num_groups; ++gr) { never evaluated: gr < currPPD->num_groups | 0 |
| 197 | for (int opt = 0; opt < currPPD->groups[gr].num_options; ++opt) { never evaluated: opt < currPPD->groups[gr].num_options | 0 |
| 198 | if (qstrcmp(currPPD->groups[gr].options[opt].keyword, key) == 0) never evaluated: qstrcmp(currPPD->groups[gr].options[opt].keyword, key) == 0 | 0 |
| 199 | return &currPPD->groups[gr].options[opt]; never executed: return &currPPD->groups[gr].options[opt]; | 0 |
| 200 | } | 0 |
| 201 | } | 0 |
| 202 | } | 0 |
| 203 | return 0; never executed: return 0; | 0 |
| 204 | } | - |
| 205 | | - |
| 206 | const cups_option_t* QCUPSSupport::printerOption(const QString &key) const | - |
| 207 | { | - |
| 208 | for (int i = 0; i < printers[currPrinterIndex].num_options; ++i) { never evaluated: i < printers[currPrinterIndex].num_options | 0 |
| 209 | if (QLatin1String(printers[currPrinterIndex].options[i].name) == key) never evaluated: QLatin1String(printers[currPrinterIndex].options[i].name) == key | 0 |
| 210 | return &printers[currPrinterIndex].options[i]; never executed: return &printers[currPrinterIndex].options[i]; | 0 |
| 211 | } | 0 |
| 212 | return 0; never executed: return 0; | 0 |
| 213 | } | - |
| 214 | | - |
| 215 | const ppd_option_t* QCUPSSupport::pageSizes() const | - |
| 216 | { | - |
| 217 | return page_sizes; never executed: return page_sizes; | 0 |
| 218 | } | - |
| 219 | | - |
| 220 | int QCUPSSupport::markOption(const char* name, const char* value) | - |
| 221 | { | - |
| 222 | return _ppdMarkOption(currPPD, name, value); never executed: return _ppdMarkOption(currPPD, name, value); | 0 |
| 223 | } | - |
| 224 | | - |
| 225 | void QCUPSSupport::saveOptions(QList<const ppd_option_t*> options, QList<const char*> markedOptions) | - |
| 226 | { | - |
| 227 | int oldOptionCount = printers[currPrinterIndex].num_options; | - |
| 228 | cups_option_t* oldOptions = printers[currPrinterIndex].options; | - |
| 229 | | - |
| 230 | int newOptionCount = 0; | - |
| 231 | cups_option_t* newOptions = 0; | - |
| 232 | | - |
| 233 | | - |
| 234 | for (int i = 0; i < oldOptionCount; ++i) { never evaluated: i < oldOptionCount | 0 |
| 235 | bool contains = false; | - |
| 236 | for (int j = 0; j < options.count(); ++j) { never evaluated: j < options.count() | 0 |
| 237 | if (qstrcmp(options.at(j)->keyword, oldOptions[i].name) == 0) { never evaluated: qstrcmp(options.at(j)->keyword, oldOptions[i].name) == 0 | 0 |
| 238 | contains = true; | - |
| 239 | break; | 0 |
| 240 | } | - |
| 241 | } | 0 |
| 242 | | - |
| 243 | if (!contains) { never evaluated: !contains | 0 |
| 244 | newOptionCount = _cupsAddOption(oldOptions[i].name, oldOptions[i].value, newOptionCount, &newOptions); | - |
| 245 | } | 0 |
| 246 | } | 0 |
| 247 | | - |
| 248 | | - |
| 249 | _cupsFreeOptions(oldOptionCount, oldOptions); | - |
| 250 | | - |
| 251 | | - |
| 252 | for (int i = 0; i < markedOptions.count(); ++i) { never evaluated: i < markedOptions.count() | 0 |
| 253 | const char* name = markedOptions.at(i); | - |
| 254 | ++i; | - |
| 255 | newOptionCount = _cupsAddOption(name, markedOptions.at(i), newOptionCount, &newOptions); | - |
| 256 | } | 0 |
| 257 | | - |
| 258 | | - |
| 259 | printers[currPrinterIndex].num_options = newOptionCount; | - |
| 260 | printers[currPrinterIndex].options = newOptions; | - |
| 261 | | - |
| 262 | | - |
| 263 | _cupsSetDests(prnCount, printers); | - |
| 264 | } | 0 |
| 265 | | - |
| 266 | QRect QCUPSSupport::paperRect(const char *choice) const | - |
| 267 | { | - |
| 268 | if (!currPPD) never evaluated: !currPPD | 0 |
| 269 | return QRect(); never executed: return QRect(); | 0 |
| 270 | for (int i = 0; i < currPPD->num_sizes; ++i) { never evaluated: i < currPPD->num_sizes | 0 |
| 271 | if (qstrcmp(currPPD->sizes[i].name, choice) == 0) never evaluated: qstrcmp(currPPD->sizes[i].name, choice) == 0 | 0 |
| 272 | return QRect(0, 0, qRound(currPPD->sizes[i].width), qRound(currPPD->sizes[i].length)); never executed: return QRect(0, 0, qRound(currPPD->sizes[i].width), qRound(currPPD->sizes[i].length)); | 0 |
| 273 | } | 0 |
| 274 | return QRect(); never executed: return QRect(); | 0 |
| 275 | } | - |
| 276 | | - |
| 277 | QRect QCUPSSupport::pageRect(const char *choice) const | - |
| 278 | { | - |
| 279 | if (!currPPD) never evaluated: !currPPD | 0 |
| 280 | return QRect(); never executed: return QRect(); | 0 |
| 281 | for (int i = 0; i < currPPD->num_sizes; ++i) { never evaluated: i < currPPD->num_sizes | 0 |
| 282 | if (qstrcmp(currPPD->sizes[i].name, choice) == 0) never evaluated: qstrcmp(currPPD->sizes[i].name, choice) == 0 | 0 |
| 283 | return QRect(qRound(currPPD->sizes[i].left), | 0 |
| 284 | qRound(currPPD->sizes[i].length - currPPD->sizes[i].top), | 0 |
| 285 | qRound(currPPD->sizes[i].right - currPPD->sizes[i].left), | 0 |
| 286 | qRound(currPPD->sizes[i].top - currPPD->sizes[i].bottom)); never executed: return QRect(qRound(currPPD->sizes[i].left), qRound(currPPD->sizes[i].length - currPPD->sizes[i].top), qRound(currPPD->sizes[i].right - currPPD->sizes[i].left), qRound(currPPD->sizes[i].top - currPPD->sizes[i].bottom)); | 0 |
| 287 | } | 0 |
| 288 | return QRect(); never executed: return QRect(); | 0 |
| 289 | } | - |
| 290 | | - |
| 291 | QStringList QCUPSSupport::options() const | - |
| 292 | { | - |
| 293 | QStringList list; | - |
| 294 | collectMarkedOptions(list); | - |
| 295 | return list; never executed: return list; | 0 |
| 296 | } | - |
| 297 | | - |
| 298 | bool QCUPSSupport::printerHasPPD(const char *printerName) | - |
| 299 | { | - |
| 300 | if (!isAvailable()) never evaluated: !isAvailable() | 0 |
| 301 | return false; never executed: return false; | 0 |
| 302 | const char *ppdFile = _cupsGetPPD(printerName); | - |
| 303 | if (ppdFile) | 0 |
| 304 | unlink(ppdFile); never executed: unlink(ppdFile); | 0 |
| 305 | return (ppdFile != 0); never executed: return (ppdFile != 0); | 0 |
| 306 | } | - |
| 307 | | - |
| 308 | QString QCUPSSupport::unicodeString(const char *s) | - |
| 309 | { | - |
| 310 | | - |
| 311 | return codec->toUnicode(s); never executed: return codec->toUnicode(s); | 0 |
| 312 | | - |
| 313 | | - |
| 314 | | - |
| 315 | } | - |
| 316 | | - |
| 317 | void QCUPSSupport::collectMarkedOptions(QStringList& list, const ppd_group_t* group) const | - |
| 318 | { | - |
| 319 | if (group == 0) { never evaluated: group == 0 | 0 |
| 320 | if (!currPPD) never evaluated: !currPPD | 0 |
| 321 | return; | 0 |
| 322 | for (int i = 0; i < currPPD->num_groups; ++i) { never evaluated: i < currPPD->num_groups | 0 |
| 323 | collectMarkedOptions(list, &currPPD->groups[i]); | - |
| 324 | collectMarkedOptionsHelper(list, &currPPD->groups[i]); | - |
| 325 | } | 0 |
| 326 | } else { | 0 |
| 327 | for (int i = 0; i < group->num_subgroups; ++i) never evaluated: i < group->num_subgroups | 0 |
| 328 | collectMarkedOptionsHelper(list, &group->subgroups[i]); never executed: collectMarkedOptionsHelper(list, &group->subgroups[i]); | 0 |
| 329 | } | 0 |
| 330 | } | - |
| 331 | | - |
| 332 | void QCUPSSupport::collectMarkedOptionsHelper(QStringList& list, const ppd_group_t* group) const | - |
| 333 | { | - |
| 334 | for (int i = 0; i < group->num_options; ++i) { never evaluated: i < group->num_options | 0 |
| 335 | for (int j = 0; j < group->options[i].num_choices; ++j) { never evaluated: j < group->options[i].num_choices | 0 |
| 336 | if (group->options[i].choices[j].marked == 1 && qstrcmp(group->options[i].choices[j].choice, group->options[i].defchoice) != 0) never evaluated: group->options[i].choices[j].marked == 1 never evaluated: qstrcmp(group->options[i].choices[j].choice, group->options[i].defchoice) != 0 | 0 |
| 337 | list << QString::fromLocal8Bit(group->options[i].keyword) << QString::fromLocal8Bit(group->options[i].choices[j].choice); never executed: list << QString::fromLocal8Bit(group->options[i].keyword) << QString::fromLocal8Bit(group->options[i].choices[j].choice); | 0 |
| 338 | } | 0 |
| 339 | } | 0 |
| 340 | } | 0 |
| 341 | | - |
| 342 | QPair<int, QString> QCUPSSupport::tempFd() | - |
| 343 | { | - |
| 344 | char filename[512]; | - |
| 345 | int fd = _cupsTempFd(filename, 512); | - |
| 346 | return QPair<int, QString>(fd, QString::fromLocal8Bit(filename)); never executed: return QPair<int, QString>(fd, QString::fromLocal8Bit(filename)); | 0 |
| 347 | } | - |
| 348 | | - |
| 349 | | - |
| 350 | int QCUPSSupport::printFile(const char * printerName, const char * filename, const char * title, | - |
| 351 | int num_options, cups_option_t * options) | - |
| 352 | { | - |
| 353 | return _cupsPrintFile(printerName, filename, title, num_options, options); never executed: return _cupsPrintFile(printerName, filename, title, num_options, options); | 0 |
| 354 | } | - |
| 355 | | - |
| 356 | QCUPSSupport::Printer::Printer(const QString &n) : name(n), isDefault(false), cupsPrinterIndex(-1) | - |
| 357 | { | - |
| 358 | } | 0 |
| 359 | | - |
| 360 | QList<QCUPSSupport::Printer> QCUPSSupport::availableUnixPrinters() | - |
| 361 | { | - |
| 362 | QList<Printer> printers; | - |
| 363 | | - |
| 364 | if (QCUPSSupport::isAvailable()) { never evaluated: QCUPSSupport::isAvailable() | 0 |
| 365 | QCUPSSupport cups; | - |
| 366 | int cupsPrinterCount = cups.availablePrintersCount(); | - |
| 367 | const cups_dest_t* cupsPrinters = cups.availablePrinters(); | - |
| 368 | for (int i = 0; i < cupsPrinterCount; ++i) { never evaluated: i < cupsPrinterCount | 0 |
| 369 | QString printerName(QString::fromLocal8Bit(cupsPrinters[i].name)); | - |
| 370 | if (cupsPrinters[i].instance) never evaluated: cupsPrinters[i].instance | 0 |
| 371 | printerName += QLatin1Char('/') + QString::fromLocal8Bit(cupsPrinters[i].instance); never executed: printerName += QLatin1Char('/') + QString::fromLocal8Bit(cupsPrinters[i].instance); | 0 |
| 372 | | - |
| 373 | Printer p(printerName); | - |
| 374 | if (cupsPrinters[i].is_default) never evaluated: cupsPrinters[i].is_default | 0 |
| 375 | p.isDefault = true; never executed: p.isDefault = true; | 0 |
| 376 | p.cupsPrinterIndex = i; | - |
| 377 | printers.append(p); | - |
| 378 | } | 0 |
| 379 | } | 0 |
| 380 | | - |
| 381 | return printers; never executed: return printers; | 0 |
| 382 | } | - |
| 383 | | - |
| 384 | | - |
| 385 | static const struct NamedPaperSize { | - |
| 386 | const char *const name; | - |
| 387 | QPrinter::PaperSize size; | - |
| 388 | } named_sizes_map[QPrinter::NPageSize] = { | - |
| 389 | { "A0", QPrinter::A0 }, | - |
| 390 | { "A1", QPrinter::A1 }, | - |
| 391 | { "A2", QPrinter::A2 }, | - |
| 392 | { "A3", QPrinter::A3 }, | - |
| 393 | { "A4", QPrinter::A4 }, | - |
| 394 | { "A5", QPrinter::A5 }, | - |
| 395 | { "A6", QPrinter::A6 }, | - |
| 396 | { "A7", QPrinter::A7 }, | - |
| 397 | { "A8", QPrinter::A8 }, | - |
| 398 | { "A9", QPrinter::A9 }, | - |
| 399 | { "B0", QPrinter::B0 }, | - |
| 400 | { "B1", QPrinter::B1 }, | - |
| 401 | { "B10", QPrinter::B10 }, | - |
| 402 | { "B2", QPrinter::B2 }, | - |
| 403 | { "B4", QPrinter::B4 }, | - |
| 404 | { "B5", QPrinter::B5 }, | - |
| 405 | { "B6", QPrinter::B6 }, | - |
| 406 | { "B7", QPrinter::B7 }, | - |
| 407 | { "B8", QPrinter::B8 }, | - |
| 408 | { "B9", QPrinter::B9 }, | - |
| 409 | { "C5E", QPrinter::C5E }, | - |
| 410 | { "Comm10E", QPrinter::Comm10E }, | - |
| 411 | { "Custom", QPrinter::Custom }, | - |
| 412 | { "DLE", QPrinter::DLE }, | - |
| 413 | { "Executive", QPrinter::Executive }, | - |
| 414 | { "Folio", QPrinter::Folio }, | - |
| 415 | { "Ledger", QPrinter::Ledger }, | - |
| 416 | { "Legal", QPrinter::Legal }, | - |
| 417 | { "Letter", QPrinter::Letter }, | - |
| 418 | { "Tabloid", QPrinter::Tabloid } | - |
| 419 | }; | - |
| 420 | | - |
| 421 | inline bool operator<(const char *name, const NamedPaperSize &data) | - |
| 422 | { return qstrcmp(name, data.name) < 0; } never executed: return qstrcmp(name, data.name) < 0; | 0 |
| 423 | inline bool operator<(const NamedPaperSize &data, const char *name) | - |
| 424 | { return qstrcmp(data.name, name) < 0; } never executed: return qstrcmp(data.name, name) < 0; | 0 |
| 425 | | - |
| 426 | static inline QPrinter::PaperSize string2PaperSize(const char *name) | - |
| 427 | { | - |
| 428 | const NamedPaperSize *r = qBinaryFind(named_sizes_map, named_sizes_map + QPrinter::NPageSize, name); | - |
| 429 | if (r - named_sizes_map != QPrinter::NPageSize) never evaluated: r - named_sizes_map != QPrinter::NPageSize | 0 |
| 430 | return r->size; never executed: return r->size; | 0 |
| 431 | return QPrinter::Custom; never executed: return QPrinter::Custom; | 0 |
| 432 | } | - |
| 433 | | - |
| 434 | static inline const char *paperSize2String(QPrinter::PaperSize size) | - |
| 435 | { | - |
| 436 | for (int i = 0; i < QPrinter::NPageSize; ++i) { never evaluated: i < QPrinter::NPageSize | 0 |
| 437 | if (size == named_sizes_map[i].size) never evaluated: size == named_sizes_map[i].size | 0 |
| 438 | return named_sizes_map[i].name; never executed: return named_sizes_map[i].name; | 0 |
| 439 | } | 0 |
| 440 | return 0; never executed: return 0; | 0 |
| 441 | } | - |
| 442 | | - |
| 443 | QList<QPrinter::PaperSize> QCUPSSupport::getCupsPrinterPaperSizes(int cupsPrinterIndex) | - |
| 444 | { | - |
| 445 | QList<QPrinter::PaperSize> result; | - |
| 446 | if (!QCUPSSupport::isAvailable() || cupsPrinterIndex < 0) never evaluated: !QCUPSSupport::isAvailable() never evaluated: cupsPrinterIndex < 0 | 0 |
| 447 | return result; never executed: return result; | 0 |
| 448 | | - |
| 449 | QCUPSSupport cups; | - |
| 450 | cups.setCurrentPrinter(cupsPrinterIndex); | - |
| 451 | if (const ppd_option_t* size = cups.pageSizes()) { never evaluated: const ppd_option_t* size = cups.pageSizes() | 0 |
| 452 | for (int j = 0; j < size->num_choices; ++j) never evaluated: j < size->num_choices | 0 |
| 453 | result.append(string2PaperSize(size->choices[j].choice)); never executed: result.append(string2PaperSize(size->choices[j].choice)); | 0 |
| 454 | } | 0 |
| 455 | return result; never executed: return result; | 0 |
| 456 | } | - |
| 457 | | - |
| 458 | | - |
| 459 | | - |
| | |