fix scanner detection, make entrance tab get focus on scan
authorKonrad Rosenbaum <konrad@silmor.de>
Wed, 18 Nov 2015 21:40:13 +0000 (22:40 +0100)
committerKonrad Rosenbaum <konrad@silmor.de>
Wed, 18 Nov 2015 21:40:13 +0000 (22:40 +0100)
plugins/bcs-usb/bcs-plugin.cpp
plugins/bcs-usb/bcs-plugin.h
plugins/bcs-usb/hidscanner.cpp
src/mwin/entrancetab.cpp
src/mwin/entrancetab.h
src/mwin/overview.cpp
src/widgets/barcodeline.cpp
src/widgets/barcodeline.h

index c070d5f..9d29369 100644 (file)
@@ -102,6 +102,7 @@ void MHidBarcodePlugin::restartDetect()
 
 void MHidBarcodePlugin::detectScanners()
 {
+       mscanners.removeAll(nullptr);
        if(!misopen)return;
        qDebug()<<"scanning for scanners...";
        hid_device_info *info=hid_enumerate(0,0);
index f09e732..7c9d76c 100644 (file)
@@ -15,6 +15,8 @@
 
 #include "barcode-plugin.h"
 
+#include <QPointer>
+
 class QTimer;
 class MHidBarcodeScanner;
 class QSettings;
@@ -47,7 +49,7 @@ class MHidBarcodePlugin:public QObject,public MBarcodePlugin
                };
                QList<Config>mconfig;
                Config findCfgMatch(int vendor,int product,int iface,QString serial);
-               QList<MHidBarcodeScanner*>mscanners;
+               QList<QPointer<MHidBarcodeScanner>>mscanners;
                MHidBarcodeScanner*findScanner(QString path);
 };
 
index 7835b68..f683e04 100644 (file)
@@ -34,6 +34,7 @@ MHidBarcodeScanner::MHidBarcodeScanner(QString path,QString setGrp, QObject* par
 MHidBarcodeScanner::~MHidBarcodeScanner()
 {
        deactivate();
+       qDebug()<<"Deleting Scanner"<<mpath<<mname;
 }
 
 void MHidBarcodeScanner::activate()
@@ -81,8 +82,9 @@ void MHidBarcodeScanner::readData()
        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;
index 1feb769..0b96f48 100644 (file)
@@ -48,6 +48,8 @@ MEntranceTab::MEntranceTab(QString pk)
        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();
@@ -118,6 +120,11 @@ class METUtility
                }
 };
 
+void MEntranceTab::askForFocus()
+{
+       emit askForFocus(this);
+}
+
 void MEntranceTab::entranceValidate()
 {
        //get event ID
index ab25294..6ea3dc3 100644 (file)
@@ -50,6 +50,12 @@ class MEntranceTab:public QWidget
                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
index 426a89e..4c737e3 100644 (file)
@@ -174,7 +174,7 @@ MOverview::MOverview(QString pk,std::function<void(int,QString)>initUpdate)
         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)){
index 16a50bb..d993a9a 100644 (file)
@@ -20,17 +20,22 @@ MBarcodeLine::MBarcodeLine(QWidget* parent): MBarcodeLine(QString(),parent)
 
 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();
 }
index 6da7b37..dccda13 100644 (file)
@@ -1,7 +1,7 @@
 //
 // 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