klpdunixprinterimpl.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "klpdunixprinterimpl.h"
00021 #include "kprinter.h"
00022
00023 #include <qfile.h>
00024 #include <kstandarddirs.h>
00025 #include <klocale.h>
00026 #include <kmacroexpander.h>
00027
00028 KLpdUnixPrinterImpl::KLpdUnixPrinterImpl(QObject *parent, const char *name, const QStringList & )
00029 : KPrinterImpl(parent,name)
00030 {
00031 }
00032
00033 KLpdUnixPrinterImpl::~KLpdUnixPrinterImpl()
00034 {
00035 }
00036
00037 void KLpdUnixPrinterImpl::initLpPrint(QString& cmd, KPrinter *printer)
00038 {
00039 cmd += QString::fromLatin1(" -d %1 -n%2").arg(quote(printer->printerName())).arg(printer->numCopies());
00040 }
00041
00042 void KLpdUnixPrinterImpl::initLprPrint(QString& cmd, KPrinter *printer)
00043 {
00044 cmd += QString::fromLatin1(" -P %1 '-#%2'").arg(quote(printer->printerName())).arg(printer->numCopies());
00045 }
00046
00047
00048 QString KLpdUnixPrinterImpl::executable()
00049 {
00050 QString exe = KStandardDirs::findExe("lpr");
00051 if (exe.isEmpty())
00052 exe = KStandardDirs::findExe("lp");
00053 return exe;
00054 }
00055
00056 bool KLpdUnixPrinterImpl::setupCommand(QString& cmd, KPrinter *printer)
00057 {
00058 QString exe = printer->option( "kde-printcommand" );
00059 if ( exe.isEmpty() || exe == "<automatic>" )
00060 {
00061 exe = executable();
00062 if (!exe.isEmpty())
00063 {
00064 cmd = exe;
00065 if (exe.right(3) == "lpr")
00066 initLprPrint(cmd,printer);
00067 else
00068 initLpPrint(cmd,printer);
00069 return true;
00070 }
00071 else
00072 printer->setErrorMessage(i18n("No valid print executable was found in your path. Check your installation."));
00073 return false;
00074 }
00075 else
00076 {
00077 QMap<QString,QString> map;
00078 map.insert( "printer", printer->printerName() );
00079 map.insert( "copies", QString::number( printer->numCopies() ) );
00080 cmd = KMacroExpander::expandMacrosShellQuote( exe, map );
00081 return true;
00082 }
00083 }
|