Showing the changes to interface/src/scripting/LocationScriptingInterface.cpp (1 of 4 files). Show all
Unified · Split
| @@ -0,0 +1,49 @@ | ||
| 1 | +// | |
| 2 | +// LocationScriptingInterface.cpp | |
| 3 | +// interface/src/scripting | |
| 4 | +// | |
| 5 | +// Created by Ryan Huffman on 4/29/14. | |
| 6 | +// Copyright 2014 High Fidelity, Inc. | |
| 7 | +// | |
| 8 | +// Distributed under the Apache License, Version 2.0. | |
| 9 | +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html | |
| 10 | +// | |
| 11 | + | |
| 12 | +#include <glm/glm.hpp> | |
| 13 | + | |
| 14 | +#include "NodeList.h" | |
| 15 | + | |
| 16 | +#include "LocationScriptingInterface.h" | |
| 17 | + | |
| 18 | +LocationScriptingInterface* LocationScriptingInterface::getInstance() { | |
| 19 | + static LocationScriptingInterface sharedInstance; | |
| 20 | + return &sharedInstance; | |
| 21 | +} | |
| 22 | + | |
| 23 | +QString LocationScriptingInterface::getHref() { | |
| 24 | + return getProtocol() + "//" + getHostname() + getPathname(); | |
| 25 | +} | |
| 26 | + | |
| 27 | +QString LocationScriptingInterface::getPathname() { | |
| 28 | + const glm::vec3& position = Application::getInstance()->getAvatar()->getPosition(); | |
| 29 | + QString path; | |
| 30 | + path.sprintf("/%.4f,%.4f,%.4f", position.x, position.y, position.z); | |
| 31 | + return path; | |
| 32 | +} | |
| 33 | + | |
| 34 | +QString LocationScriptingInterface::getHostname() { | |
| 35 | + return NodeList::getInstance()->getDomainHandler().getHostname(); | |
| 36 | +} | |
| 37 | + | |
| 38 | +void LocationScriptingInterface::assign(const QString& url) { | |
| 39 | + QMetaObject::invokeMethod(Menu::getInstance(), "goToURL", Q_ARG(const QString&, url)); | |
| 40 | +} | |
| 41 | + | |
| 42 | +QScriptValue LocationScriptingInterface::locationGetter(QScriptContext* context, QScriptEngine* engine) { | |
| 43 | + return engine->newQObject(getInstance()); | |
| 44 | +} | |
| 45 | + | |
| 46 | +QScriptValue LocationScriptingInterface::locationSetter(QScriptContext* context, QScriptEngine* engine) { | |
| 47 | + LocationScriptingInterface::getInstance()->assign(context->argument(0).toString()); | |
| 48 | + return QScriptValue::UndefinedValue; | |
| 49 | +} | |