QXmpp Version: 1.10.0
QXmppPubSubNodeConfig.h
1// SPDX-FileCopyrightText: 2020 Linus Jahn <lnj@kaidan.im>
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4
5#ifndef QXMPPPUBSUBNODECONFIG_H
6#define QXMPPPUBSUBNODECONFIG_H
7
8#include "QXmppDataForm.h"
9#include "QXmppDataFormBase.h"
10
11#include <variant>
12
13class QXmppPubSubNodeConfigPrivate;
14
15class QXMPP_EXPORT QXmppPubSubNodeConfig : public QXmppExtensibleDataFormBase
16{
17public:
18 struct Unset { };
19 struct Max { };
20 using ItemLimit = std::variant<Unset, uint64_t, Max>;
21
22 enum AccessModel : uint8_t {
23 Open,
24 Presence,
25 Roster,
26 Authorize,
27 Allowlist
28 };
29 static std::optional<AccessModel> accessModelFromString(const QString &);
30 static QString accessModelToString(AccessModel);
31
32 enum PublishModel : uint8_t {
33 Publishers,
34 Subscribers,
35 Anyone
36 };
37 static std::optional<PublishModel> publishModelFromString(const QString &);
38 static QString publishModelToString(PublishModel);
39
40 enum class ChildAssociationPolicy : uint8_t {
41 All,
42 Owners,
43 Whitelist
44 };
45 static std::optional<ChildAssociationPolicy> childAssociatationPolicyFromString(const QString &);
46 static QString childAssociationPolicyToString(ChildAssociationPolicy);
47
48 enum ItemPublisher : uint8_t {
49 NodeOwner,
50 Publisher
51 };
52 static std::optional<ItemPublisher> itemPublisherFromString(const QString &);
53 static QString itemPublisherToString(ItemPublisher);
54
55 enum NodeType : uint8_t {
56 Leaf,
57 Collection
58 };
59 static std::optional<NodeType> nodeTypeFromString(const QString &);
60 static QString nodeTypeToString(NodeType);
61
62 enum NotificationType : uint8_t {
63 Normal,
64 Headline
65 };
66 static std::optional<NotificationType> notificationTypeFromString(const QString &);
67 static QString notificationTypeToString(NotificationType);
68
69 enum SendLastItemType : uint8_t {
70 Never,
71 OnSubscription,
72 OnSubscriptionAndPresence
73 };
74 static std::optional<SendLastItemType> sendLastItemTypeFromString(const QString &);
75 static QString sendLastItemTypeToString(SendLastItemType);
76
77 static std::optional<QXmppPubSubNodeConfig> fromDataForm(const QXmppDataForm &form);
78
79 QXmppPubSubNodeConfig();
80 QXmppPubSubNodeConfig(const QXmppPubSubNodeConfig &);
81 QXmppPubSubNodeConfig(QXmppPubSubNodeConfig &&);
82 ~QXmppPubSubNodeConfig() override;
83
84 QXmppPubSubNodeConfig &operator=(const QXmppPubSubNodeConfig &);
85 QXmppPubSubNodeConfig &operator=(QXmppPubSubNodeConfig &&);
86
87 std::optional<AccessModel> accessModel() const;
88 void setAccessModel(std::optional<AccessModel> accessModel);
89
90 QString bodyXslt() const;
91 void setBodyXslt(const QString &bodyXslt);
92
93 std::optional<ChildAssociationPolicy> childAssociationPolicy() const;
94 void setChildAssociationPolicy(std::optional<ChildAssociationPolicy> childAssociationPolicy);
95
96 QStringList childAssociationAllowlist() const;
97 void setChildAssociationAllowlist(const QStringList &childAssociationWhitelist);
98
99 QStringList childNodes() const;
100 void setChildNodes(const QStringList &childNodes);
101
102 std::optional<quint32> childNodesMax() const;
103 void setChildNodesMax(std::optional<quint32> childNodesMax);
104
105 QStringList collections() const;
106 void setCollections(const QStringList &collections);
107
108 QStringList contactJids() const;
109 void setContactJids(const QStringList &contactJids);
110
111 QString dataFormXslt() const;
112 void setDataFormXslt(const QString &dataFormXslt);
113
114 std::optional<bool> notificationsEnabled() const;
115 void setNotificationsEnabled(std::optional<bool> notificationsEnabled);
116
117 std::optional<bool> includePayloads() const;
118 void setIncludePayloads(std::optional<bool> includePayloads);
119
120 QString description() const;
121 void setDescription(const QString &description);
122
123 std::optional<quint32> itemExpiry() const;
124 void setItemExpiry(std::optional<quint32> itemExpiry);
125
126 std::optional<ItemPublisher> notificationItemPublisher() const;
127 void setNotificationItemPublisher(std::optional<ItemPublisher> notificationItemPublisher);
128
129 QString language() const;
130 void setLanguage(const QString &language);
131
132 ItemLimit maxItems() const;
133 void setMaxItems(ItemLimit maxItems);
134 inline void resetMaxItems() { setMaxItems(Unset()); }
135
136 std::optional<quint32> maxPayloadSize() const;
137 void setMaxPayloadSize(std::optional<quint32> maxPayloadSize);
138
139 std::optional<NodeType> nodeType() const;
140 void setNodeType(std::optional<NodeType> nodeType);
141
142 std::optional<QXmppPubSubNodeConfig::NotificationType> notificationType() const;
143 void setNotificationType(std::optional<QXmppPubSubNodeConfig::NotificationType> notificationType);
144
145 std::optional<bool> configNotificationsEnabled() const;
146 void setConfigNotificationsEnabled(std::optional<bool> configNotificationsEnabled);
147
148 std::optional<bool> deleteNotificationsEnabled() const;
149 void setDeleteNotificationsEnabled(std::optional<bool> nodeDeleteNotificationsEnabled);
150
151 std::optional<bool> retractNotificationsEnabled() const;
152 void setRetractNotificationsEnabled(std::optional<bool> retractNotificationsEnabled);
153
154 std::optional<bool> subNotificationsEnabled() const;
155 void setSubNotificationsEnabled(std::optional<bool> subNotificationsEnabled);
156
157 std::optional<bool> persistItems() const;
158 void setPersistItems(std::optional<bool> persistItems);
159
160 std::optional<bool> presenceBasedNotifications() const;
161 void setPresenceBasedNotifications(std::optional<bool> presenceBasedNotifications);
162
163 std::optional<PublishModel> publishModel() const;
164 void setPublishModel(std::optional<PublishModel> publishModel);
165
166 std::optional<bool> purgeWhenOffline() const;
167 void setPurgeWhenOffline(std::optional<bool> purgeWhenOffline);
168
169 QStringList allowedRosterGroups() const;
170 void setAllowedRosterGroups(const QStringList &allowedRosterGroups);
171
172 std::optional<SendLastItemType> sendLastItem() const;
173 void setSendLastItem(std::optional<SendLastItemType> sendLastItem);
174
175 std::optional<bool> temporarySubscriptions() const;
176 void setTemporarySubscriptions(std::optional<bool> temporarySubscriptions);
177
178 std::optional<bool> allowSubscriptions() const;
179 void setAllowSubscriptions(std::optional<bool> allowSubscriptions);
180
181 QString title() const;
182 void setTitle(const QString &title);
183
184 QString payloadType() const;
185 void setPayloadType(const QString &payloadType);
186
187protected:
188 QString formType() const override;
189 bool parseField(const QXmppDataForm::Field &) override;
190 void serializeForm(QXmppDataForm &) const override;
191
192private:
193 QSharedDataPointer<QXmppPubSubNodeConfigPrivate> d;
194};
195
196class QXMPP_EXPORT QXmppPubSubPublishOptions : public QXmppPubSubNodeConfig
197{
198public:
199 static std::optional<QXmppPubSubPublishOptions> fromDataForm(const QXmppDataForm &form);
200
201protected:
202 QString formType() const override;
203};
204
205Q_DECLARE_METATYPE(QXmppPubSubNodeConfig);
206Q_DECLARE_METATYPE(QXmppPubSubPublishOptions);
207
208#endif // QXMPPPUBSUBNODECONFIG_H
static bool fromDataForm(const QXmppDataForm &form, QXmppDataFormBase &parent)
Definition: QXmppDataFormBase.cpp:55
virtual QString formType() const =0
Definition: QXmppDataForm.h:89
Definition: QXmppDataForm.h:27
Definition: QXmppDataFormBase.h:97
void serializeForm(QXmppDataForm &) const override
Definition: QXmppDataFormBase.cpp:204
virtual bool parseField(const QXmppDataForm::Field &)
Definition: QXmppDataFormBase.cpp:215