Finally fix the grey security pic bug!

This commit is contained in:
Zach Fox 2018-04-10 16:00:53 -07:00
parent 01fec2edc7
commit b9d0360ea2
5 changed files with 79 additions and 78 deletions

View file

@ -13,8 +13,9 @@
#include "Ledger.h"
#include "Wallet.h"
#include "Application.h"
#include "ui/ImageProvider.h"
#include "ui/SecurityImageProvider.h"
#include "scripting/HMDScriptingInterface.h"
#include <ui/TabletScriptingInterface.h>
#include <PathUtils.h>
#include <OffscreenUi.h>
@ -607,11 +608,17 @@ QString Wallet::signWithKey(const QByteArray& text, const QString& key) {
}
void Wallet::updateImageProvider() {
// inform the image provider. Note it doesn't matter which one you inform, as the
// images are statics
auto engine = DependencyManager::get<OffscreenUi>()->getSurfaceContext()->engine();
auto imageProvider = reinterpret_cast<ImageProvider*>(engine->imageProvider(ImageProvider::PROVIDER_NAME));
imageProvider->setSecurityImage(_securityImage);
SecurityImageProvider* securityImageProvider;
// inform offscreenUI security image provider
QQmlEngine* engine = DependencyManager::get<OffscreenUi>()->getSurfaceContext()->engine();
securityImageProvider = reinterpret_cast<SecurityImageProvider*>(engine->imageProvider(SecurityImageProvider::PROVIDER_NAME));
securityImageProvider->setSecurityImage(_securityImage);
// inform tablet security image provider
QQmlEngine* tabletEngine = DependencyManager::get<TabletScriptingInterface>()->getTablet("com.highfidelity.interface.tablet.system")->getTabletSurface()->getSurfaceContext()->engine();
securityImageProvider = reinterpret_cast<SecurityImageProvider*>(tabletEngine->imageProvider(SecurityImageProvider::PROVIDER_NAME));
securityImageProvider->setSecurityImage(_securityImage);
}
void Wallet::chooseSecurityImage(const QString& filename) {
@ -651,6 +658,7 @@ bool Wallet::getSecurityImage() {
// if already decrypted, don't do it again
if (_securityImage) {
updateImageProvider();
emit securityImageResult(true);
return true;
}

View file

@ -1,59 +0,0 @@
//
// ImageProvider.cpp
// interface/src/ui
//
// Created by David Kelly on 8/23/2017.
// Copyright 2017 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "ImageProvider.h"
#include <QReadLocker>
#include <QWriteLocker>
const QString ImageProvider::PROVIDER_NAME = "security";
QReadWriteLock ImageProvider::_rwLock;
QPixmap* ImageProvider::_securityImage = nullptr;
ImageProvider::~ImageProvider() {
QWriteLocker lock(&_rwLock);
if (_securityImage) {
delete _securityImage;
_securityImage = nullptr;
}
}
void ImageProvider::setSecurityImage(const QPixmap* pixmap) {
// no need to delete old one, that is managed by the wallet
QWriteLocker lock(&_rwLock);
if (_securityImage) {
delete _securityImage;
}
if (pixmap) {
_securityImage = new QPixmap(*pixmap);
} else {
_securityImage = nullptr;
}
}
QPixmap ImageProvider::requestPixmap(const QString& id, QSize* size, const QSize& requestedSize) {
// adjust the internal pixmap to have the requested size
QReadLocker lock(&_rwLock);
if (id == "securityImage" && _securityImage) {
*size = _securityImage->size();
if (requestedSize.width() > 0 && requestedSize.height() > 0) {
return _securityImage->scaled(requestedSize.width(), requestedSize.height(), Qt::KeepAspectRatio);
} else {
return _securityImage->copy();
}
}
// otherwise just return a grey pixmap. This avoids annoying error messages in qml we would get
// when sending a 'null' pixmap (QPixmap())
QPixmap greyPixmap(200, 200);
greyPixmap.fill(QColor("darkGrey"));
return greyPixmap;
}

View file

@ -48,7 +48,7 @@
#include <gl/Context.h>
#include <shared/ReadWriteLockable.h>
#include "ImageProvider.h"
#include "SecurityImageProvider.h"
#include "types/FileTypeProfile.h"
#include "types/HFWebEngineProfile.h"
#include "types/SoundEffect.h"
@ -233,8 +233,8 @@ void OffscreenQmlSurface::initializeEngine(QQmlEngine* engine) {
qmlRegisterType<SoundEffect>("Hifi", 1, 0, "SoundEffect");
});
// register the pixmap image provider (used only for security image, for now)
engine->addImageProvider(ImageProvider::PROVIDER_NAME, new ImageProvider());
// Register the pixmap Security Image Provider
engine->addImageProvider(SecurityImageProvider::PROVIDER_NAME, new SecurityImageProvider());
engine->setNetworkAccessManagerFactory(new QmlNetworkAccessManagerFactory);
auto importList = engine->importPathList();
@ -335,6 +335,7 @@ void OffscreenQmlSurface::onRootCreated() {
tabletScriptingInterface->setQmlTabletRoot("com.highfidelity.interface.tablet.system", this);
QObject* tablet = tabletScriptingInterface->getTablet("com.highfidelity.interface.tablet.system");
getSurfaceContext()->engine()->setObjectOwnership(tablet, QQmlEngine::CppOwnership);
getSurfaceContext()->engine()->addImageProvider(SecurityImageProvider::PROVIDER_NAME, new SecurityImageProvider());
}
QMetaObject::invokeMethod(this, "forceQmlAudioOutputDeviceUpdate", Qt::QueuedConnection);
}

