20 #include "kmmanager.h"
21 #include "kmprinter.h"
22 #include "kmdbentry.h"
23 #include "kmfactory.h"
24 #include "kmvirtualmanager.h"
25 #include "kmspecialmanager.h"
26 #include "printerfilter.h"
31 #include <kstandarddirs.h>
32 #include <tdeconfig.h>
33 #include <tdelocale.h>
35 #include <tdeapplication.h>
36 #include <klibloader.h>
39 KMManager::KMManager(TQObject *parent,
const char *name)
40 : TQObject(parent,name)
42 m_printers.setAutoDelete(
true);
43 m_fprinters.setAutoDelete(
false);
44 m_hasmanagement =
false;
45 m_printeroperationmask = 0;
46 m_serveroperationmask = 0;
47 m_printerfilter =
new PrinterFilter(
this);
49 m_specialmgr =
new KMSpecialManager(
this);
50 TQ_CHECK_PTR(m_specialmgr);
51 m_virtualmgr =
new KMVirtualManager(
this);
52 TQ_CHECK_PTR(m_virtualmgr);
56 m_updatepossible =
true;
59 KMManager::~KMManager()
63 KMManager* KMManager::self()
65 return KMFactory::self()->manager();
68 bool KMManager::notImplemented()
70 setErrorMsg(i18n(
"This operation is not implemented."));
74 bool KMManager::modifyPrinter(KMPrinter *oldp, KMPrinter *newp)
76 if (oldp->printerName() != newp->printerName())
81 DrMain *driver = loadPrinterDriver(oldp,
true);
82 newp->setDriver(driver);
83 if (!removePrinter(oldp))
86 return createPrinter(newp);
89 bool KMManager::createPrinter(KMPrinter*)
91 return notImplemented();
94 bool KMManager::removePrinter(KMPrinter*)
96 return notImplemented();
99 bool KMManager::removePrinter(
const TQString& name)
101 KMPrinter *p = findPrinter(name);
102 return (p ? removePrinter(p) :
false);
105 bool KMManager::enablePrinter(KMPrinter*,
bool)
107 return notImplemented();
110 bool KMManager::enablePrinter(
const TQString& name,
bool state)
112 KMPrinter *p = findPrinter(name);
113 return (p ? enablePrinter(p, state) :
false);
116 bool KMManager::startPrinter(KMPrinter*,
bool)
118 return notImplemented();
121 bool KMManager::startPrinter(
const TQString& name,
bool state)
123 KMPrinter *p = findPrinter(name);
124 return (p ? startPrinter(p, state) :
false);
127 bool KMManager::upPrinter(KMPrinter *p,
bool state)
129 bool result = enablePrinter(p, state);
131 result = startPrinter(p, state);
135 bool KMManager::completePrinter(KMPrinter*)
141 bool KMManager::completePrinterShort(KMPrinter *p)
143 return completePrinter(p);
146 bool KMManager::completePrinter(
const TQString& name)
148 KMPrinter *p = findPrinter(name);
149 return (p ? completePrinter(p) :
false);
152 bool KMManager::setDefaultPrinter(KMPrinter*)
154 return notImplemented();
157 bool KMManager::setDefaultPrinter(
const TQString& name)
159 KMPrinter *p = findPrinter(name);
160 return (p ? setDefaultPrinter(p) :
false);
163 bool KMManager::testPrinter(KMPrinter *prt)
166 TQString testpage = testPage();
167 if (testpage.isEmpty())
169 setErrorMsg(i18n(
"Unable to locate test page."));
173 bool prExist = (findPrinter(prt->printerName()) != 0), result(
false);
181 m_printers.append(prt);
182 result = pr.
printFiles(testpage,
false,
false);
184 m_printers.take(m_printers.count()-1);
189 KMPrinter* KMManager::findPrinter(
const TQString& name)
191 TQPtrListIterator<KMPrinter> it(m_printers);
192 for (;it.current();++it)
193 if (it.current()->name() == name)
return it.current();
198 KMPrinter* KMManager::softDefault()
const
200 TQPtrListIterator<KMPrinter> it(m_printers);
201 for (;it.current();++it)
202 if (it.current()->isSoftDefault())
return it.current();
206 KMPrinter* KMManager::hardDefault()
const
208 TQPtrListIterator<KMPrinter> it(m_printers);
209 for (; it.current();++it)
210 if (it.current()->isHardDefault())
215 KMPrinter* KMManager::defaultPrinter()
218 KMPrinter *prt = softDefault();
224 TQPtrList<KMPrinter>* KMManager::printerList(
bool reload)
226 setErrorMsg(TQString::null);
229 if (reload || m_printers.count() == 0)
232 m_printerfilter->update();
236 discardAllPrinters(
true);
240 if (m_printers.count() == 0)
241 m_virtualmgr->reset();
244 if ( m_updatepossible )
248 m_specialmgr->refresh();
250 if ( m_updatepossible )
251 m_virtualmgr->refresh();
254 for (uint i=0; i<m_printers.count(); i++)
256 KMPrinter *prt = m_printers.at(i);
257 if (prt->isDiscarded())
259 m_printers.remove(i);
262 else if (prt->isSpecial() || m_printerfilter->filter(prt))
263 m_fprinters.append(prt);
271 KMPrinter *defprinter = findPrinter(TQString::fromLatin1(getenv(
"PRINTER")));
273 setSoftDefault(defprinter);
275 emit printerListUpdated();
281 TQPtrList<KMPrinter>* KMManager::printerListComplete(
bool reload)
287 void KMManager::listPrinters()
292 void KMManager::addPrinter(KMPrinter *p)
296 if (p->name().isEmpty())
301 KMPrinter *other = findPrinter(p->name());
309 p->setDiscarded(
false);
310 m_printers.inSort(p);
316 TQString KMManager::driverDbCreationProgram()
318 return TQString::null;
321 TQString KMManager::driverDirectory()
323 return TQString::null;
326 DrMain* KMManager::loadPrinterDriver(KMPrinter*,
bool)
331 DrMain* KMManager::loadDbDriver(KMDBEntry *entry)
333 return loadFileDriver(entry->file);
336 DrMain* KMManager::loadFileDriver(
const TQString&)
341 DrMain* KMManager::loadDriver(KMPrinter *p,
bool config)
344 return m_specialmgr->loadDriver(p);
346 return loadPrinterDriver(p, config);
349 bool KMManager::savePrinterDriver(KMPrinter*,DrMain*)
351 return notImplemented();
354 bool KMManager::uncompressFile(
const TQString& filename, TQString& destname)
358 destname = TQString::null;
359 if (f.exists() && f.open(IO_ReadOnly))
361 char buf[1024] = {0};
363 if ((uchar)(buf[0]) == 037 && (uchar)(buf[1]) == 0213)
366 destname = locateLocal(
"tmp",
"tdeprint_") + TDEApplication::randomString(8);
369 if (f.open(IO_WriteOnly))
371 gzFile in = gzopen(filename.latin1(),
"r");
373 while ((n=gzread(in,buf,1024)) > 0)
374 if (f.writeBlock(buf,n) != n)
376 if (n != 0) result =
false;
385 void KMManager::setHardDefault(KMPrinter *p)
387 TQPtrListIterator<KMPrinter> it(m_printers);
388 for (;it.current();++it)
389 it.current()->setHardDefault(
false);
390 if (p) p->setHardDefault(
true);
393 void KMManager::setSoftDefault(KMPrinter *p)
395 TQPtrListIterator<KMPrinter> it(m_printers);
396 for (;it.current();++it)
398 it.current()->setSoftDefault(
false);
399 it.current()->setOwnSoftDefault(
false);
403 p->setSoftDefault(
true);
404 KMPrinter *pp = findPrinter(p->printerName());
406 pp->setOwnSoftDefault(
true);
410 bool KMManager::restartServer()
412 return notImplemented();
415 bool KMManager::configureServer(TQWidget*)
417 return notImplemented();
420 TQString KMManager::testPage()
422 TDEConfig *conf = KMFactory::self()->printConfig();
423 conf->setGroup(
"General");
424 TQString tpage = conf->readPathEntry(
"TestPage");
426 tpage = locate(
"data",
"tdeprint/testprint.ps");
430 void KMManager::discardAllPrinters(
bool on)
432 TQPtrListIterator<KMPrinter> it(m_printers);
433 for (;it.current();++it)
434 if (!on || !it.current()->isSpecial())
435 it.current()->setDiscarded(on);
438 bool KMManager::validateDbDriver(KMDBEntry*)
443 bool KMManager::createSpecialPrinter(KMPrinter *p)
445 if (p && p->isSpecial())
447 KMPrinter *old = findPrinter(p->name());
448 if (old && !old->isSpecial())
450 setErrorMsg(i18n(
"Can't overwrite regular printer with special printer settings."));
455 return m_specialmgr->savePrinters();
460 bool KMManager::removeSpecialPrinter(KMPrinter *p)
462 if (p && p->isSpecial() && m_printers.findRef(p) != -1)
464 m_printers.removeRef(p);
465 return m_specialmgr->savePrinters();
475 TQStringList KMManager::detectLocalPrinters()
478 for (
int i=0; i<3; i++)
479 list << TQString() << TQString::fromLatin1(
"parallel:/dev/lp%1").arg(i) << i18n(
"Parallel Port #%1").arg(i+1) << TQString();
483 int KMManager::addPrinterWizard(TQWidget *parent)
485 KLibrary *lib = KLibLoader::self()->library(
"libtdeprint_management_module");
487 setErrorMsg(i18n(
"Unable to load TDE print management library: %1").arg(KLibLoader::self()->lastErrorMessage()));
490 int (*func)(TQWidget*) = (
int(*)(TQWidget*))lib->symbol(
"add_printer_wizard");
492 setErrorMsg(i18n(
"Unable to find wizard object in management library."));
499 bool KMManager::invokeOptionsDialog(TQWidget *parent)
501 KLibrary *lib = KLibLoader::self()->library(
"libtdeprint_management_module");
503 setErrorMsg(i18n(
"Unable to load TDE print management library: %1").arg(KLibLoader::self()->lastErrorMessage()));
506 bool (*func)(TQWidget*) = (
bool(*)(TQWidget*))lib->symbol(
"config_dialog");
508 setErrorMsg(i18n(
"Unable to find options dialog in management library."));
515 void KMManager::createPluginActions(TDEActionCollection*)
519 void KMManager::validatePluginActions(TDEActionCollection*, KMPrinter*)
523 void KMManager::enableFilter(
bool on)
525 m_printerfilter->setEnabled(on);
528 bool KMManager::isFilterEnabled()
const
530 return m_printerfilter->isEnabled();
533 TQString KMManager::stateInformation()
535 return i18n(
"No plugin information available");
538 void KMManager::checkUpdatePossible()
540 m_updatepossible =
false;
541 checkUpdatePossibleInternal();
544 void KMManager::checkUpdatePossibleInternal()
546 setUpdatePossible(
true );
549 void KMManager::setUpdatePossible(
bool value )
551 if ( value != m_updatepossible )
552 m_virtualmgr->reset();
553 m_updatepossible = value;
554 emit updatePossible( m_updatepossible );
557 #include "kmmanager.moc"
This class is the main interface to access the TDE print framework.
void setPrinterName(const TQString &)
See TQPrinter::setPrinterName().
bool printFiles(const TQStringList &files, bool removeafter=false, bool startviewer=true)
Prints the files given in argument.
void setDocName(const TQString &)
See TQPrinter::setDocName().
void setSearchName(const TQString &n)
Sets the search name of the KPrinter object.