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

tdeprint

  • tdeprint
  • cups
kmwippprinter.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 "kmwippprinter.h"
21#include "kmwizard.h"
22#include "kmprinter.h"
23#include "ipprequest.h"
24#include "kmcupsmanager.h"
25#include "networkscanner.h"
26
27#include <tdelistview.h>
28#include <tqheader.h>
29#include <kpushbutton.h>
30#include <tqlineedit.h>
31#include <tqlabel.h>
32#include <tdemessagebox.h>
33#include <tqtextview.h>
34#include <tqlayout.h>
35#include <tqregexp.h>
36#include <kseparator.h>
37#include <tdelocale.h>
38#include <kiconloader.h>
39#include <kguiitem.h>
40#include <kurl.h>
41
42KMWIppPrinter::KMWIppPrinter(TQWidget *parent, const char *name)
43: KMWizardPage(parent,name)
44{
45 m_title = i18n("IPP Printer Information");
46 m_ID = KMWizard::Custom+1;
47 m_nextpage = KMWizard::Driver;
48
49 m_list = new TDEListView(this);
50 m_list->addColumn("");
51 m_list->header()->hide();
52 m_list->setFrameStyle(TQFrame::WinPanel|TQFrame::Sunken);
53 m_list->setLineWidth(1);
54
55 TQLabel *l1 = new TQLabel(i18n("&Printer URI:"),this);
56
57 m_uri = new TQLineEdit(this);
58
59 l1->setBuddy(m_uri);
60
61 m_info = new TQTextView(this);
62 m_info->setPaper(colorGroup().background());
63 m_info->setMinimumHeight(100);
64 m_info->setText(i18n("<p>Either enter the printer URI directly, or use the network scanning facility.</p>"));
65 m_ippreport = new KPushButton(KGuiItem(i18n("&IPP Report"), "tdeprint_report"), this);
66 m_ippreport->setEnabled(false);
67
68 m_scanner = new NetworkScanner( 631, this );
69
70 KSeparator* sep = new KSeparator( KSeparator::HLine, this);
71 sep->setFixedHeight(20);
72
73 connect(m_list,TQ_SIGNAL(selectionChanged(TQListViewItem*)),TQ_SLOT(slotPrinterSelected(TQListViewItem*)));
74 connect( m_scanner, TQ_SIGNAL( scanStarted() ), TQ_SLOT( slotScanStarted() ) );
75 connect( m_scanner, TQ_SIGNAL( scanFinished() ), TQ_SLOT( slotScanFinished() ) );
76 connect( m_scanner, TQ_SIGNAL( scanStarted() ), parent, TQ_SLOT( disableWizard() ) );
77 connect( m_scanner, TQ_SIGNAL( scanFinished() ), parent, TQ_SLOT( enableWizard() ) );
78 connect(m_ippreport, TQ_SIGNAL(clicked()), TQ_SLOT(slotIppReport()));
79
80 // layout
81 TQHBoxLayout *lay3 = new TQHBoxLayout(this, 0, 10);
82 TQVBoxLayout *lay2 = new TQVBoxLayout(0, 0, 0);
83 TQHBoxLayout *lay4 = new TQHBoxLayout(0, 0, 0);
84
85 lay3->addWidget(m_list,1);
86 lay3->addLayout(lay2,1);
87 lay2->addWidget(l1);
88 lay2->addWidget(m_uri);
89 lay2->addSpacing(10);
90 lay2->addWidget(m_info, 1);
91 lay2->addSpacing(5);
92 lay2->addLayout(lay4);
93 lay4->addStretch(1);
94 lay4->addWidget(m_ippreport);
95 lay2->addWidget(sep);
96 lay2->addWidget( m_scanner );
97}
98
99KMWIppPrinter::~KMWIppPrinter()
100{
101}
102
103void KMWIppPrinter::updatePrinter(KMPrinter *p)
104{
105 p->setDevice(m_uri->text());
106}
107
108bool KMWIppPrinter::isValid(TQString& msg)
109{
110 if (m_uri->text().isEmpty())
111 {
112 msg = i18n("You must enter a printer URI.");
113 return false;
114 }
115
116 KURL uri( m_uri->text() );
117 if (!m_scanner->checkPrinter(uri.host(),(uri.port()==0?631:uri.port())))
118 {
119 msg = i18n("No printer found at this address/port.");
120 return false;
121 }
122 return true;
123}
124
125void KMWIppPrinter::slotScanStarted()
126{
127 m_list->clear();
128}
129
130void KMWIppPrinter::slotScanFinished()
131{
132 m_ippreport->setEnabled(false);
133 const TQPtrList<NetworkScanner::SocketInfo> *list = m_scanner->printerList();
134 TQPtrListIterator<NetworkScanner::SocketInfo> it(*list);
135 for (;it.current();++it)
136 {
137 TQString name;
138 if (it.current()->Name.isEmpty())
139 name = i18n("Unknown host - 1 is the IP", "<Unknown> (%1)").arg(it.current()->IP);
140 else
141 name = it.current()->Name;
142 TQListViewItem *item = new TQListViewItem(m_list,name,it.current()->IP,TQString::number(it.current()->Port));
143 item->setPixmap(0,SmallIcon("tdeprint_printer"));
144 }
145}
146
147void KMWIppPrinter::slotPrinterSelected(TQListViewItem *item)
148{
149 m_ippreport->setEnabled(item != 0);
150 if (!item) return;
151
152 // trying to get printer attributes
153 IppRequest req;
154 TQString uri;
155 TQStringList keys;
156
157 req.setOperation(IPP_GET_PRINTER_ATTRIBUTES);
158 req.setHost(item->text(1));
159 req.setPort(item->text(2).toInt());
160 uri = TQString::fromLatin1("ipp://%1:%2/ipp").arg(item->text(1)).arg(item->text(2));
161 req.addURI(IPP_TAG_OPERATION,"printer-uri",uri);
162 keys.append("printer-name");
163 keys.append("printer-state");
164 keys.append("printer-info");
165 keys.append("printer-uri-supported");
166 keys.append("printer-make-and-model");
167 keys.append("printer-location");
168 req.addKeyword(IPP_TAG_OPERATION,"requested-attributes",keys);
169 if (req.doRequest("/ipp/") && (req.status() == IPP_OK || req.status() == IPP_OK_SUBST || req.status() == IPP_OK_CONFLICT))
170 {
171 TQString value, txt;
172 int state;
173 if (req.name("printer-name",value)) txt.append(i18n("<b>Name</b>: %1<br>").arg(value));
174 if (req.text("printer-location",value) && !value.isEmpty()) txt.append(i18n("<b>Location</b>: %1<br>").arg(value));
175 if (req.text("printer-info",value) && !value.isEmpty()) txt.append(i18n("<b>Description</b>: %1<br>").arg(value.replace(TQRegExp(";"),"<br>")));
176 if (req.uri("printer-uri-supported",value))
177 {
178 if (value[0] == '/')
179 value.prepend(TQString::fromLatin1("ipp://%1:%2").arg(item->text(1)).arg(item->text(2)));
180 m_uri->setText(value);
181 }
182 if (req.text("printer-make-and-model",value) && !value.isEmpty()) txt.append(i18n("<b>Model</b>: %1<br>").arg(value));
183 if (req.enumvalue("printer-state",state))
184 {
185 switch (state)
186 {
187 case IPP_PRINTER_IDLE: value = i18n("Idle"); break;
188 case IPP_PRINTER_STOPPED: value = i18n("Stopped"); break;
189 case IPP_PRINTER_PROCESSING: value = i18n("Processing..."); break;
190 default: value = i18n("Unknown State", "Unknown"); break;
191 }
192 txt.append(i18n("<b>State</b>: %1<br>").arg(value));
193 }
194 m_info->setText(txt);
195 }
196 else
197 {
198 m_uri->setText(uri);
199 m_info->setText(i18n("Unable to retrieve printer info. Printer answered:<br><br>%1").arg(ippErrorString((ipp_status_t)req.status())));
200 }
201}
202
203void KMWIppPrinter::slotIppReport()
204{
205 IppRequest req;
206 TQString uri("ipp://%1:%2/ipp");
207 TQListViewItem *item = m_list->currentItem();
208
209 if (item)
210 {
211 req.setOperation(IPP_GET_PRINTER_ATTRIBUTES);
212 req.setHost(item->text(1));
213 req.setPort(item->text(2).toInt());
214 uri = uri.arg(item->text(1)).arg(item->text(2));
215 req.addURI(IPP_TAG_OPERATION, "printer-uri", uri);
216 if (req.doRequest("/ipp/"))
217 {
218 TQString caption = i18n("IPP Report for %1").arg(item->text(0));
219 static_cast<KMCupsManager*>(KMManager::self())->ippReport(req, IPP_TAG_PRINTER, caption);
220 }
221 else
222 KMessageBox::error(this, i18n("Unable to generate report. IPP request failed with message: "
223 "%1 (0x%2).").arg(ippErrorString((ipp_status_t)req.status())).arg(req.status(),0,16));
224 }
225}
226
227#include "kmwippprinter.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.