Make QtMultimedia dependency optional

This commit is contained in:
MoroccanMalinois 2017-03-27 17:39:47 +00:00
parent 12573652a0
commit fb3a6182fc
No known key found for this signature in database
GPG key ID: A63BDCF76B8B38BD
6 changed files with 50 additions and 28 deletions

View file

@ -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;
}
}
}

View file

@ -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<TransactionInfo::Direction>();
qRegisterMetaType<TransactionHistoryModel::TransactionInfoRole>();
#ifdef WITH_SCANNER
qmlRegisterType<QrCodeScanner>("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<QObject*>("qrCameraQML");
QCamera *camera_ = qvariant_cast<QCamera*>(qmlCamera->property("mediaObject"));
QObject *qmlFinder = rootObject->findChild<QObject*>("QrFinder");
qobject_cast<QrCodeScanner*>(qmlFinder)->setSource(camera_);
if( qmlCamera ){
qDebug() << "QrCodeScanner : object found";
QCamera *camera_ = qvariant_cast<QCamera*>(qmlCamera->property("mediaObject"));
QObject *qmlFinder = rootObject->findChild<QObject*>("QrFinder");
qobject_cast<QrCodeScanner*>(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)));

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -31,9 +31,7 @@
#include <QImage>
#include <QVideoFrame>
#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;