mirror of
https://github.com/Armored-Dragon/overte.git
synced 2025-03-11 16:13:16 +01:00
GlobalServicesScriptingInterface added, functions and properties functional
This commit is contained in:
parent
c815ee53c9
commit
cb907c1891
3 changed files with 125 additions and 2 deletions
|
@ -80,6 +80,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/MenuScriptingInterface.h"
|
#include "scripting/MenuScriptingInterface.h"
|
||||||
#include "scripting/SettingsScriptingInterface.h"
|
#include "scripting/SettingsScriptingInterface.h"
|
||||||
#include "scripting/WindowScriptingInterface.h"
|
#include "scripting/WindowScriptingInterface.h"
|
||||||
|
@ -3778,9 +3779,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
|
||||||
|
|
67
interface/src/scripting/GlobalServicesScriptingInterface.cpp
Normal file
67
interface/src/scripting/GlobalServicesScriptingInterface.cpp
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
//
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
53
interface/src/scripting/GlobalServicesScriptingInterface.h
Normal file
53
interface/src/scripting/GlobalServicesScriptingInterface.h
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
//
|
||||||
|
// 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();
|
||||||
|
public:
|
||||||
|
static GlobalServicesScriptingInterface* getInstance();
|
||||||
|
|
||||||
|
bool isConnected();
|
||||||
|
QString getMyUsername();
|
||||||
|
QStringList getOnlineUsers();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
QScriptValue chat(const QString& 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
|
Loading…
Reference in a new issue