00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
#include "escpwidget.h"
00021
00022
#include <qpushbutton.h>
00023
#include <qlayout.h>
00024
#include <qlabel.h>
00025
#include <qcheckbox.h>
00026
#include <qaccel.h>
00027
#include <kdemacros.h>
00028
#include <klocale.h>
00029
#include <kmessagebox.h>
00030
#include <kstandarddirs.h>
00031
#include <kiconloader.h>
00032
#include <kdialogbase.h>
00033
#include <klibloader.h>
00034
#include <kseparator.h>
00035
#include <kdebug.h>
00036
00037
class EscpFactory :
public KLibFactory
00038 {
00039
public:
00040 EscpFactory(
QObject *parent = 0,
const char *name = 0) : KLibFactory(parent, name) {}
00041
protected:
00042
QObject* createObject(
QObject *parent = 0,
const char *name = 0,
const char * =
"QObject",
const QStringList& args =
QStringList())
00043 {
00044 KDialogBase *dlg =
new KDialogBase(static_cast<QWidget*>(parent), name,
true, i18n(
"EPSON InkJet Printer Utilities"), KDialogBase::Close);
00045 EscpWidget *w =
new EscpWidget(dlg);
00046
if (args.count() > 0)
00047 w->setDevice(args[0]);
00048
if (args.count() > 1)
00049 w->setPrinterName(args[1]);
00050 dlg->setMainWidget(w);
00051
return dlg;
00052 }
00053 };
00054
00055
extern "C"
00056 {
00057
void* init_kdeprint_tool_escputil() KDE_EXPORT;
00058
void* init_kdeprint_tool_escputil()
00059 {
00060
return new EscpFactory;
00061 }
00062 }
00063
00064 EscpWidget::EscpWidget(
QWidget *parent,
const char *name)
00065 :
QWidget(parent, name)
00066 {
00067 m_hasoutput =
false;
00068
00069 connect(&m_proc, SIGNAL(processExited(KProcess*)), SLOT(slotProcessExited(KProcess*)));
00070 connect(&m_proc, SIGNAL(receivedStdout(KProcess*,
char*,
int)), SLOT(slotReceivedStdout(KProcess*,
char*,
int)));
00071 connect(&m_proc, SIGNAL(receivedStderr(KProcess*,
char*,
int)), SLOT(slotReceivedStderr(KProcess*,
char*,
int)));
00072
00073
QPushButton *cleanbtn =
new QPushButton(
this,
"-c");
00074 cleanbtn->setPixmap(DesktopIcon(
"exec"));
00075 QPushButton *nozzlebtn =
new QPushButton(
this,
"-n");
00076 nozzlebtn->setPixmap(DesktopIcon(
"exec"));
00077 QPushButton *alignbtn =
new QPushButton(
this,
"-a");
00078 alignbtn->setPixmap(DesktopIcon(
"exec"));
00079 QPushButton *inkbtn =
new QPushButton(
this,
"-i");
00080 inkbtn->setPixmap(DesktopIcon(
"kdeprint_inklevel"));
00081 QPushButton *identbtn =
new QPushButton(
this,
"-d");
00082 identbtn->setPixmap(DesktopIcon(
"exec"));
00083
00084
QFont f(font());
00085 f.setBold(
true);
00086 m_printer =
new QLabel(
this);
00087 m_printer->setFont(f);
00088 m_device =
new QLabel(
this);
00089 m_device->setFont(f);
00090 m_useraw =
new QCheckBox(i18n(
"&Use direct connection (might need root permissions)"),
this);
00091
00092 connect(cleanbtn, SIGNAL(clicked()), SLOT(slotButtonClicked()));
00093 connect(nozzlebtn, SIGNAL(clicked()), SLOT(slotButtonClicked()));
00094 connect(alignbtn, SIGNAL(clicked()), SLOT(slotButtonClicked()));
00095 connect(inkbtn, SIGNAL(clicked()), SLOT(slotButtonClicked()));
00096 connect(identbtn, SIGNAL(clicked()), SLOT(slotButtonClicked()));
00097
00098 QLabel *printerlab =
new QLabel(i18n(
"Printer:"),
this);
00099 printerlab->setAlignment(AlignRight|AlignVCenter);
00100 QLabel *devicelab =
new QLabel(i18n(
"Device:"),
this);
00101 devicelab->setAlignment(AlignRight|AlignVCenter);
00102 QLabel *cleanlab =
new QLabel(i18n(
"Clea&n print head"),
this);
00103 QLabel *nozzlelab =
new QLabel(i18n(
"&Print a nozzle test pattern"),
this);
00104 QLabel *alignlab =
new QLabel(i18n(
"&Align print head"),
this);
00105 QLabel *inklab =
new QLabel(i18n(
"&Ink level"),
this);
00106 QLabel *identlab =
new QLabel(i18n(
"P&rinter identification"),
this);
00107
00108 cleanlab->setAlignment(AlignLeft|AlignVCenter|ShowPrefix);
00109 nozzlelab->setAlignment(AlignLeft|AlignVCenter|ShowPrefix);
00110 alignlab->setAlignment(AlignLeft|AlignVCenter|ShowPrefix);
00111 inklab->setAlignment(AlignLeft|AlignVCenter|ShowPrefix);
00112 identlab->setAlignment(AlignLeft|AlignVCenter|ShowPrefix);
00113
00114 cleanbtn->setAccel(QAccel::shortcutKey(cleanlab->text()));
00115 nozzlebtn->setAccel(QAccel::shortcutKey(nozzlelab->text()));
00116 alignbtn->setAccel(QAccel::shortcutKey(alignlab->text()));
00117 inkbtn->setAccel(QAccel::shortcutKey(inklab->text()));
00118 identbtn->setAccel(QAccel::shortcutKey(identlab->text()));
00119
00120 KSeparator *sep =
new KSeparator(
this);
00121 sep->setFixedHeight(10);
00122
00123
QGridLayout *l0 =
new QGridLayout(
this, 8, 2, 10, 10);
00124 QGridLayout *l1 =
new QGridLayout(0, 2, 2, 0, 5);
00125 l0->addMultiCellLayout(l1, 0, 0, 0, 1);
00126 l1->addWidget(printerlab, 0, 0);
00127 l1->addWidget(devicelab, 1, 0);
00128 l1->addWidget(m_printer, 0, 1);
00129 l1->addWidget(m_device, 1, 1);
00130 l1->setColStretch(1, 1);
00131 l0->addMultiCellWidget(sep, 1, 1, 0, 1);
00132 l0->addWidget(cleanbtn, 2, 0);
00133 l0->addWidget(nozzlebtn, 3, 0);
00134 l0->addWidget(alignbtn, 4, 0);
00135 l0->addWidget(inkbtn, 5, 0);
00136 l0->addWidget(identbtn, 6, 0);
00137 l0->addWidget(cleanlab, 2, 1);
00138 l0->addWidget(nozzlelab, 3, 1);
00139 l0->addWidget(alignlab, 4, 1);
00140 l0->addWidget(inklab, 5, 1);
00141 l0->addWidget(identlab, 6, 1);
00142 l0->addMultiCellWidget(m_useraw, 7, 7, 0, 1);
00143 l0->setColStretch(1, 1);
00144 }
00145
00146
void EscpWidget::startCommand(
const QString& arg)
00147 {
00148
bool useUSB(
false);
00149
00150
if (m_deviceURL.isEmpty())
00151 {
00152 KMessageBox::error(
this, i18n(
"Internal error: no device set."));
00153
return;
00154 }
00155
else
00156 {
00157
QString protocol = m_deviceURL.protocol();
00158
if (protocol ==
"usb")
00159 useUSB =
true;
00160
else if (protocol !=
"file" && protocol !=
"parallel" && protocol !=
"serial" && !protocol.isEmpty())
00161 {
00162 KMessageBox::error(
this,
00163 i18n(
"Unsupported connection type: %1").arg(protocol));
00164
return;
00165 }
00166 }
00167
00168
if (m_proc.isRunning())
00169 {
00170 KMessageBox::error(
this, i18n(
"An escputil process is still running. "
00171
"You must wait until its completion before continuing."));
00172
return;
00173 }
00174
00175
QString exestr = KStandardDirs::findExe(
"escputil");
00176
if (exestr.isEmpty())
00177 {
00178 KMessageBox::error(
this, i18n(
"The executable escputil cannot be found in your "
00179
"PATH environment variable. Make sure gimp-print is "
00180
"installed and that escputil is in your PATH."));
00181
return;
00182 }
00183
00184 m_proc.clearArguments();
00185 m_proc << exestr;
00186
if (m_useraw->isChecked() || arg ==
"-i")
00187 m_proc <<
"-r" << m_deviceURL.path();
00188
else
00189 m_proc <<
"-P" << m_printer->text();
00190
if (useUSB)
00191 m_proc <<
"-u";
00192
00193 m_proc << arg <<
"-q";
00194 m_errorbuffer = m_outbuffer = QString::null;
00195 m_hasoutput = ( arg ==
"-i" || arg ==
"-d" );
00196
for (
QValueList<QCString>::ConstIterator it=m_proc.args().begin(); it!=m_proc.args().end(); ++it )
00197 kdDebug() <<
"ARG: " << *it << endl;
00198
if (m_proc.start(KProcess::NotifyOnExit, KProcess::AllOutput))
00199 setEnabled(
false);
00200
else
00201 {
00202 KMessageBox::error(
this,
00203 i18n(
"Internal error: unable to start escputil process."));
00204
return;
00205 }
00206 }
00207
00208
void EscpWidget::slotProcessExited(KProcess*)
00209 {
00210 setEnabled(
true);
00211
if (!m_proc.normalExit() || m_proc.exitStatus() != 0)
00212 {
00213
QString msg1 =
"<qt>"+i18n(
"Operation terminated with errors.")+
"</qt>";
00214
QString msg2;
00215
if (!m_outbuffer.isEmpty())
00216 msg2 +=
"<p><b><u>"+i18n(
"Output")+
"</u></b></p><p>"+m_outbuffer+
"</p>";
00217
if (!m_errorbuffer.isEmpty())
00218 msg2 +=
"<p><b><u>"+i18n(
"Error")+
"</u></b></p><p>"+m_errorbuffer+
"</p>";
00219
if (!msg2.isEmpty())
00220 KMessageBox::detailedError(
this, msg1, msg2);
00221
else
00222 KMessageBox::error(
this, msg1);
00223 }
00224
else if ( !m_outbuffer.isEmpty() && m_hasoutput )
00225 {
00226 KMessageBox::information(
this, m_outbuffer );
00227 }
00228 m_hasoutput =
false;
00229 }
00230
00231
void EscpWidget::slotReceivedStdout(KProcess*,
char *buf,
int len)
00232 {
00233
QString bufstr =
QCString(buf, len);
00234 m_outbuffer.append(bufstr);
00235 }
00236
00237
void EscpWidget::slotReceivedStderr(KProcess*,
char *buf,
int len)
00238 {
00239
QString bufstr =
QCString(buf, len);
00240 m_errorbuffer.append(bufstr);
00241 }
00242
00243
void EscpWidget::slotButtonClicked()
00244 {
00245
QString arg = sender()->name();
00246 startCommand(arg);
00247 }
00248
00249
void EscpWidget::setPrinterName(
const QString& p)
00250 {
00251 m_printer->setText(p);
00252 }
00253
00254
void EscpWidget::setDevice(
const QString& dev)
00255 {
00256 m_deviceURL = dev;
00257 m_device->setText(dev);
00258 }
00259
00260
#include "escpwidget.moc"