From d33dfb93bad0bc9f21bb93d437f4d2d437e91830 Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Tue, 5 Dec 2023 18:43:16 +0100 Subject: [PATCH 1/2] ClientExtension: Add onRegister()/onUnregister() functions Closes #586. --- src/client/QXmppClient.cpp | 6 +++--- src/client/QXmppClientExtension.cpp | 28 ++++++++++++++++++++++++++++ src/client/QXmppClientExtension.h | 3 +++ 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/client/QXmppClient.cpp b/src/client/QXmppClient.cpp index fc0ff6a84..2d13263e9 100644 --- a/src/client/QXmppClient.cpp +++ b/src/client/QXmppClient.cpp @@ -298,20 +298,20 @@ bool QXmppClient::insertExtension(int index, QXmppClientExtension *extension) } extension->setParent(this); - extension->setClient(this); d->extensions.insert(index, extension); + extension->setClient(this); return true; } +/// /// Unregisters the given extension from the client. If the extension /// is found, it will be destroyed. /// -/// \param extension - bool QXmppClient::removeExtension(QXmppClientExtension *extension) { if (d->extensions.contains(extension)) { d->extensions.removeAll(extension); + extension->setClient(nullptr); delete extension; return true; } else { diff --git a/src/client/QXmppClientExtension.cpp b/src/client/QXmppClientExtension.cpp index 131af7c31..cd14cfe56 100644 --- a/src/client/QXmppClientExtension.cpp +++ b/src/client/QXmppClientExtension.cpp @@ -87,7 +87,35 @@ QXmppClient *QXmppClientExtension::client() /// void QXmppClientExtension::setClient(QXmppClient *client) { + if (m_client != nullptr) { + onUnregistered(m_client); + } + m_client = client; + + if (client != nullptr) { + onRegistered(client); + } +} + +/// +/// Called after the extension has been added to a QXmppClient. +/// +/// \param client +/// +void QXmppClientExtension::onRegistered(QXmppClient *client) +{ + Q_UNUSED(client); +} + +/// +/// Called after the extension has been removed from a QXmppClient. +/// +/// \param client +/// +void QXmppClientExtension::onUnregistered(QXmppClient *client) +{ + Q_UNUSED(client); } /// diff --git a/src/client/QXmppClientExtension.h b/src/client/QXmppClientExtension.h index d05d6448c..c5a138d87 100644 --- a/src/client/QXmppClientExtension.h +++ b/src/client/QXmppClientExtension.h @@ -47,6 +47,9 @@ class QXMPP_EXPORT QXmppClientExtension : public QXmppLoggable, public QXmppExte QXmppClient *client(); virtual void setClient(QXmppClient *client); + virtual void onRegistered(QXmppClient *client); + virtual void onUnregistered(QXmppClient *client); + void injectIq(const QDomElement &element, const std::optional &e2eeMetadata); bool injectMessage(QXmppMessage &&message); From 0a57b0765eeb24ab5ae5cecbd43f7f4d3eeac0ef Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Sun, 25 Feb 2024 16:48:41 +0100 Subject: [PATCH 2/2] Increase SO_VERSION Changes have been made in ClientExtension. Other changes in Stream, OutgoingClient will follow. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e368a3b7..e99fe9531 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.7) project(qxmpp VERSION 1.7.0) -set(SO_VERSION 4) +set(SO_VERSION 5) # C++ standard settings: set(CMAKE_CXX_STANDARD 17)