Qt 4.8
Public Functions | Static Public Functions | Private Functions | Properties | List of all members
QCUPSSupport Class Reference

#include <qcups_p.h>

Public Functions

const cups_dest_t * availablePrinters () const
 
int availablePrintersCount () const
 
const ppd_file_t * currentPPD () const
 
int currentPrinterIndex () const
 
int markOption (const char *name, const char *value)
 
QStringList options () const
 
QRect pageRect (const char *choice) const
 
const ppd_option_t * pageSizes () const
 
QRect paperRect (const char *choice) const
 
const ppd_option_t * ppdOption (const char *key) const
 
const cups_option_t * printerOption (const QString &key) const
 
int printFile (const char *printerName, const char *filename, const char *title, int num_options, cups_option_t *options)
 
 QCUPSSupport ()
 
void saveOptions (QList< const ppd_option_t *> options, QList< const char *> markedOptions)
 
const ppd_file_t * setCurrentPrinter (int index)
 
QPair< int, QStringtempFd ()
 
QString unicodeString (const char *s)
 
 ~QCUPSSupport ()
 

Static Public Functions

static int cupsVersion ()
 
static bool isAvailable ()
 
static bool printerHasPPD (const char *printerName)
 

Private Functions

void collectMarkedOptions (QStringList &list, const ppd_group_t *group=0) const
 
void collectMarkedOptionsHelper (QStringList &list, const ppd_group_t *group) const
 

Properties

QTextCodeccodec
 
ppd_file_t * currPPD
 
int currPrinterIndex
 
const ppd_option_t * page_sizes
 
cups_dest_t * printers
 
int prnCount
 

Detailed Description

Definition at line 68 of file qcups_p.h.

Constructors and Destructors

◆ QCUPSSupport()

QCUPSSupport::QCUPSSupport ( )

Definition at line 121 of file qcups.cpp.

122  :
123  prnCount(0),
124  printers(0),
125  page_sizes(0),
126  currPrinterIndex(0),
127  currPPD(0)
128 {
129  if (!cupsLoaded)
130  resolveCups();
131 
132  // getting all available printers
133  if (!isAvailable())
134  return;
135 
136  // Update the available printer count
138 
139  for (int i = 0; i < prnCount; ++i) {
140  if (printers[i].is_default) {
141  currPrinterIndex = i;
143  break;
144  }
145  }
146 
147 #ifndef QT_NO_TEXTCODEC
148  cups_lang_t *cupsLang = _cupsLangGet(0);
150  if (!codec)
152 #endif
153 }
static QTextCodec * codecForLocale()
Returns a pointer to the codec most suitable for this locale.
static CupsLangEncoding _cupsLangEncoding
Definition: qcups.cpp:83
static int qt_cups_num_printers
Definition: qcups.cpp:71
const ppd_option_t * page_sizes
Definition: qcups_p.h:109
static void resolveCups()
Definition: qcups.cpp:88
QTextCodec * codec
Definition: qcups_p.h:113
static bool isAvailable()
Definition: qcups.cpp:216
cups_dest_t * printers
Definition: qcups_p.h:108
ppd_file_t * currPPD
Definition: qcups_p.h:111
static CupsGetDests _cupsGetDests
Definition: qcups.cpp:72
static bool cupsLoaded
Definition: qcups.cpp:70
const ppd_file_t * setCurrentPrinter(int index)
Definition: qcups.cpp:178
static QTextCodec * codecForName(const QByteArray &name)
Searches all installed QTextCodec objects and returns the one which best matches name; the match is c...
static CupsLangGet _cupsLangGet
Definition: qcups.cpp:82
int currPrinterIndex
Definition: qcups_p.h:110
int prnCount
Definition: qcups_p.h:107

◆ ~QCUPSSupport()

QCUPSSupport::~QCUPSSupport ( )

Definition at line 155 of file qcups.cpp.

156 {
157  if (currPPD)
159  if (prnCount)
161 }
cups_dest_t * printers
Definition: qcups_p.h:108
static CupsFreeDests _cupsFreeDests
Definition: qcups.cpp:73
ppd_file_t * currPPD
Definition: qcups_p.h:111
static PPDClose _ppdClose
Definition: qcups.cpp:77
int prnCount
Definition: qcups_p.h:107

Functions

◆ availablePrinters()

const cups_dest_t * QCUPSSupport::availablePrinters ( ) const

Definition at line 168 of file qcups.cpp.

