QXmpp  Version: 1.15.1
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 
18 class QMimeType;
19 class QUrl;
20 
21 class QXmppDataFormBase;
22 class QXmppDataFormPrivate;
23 class QXmppDataFormFieldPrivate;
24 class QXmppDataFormMediaPrivate;
25 class QXmppDataFormMediaSourcePrivate;
26 
27 class QXMPP_EXPORT QXmppDataForm
28 {
29 public:
30  class QXMPP_EXPORT MediaSource
31  {
32  public:
33  MediaSource();
34  MediaSource(const QUrl &uri, const QMimeType &contentType);
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);
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
169 
171  private:
172  QSharedDataPointer<QXmppDataFormFieldPrivate> d;
173  };
174 
176  enum Type {
178  Form,
179  Submit,
181  Cancel,
183  Result
185  };
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);
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
232 
234 private:
235  QSharedDataPointer<QXmppDataFormPrivate> d;
236 };
237 
238 Q_DECLARE_METATYPE(QXmppDataForm)
239 
240 #endif
Type
This enum is used to describe a form&#39;s type.
Definition: QXmppDataForm.h:176
Unknown form type.
Definition: QXmppDataForm.h:177
Type
This enum is used to describe a field&#39;s type.
Definition: QXmppDataForm.h:96
Definition: QXmppDataForm.h:30
Definition: QXmppDataForm.h:27
Definition: QXmppDataForm.h:92
Definition: QXmppDataForm.h:58
Definition: QXmppDataFormBase.h:14