From 615627e98138a82089385841e20d223447d12f2e Mon Sep 17 00:00:00 2001 From: elisa-lj11 Date: Fri, 22 Jul 2016 15:33:58 -0700 Subject: [PATCH] Working download and unpackage from Clara.io --- interface/resources/qml/Browser.qml | 3 +++ interface/resources/qml/controls-uit/WebView.qml | 10 ++++++++++ interface/resources/qml/hifi/Desktop.qml | 14 ++++++++------ .../script-engine/src/FileScriptingInterface.cpp | 9 +++++---- scripts/system/examples.js | 3 ++- 5 files changed, 28 insertions(+), 11 deletions(-) diff --git a/interface/resources/qml/Browser.qml b/interface/resources/qml/Browser.qml index f3bdab74f4..833816972a 100644 --- a/interface/resources/qml/Browser.qml +++ b/interface/resources/qml/Browser.qml @@ -225,6 +225,9 @@ ScrollingWindow { Component.onCompleted: { desktop.initWebviewProfileHandlers(webview.profile) } + + + //profile: desktop.browserProfile diff --git a/interface/resources/qml/controls-uit/WebView.qml b/interface/resources/qml/controls-uit/WebView.qml index 5fa0f5f584..50ba2d92c3 100644 --- a/interface/resources/qml/controls-uit/WebView.qml +++ b/interface/resources/qml/controls-uit/WebView.qml @@ -25,6 +25,8 @@ WebEngineView { }); } + + // FIXME hack to get the URL with the auth token included. Remove when we move to Qt 5.6 Timer { id: urlReplacementTimer @@ -68,9 +70,17 @@ WebEngineView { request.openIn(newWindow.webView); } + property var myScript: 'var element = $("a.download-file"); + element.removeClass("download-file"); + element.removeAttr("download _target");' + onLinkHovered: { desktop.currentUrl = hoveredUrl console.log("my url in WebView: " + desktop.currentUrl) + if (File.testUrl(desktop.currentUrl)) { + runJavaScript(myScript, function() {console.log("ran the JS"); }); + } + } // This breaks the webchannel used for passing messages. Fixed in Qt 5.6 diff --git a/interface/resources/qml/hifi/Desktop.qml b/interface/resources/qml/hifi/Desktop.qml index 29f982887c..db501be031 100644 --- a/interface/resources/qml/hifi/Desktop.qml +++ b/interface/resources/qml/hifi/Desktop.qml @@ -19,7 +19,9 @@ OriginalDesktop.Desktop { scrollGestureEnabled: false // we don't need/want these onEntered: ApplicationCompositor.reticleOverDesktop = true onExited: ApplicationCompositor.reticleOverDesktop = false - acceptedButtons: Qt.NoButton + acceptedButtons: Qt.NoButtonMouseArea + + } // The tool window, one instance @@ -82,11 +84,11 @@ OriginalDesktop.Desktop { profile.downloadRequested.connect(function(download){ console.log("Download start: " + download.state) - if (!File.testUrl(currentUrl)) { - console.log("This file type is not accepted. Look for a zip file") - download.cancel() - return - } + //if (!File.testUrl(currentUrl)) { + //console.log("This file type is not accepted. Look for a zip file") + //download.cancel() + //return + //} adaptedPath = File.convertUrlToPath(currentUrl) download.path = "C:/Users/elisa/Downloads/" + adaptedPath console.log("Path where it should download: " + download.path) diff --git a/libraries/script-engine/src/FileScriptingInterface.cpp b/libraries/script-engine/src/FileScriptingInterface.cpp index ad4ae8bdc2..3a9cca64c4 100644 --- a/libraries/script-engine/src/FileScriptingInterface.cpp +++ b/libraries/script-engine/src/FileScriptingInterface.cpp @@ -38,7 +38,8 @@ void FileScriptingInterface::runUnzip(QString path, QUrl url) { } bool FileScriptingInterface::testUrl(QUrl url) { - if (url.toString().contains(".zip")) return true; + if (url.toString().contains(".zip") && url.toString().contains("fbx")) return true; + qDebug() << "This model is not a .fbx packaged in a .zip. Please try with another model."; return false; } @@ -80,14 +81,14 @@ void FileScriptingInterface::unzipFile(QString path) { //QString zipFileName = QFile::decodeName(compressedFileContent); QString dirName = dir.path(); - QDir testPath("C:/Users/elisa/Downloads/banana.zip"); + //QDir testPath("C:/Users/elisa/Downloads/banana.zip"); qDebug() << "Zip directory is stored at: " + dirName; - QStringList list = JlCompress::extractDir(testPath.path(), "C:/Users/elisa/Downloads/test"); + QStringList list = JlCompress::extractDir(dirName, "C:/Users/elisa/Downloads/test"); qDebug() << list; //QFileInfoList files = dir.entryInfoList(); - QFileInfoList files = testPath.entryInfoList(); + QFileInfoList files = dir.entryInfoList(); foreach(QFileInfo file, files) { qDebug() << "My file: " + file.fileName(); recursiveFileScan(file, &dirName); diff --git a/scripts/system/examples.js b/scripts/system/examples.js index c445f218bc..6c01fd58af 100644 --- a/scripts/system/examples.js +++ b/scripts/system/examples.js @@ -12,7 +12,8 @@ var toolIconUrl = Script.resolvePath("assets/images/tools/"); //var EXAMPLES_URL = "https://metaverse.highfidelity.com/examples"; -var EXAMPLES_URL = "https://clara.io/view/c1c4d926-5648-4fd3-9673-6d9018ad4627"; +//var EXAMPLES_URL = "https://clara.io/view/c1c4d926-5648-4fd3-9673-6d9018ad4627"; +var EXAMPLES_URL = "https://clara.io/library"; //var EXAMPLES_URL = "http://s3.amazonaws.com/DreamingContent/test.html"; //var EXAMPLES_URL = "https://hifi-content.s3.amazonaws.com/elisalj/test.html"; //var EXAMPLES_URL = "https://hifi-content.s3.amazonaws.com/elisalj/test_download.html";