void MHidBarcodePlugin::detectScanners()
{
+ mscanners.removeAll(nullptr);
if(!misopen)return;
qDebug()<<"scanning for scanners...";
hid_device_info *info=hid_enumerate(0,0);
#include "barcode-plugin.h"
+#include <QPointer>
+
class QTimer;
class MHidBarcodeScanner;
class QSettings;
};
QList<Config>mconfig;
Config findCfgMatch(int vendor,int product,int iface,QString serial);
- QList<MHidBarcodeScanner*>mscanners;
+ QList<QPointer<MHidBarcodeScanner>>mscanners;
MHidBarcodeScanner*findScanner(QString path);
};
MHidBarcodeScanner::~MHidBarcodeScanner()
{
deactivate();
+ qDebug()<<"Deleting Scanner"<<mpath<<mname;
}
void MHidBarcodeScanner::activate()
while(true){
const int rs=hid_read(mdev,buf,sizeof(buf));
if(rs<0){
- qDebug()<<"Error reading from USB device"<<mpath<<mname;
+ qDebug()<<"Error reading from USB device"<<mpath<<mname<<"Device will be closed.";
deactivate();
+ deleteLater();
break;
}
if(rs==0)break;
vl->addWidget(new QLabel(tr("Enter or scan Ticket-ID:")),0);
vl->addWidget(entrancescan=new MBarcodeLine,0);
connect(entrancescan,SIGNAL(returnPressed()),this,SLOT(entranceValidate()));
+ connect(entrancescan,SIGNAL(askForFocus()),this,SLOT(askForFocus()));
+ qobject_cast< MBarcodeLine* >(entrancescan)->setScanMode(MBarcodeLine::ScanMode::ForceFocus);
vl->addWidget(entrancelabel=new QLabel(" "),10);
entrancelabel->setAutoFillBackground(true);
QFont fnt=entrancelabel->font();
}
};
+void MEntranceTab::askForFocus()
+{
+ emit askForFocus(this);
+}
+
void MEntranceTab::entranceValidate()
{
//get event ID
void resetAmounts();
/**configure the entrance*/
void configure();
+ ///handles the askForFocus signal from the barcode line
+ void askForFocus();
+
+ signals:
+ ///asks the parent to get focus
+ void askForFocus(QWidget*);
private:
friend class METUtility;
//the profile associated with this session
if(initUpdate)initUpdate(70,tr("Getting Entrance Data..."));
entrancetab=new MEntranceTab(pk);
addTab(entrancetab,tr("Entrance"),entrancetab->menu());
-
+ connect(entrancetab,SIGNAL(askForFocus(QWidget*)),this,SLOT(setCurrentTab(QWidget*)));
//unused tab disabling...
if(!req->hasRight(req->RGetAllEvents)){
MBarcodeLine::MBarcodeLine(const QString& cont, QWidget* parent): QLineEdit(cont,parent)
{
- setToolTip(tr("Type a barcode into this line or scan it with a barcode scanner."));
- setPlaceholderText(tr("Type or scan a barcode."));
- connect(MBarcodeHub::instance(),SIGNAL(newBarcode(QString)), this,SLOT(setBarcode(QString)));
+ setToolTip(tr("Type a barcode into this line or scan it with a barcode scanner."));
+ setPlaceholderText(tr("Type or scan a barcode."));
+ connect(MBarcodeHub::instance(),SIGNAL(newBarcode(QString)), this,SLOT(setBarcode(QString)));
}
void MBarcodeLine::setBarcode(QString bc)
{
- //do we actually have focus?
- //TODO: maybe this should be visibility?
- if(!hasFocus())return;
- //enter barcode and emit ready signal
- setText(bc);
- emit returnPressed();
+ if(bc.isEmpty())return;
+ //do we actually have focus?
+ //TODO: maybe this should be visibility?
+ if(scanMode()==ScanMode::InFocus && !hasFocus())return;
+ if(scanMode()==ScanMode::ForceFocus){
+ setFocus();
+ emit askForFocus();
+ }
+ //enter barcode and emit ready signal
+ setText(bc);
+ emit returnPressed();
}
//
// C++ Interface: barcode line edit
//
-// Description:
+// Description:
//
//
// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2014
class MBarcodeLine:public QLineEdit
{
- Q_OBJECT
- public:
- explicit MBarcodeLine(QWidget* parent = 0);
- explicit MBarcodeLine(const QString& , QWidget* parent = 0);
- private slots:
- void setBarcode(QString);
+ Q_OBJECT
+ public:
+ explicit MBarcodeLine(QWidget* parent = 0);
+ explicit MBarcodeLine(const QString& , QWidget* parent = 0);
+
+ enum class ScanMode{
+ InFocus,
+ InBackground,
+ ForceFocus,
+ };
+
+ ScanMode scanMode()const{return mscanmode;}
+
+ private slots:
+ void setBarcode(QString);
+
+ public slots:
+ void setScanMode(ScanMode mode){mscanmode=mode;}
+
+ signals:
+ void askForFocus();
+
+ private:
+ ScanMode mscanmode=ScanMode::InFocus;
};
#endif