History

GlobalServicesScriptingInterface added, functions and properties functional

Thijs Wenker committed 12 years ago

Commit cb907c11 parent c815ee53 files · +125 −2Browse files

Showing the changes to interface/src/scripting/GlobalServicesScriptingInterface.cpp (1 of 3 files). Show all

Unified · Split

interface/src/scripting/GlobalServicesScriptingInterface.cpp+67−0
@@ -0,0 +1,67 @@
1+//
2+// GlobalServicesScriptingInterface.cpp
3+// interface/src/scripting
4+//
5+// Created by Thijs Wenker on 9/10/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 "AccountManager.h"
13+#include "XmppClient.h"
14+
15+#include "GlobalServicesScriptingInterface.h"
16+
17+GlobalServicesScriptingInterface::GlobalServicesScriptingInterface() {
18+ AccountManager& accountManager = AccountManager::getInstance();
19+ connect(&accountManager, &AccountManager::usernameChanged, this,
20+ &GlobalServicesScriptingInterface::myUsernameChanged);
21+
22+}
23+
24+GlobalServicesScriptingInterface* GlobalServicesScriptingInterface::getInstance() {
25+ static GlobalServicesScriptingInterface sharedInstance;
26+ return &sharedInstance;
27+}
28+
29+bool GlobalServicesScriptingInterface::isConnected() {
30+#ifdef HAVE_QXMPP
31+ return XmppClient::getInstance().getXMPPClient().isConnected();
32+#else
33+ return false;
34+#endif // HAVE_QXMPP
35+}
36+
37+QScriptValue GlobalServicesScriptingInterface::chat(const QString& message) {
38+#ifdef HAVE_QXMPP
39+ if (XmppClient::getInstance().getXMPPClient().isConnected()) {
40+ const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom();
41+ QXmppMessage messageObject;
42+ messageObject.setTo(publicChatRoom->jid());
43+ messageObject.setType(QXmppMessage::GroupChat);
44+ messageObject.setBody(message);
45+ return XmppClient::getInstance().getXMPPClient().sendPacket(messageObject);
46+ }
47+#endif // HAVE_QXMPP
48+ return false;
49+}
50+
51+QString GlobalServicesScriptingInterface::getMyUsername() {
52+ return AccountManager::getInstance().getAccountInfo().getUsername();
53+}
54+
55+QStringList GlobalServicesScriptingInterface::getOnlineUsers() {
56+#ifdef HAVE_QXMPP
57+ if (XmppClient::getInstance().getXMPPClient().isConnected()) {
58+ QStringList usernames;
59+ const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom();
60+ foreach(const QString& participant, XmppClient::getInstance().getPublicChatRoom()->participants()) {
61+ usernames.append(participant.right(participant.count() - 1 - publicChatRoom->jid().count()));
62+ }
63+ return usernames;
64+ }
65+#endif // HAVE_QXMPP
66+ return QStringList();
67+}