Showing the changes to interface/src/scripting/LocationScriptingInterface.cpp (1 of 4 files). Show all
Unified · Split
| @@ -0,0 +1,52 @@ | ||
| 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 | +bool LocationScriptingInterface::isConnected() { | |
| 24 | + return NodeList::getInstance()->getDomainHandler().isConnected(); | |
| 25 | +} | |
| 26 | + | |
| 27 | +QString LocationScriptingInterface::getHref() { | |
| 28 | + return getProtocol() + "//" + getHostname() + getPathname(); | |
| 29 | +} | |
| 30 | + | |
| 31 | +QString LocationScriptingInterface::getPathname() { | |
| 32 | + MyAvatar* applicationAvatar = Application::getInstance()->getAvatar(); | |
| 33 | + return AddressManager::pathForPositionAndOrientation(applicationAvatar->getPosition(), | |
| 34 | + true, applicationAvatar->getOrientation()); | |
| 35 | +} | |
| 36 | + | |
| 37 | +QString LocationScriptingInterface::getHostname() { | |
| 38 | + return NodeList::getInstance()->getDomainHandler().getHostname(); | |
| 39 | +} | |
| 40 | + | |
| 41 | +void LocationScriptingInterface::assign(const QString& url) { | |
| 42 | + QMetaObject::invokeMethod(&AddressManager::getInstance(), "handleLookupString", Q_ARG(const QString&, url)); | |
| 43 | +} | |
| 44 | + | |
| 45 | +QScriptValue LocationScriptingInterface::locationGetter(QScriptContext* context, QScriptEngine* engine) { | |
| 46 | + return engine->newQObject(getInstance()); | |
| 47 | +} | |
| 48 | + | |
| 49 | +QScriptValue LocationScriptingInterface::locationSetter(QScriptContext* context, QScriptEngine* engine) { | |
| 50 | + LocationScriptingInterface::getInstance()->assign(context->argument(0).toString()); | |
| 51 | + return QScriptValue::UndefinedValue; | |
| 52 | +} | |