| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
|---|
| 6 | **
|
|---|
| 7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
|---|
| 8 | **
|
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 10 | ** Commercial Usage
|
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 14 | ** a written agreement between you and Nokia.
|
|---|
| 15 | **
|
|---|
| 16 | ** GNU Lesser General Public License Usage
|
|---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 20 | ** packaging of this file. Please review the following information to
|
|---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 23 | **
|
|---|
| 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
|---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
|---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you have questions regarding the use of this file, please contact
|
|---|
| 37 | ** Nokia at [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 | #include <qdebug.h>
|
|---|
| 42 | #include "qcups_p.h"
|
|---|
| 43 |
|
|---|
| 44 | #ifndef QT_NO_CUPS
|
|---|
| 45 |
|
|---|
| 46 | #ifndef QT_LINUXBASE // LSB merges everything into cups.h
|
|---|
| 47 | # include <cups/language.h>
|
|---|
| 48 | #endif
|
|---|
| 49 | #include <qtextcodec.h>
|
|---|
| 50 |
|
|---|
| 51 | QT_BEGIN_NAMESPACE
|
|---|
| 52 |
|
|---|
| 53 | #ifndef Q_WS_PM
|
|---|
| 54 |
|
|---|
| 55 | typedef int (*CupsGetDests)(cups_dest_t **dests);
|
|---|
| 56 | typedef void (*CupsFreeDests)(int num_dests, cups_dest_t *dests);
|
|---|
| 57 | typedef const char* (*CupsGetPPD)(const char *printer);
|
|---|
| 58 | typedef int (*CupsMarkOptions)(ppd_file_t *ppd, int num_options, cups_option_t *options);
|
|---|
| 59 | typedef ppd_file_t* (*PPDOpenFile)(const char *filename);
|
|---|
| 60 | typedef void (*PPDMarkDefaults)(ppd_file_t *ppd);
|
|---|
| 61 | typedef int (*PPDMarkOption)(ppd_file_t *ppd, const char *keyword, const char *option);
|
|---|
| 62 | typedef void (*PPDClose)(ppd_file_t *ppd);
|
|---|
| 63 | typedef int (*PPDMarkOption)(ppd_file_t *ppd, const char *keyword, const char *option);
|
|---|
| 64 | typedef void (*CupsFreeOptions)(int num_options, cups_option_t *options);
|
|---|
| 65 | typedef void (*CupsSetDests)(int num_dests, cups_dest_t *dests);
|
|---|
| 66 | typedef cups_lang_t* (*CupsLangGet)(const char *language);
|
|---|
| 67 | typedef const char* (*CupsLangEncoding)(cups_lang_t *language);
|
|---|
| 68 | typedef int (*CupsAddOption)(const char *name, const char *value, int num_options, cups_option_t **options);
|
|---|
| 69 | typedef int (*CupsTempFd)(char *name, int len);
|
|---|
| 70 | typedef int (*CupsPrintFile)(const char * name, const char * filename, const char * title, int num_options, cups_option_t * options);
|
|---|
| 71 |
|
|---|
| 72 | static bool cupsLoaded = false;
|
|---|
| 73 | static int qt_cups_num_printers = 0;
|
|---|
| 74 | static CupsGetDests _cupsGetDests = 0;
|
|---|
| 75 | static CupsFreeDests _cupsFreeDests = 0;
|
|---|
| 76 | static CupsGetPPD _cupsGetPPD = 0;
|
|---|
| 77 | static PPDOpenFile _ppdOpenFile = 0;
|
|---|
| 78 | static PPDMarkDefaults _ppdMarkDefaults = 0;
|
|---|
| 79 | static PPDClose _ppdClose = 0;
|
|---|
| 80 | static CupsMarkOptions _cupsMarkOptions = 0;
|
|---|
| 81 | static PPDMarkOption _ppdMarkOption = 0;
|
|---|
| 82 | static CupsFreeOptions _cupsFreeOptions = 0;
|
|---|
| 83 | static CupsSetDests _cupsSetDests = 0;
|
|---|
| 84 | static CupsLangGet _cupsLangGet = 0;
|
|---|
| 85 | static CupsLangEncoding _cupsLangEncoding = 0;
|
|---|
| 86 | static CupsAddOption _cupsAddOption = 0;
|
|---|
| 87 | static CupsTempFd _cupsTempFd = 0;
|
|---|
| 88 | static CupsPrintFile _cupsPrintFile = 0;
|
|---|
| 89 |
|
|---|
| 90 | #else // ifndef Q_WS_PM
|
|---|
| 91 |
|
|---|
| 92 | // On OS/2, we link to libcups statically
|
|---|
| 93 |
|
|---|
| 94 | static bool cupsLoaded = false;
|
|---|
| 95 | static int qt_cups_num_printers = 0;
|
|---|
| 96 |
|
|---|
| 97 | #define _cupsGetDests cupsGetDests
|
|---|
| 98 | #define _cupsFreeDests cupsFreeDests
|
|---|
| 99 | #define _cupsGetPPD cupsGetPPD
|
|---|
| 100 | #define _cupsLangGet cupsLangGet
|
|---|
| 101 | #define _cupsLangEncoding cupsLangEncoding
|
|---|
| 102 | #define _ppdOpenFile ppdOpenFile
|
|---|
| 103 | #define _ppdMarkDefaults ppdMarkDefaults
|
|---|
| 104 | #define _ppdClose ppdClose
|
|---|
| 105 | #define _cupsMarkOptions cupsMarkOptions
|
|---|
| 106 | #define _ppdMarkOption ppdMarkOption
|
|---|
| 107 | #define _cupsFreeOptions cupsFreeOptions
|
|---|
| 108 | #define _cupsSetDests cupsSetDests
|
|---|
| 109 | #define _cupsAddOption cupsAddOption
|
|---|
| 110 | #define _cupsTempFd cupsTempFd
|
|---|
| 111 | #define _cupsPrintFile cupsPrintFile
|
|---|
| 112 |
|
|---|
| 113 | #endif // ifndef Q_WS_PM
|
|---|
| 114 |
|
|---|
| 115 | static void resolveCups()
|
|---|
| 116 | {
|
|---|
| 117 | #ifndef Q_WS_PM
|
|---|
| 118 | QLibrary cupsLib(QLatin1String("cups"), 2);
|
|---|
| 119 | if(cupsLib.load()) {
|
|---|
| 120 | _cupsGetDests = (CupsGetDests) cupsLib.resolve("cupsGetDests");
|
|---|
| 121 | _cupsFreeDests = (CupsFreeDests) cupsLib.resolve("cupsFreeDests");
|
|---|
| 122 | _cupsGetPPD = (CupsGetPPD) cupsLib.resolve("cupsGetPPD");
|
|---|
| 123 | _cupsLangGet = (CupsLangGet) cupsLib.resolve("cupsLangGet");
|
|---|
| 124 | _cupsLangEncoding = (CupsLangEncoding) cupsLib.resolve("cupsLangEncoding");
|
|---|
| 125 | _ppdOpenFile = (PPDOpenFile) cupsLib.resolve("ppdOpenFile");
|
|---|
| 126 | _ppdMarkDefaults = (PPDMarkDefaults) cupsLib.resolve("ppdMarkDefaults");
|
|---|
| 127 | _ppdClose = (PPDClose) cupsLib.resolve("ppdClose");
|
|---|
| 128 | _cupsMarkOptions = (CupsMarkOptions) cupsLib.resolve("cupsMarkOptions");
|
|---|
| 129 | _ppdMarkOption = (PPDMarkOption) cupsLib.resolve("ppdMarkOption");
|
|---|
| 130 | _cupsFreeOptions = (CupsFreeOptions) cupsLib.resolve("cupsFreeOptions");
|
|---|
| 131 | _cupsSetDests = (CupsSetDests) cupsLib.resolve("cupsSetDests");
|
|---|
| 132 | _cupsAddOption = (CupsAddOption) cupsLib.resolve("cupsAddOption");
|
|---|
| 133 | _cupsTempFd = (CupsTempFd) cupsLib.resolve("cupsTempFd");
|
|---|
| 134 | _cupsPrintFile = (CupsPrintFile) cupsLib.resolve("cupsPrintFile");
|
|---|
| 135 |
|
|---|
| 136 | if (_cupsGetDests && _cupsFreeDests) {
|
|---|
| 137 | #endif
|
|---|
| 138 | cups_dest_t *printers;
|
|---|
| 139 | int num_printers = _cupsGetDests(&printers);
|
|---|
| 140 | if (num_printers)
|
|---|
| 141 | _cupsFreeDests(num_printers, printers);
|
|---|
|
|---|