Skip to content

Commit

Permalink
managers: Use onRegistered()/onUnregistered() instead of setClient()
Browse files Browse the repository at this point in the history
  • Loading branch information
lnjX committed Feb 25, 2024
1 parent 43c6697 commit 68ffe9e
Show file tree
Hide file tree
Showing 26 changed files with 115 additions and 71 deletions.
8 changes: 6 additions & 2 deletions src/client/QXmppAtmManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,16 @@ QXmppTask<void> QXmppAtmManager::makeTrustDecisions(const QString &encryption, c
}

/// \cond
void QXmppAtmManager::setClient(QXmppClient *client)
void QXmppAtmManager::onRegistered(QXmppClient *client)
{
QXmppClientExtension::setClient(client);
connect(client, &QXmppClient::messageReceived, this, &QXmppAtmManager::handleMessageReceived);
}

void QXmppAtmManager::onUnregistered(QXmppClient *client)
{
disconnect(client, &QXmppClient::messageReceived, this, &QXmppAtmManager::handleMessageReceived);
}

void QXmppAtmManager::handleMessageReceived(const QXmppMessage &message)
{
handleMessage(message);
Expand Down
3 changes: 2 additions & 1 deletion src/client/QXmppAtmManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class QXMPP_EXPORT QXmppAtmManager : public QXmppTrustManager

protected:
/// \cond
void setClient(QXmppClient *client) override;
void onRegistered(QXmppClient *client) override;
void onUnregistered(QXmppClient *client) override;

private:
Q_SLOT void handleMessageReceived(const QXmppMessage &message);
Expand Down
10 changes: 7 additions & 3 deletions src/client/QXmppAttentionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,18 @@ QString QXmppAttentionManager::requestAttention(const QString &jid, const QStrin
return {};
}

void QXmppAttentionManager::setClient(QXmppClient *client)
void QXmppAttentionManager::onRegistered(QXmppClient *client)
{
QXmppClientExtension::setClient(client);

connect(client, &QXmppClient::messageReceived,
this, &QXmppAttentionManager::handleMessageReceived);
}

void QXmppAttentionManager::onUnregistered(QXmppClient *client)
{
disconnect(client, &QXmppClient::messageReceived,
this, &QXmppAttentionManager::handleMessageReceived);
}

void QXmppAttentionManager::handleMessageReceived(const QXmppMessage &message)
{
if (!message.isAttentionRequested() || !message.stamp().isNull()) {
Expand Down
3 changes: 2 additions & 1 deletion src/client/QXmppAttentionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public Q_SLOTS:
void attentionRequestRateLimited(const QXmppMessage &message);

protected:
void setClient(QXmppClient *client) override;
void onRegistered(QXmppClient *client) override;
void onUnregistered(QXmppClient *client) override;

private Q_SLOTS:
void handleMessageReceived(const QXmppMessage &message);
Expand Down
14 changes: 6 additions & 8 deletions src/client/QXmppBlockingManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,16 +355,14 @@ QStringList QXmppBlockingManager::discoveryFeatures() const
return { XMLNS_BLOCKING.toString() };
}

void QXmppBlockingManager::setClient(QXmppClient *newClient)
void QXmppBlockingManager::onRegistered(QXmppClient *client)
{
// disconnect from old client
if (client()) {
disconnect(client(), &QXmppClient::connected, this, &QXmppBlockingManager::onConnected);
}

QXmppClientExtension::setClient(newClient);
connect(client, &QXmppClient::connected, this, &QXmppBlockingManager::onConnected);
}

connect(client(), &QXmppClient::connected, this, &QXmppBlockingManager::onConnected);
void QXmppBlockingManager::onUnregistered(QXmppClient *oldClient)
{
disconnect(oldClient, &QXmppClient::connected, this, &QXmppBlockingManager::onConnected);
}

bool QXmppBlockingManager::handleStanza(const QDomElement &stanza, const std::optional<QXmppE2eeMetadata> &)
Expand Down
3 changes: 2 additions & 1 deletion src/client/QXmppBlockingManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ class QXMPP_EXPORT QXmppBlockingManager : public QXmppClientExtension

/// \cond
QStringList discoveryFeatures() const override;
void setClient(QXmppClient *) override;
void onRegistered(QXmppClient *) override;
void onUnregistered(QXmppClient *) override;
bool handleStanza(const QDomElement &, const std::optional<QXmppE2eeMetadata> &) override;
/// \endcond

Expand Down
30 changes: 18 additions & 12 deletions src/client/QXmppBookmarkManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,6 @@ bool QXmppBookmarkManager::setBookmarks(const QXmppBookmarkSet &bookmarks)
}

/// \cond
void QXmppBookmarkManager::setClient(QXmppClient *client)
{

QXmppClientExtension::setClient(client);

connect(client, &QXmppClient::connected,
this, &QXmppBookmarkManager::slotConnected);

connect(client, &QXmppClient::disconnected,
this, &QXmppBookmarkManager::slotDisconnected);
}

bool QXmppBookmarkManager::handleStanza(const QDomElement &stanza)
{
if (stanza.tagName() == u"iq") {
Expand All @@ -162,6 +150,24 @@ bool QXmppBookmarkManager::handleStanza(const QDomElement &stanza)
}
return false;
}

void QXmppBookmarkManager::onRegistered(QXmppClient *client)
{
connect(client, &QXmppClient::connected,
this, &QXmppBookmarkManager::slotConnected);

connect(client, &QXmppClient::disconnected,
this, &QXmppBookmarkManager::slotDisconnected);
}

void QXmppBookmarkManager::onUnregistered(QXmppClient *client)
{
disconnect(client, &QXmppClient::connected,
this, &QXmppBookmarkManager::slotConnected);

disconnect(client, &QXmppClient::disconnected,
this, &QXmppBookmarkManager::slotDisconnected);
}
/// \endcond

void QXmppBookmarkManager::slotConnected()
Expand Down
3 changes: 2 additions & 1 deletion src/client/QXmppBookmarkManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class QXMPP_EXPORT QXmppBookmarkManager : public QXmppClientExtension

protected:
/// \cond
void setClient(QXmppClient *client) override;
void onRegistered(QXmppClient *client) override;
void onUnregistered(QXmppClient *client) override;
/// \endcond

private Q_SLOTS:
Expand Down
5 changes: 0 additions & 5 deletions src/client/QXmppCallInviteManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,6 @@ bool QXmppCallInviteManager::handleMessage(const QXmppMessage &message)

return false;
}

