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

# kmprinter.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 "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         if (option("kde-special-file") == "1")
    00161         {
    00162             // build-up default filename/directory
    00163             QString fName = printer->docFileName(), ext = option( "kde-special-extension" );
    00164             if ( fName.isEmpty() )
    00165                 fName = ( printer->docName() + "." + ext );
    00166             else
    00167             {
    00168                 int p = fName.findRev( '.' );
    00169                 if ( p == -1 )
    00170                     fName.append( "." ).append( ext );
    00171                 else
    00172                 {
    00173                     fName.truncate( p+1 );
    00174                     fName.append( ext );
    00175                 }
    00176             }
    00177             fName.prepend( "/" ).prepend( printer->docDirectory() );
    00178
    00179             // build-up file dialog
    00180             KFileDialog *dialog = new KFileDialog (fName,
    00181                                 QString::null,
    00182                                 parent,
    00183                                 "filedialog",
    00184                                 true);
    00185             dialog->setOperationMode (KFileDialog::Saving);
    00186
    00187             QString mimetype = option("kde-special-mimetype");
    00188
    00189             if (!mimetype.isEmpty())
    00190             {
    00191                 QStringList filter;
    00192                 filter << mimetype;
    00193                 filter << "all/allfiles";
    00194                 dialog->setMimeFilter (filter, mimetype);
    00195             }
    00196             else if (!ext.isEmpty())
    00197                 dialog->setFilter ("*." + ext + "\n*|" + i18n ("All Files"));
    00198
    00199             if (dialog->exec ())
    00200             {
    00201                 printer->setOutputToFile(true);
    00202                 printer->setOutputFileName(dialog->selectedFile ());
    00203             }
    00204             else
    00205             {
    00206                 // action canceled
    00207                 return false;
    00208             }
    00209         }
    00210         printer->setOption( "kde-isspecial", "1" );
    00211         printer->setOption( "kde-special-command", option( "kde-special-command" ) );
    00212     }
    00213
    00214     return true;
    00215 }
    00216
    00217 QString KMPrinter::deviceProtocol() const
    00218 {
    00219     int p = m_device.find( ':' );
    00220     if ( p != -1 )
    00221         return m_device.left( p );
    00222     else
    00223         return QString::null;
    00224 }

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:03 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003