Referenced by cupsVersion(), QPdfBaseEngine::QPdfBaseEngine(), qt_getLprPrinters(), and QUnixPrintWidgetPrivate::QUnixPrintWidgetPrivate().

169 {
170  return printers;
171 }
cups_dest_t * printers
Definition: qcups_p.h:108

◆ availablePrintersCount()

int QCUPSSupport::availablePrintersCount ( ) const

◆ collectMarkedOptions()

void QCUPSSupport::collectMarkedOptions ( QStringList list,
const ppd_group_t *  group = 0 
) const
private

Definition at line 361 of file qcups.cpp.

Referenced by cupsVersion(), and options().

362 {
363  if (group == 0) {
364  if (!currPPD)
365  return;
366  for (int i = 0; i < currPPD->num_groups; ++i) {
367  collectMarkedOptions(list, &currPPD->groups[i]);
368  collectMarkedOptionsHelper(list, &currPPD->groups[i]);
369  }
370  } else {
371  for (int i = 0; i < group->num_subgroups; ++i)
372  collectMarkedOptionsHelper(list, &group->subgroups[i]);
373  }
374 }
void collectMarkedOptionsHelper(QStringList &list, const ppd_group_t *group) const
Definition: qcups.cpp:376
ppd_file_t * currPPD
Definition: qcups_p.h:111
void collectMarkedOptions(QStringList &list, const ppd_group_t *group=0) const
Definition: qcups.cpp:361

◆ collectMarkedOptionsHelper()

void QCUPSSupport::collectMarkedOptionsHelper ( QStringList list,
const ppd_group_t *  group 
) const
private

Definition at line 376 of file qcups.cpp.

Referenced by collectMarkedOptions(), and cupsVersion().

377 {
378  for (int i = 0; i < group->num_options; ++i) {
379  for (int j = 0; j < group->options[i].num_choices; ++j) {
380  if (group->options[i].choices[j].marked == 1 && qstrcmp(group->options[i].choices[j].choice, group->options[i].defchoice) != 0)
381  list << QString::fromLocal8Bit(group->options[i].keyword) << QString::fromLocal8Bit(group->options[i].choices[j].choice);
382  }
383  }
384 }
static QString fromLocal8Bit(const char *, int size=-1)
Returns a QString initialized with the first size characters of the 8-bit string str.
Definition: qstring.cpp:4245
int qstrcmp(const QByteArray &str1, const char *str2)
Definition: qbytearray.cpp:336

◆ cupsVersion()

static int QCUPSSupport::cupsVersion ( )
inlinestatic

Definition at line 75 of file qcups_p.h.

Referenced by QPdfBaseEnginePrivate::closePrintDevice(), QPrinter::init(), and QPrinter::setPrinterName().

75 { return isAvailable() ? CUPS_VERSION_MAJOR*10000+CUPS_VERSION_MINOR*100+CUPS_VERSION_PATCH : 0; }
static bool isAvailable()
Definition: qcups.cpp:216

◆ currentPPD()

const ppd_file_t * QCUPSSupport::currentPPD ( ) const

◆ currentPrinterIndex()

int QCUPSSupport::currentPrinterIndex ( ) const

Definition at line 211 of file qcups.cpp.

Referenced by cupsVersion(), and QUnixPrintWidgetPrivate::QUnixPrintWidgetPrivate().

212 {
213  return currPrinterIndex;
214 }
int currPrinterIndex
Definition: qcups_p.h:110

◆ isAvailable()

bool QCUPSSupport::isAvailable ( )
static

Definition at line 216 of file qcups.cpp.

Referenced by QUnixPrintWidgetPrivate::_q_printerChanged(), cupsVersion(), QPageSetupDialogPrivate::init(), QPdfBaseEnginePrivate::openPrintDevice(), QPdfBaseEnginePrivate::pageRect(), QPdfBaseEnginePrivate::paperRect(), printerHasPPD(), QPdfBaseEngine::property(), QCUPSSupport(), QPdfBaseEngine::QPdfBaseEngine(), qt_getLprPrinters(), QUnixPrintWidgetPrivate::QUnixPrintWidgetPrivate(), QPageSetupWidget::selectPrinter(), QPrintPropertiesDialog::selectPrinter(), QUnixPrintWidgetPrivate::setCupsProperties(), and QPageSetupWidget::setupPrinter().

