1
0

qt: new qrreader using QtMultimedia; drop CalinsQRReader(mac)

This commit ports the work of EchterAgo and cculianu from Electron-Cash,
to implement a new toolchain to scan qr codes.

Previously, on Linux and Win, we have been using zbar to access the camera
and read qrcodes; and on macOS we used CalinsQRReader (an objective-C
project by cculianu).

The new toolchain added here can use QtMultimedia to access the camera,
and then feed that image into zbar. When used this way, zbar needs
fewer dependencies and is easier to compile, in particular it can be
compiled for macOS.

The new toolchain works on all three platforms, with some caveats
(see code comments in related commits) -- so we also keep the end-to-end
zbar toolchain; but at least we can drop CalinsQRReader.

The related changes in Electron-Cash are spread over 50+ commits (several PRs and direct
pushes to master), but see in particular:
https://github.com/Electron-Cash/Electron-Cash/pull/1376

some other interesting links:
b2b737001c
163224cf1f
3b31e0fcb1
eda015908e
https://github.com/Electron-Cash/Electron-Cash/pull/1545
052aa06c23
This commit is contained in:
SomberNight
2021-06-25 15:48:22 +02:00
parent 129d5ba417
commit c1dbcab9bb
24 changed files with 1630 additions and 130 deletions

View File

@@ -39,7 +39,7 @@ except Exception:
from PyQt5.QtGui import QGuiApplication
from PyQt5.QtWidgets import (QApplication, QSystemTrayIcon, QWidget, QMenu,
QMessageBox)
from PyQt5.QtCore import QObject, pyqtSignal, QTimer
from PyQt5.QtCore import QObject, pyqtSignal, QTimer, Qt
import PyQt5.QtCore as QtCore
from electrum.i18n import _, set_language
@@ -52,7 +52,7 @@ from electrum.wallet_db import WalletDB
from electrum.logging import Logger
from .installwizard import InstallWizard, WalletAlreadyOpenInMemory
from .util import get_default_language, read_QIcon, ColorScheme, custom_message_box
from .util import get_default_language, read_QIcon, ColorScheme, custom_message_box, MessageBoxMixin
from .main_window import ElectrumWindow
from .network_dialog import NetworkDialog
from .stylesheet_patcher import patch_qt_stylesheet
@@ -275,6 +275,28 @@ class ElectrumGui(Logger):
network_updated_signal_obj=self.network_updated_signal_obj)
self.network_dialog.show()
@staticmethod
def warn_if_cant_import_qrreader(parent, *, show_warning=True) -> bool:
"""Checks it QR reading from camera is possible. It can fail on a
system lacking QtMultimedia. This can be removed in the future when
we are unlikely to encounter Qt5 installations that are missing
QtMultimedia
"""
try:
from .qrreader import QrReaderCameraDialog
except ImportError as e:
if show_warning:
icon = QMessageBox.Warning
title = _("QR Reader Error")
message = _("QR reader failed to load. This may happen if "
"you are using an older version of PyQt5.") + "\n\n" + str(e)
if isinstance(parent, MessageBoxMixin):
parent.msg_box(title=title, text=message, icon=icon, parent=None)
else:
custom_message_box(title=title, text=message, icon=icon, parent=parent)
return True
return False
def _create_window_for_wallet(self, wallet):
w = ElectrumWindow(self, wallet)
self.windows.append(w)