20#include "kcupsprinterimpl.h"
30#include <tdeprocess.h>
31#include <tdestandarddirs.h>
34static void mapToCupsOptions(
const TQMap<TQString,TQString>& opts, TQString& cmd);
36TQSize rangeToSize(
const TQString& s)
42 if ((p=range.find(
',')) != -1)
44 if ((p=range.find(
'-')) != -1)
46 from = range.left(p).toInt();
47 to = range.right(range.length()-p-1).toInt();
49 else if (!range.isEmpty())
50 from = to = range.toInt();
54 return TQSize(from,to);
58KCupsPrinterImpl::KCupsPrinterImpl(TQObject *parent,
const char *name,
const TQStringList & )
59: KPrinterImpl(parent,name)
63KCupsPrinterImpl::~KCupsPrinterImpl()
67bool KCupsPrinterImpl::setupCommand(TQString& cmd,
KPrinter *printer)
70 if (!printer)
return false;
72 TQString exe = TDEStandardDirs::findExe(
"cupsdoprint");
75 printer->
setErrorMessage(i18n(
"Unable to locate the CUPS print helper <b>cupsdoprint</b>."));
79 TQString hoststr = TQString::fromLatin1(
"%1:%2").arg(CupsInfos::self()->host()).arg(CupsInfos::self()->port());
80 cmd = TQString::fromLatin1(
"%1 -P %2 -J %4 -H %3").arg(quote(exe)).arg(quote(printer->
printerName())).arg(quote(hoststr)).arg(quote(printer->
docName()));
81 if (!CupsInfos::self()->login().isEmpty())
83 TQString userstr(CupsInfos::self()->login());
86 cmd.append(
" -U ").append(quote(userstr));
88 mapToCupsOptions(printer->
options(),cmd);
92void KCupsPrinterImpl::preparePrinting(
KPrinter *printer)
95 TQString o = printer->
option(
"orientation-requested");
96 printer->
setOption(
"kde-orientation",(o ==
"4" || o ==
"5" ?
"Landscape" :
"Portrait"));
99 printer->
setOption(
"orientation-requested",(o ==
"5" || o ==
"6" ?
"6" :
"3"));
102 if (!printer->
option(
"kde-copies").isEmpty()) printer->
setOption(
"copies",printer->
option(
"kde-copies"));
108 if (!printer->
option(
"kde-range").isEmpty())
110 if (printer->
option(
"kde-pageorder") ==
"Reverse")
112 o = printer->
option(
"kde-pageset");
113 if (!o.isEmpty() && o !=
"0")
114 printer->
setOption(
"page-set",(o ==
"1" ?
"odd" :
"even"));
115 printer->
setOption(
"multiple-document-handling",(printer->
option(
"kde-collate") ==
"Collate" ?
"separate-documents-collated-copies" :
"separate-documents-uncollated-copies"));
119 TQString range = printer->
option(
"kde-range");
120 if (!range.isEmpty())
122 TQSize s = rangeToSize(range);
123 printer->
setOption(
"kde-from",TQString::number(s.width()));
124 printer->
setOption(
"kde-to",TQString::number(s.height()));
129 KPrinterImpl::preparePrinting(printer);
132void KCupsPrinterImpl::broadcastOption(
const TQString& key,
const TQString& value)
134 KPrinterImpl::broadcastOption(key,value);
135 if (key ==
"kde-orientation")
136 KPrinterImpl::broadcastOption(
"orientation-requested",(value ==
"Landscape" ?
"4" :
"3"));
137 else if (key ==
"kde-pagesize")
139 TQString pagename = TQString::fromLatin1(pageSizeToPageName((
KPrinter::PageSize)value.toInt()));
140 KPrinterImpl::broadcastOption(
"PageSize",pagename);
142 KPrinterImpl::broadcastOption(
"media",pagename);
148static void mapToCupsOptions(
const TQMap<TQString,TQString>& opts, TQString& cmd)
151 for (TQMap<TQString,TQString>::ConstIterator it=opts.begin(); it!=opts.end(); ++it)
154 if (!it.key().startsWith(
"kde-") && !it.key().startsWith(
"app-") && !it.key().startsWith(
"_kde"))
156 TQString key = it.key();
157 if (key.startsWith(
"KDEPrint-"))
161 optstr.append(
" ").append(key);
162 if (!it.data().isEmpty())
163 optstr.append(
"=").append(it.data());
166 if (!optstr.isEmpty())
167 cmd.append(
" -o ").append( TDEProcess::quote( optstr ) );
This class is the main interface to access the TDE print framework.
TQString docName() const
See TQPrinter::docName().
PageSize
Defines the paper size to use.
const TQString & option(const TQString &key) const
Starts the add printer wizard.
void setErrorMessage(const TQString &msg)
Sets the last error message.
TQString printerName() const
See TQPrinter::printerName().
void setOption(const TQString &key, const TQString &value)
Adds or modifies an option in the KPrinter object.
const TQMap< TQString, TQString > & options() const
Returns the complete set of print options from the KPrinter object.
static PageSelectionType pageSelection()
Returns the page selection mode of the current application.
static ApplicationType applicationType()
Returns the application type concerning the print dialog.