20 #include "kmrlprmanager.h"
21 #include "kmprinter.h"
24 #include <tqfileinfo.h>
25 #include <tqtextstream.h>
28 #include <kstandarddirs.h>
29 #include <tdelocale.h>
31 KMRlprManager::KMRlprManager(TQObject *parent,
const char *name,
const TQStringList & )
32 : KMManager(parent,name)
34 setHasManagement(
true);
35 setPrinterOperationMask(KMManager::PrinterCreation|KMManager::PrinterRemoval|KMManager::PrinterTesting);
38 KMRlprManager::~KMRlprManager()
42 bool KMRlprManager::createPrinter(KMPrinter *p)
44 if (p->name().isEmpty())
45 setErrorMsg(i18n(
"Empty printer name."));
46 else if (p->option(
"host").isEmpty())
47 setErrorMsg(i18n(
"Empty host name."));
48 else if (p->option(
"queue").isEmpty())
49 setErrorMsg(i18n(
"Empty queue name."));
52 KMPrinter *pr =
new KMPrinter(*p);
60 bool KMRlprManager::removePrinter(KMPrinter *p)
62 if (m_printers.findRef(p) == -1)
63 setErrorMsg(i18n(
"Printer not found."));
66 m_printers.removeRef(p);
73 bool KMRlprManager::testPrinter(KMPrinter *)
75 setErrorMsg(i18n(
"Not implemented yet."));
79 void KMRlprManager::listPrinters()
81 TQFileInfo pfi(printerFile());
82 if (pfi.exists() && (!m_checktime.isValid() || m_checktime < pfi.lastModified()))
84 loadPrintersConf(pfi.absFilePath());
85 m_checktime = pfi.lastModified();
88 discardAllPrinters(
false);
91 void KMRlprManager::loadPrintersConf(
const TQString& filename)
94 if (f.exists() && f.open(IO_ReadOnly))
100 line = t.readLine().stripWhiteSpace();
101 if (line.isEmpty() || line[0] ==
'#')
103 TQStringList w = TQStringList::split(
'\t',line,
true);
107 KMPrinter *printer =
new KMPrinter;
108 printer->setName(w[0]);
109 printer->setPrinterName(w[0]);
110 printer->setType(KMPrinter::Printer);
111 printer->setOption(
"host",w[1]);
112 printer->setOption(
"queue",w[2]);
115 printer->setDescription(w[3]);
116 if (w.count() > 4) printer->setLocation(w[4]);
118 printer->setState(KMPrinter::Idle);
119 printer->setDevice(TQString::fromLatin1(
"lpd://%1/%2").arg(w[1]).arg(w[2]));
126 void KMRlprManager::savePrinters()
128 savePrintersConf(printerFile());
131 void KMRlprManager::savePrintersConf(
const TQString& filename)
134 if (f.open(IO_WriteOnly))
137 t <<
"# File generated by TDE print system. Don't edit by hand." << endl;
138 TQPtrListIterator<KMPrinter> it(m_printers);
139 for (;it.current();++it)
141 if (!it.current()->name().isEmpty() && it.current()->instanceName().isEmpty())
143 TQString host = it.current()->option(
"host");
144 TQString queue = it.current()->option(
"queue");
145 if (!host.isEmpty() && !queue.isEmpty())
147 t << it.current()->name() <<
'\t' << host <<
'\t' << queue;
148 t <<
'\t' << it.current()->description() <<
'\t' << it.current()->location() << endl;
155 TQString KMRlprManager::printerFile()
157 return locateLocal(
"data",
"tdeprint/printers.conf");