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

tdeprint

  • tdeprint
  • tools
  • escputil
escpwidget.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 "escpwidget.h"
21 
22 #include <tqpushbutton.h>
23 #include <tqlayout.h>
24 #include <tqlabel.h>
25 #include <tqcheckbox.h>
26 #include <tqaccel.h>
27 #include <tdemacros.h>
28 #include <tdelocale.h>
29 #include <tdemessagebox.h>
30 #include <kstandarddirs.h>
31 #include <kiconloader.h>
32 #include <kdialogbase.h>
33 #include <klibloader.h>
34 #include <kseparator.h>
35 #include <kdebug.h>
36 
37 class EscpFactory : public KLibFactory
38 {
39 public:
40  EscpFactory(TQObject *parent = 0, const char *name = 0) : KLibFactory(parent, name) {}
41 protected:
42  TQObject* createObject(TQObject *parent = 0, const char *name = 0, const char * className = "TQObject", const TQStringList& args = TQStringList())
43  {
44  Q_UNUSED(className);
45  KDialogBase *dlg = new KDialogBase(static_cast<TQWidget*>(parent), name, true, i18n("EPSON InkJet Printer Utilities"), KDialogBase::Close);
46  EscpWidget *w = new EscpWidget(dlg);
47  if (args.count() > 0)
48  w->setDevice(args[0]);
49  if (args.count() > 1)
50  w->setPrinterName(args[1]);
51  dlg->setMainWidget(w);
52  return dlg;
53  }
54 };
55 
56 extern "C"
57 {
58  void* init_tdeprint_tool_escputil() TDE_EXPORT;
59  void* init_tdeprint_tool_escputil()
60  {
61  return new EscpFactory;
62  }
63 }
64 
65 EscpWidget::EscpWidget(TQWidget *parent, const char *name)
66 : TQWidget(parent, name)
67 {
68  m_hasoutput = false;
69 
70  connect(&m_proc, TQ_SIGNAL(processExited(TDEProcess*)), TQ_SLOT(slotProcessExited(TDEProcess*)));
71  connect(&m_proc, TQ_SIGNAL(receivedStdout(TDEProcess*,char*,int)), TQ_SLOT(slotReceivedStdout(TDEProcess*,char*,int)));
72  connect(&m_proc, TQ_SIGNAL(receivedStderr(TDEProcess*,char*,int)), TQ_SLOT(slotReceivedStderr(TDEProcess*,char*,int)));
73 
74  TQPushButton *cleanbtn = new TQPushButton(this, "-c");
75  cleanbtn->setPixmap(DesktopIcon("application-x-executable"));
76  TQPushButton *nozzlebtn = new TQPushButton(this, "-n");
77  nozzlebtn->setPixmap(DesktopIcon("application-x-executable"));
78  TQPushButton *alignbtn = new TQPushButton(this, "-a");
79  alignbtn->setPixmap(DesktopIcon("application-x-executable"));
80  TQPushButton *inkbtn = new TQPushButton(this, "-i");
81  inkbtn->setPixmap(DesktopIcon("tdeprint_inklevel"));
82  TQPushButton *identbtn = new TQPushButton(this, "-d");
83  identbtn->setPixmap(DesktopIcon("application-x-executable"));
84 
85  TQFont f(font());
86  f.setBold(true);
87  m_printer = new TQLabel(this);
88  m_printer->setFont(f);
89  m_device = new TQLabel(this);
90  m_device->setFont(f);
91  m_useraw = new TQCheckBox(i18n("&Use direct connection (might need root permissions)"), this);
92 
93  connect(cleanbtn, TQ_SIGNAL(clicked()), TQ_SLOT(slotButtonClicked()));
94  connect(nozzlebtn, TQ_SIGNAL(clicked()), TQ_SLOT(slotButtonClicked()));
95  connect(alignbtn, TQ_SIGNAL(clicked()), TQ_SLOT(slotButtonClicked()));
96  connect(inkbtn, TQ_SIGNAL(clicked()), TQ_SLOT(slotButtonClicked()));
97  connect(identbtn, TQ_SIGNAL(clicked()), TQ_SLOT(slotButtonClicked()));
98 
99  TQLabel *printerlab = new TQLabel(i18n("Printer:"), this);
100  printerlab->setAlignment(AlignRight|AlignVCenter);
101  TQLabel *devicelab = new TQLabel(i18n("Device:"), this);
102  devicelab->setAlignment(AlignRight|AlignVCenter);
103  TQLabel *cleanlab = new TQLabel(i18n("Clea&n print head"), this);
104  TQLabel *nozzlelab = new TQLabel(i18n("&Print a nozzle test pattern"), this);
105  TQLabel *alignlab = new TQLabel(i18n("&Align print head"), this);
106  TQLabel *inklab = new TQLabel(i18n("&Ink level"), this);
107  TQLabel *identlab = new TQLabel(i18n("P&rinter identification"), this);
108 
109  cleanlab->setAlignment(AlignLeft|AlignVCenter|ShowPrefix);
110  nozzlelab->setAlignment(AlignLeft|AlignVCenter|ShowPrefix);
111  alignlab->setAlignment(AlignLeft|AlignVCenter|ShowPrefix);
112  inklab->setAlignment(AlignLeft|AlignVCenter|ShowPrefix);
113  identlab->setAlignment(AlignLeft|AlignVCenter|ShowPrefix);
114 
115  cleanbtn->setAccel(TQAccel::shortcutKey(cleanlab->text()));
116  nozzlebtn->setAccel(TQAccel::shortcutKey(nozzlelab->text()));
117  alignbtn->setAccel(TQAccel::shortcutKey(alignlab->text()));
118  inkbtn->setAccel(TQAccel::shortcutKey(inklab->text()));
119  identbtn->setAccel(TQAccel::shortcutKey(identlab->text()));
120 
121  KSeparator *sep = new KSeparator(this);
122  sep->setFixedHeight(10);
123 
124  TQGridLayout *l0 = new TQGridLayout(this, 8, 2, 10, 10);
125  TQGridLayout *l1 = new TQGridLayout(0, 2, 2, 0, 5);
126  l0->addMultiCellLayout(l1, 0, 0, 0, 1);
127  l1->addWidget(printerlab, 0, 0);
128  l1->addWidget(devicelab, 1, 0);
129  l1->addWidget(m_printer, 0, 1);
130  l1->addWidget(m_device, 1, 1);
131  l1->setColStretch(1, 1);
132  l0->addMultiCellWidget(sep, 1, 1, 0, 1);
133  l0->addWidget(cleanbtn, 2, 0);
134  l0->addWidget(nozzlebtn, 3, 0);
135  l0->addWidget(alignbtn, 4, 0);
136  l0->addWidget(inkbtn, 5, 0);
137  l0->addWidget(identbtn, 6, 0);
138  l0->addWidget(cleanlab, 2, 1);
139  l0->addWidget(nozzlelab, 3, 1);
140  l0->addWidget(alignlab, 4, 1);
141  l0->addWidget(inklab, 5, 1);
142  l0->addWidget(identlab, 6, 1);
143  l0->addMultiCellWidget(m_useraw, 7, 7, 0, 1);
144  l0->setColStretch(1, 1);
145 }
146 
147 void EscpWidget::startCommand(const TQString& arg)
148 {
149  bool useUSB(false);
150 
151  if (m_deviceURL.isEmpty())
152  {
153  KMessageBox::error(this, i18n("Internal error: no device set."));
154  return;
155  }
156  else
157  {
158  TQString protocol = m_deviceURL.protocol();
159  if (protocol == "usb")
160  useUSB = true;
161  else if (protocol != "file" && protocol != "parallel" && protocol != "serial" && !protocol.isEmpty())
162  {
163  KMessageBox::error(this,
164  i18n("Unsupported connection type: %1").arg(protocol));
165  return;
166  }
167  }
168 
169  if (m_proc.isRunning())
170  {
171  KMessageBox::error(this, i18n("An escputil process is still running. "
172  "You must wait until its completion before continuing."));
173  return;
174  }
175 
176  TQString exestr = TDEStandardDirs::findExe("escputil");
177  if (exestr.isEmpty())
178  {
179  KMessageBox::error(this, i18n("The executable escputil cannot be found in your "
180  "PATH environment variable. Make sure gimp-print is "
181  "installed and that escputil is in your PATH."));
182  return;
183  }
184 
185  m_proc.clearArguments();
186  m_proc << exestr;
187  if (m_useraw->isChecked() || arg == "-i")
188  m_proc << "-r" << m_deviceURL.path();
189  else
190  m_proc << "-P" << m_printer->text();
191  if (useUSB)
192  m_proc << "-u";
193 
194  m_proc << arg << "-q";
195  m_errorbuffer = m_outbuffer = TQString::null;
196  m_hasoutput = ( arg == "-i" || arg == "-d" );
197  for ( TQValueList<TQCString>::ConstIterator it=m_proc.args().begin(); it!=m_proc.args().end(); ++it )
198  kdDebug() << "ARG: " << *it << endl;
199  if (m_proc.start(TDEProcess::NotifyOnExit, TDEProcess::AllOutput))
200  setEnabled(false);
201  else
202  {
203  KMessageBox::error(this,
204  i18n("Internal error: unable to start escputil process."));
205  return;
206  }
207 }
208 
209 void EscpWidget::slotProcessExited(TDEProcess*)
210 {
211  setEnabled(true);
212  if (!m_proc.normalExit() || m_proc.exitStatus() != 0)
213  {
214  TQString msg1 = "<qt>"+i18n("Operation terminated with errors.")+"</qt>";
215  TQString msg2;
216  if (!m_outbuffer.isEmpty())
217  msg2 += "<p><b><u>"+i18n("Output")+"</u></b></p><p>"+m_outbuffer+"</p>";
218  if (!m_errorbuffer.isEmpty())
219  msg2 += "<p><b><u>"+i18n("Error")+"</u></b></p><p>"+m_errorbuffer+"</p>";
220  if (!msg2.isEmpty())
221  KMessageBox::detailedError(this, msg1, msg2);
222  else
223  KMessageBox::error(this, msg1);
224  }
225  else if ( !m_outbuffer.isEmpty() && m_hasoutput )
226  {
227  KMessageBox::information( this, m_outbuffer );
228  }
229  m_hasoutput = false;
230 }
231 
232 void EscpWidget::slotReceivedStdout(TDEProcess*, char *buf, int len)
233 {
234  TQString bufstr = TQCString(buf, len);
235  m_outbuffer.append(bufstr);
236 }
237 
238 void EscpWidget::slotReceivedStderr(TDEProcess*, char *buf, int len)
239 {
240  TQString bufstr = TQCString(buf, len);
241  m_errorbuffer.append(bufstr);
242 }
243 
244 void EscpWidget::slotButtonClicked()
245 {
246  TQString arg = sender()->name();
247  startCommand(arg);
248 }
249 
250 void EscpWidget::setPrinterName(const TQString& p)
251 {
252  m_printer->setText(p);
253 }
254 
255 void EscpWidget::setDevice(const TQString& dev)
256 {
257  m_deviceURL = dev;
258  m_device->setText(dev);
259 }
260 
261 #include "escpwidget.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.9.1
This website is maintained by Timothy Pearson.