Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClientExtension: Add onRegister()/onUnregister() functions #599

Merged
merged 2 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/client/QXmppClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
28 changes: 28 additions & 0 deletions src/client/QXmppClientExtension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

///
Expand Down
3 changes: 3 additions & 0 deletions src/client/QXmppClientExtension.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<QXmppE2eeMetadata> &e2eeMetadata);
bool injectMessage(QXmppMessage &&message);

Expand Down
Loading