20 #include "escpwidget.h"
22 #include <tqpushbutton.h>
25 #include <tqcheckbox.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>
37 class EscpFactory :
public KLibFactory
40 EscpFactory(TQObject *parent = 0,
const char *name = 0) : KLibFactory(parent, name) {}
42 TQObject* createObject(TQObject *parent = 0,
const char *name = 0,
const char * className =
"TQObject",
const TQStringList& args = TQStringList())
45 KDialogBase *dlg =
new KDialogBase(
static_cast<TQWidget*
>(parent), name,
true, i18n(
"EPSON InkJet Printer Utilities"), KDialogBase::Close);
46 EscpWidget *w =
new EscpWidget(dlg);
48 w->setDevice(args[0]);
50 w->setPrinterName(args[1]);
51 dlg->setMainWidget(w);
58 void* init_tdeprint_tool_escputil() TDE_EXPORT;
59 void* init_tdeprint_tool_escputil()
61 return new EscpFactory;
65 EscpWidget::EscpWidget(TQWidget *parent,
const char *name)
66 : TQWidget(parent, name)
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)));
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"));
87 m_printer =
new TQLabel(
this);
88 m_printer->setFont(f);
89 m_device =
new TQLabel(
this);
91 m_useraw =
new TQCheckBox(i18n(
"&Use direct connection (might need root permissions)"),
this);
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()));
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);
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);
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()));
121 KSeparator *sep =
new KSeparator(
this);
122 sep->setFixedHeight(10);
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);
147 void EscpWidget::startCommand(
const TQString& arg)
151 if (m_deviceURL.isEmpty())
153 KMessageBox::error(
this, i18n(
"Internal error: no device set."));
158 TQString protocol = m_deviceURL.protocol();
159 if (protocol ==
"usb")
161 else if (protocol !=
"file" && protocol !=
"parallel" && protocol !=
"serial" && !protocol.isEmpty())
163 KMessageBox::error(
this,
164 i18n(
"Unsupported connection type: %1").arg(protocol));
169 if (m_proc.isRunning())
171 KMessageBox::error(
this, i18n(
"An escputil process is still running. "
172 "You must wait until its completion before continuing."));
176 TQString exestr = TDEStandardDirs::findExe(
"escputil");
177 if (exestr.isEmpty())
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."));
185 m_proc.clearArguments();
187 if (m_useraw->isChecked() || arg ==
"-i")
188 m_proc <<
"-r" << m_deviceURL.path();
190 m_proc <<
"-P" << m_printer->text();
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))
203 KMessageBox::error(
this,
204 i18n(
"Internal error: unable to start escputil process."));
209 void EscpWidget::slotProcessExited(TDEProcess*)
212 if (!m_proc.normalExit() || m_proc.exitStatus() != 0)
214 TQString msg1 =
"<qt>"+i18n(
"Operation terminated with errors.")+
"</qt>";
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>";
221 KMessageBox::detailedError(
this, msg1, msg2);
223 KMessageBox::error(
this, msg1);
225 else if ( !m_outbuffer.isEmpty() && m_hasoutput )
227 KMessageBox::information(
this, m_outbuffer );
232 void EscpWidget::slotReceivedStdout(TDEProcess*,
char *buf,
int len)
234 TQString bufstr = TQCString(buf, len);
235 m_outbuffer.append(bufstr);
238 void EscpWidget::slotReceivedStderr(TDEProcess*,
char *buf,
int len)
240 TQString bufstr = TQCString(buf, len);
241 m_errorbuffer.append(bufstr);
244 void EscpWidget::slotButtonClicked()
246 TQString arg = sender()->name();
250 void EscpWidget::setPrinterName(
const TQString& p)
252 m_printer->setText(p);
255 void EscpWidget::setDevice(
const TQString& dev)
258 m_device->setText(dev);
261 #include "escpwidget.moc"