# kdeprint Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# kmwsocket.cpp

    00001 /*
    00002  *  This file is part of the KDE libraries
    00003  *  Copyright (c) 2001 Michael Goffioul <kdeprint@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., 59 Temple Place - Suite 330,
    00017  *  Boston, MA 02111-1307, USA.
    00018  **/
    00019
    00020 #include "kmwsocket.h"
    00021 #include "networkscanner.h"
    00022 #include "kmwizard.h"
    00023 #include "kmprinter.h"
    00024
    00025 #include <klistview.h>
    00026 #include <qheader.h>
    00027 #include <qlineedit.h>
    00028 #include <qlabel.h>
    00029 #include <kmessagebox.h>
    00030 #include <qlayout.h>
    00031 #include <klocale.h>
    00032 #include <kiconloader.h>
    00033 #include <kseparator.h>
    00034
    00035 KMWSocket::KMWSocket(QWidget *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 KListView(this);
    00043     m_list->addColumn("");
    00044     m_list->header()->hide();
    00045     m_list->setFrameStyle(QFrame::WinPanel|QFrame::Sunken);
    00046     m_list->setLineWidth(1);
    00047
    00048     QLabel  *l1 = new QLabel(i18n("&Printer address:"),this);
    00049     QLabel  *l2 = new QLabel(i18n("P&ort:"),this);
    00050
    00051     m_printer = new QLineEdit(this);
    00052     m_port = new QLineEdit(this);
    00053
    00054     l1->setBuddy(m_printer);
    00055     l2->setBuddy(m_port);
    00056
    00057     m_scanner = new NetworkScanner( 9100, this );
    00058
    00059     KSeparator* sep = new KSeparator( KSeparator::HLine, this);
    00060     sep->setFixedHeight(40);
    00061
    00062     connect(m_list,SIGNAL(selectionChanged(QListViewItem*)),SLOT(slotPrinterSelected(QListViewItem*)));
    00063     connect( m_scanner, SIGNAL( scanStarted() ), SLOT( slotScanStarted() ) );
    00064     connect( m_scanner, SIGNAL( scanFinished() ), SLOT( slotScanFinished() ) );
    00065     connect( m_scanner, SIGNAL( scanStarted() ), parent, SLOT( disableWizard() ) );
    00066     connect( m_scanner, SIGNAL( scanFinished() ), parent, SLOT( enableWizard() ) );
    00067
    00068     // layout
    00069     QHBoxLayout *lay3 = new QHBoxLayout(this, 0, 10);
    00070     QVBoxLayout *lay2 = new QVBoxLayout(0, 0, 0);
    00071
    00072     lay3->addWidget(m_list,1);
    00073     lay3->addLayout(lay2,1);
    00074     lay2->addWidget(l1);
    00075     lay2->addWidget(m_printer);
    00076     lay2->addSpacing(10);
    00077     lay2->addWidget(l2);
    00078     lay2->addWidget(m_port);
    00079     lay2->addWidget(sep);
    00080     lay2->addWidget( m_scanner );
    00081     lay2->addStretch(1);
    00082 }
    00083
    00084 KMWSocket::~KMWSocket()
    00085 {
    00086 }
    00087
    00088 void KMWSocket::updatePrinter(KMPrinter *p)
    00089 {
    00090     QString dev = QString::fromLatin1("socket://%1:%2").arg(m_printer->text()).arg(m_port->text());
    00091     p->setDevice(dev);
    00092 }
    00093
    00094 bool KMWSocket::isValid(QString& msg)
    00095 {
    00096     if (m_printer->text().isEmpty())
    00097     {
    00098         msg = i18n("You must enter a printer address.");
    00099         return false;
    00100     }
    00101     QString port(m_port->text());
    00102     int p(9100);
    00103     if (!port.isEmpty())
    00104     {
    00105         bool    ok;
    00106         p = port.toInt(&ok);
    00107         if (!ok)
    00108         {
    00109             msg = i18n("Wrong port number.");
    00110             return false;
    00111         }
    00112     }
    00113
    00114     if (!m_scanner->checkPrinter(m_printer->text(),p))
    00115     {
    00116         msg = i18n("No printer found at this address/port.");
    00117         return false;
    00118     }
    00119     return true;
    00120 }
    00121
    00122 void KMWSocket::slotScanStarted()
    00123 {
    00124     m_list->clear();
    00125 }
    00126
    00127 void KMWSocket::slotScanFinished()
    00128 {
    00129     const QPtrList<NetworkScanner::SocketInfo>  *list = m_scanner->printerList();
    00130     QPtrListIterator<NetworkScanner::SocketInfo>    it(*list);
    00131     for (;it.current();++it)
    00132     {
    00133         QString name;
    00134         if (it.current()->Name.isEmpty())
    00135             name = i18n("Unknown host - 1 is the IP", "<Unknown> (%1)").arg(it.current()->IP);
    00136         else
    00137             name = it.current()->Name;
    00138         QListViewItem   *item = new QListViewItem(m_list,name,it.current()->IP,QString::number(it.current()->Port));
    00139         item->setPixmap(0,SmallIcon("kdeprint_printer"));
    00140     }
    00141 }
    00142
    00143 void KMWSocket::slotPrinterSelected(QListViewItem *item)
    00144 {
    00145     if (!item) return;
    00146     m_printer->setText(item->text(1));
    00147     m_port->setText(item->text(2));
    00148 }
    00149
    00150 #include "kmwsocket.moc"

This file is part of the documentation for kdeprint Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:31:03 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003