QXmpp Version: 1.11.3
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#if QXMPP_DEPRECATED_SINCE(1, 1)
133 QT_DEPRECATED_X("Use QXmppDataForm::Field::mediaSources() or QXmppDataForm::Field::mediaSize() instead")
134 Media media() const;
135
136 QT_DEPRECATED_X("Use QXmppDataForm::Field::setMediaSources() or QXmppDataForm::Field::setMediaSize() instead")
137 void setMedia(const Media &media);
138#endif
139
140 QList<QPair<QString, QString>> options() const;
141 void setOptions(const QList<QPair<QString, QString>> &options);
142
143 bool isRequired() const;
144 void setRequired(bool required);
145
146 QXmppDataForm::Field::Type type() const;
147 void setType(QXmppDataForm::Field::Type type);
148
149 QVariant value() const;
150 void setValue(const QVariant &value);
151
152 QVector<QXmppDataForm::MediaSource> &mediaSources();
153 QVector<QXmppDataForm::MediaSource> mediaSources() const;
154 void setMediaSources(const QVector<QXmppDataForm::MediaSource> &mediaSources);
155
156 QSize mediaSize() const;
157 QSize &mediaSize();
158 void setMediaSize(const QSize &size);
159
160 bool operator==(const Field &other) const;
161
163 static constexpr std::tuple XmlTag = { u"field", QXmpp::Private::ns_data };
164 static std::optional<Field> fromDom(const QDomElement &el);
165 void toXml(QXmlStreamWriter *writer) const;
167
168 private:
169 QSharedDataPointer<QXmppDataFormFieldPrivate> d;
170 };
171
173 enum Type {
175 Form,
177 Submit,
179 Cancel,
181 Result
184 };
185
186 QXmppDataForm(Type type = None,
187 const QList<Field> &fields = {},
188 const QString &title = {},
189 const QString &instructions = {});
190 QXmppDataForm(const QXmppDataFormBase &based);
194
197
198 QString instructions() const;
199 void setInstructions(const QString &instructions);
200
201 QList<Field> fields() const;
202 QList<Field> &fields();
203 void setFields(const QList<QXmppDataForm::Field> &fields);
204
205 QString title() const;
206 void setTitle(const QString &title);
207
208 QXmppDataForm::Type type() const;
209 void setType(QXmppDataForm::Type type);
210
211 QString formType() const;
212
213 bool isNull() const;
214
216 static constexpr std::tuple XmlTag = { u"x", QXmpp::Private::ns_data };
217 void parse(const QDomElement &element);
218 void toXml(QXmlStreamWriter *writer) const;
220
221private:
222 QSharedDataPointer<QXmppDataFormPrivate> d;
223};
224
225Q_DECLARE_METATYPE(QXmppDataForm)
226
227#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:173
@ None
Unknown form type.
Definition QXmppDataForm.h:174