217 {
218  if(!cupsLoaded)
219  resolveCups();
220 
221  return _cupsGetDests &&
222  _cupsFreeDests &&
223  _cupsGetPPD &&
224  _ppdOpenFile &&
226  _ppdClose &&
228  _ppdMarkOption &&
230  _cupsSetDests &&
231  _cupsLangGet &&
233  _cupsAddOption &&
234  (qt_cups_num_printers > 0);
235 }
static PPDMarkOption _ppdMarkOption
Definition: qcups.cpp:79
static CupsGetPPD _cupsGetPPD
Definition: qcups.cpp:74
static CupsLangEncoding _cupsLangEncoding
Definition: qcups.cpp:83
static int qt_cups_num_printers
Definition: qcups.cpp:71
static CupsAddOption _cupsAddOption
Definition: qcups.cpp:84
static CupsSetDests _cupsSetDests
Definition: qcups.cpp:81
static void resolveCups()
Definition: qcups.cpp:88
static CupsMarkOptions _cupsMarkOptions
Definition: qcups.cpp:78
static PPDMarkDefaults _ppdMarkDefaults
Definition: qcups.cpp:76
static CupsFreeDests _cupsFreeDests
Definition: qcups.cpp:73
static CupsFreeOptions _cupsFreeOptions
Definition: qcups.cpp:80
static CupsGetDests _cupsGetDests
Definition: qcups.cpp:72
static bool cupsLoaded
Definition: qcups.cpp:70
static PPDClose _ppdClose
Definition: qcups.cpp:77
static PPDOpenFile _ppdOpenFile
Definition: qcups.cpp:75
static CupsLangGet _cupsLangGet
Definition: qcups.cpp:82

◆ markOption()

int QCUPSSupport::markOption ( const char *  name,
const char *  value 
)

Definition at line 264 of file qcups.cpp.

Referenced by cupsVersion(), and QPPDOptionsEditor::setModelData().

265 {
266  return _ppdMarkOption(currPPD, name, value);
267 }
static PPDMarkOption _ppdMarkOption
Definition: qcups.cpp:79
ppd_file_t * currPPD
Definition: qcups_p.h:111
const char * name

◆ options()

QStringList QCUPSSupport::options ( ) const

Definition at line 335 of file qcups.cpp.

Referenced by cupsVersion(), printerOption(), QUnixPrintWidgetPrivate::setCupsProperties(), setCurrentPrinter(), and QPageSetupWidget::setupPrinter().

336 {
337  QStringList list;
338  collectMarkedOptions(list);
339  return list;
340 }
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
void collectMarkedOptions(QStringList &list, const ppd_group_t *group=0) const
Definition: qcups.cpp:361

◆ pageRect()

QRect QCUPSSupport::pageRect ( const char *  choice) const

Definition at line 321 of file qcups.cpp.

Referenced by cupsVersion(), QPageSetupWidget::selectPrinter(), QUnixPrintWidgetPrivate::setCupsProperties(), and QPageSetupWidget::setupPrinter().

322 {
323  if (!currPPD)
324  return QRect();
325  for (int i = 0; i < currPPD->num_sizes; ++i) {
326  if (qstrcmp(currPPD->sizes[i].name, choice) == 0)
327  return QRect(qRound(currPPD->sizes[i].left),
328  qRound(currPPD->sizes[i].length - currPPD->sizes[i].top),
329  qRound(currPPD->sizes[i].right - currPPD->sizes[i].left),
330  qRound(currPPD->sizes[i].top - currPPD->sizes[i].bottom));
331  }
332  return QRect();
333 }
ppd_file_t * currPPD
Definition: qcups_p.h:111
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
int qstrcmp(const QByteArray &str1, const char *str2)
Definition: qbytearray.cpp:336
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ pageSizes()

const ppd_option_t * QCUPSSupport::pageSizes ( ) const

Definition at line 259 of file qcups.cpp.

Referenced by cupsVersion(), qt_getLprPrinters(), QPageSetupWidget::selectPrinter(), and QUnixPrintWidgetPrivate::setCupsProperties().

260 {
261  return page_sizes;
262 }
const ppd_option_t * page_sizes
Definition: qcups_p.h:109

◆ paperRect()

QRect QCUPSSupport::paperRect ( const char *  choice) const

Definition at line 310 of file qcups.cpp.

Referenced by QPageSetupWidget::_q_paperSizeChanged(), cupsVersion(), QPageSetupWidget::selectPrinter(), QUnixPrintWidgetPrivate::setCupsProperties(), and QPageSetupWidget::setupPrinter().

