From 12747d26e082c6314f76047a25fd9fa7717e0e15 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Sun, 30 Oct 2016 13:58:17 +1300 Subject: [PATCH] Add parameter that enables automatically adding download model to world --- interface/resources/qml/Browser.qml | 2 +- interface/resources/qml/hifi/Desktop.qml | 6 ++++-- interface/src/Application.cpp | 16 +++++++++++++++- interface/src/Application.h | 2 ++ .../script-engine/src/FileScriptingInterface.cpp | 4 ++-- .../script-engine/src/FileScriptingInterface.h | 4 ++-- 6 files changed, 26 insertions(+), 8 deletions(-) diff --git a/interface/resources/qml/Browser.qml b/interface/resources/qml/Browser.qml index 65d0777d19..2097dc7148 100644 --- a/interface/resources/qml/Browser.qml +++ b/interface/resources/qml/Browser.qml @@ -257,7 +257,7 @@ ScrollingWindow { } Component.onCompleted: { - desktop.initWebviewProfileHandlers(webview.profile) + desktop.initWebviewProfileHandlers(webview.profile, false); } } diff --git a/interface/resources/qml/hifi/Desktop.qml b/interface/resources/qml/hifi/Desktop.qml index 7f1fbcb174..a1848f51cf 100644 --- a/interface/resources/qml/hifi/Desktop.qml +++ b/interface/resources/qml/hifi/Desktop.qml @@ -88,10 +88,12 @@ OriginalDesktop.Desktop { property string currentUrl: "" property string adaptedPath: "" property string tempDir: "" + property bool autoAdd: false - function initWebviewProfileHandlers(profile) { + function initWebviewProfileHandlers(profile, auto) { console.log("The webview url in desktop is: " + currentUrl); if (webViewProfileSetup) return; + autoAdd = auto; webViewProfileSetup = true; profile.downloadRequested.connect(function(download){ @@ -109,7 +111,7 @@ OriginalDesktop.Desktop { profile.downloadFinished.connect(function(download){ if (download.state === WebEngineDownloadItem.DownloadCompleted) { - File.runUnzip(download.path, currentUrl); + File.runUnzip(download.path, currentUrl, autoAdd); } else { console.log("The download was corrupted, state: " + download.state); } diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 425fccf8fb..9158a9085e 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1769,7 +1769,7 @@ void Application::initializeUi() { rootContext->setContextProperty("Entities", DependencyManager::get().data()); FileScriptingInterface* fileDownload = new FileScriptingInterface(engine); 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("Messages", DependencyManager::get().data()); rootContext->setContextProperty("Recording", DependencyManager::get().data()); @@ -5330,6 +5330,20 @@ void Application::showAssetServerWidget(QString filePath) { 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() { ModelPackager::package(); } diff --git a/interface/src/Application.h b/interface/src/Application.h index 23cb58c19b..bd5f111588 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -306,6 +306,8 @@ public slots: void toggleLogDialog(); void toggleRunningScriptsWidget() const; Q_INVOKABLE void showAssetServerWidget(QString filePath = ""); + void addAssetToWorld(QString filePath); + void handleUnzip(QString filePath = "", bool autoAdd = false); void handleLocalServerConnection() const; void readArgumentsFromLocalSocket() const; diff --git a/libraries/script-engine/src/FileScriptingInterface.cpp b/libraries/script-engine/src/FileScriptingInterface.cpp index ad6a3cdf6f..c6a16e9d4c 100644 --- a/libraries/script-engine/src/FileScriptingInterface.cpp +++ b/libraries/script-engine/src/FileScriptingInterface.cpp @@ -31,7 +31,7 @@ FileScriptingInterface::FileScriptingInterface(QObject* parent) : QObject(parent // 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() << "Path where download is saved: " + path; QString fileName = "/" + path.section("/", -1); @@ -47,7 +47,7 @@ void FileScriptingInterface::runUnzip(QString path, QUrl url) { if (file != "") { qDebug() << "Object file to upload: " + file; QUrl url = QUrl::fromLocalFile(file); - emit unzipSuccess(url.toString()); + emit unzipSuccess(url.toString(), autoAdd); } else { qDebug() << "unzip failed"; } diff --git a/libraries/script-engine/src/FileScriptingInterface.h b/libraries/script-engine/src/FileScriptingInterface.h index d9a100b293..900aec2b0b 100644 --- a/libraries/script-engine/src/FileScriptingInterface.h +++ b/libraries/script-engine/src/FileScriptingInterface.h @@ -28,11 +28,11 @@ public slots: bool isZipped(QUrl url); bool isClaraLink(QUrl url); QString convertUrlToPath(QUrl url); - void runUnzip(QString path, QUrl url); + void runUnzip(QString path, QUrl url, bool autoAdd); QString getTempDir(); signals: - void unzipSuccess(QString url); + void unzipSuccess(QString url, bool autoAdd); private: bool isTempDir(QString tempDir);