| # kdeprint Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# klpdunixprinterimpl.cpp

    00001 /*
    00002  *  This file is part of the KDE libraries
    00003  *  Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
    00004  *
    00005  *  This library is free software; you can redistribute it and/or
    00006  *  modify it under the terms of the GNU Library General Public
    00007  *  License version 2 as published by the Free Software Foundation.
    00008  *
    00009  *  This library is distributed in the hope that it will be useful,
    00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00012  *  Library General Public License for more details.
    00013  *
    00014  *  You should have received a copy of the GNU Library General Public License
    00015  *  along with this library; see the file COPYING.LIB.  If not, write to
    00016  *  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00017  *  Boston, MA 02111-1307, USA.
    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 & /*args*/)
    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 // look for executable, starting with "lpr"
    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 }

This file is part of the documentation for kdeprint Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:31:01 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003