void QXmppCallInviteManager::setClient(QXmppClient *client)
{
QXmppClientExtension::setClient(client);
}
/// \endcond

///
Expand Down
1 change: 0 additions & 1 deletion src/client/QXmppCallInviteManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ class QXMPP_EXPORT QXmppCallInviteManager : public QXmppClientExtension, public
protected:
/// \cond
bool handleMessage(const QXmppMessage &) override;
void setClient(QXmppClient *client) override;
/// \endcond

private:
Expand Down
16 changes: 13 additions & 3 deletions src/client/QXmppCallManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,8 @@ bool QXmppCallManager::handleStanza(const QDomElement &element)
return false;
}

void QXmppCallManager::setClient(QXmppClient *client)
void QXmppCallManager::onRegistered(QXmppClient *client)
{
QXmppClientExtension::setClient(client);

connect(client, &QXmppClient::disconnected,
this, &QXmppCallManager::_q_disconnected);

Expand All @@ -104,6 +102,18 @@ void QXmppCallManager::setClient(QXmppClient *client)
connect(client, &QXmppClient::presenceReceived,
this, &QXmppCallManager::_q_presenceReceived);
}

void QXmppCallManager::onUnregistered(QXmppClient *client)
{
disconnect(client, &QXmppClient::disconnected,
this, &QXmppCallManager::_q_disconnected);

disconnect(client, &QXmppClient::iqReceived,
this, &QXmppCallManager::_q_iqReceived);

disconnect(client, &QXmppClient::presenceReceived,
this, &QXmppCallManager::_q_presenceReceived);
}
/// \endcond

