Add parameter that enables automatically adding download model to world

This commit is contained in:
David Rowe 2016-10-30 13:58:17 +13:00
parent 97407e1cd5
commit 12747d26e0
6 changed files with 26 additions and 8 deletions

View file

@ -257,7 +257,7 @@ ScrollingWindow {
} }
Component.onCompleted: { Component.onCompleted: {
desktop.initWebviewProfileHandlers(webview.profile) desktop.initWebviewProfileHandlers(webview.profile, false);
} }
} }

View file

@ -88,10 +88,12 @@ OriginalDesktop.Desktop {
property string currentUrl: "" property string currentUrl: ""
property string adaptedPath: "" property string adaptedPath: ""
property string tempDir: "" property string tempDir: ""
property bool autoAdd: false
function initWebviewProfileHandlers(profile) { function initWebviewProfileHandlers(profile, auto) {
console.log("The webview url in desktop is: " + currentUrl); console.log("The webview url in desktop is: " + currentUrl);
if (webViewProfileSetup) return; if (webViewProfileSetup) return;
autoAdd = auto;
webViewProfileSetup = true; webViewProfileSetup = true;
profile.downloadRequested.connect(function(download){ profile.downloadRequested.connect(function(download){
@ -109,7 +111,7 @@ OriginalDesktop.Desktop {
profile.downloadFinished.connect(function(download){ profile.downloadFinished.connect(function(download){
if (download.state === WebEngineDownloadItem.DownloadCompleted) { if (download.state === WebEngineDownloadItem.DownloadCompleted) {
File.runUnzip(download.path, currentUrl); File.runUnzip(download.path, currentUrl, autoAdd);
} else { } else {
console.log("The download was corrupted, state: " + download.state); console.log("The download was corrupted, state: " + download.state);
} }

View file

@ -1769,7 +1769,7 @@ void Application::initializeUi() {
rootContext->setContextProperty("Entities", DependencyManager::get<EntityScriptingInterface>().data()); rootContext->setContextProperty("Entities", DependencyManager::get<EntityScriptingInterface>().data());
FileScriptingInterface* fileDownload = new FileScriptingInterface(engine); FileScriptingInterface* fileDownload = new FileScriptingInterface(engine);
rootContext->setContextProperty("File", fileDownload); rootContext->setContextProperty("File", fileDownload);
connect(fileDownload, &FileScriptingInterface::unzipSuccess, this, &Application::showAssetServerWidget); connect(fileDownload, &FileScriptingInterface::unzipSuccess, this, &Application::handleUnzip);
rootContext->setContextProperty("MyAvatar", getMyAvatar().get()); rootContext->setContextProperty("MyAvatar", getMyAvatar().get());
rootContext->setContextProperty("Messages", DependencyManager::get<MessagesClient>().data()); rootContext->setContextProperty("Messages", DependencyManager::get<MessagesClient>().data());
rootContext->setContextProperty("Recording", DependencyManager::get<RecordingScriptingInterface>().data()); rootContext->setContextProperty("Recording", DependencyManager::get<RecordingScriptingInterface>().data());
@ -5330,6 +5330,20 @@ void Application::showAssetServerWidget(QString filePath) {
startUpload(nullptr, nullptr); startUpload(nullptr, nullptr);
} }
void Application::addAssetToWorld(QString filePath) {
// Automatically upload and add asset to world rather than proceeding manually per showAssetServerWidget().
// TODO
}
void Application::handleUnzip(QString filePath, bool autoAdd) {
if (autoAdd && !filePath.isEmpty()) {
addAssetToWorld(filePath);
} else {
showAssetServerWidget(filePath);
}
}
void Application::packageModel() { void Application::packageModel() {
ModelPackager::package(); ModelPackager::package();
} }

View file

@ -306,6 +306,8 @@ public slots:
void toggleLogDialog(); void toggleLogDialog();
void toggleRunningScriptsWidget() const; void toggleRunningScriptsWidget() const;
Q_INVOKABLE void showAssetServerWidget(QString filePath = ""); Q_INVOKABLE void showAssetServerWidget(QString filePath = "");
void addAssetToWorld(QString filePath);
void handleUnzip(QString filePath = "", bool autoAdd = false);
void handleLocalServerConnection() const; void handleLocalServerConnection() const;
void readArgumentsFromLocalSocket() const; void readArgumentsFromLocalSocket() const;

View file

@ -31,7 +31,7 @@ FileScriptingInterface::FileScriptingInterface(QObject* parent) : QObject(parent
// nothing for now // nothing for now
} }
void FileScriptingInterface::runUnzip(QString path, QUrl url) { void FileScriptingInterface::runUnzip(QString path, QUrl url, bool autoAdd) {
qDebug() << "Url that was downloaded: " + url.toString(); qDebug() << "Url that was downloaded: " + url.toString();
qDebug() << "Path where download is saved: " + path; qDebug() << "Path where download is saved: " + path;
QString fileName = "/" + path.section("/", -1); QString fileName = "/" + path.section("/", -1);
@ -47,7 +47,7 @@ void FileScriptingInterface::runUnzip(QString path, QUrl url) {
if (file != "") { if (file != "") {
qDebug() << "Object file to upload: " + file; qDebug() << "Object file to upload: " + file;
QUrl url = QUrl::fromLocalFile(file); QUrl url = QUrl::fromLocalFile(file);
emit unzipSuccess(url.toString()); emit unzipSuccess(url.toString(), autoAdd);
} else { } else {
qDebug() << "unzip failed"; qDebug() << "unzip failed";
} }

View file

@ -28,11 +28,11 @@ public slots:
bool isZipped(QUrl url); bool isZipped(QUrl url);
bool isClaraLink(QUrl url); bool isClaraLink(QUrl url);
QString convertUrlToPath(QUrl url); QString convertUrlToPath(QUrl url);
void runUnzip(QString path, QUrl url); void runUnzip(QString path, QUrl url, bool autoAdd);
QString getTempDir(); QString getTempDir();
signals: signals:
void unzipSuccess(QString url); void unzipSuccess(QString url, bool autoAdd);
private: private:
bool isTempDir(QString tempDir); bool isTempDir(QString tempDir);