View file

@ -0,0 +1,52 @@
//
// SecurityImageProvider.cpp
// interface/src/ui
//
// Created by David Kelly on 8/23/2017.
// Copyright 2017 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "SecurityImageProvider.h"
#include <QReadLocker>
#include <QWriteLocker>
const QString SecurityImageProvider::PROVIDER_NAME = "security";
SecurityImageProvider::~SecurityImageProvider() {
}
void SecurityImageProvider::setSecurityImage(const QPixmap* pixmap) {
// no need to delete old one, that is managed by the wallet
QWriteLocker lock(&_rwLock);
if (pixmap) {
_securityImage = pixmap->copy();
} else {
QPixmap greyPixmap(200, 200);
greyPixmap.fill(QColor("darkGrey"));
_securityImage = greyPixmap.copy();
}
}
QPixmap SecurityImageProvider::requestPixmap(const QString& id, QSize* size, const QSize& requestedSize) {
// adjust the internal pixmap to have the requested size
QReadLocker lock(&_rwLock);
if (id == "securityImage") {
*size = _securityImage.size();
if (requestedSize.width() > 0 && requestedSize.height() > 0) {
return _securityImage.scaled(requestedSize.width(), requestedSize.height(), Qt::KeepAspectRatio);
} else {
return _securityImage.copy();
}
}
// otherwise just return a grey pixmap. This avoids annoying error messages in qml we would get
// when sending a 'null' pixmap (QPixmap())
QPixmap greyPixmap(200, 200);
greyPixmap.fill(QColor("darkGrey"));
return greyPixmap;
}

View file

@ -1,5 +1,5 @@
//
// ImageProvider.h
// SecurityImageProvider.h
//
// Created by David Kelly on 2017/08/23
// Copyright 2017 High Fidelity, Inc.
@ -9,26 +9,25 @@
//
#pragma once
#ifndef hifi_ImageProvider_h
#define hifi_ImageProvider_h
#ifndef hifi_SecurityImageProvider_h
#define hifi_SecurityImageProvider_h
#include <QQuickImageProvider>
#include <QReadWriteLock>
class ImageProvider: public QQuickImageProvider {
class SecurityImageProvider: public QQuickImageProvider {
public:
static const QString PROVIDER_NAME;
ImageProvider() : QQuickImageProvider(QQuickImageProvider::Pixmap) {}
virtual ~ImageProvider();
SecurityImageProvider() : QQuickImageProvider(QQuickImageProvider::Pixmap) {}
virtual ~SecurityImageProvider();
QPixmap requestPixmap(const QString& id, QSize* size, const QSize& requestedSize) override;
void setSecurityImage(const QPixmap* pixmap);
protected:
static QReadWriteLock _rwLock;
static QPixmap* _securityImage;
QReadWriteLock _rwLock;
QPixmap _securityImage;
};
#endif //hifi_ImageProvider_h
#endif //hifi_SecurityImageProvider_h