Merge branch 'master' of https://github.com/highfidelity/hifi into commerce_zachsPunchlist2

This commit is contained in:
Zach Fox 2017-08-30 11:07:24 -07:00
commit e0878e7a3f
6 changed files with 44 additions and 20 deletions

View file

@ -183,7 +183,6 @@
#include "ui/UpdateDialog.h"
#include "ui/overlays/Overlays.h"
#include "ui/DomainConnectionModel.h"
#include "ui/ImageProvider.h"
#include "Util.h"
#include "InterfaceParentFinder.h"
#include "ui/OctreeStatsProvider.h"
@ -2246,8 +2245,6 @@ void Application::initializeUi() {
qApp->quit();
});
// register the pixmap image provider (used only for security image, for now)
engine->addImageProvider(ImageProvider::PROVIDER_NAME, new ImageProvider());
setupPreferences();

View file

@ -224,6 +224,12 @@ void initializeAESKeys(unsigned char* ivec, unsigned char* ckey, const QByteArra
memcpy(ckey, hash.data(), 32);
}
Wallet::~Wallet() {
if (_securityImage) {
delete _securityImage;
}
}
void Wallet::setPassphrase(const QString& passphrase) {
if (_passphrase) {
delete _passphrase;
@ -411,6 +417,13 @@ QString Wallet::signWithKey(const QByteArray& text, const QString& key) {
return QString();
}
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);
}
void Wallet::chooseSecurityImage(const QString& filename) {
@ -431,10 +444,7 @@ void Wallet::chooseSecurityImage(const QString& filename) {
if (encryptFile(path, imageFilePath())) {
qCDebug(commerce) << "emitting pixmap";
// inform the image provider
auto engine = DependencyManager::get<OffscreenUi>()->getSurfaceContext()->engine();
auto imageProvider = reinterpret_cast<ImageProvider*>(engine->imageProvider(ImageProvider::PROVIDER_NAME));
imageProvider->setSecurityImage(_securityImage);
updateImageProvider();
emit securityImageResult(true);
} else {
@ -460,10 +470,7 @@ void Wallet::getSecurityImage() {
_securityImage->loadFromData(data, dataLen, "jpg");
qCDebug(commerce) << "created pixmap from encrypted file";
// inform the image provider
auto engine = DependencyManager::get<OffscreenUi>()->getSurfaceContext()->engine();
auto imageProvider = reinterpret_cast<ImageProvider*>(engine->imageProvider(ImageProvider::PROVIDER_NAME));
imageProvider->setSecurityImage(_securityImage);
updateImageProvider();
delete[] data;
emit securityImageResult(true);

View file

@ -23,6 +23,8 @@ class Wallet : public QObject, public Dependency {
SINGLETON_DEPENDENCY
public:
~Wallet();
// These are currently blocking calls, although they might take a moment.
bool createIfNeeded();
bool generateKeyPair();
@ -48,6 +50,7 @@ private:
QByteArray _salt {"iamsalt!"};
QString* _passphrase { new QString("pwd") };
void updateImageProvider();
bool encryptFile(const QString& inputFilePath, const QString& outputFilePath);
bool decryptFile(const QString& inputFilePath, unsigned char** outputBufferPtr, int* outputBufferLen);
};

View file

@ -10,13 +10,24 @@
//
#include "ImageProvider.h"
#include <QDebug>
#include <QReadLocker>
#include <QWriteLocker>
const QString ImageProvider::PROVIDER_NAME = "security";
QReadWriteLock ImageProvider::_rwLock;
QPixmap* ImageProvider::_securityImage = nullptr;
void ImageProvider::setSecurityImage(QPixmap* pixmap) {
// no need to delete old one, that is managed by the wallet
QWriteLocker lock(&_rwLock);
_securityImage = pixmap;
}
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) {

View file

@ -13,6 +13,7 @@
#define hifi_ImageProvider_h
#include <QQuickImageProvider>
#include <QReadWriteLock>
class ImageProvider: public QQuickImageProvider {
public:
@ -22,10 +23,10 @@ public:
QPixmap requestPixmap(const QString& id, QSize* size, const QSize& requestedSize) override;
void setSecurityImage(QPixmap* pixmap) { _securityImage = pixmap; }
void setSecurityImage(QPixmap* pixmap);
protected:
QPixmap* _securityImage { nullptr };
static QReadWriteLock _rwLock;
static QPixmap* _securityImage;
};

View file

@ -6,6 +6,7 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "OffscreenQmlSurface.h"
#include "ImageProvider.h"
// Has to come before Qt GL includes
#include <gl/Config.h>
@ -305,6 +306,9 @@ static size_t globalEngineRefCount{ 0 };
#endif
void initializeQmlEngine(QQmlEngine* engine, QQuickWindow* window) {
// register the pixmap image provider (used only for security image, for now)
engine->addImageProvider(ImageProvider::PROVIDER_NAME, new ImageProvider());
engine->setNetworkAccessManagerFactory(new QmlNetworkAccessManagerFactory);
auto importList = engine->importPathList();
importList.insert(importList.begin(), PathUtils::resourcesPath());
@ -526,6 +530,7 @@ void OffscreenQmlSurface::create() {
// Create a QML engine.
auto qmlEngine = acquireEngine(_quickWindow);
_qmlContext = new QQmlContext(qmlEngine->rootContext());
_qmlContext->setContextProperty("offscreenWindow", QVariant::fromValue(getWindow()));