Loading...
Searching...
No Matches
QXmppPubSubEvent.h
// SPDX-FileCopyrightText: 2020 Linus Jahn <lnj@kaidan.im>
//
// SPDX-License-Identifier: LGPL-2.1-or-later
#ifndef QXMPPPUBSUBEVENT_H
#define QXMPPPUBSUBEVENT_H
#include "QXmppMessage.h"
#include "QXmppPubSubSubscription.h"
#include <functional>
#include <QDomElement>
#include <QSharedData>
class QXmppDataForm;
class QXmppPubSubEventPrivate;
class QXmppPubSubBaseItem;
class QXMPP_EXPORT QXmppPubSubEventBase : public QXmppMessage
{
public:
enum EventType : uint8_t {
Configuration,
Delete,
Items,
Retract,
Purge,
Subscription,
};
QXmppPubSubEventBase(EventType = Items, const QString &node = {});
QXmppPubSubEventBase(const QXmppPubSubEventBase &other);
QXmppPubSubEventBase(QXmppPubSubEventBase &&);
virtual ~QXmppPubSubEventBase();
QXmppPubSubEventBase &operator=(const QXmppPubSubEventBase &other);
QXmppPubSubEventBase &operator=(QXmppPubSubEventBase &&);
EventType eventType() const;
void setEventType(EventType);
QString node() const;
void setNode(const QString &node);
QStringList retractIds() const;
void setRetractIds(const QStringList &);
QString redirectUri() const;
void setRedirectUri(const QString &);
std::optional<QXmppPubSubSubscription> subscription() const;
void setSubscription(const std::optional<QXmppPubSubSubscription> &subscription);
std::optional<QXmppDataForm> configurationForm() const;
void setConfigurationForm(const std::optional<QXmppDataForm> &configurationForm);
protected:
static bool isPubSubEvent(const QDomElement &element, std::function<bool(const QDomElement &)> isItemValid);
bool parseExtension(const QDomElement &element, QXmpp::SceMode) override;
void serializeExtensions(QXmlStreamWriter *writer, QXmpp::SceMode, const QString &baseNamespace) const override;
virtual void parseItems(const QDomElement &) = 0;
virtual void serializeItems(QXmlStreamWriter *writer) const = 0;
private:
QSharedDataPointer<QXmppPubSubEventPrivate> d;
};
template<typename T = QXmppPubSubBaseItem>
class QXmppPubSubEvent : public QXmppPubSubEventBase
{
public:
QVector<T> items() const;
void setItems(const QVector<T> &items);
static bool isPubSubEvent(const QDomElement &element);
protected:
void parseItems(const QDomElement &) override;
void serializeItems(QXmlStreamWriter *writer) const override;
private:
QVector<T> m_items;
};
template<typename T>
QVector<T> QXmppPubSubEvent<T>::items() const
{
return m_items;
}
template<typename T>
void QXmppPubSubEvent<T>::setItems(const QVector<T> &items)
{
m_items = items;
}
template<typename T>
bool QXmppPubSubEvent<T>::isPubSubEvent(const QDomElement &element)
{
return QXmppPubSubEventBase::isPubSubEvent(element, [](const QDomElement &element) {
return T::isItem(element);
});
}
template<typename T>
void QXmppPubSubEvent<T>::parseItems(const QDomElement &parent)
{
QDomElement child = parent.firstChildElement(QStringLiteral("item"));
while (!child.isNull()) {
T item;
item.parse(child);
m_items << item;
child = child.nextSiblingElement(QStringLiteral("item"));
}
}
template<typename T>
void QXmppPubSubEvent<T>::serializeItems(QXmlStreamWriter *writer) const
{
for (const auto &item : qAsConst(m_items)) {
item.toXml(writer);
}
}
Q_DECLARE_METATYPE(QXmppPubSubEventBase::EventType)
#endif // QXMPPPUBSUBEVENT_H
QXmppDataForm
Definition QXmppDataForm.h:27
QXmppMessage
The QXmppMessage class represents an XMPP message.
Definition QXmppMessage.h:35
QXmppMessage::parseExtension
virtual bool parseExtension(const QDomElement &element, QXmpp::SceMode)
Definition QXmppMessage.cpp:1375
QXmppMessage::serializeExtensions
virtual void serializeExtensions(QXmlStreamWriter *writer, QXmpp::SceMode, const QString &baseNamespace={}) const
Definition QXmppMessage.cpp:1607
QXmppNonza::parse
virtual void parse(const QDomElement &)=0
QXmppNonza::toXml
virtual void toXml(QXmlStreamWriter *writer) const =0
QXmppPubSubBaseItem
Definition QXmppPubSubBaseItem.h:18
QXmppPubSubEventBase
Definition QXmppPubSubEvent.h:21
QXmppPubSubEventBase::operator=
QXmppPubSubEventBase & operator=(const QXmppPubSubEventBase &other)
Default assignment operator.
QXmppPubSubEventBase::EventType
EventType
Definition QXmppPubSubEvent.h:26
QXmppPubSubEventBase::operator=
QXmppPubSubEventBase & operator=(QXmppPubSubEventBase &&)
Default move-assignment operator.
QXmppPubSubEventBase::QXmppPubSubEventBase
QXmppPubSubEventBase(const QXmppPubSubEventBase &other)
Default copy-constructor.
QXmppPubSubEventBase::QXmppPubSubEventBase
QXmppPubSubEventBase(QXmppPubSubEventBase &&)
Default move-constructor.
QXmppPubSubEvent
The QXmppPubSubEvent class represents a PubSub event notification as defined by XEP-0060: Publish-Sub...
Definition QXmppPubSubEvent.h:78
QXmppPubSubEvent::isPubSubEvent
static bool isPubSubEvent(const QDomElement &element)
Definition QXmppPubSubEvent.h:118
QXmppPubSubEvent::items
QVector< T > items() const
Definition QXmppPubSubEvent.h:99
QXmppPubSubEvent::setItems
void setItems(const QVector< T > &items)
Definition QXmppPubSubEvent.h:108
QXmpp::SceMode
SceMode
Definition QXmppGlobal.h:136