20 #include "kmwippprinter.h"
22 #include "kmprinter.h"
23 #include "ipprequest.h"
24 #include "kmcupsmanager.h"
25 #include "networkscanner.h"
27 #include <tdelistview.h>
29 #include <kpushbutton.h>
30 #include <tqlineedit.h>
32 #include <tdemessagebox.h>
33 #include <tqtextview.h>
36 #include <kseparator.h>
37 #include <tdelocale.h>
38 #include <kiconloader.h>
42 KMWIppPrinter::KMWIppPrinter(TQWidget *parent,
const char *name)
43 : KMWizardPage(parent,name)
45 m_title = i18n(
"IPP Printer Information");
46 m_ID = KMWizard::Custom+1;
47 m_nextpage = KMWizard::Driver;
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);
55 TQLabel *l1 =
new TQLabel(i18n(
"&Printer URI:"),
this);
57 m_uri =
new TQLineEdit(
this);
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);
68 m_scanner =
new NetworkScanner( 631,
this );
70 KSeparator* sep =
new KSeparator( KSeparator::HLine,
this);
71 sep->setFixedHeight(20);
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()));
81 TQHBoxLayout *lay3 =
new TQHBoxLayout(
this, 0, 10);
82 TQVBoxLayout *lay2 =
new TQVBoxLayout(0, 0, 0);
83 TQHBoxLayout *lay4 =
new TQHBoxLayout(0, 0, 0);
85 lay3->addWidget(m_list,1);
86 lay3->addLayout(lay2,1);
88 lay2->addWidget(m_uri);
90 lay2->addWidget(m_info, 1);
92 lay2->addLayout(lay4);
94 lay4->addWidget(m_ippreport);
96 lay2->addWidget( m_scanner );
99 KMWIppPrinter::~KMWIppPrinter()
103 void KMWIppPrinter::updatePrinter(KMPrinter *p)
105 p->setDevice(m_uri->text());
108 bool KMWIppPrinter::isValid(TQString& msg)
110 if (m_uri->text().isEmpty())
112 msg = i18n(
"You must enter a printer URI.");
116 KURL uri( m_uri->text() );
117 if (!m_scanner->checkPrinter(uri.host(),(uri.port()==0?631:uri.port())))
119 msg = i18n(
"No printer found at this address/port.");
125 void KMWIppPrinter::slotScanStarted()
130 void KMWIppPrinter::slotScanFinished()
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)
138 if (it.current()->Name.isEmpty())
139 name = i18n(
"Unknown host - 1 is the IP",
"<Unknown> (%1)").arg(it.current()->IP);
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"));
147 void KMWIppPrinter::slotPrinterSelected(TQListViewItem *item)
149 m_ippreport->setEnabled(item != 0);
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))
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))
179 value.prepend(TQString::fromLatin1(
"ipp://%1:%2").arg(item->text(1)).arg(item->text(2)));
180 m_uri->setText(value);
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))
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;
192 txt.append(i18n(
"<b>State</b>: %1<br>").arg(value));
194 m_info->setText(txt);
199 m_info->setText(i18n(
"Unable to retrieve printer info. Printer answered:<br><br>%1").arg(ippErrorString((ipp_status_t)req.status())));
203 void KMWIppPrinter::slotIppReport()
206 TQString uri(
"ipp://%1:%2/ipp");
207 TQListViewItem *item = m_list->currentItem();
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/"))
218 TQString caption = i18n(
"IPP Report for %1").arg(item->text(0));
219 static_cast<KMCupsManager*
>(KMManager::self())->ippReport(req, IPP_TAG_PRINTER, caption);
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));
227 #include "kmwippprinter.moc"