311 {
312  if (!currPPD)
313  return QRect();
314  for (int i = 0; i < currPPD->num_sizes; ++i) {
315  if (qstrcmp(currPPD->sizes[i].name, choice) == 0)
316  return QRect(0, 0, qRound(currPPD->sizes[i].width), qRound(currPPD->sizes[i].length));
317  }
318  return QRect();
319 }
ppd_file_t * currPPD
Definition: qcups_p.h:111
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
int qstrcmp(const QByteArray &str1, const char *str2)
Definition: qbytearray.cpp:336
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ ppdOption()

const ppd_option_t * QCUPSSupport::ppdOption ( const char *  key) const

Definition at line 237 of file qcups.cpp.

Referenced by cupsVersion(), QPrintDialogPrivate::selectPrinter(), and setCurrentPrinter().

238 {
239  if (currPPD) {
240  for (int gr = 0; gr < currPPD->num_groups; ++gr) {
241  for (int opt = 0; opt < currPPD->groups[gr].num_options; ++opt) {
242  if (qstrcmp(currPPD->groups[gr].options[opt].keyword, key) == 0)
243  return &currPPD->groups[gr].options[opt];
244  }
245  }
246  }
247  return 0;
248 }
ppd_file_t * currPPD
Definition: qcups_p.h:111
int key
int qstrcmp(const QByteArray &str1, const char *str2)
Definition: qbytearray.cpp:336

◆ printerHasPPD()

bool QCUPSSupport::printerHasPPD ( const char *  printerName)
static

Definition at line 342 of file qcups.cpp.

Referenced by cupsVersion(), and QPrinter::setPrinterName().

343 {
344  if (!isAvailable())
345  return false;
346  const char *ppdFile = _cupsGetPPD(printerName);
347  if (ppdFile)
348  unlink(ppdFile);
349  return (ppdFile != 0);
350 }
static CupsGetPPD _cupsGetPPD
Definition: qcups.cpp:74
static bool isAvailable()
Definition: qcups.cpp:216

◆ printerOption()

const cups_option_t * QCUPSSupport::printerOption ( const QString key) const

Definition at line 250 of file qcups.cpp.

Referenced by QUnixPrintWidgetPrivate::_q_printerChanged(), and cupsVersion().

