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

tdeprint

kmwsocket.cpp

00001 /*
00002  *  This file is part of the KDE libraries
00003  *  Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
00004  *
00005  *  This library is free software; you can redistribute it and/or
00006  *  modify it under the terms of the GNU Library General Public
00007  *  License version 2 as published by the Free Software Foundation.
00008  *
00009  *  This library is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  *  Library General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU Library General Public License
00015  *  along with this library; see the file COPYING.LIB.  If not, write to
00016  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  *  Boston, MA 02110-1301, USA.
00018  **/
00019 
00020 #include "kmwsocket.h"
00021 #include "networkscanner.h"
00022 #include "kmwizard.h"
00023 #include "kmprinter.h"
00024 
00025 #include <tdelistview.h>
00026 #include <tqheader.h>
00027 #include <tqlineedit.h>
00028 #include <tqlabel.h>
00029 #include <tdemessagebox.h>
00030 #include <tqlayout.h>
00031 #include <tdelocale.h>
00032 #include <kiconloader.h>
00033 #include <kseparator.h>
00034 
00035 KMWSocket::KMWSocket(TQWidget *parent, const char *name)
00036 : KMWizardPage(parent,name)
00037 {
00038     m_title = i18n("Network Printer Information");
00039     m_ID = KMWizard::TCP;
00040     m_nextpage = KMWizard::Driver;
00041 
00042     m_list = new TDEListView(this);
00043     m_list->addColumn("");
00044     m_list->header()->hide();
00045     m_list->setFrameStyle(TQFrame::WinPanel|TQFrame::Sunken);
00046     m_list->setLineWidth(1);
00047 
00048     TQLabel *l1 = new TQLabel(i18n("&Printer address:"),this);
00049     TQLabel *l2 = new TQLabel(i18n("P&ort:"),this);
00050 
00051     m_printer = new TQLineEdit(this);
00052     m_port = new TQLineEdit(this);
00053     m_port->setText(TQString("9100"));
00054 
00055     l1->setBuddy(m_printer);
00056     l2->setBuddy(m_port);
00057 
00058     m_scanner = new NetworkScanner( 9100, this );
00059 
00060     KSeparator* sep = new KSeparator( KSeparator::HLine, this);
00061     sep->setFixedHeight(40);
00062 
00063     connect(m_list,TQT_SIGNAL(selectionChanged(TQListViewItem*)),TQT_SLOT(slotPrinterSelected(TQListViewItem*)));
00064     connect( m_scanner, TQT_SIGNAL( scanStarted() ), TQT_SLOT( slotScanStarted() ) );
00065     connect( m_scanner, TQT_SIGNAL( scanFinished() ), TQT_SLOT( slotScanFinished() ) );
00066     connect( m_scanner, TQT_SIGNAL( scanStarted() ), parent, TQT_SLOT( disableWizard() ) );
00067     connect( m_scanner, TQT_SIGNAL( scanFinished() ), parent, TQT_SLOT( enableWizard() ) );
00068 
00069     // layout
00070     TQHBoxLayout    *lay3 = new TQHBoxLayout(this, 0, 10);
00071     TQVBoxLayout    *lay2 = new TQVBoxLayout(0, 0, 0);
00072 
00073     lay3->addWidget(m_list,1);
00074     lay3->addLayout(lay2,1);
00075     lay2->addWidget(l1);
00076     lay2->addWidget(m_printer);
00077     lay2->addSpacing(10);
00078     lay2->addWidget(l2);
00079     lay2->addWidget(m_port);
00080     lay2->addWidget(sep);
00081     lay2->addWidget( m_scanner );
00082     lay2->addStretch(1);
00083 }
00084 
00085 KMWSocket::~KMWSocket()
00086 {
00087 }
00088 
00089 void KMWSocket::updatePrinter(KMPrinter *p)
00090 {
00091     TQString    dev = TQString::fromLatin1("socket://%1:%2").arg(m_printer->text()).arg(m_port->text());
00092     p->setDevice(dev);
00093 }
00094 
00095 bool KMWSocket::isValid(TQString& msg)
00096 {
00097     if (m_printer->text().isEmpty())
00098     {
00099         msg = i18n("You must enter a printer address.");
00100         return false;
00101     }
00102     TQString    port(m_port->text());
00103     int p(9100);
00104     if (!port.isEmpty())
00105     {
00106         bool    ok;
00107         p = port.toInt(&ok);
00108         if (!ok)
00109         {
00110             msg = i18n("Wrong port number.");
00111             return false;
00112         }
00113     }
00114 
00115     if (!m_scanner->checkPrinter(m_printer->text(),p))
00116     {
00117         msg = i18n("No printer found at this address/port.");
00118         return false;
00119     }
00120     return true;
00121 }
00122 
00123 void KMWSocket::slotScanStarted()
00124 {
00125     m_list->clear();
00126 }
00127 
00128 void KMWSocket::slotScanFinished()
00129 {
00130     const TQPtrList<NetworkScanner::SocketInfo> *list = m_scanner->printerList();
00131     TQPtrListIterator<NetworkScanner::SocketInfo>   it(*list);
00132     for (;it.current();++it)
00133     {
00134         TQString    name;
00135         if (it.current()->Name.isEmpty())
00136             name = i18n("Unknown host - 1 is the IP", "<Unknown> (%1)").arg(it.current()->IP);
00137         else
00138             name = it.current()->Name;
00139         TQListViewItem  *item = new TQListViewItem(m_list,name,it.current()->IP,TQString::number(it.current()->Port));
00140         item->setPixmap(0,SmallIcon("tdeprint_printer"));
00141     }
00142 }
00143 
00144 void KMWSocket::slotPrinterSelected(TQListViewItem *item)
00145 {
00146     if (!item) return;
00147     m_printer->setText(item->text(1));
00148     m_port->setText(item->text(2));
00149 }
00150 
00151 #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
  • 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.7.1
This website is maintained by Timothy Pearson.