///
Expand Down
3 changes: 2 additions & 1 deletion src/client/QXmppCallManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public Q_SLOTS:

protected:
/// \cond
void setClient(QXmppClient *client) override;
void onRegistered(QXmppClient *client) override;
void onUnregistered(QXmppClient *client) override;
/// \endcond

private Q_SLOTS:
Expand Down
12 changes: 6 additions & 6 deletions src/client/QXmppCarbonManagerV2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,14 @@ bool QXmppCarbonManagerV2::handleStanza(const QDomElement &element, const std::o
return true;
}

void QXmppCarbonManagerV2::setClient(QXmppClient *newClient)
void QXmppCarbonManagerV2::onRegistered(QXmppClient *client)
{
if (client()) {
disconnect(client(), &QXmppClient::connected, this, &QXmppCarbonManagerV2::enableCarbons);
}
connect(client, &QXmppClient::connected, this, &QXmppCarbonManagerV2::enableCarbons);
}

QXmppClientExtension::setClient(newClient);
connect(newClient, &QXmppClient::connected, this, &QXmppCarbonManagerV2::enableCarbons);
void QXmppCarbonManagerV2::onUnregistered(QXmppClient *client)
{
disconnect(client, &QXmppClient::connected, this, &QXmppCarbonManagerV2::enableCarbons);
}

void QXmppCarbonManagerV2::enableCarbons()
Expand Down
3 changes: 2 additions & 1 deletion src/client/QXmppCarbonManagerV2.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class QXMPP_EXPORT QXmppCarbonManagerV2 : public QXmppClientExtension
bool handleStanza(const QDomElement &, const std::optional<QXmppE2eeMetadata> &) override;

protected:
void setClient(QXmppClient *client) override;
void onRegistered(QXmppClient *client) override;
void onUnregistered(QXmppClient *client) override;

private:
void enableCarbons();
Expand Down
5 changes: 0 additions & 5 deletions src/client/QXmppJingleMessageInitiationManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,6 @@ bool QXmppJingleMessageInitiationManager::handleMessage(const QXmppMessage &mess

return false;
}

void QXmppJingleMessageInitiationManager::setClient(QXmppClient *client)
{
QXmppClientExtension::setClient(client);
}
/// \endcond

///
Expand Down
1 change: 0 additions & 1 deletion src/client/QXmppJingleMessageInitiationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ class QXMPP_EXPORT QXmppJingleMessageInitiationManager : public QXmppClientExten
protected:
/// \cond
bool handleMessage(const QXmppMessage &) override;
void setClient(QXmppClient *client) override;
/// \endcond

private:
Expand Down
10 changes: 7 additions & 3 deletions src/client/QXmppMucManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,17 @@ bool QXmppMucManager::handleStanza(const QDomElement &element)
return false;
}

void QXmppMucManager::setClient(QXmppClient *client)
void QXmppMucManager::onRegistered(QXmppClient *client)
{
QXmppClientExtension::setClient(client);

connect(client, &QXmppClient::messageReceived,
this, &QXmppMucManager::_q_messageReceived);
}

void QXmppMucManager::onUnregistered(QXmppClient *client)
{
disconnect(client, &QXmppClient::messageReceived,
this, &QXmppMucManager::_q_messageReceived);
}
/// \endcond

void QXmppMucManager::_q_messageReceived(const QXmppMessage &msg)
Expand Down
6 changes: 4 additions & 2 deletions src/client/QXmppMucManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class QXmppMucManagerPrivate;
class QXmppMucRoom;
class QXmppMucRoomPrivate;

///
/// \brief The QXmppMucManager class makes it possible to interact with
/// multi-user chat rooms as defined by \xep{0045}: Multi-User Chat.
///
Expand All @@ -36,7 +37,7 @@ class QXmppMucRoomPrivate;
/// \endcode
///
/// \ingroup Managers

