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

tdeprint

  • tdeprint
  • management
kmwlpd.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 <config.h>
21 #include "kmwlpd.h"
22 #include "kmwizard.h"
23 #include "kmprinter.h"
24 
25 #include <kurl.h>
26 #include <tdelocale.h>
27 #include <tqlabel.h>
28 #include <kdebug.h>
29 #include <tqlineedit.h>
30 #include <tdemessagebox.h>
31 #include <kextsock.h>
32 
33 static bool checkLpdQueue(const char *host, const char *queue);
34 
35 //********************************************************************************************************
36 
37 KMWLpd::KMWLpd(TQWidget *parent, const char *name)
38 : KMWInfoBase(2,parent,name)
39 {
40  m_ID = KMWizard::LPD;
41  m_title = i18n("LPD Queue Information");
42  m_nextpage = KMWizard::Driver;
43 
44  setInfo(i18n("<p>Enter the information concerning the remote LPD queue; "
45  "this wizard will check it before continuing.</p>"));
46  setLabel(0,i18n("Host:"));
47  setLabel(1,i18n("Queue:"));
48 }
49 
50 bool KMWLpd::isValid(TQString& msg)
51 {
52  if (text(0).isEmpty() || text(1).isEmpty())
53  {
54  msg = i18n("Some information is missing.");
55  return false;
56  }
57 
58  // check LPD queue
59  if (!checkLpdQueue(text(0).latin1(),text(1).latin1()))
60  {
61  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)
62  return false;
63  }
64  return true;
65 }
66 
67 void KMWLpd::updatePrinter(KMPrinter *p)
68 {
69  TQString dev = TQString::fromLatin1("lpd://%1/%2").arg(text(0)).arg(text(1));
70  p->setDevice(dev);
71 }
72 
73 //*******************************************************************************************************
74 
75 bool checkLpdQueue(const char *host, const char *queue)
76 {
77  KExtendedSocket sock(host, "printer", KExtendedSocket::streamSocket);
78  sock.setBlockingMode(true);
79  if (sock.connect() != 0)
80  return false;
81 
82  char res[64] = {0};
83  snprintf(res,64,"%c%s\n",(char)4,queue);
84  if (sock.writeBlock(res, strlen(res)) != (TQ_LONG)(strlen(res)))
85  return false;
86 
87  char buf[1024] = {0};
88  int n, tot(1);
89  while ((n = sock.readBlock(res, 63)) > 0)
90  {
91  res[n] = 0;
92  tot += n;
93  if (tot >= 1024)
94  break;
95  else
96  strcat(buf, res);
97  }
98  sock.close();
99  if (strlen(buf) == 0 || strstr(buf, "unknown printer") != NULL)
100  return false;
101  return true;
102 }

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