Handle Clara marketplace downloads

This commit is contained in:
David Rowe 2016-12-07 09:16:59 +13:00
parent b83d5c6275
commit d857f943f8
8 changed files with 111 additions and 13 deletions

View file

@ -99,6 +99,16 @@ Windows.ScrollingWindow {
}
userScripts: [ createGlobalEventBridge, raiseAndLowerKeyboard, userScript ]
function onWebEventReceived(event) {
if (event.slice(0, 17) === "CLARA.IO DOWNLOAD") {
ApplicationInterface.addAssetToWorldFromURL(event.slice(18));
}
}
Component.onCompleted: {
eventBridge.webEventReceived.connect(onWebEventReceived);
}
}
}
}

View file

@ -0,0 +1,27 @@
//
// Web3DOverlay.qml
//
// Created by David Rowe on 16 Dec 2016.
// Copyright 2016 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
//
import QtQuick 2.5
import QtQuick.Controls 1.4
import "controls" as Controls
Controls.WebView {
function onWebEventReceived(event) {
if (event.slice(0, 17) === "CLARA.IO DOWNLOAD") {
ApplicationInterface.addAssetToWorldFromURL(event.slice(18));
}
}
Component.onCompleted: {
eventBridge.webEventReceived.connect(onWebEventReceived);
}
}

View file

