diff --git a/components/QRCodeScanner.qml b/components/QRCodeScanner.qml index 10c1592a..d9a6d933 100644 --- a/components/QRCodeScanner.qml +++ b/components/QRCodeScanner.qml @@ -131,4 +131,11 @@ Rectangle { root.state = "Stopped" } } + + Component.onCompleted: { + if( QtMultimedia.availableCameras.length == 0) { + console.log("No camera available. Disable qrScannerEnabled"); + appWindow.qrScannerEnabled = false; + } + } } diff --git a/main.cpp b/main.cpp index ab5ecae0..67470a8e 100644 --- a/main.cpp +++ b/main.cpp @@ -39,7 +39,6 @@ #include "WalletManager.h" #include "Wallet.h" #include "QRCodeImageProvider.h" -#include "QrCodeScanner.h" #include "PendingTransaction.h" #include "UnsignedTransaction.h" #include "TranslationManager.h" @@ -57,6 +56,10 @@ #include "daemon/DaemonManager.h" #endif +#ifdef WITH_SCANNER +#include "QrCodeScanner.h" +#endif + void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg) { // Send all message types to logger @@ -131,7 +134,9 @@ int main(int argc, char *argv[]) qRegisterMetaType(); qRegisterMetaType(); +#ifdef WITH_SCANNER qmlRegisterType("moneroComponents.QRCodeScanner", 1, 0, "QRCodeScanner"); +#endif QQmlApplicationEngine engine; @@ -197,19 +202,27 @@ int main(int argc, char *argv[]) engine.rootContext()->setContextProperty("defaultAccountName", accountName); engine.rootContext()->setContextProperty("applicationDirectory", QApplication::applicationDirPath()); + bool builtWithScanner = false; +#ifdef WITH_SCANNER + builtWithScanner = true; +#endif + engine.rootContext()->setContextProperty("builtWithScanner", builtWithScanner); + // Load main window (context properties needs to be defined obove this line) engine.load(QUrl(QStringLiteral("qrc:///main.qml"))); QObject *rootObject = engine.rootObjects().first(); - bool builtWithScanner = false; #ifdef WITH_SCANNER - builtWithScanner = true; QObject *qmlCamera = rootObject->findChild("qrCameraQML"); - QCamera *camera_ = qvariant_cast(qmlCamera->property("mediaObject")); - QObject *qmlFinder = rootObject->findChild("QrFinder"); - qobject_cast(qmlFinder)->setSource(camera_); + if( qmlCamera ){ + qDebug() << "QrCodeScanner : object found"; + QCamera *camera_ = qvariant_cast(qmlCamera->property("mediaObject")); + QObject *qmlFinder = rootObject->findChild("QrFinder"); + qobject_cast(qmlFinder)->setSource(camera_); + } else { + qDebug() << "QrCodeScanner : something went wrong !"; + } #endif - engine.rootContext()->setContextProperty("builtWithScanner", builtWithScanner); QObject::connect(eventFilter, SIGNAL(sequencePressed(QVariant,QVariant)), rootObject, SLOT(sequencePressed(QVariant,QVariant))); QObject::connect(eventFilter, SIGNAL(sequenceReleased(QVariant,QVariant)), rootObject, SLOT(sequenceReleased(QVariant,QVariant))); diff --git a/main.qml b/main.qml index 267461d1..d52d1027 100644 --- a/main.qml +++ b/main.qml @@ -32,7 +32,6 @@ import QtQuick.Controls 1.1 import QtQuick.Controls.Styles 1.1 import QtQuick.Dialogs 1.2 import Qt.labs.settings 1.0 -import QtMultimedia 5.4 import moneroComponents.Wallet 1.0 import moneroComponents.PendingTransaction 1.0 @@ -65,9 +64,10 @@ ApplicationWindow { property bool viewOnly: false property bool foundNewBlock: false property int timeToUnlock: 0 - property bool qrScannerEnabled: (typeof builtWithScanner != "undefined") && builtWithScanner && (QtMultimedia.availableCameras.length > 0) + property bool qrScannerEnabled: (typeof builtWithScanner != "undefined") && builtWithScanner property int blocksToSync: 1 property var isMobile: (appWindow.width > 700) ? false : true + property var cameraUi // true if wallet ever synchronized property bool walletInitialized : false @@ -809,6 +809,18 @@ ApplicationWindow { // Connect app exit to qml window exit handling mainApp.closing.connect(appWindow.close); + if( appWindow.qrScannerEnabled ){ + console.log("qrScannerEnabled : load component QRCodeScanner"); + var component = Qt.createComponent("components/QRCodeScanner.qml"); + if (component.status == Component.Ready) { + console.log("Camera component ready"); + cameraUi = component.createObject(appWindow); + } else { + console.log("component not READY !!!"); + appWindow.qrScannerEnabled = false; + } + } else console.log("qrScannerEnabled disabled"); + if(!walletsFound()) { rootItem.state = "wizard" } else { @@ -941,11 +953,6 @@ ApplicationWindow { messageText: qsTr("Please wait...") } - QRCodeScanner { - id: cameraUi - visible : false - } - Item { id: rootItem anchors.fill: parent diff --git a/monero-wallet-gui.pro b/monero-wallet-gui.pro index 2035ea6f..2ece7444 100644 --- a/monero-wallet-gui.pro +++ b/monero-wallet-gui.pro @@ -1,6 +1,6 @@ TEMPLATE = app -QT += qml quick widgets multimedia +QT += qml quick widgets WALLET_ROOT=$$PWD/monero @@ -12,7 +12,6 @@ QMAKE_DISTCLEAN += -r $$WALLET_ROOT INCLUDEPATH += $$WALLET_ROOT/include \ $$PWD/src/libwalletqt \ $$PWD/src/QR-Code-generator \ - $$PWD/src/QR-Code-scanner \ $$PWD/src \ $$WALLET_ROOT/src @@ -38,7 +37,6 @@ HEADERS += \ src/libwalletqt/AddressBook.h \ src/zxcvbn-c/zxcvbn.h \ src/libwalletqt/UnsignedTransaction.h \ - src/QR-Code-scanner/QrCodeScanner.h \ MainApp.h SOURCES += main.cpp \ @@ -62,7 +60,6 @@ SOURCES += main.cpp \ src/libwalletqt/AddressBook.cpp \ src/zxcvbn-c/zxcvbn.c \ src/libwalletqt/UnsignedTransaction.cpp \ - src/QR-Code-scanner/QrCodeScanner.cpp \ MainApp.cpp !ios { @@ -125,9 +122,15 @@ ios { CONFIG(WITH_SCANNER) { if( greaterThan(QT_MINOR_VERSION, 5) ) { message("using camera scanner") + QT += multimedia DEFINES += "WITH_SCANNER" - HEADERS += src/QR-Code-scanner/QrScanThread.h - SOURCES += src/QR-Code-scanner/QrScanThread.cpp + INCLUDEPATH += $$PWD/src/QR-Code-scanner + HEADERS += \ + src/QR-Code-scanner/QrScanThread.h \ + src/QR-Code-scanner/QrCodeScanner.h + SOURCES += \ + src/QR-Code-scanner/QrScanThread.cpp \ + src/QR-Code-scanner/QrCodeScanner.cpp android { INCLUDEPATH += $$PWD/../ZBar/include LIBS += -lzbarjni -liconv diff --git a/src/QR-Code-scanner/QrCodeScanner.cpp b/src/QR-Code-scanner/QrCodeScanner.cpp index 94102429..1129e986 100644 --- a/src/QR-Code-scanner/QrCodeScanner.cpp +++ b/src/QR-Code-scanner/QrCodeScanner.cpp @@ -37,14 +37,12 @@ QrCodeScanner::QrCodeScanner(QObject *parent) , m_processInterval(750) , m_enabled(true) { -#ifdef WITH_SCANNER m_probe = new QVideoProbe(this); m_thread = new QrScanThread(this); m_thread->start(); QObject::connect(m_thread, SIGNAL(decoded(int,QString)), this, SLOT(processCode(int,QString))); 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))); -#endif } void QrCodeScanner::setSource(QCamera *camera) { @@ -97,12 +95,10 @@ void QrCodeScanner::setEnabled(bool enabled) } emit enabledChanged(); } -#ifdef WITH_SCANNER void QrCodeScanner::timerEvent(QTimerEvent *event) { if( (event->timerId() == m_processTimerId) ){ m_thread->addFrame(m_curFrame); } } -#endif diff --git a/src/QR-Code-scanner/QrCodeScanner.h b/src/QR-Code-scanner/QrCodeScanner.h index 791800f0..a6a747b3 100644 --- a/src/QR-Code-scanner/QrCodeScanner.h +++ b/src/QR-Code-scanner/QrCodeScanner.h @@ -31,9 +31,7 @@ #include #include -#ifdef WITH_SCANNER #include "QrScanThread.h" -#endif class QVideoProbe; class QCamera; @@ -64,10 +62,8 @@ Q_SIGNALS: void notifyError(const QString &error, bool warning = false); protected: -#ifdef WITH_SCANNER void timerEvent(QTimerEvent *); QrScanThread *m_thread; -#endif int m_processTimerId; int m_processInterval; int m_enabled;