20 #include "kmwsocket.h"
21 #include "networkscanner.h"
23 #include "kmprinter.h"
25 #include <tdelistview.h>
27 #include <tqlineedit.h>
29 #include <tdemessagebox.h>
31 #include <tdelocale.h>
32 #include <kiconloader.h>
33 #include <kseparator.h>
35 KMWSocket::KMWSocket(TQWidget *parent,
const char *name)
36 : KMWizardPage(parent,name)
38 m_title = i18n(
"Network Printer Information");
40 m_nextpage = KMWizard::Driver;
42 m_list =
new TDEListView(
this);
43 m_list->addColumn(
"");
44 m_list->header()->hide();
45 m_list->setFrameStyle(TQFrame::WinPanel|TQFrame::Sunken);
46 m_list->setLineWidth(1);
48 TQLabel *l1 =
new TQLabel(i18n(
"&Printer address:"),
this);
49 TQLabel *l2 =
new TQLabel(i18n(
"P&ort:"),
this);
51 m_printer =
new TQLineEdit(
this);
52 m_port =
new TQLineEdit(
this);
53 m_port->setText(TQString(
"9100"));
55 l1->setBuddy(m_printer);
58 m_scanner =
new NetworkScanner( 9100,
this );
60 KSeparator* sep =
new KSeparator( KSeparator::HLine,
this);
61 sep->setFixedHeight(40);
63 connect(m_list,TQ_SIGNAL(selectionChanged(TQListViewItem*)),TQ_SLOT(slotPrinterSelected(TQListViewItem*)));
64 connect( m_scanner, TQ_SIGNAL( scanStarted() ), TQ_SLOT( slotScanStarted() ) );
65 connect( m_scanner, TQ_SIGNAL( scanFinished() ), TQ_SLOT( slotScanFinished() ) );
66 connect( m_scanner, TQ_SIGNAL( scanStarted() ), parent, TQ_SLOT( disableWizard() ) );
67 connect( m_scanner, TQ_SIGNAL( scanFinished() ), parent, TQ_SLOT( enableWizard() ) );
70 TQHBoxLayout *lay3 =
new TQHBoxLayout(
this, 0, 10);
71 TQVBoxLayout *lay2 =
new TQVBoxLayout(0, 0, 0);
73 lay3->addWidget(m_list,1);
74 lay3->addLayout(lay2,1);
76 lay2->addWidget(m_printer);
79 lay2->addWidget(m_port);
81 lay2->addWidget( m_scanner );
85 KMWSocket::~KMWSocket()
89 void KMWSocket::updatePrinter(KMPrinter *p)
91 TQString dev = TQString::fromLatin1(
"socket://%1:%2").arg(m_printer->text()).arg(m_port->text());
95 bool KMWSocket::isValid(TQString& msg)
97 if (m_printer->text().isEmpty())
99 msg = i18n(
"You must enter a printer address.");
102 TQString port(m_port->text());
110 msg = i18n(
"Wrong port number.");
115 if (!m_scanner->checkPrinter(m_printer->text(),p))
117 msg = i18n(
"No printer found at this address/port.");
123 void KMWSocket::slotScanStarted()
128 void KMWSocket::slotScanFinished()
130 const TQPtrList<NetworkScanner::SocketInfo> *list = m_scanner->printerList();
131 TQPtrListIterator<NetworkScanner::SocketInfo> it(*list);
132 for (;it.current();++it)
135 if (it.current()->Name.isEmpty())
136 name = i18n(
"Unknown host - 1 is the IP",
"<Unknown> (%1)").arg(it.current()->IP);
138 name = it.current()->Name;
139 TQListViewItem *item =
new TQListViewItem(m_list,name,it.current()->IP,TQString::number(it.current()->Port));
140 item->setPixmap(0,SmallIcon(
"tdeprint_printer"));
144 void KMWSocket::slotPrinterSelected(TQListViewItem *item)
147 m_printer->setText(item->text(1));
148 m_port->setText(item->text(2));
151 #include "kmwsocket.moc"