#include <qlabel.h>
#include <qmultilineedit.h>
#include <qlineedit.h>
#include <qpushbutton.h>
#include <qmessagebox.h>
#include <qdatastream.h>
#include <qfile.h>
#include <qtextstream.h>
IrTest::IrTest(QWidget *parent, const char *name) : IrBase(parent, name, true) {
connect(sendTextButton, SIGNAL(clicked()), this, SLOT(sendText()));
connect(sendFileButton, SIGNAL(clicked()), this, SLOT(sendFile()));
irStatus->setText("Especifique el numero del CB");
}
void IrTest::sendText(){
if(textToSend->text().length() == 0 || textToSend->text().length() != 11 ){
QMessageBox::critical(this, "Mensaje", "Por favor escriba un numero de 11 digitos" ,QString("Ok") );
return;
}
QFile b("/usr/mnt.rom/card/bc_ejemplo.lbl");
if ( b.open(IO_ReadWrite) ) { // file opened successfull
QTextStream u( &b ); // use a text stream
u << "! 0 200 200 400 1\r\n";
u << "LABEL\r\n";
u << "CONTRAST 0\r\n";
u << "TONE 0\r\n";
u << "SPEED 5\r\n";
u << "PAGE-WIDTH 600\r\n";
u << "BAR-SENSE\r\n";
u << ";// PAGE 0000000006000400\r\n";
u << "T90 5 3 21 296 Hola Mundo\r\n";
u << "T 5 3 157 89 Desde la ZAURUS\r\n";
u << "BT 0 2 10\r\n";
u << "B UPCA 2 1 90 164 176 " << textToSend->text() << "\r\n";
u << "BT OFF\r\n";
u << "BOX 24 90 129 308 1\r\n";
u << "LINE 279 322 279 338 21\r\n";
u << "BOX 262 314 322 350 1\r\n";
u << "FORM\r\n";
u << "PRINT\r\n";
b.close();
}
QFile f("/usr/mnt.rom/card/bc_ejemplo.lbl");
if ( f.open(IO_ReadOnly) ) { // arch abierto con exito
QDataStream t( &f ); // uso de un stream para texto
QFile p( "/dev/irlpt0" );
if( p.open( IO_WriteOnly ) ) {
QDataStream q( &p );
while ( !t.eof() ) {
q << t;
}
f.close();
p.close();
QMessageBox::critical(this, "Mensaje", "Impresion finalizada." ,QString("Ok") );
}
}
}
void IrTest::sendFile(){
if(!QFile::exists(fileLocation->text())){
QMessageBox::critical(this, "Message", "El archivo no existe." ,QString("Ok") );
return;
}
QFile f( fileLocation->text() );
if ( !f.open( IO_ReadOnly ) ) {
QMessageBox::critical(this, "Mensaje", "El archivo no se pudo abrir." ,QString("Ok") );
return;
} else {
QDataStream t( &f );
QFile p( "/dev/irlpt0" );
if( p.open( IO_WriteOnly ) ) {
QDataStream q( &p );
while ( !t.eof() ) {
q << t;
}
f.close();
p.close();
QMessageBox::critical(this, "Mensaje", "Impresion finalizada." ,QString("Ok") );
}
}
}