QrCodeScanner: parse extra parameters

This commit is contained in:
Jaquee
2017-08-06 16:27:55 +02:00
parent 6f95f8a754
commit 77335b300a
5 changed files with 31 additions and 9 deletions

View File

@@ -44,7 +44,7 @@ Rectangle {
color: "black" color: "black"
state: "Stopped" 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: [ states: [
State { State {
@@ -83,7 +83,7 @@ Rectangle {
id : finder id : finder
objectName: "QrFinder" objectName: "QrFinder"
onDecoded : { 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" root.state = "Stopped"
} }
onNotifyError : { onNotifyError : {
@@ -126,7 +126,7 @@ Rectangle {
MessageDialog { MessageDialog {
id: messageDialog id: messageDialog
title: "Scanning QrCode" title: qsTr("QrCode Scanned") + translationManager.emptyString
onAccepted: { onAccepted: {
root.state = "Stopped" root.state = "Stopped"
} }

View File

@@ -61,15 +61,23 @@ void QrCodeScanner::processCode(int type, const QString &data)
emit notifyError(error); emit notifyError(error);
return; return;
} }
QVariantMap parsed_unknown_parameters;
if(unknown_parameters.size() > 0) if(unknown_parameters.size() > 0)
{ {
qDebug() << "unknown parameters " << unknown_parameters; 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); emit notifyError(error, true);
} }
qDebug() << "Parsed URI : " << address << " " << payment_id << " " << amount << " " << tx_description << " " << recipient_name << " " << error; qDebug() << "Parsed URI : " << address << " " << payment_id << " " << amount << " " << tx_description << " " << recipient_name << " " << error;
QString s_amount = WalletManager::instance()->displayAmount(amount); QString s_amount = WalletManager::instance()->displayAmount(amount);
qDebug() << "Amount passed " << s_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) 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();
}
}

View File

@@ -44,7 +44,7 @@ class QrCodeScanner : public QObject
public: public:
QrCodeScanner(QObject *parent = Q_NULLPTR); QrCodeScanner(QObject *parent = Q_NULLPTR);
~QrCodeScanner();
void setSource(QCamera*); void setSource(QCamera*);
bool enabled() const; bool enabled() const;
@@ -57,7 +57,7 @@ public Q_SLOTS:
Q_SIGNALS: Q_SIGNALS:
void enabledChanged(); 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 decode(int type, const QString &data);
void notifyError(const QString &error, bool warning = false); void notifyError(const QString &error, bool warning = false);

View File

@@ -110,6 +110,7 @@ void QrScanThread::processVideoFrame(const QVideoFrame &frame)
void QrScanThread::stop() void QrScanThread::stop()
{ {
m_running = false; m_running = false;
m_waitCondition.wakeOne();
} }
void QrScanThread::addFrame(const QVideoFrame &frame) void QrScanThread::addFrame(const QVideoFrame &frame)
@@ -124,9 +125,10 @@ void QrScanThread::run()
QVideoFrame frame; QVideoFrame frame;
while(m_running) { while(m_running) {
QMutexLocker locker(&m_mutex); QMutexLocker locker(&m_mutex);
while(m_queue.isEmpty()) while(m_queue.isEmpty() && m_running)
m_waitCondition.wait(&m_mutex); m_waitCondition.wait(&m_mutex);
processVideoFrame(m_queue.takeFirst()); if(!m_queue.isEmpty())
processVideoFrame(m_queue.takeFirst());
} }
} }

View File

@@ -44,6 +44,7 @@ class QrScanThread : public QThread, public zbar::Image::Handler
public: public:
QrScanThread(QObject *parent = Q_NULLPTR); QrScanThread(QObject *parent = Q_NULLPTR);
void addFrame(const QVideoFrame &frame); void addFrame(const QVideoFrame &frame);
virtual void stop();
Q_SIGNALS: Q_SIGNALS:
void decoded(int type, const QString &data); void decoded(int type, const QString &data);
@@ -51,7 +52,6 @@ Q_SIGNALS:
protected: protected:
virtual void run(); virtual void run();
virtual void stop();
void processVideoFrame(const QVideoFrame &); void processVideoFrame(const QVideoFrame &);
void processQImage(const QImage &); void processQImage(const QImage &);
void processZImage(zbar::Image &image); void processZImage(zbar::Image &image);