summaryrefslogtreecommitdiffstats
path: root/tdeprint/lpd
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2011-11-06 15:56:40 -0600
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2011-11-06 15:56:40 -0600
commite16866e072f94410321d70daedbcb855ea878cac (patch)
treeee3f52eabde7da1a0e6ca845fb9c2813cf1558cf /tdeprint/lpd
parenta58c20c1a7593631a1b50213c805507ebc16adaf (diff)
downloadtdelibs-e16866e072f94410321d70daedbcb855ea878cac.tar.gz
tdelibs-e16866e072f94410321d70daedbcb855ea878cac.zip
Actually move the kde files that were renamed in the last commit
Diffstat (limited to 'tdeprint/lpd')
-rw-r--r--tdeprint/lpd/Makefile.am18
-rw-r--r--tdeprint/lpd/gschecker.cpp61
-rw-r--r--tdeprint/lpd/gschecker.h40
-rw-r--r--tdeprint/lpd/klpdprinterimpl.cpp51
-rw-r--r--tdeprint/lpd/klpdprinterimpl.h37
-rw-r--r--tdeprint/lpd/kmlpdfactory.cpp52
-rw-r--r--tdeprint/lpd/kmlpdfactory.h35
-rw-r--r--tdeprint/lpd/kmlpdmanager.cpp651
-rw-r--r--tdeprint/lpd/kmlpdmanager.h76
-rw-r--r--tdeprint/lpd/kmlpduimanager.cpp60
-rw-r--r--tdeprint/lpd/kmlpduimanager.h35
-rw-r--r--tdeprint/lpd/lpd.print87
-rw-r--r--tdeprint/lpd/lpdtools.cpp417
-rw-r--r--tdeprint/lpd/lpdtools.h76
-rw-r--r--tdeprint/lpd/make_driver_db_lpd.c112
15 files changed, 1808 insertions, 0 deletions
diff --git a/tdeprint/lpd/Makefile.am b/tdeprint/lpd/Makefile.am
new file mode 100644
index 000000000..5c6559a27
--- /dev/null
+++ b/tdeprint/lpd/Makefile.am
@@ -0,0 +1,18 @@
+INCLUDES= -I$(top_srcdir) -I$(top_srcdir)/tdeprint -I$(top_srcdir)/tdeprint/management $(all_includes)
+
+kde_module_LTLIBRARIES = tdeprint_lpd.la
+
+tdeprint_lpd_la_SOURCES = kmlpdfactory.cpp kmlpdmanager.cpp klpdprinterimpl.cpp kmlpduimanager.cpp \
+ lpdtools.cpp gschecker.cpp
+tdeprint_lpd_la_LDFLAGS = $(all_libraries) -module -avoid-version -no-undefined
+tdeprint_lpd_la_LIBADD = $(top_builddir)/tdeprint/management/libtdeprint_management.la
+tdeprint_lpd_la_METASOURCES = AUTO
+
+noinst_HEADERS = kmlpdfactory.h kmlpdmanager.h klpdprinterimpl.h kmlpduimanager.h lpdtools.h gschecker.h
+
+bin_PROGRAMS = make_driver_db_lpd
+make_driver_db_lpd_SOURCES = make_driver_db_lpd.c
+make_driver_db_lpd_LDADD = $(top_builddir)/tdecore/libtdefakes.la
+
+entry_DATA = lpd.print
+entrydir = $(kde_datadir)/tdeprint/plugins
diff --git a/tdeprint/lpd/gschecker.cpp b/tdeprint/lpd/gschecker.cpp
new file mode 100644
index 000000000..9fe6e290b
--- /dev/null
+++ b/tdeprint/lpd/gschecker.cpp
@@ -0,0 +1,61 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "gschecker.h"
+#include "kpipeprocess.h"
+
+#include <tqfile.h>
+#include <tqtextstream.h>
+
+GsChecker::GsChecker(TQObject *parent, const char *name)
+: TQObject(parent,name)
+{
+}
+
+bool GsChecker::checkGsDriver(const TQString& name)
+{
+ if (m_driverlist.count() == 0)
+ loadDriverList();
+ return m_driverlist.contains(name);
+}
+
+void GsChecker::loadDriverList()
+{
+ KPipeProcess proc;
+ if (proc.open("gs -h",IO_ReadOnly))
+ {
+ QTextStream t(&proc);
+ QString buffer, line;
+ bool ok(false);
+ while (!t.eof())
+ {
+ line = t.readLine().stripWhiteSpace();
+ if (ok)
+ {
+ if (line.find(':') != -1)
+ break;
+ else
+ buffer.append(line).append(" ");
+ }
+ else if (line.startsWith(TQString::tqfromLatin1("Available devices:")))
+ ok = true;
+ }
+ m_driverlist = TQStringList::split(' ',buffer,false);
+ }
+}
diff --git a/tdeprint/lpd/gschecker.h b/tdeprint/lpd/gschecker.h
new file mode 100644
index 000000000..c3c23a5be
--- /dev/null
+++ b/tdeprint/lpd/gschecker.h
@@ -0,0 +1,40 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef GSCHECKER_H
+#define GSCHECKER_H
+
+#include <tqstring.h>
+#include <tqstringlist.h>
+#include <tqobject.h>
+
+class GsChecker : public TQObject
+{
+public:
+ GsChecker(TQObject *parent = 0, const char *name = 0);
+ bool checkGsDriver(const TQString& name);
+
+protected:
+ void loadDriverList();
+
+private:
+ QStringList m_driverlist;
+};
+
+#endif
diff --git a/tdeprint/lpd/klpdprinterimpl.cpp b/tdeprint/lpd/klpdprinterimpl.cpp
new file mode 100644
index 000000000..59f04e74c
--- /dev/null
+++ b/tdeprint/lpd/klpdprinterimpl.cpp
@@ -0,0 +1,51 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "klpdprinterimpl.h"
+#include "kprinter.h"
+
+#include <tqfile.h>
+#include <kstandarddirs.h>
+#include <klocale.h>
+
+KLpdPrinterImpl::KLpdPrinterImpl(TQObject *parent, const char *name)
+: KPrinterImpl(parent,name)
+{
+}
+
+KLpdPrinterImpl::~KLpdPrinterImpl()
+{
+}
+
+TQString KLpdPrinterImpl::executable()
+{
+ return KStandardDirs::findExe("lpr");
+}
+
+bool KLpdPrinterImpl::setupCommand(TQString& cmd, KPrinter *printer)
+{
+ QString exestr = executable();
+ if (exestr.isEmpty())
+ {
+ printer->setErrorMessage(i18n("The <b>%1</b> executable could not be found in your path. Check your installation.").arg("lpr"));
+ return false;
+ }
+ cmd = TQString::tqfromLatin1("%1 -P %2 '-#%3'").arg(exestr).arg(quote(printer->printerName())).arg(printer->numCopies());
+ return true;
+}
diff --git a/tdeprint/lpd/klpdprinterimpl.h b/tdeprint/lpd/klpdprinterimpl.h
new file mode 100644
index 000000000..a757d0c8c
--- /dev/null
+++ b/tdeprint/lpd/klpdprinterimpl.h
@@ -0,0 +1,37 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KLPDPRINTERIMPL_H
+#define KLPDPRINTERIMPL_H
+
+#include "kprinterimpl.h"
+
+class KLpdPrinterImpl : public KPrinterImpl
+{
+public:
+ KLpdPrinterImpl(TQObject *parent = 0, const char *name = 0);
+ ~KLpdPrinterImpl();
+
+ bool setupCommand(TQString&, KPrinter*);
+
+protected:
+ TQString executable();
+};
+
+#endif
diff --git a/tdeprint/lpd/kmlpdfactory.cpp b/tdeprint/lpd/kmlpdfactory.cpp
new file mode 100644
index 000000000..05ee61bd5
--- /dev/null
+++ b/tdeprint/lpd/kmlpdfactory.cpp
@@ -0,0 +1,52 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kmlpdfactory.h"
+#include "kmlpdmanager.h"
+#include "kmlpduimanager.h"
+#include "klpdprinterimpl.h"
+
+extern "C"
+{
+ void* init_tdeprint_lpd()
+ {
+ return new KLpdFactory;
+ }
+};
+
+KLpdFactory::KLpdFactory(TQObject *parent, const char *name)
+: KLibFactory(parent,name)
+{
+}
+
+KLpdFactory::~KLpdFactory()
+{
+}
+
+TQObject* KLpdFactory::createObject(TQObject *parent, const char *name, const char *classname, const TQStringList&)
+{
+ if (strcmp(classname,"KMManager") == 0)
+ return new KMLpdManager(parent,name);
+ else if (strcmp(classname,"KMUiManager") == 0)
+ return new KMLpdUiManager(parent,name);
+ else if (strcmp(classname,"KPrinterImpl") == 0)
+ return new KLpdPrinterImpl(parent,name);
+ else
+ return NULL;
+}
diff --git a/tdeprint/lpd/kmlpdfactory.h b/tdeprint/lpd/kmlpdfactory.h
new file mode 100644
index 000000000..ffc05af71
--- /dev/null
+++ b/tdeprint/lpd/kmlpdfactory.h
@@ -0,0 +1,35 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMLPDFACTORY_H
+#define KMLPDFACTORY_H
+
+#include <klibloader.h>
+
+class KLpdFactory : public KLibFactory
+{
+public:
+ KLpdFactory(TQObject *parent = 0, const char *name = 0);
+ virtual ~KLpdFactory();
+
+protected:
+ TQObject* createObject(TQObject *parent = 0, const char *name = 0, const char *className = TQOBJECT_OBJECT_NAME_STRING, const TQStringList& args = TQStringList());
+};
+
+#endif
diff --git a/tdeprint/lpd/kmlpdmanager.cpp b/tdeprint/lpd/kmlpdmanager.cpp
new file mode 100644
index 000000000..a5612ad58
--- /dev/null
+++ b/tdeprint/lpd/kmlpdmanager.cpp
@@ -0,0 +1,651 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kmlpdmanager.h"
+#include "kmprinter.h"
+#include "kmdbentry.h"
+#include "driver.h"
+#include "kmfactory.h"
+#include "lpdtools.h"
+#include "gschecker.h"
+#include "kpipeprocess.h"
+
+#include <tqfile.h>
+#include <tqfileinfo.h>
+#include <tqtextstream.h>
+#include <tqmap.h>
+#include <tqregexp.h>
+
+#include <klocale.h>
+#include <kstandarddirs.h>
+#include <kconfig.h>
+#include <kprocess.h>
+
+#include <pwd.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+
+// only there to allow testing on my system. Should be removed
+// when everything has proven to be working and stable
+QString lpdprefix = "";
+TQString ptPrinterType(KMPrinter*);
+
+//************************************************************************************************
+
+KMLpdManager::KMLpdManager(TQObject *parent, const char *name)
+: KMManager(parent,name)
+{
+ m_entries.setAutoDelete(true);
+ m_ptentries.setAutoDelete(true);
+ setHasManagement(getuid() == 0);
+ setPrinterOperationMask(KMManager::PrinterCreation|KMManager::PrinterConfigure|KMManager::PrinterRemoval|KMManager::PrinterEnabling);
+ m_gschecker = new GsChecker(this,"GsChecker");
+}
+
+KMLpdManager::~KMLpdManager()
+{
+}
+
+TQString KMLpdManager::driverDbCreationProgram()
+{
+ return TQString::tqfromLatin1("make_driver_db_lpd");
+}
+
+TQString KMLpdManager::driverDirectory()
+{
+ return TQString::tqfromLatin1("/usr/lib/rhs/rhs-printfilters");
+}
+
+bool KMLpdManager::completePrinter(KMPrinter *printer)
+{
+ return completePrinterShort(printer);
+}
+
+bool KMLpdManager::completePrinterShort(KMPrinter *printer)
+{
+ PrintcapEntry *entry = m_entries.find(printer->name());
+ if (entry)
+ {
+ QString type(entry->comment(2)), driver(entry->comment(7)), lp(entry->arg("lp"));
+ printer->setDescription(i18n("Local printer queue (%1)").arg(type.isEmpty() ? i18n("Unknown type of local printer queue", "Unknown") : type));
+ printer->setLocation(i18n("<Not available>"));
+ printer->setDriverInfo(driver.isEmpty() ? i18n("Unknown Driver", "Unknown") : driver);
+ // device
+ KURL url;
+ if (!entry->arg("rm").isEmpty())
+ {
+ url = TQString::tqfromLatin1("lpd://%1/%2").arg(entry->arg("rm")).arg(entry->arg("rp"));
+ printer->setDescription(i18n("Remote LPD queue %1@%2").arg(entry->arg("rp")).arg(entry->arg("rm")));
+ }
+ else if (!lp.isEmpty() && lp != "/dev/null")
+ url = TQString::tqfromLatin1("parallel:%1").arg(lp);
+ else if (TQFile::exists(entry->arg("sd")+"/.config"))
+ {
+ TQMap<TQString,TQString> map = loadPrinttoolCfgFile(entry->arg("sd")+"/.config");
+ if (type == "SMB")
+ {
+ QStringList l = TQStringList::split('\\',map["share"],false);
+ if (map["workgroup"].isEmpty())
+ url = TQString::tqfromLatin1("smb://%1/%2").arg(l[0]).arg(l[1]);
+ else
+ url = TQString::tqfromLatin1("smb://%1/%2/%3").arg(map["workgroup"]).arg(l[0]).arg(l[1]);
+ url.setUser(map["user"]);
+ url.setPass(map["password"]);
+ }
+ else if (type == "DIRECT")
+ url = TQString::tqfromLatin1("socket://%1:%2").arg(map["printer_ip"]).arg(map["port"]);
+ else if (type == "NCP")
+ {
+ url = TQString::tqfromLatin1("ncp://%1/%2").arg(map["server"]).arg(map["queue"]);
+ url.setUser(map["user"]);
+ url.setPass(map["password"]);
+ }
+ }
+ printer->setDevice(url);
+ return true;
+ }
+ else return false;
+}
+
+bool KMLpdManager::createPrinter(KMPrinter *printer)
+{
+ // 1) create the printcap entry
+ PrintcapEntry *ent = findPrintcapEntry(printer->printerName());
+ if (!ent)
+ {
+ ent = new PrintcapEntry();
+ ent->m_name = printer->printerName();
+ }
+ else
+ {
+ if (!printer->driver() && printer->option("kde-driver") != "raw")
+ printer->setDriver(loadPrinterDriver(printer,true));
+ // remove it from current entries
+ ent = m_entries.take(ent->m_name);
+ ent->m_args.clear();
+ }
+ // Standard options
+ if (printer->device().protocol() == "lpd")
+ {
+ // remote lpd queue
+ ent->m_args["rm"] = printer->device().host();
+ ent->m_args["rp"] = printer->device().path().replace("/",TQString::tqfromLatin1(""));
+ ent->m_args["lpd_bounce"] = "true";
+ ent->m_comment = TQString::tqfromLatin1("##PRINTTOOL3## REMOTE");
+ }
+ ent->m_args["mx"] = (printer->option("mx").isEmpty() ? "#0" : printer->option("mx"));
+ ent->m_args["sh"] = TQString::null;
+ // create spool directory (if necessary) and update PrintcapEntry object
+ if (!createSpooldir(ent))
+ {
+ setErrorMsg(i18n("Unable to create spool directory %1 for printer %2.").arg(ent->arg("sd")).arg(ent->m_name));
+ delete ent;
+ return false;
+ }
+ if (!printer->driver() || printer->driver()->get("drtype") == "printtool")
+ if (!createPrinttoolEntry(printer,ent))
+ {
+ setErrorMsg(i18n("Unable to save information for printer <b>%1</b>.").arg(printer->printerName()));
+ delete ent;
+ return false;
+ }
+
+ // 2) write the printcap file
+ m_entries.insert(ent->m_name,ent);
+ if (!writePrinters())
+ return false;
+
+ // 3) save the printer driver (if any)
+ if (printer->driver())
+ {
+ if (!savePrinterDriver(printer,printer->driver()))
+ {
+ m_entries.remove(ent->m_name);
+ writePrinters();
+ return false;
+ }
+ }
+
+ // 4) change permissions of spool directory
+ TQCString cmd = "chmod -R o-rwx,g+rwX ";
+ cmd += TQFile::encodeName(KProcess::quote(ent->arg("sd")));
+ cmd += "&& chown -R lp.lp ";
+ cmd += TQFile::encodeName(KProcess::quote(ent->arg("sd")));
+ if (system(cmd.data()) != 0)
+ {
+ setErrorMsg(i18n("Unable to set correct permissions on spool directory %1 for printer <b>%2</b>.").arg(ent->arg("sd")).arg(ent->m_name));
+ return false;
+ }
+
+ return true;
+}
+
+bool KMLpdManager::removePrinter(KMPrinter *printer)
+{
+ PrintcapEntry *ent = findPrintcapEntry(printer->printerName());
+ if (ent)
+ {
+ ent = m_entries.take(printer->printerName());
+ if (!writePrinters())
+ {
+ m_entries.insert(ent->m_name,ent);
+ return false;
+ }
+ TQCString cmd = "rm -rf ";
+ cmd += TQFile::encodeName(KProcess::quote(ent->arg("sd")));
+ system(cmd.data());
+ delete ent;
+ return true;
+ }
+ else
+ return false;
+}
+
+bool KMLpdManager::enablePrinter(KMPrinter *printer, bool state)
+{
+ KPipeProcess proc;
+ QString cmd = programName(0);
+ cmd += " ";
+ cmd += state ? "up" : "down";
+ cmd += " ";
+ cmd += KProcess::quote(printer->printerName());
+ if (proc.open(cmd))
+ {
+ QTextStream t(&proc);
+ QString buffer;
+ while (!t.eof())
+ buffer.append(t.readLine());
+ if (buffer.startsWith("?Privilege"))
+ {
+ setErrorMsg(i18n("Permission denied: you must be root."));
+ return false;
+ }
+ return true;
+ }
+ else
+ {
+ setErrorMsg(i18n("Unable to execute command \"%1\".").arg(cmd));
+ return false;
+ }
+}
+
+bool KMLpdManager::enablePrinter(KMPrinter *printer)
+{
+ return enablePrinter(printer,true);
+}
+
+bool KMLpdManager::disablePrinter(KMPrinter *printer)
+{
+ return enablePrinter(printer,false);
+}
+
+void KMLpdManager::listPrinters()
+{
+ m_entries.clear();
+ loadPrintcapFile(TQString::tqfromLatin1("%1/etc/printcap").arg(lpdprefix));
+
+ TQDictIterator<PrintcapEntry> it(m_entries);
+ for (;it.current();++it)
+ {
+ KMPrinter *printer = it.current()->createPrinter();
+ addPrinter(printer);
+ }
+
+ checkStatus();
+}
+
+TQString KMLpdManager::programName(int f)
+{
+ KConfig *conf = KMFactory::self()->printConfig();
+ conf->setGroup("LPD");
+ switch (f)
+ {
+ case 0: return conf->readPathEntry("LpdCommand","/usr/sbin/lpc");
+ case 1: return conf->readPathEntry("LpdQueue","lpq");
+ case 2: return conf->readPathEntry("LpdRemove","lprm");
+ }
+ return TQString::null;
+}
+
+void KMLpdManager::checkStatus()
+{
+ KPipeProcess proc;
+ QString cmd = programName(0) + " status all";
+ if (proc.open(cmd))
+ {
+ QTextStream t(&proc);
+ QString line;
+ KMPrinter *printer(0);
+ int p(-1);
+ while (!t.eof())
+ {
+ line = t.readLine().stripWhiteSpace();
+ if (line.isEmpty())
+ continue;
+ if ((p=line.find(':')) != -1)
+ printer = findPrinter(line.left(p));
+ else if (line.startsWith("printing") && printer)
+ printer->setState(line.find("enabled") != -1 ? KMPrinter::Idle : KMPrinter::Stopped);
+ else if (line.find("entries") != -1 && printer)
+ if (!line.startsWith("no") && printer->state() == KMPrinter::Idle)
+ printer->setState(KMPrinter::Processing);
+ }
+ }
+}
+
+bool KMLpdManager::writePrinters()
+{
+ if (!writePrintcapFile(TQString::tqfromLatin1("%1/etc/printcap").arg(lpdprefix)))
+ {
+ setErrorMsg(i18n("Unable to write printcap file."));
+ return false;
+ }
+ return true;
+}
+
+void KMLpdManager::loadPrintcapFile(const TQString& filename)
+{
+ QFile f(filename);
+ if (f.exists() && f.open(IO_ReadOnly))
+ {
+ QTextStream t(&f);
+ QString line, comment;
+ PrintcapEntry *entry;
+ while (!t.eof())
+ {
+ line = getPrintcapLine(t,&comment);
+ if (line.isEmpty())
+ continue;
+ entry = new PrintcapEntry;
+ if (entry->readLine(line))
+ {
+ m_entries.insert(entry->m_name,entry);
+ entry->m_comment = comment;
+ }
+ else
+ {
+ delete entry;
+ break;
+ }
+ }
+ }
+}
+
+bool KMLpdManager::writePrintcapFile(const TQString& filename)
+{
+ QFile f(filename);
+ if (f.open(IO_WriteOnly))
+ {
+ QTextStream t(&f);
+ t << "# File generated by KDE print (LPD plugin).\n#Don't edit by hand." << endl << endl;
+ TQDictIterator<PrintcapEntry> it(m_entries);
+ for (;it.current();++it)
+ it.current()->writeEntry(t);
+ return true;
+ }
+ return false;
+}
+
+PrinttoolEntry* KMLpdManager::findPrinttoolEntry(const TQString& name)
+{
+ if (m_ptentries.count() == 0)
+ loadPrinttoolDb(driverDirectory()+"/printerdb");
+ PrinttoolEntry *ent = m_ptentries.find(name);
+ if (!ent)
+ setErrorMsg(i18n("Couldn't find driver <b>%1</b> in printtool database.").arg(name));
+ return ent;
+}
+
+void KMLpdManager::loadPrinttoolDb(const TQString& filename)
+{
+ QFile f(filename);
+ if (f.exists() && f.open(IO_ReadOnly))
+ {
+ QTextStream t(&f);
+ PrinttoolEntry *entry = new PrinttoolEntry;
+ while (entry->readEntry(t))
+ {
+ m_ptentries.insert(entry->m_name,entry);
+ entry = new PrinttoolEntry;
+ }
+ delete entry;
+ }
+}
+
+DrMain* KMLpdManager::loadDbDriver(KMDBEntry *entry)
+{
+ QString ptdbfilename = driverDirectory() + "/printerdb";
+ if (entry->file == ptdbfilename)
+ {
+ PrinttoolEntry *ptentry = findPrinttoolEntry(entry->modelname);
+ if (ptentry)
+ {
+ DrMain *dr = ptentry->createDriver();
+ return dr;
+ }
+ }
+ return NULL;
+}
+
+PrintcapEntry* KMLpdManager::findPrintcapEntry(const TQString& name)
+{
+ PrintcapEntry *ent = m_entries.find(name);
+ if (!ent)
+ setErrorMsg(i18n("Couldn't find printer <b>%1</b> in printcap file.").arg(name));
+ return ent;
+}
+
+DrMain* KMLpdManager::loadPrinterDriver(KMPrinter *printer, bool config)
+{
+ PrintcapEntry *entry = findPrintcapEntry(printer->name());
+ if (!entry)
+ return NULL;
+
+ // check for printtool driver (only for configuration)
+ QString sd = entry->arg("sd"), dr(entry->comment(7));
+ if (TQFile::exists(sd+"/postscript.cfg") && config && !dr.isEmpty())
+ {
+ TQMap<TQString,TQString> map = loadPrinttoolCfgFile(sd+"/postscript.cfg");
+ PrinttoolEntry *ptentry = findPrinttoolEntry(dr);
+ if (!ptentry)
+ return NULL;
+ DrMain *dr = ptentry->createDriver();
+ dr->setOptions(map);
+ map = loadPrinttoolCfgFile(sd+"/general.cfg");
+ dr->setOptions(map);
+ map = loadPrinttoolCfgFile(sd+"/textonly.cfg");
+ dr->setOptions(map);
+ return dr;
+ }
+
+ // default
+ if (entry->m_comment.startsWith("##PRINTTOOL3##"))
+ setErrorMsg(i18n("No driver found (raw printer)"));
+ else
+ setErrorMsg(i18n("Printer type not recognized."));
+ return NULL;
+}
+
+bool KMLpdManager::checkGsDriver(const TQString& gsdriver)
+{
+ if (gsdriver == "ppa" || gsdriver == "POSTSCRIPT" || gsdriver == "TEXT")
+ return true;
+ else if (!m_gschecker->checkGsDriver(gsdriver))
+ {
+ setErrorMsg(i18n("The driver device <b>%1</b> is not compiled in your GhostScript distribution. Check your installation or use another driver.").arg(gsdriver));
+ return false;
+ }
+ return true;
+}
+
+TQMap<TQString,TQString> KMLpdManager::loadPrinttoolCfgFile(const TQString& filename)
+{
+ QFile f(filename);
+ TQMap<TQString,TQString> map;
+ if (f.exists() && f.open(IO_ReadOnly))
+ {
+ QTextStream t(&f);
+ QString line, name, val;
+ int p(-1);
+ while (!t.eof())
+ {
+ line = getPrintcapLine(t);
+ if (line.isEmpty())
+ break;
+ if (line.startsWith("export "))
+ line.replace(0,7,"");
+ if ((p=line.find('=')) != -1)
+ {
+ name = line.left(p);
+ val = line.right(line.length()-p-1);
+ val.replace("\"","");
+ val.replace("'","");
+ if (!name.isEmpty() && !val.isEmpty())
+ map[name] = val;
+ }
+ }
+ }
+ return map;
+}
+
+bool KMLpdManager::savePrinttoolCfgFile(const TQString& templatefile, const TQString& dirname, const TQMap<TQString,TQString>& options)
+{
+ // defines input and output file
+ QString fname = TQFileInfo(templatefile).fileName();
+ fname.replace(TQRegExp("\\.in$"),TQString::tqfromLatin1(""));
+ QFile fin(templatefile);
+ QFile fout(dirname + "/" + fname);
+ if (fin.exists() && fin.open(IO_ReadOnly) && fout.open(IO_WriteOnly))
+ {
+ QTextStream tin(&fin), tout(&fout);
+ QString line, name;
+ int p(-1);
+ while (!tin.eof())
+ {
+ line = tin.readLine().stripWhiteSpace();
+ if (line.isEmpty() || line[0] == '#')
+ {
+ tout << line << endl;
+ continue;
+ }
+ if (line.startsWith("export "))
+ {
+ tout << "export ";
+ line.replace(0,7,TQString::tqfromLatin1(""));
+ }
+ if ((p=line.find('=')) != -1)
+ {
+ name = line.left(p);
+ tout << name << '=' << options[name] << endl;
+ }
+ }
+ return true;
+ }
+ else return false;
+}
+
+bool KMLpdManager::savePrinterDriver(KMPrinter *printer, DrMain *driver)
+{
+ // To be able to save a printer driver, a printcap entry MUST exist.
+ // We can then retrieve the spool directory from it.
+ QString spooldir;
+ PrintcapEntry *ent = findPrintcapEntry(printer->printerName());
+ if (!ent)
+ return false;
+ spooldir = ent->arg("sd");
+
+ if (driver->get("drtype") == "printtool" && !spooldir.isEmpty())
+ {
+ TQMap<TQString,TQString> options;
+ driver->getOptions(options,true);
+ // add some standard options
+ options["DESIRED_TO"] = "ps";
+ options["PRINTER_TYPE"] = ent->comment(2); // get type from printcap entry (works in anycases)
+ options["PS_SEND_EOF"] = "NO";
+ if (!checkGsDriver(options["GSDEVICE"]))
+ return false;
+ QString resol(options["RESOLUTION"]), color(options["COLOR"]);
+ // update entry comment to make printtool happy and save printcap file
+ ent->m_comment = TQString::tqfromLatin1("##PRINTTOOL3## %1 %2 %3 %4 {} {%5} %6 {}").arg(options["PRINTER_TYPE"]).arg(options["GSDEVICE"]).arg((resol.isEmpty() ? TQString::tqfromLatin1("NAxNA") : resol)).arg(options["PAPERSIZE"]).arg(driver->name()).arg((color.isEmpty() ? TQString::tqfromLatin1("Default") : color.right(color.length()-15)));
+ ent->m_args["if"] = spooldir+TQString::tqfromLatin1("/filter");
+ if (!writePrinters())
+ return false;
+ // write various driver files using templates
+ TQCString cmd = "cp ";
+ cmd += TQFile::encodeName(KProcess::quote(driverDirectory()+"/master-filter"));
+ cmd += " ";
+ cmd += TQFile::encodeName(KProcess::quote(spooldir + "/filter"));
+ if (system(cmd.data()) == 0 &&
+ savePrinttoolCfgFile(driverDirectory()+"/general.cfg.in",spooldir,options) &&
+ savePrinttoolCfgFile(driverDirectory()+"/postscript.cfg.in",spooldir,options) &&
+ savePrinttoolCfgFile(driverDirectory()+"/textonly.cfg.in",spooldir,options))
+ return true;
+ setErrorMsg(i18n("Unable to write driver associated files in spool directory."));
+ }
+ return false;
+}
+
+bool KMLpdManager::createPrinttoolEntry(KMPrinter *printer, PrintcapEntry *entry)
+{
+ KURL dev(printer->device());
+ QString prot = dev.protocol(), sd(entry->arg("sd"));
+ entry->m_comment = TQString::tqfromLatin1("##PRINTTOOL3## %1").arg(ptPrinterType(printer));
+ if (prot == "smb" || prot == "ncp" || prot == "socket")
+ {
+ entry->m_args["af"] = sd+TQString::tqfromLatin1("/acct");
+ QFile f(sd+TQString::tqfromLatin1("/.config"));
+ if (f.open(IO_WriteOnly))
+ {
+ QTextStream t(&f);
+ if (prot == "socket")
+ {
+ t << "printer_ip=" << dev.host() << endl;
+ t << "port=" << dev.port() << endl;
+ entry->m_args["if"] = driverDirectory()+TQString::tqfromLatin1("/directprint");
+ }
+ else if (prot == "smb")
+ {
+ QStringList l = TQStringList::split('/',dev.path(),false);
+ if (l.count() == 2)
+ {
+ t << "share='\\\\" << l[0] << '\\' << l[1] << '\'' << endl;
+ }
+ else if (l.count() == 1)
+ {
+ t << "share='\\\\" << dev.host() << '\\' << l[0] << '\'' << endl;
+ }
+ t << "hostip=" << endl;
+ t << "user='" << dev.user() << '\'' << endl;
+ t << "password='" << dev.pass() << '\'' << endl;
+ t << "workgroup='" << (l.count() == 2 ? dev.host() : TQString::tqfromLatin1("")) << '\'' << endl;
+ entry->m_args["if"] = driverDirectory()+TQString::tqfromLatin1("/smbprint");
+ }
+ else if (prot == "ncp")
+ {
+ t << "server=" << dev.host() << endl;
+ t << "queue=" << dev.path().replace("/",TQString::tqfromLatin1("")) << endl;
+ t << "user=" << dev.user() << endl;
+ t << "password=" << dev.pass() << endl;
+ entry->m_args["if"] = driverDirectory()+TQString::tqfromLatin1("/ncpprint");
+ }
+ }
+ else return false;
+ entry->m_args["lp"] = TQString::tqfromLatin1("/dev/null");
+ }
+ else if (prot != "lpd")
+ entry->m_args["lp"] = dev.path();
+ return true;
+}
+
+bool KMLpdManager::createSpooldir(PrintcapEntry *entry)
+{
+ // first check if it has a "sd" defined
+ if (entry->arg("sd").isEmpty())
+ entry->m_args["sd"] = TQString::tqfromLatin1("/var/spool/lpd/")+entry->m_name;
+ QString sd = entry->arg("sd");
+ if (!KStandardDirs::exists(sd))
+ {
+ if (!KStandardDirs::makeDir(sd,0750))
+ return false;
+ struct passwd *lp_pw = getpwnam("lp");
+ if (lp_pw && chown(TQFile::encodeName(sd),lp_pw->pw_uid,lp_pw->pw_gid) != 0)
+ return false;
+ }
+ return true;
+}
+
+bool KMLpdManager::validateDbDriver(KMDBEntry *entry)
+{
+ PrinttoolEntry *ptentry = findPrinttoolEntry(entry->modelname);
+ return (ptentry && checkGsDriver(ptentry->m_gsdriver));
+}
+
+//************************************************************************************************
+
+TQString ptPrinterType(KMPrinter *p)
+{
+ QString type, prot = p->device().protocol();
+ if (prot == "lpd") type = "REMOTE";
+ else if (prot == "smb") type = "SMB";
+ else if (prot == "ncp") type = "NCP";
+ else if (prot == "socket") type = "DIRECT";
+ else type = "LOCAL";
+ return type;
+}
diff --git a/tdeprint/lpd/kmlpdmanager.h b/tdeprint/lpd/kmlpdmanager.h
new file mode 100644
index 000000000..3c2291017
--- /dev/null
+++ b/tdeprint/lpd/kmlpdmanager.h
@@ -0,0 +1,76 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMLPDMANAGER_H
+#define KMLPDMANAGER_H
+
+#include "kmmanager.h"
+#include <tqdict.h>
+
+class PrintcapEntry;
+class PrinttoolEntry;
+class GsChecker;
+
+class KMLpdManager : public KMManager
+{
+public:
+ KMLpdManager(TQObject *parent = 0, const char *name = 0);
+ ~KMLpdManager();
+
+ bool completePrinterShort(KMPrinter*);
+ bool completePrinter(KMPrinter*);
+ bool createPrinter(KMPrinter*);
+ bool removePrinter(KMPrinter*);
+ bool enablePrinter(KMPrinter*);
+ bool disablePrinter(KMPrinter*);
+
+ // Driver DB functions
+ TQString driverDbCreationProgram();
+ TQString driverDirectory();
+
+ // Driver loading functions
+ DrMain* loadDbDriver(KMDBEntry*);
+ DrMain* loadPrinterDriver(KMPrinter *p, bool config = false);
+ bool savePrinterDriver(KMPrinter*, DrMain*);
+ bool validateDbDriver(KMDBEntry*);
+
+protected:
+ void listPrinters();
+ bool writePrinters();
+ void loadPrintcapFile(const TQString& filename);
+ bool writePrintcapFile(const TQString& filename);
+ void loadPrinttoolDb(const TQString& filename);
+ TQMap<TQString,TQString> loadPrinttoolCfgFile(const TQString& filename);
+ bool savePrinttoolCfgFile(const TQString& templatefile, const TQString& dirname, const TQMap<TQString,TQString>& options);
+ bool checkGsDriver(const TQString& gsdriver);
+ bool createSpooldir(PrintcapEntry*);
+ bool createPrinttoolEntry(KMPrinter*, PrintcapEntry*);
+ PrintcapEntry* findPrintcapEntry(const TQString& name);
+ PrinttoolEntry* findPrinttoolEntry(const TQString& name);
+ TQString programName(int);
+ void checkStatus();
+ bool enablePrinter(KMPrinter*, bool);
+
+private:
+ TQDict<PrintcapEntry> m_entries;
+ TQDict<PrinttoolEntry> m_ptentries;
+ GsChecker *m_gschecker;
+};
+
+#endif
diff --git a/tdeprint/lpd/kmlpduimanager.cpp b/tdeprint/lpd/kmlpduimanager.cpp
new file mode 100644
index 000000000..fad3fcd58
--- /dev/null
+++ b/tdeprint/lpd/kmlpduimanager.cpp
@@ -0,0 +1,60 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kmlpduimanager.h"
+#include "kmfactory.h"
+#include "kmmanager.h"
+#include "kmwizard.h"
+#include "kmwbackend.h"
+#include "kmpropertypage.h"
+#include "kmpropbackend.h"
+#include "kmpropdriver.h"
+
+#include <tqfile.h>
+#include <klocale.h>
+
+KMLpdUiManager::KMLpdUiManager(TQObject *parent, const char *name)
+: KMUiManager(parent,name)
+{
+}
+
+KMLpdUiManager::~KMLpdUiManager()
+{
+}
+
+void KMLpdUiManager::setupWizard(KMWizard *wizard)
+{
+ KMWBackend *backend = wizard->backendPage();
+ backend->addBackend(KMWizard::Local,i18n("Local printer (parallel, serial, USB)"),true);
+ backend->addBackend(KMWizard::LPD,i18n("Remote LPD queue"),true);
+ backend->addBackend(KMWizard::SMB,i18n("SMB shared printer (Windows)"),false,KMWizard::Password);
+ backend->addBackend(KMWizard::TCP,i18n("Network printer (TCP)"),false);
+ backend->addBackend(KMWizard::File,i18n("File printer (print to file)"),true);
+
+ KMManager *mgr = KMFactory::self()->manager();
+ if (TQFile::exists(mgr->driverDirectory()+"/smbprint")) backend->enableBackend(KMWizard::SMB,true);
+ if (TQFile::exists(mgr->driverDirectory()+"/directprint")) backend->enableBackend(KMWizard::TCP,true);
+ if (TQFile::exists(mgr->driverDirectory()+"/ncpprint")) backend->enableBackend(KMWizard::Custom+1,true);
+}
+
+void KMLpdUiManager::setupPropertyPages(KMPropertyPage *p)
+{
+ p->addPropPage(new KMPropBackend(p, "Backend"));
+ p->addPropPage(new KMPropDriver(p, "Driver"));
+}
diff --git a/tdeprint/lpd/kmlpduimanager.h b/tdeprint/lpd/kmlpduimanager.h
new file mode 100644
index 000000000..7aca6ed1d
--- /dev/null
+++ b/tdeprint/lpd/kmlpduimanager.h
@@ -0,0 +1,35 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifndef KMLPDUIMANAGER_H
+#define KMLPDUIMANAGER_H
+
+#include "kmuimanager.h"
+
+class KMLpdUiManager : public KMUiManager
+{
+public:
+ KMLpdUiManager(TQObject *parent = 0, const char *name = 0);
+ ~KMLpdUiManager();
+
+ void setupWizard(KMWizard*);
+ void setupPropertyPages(KMPropertyPage*);
+};
+
+#endif
diff --git a/tdeprint/lpd/lpd.print b/tdeprint/lpd/lpd.print
new file mode 100644
index 000000000..019d5b9c8
--- /dev/null
+++ b/tdeprint/lpd/lpd.print
@@ -0,0 +1,87 @@
+[KDE Print Entry]
+PrintSystem=lpd
+Comment=LPR (Standard BSD print system)
+Comment[af]= Lpr (Standaard Bsd druk stelsel)
+Comment[ar]=LPR (نظام طباعة BSD المعياري)
+Comment[az]=LPR (Standard BSD çap sistemi)
+Comment[be]=LPR (Звычайная сістэма друку BSD)
+Comment[bn]=এল-পি-আর (স্ট্যাণ্ডার্ড বি-এস-ডি মুদ্রণ ব্যবস্থা)
+Comment[br]=LPR (Reizhiad moulañ reoliek evit BSD)
+Comment[bs]=LPR (standardni BSD sistem štampe)
+Comment[ca]=LPR (sistema d'impressió estàndard de BSD)
+Comment[cs]=LPR (Standardní tiskový systém na BSD)
+Comment[csb]=LPR (sztandardowô systema drëkù BSD)
+Comment[cy]=LPR (Cysawd argraffu cyffredinol BSD)
+Comment[da]=LPR (Standard BSD-udskriftssystem)
+Comment[de]=LPR (standardmäßiges BSD-Drucksystem)
+Comment[el]=LPR (Τυπικό BSD σύστημα εκτύπωσης)
+Comment[eo]=LPR (Normala BSD-pressistemo)
+Comment[es]=LPR (sistema de impresión estándar de BSD)
+Comment[et]=LPR (standardne BSD trükkimise süsteem)
+Comment[eu]=LPR (BSDren inprimatze-sistema estandarra)
+Comment[fa]=LPR (سیستم چاپ BSD استاندارد)
+Comment[fi]=LPR (standardi BSD-tulostusjärjestelmä)
+Comment[fr]=LPR (système d'impression BSD standard)
+Comment[fy]=LPR (standert BSD-ôfdruksysteem)
+Comment[ga]=LPR (Gnáthchóras priontála BSD)
+Comment[gl]=LPR (Sistema de Impresión Estándar de BSD)
+Comment[he]=מערכת ההדפסה הסטנדרטית של LPR) BSD)
+Comment[hi]=LPR (मानक BSD छपाई पद्धत्ति)
+Comment[hr]=LPR (standardni BSD sustav za ispis)
+Comment[hsb]=LPR (Standardny ćišćenski system za BSD)
+Comment[hu]=LPR (BSD-típusú nyomtatórendszer)
+Comment[id]=LPR (sistem pencetakan standar BSD)
+Comment[is]= LPR (Venjulega BSD prentkerfið)
+Comment[it]=LPR (sistema di stampa standard di BSD)
+Comment[ja]=LPR (標準 BSD 印刷システム)
+Comment[ka]=LPR (სტანდარტული BSD ბეჭდვის სისტემა)
+Comment[kk]=LPR (BSD жүйесіндегі стандартты басып шығаруы)
+Comment[km]=LPR (ប្រព័ន្ធ​បោះពុម្ព BSD ខ្នាត​គំរូ)
+Comment[ko]=LPR (표준 BSD 인쇄 시스템)
+Comment[lb]=LPR (Standard-Drécksystem vu BSD)
+Comment[lt]=LPR (Standartinė BSD spausdinimo sistema)
+Comment[lv]=LPR (Standarta BSD drukas sistēma)
+Comment[mk]=LPR (Стандардниот BSD систем за печатење)
+Comment[mn]=LPR (Стандарт BSD-Хэвлэх систем)
+Comment[ms]=LPR (Sistem cetak piawai BSD)
+Comment[mt]=LPR (sistema tal-ipprintjar standard BSD)
+Comment[nb]=LPR (Standard BSD skriversystem)
+Comment[nds]=LPR (Dat Standard-Drucksysteem vun BSD)
+Comment[ne]=LPR (मानक BSD मुद्रण प्रणाली)
+Comment[nl]=LPR (standaard BSD-afdruksysteem)
+Comment[nn]=LPR (vanleg BSD-utskriftssystem)
+Comment[nso]=LPR (System yeo e lekanetsego ya kgatiso ya BSD)
+Comment[pa]=LPR (ਮਿਆਰੀ BSD ਪ੍ਰਿੰਟ ਸਿਸਟਮ)
+Comment[pl]=LPR (standardowy system druku BSD)
+Comment[pt]=LPR (o sistema de impressão do BSD)
+Comment[pt_BR]=LPR (Sistema padrão de Impressão do BSD)
+Comment[ro]=LPR (Sistemul de tipărire standard BSD)
+Comment[ru]=LPR (стандартная система печати BSD)
+Comment[rw]=LPR (Sisitemu yo gucapa BSD isanzwe)
+Comment[se]=LPR (Standárda BSD čálihanvuogádat)
+Comment[sk]=LPR (Štandardný tlačový systém BSD)
+Comment[sl]=LPR (običajni tiskalniški sistem iz BSD)
+Comment[sq]=LPR (BSD Sistem Standard Shtypi
+Comment[sr]=LPR (стандардни BSD систем за штампање)
+Comment[sr@Latn]=LPR (standardni BSD sistem za štampanje)
+Comment[ss]=LPR (Umhini wekushicelela welizinga le BSD)
+Comment[sv]=LPR (Standardskrivarsystem för BSD)
+Comment[ta]=LPR (நிலையான BSD அச்சு அமைப்பு)
+Comment[te]=ఎల్ పి ఆర్ (సాధరణ బి ఎస్ డి ప్రచురణ వ్యవస్థ)
+Comment[tg]=LPR (системаи чопи стандартии BSD)
+Comment[th]=LPR (ระบบการพิมพ์มาตรฐานของ BSD)
+Comment[tr]=LPR (Standart BSD yazdırma sistemi)
+Comment[tt]=LPR (BSD'nıñ töp bastıru sisteme)
+Comment[uk]=LPR (типова система друку BSD)
+Comment[uz]=LPR (BSD'ning andoza bosib chiqarish tizimi)
+Comment[uz@cyrillic]=LPR (BSD'нинг андоза босиб чиқариш тизими)
+Comment[ven]=LPR (maitele a u phirintha a zwino fana zwa BCD)
+Comment[vi]=LPR (hệ thống in BSD chuẩn)
+Comment[wa]=LPR (Sistinme d' imprimaedje BSD standård)
+Comment[xh]=LPR (Indlela esezantsi yoshicilelo lwe BSD)
+Comment[zh_CN]=LPR (标准 BSD 打印系统)
+Comment[zh_HK]=LPR (標準 BSD 列印系統)
+Comment[zh_TW]=LPR (標準 BSD 列印系統)
+Comment[zu]=LPR (Isistimu yokushicelela evamile ye-BSD)
+DetectUris=service:/printer,config:/printcap
+DetectPrecedence=5
diff --git a/tdeprint/lpd/lpdtools.cpp b/tdeprint/lpd/lpdtools.cpp
new file mode 100644
index 000000000..610e8ead5
--- /dev/null
+++ b/tdeprint/lpd/lpdtools.cpp
@@ -0,0 +1,417 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "lpdtools.h"
+#include "driver.h"
+#include "kmprinter.h"
+
+#include <tqfile.h>
+#include <klocale.h>
+
+static const char *pt_pagesize[] = {
+ "ledger", I18N_NOOP("Ledger"),
+ "legal", I18N_NOOP("US Legal"),
+ "letter", I18N_NOOP("US Letter"),
+ "a4", I18N_NOOP("A4"),
+ "a3", I18N_NOOP("A3"),
+ "b4", I18N_NOOP("B4"),
+ "b5", I18N_NOOP("B5"),
+ 0
+};
+static int pt_nup[] = { 1, 2, 4, 8, -1 };
+static const char *pt_bool[] = {
+ "YES", I18N_NOOP("Enabled"),
+ "NO", I18N_NOOP("Disabled"),
+ 0
+};
+
+void setupBooleanOption(DrBooleanOption *opt)
+{
+ int i(0);
+ while (pt_bool[i])
+ {
+ DrBase *ch = new DrBase();
+ ch->setName(pt_bool[i++]);
+ ch->set("text",pt_bool[i++]);
+ opt->addChoice(ch);
+ }
+}
+
+TQString nextWord(const TQString& s, int& pos)
+{
+ int p1(pos), p2(0);
+ while (s[p1].isSpace() && p1 < (int)s.length()) p1++;
+ if (s[p1] == '{')
+ {
+ p1++;
+ p2 = s.find('}',p1);
+ }
+ else
+ {
+ p2 = p1;
+ while (!s[p2].isSpace() && p2 < (int)s.length()) p2++;
+ }
+ pos = (p2+1);
+ return s.mid(p1,p2-p1);
+}
+
+//************************************************************************************************
+
+bool PrintcapEntry::readLine(const TQString& line)
+{
+ QStringList l = TQStringList::split(':',line,false);
+ if (l.count() > 0)
+ {
+ m_name = l[0];
+ int p(-1);
+ // discard aliases
+ if ((p=m_name.find('|')) != -1)
+ m_name = m_name.left(p);
+ m_args.clear();
+ for (uint i=1; i<l.count(); i++)
+ {
+ int p = l[i].find('=');
+ if (p == -1) p = 2;
+ QString key = l[i].left(p);
+ QString value = l[i].right(l[i].length()-(l[i][p] == '=' ? p+1 : p));
+ m_args[key] = value;
+ }
+ return true;
+ }
+ return false;
+}
+
+void PrintcapEntry::writeEntry(TQTextStream& t)
+{
+ if (m_comment.isEmpty()) t << "# Entry for printer " << m_name << endl;
+ else t << m_comment << endl;
+ t << m_name << ":";
+ for (TQMap<TQString,TQString>::ConstIterator it=m_args.begin(); it!=m_args.end(); ++it)
+ {
+ t << "\\\n\t:" << it.key();
+ if (!it.data().isEmpty())
+ t << ((*it)[0] == '#' ? "" : "=") << *it;
+ t << ":";
+ }
+ t << endl << endl;
+}
+
+TQString PrintcapEntry::comment(int index)
+{
+ QString w;
+ if (m_comment.startsWith("##PRINTTOOL3##"))
+ {
+ int p(0);
+ for (int i=0;i<index;i++)
+ w = nextWord(m_comment,p);
+ }
+ return w;
+}
+
+KMPrinter* PrintcapEntry::createPrinter()
+{
+ KMPrinter *printer = new KMPrinter();
+ printer->setName(m_name);
+ printer->setPrinterName(m_name);
+ printer->setInstanceName(TQString::null);
+ printer->setState(KMPrinter::Idle);
+ printer->setType(KMPrinter::Printer);
+ return printer;
+}
+
+//************************************************************************************************
+
+TQStringList splitPrinttoolLine(const TQString& line)
+{
+ QStringList l;
+ int p = line.find(':');
+ if (p != -1)
+ {
+ l.append(line.left(p));
+ p = line.find('{',p);
+ if (p == -1)
+ l.append(line.right(line.length()-l[0].length()-1).stripWhiteSpace());
+ else
+ {
+ while (p != -1)
+ {
+ int q = line.find('}',p);
+ if (q != -1)
+ {
+ l.append(line.mid(p+1,q-p-1));
+ p = line.find('{',q);
+ }
+ else break;
+ }
+ }
+ }
+ return l;
+}
+
+bool PrinttoolEntry::readEntry(TQTextStream& t)
+{
+ QString line;
+ QStringList args;
+
+ m_resolutions.setAutoDelete(true);
+ m_depths.setAutoDelete(true);
+ m_resolutions.clear();
+ m_depths.clear();
+ while (!t.eof())
+ {
+ line = getPrintcapLine(t);
+ if (line.isEmpty())
+ break;
+ if (line == "EndEntry")
+ return !m_name.isEmpty();
+ QStringList l = splitPrinttoolLine(line);
+ if (l.count() > 1)
+ {
+ if (l[0] == "StartEntry") m_name = l[1];
+ else if (l[0] == "GSDriver") m_gsdriver = l[1];
+ else if (l[0] == "About") m_about = l[1];
+ else if (l[0] == "Description") m_description = l[1];
+ else if (l[0] == "Resolution" && l.count() > 2)
+ {
+ Resolution *resol = new Resolution;
+ bool ok(false);
+ resol->xdpi = l[1].toInt(&ok);
+ if (ok) resol->ydpi = l[2].toInt(&ok);
+ if (l.count() > 3)
+ resol->comment = l[3];
+ if (ok) m_resolutions.append(resol);
+ else delete resol;
+ }
+ else if (l[0] == "BitsPerPixel" && l.count() > 1)
+ {
+ BitsPerPixel *dpth = new BitsPerPixel;
+ dpth->bpp = l[1];
+ if (l.count() > 2)
+ dpth->comment = l[2];
+ m_depths.append(dpth);
+ }
+ }
+ }
+ return false;
+}
+
+DrMain* PrinttoolEntry::createDriver()
+{
+ // create driver
+ DrMain *dr = new DrMain();
+ dr->setName(m_name);
+ dr->set("description",m_description);
+ dr->set("text",m_description);
+ dr->set("drtype","printtool");
+
+ DrGroup *gr(0);
+ DrListOption *lopt(0);
+ DrStringOption *sopt(0);
+ DrBooleanOption *bopt(0);
+ DrBase *ch(0);
+
+ if (m_gsdriver != "TEXT")
+ {
+ // create GS group
+ gr = new DrGroup();
+ gr->set("text",i18n("GhostScript settings"));
+ dr->addGroup(gr);
+
+ // Pseudo option to have access to GS driver
+ lopt = new DrListOption();
+ lopt->setName("GSDEVICE");
+ lopt->set("text",i18n("Driver"));
+ lopt->set("default",m_gsdriver);
+ gr->addOption(lopt);
+ ch = new DrBase();
+ ch->setName(m_gsdriver);
+ ch->set("text",m_gsdriver);
+ lopt->addChoice(ch);
+ lopt->setValueText(m_gsdriver);
+
+
+ // Resolutions
+ if (m_resolutions.count() > 0)
+ {
+ lopt = new DrListOption();
+ lopt->setName("RESOLUTION");
+ lopt->set("text",i18n("Resolution"));
+ gr->addOption(lopt);
+ TQPtrListIterator<Resolution> it(m_resolutions);
+ for (int i=0;it.current();++it,i++)
+ {
+ ch = new DrBase;
+ ch->setName(TQString::tqfromLatin1("%1x%2").arg(it.current()->xdpi).arg(it.current()->ydpi));
+ if (it.current()->comment.isEmpty())
+ ch->set("text",TQString::tqfromLatin1("%1x%2 DPI").arg(it.current()->xdpi).arg(it.current()->ydpi));
+ else
+ ch->set("text",TQString::tqfromLatin1("%2x%3 DPI (%1)").arg(it.current()->comment).arg(it.current()->xdpi).arg(it.current()->ydpi));
+ lopt->addChoice(ch);
+ }
+ QString defval = lopt->choices()->first()->name();
+ lopt->set("default",defval);
+ lopt->setValueText(defval);
+ }
+
+ // BitsPerPixels
+ if (m_depths.count() > 0)
+ {
+ lopt = new DrListOption();
+ lopt->setName("COLOR");
+ lopt->set("text",i18n("Color depth"));
+ gr->addOption(lopt);
+ TQPtrListIterator<BitsPerPixel> it(m_depths);
+ for (int i=0;it.current();++it,i++)
+ {
+ ch = new DrBase;
+ if (m_gsdriver != "uniprint")
+ ch->setName(TQString::tqfromLatin1("-dBitsPerPixel=%1").arg(it.current()->bpp));
+ else
+ ch->setName(it.current()->bpp);
+ if (it.current()->comment.isEmpty())
+ ch->set("text",it.current()->bpp);
+ else
+ ch->set("text",TQString::tqfromLatin1("%1 - %2").arg(it.current()->bpp).arg(it.current()->comment));
+ lopt->addChoice(ch);
+ }
+ QString defval = lopt->choices()->first()->name();
+ lopt->set("default",defval);
+ lopt->setValueText(defval);
+ }
+
+ // additional GS options
+ sopt = new DrStringOption;
+ sopt->setName("EXTRA_GS_OPTIONS");
+ sopt->set("text",i18n("Additional GS options"));
+ gr->addOption(sopt);
+ }
+
+ // General group
+ gr = new DrGroup();
+ gr->set("text",i18n("General"));
+ dr->addGroup(gr);
+
+ // Page size
+ lopt = new DrListOption();
+ lopt->setName("PAPERSIZE");
+ lopt->set("text",i18n("Page size"));
+ lopt->set("default","letter");
+ gr->addOption(lopt);
+ int i(0);
+ while (pt_pagesize[i])
+ {
+ ch = new DrBase();
+ ch->setName(pt_pagesize[i++]);
+ ch->set("text",i18n(pt_pagesize[i++]));
+ lopt->addChoice(ch);
+ }
+ lopt->setValueText("letter");
+
+ // Nup
+ lopt = new DrListOption();
+ lopt->setName("NUP");
+ lopt->set("text",i18n("Pages per sheet"));
+ lopt->set("default","1");
+ gr->addOption(lopt);
+ i = 0;
+ while (pt_nup[i] != -1)
+ {
+ ch = new DrBase();
+ ch->setName(TQString::number(pt_nup[i++]));
+ ch->set("text",ch->name());
+ lopt->addChoice(ch);
+ }
+ lopt->setValueText("1");
+
+ // Margins
+ sopt = new DrStringOption();
+ sopt->setName("RTLFTMAR");
+ sopt->set("text",i18n("Left/right margin (1/72 in)"));
+ sopt->setValueText("18");
+ gr->addOption(sopt);
+ sopt = new DrStringOption();
+ sopt->setName("TOPBOTMAR");
+ sopt->set("text",i18n("Top/bottom margin (1/72 in)"));
+ sopt->setValueText("18");
+ gr->addOption(sopt);
+
+ // Text group
+ gr = new DrGroup();
+ gr->set("text",i18n("Text options"));
+ dr->addGroup(gr);
+
+ // Send EOF
+ bopt = new DrBooleanOption();
+ bopt->setName("TEXT_SEND_EOF");
+ bopt->set("text",i18n("Send EOF after job to eject page"));
+ gr->addOption(bopt);
+ setupBooleanOption(bopt);
+ bopt->setValueText("NO");
+
+ // Fix stair-stepping
+ bopt = new DrBooleanOption();
+ bopt->setName("CRLFTRANS");
+ bopt->set("text",i18n("Fix stair-stepping text"));
+ gr->addOption(bopt);
+ setupBooleanOption(bopt);
+ bopt->choices()->first()->setName("1");
+ bopt->choices()->last()->setName("0");
+ bopt->setValueText("0");
+
+ if (m_gsdriver != "POSTSCRIPT")
+ {
+ // Fast text printing
+ bopt = new DrBooleanOption();
+ bopt->setName("ASCII_TO_PS");
+ bopt->set("text",i18n("Fast text printing (non-PS printers only)"));
+ gr->addOption(bopt);
+ setupBooleanOption(bopt);
+ bopt->choices()->first()->setName("NO");
+ bopt->choices()->last()->setName("YES");
+ bopt->setValueText("NO");
+ }
+
+ return dr;
+}
+
+//************************************************************************************************
+
+TQString getPrintcapLine(TQTextStream& t, TQString *lastcomment)
+{
+ QString line, buffer, comm;
+ while (!t.eof())
+ {
+ buffer = t.readLine().stripWhiteSpace();
+ if (buffer.isEmpty() || buffer[0] == '#')
+ {
+ comm = buffer;
+ continue;
+ }
+ line.append(buffer);
+ if (line.right(1) == "\\")
+ {
+ line.truncate(line.length()-1);
+ line = line.stripWhiteSpace();
+ }
+ else break;
+ }
+ if (lastcomment)
+ *lastcomment = comm;
+ return line;
+}
diff --git a/tdeprint/lpd/lpdtools.h b/tdeprint/lpd/lpdtools.h
new file mode 100644
index 000000000..692dd0fa2
--- /dev/null
+++ b/tdeprint/lpd/lpdtools.h
@@ -0,0 +1,76 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+#ifndef LPDTOOLS_H
+#define LPDTOOLS_H
+
+#include <tqstring.h>
+#include <tqmap.h>
+#include <tqptrlist.h>
+#include <tqtextstream.h>
+
+class KMLpdManager;
+class DrMain;
+class KMPrinter;
+
+class PrintcapEntry
+{
+friend class KMLpdManager;
+public:
+ bool readLine(const TQString& line);
+ void writeEntry(TQTextStream&);
+ KMPrinter* createPrinter();
+ TQString arg(const TQString& key) const { return m_args[key]; }
+ TQString comment(int i);
+private:
+ QString m_name;
+ QString m_comment;
+ TQMap<TQString,TQString> m_args;
+};
+
+//*****************************************************************************************************
+
+struct Resolution
+{
+ int xdpi, ydpi;
+ QString comment;
+};
+
+struct BitsPerPixel
+{
+ QString bpp;
+ QString comment;
+};
+
+class PrinttoolEntry
+{
+friend class KMLpdManager;
+public:
+ bool readEntry(TQTextStream& t);
+ DrMain* createDriver();
+private:
+ QString m_name, m_gsdriver, m_description, m_about;
+ TQPtrList<Resolution> m_resolutions;
+ TQPtrList<BitsPerPixel> m_depths;
+};
+
+//*****************************************************************************************************
+
+TQString getPrintcapLine(TQTextStream& t, TQString *lastcomment = NULL);
+
+#endif // LPDTOOLS_H
diff --git a/tdeprint/lpd/make_driver_db_lpd.c b/tdeprint/lpd/make_driver_db_lpd.c
new file mode 100644
index 000000000..02aced962
--- /dev/null
+++ b/tdeprint/lpd/make_driver_db_lpd.c
@@ -0,0 +1,112 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <string.h>
+
+#include <config.h>
+
+#define BUFFER_SIZE 1024
+
+int parseRhsPrinterDb(const char *filename, FILE *out);
+
+int main(int argc, char *argv[])
+{
+ FILE *out;
+
+ if (argc != 3)
+ {
+ fprintf(stderr,"usage: make_driver_db_lpd <dbdirectory> <dbfilename>\n");
+ exit(-1);
+ }
+ out = fopen(argv[2],"w");
+ if (out == NULL)
+ {
+ fprintf(stderr,"Unable to open DB file: %s\n",argv[2]);
+ exit(-1);
+ }
+ /* first parse RHS driver DB */
+ if (!parseRhsPrinterDb("/usr/lib/rhs/rhs-printfilters/printerdb",out))
+ fprintf(stderr,"Unable to parse RHS DB file\n");
+ return 0;
+}
+
+char* skipSpaces(char *c)
+{
+ char *cc = c;
+ while (cc && *cc && isspace(*cc)) cc++;
+ return cc;
+}
+
+int parseRhsPrinterDb(const char *filename, FILE *out)
+{
+ FILE *in;
+ char buffer[BUFFER_SIZE], *c;
+
+ in = fopen(filename,"r");
+ if (in == NULL)
+ return 0;
+ while (fgets(buffer,BUFFER_SIZE,in))
+ {
+ c = skipSpaces(buffer); /* skip leading white spaces */
+ if (c == NULL || *c == '#') /* empty line or comment line */
+ continue;
+ if (strncmp(c,"StartEntry:",11) == 0) /* start a new entry */
+ {
+ fprintf(out,"\n");
+ fprintf(out,"FILE=%s\n",filename);
+ c = skipSpaces(c+11);
+ if (c)
+ fprintf(out,"MODELNAME=%s",c);
+ }
+ else if (strncmp(c,"Description:",12) == 0)
+ {
+ char *c1, *c2;
+ c1 = strchr(c+12,'{');
+ c2 = strchr(c+12,'}');
+ if (c1 && c2)
+ {
+ char model[BUFFER_SIZE], manuf[BUFFER_SIZE];
+ char *c3;
+
+ *c2 = 0;
+ c1++;
+ c3 = strchr(c1,' ');
+ if (c3)
+ {
+ *c3 = 0;
+ c3++;
+ strlcpy(manuf,c1, sizeof(manuf));
+ strlcpy(model,c3, sizeof(model));
+ }
+ else
+ {
+ strlcpy(model,c1, sizeof(model));
+ strlcpy(manuf,"PrintTool (RH)", sizeof(manuf));
+ }
+ fprintf(out,"MANUFACTURER=%s\n",manuf);
+ fprintf(out,"MODEL=%s\n",model);
+ fprintf(out,"DESCRIPTION=%s %s\n",manuf,model);
+ }
+ }
+ }
+ return 1;
+}