summaryrefslogtreecommitdiffstats
path: root/kdeprint/foomatic
diff options
context:
space:
mode:
Diffstat (limited to 'kdeprint/foomatic')
-rw-r--r--kdeprint/foomatic/Makefile.am20
-rw-r--r--kdeprint/foomatic/foomatic.print17
-rw-r--r--kdeprint/foomatic/kfoomaticprinterimpl.cpp53
-rw-r--r--kdeprint/foomatic/kfoomaticprinterimpl.h37
-rw-r--r--kdeprint/foomatic/kmfoomaticfactory.cpp27
-rw-r--r--kdeprint/foomatic/kmfoomaticmanager.cpp197
-rw-r--r--kdeprint/foomatic/kmfoomaticmanager.h42
-rw-r--r--kdeprint/foomatic/make_driver_db_foomatic.c192
8 files changed, 585 insertions, 0 deletions
diff --git a/kdeprint/foomatic/Makefile.am b/kdeprint/foomatic/Makefile.am
new file mode 100644
index 000000000..5d05859d3
--- /dev/null
+++ b/kdeprint/foomatic/Makefile.am
@@ -0,0 +1,20 @@
+INCLUDES = -I$(top_srcdir)/kdeprint $(all_includes)
+
+kde_module_LTLIBRARIES = kdeprint_foomatic.la
+
+kdeprint_foomatic_la_SOURCES = kmfoomaticfactory.cpp \
+ kmfoomaticmanager.cpp \
+ kfoomaticprinterimpl.cpp
+kdeprint_foomatic_la_LDFLAGS = $(all_libraries) -module -avoid-version -no-undefined
+kdeprint_foomatic_la_LIBADD = $(top_builddir)/kdeprint/management/libkdeprint_management.la
+kdeprint_foomatic_la_METASOURCES = AUTO
+
+noinst_HEADERS = kmfoomaticmanager.h \
+ kfoomaticprinterimpl.h
+
+bin_PROGRAMS = make_driver_db_foomatic
+
+make_driver_db_foomatic_SOURCES = make_driver_db_foomatic.c
+
+entry_DATA = foomatic.print
+entrydir = $(kde_datadir)/kdeprint/plugins
diff --git a/kdeprint/foomatic/foomatic.print b/kdeprint/foomatic/foomatic.print
new file mode 100644
index 000000000..0ead9632c
--- /dev/null
+++ b/kdeprint/foomatic/foomatic.print
@@ -0,0 +1,17 @@
+[KDE Print Entry]
+PrintSystem=foomatic
+Comment=Foomatic (CUPS, LPRng, PDQ)
+Comment[af]=Foomaties (Cups, Lprng, Pdq)
+Comment[ar]= Foomatic (CUPS, LPRng, PDQ)
+Comment[bn]=ফুম্যাটিক (CUPS, LPRng, PDQ)
+Comment[cy]=Foomatic (CUPS, LPRng, PDQ)
+Comment[eo]=Presprogramo "Foomatic" (CUPS, LPRng, PDQ)
+Comment[fa]=)Foomatic (CUPS,LPRng,PDQ
+Comment[hi]=फूमेटिक (CUPS, LPRng, PDQ)
+Comment[ne]=फुम्याटिक (CUPS, LPRng, PDQ)
+Comment[rw]=Fumatike (CUPS, LPRng, PDQ)
+Comment[sq]=Foomatik (CUPS, LPRng, PDQ)
+Comment[sv]=Foomatic (Cups, LPRng, PDQ)
+Comment[te]=ఫూమెటిక్ (సియుపిఎస్, ఎల్ పి ఆర్ అన్ జి,పిడిక్యు)
+DetectUris=exec:/foomatic-configure,config:/foomatic/
+DetectPrecedence=0
diff --git a/kdeprint/foomatic/kfoomaticprinterimpl.cpp b/kdeprint/foomatic/kfoomaticprinterimpl.cpp
new file mode 100644
index 000000000..e476b5581
--- /dev/null
+++ b/kdeprint/foomatic/kfoomaticprinterimpl.cpp
@@ -0,0 +1,53 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@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 "kfoomaticprinterimpl.h"
+#include "kprinter.h"
+
+#include <kstandarddirs.h>
+#include <klocale.h>
+
+KFoomaticPrinterImpl::KFoomaticPrinterImpl(QObject *parent, const char *name, const QStringList & /*args*/)
+: KPrinterImpl(parent,name)
+{
+}
+
+KFoomaticPrinterImpl::~KFoomaticPrinterImpl()
+{
+}
+
+// look for executable
+QString KFoomaticPrinterImpl::executable()
+{
+ QString exe = KStandardDirs::findExe("foomatic-printjob");
+ return exe;
+}
+
+bool KFoomaticPrinterImpl::setupCommand(QString& cmd, KPrinter *printer)
+{
+ QString exe = executable();
+ if (!exe.isEmpty())
+ {
+ cmd = exe + QString::fromLatin1(" -P %1 -# %2").arg(quote(printer->printerName())).arg(printer->numCopies());
+ return true;
+ }
+ else
+ printer->setErrorMessage(i18n("No valid print executable was found in your path. Check your installation."));
+ return false;
+}
diff --git a/kdeprint/foomatic/kfoomaticprinterimpl.h b/kdeprint/foomatic/kfoomaticprinterimpl.h
new file mode 100644
index 000000000..7d0699b58
--- /dev/null
+++ b/kdeprint/foomatic/kfoomaticprinterimpl.h
@@ -0,0 +1,37 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@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 KFOOMATICPRINTERIMPL_H
+#define KFOOMATICPRINTERIMPL_H
+
+#include "kprinterimpl.h"
+
+class KFoomaticPrinterImpl : public KPrinterImpl
+{
+public:
+ KFoomaticPrinterImpl(QObject *parent, const char *name, const QStringList & /*args*/);
+ ~KFoomaticPrinterImpl();
+
+ bool setupCommand(QString&, KPrinter*);
+
+protected:
+ QString executable();
+};
+
+#endif
diff --git a/kdeprint/foomatic/kmfoomaticfactory.cpp b/kdeprint/foomatic/kmfoomaticfactory.cpp
new file mode 100644
index 000000000..0355b1dd6
--- /dev/null
+++ b/kdeprint/foomatic/kmfoomaticfactory.cpp
@@ -0,0 +1,27 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@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 "kmfoomaticfactory.h"
+#include "kmfoomaticmanager.h"
+#include "kfoomaticprinterimpl.h"
+
+#include <kgenericfactory.h>
+typedef K_TYPELIST_2( KMFoomaticManager, KFoomaticPrinterImpl ) Products;
+K_EXPORT_COMPONENT_FACTORY( kdeprint_foomatic, KGenericFactory< Products > )
+
diff --git a/kdeprint/foomatic/kmfoomaticmanager.cpp b/kdeprint/foomatic/kmfoomaticmanager.cpp
new file mode 100644
index 000000000..33be966b9
--- /dev/null
+++ b/kdeprint/foomatic/kmfoomaticmanager.cpp
@@ -0,0 +1,197 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@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 "kmfoomaticmanager.h"
+#include "kpipeprocess.h"
+#include "driver.h"
+
+#include <qdom.h>
+#include <klocale.h>
+#include <kdebug.h>
+#include <kprocess.h>
+
+#include <unistd.h>
+
+KMFoomaticManager::KMFoomaticManager(QObject *parent, const char *name, const QStringList & /*args*/)
+: KMManager(parent,name)
+{
+ setHasManagement(getuid() == 0);
+ setPrinterOperationMask(KMManager::PrinterConfigure);
+}
+
+KMFoomaticManager::~KMFoomaticManager()
+{
+}
+
+void KMFoomaticManager::listPrinters()
+{
+ KPipeProcess proc("foomatic-configure -Q -q -r");
+ QDomDocument doc;
+
+ doc.setContent(&proc);
+ QDomElement docElem = doc.documentElement();
+ if (docElem.isNull() || docElem.tagName() != "queues")
+ return;
+
+ QDomNode queueNode = docElem.firstChild();
+ while (!queueNode.isNull())
+ {
+ QDomElement queueElem = queueNode.toElement();
+ if (!queueElem.isNull() && queueElem.tagName() == "queue")
+ {
+ KMPrinter *printer = createPrinterFromElement(&queueElem);
+ if (printer)
+ addPrinter(printer);
+ }
+ queueNode = queueNode.nextSibling();
+ }
+}
+
+DrMain* KMFoomaticManager::loadPrinterDriver(KMPrinter *printer, bool)
+{
+ if (printer->option("foomatic") != "1")
+ {
+ setErrorMsg(i18n("This is not a Foomatic printer"));
+ return NULL;
+ }
+ else if (printer->option("driver").isEmpty() || printer->option("printer").isEmpty())
+ {
+ setErrorMsg(i18n("Some printer information are missing"));
+ return NULL;
+ }
+
+ QString cmd = "foomatic-combo-xml -p ";
+ cmd += KProcess::quote(printer->option("printer"));
+ cmd += " -d ";
+ cmd += KProcess::quote(printer->option("driver"));
+ KPipeProcess proc(cmd);
+ QDomDocument doc;
+ doc.setContent(&proc);
+ QDomElement docElem = doc.documentElement();
+ return createDriverFromXML(&docElem);
+}
+
+KMPrinter* KMFoomaticManager::createPrinterFromElement(QDomElement *elem)
+{
+ QDomElement e = elem->namedItem("name").toElement();
+ if (!e.isNull())
+ {
+ KMPrinter *printer = new KMPrinter;
+ printer->setType(KMPrinter::Printer);
+ printer->setName(e.text());
+ printer->setPrinterName(e.text());
+ printer->setState(KMPrinter::Idle);
+ /*if (printer->name().find('/') != -1)
+ {
+ QString s(printer->name());
+ int p = s.find('/');
+ printer->setPrinterName(s.left(p));
+ printer->setInstanceName(s.mid(p+1));
+ printer->addType(KMPrinter::Virtual);
+ }*/
+
+ if (!(e=elem->namedItem("description").toElement()).isNull())
+ printer->setDescription(e.text());
+ if (!(e=elem->namedItem("location").toElement()).isNull())
+ printer->setLocation(e.text());
+ if (!(e=elem->namedItem("connect").toElement()).isNull())
+ printer->setDevice(e.text());
+
+ printer->setOption("foomatic", elem->attribute("foomatic"));
+ printer->setOption("spooler", elem->attribute("spooler"));
+ if (elem->attribute("foomatic") == "1")
+ {
+ if (!(e=elem->namedItem("printer").toElement()).isNull())
+ printer->setOption("printer", e.text());
+ if (!(e=elem->namedItem("driver").toElement()).isNull())
+ printer->setOption("driver", e.text());
+ }
+
+ return printer;
+ }
+ return NULL;
+}
+
+DrMain* KMFoomaticManager::createDriverFromXML(QDomElement *elem)
+{
+ DrMain *driver = new DrMain();
+ QDomElement pelem = elem->namedItem("printer").toElement(), delem = elem->namedItem("driver").toElement();
+ if (!pelem.isNull() && !delem.isNull())
+ {
+ driver->set("manufacturer", pelem.namedItem("make").toElement().text());
+ driver->set("model", pelem.namedItem("model").toElement().text());
+ QString s = QString::fromLatin1("%1 %2 (%3)").arg(driver->get("manufacturer")).arg(driver->get("model")).arg(delem.namedItem("name").toElement().text());
+ driver->set("description", s);
+ driver->set("text", s);
+
+ QDomElement opts = elem->namedItem("options").toElement();
+ if (!opts.isNull())
+ {
+ QDomElement o = opts.firstChild().toElement();
+ while (!o.isNull())
+ {
+ if (o.tagName() == "option")
+ {
+ QString type = o.attribute("type");
+ DrBase *dropt(0);
+
+ if (type == "bool" || type == "enum")
+ {
+ if (type == "bool") dropt = new DrBooleanOption();
+ else dropt = new DrListOption();
+ QString defval = o.namedItem("arg_defval").toElement().text(), valuetext;
+ QDomNode val = o.namedItem("enum_vals").firstChild();
+ while (!val.isNull())
+ {
+ DrBase *choice = new DrBase();
+ choice->setName(val.namedItem("ev_shortname").namedItem("en").toElement().text());
+ choice->set("text", i18n(val.namedItem("ev_longname").namedItem("en").toElement().text().latin1()));
+ static_cast<DrListOption*>(dropt)->addChoice(choice);
+ if (val.toElement().attribute("id") == defval)
+ valuetext = choice->name();
+
+ val = val.nextSibling();
+ }
+ dropt->set("default", valuetext);
+ dropt->setValueText(valuetext);
+ }
+ else if (type == "int" || type == "float")
+ {
+ if (type == "int") dropt = new DrIntegerOption();
+ else dropt = new DrFloatOption();
+ dropt->set("minval", o.namedItem("arg_min").toElement().text());
+ dropt->set("maxval", o.namedItem("arg_max").toElement().text());
+ QString defval = o.namedItem("arg_defval").toElement().text();
+ dropt->set("default", defval);
+ dropt->setValueText(defval);
+ }
+
+ if (dropt)
+ {
+ dropt->setName(o.namedItem("arg_shortname").namedItem("en").toElement().text());
+ dropt->set("text", i18n(o.namedItem("arg_longname").namedItem("en").toElement().text().latin1()));
+ driver->addOption(dropt);
+ }
+ }
+ o = o.nextSibling().toElement();
+ }
+ }
+ }
+ return driver;
+}
diff --git a/kdeprint/foomatic/kmfoomaticmanager.h b/kdeprint/foomatic/kmfoomaticmanager.h
new file mode 100644
index 000000000..b5d18fc0c
--- /dev/null
+++ b/kdeprint/foomatic/kmfoomaticmanager.h
@@ -0,0 +1,42 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@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 KMFOOMATICMANAGER_H
+#define KMFOOMATICMANAGER_H
+
+#include "kmmanager.h"
+
+class QDomElement;
+class KMPrinter;
+
+class KMFoomaticManager : public KMManager
+{
+public:
+ KMFoomaticManager(QObject *parent, const char *name, const QStringList & /*args*/);
+ virtual ~KMFoomaticManager();
+
+ DrMain* loadPrinterDriver(KMPrinter *p, bool config = false);
+
+protected:
+ void listPrinters();
+ KMPrinter* createPrinterFromElement(QDomElement*);
+ DrMain* createDriverFromXML(QDomElement*);
+};
+
+#endif
diff --git a/kdeprint/foomatic/make_driver_db_foomatic.c b/kdeprint/foomatic/make_driver_db_foomatic.c
new file mode 100644
index 000000000..0419473f6
--- /dev/null
+++ b/kdeprint/foomatic/make_driver_db_foomatic.c
@@ -0,0 +1,192 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@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>
+
+#define BUFFER_SIZE 1024
+#define WORD_SIZE 256
+
+int parseOverview(const char *dbdir, FILE *out);
+
+int main(int argc, char *argv[])
+{
+ FILE *out;
+
+ if (argc != 3)
+ {
+ fprintf(stderr,"usage: make_driver_db_foomatic <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 (!parseOverview(argv[1], out))
+ fprintf(stderr,"Unable to parse printer DB\n");
+ return 0;
+}
+
+char* skipSpaces(char *c)
+{
+ char *cc = c;
+ while (cc && *cc && isspace(*cc)) cc++;
+ return cc;
+}
+
+int nextEntity(char *s, FILE *in)
+{
+ char c, p[WORD_SIZE] = {0};
+ int index, istag;
+
+ index = 0;
+ do
+ {
+ c = fgetc(in);
+ } while (isspace(c) && c != EOF);
+ if (c == EOF)
+ return -1;
+ if (c == '<')
+ {
+ istag = 1;
+ c = fgetc(in);
+ if (c != '/')
+ ungetc(c, in);
+ }
+ else
+ {
+ istag = 0;
+ p[index++] = c;
+ }
+ while (index < WORD_SIZE)
+ {
+ c = fgetc(in);
+ if (c != '>' && c != '<')
+ p[index++] = c;
+ else
+ {
+ if (c == '<')
+ ungetc(c, in);
+ break;
+ }
+ }
+
+ p[WORD_SIZE - 1] = 0;
+ strcpy(s, p);
+ return istag;
+}
+
+void discardTag(const char *tagname, FILE *in)
+{
+ char entity[WORD_SIZE];
+ int istag;
+
+ while ((istag=nextEntity(entity, in)) != -1)
+ {
+ if (istag == 1 && strcmp(tagname, entity) == 0)
+ break;
+ }
+}
+
+void clearDrivers(char **d)
+{
+ int index = 0;
+
+ while (d[index])
+ {
+ free(d[index]);
+ d[index++] = 0;
+ }
+}
+
+int parseOverview(const char *dbdir, FILE *out)
+{
+ FILE *in;
+ char printerid[WORD_SIZE], manu[WORD_SIZE], model[WORD_SIZE], tag[WORD_SIZE], driver[WORD_SIZE];
+ char *drivers[20] = {0};
+ int index = 0;
+ char cmd[BUFFER_SIZE] = {0};
+
+ snprintf(cmd, BUFFER_SIZE, "foomatic-combo-xml -O -l %s", dbdir);
+ in = popen(cmd, "r");
+ if (in == NULL)
+ return 0;
+ if (nextEntity(tag, in) == 1 && strcmp(tag, "overview") == 0)
+ {
+ printf("-1\n");
+ while (nextEntity(tag, in) == 1)
+ {
+ if (strcmp(tag, "overview") == 0 || strcmp(tag, "printer") != 0)
+ break;
+ strcpy(printerid, "");
+ strcpy(manu, "");
+ strcpy(model, "");
+ clearDrivers(drivers);
+ while (nextEntity(tag, in) == 1)
+ {
+ if (strcmp(tag, "id") == 0) nextEntity(printerid, in);
+ else if (strcmp(tag, "make") == 0) nextEntity(manu, in);
+ else if (strcmp(tag, "model") == 0) nextEntity(model, in);
+ else if (strcmp(tag, "drivers") == 0)
+ {
+ index = 0;
+ while (nextEntity(tag, in) == 1 && strcmp(tag, "driver") == 0 && index < 20)
+ {
+ nextEntity(driver, in);
+ drivers[index++] = strdup(driver);
+ nextEntity(driver, in);
+ }
+ continue;
+ }
+ else if (strcmp(tag, "printer") == 0)
+ {
+ printf("%s %s\n", manu, model);
+ index = 0;
+ while (drivers[index])
+ {
+ fprintf(out, "FILE=%s|%s\n", printerid, drivers[index]);
+ fprintf(out, "MANUFACTURER=%s\n", manu);
+ fprintf(out, "MODELNAME=%s\n", model);
+ fprintf(out, "MODEL=%s\n", model);
+ fprintf(out, "DESCRIPTION=%s %s (%s)\n", manu, model, drivers[index]);
+ fprintf(out, "\n");
+ index++;
+ }
+ break;
+ }
+ else
+ {
+ discardTag(tag, in);
+ continue;
+ }
+ nextEntity(tag, in);
+ }
+ }
+ }
+ if (pclose(in) == 0)
+ index = 1;
+ else
+ index = 0;
+ return index;
+}