21 #include "kmprinter.h"
26 #include <tqtextstream.h>
29 #include <tqlineedit.h>
31 #include <tdelistview.h>
32 #include <tdelocale.h>
33 #include <kiconloader.h>
35 static TQListViewItem* rlpr_findChild(TQListViewItem *c,
const TQString& txt)
37 TQListViewItem *item(c);
39 if (item->text(0) == txt)
return item;
40 else item = item->nextSibling();
46 KMWRlpr::KMWRlpr(TQWidget *parent,
const char *name)
47 : KMWizardPage(parent,name)
49 m_ID = KMWizard::Custom+1;
50 m_title = i18n(
"Remote LPD Queue Settings");
51 m_nextpage = KMWizard::Name;
53 m_view =
new TDEListView(
this);
54 m_view->setFrameStyle(TQFrame::WinPanel|TQFrame::Sunken);
55 m_view->setLineWidth(1);
56 m_view->addColumn(TQString::fromLatin1(
""));
57 m_view->header()->hide();
58 m_view->setRootIsDecorated(
true);
59 m_view->setSorting(0);
60 m_host =
new TQLineEdit(
this);
61 m_queue =
new TQLineEdit(
this);
62 TQLabel *m_hostlabel =
new TQLabel(i18n(
"Host:"),
this);
63 TQLabel *m_queuelabel =
new TQLabel(i18n(
"Queue:"),
this);
64 m_hostlabel->setBuddy(m_host);
65 m_queuelabel->setBuddy(m_queue);
66 connect(m_view,TQ_SIGNAL(selectionChanged(TQListViewItem*)),TQ_SLOT(slotPrinterSelected(TQListViewItem*)));
68 TQHBoxLayout *lay0 =
new TQHBoxLayout(
this, 0, 10);
69 TQVBoxLayout *lay1 =
new TQVBoxLayout(0, 0, 5);
70 lay0->addWidget(m_view,1);
71 lay0->addLayout(lay1,1);
72 lay1->addWidget(m_hostlabel);
73 lay1->addWidget(m_host);
75 lay1->addWidget(m_queuelabel);
76 lay1->addWidget(m_queue);
82 bool KMWRlpr::isValid(TQString& msg)
84 if (m_host->text().isEmpty())
85 msg = i18n(
"Empty host name.");
86 else if (m_queue->text().isEmpty())
87 msg = i18n(
"Empty queue name.");
93 void KMWRlpr::initPrinter(KMPrinter *p)
95 m_host->setText(p->option(
"host"));
96 m_queue->setText(p->option(
"queue"));
97 TQListViewItem *item = rlpr_findChild(m_view->firstChild(),m_host->text());
100 item = rlpr_findChild(item->firstChild(),m_queue->text());
103 item->parent()->setOpen(
true);
104 m_view->setCurrentItem(item);
105 m_view->ensureItemVisible(item);
110 void KMWRlpr::updatePrinter(KMPrinter *p)
112 TQString uri = TQString::fromLatin1(
"lpd://%1/%2").arg(m_host->text()).arg(m_queue->text());
114 p->setOption(
"host",m_host->text());
115 p->setOption(
"queue",m_queue->text());
116 p->setOption(
"kde-backend-description",i18n(
"Remote LPD queue"));
120 if (p->name().isEmpty())
122 p->setName(m_queue->text());
123 p->setPrinterName(p->name());
124 p->setDescription(i18n(
"Remote queue %1 on %2").arg(m_queue->text()).arg(m_host->text()));
128 void KMWRlpr::initialize()
131 TQFile f(TQDir::homeDirPath()+
"/.rlprrc");
132 if (!f.exists()) f.setName(
"/etc/rlprrc");
133 if (f.exists() && f.open(IO_ReadOnly))
140 line = t.readLine().stripWhiteSpace();
143 if ((p=line.find(
':')) != -1)
145 host = line.left(p).stripWhiteSpace();
146 TQListViewItem *hitem =
new TQListViewItem(m_view,host);
147 hitem->setPixmap(0,SmallIcon(
"tdeprint_computer"));
148 TQStringList prs = TQStringList::split(
' ',line.right(line.length()-p-1),
false);
149 for (TQStringList::ConstIterator it=prs.begin(); it!=prs.end(); ++it)
151 TQListViewItem *pitem =
new TQListViewItem(hitem,*it);
152 pitem->setPixmap(0,SmallIcon(
"tdeprint_printer"));
160 f.setName(
"/etc/printcap");
161 if (f.exists() && f.open(IO_ReadOnly))
164 TQString line, buffer;
165 TQListViewItem *hitem(m_view->firstChild());
166 while (hitem)
if (hitem->text(0) ==
"localhost")
break;
else hitem = hitem->nextSibling();
169 buffer = TQString::null;
172 line = t.readLine().stripWhiteSpace();
173 if (line.isEmpty() || line[0] ==
'#')
176 if (buffer.right(1) ==
"\\")
177 buffer = buffer.left(buffer.length()-1).stripWhiteSpace();
181 if (buffer.isEmpty())
183 int p = buffer.find(
':');
186 TQString name = buffer.left(p);
189 hitem =
new TQListViewItem(m_view,
"localhost");
190 hitem->setPixmap(0,SmallIcon(
"tdeprint_computer"));
192 TQListViewItem *pitem =
new TQListViewItem(hitem,name);
193 pitem->setPixmap(0,SmallIcon(
"tdeprint_printer"));
198 if (m_view->childCount() == 0)
199 new TQListViewItem(m_view,i18n(
"No Predefined Printers"));
202 void KMWRlpr::slotPrinterSelected(TQListViewItem *item)
204 if (item && item->depth() == 1)
206 m_host->setText(item->parent()->text(0));
207 m_queue->setText(item->text(0));
210 #include "kmwrlpr.moc"