From 7d7e0129656959558a563f87ceabfd0d4c399c9b Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 6 May 2014 11:28:09 -0700 Subject: [PATCH 01/20] Add XMLHttpRequest --- .../script-engine/src/XMLHttpRequestClass.cpp | 233 ++++++++++++++++++ .../script-engine/src/XMLHttpRequestClass.h | 128 ++++++++++ 2 files changed, 361 insertions(+) create mode 100644 libraries/script-engine/src/XMLHttpRequestClass.cpp create mode 100644 libraries/script-engine/src/XMLHttpRequestClass.h diff --git a/libraries/script-engine/src/XMLHttpRequestClass.cpp b/libraries/script-engine/src/XMLHttpRequestClass.cpp new file mode 100644 index 0000000000..77b03db999 --- /dev/null +++ b/libraries/script-engine/src/XMLHttpRequestClass.cpp @@ -0,0 +1,233 @@ +// +// XMLHttpRequestClass.cpp +// libraries/script-engine/src/ +// +// Created by Ryan Huffman on 5/2/14. +// Copyright (c) 2014 High Fidelity, Inc. All rights reserved. +// +// This class is an implementation of the XMLHttpRequest object for scripting use. It provides a near-complete implementation +// of the class described in the Mozilla docs: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include + +#include "XMLHttpRequestClass.h" + +XMLHttpRequestClass::XMLHttpRequestClass(QScriptEngine* engine) : + _engine(engine), + _async(true), + _url(), + _method(""), + _responseType(""), + _manager(this), + _request(), + _reply(NULL), + _sendData(NULL), + _rawResponseData(), + _responseData(""), + _onTimeout(QScriptValue::NullValue), + _onReadyStateChange(QScriptValue::NullValue), + _readyState(XMLHttpRequestClass::UNSENT), + _errorCode(QNetworkReply::NoError), + _timeout(0), + _timer(this), + _numRedirects(0) { + + _timer.setSingleShot(true); +} + +XMLHttpRequestClass::~XMLHttpRequestClass() { + if (_reply) { delete _reply; } + if (_sendData) { delete _sendData; } +} + +QScriptValue XMLHttpRequestClass::constructor(QScriptContext* context, QScriptEngine* engine) { + return engine->newQObject(new XMLHttpRequestClass(engine)); +} + +QScriptValue XMLHttpRequestClass::getStatus() const { + if (_reply) { + return QScriptValue(_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt()); + } + return QScriptValue(0); +} + +QString XMLHttpRequestClass::getStatusText() const { + if (_reply) { + return _reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString(); + } + return ""; +} + +void XMLHttpRequestClass::abort() { + _abortRequest(); +} + +void XMLHttpRequestClass::setRequestHeader(const QString& name, const QString& value) { + _request.setRawHeader(QByteArray(name.toLatin1()), QByteArray(value.toLatin1())); +} + +void XMLHttpRequestClass::requestMetaDataChanged() { + QVariant redirect = _reply->attribute(QNetworkRequest::RedirectionTargetAttribute); + + // If this is a redirect, abort the current request and start a new one + if (redirect.isValid() && _numRedirects < MAXIMUM_REDIRECTS) { + _numRedirects++; + _abortRequest(); + + QUrl newUrl = _url.resolved(redirect.toUrl().toString()); + _request.setUrl(newUrl); + _doSend(); + } +} + +void XMLHttpRequestClass::requestDownloadProgress(qint64 bytesReceived, qint64 bytesTotal) { + if (_readyState == OPENED && bytesReceived > 0) { + _setReadyState(HEADERS_RECEIVED); + _setReadyState(LOADING); + } +} + +QScriptValue XMLHttpRequestClass::getAllResponseHeaders() const { + if (_reply) { + QList headerList = _reply->rawHeaderPairs(); + QByteArray headers; + for (int i = 0; i < headerList.size(); i++) { + headers.append(headerList[i].first); + headers.append(": "); + headers.append(headerList[i].second); + headers.append("\n"); + } + return QString(headers.data()); + } + return QScriptValue(""); +} + +QScriptValue XMLHttpRequestClass::getResponseHeader(const QString& name) const { + if (_reply && _reply->hasRawHeader(name.toLatin1())) { + return QScriptValue(QString(_reply->rawHeader(name.toLatin1()))); + } + return QScriptValue::NullValue; +} + +void XMLHttpRequestClass::_setReadyState(ReadyState readyState) { + if (readyState != _readyState) { + _readyState = readyState; + if (_onReadyStateChange.isFunction()) { + _onReadyStateChange.call(QScriptValue::NullValue); + } + } +} + +void XMLHttpRequestClass::open(const QString& method, const QString& url, bool async, const QString& username, + const QString& password) { + if (_readyState == UNSENT) { + _async = async; + _url.setUrl(url); + if (!username.isEmpty()) { + _url.setUserName(username); + } + if (!password.isEmpty()) { + _url.setPassword(password); + } + _request.setUrl(_url); + _method = method; + _setReadyState(OPENED); + } +} + +void XMLHttpRequestClass::send() { + send(QString::Null()); +} + +void XMLHttpRequestClass::send(const QString& data) { + if (_readyState == OPENED && !_reply) { + if (!data.isNull()) { + _sendData = new QBuffer(this); + _sendData->setData(data.toUtf8()); + } + + _doSend(); + + if (!_async) { + QEventLoop loop; + connect(this, SIGNAL(requestComplete()), &loop, SLOT(quit())); + loop.exec(); + } + } +} + +void XMLHttpRequestClass::_doSend() { + _reply = _manager.sendCustomRequest(_request, _method.toLatin1(), _sendData); + + _connectToReply(_reply); + + if (_timeout > 0) { + _timer.start(_timeout); + connect(&_timer, SIGNAL(timeout()), this, SLOT(requestTimeout())); + } +} + +void XMLHttpRequestClass::requestTimeout() { + if (_onTimeout.isFunction()) { + _onTimeout.call(QScriptValue::NullValue); + } + _abortRequest(); + _errorCode = QNetworkReply::TimeoutError; + _setReadyState(DONE); + emit requestComplete(); +} + +void XMLHttpRequestClass::requestError(QNetworkReply::NetworkError code) { +} + +void XMLHttpRequestClass::requestFinished() { + disconnect(&_timer, SIGNAL(timeout()), this, SLOT(requestTimeout())); + + _errorCode = _reply->error(); + if (_errorCode == QNetworkReply::NoError) { + _rawResponseData.append(_reply->readAll()); + + if (_responseType == "json") { + _responseData = _engine->evaluate("(" + QString(_rawResponseData.data()) + ")"); + if (_responseData.isError()) { + _engine->clearExceptions(); + _responseData = QScriptValue::NullValue; + } + } else if (_responseType == "arraybuffer") { + _responseData = QScriptValue(_rawResponseData.data()); + } else { + _responseData = QScriptValue(QString(_rawResponseData.data())); + } + } + _setReadyState(DONE); + emit requestComplete(); +} + +void XMLHttpRequestClass::_abortRequest() { + // Disconnect from signals we don't want to receive any longer. + disconnect(&_timer, SIGNAL(timeout()), this, SLOT(requestTimeout())); + if (_reply) { + _disconnectFromReply(_reply); + _reply->abort(); + delete _reply; + _reply = NULL; + } +} + +void XMLHttpRequestClass::_connectToReply(QNetworkReply* reply) { + connect(reply, SIGNAL(finished()), this, SLOT(requestFinished())); + connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(requestError(QNetworkReply::NetworkError))); + connect(reply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(requestDownloadProgress(qint64, qint64))); + connect(reply, SIGNAL(metaDataChanged()), this, SLOT(requestMetaDataChanged())); +} + +void XMLHttpRequestClass::_disconnectFromReply(QNetworkReply* reply) { + disconnect(reply, SIGNAL(finished()), this, SLOT(requestFinished())); + disconnect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(requestError(QNetworkReply::NetworkError))); + disconnect(reply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(requestDownloadProgress(qint64, qint64))); + disconnect(reply, SIGNAL(metaDataChanged()), this, SLOT(requestMetaDataChanged())); +} diff --git a/libraries/script-engine/src/XMLHttpRequestClass.h b/libraries/script-engine/src/XMLHttpRequestClass.h new file mode 100644 index 0000000000..b1b33e4cc6 --- /dev/null +++ b/libraries/script-engine/src/XMLHttpRequestClass.h @@ -0,0 +1,128 @@ +// +// XMLHttpRequestClass.h +// libraries/script-engine/src/ +// +// Created by Ryan Huffman on 5/2/14. +// Copyright (c) 2014 High Fidelity, Inc. All rights reserved. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_XMLHttpRequestClass_h +#define hifi_XMLHttpRequestClass_h + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class XMLHttpRequestClass : public QObject { + Q_OBJECT + Q_PROPERTY(QScriptValue response READ getResponse) + Q_PROPERTY(QScriptValue responseText READ getResponseText) + Q_PROPERTY(QString responseType READ getResponseType WRITE setResponseType) + Q_PROPERTY(QScriptValue status READ getStatus) + Q_PROPERTY(QString statusText READ getStatusText) + Q_PROPERTY(QScriptValue readyState READ getReadyState) + Q_PROPERTY(QScriptValue errorCode READ getError) + Q_PROPERTY(int timeout READ getTimeout WRITE setTimeout) + + Q_PROPERTY(int UNSENT READ getUnsent) + Q_PROPERTY(int OPENED READ getOpened) + Q_PROPERTY(int HEADERS_RECEIVED READ getHeadersReceived) + Q_PROPERTY(int LOADING READ getLoading) + Q_PROPERTY(int DONE READ getDone) + + // Callbacks + Q_PROPERTY(QScriptValue ontimeout WRITE setOnTimeout) + Q_PROPERTY(QScriptValue onreadystatechange WRITE setOnReadyStateChange) +public: + XMLHttpRequestClass(QScriptEngine* engine); + ~XMLHttpRequestClass(); + + static const int MAXIMUM_REDIRECTS = 5; + enum ReadyState { + UNSENT = 0, + OPENED, + HEADERS_RECEIVED, + LOADING, + DONE + }; + + int getUnsent() const { return UNSENT; }; + int getOpened() const { return OPENED; }; + int getHeadersReceived() const { return HEADERS_RECEIVED; }; + int getLoading() const { return LOADING; }; + int getDone() const { return DONE; }; + + static QScriptValue constructor(QScriptContext* context, QScriptEngine* engine); + static QString escapeJavascriptString(const QString& jsString); + + int getTimeout() const { return _timeout; } + void setTimeout(int timeout) { _timeout = timeout; } + QScriptValue getResponse() const { return _responseData; } + QScriptValue getResponseText() const { return QScriptValue(QString(_rawResponseData.data())); } + QString getResponseType() const { return _responseType; } + void setResponseType(const QString& responseType) { _responseType = responseType; } + QScriptValue getReadyState() const { return QScriptValue(_readyState); } + QScriptValue getError() const { return QScriptValue(_errorCode); } + QScriptValue getStatus() const; + QString getStatusText() const; + + void setOnTimeout(QScriptValue function) { _onTimeout = function; } + void setOnReadyStateChange(QScriptValue function) { _onReadyStateChange = function; } + +public slots: + void abort(); + void setRequestHeader(const QString& name, const QString& value); + void open(const QString& method, const QString& url, bool async = true, const QString& username = "", + const QString& password = ""); + void send(); + void send(const QString& data); + QScriptValue getAllResponseHeaders() const; + QScriptValue getResponseHeader(const QString& name) const; + +signals: + void requestComplete(); + +private: + void _setReadyState(ReadyState readyState); + void _doSend(); + void _connectToReply(QNetworkReply* reply); + void _disconnectFromReply(QNetworkReply* reply); + void _abortRequest(); + + QScriptEngine* _engine; + bool _async; + QUrl _url; + QString _method; + QString _responseType; + QNetworkAccessManager _manager; + QNetworkRequest _request; + QNetworkReply* _reply; + QBuffer* _sendData; + QByteArray _rawResponseData; + QScriptValue _responseData; + QScriptValue _onTimeout; + QScriptValue _onReadyStateChange; + ReadyState _readyState; + QNetworkReply::NetworkError _errorCode; + int _timeout; + QTimer _timer; + int _numRedirects; + +private slots: + void requestFinished(); + void requestError(QNetworkReply::NetworkError code); + void requestMetaDataChanged(); + void requestDownloadProgress(qint64 bytesReceived, qint64 bytesTotal); + void requestTimeout(); +}; + +#endif // hifi_XMLHttpRequestClass_h From 2dda87fe7f4c5d8d8ed78e0ea73c2794d6b26c97 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 6 May 2014 11:28:35 -0700 Subject: [PATCH 02/20] Add XMLHttpRequest constructor to ScriptEngine --- libraries/script-engine/src/ScriptEngine.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index 402f1a2885..41ed07cc23 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -34,6 +34,7 @@ #include "MenuItemProperties.h" #include "LocalVoxels.h" #include "ScriptEngine.h" +#include "XMLHttpRequestClass.h" VoxelsScriptingInterface ScriptEngine::_voxelsScriptingInterface; ParticlesScriptingInterface ScriptEngine::_particlesScriptingInterface; @@ -214,6 +215,9 @@ void ScriptEngine::init() { qScriptRegisterSequenceMetaType >(&_engine); qScriptRegisterSequenceMetaType >(&_engine); + QScriptValue xmlHttpRequestConstructorValue = _engine.newFunction(XMLHttpRequestClass::constructor); + _engine.globalObject().setProperty("XMLHttpRequest", xmlHttpRequestConstructorValue); + QScriptValue printConstructorValue = _engine.newFunction(debugPrint); _engine.globalObject().setProperty("print", printConstructorValue); From 39e6e61a6d2026c3c57da3a425566551a6fca982 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 6 May 2014 11:31:33 -0700 Subject: [PATCH 03/20] Add XMLHttpRequest tests and examples --- examples/Test.js | 68 +++++++++++++++ examples/streetAreaExample.js | 51 ++++++++++++ examples/testXMLHttpRequest.js | 147 +++++++++++++++++++++++++++++++++ 3 files changed, 266 insertions(+) create mode 100644 examples/Test.js create mode 100644 examples/streetAreaExample.js create mode 100644 examples/testXMLHttpRequest.js diff --git a/examples/Test.js b/examples/Test.js new file mode 100644 index 0000000000..c56c7ebdc1 --- /dev/null +++ b/examples/Test.js @@ -0,0 +1,68 @@ +// +// Test.js +// examples +// +// Created by Ryan Huffman on 5/4//14 +// Copyright 2014 High Fidelity, Inc. +// +// This provides very basic unit testing functionality. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +test = function(name, func) { + print("Running test: " + name); + + var unitTest = new UnitTest(name, func); + + try { + unitTest.run(); + print(" Success: " + unitTest.numAssertions + " assertions passed"); + } catch (error) { + print(" Failure: " + error.message); + } +}; + +AssertionException = function(expected, actual, message) { + print("Creating exception"); + this.message = message + "\n: " + actual + " != " + expected; + this.name = 'AssertionException'; +}; + +UnitTest = function(name, func) { + this.numAssertions = 0; + this.func = func; +}; + +UnitTest.prototype.run = function() { + this.func(); +}; + +UnitTest.prototype.assertNotEquals = function(expected, actual, message) { + this.numAssertions++; + if (expected == actual) { + throw new AssertionException(expected, actual, message); + } +}; + +UnitTest.prototype.assertEquals = function(expected, actual, message) { + this.numAssertions++; + if (expected != actual) { + throw new AssertionException(expected, actual, message); + } +}; + +UnitTest.prototype.assertHasProperty = function(property, actual, message) { + this.numAssertions++; + if (actual[property] === undefined) { + throw new AssertionException(property, actual, message); + } +}; + +UnitTest.prototype.assertNull = function(value, message) { + this.numAssertions++; + if (value !== null) { + throw new AssertionException(value, null, message); + } +}; diff --git a/examples/streetAreaExample.js b/examples/streetAreaExample.js new file mode 100644 index 0000000000..5e92753689 --- /dev/null +++ b/examples/streetAreaExample.js @@ -0,0 +1,51 @@ +// +// streetAreaExample.js +// examples +// +// Created by Ryan Huffman on 5/4//14 +// Copyright 2014 High Fidelity, Inc. +// +// This is an example script showing how to load JSON data using XMLHttpRequest. +// +// URL Macro created by Thijs Wenker. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +var url = "https://script.google.com/macros/s/AKfycbwIo4lmF-qUwX1Z-9eA_P-g2gse9oFhNcjVyyksGukyDDEFXgU/exec?action=listOwners&domain=alpha.highfidelity.io"; +print("Loading street data from " + url); + +var req = new XMLHttpRequest(); + +// Set response type to "json". This will tell XMLHttpRequest to parse the response data as json, so req.response can be used +// as a regular javascript object +req.responseType = 'json'; + +req.open("GET", url, false); +req.send(); + +if (req.status == 200) { + for (var domain in req.response) { + print("DOMAIN: " + domain); + var locations = req.response[domain]; + var userAreas = []; + for (var i = 0; i < locations.length; i++) { + var loc = locations[i]; + var x1 = loc[1], + y1 = loc[2], + x2 = loc[3], + y2 = loc[4]; + userAreas.push({ + username: loc[0], + area: Math.abs(x2 - x1) * Math.abs(y2 - y1), + }); + } + userAreas.sort(function(a, b) { return a.area > b.area ? -1 : (a.area < b.area ? 1 : 0) }); + for (var i = 0; i < userAreas.length; i++) { + print(userAreas[i].username + ": " + userAreas[i].area + " sq units"); + } + } +} else { + print("Error loading data: " + req.status + " " + req.statusText + ", " + req.errorCode); +} diff --git a/examples/testXMLHttpRequest.js b/examples/testXMLHttpRequest.js new file mode 100644 index 0000000000..6471b2fdeb --- /dev/null +++ b/examples/testXMLHttpRequest.js @@ -0,0 +1,147 @@ +// +// testXMLHttpRequest.js +// examples +// +// Created by Ryan Huffman on 5/4//14 +// Copyright 2014 High Fidelity, Inc. +// +// XMLHttpRequest Tests +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +Script.include("Test.js"); + +test("Test default request values", function(finished) { + var req = new XMLHttpRequest(); + + this.assertEquals(req.UNSENT, req.readyState, "readyState should be UNSENT"); + this.assertEquals(0, req.status, "status should be `0` by default"); + this.assertEquals("", req.statusText, "statusText should be empty string by default"); + this.assertEquals("", req.getAllResponseHeaders(), "getAllResponseHeaders() should return empty string by default"); + this.assertEquals("", req.response, "response should be empty string by default"); + this.assertEquals("", req.responseText, "responseText should be empty string by default"); + this.assertEquals("", req.responseType, "responseType should be empty string by default"); + this.assertEquals(0, req.timeout, "timeout should be `0` by default"); + this.assertEquals(0, req.errorCode, "there should be no error by default"); +}); + + +test("Test readyStates", function() { + var req = new XMLHttpRequest(); + var state = req.readyState; + + var statesVisited = [true, false, false, false, false] + + req.onreadystatechange = function() { + statesVisited[req.readyState] = true; + }; + + req.open("GET", "https://gist.githubusercontent.com/huffman/33cc618fec183d1bccd0/raw/test.json", false); + req.send(); + for (var i = 0; i <= req.DONE; i++) { + this.assertEquals(true, statesVisited[i], i + " should be set"); + } + this.assertEquals(req.DONE, req.readyState, "readyState should be DONE"); +}); + +test("Test TEXT request", function() { + var req = new XMLHttpRequest(); + var state = req.readyState; + + req.open("GET", "https://gist.githubusercontent.com/huffman/33cc618fec183d1bccd0/raw/test.json", false); + req.send(); + + this.assertEquals(req.DONE, req.readyState, "readyState should be DONE"); + this.assertEquals(200, req.status, "status should be `200`"); + this.assertEquals(0, req.errorCode); + this.assertEquals("OK", req.statusText, "statusText should be `OK`"); + this.assertNotEquals("", req.getAllResponseHeaders(), "headers should no longer be empty string"); + this.assertNull(req.getResponseHeader('invalidheader'), "invalid header should return `null`"); + this.assertEquals("GitHub.com", req.getResponseHeader('Server'), "Server header should be GitHub.com"); + this.assertEquals('{"id": 1}', req.response); + this.assertEquals('{"id": 1}', req.responseText); +}); + +test("Test JSON request", function() { + var req = new XMLHttpRequest(); + var state = req.readyState; + + req.responseType = "json"; + req.open("GET", "https://gist.githubusercontent.com/huffman/33cc618fec183d1bccd0/raw/test.json", false); + req.send(); + + this.assertEquals(req.DONE, req.readyState, "readyState should be DONE"); + this.assertEquals(200, req.status, "status should be `200`"); + this.assertEquals(0, req.errorCode); + this.assertEquals("OK", req.statusText, "statusText should be `OK`"); + this.assertNotEquals("", req.getAllResponseHeaders(), "headers should no longer be empty string"); + this.assertNull(req.getResponseHeader('invalidheader'), "invalid header should return `null`"); + this.assertEquals("GitHub.com", req.getResponseHeader('Server'), "Server header should be GitHub.com"); + this.assertHasProperty('id', req.response); + this.assertEquals(1, req.response.id); + this.assertEquals('{"id": 1}', req.responseText); +}); + +test("Test Bad URL", function() { + var req = new XMLHttpRequest(); + var state = req.readyState; + + req.open("POST", "hifi://domain/path", false); + req.send(); + + this.assertEquals(req.DONE, req.readyState, "readyState should be DONE"); + this.assertNotEquals(0, req.errorCode); +}); + +test("Test Bad Method Error", function() { + var req = new XMLHttpRequest(); + var state = req.readyState; + + req.open("POST", "https://www.google.com", false); + + req.send("randomdata"); + + this.assertEquals(req.DONE, req.readyState, "readyState should be DONE"); + this.assertEquals(405, req.status); + this.assertEquals(202, req.errorCode); + + req.open("POST", "https://www.google.com", false) + req.send(); + + this.assertEquals(req.DONE, req.readyState, "readyState should be DONE"); + this.assertEquals(405, req.status); + this.assertEquals(202, req.errorCode); +}); + +test("Test abort", function() { + var req = new XMLHttpRequest(); + var state = req.readyState; + + req.open("POST", "https://www.google.com", true) + req.send(); + req.abort(); + + this.assertEquals(0, req.status); + this.assertEquals(0, req.errorCode); +}); + +test("Test timeout", function() { + var req = new XMLHttpRequest(); + var state = req.readyState; + var timedOut = false; + + req.ontimeout = function() { + timedOut = true; + }; + + req.open("POST", "https://gist.githubusercontent.com/huffman/33cc618fec183d1bccd0/raw/test.json", false) + req.timeout = 1; + req.send(); + + this.assertEquals(true, timedOut, "request should have timed out"); + this.assertEquals(req.DONE, req.readyState, "readyState should be DONE"); + this.assertEquals(0, req.status, "status should be `0`"); + this.assertEquals(4, req.errorCode, "4 is the timeout error code for QNetworkReply::NetworkError"); +}); From 5a7b133d2556bae5b9620e67b219c3e692a707a8 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 6 May 2014 11:38:12 -0700 Subject: [PATCH 04/20] Fix dates in XMLHttpRequest js files --- examples/Test.js | 2 +- examples/streetAreaExample.js | 2 +- examples/testXMLHttpRequest.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/Test.js b/examples/Test.js index c56c7ebdc1..056ec3cbbf 100644 --- a/examples/Test.js +++ b/examples/Test.js @@ -2,7 +2,7 @@ // Test.js // examples // -// Created by Ryan Huffman on 5/4//14 +// Created by Ryan Huffman on 5/4/14 // Copyright 2014 High Fidelity, Inc. // // This provides very basic unit testing functionality. diff --git a/examples/streetAreaExample.js b/examples/streetAreaExample.js index 5e92753689..deb10dd65a 100644 --- a/examples/streetAreaExample.js +++ b/examples/streetAreaExample.js @@ -2,7 +2,7 @@ // streetAreaExample.js // examples // -// Created by Ryan Huffman on 5/4//14 +// Created by Ryan Huffman on 5/4/14 // Copyright 2014 High Fidelity, Inc. // // This is an example script showing how to load JSON data using XMLHttpRequest. diff --git a/examples/testXMLHttpRequest.js b/examples/testXMLHttpRequest.js index 6471b2fdeb..421eb458e4 100644 --- a/examples/testXMLHttpRequest.js +++ b/examples/testXMLHttpRequest.js @@ -2,7 +2,7 @@ // testXMLHttpRequest.js // examples // -// Created by Ryan Huffman on 5/4//14 +// Created by Ryan Huffman on 5/4/14 // Copyright 2014 High Fidelity, Inc. // // XMLHttpRequest Tests From f3305a51e28047feaad47b43bac1ea9735af6200 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 6 May 2014 13:09:49 -0700 Subject: [PATCH 05/20] Remove XMLHttpRequestClass::escapeJavascriptString --- libraries/script-engine/src/XMLHttpRequestClass.h | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/script-engine/src/XMLHttpRequestClass.h b/libraries/script-engine/src/XMLHttpRequestClass.h index b1b33e4cc6..bff88d91a9 100644 --- a/libraries/script-engine/src/XMLHttpRequestClass.h +++ b/libraries/script-engine/src/XMLHttpRequestClass.h @@ -62,7 +62,6 @@ public: int getDone() const { return DONE; }; static QScriptValue constructor(QScriptContext* context, QScriptEngine* engine); - static QString escapeJavascriptString(const QString& jsString); int getTimeout() const { return _timeout; } void setTimeout(int timeout) { _timeout = timeout; } From debd76b2cbb41b1ffef4000d7c13945314baf0d5 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 13 May 2014 10:38:43 -0700 Subject: [PATCH 06/20] use sheet window modality so OAuth window doesn't take over full screen --- interface/src/ui/OAuthWebViewHandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/ui/OAuthWebViewHandler.cpp b/interface/src/ui/OAuthWebViewHandler.cpp index b3b914bd64..83d900cd5c 100644 --- a/interface/src/ui/OAuthWebViewHandler.cpp +++ b/interface/src/ui/OAuthWebViewHandler.cpp @@ -59,7 +59,7 @@ void OAuthWebViewHandler::displayWebviewForAuthorizationURL(const QUrl& authoriz _activeWebView = new QWebView; // keep the window on top and delete it when it closes - _activeWebView->setWindowFlags(Qt::WindowStaysOnTopHint); + _activeWebView->setWindowFlags(Qt::Sheet | Qt::WindowStaysOnTopHint); _activeWebView->setAttribute(Qt::WA_DeleteOnClose); qDebug() << "Displaying QWebView for OAuth authorization at" << authorizationURL.toString(); From da7081300291c6179d7325c5ad58606d861ad996 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Tue, 13 May 2014 15:45:24 -0700 Subject: [PATCH 07/20] On Windows, Visage takes the folder containing the license file, not the license file itself. --- interface/src/devices/Visage.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/interface/src/devices/Visage.cpp b/interface/src/devices/Visage.cpp index a467d2d4a8..8173519478 100644 --- a/interface/src/devices/Visage.cpp +++ b/interface/src/devices/Visage.cpp @@ -41,7 +41,11 @@ Visage::Visage() : _headOrigin(DEFAULT_HEAD_ORIGIN) { #ifdef HAVE_VISAGE +#ifdef WIN32 + QByteArray licensePath = Application::resourcesPath().toLatin1() + "visage"; +#else QByteArray licensePath = Application::resourcesPath().toLatin1() + "visage/license.vlc"; +#endif initializeLicenseManager(licensePath.data()); _tracker = new VisageTracker2(Application::resourcesPath().toLatin1() + "visage/tracker.cfg"); _data = new FaceData(); From 19404fe0e5238c6315c5e0d16097d29385381caf Mon Sep 17 00:00:00 2001 From: Kai Ludwig Date: Wed, 14 May 2014 07:10:31 +0200 Subject: [PATCH 08/20] Changed start domain to sandbox. Changed start location to xyz: 6270, 211, 6000. goHome behaviour is unchanged and will still just go to the start location keeping the currently select domain. --- interface/src/avatar/Avatar.h | 7 +++---- libraries/networking/src/DomainHandler.h | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/interface/src/avatar/Avatar.h b/interface/src/avatar/Avatar.h index 289a0500d0..c2a8af55b2 100755 --- a/interface/src/avatar/Avatar.h +++ b/interface/src/avatar/Avatar.h @@ -54,10 +54,9 @@ enum ScreenTintLayer { NUM_SCREEN_TINT_LAYERS }; -// Where one's own Avatar begins in the world (will be overwritten if avatar data file is found) -// this is basically in the center of the ground plane. Slightly adjusted. This was asked for by -// Grayson as he's building a street around here for demo dinner 2 -const glm::vec3 START_LOCATION(0.485f * TREE_SCALE, 0.0f, 0.5f * TREE_SCALE); +// Where one's own Avatar begins in the world (will be overwritten if avatar data file is found). +// This is the start location in the Sandbox (xyz: 6270, 211, 6000). +const glm::vec3 START_LOCATION(0.38269043f * TREE_SCALE, 0.01287842f * TREE_SCALE, 0.36621094f * TREE_SCALE); class Texture; diff --git a/libraries/networking/src/DomainHandler.h b/libraries/networking/src/DomainHandler.h index b78b8875c4..599f6d4a0f 100644 --- a/libraries/networking/src/DomainHandler.h +++ b/libraries/networking/src/DomainHandler.h @@ -21,7 +21,7 @@ #include "DTLSClientSession.h" #include "HifiSockAddr.h" -const QString DEFAULT_DOMAIN_HOSTNAME = "alpha.highfidelity.io"; +const QString DEFAULT_DOMAIN_HOSTNAME = "sandbox.highfidelity.io"; const unsigned short DEFAULT_DOMAIN_SERVER_PORT = 40102; const unsigned short DEFAULT_DOMAIN_SERVER_DTLS_PORT = 40103; From d59bedfa96a1efaab3011ad18697ae71788f5a0f Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 13 May 2014 22:25:08 -0700 Subject: [PATCH 09/20] Fix running scripts not properly updated when done programmatically Add a slot to Application to receive ScriptEngine::finished signals. Notify the Running scripts widget of stopped scripts so it can properly move them to the recent scripts list. --- interface/src/Application.cpp | 16 ++++++++++------ interface/src/Application.h | 1 + interface/src/ui/RunningScriptsWidget.cpp | 9 ++++----- interface/src/ui/RunningScriptsWidget.h | 1 + 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 8858b6d324..ab8d69c319 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3405,6 +3405,8 @@ ScriptEngine* Application::loadScript(const QString& scriptName, bool loadScript scriptEngine->registerGlobalObject("Clipboard", clipboardScriptable); connect(scriptEngine, SIGNAL(finished(const QString&)), clipboardScriptable, SLOT(deleteLater())); + connect(scriptEngine, SIGNAL(finished(const QString&)), this, SLOT(scriptFinished(const QString&))); + scriptEngine->registerGlobalObject("Overlays", &_overlays); QScriptValue windowValue = scriptEngine->registerGlobalObject("Window", WindowScriptingInterface::getInstance()); @@ -3447,6 +3449,14 @@ ScriptEngine* Application::loadScript(const QString& scriptName, bool loadScript return scriptEngine; } +void Application::scriptFinished(const QString &scriptName) { + if (_scriptEnginesHash.remove(scriptName)) { + _runningScriptsWidget->scriptStopped(scriptName); + _runningScriptsWidget->setRunningScripts(getRunningScripts()); + bumpSettings(); + } +} + void Application::stopAllScripts(bool restart) { // stops all current running scripts for (QHash::const_iterator it = _scriptEnginesHash.constBegin(); @@ -3457,18 +3467,12 @@ void Application::stopAllScripts(bool restart) { it.value()->stop(); qDebug() << "stopping script..." << it.key(); } - _scriptEnginesHash.clear(); - _runningScriptsWidget->setRunningScripts(getRunningScripts()); - bumpSettings(); } void Application::stopScript(const QString &scriptName) { if (_scriptEnginesHash.contains(scriptName)) { _scriptEnginesHash.value(scriptName)->stop(); qDebug() << "stopping script..." << scriptName; - _scriptEnginesHash.remove(scriptName); - _runningScriptsWidget->setRunningScripts(getRunningScripts()); - bumpSettings(); } } diff --git a/interface/src/Application.h b/interface/src/Application.h index 67cf7dad44..174ac61c06 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -292,6 +292,7 @@ public slots: void toggleLogDialog(); void initAvatarAndViewFrustum(); ScriptEngine* loadScript(const QString& fileNameString, bool loadScriptFromEditor = false); + void scriptFinished(const QString& scriptName); void stopAllScripts(bool restart = false); void stopScript(const QString& scriptName); void reloadAllScripts(); diff --git a/interface/src/ui/RunningScriptsWidget.cpp b/interface/src/ui/RunningScriptsWidget.cpp index 61241f71fb..328974dc9d 100644 --- a/interface/src/ui/RunningScriptsWidget.cpp +++ b/interface/src/ui/RunningScriptsWidget.cpp @@ -157,6 +157,10 @@ void RunningScriptsWidget::paintEvent(QPaintEvent* event) { painter.end(); } +void RunningScriptsWidget::scriptStopped(const QString& scriptName) { + _recentlyLoadedScripts.prepend(scriptName); +} + void RunningScriptsWidget::stopScript(int row, int column) { if (column == 1) { // make sure the user has clicked on the close icon _lastStoppedScript = _runningScriptsTable->item(row, 0)->toolTip(); @@ -169,11 +173,6 @@ void RunningScriptsWidget::loadScript(int row, int column) { } void RunningScriptsWidget::allScriptsStopped() { - QStringList list = Application::getInstance()->getRunningScripts(); - for (int i = 0; i < list.size(); ++i) { - _recentlyLoadedScripts.prepend(list.at(i)); - } - Application::getInstance()->stopAllScripts(); } diff --git a/interface/src/ui/RunningScriptsWidget.h b/interface/src/ui/RunningScriptsWidget.h index ad310c4ed4..14a1f4a58e 100644 --- a/interface/src/ui/RunningScriptsWidget.h +++ b/interface/src/ui/RunningScriptsWidget.h @@ -36,6 +36,7 @@ protected: virtual void paintEvent(QPaintEvent* event); public slots: + void scriptStopped(const QString& scriptName); void setBoundary(const QRect& rect); private slots: From b01b14485491fcb3962d75839657c9cfc24c4b15 Mon Sep 17 00:00:00 2001 From: Kai Ludwig Date: Wed, 14 May 2014 07:36:27 +0200 Subject: [PATCH 10/20] No more hand movement when clicking with the mouse. --- interface/src/avatar/MyAvatar.cpp | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 36c51dc9fd..20e4bcc44e 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -137,15 +137,8 @@ void MyAvatar::simulate(float deltaTime) { Application::getInstance()->getCamera()->setScale(scale); } - // update the movement of the hand and process handshaking with other avatars... - bool pointing = false; - if (_mousePressed) { - _handState = HAND_STATE_GRASPING; - } else if (pointing) { - _handState = HAND_STATE_POINTING; - } else { - _handState = HAND_STATE_NULL; - } + // no extra movement of the hand here any more ... + _handState = HAND_STATE_NULL; updateOrientation(deltaTime); From 8247e5a55277e4361af4fd3663dfb944f637033f Mon Sep 17 00:00:00 2001 From: Stojce Slavkovski Date: Wed, 14 May 2014 17:25:40 +0200 Subject: [PATCH 11/20] added discourse key in shift operators --- libraries/networking/src/DataServerAccountInfo.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/networking/src/DataServerAccountInfo.cpp b/libraries/networking/src/DataServerAccountInfo.cpp index a9522148a8..0fdb5ff4b1 100644 --- a/libraries/networking/src/DataServerAccountInfo.cpp +++ b/libraries/networking/src/DataServerAccountInfo.cpp @@ -76,11 +76,11 @@ void DataServerAccountInfo::setDiscourseApiKey(const QString& discourseApiKey) { } QDataStream& operator<<(QDataStream &out, const DataServerAccountInfo& info) { - out << info._accessToken << info._username << info._xmppPassword; + out << info._accessToken << info._username << info._xmppPassword << info._discourseApiKey; return out; } QDataStream& operator>>(QDataStream &in, DataServerAccountInfo& info) { - in >> info._accessToken >> info._username >> info._xmppPassword; + in >> info._accessToken >> info._username >> info._xmppPassword >> info._discourseApiKey; return in; } From d2d9ca878884c3e097aab36f34ea3e356c74b368 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Wed, 14 May 2014 09:04:59 -0700 Subject: [PATCH 12/20] optimization: only compute baseTransform once --- interface/src/renderer/Model.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/renderer/Model.cpp b/interface/src/renderer/Model.cpp index f46fd48beb..0c688865f3 100644 --- a/interface/src/renderer/Model.cpp +++ b/interface/src/renderer/Model.cpp @@ -128,6 +128,7 @@ QVector Model::createJointStates(const FBXGeometry& geometry) jointIsSet.fill(false, numJoints); int numJointsSet = 0; int lastNumJointsSet = -1; + glm::mat4 baseTransform = glm::mat4_cast(_rotation) * glm::scale(_scale) * glm::translate(_offset); while (numJointsSet < numJoints && numJointsSet != lastNumJointsSet) { lastNumJointsSet = numJointsSet; for (int i = 0; i < numJoints; ++i) { @@ -138,7 +139,6 @@ QVector Model::createJointStates(const FBXGeometry& geometry) const FBXJoint& joint = geometry.joints[i]; int parentIndex = joint.parentIndex; if (parentIndex == -1) { - glm::mat4 baseTransform = glm::mat4_cast(_rotation) * glm::scale(_scale) * glm::translate(_offset); glm::quat combinedRotation = joint.preRotation * state.rotation * joint.postRotation; state.transform = baseTransform * geometry.offset * glm::translate(state.translation) * joint.preTransform * glm::mat4_cast(combinedRotation) * joint.postTransform; From 366e9c7d3452cbed0cc78edbd59463c8a615b64f Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Wed, 14 May 2014 09:05:54 -0700 Subject: [PATCH 13/20] PalmDataA::getPalmDirection --> getNormal() --- interface/src/avatar/Avatar.cpp | 2 +- interface/src/avatar/Hand.cpp | 3 +-- interface/src/scripting/ControllerScriptingInterface.cpp | 2 +- libraries/avatars/src/HandData.cpp | 2 +- libraries/avatars/src/HandData.h | 2 +- 5 files changed, 5 insertions(+), 6 deletions(-) diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 2bd0bbbc6d..20f6275441 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -622,7 +622,7 @@ bool Avatar::findParticleCollisions(const glm::vec3& particleCenter, float parti glm::vec3 fingerAxis = palm->getFingerDirection(); glm::vec3 diskCenter = handPosition + HAND_PADDLE_OFFSET * fingerAxis; - glm::vec3 diskNormal = palm->getPalmDirection(); + glm::vec3 diskNormal = palm->getNormal(); const float DISK_THICKNESS = 0.08f; // collide against the disk diff --git a/interface/src/avatar/Hand.cpp b/interface/src/avatar/Hand.cpp index 78eab424ab..ee7a633a54 100644 --- a/interface/src/avatar/Hand.cpp +++ b/interface/src/avatar/Hand.cpp @@ -23,7 +23,6 @@ using namespace std; -const float FINGERTIP_COLLISION_RADIUS = 0.01f; const float PALM_COLLISION_RADIUS = 0.03f; @@ -201,7 +200,7 @@ void Hand::renderHandTargets(bool isMine) { glm::vec3 root = palm.getPosition(); Avatar::renderJointConnectingCone(root, tip, PALM_FINGER_ROD_RADIUS, PALM_FINGER_ROD_RADIUS); // Render sphere at palm/finger root - glm::vec3 offsetFromPalm = root + palm.getPalmDirection() * PALM_DISK_THICKNESS; + glm::vec3 offsetFromPalm = root + palm.getNormal() * PALM_DISK_THICKNESS; Avatar::renderJointConnectingCone(root, offsetFromPalm, PALM_DISK_RADIUS, 0.0f); glPushMatrix(); glTranslatef(root.x, root.y, root.z); diff --git a/interface/src/scripting/ControllerScriptingInterface.cpp b/interface/src/scripting/ControllerScriptingInterface.cpp index 5e58ac66ea..58a08066d6 100644 --- a/interface/src/scripting/ControllerScriptingInterface.cpp +++ b/interface/src/scripting/ControllerScriptingInterface.cpp @@ -198,7 +198,7 @@ glm::vec3 ControllerScriptingInterface::getSpatialControlNormal(int controlIndex if (palmData) { switch (controlOfPalm) { case PALM_SPATIALCONTROL: - return palmData->getPalmDirection(); + return palmData->getNormal(); case TIP_SPATIALCONTROL: return palmData->getFingerDirection(); } diff --git a/libraries/avatars/src/HandData.cpp b/libraries/avatars/src/HandData.cpp index bd366f020a..0105145466 100644 --- a/libraries/avatars/src/HandData.cpp +++ b/libraries/avatars/src/HandData.cpp @@ -120,7 +120,7 @@ glm::vec3 PalmData::getFingerDirection() const { return _owningHandData->localToWorldDirection(_rawRotation * LOCAL_FINGER_DIRECTION); } -glm::vec3 PalmData::getPalmDirection() const { +glm::vec3 PalmData::getNormal() const { const glm::vec3 LOCAL_PALM_DIRECTION(0.0f, -1.0f, 0.0f); return _owningHandData->localToWorldDirection(_rawRotation * LOCAL_PALM_DIRECTION); } diff --git a/libraries/avatars/src/HandData.h b/libraries/avatars/src/HandData.h index 1f2d134c43..505b1b600a 100755 --- a/libraries/avatars/src/HandData.h +++ b/libraries/avatars/src/HandData.h @@ -146,7 +146,7 @@ public: // return world-frame: glm::vec3 getFingerTipPosition() const; glm::vec3 getFingerDirection() const; - glm::vec3 getPalmDirection() const; + glm::vec3 getNormal() const; private: glm::quat _rawRotation; From 498f2843b06655028db150ea7870fde8beea6b9c Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Wed, 14 May 2014 09:06:46 -0700 Subject: [PATCH 14/20] Fix for bad hand rotations --- interface/src/avatar/SkeletonModel.cpp | 22 ++++++++-------------- interface/src/avatar/SkeletonModel.h | 3 +-- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/interface/src/avatar/SkeletonModel.cpp b/interface/src/avatar/SkeletonModel.cpp index a2e637f4e7..544f573eda 100644 --- a/interface/src/avatar/SkeletonModel.cpp +++ b/interface/src/avatar/SkeletonModel.cpp @@ -52,15 +52,12 @@ void SkeletonModel::simulate(float deltaTime, bool fullUpdate) { } else if (leftPalmIndex == rightPalmIndex) { // right hand only - applyPalmData(geometry.rightHandJointIndex, geometry.rightFingerJointIndices, geometry.rightFingertipJointIndices, - hand->getPalms()[leftPalmIndex]); + applyPalmData(geometry.rightHandJointIndex, hand->getPalms()[leftPalmIndex]); restoreLeftHandPosition(HAND_RESTORATION_RATE); } else { - applyPalmData(geometry.leftHandJointIndex, geometry.leftFingerJointIndices, geometry.leftFingertipJointIndices, - hand->getPalms()[leftPalmIndex]); - applyPalmData(geometry.rightHandJointIndex, geometry.rightFingerJointIndices, geometry.rightFingertipJointIndices, - hand->getPalms()[rightPalmIndex]); + applyPalmData(geometry.leftHandJointIndex, hand->getPalms()[leftPalmIndex]); + applyPalmData(geometry.rightHandJointIndex, hand->getPalms()[rightPalmIndex]); } } @@ -140,8 +137,7 @@ void SkeletonModel::applyHandPosition(int jointIndex, const glm::vec3& position) applyRotationDelta(jointIndex, rotationBetween(handRotation * glm::vec3(-sign, 0.0f, 0.0f), forearmVector)); } -void SkeletonModel::applyPalmData(int jointIndex, const QVector& fingerJointIndices, - const QVector& fingertipJointIndices, PalmData& palm) { +void SkeletonModel::applyPalmData(int jointIndex, PalmData& palm) { if (jointIndex == -1) { return; } @@ -152,19 +148,17 @@ void SkeletonModel::applyPalmData(int jointIndex, const QVector& fingerJoin return; } - // rotate palm to align with palm direction + // rotate palm to align with its normal (normal points out of hand's palm) glm::quat palmRotation; if (Menu::getInstance()->isOptionChecked(MenuOption::AlignForearmsWithWrists)) { getJointRotation(parentJointIndex, palmRotation, true); } else { getJointRotation(jointIndex, palmRotation, true); } - palmRotation = rotationBetween(palmRotation * geometry.palmDirection, palm.getPalmDirection()) * palmRotation; + palmRotation = rotationBetween(palmRotation * geometry.palmDirection, palm.getNormal()) * palmRotation; - // rotate forearm according to average finger direction - // NOTE: we're doing this in the avatar local frame, so we DON'T want to use Palm::getHandDirection() - // which returns the world-frame. - glm::vec3 direction = palm.getRawRotation() * glm::vec3(0.0f, 0.0f, 1.0f); + // rotate palm to align with finger direction + glm::vec3 direction = palm.getFingerDirection(); palmRotation = rotationBetween(palmRotation * glm::vec3(-sign, 0.0f, 0.0f), direction) * palmRotation; // set hand position, rotation diff --git a/interface/src/avatar/SkeletonModel.h b/interface/src/avatar/SkeletonModel.h index ee6b3b9de3..20384829ea 100644 --- a/interface/src/avatar/SkeletonModel.h +++ b/interface/src/avatar/SkeletonModel.h @@ -39,8 +39,7 @@ protected: void applyHandPosition(int jointIndex, const glm::vec3& position); - void applyPalmData(int jointIndex, const QVector& fingerJointIndices, - const QVector& fingertipJointIndices, PalmData& palm); + void applyPalmData(int jointIndex, PalmData& palm); /// Updates the state of the joint at the specified index. virtual void updateJointState(int index); From 146b9958cb0380a0cdefb7e928eb1ca7175cdf10 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 14 May 2014 09:41:13 -0700 Subject: [PATCH 15/20] Fix style issue --- interface/src/Application.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index ab8d69c319..c23804166c 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3449,7 +3449,7 @@ ScriptEngine* Application::loadScript(const QString& scriptName, bool loadScript return scriptEngine; } -void Application::scriptFinished(const QString &scriptName) { +void Application::scriptFinished(const QString& scriptName) { if (_scriptEnginesHash.remove(scriptName)) { _runningScriptsWidget->scriptStopped(scriptName); _runningScriptsWidget->setRunningScripts(getRunningScripts()); From 310f184978b4b396d698e72916b21f3187465ea4 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 14 May 2014 09:53:44 -0700 Subject: [PATCH 16/20] Add getters for onTimeout and onReadyStateChange --- libraries/script-engine/src/XMLHttpRequestClass.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libraries/script-engine/src/XMLHttpRequestClass.h b/libraries/script-engine/src/XMLHttpRequestClass.h index bff88d91a9..e94c67562a 100644 --- a/libraries/script-engine/src/XMLHttpRequestClass.h +++ b/libraries/script-engine/src/XMLHttpRequestClass.h @@ -40,8 +40,8 @@ class XMLHttpRequestClass : public QObject { Q_PROPERTY(int DONE READ getDone) // Callbacks - Q_PROPERTY(QScriptValue ontimeout WRITE setOnTimeout) - Q_PROPERTY(QScriptValue onreadystatechange WRITE setOnReadyStateChange) + Q_PROPERTY(QScriptValue ontimeout READ getOnTimeout WRITE setOnTimeout) + Q_PROPERTY(QScriptValue onreadystatechange READ getOnReadyStateChange WRITE setOnReadyStateChange) public: XMLHttpRequestClass(QScriptEngine* engine); ~XMLHttpRequestClass(); @@ -74,7 +74,9 @@ public: QScriptValue getStatus() const; QString getStatusText() const; + QScriptValue getOnTimeout() const { return _onTimeout; } void setOnTimeout(QScriptValue function) { _onTimeout = function; } + QScriptValue getOnReadyStateChange() const { return _onReadyStateChange; } void setOnReadyStateChange(QScriptValue function) { _onReadyStateChange = function; } public slots: From 02676848c605643e46789767a489701e5b8286dd Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 14 May 2014 09:58:04 -0700 Subject: [PATCH 17/20] Fix order of components in streetAreaExample.js --- examples/streetAreaExample.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/streetAreaExample.js b/examples/streetAreaExample.js index deb10dd65a..b4efd99b70 100644 --- a/examples/streetAreaExample.js +++ b/examples/streetAreaExample.js @@ -33,8 +33,8 @@ if (req.status == 200) { for (var i = 0; i < locations.length; i++) { var loc = locations[i]; var x1 = loc[1], - y1 = loc[2], - x2 = loc[3], + x2 = loc[2], + y1 = loc[3], y2 = loc[4]; userAreas.push({ username: loc[0], From bd56ab911dad4ad92cc1162b602c5e81353d8cba Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 14 May 2014 10:05:04 -0700 Subject: [PATCH 18/20] Fix bug with js print() breaking on certain characters The message text needs to be escaped before beign evaluated. --- libraries/script-engine/src/ScriptEngine.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index be97b37b46..7b09916a1a 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -49,7 +49,11 @@ static QScriptValue soundConstructor(QScriptContext* context, QScriptEngine* eng static QScriptValue debugPrint(QScriptContext* context, QScriptEngine* engine){ qDebug() << "script:print()<<" << context->argument(0).toString(); - engine->evaluate("Script.print('" + context->argument(0).toString() + "')"); + QString message = context->argument(0).toString() + .replace("\\", "\\\\") + .replace("\n", "\\n") + .replace("'", "\\'"); + engine->evaluate("Script.print('" + message + "')"); return QScriptValue(); } From c16654628a5530f4051703f739eb95741deaf9a7 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 14 May 2014 10:08:54 -0700 Subject: [PATCH 19/20] Add carriage return to escaped string in print() --- libraries/script-engine/src/ScriptEngine.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index 7b09916a1a..3427d0b19d 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -52,6 +52,7 @@ static QScriptValue debugPrint(QScriptContext* context, QScriptEngine* engine){ QString message = context->argument(0).toString() .replace("\\", "\\\\") .replace("\n", "\\n") + .replace("\r", "\\r") .replace("'", "\\'"); engine->evaluate("Script.print('" + message + "')"); return QScriptValue(); From a5c10220e6d62ddcac541893f0209c9be446eb50 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 14 May 2014 10:16:04 -0700 Subject: [PATCH 20/20] Remove _ prefix from private methods in XMLHttpRequest --- .../script-engine/src/XMLHttpRequestClass.cpp | 34 +++++++++---------- .../script-engine/src/XMLHttpRequestClass.h | 10 +++--- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/libraries/script-engine/src/XMLHttpRequestClass.cpp b/libraries/script-engine/src/XMLHttpRequestClass.cpp index 77b03db999..a81f8950fa 100644 --- a/libraries/script-engine/src/XMLHttpRequestClass.cpp +++ b/libraries/script-engine/src/XMLHttpRequestClass.cpp @@ -63,7 +63,7 @@ QString XMLHttpRequestClass::getStatusText() const { } void XMLHttpRequestClass::abort() { - _abortRequest(); + abortRequest(); } void XMLHttpRequestClass::setRequestHeader(const QString& name, const QString& value) { @@ -76,18 +76,18 @@ void XMLHttpRequestClass::requestMetaDataChanged() { // If this is a redirect, abort the current request and start a new one if (redirect.isValid() && _numRedirects < MAXIMUM_REDIRECTS) { _numRedirects++; - _abortRequest(); + abortRequest(); QUrl newUrl = _url.resolved(redirect.toUrl().toString()); _request.setUrl(newUrl); - _doSend(); + doSend(); } } void XMLHttpRequestClass::requestDownloadProgress(qint64 bytesReceived, qint64 bytesTotal) { if (_readyState == OPENED && bytesReceived > 0) { - _setReadyState(HEADERS_RECEIVED); - _setReadyState(LOADING); + setReadyState(HEADERS_RECEIVED); + setReadyState(LOADING); } } @@ -113,7 +113,7 @@ QScriptValue XMLHttpRequestClass::getResponseHeader(const QString& name) const { return QScriptValue::NullValue; } -void XMLHttpRequestClass::_setReadyState(ReadyState readyState) { +void XMLHttpRequestClass::setReadyState(ReadyState readyState) { if (readyState != _readyState) { _readyState = readyState; if (_onReadyStateChange.isFunction()) { @@ -135,7 +135,7 @@ void XMLHttpRequestClass::open(const QString& method, const QString& url, bool a } _request.setUrl(_url); _method = method; - _setReadyState(OPENED); + setReadyState(OPENED); } } @@ -150,7 +150,7 @@ void XMLHttpRequestClass::send(const QString& data) { _sendData->setData(data.toUtf8()); } - _doSend(); + doSend(); if (!_async) { QEventLoop loop; @@ -160,10 +160,10 @@ void XMLHttpRequestClass::send(const QString& data) { } } -void XMLHttpRequestClass::_doSend() { +void XMLHttpRequestClass::doSend() { _reply = _manager.sendCustomRequest(_request, _method.toLatin1(), _sendData); - _connectToReply(_reply); + connectToReply(_reply); if (_timeout > 0) { _timer.start(_timeout); @@ -175,9 +175,9 @@ void XMLHttpRequestClass::requestTimeout() { if (_onTimeout.isFunction()) { _onTimeout.call(QScriptValue::NullValue); } - _abortRequest(); + abortRequest(); _errorCode = QNetworkReply::TimeoutError; - _setReadyState(DONE); + setReadyState(DONE); emit requestComplete(); } @@ -203,29 +203,29 @@ void XMLHttpRequestClass::requestFinished() { _responseData = QScriptValue(QString(_rawResponseData.data())); } } - _setReadyState(DONE); + setReadyState(DONE); emit requestComplete(); } -void XMLHttpRequestClass::_abortRequest() { +void XMLHttpRequestClass::abortRequest() { // Disconnect from signals we don't want to receive any longer. disconnect(&_timer, SIGNAL(timeout()), this, SLOT(requestTimeout())); if (_reply) { - _disconnectFromReply(_reply); + disconnectFromReply(_reply); _reply->abort(); delete _reply; _reply = NULL; } } -void XMLHttpRequestClass::_connectToReply(QNetworkReply* reply) { +void XMLHttpRequestClass::connectToReply(QNetworkReply* reply) { connect(reply, SIGNAL(finished()), this, SLOT(requestFinished())); connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(requestError(QNetworkReply::NetworkError))); connect(reply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(requestDownloadProgress(qint64, qint64))); connect(reply, SIGNAL(metaDataChanged()), this, SLOT(requestMetaDataChanged())); } -void XMLHttpRequestClass::_disconnectFromReply(QNetworkReply* reply) { +void XMLHttpRequestClass::disconnectFromReply(QNetworkReply* reply) { disconnect(reply, SIGNAL(finished()), this, SLOT(requestFinished())); disconnect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(requestError(QNetworkReply::NetworkError))); disconnect(reply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(requestDownloadProgress(qint64, qint64))); diff --git a/libraries/script-engine/src/XMLHttpRequestClass.h b/libraries/script-engine/src/XMLHttpRequestClass.h index e94c67562a..49a952e638 100644 --- a/libraries/script-engine/src/XMLHttpRequestClass.h +++ b/libraries/script-engine/src/XMLHttpRequestClass.h @@ -93,11 +93,11 @@ signals: void requestComplete(); private: - void _setReadyState(ReadyState readyState); - void _doSend(); - void _connectToReply(QNetworkReply* reply); - void _disconnectFromReply(QNetworkReply* reply); - void _abortRequest(); + void setReadyState(ReadyState readyState); + void doSend(); + void connectToReply(QNetworkReply* reply); + void disconnectFromReply(QNetworkReply* reply); + void abortRequest(); QScriptEngine* _engine; bool _async;