QXmpp Version: 1.12.0
Loading...
Searching...
No Matches
QXmppDataForm.h
1// SPDX-FileCopyrightText: 2010 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 QXMPPDATAFORM_H
7#define QXMPPDATAFORM_H
8
9#include "QXmppConstants_p.h"
10#include "QXmppStanza.h"
11
12#if QXMPP_DEPRECATED_SINCE(1, 1)
13#include <QPair>
14#endif
15#include <QVariant>
16#include <QVector>
17
18class QMimeType;
19class QUrl;
20
22class QXmppDataFormPrivate;
23class QXmppDataFormFieldPrivate;
24class QXmppDataFormMediaPrivate;
25class QXmppDataFormMediaSourcePrivate;
26
27class QXMPP_EXPORT QXmppDataForm
28{
29public:
30 class QXMPP_EXPORT MediaSource
31 {
32 public:
34 MediaSource(const QUrl &uri, const QMimeType &contentType);
38
41
42 QUrl uri() const;
43 void setUri(const QUrl &uri);
44
45 QMimeType contentType() const;
46 void setContentType(const QMimeType &contentType);
47
48 bool operator==(const MediaSource &other) const;
50 static constexpr std::tuple XmlTag = { u"uri", QXmpp::Private::ns_media_element };
52
53 private:
54 QSharedDataPointer<QXmppDataFormMediaSourcePrivate> d;
55 };
56
57#if QXMPP_DEPRECATED_SINCE(1, 1)
58 class QXMPP_EXPORT Media
59 {
60 public:
61 QT_DEPRECATED_X("Use QXmppDataForm::Field() instead")
62 Media();
63 QT_DEPRECATED_X("Use QXmppDataForm::Field() instead")
64 Media(const QXmppDataForm::Media &other);
66
67 QXmppDataForm::Media &operator=(const QXmppDataForm::Media &other);
68
69 QT_DEPRECATED_X("Use QXmppDataForm::Field::mediaSize().height() instead")
70 int height() const;
71 QT_DEPRECATED_X("Use QXmppDataForm::Field::mediaSize().setHeight() instead")
72 void setHeight(int height);
73
74 QT_DEPRECATED_X("Use QXmppDataForm::Field::mediaSize().width() instead")
75 int width() const;
76 QT_DEPRECATED_X("Use QXmppDataForm::Field::mediaSize().setWidth() instead")
77 void setWidth(int width);
78
79 QT_DEPRECATED_X("Use QXmppDataForm::Field::mediaSources() instead")
80 QList<QPair<QString, QString>> uris() const;
81 QT_DEPRECATED_X("Use QXmppDataForm::Field::setMediaSources() instead")
82 void setUris(const QList<QPair<QString, QString>> &uris);
83
84 QT_DEPRECATED_X("Use QXmppDataForm::Field::mediaSources().isEmpty() instead")
85 bool isNull() const;
86
87 private:
88 QSharedDataPointer<QXmppDataFormMediaPrivate> d;
89 };
90#endif
91
92 class QXMPP_EXPORT Field
93 {
94 public:
96 enum Type {
97 BooleanField,
98 FixedField,
99 HiddenField,
100 JidMultiField,
101 JidSingleField,
102 ListMultiField,
103 ListSingleField,
104 TextMultiField,
105 TextPrivateField,
106 TextSingleField
107 };
108
109 Field(Type type = TextSingleField,
110 const QString &key = {},
111 const QVariant &value = {},
112 bool isRequired = false,
113 const QString &label = {},
114 const QString &description = {},
115 const QList<QPair<QString, QString>> &options = {});
119
122
123 QString description() const;
124 void setDescription(const QString &description);
125
126 QString key() const;
127 void setKey(const QString &key);
128
129 QString label() const;
130 void setLabel(const QString &label);
131
132 QList<QPair<QString, QString>> options() const;
133 void setOptions(const QList<QPair<QString, QString>> &options);
134
135 bool isRequired() const;
136 void setRequired(bool required);
137
138 QXmppDataForm::Field::Type type() const;
139 void setType(QXmppDataForm::Field::Type type);
140
141 QVariant value() const;
142 void setValue(const QVariant &value);
143
144 QVector<QXmppDataForm::MediaSource> mediaSources() const;
145 void setMediaSources(const QVector<QXmppDataForm::MediaSource> &mediaSources);
146
147 QSize mediaSize() const;
148 void setMediaSize(const QSize &size);
149
150 bool operator==(const Field &other) const;
151
153 static constexpr std::tuple XmlTag = { u"field", QXmpp::Private::ns_data };
154 static std::optional<Field> fromDom(const QDomElement &el);
155 void toXml(QXmlStreamWriter *writer) const;
156
157#if QXMPP_DEPRECATED_SINCE(1, 1)
158 [[deprecated("Use mediaSources() and mediaSize()")]]
159 Media media() const;
160 [[deprecated("Use setMediaSources() and setMediaSize()")]]
161 void setMedia(const Media &media);
162#endif
163#if QXMPP_DEPRECATED_SINCE(1, 12)
164 [[deprecated("Use const-getter or setter")]]
165 QVector<QXmppDataForm::MediaSource> &mediaSources();
166 [[deprecated("Use const-getter or setter")]]
167 QSize &mediaSize();
168#endif
170
171 private:
172 QSharedDataPointer<QXmppDataFormFieldPrivate> d;
173 };
174
176 enum Type {
178 Form,
180 Submit,
182 Cancel,
184 Result
187 };
188
189 QXmppDataForm(Type type = None,
190 const QList<Field> &fields = {},
191 const QString &title = {},
192 const QString &instructions = {});
193 QXmppDataForm(const QXmppDataFormBase &based);
197
200
201 QString instructions() const;
202 void setInstructions(const QString &instructions);
203
204 QList<Field> fields() const;
205 const QList<Field> &constFields() const;
206 void setFields(const QList<QXmppDataForm::Field> &fields);
207 void appendField(QXmppDataForm::Field &&field);
208
209 // lookup by key
210 std::optional<QXmppDataForm::Field> field(QStringView fieldName) const;
211 std::optional<QVariant> fieldValue(QStringView fieldName) const;
212
213 QString title() const;
214 void setTitle(const QString &title);
215
216 QXmppDataForm::Type type() const;
217 void setType(QXmppDataForm::Type type);
218
219 QString formType() const;
220
221 bool isNull() const;
222
224 static constexpr std::tuple XmlTag = { u"x", QXmpp::Private::ns_data };
225 void parse(const QDomElement &element);
226 void toXml(QXmlStreamWriter *writer) const;
227
228#if QXMPP_DEPRECATED_SINCE(1, 12)
229 [[deprecated("Use const-getter or setter")]]
230 QList<Field> &fields();
231#endif
233
234private:
235 QSharedDataPointer<QXmppDataFormPrivate> d;
236};
237
238Q_DECLARE_METATYPE(QXmppDataForm)
239
240#endif
Definition QXmppDataFormBase.h:15
Definition QXmppDataForm.h:93
Field(QXmppDataForm::Field &&)
Default move constructor.
Type
This enum is used to describe a field's type.
Definition QXmppDataForm.h:96
Field(const QXmppDataForm::Field &other)
Constructs a copy of other.
QXmppDataForm::Field & operator=(const QXmppDataForm::Field &other)
Assigns other to this field.
~Field()
Destroys the form field.
QXmppDataForm::Field & operator=(QXmppDataForm::Field &&)
Default move-assignment operator.
Definition QXmppDataForm.h:31
MediaSource & operator=(MediaSource &&)
Default move-assignment operator.
MediaSource & operator=(const MediaSource &)
Default assignment operator.
MediaSource(const QXmppDataForm::MediaSource &)
Default copy-constructor.
MediaSource(QXmppDataForm::MediaSource &&)
Default move-constructor.
Definition QXmppDataForm.h:59
Definition QXmppDataForm.h:28
QXmppDataForm(QXmppDataForm &&)
Default move constructor.
QXmppDataForm & operator=(QXmppDataForm &&)
Default move-assignment operator.
QXmppDataForm(const QXmppDataForm &other)
Constructs a copy of other.
QXmppDataForm & operator=(const QXmppDataForm &other)
Assigns other to this form.
~QXmppDataForm()
Destroys the form.
Type
This enum is used to describe a form's type.
Definition QXmppDataForm.h:176
@ None
Unknown form type.
Definition QXmppDataForm.h:177