kdeprint Library API Documentation

kmprinter.cpp

00001 /*
00002  *  This file is part of the KDE libraries
00003  *  Copyright (c) 2001 Michael Goffioul <goffioul@imec.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 "kmprinter.h"
00021 #include "kprinter.h"
00022 #include "driver.h"
00023 
00024 #include <klocale.h>
00025 #include <kfiledialog.h>
00026 
00027 KMPrinter::KMPrinter()
00028 : KMObject()
00029 {
00030     m_type = KMPrinter::Printer;
00031     m_dbentry = 0;
00032     m_harddefault = m_softdefault = m_ownsoftdefault = false;
00033     m_driver = 0;
00034     m_isedited = false;
00035     m_printercap = 0;
00036 }
00037 
00038 KMPrinter::KMPrinter(const KMPrinter& p)
00039 : KMObject()
00040 {
00041     m_driver = 0;   // don't copy driver structure
00042     m_harddefault = m_softdefault = m_ownsoftdefault = false;
00043     m_isedited = false;
00044     copy(p);
00045 }
00046 
00047 KMPrinter::~KMPrinter()
00048 {
00049     delete m_driver;
00050 }
00051 
00052 void KMPrinter::copy(const KMPrinter& p)
00053 {
00054     m_name = p.m_name;
00055     m_printername = p.m_printername;
00056     m_instancename = p.m_instancename;
00057     m_type = p.m_type;
00058     m_state = p.m_state;
00059     m_device = p.m_device;
00060     m_members = p.m_members;
00061     m_description = p.m_description;
00062     m_location = p.m_location;
00063     m_manufacturer = p.m_manufacturer;
00064     m_model = p.m_model;
00065     m_uri = p.m_uri;
00066     m_driverinfo = p.m_driverinfo;
00067     m_dbentry = p.m_dbentry;
00068     m_pixmap = p.m_pixmap;
00069     //m_harddefault = p.m_harddefault;
00070     //m_softdefault = p.m_softdefault;
00071     m_options = p.m_options;
00072     m_printercap = p.m_printercap;
00073     setDiscarded(false);
00074 }
00075 
00076 void KMPrinter::setDriver(DrMain *driver)
00077 {
00078     delete m_driver;
00079     m_driver = driver;
00080 }
00081 
00082 DrMain* KMPrinter::takeDriver()
00083 {
00084     DrMain  *dr = m_driver;
00085     m_driver = 0;
00086     return dr;
00087 }
00088 
00089 QString KMPrinter::pixmap()
00090 {
00091     if (!m_pixmap.isEmpty()) return m_pixmap;
00092 
00093     QString str("kdeprint_printer");
00094     if (!isValid()) str.append("_defect");
00095     else
00096     {
00097         //if (isHardDefault()) str.append("_default");
00098         if (isClass(true)) str.append("_class");
00099         else if (isRemote()) str.append("_remote");
00100         switch (state())
00101         {
00102             case KMPrinter::Stopped:
00103                 str.append("_stopped");
00104                 break;
00105             case KMPrinter::Processing:
00106                 str.append("_process");
00107                 break;
00108             default:
00109                 break;
00110         }
00111     }
00112     return str;
00113 }
00114 
00115 int KMPrinter::compare(KMPrinter *p1, KMPrinter *p2)
00116 {
00117     if (p1 && p2)
00118     {
00119         bool    s1(p1->isSpecial()), s2(p2->isSpecial());
00120         if (s1 && s2) return QString::compare(p1->name(),p2->name());
00121         else if (s1) return 1;
00122         else if (s2) return -1;
00123         else
00124         {
00125             bool    c1(p1->isClass(false)), c2(p2->isClass(false));
00126             if (c1 == c2) return QString::compare(p1->name(),p2->name());
00127             else if (c1 && !c2) return -1;
00128             else if (!c1 && c2) return 1;
00129         }
00130     }
00131     return 0;
00132 }
00133 
00134 QString KMPrinter::stateString() const
00135 {
00136     QString s;
00137     switch (state())
00138     {
00139         case KMPrinter::Idle: s = i18n("Idle"); break;
00140         case KMPrinter::Processing: s = i18n("Processing..."); break;
00141         case KMPrinter::Stopped: s = i18n("Stopped"); break;
00142         default: return i18n("Unknown State", "Unknown");
00143     }
00144     s += (" " + (m_state & Rejecting ? i18n("(rejecting jobs)") : i18n("(accepting jobs)")));
00145     return s;
00146 }
00147 
00148 bool KMPrinter::autoConfigure(KPrinter *printer, QWidget *parent)
00149 {
00150     // standard settings
00151     printer->setPrinterName(printerName());
00152     printer->setSearchName(name());
00153     // printer default settings (useful for instances)
00154     printer->setOptions(defaultOptions());
00155     // special printer case:
00156     //  - add command
00157     //  - ask for output file (if needed) using default extension.
00158     if (isSpecial())
00159     {
00160         printer->setPrintProgram(option("kde-special-command"));
00161         if (option("kde-special-file") == "1")
00162         {
00163             KFileDialog *dialog = new KFileDialog (QString::fromLatin1("print.")+option("kde-special-extension"),
00164                                 QString::null,
00165                                 parent,
00166                                 "filedialog",
00167                                 true);
00168             dialog->setOperationMode (KFileDialog::Saving);
00169 
00170             QString mimetype = option("kde-special-mimetype");
00171             QString ext = option("kde-special-extension");
00172 
00173             if (!mimetype.isEmpty())
00174             {
00175                 QStringList filter;
00176                 filter << mimetype;
00177                 filter << "all/allfiles";
00178                 dialog->setMimeFilter (filter, mimetype);
00179             }
00180             else if (!ext.isEmpty())
00181                 dialog->setFilter ("*." + ext + "\n*|" + i18n ("All Files"));
00182 
00183             if (dialog->exec ())
00184             {
00185                 printer->setOutputToFile(true);
00186                 printer->setOutputFileName(dialog->selectedFile ());
00187             }
00188             else
00189             {
00190                 // action canceled
00191                 return false;
00192             }
00193         }
00194     }
00195 
00196     return true;
00197 }
00198 
00199 QString KMPrinter::deviceProtocol() const
00200 {
00201     int p = m_device.find( ':' );
00202     if ( p != -1 )
00203         return m_device.left( p );
00204     else
00205         return QString::null;
00206 }
KDE Logo
This file is part of the documentation for kdeprint Library Version 3.2.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Mar 4 22:45:13 2004 by doxygen 1.3.6-20040222 written by Dimitri van Heesch, © 1997-2003