From fb3a6182fc7db83ffac04752c37192f3dc1acd5f Mon Sep 17 00:00:00 2001 From: MoroccanMalinois Date: Mon, 27 Mar 2017 17:39:47 +0000 Subject: [PATCH 1/2] Make QtMultimedia dependency optional --- components/QRCodeScanner.qml | 7 +++++++ main.cpp | 27 ++++++++++++++++++++------- main.qml | 21 ++++++++++++++------- monero-wallet-gui.pro | 15 +++++++++------ src/QR-Code-scanner/QrCodeScanner.cpp | 4 ---- src/QR-Code-scanner/QrCodeScanner.h | 4 ---- 6 files changed, 50 insertions(+), 28 deletions(-) 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; From 716010a8698162404ee72c264a33af0a7c5f3be7 Mon Sep 17 00:00:00 2001 From: MoroccanMalinois Date: Mon, 27 Mar 2017 17:49:54 +0000 Subject: [PATCH 2/2] README: QtMultimedia dependency optional --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b98a4d37..6ef0d6f9 100644 --- a/README.md +++ b/README.md @@ -91,12 +91,16 @@ Packaging for your favorite distribution would be a welcome contribution! - For Ubuntu 16.04+ x64 - `sudo apt-get install qtbase5-dev qt5-default qtdeclarative5-dev qtmultimedia5-dev qml-module-qtquick-controls qml-module-qtquick-xmllistmodel qttools5-dev-tools qml-module-qtquick-dialogs qml-module-qt-labs-settings libqt5qml-graphicaleffects qml-module-qtmultimedia` + `sudo apt-get install qtbase5-dev qt5-default qtdeclarative5-dev qml-module-qtquick-controls qml-module-qtquick-xmllistmodel qttools5-dev-tools qml-module-qtquick-dialogs qml-module-qt-labs-settings libqt5qml-graphicaleffects` - For Linux Mint 18 "Sarah" - Cinnamon x64 `sudo apt install qml-module-qt-labs-settings qml-module-qtgraphicaleffects` + - Optional : To build the flag `WITH_SCANNER` + + `sudo apt install qtmultimedia5-dev qml-module-qtmultimedia libzbar-dev` + 6. Build the GUI. `./build.sh`