diff --git a/components/QRCodeScanner.qml b/components/QRCodeScanner.qml index d9a6d933..669bd271 100644 --- a/components/QRCodeScanner.qml +++ b/components/QRCodeScanner.qml @@ -44,7 +44,7 @@ Rectangle { color: "black" state: "Stopped" - signal qrcode_decoded(string address, string payment_id, string amount, string tx_description, string recipient_name) + signal qrcode_decoded(string address, string payment_id, string amount, string tx_description, string recipient_name, var extra_parameters) states: [ State { @@ -83,7 +83,7 @@ Rectangle { id : finder objectName: "QrFinder" onDecoded : { - root.qrcode_decoded(address, payment_id, amount, tx_description, recipient_name) + root.qrcode_decoded(address, payment_id, amount, tx_description, recipient_name, extra_parameters) root.state = "Stopped" } onNotifyError : { @@ -126,7 +126,7 @@ Rectangle { MessageDialog { id: messageDialog - title: "Scanning QrCode" + title: qsTr("QrCode Scanned") + translationManager.emptyString onAccepted: { root.state = "Stopped" } diff --git a/src/QR-Code-scanner/QrCodeScanner.cpp b/src/QR-Code-scanner/QrCodeScanner.cpp index 1129e986..62c639f9 100644 --- a/src/QR-Code-scanner/QrCodeScanner.cpp +++ b/src/QR-Code-scanner/QrCodeScanner.cpp @@ -61,15 +61,23 @@ void QrCodeScanner::processCode(int type, const QString &data) emit notifyError(error); return; } + QVariantMap parsed_unknown_parameters; if(unknown_parameters.size() > 0) { qDebug() << "unknown parameters " << unknown_parameters; + foreach(const QString &item, unknown_parameters ) + { + QStringList parsed_item = item.split("="); + if(parsed_item.size() == 2) { + parsed_unknown_parameters.insert(parsed_item[0], parsed_item[1]); + } + } emit notifyError(error, true); } qDebug() << "Parsed URI : " << address << " " << payment_id << " " << amount << " " << tx_description << " " << recipient_name << " " << error; QString s_amount = WalletManager::instance()->displayAmount(amount); qDebug() << "Amount passed " << s_amount ; - emit decoded(address, payment_id, s_amount, tx_description, recipient_name); + emit decoded(address, payment_id, s_amount, tx_description, recipient_name, parsed_unknown_parameters); } void QrCodeScanner::processFrame(QVideoFrame frame) { @@ -102,3 +110,15 @@ void QrCodeScanner::timerEvent(QTimerEvent *event) } } +QrCodeScanner::~QrCodeScanner() +{ + m_thread->stop(); + m_thread->quit(); + if(!m_thread->wait(5000)) + { + m_thread->terminate(); + m_thread->wait(); + } + +} + diff --git a/src/QR-Code-scanner/QrCodeScanner.h b/src/QR-Code-scanner/QrCodeScanner.h index a6a747b3..a83cf2ac 100644 --- a/src/QR-Code-scanner/QrCodeScanner.h +++ b/src/QR-Code-scanner/QrCodeScanner.h @@ -44,7 +44,7 @@ class QrCodeScanner : public QObject public: QrCodeScanner(QObject *parent = Q_NULLPTR); - + ~QrCodeScanner(); void setSource(QCamera*); bool enabled() const; @@ -57,7 +57,7 @@ public Q_SLOTS: Q_SIGNALS: void enabledChanged(); - void decoded(const QString &address, const QString &payment_id, const QString &amount, const QString &tx_description, const QString &recipient_name); + void decoded(const QString &address, const QString &payment_id, const QString &amount, const QString &tx_description, const QString &recipient_name, const QVariantMap &extra_parameters); void decode(int type, const QString &data); void notifyError(const QString &error, bool warning = false); diff --git a/src/QR-Code-scanner/QrScanThread.cpp b/src/QR-Code-scanner/QrScanThread.cpp index b6e9b9ff..48ecb53a 100644 --- a/src/QR-Code-scanner/QrScanThread.cpp +++ b/src/QR-Code-scanner/QrScanThread.cpp @@ -110,6 +110,7 @@ void QrScanThread::processVideoFrame(const QVideoFrame &frame) void QrScanThread::stop() { m_running = false; + m_waitCondition.wakeOne(); } void QrScanThread::addFrame(const QVideoFrame &frame) @@ -124,9 +125,10 @@ void QrScanThread::run() QVideoFrame frame; while(m_running) { QMutexLocker locker(&m_mutex); - while(m_queue.isEmpty()) + while(m_queue.isEmpty() && m_running) m_waitCondition.wait(&m_mutex); - processVideoFrame(m_queue.takeFirst()); + if(!m_queue.isEmpty()) + processVideoFrame(m_queue.takeFirst()); } } diff --git a/src/QR-Code-scanner/QrScanThread.h b/src/QR-Code-scanner/QrScanThread.h index 03f17be3..296e1dc5 100644 --- a/src/QR-Code-scanner/QrScanThread.h +++ b/src/QR-Code-scanner/QrScanThread.h @@ -44,6 +44,7 @@ class QrScanThread : public QThread, public zbar::Image::Handler public: QrScanThread(QObject *parent = Q_NULLPTR); void addFrame(const QVideoFrame &frame); + virtual void stop(); Q_SIGNALS: void decoded(int type, const QString &data); @@ -51,7 +52,6 @@ Q_SIGNALS: protected: virtual void run(); - virtual void stop(); void processVideoFrame(const QVideoFrame &); void processQImage(const QImage &); void processZImage(zbar::Image &image);