From b131338dd0cce16e3067fc72766323e10361c157 Mon Sep 17 00:00:00 2001 From: elisa-lj11 Date: Wed, 31 Aug 2016 14:13:26 -0700 Subject: [PATCH] Injected script to remove other file types from download options --- interface/resources/qml/Marketplaces.qml | 43 +++++++++++-------- .../src/FileScriptingInterface.cpp | 5 +++ .../src/FileScriptingInterface.h | 1 + 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/interface/resources/qml/Marketplaces.qml b/interface/resources/qml/Marketplaces.qml index 90d12d4633..91e65acb8e 100644 --- a/interface/resources/qml/Marketplaces.qml +++ b/interface/resources/qml/Marketplaces.qml @@ -25,27 +25,19 @@ Rectangle { HifiConstants { id: hifi } id: marketplace anchors.fill: parent - property var currentUrl: "https://metaverse.highfidelity.com/marketplace" + property var marketplacesUrl: "../../scripts/system/html/marketplaces.html" property int statusBarHeight: 50 property int statusMargin: 50 + property string standardMessage: "Check out other marketplaces" + property string claraMessage: "Choose a model from the list and click Download -> Autodesk FBX" Controls.BaseWebView { id: webview - url: currentUrl + url: marketplacesUrl anchors.top: marketplace.top width: parent.width height: parent.height - statusBarHeight focus: true - newWindowHook: function (component, newWindow) { - if (File.isZippedFbx(desktop.currentUrl)) { - runJavaScript(autoCancel); - zipTimer.handler = function() { - console.log("timer started", newWindow) - newWindow.destroy(); - } - zipTimer.start(); - } - } Timer { id: zipTimer @@ -63,13 +55,24 @@ Rectangle { element.removeClass("download-file"); element.removeAttr("download");' + property var checkFileType: "$('[data-extension]:not([data-extension=\"fbx\"])').parent().remove()" + onLinkHovered: { desktop.currentUrl = hoveredUrl; - // add an error message for non-fbx files - if (File.isZippedFbx(desktop.currentUrl)) { - runJavaScript(simpleDownload, function(){console.log("ran the JS");}); - } + if (File.isClaraLink(desktop.currentUrl)) { + //runJavaScript(checkFileType, function(){console.log("Remove filetypes JS injection");}); + if (File.isZippedFbx(desktop.currentUrl)) { + runJavaScript(simpleDownload, function(){console.log("Download JS injection");}); + } + } + } + onLoadingChanged: { + if (File.isClaraLink(webview.url)) { + statusLabel.text = claraMessage; + } else { + statusLabel.text = standardMessage; + } } } @@ -89,8 +92,10 @@ Rectangle { anchors.verticalCenter: parent.verticalCenter width: 150 text: "See all markets" - //onClicked: webview.url = "file:///E:/GitHub/hifi/scripts/system/html/marketplaces.html" - onClicked: webview.url = "../../scripts/system/html/marketplaces.html" + onClicked: { + webview.url = "../../scripts/system/html/marketplaces.html"; + statusLabel.text = standardMessage; + } } Controls.Label { @@ -99,7 +104,7 @@ Rectangle { anchors.left: parent.left anchors.leftMargin: statusMargin color: hifi.colors.white - text: "Check out other marketplaces" + text: standardMessage } HiFiGlyphs { diff --git a/libraries/script-engine/src/FileScriptingInterface.cpp b/libraries/script-engine/src/FileScriptingInterface.cpp index fa38e46d31..46bcd66ede 100644 --- a/libraries/script-engine/src/FileScriptingInterface.cpp +++ b/libraries/script-engine/src/FileScriptingInterface.cpp @@ -69,6 +69,11 @@ bool FileScriptingInterface::isTempDir(QString tempDir) { return false; } +bool FileScriptingInterface::isClaraLink(QUrl url) { + if (url.toString().contains("clara") && !url.toString().contains("clara.io/signup")) return true; + return false; +} + bool FileScriptingInterface::isZippedFbx(QUrl url) { if (url.toString().contains(".zip") && url.toString().contains("fbx")) return true; return false; diff --git a/libraries/script-engine/src/FileScriptingInterface.h b/libraries/script-engine/src/FileScriptingInterface.h index dd6ca3225b..976a9a0097 100644 --- a/libraries/script-engine/src/FileScriptingInterface.h +++ b/libraries/script-engine/src/FileScriptingInterface.h @@ -25,6 +25,7 @@ public: public slots: bool isZippedFbx(QUrl url); + bool isClaraLink(QUrl url); QString convertUrlToPath(QUrl url); void runUnzip(QString path, QUrl url); QString getTempDir();