QXmpp Version: 1.10.0
QXmppPubSubBaseItem.h
1// SPDX-FileCopyrightText: 2019 Jeremy Lainé <jeremy.laine@m4x.org>
2// SPDX-FileCopyrightText: 2019 Linus Jahn <lnj@kaidan.im>
3//
4// SPDX-License-Identifier: LGPL-2.1-or-later
5
6#ifndef QXMPPPUBSUBBASEITEM_H
7#define QXMPPPUBSUBBASEITEM_H
8
9#include "QXmppGlobal.h"
10
11#include <QDomElement>
12#include <QMetaType>
13#include <QSharedDataPointer>
14
15class QXmlStreamWriter;
16class QXmppPubSubBaseItemPrivate;
17
18class QXMPP_EXPORT QXmppPubSubBaseItem
19{
20public:
21 QXmppPubSubBaseItem(const QString &id = {}, const QString &publisher = {});
24 virtual ~QXmppPubSubBaseItem() noexcept;
25
26 QXmppPubSubBaseItem &operator=(const QXmppPubSubBaseItem &) noexcept;
28
29 QString id() const;
30 void setId(const QString &id);
31
32 QString publisher() const;
33 void setPublisher(const QString &publisher);
34
36 void parse(const QDomElement &element);
37 void toXml(QXmlStreamWriter *writer) const;
39
40 static bool isItem(const QDomElement &element);
41
42protected:
43 virtual void parsePayload(const QDomElement &payloadElement);
44 virtual void serializePayload(QXmlStreamWriter *writer) const;
45
46 template<typename PayloadChecker>
47 static bool isItem(const QDomElement &element, PayloadChecker isPayloadValid);
48
49private:
50 QSharedDataPointer<QXmppPubSubBaseItemPrivate> d;
51};
52
72template<typename PayloadChecker>
73bool QXmppPubSubBaseItem::isItem(const QDomElement &element, PayloadChecker isPayloadValid)
74{
75 if (!isItem(element)) {
76 return false;
77 }
78
79 const QDomElement payload = element.firstChildElement();
80
81 // we can only check the payload if it's existant
82 if (!payload.isNull()) {
83 return isPayloadValid(payload);
84 }
85 return true;
86}
87
88Q_DECLARE_METATYPE(QXmppPubSubBaseItem)
89
90#endif // QXMPPPUBSUBBASEITEM_H
Definition: QXmppPubSubBaseItem.h:19
QXmppPubSubBaseItem(const QXmppPubSubBaseItem &) noexcept
Default copy-constructor.
QXmppPubSubBaseItem(QXmppPubSubBaseItem &&) noexcept
Default move-constructor.