QXmpp: QXmppDataForm.h Source File

QXmpp Version: 1.14.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
21class QXmppDataFormBase;
22class QXmppDataFormPrivate;
23class QXmppDataFormFieldPrivate;
24class QXmppDataFormMediaPrivate;
25class QXmppDataFormMediaSourcePrivate;
26
27 class QXMPP_EXPORT QXmppDataForm
28{
29public:
30 class QXMPP_EXPORT MediaSource
31 {
32 public:
33 MediaSource();
34 MediaSource(const QUrl &uri, const QMimeType &contentType);
35 MediaSource(const QXmppDataForm::MediaSource &);
36 MediaSource(QXmppDataForm::MediaSource &&);
37 ~MediaSource();
38
39 MediaSource &operator=(const MediaSource &);
40 MediaSource &operator=(MediaSource &&);
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);
65 ~Media();
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 = {});
116 Field(const QXmppDataForm::Field &other);
117 Field(QXmppDataForm::Field &&);
118 ~Field();
119
120 QXmppDataForm::Field &operator=(const QXmppDataForm::Field &other);
121 QXmppDataForm::Field &operator=(QXmppDataForm::Field &&);
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 {
177 None,
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);
194 QXmppDataForm(const QXmppDataForm &other);
195 QXmppDataForm(QXmppDataForm &&);
196 ~QXmppDataForm();
197
198 QXmppDataForm &operator=(const QXmppDataForm &other);
199 QXmppDataForm &operator=(QXmppDataForm &&);
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
QXmppDataForm::Field
Definition QXmppDataForm.h:93
QXmppDataForm::Field::setOptions
void setOptions(const QList< QPair< QString, QString > > &options)
Definition QXmppDataForm.cpp:409
QXmppDataForm::Field::key
QString key() const
Definition QXmppDataForm.cpp:361
QXmppDataForm::Field::mediaSize
QSize mediaSize() const
Definition QXmppDataForm.cpp:476
QXmppDataForm::Field::description
QString description() const
Definition QXmppDataForm.cpp:343
QXmppDataForm::Field::Field
Field(QXmppDataForm::Field &&)
Default move constructor.
QXmppDataForm::Field::Type
Type
This enum is used to describe a field's type.
Definition QXmppDataForm.h:96
QXmppDataForm::Field::label
QString label() const
Definition QXmppDataForm.cpp:379
QXmppDataForm::Field::mediaSources
QVector< QXmppDataForm::MediaSource > mediaSources() const
Definition QXmppDataForm.cpp:498
QXmppDataForm::Field::setKey
void setKey(const QString &key)
Definition QXmppDataForm.cpp:371
QXmppDataForm::Field::Field
Field(const QXmppDataForm::Field &other)
Constructs a copy of other.
QXmppDataForm::Field::operator=
QXmppDataForm::Field & operator=(const QXmppDataForm::Field &other)
Assigns other to this field.
QXmppDataForm::Field::~Field
~Field()
Destroys the form field.
QXmppDataForm::Field::isRequired
bool isRequired() const
Definition QXmppDataForm.cpp:419
QXmppDataForm::Field::setValue
void setValue(const QVariant &value)
Definition QXmppDataForm.cpp:465
QXmppDataForm::Field::operator=
QXmppDataForm::Field & operator=(QXmppDataForm::Field &&)
Default move-assignment operator.
QXmppDataForm::Field::setMediaSize
void setMediaSize(const QSize &size)
Definition QXmppDataForm.cpp:487
QXmppDataForm::Field::setRequired
void setRequired(bool required)
Definition QXmppDataForm.cpp:429
QXmppDataForm::Field::value
QVariant value() const
Definition QXmppDataForm.cpp:455
QXmppDataForm::Field::type
QXmppDataForm::Field::Type type() const
Definition QXmppDataForm.cpp:437
QXmppDataForm::Field::operator==
bool operator==(const Field &other) const
Definition QXmppDataForm.cpp:519
QXmppDataForm::Field::setDescription
void setDescription(const QString &description)
Definition QXmppDataForm.cpp:353
QXmppDataForm::Field::setType
void setType(QXmppDataForm::Field::Type type)
Definition QXmppDataForm.cpp:447
QXmppDataForm::Field::Field
Field(Type type=TextSingleField, const QString &key={}, const QVariant &value={}, bool isRequired=false, const QString &label={}, const QString &description={}, const QList< QPair< QString, QString > > &options={})
Definition QXmppDataForm.cpp:311
QXmppDataForm::Field::setLabel
void setLabel(const QString &label)
Definition QXmppDataForm.cpp:389
QXmppDataForm::Field::setMediaSources
void setMediaSources(const QVector< QXmppDataForm::MediaSource > &mediaSources)
Definition QXmppDataForm.cpp:509
QXmppDataForm::Field::options
QList< QPair< QString, QString > > options() const
Definition QXmppDataForm.cpp:397
QXmppDataForm::Media
Definition QXmppDataForm.h:59
QXmppDataForm::Media::setUris
void setUris(const QList< QPair< QString, QString > > &uris)
Definition QXmppDataForm.cpp:253
QXmppDataForm::Media::Media
Media()
Definition QXmppDataForm.cpp:166
QXmppDataForm::Media::uris
QList< QPair< QString, QString > > uris() const
Definition QXmppDataForm.cpp:242
QXmppDataForm::Media::setHeight
void setHeight(int height)
Definition QXmppDataForm.cpp:209
QXmppDataForm::Media::width
int width() const
Definition QXmppDataForm.cpp:220
QXmppDataForm::Media::setWidth
void setWidth(int width)
Definition QXmppDataForm.cpp:231
QXmppDataForm::Media::height
int height() const
Definition QXmppDataForm.cpp:198
QXmppDataForm::Media::isNull
bool isNull() const
Definition QXmppDataForm.cpp:261
QXmppDataForm::MediaSource
Definition QXmppDataForm.h:31
QXmppDataForm::MediaSource::setContentType
void setContentType(const QMimeType &contentType)
Definition QXmppDataForm.cpp:132
QXmppDataForm::MediaSource::operator=
MediaSource & operator=(MediaSource &&)
Default move-assignment operator.
QXmppDataForm::MediaSource::operator=
MediaSource & operator=(const MediaSource &)
Default assignment operator.
QXmppDataForm::MediaSource::MediaSource
MediaSource(const QXmppDataForm::MediaSource &)
Default copy-constructor.
QXmppDataForm::MediaSource::MediaSource
MediaSource()
Definition QXmppDataForm.cpp:76
QXmppDataForm::MediaSource::contentType
QMimeType contentType() const
Definition QXmppDataForm.cpp:124
QXmppDataForm::MediaSource::operator==
bool operator==(const MediaSource &other) const
Definition QXmppDataForm.cpp:140
QXmppDataForm::MediaSource::uri
QUrl uri() const
Definition QXmppDataForm.cpp:108
QXmppDataForm::MediaSource::setUri
void setUri(const QUrl &uri)
Definition QXmppDataForm.cpp:116
QXmppDataForm::MediaSource::MediaSource
MediaSource(QXmppDataForm::MediaSource &&)
Default move-constructor.
QXmppDataFormBase
Definition QXmppDataFormBase.h:15
QXmppDataForm
Definition QXmppDataForm.h:28
QXmppDataForm::appendField
void appendField(QXmppDataForm::Field &&field)
Definition QXmppDataForm.cpp:779
QXmppDataForm::fields
QList< Field > fields() const
Returns all fields.
Definition QXmppDataForm.cpp:759
QXmppDataForm::QXmppDataForm
QXmppDataForm(QXmppDataForm &&)
Default move constructor.
QXmppDataForm::constFields
const QList< Field > & constFields() const
Definition QXmppDataForm.cpp:766
QXmppDataForm::type
QXmppDataForm::Type type() const
Definition QXmppDataForm.cpp:851
QXmppDataForm::operator=
QXmppDataForm & operator=(QXmppDataForm &&)
Default move-assignment operator.
QXmppDataForm::setType
void setType(QXmppDataForm::Type type)
Definition QXmppDataForm.cpp:861
QXmppDataForm::field
std::optional< QXmppDataForm::Field > field(QStringView fieldName) const
Definition QXmppDataForm.cpp:789
QXmppDataForm::setInstructions
void setInstructions(const QString &instructions)
Definition QXmppDataForm.cpp:825
QXmppDataForm::QXmppDataForm
QXmppDataForm(const QXmppDataForm &other)
Constructs a copy of other.
QXmppDataForm::operator=
QXmppDataForm & operator=(const QXmppDataForm &other)
Assigns other to this form.
QXmppDataForm::isNull
bool isNull() const
Definition QXmppDataForm.cpp:890
QXmppDataForm::formType
QString formType() const
Definition QXmppDataForm.cpp:874
QXmppDataForm::fieldValue
std::optional< QVariant > fieldValue(QStringView fieldName) const
Definition QXmppDataForm.cpp:803
QXmppDataForm::title
QString title() const
Definition QXmppDataForm.cpp:833
QXmppDataForm::setFields
void setFields(const QList< QXmppDataForm::Field > &fields)
Sets the form's fields.
Definition QXmppDataForm.cpp:772
QXmppDataForm::instructions
QString instructions() const
Definition QXmppDataForm.cpp:815
QXmppDataForm::~QXmppDataForm
~QXmppDataForm()
Destroys the form.
QXmppDataForm::Type
Type
This enum is used to describe a form's type.
Definition QXmppDataForm.h:176
QXmppDataForm::None
@ None
Unknown form type.
Definition QXmppDataForm.h:177
QXmppDataForm::Form
@ Form
Definition QXmppDataForm.h:178
QXmppDataForm::Cancel
@ Cancel
Definition QXmppDataForm.h:182
QXmppDataForm::Result
@ Result
Definition QXmppDataForm.h:184
QXmppDataForm::Submit
@ Submit
Definition QXmppDataForm.h:180
QXmppDataForm::QXmppDataForm
QXmppDataForm(Type type=None, const QList< Field > &fields={}, const QString &title={}, const QString &instructions={})
Definition QXmppDataForm.cpp:725
QXmppDataForm::setTitle
void setTitle(const QString &title)
Definition QXmppDataForm.cpp:843