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

tdeprint

kmwlpd.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 <config.h>
00021 #include "kmwlpd.h"
00022 #include "kmwizard.h"
00023 #include "kmprinter.h"
00024 
00025 #include <kurl.h>
00026 #include <tdelocale.h>
00027 #include <tqlabel.h>
00028 #include <kdebug.h>
00029 #include <tqlineedit.h>
00030 #include <tdemessagebox.h>
00031 #include <kextsock.h>
00032 
00033 static bool checkLpdQueue(const char *host, const char *queue);
00034 
00035 //********************************************************************************************************
00036 
00037 KMWLpd::KMWLpd(TQWidget *parent, const char *name)
00038 : KMWInfoBase(2,parent,name)
00039 {
00040     m_ID = KMWizard::LPD;
00041     m_title = i18n("LPD Queue Information");
00042     m_nextpage = KMWizard::Driver;
00043 
00044     setInfo(i18n("<p>Enter the information concerning the remote LPD queue; "
00045              "this wizard will check it before continuing.</p>"));
00046     setLabel(0,i18n("Host:"));
00047     setLabel(1,i18n("Queue:"));
00048 }
00049 
00050 bool KMWLpd::isValid(TQString& msg)
00051 {
00052     if (text(0).isEmpty() || text(1).isEmpty())
00053     {
00054         msg = i18n("Some information is missing.");
00055         return false;
00056     }
00057 
00058     // check LPD queue
00059     if (!checkLpdQueue(text(0).latin1(),text(1).latin1()))
00060     {
00061         if (KMessageBox::warningContinueCancel(this, i18n("Cannot find queue %1 on server %2; do you want to continue anyway?").arg(text(1)).arg(text(0))) == KMessageBox::Cancel)
00062             return false;
00063     }
00064     return true;
00065 }
00066 
00067 void KMWLpd::updatePrinter(KMPrinter *p)
00068 {
00069     QString dev = TQString::fromLatin1("lpd://%1/%2").arg(text(0)).arg(text(1));
00070     p->setDevice(dev);
00071 }
00072 
00073 //*******************************************************************************************************
00074 
00075 bool checkLpdQueue(const char *host, const char *queue)
00076 {
00077     KExtendedSocket sock(host, "printer", KExtendedSocket::streamSocket);
00078     sock.setBlockingMode(true);
00079     if (sock.connect() != 0)
00080         return false;
00081 
00082     char    res[64] = {0};
00083     snprintf(res,64,"%c%s\n",(char)4,queue);
00084     if (sock.tqwriteBlock(res, strlen(res)) != (TQ_LONG)(strlen(res)))
00085         return false;
00086 
00087     char    buf[1024] = {0};
00088     int n, tot(1);
00089     while ((n = sock.tqreadBlock(res, 63)) > 0)
00090     {
00091         res[n] = 0;
00092         tot += n;
00093         if (tot >= 1024)
00094             break;
00095         else
00096             strcat(buf, res);
00097     }
00098     sock.close();
00099     if (strlen(buf) == 0 || strstr(buf, "unknown printer") != NULL)
00100         return false;
00101     return true;
00102 }

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.6.3
This website is maintained by Timothy Pearson.