mirror of
https://github.com/monero-project/monero-gui.git
synced 2025-01-09 11:22:05 +02:00
QrCodeScanner: use parse_uri_to_object to parse scanned codes
This commit is contained in:
parent
c137a6ea36
commit
352da92229
@ -86,9 +86,14 @@ Rectangle {
|
|||||||
id : finder
|
id : finder
|
||||||
objectName: "QrFinder"
|
objectName: "QrFinder"
|
||||||
onDecoded : {
|
onDecoded : {
|
||||||
root.qrcode_decoded(address, payment_id, amount, tx_description, recipient_name, extra_parameters)
|
const parsed = walletManager.parse_uri_to_object(data);
|
||||||
root.state = "Stopped"
|
if (!parsed.error) {
|
||||||
}
|
root.qrcode_decoded(parsed.address, parsed.payment_id, parsed.amount, parsed.tx_description, parsed.recipient_name, parsed.extra_parameters);
|
||||||
|
root.state = "Stopped";
|
||||||
|
} else {
|
||||||
|
onNotifyError(parsed.error);
|
||||||
|
}
|
||||||
|
}
|
||||||
onNotifyError : {
|
onNotifyError : {
|
||||||
if( warning )
|
if( warning )
|
||||||
messageDialog.icon = StandardIcon.Critical
|
messageDialog.icon = StandardIcon.Critical
|
||||||
|
@ -40,7 +40,7 @@ QrCodeScanner::QrCodeScanner(QObject *parent)
|
|||||||
m_probe = new QVideoProbe(this);
|
m_probe = new QVideoProbe(this);
|
||||||
m_thread = new QrScanThread(this);
|
m_thread = new QrScanThread(this);
|
||||||
m_thread->start();
|
m_thread->start();
|
||||||
QObject::connect(m_thread, SIGNAL(decoded(int,QString)), this, SLOT(processCode(int,QString)));
|
QObject::connect(m_thread, SIGNAL(decoded(int, QString)), this, SIGNAL(decoded(int, QString)));
|
||||||
QObject::connect(m_thread, SIGNAL(notifyError(const QString &, bool)), this, SIGNAL(notifyError(const QString &, bool)));
|
QObject::connect(m_thread, SIGNAL(notifyError(const QString &, bool)), this, SIGNAL(notifyError(const QString &, bool)));
|
||||||
connect(m_probe, SIGNAL(videoFrameProbed(QVideoFrame)), this, SLOT(processFrame(QVideoFrame)));
|
connect(m_probe, SIGNAL(videoFrameProbed(QVideoFrame)), this, SLOT(processFrame(QVideoFrame)));
|
||||||
}
|
}
|
||||||
@ -48,37 +48,6 @@ void QrCodeScanner::setSource(QCamera *camera)
|
|||||||
{
|
{
|
||||||
m_probe->setSource(camera);
|
m_probe->setSource(camera);
|
||||||
}
|
}
|
||||||
void QrCodeScanner::processCode(int type, const QString &data)
|
|
||||||
{
|
|
||||||
if (! m_enabled) return;
|
|
||||||
qDebug() << "decoded - type: " << type << " data: " << data;
|
|
||||||
QString address, payment_id, tx_description, recipient_name, error;
|
|
||||||
QVector<QString> unknown_parameters;
|
|
||||||
uint64_t amount(0);
|
|
||||||
if( ! WalletManager::instance()->parse_uri(data, address, payment_id, amount, tx_description, recipient_name, unknown_parameters, error) )
|
|
||||||
{
|
|
||||||
qDebug() << "Failed to parse_uri : " << error;
|
|
||||||
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::displayAmount(amount);
|
|
||||||
qDebug() << "Amount passed " << s_amount ;
|
|
||||||
emit decoded(address, payment_id, s_amount, tx_description, recipient_name, parsed_unknown_parameters);
|
|
||||||
}
|
|
||||||
void QrCodeScanner::processFrame(QVideoFrame frame)
|
void QrCodeScanner::processFrame(QVideoFrame frame)
|
||||||
{
|
{
|
||||||
if(frame.isValid()){
|
if(frame.isValid()){
|
||||||
|
@ -51,13 +51,12 @@ public:
|
|||||||
void setEnabled(bool enabled);
|
void setEnabled(bool enabled);
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void processCode(int type, const QString &data);
|
|
||||||
void processFrame(QVideoFrame);
|
void processFrame(QVideoFrame);
|
||||||
|
|
||||||
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, const QVariantMap &extra_parameters);
|
void decoded(int type, const QString &data);
|
||||||
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);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user