mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 21:57:00 +02:00
the GlobalServices Events are functional now
This commit is contained in:
parent
753dedce22
commit
807173ae0a
2 changed files with 55 additions and 2 deletions
|
@ -16,9 +16,43 @@
|
||||||
|
|
||||||
GlobalServicesScriptingInterface::GlobalServicesScriptingInterface() {
|
GlobalServicesScriptingInterface::GlobalServicesScriptingInterface() {
|
||||||
AccountManager& accountManager = AccountManager::getInstance();
|
AccountManager& accountManager = AccountManager::getInstance();
|
||||||
connect(&accountManager, &AccountManager::usernameChanged, this,
|
connect(&accountManager, &AccountManager::usernameChanged, this, &GlobalServicesScriptingInterface::myUsernameChanged);
|
||||||
&GlobalServicesScriptingInterface::myUsernameChanged);
|
connect(&accountManager, &AccountManager::logoutComplete, this, &GlobalServicesScriptingInterface::loggedOut);
|
||||||
|
#ifdef HAVE_QXMPP
|
||||||
|
const XmppClient& xmppClient = XmppClient::getInstance();
|
||||||
|
connect(&xmppClient, &XmppClient::joinedPublicChatRoom, this, &GlobalServicesScriptingInterface::connected);
|
||||||
|
connect(&xmppClient, &XmppClient::joinedPublicChatRoom, this, &GlobalServicesScriptingInterface::onConnected);
|
||||||
|
const QXmppClient& qxmppClient = XmppClient::getInstance().getXMPPClient();
|
||||||
|
connect(&qxmppClient, &QXmppClient::messageReceived, this, &GlobalServicesScriptingInterface::messageReceived);
|
||||||
|
#endif // HAVE_QXMPP
|
||||||
|
}
|
||||||
|
|
||||||
|
GlobalServicesScriptingInterface::~GlobalServicesScriptingInterface() {
|
||||||
|
AccountManager& accountManager = AccountManager::getInstance();
|
||||||
|
disconnect(&accountManager, &AccountManager::usernameChanged, this, &GlobalServicesScriptingInterface::myUsernameChanged);
|
||||||
|
disconnect(&accountManager, &AccountManager::logoutComplete, this, &GlobalServicesScriptingInterface::loggedOut);
|
||||||
|
#ifdef HAVE_QXMPP
|
||||||
|
const XmppClient& xmppClient = XmppClient::getInstance();
|
||||||
|
disconnect(&xmppClient, &XmppClient::joinedPublicChatRoom, this, &GlobalServicesScriptingInterface::connected);
|
||||||
|
disconnect(&xmppClient, &XmppClient::joinedPublicChatRoom, this, &GlobalServicesScriptingInterface::onConnected);
|
||||||
|
const QXmppClient& qxmppClient = XmppClient::getInstance().getXMPPClient();
|
||||||
|
disconnect(&qxmppClient, &QXmppClient::messageReceived, this, &GlobalServicesScriptingInterface::messageReceived);
|
||||||
|
const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom();
|
||||||
|
disconnect(publicChatRoom, &QXmppMucRoom::participantsChanged, this, &GlobalServicesScriptingInterface::participantsChanged);
|
||||||
|
#endif // HAVE_QXMPP
|
||||||
|
}
|
||||||
|
|
||||||
|
void GlobalServicesScriptingInterface::onConnected() {
|
||||||
|
#ifdef HAVE_QXMPP
|
||||||
|
const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom();
|
||||||
|
connect(publicChatRoom, &QXmppMucRoom::participantsChanged, this, &GlobalServicesScriptingInterface::participantsChanged, Qt::UniqueConnection);
|
||||||
|
#endif // HAVE_QXMPP
|
||||||
|
}
|
||||||
|
|
||||||
|
void GlobalServicesScriptingInterface::participantsChanged() {
|
||||||
|
#ifdef HAVE_QXMPP
|
||||||
|
emit GlobalServicesScriptingInterface::onlineUsersChanged(this->getOnlineUsers());
|
||||||
|
#endif // HAVE_QXMPP
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalServicesScriptingInterface* GlobalServicesScriptingInterface::getInstance() {
|
GlobalServicesScriptingInterface* GlobalServicesScriptingInterface::getInstance() {
|
||||||
|
@ -64,4 +98,16 @@ QStringList GlobalServicesScriptingInterface::getOnlineUsers() {
|
||||||
}
|
}
|
||||||
#endif // HAVE_QXMPP
|
#endif // HAVE_QXMPP
|
||||||
return QStringList();
|
return QStringList();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GlobalServicesScriptingInterface::loggedOut() {
|
||||||
|
emit GlobalServicesScriptingInterface::disconnected(QString("logout"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void GlobalServicesScriptingInterface::messageReceived(const QXmppMessage& message) {
|
||||||
|
if (message.type() != QXmppMessage::GroupChat) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom();
|
||||||
|
emit GlobalServicesScriptingInterface::incomingMessage(message.from().right(message.from().count() - 1 - publicChatRoom->jid().count()), message.body());
|
||||||
}
|
}
|
|
@ -32,6 +32,7 @@ class GlobalServicesScriptingInterface : public QObject {
|
||||||
Q_PROPERTY(QString myUsername READ getMyUsername)
|
Q_PROPERTY(QString myUsername READ getMyUsername)
|
||||||
Q_PROPERTY(QStringList onlineUsers READ getOnlineUsers)
|
Q_PROPERTY(QStringList onlineUsers READ getOnlineUsers)
|
||||||
GlobalServicesScriptingInterface();
|
GlobalServicesScriptingInterface();
|
||||||
|
~GlobalServicesScriptingInterface();
|
||||||
public:
|
public:
|
||||||
static GlobalServicesScriptingInterface* getInstance();
|
static GlobalServicesScriptingInterface* getInstance();
|
||||||
|
|
||||||
|
@ -42,6 +43,12 @@ public:
|
||||||
public slots:
|
public slots:
|
||||||
QScriptValue chat(const QString& message);
|
QScriptValue chat(const QString& message);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void loggedOut();
|
||||||
|
void onConnected();
|
||||||
|
void participantsChanged();
|
||||||
|
void messageReceived(const QXmppMessage& message);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void connected();
|
void connected();
|
||||||
void disconnected(const QString& reason);
|
void disconnected(const QString& reason);
|
||||||
|
|
Loading…
Reference in a new issue