251 {
252  for (int i = 0; i < printers[currPrinterIndex].num_options; ++i) {
254  return &printers[currPrinterIndex].options[i];
255  }
256  return 0;
257 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
cups_dest_t * printers
Definition: qcups_p.h:108
QStringList options() const
Definition: qcups.cpp:335
const char * name
int currPrinterIndex
Definition: qcups_p.h:110

◆ printFile()

int QCUPSSupport::printFile ( const char *  printerName,
const char *  filename,
const char *  title,
int  num_options,
cups_option_t *  options 
)

Definition at line 394 of file qcups.cpp.

Referenced by QPdfBaseEnginePrivate::closePrintDevice(), and cupsVersion().

396 {
397  return _cupsPrintFile(printerName, filename, title, num_options, options);
398 }
static CupsPrintFile _cupsPrintFile
Definition: qcups.cpp:86
QStringList options() const
Definition: qcups.cpp:335

◆ saveOptions()

void QCUPSSupport::saveOptions ( QList< const ppd_option_t *>  options,
QList< const char *>  markedOptions 
)

Definition at line 269 of file qcups.cpp.

Referenced by cupsVersion(), and QPrintPropertiesDialog::setupPrinter().

270 {
271  int oldOptionCount = printers[currPrinterIndex].num_options;
272  cups_option_t* oldOptions = printers[currPrinterIndex].options;
273 
274  int newOptionCount = 0;
275  cups_option_t* newOptions = 0;
276 
277  // copying old options that are not on the new list
278  for (int i = 0; i < oldOptionCount; ++i) {
279  bool contains = false;
280  for (int j = 0; j < options.count(); ++j) {
281  if (qstrcmp(options.at(j)->keyword, oldOptions[i].name) == 0) {
282  contains = true;
283  break;
284  }
285  }
286 
287  if (!contains) {
288  newOptionCount = _cupsAddOption(oldOptions[i].name, oldOptions[i].value, newOptionCount, &newOptions);
289  }
290  }
291 
292  // we can release old option list
293  _cupsFreeOptions(oldOptionCount, oldOptions);
294 
295  // adding marked options
296  for (int i = 0; i < markedOptions.count(); ++i) {
297  const char* name = markedOptions.at(i);
298  ++i;
299  newOptionCount = _cupsAddOption(name, markedOptions.at(i), newOptionCount, &newOptions);
300  }
301 
302  // placing the new option list
303  printers[currPrinterIndex].num_options = newOptionCount;
304  printers[currPrinterIndex].options = newOptions;
305 
306  // saving new default values
308 }
static CupsAddOption _cupsAddOption
Definition: qcups.cpp:84
static CupsSetDests _cupsSetDests
Definition: qcups.cpp:81
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
cups_dest_t * printers
Definition: qcups_p.h:108
const char * name
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
static CupsFreeOptions _cupsFreeOptions
Definition: qcups.cpp:80
int qstrcmp(const QByteArray &str1, const char *str2)
Definition: qbytearray.cpp:336
int currPrinterIndex
Definition: qcups_p.h:110
int prnCount
Definition: qcups_p.h:107

◆ setCurrentPrinter()

const ppd_file_t * QCUPSSupport::setCurrentPrinter ( int  index)

Definition at line 178 of file qcups.cpp.

Referenced by QUnixPrintWidgetPrivate::_q_printerChanged(), cupsVersion(), QCUPSSupport(), and qt_getLprPrinters().

179 {
180  Q_ASSERT(index >= 0 && index <= prnCount);
181  if (index == prnCount)
182  return 0;
183 
185 
186  if (currPPD)
188  currPPD = 0;
189  page_sizes = 0;
190 
191  const char *ppdFile = _cupsGetPPD(printers[index].name);
192 
193  if (!ppdFile)
194  return 0;
195 
196  currPPD = _ppdOpenFile(ppdFile);
197  unlink(ppdFile);
198 
199  // marking default options
201 
202  // marking options explicitly set
204 
205  // getting pointer to page sizes
206  page_sizes = ppdOption("PageSize");
207 
208  return currPPD;
209 }
const ppd_option_t * ppdOption(const char *key) const
Definition: qcups.cpp:237
static CupsGetPPD _cupsGetPPD
Definition: qcups.cpp:74
const ppd_option_t * page_sizes
Definition: qcups_p.h:109
static CupsMarkOptions _cupsMarkOptions
Definition: qcups.cpp:78
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
cups_dest_t * printers
Definition: qcups_p.h:108
static PPDMarkDefaults _ppdMarkDefaults
Definition: qcups.cpp:76
ppd_file_t * currPPD
Definition: qcups_p.h:111
QStringList options() const
Definition: qcups.cpp:335
const char * name
static PPDClose _ppdClose
Definition: qcups.cpp:77
static PPDOpenFile _ppdOpenFile
Definition: qcups.cpp:75
quint16 index
int currPrinterIndex
Definition: qcups_p.h:110
int prnCount
Definition: qcups_p.h:107

◆ tempFd()

QPair< int, QString > QCUPSSupport::tempFd ( )

Definition at line 386 of file qcups.cpp.

Referenced by cupsVersion(), and QPdfBaseEnginePrivate::openPrintDevice().

387 {
388  char filename[512];
389  int fd = _cupsTempFd(filename, 512);
390  return QPair<int, QString>(fd, QString::fromLocal8Bit(filename));
391 }
static QString fromLocal8Bit(const char *, int size=-1)
Returns a QString initialized with the first size characters of the 8-bit string str.
Definition: qstring.cpp:4245
static CupsTempFd _cupsTempFd
Definition: qcups.cpp:85

◆ unicodeString()

QString QCUPSSupport::unicodeString ( const char *  s)

Definition at line 352 of file qcups.cpp.

Referenced by cupsVersion(), and QPPDOptionsModel::data().

353 {
354 #ifndef QT_NO_TEXTCODEC
355  return codec->toUnicode(s);
356 #else
357  return QLatin1String(s);
358 #endif
359 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QTextCodec * codec
Definition: qcups_p.h:113
QString toUnicode(const QByteArray &) const
Converts a from the encoding of this codec to Unicode, and returns the result in a QString...

Properties

◆ codec

QTextCodec* QCUPSSupport::codec
private

Definition at line 113 of file qcups_p.h.

Referenced by QCUPSSupport(), and unicodeString().

◆ currPPD

ppd_file_t* QCUPSSupport::currPPD
private

◆ currPrinterIndex

int QCUPSSupport::currPrinterIndex
private

◆ page_sizes

const ppd_option_t* QCUPSSupport::page_sizes
private

Definition at line 109 of file qcups_p.h.

Referenced by pageSizes(), and setCurrentPrinter().

◆ printers

cups_dest_t* QCUPSSupport::printers
private

◆ prnCount

int QCUPSSupport::prnCount
private

The documentation for this class was generated from the following files: