You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
225 lines
5.3 KiB
225 lines
5.3 KiB
15 years ago
|
/*
|
||
|
* This file is part of the KDE libraries
|
||
13 years ago
|
* Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
|
||
15 years ago
|
*
|
||
|
* 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 "kmprinter.h"
|
||
|
#include "kprinter.h"
|
||
|
#include "driver.h"
|
||
|
|
||
|
#include <klocale.h>
|
||
|
#include <kfiledialog.h>
|
||
|
|
||
|
KMPrinter::KMPrinter()
|
||
|
: KMObject()
|
||
|
{
|
||
|
m_type = KMPrinter::Printer;
|
||
|
m_dbentry = 0;
|
||
|
m_harddefault = m_softdefault = m_ownsoftdefault = false;
|
||
|
m_driver = 0;
|
||
|
m_isedited = false;
|
||
|
m_printercap = 0;
|
||
|
}
|
||
|
|
||
|
KMPrinter::KMPrinter(const KMPrinter& p)
|
||
|
: KMObject()
|
||
|
{
|
||
|
m_driver = 0; // don't copy driver structure
|
||
|
m_harddefault = m_softdefault = m_ownsoftdefault = false;
|
||
|
m_isedited = false;
|
||
|
copy(p);
|
||
|
}
|
||
|
|
||
|
KMPrinter::~KMPrinter()
|
||
|
{
|
||
|
delete m_driver;
|
||
|
}
|
||
|
|
||
|
void KMPrinter::copy(const KMPrinter& p)
|
||
|
{
|
||
|
m_name = p.m_name;
|
||
|
m_printername = p.m_printername;
|
||
|
m_instancename = p.m_instancename;
|
||
|
m_type = p.m_type;
|
||
|
m_state = p.m_state;
|
||
|
m_device = p.m_device;
|
||
|
m_members = p.m_members;
|
||
|
m_description = p.m_description;
|
||
|
m_location = p.m_location;
|
||
|
m_manufacturer = p.m_manufacturer;
|
||
|
m_model = p.m_model;
|
||
|
m_uri = p.m_uri;
|
||
|
m_driverinfo = p.m_driverinfo;
|
||
|
m_dbentry = p.m_dbentry;
|
||
|
m_pixmap = p.m_pixmap;
|
||
|
//m_harddefault = p.m_harddefault;
|
||
|
//m_softdefault = p.m_softdefault;
|
||
|
m_options = p.m_options;
|
||
|
m_printercap = p.m_printercap;
|
||
|
setDiscarded(false);
|
||
|
}
|
||
|
|
||
|
void KMPrinter::setDriver(DrMain *driver)
|
||
|
{
|
||
|
delete m_driver;
|
||
|
m_driver = driver;
|
||
|
}
|
||
|
|
||
|
DrMain* KMPrinter::takeDriver()
|
||
|
{
|
||
|
DrMain *dr = m_driver;
|
||
|
m_driver = 0;
|
||
|
return dr;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString KMPrinter::pixmap()
|
||
15 years ago
|
{
|
||
|
if (!m_pixmap.isEmpty()) return m_pixmap;
|
||
|
|
||
13 years ago
|
QString str("tdeprint_printer");
|
||
15 years ago
|
if (!isValid()) str.append("_defect");
|
||
|
else
|
||
|
{
|
||
|
//if (isHardDefault()) str.append("_default");
|
||
|
if (isClass(true)) str.append("_class");
|
||
|
else if (isRemote()) str.append("_remote");
|
||
|
switch (state())
|
||
|
{
|
||
|
case KMPrinter::Stopped:
|
||
|
str.append("_stopped");
|
||
|
break;
|
||
|
case KMPrinter::Processing:
|
||
|
str.append("_process");
|
||
|
break;
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
return str;
|
||
|
}
|
||
|
|
||
|
int KMPrinter::compare(KMPrinter *p1, KMPrinter *p2)
|
||
|
{
|
||
|
if (p1 && p2)
|
||
|
{
|
||
|
bool s1(p1->isSpecial()), s2(p2->isSpecial());
|
||
15 years ago
|
if (s1 && s2) return TQString::compare(p1->name(),p2->name());
|
||
15 years ago
|
else if (s1) return 1;
|
||
|
else if (s2) return -1;
|
||
|
else
|
||
|
{
|
||
|
bool c1(p1->isClass(false)), c2(p2->isClass(false));
|
||
15 years ago
|
if (c1 == c2) return TQString::compare(p1->name(),p2->name());
|
||
15 years ago
|
else if (c1 && !c2) return -1;
|
||
|
else if (!c1 && c2) return 1;
|
||
|
}
|
||
|
}
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString KMPrinter::stateString() const
|
||
15 years ago
|
{
|
||
|
QString s;
|
||
|
switch (state())
|
||
|
{
|
||
|
case KMPrinter::Idle: s = i18n("Idle"); break;
|
||
|
case KMPrinter::Processing: s = i18n("Processing..."); break;
|
||
|
case KMPrinter::Stopped: s = i18n("Stopped"); break;
|
||
|
default: return i18n("Unknown State", "Unknown");
|
||
|
}
|
||
|
s += (" " + (m_state & Rejecting ? i18n("(rejecting jobs)") : i18n("(accepting jobs)")));
|
||
|
return s;
|
||
|
}
|
||
|
|
||
15 years ago
|
bool KMPrinter::autoConfigure(KPrinter *printer, TQWidget *parent)
|
||
15 years ago
|
{
|
||
|
// standard settings
|
||
|
printer->setPrinterName(printerName());
|
||
|
printer->setSearchName(name());
|
||
|
// printer default settings (useful for instances)
|
||
|
printer->setOptions(defaultOptions());
|
||
|
// special printer case:
|
||
|
// - add command
|
||
|
// - ask for output file (if needed) using default extension.
|
||
|
if (isSpecial())
|
||
|
{
|
||
|
if (option("kde-special-file") == "1")
|
||
|
{
|
||
|
// build-up default filename/directory
|
||
15 years ago
|
TQString fName = printer->docFileName(), ext = option( "kde-special-extension" );
|
||
15 years ago
|
if ( fName.isEmpty() )
|
||
|
fName = ( printer->docName() + "." + ext );
|
||
|
else
|
||
|
{
|
||
14 years ago
|
int p = fName.findRev( '.' );
|
||
15 years ago
|
if ( p == -1 )
|
||
|
fName.append( "." ).append( ext );
|
||
|
else
|
||
|
{
|
||
|
fName.truncate( p+1 );
|
||
|
fName.append( ext );
|
||
|
}
|
||
|
}
|
||
|
fName.prepend( "/" ).prepend( printer->docDirectory() );
|
||
|
|
||
|
// build-up file dialog
|
||
|
KFileDialog *dialog = new KFileDialog (fName,
|
||
15 years ago
|
TQString::null,
|
||
15 years ago
|
parent,
|
||
|
"filedialog",
|
||
|
true);
|
||
|
dialog->setOperationMode (KFileDialog::Saving);
|
||
|
|
||
|
QString mimetype = option("kde-special-mimetype");
|
||
|
|
||
|
if (!mimetype.isEmpty())
|
||
|
{
|
||
15 years ago
|
TQStringList filter;
|
||
15 years ago
|
filter << mimetype;
|
||
|
filter << "all/allfiles";
|
||
|
dialog->setMimeFilter (filter, mimetype);
|
||
|
}
|
||
|
else if (!ext.isEmpty())
|
||
|
dialog->setFilter ("*." + ext + "\n*|" + i18n ("All Files"));
|
||
|
|
||
|
if (dialog->exec ())
|
||
|
{
|
||
|
printer->setOutputToFile(true);
|
||
|
printer->setOutputFileName(dialog->selectedFile ());
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
// action canceled
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
printer->setOption( "kde-isspecial", "1" );
|
||
|
printer->setOption( "kde-special-command", option( "kde-special-command" ) );
|
||
|
}
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString KMPrinter::deviceProtocol() const
|
||
15 years ago
|
{
|
||
14 years ago
|
int p = m_device.find( ':' );
|
||
15 years ago
|
if ( p != -1 )
|
||
|
return m_device.left( p );
|
||
|
else
|
||
15 years ago
|
return TQString::null;
|
||
15 years ago
|
}
|