QXmpp: QXmppPubSubBaseItem.h Source File

QXmpp Version: 1.14.4

Loading...
Searching...
No Matches
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
18 class QXMPP_EXPORT QXmppPubSubBaseItem
19{
20public:
21 QXmppPubSubBaseItem(const QString &id = {}, const QString &publisher = {});
22 QXmppPubSubBaseItem(const QXmppPubSubBaseItem &) noexcept;
23 QXmppPubSubBaseItem(QXmppPubSubBaseItem &&) noexcept;
24 virtual ~QXmppPubSubBaseItem() noexcept;
25
26 QXmppPubSubBaseItem &operator=(const QXmppPubSubBaseItem &) noexcept;
27 QXmppPubSubBaseItem &operator=(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>
73 bool 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
QXmppPubSubBaseItem
Definition QXmppPubSubBaseItem.h:19
QXmppPubSubBaseItem::QXmppPubSubBaseItem
QXmppPubSubBaseItem(const QXmppPubSubBaseItem &) noexcept
Default copy-constructor.
QXmppPubSubBaseItem::setId
void setId(const QString &id)
Definition QXmppPubSubBaseItem.cpp:90
QXmppPubSubBaseItem::serializePayload
virtual void serializePayload(QXmlStreamWriter *writer) const
Definition QXmppPubSubBaseItem.cpp:154
QXmppPubSubBaseItem::publisher
QString publisher() const
Definition QXmppPubSubBaseItem.cpp:98
QXmppPubSubBaseItem::setPublisher
void setPublisher(const QString &publisher)
Definition QXmppPubSubBaseItem.cpp:106
QXmppPubSubBaseItem::QXmppPubSubBaseItem
QXmppPubSubBaseItem(QXmppPubSubBaseItem &&) noexcept
Default move-constructor.
QXmppPubSubBaseItem::QXmppPubSubBaseItem
QXmppPubSubBaseItem(const QString &id={}, const QString &publisher={})
Definition QXmppPubSubBaseItem.cpp:62
QXmppPubSubBaseItem::parsePayload
virtual void parsePayload(const QDomElement &payloadElement)
Definition QXmppPubSubBaseItem.cpp:144
QXmppPubSubBaseItem::isItem
static bool isItem(const QDomElement &element)
Definition QXmppPubSubBaseItem.cpp:134