20 #include "kcupsprinterimpl.h"
23 #include "kmfactory.h"
24 #include "kmmanager.h"
25 #include "cupsinfos.h"
28 #include <cups/cups.h>
32 static void mapToCupsOptions(
const TQMap<TQString,TQString>& opts, TQString& cmd);
34 TQSize rangeToSize(
const TQString& s)
40 if ((p=range.find(
',')) != -1)
42 if ((p=range.find(
'-')) != -1)
44 from = range.left(p).toInt();
45 to = range.right(range.length()-p-1).toInt();
47 else if (!range.isEmpty())
48 from = to = range.toInt();
52 return TQSize(from,to);
56 KCupsPrinterImpl::KCupsPrinterImpl(TQObject *parent,
const char *name,
const TQStringList & )
57 : KPrinterImpl(parent,name)
61 KCupsPrinterImpl::~KCupsPrinterImpl()
65 bool KCupsPrinterImpl::setupCommand(TQString& cmd,
KPrinter *printer)
68 if (!printer)
return false;
70 TQString hoststr = TQString::fromLatin1(
"%1:%2").arg(CupsInfos::self()->host()).arg(CupsInfos::self()->port());
71 cmd = TQString::fromLatin1(
"cupsdoprint -P %1 -J %3 -H %2").arg(quote(printer->
printerName())).arg(quote(hoststr)).arg(quote(printer->
docName()));
72 if (!CupsInfos::self()->login().isEmpty())
74 TQString userstr(CupsInfos::self()->login());
77 cmd.append(
" -U ").append(quote(userstr));
79 mapToCupsOptions(printer->
options(),cmd);
83 void KCupsPrinterImpl::preparePrinting(
KPrinter *printer)
86 TQString o = printer->
option(
"orientation-requested");
87 printer->
setOption(
"kde-orientation",(o ==
"4" || o ==
"5" ?
"Landscape" :
"Portrait"));
90 printer->
setOption(
"orientation-requested",(o ==
"5" || o ==
"6" ?
"6" :
"3"));
93 if (!printer->
option(
"kde-copies").isEmpty()) printer->
setOption(
"copies",printer->
option(
"kde-copies"));
99 if (!printer->
option(
"kde-range").isEmpty())
101 if (printer->
option(
"kde-pageorder") ==
"Reverse")
103 o = printer->
option(
"kde-pageset");
104 if (!o.isEmpty() && o !=
"0")
105 printer->
setOption(
"page-set",(o ==
"1" ?
"odd" :
"even"));
106 printer->
setOption(
"multiple-document-handling",(printer->
option(
"kde-collate") ==
"Collate" ?
"separate-documents-collated-copies" :
"separate-documents-uncollated-copies"));
110 TQString range = printer->
option(
"kde-range");
111 if (!range.isEmpty())
113 TQSize s = rangeToSize(range);
114 printer->
setOption(
"kde-from",TQString::number(s.width()));
115 printer->
setOption(
"kde-to",TQString::number(s.height()));
120 KPrinterImpl::preparePrinting(printer);
123 void KCupsPrinterImpl::broadcastOption(
const TQString& key,
const TQString& value)
125 KPrinterImpl::broadcastOption(key,value);
126 if (key ==
"kde-orientation")
127 KPrinterImpl::broadcastOption(
"orientation-requested",(value ==
"Landscape" ?
"4" :
"3"));
128 else if (key ==
"kde-pagesize")
130 TQString pagename = TQString::fromLatin1(pageSizeToPageName((
KPrinter::PageSize)value.toInt()));
131 KPrinterImpl::broadcastOption(
"PageSize",pagename);
133 KPrinterImpl::broadcastOption(
"media",pagename);
139 static void mapToCupsOptions(
const TQMap<TQString,TQString>& opts, TQString& cmd)
142 for (TQMap<TQString,TQString>::ConstIterator it=opts.begin(); it!=opts.end(); ++it)
145 if (!it.key().startsWith(
"kde-") && !it.key().startsWith(
"app-") && !it.key().startsWith(
"_kde"))
147 TQString key = it.key();
148 if (key.startsWith(
"KDEPrint-"))
152 optstr.append(
" ").append(key);
153 if (!it.data().isEmpty())
154 optstr.append(
"=").append(it.data());
157 if (!optstr.isEmpty())
158 cmd.append(
" -o ").append( TDEProcess::quote( optstr ) );
const TQString & option(const TQString &key) const
Starts the add printer wizard.
const TQMap< TQString, TQString > & options() const
Returns the complete set of print options from the KPrinter object.
This class is the main interface to access the TDE print framework.
TQString docName() const
See TQPrinter::docName().
static PageSelectionType pageSelection()
Returns the page selection mode of the current application.
TQString printerName() const
See TQPrinter::printerName().
static ApplicationType applicationType()
Returns the application type concerning the print dialog.
PageSize
Defines the paper size to use.
void setOption(const TQString &key, const TQString &value)
Adds or modifies an option in the KPrinter object.