mirror of
https://github.com/wownero/wowlet.git
synced 2026-10-25 10:18:33 +01:00
build: fix -DWITH_SCANNER=Off
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
// SPDX-FileCopyrightText: 2020-2023 The Monero Project
|
||||
|
||||
#include "URDialog.h"
|
||||
#include "ui_URDialog.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QInputDialog>
|
||||
|
||||
#include "utils/Utils.h"
|
||||
#include "WalletManager.h"
|
||||
|
||||
URDialog::URDialog(QWidget *parent)
|
||||
: WindowModalDialog(parent)
|
||||
, ui(new Ui::URDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
connect(ui->btn_loadFile, &QPushButton::clicked, [this]{
|
||||
QString fn = QFileDialog::getOpenFileName(this, "Load file", QDir::homePath(), "All Files (*)");
|
||||
if (fn.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QFile file(fn);
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
return;
|
||||
}
|
||||
|
||||
QByteArray qdata = file.readAll();
|
||||
std::string data = qdata.toStdString();
|
||||
file.close();
|
||||
|
||||
ui->widgetUR->setData("any", data);
|
||||
});
|
||||
|
||||
connect(ui->btn_loadClipboard, &QPushButton::clicked, [this]{
|
||||
QString qdata = Utils::copyFromClipboard();
|
||||
if (qdata.length() < 10) {
|
||||
Utils::showError(this, "Not enough data on clipboard to encode as UR");
|
||||
return;
|
||||
}
|
||||
|
||||
std::string data = qdata.toStdString();
|
||||
|
||||
ui->widgetUR->setData("any", data);
|
||||
});
|
||||
|
||||
connect(ui->tabWidget, &QTabWidget::currentChanged, [this](int index){
|
||||
if (index == 1) {
|
||||
ui->widgetScanner->startCapture(true);
|
||||
}
|
||||
});
|
||||
|
||||
connect(ui->widgetScanner, &QrCodeScanWidget::finished, [this](bool success){
|
||||
if (!success) {
|
||||
Utils::showError(this, "Unable to scan UR");
|
||||
ui->widgetScanner->reset();
|
||||
return;
|
||||
}
|
||||
|
||||
if (ui->radio_clipboard->isChecked()) {
|
||||
Utils::copyToClipboard(QString::fromStdString(ui->widgetScanner->getURData()));
|
||||
Utils::showInfo(this, "Data copied to clipboard");
|
||||
}
|
||||
else if (ui->radio_file->isChecked()) {
|
||||
QString fn = QFileDialog::getSaveFileName(this, "Save to file", QDir::homePath(), "ur_data");
|
||||
if (fn.isEmpty()) {
|
||||
ui->widgetScanner->reset();
|
||||
return;
|
||||
}
|
||||
|
||||
QFile file{fn};
|
||||
if (!file.open(QIODevice::WriteOnly)) {
|
||||
Utils::showError(this, "Failed to save file", QString("Could not open file %1 for writing").arg(fn));
|
||||
ui->widgetScanner->reset();
|
||||
return;
|
||||
}
|
||||
|
||||
std::string data = ui->widgetScanner->getURData();
|
||||
file.write(data.data(), data.size());
|
||||
file.close();
|
||||
|
||||
Utils::showInfo(this, "Successfully saved data to file");
|
||||
}
|
||||
|
||||
ui->widgetScanner->reset();
|
||||
});
|
||||
|
||||
ui->radio_file->setChecked(true);
|
||||
ui->tabWidget->setCurrentIndex(0);
|
||||
|
||||
this->resize(600, 700);
|
||||
}
|
||||
|
||||
URDialog::~URDialog() = default;
|
||||
@@ -0,0 +1,28 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
// SPDX-FileCopyrightText: 2020-2023 The Monero Project
|
||||
|
||||
#ifndef FEATHER_URDIALOG_H
|
||||
#define FEATHER_URDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
#include "components.h"
|
||||
|
||||
namespace Ui {
|
||||
class URDialog;
|
||||
}
|
||||
|
||||
class URDialog : public WindowModalDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit URDialog(QWidget *parent);
|
||||
~URDialog() override;
|
||||
|
||||
private:
|
||||
QScopedPointer<Ui::URDialog> ui;
|
||||
};
|
||||
|
||||
|
||||
#endif //FEATHER_URDIALOG_H
|
||||
@@ -0,0 +1,157 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>URDialog</class>
|
||||
<widget class="QDialog" name="URDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>788</width>
|
||||
<height>703</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Transmit UR</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tabSend">
|
||||
<attribute name="title">
|
||||
<string>Send</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="URWidget" name="widgetUR" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="btn_loadFile">
|
||||
<property name="text">
|
||||
<string>Load file</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btn_loadClipboard">
|
||||
<property name="text">
|
||||
<string>Load from clipboard</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tabReceive">
|
||||
<attribute name="title">
|
||||
<string>Receive</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QrCodeScanWidget" name="widgetScanner" native="true"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="radio_clipboard">
|
||||
<property name="text">
|
||||
<string>Copy to clipboard</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="radio_file">
|
||||
<property name="text">
|
||||
<string>Save to file</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>QrCodeScanWidget</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>qrcode/scanner/QrCodeScanWidget.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>URWidget</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>qrcode/scanner/URWidget.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>URDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>URDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
@@ -0,0 +1,77 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
// SPDX-FileCopyrightText: 2020-2023 The Monero Project
|
||||
|
||||
#include "URWidget.h"
|
||||
#include "ui_URWidget.h"
|
||||
|
||||
#include "dialog/URSettingsDialog.h"
|
||||
#include "utils/config.h"
|
||||
|
||||
URWidget::URWidget(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, ui(new Ui::URWidget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
connect(&m_timer, &QTimer::timeout, this, &URWidget::nextQR);
|
||||
connect(ui->btn_options, &QPushButton::clicked, this, &URWidget::setOptions);
|
||||
}
|
||||
|
||||
void URWidget::setData(const QString &type, const std::string &data) {
|
||||
m_type = type;
|
||||
m_data = data;
|
||||
|
||||
m_timer.stop();
|
||||
allParts.clear();
|
||||
|
||||
if (m_data.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::string type_std = m_type.toStdString();
|
||||
|
||||
ur::ByteVector a = ur::string_to_bytes(m_data);
|
||||
ur::ByteVector cbor;
|
||||
ur::CborLite::encodeBytes(cbor, a);
|
||||
ur::UR h = ur::UR(type_std, cbor);
|
||||
|
||||
int bytesPerFragment = conf()->get(Config::URfragmentLength).toInt();
|
||||
|
||||
delete m_urencoder;
|
||||
m_urencoder = new ur::UREncoder(h, bytesPerFragment);
|
||||
|
||||
for (int i=0; i < m_urencoder->seq_len(); i++) {
|
||||
allParts.append(m_urencoder->next_part());
|
||||
}
|
||||
|
||||
m_timer.setInterval(conf()->get(Config::URmsPerFragment).toInt());
|
||||
m_timer.start();
|
||||
}
|
||||
|
||||
void URWidget::nextQR() {
|
||||
currentIndex = currentIndex % m_urencoder->seq_len();
|
||||
|
||||
std::string data;
|
||||
if (conf()->get(Config::URfountainCode).toBool()) {
|
||||
data = m_urencoder->next_part();
|
||||
} else {
|
||||
data = allParts[currentIndex];
|
||||
}
|
||||
|
||||
ui->label_seq->setText(QString("%1/%2").arg(QString::number(currentIndex % m_urencoder->seq_len() + 1), QString::number(m_urencoder->seq_len())));
|
||||
|
||||
m_code = new QrCode{QString::fromStdString(data), QrCode::Version::AUTO, QrCode::ErrorCorrectionLevel::MEDIUM};
|
||||
ui->qrWidget->setQrCode(m_code);
|
||||
|
||||
currentIndex += 1;
|
||||
}
|
||||
|
||||
void URWidget::setOptions() {
|
||||
URSettingsDialog dialog{this};
|
||||
dialog.exec();
|
||||
this->setData(m_type, m_data);
|
||||
}
|
||||
|
||||
URWidget::~URWidget() {
|
||||
delete m_urencoder;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
// SPDX-FileCopyrightText: 2020-2023 The Monero Project
|
||||
|
||||
#ifndef FEATHER_URWIDGET_H
|
||||
#define FEATHER_URWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QTimer>
|
||||
|
||||
#include "qrcode/QrCode.h"
|
||||
#include "widgets/QrCodeWidget.h"
|
||||
#include <bcur/bc-ur.hpp>
|
||||
|
||||
namespace Ui {
|
||||
class URWidget;
|
||||
}
|
||||
|
||||
class URWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit URWidget(QWidget *parent = nullptr);
|
||||
~URWidget();
|
||||
|
||||
void setData(const QString &type, const std::string &data);
|
||||
|
||||
private slots:
|
||||
void nextQR();
|
||||
void setOptions();
|
||||
|
||||
private:
|
||||
QScopedPointer<Ui::URWidget> ui;
|
||||
QTimer m_timer;
|
||||
ur::UREncoder *m_urencoder = nullptr;
|
||||
QrCode *m_code = nullptr;
|
||||
QList<std::string> allParts;
|
||||
qsizetype currentIndex = 0;
|
||||
|
||||
std::string m_data;
|
||||
QString m_type;
|
||||
};
|
||||
|
||||
#endif //FEATHER_URWIDGET_H
|
||||
@@ -0,0 +1,85 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>URWidget</class>
|
||||
<widget class="QWidget" name="URWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QrCodeWidget" name="qrWidget" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="contextMenuPolicy">
|
||||
<enum>Qt::DefaultContextMenu</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_seq">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btn_options">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../assets.qrc">
|
||||
<normaloff>:/assets/images/preferences.svg</normaloff>:/assets/images/preferences.svg</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>QrCodeWidget</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>widgets/QrCodeWidget.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="../assets.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user