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

tdeprint

  • tdeprint
  • management
kmwsocket.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 "kmwsocket.h"
21 #include "networkscanner.h"
22 #include "kmwizard.h"
23 #include "kmprinter.h"
24 
25 #include <tdelistview.h>
26 #include <tqheader.h>
27 #include <tqlineedit.h>
28 #include <tqlabel.h>
29 #include <tdemessagebox.h>
30 #include <tqlayout.h>
31 #include <tdelocale.h>
32 #include <kiconloader.h>
33 #include <kseparator.h>
34 
35 KMWSocket::KMWSocket(TQWidget *parent, const char *name)
36 : KMWizardPage(parent,name)
37 {
38  m_title = i18n("Network Printer Information");
39  m_ID = KMWizard::TCP;
40  m_nextpage = KMWizard::Driver;
41 
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);
47 
48  TQLabel *l1 = new TQLabel(i18n("&Printer address:"),this);
49  TQLabel *l2 = new TQLabel(i18n("P&ort:"),this);
50 
51  m_printer = new TQLineEdit(this);
52  m_port = new TQLineEdit(this);
53  m_port->setText(TQString("9100"));
54 
55  l1->setBuddy(m_printer);
56  l2->setBuddy(m_port);
57 
58  m_scanner = new NetworkScanner( 9100, this );
59 
60  KSeparator* sep = new KSeparator( KSeparator::HLine, this);
61  sep->setFixedHeight(40);
62 
63  connect(m_list,TQT_SIGNAL(selectionChanged(TQListViewItem*)),TQT_SLOT(slotPrinterSelected(TQListViewItem*)));
64  connect( m_scanner, TQT_SIGNAL( scanStarted() ), TQT_SLOT( slotScanStarted() ) );
65  connect( m_scanner, TQT_SIGNAL( scanFinished() ), TQT_SLOT( slotScanFinished() ) );
66  connect( m_scanner, TQT_SIGNAL( scanStarted() ), parent, TQT_SLOT( disableWizard() ) );
67  connect( m_scanner, TQT_SIGNAL( scanFinished() ), parent, TQT_SLOT( enableWizard() ) );
68 
69  // layout
70  TQHBoxLayout *lay3 = new TQHBoxLayout(this, 0, 10);
71  TQVBoxLayout *lay2 = new TQVBoxLayout(0, 0, 0);
72 
73  lay3->addWidget(m_list,1);
74  lay3->addLayout(lay2,1);
75  lay2->addWidget(l1);
76  lay2->addWidget(m_printer);
77  lay2->addSpacing(10);
78  lay2->addWidget(l2);
79  lay2->addWidget(m_port);
80  lay2->addWidget(sep);
81  lay2->addWidget( m_scanner );
82  lay2->addStretch(1);
83 }
84 
85 KMWSocket::~KMWSocket()
86 {
87 }
88 
89 void KMWSocket::updatePrinter(KMPrinter *p)
90 {
91  TQString dev = TQString::fromLatin1("socket://%1:%2").arg(m_printer->text()).arg(m_port->text());
92  p->setDevice(dev);
93 }
94 
95 bool KMWSocket::isValid(TQString& msg)
96 {
97  if (m_printer->text().isEmpty())
98  {
99  msg = i18n("You must enter a printer address.");
100  return false;
101  }
102  TQString port(m_port->text());
103  int p(9100);
104  if (!port.isEmpty())
105  {
106  bool ok;
107  p = port.toInt(&ok);
108  if (!ok)
109  {
110  msg = i18n("Wrong port number.");
111  return false;
112  }
113  }
114 
115  if (!m_scanner->checkPrinter(m_printer->text(),p))
116  {
117  msg = i18n("No printer found at this address/port.");
118  return false;
119  }
120  return true;
121 }
122 
123 void KMWSocket::slotScanStarted()
124 {
125  m_list->clear();
126 }
127 
128 void KMWSocket::slotScanFinished()
129 {
130  const TQPtrList<NetworkScanner::SocketInfo> *list = m_scanner->printerList();
131  TQPtrListIterator<NetworkScanner::SocketInfo> it(*list);
132  for (;it.current();++it)
133  {
134  TQString name;
135  if (it.current()->Name.isEmpty())
136  name = i18n("Unknown host - 1 is the IP", "<Unknown> (%1)").arg(it.current()->IP);
137  else
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"));
141  }
142 }
143 
144 void KMWSocket::slotPrinterSelected(TQListViewItem *item)
145 {
146  if (!item) return;
147  m_printer->setText(item->text(1));
148  m_port->setText(item->text(2));
149 }
150 
151 #include "kmwsocket.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
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeprint by doxygen 1.8.8
This website is maintained by Timothy Pearson.