///
class QXMPP_EXPORT QXmppMucManager : public QXmppClientExtension
{
Q_OBJECT
Expand Down Expand Up @@ -67,7 +68,8 @@ class QXMPP_EXPORT QXmppMucManager : public QXmppClientExtension

protected:
/// \cond
void setClient(QXmppClient *client) override;
void onRegistered(QXmppClient *client) override;
void onUnregistered(QXmppClient *client) override;
/// \endcond

private Q_SLOTS:
Expand Down
11 changes: 8 additions & 3 deletions src/client/QXmppRegistrationManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,11 @@ bool QXmppRegistrationManager::handleStanza(const QDomElement &stanza)
}
/// \endcond

void QXmppRegistrationManager::setClient(QXmppClient *client)
void QXmppRegistrationManager::onRegistered(QXmppClient *client)
{
QXmppClientExtension::setClient(client);
// get service discovery manager
auto *disco = client->findExtension<QXmppDiscoveryManager>();
if (disco) {
if (disco != nullptr) {
connect(disco, &QXmppDiscoveryManager::infoReceived, this, &QXmppRegistrationManager::handleDiscoInfo);
}

Expand All @@ -288,6 +287,12 @@ void QXmppRegistrationManager::setClient(QXmppClient *client)
});
}

void QXmppRegistrationManager::onUnregistered(QXmppClient *client)
{
// TODO: Proper clean up of connections (currently no issue because extensions are deleted
// on removal)
}

void QXmppRegistrationManager::handleDiscoInfo(const QXmppDiscoveryIq &iq)
{
// check features of own server
Expand Down
3 changes: 2 additions & 1 deletion src/client/QXmppRegistrationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,8 @@ class QXMPP_EXPORT QXmppRegistrationManager : public QXmppClientExtension
void registrationFailed(const QXmppStanza::Error &error);

protected:
void setClient(QXmppClient *client) override;
void onRegistered(QXmppClient *client) override;
void onUnregistered(QXmppClient *client) override;

private Q_SLOTS:
void handleDiscoInfo(const QXmppDiscoveryIq &iq);
Expand Down
9 changes: 6 additions & 3 deletions src/client/QXmppTransferManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -944,13 +944,16 @@ bool QXmppTransferManager::handleStanza(const QDomElement &element)
return false;
}

void QXmppTransferManager::setClient(QXmppClient *client)
void QXmppTransferManager::onRegistered(QXmppClient *client)
{
QXmppClientExtension::setClient(client);

// XEP-0047: In-Band Bytestreams
connect(client, &QXmppClient::iqReceived, this, &QXmppTransferManager::_q_iqReceived);
}

void QXmppTransferManager::onUnregistered(QXmppClient *client)
{
disconnect(client, &QXmppClient::iqReceived, this, &QXmppTransferManager::_q_iqReceived);
}
/// \endcond

void QXmppTransferManager::ibbCloseIqReceived(const QXmppIbbCloseIq &iq)
Expand Down
3 changes: 2 additions & 1 deletion src/client/QXmppTransferManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ public Q_SLOTS:

protected:
/// \cond
void setClient(QXmppClient *client) override;
void onRegistered(QXmppClient *client) override;
void onUnregistered(QXmppClient *client) override;
/// \endcond

private Q_SLOTS:
Expand Down
9 changes: 7 additions & 2 deletions src/client/QXmppUploadRequestManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,8 @@ void QXmppUploadRequestManager::handleDiscoInfo(const QXmppDiscoveryIq &iq)
return;
}

void QXmppUploadRequestManager::setClient(QXmppClient *client)
void QXmppUploadRequestManager::onRegistered(QXmppClient *client)
{
QXmppClientExtension::setClient(client);
// connect to service discovery manager
auto *disco = client->findExtension<QXmppDiscoveryManager>();
if (disco) {
Expand All @@ -334,3 +333,9 @@ void QXmppUploadRequestManager::setClient(QXmppClient *client)
});
}
}

void QXmppUploadRequestManager::onUnregistered(QXmppClient *client)
{
// TODO: Proper clean up of connections (currently no issue because extensions are deleted
// on removal)
}
Loading

0 comments on commit 68ffe9e

Please sign in to comment.