mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 16:14:35 +02:00
Merge branch 'master' of https://github.com/highfidelity/hifi into deference
This commit is contained in:
commit
3d48a5b872
12 changed files with 331 additions and 29 deletions
57
examples/globalServicesExample.js
Normal file
57
examples/globalServicesExample.js
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
//
|
||||||
|
// globalServicesExample.js
|
||||||
|
// examples
|
||||||
|
//
|
||||||
|
// Created by Thijs Wenker on 9/12/14.
|
||||||
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Example usage of the GlobalServices object. You could use it to make your own chatbox.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
function onConnected() {
|
||||||
|
if (GlobalServices.onlineUsers.length > 0) {
|
||||||
|
sendMessageForm()
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Script.setTimeout(function() { sendMessageForm(); }, 5000);
|
||||||
|
}
|
||||||
|
|
||||||
|
function onDisconnected(reason) {
|
||||||
|
switch(reason) {
|
||||||
|
case "logout":
|
||||||
|
Window.alert("logged out!");
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onOnlineUsersChanged(users) {
|
||||||
|
print(users);
|
||||||
|
}
|
||||||
|
|
||||||
|
function onIncommingMessage(user, message) {
|
||||||
|
print(user + ": " + message);
|
||||||
|
if (message === "hello") {
|
||||||
|
GlobalServices.chat("hello, @" + user + "!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function sendMessageForm() {
|
||||||
|
var form =
|
||||||
|
[
|
||||||
|
{ label: "To:", options: ["(noone)"].concat(GlobalServices.onlineUsers) },
|
||||||
|
{ label: "Message:", value: "Enter message here" }
|
||||||
|
];
|
||||||
|
if (Window.form("Send message on public chat", form)) {
|
||||||
|
GlobalServices.chat(form[0].value == "(noone)" ? form[1].value : "@" + form[0].value + ", " + form[1].value);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GlobalServices.connected.connect(onConnected);
|
||||||
|
GlobalServices.disconnected.connect(onDisconnected);
|
||||||
|
GlobalServices.onlineUsersChanged.connect(onOnlineUsersChanged);
|
||||||
|
GlobalServices.incomingMessage.connect(onIncommingMessage);
|
|
@ -81,6 +81,7 @@
|
||||||
#include "scripting/AccountScriptingInterface.h"
|
#include "scripting/AccountScriptingInterface.h"
|
||||||
#include "scripting/AudioDeviceScriptingInterface.h"
|
#include "scripting/AudioDeviceScriptingInterface.h"
|
||||||
#include "scripting/ClipboardScriptingInterface.h"
|
#include "scripting/ClipboardScriptingInterface.h"
|
||||||
|
#include "scripting/GlobalServicesScriptingInterface.h"
|
||||||
#include "scripting/LocationScriptingInterface.h"
|
#include "scripting/LocationScriptingInterface.h"
|
||||||
#include "scripting/MenuScriptingInterface.h"
|
#include "scripting/MenuScriptingInterface.h"
|
||||||
#include "scripting/SettingsScriptingInterface.h"
|
#include "scripting/SettingsScriptingInterface.h"
|
||||||
|
@ -290,6 +291,15 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
|
||||||
|
|
||||||
// once the event loop has started, check and signal for an access token
|
// once the event loop has started, check and signal for an access token
|
||||||
QMetaObject::invokeMethod(&accountManager, "checkAndSignalForAccessToken", Qt::QueuedConnection);
|
QMetaObject::invokeMethod(&accountManager, "checkAndSignalForAccessToken", Qt::QueuedConnection);
|
||||||
|
|
||||||
|
AddressManager& addressManager = AddressManager::getInstance();
|
||||||
|
|
||||||
|
// connect to the domainChangeRequired signal on AddressManager
|
||||||
|
connect(&addressManager, &AddressManager::possibleDomainChangeRequired,
|
||||||
|
this, &Application::changeDomainHostname);
|
||||||
|
|
||||||
|
// when -url in command line, teleport to location
|
||||||
|
addressManager.handleLookupString(getCmdOption(argc, constArgv, "-url"));
|
||||||
|
|
||||||
_settings = new QSettings(this);
|
_settings = new QSettings(this);
|
||||||
_numChangedSettings = 0;
|
_numChangedSettings = 0;
|
||||||
|
@ -403,15 +413,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
|
||||||
|
|
||||||
connect(_window, &MainWindow::windowGeometryChanged,
|
connect(_window, &MainWindow::windowGeometryChanged,
|
||||||
_runningScriptsWidget, &RunningScriptsWidget::setBoundary);
|
_runningScriptsWidget, &RunningScriptsWidget::setBoundary);
|
||||||
|
|
||||||
AddressManager& addressManager = AddressManager::getInstance();
|
|
||||||
|
|
||||||
// connect to the domainChangeRequired signal on AddressManager
|
|
||||||
connect(&addressManager, &AddressManager::possibleDomainChangeRequired,
|
|
||||||
this, &Application::changeDomainHostname);
|
|
||||||
|
|
||||||
// when -url in command line, teleport to location
|
|
||||||
addressManager.handleLookupString(getCmdOption(argc, constArgv, "-url"));
|
|
||||||
|
|
||||||
// call the OAuthWebviewHandler static getter so that its instance lives in our thread
|
// call the OAuthWebviewHandler static getter so that its instance lives in our thread
|
||||||
OAuthWebViewHandler::getInstance();
|
OAuthWebViewHandler::getInstance();
|
||||||
|
@ -810,6 +811,7 @@ bool Application::event(QEvent* event) {
|
||||||
|
|
||||||
// handle custom URL
|
// handle custom URL
|
||||||
if (event->type() == QEvent::FileOpen) {
|
if (event->type() == QEvent::FileOpen) {
|
||||||
|
|
||||||
QFileOpenEvent* fileEvent = static_cast<QFileOpenEvent*>(event);
|
QFileOpenEvent* fileEvent = static_cast<QFileOpenEvent*>(event);
|
||||||
|
|
||||||
if (!fileEvent->url().isEmpty()) {
|
if (!fileEvent->url().isEmpty()) {
|
||||||
|
@ -3836,9 +3838,11 @@ ScriptEngine* Application::loadScript(const QString& scriptFilename, bool isUser
|
||||||
scriptEngine->registerGlobalObject("AudioReflector", &_audioReflector);
|
scriptEngine->registerGlobalObject("AudioReflector", &_audioReflector);
|
||||||
scriptEngine->registerGlobalObject("Account", AccountScriptingInterface::getInstance());
|
scriptEngine->registerGlobalObject("Account", AccountScriptingInterface::getInstance());
|
||||||
scriptEngine->registerGlobalObject("Metavoxels", &_metavoxels);
|
scriptEngine->registerGlobalObject("Metavoxels", &_metavoxels);
|
||||||
|
|
||||||
|
scriptEngine->registerGlobalObject("GlobalServices", GlobalServicesScriptingInterface::getInstance());
|
||||||
|
|
||||||
scriptEngine->registerGlobalObject("AvatarManager", &_avatarManager);
|
scriptEngine->registerGlobalObject("AvatarManager", &_avatarManager);
|
||||||
|
|
||||||
#ifdef HAVE_RTMIDI
|
#ifdef HAVE_RTMIDI
|
||||||
scriptEngine->registerGlobalObject("MIDI", &MIDIManager::getInstance());
|
scriptEngine->registerGlobalObject("MIDI", &MIDIManager::getInstance());
|
||||||
#endif
|
#endif
|
||||||
|
@ -3957,11 +3961,13 @@ void Application::uploadAttachment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::openUrl(const QUrl& url) {
|
void Application::openUrl(const QUrl& url) {
|
||||||
if (url.scheme() == HIFI_URL_SCHEME) {
|
if (!url.isEmpty()) {
|
||||||
AddressManager::getInstance().handleLookupString(url.toString());
|
if (url.scheme() == HIFI_URL_SCHEME) {
|
||||||
} else {
|
AddressManager::getInstance().handleLookupString(url.toString());
|
||||||
// address manager did not handle - ask QDesktopServices to handle
|
} else {
|
||||||
QDesktopServices::openUrl(url);
|
// address manager did not handle - ask QDesktopServices to handle
|
||||||
|
QDesktopServices::openUrl(url);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -142,9 +142,14 @@ Menu::Menu() :
|
||||||
// call our toggle login function now so the menu option is setup properly
|
// call our toggle login function now so the menu option is setup properly
|
||||||
toggleLoginMenuItem();
|
toggleLoginMenuItem();
|
||||||
|
|
||||||
// connect to the appropriate slots of the AccountManager so that we can change the Login/Logout menu item
|
// connect to the appropriate signal of the AccountManager so that we can change the Login/Logout menu item
|
||||||
connect(&accountManager, &AccountManager::profileChanged, this, &Menu::toggleLoginMenuItem);
|
connect(&accountManager, &AccountManager::profileChanged, this, &Menu::toggleLoginMenuItem);
|
||||||
connect(&accountManager, &AccountManager::logoutComplete, this, &Menu::toggleLoginMenuItem);
|
connect(&accountManager, &AccountManager::logoutComplete, this, &Menu::toggleLoginMenuItem);
|
||||||
|
|
||||||
|
// connect to signal of account manager so we can tell user when the user/place they looked at is offline
|
||||||
|
AddressManager& addressManager = AddressManager::getInstance();
|
||||||
|
connect(&addressManager, &AddressManager::lookupResultIsOffline, this, &Menu::displayAddressOfflineMessage);
|
||||||
|
connect(&addressManager, &AddressManager::lookupResultIsNotFound, this, &Menu::displayAddressNotFoundMessage);
|
||||||
|
|
||||||
addDisabledActionAndSeparator(fileMenu, "Scripts");
|
addDisabledActionAndSeparator(fileMenu, "Scripts");
|
||||||
addActionToQMenuAndActionHash(fileMenu, MenuOption::LoadScript, Qt::CTRL | Qt::Key_O, appInstance, SLOT(loadDialog()));
|
addActionToQMenuAndActionHash(fileMenu, MenuOption::LoadScript, Qt::CTRL | Qt::Key_O, appInstance, SLOT(loadDialog()));
|
||||||
|
@ -1158,6 +1163,16 @@ void Menu::toggleAddressBar() {
|
||||||
sendFakeEnterEvent();
|
sendFakeEnterEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Menu::displayAddressOfflineMessage() {
|
||||||
|
QMessageBox::information(Application::getInstance()->getWindow(), "Address offline",
|
||||||
|
"That user or place is currently offline.");
|
||||||
|
}
|
||||||
|
|
||||||
|
void Menu::displayAddressNotFoundMessage() {
|
||||||
|
QMessageBox::information(Application::getInstance()->getWindow(), "Address not found",
|
||||||
|
"There is no address information for that user or place.");
|
||||||
|
}
|
||||||
|
|
||||||
void Menu::muteEnvironment() {
|
void Menu::muteEnvironment() {
|
||||||
int headerSize = numBytesForPacketHeaderGivenPacketType(PacketTypeMuteEnvironment);
|
int headerSize = numBytesForPacketHeaderGivenPacketType(PacketTypeMuteEnvironment);
|
||||||
int packetSize = headerSize + sizeof(glm::vec3) + sizeof(float);
|
int packetSize = headerSize + sizeof(glm::vec3) + sizeof(float);
|
||||||
|
|
|
@ -219,6 +219,8 @@ private slots:
|
||||||
void toggleChat();
|
void toggleChat();
|
||||||
void audioMuteToggled();
|
void audioMuteToggled();
|
||||||
void displayNameLocationResponse(const QString& errorString);
|
void displayNameLocationResponse(const QString& errorString);
|
||||||
|
void displayAddressOfflineMessage();
|
||||||
|
void displayAddressNotFoundMessage();
|
||||||
void muteEnvironment();
|
void muteEnvironment();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -61,7 +61,10 @@ Model::Model(QObject* parent) :
|
||||||
_showTrueJointTransforms(true),
|
_showTrueJointTransforms(true),
|
||||||
_lodDistance(0.0f),
|
_lodDistance(0.0f),
|
||||||
_pupilDilation(0.0f),
|
_pupilDilation(0.0f),
|
||||||
_url("http://invalid.com") {
|
_url("http://invalid.com"),
|
||||||
|
_blenderPending(false),
|
||||||
|
_blendRequired(false) {
|
||||||
|
|
||||||
// we may have been created in the network thread, but we live in the main thread
|
// we may have been created in the network thread, but we live in the main thread
|
||||||
moveToThread(Application::getInstance()->thread());
|
moveToThread(Application::getInstance()->thread());
|
||||||
}
|
}
|
||||||
|
@ -998,9 +1001,15 @@ void Model::simulateInternal(float deltaTime) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// post the blender
|
// post the blender if we're not currently waiting for one to finish
|
||||||
if (geometry.hasBlendedMeshes()) {
|
if (geometry.hasBlendedMeshes()) {
|
||||||
QThreadPool::globalInstance()->start(new Blender(this, _geometry, geometry.meshes, _blendshapeCoefficients));
|
if (_blenderPending) {
|
||||||
|
_blendRequired = true;
|
||||||
|
} else {
|
||||||
|
_blendRequired = false;
|
||||||
|
_blenderPending = true;
|
||||||
|
QThreadPool::globalInstance()->start(new Blender(this, _geometry, geometry.meshes, _blendshapeCoefficients));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1264,10 +1273,20 @@ void Model::renderJointCollisionShapes(float alpha) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Model::setBlendedVertices(const QVector<glm::vec3>& vertices, const QVector<glm::vec3>& normals) {
|
void Model::setBlendedVertices(const QVector<glm::vec3>& vertices, const QVector<glm::vec3>& normals) {
|
||||||
|
_blenderPending = false;
|
||||||
|
|
||||||
|
// start the next blender if required
|
||||||
|
const FBXGeometry& geometry = _geometry->getFBXGeometry();
|
||||||
|
if (_blendRequired) {
|
||||||
|
_blendRequired = false;
|
||||||
|
if (geometry.hasBlendedMeshes()) {
|
||||||
|
_blenderPending = true;
|
||||||
|
QThreadPool::globalInstance()->start(new Blender(this, _geometry, geometry.meshes, _blendshapeCoefficients));
|
||||||
|
}
|
||||||
|
}
|
||||||
if (_blendedVertexBuffers.isEmpty()) {
|
if (_blendedVertexBuffers.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const FBXGeometry& geometry = _geometry->getFBXGeometry();
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for (int i = 0; i < geometry.meshes.size(); i++) {
|
for (int i = 0; i < geometry.meshes.size(); i++) {
|
||||||
const FBXMesh& mesh = geometry.meshes.at(i);
|
const FBXMesh& mesh = geometry.meshes.at(i);
|
||||||
|
|
|
@ -284,6 +284,9 @@ private:
|
||||||
glm::vec4 _localLightColors[MAX_LOCAL_LIGHTS];
|
glm::vec4 _localLightColors[MAX_LOCAL_LIGHTS];
|
||||||
glm::vec4 _localLightDirections[MAX_LOCAL_LIGHTS];
|
glm::vec4 _localLightDirections[MAX_LOCAL_LIGHTS];
|
||||||
|
|
||||||
|
bool _blenderPending;
|
||||||
|
bool _blendRequired;
|
||||||
|
|
||||||
static ProgramObject _program;
|
static ProgramObject _program;
|
||||||
static ProgramObject _normalMapProgram;
|
static ProgramObject _normalMapProgram;
|
||||||
static ProgramObject _specularMapProgram;
|
static ProgramObject _specularMapProgram;
|
||||||
|
|
113
interface/src/scripting/GlobalServicesScriptingInterface.cpp
Normal file
113
interface/src/scripting/GlobalServicesScriptingInterface.cpp
Normal file
|
@ -0,0 +1,113 @@
|
||||||
|
//
|
||||||
|
// GlobalServicesScriptingInterface.cpp
|
||||||
|
// interface/src/scripting
|
||||||
|
//
|
||||||
|
// Created by Thijs Wenker on 9/10/14.
|
||||||
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "AccountManager.h"
|
||||||
|
#include "XmppClient.h"
|
||||||
|
|
||||||
|
#include "GlobalServicesScriptingInterface.h"
|
||||||
|
|
||||||
|
GlobalServicesScriptingInterface::GlobalServicesScriptingInterface() {
|
||||||
|
AccountManager& accountManager = AccountManager::getInstance();
|
||||||
|
connect(&accountManager, &AccountManager::usernameChanged, this, &GlobalServicesScriptingInterface::myUsernameChanged);
|
||||||
|
connect(&accountManager, &AccountManager::logoutComplete, this, &GlobalServicesScriptingInterface::loggedOut);
|
||||||
|
#ifdef HAVE_QXMPP
|
||||||
|
const XmppClient& xmppClient = XmppClient::getInstance();
|
||||||
|
connect(&xmppClient, &XmppClient::joinedPublicChatRoom, this, &GlobalServicesScriptingInterface::connected);
|
||||||
|
connect(&xmppClient, &XmppClient::joinedPublicChatRoom, this, &GlobalServicesScriptingInterface::onConnected);
|
||||||
|
const QXmppClient& qxmppClient = XmppClient::getInstance().getXMPPClient();
|
||||||
|
connect(&qxmppClient, &QXmppClient::messageReceived, this, &GlobalServicesScriptingInterface::messageReceived);
|
||||||
|
#endif // HAVE_QXMPP
|
||||||
|
}
|
||||||
|
|
||||||
|
GlobalServicesScriptingInterface::~GlobalServicesScriptingInterface() {
|
||||||
|
AccountManager& accountManager = AccountManager::getInstance();
|
||||||
|
disconnect(&accountManager, &AccountManager::usernameChanged, this, &GlobalServicesScriptingInterface::myUsernameChanged);
|
||||||
|
disconnect(&accountManager, &AccountManager::logoutComplete, this, &GlobalServicesScriptingInterface::loggedOut);
|
||||||
|
#ifdef HAVE_QXMPP
|
||||||
|
const XmppClient& xmppClient = XmppClient::getInstance();
|
||||||
|
disconnect(&xmppClient, &XmppClient::joinedPublicChatRoom, this, &GlobalServicesScriptingInterface::connected);
|
||||||
|
disconnect(&xmppClient, &XmppClient::joinedPublicChatRoom, this, &GlobalServicesScriptingInterface::onConnected);
|
||||||
|
const QXmppClient& qxmppClient = XmppClient::getInstance().getXMPPClient();
|
||||||
|
disconnect(&qxmppClient, &QXmppClient::messageReceived, this, &GlobalServicesScriptingInterface::messageReceived);
|
||||||
|
const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom();
|
||||||
|
disconnect(publicChatRoom, &QXmppMucRoom::participantsChanged, this, &GlobalServicesScriptingInterface::participantsChanged);
|
||||||
|
#endif // HAVE_QXMPP
|
||||||
|
}
|
||||||
|
|
||||||
|
void GlobalServicesScriptingInterface::onConnected() {
|
||||||
|
#ifdef HAVE_QXMPP
|
||||||
|
const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom();
|
||||||
|
connect(publicChatRoom, &QXmppMucRoom::participantsChanged, this, &GlobalServicesScriptingInterface::participantsChanged, Qt::UniqueConnection);
|
||||||
|
#endif // HAVE_QXMPP
|
||||||
|
}
|
||||||
|
|
||||||
|
void GlobalServicesScriptingInterface::participantsChanged() {
|
||||||
|
#ifdef HAVE_QXMPP
|
||||||
|
emit GlobalServicesScriptingInterface::onlineUsersChanged(this->getOnlineUsers());
|
||||||
|
#endif // HAVE_QXMPP
|
||||||
|
}
|
||||||
|
|
||||||
|
GlobalServicesScriptingInterface* GlobalServicesScriptingInterface::getInstance() {
|
||||||
|
static GlobalServicesScriptingInterface sharedInstance;
|
||||||
|
return &sharedInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GlobalServicesScriptingInterface::isConnected() {
|
||||||
|
#ifdef HAVE_QXMPP
|
||||||
|
return XmppClient::getInstance().getXMPPClient().isConnected();
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif // HAVE_QXMPP
|
||||||
|
}
|
||||||
|
|
||||||
|
QScriptValue GlobalServicesScriptingInterface::chat(const QString& message) {
|
||||||
|
#ifdef HAVE_QXMPP
|
||||||
|
if (XmppClient::getInstance().getXMPPClient().isConnected()) {
|
||||||
|
const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom();
|
||||||
|
QXmppMessage messageObject;
|
||||||
|
messageObject.setTo(publicChatRoom->jid());
|
||||||
|
messageObject.setType(QXmppMessage::GroupChat);
|
||||||
|
messageObject.setBody(message);
|
||||||
|
return XmppClient::getInstance().getXMPPClient().sendPacket(messageObject);
|
||||||
|
}
|
||||||
|
#endif // HAVE_QXMPP
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString GlobalServicesScriptingInterface::getMyUsername() {
|
||||||
|
return AccountManager::getInstance().getAccountInfo().getUsername();
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList GlobalServicesScriptingInterface::getOnlineUsers() {
|
||||||
|
#ifdef HAVE_QXMPP
|
||||||
|
if (XmppClient::getInstance().getXMPPClient().isConnected()) {
|
||||||
|
QStringList usernames;
|
||||||
|
const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom();
|
||||||
|
foreach(const QString& participant, XmppClient::getInstance().getPublicChatRoom()->participants()) {
|
||||||
|
usernames.append(participant.right(participant.count() - 1 - publicChatRoom->jid().count()));
|
||||||
|
}
|
||||||
|
return usernames;
|
||||||
|
}
|
||||||
|
#endif // HAVE_QXMPP
|
||||||
|
return QStringList();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GlobalServicesScriptingInterface::loggedOut() {
|
||||||
|
emit GlobalServicesScriptingInterface::disconnected(QString("logout"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void GlobalServicesScriptingInterface::messageReceived(const QXmppMessage& message) {
|
||||||
|
if (message.type() != QXmppMessage::GroupChat) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom();
|
||||||
|
emit GlobalServicesScriptingInterface::incomingMessage(message.from().right(message.from().count() - 1 - publicChatRoom->jid().count()), message.body());
|
||||||
|
}
|
60
interface/src/scripting/GlobalServicesScriptingInterface.h
Normal file
60
interface/src/scripting/GlobalServicesScriptingInterface.h
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
//
|
||||||
|
// GlobalServicesScriptingInterface.h
|
||||||
|
// interface/src/scripting
|
||||||
|
//
|
||||||
|
// Created by Thijs Wenker on 9/10/14.
|
||||||
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// 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_GlobalServicesScriptingInterface_h
|
||||||
|
#define hifi_GlobalServicesScriptingInterface_h
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QScriptContext>
|
||||||
|
#include <QScriptEngine>
|
||||||
|
#include <QScriptValue>
|
||||||
|
#include <QString>
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
|
#ifdef HAVE_QXMPP
|
||||||
|
|
||||||
|
#include <QXmppClient.h>
|
||||||
|
#include <QXmppMessage.h>
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
class GlobalServicesScriptingInterface : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(bool isConnected READ isConnected)
|
||||||
|
Q_PROPERTY(QString myUsername READ getMyUsername)
|
||||||
|
Q_PROPERTY(QStringList onlineUsers READ getOnlineUsers)
|
||||||
|
GlobalServicesScriptingInterface();
|
||||||
|
~GlobalServicesScriptingInterface();
|
||||||
|
public:
|
||||||
|
static GlobalServicesScriptingInterface* getInstance();
|
||||||
|
|
||||||
|
bool isConnected();
|
||||||
|
QString getMyUsername();
|
||||||
|
QStringList getOnlineUsers();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
QScriptValue chat(const QString& message);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void loggedOut();
|
||||||
|
void onConnected();
|
||||||
|
void participantsChanged();
|
||||||
|
void messageReceived(const QXmppMessage& message);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void connected();
|
||||||
|
void disconnected(const QString& reason);
|
||||||
|
void incomingMessage(const QString& username, const QString& message);
|
||||||
|
void onlineUsersChanged(const QStringList& usernames);
|
||||||
|
void myUsernameChanged(const QString& username);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // hifi_GlobalServicesScriptingInterface_h
|
|
@ -240,6 +240,7 @@ QScriptValue WindowScriptingInterface::doGetNonBlockingFormResult(QScriptValue a
|
||||||
if (_formResult == QDialog::Accepted) {
|
if (_formResult == QDialog::Accepted) {
|
||||||
int e = -1;
|
int e = -1;
|
||||||
int d = -1;
|
int d = -1;
|
||||||
|
int c = -1;
|
||||||
for (int i = 0; i < _form.property("length").toInt32(); ++i) {
|
for (int i = 0; i < _form.property("length").toInt32(); ++i) {
|
||||||
QScriptValue item = _form.property(i);
|
QScriptValue item = _form.property(i);
|
||||||
QScriptValue value = item.property("value");
|
QScriptValue value = item.property("value");
|
||||||
|
@ -255,6 +256,10 @@ QScriptValue WindowScriptingInterface::doGetNonBlockingFormResult(QScriptValue a
|
||||||
value = _directories.at(d)->property("path").toString();
|
value = _directories.at(d)->property("path").toString();
|
||||||
item.setProperty("directory", value);
|
item.setProperty("directory", value);
|
||||||
_form.setProperty(i, item);
|
_form.setProperty(i, item);
|
||||||
|
} else if (item.property("options").isArray()) {
|
||||||
|
c += 1;
|
||||||
|
item.setProperty("value", _combos.at(c)->currentText());
|
||||||
|
_form.setProperty(i, item);
|
||||||
} else {
|
} else {
|
||||||
e += 1;
|
e += 1;
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
|
@ -308,6 +313,7 @@ QScriptValue WindowScriptingInterface::showForm(const QString& title, QScriptVal
|
||||||
if (result == QDialog::Accepted) {
|
if (result == QDialog::Accepted) {
|
||||||
int e = -1;
|
int e = -1;
|
||||||
int d = -1;
|
int d = -1;
|
||||||
|
int c = -1;
|
||||||
for (int i = 0; i < form.property("length").toInt32(); ++i) {
|
for (int i = 0; i < form.property("length").toInt32(); ++i) {
|
||||||
QScriptValue item = form.property(i);
|
QScriptValue item = form.property(i);
|
||||||
QScriptValue value = item.property("value");
|
QScriptValue value = item.property("value");
|
||||||
|
@ -323,6 +329,10 @@ QScriptValue WindowScriptingInterface::showForm(const QString& title, QScriptVal
|
||||||
value = _directories.at(d)->property("path").toString();
|
value = _directories.at(d)->property("path").toString();
|
||||||
item.setProperty("directory", value);
|
item.setProperty("directory", value);
|
||||||
form.setProperty(i, item);
|
form.setProperty(i, item);
|
||||||
|
} else if (item.property("options").isArray()) {
|
||||||
|
c += 1;
|
||||||
|
item.setProperty("value", _combos.at(c)->currentText());
|
||||||
|
_form.setProperty(i, item);
|
||||||
} else {
|
} else {
|
||||||
e += 1;
|
e += 1;
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
|
@ -425,6 +435,15 @@ QDialog* WindowScriptingInterface::createForm(const QString& title, QScriptValue
|
||||||
|
|
||||||
} else if (item.property("type").toString() == "header") {
|
} else if (item.property("type").toString() == "header") {
|
||||||
formLayout->addRow(new QLabel(item.property("label").toString()));
|
formLayout->addRow(new QLabel(item.property("label").toString()));
|
||||||
|
} else if (item.property("options").isArray()) {
|
||||||
|
QComboBox* combo = new QComboBox();
|
||||||
|
combo->setMinimumWidth(200);
|
||||||
|
QStringList options = item.property("options").toVariant().toStringList();
|
||||||
|
for (QStringList::const_iterator it = options.begin(); it != options.end(); it += 1) {
|
||||||
|
combo->addItem(*it);
|
||||||
|
}
|
||||||
|
_combos.push_back(combo);
|
||||||
|
formLayout->addRow(new QLabel(item.property("label").toString()), combo);
|
||||||
} else {
|
} else {
|
||||||
QLineEdit* edit = new QLineEdit(item.property("value").toString());
|
QLineEdit* edit = new QLineEdit(item.property("value").toString());
|
||||||
edit->setMinimumWidth(200);
|
edit->setMinimumWidth(200);
|
||||||
|
|
|
@ -80,6 +80,7 @@ private:
|
||||||
QScriptValue _form;
|
QScriptValue _form;
|
||||||
bool _nonBlockingFormActive;
|
bool _nonBlockingFormActive;
|
||||||
int _formResult;
|
int _formResult;
|
||||||
|
QVector<QComboBox*> _combos;
|
||||||
QVector<QLineEdit*> _edits;
|
QVector<QLineEdit*> _edits;
|
||||||
QVector<QPushButton*> _directories;
|
QVector<QPushButton*> _directories;
|
||||||
};
|
};
|
||||||
|
|
|
@ -52,6 +52,8 @@ const JSONCallbackParameters& AddressManager::apiCallbackParameters() {
|
||||||
bool AddressManager::handleUrl(const QUrl& lookupUrl) {
|
bool AddressManager::handleUrl(const QUrl& lookupUrl) {
|
||||||
if (lookupUrl.scheme() == HIFI_URL_SCHEME) {
|
if (lookupUrl.scheme() == HIFI_URL_SCHEME) {
|
||||||
|
|
||||||
|
qDebug() << "Trying to go to URL" << lookupUrl.toString();
|
||||||
|
|
||||||
// there are 4 possible lookup strings
|
// there are 4 possible lookup strings
|
||||||
|
|
||||||
// 1. global place name (name of domain or place) - example: sanfrancisco
|
// 1. global place name (name of domain or place) - example: sanfrancisco
|
||||||
|
@ -59,8 +61,6 @@ bool AddressManager::handleUrl(const QUrl& lookupUrl) {
|
||||||
// 3. location string (posX,posY,posZ/eulerX,eulerY,eulerZ)
|
// 3. location string (posX,posY,posZ/eulerX,eulerY,eulerZ)
|
||||||
// 4. domain network address (IP or dns resolvable hostname)
|
// 4. domain network address (IP or dns resolvable hostname)
|
||||||
|
|
||||||
qDebug() << lookupUrl;
|
|
||||||
|
|
||||||
if (lookupUrl.isRelative()) {
|
if (lookupUrl.isRelative()) {
|
||||||
// if this is a relative path then handle it as a relative viewpoint
|
// if this is a relative path then handle it as a relative viewpoint
|
||||||
handleRelativeViewpoint(lookupUrl.path());
|
handleRelativeViewpoint(lookupUrl.path());
|
||||||
|
@ -86,12 +86,14 @@ bool AddressManager::handleUrl(const QUrl& lookupUrl) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddressManager::handleLookupString(const QString& lookupString) {
|
void AddressManager::handleLookupString(const QString& lookupString) {
|
||||||
// we've verified that this is a valid hifi URL - hand it off to handleLookupString
|
if (!lookupString.isEmpty()) {
|
||||||
QString sanitizedString = lookupString;
|
// make this a valid hifi URL and handle it off to handleUrl
|
||||||
const QRegExp HIFI_SCHEME_REGEX = QRegExp(HIFI_URL_SCHEME + ":\\/{1,2}", Qt::CaseInsensitive);
|
QString sanitizedString = lookupString;
|
||||||
sanitizedString = sanitizedString.remove(HIFI_SCHEME_REGEX);
|
const QRegExp HIFI_SCHEME_REGEX = QRegExp(HIFI_URL_SCHEME + ":\\/{1,2}", Qt::CaseInsensitive);
|
||||||
|
sanitizedString = sanitizedString.remove(HIFI_SCHEME_REGEX);
|
||||||
handleUrl(QUrl(HIFI_URL_SCHEME + "://" + sanitizedString));
|
|
||||||
|
handleUrl(QUrl(HIFI_URL_SCHEME + "://" + sanitizedString));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddressManager::handleAPIResponse(const QJsonObject &jsonObject) {
|
void AddressManager::handleAPIResponse(const QJsonObject &jsonObject) {
|
||||||
|
@ -141,6 +143,10 @@ void AddressManager::handleAPIResponse(const QJsonObject &jsonObject) {
|
||||||
|
|
||||||
void AddressManager::handleAPIError(QNetworkReply& errorReply) {
|
void AddressManager::handleAPIError(QNetworkReply& errorReply) {
|
||||||
qDebug() << "AddressManager API error -" << errorReply.error() << "-" << errorReply.errorString();
|
qDebug() << "AddressManager API error -" << errorReply.error() << "-" << errorReply.errorString();
|
||||||
|
|
||||||
|
if (errorReply.error() == QNetworkReply::ContentNotFoundError) {
|
||||||
|
emit lookupResultIsNotFound();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString GET_PLACE = "/api/v1/places/%1";
|
const QString GET_PLACE = "/api/v1/places/%1";
|
||||||
|
|
|
@ -38,6 +38,7 @@ public slots:
|
||||||
void goToUser(const QString& username);
|
void goToUser(const QString& username);
|
||||||
signals:
|
signals:
|
||||||
void lookupResultIsOffline();
|
void lookupResultIsOffline();
|
||||||
|
void lookupResultIsNotFound();
|
||||||
void possibleDomainChangeRequired(const QString& newHostname);
|
void possibleDomainChangeRequired(const QString& newHostname);
|
||||||
void locationChangeRequired(const glm::vec3& newPosition, bool hasOrientationChange, const glm::vec3& newOrientation);
|
void locationChangeRequired(const glm::vec3& newPosition, bool hasOrientationChange, const glm::vec3& newOrientation);
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in a new issue