Showing the changes to interface/src/scripting/GlobalServicesScriptingInterface.cpp (1 of 2 files). Show all
Unified · Split
| @@ -16,9 +16,43 @@ · 15 unmodified lines | ||
| 16 | 16 | |
| 17 | 17 | GlobalServicesScriptingInterface::GlobalServicesScriptingInterface() { |
| 18 | 18 | AccountManager& accountManager = AccountManager::getInstance(); |
| 19 | − connect(&accountManager, &AccountManager::usernameChanged, this, | |
| 20 | − &GlobalServicesScriptingInterface::myUsernameChanged); | |
| 19 | + connect(&accountManager, &AccountManager::usernameChanged, this, &GlobalServicesScriptingInterface::myUsernameChanged); | |
| 20 | + connect(&accountManager, &AccountManager::logoutComplete, this, &GlobalServicesScriptingInterface::loggedOut); | |
| 21 | +#ifdef HAVE_QXMPP | |
| 22 | + const XmppClient& xmppClient = XmppClient::getInstance(); | |
| 23 | + connect(&xmppClient, &XmppClient::joinedPublicChatRoom, this, &GlobalServicesScriptingInterface::connected); | |
| 24 | + connect(&xmppClient, &XmppClient::joinedPublicChatRoom, this, &GlobalServicesScriptingInterface::onConnected); | |
| 25 | + const QXmppClient& qxmppClient = XmppClient::getInstance().getXMPPClient(); | |
| 26 | + connect(&qxmppClient, &QXmppClient::messageReceived, this, &GlobalServicesScriptingInterface::messageReceived); | |
| 27 | +#endif // HAVE_QXMPP | |
| 28 | +} | |
| 29 | + | |
| 30 | +GlobalServicesScriptingInterface::~GlobalServicesScriptingInterface() { | |
| 31 | + AccountManager& accountManager = AccountManager::getInstance(); | |
| 32 | + disconnect(&accountManager, &AccountManager::usernameChanged, this, &GlobalServicesScriptingInterface::myUsernameChanged); | |
| 33 | + disconnect(&accountManager, &AccountManager::logoutComplete, this, &GlobalServicesScriptingInterface::loggedOut); | |
| 34 | +#ifdef HAVE_QXMPP | |
| 35 | + const XmppClient& xmppClient = XmppClient::getInstance(); | |
| 36 | + disconnect(&xmppClient, &XmppClient::joinedPublicChatRoom, this, &GlobalServicesScriptingInterface::connected); | |
| 37 | + disconnect(&xmppClient, &XmppClient::joinedPublicChatRoom, this, &GlobalServicesScriptingInterface::onConnected); | |
| 38 | + const QXmppClient& qxmppClient = XmppClient::getInstance().getXMPPClient(); | |
| 39 | + disconnect(&qxmppClient, &QXmppClient::messageReceived, this, &GlobalServicesScriptingInterface::messageReceived); | |
| 40 | + const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom(); | |
| 41 | + disconnect(publicChatRoom, &QXmppMucRoom::participantsChanged, this, &GlobalServicesScriptingInterface::participantsChanged); | |
| 42 | +#endif // HAVE_QXMPP | |
| 43 | +} | |
| 21 | 44 | |
| 45 | +void GlobalServicesScriptingInterface::onConnected() { | |
| 46 | +#ifdef HAVE_QXMPP | |
| 47 | + const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom(); | |
| 48 | + connect(publicChatRoom, &QXmppMucRoom::participantsChanged, this, &GlobalServicesScriptingInterface::participantsChanged, Qt::UniqueConnection); | |
| 49 | +#endif // HAVE_QXMPP | |
| 50 | +} | |
| 51 | + | |
| 52 | +void GlobalServicesScriptingInterface::participantsChanged() { | |
| 53 | +#ifdef HAVE_QXMPP | |
| 54 | + emit GlobalServicesScriptingInterface::onlineUsersChanged(this->getOnlineUsers()); | |
| 55 | +#endif // HAVE_QXMPP | |
| 22 | 56 | } |
| 23 | 57 | |
| 24 | 58 | GlobalServicesScriptingInterface* GlobalServicesScriptingInterface::getInstance() { |
| @@ -64,4 +98,16 @@ QStringList GlobalServicesScriptingInterface::getOnlineUsers() { · 39 unmodified lines | ||
| 64 | 98 | } |
| 65 | 99 | #endif // HAVE_QXMPP |
| 66 | 100 | return QStringList(); |
| 101 | +} | |
| 102 | + | |
| 103 | +void GlobalServicesScriptingInterface::loggedOut() { | |
| 104 | + emit GlobalServicesScriptingInterface::disconnected(QString("logout")); | |
| 105 | +} | |
| 106 | + | |
| 107 | +void GlobalServicesScriptingInterface::messageReceived(const QXmppMessage& message) { | |
| 108 | + if (message.type() != QXmppMessage::GroupChat) { | |
| 109 | + return; | |
| 110 | + } | |
| 111 | + const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom(); | |
| 112 | + emit GlobalServicesScriptingInterface::incomingMessage(message.from().right(message.from().count() - 1 - publicChatRoom->jid().count()), message.body()); | |
| 67 | 113 | } |