20 #include "lprhandler.h"
21 #include "kmprinter.h"
22 #include "printcapentry.h"
23 #include "kmmanager.h"
24 #include "lprsettings.h"
28 #include <tqtextstream.h>
29 #include <tqvaluestack.h>
30 #include <tdelocale.h>
34 LprHandler::LprHandler(
const TQString& name, KMManager *mgr)
35 : m_name(name), m_manager(mgr)
39 LprHandler::~LprHandler()
43 bool LprHandler::validate(PrintcapEntry*)
48 KMPrinter* LprHandler::createPrinter(PrintcapEntry *entry)
50 KMPrinter *prt =
new KMPrinter;
51 prt->setPrinterName(entry->name);
52 prt->setName(entry->name);
53 prt->setType(KMPrinter::Printer);
57 bool LprHandler::completePrinter(KMPrinter *prt, PrintcapEntry *entry,
bool)
59 prt->setDescription(i18n(
"Unknown (unrecognized entry)"));
60 TQString val = entry->field(
"lp");
62 if (!val.isEmpty() && val !=
"/dev/null")
64 int p = val.find(
'@');
67 prt->setLocation(i18n(
"Remote queue (%1) on %2").arg(val.left(p)).arg(val.mid(p+1)));
68 uri.setProtocol(
"lpd");
69 uri.setHost(val.mid(p+1));
70 uri.setPath(
"/" + val.left(p));
72 else if ((p = val.find(
'%')) != -1)
74 prt->setLocation(i18n(
"Network printer (%1)").arg(
"socket"));
75 uri.setProtocol(
"socket");
76 uri.setHost(val.left(p));
77 uri.setPort(val.mid(p+1).toInt());
81 prt->setLocation(i18n(
"Local printer on %1").arg(val));
82 uri.setProtocol(
"parallel");
86 else if (!(val = entry->field(
"rp")).isEmpty())
88 TQString rm = entry->has(
"rm") ?
90 LprSettings::self()->defaultRemoteHost();
91 prt->setLocation(i18n(
"Remote queue (%1) on %2").arg(val).arg(rm));
92 uri.setProtocol(
"lpd");
94 uri.setPath(
"/" + val);
97 prt->setLocation(i18n(
"Unknown (unrecognized entry)"));
98 prt->setDevice(uri.url());
102 DrMain* LprHandler::loadDriver(KMPrinter*, PrintcapEntry*,
bool)
104 manager()->setErrorMsg(i18n(
"Unrecognized entry."));
108 bool LprHandler::savePrinterDriver(KMPrinter*, PrintcapEntry*, DrMain*,
bool*)
110 manager()->setErrorMsg(i18n(
"Unrecognized entry."));
114 DrMain* LprHandler::loadDbDriver(
const TQString&)
116 manager()->setErrorMsg(i18n(
"Unrecognized entry."));
120 PrintcapEntry* LprHandler::createEntry(KMPrinter *prt)
123 KURL uri ( prt->device() );
124 TQString prot = uri.protocol();
125 if (!prot.isEmpty() && prot !=
"parallel" && prot !=
"file" && prot !=
"lpd" && prot !=
"socket")
127 manager()->setErrorMsg(i18n(
"Unsupported backend: %1.").arg(prot));
130 PrintcapEntry *entry =
new PrintcapEntry;
131 entry->comment =
"# Default handler";
134 entry->addField(
"rm", Field::String, uri.host());
135 TQString rp = uri.path();
138 entry->addField(
"rp", Field::String, rp);
141 entry->addField(
"lp", Field::String, TQString::null);
143 else if ( prot ==
"socket" )
145 TQString lp = uri.host();
146 if ( uri.port() == 0 )
147 lp.append(
"%9100" );
149 lp.append(
"%" ).append( TQString::number( uri.port() ) );
150 entry->addField(
"lp", Field::String, lp);
154 entry->addField(
"lp", Field::String, uri.path());
159 bool LprHandler::removePrinter(KMPrinter*, PrintcapEntry*)
164 TQString LprHandler::printOptions(
KPrinter*)
166 return TQString::null;
169 void LprHandler::reset()
173 DrMain* LprHandler::loadToolDriver(
const TQString& filename)
176 if (f.open(IO_ReadOnly))
178 DrMain *driver =
new DrMain;
179 TQValueStack<DrGroup*> groups;
182 DrListOption *lopt(0);
186 driver->set(
"text",
"Tool Driver");
189 l = TQStringList::split(
'|', t.readLine().stripWhiteSpace(),
false);
194 DrGroup *grp =
new DrGroup;
196 grp->set(
"text", l[2]);
197 groups.top()->addGroup(grp);
200 else if (l[0] ==
"ENDGROUP")
204 else if (l[0] ==
"OPTION")
210 if (l[3] ==
"STRING")
211 opt =
new DrStringOption;
212 else if (l[3] ==
"BOOLEAN")
214 lopt =
new DrBooleanOption;
220 lopt =
new DrListOption;
226 opt->set(
"text", l[2]);
227 groups.top()->addOption(opt);
230 else if (l[0] ==
"CHOICE" && lopt)
232 DrBase *ch =
new DrBase;
234 ch->set(
"text", l[2]);
237 else if (l[0] ==
"DEFAULT" && opt)
239 opt->setValueText(l[1]);
240 opt->set(
"default", l[1]);
248 TQString LprHandler::driverDirectory()
250 if (m_cacheddriverdir.isEmpty())
251 m_cacheddriverdir = driverDirInternal();
252 return m_cacheddriverdir;
255 TQString LprHandler::driverDirInternal()
257 return TQString::null;
260 TQString LprHandler::locateDir(
const TQString& dirname,
const TQString& paths)
262 TQStringList pathlist = TQStringList::split(
':', paths,
false);
263 for (TQStringList::ConstIterator it=pathlist.begin(); it!=pathlist.end(); ++it)
265 TQString testpath = *it +
"/" + dirname;
266 if (::access(TQFile::encodeName(testpath), F_OK) == 0)
269 return TQString::null;
This class is the main interface to access the TDE print framework.