• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeprint
 

tdeprint

  • tdeprint
  • rlpr
kmwrlpr.cpp
1/*
2 * This file is part of the KDE libraries
3 * Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License version 2 as published by the Free Software Foundation.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 **/
19
20#include "kmwrlpr.h"
21#include "kmprinter.h"
22#include "kmwizard.h"
23
24#include <tqdir.h>
25#include <tqfile.h>
26#include <tqtextstream.h>
27#include <tqlayout.h>
28#include <tqlabel.h>
29#include <tqlineedit.h>
30#include <tqheader.h>
31#include <tdelistview.h>
32#include <tdelocale.h>
33#include <kiconloader.h>
34
35static TQListViewItem* rlpr_findChild(TQListViewItem *c, const TQString& txt)
36{
37 TQListViewItem *item(c);
38 while (item)
39 if (item->text(0) == txt) return item;
40 else item = item->nextSibling();
41 return NULL;
42}
43
44//*****************************************************************************************************
45
46KMWRlpr::KMWRlpr(TQWidget *parent, const char *name)
47: KMWizardPage(parent,name)
48{
49 m_ID = KMWizard::Custom+1;
50 m_title = i18n("Remote LPD Queue Settings");
51 m_nextpage = KMWizard::Name;
52
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*)));
67
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);
74 lay1->addSpacing(20);
75 lay1->addWidget(m_queuelabel);
76 lay1->addWidget(m_queue);
77 lay1->addStretch(1);
78
79 initialize();
80}
81
82bool KMWRlpr::isValid(TQString& msg)
83{
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.");
88 else
89 return true;
90 return false;
91}
92
93void KMWRlpr::initPrinter(KMPrinter *p)
94{
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());
98 if (item)
99 {
100 item = rlpr_findChild(item->firstChild(),m_queue->text());
101 if (item)
102 {
103 item->parent()->setOpen(true);
104 m_view->setCurrentItem(item);
105 m_view->ensureItemVisible(item);
106 }
107 }
108}
109
110void KMWRlpr::updatePrinter(KMPrinter *p)
111{
112 TQString uri = TQString::fromLatin1("lpd://%1/%2").arg(m_host->text()).arg(m_queue->text());
113 p->setDevice(uri);
114 p->setOption("host",m_host->text());
115 p->setOption("queue",m_queue->text());
116 p->setOption("kde-backend-description",i18n("Remote LPD queue"));
117 // setting default name and description, but only if the "name()" is empty
118 // which is the case on first pass when adding a printer. This prevents from
119 // bad side-effects when simply modifying an existing printer.
120 if (p->name().isEmpty())
121 {
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()));
125 }
126}
127
128void KMWRlpr::initialize()
129{
130 m_view->clear();
131 TQFile f(TQDir::homeDirPath()+"/.rlprrc");
132 if (!f.exists()) f.setName("/etc/rlprrc");
133 if (f.exists() && f.open(IO_ReadOnly))
134 {
135 TQTextStream t(&f);
136 TQString line, host;
137 int p(-1);
138 while (!t.eof())
139 {
140 line = t.readLine().stripWhiteSpace();
141 if (line.isEmpty())
142 continue;
143 if ((p=line.find(':')) != -1)
144 {
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)
150 {
151 TQListViewItem *pitem = new TQListViewItem(hitem,*it);
152 pitem->setPixmap(0,SmallIcon("tdeprint_printer"));
153 }
154 }
155 }
156 f.close();
157 }
158
159 // parse printcap file for local printers
160 f.setName("/etc/printcap");
161 if (f.exists() && f.open(IO_ReadOnly))
162 {
163 TQTextStream t(&f);
164 TQString line, buffer;
165 TQListViewItem *hitem(m_view->firstChild());
166 while (hitem) if (hitem->text(0) == "localhost") break; else hitem = hitem->nextSibling();
167 while (!t.eof())
168 {
169 buffer = TQString::null;
170 while (!t.eof())
171 {
172 line = t.readLine().stripWhiteSpace();
173 if (line.isEmpty() || line[0] == '#')
174 continue;
175 buffer.append(line);
176 if (buffer.right(1) == "\\")
177 buffer = buffer.left(buffer.length()-1).stripWhiteSpace();
178 else
179 break;
180 }
181 if (buffer.isEmpty())
182 continue;
183 int p = buffer.find(':');
184 if (p != -1)
185 {
186 TQString name = buffer.left(p);
187 if (!hitem)
188 {
189 hitem = new TQListViewItem(m_view,"localhost");
190 hitem->setPixmap(0,SmallIcon("tdeprint_computer"));
191 }
192 TQListViewItem *pitem = new TQListViewItem(hitem,name);
193 pitem->setPixmap(0,SmallIcon("tdeprint_printer"));
194 }
195 }
196 }
197
198 if (m_view->childCount() == 0)
199 new TQListViewItem(m_view,i18n("No Predefined Printers"));
200}
201
202void KMWRlpr::slotPrinterSelected(TQListViewItem *item)
203{
204 if (item && item->depth() == 1)
205 {
206 m_host->setText(item->parent()->text(0));
207 m_queue->setText(item->text(0));
208 }
209}
210#include "kmwrlpr.moc"

tdeprint

Skip menu "tdeprint"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tdeprint

Skip menu "tdeprint"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeprint by doxygen 1.9.4
This website is maintained by Timothy Pearson.