QXmpp  Version:1.2.0
QXmppDataForm.h
1 /*
2  * Copyright (C) 2008-2020 The QXmpp developers
3  *
4  * Author:
5  * Jeremy LainĂ©
6  * Linus Jahn
7  *
8  * Source:
9  * https://github.com/qxmpp-project/qxmpp
10  *
11  * This file is a part of QXmpp library.
12  *
13  * This library is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU Lesser General Public
15  * License as published by the Free Software Foundation; either
16  * version 2.1 of the License, or (at your option) any later version.
17  *
18  * This library is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  * Lesser General Public License for more details.
22  *
23  */
24 
25 #ifndef QXMPPDATAFORM_H
26 #define QXMPPDATAFORM_H
27 
28 #include "QXmppStanza.h"
29 
30 #if QXMPP_DEPRECATED_SINCE(1, 1)
31 #include <QPair>
32 #endif
33 #include <QVariant>
34 #include <QVector>
35 
36 class QMimeType;
37 class QUrl;
38 
39 class QXmppDataFormPrivate;
40 class QXmppDataFormFieldPrivate;
41 class QXmppDataFormMediaPrivate;
42 class QXmppDataFormMediaSourcePrivate;
43 
46 
47 class QXMPP_EXPORT QXmppDataForm
48 {
49 public:
55 
56  class QXMPP_EXPORT MediaSource
57  {
58  public:
59  MediaSource();
60  MediaSource(const QUrl &uri, const QMimeType &contentType);
62  ~MediaSource();
63 
64  MediaSource &operator=(const MediaSource &);
65 
66  QUrl uri() const;
67  void setUri(const QUrl &uri);
68 
69  QMimeType contentType() const;
70  void setContentType(const QMimeType &contentType);
71 
72  bool operator==(const MediaSource &other) const;
73 
74  private:
75  QSharedDataPointer<QXmppDataFormMediaSourcePrivate> d;
76  };
77 
78 #if QXMPP_DEPRECATED_SINCE(1, 1)
79 
84  class QXMPP_EXPORT Media
85  {
86  public:
87  QT_DEPRECATED_X("Use QXmppDataForm::Field() instead")
88  Media();
89  QT_DEPRECATED_X("Use QXmppDataForm::Field() instead")
90  Media(const QXmppDataForm::Media &other);
91  ~Media();
92 
93  QXmppDataForm::Media &operator=(const QXmppDataForm::Media &other);
94 
95  QT_DEPRECATED_X("Use QXmppDataForm::Field::mediaSize().height() instead")
96  int height() const;
97  QT_DEPRECATED_X("Use QXmppDataForm::Field::mediaSize().setHeight() instead")
98  void setHeight(int height);
99 
100  QT_DEPRECATED_X("Use QXmppDataForm::Field::mediaSize().width() instead")
101  int width() const;
102  QT_DEPRECATED_X("Use QXmppDataForm::Field::mediaSize().setWidth() instead")
103  void setWidth(int width);
104 
105  QT_DEPRECATED_X("Use QXmppDataForm::Field::mediaSources() instead")
106  QList<QPair<QString, QString>> uris() const;
107  QT_DEPRECATED_X("Use QXmppDataForm::Field::setMediaSources() instead")
108  void setUris(const QList<QPair<QString, QString>> &uris);
109 
110  QT_DEPRECATED_X("Use QXmppDataForm::Field::mediaSources().isEmpty() instead")
111  bool isNull() const;
112 
113  private:
114  QSharedDataPointer<QXmppDataFormMediaPrivate> d;
115  };
116 #endif
117 
120 
121  class QXMPP_EXPORT Field
122  {
123  public:
125  enum Type {
126  BooleanField,
127  FixedField,
128  HiddenField,
129  JidMultiField,
130  JidSingleField,
131  ListMultiField,
132  ListSingleField,
133  TextMultiField,
134  TextPrivateField,
135  TextSingleField
136  };
137 
138  Field(QXmppDataForm::Field::Type type = QXmppDataForm::Field::TextSingleField);
139  Field(const QXmppDataForm::Field &other);
140  ~Field();
141 
142  QXmppDataForm::Field &operator=(const QXmppDataForm::Field &other);
143 
144  QString description() const;
145  void setDescription(const QString &description);
146 
147  QString key() const;
148  void setKey(const QString &key);
149 
150  QString label() const;
151  void setLabel(const QString &label);
152 
153 #if QXMPP_DEPRECATED_SINCE(1, 1)
154  QT_DEPRECATED_X("Use QXmppDataForm::Field::mediaSources() or QXmppDataForm::Field::mediaSize() instead")
155  Media media() const;
156 
157  QT_DEPRECATED_X("Use QXmppDataForm::Field::setMediaSources() or QXmppDataForm::Field::setMediaSize() instead")
158  void setMedia(const Media &media);
159 #endif
160 
161  QList<QPair<QString, QString>> options() const;
162  void setOptions(const QList<QPair<QString, QString>> &options);
163 
164  bool isRequired() const;
165  void setRequired(bool required);
166 
167  QXmppDataForm::Field::Type type() const;
168  void setType(QXmppDataForm::Field::Type type);
169 
170  QVariant value() const;
171  void setValue(const QVariant &value);
172 
173  QVector<QXmppDataForm::MediaSource> &mediaSources();
174  QVector<QXmppDataForm::MediaSource> mediaSources() const;
175  void setMediaSources(const QVector<QXmppDataForm::MediaSource> &mediaSources);
176 
177  QSize mediaSize() const;
178  QSize &mediaSize();
179  void setMediaSize(const QSize &size);
180 
181  bool operator==(const Field &other) const;
182 
183  private:
184  QSharedDataPointer<QXmppDataFormFieldPrivate> d;
185  };
186 
188  enum Type {
190  Form,
191  Submit,
193  Cancel,
195  Result
197  };
200 
202  QXmppDataForm(const QXmppDataForm &other);
203  ~QXmppDataForm();
204 
205  QXmppDataForm &operator=(const QXmppDataForm &other);
206 
207  QString instructions() const;
208  void setInstructions(const QString &instructions);
209 
210  QList<Field> fields() const;
211  QList<Field> &fields();
212  void setFields(const QList<QXmppDataForm::Field> &fields);
213 
214  QString title() const;
215  void setTitle(const QString &title);
216 
217  QXmppDataForm::Type type() const;
218  void setType(QXmppDataForm::Type type);
219 
220  bool isNull() const;
221 
223  void parse(const QDomElement &element);
224  void toXml(QXmlStreamWriter *writer) const;
226 
227 private:
228  QSharedDataPointer<QXmppDataFormPrivate> d;
229 };
230 
231 #endif
QXmppDataForm::Field::Type
Type
This enum is used to describe a field's type.
Definition: QXmppDataForm.h:125
QXmppDataForm::Field
The QXmppDataForm::Field class represents a data form field as defined by XEP-0004: Data Forms.
Definition: QXmppDataForm.h:121
QXmppDataForm
The QXmppDataForm class represents a data form as defined by XEP-0004: Data Forms.
Definition: QXmppDataForm.h:47
QXmppDataForm::None
Unknown form type.
Definition: QXmppDataForm.h:189
QXmppDataForm::Media
The QXmppDataForm::Media class represents a media field as defined by XEP-0221: Data Forms Media Elem...
Definition: QXmppDataForm.h:84
QXmppDataForm::MediaSource
The QXmppDataForm::MediaSource class represents a link to one of possibly multiple sources for a medi...
Definition: QXmppDataForm.h:56
QXmppDataForm::Type
Type
This enum is used to describe a form's type.
Definition: QXmppDataForm.h:188