History

the GlobalServices Events are functional now

Thijs Wenker committed 12 years ago

Commit 807173a1 parent 753dedc2 files · +55 −2Browse files

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

Unified · Split

interface/src/scripting/GlobalServicesScriptingInterface.cpp+48−2
@@ -16,9 +16,43 @@ · 15 unmodified lines
1616
1717 GlobalServicesScriptingInterface::GlobalServicesScriptingInterface() {
1818 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+}
2144
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
2256 }
2357
2458 GlobalServicesScriptingInterface* GlobalServicesScriptingInterface::getInstance() {
@@ -64,4 +98,16 @@ QStringList GlobalServicesScriptingInterface::getOnlineUsers() { · 39 unmodified lines
6498 }
6599 #endif // HAVE_QXMPP
66100 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());
67113 }