QXmpp Version: 1.5.6
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 "QXmppStanza.h"
10
11#if QXMPP_DEPRECATED_SINCE(1, 1)
12#include <QPair>
13#endif
14#include <QVariant>
15#include <QVector>
16
17class QMimeType;
18class QUrl;
19
21class QXmppDataFormPrivate;
22class QXmppDataFormFieldPrivate;
23class QXmppDataFormMediaPrivate;
24class QXmppDataFormMediaSourcePrivate;
25
26class QXMPP_EXPORT QXmppDataForm
27{
28public:
29 class QXMPP_EXPORT MediaSource
30 {
31 public:
33 MediaSource(const QUrl &uri, const QMimeType &contentType);
37
40
41 QUrl uri() const;
42 void setUri(const QUrl &uri);
43
44 QMimeType contentType() const;
45 void setContentType(const QMimeType &contentType);
46
47 bool operator==(const MediaSource &other) const;
48
49 private:
50 QSharedDataPointer<QXmppDataFormMediaSourcePrivate> d;
51 };
52
53#if QXMPP_DEPRECATED_SINCE(1, 1)
54 class QXMPP_EXPORT Media
55 {
56 public:
57 QT_DEPRECATED_X("Use QXmppDataForm::Field() instead")
58 Media();
59 QT_DEPRECATED_X("Use QXmppDataForm::Field() instead")
60 Media(const QXmppDataForm::Media &other);
62
63 QXmppDataForm::Media &operator=(const QXmppDataForm::Media &other);
64
65 QT_DEPRECATED_X("Use QXmppDataForm::Field::mediaSize().height() instead")
66 int height() const;
67 QT_DEPRECATED_X("Use QXmppDataForm::Field::mediaSize().setHeight() instead")
68 void setHeight(int height);
69
70 QT_DEPRECATED_X("Use QXmppDataForm::Field::mediaSize().width() instead")
71 int width() const;
72 QT_DEPRECATED_X("Use QXmppDataForm::Field::mediaSize().setWidth() instead")
73 void setWidth(int width);
74
75 QT_DEPRECATED_X("Use QXmppDataForm::Field::mediaSources() instead")
76 QList<QPair<QString, QString>> uris() const;
77 QT_DEPRECATED_X("Use QXmppDataForm::Field::setMediaSources() instead")
78 void setUris(const QList<QPair<QString, QString>> &uris);
79
80 QT_DEPRECATED_X("Use QXmppDataForm::Field::mediaSources().isEmpty() instead")
81 bool isNull() const;
82
83 private:
84 QSharedDataPointer<QXmppDataFormMediaPrivate> d;
85 };
86#endif
87
88 class QXMPP_EXPORT Field
89 {
90 public:
92 enum Type {
93 BooleanField,
94 FixedField,
95 HiddenField,
96 JidMultiField,
97 JidSingleField,
98 ListMultiField,
99 ListSingleField,
100 TextMultiField,
101 TextPrivateField,
102 TextSingleField
103 };
104
105 Field(Type type = TextSingleField,
106 const QString &key = {},
107 const QVariant &value = {},
108 bool isRequired = false,
109 const QString &label = {},
110 const QString &description = {},
111 const QList<QPair<QString, QString>> &options = {});
115
118
119 QString description() const;
120 void setDescription(const QString &description);
121
122 QString key() const;
123 void setKey(const QString &key);
124
125 QString label() const;
126 void setLabel(const QString &label);
127
128#if QXMPP_DEPRECATED_SINCE(1, 1)
129 QT_DEPRECATED_X("Use QXmppDataForm::Field::mediaSources() or QXmppDataForm::Field::mediaSize() instead")
130 Media media() const;
131
132 QT_DEPRECATED_X("Use QXmppDataForm::Field::setMediaSources() or QXmppDataForm::Field::setMediaSize() instead")
133 void setMedia(const Media &media);
134#endif
135
136 QList<QPair<QString, QString>> options() const;
137 void setOptions(const QList<QPair<QString, QString>> &options);
138
139 bool isRequired() const;
140 void setRequired(bool required);
141
142 QXmppDataForm::Field::Type type() const;
143 void setType(QXmppDataForm::Field::Type type);
144
145 QVariant value() const;
146 void setValue(const QVariant &value);
147
148 QVector<QXmppDataForm::MediaSource> &mediaSources();
149 QVector<QXmppDataForm::MediaSource> mediaSources() const;
150 void setMediaSources(const QVector<QXmppDataForm::MediaSource> &mediaSources);
151
152 QSize mediaSize() const;
153 QSize &mediaSize();
154 void setMediaSize(const QSize &size);
155
156 bool operator==(const Field &other) const;
157
158 private:
159 QSharedDataPointer<QXmppDataFormFieldPrivate> d;
160 };
161
163 enum Type {
165 Form,
167 Submit,
169 Cancel,
171 Result
174 };
175
176 QXmppDataForm(Type type = None,
177 const QList<Field> &fields = {},
178 const QString &title = {},
179 const QString &instructions = {});
180 QXmppDataForm(const QXmppDataFormBase &based);
184
187
188 QString instructions() const;
189 void setInstructions(const QString &instructions);
190
191 QList<Field> fields() const;
192 QList<Field> &fields();
193 void setFields(const QList<QXmppDataForm::Field> &fields);
194
195 QString title() const;
196 void setTitle(const QString &title);
197
198 QXmppDataForm::Type type() const;
199 void setType(QXmppDataForm::Type type);
200
201 QString formType() const;
202
203 bool isNull() const;
204
206 void parse(const QDomElement &element);
207 void toXml(QXmlStreamWriter *writer) const;
209
210private:
211 QSharedDataPointer<QXmppDataFormPrivate> d;
212};
213
214Q_DECLARE_METATYPE(QXmppDataForm)
215
216#endif
Definition QXmppDataFormBase.h:15
Definition QXmppDataForm.h:89
Field(QXmppDataForm::Field &&)
Default move constructor.
Type
This enum is used to describe a field's type.
Definition QXmppDataForm.h:92
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:30
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:55
Definition QXmppDataForm.h:27
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:163
@ None
Unknown form type.
Definition QXmppDataForm.h:164