@ -42,6 +42,7 @@
#include <QtMultimedia/QMediaPlayer>
#include <QProcessEnvironment>
#include <QTemporaryDir>
#include <gl/QOpenGLContextWrapper.h>
@ -1803,9 +1804,9 @@ void Application::initializeUi() {
rootContext->setContextProperty("AudioStats", DependencyManager::get<AudioClient>()->getStats().data());
rootContext->setContextProperty("Controller", DependencyManager::get<controller::ScriptingInterface>().data());
rootContext->setContextProperty("Entities", DependencyManager::get<EntityScriptingInterface>().data());
FileScriptingInterface* fileDownload = new FileScriptingInterface(engine);
rootContext->setContextProperty("File", fileDownload);
connect(fileDownload, &FileScriptingInterface::unzipSuccess, this, &Application::handleUnzip);
_fileDownload = new FileScriptingInterface(engine);
rootContext->setContextProperty("File", _fileDownload);
connect(_fileDownload, &FileScriptingInterface::unzipSuccess, this, &Application::handleUnzip);
rootContext->setContextProperty("MyAvatar", getMyAvatar().get());
rootContext->setContextProperty("Messages", DependencyManager::get<MessagesClient>().data());
rootContext->setContextProperty("Recording", DependencyManager::get<RecordingScriptingInterface>().data());
@ -5457,15 +5458,52 @@ void Application::showAssetServerWidget(QString filePath) {
startUpload(nullptr, nullptr);
}
void Application::addAssetToWorldInitiate() {
qCDebug(interfaceapp) << "Start downloading asset file";
void Application::addAssetToWorldFromURL(QString url) {
qInfo(interfaceapp) << "Download asset and add to world from" << url;
QUrl urlURL = QUrl(url);
auto request = ResourceManager::createResourceRequest(nullptr, urlURL);
connect(request, &ResourceRequest::finished, this, &Application::addAssetToWorldFromURLRequestFinished);
request->send();
if (!_addAssetToWorldMessageBox) {
_addAssetToWorldMessageBox = DependencyManager::get<OffscreenUi>()->createMessageBox(OffscreenUi::ICON_INFORMATION,
"Downloading Asset", "Downloading asset file.", QMessageBox::Cancel, QMessageBox::NoButton);
_addAssetToWorldMessageBox = DependencyManager::get<OffscreenUi>()->createMessageBox(OffscreenUi::ICON_INFORMATION,
"Downloading Asset", "Downloading asset file " + url.section("filename=", 1, 1),
QMessageBox::Cancel, QMessageBox::NoButton);
}
connect(_addAssetToWorldMessageBox, SIGNAL(destroyed()), this, SLOT(onAssetToWorldMessageBoxClosed()));
}
void Application::addAssetToWorldFromURLRequestFinished() {
auto request = qobject_cast<ResourceRequest*>(sender());
auto url = request->getUrl().toString();
auto result = request->getResult();
if (result == ResourceRequest::Success) {
qInfo(interfaceapp) << "Downloaded asset from" << url;
QTemporaryDir temporaryDir;
temporaryDir.setAutoRemove(false);
QString temporaryDirPath = temporaryDir.path();
QString filename = url.section("filename=", 1, 1);
QString downloadPath = temporaryDirPath + "/" + filename;
qInfo() << "Download path:" << downloadPath;
QFile tempFile(downloadPath);
if (tempFile.open(QIODevice::WriteOnly)) {
tempFile.write(request->getData());
qApp->getFileDownloadInterface()->runUnzip(downloadPath, url, true);
} else {
QString errorInfo = "Couldn't open temporary file for writing";
qWarning(interfaceapp) << errorInfo;
addAssetToWorldError(errorInfo);
}
} else {
qWarning(interfaceapp) << "Error downloading" << url << ":" << request->getResultString();
addAssetToWorldError("Error downloading " + url.section("filename=", 1, 1) + " : " + request->getResultString());
}
connect(_addAssetToWorldMessageBox, SIGNAL(destroyed()), this, SLOT(onAssetToWorldMessageBoxClosed()));
request->deleteLater();
}
void Application::onAssetToWorldMessageBoxClosed() {

View file

@ -29,6 +29,7 @@
#include <AbstractViewStateInterface.h>
#include <EntityEditPacketSender.h>
#include <EntityTreeRenderer.h>
#include <FileScriptingInterface.h>
#include <input-plugins/KeyboardMouseDevice.h>
#include <input-plugins/TouchscreenDevice.h>
#include <OctreeQuery.h>
@ -310,7 +311,10 @@ public slots:
void toggleLogDialog();
void toggleRunningScriptsWidget() const;
Q_INVOKABLE void showAssetServerWidget(QString filePath = "");
Q_INVOKABLE void addAssetToWorldInitiate();
// FIXME: Move addAssetToWorld* methods to own class?
void addAssetToWorldFromURL(QString url);
void addAssetToWorldFromURLRequestFinished();
void addAssetToWorld(QString filePath);
void addAssetToWorldWithNewMapping(QString path, QString mapping, int copy);
void addAssetToWorldUpload(QString path, QString mapping);
@ -318,6 +322,8 @@ public slots:
void addAssetToWorldAddEntity(QString mapping);
void handleUnzip(QString filePath = "", bool autoAdd = false);
FileScriptingInterface* getFileDownloadInterface() { return _fileDownload; }
void handleLocalServerConnection() const;
void readArgumentsFromLocalSocket() const;
@ -627,6 +633,8 @@ private:
QQuickItem* _addAssetToWorldMessageBox{ nullptr };
void addAssetToWorldError(QString errorText);
FileScriptingInterface* _fileDownload;
};

View file

@ -16,6 +16,7 @@
#include <QQuickWindow>
#include <QtGui/QOpenGLContext>
#include <QtQuick/QQuickItem>
#include <QtQml/QQmlContext>
#include <DependencyManager.h>
#include <GeometryCache.h>
@ -112,11 +113,12 @@ void Web3DOverlay::render(RenderArgs* args) {
// and the current rendering load)
_webSurface->setMaxFps(10);
_webSurface->create(currentContext);
_webSurface->setBaseUrl(QUrl::fromLocalFile(PathUtils::resourcesPath() + "/qml/controls/"));
_webSurface->load("WebView.qml");
_webSurface->setBaseUrl(QUrl::fromLocalFile(PathUtils::resourcesPath() + "/qml/"));
_webSurface->load("Web3DOverlay.qml");
_webSurface->resume();
_webSurface->getRootItem()->setProperty("url", _url);
_webSurface->getRootItem()->setProperty("scriptURL", _scriptURL);
_webSurface->getRootContext()->setContextProperty("ApplicationInterface", qApp);
_webSurface->resize(QSize(_resolution.x, _resolution.y));
currentContext->makeCurrent(currentSurface);

View file

@ -26,3 +26,16 @@ void ResourceRequest::send() {
_state = InProgress;
doSend();
}
QString ResourceRequest::getResultString() const {
switch (_result) {
case Success: return "Success";
case Error: return "Error";
case Timeout: return "Timeout";
case ServerUnavailable: return "Server Unavailable";
case AccessDenied: return "Access Denied";
case InvalidURL: return "Ivalid URL";
case NotFound: return "Not Found";
default: return "Unspecified Error";
}
}

View file

@ -42,6 +42,7 @@ public:
QByteArray getData() { return _data; }
State getState() const { return _state; }
Result getResult() const { return _result; }
QString getResultString() const;
QUrl getUrl() const { return _url; }
bool loadedFromCache() const { return _loadedFromCache; }

View file

@ -64,9 +64,8 @@
downloadTimer = null;
var href = downloadButton[0].href;
EventBridge.emitWebEvent("CLARA.IO DOWNLOAD " + href);
console.log("Clara.io FBX file download initiated");
console.log("Clara.io FBX file download initiated for " + href);
$("a.btn.cancel").click();
setTimeout(function () { window.open(href); }, 500); // Let cancel click take effect.
};
} else {
clearInterval(downloadTimer);