Showing the changes to interface/src/scripting/GlobalServicesScriptingInterface.cpp (1 of 14 files). Show all
Unified · Split
| @@ -12,7 +12,6 @@ · 11 unmodified lines | |||
| 12 | #include "AccountManager.h" | 12 | #include "AccountManager.h" |
| 13 | #include "Application.h" | 13 | #include "Application.h" |
| 14 | #include "ResourceCache.h" | 14 | #include "ResourceCache.h" |
| 15 | #include "XmppClient.h" | ||
| 16 | 15 | ||
| 17 | #include "GlobalServicesScriptingInterface.h" | 16 | #include "GlobalServicesScriptingInterface.h" |
| 18 | 17 | ||
| @@ -20,13 +19,6 @@ GlobalServicesScriptingInterface::GlobalServicesScriptingInterface() { · 1 unmodified line | |||
| 20 | AccountManager& accountManager = AccountManager::getInstance(); | 19 | AccountManager& accountManager = AccountManager::getInstance(); |
| 21 | connect(&accountManager, &AccountManager::usernameChanged, this, &GlobalServicesScriptingInterface::myUsernameChanged); | 20 | connect(&accountManager, &AccountManager::usernameChanged, this, &GlobalServicesScriptingInterface::myUsernameChanged); |
| 22 | connect(&accountManager, &AccountManager::logoutComplete, this, &GlobalServicesScriptingInterface::loggedOut); | 21 | connect(&accountManager, &AccountManager::logoutComplete, this, &GlobalServicesScriptingInterface::loggedOut); |
| 23 | #ifdef HAVE_QXMPP | ||
| 24 | const XmppClient& xmppClient = XmppClient::getInstance(); | ||
| 25 | connect(&xmppClient, &XmppClient::joinedPublicChatRoom, this, &GlobalServicesScriptingInterface::connected); | ||
| 26 | connect(&xmppClient, &XmppClient::joinedPublicChatRoom, this, &GlobalServicesScriptingInterface::onConnected); | ||
| 27 | const QXmppClient& qxmppClient = XmppClient::getInstance().getXMPPClient(); | ||
| 28 | connect(&qxmppClient, &QXmppClient::messageReceived, this, &GlobalServicesScriptingInterface::messageReceived); | ||
| 29 | #endif // HAVE_QXMPP | ||
| 30 | 22 | ||
| 31 | _downloading = false; | 23 | _downloading = false; |
| 32 | connect(Application::getInstance(), &Application::renderingInWorldInterface, | 24 | connect(Application::getInstance(), &Application::renderingInWorldInterface, |
| @@ -37,30 +29,6 @@ GlobalServicesScriptingInterface::~GlobalServicesScriptingInterface() { · 4 unmodified lines | |||
| 37 | AccountManager& accountManager = AccountManager::getInstance(); | 29 | AccountManager& accountManager = AccountManager::getInstance(); |
| 38 | disconnect(&accountManager, &AccountManager::usernameChanged, this, &GlobalServicesScriptingInterface::myUsernameChanged); | 30 | disconnect(&accountManager, &AccountManager::usernameChanged, this, &GlobalServicesScriptingInterface::myUsernameChanged); |
| 39 | disconnect(&accountManager, &AccountManager::logoutComplete, this, &GlobalServicesScriptingInterface::loggedOut); | 31 | disconnect(&accountManager, &AccountManager::logoutComplete, this, &GlobalServicesScriptingInterface::loggedOut); |
| 40 | #ifdef HAVE_QXMPP | ||
| 41 | const XmppClient& xmppClient = XmppClient::getInstance(); | ||
| 42 | disconnect(&xmppClient, &XmppClient::joinedPublicChatRoom, this, &GlobalServicesScriptingInterface::connected); | ||
| 43 | disconnect(&xmppClient, &XmppClient::joinedPublicChatRoom, this, &GlobalServicesScriptingInterface::onConnected); | ||
| 44 | const QXmppClient& qxmppClient = XmppClient::getInstance().getXMPPClient(); | ||
| 45 | disconnect(&qxmppClient, &QXmppClient::messageReceived, this, &GlobalServicesScriptingInterface::messageReceived); | ||
| 46 | const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom(); | ||
| 47 | disconnect(publicChatRoom, &QXmppMucRoom::participantsChanged, | ||
| 48 | this, &GlobalServicesScriptingInterface::participantsChanged); | ||
| 49 | #endif // HAVE_QXMPP | ||
| 50 | } | ||
| 51 | |||
| 52 | void GlobalServicesScriptingInterface::onConnected() { | ||
| 53 | #ifdef HAVE_QXMPP | ||
| 54 | const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom(); | ||
| 55 | connect(publicChatRoom, &QXmppMucRoom::participantsChanged, | ||
| 56 | this, &GlobalServicesScriptingInterface::participantsChanged, Qt::UniqueConnection); | ||
| 57 | #endif // HAVE_QXMPP | ||
| 58 | } | ||
| 59 | |||
| 60 | void GlobalServicesScriptingInterface::participantsChanged() { | ||
| 61 | #ifdef HAVE_QXMPP | ||
| 62 | emit GlobalServicesScriptingInterface::onlineUsersChanged(this->getOnlineUsers()); | ||
| 63 | #endif // HAVE_QXMPP | ||
| 64 | } | 32 | } |
| 65 | 33 | ||
| 66 | GlobalServicesScriptingInterface* GlobalServicesScriptingInterface::getInstance() { | 34 | GlobalServicesScriptingInterface* GlobalServicesScriptingInterface::getInstance() { |
| @@ -68,62 +36,14 @@ GlobalServicesScriptingInterface* GlobalServicesScriptingInterface::getInstance( · 1 unmodified line | |||
| 68 | return &sharedInstance; | 36 | return &sharedInstance; |
| 69 | } | 37 | } |
| 70 | 38 | ||
| 71 | bool GlobalServicesScriptingInterface::isConnected() { | ||
| 72 | #ifdef HAVE_QXMPP | ||
| 73 | return XmppClient::getInstance().getXMPPClient().isConnected(); | ||
| 74 | #else | ||
| 75 | return false; | ||
| 76 | #endif // HAVE_QXMPP | ||
| 77 | } | ||
| 78 | |||
| 79 | QScriptValue GlobalServicesScriptingInterface::chat(const QString& message) { | ||
| 80 | #ifdef HAVE_QXMPP | ||
| 81 | if (XmppClient::getInstance().getXMPPClient().isConnected()) { | ||
| 82 | const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom(); | ||
| 83 | QXmppMessage messageObject; | ||
| 84 | messageObject.setTo(publicChatRoom->jid()); | ||
| 85 | messageObject.setType(QXmppMessage::GroupChat); | ||
| 86 | messageObject.setBody(message); | ||
| 87 | return XmppClient::getInstance().getXMPPClient().sendPacket(messageObject); | ||
| 88 | } | ||
| 89 | #endif // HAVE_QXMPP | ||
| 90 | return false; | ||
| 91 | } | ||
| 92 | |||
| 93 | QString GlobalServicesScriptingInterface::getMyUsername() { | 39 | QString GlobalServicesScriptingInterface::getMyUsername() { |
| 94 | return AccountManager::getInstance().getAccountInfo().getUsername(); | 40 | return AccountManager::getInstance().getAccountInfo().getUsername(); |
| 95 | } | 41 | } |
| 96 | 42 | ||
| 97 | QStringList GlobalServicesScriptingInterface::getOnlineUsers() { | ||
| 98 | #ifdef HAVE_QXMPP | ||
| 99 | if (XmppClient::getInstance().getXMPPClient().isConnected()) { | ||
| 100 | QStringList usernames; | ||
| 101 | const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom(); | ||
| 102 | foreach(const QString& participant, XmppClient::getInstance().getPublicChatRoom()->participants()) { | ||
| 103 | usernames.append(participant.right(participant.count() - 1 - publicChatRoom->jid().count())); | ||
| 104 | } | ||
| 105 | return usernames; | ||
| 106 | } | ||
| 107 | #endif // HAVE_QXMPP | ||
| 108 | return QStringList(); | ||
| 109 | } | ||
| 110 | |||
| 111 | void GlobalServicesScriptingInterface::loggedOut() { | 43 | void GlobalServicesScriptingInterface::loggedOut() { |
| 112 | emit GlobalServicesScriptingInterface::disconnected(QString("logout")); | 44 | emit GlobalServicesScriptingInterface::disconnected(QString("logout")); |
| 113 | } | 45 | } |
| 114 | 46 | ||
| 115 | #ifdef HAVE_QXMPP | ||
| 116 | void GlobalServicesScriptingInterface::messageReceived(const QXmppMessage& message) { | ||
| 117 | if (message.type() != QXmppMessage::GroupChat) { | ||
| 118 | return; | ||
| 119 | } | ||
| 120 | const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom(); | ||
| 121 | QString username = message.from().right(message.from().count() - 1 - publicChatRoom->jid().count()); | ||
| 122 | emit GlobalServicesScriptingInterface::incomingMessage(username, message.body()); | ||
| 123 | } | ||
| 124 | #endif // HAVE_QXMPP | ||
| 125 | |||
| 126 | |||
| 127 | DownloadInfoResult::DownloadInfoResult() : | 47 | DownloadInfoResult::DownloadInfoResult() : |
| 128 | downloading(QList<float>()), | 48 | downloading(QList<float>()), |
| 129 | pending(0.0f) | 49 | pending(0.0f) |