blob: dc1fab5af59ea2062f67e96505e20155705b5441 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
// SPDX-FileCopyrightText: 2020 Robert Märkisch <zatrox@kaidan.im>
// SPDX-FileCopyrightText: 2021 Linus Jahn <lnj@kaidan.im>
// SPDX-FileCopyrightText: 2020 Jonah Brüchert <jbb@kaidan.im>
//
// SPDX-License-Identifier: LGPL-2.1-or-later
#include "QXmppPushEnableIq.h"
#include "QXmppConstants_p.h"
#include "QXmppDataForm.h"
#include <QDomElement>
class QXmppPushEnableIqPrivate : public QSharedData
{
public:
QString node;
QString jid;
QXmppPushEnableIq::Mode mode;
QXmppDataForm dataForm;
};
QXmppPushEnableIq::QXmppPushEnableIq()
: d(new QXmppPushEnableIqPrivate())
{
}
/// Default copy-constructor
QXmppPushEnableIq::QXmppPushEnableIq(const QXmppPushEnableIq &) = default;
/// Default move-constructor
QXmppPushEnableIq::QXmppPushEnableIq(QXmppPushEnableIq &&) = default;
QXmppPushEnableIq::~QXmppPushEnableIq() = default;
/// Default assignment operator
QXmppPushEnableIq &QXmppPushEnableIq::operator=(const QXmppPushEnableIq &) = default;
/// Default move-assignment operator
QXmppPushEnableIq &QXmppPushEnableIq::operator=(QXmppPushEnableIq &&) = default;
///
/// \brief Returns the jid of the app server
///
QString QXmppPushEnableIq::jid() const
{
return d->jid;
}
///
/// \brief Sets the jid of the app server
///
void QXmppPushEnableIq::setJid(const QString &jid)
{
d->jid = jid;
}
///
/// \brief Returns the pubsub node on the app server used by the IQ
///
QString QXmppPushEnableIq::node() const
{
return d->node;
}
///
/// \brief Set the pubsub note on the app server to be used by the IQ
///
void QXmppPushEnableIq::setNode(const QString &node)
{
d->node = node;
}
///
/// \brief Returns the mode
///
QXmppPushEnableIq::Mode QXmppPushEnableIq::mode()
{
return d->mode;
}
///
/// \brief Set whether the IQ should enable or disable push notifications
///
void QXmppPushEnableIq::setMode(QXmppPushEnableIq::Mode mode)
{
d->mode = mode;
}
///
/// \brief Returns the data form containing the publish options which the user
/// server Should send to the app server.
///
/// It is only available for enable IQs.
///
QXmppDataForm QXmppPushEnableIq::dataForm() const
{
return d->dataForm;
}
///
/// \brief Sets the data form containing the publish options which the user
/// server Should send to the app server.
///
/// It should only be set for enable IQs.
///
void QXmppPushEnableIq::setDataForm(const QXmppDataForm &form)
{
d->dataForm = form;
}
///
/// \brief Checks whether a QDomElement is a push notification enable / disable
/// IQ.
///
bool QXmppPushEnableIq::isPushEnableIq(const QDomElement &element)
{
auto childElement = element.firstChildElement();
return childElement.namespaceURI() == ns_push &&
(childElement.tagName() == QStringLiteral("enable") || childElement.tagName() == QStringLiteral("disable"));
}
/// \cond
void QXmppPushEnableIq::parseElementFromChild(const QDomElement &element)
{
QDomElement childElement = element.firstChildElement();
while (!childElement.isNull()) {
if (childElement.namespaceURI() == ns_push) {
if (childElement.tagName() == QStringLiteral("enable")) {
d->mode = Enable;
auto dataFormElement = childElement.firstChildElement("x");
if (!dataFormElement.isNull() && dataFormElement.namespaceURI() == ns_data) {
QXmppDataForm dataForm;
dataForm.parse(dataFormElement);
d->dataForm = dataForm;
}
} else {
d->mode = Disable;
}
d->jid = childElement.attribute(QStringLiteral("jid"));
d->node = childElement.attribute(QStringLiteral("node"));
break;
}
childElement = childElement.nextSiblingElement();
}
}
void QXmppPushEnableIq::toXmlElementFromChild(QXmlStreamWriter *writer) const
{
switch (d->mode) {
case Enable:
writer->writeStartElement(QStringLiteral("enable"));
break;
case Disable:
writer->writeStartElement(QStringLiteral("disable"));
break;
}
writer->writeDefaultNamespace(ns_push);
writer->writeAttribute(QStringLiteral("jid"), d->jid);
writer->writeAttribute(QStringLiteral("node"), d->node);
if (d->mode == Enable) {
d->dataForm.toXml(writer);
}
writer->writeEndElement();
}
/// \endcond
|