mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-07-30 02:49:52 +02:00
Made code more QA; extra browser and download widget close upon download
This commit is contained in:
parent
a94a304700
commit
b1b2ea48b2
13 changed files with 144 additions and 196 deletions
|
@ -320,7 +320,7 @@ ScrollingWindow {
|
||||||
id: timer
|
id: timer
|
||||||
}
|
}
|
||||||
function uploadClicked(fileUrl) {
|
function uploadClicked(fileUrl) {
|
||||||
console.log("Upload clicked url: " + fileUrl);
|
console.log("Upload clicked url: " + fileUrl);
|
||||||
if (uploadOpen) {
|
if (uploadOpen) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,7 +140,6 @@ ScrollingWindow {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
<<<<<<< ab02d16eb7656ea0a37785a398716fad62dff045
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id:permissionsContainer
|
id:permissionsContainer
|
||||||
visible:false
|
visible:false
|
||||||
|
@ -197,8 +196,6 @@ ScrollingWindow {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
=======
|
|
||||||
>>>>>>> Zip download works
|
|
||||||
|
|
||||||
WebEngineView {
|
WebEngineView {
|
||||||
id: webview
|
id: webview
|
||||||
|
@ -221,15 +218,11 @@ ScrollingWindow {
|
||||||
onIconChanged: {
|
onIconChanged: {
|
||||||
console.log("New icon: " + icon)
|
console.log("New icon: " + icon)
|
||||||
}
|
}
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
desktop.initWebviewProfileHandlers(webview.profile)
|
desktop.initWebviewProfileHandlers(webview.profile)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//profile: desktop.browserProfile
|
//profile: desktop.browserProfile
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ WebEngineView {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// FIXME hack to get the URL with the auth token included. Remove when we move to Qt 5.6
|
// FIXME hack to get the URL with the auth token included. Remove when we move to Qt 5.6
|
||||||
Timer {
|
Timer {
|
||||||
|
@ -51,7 +51,7 @@ WebEngineView {
|
||||||
|
|
||||||
onLoadingChanged: {
|
onLoadingChanged: {
|
||||||
// Required to support clicking on "hifi://" links
|
// Required to support clicking on "hifi://" links
|
||||||
console.log("loading change requested url");
|
console.log("loading change requested url");
|
||||||
if (WebEngineView.LoadStartedStatus == loadRequest.status) {
|
if (WebEngineView.LoadStartedStatus == loadRequest.status) {
|
||||||
var url = loadRequest.url.toString();
|
var url = loadRequest.url.toString();
|
||||||
if (urlHandler.canHandleUrl(url)) {
|
if (urlHandler.canHandleUrl(url)) {
|
||||||
|
@ -62,26 +62,44 @@ WebEngineView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onNewViewRequested: {
|
Timer {
|
||||||
console.log("new view requested url");
|
id: zipTimer
|
||||||
//console.log("new view requested url" + request.url.toString());
|
running: false
|
||||||
var component = Qt.createComponent("../Browser.qml");
|
repeat: false
|
||||||
var newWindow = component.createObject(desktop);
|
interval: 1000
|
||||||
request.openIn(newWindow.webView);
|
property var handler;
|
||||||
|
onTriggered: handler();
|
||||||
}
|
}
|
||||||
|
|
||||||
property var myScript: 'var element = $("a.download-file");
|
property var autoCancel: 'var element = $("a.btn.cancel");
|
||||||
element.removeClass("download-file");
|
element.click();'
|
||||||
element.removeAttr("download _target");'
|
|
||||||
|
|
||||||
onLinkHovered: {
|
onNewViewRequested: {
|
||||||
desktop.currentUrl = hoveredUrl
|
console.log("new view requested url");
|
||||||
console.log("my url in WebView: " + desktop.currentUrl)
|
var component = Qt.createComponent("../Browser.qml");
|
||||||
if (File.testUrl(desktop.currentUrl)) {
|
var newWindow = component.createObject(desktop);
|
||||||
runJavaScript(myScript, function() {console.log("ran the JS"); });
|
request.openIn(newWindow.webView);
|
||||||
}
|
if (File.testUrl(desktop.currentUrl)) {
|
||||||
|
zipTimer.handler = function() {
|
||||||
|
newWindow.destroy();
|
||||||
|
runJavaScript(autoCancel);
|
||||||
|
}
|
||||||
|
zipTimer.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
property var simpleDownload: 'var element = $("a.download-file");
|
||||||
|
element.removeClass("download-file");
|
||||||
|
element.removeAttr("download");'
|
||||||
|
|
||||||
|
onLinkHovered: {
|
||||||
|
desktop.currentUrl = hoveredUrl
|
||||||
|
console.log("my url in WebView: " + desktop.currentUrl)
|
||||||
|
if (File.testUrl(desktop.currentUrl)) {
|
||||||
|
runJavaScript(simpleDownload, function(){console.log("ran the JS");});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// This breaks the webchannel used for passing messages. Fixed in Qt 5.6
|
// This breaks the webchannel used for passing messages. Fixed in Qt 5.6
|
||||||
// See https://bugreports.qt.io/browse/QTBUG-49521
|
// See https://bugreports.qt.io/browse/QTBUG-49521
|
||||||
|
|
|
@ -19,7 +19,7 @@ OriginalDesktop.Desktop {
|
||||||
scrollGestureEnabled: false // we don't need/want these
|
scrollGestureEnabled: false // we don't need/want these
|
||||||
onEntered: ApplicationCompositor.reticleOverDesktop = true
|
onEntered: ApplicationCompositor.reticleOverDesktop = true
|
||||||
onExited: ApplicationCompositor.reticleOverDesktop = false
|
onExited: ApplicationCompositor.reticleOverDesktop = false
|
||||||
acceptedButtons: Qt.NoButtonMouseArea
|
acceptedButtons: Qt.NoButton
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -73,44 +73,39 @@ OriginalDesktop.Desktop {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Accept a download through the webview
|
// Accept a download through the webview
|
||||||
property bool webViewProfileSetup: false
|
property bool webViewProfileSetup: false
|
||||||
property string currentUrl: ""
|
property string currentUrl: ""
|
||||||
property string adaptedPath: ""
|
property string adaptedPath: ""
|
||||||
function initWebviewProfileHandlers(profile) {
|
|
||||||
console.log("the webview url in desktop is: " + currentUrl)
|
|
||||||
if (webViewProfileSetup) return;
|
|
||||||
webViewProfileSetup = true;
|
|
||||||
|
|
||||||
profile.downloadRequested.connect(function(download){
|
function initWebviewProfileHandlers(profile) {
|
||||||
console.log("Download start: " + download.state)
|
console.log("the webview url in desktop is: " + currentUrl);
|
||||||
//if (!File.testUrl(currentUrl)) {
|
if (webViewProfileSetup) return;
|
||||||
//console.log("This file type is not accepted. Look for a zip file")
|
webViewProfileSetup = true;
|
||||||
//download.cancel()
|
|
||||||
//return
|
|
||||||
//}
|
|
||||||
adaptedPath = File.convertUrlToPath(currentUrl)
|
|
||||||
download.path = "C:/Users/elisa/Downloads/" + adaptedPath
|
|
||||||
console.log("Path where it should download: " + download.path)
|
|
||||||
download.accept()
|
|
||||||
console.log("Download accept: " + download.state)
|
|
||||||
if (download.state === WebEngineDownloadItem.DownloadInterrupted) {
|
|
||||||
console.log("Download? " + download.state)
|
|
||||||
console.log("download failed to complete")
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
profile.downloadFinished.connect(function(download){
|
profile.downloadRequested.connect(function(download){
|
||||||
if (download.state === WebEngineDownloadItem.DownloadCompleted) {
|
console.log("Download start: " + download.state);
|
||||||
console.log("Download Finished: " + download.state)
|
adaptedPath = File.convertUrlToPath(currentUrl);
|
||||||
console.log("File object is: " + File)
|
download.path = "C:/Users/elisa/Downloads/" + adaptedPath;
|
||||||
File.runUnzip(download.path, currentUrl)
|
console.log("Path where it should download: " + download.path);
|
||||||
//download.cancel()
|
download.accept();
|
||||||
} else {
|
console.log("Download accept: " + download.state);
|
||||||
console.log("The download was corrupted, state: " + download.state)
|
if (download.state === WebEngineDownloadItem.DownloadInterrupted) {
|
||||||
}
|
console.log("Download? " + download.state);
|
||||||
})
|
console.log("download failed to complete");
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
profile.downloadFinished.connect(function(download){
|
||||||
|
if (download.state === WebEngineDownloadItem.DownloadCompleted) {
|
||||||
|
console.log("Download Finished: " + download.state);
|
||||||
|
console.log("File object is: " + File);
|
||||||
|
File.runUnzip(download.path, currentUrl);
|
||||||
|
} else {
|
||||||
|
console.log("The download was corrupted, state: " + download.state);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// Create or fetch a toolbar with the given name
|
// Create or fetch a toolbar with the given name
|
||||||
function getToolbar(name) {
|
function getToolbar(name) {
|
||||||
|
|
|
@ -355,7 +355,6 @@ public:
|
||||||
|
|
||||||
if (message->message == WM_COPYDATA) {
|
if (message->message == WM_COPYDATA) {
|
||||||
COPYDATASTRUCT* pcds = (COPYDATASTRUCT*)(message->lParam);
|
COPYDATASTRUCT* pcds = (COPYDATASTRUCT*)(message->lParam);
|
||||||
qDebug() << "os windows url for some reason";
|
|
||||||
QUrl url = QUrl((const char*)(pcds->lpData));
|
QUrl url = QUrl((const char*)(pcds->lpData));
|
||||||
if (url.isValid() && url.scheme() == HIFI_URL_SCHEME) {
|
if (url.isValid() && url.scheme() == HIFI_URL_SCHEME) {
|
||||||
DependencyManager::get<AddressManager>()->handleLookupString(url.toString());
|
DependencyManager::get<AddressManager>()->handleLookupString(url.toString());
|
||||||
|
@ -1543,10 +1542,9 @@ void Application::initializeUi() {
|
||||||
rootContext->setContextProperty("Audio", &AudioScriptingInterface::getInstance());
|
rootContext->setContextProperty("Audio", &AudioScriptingInterface::getInstance());
|
||||||
rootContext->setContextProperty("Controller", DependencyManager::get<controller::ScriptingInterface>().data());
|
rootContext->setContextProperty("Controller", DependencyManager::get<controller::ScriptingInterface>().data());
|
||||||
rootContext->setContextProperty("Entities", DependencyManager::get<EntityScriptingInterface>().data());
|
rootContext->setContextProperty("Entities", DependencyManager::get<EntityScriptingInterface>().data());
|
||||||
//rootContext->setContextProperty("File", new FileScriptingInterface(engine));
|
FileScriptingInterface* fileDownload = new FileScriptingInterface(engine);
|
||||||
FileScriptingInterface* fileDownload = new FileScriptingInterface(engine);
|
rootContext->setContextProperty("File", fileDownload);
|
||||||
rootContext->setContextProperty("File", fileDownload);
|
connect(fileDownload, &FileScriptingInterface::unzipSuccess, this, &Application::toggleAssetServerWidget);
|
||||||
connect(fileDownload, &FileScriptingInterface::unzipSuccess, this, &Application::toggleAssetServerWidget);
|
|
||||||
rootContext->setContextProperty("MyAvatar", getMyAvatar());
|
rootContext->setContextProperty("MyAvatar", getMyAvatar());
|
||||||
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());
|
||||||
|
@ -2020,14 +2018,6 @@ bool Application::importSVOFromURL(const QString& urlString) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// attempt to start ZIP download project
|
|
||||||
bool Application::importZIPFromURL(const QString& urlString) {
|
|
||||||
qDebug() << "zip import request has been emitted";
|
|
||||||
emit zipImportRequested(urlString);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
// end attempt
|
|
||||||
|
|
||||||
bool Application::event(QEvent* event) {
|
bool Application::event(QEvent* event) {
|
||||||
|
|
||||||
if (!Menu::getInstance()) {
|
if (!Menu::getInstance()) {
|
||||||
|
@ -2147,26 +2137,21 @@ bool Application::event(QEvent* event) {
|
||||||
// handle custom URL
|
// handle custom URL
|
||||||
if (event->type() == QEvent::FileOpen) {
|
if (event->type() == QEvent::FileOpen) {
|
||||||
|
|
||||||
qDebug() << "we have received one url!: ";
|
|
||||||
QFileOpenEvent* fileEvent = static_cast<QFileOpenEvent*>(event);
|
QFileOpenEvent* fileEvent = static_cast<QFileOpenEvent*>(event);
|
||||||
|
|
||||||
QUrl url = fileEvent->url();
|
QUrl url = fileEvent->url();
|
||||||
|
|
||||||
if (!url.isEmpty()) {
|
if (!url.isEmpty()) {
|
||||||
QString urlString = url.toString();
|
QString urlString = url.toString();
|
||||||
qDebug() << "we got a url!: " + urlString;
|
|
||||||
if (canAcceptURL(urlString)) {
|
if (canAcceptURL(urlString)) {
|
||||||
qDebug() << "we got an ACCEPTED url!: " + urlString;
|
|
||||||
return acceptURL(urlString);
|
return acceptURL(urlString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event->type() == QEvent::None) {
|
|
||||||
qDebug() << "this url just didn't click";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (HFActionEvent::types().contains(event->type())) {
|
if (HFActionEvent::types().contains(event->type())) {
|
||||||
_controllerScriptingInterface->handleMetaEvent(static_cast<HFMetaEvent*>(event));
|
_controllerScriptingInterface->handleMetaEvent(static_cast<HFMetaEvent*>(event));
|
||||||
}
|
}
|
||||||
|
@ -3190,7 +3175,6 @@ void Application::saveSettings() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Application::importEntities(const QString& urlOrFilename) {
|
bool Application::importEntities(const QString& urlOrFilename) {
|
||||||
qDebug() << "import entities url";
|
|
||||||
bool success = false;
|
bool success = false;
|
||||||
_entityClipboard->withWriteLock([&] {
|
_entityClipboard->withWriteLock([&] {
|
||||||
_entityClipboard->eraseAllOctreeElements();
|
_entityClipboard->eraseAllOctreeElements();
|
||||||
|
@ -4800,7 +4784,6 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Application::canAcceptURL(const QString& urlString) const {
|
bool Application::canAcceptURL(const QString& urlString) const {
|
||||||
qDebug() << "stepping through 'canAcceptURL'";
|
|
||||||
QUrl url(urlString);
|
QUrl url(urlString);
|
||||||
if (urlString.startsWith(HIFI_URL_SCHEME)) {
|
if (urlString.startsWith(HIFI_URL_SCHEME)) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -4817,7 +4800,6 @@ bool Application::canAcceptURL(const QString& urlString) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Application::acceptURL(const QString& urlString, bool defaultUpload) {
|
bool Application::acceptURL(const QString& urlString, bool defaultUpload) {
|
||||||
qDebug() << "stepping through 'acceptURL'";
|
|
||||||
if (urlString.startsWith(HIFI_URL_SCHEME)) {
|
if (urlString.startsWith(HIFI_URL_SCHEME)) {
|
||||||
// this is a hifi URL - have the AddressManager handle it
|
// this is a hifi URL - have the AddressManager handle it
|
||||||
QMetaObject::invokeMethod(DependencyManager::get<AddressManager>().data(), "handleLookupString",
|
QMetaObject::invokeMethod(DependencyManager::get<AddressManager>().data(), "handleLookupString",
|
||||||
|
@ -4847,7 +4829,6 @@ void Application::setSessionUUID(const QUuid& sessionUUID) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Application::askToSetAvatarUrl(const QString& url) {
|
bool Application::askToSetAvatarUrl(const QString& url) {
|
||||||
qDebug() << "setting avatar url";
|
|
||||||
QUrl realUrl(url);
|
QUrl realUrl(url);
|
||||||
if (realUrl.isLocalFile()) {
|
if (realUrl.isLocalFile()) {
|
||||||
OffscreenUi::warning("", "You can not use local files for avatar components.");
|
OffscreenUi::warning("", "You can not use local files for avatar components.");
|
||||||
|
@ -4904,7 +4885,6 @@ bool Application::askToSetAvatarUrl(const QString& url) {
|
||||||
|
|
||||||
|
|
||||||
bool Application::askToLoadScript(const QString& scriptFilenameOrURL) {
|
bool Application::askToLoadScript(const QString& scriptFilenameOrURL) {
|
||||||
qDebug() << "setting script url";
|
|
||||||
QMessageBox::StandardButton reply;
|
QMessageBox::StandardButton reply;
|
||||||
|
|
||||||
QString shortName = scriptFilenameOrURL;
|
QString shortName = scriptFilenameOrURL;
|
||||||
|
@ -4929,7 +4909,6 @@ bool Application::askToLoadScript(const QString& scriptFilenameOrURL) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Application::askToWearAvatarAttachmentUrl(const QString& url) {
|
bool Application::askToWearAvatarAttachmentUrl(const QString& url) {
|
||||||
qDebug() << "setting avatar attachment url";
|
|
||||||
QNetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance();
|
QNetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance();
|
||||||
QNetworkRequest networkRequest = QNetworkRequest(url);
|
QNetworkRequest networkRequest = QNetworkRequest(url);
|
||||||
networkRequest.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT);
|
networkRequest.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT);
|
||||||
|
@ -5011,7 +4990,6 @@ bool Application::displayAvatarAttachmentConfirmationDialog(const QString& name)
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::toggleRunningScriptsWidget() const {
|
void Application::toggleRunningScriptsWidget() const {
|
||||||
qDebug() << "toggle running scripts url";
|
|
||||||
static const QUrl url("hifi/dialogs/RunningScripts.qml");
|
static const QUrl url("hifi/dialogs/RunningScripts.qml");
|
||||||
DependencyManager::get<OffscreenUi>()->show(url, "RunningScripts");
|
DependencyManager::get<OffscreenUi>()->show(url, "RunningScripts");
|
||||||
//if (_runningScriptsWidget->isVisible()) {
|
//if (_runningScriptsWidget->isVisible()) {
|
||||||
|
@ -5029,16 +5007,16 @@ void Application::toggleRunningScriptsWidget() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::toggleAssetServerWidget(QString filePath) {
|
void Application::toggleAssetServerWidget(QString filePath) {
|
||||||
qDebug() << "toggle asset before if";
|
qDebug() << "toggle asset before if: " + filePath;
|
||||||
if (!DependencyManager::get<NodeList>()->getThisNodeCanWriteAssets()) {
|
if (!DependencyManager::get<NodeList>()->getThisNodeCanWriteAssets()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
qDebug() << "toggle asset after if";
|
qDebug() << "toggle asset after if";
|
||||||
static const QUrl url { "AssetServer.qml" };
|
static const QUrl url { "AssetServer.qml" };
|
||||||
|
|
||||||
auto startUpload = [=](QQmlContext* context, QObject* newObject){
|
auto startUpload = [=](QQmlContext* context, QObject* newObject){
|
||||||
if (!filePath.isEmpty()) {
|
if (!filePath.isEmpty()) {
|
||||||
qDebug() << "file in toggle: " + filePath;
|
qDebug() << "file in toggle: " + filePath;
|
||||||
emit uploadRequest(filePath);
|
emit uploadRequest(filePath);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -5051,7 +5029,6 @@ void Application::packageModel() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::openUrl(const QUrl& url) const {
|
void Application::openUrl(const QUrl& url) const {
|
||||||
qDebug() << "open url";
|
|
||||||
if (!url.isEmpty()) {
|
if (!url.isEmpty()) {
|
||||||
if (url.scheme() == HIFI_URL_SCHEME) {
|
if (url.scheme() == HIFI_URL_SCHEME) {
|
||||||
DependencyManager::get<AddressManager>()->handleLookupString(url.toString());
|
DependencyManager::get<AddressManager>()->handleLookupString(url.toString());
|
||||||
|
@ -5082,7 +5059,6 @@ void Application::setPreviousScriptLocation(const QString& location) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::loadScriptURLDialog() const {
|
void Application::loadScriptURLDialog() const {
|
||||||
qDebug() << "load script url dialog";
|
|
||||||
auto newScript = OffscreenUi::getText(nullptr, "Open and Run Script", "Script URL");
|
auto newScript = OffscreenUi::getText(nullptr, "Open and Run Script", "Script URL");
|
||||||
if (!newScript.isEmpty()) {
|
if (!newScript.isEmpty()) {
|
||||||
DependencyManager::get<ScriptEngines>()->loadScript(newScript);
|
DependencyManager::get<ScriptEngines>()->loadScript(newScript);
|
||||||
|
|
|
@ -250,7 +250,6 @@ public:
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void svoImportRequested(const QString& url);
|
void svoImportRequested(const QString& url);
|
||||||
void zipImportRequested(const QString& url);
|
|
||||||
|
|
||||||
void fullAvatarURLChanged(const QString& newValue, const QString& modelName);
|
void fullAvatarURLChanged(const QString& newValue, const QString& modelName);
|
||||||
|
|
||||||
|
@ -386,7 +385,6 @@ private:
|
||||||
|
|
||||||
bool importJSONFromURL(const QString& urlString);
|
bool importJSONFromURL(const QString& urlString);
|
||||||
bool importSVOFromURL(const QString& urlString);
|
bool importSVOFromURL(const QString& urlString);
|
||||||
bool importZIPFromURL(const QString& urlString);
|
|
||||||
|
|
||||||
bool nearbyEntitiesAreReadyForPhysics();
|
bool nearbyEntitiesAreReadyForPhysics();
|
||||||
int processOctreeStats(ReceivedMessage& message, SharedNodePointer sendingNode);
|
int processOctreeStats(ReceivedMessage& message, SharedNodePointer sendingNode);
|
||||||
|
|
|
@ -59,20 +59,6 @@ WindowScriptingInterface::WindowScriptingInterface() {
|
||||||
OffscreenUi::warning("Import SVO Error", "You need to be running edit.js to import entities.");
|
OffscreenUi::warning("Import SVO Error", "You need to be running edit.js to import entities.");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// attempt to start ZIP download project
|
|
||||||
connect(qApp, &Application::zipImportRequested, [this](const QString& urlString) {
|
|
||||||
qDebug() << "zip import has been requested";
|
|
||||||
static const QMetaMethod zipImportRequestedSignal =
|
|
||||||
QMetaMethod::fromSignal(&WindowScriptingInterface::zipImportRequested);
|
|
||||||
|
|
||||||
if (isSignalConnected(zipImportRequestedSignal)) {
|
|
||||||
QUrl url(urlString);
|
|
||||||
emit zipImportRequested(url.url());
|
|
||||||
} else {
|
|
||||||
OffscreenUi::warning("Import ZIP Error", "You need to be running edit.js to import entities.");
|
|
||||||
}
|
|
||||||
// end attempt
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WebWindowClass* WindowScriptingInterface::doCreateWebWindow(const QString& title, const QString& url, int width, int height) {
|
WebWindowClass* WindowScriptingInterface::doCreateWebWindow(const QString& title, const QString& url, int width, int height) {
|
||||||
|
|
|
@ -58,7 +58,6 @@ public slots:
|
||||||
signals:
|
signals:
|
||||||
void domainChanged(const QString& domainHostname);
|
void domainChanged(const QString& domainHostname);
|
||||||
void svoImportRequested(const QString& url);
|
void svoImportRequested(const QString& url);
|
||||||
void zipImportRequested(const QString& url); // zip project
|
|
||||||
void domainConnectionRefused(const QString& reasonMessage, int reasonCode);
|
void domainConnectionRefused(const QString& reasonMessage, int reasonCode);
|
||||||
void snapshotTaken(const QString& path);
|
void snapshotTaken(const QString& path);
|
||||||
|
|
||||||
|
|
|
@ -28,94 +28,97 @@
|
||||||
|
|
||||||
|
|
||||||
FileScriptingInterface::FileScriptingInterface(QObject* parent) : QObject(parent) {
|
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) {
|
||||||
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 file = unzipFile(path);
|
QString file = unzipFile(path);
|
||||||
if (file != "") {
|
if (file != "") {
|
||||||
qDebug() << "file to upload: " + file;
|
qDebug() << "file to upload: " + file;
|
||||||
QUrl url = QUrl::fromLocalFile(file);
|
QUrl url = QUrl::fromLocalFile(file);
|
||||||
qDebug() << "url from local file: " + url.toString();
|
qDebug() << "url from local file: " + url.toString();
|
||||||
emit unzipSuccess(url.toString());
|
emit unzipSuccess(url.toString());
|
||||||
//Application::toggleAssetServerWidget(file);
|
} else {
|
||||||
} else {
|
qDebug() << "unzip failed";
|
||||||
qDebug() << "unzip failed";
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileScriptingInterface::testUrl(QUrl url) {
|
bool FileScriptingInterface::testUrl(QUrl url) {
|
||||||
if (url.toString().contains(".zip") && url.toString().contains("fbx")) 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.";
|
qDebug() << "This model is not a .fbx packaged in a .zip. Please try with another model.";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// this function is not in use
|
||||||
QString FileScriptingInterface::getTempDir() {
|
QString FileScriptingInterface::getTempDir() {
|
||||||
QTemporaryDir dir;
|
QTemporaryDir dir;
|
||||||
dir.setAutoRemove(false);
|
dir.setAutoRemove(false);
|
||||||
return dir.path();
|
return dir.path();
|
||||||
// remember I must do something to delete this temp dir later
|
// do something to delete this temp dir later
|
||||||
}
|
}
|
||||||
|
|
||||||
QString FileScriptingInterface::convertUrlToPath(QUrl url) {
|
QString FileScriptingInterface::convertUrlToPath(QUrl url) {
|
||||||
QString newUrl;
|
QString newUrl;
|
||||||
QString oldUrl = url.toString();
|
QString oldUrl = url.toString();
|
||||||
newUrl = oldUrl.section("filename=", 1, 1);
|
newUrl = oldUrl.section("filename=", 1, 1);
|
||||||
qDebug() << "Filename should be: " + newUrl;
|
qDebug() << "Filename should be: " + newUrl;
|
||||||
return newUrl;
|
return newUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// this function is not in use
|
||||||
void FileScriptingInterface::downloadZip(QString path, const QString link) {
|
void FileScriptingInterface::downloadZip(QString path, const QString link) {
|
||||||
QUrl url = QUrl(link);
|
QUrl url = QUrl(link);
|
||||||
auto request = ResourceManager::createResourceRequest(nullptr, url);
|
auto request = ResourceManager::createResourceRequest(nullptr, url);
|
||||||
connect(request, &ResourceRequest::finished, this, [this, path]{
|
connect(request, &ResourceRequest::finished, this, [this, path]{
|
||||||
unzipFile(path);
|
unzipFile(path);
|
||||||
});
|
});
|
||||||
request->send();
|
request->send();
|
||||||
}
|
}
|
||||||
|
|
||||||
// clement's help :D
|
|
||||||
QString FileScriptingInterface::unzipFile(QString path) {
|
QString FileScriptingInterface::unzipFile(QString path) {
|
||||||
|
|
||||||
qDebug() << "Zip file was downloaded";
|
QDir dir(path);
|
||||||
QDir dir(path);
|
|
||||||
QString dirName = dir.path();
|
QString dirName = dir.path();
|
||||||
qDebug() << "Zip directory is stored at: " + dirName;
|
qDebug() << "Zip directory is stored at: " + dirName;
|
||||||
|
QString target = path.section("/", -1) + "/model_repo";
|
||||||
|
qDebug() << "Target path: " + target;
|
||||||
QStringList list = JlCompress::extractDir(dirName, "C:/Users/elisa/Downloads/test");
|
QStringList list = JlCompress::extractDir(dirName, "C:/Users/elisa/Downloads/test");
|
||||||
|
|
||||||
qDebug() << list;
|
qDebug() << list;
|
||||||
|
|
||||||
if (!list.isEmpty()) {
|
if (!list.isEmpty()) {
|
||||||
return list.front();
|
return list.front();
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "Extraction failed";
|
qDebug() << "Extraction failed";
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// this function is not in use
|
||||||
void FileScriptingInterface::recursiveFileScan(QFileInfo file, QString* dirName) {
|
void FileScriptingInterface::recursiveFileScan(QFileInfo file, QString* dirName) {
|
||||||
/*if (!file.isDir()) {
|
/*if (!file.isDir()) {
|
||||||
qDebug() << "Regular file logged: " + file.fileName();
|
qDebug() << "Regular file logged: " + file.fileName();
|
||||||
return;
|
return;
|
||||||
}*/
|
}*/
|
||||||
QFileInfoList files;
|
QFileInfoList files;
|
||||||
|
|
||||||
if (file.fileName().contains(".zip")) {
|
if (file.fileName().contains(".zip")) {
|
||||||
qDebug() << "Extracting archive: " + file.fileName();
|
qDebug() << "Extracting archive: " + file.fileName();
|
||||||
JlCompress::extractDir(file.fileName());
|
JlCompress::extractDir(file.fileName());
|
||||||
}
|
}
|
||||||
files = file.dir().entryInfoList();
|
files = file.dir().entryInfoList();
|
||||||
|
|
||||||
/*if (files.empty()) {
|
/*if (files.empty()) {
|
||||||
files = JlCompress::getFileList(file.fileName());
|
files = JlCompress::getFileList(file.fileName());
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
foreach (QFileInfo file, files) {
|
foreach (QFileInfo file, files) {
|
||||||
qDebug() << "Looking into file: " + file.fileName();
|
qDebug() << "Looking into file: " + file.fileName();
|
||||||
recursiveFileScan(file, dirName);
|
recursiveFileScan(file, dirName);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,24 +22,24 @@ class FileScriptingInterface : public QObject {
|
||||||
public:
|
public:
|
||||||
FileScriptingInterface(QObject* parent);
|
FileScriptingInterface(QObject* parent);
|
||||||
|
|
||||||
//void runUnzip(QString path, QString importURL);
|
//void runUnzip(QString path, QString importURL);
|
||||||
QString getTempDir();
|
QString getTempDir();
|
||||||
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
//void unzipFile(QString path);
|
//void unzipFile(QString path);
|
||||||
bool testUrl(QUrl url);
|
bool testUrl(QUrl url);
|
||||||
QString convertUrlToPath(QUrl url);
|
QString convertUrlToPath(QUrl url);
|
||||||
void runUnzip(QString path, QUrl url);
|
void runUnzip(QString path, QUrl url);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void unzipSuccess(QString url);
|
void unzipSuccess(QString url);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//void downloadZip();
|
//void downloadZip();
|
||||||
QString unzipFile(QString path);
|
QString unzipFile(QString path);
|
||||||
void recursiveFileScan(QFileInfo file, QString* dirName);
|
void recursiveFileScan(QFileInfo file, QString* dirName);
|
||||||
void downloadZip(QString path, const QString link);
|
void downloadZip(QString path, const QString link);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -503,7 +503,6 @@ void ScriptEngine::init() {
|
||||||
registerGlobalObject("Uuid", &_uuidLibrary);
|
registerGlobalObject("Uuid", &_uuidLibrary);
|
||||||
registerGlobalObject("Messages", DependencyManager::get<MessagesClient>().data());
|
registerGlobalObject("Messages", DependencyManager::get<MessagesClient>().data());
|
||||||
|
|
||||||
// unzip project
|
|
||||||
registerGlobalObject("File", new FileScriptingInterface(this));
|
registerGlobalObject("File", new FileScriptingInterface(this));
|
||||||
|
|
||||||
qScriptRegisterMetaType(this, animVarMapToScriptValue, animVarMapFromScriptValue);
|
qScriptRegisterMetaType(this, animVarMapToScriptValue, animVarMapFromScriptValue);
|
||||||
|
|
|
@ -78,20 +78,17 @@ class UrlHandler : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
Q_INVOKABLE bool canHandleUrl(const QString& url) {
|
Q_INVOKABLE bool canHandleUrl(const QString& url) {
|
||||||
qDebug() << Q_FUNC_INFO;
|
|
||||||
static auto handler = dynamic_cast<AbstractUriHandler*>(qApp);
|
static auto handler = dynamic_cast<AbstractUriHandler*>(qApp);
|
||||||
return handler->canAcceptURL(url);
|
return handler->canAcceptURL(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_INVOKABLE bool handleUrl(const QString& url) {
|
Q_INVOKABLE bool handleUrl(const QString& url) {
|
||||||
qDebug() << Q_FUNC_INFO;
|
|
||||||
static auto handler = dynamic_cast<AbstractUriHandler*>(qApp);
|
static auto handler = dynamic_cast<AbstractUriHandler*>(qApp);
|
||||||
return handler->acceptURL(url);
|
return handler->acceptURL(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME hack for authentication, remove when we migrate to Qt 5.6
|
// FIXME hack for authentication, remove when we migrate to Qt 5.6
|
||||||
Q_INVOKABLE QString fixupUrl(const QString& originalUrl) {
|
Q_INVOKABLE QString fixupUrl(const QString& originalUrl) {
|
||||||
qDebug() << Q_FUNC_INFO;
|
|
||||||
return fixupHifiUrl(originalUrl);
|
return fixupHifiUrl(originalUrl);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1205,22 +1205,6 @@ function importSVO(importURL) {
|
||||||
}
|
}
|
||||||
Window.svoImportRequested.connect(importSVO);
|
Window.svoImportRequested.connect(importSVO);
|
||||||
|
|
||||||
// attempt to start ZIP download project, GET RID OF THIS
|
|
||||||
function importZIP(importURL) {
|
|
||||||
print("Import ZIP requested: " + importURL);
|
|
||||||
/*if (!Entities.canAdjustLocks()) {
|
|
||||||
Window.alert(INSUFFICIENT_PERMISSIONS_IMPORT_ERROR_MSG);
|
|
||||||
return;
|
|
||||||
}*/
|
|
||||||
var path = File.getTempDir();
|
|
||||||
print("Temporary path to zip: " + path);
|
|
||||||
File.runUnzip(path, importURL);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
Window.zipImportRequested.connect(importZIP);
|
|
||||||
//end attempt
|
|
||||||
|
|
||||||
Menu.menuItemEvent.connect(handeMenuEvent);
|
Menu.menuItemEvent.connect(handeMenuEvent);
|
||||||
|
|
||||||
Controller.keyPressEvent.connect(function (event) {
|
Controller.keyPressEvent.connect(function (event) {
|
||||||
|
|
Loading…
Reference in a new issue