summaryrefslogtreecommitdiffstats
path: root/src/gui/painting/qprinterinfo_unix.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/painting/qprinterinfo_unix.cpp')
-rw-r--r--src/gui/painting/qprinterinfo_unix.cpp106
1 files changed, 18 insertions, 88 deletions
diff --git a/src/gui/painting/qprinterinfo_unix.cpp b/src/gui/painting/qprinterinfo_unix.cpp
index aa220aad57..3c66481b4d 100644
--- a/src/gui/painting/qprinterinfo_unix.cpp
+++ b/src/gui/painting/qprinterinfo_unix.cpp
@@ -45,9 +45,9 @@
#include <qfile.h>
#include <qfileinfo.h>
#include <qdir.h>
-#include <qprintdialog.h>
#include <qlibrary.h>
#include <qtextstream.h>
+#include <qcoreapplication.h>
#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
# include <private/qcups_p.h>
@@ -130,10 +130,8 @@ void qt_perhapsAddPrinter(QList<QPrinterDescription> *printers, const QString &n
if (printers->at(i).samePrinter(name))
return;
-#ifndef QT_NO_PRINTDIALOG
if (host.isEmpty())
- host = QPrintDialog::tr("locally connected");
-#endif
+ host = QCoreApplication::translate("QPrinter", "locally connected");
printers->append(QPrinterDescription(name.simplified(), host.simplified(), comment.simplified(), aliases));
}
@@ -153,11 +151,9 @@ void qt_parsePrinterDesc(QString printerDesc, QList<QPrinterDescription> *printe
if (j > 0 && j < i) {
printerName = printerDesc.left(j);
aliases = printerDesc.mid(j + 1, i - j - 1).split(QLatin1Char('|'));
-#ifndef QT_NO_PRINTDIALOG
// try extracting a comment from the aliases
- printerComment = QPrintDialog::tr("Aliases: %1")
+ printerComment = QCoreApplication::translate("QPrinter", "Aliases: %1")
.arg(aliases.join(QLatin1String(", ")));
-#endif
} else {
printerName = printerDesc.left(i);
}
@@ -379,10 +375,8 @@ char *qt_parsePrintersConf(QList<QPrinterDescription> *printers, bool *found)
if (j > 0) {
// try extracting a comment from the aliases
aliases = printerDesc.mid(j + 1, i - j - 1).split(QLatin1Char('|'));
-#ifndef QT_NO_PRINTDIALOG
- printerComment = QPrintDialog::tr("Aliases: %1")
+ printerComment = QCoreApplication::translate("QPrinter", "Aliases: %1")
.arg(aliases.join(QLatin1String(", ")));
-#endif
}
// look for signs of this being a remote printer
i = printerDesc.indexOf(
@@ -593,9 +587,6 @@ void qt_parseEtcLpMember(QList<QPrinterDescription> *printers)
if (dirs.isEmpty())
return;
-#ifdef QT_NO_PRINTDIALOG
- Q_UNUSED(printers);
-#else
QString tmp;
for (int i = 0; i < dirs.size(); ++i) {
QFileInfo printer = dirs.at(i);
@@ -605,10 +596,9 @@ void qt_parseEtcLpMember(QList<QPrinterDescription> *printers)
// decent way to locate aliases and remote printers.
if (printer.isFile())
qt_perhapsAddPrinter(printers, printer.fileName(),
- QPrintDialog::tr("unknown"),
+ QCoreApplication::translate("QPrinter", "unknown"),
QLatin1String(""));
}
-#endif
}
// IRIX 6.x
@@ -751,7 +741,7 @@ void qt_parseQconfig(QList<QPrinterDescription> *printers)
} while (!ts.atEnd());
}
-int qt_getLprPrinters(QList<QPrinterDescription>& printers)
+Q_GUI_EXPORT int qt_getLprPrinters(QList<QPrinterDescription>& printers)
{
QByteArray etcLpDefault;
qt_parsePrintcap(&printers, QLatin1String("/etc/printcap"));
@@ -801,12 +791,10 @@ int qt_getLprPrinters(QList<QPrinterDescription>& printers)
dollarPrinter = QString::fromLocal8Bit(qgetenv("NPRINTER"));
if (dollarPrinter.isEmpty())
dollarPrinter = QString::fromLocal8Bit(qgetenv("NGPRINTER"));
-#ifndef QT_NO_PRINTDIALOG
if (!dollarPrinter.isEmpty())
qt_perhapsAddPrinter(&printers, dollarPrinter,
- QPrintDialog::tr("unknown"),
+ QCoreApplication::translate("QPrinter", "unknown"),
QLatin1String(""));
-#endif
}
QRegExp ps(QLatin1String("[^a-z]ps(?:[^a-z]|$)"));
@@ -847,78 +835,20 @@ int qt_getLprPrinters(QList<QPrinterDescription>& printers)
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
-QList<QPrinterInfo> QPrinterInfo::availablePrinters()
-{
- QList<QPrinterInfo> printers;
-
-#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
- if (QCUPSSupport::isAvailable()) {
- QCUPSSupport cups;
- int cupsPrinterCount = cups.availablePrintersCount();
- const cups_dest_t* cupsPrinters = cups.availablePrinters();
- for (int i = 0; i < cupsPrinterCount; ++i) {
- QString printerName(QString::fromLocal8Bit(cupsPrinters[i].name));
- if (cupsPrinters[i].instance)
- printerName += QLatin1Char('/') + QString::fromLocal8Bit(cupsPrinters[i].instance);
-
- QPrinterInfo printerInfo(printerName);
- if (cupsPrinters[i].is_default)
- printerInfo.d_ptr->isDefault = true;
- printerInfo.d_ptr->cupsPrinterIndex = i;
- printers.append(printerInfo);
- }
- } else
-#endif
- {
- QList<QPrinterDescription> lprPrinters;
- int defprn = qt_getLprPrinters(lprPrinters);
- // populating printer combo
- foreach (const QPrinterDescription &description, lprPrinters)
- printers.append(QPrinterInfo(description.name));
- if (defprn >= 0 && defprn < printers.size())
- printers[defprn].d_ptr->isDefault = true;
- }
-
- return printers;
-}
-
-QPrinterInfo QPrinterInfo::defaultPrinter()
-{
- QList<QPrinterInfo> printers = availablePrinters();
- foreach (const QPrinterInfo &printerInfo, printers) {
- if (printerInfo.isDefault())
- return printerInfo;
- }
-
- return printers.value(0);
-}
-
-QList<QPrinter::PaperSize> QPrinterInfo::supportedPaperSizes() const
+QList<QPrinter::PaperSize> qt_getCupsPrinterPaperSizes(int cupsPrinterIndex)
{
+ QList<QPrinter::PaperSize> result;
#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
- const Q_D(QPrinterInfo);
-
- if (isNull())
- return d->paperSizes;
-
- if (!d->hasPaperSizes) {
- d->hasPaperSizes = true;
-
- if (QCUPSSupport::isAvailable()) {
- // Find paper sizes from CUPS.
- QCUPSSupport cups;
- cups.setCurrentPrinter(d->cupsPrinterIndex);
- const ppd_option_t* sizes = cups.pageSizes();
- if (sizes) {
- for (int j = 0; j < sizes->num_choices; ++j)
- d->paperSizes.append(string2PaperSize(sizes->choices[j].choice));
- }
- }
+ if (!QCUPSSupport::isAvailable() || cupsPrinterIndex < 0)
+ return result;
+ // Find paper sizes from CUPS.
+ QCUPSSupport cups;
+ cups.setCurrentPrinter(cupsPrinterIndex);
+ if (const ppd_option_t* size = cups.pageSizes()) {
+ for (int j = 0; j < size->num_choices; ++j)
+ result.append(string2PaperSize(size->choices[j].choice));
}
-
- return d->paperSizes;
-#else
- return QList<QPrinter::PaperSize>();
+ return result;
#endif
}