mirror of
https://github.com/wownero/wowlet.git
synced 2026-10-25 10:18:33 +01:00
airgapped signing with UR
This commit is contained in:
@@ -13,92 +13,21 @@
|
||||
|
||||
#include "Utils.h"
|
||||
|
||||
QrCodeScanDialog::QrCodeScanDialog(QWidget *parent)
|
||||
QrCodeScanDialog::QrCodeScanDialog(QWidget *parent, bool scan_ur)
|
||||
: QDialog(parent)
|
||||
, ui(new Ui::QrCodeScanDialog)
|
||||
, m_sink(new QVideoSink(this))
|
||||
{
|
||||
ui->setupUi(this);
|
||||
this->setWindowTitle("Scan QR code");
|
||||
|
||||
QPixmap pixmap = QPixmap(":/assets/images/warning.png");
|
||||
ui->icon_warning->setPixmap(pixmap.scaledToWidth(32, Qt::SmoothTransformation));
|
||||
|
||||
const QList<QCameraDevice> cameras = QMediaDevices::videoInputs();
|
||||
for (const auto &camera : cameras) {
|
||||
ui->combo_camera->addItem(camera.description());
|
||||
}
|
||||
|
||||
connect(ui->combo_camera, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &QrCodeScanDialog::onCameraSwitched);
|
||||
|
||||
connect(ui->viewfinder->videoSink(), &QVideoSink::videoFrameChanged, this, &QrCodeScanDialog::handleFrameCaptured);
|
||||
|
||||
this->onCameraSwitched(0);
|
||||
|
||||
m_thread = new QrScanThread(this);
|
||||
m_thread->start();
|
||||
|
||||
connect(m_thread, &QrScanThread::decoded, this, &QrCodeScanDialog::onDecoded);
|
||||
ui->widget_scanner->startCapture(scan_ur);
|
||||
}
|
||||
|
||||
void QrCodeScanDialog::handleFrameCaptured(const QVideoFrame &frame) {
|
||||
QImage img = this->videoFrameToImage(frame);
|
||||
m_thread->addImage(img);
|
||||
}
|
||||
|
||||
QImage QrCodeScanDialog::videoFrameToImage(const QVideoFrame &videoFrame)
|
||||
{
|
||||
auto handleType = videoFrame.handleType();
|
||||
|
||||
if (handleType == QVideoFrame::NoHandle) {
|
||||
|
||||
QImage image = videoFrame.toImage();
|
||||
|
||||
if (image.isNull()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
if (image.format() != QImage::Format_ARGB32) {
|
||||
image = image.convertToFormat(QImage::Format_ARGB32);
|
||||
}
|
||||
|
||||
return image.copy();
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
void QrCodeScanDialog::onCameraSwitched(int index) {
|
||||
const QList<QCameraDevice> cameras = QMediaDevices::videoInputs();
|
||||
|
||||
if (index >= cameras.size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_camera.reset(new QCamera(cameras.at(index)));
|
||||
m_captureSession.setCamera(m_camera.data());
|
||||
m_captureSession.setVideoOutput(ui->viewfinder);
|
||||
|
||||
connect(m_camera.data(), &QCamera::activeChanged, [this](bool active){
|
||||
ui->frame_unavailable->setVisible(!active);
|
||||
});
|
||||
|
||||
m_camera->start();
|
||||
}
|
||||
|
||||
void QrCodeScanDialog::onDecoded(const QString &data) {
|
||||
decodedString = data;
|
||||
this->accept();
|
||||
QString QrCodeScanDialog::decodedString() {
|
||||
return ui->widget_scanner->decodedString;
|
||||
}
|
||||
|
||||
QrCodeScanDialog::~QrCodeScanDialog()
|
||||
{
|
||||
m_thread->stop();
|
||||
m_thread->quit();
|
||||
if (!m_thread->wait(5000))
|
||||
{
|
||||
m_thread->terminate();
|
||||
m_thread->wait();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user