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
16 16
17GlobalServicesScriptingInterface::GlobalServicesScriptingInterface() {17GlobalServicesScriptingInterface::GlobalServicesScriptingInterface() {
18 AccountManager& accountManager = AccountManager::getInstance();18 AccountManager& accountManager = AccountManager::getInstance();
19 connect(&accountManager, &AccountManager::usernameChanged, this,19 connect(&accountManager, &AccountManager::usernameChanged, this, &GlobalServicesScriptingInterface::myUsernameChanged);
20 &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
30GlobalServicesScriptingInterface::~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
45void 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
52void GlobalServicesScriptingInterface::participantsChanged() {
53#ifdef HAVE_QXMPP
54 emit GlobalServicesScriptingInterface::onlineUsersChanged(this->getOnlineUsers());
55#endif // HAVE_QXMPP
22}56}
23 57
24GlobalServicesScriptingInterface* GlobalServicesScriptingInterface::getInstance() {58GlobalServicesScriptingInterface* GlobalServicesScriptingInterface::getInstance() {
@@ -64,4 +98,16 @@ QStringList GlobalServicesScriptingInterface::getOnlineUsers() { · 39 unmodified lines
64 }98 }
65#endif // HAVE_QXMPP99#endif // HAVE_QXMPP
66 return QStringList();100 return QStringList();
101}
102
103void GlobalServicesScriptingInterface::loggedOut() {
104 emit GlobalServicesScriptingInterface::disconnected(QString("logout"));
105}
106
107void 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}